@cubicecho/agent-core 2.24.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 +10 -7
  2. package/dist/agent-loop.d.ts +84 -205
  3. package/dist/agent-loop.js +288 -597
  4. package/dist/calibration.d.ts +14 -10
  5. package/dist/calibration.js +30 -23
  6. package/dist/capabilities.d.ts +111 -42
  7. package/dist/capabilities.js +281 -138
  8. package/dist/client.d.ts +104 -35
  9. package/dist/client.js +205 -74
  10. package/dist/compaction.d.ts +103 -60
  11. package/dist/compaction.js +160 -86
  12. package/dist/config.d.ts +48 -12
  13. package/dist/config.js +20 -1
  14. package/dist/continuation.d.ts +24 -16
  15. package/dist/continuation.js +70 -44
  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 +100 -63
  21. package/dist/events.js +250 -120
  22. package/dist/guards.d.ts +35 -4
  23. package/dist/guards.js +38 -5
  24. package/dist/hook-events.d.ts +21 -5
  25. package/dist/hook-events.js +23 -9
  26. package/dist/hooks.d.ts +96 -73
  27. package/dist/hooks.js +202 -116
  28. package/dist/index.d.ts +30 -26
  29. package/dist/index.js +29 -24
  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 +29 -138
  41. package/dist/retry.js +69 -282
  42. package/dist/run-calls.d.ts +123 -0
  43. package/dist/run-calls.js +351 -0
  44. package/dist/run-turn.d.ts +36 -15
  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 +35 -18
  49. package/dist/schema-compat.js +340 -175
  50. package/dist/scope.d.ts +28 -5
  51. package/dist/scope.js +37 -10
  52. package/dist/side-task.d.ts +123 -40
  53. package/dist/side-task.js +181 -63
  54. package/dist/snapshot.d.ts +10 -5
  55. package/dist/snapshot.js +73 -30
  56. package/dist/spec.d.ts +56 -25
  57. package/dist/spec.js +494 -215
  58. package/dist/stream.d.ts +66 -16
  59. package/dist/stream.js +220 -97
  60. package/dist/thinking.d.ts +23 -8
  61. package/dist/thinking.js +92 -44
  62. package/dist/tokens.d.ts +164 -6
  63. package/dist/tokens.js +319 -6
  64. package/dist/tool-calls.d.ts +82 -17
  65. package/dist/tool-calls.js +198 -83
  66. package/dist/tool-loading.d.ts +101 -189
  67. package/dist/tool-loading.js +277 -371
  68. package/dist/wire.d.ts +81 -0
  69. package/dist/wire.js +73 -0
  70. package/llms.txt +76 -39
  71. package/package.json +4 -4
