agentfootprint 7.11.0 → 7.13.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/dist/core/Agent.js +52 -7
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +59 -1
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +6 -0
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +14 -0
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/callLLM.js +10 -4
- package/dist/core/agent/stages/callLLM.js.map +1 -1
- package/dist/core/agent/stages/seed.js +16 -0
- package/dist/core/agent/stages/seed.js.map +1 -1
- package/dist/core/slots/buildSystemPromptSlot.js +2 -1
- package/dist/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/debug.js +5 -2
- package/dist/debug.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +11 -3
- package/dist/esm/core/Agent.js +52 -7
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +48 -1
- package/dist/esm/core/agent/AgentBuilder.js +59 -1
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.js +6 -0
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +14 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/stages/callLLM.d.ts +9 -0
- package/dist/esm/core/agent/stages/callLLM.js +10 -4
- package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
- package/dist/esm/core/agent/stages/seed.d.ts +10 -1
- package/dist/esm/core/agent/stages/seed.js +16 -0
- package/dist/esm/core/agent/stages/seed.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +69 -1
- package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +19 -4
- package/dist/esm/core/slots/buildSystemPromptSlot.js +2 -1
- package/dist/esm/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/esm/debug.d.ts +2 -2
- package/dist/esm/debug.js +2 -2
- package/dist/esm/debug.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/context-bisect/index.d.ts +3 -1
- package/dist/esm/lib/context-bisect/index.js +5 -0
- package/dist/esm/lib/context-bisect/index.js.map +1 -1
- package/dist/esm/lib/context-bisect/trajectory.d.ts +8 -0
- package/dist/esm/lib/context-bisect/trajectory.js +10 -3
- package/dist/esm/lib/context-bisect/trajectory.js.map +1 -1
- package/dist/esm/lib/context-bisect/variable-recall.d.ts +171 -0
- package/dist/esm/lib/context-bisect/variable-recall.js +0 -0
- package/dist/esm/lib/context-bisect/variable-recall.js.map +1 -0
- package/dist/esm/lib/context-bisect/variableToBacktrackTrace.d.ts +53 -0
- package/dist/esm/lib/context-bisect/variableToBacktrackTrace.js +142 -0
- package/dist/esm/lib/context-bisect/variableToBacktrackTrace.js.map +1 -0
- package/dist/esm/lib/context-bisect/walk-to-root.d.ts +37 -2
- package/dist/esm/lib/context-bisect/walk-to-root.js +61 -6
- package/dist/esm/lib/context-bisect/walk-to-root.js.map +1 -1
- package/dist/esm/lib/injection-engine/index.d.ts +1 -0
- package/dist/esm/lib/injection-engine/index.js +4 -0
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillsFromDir.d.ts +80 -0
- package/dist/esm/lib/injection-engine/skillsFromDir.js +243 -0
- package/dist/esm/lib/injection-engine/skillsFromDir.js.map +1 -0
- package/dist/esm/lib/mcp/index.d.ts +6 -5
- package/dist/esm/lib/mcp/index.js +5 -4
- package/dist/esm/lib/mcp/index.js.map +1 -1
- package/dist/esm/lib/mcp/mcpClient.js +21 -9
- package/dist/esm/lib/mcp/mcpClient.js.map +1 -1
- package/dist/esm/lib/mcp/mcpServe.d.ts +70 -0
- package/dist/esm/lib/mcp/mcpServe.js +374 -0
- package/dist/esm/lib/mcp/mcpServe.js.map +1 -0
- package/dist/esm/lib/mcp/types.d.ts +130 -17
- package/dist/esm/lib/mcp/types.js +10 -10
- package/dist/esm/tool-providers/index.d.ts +8 -2
- package/dist/esm/tool-providers/index.js +7 -1
- package/dist/esm/tool-providers/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/context-bisect/index.js +9 -1
- package/dist/lib/context-bisect/index.js.map +1 -1
- package/dist/lib/context-bisect/trajectory.js +10 -3
- package/dist/lib/context-bisect/trajectory.js.map +1 -1
- package/dist/lib/context-bisect/variable-recall.js +0 -0
- package/dist/lib/context-bisect/variable-recall.js.map +1 -0
- package/dist/lib/context-bisect/variableToBacktrackTrace.js +146 -0
- package/dist/lib/context-bisect/variableToBacktrackTrace.js.map +1 -0
- package/dist/lib/context-bisect/walk-to-root.js +61 -6
- package/dist/lib/context-bisect/walk-to-root.js.map +1 -1
- package/dist/lib/injection-engine/index.js +6 -1
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillsFromDir.js +270 -0
- package/dist/lib/injection-engine/skillsFromDir.js.map +1 -0
- package/dist/lib/mcp/index.js +7 -5
- package/dist/lib/mcp/index.js.map +1 -1
- package/dist/lib/mcp/mcpClient.js +21 -9
- package/dist/lib/mcp/mcpClient.js.map +1 -1
- package/dist/lib/mcp/mcpServe.js +401 -0
- package/dist/lib/mcp/mcpServe.js.map +1 -0
- package/dist/lib/mcp/types.js +10 -10
- package/dist/tool-providers/index.js +8 -1
- package/dist/tool-providers/index.js.map +1 -1
- package/dist/types/core/Agent.d.ts +11 -3
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts +48 -1
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/callLLM.d.ts +9 -0
- package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
- package/dist/types/core/agent/stages/seed.d.ts +10 -1
- package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +69 -1
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/slots/buildSystemPromptSlot.d.ts +19 -4
- package/dist/types/core/slots/buildSystemPromptSlot.d.ts.map +1 -1
- package/dist/types/debug.d.ts +2 -2
- package/dist/types/debug.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/index.d.ts +3 -1
- package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/trajectory.d.ts +8 -0
- package/dist/types/lib/context-bisect/trajectory.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/variable-recall.d.ts +172 -0
- package/dist/types/lib/context-bisect/variable-recall.d.ts.map +1 -0
- package/dist/types/lib/context-bisect/variableToBacktrackTrace.d.ts +54 -0
- package/dist/types/lib/context-bisect/variableToBacktrackTrace.d.ts.map +1 -0
- package/dist/types/lib/context-bisect/walk-to-root.d.ts +37 -2
- package/dist/types/lib/context-bisect/walk-to-root.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/index.d.ts +1 -0
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillsFromDir.d.ts +81 -0
- package/dist/types/lib/injection-engine/skillsFromDir.d.ts.map +1 -0
- package/dist/types/lib/mcp/index.d.ts +6 -5
- package/dist/types/lib/mcp/index.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpServe.d.ts +71 -0
- package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -0
- package/dist/types/lib/mcp/types.d.ts +130 -17
- package/dist/types/lib/mcp/types.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +8 -2
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -18,7 +18,7 @@ export function buildWriterFrameIndex(trajectory) {
|
|
|
18
18
|
});
|
|
19
19
|
return map;
|
|
20
20
|
}
|
|
21
|
-
/** Map each suspectId present in a frame to
|
|
21
|
+
/** Map each suspectId present in a frame to its {@link SuspectOrigin}. */
|
|
22
22
|
function writtenByOf(frame) {
|
|
23
23
|
const map = new Map();
|
|
24
24
|
for (const src of frame.contextSources) {
|
|
@@ -28,7 +28,7 @@ function writtenByOf(frame) {
|
|
|
28
28
|
for (const rec of v) {
|
|
29
29
|
const id = typeof rec.sourceId === 'string' ? rec.sourceId : undefined;
|
|
30
30
|
if (id !== undefined && !map.has(id))
|
|
31
|
-
map.set(id, src.writerId);
|
|
31
|
+
map.set(id, { writerId: src.writerId, stateKey: src.key });
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
else if (v !== null &&
|
|
@@ -37,7 +37,7 @@ function writtenByOf(frame) {
|
|
|
37
37
|
// lastToolResult: a { toolName, result } object → the tool suspect
|
|
38
38
|
const tool = v.toolName;
|
|
39
39
|
if (!map.has(tool))
|
|
40
|
-
map.set(tool, src.writerId);
|
|
40
|
+
map.set(tool, { writerId: src.writerId, stateKey: src.key });
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
// The WALK-ONLY proximate tool source (proposal 008) — the cross-loop descent edge. NOT in
|
|
@@ -46,10 +46,46 @@ function writtenByOf(frame) {
|
|
|
46
46
|
if (tool && typeof tool.value?.toolName === 'string') {
|
|
47
47
|
const name = tool.value.toolName;
|
|
48
48
|
if (!map.has(name))
|
|
49
|
-
map.set(name, tool.writerId);
|
|
49
|
+
map.set(name, { writerId: tool.writerId, stateKey: tool.stateKey });
|
|
50
50
|
}
|
|
51
51
|
return map;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The DETERMINISTIC descent: the write that produced the value this loop's
|
|
55
|
+
* `call-llm` read of `stateKey` — straight off the recorded moments, no
|
|
56
|
+
* embedding involved.
|
|
57
|
+
*
|
|
58
|
+
* Preference order, both commit-log facts:
|
|
59
|
+
* 1. the read moment BY this loop's call-llm → its `fromWriteIdx` → that
|
|
60
|
+
* write (exact value identity — footprintjs pins the same rule its forward
|
|
61
|
+
* walk uses);
|
|
62
|
+
* 2. otherwise the last write strictly before the call-llm's commit (the key
|
|
63
|
+
* the call-llm did not read directly — e.g. an inferred proximate).
|
|
64
|
+
*
|
|
65
|
+
* Returns `undefined` unless coverage is EXACT: a conservative (stage-level)
|
|
66
|
+
* edge must never be presented as an exact hop.
|
|
67
|
+
*/
|
|
68
|
+
function dataflowWriter(slice, frame) {
|
|
69
|
+
const coverage = slice?.coverage;
|
|
70
|
+
if (slice === undefined || coverage !== 'exact')
|
|
71
|
+
return undefined;
|
|
72
|
+
// Grouped frames index a subflow's OWN inner log; a run-log slice cannot be
|
|
73
|
+
// joined to them (see LoopFrame.subflowScope).
|
|
74
|
+
if (frame.subflowScope !== undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
const writes = slice.moments.filter((m) => m.kind === 'write');
|
|
77
|
+
const read = frame.llmCallId !== undefined
|
|
78
|
+
? slice.moments.find((m) => m.kind === 'read' && m.runtimeStageId === frame.llmCallId)
|
|
79
|
+
: undefined;
|
|
80
|
+
if (read?.fromWriteIdx !== undefined) {
|
|
81
|
+
return writes.find((w) => w.commitIdx === read.fromWriteIdx);
|
|
82
|
+
}
|
|
83
|
+
const llmIdx = frame.llmCallArrayIdx;
|
|
84
|
+
if (llmIdx === undefined)
|
|
85
|
+
return undefined;
|
|
86
|
+
const before = writes.filter((w) => w.commitIdx < llmIdx);
|
|
87
|
+
return before.length > 0 ? before[before.length - 1] : undefined;
|
|
88
|
+
}
|
|
53
89
|
/** A minimal Suspect for ablationForSuspect (only kind + detail identity are read). */
|
|
54
90
|
function suspectFor(suspectId, kind) {
|
|
55
91
|
const detail = kind === 'tool' ? { toolName: suspectId } : { injectionId: suspectId };
|
|
@@ -89,6 +125,8 @@ export async function walkTrajectory(trajectory, opts) {
|
|
|
89
125
|
});
|
|
90
126
|
}
|
|
91
127
|
const writerFrame = buildWriterFrameIndex(trajectory);
|
|
128
|
+
const variables = new Map((opts.variables ?? []).map((v) => [v.key, v]));
|
|
129
|
+
const variableOf = (key) => variables.get(key);
|
|
92
130
|
// Baseline stability (the un-ablated scenario must reproduce for any ablation verdict to be trusted).
|
|
93
131
|
let baselineStable = true;
|
|
94
132
|
let ablationsUsed = 0;
|
|
@@ -148,17 +186,34 @@ export async function walkTrajectory(trajectory, opts) {
|
|
|
148
186
|
}
|
|
149
187
|
}
|
|
150
188
|
}
|
|
189
|
+
// NARROW → HOP. The beam picked WHO; this picks WHERE. When the narrowed
|
|
190
|
+
// suspect rode in on a state key whose dataflow is per-write EXACT, WHERE is
|
|
191
|
+
// a commit-log fact — the write that produced the value THIS loop read —
|
|
192
|
+
// instead of a provenance scrape or an inferred proximate. Absent
|
|
193
|
+
// `variables`, `exactWriter` is always undefined and nothing below changes.
|
|
194
|
+
const beamOrigin = writtenBy.get(chosen.suspectId);
|
|
195
|
+
const exactWrite = beamOrigin?.stateKey !== undefined
|
|
196
|
+
? dataflowWriter(variableOf(beamOrigin.stateKey), frame)
|
|
197
|
+
: undefined;
|
|
198
|
+
const exactFrameIdx = exactWrite !== undefined ? writerFrame.get(exactWrite.runtimeStageId) : undefined;
|
|
199
|
+
const exactWriter = exactWrite !== undefined && exactFrameIdx !== undefined && exactFrameIdx < frameIdx
|
|
200
|
+
? exactWrite.runtimeStageId
|
|
201
|
+
: undefined; // strictly backward, or it is no descent at all
|
|
151
202
|
// The proximate tool source (walk-only, proposal 008) is the cross-loop DESCENT edge. When this
|
|
152
203
|
// loop did NOT convict, follow it back to the loop that PRODUCED the tool output the decision was
|
|
153
204
|
// conditioned on — that's where a buried root (e.g. the misdirecting instruction) scores + convicts.
|
|
205
|
+
// It is an INFERRED proximate (`call-llm` read `history`, not this key), so a RECORDED exact edge
|
|
206
|
+
// for the narrowed suspect outranks it: better evidence wins, and the hop says which it used.
|
|
154
207
|
const toolName = !convicted &&
|
|
208
|
+
exactWriter === undefined &&
|
|
155
209
|
frame.proximateToolSource &&
|
|
156
210
|
typeof frame.proximateToolSource.value?.toolName === 'string'
|
|
157
211
|
? frame.proximateToolSource.value.toolName
|
|
158
212
|
: undefined;
|
|
159
213
|
if (toolName !== undefined)
|
|
160
214
|
chosen = { suspectId: toolName, kind: 'tool' };
|
|
161
|
-
const
|
|
215
|
+
const narrowedBy = exactWriter !== undefined ? 'dataflow' : 'text-similarity';
|
|
216
|
+
const writer = exactWriter ?? writtenBy.get(chosen.suspectId)?.writerId;
|
|
162
217
|
const nextFrameIdx = writer !== undefined ? writerFrame.get(writer) : undefined;
|
|
163
218
|
const descendIdx = nextFrameIdx !== undefined && nextFrameIdx < frameIdx ? nextFrameIdx : undefined; // strictly backward
|
|
164
219
|
// Per-hop honest note: untracked-origin (structural — no provenance writer to descend) is set
|
|
@@ -172,7 +227,7 @@ export async function walkTrajectory(trajectory, opts) {
|
|
|
172
227
|
loopIndex: frame.loopIndex,
|
|
173
228
|
suspectId: chosen.suspectId,
|
|
174
229
|
kind: chosen.kind,
|
|
175
|
-
narrowedBy
|
|
230
|
+
narrowedBy,
|
|
176
231
|
...(chosenVerdict ? { verdict: chosenVerdict } : {}),
|
|
177
232
|
...(writer !== undefined ? { writtenBy: writer } : {}),
|
|
178
233
|
...(descendIdx !== undefined ? { cameFrom: trajectory.frames[descendIdx].loopIndex } : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk-to-root.js","sourceRoot":"","sources":["../../../../src/lib/context-bisect/walk-to-root.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"walk-to-root.js","sourceRoot":"","sources":["../../../../src/lib/context-bisect/walk-to-root.ts"],"names":[],"mappings":"AA0CA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAA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AK,SAAS,EAAE,CAAC;YAC5D,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC;QAC5E,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzB,YAAY;QACZ,GAAG,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC"}
|
|
@@ -13,6 +13,7 @@ export { defineInstruction, type DefineInstructionOptions } from './factories/de
|
|
|
13
13
|
export { defineRelevanceHint, type RelevanceHintOptions } from './factories/defineRelevanceHint.js';
|
|
14
14
|
export { defineSkill, resolveSurfaceMode, type DefineSkillOptions, type SurfaceMode, type RefreshPolicy, type AutoActivateMode, } from './factories/defineSkill.js';
|
|
15
15
|
export { SkillRegistry, type SkillRegistryOptions } from './SkillRegistry.js';
|
|
16
|
+
export { skillsFromDir, type SkillsFromDirOptions } from './skillsFromDir.js';
|
|
16
17
|
export { buildListSkillsTool, buildReadSkillTool, type SkillToolPair } from './skillTools.js';
|
|
17
18
|
export { defineSteering, type DefineSteeringOptions } from './factories/defineSteering.js';
|
|
18
19
|
export { defineFact, type DefineFactOptions } from './factories/defineFact.js';
|
|
@@ -15,6 +15,10 @@ export { defineInstruction } from './factories/defineInstruction.js';
|
|
|
15
15
|
export { defineRelevanceHint } from './factories/defineRelevanceHint.js';
|
|
16
16
|
export { defineSkill, resolveSurfaceMode, } from './factories/defineSkill.js';
|
|
17
17
|
export { SkillRegistry } from './SkillRegistry.js';
|
|
18
|
+
// File-authored skills — a loader over `defineSkill`, not a second mechanism.
|
|
19
|
+
// Node-only (reads the filesystem); node:fs is imported lazily inside the call
|
|
20
|
+
// so this barrel stays safe to import from a browser bundle.
|
|
21
|
+
export { skillsFromDir } from './skillsFromDir.js';
|
|
18
22
|
// Skill-tool builders — used by SkillRegistry.toTools() and the Agent's
|
|
19
23
|
// auto-attach path. Exported so consumers building custom tool wiring
|
|
20
24
|
// (e.g., gatedTools chains) can compose the same `list_skills` /
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/injection-engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,+DAA+D;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,SAAS;AACT,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EACL,2BAA2B,GAE5B,MAAM,kCAAkC,CAAC;AAE1C,gFAAgF;AAChF,OAAO,EAAE,iBAAiB,EAAiC,MAAM,kCAAkC,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAA6B,MAAM,oCAAoC,CAAC;AAEpG,OAAO,EACL,WAAW,EACX,kBAAkB,GAKnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAE9E,wEAAwE;AACxE,sEAAsE;AACtE,iEAAiE;AACjE,+BAA+B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAsB,MAAM,iBAAiB,CAAC;AAE9F,OAAO,EAAE,cAAc,EAA8B,MAAM,+BAA+B,CAAC;AAE3F,OAAO,EAAE,UAAU,EAA0B,MAAM,2BAA2B,CAAC;AAE/E,6EAA6E;AAC7E,0EAA0E;AAC1E,qDAAqD;AACrD,OAAO,EACL,eAAe,GAGhB,MAAM,gCAAgC,CAAC;AAExC,4EAA4E;AAC5E,8EAA8E;AAC9E,OAAO,EACL,UAAU,EACV,WAAW,EACX,wBAAwB,GAoBzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,aAAa,EACb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,WAAW,GAIZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skillsFromDir — load Skills that were AUTHORED AS FILES.
|
|
3
|
+
*
|
|
4
|
+
* The just-in-time half of skills already ships: `defineSkill` produces an
|
|
5
|
+
* Injection whose `description` is all the model sees until it calls
|
|
6
|
+
* `read_skill(<id>)`, at which point the body enters the context. What did not
|
|
7
|
+
* ship was the other half — a way to keep those bodies where prose belongs, in
|
|
8
|
+
* files, next to the code they describe, reviewable in a diff.
|
|
9
|
+
*
|
|
10
|
+
* This is that loader, and nothing more. It reads a directory of `SKILL.md`
|
|
11
|
+
* files and hands each one to `defineSkill`. The progressive disclosure, the
|
|
12
|
+
* activation tool, the slot routing — all unchanged, all upstream of here.
|
|
13
|
+
*
|
|
14
|
+
* skills/
|
|
15
|
+
* billing/SKILL.md
|
|
16
|
+
* refunds/SKILL.md
|
|
17
|
+
*
|
|
18
|
+
* ---
|
|
19
|
+
* name: billing
|
|
20
|
+
* description: Use for refunds, charges and billing questions.
|
|
21
|
+
* ---
|
|
22
|
+
* When handling billing: confirm identity first, then …
|
|
23
|
+
*
|
|
24
|
+
* const skills = await skillsFromDir('./skills');
|
|
25
|
+
* const agent = Agent.create({ provider, model }).skills({ list: () => skills }).build();
|
|
26
|
+
*
|
|
27
|
+
* The frontmatter is the disclosure stub (`name` + `description` — what the
|
|
28
|
+
* model reads when deciding), and everything after the closing fence is the
|
|
29
|
+
* body (what it reads after deciding). That is the same file convention Claude
|
|
30
|
+
* Code made familiar, so a skill folder is portable between the two.
|
|
31
|
+
*
|
|
32
|
+
* ── Why authorship is decided here, at load time ─────────────────────────────
|
|
33
|
+
* A Skill body is *instructions to a model*. Where it came from is therefore a
|
|
34
|
+
* security property, not a convenience: content fetched at run time from
|
|
35
|
+
* somewhere else is content someone else can change after you reviewed it.
|
|
36
|
+
* This loader accepts a local directory and nothing else — a URL is refused BY
|
|
37
|
+
* NAME rather than fetched — because "these files are mine" is a claim you can
|
|
38
|
+
* only make about a path on your own disk at build time. Each file is read
|
|
39
|
+
* ONCE, here; a later edit does not reach a run already in flight.
|
|
40
|
+
*
|
|
41
|
+
* Node-only. `node:fs/promises` and `node:path` are imported lazily inside the
|
|
42
|
+
* call, the same gating `lib/tool-lint/cli.ts` uses: this module is reachable
|
|
43
|
+
* from the `agentfootprint/injection-engine` barrel, and a TOP-LEVEL node:fs
|
|
44
|
+
* import detonates a browser bundle at module-eval even when nothing calls it.
|
|
45
|
+
*/
|
|
46
|
+
import type { Injection } from './types.js';
|
|
47
|
+
import { type SurfaceMode } from './factories/defineSkill.js';
|
|
48
|
+
export interface SkillsFromDirOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Override the activation tool name for every loaded skill. Defaults to
|
|
51
|
+
* `defineSkill`'s own default, `'read_skill'`.
|
|
52
|
+
*/
|
|
53
|
+
readonly viaToolName?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Where a loaded skill's body lands once activated. Defaults to
|
|
56
|
+
* `defineSkill`'s own default, `'auto'`. See {@link SurfaceMode}.
|
|
57
|
+
*/
|
|
58
|
+
readonly surfaceMode?: SurfaceMode;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Load every `SKILL.md` under `dir` as a Skill Injection.
|
|
62
|
+
*
|
|
63
|
+
* Two layouts are accepted, and they can be mixed:
|
|
64
|
+
* - `dir/<anything>/SKILL.md` — one folder per skill (the portable layout,
|
|
65
|
+
* and the one to prefer: the folder can hold the skill's other assets).
|
|
66
|
+
* - `dir/SKILL.md` — the directory IS one skill.
|
|
67
|
+
*
|
|
68
|
+
* The returned array is sorted by skill name, so a chart built from it is
|
|
69
|
+
* stable regardless of the order the filesystem happened to hand back.
|
|
70
|
+
*
|
|
71
|
+
* @param dir - A local filesystem path. A URL (or any `scheme://` string, or a
|
|
72
|
+
* UNC network path) is refused by name — see the module header for why.
|
|
73
|
+
* @param opts - Applied uniformly to every loaded skill.
|
|
74
|
+
*
|
|
75
|
+
* @throws when `dir` is not a local path, does not exist, is not a directory,
|
|
76
|
+
* or contains no `SKILL.md` at all; when a file's frontmatter is malformed
|
|
77
|
+
* (the message names the file); or when two files claim the same skill name
|
|
78
|
+
* (the message names both).
|
|
79
|
+
*/
|
|
80
|
+
export declare function skillsFromDir(dir: string, opts?: SkillsFromDirOptions): Promise<readonly Injection[]>;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skillsFromDir — load Skills that were AUTHORED AS FILES.
|
|
3
|
+
*
|
|
4
|
+
* The just-in-time half of skills already ships: `defineSkill` produces an
|
|
5
|
+
* Injection whose `description` is all the model sees until it calls
|
|
6
|
+
* `read_skill(<id>)`, at which point the body enters the context. What did not
|
|
7
|
+
* ship was the other half — a way to keep those bodies where prose belongs, in
|
|
8
|
+
* files, next to the code they describe, reviewable in a diff.
|
|
9
|
+
*
|
|
10
|
+
* This is that loader, and nothing more. It reads a directory of `SKILL.md`
|
|
11
|
+
* files and hands each one to `defineSkill`. The progressive disclosure, the
|
|
12
|
+
* activation tool, the slot routing — all unchanged, all upstream of here.
|
|
13
|
+
*
|
|
14
|
+
* skills/
|
|
15
|
+
* billing/SKILL.md
|
|
16
|
+
* refunds/SKILL.md
|
|
17
|
+
*
|
|
18
|
+
* ---
|
|
19
|
+
* name: billing
|
|
20
|
+
* description: Use for refunds, charges and billing questions.
|
|
21
|
+
* ---
|
|
22
|
+
* When handling billing: confirm identity first, then …
|
|
23
|
+
*
|
|
24
|
+
* const skills = await skillsFromDir('./skills');
|
|
25
|
+
* const agent = Agent.create({ provider, model }).skills({ list: () => skills }).build();
|
|
26
|
+
*
|
|
27
|
+
* The frontmatter is the disclosure stub (`name` + `description` — what the
|
|
28
|
+
* model reads when deciding), and everything after the closing fence is the
|
|
29
|
+
* body (what it reads after deciding). That is the same file convention Claude
|
|
30
|
+
* Code made familiar, so a skill folder is portable between the two.
|
|
31
|
+
*
|
|
32
|
+
* ── Why authorship is decided here, at load time ─────────────────────────────
|
|
33
|
+
* A Skill body is *instructions to a model*. Where it came from is therefore a
|
|
34
|
+
* security property, not a convenience: content fetched at run time from
|
|
35
|
+
* somewhere else is content someone else can change after you reviewed it.
|
|
36
|
+
* This loader accepts a local directory and nothing else — a URL is refused BY
|
|
37
|
+
* NAME rather than fetched — because "these files are mine" is a claim you can
|
|
38
|
+
* only make about a path on your own disk at build time. Each file is read
|
|
39
|
+
* ONCE, here; a later edit does not reach a run already in flight.
|
|
40
|
+
*
|
|
41
|
+
* Node-only. `node:fs/promises` and `node:path` are imported lazily inside the
|
|
42
|
+
* call, the same gating `lib/tool-lint/cli.ts` uses: this module is reachable
|
|
43
|
+
* from the `agentfootprint/injection-engine` barrel, and a TOP-LEVEL node:fs
|
|
44
|
+
* import detonates a browser bundle at module-eval even when nothing calls it.
|
|
45
|
+
*/
|
|
46
|
+
import { defineSkill } from './factories/defineSkill.js';
|
|
47
|
+
/** The file name every skill folder is expected to use. */
|
|
48
|
+
const SKILL_FILE = 'SKILL.md';
|
|
49
|
+
/**
|
|
50
|
+
* Skill ids ride into `read_skill`'s `enum` and into the skill-graph's node
|
|
51
|
+
* ids. The house tool-name charset keeps them quotable in a prompt, comparable
|
|
52
|
+
* as plain strings, and safe as an object key.
|
|
53
|
+
*/
|
|
54
|
+
const SKILL_NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
55
|
+
/** Anything of the form `scheme://…` — http, https, s3, git+ssh, file, … */
|
|
56
|
+
const URL_LIKE_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
|
|
57
|
+
/**
|
|
58
|
+
* Load every `SKILL.md` under `dir` as a Skill Injection.
|
|
59
|
+
*
|
|
60
|
+
* Two layouts are accepted, and they can be mixed:
|
|
61
|
+
* - `dir/<anything>/SKILL.md` — one folder per skill (the portable layout,
|
|
62
|
+
* and the one to prefer: the folder can hold the skill's other assets).
|
|
63
|
+
* - `dir/SKILL.md` — the directory IS one skill.
|
|
64
|
+
*
|
|
65
|
+
* The returned array is sorted by skill name, so a chart built from it is
|
|
66
|
+
* stable regardless of the order the filesystem happened to hand back.
|
|
67
|
+
*
|
|
68
|
+
* @param dir - A local filesystem path. A URL (or any `scheme://` string, or a
|
|
69
|
+
* UNC network path) is refused by name — see the module header for why.
|
|
70
|
+
* @param opts - Applied uniformly to every loaded skill.
|
|
71
|
+
*
|
|
72
|
+
* @throws when `dir` is not a local path, does not exist, is not a directory,
|
|
73
|
+
* or contains no `SKILL.md` at all; when a file's frontmatter is malformed
|
|
74
|
+
* (the message names the file); or when two files claim the same skill name
|
|
75
|
+
* (the message names both).
|
|
76
|
+
*/
|
|
77
|
+
export async function skillsFromDir(dir, opts = {}) {
|
|
78
|
+
assertLocalDirectoryArgument(dir);
|
|
79
|
+
// Lazy node imports (browser-compat) — see module header.
|
|
80
|
+
const { readdir, readFile, stat } = await import('node:fs/promises');
|
|
81
|
+
const { join } = await import('node:path');
|
|
82
|
+
let isDirectory = false;
|
|
83
|
+
try {
|
|
84
|
+
isDirectory = (await stat(dir)).isDirectory();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new Error(`skillsFromDir: '${dir}' does not exist. Pass the directory that holds your ` +
|
|
88
|
+
`${SKILL_FILE} folders.`);
|
|
89
|
+
}
|
|
90
|
+
if (!isDirectory) {
|
|
91
|
+
throw new Error(`skillsFromDir: '${dir}' is a file, not a directory. Pass the directory that holds ` +
|
|
92
|
+
`your ${SKILL_FILE} folders.`);
|
|
93
|
+
}
|
|
94
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
95
|
+
const files = [];
|
|
96
|
+
// `dir/SKILL.md` — the whole directory is one skill.
|
|
97
|
+
if (entries.some((e) => e.isFile() && e.name === SKILL_FILE)) {
|
|
98
|
+
files.push(join(dir, SKILL_FILE));
|
|
99
|
+
}
|
|
100
|
+
// `dir/<folder>/SKILL.md` — the portable layout.
|
|
101
|
+
for (const entry of entries) {
|
|
102
|
+
if (!entry.isDirectory())
|
|
103
|
+
continue;
|
|
104
|
+
const candidate = join(dir, entry.name, SKILL_FILE);
|
|
105
|
+
try {
|
|
106
|
+
if ((await stat(candidate)).isFile())
|
|
107
|
+
files.push(candidate);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// A subdirectory without a SKILL.md is not an error — a skill folder can
|
|
111
|
+
// sit next to assets, fixtures, or anything else the author keeps here.
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (files.length === 0) {
|
|
115
|
+
throw new Error(`skillsFromDir: no ${SKILL_FILE} found under '${dir}'. Expected '${dir}/<skill>/${SKILL_FILE}' ` +
|
|
116
|
+
`or '${dir}/${SKILL_FILE}'.`);
|
|
117
|
+
}
|
|
118
|
+
const parsed = [];
|
|
119
|
+
for (const file of files.sort()) {
|
|
120
|
+
parsed.push(parseSkillFile(await readFile(file, 'utf8'), file));
|
|
121
|
+
}
|
|
122
|
+
// Collisions are refused naming BOTH files: with only the id in the message
|
|
123
|
+
// you would know a duplicate exists and still have to go find the pair.
|
|
124
|
+
const byName = new Map();
|
|
125
|
+
for (const skill of parsed) {
|
|
126
|
+
const clash = byName.get(skill.name);
|
|
127
|
+
if (clash) {
|
|
128
|
+
throw new Error(`skillsFromDir: two files claim the skill name '${skill.name}' — '${clash.file}' and ` +
|
|
129
|
+
`'${skill.file}'. Skill ids must be unique (read_skill dispatches by id); rename one.`);
|
|
130
|
+
}
|
|
131
|
+
byName.set(skill.name, skill);
|
|
132
|
+
}
|
|
133
|
+
return parsed
|
|
134
|
+
.slice()
|
|
135
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
136
|
+
.map((skill) => defineSkill({
|
|
137
|
+
id: skill.name,
|
|
138
|
+
description: skill.description,
|
|
139
|
+
body: skill.body,
|
|
140
|
+
...(opts.viaToolName !== undefined && { viaToolName: opts.viaToolName }),
|
|
141
|
+
...(opts.surfaceMode !== undefined && { surfaceMode: opts.surfaceMode }),
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
// ─── Authorship guard ──────────────────────────────────────────────
|
|
145
|
+
/**
|
|
146
|
+
* Refuse anything that is not a local path, BY NAME. The message quotes what
|
|
147
|
+
* was passed, because the whole point is that the reader can see the thing
|
|
148
|
+
* that was rejected.
|
|
149
|
+
*/
|
|
150
|
+
function assertLocalDirectoryArgument(dir) {
|
|
151
|
+
if (typeof dir !== 'string' || dir.trim().length === 0) {
|
|
152
|
+
throw new Error(`skillsFromDir: expected a local directory path, got ${JSON.stringify(dir)}.`);
|
|
153
|
+
}
|
|
154
|
+
const scheme = URL_LIKE_RE.exec(dir);
|
|
155
|
+
if (scheme) {
|
|
156
|
+
throw new Error(`skillsFromDir: '${dir}' is a ${scheme[0].slice(0, -3)} URL, not a local directory. ` +
|
|
157
|
+
`Skill bodies are instructions to a model, so this loader only reads files you own ` +
|
|
158
|
+
`at build time — fetch remote content yourself, review it, and pass defineSkill(...) ` +
|
|
159
|
+
`the result.`);
|
|
160
|
+
}
|
|
161
|
+
if (dir.startsWith('\\\\')) {
|
|
162
|
+
throw new Error(`skillsFromDir: '${dir}' is a network (UNC) path, not a local directory. ` +
|
|
163
|
+
`Skill bodies are instructions to a model, so this loader only reads files you own ` +
|
|
164
|
+
`at build time.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// ─── Frontmatter ───────────────────────────────────────────────────
|
|
168
|
+
/**
|
|
169
|
+
* Parse one `SKILL.md`. Every refusal names the file — a loader that says
|
|
170
|
+
* "malformed frontmatter" over a directory of forty files has told you nothing.
|
|
171
|
+
*
|
|
172
|
+
* The grammar is deliberately small: an opening `---` line, `key: value` lines
|
|
173
|
+
* (`#` comments and blank lines skipped, single/double quotes stripped), a
|
|
174
|
+
* closing `---` line, then the body. Keys other than `name` and `description`
|
|
175
|
+
* are IGNORED rather than rejected, so a file carrying extra frontmatter for
|
|
176
|
+
* another tool still loads here.
|
|
177
|
+
*/
|
|
178
|
+
function parseSkillFile(raw, file) {
|
|
179
|
+
// Strip a UTF-8 BOM — an editor artifact, not the author's intent.
|
|
180
|
+
const text = raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw;
|
|
181
|
+
const lines = text.split(/\r?\n/);
|
|
182
|
+
if (lines[0]?.trim() !== '---') {
|
|
183
|
+
throw new Error(`skillsFromDir: '${file}' does not start with a '---' frontmatter block. ` +
|
|
184
|
+
`Expected:\n---\nname: my-skill\ndescription: When to use it.\n---\n<the body>`);
|
|
185
|
+
}
|
|
186
|
+
const closingIndex = lines.findIndex((line, i) => i > 0 && line.trim() === '---');
|
|
187
|
+
if (closingIndex === -1) {
|
|
188
|
+
throw new Error(`skillsFromDir: '${file}' opens a '---' frontmatter block that is never closed. ` +
|
|
189
|
+
`Add a '---' line after the last frontmatter key.`);
|
|
190
|
+
}
|
|
191
|
+
const fields = new Map();
|
|
192
|
+
for (let i = 1; i < closingIndex; i++) {
|
|
193
|
+
const line = lines[i] ?? '';
|
|
194
|
+
if (line.trim().length === 0 || line.trimStart().startsWith('#'))
|
|
195
|
+
continue;
|
|
196
|
+
const separator = line.indexOf(':');
|
|
197
|
+
if (separator === -1) {
|
|
198
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter line ${i + 1} is not 'key: value' — got ` +
|
|
199
|
+
`${JSON.stringify(line)}.`);
|
|
200
|
+
}
|
|
201
|
+
const key = line.slice(0, separator).trim();
|
|
202
|
+
if (key.length === 0) {
|
|
203
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter line ${i + 1} has an empty key — got ` +
|
|
204
|
+
`${JSON.stringify(line)}.`);
|
|
205
|
+
}
|
|
206
|
+
fields.set(key, unquote(line.slice(separator + 1).trim()));
|
|
207
|
+
}
|
|
208
|
+
const name = fields.get('name') ?? '';
|
|
209
|
+
const description = fields.get('description') ?? '';
|
|
210
|
+
const body = lines
|
|
211
|
+
.slice(closingIndex + 1)
|
|
212
|
+
.join('\n')
|
|
213
|
+
.trim();
|
|
214
|
+
if (name.length === 0) {
|
|
215
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter is missing 'name'. It becomes the skill id the ` +
|
|
216
|
+
`model passes to read_skill.`);
|
|
217
|
+
}
|
|
218
|
+
if (!SKILL_NAME_RE.test(name)) {
|
|
219
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter name '${name}' must match ` +
|
|
220
|
+
`/^[a-zA-Z0-9_-]{1,64}$/ — it is the id the model passes to read_skill.`);
|
|
221
|
+
}
|
|
222
|
+
if (description.length === 0) {
|
|
223
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter is missing 'description'. It is the ONLY thing ` +
|
|
224
|
+
`the model reads when deciding whether to open this skill.`);
|
|
225
|
+
}
|
|
226
|
+
if (body.length === 0) {
|
|
227
|
+
throw new Error(`skillsFromDir: '${file}' has no body after the closing '---'. The body is what the ` +
|
|
228
|
+
`model reads once it activates the skill.`);
|
|
229
|
+
}
|
|
230
|
+
return { name, description, body, file };
|
|
231
|
+
}
|
|
232
|
+
/** Strip one layer of matching single or double quotes from a YAML-ish scalar. */
|
|
233
|
+
function unquote(value) {
|
|
234
|
+
if (value.length >= 2) {
|
|
235
|
+
const first = value[0];
|
|
236
|
+
const last = value[value.length - 1];
|
|
237
|
+
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
|
238
|
+
return value.slice(1, -1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=skillsFromDir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skillsFromDir.js","sourceRoot":"","sources":["../../../../src/lib/injection-engine/skillsFromDir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAGH,OAAO,EAAE,WAAW,EAAoB,MAAM,4BAA4B,CAAC;AAE3E,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
|
|
1
1
|
/**
|
|
2
|
-
* MCP — Model Context Protocol
|
|
3
|
-
* server
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* MCP — Model Context Protocol, both directions. `mcpClient` connects to
|
|
3
|
+
* someone else's MCP server and registers its tools on your Agent;
|
|
4
|
+
* `mcpServe` exposes your own tools AS an MCP server so any MCP client
|
|
5
|
+
* can call them.
|
|
6
6
|
*/
|
|
7
7
|
export { mcpClient } from './mcpClient.js';
|
|
8
|
+
export { mcpServe } from './mcpServe.js';
|
|
8
9
|
export { mockMcpClient, type MockMcpClientOptions, type MockMcpTool } from './mockMcpClient.js';
|
|
9
|
-
export type { McpClient, McpClientOptions, McpHttpTransport, McpStdioTransport, McpTransport, McpSdkClient, } from './types.js';
|
|
10
|
+
export type { McpClient, McpClientOptions, McpHttpTransport, McpStdioTransport, McpTransport, McpSdkClient, McpServeOptions, McpServeHandle, McpServeTransport, McpHttpServeTransport, McpStdioServeTransport, McpSdkServer, } from './types.js';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP — Model Context Protocol
|
|
3
|
-
* server
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* MCP — Model Context Protocol, both directions. `mcpClient` connects to
|
|
3
|
+
* someone else's MCP server and registers its tools on your Agent;
|
|
4
|
+
* `mcpServe` exposes your own tools AS an MCP server so any MCP client
|
|
5
|
+
* can call them.
|
|
6
6
|
*/
|
|
7
7
|
export { mcpClient } from './mcpClient.js';
|
|
8
|
+
export { mcpServe } from './mcpServe.js';
|
|
8
9
|
export { mockMcpClient } from './mockMcpClient.js';
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAA+C,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAA+C,MAAM,oBAAoB,CAAC"}
|
|
@@ -52,7 +52,7 @@ const DEFAULT_CLIENT_INFO = {
|
|
|
52
52
|
*/
|
|
53
53
|
export async function mcpClient(opts) {
|
|
54
54
|
const name = opts.name ?? 'mcp';
|
|
55
|
-
const sdk = opts._client ?? (await resolveClient(opts.transport, opts.clientInfo));
|
|
55
|
+
const sdk = opts._client ?? (await resolveClient(opts.transport, opts.clientInfo, opts.signal));
|
|
56
56
|
// Tool cache so consumers calling `.tools()` more than once don't
|
|
57
57
|
// hammer the server. `.refresh()` invalidates it.
|
|
58
58
|
let cache = null;
|
|
@@ -63,7 +63,11 @@ export async function mcpClient(opts) {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
const buildTools = async () => {
|
|
66
|
-
|
|
66
|
+
// `signal` rides in the SDK's THIRD argument (RequestOptions), not in
|
|
67
|
+
// the request params — see `wrapMcpTool`.
|
|
68
|
+
const listed = opts.signal
|
|
69
|
+
? await sdk.listTools(undefined, { signal: opts.signal })
|
|
70
|
+
: await sdk.listTools();
|
|
67
71
|
return listed.tools.map((t) => wrapMcpTool(name, sdk, t, opts.signal));
|
|
68
72
|
};
|
|
69
73
|
return {
|
|
@@ -89,7 +93,7 @@ export async function mcpClient(opts) {
|
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
95
|
// ─── SDK construction (lazy require) ───────────────────────────────
|
|
92
|
-
async function resolveClient(transport, clientInfo) {
|
|
96
|
+
async function resolveClient(transport, clientInfo, signal) {
|
|
93
97
|
let mod;
|
|
94
98
|
try {
|
|
95
99
|
mod = lazyRequire('@modelcontextprotocol/sdk/client/index.js');
|
|
@@ -103,7 +107,11 @@ async function resolveClient(transport, clientInfo) {
|
|
|
103
107
|
capabilities: {},
|
|
104
108
|
});
|
|
105
109
|
const transportImpl = await buildTransport(transport);
|
|
106
|
-
|
|
110
|
+
// Same rule as callTool: options ride beside the transport, never inside it.
|
|
111
|
+
if (signal)
|
|
112
|
+
await client.connect(transportImpl, { signal });
|
|
113
|
+
else
|
|
114
|
+
await client.connect(transportImpl);
|
|
107
115
|
return client;
|
|
108
116
|
}
|
|
109
117
|
async function buildTransport(t) {
|
|
@@ -151,11 +159,15 @@ function wrapMcpTool(serverName, sdk, mcp, signal) {
|
|
|
151
159
|
const argsObj = args !== null && typeof args === 'object' && !Array.isArray(args)
|
|
152
160
|
? args
|
|
153
161
|
: {};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
// The abort signal is NOT a request param — it belongs to the SDK's
|
|
163
|
+
// third argument (`RequestOptions`). Put it in the params object and
|
|
164
|
+
// it gets serialized onto the wire as an empty `{}` and the call is
|
|
165
|
+
// uncancellable: a silent no-op that only a real transport reveals.
|
|
166
|
+
// `resultSchema` (2nd arg) is left to the SDK's own default.
|
|
167
|
+
const params = { name: mcp.name, arguments: argsObj };
|
|
168
|
+
const result = signal
|
|
169
|
+
? await sdk.callTool(params, undefined, { signal })
|
|
170
|
+
: await sdk.callTool(params);
|
|
159
171
|
// MCP returns content blocks. We concatenate text blocks into
|
|
160
172
|
// a single string for the agent's tool-result event payload.
|
|
161
173
|
// Non-text blocks (images, resources) are summarized with their
|