MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / collectResults

Function collectResults

server/src/utils/batch.ts:163–185  ·  view source on GitHub ↗

* Stream JSONL results from a completed batch and return as a Map.

(
  client: Anthropic,
  batch: MessageBatch,
  operationName: string,
)

Source from the content-addressed store, hash-verified

161 * Stream JSONL results from a completed batch and return as a Map.
162 */
163async function collectResults(
164 client: Anthropic,
165 batch: MessageBatch,
166 operationName: string,
167): Promise<Map<string, BatchItemResult>> {
168 const results = new Map<string, BatchItemResult>();
169 const decoder = await client.messages.batches.results(batch.id);
170
171 for await (const entry of decoder) {
172 const item = toBatchItemResult(entry);
173 results.set(item.customId, item);
174 }
175
176 let succeeded = 0;
177 results.forEach((r) => { if (r.status === 'succeeded') succeeded++; });
178 const failed = results.size - succeeded;
179 logger.info(
180 { batchId: batch.id, succeeded, failed, operation: operationName },
181 'Batch results collected',
182 );
183
184 return results;
185}
186
187/**
188 * Convert an SDK batch result entry to our BatchItemResult.

Callers 1

submitBatchFunction · 0.85

Calls 2

toBatchItemResultFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected