@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
package/dist/wire.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The words the chat-completions wire is written in, each under a name.
3
+ *
4
+ * A leaf with no imports, because every module that builds a message or reads one needs these and
5
+ * they share nothing else. The `openai` types still say which word a field takes — these are the
6
+ * same literals, so a message built from them is checked exactly as one built from strings — and
7
+ * what the names add is that a role or a finish reason is spelled in one place.
8
+ */
9
+ /** Who a message is from. */
10
+ export declare const Role: {
11
+ /** The instructions a conversation opens with. */
12
+ readonly System: 'system';
13
+ /** What a reasoning model takes in place of `system`. */
14
+ readonly Developer: 'developer';
15
+ /** The person, or whatever stands in for one. */
16
+ readonly User: 'user';
17
+ /** The model. */
18
+ readonly Assistant: 'assistant';
19
+ /** A tool's result, answering the call whose id it carries. */
20
+ readonly Tool: 'tool';
21
+ };
22
+ /** Any one of the roles in `Role`. */
23
+ export type Role = (typeof Role)[keyof typeof Role];
24
+ /** Why a model stopped writing. */
25
+ export declare const FinishReason: {
26
+ /** It was done. */
27
+ readonly Stop: 'stop';
28
+ /** It ran into the reply ceiling, and what it wrote is cut off. */
29
+ readonly Length: 'length';
30
+ /** It asked for tools. */
31
+ readonly ToolCalls: 'tool_calls';
32
+ /** A filter withheld the reply. */
33
+ readonly ContentFilter: 'content_filter';
34
+ };
35
+ /** Any one of the reasons in `FinishReason`. */
36
+ export type FinishReason = (typeof FinishReason)[keyof typeof FinishReason];
37
+ /** What a part of a message's content is. */
38
+ export declare const PartType: {
39
+ /** Text. */
40
+ readonly Text: 'text';
41
+ /** The model declining, in place of an answer. */
42
+ readonly Refusal: 'refusal';
43
+ /** An image, by URL or inline. */
44
+ readonly ImageUrl: 'image_url';
45
+ /** An attached file. */
46
+ readonly File: 'file';
47
+ };
48
+ /** Any one of the part types in `PartType`. */
49
+ export type PartType = (typeof PartType)[keyof typeof PartType];
50
+ /** The types JSON Schema has, as the `type` keyword spells them. */
51
+ export declare const SchemaType: {
52
+ readonly Object: 'object';
53
+ readonly Array: 'array';
54
+ readonly String: 'string';
55
+ readonly Number: 'number';
56
+ readonly Integer: 'integer';
57
+ readonly Boolean: 'boolean';
58
+ readonly Null: 'null';
59
+ };
60
+ /** Any one of the types in `SchemaType`. */
61
+ export type SchemaType = (typeof SchemaType)[keyof typeof SchemaType];
62
+ /** The one `type` a tool definition or a tool call has on this wire. */
63
+ export declare const FUNCTION_TOOL: 'function';
64
+ /** The `response_format` type that carries a schema the reply has to fit. */
65
+ export declare const JSON_SCHEMA_FORMAT: 'json_schema';
66
+ /** The HTTP statuses this package reads a meaning into. */
67
+ export declare const HttpStatus: {
68
+ readonly Ok: 200;
69
+ readonly BadRequest: 400;
70
+ readonly Unauthorized: 401;
71
+ readonly NotFound: 404;
72
+ readonly MethodNotAllowed: 405;
73
+ readonly RequestTimeout: 408;
74
+ readonly Conflict: 409;
75
+ readonly UnprocessableEntity: 422;
76
+ readonly TooManyRequests: 429;
77
+ /** The first of the 5xx range, and so the floor of "the server's fault". */
78
+ readonly InternalServerError: 500;
79
+ readonly NotImplemented: 501;
80
+ readonly ServiceUnavailable: 503;
81
+ };
package/dist/wire.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The words the chat-completions wire is written in, each under a name.
3
+ *
4
+ * A leaf with no imports, because every module that builds a message or reads one needs these and
5
+ * they share nothing else. The `openai` types still say which word a field takes — these are the
6
+ * same literals, so a message built from them is checked exactly as one built from strings — and
7
+ * what the names add is that a role or a finish reason is spelled in one place.
8
+ */
9
+ /** Who a message is from. */
10
+ export const Role = {
11
+ /** The instructions a conversation opens with. */
12
+ System: 'system',
13
+ /** What a reasoning model takes in place of `system`. */
14
+ Developer: 'developer',
15
+ /** The person, or whatever stands in for one. */
16
+ User: 'user',
17
+ /** The model. */
18
+ Assistant: 'assistant',
19
+ /** A tool's result, answering the call whose id it carries. */
20
+ Tool: 'tool',
21
+ };
22
+ /** Why a model stopped writing. */
23
+ export const FinishReason = {
24
+ /** It was done. */
25
+ Stop: 'stop',
26
+ /** It ran into the reply ceiling, and what it wrote is cut off. */
27
+ Length: 'length',
28
+ /** It asked for tools. */
29
+ ToolCalls: 'tool_calls',
30
+ /** A filter withheld the reply. */
31
+ ContentFilter: 'content_filter',
32
+ };
33
+ /** What a part of a message's content is. */
34
+ export const PartType = {
35
+ /** Text. */
36
+ Text: 'text',
37
+ /** The model declining, in place of an answer. */
38
+ Refusal: 'refusal',
39
+ /** An image, by URL or inline. */
40
+ ImageUrl: 'image_url',
41
+ /** An attached file. */
42
+ File: 'file',
43
+ };
44
+ /** The types JSON Schema has, as the `type` keyword spells them. */
45
+ export const SchemaType = {
46
+ Object: 'object',
47
+ Array: 'array',
48
+ String: 'string',
49
+ Number: 'number',
50
+ Integer: 'integer',
51
+ Boolean: 'boolean',
52
+ Null: 'null',
53
+ };
54
+ /** The one `type` a tool definition or a tool call has on this wire. */
55
+ export const FUNCTION_TOOL = 'function';
56
+ /** The `response_format` type that carries a schema the reply has to fit. */
57
+ export const JSON_SCHEMA_FORMAT = 'json_schema';
58
+ /** The HTTP statuses this package reads a meaning into. */
59
+ export const HttpStatus = {
60
+ Ok: 200,
61
+ BadRequest: 400,
62
+ Unauthorized: 401,
63
+ NotFound: 404,
64
+ MethodNotAllowed: 405,
65
+ RequestTimeout: 408,
66
+ Conflict: 409,
67
+ UnprocessableEntity: 422,
68
+ TooManyRequests: 429,
69
+ /** The first of the 5xx range, and so the floor of "the server's fault". */
70
+ InternalServerError: 500,
71
+ NotImplemented: 501,
72
+ ServiceUnavailable: 503,
73
+ };
package/llms.txt CHANGED
@@ -17,16 +17,10 @@ The loop above a turn: send, run the tools the model asked for, send again, unti
17
17
  - `AgentLoopOptions` (type) — What `runAgentLoop` takes.