package/dist/events.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { TokenLedger } from "./ledger.ts";
2
- import type { TurnUsage } from "./stream.ts";
1
+ import type { TokenLedger } from './ledger.ts';
2
+ import type { TurnUsage } from './stream.ts';
3
+ import { CacheBreakReason } from './stream.ts';
3
4
  /**
4
5
  * What a run is doing, while it is doing it.
5
6
  *
@@ -18,6 +19,7 @@ export interface EventBusOptions {
18
19
  /**
19
20
  * How far past the cap the backlog is allowed to run before it is trimmed.
20
21
  *
22
+ * @remarks
21
23
  * Dropping the oldest event on every push means shifting a thousand-element array tens of
22
24
  * thousands of times over a reasoning run — the one thing in here that would ever show up in a
23
25
  * profile. Trimming in batches makes it a few dozen splices instead, at the cost of the backlog
@@ -31,6 +33,7 @@ export interface EventBusOptions {
31
33
  /**
32
34
  * The same for a run that has not said `done`, which is a far more dangerous thing to drop.
33
35
  *
36
+ * @remarks
34
37
  * A finished run has nothing more to say, so forgetting it a minute later costs a late watcher
35
38
  * a backlog and nothing else. An unfinished one is still writing: `touched` only moves on
36
39
  * `emit`, so a live run that spends a minute inside one slow tool call looked exactly like an
@@ -50,6 +53,11 @@ export interface EventBusOptions {
50
53
  * Changes what the bus keeps, for a process whose runs are not shaped like the ones these
51
54
  * defaults were chosen for.
52
55
  *
56
+ * @param [options] - The bounds to change. A field left out — or given anything that is not a
57
+ * number above zero — keeps what it has, so a partial or a half-built config narrows nothing.
58
+ * @returns Everything in force afterwards, including what this call did not change.
59
+ *
60
+ * @remarks
53
61
  * The bus is one thing per runtime rather than an object a caller holds, so this is too: it is
54
62
  * a deployment's setting, said once at startup, and not something to move around under a run.
55
63
  * Called at the top level that is the process's bus; a runtime made by `createRuntime` has its
@@ -61,38 +69,37 @@ export interface EventBusOptions {
61
69
  * Changes apply from the next event and the next sweep. Nothing already buffered is trimmed to
62
70
  * a cap that has just come down, because the trim happens on push; the backlog settles to the
63
71
  * new number as the run goes on.
64
- *
65
- * @param options The bounds to change. A field left out — or given anything that is not a
66
- * number above zero — keeps what it has, so a partial or a half-built config narrows nothing.
67
- * @returns Everything in force afterwards, including what this call did not change.
68
72
  */
69
73
  export declare function configureEvents(options?: EventBusOptions): Required<EventBusOptions>;
70
74
  /** Which kind of thing happened, and what `text`, `name`, `ok` and `usage` carry for it. */
71
- export type RunEventKind =
72
- /** A step of a caller's own flow began. `name` is the step, `text` its kind. */
73
- "step"
74
- /** A decision step chose an arm. `text` is the arm it took. */
75
- | "decision"
76
- /** A new turn of the agent loop began, inside whichever step is running. */
77
- | "turn"
78
- /** Reasoning tokens, as they arrive. */
79
- | "thinking"
80
- /** Reply tokens, as they arrive. */
81
- | "output"
82
- /** The model asked for a tool, with the arguments it chose. `id` is the call's. */
83
- | "tool-call"
84
- /** A tool came back, with what it said. `id` is the id of the call it answers. */
85
- | "tool-result"
86
- /** Something the runner did that is not the model's doing — a preselection, a retry. */
87
- | "notice"
88
- /**
89
- * What the run has cost so far, at the end of every turn, and what that one turn did. Sent
90
- * whether or not the endpoint reported tokens, since the timings and the cache comparison are
91
- * measured either way.
92
- */
93
- | "usage"
94
- /** The run ended. Always last, and always sent. */
95
- | "done";
75
+ export declare const RunEventKind: {
76
+ /** A step of a caller's own flow began. `name` is the step, `text` its kind. */
77
+ readonly Step: 'step';
78
+ /** A decision step chose an arm. `text` is the arm it took. */
79
+ readonly Decision: 'decision';
80
+ /** A new turn of the agent loop began, inside whichever step is running. */
81
+ readonly Turn: 'turn';
82
+ /** Reasoning tokens, as they arrive. */
83
+ readonly Thinking: 'thinking';
84
+ /** Reply tokens, as they arrive. */
85
+ readonly Output: 'output';
86
+ /** The model asked for a tool, with the arguments it chose. `id` is the call's. */
87
+ readonly ToolCall: 'tool-call';
88
+ /** A tool came back, with what it said. `id` is the id of the call it answers. */
89
+ readonly ToolResult: 'tool-result';
90
+ /** Something the runner did that is not the model's doing — a preselection, a retry. */
91
+ readonly Notice: 'notice';
92
+ /**
93
+ * What the run has cost so far, at the end of every turn, and what that one turn did. Sent
94
+ * whether or not the endpoint reported tokens, since the timings and the cache comparison are
95
+ * measured either way.
96
+ */
97
+ readonly Usage: 'usage';
98
+ /** The run ended. Always last, and always sent. */
99
+ readonly Done: 'done';
100
+ };
101
+ /** Any one of the kinds in `RunEventKind`. */
102
+ export type RunEventKind = (typeof RunEventKind)[keyof typeof RunEventKind];
96
103
  /**
97
104
  * What a run has spent, counted from the start of the run rather than for the turn that
98
105
  * carried it: a client draws the latest one it has seen and needs no arithmetic of its own,
@@ -128,6 +135,7 @@ export interface TurnReport extends TurnUsage {
128
135
  /**
129
136
  * One thing that happened in a run, as a watcher receives it.
130
137
  *
138
+ * @remarks
131
139
  * Every field but `id` is always present — the empty ones are `""` or `null` rather than
132
140
  * missing — so a client reads it without guarding each key.
133
141
  */
