@exaudeus/workrail 2.0.0 → 3.0.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 (72) hide show
  1. package/dist/application/services/compiler/template-registry.d.ts +4 -2
  2. package/dist/application/services/compiler/template-registry.js +97 -5
  3. package/dist/application/services/workflow-compiler.d.ts +5 -1
  4. package/dist/application/services/workflow-compiler.js +20 -7
  5. package/dist/application/use-cases/raw-workflow-file-scanner.d.ts +1 -1
  6. package/dist/application/use-cases/raw-workflow-file-scanner.js +2 -0
  7. package/dist/application/use-cases/validate-workflow-registry.js +2 -1
  8. package/dist/config/feature-flags.js +8 -0
  9. package/dist/di/container.js +10 -1
  10. package/dist/di/tokens.d.ts +1 -0
  11. package/dist/di/tokens.js +1 -0
  12. package/dist/engine/engine-factory.d.ts +3 -0
  13. package/dist/engine/engine-factory.js +295 -0
  14. package/dist/engine/index.d.ts +3 -0
  15. package/dist/engine/index.js +12 -0
  16. package/dist/engine/types.d.ts +130 -0
  17. package/dist/engine/types.js +18 -0
  18. package/dist/infrastructure/storage/file-workflow-storage.d.ts +1 -0
  19. package/dist/infrastructure/storage/file-workflow-storage.js +18 -3
  20. package/dist/infrastructure/storage/workflow-resolution.d.ts +9 -6
  21. package/dist/infrastructure/storage/workflow-resolution.js +14 -1
  22. package/dist/manifest.json +166 -94
  23. package/dist/mcp/handlers/shared/request-workflow-reader.d.ts +19 -0
  24. package/dist/mcp/handlers/shared/request-workflow-reader.js +50 -0
  25. package/dist/mcp/handlers/v2-checkpoint.d.ts +31 -1
  26. package/dist/mcp/handlers/v2-checkpoint.js +76 -64
  27. package/dist/mcp/handlers/v2-execution/continue-advance.d.ts +2 -0
  28. package/dist/mcp/handlers/v2-execution/continue-advance.js +5 -5
  29. package/dist/mcp/handlers/v2-execution/continue-rehydrate.d.ts +2 -0
  30. package/dist/mcp/handlers/v2-execution/continue-rehydrate.js +17 -22
  31. package/dist/mcp/handlers/v2-execution/index.d.ts +10 -17
  32. package/dist/mcp/handlers/v2-execution/index.js +44 -54
  33. package/dist/mcp/handlers/v2-execution/replay.d.ts +4 -15
  34. package/dist/mcp/handlers/v2-execution/replay.js +52 -128
  35. package/dist/mcp/handlers/v2-execution/start.d.ts +4 -3
  36. package/dist/mcp/handlers/v2-execution/start.js +32 -49
  37. package/dist/mcp/handlers/v2-token-ops.d.ts +45 -24
  38. package/dist/mcp/handlers/v2-token-ops.js +372 -32
  39. package/dist/mcp/handlers/v2-workflow.d.ts +1 -1
  40. package/dist/mcp/handlers/v2-workflow.js +25 -4
  41. package/dist/mcp/output-schemas.d.ts +104 -283
  42. package/dist/mcp/output-schemas.js +24 -22
  43. package/dist/mcp/server.js +8 -0
  44. package/dist/mcp/tool-descriptions.js +9 -2
  45. package/dist/mcp/types.d.ts +4 -0
  46. package/dist/mcp/v2/tools.d.ts +32 -53
  47. package/dist/mcp/v2/tools.js +27 -37
  48. package/dist/mcp/v2-response-formatter.js +12 -16
  49. package/dist/runtime/runtime-mode.d.ts +2 -0
  50. package/dist/v2/durable-core/domain/prompt-renderer.d.ts +1 -0
  51. package/dist/v2/durable-core/domain/prompt-renderer.js +5 -3
  52. package/dist/v2/durable-core/schemas/export-bundle/index.d.ts +14 -14
  53. package/dist/v2/durable-core/schemas/session/events.d.ts +4 -4
  54. package/dist/v2/durable-core/schemas/session/validation-event.d.ts +2 -2
  55. package/dist/v2/durable-core/tokens/payloads.d.ts +32 -32
  56. package/dist/v2/durable-core/tokens/short-token.d.ts +38 -0
  57. package/dist/v2/durable-core/tokens/short-token.js +126 -0
  58. package/dist/v2/durable-core/tokens/token-patterns.d.ts +4 -0
  59. package/dist/v2/durable-core/tokens/token-patterns.js +9 -0
  60. package/dist/v2/infra/in-memory/token-alias-store/index.d.ts +11 -0
  61. package/dist/v2/infra/in-memory/token-alias-store/index.js +38 -0
  62. package/dist/v2/infra/local/data-dir/index.d.ts +1 -0
  63. package/dist/v2/infra/local/data-dir/index.js +3 -0
  64. package/dist/v2/infra/local/token-alias-store/index.d.ts +16 -0
  65. package/dist/v2/infra/local/token-alias-store/index.js +117 -0
  66. package/dist/v2/ports/data-dir.port.d.ts +1 -0
  67. package/dist/v2/ports/token-alias-store.port.d.ts +33 -0
  68. package/dist/v2/ports/token-alias-store.port.js +2 -0
  69. package/package.json +8 -1
  70. package/workflows/coding-task-workflow-agentic.lean.v2.json +224 -0
  71. package/workflows/routines/philosophy-alignment.json +12 -12
  72. package/workflows/routines/tension-driven-design.json +63 -0
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildBlockedReplayResponse = buildBlockedReplayResponse;
4
3
  exports.buildAdvancedReplayResponse = buildAdvancedReplayResponse;
5
4
  exports.replayFromRecordedAdvance = replayFromRecordedAdvance;
6
5
  const output_schemas_js_1 = require("../../output-schemas.js");
7
6
  const snapshot_state_js_1 = require("../../../v2/durable-core/projections/snapshot-state.js");
8
- const index_js_1 = require("../../../v2/durable-core/tokens/index.js");
9
- const index_js_2 = require("../../../v2/durable-core/ids/index.js");
7
+ const index_js_1 = require("../../../v2/durable-core/ids/index.js");
10
8
  const workflow_hash_ref_js_1 = require("../../../v2/durable-core/ids/workflow-hash-ref.js");
11
9
  const neverthrow_1 = require("neverthrow");
12
10
  const validation_loader_js_1 = require("../../../v2/durable-core/domain/validation-loader.js");
@@ -15,54 +13,10 @@ const prompt_renderer_js_1 = require("../../../v2/durable-core/domain/prompt-ren
15
13
  const v2_token_ops_js_1 = require("../v2-token-ops.js");
16
14
  const v2_state_conversion_js_1 = require("../v2-state-conversion.js");
17
15
  const constants_js_1 = require("../../../v2/durable-core/constants.js");
18
- const index_js_3 = require("./index.js");
19
- function buildBlockedReplayResponse(args) {
20
- const { sessionId, runId, nodeId, attemptId, blockers, snapshot, truth, workflow, inputStateToken, inputAckToken, ports } = args;
21
- const pendingNow = snapshot ? (0, snapshot_state_js_1.derivePendingStep)(snapshot.enginePayload.engineState) : null;
22
- const isCompleteNow = snapshot ? (0, snapshot_state_js_1.deriveIsComplete)(snapshot.enginePayload.engineState) : false;
23
- let metaOrNull = null;
24
- if (pendingNow) {
25
- const result = (0, prompt_renderer_js_1.renderPendingPrompt)({
26
- workflow,
27
- stepId: String(pendingNow.stepId),
28
- loopPath: pendingNow.loopPath,
29
- truth,
30
- runId: (0, index_js_2.asRunId)(String(runId)),
31
- nodeId: (0, index_js_2.asNodeId)(String(nodeId)),
32
- rehydrateOnly: false,
33
- });
34
- if (result.isErr()) {
35
- return (0, neverthrow_1.errAsync)({ kind: 'prompt_render_failed', message: result.error.message });
36
- }
37
- metaOrNull = result.value;
38
- }
39
- const preferences = (0, v2_execution_helpers_js_1.derivePreferencesOrDefault)({ truth, runId, nodeId });
40
- const nextIntent = (0, v2_state_conversion_js_1.deriveNextIntent)({ rehydrateOnly: false, isComplete: isCompleteNow, pending: metaOrNull });
41
- const replayCheckpointTokenRes = pendingNow
42
- ? (0, v2_token_ops_js_1.signTokenOrErr)({
43
- payload: { tokenVersion: 1, tokenKind: 'checkpoint', sessionId, runId, nodeId, attemptId },
44
- ports,
45
- })
46
- : (0, neverthrow_1.ok)(undefined);
47
- return (0, neverthrow_1.okAsync)(output_schemas_js_1.V2ContinueWorkflowOutputSchema.parse({
48
- kind: 'blocked',
49
- stateToken: inputStateToken,
50
- ackToken: inputAckToken,
51
- checkpointToken: replayCheckpointTokenRes.isOk() ? replayCheckpointTokenRes.value : undefined,
52
- isComplete: isCompleteNow,
53
- pending: metaOrNull ? { stepId: metaOrNull.stepId, title: metaOrNull.title, prompt: metaOrNull.prompt } : null,
54
- preferences,
55
- nextIntent,
56
- nextCall: (0, index_js_3.buildNextCall)({ stateToken: inputStateToken, ackToken: inputAckToken, isComplete: isCompleteNow, pending: metaOrNull }),
57
- blockers,
58
- retryable: undefined,
59
- retryAckToken: undefined,
60
- validation: (0, validation_loader_js_1.loadValidationResultV1)(truth.events, `validation_${String(attemptId)}`).unwrapOr(null) ?? undefined,
61
- }));
62
- }
16
+ const index_js_2 = require("./index.js");
63
17
  function buildAdvancedReplayResponse(args) {
64
- const { sessionId, runId, toNodeId, attemptId, toSnapshot, workflow, truth, workflowHash, ports, sha256 } = args;
65
- const toNodeIdBranded = (0, index_js_2.asNodeId)(String(toNodeId));
18
+ const { sessionId, runId, toNodeId, attemptId, toSnapshot, workflow, truth, workflowHash, ports, sha256, aliasStore, entropy } = args;
19
+ const toNodeIdBranded = (0, index_js_1.asNodeId)(String(toNodeId));
66
20
  const pending = (0, snapshot_state_js_1.derivePendingStep)(toSnapshot.enginePayload.engineState);
67
21
  const isComplete = (0, snapshot_state_js_1.deriveIsComplete)(toSnapshot.enginePayload.engineState);
68
22
  const nextAttemptIdRes = (0, v2_token_ops_js_1.attemptIdForNextNode)(attemptId, sha256);
@@ -70,55 +24,39 @@ function buildAdvancedReplayResponse(args) {
70
24
  return (0, neverthrow_1.errAsync)({ kind: 'invariant_violation', message: `Failed to derive next attemptId: ${nextAttemptIdRes.error.message}` });
71
25
  }
72
26
  const nextAttemptId = nextAttemptIdRes.value;
73
- const nextAckTokenRes = pending
74
- ? (0, v2_token_ops_js_1.signTokenOrErr)({
75
- payload: { tokenVersion: 1, tokenKind: 'ack', sessionId, runId, nodeId: toNodeIdBranded, attemptId: nextAttemptId },
76
- ports,
77
- })
78
- : (0, neverthrow_1.ok)(undefined);
79
- if (nextAckTokenRes.isErr()) {
80
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: nextAckTokenRes.error });
81
- }
82
- const nextCheckpointTokenRes = pending
83
- ? (0, v2_token_ops_js_1.signTokenOrErr)({
84
- payload: { tokenVersion: 1, tokenKind: 'checkpoint', sessionId, runId, nodeId: toNodeIdBranded, attemptId: nextAttemptId },
85
- ports,
86
- })
87
- : (0, neverthrow_1.ok)(undefined);
88
- if (nextCheckpointTokenRes.isErr()) {
89
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: nextCheckpointTokenRes.error });
90
- }
91
27
  const wfRefRes = (0, workflow_hash_ref_js_1.deriveWorkflowHashRef)(workflowHash);
