agentfootprint 7.16.0 → 7.18.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/conventions.js +8 -6
- package/dist/conventions.js.map +1 -1
- package/dist/core/Agent.js +81 -27
- 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 +209 -43
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +8 -8
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +6 -6
- package/dist/core/agent/buildDynamicAgentChart.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 +195 -8
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/agent/stages/window.js +141 -0
- package/dist/core/agent/stages/window.js.map +1 -0
- package/dist/core/agent/window/errors.js.map +1 -0
- package/dist/core/agent/window/index.js +36 -0
- package/dist/core/agent/window/index.js.map +1 -0
- package/dist/core/agent/window/notice.js +57 -0
- package/dist/core/agent/window/notice.js.map +1 -0
- package/dist/core/agent/window/options.js +93 -0
- package/dist/core/agent/window/options.js.map +1 -0
- package/dist/core/agent/window/removal.js +45 -0
- package/dist/core/agent/window/removal.js.map +1 -0
- package/dist/core/agent/window/strategies/drop.js +106 -0
- package/dist/core/agent/window/strategies/drop.js.map +1 -0
- package/dist/core/agent/window/strategies/slidingWindow.js +87 -0
- package/dist/core/agent/window/strategies/slidingWindow.js.map +1 -0
- package/dist/core/agent/window/strategies/summarizeOldest.js +178 -0
- package/dist/core/agent/window/strategies/summarizeOldest.js.map +1 -0
- package/dist/core/agent/window/strategies/tokenBudget.js +95 -0
- package/dist/core/agent/window/strategies/tokenBudget.js.map +1 -0
- package/dist/core/agent/window/strategy.js +42 -0
- package/dist/core/agent/window/strategy.js.map +1 -0
- package/dist/core/agent/window/summarize.js.map +1 -0
- package/dist/core/agent/{compaction → window}/turns.js +50 -28
- package/dist/core/agent/window/turns.js.map +1 -0
- package/dist/core/agent/window/types.js +23 -0
- package/dist/core/agent/window/types.js.map +1 -0
- package/dist/core/pause.js +19 -1
- package/dist/core/pause.js.map +1 -1
- package/dist/esm/conventions.d.ts +8 -6
- package/dist/esm/conventions.js +8 -6
- package/dist/esm/conventions.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +14 -6
- package/dist/esm/core/Agent.js +82 -28
- 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 +157 -4
- package/dist/esm/core/agent/AgentBuilder.js +209 -43
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.d.ts +16 -9
- package/dist/esm/core/agent/buildAgentChart.js +8 -8
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +6 -6
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- 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 +23 -0
- package/dist/esm/core/agent/stages/toolCalls.js +195 -8
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/agent/stages/window.d.ts +63 -0
- package/dist/esm/core/agent/stages/window.js +137 -0
- package/dist/esm/core/agent/stages/window.js.map +1 -0
- package/dist/esm/core/agent/types.d.ts +33 -8
- package/dist/esm/core/agent/window/errors.js.map +1 -0
- package/dist/esm/core/agent/window/index.d.ts +27 -0
- package/dist/esm/core/agent/window/index.js +25 -0
- package/dist/esm/core/agent/window/index.js.map +1 -0
- package/dist/esm/core/agent/window/notice.d.ts +46 -0
- package/dist/esm/core/agent/window/notice.js +52 -0
- package/dist/esm/core/agent/window/notice.js.map +1 -0
- package/dist/esm/core/agent/window/options.d.ts +33 -0
- package/dist/esm/core/agent/window/options.js +87 -0
- package/dist/esm/core/agent/window/options.js.map +1 -0
- package/dist/esm/core/agent/window/removal.d.ts +22 -0
- package/dist/esm/core/agent/window/removal.js +40 -0
- package/dist/esm/core/agent/window/removal.js.map +1 -0
- package/dist/esm/core/agent/window/strategies/drop.d.ts +54 -0
- package/dist/esm/core/agent/window/strategies/drop.js +102 -0
- package/dist/esm/core/agent/window/strategies/drop.js.map +1 -0
- package/dist/esm/core/agent/window/strategies/slidingWindow.d.ts +48 -0
- package/dist/esm/core/agent/window/strategies/slidingWindow.js +83 -0
- package/dist/esm/core/agent/window/strategies/slidingWindow.js.map +1 -0
- package/dist/esm/core/agent/window/strategies/summarizeOldest.d.ts +42 -0
- package/dist/esm/core/agent/window/strategies/summarizeOldest.js +174 -0
- package/dist/esm/core/agent/window/strategies/summarizeOldest.js.map +1 -0
- package/dist/esm/core/agent/window/strategies/tokenBudget.d.ts +47 -0
- package/dist/esm/core/agent/window/strategies/tokenBudget.js +91 -0
- package/dist/esm/core/agent/window/strategies/tokenBudget.js.map +1 -0
- package/dist/esm/core/agent/window/strategy.d.ts +181 -0
- package/dist/esm/core/agent/window/strategy.js +41 -0
- package/dist/esm/core/agent/window/strategy.js.map +1 -0
- package/dist/esm/core/agent/window/summarize.js.map +1 -0
- package/dist/esm/core/agent/window/turns.d.ts +108 -0
- package/dist/esm/core/agent/{compaction → window}/turns.js +48 -26
- package/dist/esm/core/agent/window/turns.js.map +1 -0
- package/dist/esm/core/agent/window/types.d.ts +263 -0
- package/dist/esm/core/agent/window/types.js +22 -0
- package/dist/esm/core/agent/window/types.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/index.d.ts +3 -2
- package/dist/esm/index.js +23 -6
- 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/esm/recorders/core/CompactionMeter.d.ts +25 -19
- package/dist/esm/recorders/core/CompactionMeter.js +27 -19
- package/dist/esm/recorders/core/CompactionMeter.js.map +1 -1
- 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/index.js +40 -13
- 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/recorders/core/CompactionMeter.js +27 -19
- package/dist/recorders/core/CompactionMeter.js.map +1 -1
- package/dist/types/conventions.d.ts +8 -6
- package/dist/types/conventions.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +14 -6
- 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 +157 -4
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts +16 -9
- 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 +23 -0
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/agent/stages/window.d.ts +64 -0
- package/dist/types/core/agent/stages/window.d.ts.map +1 -0
- package/dist/types/core/agent/types.d.ts +33 -8
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/agent/window/errors.d.ts.map +1 -0
- package/dist/types/core/agent/window/index.d.ts +28 -0
- package/dist/types/core/agent/window/index.d.ts.map +1 -0
- package/dist/types/core/agent/window/notice.d.ts +47 -0
- package/dist/types/core/agent/window/notice.d.ts.map +1 -0
- package/dist/types/core/agent/window/options.d.ts +34 -0
- package/dist/types/core/agent/window/options.d.ts.map +1 -0
- package/dist/types/core/agent/window/removal.d.ts +23 -0
- package/dist/types/core/agent/window/removal.d.ts.map +1 -0
- package/dist/types/core/agent/window/strategies/drop.d.ts +55 -0
- package/dist/types/core/agent/window/strategies/drop.d.ts.map +1 -0
- package/dist/types/core/agent/window/strategies/slidingWindow.d.ts +49 -0
- package/dist/types/core/agent/window/strategies/slidingWindow.d.ts.map +1 -0
- package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts +43 -0
- package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts.map +1 -0
- package/dist/types/core/agent/window/strategies/tokenBudget.d.ts +48 -0
- package/dist/types/core/agent/window/strategies/tokenBudget.d.ts.map +1 -0
- package/dist/types/core/agent/window/strategy.d.ts +182 -0
- package/dist/types/core/agent/window/strategy.d.ts.map +1 -0
- package/dist/types/core/agent/window/summarize.d.ts.map +1 -0
- package/dist/types/core/agent/window/turns.d.ts +109 -0
- package/dist/types/core/agent/window/turns.d.ts.map +1 -0
- package/dist/types/core/agent/window/types.d.ts +264 -0
- package/dist/types/core/agent/window/types.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/index.d.ts +3 -2
- 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/dist/types/recorders/core/CompactionMeter.d.ts +25 -19
- package/dist/types/recorders/core/CompactionMeter.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/core/agent/compaction/errors.js.map +0 -1
- package/dist/core/agent/compaction/index.js +0 -24
- package/dist/core/agent/compaction/index.js.map +0 -1
- package/dist/core/agent/compaction/strategy.js +0 -152
- package/dist/core/agent/compaction/strategy.js.map +0 -1
- package/dist/core/agent/compaction/summarize.js.map +0 -1
- package/dist/core/agent/compaction/turns.js.map +0 -1
- package/dist/core/agent/compaction/types.js +0 -21
- package/dist/core/agent/compaction/types.js.map +0 -1
- package/dist/core/agent/stages/compact.js +0 -130
- package/dist/core/agent/stages/compact.js.map +0 -1
- package/dist/esm/core/agent/compaction/errors.js.map +0 -1
- package/dist/esm/core/agent/compaction/index.d.ts +0 -18
- package/dist/esm/core/agent/compaction/index.js +0 -18
- package/dist/esm/core/agent/compaction/index.js.map +0 -1
- package/dist/esm/core/agent/compaction/strategy.d.ts +0 -103
- package/dist/esm/core/agent/compaction/strategy.js +0 -148
- package/dist/esm/core/agent/compaction/strategy.js.map +0 -1
- package/dist/esm/core/agent/compaction/summarize.js.map +0 -1
- package/dist/esm/core/agent/compaction/turns.d.ts +0 -85
- package/dist/esm/core/agent/compaction/turns.js.map +0 -1
- package/dist/esm/core/agent/compaction/types.d.ts +0 -148
- package/dist/esm/core/agent/compaction/types.js +0 -20
- package/dist/esm/core/agent/compaction/types.js.map +0 -1
- package/dist/esm/core/agent/stages/compact.d.ts +0 -59
- package/dist/esm/core/agent/stages/compact.js +0 -126
- package/dist/esm/core/agent/stages/compact.js.map +0 -1
- package/dist/types/core/agent/compaction/errors.d.ts.map +0 -1
- package/dist/types/core/agent/compaction/index.d.ts +0 -19
- package/dist/types/core/agent/compaction/index.d.ts.map +0 -1
- package/dist/types/core/agent/compaction/strategy.d.ts +0 -104
- package/dist/types/core/agent/compaction/strategy.d.ts.map +0 -1
- package/dist/types/core/agent/compaction/summarize.d.ts.map +0 -1
- package/dist/types/core/agent/compaction/turns.d.ts +0 -86
- package/dist/types/core/agent/compaction/turns.d.ts.map +0 -1
- package/dist/types/core/agent/compaction/types.d.ts +0 -149
- package/dist/types/core/agent/compaction/types.d.ts.map +0 -1
- package/dist/types/core/agent/stages/compact.d.ts +0 -60
- package/dist/types/core/agent/stages/compact.d.ts.map +0 -1
- /package/dist/core/agent/{compaction → window}/errors.js +0 -0
- /package/dist/core/agent/{compaction → window}/summarize.js +0 -0
- /package/dist/esm/core/agent/{compaction → window}/errors.d.ts +0 -0
- /package/dist/esm/core/agent/{compaction → window}/errors.js +0 -0
- /package/dist/esm/core/agent/{compaction → window}/summarize.d.ts +0 -0
- /package/dist/esm/core/agent/{compaction → window}/summarize.js +0 -0
- /package/dist/types/core/agent/{compaction → window}/errors.d.ts +0 -0
- /package/dist/types/core/agent/{compaction → window}/summarize.d.ts +0 -0
|
@@ -20,7 +20,9 @@ import type { ToolProvider } from '../../tool-providers/types.js';
|
|
|
20
20
|
import { type SelfExplainOptions } from '../../lib/trace-toolpack/selfExplain.js';
|
|
21
21
|
import { Agent } from '../Agent.js';
|
|
22
22
|
import type { AgentOptions, RunConfigFn } from './types.js';
|
|
23
|
-
import type { CompactionOptions } from './
|
|
23
|
+
import type { CompactionOptions } from './window/types.js';
|
|
24
|
+
import type { WindowStrategy } from './window/strategy.js';
|
|
25
|
+
import type { MessageMiddleware, ToolMiddleware } from './middleware/types.js';
|
|
24
26
|
/**
|
|
25
27
|
* Fluent builder. `tool()` accepts any Tool<TArgs, TResult> and registers
|
|
26
28
|
* it by its schema.name. Duplicate names throw at build time.
|
|
@@ -125,9 +127,14 @@ export declare class AgentBuilder {
|
|
|
125
127
|
/** Per-run config resolver set via `.configure()`. Undefined = the agent
|
|
126
128
|
* runs on its build-time model + system prompt, unchanged. */
|
|
127
129
|
private runConfigFn?;
|
|
128
|
-
/**
|
|
129
|
-
* the ReAct loop target is unchanged,
|
|
130
|
-
|
|
130
|
+
/** The agent's one window strategy, from `.window()` or `.compaction()`.
|
|
131
|
+
* Undefined = no window stage exists, the ReAct loop target is unchanged,
|
|
132
|
+
* and the run is byte-identical to an agent that never heard of them. */
|
|
133
|
+
private windowStrategyValue?;
|
|
134
|
+
/** The tool-dispatch chain, in call order. Empty = no chain, no ledger. */
|
|
135
|
+
private toolMiddlewareList;
|
|
136
|
+
/** The message chain, in call order. Empty = no chain, no ledger. */
|
|
137
|
+
private messageMiddlewareList;
|
|
131
138
|
constructor(opts: AgentOptions);
|
|
132
139
|
/**
|
|
133
140
|
* Set the base system prompt.
|
|
@@ -234,10 +241,58 @@ export declare class AgentBuilder {
|
|
|
234
241
|
* .build();
|
|
235
242
|
*/
|
|
236
243
|
configure(fn: RunConfigFn): this;
|
|
244
|
+
/**
|
|
245
|
+
* Choose how the live context window is kept inside its budget.
|
|
246
|
+
*
|
|
247
|
+
* This is the general door; the strategy decides everything about WHEN it
|
|
248
|
+
* acts and WHAT leaves. Three ship, and they share one turn segmentation
|
|
249
|
+
* and one refusal engine, so a refusal reason means the same thing under
|
|
250
|
+
* all of them:
|
|
251
|
+
*
|
|
252
|
+
* `summarizeOldest({ thresholdTokens, summarizer, ... })`
|
|
253
|
+
* fold the oldest span into one summary message. `.compaction()` is
|
|
254
|
+
* this, spelled shorter.
|
|
255
|
+
* `slidingWindow({ keepRecentTurns })`
|
|
256
|
+
* keep the last N turns and drop older ones. No summarizer, no LLM
|
|
257
|
+
* call, no usage requirement — it runs on any provider.
|
|
258
|
+
* `tokenBudget({ thresholdTokens })`
|
|
259
|
+
* the counted-token trigger, dropping instead of summarizing.
|
|
260
|
+
*
|
|
261
|
+
* Never removed by any of them: the system envelope, the recent turns, and
|
|
262
|
+
* any turn holding something unresolved — an unanswered tool call, a paused
|
|
263
|
+
* tool, a pending check-in. Those refuse BY NAME in the record and the
|
|
264
|
+
* strategy takes the next oldest instead. Removing an unanswered question
|
|
265
|
+
* would destroy the referent of the answer that has not arrived yet, and
|
|
266
|
+
* splitting a `tool_use` from its `tool_result` produces a request the
|
|
267
|
+
* vendor rejects.
|
|
268
|
+
*
|
|
269
|
+
* **Whatever leaves the window stays in the ledger.** footprintjs's commit
|
|
270
|
+
* log is append-only, so the turns were committed before the strategy ran
|
|
271
|
+
* and remain byte-identical; every strategy files its own recorded step
|
|
272
|
+
* naming the `runtimeStageId`s whose messages left, and emits one
|
|
273
|
+
* `context.evicted` per message. Removing is not forgetting.
|
|
274
|
+
*
|
|
275
|
+
* Exactly one strategy per agent. Omit this (and `.compaction()`) and
|
|
276
|
+
* nothing changes: no stage, no extra committed key, the same request bytes.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* import { Agent, slidingWindow } from 'agentfootprint';
|
|
281
|
+
*
|
|
282
|
+
* const agent = Agent.create({ provider, model })
|
|
283
|
+
* .window(slidingWindow({ keepRecentTurns: 12 }))
|
|
284
|
+
* .build();
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
window(strategy: WindowStrategy): this;
|
|
237
288
|
/**
|
|
238
289
|
* Keep the live context window inside a token budget — without ever losing
|
|
239
290
|
* the record.
|
|
240
291
|
*
|
|
292
|
+
* Sugar for `.window(summarizeOldest(options))`, and byte-for-byte the same
|
|
293
|
+
* agent. It keeps its own name because compaction is what the market calls
|
|
294
|
+
* this and it is the strategy most people want first.
|
|
295
|
+
*
|
|
241
296
|
* At each ReAct iteration boundary, compaction compares the LAST call's
|
|
242
297
|
* **adapter-reported** input tokens against `thresholdTokens`. Over budget,
|
|
243
298
|
* it folds the oldest foldable span of the conversation into one summary
|
|
@@ -273,6 +328,12 @@ export declare class AgentBuilder {
|
|
|
273
328
|
* ```
|
|
274
329
|
*/
|
|
275
330
|
compaction(options: CompactionOptions): this;
|
|
331
|
+
/**
|
|
332
|
+
* One window strategy per agent, whichever door set it — a second would
|
|
333
|
+
* silently override the first, and a window policy that quietly changed is
|
|
334
|
+
* a policy you cannot audit.
|
|
335
|
+
*/
|
|
336
|
+
private assertNoWindowStrategy;
|
|
276
337
|
/**
|
|
277
338
|
* Override the ReAct iteration cap set via `Agent.create({
|
|
278
339
|
* maxIterations })`. Convenience for builder-style code that prefers
|
|
@@ -676,6 +737,98 @@ export declare class AgentBuilder {
|
|
|
676
737
|
* .checkIn({ evidence: 'standard' })
|
|
677
738
|
* .build();
|
|
678
739
|
*/
|
|
740
|
+
/**
|
|
741
|
+
* Wrap every tool dispatch in a governance chain.
|
|
742
|
+
*
|
|
743
|
+
* Each middleware answers with one of three verbs — `allow()`, `deny(reason)`
|
|
744
|
+
* or `ask({ question })` — and there is deliberately no fourth. In
|
|
745
|
+
* particular there is no way to return a result: whatever the chain decides,
|
|
746
|
+
* the answer the model finally reads is the real tool's output or a refusal.
|
|
747
|
+
* A rule cannot quietly become the tool.
|
|
748
|
+
*
|
|
749
|
+
* - **`allow()`** passes the call through. **`allow(args, why)`** replaces
|
|
750
|
+
* the args and the run commits BOTH versions with your `why` beside them,
|
|
751
|
+
* so a slice taken later can find the moment they changed and who changed
|
|
752
|
+
* them.
|
|
753
|
+
* - **`deny(reason)`** refuses. The reason reaches the model verbatim, as
|
|
754
|
+
* the tool result, and the loop continues — the agent adapts in-flight. A
|
|
755
|
+
* denial is data, not a crash.
|
|
756
|
+
* - **`ask({ question })`** suspends the run for a person, on the same
|
|
757
|
+
* checkpoint machinery `checkIn` and `askHuman` use. The answer is a
|
|
758
|
+
* DECISION, not a result: approve and the chain resumes and the real tool
|
|
759
|
+
* runs; decline and it becomes a denial the model reads.
|
|
760
|
+
*
|
|
761
|
+
* Order is call order, and each middleware sees the previous one's output.
|
|
762
|
+
* The first non-allow answer wins and the rest of the chain does not run. A
|
|
763
|
+
* middleware that throws is a denial carrying the error as its reason —
|
|
764
|
+
* never a silent pass.
|
|
765
|
+
*
|
|
766
|
+
* An existing `PermissionChecker` still decides FIRST: it is not part of
|
|
767
|
+
* this chain, it runs ahead of it, so a call it denies never reaches a
|
|
768
|
+
* middleware. `gatedTools` is a different layer again — it decides which
|
|
769
|
+
* tools the model can SEE; this decides what happens when one is called.
|
|
770
|
+
*
|
|
771
|
+
* Omit this and nothing changes: no chain walk, no committed ledger key, the
|
|
772
|
+
* same request bytes.
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```ts
|
|
776
|
+
* import { Agent, allow, deny } from 'agentfootprint';
|
|
777
|
+
*
|
|
778
|
+
* const agent = Agent.create({ provider, model })
|
|
779
|
+
* .toolMiddleware({
|
|
780
|
+
* name: 'no-prod-writes',
|
|
781
|
+
* onToolCall: (call) =>
|
|
782
|
+
* call.args.env === 'prod' ? deny('writes to prod need a change ticket') : allow(),
|
|
783
|
+
* })
|
|
784
|
+
* .build();
|
|
785
|
+
* ```
|
|
786
|
+
*/
|
|
787
|
+
toolMiddleware(...middleware: readonly ToolMiddleware[]): this;
|
|
788
|
+
/**
|
|
789
|
+
* Wrap the message boundary in a governance chain — the input before the
|
|
790
|
+
* model sees it, the output before the caller receives it.
|
|
791
|
+
*
|
|
792
|
+
* Same verbs as {@link toolMiddleware} minus one: there is no `ask` here,
|
|
793
|
+
* and the type says so. Tool dispatch runs inside a pausable stage, so it
|
|
794
|
+
* has a checkpoint to suspend on; the message boundary is a plain stage, and
|
|
795
|
+
* inventing a second pause to give it one would be a worse answer than not
|
|
796
|
+
* offering it.
|
|
797
|
+
*
|
|
798
|
+
* The `'input'` half runs at the very top of the run, BEFORE the message is
|
|
799
|
+
* committed. That placement is the point: everything downstream reads
|
|
800
|
+
* `scope.history` — the window strategies, the injections, all three slots,
|
|
801
|
+
* the bytes on the wire and every slice taken afterwards — so the
|
|
802
|
+
* transformed text is what the whole run agrees was said. The `'output'`
|
|
803
|
+
* half runs where the final answer is captured, so the record and the caller
|
|
804
|
+
* receive the same string.
|
|
805
|
+
*
|
|
806
|
+
* `deny(reason)` at either phase raises a `MessageDeniedError` rather than
|
|
807
|
+
* returning. At `'input'` there is no model to tell; at `'output'` the
|
|
808
|
+
* middleware has just refused to release an answer, and handing the caller a
|
|
809
|
+
* string in its place is the one substitution they must never make without
|
|
810
|
+
* noticing. The error carries the reason, the phase and the middleware's
|
|
811
|
+
* name — never the refused content.
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```ts
|
|
815
|
+
* import { Agent, allow } from 'agentfootprint';
|
|
816
|
+
*
|
|
817
|
+
* const agent = Agent.create({ provider, model })
|
|
818
|
+
* .messageMiddleware({
|
|
819
|
+
* name: 'mask-card-numbers',
|
|
820
|
+
* onMessage: (msg) => {
|
|
821
|
+
* const clean = msg.content.replace(/\b(?:\d[ -]?){13,16}\b/g, '[card]');
|
|
822
|
+
* return clean === msg.content ? allow() : allow(clean, 'masked a card number');
|
|
823
|
+
* },
|
|
824
|
+
* })
|
|
825
|
+
* .build();
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
messageMiddleware(...middleware: readonly MessageMiddleware[]): this;
|
|
829
|
+
/** Shared shape check — a chain built from a typo fails at build time, not
|
|
830
|
+
* as a silent no-op on the one call that needed governing. */
|
|
831
|
+
private assertMiddleware;
|
|
679
832
|
checkIn(opts?: CheckInBuilderOptions): this;
|
|
680
833
|
selfExplain(opts?: SelfExplainOptions): this;
|
|
681
834
|
build(): Agent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentBuilder.d.ts","sourceRoot":"","sources":["../../../../src/core/agent/AgentBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC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iBAAiB,CAAC,GAAG,UAAU,EAAE,SAAS,iBAAiB,EAAE,GAAG,IAAI;IAMpE;mEAC+D;IAC/D,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,IAAI,GAAE,qBAA0B,GAAG,IAAI;IAQ/C,WAAW,CAAC,IAAI,GAAE,kBAAuB,GAAG,IAAI;IAmBhD,KAAK,IAAI,KAAK;CAsFf"}
|
|
@@ -63,9 +63,9 @@ export interface AgentChartDeps {
|
|
|
63
63
|
/** Hard ReAct iteration cap, threaded into CacheDecision's
|
|
64
64
|
* inputMapper for max-iteration policies. */
|
|
65
65
|
readonly maxIterations: number;
|
|
66
|
-
readonly seed: (scope: never) => void
|
|
66
|
+
readonly seed: (scope: never) => void | Promise<void>;
|
|
67
67
|
readonly callLLM: (scope: never) => Promise<void>;
|
|
68
|
-
readonly routeDecider: (scope: never) => 'tool-calls' | 'final'
|
|
68
|
+
readonly routeDecider: (scope: never) => 'tool-calls' | 'final' | Promise<'tool-calls' | 'final'>;
|
|
69
69
|
readonly toolCallsHandler: import('footprintjs').PausableHandler<never>;
|
|
70
70
|
readonly injectionEngineSubflow: FlowChart;
|
|
71
71
|
/** Relevance entry router (`entryByRelevance`) — a once-per-turn function stage
|
|
@@ -73,18 +73,25 @@ export interface AgentChartDeps {
|
|
|
73
73
|
* skill graph was built with a relevance scorer. */
|
|
74
74
|
readonly pickEntryStage?: (scope: never) => Promise<void>;
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
77
|
-
* consumer configured
|
|
78
|
-
* loop target, mounted immediately before the current one.
|
|
76
|
+
* The window-strategy stage (`.window()` / `.compaction()`). Present ONLY
|
|
77
|
+
* when the consumer configured a strategy — and when present it BECOMES the
|
|
78
|
+
* ReAct loop target, mounted immediately before the current one.
|
|
79
79
|
*
|
|
80
80
|
* It has to be the loop target rather than merely sit in the loop body:
|
|
81
81
|
* the loop is branch-sourced (`tool-calls → { loopTo }`), so anything ahead
|
|
82
82
|
* of the target runs once and is never seen again. Being the target also
|
|
83
|
-
* puts the
|
|
84
|
-
* point — the triggers, the three slots and the wire then all see
|
|
85
|
-
* window, and no component gets a different past than the model
|
|
83
|
+
* puts the window change BEFORE the injection engine and the slots, which
|
|
84
|
+
* is the point — the triggers, the three slots and the wire then all see
|
|
85
|
+
* the same window, and no component gets a different past than the model
|
|
86
|
+
* does.
|
|
87
|
+
*
|
|
88
|
+
* `strategyName` rides along so the chart itself says which policy is
|
|
89
|
+
* mounted; a reader of the graph should not have to guess.
|
|
86
90
|
*/
|
|
87
|
-
readonly
|
|
91
|
+
readonly windowStage?: {
|
|
92
|
+
readonly strategyName: string;
|
|
93
|
+
readonly run: (scope: never) => Promise<void>;
|
|
94
|
+
};
|
|
88
95
|
readonly systemPromptSubflow: FlowChart;
|
|
89
96
|
readonly messagesSubflow: FlowChart;
|
|
90
97
|
readonly toolsSubflow: FlowChart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAgentChart.d.ts","sourceRoot":"","sources":["../../../../src/core/agent/buildAgentChart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAc,MAAM,aAAa,CAAC;AAE5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAOxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAUrE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAE/C;;;8DAG0D;IAC1D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,OAAO,yCAAyC,EAAE,WAAW,CAAC;IAEpG;uEACmE;IACnE,QAAQ,CAAC,uBAAuB,EAAE,WAAW,CAAC;IAE9C;kDAC8C;IAC9C,QAAQ,CAAC,aAAa,EAAE,MAA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ACrD,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE;QACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/C,CAAC;IACF,QAAQ,CAAC,mBAAmB,EAAE,SAAS,CAAC;IACxC,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,CAAC;IAMrC,QAAQ,CAAC,uBAAuB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEzD;;;;;;;OAOG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAG3C;;;;0CAIsC;IACtC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,CA4X/D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageDeniedError — typed error thrown by `Agent.run()` when a
|
|
3
|
+
* `messageMiddleware` returns `deny(reason)`.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Typed Error (the `PolicyHaltError` shape, for the same reason).
|
|
6
|
+
* Role: Surface layer for the message boundary. The stage writes the
|
|
7
|
+
* refusal to scope; `Agent.finalizeResult` translates it here, so
|
|
8
|
+
* a caller can `instanceof` it and route on `.phase` / `.middleware`.
|
|
9
|
+
* Emits: N/A — `agentfootprint.middleware.decision` fires from the stage
|
|
10
|
+
* at the moment the refusal is decided.
|
|
11
|
+
*
|
|
12
|
+
* ## Why a refusal is not returned as an answer
|
|
13
|
+
*
|
|
14
|
+
* At the `'input'` phase there is no model to tell: the message never
|
|
15
|
+
* reached one, so there is nothing in the run for a denial to become. At
|
|
16
|
+
* the `'output'` phase there IS an answer, and the middleware has just
|
|
17
|
+
* refused to release it — handing the caller a string in its place is the
|
|
18
|
+
* one substitution a caller must never be able to make silently. Both
|
|
19
|
+
* phases therefore raise, exactly the way a policy halt does.
|
|
20
|
+
*
|
|
21
|
+
* ## What it deliberately does not carry
|
|
22
|
+
*
|
|
23
|
+
* Never the refused content. A middleware that suppressed an answer would
|
|
24
|
+
* be undone by an error object that carried the answer out anyway. The
|
|
25
|
+
* content stays where the run put it — in the commit log, under whatever
|
|
26
|
+
* redaction the run configured.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* try {
|
|
30
|
+
* await agent.run({ message: userText });
|
|
31
|
+
* } catch (e) {
|
|
32
|
+
* if (e instanceof MessageDeniedError) {
|
|
33
|
+
* console.log(`${e.middleware} refused this ${e.phase}: ${e.reason}`);
|
|
34
|
+
* } else throw e;
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
export interface MessageDeniedContext {
|
|
38
|
+
/** The refusal text the middleware returned. */
|
|
39
|
+
readonly reason: string;
|
|
40
|
+
/** Which boundary refused. */
|
|
41
|
+
readonly phase: 'input' | 'output';
|
|
42
|
+
/** `name` of the middleware that returned `deny`. */
|
|
43
|
+
readonly middleware: string;
|
|
44
|
+
}
|
|
45
|
+
export declare class MessageDeniedError extends Error {
|
|
46
|
+
readonly code: "ERR_MESSAGE_DENIED";
|
|
47
|
+
readonly reason: string;
|
|
48
|
+
readonly phase: 'input' | 'output';
|
|
49
|
+
readonly middleware: string;
|
|
50
|
+
constructor(ctx: MessageDeniedContext);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/middleware/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC;IACnC,qDAAqD;IACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,uBAAiC;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,GAAG,EAAE,oBAAoB;CAOtC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* middleware — PUBLIC barrel. The governance chain family.
|
|
3
|
+
*
|
|
4
|
+
* Two chains, one vocabulary:
|
|
5
|
+
*
|
|
6
|
+
* `.toolMiddleware(...)` wraps every tool dispatch
|
|
7
|
+
* `.messageMiddleware(...)` wraps the message boundary — the input
|
|
8
|
+
* before the model sees it, the output before
|
|
9
|
+
* the caller receives it
|
|
10
|
+
*
|
|
11
|
+
* Three verbs: `allow`, `deny`, `ask`. There is no fourth, and in
|
|
12
|
+
* particular there is no way to return a result — see `types.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export { allow, ask, deny } from './outcomes.js';
|
|
15
|
+
export { MessageDeniedError, type MessageDeniedContext } from './errors.js';
|
|
16
|
+
export type { AllowOutcome, AskOutcome, AskPayload, DenyOutcome, MessageMiddleware, MessageMiddlewareContext, MessageOutcome, MiddlewareDecision, ToolMiddleware, ToolMiddlewareContext, ToolOutcome, } from './types.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/middleware/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5E,YAAY,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,WAAW,GACZ,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* middleware/ledger — INTERNAL. Where a chain's decisions become record.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: one writer for one committed key.
|
|
5
|
+
* Role: core/ layer. `runChain` decides; this file is the only thing
|
|
6
|
+
* that commits what it decided and emits the matching event, so
|
|
7
|
+
* the three call sites cannot record the same fact three
|
|
8
|
+
* different ways.
|
|
9
|
+
* Emits: `agentfootprint.middleware.decision`, one per row.
|
|
10
|
+
*
|
|
11
|
+
* ## Why the original value is committed too
|
|
12
|
+
*
|
|
13
|
+
* A transform makes the trace and the wire disagree — the model saw one
|
|
14
|
+
* string, the run remembers another. Committing the pair, with the
|
|
15
|
+
* middleware's name and its `why` beside it, is what turns that
|
|
16
|
+
* disagreement from a lie into a record. Every slice taken afterwards can
|
|
17
|
+
* then find the moment the value changed and who changed it.
|
|
18
|
+
*
|
|
19
|
+
* This is not a redaction layer, and it is not trying to be one. For the
|
|
20
|
+
* `'input'` phase in particular, the ledger row is the ONLY copy of the
|
|
21
|
+
* pre-scrub text anywhere in the run — the seed stage commits the
|
|
22
|
+
* transformed message and nothing else ever holds the original. If your
|
|
23
|
+
* threat model says the original must not survive in the commit log,
|
|
24
|
+
* configure footprintjs redaction over this key; it scrubs `before` /
|
|
25
|
+
* `after` at write time and the row itself survives, so the run still says
|
|
26
|
+
* a scrub happened and who did it.
|
|
27
|
+
*/
|
|
28
|
+
import type { MiddlewareDecision } from './types.js';
|
|
29
|
+
/** The scope surface this file needs. Structurally a `TypedScope<AgentState>`. */
|
|
30
|
+
export interface LedgerScope {
|
|
31
|
+
middlewareDecisions?: readonly MiddlewareDecision[];
|
|
32
|
+
$emit(name: string, payload?: unknown): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Append decision rows to the run's ledger and emit one event per row.
|
|
36
|
+
*
|
|
37
|
+
* No-op on an empty list, so an agent with no middleware never writes the
|
|
38
|
+
* key at all and its commit log is the one it always had.
|
|
39
|
+
*/
|
|
40
|
+
export declare function recordDecisions(scope: LedgerScope, rows: readonly MiddlewareDecision[]): void;
|
|
41
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/middleware/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B,mBAAmB,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACpD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,kBAAkB,EAAE,GAAG,IAAI,CAoB7F"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* middleware/outcomes — PUBLIC. The three verbs a middleware speaks.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Smart constructors over a closed union.
|
|
5
|
+
* Role: core/ layer. `allow` / `deny` / `ask` are the entire vocabulary
|
|
6
|
+
* of both chains, which is why they are short: they are written
|
|
7
|
+
* inside every middleware body, several times, and a governance
|
|
8
|
+
* rule reads better as `deny('writes to prod need a ticket')` than
|
|
9
|
+
* as a namespaced ceremony.
|
|
10
|
+
* Emits: N/A.
|
|
11
|
+
*
|
|
12
|
+
* The `allow` overloads carry a rule: you can pass the value through
|
|
13
|
+
* untouched with no explanation, but you cannot CHANGE it without one. A
|
|
14
|
+
* transform is the only thing here that makes the trace and the wire
|
|
15
|
+
* disagree, so it is the only thing required to say why.
|
|
16
|
+
*/
|
|
17
|
+
import type { AllowOutcome, AskOutcome, AskPayload, DenyOutcome } from './types.js';
|
|
18
|
+
/** Pass the value through untouched. */
|
|
19
|
+
export declare function allow(): AllowOutcome<never>;
|
|
20
|
+
/**
|
|
21
|
+
* Replace the value and say why.
|
|
22
|
+
*
|
|
23
|
+
* The `why` is mandatory and lands in the ledger next to the before/after
|
|
24
|
+
* pair, so a run that was scrubbed can be read back as a run that was
|
|
25
|
+
* scrubbed rather than as a run whose input was always that way.
|
|
26
|
+
*/
|
|
27
|
+
export declare function allow<T>(value: T, why: string): AllowOutcome<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Refuse the call.
|
|
30
|
+
*
|
|
31
|
+
* For a tool the reason reaches the model verbatim, as the tool's result,
|
|
32
|
+
* and the loop continues — the agent gets to adapt. For a message it
|
|
33
|
+
* surfaces as a `MessageDeniedError`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function deny(reason: string): DenyOutcome;
|
|
36
|
+
/**
|
|
37
|
+
* Suspend the run and put the question to a person. Tool dispatch only —
|
|
38
|
+
* `MessageOutcome` has no `ask` arm, so this cannot be returned from a
|
|
39
|
+
* message middleware.
|
|
40
|
+
*
|
|
41
|
+
* The answer is a decision, not a result: approve and the chain continues
|
|
42
|
+
* and the REAL tool runs; decline and it becomes a denial the model reads.
|
|
43
|
+
* A middleware never gets to write the answer itself.
|
|
44
|
+
*/
|
|
45
|
+
export declare function ask(payload: AskPayload): AskOutcome;
|
|
46
|
+
//# sourceMappingURL=outcomes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcomes.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/middleware/outcomes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpF,wCAAwC;AACxC,wBAAgB,KAAK,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;AAC7C;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAajE;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAQhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAanD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* middleware/runChain — INTERNAL. The one place a chain is walked.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Chain of Responsibility driver.
|
|
5
|
+
* Role: core/ layer. Both stages (tool dispatch, message boundary) and
|
|
6
|
+
* the MCP server call in here, so the ordering law, the
|
|
7
|
+
* throw-is-a-denial law and the ledger row shape are written once
|
|
8
|
+
* and cannot drift between the three callers.
|
|
9
|
+
* Emits: N/A — it RETURNS rows; the caller commits and emits them, so a
|
|
10
|
+
* middleware still never touches scope.
|
|
11
|
+
*
|
|
12
|
+
* ## The rules this file implements
|
|
13
|
+
*
|
|
14
|
+
* **Order is declaration order.** The chain is walked front to back, and
|
|
15
|
+
* each link is handed the previous link's output — so a scrubber placed
|
|
16
|
+
* first is a scrubber every later rule sees the effect of.
|
|
17
|
+
*
|
|
18
|
+
* **The first non-allow answer wins.** A deny or an ask stops the walk;
|
|
19
|
+
* the links behind it do not run. There is no "second opinion" pass,
|
|
20
|
+
* because a refusal that a later middleware could overturn is not a
|
|
21
|
+
* refusal.
|
|
22
|
+
*
|
|
23
|
+
* **A middleware that throws is a denial, never a pass.** The thrown
|
|
24
|
+
* message becomes the reason. This is the same deny-by-default the
|
|
25
|
+
* permission gate has always applied to a checker that throws: a
|
|
26
|
+
* governance layer whose failure mode is "allow" is not a governance
|
|
27
|
+
* layer.
|
|
28
|
+
*/
|
|
29
|
+
import type { LLMMessage } from '../../../adapters/types.js';
|
|
30
|
+
import type { MemoryIdentity } from '../../../memory/identity/types.js';
|
|
31
|
+
import type { AskPayload, MessageMiddleware, MiddlewareDecision, ToolMiddleware } from './types.js';
|
|
32
|
+
/** Tool args, as they travel the chain. */
|
|
33
|
+
export type ToolArgs = Readonly<Record<string, unknown>>;
|
|
34
|
+
/**
|
|
35
|
+
* What to do when a middleware answers `ask` somewhere that cannot pause.
|
|
36
|
+
*
|
|
37
|
+
* `'pause'` — the caller will checkpoint (the normal dispatch path).
|
|
38
|
+
* `'refuse'` — the ask is converted into a deny naming the middleware. Used
|
|
39
|
+
* on the resume path (footprintjs's `PausableHandler.resume` returns void,
|
|
40
|
+
* so a resumed dispatch cannot suspend a second time) and by `mcpServe`
|
|
41
|
+
* (MCP is request/response — there is no pause to carry the ask).
|
|
42
|
+
*/
|
|
43
|
+
export type AskPolicy = 'pause' | 'refuse';
|
|
44
|
+
export type ToolChainResult = {
|
|
45
|
+
readonly kind: 'allow';
|
|
46
|
+
readonly args: ToolArgs;
|
|
47
|
+
readonly decisions: MiddlewareDecision[];
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: 'deny';
|
|
50
|
+
readonly reason: string;
|
|
51
|
+
readonly middleware: string;
|
|
52
|
+
readonly args: ToolArgs;
|
|
53
|
+
readonly decisions: MiddlewareDecision[];
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'ask';
|
|
56
|
+
readonly payload: AskPayload;
|
|
57
|
+
readonly middleware: string;
|
|
58
|
+
/** Index of the link that asked — resume continues from `index + 1`. */
|
|
59
|
+
readonly index: number;
|
|
60
|
+
/** Args as transformed up to the ask. These ride the checkpoint. */
|
|
61
|
+
readonly args: ToolArgs;
|
|
62
|
+
readonly decisions: MiddlewareDecision[];
|
|
63
|
+
};
|
|
64
|
+
export interface ToolChainInput {
|
|
65
|
+
readonly toolName: string;
|
|
66
|
+
readonly toolCallId: string;
|
|
67
|
+
readonly iteration: number;
|
|
68
|
+
readonly args: ToolArgs;
|
|
69
|
+
readonly history: readonly LLMMessage[];
|
|
70
|
+
readonly identity?: MemoryIdentity;
|
|
71
|
+
readonly signal?: AbortSignal;
|
|
72
|
+
/**
|
|
73
|
+
* Where to start walking. `0` for a fresh dispatch; `n` on resume, to
|
|
74
|
+
* continue the chain AFTER the link that asked without re-running the
|
|
75
|
+
* links whose decisions the checkpoint already carries.
|
|
76
|
+
*/
|
|
77
|
+
readonly startIndex?: number;
|
|
78
|
+
readonly askPolicy?: AskPolicy;
|
|
79
|
+
}
|
|
80
|
+
/** Walk the tool chain. Never throws — a throwing link becomes a denial. */
|
|
81
|
+
export declare function runToolChain(chain: readonly ToolMiddleware[], input: ToolChainInput): Promise<ToolChainResult>;
|
|
82
|
+
export type MessageChainResult = {
|
|
83
|
+
readonly kind: 'allow';
|
|
84
|
+
readonly content: string;
|
|
85
|
+
readonly decisions: MiddlewareDecision[];
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: 'deny';
|
|
88
|
+
readonly reason: string;
|
|
89
|
+
readonly middleware: string;
|
|
90
|
+
/** Content as transformed by the links BEFORE the refusal. */
|
|
91
|
+
readonly content: string;
|
|
92
|
+
readonly decisions: MiddlewareDecision[];
|
|
93
|
+
};
|
|
94
|
+
export interface MessageChainInput {
|
|
95
|
+
readonly phase: 'input' | 'output';
|
|
96
|
+
readonly content: string;
|
|
97
|
+
readonly history: readonly LLMMessage[];
|
|
98
|
+
/** ReAct iteration for the ledger row. `0` at `'input'` (before iter 1). */
|
|
99
|
+
readonly iteration: number;
|
|
100
|
+
readonly identity?: MemoryIdentity;
|
|
101
|
+
readonly signal?: AbortSignal;
|
|
102
|
+
}
|
|
103
|
+
/** Walk the message chain. Never throws — a throwing link becomes a denial. */
|
|
104
|
+
export declare function runMessageChain(chain: readonly MessageMiddleware[], input: MessageChainInput): Promise<MessageChainResult>;
|
|
105
|
+
//# sourceMappingURL=runChain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runChain.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/middleware/runChain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EAEjB,kBAAkB,EAClB,cAAc,EAEf,MAAM,YAAY,CAAC;AAEpB,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE3C,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,kBAAkB,EAAE,CAAA;CAAE,GAC7F;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,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