@@ -139,6 +147,7 @@ export interface RunEvent {
139
147
  /**
140
148
  * When it happened, as epoch milliseconds.
141
149
  *
150
+ * @remarks
142
151
  * A number rather than a `Date`: these events are read over a wire, where a `Date` is an ISO
143
152
  * string by the time anyone sees it, and `emit` runs once per streamed token — so the object
144
153
  * it does not allocate is one per token. It also spares the `getTime()` the sweep used to do
@@ -170,22 +179,25 @@ export interface RunEvent {
170
179
  /**
171
180
  * What `emit` is given: the run and the sequence are the bus's to assign.
172
181
  *
182
+ * @remarks
173
183
  * Named exclusions rather than a blanket `Partial`, which permitted both and let the spread in
174
184
  * `emit` overwrite them — a caller could file an event under another run and hand every watcher
175
185
  * a duplicate `seq`, which is the one thing the sequence is for.
176
186
  */
177
- export type RunEventInput = Pick<RunEvent, "kind"> & Partial<Omit<RunEvent, "kind" | "runId" | "seq">>;
187
+ export type RunEventInput = Pick<RunEvent, 'kind'> & Partial<Omit<RunEvent, 'kind' | 'runId' | 'seq'>>;
178
188
  /**
179
189
  * A whole event from what a caller said of it: the empty defaults under it, the run and sequence over it.
180
190
  *
191
+ * @param input - What happened. An `at` it carries wins over the one given here.
192
+ * @param runId - The run it belongs to. Written after `input`, which gets no say in it.
193
+ * @param seq - Its place in that run, the same.
194
+ * @param at - When, for an input that does not say.
195
+ * @returns A new event; `input` is not written to.
196
+ *
197
+ * @remarks
181
198
  * The one place the defaults are written, so an event the bus stamps, one the loop keeps for its
182
199
  * own metrics and the notice a slow watcher is sent cannot come to disagree about what an unset
183
200
  * field reads as.
184
- *
185
- * @param input What happened. An `at` it carries wins over the one given here.
186
- * @param runId The run it belongs to. Written after `input`, which gets no say in it.
187
- * @param seq Its place in that run, the same.
188
- * @param at When, for an input that does not say.
189
201
  */
190
202
  export declare const stamp: (input: RunEventInput, runId: string, seq: number, at: number) => RunEvent;
191
203
  /**
@@ -193,45 +205,54 @@ export declare const stamp: (input: RunEventInput, runId: string, seq: number, a
193
205
  * loop threw where it could not be caught. The sweep gets there on its own; this is for a
194
206
  * caller that already knows.
195
207
  *
196
- * @param runId The run to forget. An id nothing was emitted under is ignored.
208
+ * @param runId - The run to forget. An id nothing was emitted under is ignored.
197
209
  */
198
210
  export declare function endRun(runId: string): void;
199
211
  /**
200
212
  * Records one event and hands it to everyone watching that run. Never throws at the caller.
201
213
  *
202
- * @param runId The run this belongs to. Created on first use.
203
- * @param input The event. `kind` is required; `runId` and `seq` are not a caller's to set.
214
+ * @param runId - The run this belongs to. Created on first use.
215
+ * @param input - The event. `kind` is required; `runId` and `seq` are not a caller's to set.
216
+ * @returns The event as it was recorded: its `seq` in the run, its time, and every unset field
217
+ * filled in.
204
218
  */
205
219
  export declare function emit(runId: string, input: RunEventInput): RunEvent;
206
220
  /**
207
221
  * Everything that has happened on a run, then everything that happens next, until it ends.
208
222
  *
209
- * The backlog comes first so a watcher that joins halfway through — or after the run finished,
210
- * inside the retention window — reads the same story as one that was there from the start.
211
- *
212
- * @param runId The run to follow. One that has not started yet is waited on, not refused.
213
- * @param signal Stops following. The only other way out is the run's own `done`, and a watcher
223
+ * @param runId - The run to follow. One that has not started yet is waited on, not refused.
224
+ * @param [signal] - Stops following. The only other way out is the run's own `done`, and a watcher
214
225
  * with no way out is a leak rather than a lost backlog: the sweep below skips any stream a
215
226
  * listener is on, so a run that dies without `done` pins its backlog for the life of the process.
216
227
  * Returning the generator is not that way out — parked on the promise at the foot of this
217
228
  * function it is suspended at an `await` rather than at a `yield`, and a `return()` there is
218
229
  * queued behind a promise only the next event can settle. An abort resolves that promise itself.
230
+ * @returns The run's events in order, ending after its `done` or at the abort. A watcher that fell
231
+ * too far behind is given one notice in place of the events it missed. Nothing is subscribed until
232
+ * the first event is asked for.
233
+ *
234
+ * @remarks
235
+ * The backlog comes first so a watcher that joins halfway through — or after the run finished,
236
+ * inside the retention window — reads the same story as one that was there from the start.
219
237
  */
220
238
  export declare function watch(runId: string, signal?: AbortSignal): AsyncGenerator<RunEvent>;
221
239
  /**
222
240
  * The backlog alone, for a caller that wants a snapshot rather than a subscription.
223
241
  *
242
+ * @param runId - The run to read. An unknown or already-swept run gives an empty array.
243
+ * @returns The events still held, oldest first, in an array of the caller's own.
244
+ *
245
+ * @remarks
224
246
  * The array is a copy; the events in it are not. They are the same objects the bus holds and
225
247
  * every watcher was handed, so writing to one rewrites the run for everybody — which is what
226
248
  * `fold` copies to avoid, and this is the other half of the same warning. Read them, or copy
227
249
  * what you mean to change.
228
- *
229
- * @param runId The run to read. An unknown or already-swept run gives an empty array.
230
250
  */
231
251
  export declare const history: (runId: string) => RunEvent[];
232
252
  /**
233
253
  * Test seam: forget every run, so one test's events cannot be read by the next.
234
254
  *
255
+ * @remarks
235
256
  * Named for what it forgets rather than bare `reset`, which sat in a consumer's imports beside
236
257
  * `resetAll`, `resetClients`, `resetCapabilities` and `resetHints` saying nothing about which
237
258
  * of the five it was — `reset.ts` had to alias it on the way in to stay readable.
@@ -243,21 +264,25 @@ export declare const history: (runId: string) => RunEvent[];
243
264
  */
244
265
  export declare const resetEvents: () => void;
245
266
  /**
246
- * Consecutive tokens of one kind are one thing being said, not hundreds of things.
267
+ * A run's events with each stretch of `thinking` or of `output` joined into one block, for a
268
+ * reader that takes a run in snapshots.
269
+ *
270
+ * @param events - Events in `seq` order, from `history` or collected from `watch`. Not written to.
271
+ * @returns One event per block, every one a copy. A run of `thinking` or of `output` within one
272
+ * step is a single block with the texts joined; anything else is a block to itself.
247
273
  *
248
- * A client that reads a run in snapshots rather than token by token wants it that way: a
274
+ * @remarks
275
+ * Consecutive tokens of one kind are one thing being said, not hundreds of things. A client that
276
+ * reads a run in snapshots rather than token by token wants it that way: a
249
277
  * reasoning model spends ten thousand deltas on a paragraph, and a paragraph is what it meant.
250
278
  * Each block carries the `seq` of its last event, so asking for what came after one block
251
279
  * picks up exactly where it left off.
252
- *
253
- * @param events Events in `seq` order, from `history` or collected from `watch`.
254
280
  */
255
281
  export declare function fold(events: RunEvent[]): RunEvent[];
256
- /** Why a turn's cache broke, as `TurnUsage.cacheBreakReason` names it. */
257
- type CacheBreakReason = NonNullable<TurnUsage["cacheBreakReason"]>;
258
282
  /**
259
283
  * A run summed and derived from its events: what it cost, where the time went, and why.
260
284
  *
285
+ * @remarks
261
286
  * The counts are always there, zero when nothing happened. Every other field is absent where no
262
287
  * turn reported what it is made of, and summed over the turns that did where only some did —
263
288
  * a mean of a number a server never sent would be a number nobody measured.
@@ -321,13 +346,23 @@ export interface RunMetrics {
321
346
  largestPrompt?: number;
322
347
  /** `largestPrompt` over the window `runMetrics` was told, for how close the run came. */
323
348
  largestPromptShare?: number;
349
+ /** How it ended, read off `done` and the last turn. */
350
+ outcome?: RunOutcome;
351
+ }
352
+ /** How a run ended, as `runMetrics` reads it. */
353
+ export declare const RunOutcome: {
354
+ /** The run did not fail, and its last turn was not cut off. */
355
+ readonly Answered: 'answered';
356
+ /** The run did not fail, and its last turn is an answer the reply ceiling cut off. */
357
+ readonly Truncated: 'truncated';
324
358
  /**
325
- * How it ended, read off `done` and the last turn: `truncated` is an answer the ceiling cut off.
326
- * A failure does not say whether it was an error, a stop or the tool budget — that is in the
327
- * host's own `done` text.
359
+ * `done` said the run was not ok. Whether that was an error, a stop or the tool budget is in
360
+ * the host's own `done` text and not here.
328
361
  */
329
- outcome?: "answered" | "truncated" | "failed";
330
- }
362
+ readonly Failed: 'failed';
363
+ };
364
+ /** Any one of the outcomes in `RunOutcome`. */
365
+ export type RunOutcome = (typeof RunOutcome)[keyof typeof RunOutcome];
331
366
  /** What `runMetrics` takes besides the events. */
