@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
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The checks a value read off the wire is put through before anything is read from it.
3
+ *
4
+ * A leaf with no imports, because the modules that need these — a browser-safe `spec`, the schema
5
+ * walk, the tool-call reader, the snapshot importer — otherwise share nothing, and each had grown
6
+ * its own copy. `getOrCreate` and `counted` are here for the same reason and are the two things that
7
+ * are not checks: every cache in the package fills itself on a miss, and each had written that
8
+ * out, and a notice that counts something is written in more than one module.
9
+ */
10
+ /**
11
+ * Whether a value is a plain keyed object: not null, and not an array.
12
+ *
13
+ * @param value - Anything, usually just parsed. An array is an object to `typeof` and not to this.
14
+ * @returns True for anything else `typeof` calls an object — a `Date`, a `Map` and a class
15
+ * instance included, since the prototype is not looked at.
16
+ */
17
+ export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
18
+ /**
19
+ * Whether a value is a number above zero, which is what a limit has to be to be one.
20
+ *
21
+ * @param value - Anything, usually a setting that may be absent, zero or mistyped.
22
+ * @returns True only for a `number` greater than zero: a numeric string or a `bigint` is not one.
23
+ *
24
+ * @remarks
25
+ * `Infinity` passes and `NaN` does not, so a caller lifting a bound and one handing over a
26
+ * half-built config are told apart without either being asked.
27
+ */
28
+ export declare const isPositive: (value: unknown) => value is number;
29
+ /** What `getOrCreate` needs of a map, so a `WeakMap` serves as well as a `Map`. */
30
+ interface Lookup<K, V> {
31
+ get(key: K): V | undefined;
32
+ set(key: K, value: V): unknown;
33
+ }
34
+ /**
35
+ * What a map holds under a key, made and stored first where it holds nothing.
36
+ *
37
+ * @param map - Where to look. Gains an entry on a miss, which is the point of calling this.
38
+ * @param key - What to look under.
39
+ * @param create - Builds the value on a miss, and is not called on a hit. A stored `undefined`
40
+ * reads as a miss, so one that returns it is called every time.
41
+ * @returns What the map holds under the key afterwards: the held value itself on a hit, what
42
+ * `create` returned on a miss.
43
+ */
44
+ export declare function getOrCreate<K, V>(map: Lookup<K, V>, key: K, create: () => V): V;
45
+ /**
46
+ * A count and its noun, plural unless the count is one: `1 tool`, `3 tools`.
47
+ *
48
+ * @param count - How many.
49
+ * @param noun - The singular, which takes an `s` and nothing cleverer.
50
+ * @returns The phrase. Only a count of exactly one is singular: zero reads `0 tools`.
51
+ */
52
+ export declare const counted: (count: number, noun: string) => string;
53
+ export {};
package/dist/guards.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The checks a value read off the wire is put through before anything is read from it.
3
+ *
4
+ * A leaf with no imports, because the modules that need these — a browser-safe `spec`, the schema
5
+ * walk, the tool-call reader, the snapshot importer — otherwise share nothing, and each had grown
6
+ * its own copy. `getOrCreate` and `counted` are here for the same reason and are the two things that
7
+ * are not checks: every cache in the package fills itself on a miss, and each had written that
8
+ * out, and a notice that counts something is written in more than one module.
9
+ */
10
+ /**
11
+ * Whether a value is a plain keyed object: not null, and not an array.
12
+ *
13
+ * @param value - Anything, usually just parsed. An array is an object to `typeof` and not to this.
14
+ * @returns True for anything else `typeof` calls an object — a `Date`, a `Map` and a class
15
+ * instance included, since the prototype is not looked at.
16
+ */
17
+ export const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
18
+ /**
19
+ * Whether a value is a number above zero, which is what a limit has to be to be one.
20
+ *
21
+ * @param value - Anything, usually a setting that may be absent, zero or mistyped.
22
+ * @returns True only for a `number` greater than zero: a numeric string or a `bigint` is not one.
23
+ *
24
+ * @remarks
25
+ * `Infinity` passes and `NaN` does not, so a caller lifting a bound and one handing over a
26
+ * half-built config are told apart without either being asked.
27
+ */
28
+ export const isPositive = (value) => typeof value === 'number' && value > 0;
29
+ /**
30
+ * What a map holds under a key, made and stored first where it holds nothing.
31
+ *
32
+ * @param map - Where to look. Gains an entry on a miss, which is the point of calling this.
33
+ * @param key - What to look under.
34
+ * @param create - Builds the value on a miss, and is not called on a hit. A stored `undefined`
35
+ * reads as a miss, so one that returns it is called every time.
36
+ * @returns What the map holds under the key afterwards: the held value itself on a hit, what
37
+ * `create` returned on a miss.
38
+ */
39
+ export function getOrCreate(map, key, create) {
40
+ const held = map.get(key);
41
+ if (held !== undefined) {
42
+ return held;
43
+ }
44
+ const made = create();
45
+ map.set(key, made);
46
+ return made;
47
+ }
48
+ /**
49
+ * A count and its noun, plural unless the count is one: `1 tool`, `3 tools`.
50
+ *
51
+ * @param count - How many.
52
+ * @param noun - The singular, which takes an `s` and nothing cleverer.
53
+ * @returns The phrase. Only a count of exactly one is singular: zero reads `0 tools`.
54
+ */
55
+ export const counted = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The points in a session a hook can be bound to, apart from everything that runs one.
3
+ *
4
+ * A leaf with no imports, because two modules need these lists and only one of them may load
5
+ * `node:crypto`: `hooks.ts` hashes a turn into the uuid a memory server dedups on, and `spec.ts`
6
+ * has to stay importable in a browser. Before this each kept its own copy, with a test holding
7
+ * one pair together and nothing holding the other.
8
+ */
9
+ /**
10
+ * The points in a session a hook can be bound to, in the order a session meets them.
11
+ *
12
+ * @remarks
13
+ * Named after Claude Code's hooks of the same shape, which each member names, plus
14
+ * `sessionDelete`, which has no counterpart there.
15
+ */
16
+ export declare const HookEvent: {
17
+ /** A session opened. Claude Code's SessionStart. */
18
+ readonly SessionStart: 'sessionStart';
19
+ /** A turn is about to be requested. Claude Code's UserPromptSubmit. */
20
+ readonly BeforeTurn: 'beforeTurn';
21
+ /** A turn was answered. Claude Code's Stop. */
22
+ readonly AfterTurn: 'afterTurn';
23
+ /** Part of the transcript is about to be summarised away. Claude Code's PreCompact. */
24
+ readonly BeforeCompact: 'beforeCompact';
25
+ /** A session closed. Claude Code's SessionEnd. */
26
+ readonly SessionEnd: 'sessionEnd';
27
+ /** The host deleted a session's record. */
28
+ readonly SessionDelete: 'sessionDelete';
29
+ };
30
+ /** Any one of the events in `HookEvent`. */
31
+ export type HookEvent = (typeof HookEvent)[keyof typeof HookEvent];
32
+ /** Every event a hook can be bound to, in the order a session meets them. */
33
+ export declare const HOOK_EVENTS: readonly HookEvent[];
34
+ /**
35
+ * The events whose hooks run before a request, and so the only ones whose output can reach it.
36
+ * Anything later runs once the model has already answered.
37
+ */
38
+ export declare const INJECT_EVENTS: ReadonlySet<HookEvent>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The points in a session a hook can be bound to, apart from everything that runs one.
3
+ *
4
+ * A leaf with no imports, because two modules need these lists and only one of them may load
5
+ * `node:crypto`: `hooks.ts` hashes a turn into the uuid a memory server dedups on, and `spec.ts`
6
+ * has to stay importable in a browser. Before this each kept its own copy, with a test holding
7
+ * one pair together and nothing holding the other.
8
+ */
9
+ /**
10
+ * The points in a session a hook can be bound to, in the order a session meets them.
11
+ *
12
+ * @remarks
13
+ * Named after Claude Code's hooks of the same shape, which each member names, plus
14
+ * `sessionDelete`, which has no counterpart there.
15
+ */
16
+ export const HookEvent = {
17
+ /** A session opened. Claude Code's SessionStart. */
18
+ SessionStart: 'sessionStart',
19
+ /** A turn is about to be requested. Claude Code's UserPromptSubmit. */
20
+ BeforeTurn: 'beforeTurn',
21
+ /** A turn was answered. Claude Code's Stop. */
22
+ AfterTurn: 'afterTurn',
23
+ /** Part of the transcript is about to be summarised away. Claude Code's PreCompact. */
24
+ BeforeCompact: 'beforeCompact',
25
+ /** A session closed. Claude Code's SessionEnd. */
26
+ SessionEnd: 'sessionEnd',
27
+ /** The host deleted a session's record. */
28
+ SessionDelete: 'sessionDelete',
29
+ };
30
+ /** Every event a hook can be bound to, in the order a session meets them. */
31
+ export const HOOK_EVENTS = Object.values(HookEvent);
32
+ /**
33
+ * The events whose hooks run before a request, and so the only ones whose output can reach it.
34
+ * Anything later runs once the model has already answered.
35
+ */
36
+ export const INJECT_EVENTS = new Set([HookEvent.SessionStart, HookEvent.BeforeTurn]);
package/dist/hooks.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type OpenAI from "openai";
1
+ import type OpenAI from 'openai';
2
+ import { type HookEvent } from './hook-events.ts';
2
3
  /**
3
4
  * Lifecycle hooks, from the host's side: what a session looks like to them, where their context
4
5
  * lands in a request, and what is said about each one.
@@ -9,20 +10,6 @@ import type OpenAI from "openai";
9
10
  * `runHooks` is a runner as it stands and its outcomes pass straight through, without this
10
11
  * package depending on it.
11
12
  */
