@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.
Files changed (271) hide show
  1. package/CHANGELOG.md +327 -0
  2. package/README.md +295 -251
  3. package/dist/agent-runner/approval-shapes.d.ts +36 -0
  4. package/dist/agent-runner/approval-shapes.d.ts.map +1 -0
  5. package/dist/agent-runner/approval-shapes.js +101 -0
  6. package/dist/agent-runner/approval-shapes.js.map +1 -0
  7. package/dist/agent-runner/durable-agent-runner.d.ts +158 -0
  8. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
  9. package/dist/agent-runner/durable-agent-runner.js +295 -0
  10. package/dist/agent-runner/durable-agent-runner.js.map +1 -0
  11. package/dist/agent-runner/index.d.ts +3 -0
  12. package/dist/agent-runner/index.d.ts.map +1 -0
  13. package/dist/agent-runner/index.js +10 -0
  14. package/dist/agent-runner/index.js.map +1 -0
  15. package/dist/approval-api/contract.d.ts +2 -2
  16. package/dist/approval-api/d1-store.d.ts.map +1 -1
  17. package/dist/approval-api/d1-store.js +87 -19
  18. package/dist/approval-api/d1-store.js.map +1 -1
  19. package/dist/approval-api/grants.d.ts +1 -1
  20. package/dist/approval-api/grants.js +1 -1
  21. package/dist/approval-api/index.d.ts +1 -1
  22. package/dist/approval-api/index.d.ts.map +1 -1
  23. package/dist/approval-api/index.js.map +1 -1
  24. package/dist/approval-api/router.d.ts +2 -2
  25. package/dist/approval-api/router.d.ts.map +1 -1
  26. package/dist/approval-api/router.js +1 -0
  27. package/dist/approval-api/router.js.map +1 -1
  28. package/dist/approval-api/service.d.ts +10 -11
  29. package/dist/approval-api/service.d.ts.map +1 -1
  30. package/dist/approval-api/service.js +22 -9
  31. package/dist/approval-api/service.js.map +1 -1
  32. package/dist/approval-api/store.d.ts +27 -22
  33. package/dist/approval-api/store.d.ts.map +1 -1
  34. package/dist/approval-api/store.js +25 -9
  35. package/dist/approval-api/store.js.map +1 -1
  36. package/dist/approval-api/tenant-context.d.ts +6 -6
  37. package/dist/approval-api/tenant-context.d.ts.map +1 -1
  38. package/dist/approval-api/tenant-context.js +15 -0
  39. package/dist/approval-api/tenant-context.js.map +1 -1
  40. package/dist/approval-api/tenant-store.d.ts +1 -1
  41. package/dist/approval-api/tenant-store.d.ts.map +1 -1
  42. package/dist/approval-api/types.d.ts +13 -4
  43. package/dist/approval-api/types.d.ts.map +1 -1
  44. package/dist/approval-api/types.js +2 -1
  45. package/dist/approval-api/types.js.map +1 -1
  46. package/dist/approval-ui/App.d.ts +2 -2
  47. package/dist/approval-ui/FilterBar.d.ts +3 -3
  48. package/dist/approval-ui/FilterBar.js +3 -3
  49. package/dist/approval-ui/client.d.ts +1 -1
  50. package/dist/approval-ui/components.d.ts +1 -1
  51. package/dist/approval-ui/stream.d.ts +3 -3
  52. package/dist/approval-ui/stream.js +2 -2
  53. package/dist/approval-ui/use-approval-dashboard.d.ts +9 -12
  54. package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
  55. package/dist/approval-ui/use-approval-dashboard.js +6 -9
  56. package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
  57. package/dist/approval-ui/use-web-socket-transport.d.ts +1 -1
  58. package/dist/approval-ui/use-web-socket-transport.js +1 -1
  59. package/dist/background-tasks/d1-storage.d.ts +66 -0
  60. package/dist/background-tasks/d1-storage.d.ts.map +1 -0
  61. package/dist/background-tasks/d1-storage.js +196 -0
  62. package/dist/background-tasks/d1-storage.js.map +1 -0
  63. package/dist/background-tasks/host.d.ts +82 -0
  64. package/dist/background-tasks/host.d.ts.map +1 -0
  65. package/dist/background-tasks/host.js +275 -0
  66. package/dist/background-tasks/host.js.map +1 -0
  67. package/dist/background-tasks/index.d.ts +7 -0
  68. package/dist/background-tasks/index.d.ts.map +1 -0
  69. package/dist/background-tasks/index.js +10 -0
  70. package/dist/background-tasks/index.js.map +1 -0
  71. package/dist/background-tasks/routes.d.ts +15 -0
  72. package/dist/background-tasks/routes.d.ts.map +1 -0
  73. package/dist/background-tasks/routes.js +144 -0
  74. package/dist/background-tasks/routes.js.map +1 -0
  75. package/dist/do-runner/breakwater-keys.d.ts +1 -1
  76. package/dist/do-runner/breakwater-keys.js +1 -1
  77. package/dist/do-runner/cf-types.d.ts +1 -1
  78. package/dist/do-runner/d1-storage.d.ts +347 -5
  79. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  80. package/dist/do-runner/d1-storage.js +571 -17
  81. package/dist/do-runner/d1-storage.js.map +1 -1
  82. package/dist/do-runner/do-error-response.d.ts +29 -0
  83. package/dist/do-runner/do-error-response.d.ts.map +1 -0
  84. package/dist/do-runner/do-error-response.js +73 -0
  85. package/dist/do-runner/do-error-response.js.map +1 -0
  86. package/dist/do-runner/durable-object.d.ts +3 -3
  87. package/dist/do-runner/durable-object.d.ts.map +1 -1
  88. package/dist/do-runner/durable-object.js +7 -21
  89. package/dist/do-runner/durable-object.js.map +1 -1
  90. package/dist/do-runner/hub-do.d.ts +2 -2
  91. package/dist/do-runner/index.d.ts +9 -3
  92. package/dist/do-runner/index.d.ts.map +1 -1
  93. package/dist/do-runner/index.js +8 -2
  94. package/dist/do-runner/index.js.map +1 -1
  95. package/dist/do-runner/init.d.ts +20 -0
  96. package/dist/do-runner/init.d.ts.map +1 -1
  97. package/dist/do-runner/init.js +12 -1
  98. package/dist/do-runner/init.js.map +1 -1
  99. package/dist/do-runner/memory-id.d.ts +3 -3
  100. package/dist/do-runner/memory-id.js +3 -3
  101. package/dist/do-runner/path-safe-id.d.ts +6 -6
  102. package/dist/do-runner/path-safe-id.js +6 -6
  103. package/dist/do-runner/pubsub.d.ts +18 -0
  104. package/dist/do-runner/pubsub.d.ts.map +1 -0
  105. package/dist/do-runner/pubsub.js +42 -0
  106. package/dist/do-runner/pubsub.js.map +1 -0
  107. package/dist/do-runner/runtime.d.ts +24 -1
  108. package/dist/do-runner/runtime.d.ts.map +1 -1
  109. package/dist/do-runner/runtime.js +28 -2
  110. package/dist/do-runner/runtime.js.map +1 -1
  111. package/dist/do-runner/thread-do.d.ts +74 -0
  112. package/dist/do-runner/thread-do.d.ts.map +1 -0
  113. package/dist/do-runner/thread-do.js +156 -0
  114. package/dist/do-runner/thread-do.js.map +1 -0
  115. package/dist/do-runner/thread-header.d.ts +16 -0
  116. package/dist/do-runner/thread-header.d.ts.map +1 -0
  117. package/dist/do-runner/thread-header.js +24 -0
  118. package/dist/do-runner/thread-header.js.map +1 -0
  119. package/dist/goals/index.d.ts +2 -0
  120. package/dist/goals/index.d.ts.map +1 -0
  121. package/dist/goals/index.js +7 -0
  122. package/dist/goals/index.js.map +1 -0
  123. package/dist/goals/objective-routes.d.ts +87 -0
  124. package/dist/goals/objective-routes.d.ts.map +1 -0
  125. package/dist/goals/objective-routes.js +375 -0
  126. package/dist/goals/objective-routes.js.map +1 -0
  127. package/dist/host-kit/approval-bridge.d.ts +28 -8
  128. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  129. package/dist/host-kit/approval-bridge.js +37 -15
  130. package/dist/host-kit/approval-bridge.js.map +1 -1
  131. package/dist/host-kit/bearer-auth.d.ts +1 -1
  132. package/dist/host-kit/bearer-auth.js +1 -1
  133. package/dist/host-kit/env-vars.d.ts +20 -0
  134. package/dist/host-kit/env-vars.d.ts.map +1 -1
  135. package/dist/host-kit/env-vars.js +30 -0
  136. package/dist/host-kit/env-vars.js.map +1 -1
  137. package/dist/host-kit/flowsafe-worker.d.ts +113 -6
  138. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  139. package/dist/host-kit/flowsafe-worker.js +253 -63
  140. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  141. package/dist/host-kit/host-approval-service.d.ts +13 -13
  142. package/dist/host-kit/host-approval-service.js +10 -10
  143. package/dist/host-kit/index.d.ts +3 -1
  144. package/dist/host-kit/index.d.ts.map +1 -1
  145. package/dist/host-kit/index.js +7 -0
  146. package/dist/host-kit/index.js.map +1 -1
  147. package/dist/host-kit/memory-boundary.d.ts +64 -0
  148. package/dist/host-kit/memory-boundary.d.ts.map +1 -0
  149. package/dist/host-kit/memory-boundary.js +109 -0
  150. package/dist/host-kit/memory-boundary.js.map +1 -0
  151. package/dist/host-kit/route-path.d.ts +17 -0
  152. package/dist/host-kit/route-path.d.ts.map +1 -0
  153. package/dist/host-kit/route-path.js +35 -0
  154. package/dist/host-kit/route-path.js.map +1 -0
  155. package/dist/host-kit/run-router.d.ts +10 -11
  156. package/dist/host-kit/run-router.d.ts.map +1 -1
  157. package/dist/host-kit/run-router.js.map +1 -1
  158. package/dist/host-kit/stream-router.d.ts +1 -1
  159. package/dist/host-kit/stream-router.d.ts.map +1 -1
  160. package/dist/host-kit/stream-ticket.d.ts +3 -3
  161. package/dist/host-kit/stream-ticket.d.ts.map +1 -1
  162. package/dist/host-kit/stream-ticket.js +1 -1
  163. package/dist/host-kit/tenant-registry.d.ts +1 -1
  164. package/dist/host-kit/tenant-registry.js +1 -1
  165. package/dist/host-kit/thread-topology.d.ts +44 -0
  166. package/dist/host-kit/thread-topology.d.ts.map +1 -0
  167. package/dist/host-kit/thread-topology.js +76 -0
  168. package/dist/host-kit/thread-topology.js.map +1 -0
  169. package/dist/host-kit/verifier.d.ts +1 -1
  170. package/dist/host-kit/verifier.js +1 -1
  171. package/dist/index.d.ts +4 -8
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +4 -4
  174. package/dist/index.js.map +1 -1
  175. package/dist/internal-error-response.d.ts +3 -0
  176. package/dist/internal-error-response.d.ts.map +1 -0
  177. package/dist/internal-error-response.js +20 -0
  178. package/dist/internal-error-response.js.map +1 -0
  179. package/dist/numeric-config.d.ts +4 -0
  180. package/dist/numeric-config.d.ts.map +1 -0
  181. package/dist/numeric-config.js +23 -0
  182. package/dist/numeric-config.js.map +1 -0
  183. package/dist/schedules/index.d.ts +5 -0
  184. package/dist/schedules/index.d.ts.map +1 -0
  185. package/dist/schedules/index.js +13 -0
  186. package/dist/schedules/index.js.map +1 -0
  187. package/dist/schedules/router.d.ts +66 -0
  188. package/dist/schedules/router.d.ts.map +1 -0
  189. package/dist/schedules/router.js +827 -0
  190. package/dist/schedules/router.js.map +1 -0
  191. package/dist/schedules/schedules-d1.d.ts +30 -0
  192. package/dist/schedules/schedules-d1.d.ts.map +1 -0
  193. package/dist/schedules/schedules-d1.js +374 -0
  194. package/dist/schedules/schedules-d1.js.map +1 -0
  195. package/dist/schedules/storage.d.ts +11 -0
  196. package/dist/schedules/storage.d.ts.map +1 -0
  197. package/dist/schedules/storage.js +34 -0
  198. package/dist/schedules/storage.js.map +1 -0
  199. package/dist/schedules/tick.d.ts +132 -0
  200. package/dist/schedules/tick.d.ts.map +1 -0
  201. package/dist/schedules/tick.js +598 -0
  202. package/dist/schedules/tick.js.map +1 -0
  203. package/dist/signal-providers/delivery.d.ts +24 -0
  204. package/dist/signal-providers/delivery.d.ts.map +1 -0
  205. package/dist/signal-providers/delivery.js +62 -0
  206. package/dist/signal-providers/delivery.js.map +1 -0
  207. package/dist/signal-providers/github-provider.d.ts +33 -0
  208. package/dist/signal-providers/github-provider.d.ts.map +1 -0
  209. package/dist/signal-providers/github-provider.js +116 -0
  210. package/dist/signal-providers/github-provider.js.map +1 -0
  211. package/dist/signal-providers/host-do.d.ts +81 -0
  212. package/dist/signal-providers/host-do.d.ts.map +1 -0
  213. package/dist/signal-providers/host-do.js +229 -0
  214. package/dist/signal-providers/host-do.js.map +1 -0
  215. package/dist/signal-providers/host-topology.d.ts +27 -0
  216. package/dist/signal-providers/host-topology.d.ts.map +1 -0
  217. package/dist/signal-providers/host-topology.js +36 -0
  218. package/dist/signal-providers/host-topology.js.map +1 -0
  219. package/dist/signal-providers/index.d.ts +8 -0
  220. package/dist/signal-providers/index.d.ts.map +1 -0
  221. package/dist/signal-providers/index.js +21 -0
  222. package/dist/signal-providers/index.js.map +1 -0
  223. package/dist/signal-providers/provider.d.ts +93 -0
  224. package/dist/signal-providers/provider.d.ts.map +1 -0
  225. package/dist/signal-providers/provider.js +89 -0
  226. package/dist/signal-providers/provider.js.map +1 -0
  227. package/dist/signal-providers/subscription-d1.d.ts +88 -0
  228. package/dist/signal-providers/subscription-d1.d.ts.map +1 -0
  229. package/dist/signal-providers/subscription-d1.js +259 -0
  230. package/dist/signal-providers/subscription-d1.js.map +1 -0
  231. package/dist/signal-providers/webhook-route.d.ts +96 -0
  232. package/dist/signal-providers/webhook-route.d.ts.map +1 -0
  233. package/dist/signal-providers/webhook-route.js +444 -0
  234. package/dist/signal-providers/webhook-route.js.map +1 -0
  235. package/dist/signals/client.d.ts +72 -0
  236. package/dist/signals/client.d.ts.map +1 -0
  237. package/dist/signals/client.js +87 -0
  238. package/dist/signals/client.js.map +1 -0
  239. package/dist/signals/d1-shared.d.ts +43 -0
  240. package/dist/signals/d1-shared.d.ts.map +1 -0
  241. package/dist/signals/d1-shared.js +46 -0
  242. package/dist/signals/d1-shared.js.map +1 -0
  243. package/dist/signals/index.d.ts +9 -0
  244. package/dist/signals/index.d.ts.map +1 -0
  245. package/dist/signals/index.js +15 -0
  246. package/dist/signals/index.js.map +1 -0
  247. package/dist/signals/notification-dispatch.d.ts +52 -0
  248. package/dist/signals/notification-dispatch.d.ts.map +1 -0
  249. package/dist/signals/notification-dispatch.js +198 -0
  250. package/dist/signals/notification-dispatch.js.map +1 -0
  251. package/dist/signals/notifications-d1.d.ts +27 -0
  252. package/dist/signals/notifications-d1.d.ts.map +1 -0
  253. package/dist/signals/notifications-d1.js +703 -0
  254. package/dist/signals/notifications-d1.js.map +1 -0
  255. package/dist/signals/router.d.ts +73 -0
  256. package/dist/signals/router.d.ts.map +1 -0
  257. package/dist/signals/router.js +240 -0
  258. package/dist/signals/router.js.map +1 -0
  259. package/dist/signals/storage.d.ts +11 -0
  260. package/dist/signals/storage.d.ts.map +1 -0
  261. package/dist/signals/storage.js +27 -0
  262. package/dist/signals/storage.js.map +1 -0
  263. package/dist/signals/thread-do-routes.d.ts +82 -0
  264. package/dist/signals/thread-do-routes.d.ts.map +1 -0
  265. package/dist/signals/thread-do-routes.js +660 -0
  266. package/dist/signals/thread-do-routes.js.map +1 -0
  267. package/dist/signals/thread-state-d1.d.ts +22 -0
  268. package/dist/signals/thread-state-d1.d.ts.map +1 -0
  269. package/dist/signals/thread-state-d1.js +83 -0
  270. package/dist/signals/thread-state-d1.js.map +1 -0
  271. package/package.json +11 -2
