(runId: string, patch: GenerationRunPatch<TOutput>)
| 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 |
no test coverage detected