(args: {
workspaceId: string;
routerId: string;
protocol: AIRouterProtocol;
statusCode: number;
errorType: string;
message: string;
duration: number;
})
| 1359 | } |
| 1360 | |
| 1361 | async function createAIRouterRuntimeFailureLog(args: { |
| 1362 | workspaceId: string; |
| 1363 | routerId: string; |
| 1364 | protocol: AIRouterProtocol; |
| 1365 | statusCode: number; |
| 1366 | errorType: string; |
| 1367 | message: string; |
| 1368 | duration: number; |
| 1369 | }) { |
| 1370 | try { |
| 1371 | const router = await prisma.aIRouter.findFirst({ |
| 1372 | where: { |
| 1373 | id: args.routerId, |
| 1374 | workspaceId: args.workspaceId, |
| 1375 | enabled: true, |
| 1376 | }, |
| 1377 | select: { |
| 1378 | id: true, |
| 1379 | }, |
| 1380 | }); |
| 1381 | |
| 1382 | if (!router) { |
| 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | await prisma.aIRouterLogs.create({ |
| 1387 | data: buildAIRouterLogData({ |
| 1388 | workspaceId: args.workspaceId, |
| 1389 | routerId: args.routerId, |
| 1390 | protocol: args.protocol, |
| 1391 | status: AIRouterLogsStatus.Failed, |
| 1392 | attempts: [], |
| 1393 | attemptErrors: [ |
| 1394 | compactObject({ |
| 1395 | statusCode: args.statusCode, |
| 1396 | retryable: false, |
| 1397 | errorType: args.errorType, |
| 1398 | message: args.message, |
| 1399 | }), |
| 1400 | ], |
| 1401 | duration: args.duration, |
| 1402 | }), |
| 1403 | }); |
| 1404 | } catch (error) { |
| 1405 | logger.warn('[ai-router] failed to write runtime failure log', error); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | function buildAIRouterLogData(args: { |
| 1410 | workspaceId: string; |
no test coverage detected