18
18
  - `AgentLoopRequest` (type) — One step's request as `onRequest` is handed it: what the model is about to read.
19
19
  - `AgentLoopResult` (type) — What a finished loop hands back.
20
- - `buildBody` — The one place a streamed request's body is decided from a config and what the endpoint and the model have refused.
21
- - `preselect` — The tools a request is likely to need, picked by a small model before the run starts, or none.
22
- - `preview` — A long tool argument or result cut to what a watcher needs, with the full length said.
23
- - `resolveApiKey` — The key to send, where an endpoint may inherit one from the settings it overrides.
20
+ - `PRESELECT_APPEND` — The `preselectRouting` that loads the shortlist after what was carried, and sends the first step like any other.
21
+ - `PRESELECT_EXCLUSIVE` — The `preselectRouting` that sends the first step the shortlist alone.
24
22
  - `runAgentLoop` — Runs a question to its answer: one `runTurn` per step, the tools it asks for between them, until a turn asks for none.
25
23
  - `StepWindow` (type) — How full the window is as a step is about to be sent, as `beforeStep` is told it.
26
- - `ToolCallOutcome` (type) — What one tool call did, in the order the model asked.
27
- - `ToolCallRequest` (type) — One call the model made, as `dispatch` and `onToolCall` are handed it.
28
- - `ToolCallResult` (type) — One call's whole answer, as `onToolResult` is handed it.
29
- - `taskCall` — A side task's settings as the call that honours them: its endpoint, its model, and the options `ask`, `askJson`, `summariser` and `preselect` take last.
30
24
 
