mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Refactor AI query logging to handle serialization errors gracefully and improve async task management
This commit is contained in:
parent
2e78347464
commit
0cedc495d7
@ -51,7 +51,7 @@ export function handleStreamMode(ctx: ModeContext & {
|
||||
text,
|
||||
usage,
|
||||
providerMetadata,
|
||||
openrouterGenerationId: response?.id,
|
||||
openrouterGenerationId: response.id,
|
||||
});
|
||||
logIfMcpToolCall({
|
||||
mcpCallMetadata,
|
||||
@ -142,7 +142,7 @@ export async function handleGenerateMode(ctx: ModeContext & {
|
||||
text: result.text,
|
||||
usage: result.usage,
|
||||
providerMetadata: result.providerMetadata,
|
||||
openrouterGenerationId: result.response?.id,
|
||||
openrouterGenerationId: result.response.id,
|
||||
});
|
||||
|
||||
const responseConversationId = mcpCallMetadata != null ? conversationIdForLog : undefined;
|
||||
|
||||
@ -142,7 +142,7 @@ export function logAiQuerySuccess(args: {
|
||||
inputTokens: usage.inputTokens ?? undefined,
|
||||
outputTokens: usage.outputTokens ?? undefined,
|
||||
cachedInputTokens: extractCachedTokens(providerMetadata),
|
||||
cacheCreationTokens: usage.inputTokenDetails?.cacheWriteTokens ?? undefined,
|
||||
cacheCreationTokens: usage.inputTokenDetails.cacheWriteTokens ?? undefined,
|
||||
costUsd: rawCost.costUsd ?? extractOpenRouterCost(providerMetadata),
|
||||
cacheDiscountUsd: undefined, // backfilled by refineGenerationCost below
|
||||
openrouterGenerationId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user