@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.
- package/README.md +14 -9
- package/dist/agent-loop.d.ts +84 -204
- package/dist/agent-loop.js +416 -643
- package/dist/calibration.d.ts +14 -10
- package/dist/calibration.js +30 -22
- package/dist/capabilities.d.ts +140 -35
- package/dist/capabilities.js +345 -152
- package/dist/client.d.ts +104 -35
- package/dist/client.js +210 -78
- package/dist/compaction.d.ts +103 -60
- package/dist/compaction.js +163 -93
- package/dist/config.d.ts +48 -12
- package/dist/config.js +20 -1
- package/dist/continuation.d.ts +25 -17
- package/dist/continuation.js +70 -47
- package/dist/digest.d.ts +7 -0
- package/dist/digest.js +18 -0
- package/dist/errors.d.ts +24 -15
- package/dist/errors.js +23 -15
- package/dist/events.d.ts +108 -58
- package/dist/events.js +265 -128
- package/dist/guards.d.ts +53 -0
- package/dist/guards.js +55 -0
- package/dist/hook-events.d.ts +38 -0
- package/dist/hook-events.js +36 -0
- package/dist/hooks.d.ts +105 -83
- package/dist/hooks.js +224 -139
- package/dist/index.d.ts +30 -25
- package/dist/index.js +29 -23
- package/dist/ledger.d.ts +62 -30
- package/dist/ledger.js +163 -56
- package/dist/platform.d.ts +13 -0
- package/dist/platform.js +13 -0
- package/dist/preselect.d.ts +222 -0
- package/dist/preselect.js +290 -0
- package/dist/request-body.d.ts +32 -0
- package/dist/request-body.js +47 -0
- package/dist/reset.d.ts +1 -0
- package/dist/reset.js +7 -6
- package/dist/retry.d.ts +40 -143
- package/dist/retry.js +79 -285
- package/dist/run-calls.d.ts +123 -0
- package/dist/run-calls.js +351 -0
- package/dist/run-turn.d.ts +44 -16
- package/dist/run-turn.js +74 -37
- package/dist/runtime.d.ts +23 -17
- package/dist/runtime.js +34 -24
- package/dist/schema-compat.d.ts +51 -11
- package/dist/schema-compat.js +375 -193
- package/dist/scope.d.ts +28 -5
- package/dist/scope.js +37 -10
- package/dist/side-task.d.ts +127 -39
- package/dist/side-task.js +189 -100
- package/dist/snapshot.d.ts +12 -7
- package/dist/snapshot.js +87 -65
- package/dist/spec.d.ts +66 -36
- package/dist/spec.js +514 -265
- package/dist/stream.d.ts +73 -16
- package/dist/stream.js +228 -98
- package/dist/thinking.d.ts +23 -8
- package/dist/thinking.js +96 -46
- package/dist/tokens.d.ts +171 -6
- package/dist/tokens.js +326 -6
- package/dist/tool-calls.d.ts +89 -15
- package/dist/tool-calls.js +205 -85
- package/dist/tool-loading.d.ts +109 -187
- package/dist/tool-loading.js +286 -372
- package/dist/wire.d.ts +81 -0
- package/dist/wire.js +73 -0
- package/llms.txt +87 -43
- package/package.json +4 -4
package/dist/runtime.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { calibrate, charsPerTokenFor, resetCalibration } from
|
|
3
|
-
import { capabilitiesFor, expireCapabilities, resetCapabilities } from
|
|
4
|
-
import { type ClientPoolOptions, configureClients, contextLimitFor, getClient, listModels, resetClients, servedWindow } from
|
|
5
|
-
import { compactTranscript, runCompaction, summariser } from
|
|
6
|
-
import { continueTurn } from
|
|
7
|
-
import { configureEvents, type EventBusOptions, emit, endRun, history, resetEvents, watch } from
|
|
8
|
-
import { assembleContext, configureHooks, consult, gather, type HookOptions, notify, resetHooks, withContext } from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { runAgentLoop } from './agent-loop.ts';
|
|
2
|
+
import { calibrate, charsPerTokenFor, resetCalibration } from './calibration.ts';
|
|
3
|
+
import { capabilitiesFor, expireCapabilities, resetCapabilities } from './capabilities.ts';
|
|
4
|
+
import { type ClientPoolOptions, configureClients, contextLimitFor, getClient, listModels, resetClients, servedWindow } from './client.ts';
|
|
5
|
+
import { compactTranscript, runCompaction, summariser } from './compaction.ts';
|
|
6
|
+
import { continueTurn } from './continuation.ts';
|
|
7
|
+
import { configureEvents, type EventBusOptions, emit, endRun, history, resetEvents, watch } from './events.ts';
|
|
8
|
+
import { assembleContext, configureHooks, consult, gather, type HookOptions, notify, resetHooks, withContext } from './hooks.ts';
|
|
9
|
+
import { preselect } from './preselect.ts';
|
|
10
|
+
import { resetAll } from './reset.ts';
|
|
11
|
+
import { runTurn } from './run-turn.ts';
|
|
12
|
+
import { ask, askJson, resetHints, tryAsk } from './side-task.ts';
|
|
13
|
+
import { exportCapabilities, importCapabilities } from './snapshot.ts';
|
|
13
14
|
/**
|
|
14
15
|
* Every exported function that reads or writes what a runtime remembers, itself or through what
|
|
15
16
|
* it calls. The rest of the package is pure, and is the same function whichever runtime it is
|
|
@@ -68,6 +69,7 @@ export interface RuntimeOptions {
|
|
|
68
69
|
/**
|
|
69
70
|
* One set of the package's caches, with the functions that use them as methods.
|
|
70
71
|
*
|
|
72
|
+
* @remarks
|
|
71
73
|
* Each method is the top-level function of the same name, with the same signature and doc
|
|
72
74
|
* comment, run against this runtime's state instead of the process's: its pooled clients and
|
|
73
75
|
* model listings, latched capabilities, measured characters per token, no-thinking hints, event
|
|
@@ -79,10 +81,11 @@ export type Runtime = typeof STATEFUL & {
|
|
|
79
81
|
* an `await`, or from a timer it sets — uses this runtime's state. What the methods do, for
|
|
80
82
|
* code that calls the top-level functions itself.
|
|
81
83
|
*
|
|
84
|
+
* @param fn - What to run. Its return value, or what it throws, is handed straight back.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
82
87
|
* It does not reach a callback that outlives `fn` and is called from elsewhere — a generator
|
|
83
88
|
* resumed later, a function handed back and called by someone else. Call a method there.
|
|
84
|
-
*
|
|
85
|
-
* @param fn What to run. Its return value, or what it throws, is handed straight back.
|
|
86
89
|
*/
|
|
87
90
|
run<T>(fn: () => T): T;
|
|
88
91
|
};
|
|
@@ -90,6 +93,11 @@ export type Runtime = typeof STATEFUL & {
|
|
|
90
93
|
* A runtime of its own: separate clients, listings, capability latches, hints, event bus and hook
|
|
91
94
|
* settings from the process's and from every other runtime's.
|
|
92
95
|
*
|
|
96
|
+
* @param [options] - What to configure it with before first use. A part left out keeps the
|
|
97
|
+
* defaults — not the default runtime's settings, which a new runtime does not inherit.
|
|
98
|
+
* @returns A runtime whose state starts empty, with whatever `options` gave already applied.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
93
101
|
* For a host that must not share them — one that mints a key per tenant, where a shared pool has
|
|
94
102
|
* tenants evicting each other's clients and a shared bus has one tenant's run id readable by
|
|
95
103
|
* another — and for tests, where a runtime per case needs no `resetAll` between them and can run
|
|
@@ -104,14 +112,12 @@ export type Runtime = typeof STATEFUL & {
|
|
|
104
112
|
*
|
|
105
113
|
* Nothing needs closing. A runtime is garbage once nothing holds it; its one timer, the event
|
|
106
114
|
* bus's sweep, is unreferenced and stops rescheduling when its last run has been swept.
|
|
107
|
-
*
|
|
108
|
-
* @param options What to configure it with before first use. A part left out keeps the
|
|
109
|
-
* defaults — not the default runtime's settings, which a new runtime does not inherit.
|
|
110
115
|
*/
|
|
111
116
|
export declare function createRuntime(options?: RuntimeOptions): Runtime;
|
|
112
117
|
/**
|
|
113
118
|
* The runtime the top-level functions use when no other is running.
|
|
114
119
|
*
|
|
120
|
+
* @remarks
|
|
115
121
|
* `defaultRuntime.getClient(endpoint)` and `getClient(endpoint)` are the same call outside any
|
|
116
122
|
* runtime. Inside one they differ: the top-level function follows the runtime that is running,
|
|
117
123
|
* and this always reaches the process-wide state.
|
package/dist/runtime.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { calibrate, charsPerTokenFor, resetCalibration } from
|
|
3
|
-
import { capabilitiesFor, expireCapabilities, resetCapabilities } from
|
|
4
|
-
import { configureClients, contextLimitFor, getClient, listModels, resetClients, servedWindow, } from
|
|
5
|
-
import { compactTranscript, runCompaction, summariser } from
|
|
6
|
-
import { continueTurn } from
|
|
7
|
-
import { configureEvents, emit, endRun, history, resetEvents, watch
|
|
8
|
-
import { assembleContext, configureHooks, consult, gather, notify, resetHooks, withContext, } from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
1
|
+
import { runAgentLoop } from './agent-loop.js';
|
|
2
|
+
import { calibrate, charsPerTokenFor, resetCalibration } from './calibration.js';
|
|
3
|
+
import { capabilitiesFor, expireCapabilities, resetCapabilities } from './capabilities.js';
|
|
4
|
+
import { configureClients, contextLimitFor, getClient, listModels, resetClients, servedWindow, } from './client.js';
|
|
5
|
+
import { compactTranscript, runCompaction, summariser } from './compaction.js';
|
|
6
|
+
import { continueTurn } from './continuation.js';
|
|
7
|
+
import { configureEvents, emit, endRun, history, resetEvents, watch } from './events.js';
|
|
8
|
+
import { assembleContext, configureHooks, consult, gather, notify, resetHooks, withContext, } from './hooks.js';
|
|
9
|
+
import { preselect } from './preselect.js';
|
|
10
|
+
import { resetAll } from './reset.js';
|
|
11
|
+
import { runTurn } from './run-turn.js';
|
|
12
|
+
import { inScope, rootScope } from './scope.js';
|
|
13
|
+
import { ask, askJson, resetHints, tryAsk } from './side-task.js';
|
|
14
|
+
import { exportCapabilities, importCapabilities } from './snapshot.js';
|
|
14
15
|
/**
|
|
15
16
|
* Every exported function that reads or writes what a runtime remembers, itself or through what
|
|
16
17
|
* it calls. The rest of the package is pure, and is the same function whichever runtime it is
|
|
@@ -57,13 +58,16 @@ const STATEFUL = {
|
|
|
57
58
|
resetHooks,
|
|
58
59
|
resetAll,
|
|
59
60
|
};
|
|
60
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Makes the methods of the runtime whose state is `scope`.
|
|
63
|
+
*
|
|
64
|
+
* @param scope - The state the methods run against. Held, not copied.
|
|
65
|
+
* @returns Every function in `STATEFUL` wrapped to run in `scope`, and `run`. What `summariser`
|
|
66
|
+
* hands back is wrapped as well, since it is called after the method has returned.
|
|
67
|
+
*/
|
|
61
68
|
function bind(scope) {
|
|
62
69
|
const within = (fn) => (...args) => inScope(scope, () => fn(...args));
|
|
63
|
-
const methods = Object.fromEntries(Object.entries(STATEFUL).map(([name, fn]) => [
|
|
64
|
-
name,
|
|
65
|
-
within(fn),
|
|
66
|
-
]));
|
|
70
|
+
const methods = Object.fromEntries(Object.entries(STATEFUL).map(([name, fn]) => [name, within(fn)]));
|
|
67
71
|
return {
|
|
68
72
|
...methods,
|
|
69
73
|
// What it hands back is called later, by `compactTranscript` or by the host, and asks then.
|
|
@@ -75,6 +79,11 @@ function bind(scope) {
|
|
|
75
79
|
* A runtime of its own: separate clients, listings, capability latches, hints, event bus and hook
|
|
76
80
|
* settings from the process's and from every other runtime's.
|
|
77
81
|
*
|
|
82
|
+
* @param [options] - What to configure it with before first use. A part left out keeps the
|
|
83
|
+
* defaults — not the default runtime's settings, which a new runtime does not inherit.
|
|
84
|
+
* @returns A runtime whose state starts empty, with whatever `options` gave already applied.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
78
87
|
* For a host that must not share them — one that mints a key per tenant, where a shared pool has
|
|
79
88
|
* tenants evicting each other's clients and a shared bus has one tenant's run id readable by
|
|
80
89
|
* another — and for tests, where a runtime per case needs no `resetAll` between them and can run
|
|
@@ -89,23 +98,24 @@ function bind(scope) {
|
|
|
89
98
|
*
|
|
90
99
|
* Nothing needs closing. A runtime is garbage once nothing holds it; its one timer, the event
|
|
91
100
|
* bus's sweep, is unreferenced and stops rescheduling when its last run has been swept.
|
|
92
|
-
*
|
|
93
|
-
* @param options What to configure it with before first use. A part left out keeps the
|
|
94
|
-
* defaults — not the default runtime's settings, which a new runtime does not inherit.
|
|
95
101
|
*/
|
|
96
102
|
export function createRuntime(options = {}) {
|
|
97
103
|
const runtime = bind(new Map());
|
|
98
|
-
if (options.clients)
|
|
104
|
+
if (options.clients) {
|
|
99
105
|
runtime.configureClients(options.clients);
|
|
100
|
-
|
|
106
|
+
}
|
|
107
|
+
if (options.events) {
|
|
101
108
|
runtime.configureEvents(options.events);
|
|
102
|
-
|
|
109
|
+
}
|
|
110
|
+
if (options.hooks) {
|
|
103
111
|
runtime.configureHooks(options.hooks);
|
|
112
|
+
}
|
|
104
113
|
return runtime;
|
|
105
114
|
}
|
|
106
115
|
/**
|
|
107
116
|
* The runtime the top-level functions use when no other is running.
|
|
108
117
|
*
|
|
118
|
+
* @remarks
|
|
109
119
|
* `defaultRuntime.getClient(endpoint)` and `getClient(endpoint)` are the same call outside any
|
|
110
120
|
* runtime. Inside one they differ: the top-level function follows the runtime that is running,
|
|
111
121
|
* and this always reaches the process-wide state.
|
package/dist/schema-compat.d.ts
CHANGED
|
@@ -1,30 +1,70 @@
|
|
|
1
|
-
import type OpenAI from
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
/**
|
|
3
|
+
* One JSON Schema as a strict server will accept it, for a schema that is not a tool's parameters.
|
|
4
|
+
*
|
|
5
|
+
* @param schema - The schema as written. Never mutated. Its root is held to an object, as a tool's
|
|
6
|
+
* parameters are, and anything that is not a schema at all comes back as an object with no
|
|
7
|
+
* properties.
|
|
8
|
+
* @returns A new object: `type: "object"` with a `properties` map, no combinator at the root, no
|
|
9
|
+
* `required` name without a property, and no definition that nothing points at.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* What `sanitizeTools` does to each tool, without the tool: a `response_format` schema goes through
|
|
13
|
+
* the same grammar converter a tool's parameters do, and a caller holding only the schema had to
|
|
14
|
+
* wrap it in a definition to get here. Nothing is remembered — the cache is keyed on a tool
|
|
15
|
+
* definition's identity, and a bare schema has no object that stands for it across requests.
|
|
16
|
+
*/
|
|
17
|
+
export declare function sanitizeSchema(schema: unknown): Record<string, unknown>;
|
|
2
18
|
/**
|
|
3
19
|
* Tool definitions a strict server will accept, remembered per definition object.
|
|
4
20
|
*
|
|
21
|
+
* @param tools - The definitions as the pool hands them over. Never mutated — where a schema
|
|
22
|
+
* changed, a new definition is returned in its place.
|
|
23
|
+
* @returns A new array in the same order. Each entry is the definition remembered for its tool, so
|
|
24
|
+
* the same object on every call; a tool that is not a function tool is its own entry.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
5
27
|
* The first call on a connection's tools does the work and every later one is a lookup, so
|
|
6
28
|
* calling this per request costs nothing.
|
|
7
|
-
*
|
|
8
|
-
* @param tools The definitions as the pool hands them over. Never mutated — where a schema
|
|
9
|
-
* changed, a new definition is returned in its place.
|
|
10
29
|
*/
|
|
11
30
|
export declare const sanitizeTools: (tools: OpenAI.ChatCompletionTool[]) => OpenAI.ChatCompletionTool[];
|
|
12
31
|
/**
|
|
13
|
-
*
|
|
14
|
-
* `pattern` and most `format` values, both of which only ever narrowed a string the tool
|
|
15
|
-
* re-validates anyway.
|
|
32
|
+
* One schema without its `pattern` and `format` keywords, for a schema that is not a tool's.
|
|
16
33
|
*
|
|
17
|
-
* @param
|
|
34
|
+
* @param schema - Already sanitised. Relaxing is the retry, not a substitute for `sanitizeSchema`.
|
|
35
|
+
* Never mutated; anything that is not a schema comes back as an object with no properties.
|
|
36
|
+
* @returns A new object, the keywords gone from every schema position in it.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The retry `relaxTools` makes, on a bare schema. Only the keywords go: a property that happens to
|
|
40
|
+
* be called `format` is an argument name and stays.
|
|
41
|
+
*/
|
|
42
|
+
export declare function relaxSchema(schema: unknown): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* The tool array with every schema's `pattern` and `format` keywords gone — the shape a turn is
|
|
45
|
+
* retried with.
|
|
46
|
+
*
|
|
47
|
+
* @param tools - Already sanitised. Relaxing is the retry, not a substitute for `sanitizeTools`.
|
|
48
|
+
* Never mutated.
|
|
49
|
+
* @returns A new array in the same order. Each entry is the relaxed definition remembered for its
|
|
50
|
+
* tool, so the same object on every call; a tool that is not a function tool is its own entry.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* llama.cpp's converter rejects regex escape classes (`\d`, `\w`, `\s`) in `pattern` and most
|
|
54
|
+
* `format` values, both of which only ever narrowed a string the tool re-validates anyway.
|
|
18
55
|
*/
|
|
19
56
|
export declare const relaxTools: (tools: OpenAI.ChatCompletionTool[]) => OpenAI.ChatCompletionTool[];
|
|
20
57
|
/**
|
|
21
|
-
*
|
|
58
|
+
* Whether a failure looks like the server could not build a grammar from our tool schemas.
|
|
59
|
+
*
|
|
60
|
+
* @param message - The server's error text. Matched case-insensitively.
|
|
61
|
+
* @returns `true` for a grammar or schema-conversion failure. `false` for anything else, and
|
|
62
|
+
* always for a chat template's "no user query found", whatever it is wrapped in.
|
|
22
63
|
*
|
|
64
|
+
* @remarks
|
|
23
65
|
* Every server words this differently — llama-server says "error parsing grammar", Lemonade
|
|
24
66
|
* says "Failed to initialize samplers: failed to parse grammar", others surface the converter
|
|
25
67
|
* by name. Since a grammar is only ever involved in constrained decoding, treat any mention of
|
|
26
68
|
* one as ours; the retry is cheap and latches after a single request.
|
|
27
|
-
*
|
|
28
|
-
* @param message The server's error text. Matched case-insensitively.
|
|
29
69
|
*/
|
|
30
70
|
export declare function isGrammarError(message: string): boolean;
|