@exaudeus/workrail 2.1.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 (58) 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/di/container.js +10 -1
  6. package/dist/di/tokens.d.ts +1 -0
  7. package/dist/di/tokens.js +1 -0
  8. package/dist/engine/engine-factory.d.ts +3 -0
  9. package/dist/engine/engine-factory.js +295 -0
  10. package/dist/engine/index.d.ts +3 -0
  11. package/dist/engine/index.js +12 -0
  12. package/dist/engine/types.d.ts +130 -0
  13. package/dist/engine/types.js +18 -0
  14. package/dist/infrastructure/storage/file-workflow-storage.d.ts +1 -0
  15. package/dist/infrastructure/storage/file-workflow-storage.js +10 -0
  16. package/dist/manifest.json +140 -76
  17. package/dist/mcp/handlers/v2-checkpoint.d.ts +31 -1
  18. package/dist/mcp/handlers/v2-checkpoint.js +76 -64
  19. package/dist/mcp/handlers/v2-execution/continue-advance.d.ts +2 -0
  20. package/dist/mcp/handlers/v2-execution/continue-advance.js +5 -5
  21. package/dist/mcp/handlers/v2-execution/continue-rehydrate.d.ts +2 -0
  22. package/dist/mcp/handlers/v2-execution/continue-rehydrate.js +17 -22
  23. package/dist/mcp/handlers/v2-execution/index.d.ts +10 -17
  24. package/dist/mcp/handlers/v2-execution/index.js +44 -54
  25. package/dist/mcp/handlers/v2-execution/replay.d.ts +4 -15
  26. package/dist/mcp/handlers/v2-execution/replay.js +52 -128
  27. package/dist/mcp/handlers/v2-execution/start.d.ts +3 -2
  28. package/dist/mcp/handlers/v2-execution/start.js +18 -46
  29. package/dist/mcp/handlers/v2-token-ops.d.ts +45 -24
  30. package/dist/mcp/handlers/v2-token-ops.js +372 -32
  31. package/dist/mcp/output-schemas.d.ts +104 -283
  32. package/dist/mcp/output-schemas.js +24 -22
  33. package/dist/mcp/server.js +8 -0
  34. package/dist/mcp/types.d.ts +4 -0
  35. package/dist/mcp/v2/tools.d.ts +22 -52
  36. package/dist/mcp/v2/tools.js +18 -32
  37. package/dist/mcp/v2-response-formatter.js +12 -16
  38. package/dist/runtime/runtime-mode.d.ts +2 -0
  39. package/dist/v2/durable-core/domain/prompt-renderer.d.ts +1 -0
  40. package/dist/v2/durable-core/domain/prompt-renderer.js +5 -3
  41. package/dist/v2/durable-core/schemas/export-bundle/index.d.ts +14 -14
  42. package/dist/v2/durable-core/schemas/session/events.d.ts +4 -4
  43. package/dist/v2/durable-core/schemas/session/validation-event.d.ts +2 -2
  44. package/dist/v2/durable-core/tokens/payloads.d.ts +32 -32
  45. package/dist/v2/durable-core/tokens/short-token.d.ts +38 -0
  46. package/dist/v2/durable-core/tokens/short-token.js +126 -0
  47. package/dist/v2/durable-core/tokens/token-patterns.d.ts +4 -0
  48. package/dist/v2/durable-core/tokens/token-patterns.js +9 -0
  49. package/dist/v2/infra/in-memory/token-alias-store/index.d.ts +11 -0
  50. package/dist/v2/infra/in-memory/token-alias-store/index.js +38 -0
  51. package/dist/v2/infra/local/data-dir/index.d.ts +1 -0
  52. package/dist/v2/infra/local/data-dir/index.js +3 -0
  53. package/dist/v2/infra/local/token-alias-store/index.d.ts +16 -0
  54. package/dist/v2/infra/local/token-alias-store/index.js +117 -0
  55. package/dist/v2/ports/data-dir.port.d.ts +1 -0
  56. package/dist/v2/ports/token-alias-store.port.d.ts +33 -0
  57. package/dist/v2/ports/token-alias-store.port.js +2 -0
  58. package/package.json +8 -1
