@proofoftech/flowsafe 0.6.0 → 0.8.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/CHANGELOG.md +31 -1
- package/README.md +305 -251
- package/dist/agent-host/approval-resumer.d.ts +13 -0
- package/dist/agent-host/approval-resumer.d.ts.map +1 -0
- package/dist/agent-host/approval-resumer.js +43 -0
- package/dist/agent-host/approval-resumer.js.map +1 -0
- package/dist/agent-host/catalog.d.ts +6 -0
- package/dist/agent-host/catalog.d.ts.map +1 -0
- package/dist/agent-host/catalog.js +98 -0
- package/dist/agent-host/catalog.js.map +1 -0
- package/dist/agent-host/index.d.ts +9 -0
- package/dist/agent-host/index.d.ts.map +1 -0
- package/dist/agent-host/index.js +11 -0
- package/dist/agent-host/index.js.map +1 -0
- package/dist/agent-host/router.d.ts +11 -0
- package/dist/agent-host/router.d.ts.map +1 -0
- package/dist/agent-host/router.js +240 -0
- package/dist/agent-host/router.js.map +1 -0
- package/dist/agent-host/thread-host.d.ts +55 -0
- package/dist/agent-host/thread-host.d.ts.map +1 -0
- package/dist/agent-host/thread-host.js +636 -0
- package/dist/agent-host/thread-host.js.map +1 -0
- package/dist/agent-host/thread-topology.d.ts +39 -0
- package/dist/agent-host/thread-topology.d.ts.map +1 -0
- package/dist/agent-host/thread-topology.js +127 -0
- package/dist/agent-host/thread-topology.js.map +1 -0
- package/dist/agent-host/trusted-context.d.ts +9 -0
- package/dist/agent-host/trusted-context.d.ts.map +1 -0
- package/dist/agent-host/trusted-context.js +40 -0
- package/dist/agent-host/trusted-context.js.map +1 -0
- package/dist/agent-host/types.d.ts +49 -0
- package/dist/agent-host/types.d.ts.map +1 -0
- package/dist/agent-host/types.js +3 -0
- package/dist/agent-host/types.js.map +1 -0
- package/dist/agent-runner/agent-run-state.d.ts +30 -0
- package/dist/agent-runner/agent-run-state.d.ts.map +1 -0
- package/dist/agent-runner/agent-run-state.js +128 -0
- package/dist/agent-runner/agent-run-state.js.map +1 -0
- package/dist/agent-runner/approval-shapes.d.ts +1 -1
- package/dist/agent-runner/approval-shapes.js +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +32 -16
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +149 -28
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +2 -0
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js +1 -0
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/contract.d.ts +2 -2
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +27 -11
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.js +1 -1
- package/dist/approval-api/router.d.ts +1 -1
- package/dist/approval-api/service.d.ts +8 -9
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +37 -16
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +17 -16
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +10 -9
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts +6 -6
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +20 -3
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/types.d.ts +14 -7
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +2 -1
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +2 -2
- package/dist/approval-ui/FilterBar.d.ts +3 -3
- package/dist/approval-ui/FilterBar.js +3 -3
- package/dist/approval-ui/client.d.ts +1 -1
- package/dist/approval-ui/components.d.ts +1 -1
- package/dist/approval-ui/stream.d.ts +3 -3
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/use-approval-dashboard.d.ts +9 -12
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +6 -9
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +1 -1
- package/dist/approval-ui/use-web-socket-transport.js +1 -1
- package/dist/background-tasks/d1-storage.d.ts +3 -3
- package/dist/background-tasks/d1-storage.js +3 -3
- package/dist/background-tasks/host.d.ts +4 -4
- package/dist/background-tasks/host.js +2 -2
- package/dist/background-tasks/routes.js +3 -3
- package/dist/do-runner/breakwater-keys.d.ts +1 -1
- package/dist/do-runner/breakwater-keys.js +1 -1
- package/dist/do-runner/cf-types.d.ts +1 -1
- package/dist/do-runner/d1-storage.d.ts +37 -36
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +24 -23
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts +2 -2
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +5 -5
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-context.d.ts +19 -0
- package/dist/do-runner/execution-context.d.ts.map +1 -0
- package/dist/do-runner/execution-context.js +70 -0
- package/dist/do-runner/execution-context.js.map +1 -0
- package/dist/do-runner/hub-do.d.ts +2 -2
- package/dist/do-runner/index.d.ts +2 -1
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +2 -1
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +1 -1
- package/dist/do-runner/memory-id.d.ts +3 -3
- package/dist/do-runner/memory-id.js +3 -3
- package/dist/do-runner/path-safe-id.d.ts +6 -6
- package/dist/do-runner/path-safe-id.js +6 -6
- package/dist/do-runner/runtime.d.ts +12 -5
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +158 -21
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +8 -5
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +23 -6
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/do-runner/thread-header.d.ts +2 -0
- package/dist/do-runner/thread-header.d.ts.map +1 -1
- package/dist/do-runner/thread-header.js +2 -0
- package/dist/do-runner/thread-header.js.map +1 -1
- package/dist/goals/objective-routes.d.ts +6 -6
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +3 -3
- package/dist/host-kit/approval-bridge.d.ts +14 -17
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +20 -20
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +1 -1
- package/dist/host-kit/bearer-auth.js +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +27 -14
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +9 -1
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +13 -13
- package/dist/host-kit/host-approval-service.js +10 -10
- package/dist/host-kit/index.d.ts +1 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/memory-boundary.d.ts +1 -1
- package/dist/host-kit/memory-boundary.js +1 -1
- package/dist/host-kit/run-router.d.ts +10 -11
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/stream-router.d.ts +1 -1
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +3 -3
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +1 -1
- package/dist/host-kit/tenant-registry.d.ts +1 -1
- package/dist/host-kit/tenant-registry.js +1 -1
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +3 -1
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/host-kit/verifier.d.ts +1 -1
- package/dist/host-kit/verifier.js +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/schedules/router.d.ts +3 -3
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +2 -2
- package/dist/schedules/tick.d.ts +8 -11
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +11 -45
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/delivery.d.ts +1 -1
- package/dist/signal-providers/delivery.js +1 -1
- package/dist/signal-providers/host-do.d.ts +9 -7
- package/dist/signal-providers/host-do.d.ts.map +1 -1
- package/dist/signal-providers/host-do.js +28 -15
- package/dist/signal-providers/host-do.js.map +1 -1
- package/dist/signal-providers/host-topology.d.ts +27 -0
- package/dist/signal-providers/host-topology.d.ts.map +1 -0
- package/dist/signal-providers/host-topology.js +36 -0
- package/dist/signal-providers/host-topology.js.map +1 -0
- package/dist/signal-providers/index.d.ts +1 -0
- package/dist/signal-providers/index.d.ts.map +1 -1
- package/dist/signal-providers/index.js +2 -0
- package/dist/signal-providers/index.js.map +1 -1
- package/dist/signal-providers/provider.d.ts +8 -7
- package/dist/signal-providers/provider.d.ts.map +1 -1
- package/dist/signal-providers/provider.js +11 -9
- package/dist/signal-providers/provider.js.map +1 -1
- package/dist/signal-providers/subscription-d1.d.ts +3 -3
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
- package/dist/signal-providers/subscription-d1.js +1 -1
- package/dist/signal-providers/subscription-d1.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +10 -2
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +55 -2
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +3 -4
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +3 -4
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +1 -1
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +10 -5
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +54 -18
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { BREAKWATER_ACTOR_KEY, BREAKWATER_APPROVED_CONNECTORS_KEY, BREAKWATER_ISOLATION_SCOPE_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, } from './breakwater-keys.js';
|
|
3
|
+
const BREAKWATER_KEY_PREFIX = 'breakwater.';
|
|
4
|
+
const GOAL_REQUEST_CONTEXT_KEY = 'mastra:goal';
|
|
5
|
+
/**
|
|
6
|
+
* Runtime-owned request-context keys. The predicate below also reserves the
|
|
7
|
+
* complete `breakwater.*` namespace so future capability keys are protected
|
|
8
|
+
* before this inventory is updated.
|
|
9
|
+
*/
|
|
10
|
+
export const RESERVED_EXECUTION_CONTEXT_KEYS = [
|
|
11
|
+
BREAKWATER_APPROVED_CONNECTORS_KEY,
|
|
12
|
+
BREAKWATER_ACTOR_KEY,
|
|
13
|
+
BREAKWATER_WORKFLOW_SCOPE_KEY,
|
|
14
|
+
BREAKWATER_ISOLATION_SCOPE_KEY,
|
|
15
|
+
GOAL_REQUEST_CONTEXT_KEY,
|
|
16
|
+
'runId',
|
|
17
|
+
'threadId',
|
|
18
|
+
'resourceId',
|
|
19
|
+
'__proto__',
|
|
20
|
+
'constructor',
|
|
21
|
+
'prototype',
|
|
22
|
+
];
|
|
23
|
+
export function isReservedExecutionContextKey(key) {
|
|
24
|
+
return (key.startsWith(BREAKWATER_KEY_PREFIX) ||
|
|
25
|
+
key === GOAL_REQUEST_CONTEXT_KEY ||
|
|
26
|
+
key === 'runId' ||
|
|
27
|
+
key === 'threadId' ||
|
|
28
|
+
key === 'resourceId' ||
|
|
29
|
+
key === '__proto__' ||
|
|
30
|
+
key === 'constructor' ||
|
|
31
|
+
key === 'prototype');
|
|
32
|
+
}
|
|
33
|
+
export function findReservedExecutionContextKey(context) {
|
|
34
|
+
return Object.keys(context).find(isReservedExecutionContextKey);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sanitize a persisted compatibility context. External request boundaries
|
|
38
|
+
* must reject reserved keys with assertNoReservedExecutionContext instead.
|
|
39
|
+
*/
|
|
40
|
+
export function stripReservedExecutionContext(context) {
|
|
41
|
+
const safe = {};
|
|
42
|
+
if (!context)
|
|
43
|
+
return safe;
|
|
44
|
+
for (const [key, value] of Object.entries(context)) {
|
|
45
|
+
if (!isReservedExecutionContextKey(key)) {
|
|
46
|
+
Object.defineProperty(safe, key, {
|
|
47
|
+
value,
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return safe;
|
|
55
|
+
}
|
|
56
|
+
export class ReservedExecutionContextError extends Error {
|
|
57
|
+
key;
|
|
58
|
+
constructor(key, label = 'requestContext') {
|
|
59
|
+
super(`${label} may not carry the reserved key '${key}'`);
|
|
60
|
+
this.name = 'ReservedExecutionContextError';
|
|
61
|
+
this.key = key;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function assertNoReservedExecutionContext(context, label) {
|
|
65
|
+
const key = findReservedExecutionContextKey(context);
|
|
66
|
+
if (key !== undefined) {
|
|
67
|
+
throw new ReservedExecutionContextError(key, label);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=execution-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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,GAAG,EAAE;gBAC/B,KAAK;gBACL,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAC7C,GAAG,CAAS;IAErB,YAAY,GAAW,EAAE,KAAK,GAAG,gBAAgB;QAC/C,KAAK,CAAC,GAAG,KAAK,oCAAoC,GAAG,GAAG,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;QAC5C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AAED,MAAM,UAAU,gCAAgC,CAC9C,OAAgC,EAChC,KAAc;IAEd,MAAM,GAAG,GAAG,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,6BAA6B,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
|
@@ -8,8 +8,8 @@ import type { HubDurableObjectState, WebSocketLike } from './cf-types.js';
|
|
|
8
8
|
* `event.record.tenantId` (the defense-in-depth tenant assertion) and
|
|
9
9
|
* re-serializes the whole event to subscribers, so this local subset is
|
|
10
10
|
* sufficient. The real ApprovalStreamEvent (approval-api/contract.ts) is
|
|
11
|
-
* bridged onto the hub's POST body
|
|
12
|
-
*
|
|
11
|
+
* bridged onto the hub's POST body by host-kit through `createHubTopology`,
|
|
12
|
+
* which may import both packages.
|
|
13
13
|
*/
|
|
14
14
|
export interface HubStreamEvent {
|
|
15
15
|
record: {
|
|
@@ -3,6 +3,7 @@ export type { D1StorageOptions, PurgeExpiredBackgroundTasksOptions, PurgeExpired
|
|
|
3
3
|
export { BACKGROUND_TASK_TTL_PURGE_TABLES, createD1Storage, d1Changes, ensureSnapshotRunIdIndex, NOTIFICATION_TTL_PURGE_TABLES, purgeExpiredBackgroundTasks, purgeExpiredNotifications, purgeExpiredScheduleTriggers, purgeExpiredThreadState, purgeExpiredThreads, purgeExpiredWorkflowRuns, purgeTenant, RUN_TTL_PURGE_TABLES, SCHEDULE_TRIGGER_TTL_PURGE_TABLES, TENANT_METADATA_PURGE_TABLES, TENANT_RANGE_PURGE_TABLES, THREAD_STATE_TTL_PURGE_TABLES, THREAD_TTL_PURGE_TABLES, } from './d1-storage.js';
|
|
4
4
|
export { DoStatusError, doErrorResponse } from './do-error-response.js';
|
|
5
5
|
export { DurableObjectRunner } from './durable-object.js';
|
|
6
|
+
export { assertNoReservedExecutionContext, findReservedExecutionContextKey, isReservedExecutionContextKey, RESERVED_EXECUTION_CONTEXT_KEYS, ReservedExecutionContextError, stripReservedExecutionContext, } from './execution-context.js';
|
|
6
7
|
export type { HubStreamEvent, PresenceMember } from './hub-do.js';
|
|
7
8
|
export { HubDurableObject } from './hub-do.js';
|
|
8
9
|
export type { DORunnerEnv, InitOptions, InitResult, InitSource, } from './init.js';
|
|
@@ -17,5 +18,5 @@ export type { RequestContextProvider, ResumeRunOptions, RunLeg, RunnerRuntimeOpt
|
|
|
17
18
|
export { InvalidRunRequestError, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, UnknownRunError, UnknownWorkflowError, } from './runtime.js';
|
|
18
19
|
export type { ThreadScope } from './thread-do.js';
|
|
19
20
|
export { ThreadDurableObject, ThreadIdentityError } from './thread-do.js';
|
|
20
|
-
export { THREAD_ACTOR_HEADER, THREAD_TENANT_HEADER, } from './thread-header.js';
|
|
21
|
+
export { THREAD_ACTOR_HEADER, THREAD_ACTOR_ROLE_HEADER, THREAD_TENANT_HEADER, } from './thread-header.js';
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAMA,YAAY,EACV,iBAAiB,EACj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AAC3B,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,EACN,oBAAoB,EACpB,UAAU,EACV,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAMA,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,gBAAgB,EAChB,kCAAkC,EAClC,iCAAiC,EACjC,gCAAgC,EAChC,uBAAuB,EACvB,mCAAmC,EACnC,8BAA8B,EAC9B,0BAA0B,EAC1B,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gCAAgC,EAChC,eAAe,EACf,SAAS,EACT,wBAAwB,EACxB,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB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CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
package/dist/do-runner/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { BACKGROUND_TASK_TTL_PURGE_TABLES, createD1Storage, d1Changes, ensureSna
|
|
|
8
8
|
// status by extending DoStatusError (see do-error-response.ts).
|
|
9
9
|
export { DoStatusError, doErrorResponse } from './do-error-response.js';
|
|
10
10
|
export { DurableObjectRunner } from './durable-object.js';
|
|
11
|
+
export { assertNoReservedExecutionContext, findReservedExecutionContextKey, isReservedExecutionContextKey, RESERVED_EXECUTION_CONTEXT_KEYS, ReservedExecutionContextError, stripReservedExecutionContext, } from './execution-context.js';
|
|
11
12
|
export { HubDurableObject } from './hub-do.js';
|
|
12
13
|
export { init } from './init.js';
|
|
13
14
|
// Agent-memory tenancy chokepoint (docs/agent-memory-tenancy.md): the only
|
|
@@ -18,5 +19,5 @@ export { createHostPubSub } from './pubsub.js';
|
|
|
18
19
|
export { DurableStorageResumeLedger, InMemoryResumeLedger, } from './resume-ledger.js';
|
|
19
20
|
export { InvalidRunRequestError, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, UnknownRunError, UnknownWorkflowError, } from './runtime.js';
|
|
20
21
|
export { ThreadDurableObject, ThreadIdentityError } from './thread-do.js';
|
|
21
|
-
export { THREAD_ACTOR_HEADER, THREAD_TENANT_HEADER, } from './thread-header.js';
|
|
22
|
+
export { THREAD_ACTOR_HEADER, THREAD_ACTOR_ROLE_HEADER, THREAD_TENANT_HEADER, } from './thread-header.js';
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qEAAqE;AACrE,6EAA6E;AAC7E,qEAAqE;AACrE,yEAAyE;AA4BzE,OAAO,EACL,gCAAgC,EAChC,eAAe,EACf,SAAS,EACT,wBAAwB,EACxB,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,oBAAoB,EACpB,iCAAiC,EACjC,4BAA4B,EAC5B,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,gFAAgF;AAChF,gEAAgE;AAChE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qEAAqE;AACrE,6EAA6E;AAC7E,qEAAqE;AACrE,yEAAyE;AA4BzE,OAAO,EACL,gCAAgC,EAChC,eAAe,EACf,SAAS,EACT,wBAAwB,EACxB,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,oBAAoB,EACpB,iCAAiC,EACjC,4BAA4B,EAC5B,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,gFAAgF;AAChF,gEAAgE;AAChE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAO/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,2EAA2E;AAC3E,+DAA+D;AAC/D,OAAO,EACL,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAS5B,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
package/dist/do-runner/init.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface InitOptions {
|
|
|
30
30
|
*/
|
|
31
31
|
resumeLedger?: ResumeLedger;
|
|
32
32
|
/**
|
|
33
|
-
* The host
|
|
33
|
+
* The host Durable Object's single pubsub identity — `createHostPubSub()` for the
|
|
34
34
|
* default in-process emitter, or any PubSub the host built. init() is where a
|
|
35
35
|
* DO's identity is established: it echoes the instance on InitResult, so every
|
|
36
36
|
* consumer in the isolate takes THAT one rather than building its own (core
|
|
@@ -6,12 +6,12 @@ export declare function mintThreadId(tenantId: string, mintUuid?: () => string):
|
|
|
6
6
|
* lead id) and is deliberately stable across runs — two tenants using the
|
|
7
7
|
* SAME key stay disjoint because the prefix differs. The key must match the
|
|
8
8
|
* do-runner's PATH_SAFE_ID_PATTERN (RFC 3986 unreserved); '_' inside it is
|
|
9
|
-
* fine —
|
|
9
|
+
* fine — the tenant-ID pattern excludes '_' from tenant ids, so the first underscore is
|
|
10
10
|
* always the tenant boundary.
|
|
11
11
|
*/
|
|
12
12
|
export declare function mintResourceId(tenantId: string, resourceKey: string): string;
|
|
13
13
|
/**
|
|
14
|
-
* Recover the
|
|
14
|
+
* Recover the validated tenant prefix of a memory id (threadId or
|
|
15
15
|
* resourceId), or undefined when it carries none. Memory ids share the runId
|
|
16
16
|
* carrier deliberately, so this delegates to the ONE decode (`tenantOfRunId`)
|
|
17
17
|
* instead of growing a second parse that could drift.
|
|
@@ -20,7 +20,7 @@ export declare function tenantOfMemoryId(id: string): string | undefined;
|
|
|
20
20
|
/**
|
|
21
21
|
* Exact tenant ownership of a memory id — delegates to the ONE salted-id
|
|
22
22
|
* ownership predicate (`tenantOwnsSaltedId`) so memory and run ownership can
|
|
23
|
-
* never drift. Exact
|
|
23
|
+
* never drift. Exact because the '_' delimiter cannot occur
|
|
24
24
|
* inside a tenantId, so 'acme' can never own 'acmecorp_...'. Assert on EVERY
|
|
25
25
|
* memory read/write path.
|
|
26
26
|
*/
|
|
@@ -30,7 +30,7 @@ export function mintThreadId(tenantId, mintUuid = () => crypto.randomUUID()) {
|
|
|
30
30
|
* lead id) and is deliberately stable across runs — two tenants using the
|
|
31
31
|
* SAME key stay disjoint because the prefix differs. The key must match the
|
|
32
32
|
* do-runner's PATH_SAFE_ID_PATTERN (RFC 3986 unreserved); '_' inside it is
|
|
33
|
-
* fine —
|
|
33
|
+
* fine — the tenant-ID pattern excludes '_' from tenant ids, so the first underscore is
|
|
34
34
|
* always the tenant boundary.
|
|
35
35
|
*/
|
|
36
36
|
export function mintResourceId(tenantId, resourceKey) {
|
|
@@ -40,7 +40,7 @@ export function mintResourceId(tenantId, resourceKey) {
|
|
|
40
40
|
return mintSaltedId(tenantId, resourceKey, 'mintResourceId');
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Recover the
|
|
43
|
+
* Recover the validated tenant prefix of a memory id (threadId or
|
|
44
44
|
* resourceId), or undefined when it carries none. Memory ids share the runId
|
|
45
45
|
* carrier deliberately, so this delegates to the ONE decode (`tenantOfRunId`)
|
|
46
46
|
* instead of growing a second parse that could drift.
|
|
@@ -51,7 +51,7 @@ export function tenantOfMemoryId(id) {
|
|
|
51
51
|
/**
|
|
52
52
|
* Exact tenant ownership of a memory id — delegates to the ONE salted-id
|
|
53
53
|
* ownership predicate (`tenantOwnsSaltedId`) so memory and run ownership can
|
|
54
|
-
* never drift. Exact
|
|
54
|
+
* never drift. Exact because the '_' delimiter cannot occur
|
|
55
55
|
* inside a tenantId, so 'acme' can never own 'acmecorp_...'. Assert on EVERY
|
|
56
56
|
* memory read/write path.
|
|
57
57
|
*/
|
|
@@ -2,8 +2,8 @@ export declare const PATH_SAFE_ID_PATTERN: RegExp;
|
|
|
2
2
|
export declare const TENANT_ID_PATTERN: RegExp;
|
|
3
3
|
export declare const RESERVED_TENANT_IDS: readonly string[];
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
5
|
+
* The single place the `${tenantId}_${uuid}` carrier is decoded. Returns the
|
|
6
|
+
* validated tenant prefix, or undefined when the runId carries none.
|
|
7
7
|
*
|
|
8
8
|
* Centralized for the same reason RunnerRuntime composes `#runKey` in one
|
|
9
9
|
* place: this parse IS the tenant boundary, so four hand-rolled
|
|
@@ -12,13 +12,13 @@ export declare const RESERVED_TENANT_IDS: readonly string[];
|
|
|
12
12
|
* unscoped grant store is a cross-tenant mint), the grant provider mints an
|
|
13
13
|
* empty list, the runtime mints no isolation scope.
|
|
14
14
|
*
|
|
15
|
-
* Safe:
|
|
15
|
+
* Safe: the tenant-ID pattern excludes '_' from tenantId, so the first underscore is always
|
|
16
16
|
* the boundary regardless of what the uuid half contains.
|
|
17
17
|
*/
|
|
18
18
|
export declare function tenantOfRunId(runId: string): string | undefined;
|
|
19
19
|
/**
|
|
20
20
|
* Exact tenant-salted ownership: `id.startsWith(`${tenantId}_`)`. Exact because
|
|
21
|
-
* TENANT_ID_PATTERN
|
|
21
|
+
* TENANT_ID_PATTERN excludes '_' (0x5F) and backtick (0x60), so the
|
|
22
22
|
* FIRST '_' delimiter can never occur inside a tenantId — 'acme' can never own
|
|
23
23
|
* 'acmecorp_...'. The trailing '_' is load-bearing: it is the same delimiter the
|
|
24
24
|
* `[tid_, tid\x60)` range purge keys on, so dropping it would make 'acme' match
|
|
@@ -28,7 +28,7 @@ export declare function tenantOwnsSaltedId(tenantId: string, id: string): boolea
|
|
|
28
28
|
/**
|
|
29
29
|
* The MINT-path precondition: throws a GENERIC Error — the programmer-error
|
|
30
30
|
* contract, since a client never reaches a mint with a bad tenant — when
|
|
31
|
-
* `tenantId` fails TENANT_ID_PATTERN
|
|
31
|
+
* `tenantId` fails TENANT_ID_PATTERN or names a RESERVED_TENANT_IDS
|
|
32
32
|
* identity. Deliberately NOT a TenantResolutionError: createTenantResolver owns
|
|
33
33
|
* that request-facing 403 contract; the mints are internal. Shared by every
|
|
34
34
|
* salted-id mint (runIds and memory ids).
|
|
@@ -42,7 +42,7 @@ export declare function assertMintableTenantId(tenantId: string, caller: string)
|
|
|
42
42
|
*
|
|
43
43
|
* The suffix may be a thunk (a uuid generator): it is evaluated ONLY after the
|
|
44
44
|
* tenant passes assertMintableTenantId, so a caller-supplied producer can never
|
|
45
|
-
* run its side effects — or throw and mask
|
|
45
|
+
* run its side effects — or throw and mask tenant validation — for an
|
|
46
46
|
* invalid tenant. Callers with a callback MUST pass the function, not its call,
|
|
47
47
|
* or JS argument evaluation would defeat this ordering.
|
|
48
48
|
*/
|
|
@@ -48,8 +48,8 @@ export const TENANT_ID_PATTERN = /^[a-z0-9]{3,32}$/;
|
|
|
48
48
|
// re-exports it for the public surface.
|
|
49
49
|
export const RESERVED_TENANT_IDS = ['system'];
|
|
50
50
|
/**
|
|
51
|
-
* The
|
|
52
|
-
*
|
|
51
|
+
* The single place the `${tenantId}_${uuid}` carrier is decoded. Returns the
|
|
52
|
+
* validated tenant prefix, or undefined when the runId carries none.
|
|
53
53
|
*
|
|
54
54
|
* Centralized for the same reason RunnerRuntime composes `#runKey` in one
|
|
55
55
|
* place: this parse IS the tenant boundary, so four hand-rolled
|
|
@@ -58,7 +58,7 @@ export const RESERVED_TENANT_IDS = ['system'];
|
|
|
58
58
|
* unscoped grant store is a cross-tenant mint), the grant provider mints an
|
|
59
59
|
* empty list, the runtime mints no isolation scope.
|
|
60
60
|
*
|
|
61
|
-
* Safe:
|
|
61
|
+
* Safe: the tenant-ID pattern excludes '_' from tenantId, so the first underscore is always
|
|
62
62
|
* the boundary regardless of what the uuid half contains.
|
|
63
63
|
*/
|
|
64
64
|
export function tenantOfRunId(runId) {
|
|
@@ -70,7 +70,7 @@ export function tenantOfRunId(runId) {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Exact tenant-salted ownership: `id.startsWith(`${tenantId}_`)`. Exact because
|
|
73
|
-
* TENANT_ID_PATTERN
|
|
73
|
+
* TENANT_ID_PATTERN excludes '_' (0x5F) and backtick (0x60), so the
|
|
74
74
|
* FIRST '_' delimiter can never occur inside a tenantId — 'acme' can never own
|
|
75
75
|
* 'acmecorp_...'. The trailing '_' is load-bearing: it is the same delimiter the
|
|
76
76
|
* `[tid_, tid\x60)` range purge keys on, so dropping it would make 'acme' match
|
|
@@ -82,7 +82,7 @@ export function tenantOwnsSaltedId(tenantId, id) {
|
|
|
82
82
|
/**
|
|
83
83
|
* The MINT-path precondition: throws a GENERIC Error — the programmer-error
|
|
84
84
|
* contract, since a client never reaches a mint with a bad tenant — when
|
|
85
|
-
* `tenantId` fails TENANT_ID_PATTERN
|
|
85
|
+
* `tenantId` fails TENANT_ID_PATTERN or names a RESERVED_TENANT_IDS
|
|
86
86
|
* identity. Deliberately NOT a TenantResolutionError: createTenantResolver owns
|
|
87
87
|
* that request-facing 403 contract; the mints are internal. Shared by every
|
|
88
88
|
* salted-id mint (runIds and memory ids).
|
|
@@ -103,7 +103,7 @@ export function assertMintableTenantId(tenantId, caller) {
|
|
|
103
103
|
*
|
|
104
104
|
* The suffix may be a thunk (a uuid generator): it is evaluated ONLY after the
|
|
105
105
|
* tenant passes assertMintableTenantId, so a caller-supplied producer can never
|
|
106
|
-
* run its side effects — or throw and mask
|
|
106
|
+
* run its side effects — or throw and mask tenant validation — for an
|
|
107
107
|
* invalid tenant. Callers with a callback MUST pass the function, not its call,
|
|
108
108
|
* or JS argument evaluation would defeat this ordering.
|
|
109
109
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
2
3
|
import type { MastraCompositeStore } from '@mastra/core/storage';
|
|
3
4
|
import type { AnyWorkflow, WorkflowRunStatus } from '@mastra/core/workflows';
|
|
4
5
|
import type { HostPubSub } from './pubsub.js';
|
|
@@ -119,14 +120,14 @@ export interface RunnerRuntimeOptions {
|
|
|
119
120
|
*/
|
|
120
121
|
resumeLedger?: ResumeLedger;
|
|
121
122
|
/**
|
|
122
|
-
* The host
|
|
123
|
+
* The host Durable Object's single pubsub identity from do-runner/pubsub.ts, threaded
|
|
123
124
|
* here by init() alongside storage and the ledger so a host that configures it
|
|
124
125
|
* reaches the runtime with no host change: every DO subclass already returns
|
|
125
126
|
* init()'s runtime from build(), and nothing else in the isolate can hand this
|
|
126
127
|
* object a pubsub.
|
|
127
128
|
*
|
|
128
129
|
* PASSED TO CORE at the two `workflow.createRun({ runId, pubsub })` sites in
|
|
129
|
-
* start()/resume()
|
|
130
|
+
* start()/resume() — the only place core accepts one; the
|
|
130
131
|
* `pubsub` getter still exposes the held identity so an agent runner sharing
|
|
131
132
|
* this isolate takes THIS instance rather than building a second feed. Absent
|
|
132
133
|
* ⇒ undefined ⇒ core defaults a fresh emitter per run ⇒ byte-identical to
|
|
@@ -136,7 +137,7 @@ export interface RunnerRuntimeOptions {
|
|
|
136
137
|
}
|
|
137
138
|
export interface StartRunOptions {
|
|
138
139
|
/**
|
|
139
|
-
*
|
|
140
|
+
* Required: the runtime never generates a runId. Multi-tenant
|
|
140
141
|
* hosts mint `${tenantId}_${uuid}` server-side (createRunRouter) so the
|
|
141
142
|
* runId carries its tenant everywhere it becomes a key (D1 snapshot row,
|
|
142
143
|
* DO name, R2 segment, grant-list predicate). A generation fallback here
|
|
@@ -156,8 +157,7 @@ export declare class RunnerRuntime {
|
|
|
156
157
|
constructor(options: RunnerRuntimeOptions);
|
|
157
158
|
/**
|
|
158
159
|
* The host pubsub identity this runtime was built with, or undefined when the
|
|
159
|
-
* host configured none. Exposed so
|
|
160
|
-
* class (a private field held for a milestone is otherwise unobservable) and so
|
|
160
|
+
* host configured none. Exposed so callers can verify the identity and so
|
|
161
161
|
* an agent runner sharing this runtime's isolate takes THIS instance rather
|
|
162
162
|
* than building a second feed.
|
|
163
163
|
*/
|
|
@@ -181,5 +181,12 @@ export declare class RunnerRuntime {
|
|
|
181
181
|
*/
|
|
182
182
|
resume(workflowId: string, runId: string, options?: ResumeRunOptions): Promise<RunSummary>;
|
|
183
183
|
status(workflowId: string, runId: string): Promise<RunSummary | null>;
|
|
184
|
+
/**
|
|
185
|
+
* Derive the exact trusted context the next resume leg will receive without
|
|
186
|
+
* advancing the run. Durable-agent hosts use it while rehydrating the
|
|
187
|
+
* in-process registry, then call resume(); resume independently re-derives
|
|
188
|
+
* the same suspension fingerprint before execution.
|
|
189
|
+
*/
|
|
190
|
+
trustedRequestContextForResume(workflowId: string, runId: string, options?: Pick<ResumeRunOptions, 'step'>): Promise<RequestContext>;
|
|
184
191
|
}
|
|
185
192
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/do-runner/runtime.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/do-runner/runtime.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EACV,oBAAoB,EAErB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAElB,MAAM,wBAAwB,CAAC;AAShC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7E,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,UAAU,EAAE,MAAM;CAI/B;AAED,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAI9C;AAED,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;CAMzE;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;CAMzE;AAED,6EAA6E;AAC7E,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAyBD,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,S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CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,qBAAa,aAAa;;gBAgCZ,OAAO,EAAE,oBAAoB;IASzC;;;;;OAKG;IACH,IAAI,MAAM,IAAI,UAAU,GAAG,SAAS,CAEnC;IAED;;;;;;;OAOG;IACH,wBAAwB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAUpD,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IAiBrC,WAAW,IAAI,MAAM,EAAE;IAIjB,KAAK,CACT,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,UAAU,CAAC;IA2DtB;;;;OAIG;IACG,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,UAAU,CAAC;IAyDhB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAgB3E;;;;;OAKG;IACG,8BAA8B,CAClC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAM,GAC3C,OAAO,CAAC,cAAc,CAAC;CAoL3B"}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// (see durable-object.ts).
|
|
20
20
|
import { Mastra } from '@mastra/core/mastra';
|
|
21
21
|
import { RequestContext } from '@mastra/core/request-context';
|
|
22
|
-
import { BREAKWATER_ISOLATION_SCOPE_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, } from './breakwater-keys.js';
|
|
22
|
+
import { BREAKWATER_ACTOR_KEY, BREAKWATER_APPROVED_CONNECTORS_KEY, BREAKWATER_ISOLATION_SCOPE_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, } from './breakwater-keys.js';
|
|
23
23
|
import { PATH_SAFE_ID_PATTERN, tenantOfRunId } from './path-safe-id.js';
|
|
24
24
|
import { InMemoryResumeLedger } from './resume-ledger.js';
|
|
25
25
|
export class UnknownWorkflowError extends Error {
|
|
@@ -74,6 +74,61 @@ function asClientError(error) {
|
|
|
74
74
|
? new InvalidRunRequestError(error.message)
|
|
75
75
|
: undefined;
|
|
76
76
|
}
|
|
77
|
+
const NONTERMINAL_RUN_STATUSES = new Set([
|
|
78
|
+
'running',
|
|
79
|
+
'suspended',
|
|
80
|
+
'waiting',
|
|
81
|
+
'pending',
|
|
82
|
+
'paused',
|
|
83
|
+
]);
|
|
84
|
+
function terminalStateUpdate(result) {
|
|
85
|
+
if (NONTERMINAL_RUN_STATUSES.has(result.status))
|
|
86
|
+
return undefined;
|
|
87
|
+
const common = {
|
|
88
|
+
status: result.status,
|
|
89
|
+
result: undefined,
|
|
90
|
+
error: undefined,
|
|
91
|
+
suspendedPaths: {},
|
|
92
|
+
waitingPaths: {},
|
|
93
|
+
resumeLabels: {},
|
|
94
|
+
activePaths: [],
|
|
95
|
+
activeStepsPath: {},
|
|
96
|
+
};
|
|
97
|
+
if (result.status === 'success') {
|
|
98
|
+
return {
|
|
99
|
+
...common,
|
|
100
|
+
result: result.result,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (result.status === 'failed') {
|
|
104
|
+
const error = result.error;
|
|
105
|
+
const name = error instanceof Error
|
|
106
|
+
? error.name
|
|
107
|
+
: error !== null &&
|
|
108
|
+
typeof error === 'object' &&
|
|
109
|
+
'name' in error &&
|
|
110
|
+
typeof error.name === 'string'
|
|
111
|
+
? error.name
|
|
112
|
+
: 'Error';
|
|
113
|
+
const stack = error instanceof Error
|
|
114
|
+
? error.stack
|
|
115
|
+
: error !== null &&
|
|
116
|
+
typeof error === 'object' &&
|
|
117
|
+
'stack' in error &&
|
|
118
|
+
typeof error.stack === 'string'
|
|
119
|
+
? error.stack
|
|
120
|
+
: undefined;
|
|
121
|
+
return {
|
|
122
|
+
...common,
|
|
123
|
+
error: {
|
|
124
|
+
name,
|
|
125
|
+
message: errorText(error),
|
|
126
|
+
...(stack !== undefined ? { stack } : {}),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return common;
|
|
131
|
+
}
|
|
77
132
|
// Failed runs carry the step's thrown error as an Error instance, a string,
|
|
78
133
|
// or — once it crossed an engine/persistence boundary — a serialized
|
|
79
134
|
// { name, message, stack } object; String() on the last reads
|
|
@@ -231,6 +286,42 @@ function summarizeState(runId, state, counts) {
|
|
|
231
286
|
}
|
|
232
287
|
return summary;
|
|
233
288
|
}
|
|
289
|
+
const TRUSTED_IDENTITY_CONTEXT_KEYS = new Set([
|
|
290
|
+
BREAKWATER_ACTOR_KEY,
|
|
291
|
+
'breakwater.auditContext',
|
|
292
|
+
'runId',
|
|
293
|
+
'threadId',
|
|
294
|
+
'resourceId',
|
|
295
|
+
]);
|
|
296
|
+
function orderedRequestContext(runtimeContext, provided) {
|
|
297
|
+
const stored = [];
|
|
298
|
+
const capabilities = [];
|
|
299
|
+
const identity = [];
|
|
300
|
+
for (const entry of Object.entries(provided ?? {})) {
|
|
301
|
+
const [key] = entry;
|
|
302
|
+
if (key === BREAKWATER_WORKFLOW_SCOPE_KEY ||
|
|
303
|
+
key === BREAKWATER_ISOLATION_SCOPE_KEY) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (TRUSTED_IDENTITY_CONTEXT_KEYS.has(key)) {
|
|
307
|
+
identity.push(entry);
|
|
308
|
+
}
|
|
309
|
+
else if (key === BREAKWATER_APPROVED_CONNECTORS_KEY ||
|
|
310
|
+
key.startsWith('breakwater.') ||
|
|
311
|
+
key === 'mastra:goal') {
|
|
312
|
+
capabilities.push(entry);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
stored.push(entry);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return new RequestContext([
|
|
319
|
+
...stored,
|
|
320
|
+
...Object.entries(runtimeContext),
|
|
321
|
+
...capabilities,
|
|
322
|
+
...identity,
|
|
323
|
+
]);
|
|
324
|
+
}
|
|
234
325
|
export class RunnerRuntime {
|
|
235
326
|
#storage;
|
|
236
327
|
#logger;
|
|
@@ -272,8 +363,7 @@ export class RunnerRuntime {
|
|
|
272
363
|
}
|
|
273
364
|
/**
|
|
274
365
|
* The host pubsub identity this runtime was built with, or undefined when the
|
|
275
|
-
* host configured none. Exposed so
|
|
276
|
-
* class (a private field held for a milestone is otherwise unobservable) and so
|
|
366
|
+
* host configured none. Exposed so callers can verify the identity and so
|
|
277
367
|
* an agent runner sharing this runtime's isolate takes THIS instance rather
|
|
278
368
|
* than building a second feed.
|
|
279
369
|
*/
|
|
@@ -362,6 +452,7 @@ export class RunnerRuntime {
|
|
|
362
452
|
catch (error) {
|
|
363
453
|
throw asClientError(error) ?? error;
|
|
364
454
|
}
|
|
455
|
+
await this.#reconcileTerminalState(workflowId, run.runId, result);
|
|
365
456
|
return summarize(run.runId, result);
|
|
366
457
|
});
|
|
367
458
|
}
|
|
@@ -383,21 +474,7 @@ export class RunnerRuntime {
|
|
|
383
474
|
// Provider before createRun for symmetry with start(): a resume-time
|
|
384
475
|
// createRun only reattaches (no snapshot write), but failing before it
|
|
385
476
|
// still does the least work and keeps the ordering invariant uniform.
|
|
386
|
-
const
|
|
387
|
-
const stepKey = step?.join('.');
|
|
388
|
-
// resumeCount is read BEFORE this resume increments it: it is the count
|
|
389
|
-
// of prior resumes = the ordinal of the CURRENT suspension being resumed
|
|
390
|
-
// (undefined for a first suspension), which the minting approval captured
|
|
391
|
-
// at that suspension. suspendedAt still comes from the snapshot.
|
|
392
|
-
const priorCounts = await this.#resumeLedger.counts(runKey);
|
|
393
|
-
const requestContext = await this.#requestContextFor(workflowId, runId, {
|
|
394
|
-
kind: 'resume',
|
|
395
|
-
step,
|
|
396
|
-
suspendedAt: stepKey !== undefined
|
|
397
|
-
? suspendedAtOf(state.steps, stepKey)
|
|
398
|
-
: undefined,
|
|
399
|
-
resumeCount: stepKey !== undefined ? priorCounts?.get(stepKey) : undefined,
|
|
400
|
-
});
|
|
477
|
+
const { stepKey, priorCounts, requestContext } = await this.#trustedResumePreparation(workflowId, runId, state, options.step);
|
|
401
478
|
// Same host pubsub identity as start() (CI-M-002-002) — see the note
|
|
402
479
|
// there; undefined stays byte-identical to `createRun({ runId })`.
|
|
403
480
|
const run = await workflow.createRun({ runId, pubsub: this.#pubsub });
|
|
@@ -424,6 +501,7 @@ export class RunnerRuntime {
|
|
|
424
501
|
counts = await this.#resumeLedger.increment(runKey, stepKey, priorCounts ?? new Map());
|
|
425
502
|
}
|
|
426
503
|
const summary = summarize(run.runId, result, counts);
|
|
504
|
+
await this.#reconcileTerminalState(workflowId, run.runId, result);
|
|
427
505
|
// Terminal run: drop the ledger (no further suspension can occur).
|
|
428
506
|
if (summary.status !== 'suspended') {
|
|
429
507
|
await this.#resumeLedger.delete(runKey);
|
|
@@ -446,6 +524,22 @@ export class RunnerRuntime {
|
|
|
446
524
|
: undefined;
|
|
447
525
|
return summarizeState(runId, state, counts);
|
|
448
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* Derive the exact trusted context the next resume leg will receive without
|
|
529
|
+
* advancing the run. Durable-agent hosts use it while rehydrating the
|
|
530
|
+
* in-process registry, then call resume(); resume independently re-derives
|
|
531
|
+
* the same suspension fingerprint before execution.
|
|
532
|
+
*/
|
|
533
|
+
async trustedRequestContextForResume(workflowId, runId, options = {}) {
|
|
534
|
+
const workflow = this.#getWorkflow(workflowId);
|
|
535
|
+
const state = await workflow.getWorkflowRunById(runId);
|
|
536
|
+
if (!state)
|
|
537
|
+
throw new UnknownRunError(workflowId, runId);
|
|
538
|
+
if (state.status !== 'suspended') {
|
|
539
|
+
throw new RunNotSuspendedError(workflowId, runId, state.status);
|
|
540
|
+
}
|
|
541
|
+
return (await this.#trustedResumePreparation(workflowId, runId, state, options.step)).requestContext;
|
|
542
|
+
}
|
|
449
543
|
// A provider crash propagates (fail loud): silently starting the leg with
|
|
450
544
|
// fewer capabilities than intended would mask the fault. Missing grants can
|
|
451
545
|
// only ever deny downstream (fail closed), so loud propagation is safe.
|
|
@@ -453,8 +547,9 @@ export class RunnerRuntime {
|
|
|
453
547
|
// Every leg — provider or not — carries a base context minting the
|
|
454
548
|
// workflow-scope key (breakwater's crossWorkflowIsolation reads it): the
|
|
455
549
|
// runtime is the trusted authority for "which workflow is executing", so
|
|
456
|
-
// the scope is never client-suppliable. Provider values
|
|
457
|
-
//
|
|
550
|
+
// the scope is never client-suppliable. Provider values are partitioned into
|
|
551
|
+
// stored application context, capabilities, and trusted identity so every
|
|
552
|
+
// layer has an explicit order and a provider cannot replace runtime scope.
|
|
458
553
|
async #requestContextFor(workflowId, runId, leg) {
|
|
459
554
|
const base = {
|
|
460
555
|
[BREAKWATER_WORKFLOW_SCOPE_KEY]: workflowId,
|
|
@@ -486,7 +581,49 @@ export class RunnerRuntime {
|
|
|
486
581
|
const values = this.#requestContextForRun
|
|
487
582
|
? await this.#requestContextForRun(workflowId, runId, leg)
|
|
488
583
|
: undefined;
|
|
489
|
-
return
|
|
584
|
+
return orderedRequestContext(base, values);
|
|
585
|
+
}
|
|
586
|
+
async #trustedResumePreparation(workflowId, runId, state, selectedStep) {
|
|
587
|
+
const step = resolveResumeStep(selectedStep, state);
|
|
588
|
+
const stepKey = step?.join('.');
|
|
589
|
+
// resumeCount is read BEFORE this resume increments it: it is the count
|
|
590
|
+
// of prior resumes = the ordinal of the CURRENT suspension being resumed
|
|
591
|
+
// (undefined for a first suspension), which the minting approval captured.
|
|
592
|
+
const priorCounts = await this.#resumeLedger.counts(this.#runKey(workflowId, runId));
|
|
593
|
+
const requestContext = await this.#requestContextFor(workflowId, runId, {
|
|
594
|
+
kind: 'resume',
|
|
595
|
+
step,
|
|
596
|
+
suspendedAt: stepKey !== undefined ? suspendedAtOf(state.steps, stepKey) : undefined,
|
|
597
|
+
resumeCount: stepKey !== undefined ? priorCounts?.get(stepKey) : undefined,
|
|
598
|
+
});
|
|
599
|
+
return { stepKey, priorCounts, requestContext };
|
|
600
|
+
}
|
|
601
|
+
async #reconcileTerminalState(workflowId, runId, result) {
|
|
602
|
+
const opts = terminalStateUpdate(result);
|
|
603
|
+
if (!opts)
|
|
604
|
+
return;
|
|
605
|
+
const workflows = await this.#storage.getStore('workflows');
|
|
606
|
+
if (!workflows) {
|
|
607
|
+
throw new Error('RunnerRuntime: workflows storage is unavailable while persisting terminal state');
|
|
608
|
+
}
|
|
609
|
+
const snapshot = await workflows.loadWorkflowSnapshot({
|
|
610
|
+
workflowName: workflowId,
|
|
611
|
+
runId,
|
|
612
|
+
});
|
|
613
|
+
if (!snapshot) {
|
|
614
|
+
throw new Error(`RunnerRuntime: run '${runId}' of workflow '${workflowId}' completed without a durable snapshot`);
|
|
615
|
+
}
|
|
616
|
+
if (snapshot.status === result.status)
|
|
617
|
+
return;
|
|
618
|
+
await workflows.persistWorkflowSnapshot({
|
|
619
|
+
workflowName: workflowId,
|
|
620
|
+
runId,
|
|
621
|
+
snapshot: {
|
|
622
|
+
...snapshot,
|
|
623
|
+
...opts,
|
|
624
|
+
timestamp: Date.now(),
|
|
625
|
+
},
|
|
626
|
+
});
|
|
490
627
|
}
|
|
491
628
|
#getWorkflow(workflowId) {
|
|
492
629
|
this.#ensureMastra();
|