@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,128 @@
|
|
|
1
|
+
import { D1Store } from '@mastra/cloudflare-d1';
|
|
2
|
+
import type { D1DatabaseBinding } from './cf-types.js';
|
|
3
|
+
export interface D1StorageOptions {
|
|
4
|
+
/** D1 binding from the Worker/DO environment. */
|
|
5
|
+
binding: D1DatabaseBinding;
|
|
6
|
+
/** Storage instance id. Default: 'flowsafe'. */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Table name prefix (letters, numbers, underscores). */
|
|
9
|
+
tablePrefix?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createD1Storage(options: D1StorageOptions): D1Store;
|
|
12
|
+
/**
|
|
13
|
+
* Minimal structural D1 surface the purge uses — same posture as the
|
|
14
|
+
* approval store: tests back it with node:sqlite, Workers pass env.DB.
|
|
15
|
+
*/
|
|
16
|
+
export interface SnapshotDatabase {
|
|
17
|
+
prepare(query: string): SnapshotStatement;
|
|
18
|
+
}
|
|
19
|
+
export interface SnapshotStatement {
|
|
20
|
+
bind(...values: unknown[]): SnapshotStatement;
|
|
21
|
+
run(): Promise<unknown>;
|
|
22
|
+
all<T = unknown>(): Promise<{
|
|
23
|
+
results: T[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
/** Structural: R2ArtifactStore.deleteRun, without importing the artifacts module. */
|
|
27
|
+
export interface TenantArtifactPurger {
|
|
28
|
+
deleteRun(workflowId: string, runId: string): Promise<number>;
|
|
29
|
+
}
|
|
30
|
+
export interface PurgeExpiredRunsOptions {
|
|
31
|
+
/** workflowOutputTTL: runs untouched for longer than this are eligible. */
|
|
32
|
+
ttlMs: number;
|
|
33
|
+
/** Must match createD1Storage's tablePrefix. */
|
|
34
|
+
tablePrefix?: string;
|
|
35
|
+
/**
|
|
36
|
+
* When set, each purged run's R2 artifacts are deleted WITH its snapshot
|
|
37
|
+
* row. Hosts that store artifacts must pass the same store purgeTenant
|
|
38
|
+
* gets: the snapshot row is the only enumerable record of a run's
|
|
39
|
+
* artifact keys (R2 keys lead with workflowId — there is no run-level
|
|
40
|
+
* listing without it), so a retention purge without this pairing strands
|
|
41
|
+
* the run's artifacts beyond even purgeTenant's reach.
|
|
42
|
+
*/
|
|
43
|
+
artifactStore?: TenantArtifactPurger;
|
|
44
|
+
/**
|
|
45
|
+
* Runs processed per call. Artifact-paired path: default 100 — the cron's
|
|
46
|
+
* subrequest-budget guard, same batching as the demo-tenant reaper. Each
|
|
47
|
+
* run costs ~2+N subrequests (R2 list, per-artifact deletes, its row's
|
|
48
|
+
* DELETE), so an UNBOUNDED first backlog would blow the Workers
|
|
49
|
+
* per-invocation cap mid-pass and log an error every firing until it
|
|
50
|
+
* drained; size this to your plan's budget instead. Row-only path:
|
|
51
|
+
* default 1000 — one LIMIT-batched DELETE statement per firing, bounding
|
|
52
|
+
* D1 per-query cost instead of subrequests. Both paths use the shrinking
|
|
53
|
+
* eligible set as the cursor — the next firing resumes at the survivors.
|
|
54
|
+
*/
|
|
55
|
+
limit?: number;
|
|
56
|
+
/** Clock override for tests. */
|
|
57
|
+
now?: () => number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Data-retention purge: deletes TERMINAL runs (success/failed/tripwire/
|
|
61
|
+
* canceled/bailed/skipped) whose updatedAt is older than the TTL from
|
|
62
|
+
* mastra_workflow_snapshot — and, when `artifactStore` is wired, each purged
|
|
63
|
+
* run's R2 artifacts with its row. Live runs (running/suspended/waiting/
|
|
64
|
+
* pending/paused) are never touched — expiring a suspended run would kill a
|
|
65
|
+
* pending approval. A missing snapshot table reads as zero purgeable runs
|
|
66
|
+
* (Mastra creates it lazily with the first persisted run). TTL enforcement
|
|
67
|
+
* is a storage-layer property, so it lives here; scheduling (Worker cron /
|
|
68
|
+
* DO alarm) stays with the caller. Returns the number of deleted rows.
|
|
69
|
+
*/
|
|
70
|
+
export declare function purgeExpiredWorkflowRuns(db: SnapshotDatabase, options: PurgeExpiredRunsOptions): Promise<number>;
|
|
71
|
+
/**
|
|
72
|
+
* Additive, app-owned index for the tenant range predicate. It couples us to
|
|
73
|
+
* Mastra's snapshot column name (`run_id`, snake_case — its timestamps are
|
|
74
|
+
* camelCase) — the schema-guard test pins that name so a @mastra/core bump
|
|
75
|
+
* that renames it fails CI, not a purge.
|
|
76
|
+
*/
|
|
77
|
+
export declare function ensureSnapshotRunIdIndex(db: SnapshotDatabase, tablePrefix?: string): Promise<void>;
|
|
78
|
+
export interface PurgeTenantOptions {
|
|
79
|
+
/** MUST satisfy INV-3 (^[a-z0-9]{3,32}$) — see the range note below. */
|
|
80
|
+
tenantId: string;
|
|
81
|
+
/** Must match createD1Storage's tablePrefix. */
|
|
82
|
+
tablePrefix?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The tenant's R2 artifacts are deleted per surviving run BEFORE the
|
|
85
|
+
* snapshot rows go (deleteRun needs the run list — snapshot rows are the
|
|
86
|
+
* only enumerable record of a run's artifact keys). That is also why the
|
|
87
|
+
* SAME store must ride purgeExpiredWorkflowRuns' `artifactStore`:
|
|
88
|
+
* retention deletes rows this offboarding can then no longer see, so an
|
|
89
|
+
* unpaired retention purge strands those runs' artifacts.
|
|
90
|
+
*/
|
|
91
|
+
artifactStore?: TenantArtifactPurger;
|
|
92
|
+
}
|
|
93
|
+
export interface PurgeTenantResult {
|
|
94
|
+
snapshots: number;
|
|
95
|
+
approvals: number;
|
|
96
|
+
artifacts: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Complete tenant offboarding: reaps ALL THREE stores — snapshot rows of ANY
|
|
100
|
+
* status (a tenant's suspended-and-abandoned runs are never eligible for the
|
|
101
|
+
* terminal-only retention purge at any age), the tenant's approval records
|
|
102
|
+
* (titles, summaries, payloads, decider identities), and its R2 artifacts.
|
|
103
|
+
*
|
|
104
|
+
* The snapshot predicate is a RANGE over the INV-1 salted runId:
|
|
105
|
+
* `run_id >= '<tid>_' AND run_id < '<tid>' || CHAR(0x60)`. tenantId is
|
|
106
|
+
* re-validated against INV-3 here — not for injection safety (every query is
|
|
107
|
+
* parameter-bound) but for RANGE-EXACTNESS: the predicate selects exactly one
|
|
108
|
+
* tenant only because the charset excludes every character in [0x5F, 0x60]
|
|
109
|
+
* ('_' is 0x5F; its successor 0x60, backtick, closes the range under BINARY
|
|
110
|
+
* collation). 'abc' can never sweep 'abcdefg'.
|
|
111
|
+
*
|
|
112
|
+
* PURGE POLICY (the race): this deletes SUSPENDED rows, and a reviewer
|
|
113
|
+
* approving at that moment would resume against a vanishing row (absorbed:
|
|
114
|
+
* the runtime's pre-check throws before any step re-executes — pinned by the
|
|
115
|
+
* purge-race regression test). Only purge tenants whose tokens have already
|
|
116
|
+
* expired, so no live caller can be mid-resume by construction — or purge at
|
|
117
|
+
* the tenant's own explicit request (the showcase's self-service /demo/reset).
|
|
118
|
+
* That caller, uniquely, can race ITSELF: a run started between the artifact
|
|
119
|
+
* SELECT and the snapshot DELETE is reaped by the DELETE (which re-reads the
|
|
120
|
+
* range) with its artifacts unenumerated, and the three statements are not one
|
|
121
|
+
* transaction — an R2 delete can never join a SQL one — so a mid-purge failure
|
|
122
|
+
* leaves it partially applied. Both are pinned in d1-storage.test.ts. Neither
|
|
123
|
+
* can escape the requester's own tenant: the range predicate is exact.
|
|
124
|
+
*/
|
|
125
|
+
export declare function purgeTenant(db: SnapshotDatabase, options: PurgeTenantOptions): Promise<PurgeTenantResult>;
|
|
126
|
+
/** Rows affected by a D1 write, read from its `{ meta: { changes } }` envelope. */
|
|
127
|
+
export declare function d1Changes(result: unknown): number;
|
|
128
|
+
//# sourceMappingURL=d1-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"d1-storage.d.ts","sourceRoot":"","sources":["../../src/do-runner/d1-storage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,MAAM,WAAW,gBA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EACpB,WAAW,SAAK,GACf,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,gBAAgB,EACpB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAwE5B;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAIjD"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// Roadmap Phase 1: "D1 storage adapter (wrap Mastra's)". The wrap pins
|
|
2
|
+
// flowsafe defaults and is the seam where audit export / Queues hooks
|
|
3
|
+
// attach in later phases. Table auto-creation (CREATE TABLE IF NOT EXISTS)
|
|
4
|
+
// happens lazily via Mastra's storage-init proxy once the store is handed
|
|
5
|
+
// to `new Mastra({ storage })` — no migration step needed for the runner.
|
|
6
|
+
import { D1Store } from '@mastra/cloudflare-d1';
|
|
7
|
+
import { TENANT_ID_PATTERN } from './path-safe-id.js';
|
|
8
|
+
export function createD1Storage(options) {
|
|
9
|
+
return new D1Store({
|
|
10
|
+
id: options.id ?? 'flowsafe',
|
|
11
|
+
// @mastra/cloudflare-d1's own D1Store signature wants the real
|
|
12
|
+
// D1Database; D1DatabaseBinding is the structural subset this package
|
|
13
|
+
// exposes instead, so consumers of its shipped types don't need
|
|
14
|
+
// @cloudflare/workers-types installed.
|
|
15
|
+
binding: options.binding,
|
|
16
|
+
...(options.tablePrefix !== undefined
|
|
17
|
+
? { tablePrefix: options.tablePrefix }
|
|
18
|
+
: {}),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// Terminal statuses per WorkflowRunStatus (@mastra/core workflows/types).
|
|
22
|
+
// Deleting a live run (running/suspended/waiting/pending/paused) would kill
|
|
23
|
+
// a pending approval, so only these are ever purged.
|
|
24
|
+
const TERMINAL_STATUSES = [
|
|
25
|
+
'success',
|
|
26
|
+
'failed',
|
|
27
|
+
'tripwire',
|
|
28
|
+
'canceled',
|
|
29
|
+
'bailed',
|
|
30
|
+
'skipped',
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Data-retention purge: deletes TERMINAL runs (success/failed/tripwire/
|
|
34
|
+
* canceled/bailed/skipped) whose updatedAt is older than the TTL from
|
|
35
|
+
* mastra_workflow_snapshot — and, when `artifactStore` is wired, each purged
|
|
36
|
+
* run's R2 artifacts with its row. Live runs (running/suspended/waiting/
|
|
37
|
+
* pending/paused) are never touched — expiring a suspended run would kill a
|
|
38
|
+
* pending approval. A missing snapshot table reads as zero purgeable runs
|
|
39
|
+
* (Mastra creates it lazily with the first persisted run). TTL enforcement
|
|
40
|
+
* is a storage-layer property, so it lives here; scheduling (Worker cron /
|
|
41
|
+
* DO alarm) stays with the caller. Returns the number of deleted rows.
|
|
42
|
+
*/
|
|
43
|
+
export async function purgeExpiredWorkflowRuns(db, options) {
|
|
44
|
+
const now = options.now ?? Date.now;
|
|
45
|
+
const prefix = options.tablePrefix ?? '';
|
|
46
|
+
// @mastra/cloudflare-d1 stores updatedAt as ISO-8601 TEXT
|
|
47
|
+
// (persistWorkflowSnapshot serializes via toISOString), so lexicographic
|
|
48
|
+
// < against an ISO cutoff is a correct timestamp comparison.
|
|
49
|
+
const cutoff = new Date(now() - options.ttlMs).toISOString();
|
|
50
|
+
const placeholders = TERMINAL_STATUSES.map(() => '?').join(', ');
|
|
51
|
+
// json_extract throws on malformed JSON and would abort the WHOLE delete —
|
|
52
|
+
// one corrupt row must not stop every valid terminal row from being
|
|
53
|
+
// reclaimed. The CASE guard (not `AND json_valid(...)`) is load-bearing:
|
|
54
|
+
// SQLite does not guarantee AND short-circuit order in a WHERE, so a bare
|
|
55
|
+
// conjunct could still evaluate the extract on the bad row. Unclassifiable
|
|
56
|
+
// rows yield NULL and survive (fail safe: never delete what can't be
|
|
57
|
+
// proven terminal).
|
|
58
|
+
const eligible = `updatedAt < ?
|
|
59
|
+
AND CASE
|
|
60
|
+
WHEN json_valid(snapshot)
|
|
61
|
+
THEN json_extract(snapshot, '$.status')
|
|
62
|
+
END IN (${placeholders})`;
|
|
63
|
+
if (options.artifactStore) {
|
|
64
|
+
// Artifact-paired path, run by run: artifacts BEFORE the row, because
|
|
65
|
+
// the row is the only record of the run's artifact keys — dying between
|
|
66
|
+
// the two leaves the row for the next sweep (deleteRun is idempotent),
|
|
67
|
+
// while row-first would strand the artifacts forever. Each deleted row
|
|
68
|
+
// is durable progress: a mid-pass crash or the LIMIT batch cap resumes
|
|
69
|
+
// at the survivors on the next firing, and per-run failures are
|
|
70
|
+
// isolated below so one wedged run cannot stall the rows behind it.
|
|
71
|
+
let rows;
|
|
72
|
+
try {
|
|
73
|
+
({ results: rows } = await db
|
|
74
|
+
.prepare(`SELECT workflow_name, run_id
|
|
75
|
+
FROM ${prefix}mastra_workflow_snapshot
|
|
76
|
+
WHERE ${eligible}
|
|
77
|
+
LIMIT ?`)
|
|
78
|
+
.bind(cutoff, ...TERMINAL_STATUSES, options.limit ?? 100)
|
|
79
|
+
.all());
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (!isMissingTable(error))
|
|
83
|
+
throw error;
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
let deleted = 0;
|
|
87
|
+
const failures = [];
|
|
88
|
+
for (const row of rows) {
|
|
89
|
+
try {
|
|
90
|
+
await options.artifactStore.deleteRun(row.workflow_name, row.run_id);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
// Isolate per run, same as the demo-tenant reaper: aborting the
|
|
94
|
+
// loop would re-hit this run at the same scan position every firing
|
|
95
|
+
// and stall every eligible row behind it forever. Its row survives
|
|
96
|
+
// as its own retry cursor; the aggregate throw below keeps the
|
|
97
|
+
// cron's error surface firing. A wedged run does occupy a batch
|
|
98
|
+
// slot until fixed, so isolation holds while wedged runs number
|
|
99
|
+
// fewer than `limit`.
|
|
100
|
+
failures.push({
|
|
101
|
+
run: `${row.workflow_name}/${row.run_id}`,
|
|
102
|
+
message: errorMessageOf(error),
|
|
103
|
+
});
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// Re-checking eligibility keys the delete to the row the SELECT saw;
|
|
107
|
+
// terminal is absorbing, so this is belt-and-braces, not a race fix.
|
|
108
|
+
deleted += d1Changes(await db
|
|
109
|
+
.prepare(`DELETE FROM ${prefix}mastra_workflow_snapshot
|
|
110
|
+
WHERE workflow_name = ? AND run_id = ? AND ${eligible}`)
|
|
111
|
+
.bind(row.workflow_name, row.run_id, cutoff, ...TERMINAL_STATUSES)
|
|
112
|
+
.run());
|
|
113
|
+
}
|
|
114
|
+
if (failures.length > 0) {
|
|
115
|
+
throw new Error(`purgeExpiredWorkflowRuns: artifact deletion failed for ${failures.length} of ${rows.length} eligible run(s), the rest were purged (${failures
|
|
116
|
+
.map((failure) => `${failure.run}: ${failure.message}`)
|
|
117
|
+
.join('; ')})`);
|
|
118
|
+
}
|
|
119
|
+
return deleted;
|
|
120
|
+
}
|
|
121
|
+
// Row-only path: LIMIT-batched like the artifact path, but against D1's
|
|
122
|
+
// per-QUERY budget rather than the subrequest cap (it stays one statement
|
|
123
|
+
// per firing whatever the batch size, hence the larger default). An
|
|
124
|
+
// unbounded DELETE over a huge first backlog can exceed the per-query
|
|
125
|
+
// limits and then fail the same way on EVERY firing — retention silently
|
|
126
|
+
// unenforced, the exact wedge the cron split exists to avoid. The
|
|
127
|
+
// shrinking eligible set is the cursor: a backlog drains across firings.
|
|
128
|
+
try {
|
|
129
|
+
return d1Changes(await db
|
|
130
|
+
.prepare(`DELETE FROM ${prefix}mastra_workflow_snapshot
|
|
131
|
+
WHERE rowid IN (
|
|
132
|
+
SELECT rowid FROM ${prefix}mastra_workflow_snapshot
|
|
133
|
+
WHERE ${eligible}
|
|
134
|
+
LIMIT ?
|
|
135
|
+
)`)
|
|
136
|
+
.bind(cutoff, ...TERMINAL_STATUSES, options.limit ?? 1000)
|
|
137
|
+
.run());
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (!isMissingTable(error))
|
|
141
|
+
throw error;
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// One CREATE INDEX per (database, prefix) per isolate: purgeTenant runs this,
|
|
146
|
+
// and the demo reaper invokes purgeTenant in a LIMIT-batched loop — without
|
|
147
|
+
// the memo that is one DDL round-trip to the D1 primary per tenant per cron
|
|
148
|
+
// firing (24 no-ops out of 25), plus one on every expired-sandbox re-auth.
|
|
149
|
+
// Same clear-on-failure promise memo as D1ApprovalStoreFactory's
|
|
150
|
+
// #schemaReady: only SUCCESS memoizes, so a missing snapshot table (this call
|
|
151
|
+
// doubles as purgeTenant's table probe) or a transient error retries on the
|
|
152
|
+
// next call instead of pinning the database to a dead promise.
|
|
153
|
+
const snapshotIndexReady = new WeakMap();
|
|
154
|
+
/**
|
|
155
|
+
* Additive, app-owned index for the tenant range predicate. It couples us to
|
|
156
|
+
* Mastra's snapshot column name (`run_id`, snake_case — its timestamps are
|
|
157
|
+
* camelCase) — the schema-guard test pins that name so a @mastra/core bump
|
|
158
|
+
* that renames it fails CI, not a purge.
|
|
159
|
+
*/
|
|
160
|
+
export async function ensureSnapshotRunIdIndex(db, tablePrefix = '') {
|
|
161
|
+
let prefixes = snapshotIndexReady.get(db);
|
|
162
|
+
if (!prefixes) {
|
|
163
|
+
prefixes = new Map();
|
|
164
|
+
snapshotIndexReady.set(db, prefixes);
|
|
165
|
+
}
|
|
166
|
+
const memo = prefixes;
|
|
167
|
+
let ready = memo.get(tablePrefix);
|
|
168
|
+
if (!ready) {
|
|
169
|
+
ready = Promise.resolve(db
|
|
170
|
+
.prepare(`CREATE INDEX IF NOT EXISTS idx_${tablePrefix}snapshot_run_id
|
|
171
|
+
ON ${tablePrefix}mastra_workflow_snapshot (run_id)`)
|
|
172
|
+
.run()).then(() => undefined, (error) => {
|
|
173
|
+
memo.delete(tablePrefix);
|
|
174
|
+
throw error;
|
|
175
|
+
});
|
|
176
|
+
memo.set(tablePrefix, ready);
|
|
177
|
+
}
|
|
178
|
+
await ready;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Complete tenant offboarding: reaps ALL THREE stores — snapshot rows of ANY
|
|
182
|
+
* status (a tenant's suspended-and-abandoned runs are never eligible for the
|
|
183
|
+
* terminal-only retention purge at any age), the tenant's approval records
|
|
184
|
+
* (titles, summaries, payloads, decider identities), and its R2 artifacts.
|
|
185
|
+
*
|
|
186
|
+
* The snapshot predicate is a RANGE over the INV-1 salted runId:
|
|
187
|
+
* `run_id >= '<tid>_' AND run_id < '<tid>' || CHAR(0x60)`. tenantId is
|
|
188
|
+
* re-validated against INV-3 here — not for injection safety (every query is
|
|
189
|
+
* parameter-bound) but for RANGE-EXACTNESS: the predicate selects exactly one
|
|
190
|
+
* tenant only because the charset excludes every character in [0x5F, 0x60]
|
|
191
|
+
* ('_' is 0x5F; its successor 0x60, backtick, closes the range under BINARY
|
|
192
|
+
* collation). 'abc' can never sweep 'abcdefg'.
|
|
193
|
+
*
|
|
194
|
+
* PURGE POLICY (the race): this deletes SUSPENDED rows, and a reviewer
|
|
195
|
+
* approving at that moment would resume against a vanishing row (absorbed:
|
|
196
|
+
* the runtime's pre-check throws before any step re-executes — pinned by the
|
|
197
|
+
* purge-race regression test). Only purge tenants whose tokens have already
|
|
198
|
+
* expired, so no live caller can be mid-resume by construction — or purge at
|
|
199
|
+
* the tenant's own explicit request (the showcase's self-service /demo/reset).
|
|
200
|
+
* That caller, uniquely, can race ITSELF: a run started between the artifact
|
|
201
|
+
* SELECT and the snapshot DELETE is reaped by the DELETE (which re-reads the
|
|
202
|
+
* range) with its artifacts unenumerated, and the three statements are not one
|
|
203
|
+
* transaction — an R2 delete can never join a SQL one — so a mid-purge failure
|
|
204
|
+
* leaves it partially applied. Both are pinned in d1-storage.test.ts. Neither
|
|
205
|
+
* can escape the requester's own tenant: the range predicate is exact.
|
|
206
|
+
*/
|
|
207
|
+
export async function purgeTenant(db, options) {
|
|
208
|
+
const { tenantId } = options;
|
|
209
|
+
if (!TENANT_ID_PATTERN.test(tenantId)) {
|
|
210
|
+
throw new Error(`purgeTenant: tenantId '${tenantId}' violates INV-3 (^[a-z0-9]{3,32}$) — refusing (the range predicate is only exact over that charset)`);
|
|
211
|
+
}
|
|
212
|
+
const prefix = options.tablePrefix ?? '';
|
|
213
|
+
const lower = `${tenantId}_`;
|
|
214
|
+
const upper = `${tenantId}\x60`;
|
|
215
|
+
// The snapshot table exists only once Mastra lazily creates it for the
|
|
216
|
+
// first persisted run. A tenant that never started one — routine for an
|
|
217
|
+
// expired demo sandbox — has zero snapshots and artifacts, and its
|
|
218
|
+
// approvals below MUST still be reaped: throwing here would wedge every
|
|
219
|
+
// offboarding (the purge cron AND the demo re-auth's inline purge) until
|
|
220
|
+
// some unrelated run initializes the schema.
|
|
221
|
+
let hasSnapshotTable = true;
|
|
222
|
+
try {
|
|
223
|
+
await ensureSnapshotRunIdIndex(db, prefix);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (!isMissingTable(error))
|
|
227
|
+
throw error;
|
|
228
|
+
hasSnapshotTable = false;
|
|
229
|
+
}
|
|
230
|
+
let artifacts = 0;
|
|
231
|
+
let snapshots = 0;
|
|
232
|
+
if (hasSnapshotTable) {
|
|
233
|
+
// 1. Artifacts first — deleteRun needs the run list the snapshot DELETE
|
|
234
|
+
// would destroy.
|
|
235
|
+
if (options.artifactStore) {
|
|
236
|
+
const { results } = await db
|
|
237
|
+
.prepare(`SELECT workflow_name, run_id FROM ${prefix}mastra_workflow_snapshot
|
|
238
|
+
WHERE run_id >= ? AND run_id < ?`)
|
|
239
|
+
.bind(lower, upper)
|
|
240
|
+
.all();
|
|
241
|
+
for (const row of results) {
|
|
242
|
+
artifacts += await options.artifactStore.deleteRun(row.workflow_name, row.run_id);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// 2. Snapshots — ANY status.
|
|
246
|
+
snapshots = d1Changes(await db
|
|
247
|
+
.prepare(`DELETE FROM ${prefix}mastra_workflow_snapshot
|
|
248
|
+
WHERE run_id >= ? AND run_id < ?`)
|
|
249
|
+
.bind(lower, upper)
|
|
250
|
+
.run());
|
|
251
|
+
}
|
|
252
|
+
// 3. Approvals — by the tenant_id column. Hosts without the approval queue
|
|
253
|
+
// have no such table; a missing table is the only tolerated failure.
|
|
254
|
+
let approvals = 0;
|
|
255
|
+
try {
|
|
256
|
+
approvals = d1Changes(await db
|
|
257
|
+
.prepare('DELETE FROM flowsafe_approvals WHERE tenant_id = ?')
|
|
258
|
+
.bind(tenantId)
|
|
259
|
+
.run());
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (!isMissingTable(error))
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
return { snapshots, approvals, artifacts };
|
|
266
|
+
}
|
|
267
|
+
/** Rows affected by a D1 write, read from its `{ meta: { changes } }` envelope. */
|
|
268
|
+
export function d1Changes(result) {
|
|
269
|
+
const changes = result?.meta
|
|
270
|
+
?.changes;
|
|
271
|
+
return typeof changes === 'number' ? changes : 0;
|
|
272
|
+
}
|
|
273
|
+
function errorMessageOf(error) {
|
|
274
|
+
return error instanceof Error ? error.message : String(error);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* SQLite/D1's "no such table". For the purges, a table that was never
|
|
278
|
+
* created is an EMPTY table, not an error: Mastra creates the snapshot
|
|
279
|
+
* table lazily with the first persisted run, and hosts without the approval
|
|
280
|
+
* queue never create flowsafe_approvals. Matched on the message because the
|
|
281
|
+
* structural SnapshotDatabase seam carries no error codes (D1 wraps the
|
|
282
|
+
* SQLite text but preserves it).
|
|
283
|
+
*/
|
|
284
|
+
function isMissingTable(error) {
|
|
285
|
+
return /no such table/i.test(errorMessageOf(error));
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=d1-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"d1-storage.js","sourceRoot":"","sources":["../../src/do-runner/d1-storage.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,sEAAsE;AACtE,2EAA2E;AAC3E,0EAA0E;AAC1E,0EAA0E;AAG1E,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWtD,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,OAAO,IAAI,OAAO,CAAC;QACjB,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,UAAU;QAC5B,+DAA+D;QAC/D,sEAAsE;QACtE,gEAAgE;QAChE,uCAAuC;QACvC,OAAO,EAAE,OAAO,CAAC,OAAgC;QACjD,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS;YACnC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE;YACtC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC;AAED,0EAA0E;AAC1E,4EAA4E;AAC5E,qDAAqD;AACrD,MAAM,iBAAiB,GAAG;IACxB,SAAS;IACT,QAAQ;IACR,UAAU;IACV,UAAU;IACV,QAAQ;IACR,SAAS;CACD,CAAC;AAmDX;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,EAAoB,EACpB,OAAgC;IAEhC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,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AAO,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DurableObjectRunnerState } from './cf-types.js';
|
|
2
|
+
import { type RunnerRuntime } from './runtime.js';
|
|
3
|
+
export declare abstract class DurableObjectRunner<TEnv = unknown> {
|
|
4
|
+
#private;
|
|
5
|
+
protected readonly env: TEnv;
|
|
6
|
+
/** Absent in node tests; present under workerd. Reserved for Phase 2 alarms. */
|
|
7
|
+
protected readonly state?: DurableObjectRunnerState;
|
|
8
|
+
constructor(state: DurableObjectRunnerState | undefined, env: TEnv);
|
|
9
|
+
/** Define workflows via init() and return its runtime. Called once, lazily. */
|
|
10
|
+
protected abstract build(env: TEnv): RunnerRuntime;
|
|
11
|
+
/**
|
|
12
|
+
* The tenant this instance serves, recovered from the DO's OWN identity.
|
|
13
|
+
* The name was set by the trusted Worker via
|
|
14
|
+
* idFromName(`${workflowId}:${runId}`) and is unforgeable at this boundary
|
|
15
|
+
* (`id.name` is populated only for idFromName-created ids). Safe to parse:
|
|
16
|
+
* PATH_SAFE_ID_PATTERN excludes ':' from workflowId, so the first ':' is
|
|
17
|
+
* the join; INV-3 excludes '_' from tenantId, so the first '_' in the runId
|
|
18
|
+
* is the tenant boundary.
|
|
19
|
+
*
|
|
20
|
+
* THROWS rather than defaulting — an unscoped grant store is a cross-tenant
|
|
21
|
+
* capability mint. Node tests that exercise tenant-bound wiring pass a stub
|
|
22
|
+
* state `{ id: { name: 'wf:tenant_uuid' } }`; never soften this to a
|
|
23
|
+
* default for the workerd path.
|
|
24
|
+
*/
|
|
25
|
+
protected get tenantId(): string;
|
|
26
|
+
fetch(request: Request): Promise<Response>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=durable-object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-object.d.ts","sourceRoot":"","sources":["../../src/do-runner/durable-object.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAIL,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AAatB,8BAAsB,mBAAmB,CAAC,IAAI,GAAG,OAAO;;IACtD,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IAC7B,gFAAgF;IAChF,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,wBAAwB,CAAC;gBAGxC,KAAK,EAAE,wBAAwB,GAAG,SAAS,EAAE,GAAG,EAAE,IAAI;IAKlE,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,GAAG,aAAa;IAElD;;;;;;;;;;;;;OAaG;IACH,SAAS,KAAK,QAAQ,IAAI,MAAM,CAe/B;IAEK,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsGjD"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Classic fetch-contract Durable Object (constructor(state, env) + fetch).
|
|
2
|
+
// Deliberately NOT `extends DurableObject` from 'cloudflare:workers': the
|
|
3
|
+
// classic contract needs no workers-only runtime import, so this module and
|
|
4
|
+
// everything under it load in node/vitest. Run state lives in D1, not DO
|
|
5
|
+
// storage — that is what lets a run started before a restart resume after
|
|
6
|
+
// one. Serialization of start/resume on a single run is enforced by
|
|
7
|
+
// RunnerRuntime's per-run FIFO lock; routing one DO instance per run
|
|
8
|
+
// (idFromName(`${workflowId}:${runId}`)) makes that lock authoritative,
|
|
9
|
+
// since all traffic for a run lands on one instance. `state` is captured
|
|
10
|
+
// for the Phase 2 alarm-chained engine (setAlarm/alarm) but unused today.
|
|
11
|
+
import { tenantOfRunId } from './path-safe-id.js';
|
|
12
|
+
import { DurableStorageResumeLedger } from './resume-ledger.js';
|
|
13
|
+
import { InvalidRunRequestError, RunAlreadyExistsError, RunNotSuspendedError, UnknownRunError, UnknownWorkflowError, } from './runtime.js';
|
|
14
|
+
export class DurableObjectRunner {
|
|
15
|
+
env;
|
|
16
|
+
/** Absent in node tests; present under workerd. Reserved for Phase 2 alarms. */
|
|
17
|
+
state;
|
|
18
|
+
#runtime;
|
|
19
|
+
constructor(state, env) {
|
|
20
|
+
this.state = state;
|
|
21
|
+
this.env = env;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The tenant this instance serves, recovered from the DO's OWN identity.
|
|
25
|
+
* The name was set by the trusted Worker via
|
|
26
|
+
* idFromName(`${workflowId}:${runId}`) and is unforgeable at this boundary
|
|
27
|
+
* (`id.name` is populated only for idFromName-created ids). Safe to parse:
|
|
28
|
+
* PATH_SAFE_ID_PATTERN excludes ':' from workflowId, so the first ':' is
|
|
29
|
+
* the join; INV-3 excludes '_' from tenantId, so the first '_' in the runId
|
|
30
|
+
* is the tenant boundary.
|
|
31
|
+
*
|
|
32
|
+
* THROWS rather than defaulting — an unscoped grant store is a cross-tenant
|
|
33
|
+
* capability mint. Node tests that exercise tenant-bound wiring pass a stub
|
|
34
|
+
* state `{ id: { name: 'wf:tenant_uuid' } }`; never soften this to a
|
|
35
|
+
* default for the workerd path.
|
|
36
|
+
*/
|
|
37
|
+
get tenantId() {
|
|
38
|
+
const name = this.state?.id?.name;
|
|
39
|
+
if (!name) {
|
|
40
|
+
throw new Error('DurableObjectRunner.tenantId: the DO has no id.name (not created via idFromName, or running without state) — tenant unresolvable, refusing to scope');
|
|
41
|
+
}
|
|
42
|
+
const runId = name.slice(name.indexOf(':') + 1);
|
|
43
|
+
const tenantId = tenantOfRunId(runId);
|
|
44
|
+
if (tenantId === undefined) {
|
|
45
|
+
throw new Error(`DurableObjectRunner.tenantId: runId '${runId}' carries no INV-3 tenant segment (INV-1 runIds are \`\${tenantId}_\${uuid}\`)`);
|
|
46
|
+
}
|
|
47
|
+
return tenantId;
|
|
48
|
+
}
|
|
49
|
+
async fetch(request) {
|
|
50
|
+
try {
|
|
51
|
+
return await this.#route(request);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return errorResponse(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
#ensureRuntime() {
|
|
58
|
+
if (!this.#runtime) {
|
|
59
|
+
this.#runtime = this.build(this.env);
|
|
60
|
+
// Durable resume ledger: ctx.storage survives eviction, hibernation,
|
|
61
|
+
// and code deploys; in-memory class state does not. Adopting it HERE —
|
|
62
|
+
// not via a host-threaded parameter — is what makes the guarantee
|
|
63
|
+
// un-forgettable: every DO host gets eviction-proof resume ordinals.
|
|
64
|
+
// Absent under node/vitest (state is undefined), the runtime keeps its
|
|
65
|
+
// in-memory default.
|
|
66
|
+
const storage = this.state?.storage;
|
|
67
|
+
if (storage) {
|
|
68
|
+
this.#runtime.adoptDefaultResumeLedger(new DurableStorageResumeLedger(storage));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return this.#runtime;
|
|
72
|
+
}
|
|
73
|
+
// INV-1 enforcement at the DO boundary: this instance was addressed as
|
|
74
|
+
// idFromName(`${workflowId}:${runId}`) by the trusted Worker, and id.name
|
|
75
|
+
// is unforgeable at this boundary. If a request asks the instance to act on
|
|
76
|
+
// a DIFFERENT (workflowId, runId), someone routed around the name join —
|
|
77
|
+
// acting on the request's ids would run outside this instance's identity
|
|
78
|
+
// (and outside its per-run serialization). Refuse loudly. `id.name` is only
|
|
79
|
+
// populated for idFromName-created ids; it is absent under node tests
|
|
80
|
+
// (state undefined / minimal stubs), where the runtime's own validation
|
|
81
|
+
// still applies.
|
|
82
|
+
#assertRunIdentity(workflowId, runId) {
|
|
83
|
+
const name = this.state?.id?.name;
|
|
84
|
+
if (name === undefined)
|
|
85
|
+
return;
|
|
86
|
+
if (name !== `${workflowId}:${runId}`) {
|
|
87
|
+
throw new Error(`DO identity mismatch: instance is '${name}' but the request names '${workflowId}:${runId}' — refusing (INV-1)`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async #route(request) {
|
|
91
|
+
const segments = new URL(request.url).pathname.split('/').filter(Boolean);
|
|
92
|
+
if (segments[0] !== 'runs')
|
|
93
|
+
return json({ error: 'not found' }, 404);
|
|
94
|
+
const runtime = this.#ensureRuntime();
|
|
95
|
+
const [, workflowId, runId, action] = segments;
|
|
96
|
+
if (request.method === 'POST' && segments.length === 1) {
|
|
97
|
+
const body = await readJson(request);
|
|
98
|
+
if (!body || typeof body.workflowId !== 'string') {
|
|
99
|
+
return json({ error: 'workflowId is required' }, 400);
|
|
100
|
+
}
|
|
101
|
+
// The DO never generates a runId (INV-1): the trusted Worker mints the
|
|
102
|
+
// tenant-salted id and addresses this instance with it. A start without
|
|
103
|
+
// one is a caller bug, not a request for generation.
|
|
104
|
+
if (typeof body.runId !== 'string') {
|
|
105
|
+
return json({ error: 'runId is required (server-minted by the run router)' }, 400);
|
|
106
|
+
}
|
|
107
|
+
this.#assertRunIdentity(body.workflowId, body.runId);
|
|
108
|
+
return json(await runtime.start(body.workflowId, {
|
|
109
|
+
runId: body.runId,
|
|
110
|
+
inputData: body.inputData,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
if (request.method === 'GET' &&
|
|
114
|
+
segments.length === 3 &&
|
|
115
|
+
workflowId &&
|
|
116
|
+
runId) {
|
|
117
|
+
this.#assertRunIdentity(workflowId, runId);
|
|
118
|
+
const summary = await runtime.status(workflowId, runId);
|
|
119
|
+
return summary ? json(summary) : json({ error: 'run not found' }, 404);
|
|
120
|
+
}
|
|
121
|
+
if (request.method === 'POST' &&
|
|
122
|
+
segments.length === 4 &&
|
|
123
|
+
action === 'resume' &&
|
|
124
|
+
workflowId &&
|
|
125
|
+
runId) {
|
|
126
|
+
this.#assertRunIdentity(workflowId, runId);
|
|
127
|
+
const body = (await readJson(request)) ?? {};
|
|
128
|
+
return json(await runtime.resume(workflowId, runId, {
|
|
129
|
+
step: body.step,
|
|
130
|
+
resumeData: body.resumeData,
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
return json({ error: 'not found' }, 404);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function readJson(request) {
|
|
137
|
+
try {
|
|
138
|
+
return (await request.json());
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function json(payload, status = 200) {
|
|
145
|
+
return new Response(JSON.stringify(payload), {
|
|
146
|
+
status,
|
|
147
|
+
headers: { 'content-type': 'application/json' },
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function errorResponse(error) {
|
|
151
|
+
if (error instanceof UnknownWorkflowError ||
|
|
152
|
+
error instanceof UnknownRunError) {
|
|
153
|
+
return json({ error: error.message }, 404);
|
|
154
|
+
}
|
|
155
|
+
if (error instanceof RunNotSuspendedError ||
|
|
156
|
+
error instanceof RunAlreadyExistsError) {
|
|
157
|
+
return json({ error: error.message }, 409);
|
|
158
|
+
}
|
|
159
|
+
if (error instanceof InvalidRunRequestError) {
|
|
160
|
+
return json({ error: error.message }, 400);
|
|
161
|
+
}
|
|
162
|
+
return json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=durable-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-object.js","sourceRoot":"","sources":["../../src/do-runner/durable-object.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,yEAAyE;AACzE,0EAA0E;AAC1E,oEAAoE;AACpE,qEAAqE;AACrE,wEAAwE;AACxE,yEAAyE;AACzE,0EAA0E;AAG1E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EAEpB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC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IAC7C,CAAC;IACD,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,IAAI,CACT,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACjE,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { D1DatabaseBinding, DurableObjectRunnerState, } from './cf-types.js';
|
|
2
|
+
export type { D1StorageOptions, PurgeExpiredRunsOptions, PurgeTenantOptions, PurgeTenantResult, SnapshotDatabase, SnapshotStatement, TenantArtifactPurger, } from './d1-storage.js';
|
|
3
|
+
export { createD1Storage, d1Changes, ensureSnapshotRunIdIndex, purgeExpiredWorkflowRuns, purgeTenant, } from './d1-storage.js';
|
|
4
|
+
export { DurableObjectRunner } from './durable-object.js';
|
|
5
|
+
export type { DORunnerEnv, InitOptions, InitResult, InitSource, } from './init.js';
|
|
6
|
+
export { init } from './init.js';
|
|
7
|
+
export { PATH_SAFE_ID_PATTERN, TENANT_ID_PATTERN, tenantOfRunId, } from './path-safe-id.js';
|
|
8
|
+
export type { ResumeLedger, ResumeLedgerStorage } from './resume-ledger.js';
|
|
9
|
+
export { DurableStorageResumeLedger, InMemoryResumeLedger, } from './resume-ledger.js';
|
|
10
|
+
export type { RequestContextProvider, ResumeRunOptions, RunLeg, RunnerRuntimeOptions, RunSummary, StartRunOptions, } from './runtime.js';
|
|
11
|
+
export { InvalidRunRequestError, RunAlreadyExistsError, RunNotSuspendedError, RunnerRuntime, UnknownRunError, UnknownWorkflowError, } from './runtime.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|