Skip to main content
Glama
by alucardeht
ResponseChunker.js1.48 kB
import TokenEstimator from "./TokenEstimator.js"; class ResponseChunker { constructor(tokenEstimator, sessionManager) { this.tokenEstimator = tokenEstimator; this.session = sessionManager; } wrapResponse(data, options = {}) { const { step = "Operation completed", progress = "1/1", nextStep = null, canContinue = false, guidance = null, progressInfo = null, } = options; const response = { _navigation: { currentStep: step, progress, tokensThisResponse: 0, canContinue, }, data, }; if (nextStep) { response._navigation.nextStep = nextStep; } if (guidance) { response._guidance = guidance; } if (progressInfo) { response._progress = progressInfo; } response._navigation.tokensThisResponse = this.tokenEstimator.estimate(response); this.session.storeLastResponse(response); return response; } chunkArray(array, operationId, maxItemsPerChunk = 20) { if (array.length <= maxItemsPerChunk) { return null; } const chunks = []; for (let i = 0; i < array.length; i += maxItemsPerChunk) { chunks.push(array.slice(i, i + maxItemsPerChunk)); } this.session.storePendingChunks(operationId, chunks); return { items: chunks[0], chunkIndex: 1, totalChunks: chunks.length, totalItems: array.length, }; } } export default ResponseChunker;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/alucardeht/figma-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server