@proofoftech/flowsafe 0.20.0 → 0.22.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 +101 -0
- package/README.md +55 -10
- package/deployment-identity-protocol.d.mts +28 -3
- package/deployment-identity-protocol.mjs +275 -21
- package/dist/agent-host/router.d.ts.map +1 -1
- package/dist/agent-host/router.js +11 -2
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +3 -1
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +858 -351
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +8 -0
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +243 -64
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +89 -14
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +369 -44
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/actor-context.d.ts +4 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -1
- package/dist/approval-api/actor-context.js +53 -5
- package/dist/approval-api/actor-context.js.map +1 -1
- package/dist/approval-api/principal.d.ts +1 -1
- package/dist/approval-api/principal.js +1 -1
- package/dist/approval-api/retention.d.ts +1 -2
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/service.d.ts +13 -20
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +52 -28
- package/dist/approval-api/service.js.map +1 -1
- package/dist/audit-export/index.d.ts +2 -2
- package/dist/audit-export/index.js +2 -2
- package/dist/background-tasks/d1-storage.d.ts +4 -3
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +8 -14
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/background-tasks/host.d.ts.map +1 -1
- package/dist/background-tasks/host.js +3 -2
- package/dist/background-tasks/host.js.map +1 -1
- package/dist/do-runner/constants.d.ts +3 -0
- package/dist/do-runner/constants.d.ts.map +1 -0
- package/dist/do-runner/constants.js +3 -0
- package/dist/do-runner/constants.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +34 -158
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +935 -402
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +472 -185
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-admission.d.ts +114 -0
- package/dist/do-runner/execution-admission.d.ts.map +1 -0
- package/dist/do-runner/execution-admission.js +206 -0
- package/dist/do-runner/execution-admission.js.map +1 -0
- package/dist/do-runner/execution-context.d.ts +5 -1
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +6 -1
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/execution-fence.d.ts +74 -30
- package/dist/do-runner/execution-fence.d.ts.map +1 -1
- package/dist/do-runner/execution-fence.js +684 -120
- package/dist/do-runner/execution-fence.js.map +1 -1
- package/dist/do-runner/fenced-workflow-capability.d.ts +64 -0
- package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -0
- package/dist/do-runner/fenced-workflow-capability.js +3 -0
- package/dist/do-runner/fenced-workflow-capability.js.map +1 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts +15 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -0
- package/dist/do-runner/fenced-workflows-d1.js +894 -0
- package/dist/do-runner/fenced-workflows-d1.js.map +1 -0
- package/dist/do-runner/index.d.ts +13 -8
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +6 -2
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/initial-admission-refusal.d.ts +7 -0
- package/dist/do-runner/initial-admission-refusal.d.ts.map +1 -0
- package/dist/do-runner/initial-admission-refusal.js +41 -0
- package/dist/do-runner/initial-admission-refusal.js.map +1 -0
- package/dist/do-runner/inventory.d.ts +2 -1
- package/dist/do-runner/inventory.d.ts.map +1 -1
- package/dist/do-runner/inventory.js +28 -39
- package/dist/do-runner/inventory.js.map +1 -1
- package/dist/do-runner/notification-predicate.d.ts +7 -7
- package/dist/do-runner/notification-predicate.d.ts.map +1 -1
- package/dist/do-runner/notification-predicate.js +134 -7
- package/dist/do-runner/notification-predicate.js.map +1 -1
- package/dist/do-runner/run-lifecycle.d.ts +20 -1
- package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
- package/dist/do-runner/run-lifecycle.js +69 -15
- package/dist/do-runner/run-lifecycle.js.map +1 -1
- package/dist/do-runner/run-provenance.d.ts +38 -0
- package/dist/do-runner/run-provenance.d.ts.map +1 -0
- package/dist/do-runner/run-provenance.js +152 -0
- package/dist/do-runner/run-provenance.js.map +1 -0
- package/dist/do-runner/run-storage-tables.d.ts +2 -0
- package/dist/do-runner/run-storage-tables.d.ts.map +1 -0
- package/dist/do-runner/run-storage-tables.js +4 -0
- package/dist/do-runner/run-storage-tables.js.map +1 -0
- package/dist/do-runner/run-terminal-state.d.ts +29 -0
- package/dist/do-runner/run-terminal-state.d.ts.map +1 -0
- package/dist/do-runner/run-terminal-state.js +105 -0
- package/dist/do-runner/run-terminal-state.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +108 -46
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +927 -438
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/start-idempotency.d.ts +35 -258
- package/dist/do-runner/start-idempotency.d.ts.map +1 -1
- package/dist/do-runner/start-idempotency.js +606 -498
- package/dist/do-runner/start-idempotency.js.map +1 -1
- package/dist/do-runner/start-reservation-contract.d.ts +103 -0
- package/dist/do-runner/start-reservation-contract.d.ts.map +1 -0
- package/dist/do-runner/start-reservation-contract.js +338 -0
- package/dist/do-runner/start-reservation-contract.js.map +1 -0
- package/dist/do-runner/suspension-deadline.d.ts +4 -11
- package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
- package/dist/do-runner/suspension-deadline.js +8 -12
- package/dist/do-runner/suspension-deadline.js.map +1 -1
- package/dist/do-runner/table-prefix.d.ts.map +1 -1
- package/dist/do-runner/table-prefix.js +2 -1
- package/dist/do-runner/table-prefix.js.map +1 -1
- package/dist/do-runner/testing.d.ts +3 -0
- package/dist/do-runner/testing.d.ts.map +1 -0
- package/dist/do-runner/testing.js +3 -0
- package/dist/do-runner/testing.js.map +1 -0
- package/dist/do-runner/thread-do.d.ts +2 -1
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +14 -10
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.d.ts +49 -0
- package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -0
- package/dist/do-runner/workflow-snapshot-row.js +97 -0
- package/dist/do-runner/workflow-snapshot-row.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +1 -5
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +32 -53
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +8 -8
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +18 -15
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/do-response.d.ts +16 -0
- package/dist/host-kit/do-response.d.ts.map +1 -1
- package/dist/host-kit/do-response.js +181 -0
- package/dist/host-kit/do-response.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +2 -14
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +31 -24
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +5 -6
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +38 -6
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +115 -93
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +4 -14
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +23 -40
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +7 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +4 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/run-route-error.d.ts +3 -17
- package/dist/host-kit/run-route-error.d.ts.map +1 -1
- package/dist/host-kit/run-route-error.js +4 -24
- package/dist/host-kit/run-route-error.js.map +1 -1
- package/dist/host-kit/run-router.d.ts +6 -2
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +93 -80
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +1 -1
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +7 -3
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/internal-error-response.d.ts.map +1 -1
- package/dist/internal-error-response.js +16 -6
- package/dist/internal-error-response.js.map +1 -1
- package/dist/schedules/index.d.ts +1 -0
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +1 -7
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/mutation-contract.d.ts +38 -0
- package/dist/schedules/mutation-contract.d.ts.map +1 -0
- package/dist/schedules/mutation-contract.js +21 -0
- package/dist/schedules/mutation-contract.js.map +1 -0
- package/dist/schedules/router.d.ts +11 -19
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +130 -49
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/schedules-d1.d.ts +11 -5
- package/dist/schedules/schedules-d1.d.ts.map +1 -1
- package/dist/schedules/schedules-d1.js +571 -144
- package/dist/schedules/schedules-d1.js.map +1 -1
- package/dist/schedules/storage.d.ts +0 -7
- package/dist/schedules/storage.d.ts.map +1 -1
- package/dist/schedules/storage.js +0 -27
- package/dist/schedules/storage.js.map +1 -1
- package/dist/schedules/tick.d.ts +1 -8
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +15 -20
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +1 -1
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +99 -109
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/d1-shared.d.ts +11 -8
- package/dist/signals/d1-shared.d.ts.map +1 -1
- package/dist/signals/d1-shared.js +2 -7
- package/dist/signals/d1-shared.js.map +1 -1
- package/dist/signals/index.d.ts +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +1 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +84 -4
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +365 -53
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +6 -1
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +215 -10
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +6 -4
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/router.js +49 -84
- package/dist/signals/router.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +2 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +250 -81
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +9 -7
- package/scripts/seed-deployment-identity.mjs +27 -6
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { MastraCompositeStore, type MastraStorageDomains } from '@mastra/core/storage';
|
|
2
2
|
import type { D1DatabaseBinding } from './cf-types.js';
|
|
3
|
+
import { type SnapshotDatabase } from './workflow-snapshot-row.js';
|
|
4
|
+
export { RESOURCE_OWNER_TABLE } from './run-storage-tables.js';
|
|
5
|
+
export type { SnapshotDatabase, SnapshotStatement, } from './workflow-snapshot-row.js';
|
|
3
6
|
export interface D1StorageOptions {
|
|
4
7
|
/** D1 binding from the Worker/DO environment. */
|
|
5
8
|
binding: D1DatabaseBinding;
|
|
@@ -10,41 +13,20 @@ export interface D1StorageOptions {
|
|
|
10
13
|
/**
|
|
11
14
|
* Additional storage domains composed over the D1Store default, such as
|
|
12
15
|
* notifications and thread state, which @mastra/cloudflare-d1 does not ship, so
|
|
13
|
-
* they are flowsafe-owned D1 impls
|
|
16
|
+
* they are flowsafe-owned D1 impls. Injected rather than imported so this
|
|
14
17
|
* lower layer never depends on `signals/` (which imports do-runner) — build
|
|
15
|
-
* them with `createSignalStorageDomains()` and pass them here.
|
|
16
|
-
*
|
|
18
|
+
* them with `createSignalStorageDomains()` and pass them here. The default
|
|
19
|
+
* workflow domain supports explicit initial-admission scopes; false/custom
|
|
20
|
+
* workflow overrides retain precedence. `workflowDefinitions` and `knowledge`
|
|
21
|
+
* are injectable through this seam on the same terms: @mastra/cloudflare-d1
|
|
22
|
+
* backs neither, so each resolves undefined unless a host supplies one.
|
|
17
23
|
*/
|
|
18
24
|
domains?: MastraStorageDomains;
|
|
19
25
|
}
|
|
20
26
|
export declare function createD1Storage(options: D1StorageOptions): MastraCompositeStore;
|
|
21
|
-
/**
|
|
22
|
-
* Mastra workflow terminals plus FlowSafe's lifecycle-owned terminals.
|
|
23
|
-
* Deleting a live run (running/suspended/waiting/pending/paused) would kill a
|
|
24
|
-
* pending approval, so only these are ever purged.
|
|
25
|
-
*
|
|
26
|
-
* Exported because retention and the drain inventory must agree on the word
|
|
27
|
-
* "terminal" to the letter. The purge deletes what this set matches; the
|
|
28
|
-
* inventory counts what it does NOT, and a run that is terminal to one and live
|
|
29
|
-
* to the other is either a row the purge reaps while the inventory still calls
|
|
30
|
-
* it work, or — worse — a run the inventory declares finished while it is still
|
|
31
|
-
* executing, which is exactly the reading a migration would act on.
|
|
32
|
-
*/
|
|
27
|
+
/** Shared with the drain inventory so cleanup and liveness use the same vocabulary. */
|
|
33
28
|
export declare const RUN_TERMINAL_STATUSES: readonly ["success", "failed", "tripwire", "canceled", "bailed", "skipped", "cancelled", "timed_out"];
|
|
34
|
-
/**
|
|
35
|
-
* The SQL that decides one snapshot row is TERMINAL, with `?` for each entry of
|
|
36
|
-
* RUN_TERMINAL_STATUSES in order.
|
|
37
|
-
*
|
|
38
|
-
* A shared FRAGMENT rather than a shared list because the rule is not "the
|
|
39
|
-
* status is in the set": a run that reached 'cancelled' or 'timed_out' is
|
|
40
|
-
* terminal only once its lifecycle cleanup stamped `cleanupCompletedAt`, and
|
|
41
|
-
* before that it is still executing compensation. Two hand-written copies of
|
|
42
|
-
* that carve-out are two chances for one of them to answer "finished" for a run
|
|
43
|
-
* that is mid-cleanup — the retention purge would delete a live run's snapshot,
|
|
44
|
-
* and the drain inventory would report a deployment empty while it still runs
|
|
45
|
-
* work. The caller supplies the `json_valid` guard, because it decides which
|
|
46
|
-
* way an unclassifiable row should fail.
|
|
47
|
-
*/
|
|
29
|
+
/** Duplicate keys can disagree between SQLite and JSON.parse on terminal eligibility. */
|
|
48
30
|
export declare const RUN_TERMINAL_SNAPSHOT_SQL: string;
|
|
49
31
|
export interface RunDeadlineCandidate {
|
|
50
32
|
workflowId: string;
|
|
@@ -76,148 +58,43 @@ export interface SweepExpiredRunDeadlinesOptions {
|
|
|
76
58
|
* timed-out rows whose terminal cleanup is incomplete remain resumable cursors.
|
|
77
59
|
*/
|
|
78
60
|
export declare function sweepExpiredRunDeadlines(db: SnapshotDatabase, options: SweepExpiredRunDeadlinesOptions): Promise<number>;
|
|
79
|
-
/**
|
|
80
|
-
* Minimal structural D1 surface the purge uses — same posture as the
|
|
81
|
-
* approval store: tests back it with node:sqlite, Workers pass env.DB.
|
|
82
|
-
*/
|
|
83
|
-
export interface SnapshotDatabase {
|
|
84
|
-
prepare(query: string): SnapshotStatement;
|
|
85
|
-
/** D1 transactional batch, required when owner lifecycle cleanup is wired. */
|
|
86
|
-
batch?(statements: SnapshotStatement[]): Promise<unknown[]>;
|
|
87
|
-
}
|
|
88
|
-
export interface SnapshotStatement {
|
|
89
|
-
bind(...values: unknown[]): SnapshotStatement;
|
|
90
|
-
run(): Promise<unknown>;
|
|
91
|
-
all<T = unknown>(): Promise<{
|
|
92
|
-
results: T[];
|
|
93
|
-
}>;
|
|
94
|
-
}
|
|
95
61
|
/** Structural: R2ArtifactStore.deleteRun, without importing the artifacts module. */
|
|
96
62
|
export interface RunArtifactPurger {
|
|
97
63
|
deleteRun(workflowId: string, runId: string): Promise<number>;
|
|
98
64
|
}
|
|
65
|
+
export interface RunRetentionScanPosition {
|
|
66
|
+
readonly afterRowId: number;
|
|
67
|
+
readonly highWaterRowId: number;
|
|
68
|
+
}
|
|
69
|
+
export interface RunRetentionCursor {
|
|
70
|
+
readonly version: 1;
|
|
71
|
+
readonly tablePrefix: string;
|
|
72
|
+
readonly startIdempotencyTable?: string;
|
|
73
|
+
readonly snapshots?: RunRetentionScanPosition;
|
|
74
|
+
readonly reservations?: RunRetentionScanPosition;
|
|
75
|
+
}
|
|
99
76
|
export interface PurgeExpiredRunsOptions {
|
|
100
|
-
/**
|
|
77
|
+
/** Terminal snapshot retention measured from updatedAt. */
|
|
101
78
|
ttlMs: number;
|
|
102
|
-
/** Must satisfy and match createD1Storage's max-39 tablePrefix contract. */
|
|
103
79
|
tablePrefix?: string;
|
|
104
|
-
/**
|
|
105
|
-
* When set, each purged run's R2 artifacts are deleted WITH its snapshot
|
|
106
|
-
* row. Hosts that store artifacts must wire this: the snapshot row is the
|
|
107
|
-
* only enumerable record of a run's artifact keys (R2 keys lead with
|
|
108
|
-
* workflowId — there is no run-level listing without it), so a retention
|
|
109
|
-
* purge without this pairing strands the run's artifacts until the
|
|
110
|
-
* deployment itself is decommissioned.
|
|
111
|
-
*/
|
|
80
|
+
/** Artifact deletion precedes the guarded snapshot transaction. */
|
|
112
81
|
artifactStore?: RunArtifactPurger;
|
|
113
|
-
/**
|
|
114
|
-
* Deployment-local resource-owner table. When supplied, each snapshot delete
|
|
115
|
-
* and its run-owner release commit in the same D1 transaction. The composed
|
|
116
|
-
* Flowsafe Worker always supplies this; lower-level callers without the
|
|
117
|
-
* resource registry omit it.
|
|
118
|
-
*/
|
|
119
82
|
resourceOwnerTable?: string;
|
|
120
|
-
/**
|
|
121
|
-
* The start-reservation table (`flowsafe_start_idempotency`). When supplied,
|
|
122
|
-
* this purge is also what keeps idempotency keys finite.
|
|
123
|
-
*
|
|
124
|
-
* Wired the same way `resourceOwnerTable` is — by name, from the composed
|
|
125
|
-
* Flowsafe Worker — for the same reason: this module owns the SQL of run
|
|
126
|
-
* retention, and a reservation must be reaped in the same transaction that
|
|
127
|
-
* removes the run it points at, never by a second sweep that could interleave
|
|
128
|
-
* with it.
|
|
129
|
-
*/
|
|
130
83
|
startIdempotencyTable?: string;
|
|
131
|
-
/**
|
|
132
|
-
* How long a spent idempotency key stays answerable after its run settled —
|
|
133
|
-
* the KEY-VALIDITY HORIZON, and the only tuning decision this feature has.
|
|
134
|
-
*
|
|
135
|
-
* Until it elapses, a retry of a completed run is told ALREADY_SETTLED. After
|
|
136
|
-
* it, the reservation is gone and the same key reads as brand new, so a retry
|
|
137
|
-
* would START A SECOND RUN. That is the whole reason this exists as its own
|
|
138
|
-
* knob rather than riding `ttlMs`: a host whose callers retry for longer than
|
|
139
|
-
* its run retention (an overnight batch re-run, a queue with a multi-day
|
|
140
|
-
* redrive) needs keys to outlive summaries, and a host whose keys are minted
|
|
141
|
-
* per HTTP request does not.
|
|
142
|
-
*
|
|
143
|
-
* DEFAULTS TO `ttlMs`, and is floored at it: a reservation shorter-lived than
|
|
144
|
-
* the snapshot it guards would be deleted while its run is still readable,
|
|
145
|
-
* and the very next retry would mint a fresh run alongside the live one — the
|
|
146
|
-
* exact double-execution this feature exists to prevent. A caller asking for
|
|
147
|
-
* less gets `ttlMs`, silently, because there is no configuration in which the
|
|
148
|
-
* smaller number is what anybody meant.
|
|
149
|
-
*/
|
|
84
|
+
/** Defaults to ttlMs and cannot shorten the snapshot retention horizon. */
|
|
150
85
|
startIdempotencyTtlMs?: number;
|
|
151
|
-
/**
|
|
152
|
-
* Runs processed per call. Artifact-paired path: default 100 — the purge duty's
|
|
153
|
-
* subrequest-budget guard, same batching as any batched reaper. Each
|
|
154
|
-
* run costs ~2+N subrequests (R2 list, per-artifact deletes, its row's
|
|
155
|
-
* DELETE), so an UNBOUNDED first backlog would blow the Workers
|
|
156
|
-
* per-invocation cap mid-pass and log an error every firing until it
|
|
157
|
-
* drained; size this to your plan's budget instead. Row-only path:
|
|
158
|
-
* default 1000 — one LIMIT-batched DELETE statement per firing, bounding
|
|
159
|
-
* D1 per-query cost instead of subrequests. Both paths use the shrinking
|
|
160
|
-
* eligible set as the cursor — the next firing resumes at the survivors.
|
|
161
|
-
*/
|
|
86
|
+
/** Physical rows scanned per phase, capped at 90. */
|
|
162
87
|
limit?: number;
|
|
163
|
-
/** Clock override for tests. */
|
|
164
88
|
now?: () => number;
|
|
89
|
+
cursor?: RunRetentionCursor;
|
|
90
|
+
advanceCursor: (next: RunRetentionCursor) => Promise<void>;
|
|
165
91
|
}
|
|
166
|
-
/**
|
|
167
|
-
* The MASTRA-OWNED tables `purgeExpiredWorkflowRuns` deletes from under the run
|
|
168
|
-
* TTL — the production anchor the schema guard cross-checks every `run-ttl`
|
|
169
|
-
* retention declaration against. The guard reads THIS, not a literal copied
|
|
170
|
-
* into the test, so a purge that changes what it targets and a guard that still
|
|
171
|
-
* blesses the old set cannot drift apart silently.
|
|
172
|
-
*
|
|
173
|
-
* Mastra-owned specifically: the purge ALSO deletes from flowsafe's own
|
|
174
|
-
* registries when a caller wires them, and those live in
|
|
175
|
-
* RUN_TTL_FLOWSAFE_PURGE_TABLES below rather than here — see its note for why
|
|
176
|
-
* the two sets are not one.
|
|
177
|
-
*/
|
|
178
92
|
export declare const RUN_TTL_PURGE_TABLES: readonly string[];
|
|
179
|
-
/**
|
|
180
|
-
* The resource-ownership registry's table, named here rather than imported from
|
|
181
|
-
* the store that creates it (approval-api/resource-ownership.ts).
|
|
182
|
-
*
|
|
183
|
-
* The layering forbids the import: do-runner may reach approval-api only
|
|
184
|
-
* through its declared leaves, and the ownership store is not one — it is built
|
|
185
|
-
* ON do-runner. So this file has always carried the name as a literal inside
|
|
186
|
-
* RUN_TTL_FLOWSAFE_PURGE_TABLES; giving it a name adds no second home, it names
|
|
187
|
-
* the one that was already here, and lets the drain inventory read the registry
|
|
188
|
-
* without a third copy. The census test crosses it against
|
|
189
|
-
* RESOURCE_OWNERSHIP_TABLE, which is the only place the two can be compared.
|
|
190
|
-
*/
|
|
191
|
-
export declare const RESOURCE_OWNER_TABLE = "flowsafe_resource_owners";
|
|
192
|
-
/**
|
|
193
|
-
* The FLOWSAFE-owned tables this purge also deletes from when the caller wires
|
|
194
|
-
* them, and the reason they are not in the list above.
|
|
195
|
-
*
|
|
196
|
-
* `RUN_TTL_PURGE_TABLES` is cross-checked against the `mastra_%` inventory in
|
|
197
|
-
* mastra-schema-guard.test.ts — its job is to catch a @mastra/core bump that
|
|
198
|
-
* changes what run retention targets. These two are ours, they are optional
|
|
199
|
-
* (a lower-level caller without the registries omits both), and they are
|
|
200
|
-
* deleted on a DIFFERENT predicate: `flowsafe_resource_owners` when its run's
|
|
201
|
-
* last snapshot is gone, `flowsafe_start_idempotency` when its reservation is
|
|
202
|
-
* settled AND past the key-validity horizon. Folding them into the Mastra
|
|
203
|
-
* anchor would make that guard assert an equality it cannot mean.
|
|
204
|
-
*/
|
|
205
93
|
export declare const RUN_TTL_FLOWSAFE_PURGE_TABLES: readonly string[];
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
* mastra_workflow_snapshot — and, when `artifactStore` is wired, each purged
|
|
211
|
-
* run's R2 artifacts with its row, plus (when their tables are wired) the run's
|
|
212
|
-
* ownership row and its spent start reservation, each in the SAME transaction
|
|
213
|
-
* as the snapshot delete. Live runs (running/suspended/waiting/
|
|
214
|
-
* pending/paused) are never touched — expiring a suspended run would kill a
|
|
215
|
-
* pending approval. A missing snapshot table reads as zero purgeable runs
|
|
216
|
-
* (Mastra creates it lazily with the first persisted run). TTL enforcement
|
|
217
|
-
* is a storage-layer property, so it lives here; alarm scheduling stays with
|
|
218
|
-
* the caller. Returns the number of deleted rows.
|
|
219
|
-
*/
|
|
220
|
-
export declare function purgeExpiredWorkflowRuns(db: SnapshotDatabase, options: PurgeExpiredRunsOptions): Promise<number>;
|
|
94
|
+
/** @internal */
|
|
95
|
+
export declare function parseRunRetentionCursor(value: unknown): RunRetentionCursor | undefined;
|
|
96
|
+
/** Delete expired snapshots with durable, independent physical scan positions. */
|
|
97
|
+
export declare function purgeExpiredWorkflowRuns(db: SnapshotDatabase & Required<Pick<SnapshotDatabase, 'batch'>>, options: PurgeExpiredRunsOptions): Promise<number>;
|
|
221
98
|
export interface PurgeExpiredThreadsOptions {
|
|
222
99
|
/** Threads untouched for longer than this are eligible, with their messages. */
|
|
223
100
|
ttlMs: number;
|
|
@@ -397,9 +274,8 @@ export interface PurgeExpiredNotificationsOptions {
|
|
|
397
274
|
* rows from `mastra_notifications` once their `updatedAt` is older than the TTL,
|
|
398
275
|
* at the storage layer so alarm maintenance reaps them without a live agent —
|
|
399
276
|
* the same posture as the other purges (raw D1 binding, failure-isolated duty).
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* sent). Scheduling stays with the caller.
|
|
277
|
+
* A missing table reads as zero (notifications may never have been sent).
|
|
278
|
+
* Scheduling stays with the caller.
|
|
403
279
|
*/
|
|
404
280
|
export declare function purgeExpiredNotifications(db: SnapshotDatabase, options: PurgeExpiredNotificationsOptions): Promise<number>;
|
|
405
281
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d1-storage.d.ts","sourceRoot":"","sources":["../../src/do-runner/d1-storage.ts"],"names":[],"mappings":"AASA,OAAO,EACL,oBAAoB,EACpB,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"d1-storage.d.ts","sourceRoot":"","sources":["../../src/do-runner/d1-storage.ts"],"names":[],"mappings":"AASA,OAAO,EACL,oBAAoB,EACpB,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAyBvD,OAAO,EAIL,KAAK,gBAAgB,EAGtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,YAAY,EACV,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,OAAO,EAAE,iBAAiB,CAAC;IAC3B,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,gBAAgB,GACxB,oBAAoB,CA0DtB;AAED,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,uGASxB,CAAC;AAEX,yFAAyF;AACzF,eAAO,MAAM,yBAAyB,QAkBvB,CAAC;AAahB,MAAM,WAAW,oBAAo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