agentfootprint 7.17.0 → 7.19.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/AGENTS.md +1 -1
- package/CLAUDE.md +2 -2
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/dist/adapters/hosting/agentcore.js +23 -9
- package/dist/adapters/hosting/agentcore.js.map +1 -1
- package/dist/core/Agent.js +57 -2
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/RunnerBase.js +16 -1
- package/dist/core/RunnerBase.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +117 -1
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/middleware/errors.js +54 -0
- package/dist/core/agent/middleware/errors.js.map +1 -0
- package/dist/core/agent/middleware/index.js +23 -0
- package/dist/core/agent/middleware/index.js.map +1 -0
- package/dist/core/agent/middleware/ledger.js +61 -0
- package/dist/core/agent/middleware/ledger.js.map +1 -0
- package/dist/core/agent/middleware/outcomes.js +66 -0
- package/dist/core/agent/middleware/outcomes.js.map +1 -0
- package/dist/core/agent/middleware/runChain.js +144 -0
- package/dist/core/agent/middleware/runChain.js.map +1 -0
- package/dist/core/agent/middleware/types.js +41 -0
- package/dist/core/agent/middleware/types.js.map +1 -0
- package/dist/core/agent/stages/prepareFinal.js +10 -0
- package/dist/core/agent/stages/prepareFinal.js.map +1 -1
- package/dist/core/agent/stages/route.js +62 -1
- package/dist/core/agent/stages/route.js.map +1 -1
- package/dist/core/agent/stages/seed.js +130 -85
- package/dist/core/agent/stages/seed.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +208 -8
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/durabilityBarrier.js +68 -0
- package/dist/core/durabilityBarrier.js.map +1 -0
- package/dist/core/pause.js +19 -1
- package/dist/core/pause.js.map +1 -1
- package/dist/esm/adapters/hosting/agentcore.d.ts +4 -4
- package/dist/esm/adapters/hosting/agentcore.js +24 -10
- package/dist/esm/adapters/hosting/agentcore.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +9 -1
- package/dist/esm/core/Agent.js +58 -3
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/RunnerBase.js +16 -1
- package/dist/esm/core/RunnerBase.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +97 -0
- package/dist/esm/core/agent/AgentBuilder.js +117 -1
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.d.ts +2 -2
- package/dist/esm/core/agent/middleware/errors.d.ts +51 -0
- package/dist/esm/core/agent/middleware/errors.js +50 -0
- package/dist/esm/core/agent/middleware/errors.js.map +1 -0
- package/dist/esm/core/agent/middleware/index.d.ts +16 -0
- package/dist/esm/core/agent/middleware/index.js +16 -0
- package/dist/esm/core/agent/middleware/index.js.map +1 -0
- package/dist/esm/core/agent/middleware/ledger.d.ts +40 -0
- package/dist/esm/core/agent/middleware/ledger.js +57 -0
- package/dist/esm/core/agent/middleware/ledger.js.map +1 -0
- package/dist/esm/core/agent/middleware/outcomes.d.ts +45 -0
- package/dist/esm/core/agent/middleware/outcomes.js +60 -0
- package/dist/esm/core/agent/middleware/outcomes.js.map +1 -0
- package/dist/esm/core/agent/middleware/runChain.d.ts +104 -0
- package/dist/esm/core/agent/middleware/runChain.js +139 -0
- package/dist/esm/core/agent/middleware/runChain.js.map +1 -0
- package/dist/esm/core/agent/middleware/types.d.ts +191 -0
- package/dist/esm/core/agent/middleware/types.js +40 -0
- package/dist/esm/core/agent/middleware/types.js.map +1 -0
- package/dist/esm/core/agent/stages/prepareFinal.d.ts +10 -0
- package/dist/esm/core/agent/stages/prepareFinal.js +10 -0
- package/dist/esm/core/agent/stages/prepareFinal.js.map +1 -1
- package/dist/esm/core/agent/stages/route.d.ts +29 -0
- package/dist/esm/core/agent/stages/route.js +60 -0
- package/dist/esm/core/agent/stages/route.js.map +1 -1
- package/dist/esm/core/agent/stages/seed.d.ts +16 -1
- package/dist/esm/core/agent/stages/seed.js +130 -85
- package/dist/esm/core/agent/stages/seed.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.d.ts +44 -0
- package/dist/esm/core/agent/stages/toolCalls.js +208 -8
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +18 -0
- package/dist/esm/core/durabilityBarrier.d.ts +61 -0
- package/dist/esm/core/durabilityBarrier.js +63 -0
- package/dist/esm/core/durabilityBarrier.js.map +1 -0
- package/dist/esm/core/pause.d.ts +42 -0
- package/dist/esm/core/pause.js +17 -0
- package/dist/esm/core/pause.js.map +1 -1
- package/dist/esm/events/dispatcher.d.ts +1 -1
- package/dist/esm/events/dispatcher.js.map +1 -1
- package/dist/esm/events/payloads.d.ts +26 -0
- package/dist/esm/events/registry.d.ts +5 -1
- package/dist/esm/events/registry.js +4 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/hosting/durability.d.ts +92 -0
- package/dist/esm/hosting/durability.js +174 -0
- package/dist/esm/hosting/durability.js.map +1 -0
- package/dist/esm/hosting/envelope.d.ts +75 -14
- package/dist/esm/hosting/envelope.js +141 -16
- package/dist/esm/hosting/envelope.js.map +1 -1
- package/dist/esm/hosting/errors.d.ts +60 -11
- package/dist/esm/hosting/errors.js +92 -18
- package/dist/esm/hosting/errors.js.map +1 -1
- package/dist/esm/hosting/httpHost.d.ts +17 -1
- package/dist/esm/hosting/httpHost.js +42 -6
- package/dist/esm/hosting/httpHost.js.map +1 -1
- package/dist/esm/hosting/index.d.ts +7 -4
- package/dist/esm/hosting/index.js +6 -3
- package/dist/esm/hosting/index.js.map +1 -1
- package/dist/esm/hosting/nodeHost.d.ts +4 -2
- package/dist/esm/hosting/nodeHost.js +14 -3
- package/dist/esm/hosting/nodeHost.js.map +1 -1
- package/dist/esm/hosting/standingAgent.d.ts +22 -7
- package/dist/esm/hosting/standingAgent.js +144 -32
- package/dist/esm/hosting/standingAgent.js.map +1 -1
- package/dist/esm/hosting/types.d.ts +193 -19
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +13 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/mcp/mcpServe.js +39 -6
- package/dist/esm/lib/mcp/mcpServe.js.map +1 -1
- package/dist/esm/lib/mcp/types.d.ts +16 -0
- package/dist/events/dispatcher.js.map +1 -1
- package/dist/events/registry.js +4 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/hosting/durability.js +178 -0
- package/dist/hosting/durability.js.map +1 -0
- package/dist/hosting/envelope.js +146 -18
- package/dist/hosting/envelope.js.map +1 -1
- package/dist/hosting/errors.js +95 -19
- package/dist/hosting/errors.js.map +1 -1
- package/dist/hosting/httpHost.js +42 -6
- package/dist/hosting/httpHost.js.map +1 -1
- package/dist/hosting/index.js +10 -2
- package/dist/hosting/index.js.map +1 -1
- package/dist/hosting/nodeHost.js +14 -3
- package/dist/hosting/nodeHost.js.map +1 -1
- package/dist/hosting/standingAgent.js +142 -30
- package/dist/hosting/standingAgent.js.map +1 -1
- package/dist/index.js +31 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/mcp/mcpServe.js +39 -6
- package/dist/lib/mcp/mcpServe.js.map +1 -1
- package/dist/types/adapters/hosting/agentcore.d.ts +4 -4
- package/dist/types/adapters/hosting/agentcore.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +9 -1
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/RunnerBase.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts +97 -0
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts +2 -2
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/middleware/errors.d.ts +52 -0
- package/dist/types/core/agent/middleware/errors.d.ts.map +1 -0
- package/dist/types/core/agent/middleware/index.d.ts +17 -0
- package/dist/types/core/agent/middleware/index.d.ts.map +1 -0
- package/dist/types/core/agent/middleware/ledger.d.ts +41 -0
- package/dist/types/core/agent/middleware/ledger.d.ts.map +1 -0
- package/dist/types/core/agent/middleware/outcomes.d.ts +46 -0
- package/dist/types/core/agent/middleware/outcomes.d.ts.map +1 -0
- package/dist/types/core/agent/middleware/runChain.d.ts +105 -0
- package/dist/types/core/agent/middleware/runChain.d.ts.map +1 -0
- package/dist/types/core/agent/middleware/types.d.ts +192 -0
- package/dist/types/core/agent/middleware/types.d.ts.map +1 -0
- package/dist/types/core/agent/stages/prepareFinal.d.ts +10 -0
- package/dist/types/core/agent/stages/prepareFinal.d.ts.map +1 -1
- package/dist/types/core/agent/stages/route.d.ts +29 -0
- package/dist/types/core/agent/stages/route.d.ts.map +1 -1
- package/dist/types/core/agent/stages/seed.d.ts +16 -1
- package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts +44 -0
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +18 -0
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/durabilityBarrier.d.ts +62 -0
- package/dist/types/core/durabilityBarrier.d.ts.map +1 -0
- package/dist/types/core/pause.d.ts +42 -0
- package/dist/types/core/pause.d.ts.map +1 -1
- package/dist/types/events/dispatcher.d.ts +1 -1
- package/dist/types/events/dispatcher.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +26 -0
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +5 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/hosting/durability.d.ts +93 -0
- package/dist/types/hosting/durability.d.ts.map +1 -0
- package/dist/types/hosting/envelope.d.ts +75 -14
- package/dist/types/hosting/envelope.d.ts.map +1 -1
- package/dist/types/hosting/errors.d.ts +60 -11
- package/dist/types/hosting/errors.d.ts.map +1 -1
- package/dist/types/hosting/httpHost.d.ts +17 -1
- package/dist/types/hosting/httpHost.d.ts.map +1 -1
- package/dist/types/hosting/index.d.ts +7 -4
- package/dist/types/hosting/index.d.ts.map +1 -1
- package/dist/types/hosting/nodeHost.d.ts +4 -2
- package/dist/types/hosting/nodeHost.d.ts.map +1 -1
- package/dist/types/hosting/standingAgent.d.ts +22 -7
- package/dist/types/hosting/standingAgent.d.ts.map +1 -1
- package/dist/types/hosting/types.d.ts +193 -19
- package/dist/types/hosting/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -1
- package/dist/types/lib/mcp/types.d.ts +16 -0
- package/dist/types/lib/mcp/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* core/durabilityBarrier — the one seam a durable session composer may hold
|
|
3
|
+
* inside a run, and nothing else may.
|
|
4
|
+
*
|
|
5
|
+
* ── What it is ───────────────────────────────────────────────────────────────
|
|
6
|
+
* A run's tool dispatch asks, once per ReAct iteration, "is there a durable
|
|
7
|
+
* write still in flight from the LAST iteration?" and — only if there is —
|
|
8
|
+
* waits for it before executing this iteration's tools. That is the entire
|
|
9
|
+
* mechanism. It exists because the alternative is a bound nobody can state:
|
|
10
|
+
* without it, iteration N's tools can run while iteration N-1's write is still
|
|
11
|
+
* on the wire, so a crash replays MORE than one iteration of side effects and
|
|
12
|
+
* "how much can re-execute?" has no answer.
|
|
13
|
+
*
|
|
14
|
+
* ── Why it is a WeakMap and not an option ────────────────────────────────────
|
|
15
|
+
* This is deliberately **not** a public extension point. footprintjs's stage
|
|
16
|
+
* seams and phase chain are closed here, and a general "run something between
|
|
17
|
+
* my stages" hook would be a new one — it would let any consumer inject
|
|
18
|
+
* latency, ordering and failures into a traversal, and every later feature
|
|
19
|
+
* would have to reason about it. So the barrier is keyed off the runner
|
|
20
|
+
* instance in a module-private WeakMap that appears on no barrel and no
|
|
21
|
+
* subpath: `agentfootprint/hosting`'s session writer installs it, the tool
|
|
22
|
+
* dispatch reads it, and there is no third party. Nothing in the public API
|
|
23
|
+
* surface mentions it, which is the point.
|
|
24
|
+
*
|
|
25
|
+
* ── Why it costs nothing when nobody installed one ───────────────────────────
|
|
26
|
+
* {@link pendingDurableWrite} returns `undefined` — not a resolved promise —
|
|
27
|
+
* when no barrier is installed, so the dispatch loop does not `await`, does not
|
|
28
|
+
* schedule a microtask, and produces byte-identical timing to an agent that
|
|
29
|
+
* never heard of durability.
|
|
30
|
+
*
|
|
31
|
+
* Pattern: Instance-keyed private capability (a WeakMap "friend" channel).
|
|
32
|
+
* Role: core/ layer, internal. No events, no state, no scope.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
const barriers = new WeakMap();
|
|
37
|
+
/**
|
|
38
|
+
* Install the barrier for one runner. Returns the uninstall function; the
|
|
39
|
+
* caller owns it, exactly as `attach()` and `on()` hand back their own.
|
|
40
|
+
*
|
|
41
|
+
* Last install wins. One runner has at most one barrier because one composer
|
|
42
|
+
* owns its durability — two would be two answers to "has the last write
|
|
43
|
+
* landed?", and a run cannot honour both.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export function installDurabilityBarrier(owner, barrier) {
|
|
48
|
+
barriers.set(owner, barrier);
|
|
49
|
+
return () => {
|
|
50
|
+
if (barriers.get(owner) === barrier)
|
|
51
|
+
barriers.delete(owner);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The durable write still in flight for this runner, or `undefined` when there
|
|
56
|
+
* is no barrier installed or nothing outstanding.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export function pendingDurableWrite(owner) {
|
|
61
|
+
return barriers.get(owner)?.();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=durabilityBarrier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durabilityBarrier.js","sourceRoot":"","sources":["../../../src/core/durabilityBarrier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAWH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA6B,CAAC;AAE1D;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAa,EAAE,OAA0B;IAChF,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,GAAG,EAAE;QACV,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,OAAO;YAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;AACjC,CAAC"}
|
package/dist/esm/core/pause.d.ts
CHANGED
|
@@ -37,6 +37,31 @@ export interface RunnerPauseOutcome {
|
|
|
37
37
|
* (`checkInApproved` / `checkInDeclined`).
|
|
38
38
|
*/
|
|
39
39
|
readonly checkIn?: CheckInRequest;
|
|
40
|
+
/**
|
|
41
|
+
* Present ONLY when a `toolMiddleware` answered `ask` — the question it put
|
|
42
|
+
* to a person, plus the middleware that asked. Absent for every other pause,
|
|
43
|
+
* which is the discriminant.
|
|
44
|
+
*
|
|
45
|
+
* Resume with a `CheckInDecision` (`checkInApproved` / `checkInDeclined`).
|
|
46
|
+
* That is deliberate rather than a second decision type: a person approving
|
|
47
|
+
* is a person approving, whether the gate was a tool's `checkIn` or a
|
|
48
|
+
* middleware's `ask`, and one word for one thing beats a synonym.
|
|
49
|
+
*
|
|
50
|
+
* The answer is a DECISION, not a result. Approve and the chain resumes from
|
|
51
|
+
* the next middleware and the REAL tool runs; decline and the model receives
|
|
52
|
+
* a denial it can adapt to. Nobody — not the middleware, not the person —
|
|
53
|
+
* gets to write the tool's answer.
|
|
54
|
+
*/
|
|
55
|
+
readonly ask?: MiddlewareAsk;
|
|
56
|
+
}
|
|
57
|
+
/** The question a `toolMiddleware` put to a person, as it rides the checkpoint. */
|
|
58
|
+
export interface MiddlewareAsk {
|
|
59
|
+
/** The question, in the middleware author's own words. */
|
|
60
|
+
readonly question: string;
|
|
61
|
+
/** Anything else the answering UI should render. Never interpreted here. */
|
|
62
|
+
readonly detail?: unknown;
|
|
63
|
+
/** `name` of the middleware that asked. */
|
|
64
|
+
readonly middleware: string;
|
|
40
65
|
}
|
|
41
66
|
/** Type guard — discriminates `RunnerPauseOutcome` from a normal `TOut`. */
|
|
42
67
|
export declare function isPaused<T>(result: T | RunnerPauseOutcome): result is RunnerPauseOutcome;
|
|
@@ -55,6 +80,23 @@ export declare function isPaused<T>(result: T | RunnerPauseOutcome): result is R
|
|
|
55
80
|
export declare function isCheckInPause(result: unknown): result is RunnerPauseOutcome & {
|
|
56
81
|
readonly checkIn: CheckInRequest;
|
|
57
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Type guard — is this a middleware-ask pause (a `toolMiddleware` answered
|
|
85
|
+
* `ask`), as opposed to a check-in or a plain `askHuman` pause? Narrows `ask`
|
|
86
|
+
* to present.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const out = await agent.run({ message });
|
|
90
|
+
* if (isAskPause(out)) {
|
|
91
|
+
* const yes = await showToHuman(out.ask.question); // asked by out.ask.middleware
|
|
92
|
+
* await agent.resume(out.checkpoint, yes
|
|
93
|
+
* ? checkInApproved({ by: 'alice' })
|
|
94
|
+
* : checkInDeclined({ by: 'alice', note: 'not this one' }));
|
|
95
|
+
* }
|
|
96
|
+
*/
|
|
97
|
+
export declare function isAskPause(result: unknown): result is RunnerPauseOutcome & {
|
|
98
|
+
readonly ask: MiddlewareAsk;
|
|
99
|
+
};
|
|
58
100
|
/**
|
|
59
101
|
* Control-flow error raised by `pauseHere()` inside a tool's `execute()`.
|
|
60
102
|
* Caught by the Agent's tool-call stage, which forwards to `scope.$pause()`.
|
package/dist/esm/core/pause.js
CHANGED
|
@@ -34,6 +34,23 @@ export function isPaused(result) {
|
|
|
34
34
|
export function isCheckInPause(result) {
|
|
35
35
|
return isPaused(result) && result.checkIn !== undefined;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Type guard — is this a middleware-ask pause (a `toolMiddleware` answered
|
|
39
|
+
* `ask`), as opposed to a check-in or a plain `askHuman` pause? Narrows `ask`
|
|
40
|
+
* to present.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const out = await agent.run({ message });
|
|
44
|
+
* if (isAskPause(out)) {
|
|
45
|
+
* const yes = await showToHuman(out.ask.question); // asked by out.ask.middleware
|
|
46
|
+
* await agent.resume(out.checkpoint, yes
|
|
47
|
+
* ? checkInApproved({ by: 'alice' })
|
|
48
|
+
* : checkInDeclined({ by: 'alice', note: 'not this one' }));
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
51
|
+
export function isAskPause(result) {
|
|
52
|
+
return isPaused(result) && result.ask !== undefined;
|
|
53
|
+
}
|
|
37
54
|
/**
|
|
38
55
|
* Control-flow error raised by `pauseHere()` inside a tool's `execute()`.
|
|
39
56
|
* Caught by the Agent's tool-call stage, which forwards to `scope.$pause()`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pause.js","sourceRoot":"","sources":["../../../src/core/pause.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"pause.js","sourceRoot":"","sources":["../../../src/core/pause.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAqDH,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAI,MAA8B;IACxD,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAK,MAA6B,CAAC,MAAM,KAAK,IAAI,CAChG,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAe;IAEf,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAK,MAA6B,CAAC,OAAO,KAAK,SAAS,CAAC;AAClF,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CACxB,MAAe;IAEf,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAK,MAA6B,CAAC,GAAG,KAAK,SAAS,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAU;IACvB,YAAY,IAAa;QACvB,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,kEAAkE;QAClE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,OAAO,CACL,GAAG,YAAY,YAAY;QAC3B,CAAC,GAAG,YAAY,KAAK;YACnB,GAAG,CAAC,IAAI,KAAK,cAAc;YAC3B,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CACrD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC"}
|
|
@@ -30,7 +30,7 @@ export interface ListenOptions {
|
|
|
30
30
|
readonly signal?: AbortSignal;
|
|
31
31
|
}
|
|
32
32
|
export type Unsubscribe = () => void;
|
|
33
|
-
export type DomainWildcard = 'agentfootprint.composition.*' | 'agentfootprint.agent.*' | 'agentfootprint.stream.*' | 'agentfootprint.context.*' | 'agentfootprint.memory.*' | 'agentfootprint.tools.*' | 'agentfootprint.skill.*' | 'agentfootprint.permission.*' | 'agentfootprint.risk.*' | 'agentfootprint.fallback.*' | 'agentfootprint.cost.*' | 'agentfootprint.eval.*' | 'agentfootprint.error.*' | 'agentfootprint.pause.*' | 'agentfootprint.checkin.*' | 'agentfootprint.embedding.*';
|
|
33
|
+
export type DomainWildcard = 'agentfootprint.composition.*' | 'agentfootprint.agent.*' | 'agentfootprint.stream.*' | 'agentfootprint.context.*' | 'agentfootprint.memory.*' | 'agentfootprint.tools.*' | 'agentfootprint.skill.*' | 'agentfootprint.permission.*' | 'agentfootprint.risk.*' | 'agentfootprint.fallback.*' | 'agentfootprint.cost.*' | 'agentfootprint.eval.*' | 'agentfootprint.error.*' | 'agentfootprint.pause.*' | 'agentfootprint.checkin.*' | 'agentfootprint.middleware.*' | 'agentfootprint.embedding.*';
|
|
34
34
|
export type AllWildcard = '*';
|
|
35
35
|
export type WildcardSubscription = DomainWildcard | AllWildcard;
|
|
36
36
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../src/events/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA0BxC;2EAC2E;AAC3E,MAAM,eAAe,GAAgB,GAAG,EAAE,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../src/events/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA0BxC;2EAC2E;AAC3E,MAAM,eAAe,GAAgB,GAAG,EAAE,CAAC,SAAS,CAAC;AAoDrD;;;GAGG;AACH,SAAS,WAAW,CAAC,MAA2B;IAC9C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AAC,CAAC;QAC3C,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CACF;AAED,wEAAwE;AAExE;;;;GAIG;AACH,oJAAoJ;AACpJ,MAAM,YAAY,GAAG,IAAI,OAAO,EAAoB,CAAC;AAErD;;;;;;;GAOG;AACH,SAAS,UAAU,CACjB,QAA8C,EAC9C,IAAY;IAEZ,IAAI,CAAC,SAAS,EAAE;QAAE,OAAO,QAAQ,CAAC;IAElC,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC7C,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAY,CAAC;QAC1C,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YAC7D,sCAAsC;YACtC,OAAO,CAAC,IAAI,CACV,kCAAkC,IAAI,yBAAyB;gBAC7D,0EAA0E;gBAC1E,sEAAsE;gBACtE,+DAA+D,CAClE,CAAC;YACF,8DAA8D;YAC7D,MAA2B,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;gBAClD,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,0CAA0C,IAAI,aAAa,EAAE,GAAG,CAAC,CAAC;YAClF,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;IAEF,YAAY,CAAC,GAAG,CAAC,OAA4B,EAAE,QAAQ,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -329,6 +329,32 @@ export interface CheckInDecisionPayload {
|
|
|
329
329
|
readonly by: string;
|
|
330
330
|
readonly note?: string;
|
|
331
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* One link of a `toolMiddleware` / `messageMiddleware` chain answered.
|
|
334
|
+
*
|
|
335
|
+
* Its own domain rather than a `permission.check` with a different label:
|
|
336
|
+
* a middleware decision is not a permission check, and reporting it as one
|
|
337
|
+
* would make every consumer reading that channel believe a checker they
|
|
338
|
+
* never configured had fired.
|
|
339
|
+
*
|
|
340
|
+
* Deliberately carries no `before` / `after` — the values live in the
|
|
341
|
+
* committed `middlewareDecisions` ledger, under whatever redaction the run
|
|
342
|
+
* configured. An event stream is a fan-out to sinks we do not control, and
|
|
343
|
+
* a scrubbed value should not leave the run through it.
|
|
344
|
+
*/
|
|
345
|
+
export interface MiddlewareDecisionPayload {
|
|
346
|
+
readonly middleware: string;
|
|
347
|
+
readonly at: 'tool' | 'message';
|
|
348
|
+
readonly phase?: 'input' | 'output';
|
|
349
|
+
readonly toolName?: string;
|
|
350
|
+
readonly toolCallId?: string;
|
|
351
|
+
readonly iteration: number;
|
|
352
|
+
readonly outcome: 'allow' | 'deny' | 'ask';
|
|
353
|
+
/** True when this link changed the value the chain carries forward. */
|
|
354
|
+
readonly changed: boolean;
|
|
355
|
+
/** The transform's `why`, the denial's `reason`, or the ask's `question`. */
|
|
356
|
+
readonly why?: string;
|
|
357
|
+
}
|
|
332
358
|
export interface MemoryStrategyAppliedPayload {
|
|
333
359
|
readonly strategyId: string;
|
|
334
360
|
readonly strategyKind: 'sliding-window' | 'summarizing' | 'semantic' | 'fact-extraction' | 'hybrid';
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* major bump. See agentfootprint_v2_detailed_design.md for rules.
|
|
17
17
|
*/
|
|
18
18
|
import type { AgentfootprintEventEnvelope } from './types.js';
|
|
19
|
-
import type { AgentHandoffPayload, AgentIterationEndPayload, AgentIterationStartPayload, AgentRouteDecidedPayload, AgentTurnEndPayload, AgentTurnStartPayload, CompositionEnterPayload, CompositionExitPayload, ConditionalRouteDecidedPayload, ContextBudgetPressurePayload, ContextEvaluatedPayload, ContextEvictedPayload, ContextInjectedPayload, ContextSlotComposedPayload, CostLimitHitPayload, CostTickPayload, EmbeddingGeneratedPayload, ErrorFatalPayload, ErrorRecoveredPayload, ErrorRetriedPayload, EvalScorePayload, EvalThresholdCrossedPayload, AgentOutputSchemaValidationFailedPayload, AgentThinkingParseFailedPayload, StreamThinkingDeltaPayload, StreamThinkingEndPayload, FallbackTriggeredPayload, LLMEndPayload, LLMStartPayload, LLMTokenPayload, LoopIterationExitPayload, LoopIterationStartPayload, MemoryAttachedPayload, MemoryDetachedPayload, MemoryStrategyAppliedPayload, MemoryWrittenPayload, ParallelBranchCompletePayload, ParallelForkStartPayload, ParallelMergeEndPayload, PauseRequestPayload, PauseResumePayload, CheckInRequestPayload, CheckInDecisionPayload, PermissionCheckPayload, PermissionGateClosedPayload, PermissionHaltPayload, PermissionGateOpenedPayload, CredentialRequestedPayload, CredentialAcquiredPayload, CredentialAuthorizationRequiredPayload, CredentialFailedPayload, ReliabilityFailFastPayload, ReliabilityRetriedPayload, ReliabilityRecoveredPayload, RiskFlaggedPayload, SkillActivatedPayload, SkillDeactivatedPayload, SkillRejectedPayload, ToolEndPayload, ToolsActivatedPayload, ToolsDeactivatedPayload, ToolsDiscoveryStartedPayload, ToolsDiscoveryCompletedPayload, ToolsDiscoveryFailedPayload, ToolsOfferedPayload, ToolStartPayload, ValidationArgsInvalidPayload } from './payloads.js';
|
|
19
|
+
import type { AgentHandoffPayload, AgentIterationEndPayload, AgentIterationStartPayload, AgentRouteDecidedPayload, AgentTurnEndPayload, AgentTurnStartPayload, CompositionEnterPayload, CompositionExitPayload, ConditionalRouteDecidedPayload, ContextBudgetPressurePayload, ContextEvaluatedPayload, ContextEvictedPayload, ContextInjectedPayload, ContextSlotComposedPayload, CostLimitHitPayload, CostTickPayload, EmbeddingGeneratedPayload, ErrorFatalPayload, ErrorRecoveredPayload, ErrorRetriedPayload, EvalScorePayload, EvalThresholdCrossedPayload, AgentOutputSchemaValidationFailedPayload, AgentThinkingParseFailedPayload, StreamThinkingDeltaPayload, StreamThinkingEndPayload, FallbackTriggeredPayload, LLMEndPayload, LLMStartPayload, LLMTokenPayload, LoopIterationExitPayload, LoopIterationStartPayload, MemoryAttachedPayload, MemoryDetachedPayload, MemoryStrategyAppliedPayload, MemoryWrittenPayload, ParallelBranchCompletePayload, ParallelForkStartPayload, ParallelMergeEndPayload, PauseRequestPayload, PauseResumePayload, CheckInRequestPayload, CheckInDecisionPayload, PermissionCheckPayload, PermissionGateClosedPayload, PermissionHaltPayload, PermissionGateOpenedPayload, CredentialRequestedPayload, CredentialAcquiredPayload, CredentialAuthorizationRequiredPayload, CredentialFailedPayload, ReliabilityFailFastPayload, ReliabilityRetriedPayload, ReliabilityRecoveredPayload, RiskFlaggedPayload, SkillActivatedPayload, SkillDeactivatedPayload, SkillRejectedPayload, ToolEndPayload, ToolsActivatedPayload, ToolsDeactivatedPayload, ToolsDiscoveryStartedPayload, ToolsDiscoveryCompletedPayload, ToolsDiscoveryFailedPayload, ToolsOfferedPayload, ToolStartPayload, ValidationArgsInvalidPayload, MiddlewareDecisionPayload } from './payloads.js';
|
|
20
20
|
export declare const EVENT_NAMES: {
|
|
21
21
|
readonly composition: {
|
|
22
22
|
readonly enter: "agentfootprint.composition.enter";
|
|
@@ -120,6 +120,9 @@ export declare const EVENT_NAMES: {
|
|
|
120
120
|
readonly request: "agentfootprint.checkin.request";
|
|
121
121
|
readonly decision: "agentfootprint.checkin.decision";
|
|
122
122
|
};
|
|
123
|
+
readonly middleware: {
|
|
124
|
+
readonly decision: "agentfootprint.middleware.decision";
|
|
125
|
+
};
|
|
123
126
|
readonly embedding: {
|
|
124
127
|
readonly generated: "agentfootprint.embedding.generated";
|
|
125
128
|
};
|
|
@@ -191,6 +194,7 @@ export interface AgentfootprintEventMap {
|
|
|
191
194
|
'agentfootprint.pause.resume': AgentfootprintEventEnvelope<'agentfootprint.pause.resume', PauseResumePayload>;
|
|
192
195
|
'agentfootprint.checkin.request': AgentfootprintEventEnvelope<'agentfootprint.checkin.request', CheckInRequestPayload>;
|
|
193
196
|
'agentfootprint.checkin.decision': AgentfootprintEventEnvelope<'agentfootprint.checkin.decision', CheckInDecisionPayload>;
|
|
197
|
+
'agentfootprint.middleware.decision': AgentfootprintEventEnvelope<'agentfootprint.middleware.decision', MiddlewareDecisionPayload>;
|
|
194
198
|
'agentfootprint.embedding.generated': AgentfootprintEventEnvelope<'agentfootprint.embedding.generated', EmbeddingGeneratedPayload>;
|
|
195
199
|
}
|
|
196
200
|
/** Union of every typed event. Consumers use this for exhaustive `switch`. */
|
|
@@ -121,6 +121,9 @@ export const EVENT_NAMES = {
|
|
|
121
121
|
request: 'agentfootprint.checkin.request',
|
|
122
122
|
decision: 'agentfootprint.checkin.decision',
|
|
123
123
|
},
|
|
124
|
+
middleware: {
|
|
125
|
+
decision: 'agentfootprint.middleware.decision',
|
|
126
|
+
},
|
|
124
127
|
embedding: {
|
|
125
128
|
generated: 'agentfootprint.embedding.generated',
|
|
126
129
|
},
|
|
@@ -196,6 +199,7 @@ export const ALL_EVENT_TYPES = [
|
|
|
196
199
|
'agentfootprint.pause.resume',
|
|
197
200
|
'agentfootprint.checkin.request',
|
|
198
201
|
'agentfootprint.checkin.decision',
|
|
202
|
+
'agentfootprint.middleware.decision',
|
|
199
203
|
'agentfootprint.embedding.generated',
|
|
200
204
|
];
|
|
201
205
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/events/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/events/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA0EH,yEAAyE;AACzE,gEAAgE;AAChE,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,WAAW,EAAE;QACX,KAAK,EAAE,kCAAkC;QACzC,IAAI,EAAE,iCAAiC;QACvC,SAAS,EAAE,uCAAuC;QAClD,cAAc,EAAE,4CAA4C;QAC5D,QAAQ,EAAE,sCAAsC;QAChD,YA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A+B;IAC/B,6BAA6B;IAC7B,kCAAkC;IAClC,gCAAgC;IAChC,sCAAsC;IACtC,oCAAoC;IACpC,iCAAiC;IACjC,gCAAgC;IAChC,sCAAsC;IACtC,wCAAwC;IACxC,kCAAkC;IAClC,wCAAwC;IACxC,gCAAgC;IAChC,gCAAgC;IAChC,+BAA+B;IAC/B,8BAA8B;IAC9B,gCAAgC;IAChC,kCAAkC;IAClC,wCAAwC;IACxC,0CAA0C;IAC1C,uCAAuC;IACvC,wCAAwC;IACxC,gCAAgC;IAChC,kCAAkC;IAClC,+BAA+B;IAC/B,iCAAiC;IACjC,uCAAuC;IACvC,uCAAuC;IACvC,gCAAgC;IAChC,qCAAqC;IACrC,oCAAoC;IACpC,kDAAkD;IAClD,kCAAkC;IAClC,6BAA6B;IAC7B,mCAAmC;IACnC,0BAA0B;IAC1B,+BAA+B;IAC/B,2BAA2B;IAC3B,uCAAuC;IACvC,8BAA8B;IAC9B,gCAAgC;IAChC,4BAA4B;IAC5B,sCAAsC;IACtC,oCAAoC;IACpC,sCAAsC;IACtC,8BAA8B;IAC9B,6BAA6B;IAC7B,gCAAgC;IAChC,iCAAiC;IACjC,oCAAoC;IACpC,oCAAoC;CAC5B,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hosting/durability — how often a run's progress becomes crash-survivable.
|
|
3
|
+
*
|
|
4
|
+
* A standing agent that only writes at the end of a turn is one restart away
|
|
5
|
+
* from losing everything the turn had done: the tool calls it made, the results
|
|
6
|
+
* it read, the iterations it spent. This is the dial that decides how much of
|
|
7
|
+
* that survives, and what it costs.
|
|
8
|
+
*
|
|
9
|
+
* ── Where a mid-run write can honestly come from ─────────────────────────────
|
|
10
|
+
* From the COMMIT boundary, and nowhere else. footprintjs commits a stage's
|
|
11
|
+
* writes after the stage function returns, and committed state is
|
|
12
|
+
* immutable-after-swap — so `ScopeRecorder.onCommit` is the one moment where
|
|
13
|
+
* "what the run has agreed on so far" is a real, complete, consistent thing.
|
|
14
|
+
* Reading the agent's live state at any other moment would be reading a stage's
|
|
15
|
+
* work in progress.
|
|
16
|
+
*
|
|
17
|
+
* There is no mid-run engine checkpoint to store: footprintjs builds a
|
|
18
|
+
* `FlowchartCheckpoint` only at a pause (`getCheckpoint()` is documented as "the
|
|
19
|
+
* most recent PAUSED execution"). So what a mid-run write can carry is a
|
|
20
|
+
* CONVERSATION — the same `AgentRunCheckpoint` every finished turn stores — and
|
|
21
|
+
* that is exactly enough, because that is what the next turn resumes from.
|
|
22
|
+
*
|
|
23
|
+
* ── Why it writes on SOME commits and not all of them ────────────────────────
|
|
24
|
+
* A two-iteration turn commits about forty times. Exactly two of those commits
|
|
25
|
+
* change the conversation: `Initialize` (the user's message lands) and
|
|
26
|
+
* `ToolCalls` (an iteration's assistant turn and its tool results land). Every
|
|
27
|
+
* other commit would store bytes identical to the last write. So the trigger is
|
|
28
|
+
* "this commit wrote `history`", which is not an optimisation but the honest
|
|
29
|
+
* reading of the question: the conversation moved iff `history` moved.
|
|
30
|
+
*
|
|
31
|
+
* ── What a commit boundary actually guarantees, and what it does not ─────────
|
|
32
|
+
* It guarantees the whole stage. The agent dispatches ALL of one iteration's
|
|
33
|
+
* tool calls inside one stage body, so a crash part-way through that body stores
|
|
34
|
+
* nothing from it and a replay re-runs that iteration's tools. That is the
|
|
35
|
+
* shipped idempotency requirement, unchanged — mutating tools must be
|
|
36
|
+
* idempotent, keyed on stable call content rather than `ctx.toolCallId`. What
|
|
37
|
+
* `'sync'` adds is a BOUND on it: iteration N's tools do not start until
|
|
38
|
+
* iteration N-1's write has landed, so the replay is the current iteration and
|
|
39
|
+
* never an earlier one.
|
|
40
|
+
*
|
|
41
|
+
* Pattern: an observer (`CombinedRecorder`) for the snapshot, a serialiser for
|
|
42
|
+
* the writes, and — for `'sync'` only — a barrier the tool dispatch waits on.
|
|
43
|
+
* Role: internal to `standingAgent`. Deliberately not exported: it is how the
|
|
44
|
+
* composer keeps its promise, not a second way to write to a store.
|
|
45
|
+
*/
|
|
46
|
+
import type { CombinedRecorder } from 'footprintjs';
|
|
47
|
+
import type { AgentRunCheckpoint } from '../core/runCheckpoint.js';
|
|
48
|
+
import type { DurabilityMode } from './types.js';
|
|
49
|
+
/** What the writer needs from the composer around it. */
|
|
50
|
+
export interface DurableWriterOptions {
|
|
51
|
+
/** `'async'` or `'sync'`. `'exit'` never builds a writer at all. */
|
|
52
|
+
readonly mode: Exclude<DurabilityMode, 'exit'>;
|
|
53
|
+
/**
|
|
54
|
+
* The session this run belongs to, asked at every commit. `undefined` means
|
|
55
|
+
* "nothing to write to" — an anonymous request, or no run of ours in flight —
|
|
56
|
+
* and the commit is ignored.
|
|
57
|
+
*/
|
|
58
|
+
readonly session: () => string | undefined;
|
|
59
|
+
/** The run id to stamp on the conversation, for correlating back to the run. */
|
|
60
|
+
readonly runId: () => string | undefined;
|
|
61
|
+
/** Where the conversation goes. */
|
|
62
|
+
readonly write: (sessionId: string, conversation: AgentRunCheckpoint) => Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
/** The composer's handle on its own durability. */
|
|
65
|
+
export interface DurableWriter {
|
|
66
|
+
/** Attach this to the agent to start observing commits. */
|
|
67
|
+
readonly recorder: CombinedRecorder;
|
|
68
|
+
/** Install the tool-dispatch barrier. Returns the uninstall function. */
|
|
69
|
+
install(agent: object): () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Everything outstanding has landed.
|
|
72
|
+
*
|
|
73
|
+
* The composer awaits this before writing a run's FINAL envelope, and that
|
|
74
|
+
* ordering is load-bearing rather than tidy: an `'async'` conversation write
|
|
75
|
+
* still in flight would otherwise land AFTER the terminal envelope and
|
|
76
|
+
* overwrite it — turning a stored pause back into a plain conversation and
|
|
77
|
+
* losing the question a person was asked.
|
|
78
|
+
*
|
|
79
|
+
* **Rejects when the newest write did not land.** Fail-closed on purpose: a
|
|
80
|
+
* store that refused the run's progress has not made it durable, and both
|
|
81
|
+
* things waiting on this — the next tool call under `'sync'`, and the reply —
|
|
82
|
+
* would otherwise proceed on a promise nobody kept.
|
|
83
|
+
*/
|
|
84
|
+
settle(): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Build the writer.
|
|
88
|
+
*
|
|
89
|
+
* Under `'sync'` it also answers the tool-dispatch barrier, which is what turns
|
|
90
|
+
* "we write often" into a bound on how much can re-run.
|
|
91
|
+
*/
|
|
92
|
+
export declare function durableWriter(options: DurableWriterOptions): DurableWriter;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hosting/durability — how often a run's progress becomes crash-survivable.
|
|
3
|
+
*
|
|
4
|
+
* A standing agent that only writes at the end of a turn is one restart away
|
|
5
|
+
* from losing everything the turn had done: the tool calls it made, the results
|
|
6
|
+
* it read, the iterations it spent. This is the dial that decides how much of
|
|
7
|
+
* that survives, and what it costs.
|
|
8
|
+
*
|
|
9
|
+
* ── Where a mid-run write can honestly come from ─────────────────────────────
|
|
10
|
+
* From the COMMIT boundary, and nowhere else. footprintjs commits a stage's
|
|
11
|
+
* writes after the stage function returns, and committed state is
|
|
12
|
+
* immutable-after-swap — so `ScopeRecorder.onCommit` is the one moment where
|
|
13
|
+
* "what the run has agreed on so far" is a real, complete, consistent thing.
|
|
14
|
+
* Reading the agent's live state at any other moment would be reading a stage's
|
|
15
|
+
* work in progress.
|
|
16
|
+
*
|
|
17
|
+
* There is no mid-run engine checkpoint to store: footprintjs builds a
|
|
18
|
+
* `FlowchartCheckpoint` only at a pause (`getCheckpoint()` is documented as "the
|
|
19
|
+
* most recent PAUSED execution"). So what a mid-run write can carry is a
|
|
20
|
+
* CONVERSATION — the same `AgentRunCheckpoint` every finished turn stores — and
|
|
21
|
+
* that is exactly enough, because that is what the next turn resumes from.
|
|
22
|
+
*
|
|
23
|
+
* ── Why it writes on SOME commits and not all of them ────────────────────────
|
|
24
|
+
* A two-iteration turn commits about forty times. Exactly two of those commits
|
|
25
|
+
* change the conversation: `Initialize` (the user's message lands) and
|
|
26
|
+
* `ToolCalls` (an iteration's assistant turn and its tool results land). Every
|
|
27
|
+
* other commit would store bytes identical to the last write. So the trigger is
|
|
28
|
+
* "this commit wrote `history`", which is not an optimisation but the honest
|
|
29
|
+
* reading of the question: the conversation moved iff `history` moved.
|
|
30
|
+
*
|
|
31
|
+
* ── What a commit boundary actually guarantees, and what it does not ─────────
|
|
32
|
+
* It guarantees the whole stage. The agent dispatches ALL of one iteration's
|
|
33
|
+
* tool calls inside one stage body, so a crash part-way through that body stores
|
|
34
|
+
* nothing from it and a replay re-runs that iteration's tools. That is the
|
|
35
|
+
* shipped idempotency requirement, unchanged — mutating tools must be
|
|
36
|
+
* idempotent, keyed on stable call content rather than `ctx.toolCallId`. What
|
|
37
|
+
* `'sync'` adds is a BOUND on it: iteration N's tools do not start until
|
|
38
|
+
* iteration N-1's write has landed, so the replay is the current iteration and
|
|
39
|
+
* never an earlier one.
|
|
40
|
+
*
|
|
41
|
+
* Pattern: an observer (`CombinedRecorder`) for the snapshot, a serialiser for
|
|
42
|
+
* the writes, and — for `'sync'` only — a barrier the tool dispatch waits on.
|
|
43
|
+
* Role: internal to `standingAgent`. Deliberately not exported: it is how the
|
|
44
|
+
* composer keeps its promise, not a second way to write to a store.
|
|
45
|
+
*/
|
|
46
|
+
import { installDurabilityBarrier } from '../core/durabilityBarrier.js';
|
|
47
|
+
/**
|
|
48
|
+
* Build the writer.
|
|
49
|
+
*
|
|
50
|
+
* Under `'sync'` it also answers the tool-dispatch barrier, which is what turns
|
|
51
|
+
* "we write often" into a bound on how much can re-run.
|
|
52
|
+
*/
|
|
53
|
+
export function durableWriter(options) {
|
|
54
|
+
const { mode, session, runId, write } = options;
|
|
55
|
+
/** The write currently on the wire, or `undefined` when nothing is. */
|
|
56
|
+
let inFlight;
|
|
57
|
+
/**
|
|
58
|
+
* The newest snapshot that has not been started yet. At most ONE, and a newer
|
|
59
|
+
* one replaces it: the conversation only grows, so a superseded snapshot is a
|
|
60
|
+
* prefix of the one replacing it and writing it first would buy nothing.
|
|
61
|
+
*/
|
|
62
|
+
let queued;
|
|
63
|
+
/**
|
|
64
|
+
* Why the NEWEST write did not land, or `undefined` when it did. Cleared by a
|
|
65
|
+
* write that succeeds — a store that failed once and then took the newer
|
|
66
|
+
* state has made that state durable, and reporting the older failure would be
|
|
67
|
+
* describing a problem that no longer exists.
|
|
68
|
+
*/
|
|
69
|
+
let failure;
|
|
70
|
+
/** Per-run accumulation, rebuilt from the commits themselves. */
|
|
71
|
+
let history = [];
|
|
72
|
+
let userMessage = '';
|
|
73
|
+
let iteration = 0;
|
|
74
|
+
function pump() {
|
|
75
|
+
if (inFlight !== undefined || queued === undefined)
|
|
76
|
+
return;
|
|
77
|
+
const next = queued;
|
|
78
|
+
queued = undefined;
|
|
79
|
+
inFlight = write(next.sessionId, next.conversation)
|
|
80
|
+
.then(() => {
|
|
81
|
+
failure = undefined;
|
|
82
|
+
}, (err) => {
|
|
83
|
+
failure = new Error(`[hosting] the session store did not accept this run's progress, so nothing ` +
|
|
84
|
+
`after this point may proceed as if it had` +
|
|
85
|
+
(mode === 'sync' ? ` — the next tool call was not allowed to run` : '') +
|
|
86
|
+
`. Underlying error: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
87
|
+
})
|
|
88
|
+
.then(() => {
|
|
89
|
+
inFlight = undefined;
|
|
90
|
+
pump();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function enqueue(sessionId) {
|
|
94
|
+
queued = {
|
|
95
|
+
sessionId,
|
|
96
|
+
conversation: {
|
|
97
|
+
version: 1,
|
|
98
|
+
runId: runId() ?? 'unknown',
|
|
99
|
+
// The commit event hands over the stage's retained write view. Clone on
|
|
100
|
+
// the way to a store so nothing a persistence layer does can reach back
|
|
101
|
+
// into the run's own snapshot.
|
|
102
|
+
history: structuredClone(history),
|
|
103
|
+
lastCompletedIteration: iteration,
|
|
104
|
+
originalInput: { message: userMessage },
|
|
105
|
+
checkpointedAt: Date.now(),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
pump();
|
|
109
|
+
}
|
|
110
|
+
const recorder = {
|
|
111
|
+
id: 'af-hosting-durability',
|
|
112
|
+
// INLINE, always. A write delivered one beat behind is a write that can be
|
|
113
|
+
// lost by the very crash it exists to survive — and under `'sync'` the
|
|
114
|
+
// barrier would be waiting on a snapshot the queue had not handed over yet.
|
|
115
|
+
// The causal-evidence bridge and the compaction meter are inline for the
|
|
116
|
+
// same class of reason.
|
|
117
|
+
delivery: 'inline',
|
|
118
|
+
onCommit(event) {
|
|
119
|
+
let conversationMoved = false;
|
|
120
|
+
for (const mutation of event.mutations) {
|
|
121
|
+
if (mutation.key === 'history' && Array.isArray(mutation.value)) {
|
|
122
|
+
history = mutation.value;
|
|
123
|
+
conversationMoved = true;
|
|
124
|
+
}
|
|
125
|
+
else if (mutation.key === 'userMessage' && typeof mutation.value === 'string') {
|
|
126
|
+
userMessage = mutation.value;
|
|
127
|
+
}
|
|
128
|
+
else if (mutation.key === 'iteration' && typeof mutation.value === 'number') {
|
|
129
|
+
iteration = mutation.value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!conversationMoved)
|
|
133
|
+
return;
|
|
134
|
+
const sessionId = session();
|
|
135
|
+
if (sessionId === undefined)
|
|
136
|
+
return;
|
|
137
|
+
enqueue(sessionId);
|
|
138
|
+
},
|
|
139
|
+
// A fresh run starts from a fresh conversation. Without this a resumed run
|
|
140
|
+
// whose first commit has not landed yet could stamp the previous run's
|
|
141
|
+
// history onto this run's id.
|
|
142
|
+
clear() {
|
|
143
|
+
history = [];
|
|
144
|
+
userMessage = '';
|
|
145
|
+
iteration = 0;
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
const settle = async () => {
|
|
149
|
+
// Loop rather than await once: a write that completes may release a queued
|
|
150
|
+
// successor, and "settled" has to mean nothing is left.
|
|
151
|
+
while (inFlight !== undefined || queued !== undefined) {
|
|
152
|
+
pump();
|
|
153
|
+
await inFlight;
|
|
154
|
+
}
|
|
155
|
+
if (failure)
|
|
156
|
+
throw failure;
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
recorder,
|
|
160
|
+
install(agent) {
|
|
161
|
+
// `'async'` deliberately takes NO barrier: its whole promise is that the
|
|
162
|
+
// run does not wait, and a barrier would be that promise broken quietly.
|
|
163
|
+
if (mode !== 'sync')
|
|
164
|
+
return () => undefined;
|
|
165
|
+
return installDurabilityBarrier(agent, () => {
|
|
166
|
+
if (inFlight === undefined && queued === undefined && failure === undefined)
|
|
167
|
+
return undefined;
|
|
168
|
+
return settle();
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
settle,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=durability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durability.js","sourceRoot":"","sources":["../../../src/hosting/durability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAIH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AA4CxE;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAEhD,uEAAuE;IACvE,IAAI,QAAmC,CAAC;IACxC;;;;OAIG;IACH,IAAI,MAA2E,CAAC;IAChF;;;;;OAKG;IACH,IAAI,OAA0B,CAAC;IAE/B,iEAAiE;IACjE,IAAI,OAAO,GAA0B,EAAE,CAAC;IACxC,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,SAAS,IAAI;QACX,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO;QAC3D,MAAM,IAAI,GAAG,MAAM,CAAC;QACpB,MAAM,GAAG,SAAS,CAAC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