@proofoftech/flowsafe 0.3.0 → 0.6.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 +336 -0
- 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 +154 -0
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
- package/dist/agent-runner/durable-agent-runner.js +291 -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 +29 -0
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +112 -18
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +8 -32
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +2 -2
- 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 +1 -1
- 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 +24 -3
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +116 -1
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +29 -6
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +62 -2
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +17 -1
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/tenant-store.js +8 -2
- package/dist/approval-api/tenant-store.js.map +1 -1
- package/dist/approval-api/types.d.ts +19 -0
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +16 -0
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +9 -1
- package/dist/approval-ui/App.d.ts.map +1 -1
- package/dist/approval-ui/App.js +10 -5
- package/dist/approval-ui/App.js.map +1 -1
- package/dist/approval-ui/DetailView.d.ts +4 -1
- package/dist/approval-ui/DetailView.d.ts.map +1 -1
- package/dist/approval-ui/DetailView.js +2 -2
- package/dist/approval-ui/DetailView.js.map +1 -1
- package/dist/approval-ui/QueueView.d.ts +7 -1
- package/dist/approval-ui/QueueView.d.ts.map +1 -1
- package/dist/approval-ui/QueueView.js +8 -3
- package/dist/approval-ui/QueueView.js.map +1 -1
- package/dist/approval-ui/client.d.ts +19 -0
- package/dist/approval-ui/client.d.ts.map +1 -1
- package/dist/approval-ui/client.js +29 -1
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/components.d.ts +20 -0
- package/dist/approval-ui/components.d.ts.map +1 -1
- package/dist/approval-ui/components.js +2 -0
- package/dist/approval-ui/components.js.map +1 -1
- package/dist/approval-ui/index.d.ts +4 -2
- package/dist/approval-ui/index.d.ts.map +1 -1
- package/dist/approval-ui/index.js +3 -0
- package/dist/approval-ui/index.js.map +1 -1
- package/dist/approval-ui/stream.d.ts +142 -0
- package/dist/approval-ui/stream.d.ts.map +1 -0
- package/dist/approval-ui/stream.js +136 -0
- package/dist/approval-ui/stream.js.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts +74 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +307 -7
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +10 -0
- package/dist/approval-ui/use-web-socket-transport.d.ts.map +1 -0
- package/dist/approval-ui/use-web-socket-transport.js +46 -0
- package/dist/approval-ui/use-web-socket-transport.js.map +1 -0
- 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/cf-types.d.ts +70 -2
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js +30 -1
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +343 -2
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +566 -13
- 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 +5 -2
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +87 -20
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/hub-do.d.ts +55 -0
- package/dist/do-runner/hub-do.d.ts.map +1 -0
- package/dist/do-runner/hub-do.js +197 -0
- package/dist/do-runner/hub-do.js.map +1 -0
- package/dist/do-runner/index.d.ts +12 -4
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +9 -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/path-safe-id.js +1 -1
- package/dist/do-runner/path-safe-id.js.map +1 -1
- 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 -0
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +29 -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 +24 -4
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +32 -10
- package/dist/host-kit/approval-bridge.js.map +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 +134 -5
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +283 -47
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +20 -1
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +15 -0
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/hub-topology.d.ts +35 -0
- package/dist/host-kit/hub-topology.d.ts.map +1 -0
- package/dist/host-kit/hub-topology.js +32 -0
- package/dist/host-kit/hub-topology.js.map +1 -0
- package/dist/host-kit/index.d.ts +8 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +10 -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/stream-router.d.ts +22 -0
- package/dist/host-kit/stream-router.d.ts.map +1 -0
- package/dist/host-kit/stream-router.js +191 -0
- package/dist/host-kit/stream-router.js.map +1 -0
- package/dist/host-kit/stream-ticket.d.ts +55 -0
- package/dist/host-kit/stream-ticket.d.ts.map +1 -0
- package/dist/host-kit/stream-ticket.js +156 -0
- package/dist/host-kit/stream-ticket.js.map +1 -0
- package/dist/host-kit/tenant-registry.js +1 -1
- package/dist/host-kit/tenant-registry.js.map +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/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- 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 +131 -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 +79 -0
- package/dist/signal-providers/host-do.d.ts.map +1 -0
- package/dist/signal-providers/host-do.js +216 -0
- package/dist/signal-providers/host-do.js.map +1 -0
- package/dist/signal-providers/index.d.ts +7 -0
- package/dist/signal-providers/index.d.ts.map +1 -0
- package/dist/signal-providers/index.js +19 -0
- package/dist/signal-providers/index.js.map +1 -0
- package/dist/signal-providers/provider.d.ts +92 -0
- package/dist/signal-providers/provider.d.ts.map +1 -0
- package/dist/signal-providers/provider.js +87 -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 +88 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -0
- package/dist/signal-providers/webhook-route.js +391 -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 +28 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -0
- package/dist/signals/notifications-d1.js +704 -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
|
@@ -0,0 +1,154 @@
|
|
|
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 INV-1-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. Track C's thread-DO 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 — a second execution path DL-001 forbids, 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 Track C's host-owned idle-start seam: the thread DO
|
|
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 the loop is driven through (DL-001/DL-010). REQUIRED —
|
|
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 INV-1, 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 DO's ONE identity, DL-001) 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 Track C's thread-DO 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 INV-1 before the inherited durable `stream()` runs: without this the
|
|
89
|
+
* optional `options.runId` would let core mint a tenant-less
|
|
90
|
+
* `crypto.randomUUID()` upstream (see {@link FlowsafeDurableAgent.#assertCallerRunId}).
|
|
91
|
+
* A host mints `${tenantId}_${uuid}` and passes it as `options.runId`.
|
|
92
|
+
*/
|
|
93
|
+
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']>>>;
|
|
94
|
+
/**
|
|
95
|
+
* Same INV-1 boundary guard as {@link FlowsafeDurableAgent.stream} — `generate()`
|
|
96
|
+
* re-implements the durable setup and mints its own runId the same way when
|
|
97
|
+
* one is not supplied.
|
|
98
|
+
*/
|
|
99
|
+
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']>>>;
|
|
100
|
+
/**
|
|
101
|
+
* Same INV-1 boundary guard as {@link FlowsafeDurableAgent.stream}. `prepare()`
|
|
102
|
+
* is the third inherited minting entry point: it forwards `options?.runId` into
|
|
103
|
+
* core's `prepareForDurableExecution` (agent/durable/index.js:5980), which mints
|
|
104
|
+
* a tenant-less `crypto.randomUUID()` when it is absent (index.js:589) AND
|
|
105
|
+
* REGISTERS a run under that id (index.js:5984) — so a later
|
|
106
|
+
* `resume(runId)`/`executeWorkflow` sees a bare UUID `PATH_SAFE_ID_PATTERN`
|
|
107
|
+
* already accepts, past every downstream guard. Enforce INV-1 HERE, while
|
|
108
|
+
* "absent" is still visible.
|
|
109
|
+
*/
|
|
110
|
+
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']>>>;
|
|
111
|
+
/**
|
|
112
|
+
* Rehydrate a suspended durable-agent run after isolate eviction, restore its
|
|
113
|
+
* active thread registration, then resume through RunnerRuntime so approval
|
|
114
|
+
* grant derivation and the durable resume ledger remain authoritative.
|
|
115
|
+
* Hosts expose this only from their trusted approval-decision topology.
|
|
116
|
+
*/
|
|
117
|
+
resumeViaRuntime(options: {
|
|
118
|
+
runId: string;
|
|
119
|
+
step?: string | string[];
|
|
120
|
+
resumeData?: unknown;
|
|
121
|
+
memory?: DurableAgentStreamOptions<TOutput>['memory'];
|
|
122
|
+
}): Promise<RunSummary>;
|
|
123
|
+
/**
|
|
124
|
+
* Drive the durable-agentic-loop through RunnerRuntime instead of the base
|
|
125
|
+
* `createRun + run.start` (DL-010). stream()/generate() have already parked the
|
|
126
|
+
* non-serializables (model/tools/messageList) on the in-process run registry
|
|
127
|
+
* keyed by this runId, so the loop the runtime starts resolves them in-isolate
|
|
128
|
+
* while the runtime mints the per-leg grant context. The runId guard here is
|
|
129
|
+
* defense in depth — the public boundary (stream/generate) already enforced
|
|
130
|
+
* INV-1; this catches any future internal caller.
|
|
131
|
+
*/
|
|
132
|
+
protected executeWorkflow(runId: string, workflowInput: DurableAgenticWorkflowInput): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Wrap an Agent as a {@link FlowsafeDurableAgent} and register its loop workflow
|
|
136
|
+
* on the runtime — the same `runtime.register` path init()'s boundCreateWorkflow
|
|
137
|
+
* uses.
|
|
138
|
+
*
|
|
139
|
+
* Registration is IDEMPOTENT by id: every durable agent compiles to the ONE
|
|
140
|
+
* shared 'durable-agentic-loop' workflow (the `agentId` in each run's input
|
|
141
|
+
* routes to the right agent via the per-run registry), so a second
|
|
142
|
+
* createFlowsafeDurableAgent on a shared runtime must not throw 'duplicate
|
|
143
|
+
* workflow id'. Like init()'s createWorkflow, register() also throws once runs
|
|
144
|
+
* have started (the Mastra instance is frozen) — call this at host setup, before
|
|
145
|
+
* any run.
|
|
146
|
+
*
|
|
147
|
+
* Multi-agent caveat: the shared loop bakes in the FIRST registrant's `maxSteps`
|
|
148
|
+
* (it is compiled into the isTaskComplete step) as the DEFAULT — a per-call
|
|
149
|
+
* `stream(msg, { maxSteps })` still overrides it, so this only bites a
|
|
150
|
+
* second-plus agent that relies on its CONSTRUCTOR budget. Agents needing
|
|
151
|
+
* distinct default step budgets take separate runtimes.
|
|
152
|
+
*/
|
|
153
|
+
export declare function createFlowsafeDurableAgent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TOutput = undefined>(options: FlowsafeDurableAgentOptions<TAgentId, TTools, TOutput>): FlowsafeDurableAgent<TAgentId, TTools, TOutput>;
|
|
154
|
+
//# 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,EAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,yBAAyB,CAAC;AAEvE;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB,EAAE,OAAO,MAEzC,CAAC;AAE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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,291 @@
|
|
|
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 INV-1-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. Track C's thread-DO 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 — a second execution path DL-001 forbids, 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 Track C's host-owned idle-start seam: the thread DO
|
|
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 Track C's thread-DO 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
|
+
* INV-1 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 INV-1 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 INV-1 before the inherited durable `stream()` runs: without this the
|
|
149
|
+
* optional `options.runId` would let core mint a tenant-less
|
|
150
|
+
* `crypto.randomUUID()` upstream (see {@link FlowsafeDurableAgent.#assertCallerRunId}).
|
|
151
|
+
* A host mints `${tenantId}_${uuid}` and passes it as `options.runId`.
|
|
152
|
+
*/
|
|
153
|
+
async stream(messages, options) {
|
|
154
|
+
this.#assertCallerRunId(options?.runId);
|
|
155
|
+
const result = await super.stream(messages, options);
|
|
156
|
+
if (!options?.untilIdle) {
|
|
157
|
+
await this.#threadRuntime?.registerRun(this, result.output, (options ?? {}), this.pubsub);
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Same INV-1 boundary guard as {@link FlowsafeDurableAgent.stream} — `generate()`
|
|
163
|
+
* re-implements the durable setup and mints its own runId the same way when
|
|
164
|
+
* one is not supplied.
|
|
165
|
+
*/
|
|
166
|
+
async generate(messages, options) {
|
|
167
|
+
this.#assertCallerRunId(options?.runId);
|
|
168
|
+
return super.generate(messages, options);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Same INV-1 boundary guard as {@link FlowsafeDurableAgent.stream}. `prepare()`
|
|
172
|
+
* is the third inherited minting entry point: it forwards `options?.runId` into
|
|
173
|
+
* core's `prepareForDurableExecution` (agent/durable/index.js:5980), which mints
|
|
174
|
+
* a tenant-less `crypto.randomUUID()` when it is absent (index.js:589) AND
|
|
175
|
+
* REGISTERS a run under that id (index.js:5984) — so a later
|
|
176
|
+
* `resume(runId)`/`executeWorkflow` sees a bare UUID `PATH_SAFE_ID_PATTERN`
|
|
177
|
+
* already accepts, past every downstream guard. Enforce INV-1 HERE, while
|
|
178
|
+
* "absent" is still visible.
|
|
179
|
+
*/
|
|
180
|
+
async prepare(messages, options) {
|
|
181
|
+
this.#assertCallerRunId(options?.runId);
|
|
182
|
+
return super.prepare(messages, options);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Rehydrate a suspended durable-agent run after isolate eviction, restore its
|
|
186
|
+
* active thread registration, then resume through RunnerRuntime so approval
|
|
187
|
+
* grant derivation and the durable resume ledger remain authoritative.
|
|
188
|
+
* Hosts expose this only from their trusted approval-decision topology.
|
|
189
|
+
*/
|
|
190
|
+
async resumeViaRuntime(options) {
|
|
191
|
+
this.#assertCallerRunId(options.runId);
|
|
192
|
+
await this.prepare([], {
|
|
193
|
+
runId: options.runId,
|
|
194
|
+
...(options.memory !== undefined ? { memory: options.memory } : {}),
|
|
195
|
+
});
|
|
196
|
+
const observed = await this.observe(options.runId);
|
|
197
|
+
const emitTerminalError = async (error) => {
|
|
198
|
+
try {
|
|
199
|
+
await this.emitError(options.runId, error instanceof Error ? error : new Error(String(error)));
|
|
200
|
+
}
|
|
201
|
+
catch (publicationError) {
|
|
202
|
+
console.error(JSON.stringify({
|
|
203
|
+
type: 'durable-agent-resume-error-publication-failed',
|
|
204
|
+
runId: options.runId,
|
|
205
|
+
error: publicationError instanceof Error
|
|
206
|
+
? publicationError.message
|
|
207
|
+
: String(publicationError),
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
try {
|
|
212
|
+
await this.#threadRuntime?.registerRun(this, observed.output, {
|
|
213
|
+
runId: options.runId,
|
|
214
|
+
...(options.memory !== undefined ? { memory: options.memory } : {}),
|
|
215
|
+
}, this.pubsub);
|
|
216
|
+
const summary = await this.#runtime.resume(this.getWorkflow().id, options.runId, {
|
|
217
|
+
...(options.step !== undefined ? { step: options.step } : {}),
|
|
218
|
+
...(options.resumeData !== undefined
|
|
219
|
+
? { resumeData: options.resumeData }
|
|
220
|
+
: {}),
|
|
221
|
+
});
|
|
222
|
+
if (summary.status === 'failed') {
|
|
223
|
+
await emitTerminalError(new Error(summary.error ?? 'Durable agent workflow resume failed'));
|
|
224
|
+
}
|
|
225
|
+
return summary;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
await emitTerminalError(error);
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Drive the durable-agentic-loop through RunnerRuntime instead of the base
|
|
234
|
+
* `createRun + run.start` (DL-010). stream()/generate() have already parked the
|
|
235
|
+
* non-serializables (model/tools/messageList) on the in-process run registry
|
|
236
|
+
* keyed by this runId, so the loop the runtime starts resolves them in-isolate
|
|
237
|
+
* while the runtime mints the per-leg grant context. The runId guard here is
|
|
238
|
+
* defense in depth — the public boundary (stream/generate) already enforced
|
|
239
|
+
* INV-1; this catches any future internal caller.
|
|
240
|
+
*/
|
|
241
|
+
async executeWorkflow(runId, workflowInput) {
|
|
242
|
+
this.#assertCallerRunId(runId);
|
|
243
|
+
// getWorkflow() is memoized and its id is the shared loop id the factory
|
|
244
|
+
// registered; driving that exact id keeps the started run and the
|
|
245
|
+
// registered workflow in lockstep.
|
|
246
|
+
const summary = await this.#runtime.start(this.getWorkflow().id, {
|
|
247
|
+
runId,
|
|
248
|
+
inputData: workflowInput,
|
|
249
|
+
});
|
|
250
|
+
// Mirror the base: a FAILED run emits an error onto the agent's stream so
|
|
251
|
+
// observe()/onError see it. A SUSPENDED run is the approval-gate path — it
|
|
252
|
+
// returns normally and the host bridges the suspension to the approval
|
|
253
|
+
// queue. emitError publishes on this.pubsub, which the constructor defaults
|
|
254
|
+
// to the runtime's identity so the event reaches the run's observers.
|
|
255
|
+
if (summary.status === 'failed') {
|
|
256
|
+
await this.emitError(runId, new Error(summary.error ?? 'Durable agent workflow execution failed'));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Wrap an Agent as a {@link FlowsafeDurableAgent} and register its loop workflow
|
|
262
|
+
* on the runtime — the same `runtime.register` path init()'s boundCreateWorkflow
|
|
263
|
+
* uses.
|
|
264
|
+
*
|
|
265
|
+
* Registration is IDEMPOTENT by id: every durable agent compiles to the ONE
|
|
266
|
+
* shared 'durable-agentic-loop' workflow (the `agentId` in each run's input
|
|
267
|
+
* routes to the right agent via the per-run registry), so a second
|
|
268
|
+
* createFlowsafeDurableAgent on a shared runtime must not throw 'duplicate
|
|
269
|
+
* workflow id'. Like init()'s createWorkflow, register() also throws once runs
|
|
270
|
+
* have started (the Mastra instance is frozen) — call this at host setup, before
|
|
271
|
+
* any run.
|
|
272
|
+
*
|
|
273
|
+
* Multi-agent caveat: the shared loop bakes in the FIRST registrant's `maxSteps`
|
|
274
|
+
* (it is compiled into the isTaskComplete step) as the DEFAULT — a per-call
|
|
275
|
+
* `stream(msg, { maxSteps })` still overrides it, so this only bites a
|
|
276
|
+
* second-plus agent that relies on its CONSTRUCTOR budget. Agents needing
|
|
277
|
+
* distinct default step budgets take separate runtimes.
|
|
278
|
+
*/
|
|
279
|
+
export function createFlowsafeDurableAgent(options) {
|
|
280
|
+
const durableAgent = new FlowsafeDurableAgent(options);
|
|
281
|
+
const workflow = durableAgent.getWorkflow();
|
|
282
|
+
if (!options.runtime.workflowIds().includes(workflow.id)) {
|
|
283
|
+
// getWorkflow()'s concrete engine generics are not single-cast-assignable to
|
|
284
|
+
// AnyWorkflow, so the double cast through `unknown` is required (init.ts gets
|
|
285
|
+
// away with a single cast because coreCreateWorkflow's return already lines
|
|
286
|
+
// up). The runtime only ever reads id / getWorkflowRunById / createRun off it.
|
|
287
|
+
options.runtime.register(workflow);
|
|
288
|
+
}
|
|
289
|
+
return durableAgent;
|
|
290
|
+
}
|
|
291
|
+
//# 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+D;AAC/D,mDAAmD;AACnD,yEAAyE;AACzE,6EAA6E;AAC7E,gEAAgE;AAChE,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,2BAA2B;AAC3B,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,4DAA4D;AAC5D,gEAAgE;AAChE,+EAA+E;AAC/E,0EAA0E;AAC1E,gFAAgF;AAChF,4EAA4E;AAC5E,mFAAmF;AACnF,8EAA8E;AAC9E,0EAA0E;AAC1E,kEAAkE;AAClE,gFAAgF;AAChF,sEAAsE;AACtE,gFAAgF;AAChF,yDAAyD;AACzD,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,gFAAgF;AAChF,8EAA8E;AAC9E,4EAA4E;AAG5E,OAAO,EACL,YAAY,GAIb,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAGrB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,sBAAsB,CAAC;AAEvE;;;;;;;;;;;;;;;;;GAiBG;AACH,M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AAW,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"}
|
|
@@ -93,4 +93,33 @@ export interface ApprovalNotificationEvent {
|
|
|
93
93
|
* or redact the record itself — title/ids/priority/SLA usually suffice.
|
|
94
94
|
*/
|
|
95
95
|
export type ApprovalNotificationSink = (event: ApprovalNotificationEvent) => void | Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* A live-stream moment worth fanning out to every open dashboard of the
|
|
98
|
+
* tenant: a request was created, claimed, decided, delegated, superseded, or
|
|
99
|
+
* escalated. Distinct from ApprovalNotificationEvent (deliberately only
|
|
100
|
+
* 'created' | 'escalated', the reviewer-facing transport): a live queue also
|
|
101
|
+
* needs claimed/decided/delegated/superseded so a dashboard can upsert-by-id
|
|
102
|
+
* without a refetch. `record` is the POST-transition record.
|
|
103
|
+
*/
|
|
104
|
+
export interface ApprovalStreamEvent {
|
|
105
|
+
type: 'created' | 'claimed' | 'decided' | 'delegated' | 'superseded' | 'escalated';
|
|
106
|
+
record: ApprovalRecord;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The live fan-out seam (a per-tenant hub Durable Object relays each event to
|
|
110
|
+
* that tenant's open dashboard sockets — flowsafe ships NO transport).
|
|
111
|
+
* Fire-and-forget with the same availability-over-delivery policy as
|
|
112
|
+
* ApprovalNotificationSink: a sink that throws or rejects never fails the
|
|
113
|
+
* approval mutation that fired it — the failure is recorded to the AUDIT sink
|
|
114
|
+
* as `approval.stream`/'error' and the mutation proceeds. Workers hosts whose
|
|
115
|
+
* transport must outlive the response wrap it in ctx.waitUntil themselves; the
|
|
116
|
+
* service never awaits the sink.
|
|
117
|
+
*
|
|
118
|
+
* TRUST: unlike ApprovalNotificationSink — which addresses lower-trust channels
|
|
119
|
+
* (email, chat) and so a transport must project or redact the record — this is
|
|
120
|
+
* a SAME-TRUST intra-tenant feed: every subscriber is already an authenticated
|
|
121
|
+
* reviewer of THIS tenant, so it carries the FULL ApprovalRecord unredacted. It
|
|
122
|
+
* is an ADDRESSING feed, never a capability — no grant ever travels on it.
|
|
123
|
+
*/
|
|
124
|
+
export type ApprovalStreamSink = (event: ApprovalStreamEvent) => void | Promise<void>;
|
|
96
125
|
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/approval-api/contract.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,sEAAsE;AACtE,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,SAAS,GACT,UAAU,GACV,UAAU,GACV,QAAQ,CAAC;AAEb,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAMjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAA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c,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,EAAE,mBAAmB,KACvB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d1-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/d1-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"d1-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/d1-store.ts"],"names":[],"mappings":"AAqBA,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,EAEnB,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;AAiWD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH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