92
28
  if (wfRefRes.isErr()) {
93
29
  return (0, neverthrow_1.errAsync)({ kind: 'precondition_failed', message: wfRefRes.error.message, suggestion: 'Ensure workflowHash is a valid sha256 digest.' });
94
30
  }
95
- const nextStateTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({
96
- payload: { tokenVersion: 1, tokenKind: 'state', sessionId, runId, nodeId: toNodeIdBranded, workflowHashRef: wfRefRes.value },
97
- ports,
98
- });
99
- if (nextStateTokenRes.isErr()) {
100
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: nextStateTokenRes.error });
101
- }
31
+ const entryBase = {
32
+ sessionId: String(sessionId),
33
+ runId: String(runId),
34
+ nodeId: String(toNodeIdBranded),
35
+ attemptId: String(nextAttemptId),
36
+ workflowHashRef: String(wfRefRes.value),
37
+ };
38
+ const nextTokensMint = (0, v2_token_ops_js_1.mintContinueAndCheckpointTokens)({ entry: entryBase, ports, aliasStore, entropy })
39
+ .mapErr((failure) => ({ kind: 'token_signing_failed', cause: failure }));
102
40
  if (toSnapshot.enginePayload.engineState.kind === 'blocked') {
103
41
  const blocked = toSnapshot.enginePayload.engineState.blocked;
104
42
  const blockers = blocked.blockers;
105
43
  const retryable = blocked.kind === 'retryable_block';
106
- const retryAckTokenRes = retryable
107
- ? (0, v2_token_ops_js_1.signTokenOrErr)({
108
- payload: {
109
- tokenVersion: 1,
110
- tokenKind: 'ack',
111
- sessionId,
112
- runId,
113
- nodeId: toNodeIdBranded,
114
- attemptId: (0, index_js_1.asAttemptId)(String(blocked.retryAttemptId)),
44
+ const retryContinueMint = retryable
45
+ ? (0, v2_token_ops_js_1.mintContinueAndCheckpointTokens)({
46
+ entry: {
47
+ aliasSlot: 'retry',
48
+ sessionId: String(sessionId),
49
+ runId: String(runId),
50
+ nodeId: String(toNodeIdBranded),
51
+ attemptId: String(blocked.retryAttemptId),
52
+ workflowHashRef: String(wfRefRes.value),
115
53
  },
116
54
  ports,
117
- })
118
- : (0, neverthrow_1.ok)(undefined);
119
- if (retryAckTokenRes.isErr()) {
120
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: retryAckTokenRes.error });
121
- }
55
+ aliasStore,
56
+ entropy,
57
+ }).map((tokens) => tokens.continueToken)
58
+ .mapErr((failure) => ({ kind: 'token_signing_failed', cause: failure }))
59
+ : (0, neverthrow_1.okAsync)(undefined);
122
60
  const validation = (0, validation_loader_js_1.loadValidationResultV1)(truth.events, String(blocked.validationRef)).unwrapOr(null) ?? undefined;