@@ -0,0 +1,101 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Durable-agent approval-suspend shape parsing (validation finding R-003).
3
+ //
4
+ // The durable-agentic-loop's tool-call step suspends for approval in TWO
5
+ // payload shapes, both validated against @mastra/core 1.50.0 dist
6
+ // (agent/durable/index.js):
7
+ //
8
+ // FLAT (pre-exec gate, :3283): { type:'approval', toolCallId, toolName, args }
9
+ // NESTED (mid-exec, :3385): { type:'approval', requireToolApproval:{ toolCallId, toolName, args } }
10
+ //
11
+ // Both carry `resumeLabel: toolCallId` and a `{ approved: boolean }` resume
12
+ // schema. A workflow STEP gate declares its own grants in an explicit
13
+ // `connectors` array; an AGENT gate instead names the tool the model wants to
14
+ // call by its provider-visible `toolName`. For a breakwater connector this must
15
+ // be the SAME provider-safe id (`[A-Za-z0-9_-]+`) the write gate checks.
16
+ // Providers rewrite punctuation-bearing ids such as `salesforce.createContact`
17
+ // before returning a tool call, and that rewrite is not reversible in the
18
+ // suspend payload. Hosts using automatic agent-gate grants must therefore give
19
+ // those connectors provider-safe ids. agentGateConnectors() mints [toolName],
20
+ // and the runtime's approvalGrantProvider derives that exact grant from the
21
+ // APPROVED record on resume.
22
+ //
23
+ // Pure and dependency-free (no @mastra import): it inspects a plain payload
24
+ // object only, so the record-creation/bridge path (host-kit/approval-bridge.ts)
25
+ // can call it without dragging the durable Agent — and therefore @mastra's
26
+ // Node built-ins — into any browser-reachable module.
27
+ /** The suspend-payload `type` discriminator core stamps on an approval gate. */
28
+ export const AGENT_APPROVAL_SUSPEND_TYPE = 'approval';
29
+ const PROVIDER_SAFE_TOOL_NAME = /^[A-Za-z0-9_-]+$/;
30
+ function asRecord(value) {
31
+ return value !== null && typeof value === 'object'
32
+ ? value
33
+ : undefined;
34
+ }
35
+ function asString(value) {
36
+ return typeof value === 'string' ? value : undefined;
37
+ }
38
+ /**
39
+ * Parse a durable-agent approval suspend payload — a PER-STEP payload, already
40
+ * unwrapped from RunSummary.suspendPayload's step-keyed map — into its tool-call
41
+ * identity, reading both supported shapes: the nested `requireToolApproval` object
42
+ * when present, else the FLAT top-level fields.
43
+ *
44
+ * Returns undefined for any payload that is NOT an agent tool-call gate: a
45
+ * non-object, a non-'approval' `type`, or a workflow-step gate that names no
46
+ * tool (it declares its own `connectors` instead — the caller keeps its
47
+ * existing handling for those). Fail-closed: a payload naming no tool at all
48
+ * yields undefined so agentGateConnectors() invents no grant.
49
+ */
50
+ export function parseAgentApprovalSuspend(payload) {
51
+ const record = asRecord(payload);
52
+ if (record === undefined)
53
+ return undefined;
54
+ if (record.type !== AGENT_APPROVAL_SUSPEND_TYPE)
55
+ return undefined;
56
+ // The two shapes are disjoint: NESTED carries a `requireToolApproval` object
57
+ // (mid-exec) and FLAT carries the fields at top level (pre-exec). Resolve the
58
+ // source as a UNIT — whichever shape is present — rather than field-by-field,
59
+ // so a malformed payload can never produce a mixed-provenance result.
60
+ const source = asRecord(record.requireToolApproval) ?? record;
61
+ const toolCallId = asString(source.toolCallId);
62
+ const toolName = asString(source.toolName);
63
+ const args = asRecord(source.args);
64
+ // An 'approval' payload that names neither a tool nor a call is not an agent
65
+ // tool-call gate we can round-trip — treat it as "not an agent gate" so the
66
+ // caller falls back to its workflow-step handling and no grant is invented.
67
+ if (toolName === undefined && toolCallId === undefined)
68
+ return undefined;
69
+ const parsed = {};
70
+ if (toolCallId !== undefined)
71
+ parsed.toolCallId = toolCallId;
72
+ if (toolName !== undefined)
73
+ parsed.toolName = toolName;
74
+ if (args !== undefined)
75
+ parsed.args = args;
76
+ return parsed;
77
+ }
78
+ /**
79
+ * The breakwater connector ids an approved agent gate should grant: the single
80
+ * provider-safe tool id the model called (== the connector id the write gate
81
+ * checks; see the file header's provider-rewrite constraint). Requires
82
+ * BOTH a non-empty `toolName` AND a non-empty `toolCallId` — a real
83
+ * durable-agent gate always carries both (toolCallId is the suspend's
84
+ * `resumeLabel`), so demanding both never rejects a real gate while narrowing
85
+ * the surface where a workflow-step gate COINCIDENTALLY shaped `{type:'approval',
86
+ * toolName}` would mint an unintended grant (a workflow author's own convention
87
+ * is an explicit `connectors` array, which requestedConnectors takes first).
88
+ * Returns [] otherwise, so a decision never invents a grant the suspension did
89
+ * not request (fail-closed).
90
+ */
91
+ export function agentGateConnectors(payload) {
92
+ const parsed = parseAgentApprovalSuspend(payload);
93
+ return parsed?.toolName !== undefined &&
94
+ parsed.toolName.length > 0 &&
95
+ PROVIDER_SAFE_TOOL_NAME.test(parsed.toolName) &&
96
+ parsed.toolCallId !== undefined &&
97
+ parsed.toolCallId.length > 0
98
+ ? [parsed.toolName]
99
+ : [];
100
+ }
101
+ //# sourceMappingURL=approval-shapes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-shapes.js","sourceRoot":"","sources":["../../src/agent-runner/approval-shapes.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAC3E,EAAE;AACF,yEAAyE;AACzE,kEAAkE;AAClE,4BAA4B;AAC5B,EAAE;AACF,oFAAoF;AACpF,4GAA4G;AAC5G,EAAE;AACF,4EAA4E;AAC5E,sEAAsE;AACtE,8EAA8E;AAC9E,gFAAgF;AAChF,yEAAyE;AACzE,+EAA+E;AAC/E,0EAA0E;AAC1E,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,6BAA6B;AAC7B,EAAE;AACF,4EAA4E;AAC5E,gFAAgF;AAChF,2EAA2E;AAC3E,sDAAsD;AAEtD,gFAAgF;AAChF,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC;AAEtD,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AASnD,SAAS,QAAQ,CAAC,KAAc;IAC9B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AAC;IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,MAAM,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAClD,OAAO,MAAM,EAAE,QAAQ,KAAK,SAAS;QACnC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC1B,uBAAuB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC7C,MAAM,CAAC,UAAU,KAAK,SAAS;QAC/B,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;QAC5B,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACnB,CAAC,CAAC,EAAE,CAAC;AACT,CAAC"}
@@ -0,0 +1,158 @@
1
+ import type { Agent, ToolsInput } from '@mastra/core/agent';
2
+ import { DurableAgent, type DurableAgentConfig, type DurableAgenticWorkflowInput, type DurableAgentStreamOptions } from '@mastra/core/agent/durable';
3
+ import type { Mastra } from '@mastra/core/mastra';
4
+ import { type RunnerRuntime, type RunSummary } from '../do-runner/index.js';
5
+ /**
6
+ * The shared workflow id every durable-agent loop compiles to (core's
7
+ * DurableAgentDefaults.AGENTIC_LOOP). Exposed so hosts and tests can reference
8
+ * the registered id without a magic string.
9
+ */
10
+ export declare const DURABLE_AGENTIC_LOOP_WORKFLOW_ID = "durable-agentic-loop";
11
+ /**
12
+ * Brand marking an agent as RUNTIME-DRIVEN: its inherited signal wake
13
+ * (`agent.stream` under `ifIdle:'wake'`) re-enters the tenant-run-ID-guarded
14
+ * {@link FlowsafeDurableAgent.executeWorkflow}, which drives
15
+ * `runtime.start('durable-agentic-loop', …)` rather than the base
16
+ * `createRun + run.start` on the default engine. The thread-Durable-Object signal
17
+ * routes require this brand before honoring an idle wake, because the wake is the
18
+ * one signal path that starts a run: a plain core `Agent` (or a STOCK
19
+ * `DurableAgent`, whose `stream()` mints a tenant-less UUID and whose
20
+ * `executeWorkflow` runs on the default engine) would start a run OUTSIDE
21
+ * RunnerRuntime — an unsafe second execution path that is tenant-unscoped and
22
+ * grant-underivable. Structural (a `unique symbol`-keyed truthy field) so a test
23
+ * double can opt in without constructing a real durable agent.
24
+ *
25
+ * The brand is paired with the host-owned idle-start seam: the thread Durable Object
26
+ * mints the tenant-salted run id and invokes the wrapper directly, avoiding
27
+ * core's tenant-less idle-wake id generation.
28
+ */
29
+ export declare const RUNTIME_DRIVEN_AGENT: unique symbol;
30
+ /**
31
+ * Does this value carry the {@link RUNTIME_DRIVEN_AGENT} brand — i.e. is its
32
+ * signal wake driven through RunnerRuntime rather than the default engine?
33
+ * Takes `unknown` so a caller holding a core `Agent` (whose type has no index
34
+ * for the brand symbol) can check without a cast.
35
+ */
36
+ export declare function isRuntimeDrivenAgent(agent: unknown): boolean;
37
+ /** Options for {@link createFlowsafeDurableAgent}. */
38
+ export interface FlowsafeDurableAgentOptions<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TOutput = undefined> {
39
+ /** The Agent to wrap with durable, runtime-driven execution. */
40
+ agent: Agent<TAgentId, TTools, TOutput>;
41
+ /**
42
+ * The RunnerRuntime through which the loop is driven. Required because
43
+ * this is the whole point of the flowsafe wrapper: executeWorkflow() calls
44
+ * `runtime.start('durable-agentic-loop', ...)` instead of the base
45
+ * `createRun + start`, so tenant-scoped run IDs, the per-leg grant context, and the resume
46
+ * ledger apply to agent legs. The loop workflow is registered on this runtime
47
+ * by the factory (idempotently — one shared id serves every durable agent).
48
+ */
49
+ runtime: RunnerRuntime;
50
+ /** Optional id override (defaults to agent.id). */
51
+ id?: TAgentId;
52
+ /** Optional name override (defaults to agent.name). */
53
+ name?: string;
54
+ /** Resumable-stream cache — see createDurableAgent's `cache`. */
55
+ cache?: DurableAgentConfig<TAgentId, TTools, TOutput>['cache'];
56
+ /**
57
+ * PubSub for the agent's own stream events (observe()/onChunk). DEFAULTS to
58
+ * `runtime.pubsub` (the host Durable Object's single identity) when omitted, so the
59
+ * run's events and the agent's observe()/emitError feed agree without the host
60
+ * wiring it twice — a mismatched pubsub would leave observe() replaying an
61
+ * empty feed. Pass an explicit instance only to override that default.
62
+ */
63
+ pubsub?: DurableAgentConfig<TAgentId, TTools, TOutput>['pubsub'];
64
+ /**
65
+ * Public Mastra thread runtime (`mastra.agentThreadStreamRuntime`). When
66
+ * present, started and rehydrated outputs are registered on the same pubsub
67
+ * identity so active-thread signals join the durable loop.
68
+ */
69
+ threadRuntime?: Mastra['agentThreadStreamRuntime'];
70
+ /** Max steps for the agentic loop (bakes into the shared loop's isTaskComplete step). */
71
+ maxSteps?: number;
72
+ }
73
+ /**
74
+ * A DurableAgent whose loop runs through {@link RunnerRuntime} rather than the
75
+ * base `createRun + run.start`. Construct via {@link createFlowsafeDurableAgent}
76
+ * so the loop workflow is registered on the runtime.
77
+ */
78
+ export declare class FlowsafeDurableAgent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TOutput = undefined> extends DurableAgent<TAgentId, TTools, TOutput> {
79
+ #private;
80
+ /**
81
+ * The runtime-driven brand the thread-Durable-Object signal wake requires (see
82
+ * {@link RUNTIME_DRIVEN_AGENT}). A `unique symbol` field, so it cannot collide
83
+ * with an inherited property and a plain `Agent` never carries it.
84
+ */
85
+ readonly [RUNTIME_DRIVEN_AGENT] = true;
86
+ constructor(options: FlowsafeDurableAgentOptions<TAgentId, TTools, TOutput>);
87
+ /**
88
+ * Enforce a caller-minted tenant-scoped run ID before the inherited durable
89
+ * `stream()` runs: without this the
90
+ * optional `options.runId` would let core mint a tenant-less
91
+ * `crypto.randomUUID()` upstream. The private run-ID guard rejects a missing or
92
+ * non-path-safe value before delegating to core.
93
+ * A host mints `${tenantId}_${uuid}` and passes it as `options.runId`.
94
+ */
95
+ stream(messages: Parameters<DurableAgent<TAgentId, TTools, TOutput>['stream']>[0], options?: Parameters<DurableAgent<TAgentId, TTools, TOutput>['stream']>[1]): Promise<Awaited<ReturnType<DurableAgent<TAgentId, TTools, TOutput>['stream']>>>;
96
+ /**
97
+ * The same tenant-scoped run-ID guard as {@link FlowsafeDurableAgent.stream} —
98
+ * `generate()`
99
+ * re-implements the durable setup and mints its own runId the same way when
100
+ * one is not supplied.
101
+ */
102
+ generate(messages: Parameters<DurableAgent<TAgentId, TTools, TOutput>['generate']>[0], options?: Parameters<DurableAgent<TAgentId, TTools, TOutput>['generate']>[1]): Promise<Awaited<ReturnType<DurableAgent<TAgentId, TTools, TOutput>['generate']>>>;
103
+ /**
104
+ * The same tenant-scoped run-ID guard as {@link FlowsafeDurableAgent.stream}.
105
+ * `prepare()`
106
+ * is the third inherited minting entry point: it forwards `options?.runId` into
107
+ * core's `prepareForDurableExecution` (agent/durable/index.js:5980), which mints
108
+ * a tenant-less `crypto.randomUUID()` when it is absent (index.js:589) AND
109
+ * REGISTERS a run under that id (index.js:5984) — so a later
110
+ * `resume(runId)`/`executeWorkflow` sees a bare UUID `PATH_SAFE_ID_PATTERN`
111
+ * already accepts, past every downstream guard. Enforce the caller-minted ID here, while
112
+ * "absent" is still visible.
113
+ */
114
+ prepare(messages: Parameters<DurableAgent<TAgentId, TTools, TOutput>['prepare']>[0], options?: Parameters<DurableAgent<TAgentId, TTools, TOutput>['prepare']>[1]): Promise<Awaited<ReturnType<DurableAgent<TAgentId, TTools, TOutput>['prepare']>>>;
115
+ /**
116
+ * Rehydrate a suspended durable-agent run after isolate eviction, restore its
117
+ * active thread registration, then resume through RunnerRuntime so approval
118
+ * grant derivation and the durable resume ledger remain authoritative.
119
+ * Hosts expose this only from their trusted approval-decision topology.
120
+ */
121
+ resumeViaRuntime(options: {
122
+ runId: string;
123
+ step?: string | string[];
124
+ resumeData?: unknown;
125
+ memory?: DurableAgentStreamOptions<TOutput>['memory'];
126
+ }): Promise<RunSummary>;
127
+ /**
128
+ * Drive the durable-agentic-loop through RunnerRuntime instead of the base
129
+ * `createRun + run.start`. stream()/generate() have already parked the
130
+ * non-serializables (model/tools/messageList) on the in-process run registry
131
+ * keyed by this runId, so the loop the runtime starts resolves them in-isolate
132
+ * while the runtime mints the per-leg grant context. The runId guard here is
133
+ * defense in depth — the public boundary (stream/generate) already enforced
134
+ * the tenant-scoped run-ID rule; this catches any future internal caller.
135
+ */
136
+ protected executeWorkflow(runId: string, workflowInput: DurableAgenticWorkflowInput): Promise<void>;
137
+ }
138
+ /**
139
+ * Wrap an Agent as a {@link FlowsafeDurableAgent} and register its loop workflow
140
+ * on the runtime — the same `runtime.register` path init()'s boundCreateWorkflow
141
+ * uses.
142
+ *
143
+ * Registration is IDEMPOTENT by id: every durable agent compiles to the ONE
144
+ * shared 'durable-agentic-loop' workflow (the `agentId` in each run's input
145
+ * routes to the right agent via the per-run registry), so a second
146
+ * createFlowsafeDurableAgent on a shared runtime must not throw 'duplicate
147
+ * workflow id'. Like init()'s createWorkflow, register() also throws once runs
148
+ * have started (the Mastra instance is frozen) — call this at host setup, before
149
+ * any run.
150
+ *
151
+ * Multi-agent caveat: the shared loop bakes in the FIRST registrant's `maxSteps`
152
+ * (it is compiled into the isTaskComplete step) as the DEFAULT — a per-call
153
+ * `stream(msg, { maxSteps })` still overrides it, so this only bites a
154
+ * second-plus agent that relies on its CONSTRUCTOR budget. Agents needing
155
+ * distinct default step budgets take separate runtimes.
156
+ */
157
+ export declare function createFlowsafeDurableAgent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TOutput = undefined>(options: FlowsafeDurableAgentOptions<TAgentId, TTools, TOutput>): FlowsafeDurableAgent<TAgentId, TTools, TOutput>;
158
+ //# sourceMappingURL=durable-agent-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-agent-runner.d.ts","sourceRoot":"","sources":["../../src/agent-runner/durable-agent-runner.ts"],"names":[],"mappings":"AAyDA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,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,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1E,OAAO,CACR,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CACxE;IAKD;;;;;OAKG;IACG,gBAAgB,CAAC,OAAO,EAAE;QAC9B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QACzB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,MAAM,CAAC,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;KACvD,GAAG,OAAO,CAAC,UAAU,CAAC;IA8DvB;;;;;;;;OAQG;cACsB,eAAe,CACtC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,2BAA2B,GACzC,OAAO,CAAC,IAAI,CAAC;CAqBjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,OAAO,GAAG,SAAS,EAEnB,OAAO,EAAE,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,GAC9D,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAWjD"}
@@ -0,0 +1,295 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // FlowsafeDurableAgent — drive Mastra's durable-agent loop through the ONE
3
+ // RunnerRuntime chokepoint (DL-001/DL-010) so every agent leg inherits the
4
+ // substrate's invariants: INV-1 server-minted runIds, per-leg
5
+ // requestContextForRun grant derivation, the resume ledger, RunSummary, and
6
+ // retention purge — with no second execution path to audit.
7
+ //
8
+ // The mechanic (validated against @mastra/core 1.50.0 dist, spike S1):
9
+ // DurableAgent compiles the agent loop to the default-engine workflow
10
+ // 'durable-agentic-loop' (agent/durable index.js: AGENTIC_LOOP :62,
11
+ // getWorkflow() :5936, agent-agnostic — the agent is resolved per run by the
12
+ // `agentId` in the input, so ONE registered loop serves every durable agent).
13
+ // `DurableAgent.stream()` resolves the non-serializable model/tools onto the
14
+ // in-process globalRunRegistry (keyed by runId), builds a serializable
15
+ // DurableAgenticWorkflowInput, then calls the OVERRIDABLE
16
+ // `executeWorkflow(runId, workflowInput)` — the documented subclass seam
17
+ // (durable-agent.d.ts: "Subclasses override this method to customize how the
18
+ // workflow is executed"; EventedAgent/InngestAgent override it the same way).
19
+ // The base runs it via `workflow.createRun() + run.start()`; we route it
20
+ // through `runtime.start('durable-agentic-loop', { runId, inputData })` instead.
21
+ //
22
+ // Why this composes the grant-only doctrine for free: the durable tool-call
23
+ // step hands `tool.execute` the ENGINE-LEG requestContext from its step params
24
+ // (index.js: `const { ..., requestContext } = params` :3138 ->
25
+ // `toolOptions = { ..., requestContext }` :3339 ->
26
+ // `tool.execute(cleanedArgs, toolOptions)` :3642), NOT the stream()-time
27
+ // registry copy. Under runtime drive that engine-leg context is exactly what
28
+ // #requestContextFor mints per leg — so approvalGrantProvider's
29
+ // `breakwater.approvedConnectors` grant reaches the connector write gate with
30
+ // zero extra wiring, and a forged/self resume that mints no grant fails closed
31
+ // there (the registry copy is read only for the fail-closed, over-require-safe
32
+ // approval PRE-check, S5).
33
+ //
34
+ // INV-1 at the boundary: stream()/generate()/prepare() are the THREE inherited
35
+ // minting entry points — each takes an OPTIONAL runId and, when it is absent,
36
+ // lets core mint a tenant-less crypto.randomUUID() upstream
37
+ // (prepareForDurableExecution, agent/durable index.js:589) that
38
+ // PATH_SAFE_ID_PATTERN then accepts, slipping past executeWorkflow's guard AND
39
+ // RunnerRuntime.start's (the exact fallback INV-1 forbids). All three are
40
+ // overridden ONLY to REQUIRE a caller-minted runId before delegating to super —
41
+ // and prepare() also REGISTERS the run under that id (index.js:5984), so an
42
+ // unguarded prepare() strands a tenant-less run in the registry. streamUntilIdle()
43
+ // needs no override: it drives agent.stream() (index.js:368), so the stream()
44
+ // guard already covers it. resume() is NOT overridden to be client-facing
45
+ // (A-D2/P8): resume flows ONLY through the approval-decision path
46
+ // (ApprovalService.decide -> resumeViaRuntime -> runtime.resume), which derives
47
+ // grants on the (suspendedAt, resumeCount) fingerprint. The inherited
48
+ // resume()/approveToolCall()/declineToolCall() still exist and never mint (they
49
+ // read the run-registry entry), but no route wires them.
50
+ //
51
+ // Live-isolate scope: the loop resolves the tool's execute closure from the
52
+ // in-process globalRunRegistry (populated by stream()). A DO holds one run in
53
+ // one isolate (P1), so a resume decided before eviction finds it. A resume
54
+ // AFTER eviction must first rehydrate that registry with DurableAgent.prepare()
55
+ // (the snapshot's messageListState wins) before runtime.resume — the S3 seam,
56
+ // wired by the host that owns the resume topology (see the CLAUDE.md note).
57
+ import { DurableAgent, } from '@mastra/core/agent/durable';
58
+ import { InvalidRunRequestError, PATH_SAFE_ID_PATTERN, } from '../do-runner/index.js';
59
+ /**
60
+ * The shared workflow id every durable-agent loop compiles to (core's
61
+ * DurableAgentDefaults.AGENTIC_LOOP). Exposed so hosts and tests can reference
62
+ * the registered id without a magic string.
63
+ */
64
+ export const DURABLE_AGENTIC_LOOP_WORKFLOW_ID = 'durable-agentic-loop';
65
+ /**
66
+ * Brand marking an agent as RUNTIME-DRIVEN: its inherited signal wake
67
+ * (`agent.stream` under `ifIdle:'wake'`) re-enters the tenant-run-ID-guarded
68
+ * {@link FlowsafeDurableAgent.executeWorkflow}, which drives
69
+ * `runtime.start('durable-agentic-loop', …)` rather than the base
70
+ * `createRun + run.start` on the default engine. The thread-Durable-Object signal
71
+ * routes require this brand before honoring an idle wake, because the wake is the
72
+ * one signal path that starts a run: a plain core `Agent` (or a STOCK
73
+ * `DurableAgent`, whose `stream()` mints a tenant-less UUID and whose
74
+ * `executeWorkflow` runs on the default engine) would start a run OUTSIDE
75
+ * RunnerRuntime — an unsafe second execution path that is tenant-unscoped and
76
+ * grant-underivable. Structural (a `unique symbol`-keyed truthy field) so a test
77
+ * double can opt in without constructing a real durable agent.
78
+ *
79
+ * The brand is paired with the host-owned idle-start seam: the thread Durable Object
80
+ * mints the tenant-salted run id and invokes the wrapper directly, avoiding
81
+ * core's tenant-less idle-wake id generation.
82
+ */
83
+ export const RUNTIME_DRIVEN_AGENT = Symbol('flowsafe.runtimeDrivenAgent');
84
+ /**
85
+ * Does this value carry the {@link RUNTIME_DRIVEN_AGENT} brand — i.e. is its
86
+ * signal wake driven through RunnerRuntime rather than the default engine?
87
+ * Takes `unknown` so a caller holding a core `Agent` (whose type has no index
88
+ * for the brand symbol) can check without a cast.
89
+ */
90
+ export function isRuntimeDrivenAgent(agent) {
91
+ return (typeof agent === 'object' &&
92
+ agent !== null &&
93
+ agent[RUNTIME_DRIVEN_AGENT] === true);
94
+ }
95
+ /**
96
+ * A DurableAgent whose loop runs through {@link RunnerRuntime} rather than the
97
+ * base `createRun + run.start`. Construct via {@link createFlowsafeDurableAgent}
98
+ * so the loop workflow is registered on the runtime.
99
+ */
100
+ export class FlowsafeDurableAgent extends DurableAgent {
101
+ /**
102
+ * The runtime-driven brand the thread-Durable-Object signal wake requires (see
103
+ * {@link RUNTIME_DRIVEN_AGENT}). A `unique symbol` field, so it cannot collide
104
+ * with an inherited property and a plain `Agent` never carries it.
105
+ */
106
+ [RUNTIME_DRIVEN_AGENT] = true;
107
+ #runtime;
108
+ #threadRuntime;
109
+ constructor(options) {
110
+ super({
111
+ agent: options.agent,
112
+ id: options.id,
113
+ name: options.name,
114
+ cache: options.cache,
115
+ // Default the agent's own stream pubsub to the runtime's identity (DL-001:
116
+ // ONE feed per DO), so a host that configures only init()'s pubsub still
117
+ // gets observe()/emitError aligned with the run's events (the run is driven
118
+ // through the runtime, which publishes on THAT identity). An explicit
119
+ // pubsub wins; both-absent falls to core's per-agent default (poll-only,
120
+ // byte-identical to before this seam existed).
121
+ pubsub: options.pubsub ?? options.runtime.pubsub,
122
+ maxSteps: options.maxSteps,
123
+ });
124
+ this.#runtime = options.runtime;
125
+ this.#threadRuntime = options.threadRuntime;
126
+ }
127
+ /**
128
+ * Tenant-scoped run-ID enforcement at the public boundary. The durable-agent entry points (stream /
129
+ * generate / prepare) take an OPTIONAL runId, and when it is omitted core's
130
+ * `prepareForDurableExecution` mints `crypto.randomUUID()`
131
+ * (agent/durable/index.js:589) — the exact tenant-less fallback this wrapper forbids —
132
+ * and hands it to `executeWorkflow` BELOW this class's own guard, where a bare
133
+ * UUID is already indistinguishable from a legitimately caller-minted one. So
134
+ * the guard must ALSO fire HERE, before `super.stream()/generate()/prepare()`,
135
+ * while "absent" is still visible. Same posture as `RunnerRuntime.start`
136
+ * (typeof + PATH_SAFE_ID_PATTERN, NO generation fallback); the `typeof` check
137
+ * is load-bearing because `RegExp.test` coerces its argument to a string, so a
138
+ * numeric runId would pass the pattern yet key a run by the number. Homed once
139
+ * and shared by the four call sites below so the rule cannot drift within this
140
+ * class.
141
+ */
142
+ #assertCallerRunId(runId) {
143
+ if (typeof runId !== 'string' || !PATH_SAFE_ID_PATTERN.test(runId)) {
144
+ throw new InvalidRunRequestError('a caller-minted runId is required and must be URL-path-safe (INV-1: hosts mint `<tenantId>_<uuid>`) — the durable-agent runner never generates one');
145
+ }
146
+ }
147
+ /**
148
+ * Enforce a caller-minted tenant-scoped run ID before the inherited durable
149
+ * `stream()` runs: without this the
150
+ * optional `options.runId` would let core mint a tenant-less
151
+ * `crypto.randomUUID()` upstream. The private run-ID guard rejects a missing or
152
+ * non-path-safe value before delegating to core.
153
+ * A host mints `${tenantId}_${uuid}` and passes it as `options.runId`.
154
+ */
155
+ async stream(messages, options) {
156
+ this.#assertCallerRunId(options?.runId);
157
+ const result = await super.stream(messages, options);
158
+ if (!options?.untilIdle) {
159
+ await this.#threadRuntime?.registerRun(this, result.output, (options ?? {}), this.pubsub);
160
+ }
161
+ return result;
162
+ }
163
+ /**
164
+ * The same tenant-scoped run-ID guard as {@link FlowsafeDurableAgent.stream} —
165
+ * `generate()`
166
+ * re-implements the durable setup and mints its own runId the same way when
167
+ * one is not supplied.
168
+ */
169
+ async generate(messages, options) {
170
+ this.#assertCallerRunId(options?.runId);
171
+ return super.generate(messages, options);
172
+ }
173
+ /**
174
+ * The same tenant-scoped run-ID guard as {@link FlowsafeDurableAgent.stream}.
175
+ * `prepare()`
176
+ * is the third inherited minting entry point: it forwards `options?.runId` into
177
+ * core's `prepareForDurableExecution` (agent/durable/index.js:5980), which mints
178
+ * a tenant-less `crypto.randomUUID()` when it is absent (index.js:589) AND
179
+ * REGISTERS a run under that id (index.js:5984) — so a later
180
+ * `resume(runId)`/`executeWorkflow` sees a bare UUID `PATH_SAFE_ID_PATTERN`
181
+ * already accepts, past every downstream guard. Enforce the caller-minted ID here, while
182
+ * "absent" is still visible.
183
+ */
184
+ async prepare(messages, options) {
185
+ this.#assertCallerRunId(options?.runId);
186
+ return super.prepare(messages, options);
187
+ }
188
+ /**
189
+ * Rehydrate a suspended durable-agent run after isolate eviction, restore its
190
+ * active thread registration, then resume through RunnerRuntime so approval
191
+ * grant derivation and the durable resume ledger remain authoritative.
192
+ * Hosts expose this only from their trusted approval-decision topology.
193
+ */
194
+ async resumeViaRuntime(options) {
195
+ this.#assertCallerRunId(options.runId);
196
+ await this.prepare([], {
197
+ runId: options.runId,
198
+ ...(options.memory !== undefined ? { memory: options.memory } : {}),
199
+ });
200
+ const observed = await this.observe(options.runId);
201
+ const emitTerminalError = async (error) => {
202
+ try {
203
+ await this.emitError(options.runId, error instanceof Error ? error : new Error(String(error)));
204
+ }
205
+ catch (publicationError) {
206
+ console.error(JSON.stringify({
207
+ type: 'durable-agent-resume-error-publication-failed',
208
+ runId: options.runId,
209
+ error: publicationError instanceof Error
210
+ ? publicationError.message
211
+ : String(publicationError),
212
+ }));
213
+ }
214
+ };
215
+ try {
216
+ await this.#threadRuntime?.registerRun(this, observed.output, {
217
+ runId: options.runId,
218
+ ...(options.memory !== undefined ? { memory: options.memory } : {}),
219
+ }, this.pubsub);
220
+ const summary = await this.#runtime.resume(this.getWorkflow().id, options.runId, {
221
+ ...(options.step !== undefined ? { step: options.step } : {}),
222
+ ...(options.resumeData !== undefined
223
+ ? { resumeData: options.resumeData }
224
+ : {}),
225
+ });
226
+ if (summary.status === 'failed') {
227
+ await emitTerminalError(new Error(summary.error ?? 'Durable agent workflow resume failed'));
228
+ }
229
+ return summary;
230
+ }
231
+ catch (error) {
232
+ await emitTerminalError(error);
233
+ throw error;
234
+ }
235
+ }
236
+ /**
237
+ * Drive the durable-agentic-loop through RunnerRuntime instead of the base
238
+ * `createRun + run.start`. stream()/generate() have already parked the
239
+ * non-serializables (model/tools/messageList) on the in-process run registry
240
+ * keyed by this runId, so the loop the runtime starts resolves them in-isolate
241
+ * while the runtime mints the per-leg grant context. The runId guard here is
242
+ * defense in depth — the public boundary (stream/generate) already enforced
243
+ * the tenant-scoped run-ID rule; this catches any future internal caller.
244
+ */
245
+ async executeWorkflow(runId, workflowInput) {
246
+ this.#assertCallerRunId(runId);
247
+ // getWorkflow() is memoized and its id is the shared loop id the factory
248
+ // registered; driving that exact id keeps the started run and the
249
+ // registered workflow in lockstep.
250
+ const summary = await this.#runtime.start(this.getWorkflow().id, {
251
+ runId,
252
+ inputData: workflowInput,
253
+ });
254
+ // Mirror the base: a FAILED run emits an error onto the agent's stream so
255
+ // observe()/onError see it. A SUSPENDED run is the approval-gate path — it
256
+ // returns normally and the host bridges the suspension to the approval
257
+ // queue. emitError publishes on this.pubsub, which the constructor defaults
258
+ // to the runtime's identity so the event reaches the run's observers.
259
+ if (summary.status === 'failed') {
260
+ await this.emitError(runId, new Error(summary.error ?? 'Durable agent workflow execution failed'));
261
+ }
262
+ }
263
+ }
264
+ /**
265
+ * Wrap an Agent as a {@link FlowsafeDurableAgent} and register its loop workflow
266
+ * on the runtime — the same `runtime.register` path init()'s boundCreateWorkflow
267
+ * uses.
268
+ *
269
+ * Registration is IDEMPOTENT by id: every durable agent compiles to the ONE
270
+ * shared 'durable-agentic-loop' workflow (the `agentId` in each run's input
271
+ * routes to the right agent via the per-run registry), so a second
272
+ * createFlowsafeDurableAgent on a shared runtime must not throw 'duplicate
273
+ * workflow id'. Like init()'s createWorkflow, register() also throws once runs
274
+ * have started (the Mastra instance is frozen) — call this at host setup, before
275
+ * any run.
276
+ *
277
+ * Multi-agent caveat: the shared loop bakes in the FIRST registrant's `maxSteps`
278
+ * (it is compiled into the isTaskComplete step) as the DEFAULT — a per-call
279
+ * `stream(msg, { maxSteps })` still overrides it, so this only bites a
280
+ * second-plus agent that relies on its CONSTRUCTOR budget. Agents needing
281
+ * distinct default step budgets take separate runtimes.
282
+ */
283
+ export function createFlowsafeDurableAgent(options) {
284
+ const durableAgent = new FlowsafeDurableAgent(options);
285
+ const workflow = durableAgent.getWorkflow();
286
+ if (!options.runtime.workflowIds().includes(workflow.id)) {
287
+ // getWorkflow()'s concrete engine generics are not single-cast-assignable to
288
+ // AnyWorkflow, so the double cast through `unknown` is required (init.ts gets
289
+ // away with a single cast because coreCreateWorkflow's return already lines
290
+ // up). The runtime only ever reads id / getWorkflowRunById / createRun off it.
291
+ options.runtime.register(workflow);
292
+ }
293
+ return durableAgent;
294
+ }
295
+ //# sourceMappingURL=durable-agent-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-agent-runner.js","sourceRoot":"","sources":["../../src/agent-runner/durable-agent-runner.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAC3E,2EAA2E;AAC3E,8DAA8D;AAC9D,4EAA4E;AAC5E,4DAA4D;AAC5D,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,oEAAoE;AACpE,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,uEAAuE;AACvE,0DAA0D;AAC1D,yEAAyE;AACzE,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,iFAAiF;AACjF,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,+DAA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AA0C;QAE1C,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC/B,yEAAyE;QACzE,kEAAkE;QAClE,mCAAmC;QACnC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE;YAC/D,KAAK;YACL,SAAS,EAAE,aAAa;SACzB,CAAC,CAAC;QACH,0EAA0E;QAC1E,2EAA2E;QAC3E,uEAAuE;QACvE,4EAA4E;QAC5E,sEAAsE;QACtE,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,IAAI,CAAC,SAAS,CAClB,KAAK,EACL,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,yCAAyC,CAAC,CACtE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,0BAA0B,CAKxC,OAA+D;IAE/D,MAAM,YAAY,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QACzD,6EAA6E;QAC7E,8EAA8E;QAC9E,4EAA4E;QAC5E,+EAA+E;QAC/E,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAkC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { AGENT_APPROVAL_SUSPEND_TYPE, type AgentApprovalSuspend, agentGateConnectors, parseAgentApprovalSuspend, } from './approval-shapes.js';
2
+ export { createFlowsafeDurableAgent, DURABLE_AGENTIC_LOOP_WORKFLOW_ID, FlowsafeDurableAgent, type FlowsafeDurableAgentOptions, isRuntimeDrivenAgent, RUNTIME_DRIVEN_AGENT, } from './durable-agent-runner.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-runner/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,2BAA2B,EAC3B,KAAK,oBAAoB,EACzB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @proofoftech/flowsafe/agent-runner — drive Mastra durable agents through the
3
+ // RunnerRuntime chokepoint (Track A, DL-001/DL-010).
4
+ //
5
+ // Subpath-only (like host-kit): it imports the durable Agent, which drags
6
+ // @mastra's Node built-ins, so it stays out of the root barrel and off the
7
+ // browser's import graph.
8
+ export { AGENT_APPROVAL_SUSPEND_TYPE, agentGateConnectors, parseAgentApprovalSuspend, } from './approval-shapes.js';
9
+ export { createFlowsafeDurableAgent, DURABLE_AGENTIC_LOOP_WORKFLOW_ID, FlowsafeDurableAgent, isRuntimeDrivenAgent, RUNTIME_DRIVEN_AGENT, } from './durable-agent-runner.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent-runner/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,+EAA+E;AAC/E,qDAAqD;AACrD,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,0BAA0B;AAE1B,OAAO,EACL,2BAA2B,EAE3B,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,oBAAoB,EAEpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,2BAA2B,CAAC"}
@@ -29,8 +29,8 @@ export declare const DECIDER_ROLES: readonly ApprovalRole[];
29
29
  * e2e mirror tripwire pins "breakwater's Actor fields + tenantId".
30
30
  *
31
31
  * `tenantId` crosses an authentication boundary (bearer map or JWT claims):
32
- * every verifier must validate it against TENANT_ID_PATTERN (INV-3,
33
- * do-runner/path-safe-id.ts) before constructing an ApprovalActor — the type
32
+ * every verifier must validate it against TENANT_ID_PATTERN in
33
+ * do-runner/path-safe-id.ts before constructing an ApprovalActor — the type
34
34
  * says `string`, but the type system has no authority over a decoded token.
35
35
  */
36
36
  export interface ApprovalActor {
@@ -1 +1 @@
1
- {"version":3,"file":"d1-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/d1-store.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EAQpB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,CAAC;CACnD;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,yBAAyB,CAAC;IACtD,KAAK,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACxC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;CAC/C;AAmTD,MAAM,WA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