@proofoftech/flowsafe 0.4.0 → 0.7.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 +327 -0
- package/README.md +295 -251
- package/dist/agent-runner/approval-shapes.d.ts +36 -0
- package/dist/agent-runner/approval-shapes.d.ts.map +1 -0
- package/dist/agent-runner/approval-shapes.js +101 -0
- package/dist/agent-runner/approval-shapes.js.map +1 -0
- package/dist/agent-runner/durable-agent-runner.d.ts +158 -0
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
- package/dist/agent-runner/durable-agent-runner.js +295 -0
- package/dist/agent-runner/durable-agent-runner.js.map +1 -0
- package/dist/agent-runner/index.d.ts +3 -0
- package/dist/agent-runner/index.d.ts.map +1 -0
- package/dist/agent-runner/index.js +10 -0
- package/dist/agent-runner/index.js.map +1 -0
- package/dist/approval-api/contract.d.ts +2 -2
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +87 -19
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.js +1 -1
- package/dist/approval-api/index.d.ts +1 -1
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/router.d.ts +2 -2
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +1 -0
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +10 -11
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +22 -9
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +27 -22
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +25 -9
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts +6 -6
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +15 -0
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/types.d.ts +13 -4
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +2 -1
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +2 -2
- package/dist/approval-ui/FilterBar.d.ts +3 -3
- package/dist/approval-ui/FilterBar.js +3 -3
- package/dist/approval-ui/client.d.ts +1 -1
- package/dist/approval-ui/components.d.ts +1 -1
- package/dist/approval-ui/stream.d.ts +3 -3
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/use-approval-dashboard.d.ts +9 -12
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +6 -9
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +1 -1
- package/dist/approval-ui/use-web-socket-transport.js +1 -1
- package/dist/background-tasks/d1-storage.d.ts +66 -0
- package/dist/background-tasks/d1-storage.d.ts.map +1 -0
- package/dist/background-tasks/d1-storage.js +196 -0
- package/dist/background-tasks/d1-storage.js.map +1 -0
- package/dist/background-tasks/host.d.ts +82 -0
- package/dist/background-tasks/host.d.ts.map +1 -0
- package/dist/background-tasks/host.js +275 -0
- package/dist/background-tasks/host.js.map +1 -0
- package/dist/background-tasks/index.d.ts +7 -0
- package/dist/background-tasks/index.d.ts.map +1 -0
- package/dist/background-tasks/index.js +10 -0
- package/dist/background-tasks/index.js.map +1 -0
- package/dist/background-tasks/routes.d.ts +15 -0
- package/dist/background-tasks/routes.d.ts.map +1 -0
- package/dist/background-tasks/routes.js +144 -0
- package/dist/background-tasks/routes.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +1 -1
- package/dist/do-runner/breakwater-keys.js +1 -1
- package/dist/do-runner/cf-types.d.ts +1 -1
- package/dist/do-runner/d1-storage.d.ts +347 -5
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +571 -17
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +29 -0
- package/dist/do-runner/do-error-response.d.ts.map +1 -0
- package/dist/do-runner/do-error-response.js +73 -0
- package/dist/do-runner/do-error-response.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +3 -3
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +7 -21
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/hub-do.d.ts +2 -2
- package/dist/do-runner/index.d.ts +9 -3
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +8 -2
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +20 -0
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +12 -1
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/memory-id.d.ts +3 -3
- package/dist/do-runner/memory-id.js +3 -3
- package/dist/do-runner/path-safe-id.d.ts +6 -6
- package/dist/do-runner/path-safe-id.js +6 -6
- package/dist/do-runner/pubsub.d.ts +18 -0
- package/dist/do-runner/pubsub.d.ts.map +1 -0
- package/dist/do-runner/pubsub.js +42 -0
- package/dist/do-runner/pubsub.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +24 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +28 -2
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +74 -0
- package/dist/do-runner/thread-do.d.ts.map +1 -0
- package/dist/do-runner/thread-do.js +156 -0
- package/dist/do-runner/thread-do.js.map +1 -0
- package/dist/do-runner/thread-header.d.ts +16 -0
- package/dist/do-runner/thread-header.d.ts.map +1 -0
- package/dist/do-runner/thread-header.js +24 -0
- package/dist/do-runner/thread-header.js.map +1 -0
- package/dist/goals/index.d.ts +2 -0
- package/dist/goals/index.d.ts.map +1 -0
- package/dist/goals/index.js +7 -0
- package/dist/goals/index.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +87 -0
- package/dist/goals/objective-routes.d.ts.map +1 -0
- package/dist/goals/objective-routes.js +375 -0
- package/dist/goals/objective-routes.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +28 -8
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +37 -15
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +1 -1
- package/dist/host-kit/bearer-auth.js +1 -1
- package/dist/host-kit/env-vars.d.ts +20 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +30 -0
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +113 -6
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +253 -63
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +13 -13
- package/dist/host-kit/host-approval-service.js +10 -10
- package/dist/host-kit/index.d.ts +3 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +7 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/memory-boundary.d.ts +64 -0
- package/dist/host-kit/memory-boundary.d.ts.map +1 -0
- package/dist/host-kit/memory-boundary.js +109 -0
- package/dist/host-kit/memory-boundary.js.map +1 -0
- package/dist/host-kit/route-path.d.ts +17 -0
- package/dist/host-kit/route-path.d.ts.map +1 -0
- package/dist/host-kit/route-path.js +35 -0
- package/dist/host-kit/route-path.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +10 -11
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/stream-router.d.ts +1 -1
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +3 -3
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +1 -1
- package/dist/host-kit/tenant-registry.d.ts +1 -1
- package/dist/host-kit/tenant-registry.js +1 -1
- package/dist/host-kit/thread-topology.d.ts +44 -0
- package/dist/host-kit/thread-topology.d.ts.map +1 -0
- package/dist/host-kit/thread-topology.js +76 -0
- package/dist/host-kit/thread-topology.js.map +1 -0
- package/dist/host-kit/verifier.d.ts +1 -1
- package/dist/host-kit/verifier.js +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal-error-response.d.ts +3 -0
- package/dist/internal-error-response.d.ts.map +1 -0
- package/dist/internal-error-response.js +20 -0
- package/dist/internal-error-response.js.map +1 -0
- package/dist/numeric-config.d.ts +4 -0
- package/dist/numeric-config.d.ts.map +1 -0
- package/dist/numeric-config.js +23 -0
- package/dist/numeric-config.js.map +1 -0
- package/dist/schedules/index.d.ts +5 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +13 -0
- package/dist/schedules/index.js.map +1 -0
- package/dist/schedules/router.d.ts +66 -0
- package/dist/schedules/router.d.ts.map +1 -0
- package/dist/schedules/router.js +827 -0
- package/dist/schedules/router.js.map +1 -0
- package/dist/schedules/schedules-d1.d.ts +30 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -0
- package/dist/schedules/schedules-d1.js +374 -0
- package/dist/schedules/schedules-d1.js.map +1 -0
- package/dist/schedules/storage.d.ts +11 -0
- package/dist/schedules/storage.d.ts.map +1 -0
- package/dist/schedules/storage.js +34 -0
- package/dist/schedules/storage.js.map +1 -0
- package/dist/schedules/tick.d.ts +132 -0
- package/dist/schedules/tick.d.ts.map +1 -0
- package/dist/schedules/tick.js +598 -0
- package/dist/schedules/tick.js.map +1 -0
- package/dist/signal-providers/delivery.d.ts +24 -0
- package/dist/signal-providers/delivery.d.ts.map +1 -0
- package/dist/signal-providers/delivery.js +62 -0
- package/dist/signal-providers/delivery.js.map +1 -0
- package/dist/signal-providers/github-provider.d.ts +33 -0
- package/dist/signal-providers/github-provider.d.ts.map +1 -0
- package/dist/signal-providers/github-provider.js +116 -0
- package/dist/signal-providers/github-provider.js.map +1 -0
- package/dist/signal-providers/host-do.d.ts +81 -0
- package/dist/signal-providers/host-do.d.ts.map +1 -0
- package/dist/signal-providers/host-do.js +229 -0
- package/dist/signal-providers/host-do.js.map +1 -0
- package/dist/signal-providers/host-topology.d.ts +27 -0
- package/dist/signal-providers/host-topology.d.ts.map +1 -0
- package/dist/signal-providers/host-topology.js +36 -0
- package/dist/signal-providers/host-topology.js.map +1 -0
- package/dist/signal-providers/index.d.ts +8 -0
- package/dist/signal-providers/index.d.ts.map +1 -0
- package/dist/signal-providers/index.js +21 -0
- package/dist/signal-providers/index.js.map +1 -0
- package/dist/signal-providers/provider.d.ts +93 -0
- package/dist/signal-providers/provider.d.ts.map +1 -0
- package/dist/signal-providers/provider.js +89 -0
- package/dist/signal-providers/provider.js.map +1 -0
- package/dist/signal-providers/subscription-d1.d.ts +88 -0
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -0
- package/dist/signal-providers/subscription-d1.js +259 -0
- package/dist/signal-providers/subscription-d1.js.map +1 -0
- package/dist/signal-providers/webhook-route.d.ts +96 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -0
- package/dist/signal-providers/webhook-route.js +444 -0
- package/dist/signal-providers/webhook-route.js.map +1 -0
- package/dist/signals/client.d.ts +72 -0
- package/dist/signals/client.d.ts.map +1 -0
- package/dist/signals/client.js +87 -0
- package/dist/signals/client.js.map +1 -0
- package/dist/signals/d1-shared.d.ts +43 -0
- package/dist/signals/d1-shared.d.ts.map +1 -0
- package/dist/signals/d1-shared.js +46 -0
- package/dist/signals/d1-shared.js.map +1 -0
- package/dist/signals/index.d.ts +9 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +15 -0
- package/dist/signals/index.js.map +1 -0
- package/dist/signals/notification-dispatch.d.ts +52 -0
- package/dist/signals/notification-dispatch.d.ts.map +1 -0
- package/dist/signals/notification-dispatch.js +198 -0
- package/dist/signals/notification-dispatch.js.map +1 -0
- package/dist/signals/notifications-d1.d.ts +27 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -0
- package/dist/signals/notifications-d1.js +703 -0
- package/dist/signals/notifications-d1.js.map +1 -0
- package/dist/signals/router.d.ts +73 -0
- package/dist/signals/router.d.ts.map +1 -0
- package/dist/signals/router.js +240 -0
- package/dist/signals/router.js.map +1 -0
- package/dist/signals/storage.d.ts +11 -0
- package/dist/signals/storage.d.ts.map +1 -0
- package/dist/signals/storage.js +27 -0
- package/dist/signals/storage.js.map +1 -0
- package/dist/signals/thread-do-routes.d.ts +82 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -0
- package/dist/signals/thread-do-routes.js +660 -0
- package/dist/signals/thread-do-routes.js.map +1 -0
- package/dist/signals/thread-state-d1.d.ts +22 -0
- package/dist/signals/thread-state-d1.d.ts.map +1 -0
- package/dist/signals/thread-state-d1.js +83 -0
- package/dist/signals/thread-state-d1.js.map +1 -0
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -1,287 +1,331 @@
|
|
|
1
|
-
# flowsafe
|
|
1
|
+
# @proofoftech/flowsafe
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Workers and Durable Objects.
|
|
3
|
+
Durable approvals and tenant-safe long-running execution for Mastra on Cloudflare.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Flowsafe runs Mastra workflows and agents through Cloudflare Durable Objects, stores their snapshots in D1, turns suspensions into human approval requests, and derives connector grants from stored decisions when a run resumes.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
durable execution via the Durable Object import-swap pattern. It ships as a
|
|
10
|
-
standalone service with a React approval UI and a DO-based workflow runner.
|
|
7
|
+
[Documentation](https://github.com/ProofOfTechOrg/anchorage/tree/main/docs) · [Getting started](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/getting-started.md) · [API reference](https://proofoftechorg.github.io/anchorage/) · [Live demo](https://anchorage.proofoftech.org/)
|
|
11
8
|
|
|
12
|
-
##
|
|
9
|
+
## Install
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| `approval-ui` | Styling-agnostic React UI surfacing pending approvals and history, with queue triage (filter bar + batch selection/decide) |
|
|
18
|
-
| `do-runner` | Durable Object workflow runner (import-swap pattern) |
|
|
19
|
-
| `audit-export` | Cloudflare Queues → SIEM audit export (producer sink + batch consumer) |
|
|
20
|
-
| `artifacts` | R2-backed workflow artifact storage keyed by run identity |
|
|
21
|
-
| `host-kit` | Host-agnostic glue: the identity seam (`TokenVerifier`), the tenant resolver, the shared `/workflows` + `/runs` routes, the tenants registry, the suspension→approval bridge, and `createFlowsafeWorker()` — the composed production Worker hosts consume as thin shells |
|
|
22
|
-
|
|
23
|
-
A copy-ready production deployment lives in [`deploy/`](deploy/) — a thin
|
|
24
|
-
shell over `createFlowsafeWorker()` with cron-owned SLA enforcement and
|
|
25
|
-
retention purge.
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/core@^1.50.0 @proofoftech/flowsafe
|
|
13
|
+
```
|
|
26
14
|
|
|
27
|
-
|
|
15
|
+
Install `@proofoftech/breakwater` when resumed steps call approval-protected connectors:
|
|
28
16
|
|
|
29
|
-
```
|
|
30
|
-
npm install @proofoftech/
|
|
17
|
+
```bash
|
|
18
|
+
npm install @proofoftech/breakwater
|
|
31
19
|
```
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
`
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
flowsafe
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
21
|
+
Install React and React DOM only when you import `@proofoftech/flowsafe/approval-ui`.
|
|
22
|
+
|
|
23
|
+
Compatibility:
|
|
24
|
+
|
|
25
|
+
- Node.js 22 or later (engine range `>=22`)
|
|
26
|
+
- ESM only
|
|
27
|
+
- TypeScript `moduleResolution: "NodeNext"`, `"Node16"`, or `"Bundler"`
|
|
28
|
+
- `@mastra/core` in the declared `^1.50.0` peer range
|
|
29
|
+
- `react` and `react-dom` `>=18 <20` (React 18 or 19) for the optional approval UI
|
|
30
|
+
- `@proofoftech/breakwater` `>=0.2.0 <1.0.0` when used
|
|
31
|
+
|
|
32
|
+
## Choose an export
|
|
33
|
+
|
|
34
|
+
| Import | Purpose |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `@proofoftech/flowsafe` | Compatibility barrel for approval API, runner, artifacts, and audit export |
|
|
37
|
+
| `@proofoftech/flowsafe/approval-api` | Approval records, service, tenant-bound stores, REST router, grants, SLA, retention, notifications, and stream events |
|
|
38
|
+
| `@proofoftech/flowsafe/do-runner` | Durable Object runner, D1 storage, run summaries, identities, pub/sub, resume ledger, retention, and offboarding |
|
|
39
|
+
| `@proofoftech/flowsafe/approval-ui` | Styling-library-agnostic React dashboard, DOM-free API client, headless hook, and live transport |
|
|
40
|
+
| `@proofoftech/flowsafe/host-kit` | Auth seams, tenant resolver, topologies, run/stream routers, approval bridges, and composed Worker |
|
|
41
|
+
| `@proofoftech/flowsafe/host-kit/module` | Import-safe workflow module contract |
|
|
42
|
+
| `@proofoftech/flowsafe/artifacts` | R2 artifact store and in-memory test bucket |
|
|
43
|
+
| `@proofoftech/flowsafe/audit-export` | Cloudflare Queue producer sink and NDJSON SIEM consumer |
|
|
44
|
+
| `@proofoftech/flowsafe/agent-runner` | Runtime-driven Mastra durable agents and restart-safe approval resume |
|
|
45
|
+
| `@proofoftech/flowsafe/signals` | Thread signal routes, ingestion router, D1 notification/state domains, dispatch, and client |
|
|
46
|
+
| `@proofoftech/flowsafe/signals/client` | DOM-free signal client without Worker code |
|
|
47
|
+
| `@proofoftech/flowsafe/goals` | Durable objective router |
|
|
48
|
+
| `@proofoftech/flowsafe/schedules` | D1 schedules, tenant facade, reserved-context controls, and CAS tick |
|
|
49
|
+
| `@proofoftech/flowsafe/background-tasks` | Tenant task host, D1 task domains, routes, and cleanup |
|
|
50
|
+
| `@proofoftech/flowsafe/signal-providers` | Alarm-driven provider host, topology, subscriptions, verified webhooks, and GitHub reference provider |
|
|
51
|
+
|
|
52
|
+
New host-side and React features are subpath-only. This keeps the root import free of durable-agent and UI dependency graphs.
|
|
53
|
+
|
|
54
|
+
## Start with the baseline Worker
|
|
55
|
+
|
|
56
|
+
Copy the [reference deployment](https://github.com/ProofOfTechOrg/anchorage/tree/main/packages/flowsafe/deploy). It supplies:
|
|
57
|
+
|
|
58
|
+
- one Durable Object per run;
|
|
59
|
+
- D1-backed Mastra snapshots and approvals;
|
|
60
|
+
- bearer-authentication seam and tenant resolver;
|
|
61
|
+
- workflow catalog, start, status, and resume routes;
|
|
62
|
+
- suspension-to-approval bridge;
|
|
63
|
+
- exact suspension-bound breakwater grant derivation;
|
|
64
|
+
- role checks and separation of duties;
|
|
65
|
+
- optional live approval/run WebSockets;
|
|
66
|
+
- cron-owned SLA sweep and retention purge;
|
|
67
|
+
- structured audit and optional Queue-to-SIEM export;
|
|
68
|
+
- a sample gated workflow.
|
|
69
|
+
|
|
70
|
+
Replace the example workflow and identity verifier. Keep the trusted host-kit composition and grant provider.
|
|
66
71
|
|
|
67
72
|
```typescript
|
|
68
|
-
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
import {
|
|
74
|
+
approvalGrantProvider,
|
|
75
|
+
} from '@proofoftech/flowsafe/approval-api';
|
|
76
|
+
import {
|
|
77
|
+
DurableObjectRunner,
|
|
78
|
+
init,
|
|
79
|
+
type RunnerRuntime,
|
|
80
|
+
} from '@proofoftech/flowsafe/do-runner';
|
|
81
|
+
import { approvalStoreFactoryFor } from '@proofoftech/flowsafe/host-kit';
|
|
82
|
+
|
|
83
|
+
export class AppRunner extends DurableObjectRunner<Env> {
|
|
76
84
|
protected build(env: Env): RunnerRuntime {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
inputSchema: z.object({ topic: z.string() }),
|
|
81
|
-
outputSchema: z.object({ topic: z.string(), approvedBy: z.string() }),
|
|
82
|
-
suspendSchema: z.object({ reason: z.string() }),
|
|
83
|
-
resumeSchema: z.object({ approvedBy: z.string() }),
|
|
84
|
-
execute: async ({ inputData, resumeData, suspend }) => {
|
|
85
|
-
if (!resumeData) return suspend({ reason: 'approval required' });
|
|
86
|
-
return { topic: inputData.topic, approvedBy: resumeData.approvedBy };
|
|
87
|
-
},
|
|
85
|
+
const approvals = approvalStoreFactoryFor(env.DB).forTenant(this.tenantId);
|
|
86
|
+
const { createWorkflow, createStep, runtime } = init(env, {
|
|
87
|
+
requestContextForRun: approvalGrantProvider(approvals),
|
|
88
88
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
outputSchema: z.object({ topic: z.string(), approvedBy: z.string() }),
|
|
93
|
-
})
|
|
94
|
-
.then(gate)
|
|
95
|
-
.commit();
|
|
89
|
+
|
|
90
|
+
// Define and commit workflows through the import-swapped factories.
|
|
91
|
+
|
|
96
92
|
return runtime;
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
```
|
|
100
96
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
`init()` creates D1-backed Mastra storage from the conventional `DB` binding unless you inject storage. Workflow definitions use the same `createWorkflow()` and `createStep()` shape as Mastra.
|
|
98
|
+
|
|
99
|
+
## Approval lifecycle
|
|
100
|
+
|
|
101
|
+
When a workflow or durable agent suspends:
|
|
102
|
+
|
|
103
|
+
1. The authoritative run summary captures `stepPath`, `suspendedAt`, and `resumeCount`.
|
|
104
|
+
2. The trusted host bridge creates one open approval in a tenant-bound store.
|
|
105
|
+
3. The record's connector ids come from a server-authored suspend payload.
|
|
106
|
+
4. A reviewer claims, delegates, approves, or rejects through the service or REST router.
|
|
107
|
+
5. A compare-and-swap commits the mutation.
|
|
108
|
+
6. An approval re-enters the owning runtime.
|
|
109
|
+
7. `approvalGrantProvider()` reads D1 and writes only the matching approved connectors into the resumed leg's request context.
|
|
110
|
+
8. Another suspension creates a new approval. A completed or failed run ends the loop.
|
|
111
|
+
|
|
112
|
+
Grants never travel in public request bodies. A raw or forged resume finds no stored capability and fails at the breakwater connector gate.
|
|
113
|
+
|
|
114
|
+
### REST surface
|
|
115
|
+
|
|
116
|
+
The default approval base is `/api/approvals`.
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
GET /
|
|
120
|
+
GET /metrics
|
|
121
|
+
GET /:id
|
|
122
|
+
POST /:id/claim
|
|
123
|
+
POST /:id/delegate
|
|
124
|
+
POST /:id/decide
|
|
125
|
+
POST /batch/decide
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The create route is disabled by default. If enabled, it rejects capability, attribution, fingerprint, and resume-target fields.
|
|
129
|
+
|
|
130
|
+
Queue filters cover status, workflow, run, claimant, requester, strict creation-time bounds, bounded pagination, and reviewer-priority ordering. Batch decisions contain per-record outcomes and preserve all single-record checks.
|
|
131
|
+
|
|
132
|
+
### Separation of duties
|
|
133
|
+
|
|
134
|
+
Self-decision is denied by default. A non-exempt actor also cannot approve a later gate after approving an earlier gate that advanced the run. Set a narrow role exemption only for an installation that cannot supply an independent reviewer.
|
|
135
|
+
|
|
136
|
+
### SLA, notifications, and retention
|
|
137
|
+
|
|
138
|
+
`sweepSLA()` accepts the system-only cross-tenant store and escalates overdue open records. It is intended for a scheduled invocation and is not an HTTP service method.
|
|
106
139
|
|
|
107
|
-
|
|
140
|
+
`ApprovalNotificationSink` receives creation and escalation events. Failures are contained and audited. `ApprovalStreamSink` publishes mutations to the optional tenant hub.
|
|
141
|
+
|
|
142
|
+
`purgeExpiredApprovals()` deletes only approved and rejected records past the configured age. Pending, claimed, and escalated records remain live at any age.
|
|
143
|
+
|
|
144
|
+
Read the [approval-system guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/approval-system.md) for exact grant binding and recovery behavior.
|
|
145
|
+
|
|
146
|
+
## Approval dashboard
|
|
147
|
+
|
|
148
|
+
The optional UI exports a plain-HTML default and an injected component contract:
|
|
108
149
|
|
|
109
150
|
```typescript
|
|
110
151
|
import {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
import { bearerActorAuthenticator, staticTokenVerifier, parseActorTokens }
|
|
120
|
-
from '@proofoftech/flowsafe/host-kit';
|
|
121
|
-
|
|
122
|
-
// Hoist the factory to module scope: it owns one memoized schema-init pass,
|
|
123
|
-
// so rebuilding it per request re-runs the DDL every time.
|
|
124
|
-
const factory = new D1ApprovalStoreFactory(env.DB); // shares the runner's D1
|
|
125
|
-
|
|
126
|
-
// 1. Grant-minting seam. Inside a Durable Object, bind the store to THIS
|
|
127
|
-
// instance's tenant (recovered from its own idFromName identity), so the
|
|
128
|
-
// mint can only ever read its own tenant's records.
|
|
129
|
-
const { createWorkflow, createStep, runtime } = init(env, {
|
|
130
|
-
requestContextForRun: approvalGrantProvider(factory.forTenant(this.tenantId)),
|
|
152
|
+
ApprovalApiClient,
|
|
153
|
+
createApprovalDashboard,
|
|
154
|
+
} from '@proofoftech/flowsafe/approval-ui';
|
|
155
|
+
|
|
156
|
+
const client = new ApprovalApiClient({
|
|
157
|
+
headers: {
|
|
158
|
+
authorization: `Bearer ${token}`,
|
|
159
|
+
},
|
|
131
160
|
});
|
|
132
161
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// later refactor to reach for.
|
|
136
|
-
const resolve = createTenantResolver({
|
|
137
|
-
authenticate: bearerActorAuthenticator(
|
|
138
|
-
staticTokenVerifier(parseActorTokens(env.APPROVAL_ACTOR_TOKENS)),
|
|
139
|
-
),
|
|
140
|
-
storeFactory: factory,
|
|
141
|
-
buildService: (store) =>
|
|
142
|
-
new ApprovalService({
|
|
143
|
-
store, // tenant-bound; required
|
|
144
|
-
defaultSlaSeconds: 15 * 60,
|
|
145
|
-
resumeRun: resumeViaRuntime(runtime), // or a DO-stub fetch
|
|
146
|
-
audit: (event) => auditLogger.record(event),
|
|
147
|
-
}),
|
|
162
|
+
createApprovalDashboard(document.getElementById('root')!, {
|
|
163
|
+
client,
|
|
148
164
|
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The package includes:
|
|
168
|
+
|
|
169
|
+
- queue, detail, metrics, filter, and batch-decision views;
|
|
170
|
+
- `useApprovalDashboard()` for headless composition;
|
|
171
|
+
- `ApprovalUIProvider` and `ApprovalUIComponents` slots;
|
|
172
|
+
- optional checkbox, select, toast, and presence slots;
|
|
173
|
+
- optimistic decisions with conflict reporting;
|
|
174
|
+
- polling reconciliation;
|
|
175
|
+
- WebSocket live merge and liveness heartbeat;
|
|
176
|
+
- `ApprovalApiClient` without a DOM dependency.
|
|
177
|
+
|
|
178
|
+
Flowsafe has no Astryx or CSS dependency. The repository showcase injects Astryx in the application only.
|
|
179
|
+
|
|
180
|
+
## Multi-tenancy
|
|
181
|
+
|
|
182
|
+
Flowsafe applies three base invariants.
|
|
183
|
+
|
|
184
|
+
### The run id carries the tenant
|
|
185
|
+
|
|
186
|
+
The host mints `${tenantId}_${uuid}` from authenticated context. `RunnerRuntime.start()` requires a run id and has no generation fallback. Status and resume return 404 for a foreign run.
|
|
187
|
+
|
|
188
|
+
The run id scopes the snapshot, Durable Object, connector isolation context, approval lookup, and artifact path.
|
|
189
|
+
|
|
190
|
+
### Stores bind at construction
|
|
191
|
+
|
|
192
|
+
`D1ApprovalStoreFactory.forTenant()` returns a branded tenant-bound store. Request handlers cannot pass an unbound or system store where a tenant store is required.
|
|
193
|
+
|
|
194
|
+
Construct the store after authentication through `createTenantResolver()`. The system store exists only for scheduled cross-tenant maintenance.
|
|
195
|
+
|
|
196
|
+
### The tenant charset makes prefix ownership exact
|
|
197
|
+
|
|
198
|
+
Tenant ids match `^[a-z0-9]{3,32}$`. This excludes the `_` run and memory delimiter, making prefix ownership and D1 range deletion exact.
|
|
199
|
+
|
|
200
|
+
Provision each named tenant before issuing credentials. Do not infer customer identity from a slug without the registry.
|
|
201
|
+
|
|
202
|
+
## Memory, retention, and offboarding
|
|
149
203
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
204
|
+
Mastra memory ids are caller-chosen by default. In a multi-tenant host:
|
|
205
|
+
|
|
206
|
+
- mint threads with `TenantContext.newThreadId()`;
|
|
207
|
+
- mint resources with `TenantContext.newResourceId(key)`;
|
|
208
|
+
- reject client bodies that name memory ids;
|
|
209
|
+
- return 404 for foreign stored ids;
|
|
210
|
+
- reach a thread Durable Object only through `createThreadTopology()`.
|
|
211
|
+
|
|
212
|
+
Retention helpers cover:
|
|
213
|
+
|
|
214
|
+
- terminal workflow snapshots;
|
|
215
|
+
- decided approvals;
|
|
216
|
+
- idle threads and their messages;
|
|
217
|
+
- terminal notifications;
|
|
218
|
+
- thread state and goals;
|
|
219
|
+
- schedule trigger history;
|
|
220
|
+
- terminal background tasks.
|
|
221
|
+
|
|
222
|
+
Schedules, resources/working memory, and provider subscriptions are standing state and delete at offboarding, not by default TTL.
|
|
223
|
+
|
|
224
|
+
`purgeTenant()` deletes every adopted tenant domain. Pass the artifact store so R2 objects delete with their owning run rows.
|
|
225
|
+
|
|
226
|
+
## Artifacts
|
|
227
|
+
|
|
228
|
+
`R2ArtifactStore` uses keys shaped as:
|
|
229
|
+
|
|
230
|
+
```text
|
|
231
|
+
[prefix/]workflowId/runId/name
|
|
153
232
|
```
|
|
154
233
|
|
|
155
|
-
|
|
156
|
-
sweep is an unfiltered cross-tenant read *and write*, so it lives in a
|
|
157
|
-
standalone `sweepSLA(factory.system(), { systemActor, audit, onEscalation })`
|
|
158
|
-
that takes a `SystemApprovalStore` — a type a request handler cannot obtain.
|
|
159
|
-
Call it from `scheduled()`. Breached open requests transition to `escalated`
|
|
160
|
-
(still decidable) and fire `onEscalation`.
|
|
161
|
-
|
|
162
|
-
Grant scope: a step-keyed approval unlocks its connectors only for the leg
|
|
163
|
-
that resumes that step, and only for the suspension it was decided during —
|
|
164
|
-
when the same step suspends again, the earlier approval is spent and the new
|
|
165
|
-
suspension needs its own decision. Create a step-less approval for
|
|
166
|
-
deliberately run-scoped standing grants. Self-approval (decider ==
|
|
167
|
-
requester) is denied unless the service is constructed with
|
|
168
|
-
`allowSelfDecision` — `true` exempts every decider, or `{ roles }` exempts
|
|
169
|
-
only the listed roles (a single-operator deployment sets e.g.
|
|
170
|
-
`{ roles: ['admin'] }`; composed hosts pass `APPROVAL_ALLOW_SELF_DECISION`).
|
|
171
|
-
A permitted self-decision is audited with `detail.selfDecision: true`. If a decision's
|
|
172
|
-
resume attempt fails (`resume.ok === false`), the decision is already
|
|
173
|
-
durable — re-drive the run by POSTing its resume route with the record's
|
|
174
|
-
`stepPath` and the `defaultResumeData` shape; grants re-derive from the
|
|
175
|
-
store.
|
|
176
|
-
|
|
177
|
-
### Dashboard (`@proofoftech/flowsafe/approval-ui`)
|
|
178
|
-
|
|
179
|
-
A React dashboard over the REST API — queue, detail + decision form, metrics.
|
|
180
|
-
It is **styling-library agnostic**: the views render through injected slot
|
|
181
|
-
components, so you plug in your own design system — or use the built-in unstyled
|
|
182
|
-
HTML default. `react`/`react-dom` are optional peers needed only for this
|
|
183
|
-
subpath, and it runs on React 18+.
|
|
234
|
+
Workflow and run ids use the runner's path-safe pattern. Artifact names are validated segment by segment. `deleteRun()` pairs with terminal-run retention; tenant purge removes the remaining tenant artifacts.
|
|
184
235
|
|
|
185
|
-
|
|
186
|
-
|
|
236
|
+
`InMemoryArtifactBucket` is available for tests and offline demos.
|
|
237
|
+
|
|
238
|
+
## Audit export
|
|
239
|
+
|
|
240
|
+
`queueAuditSink(queue)` turns the shared audit contract into Cloudflare Queue messages. `createAuditQueueConsumer()` batches records as NDJSON, posts them to the configured collector, acknowledges the batch on 2xx, and retries otherwise.
|
|
241
|
+
|
|
242
|
+
The types are structural and do not require `@cloudflare/workers-types`. A transform seam can map internal events to your SIEM schema.
|
|
243
|
+
|
|
244
|
+
## Live streaming
|
|
245
|
+
|
|
246
|
+
Live updates are opt-in behind a `HUB` Durable Object binding and `STREAM_TICKET_SECRET`.
|
|
247
|
+
|
|
248
|
+
An authenticated REST request mints a short-lived HMAC ticket. The browser presents it when opening a queue or run WebSocket. The Worker is the only verifier, and each Durable Object rebinds the addressed tenant or run through its own identity.
|
|
249
|
+
|
|
250
|
+
Tickets carry addressing information only. They contain no connector grant or approval decision. Polling remains available as fallback and reconciliation.
|
|
251
|
+
|
|
252
|
+
## Long-running agents
|
|
253
|
+
|
|
254
|
+
The following surfaces are supported and opt-in: they are tested and covered by package compatibility guarantees, but the host must explicitly wire the required routes, bindings, storage domains, or scheduled duties.
|
|
255
|
+
|
|
256
|
+
### Durable agents
|
|
257
|
+
|
|
258
|
+
`createFlowsafeDurableAgent()` routes Mastra's durable-agent workflow through `RunnerRuntime`. Public start entry points require a caller-minted tenant run id. After an isolate restart, `resumeViaRuntime()` prepares the agent registry, registers observation, and resumes through the runtime after validating memory ownership.
|
|
259
|
+
|
|
260
|
+
### Signals and notifications
|
|
261
|
+
|
|
262
|
+
`createThreadSignalRoutes()` hosts message, queue, signal, state, and notification delivery in the thread Durable Object. `createSignalRouter()` is the Worker trust boundary: authenticate, authorize, ownership-check, cap, parse, reject memory ids, allowlist attributes, rate-limit, audit, then forward.
|
|
263
|
+
|
|
264
|
+
`D1NotificationsStorage` and `D1ThreadStateStorage` mirror Mastra's in-memory domains on D1. `SignalClient` is available from the browser-safe `signals/client` export.
|
|
187
265
|
|
|
188
|
-
|
|
266
|
+
### Goals
|
|
189
267
|
|
|
190
|
-
|
|
191
|
-
const dashboard = createApprovalDashboard(document.getElementById('root')!, { client });
|
|
268
|
+
`createObjectiveRouter()` manages one durable objective per thread through Mastra's own goal read/write shape. Writes are role-gated, size- and run-budget-capped, and audited.
|
|
192
269
|
|
|
193
|
-
|
|
194
|
-
|
|
270
|
+
### Schedules
|
|
271
|
+
|
|
272
|
+
`D1SchedulesStorage` implements the schedule domain. `createScheduleRouter()` provides tenant-filtered CRUD and read-only trigger history. `createScheduleTick()` claims due fires with CAS, protects reserved context keys, checks unattended-run caps, mints a tenant run id, and starts a workflow or agent through the correct topology.
|
|
273
|
+
|
|
274
|
+
### Background tasks
|
|
275
|
+
|
|
276
|
+
`createBackgroundTaskD1Domains()` supplies serialized workflow and tenant task storage. `BackgroundTaskHost` owns one manager per tenant Durable Object, while `createBackgroundTaskRoutes()` exposes its host surface. Terminal task cleanup is opt-in through the composed Worker.
|
|
277
|
+
|
|
278
|
+
### Signal providers
|
|
279
|
+
|
|
280
|
+
Flowsafe providers route polling and webhook deliveries through the thread topology instead of Mastra's in-process registry.
|
|
281
|
+
|
|
282
|
+
`SignalProviderHost` runs one alarm-driven host per tenant. `D1SubscriptionStoreFactory` persists subscriptions. Human-only subscription routes reconcile provider alarms after each committed mutation. Webhook routes verify raw bytes before parsing, derive the tenant from the stored subscription, apply a provider-and-tenant rate cap, and bound forgery audit.
|
|
283
|
+
|
|
284
|
+
`githubSignalProvider()` is the reference provider.
|
|
285
|
+
|
|
286
|
+
Complete wiring is in the [durable-agents guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md) and [advanced starter](https://github.com/ProofOfTechOrg/anchorage/tree/main/packages/agent-starter).
|
|
287
|
+
|
|
288
|
+
## Deployment and operations
|
|
289
|
+
|
|
290
|
+
The composed `createFlowsafeWorker()` owns the shared route, scheduled, and Queue pipeline. Hosts inject workflows, identity verification, topology-backed optional routers, budget wrappers, notification transport, artifact pairing, schedule tick, and extra purge duties.
|
|
291
|
+
|
|
292
|
+
Use separate cron expressions for approval SLA sweep, retention purge, and schedule fire. Provider polling uses per-tenant Durable Object alarms.
|
|
293
|
+
|
|
294
|
+
Read:
|
|
295
|
+
|
|
296
|
+
- [Deployment reference](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/deployment-reference.md)
|
|
297
|
+
- [Operations runbook](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/operations-runbook.md)
|
|
298
|
+
- [Security threat model](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/security-threat-model.md)
|
|
299
|
+
|
|
300
|
+
## Security boundaries
|
|
301
|
+
|
|
302
|
+
Flowsafe does not authenticate users, execute an identity-provider protocol, provide a network sandbox, or decide which business action is safe. It supplies enforcement seams after your host has verified identity and selected policy.
|
|
303
|
+
|
|
304
|
+
Critical host obligations:
|
|
305
|
+
|
|
306
|
+
- derive tenants and actors from verified credentials;
|
|
307
|
+
- mint run, thread, resource, schedule, and subscription identities server-side;
|
|
308
|
+
- keep connector lists and resume targets server-authored;
|
|
309
|
+
- expose decisions only through the approval path;
|
|
310
|
+
- configure shared stores for cross-isolate connector budgets;
|
|
311
|
+
- keep raw Durable Object namespaces behind the exported topologies;
|
|
312
|
+
- schedule every enabled domain's retention and offboarding path;
|
|
313
|
+
- protect model, provider, stream-ticket, webhook, and SIEM secrets separately.
|
|
314
|
+
|
|
315
|
+
## Verification
|
|
316
|
+
|
|
317
|
+
The repository's deterministic workerd spike proves suspend, process restart, resume, forged-resume denial, repeated gates, tenant isolation, live streaming, durable-agent recovery, signals, goals, schedules, providers, notifications, and background-task restart.
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
pnpm --filter @proofoftech/flowsafe spike:verify
|
|
195
321
|
```
|
|
196
322
|
|
|
197
|
-
|
|
198
|
-
render any UI you like. A ready-to-run reference app lives in the repo's
|
|
199
|
-
`showcase` package (`packages/showcase/` — `pnpm --filter showcase dev`, or
|
|
200
|
-
`pnpm dev` at the root): a full Vite build that injects an
|
|
201
|
-
[Astryx](https://astryx.atmeta.com) adapter, bundles that library's CSS, and —
|
|
202
|
-
in dev — mounts a live seeded approval-api at `/api/approvals` so
|
|
203
|
-
claim/decide/delegate drive real state.
|
|
323
|
+
The optional live-model proof requires `SPIKE_LLM_MODEL_ID` and `SPIKE_LLM_API_KEY`:
|
|
204
324
|
|
|
205
|
-
|
|
325
|
+
```bash
|
|
326
|
+
pnpm --filter @proofoftech/flowsafe spike:verify:llm
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## License
|
|
206
330
|
|
|
207
|
-
|
|
208
|
-
corollary.
|
|
209
|
-
|
|
210
|
-
**INV-1 — the run id carries the tenant.** Every `runId` is minted
|
|
211
|
-
server-side as `` `${tenantId}_${uuid}` `` from the *authenticated* tenant.
|
|
212
|
-
`createRunRouter` rejects a client-supplied `body.runId` with 400,
|
|
213
|
-
`RunnerRuntime.start` requires a `runId` (there is no generation fallback),
|
|
214
|
-
and the Durable Object refuses any request whose `(workflowId, runId)`
|
|
215
|
-
disagrees with its own `ctx.id.name`. Because `runId` is the key everything
|
|
216
|
-
else derives from, this makes the Mastra snapshot row, the DO instance, the
|
|
217
|
-
per-run lock, the grant-mint predicate, and the R2 key tenant-disjoint with
|
|
218
|
-
no schema change and no signature change. Status and resume additionally
|
|
219
|
-
check ownership and answer **404** — not 403 — for another tenant's run, so
|
|
220
|
-
the route is not an existence oracle.
|
|
221
|
-
|
|
222
|
-
**INV-2 — the store is bound to one tenant at construction.** Approval
|
|
223
|
-
stores come only from a factory (`D1ApprovalStoreFactory.forTenant()`), and
|
|
224
|
-
the bound type carries a `unique symbol` brand: an unbound store, or the
|
|
225
|
-
cron-only `SystemApprovalStore`, is a *compile error* wherever a request
|
|
226
|
-
handler expects a bound one. `tenantId` is deliberately not a member of
|
|
227
|
-
`ApprovalListFilter` — an omissible tenant filter is the canonical fail-open.
|
|
228
|
-
Requests flow through a `TenantResolver` (authenticate → validate → bind), so
|
|
229
|
-
no pre-auth store exists.
|
|
230
|
-
|
|
231
|
-
**INV-3 — the charset makes the prefix exact.** `tenantId` matches
|
|
232
|
-
`^[a-z0-9]{3,32}$`. That set contains no character in `[0x5F, 0x60]` —
|
|
233
|
-
neither `_` nor `` ` `` — so `runId.startsWith(tenantId + '_')` cannot match
|
|
234
|
-
another tenant (`acme` never matches `acmecorp`), and the offboarding range
|
|
235
|
-
delete `` run_id >= '<tid>_' AND run_id < '<tid>`' `` selects exactly one
|
|
236
|
-
tenant's rows. Loosening the charset silently breaks both; a
|
|
237
|
-
character-exhaustive test pins it.
|
|
238
|
-
|
|
239
|
-
Consequences worth knowing:
|
|
240
|
-
|
|
241
|
-
- **Provision before you issue tokens.** `provisionTenant(db, { tenantId, kind })`
|
|
242
|
-
(import from `@proofoftech/flowsafe/host-kit`)
|
|
243
|
-
inserts into the `tenants` registry or fails. Nothing else enforces tenant-id
|
|
244
|
-
uniqueness, and two clients slugged `acme` would merge entirely.
|
|
245
|
-
- **Every actor carries a tenant.** `ApprovalActor` is `{ id, role, tenantId }`;
|
|
246
|
-
a bearer-map entry or JWT claim without an INV-3-valid `tenantId` is dropped
|
|
247
|
-
and its token 401s. breakwater's own `Actor` stays tenant-agnostic.
|
|
248
|
-
- **Connector budgets are per-tenant.** The runtime mints an opaque
|
|
249
|
-
`breakwater.isolationScope` on every leg of a tenant-salted run, and
|
|
250
|
-
breakwater segments its idempotency and rate-limit keys by it — so one
|
|
251
|
-
tenant exhausting a connector's budget cannot throttle another, and two
|
|
252
|
-
tenants sharing a business-level idempotency key do not replay each other's
|
|
253
|
-
results. Absent scope preserves the single-tenant keys exactly; there is no
|
|
254
|
-
flag to forget.
|
|
255
|
-
- **Offboarding is one call.** `purgeTenant(db, { tenantId, artifactStore })`
|
|
256
|
-
(import from `@proofoftech/flowsafe/do-runner` or the package root)
|
|
257
|
-
reaps snapshots of *any* status (a run abandoned at a gate is never eligible
|
|
258
|
-
for the terminal-only retention purge), the tenant's agent-memory rows
|
|
259
|
-
(threads/messages/resources — salted ids, same exact range predicate), the
|
|
260
|
-
tenant's approval records, and its R2 artifacts. Only purge tenants whose
|
|
261
|
-
tokens have already expired.
|
|
262
|
-
- **Agent-memory ids are tenant-salted.** Mastra memory is keyed by
|
|
263
|
-
caller-chosen `threadId`/`resourceId`, which two tenants can legitimately
|
|
264
|
-
share. `TenantContext.newThreadId()`/`newResourceId(key)` (and the
|
|
265
|
-
underlying `mintThreadId`/`mintResourceId` from
|
|
266
|
-
`@proofoftech/flowsafe/do-runner`) are the only constructors: ids are
|
|
267
|
-
`${tenantId}_${suffix}`, ownership is an exact prefix check
|
|
268
|
-
(`ownsMemoryId`), and hosts never accept a client-supplied memory id. See
|
|
269
|
-
`docs/agent-memory-tenancy.md` for the feature-side obligations.
|
|
270
|
-
|
|
271
|
-
### Deployment & ops
|
|
272
|
-
|
|
273
|
-
Copy [`deploy/`](deploy/) as a production starting point: a Worker wiring one
|
|
274
|
-
DO per run, the D1 approval queue, the tenant resolver over a bearer-token
|
|
275
|
-
verifier, an optional subdomain↔tenant cross-check, and a cron trigger that
|
|
276
|
-
owns the SLA sweep and snapshot retention purge. `pnpm deploy:dev` runs it on
|
|
277
|
-
local workerd (no Cloudflare account); `pnpm deploy:cf` deploys it. Checklist
|
|
278
|
-
and configuration table: [`deploy/README.md`](deploy/README.md).
|
|
279
|
-
|
|
280
|
-
Audit export ships as a Cloudflare Queues sink + SIEM consumer
|
|
281
|
-
(`@proofoftech/flowsafe/audit-export`): `queueAuditSink(env.QUEUE)` plugs into
|
|
282
|
-
any breakwater/approval audit sink, and `createAuditQueueConsumer({ endpoint })`
|
|
283
|
-
POSTs each batch as NDJSON, acking on 2xx and retrying otherwise. Workflow
|
|
284
|
-
artifacts persist to R2 via `R2ArtifactStore`
|
|
285
|
-
(`@proofoftech/flowsafe/artifacts`), keyed `workflowId/runId/name`.
|
|
286
|
-
|
|
287
|
-
See `docs/flowsafe-architecture.md` and `docs/do-runner-design.md` for design details.
|
|
331
|
+
Apache-2.0.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The suspend-payload `type` discriminator core stamps on an approval gate. */
|
|
2
|
+
export declare const AGENT_APPROVAL_SUSPEND_TYPE = "approval";
|
|
3
|
+
/** The tool-call identity parsed out of an agent approval suspend payload. */
|
|
4
|
+
export interface AgentApprovalSuspend {
|
|
5
|
+
toolCallId?: string;
|
|
6
|
+
toolName?: string;
|
|
7
|
+
args?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parse a durable-agent approval suspend payload — a PER-STEP payload, already
|
|
11
|
+
* unwrapped from RunSummary.suspendPayload's step-keyed map — into its tool-call
|
|
12
|
+
* identity, reading both supported shapes: the nested `requireToolApproval` object
|
|
13
|
+
* when present, else the FLAT top-level fields.
|
|
14
|
+
*
|
|
15
|
+
* Returns undefined for any payload that is NOT an agent tool-call gate: a
|
|
16
|
+
* non-object, a non-'approval' `type`, or a workflow-step gate that names no
|
|
17
|
+
* tool (it declares its own `connectors` instead — the caller keeps its
|
|
18
|
+
* existing handling for those). Fail-closed: a payload naming no tool at all
|
|
19
|
+
* yields undefined so agentGateConnectors() invents no grant.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseAgentApprovalSuspend(payload: unknown): AgentApprovalSuspend | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The breakwater connector ids an approved agent gate should grant: the single
|
|
24
|
+
* provider-safe tool id the model called (== the connector id the write gate
|
|
25
|
+
* checks; see the file header's provider-rewrite constraint). Requires
|
|
26
|
+
* BOTH a non-empty `toolName` AND a non-empty `toolCallId` — a real
|
|
27
|
+
* durable-agent gate always carries both (toolCallId is the suspend's
|
|
28
|
+
* `resumeLabel`), so demanding both never rejects a real gate while narrowing
|
|
29
|
+
* the surface where a workflow-step gate COINCIDENTALLY shaped `{type:'approval',
|
|
30
|
+
* toolName}` would mint an unintended grant (a workflow author's own convention
|
|
31
|
+
* is an explicit `connectors` array, which requestedConnectors takes first).
|
|
32
|
+
* Returns [] otherwise, so a decision never invents a grant the suspension did
|
|
33
|
+
* not request (fail-closed).
|
|
34
|
+
*/
|
|
35
|
+
export declare function agentGateConnectors(payload: unknown): string[];
|
|
36
|
+
//# sourceMappingURL=approval-shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-shapes.d.ts","sourceRoot":"","sources":["../../src/agent-runner/approval-shapes.ts"],"names":[],"mappings":"AA2BA,gFAAgF;AAChF,eAAO,MAAM,2BAA2B,aAAa,CAAC;AAItD,8EAA8E;AAC9E,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAYD;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,GACf,oBAAoB,GAAG,SAAS,CAqBlC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAS9D"}
|