MCPcopy Index your code
hub / github.com/simstudioai/sim / chunkOpsByByteBudget

Function chunkOpsByByteBudget

apps/sim/lib/knowledge/connectors/sync-engine.ts:125–147  ·  view source on GitHub ↗
(
  ops: DocOp[],
  budgetBytes: number,
  maxCount: number
)

Source from the content-addressed store, hash-verified

123 * larger than the budget still forms its own chunk (always >= 1 op per chunk).
124 */
125export function chunkOpsByByteBudget(
126 ops: DocOp[],
127 budgetBytes: number,
128 maxCount: number
129): DocOp[][] {
130 const chunks: DocOp[][] = []
131 let current: DocOp[] = []
132 let currentBytes = 0
133 for (const op of ops) {
134 const bytes = estimateOpSizeBytes(op)
135 if (current.length > 0 && (current.length >= maxCount || currentBytes + bytes > budgetBytes)) {
136 chunks.push(current)
137 current = []
138 currentBytes = 0
139 }
140 current.push(op)
141 currentBytes += bytes
142 }
143 if (current.length > 0) {
144 chunks.push(current)
145 }
146 return chunks
147}
148
149/** Single-roundtrip liveness check used between batches. */
150async function checkSyncLiveness(

Callers 2

executeSyncFunction · 0.85

Calls 2

estimateOpSizeBytesFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected