@bevel-software/platform-mcp-core 0.23.0 → 0.24.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/chain-example.d.ts +58 -0
- package/dist/chain-example.d.ts.map +1 -0
- package/dist/chain-example.js +259 -0
- package/dist/chain-example.js.map +1 -0
- package/dist/chain-runtime.d.ts +122 -0
- package/dist/chain-runtime.d.ts.map +1 -0
- package/dist/chain-runtime.js +352 -0
- package/dist/chain-runtime.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/meta-tools.d.ts +100 -1
- package/dist/meta-tools.d.ts.map +1 -1
- package/dist/meta-tools.js +181 -53
- package/dist/meta-tools.js.map +1 -1
- package/dist/results.d.ts +20 -0
- package/dist/results.d.ts.map +1 -1
- package/dist/results.js +111 -1
- package/dist/results.js.map +1 -1
- package/dist/retired-tools.d.ts +0 -12
- package/dist/retired-tools.d.ts.map +1 -1
- package/dist/retired-tools.js +0 -22
- package/dist/retired-tools.js.map +1 -1
- package/package.json +1 -1
- package/src/chain-example.ts +315 -0
- package/src/chain-runtime.ts +382 -0
- package/src/index.ts +29 -2
- package/src/meta-tools.ts +212 -58
- package/src/results.ts +106 -1
- package/src/retired-tools.ts +0 -22
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The example call in `call_tool_chain`'s description, derived from the live
|
|
3
|
+
* catalog — the NAME and the ARGUMENTS both.
|
|
4
|
+
*
|
|
5
|
+
* The name alone was not enough. A first pass read the callable name off the
|
|
6
|
+
* catalog (which the two surfaces spell differently: `KNOWLEDGE_BASE.read_file`
|
|
7
|
+
* on the hosted endpoint, `hexis.hexis_read_file` through the local server) but
|
|
8
|
+
* kept the arguments as fixed text, `{ body: { path: '…' } }`. Every knowledge-
|
|
9
|
+
* base tool declares `branch` REQUIRED, so an agent copying that example got
|
|
10
|
+
* `400 … \`branch\` is required` — the acceptance criterion is that a copied
|
|
11
|
+
* example WORKS, and a right name with wrong arguments fails it just as
|
|
12
|
+
* squarely as a wrong name.
|
|
13
|
+
*
|
|
14
|
+
* So the arguments come from the tool's own input schema, and only when the
|
|
15
|
+
* schema determines them. `branch` is a free-form required string with no
|
|
16
|
+
* `default` and no `enum`: nothing in the catalog says WHICH branch, and
|
|
17
|
+
* `'main'` would be a guess that breaks on any deployment whose default branch
|
|
18
|
+
* is named otherwise — as would a guessed `path`, which has to name a file that
|
|
19
|
+
* exists. A tool like that is therefore not used for the example at all.
|
|
20
|
+
* Instead the example is the simplest call the catalog fully determines, which
|
|
21
|
+
* in practice is a no-argument discovery tool (`start_session({ body: {} })`):
|
|
22
|
+
* it demonstrates the namespace, the dotted name and the `{ body: … }` wrapper
|
|
23
|
+
* — the three things an agent actually gets wrong — and it cannot be stale,
|
|
24
|
+
* because every value in it was read from the schema rather than invented.
|
|
25
|
+
*/
|
|
26
|
+
/** One tool of the surface's catalog, as both surfaces already hold it. */
|
|
27
|
+
export interface ChainExampleTool {
|
|
28
|
+
/** The UTCP name, e.g. `KNOWLEDGE_BASE.read_file`. */
|
|
29
|
+
utcpName: string;
|
|
30
|
+
/** The tool's UTCP input schema (`ProxiedTool.inputSchema`). */
|
|
31
|
+
inputSchema?: unknown;
|
|
32
|
+
}
|
|
33
|
+
export interface ChainExample {
|
|
34
|
+
/** The namespace, as the chain runtime spells it. */
|
|
35
|
+
namespace: string;
|
|
36
|
+
/**
|
|
37
|
+
* A callable NAME from the catalog — safe to print on its own, no arguments
|
|
38
|
+
* implied. Null when the catalog affords none (it is empty, or every name in
|
|
39
|
+
* it is shared by two tools): a name nothing here serves is the very thing
|
|
40
|
+
* an agent copies into a chain and watches die of `ReferenceError`.
|
|
41
|
+
*/
|
|
42
|
+
name: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* A complete call that works as written, or null when the catalog affords
|
|
45
|
+
* none. Null prints no example at all rather than a call that would fail:
|
|
46
|
+
* an example an agent cannot trust is worse than the shape plus `tools_info`.
|
|
47
|
+
*/
|
|
48
|
+
call: string | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The namespace, a callable name and a working call for this connection.
|
|
52
|
+
*
|
|
53
|
+
* This connection's OWN namespace is used when it has any tools: a third-party
|
|
54
|
+
* `.tool` is a worse example than a core tool, since what an agent most needs
|
|
55
|
+
* demonstrated is how to reach the knowledge base.
|
|
56
|
+
*/
|
|
57
|
+
export declare function chainExample(namespace: string, tools: readonly ChainExampleTool[]): ChainExample;
|
|
58
|
+
//# sourceMappingURL=chain-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-example.d.ts","sourceRoot":"","sources":["../src/chain-example.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB;;;;OAIG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AA0ND;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,YAAY,CAqChG"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { sanitizeIdentifier, utcpNameToTsInterfaceName } from './code-mode-names.js';
|
|
2
|
+
/** How deep into a schema to look before giving up on writing a value for it. */
|
|
3
|
+
const MAX_DEPTH = 6;
|
|
4
|
+
/**
|
|
5
|
+
* The one name preferred as the example call when several are equally simple.
|
|
6
|
+
*
|
|
7
|
+
* `start_session` is the call an external agent is told to make first in any
|
|
8
|
+
* case, and the one with no preconditions — no branch, no path, no per-user
|
|
9
|
+
* credential, nothing that has to already exist. Among no-argument tools that
|
|
10
|
+
* makes it the one least able to fail for a reason the schema cannot see.
|
|
11
|
+
*/
|
|
12
|
+
const PREFERRED_EXAMPLE_TOOLS = ['start_session'];
|
|
13
|
+
/**
|
|
14
|
+
* A single-quoted JavaScript string, safe to paste into chain source AND into
|
|
15
|
+
* the Markdown code span the description prints the example inside.
|
|
16
|
+
*
|
|
17
|
+
* Every escape here is load-bearing. A raw line terminator inside a
|
|
18
|
+
* single-quoted literal is a SyntaxError, so a schema `default` or `enum` entry
|
|
19
|
+
* carrying one would print a chain that cannot even parse; a backtick would
|
|
20
|
+
* close the `` `return …;` `` span the example is printed in and truncate the
|
|
21
|
+
* call halfway. U+2028/U+2029 are the pair worth naming: line terminators to a
|
|
22
|
+
* JavaScript parser, invisible to everything else.
|
|
23
|
+
*/
|
|
24
|
+
function quote(text) {
|
|
25
|
+
let out = '';
|
|
26
|
+
for (const ch of text) {
|
|
27
|
+
const cp = ch.codePointAt(0);
|
|
28
|
+
if (ch === '\\')
|
|
29
|
+
out += '\\\\';
|
|
30
|
+
else if (ch === "'")
|
|
31
|
+
out += "\\'";
|
|
32
|
+
else if (ch === '\n')
|
|
33
|
+
out += '\\n';
|
|
34
|
+
else if (ch === '\r')
|
|
35
|
+
out += '\\r';
|
|
36
|
+
else if (ch === '\t')
|
|
37
|
+
out += '\\t';
|
|
38
|
+
else if (ch === '`')
|
|
39
|
+
out += '\\x60';
|
|
40
|
+
else if (cp < 0x20 || cp === 0x7f)
|
|
41
|
+
out += `\\x${cp.toString(16).padStart(2, '0')}`;
|
|
42
|
+
else if (cp === 0x2028 || cp === 0x2029)
|
|
43
|
+
out += `\\u${cp.toString(16)}`;
|
|
44
|
+
else
|
|
45
|
+
out += ch;
|
|
46
|
+
}
|
|
47
|
+
return `'${out}'`;
|
|
48
|
+
}
|
|
49
|
+
/** Whether `value` is of JSON Schema `type`. An unrecognised type word matches nothing. */
|
|
50
|
+
function matchesJsonType(value, type) {
|
|
51
|
+
switch (type) {
|
|
52
|
+
case 'string':
|
|
53
|
+
return typeof value === 'string';
|
|
54
|
+
case 'boolean':
|
|
55
|
+
return typeof value === 'boolean';
|
|
56
|
+
case 'integer':
|
|
57
|
+
return typeof value === 'number' && Number.isInteger(value);
|
|
58
|
+
case 'number':
|
|
59
|
+
return typeof value === 'number';
|
|
60
|
+
case 'null':
|
|
61
|
+
return value === null;
|
|
62
|
+
case 'array':
|
|
63
|
+
return Array.isArray(value);
|
|
64
|
+
case 'object':
|
|
65
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
66
|
+
default:
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether `value` satisfies the constraints declared BESIDE the `default` or
|
|
72
|
+
* `enum` it was read from.
|
|
73
|
+
*
|
|
74
|
+
* A schema is free to contradict itself — `enum: [1, 5]` with `minimum: 5`
|
|
75
|
+
* makes the first entry invalid — and the whole point of reading a value off
|
|
76
|
+
* the schema instead of inventing one is that the printed call works. So a
|
|
77
|
+
* candidate that fails any sibling bound is not used, and a keyword this does
|
|
78
|
+
* not know is not assumed to pass: an unrecognised `type` word, or a `pattern`
|
|
79
|
+
* this runtime cannot compile, rejects the candidate rather than advertising a
|
|
80
|
+
* call the server may refuse.
|
|
81
|
+
*/
|
|
82
|
+
function satisfiesConstraints(value, s) {
|
|
83
|
+
const declared = Array.isArray(s.type)
|
|
84
|
+
? s.type.filter((t) => typeof t === 'string')
|
|
85
|
+
: typeof s.type === 'string'
|
|
86
|
+
? [s.type]
|
|
87
|
+
: [];
|
|
88
|
+
if (declared.length > 0 && !declared.some((t) => matchesJsonType(value, t)))
|
|
89
|
+
return false;
|
|
90
|
+
if ('const' in s && s.const !== value)
|
|
91
|
+
return false;
|
|
92
|
+
if (typeof value === 'number') {
|
|
93
|
+
if (typeof s.minimum === 'number' && value < s.minimum)
|
|
94
|
+
return false;
|
|
95
|
+
if (typeof s.maximum === 'number' && value > s.maximum)
|
|
96
|
+
return false;
|
|
97
|
+
if (typeof s.exclusiveMinimum === 'number' && value <= s.exclusiveMinimum)
|
|
98
|
+
return false;
|
|
99
|
+
if (typeof s.exclusiveMaximum === 'number' && value >= s.exclusiveMaximum)
|
|
100
|
+
return false;
|
|
101
|
+
if (typeof s.multipleOf === 'number' && s.multipleOf > 0 && !Number.isInteger(value / s.multipleOf))
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (typeof value === 'string') {
|
|
105
|
+
if (typeof s.minLength === 'number' && value.length < s.minLength)
|
|
106
|
+
return false;
|
|
107
|
+
if (typeof s.maxLength === 'number' && value.length > s.maxLength)
|
|
108
|
+
return false;
|
|
109
|
+
if (typeof s.pattern === 'string') {
|
|
110
|
+
try {
|
|
111
|
+
if (!new RegExp(s.pattern).test(value))
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
/** `value` as JavaScript source, or null when it is not a plain scalar. */
|
|
122
|
+
function scalarLiteral(value) {
|
|
123
|
+
if (value === null)
|
|
124
|
+
return 'null';
|
|
125
|
+
if (typeof value === 'string')
|
|
126
|
+
return quote(value);
|
|
127
|
+
if (typeof value === 'boolean')
|
|
128
|
+
return String(value);
|
|
129
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
130
|
+
return String(value);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* An object key, bare when it is an identifier and quoted when it is not.
|
|
135
|
+
*
|
|
136
|
+
* `__proto__` is neither. In an object literal, `__proto__: v` does not create
|
|
137
|
+
* a property — it SETS THE PROTOTYPE, and quoting it (`'__proto__': v`) does
|
|
138
|
+
* exactly the same. So a copied example would send the tool an object without
|
|
139
|
+
* the argument its schema requires. Only the computed form is an ordinary own
|
|
140
|
+
* property.
|
|
141
|
+
*/
|
|
142
|
+
function propertyKey(key) {
|
|
143
|
+
if (key === '__proto__')
|
|
144
|
+
return `[${quote(key)}]`;
|
|
145
|
+
return /^[A-Za-z_$][\w$]*$/.test(key) ? key : quote(key);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The smallest value that satisfies `schema`, as JavaScript source, or null
|
|
149
|
+
* when the schema does not say enough to write one.
|
|
150
|
+
*
|
|
151
|
+
* Only the REQUIRED properties are written: an optional argument an agent did
|
|
152
|
+
* not ask for has no business in an example. A free-form required string,
|
|
153
|
+
* number or boolean returns null — the schema names a type, not a value, and
|
|
154
|
+
* inventing one is exactly how the example stopped working.
|
|
155
|
+
*/
|
|
156
|
+
function satisfyingValue(schema, depth) {
|
|
157
|
+
if (depth > MAX_DEPTH || !schema || typeof schema !== 'object' || Array.isArray(schema))
|
|
158
|
+
return null;
|
|
159
|
+
const s = schema;
|
|
160
|
+
// A `default`, or a closed `enum`, is the schema itself naming a value —
|
|
161
|
+
// but only a value its OWN siblings accept (see `satisfiesConstraints`).
|
|
162
|
+
if ('default' in s) {
|
|
163
|
+
const literal = scalarLiteral(s.default);
|
|
164
|
+
if (literal !== null && satisfiesConstraints(s.default, s))
|
|
165
|
+
return { source: literal, scalars: 1 };
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(s.enum) && s.enum.length > 0) {
|
|
168
|
+
// Every entry, not just the first: a schema may list one its own bounds
|
|
169
|
+
// forbid, and any entry that satisfies them is an equally good example.
|
|
170
|
+
for (const candidate of s.enum) {
|
|
171
|
+
const literal = scalarLiteral(candidate);
|
|
172
|
+
if (literal !== null && satisfiesConstraints(candidate, s))
|
|
173
|
+
return { source: literal, scalars: 1 };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const declared = Array.isArray(s.type) ? s.type.find((t) => typeof t === 'string') : s.type;
|
|
177
|
+
const type = typeof declared === 'string' ? declared : s.properties ? 'object' : undefined;
|
|
178
|
+
if (type === 'object') {
|
|
179
|
+
const properties = (s.properties ?? {});
|
|
180
|
+
const required = Array.isArray(s.required) ? s.required.filter((k) => typeof k === 'string') : [];
|
|
181
|
+
const parts = [];
|
|
182
|
+
let scalars = 0;
|
|
183
|
+
for (const key of required) {
|
|
184
|
+
const child = satisfyingValue(properties[key], depth + 1);
|
|
185
|
+
// A required argument whose value the schema does not determine
|
|
186
|
+
// disqualifies the whole tool: a call missing it is a call that 400s.
|
|
187
|
+
if (!child)
|
|
188
|
+
return null;
|
|
189
|
+
parts.push(`${propertyKey(key)}: ${child.source}`);
|
|
190
|
+
scalars += child.scalars;
|
|
191
|
+
}
|
|
192
|
+
// A schema may demand more properties than it names in `required` — an
|
|
193
|
+
// example satisfying only `required` would then be refused for being too
|
|
194
|
+
// thin, and which properties to add is not something the schema says.
|
|
195
|
+
if (typeof s.minProperties === 'number' && parts.length < s.minProperties)
|
|
196
|
+
return null;
|
|
197
|
+
return { source: parts.length > 0 ? `{ ${parts.join(', ')} }` : '{}', scalars };
|
|
198
|
+
}
|
|
199
|
+
if (type === 'array') {
|
|
200
|
+
// An empty array satisfies an array that demands no minimum. One that does
|
|
201
|
+
// needs an element whose value the schema has not named.
|
|
202
|
+
const min = typeof s.minItems === 'number' ? s.minItems : 0;
|
|
203
|
+
return min === 0 ? { source: '[]', scalars: 0 } : null;
|
|
204
|
+
}
|
|
205
|
+
if (type === 'null')
|
|
206
|
+
return { source: 'null', scalars: 1 };
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
/** Where `name` sits in {@link PREFERRED_EXAMPLE_TOOLS}; past the end when absent. */
|
|
210
|
+
function preference(name) {
|
|
211
|
+
const index = PREFERRED_EXAMPLE_TOOLS.findIndex((p) => name === p || name.endsWith(`.${p}`) || name.endsWith(`_${p}`));
|
|
212
|
+
return index === -1 ? PREFERRED_EXAMPLE_TOOLS.length : index;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The namespace, a callable name and a working call for this connection.
|
|
216
|
+
*
|
|
217
|
+
* This connection's OWN namespace is used when it has any tools: a third-party
|
|
218
|
+
* `.tool` is a worse example than a core tool, since what an agent most needs
|
|
219
|
+
* demonstrated is how to reach the knowledge base.
|
|
220
|
+
*/
|
|
221
|
+
export function chainExample(namespace, tools) {
|
|
222
|
+
const ns = sanitizeIdentifier(namespace);
|
|
223
|
+
const callable = tools
|
|
224
|
+
.map((t) => ({ name: utcpNameToTsInterfaceName(t.utcpName), schema: t.inputSchema }))
|
|
225
|
+
// Sorted so that every tie below breaks the same way on every request —
|
|
226
|
+
// a description that changed between two listings of the same catalog
|
|
227
|
+
// would be its own small puzzle.
|
|
228
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
229
|
+
// A sanitized name that TWO catalog entries share is no use as an example:
|
|
230
|
+
// the runtime binds one of them and the description cannot say which, so a
|
|
231
|
+
// copied call might reach a tool whose arguments are not the schema the
|
|
232
|
+
// example was derived from. Both halves are drawn from the rest.
|
|
233
|
+
const occurrences = new Map();
|
|
234
|
+
for (const t of callable)
|
|
235
|
+
occurrences.set(t.name, (occurrences.get(t.name) ?? 0) + 1);
|
|
236
|
+
const unambiguous = callable.filter((t) => occurrences.get(t.name) === 1);
|
|
237
|
+
const own = unambiguous.filter((t) => t.name.startsWith(`${ns}.`));
|
|
238
|
+
const pool = own.length > 0 ? own : unambiguous;
|
|
239
|
+
// The NAME example. `read_file` is preferred because every surface has it
|
|
240
|
+
// and an agent reading the description recognises it; printed without
|
|
241
|
+
// arguments, so its required `branch` is not at stake here. From the pool or
|
|
242
|
+
// not at all: with nothing to draw on, `<namespace>.read_file` would be a
|
|
243
|
+
// name this surface invented.
|
|
244
|
+
const name = pool.find((t) => t.name.endsWith('read_file'))?.name ?? pool[0]?.name ?? null;
|
|
245
|
+
// The CALL example: the simplest call the catalog fully determines.
|
|
246
|
+
let best;
|
|
247
|
+
for (const tool of pool) {
|
|
248
|
+
const value = satisfyingValue(tool.schema, 0);
|
|
249
|
+
if (!value)
|
|
250
|
+
continue;
|
|
251
|
+
if (!best ||
|
|
252
|
+
value.scalars < best.value.scalars ||
|
|
253
|
+
(value.scalars === best.value.scalars && preference(tool.name) < preference(best.name))) {
|
|
254
|
+
best = { name: tool.name, value };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { namespace: ns, name, call: best ? `${best.name}(${best.value.source})` : null };
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=chain-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-example.js","sourceRoot":"","sources":["../src/chain-example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAsDrF,iFAAiF;AACjF,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB;;;;;;;GAOG;AACH,MAAM,uBAAuB,GAAG,CAAC,eAAe,CAAC,CAAC;AAqBlD;;;;;;;;;;GAUG;AACH,SAAS,KAAK,CAAC,IAAY;IACzB,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QAC9B,IAAI,EAAE,KAAK,IAAI;YAAE,GAAG,IAAI,MAAM,CAAC;aAC1B,IAAI,EAAE,KAAK,GAAG;YAAE,GAAG,IAAI,KAAK,CAAC;aAC7B,IAAI,EAAE,KAAK,IAAI;YAAE,GAAG,IAAI,KAAK,CAAC;aAC9B,IAAI,EAAE,KAAK,IAAI;YAAE,GAAG,IAAI,KAAK,CAAC;aAC9B,IAAI,EAAE,KAAK,IAAI;YAAE,GAAG,IAAI,KAAK,CAAC;aAC9B,IAAI,EAAE,KAAK,GAAG;YAAE,GAAG,IAAI,OAAO,CAAC;aAC/B,IAAI,EAAE,GAAG,IAAI,IAAI,EA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AM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK;YAAE,SAAS;QACrB,IACE,CAAC,IAAI;YACL,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO;YAClC,CAAC,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EACvF,CAAC;YACD,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { CodeModeUtcpClient } from '@utcp/code-mode';
|
|
2
|
+
/**
|
|
3
|
+
* What runs a `call_tool_chain` chain, for every surface that offers one: the
|
|
4
|
+
* hosted MCP proxy, the local `hexis-mcp` server and the in-process agent's
|
|
5
|
+
* Mastra tool.
|
|
6
|
+
*
|
|
7
|
+
* Three things live here because all three surfaces need them to be the same:
|
|
8
|
+
*
|
|
9
|
+
* - the BROWSER GLOBALS a chain is promised (`atob`, `btoa`, `TextEncoder`,
|
|
10
|
+
* `TextDecoder`). `@utcp/code-mode` runs the chain in a bare `isolated-vm`
|
|
11
|
+
* isolate — plain V8, so no Node globals (`Buffer`) and no web platform
|
|
12
|
+
* (`atob`), and a chain could not decode base64 or bytes at all. They are
|
|
13
|
+
* added as a PRELUDE to the chain's own source rather than injected into
|
|
14
|
+
* the isolate's context, because the isolate is created inside
|
|
15
|
+
* `callToolChain` and is reachable from nowhere else (see
|
|
16
|
+
* {@link CHAIN_RUNTIME_PRELUDE});
|
|
17
|
+
* - the ANSWER for a chain that failed. `callToolChain` does not throw when
|
|
18
|
+
* the chain dies: it resolves `{ result: null, logs: ['[ERROR] Code
|
|
19
|
+
* execution failed: …'] }`, so a surface that read only `result` reported
|
|
20
|
+
* `success: true` with a null result and the agent was told nothing. Every
|
|
21
|
+
* failure — a timeout, an undefined namespace, a tool that threw — becomes
|
|
22
|
+
* an error that says what happened;
|
|
23
|
+
* - the promise that a chain ALWAYS answers. A request that never settles is
|
|
24
|
+
* what reaches an agent as a dropped connection rather than as something it
|
|
25
|
+
* can act on, so the runner is raced against a watchdog (see
|
|
26
|
+
* {@link WATCHDOG_GRACE_MS}).
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* The largest `timeout` a chain may ask for, in milliseconds. One constant: it
|
|
30
|
+
* is the schema's bound on every surface AND the figure the timeout error tells
|
|
31
|
+
* the agent it may raise `timeout` to, and those two drifting apart would send
|
|
32
|
+
* an agent to retry with a value the schema then clamps straight back down.
|
|
33
|
+
*/
|
|
34
|
+
export declare const CHAIN_TIMEOUT_MAX_MS = 120000;
|
|
35
|
+
/** The smallest `timeout` a chain may ask for, in milliseconds. */
|
|
36
|
+
export declare const CHAIN_TIMEOUT_MIN_MS = 1000;
|
|
37
|
+
/** The `timeout` a chain that does not ask for one gets, in milliseconds. */
|
|
38
|
+
export declare const CHAIN_TIMEOUT_DEFAULT_MS = 30000;
|
|
39
|
+
/**
|
|
40
|
+
* The browser globals, as ONE physical line of plain ES5 JavaScript.
|
|
41
|
+
*
|
|
42
|
+
* One line on purpose. The prelude is prepended to the agent's own chain
|
|
43
|
+
* source, and a failed chain is reported with its stack in it; a multi-line
|
|
44
|
+
* prelude would shift every line number in that stack and point the agent at
|
|
45
|
+
* the wrong line of its own code. Prepended WITHOUT a trailing newline for the
|
|
46
|
+
* same reason, so the chain's first line stays line one. (The one casualty is
|
|
47
|
+
* a `'use strict'` directive written as a chain's first statement, which is no
|
|
48
|
+
* longer in first position and so no longer applies. A chain is a handful of
|
|
49
|
+
* statements against a tool catalog, and strict mode is not something the
|
|
50
|
+
* chain protocol ever offered.)
|
|
51
|
+
*
|
|
52
|
+
* `atob`/`btoa` follow WHATWG forgiving-base64: ASCII whitespace is stripped,
|
|
53
|
+
* the padding is optional, and anything else throws rather than decoding to
|
|
54
|
+
* silent garbage. `TextEncoder`/`TextDecoder` are UTF-8 only — that is the
|
|
55
|
+
* encoding the Specification asks for, and a decoder that took a `label` it
|
|
56
|
+
* then ignored would quietly answer mojibake. `TextDecoder` drops a leading
|
|
57
|
+
* byte-order mark the way a browser's default does, and keeps it under
|
|
58
|
+
* `{ ignoreBOM: true }`: a chain decoding a UTF-8 file written on Windows would
|
|
59
|
+
* otherwise find a stray `\uFEFF` at the front of it, which breaks a
|
|
60
|
+
* `JSON.parse` and every exact-match comparison. It honours `{ stream: true }`:
|
|
61
|
+
* a chain that decodes bytes in pieces gets a character whose bytes straddle
|
|
62
|
+
* two pieces whole, where a decoder that started afresh on every call returned
|
|
63
|
+
* two replacement characters for it — and a call without the option ends the
|
|
64
|
+
* stream, answering a sequence left unfinished as one. Each is defined only when the
|
|
65
|
+
* runtime does not already have it, so a future `@utcp/code-mode` that ships
|
|
66
|
+
* them natively wins.
|
|
67
|
+
*/
|
|
68
|
+
export declare const CHAIN_RUNTIME_PRELUDE: string;
|
|
69
|
+
/**
|
|
70
|
+
* The agent's chain source with the runtime prelude in front of it, on the same
|
|
71
|
+
* physical line, so a stack from the chain still names the chain's own line
|
|
72
|
+
* numbers (see {@link CHAIN_RUNTIME_PRELUDE}).
|
|
73
|
+
*/
|
|
74
|
+
export declare function withChainRuntime(code: string): string;
|
|
75
|
+
/** The outcome of a chain: either its value, or the reason it has none. */
|
|
76
|
+
export type ToolChainOutcome = {
|
|
77
|
+
ok: true;
|
|
78
|
+
result: unknown;
|
|
79
|
+
logs: string[];
|
|
80
|
+
} | {
|
|
81
|
+
ok: false;
|
|
82
|
+
error: string;
|
|
83
|
+
logs: string[];
|
|
84
|
+
status?: number;
|
|
85
|
+
data?: unknown;
|
|
86
|
+
};
|
|
87
|
+
/** The namespaces and bare functions a chain can call, as the runtime spells them. */
|
|
88
|
+
export interface ChainNamespaces {
|
|
89
|
+
namespaces: string[];
|
|
90
|
+
bare: string[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What a chain can actually call. `@utcp/code-mode` gives every tool whose UTCP
|
|
94
|
+
* name is `MANUAL.tool` a `global.MANUAL` object, so the namespaces are the
|
|
95
|
+
* sanitized manual names — and a tool registered under a bare name becomes a
|
|
96
|
+
* global function rather than a namespace, which is why those are listed apart.
|
|
97
|
+
*/
|
|
98
|
+
export declare function chainNamespaces(client: CodeModeUtcpClient): Promise<ChainNamespaces>;
|
|
99
|
+
/** What a chain is told when it timed out: the limit it hit, and how to raise it. */
|
|
100
|
+
export declare function chainTimeoutMessage(timeoutMs: number): string;
|
|
101
|
+
/** What a chain is told when it exhausted the isolate's heap. */
|
|
102
|
+
export declare function chainOutOfMemoryMessage(reason: string): string;
|
|
103
|
+
/** What a chain is told when it named something the runtime has no binding for. */
|
|
104
|
+
export declare function unknownNamespaceMessage(identifier: string, found: ChainNamespaces): string;
|
|
105
|
+
/**
|
|
106
|
+
* Turn the runner's reason into the sentence the agent reads. A timeout, an
|
|
107
|
+
* exhausted heap and an undefined namespace each get their own; anything else
|
|
108
|
+
* passes through exactly as the runner reported it, so a real cause is never
|
|
109
|
+
* replaced by a guess.
|
|
110
|
+
*/
|
|
111
|
+
export declare function describeChainFailure(client: CodeModeUtcpClient, reason: string, timeoutMs: number): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Run a chain and ALWAYS answer: with its value, or with the reason it has
|
|
114
|
+
* none. Never throws, and never leaves a caller waiting past the chain's own
|
|
115
|
+
* timeout plus {@link WATCHDOG_GRACE_MS}.
|
|
116
|
+
*
|
|
117
|
+
* What the caller does with an error is still the caller's (the hosted proxy
|
|
118
|
+
* maps a retired tool's name onto its own message first, for instance); this
|
|
119
|
+
* decides only whether there IS one and what it says about the runtime.
|
|
120
|
+
*/
|
|
121
|
+
export declare function runToolChain(client: CodeModeUtcpClient, code: string, timeoutMs: number): Promise<ToolChainOutcome>;
|
|
122
|
+
//# sourceMappingURL=chain-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-runtime.d.ts","sourceRoot":"","sources":["../src/chain-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAI1D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,SAAU,CAAC;AAE5C,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAE1C,6EAA6E;AAC7E,eAAO,MAAM,wBAAwB,QAAS,CAAC;AA0B/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAoE1B,CAAC;AAEX;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,2EAA2E;AAC3E,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAC7C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAElF,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,E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