@proofoftech/flowsafe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +202 -0
- package/README.md +273 -0
- package/dist/approval-api/contract.d.ts +45 -0
- package/dist/approval-api/contract.d.ts.map +1 -0
- package/dist/approval-api/contract.js +37 -0
- package/dist/approval-api/contract.js.map +1 -0
- package/dist/approval-api/d1-store.d.ts +52 -0
- package/dist/approval-api/d1-store.d.ts.map +1 -0
- package/dist/approval-api/d1-store.js +468 -0
- package/dist/approval-api/d1-store.js.map +1 -0
- package/dist/approval-api/grants.d.ts +52 -0
- package/dist/approval-api/grants.d.ts.map +1 -0
- package/dist/approval-api/grants.js +200 -0
- package/dist/approval-api/grants.js.map +1 -0
- package/dist/approval-api/index.d.ts +21 -0
- package/dist/approval-api/index.d.ts.map +1 -0
- package/dist/approval-api/index.js +18 -0
- package/dist/approval-api/index.js.map +1 -0
- package/dist/approval-api/retention.d.ts +32 -0
- package/dist/approval-api/retention.d.ts.map +1 -0
- package/dist/approval-api/retention.js +81 -0
- package/dist/approval-api/retention.js.map +1 -0
- package/dist/approval-api/router.d.ts +51 -0
- package/dist/approval-api/router.d.ts.map +1 -0
- package/dist/approval-api/router.js +245 -0
- package/dist/approval-api/router.js.map +1 -0
- package/dist/approval-api/service.d.ts +134 -0
- package/dist/approval-api/service.d.ts.map +1 -0
- package/dist/approval-api/service.js +537 -0
- package/dist/approval-api/service.js.map +1 -0
- package/dist/approval-api/store.d.ts +126 -0
- package/dist/approval-api/store.d.ts.map +1 -0
- package/dist/approval-api/store.js +189 -0
- package/dist/approval-api/store.js.map +1 -0
- package/dist/approval-api/tenant-brand.d.ts +35 -0
- package/dist/approval-api/tenant-brand.d.ts.map +1 -0
- package/dist/approval-api/tenant-brand.js +18 -0
- package/dist/approval-api/tenant-brand.js.map +1 -0
- package/dist/approval-api/tenant-context.d.ts +44 -0
- package/dist/approval-api/tenant-context.d.ts.map +1 -0
- package/dist/approval-api/tenant-context.js +49 -0
- package/dist/approval-api/tenant-context.js.map +1 -0
- package/dist/approval-api/tenant-store.d.ts +36 -0
- package/dist/approval-api/tenant-store.d.ts.map +1 -0
- package/dist/approval-api/tenant-store.js +122 -0
- package/dist/approval-api/tenant-store.js.map +1 -0
- package/dist/approval-api/types.d.ts +247 -0
- package/dist/approval-api/types.d.ts.map +1 -0
- package/dist/approval-api/types.js +157 -0
- package/dist/approval-api/types.js.map +1 -0
- package/dist/approval-ui/App.d.ts +11 -0
- package/dist/approval-ui/App.d.ts.map +1 -0
- package/dist/approval-ui/App.js +15 -0
- package/dist/approval-ui/App.js.map +1 -0
- package/dist/approval-ui/DetailView.d.ts +13 -0
- package/dist/approval-ui/DetailView.d.ts.map +1 -0
- package/dist/approval-ui/DetailView.js +20 -0
- package/dist/approval-ui/DetailView.js.map +1 -0
- package/dist/approval-ui/MetricsView.d.ts +7 -0
- package/dist/approval-ui/MetricsView.d.ts.map +1 -0
- package/dist/approval-ui/MetricsView.js +22 -0
- package/dist/approval-ui/MetricsView.js.map +1 -0
- package/dist/approval-ui/QueueView.d.ts +11 -0
- package/dist/approval-ui/QueueView.d.ts.map +1 -0
- package/dist/approval-ui/QueueView.js +59 -0
- package/dist/approval-ui/QueueView.js.map +1 -0
- package/dist/approval-ui/client.d.ts +34 -0
- package/dist/approval-ui/client.d.ts.map +1 -0
- package/dist/approval-ui/client.js +103 -0
- package/dist/approval-ui/client.js.map +1 -0
- package/dist/approval-ui/components.d.ts +125 -0
- package/dist/approval-ui/components.d.ts.map +1 -0
- package/dist/approval-ui/components.js +54 -0
- package/dist/approval-ui/components.js.map +1 -0
- package/dist/approval-ui/index.d.ts +21 -0
- package/dist/approval-ui/index.d.ts.map +1 -0
- package/dist/approval-ui/index.js +21 -0
- package/dist/approval-ui/index.js.map +1 -0
- package/dist/approval-ui/mount.d.ts +23 -0
- package/dist/approval-ui/mount.d.ts.map +1 -0
- package/dist/approval-ui/mount.js +17 -0
- package/dist/approval-ui/mount.js.map +1 -0
- package/dist/approval-ui/tips.d.ts +32 -0
- package/dist/approval-ui/tips.d.ts.map +1 -0
- package/dist/approval-ui/tips.js +32 -0
- package/dist/approval-ui/tips.js.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts +70 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.js +148 -0
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -0
- package/dist/approval-ui/view-model.d.ts +24 -0
- package/dist/approval-ui/view-model.d.ts.map +1 -0
- package/dist/approval-ui/view-model.js +62 -0
- package/dist/approval-ui/view-model.js.map +1 -0
- package/dist/artifacts/index.d.ts +123 -0
- package/dist/artifacts/index.d.ts.map +1 -0
- package/dist/artifacts/index.js +223 -0
- package/dist/artifacts/index.js.map +1 -0
- package/dist/audit-export/index.d.ts +71 -0
- package/dist/audit-export/index.d.ts.map +1 -0
- package/dist/audit-export/index.js +124 -0
- package/dist/audit-export/index.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +23 -0
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -0
- package/dist/do-runner/breakwater-keys.js +38 -0
- package/dist/do-runner/breakwater-keys.js.map +1 -0
- package/dist/do-runner/cf-types.d.ts +26 -0
- package/dist/do-runner/cf-types.d.ts.map +1 -0
- package/dist/do-runner/cf-types.js +13 -0
- package/dist/do-runner/cf-types.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +128 -0
- package/dist/do-runner/d1-storage.d.ts.map +1 -0
- package/dist/do-runner/d1-storage.js +287 -0
- package/dist/do-runner/d1-storage.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +28 -0
- package/dist/do-runner/durable-object.d.ts.map +1 -0
- package/dist/do-runner/durable-object.js +164 -0
- package/dist/do-runner/durable-object.js.map +1 -0
- package/dist/do-runner/index.d.ts +12 -0
- package/dist/do-runner/index.d.ts.map +1 -0
- package/dist/do-runner/index.js +11 -0
- package/dist/do-runner/index.js.map +1 -0
- package/dist/do-runner/init.d.ts +38 -0
- package/dist/do-runner/init.d.ts.map +1 -0
- package/dist/do-runner/init.js +45 -0
- package/dist/do-runner/init.js.map +1 -0
- package/dist/do-runner/path-safe-id.d.ts +19 -0
- package/dist/do-runner/path-safe-id.d.ts.map +1 -0
- package/dist/do-runner/path-safe-id.js +70 -0
- package/dist/do-runner/path-safe-id.js.map +1 -0
- package/dist/do-runner/resume-ledger.d.ts +48 -0
- package/dist/do-runner/resume-ledger.d.ts.map +1 -0
- package/dist/do-runner/resume-ledger.js +59 -0
- package/dist/do-runner/resume-ledger.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +161 -0
- package/dist/do-runner/runtime.d.ts.map +1 -0
- package/dist/do-runner/runtime.js +509 -0
- package/dist/do-runner/runtime.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +109 -0
- package/dist/host-kit/approval-bridge.d.ts.map +1 -0
- package/dist/host-kit/approval-bridge.js +262 -0
- package/dist/host-kit/approval-bridge.js.map +1 -0
- package/dist/host-kit/bearer-auth.d.ts +19 -0
- package/dist/host-kit/bearer-auth.d.ts.map +1 -0
- package/dist/host-kit/bearer-auth.js +67 -0
- package/dist/host-kit/bearer-auth.js.map +1 -0
- package/dist/host-kit/do-response.d.ts +13 -0
- package/dist/host-kit/do-response.d.ts.map +1 -0
- package/dist/host-kit/do-response.js +24 -0
- package/dist/host-kit/do-response.js.map +1 -0
- package/dist/host-kit/do-run-topology.d.ts +32 -0
- package/dist/host-kit/do-run-topology.d.ts.map +1 -0
- package/dist/host-kit/do-run-topology.js +39 -0
- package/dist/host-kit/do-run-topology.js.map +1 -0
- package/dist/host-kit/env-vars.d.ts +26 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -0
- package/dist/host-kit/env-vars.js +48 -0
- package/dist/host-kit/env-vars.js.map +1 -0
- package/dist/host-kit/host-approval-service.d.ts +125 -0
- package/dist/host-kit/host-approval-service.d.ts.map +1 -0
- package/dist/host-kit/host-approval-service.js +187 -0
- package/dist/host-kit/host-approval-service.js.map +1 -0
- package/dist/host-kit/index.d.ts +18 -0
- package/dist/host-kit/index.d.ts.map +1 -0
- package/dist/host-kit/index.js +34 -0
- package/dist/host-kit/index.js.map +1 -0
- package/dist/host-kit/module.d.ts +34 -0
- package/dist/host-kit/module.d.ts.map +1 -0
- package/dist/host-kit/module.js +17 -0
- package/dist/host-kit/module.js.map +1 -0
- package/dist/host-kit/registration.d.ts +11 -0
- package/dist/host-kit/registration.d.ts.map +1 -0
- package/dist/host-kit/registration.js +21 -0
- package/dist/host-kit/registration.js.map +1 -0
- package/dist/host-kit/run-route-error.d.ts +11 -0
- package/dist/host-kit/run-route-error.d.ts.map +1 -0
- package/dist/host-kit/run-route-error.js +22 -0
- package/dist/host-kit/run-route-error.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +60 -0
- package/dist/host-kit/run-router.d.ts.map +1 -0
- package/dist/host-kit/run-router.js +212 -0
- package/dist/host-kit/run-router.js.map +1 -0
- package/dist/host-kit/subdomain-check.d.ts +23 -0
- package/dist/host-kit/subdomain-check.d.ts.map +1 -0
- package/dist/host-kit/subdomain-check.js +60 -0
- package/dist/host-kit/subdomain-check.js.map +1 -0
- package/dist/host-kit/tenant-registry.d.ts +51 -0
- package/dist/host-kit/tenant-registry.d.ts.map +1 -0
- package/dist/host-kit/tenant-registry.js +87 -0
- package/dist/host-kit/tenant-registry.js.map +1 -0
- package/dist/host-kit/verifier.d.ts +63 -0
- package/dist/host-kit/verifier.d.ts.map +1 -0
- package/dist/host-kit/verifier.js +191 -0
- package/dist/host-kit/verifier.js.map +1 -0
- package/dist/host-kit/workflow-meta.d.ts +25 -0
- package/dist/host-kit/workflow-meta.d.ts.map +1 -0
- package/dist/host-kit/workflow-meta.js +12 -0
- package/dist/host-kit/workflow-meta.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,eAAe,EACf,SAAS,EACT,wBAAwB,EACxB,wBAAwB,EACxB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,UAAU,GACX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Cloudflare Durable Objects workflow runner — the Cloudflare-native
|
|
2
|
+
// counterpart of @mastra/inngest / @mastra/temporal. init() returns DO-bound
|
|
3
|
+
// createWorkflow/createStep (import-swap); DurableObjectRunner hosts
|
|
4
|
+
// execution; D1 holds run snapshots so suspend/resume survives restarts.
|
|
5
|
+
export { createD1Storage, d1Changes, ensureSnapshotRunIdIndex, purgeExpiredWorkflowRuns, purgeTenant, } from './d1-storage.js';
|
|
6
|
+
export { DurableObjectRunner } from './durable-object.js';
|
|
7
|
+
export { init } from './init.js';
|
|
8
|
+
export { PATH_SAFE_ID_PATTERN, TENANT_ID_PATTERN, tenantOfRunId, } from './path-safe-id.js';
|
|
9
|
+
export { DurableStorageResumeLedger, InMemoryResumeLedger, } from './resume-ledger.js';
|
|
10
|
+
export { InvalidRunRequestError, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, UnknownRunError, UnknownWorkflowError, } from './runtime.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,6EAA6E;AAC7E,qEAAqE;AACrE,yEAAyE;AAezE,OAAO,EACL,eAAe,EACf,SAAS,EACT,wBAAwB,EACxB,wBAAwB,EACxB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAO1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MastraCompositeStore } from '@mastra/core/storage';
|
|
2
|
+
import { createWorkflow as coreCreateWorkflow, createStep } from '@mastra/core/workflows';
|
|
3
|
+
import type { D1DatabaseBinding } from './cf-types.js';
|
|
4
|
+
import type { ResumeLedger } from './resume-ledger.js';
|
|
5
|
+
import type { RequestContextProvider } from './runtime.js';
|
|
6
|
+
import { RunnerRuntime } from './runtime.js';
|
|
7
|
+
/** Workers env shape init() understands directly. */
|
|
8
|
+
export interface DORunnerEnv {
|
|
9
|
+
DB: D1DatabaseBinding;
|
|
10
|
+
}
|
|
11
|
+
/** Explicit storage takes precedence over a DB binding when both are present. */
|
|
12
|
+
export type InitSource = {
|
|
13
|
+
storage: MastraCompositeStore;
|
|
14
|
+
} | DORunnerEnv;
|
|
15
|
+
export interface InitOptions {
|
|
16
|
+
/** Storage instance id when init builds the D1 store. Default: 'flowsafe'. */
|
|
17
|
+
id?: string;
|
|
18
|
+
/** Table name prefix when init builds the D1 store. */
|
|
19
|
+
tablePrefix?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Server-side requestContext source consulted on every start/resume — the
|
|
22
|
+
* grant-minting seam. See RequestContextProvider in runtime.ts.
|
|
23
|
+
*/
|
|
24
|
+
requestContextForRun?: RequestContextProvider;
|
|
25
|
+
/**
|
|
26
|
+
* Explicit resume ledger (see RunnerRuntimeOptions.resumeLedger). When
|
|
27
|
+
* omitted, the runtime defaults to in-memory and the DO shell adopts a
|
|
28
|
+
* ctx.storage-backed ledger.
|
|
29
|
+
*/
|
|
30
|
+
resumeLedger?: ResumeLedger;
|
|
31
|
+
}
|
|
32
|
+
export interface InitResult {
|
|
33
|
+
createWorkflow: typeof coreCreateWorkflow;
|
|
34
|
+
createStep: typeof createStep;
|
|
35
|
+
runtime: RunnerRuntime;
|
|
36
|
+
}
|
|
37
|
+
export declare function init(source: InitSource, options?: InitOptions): InitResult;
|
|
38
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/do-runner/init.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,UAAU,EACX,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,iBAAiB,CAAC;CACvB;AAED,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,oBAAoB,CAAA;CAAE,GAAG,WAAW,CAAC;AAEzE,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,sBAAsB,CAAC;IAC9C;;;;OAIG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,OAAO,kBAAkB,CAAC;IAC1C,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,IAAI,CAClB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,WAAgB,GACxB,UAAU,CAmCZ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// init()-based import-swap, the pattern @mastra/inngest and @mastra/temporal
|
|
2
|
+
// ship: init(...) returns backend-bound createWorkflow/createStep imported in
|
|
3
|
+
// place of the @mastra/core/workflows versions, leaving workflow definition
|
|
4
|
+
// code unchanged. Like @mastra/temporal, createStep passes through unmodified;
|
|
5
|
+
// createWorkflow registers the workflow on the runner runtime.
|
|
6
|
+
//
|
|
7
|
+
// init takes the Workers env (conventional `DB` D1 binding) or an explicit
|
|
8
|
+
// { storage } (tests, other adapters) — rather than raw env only — because
|
|
9
|
+
// binding names are deploy-specific and Workers env objects only exist inside
|
|
10
|
+
// handlers/DO constructors, never at module scope.
|
|
11
|
+
import { createWorkflow as coreCreateWorkflow, createStep, } from '@mastra/core/workflows';
|
|
12
|
+
import { createD1Storage } from './d1-storage.js';
|
|
13
|
+
import { RunnerRuntime } from './runtime.js';
|
|
14
|
+
export function init(source, options = {}) {
|
|
15
|
+
let storage;
|
|
16
|
+
if ('storage' in source) {
|
|
17
|
+
if (options.id !== undefined || options.tablePrefix !== undefined) {
|
|
18
|
+
// Silently ignoring these would mask a misconfiguration: they only
|
|
19
|
+
// apply when init builds the D1 store itself.
|
|
20
|
+
throw new Error("init: 'id'/'tablePrefix' apply only when init builds the D1 store from env.DB — configure the passed storage instance directly");
|
|
21
|
+
}
|
|
22
|
+
storage = source.storage;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
storage = createD1Storage({
|
|
26
|
+
binding: source.DB,
|
|
27
|
+
id: options.id,
|
|
28
|
+
tablePrefix: options.tablePrefix,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const runtime = new RunnerRuntime({
|
|
32
|
+
storage,
|
|
33
|
+
requestContextForRun: options.requestContextForRun,
|
|
34
|
+
resumeLedger: options.resumeLedger,
|
|
35
|
+
});
|
|
36
|
+
// Cast preserves core's generic call-site inference (6 type params); the
|
|
37
|
+
// wrapper body is inference-erased but only registers and returns.
|
|
38
|
+
const boundCreateWorkflow = ((params) => {
|
|
39
|
+
const workflow = coreCreateWorkflow(params);
|
|
40
|
+
runtime.register(workflow);
|
|
41
|
+
return workflow;
|
|
42
|
+
});
|
|
43
|
+
return { createWorkflow: boundCreateWorkflow, createStep, runtime };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AAQ,CAAC,QAAuB,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC;IAClB,CAAC,CAA8B,CAAC;IAEhC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const PATH_SAFE_ID_PATTERN: RegExp;
|
|
2
|
+
export declare const TENANT_ID_PATTERN: RegExp;
|
|
3
|
+
export declare const RESERVED_TENANT_IDS: readonly string[];
|
|
4
|
+
/**
|
|
5
|
+
* The ONE place INV-1's `${tenantId}_${uuid}` carrier is decoded. Returns the
|
|
6
|
+
* INV-3-validated tenant prefix, or undefined when the runId carries none.
|
|
7
|
+
*
|
|
8
|
+
* Centralized for the same reason RunnerRuntime composes `#runKey` in one
|
|
9
|
+
* place: this parse IS the tenant boundary, so four hand-rolled
|
|
10
|
+
* `indexOf('_')` decodes would drift (and did — one skipped the pattern
|
|
11
|
+
* check). Callers apply their own policy on undefined: the DO throws (an
|
|
12
|
+
* unscoped grant store is a cross-tenant mint), the grant provider mints an
|
|
13
|
+
* empty list, the runtime mints no isolation scope.
|
|
14
|
+
*
|
|
15
|
+
* Safe: INV-3 excludes '_' from tenantId, so the FIRST underscore is always
|
|
16
|
+
* the boundary regardless of what the uuid half contains.
|
|
17
|
+
*/
|
|
18
|
+
export declare function tenantOfRunId(runId: string): string | undefined;
|
|
19
|
+
//# sourceMappingURL=path-safe-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-safe-id.d.ts","sourceRoot":"","sources":["../../src/do-runner/path-safe-id.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,oBAAoB,QAAuC,CAAC;AAmBzE,eAAO,MAAM,iBAAiB,QAAqB,CAAC;AAapD,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAAe,CAAC;AAEjE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK/D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Path-safe id pattern — a leaf module (zero imports) the do-runner owns.
|
|
2
|
+
//
|
|
3
|
+
// The pattern lives HERE, not in runtime.ts, so consumers that only need the
|
|
4
|
+
// validation (artifacts/ keys R2 objects by these same ids) can import it
|
|
5
|
+
// without transitively loading runtime.ts — which value-imports @mastra/core
|
|
6
|
+
// and the whole RunnerRuntime. Same reasoning as breakwater-keys.ts: a shared
|
|
7
|
+
// constant belongs in a leaf so it never forces a heavy import.
|
|
8
|
+
//
|
|
9
|
+
// A runId or workflowId flows into three addressing contexts that must agree
|
|
10
|
+
// with zero encoding: the D1 snapshot key, the Durable Object name join
|
|
11
|
+
// (idFromName(`${workflowId}:${runId}`)), and the `/runs/:workflowId/:runId`
|
|
12
|
+
// URL path. Restricting both ids to RFC 3986 unreserved characters keeps them
|
|
13
|
+
// unambiguous in all three: no '/' (path split), no '%' (percent-encoding),
|
|
14
|
+
// no ':' (name join), no whitespace. The leading (?!\.\.?$) also rejects the
|
|
15
|
+
// bare dot-segments '.' and '..', which the URL parser normalizes out of the
|
|
16
|
+
// status/resume path — a run created under one would never be addressable
|
|
17
|
+
// again. Generated UUIDs, ULIDs, nanoids, and slugs all satisfy it.
|
|
18
|
+
export const PATH_SAFE_ID_PATTERN = /^(?!\.\.?$)[A-Za-z0-9._~-]{1,200}$/;
|
|
19
|
+
// INV-3: the tenant id charset — STRICTER than PATH_SAFE_ID_PATTERN, and the
|
|
20
|
+
// two must never be conflated. Every runId is minted as `${tenantId}_${uuid}`
|
|
21
|
+
// and the tenant is recovered by prefix, so the charset is what makes the
|
|
22
|
+
// prefix EXACT. It is `0x30–0x39 ∪ 0x61–0x7A`, which contains no character in
|
|
23
|
+
// `[0x5F, 0x60]` — neither `_` (0x5F) nor backtick (0x60). Two consequences,
|
|
24
|
+
// both load-bearing:
|
|
25
|
+
//
|
|
26
|
+
// 1. Ownership is exact: `runId.startsWith(tenantId + '_')` cannot match
|
|
27
|
+
// another tenant ('acme' vs 'acmecorp': at index 4 one has '_' 0x5F, the
|
|
28
|
+
// other 'c' 0x63 — the delimiter cannot occur inside a tenantId).
|
|
29
|
+
// 2. The range purge is exact: `run_id >= '<tid>_' AND run_id < '<tid>' ||
|
|
30
|
+
// CHAR(0x60)` selects exactly one tenant's rows under BINARY collation
|
|
31
|
+
// (any other tenant's character at the delimiter position is < 0x5F or
|
|
32
|
+
// > 0x60, falling outside the range).
|
|
33
|
+
//
|
|
34
|
+
// Loosening this charset silently breaks BOTH properties —
|
|
35
|
+
// path-safe-id.test.ts pins it character-by-character.
|
|
36
|
+
export const TENANT_ID_PATTERN = /^[a-z0-9]{3,32}$/;
|
|
37
|
+
// Ids that collide with the TCB's own audit identity: the cron maintenance
|
|
38
|
+
// actor attributes sweeps and purges as tenantId 'system'. Never a valid
|
|
39
|
+
// tenantId ANYWHERE, enforced twice: toApprovalActor drops it at token
|
|
40
|
+
// verification, and createTenantResolver re-refuses it before any store binds
|
|
41
|
+
// or runId mints — a custom TokenVerifier (a supported seam) or a hand-built
|
|
42
|
+
// actor map handed to staticTokenVerifier never crosses toApprovalActor.
|
|
43
|
+
// (Audit-attribution collision, not privilege escalation: a
|
|
44
|
+
// SystemApprovalStore comes only from `.system()`, never from naming a
|
|
45
|
+
// tenant.) Lives in this leaf, not host-kit/tenant-registry, so approval-api
|
|
46
|
+
// can enforce it without importing host-kit against the layering; host-kit
|
|
47
|
+
// re-exports it for the public surface.
|
|
48
|
+
export const RESERVED_TENANT_IDS = ['system'];
|
|
49
|
+
/**
|
|
50
|
+
* The ONE place INV-1's `${tenantId}_${uuid}` carrier is decoded. Returns the
|
|
51
|
+
* INV-3-validated tenant prefix, or undefined when the runId carries none.
|
|
52
|
+
*
|
|
53
|
+
* Centralized for the same reason RunnerRuntime composes `#runKey` in one
|
|
54
|
+
* place: this parse IS the tenant boundary, so four hand-rolled
|
|
55
|
+
* `indexOf('_')` decodes would drift (and did — one skipped the pattern
|
|
56
|
+
* check). Callers apply their own policy on undefined: the DO throws (an
|
|
57
|
+
* unscoped grant store is a cross-tenant mint), the grant provider mints an
|
|
58
|
+
* empty list, the runtime mints no isolation scope.
|
|
59
|
+
*
|
|
60
|
+
* Safe: INV-3 excludes '_' from tenantId, so the FIRST underscore is always
|
|
61
|
+
* the boundary regardless of what the uuid half contains.
|
|
62
|
+
*/
|
|
63
|
+
export function tenantOfRunId(runId) {
|
|
64
|
+
const separator = runId.indexOf('_');
|
|
65
|
+
if (separator <= 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
const tenantId = runId.slice(0, separator);
|
|
68
|
+
return TENANT_ID_PATTERN.test(tenantId) ? tenantId : undefined;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=path-safe-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-safe-id.js","sourceRoot":"","sources":["../../src/do-runner/path-safe-id.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,6EAA6E;AAC7E,0EAA0E;AAC1E,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,oCAAoC,CAAC;AAEzE,6EAA6E;AAC7E,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAC9E,6EAA6E;AAC7E,qBAAqB;AACrB,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,uEAAuE;AACvE,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,2CAA2C;AAC3C,EAAE;AACF,2DAA2D;AAC3D,uDAAuD;AACvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAEpD,2EAA2E;AAC3E,yEAAyE;AACzE,uEAAuE;AACvE,8EAA8E;AAC9E,6EAA6E;AAC7E,yEAAyE;AACzE,4DAA4D;AAC5D,uEAAuE;AACvE,6EAA6E;AAC7E,2EAA2E;AAC3E,wCAAwC;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAsB,CAAC,QAAQ,CAAC,CAAC;AAEjE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACrC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3C,OAAO,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface ResumeLedger {
|
|
2
|
+
/**
|
|
3
|
+
* stepKey -> prior resume count for the run; undefined when the run has no
|
|
4
|
+
* recorded resumes. Read BEFORE an increment, the count is the ordinal of
|
|
5
|
+
* the suspension currently being resumed (undefined = first suspension).
|
|
6
|
+
*/
|
|
7
|
+
counts(runKey: string): Promise<ReadonlyMap<string, number> | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Record one more resume of stepKey; resolves to the run's updated counts.
|
|
10
|
+
* `prior` is a read-elision hint: the run's current counts as read by
|
|
11
|
+
* counts() under the SAME per-run lock, with nothing writing in between
|
|
12
|
+
* (an empty map when the run has none). An I/O-backed ledger uses it to
|
|
13
|
+
* skip re-reading what the lock guarantees unchanged; implementations with
|
|
14
|
+
* free reads may ignore it. Omit when no such fresh read exists.
|
|
15
|
+
*/
|
|
16
|
+
increment(runKey: string, stepKey: string, prior?: ReadonlyMap<string, number>): Promise<ReadonlyMap<string, number>>;
|
|
17
|
+
/** Drop the run's ledger — call only once the run is terminal. */
|
|
18
|
+
delete(runKey: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare class InMemoryResumeLedger implements ResumeLedger {
|
|
21
|
+
#private;
|
|
22
|
+
counts(runKey: string): Promise<ReadonlyMap<string, number> | undefined>;
|
|
23
|
+
increment(runKey: string, stepKey: string): Promise<ReadonlyMap<string, number>>;
|
|
24
|
+
delete(runKey: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Structural subset of DurableObjectStorage the ledger needs — a seam, so
|
|
28
|
+
* node tests can back it with a plain Map and this module needs no
|
|
29
|
+
* workers-only import.
|
|
30
|
+
*/
|
|
31
|
+
export interface ResumeLedgerStorage {
|
|
32
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
33
|
+
put<T>(key: string, value: T): Promise<void>;
|
|
34
|
+
delete(key: string): Promise<boolean>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* ctx.storage-backed ledger. One storage key per run; reads and writes ride
|
|
38
|
+
* the DO's own serialization (the runtime's per-run FIFO lock already orders
|
|
39
|
+
* the increment after the fingerprint read within one resume).
|
|
40
|
+
*/
|
|
41
|
+
export declare class DurableStorageResumeLedger implements ResumeLedger {
|
|
42
|
+
#private;
|
|
43
|
+
constructor(storage: ResumeLedgerStorage);
|
|
44
|
+
counts(runKey: string): Promise<ReadonlyMap<string, number> | undefined>;
|
|
45
|
+
increment(runKey: string, stepKey: string, prior?: ReadonlyMap<string, number>): Promise<ReadonlyMap<string, number>>;
|
|
46
|
+
delete(runKey: string): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=resume-ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume-ledger.d.ts","sourceRoot":"","sources":["../../src/do-runner/resume-ledger.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,YAAY;IAC3B;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M,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAK7C,SAAS,CACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAYjC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The per-run resume ledger: runKey (`${workflowId}:${runId}`, composed by
|
|
2
|
+
// RunnerRuntime.#runKey) -> (stepKey -> times that step has been resumed).
|
|
3
|
+
// The count is the grant-binding tie-breaker (RunLeg.resumeCount /
|
|
4
|
+
// RunSummary.resumeCount): approvals capture it at suspension time and the
|
|
5
|
+
// provider must see the same value on the resuming leg.
|
|
6
|
+
//
|
|
7
|
+
// Durability contract: a lost ledger is fail-closed for grants — the leg
|
|
8
|
+
// reads resumeCount undefined against an approval's captured ordinal, the
|
|
9
|
+
// pair mismatch denies, and the APPROVED action silently no-ops. That is an
|
|
10
|
+
// availability bug, not a leak, and it is exactly what a Durable Object
|
|
11
|
+
// eviction (~70-140s idle), hibernation, or code deploy does to in-memory
|
|
12
|
+
// state. ctx.storage survives all three, so the DO shell adopts
|
|
13
|
+
// DurableStorageResumeLedger (see durable-object.ts); InMemoryResumeLedger
|
|
14
|
+
// remains the default for node tests and non-DO hosts, preserving the
|
|
15
|
+
// pre-seam behavior exactly.
|
|
16
|
+
export class InMemoryResumeLedger {
|
|
17
|
+
#counts = new Map();
|
|
18
|
+
async counts(runKey) {
|
|
19
|
+
return this.#counts.get(runKey);
|
|
20
|
+
}
|
|
21
|
+
async increment(runKey, stepKey) {
|
|
22
|
+
const counts = this.#counts.get(runKey) ?? new Map();
|
|
23
|
+
counts.set(stepKey, (counts.get(stepKey) ?? 0) + 1);
|
|
24
|
+
this.#counts.set(runKey, counts);
|
|
25
|
+
return counts;
|
|
26
|
+
}
|
|
27
|
+
async delete(runKey) {
|
|
28
|
+
this.#counts.delete(runKey);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const KEY_PREFIX = 'flowsafe:resume-ledger:';
|
|
32
|
+
/**
|
|
33
|
+
* ctx.storage-backed ledger. One storage key per run; reads and writes ride
|
|
34
|
+
* the DO's own serialization (the runtime's per-run FIFO lock already orders
|
|
35
|
+
* the increment after the fingerprint read within one resume).
|
|
36
|
+
*/
|
|
37
|
+
export class DurableStorageResumeLedger {
|
|
38
|
+
#storage;
|
|
39
|
+
constructor(storage) {
|
|
40
|
+
this.#storage = storage;
|
|
41
|
+
}
|
|
42
|
+
async counts(runKey) {
|
|
43
|
+
const stored = await this.#storage.get(KEY_PREFIX + runKey);
|
|
44
|
+
return stored ? new Map(stored) : undefined;
|
|
45
|
+
}
|
|
46
|
+
async increment(runKey, stepKey, prior) {
|
|
47
|
+
const key = KEY_PREFIX + runKey;
|
|
48
|
+
// `prior` (read under the run lock) elides a second billed storage.get
|
|
49
|
+
// for the value the lock guarantees unchanged.
|
|
50
|
+
const counts = new Map(prior ?? (await this.#storage.get(key)) ?? []);
|
|
51
|
+
counts.set(stepKey, (counts.get(stepKey) ?? 0) + 1);
|
|
52
|
+
await this.#storage.put(key, [...counts.entries()]);
|
|
53
|
+
return counts;
|
|
54
|
+
}
|
|
55
|
+
async delete(runKey) {
|
|
56
|
+
await this.#storage.delete(KEY_PREFIX + runKey);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=resume-ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume-ledger.js","sourceRoot":"","sources":["../../src/do-runner/resume-ledger.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,mEAAmE;AACnE,2EAA2E;AAC3E,wDAAwD;AACxD,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC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Ae,EACf,KAAmC;QAEnC,MAAM,GAAG,GAAG,UAAU,GAAG,MAAM,CAAC;QAChC,uEAAuE;QACvE,+CAA+C;QAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAe,GAAG,CAAC,CAAC,IAAI,EAAE,CAC5D,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACpD,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
+
import type { MastraCompositeStore } from '@mastra/core/storage';
|
|
3
|
+
import type { AnyWorkflow, WorkflowRunStatus } from '@mastra/core/workflows';
|
|
4
|
+
import { type ResumeLedger } from './resume-ledger.js';
|
|
5
|
+
export declare class UnknownWorkflowError extends Error {
|
|
6
|
+
constructor(workflowId: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class UnknownRunError extends Error {
|
|
9
|
+
constructor(workflowId: string, runId: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class RunNotSuspendedError extends Error {
|
|
12
|
+
constructor(workflowId: string, runId: string, status: WorkflowRunStatus);
|
|
13
|
+
}
|
|
14
|
+
export declare class RunAlreadyExistsError extends Error {
|
|
15
|
+
constructor(workflowId: string, runId: string, status: WorkflowRunStatus);
|
|
16
|
+
}
|
|
17
|
+
/** A request the caller can fix: bad input/resume data or step selection. */
|
|
18
|
+
export declare class InvalidRunRequestError extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
/** JSON-safe projection of a workflow run outcome for HTTP transport. */
|
|
22
|
+
export interface RunSummary {
|
|
23
|
+
runId: string;
|
|
24
|
+
status: WorkflowRunStatus;
|
|
25
|
+
result?: unknown;
|
|
26
|
+
error?: string;
|
|
27
|
+
/** Suspended step paths, e.g. [['approval']]. Present when status is 'suspended'. */
|
|
28
|
+
suspended?: string[][];
|
|
29
|
+
/** Keyed by suspended step id, e.g. { approval: { reason } }. */
|
|
30
|
+
suspendPayload?: unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Epoch-ms suspension time per dot-joined suspended step key (core clock),
|
|
33
|
+
* e.g. { approval: 1751882400000 }. Present when status is 'suspended' and
|
|
34
|
+
* the snapshot recorded step timestamps. Approval bridges copy the resumed
|
|
35
|
+
* step's entry into CreateApprovalInput.suspendedAt so grant minting can
|
|
36
|
+
* bind the decision to this exact suspension (clock-free).
|
|
37
|
+
*/
|
|
38
|
+
suspendedAt?: Record<string, number>;
|
|
39
|
+
/**
|
|
40
|
+
* Epoch-ms resume time per dot-joined suspended step key (core clock).
|
|
41
|
+
* INFORMATIONAL audit metadata only — NOT the grant-binding tie-breaker
|
|
42
|
+
* (that is `resumeCount`). Mastra stamps it only on a payload-bearing
|
|
43
|
+
* resume, so it is absent for a first suspension AND for any re-suspension
|
|
44
|
+
* reached via a falsy resume; do not use its presence to tell a first
|
|
45
|
+
* suspension from a re-suspension.
|
|
46
|
+
*/
|
|
47
|
+
resumedAt?: Record<string, number>;
|
|
48
|
+
/**
|
|
49
|
+
* Runtime-owned monotonic per-step resume ordinal (dot-joined step key ->
|
|
50
|
+
* count). ABSENT for a step's first suspension (never resumed), `1` after
|
|
51
|
+
* the first resume, `2` after the second, and so on. This is the grant
|
|
52
|
+
* binding tie-breaker paired with `suspendedAt`: unlike `resumedAt` the
|
|
53
|
+
* runtime increments it on EVERY resume regardless of payload, so it is
|
|
54
|
+
* collision-free and cannot be erased by a same-ms suspendedAt collision or
|
|
55
|
+
* a no-payload resume. Approval bridges copy it into
|
|
56
|
+
* CreateApprovalInput.resumeCount.
|
|
57
|
+
*/
|
|
58
|
+
resumeCount?: Record<string, number>;
|
|
59
|
+
/** ISO 8601. Present on status() projections (read from the stored snapshot). */
|
|
60
|
+
createdAt?: string;
|
|
61
|
+
/** ISO 8601. Present on status() projections (read from the stored snapshot). */
|
|
62
|
+
updatedAt?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Which execution leg the provider is minting for. On resume, `step` is the
|
|
66
|
+
* resumed step's normalized path — taken from the caller's step selection,
|
|
67
|
+
* or resolved from the snapshot when exactly one step is suspended;
|
|
68
|
+
* undefined when the target step cannot be determined (ambiguous multi-step
|
|
69
|
+
* resume without an explicit selection). `suspendedAt` is the epoch-ms
|
|
70
|
+
* timestamp of that step's CURRENT suspension (from the persisted snapshot):
|
|
71
|
+
* providers bind capabilities to the specific suspension they were granted
|
|
72
|
+
* for — an approval decided before this suspension began belongs to an
|
|
73
|
+
* earlier incarnation of the gate and must not mint again (see flowsafe's
|
|
74
|
+
* approvalGrantProvider). `resumeCount` pairs with `suspendedAt` — the
|
|
75
|
+
* runtime-owned monotonic resume ordinal (undefined on a step's first
|
|
76
|
+
* suspension, `1,2,…` on successive re-suspensions) — so a provider can tell
|
|
77
|
+
* two same-step suspensions apart even when their `suspendedAt` stamps collide
|
|
78
|
+
* within a millisecond. It replaces the payload-conditional `resumedAt` as the
|
|
79
|
+
* tie-breaker: the runtime increments it on every resume, so no-payload
|
|
80
|
+
* resumes cannot erase the first-vs-re-suspension distinction.
|
|
81
|
+
*/
|
|
82
|
+
export type RunLeg = {
|
|
83
|
+
kind: 'start';
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'resume';
|
|
86
|
+
step?: string[];
|
|
87
|
+
suspendedAt?: number;
|
|
88
|
+
resumeCount?: number;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Server-side requestContext source, consulted on EVERY start and resume.
|
|
92
|
+
* This is the trusted-computing-base seam (security-threat-model.md, trust
|
|
93
|
+
* boundary 6): the DO HTTP boundary never maps requestContext from request
|
|
94
|
+
* bodies, so capability keys — e.g. breakwater's approval grants
|
|
95
|
+
* ('breakwater.approvedConnectors') — can only enter a run through this
|
|
96
|
+
* provider. Wire it to derive values from trusted server-side state (the
|
|
97
|
+
* flowsafe approval store), never from client input, model output, or tool
|
|
98
|
+
* results.
|
|
99
|
+
*
|
|
100
|
+
* Merge semantics (pinned by test against core 1.49.0): the context provided
|
|
101
|
+
* at resume merges OVER the run's persisted context — provided keys win,
|
|
102
|
+
* persisted start-time keys survive. Omitting a key therefore does not
|
|
103
|
+
* revoke it; a provider that scopes a capability per leg must return the key
|
|
104
|
+
* on EVERY leg (an empty value when nothing applies) so the overwrite
|
|
105
|
+
* retires stale grants.
|
|
106
|
+
*/
|
|
107
|
+
export type RequestContextProvider = (workflowId: string, runId: string, leg: RunLeg) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>;
|
|
108
|
+
export interface RunnerRuntimeOptions {
|
|
109
|
+
storage: MastraCompositeStore;
|
|
110
|
+
logger?: IMastraLogger | false;
|
|
111
|
+
/** Consulted on every start/resume — see RequestContextProvider. */
|
|
112
|
+
requestContextForRun?: RequestContextProvider;
|
|
113
|
+
/**
|
|
114
|
+
* Per-run resume ledger backing RunSummary.resumeCount / RunLeg.resumeCount.
|
|
115
|
+
* Default: in-memory. The DO shell adopts a ctx.storage-backed ledger via
|
|
116
|
+
* adoptDefaultResumeLedger() so the ordinal survives eviction — an explicit
|
|
117
|
+
* ledger here wins over that adoption.
|
|
118
|
+
*/
|
|
119
|
+
resumeLedger?: ResumeLedger;
|
|
120
|
+
}
|
|
121
|
+
export interface StartRunOptions {
|
|
122
|
+
/**
|
|
123
|
+
* REQUIRED — the runtime never generates a runId (INV-1). Multi-tenant
|
|
124
|
+
* hosts mint `${tenantId}_${uuid}` server-side (createRunRouter) so the
|
|
125
|
+
* runId carries its tenant everywhere it becomes a key (D1 snapshot row,
|
|
126
|
+
* DO name, R2 segment, grant-list predicate). A generation fallback here
|
|
127
|
+
* would let any caller that forgets to mint create a bare, tenant-less
|
|
128
|
+
* run — unreachable by tenant purge and un-ownable by every actor.
|
|
129
|
+
*/
|
|
130
|
+
runId: string;
|
|
131
|
+
inputData?: unknown;
|
|
132
|
+
}
|
|
133
|
+
export interface ResumeRunOptions {
|
|
134
|
+
/** Suspended step id (or nested path). Optional when only one step is suspended. */
|
|
135
|
+
step?: string | string[];
|
|
136
|
+
resumeData?: unknown;
|
|
137
|
+
}
|
|
138
|
+
export declare class RunnerRuntime {
|
|
139
|
+
#private;
|
|
140
|
+
constructor(options: RunnerRuntimeOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Host-shell seam: replace the DEFAULT in-memory ledger with a durable one.
|
|
143
|
+
* The DO shell calls this with a ctx.storage-backed ledger right after
|
|
144
|
+
* build(), so every DO host gets eviction-proof ordinals without threading
|
|
145
|
+
* a parameter (a forgettable thread is how the durability guarantee rots).
|
|
146
|
+
* A ledger explicitly injected via options wins; adoption is rejected once
|
|
147
|
+
* runs may have consulted the ledger.
|
|
148
|
+
*/
|
|
149
|
+
adoptDefaultResumeLedger(ledger: ResumeLedger): void;
|
|
150
|
+
register(workflow: AnyWorkflow): void;
|
|
151
|
+
workflowIds(): string[];
|
|
152
|
+
start(workflowId: string, options: StartRunOptions): Promise<RunSummary>;
|
|
153
|
+
/**
|
|
154
|
+
* Reattach to a suspended run — the designed fresh-process pattern:
|
|
155
|
+
* createRun({ runId }) does not clobber an existing snapshot; resume()
|
|
156
|
+
* loads it and re-enters the engine at the suspended step.
|
|
157
|
+
*/
|
|
158
|
+
resume(workflowId: string, runId: string, options?: ResumeRunOptions): Promise<RunSummary>;
|
|
159
|
+
status(workflowId: string, runId: string): Promise<RunSummary | null>;
|
|
160
|
+
}
|
|
161
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