@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/scope.d.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Everything one runtime remembers: each module's state, under a key only that module holds.
|
|
3
3
|
*
|
|
4
|
+
* @remarks
|
|
4
5
|
* A map rather than a record of named caches, so a module that grows a cache declares it where
|
|
5
6
|
* it is used and `runtime.ts` does not have to hear about it.
|
|
6
7
|
*/
|
|
7
8
|
export type Scope = Map<symbol, unknown>;
|
|
8
9
|
/** The default runtime's scope: what the top-level functions use when no runtime is running. */
|
|
9
10
|
export declare const rootScope: Scope;
|
|
10
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The scope of the runtime whose method is running, or the default one outside any.
|
|
13
|
+
*
|
|
14
|
+
* @returns The scope itself, not a copy — writing to it is writing to that runtime's state.
|
|
15
|
+
*/
|
|
11
16
|
export declare const currentScope: () => Scope;
|
|
12
17
|
/**
|
|
13
18
|
* Runs `fn` with `scope` as the current one, for it and for everything it awaits or schedules.
|
|
14
19
|
*
|
|
15
|
-
* @param scope The runtime's state. Nested calls replace it for their own duration only.
|
|
16
|
-
* @param fn What to run. Its return value, or what it throws, is handed straight back.
|
|
20
|
+
* @param scope - The runtime's state. Nested calls replace it for their own duration only.
|
|
21
|
+
* @param fn - What to run. Its return value, or what it throws, is handed straight back.
|
|
22
|
+
* @returns What `fn` returned, as it returned it — from an async one the promise itself, unawaited.
|
|
17
23
|
*/
|
|
18
24
|
export declare const inScope: <T>(scope: Scope, fn: () => T) => T;
|
|
19
25
|
/** One module's state, read from whichever scope is current. See `scoped`. */
|
|
@@ -26,10 +32,27 @@ export interface Scoped<T> {
|
|
|
26
32
|
/**
|
|
27
33
|
* Declares a piece of module state that every runtime has its own copy of.
|
|
28
34
|
*
|
|
35
|
+
* @param create - Builds a fresh, empty copy. Called once per scope, and again after `reset`.
|
|
36
|
+
* @returns A function that reads the copy of whichever scope is current when it is called, not
|
|
37
|
+
* when this was, with a `reset` on it that drops that scope's copy.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
29
40
|
* What used to be `const cache = new Map()` at the top of a module is `scoped(() => new Map())`,
|
|
30
41
|
* and each use reads `cache()`. The copy is made lazily, so a runtime pays only for the modules
|
|
31
42
|
* it touches.
|
|
32
|
-
*
|
|
33
|
-
* @param create Builds a fresh, empty copy. Called once per scope, and again after `reset`.
|
|
34
43
|
*/
|
|
35
44
|
export declare function scoped<T>(create: () => T): Scoped<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Writes what a caller gave onto the settings in force, field by field, skipping what is unusable.
|
|
47
|
+
*
|
|
48
|
+
* @param held - The settings in force. Written to — the same object the module goes on reading.
|
|
49
|
+
* @param options - What to change. A field left out is left alone.
|
|
50
|
+
* @param [usable] - Whether a value may be written under a name.
|
|
51
|
+
* @returns A copy of everything in force afterwards, including what this call did not change.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* The body of every `configure*`: a module's settings are one object per runtime, read where they
|
|
55
|
+
* are used, so writing a field onto it is what makes the change apply from the next read. A field
|
|
56
|
+
* that fails its check keeps what it had, which is how a half-built config narrows nothing.
|
|
57
|
+
*/
|
|
58
|
+
export declare function assignSettings<T extends object>(held: T, options: Partial<T>, usable?: (value: unknown, name: string) => boolean): T;
|
package/dist/scope.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { getOrCreate, isPositive } from './guards.js';
|
|
2
3
|
/**
|
|
3
4
|
* Which scope the code running now belongs to, carried across every `await` beneath a runtime's
|
|
4
5
|
* method. Async context rather than a parameter, because the state is read five calls down —
|
|
@@ -8,31 +9,36 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
8
9
|
const active = new AsyncLocalStorage();
|
|
9
10
|
/** The default runtime's scope: what the top-level functions use when no runtime is running. */
|
|
10
11
|
export const rootScope = new Map();
|
|
11
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The scope of the runtime whose method is running, or the default one outside any.
|
|
14
|
+
*
|
|
15
|
+
* @returns The scope itself, not a copy — writing to it is writing to that runtime's state.
|
|
16
|
+
*/
|
|
12
17
|
export const currentScope = () => active.getStore() ?? rootScope;
|
|
13
18
|
/**
|
|
14
19
|
* Runs `fn` with `scope` as the current one, for it and for everything it awaits or schedules.
|
|
15
20
|
*
|
|
16
|
-
* @param scope The runtime's state. Nested calls replace it for their own duration only.
|
|
17
|
-
* @param fn What to run. Its return value, or what it throws, is handed straight back.
|
|
21
|
+
* @param scope - The runtime's state. Nested calls replace it for their own duration only.
|
|
22
|
+
* @param fn - What to run. Its return value, or what it throws, is handed straight back.
|
|
23
|
+
* @returns What `fn` returned, as it returned it — from an async one the promise itself, unawaited.
|
|
18
24
|
*/
|
|
19
25
|
export const inScope = (scope, fn) => active.run(scope, fn);
|
|
20
26
|
/**
|
|
21
27
|
* Declares a piece of module state that every runtime has its own copy of.
|
|
22
28
|
*
|
|
29
|
+
* @param create - Builds a fresh, empty copy. Called once per scope, and again after `reset`.
|
|
30
|
+
* @returns A function that reads the copy of whichever scope is current when it is called, not
|
|
31
|
+
* when this was, with a `reset` on it that drops that scope's copy.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
23
34
|
* What used to be `const cache = new Map()` at the top of a module is `scoped(() => new Map())`,
|
|
24
35
|
* and each use reads `cache()`. The copy is made lazily, so a runtime pays only for the modules
|
|
25
36
|
* it touches.
|
|
26
|
-
*
|
|
27
|
-
* @param create Builds a fresh, empty copy. Called once per scope, and again after `reset`.
|
|
28
37
|
*/
|
|
29
38
|
export function scoped(create) {
|
|
30
39
|
const key = Symbol();
|
|
31
40
|
const read = () => {
|
|
32
|
-
|
|
33
|
-
if (!scope.has(key))
|
|
34
|
-
scope.set(key, create());
|
|
35
|
-
return scope.get(key);
|
|
41
|
+
return getOrCreate(currentScope(), key, create);
|
|
36
42
|
};
|
|
37
43
|
return Object.assign(read, {
|
|
38
44
|
reset: () => {
|
|
@@ -40,3 +46,24 @@ export function scoped(create) {
|
|
|
40
46
|
},
|
|
41
47
|
});
|
|
42
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Writes what a caller gave onto the settings in force, field by field, skipping what is unusable.
|
|
51
|
+
*
|
|
52
|
+
* @param held - The settings in force. Written to — the same object the module goes on reading.
|
|
53
|
+
* @param options - What to change. A field left out is left alone.
|
|
54
|
+
* @param [usable] - Whether a value may be written under a name.
|
|
55
|
+
* @returns A copy of everything in force afterwards, including what this call did not change.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* The body of every `configure*`: a module's settings are one object per runtime, read where they
|
|
59
|
+
* are used, so writing a field onto it is what makes the change apply from the next read. A field
|
|
60
|
+
* that fails its check keeps what it had, which is how a half-built config narrows nothing.
|
|
61
|
+
*/
|
|
62
|
+
export function assignSettings(held, options, usable = isPositive) {
|
|
63
|
+
for (const [name, value] of Object.entries(options)) {
|
|
64
|
+
if (usable(value, name)) {
|
|
65
|
+
held[name] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { ...held };
|
|
69
|
+
}
|
package/dist/side-task.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import OpenAI from
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { type OnNotice } from './capabilities.ts';
|
|
3
|
+
import type { Endpoint, EndpointIdentity } from './config.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The pairs that refused the hints, the live set, for `exportCapabilities` and
|
|
6
|
+
* `importCapabilities`.
|
|
7
|
+
*
|
|
8
|
+
* @returns The current scope's set itself and not a copy, each pair a
|
|
9
|
+
* `modelKey(endpointId, model)`. Adding to it stops the hints being sent to that pair from the
|
|
10
|
+
* next call.
|
|
11
|
+
*/
|
|
6
12
|
export declare const refusedHints: () => Set<string>;
|
|
7
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Test seam, alongside `resetClients` and `resetAll`: forget which models refused the hints.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The current scope's set is emptied in place, so a holder of it sees it empty.
|
|
18
|
+
*/
|
|
8
19
|
export declare const resetHints: () => void;
|
|
9
20
|
/**
|
|
10
21
|
* The input a side task applies its instruction to: text, or the content parts a vision model
|
|
11
22
|
* reads.
|
|
12
23
|
*
|
|
24
|
+
* @remarks
|
|
13
25
|
* A string is the ordinary case and stays the cheapest thing to write. The array is what an
|
|
14
26
|
* image needs, because a page, a screenshot or a photo reaches an OpenAI-compatible server only
|
|
15
27
|
* as an `image_url` part alongside the text — there is no other spelling for it, and a caller
|
|
@@ -21,16 +33,23 @@ export type SideTaskInput = string | OpenAI.ChatCompletionContentPart[];
|
|
|
21
33
|
/** What a side task may be given. All optional — one given none of them still runs. */
|
|
22
34
|
export interface SideTaskOptions {
|
|
23
35
|
/**
|
|
24
|
-
* Ceiling on the reply
|
|
25
|
-
*
|
|
36
|
+
* Ceiling on the reply. These answers are meant to be short. Zero or less sends none and leaves
|
|
37
|
+
* it to the server, which is what `maxTokens: 0` means on the main model too.
|
|
38
|
+
*
|
|
39
|
+
* @defaultValue `512`
|
|
26
40
|
*/
|
|
27
41
|
maxTokens?: number;
|
|
28
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Sampling temperature. Naming and classifying want the same answer twice.
|
|
44
|
+
*
|
|
45
|
+
* @defaultValue `0.3`
|
|
46
|
+
*/
|
|
29
47
|
temperature?: number;
|
|
30
48
|
/**
|
|
31
49
|
* A reasoning effort to ask for in place of the no-thinking hints, for a side task an operator
|
|
32
50
|
* has pointed at a model that should deliberate — a compaction summary is the usual one.
|
|
33
51
|
*
|
|
52
|
+
* @remarks
|
|
34
53
|
* Absent, `""` and `"off"` all keep the hints, because off is what they already ask for. Any
|
|
35
54
|
* other value is sent as `reasoning_effort`, stepped up by `effortFor` where the model has
|
|
36
55
|
* refused it by value, and `chat_template_kwargs` is left out of the request altogether.
|
|
@@ -41,6 +60,7 @@ export interface SideTaskOptions {
|
|
|
41
60
|
/**
|
|
42
61
|
* Told what was given up on, the same way `runTurn` and `negotiate` tell a caller.
|
|
43
62
|
*
|
|
63
|
+
* @remarks
|
|
44
64
|
* The one notice `ask` raises itself opens with the model's name, as `negotiate`'s do for the
|
|
45
65
|
* refusals that are the model's: what it announces is latched on the (endpoint, model) pair,
|
|
46
66
|
* so on a consumer reaching several models through one base URL the name is the only thing
|
|
@@ -50,11 +70,12 @@ export interface SideTaskOptions {
|
|
|
50
70
|
* console decides for its consumer where operator text goes — which a server embedding this
|
|
51
71
|
* cannot then route to its own logger, attach to the run it belongs to, or silence in tests.
|
|
52
72
|
*/
|
|
53
|
-
onNotice?:
|
|
73
|
+
onNotice?: OnNotice;
|
|
54
74
|
}
|
|
55
75
|
/**
|
|
56
76
|
* One side task's own settings, as a resolved agent spec carries them under `tasks.<key>`.
|
|
57
77
|
*
|
|
78
|
+
* @remarks
|
|
58
79
|
* Declared here rather than imported from `spec.ts`, whose `ResolvedTask` it matches field for
|
|
59
80
|
* field: the spec module is one nothing else in `src/` imports, and a host that is not on the spec
|
|
60
81
|
* can write one of these by hand. An absent setting is the side task's own default — 0.3, the
|
|
@@ -68,7 +89,11 @@ export interface SideTask {
|
|
|
68
89
|
endpoint: Endpoint;
|
|
69
90
|
/** The reply's ceiling. Absent is the entry point's default; zero sends none. */
|
|
70
91
|
maxTokens?: number;
|
|
71
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Sampling temperature, whatever the agent's own is. Zero means zero.
|
|
94
|
+
*
|
|
95
|
+
* @defaultValue `0.3`
|
|
96
|
+
*/
|
|
72
97
|
temperature?: number;
|
|
73
98
|
/** As `SideTaskOptions.reasoningEffort`: a level replaces the no-thinking hints. */
|
|
74
99
|
reasoningEffort?: string;
|
|
@@ -76,21 +101,29 @@ export interface SideTask {
|
|
|
76
101
|
/**
|
|
77
102
|
* Runs a side task and returns the reply text, thinking stripped. Throws like any request.
|
|
78
103
|
*
|
|
79
|
-
* @param config Where to send it and how long to wait.
|
|
80
|
-
* @param model The model to ask, usually smaller than the one running the work.
|
|
81
|
-
* @param system The instruction.
|
|
82
|
-
* @param user The input it applies to. Content parts where the model is being shown an image.
|
|
83
|
-
* @param options Reply ceiling, temperature, a reasoning effort, cancellation, notices.
|
|
104
|
+
* @param config - Where to send it and how long to wait.
|
|
105
|
+
* @param model - The model to ask, usually smaller than the one running the work.
|
|
106
|
+
* @param system - The instruction.
|
|
107
|
+
* @param user - The input it applies to. Content parts where the model is being shown an image.
|
|
108
|
+
* @param [options] - Reply ceiling, temperature, a reasoning effort, cancellation, notices.
|
|
109
|
+
* @returns The reply's content, trimmed. Where that is empty once the thinking is stripped, a
|
|
110
|
+
* `reasoning_content` the server sent beside it, stripped the same way, or an empty string.
|
|
84
111
|
*/
|
|
85
112
|
export declare function ask(config: Endpoint, model: string, system: string, user: SideTaskInput, options?: SideTaskOptions): Promise<string>;
|
|
86
113
|
/** What `askJson` takes besides a side task's options. */
|
|
87
114
|
export interface AskJsonOptions extends SideTaskOptions {
|
|
88
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* What the schema is called in the request. Letters, digits, `_` and `-`.
|
|
117
|
+
*
|
|
118
|
+
* @defaultValue `'answer'`
|
|
119
|
+
*/
|
|
89
120
|
name?: string;
|
|
90
121
|
/**
|
|
91
|
-
* Asks the server to hold the reply to the schema exactly
|
|
92
|
-
*
|
|
93
|
-
*
|
|
122
|
+
* Asks the server to hold the reply to the schema exactly. OpenAI's strict mode wants every
|
|
123
|
+
* property required and `additionalProperties: false`; a schema written otherwise wants this
|
|
124
|
+
* off there.
|
|
125
|
+
*
|
|
126
|
+
* @defaultValue `true`
|
|
94
127
|
*/
|
|
95
128
|
strict?: boolean;
|
|
96
129
|
}
|
|
@@ -98,41 +131,62 @@ export interface AskJsonOptions extends SideTaskOptions {
|
|
|
98
131
|
* A side task whose answer is JSON matching a schema, parsed. Undefined when no JSON came back.
|
|
99
132
|
* Throws like any request.
|
|
100
133
|
*
|
|
134
|
+
* @param config - Where to send it and how long to wait.
|
|
135
|
+
* @param model - The model to ask.
|
|
136
|
+
* @param system - The instruction. The schema is appended to it.
|
|
137
|
+
* @param user - The input it applies to. Content parts where the model is being shown an image.
|
|
138
|
+
* @param schema - The JSON Schema of the answer. Its root is held to an object, as a tool's is.
|
|
139
|
+
* @param [options] - A side task's options, plus the schema's `name` and whether it is `strict`.
|
|
140
|
+
* @returns What the reply parsed to, unchecked against the schema: `T` is the caller's claim.
|
|
141
|
+
* `undefined` when `parseJson` found nothing in it.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
101
144
|
* Sends `response_format` with the schema, which a llama.cpp server compiles into a grammar and
|
|
102
145
|
* vLLM, LM Studio, Ollama and OpenAI each hold the reply to, so a small model that wraps JSON in
|
|
103
146
|
* prose cannot. The schema is normalised as a tool's parameters are, and relaxed where the endpoint
|
|
104
147
|
* could not build a grammar, since the same converter reads both. A model that refuses the field
|
|
105
148
|
* latches it off and is asked in words: the schema rides on the system prompt either way, and
|
|
106
149
|
* the reply goes through `parseJson`, which finds the JSON in whatever came back.
|
|
107
|
-
*
|
|
108
|
-
* @param config Where to send it and how long to wait.
|
|
109
|
-
* @param model The model to ask.
|
|
110
|
-
* @param system The instruction. The schema is appended to it.
|
|
111
|
-
* @param user The input it applies to. Content parts where the model is being shown an image.
|
|
112
|
-
* @param schema The JSON Schema of the answer. Its root is held to an object, as a tool's is.
|
|
113
|
-
* @param options A side task's options, plus the schema's `name` and whether it is `strict`.
|
|
114
150
|
*/
|
|
115
151
|
export declare function askJson<T>(config: Endpoint, model: string, system: string, user: SideTaskInput, schema: Record<string, unknown>, { name, strict, ...options }?: AskJsonOptions): Promise<T | undefined>;
|
|
116
152
|
/**
|
|
153
|
+
* Runs a side task and answers `undefined` where it fails, so the work it supports carries on.
|
|
154
|
+
*
|
|
155
|
+
* @param label - Names the task in the notice when it fails.
|
|
156
|
+
* @param run - The call to attempt. Anything it throws becomes `undefined`, an abort excepted.
|
|
157
|
+
* @param [options] - `onNotice`, told what was given up on.
|
|
158
|
+
* @returns What `run` resolved with, or `undefined` when it threw. An `APIUserAbortError` is thrown
|
|
159
|
+
* on and raises no notice.
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
117
162
|
* A side task is never worth failing the work it supports. Callers that can carry on without
|
|
118
163
|
* an answer use this and get `undefined` instead of an exception.
|
|
119
|
-
*
|
|
120
|
-
* @param label Names the task in the notice when it fails.
|
|
121
|
-
* @param run The call to attempt. Anything it throws becomes `undefined`, an abort excepted.
|
|
122
|
-
* @param options `onNotice`, told what was given up on.
|
|
123
164
|
*/
|
|
124
|
-
export declare function tryAsk<T>(label: string, run: () => Promise<T>, { onNotice }?: Pick<SideTaskOptions,
|
|
165
|
+
export declare function tryAsk<T>(label: string, run: () => Promise<T>, { onNotice }?: Pick<SideTaskOptions, 'onNotice'>): Promise<T | undefined>;
|
|
125
166
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
167
|
+
* The first array or object in a model's reply, parsed, whatever prose or fence surrounds it.
|
|
168
|
+
*
|
|
169
|
+
* @param text - The reply, fences and prose included. Nothing parseable gives `undefined`.
|
|
170
|
+
* @returns What lies between the first `[` or `{` and the last `]` or `}`, parsed — inside the
|
|
171
|
+
* first fenced block where there is one. Unchecked: `T` is the caller's claim. `undefined` when
|
|
172
|
+
* there is no such stretch or it will not parse even repaired.
|
|
173
|
+
*
|
|
174
|
+
* @remarks
|
|
175
|
+
* Models are asked for JSON and often answer with prose around it, or a fenced block, and a
|
|
176
|
+
* wrapper is not worth failing the task over.
|
|
128
177
|
*
|
|
129
|
-
*
|
|
178
|
+
* What is pulled out is read the way a tool call's arguments are: as written where that parses,
|
|
179
|
+
* and otherwise with the almost-JSON a local model writes repaired — single quotes, `True` and
|
|
180
|
+
* `None`, bare keys, a trailing comma. A small model asked for a list gets these wrong as often in
|
|
181
|
+
* a reply as in a call, and a side task that fails over one costs the run a second request.
|
|
130
182
|
*/
|
|
131
183
|
export declare function parseJson<T>(text: string): T | undefined;
|
|
132
184
|
/**
|
|
133
185
|
* Strips the quoting and list punctuation models decorate short answers with.
|
|
134
186
|
*
|
|
135
|
-
* @param line One line of a reply.
|
|
187
|
+
* @param line - One line of a reply.
|
|
188
|
+
* @returns The line trimmed, without one leading bullet or number, any quotes or backticks at
|
|
189
|
+
* either end, or trailing full stops. Empty when nothing else was there.
|
|
136
190
|
*/
|
|
137
191
|
export declare const clean: (line: string) => string;
|
|
138
192
|
/**
|
|
@@ -140,8 +194,42 @@ export declare const clean: (line: string) => string;
|
|
|
140
194
|
* them with. Overlong items are dropped rather than truncated — a suggestion that has to be
|
|
141
195
|
* squinted at is worse than one fewer suggestion.
|
|
142
196
|
*
|
|
143
|
-
* @param text The reply, one item per line.
|
|
144
|
-
* @param max How many items to keep.
|
|
145
|
-
* @param maxChars Longest item kept. Longer ones are dropped, not truncated.
|
|
197
|
+
* @param text - The reply, one item per line.
|
|
198
|
+
* @param max - How many items to keep.
|
|
199
|
+
* @param maxChars - Longest item kept. Longer ones are dropped, not truncated.
|
|
200
|
+
* @returns The first `max` items that survive, in reply order. Lines that clean to nothing are not
|
|
201
|
+
* items, and an overlong one does not count towards `max`.
|
|
146
202
|
*/
|
|
147
203
|
export declare const listLines: (text: string, max: number, maxChars: number) => string[];
|
|
204
|
+
/**
|
|
205
|
+
* A side task's settings as the call that honours them: its endpoint, its model, and the options
|
|
206
|
+
* `ask`, `askJson`, `summariser` and `preselect` take last.
|
|
207
|
+
*
|
|
208
|
+
* @param task - The task, ordinarily `resolved.tasks.<key>`.
|
|
209
|
+
* @param [options] - What the host adds — cancellation, notices, `keywords` — and its own defaults
|
|
210
|
+
* for the settings a task may leave out.
|
|
211
|
+
* @param [agent] - The endpoint the main turn uses, key included. Absent sends the task's endpoint
|
|
212
|
+
* as it stands.
|
|
213
|
+
* @returns The three arguments a side-task entry point takes. `options` is a new object, and
|
|
214
|
+
* `endpoint` is the task's own object when no `agent` was given, a copy otherwise.
|
|
215
|
+
*
|
|
216
|
+
* @remarks
|
|
217
|
+
* A helper rather than a second signature on each of the four, so a setting added to a task later
|
|
218
|
+
* arrives through `options` without a host's call changing. What the task states wins over the
|
|
219
|
+
* same field in `options`: the host's code is written once and the task is what an operator
|
|
220
|
+
* configured over it, so a host passes its own ceiling as the value for a task that names none.
|
|
221
|
+
* A setting the task leaves out and `options` does too is absent from the result, which is what
|
|
222
|
+
* leaves it to the entry point's own default — 0.3, not the agent's temperature.
|
|
223
|
+
*
|
|
224
|
+
* A resolved spec carries no key, so a task on the agent's own endpoint would otherwise go out
|
|
225
|
+
* unkeyed, and be remembered under a second capability entry beside the agent's. Given `agent`,
|
|
226
|
+
* such a task is sent the agent's `baseUrl` as the agent spells it and, having no key of its own,
|
|
227
|
+
* the agent's key, so `capabilitiesFor` answers both with one object; a task on another endpoint
|
|
228
|
+
* is sent only a key of its own, as `resolveApiKey` has it. The environment is not read: the
|
|
229
|
+
* agent's key is whatever the main turn is sent.
|
|
230
|
+
*/
|
|
231
|
+
export declare function taskCall<Options extends SideTaskOptions = SideTaskOptions>(task: SideTask, options?: Options, agent?: EndpointIdentity): {
|
|
232
|
+
endpoint: Endpoint;
|
|
233
|
+
model: string;
|
|
234
|
+
options: Options;
|
|
235
|
+
};
|