123
61
  let blockedMeta = null;
124
62
  if (pending) {
@@ -127,8 +65,8 @@ function buildAdvancedReplayResponse(args) {
127
65
  stepId: String(pending.stepId),
128
66
  loopPath: pending.loopPath,
129
67
  truth,
130
- runId: (0, index_js_2.asRunId)(String(runId)),
131
- nodeId: (0, index_js_2.asNodeId)(String(toNodeIdBranded)),
68
+ runId: (0, index_js_1.asRunId)(String(runId)),
69
+ nodeId: (0, index_js_1.asNodeId)(String(toNodeIdBranded)),
132
70
  rehydrateOnly: false,
133
71
  });
134
72
  if (result.isErr()) {
@@ -138,21 +76,20 @@ function buildAdvancedReplayResponse(args) {
138
76
  }
139
77
  const preferences = (0, v2_execution_helpers_js_1.derivePreferencesOrDefault)({ truth, runId, nodeId: toNodeIdBranded });
140
78
  const nextIntent = (0, v2_state_conversion_js_1.deriveNextIntent)({ rehydrateOnly: false, isComplete, pending: blockedMeta });
141
- return (0, neverthrow_1.okAsync)(output_schemas_js_1.V2ContinueWorkflowOutputSchema.parse({
79
+ return nextTokensMint.andThen((nextTokens) => retryContinueMint.andThen((retryContinueToken) => (0, neverthrow_1.okAsync)(output_schemas_js_1.V2ContinueWorkflowOutputSchema.parse({
142
80
  kind: 'blocked',
143
- stateToken: nextStateTokenRes.value,
144
- ackToken: pending ? nextAckTokenRes.value : undefined,
145
- checkpointToken: pending ? nextCheckpointTokenRes.value : undefined,
81
+ continueToken: pending ? nextTokens.continueToken : undefined,
82
+ checkpointToken: pending ? nextTokens.checkpointToken : undefined,
146
83
  isComplete,
147
- pending: blockedMeta ? { stepId: blockedMeta.stepId, title: blockedMeta.title, prompt: blockedMeta.prompt } : null,
84
+ pending: (0, output_schemas_js_1.toPendingStep)(blockedMeta),
148
85
  preferences,
149
86
  nextIntent,
150
- nextCall: (0, index_js_3.buildNextCall)({ stateToken: nextStateTokenRes.value, ackToken: pending ? nextAckTokenRes.value : undefined, isComplete, pending: blockedMeta, retryable, retryAckToken: retryAckTokenRes.value }),
87
+ nextCall: (0, index_js_2.buildNextCall)({ continueToken: pending ? nextTokens.continueToken : undefined, isComplete, pending: blockedMeta, retryContinueToken }),
151
88
  blockers,
152
89
  retryable,
153
- retryAckToken: retryAckTokenRes.value,
90
+ retryContinueToken,
154
91
  validation,
155
- }));
92
+ }))));
156
93
  }
157
94
  let okMeta = null;
158
95
  if (pending) {
@@ -161,8 +98,8 @@ function buildAdvancedReplayResponse(args) {
161
98
  stepId: String(pending.stepId),
162
99
  loopPath: pending.loopPath,
163
100
  truth,
164
- runId: (0, index_js_2.asRunId)(String(runId)),
165
- nodeId: (0, index_js_2.asNodeId)(String(toNodeIdBranded)),
101
+ runId: (0, index_js_1.asRunId)(String(runId)),
102
+ nodeId: (0, index_js_1.asNodeId)(String(toNodeIdBranded)),
166
103
  rehydrateOnly: false,
167
104
  });
168
105
  if (result.isErr()) {
@@ -172,41 +109,26 @@ function buildAdvancedReplayResponse(args) {
172
109
  }
173
110
  const preferences = (0, v2_execution_helpers_js_1.derivePreferencesOrDefault)({ truth, runId, nodeId: toNodeIdBranded });
174
111
  const nextIntent = (0, v2_state_conversion_js_1.deriveNextIntent)({ rehydrateOnly: false, isComplete, pending: okMeta });
175
- return (0, neverthrow_1.okAsync)(output_schemas_js_1.V2ContinueWorkflowOutputSchema.parse({
112
+ return nextTokensMint.andThen((nextTokens) => (0, neverthrow_1.okAsync)(output_schemas_js_1.V2ContinueWorkflowOutputSchema.parse({
176
113
  kind: 'ok',
177
- stateToken: nextStateTokenRes.value,
178
- ackToken: pending ? nextAckTokenRes.value : undefined,
179
- checkpointToken: pending ? nextCheckpointTokenRes.value : undefined,
114
+ continueToken: pending ? nextTokens.continueToken : undefined,
115
+ checkpointToken: pending ? nextTokens.checkpointToken : undefined,
180
116
  isComplete,
181
- pending: okMeta ? { stepId: okMeta.stepId, title: okMeta.title, prompt: okMeta.prompt } : null,
117
+ pending: (0, output_schemas_js_1.toPendingStep)(okMeta),
182
118
  preferences,
183
119
  nextIntent,
184
- nextCall: (0, index_js_3.buildNextCall)({ stateToken: nextStateTokenRes.value, ackToken: pending ? nextAckTokenRes.value : undefined, isComplete, pending: okMeta }),
185
- }));
120
+ nextCall: (0, index_js_2.buildNextCall)({ continueToken: pending ? nextTokens.continueToken : undefined, isComplete, pending: okMeta }),
121
+ })));
186
122
  }
187
123
  function replayFromRecordedAdvance(args) {
188
- const { recordedEvent, truth, sessionId, runId, nodeId, workflowHash, attemptId, inputStateToken, inputAckToken, pinnedWorkflow, snapshotStore, sha256, tokenCodecPorts, } = args;
124
+ const { recordedEvent, truth, sessionId, runId, nodeId, workflowHash, attemptId, pinnedWorkflow, snapshotStore, sha256, tokenCodecPorts, aliasStore, entropy, } = args;
189
125
  if (recordedEvent.data.outcome.kind === 'blocked') {
190
- const blockers = recordedEvent.data.outcome.blockers;
191
- const snapNode = truth.events.find((e) => e.kind === constants_js_1.EVENT_KIND.NODE_CREATED && e.scope?.nodeId === String(nodeId));
192
- const snapRA = snapNode
193
- ? snapshotStore.getExecutionSnapshotV1(snapNode.data.snapshotRef).mapErr((cause) => ({ kind: 'snapshot_load_failed', cause }))
194
- : (0, neverthrow_1.okAsync)(null);
195
- return snapRA.andThen((snapshot) => buildBlockedReplayResponse({
196
- sessionId,
197
- runId,
198
- nodeId,
199
- attemptId,
200
- blockers,
201
- snapshot,
202
- truth,
203
- workflow: pinnedWorkflow,
204
- inputStateToken,
205
- inputAckToken,
206
- ports: tokenCodecPorts,
207
- }));
126
+ return (0, neverthrow_1.errAsync)({
127
+ kind: 'invariant_violation',
128
+ message: 'Legacy blocked advance_recorded outcomes are no longer supported. Sessions must be re-created.',
129
+ });
208
130
  }
209
- const toNodeId = (0, index_js_2.asNodeId)(String(recordedEvent.data.outcome.toNodeId));
131
+ const toNodeId = (0, index_js_1.asNodeId)(String(recordedEvent.data.outcome.toNodeId));
210
132
  const toNode = truth.events.find((e) => e.kind === constants_js_1.EVENT_KIND.NODE_CREATED && e.scope?.nodeId === String(toNodeId));
211
133
  if (!toNode) {
212
134
  return (0, neverthrow_1.errAsync)({
@@ -236,6 +158,8 @@ function replayFromRecordedAdvance(args) {
236
158
  workflowHash,
237
159
  ports: tokenCodecPorts,
238
160
  sha256,
161
+ aliasStore,
162
+ entropy,
239
163
  });
240
164
  });
241
165
  }
@@ -12,7 +12,7 @@ import { type StartWorkflowError } from '../v2-execution-helpers.js';
12
12
  import * as z from 'zod';
13
13
  export declare function loadAndPinWorkflow(args: {
14
14
  readonly workflowId: string;
15
- readonly workflowService: import('../../../application/services/workflow-service.js').WorkflowService;
15
+ readonly workflowReader: Pick<import('../../../types/storage.js').IWorkflowReader, 'getWorkflowById'>;
16
16
  readonly crypto: Sha256PortV2;
17
17
  readonly pinnedStore: import('../../../v2/ports/pinned-workflow-store.port.js').PinnedWorkflowStorePortV2;
18
18
  readonly validationPipelineDeps: ValidationPipelineDepsPhase1a;
@@ -45,9 +45,10 @@ export declare function mintStartTokens(args: {
45
45
  readonly attemptId: import('../../../v2/durable-core/tokens/index.js').AttemptId;
46
46
  readonly workflowHashRef: import('../../../v2/durable-core/ids/index.js').WorkflowHashRef;
47
47
  readonly ports: TokenCodecPorts;
48
+ readonly aliasStore: import('../../../v2/ports/token-alias-store.port.js').TokenAliasStorePortV2;
49
+ readonly entropy: import('../../../v2/ports/random-entropy.port.js').RandomEntropyPortV2;
48
50
  }): RA<{
49
- readonly stateToken: string;
50
- readonly ackToken: string;
51
+ readonly continueToken: string;
51
52
  readonly checkpointToken: string;
52
53
  }, StartWorkflowError>;
53
54
  export declare function executeStartWorkflow(input: import('../../v2/tools.js').V2StartWorkflowInput, ctx: V2ToolContext): RA<z.infer<typeof V2StartWorkflowOutputSchema>, StartWorkflowError>;
@@ -23,9 +23,10 @@ const v2_execution_helpers_js_1 = require("../v2-execution-helpers.js");
23
23
  const constants_js_1 = require("../../../v2/durable-core/constants.js");
24
24
  const index_js_2 = require("./index.js");
25
25
  const start_construction_js_1 = require("../../../v2/durable-core/domain/start-construction.js");
26
+ const request_workflow_reader_js_1 = require("../shared/request-workflow-reader.js");
26
27
  function loadAndPinWorkflow(args) {
27
- const { workflowId, workflowService, crypto, pinnedStore, validationPipelineDeps } = args;
28
- return neverthrow_1.ResultAsync.fromPromise(workflowService.getWorkflowById(workflowId), (e) => ({
28
+ const { workflowId, workflowReader, crypto, pinnedStore, validationPipelineDeps } = args;
29
+ return neverthrow_1.ResultAsync.fromPromise(workflowReader.getWorkflowById(workflowId), (e) => ({
29
30
  kind: 'precondition_failed',
30
31
  message: e instanceof Error ? e.message : String(e),
31
32
  }))
@@ -182,54 +183,35 @@ function buildInitialEvents(args) {
182
183
  return mutableEvents;
183
184
  }
184
185
  function mintStartTokens(args) {
185
- const { sessionId, runId, nodeId, attemptId, workflowHashRef, ports } = args;
186
- const statePayload = {
187
- tokenVersion: 1,
188
- tokenKind: 'state',
189
- sessionId,
190
- runId,
191
- nodeId,
192
- workflowHashRef,
186
+ const { sessionId, runId, nodeId, attemptId, workflowHashRef, ports, aliasStore, entropy } = args;
187
+ const entryBase = {
188
+ sessionId: String(sessionId),
189
+ runId: String(runId),
190
+ nodeId: String(nodeId),
191
+ attemptId: String(attemptId),
192
+ workflowHashRef: String(workflowHashRef),
193
193
  };
194
- const ackPayload = {
195
- tokenVersion: 1,
196
- tokenKind: 'ack',
197
- sessionId,
198
- runId,
199
- nodeId,
200
- attemptId,
201
- };
202
- const checkpointPayload = {
203
- tokenVersion: 1,
204
- tokenKind: 'checkpoint',
205
- sessionId,
206
- runId,
207
- nodeId,
208
- attemptId,
209
- };
210
- const stateTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({ payload: statePayload, ports });
211
- if (stateTokenRes.isErr()) {
212
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: stateTokenRes.error });
213
- }
214
- const ackTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({ payload: ackPayload, ports });
215
- if (ackTokenRes.isErr()) {
216
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: ackTokenRes.error });
217
- }
218
- const checkpointTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({ payload: checkpointPayload, ports });
219
- if (checkpointTokenRes.isErr()) {
220
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: checkpointTokenRes.error });
221
- }
222
- return (0, neverthrow_1.okAsync)({
223
- stateToken: stateTokenRes.value,
224
- ackToken: ackTokenRes.value,
225
- checkpointToken: checkpointTokenRes.value,
226
- });
194
+ return (0, v2_token_ops_js_1.mintContinueAndCheckpointTokens)({ entry: entryBase, ports, aliasStore, entropy })
195
+ .mapErr((failure) => ({
196
+ kind: 'token_signing_failed',
197
+ cause: failure,
198
+ }));
227
199
  }
228
200
  function executeStartWorkflow(input, ctx) {
229
- const { gate, sessionStore, snapshotStore, pinnedStore, crypto, tokenCodecPorts, idFactory, validationPipelineDeps } = ctx.v2;
201
+ const { gate, sessionStore, snapshotStore, pinnedStore, crypto, tokenCodecPorts, idFactory, validationPipelineDeps, tokenAliasStore, entropy } = ctx.v2;
202
+ const workflowReader = (0, request_workflow_reader_js_1.hasRequestWorkspaceSignal)({
203
+ workspacePath: input.workspacePath,
204
+ resolvedRootUris: ctx.v2.resolvedRootUris,
205
+ })
206
+ ? (0, request_workflow_reader_js_1.createWorkflowReaderForRequest)({
207
+ featureFlags: ctx.featureFlags,
208
+ workspacePath: input.workspacePath,
209
+ resolvedRootUris: ctx.v2.resolvedRootUris,
210
+ })
211
+ : ctx.workflowService;
230
212
  return loadAndPinWorkflow({
231
213
  workflowId: input.workflowId,
232
- workflowService: ctx.workflowService,
214
+ workflowReader,
233
215
  crypto,
234
216
  pinnedStore,
235
217
  validationPipelineDeps,
@@ -304,6 +286,8 @@ function executeStartWorkflow(input, ctx) {
304
286
  attemptId,
305
287
  workflowHashRef: wfRefRes.value,
306
288
  ports: tokenCodecPorts,
289
+ aliasStore: tokenAliasStore,
290
+ entropy,
307
291
  }).andThen((tokens) => {
308
292
  const metaResult = (0, prompt_renderer_js_1.renderPendingPrompt)({
309
293
  workflow: pinnedWorkflow,
@@ -321,18 +305,17 @@ function executeStartWorkflow(input, ctx) {
321
305
  });
322
306
  }
323
307
  const meta = metaResult.value;
324
- const pending = { stepId: meta.stepId, title: meta.title, prompt: meta.prompt };
308
+ const pending = (0, output_schemas_js_1.toPendingStep)(meta);
325
309
  const preferences = v2_execution_helpers_js_1.defaultPreferences;
326
310
  const nextIntent = (0, v2_state_conversion_js_1.deriveNextIntent)({ rehydrateOnly: false, isComplete: false, pending: meta });
327
311
  return (0, neverthrow_1.okAsync)(output_schemas_js_1.V2StartWorkflowOutputSchema.parse({
328
- stateToken: tokens.stateToken,
329
- ackToken: tokens.ackToken,
312
+ continueToken: tokens.continueToken,
330
313
  checkpointToken: tokens.checkpointToken,
331
314
  isComplete: false,
332
315
  pending,
333
316
  preferences,
334
317
  nextIntent,
335
- nextCall: (0, index_js_2.buildNextCall)({ stateToken: tokens.stateToken, ackToken: tokens.ackToken, isComplete: false, pending }),
318
+ nextCall: (0, index_js_2.buildNextCall)({ continueToken: tokens.continueToken, isComplete: false, pending }),
336
319
  }));
337
320
  });
338
321
  });
@@ -1,38 +1,59 @@
1
+ import type { ResultAsync } from 'neverthrow';
1
2
  import type { Result } from 'neverthrow';
2
3
  import { type ParsedTokenV1Binary, type TokenDecodeErrorV2, type TokenVerifyErrorV2, type TokenSignErrorV2, type TokenPayloadV1, type AttemptId } from '../../v2/durable-core/tokens/index.js';
3
4
  import type { TokenCodecPorts } from '../../v2/durable-core/tokens/token-codec-ports.js';
4
5
  import type { Sha256PortV2 } from '../../v2/ports/sha256.port.js';
5
6
  import { type ToolFailure } from './v2-execution-helpers.js';
7
+ import type { TokenAliasStorePortV2, TokenAliasEntryV2 } from '../../v2/ports/token-alias-store.port.js';
8
+ import type { RandomEntropyPortV2 } from '../../v2/ports/random-entropy.port.js';
9
+ import type { StateTokenPayloadV1, AckTokenPayloadV1, CheckpointTokenPayloadV1 } from '../../v2/durable-core/tokens/payloads.js';
6
10
  export type StateTokenInput = ParsedTokenV1Binary & {
7
- readonly payload: import('../../v2/durable-core/tokens/payloads.js').StateTokenPayloadV1;
11
+ readonly payload: StateTokenPayloadV1;
8
12
  };
9
13
  export type AckTokenInput = ParsedTokenV1Binary & {
10
- readonly payload: import('../../v2/durable-core/tokens/payloads.js').AckTokenPayloadV1;
14
+ readonly payload: AckTokenPayloadV1;
11
15
  };
12
16
  export type CheckpointTokenInput = ParsedTokenV1Binary & {
13
- readonly payload: import('../../v2/durable-core/tokens/payloads.js').CheckpointTokenPayloadV1;
14
- };
15
- export declare function parseStateTokenOrFail(raw: string, ports: TokenCodecPorts): {
16
- ok: true;
17
- token: StateTokenInput;
18
- } | {
19
- ok: false;
20
- failure: ToolFailure;
21
- };
22
- export declare function parseAckTokenOrFail(raw: string, ports: TokenCodecPorts): {
23
- ok: true;
24
- token: AckTokenInput;
25
- } | {
26
- ok: false;
27
- failure: ToolFailure;
28
- };
29
- export declare function parseCheckpointTokenOrFail(raw: string, ports: TokenCodecPorts): {
30
- ok: true;
31
- token: CheckpointTokenInput;
32
- } | {
33
- ok: false;
34
- failure: ToolFailure;
17
+ readonly payload: CheckpointTokenPayloadV1;
35
18
  };
19
+ export interface ContinueTokenResolved {
20
+ readonly sessionId: string;
21
+ readonly runId: string;
22
+ readonly nodeId: string;
23
+ readonly attemptId: string;
24
+ readonly workflowHashRef: string;
25
+ }
26
+ export declare function parseStateTokenOrFail(raw: string, ports: TokenCodecPorts, aliasStore: TokenAliasStorePortV2): ResultAsync<StateTokenInput, ToolFailure>;
27
+ export declare function parseAckTokenOrFail(raw: string, ports: TokenCodecPorts, aliasStore: TokenAliasStorePortV2): ResultAsync<AckTokenInput, ToolFailure>;
28
+ export declare function parseCheckpointTokenOrFail(raw: string, ports: TokenCodecPorts, aliasStore: TokenAliasStorePortV2): ResultAsync<CheckpointTokenInput, ToolFailure>;
29
+ export declare function parseContinueTokenOrFail(raw: string, ports: TokenCodecPorts, aliasStore: TokenAliasStorePortV2): ResultAsync<ContinueTokenResolved, ToolFailure>;
30
+ export interface ContinueAndCheckpointTokens {
31
+ readonly continueToken: string;
32
+ readonly checkpointToken: string;
33
+ }
34
+ export declare function mintContinueAndCheckpointTokens(args: Omit<MintShortTokenTripleArgs, 'entry'> & {
35
+ readonly entry: Omit<TokenAliasEntryV2, 'nonceHex' | 'tokenKind'>;
36
+ }): ResultAsync<ContinueAndCheckpointTokens, ToolFailure>;
37
+ export interface ShortTokenTriple {
38
+ readonly stateToken: string;
39
+ readonly ackToken: string;
40
+ readonly checkpointToken: string;
41
+ }
42
+ export interface MintShortTokenTripleArgs {
43
+ readonly entry: Omit<TokenAliasEntryV2, 'nonceHex' | 'tokenKind'>;
44
+ readonly ports: TokenCodecPorts;
45
+ readonly aliasStore: TokenAliasStorePortV2;
46
+ readonly entropy: RandomEntropyPortV2;
47
+ }
48
+ export declare function mintShortTokenTriple(args: MintShortTokenTripleArgs): ResultAsync<ShortTokenTriple, ToolFailure>;
49
+ export interface MintSingleShortTokenArgs {
50
+ readonly kind: import('../../v2/durable-core/tokens/short-token.js').ShortTokenKind;
51
+ readonly entry: Omit<TokenAliasEntryV2, 'nonceHex' | 'tokenKind'>;
52
+ readonly ports: TokenCodecPorts;
53
+ readonly aliasStore: TokenAliasStorePortV2;
54
+ readonly entropy: RandomEntropyPortV2;
55
+ }
56
+ export declare function mintSingleShortToken(args: MintSingleShortTokenArgs): ResultAsync<string, ToolFailure>;
36
57
  export declare function newAttemptId(idFactory: {
37
58
  readonly mintAttemptId: () => AttemptId;
38
59
  }): AttemptId;