31
25
  ### calibration
32
26
 
@@ -43,6 +37,8 @@ What an endpoint turned out not to support, and answering it when it says so.
43
37
  - `Capabilities` (type) — What one endpoint turned out not to support.
44
38
  - `capabilitiesFor` — What this endpoint is known not to support.
45
39
  - `EFFORT_LADDER` — The efforts this package can place, cheapest first.
40
+ - `EFFORT_NONE` — The lowest effort the wire has a word for, which is what a side task asks for.
41
+ - `EFFORT_OFF` — The setting that asks for no `reasoning_effort` field at all.
46
42
  - `effortFor` — What to actually put in `reasoning_effort` for a model that has refused the value asked for.
47
43
  - `expireCapabilities` — Forgets every endpoint whose entry is older than this, so the next request finds out again.
48
44
  - `ModelCapabilities` (type) — What one model on that endpoint turned out not to support.
@@ -71,8 +67,9 @@ The contract between whatever holds the tools and the loop that offers them to a
71
67
  - `ModelInfo` (type) — A model an endpoint offers, and what it says the model will read.
72
68
  - `NO_KEY` — The SDK insists on a non-empty key even where the server will not look at it.
73
69
  - `resetClients` — Forgets every cached client and listing, and puts `configureClients` back to the defaults.
70
+ - `resolveApiKey` — The key to send, where an endpoint may inherit one from the settings it overrides.
74
71
  - `servedWindow` — The window a local server's own API says it is serving a model in, for the servers whose listing does not say.
75
- - `timeoutMs` — Zero, less, or absent means no limit, which the SDK spells as `undefined`.
72
+ - `timeoutMs` — An endpoint's request timeout in the SDK's spelling: milliseconds, and `undefined` for no limit.
76
73
 
77
74
  ### compaction
78
75
 
@@ -104,6 +101,7 @@ What this package needs to know about a caller's configuration.
104
101
  - `Endpoint` (type) — Where to send a request and how long to wait.
105
102
  - `ModelParams` (type) — What to ask the model for.
106
103
  - `RetryPolicy` (type) — How many times a lost or refused request is worth sending again.
104
+ - `ToolDiscovery` — Any one of the modes in `ToolDiscovery`.
107
105
  - `ToolPolicy` (type) — How tools reach the model, and how long it may keep calling them.
108
106
 
109
107
  ### continuation
@@ -131,19 +129,28 @@ What a run is doing, while it is doing it.
131
129
  - `EventBusOptions` (type) — What the bus keeps and for how long.
132
130
  - `emit` — Records one event and hands it to everyone watching that run.
133
131
  - `endRun` — Forgets a run that will not be emitting `done` — one whose process is tearing down, or whose loop threw where it could not be caught.
134
- - `fold` — Consecutive tokens of one kind are one thing being said, not hundreds of things.
132
+ - `fold` — A run's events with each stretch of `thinking` or of `output` joined into one block, for a reader that takes a run in snapshots.
135
133
  - `history` — The backlog alone, for a caller that wants a snapshot rather than a subscription.
136
134
  - `RunEvent` (type) — One thing that happened in a run, as a watcher receives it.
137
135
  - `RunEventInput` (type) — What `emit` is given: the run and the sequence are the bus's to assign.
138
- - `RunEventKind` (type) — Which kind of thing happened, and what `text`, `name`, `ok` and `usage` carry for it.
136
+ - `RunEventKind` — Any one of the kinds in `RunEventKind`.
139
137
  - `RunMetrics` (type) — A run summed and derived from its events: what it cost, where the time went, and why.
140
138
  - `RunMetricsOptions` (type) — What `runMetrics` takes besides the events.
139
+ - `RunOutcome` — Any one of the outcomes in `RunOutcome`.
141
140
  - `RunUsage` (type) — What a run has spent, counted from the start of the run rather than for the turn that carried it: a client draws the latest one it has seen and needs no arithmetic of its own, and one lost to the backlog cap costs nothing because the next supersedes it.
142
141
  - `resetEvents` — Test seam: forget every run, so one test's events cannot be read by the next.
143
142
  - `runMetrics` — A run's totals, timings and cache findings, derived from the events it emitted.
144
143
  - `TurnReport` (type) — One turn's usage and measurements as a `usage` event carries them.
145
144
  - `watch` — Everything that has happened on a run, then everything that happens next, until it ends.
146
145
 
146
+ ### hook-events
147
+
148
+ The points in a session a hook can be bound to, apart from everything that runs one.
149
+
150
+ - `HOOK_EVENTS` — Every event a hook can be bound to, in the order a session meets them.
151
+ - `HookEvent` — Any one of the events in `HookEvent`.
152
+ - `INJECT_EVENTS` — The events whose hooks run before a request, and so the only ones whose output can reach it.
153
+
147
154
  ### hooks
148
155
 
149
156
  Lifecycle hooks, from the host's side: what a session looks like to them, where their context lands in a request, and what is said about each one.
@@ -154,16 +161,13 @@ Lifecycle hooks, from the host's side: what a session looks like to them, where
154
161
  - `Gathered` (type) — The context a set of outcomes adds to a request, and a note for each hook worth mentioning.
155
162
  - `gather` — Runs the hooks ahead of a request and builds what they add to it.
156
163
  - `HOOK_CONTEXT_TOKENS` — The most context all of a request's hooks add between them by default, in estimated tokens.
157
- - `HOOK_EVENTS` — Every event a hook can be bound to, in the order a session meets them.
158
164
  - `HOOK_PREFACE` — Said once, above the blocks, so the model reads them as background rather than instructions.
159
165
  - `HookContext` (type) — What a host knows at an event.
160
- - `HookEvent` (type) — A point in a session a hook can be bound to.
161
166
  - `HookMessage` (type) — One message of a session as a hook is handed it.
162
167
  - `HookNote` (type) — One hook's line for whoever is watching: the context it added, or why it added none.
163
168
  - `HookOptions` (type) — What hooks are held to across a process.
164
169
  - `HookOutcome` (type) — What one hook did.
165
170
  - `HookRunner` (type) — Runs one event's hooks.
166
- - `INJECT_EVENTS` — The events whose hooks run before a request, and so the only ones whose output can reach it.
167
171
  - `notify` — Runs the hooks for an event that reads what happened and adds nothing to a request.
168
172
  - `resetHooks` — Test seam: puts `configureHooks` back to the defaults, so one test's budget or preface is not the next's.
169
173
  - `turnIndex` — Which turn of a session begins at a point, from 0: the user messages ahead of it.
@@ -185,6 +189,27 @@ What stretches of a transcript cost, read off the prompt counts the server alrea
185
189
  - `TokenLedger` (type) — A transcript's entries in the order their requests were sent, which is also by `through`.
186
190
  - `tokensBetween` — What the messages from `from` up to, not including, `to` cost the window, measured where the ledger can say and estimated where it cannot.
187
191
 
192
+ ### preselect
193
+
194
+ Choosing a run's tools before it starts, from the request and the catalogue's names.
195
+
196
+ - `KEYWORD_DROPOFF` — How far the best unpicked tool must fall below the last picked one for the cut to count clean.
197
+ - `KEYWORD_MIN_SCORE` — The least a best match may score and still be acted on without a model.
198
+ - `KeywordPreselection` (type) — What `preselectByKeywords` found.
199
+ - `KeywordPreselectOptions` (type) — What `preselectByKeywords` takes besides the catalogue and the request.
200
+ - `PRESELECT_SCHEMA` — The shape a preselector's answer is held to where the server takes a schema: `{ tools: [...] }`.
201
+ - `PRESELECT_SYSTEM` — The preselection system prompt at the default cap, for a caller that never changes it.
202
+ - `preselect` — The tools a request is likely to need, picked by a small model before the run starts, or none.
203
+ - `preselectByKeywords` — The tools a request's own words point at, ranked, and whether they point clearly enough.
204
+ - `preselectInput` — The user message for a preselection call: the catalogue, then the request.
205
+ - `preselection` — Resolves a preselection against the catalogue: unknown names dropped, count capped.
206
+ - `preselectSystem` — The system prompt a preselector is given, holding it to the cap its answer will be held to.
207
+ - `ToolMatch` (type) — One tool's score against a request.
208
+
209
+ ### request-body
210
+
211
+ - `buildBody` — The one place a streamed request's body is decided from a config and what the endpoint and the model have refused.
212
+
188
213
  ### reset
189
214
 
190
215
  - `resetAll` — Forgets everything this package remembers between calls.
@@ -193,34 +218,29 @@ What stretches of a transcript cost, read off the prompt counts the server alrea
193
218
 
194
219
  Everything about a request failing that is not about what the request said.
195
220
 
196
- - `backoffMs` — Exponential, with jitter so several tasks failing at once do not return in lockstep.
197
- - `CHARS_PER_TOKEN` — The divisor behind `estimateTokens`, applied here to a character count rather than a string.
198
- - `ContextBreakdown` (type) — What a request is made of, by the part of it a consumer can actually do something about.
199
- - `ContextBreakdownOptions` (type) — What `contextTokens` takes besides the request.
221
+ - `backoffMs` — How long to wait before a retry: exponential, with jitter so several tasks failing at once do not return in lockstep.
200
222
  - `ContextOverflow` — The request was bigger than the model will read.
201
- - `compact` — 1234 → "1.2k".
202
- - `contextChars` — What each part of a request is worth in characters, by the same walk `requestTokens` divides.
203
- - `contextTokens` — What each part of a request costs the window, in tokens, adding up to the whole.
204
223
  - `EndpointSilent` — The endpoint stopped answering mid-request.
205
224
  - `isModelLoading` — Whether a failure is a local server still loading the model, rather than one failing to serve.
206
225
  - `isOverflow` — Whether a refusal means the request was too big, rather than merely refused.
207
226
  - `isTransient` — Whether a failed request is worth trying again.
208
227
  - `LOADING_POLL_MS` — How long to wait between asking a loading server again.
209
228
  - `LOADING_TIMEOUT_MS` — How long `runTurn` waits for a model to load unless told otherwise.
210
- - `messageTokens` — One message's estimated tokens, by the same count `requestTokens` sums for a whole request.
211
- - `requestChars` — How many characters a request is worth: the walk `requestTokens` divides, without the division.
212
- - `requestTokens` — What this request will cost the window, in tokens, near enough.
213
229
  - `SMALLEST_LIKELY_WINDOW` — The smallest window worth believing in, and the floor under `runTurn`'s guard.
214
230
  - `sleep` — A delay an abort cuts short, rejecting rather than resolving early.
215
- - `TokenEstimateOptions` (type) — What the two token estimates below take besides what they measure.
216
- - `toolsChars` — How many characters a tool array is worth, measured once per array.
231
+
232
+ ### run-calls
233
+
234
+ The tools between two turns: a step's calls read, run and written into the transcript.
235
+
236
+ - `preview` — A long tool argument or result cut to what a watcher needs, with the full length said.
217
237
 
218
238
  ### run-turn
219
239
 
220
240
  One turn, given as many attempts as the caller allows.
221
241
 
222
242
  - `RunTurnOptions` (type) — A retry is not the same event as a downgrade, but a watcher wants to be told about both.
223
- - `runTurn` — `request` is a callback rather than a body because the body has to be rebuilt from whatever the last attempt latched off: the tools it sends depend on `strictSchemas`, and `relaxTools` has to apply to the schemas that were just sanitised.
243
+ - `runTurn` — One turn seen through to an answer: negotiated with the endpoint, retried where the failure is transient, and waited for where the model is still loading.
224
244
 
225
245
  ### runtime
226
246
 
@@ -233,8 +253,10 @@ One turn, given as many attempts as the caller allows.
233
253
 
234
254
  JSON Schema compatibility for llama.cpp-backed servers.
235
255
 