@@ -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
  }
@@ -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>;
@@ -183,51 +183,22 @@ function buildInitialEvents(args) {
183
183
  return mutableEvents;
184
184
  }
185
185
  function mintStartTokens(args) {
186
- const { sessionId, runId, nodeId, attemptId, workflowHashRef, ports } = args;
187
- const statePayload = {
188
- tokenVersion: 1,
189
- tokenKind: 'state',
190
- sessionId,
191
- runId,
192
- nodeId,
193
- 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),
194
193
  };
195
- const ackPayload = {
196
- tokenVersion: 1,
197
- tokenKind: 'ack',
198
- sessionId,
199
- runId,
200
- nodeId,
201
- attemptId,
202
- };
203
- const checkpointPayload = {
204
- tokenVersion: 1,
205
- tokenKind: 'checkpoint',
206
- sessionId,
207
- runId,
208
- nodeId,
209
- attemptId,
210
- };
211
- const stateTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({ payload: statePayload, ports });
212
- if (stateTokenRes.isErr()) {
213
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: stateTokenRes.error });
214
- }
215
- const ackTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({ payload: ackPayload, ports });
216
- if (ackTokenRes.isErr()) {
217
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: ackTokenRes.error });
218
- }
219
- const checkpointTokenRes = (0, v2_token_ops_js_1.signTokenOrErr)({ payload: checkpointPayload, ports });
220
- if (checkpointTokenRes.isErr()) {
221
- return (0, neverthrow_1.errAsync)({ kind: 'token_signing_failed', cause: checkpointTokenRes.error });
222
- }
223
- return (0, neverthrow_1.okAsync)({
224
- stateToken: stateTokenRes.value,
225
- ackToken: ackTokenRes.value,
226
- checkpointToken: checkpointTokenRes.value,
227
- });
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
+ }));
228
199
  }
229
200
  function executeStartWorkflow(input, ctx) {
230
- 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;
231
202
  const workflowReader = (0, request_workflow_reader_js_1.hasRequestWorkspaceSignal)({
232
203
  workspacePath: input.workspacePath,
233
204
  resolvedRootUris: ctx.v2.resolvedRootUris,
@@ -315,6 +286,8 @@ function executeStartWorkflow(input, ctx) {
315
286
  attemptId,
316
287
  workflowHashRef: wfRefRes.value,
317
288
  ports: tokenCodecPorts,
289
+ aliasStore: tokenAliasStore,
290
+ entropy,
318
291
  }).andThen((tokens) => {
319
292
  const metaResult = (0, prompt_renderer_js_1.renderPendingPrompt)({
320
293
  workflow: pinnedWorkflow,
@@ -332,18 +305,17 @@ function executeStartWorkflow(input, ctx) {
332
305
  });
333
306
  }
334
307
  const meta = metaResult.value;
335
- const pending = { stepId: meta.stepId, title: meta.title, prompt: meta.prompt };
308
+ const pending = (0, output_schemas_js_1.toPendingStep)(meta);
336
309
  const preferences = v2_execution_helpers_js_1.defaultPreferences;
337
310
  const nextIntent = (0, v2_state_conversion_js_1.deriveNextIntent)({ rehydrateOnly: false, isComplete: false, pending: meta });
338
311
  return (0, neverthrow_1.okAsync)(output_schemas_js_1.V2StartWorkflowOutputSchema.parse({
339
- stateToken: tokens.stateToken,
340
- ackToken: tokens.ackToken,
312
+ continueToken: tokens.continueToken,
341
313
  checkpointToken: tokens.checkpointToken,
342
314
  isComplete: false,
343
315
  pending,
344
316
  preferences,
345
317
  nextIntent,
346
- 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 }),
347
319
  }));
348
320
  });
349
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;