import { type WorkflowDisplay, type WorkflowRunListPage, type WorkflowRunView, type WorkflowSessionRunView, type WorkflowSessionView } from "../client/view.js"; import type { StateDatabase } from "../state/database.js"; import { type JsonValue } from "../state/json.js"; import { type WorkflowMessage, type WorkflowMessageSummary } from "../state/workflow-messages.js"; import type { WorkflowRunQueueStore, WorkflowRunQueueRecord } from "../workflows/queue.js"; import type { WorkflowRunStore } from "../workflows/store.js"; import type { WorkflowRunState, WorkflowStepRecord } from "../workflows/types.js"; import type { ServerStateStore } from "./state.js"; export declare const WORKFLOW_PAGE_KINDS: readonly ["steps", "trace", "trace_at_step", "session_entries", "session_events", "settings", "follow_ups", "updates", "workflow_messages"]; export type WorkflowPageKind = (typeof WORKFLOW_PAGE_KINDS)[number]; type RunPageRequest = { kind: WorkflowPageKind; cursor: number; }; export declare class ServerViewStore { private readonly state; private readonly queue; private readonly serverState; private readonly runs; private readonly hasLiveRunner; private readonly hasActiveSessionTurn; private readonly contentRecords; private readonly listCache; private readonly runCache; private readonly sessionCache; private readonly selectionCache; private contentBytes; private activityRevision; private readonly workflowMessages; constructor(state: StateDatabase, queue: WorkflowRunQueueStore, serverState: ServerStateStore, runs: WorkflowRunStore, hasLiveRunner: (runId: string) => boolean, hasActiveSessionTurn: (targetSessionId: string) => boolean); noteWorkflowActivityChange(): void; list(cursor?: number, limit?: number): WorkflowRunListPage; run(runId: string): WorkflowRunView | null; page(runId: string, request: RunPageRequest): WorkflowRunView | null; private readRun; session(sessionId: string, coordinator?: { epoch: string; active: boolean; branchReportRequired: boolean; } | null, nodeCursor?: number): WorkflowSessionView; /** The one workflow message Pi must inspect, add, finish, or confirm next. */ currentWorkflowMessage(sessionId: string): WorkflowMessage | undefined; /** * Selection reads message metadata only. Content loads once, for the message * the session must act on. */ /** The one workflow message Pi must inspect, add, finish, or confirm next. */ private currentWorkflowMessageSummary; /** The retained terminal run the session view shows, or undefined. */ private retainedTerminalRunIdForView; /** * The selection and the retained terminal run of one session, held under the * indexed facts both depend on. The held result follows the item bound of the * view caches, so viewing many sessions cannot grow this map without limit, and a * repeat call over a session whose messages did not change reads no message row. */ private sessionSelection; /** * Whether a held selection still answers this session. A message inside the * terminal retention window and a retained run both expire with the clock, not * with a stored write, so both are checked before the result is reused. */ private selectionHolds; /** * Whether a delivered terminal message is still inside its retention window. The * window closes with time and not with a stored write, so the held selection is * checked against the clock before it is reused. */ private retentionStillHolds; /** * The indexed facts the selection depends on: the message revision the database * maintains, the run and request revisions, the state of the session runs, and the * open turns of the session. */ private selectionKey; /** * The count and state of the session runs. Eligibility also depends on whether a * run is paused and whether its status is terminal, so the selection key covers * those facts without reading any message. */ private sessionRunsRevision; /** Walk the session message metadata for the one message Pi must act on. */ private selectWorkflowMessageSummary; /** * Walk one session's message metadata in bounded batches, in durable order or * newest first, with the named candidate filter for that step. The caller stops * at the first message it needs. */ private walkSessionSummaries; /** Whether Pi still owes delivery confirmation or a model turn for this message. */ private needsPiWork; private currentInteraction; private sessionMessage; /** * The number of message writes this session has seen. The database maintains it, * so the session view cache key notices every insert, update, and delete without * reading the session's stored messages. */ private sessionMessageRevision; private openTurnRevision; /** * Bounded current run projection for Pi. It carries the semantic facts for the * status line and widget and leaves complete history to the detailed view. */ sessionRun(runId: string, nodeCursor?: number): WorkflowSessionRunView | null; /** * One row per definition node, in definition order. Attempt facts come from * durable attempts so the rows stay correct for long histories. Detailed text * travels only for the current, waiting, and most recent failed node. */ private sessionNodeRows; private readAttemptError; /** The last node that did not finish cleanly, in completion order. */ private sessionFailureNodeId; clearTerminal(sessionId: string, runId?: string, now?: number): string | null; content(runId: string, contentPath: string, offset: number): JsonValue | null; private projectStep; private projectTraceEvent; private projectSessionEntry; private projectSessionEvent; private projectUpdate; private projectReplayCheckpoint; private projectRecordField; private projectState; private projectWorkflow; private projectWorkflowNode; private projectDisplay; private projectValue; private registerContent; private rememberContent; private recoverContent; clearConnection(_connectionId: string): void; /** The retained terminal run of one session, if the session view shows one. */ private retainedTerminalRunId; /** * The retained terminal run of one session, with the moment its retention window * closes. A run kept by a waiting message or a triggering turn has no such moment, * because its state and not the clock holds it. */ private retainedTerminalForView; hasCancelledSource(message: WorkflowMessageSummary): boolean; private isMessageEligible; private openWorkflowMessage; private workflowActivityRevision; private display; private hasActivity; private pendingRequestKind; private requestDeliveryConfirmed; private hasAmbiguousEffect; private runVersion; private pendingSessionRevision; private presentationRevision; } export type WorkflowDisplayFacts = { queueStatus: WorkflowRunQueueRecord["status"]; durableStatus: WorkflowRunState["status"] | undefined; paused: boolean; ambiguous: boolean; runnerActive: boolean; originTurnActive: boolean; pendingRequestKind: "agent" | "assistant" | "checkpoint" | "decision" | null; requestDeliveryConfirmed: boolean; errorMessage: string | null; }; export declare function reduceWorkflowDisplay(facts: WorkflowDisplayFacts): WorkflowDisplay; export declare function toCompactStepJson(step: WorkflowStepRecord): JsonValue; export declare function workflowPageStart(total: number, cursor?: number): number; export {};