236
- - `isGrammarError` — Does this failure look like the server could not build a grammar from our tool schemas?
237
- - `relaxTools` — The retry shape: llama.cpp's converter rejects regex escape classes (`\d`, `\w`, `\s`) in `pattern` and most `format` values, both of which only ever narrowed a string the tool re-validates anyway.
256
+ - `isGrammarError` — Whether a failure looks like the server could not build a grammar from our tool schemas.
257
+ - `relaxSchema` — One schema without its `pattern` and `format` keywords, for a schema that is not a tool's.
258
+ - `relaxTools` — The tool array with every schema's `pattern` and `format` keywords gone — the shape a turn is retried with.
259
+ - `sanitizeSchema` — One JSON Schema as a strict server will accept it, for a schema that is not a tool's parameters.
238
260
  - `sanitizeTools` — Tool definitions a strict server will accept, remembered per definition object.
239
261
 
240
262
  ### side-task
@@ -246,12 +268,13 @@ One-shot calls that support a run without being one: picking tools, naming a ses
246
268
  - `askJson` — A side task whose answer is JSON matching a schema, parsed.
247
269
  - `clean` — Strips the quoting and list punctuation models decorate short answers with.
248
270
  - `listLines` — A list-shaped reply, one item per line, cleaned of the bullets and quotes models decorate them with.
249
- - `parseJson` — Models are asked for JSON and often answer with prose around it, or a fenced block.
271
+ - `parseJson` — The first array or object in a model's reply, parsed, whatever prose or fence surrounds it.
250
272
  - `resetHints` — Test seam, alongside `resetClients` and `resetAll`: forget which models refused the hints.
251
273
  - `SideTask` (type) — One side task's own settings, as a resolved agent spec carries them under `tasks.<key>`.
252
274
  - `SideTaskInput` (type) — The input a side task applies its instruction to: text, or the content parts a vision model reads.
253
275
  - `SideTaskOptions` (type) — What a side task may be given.
254
- - `tryAsk` — A side task is never worth failing the work it supports.
276
+ - `taskCall` — A side task's settings as the call that honours them: its endpoint, its model, and the options `ask`, `askJson`, `summariser` and `preselect` take last.
277
+ - `tryAsk` — Runs a side task and answers `undefined` where it fails, so the work it supports carries on.
255
278
 
256
279
  ### snapshot
257
280
 
@@ -281,12 +304,14 @@ A JSON document that defines an agent, and the rules for reading one.
281
304
  - `ParseSpecOptions` (type) — What `parseSpec` takes besides the document.
282
305
  - `PromptPart` (type) — One layer of system prompt, named so a layer above can stack beside it or replace it.
283
306
  - `parseSpec` — Reads a document, dropping what it cannot use and refusing only what it cannot identify.
307
+ - `REF_FILE` — The `ref.type` of a prompt part whose text is in a file.
308
+ - `REF_URL` — The `ref.type` of a prompt part whose text is behind a URL.
284
309
  - `RESOLVED_DEFAULTS` — What a field falls back to when no layer said anything at all.
285
310
  - `ResolvedAgent` (type) — What layered documents resolve to: the flat shape the loop already takes, plus the parts of an agent that are the host's to act on.
286
311
  - `ResolvedTask` (type) — One side task, resolved: a model, and the endpoint it is reached through.
287
312
  - `RetrySpec` (type) — What to do about a request lost before the model produced anything.
288
313
  - `resolveAgentSpec` — Layers documents into the flat object the loop takes, weakest first.
289
- - `SPEC_EVENTS` — Every event a hook may be bound to, restated so this module stays free of `node:crypto`.
314
+ - `SPEC_EVENTS` — Every event a hook may be bound to: `HOOK_EVENTS`, under the name a document's reader knows.
290
315
  - `SpecBundle` (type) — What an agent carries so it can travel whole: the definitions of the servers it names.
291
316
  - `SpecServer` (type) — A bundled MCP server, validated only as far as a round trip needs and otherwise passed through.
292
317
  - `TaskSpec` (type) — One side task, which may run on a different model — and a different machine — than the agent.
@@ -296,6 +321,7 @@ A JSON document that defines an agent, and the rules for reading one.
296
321
 
297
322
  Reading one streamed turn back into a message.
298
323
 
324
+ - `CacheBreakReason` — Any one of the reasons in `CacheBreakReason`.
299
325
  - `Produced` (type) — Whether the model has said anything a second attempt would say twice.
