@cubicecho/agent-core 2.24.0 → 2.25.1

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 +49 -4
  23. package/dist/guards.js +60 -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 +15 -0
  33. package/dist/platform.js +15 -0
  34. package/dist/preselect.d.ts +223 -0
  35. package/dist/preselect.js +291 -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 +44 -138
  41. package/dist/retry.js +83 -281
  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 +346 -176
  50. package/dist/scope.d.ts +28 -5
  51. package/dist/scope.js +37 -10
  52. package/dist/side-task.d.ts +124 -40
  53. package/dist/side-task.js +186 -66
  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 +90 -17
  65. package/dist/tool-calls.js +207 -84
  66. package/dist/tool-loading.d.ts +101 -189
  67. package/dist/tool-loading.js +257 -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
@@ -1,7 +1,7 @@
1
- import type OpenAI from "openai";
2
- import type { Endpoint } from "./config.ts";
3
- import { type HookContext, type HookNote, type HookRunner } from "./hooks.ts";
4
- import { type SideTaskOptions } from "./side-task.ts";
1
+ import type OpenAI from 'openai';
2
+ import type { Endpoint } from './config.ts';
3
+ import { type HookContext, type HookRunner, type OnNote } from './hooks.ts';
4
+ import { type SideTaskOptions } from './side-task.ts';
5
5
  /**
6
6
  * Keeping a long run inside its window: stale tool results cleared, and the oldest stretch folded
7
7
  * into a summary the model writes itself.
@@ -20,6 +20,7 @@ export declare const KEEP_RATIO = 0.35;
20
20
  /**
21
21
  * The summariser's instruction when the caller gives none.
22
22
  *
23
+ * @remarks
23
24
  * Asks for notes rather than a retelling, because what the summary replaces is the model's only
24
25
  * record of what was decided, and a narrative spends its words on the order things happened in.
25
26
  */
@@ -30,14 +31,28 @@ export declare const SUMMARY_PROMPT: string;
30
31
  export declare const SUMMARY_LEAD = "Summary of the earlier part of this conversation, which is no longer shown in full:\n\n";
31
32
  /** What `pruneToolResults` takes. */
32
33
  export interface PruneOptions {
33
- /** How many of the latest tool results are left whole, 5 by default. */
34
+ /**
35
+ * How many of the latest tool results are left whole.
36
+ *
37
+ * @defaultValue `5`
38
+ */
34
39
  keepLast?: number;
35
- /** A result this long or shorter is left whole wherever it is, 256 characters by default. */
40
+ /**
41
+ * A result this long or shorter, in characters, is left whole wherever it is.
42
+ *
43
+ * @defaultValue `256`
44
+ */
36
45
  maxChars?: number;
37
46
  }
38
47
  /**
39
48
  * The transcript with every tool result but the latest few replaced by a one-line stub.
40
49
  *
50
+ * @param messages - The transcript. Not written to.
51
+ * @param [options] - How many results to keep and how long one must be to clear.
52
+ * @returns `messages` itself when nothing was cleared, otherwise a new array in which each cleared
53
+ * result is a new message and every other one the same object.
54
+ *
55
+ * @remarks
41
56
  * The cheap half of compaction. A `read_file` of a 40k-character file is 10k tokens on every turn
42
57
  * after it, and by then the model has usually taken what it wanted from it; the stub keeps the
43
58
  * call answered — a call with no result is a malformed transcript — and says how much was there,
@@ -46,9 +61,6 @@ export interface PruneOptions {
46
61
  * only copy of them the model has (`holdsDefinitions`); either still counts as one of the latest
47
62
  * few. Returns the same array when there was nothing to clear. Rewrites the prefix;
48
63
  * see the module comment on when to run it.
49
- *
50
- * @param messages The transcript. Not written to.
51
- * @param options How many results to keep and how long one must be to clear.
52
64
  */
53
65
  export declare function pruneToolResults(messages: Message[], { keepLast, maxChars }?: PruneOptions): Message[];
54
66
  /** What `planCompaction` takes. */
