import { type RuntimeQuery, type RuntimeProjection } from './runtime-compact-query.js'; import { type RuntimeOutcome, type RuntimeStoppedAction } from './runtime-action.js'; import { type RuntimeValue } from './runtime-json.js'; import type { RuntimeStore } from './runtime-store.js'; import { type DefineWorkflowOptions } from './workflow-definition.js'; import type { RuntimeEvidenceValidator, RuntimeCommandValidator, RuntimeExecutor, RuntimeInvocationContext, RuntimeValidator, RuntimeStateValidator, WorkflowRef, WorkflowRun, WorkflowTransitionHandler } from './workflow-run.js'; export interface CreateRuntimeOptions { store: RuntimeStore; workflows: readonly DefineWorkflowOptions[]; validators?: readonly RuntimeValidator[]; stateValidators?: readonly RuntimeStateValidator[]; executors?: readonly RuntimeExecutor[]; transitionHandlers?: readonly WorkflowTransitionHandler[]; evidenceValidators?: readonly RuntimeEvidenceValidator[]; commandValidators?: readonly RuntimeCommandValidator[]; /** 应用的结果契约检查;不执行派发授权,拒绝时保留原结果与工件。 */ validateOutcome?: RuntimeValidator['validate']; /** 应用显式核对已提交结果后,可重走其声明的成功转移;原 Action 和回执保持不变。 */ validateRecovery?: (input: Parameters[0] & { proposalHash: string; }) => ReturnType; } interface RunCommand { runId: string; expectedRevision?: number; context?: RuntimeInvocationContext; } export interface StartRuntimeRun { runId?: string; workflow: WorkflowRef; input: unknown; initialState?: unknown; context?: RuntimeInvocationContext; } export interface ClaimRuntimeRunAction extends RunCommand { actionId: string; attempt: number; inputHash: string; executorId: string; sessionId?: string; claimToken?: string; capabilities?: readonly string[]; } export interface ResolveRuntimeWait extends RunCommand { waitId: string; proposalHash: string; decisionId: string; choice: string; /** 决定说明,只绑定此 Wait;省略时保持既有输出与重试语义。 */ reason?: string; } export interface DispatchRuntimeCommand extends RunCommand { expectedRevision: number; commandId: string; name: string; input: unknown; } export interface RecordRuntimeEvidence extends RunCommand { evidenceId: string; kind: string; ref: string; contentHash: string; submissionId: string; expectedRevision: number; } export type InvalidateRuntimeEvidence = RecordRuntimeEvidence; export interface RunRuntimeUntilBlocked { runId: string; executorId: string; /** 每次调用最多执行多少个 Action,默认 100;不限制单个执行器的耗时。 */ maxActions?: number; context?: RuntimeInvocationContext; } export type RuntimeStopReason = 'completed' | 'failed' | 'cancelled' | 'approval-required' | 'evidence-required' | 'execution-unknown' | 'action-in-flight' | 'executor-required' | 'action-limit' | 'idle'; export interface RuntimeProgress { reason: RuntimeStopReason; run: WorkflowRun; /** 本次调用已尝试执行的 Action 数,包括结果未知的执行。 */ actionsExecuted: number; } /** 返回对象省略已结束 Action 的累计输入;冷读取仍完整校验存储,证据由 inspect 返回。 */ export interface RuntimeCurrentRun { runId: string; revision: number; status: WorkflowRun['status']; sequence: number; workflow: WorkflowRun['workflow']; input: RuntimeValue; state?: RuntimeValue; reason?: string; actions: WorkflowRun['actions']; waits: WorkflowRun['waits']; evidenceWaits: NonNullable; outputs: WorkflowRun['outputs']; history: { actions: number; waits: number; evidenceWaits: number; }; } export interface RuntimeCurrentProgress extends Omit { run: RuntimeCurrentRun; } export declare function createRuntime(options: CreateRuntimeOptions): { start: (input: StartRuntimeRun) => Promise; dispatchCommand: (command: DispatchRuntimeCommand) => Promise; inspect: (runId: string) => Promise; inspectProjection: (runId: string) => Promise; query: (command: RuntimeQuery & { runId: string; }) => Promise; inspectCurrent: (runId: string) => Promise; executeCurrent: (command: RunCommand & { actionId: string; executorId: string; }) => Promise; runUntilBlockedCurrent: (command: RunRuntimeUntilBlocked) => Promise; next: (command: RunCommand) => Promise; claim: (command: ClaimRuntimeRunAction) => Promise; recordOutcome: (command: RunCommand & { outcome: RuntimeOutcome; }) => Promise; resolveWait: (command: ResolveRuntimeWait) => Promise; recordEvidence: (command: RecordRuntimeEvidence) => Promise; invalidateEvidence: (command: RecordRuntimeEvidence) => Promise; reviseWait: (command: RunCommand & { waitId: string; proposalHash: string; proposal: unknown; }) => Promise; cancel: (command: RunCommand & { reason: string; stoppedActions?: readonly RuntimeStoppedAction[]; }) => Promise; acknowledgeStopped: (command: RunCommand & { stoppedActions: readonly RuntimeStoppedAction[]; }) => Promise; markUnknown: (command: RunCommand & { actionId: string; attempt: number; reason: string; }) => Promise; retry: (command: RunCommand & { actionId: string; attempt: number; proposalHash?: string; reconciliation?: { resolution: "not-executed"; evidence: unknown; }; }) => Promise; execute: (command: RunCommand & { actionId: string; executorId: string; }) => Promise; runUntilBlocked: (command: RunRuntimeUntilBlocked) => Promise; }; export type WorkflowRuntime = ReturnType; export {}; //# sourceMappingURL=runtime-service.d.ts.map