12
- /**
13
- * A point in a session a hook can be bound to. Named after Claude Code's hooks of the same shape
14
- * — `sessionStart` (SessionStart), `beforeTurn` (UserPromptSubmit), `afterTurn` (Stop),
15
- * `beforeCompact` (PreCompact), `sessionEnd` (SessionEnd) — plus `sessionDelete`, for when the host
16
- * deletes a session's record.
17
- */
18
- export type HookEvent = "sessionStart" | "beforeTurn" | "afterTurn" | "beforeCompact" | "sessionEnd" | "sessionDelete";
19
- /** Every event a hook can be bound to, in the order a session meets them. */
20
- export declare const HOOK_EVENTS: readonly HookEvent[];
21
- /**
22
- * The events whose hooks run before a request, and so the only ones whose output can reach it.
23
- * Anything later runs once the model has already answered.
24
- */
25
- export declare const INJECT_EVENTS: ReadonlySet<HookEvent>;
26
13
  /**
27
14
  * One message of a session as a hook is handed it. The shape a memory server's `remember` takes,
28
15
  * so a template can pass a turn straight through.
@@ -63,7 +50,7 @@ export interface HookContext {
63
50
  through: number;
64
51
  };
65
52
  /** How a run ended. */
66
- status?: "ok" | "stopped" | "error";
53
+ status?: 'ok' | 'stopped' | 'error';
67
54
  /** The host's own extras — a card id, a task step. */
