@exaudeus/workrail 0.11.0 → 0.13.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.
- package/dist/application/services/enhanced-loop-validator.js +3 -3
- package/dist/application/services/step-output-decoder.d.ts +6 -0
- package/dist/application/services/step-output-decoder.js +49 -0
- package/dist/application/services/validation-engine.d.ts +9 -0
- package/dist/application/services/validation-engine.js +142 -18
- package/dist/application/services/workflow-interpreter.d.ts +1 -1
- package/dist/application/services/workflow-interpreter.js +147 -81
- package/dist/application/services/workflow-service.d.ts +2 -0
- package/dist/application/services/workflow-service.js +3 -3
- package/dist/application/use-cases/validate-step-output.d.ts +2 -0
- package/dist/config/feature-flags.js +1 -1
- package/dist/di/container.js +88 -0
- package/dist/di/tokens.d.ts +16 -0
- package/dist/di/tokens.js +16 -0
- package/dist/domain/execution/state.d.ts +6 -6
- package/dist/domain/workflow-id-policy.d.ts +17 -0
- package/dist/domain/workflow-id-policy.js +57 -0
- package/dist/infrastructure/storage/enhanced-multi-source-workflow-storage.js +33 -6
- package/dist/infrastructure/storage/file-workflow-storage.js +3 -1
- package/dist/infrastructure/storage/schema-validating-workflow-storage.js +13 -8
- package/dist/manifest.json +329 -161
- package/dist/mcp/error-mapper.d.ts +3 -8
- package/dist/mcp/error-mapper.js +41 -19
- package/dist/mcp/handlers/session.js +25 -11
- package/dist/mcp/handlers/v2-execution-helpers.d.ts +99 -0
- package/dist/mcp/handlers/v2-execution-helpers.js +249 -0
- package/dist/mcp/handlers/v2-execution.d.ts +4 -0
- package/dist/mcp/handlers/v2-execution.js +1044 -0
- package/dist/mcp/handlers/v2-workflow.js +21 -16
- package/dist/mcp/handlers/workflow.js +21 -12
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +4 -1
- package/dist/mcp/output-schemas.d.ts +411 -4
- package/dist/mcp/output-schemas.js +57 -1
- package/dist/mcp/server.d.ts +1 -1
- package/dist/mcp/server.js +96 -65
- package/dist/mcp/tool-descriptions.js +32 -15
- package/dist/mcp/tools.js +26 -14
- package/dist/mcp/types/tool-description-types.d.ts +1 -1
- package/dist/mcp/types/tool-description-types.js +7 -5
- package/dist/mcp/types.d.ts +40 -3
- package/dist/mcp/types.js +32 -3
- package/dist/mcp/v2/tool-registry.js +16 -1
- package/dist/mcp/v2/tools.d.ts +45 -0
- package/dist/mcp/v2/tools.js +21 -1
- package/dist/mcp/validation/workflow-next-prevalidate.d.ts +2 -3
- package/dist/mcp/validation/workflow-next-prevalidate.js +38 -27
- package/dist/v2/durable-core/constants.d.ts +15 -0
- package/dist/v2/durable-core/constants.js +18 -0
- package/dist/v2/durable-core/domain/ack-advance-append-plan.d.ts +32 -0
- package/dist/v2/durable-core/domain/ack-advance-append-plan.js +95 -0
- package/dist/v2/durable-core/domain/loop-runtime.d.ts +50 -0
- package/dist/v2/durable-core/domain/loop-runtime.js +95 -0
- package/dist/v2/durable-core/domain/notes-markdown.d.ts +4 -0
- package/dist/v2/durable-core/domain/notes-markdown.js +46 -0
- package/dist/v2/durable-core/domain/outputs.d.ts +12 -0
- package/dist/v2/durable-core/domain/outputs.js +18 -0
- package/dist/v2/durable-core/ids/index.d.ts +2 -0
- package/dist/v2/durable-core/ids/index.js +4 -0
- package/dist/v2/durable-core/schemas/compiled-workflow/index.d.ts +100 -6
- package/dist/v2/durable-core/schemas/compiled-workflow/index.js +18 -3
- package/dist/v2/durable-core/schemas/execution-snapshot/execution-snapshot.v1.d.ts +113 -113
- package/dist/v2/durable-core/schemas/execution-snapshot/execution-snapshot.v1.js +11 -10
- package/dist/v2/durable-core/schemas/export-bundle/index.d.ts +7129 -0
- package/dist/v2/durable-core/schemas/export-bundle/index.js +82 -0
- package/dist/v2/durable-core/schemas/lib/decision-trace-ref.d.ts +80 -0
- package/dist/v2/durable-core/schemas/lib/decision-trace-ref.js +38 -0
- package/dist/v2/durable-core/schemas/lib/dedupe-key.d.ts +8 -0
- package/dist/v2/durable-core/schemas/lib/dedupe-key.js +28 -0
- package/dist/v2/durable-core/schemas/lib/utf8-bounded-string.d.ts +6 -0
- package/dist/v2/durable-core/schemas/lib/utf8-bounded-string.js +12 -0
- package/dist/v2/durable-core/schemas/session/events.d.ts +238 -62
- package/dist/v2/durable-core/schemas/session/events.js +74 -29
- package/dist/v2/durable-core/schemas/session/manifest.d.ts +3 -3
- package/dist/v2/durable-core/schemas/session/manifest.js +6 -1
- package/dist/v2/durable-core/schemas/session/preferences.d.ts +5 -0
- package/dist/v2/durable-core/schemas/session/preferences.js +6 -0
- package/dist/v2/durable-core/schemas/session/session-health.d.ts +3 -0
- package/dist/v2/durable-core/tokens/index.d.ts +2 -1
- package/dist/v2/durable-core/tokens/index.js +4 -4
- package/dist/v2/durable-core/tokens/payloads.d.ts +4 -4
- package/dist/v2/durable-core/tokens/token-codec.d.ts +3 -2
- package/dist/v2/durable-core/tokens/token-codec.js +12 -6
- package/dist/v2/durable-core/tokens/token-signer.d.ts +3 -2
- package/dist/v2/durable-core/tokens/token-signer.js +8 -9
- package/dist/v2/infra/local/base64url/index.d.ts +5 -0
- package/dist/v2/infra/local/base64url/index.js +48 -0
- package/dist/v2/infra/local/fs/index.js +8 -4
- package/dist/v2/infra/local/keyring/index.d.ts +5 -1
- package/dist/v2/infra/local/keyring/index.js +41 -32
- package/dist/v2/infra/local/pinned-workflow-store/index.d.ts +6 -4
- package/dist/v2/infra/local/pinned-workflow-store/index.js +50 -62
- package/dist/v2/infra/local/random-entropy/index.d.ts +4 -0
- package/dist/v2/infra/local/random-entropy/index.js +10 -0
- package/dist/v2/infra/local/session-lock/index.d.ts +3 -1
- package/dist/v2/infra/local/session-lock/index.js +5 -4
- package/dist/v2/infra/local/session-store/index.d.ts +0 -1
- package/dist/v2/infra/local/session-store/index.js +372 -282
- package/dist/v2/infra/local/snapshot-store/index.js +20 -25
- package/dist/v2/infra/local/time-clock/index.d.ts +5 -0
- package/dist/v2/infra/local/time-clock/index.js +12 -0
- package/dist/v2/infra/local/utf8/index.d.ts +5 -0
- package/dist/v2/infra/local/utf8/index.js +12 -0
- package/dist/v2/ports/base64url.port.d.ts +12 -0
- package/dist/v2/ports/base64url.port.js +2 -0
- package/dist/v2/ports/pinned-workflow-store.port.d.ts +3 -3
- package/dist/v2/ports/random-entropy.port.d.ts +3 -0
- package/dist/v2/ports/random-entropy.port.js +2 -0
- package/dist/v2/ports/session-event-log-store.port.d.ts +1 -1
- package/dist/v2/ports/session-lock.port.d.ts +1 -1
- package/dist/v2/ports/time-clock.port.d.ts +4 -0
- package/dist/v2/ports/time-clock.port.js +2 -0
- package/dist/v2/ports/utf8.port.d.ts +3 -0
- package/dist/v2/ports/utf8.port.js +2 -0
- package/dist/v2/projections/node-outputs.js +28 -11
- package/dist/v2/projections/preferences.d.ts +1 -2
- package/dist/v2/projections/preferences.js +11 -4
- package/dist/v2/projections/run-dag.js +40 -28
- package/dist/v2/projections/run-status-signals.d.ts +1 -2
- package/dist/v2/read-only/v1-to-v2-shim.d.ts +6 -1
- package/dist/v2/read-only/v1-to-v2-shim.js +16 -4
- package/dist/v2/usecases/execution-session-gate.d.ts +3 -2
- package/dist/v2/usecases/execution-session-gate.js +81 -85
- package/package.json +4 -1
- package/spec/workflow.schema.json +2 -2
- package/workflows/coding-task-workflow-agentic.json +498 -78
- package/workflows/design-thinking-workflow-autonomous.agentic.json +1 -1
- package/workflows/design-thinking-workflow.json +1 -1
- package/workflows/relocation-workflow-us.json +430 -0
- package/dist/v2/durable-core/tokens/base64url.d.ts +0 -7
- package/dist/v2/durable-core/tokens/base64url.js +0 -16
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { DomainError } from '../domain/execution/error.js';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
readonly message: string;
|
|
6
|
-
readonly suggestion?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function mapDomainErrorToToolError(err: DomainError): ToolErrorMapping;
|
|
9
|
-
export declare function mapUnknownErrorToToolError(err: unknown): ToolErrorMapping;
|
|
2
|
+
import type { ToolError } from './types.js';
|
|
3
|
+
export declare function mapDomainErrorToToolError(err: DomainError): ToolError;
|
|
4
|
+
export declare function mapUnknownErrorToToolError(err: unknown): ToolError;
|
package/dist/mcp/error-mapper.js
CHANGED
|
@@ -4,55 +4,77 @@ exports.mapDomainErrorToToolError = mapDomainErrorToToolError;
|
|
|
4
4
|
exports.mapUnknownErrorToToolError = mapUnknownErrorToToolError;
|
|
5
5
|
const bounded_json_js_1 = require("./validation/bounded-json.js");
|
|
6
6
|
function assertNever(x) {
|
|
7
|
-
|
|
7
|
+
return {
|
|
8
|
+
type: 'error',
|
|
9
|
+
code: 'INTERNAL_ERROR',
|
|
10
|
+
message: `Unhandled DomainError variant: ${JSON.stringify(x)}`,
|
|
11
|
+
retry: { kind: 'not_retryable' },
|
|
12
|
+
details: { invariantViolation: 'exhaustiveness_check_failed' },
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
function mapDomainErrorToToolError(err) {
|
|
10
16
|
switch (err._tag) {
|
|
11
17
|
case 'WorkflowNotFound':
|
|
12
18
|
return {
|
|
19
|
+
type: 'error',
|
|
13
20
|
code: 'NOT_FOUND',
|
|
14
21
|
message: err.message,
|
|
15
|
-
|
|
22
|
+
retry: { kind: 'not_retryable' },
|
|
23
|
+
details: { suggestion: `Check available workflows with workflow_list` },
|
|
16
24
|
};
|
|
17
25
|
case 'InvalidState':
|
|
18
26
|
return {
|
|
27
|
+
type: 'error',
|
|
19
28
|
code: 'VALIDATION_ERROR',
|
|
20
29
|
message: err.message,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
retry: { kind: 'not_retryable' },
|
|
31
|
+
details: {
|
|
32
|
+
suggestion: `Use the "state" returned by the last workflow_next call.\n` +
|
|
33
|
+
`If you are completing a step, send an event like:\n` +
|
|
34
|
+
(0, bounded_json_js_1.toBoundedJsonString)({
|
|
35
|
+
kind: 'step_completed',
|
|
36
|
+
stepInstanceId: {
|
|
37
|
+
stepId: '<previous next.stepInstanceId.stepId>',
|
|
38
|
+
loopPath: [],
|
|
39
|
+
},
|
|
40
|
+
}, 512),
|
|
41
|
+
},
|
|
30
42
|
};
|
|
31
43
|
case 'InvalidLoop':
|
|
32
44
|
return {
|
|
45
|
+
type: 'error',
|
|
33
46
|
code: 'VALIDATION_ERROR',
|
|
34
47
|
message: err.message,
|
|
35
|
-
|
|
48
|
+
retry: { kind: 'not_retryable' },
|
|
49
|
+
details: { suggestion: 'Validate the workflow definition and ensure loop/body step IDs are consistent' },
|
|
36
50
|
};
|
|
37
51
|
case 'MissingContext':
|
|
38
52
|
return {
|
|
53
|
+
type: 'error',
|
|
39
54
|
code: 'PRECONDITION_FAILED',
|
|
40
55
|
message: err.message,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
retry: { kind: 'not_retryable' },
|
|
57
|
+
details: {
|
|
58
|
+
suggestion: 'Provide the required keys in the `context` object for condition evaluation and loop inputs.\n' +
|
|
59
|
+
'Example:\n' +
|
|
60
|
+
(0, bounded_json_js_1.toBoundedJsonString)({ context: { '<requiredKey>': '<value>' } }, 256),
|
|
61
|
+
},
|
|
44
62
|
};
|
|
45
63
|
case 'ConditionEvalFailed':
|
|
46
64
|
return {
|
|
65
|
+
type: 'error',
|
|
47
66
|
code: 'INTERNAL_ERROR',
|
|
48
67
|
message: err.message,
|
|
49
|
-
|
|
68
|
+
retry: { kind: 'not_retryable' },
|
|
69
|
+
details: { suggestion: 'Validate workflow JSON and condition expressions with workflow_validate_json' },
|
|
50
70
|
};
|
|
51
71
|
case 'MaxIterationsExceeded':
|
|
52
72
|
return {
|
|
73
|
+
type: 'error',
|
|
53
74
|
code: 'PRECONDITION_FAILED',
|
|
54
75
|
message: err.message,
|
|
55
|
-
|
|
76
|
+
retry: { kind: 'not_retryable' },
|
|
77
|
+
details: { suggestion: `Increase maxIterations for loop '${err.loopId}' or adjust its condition/body` },
|
|
56
78
|
};
|
|
57
79
|
default:
|
|
58
80
|
return assertNever(err);
|
|
@@ -60,7 +82,7 @@ function mapDomainErrorToToolError(err) {
|
|
|
60
82
|
}
|
|
61
83
|
function mapUnknownErrorToToolError(err) {
|
|
62
84
|
if (err instanceof Error) {
|
|
63
|
-
return { code: 'INTERNAL_ERROR', message: err.message };
|
|
85
|
+
return { type: 'error', code: 'INTERNAL_ERROR', message: err.message, retry: { kind: 'not_retryable' } };
|
|
64
86
|
}
|
|
65
|
-
return { code: 'INTERNAL_ERROR', message: String(err) };
|
|
87
|
+
return { type: 'error', code: 'INTERNAL_ERROR', message: String(err), retry: { kind: 'not_retryable' } };
|
|
66
88
|
}
|
|
@@ -42,7 +42,7 @@ const SESSION_SCHEMA_OVERVIEW = {
|
|
|
42
42
|
};
|
|
43
43
|
function requireSessionTools(ctx) {
|
|
44
44
|
if (!ctx.sessionManager || !ctx.httpServer) {
|
|
45
|
-
return (0, types_js_1.
|
|
45
|
+
return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', 'Session tools are not enabled', { suggestion: 'Set WORKRAIL_ENABLE_SESSION_TOOLS=true to enable session tools' });
|
|
46
46
|
}
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
@@ -67,7 +67,7 @@ async function handleCreateSession(input, ctx) {
|
|
|
67
67
|
}
|
|
68
68
|
catch (err) {
|
|
69
69
|
const mapped = (0, error_mapper_js_1.mapUnknownErrorToToolError)(err);
|
|
70
|
-
return
|
|
70
|
+
return mapped;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
async function handleUpdateSession(input, ctx) {
|
|
@@ -81,12 +81,19 @@ async function handleUpdateSession(input, ctx) {
|
|
|
81
81
|
return (0, types_js_1.success)(payload);
|
|
82
82
|
}
|
|
83
83
|
catch (err) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
if (err instanceof Error && (err.name === 'SessionNotFoundError' ||
|
|
85
|
+
err.message.toLowerCase().includes('not found') ||
|
|
86
|
+
err.message.toLowerCase().includes('does not exist'))) {
|
|
87
|
+
return {
|
|
88
|
+
type: 'error',
|
|
89
|
+
code: 'NOT_FOUND',
|
|
90
|
+
message: err.message,
|
|
91
|
+
retry: { kind: 'not_retryable' },
|
|
92
|
+
details: { suggestion: 'Make sure the session exists. Use workrail_create_session() first.' },
|
|
93
|
+
};
|
|
87
94
|
}
|
|
88
95
|
const mapped = (0, error_mapper_js_1.mapUnknownErrorToToolError)(err);
|
|
89
|
-
return
|
|
96
|
+
return mapped;
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
async function handleReadSession(input, ctx) {
|
|
@@ -110,12 +117,19 @@ async function handleReadSession(input, ctx) {
|
|
|
110
117
|
return (0, types_js_1.success)(payload);
|
|
111
118
|
}
|
|
112
119
|
catch (err) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
if (err instanceof Error && (err.name === 'SessionNotFoundError' ||
|
|
121
|
+
err.message.toLowerCase().includes('not found') ||
|
|
122
|
+
err.message.toLowerCase().includes('does not exist'))) {
|
|
123
|
+
return {
|
|
124
|
+
type: 'error',
|
|
125
|
+
code: 'NOT_FOUND',
|
|
126
|
+
message: err.message,
|
|
127
|
+
retry: { kind: 'not_retryable' },
|
|
128
|
+
details: { suggestion: 'Make sure the session exists. Use workrail_create_session() first.' },
|
|
129
|
+
};
|
|
116
130
|
}
|
|
117
131
|
const mapped = (0, error_mapper_js_1.mapUnknownErrorToToolError)(err);
|
|
118
|
-
return
|
|
132
|
+
return mapped;
|
|
119
133
|
}
|
|
120
134
|
}
|
|
121
135
|
async function handleOpenDashboard(input, ctx) {
|
|
@@ -130,6 +144,6 @@ async function handleOpenDashboard(input, ctx) {
|
|
|
130
144
|
}
|
|
131
145
|
catch (err) {
|
|
132
146
|
const mapped = (0, error_mapper_js_1.mapUnknownErrorToToolError)(err);
|
|
133
|
-
return
|
|
147
|
+
return mapped;
|
|
134
148
|
}
|
|
135
149
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { errNotRetryable, errRetryAfterMs } from '../types.js';
|
|
2
|
+
import type { WorkflowId, WorkflowHash } from '../../v2/durable-core/ids/index.js';
|
|
3
|
+
import type { ExecutionSessionGateErrorV2 } from '../../v2/usecases/execution-session-gate.js';
|
|
4
|
+
import type { SessionEventLogStoreError } from '../../v2/ports/session-event-log-store.port.js';
|
|
5
|
+
import type { SnapshotStoreError } from '../../v2/ports/snapshot-store.port.js';
|
|
6
|
+
import type { PinnedWorkflowStoreError } from '../../v2/ports/pinned-workflow-store.port.js';
|
|
7
|
+
import type { KeyringError } from '../../v2/ports/keyring.port.js';
|
|
8
|
+
import type { TokenDecodeErrorV2, TokenVerifyErrorV2 } from '../../v2/durable-core/tokens/index.js';
|
|
9
|
+
export type ToolFailure = ReturnType<typeof errNotRetryable> | ReturnType<typeof errRetryAfterMs>;
|
|
10
|
+
export type StartWorkflowError = {
|
|
11
|
+
readonly kind: 'precondition_failed';
|
|
12
|
+
readonly message: string;
|
|
13
|
+
readonly suggestion?: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'invariant_violation';
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly suggestion?: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'validation_failed';
|
|
20
|
+
readonly failure: ToolFailure;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'workflow_not_found';
|
|
23
|
+
readonly workflowId: WorkflowId;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'workflow_has_no_steps';
|
|
26
|
+
readonly workflowId: WorkflowId;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: 'keyring_load_failed';
|
|
29
|
+
readonly cause: KeyringError;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: 'hash_computation_failed';
|
|
32
|
+
readonly message: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'pinned_workflow_store_failed';
|
|
35
|
+
readonly cause: PinnedWorkflowStoreError;
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: 'snapshot_creation_failed';
|
|
38
|
+
readonly cause: SnapshotStoreError;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: 'session_append_failed';
|
|
41
|
+
readonly cause: ExecutionSessionGateErrorV2 | SessionEventLogStoreError;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: 'token_signing_failed';
|
|
44
|
+
readonly cause: TokenDecodeErrorV2 | TokenVerifyErrorV2;
|
|
45
|
+
};
|
|
46
|
+
export type ContinueWorkflowError = {
|
|
47
|
+
readonly kind: 'precondition_failed';
|
|
48
|
+
readonly message: string;
|
|
49
|
+
readonly suggestion?: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'token_unknown_node';
|
|
52
|
+
readonly message: string;
|
|
53
|
+
readonly suggestion?: string;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'invariant_violation';
|
|
56
|
+
readonly message: string;
|
|
57
|
+
readonly suggestion?: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: 'validation_failed';
|
|
60
|
+
readonly failure: ToolFailure;
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: 'token_decode_failed';
|
|
63
|
+
readonly cause: TokenDecodeErrorV2;
|
|
64
|
+
} | {
|
|
65
|
+
readonly kind: 'token_verify_failed';
|
|
66
|
+
readonly cause: TokenVerifyErrorV2;
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: 'keyring_load_failed';
|
|
69
|
+
readonly cause: KeyringError;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'session_load_failed';
|
|
72
|
+
readonly cause: SessionEventLogStoreError;
|
|
73
|
+
} | {
|
|
74
|
+
readonly kind: 'snapshot_load_failed';
|
|
75
|
+
readonly cause: SnapshotStoreError;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'pinned_workflow_store_failed';
|
|
78
|
+
readonly cause: PinnedWorkflowStoreError;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: 'pinned_workflow_missing';
|
|
81
|
+
readonly workflowHash: WorkflowHash;
|
|
82
|
+
} | {
|
|
83
|
+
readonly kind: 'token_signing_failed';
|
|
84
|
+
readonly cause: TokenDecodeErrorV2 | TokenVerifyErrorV2;
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: 'advance_execution_failed';
|
|
87
|
+
readonly cause: ExecutionSessionGateErrorV2 | SessionEventLogStoreError;
|
|
88
|
+
};
|
|
89
|
+
export declare function mapStartWorkflowErrorToToolError(e: StartWorkflowError): ToolFailure;
|
|
90
|
+
export declare function mapContinueWorkflowErrorToToolError(e: ContinueWorkflowError): ToolFailure;
|
|
91
|
+
export declare function mapTokenDecodeErrorToToolError(e: TokenDecodeErrorV2): ToolFailure;
|
|
92
|
+
export declare function mapTokenVerifyErrorToToolError(e: TokenVerifyErrorV2): ToolFailure;
|
|
93
|
+
export declare function mapTokenSigningErrorToToolError(e: TokenDecodeErrorV2 | TokenVerifyErrorV2): ToolFailure;
|
|
94
|
+
export declare function mapKeyringErrorToToolError(e: KeyringError): ToolFailure;
|
|
95
|
+
export declare function mapSessionEventLogStoreErrorToToolError(e: SessionEventLogStoreError): ToolFailure;
|
|
96
|
+
export declare function mapExecutionSessionGateErrorToToolError(e: ExecutionSessionGateErrorV2): ToolFailure;
|
|
97
|
+
export declare function mapSnapshotStoreErrorToToolError(e: SnapshotStoreError, suggestion?: string): ToolFailure;
|
|
98
|
+
export declare function mapPinnedWorkflowStoreErrorToToolError(e: PinnedWorkflowStoreError, suggestion?: string): ToolFailure;
|
|
99
|
+
export declare function mapSessionOrGateErrorToToolError(e: SessionEventLogStoreError | ExecutionSessionGateErrorV2): ToolFailure;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapStartWorkflowErrorToToolError = mapStartWorkflowErrorToToolError;
|
|
4
|
+
exports.mapContinueWorkflowErrorToToolError = mapContinueWorkflowErrorToToolError;
|
|
5
|
+
exports.mapTokenDecodeErrorToToolError = mapTokenDecodeErrorToToolError;
|
|
6
|
+
exports.mapTokenVerifyErrorToToolError = mapTokenVerifyErrorToToolError;
|
|
7
|
+
exports.mapTokenSigningErrorToToolError = mapTokenSigningErrorToToolError;
|
|
8
|
+
exports.mapKeyringErrorToToolError = mapKeyringErrorToToolError;
|
|
9
|
+
exports.mapSessionEventLogStoreErrorToToolError = mapSessionEventLogStoreErrorToToolError;
|
|
10
|
+
exports.mapExecutionSessionGateErrorToToolError = mapExecutionSessionGateErrorToToolError;
|
|
11
|
+
exports.mapSnapshotStoreErrorToToolError = mapSnapshotStoreErrorToToolError;
|
|
12
|
+
exports.mapPinnedWorkflowStoreErrorToToolError = mapPinnedWorkflowStoreErrorToToolError;
|
|
13
|
+
exports.mapSessionOrGateErrorToToolError = mapSessionOrGateErrorToToolError;
|
|
14
|
+
const types_js_1 = require("../types.js");
|
|
15
|
+
const types_js_2 = require("../types.js");
|
|
16
|
+
function mapStartWorkflowErrorToToolError(e) {
|
|
17
|
+
switch (e.kind) {
|
|
18
|
+
case 'precondition_failed':
|
|
19
|
+
return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', e.message, e.suggestion ? { suggestion: e.suggestion } : undefined);
|
|
20
|
+
case 'invariant_violation':
|
|
21
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', e.message, e.suggestion ? { suggestion: e.suggestion } : undefined);
|
|
22
|
+
case 'validation_failed':
|
|
23
|
+
return e.failure;
|
|
24
|
+
case 'workflow_not_found':
|
|
25
|
+
return (0, types_js_1.errNotRetryable)('NOT_FOUND', `Workflow not found: ${e.workflowId}`, {
|
|
26
|
+
suggestion: 'Use list_workflows to discover available workflows.',
|
|
27
|
+
});
|
|
28
|
+
case 'workflow_has_no_steps':
|
|
29
|
+
return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', 'Workflow has no steps and cannot be started.', {
|
|
30
|
+
suggestion: 'Fix the workflow definition (must contain at least one step).',
|
|
31
|
+
});
|
|
32
|
+
case 'keyring_load_failed':
|
|
33
|
+
return mapKeyringErrorToToolError(e.cause);
|
|
34
|
+
case 'hash_computation_failed':
|
|
35
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', `Failed to compute workflow hash: ${e.message}`, {
|
|
36
|
+
suggestion: 'Retry start_workflow; if this persists, treat as invariant violation.',
|
|
37
|
+
});
|
|
38
|
+
case 'pinned_workflow_store_failed':
|
|
39
|
+
return mapPinnedWorkflowStoreErrorToToolError(e.cause);
|
|
40
|
+
case 'snapshot_creation_failed':
|
|
41
|
+
return mapSnapshotStoreErrorToToolError(e.cause);
|
|
42
|
+
case 'session_append_failed':
|
|
43
|
+
return mapSessionOrGateErrorToToolError(e.cause);
|
|
44
|
+
case 'token_signing_failed':
|
|
45
|
+
return mapTokenSigningErrorToToolError(e.cause);
|
|
46
|
+
default:
|
|
47
|
+
const _exhaustive = e;
|
|
48
|
+
return _exhaustive;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function mapContinueWorkflowErrorToToolError(e) {
|
|
52
|
+
switch (e.kind) {
|
|
53
|
+
case 'precondition_failed':
|
|
54
|
+
return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', e.message, e.suggestion ? { suggestion: e.suggestion } : undefined);
|
|
55
|
+
case 'token_unknown_node':
|
|
56
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_UNKNOWN_NODE', e.message, e.suggestion ? { suggestion: e.suggestion } : undefined);
|
|
57
|
+
case 'invariant_violation':
|
|
58
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', e.message, e.suggestion ? { suggestion: e.suggestion } : undefined);
|
|
59
|
+
case 'validation_failed':
|
|
60
|
+
return e.failure;
|
|
61
|
+
case 'token_decode_failed':
|
|
62
|
+
return mapTokenDecodeErrorToToolError(e.cause);
|
|
63
|
+
case 'token_verify_failed':
|
|
64
|
+
return mapTokenVerifyErrorToToolError(e.cause);
|
|
65
|
+
case 'keyring_load_failed':
|
|
66
|
+
return mapKeyringErrorToToolError(e.cause);
|
|
67
|
+
case 'session_load_failed':
|
|
68
|
+
return mapSessionEventLogStoreErrorToToolError(e.cause);
|
|
69
|
+
case 'snapshot_load_failed':
|
|
70
|
+
return mapSnapshotStoreErrorToToolError(e.cause);
|
|
71
|
+
case 'pinned_workflow_store_failed':
|
|
72
|
+
return mapPinnedWorkflowStoreErrorToToolError(e.cause);
|
|
73
|
+
case 'pinned_workflow_missing':
|
|
74
|
+
return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', `Pinned workflow snapshot is missing for hash: ${e.workflowHash}`, {
|
|
75
|
+
suggestion: 'Re-run start_workflow or re-pin the workflow via inspect_workflow.',
|
|
76
|
+
});
|
|
77
|
+
case 'token_signing_failed':
|
|
78
|
+
return mapTokenSigningErrorToToolError(e.cause);
|
|
79
|
+
case 'advance_execution_failed':
|
|
80
|
+
return mapSessionOrGateErrorToToolError(e.cause);
|
|
81
|
+
default:
|
|
82
|
+
const _exhaustive = e;
|
|
83
|
+
return _exhaustive;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function mapTokenDecodeErrorToToolError(e) {
|
|
87
|
+
switch (e.code) {
|
|
88
|
+
case 'TOKEN_INVALID_FORMAT':
|
|
89
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_INVALID_FORMAT', e.message, {
|
|
90
|
+
suggestion: 'Use the exact tokens returned by WorkRail. Tokens are opaque; do not edit or construct them.',
|
|
91
|
+
});
|
|
92
|
+
case 'TOKEN_UNSUPPORTED_VERSION':
|
|
93
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_UNSUPPORTED_VERSION', e.message, {
|
|
94
|
+
suggestion: 'Update WorkRail to a version that supports this token format.',
|
|
95
|
+
});
|
|
96
|
+
case 'TOKEN_SCOPE_MISMATCH':
|
|
97
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_SCOPE_MISMATCH', e.message, {
|
|
98
|
+
suggestion: 'Tokens must come from the same WorkRail response. Do not mix tokens from different runs or nodes.',
|
|
99
|
+
});
|
|
100
|
+
case 'TOKEN_PAYLOAD_INVALID':
|
|
101
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_INVALID_FORMAT', e.message, {
|
|
102
|
+
suggestion: 'Use the exact tokens returned by WorkRail.',
|
|
103
|
+
});
|
|
104
|
+
default:
|
|
105
|
+
const _exhaustive = e;
|
|
106
|
+
return _exhaustive;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function mapTokenVerifyErrorToToolError(e) {
|
|
110
|
+
switch (e.code) {
|
|
111
|
+
case 'TOKEN_BAD_SIGNATURE':
|
|
112
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_BAD_SIGNATURE', e.message, {
|
|
113
|
+
suggestion: 'Token signature verification failed. Use the exact tokens returned by WorkRail.',
|
|
114
|
+
});
|
|
115
|
+
case 'TOKEN_INVALID_FORMAT':
|
|
116
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_INVALID_FORMAT', e.message, {
|
|
117
|
+
suggestion: 'Use the exact tokens returned by WorkRail.',
|
|
118
|
+
});
|
|
119
|
+
default:
|
|
120
|
+
const _exhaustive = e;
|
|
121
|
+
return _exhaustive;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function mapTokenSigningErrorToToolError(e) {
|
|
125
|
+
switch (e.code) {
|
|
126
|
+
case 'TOKEN_UNSUPPORTED_VERSION':
|
|
127
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_UNSUPPORTED_VERSION', e.message, {
|
|
128
|
+
suggestion: 'Update WorkRail to a version that supports this token format.',
|
|
129
|
+
});
|
|
130
|
+
case 'TOKEN_SCOPE_MISMATCH':
|
|
131
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_SCOPE_MISMATCH', e.message, {
|
|
132
|
+
suggestion: 'Tokens must come from the same WorkRail response. Do not mix tokens from different runs or nodes.',
|
|
133
|
+
});
|
|
134
|
+
case 'TOKEN_PAYLOAD_INVALID':
|
|
135
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_INVALID_FORMAT', e.message, {
|
|
136
|
+
suggestion: 'Use the exact tokens returned by WorkRail.',
|
|
137
|
+
});
|
|
138
|
+
case 'TOKEN_BAD_SIGNATURE':
|
|
139
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_BAD_SIGNATURE', e.message, {
|
|
140
|
+
suggestion: 'Token signature verification failed. Use the exact tokens returned by WorkRail.',
|
|
141
|
+
});
|
|
142
|
+
case 'TOKEN_INVALID_FORMAT':
|
|
143
|
+
return (0, types_js_1.errNotRetryable)('TOKEN_INVALID_FORMAT', e.message, {
|
|
144
|
+
suggestion: 'Use the exact tokens returned by WorkRail. Tokens are opaque; do not edit or construct them.',
|
|
145
|
+
});
|
|
146
|
+
default:
|
|
147
|
+
const _exhaustive = e;
|
|
148
|
+
return _exhaustive;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function mapKeyringErrorToToolError(e) {
|
|
152
|
+
switch (e.code) {
|
|
153
|
+
case 'KEYRING_IO_ERROR':
|
|
154
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', `Keyring I/O error: ${e.message}`, {
|
|
155
|
+
suggestion: 'Retry; check filesystem permissions. If this persists, treat as invariant violation.',
|
|
156
|
+
});
|
|
157
|
+
case 'KEYRING_CORRUPTION_DETECTED':
|
|
158
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', `Keyring corruption detected: ${e.message}`, {
|
|
159
|
+
suggestion: 'Delete the WorkRail v2 data directory for this repo and retry.',
|
|
160
|
+
});
|
|
161
|
+
case 'KEYRING_INVARIANT_VIOLATION':
|
|
162
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', `Keyring invariant violation: ${e.message}`, {
|
|
163
|
+
suggestion: 'Treat as invariant violation.',
|
|
164
|
+
});
|
|
165
|
+
default:
|
|
166
|
+
const _exhaustive = e;
|
|
167
|
+
return _exhaustive;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function mapSessionEventLogStoreErrorToToolError(e) {
|
|
171
|
+
switch (e.code) {
|
|
172
|
+
case 'SESSION_STORE_LOCK_BUSY':
|
|
173
|
+
return (0, types_js_1.errRetryAfterMs)('INTERNAL_ERROR', e.message, e.retry.afterMs, {
|
|
174
|
+
suggestion: 'Another WorkRail process may be writing to this session; retry.',
|
|
175
|
+
});
|
|
176
|
+
case 'SESSION_STORE_CORRUPTION_DETECTED':
|
|
177
|
+
return (0, types_js_1.errNotRetryable)('SESSION_NOT_HEALTHY', `Session corruption detected: ${e.reason.code}`, {
|
|
178
|
+
suggestion: 'Execution requires a healthy session. Export salvage view, then recreate.',
|
|
179
|
+
details: (0, types_js_2.detailsSessionHealth)({ kind: e.location === 'head' ? 'corrupt_head' : 'corrupt_tail', reason: e.reason }),
|
|
180
|
+
});
|
|
181
|
+
case 'SESSION_STORE_IO_ERROR':
|
|
182
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', e.message, {
|
|
183
|
+
suggestion: 'Retry; check filesystem permissions.',
|
|
184
|
+
});
|
|
185
|
+
case 'SESSION_STORE_INVARIANT_VIOLATION':
|
|
186
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', e.message, {
|
|
187
|
+
suggestion: 'Treat as invariant violation.',
|
|
188
|
+
});
|
|
189
|
+
default:
|
|
190
|
+
const _exhaustive = e;
|
|
191
|
+
return _exhaustive;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function mapExecutionSessionGateErrorToToolError(e) {
|
|
195
|
+
switch (e.code) {
|
|
196
|
+
case 'SESSION_LOCKED':
|
|
197
|
+
return (0, types_js_1.errRetryAfterMs)('TOKEN_SESSION_LOCKED', e.message, e.retry.afterMs, {
|
|
198
|
+
suggestion: 'Retry in 1–3 seconds; if this persists >10s, ensure no other WorkRail process is running.',
|
|
199
|
+
});
|
|
200
|
+
case 'LOCK_RELEASE_FAILED':
|
|
201
|
+
return (0, types_js_1.errRetryAfterMs)('TOKEN_SESSION_LOCKED', e.message, e.retry.afterMs, {
|
|
202
|
+
suggestion: 'Retry in 1–3 seconds; if this persists >10s, ensure no other WorkRail process is running.',
|
|
203
|
+
});
|
|
204
|
+
case 'SESSION_NOT_HEALTHY':
|
|
205
|
+
return (0, types_js_1.errNotRetryable)('SESSION_NOT_HEALTHY', e.message, {
|
|
206
|
+
suggestion: 'Execution requires healthy session.',
|
|
207
|
+
details: (0, types_js_2.detailsSessionHealth)(e.health),
|
|
208
|
+
});
|
|
209
|
+
case 'SESSION_LOAD_FAILED':
|
|
210
|
+
case 'SESSION_LOCK_REENTRANT':
|
|
211
|
+
case 'LOCK_ACQUIRE_FAILED':
|
|
212
|
+
case 'GATE_CALLBACK_FAILED':
|
|
213
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', e.message, {
|
|
214
|
+
suggestion: 'Retry; if this persists, treat as invariant violation.',
|
|
215
|
+
});
|
|
216
|
+
default:
|
|
217
|
+
const _exhaustive = e;
|
|
218
|
+
return _exhaustive;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function mapSnapshotStoreErrorToToolError(e, suggestion) {
|
|
222
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', `Snapshot store error: ${e.message}`, {
|
|
223
|
+
suggestion: suggestion ?? 'Retry; if this persists, treat as invariant violation.',
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function mapPinnedWorkflowStoreErrorToToolError(e, suggestion) {
|
|
227
|
+
return (0, types_js_1.errNotRetryable)('INTERNAL_ERROR', `Pinned workflow store error: ${e.message}`, {
|
|
228
|
+
suggestion: suggestion ?? 'Retry; if this persists, treat as invariant violation.',
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function mapSessionOrGateErrorToToolError(e) {
|
|
232
|
+
if (e.code === 'SESSION_LOCKED' ||
|
|
233
|
+
e.code === 'LOCK_RELEASE_FAILED' ||
|
|
234
|
+
e.code === 'SESSION_NOT_HEALTHY' ||
|
|
235
|
+
e.code === 'SESSION_LOAD_FAILED' ||
|
|
236
|
+
e.code === 'SESSION_LOCK_REENTRANT' ||
|
|
237
|
+
e.code === 'LOCK_ACQUIRE_FAILED' ||
|
|
238
|
+
e.code === 'GATE_CALLBACK_FAILED') {
|
|
239
|
+
return mapExecutionSessionGateErrorToToolError(e);
|
|
240
|
+
}
|
|
241
|
+
if (e.code === 'SESSION_STORE_LOCK_BUSY' ||
|
|
242
|
+
e.code === 'SESSION_STORE_IO_ERROR' ||
|
|
243
|
+
e.code === 'SESSION_STORE_CORRUPTION_DETECTED' ||
|
|
244
|
+
e.code === 'SESSION_STORE_INVARIANT_VIOLATION') {
|
|
245
|
+
return mapSessionEventLogStoreErrorToToolError(e);
|
|
246
|
+
}
|
|
247
|
+
const _exhaustive = e;
|
|
248
|
+
return _exhaustive;
|
|
249
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolContext, ToolResult } from '../types.js';
|
|
2
|
+
import type { V2ContinueWorkflowInput, V2StartWorkflowInput } from '../v2/tools.js';
|
|
3
|
+
export declare function handleV2StartWorkflow(input: V2StartWorkflowInput, ctx: ToolContext): Promise<ToolResult<unknown>>;
|
|
4
|
+
export declare function handleV2ContinueWorkflow(input: V2ContinueWorkflowInput, ctx: ToolContext): Promise<ToolResult<unknown>>;
|