332
367
  export interface RunMetricsOptions {
333
368
  /** The window the run was served, for `largestPromptShare`. Absent or zero leaves it out. */
@@ -336,15 +371,17 @@ export interface RunMetricsOptions {
336
371
  /**
337
372
  * A run's totals, timings and cache findings, derived from the events it emitted.
338
373
  *
374
+ * @param events - A run's events in `seq` order, from `history` or collected from `watch`. A backlog
375
+ * that has lost its oldest events to the cap sums what it still has.
376
+ * @param [options] - The served window, for how full the run came to it.
377
+ * @returns A summary of the caller's own. The counts are zero for an empty list, and `outcome` is
378
+ * absent for a run that has not reported `done`.
379
+ *
380
+ * @remarks
339
381
  * A sibling of `fold` rather than part of it. `fold` hands back events, and a client renders
340
382
  * what it returns as blocks; a summary is another shape, and folding one in would give every
341
383
  * consumer of `fold` a block it does not know how to draw. Derived from the `usage` reports' own
342
384
  * `turn` rather than the running totals, so a run with several loops in it — a question per loop —
343
385
  * adds up the same as one with a single loop.
344
- *
345
- * @param events A run's events in `seq` order, from `history` or collected from `watch`. A backlog
346
- * that has lost its oldest events to the cap sums what it still has.
347
- * @param options The served window, for how full the run came to it.
348
386
  */
349
387
  export declare function runMetrics(events: RunEvent[], { contextLength }?: RunMetricsOptions): RunMetrics;
350
- export {};