@cubicecho/agent-core 2.23.0 → 2.25.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.
Files changed (71) hide show
  1. package/README.md +14 -9
  2. package/dist/agent-loop.d.ts +84 -204
  3. package/dist/agent-loop.js +416 -643
  4. package/dist/calibration.d.ts +14 -10
  5. package/dist/calibration.js +30 -22
  6. package/dist/capabilities.d.ts +140 -35
  7. package/dist/capabilities.js +345 -152
  8. package/dist/client.d.ts +104 -35
  9. package/dist/client.js +210 -78
  10. package/dist/compaction.d.ts +103 -60
  11. package/dist/compaction.js +163 -93
  12. package/dist/config.d.ts +48 -12
  13. package/dist/config.js +20 -1
  14. package/dist/continuation.d.ts +25 -17
  15. package/dist/continuation.js +70 -47
  16. package/dist/digest.d.ts +7 -0
  17. package/dist/digest.js +18 -0
  18. package/dist/errors.d.ts +24 -15
  19. package/dist/errors.js +23 -15
  20. package/dist/events.d.ts +108 -58
  21. package/dist/events.js +265 -128
  22. package/dist/guards.d.ts +53 -0
  23. package/dist/guards.js +55 -0
  24. package/dist/hook-events.d.ts +38 -0
  25. package/dist/hook-events.js +36 -0
  26. package/dist/hooks.d.ts +105 -83
  27. package/dist/hooks.js +224 -139
  28. package/dist/index.d.ts +30 -25
  29. package/dist/index.js +29 -23
  30. package/dist/ledger.d.ts +62 -30
  31. package/dist/ledger.js +163 -56
  32. package/dist/platform.d.ts +13 -0
  33. package/dist/platform.js +13 -0
  34. package/dist/preselect.d.ts +222 -0
  35. package/dist/preselect.js +290 -0
  36. package/dist/request-body.d.ts +32 -0
  37. package/dist/request-body.js +47 -0
  38. package/dist/reset.d.ts +1 -0
  39. package/dist/reset.js +7 -6
  40. package/dist/retry.d.ts +40 -143
  41. package/dist/retry.js +79 -285
  42. package/dist/run-calls.d.ts +123 -0
  43. package/dist/run-calls.js +351 -0
  44. package/dist/run-turn.d.ts +44 -16
  45. package/dist/run-turn.js +74 -37
  46. package/dist/runtime.d.ts +23 -17
  47. package/dist/runtime.js +34 -24
  48. package/dist/schema-compat.d.ts +51 -11
  49. package/dist/schema-compat.js +375 -193
  50. package/dist/scope.d.ts +28 -5
  51. package/dist/scope.js +37 -10
  52. package/dist/side-task.d.ts +127 -39
  53. package/dist/side-task.js +189 -100
  54. package/dist/snapshot.d.ts +12 -7
  55. package/dist/snapshot.js +87 -65
  56. package/dist/spec.d.ts +66 -36
  57. package/dist/spec.js +514 -265
  58. package/dist/stream.d.ts +73 -16
  59. package/dist/stream.js +228 -98
  60. package/dist/thinking.d.ts +23 -8
  61. package/dist/thinking.js +96 -46
  62. package/dist/tokens.d.ts +171 -6
  63. package/dist/tokens.js +326 -6
  64. package/dist/tool-calls.d.ts +89 -15
  65. package/dist/tool-calls.js +205 -85
  66. package/dist/tool-loading.d.ts +109 -187
  67. package/dist/tool-loading.js +286 -372
  68. package/dist/wire.d.ts +81 -0
  69. package/dist/wire.js +73 -0
  70. package/llms.txt +87 -43
  71. package/package.json +4 -4
@@ -1,8 +1,9 @@
1
- import type OpenAI from "openai";
2
- import type { CatalogServer } from "./catalog.ts";
1
+ import type OpenAI from 'openai';
2
+ import type { CatalogServer } from './catalog.ts';
3
3
  /**
4
4
  * On-demand tool loading.
5
5
  *
6
+ * @remarks
6
7
  * A full tool definition is mostly JSON Schema, and it is sent on every request of every
7
8
  * iteration whether or not the model wants it — a couple of connected servers can cost more
8
9
  * tokens per request than the task's own prompt. So in on-demand mode the run starts with a
@@ -17,6 +18,7 @@ export declare const LOAD_TOOLS = "load_tools";
17
18
  /**
18
19
  * One object for the life of the process — the agent loop asks for it on every iteration.
19
20
  *
21
+ * @remarks
20
22
  * Frozen because it is shared: one mutable export reached by every consumer in the process
21
23
  * means a caller that edits the description in place has edited it for all of them, in a place
22
24
  * nobody would think to look for the change.
@@ -25,18 +27,28 @@ export declare const LOAD_TOOLS_DEFINITION: OpenAI.ChatCompletionTool;
25
27
  /**
26
28
  * The catalogue as a plain grouped listing of names, loaded ones marked if asked.
27
29
  *
30
+ * @param catalog - The connected servers. Ones with no tools are dropped.
31
+ * @param [loaded] - Names to mark `(loaded)` rather than remove. Absent marks nothing, which keeps the
32
+ * listing the same text for the whole run.
33
+ * @returns Each server's label on a line ending in a colon, its tool names indented beneath, one
34
+ * server straight after another. Empty where no server has a tool.
35
+ *
36
+ * @remarks
28
37
  * A server with no tools is dropped rather than titled: a pool hands one over whenever a
29
38
  * server is connected but has nothing to offer, and a label with nothing under it reads as a
30
39
  * listing that got cut off.
31
- *
32
- * @param catalog The connected servers. Ones with no tools are dropped.
33
- * @param loaded Names to mark `(loaded)` rather than remove. Absent marks nothing, which keeps the
34
- * listing the same text for the whole run.
35
40
  */
36
41
  export declare function catalogList(catalog: CatalogServer[], loaded?: ReadonlySet<string>): string;
37
42
  /**
38
43
  * The catalogue block appended to the system prompt. Names only — descriptions arrive on load.
39
44
  *
45
+ * @param catalog - The connected servers. A catalogue with no tools in it produces an empty string.
46
+ * @param [loaded] - Names to mark `(loaded)`, for a caller that rebuilds its prompt per load and does
47
+ * not mind the cache. Absent marks nothing.
48
+ * @returns The heading, the instructions and the listing, with no blank line before or after — the
49
+ * caller separates it from its own prompt. Empty where there is nothing to list.
50
+ *
51
+ * @remarks
40
52
  * `runAgentLoop` passes no `loaded`, so the block is the same text on every step. The system
41
53
  * prompt is the head of the request, and marking each load there threw away the prompt cache for
42
54
  * the whole transcript on every `load_tools` call. What is loaded is said where it does not move
@@ -47,22 +59,34 @@ export declare function catalogList(catalog: CatalogServer[], loaded?: ReadonlyS
47
59
  * it was loaded, and the model loads again to get it back; hoisting them into a separate "already
48
60
  * loaded" section splits a server's tools apart, and the model picks a sibling from the longer
49
61
  * list instead.
50
- *
51
- * @param catalog The connected servers. A catalogue with no tools in it produces an empty string.
52
- * @param loaded Names to mark `(loaded)`, for a caller that rebuilds its prompt per load and does
53
- * not mind the cache. Absent marks nothing.
54
62
  */
55
63
  export declare function catalogPrompt(catalog: CatalogServer[], loaded?: ReadonlySet<string>): string;