@@ -60,9 +72,17 @@ export interface CompactionOptions {
60
72
  * absent is the estimate of the whole transcript.
61
73
  */
62
74
  used?: number;
63
- /** The fraction of `limit` in use before compacting. `COMPACT_AT` by default. */
75
+ /**
76
+ * The fraction of `limit` in use before compacting.
77
+ *
78
+ * @defaultValue `COMPACT_AT`
79
+ */
64
80
  compactAt?: number;
65
- /** The fraction of `limit` the kept tail may fill. `KEEP_RATIO` by default. */
81
+ /**
82
+ * The fraction of `limit` the kept tail may fill.
83
+ *
84
+ * @defaultValue `KEEP_RATIO`
85
+ */
66
86
  keepRatio?: number;
67
87
  /**
68
88
  * The fraction of `limit` the whole request should come down to, in place of `keepRatio`: the
@@ -72,15 +92,22 @@ export interface CompactionOptions {
72
92
  target?: number;
73
93
  /**
74
94
  * What the summary is assumed to cost when planning to a `target` — the ceiling its writer is
75
- * held to, since the plan is made before it is written. 1024 by default, which is `summariser`'s.
95
+ * held to, since the plan is made before it is written.
96
+ *
97
+ * @defaultValue `1024`, which is `summariser`'s ceiling
76
98
  */
77
99
  summaryTokens?: number;
78
- /** One message's tokens. `messageTokens` by default, divided by `charsPerToken`. */
100
+ /**
101
+ * One message's tokens.
102
+ *
103
+ * @defaultValue `messageTokens` divided by `charsPerToken`
104
+ */
79
105
  estimate?: (message: Message) => number;
80
106
  /**
81
107
  * The divisor the default `estimate` uses — `charsPerTokenFor` the model, for a transcript
82
- * weighed the way `runTurn` sizes its requests. `CHARS_PER_TOKEN` when absent; ignored beside
83
- * an `estimate` of the caller's own.
108
+ * weighed the way `runTurn` sizes its requests. Ignored beside an `estimate` of the caller's own.
109
+ *
110
+ * @defaultValue `CHARS_PER_TOKEN`
84
111
  */
85
112
  charsPerToken?: number;
86
113
  /**
@@ -114,6 +141,13 @@ export interface CompactionPlan {
114
141
  /**
115
142
  * Where to fold a transcript that has grown into its window, or `undefined` when it should not be.
116
143
  *
144
+ * @param messages - The transcript, system prompts included if the caller keeps them in it.
145
+ * @param options - The window, what is in use, the ratios, and where the last fold ended. See
146
+ * `CompactionOptions`.
147
+ * @returns The plan, its `toSummarise` a new array of the same message objects, or `undefined` when
148
+ * there is nothing to fold. `messages` is not written to.
149
+ *
150
+ * @remarks
117
151
  * The kept tail is walked back from the end until it fills `keepRatio` of the window, then moved
118
152
  * forward onto a user message: a transcript resuming mid-exchange — a tool result with no call
119
153
  * before it, a reply with no question — is malformed and servers refuse it. The system prompts at
@@ -134,26 +168,26 @@ export interface CompactionPlan {
134
168
  * comes, and `after` says how far short it fell. An earlier summary the new one replaces is not
135
169
  * credited, so `after` errs high by at most that much. It is only as good as `estimate` — see
136
170
  * `estimateFrom` for one that is measured.
137
- *
138
- * @param messages The transcript, system prompts included if the caller keeps them in it.
139
- * @param options The window, what is in use, the ratios, and where the last fold ended. See
140
- * `CompactionOptions`.
141
171
  */
142
172
  export declare function planCompaction(messages: Message[], { limit, used, compactAt, keepRatio, target, summaryTokens, charsPerToken, estimate, from: givenFrom, previous: givenPrevious, }: CompactionOptions): CompactionPlan | undefined;
143
173
  /**
144
174
  * What the summariser is handed for a plan: the earlier summary if there was one, then each
145
175
  * message as its role and at most 4000 characters of its text.
146
176
  *
147
- * @param plan What `planCompaction` returned.
177
+ * @param plan - What `planCompaction` returned.
178
+ * @returns The text for the summariser, messages a blank line apart. A message with neither text
179
+ * nor calls is left out, and a plan with a `previous` opens with it under `Notes so far:`.
148
180
  */
149
181
  export declare function summaryInput(plan: CompactionPlan): string;
150
182
  /**
151
183
  * A summariser that asks `model` with `SUMMARY_PROMPT`, for `compactTranscript`.
152
184
  *
153
- * @param config The endpoint the summary is written through.
154
- * @param model The model to write it, which may be a smaller one than the run's.
155
- * @param options Cancellation and notices; the ceiling is 1024 and the instruction
156
- * `SUMMARY_PROMPT` unless given.
185
+ * @param config - The endpoint the summary is written through.
186
+ * @param model - The model to write it, which may be a smaller one than the run's.
187
+ * @param [options] - Cancellation and notices, and the instruction and ceiling the summary is
188
+ * written under.
189
+ * @returns A function from `summaryInput`'s text to the summary. It rejects as `ask` does, and
190
+ * resolves with an empty string where the model wrote nothing.
157
191
  */
158
192
  export declare const summariser: (config: Endpoint, model: string, { system, maxTokens, ...options }?: SideTaskOptions & {
159
193
  system?: string;
@@ -161,6 +195,7 @@ export declare const summariser: (config: Endpoint, model: string, { system, max
161
195
  /**
162
196
  * One fold, as a host that keeps its transcript append-only stores it.
163
197
  *
198
+ * @remarks
164
199
  * The other half of `compactTranscript`: the same work, recorded rather than applied. A host that
165
200
  * persists this beside an untouched transcript still shows the user every message, can undo a fold
166
201
  * by dropping one row, and rebuilds the request with `applyCompaction` — where a host that keeps
@@ -179,12 +214,12 @@ export interface CompactionRunOptions {
179
214
  /**
180
215
  * Hooks to tell. `context` is extended with `compacting` and `range`, whose indexes are the
181
216
  * plan's — and so the host's own, for a plan made over a stored transcript. `honourVeto` waits
182
- * for the hooks and lets one stop the compaction; off by default, which adds no latency.
217
+ * for the hooks and lets one stop the compaction; without it they add no latency.
183
218
  */
184
219
  hooks?: {
185
220
  run: HookRunner;
186
221
  context: HookContext;
187
- onNote?: (note: HookNote) => void;
222
+ onNote?: OnNote;
188
223
  honourVeto?: boolean;
189
224
  };
190
225
  /**
@@ -196,58 +231,75 @@ export interface CompactionRunOptions {
196
231
  /**
197
232
  * The hooks and the summariser for a plan, as a record to store rather than a transcript to send.
198
233
  *
199
- * What `compactTranscript` does before it rewrites anything, which is all a host needs when the
200
- * fold lives on the session row and the messages stay where they are. Nothing here is persisted or
201
- * logged — that is the host's, and so is deciding what to do with a fold that did not happen.
202
- *
203
- * @param messages The transcript the plan was made for. Read only, and only for the hooks.
204
- * @param plan What `planCompaction` returned for it.
205
- * @param summarise Writes the summary from `summaryInput`'s text. See `summariser`. Not called
234
+ * @param messages - The transcript the plan was made for. Read only, and only for the hooks.
235
+ * @param plan - What `planCompaction` returned for it.
236
+ * @param summarise - Writes the summary from `summaryInput`'s text. See `summariser`. Not called
206
237
  * when a hook vetoes.
207
- * @param options Hooks to tell and whether the window is already past. See `CompactionRunOptions`.
238
+ * @param [options] - Hooks to tell and whether the window is already past. See `CompactionRunOptions`.
208
239
  * @returns `undefined` when nothing was folded — a hook vetoed, or the summary came back empty —
209
240
  * so the caller stores nothing and the transcript is still whole.
241
+ *
242
+ * @remarks
243
+ * What `compactTranscript` does before it rewrites anything, which is all a host needs when the
244
+ * fold lives on the session row and the messages stay where they are. Nothing here is persisted or
245
+ * logged — that is the host's, and so is deciding what to do with a fold that did not happen.
210
246
  */
211
247
  export declare function runCompaction(messages: Message[], plan: CompactionPlan, summarise: (text: string) => Promise<string>, { hooks, forced }?: CompactionRunOptions): Promise<CompactionRecord | undefined>;
212
248
  /**
213
249
  * The transcript as the server should see it: the folded head replaced by its summary.
214
250
  *
215
- * The inverse of storing a `CompactionRecord`, and the shape `planCompaction` expects to meet
216
- * again — the same `SUMMARY_LEAD`, in a `system` message at the same place — so the next fold
217
- * continues these notes rather than summarising them a second time. Any earlier summary message in
218
- * the kept head is dropped, since the record's already contains it.
219
- *
220
- * @param messages The stored transcript, whole. Not written to.
221
- * @param record The fold, or `undefined` for a session that has not been compacted, which hands
251
+ * @param messages - The stored transcript, whole. Not written to.
252
+ * @param [record] - The fold, or `undefined` for a session that has not been compacted, which hands
222
253
  * back `messages` itself.
223
- * @param options `from` is the first message the fold was allowed to take — the plan's, for a host
254
+ * @param [options] - `from` is the first message the fold was allowed to take — the plan's, for a host
224
255
  * that keeps its system prompts in the array; everything before it is kept ahead of the summary.
225
256
  * Absent, the leading `system` messages are found by scanning, and zero of them is the ordinary
226
257
  * case for a host whose system prompt is a separate argument.
258
+ * @returns `messages` itself when there is no record or its summary is blank, otherwise a new
259
+ * array: the kept head, one summary message, then everything from the record's `through` on.
260
+ *
261
+ * @remarks
262
+ * The inverse of storing a `CompactionRecord`, and the shape `planCompaction` expects to meet
263
+ * again — the same `SUMMARY_LEAD`, in a `system` message at the same place — so the next fold
264
+ * continues these notes rather than summarising them a second time. Any earlier summary message in
265
+ * the kept head is dropped, since the record's already contains it.
227
266
  */
228
- export declare function applyCompaction(messages: Message[], record?: Pick<CompactionRecord, "summary" | "through">, { from }?: {
267
+ export declare function applyCompaction(messages: Message[], record?: Pick<CompactionRecord, 'summary' | 'through'>, { from }?: {
229
268
  from?: number;
230
269
  }): Message[];
231
270
  /**
232
271
  * Where a stored index sits in the request `applyCompaction` builds, once a fold has shifted
233
272
  * everything after it.
234
273
  *
274
+ * @param index - The position in the stored transcript.
275
+ * @param [record] - The fold in force, or `undefined` for a session that has none, which hands the
276
+ * index straight back.
277
+ * @param [head] - How many messages the request keeps ahead of the summary — the leading system
278
+ * prompts, when the host keeps them in the array. Zero is the stored-fold case,
279
+ * where the summary is the request's first message.
280
+ * @returns The index in the request. One before the record's `through` gives `head`, where the
281
+ * summary sits — an index among the kept head messages themselves included.
282
+ *
283
+ * @remarks
235
284
  * A transcript that stays append-only and a request that does not are two numberings of the same
236
285
  * conversation, and anything that names a position — `withContext`'s index, a range handed to a
237
286
  * hook — has to say which it is in. An index inside the folded stretch answers with the summary
238
287
  * message that now stands for it.
239
- *
240
- * @param index The position in the stored transcript.
241
- * @param record The fold in force, or `undefined` for a session that has none, which hands the
242
- * index straight back.
243
- * @param head How many messages the request keeps ahead of the summary — the leading system
244
- * prompts, when the host keeps them in the array. Zero, the default, is the stored-fold case,
245
- * where the summary is the request's first message.
246
288
  */
247
- export declare const requestIndex: (index: number, record?: Pick<CompactionRecord, "through">, head?: number) => number;
289
+ export declare const requestIndex: (index: number, record?: Pick<CompactionRecord, 'through'>, head?: number) => number;
248
290
  /**
249
291
  * The transcript with the plan's stretch replaced by one system message holding its summary.
250
292
  *
293
+ * @param messages - The transcript the plan was made for. Not written to.
294
+ * @param plan - What `planCompaction` returned for it.
295
+ * @param summarise - Writes the summary from `summaryInput`'s text. See `summariser`. Not called
296
+ * when a hook vetoes.
297
+ * @param [options] - Hooks to tell and whether the window is already past. See
298
+ * `CompactionRunOptions`.
299
+ * @returns `messages` itself when nothing was folded — a veto or an empty summary — otherwise a
300
+ * new array.
301
+ *
302
+ * @remarks
251
303
  * `beforeCompact` is told what is being folded while the summary is written, beside it rather
252
304
  * than ahead of it — a memory server filing it is not a rescue worth making the run wait for, and
253
305
  * `notify` never rejects. A host that wants its hooks able to stop a compaction sets
@@ -261,15 +313,6 @@ export declare const requestIndex: (index: number, record?: Pick<CompactionRecor
261
313
  * `runCompaction` and `applyCompaction` are its two halves, and it is nothing but the two in
262
314
  * order, so a host that stores the fold instead of the array gets the same summary at the same
263
315
  * cut rather than a second implementation that drifts from this one.
264
- *
265
- * @param messages The transcript the plan was made for. Not written to.
266
- * @param plan What `planCompaction` returned for it.
267
- * @param summarise Writes the summary from `summaryInput`'s text. See `summariser`. Not called
268
- * when a hook vetoes.
269
- * @param options Hooks to tell and whether the window is already past. See
270
- * `CompactionRunOptions`.
271
- * @returns `messages` itself when nothing was folded — a veto or an empty summary — otherwise a
272
- * new array.
273
316
  */
274
317
  export declare function compactTranscript(messages: Message[], plan: CompactionPlan, summarise: (text: string) => Promise<string>, options?: CompactionRunOptions): Promise<Message[]>;
275
318
  export {};