300
326
  - `StreamTurnOptions` (type) — What `streamTurn` takes besides the request body.
301
327
  - `streamTurn` — Runs one turn as a stream, reporting tokens as they arrive and assembling them back into a message.
@@ -311,22 +337,40 @@ Telling a model's scratchpad from its answer when both arrive in `content`.
311
337
  - `Fence` (type) — One way a model marks off its scratchpad inside `content`.
312
338
  - `FenceSplitter` — A state machine over a stream of `content` that routes fenced text to reasoning.
313
339
  - `FenceSplitterOptions` (type) — What `FenceSplitter` takes besides its fences.
340
+ - `SPLIT_OUTPUT` — What a `Split` is called when it was not.
341
+ - `SPLIT_REASONING` — What a `Split` is called when it was inside a fence.
314
342
  - `Split` (type) — A piece of `content`, said to be one or the other.
315
343
  - `stripThinking` — What is left of a complete reply once every scratchpad is taken out of it.
316
344
  - `THINK_FENCE` — DeepSeek, Qwen3, QwQ and most distills.
317
345
 
318
346
  ### tokens
319
347
 
348
+ - `CHARS_PER_TOKEN` — The characters one token is taken to be, where nothing has measured it.
349
+ - `ContextBreakdown` (type) — What a request is made of, by the part of it a consumer can actually do something about.
350
+ - `ContextBreakdownOptions` (type) — What `contextTokens` takes besides the request.
351
+ - `compact` — A token count as a message shows it: 1234 → "1.2k".
352
+ - `contextChars` — What each part of a request is worth in characters, by the same walk `requestTokens` divides.
353
+ - `contextTokens` — What each part of a request costs the window, in tokens, adding up to the whole.
320
354
  - `estimateTokens` — Rough token count.
355
+ - `messageTokens` — One message's estimated tokens, by the same count `requestTokens` sums for a whole request.
356
+ - `requestChars` — How many characters a request is worth: the walk `requestTokens` divides, without the division.
357
+ - `requestTokens` — What this request will cost the window, in tokens, near enough.
358
+ - `TokenEstimateOptions` (type) — What the two token estimates below take besides what they measure.
359
+ - `toolsChars` — How many characters a tool array is worth, measured once per array.
321
360
 
322
361
  ### tool-calls
323
362
 
324
363
  Reading what a model meant by a tool call when it did not write one cleanly.
325
364
 
365
+ - `ARGUMENTS_MALFORMED` — The `ToolArgumentsError` kind for a call the model wrote wrongly.
366
+ - `ARGUMENTS_TRUNCATED` — The `ToolArgumentsError` kind for a call cut off at the reply ceiling.
326
367
  - `parseToolArguments` — A tool call's arguments as the object the tool is handed.
327
368
  - `recoverToolCalls` — Tool calls a model wrote into its reply as text, taken out of it and made into calls.
328
369
  - `ToolArgumentsError` — Tool arguments that could not be read as an object, with why.
329
370
  - `ToolCall` (type) — A tool call as the loop handles it, recovered or streamed.
371
+ - `ToolCallOutcome` (type) — What one tool call did, in the order the model asked.
372
+ - `ToolCallRequest` (type) — One call the model made, as `dispatch` and `onToolCall` are handed it.
373
+ - `ToolCallResult` (type) — One call's whole answer, as `onToolResult` is handed it.
330
374
 
331
375
  ### tool-loading
332
376
 
@@ -337,10 +381,6 @@ Reading what a model meant by a tool call when it did not write one cleanly.
337
381
  - `expandNames` — Resolves requested names against the catalogue, expanding trailing `*` wildcards.
338
382
  - `holdsDefinitions` — Whether a tool result is a proxied load carrying definitions, which is the only copy of them the model has.
339
383
  - `inCatalog` — Whether the catalogue holds a tool by this name.
340
- - `KEYWORD_DROPOFF` — How far the best unpicked tool must fall below the last picked one for the cut to count clean.
341
- - `KEYWORD_MIN_SCORE` — The least a best match may score and still be acted on without a model.
342
- - `KeywordPreselection` (type) — What `preselectByKeywords` found.
343
- - `KeywordPreselectOptions` (type) — What `preselectByKeywords` takes besides the catalogue and the request.
344
384
  - `LOAD_TOOLS` — On-demand tool loading.
