|
| 1 | +import type { JsonValue } from "./json-types.js"; |
| 2 | +import type { WorkflowStore } from "./workflow-store.js"; |
| 3 | +import { |
| 4 | + ACTIVE_WORKFLOW_STATUSES, |
| 5 | + buildWorkflowRunView, |
| 6 | + loadWorkflowProjectView, |
| 7 | + type WorkflowCallCounts, |
| 8 | + type WorkflowProjectView, |
| 9 | + type WorkflowRunView, |
| 10 | +} from "./workflow-view.js"; |
| 11 | + |
| 12 | +export interface WorkflowRunSummaryView { |
| 13 | + id: string; |
| 14 | + name: string; |
| 15 | + status: WorkflowRunView["status"]; |
| 16 | + currentPhase?: string; |
| 17 | + calls: WorkflowCallCounts; |
| 18 | + updatedAt: string; |
| 19 | +} |
| 20 | + |
| 21 | +export interface WorkflowCallDetailView { |
| 22 | + runId: string; |
| 23 | + callIndex: number; |
| 24 | + status: string; |
| 25 | + provider: string; |
| 26 | + model?: string; |
| 27 | + effort?: string; |
| 28 | + label?: string; |
| 29 | + phase?: string; |
| 30 | + prompt: string; |
| 31 | + schema?: JsonValue | string; |
| 32 | + responseText?: string; |
| 33 | + structured?: JsonValue | string; |
| 34 | + error?: string; |
| 35 | + errorKind?: string; |
| 36 | + providerSessionId?: string; |
| 37 | + isolation: "shared" | "worktree"; |
| 38 | + worktreePath?: string; |
| 39 | + dirty?: boolean; |
| 40 | + fromCache: boolean; |
| 41 | + replayMatch?: "same_index" | "compatible_key"; |
| 42 | + replayedFromRunId?: string; |
| 43 | + replayedFromCallIndex?: number; |
| 44 | + replayReason?: string; |
| 45 | + createdAt: string; |
| 46 | + startedAt?: string; |
| 47 | + completedAt?: string; |
| 48 | + updatedAt: string; |
| 49 | +} |
| 50 | + |
| 51 | +export function loadActiveWorkflowSummaries( |
| 52 | + store: WorkflowStore, |
| 53 | + workspaceRoot: string, |
| 54 | +): WorkflowRunSummaryView[] { |
| 55 | + return loadWorkflowProjectView(store, workspaceRoot, { |
| 56 | + statuses: [...ACTIVE_WORKFLOW_STATUSES], |
| 57 | + limit: 50, |
| 58 | + eventLimit: 50, |
| 59 | + }).runs.map(summarizeWorkflowRun); |
| 60 | +} |
| 61 | + |
| 62 | +export function loadWorkflowUiProject( |
| 63 | + store: WorkflowStore, |
| 64 | + workspaceRoot: string, |
| 65 | +): WorkflowProjectView { |
| 66 | + return loadWorkflowProjectView(store, workspaceRoot, { |
| 67 | + statuses: [...ACTIVE_WORKFLOW_STATUSES], |
| 68 | + limit: 50, |
| 69 | + eventLimit: 100, |
| 70 | + }); |
| 71 | +} |
| 72 | + |
| 73 | +export function loadWorkflowUiRun( |
| 74 | + store: WorkflowStore, |
| 75 | + runId: string, |
| 76 | +): WorkflowRunView | undefined { |
| 77 | + const run = store.getRun(runId); |
| 78 | + if (!run) return undefined; |
| 79 | + return buildWorkflowRunView( |
| 80 | + run, |
| 81 | + store.listAgentCalls(run.id), |
| 82 | + store.listEvents(run.id, 100), |
| 83 | + ); |
| 84 | +} |
| 85 | + |
| 86 | +export function loadWorkflowUiCallDetail( |
| 87 | + store: WorkflowStore, |
| 88 | + runId: string, |
| 89 | + callIndex: number, |
| 90 | +): WorkflowCallDetailView | undefined { |
| 91 | + const call = store.getAgentCall(runId, callIndex); |
| 92 | + if (!call) return undefined; |
| 93 | + return { |
| 94 | + runId, |
| 95 | + callIndex, |
| 96 | + status: call.status, |
| 97 | + provider: call.provider, |
| 98 | + model: call.model, |
| 99 | + effort: call.effort, |
| 100 | + label: call.label, |
| 101 | + phase: call.phase, |
| 102 | + prompt: call.prompt, |
| 103 | + schema: parseStoredJson(call.schemaJson), |
| 104 | + responseText: call.responseText, |
| 105 | + structured: parseStoredJson(call.structuredJson), |
| 106 | + error: call.error, |
| 107 | + errorKind: call.errorKind, |
| 108 | + providerSessionId: call.providerSessionId, |
| 109 | + isolation: call.isolation, |
| 110 | + worktreePath: call.worktreePath, |
| 111 | + dirty: call.dirty, |
| 112 | + fromCache: call.fromCache, |
| 113 | + replayMatch: call.replayMatch, |
| 114 | + replayedFromRunId: call.replayedFromRunId, |
| 115 | + replayedFromCallIndex: call.replayedFromCallIndex, |
| 116 | + replayReason: call.replayReason, |
| 117 | + createdAt: call.createdAt, |
| 118 | + startedAt: call.startedAt, |
| 119 | + completedAt: call.completedAt, |
| 120 | + updatedAt: call.updatedAt, |
| 121 | + }; |
| 122 | +} |
| 123 | + |
| 124 | +export function summarizeWorkflowRun(run: WorkflowRunView): WorkflowRunSummaryView { |
| 125 | + return { |
| 126 | + id: run.id, |
| 127 | + name: run.name, |
| 128 | + status: run.status, |
| 129 | + currentPhase: run.currentPhase, |
| 130 | + calls: run.calls, |
| 131 | + updatedAt: run.updatedAt, |
| 132 | + }; |
| 133 | +} |
| 134 | + |
| 135 | +function parseStoredJson(value: string | undefined): JsonValue | string | undefined { |
| 136 | + if (value === undefined) return undefined; |
| 137 | + try { |
| 138 | + return JSON.parse(value) as JsonValue; |
| 139 | + } catch { |
| 140 | + return value; |
| 141 | + } |
| 142 | +} |
0 commit comments