68
55
  vars?: Record<string, unknown>;
69
56
  }
@@ -96,6 +83,8 @@ export interface HookOutcome {
96
83
  */
97
84
  veto?: boolean;
98
85
  }
86
+ /** Hears each `HookNote` as it is made, the one signature every function that raises them takes. */
87
+ export type OnNote = (note: HookNote) => void;
99
88
  /**
100
89
  * One hook's line for whoever is watching: the context it added, or why it added none. A hook
101
90
  * that worked and added nothing gets no note — a remember that succeeded is not news.
@@ -118,6 +107,7 @@ export interface HookNote {
118
107
  * Runs one event's hooks. Should resolve rather than reject — a hook failing is an outcome — but
119
108
  * `gather` and `notify` survive one that does not.
120
109
  *
110
+ * @remarks
121
111
  * The pool's `runHooks` fits as it is; wrap it to pass its scope or `onNotice`.
122
112
  */
123
113
  export type HookRunner = (event: HookEvent, context: HookContext, options: {
@@ -132,6 +122,7 @@ export interface Gathered {
132
122
  /**
133
123
  * The most context all of a request's hooks add between them by default, in estimated tokens.
134
124
  *
125
+ * @remarks
135
126
  * Enough for a handful of recalled memories, and small against any window worth running an agent
136
127
  * in. The point is that a generous hook cannot crowd out the conversation it was meant to inform.
137
128
  * `configureHooks` moves it for a process, and `gather` and `assembleContext` for one request.
@@ -160,16 +151,17 @@ export interface HookOptions {
160
151
  * Changes what hooks are held to, for a process whose windows are not the size these defaults
161
152
  * were chosen for, or whose host wants its own name above the context.
162
153
  *
163
- * One setting per runtime for the same reason `configureEvents` is: a budget and a preface are a
164
- * deployment's settings, said once at startup. A caller that sizes the budget per model or per agent — a 128k
165
- * window can afford more recall than an 8k one — passes `maxTokens` to `gather` instead, and a
166
- * `preface` passed to `withContext` or `runAgentLoop`'s hooks wins over this one the same way.
167
- *
168
- * @param options The settings to change. A field left out keeps what it has, and so does one given
154
+ * @param [options] - The settings to change. A field left out keeps what it has, and so does one given
169
155
  * the wrong kind of value — `contextTokens` anything but a number above zero, `preface` anything
170
156
  * but a string — so a half-built config narrows nothing. `Infinity` is a number above zero, and
171
157
  * lifts the shared budget entirely. An empty `preface` is a string, and turns the preface off.
172
158
  * @returns Everything in force afterwards, including what this call did not change.
159
+ *
160
+ * @remarks
161
+ * One setting per runtime for the same reason `configureEvents` is: a budget and a preface are a
162
+ * deployment's settings, said once at startup. A caller that sizes the budget per model or per agent — a 128k
163
+ * window can afford more recall than an 8k one — passes `maxTokens` to `gather` instead, and a
164
+ * `preface` passed to `withContext` or `runAgentLoop`'s hooks wins over this one the same way.
173
165
  */
174
166
  export declare function configureHooks(options?: HookOptions): Required<HookOptions>;
175
167
  /**
@@ -181,6 +173,14 @@ export declare const resetHooks: () => void;
181
173
  /**
182
174
  * Builds the context a set of outcomes adds and the notes that go with it.
183
175
  *
176
+ * @param outcomes - What the runners returned. An injecting outcome on an event that cannot inject
177
+ * adds nothing; a failed one is noted wherever it falls, including past the budget.
178
+ * @param [maxTokens] - The budget every block shares. Absent, or not a number above zero, is what
179
+ * `configureHooks` last set — `HOOK_CONTEXT_TOKENS` unless something moved it.
180
+ * @returns The blocks joined by a blank line — an empty string when nothing was injected — and the
181
+ * notes in the order of `outcomes`.
182
+ *
183
+ * @remarks
184
184
  * Each injected outcome is wrapped in `<context source="…">` naming its label, so a model reading
185
185
  * a recalled line can tell it is a memory rather than something the user said. Each is held to
186
186
  * its own `maxTokens` and the whole to `maxTokens` here, and a block past the total is dropped
@@ -190,16 +190,22 @@ export declare const resetHooks: () => void;
190
190
  *
191
191
  * The note keeps each hook's text as it was cut, so a host can show exactly what the model was
192
192
  * given without re-deriving the caps or parsing the wrapper back off.
193
- *
194
- * @param outcomes What the runners returned. An injecting outcome on an event that cannot inject
195
- * adds nothing; a failed one is noted wherever it falls, including past the budget.
196
- * @param maxTokens The budget every block shares. Absent, or not a number above zero, is what
197
- * `configureHooks` last set — `HOOK_CONTEXT_TOKENS` unless something moved it.
198
193
  */
199
194
  export declare function assembleContext(outcomes: readonly HookOutcome[], maxTokens?: number): Gathered;
200
195
  /**
201
196
  * The request, with the hooks' context added to this turn's question.
202
197
  *
198
+ * @param history - The request's messages. Neither the array nor any message in it is changed.
199
+ * @param index - Where the question sits in `history` — which is not where it sits in the
200
+ * session once a compaction has folded the head into a summary. Anything but a user message there
201
+ * leaves the request as it was.
202
+ * @param context - What `assembleContext` built, this turn or the turn the question was asked.
203
+ * Empty returns `history` itself.
204
+ * @param [preface] - Said above the blocks. Empty says nothing, rather than leaving a blank line
205
+ * where it was.
206
+ * @returns `history` when there was nothing to add or nowhere to add it, otherwise a new array.
207
+ *
208
+ * @remarks
203
209
  * It goes on the question and not in the system prompt, because it is about the question — and a
204
210
  * system prompt that changed every turn would miss the prompt cache every turn. Nothing is written
205
211
  * back: a host that stores what the user typed never remembers the context as something they said.
@@ -208,21 +214,12 @@ export declare function assembleContext(outcomes: readonly HookOutcome[], maxTok
208
214
  * it was said under, beside the question and calls this for each stored one on every later request
209
215
  * — a question sent with its blocks one turn and bare the next is a different prompt from that
210
216
  * message on, and loses the server's prefix cache behind it.
211
- *
212
- * @param history The request's messages. Neither the array nor any message in it is changed.
213
- * @param index Where the question sits in `history` — which is not where it sits in the
214
- * session once a compaction has folded the head into a summary. Anything but a user message there
215
- * leaves the request as it was.
216
- * @param context What `assembleContext` built, this turn or the turn the question was asked.
217
- * Empty returns `history` itself.
218
- * @param preface Said above the blocks. Absent is what `configureHooks` last set — `HOOK_PREFACE`
219
- * unless something moved it. Empty says nothing, rather than leaving a blank line where it was.
220
- * @returns `history` when there was nothing to add or nowhere to add it, otherwise a new array.
221
217
  */
222
218
  export declare function withContext(history: OpenAI.ChatCompletionMessageParam[], index: number, context: string, preface?: string): OpenAI.ChatCompletionMessageParam[];
223
219
  /**
224
220
  * One sentence for a system prompt, saying what an `untrusted` block is.
225
221
  *
222
+ * @remarks
226
223
  * It belongs in the system prompt rather than beside each block, because it is a standing rule
227
224
  * about every block the session will ever carry, and said once there it costs the prompt cache
228
225
  * nothing. Like `HOOK_PREFACE` it names no host.
@@ -232,6 +229,12 @@ export declare const UNTRUSTED_PREFACE: string;
232
229
  * Fences text nobody trusted — a fetched page, an email, a submitted card, a tool result — so the
233
230
  * model can see where it starts and ends and read it as data rather than as instructions.
234
231
  *
232
+ * @param text - What came in. Kept whole, apart from the escaped tags.
233
+ * @param [options] - `source` names where it came from, for the model and for whoever reads the
234
+ * transcript later — a URL, a sender, a tool's name. Left out, the block carries no attribute.
235
+ * @returns The block, with the text on its own lines between the tags.
236
+ *
237
+ * @remarks
235
238
  * A fence the text can close is no fence, so every `untrusted` tag inside it, opening or closing
236
239
  * and in any case, has its `<` escaped: a page that writes `</untrusted>` and then an instruction
237
240
  * leaves that instruction inside the block where it began. Nothing else is touched, so the text
@@ -239,19 +242,41 @@ export declare const UNTRUSTED_PREFACE: string;
239
242
  *
240
243
  * This is one layer and not a defence on its own. A model can still be talked out of a fence it
241
244
  * can see; what the text is allowed to make the agent do is the tool policy's to decide.
242
- *
243
- * @param text What came in. Kept whole, apart from the escaped tags.
244
- * @param options `source` names where it came from, for the model and for whoever reads the
245
- * transcript later — a URL, a sender, a tool's name. Left out, the block carries no attribute.
246
- * @returns The block, with the text on its own lines between the tags.
247
245
  */
248
246
  export declare function untrusted(text: string, { source }?: {
249
247
  source?: string;
250
248
  }): string;
249
+ /**
250
+ * A message's text, whether its content is a string or a list of parts.
251
+ *
252
+ * @param content - A message's `content`, in any of the shapes the API allows. One that is neither
253
+ * a string nor a list reads as empty.
254
+ * @returns The text, untrimmed. A string comes back as it is, and a list with no text part is
255
+ * empty.
256
+ *
257
+ * @remarks
258
+ * Parts are joined with nothing between them, because they are one text an API split rather than
259
+ * several: a space put in is a character the sender never wrote, and `turnMessages` hashes this
260
+ * into the uuid a memory server dedups on. Compaction reads the same function, so the summariser
261
+ * and the hook told about a fold see one message the same way. A refusal part is left out.
262
+ */
263
+ export declare const textOf: (content: unknown) => string;
251
264
  /**
252
265
  * A stretch of a transcript as a hook reads it: what the user and the assistant said, and nothing
253
266
  * else.
254
267
  *
268
+ * @param sessionId - Prefixes every uuid, so two sessions never share one.
269
+ * @param messages - The transcript, in whatever shape the host stores it, so long as each message
270
+ * has an OpenAI-style `role` and `content`.
271
+ * @param from - The first index, inclusive. Below zero reads from the start.
272
+ * @param [to] - The end, exclusive. Absent, or past the end, reads to the end.
273
+ * @param [options] - `offset` is what the array's first message is numbered as in the uuids — the
274
+ * stored index of `messages[0]`, when `messages` is a request a fold has shifted. Zero numbers
275
+ * by position. `from` and `to` stay array indexes either way.
276
+ * @returns One entry per user or assistant message in the range that has text once trimmed, in
277
+ * transcript order. Empty when there is none.
278
+ *
279
+ * @remarks
255
280
  * Tool calls and their results are left out. They are the model's working rather than the
256
281
  * conversation, and most of a transcript's characters; a memory server that filed them would
257
282
  * recall a directory listing ahead of the decision it led to.
@@ -268,15 +293,6 @@ export declare function untrusted(text: string, { source }?: {
268
293
  * and again when it is compacted, would arrive under two uuids and be remembered twice. `offset`
269
294
  * is what puts the numbering back on the host's own indexes; passing the stored transcript rather
270
295
  * than the request avoids the question entirely.
271
- *
272
- * @param sessionId Prefixes every uuid, so two sessions never share one.
273
- * @param messages The transcript, in whatever shape the host stores it, so long as each message
274
- * has an OpenAI-style `role` and `content`.
275
- * @param from The first index, inclusive. Below zero reads from the start.
276
- * @param to The end, exclusive. Absent, or past the end, reads to the end.
277
- * @param options `offset` is what the array's first message is numbered as in the uuids — the
278
- * stored index of `messages[0]`, when `messages` is a request a fold has shifted. Zero by default,
279
- * which numbers by position as before. `from` and `to` stay array indexes either way.
280
296
  */
281
297
  export declare function turnMessages(sessionId: string, messages: readonly {
282
298
  role: string;
@@ -287,15 +303,16 @@ export declare function turnMessages(sessionId: string, messages: readonly {
287
303
  /**
288
304
  * Which turn of a session begins at a point, from 0: the user messages ahead of it.
289
305
  *
306
+ * @param messages - The transcript.
307
+ * @param [before] - Where the turn begins.
308
+ * @param [offset] - Turns already folded away and so not in `messages`.
309
+ * @returns `offset` plus the count of user messages before `before`.
310
+ *
311
+ * @remarks
290
312
  * Counted over what it is given, which is the session only while nothing has been folded away — a
291
313
  * compacted request has lost the questions the summary now stands for, and turn eleven counting
292
314
  * itself as turn two is the kind of thing a hook writes into a memory. Count over the stored
293
315
  * transcript, or add what the fold took as `offset`.
294
- *
295
- * @param messages The transcript.
296
- * @param before Where the turn begins. Absent is the end, which is the index of a turn whose
297
- * question has not been appended yet.
298
- * @param offset Turns already folded away and so not in `messages`. Zero by default.
299
316
  */
300
317
  export declare const turnIndex: (messages: readonly {
301
318
  role: string;
@@ -303,59 +320,64 @@ export declare const turnIndex: (messages: readonly {
303
320
  /**
304
321
  * Runs the hooks ahead of a request and builds what they add to it.
305
322
  *
306
- * This is on the path of the first token, so the events run together rather than one after the
307
- * other, and a hook that fails costs the turn its context and never the turn — a runner that
308
- * rejects outright is noted once for its event, with an empty `hookId` and `source`, and the rest
309
- * go ahead. Bounding each hook's time is the runner's job; `signal` is how the turn ends all of
310
- * them.
311
- *
312
- * @param run Runs one event's hooks.
313
- * @param events Which to run: `["beforeTurn"]` ordinarily, and `sessionStart` ahead of it on a
323
+ * @param run - Runs one event's hooks.
324
+ * @param events - Which to run: `["beforeTurn"]` ordinarily, and `sessionStart` ahead of it on a
314
325
  * session's first turn. The outcomes are assembled in this order, so it is also the order the
315
326
  * budget is spent in.
316
- * @param context What the hooks are told.
317
- * @param options `signal` is handed to the runner, and should be the turn's own: a user who
327
+ * @param context - What the hooks are told.
328
+ * @param [options] - `signal` is handed to the runner, and should be the turn's own: a user who
318
329
  * stopped the turn stopped its recall. `onNote` hears each note as the whole is assembled.
319
330
  * `maxTokens` is the shared budget for this request, read as `assembleContext` reads it: absent
320
331
  * or unusable is the process's, from `configureHooks`.
332
+ * @returns What `assembleContext` built from every event's outcomes together. Does not reject for a
333
+ * runner that did.
334
+ *
335
+ * @remarks
336
+ * This is on the path of the first token, so the events run together rather than one after the
337
+ * other, and a hook that fails costs the turn its context and never the turn — a runner that
338
+ * rejects outright is noted once for its event, with an empty `hookId` and `source`, and the rest
339
+ * go ahead. Bounding each hook's time is the runner's job; `signal` is how the turn ends all of
340
+ * them.
321
341
  */
322
- export declare function gather(run: HookRunner, events: readonly HookEvent[], context: HookContext, { signal, onNote, maxTokens, }?: {
342
+ export declare function gather(run: HookRunner, events: readonly HookEvent[], context: HookContext, { signal, onNote, maxTokens }?: {
323
343
  signal?: AbortSignal;
324
- onNote?: (note: HookNote) => void;
344
+ onNote?: OnNote;
325
345
  maxTokens?: number;
326
346
  }): Promise<Gathered>;
327
347
  /**
328
348
  * Runs the hooks for an event that reads what happened and adds nothing to a request. Never
329
349
  * rejects, so a host can fire it without awaiting it.
330
350
  *
351
+ * @param run - Runs the event's hooks.
352
+ * @param event - `afterTurn`, `beforeCompact`, `sessionEnd` or `sessionDelete`. An injecting event
353
+ * works too, but what its hooks return is dropped, since there is no request here to add it to.
354
+ * @param context - What the hooks are told.
355
+ * @param [onNote] - Hears each note — which, with nothing injected, is only ever a failure.
356
+ * @returns The same notes.
357
+ *
358
+ * @remarks
331
359
  * No signal: these run once the turn has been answered, and a reader who stops listening at that
332
360
  * point has not asked for the turn not to be remembered. Nor is a `veto` read, since whatever it
333
361
  * would stop is already under way; `consult` is the one that waits for it.
334
- *
335
- * @param run Runs the event's hooks.
336
- * @param event `afterTurn`, `beforeCompact`, `sessionEnd` or `sessionDelete`. An injecting event
337
- * works too, but what its hooks return is dropped, since there is no request here to add it to.
338
- * @param context What the hooks are told.
339
- * @param onNote Hears each note — which, with nothing injected, is only ever a failure.
340
- * @returns The same notes.
341
362
  */
342
- export declare function notify(run: HookRunner, event: HookEvent, context: HookContext, onNote?: (note: HookNote) => void): Promise<HookNote[]>;
363
+ export declare function notify(run: HookRunner, event: HookEvent, context: HookContext, onNote?: OnNote): Promise<HookNote[]>;
343
364
  /**
344
365
  * Runs an event's hooks and waits for their say, for a host that will hold off when one of them
345
366
  * vetoes.
346
367
  *
368
+ * @param run - Runs the event's hooks.
369
+ * @param event - What is about to happen. Only `beforeCompact` has anything a veto can stop.
370
+ * @param context - What the hooks are told.
371
+ * @param [onNote] - Hears each note: every failure, and every veto, naming the hook that made it.
372
+ * @returns The same notes, and `vetoed` when any `ok` outcome carried `veto`.
373
+ *
374
+ * @remarks
347
375
  * `notify` runs beside the thing it announces and cannot stop it; this runs ahead of it, so each
348
376
  * hook's time is added to whatever waits on the answer. A host that does not mean to act on a
349
377
  * veto should call `notify` instead. Never rejects: a runner that throws is noted as a failure,
350
378
  * and a failure is not a veto — a memory server that is down has not asked for anything.
351
- *
352
- * @param run Runs the event's hooks.
353
- * @param event What is about to happen. Only `beforeCompact` has anything a veto can stop.
354
- * @param context What the hooks are told.
355
- * @param onNote Hears each note: every failure, and every veto, naming the hook that made it.
356
- * @returns The same notes, and `vetoed` when any `ok` outcome carried `veto`.
357
379
  */
358
- export declare function consult(run: HookRunner, event: HookEvent, context: HookContext, onNote?: (note: HookNote) => void): Promise<{
380
+ export declare function consult(run: HookRunner, event: HookEvent, context: HookContext, onNote?: OnNote): Promise<{
359
381
  notes: HookNote[];
360
382
  vetoed: boolean;
361
383
  }>;