@proofoftech/flowsafe 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +327 -0
- package/README.md +295 -251
- package/dist/agent-runner/approval-shapes.d.ts +36 -0
- package/dist/agent-runner/approval-shapes.d.ts.map +1 -0
- package/dist/agent-runner/approval-shapes.js +101 -0
- package/dist/agent-runner/approval-shapes.js.map +1 -0
- package/dist/agent-runner/durable-agent-runner.d.ts +158 -0
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
- package/dist/agent-runner/durable-agent-runner.js +295 -0
- package/dist/agent-runner/durable-agent-runner.js.map +1 -0
- package/dist/agent-runner/index.d.ts +3 -0
- package/dist/agent-runner/index.d.ts.map +1 -0
- package/dist/agent-runner/index.js +10 -0
- package/dist/agent-runner/index.js.map +1 -0
- package/dist/approval-api/contract.d.ts +2 -2
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +87 -19
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.js +1 -1
- package/dist/approval-api/index.d.ts +1 -1
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/router.d.ts +2 -2
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +1 -0
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +10 -11
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +22 -9
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +27 -22
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +25 -9
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts +6 -6
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +15 -0
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/types.d.ts +13 -4
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +2 -1
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +2 -2
- package/dist/approval-ui/FilterBar.d.ts +3 -3
- package/dist/approval-ui/FilterBar.js +3 -3
- package/dist/approval-ui/client.d.ts +1 -1
- package/dist/approval-ui/components.d.ts +1 -1
- package/dist/approval-ui/stream.d.ts +3 -3
- package/dist/approval-ui/stream.js +2 -2
- package/dist/approval-ui/use-approval-dashboard.d.ts +9 -12
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +6 -9
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +1 -1
- package/dist/approval-ui/use-web-socket-transport.js +1 -1
- package/dist/background-tasks/d1-storage.d.ts +66 -0
- package/dist/background-tasks/d1-storage.d.ts.map +1 -0
- package/dist/background-tasks/d1-storage.js +196 -0
- package/dist/background-tasks/d1-storage.js.map +1 -0
- package/dist/background-tasks/host.d.ts +82 -0
- package/dist/background-tasks/host.d.ts.map +1 -0
- package/dist/background-tasks/host.js +275 -0
- package/dist/background-tasks/host.js.map +1 -0
- package/dist/background-tasks/index.d.ts +7 -0
- package/dist/background-tasks/index.d.ts.map +1 -0
- package/dist/background-tasks/index.js +10 -0
- package/dist/background-tasks/index.js.map +1 -0
- package/dist/background-tasks/routes.d.ts +15 -0
- package/dist/background-tasks/routes.d.ts.map +1 -0
- package/dist/background-tasks/routes.js +144 -0
- package/dist/background-tasks/routes.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +1 -1
- package/dist/do-runner/breakwater-keys.js +1 -1
- package/dist/do-runner/cf-types.d.ts +1 -1
- package/dist/do-runner/d1-storage.d.ts +347 -5
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +571 -17
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +29 -0
- package/dist/do-runner/do-error-response.d.ts.map +1 -0
- package/dist/do-runner/do-error-response.js +73 -0
- package/dist/do-runner/do-error-response.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +3 -3
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +7 -21
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/hub-do.d.ts +2 -2
- package/dist/do-runner/index.d.ts +9 -3
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +8 -2
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +20 -0
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +12 -1
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/memory-id.d.ts +3 -3
- package/dist/do-runner/memory-id.js +3 -3
- package/dist/do-runner/path-safe-id.d.ts +6 -6
- package/dist/do-runner/path-safe-id.js +6 -6
- package/dist/do-runner/pubsub.d.ts +18 -0
- package/dist/do-runner/pubsub.d.ts.map +1 -0
- package/dist/do-runner/pubsub.js +42 -0
- package/dist/do-runner/pubsub.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +24 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +28 -2
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +74 -0
- package/dist/do-runner/thread-do.d.ts.map +1 -0
- package/dist/do-runner/thread-do.js +156 -0
- package/dist/do-runner/thread-do.js.map +1 -0
- package/dist/do-runner/thread-header.d.ts +16 -0
- package/dist/do-runner/thread-header.d.ts.map +1 -0
- package/dist/do-runner/thread-header.js +24 -0
- package/dist/do-runner/thread-header.js.map +1 -0
- package/dist/goals/index.d.ts +2 -0
- package/dist/goals/index.d.ts.map +1 -0
- package/dist/goals/index.js +7 -0
- package/dist/goals/index.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +87 -0
- package/dist/goals/objective-routes.d.ts.map +1 -0
- package/dist/goals/objective-routes.js +375 -0
- package/dist/goals/objective-routes.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +28 -8
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +37 -15
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/bearer-auth.d.ts +1 -1
- package/dist/host-kit/bearer-auth.js +1 -1
- package/dist/host-kit/env-vars.d.ts +20 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +30 -0
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +113 -6
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +253 -63
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +13 -13
- package/dist/host-kit/host-approval-service.js +10 -10
- package/dist/host-kit/index.d.ts +3 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +7 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/memory-boundary.d.ts +64 -0
- package/dist/host-kit/memory-boundary.d.ts.map +1 -0
- package/dist/host-kit/memory-boundary.js +109 -0
- package/dist/host-kit/memory-boundary.js.map +1 -0
- package/dist/host-kit/route-path.d.ts +17 -0
- package/dist/host-kit/route-path.d.ts.map +1 -0
- package/dist/host-kit/route-path.js +35 -0
- package/dist/host-kit/route-path.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +10 -11
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/stream-router.d.ts +1 -1
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.d.ts +3 -3
- package/dist/host-kit/stream-ticket.d.ts.map +1 -1
- package/dist/host-kit/stream-ticket.js +1 -1
- package/dist/host-kit/tenant-registry.d.ts +1 -1
- package/dist/host-kit/tenant-registry.js +1 -1
- package/dist/host-kit/thread-topology.d.ts +44 -0
- package/dist/host-kit/thread-topology.d.ts.map +1 -0
- package/dist/host-kit/thread-topology.js +76 -0
- package/dist/host-kit/thread-topology.js.map +1 -0
- package/dist/host-kit/verifier.d.ts +1 -1
- package/dist/host-kit/verifier.js +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal-error-response.d.ts +3 -0
- package/dist/internal-error-response.d.ts.map +1 -0
- package/dist/internal-error-response.js +20 -0
- package/dist/internal-error-response.js.map +1 -0
- package/dist/numeric-config.d.ts +4 -0
- package/dist/numeric-config.d.ts.map +1 -0
- package/dist/numeric-config.js +23 -0
- package/dist/numeric-config.js.map +1 -0
- package/dist/schedules/index.d.ts +5 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +13 -0
- package/dist/schedules/index.js.map +1 -0
- package/dist/schedules/router.d.ts +66 -0
- package/dist/schedules/router.d.ts.map +1 -0
- package/dist/schedules/router.js +827 -0
- package/dist/schedules/router.js.map +1 -0
- package/dist/schedules/schedules-d1.d.ts +30 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -0
- package/dist/schedules/schedules-d1.js +374 -0
- package/dist/schedules/schedules-d1.js.map +1 -0
- package/dist/schedules/storage.d.ts +11 -0
- package/dist/schedules/storage.d.ts.map +1 -0
- package/dist/schedules/storage.js +34 -0
- package/dist/schedules/storage.js.map +1 -0
- package/dist/schedules/tick.d.ts +132 -0
- package/dist/schedules/tick.d.ts.map +1 -0
- package/dist/schedules/tick.js +598 -0
- package/dist/schedules/tick.js.map +1 -0
- package/dist/signal-providers/delivery.d.ts +24 -0
- package/dist/signal-providers/delivery.d.ts.map +1 -0
- package/dist/signal-providers/delivery.js +62 -0
- package/dist/signal-providers/delivery.js.map +1 -0
- package/dist/signal-providers/github-provider.d.ts +33 -0
- package/dist/signal-providers/github-provider.d.ts.map +1 -0
- package/dist/signal-providers/github-provider.js +116 -0
- package/dist/signal-providers/github-provider.js.map +1 -0
- package/dist/signal-providers/host-do.d.ts +81 -0
- package/dist/signal-providers/host-do.d.ts.map +1 -0
- package/dist/signal-providers/host-do.js +229 -0
- package/dist/signal-providers/host-do.js.map +1 -0
- package/dist/signal-providers/host-topology.d.ts +27 -0
- package/dist/signal-providers/host-topology.d.ts.map +1 -0
- package/dist/signal-providers/host-topology.js +36 -0
- package/dist/signal-providers/host-topology.js.map +1 -0
- package/dist/signal-providers/index.d.ts +8 -0
- package/dist/signal-providers/index.d.ts.map +1 -0
- package/dist/signal-providers/index.js +21 -0
- package/dist/signal-providers/index.js.map +1 -0
- package/dist/signal-providers/provider.d.ts +93 -0
- package/dist/signal-providers/provider.d.ts.map +1 -0
- package/dist/signal-providers/provider.js +89 -0
- package/dist/signal-providers/provider.js.map +1 -0
- package/dist/signal-providers/subscription-d1.d.ts +88 -0
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -0
- package/dist/signal-providers/subscription-d1.js +259 -0
- package/dist/signal-providers/subscription-d1.js.map +1 -0
- package/dist/signal-providers/webhook-route.d.ts +96 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -0
- package/dist/signal-providers/webhook-route.js +444 -0
- package/dist/signal-providers/webhook-route.js.map +1 -0
- package/dist/signals/client.d.ts +72 -0
- package/dist/signals/client.d.ts.map +1 -0
- package/dist/signals/client.js +87 -0
- package/dist/signals/client.js.map +1 -0
- package/dist/signals/d1-shared.d.ts +43 -0
- package/dist/signals/d1-shared.d.ts.map +1 -0
- package/dist/signals/d1-shared.js +46 -0
- package/dist/signals/d1-shared.js.map +1 -0
- package/dist/signals/index.d.ts +9 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +15 -0
- package/dist/signals/index.js.map +1 -0
- package/dist/signals/notification-dispatch.d.ts +52 -0
- package/dist/signals/notification-dispatch.d.ts.map +1 -0
- package/dist/signals/notification-dispatch.js +198 -0
- package/dist/signals/notification-dispatch.js.map +1 -0
- package/dist/signals/notifications-d1.d.ts +27 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -0
- package/dist/signals/notifications-d1.js +703 -0
- package/dist/signals/notifications-d1.js.map +1 -0
- package/dist/signals/router.d.ts +73 -0
- package/dist/signals/router.d.ts.map +1 -0
- package/dist/signals/router.js +240 -0
- package/dist/signals/router.js.map +1 -0
- package/dist/signals/storage.d.ts +11 -0
- package/dist/signals/storage.d.ts.map +1 -0
- package/dist/signals/storage.js +27 -0
- package/dist/signals/storage.js.map +1 -0
- package/dist/signals/thread-do-routes.d.ts +82 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -0
- package/dist/signals/thread-do-routes.js +660 -0
- package/dist/signals/thread-do-routes.js.map +1 -0
- package/dist/signals/thread-state-d1.d.ts +22 -0
- package/dist/signals/thread-state-d1.d.ts.map +1 -0
- package/dist/signals/thread-state-d1.js +83 -0
- package/dist/signals/thread-state-d1.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { GoalObjectiveRecord } from '@mastra/core/storage';
|
|
2
|
+
import { type ApprovalRole, type TenantResolver } from '../approval-api/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* requestContext key @mastra/core surfaces the current objective under WITHIN a
|
|
5
|
+
* turn. MIRRORED by value: 'mastra:goal' lives in core's
|
|
6
|
+
* dist/agent/goal/objective.js, which the package `exports` map does NOT expose
|
|
7
|
+
* (there is no `@mastra/core/agent/goal` subpath, and neither `@mastra/core/tools`
|
|
8
|
+
* nor `@mastra/core/agent` re-exports it), so importing it would mean a forbidden
|
|
9
|
+
* deep `dist/` import. Signals take the same mirror-not-deep-import stance
|
|
10
|
+
* for core's XML-name validation. This surface never writes this key; it is
|
|
11
|
+
* reserved here only so the no-collision test pins that it does not collide with
|
|
12
|
+
* the runtime's #requestContextFor base keys. The mirror is defensive-only
|
|
13
|
+
* (nothing here ever writes the key), and the test suite pins it BOTH ways: the
|
|
14
|
+
* no-collision pin against the runtime base keys, and a dist drift-pin reading
|
|
15
|
+
* core's objective.d.ts declaration — so a core bump that changes the value
|
|
16
|
+
* fails a test loudly instead of silently diverging.
|
|
17
|
+
*/
|
|
18
|
+
export declare const GOAL_REQUEST_CONTEXT_KEY = "mastra:goal";
|
|
19
|
+
/**
|
|
20
|
+
* The thread-scoped state store the goal record lives in — structurally core's
|
|
21
|
+
* ResolvedGoalStore (getState/setState/deleteState over a (threadId, type)
|
|
22
|
+
* pair), which core does not export through a mapped subpath, so it is mirrored.
|
|
23
|
+
* A host injects `createSignalStorageDomains(binding).threadState` (a
|
|
24
|
+
* D1ThreadStateStorage) — the SAME domain the durable goal step resolves through
|
|
25
|
+
* resolveGoalStore, so a record this surface writes is what the loop reads.
|
|
26
|
+
*/
|
|
27
|
+
export interface ObjectiveStore {
|
|
28
|
+
getState<T = unknown>(args: {
|
|
29
|
+
threadId: string;
|
|
30
|
+
type: string;
|
|
31
|
+
}): Promise<T | undefined>;
|
|
32
|
+
setState(args: {
|
|
33
|
+
threadId: string;
|
|
34
|
+
type: string;
|
|
35
|
+
value: GoalObjectiveRecord;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
deleteState(args: {
|
|
38
|
+
threadId: string;
|
|
39
|
+
type: string;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/** The objective operations, one per HTTP verb on `/:threadId/goal`. */
|
|
43
|
+
export type ObjectiveOperation = 'set' | 'get' | 'update' | 'clear';
|
|
44
|
+
/** The structured audit event a mutation (and a denied read) emits. */
|
|
45
|
+
export interface ObjectiveAuditEvent {
|
|
46
|
+
type: 'goal.objective';
|
|
47
|
+
tenantId: string;
|
|
48
|
+
actorId: string;
|
|
49
|
+
threadId: string;
|
|
50
|
+
operation: ObjectiveOperation;
|
|
51
|
+
outcome: 'accepted' | 'rejected';
|
|
52
|
+
/** Present for rejected outcomes — WHY the write was refused. */
|
|
53
|
+
reason?: string;
|
|
54
|
+
timestamp: string;
|
|
55
|
+
}
|
|
56
|
+
/** The audit seam — a host bridges this to its AuditLogger / SIEM sink. */
|
|
57
|
+
export type ObjectiveAuditSink = (event: ObjectiveAuditEvent) => void | Promise<void>;
|
|
58
|
+
export interface ObjectiveRouterOptions {
|
|
59
|
+
/** Authenticate, validate the tenant ID, and bind it; undefined means 401. */
|
|
60
|
+
resolve: TenantResolver;
|
|
61
|
+
/** The thread-state domain in which the goal record lives. */
|
|
62
|
+
store: ObjectiveStore;
|
|
63
|
+
/**
|
|
64
|
+
* Who may SET/UPDATE/CLEAR an objective. Default RUN_START_ROLES
|
|
65
|
+
* (operator/admin) — reviewers/viewers cannot author standing instructions.
|
|
66
|
+
* Reads (GET) are not role-gated beyond ownership.
|
|
67
|
+
*/
|
|
68
|
+
roles?: readonly ApprovalRole[];
|
|
69
|
+
/** Every mutation (and denied read) is audited through this. Absent ⇒ no audit. */
|
|
70
|
+
audit?: ObjectiveAuditSink;
|
|
71
|
+
/**
|
|
72
|
+
* The ceiling on a per-objective maxRuns. A request above it is
|
|
73
|
+
* REJECTED; the stored record never carries a higher value. Default the core
|
|
74
|
+
* DEFAULT_GOAL_MAX_RUNS (50). Must be a positive safe integer.
|
|
75
|
+
*/
|
|
76
|
+
maxRunsCap?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Max raw request-body size in bytes. Must be a nonnegative safe integer;
|
|
79
|
+
* zero denies every non-empty body. Default 16384.
|
|
80
|
+
*/
|
|
81
|
+
maxContentBytes?: number;
|
|
82
|
+
/** Route prefix. Default '/api/threads' (goals mount at `/:threadId/goal`). */
|
|
83
|
+
basePath?: string;
|
|
84
|
+
}
|
|
85
|
+
export type ObjectiveRouter = (request: Request) => Promise<Response | null>;
|
|
86
|
+
export declare function createObjectiveRouter(options: ObjectiveRouterOptions): ObjectiveRouter;
|
|
87
|
+
//# sourceMappingURL=objective-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objective-routes.d.ts","sourceRoot":"","sources":["../../src/goals/objective-routes.ts"],"names":[],"mappings":"AA6DA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAQhE,OAAO,EACL,KAAK,YAAY,EAIjB,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAalC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,gBAAgB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE;QAC1B,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,mBAAmB,CAAC;KAC5B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,WAAW,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,wEAAwE;AACxE,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AASpE,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,OAAO,EAAE,UAAU,GAAG,UAAU,CAAC;IACjC,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,EAAE,mBAAmB,KACvB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,sBAAsB;IACrC,8EAA8E;IAC9E,OAAO,EAAE,cAAc,CAAC;IACxB,8DAA8D;IAC9D,KAAK,EAAE,cAAc,CAAC;IACtB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAChC,mFAAmF;IACnF,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAqM7E,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CAyKjB"}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Track F (M-005), CI-M-005-001 — the goal objective HTTP surface (DL-018).
|
|
3
|
+
//
|
|
4
|
+
// A goal is a durable, thread-scoped OBJECTIVE record (@mastra/core's
|
|
5
|
+
// GoalObjectiveRecord, stored in the mastra_thread_state domain under type
|
|
6
|
+
// 'goal') that a Mastra agent's in-loop judge reads to decide whether to keep
|
|
7
|
+
// working toward it. In the DURABLE path the goal step rebuilds RequestContext
|
|
8
|
+
// from initData and reads the objective from D1 via resolveGoalStore ->
|
|
9
|
+
// readObjective, NOT any in-process registry (DL-018). Verified against the
|
|
10
|
+
// on-disk @mastra/core 1.50.0 dist: resolveGoalStore(mastra) is
|
|
11
|
+
// `mastra.getStorage().getStore('threadState')` and readObjective is
|
|
12
|
+
// `getState({ threadId, type: 'goal' })`. So this surface writes the D1 domain
|
|
13
|
+
// DIRECTLY at the Worker level — no thread-DO affinity is needed for the record
|
|
14
|
+
// write, and a record written here is what the loop later reads: the write goes
|
|
15
|
+
// through core's OWN writeObjective/readObjective/clearObjective over the SAME
|
|
16
|
+
// (threadId, 'goal') key, so the stored shape can never drift from the reader's.
|
|
17
|
+
//
|
|
18
|
+
// An objective is a STANDING INSTRUCTION injected into every future model turn,
|
|
19
|
+
// so the write path is an ingestion trust boundary (P6-lite, DL-006) — the same
|
|
20
|
+
// gate order createSignalRouter (Track C) enforces:
|
|
21
|
+
//
|
|
22
|
+
// 1. resolve (authenticate -> INV-3 -> bind) -> 401 / 403
|
|
23
|
+
// 2. coarse role (RUN_START_ROLES) on MUTATIONS -> 403 (reads stay coarse)
|
|
24
|
+
// 3. thread-prefix ownership (requireOwnedMemoryId) -> 404 (no existence oracle)
|
|
25
|
+
// 4. size cap on the raw body, THEN JSON parse -> 413 / 400
|
|
26
|
+
// 5. body names NO client memory id (assertNoClientMemoryIds) -> 400
|
|
27
|
+
// 6. field allowlist (objective/maxRuns/judge/prompt; status on update) -> 400
|
|
28
|
+
// 7. maxRuns host cap (DL-007) -> 400
|
|
29
|
+
// 8. audit (goal.objective) + persist
|
|
30
|
+
//
|
|
31
|
+
// Every MUTATION (set/update/clear) is audited on ACCEPT and on EVERY post-auth
|
|
32
|
+
// denial (role 403, foreign 404, size/body/field/cap 400) — the Track C lesson.
|
|
33
|
+
// A GET is audited only on a post-auth denial (a cross-tenant read probe); a
|
|
34
|
+
// benign successful read is not a standing-instruction write and is not logged.
|
|
35
|
+
// Pre-auth failures (401 / a resolver throw -> 403) are NOT audited: an
|
|
36
|
+
// unauthenticated flood must never be able to write the log.
|
|
37
|
+
//
|
|
38
|
+
// maxRuns (DL-007): a requested maxRuns above the host cap is REJECTED (400),
|
|
39
|
+
// not silently clamped. A caller that asked for 200 evaluations and got 50 would
|
|
40
|
+
// see mysterious early-stopping — exactly the "your value was quietly replaced"
|
|
41
|
+
// footgun the run router 400s a client runId to avoid — so the boundary fails
|
|
42
|
+
// loud instead. The stored record therefore never carries maxRuns above the cap
|
|
43
|
+
// (default the core DEFAULT_GOAL_MAX_RUNS, 50). Track F itself starts NO runs:
|
|
44
|
+
// the per-tenant run-start budget stays enforced at the existing run-start seam;
|
|
45
|
+
// bounding maxRuns only bounds how many of those already-budgeted runs one goal
|
|
46
|
+
// can drive.
|
|
47
|
+
//
|
|
48
|
+
// P8 (goals never mint capability): no route reads or writes requestContext and
|
|
49
|
+
// none names a connector/grant/step. writeObjective is called WITHOUT a
|
|
50
|
+
// requestContext, so the within-turn GOAL_REQUEST_CONTEXT_KEY surface is never
|
|
51
|
+
// touched here — the objective payload is content only.
|
|
52
|
+
//
|
|
53
|
+
// Write serialization: update is a read-modify-write and clear an unconditional
|
|
54
|
+
// delete, both at the Worker with NO per-thread serialization — deliberately
|
|
55
|
+
// weaker than signals (whose sends ride the thread-DO lease), because DL-018
|
|
56
|
+
// writes D1 directly. Core's own
|
|
57
|
+
// Agent.updateObjectiveOptions has the identical non-atomic read-then-write, so
|
|
58
|
+
// concurrent mutations are last-write-wins WITHIN the tenant; the maxRuns cap is
|
|
59
|
+
// enforced on every write, so no interleaving can persist an over-cap value or
|
|
60
|
+
// cross a tenancy/capability line.
|
|
61
|
+
import { clearObjective, DEFAULT_GOAL_MAX_RUNS, readObjective, writeObjective, } from '@mastra/core/tools';
|
|
62
|
+
import { RUN_START_ROLES, TenantResolutionError, } from '../approval-api/index.js';
|
|
63
|
+
import { assertNoClientMemoryIds, RunRouteError, requireOwnedMemoryId, } from '../host-kit/index.js';
|
|
64
|
+
import { safeDecodeSegment } from '../host-kit/route-path.js';
|
|
65
|
+
import { internalErrorResponse } from '../internal-error-response.js';
|
|
66
|
+
import { nonnegativeSafeInteger, positiveSafeInteger, } from '../numeric-config.js';
|
|
67
|
+
/**
|
|
68
|
+
* requestContext key @mastra/core surfaces the current objective under WITHIN a
|
|
69
|
+
* turn. MIRRORED by value: 'mastra:goal' lives in core's
|
|
70
|
+
* dist/agent/goal/objective.js, which the package `exports` map does NOT expose
|
|
71
|
+
* (there is no `@mastra/core/agent/goal` subpath, and neither `@mastra/core/tools`
|
|
72
|
+
* nor `@mastra/core/agent` re-exports it), so importing it would mean a forbidden
|
|
73
|
+
* deep `dist/` import. Signals take the same mirror-not-deep-import stance
|
|
74
|
+
* for core's XML-name validation. This surface never writes this key; it is
|
|
75
|
+
* reserved here only so the no-collision test pins that it does not collide with
|
|
76
|
+
* the runtime's #requestContextFor base keys. The mirror is defensive-only
|
|
77
|
+
* (nothing here ever writes the key), and the test suite pins it BOTH ways: the
|
|
78
|
+
* no-collision pin against the runtime base keys, and a dist drift-pin reading
|
|
79
|
+
* core's objective.d.ts declaration — so a core bump that changes the value
|
|
80
|
+
* fails a test loudly instead of silently diverging.
|
|
81
|
+
*/
|
|
82
|
+
export const GOAL_REQUEST_CONTEXT_KEY = 'mastra:goal';
|
|
83
|
+
const OPERATION_BY_METHOD = {
|
|
84
|
+
PUT: 'set',
|
|
85
|
+
GET: 'get',
|
|
86
|
+
PATCH: 'update',
|
|
87
|
+
DELETE: 'clear',
|
|
88
|
+
};
|
|
89
|
+
/** The goal record statuses core's judge and this surface both use. */
|
|
90
|
+
const GOAL_STATUSES = ['active', 'paused', 'done'];
|
|
91
|
+
// Fields a client may name in a SET body (create/replace the objective). status
|
|
92
|
+
// is always 'active' and runsUsed always 0 on a fresh set, so both are omitted —
|
|
93
|
+
// naming them (or any other key) is a 400.
|
|
94
|
+
const SET_FIELDS = new Set(['objective', 'maxRuns', 'judgeModelId', 'prompt']);
|
|
95
|
+
// Fields a client may name in an UPDATE body — OPTIONS only, never the prose
|
|
96
|
+
// (mirrors core's Agent.updateObjectiveOptions: judge/maxRuns/prompt/status). To
|
|
97
|
+
// change the objective text, replace the record with a fresh set.
|
|
98
|
+
const UPDATE_FIELDS = new Set(['maxRuns', 'judgeModelId', 'prompt', 'status']);
|
|
99
|
+
function json(payload, status = 200) {
|
|
100
|
+
return new Response(JSON.stringify(payload), {
|
|
101
|
+
status,
|
|
102
|
+
headers: {
|
|
103
|
+
'content-type': 'application/json',
|
|
104
|
+
'cache-control': 'no-store',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function rejectField(reason, message) {
|
|
109
|
+
return { ok: false, error: { reason, message, status: 400 } };
|
|
110
|
+
}
|
|
111
|
+
function validateMaxRuns(value, cap) {
|
|
112
|
+
if (value === undefined)
|
|
113
|
+
return { ok: true, value: undefined };
|
|
114
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
|
|
115
|
+
return rejectField('maxruns-invalid', 'maxRuns must be a positive integer');
|
|
116
|
+
}
|
|
117
|
+
if (value > cap) {
|
|
118
|
+
return rejectField('maxruns-over-cap', `maxRuns ${value} exceeds the host cap of ${cap}`);
|
|
119
|
+
}
|
|
120
|
+
return { ok: true, value };
|
|
121
|
+
}
|
|
122
|
+
// rejectBlank: an identifier field (judgeModelId) with a whitespace-only value
|
|
123
|
+
// would persist and only fail later at model resolution, so it is refused at
|
|
124
|
+
// the boundary; prompt stays untrimmed — leading/trailing whitespace can be
|
|
125
|
+
// legitimate prompt content.
|
|
126
|
+
function validateOptionalString(value, field, rejectBlank = false) {
|
|
127
|
+
if (value === undefined)
|
|
128
|
+
return { ok: true, value: undefined };
|
|
129
|
+
if (typeof value !== 'string' ||
|
|
130
|
+
value.length === 0 ||
|
|
131
|
+
(rejectBlank && value.trim().length === 0)) {
|
|
132
|
+
return rejectField(`${field}-invalid`, `${field} must be a non-empty string`);
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, value };
|
|
135
|
+
}
|
|
136
|
+
/** Reject any body key outside the operation's allowlist (unknown or reserved). */
|
|
137
|
+
function firstDisallowedField(body, allowed, verb) {
|
|
138
|
+
const offending = Object.keys(body).find((key) => !allowed.has(key));
|
|
139
|
+
return offending === undefined
|
|
140
|
+
? undefined
|
|
141
|
+
: {
|
|
142
|
+
reason: `field-not-allowed:${offending}`,
|
|
143
|
+
message: `field '${offending}' is not ${verb} on an objective`,
|
|
144
|
+
status: 400,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build a fresh objective record from a SET body, byte-identical to core's
|
|
149
|
+
* `Agent.setObjective` (id = randomUUID, status 'active', runsUsed 0, numeric
|
|
150
|
+
* startedAt/updatedAt, only explicitly-provided optionals persisted). The `id`
|
|
151
|
+
* is the in-record correlation tag core always mints for a goal — NOT an
|
|
152
|
+
* addressing/memory id (it never keys a store, addresses a DO, or crosses the
|
|
153
|
+
* tenancy boundary; the whole row rides the already-tenant-salted threadId), so
|
|
154
|
+
* a randomUUID here is faithful to core and does not need a tenant prefix.
|
|
155
|
+
*/
|
|
156
|
+
function buildSetRecord(body, cap) {
|
|
157
|
+
const disallowed = firstDisallowedField(body, SET_FIELDS, 'settable');
|
|
158
|
+
if (disallowed)
|
|
159
|
+
return { ok: false, error: disallowed };
|
|
160
|
+
const objective = body.objective;
|
|
161
|
+
if (typeof objective !== 'string' || objective.trim().length === 0) {
|
|
162
|
+
return rejectField('objective-invalid', 'objective must be a non-empty string');
|
|
163
|
+
}
|
|
164
|
+
const maxRuns = validateMaxRuns(body.maxRuns, cap);
|
|
165
|
+
if (!maxRuns.ok)
|
|
166
|
+
return maxRuns;
|
|
167
|
+
const judgeModelId = validateOptionalString(body.judgeModelId, 'judgeModelId', true);
|
|
168
|
+
if (!judgeModelId.ok)
|
|
169
|
+
return judgeModelId;
|
|
170
|
+
const prompt = validateOptionalString(body.prompt, 'prompt');
|
|
171
|
+
if (!prompt.ok)
|
|
172
|
+
return prompt;
|
|
173
|
+
const now = Date.now();
|
|
174
|
+
const record = {
|
|
175
|
+
id: crypto.randomUUID(),
|
|
176
|
+
objective,
|
|
177
|
+
status: 'active',
|
|
178
|
+
runsUsed: 0,
|
|
179
|
+
startedAt: now,
|
|
180
|
+
updatedAt: now,
|
|
181
|
+
...(maxRuns.value !== undefined ? { maxRuns: maxRuns.value } : {}),
|
|
182
|
+
...(judgeModelId.value !== undefined
|
|
183
|
+
? { judgeModelId: judgeModelId.value }
|
|
184
|
+
: {}),
|
|
185
|
+
...(prompt.value !== undefined ? { prompt: prompt.value } : {}),
|
|
186
|
+
};
|
|
187
|
+
return { ok: true, value: record };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Merge an UPDATE body over the existing record, byte-identical to core's
|
|
191
|
+
* `Agent.updateObjectiveOptions`: only judge/maxRuns/prompt/status are settable
|
|
192
|
+
* (never the prose), runsUsed/startedAt/id are preserved, updatedAt is bumped.
|
|
193
|
+
*/
|
|
194
|
+
function buildUpdateRecord(existing, body, cap) {
|
|
195
|
+
const disallowed = firstDisallowedField(body, UPDATE_FIELDS, 'updatable');
|
|
196
|
+
if (disallowed)
|
|
197
|
+
return { ok: false, error: disallowed };
|
|
198
|
+
const maxRuns = validateMaxRuns(body.maxRuns, cap);
|
|
199
|
+
if (!maxRuns.ok)
|
|
200
|
+
return maxRuns;
|
|
201
|
+
const judgeModelId = validateOptionalString(body.judgeModelId, 'judgeModelId', true);
|
|
202
|
+
if (!judgeModelId.ok)
|
|
203
|
+
return judgeModelId;
|
|
204
|
+
const prompt = validateOptionalString(body.prompt, 'prompt');
|
|
205
|
+
if (!prompt.ok)
|
|
206
|
+
return prompt;
|
|
207
|
+
let status;
|
|
208
|
+
if (body.status !== undefined) {
|
|
209
|
+
const candidate = body.status;
|
|
210
|
+
if (typeof candidate !== 'string' ||
|
|
211
|
+
!GOAL_STATUSES.includes(candidate)) {
|
|
212
|
+
return rejectField('status-invalid', `status must be one of ${GOAL_STATUSES.join(', ')}`);
|
|
213
|
+
}
|
|
214
|
+
status = candidate;
|
|
215
|
+
}
|
|
216
|
+
const updated = {
|
|
217
|
+
...existing,
|
|
218
|
+
updatedAt: Date.now(),
|
|
219
|
+
...(judgeModelId.value !== undefined
|
|
220
|
+
? { judgeModelId: judgeModelId.value }
|
|
221
|
+
: {}),
|
|
222
|
+
...(maxRuns.value !== undefined ? { maxRuns: maxRuns.value } : {}),
|
|
223
|
+
...(prompt.value !== undefined ? { prompt: prompt.value } : {}),
|
|
224
|
+
...(status !== undefined ? { status } : {}),
|
|
225
|
+
};
|
|
226
|
+
return { ok: true, value: updated };
|
|
227
|
+
}
|
|
228
|
+
export function createObjectiveRouter(options) {
|
|
229
|
+
const { resolve, store } = options;
|
|
230
|
+
const roles = options.roles ?? RUN_START_ROLES;
|
|
231
|
+
const maxRunsCap = positiveSafeInteger(options.maxRunsCap ?? DEFAULT_GOAL_MAX_RUNS, 'maxRunsCap');
|
|
232
|
+
const maxContentBytes = nonnegativeSafeInteger(options.maxContentBytes ?? 16_384, 'objective maxContentBytes');
|
|
233
|
+
const base = options.basePath ?? '/api/threads';
|
|
234
|
+
const baseSegments = base.split('/').filter(Boolean);
|
|
235
|
+
return async (request) => {
|
|
236
|
+
const url = new URL(request.url);
|
|
237
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
238
|
+
// /api/threads/:threadId/goal — the basePath segments, the threadId, then
|
|
239
|
+
// the literal 'goal'. Any other shape composes ahead of the next router.
|
|
240
|
+
if (segments.length !== baseSegments.length + 2 ||
|
|
241
|
+
baseSegments.some((seg, i) => segments[i] !== seg) ||
|
|
242
|
+
segments[baseSegments.length + 1] !== 'goal') {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
// Malformed percent-encoding in the threadId is not a real route target —
|
|
246
|
+
// route-absent, never a pre-auth decodeURIComponent throw out of the handler.
|
|
247
|
+
const threadId = safeDecodeSegment(segments[baseSegments.length]);
|
|
248
|
+
if (threadId === undefined)
|
|
249
|
+
return null;
|
|
250
|
+
const operation = OPERATION_BY_METHOD[request.method];
|
|
251
|
+
if (operation === undefined) {
|
|
252
|
+
return json({ error: 'method not allowed' }, 405);
|
|
253
|
+
}
|
|
254
|
+
const isMutation = operation !== 'get';
|
|
255
|
+
// Hoisted above the try so the catch audits the post-auth denials that
|
|
256
|
+
// surface as thrown RunRouteErrors (the ownership 404, the memory-id 400).
|
|
257
|
+
// `tenant` is undefined until resolve succeeds and the closure no-ops while
|
|
258
|
+
// it is, so a pre-auth throw is never audited; a benign GET is not audited.
|
|
259
|
+
let tenant;
|
|
260
|
+
const audit = async (outcome, reason) => {
|
|
261
|
+
if (!options.audit || !tenant)
|
|
262
|
+
return;
|
|
263
|
+
if (operation === 'get' && outcome === 'accepted')
|
|
264
|
+
return;
|
|
265
|
+
await options.audit({
|
|
266
|
+
type: 'goal.objective',
|
|
267
|
+
tenantId: tenant.tenantId,
|
|
268
|
+
actorId: tenant.actor.id,
|
|
269
|
+
threadId,
|
|
270
|
+
operation,
|
|
271
|
+
outcome,
|
|
272
|
+
...(reason !== undefined ? { reason } : {}),
|
|
273
|
+
timestamp: new Date().toISOString(),
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
try {
|
|
277
|
+
// 1. Resolve (authenticate -> INV-3 -> bind).
|
|
278
|
+
tenant = await resolve(request);
|
|
279
|
+
if (!tenant)
|
|
280
|
+
return json({ error: 'authentication required' }, 401);
|
|
281
|
+
// 2. Coarse role on MUTATIONS: authoring a standing instruction is an
|
|
282
|
+
// operator/admin act, so a reviewer/viewer is refused before the target
|
|
283
|
+
// thread is read. Authenticated-but-unauthorized, so the rejection IS
|
|
284
|
+
// audited (a real actor, no flood risk).
|
|
285
|
+
if (isMutation && !roles.includes(tenant.actor.role)) {
|
|
286
|
+
await audit('rejected', 'forbidden-role');
|
|
287
|
+
return json({ error: 'forbidden' }, 403);
|
|
288
|
+
}
|
|
289
|
+
// 3. Thread-prefix ownership: 404 (never 403) on a foreign threadId, so a
|
|
290
|
+
// caller learns nothing about another tenant's thread ids.
|
|
291
|
+
// requireOwnedMemoryId throws RunRouteError(404), audited in the catch.
|
|
292
|
+
requireOwnedMemoryId(tenant, threadId, 'threadId');
|
|
293
|
+
// 4. GET / CLEAR carry no validated body.
|
|
294
|
+
if (operation === 'get') {
|
|
295
|
+
const record = await readObjective(store, threadId);
|
|
296
|
+
await audit('accepted');
|
|
297
|
+
return json({ objective: record ?? null });
|
|
298
|
+
}
|
|
299
|
+
if (operation === 'clear') {
|
|
300
|
+
await clearObjective(store, threadId);
|
|
301
|
+
await audit('accepted');
|
|
302
|
+
return json({ ok: true });
|
|
303
|
+
}
|
|
304
|
+
// 5. SET / UPDATE: size-cap the raw body at the wire, THEN parse.
|
|
305
|
+
const rawBody = await request.text();
|
|
306
|
+
const contentBytes = new TextEncoder().encode(rawBody).length;
|
|
307
|
+
if (contentBytes > maxContentBytes) {
|
|
308
|
+
await audit('rejected', 'payload-too-large');
|
|
309
|
+
return json({ error: `objective payload exceeds ${maxContentBytes} bytes` }, 413);
|
|
310
|
+
}
|
|
311
|
+
let body;
|
|
312
|
+
try {
|
|
313
|
+
const parsed = rawBody === '' ? {} : JSON.parse(rawBody);
|
|
314
|
+
if (typeof parsed !== 'object' ||
|
|
315
|
+
parsed === null ||
|
|
316
|
+
Array.isArray(parsed)) {
|
|
317
|
+
await audit('rejected', 'malformed-body');
|
|
318
|
+
return json({ error: 'a JSON object body is required' }, 400);
|
|
319
|
+
}
|
|
320
|
+
body = parsed;
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
await audit('rejected', 'malformed-body');
|
|
324
|
+
return json({ error: 'a JSON object body is required' }, 400);
|
|
325
|
+
}
|
|
326
|
+
// 6. No client memory id anywhere in the body (assertNoClientMemoryIds 400s).
|
|
327
|
+
assertNoClientMemoryIds(body);
|
|
328
|
+
// 7/8. Field allowlist + maxRuns cap, then persist through core's OWN
|
|
329
|
+
// writer so the stored shape matches the reader's exactly.
|
|
330
|
+
if (operation === 'set') {
|
|
331
|
+
const built = buildSetRecord(body, maxRunsCap);
|
|
332
|
+
if (!built.ok) {
|
|
333
|
+
await audit('rejected', built.error.reason);
|
|
334
|
+
return json({ error: built.error.message }, built.error.status);
|
|
335
|
+
}
|
|
336
|
+
await writeObjective(store, threadId, built.value);
|
|
337
|
+
await audit('accepted');
|
|
338
|
+
return json({ objective: built.value });
|
|
339
|
+
}
|
|
340
|
+
// operation === 'update': merge over the existing record (404 if none —
|
|
341
|
+
// the OWN thread has nothing to update, distinct from the foreign 404).
|
|
342
|
+
const existing = await readObjective(store, threadId);
|
|
343
|
+
if (!existing) {
|
|
344
|
+
await audit('rejected', 'no-objective');
|
|
345
|
+
return json({ error: 'no objective set for this thread' }, 404);
|
|
346
|
+
}
|
|
347
|
+
const built = buildUpdateRecord(existing, body, maxRunsCap);
|
|
348
|
+
if (!built.ok) {
|
|
349
|
+
await audit('rejected', built.error.reason);
|
|
350
|
+
return json({ error: built.error.message }, built.error.status);
|
|
351
|
+
}
|
|
352
|
+
await writeObjective(store, threadId, built.value);
|
|
353
|
+
await audit('accepted');
|
|
354
|
+
return json({ objective: built.value });
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
if (error instanceof RunRouteError) {
|
|
358
|
+
// A post-auth denial: the ownership 404 (foreign thread) or the
|
|
359
|
+
// memory-id 400 (a smuggled TCB-only id). tenant is set by here.
|
|
360
|
+
await audit('rejected', error.status === 404
|
|
361
|
+
? 'foreign-thread'
|
|
362
|
+
: error.status === 400
|
|
363
|
+
? 'client-memory-id'
|
|
364
|
+
: `route-error-${error.status}`);
|
|
365
|
+
return json({ error: error.message }, error.status);
|
|
366
|
+
}
|
|
367
|
+
if (error instanceof TenantResolutionError) {
|
|
368
|
+
// Pre-auth (the resolver itself threw): unauthenticated, so not audited.
|
|
369
|
+
return json({ error: 'forbidden' }, 403);
|
|
370
|
+
}
|
|
371
|
+
return internalErrorResponse('goals.objective', error);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=objective-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objective-routes.js","sourceRoot":"","sources":["../../src/goals/objective-routes.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,4EAA4E;AAC5E,EAAE;AACF,sEAAsE;AACtE,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,wEAAwE;AACxE,4EAA4E;AAC5E,gEAAgE;AAChE,qEAAqE;AACrE,+EAA+E;AAC/E,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,iFAAiF;AACjF,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,qEAAqE;AACrE,oFAAoF;AACpF,uFAAuF;AACvF,uEAAuE;AACvE,uEAAuE;AACvE,iFAAiF;AACjF,iEAAiE;AACjE,wCAAwC;AACxC,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,gFAAgF;AAChF,wEAAwE;AACxE,6DAA6D;AAC7D,EAAE;AACF,8EAA8E;AAC9E,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,aAAa;AACb,EAAE;AACF,gFAAgF;AAChF,wEAAwE;AACxE,+EAA+E;AAC/E,wDAAwD;AACxD,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,iCAAiC;AACjC,gFAAgF;AAChF,iFAAiF;AACjF,+EAA+E;AAC/E,mCAAmC;AAGnC,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,eAAe,EAEf,qBAAqB,GAEtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAA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C,MAAM,CAAC,CAAC;YACtD,CAAC;YACD,IAAI,KAAK,YAAY,qBAAqB,EAAE,CAAC;gBAC3C,yEAAyE;gBACzE,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;YACD,OAAO,qBAAqB,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ApprovalActor, type ApprovalAuditSink, type ApprovalDecision, type ApprovalRecord, type ApprovalService, type TenantContext } from '../approval-api/index.js';
|
|
1
|
+
import { type ApprovalActor, type ApprovalAuditSink, type ApprovalDecision, type ApprovalRecord, type ApprovalResumeTarget, type ApprovalService, type TenantContext } from '../approval-api/index.js';
|
|
2
2
|
import type { RunSummary } from '../do-runner/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Resumes a run after a decision. The showcase Worker fetches the run's DO stub;
|
|
@@ -6,7 +6,27 @@ import type { RunSummary } from '../do-runner/index.js';
|
|
|
6
6
|
* post-resume RunSummary so the re-queue wrapper can inspect status.
|
|
7
7
|
*/
|
|
8
8
|
export type ResumeRunFn = (record: ApprovalRecord, decision: ApprovalDecision) => Promise<RunSummary>;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The connector ids a suspended step's decision should mint. A workflow STEP
|
|
11
|
+
* gate declares them explicitly in a `connectors` array. An agent gate
|
|
12
|
+
* declares none — it names the tool the model called by `toolName` in both
|
|
13
|
+
* durable suspend shapes). For automatic grant derivation, that provider-visible
|
|
14
|
+
* name MUST already be the breakwater connector's provider-safe id
|
|
15
|
+
* (`[A-Za-z0-9_-]+`); providers can rewrite punctuation-bearing ids and the
|
|
16
|
+
* suspend payload carries no reversible original-id field. agentGateConnectors
|
|
17
|
+
* derives [toolName] so an approved agent gate mints exactly that connector's
|
|
18
|
+
* grant. The explicit array wins when present, so workflow gates are unaffected.
|
|
19
|
+
*
|
|
20
|
+
* ACCEPTED RISK (narrow): the agent fallback is a workflow-agnostic shape sniff —
|
|
21
|
+
* a suspend payload has no workflowId to prove it came from the durable loop. A
|
|
22
|
+
* workflow author who both omits `connectors` AND independently shapes a gate as
|
|
23
|
+
* `{type:'approval', toolName, toolCallId}` (all three, the second discriminator
|
|
24
|
+
* that agentGateConnectors demands) would derive [toolName] where earlier
|
|
25
|
+
* behavior returned []. It is inert unless that toolName also names a real connector
|
|
26
|
+
* the run calls; the shipped/showcase workflows all declare `connectors`, so none
|
|
27
|
+
* collide today. The right convention for workflow gates remains the explicit
|
|
28
|
+
* `connectors` array.
|
|
29
|
+
*/
|
|
10
30
|
export declare function requestedConnectors(stepPayload: unknown): string[];
|
|
11
31
|
/**
|
|
12
32
|
* A suspension IS an approval request: queue one record per suspended step
|
|
@@ -27,7 +47,7 @@ export declare function requestedConnectors(stepPayload: unknown): string[];
|
|
|
27
47
|
* attributing every request to the system actor would make that check unfireable.
|
|
28
48
|
* `systemActor` is only the record's creator (needs a create-capable role).
|
|
29
49
|
*/
|
|
30
|
-
export declare function queueApprovalForSuspension(service: ApprovalService, workflowId: string, summary: RunSummary, requestedBy: string, systemActor: ApprovalActor): Promise<ApprovalRecord[]>;
|
|
50
|
+
export declare function queueApprovalForSuspension(service: ApprovalService, workflowId: string, summary: RunSummary, requestedBy: string, systemActor: ApprovalActor, resumeTarget?: ApprovalResumeTarget): Promise<ApprovalRecord[]>;
|
|
31
51
|
/**
|
|
32
52
|
* Wrap a base resume fn so a run that re-suspends at a LATER gate auto-queues
|
|
33
53
|
* its next approval(s) — the multi-gate flow (product-launch's two gates); every
|
|
@@ -47,13 +67,13 @@ export declare function queueApprovalForSuspension(service: ApprovalService, wor
|
|
|
47
67
|
* `audit` is optional and should be the SAME sink the service itself uses
|
|
48
68
|
* (buildHostApprovalService wires it that way): the base resume above has
|
|
49
69
|
* already durably advanced the run by the time the re-queue below can fail,
|
|
50
|
-
* so a throw here
|
|
51
|
-
*
|
|
52
|
-
*
|
|
70
|
+
* so a throw here leaves a gate suspended with no approval record and no
|
|
71
|
+
* other signal that happened. reconcileApprovalsForSummary is the recovery;
|
|
72
|
+
* this event is what tells an operator it was needed.
|
|
53
73
|
*/
|
|
54
74
|
export declare function resumeRunWithRequeue(base: ResumeRunFn, getService: () => ApprovalService, systemActor: ApprovalActor, audit?: ApprovalAuditSink): ResumeRunFn;
|
|
55
75
|
/**
|
|
56
|
-
*
|
|
76
|
+
* Recovery primitive: given a run's suspended RunSummary, heals every
|
|
57
77
|
* CURRENTLY suspended step whose exact (suspendedAt, resumeCount)
|
|
58
78
|
* fingerprint has no approval record of ANY status, then files it fresh.
|
|
59
79
|
* Safe to call on every status() read of a suspended run, rather than only
|
|
@@ -97,7 +117,7 @@ export declare function resumeRunWithRequeue(base: ResumeRunFn, getService: () =
|
|
|
97
117
|
* recovery path only: the gate-A decider MAY legally decide the reconciled
|
|
98
118
|
* gate B, same as the retention-purge recovery path.
|
|
99
119
|
*/
|
|
100
|
-
export declare function reconcileApprovalsForSummary(service: ApprovalService, workflowId: string, summary: RunSummary, systemActor: ApprovalActor): Promise<ApprovalRecord[]>;
|
|
120
|
+
export declare function reconcileApprovalsForSummary(service: ApprovalService, workflowId: string, summary: RunSummary, systemActor: ApprovalActor, resumeTarget?: ApprovalResumeTarget): Promise<ApprovalRecord[]>;
|
|
101
121
|
/**
|
|
102
122
|
* Adapts reconcileApprovalsForSummary to RunRouterOptions.reconcileApprovals's
|
|
103
123
|
* per-request shape: `tenant.service()`/`tenant.tenantId` only exist once a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-bridge.d.ts","sourceRoot":"","sources":["../../src/host-kit/approval-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approval-bridge.d.ts","sourceRoot":"","sources":["../../src/host-kit/approval-bridge.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,iBAAiB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