64
+ /**
65
+ * The name a tool definition is called by, or `undefined` for one that is not a function.
66
+ *
67
+ * @param tool - The definition, as a request declares it.
68
+ * @returns The function's name as the definition spells it — an empty one comes back empty, not
69
+ * `undefined`.
70
+ *
71
+ * @remarks
72
+ * Undefined rather than empty, so a caller that skips such a tool and one that has to place it
73
+ * somewhere each say which they mean — a sort and a positional comparison want `?? ""`, a lookup
74
+ * by name wants the tool left out.
75
+ */
76
+ export declare const toolName: (tool: OpenAI.ChatCompletionTool) => string | undefined;
56
77
  /**
57
78
  * A tool array with newly loaded definitions appended, in the order they were loaded.
58
79
  *
80
+ * @param previous - What the last request declared, `load_tools` included. Not written to.
81
+ * @param matched - The definitions to add. Ones whose name is already declared, here or earlier in
82
+ * this list, are skipped rather than moved. One that is not a function has no name to be
83
+ * skipped by, and is appended.
84
+ * @returns A new array, `previous` first — a copy even where nothing was added.
85
+ *
86
+ * @remarks
59
87
  * Appended and never rebuilt from a set, so what a load adds is decided by the load and not by
60
88
  * the shape of whatever collection the definitions came out of. Where the appended array ends up
61
89
  * in the request is `orderTools`' business, which the loop applies after this.
62
- *
63
- * @param previous What the last request declared, `load_tools` included. Not written to.
64
- * @param matched The definitions to add. Ones whose name is already declared, here or earlier in
65
- * this list, are skipped rather than moved.
66
90
  */
67
91
  export declare function loadedTools(previous: readonly OpenAI.ChatCompletionTool[], matched: readonly OpenAI.ChatCompletionTool[]): OpenAI.ChatCompletionTool[];
68
92
  /**
@@ -73,6 +97,12 @@ export type ToolOrder = boolean | ((a: string, b: string) => number);
73
97
  /**
74
98
  * The tool array in a stable order, so the same set of tools renders the same way twice.
75
99
  *
100
+ * @param tools - The definitions to order. Not written to.
101
+ * @param [order] - `true` for name order, `false` to leave it alone, or a comparator over the names.
102
+ * A tool that is not a function orders as the empty name.
103
+ * @returns `tools` itself when it is already in that order, so the common case copies nothing.
104
+ *
105
+ * @remarks
76
106
  * A chat template renders the declared tools ahead of the system prompt, which makes the tool
77
107
  * array the first thing a prompt cache has to match — and an array assembled from a map, from
78
108
  * database rows, or from the order servers happened to connect in changes between processes and
@@ -84,16 +114,12 @@ export type ToolOrder = boolean | ((a: string, b: string) => number);
84
114
  *
85
115
  * `false` is for a caller that means its order: the model reads the array top to bottom, and a
86
116
  * host may be putting what it wants reached for first at the front.
87
- *
88
- * @param tools The definitions to order. Not written to.
89
- * @param order `true` for name order, `false` to leave it alone, or a comparator over the names.
90
- * A tool that is not a function orders as the empty name.
91
- * @returns `tools` itself when it is already in that order, so the common case copies nothing.
92
117
  */
93
118
  export declare function orderTools(tools: OpenAI.ChatCompletionTool[], order?: ToolOrder): OpenAI.ChatCompletionTool[];
94
119
  /**
95
120
  * The most a single `load_tools` call may pull in.
96
121
  *
122
+ * @remarks
97
123
  * A wildcard like `gmail__*` matches 33 tools, and loading them all puts the model right back
98
124
  * in the position on-demand loading exists to avoid — a tool array too large to choose from.
99
125
  * Over-broad requests are refused with the matching names listed, so the next call can be
@@ -109,6 +135,7 @@ export declare const MAX_PER_LOAD = 12;
109
135
  * The most a conversation carries between turns. Bounds the tool array no matter how long the
110
136
  * conversation runs; past it, the earliest-declared names this turn did not use fall off first.
111
137
  *
138
+ * @remarks
112
139
  * Only a multi-turn caller needs this — a run that starts from nothing each time has nothing to
113
140
  * carry. See `carryOver`, which takes another number if this one is not yours.
114
141
  */
