@cubicecho/agent-core 3.0.0 → 4.1.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 (73) hide show
  1. package/README.md +34 -3
  2. package/dist/{compaction.d.ts → context/compaction.d.ts} +6 -6
  3. package/dist/{compaction.js → context/compaction.js} +9 -9
  4. package/dist/{ledger.d.ts → context/ledger.d.ts} +2 -2
  5. package/dist/{ledger.js → context/ledger.js} +3 -3
  6. package/dist/{guards.d.ts → core/guards.d.ts} +2 -3
  7. package/dist/{guards.js → core/guards.js} +1 -2
  8. package/dist/{scope.d.ts → core/scope.d.ts} +3 -3
  9. package/dist/{calibration.js → endpoint/calibration.js} +4 -4
  10. package/dist/{capabilities.d.ts → endpoint/capabilities.d.ts} +2 -2
  11. package/dist/{capabilities.js → endpoint/capabilities.js} +3 -3
  12. package/dist/{client.d.ts → endpoint/client.d.ts} +27 -11
  13. package/dist/{client.js → endpoint/client.js} +85 -26
  14. package/dist/{schema-compat.js → endpoint/schema-compat.js} +2 -2
  15. package/dist/{hooks.js → hooks/hooks.js} +6 -6
  16. package/dist/index.d.ts +30 -30
  17. package/dist/index.js +29 -29
  18. package/dist/{agent-loop.d.ts → run/agent-loop.d.ts} +25 -16
  19. package/dist/{agent-loop.js → run/agent-loop.js} +34 -25
  20. package/dist/{events.d.ts → run/events.d.ts} +3 -3
  21. package/dist/{events.js → run/events.js} +6 -6
  22. package/dist/{request-body.d.ts → run/request-body.d.ts} +3 -3
  23. package/dist/{request-body.js → run/request-body.js} +4 -4
  24. package/dist/{run-calls.d.ts → run/run-calls.d.ts} +3 -3
  25. package/dist/{run-calls.js → run/run-calls.js} +4 -4
  26. package/dist/{reset.js → runtime/reset.js} +6 -6
  27. package/dist/{runtime.d.ts → runtime/runtime.d.ts} +11 -11
  28. package/dist/{runtime.js → runtime/runtime.js} +12 -12
  29. package/dist/{snapshot.js → runtime/snapshot.js} +4 -4
  30. package/dist/{spec.d.ts → spec/spec.d.ts} +2 -2
  31. package/dist/{spec.js → spec/spec.js} +3 -3
  32. package/dist/{preselect.d.ts → tools/preselect.d.ts} +5 -4
  33. package/dist/{preselect.js → tools/preselect.js} +6 -5
  34. package/dist/{tool-loading.js → tools/tool-loading.js} +3 -3
  35. package/dist/{continuation.d.ts → turn/continuation.d.ts} +4 -4
  36. package/dist/{continuation.js → turn/continuation.js} +7 -7
  37. package/dist/{run-turn.d.ts → turn/run-turn.d.ts} +2 -2
  38. package/dist/{run-turn.js → turn/run-turn.js} +7 -7
  39. package/dist/{side-task.d.ts → turn/side-task.d.ts} +2 -2
  40. package/dist/{side-task.js → turn/side-task.js} +9 -9
  41. package/dist/{errors.d.ts → wire/errors.d.ts} +4 -0
  42. package/dist/{errors.js → wire/errors.js} +4 -0
  43. package/dist/{retry.d.ts → wire/retry.d.ts} +1 -1
  44. package/dist/{retry.js → wire/retry.js} +2 -2
  45. package/dist/{stream.js → wire/stream.js} +1 -1
  46. package/dist/{tokens.d.ts → wire/tokens.d.ts} +2 -2
  47. package/dist/{tokens.js → wire/tokens.js} +2 -2
  48. package/dist/{tool-calls.js → wire/tool-calls.js} +1 -1
  49. package/llms.txt +177 -179
  50. package/package.json +3 -3
  51. /package/dist/{config.d.ts → core/config.d.ts} +0 -0
  52. /package/dist/{config.js → core/config.js} +0 -0
  53. /package/dist/{digest.d.ts → core/digest.d.ts} +0 -0
  54. /package/dist/{digest.js → core/digest.js} +0 -0
  55. /package/dist/{platform.d.ts → core/platform.d.ts} +0 -0
  56. /package/dist/{platform.js → core/platform.js} +0 -0
  57. /package/dist/{scope.js → core/scope.js} +0 -0
  58. /package/dist/{calibration.d.ts → endpoint/calibration.d.ts} +0 -0
  59. /package/dist/{schema-compat.d.ts → endpoint/schema-compat.d.ts} +0 -0
  60. /package/dist/{hook-events.d.ts → hooks/hook-events.d.ts} +0 -0
  61. /package/dist/{hook-events.js → hooks/hook-events.js} +0 -0
  62. /package/dist/{hooks.d.ts → hooks/hooks.d.ts} +0 -0
  63. /package/dist/{reset.d.ts → runtime/reset.d.ts} +0 -0
  64. /package/dist/{snapshot.d.ts → runtime/snapshot.d.ts} +0 -0
  65. /package/dist/{catalog.d.ts → tools/catalog.d.ts} +0 -0
  66. /package/dist/{catalog.js → tools/catalog.js} +0 -0
  67. /package/dist/{tool-loading.d.ts → tools/tool-loading.d.ts} +0 -0
  68. /package/dist/{stream.d.ts → wire/stream.d.ts} +0 -0
  69. /package/dist/{thinking.d.ts → wire/thinking.d.ts} +0 -0
  70. /package/dist/{thinking.js → wire/thinking.js} +0 -0
  71. /package/dist/{tool-calls.d.ts → wire/tool-calls.d.ts} +0 -0
  72. /package/dist/{wire.d.ts → wire/wire.d.ts} +0 -0
  73. /package/dist/{wire.js → wire/wire.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  import type OpenAI from 'openai';
2
- import { type Capabilities } from './capabilities.ts';
2
+ import { type Capabilities } from '../endpoint/capabilities.ts';
3
+ import { type Turn } from '../wire/stream.ts';
3
4
  import { type RequestBuilder, type RunTurnOptions } from './run-turn.ts';
4
- import { type Turn } from './stream.ts';
5
5
  /**
6
6
  * Picking up an answer the token ceiling cut off, instead of keeping half of it.
7
7
  *
@@ -50,8 +50,8 @@ export declare const isContinuable: (turn: Turn) => boolean;
50
50
  * continuation's `finishReason` and tool calls.
51
51
  *
52
52
  * @remarks
53
- * Only a turn `isContinuable` accepts is continued; any other comes back as it was. Content and
54
- * reasoning are joined in order, the tool calls a continuation makes are kept, and usage is summed
53
+ * Only a turn cut off at the ceiling, with an answer begun and no tool call in it, is continued;
54
+ * any other comes back as it was. Content and reasoning are joined in order, the tool calls a continuation makes are kept, and usage is summed
55
55
  * across the requests with `continuations` counting them. The continuation is read as starting in
56
56
  * the answer, whatever `startInReasoning` says: a template that opens a fence for a fresh reply
57
57
  * does not open one for a prefill. Its tokens reach `onOutput` as they arrive, so a watcher sees
@@ -1,9 +1,9 @@
1
- import { modelCapabilitiesFor } from './capabilities.js';
2
- import { errorMessage } from './errors.js';
3
- import { ContextOverflow, refusesRequest } from './retry.js';
1
+ import { modelCapabilitiesFor } from '../endpoint/capabilities.js';
2
+ import { errorMessage } from '../wire/errors.js';
3
+ import { ContextOverflow, refusesRequest } from '../wire/retry.js';
4
+ import { addCounts } from '../wire/stream.js';
5
+ import { FinishReason, Role } from '../wire/wire.js';
4
6
  import { modelLabel, runTurn } from './run-turn.js';
5
- import { addCounts } from './stream.js';
6
- import { FinishReason, Role } from './wire.js';
7
7
  /**
8
8
  * Whether a turn is one a continuation can finish: cut off at the ceiling, with an answer begun
9
9
  * and no tool call in it.
@@ -112,8 +112,8 @@ function joinUsage(first, next) {
112
112
  * continuation's `finishReason` and tool calls.
113
113
  *
114
114
  * @remarks
115
- * Only a turn `isContinuable` accepts is continued; any other comes back as it was. Content and
116
- * reasoning are joined in order, the tool calls a continuation makes are kept, and usage is summed
115
+ * Only a turn cut off at the ceiling, with an answer begun and no tool call in it, is continued;
116
+ * any other comes back as it was. Content and reasoning are joined in order, the tool calls a continuation makes are kept, and usage is summed
117
117
  * across the requests with `continuations` counting them. The continuation is read as starting in
118
118
  * the answer, whatever `startInReasoning` says: a template that opens a fence for a fresh reply
119
119
  * does not open one for a prefill. Its tokens reach `onOutput` as they arrive, so a watcher sees
@@ -1,6 +1,6 @@
1
1
  import type OpenAI from 'openai';
2
- import { type Capabilities, type ModelCapabilities, type OnNotice } from './capabilities.ts';
3
- import { type StreamTurnOptions, type Turn } from './stream.ts';
2
+ import { type Capabilities, type ModelCapabilities, type OnNotice } from '../endpoint/capabilities.ts';
3
+ import { type StreamTurnOptions, type Turn } from '../wire/stream.ts';
4
4
  /**
5
5
  * One turn, given as many attempts as the caller allows.
6
6
  *
@@ -1,10 +1,10 @@
1
- import { calibrate, charsPerTokenFor } from './calibration.js';
2
- import { negotiate } from './capabilities.js';
3
- import { errorMessage } from './errors.js';
4
- import { MS_PER_SECOND } from './platform.js';
5
- import { backoffMs, ContextOverflow, EndpointSilent, isModelLoading, isOverflow, isTransient, LOADING_POLL_MS, LOADING_TIMEOUT_MS, SMALLEST_LIKELY_WINDOW, sleep, } from './retry.js';
6
- import { streamTurn } from './stream.js';
7
- import { compact, requestTokens } from './tokens.js';
1
+ import { MS_PER_SECOND } from '../core/platform.js';
2
+ import { calibrate, charsPerTokenFor } from '../endpoint/calibration.js';
3
+ import { negotiate } from '../endpoint/capabilities.js';
4
+ import { errorMessage } from '../wire/errors.js';
5
+ import { backoffMs, ContextOverflow, EndpointSilent, isModelLoading, isOverflow, isTransient, LOADING_POLL_MS, LOADING_TIMEOUT_MS, SMALLEST_LIKELY_WINDOW, sleep, } from '../wire/retry.js';
6
+ import { streamTurn } from '../wire/stream.js';
7
+ import { compact, requestTokens } from '../wire/tokens.js';
8
8
  /**
9
9
  * What a notice calls the model, where the caller did not say which one it is.
10
10
  *
@@ -1,6 +1,6 @@
1
1
  import type OpenAI from 'openai';
2
- import { type OnNotice } from './capabilities.ts';
3
- import type { Endpoint, EndpointIdentity } from './config.ts';
2
+ import type { Endpoint, EndpointIdentity } from '../core/config.ts';
3
+ import { type OnNotice } from '../endpoint/capabilities.ts';
4
4
  /**
5
5
  * The pairs that refused the hints, the live set, for `exportCapabilities` and
6
6
  * `importCapabilities`.
@@ -1,12 +1,12 @@
1
- import { capabilitiesFor, ceilingAndTemperature, EFFORT_NONE, effortFor, modelCapabilitiesFor, negotiate, } from './capabilities.js';
2
- import { endpointId, getClient, modelKey, resolveApiKey, sameUrl } from './client.js';
3
- import { errorMessage } from './errors.js';
4
- import { isAbort, refusesRequest } from './retry.js';
5
- import { relaxSchema, sanitizeSchema } from './schema-compat.js';
6
- import { scoped } from './scope.js';
7
- import { stripThinking } from './thinking.js';
8
- import { CODE_FENCE, looseJson } from './tool-calls.js';
9
- import { JSON_SCHEMA_FORMAT, Role } from './wire.js';
1
+ import { scoped } from '../core/scope.js';
2
+ import { capabilitiesFor, ceilingAndTemperature, EFFORT_NONE, effortFor, modelCapabilitiesFor, negotiate, } from '../endpoint/capabilities.js';
3
+ import { endpointId, getClient, modelKey, resolveApiKey, sameUrl } from '../endpoint/client.js';
4
+ import { relaxSchema, sanitizeSchema } from '../endpoint/schema-compat.js';
5
+ import { errorMessage } from '../wire/errors.js';
6
+ import { isAbort, refusesRequest } from '../wire/retry.js';
7
+ import { stripThinking } from '../wire/thinking.js';
8
+ import { CODE_FENCE, looseJson } from '../wire/tool-calls.js';
9
+ import { JSON_SCHEMA_FORMAT, Role } from '../wire/wire.js';
10
10
  /**
11
11
  * One-shot calls that support a run without being one: picking tools, naming a session,
12
12
  * summarising a transcript, proposing follow-ups. They share a shape — small prompt, short
@@ -38,6 +38,8 @@ export interface AgentLoopFailure {
38
38
  loaded: string[];
39
39
  /** The tools the model had called, `load_tools` excluded. */
40
40
  used: string[];
41
+ /** The shortlist the run opened with, as the result's `preselected` would have said it. */
42
+ preselected: string[];
41
43
  }
