@backendkit-labs/agent-core 0.37.1 → 0.38.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 +219 -43
- package/dist/delegation/DelegationBus.d.ts +8 -1
- package/dist/delegation/DelegationBus.d.ts.map +1 -1
- package/dist/delegation/DelegationBus.js +2 -1
- package/dist/delegation/DelegationBus.js.map +1 -1
- package/dist/engine/AgentEngine.d.ts +108 -3
- package/dist/engine/AgentEngine.d.ts.map +1 -1
- package/dist/engine/AgentEngine.js +463 -43
- package/dist/engine/AgentEngine.js.map +1 -1
- package/dist/engine/createBaseEngine.d.ts +28 -0
- package/dist/engine/createBaseEngine.d.ts.map +1 -1
- package/dist/engine/createBaseEngine.js +7 -0
- package/dist/engine/createBaseEngine.js.map +1 -1
- package/dist/engine/package-install.d.ts +7 -0
- package/dist/engine/package-install.d.ts.map +1 -1
- package/dist/engine/package-install.js +17 -0
- package/dist/engine/package-install.js.map +1 -1
- package/dist/governance/approval-store.d.ts +32 -0
- package/dist/governance/approval-store.d.ts.map +1 -0
- package/dist/governance/approval-store.js +129 -0
- package/dist/governance/approval-store.js.map +1 -0
- package/dist/governance/approval.d.ts +35 -0
- package/dist/governance/approval.d.ts.map +1 -0
- package/dist/governance/approval.js +65 -0
- package/dist/governance/approval.js.map +1 -0
- package/dist/governance/approvers.d.ts +24 -0
- package/dist/governance/approvers.d.ts.map +1 -0
- package/dist/governance/approvers.js +69 -0
- package/dist/governance/approvers.js.map +1 -0
- package/dist/governance/audit.d.ts +101 -0
- package/dist/governance/audit.d.ts.map +1 -0
- package/dist/governance/audit.js +178 -0
- package/dist/governance/audit.js.map +1 -0
- package/dist/governance/hooks.d.ts +60 -0
- package/dist/governance/hooks.d.ts.map +1 -0
- package/dist/governance/hooks.js +26 -0
- package/dist/governance/hooks.js.map +1 -0
- package/dist/governance/policy.d.ts +28 -0
- package/dist/governance/policy.d.ts.map +1 -0
- package/dist/governance/policy.js +101 -0
- package/dist/governance/policy.js.map +1 -0
- package/dist/governance/types.d.ts +162 -0
- package/dist/governance/types.d.ts.map +1 -0
- package/dist/governance/types.js +3 -0
- package/dist/governance/types.js.map +1 -0
- package/dist/index.d.ts +21 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/MCPClientManager.d.ts.map +1 -1
- package/dist/mcp/MCPClientManager.js +20 -1
- package/dist/mcp/MCPClientManager.js.map +1 -1
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +15 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tool-server-cli.d.ts +48 -0
- package/dist/mcp/tool-server-cli.d.ts.map +1 -0
- package/dist/mcp/tool-server-cli.js +106 -0
- package/dist/mcp/tool-server-cli.js.map +1 -0
- package/dist/mcp/tool-server-http.d.ts +37 -0
- package/dist/mcp/tool-server-http.d.ts.map +1 -0
- package/dist/mcp/tool-server-http.js +117 -0
- package/dist/mcp/tool-server-http.js.map +1 -0
- package/dist/mcp/tool-server.d.ts +104 -0
- package/dist/mcp/tool-server.d.ts.map +1 -0
- package/dist/mcp/tool-server.js +312 -0
- package/dist/mcp/tool-server.js.map +1 -0
- package/dist/shared/utils/canonical-json.d.ts +12 -0
- package/dist/shared/utils/canonical-json.d.ts.map +1 -0
- package/dist/shared/utils/canonical-json.js +29 -0
- package/dist/shared/utils/canonical-json.js.map +1 -0
- package/dist/shared/utils/loopback.d.ts +10 -0
- package/dist/shared/utils/loopback.d.ts.map +1 -0
- package/dist/shared/utils/loopback.js +25 -0
- package/dist/shared/utils/loopback.js.map +1 -0
- package/dist/tools/createToolContext.d.ts +15 -0
- package/dist/tools/createToolContext.d.ts.map +1 -0
- package/dist/tools/createToolContext.js +34 -0
- package/dist/tools/createToolContext.js.map +1 -0
- package/dist/tools/defineTool.d.ts +43 -7
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +68 -10
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashArgs = void 0;
|
|
4
|
+
exports.createToolRegistrar = createToolRegistrar;
|
|
5
|
+
exports.createToolServerFactory = createToolServerFactory;
|
|
6
|
+
exports.createToolServer = createToolServer;
|
|
7
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const canonical_json_1 = require("../shared/utils/canonical-json");
|
|
10
|
+
Object.defineProperty(exports, "hashArgs", { enumerable: true, get: function () { return canonical_json_1.hashArgs; } });
|
|
11
|
+
const createToolContext_1 = require("../tools/createToolContext");
|
|
12
|
+
const defineTool_1 = require("../tools/defineTool");
|
|
13
|
+
const audit_1 = require("../governance/audit");
|
|
14
|
+
const policy_1 = require("../governance/policy");
|
|
15
|
+
const approval_1 = require("../governance/approval");
|
|
16
|
+
const node_crypto_1 = require("node:crypto");
|
|
17
|
+
const DEFAULT_MAX_OUTPUT_CHARS = 1_048_576;
|
|
18
|
+
/**
|
|
19
|
+
* Validates the tools once (names, declared facts, schemas) and returns a function that registers them, with
|
|
20
|
+
* the per-call guarantees above, on any `McpServer`: one that also serves prompt tools, resources or prompts
|
|
21
|
+
* of its own. `createToolServerFactory` is this plus a fresh `McpServer` per call.
|
|
22
|
+
*/
|
|
23
|
+
function createToolRegistrar(opts) {
|
|
24
|
+
const prepared = prepareTools(opts);
|
|
25
|
+
const maxOutputChars = opts.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;
|
|
26
|
+
return server => registerTools(server, opts, prepared, maxOutputChars);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates the tools once and returns a factory that builds a connected-ready `McpServer` per call. The
|
|
30
|
+
* stateless HTTP transport needs a fresh server per request; stdio needs one.
|
|
31
|
+
*/
|
|
32
|
+
function createToolServerFactory(opts) {
|
|
33
|
+
const register = createToolRegistrar(opts);
|
|
34
|
+
return () => {
|
|
35
|
+
const server = new mcp_js_1.McpServer({ name: opts.name, version: opts.version ?? '1.0.0' });
|
|
36
|
+
register(server);
|
|
37
|
+
return server;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** One `McpServer` with every tool registered. Connect it to any MCP server transport. */
|
|
41
|
+
function createToolServer(opts) {
|
|
42
|
+
return createToolServerFactory(opts)();
|
|
43
|
+
}
|
|
44
|
+
// ── Preparation ───────────────────────────────────────────────────────────────
|
|
45
|
+
function prepareTools(opts) {
|
|
46
|
+
if (!opts.name)
|
|
47
|
+
throw new Error('createToolServer: name is required');
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
const prepared = [];
|
|
50
|
+
for (const tool of opts.tools) {
|
|
51
|
+
(0, defineTool_1.validateToolDefinition)(tool);
|
|
52
|
+
if (seen.has(tool.name))
|
|
53
|
+
throw new Error(`createToolServer(${opts.name}): duplicate tool name "${tool.name}"`);
|
|
54
|
+
seen.add(tool.name);
|
|
55
|
+
if (tool.destructive && !opts.authorize && !opts.policy) {
|
|
56
|
+
throw new Error(`createToolServer(${opts.name}): tool "${tool.name}" is destructive and no authorize hook or policy was given. ` +
|
|
57
|
+
'A direct tool skips the engine\'s allowedTools, gates and budget; the server must gate it itself.');
|
|
58
|
+
}
|
|
59
|
+
prepared.push({ tool, schema: inputSchemaOf(opts.name, tool), annotations: annotationsOf(tool) });
|
|
60
|
+
}
|
|
61
|
+
return prepared;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The schema a tool is registered with. Tools from `defineTool` carry their Zod schema, which is used as is:
|
|
65
|
+
* no conversion, so what the client validates against is exactly what `execute` validates against. A
|
|
66
|
+
* hand-written `ToolDefinition` only has JSON Schema; it goes through `z.fromJSONSchema`, which rejects
|
|
67
|
+
* constructs it cannot express (`if/then/else`, `not`, external `$ref`) instead of degrading silently.
|
|
68
|
+
*/
|
|
69
|
+
function inputSchemaOf(serverName, tool) {
|
|
70
|
+
const own = (0, defineTool_1.getToolInputSchema)(tool);
|
|
71
|
+
if (own)
|
|
72
|
+
return own;
|
|
73
|
+
try {
|
|
74
|
+
return zod_1.z.fromJSONSchema(tool.parameters, { defaultTarget: 'openapi-3.0' });
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
throw new Error(`createToolServer(${serverName}): cannot derive an input schema for tool "${tool.name}" from its JSON Schema: ` +
|
|
78
|
+
`${err.message}. Define it with defineTool, or simplify the schema.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function annotationsOf(tool) {
|
|
82
|
+
const a = {};
|
|
83
|
+
if (tool.readOnly !== undefined)
|
|
84
|
+
a.readOnlyHint = tool.readOnly;
|
|
85
|
+
if (tool.destructive !== undefined)
|
|
86
|
+
a.destructiveHint = tool.destructive;
|
|
87
|
+
if (tool.idempotent !== undefined)
|
|
88
|
+
a.idempotentHint = tool.idempotent;
|
|
89
|
+
if (tool.openWorld !== undefined)
|
|
90
|
+
a.openWorldHint = tool.openWorld;
|
|
91
|
+
return Object.keys(a).length > 0 ? a : undefined;
|
|
92
|
+
}
|
|
93
|
+
const governanceOf = new WeakMap();
|
|
94
|
+
function governance(opts) {
|
|
95
|
+
let g = governanceOf.get(opts);
|
|
96
|
+
if (!g) {
|
|
97
|
+
g = {
|
|
98
|
+
policies: opts.policy ? (Array.isArray(opts.policy) ? opts.policy : [opts.policy]) : [],
|
|
99
|
+
sinks: new audit_1.AuditDispatcher(opts.auditSink, (err) => process.stderr.write(`[${opts.name}] audit sink failed: ${messageOf(err)}\n`)),
|
|
100
|
+
};
|
|
101
|
+
governanceOf.set(opts, g);
|
|
102
|
+
}
|
|
103
|
+
return g;
|
|
104
|
+
}
|
|
105
|
+
function registerTools(server, opts, prepared, maxOutputChars) {
|
|
106
|
+
for (const { tool, schema, annotations } of prepared) {
|
|
107
|
+
server.registerTool(tool.name, {
|
|
108
|
+
description: tool.description,
|
|
109
|
+
...(tool.title !== undefined ? { title: tool.title } : {}),
|
|
110
|
+
// The SDK accepts a whole Zod object schema here, not only a raw shape.
|
|
111
|
+
inputSchema: schema,
|
|
112
|
+
...(annotations ? { annotations } : {}),
|
|
113
|
+
...(tool.meta ? { _meta: tool.meta } : {}),
|
|
114
|
+
},
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
(async (args, extra) => runCall(opts, tool, maxOutputChars, args, extra)));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function runCall(opts, tool, maxOutputChars, rawArgs, extra) {
|
|
120
|
+
const started = Date.now();
|
|
121
|
+
const args = (rawArgs && typeof rawArgs === 'object' ? rawArgs : {});
|
|
122
|
+
const info = { tool, args, requestId: extra.requestId, ...(extra.sessionId ? { sessionId: extra.sessionId } : {}) };
|
|
123
|
+
const gov = governance(opts);
|
|
124
|
+
const principal = {
|
|
125
|
+
...opts.identity,
|
|
126
|
+
agentId: opts.name,
|
|
127
|
+
sessionId: info.sessionId ?? 'mcp',
|
|
128
|
+
chain: [opts.name],
|
|
129
|
+
};
|
|
130
|
+
let approval;
|
|
131
|
+
let policyDecision = 'allow';
|
|
132
|
+
const finish = async (outcome, text, error) => {
|
|
133
|
+
await audit(opts, {
|
|
134
|
+
at: new Date(started).toISOString(),
|
|
135
|
+
server: opts.name,
|
|
136
|
+
tool: tool.name,
|
|
137
|
+
...(info.sessionId ? { sessionId: info.sessionId } : {}),
|
|
138
|
+
requestId: extra.requestId,
|
|
139
|
+
argsHash: (0, canonical_json_1.hashArgs)(args),
|
|
140
|
+
outcome,
|
|
141
|
+
durationMs: Date.now() - started,
|
|
142
|
+
outputChars: outcome === 'ok' ? text.length : 0,
|
|
143
|
+
...(error !== undefined ? { error } : {}),
|
|
144
|
+
});
|
|
145
|
+
if (gov.sinks.enabled) {
|
|
146
|
+
const ran = outcome !== 'denied';
|
|
147
|
+
await gov.sinks.write({
|
|
148
|
+
at: new Date(started).toISOString(),
|
|
149
|
+
principal: {
|
|
150
|
+
agentId: principal.agentId, sessionId: principal.sessionId, chain: principal.chain,
|
|
151
|
+
...(principal.tenantId !== undefined ? { tenantId: principal.tenantId } : {}),
|
|
152
|
+
...(principal.userId !== undefined ? { userId: principal.userId } : {}),
|
|
153
|
+
},
|
|
154
|
+
tool: tool.name,
|
|
155
|
+
argsHash: (0, canonical_json_1.hashArgs)(args),
|
|
156
|
+
decision: ran ? 'allow' : policyDecision === 'allow' ? 'deny' : policyDecision,
|
|
157
|
+
...(error !== undefined ? { reason: error } : {}),
|
|
158
|
+
...(ran ? { outcome: outcome } : {}),
|
|
159
|
+
durationMs: Date.now() - started,
|
|
160
|
+
...(approval ? { approval } : {}),
|
|
161
|
+
...(tool.meta ? { meta: tool.meta } : {}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return outcome === 'ok'
|
|
165
|
+
? { content: [{ type: 'text', text }] }
|
|
166
|
+
: { content: [{ type: 'text', text }], isError: true };
|
|
167
|
+
};
|
|
168
|
+
// 1. Authorization — before anything else runs.
|
|
169
|
+
if (opts.authorize) {
|
|
170
|
+
let allowed = false;
|
|
171
|
+
let reason = 'denied by authorize';
|
|
172
|
+
try {
|
|
173
|
+
allowed = await opts.authorize(info);
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
reason = `authorize threw: ${messageOf(err)}`;
|
|
177
|
+
}
|
|
178
|
+
if (!allowed)
|
|
179
|
+
return finish('denied', `Tool "${tool.name}" denied: ${reason}`, reason);
|
|
180
|
+
}
|
|
181
|
+
// 2. Policy (SPEC-0014 contract): deny, ask (to the approver, validated) or allow, with an optional mode.
|
|
182
|
+
let mode;
|
|
183
|
+
if (gov.policies.length > 0) {
|
|
184
|
+
const d = await (0, policy_1.evaluatePolicies)(gov.policies, principal, { tool, args });
|
|
185
|
+
if (d.effect === 'deny')
|
|
186
|
+
return finish('denied', `Tool "${tool.name}" denied: ${d.reason}`, d.reason);
|
|
187
|
+
if (d.effect === 'ask') {
|
|
188
|
+
const resolved = await resolveAsk(opts, gov, principal, tool, args, d);
|
|
189
|
+
if (!resolved.ok) {
|
|
190
|
+
policyDecision = 'deny';
|
|
191
|
+
return finish('denied', `Tool "${tool.name}" denied: ${resolved.reason}`, resolved.reason);
|
|
192
|
+
}
|
|
193
|
+
approval = resolved.approval;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
mode = d.mode;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// 3. Cancellation: client abort or time limit, whichever comes first.
|
|
200
|
+
const timeoutMs = tool.timeoutMs ?? opts.toolTimeoutMs;
|
|
201
|
+
const controller = new AbortController();
|
|
202
|
+
const onClientAbort = () => controller.abort(extra.signal.reason);
|
|
203
|
+
if (extra.signal.aborted)
|
|
204
|
+
onClientAbort();
|
|
205
|
+
else
|
|
206
|
+
extra.signal.addEventListener('abort', onClientAbort, { once: true });
|
|
207
|
+
let timer;
|
|
208
|
+
const timedOut = new Promise((_, reject) => {
|
|
209
|
+
if (timeoutMs === undefined)
|
|
210
|
+
return;
|
|
211
|
+
timer = setTimeout(() => {
|
|
212
|
+
controller.abort(new Error(`TOOL_TIMEOUT after ${timeoutMs}ms`));
|
|
213
|
+
reject(new ToolTimeout(timeoutMs));
|
|
214
|
+
}, timeoutMs);
|
|
215
|
+
});
|
|
216
|
+
// 4. Context and execution.
|
|
217
|
+
try {
|
|
218
|
+
const ctx = {
|
|
219
|
+
...contextFor(opts, info, controller.signal),
|
|
220
|
+
principal,
|
|
221
|
+
...(mode === 'dry_run' ? { dryRun: true } : {}),
|
|
222
|
+
};
|
|
223
|
+
if (mode === 'sandboxed' && !ctx.sandbox) {
|
|
224
|
+
const reason = 'the policy requires a sandbox and the tool context has none';
|
|
225
|
+
policyDecision = 'deny';
|
|
226
|
+
return finish('denied', `Tool "${tool.name}" denied: ${reason}`, reason);
|
|
227
|
+
}
|
|
228
|
+
const output = await Promise.race([tool.execute(args, ctx), timedOut]);
|
|
229
|
+
const text = typeof output === 'string' ? output : JSON.stringify(output);
|
|
230
|
+
if (text.length > maxOutputChars) {
|
|
231
|
+
const msg = `Tool "${tool.name}" returned ${text.length} characters; the limit is ${maxOutputChars}`;
|
|
232
|
+
return finish('too_large', msg, msg);
|
|
233
|
+
}
|
|
234
|
+
return finish('ok', text);
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
if (err instanceof ToolTimeout) {
|
|
238
|
+
const msg = `Tool "${tool.name}" timed out after ${err.timeoutMs}ms`;
|
|
239
|
+
return finish('timeout', msg, msg);
|
|
240
|
+
}
|
|
241
|
+
// No stack: the client is on the other side of a wire and gets the message only.
|
|
242
|
+
const msg = messageOf(err);
|
|
243
|
+
return finish('error', `Tool "${tool.name}" failed: ${msg}`, msg);
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
if (timer)
|
|
247
|
+
clearTimeout(timer);
|
|
248
|
+
extra.signal.removeEventListener('abort', onClientAbort);
|
|
249
|
+
timedOut.catch(() => undefined);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* An `ask` in the tool server: the approver answers now, its answer is validated (accepted kind, no self-approval,
|
|
254
|
+
* an agent approver must itself be allowed by the policies), or the call is refused. There is no pending store
|
|
255
|
+
* here: an MCP client waits for its answer.
|
|
256
|
+
*/
|
|
257
|
+
async function resolveAsk(opts, gov, principal, tool, args, d) {
|
|
258
|
+
if (!opts.approver)
|
|
259
|
+
return { ok: false, reason: `needs approval (${d.reason}) and no approver is configured` };
|
|
260
|
+
const request = {
|
|
261
|
+
id: (0, node_crypto_1.randomUUID)(), principal, subject: { kind: 'tool_call', call: { tool, args } }, reason: d.reason,
|
|
262
|
+
...(d.approver ? { approver: d.approver } : {}), ...(d.accepts ? { accepts: d.accepts } : {}),
|
|
263
|
+
createdAt: new Date().toISOString(),
|
|
264
|
+
};
|
|
265
|
+
let answer;
|
|
266
|
+
try {
|
|
267
|
+
answer = await opts.approver.request(request);
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
return { ok: false, reason: `the approver failed: ${messageOf(err)}` };
|
|
271
|
+
}
|
|
272
|
+
if (answer.decision !== 'approve')
|
|
273
|
+
return { ok: false, reason: answer.reason ?? 'rejected by the approver' };
|
|
274
|
+
const problem = await (0, approval_1.approvalProblem)(answer, request, async (by) => {
|
|
275
|
+
const asAgent = await (0, policy_1.evaluatePolicies)(gov.policies, { ...principal, agentId: by.id, chain: by.chain ?? [by.id] }, { tool, args });
|
|
276
|
+
return (0, policy_1.agentCouldPerform)(asAgent);
|
|
277
|
+
});
|
|
278
|
+
if (problem)
|
|
279
|
+
return { ok: false, reason: `invalid approval: ${problem}` };
|
|
280
|
+
return { ok: true, approval: { id: request.id, by: answer.by } };
|
|
281
|
+
}
|
|
282
|
+
class ToolTimeout extends Error {
|
|
283
|
+
timeoutMs;
|
|
284
|
+
constructor(timeoutMs) {
|
|
285
|
+
super(`timed out after ${timeoutMs}ms`);
|
|
286
|
+
this.timeoutMs = timeoutMs;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function contextFor(opts, info, signal) {
|
|
290
|
+
if (typeof opts.context === 'function')
|
|
291
|
+
return opts.context({ ...info, signal });
|
|
292
|
+
return (0, createToolContext_1.createToolContext)({
|
|
293
|
+
agentId: opts.name,
|
|
294
|
+
sessionId: info.sessionId ?? 'mcp',
|
|
295
|
+
...opts.context,
|
|
296
|
+
signal,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
async function audit(opts, record) {
|
|
300
|
+
if (!opts.audit)
|
|
301
|
+
return;
|
|
302
|
+
try {
|
|
303
|
+
await opts.audit(record);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
process.stderr.write(`[${opts.name}] audit hook failed for ${record.tool}: ${messageOf(err)}\n`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function messageOf(err) {
|
|
310
|
+
return err instanceof Error ? err.message : String(err);
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=tool-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-server.js","sourceRoot":"","sources":["../../src/mcp/tool-server.ts"],"names":[],"mappings":";;;AAmHA,kDAIC;AAMD,0DAOC;AAGD,4CAEC;AAzID,oEAAoE;AAEpE,6BAAwB;AACxB,mEAA0D;AAuajD,yFAvaA,yBAAQ,OAuaA;AArajB,kEAA+D;AAC/D,oDAAiF;AACjF,+CAAsD;AACtD,iDAA2E;AAC3E,qDAAyD;AAIzD,6CAAyC;AAyFzC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAQ3C;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAuB;IACvD,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,wBAAwB,CAAC;IACvE,OAAO,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,IAAuB;IAC3D,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,GAAG,EAAE;QACR,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,OAAO,EAAE,CAAC,CAAC;QACpF,QAAQ,CAAC,MAAM,CAAC,CAAC;QACjB,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED,0FAA0F;AAC1F,SAAgB,gBAAgB,CAAC,IAAuB;IACpD,OAAO,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC;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AAC,IAAI,IAAI,CAAC,IAAI,2BAA2B,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrG,CAAC;AACL,CAAC;AAKD,SAAS,SAAS,CAAC,GAAY;IAC3B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON with object keys sorted at every level, so two values that are equal produce the same text whatever the
|
|
3
|
+
* order their keys were written in. Arrays keep their order. `undefined` inside objects is dropped (as
|
|
4
|
+
* `JSON.stringify` does); a bare `undefined` becomes `null`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function canonicalJson(value: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* SHA-256 (hex) of the canonical JSON of a tool call's arguments. This is what audit records carry instead of
|
|
9
|
+
* the arguments themselves: equal arguments hash equal, and nothing of their content is readable.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hashArgs(args: unknown): string;
|
|
12
|
+
//# sourceMappingURL=canonical-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/canonical-json.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQpD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAE9C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicalJson = canonicalJson;
|
|
4
|
+
exports.hashArgs = hashArgs;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
/**
|
|
7
|
+
* JSON with object keys sorted at every level, so two values that are equal produce the same text whatever the
|
|
8
|
+
* order their keys were written in. Arrays keep their order. `undefined` inside objects is dropped (as
|
|
9
|
+
* `JSON.stringify` does); a bare `undefined` becomes `null`.
|
|
10
|
+
*/
|
|
11
|
+
function canonicalJson(value) {
|
|
12
|
+
if (value === null || typeof value !== 'object')
|
|
13
|
+
return JSON.stringify(value) ?? 'null';
|
|
14
|
+
if (Array.isArray(value))
|
|
15
|
+
return `[${value.map(v => (v === undefined ? 'null' : canonicalJson(v))).join(',')}]`;
|
|
16
|
+
const obj = value;
|
|
17
|
+
const entries = Object.keys(obj).sort()
|
|
18
|
+
.filter(k => obj[k] !== undefined)
|
|
19
|
+
.map(k => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`);
|
|
20
|
+
return `{${entries.join(',')}}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* SHA-256 (hex) of the canonical JSON of a tool call's arguments. This is what audit records carry instead of
|
|
24
|
+
* the arguments themselves: equal arguments hash equal, and nothing of their content is readable.
|
|
25
|
+
*/
|
|
26
|
+
function hashArgs(args) {
|
|
27
|
+
return (0, node_crypto_1.createHash)('sha256').update(canonicalJson(args)).digest('hex');
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=canonical-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../../../src/shared/utils/canonical-json.ts"],"names":[],"mappings":";;AAOA,sCAQC;AAMD,4BAEC;AAvBD,6CAAyC;AAEzC;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;IACxF,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAChH,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,IAAa;IAClC,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A server bound to 127.0.0.1 can still be reached from a page in the user's browser (DNS rebinding, cross-site
|
|
3
|
+
* POST). True only when the `Host` header and, if present, the `Origin` header are loopback.
|
|
4
|
+
*
|
|
5
|
+
* The single copy for packages that depend on agent-core (the MCP tool server here, `@backendkit-labs/mcp-server`).
|
|
6
|
+
* `@backendkit-labs/mcp-connectors` keeps its own copy because it does not depend on agent-core; keep the two in
|
|
7
|
+
* step (SPEC-0013 D6).
|
|
8
|
+
*/
|
|
9
|
+
export declare function isLoopbackRequest(host: string | undefined, origin: string | undefined): boolean;
|
|
10
|
+
//# sourceMappingURL=loopback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopback.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/loopback.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAQ/F"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoopbackRequest = isLoopbackRequest;
|
|
4
|
+
const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]']);
|
|
5
|
+
/**
|
|
6
|
+
* A server bound to 127.0.0.1 can still be reached from a page in the user's browser (DNS rebinding, cross-site
|
|
7
|
+
* POST). True only when the `Host` header and, if present, the `Origin` header are loopback.
|
|
8
|
+
*
|
|
9
|
+
* The single copy for packages that depend on agent-core (the MCP tool server here, `@backendkit-labs/mcp-server`).
|
|
10
|
+
* `@backendkit-labs/mcp-connectors` keeps its own copy because it does not depend on agent-core; keep the two in
|
|
11
|
+
* step (SPEC-0013 D6).
|
|
12
|
+
*/
|
|
13
|
+
function isLoopbackRequest(host, origin) {
|
|
14
|
+
if (!host || !LOOPBACK_HOSTS.has(host.replace(/:\d+$/, '').toLowerCase()))
|
|
15
|
+
return false;
|
|
16
|
+
if (origin === undefined)
|
|
17
|
+
return true; // non-browser clients send no Origin
|
|
18
|
+
try {
|
|
19
|
+
return LOOPBACK_HOSTS.has(new URL(origin).hostname.toLowerCase().replace(/^(::1)$/, '[::1]'));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=loopback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopback.js","sourceRoot":"","sources":["../../../src/shared/utils/loopback.ts"],"names":[],"mappings":";;AAUA,8CAQC;AAlBD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,IAAwB,EAAE,MAA0B;IAClF,IAAI,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC;IACxF,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,CAAC,qCAAqC;IAC5E,IAAI,CAAC;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAClG,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ExecutionContext, SessionMemoryData } from '../types';
|
|
2
|
+
/** Everything in `ExecutionContext` is optional here; what is missing gets a safe default. */
|
|
3
|
+
export type ToolContextOptions = Partial<ExecutionContext>;
|
|
4
|
+
/** Session memory that lives only as long as the context object. */
|
|
5
|
+
export declare function createInMemorySessionMemory(): SessionMemoryData;
|
|
6
|
+
/**
|
|
7
|
+
* Builds an `ExecutionContext` for running a tool outside an `AgentEngine`: tests, scripts, cron jobs and
|
|
8
|
+
* the MCP tool server. Defaults: `agentId: 'direct'`, `sessionId: 'direct'`, in-memory session memory and an
|
|
9
|
+
* `askAgent` that rejects (there is no engine to ask). Pass `signal` so the tool can be cancelled.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const out = await myTool.execute({ id: 7 }, createToolContext({ workingDir: process.cwd() }));
|
|
13
|
+
*/
|
|
14
|
+
export declare function createToolContext(opts?: ToolContextOptions): ExecutionContext;
|
|
15
|
+
//# sourceMappingURL=createToolContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createToolContext.d.ts","sourceRoot":"","sources":["../../src/tools/createToolContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEpE,8FAA8F;AAC9F,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE3D,oEAAoE;AACpE,wBAAgB,2BAA2B,IAAI,iBAAiB,CAO/D;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,kBAAuB,GAAG,gBAAgB,CAWjF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInMemorySessionMemory = createInMemorySessionMemory;
|
|
4
|
+
exports.createToolContext = createToolContext;
|
|
5
|
+
/** Session memory that lives only as long as the context object. */
|
|
6
|
+
function createInMemorySessionMemory() {
|
|
7
|
+
const data = new Map();
|
|
8
|
+
return {
|
|
9
|
+
get: key => data.get(key),
|
|
10
|
+
set: (key, value) => { data.set(key, value); },
|
|
11
|
+
getAll: () => Object.fromEntries(data),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds an `ExecutionContext` for running a tool outside an `AgentEngine`: tests, scripts, cron jobs and
|
|
16
|
+
* the MCP tool server. Defaults: `agentId: 'direct'`, `sessionId: 'direct'`, in-memory session memory and an
|
|
17
|
+
* `askAgent` that rejects (there is no engine to ask). Pass `signal` so the tool can be cancelled.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const out = await myTool.execute({ id: 7 }, createToolContext({ workingDir: process.cwd() }));
|
|
21
|
+
*/
|
|
22
|
+
function createToolContext(opts = {}) {
|
|
23
|
+
const { agentId, sessionId, memory, askAgent, ...rest } = opts;
|
|
24
|
+
return {
|
|
25
|
+
...rest,
|
|
26
|
+
agentId: agentId ?? 'direct',
|
|
27
|
+
sessionId: sessionId ?? 'direct',
|
|
28
|
+
memory: memory ?? createInMemorySessionMemory(),
|
|
29
|
+
askAgent: askAgent ?? (async (target) => {
|
|
30
|
+
throw new Error(`askAgent("${target}") is not available outside an AgentEngine`);
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=createToolContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createToolContext.js","sourceRoot":"","sources":["../../src/tools/createToolContext.ts"],"names":[],"mappings":";;AAMA,kEAOC;AAUD,8CAWC;AA7BD,oEAAoE;AACpE,SAAgB,2BAA2B;IACvC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,OAAO;QACH,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QACzB,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;KACzC,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,OAA2B,EAAE;IAC3D,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC/D,OAAO;QACH,GAAG,IAAI;QACP,OAAO,EAAE,OAAO,IAAI,QAAQ;QAC5B,SAAS,EAAE,SAAS,IAAI,QAAQ;QAChC,MAAM,EAAE,MAAM,IAAI,2BAA2B,EAAE;QAC/C,QAAQ,EAAE,QAAQ,IAAI,CAAC,KAAK,EAAE,MAAc,EAAE,EAAE;YAC5C,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,4CAA4C,CAAC,CAAC;QACrF,CAAC,CAAC;KACL,CAAC;AACN,CAAC"}
|
|
@@ -1,18 +1,55 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ToolDefinition, ExecutionContext } from '../types';
|
|
3
3
|
export { z };
|
|
4
|
-
|
|
4
|
+
/** Declarative facts about a tool that the engine and MCP clients use to decide how to treat it. */
|
|
5
|
+
export interface ToolMetadata {
|
|
6
|
+
/** Human-readable name for UIs and MCP clients. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Mutates nothing. Implies `concurrencySafe`; incompatible with `destructive`. MCP: `readOnlyHint`. */
|
|
9
|
+
readOnly?: boolean;
|
|
10
|
+
/** A write that cannot be undone from the outside. MCP: `destructiveHint`. */
|
|
11
|
+
destructive?: boolean;
|
|
12
|
+
/** Calling it again with the same arguments has no additional effect. MCP: `idempotentHint`. */
|
|
13
|
+
idempotent?: boolean;
|
|
14
|
+
/** Talks to entities outside the system. MCP: `openWorldHint`. */
|
|
15
|
+
openWorld?: boolean;
|
|
16
|
+
/** Free-form metadata for governance clients (never read by the engine). MCP: `_meta`. */
|
|
17
|
+
meta?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface TypedToolOptions<TInput extends z.ZodTypeAny> extends ToolMetadata {
|
|
5
20
|
name: string;
|
|
6
21
|
description: string;
|
|
7
22
|
/** Zod schema for the tool's input. Used for validation and JSON Schema generation. */
|
|
8
23
|
input: TInput;
|
|
9
|
-
/** Safe to run in parallel with other concurrencySafe tools. Default false. */
|
|
24
|
+
/** Safe to run in parallel with other concurrencySafe tools. Default false (true when `readOnly`). */
|
|
10
25
|
concurrencySafe?: boolean;
|
|
11
26
|
/** Time limit for one call in ms (overrides the engine's `toolTimeoutMs`). Default: none. */
|
|
12
27
|
timeoutMs?: number;
|
|
13
28
|
/** Type-safe execute handler — args are already validated and typed. */
|
|
14
29
|
execute(args: z.infer<TInput>, ctx: ExecutionContext): Promise<string>;
|
|
15
30
|
}
|
|
31
|
+
/** A tool whose declared facts contradict each other (thrown at definition time, never at call time). */
|
|
32
|
+
export declare class ToolDefinitionError extends Error {
|
|
33
|
+
readonly toolName: string;
|
|
34
|
+
constructor(toolName: string, message: string);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks that a tool's declared facts are consistent. `defineTool` calls it; call it yourself on a hand-written
|
|
38
|
+
* `ToolDefinition` before exposing it (the MCP tool server does).
|
|
39
|
+
*
|
|
40
|
+
* - `readOnly` and `destructive` cannot both be true.
|
|
41
|
+
* - `concurrencySafe` means "read-only, order-independent", so a `destructive` tool cannot declare it.
|
|
42
|
+
* - `timeoutMs`, when present, must be a positive number.
|
|
43
|
+
* - `parameters` must describe an object.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateToolDefinition(tool: ToolDefinition): void;
|
|
46
|
+
/** The Zod schema a tool was defined with, or undefined for a hand-written ToolDefinition. */
|
|
47
|
+
export declare function getToolInputSchema(tool: ToolDefinition): z.ZodTypeAny | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Converts a Zod schema to the plain JSON Schema sent to LLMs (tool parameters, structured output):
|
|
50
|
+
* OpenAPI 3 flavour, no `$ref`s, without the top-level `$schema` / `definitions` meta.
|
|
51
|
+
*/
|
|
52
|
+
export declare function zodToParameters(schema: z.ZodTypeAny): Record<string, unknown>;
|
|
16
53
|
/**
|
|
17
54
|
* Creates a fully type-safe ToolDefinition backed by a Zod schema.
|
|
18
55
|
*
|
|
@@ -20,10 +57,14 @@ export interface TypedToolOptions<TInput extends z.ZodTypeAny> {
|
|
|
20
57
|
* validated at runtime before being passed to the execute handler.
|
|
21
58
|
* Validation errors are returned as tool result strings (not thrown).
|
|
22
59
|
*
|
|
60
|
+
* Declared facts (`readOnly`, `destructive`, `idempotent`, `openWorld`, `meta`, `title`) are checked for
|
|
61
|
+
* consistency here and throw `ToolDefinitionError` at definition time. `readOnly: true` implies `concurrencySafe`.
|
|
62
|
+
*
|
|
23
63
|
* @example
|
|
24
64
|
* const readFileTool = defineTool({
|
|
25
65
|
* name: 'read_file',
|
|
26
66
|
* description: 'Read a file from disk',
|
|
67
|
+
* readOnly: true,
|
|
27
68
|
* input: z.object({
|
|
28
69
|
* path: z.string().describe('Absolute path to the file'),
|
|
29
70
|
* encoding: z.enum(['utf-8', 'base64']).default('utf-8'),
|
|
@@ -34,10 +75,5 @@ export interface TypedToolOptions<TInput extends z.ZodTypeAny> {
|
|
|
34
75
|
* },
|
|
35
76
|
* });
|
|
36
77
|
*/
|
|
37
|
-
/**
|
|
38
|
-
* Converts a Zod schema to the plain JSON Schema sent to LLMs (tool parameters, structured output):
|
|
39
|
-
* OpenAPI 3 flavour, no `$ref`s, without the top-level `$schema` / `definitions` meta.
|
|
40
|
-
*/
|
|
41
|
-
export declare function zodToParameters(schema: z.ZodTypeAny): Record<string, unknown>;
|
|
42
78
|
export declare function defineTool<TInput extends z.ZodTypeAny>(opts: TypedToolOptions<TInput>): ToolDefinition;
|
|
43
79
|
//# sourceMappingURL=defineTool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineTool.d.ts","sourceRoot":"","sources":["../../src/tools/defineTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,EAAE,CAAC,EAAE,CAAC;AAIb,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,CAAC,CAAC,UAAU;
|
|
1
|
+
{"version":3,"file":"defineTool.d.ts","sourceRoot":"","sources":["../../src/tools/defineTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UA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