( res: Response, protocol: AIRouterProtocol, message: string, type: string )
| 1332 | } |
| 1333 | |
| 1334 | function writeAIRouterStreamError( |
| 1335 | res: Response, |
| 1336 | protocol: AIRouterProtocol, |
| 1337 | message: string, |
| 1338 | type: string |
| 1339 | ) { |
| 1340 | if (protocol === AI_ROUTER_PROTOCOLS.ANTHROPIC_MESSAGES) { |
| 1341 | writeAIGatewayAnthropicStreamError(res, new Error(message)); |
| 1342 | return; |
| 1343 | } |
| 1344 | |
| 1345 | if (res.writableEnded || res.destroyed) { |
| 1346 | return; |
| 1347 | } |
| 1348 | |
| 1349 | res.write( |
| 1350 | `data: ${JSON.stringify({ |
| 1351 | error: { |
| 1352 | message, |
| 1353 | type, |
| 1354 | }, |
| 1355 | })}\n\n` |
| 1356 | ); |
| 1357 | res.write('data: [DONE]\n\n'); |
| 1358 | res.end(); |
| 1359 | } |
| 1360 | |
| 1361 | async function createAIRouterRuntimeFailureLog(args: { |
| 1362 | workspaceId: string; |
no test coverage detected