* Stream JSONL results from a completed batch and return as a Map.
( client: Anthropic, batch: MessageBatch, operationName: string, )
| 161 | * Stream JSONL results from a completed batch and return as a Map. |
| 162 | */ |
| 163 | async 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. |
no test coverage detected