agentfootprint 2.3.0 → 2.5.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/README.md +293 -247
- package/dist/adapters/llm/AnthropicProvider.js +2 -2
- package/dist/adapters/llm/AnthropicProvider.js.map +1 -1
- package/dist/adapters/llm/BedrockProvider.js +2 -2
- package/dist/adapters/llm/BedrockProvider.js.map +1 -1
- package/dist/adapters/llm/BrowserAnthropicProvider.js +96 -28
- package/dist/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/adapters/llm/OpenAIProvider.js +2 -2
- package/dist/adapters/llm/OpenAIProvider.js.map +1 -1
- package/dist/adapters/memory/agentcore.js +9 -3
- package/dist/adapters/memory/agentcore.js.map +1 -1
- package/dist/adapters/memory/redis.js +9 -3
- package/dist/adapters/memory/redis.js.map +1 -1
- package/dist/core/Agent.js +493 -79
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/flowchartAsTool.js +188 -0
- package/dist/core/flowchartAsTool.js.map +1 -0
- package/dist/core/outputSchema.js +119 -0
- package/dist/core/outputSchema.js.map +1 -0
- package/dist/core/slots/buildSystemPromptSlot.js +8 -0
- package/dist/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/core/slots/buildToolsSlot.js +56 -5
- package/dist/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/adapters/llm/AnthropicProvider.js +2 -2
- package/dist/esm/adapters/llm/AnthropicProvider.js.map +1 -1
- package/dist/esm/adapters/llm/BedrockProvider.js +2 -2
- package/dist/esm/adapters/llm/BedrockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js +96 -28
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/esm/adapters/llm/OpenAIProvider.js +2 -2
- package/dist/esm/adapters/llm/OpenAIProvider.js.map +1 -1
- package/dist/esm/adapters/memory/agentcore.js +9 -3
- package/dist/esm/adapters/memory/agentcore.js.map +1 -1
- package/dist/esm/adapters/memory/redis.js +9 -3
- package/dist/esm/adapters/memory/redis.js.map +1 -1
- package/dist/esm/core/Agent.js +492 -78
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/flowchartAsTool.js +184 -0
- package/dist/esm/core/flowchartAsTool.js.map +1 -0
- package/dist/esm/core/outputSchema.js +113 -0
- package/dist/esm/core/outputSchema.js.map +1 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.js +8 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/esm/core/slots/buildToolsSlot.js +56 -5
- package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/index.js +34 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/SkillRegistry.js +181 -0
- package/dist/esm/lib/injection-engine/SkillRegistry.js.map +1 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.js +35 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.js.map +1 -1
- package/dist/esm/lib/injection-engine/index.js +9 -1
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillTools.js +125 -0
- package/dist/esm/lib/injection-engine/skillTools.js.map +1 -0
- package/dist/esm/lib/injection-engine/types.js +8 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/lazyRequire.js +33 -0
- package/dist/esm/lib/lazyRequire.js.map +1 -0
- package/dist/esm/lib/mcp/mcpClient.js +4 -6
- package/dist/esm/lib/mcp/mcpClient.js.map +1 -1
- package/dist/esm/llm-providers.js +31 -0
- package/dist/esm/llm-providers.js.map +1 -0
- package/dist/esm/locales/index.js +144 -0
- package/dist/esm/locales/index.js.map +1 -0
- package/dist/esm/memory-providers.js +44 -0
- package/dist/esm/memory-providers.js.map +1 -0
- package/dist/esm/providers.js +11 -0
- package/dist/esm/providers.js.map +1 -1
- package/dist/esm/recorders/core/contextEngineering.js +155 -0
- package/dist/esm/recorders/core/contextEngineering.js.map +1 -0
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.js +6 -1
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
- package/dist/esm/security/PermissionPolicy.js +135 -0
- package/dist/esm/security/PermissionPolicy.js.map +1 -0
- package/dist/esm/security/index.js +38 -0
- package/dist/esm/security/index.js.map +1 -0
- package/dist/esm/tool-providers/gatedTools.js +52 -0
- package/dist/esm/tool-providers/gatedTools.js.map +1 -0
- package/dist/esm/tool-providers/index.js +43 -0
- package/dist/esm/tool-providers/index.js.map +1 -0
- package/dist/esm/tool-providers/skillScopedTools.js +63 -0
- package/dist/esm/tool-providers/skillScopedTools.js.map +1 -0
- package/dist/esm/tool-providers/staticTools.js +33 -0
- package/dist/esm/tool-providers/staticTools.js.map +1 -0
- package/dist/esm/tool-providers/types.js +53 -0
- package/dist/esm/tool-providers/types.js.map +1 -0
- package/dist/index.js +57 -12
- package/dist/index.js.map +1 -1
- package/dist/lib/injection-engine/SkillRegistry.js +185 -0
- package/dist/lib/injection-engine/SkillRegistry.js.map +1 -0
- package/dist/lib/injection-engine/factories/defineSkill.js +37 -1
- package/dist/lib/injection-engine/factories/defineSkill.js.map +1 -1
- package/dist/lib/injection-engine/index.js +14 -1
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillTools.js +130 -0
- package/dist/lib/injection-engine/skillTools.js.map +1 -0
- package/dist/lib/injection-engine/types.js +8 -0
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/lib/lazyRequire.js +37 -0
- package/dist/lib/lazyRequire.js.map +1 -0
- package/dist/lib/mcp/mcpClient.js +4 -6
- package/dist/lib/mcp/mcpClient.js.map +1 -1
- package/dist/llm-providers.js +47 -0
- package/dist/llm-providers.js.map +1 -0
- package/dist/locales/index.js +149 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/memory-providers.js +49 -0
- package/dist/memory-providers.js.map +1 -0
- package/dist/providers.js +11 -0
- package/dist/providers.js.map +1 -1
- package/dist/recorders/core/contextEngineering.js +161 -0
- package/dist/recorders/core/contextEngineering.js.map +1 -0
- package/dist/recorders/observability/commentary/commentaryTemplates.js +6 -1
- package/dist/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
- package/dist/security/PermissionPolicy.js +139 -0
- package/dist/security/PermissionPolicy.js.map +1 -0
- package/dist/security/index.js +42 -0
- package/dist/security/index.js.map +1 -0
- package/dist/tool-providers/gatedTools.js +56 -0
- package/dist/tool-providers/gatedTools.js.map +1 -0
- package/dist/tool-providers/index.js +51 -0
- package/dist/tool-providers/index.js.map +1 -0
- package/dist/tool-providers/skillScopedTools.js +67 -0
- package/dist/tool-providers/skillScopedTools.js.map +1 -0
- package/dist/tool-providers/staticTools.js +37 -0
- package/dist/tool-providers/staticTools.js.map +1 -0
- package/dist/tool-providers/types.js +54 -0
- package/dist/tool-providers/types.js.map +1 -0
- package/dist/types/adapters/llm/AnthropicProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/BedrockProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/OpenAIProvider.d.ts.map +1 -1
- package/dist/types/adapters/memory/agentcore.d.ts +7 -1
- package/dist/types/adapters/memory/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/memory/redis.d.ts +7 -1
- package/dist/types/adapters/memory/redis.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +216 -2
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/flowchartAsTool.d.ts +161 -0
- package/dist/types/core/flowchartAsTool.d.ts.map +1 -0
- package/dist/types/core/outputSchema.d.ts +128 -0
- package/dist/types/core/outputSchema.d.ts.map +1 -0
- package/dist/types/core/slots/buildSystemPromptSlot.d.ts.map +1 -1
- package/dist/types/core/slots/buildToolsSlot.d.ts +10 -0
- package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/SkillRegistry.d.ts +148 -0
- package/dist/types/lib/injection-engine/SkillRegistry.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/factories/defineSkill.d.ts +99 -0
- package/dist/types/lib/injection-engine/factories/defineSkill.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/index.d.ts +5 -2
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillTools.d.ts +73 -0
- package/dist/types/lib/injection-engine/skillTools.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/types.d.ts +28 -0
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/lib/lazyRequire.d.ts +30 -0
- package/dist/types/lib/lazyRequire.d.ts.map +1 -0
- package/dist/types/lib/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/llm-providers.d.ts +31 -0
- package/dist/types/llm-providers.d.ts.map +1 -0
- package/dist/types/locales/index.d.ts +133 -0
- package/dist/types/locales/index.d.ts.map +1 -0
- package/dist/types/memory-providers.d.ts +41 -0
- package/dist/types/memory-providers.d.ts.map +1 -0
- package/dist/types/providers.d.ts +11 -0
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/recorders/core/contextEngineering.d.ts +137 -0
- package/dist/types/recorders/core/contextEngineering.d.ts.map +1 -0
- package/dist/types/recorders/observability/commentary/commentaryTemplates.d.ts.map +1 -1
- package/dist/types/security/PermissionPolicy.d.ts +125 -0
- package/dist/types/security/PermissionPolicy.d.ts.map +1 -0
- package/dist/types/security/index.d.ts +40 -0
- package/dist/types/security/index.d.ts.map +1 -0
- package/dist/types/tool-providers/gatedTools.d.ts +37 -0
- package/dist/types/tool-providers/gatedTools.d.ts.map +1 -0
- package/dist/types/tool-providers/index.d.ts +42 -0
- package/dist/types/tool-providers/index.d.ts.map +1 -0
- package/dist/types/tool-providers/skillScopedTools.d.ts +46 -0
- package/dist/types/tool-providers/skillScopedTools.d.ts.map +1 -0
- package/dist/types/tool-providers/staticTools.d.ts +22 -0
- package/dist/types/tool-providers/staticTools.d.ts.map +1 -0
- package/dist/types/tool-providers/types.d.ts +103 -0
- package/dist/types/tool-providers/types.d.ts.map +1 -0
- package/package.json +62 -9
- package/README.proposed.md +0 -258
- package/dist/instructions.js +0 -21
- package/dist/instructions.js.map +0 -1
- package/dist/lib/instructions/defineInstruction.js +0 -35
- package/dist/lib/instructions/defineInstruction.js.map +0 -1
- package/dist/lib/instructions/evaluator.js +0 -38
- package/dist/lib/instructions/evaluator.js.map +0 -1
- package/dist/lib/instructions/index.js +0 -48
- package/dist/lib/instructions/index.js.map +0 -1
- package/dist/lib/instructions/types.js +0 -22
- package/dist/lib/instructions/types.js.map +0 -1
- package/dist/memory/conversationHelpers.js +0 -39
- package/dist/memory/conversationHelpers.js.map +0 -1
- package/dist/types/instructions.d.ts +0 -5
- package/dist/types/instructions.d.ts.map +0 -1
- package/dist/types/lib/instructions/defineInstruction.d.ts +0 -22
- package/dist/types/lib/instructions/defineInstruction.d.ts.map +0 -1
- package/dist/types/lib/instructions/evaluator.d.ts +0 -11
- package/dist/types/lib/instructions/evaluator.d.ts.map +0 -1
- package/dist/types/lib/instructions/index.d.ts +0 -44
- package/dist/types/lib/instructions/index.d.ts.map +0 -1
- package/dist/types/lib/instructions/types.d.ts +0 -100
- package/dist/types/lib/instructions/types.d.ts.map +0 -1
- package/dist/types/memory/conversationHelpers.d.ts +0 -19
- package/dist/types/memory/conversationHelpers.d.ts.map +0 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* contextEngineering(agent) — first-class handle on the engineered
|
|
3
|
+
* subset of `context.injected` events.
|
|
4
|
+
*
|
|
5
|
+
* The Block A8 piece. agentfootprint already emits `context.injected`
|
|
6
|
+
* for EVERY piece of content that lands in a slot — including the
|
|
7
|
+
* baseline flow (the user message, every tool result, the static
|
|
8
|
+
* system prompt). For a developer who wants to inspect what their
|
|
9
|
+
* RAG / Skills / Memory / Instructions / Steering / Facts ARE
|
|
10
|
+
* INJECTING (the actual context-engineering work), the baseline flow
|
|
11
|
+
* is noise.
|
|
12
|
+
*
|
|
13
|
+
* `contextEngineering(agent)` filters the stream to ONLY the
|
|
14
|
+
* engineered injections and gives consumers two cleaner subscriptions:
|
|
15
|
+
*
|
|
16
|
+
* - `onEngineered(cb)` — fires for `source` ∈ {rag, skill, memory,
|
|
17
|
+
* instructions, steering, fact, custom}. The actual
|
|
18
|
+
* context-engineering work.
|
|
19
|
+
* - `onBaseline(cb)` — fires for `source` ∈ {user, tool-result,
|
|
20
|
+
* assistant, base, registry}. The baseline message-history flow.
|
|
21
|
+
*
|
|
22
|
+
* Use cases:
|
|
23
|
+
* - **Lens UI**: render only engineered injections in the "context
|
|
24
|
+
* bin"; show the baseline flow as edges between iterations.
|
|
25
|
+
* - **Eval pipelines**: count how many RAG chunks vs Memory entries
|
|
26
|
+
* vs Skill bodies entered the prompt for an eval-set query.
|
|
27
|
+
* - **Cost attribution**: sum tokens by `source` to know what
|
|
28
|
+
* fraction of spend is RAG vs Skills vs baseline.
|
|
29
|
+
* - **Debug logging**: tail just the engineered signals to spot
|
|
30
|
+
* surprising activations during dev.
|
|
31
|
+
*
|
|
32
|
+
* Pattern: Strategy + Filter (GoF) — pure classifier function over
|
|
33
|
+
* the existing `context.injected` event payload, paired with
|
|
34
|
+
* a thin subscription helper.
|
|
35
|
+
*
|
|
36
|
+
* Role: Layer-2 (event taxonomy) consumer-side helper. Doesn't
|
|
37
|
+
* emit new events; doesn't change the agent's flowchart.
|
|
38
|
+
* Pure observation.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* import { contextEngineering } from 'agentfootprint';
|
|
42
|
+
*
|
|
43
|
+
* const ce = contextEngineering(agent);
|
|
44
|
+
* ce.onEngineered((e) => {
|
|
45
|
+
* console.log(`[${e.payload.source}] ${e.payload.contentSummary}`);
|
|
46
|
+
* });
|
|
47
|
+
* ce.onBaseline((e) => {
|
|
48
|
+
* console.log(`[baseline:${e.payload.source}]`);
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* await agent.run({ message: 'help me' });
|
|
52
|
+
* // ... runs; engineered + baseline streams fire separately
|
|
53
|
+
*
|
|
54
|
+
* ce.detach(); // stops both subscriptions; the agent itself is fine
|
|
55
|
+
*/
|
|
56
|
+
import type { AgentfootprintEventMap } from '../../events/registry.js';
|
|
57
|
+
import type { ContextSource } from '../../events/types.js';
|
|
58
|
+
/**
|
|
59
|
+
* Public set of "engineered" sources — the context-engineering
|
|
60
|
+
* primitives that consumers configure (RAG, Skills, Memory,
|
|
61
|
+
* Instructions, Steering, Facts) plus user-defined `custom`.
|
|
62
|
+
*
|
|
63
|
+
* Frozen so consumers can `.has(value)` directly without copy.
|
|
64
|
+
*/
|
|
65
|
+
export declare const ENGINEERED_SOURCES: ReadonlySet<ContextSource>;
|
|
66
|
+
/**
|
|
67
|
+
* Public set of "baseline" sources — the message-history flow that
|
|
68
|
+
* exists regardless of context engineering: user input, tool results,
|
|
69
|
+
* assistant outputs, the always-on system prompt anchor (`base`), and
|
|
70
|
+
* the agent's static tool registry advertisement (`registry`).
|
|
71
|
+
*/
|
|
72
|
+
export declare const BASELINE_SOURCES: ReadonlySet<ContextSource>;
|
|
73
|
+
/**
|
|
74
|
+
* Pure classifier: given a `ContextSource`, is it engineered?
|
|
75
|
+
*
|
|
76
|
+
* Useful for ad-hoc filtering on a raw `agent.on('agentfootprint.context.injected', ...)`
|
|
77
|
+
* subscription when you don't need the wrapper helper.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isEngineeredSource(source: ContextSource): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Pure classifier: given a `ContextSource`, is it baseline?
|
|
82
|
+
*/
|
|
83
|
+
export declare function isBaselineSource(source: ContextSource): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The shape of the event passed to `onEngineered` / `onBaseline`
|
|
86
|
+
* callbacks. Same as `agentfootprint.context.injected`'s envelope —
|
|
87
|
+
* we don't transform it, just route by source.
|
|
88
|
+
*/
|
|
89
|
+
export type ContextInjectedEvent = AgentfootprintEventMap['agentfootprint.context.injected'];
|
|
90
|
+
/** Listener signature for the wrapper helper. */
|
|
91
|
+
export type ContextInjectedListener = (event: ContextInjectedEvent) => void;
|
|
92
|
+
/** Unsubscribe handle. */
|
|
93
|
+
export type ContextEngineeringUnsubscribe = () => void;
|
|
94
|
+
/**
|
|
95
|
+
* Minimal subset of the agent surface this helper depends on.
|
|
96
|
+
* Lets us accept any runner (Agent, LLMCall, Sequence, etc.) that
|
|
97
|
+
* implements the typed `on(type, cb)` subscription API.
|
|
98
|
+
*/
|
|
99
|
+
interface RunnerWithEvents {
|
|
100
|
+
on(type: 'agentfootprint.context.injected', listener: ContextInjectedListener): ContextEngineeringUnsubscribe;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Handle returned by `contextEngineering(agent)`. Lets consumers
|
|
104
|
+
* subscribe to engineered / baseline streams and detach cleanly.
|
|
105
|
+
*/
|
|
106
|
+
export interface ContextEngineeringHandle {
|
|
107
|
+
/**
|
|
108
|
+
* Fires for `context.injected` events whose source is in
|
|
109
|
+
* `ENGINEERED_SOURCES`. Returns an unsubscribe function.
|
|
110
|
+
*/
|
|
111
|
+
onEngineered(listener: ContextInjectedListener): ContextEngineeringUnsubscribe;
|
|
112
|
+
/**
|
|
113
|
+
* Fires for `context.injected` events whose source is in
|
|
114
|
+
* `BASELINE_SOURCES`. Returns an unsubscribe function.
|
|
115
|
+
*/
|
|
116
|
+
onBaseline(listener: ContextInjectedListener): ContextEngineeringUnsubscribe;
|
|
117
|
+
/**
|
|
118
|
+
* Detach all subscriptions registered through this handle. After
|
|
119
|
+
* calling, no further callbacks will fire. Idempotent (safe to
|
|
120
|
+
* call multiple times).
|
|
121
|
+
*/
|
|
122
|
+
detach(): void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Wrap a runner's `agentfootprint.context.injected` stream into two
|
|
126
|
+
* filtered subscriptions: engineered + baseline. Multiple listeners
|
|
127
|
+
* per stream are allowed; `detach()` removes all of them.
|
|
128
|
+
*
|
|
129
|
+
* The classifier inspects `event.payload.source`. Unknown sources
|
|
130
|
+
* (forward-compat: `ContextSource` is open-extensible) are routed
|
|
131
|
+
* to NEITHER stream — preferring under-firing over miscategorizing.
|
|
132
|
+
* Use `agent.on('agentfootprint.context.injected', ...)` directly
|
|
133
|
+
* if you need to observe sources that aren't (yet) classified.
|
|
134
|
+
*/
|
|
135
|
+
export declare function contextEngineering(agent: RunnerWithEvents): ContextEngineeringHandle;
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=contextEngineering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextEngineering.d.ts","sourceRoot":"","sources":["../../../../src/recorders/core/contextEngineering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,aAAa,CAQxD,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,aAAa,CAMtD,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAEjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAE/D;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,iCAAiC,CAAC,CAAC;AAE7F,iDAAiD;AACjD,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAE5E,0BAA0B;AAC1B,MAAM,MAAM,6BAA6B,GAAG,MAAM,IAAI,CAAC;AAEvD;;;;GAIG;AACH,UAAU,gBAAgB;IACxB,EAAE,CACA,IAAI,EAAE,iCAAiC,EACvC,QAAQ,EAAE,uBAAuB,GAChC,6BAA6B,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,uBAAuB,GAAG,6BAA6B,CAAC;IAC/E;;;OAGG;IACH,UAAU,CAAC,QAAQ,EAAE,uBAAuB,GAAG,6BAA6B,CAAC;IAC7E;;;;OAIG;IACH,MAAM,IAAI,IAAI,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,wBAAwB,CA0CpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commentaryTemplates.d.ts","sourceRoot":"","sources":["../../../../../src/recorders/observability/commentary/commentaryTemplates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE;;;2EAG2E;AAC3E,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,
|
|
1
|
+
{"version":3,"file":"commentaryTemplates.d.ts","sourceRoot":"","sources":["../../../../../src/recorders/observability/commentary/commentaryTemplates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE;;;2EAG2E;AAC3E,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,mBAyDxC,CAAC;AAEF;;6CAE6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC;6EACyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;2EAGuE;IACvE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CACxE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CA8EzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,mBAAmB,EAC1B,GAAG,EAAE,iBAAiB,EACtB,SAAS,GAAE,mBAAgD,GAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAEvF"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PermissionPolicy — data-driven role-based authorization for tool dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Closes Neo gap #2 (of 8). Permissions are CROSS-CUTTING — they're not
|
|
5
|
+
* context engineering, they're a guard ON context-engineering operations
|
|
6
|
+
* (tool dispatch, skill activation, memory writes, output emission).
|
|
7
|
+
* That's why this lives in `agentfootprint/security`, parallel to the
|
|
8
|
+
* provider subpaths.
|
|
9
|
+
*
|
|
10
|
+
* Two surfaces, one primitive:
|
|
11
|
+
* 1. `PermissionPolicy.fromRoles({...}, activeRole)` — declarative,
|
|
12
|
+
* data-driven, auditable. Production governance.
|
|
13
|
+
* 2. The PermissionPolicy instance satisfies BOTH:
|
|
14
|
+
* - `PermissionChecker` interface (async check; consumed by Agent
|
|
15
|
+
* constructor's `permissionChecker` field)
|
|
16
|
+
* - sync `isAllowed(toolId)` method (consumed by `gatedTools(...)`
|
|
17
|
+
* from `agentfootprint/tool-providers`)
|
|
18
|
+
*
|
|
19
|
+
* Pattern: Strategy (GoF) for the role-allowlist policy + Adapter
|
|
20
|
+
* (matches `PermissionChecker` interface so it composes with
|
|
21
|
+
* existing v2.4 Agent constructor).
|
|
22
|
+
*
|
|
23
|
+
* Role: Layer-3 cross-cutting guard. Not Injection. Not provider.
|
|
24
|
+
* Lives in its own subpath (`agentfootprint/security`).
|
|
25
|
+
*
|
|
26
|
+
* @example Read-only role for a support agent
|
|
27
|
+
* const policy = PermissionPolicy.fromRoles(
|
|
28
|
+
* {
|
|
29
|
+
* readonly: ['lookup_order', 'get_status', 'list_skills', 'read_skill'],
|
|
30
|
+
* support: ['lookup_order', 'get_status', 'process_refund', 'list_skills', 'read_skill'],
|
|
31
|
+
* },
|
|
32
|
+
* 'readonly',
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* policy.isAllowed('lookup_order'); // → true
|
|
36
|
+
* policy.isAllowed('process_refund'); // → false (not in readonly role)
|
|
37
|
+
*
|
|
38
|
+
* // As a tool-dispatch gate (composes with gatedTools)
|
|
39
|
+
* const provider = gatedTools(staticTools(allTools), (name) => policy.isAllowed(name));
|
|
40
|
+
*
|
|
41
|
+
* // As an Agent permissionChecker (the v2.4 surface)
|
|
42
|
+
* const agent = Agent.create({ provider, model, permissionChecker: policy }).build();
|
|
43
|
+
*
|
|
44
|
+
* @example Per-identity role switching at runtime
|
|
45
|
+
* const policy = PermissionPolicy.fromRoles({
|
|
46
|
+
* readonly: [...],
|
|
47
|
+
* admin: [...],
|
|
48
|
+
* }, 'readonly');
|
|
49
|
+
*
|
|
50
|
+
* const adminPolicy = policy.withActiveRole('admin');
|
|
51
|
+
* // Same allowlist data; different active role.
|
|
52
|
+
*/
|
|
53
|
+
import type { PermissionChecker, PermissionRequest, PermissionDecision } from '../adapters/types.js';
|
|
54
|
+
/**
|
|
55
|
+
* Map of role name → list of tool ids that role is allowed to invoke.
|
|
56
|
+
* The shape consumers extend over time as new tools / roles arrive.
|
|
57
|
+
*/
|
|
58
|
+
export type RoleAllowlist = Readonly<Record<string, readonly string[]>>;
|
|
59
|
+
export interface PermissionPolicyOptions {
|
|
60
|
+
/**
|
|
61
|
+
* The role allowlist. Each role maps to the tool ids it can invoke.
|
|
62
|
+
* Tool ids match the `name` field of `Tool.schema.name` exactly.
|
|
63
|
+
*/
|
|
64
|
+
readonly roles: RoleAllowlist;
|
|
65
|
+
/**
|
|
66
|
+
* Which role is active for this policy instance. Calls to
|
|
67
|
+
* `.isAllowed(toolId)` check against this role's allowlist.
|
|
68
|
+
* Use `.withActiveRole(name)` to derive a sibling policy with a
|
|
69
|
+
* different active role.
|
|
70
|
+
*/
|
|
71
|
+
readonly activeRole: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Data-driven role-based permission policy. Satisfies the v2.4
|
|
75
|
+
* `PermissionChecker` interface AND exposes a sync `isAllowed` method
|
|
76
|
+
* for use with `gatedTools` from `agentfootprint/tool-providers`.
|
|
77
|
+
*/
|
|
78
|
+
export declare class PermissionPolicy implements PermissionChecker {
|
|
79
|
+
private readonly opts;
|
|
80
|
+
readonly name = "PermissionPolicy";
|
|
81
|
+
private constructor();
|
|
82
|
+
/**
|
|
83
|
+
* Factory: build a role-based policy from a role → tool-ids map and
|
|
84
|
+
* the role active for this instance.
|
|
85
|
+
*
|
|
86
|
+
* Throws if `activeRole` isn't a key in `roles` — fail loud at
|
|
87
|
+
* config time, not at first denied call.
|
|
88
|
+
*/
|
|
89
|
+
static fromRoles(roles: RoleAllowlist, activeRole: string): PermissionPolicy;
|
|
90
|
+
/**
|
|
91
|
+
* Sync allowlist check. Use as a predicate with `gatedTools`:
|
|
92
|
+
*
|
|
93
|
+
* gatedTools(staticTools(allTools), (toolId) => policy.isAllowed(toolId))
|
|
94
|
+
*
|
|
95
|
+
* Returns true iff `toolId` is in the active role's allowlist.
|
|
96
|
+
* Closes-fail by design: missing role membership = denied.
|
|
97
|
+
*/
|
|
98
|
+
isAllowed(toolId: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Async check matching the `PermissionChecker` interface — consumed
|
|
101
|
+
* by `Agent.create({ permissionChecker })`. Wraps `isAllowed` with
|
|
102
|
+
* the structured `PermissionDecision` envelope (allow / deny + a
|
|
103
|
+
* `policyRuleId` so observability can trace which role decided).
|
|
104
|
+
*
|
|
105
|
+
* Today the policy only checks the tool name (request.target).
|
|
106
|
+
* Future work: also gate by capability ('memory_write', etc.) when
|
|
107
|
+
* the role allowlist is widened to capability-by-id.
|
|
108
|
+
*/
|
|
109
|
+
check(request: PermissionRequest): Promise<PermissionDecision>;
|
|
110
|
+
/**
|
|
111
|
+
* Derive a sibling policy with a different active role. Same role
|
|
112
|
+
* map; different active role. Useful for per-identity routing
|
|
113
|
+
* (one policy instance per request, varying active role per caller).
|
|
114
|
+
*
|
|
115
|
+
* Returns a NEW PermissionPolicy — original is unchanged.
|
|
116
|
+
*/
|
|
117
|
+
withActiveRole(activeRole: string): PermissionPolicy;
|
|
118
|
+
/** The role name currently active. Useful for observability. */
|
|
119
|
+
get activeRole(): string;
|
|
120
|
+
/** All defined role names. Stable order = registration order. */
|
|
121
|
+
get roles(): readonly string[];
|
|
122
|
+
/** All tool ids allowed under the current active role. */
|
|
123
|
+
allowedToolIds(): readonly string[];
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=PermissionPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PermissionPolicy.d.ts","sourceRoot":"","sources":["../../../src/security/PermissionPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;AAExE,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,iBAAiB;IAGpC,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFzC,QAAQ,CAAC,IAAI,sBAAsB;IAEnC,OAAO;IAUP;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,GAAG,gBAAgB;IAI5E;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIlC;;;;;;;;;OASG;IACG,KAAK,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAepE;;;;;;OAMG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB;IAIpD,gEAAgE;IAChE,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,iEAAiE;IACjE,IAAI,KAAK,IAAI,SAAS,MAAM,EAAE,CAE7B;IAED,0DAA0D;IAC1D,cAAc,IAAI,SAAS,MAAM,EAAE;CAGpC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentfootprint/security — cross-cutting authorization + governance.
|
|
3
|
+
*
|
|
4
|
+
* Permissions are NOT context engineering — they're a guard ON
|
|
5
|
+
* context-engineering operations (tool dispatch, skill activation,
|
|
6
|
+
* memory writes, output emission). That's why this lives in its own
|
|
7
|
+
* subpath, parallel to `agentfootprint/tool-providers` and the
|
|
8
|
+
* `agentfootprint/memory-*` and `agentfootprint/providers` subpaths.
|
|
9
|
+
*
|
|
10
|
+
* Today's surface is small and data-driven on purpose: one role
|
|
11
|
+
* allowlist primitive that satisfies BOTH the v2.4 `PermissionChecker`
|
|
12
|
+
* interface AND a sync `isAllowed(toolId)` predicate for use with
|
|
13
|
+
* `gatedTools` from `agentfootprint/tool-providers`.
|
|
14
|
+
*
|
|
15
|
+
* Future additions (capability gating, gate_open flows, audit logs)
|
|
16
|
+
* land here without expanding the public root barrel.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* import { PermissionPolicy } from 'agentfootprint/security';
|
|
20
|
+
* import { gatedTools, staticTools } from 'agentfootprint/tool-providers';
|
|
21
|
+
*
|
|
22
|
+
* const policy = PermissionPolicy.fromRoles(
|
|
23
|
+
* {
|
|
24
|
+
* readonly: ['lookup', 'list_skills', 'read_skill'],
|
|
25
|
+
* admin: ['lookup', 'list_skills', 'read_skill', 'write', 'delete'],
|
|
26
|
+
* },
|
|
27
|
+
* 'readonly',
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* const provider = gatedTools(
|
|
31
|
+
* staticTools(allTools),
|
|
32
|
+
* (name) => policy.isAllowed(name),
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* const agent = Agent.create({ provider, model, permissionChecker: policy }).build();
|
|
36
|
+
*/
|
|
37
|
+
export { PermissionPolicy } from './PermissionPolicy.js';
|
|
38
|
+
export type { RoleAllowlist, PermissionPolicyOptions } from './PermissionPolicy.js';
|
|
39
|
+
export type { PermissionChecker, PermissionRequest, PermissionDecision, } from '../adapters/types.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAMpF,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gatedTools — wrap any ToolProvider with a per-tool gating predicate.
|
|
3
|
+
*
|
|
4
|
+
* The DECORATOR for tool providers. Filters the inner provider's
|
|
5
|
+
* output by running the predicate against each tool name. Composes
|
|
6
|
+
* freely:
|
|
7
|
+
*
|
|
8
|
+
* gatedTools(
|
|
9
|
+
* gatedTools(staticTools(allTools), readOnlyPredicate),
|
|
10
|
+
* skillGatePredicate,
|
|
11
|
+
* )
|
|
12
|
+
*
|
|
13
|
+
* Reads as: "static list of all tools, filtered by readonly policy,
|
|
14
|
+
* then further filtered by the active skill's tool set." Each gate
|
|
15
|
+
* is one concern; composition handles the rest.
|
|
16
|
+
*
|
|
17
|
+
* Pattern: Decorator (GoF) — wraps any ToolProvider with an additional
|
|
18
|
+
* filter. Mirrors `withRetry` / `withFallback` over LLMProvider.
|
|
19
|
+
*
|
|
20
|
+
* @example Read-only enforcement
|
|
21
|
+
* const readOnly = gatedTools(
|
|
22
|
+
* staticTools([read, write]),
|
|
23
|
+
* (toolName) => toolName.startsWith('read_'),
|
|
24
|
+
* );
|
|
25
|
+
* readOnly.list(ctx); // → [read]
|
|
26
|
+
*
|
|
27
|
+
* @example Skill-gated dispatch (autoActivate use case)
|
|
28
|
+
* const skillGated = gatedTools(
|
|
29
|
+
* staticTools(allTools),
|
|
30
|
+
* (toolName, ctx) => ctx.activeSkillId
|
|
31
|
+
* ? skillToolMap[ctx.activeSkillId].includes(toolName)
|
|
32
|
+
* : alwaysVisible.includes(toolName),
|
|
33
|
+
* );
|
|
34
|
+
*/
|
|
35
|
+
import type { ToolProvider, ToolGatePredicate } from './types.js';
|
|
36
|
+
export declare function gatedTools(inner: ToolProvider, predicate: ToolGatePredicate): ToolProvider;
|
|
37
|
+
//# sourceMappingURL=gatedTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gatedTools.d.ts","sourceRoot":"","sources":["../../../src/tool-providers/gatedTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAuB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGvF,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,GAAG,YAAY,CAc1F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentfootprint/tool-providers — chainable tool dispatch + tool sources.
|
|
3
|
+
*
|
|
4
|
+
* Two layers under one subpath:
|
|
5
|
+
*
|
|
6
|
+
* 1. Tool dispatch (this folder)
|
|
7
|
+
* - `staticTools(arr)` — wrap a flat tool list
|
|
8
|
+
* - `gatedTools(inner, predicate)` — decorator that filters
|
|
9
|
+
* - `ToolProvider` interface — the contract
|
|
10
|
+
* - `ToolDispatchContext` — read-only context per iteration
|
|
11
|
+
*
|
|
12
|
+
* 2. Tool sources (re-exported from existing modules)
|
|
13
|
+
* - `mcpClient(opts)` — connect to an MCP server (real)
|
|
14
|
+
* - `mockMcpClient({ tools })` — in-memory MCP source for dev / tests
|
|
15
|
+
*
|
|
16
|
+
* Compose freely. The dispatch layer is decorator-shaped (mirroring
|
|
17
|
+
* `withRetry` / `withFallback` over LLMProvider). Tool sources produce
|
|
18
|
+
* `Tool[]` that flow into a `staticTools(arr)` provider, which can
|
|
19
|
+
* then be wrapped by `gatedTools(...)` for permission gating or
|
|
20
|
+
* per-skill filtering.
|
|
21
|
+
*
|
|
22
|
+
* @example Static (90% case — what `agent.tools(arr)` does today)
|
|
23
|
+
* const provider = staticTools([weatherTool, lookupTool]);
|
|
24
|
+
*
|
|
25
|
+
* @example Read-only enforcement
|
|
26
|
+
* const readOnly = gatedTools(
|
|
27
|
+
* staticTools(allTools),
|
|
28
|
+
* (name) => policy.isAllowed(name),
|
|
29
|
+
* );
|
|
30
|
+
*
|
|
31
|
+
* @example MCP source + permission gate
|
|
32
|
+
* const slack = await mcpClient({ transport: ... });
|
|
33
|
+
* const slackTools = await slack.tools();
|
|
34
|
+
* const provider = gatedTools(staticTools(slackTools), (name) => allowed(name));
|
|
35
|
+
*/
|
|
36
|
+
export { staticTools } from './staticTools.js';
|
|
37
|
+
export { gatedTools } from './gatedTools.js';
|
|
38
|
+
export { skillScopedTools } from './skillScopedTools.js';
|
|
39
|
+
export type { ToolProvider, ToolDispatchContext, ToolGatePredicate } from './types.js';
|
|
40
|
+
export { mcpClient, mockMcpClient } from '../lib/mcp/index.js';
|
|
41
|
+
export type { McpClient, McpClientOptions, McpTransport, McpStdioTransport, McpHttpTransport, MockMcpClientOptions, MockMcpTool, } from '../lib/mcp/index.js';
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tool-providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAKvF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC/D,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,GACZ,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skillScopedTools — ToolProvider that exposes a tool subset only when
|
|
3
|
+
* a specific Skill is active in the current iteration's context.
|
|
4
|
+
*
|
|
5
|
+
* The Block A5 piece. Pairs with `defineSkill({ autoActivate: 'currentSkill' })`
|
|
6
|
+
* to give the LLM a sharper choice space: when `billing` activates, the
|
|
7
|
+
* tool list flips from "all 25 agent tools" to "the 7 billing tools" +
|
|
8
|
+
* any baseline (always-on) tools the consumer composes alongside.
|
|
9
|
+
*
|
|
10
|
+
* Pattern: gated ToolProvider keyed by `ctx.activeSkillId`. Pure compute;
|
|
11
|
+
* no Agent-runtime dependency. Composes freely with `staticTools`
|
|
12
|
+
* for the always-on baseline.
|
|
13
|
+
*
|
|
14
|
+
* @example One skill's tools, scoped by activation
|
|
15
|
+
* const billingTools = skillScopedTools('billing', [refundTool, chargeTool]);
|
|
16
|
+
* billingTools.list({ iteration: 1, activeSkillId: 'billing', identity: ... });
|
|
17
|
+
* // → [refundTool, chargeTool]
|
|
18
|
+
* billingTools.list({ iteration: 1, activeSkillId: 'refund', identity: ... });
|
|
19
|
+
* // → [] (different skill active)
|
|
20
|
+
* billingTools.list({ iteration: 1, identity: ... });
|
|
21
|
+
* // → [] (no skill active)
|
|
22
|
+
*
|
|
23
|
+
* @example Compose with baseline + multiple skills
|
|
24
|
+
* const baseline = staticTools([lookupOrderTool, listSkills, readSkill]);
|
|
25
|
+
* const billingTbx = skillScopedTools('billing', [refundTool, chargeTool]);
|
|
26
|
+
* const refundTbx = skillScopedTools('refund', [reverseTool]);
|
|
27
|
+
*
|
|
28
|
+
* // Wrap each scope-provider in a gatedTools for downstream composition,
|
|
29
|
+
* // OR build a small wrapper that concatenates list(ctx) outputs:
|
|
30
|
+
* const provider: ToolProvider = {
|
|
31
|
+
* id: 'composite',
|
|
32
|
+
* list: (ctx) => [
|
|
33
|
+
* ...baseline.list(ctx),
|
|
34
|
+
* ...billingTbx.list(ctx),
|
|
35
|
+
* ...refundTbx.list(ctx),
|
|
36
|
+
* ],
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* Note: the runtime that POPULATES `ctx.activeSkillId` from
|
|
40
|
+
* `scope.activatedInjectionIds` lands in Block C / v2.5+. Today,
|
|
41
|
+
* consumers can drive it manually for tests + design-time inspection.
|
|
42
|
+
*/
|
|
43
|
+
import type { Tool } from '../core/tools.js';
|
|
44
|
+
import type { ToolProvider } from './types.js';
|
|
45
|
+
export declare function skillScopedTools(skillId: string, tools: readonly Tool[]): ToolProvider;
|
|
46
|
+
//# sourceMappingURL=skillScopedTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skillScopedTools.d.ts","sourceRoot":"","sources":["../../../src/tool-providers/skillScopedTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAGpE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,YAAY,CAgBtF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* staticTools — the simplest ToolProvider. Wraps a fixed Tool[] list.
|
|
3
|
+
*
|
|
4
|
+
* 90% case. What `agent.tools(arr)` does today, made composable.
|
|
5
|
+
* Equivalent to passing `arr` directly EXCEPT that `staticTools(arr)`
|
|
6
|
+
* is now a `ToolProvider` you can wrap with `gatedTools(...)` for
|
|
7
|
+
* permission filtering or per-skill gating.
|
|
8
|
+
*
|
|
9
|
+
* Pattern: identity ToolProvider — no filtering, just exposes the
|
|
10
|
+
* underlying list verbatim.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const provider = staticTools([weatherTool, lookupTool]);
|
|
14
|
+
* // Materialize the visible list and register via .tools(...).
|
|
15
|
+
* // Direct .toolProvider(...) wiring on the builder lands in Block A5 / v2.5+.
|
|
16
|
+
* const visible = provider.list({ iteration: 0, identity: { conversationId: '_' } });
|
|
17
|
+
* const agent = Agent.create({ provider: llm, model }).tools(visible).build();
|
|
18
|
+
*/
|
|
19
|
+
import type { Tool } from '../core/tools.js';
|
|
20
|
+
import type { ToolProvider } from './types.js';
|
|
21
|
+
export declare function staticTools(tools: readonly Tool[]): ToolProvider;
|
|
22
|
+
//# sourceMappingURL=staticTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticTools.d.ts","sourceRoot":"","sources":["../../../src/tool-providers/staticTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,YAAY,CAAC;AAGpE,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,YAAY,CAWhE"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolProvider — abstraction over tool dispatch.
|
|
3
|
+
*
|
|
4
|
+
* v2.4 shipped tools as a flat array on the agent (registered via
|
|
5
|
+
* `agent.tool(t)` / `agent.tools(arr)`). That model breaks down once
|
|
6
|
+
* production agents need:
|
|
7
|
+
* 1. Permission gating per-tool, per-caller (read-only roles, etc.)
|
|
8
|
+
* 2. Per-skill tool gating (only show the active skill's tools to
|
|
9
|
+
* the LLM each turn)
|
|
10
|
+
* 3. Composable filters (a `withReadonly` decorator over a `withSkill`
|
|
11
|
+
* decorator over the base tool list)
|
|
12
|
+
*
|
|
13
|
+
* `ToolProvider` is the answer: a chainable abstraction over "what
|
|
14
|
+
* tools does the LLM see right now?". The agent asks the provider
|
|
15
|
+
* each iteration; the provider returns the visible tool set computed
|
|
16
|
+
* from whatever predicates / role gates / skill filters the consumer
|
|
17
|
+
* composed.
|
|
18
|
+
*
|
|
19
|
+
* Pattern: Strategy (GoF) — each ToolProvider is a strategy for
|
|
20
|
+
* "compute the visible tool list given current context".
|
|
21
|
+
* Decorator (GoF) — `gatedTools(inner, predicate)` wraps any
|
|
22
|
+
* provider with an additional filter, mirroring how `withRetry`
|
|
23
|
+
* / `withFallback` decorate `LLMProvider`.
|
|
24
|
+
* Role: Layer-3 tool-dispatch primitive. Agent calls `provider.list(ctx)`
|
|
25
|
+
* each iteration to compute the visible tool set.
|
|
26
|
+
* Emits: N/A (pure compute; permission denials emit elsewhere via the
|
|
27
|
+
* permission subsystem).
|
|
28
|
+
*
|
|
29
|
+
* @example Static tool list (90% case — what `.tools(arr)` does today)
|
|
30
|
+
* const provider = staticTools([weather, lookupOrder]);
|
|
31
|
+
*
|
|
32
|
+
* @example Read-only enforcement (role-based gate)
|
|
33
|
+
* const readOnlyProvider = gatedTools(
|
|
34
|
+
* staticTools([weather, lookupOrder, processRefund]),
|
|
35
|
+
* (toolName) => policy.isAllowed(toolName),
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* @example Skill-gated dispatch (only active skill's tools visible)
|
|
39
|
+
* const skillGated = gatedTools(
|
|
40
|
+
* staticTools(allTools),
|
|
41
|
+
* (toolName, ctx) => ctx.activeSkillId
|
|
42
|
+
* ? skillsToolMap[ctx.activeSkillId].includes(toolName)
|
|
43
|
+
* : alwaysVisible.includes(toolName),
|
|
44
|
+
* );
|
|
45
|
+
*
|
|
46
|
+
* @example Stack: read-only over skill-gated
|
|
47
|
+
* const provider = gatedTools(
|
|
48
|
+
* gatedTools(staticTools(allTools), readOnlyPredicate),
|
|
49
|
+
* skillGatePredicate,
|
|
50
|
+
* );
|
|
51
|
+
*/
|
|
52
|
+
import type { Tool } from '../core/tools.js';
|
|
53
|
+
/**
|
|
54
|
+
* Read-only context the provider receives each iteration. Pure data
|
|
55
|
+
* — providers MUST NOT mutate. Used by gating predicates to inspect
|
|
56
|
+
* the current activation state.
|
|
57
|
+
*/
|
|
58
|
+
export interface ToolDispatchContext {
|
|
59
|
+
/** Current ReAct iteration (1-based). */
|
|
60
|
+
readonly iteration: number;
|
|
61
|
+
/**
|
|
62
|
+
* The id of the currently-activated Skill, if any.
|
|
63
|
+
* Set by `read_skill(id)` activation; cleared between turns.
|
|
64
|
+
* Used by `autoActivate`-driven per-skill tool gating.
|
|
65
|
+
*/
|
|
66
|
+
readonly activeSkillId?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Caller identity tuple — passed through from `agent.run({ identity })`.
|
|
69
|
+
* Permission predicates can role-check based on `identity.principal`
|
|
70
|
+
* or `identity.tenant`.
|
|
71
|
+
*/
|
|
72
|
+
readonly identity?: {
|
|
73
|
+
readonly tenant?: string;
|
|
74
|
+
readonly principal?: string;
|
|
75
|
+
readonly conversationId: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The provider interface. A `ToolProvider` answers ONE question per
|
|
80
|
+
* iteration: "what tools should the LLM see right now?"
|
|
81
|
+
*
|
|
82
|
+
* Implementations are PURE — given the same context, return the same
|
|
83
|
+
* tool list. No async (the answer is needed synchronously each
|
|
84
|
+
* iteration; if you need async filtering, precompute upstream).
|
|
85
|
+
*/
|
|
86
|
+
export interface ToolProvider {
|
|
87
|
+
/**
|
|
88
|
+
* Return the tool list visible to the LLM for the current iteration.
|
|
89
|
+
* The returned array MUST be a NEW reference each call (the agent
|
|
90
|
+
* compares for change detection). Order is preserved — the LLM may
|
|
91
|
+
* use position as a hint when tool descriptions are ambiguous.
|
|
92
|
+
*/
|
|
93
|
+
list(ctx: ToolDispatchContext): readonly Tool[];
|
|
94
|
+
/**
|
|
95
|
+
* Optional: stable id for observability / debugging. Defaults to
|
|
96
|
+
* `'static'` for `staticTools`, `'gated'` for `gatedTools`. Custom
|
|
97
|
+
* implementations should set their own id.
|
|
98
|
+
*/
|
|
99
|
+
readonly id?: string;
|
|
100
|
+
}
|
|
101
|
+
/** Predicate for `gatedTools` — runs per tool, per iteration. */
|
|
102
|
+
export type ToolGatePredicate = (toolName: string, ctx: ToolDispatchContext) => boolean;
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tool-providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAClB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;KACjC,CAAC;CACH;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,mBAAmB,GAAG,SAAS,IAAI,EAAE,CAAC;IAEhD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,iEAAiE;AACjE,MAAM,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC"}
|