@@ -116,34 +143,39 @@ export declare const MAX_CARRIED = 16;
116
143
  /**
117
144
  * The tools to start the next turn with: last turn's where they were, then what this turn used.
118
145
  *
146
+ * @param previous - Last turn's names, in the order they were declared.
147
+ * @param used - What this turn called. Names not already carried are appended in the order given,
148
+ * so pass them in load order to keep them where the tool array had them.
149
+ * @param [max] - How many to carry. Past it, the earliest names not in
150
+ * `used` go first, then the earliest of all. At least one: a cap of zero is read as one, not as
151
+ * no cap and not as none.
152
+ * @returns The names to carry, as a new array no longer than the cap.
153
+ *
154
+ * @remarks
119
155
  * Nothing carried moves. A template renders the tool array near the head of the prompt, and
120
156
  * moving each used tool to the end — which this did until it was found in a local server's cache
121
157
  * log — reordered the array between turns and re-prefilled the whole transcript from the first
122
158
  * moved definition. Kept in place, the next turn's array is this one's with only the unused
123
159
  * loads gone, a prefix of it when every load was used. Past `max`, dropping a name from the
124
160
  * middle costs the cache from there, so it happens only when the cap forces it.
125
- *
126
- * @param previous Last turn's names, in the order they were declared.
127
- * @param used What this turn called. Names not already carried are appended in the order given,
128
- * so pass them in load order to keep them where the tool array had them.
129
- * @param max How many to carry, defaulting to `MAX_CARRIED`. Past it, the earliest names not in
130
- * `used` go first, then the earliest of all. At least one: a cap of zero is read as one, not as
131
- * no cap and not as none.
132
161
  */
133
162
  export declare function carryOver(previous: readonly string[], used: ReadonlySet<string>, max?: number): string[];
134
163
  /**
135
164
  * Resolves requested names against the catalogue, expanding trailing `*` wildcards.
136
165
  *
166
+ * @param requested - What the model asked for. A trailing `*` expands.
167
+ * @param catalog - The servers to resolve against.
168
+ * @param [maxPerLoad] - The most this call may load. It comes back on
169
+ * the resolution so `loadResult` reports the same number rather than a second opinion of it.
170
+ * @returns The names that resolved, each once; the ones nothing matched; the asks too broad for
171
+ * any call, with what they matched; and the ones that only did not fit this call.
172
+ *
173
+ * @remarks
137
174
  * Names are matched leniently. Catalogue entries are slug-qualified (`nas_fs__read_file`) and
138
175
  * models routinely ask for the bare tool name, so an exact miss falls back to a suffix match
139
176
  * on the `__` boundary — accepted only when it is unambiguous. Rejecting those outright just
140
177
  * buys a wasted round trip while the model guesses the prefix, and pushes it toward
141
178
  * shotgunning wildcards.
142
- *
143
- * @param requested What the model asked for. A trailing `*` expands.
144
- * @param catalog The servers to resolve against.
145
- * @param maxPerLoad The most this call may load, defaulting to `MAX_PER_LOAD`. It comes back on
146
- * the resolution so `loadResult` reports the same number rather than a second opinion of it.
147
179
  */
