@exaudeus/workrail 2.1.0 → 3.1.0

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.
Files changed (61) hide show
  1. package/dist/application/services/compiler/resolve-templates.d.ts +5 -0
  2. package/dist/application/services/compiler/resolve-templates.js +35 -0
  3. package/dist/application/services/compiler/routine-loader.d.ts +11 -0
  4. package/dist/application/services/compiler/routine-loader.js +45 -0
  5. package/dist/application/services/compiler/template-registry.d.ts +4 -2
  6. package/dist/application/services/compiler/template-registry.js +105 -4
  7. package/dist/application/services/workflow-compiler.js +34 -3
  8. package/dist/di/container.js +10 -1
  9. package/dist/di/tokens.d.ts +1 -0
  10. package/dist/di/tokens.js +1 -0
  11. package/dist/engine/engine-factory.d.ts +3 -0
  12. package/dist/engine/engine-factory.js +295 -0
  13. package/dist/engine/index.d.ts +3 -0
  14. package/dist/engine/index.js +12 -0
  15. package/dist/engine/types.d.ts +130 -0
  16. package/dist/engine/types.js +18 -0
  17. package/dist/manifest.json +146 -74
  18. package/dist/mcp/handlers/v2-checkpoint.d.ts +31 -1
  19. package/dist/mcp/handlers/v2-checkpoint.js +76 -64
  20. package/dist/mcp/handlers/v2-execution/continue-advance.d.ts +2 -0
  21. package/dist/mcp/handlers/v2-execution/continue-advance.js +5 -5
  22. package/dist/mcp/handlers/v2-execution/continue-rehydrate.d.ts +2 -0
  23. package/dist/mcp/handlers/v2-execution/continue-rehydrate.js +17 -22
  24. package/dist/mcp/handlers/v2-execution/index.d.ts +10 -17
  25. package/dist/mcp/handlers/v2-execution/index.js +44 -54
  26. package/dist/mcp/handlers/v2-execution/replay.d.ts +4 -15
  27. package/dist/mcp/handlers/v2-execution/replay.js +52 -128
  28. package/dist/mcp/handlers/v2-execution/start.d.ts +3 -2
  29. package/dist/mcp/handlers/v2-execution/start.js +18 -46
  30. package/dist/mcp/handlers/v2-token-ops.d.ts +45 -24
  31. package/dist/mcp/handlers/v2-token-ops.js +372 -32
  32. package/dist/mcp/output-schemas.d.ts +104 -283
  33. package/dist/mcp/output-schemas.js +24 -22
  34. package/dist/mcp/server.js +8 -0
  35. package/dist/mcp/types.d.ts +4 -0
  36. package/dist/mcp/v2/tools.d.ts +22 -52
  37. package/dist/mcp/v2/tools.js +18 -32
  38. package/dist/mcp/v2-response-formatter.js +12 -16
  39. package/dist/runtime/runtime-mode.d.ts +2 -0
  40. package/dist/v2/durable-core/domain/prompt-renderer.d.ts +1 -0
  41. package/dist/v2/durable-core/domain/prompt-renderer.js +5 -3
  42. package/dist/v2/durable-core/schemas/export-bundle/index.d.ts +14 -14
  43. package/dist/v2/durable-core/schemas/session/events.d.ts +4 -4
  44. package/dist/v2/durable-core/schemas/session/validation-event.d.ts +2 -2
  45. package/dist/v2/durable-core/tokens/payloads.d.ts +32 -32
  46. package/dist/v2/durable-core/tokens/short-token.d.ts +38 -0
  47. package/dist/v2/durable-core/tokens/short-token.js +126 -0
  48. package/dist/v2/durable-core/tokens/token-patterns.d.ts +4 -0
  49. package/dist/v2/durable-core/tokens/token-patterns.js +9 -0
  50. package/dist/v2/infra/in-memory/token-alias-store/index.d.ts +11 -0
  51. package/dist/v2/infra/in-memory/token-alias-store/index.js +38 -0
  52. package/dist/v2/infra/local/data-dir/index.d.ts +1 -0
  53. package/dist/v2/infra/local/data-dir/index.js +3 -0
  54. package/dist/v2/infra/local/token-alias-store/index.d.ts +16 -0
  55. package/dist/v2/infra/local/token-alias-store/index.js +117 -0
  56. package/dist/v2/ports/data-dir.port.d.ts +1 -0
  57. package/dist/v2/ports/token-alias-store.port.d.ts +33 -0
  58. package/dist/v2/ports/token-alias-store.port.js +2 -0
  59. package/package.json +8 -1
  60. package/workflows/coding-task-workflow-agentic.lean.v2.json +41 -3
  61. package/workflows/examples/routine-injection-example.json +28 -0
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWorkRailEngine = createWorkRailEngine;
4
+ require("reflect-metadata");
5
+ const container_js_1 = require("../di/container.js");
6
+ const tokens_js_1 = require("../di/tokens.js");
7
+ const token_codec_ports_js_1 = require("../v2/durable-core/tokens/token-codec-ports.js");
8
+ const validation_js_1 = require("../application/validation.js");
9
+ const v1_to_v2_shim_js_1 = require("../v2/read-only/v1-to-v2-shim.js");
10
+ const feature_flags_js_1 = require("../config/feature-flags.js");
11
+ const index_js_1 = require("../v2/infra/local/data-dir/index.js");
12
+ const start_js_1 = require("../mcp/handlers/v2-execution/start.js");
13
+ const index_js_2 = require("../mcp/handlers/v2-execution/index.js");
14
+ const v2_checkpoint_js_1 = require("../mcp/handlers/v2-checkpoint.js");
15
+ const types_js_1 = require("./types.js");
16
+ async function safeAsync(fn) {
17
+ try {
18
+ return (0, types_js_1.engineOk)(await fn());
19
+ }
20
+ catch (e) {
21
+ return (0, types_js_1.engineErr)({
22
+ kind: 'storage_error',
23
+ message: e instanceof Error ? e.message : String(e),
24
+ });
25
+ }
26
+ }
27
+ function mapStartError(e) {
28
+ switch (e.kind) {
29
+ case 'workflow_not_found':
30
+ return { kind: 'workflow_not_found', workflowId: e.workflowId };
31
+ case 'workflow_has_no_steps':
32
+ return { kind: 'workflow_has_no_steps', workflowId: e.workflowId };
33
+ case 'workflow_compile_failed':
34
+ return { kind: 'workflow_compile_failed', message: e.message };
35
+ case 'token_signing_failed':
36
+ return { kind: 'token_signing_failed', message: String(e.cause) };
37
+ case 'prompt_render_failed':
38
+ return { kind: 'prompt_render_failed', message: e.message };
39
+ case 'precondition_failed':
40
+ return { kind: 'precondition_failed', message: e.message };
41
+ case 'invariant_violation':
42
+ return { kind: 'internal_error', message: e.message };
43
+ case 'validation_failed':
44
+ return { kind: 'validation_failed', message: e.failure.message };
45
+ case 'keyring_load_failed':
46
+ return { kind: 'internal_error', message: e.cause.message, code: e.cause.code };
47
+ case 'hash_computation_failed':
48
+ return { kind: 'internal_error', message: e.message };
49
+ case 'pinned_workflow_store_failed':
50
+ return { kind: 'storage_error', message: e.cause.message, code: e.cause.code };
51
+ case 'snapshot_creation_failed':
52
+ return { kind: 'storage_error', message: e.cause.message, code: e.cause.code };
53
+ case 'session_append_failed':
54
+ return { kind: 'session_error', message: e.cause.message, code: e.cause.code };
55
+ }
56
+ }
57
+ function mapContinueError(e) {
58
+ switch (e.kind) {
59
+ case 'precondition_failed':
60
+ return { kind: 'precondition_failed', message: e.message };
61
+ case 'token_unknown_node':
62
+ return { kind: 'token_invalid', message: e.message };
63
+ case 'invariant_violation':
64
+ return { kind: 'internal_error', message: e.message };
65
+ case 'validation_failed':
66
+ return { kind: 'validation_failed', message: e.failure.message };
67
+ case 'token_decode_failed':
68
+ return { kind: 'token_invalid', message: e.cause.message, code: e.cause.code };
69
+ case 'token_verify_failed':
70
+ return { kind: 'token_invalid', message: e.cause.message, code: e.cause.code };
71
+ case 'keyring_load_failed':
72
+ return { kind: 'internal_error', message: e.cause.message, code: e.cause.code };
73
+ case 'session_load_failed':
74
+ return { kind: 'session_error', message: e.cause.message, code: e.cause.code };
75
+ case 'snapshot_load_failed':
76
+ return { kind: 'storage_error', message: e.cause.message, code: e.cause.code };
77
+ case 'pinned_workflow_store_failed':
78
+ return { kind: 'storage_error', message: e.cause.message, code: e.cause.code };
79
+ case 'pinned_workflow_missing':
80
+ return { kind: 'storage_error', message: `Pinned workflow missing: ${e.workflowHash}` };
81
+ case 'token_signing_failed':
82
+ return { kind: 'token_signing_failed', message: String(e.cause) };
83
+ case 'advance_execution_failed':
84
+ return { kind: 'session_error', message: e.cause.message, code: e.cause.code };
85
+ case 'prompt_render_failed':
86
+ return { kind: 'prompt_render_failed', message: e.message };
87
+ }
88
+ }
89
+ function mapCheckpointError(e) {
90
+ switch (e.kind) {
91
+ case 'precondition_failed':
92
+ return { kind: 'precondition_failed', message: e.message };
93
+ case 'token_signing_failed':
94
+ return { kind: 'token_signing_failed', message: String(e.cause) };
95
+ case 'validation_failed':
96
+ return { kind: 'validation_failed', message: e.failure.message };
97
+ case 'missing_node_or_run':
98
+ return { kind: 'session_error', message: 'Node or run not found in session events' };
99
+ case 'event_schema_invalid':
100
+ return { kind: 'internal_error', message: `Event schema invalid: ${e.issues}` };
101
+ case 'gate_failed':
102
+ return { kind: 'session_error', message: e.cause.message, code: e.cause.code };
103
+ case 'store_failed':
104
+ return { kind: 'storage_error', message: e.cause.message, code: e.cause.code };
105
+ }
106
+ }
107
+ function mapPending(raw) {
108
+ if (!raw)
109
+ return null;
110
+ return {
111
+ stepId: raw.stepId,
112
+ title: raw.title,
113
+ prompt: raw.prompt,
114
+ ...(raw.agentRole ? { agentRole: raw.agentRole } : {}),
115
+ };
116
+ }
117
+ function mapStartOutput(out) {
118
+ const ct = out.continueToken ?? '';
119
+ return {
120
+ kind: 'ok',
121
+ stateToken: (0, types_js_1.asStateToken)(ct),
122
+ ackToken: (0, types_js_1.asAckToken)(ct),
123
+ checkpointToken: out.checkpointToken ? (0, types_js_1.asCheckpointToken)(out.checkpointToken) : null,
124
+ isComplete: out.isComplete,
125
+ pending: mapPending(out.pending),
126
+ preferences: out.preferences,
127
+ nextIntent: out.nextIntent,
128
+ };
129
+ }
130
+ function mapContinueOutput(out) {
131
+ const ct = out.continueToken ?? '';
132
+ const base = {
133
+ stateToken: (0, types_js_1.asStateToken)(ct),
134
+ ackToken: (0, types_js_1.asAckToken)(ct),
135
+ checkpointToken: out.checkpointToken ? (0, types_js_1.asCheckpointToken)(out.checkpointToken) : null,
136
+ isComplete: out.isComplete,
137
+ pending: mapPending(out.pending),
138
+ preferences: out.preferences,
139
+ nextIntent: out.nextIntent,
140
+ };
141
+ if (out.kind === 'blocked') {
142
+ const blocked = {
143
+ kind: 'blocked',
144
+ ...base,
145
+ blockers: out.blockers.blockers.map(b => ({
146
+ code: b.code,
147
+ message: b.message,
148
+ ...(b.suggestedFix ? { suggestedFix: b.suggestedFix } : {}),
149
+ })),
150
+ retryable: out.retryable ?? false,
151
+ retryAckToken: out.retryContinueToken ? (0, types_js_1.asAckToken)(out.retryContinueToken) : null,
152
+ };
153
+ return blocked;
154
+ }
155
+ return { kind: 'ok', ...base };
156
+ }
157
+ let engineActive = false;
158
+ async function createWorkRailEngine(config = {}) {
159
+ if (engineActive) {
160
+ return (0, types_js_1.engineErr)({
161
+ kind: 'precondition_failed',
162
+ message: 'An engine is already active. Call engine.close() before creating another instance.',
163
+ });
164
+ }
165
+ await (0, container_js_1.initializeContainer)({ runtimeMode: { kind: 'library' } });
166
+ if (config.dataDir) {
167
+ const customEnv = { ...process.env, WORKRAIL_DATA_DIR: config.dataDir };
168
+ container_js_1.container.register(tokens_js_1.DI.V2.DataDir, { useValue: new index_js_1.LocalDataDirV2(customEnv) });
169
+ }
170
+ const workflowService = container_js_1.container.resolve(tokens_js_1.DI.Services.Workflow);
171
+ const gate = container_js_1.container.resolve(tokens_js_1.DI.V2.ExecutionGate);
172
+ const sessionStore = container_js_1.container.resolve(tokens_js_1.DI.V2.SessionStore);
173
+ const snapshotStore = container_js_1.container.resolve(tokens_js_1.DI.V2.SnapshotStore);
174
+ const pinnedStore = container_js_1.container.resolve(tokens_js_1.DI.V2.PinnedWorkflowStore);
175
+ const keyringPort = container_js_1.container.resolve(tokens_js_1.DI.V2.Keyring);
176
+ const keyringResult = await keyringPort.loadOrCreate();
177
+ if (keyringResult.isErr()) {
178
+ (0, container_js_1.resetContainer)();
179
+ return (0, types_js_1.engineErr)({
180
+ kind: 'internal_error',
181
+ message: keyringResult.error.message,
182
+ code: keyringResult.error.code,
183
+ });
184
+ }
185
+ const sha256 = container_js_1.container.resolve(tokens_js_1.DI.V2.Sha256);
186
+ const crypto = container_js_1.container.resolve(tokens_js_1.DI.V2.Crypto);
187
+ const entropy = container_js_1.container.resolve(tokens_js_1.DI.V2.RandomEntropy);
188
+ const hmac = container_js_1.container.resolve(tokens_js_1.DI.V2.HmacSha256);
189
+ const base64url = container_js_1.container.resolve(tokens_js_1.DI.V2.Base64Url);
190
+ const base32 = container_js_1.container.resolve(tokens_js_1.DI.V2.Base32);
191
+ const bech32m = container_js_1.container.resolve(tokens_js_1.DI.V2.Bech32m);
192
+ const idFactory = container_js_1.container.resolve(tokens_js_1.DI.V2.IdFactory);
193
+ const tokenCodecPorts = (0, token_codec_ports_js_1.unsafeTokenCodecPorts)({
194
+ keyring: keyringResult.value,
195
+ hmac,
196
+ base64url,
197
+ base32,
198
+ bech32m,
199
+ });
200
+ const validationEngine = container_js_1.container.resolve(tokens_js_1.DI.Infra.ValidationEngine);
201
+ const compiler = container_js_1.container.resolve(tokens_js_1.DI.Services.WorkflowCompiler);
202
+ const validationPipelineDeps = {
203
+ schemaValidate: validation_js_1.validateWorkflowSchema,
204
+ structuralValidate: validationEngine.validateWorkflowStructureOnly.bind(validationEngine),
205
+ compiler,
206
+ normalizeToExecutable: v1_to_v2_shim_js_1.normalizeV1WorkflowToPinnedSnapshot,
207
+ };
208
+ const dataDir = container_js_1.container.resolve(tokens_js_1.DI.V2.DataDir);
209
+ const tokenAliasStore = container_js_1.container.resolve(tokens_js_1.DI.V2.TokenAliasStore);
210
+ const aliasLoadResult = await tokenAliasStore.loadIndex();
211
+ if (aliasLoadResult.isErr()) {
212
+ console.error(`[engine-factory] Token alias index load warning: ${aliasLoadResult.error.message}`);
213
+ }
214
+ const v2 = {
215
+ gate,
216
+ sessionStore,
217
+ snapshotStore,
218
+ pinnedStore,
219
+ sha256,
220
+ crypto,
221
+ entropy,
222
+ idFactory,
223
+ tokenCodecPorts,
224
+ tokenAliasStore,
225
+ validationPipelineDeps,
226
+ resolvedRootUris: [],
227
+ dataDir,
228
+ };
229
+ const featureFlags = new feature_flags_js_1.StaticFeatureFlagProvider({ v2Tools: true });
230
+ const ctx = {
231
+ workflowService,
232
+ featureFlags,
233
+ sessionManager: null,
234
+ httpServer: null,
235
+ v2,
236
+ };
237
+ const v2Ctx = ctx;
238
+ engineActive = true;
239
+ const engine = {
240
+ async startWorkflow(workflowId) {
241
+ const result = await (0, start_js_1.executeStartWorkflow)({ workflowId }, v2Ctx);
242
+ if (result.isErr()) {
243
+ return (0, types_js_1.engineErr)(mapStartError(result.error));
244
+ }
245
+ return (0, types_js_1.engineOk)(mapStartOutput(result.value));
246
+ },
247
+ async continueWorkflow(stateToken, ackToken, output, context) {
248
+ const intent = ackToken ? 'advance' : 'rehydrate';
249
+ const input = {
250
+ continueToken: (0, types_js_1.unwrapToken)(stateToken),
251
+ intent: intent,
252
+ ...(output ? {
253
+ output: {
254
+ notesMarkdown: output.notesMarkdown,
255
+ ...(output.artifacts?.length ? { artifacts: [...output.artifacts] } : {}),
256
+ },
257
+ } : {}),
258
+ ...(context ? { context } : {}),
259
+ };
260
+ const result = await (0, index_js_2.executeContinueWorkflow)(input, v2Ctx);
261
+ if (result.isErr()) {
262
+ return (0, types_js_1.engineErr)(mapContinueError(result.error));
263
+ }
264
+ return (0, types_js_1.engineOk)(mapContinueOutput(result.value));
265
+ },
266
+ async checkpointWorkflow(checkpointToken) {
267
+ const result = await (0, v2_checkpoint_js_1.executeCheckpoint)({ checkpointToken: (0, types_js_1.unwrapToken)(checkpointToken) }, v2Ctx);
268
+ if (result.isErr()) {
269
+ return (0, types_js_1.engineErr)(mapCheckpointError(result.error));
270
+ }
271
+ return (0, types_js_1.engineOk)({
272
+ checkpointNodeId: result.value.checkpointNodeId,
273
+ stateToken: (0, types_js_1.asStateToken)(result.value.stateToken),
274
+ });
275
+ },
276
+ async listWorkflows() {
277
+ const result = await safeAsync(() => workflowService.listWorkflowSummaries());
278
+ if (!result.ok)
279
+ return result;
280
+ return (0, types_js_1.engineOk)({
281
+ workflows: result.value.map((s) => ({
282
+ workflowId: s.id,
283
+ name: s.name,
284
+ description: s.description,
285
+ version: s.version,
286
+ })),
287
+ });
288
+ },
289
+ async close() {
290
+ (0, container_js_1.resetContainer)();
291
+ engineActive = false;
292
+ },
293
+ };
294
+ return (0, types_js_1.engineOk)(engine);
295
+ }
@@ -0,0 +1,3 @@
1
+ export { createWorkRailEngine } from './engine-factory.js';
2
+ export type { WorkRailEngine, EngineConfig, EngineResult, EngineError, InfraErrorCode, StepResponse, StepResponseOk, StepResponseBlocked, CheckpointResponse, WorkflowListResponse, WorkflowListItem, PendingStep, StepPreferences, Autonomy, RiskPolicy, NextIntent, Blocker, BlockerCode, StateToken, AckToken, CheckpointToken, } from './types.js';
3
+ export { engineOk, engineErr, asStateToken, asAckToken, asCheckpointToken, unwrapToken } from './types.js';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrapToken = exports.asCheckpointToken = exports.asAckToken = exports.asStateToken = exports.engineErr = exports.engineOk = exports.createWorkRailEngine = void 0;
4
+ var engine_factory_js_1 = require("./engine-factory.js");
5
+ Object.defineProperty(exports, "createWorkRailEngine", { enumerable: true, get: function () { return engine_factory_js_1.createWorkRailEngine; } });
6
+ var types_js_1 = require("./types.js");
7
+ Object.defineProperty(exports, "engineOk", { enumerable: true, get: function () { return types_js_1.engineOk; } });
8
+ Object.defineProperty(exports, "engineErr", { enumerable: true, get: function () { return types_js_1.engineErr; } });
9
+ Object.defineProperty(exports, "asStateToken", { enumerable: true, get: function () { return types_js_1.asStateToken; } });
10
+ Object.defineProperty(exports, "asAckToken", { enumerable: true, get: function () { return types_js_1.asAckToken; } });
11
+ Object.defineProperty(exports, "asCheckpointToken", { enumerable: true, get: function () { return types_js_1.asCheckpointToken; } });
12
+ Object.defineProperty(exports, "unwrapToken", { enumerable: true, get: function () { return types_js_1.unwrapToken; } });
@@ -0,0 +1,130 @@
1
+ declare const StateTokenBrand: unique symbol;
2
+ declare const AckTokenBrand: unique symbol;
3
+ declare const CheckpointTokenBrand: unique symbol;
4
+ export type StateToken = string & {
5
+ readonly [StateTokenBrand]: never;
6
+ };
7
+ export type AckToken = string & {
8
+ readonly [AckTokenBrand]: never;
9
+ };
10
+ export type CheckpointToken = string & {
11
+ readonly [CheckpointTokenBrand]: never;
12
+ };
13
+ export declare function asStateToken(s: string): StateToken;
14
+ export declare function asAckToken(s: string): AckToken;
15
+ export declare function asCheckpointToken(s: string): CheckpointToken;
16
+ export declare function unwrapToken(t: StateToken | AckToken | CheckpointToken): string;
17
+ export interface PendingStep {
18
+ readonly stepId: string;
19
+ readonly title: string;
20
+ readonly prompt: string;
21
+ readonly agentRole?: string;
22
+ }
23
+ export type Autonomy = 'guided' | 'full_auto_stop_on_user_deps' | 'full_auto_never_stop';
24
+ export type RiskPolicy = 'conservative' | 'balanced' | 'aggressive';
25
+ export interface StepPreferences {
26
+ readonly autonomy: Autonomy;
27
+ readonly riskPolicy: RiskPolicy;
28
+ }
29
+ export type NextIntent = 'perform_pending_then_continue' | 'await_user_confirmation' | 'rehydrate_only' | 'complete';
30
+ export type BlockerCode = 'USER_ONLY_DEPENDENCY' | 'MISSING_REQUIRED_OUTPUT' | 'INVALID_REQUIRED_OUTPUT' | 'MISSING_REQUIRED_NOTES' | 'MISSING_CONTEXT_KEY' | 'CONTEXT_BUDGET_EXCEEDED' | 'REQUIRED_CAPABILITY_UNKNOWN' | 'REQUIRED_CAPABILITY_UNAVAILABLE' | 'INVARIANT_VIOLATION' | 'STORAGE_CORRUPTION_DETECTED';
31
+ export interface Blocker {
32
+ readonly code: BlockerCode;
33
+ readonly message: string;
34
+ readonly suggestedFix?: string;
35
+ }
36
+ interface StepResponseBase {
37
+ readonly stateToken: StateToken;
38
+ readonly ackToken: AckToken | null;
39
+ readonly checkpointToken: CheckpointToken | null;
40
+ readonly isComplete: boolean;
41
+ readonly preferences: StepPreferences;
42
+ readonly nextIntent: NextIntent;
43
+ }
44
+ export interface StepResponseOk extends StepResponseBase {
45
+ readonly kind: 'ok';
46
+ readonly pending: PendingStep | null;
47
+ }
48
+ export interface StepResponseBlocked extends StepResponseBase {
49
+ readonly kind: 'blocked';
50
+ readonly pending: PendingStep | null;
51
+ readonly blockers: readonly Blocker[];
52
+ readonly retryable: boolean;
53
+ readonly retryAckToken: AckToken | null;
54
+ }
55
+ export type StepResponse = StepResponseOk | StepResponseBlocked;
56
+ export interface CheckpointResponse {
57
+ readonly checkpointNodeId: string;
58
+ readonly stateToken: StateToken;
59
+ }
60
+ export interface WorkflowListItem {
61
+ readonly workflowId: string;
62
+ readonly name: string;
63
+ readonly description: string;
64
+ readonly version: string;
65
+ }
66
+ export interface WorkflowListResponse {
67
+ readonly workflows: readonly WorkflowListItem[];
68
+ }
69
+ export type InfraErrorCode = string;
70
+ export type EngineError = {
71
+ readonly kind: 'workflow_not_found';
72
+ readonly workflowId: string;
73
+ } | {
74
+ readonly kind: 'workflow_has_no_steps';
75
+ readonly workflowId: string;
76
+ } | {
77
+ readonly kind: 'workflow_compile_failed';
78
+ readonly message: string;
79
+ } | {
80
+ readonly kind: 'validation_failed';
81
+ readonly message: string;
82
+ } | {
83
+ readonly kind: 'token_invalid';
84
+ readonly message: string;
85
+ readonly code?: InfraErrorCode;
86
+ } | {
87
+ readonly kind: 'token_signing_failed';
88
+ readonly message: string;
89
+ } | {
90
+ readonly kind: 'session_error';
91
+ readonly message: string;
92
+ readonly code?: InfraErrorCode;
93
+ } | {
94
+ readonly kind: 'storage_error';
95
+ readonly message: string;
96
+ readonly code?: InfraErrorCode;
97
+ } | {
98
+ readonly kind: 'prompt_render_failed';
99
+ readonly message: string;
100
+ } | {
101
+ readonly kind: 'precondition_failed';
102
+ readonly message: string;
103
+ } | {
104
+ readonly kind: 'internal_error';
105
+ readonly message: string;
106
+ readonly code?: InfraErrorCode;
107
+ };
108
+ export type EngineResult<T> = {
109
+ readonly ok: true;
110
+ readonly value: T;
111
+ } | {
112
+ readonly ok: false;
113
+ readonly error: EngineError;
114
+ };
115
+ export declare function engineOk<T>(value: T): EngineResult<T>;
116
+ export declare function engineErr<T>(error: EngineError): EngineResult<T>;
117
+ export interface EngineConfig {
118
+ readonly dataDir?: string;
119
+ }
120
+ export interface WorkRailEngine {
121
+ readonly startWorkflow: (workflowId: string) => Promise<EngineResult<StepResponse>>;
122
+ readonly continueWorkflow: (stateToken: StateToken, ackToken: AckToken | null, output?: {
123
+ readonly notesMarkdown?: string;
124
+ readonly artifacts?: readonly unknown[];
125
+ }, context?: Readonly<Record<string, unknown>>) => Promise<EngineResult<StepResponse>>;
126
+ readonly checkpointWorkflow: (checkpointToken: CheckpointToken) => Promise<EngineResult<CheckpointResponse>>;
127
+ readonly listWorkflows: () => Promise<EngineResult<WorkflowListResponse>>;
128
+ readonly close: () => Promise<void>;
129
+ }
130
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asStateToken = asStateToken;
4
+ exports.asAckToken = asAckToken;
5
+ exports.asCheckpointToken = asCheckpointToken;
6
+ exports.unwrapToken = unwrapToken;
7
+ exports.engineOk = engineOk;
8
+ exports.engineErr = engineErr;
9
+ function asStateToken(s) { return s; }
10
+ function asAckToken(s) { return s; }
11
+ function asCheckpointToken(s) { return s; }
12
+ function unwrapToken(t) { return t; }
13
+ function engineOk(value) {
14
+ return { ok: true, value };
15
+ }
16
+ function engineErr(error) {
17
+ return { ok: false, error };
18
+ }