@evomap/evolver-core 2.0.0-beta.5 → 2.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ import { type AcquireLockOptions } from '../util/fileLock.js';
2
+ import { type WorkflowErrorClass, type WorkflowSpec } from './dsl.js';
3
+ export declare const WORKFLOW_RUN_SCHEMA_VERSION = 4;
4
+ export declare const WORKFLOW_DEFINITION_SCHEMA_VERSION = 1;
5
+ declare const WORKFLOW_CONTROL_SCHEMA_VERSION = 1;
6
+ export declare const MAX_WORKFLOW_HISTORY_EVENTS = 4096;
7
+ export declare const MAX_WORKFLOW_HISTORY_BYTES: number;
8
+ export type WorkflowRunStatus = 'queued' | 'pending' | 'running' | 'retry_wait' | 'pause_requested' | 'paused' | 'cancel_requested' | 'cancelled' | 'waiting_approval' | 'succeeded' | 'failed' | 'unsafe_to_resume';
9
+ export type WorkflowSafeErrorClass = WorkflowErrorClass | 'sensitive_output' | 'interrupted_non_idempotent' | 'invalid_control_flow' | 'invalid_output' | 'approval_rejected' | 'resource_limit';
10
+ export interface WorkflowStepState {
11
+ executionId: string;
12
+ stepId: string;
13
+ kind: 'script' | 'agent' | 'approval';
14
+ idempotency: 'idempotent' | 'non_idempotent';
15
+ status: 'pending' | 'running' | 'retry_wait' | 'waiting_approval' | 'succeeded' | 'failed';
16
+ attempts: number;
17
+ maxAttempts: number;
18
+ nextAttemptAt?: string;
19
+ lastErrorClass?: WorkflowSafeErrorClass;
20
+ output?: unknown;
21
+ startedAt?: string;
22
+ completedAt?: string;
23
+ }
24
+ export interface WorkflowApprovalState {
25
+ gateId: string;
26
+ executionId: string;
27
+ requestedAt: string;
28
+ }
29
+ export interface WorkflowRunState {
30
+ schemaVersion: typeof WORKFLOW_RUN_SCHEMA_VERSION;
31
+ workflowSchemaVersion: typeof WORKFLOW_DEFINITION_SCHEMA_VERSION;
32
+ workflowId: string;
33
+ definitionDigest: string;
34
+ runId: string;
35
+ workflowName: string;
36
+ status: WorkflowRunStatus;
37
+ spec: WorkflowSpec;
38
+ context: {
39
+ input: Record<string, unknown>;
40
+ steps: Record<string, unknown>;
41
+ };
42
+ steps: Record<string, WorkflowStepState>;
43
+ currentStep?: string;
44
+ approval?: WorkflowApprovalState;
45
+ lastErrorClass?: WorkflowSafeErrorClass;
46
+ createdAt: string;
47
+ updatedAt: string;
48
+ completedAt?: string;
49
+ }
50
+ export type WorkflowHistoryEventType = 'run_created' | 'run_queued' | 'run_started' | 'run_succeeded' | 'run_failed' | 'step_started' | 'step_retry_scheduled' | 'step_succeeded' | 'step_failed' | 'pause_requested' | 'paused' | 'resume_requested' | 'cancel_requested' | 'cancelled' | 'approval_waiting' | 'approval_approved' | 'approval_rejected' | 'recovery_started' | 'unsafe_to_resume';
51
+ export interface WorkflowHistoryEvent {
52
+ sequence: number;
53
+ eventId: string;
54
+ runId: string;
55
+ workflowId: string;
56
+ type: WorkflowHistoryEventType;
57
+ status: WorkflowRunStatus;
58
+ at: string;
59
+ executionId?: string;
60
+ stepId?: string;
61
+ gateId?: string;
62
+ attempt?: number;
63
+ actor?: string;
64
+ reason?: string;
65
+ errorClass?: WorkflowSafeErrorClass;
66
+ }
67
+ export type WorkflowHistoryEventInput = Omit<WorkflowHistoryEvent, 'sequence' | 'eventId'>;
68
+ export interface WorkflowOperatorOptions {
69
+ actor: string;
70
+ reason?: string;
71
+ }
72
+ export interface WorkflowOperatorRequest extends WorkflowOperatorOptions {
73
+ requestedAt: string;
74
+ }
75
+ export interface WorkflowApprovalDecision extends WorkflowOperatorRequest {
76
+ gateId: string;
77
+ executionId: string;
78
+ decision: 'approved' | 'rejected';
79
+ }
80
+ export interface WorkflowControlState {
81
+ schemaVersion: typeof WORKFLOW_CONTROL_SCHEMA_VERSION;
82
+ pause?: WorkflowOperatorRequest;
83
+ cancel?: WorkflowOperatorRequest;
84
+ approvals: Record<string, WorkflowApprovalDecision>;
85
+ }
86
+ export declare class WorkflowStateError extends Error {
87
+ readonly code: 'INVALID_ID' | 'INVALID_TRANSITION' | 'CORRUPT_STATE' | 'UNSUPPORTED_SCHEMA' | 'UNSAFE_PATH' | 'INSECURE_PERMISSIONS' | 'STATE_NOT_FOUND' | 'RESOURCE_LIMIT';
88
+ constructor(message: string, code: 'INVALID_ID' | 'INVALID_TRANSITION' | 'CORRUPT_STATE' | 'UNSUPPORTED_SCHEMA' | 'UNSAFE_PATH' | 'INSECURE_PERMISSIONS' | 'STATE_NOT_FOUND' | 'RESOURCE_LIMIT');
89
+ }
90
+ export declare function assertStableId(value: string, label: string): void;
91
+ export declare function findWorkflowJsonViolation(value: unknown): string | null;
92
+ export declare function deriveWorkflowDefinitionDigest(spec: WorkflowSpec): string;
93
+ export interface WorkflowStateStoreOptions {
94
+ lock?: AcquireLockOptions;
95
+ maxHistoryEvents?: number;
96
+ maxHistoryBytes?: number;
97
+ /** Runs synchronously under the per-run commit lock; must not call back into this store. */
98
+ onTransactionPhase?: (context: WorkflowTransactionPhaseContext) => void;
99
+ }
100
+ export type WorkflowTransactionPhase = 'wal_persisted' | 'state_projected' | 'control_projected' | 'history_projected' | 'before_wal_clear';
101
+ export interface WorkflowTransactionPhaseContext {
102
+ runId: string;
103
+ transactionId: string;
104
+ mode: 'commit' | 'replay';
105
+ phase: WorkflowTransactionPhase;
106
+ }
107
+ export interface WorkflowControlPatch {
108
+ pause?: WorkflowOperatorRequest | null;
109
+ cancel?: WorkflowOperatorRequest | null;
110
+ }
111
+ export declare class WorkflowStateStore {
112
+ private readonly options;
113
+ readonly root: string;
114
+ private readonly maxHistoryEvents;
115
+ private readonly maxHistoryBytes;
116
+ constructor(root: string, options?: WorkflowStateStoreOptions);
117
+ ensureConcurrencyLimit(limit: number): number;
118
+ tryAcquireConcurrencySlot(limit: number): number | null;
119
+ releaseConcurrencySlot(slot: number): void;
120
+ private concurrencySlotPath;
121
+ statePath(runId: string): string;
122
+ private controlPath;
123
+ private historyPath;
124
+ private commitLockPath;
125
+ private legacyControlLockPath;
126
+ private legacyHistoryLockPath;
127
+ private transactionPath;
128
+ lockPath(runId: string): string;
129
+ withRunLock<T>(runId: string, fn: () => T): T;
130
+ acquireRunLock(runId: string): void;
131
+ releaseRunLock(runId: string): void;
132
+ readStored(runId: string): WorkflowRunState;
133
+ private readStoredUnlocked;
134
+ private readOptionalStoredUnlocked;
135
+ read(runId: string): WorkflowRunState;
136
+ listRunIds(): string[];
137
+ list(): WorkflowRunState[];
138
+ write(state: WorkflowRunState): void;
139
+ commit(state: WorkflowRunState, history?: WorkflowHistoryEventInput[], controlPatch?: WorkflowControlPatch): WorkflowHistoryEvent[];
140
+ /** Commit a completion only when no durable cancellation won the commit-lock race. */
141
+ commitUnlessCancelled(state: WorkflowRunState, history?: WorkflowHistoryEventInput[]): WorkflowOperatorRequest | undefined;
142
+ /** Last-resort state/control projection when bounded or corrupt history prevents a safety transition. */
143
+ commitSafetyState(state: WorkflowRunState, controlPatch?: WorkflowControlPatch): void;
144
+ readControl(runId: string): WorkflowControlState;
145
+ private readControlUnlocked;
146
+ requestPause(runId: string, options: WorkflowOperatorOptions, requestedAt?: string): void;
147
+ requestPauseWithHistory(runId: string, options: WorkflowOperatorOptions, requestedAt?: string): void;
148
+ clearPauseRequest(runId: string): void;
149
+ requestCancel(runId: string, options: WorkflowOperatorOptions, requestedAt?: string): void;
150
+ requestCancelWithHistory(runId: string, options: WorkflowOperatorOptions, requestedAt?: string): void;
151
+ clearCancelRequest(runId: string): void;
152
+ approve(runId: string, gateId: string, options: WorkflowOperatorOptions, requestedAt?: string): void;
153
+ reject(runId: string, gateId: string, options: WorkflowOperatorOptions, requestedAt?: string): void;
154
+ private decideApproval;
155
+ appendHistory(input: WorkflowHistoryEventInput): WorkflowHistoryEvent;
156
+ readHistory(runId: string): WorkflowHistoryEvent[];
157
+ history(runId: string): WorkflowHistoryEvent[];
158
+ private readHistoryUnlocked;
159
+ private transact;
160
+ private transactSelected;
161
+ private requestControl;
162
+ private requestControlOnly;
163
+ private persistTransactionUnlocked;
164
+ private replayTransactionUnlocked;
165
+ private readTransactionUnlocked;
166
+ private applyTransactionUnlocked;
167
+ private assertProjectionBase;
168
+ private notifyTransactionPhase;
169
+ private patchControl;
170
+ private withCommitLock;
171
+ }
172
+ export {};