148
180
  export declare function expandNames(requested: string[], catalog: CatalogServer[], maxPerLoad?: number): {
149
181
  matched: string[];
@@ -158,31 +190,39 @@ export declare function expandNames(requested: string[], catalog: CatalogServer[
158
190
  /**
159
191
  * What `load_tools` reports back: the descriptions, now that they are worth their tokens.
160
192
  *
193
+ * @param expanded - What `expandNames` resolved: the matches, the misses, and the over-broad asks.
194
+ * @param catalog - The servers, read for the descriptions now worth their tokens.
195
+ * @param [loaded] - What was loaded before this call. Absent reports every match as newly loaded.
196
+ * @returns What the model reads, a blank line between each thing it is told: what was loaded with
197
+ * its descriptions, what already was, each over-broad ask with its matches, what did not fit this
198
+ * call, and what is not in the catalogue. `No tool names were given.` where there is none of them.
199
+ *
200
+ * @remarks
161
201
  * A name that was loaded before this call is reported as already loaded rather than loaded
162
202
  * again. The catalogue no longer marks what is loaded — see `catalogPrompt` — so this is where a
163
203
  * model that asks twice finds out it need not have, and is told to call the tool instead.
164
- *
165
- * @param expanded What `expandNames` resolved: the matches, the misses, and the over-broad asks.
166
- * @param catalog The servers, read for the descriptions now worth their tokens.
167
- * @param loaded What was loaded before this call. Absent reports every match as newly loaded.
168
204
  */
169
205
  export declare function loadResult({ matched, unknown, overBroad, deferred, maxPerLoad }: ReturnType<typeof expandNames>, catalog: CatalogServer[], loaded?: ReadonlySet<string>): string;
170
206
  /**
171
207
  * Whether the catalogue holds a tool by this name.
172
208
  *
173
- * @param catalog The connected servers and the tools each one offers.
174
- * @param name An exact name. Nothing is prefixed, trimmed or fuzzily matched.
209
+ * @param catalog - The connected servers and the tools each one offers.
210
+ * @param name - An exact name. Nothing is prefixed, trimmed or fuzzily matched.
211
+ * @returns True where any server offers it, which no server of an empty catalogue does.
175
212
  */
176
213
  export declare const inCatalog: (catalog: CatalogServer[], name: string) => boolean;
177
214
  /**
178
215
  * `load_tools` arguments, defensively — a model may send a bare string or a nested object.
179
216
  *
180
- * @param args The tool call's arguments, exactly as the model sent them.
217
+ * @param args - The tool call's arguments, exactly as the model sent them.
218
+ * @returns The names under `names`, or failing that `tools`, or `name`: a string as a list of one,
219
+ * an array less whatever in it is not a string, and anything else as none. Not trimmed.
181
220
  */
182
221
  export declare function requestedNames(args: Record<string, unknown>): string[];
183
222
  /**
184
223
  * The one tool a proxied run reaches every catalogued tool through.
185
224
  *
225
+ * @remarks
186
226
  * Proxied discovery is on-demand loading with a tool array that never changes. On-demand mode
187
227
  * declares each tool as it is loaded, and a chat template renders the tool array in the system
188
228
  * turn, ahead of the whole conversation — so appending one definition there moves every token
@@ -198,6 +238,7 @@ export declare const CALL_TOOL = "call_tool";
198
238
  * The whole tool array of a proxied run, `load_tools` then `call_tool`, frozen because it is
199
239
  * shared.
200
240
  *
241
+ * @remarks
201
242
  * The load keeps `LOAD_TOOLS` as its name, so `requestedNames` and `expandNames` read its
202
243
  * arguments as they do on demand; only what it promises differs, which is why it is not
203
244
  * `LOAD_TOOLS_DEFINITION`. `call_tool`'s `arguments` says `additionalProperties: true` and has to:
@@ -210,52 +251,63 @@ export declare const PROXY_TOOLS: readonly OpenAI.ChatCompletionTool[];
210
251
  * The catalogue block for a proxied run's system prompt, worded for `call_tool` rather than for a
211
252
  * tool list.
212
253
  *
254
+ * @param catalog - The connected servers. A catalogue with no tools in it produces an empty string.
255
+ * @returns The heading, the instructions and the listing, with no blank line before or after.
256
+ *
257
+ * @remarks
213
258
  * `catalogPrompt` tells the model a loaded tool is in its tool list, which proxied is never true —
214
259
  * a model told so looks for it there and calls it natively. The listing itself is the same, and
215
260
  * like that one it is never marked, so the head of the prompt is one text for the whole session.
216
- *
217
- * @param catalog The connected servers. A catalogue with no tools in it produces an empty string.
218
261
  */
219
262
  export declare function proxyCatalogPrompt(catalog: CatalogServer[]): string;
220
263
  /**
221
264
  * Whether a tool result is a proxied load carrying definitions, which is the only copy of them
222
265
  * the model has.
223
266
  *
267
+ * @param result - The tool message's text. A load that only pointed back or refused is not one.
268
+ * @returns True where the text opens as `proxyLoadResult` opens a result with a definition in it.
269
+ *
270
+ * @remarks
224
271
  * On demand the definitions are in the tool array and a load's result only repeats their
225
272
  * descriptions, so clearing it loses nothing. Proxied, the result is the schema, and
226
273
  * `pruneToolResults` asks this before it stubs one. Told by how `proxyLoadResult` opens, the way
227
274
  * a summary is told by `SUMMARY_LEAD`, because a `tool` message carries no tool name of its own.
228
- *
229
- * @param result The tool message's text. A load that only pointed back or refused is not one.
230
275
  */
231
276
  export declare const holdsDefinitions: (result: string) => boolean;
232
277
  /**
233
278
  * What a proxied `load_tools` answers: each new tool's whole definition as a line of JSON, since
234
279
  * the result is the only place the model will ever see it.
235
280
  *
281
+ * @param resolved - What the call asked for, from `expandNames`.
282
+ * @param catalog - The servers, read for the refusals' wording.
283
+ * @param definitions - The definitions of `resolved.matched`, as many as the host has. Ones that
284
+ * are not functions are skipped.
285
+ * @param [loaded] - What was loaded before this call. Absent reports every match as newly loaded.
286
+ * @returns What the model reads, a blank line between each part: the count and one line of JSON
287
+ * per new definition, then what was already loaded, what has no definition, and the refusals.
288
+ * Never empty.
289
+ *
290
+ * @remarks
236
291
  * A name loaded before this call is answered with a pointer back rather than its definition a
237
292
  * second time, and one the catalogue lists but `definitions` does not hold is said to have none,
238
293
  * so the model is not left waiting on a schema that is not coming. The refusals — too broad, over
239
294
  * the per-call cap, not in the catalogue, nothing asked for — are `loadResult`'s, worded the same
240
295
  * in both modes.
241
- *
242
- * @param resolved What the call asked for, from `expandNames`.
243
- * @param catalog The servers, read for the refusals' wording.
244
- * @param definitions The definitions of `resolved.matched`, as many as the host has. Ones that
245
- * are not functions are skipped.
246
- * @param loaded What was loaded before this call. Absent reports every match as newly loaded.
247
296
  */
248
297
  export declare function proxyLoadResult(resolved: ReturnType<typeof expandNames>, catalog: CatalogServer[], definitions: readonly OpenAI.ChatCompletionTool[], loaded?: ReadonlySet<string>): string;
249
298
  /**
250
299
  * The tool a `call_tool` names and the arguments to run it with, or a throw the model can read.
251
300
  *
301
+ * @param args - The `call_tool` call's own arguments, parsed. An absent `arguments` is no arguments.
302
+ * @param catalog - What may be called. The name is trimmed and then matched exactly.
303
+ * @returns The trimmed name, and the arguments as an object: the one the model passed, not a copy,
304
+ * or the one its JSON string parsed to.
305
+ *
306
+ * @remarks
252
307
  * `arguments` arrives as an object when the model follows the schema and as a JSON string when it
253
308
  * copies the shape of a native call instead; both are taken, since the intent is the same. A name
254
309
  * outside the catalogue is refused here rather than handed to a dispatcher, which is what keeps
255
310
  * `call_tool` from reaching anything the catalogue does not offer.
256
- *
257
- * @param args The `call_tool` call's own arguments, parsed. An absent `arguments` is no arguments.
258
- * @param catalog What may be called. The name is trimmed and then matched exactly.
259
311
  */
260
312
  export declare function proxiedCall(args: Record<string, unknown>, catalog: CatalogServer[]): {
261
313
  name: string;
@@ -265,147 +317,17 @@ export declare function proxiedCall(args: Record<string, unknown>, catalog: Cata
265
317
  * A tool call as a watcher should see it: a `call_tool` as the tool it ran, anything else as it
266
318
  * is.
267
319
  *
320
+ * @param name - The name the model called.
321
+ * @param input - The call's arguments as JSON text.
322
+ * @returns The inner name and its arguments as JSON text — the string itself where the model
323
+ * passed `arguments` as one.
324
+ *
325
+ * @remarks
268
326
  * The transcript keeps the `call_tool` the model wrote, since the next request has to repeat it
269
327
  * word for word to stay in the cache; only the display looks through it. Anything that does not
270
328
  * parse as a proxied call is left as it came.
271
- *
272
- * @param name The name the model called.
273
- * @param input The call's arguments as JSON text.
274
- * @returns The inner name and its arguments as JSON text — the string itself where the model
275
- * passed `arguments` as one.
276
329
  */
277
330
  export declare function shownCall(name: string, input: string): {
278
331
  name: string;
279
332
  input: string;
280
333
  };
281
- /**
282
- * The system prompt a preselector is given, holding it to the cap its answer will be held to.
283
- *
284
- * On-demand loading otherwise costs a round trip every run: the model reads the catalogue,
285
- * calls `load_tools`, and only then can do the work. A small model reading the same catalogue
286
- * usually names the right tools outright, so the task model finds them already loaded and
287
- * starts working on its first step.
288
- *
289
- * A wrong guess is cheap — an unused definition is a few hundred tokens for one run — but a
290
- * broad guess is not, so the same cap applies here as to a `load_tools` call.
291
- *
292
- * @param maxPerLoad The most to ask for, defaulting to `MAX_PER_LOAD`. Give `preselection` the
293
- * same number: this one is what the preselector is told, and that one is what it is held to.
294
- */
295
- export declare const preselectSystem: (maxPerLoad?: number) => string;
296
- /**
297
- * The shape a preselector's answer is held to where the server takes a schema: `{ tools: [...] }`.
298
- *
299
- * An object around the array rather than the array, because a structured answer's root has to be
300
- * an object — OpenAI's strict mode and every tool-schema normaliser insist.
301
- */
302
- export declare const PRESELECT_SCHEMA: {
303
- type: string;
304
- properties: {
305
- tools: {
306
- type: string;
307
- items: {
308
- type: string;
309
- };
310
- };
311
- };
312
- required: string[];
313
- additionalProperties: boolean;
314
- };
315
- /** The preselection system prompt at the default cap, for a caller that never changes it. */
316
- export declare const PRESELECT_SYSTEM: string;
317
- /**
318
- * The user message for a preselection call: the catalogue, then the request.
319
- *
320
- * @param catalog The connected servers, rendered as the name-only listing.
321
- * @param prompt The request being planned for, truncated — choosing tools needs the shape of the
322
- * ask, not all of it.
323
- * @param maxPromptChars Where the request is cut, defaulting to 2000. A caller whose requests
324
- * carry the part that names the work at the end wants a larger one, and pays for it in the
325
- * preselector's prompt.
326
- */
327
- export declare const preselectInput: (catalog: CatalogServer[], prompt: string, maxPromptChars?: number) => string;
328
- /**
329
- * Resolves a preselection against the catalogue: unknown names dropped, count capped.
330
- *
331
- * @param names What the preselector replied: `{ tools: [...] }` as `PRESELECT_SCHEMA` has it, or
332
- * the bare array an older prompt asked for. Unvalidated: anything else gives none, and entries
333
- * that are not strings are dropped.
334
- * @param catalog The servers to resolve against.
335
- * @param maxPerLoad The most to keep, defaulting to `MAX_PER_LOAD`. The same number
336
- * `preselectSystem` was given, or the model is being held to a cap it was never told about.
337
- */
338
- export declare function preselection(names: unknown, catalog: CatalogServer[], maxPerLoad?: number): string[];
339
- /**
340
- * The least a best match may score and still be acted on without a model.
341
- *
342
- * A BM25 score, so it is read against the shape of the corpus rather than as a percentage: a
343
- * query term carried by half the catalogue is worth about 0.7, and one carried by a single tool
344
- * about 3. One at this floor is therefore "something more distinctive than a word every other
345
- * tool uses", which is the weakest evidence worth skipping a round trip on.
346
- *
347
- * A term is distinctive only against other terms, so a catalogue of three or four tools rarely
348
- * clears it. That is the right answer rather than a gap: a catalogue that small is not costing
349
- * enough tokens to be worth choosing from in the first place.
350
- */
351
- export declare const KEYWORD_MIN_SCORE = 1;
352
- /**
353
- * How far the best unpicked tool must fall below the last picked one for the cut to count clean.
354
- *
355
- * Half. The cap is the only reason a hit is dropped, so a hit just underneath it scoring nearly
356
- * as much as one just above means the ranking chose arbitrarily, which is exactly the case a
357
- * model should be spent on.
358
- */
359
- export declare const KEYWORD_DROPOFF = 0.5;
360
- /** One tool's score against a request. */
361
- export interface ToolMatch {
362
- name: string;
363
- /** Its BM25 score. Zero-scoring tools are not ranked at all. */
364
- score: number;
365
- }
366
- /** What `preselectByKeywords` found. */
367
- export interface KeywordPreselection {
368
- /** The names, best first, capped at `maxPerLoad`. */
369
- names: string[];
370
- /** Whether the match is clear enough to run on without asking a model. */
371
- confident: boolean;
372
- /** Every tool that scored at all, best first — for a caller measuring its own threshold. */
373
- ranked: ToolMatch[];
374
- }
375
- /** What `preselectByKeywords` takes besides the catalogue and the request. */
376
- export interface KeywordPreselectOptions {
377
- /** The most to pick, defaulting to `MAX_PER_LOAD`. The same cap the model is held to. */
378
- maxPerLoad?: number;
379
- /** The floor under a confident best match, defaulting to `KEYWORD_MIN_SCORE`. */
380
- minScore?: number;
381
- /** The gap a confident cut needs, defaulting to `KEYWORD_DROPOFF`. */
382
- dropoff?: number;
383
- /** Where the request is cut, defaulting to 2000 — the same head `preselectInput` reads. */
384
- maxPromptChars?: number;
385
- }
386
- /**
387
- * The tools a request's own words point at, ranked, and whether they point clearly enough.
388
- *
389
- * A preselection call costs a round trip to a model that is being asked to do term matching, and
390
- * on a local box that is seconds before the run has started. For a catalogue of a few dozen tools
391
- * the words usually decide it: a request that says "commit" and a tool called `git__commit` need
392
- * no reasoning to connect.
393
- *
394
- * BM25 rather than counting shared words, because the ranking has to survive the words every tool
395
- * uses. "list", "get" and "file" are in half the descriptions in a real catalogue, and a plain
396
- * overlap count hands the top of the ranking to whichever tool has the longest description. The
397
- * inverse document frequency makes a term worth what it distinguishes, and the length
398
- * normalisation stops a wordy description from outscoring the tool actually named.
399
- *
400
- * `confident` is what a caller acts on, and it is deliberately hard to earn: something more
401
- * distinctive than a word the whole catalogue shares has to have matched, and the tools left
402
- * unpicked have to score well below the ones picked. Anything else is ambiguous, and ambiguous is
403
- * what the model is for. Nothing matching is not confident either — the words cannot tell "this
404
- * request needs no tools" from "these words are not in the catalogue".
405
- *
406
- * @param catalog The servers to choose from. Each tool is matched on its name, its server's label
407
- * and its one-line description, which is everything the catalogue holds.
408
- * @param prompt The request being planned for. Only its head is read, as in `preselectInput`.
409
- * @param options The cap, the two confidence thresholds, and where the request is cut.
410
- */
411
- export declare function preselectByKeywords(catalog: CatalogServer[], prompt: string, { maxPerLoad, minScore, dropoff, maxPromptChars, }?: KeywordPreselectOptions): KeywordPreselection;