MCPcopy Index your code
hub / github.com/TanStack/ai / upsertRun

Method upsertRun

packages/ai-client/src/devtools.ts:1463–1503  ·  view source on GitHub ↗
(runId: string, patch: GenerationRunPatch<TOutput>)

Source from the content-addressed store, hash-verified

1461 }
1462
1463 protected upsertRun(runId: string, patch: GenerationRunPatch<TOutput>): void {
1464 const now = Date.now()
1465 const index = this.devtoolsRuns.findIndex((run) => run.id === runId)
1466 const existing = index >= 0 ? this.devtoolsRuns[index] : undefined
1467 const next: AIDevtoolsGenerationRunSnapshot<TOutput> = existing
1468 ? { ...existing }
1469 : {
1470 id: runId,
1471 input: this.getCoreState().input,
1472 result: null,
1473 preview: this.createPreview(null),
1474 progress: null,
1475 status: 'idle',
1476 isLoading: false,
1477 startedAt: now,
1478 updatedAt: now,
1479 }
1480
1481 if ('input' in patch) next.input = patch.input ?? null
1482 if ('result' in patch) next.result = patch.result ?? null
1483 if (patch.preview) next.preview = patch.preview
1484 if ('progress' in patch) next.progress = patch.progress ?? null
1485 if (patch.status) next.status = patch.status
1486 if ('isLoading' in patch) next.isLoading = patch.isLoading === true
1487 if (patch.completedAt !== undefined) next.completedAt = patch.completedAt
1488 if (patch.clearError) delete next.error
1489 if (patch.error !== undefined) next.error = patch.error
1490 next.updatedAt = now
1491
1492 if (index >= 0) {
1493 this.devtoolsRuns = this.devtoolsRuns.map((run) =>
1494 run.id === runId ? next : run,
1495 )
1496 } else {
1497 this.devtoolsRuns = [...this.devtoolsRuns, next]
1498 }
1499
1500 if (this.devtoolsRuns.length > this.maxRuns) {
1501 this.devtoolsRuns = this.devtoolsRuns.slice(-this.maxRuns)
1502 }
1503 }
1504
1505 protected renameRun(previousRunId: string, nextRunId: string): void {
1506 if (previousRunId === nextRunId) return

Callers 4

beginRunMethod · 0.95
ensureRunStartedMethod · 0.95
finishRunMethod · 0.95
updateActiveRunMethod · 0.95

Calls 2

createPreviewMethod · 0.95
nowMethod · 0.80

Tested by

no test coverage detected