345
385
  - `LOAD_TOOLS_DEFINITION` — One object for the life of the process — the agent loop asks for it on every iteration.
346
386
  - `loadedTools` — A tool array with newly loaded definitions appended, in the order they were loaded.
@@ -348,17 +388,21 @@ Reading what a model meant by a tool call when it did not write one cleanly.
348
388
  - `MAX_CARRIED` — The most a conversation carries between turns.
349
389
  - `MAX_PER_LOAD` — The most a single `load_tools` call may pull in.
350
390
  - `orderTools` — The tool array in a stable order, so the same set of tools renders the same way twice.
351
- - `PRESELECT_SCHEMA` — The shape a preselector's answer is held to where the server takes a schema: `{ tools: [...] }`.
352
- - `PRESELECT_SYSTEM` — The preselection system prompt at the default cap, for a caller that never changes it.
353
391
  - `PROXY_TOOLS` — The whole tool array of a proxied run, `load_tools` then `call_tool`, frozen because it is shared.
354
- - `preselectByKeywords` — The tools a request's own words point at, ranked, and whether they point clearly enough.
355
- - `preselectInput` — The user message for a preselection call: the catalogue, then the request.
356
- - `preselection` — Resolves a preselection against the catalogue: unknown names dropped, count capped.
357
- - `preselectSystem` — The system prompt a preselector is given, holding it to the cap its answer will be held to.
358
392
  - `proxiedCall` — The tool a `call_tool` names and the arguments to run it with, or a throw the model can read.
359
393
  - `proxyCatalogPrompt` — The catalogue block for a proxied run's system prompt, worded for `call_tool` rather than for a tool list.
360
394
  - `proxyLoadResult` — What a proxied `load_tools` answers: each new tool's whole definition as a line of JSON, since the result is the only place the model will ever see it.
361
395
  - `requestedNames` — `load_tools` arguments, defensively — a model may send a bare string or a nested object.
362
396
  - `shownCall` — A tool call as a watcher should see it: a `call_tool` as the tool it ran, anything else as it is.
363
- - `ToolMatch` (type) — One tool's score against a request.
364
397
  - `ToolOrder` (type) — How a tool array is ordered before it is sent: `true` by name, `false` as the caller built it, or a comparator over the two names.
398
+
399
+ ### wire
400
+
401
+ The words the chat-completions wire is written in, each under a name.
402
+
403
+ - `FinishReason` — Any one of the reasons in `FinishReason`.
404
+ - `FUNCTION_TOOL` — The one `type` a tool definition or a tool call has on this wire.
405
+ - `JSON_SCHEMA_FORMAT` — The `response_format` type that carries a schema the reply has to fit.
406
+ - `PartType` — Any one of the part types in `PartType`.
407
+ - `Role` — Any one of the roles in `Role`.
408
+ - `SchemaType` — Any one of the types in `SchemaType`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubicecho/agent-core",
3
- "version": "2.23.0",
3
+ "version": "2.25.0",
4
4
  "description": "The endpoint-agnostic half of an OpenAI-compatible agent loop: tool-schema compatibility, on-demand tool loading, one-shot side tasks, run events, and a pooled client.",
5
5
  "keywords": [
6
6
  "openai",
@@ -47,13 +47,13 @@
47
47
  "scripts": {
48
48
  "build": "tsc -p tsconfig.build.json && node scripts/llms-txt.mjs",
49
49
  "prepare": "npm run build",
50
- "typecheck": "tsc -p tsconfig.tests.json",
50
+ "check": "npm run check:biome && npm run check:types",
51
+ "check:biome": "biome check --write .",
52
+ "check:types": "tsc -p tsconfig.tests.json",
51
53
  "test": "vitest run",
52
54
  "test:watch": "vitest",
53
55
  "llms": "node scripts/llms-txt.mjs",
54
56
  "llms:check": "node scripts/llms-txt.mjs --check",
55
- "lint": "biome check .",
56
- "format": "biome check --write .",
57
57
  "bench": "vitest bench --run",
58
58
  "coverage": "vitest run --coverage"
59
59
  },