42
44
  /**
43
45
  * What `runAgentLoop` throws, carrying the run as it stood and what was caught as `cause`.
@@ -55,6 +57,7 @@ export declare class AgentLoopError extends Error implements AgentLoopFailure {
55
57
  readonly toolCalls: ToolCallOutcome[];
56
58
  readonly loaded: string[];
57
59
  readonly used: string[];
60
+ readonly preselected: string[];
58
61
  /**
59
62
  * @param message - What went wrong — the cause's own message, where there is a cause.
60
63
  * @param run - The run as it stood. Held, not copied.
@@ -87,6 +90,7 @@ export declare class AgentLoopOverflow extends ContextOverflow implements AgentL
87
90
  readonly toolCalls: ToolCallOutcome[];
88
91
  readonly loaded: string[];
89
92
  readonly used: string[];
93
+ readonly preselected: string[];
90
94
  /**
91
95
  * @param message - The overflow's own message.
92
96
  * @param run - The run as it stood. Held, not copied.
@@ -28,6 +28,7 @@ export class AgentLoopError extends Error {
28
28
  toolCalls;
29
29
  loaded;
30
30
  used;
31
+ preselected;
31
32
  /**
32
33
  * @param message - What went wrong — the cause's own message, where there is a cause.
33
34
  * @param run - The run as it stood. Held, not copied.
@@ -40,6 +41,7 @@ export class AgentLoopError extends Error {
40
41
  this.toolCalls = run.toolCalls;
41
42
  this.loaded = run.loaded;
42
43
  this.used = run.used;
44
+ this.preselected = run.preselected;
43
45
  }
44
46
  }
45
47
  /**
@@ -67,6 +69,7 @@ export class AgentLoopOverflow extends ContextOverflow {
67
69
  toolCalls;
68
70
  loaded;
69
71
  used;
72
+ preselected;
70
73
  /**
71
74
  * @param message - The overflow's own message.
72
75
  * @param run - The run as it stood. Held, not copied.
@@ -79,6 +82,7 @@ export class AgentLoopOverflow extends ContextOverflow {
79
82
  this.toolCalls = run.toolCalls;
80
83
  this.loaded = run.loaded;
81
84
  this.used = run.used;
85
+ this.preselected = run.preselected;
82
86
  }
83
87
  }
84
88
  /**
@@ -91,7 +91,7 @@ export declare const refusesRequest: (error: unknown) => boolean;
91
91
  *
92
92
  * @remarks
93
93
  * An abort reaches a catch in two shapes. The SDK raises its own class when a request in flight is
94
- * cancelled, and `sleep` rejects with the signal's reason when the cancel lands between attempts.
94
+ * cancelled, and the wait between attempts rejects with the signal's reason when the cancel lands there.
95
95
  * A catch that knew only the first reported the second as a failure. A signal aborted with a
96
96
  * reason of the caller's own making is not recognised, since only the error is looked at: a
97
97
  * catch that holds the signal asks it as well, as `tryAsk` does.
@@ -1,5 +1,5 @@
1
1
  import OpenAI from 'openai';
2
- import { ABORT_ERROR, ABORT_EVENT } from './platform.js';
2
+ import { ABORT_ERROR, ABORT_EVENT } from '../core/platform.js';
3
3
  import { HttpStatus } from './wire.js';
4
4
  /**
5
5
  * Everything about a request failing that is not about what the request said.
@@ -135,7 +135,7 @@ export const refusesRequest = (error) => error instanceof OpenAI.APIError &&
135
135
  *
136
136
  * @remarks
137
137
  * An abort reaches a catch in two shapes. The SDK raises its own class when a request in flight is
138
- * cancelled, and `sleep` rejects with the signal's reason when the cancel lands between attempts.
138
+ * cancelled, and the wait between attempts rejects with the signal's reason when the cancel lands there.
139
139
  * A catch that knew only the first reported the second as a failure. A signal aborted with a
140
140
  * reason of the caller's own making is not recognised, since only the error is looked at: a
141
141
  * catch that holds the signal asks it as well, as `tryAsk` does.
@@ -1,4 +1,4 @@
1
- import { MS_PER_SECOND } from './platform.js';
1
+ import { MS_PER_SECOND } from '../core/platform.js';
2
2
  import { EndpointSilent } from './retry.js';
3
3
  import { DEFAULT_FENCES, FenceSplitter, SPLIT_REASONING } from './thinking.js';
4
4
  import { FUNCTION_TOOL } from './wire.js';
@@ -72,7 +72,7 @@ export declare function toolsChars(tools: OpenAI.ChatCompletionTool[]): number;
72
72
  *
73
73
  * @param body - The request as it was sent, tools included.
74
74
  * @returns The sum of `messageChars` over the messages. The tools are not in it, whether or not
75
- * the body carries them; `toolsChars` counts those.
75
+ * the body carries them; `contextChars` counts those, under `tools`.
76
76
  *
77
77
  * @remarks
78
78
  * What calibration reads a reported prompt count against, since a ratio is only as good as the
@@ -132,7 +132,7 @@ export interface ContextBreakdown {
132
132
  * that is neither that nor a `tool` message as `history`.
133
133
  *
134
134
  * @remarks
135
- * Exact and additive: the parts sum to `total`, which is `requestChars` plus `toolsChars`. The
135
+ * Exact and additive: the parts sum to `total`, which is `requestChars` plus the characters of the tools. The
136
136
  * conversion to tokens is `contextTokens`' business, because that is where an estimate and a
137
137
  * reported count have to be told apart.
138
138
  */
