Skip to main content
Glama
mergeChunks.ts1.05 kB
export const mergeChunks = (chunks: any[]): any => { if (chunks.length === 0) return {}; let result = chunks[0]; for (let i = 1; i < chunks.length; i++) { result = customChunkMerge(result, chunks[i]); } return result; }; const customChunkMerge = (dest: any, source: any): any => { if (dest === undefined || dest === null) return source; if (source === undefined || source === null) return dest; if (Array.isArray(dest) && Array.isArray(source)) { const maxLength = Math.max(dest.length, source.length); const result = []; for (let i = 0; i < maxLength; i++) { result[i] = customChunkMerge(dest[i], source[i]); } return result; } if (typeof dest === 'object' && typeof source === 'object') { const result: any = { ...dest }; for (const key of Object.keys(source)) { result[key] = customChunkMerge(result[key], source[key]); } return result; } // Primitives: if we are here, both are not null. // Since chunks shouldn't overlap, we can return dest. return dest; };

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/aymericzip/intlayer'

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