MCPcopy Create free account
hub / github.com/TanStack/ai / onFinish

Function onFinish

packages/ai-event-client/src/devtools-middleware.ts:521–546  ·  view source on GitHub ↗
(ctx, info)

Source from the content-addressed store, hash-verified

519 },
520
521 onFinish(ctx, info) {
522 const now = Date.now()
523
524 // Emit completed for the final iteration
525 if (currentIteration >= 0) {
526 safeEmit('text:iteration:completed', {
527 ...buildEventContext(ctx),
528 iteration: currentIteration,
529 messageId: localMessageId || undefined,
530 duration: now - iterationStartTime,
531 finishReason: info.finishReason || undefined,
532 usage: info.usage,
533 timestamp: now,
534 })
535 }
536
537 safeEmit('text:request:completed', {
538 ...buildEventContext(ctx),
539 content: info.content,
540 messageId: localMessageId || undefined,
541 finishReason: info.finishReason || undefined,
542 usage: info.usage,
543 duration: info.duration,
544 timestamp: now,
545 })
546 },
547 }
548}

Callers

nothing calls this directly

Calls 3

safeEmitFunction · 0.85
buildEventContextFunction · 0.85
nowMethod · 0.80

Tested by

no test coverage detected