@@ -180,7 +180,7 @@ export function toolsChars(tools) {
180
180
  *
181
181
  * @param body - The request as it was sent, tools included.
182
182
  * @returns The sum of `messageChars` over the messages. The tools are not in it, whether or not
183
- * the body carries them; `toolsChars` counts those.
183
+ * the body carries them; `contextChars` counts those, under `tools`.
184
184
  *
185
185
  * @remarks
186
186
  * What calibration reads a reported prompt count against, since a ratio is only as good as the
@@ -232,7 +232,7 @@ const PARTS = ['system', 'tools', 'history', 'toolResults'];
232
232
  * that is neither that nor a `tool` message as `history`.
233
233
  *
234
234
  * @remarks
235
- * Exact and additive: the parts sum to `total`, which is `requestChars` plus `toolsChars`. The
235
+ * Exact and additive: the parts sum to `total`, which is `requestChars` plus the characters of the tools. The
236
236
  * conversion to tokens is `contextTokens`' business, because that is where an estimate and a
237
237
  * reported count have to be told apart.
238
238
  */
@@ -1,4 +1,4 @@
1
- import { isRecord } from './guards.js';
1
+ import { isRecord } from '../core/guards.js';
2
2
  import { THINK_FENCE } from './thinking.js';
3
3
  import { FinishReason, FUNCTION_TOOL } from './wire.js';
4
4
  /**