@theoremjs/agents 0.3.4-next.679.gcdf1a3a → 0.3.4-next.711.g78e504a
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 +5 -4
- package/esm/mod.d.ts +6 -3
- package/esm/mod.js +3 -1
- package/esm/src/cli/commands/bench.js +4 -10
- package/esm/src/cli/commands/profile.js +4 -1
- package/esm/src/guardrails/labels.d.ts +1 -1
- package/esm/src/guardrails/labels.js +9 -0
- package/esm/src/interface/blocks.js +19 -0
- package/esm/src/interface/from-profile.d.ts +2 -2
- package/esm/src/interface/from-profile.js +7 -0
- package/esm/src/interface/history.d.ts +2 -2
- package/esm/src/interface/history.js +7 -4
- package/esm/src/interface/mod.d.ts +2 -2
- package/esm/src/interface/mod.js +1 -1
- package/esm/src/interface/profile-interface.js +14 -4
- package/esm/src/interface/tool-calls.d.ts +3 -3
- package/esm/src/interface/tool-calls.js +5 -8
- package/esm/src/interface/tool-invoke.d.ts +3 -1
- package/esm/src/interface/tool-invoke.js +6 -1
- package/esm/src/interface/types.d.ts +7 -5
- package/esm/src/kernel/api-catalog.js +13 -5
- package/esm/src/kernel/auth/oauth.js +3 -1
- package/esm/src/kernel/engine/background.d.ts +7 -0
- package/esm/src/kernel/engine/background.js +18 -0
- package/esm/src/kernel/engine/runner/mod.js +24 -1
- package/esm/src/kernel/engine/runner/state.d.ts +4 -0
- package/esm/src/kernel/engine/runner/state.js +1 -0
- package/esm/src/kernel/engine/runner/step-order.d.ts +8 -0
- package/esm/src/kernel/engine/runner/step-order.js +1 -1
- package/esm/src/kernel/engine/runner/steps.js +1 -0
- package/esm/src/kernel/engine/session/mod.d.ts +2 -0
- package/esm/src/kernel/engine/session/mod.js +20 -2
- package/esm/src/kernel/engine/session/session-trace.js +1 -0
- package/esm/src/kernel/mod.d.ts +6 -3
- package/esm/src/kernel/mod.js +3 -1
- package/esm/src/kernel/profile-presence.js +1 -0
- package/esm/src/kernel/profile-scope.js +23 -21
- package/esm/src/kernel/protocols/protocol.d.ts +1 -1
- package/esm/src/kernel/protocols/protocol.js +1 -0
- package/esm/src/kernel/registry/catalog.js +4 -1
- package/esm/src/kernel/registry/ingress.d.ts +3 -1
- package/esm/src/kernel/registry/ingress.js +12 -1
- package/esm/src/kernel/registry/profile-outputs.js +2 -1
- package/esm/src/kernel/registry/profiles.d.ts +12 -2
- package/esm/src/kernel/registry/profiles.js +37 -7
- package/esm/src/kernel/registry/resolve.js +9 -5
- package/esm/src/kernel/registry/system-prompt.d.ts +6 -1
- package/esm/src/kernel/registry/system-prompt.js +20 -13
- package/esm/src/kernel/schema.d.ts +1 -1
- package/esm/src/kernel/schema.js +24 -8
- package/esm/src/kernel/system-lines.d.ts +22 -0
- package/esm/src/kernel/system-lines.js +162 -0
- package/esm/src/kernel/tools/activity-label.d.ts +15 -0
- package/esm/src/kernel/tools/activity-label.js +12 -7
- package/esm/src/kernel/tools/agent.js +1 -1
- package/esm/src/kernel/tools/background.d.ts +81 -0
- package/esm/src/kernel/tools/background.js +70 -0
- package/esm/src/kernel/tools/call-order.d.ts +18 -0
- package/esm/src/kernel/tools/call-order.js +52 -0
- package/esm/src/kernel/tools/coordinate.d.ts +8 -1
- package/esm/src/kernel/tools/coordinate.js +274 -34
- package/esm/src/kernel/tools/execute.d.ts +2 -0
- package/esm/src/kernel/tools/execute.js +17 -4
- package/esm/src/kernel/tools/invoke.js +40 -13
- package/esm/src/kernel/tools/memory-execution.js +10 -1
- package/esm/src/kernel/tools/operation.d.ts +21 -0
- package/esm/src/kernel/tools/operation.js +19 -10
- package/esm/src/kernel/tools/registry.js +28 -6
- package/esm/src/kernel/tools/resolve.d.ts +4 -2
- package/esm/src/kernel/tools/resolve.js +34 -7
- package/esm/src/kernel/tools/run.d.ts +2 -2
- package/esm/src/kernel/tools/run.js +4 -1
- package/esm/src/kernel/tools/stage-run.d.ts +3 -1
- package/esm/src/kernel/tools/stage-run.js +58 -55
- package/esm/src/kernel/tools/types.d.ts +10 -0
- package/esm/src/kernel/turn-events.d.ts +8 -1
- package/esm/src/kernel/turn-events.js +2 -0
- package/esm/src/kernel/types.d.ts +39 -4
- package/esm/src/observability/trace-catalog.js +3 -0
- package/esm/src/providers/google/interactions/steps.js +14 -3
- package/esm/src/providers/mod.d.ts +2 -0
- package/esm/src/providers/mod.js +1 -0
- package/esm/src/providers/open-ai/protocol.js +8 -4
- package/esm/src/providers/openrouter/protocol.d.ts +26 -0
- package/esm/src/providers/openrouter/protocol.js +58 -2
- package/esm/src/providers/openrouter/provider.d.ts +1 -1
- package/esm/src/providers/openrouter/provider.js +3 -1
- package/esm/src/providers/openrouter/transcriptions-protocol.d.ts +10 -0
- package/esm/src/providers/openrouter/transcriptions-protocol.js +87 -0
- package/package.json +1 -1
- package/esm/src/kernel/registry/system-role.d.ts +0 -3
- package/esm/src/kernel/registry/system-role.js +0 -9
|
@@ -11,7 +11,7 @@ import { outOfScopeFields, profileKeysOf, profileTypesForField } from '../profil
|
|
|
11
11
|
import { checkBinding, decisionModelBindingSchema, modelBindingSchema, } from '../protocols/binding.js';
|
|
12
12
|
import { CONTEXT_SENDERS, IMAGE_ATTACHMENT_ACCEPT_MIMES, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, THINKING_LEVELS, } from '../schema.js';
|
|
13
13
|
import { isContinueStopKind } from '../stop.js';
|
|
14
|
-
import {
|
|
14
|
+
import { assertSystemLines, systemLinesProblem } from '../system-lines.js';
|
|
15
15
|
import { profileToolAllow, profileToolsSpec } from '../tools/resolve.js';
|
|
16
16
|
import { isTurnMediaRef } from './attachments.js';
|
|
17
17
|
import { mediaKindForMime, mimeAllowed, profileInputs } from './catalog.js';
|
|
@@ -40,6 +40,28 @@ function defineEmbeddingProfile(input) {
|
|
|
40
40
|
labels: input.labels,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
function defineTranscriptionProfile(input) {
|
|
44
|
+
assertModelsNonEmpty(input.id, input.models);
|
|
45
|
+
assertGuardrails(input.id, input.guardrails);
|
|
46
|
+
assertObservability(input.id, input.observability);
|
|
47
|
+
for (const [modelId, binding] of Object.entries(input.models))
|
|
48
|
+
assertModelBinding(input.id, modelId, binding);
|
|
49
|
+
if ('text' in input.inputs && input.inputs.text !== false) {
|
|
50
|
+
throw new TheoremError('config', `Profile ${input.id}: a transcription takes a voice clip, so inputs.text must be false`);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
type: 'transcription',
|
|
54
|
+
id: input.id,
|
|
55
|
+
identity: { handle: input.identity.handle },
|
|
56
|
+
...profileModelFields(input),
|
|
57
|
+
providerContinuation: undefined,
|
|
58
|
+
maxSteps: undefined,
|
|
59
|
+
inputs: { ...input.inputs, text: false },
|
|
60
|
+
guardrails: input.guardrails,
|
|
61
|
+
observability: input.observability,
|
|
62
|
+
labels: input.labels,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
43
65
|
function assertBindingData(profileId, modelId, binding, schema) {
|
|
44
66
|
const parsed = schema.safeParse(binding);
|
|
45
67
|
if (!parsed.success)
|
|
@@ -340,14 +362,19 @@ function assertIdentitySystem(input) {
|
|
|
340
362
|
if (input.type === 'host' ||
|
|
341
363
|
input.type === 'decision' ||
|
|
342
364
|
input.type === 'speech' ||
|
|
365
|
+
input.type === 'transcription' ||
|
|
343
366
|
input.type === 'embedding')
|
|
344
367
|
return;
|
|
345
|
-
const {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
assertSystemPrompt(prompt, `Profile ${input.id} identity.systemByRole.${role}`);
|
|
368
|
+
const { conditions, system } = input.identity;
|
|
369
|
+
const slots = {};
|
|
370
|
+
for (const [name, decl] of Object.entries(normalizeProfileInputsSlots(input.inputs)?.slots ?? {})) {
|
|
371
|
+
slots[name] = slotValues(decl);
|
|
350
372
|
}
|
|
373
|
+
const prompt = system ?? '';
|
|
374
|
+
assertSystemLines(prompt, `Profile ${input.id} identity.system`);
|
|
375
|
+
const problem = systemLinesProblem(prompt, conditions, slots);
|
|
376
|
+
if (problem)
|
|
377
|
+
throw new TheoremError('config', `Profile ${input.id} identity.system: ${problem}`); // labels-exempt: developer contract error
|
|
351
378
|
}
|
|
352
379
|
/** Validate any definition and return the profile. */
|
|
353
380
|
function defineProfile(input) {
|
|
@@ -377,6 +404,9 @@ function defineProfile(input) {
|
|
|
377
404
|
if (input.type === 'embedding') {
|
|
378
405
|
return defineEmbeddingProfile(input);
|
|
379
406
|
}
|
|
407
|
+
if (input.type === 'transcription') {
|
|
408
|
+
return defineTranscriptionProfile(input);
|
|
409
|
+
}
|
|
380
410
|
assertModelsNonEmpty(input.id, input.models);
|
|
381
411
|
assertTurnBehaviour(input.id, input);
|
|
382
412
|
assertGuardrails(input.id, input.guardrails);
|
|
@@ -390,8 +420,8 @@ function defineProfile(input) {
|
|
|
390
420
|
? { handle: input.identity.handle }
|
|
391
421
|
: {
|
|
392
422
|
handle: input.identity.handle,
|
|
423
|
+
conditions: input.identity.conditions,
|
|
393
424
|
system: input.identity.system,
|
|
394
|
-
systemByRole: input.identity.systemByRole,
|
|
395
425
|
};
|
|
396
426
|
const guardrails = input.guardrails;
|
|
397
427
|
const observability = input.observability;
|
|
@@ -11,8 +11,8 @@ import { profileTurnResumption } from '../stop.js';
|
|
|
11
11
|
import { projectTools } from '../tools/project.js';
|
|
12
12
|
import { resolveTurnTools } from '../tools/resolve.js';
|
|
13
13
|
import { profileInputs, requireModelBinding } from './catalog.js';
|
|
14
|
-
import { assertOutputMode, assertSpeechRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, } from './ingress.js';
|
|
15
|
-
import {
|
|
14
|
+
import { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, assertTurnSlots, resolveImageFormat, resolveInputParts, resolveSpeech, } from './ingress.js';
|
|
15
|
+
import { resolveTurnSystem } from './system-prompt.js';
|
|
16
16
|
function isModelProfile(profile) {
|
|
17
17
|
return profile.type !== 'host' && profile.type !== 'decision' && profile.type !== 'embedding';
|
|
18
18
|
}
|
|
@@ -136,11 +136,12 @@ function resolveLiveSpec(live, guardrails) {
|
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* A canary for the turn while `canary_leak` reads somewhere, else none. Speech
|
|
139
|
-
*
|
|
139
|
+
* and transcription have no system prompt to plant one in.
|
|
140
140
|
*/
|
|
141
141
|
function plantedCanary(profile) {
|
|
142
142
|
const { detect } = resolveGuardrailPolicy(profile.guardrails);
|
|
143
|
-
|
|
143
|
+
const noPrompt = profile.type === 'speech' || profile.type === 'transcription';
|
|
144
|
+
return !noPrompt && detects(detect, 'canary_leak') ? mintCanary() : '';
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
146
147
|
* The request's `builtInArgs`. Args must name a tool the chosen model lists; the protocol that
|
|
@@ -177,10 +178,12 @@ function resolveTurnInRegistry(registry, req, model) {
|
|
|
177
178
|
throw new TheoremError('config', `Profile ${profile.id}: a structured turn answers through '${ANSWER_TOOL}', so no tool of its own may take that name`);
|
|
178
179
|
}
|
|
179
180
|
assertSpeechRole(profile, safe);
|
|
181
|
+
assertTranscriptionRole(profile, safe);
|
|
180
182
|
const builtInArgs = resolveBuiltInArgs(profile, picked, binding, safe.builtInArgs);
|
|
181
183
|
const transport = resolveTransport(profile, binding);
|
|
182
184
|
const provider = registry.providers.get(binding.provider);
|
|
183
185
|
const operationName = provider && operationNameOf(provider, binding, profile.type);
|
|
186
|
+
const system = resolveTurnSystem(profile, safe);
|
|
184
187
|
return {
|
|
185
188
|
profile,
|
|
186
189
|
generation: {
|
|
@@ -210,7 +213,8 @@ function resolveTurnInRegistry(registry, req, model) {
|
|
|
210
213
|
live: profile.type === 'live' ? resolveLiveSpec(profile.live, profile.guardrails) : undefined,
|
|
211
214
|
input: resolveInputParts(profile, safe),
|
|
212
215
|
canary: plantedCanary(profile),
|
|
213
|
-
resolvedSystem:
|
|
216
|
+
resolvedSystem: system.pieces,
|
|
217
|
+
systemLines: system.lines,
|
|
214
218
|
host: safe.host,
|
|
215
219
|
},
|
|
216
220
|
};
|
|
@@ -4,5 +4,10 @@ import type { ModelProfile, SystemPiece, TurnRequest } from '../types.js';
|
|
|
4
4
|
* keeps its own marks: a `{ private }` part in `req.system` leaves the
|
|
5
5
|
* profile's prompt as private as it was written.
|
|
6
6
|
*/
|
|
7
|
+
declare function resolveTurnSystem(profile: ModelProfile, req: TurnRequest): {
|
|
8
|
+
pieces: SystemPiece[];
|
|
9
|
+
lines: number[];
|
|
10
|
+
};
|
|
11
|
+
/** The whole prompt a turn sends, for what reads it outside a turn. */
|
|
7
12
|
declare function resolveTurnSystemPrompt(profile: ModelProfile, req: TurnRequest): SystemPiece[];
|
|
8
|
-
export { resolveTurnSystemPrompt };
|
|
13
|
+
export { resolveTurnSystem, resolveTurnSystemPrompt };
|
|
@@ -1,32 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pickSystemLines, turnFacts } from '../system-lines.js';
|
|
2
|
+
import { joinSystemPieces, systemPieces } from '../system-parts.js';
|
|
2
3
|
import { fillSlots } from './slot-fill.js';
|
|
3
|
-
import { pickSystemRole } from './system-role.js';
|
|
4
4
|
/**
|
|
5
5
|
* `identity.system` is trusted author-time copy and crosses no boundary: no detector reads it.
|
|
6
6
|
* A `{slot}` in it becomes the value the request chose, which is one the profile lists.
|
|
7
7
|
* `req.system` is `assembled` per turn and is read at the `system` boundary.
|
|
8
8
|
*/
|
|
9
|
-
function systemFromProfile(profile,
|
|
10
|
-
if (profile.type === 'speech') {
|
|
9
|
+
function systemFromProfile(profile, slots, req) {
|
|
10
|
+
if (profile.type === 'speech' || profile.type === 'transcription') {
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
const prompt = systemByRole?.[role] || system || '';
|
|
13
|
+
const prompt = profile.identity.system;
|
|
15
14
|
if (!prompt) {
|
|
16
15
|
return [];
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
const facts = turnFacts(profile.id, profile.identity.conditions, req, slots);
|
|
18
|
+
return pickSystemLines(prompt, facts, (text) => fillSlots(profile, text, slots, 'identity.system'));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Synchronous: snapshotted in `resolveTurn` before any async work. Each source
|
|
22
22
|
* keeps its own marks: a `{ private }` part in `req.system` leaves the
|
|
23
23
|
* profile's prompt as private as it was written.
|
|
24
24
|
*/
|
|
25
|
+
function resolveTurnSystem(profile, req) {
|
|
26
|
+
const kept = systemFromProfile(profile, req.input?.slots, req);
|
|
27
|
+
return {
|
|
28
|
+
pieces: joinSystemPieces([
|
|
29
|
+
...kept.map(({ pieces }) => pieces),
|
|
30
|
+
req.system === undefined ? [] : systemPieces(req.system),
|
|
31
|
+
]),
|
|
32
|
+
lines: kept.map(({ line }) => line),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The whole prompt a turn sends, for what reads it outside a turn. */
|
|
25
36
|
function resolveTurnSystemPrompt(profile, req) {
|
|
26
|
-
|
|
27
|
-
return joinSystemPieces([
|
|
28
|
-
systemFromProfile(profile, role, req.input?.slots),
|
|
29
|
-
req.system === undefined ? [] : systemPieces(req.system),
|
|
30
|
-
]);
|
|
37
|
+
return resolveTurnSystem(profile, req).pieces;
|
|
31
38
|
}
|
|
32
|
-
export { resolveTurnSystemPrompt };
|
|
39
|
+
export { resolveTurnSystem, resolveTurnSystemPrompt };
|
|
@@ -8,7 +8,7 @@ import "../../_dnt.polyfills.js";
|
|
|
8
8
|
import { BLOCKED_REPLY_ON_BLOCK, type BlockedReplyOnBlock } from '../guardrails/types.js';
|
|
9
9
|
export { BLOCKED_REPLY_ON_BLOCK, type BlockedReplyOnBlock };
|
|
10
10
|
/** The kinds of profile: each fixes which fields and models a profile may use. */
|
|
11
|
-
export declare const PROFILE_TYPES: readonly ["text", "image", "speech", "live", "decision", "embedding", "host"];
|
|
11
|
+
export declare const PROFILE_TYPES: readonly ["text", "image", "speech", "transcription", "live", "decision", "embedding", "host"];
|
|
12
12
|
/** One of {@linkcode PROFILE_TYPES}. */
|
|
13
13
|
export type ProfileType = (typeof PROFILE_TYPES)[number];
|
|
14
14
|
/** Reasoning effort levels, lowest to highest; a model accepts only the levels its catalog row lists. */
|
package/esm/src/kernel/schema.js
CHANGED
|
@@ -17,6 +17,7 @@ export const PROFILE_TYPES = [
|
|
|
17
17
|
'text',
|
|
18
18
|
'image',
|
|
19
19
|
'speech',
|
|
20
|
+
'transcription',
|
|
20
21
|
'live',
|
|
21
22
|
'decision',
|
|
22
23
|
'embedding',
|
|
@@ -276,7 +277,6 @@ function field(type, doc, options, optionDescriptionsOrNote, optionNote) {
|
|
|
276
277
|
export const DYNAMIC_FIELD_PARENTS = new Set([
|
|
277
278
|
'models',
|
|
278
279
|
'models.*.efforts',
|
|
279
|
-
'identity.systemByRole',
|
|
280
280
|
'labels',
|
|
281
281
|
'inputs.slots',
|
|
282
282
|
'inputs.limitsByMime',
|
|
@@ -494,20 +494,20 @@ function withScopeAndPresence(fields) {
|
|
|
494
494
|
*/
|
|
495
495
|
export const PROFILE_FIELDS = withScopeAndPresence({
|
|
496
496
|
'profile.id': field('string', 'The name this profile is registered and looked up by, at most 64 characters; registering the same id again replaces it.'),
|
|
497
|
-
'profile.type': field("'text' | 'image' | 'speech' | 'live' | 'decision' | 'embedding' | 'host'", 'What kind of agent this is, and so what each call gives back: text, image, speech, live, decision, embedding, or host.', PROFILE_TYPES, {
|
|
497
|
+
'profile.type': field("'text' | 'image' | 'speech' | 'transcription' | 'live' | 'decision' | 'embedding' | 'host'", 'What kind of agent this is, and so what each call gives back: text, image, speech, transcription, live, decision, embedding, or host.', PROFILE_TYPES, {
|
|
498
498
|
text: 'A chat or task agent. Each turn the model answers in text, or in JSON when outputs ask for a structured reply, and can call tools on the way.',
|
|
499
499
|
image: 'Makes pictures from a prompt, in the shape, size, and format the image block sets.',
|
|
500
500
|
speech: 'Gives your app a voice. Each turn reads text aloud in the voice the speech block names.',
|
|
501
|
+
transcription: 'Turns a voice clip into text. Each turn takes one clip and gives back what was said.',
|
|
501
502
|
live: 'For talking in real time. One continuous voice and video session, rather than separate turns.',
|
|
502
503
|
decision: 'For when your app needs a judgement, not a reply. It answers questions about a JSON state, each with a choice, a score, or a number.',
|
|
503
504
|
embedding: 'For when your app needs vectors from text or provider-supported media.',
|
|
504
505
|
host: 'A governed passthrough to your tool registry, with no model. It calls MCP, HTTP, and in-app function tools under the same permissions and traces as any agent, guarded by detect and network.',
|
|
505
506
|
}),
|
|
506
|
-
identity: field('{ handle,
|
|
507
|
-
'identity.handle': field('string', 'The name hosts and users see for this agent, at most 32 characters; the model never sees it.
|
|
508
|
-
'identity.
|
|
509
|
-
'identity.
|
|
510
|
-
'identity.systemByRole.*': field('string | Array<string | { private: string }>', 'The instruction that replaces identity.system when a turn names this role.'),
|
|
507
|
+
identity: field('{ handle, conditions?, system? }', "The agent's display name and the system instruction it is given."),
|
|
508
|
+
'identity.handle': field('string', 'The name hosts and users see for this agent, at most 32 characters; the model never sees it.'),
|
|
509
|
+
'identity.conditions': field('Record<string, string[]>', 'The facts every turn states, by name, with the values each can take. A line of identity.system reads them as "when plan is free: …". A condition named path reads the turn\'s path.'),
|
|
510
|
+
'identity.system': field('string | Array<string | Array<string | { private: string }>>', 'The instruction the model gets, as one string or a list of lines; some providers send it for an image profile only with includeText on. A line that opens "when plan is free: …" goes only on turns where that fits, and every line that fits is sent, a blank line apart. A line can be a list of parts; mark what must not leak as { private: text }; only that is guarded. With none, the whole prompt is.'),
|
|
511
511
|
models: field('Record<ModelId, ModelBinding | DecisionModelBinding>', 'The trained AI systems that turn input into results. Each entry binds a local name to an upstream model and its call settings.'),
|
|
512
512
|
'models.*': field('ModelBinding | DecisionModelBinding', 'One model: how to reach it and the settings sent with it.'),
|
|
513
513
|
'models.*.protocol': field('string', 'The API shape this model is spoken to in.'),
|
|
@@ -578,7 +578,7 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
578
578
|
'inputs.text': field('boolean', 'Whether a turn may send text.'),
|
|
579
579
|
'inputs.attachments': field('{ accept: string[] }', 'Lets turns send files.'),
|
|
580
580
|
'inputs.attachments.accept': field('string[]', 'The file types a turn may send, where type/* matches a whole family; image profiles take only images, video, and PDF.', ATTACHMENT_ACCEPT_MIMES, "Types the kernel knows; a listed type it doesn't know is refused when a turn sends it."),
|
|
581
|
-
'inputs.voice': field('{ accept: string[] }', 'Lets turns send voice clips.'),
|
|
581
|
+
'inputs.voice': field('{ accept: string[] }', 'Lets turns send voice clips. A transcription profile must set it.'),
|
|
582
582
|
'inputs.voice.accept': field('string[]', 'The audio types a voice clip may be; audio/* matches them all.', VOICE_ACCEPT_MIMES, 'Audio types the kernel knows.'),
|
|
583
583
|
'inputs.maxFiles': field('number', 'The most files and voice clips one turn or embedding request may send, counted together.'),
|
|
584
584
|
'inputs.maxBytes': field('number', 'The largest file or clip, in bytes, a turn or embedding request may send inline.'),
|
|
@@ -887,6 +887,22 @@ export const EXTRA_FIELDS = {
|
|
|
887
887
|
session_consent: 'Asks once; the approval lasts as long as the host keeps passing it back.',
|
|
888
888
|
always_confirm: 'Asks every time.',
|
|
889
889
|
}),
|
|
890
|
+
'registerTool.after': {
|
|
891
|
+
...field('boolean', 'Gives the model an after field on this tool: the tools called in the same step that must settle before this call starts. The kernel removes the field before the tool, the stages or a gate read the input. A name with no other call in the step fails the call wait_unknown.'),
|
|
892
|
+
unset: 'The model sets no order',
|
|
893
|
+
},
|
|
894
|
+
'registerTool.background': {
|
|
895
|
+
...field("'always' | { afterMs: number } | 'ask' | 'never'", "When the model gets its reply while the body goes on. 'always': at the hand-off. { afterMs }: once the body has run past this time. 'ask': at the hand-off if the model sets the background argument. A turn with no background service runs the tool inline."),
|
|
896
|
+
options: ['never', 'ask', 'always', 'afterMs'],
|
|
897
|
+
optionDescriptions: {
|
|
898
|
+
never: 'The model gets its reply when the body ends.',
|
|
899
|
+
ask: 'The model chooses, call by call, whether to go on without the result.',
|
|
900
|
+
always: 'The model gets its reply at once, and the body goes on after the turn.',
|
|
901
|
+
afterMs: 'The model gets its reply once the body has run past this time.',
|
|
902
|
+
},
|
|
903
|
+
unset: "'never': the model gets its reply when the body ends",
|
|
904
|
+
},
|
|
905
|
+
'registerTool.background.afterMs': field('number', 'Milliseconds the body runs before the model gets its reply. A body that ends sooner answers in the turn.'),
|
|
890
906
|
'registerTool.category': field('string', 'A label for grouping tools; nothing reads it yet.'),
|
|
891
907
|
'registerTool.labels': field('ToolLabels', "Transcript text for a call. {path} reads a value from the call. {results.0.name} reads a list item. {path|text} shows the text when the value is unusable. {count hit|hits} shows a number with the word for one or for any other number: '1 hit', '3 hits'. With no fallback, the label is dropped. A label is one line, or a list read top to bottom: the first line that fits is shown. A line fits when each {path} has a value and its condition holds, as in 'when status is archived: archiving {title}'. Neighbouring lines that open with '+ ' show together, joined in words. The last line of a list must always fit."),
|
|
892
908
|
'registerTool.labels.activity': {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProfileConditions, ProfileSystem, SystemPiece, TurnRequest } from './types.js';
|
|
2
|
+
/** What is wrong with a prompt's conditions and lines, or undefined. */
|
|
3
|
+
export declare function systemLinesProblem(prompt: ProfileSystem, conditions: ProfileConditions | undefined, slots: Record<string, readonly string[]>): string | undefined;
|
|
4
|
+
/** The facts a turn's `when` reads, once the turn has stated every condition with a listed value. */
|
|
5
|
+
export declare function turnFacts(id: string, conditions: ProfileConditions | undefined, req: Pick<TurnRequest, 'path' | 'conditions'>, slots: Record<string, string> | undefined): Record<string, string>;
|
|
6
|
+
/** A line that fit a turn: its number in the prompt as written, from 1, and its pieces. */
|
|
7
|
+
export type KeptSystemLine = {
|
|
8
|
+
line: number;
|
|
9
|
+
pieces: SystemPiece[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Every line that fits. Whether plain text is shareable is settled on the prompt as written, so a
|
|
13
|
+
* line dropped on this turn never changes the marks of one that stayed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function pickSystemLines(prompt: ProfileSystem, facts: Record<string, string>, fill: (text: string) => string): KeptSystemLine[];
|
|
16
|
+
/** `where` names the prompt in the error. A bare `{ private }` must sit inside a line's own list. */
|
|
17
|
+
export declare function assertSystemLines(prompt: unknown, where: string): asserts prompt is ProfileSystem;
|
|
18
|
+
/** The first tool in `tools` with a path `conditions.path` does not list, as a sentence. */
|
|
19
|
+
export declare function toolPathProblem(conditions: ProfileConditions | undefined, tools: readonly {
|
|
20
|
+
name: string;
|
|
21
|
+
paths?: readonly string[];
|
|
22
|
+
}[]): string | undefined;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
2
|
+
import { assertSystemPrompt } from './system-parts.js';
|
|
3
|
+
import { checkHolds, checkProblem, splitWhen } from './tools/activity-label.js';
|
|
4
|
+
const CONDITION_NAME = /^[A-Za-z_][\w-]*$/;
|
|
5
|
+
const CONDITION_VALUE = /^\S+$/;
|
|
6
|
+
function linesOf(prompt) {
|
|
7
|
+
if (typeof prompt === 'string')
|
|
8
|
+
return [[prompt]];
|
|
9
|
+
return prompt.map((line) => (typeof line === 'string' ? [line] : line));
|
|
10
|
+
}
|
|
11
|
+
function textOf(part) {
|
|
12
|
+
return typeof part === 'string' ? part : part.private;
|
|
13
|
+
}
|
|
14
|
+
function headOf(parts) {
|
|
15
|
+
return splitWhen(parts[0] === undefined ? '' : textOf(parts[0]));
|
|
16
|
+
}
|
|
17
|
+
function factsSchema(conditions, slots) {
|
|
18
|
+
const properties = {};
|
|
19
|
+
for (const [name, values] of Object.entries({ ...conditions, ...slots })) {
|
|
20
|
+
properties[name] = { type: 'string', enum: [...values] };
|
|
21
|
+
}
|
|
22
|
+
return { type: 'object', properties };
|
|
23
|
+
}
|
|
24
|
+
function conditionsProblem(conditions, slots) {
|
|
25
|
+
for (const [name, values] of Object.entries(conditions ?? {})) {
|
|
26
|
+
if (!CONDITION_NAME.test(name))
|
|
27
|
+
return `Condition "${name}" needs a plain name.`; // labels-exempt: developer contract error
|
|
28
|
+
if (name === 'input' || name === 'output')
|
|
29
|
+
return `Condition "${name}" is a reserved name.`; // labels-exempt: developer contract error
|
|
30
|
+
if (Object.hasOwn(slots, name))
|
|
31
|
+
return `"${name}" is both a condition and a slot.`; // labels-exempt: developer contract error
|
|
32
|
+
if (values.length === 0)
|
|
33
|
+
return `Condition "${name}" lists no values.`; // labels-exempt: developer contract error
|
|
34
|
+
const bad = values.find((value) => !CONDITION_VALUE.test(value) || value === 'null');
|
|
35
|
+
if (bad !== undefined)
|
|
36
|
+
return `Condition "${name}" can't take the value "${bad}".`; // labels-exempt: developer contract error
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function lineProblem(parts, schema) {
|
|
41
|
+
if (parts.length === 0)
|
|
42
|
+
return 'It has no wording to send.'; // labels-exempt: developer contract error
|
|
43
|
+
const line = headOf(parts);
|
|
44
|
+
if (line.joined)
|
|
45
|
+
return 'A prompt line can\'t start with "+"; every line that fits is sent.'; // labels-exempt: developer contract error
|
|
46
|
+
if (line.when === 'unreadable') {
|
|
47
|
+
return 'A line that opens with "when" needs a condition and a colon, like "when path is web: …".'; // labels-exempt: developer contract error
|
|
48
|
+
}
|
|
49
|
+
for (const check of line.when) {
|
|
50
|
+
if (check.path.includes('.'))
|
|
51
|
+
return `"${check.path}" isn't one condition or slot.`; // labels-exempt: developer contract error
|
|
52
|
+
if (check.expected === null)
|
|
53
|
+
return 'A condition always has a value, so "is null" never fits.'; // labels-exempt: developer contract error
|
|
54
|
+
const problem = checkProblem(check, schema, 'this profile’s conditions or slots');
|
|
55
|
+
if (problem)
|
|
56
|
+
return problem;
|
|
57
|
+
}
|
|
58
|
+
if (line.when.length > 0 && !line.text && parts.length === 1) {
|
|
59
|
+
return 'It has no wording to send.'; // labels-exempt: developer contract error
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/** What is wrong with a prompt's conditions and lines, or undefined. */
|
|
64
|
+
export function systemLinesProblem(prompt, conditions, slots) {
|
|
65
|
+
const declared = conditionsProblem(conditions, slots);
|
|
66
|
+
if (declared)
|
|
67
|
+
return declared;
|
|
68
|
+
const schema = factsSchema(conditions, slots);
|
|
69
|
+
for (const [at, parts] of linesOf(prompt).entries()) {
|
|
70
|
+
const problem = lineProblem(parts, schema);
|
|
71
|
+
if (problem)
|
|
72
|
+
return `Line ${at + 1}: ${problem}`;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
/** The facts a turn's `when` reads, once the turn has stated every condition with a listed value. */
|
|
77
|
+
export function turnFacts(id, conditions, req, slots) {
|
|
78
|
+
const stated = req.conditions ?? {};
|
|
79
|
+
if (conditions === undefined) {
|
|
80
|
+
if (req.conditions)
|
|
81
|
+
throw new TheoremError('request', `Profile ${id} declares no conditions`); // labels-exempt: developer contract error
|
|
82
|
+
return { ...slots };
|
|
83
|
+
}
|
|
84
|
+
if (Object.hasOwn(stated, 'path')) {
|
|
85
|
+
throw new TheoremError('request', `Profile ${id}: the turn's own path states path`); // labels-exempt: developer contract error
|
|
86
|
+
}
|
|
87
|
+
for (const name of Object.keys(stated)) {
|
|
88
|
+
if (!Object.hasOwn(conditions, name)) {
|
|
89
|
+
throw new TheoremError('request', `Profile ${id} has no condition '${name}'`); // labels-exempt: developer contract error
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const facts = { ...slots };
|
|
93
|
+
for (const [name, values] of Object.entries(conditions)) {
|
|
94
|
+
const value = name === 'path' ? req.path : stated[name];
|
|
95
|
+
if (value === undefined) {
|
|
96
|
+
throw new TheoremError('request', `Profile ${id}: the turn left condition '${name}' unset`); // labels-exempt: developer contract error
|
|
97
|
+
}
|
|
98
|
+
if (!values.includes(value)) {
|
|
99
|
+
throw new TheoremError('request', `Profile ${id}: '${value}' is no value of condition '${name}'`);
|
|
100
|
+
}
|
|
101
|
+
facts[name] = value;
|
|
102
|
+
}
|
|
103
|
+
return facts;
|
|
104
|
+
}
|
|
105
|
+
function lineFits(line, facts) {
|
|
106
|
+
if (line.when === 'unreadable')
|
|
107
|
+
return false;
|
|
108
|
+
return line.when.every((check) => checkHolds(check, facts));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Every line that fits. Whether plain text is shareable is settled on the prompt as written, so a
|
|
112
|
+
* line dropped on this turn never changes the marks of one that stayed.
|
|
113
|
+
*/
|
|
114
|
+
export function pickSystemLines(prompt, facts, fill) {
|
|
115
|
+
const lines = linesOf(prompt);
|
|
116
|
+
const marked = lines.flat().some((part) => typeof part !== 'string');
|
|
117
|
+
const kept = [];
|
|
118
|
+
for (const [at, parts] of lines.entries()) {
|
|
119
|
+
const line = headOf(parts);
|
|
120
|
+
if (!lineFits(line, facts))
|
|
121
|
+
continue;
|
|
122
|
+
const pieces = [];
|
|
123
|
+
for (const [partAt, part] of parts.entries()) {
|
|
124
|
+
const text = fill(partAt === 0 ? line.text : textOf(part));
|
|
125
|
+
if (text)
|
|
126
|
+
pieces.push({ text, private: typeof part === 'string' ? !marked : true });
|
|
127
|
+
}
|
|
128
|
+
kept.push({ line: at + 1, pieces });
|
|
129
|
+
}
|
|
130
|
+
return kept;
|
|
131
|
+
}
|
|
132
|
+
/** `where` names the prompt in the error. A bare `{ private }` must sit inside a line's own list. */
|
|
133
|
+
export function assertSystemLines(prompt, where) {
|
|
134
|
+
if (typeof prompt === 'string')
|
|
135
|
+
return;
|
|
136
|
+
if (!Array.isArray(prompt)) {
|
|
137
|
+
throw new TheoremError('config', `${where} must be a string or an array of lines`); // labels-exempt: developer contract error
|
|
138
|
+
}
|
|
139
|
+
if (prompt.length === 0)
|
|
140
|
+
throw new TheoremError('config', `${where} must not be an empty array`); // labels-exempt: developer contract error
|
|
141
|
+
for (const [at, line] of prompt.entries()) {
|
|
142
|
+
if (typeof line === 'string')
|
|
143
|
+
continue;
|
|
144
|
+
if (!Array.isArray(line)) {
|
|
145
|
+
throw new TheoremError('config', `${where}[${at}] must be a string or a list of parts; put { private } inside the list`);
|
|
146
|
+
}
|
|
147
|
+
assertSystemPrompt(line, `${where}[${at}]`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** The first tool in `tools` with a path `conditions.path` does not list, as a sentence. */
|
|
151
|
+
export function toolPathProblem(conditions, tools) {
|
|
152
|
+
const known = conditions?.path;
|
|
153
|
+
if (!known)
|
|
154
|
+
return undefined;
|
|
155
|
+
for (const tool of tools) {
|
|
156
|
+
const bad = tool.paths?.find((path) => path !== '*' && !known.includes(path));
|
|
157
|
+
if (bad !== undefined) {
|
|
158
|
+
return `Tool ${tool.name} lists path "${bad}", which is not one of ${known.join(', ')}.`; // labels-exempt: developer contract error
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/** One line of wording, or a list of lines read top to bottom: the first that fits is shown. */
|
|
2
2
|
export type LabelTemplate = string | readonly string[];
|
|
3
|
+
/** `expected: null` is the check "is null". */
|
|
4
|
+
export type Check = {
|
|
5
|
+
path: string;
|
|
6
|
+
negated: boolean;
|
|
7
|
+
expected: string | null;
|
|
8
|
+
};
|
|
9
|
+
export type Line = {
|
|
10
|
+
joined: boolean;
|
|
11
|
+
when: Check[] | 'unreadable';
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
/** A line's head, with its text exactly as written after the condition. */
|
|
15
|
+
export declare function splitWhen(raw: string): Line;
|
|
16
|
+
export declare function checkHolds(check: Check, input: unknown): boolean;
|
|
3
17
|
/** A tool's name as a label shows it: `manage_alert` reads "manage alert". */
|
|
4
18
|
export declare function toolNameInWords(name: string): string;
|
|
5
19
|
/**
|
|
@@ -13,6 +27,7 @@ export declare function fillActivityLabel(template: LabelTemplate | undefined, v
|
|
|
13
27
|
input: unknown;
|
|
14
28
|
output?: unknown;
|
|
15
29
|
}): string | undefined;
|
|
30
|
+
export declare function checkProblem(check: Check, input: unknown, reads?: string): string | undefined;
|
|
16
31
|
export declare function activityLabelProblem(template: LabelTemplate, schemas: {
|
|
17
32
|
input: unknown;
|
|
18
33
|
output?: unknown;
|
|
@@ -91,16 +91,21 @@ function parseChecks(raw) {
|
|
|
91
91
|
}
|
|
92
92
|
return checks;
|
|
93
93
|
}
|
|
94
|
-
/**
|
|
95
|
-
function
|
|
94
|
+
/** A line's head, with its text exactly as written after the condition. */
|
|
95
|
+
export function splitWhen(raw) {
|
|
96
96
|
const joined = JOINED.test(raw);
|
|
97
|
-
const rest = raw.replace(JOINED, '').
|
|
97
|
+
const rest = raw.replace(JOINED, '').trimStart();
|
|
98
98
|
if (!/^when(\s|$)/.test(rest))
|
|
99
99
|
return { joined, when: [], text: rest };
|
|
100
100
|
const end = rest.search(WHEN_ENDS);
|
|
101
101
|
if (end < 0)
|
|
102
102
|
return { joined, when: 'unreadable', text: '' };
|
|
103
|
-
return { joined, when: parseChecks(rest.slice(4, end)), text: rest.slice(end + 1).
|
|
103
|
+
return { joined, when: parseChecks(rest.slice(4, end)), text: rest.slice(end + 1).trimStart() };
|
|
104
|
+
}
|
|
105
|
+
/** `+ when status is archived: archiving {name}` is a joined line, with one check, then its text. */
|
|
106
|
+
function parseLine(raw) {
|
|
107
|
+
const line = splitWhen(raw);
|
|
108
|
+
return { ...line, text: line.text.trim() };
|
|
104
109
|
}
|
|
105
110
|
function entriesOf(template) {
|
|
106
111
|
const raw = typeof template === 'string' ? [template] : template;
|
|
@@ -121,7 +126,7 @@ function checkKeys(path) {
|
|
|
121
126
|
return route?.side === 'input' ? route.keys : undefined;
|
|
122
127
|
}
|
|
123
128
|
// why: "is not" is the plain opposite of "is", so a field the model left out is not any value.
|
|
124
|
-
function checkHolds(check, input) {
|
|
129
|
+
export function checkHolds(check, input) {
|
|
125
130
|
const keys = checkKeys(check.path);
|
|
126
131
|
if (!keys)
|
|
127
132
|
return false;
|
|
@@ -384,7 +389,7 @@ function oneOf(values) {
|
|
|
384
389
|
? (shown[0] ?? '')
|
|
385
390
|
: `${shown.slice(0, -1).join(', ')}${shown.length > 2 ? ',' : ''} or ${shown.at(-1)}`;
|
|
386
391
|
}
|
|
387
|
-
function checkProblem(check, input) {
|
|
392
|
+
export function checkProblem(check, input, reads = "this tool's input") {
|
|
388
393
|
const keys = checkKeys(check.path);
|
|
389
394
|
if (!keys) {
|
|
390
395
|
return `A "when" reads what the model sent; "${check.path}" is only there once the call is done.`; // labels-exempt: builder diagnostic
|
|
@@ -393,7 +398,7 @@ function checkProblem(check, input) {
|
|
|
393
398
|
if (found.holds === 'missing') {
|
|
394
399
|
const fields = inputFields(input).slice(0, 4);
|
|
395
400
|
const tryThese = fields.length ? ` Try ${oneOf(fields)}.` : ''; // labels-exempt: builder diagnostic
|
|
396
|
-
return `"${check.path}" in the "when" is not a field of
|
|
401
|
+
return `"${check.path}" in the "when" is not a field of ${reads}.${tryThese}`; // labels-exempt: builder diagnostic
|
|
397
402
|
}
|
|
398
403
|
if (found.holds === 'group') {
|
|
399
404
|
return `"${check.path}" in the "when" is a list or group; a "when" compares text, a number, or true or false.`; // labels-exempt: builder diagnostic
|
|
@@ -12,7 +12,7 @@ class AgentCallFailed extends Error {
|
|
|
12
12
|
this.failure = failure;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
/** The agents an agent tool can run: each has a turn that takes text. */
|
|
15
|
+
/** The agents an agent tool can run: each has a turn that takes text, which a transcription turn does not. */
|
|
16
16
|
const AGENT_TOOL_TYPES = new Set(['text', 'image', 'speech']);
|
|
17
17
|
// why: Bytes that are not base64, or a text of only spaces, would be refused inside the called turn as the host's error and end the caller's turn; checked here, the model reads a failed call.
|
|
18
18
|
const textInput = z.string().regex(/\S/);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { labelText } from '../../guardrails/labels.js';
|
|
3
|
+
import type { SpanHandle, TraceAttributes } from '../../observability/trace-span.js';
|
|
4
|
+
import type { TurnEvent } from '../types.js';
|
|
5
|
+
import { type ToolCallBase } from './events.js';
|
|
6
|
+
import { type ToolExecutionCoordinator, type ToolOperationReply } from './operation.js';
|
|
7
|
+
/** When the model gets its reply: at the hand-off, past a time, if it asks, or when the body ends. */
|
|
8
|
+
export type ToolBackground = 'always' | {
|
|
9
|
+
afterMs: number;
|
|
10
|
+
} | 'ask' | 'never';
|
|
11
|
+
/** The call a detached event belongs to. */
|
|
12
|
+
export interface ToolBackgroundCall {
|
|
13
|
+
operationId: string;
|
|
14
|
+
callId: string;
|
|
15
|
+
toolId: string;
|
|
16
|
+
}
|
|
17
|
+
/** The host's hold on one detached call. */
|
|
18
|
+
export interface ToolBackgroundHandle extends ToolBackgroundCall {
|
|
19
|
+
/**
|
|
20
|
+
* Stops the call. It settles as a `cancelled` failure with `reason` as its code, whatever the
|
|
21
|
+
* body does. With no reason this is a shutdown: the call ends `execution_interrupted`. With
|
|
22
|
+
* `graceMs`, a body that ignores its signal past that time settles anyway.
|
|
23
|
+
*/
|
|
24
|
+
stop(reason?: string, options?: {
|
|
25
|
+
graceMs?: number;
|
|
26
|
+
}): void;
|
|
27
|
+
/** Resolves when the call has settled or been marked. */
|
|
28
|
+
done: Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** The host's service for detached calls. Without it every tool runs inline. */
|
|
31
|
+
export interface ToolBackgroundService {
|
|
32
|
+
detached(call: ToolBackgroundHandle): void;
|
|
33
|
+
event(event: TurnEvent, call: ToolBackgroundCall): void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** A detached call's own trace record, joined to its turn through `traceparent`. */
|
|
36
|
+
export interface DetachedToolTrace {
|
|
37
|
+
open: (name: string, attributes: TraceAttributes) => SpanHandle;
|
|
38
|
+
end: () => void | Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/** The service with what a request adds: its event projection and where a detached trace goes. */
|
|
41
|
+
export interface ToolBackgroundSupport {
|
|
42
|
+
service: ToolBackgroundService;
|
|
43
|
+
project: (event: TurnEvent) => TurnEvent;
|
|
44
|
+
openTrace: (callId: string) => DetachedToolTrace;
|
|
45
|
+
}
|
|
46
|
+
export interface ToolDetach {
|
|
47
|
+
at: 'claim' | {
|
|
48
|
+
afterMs: number;
|
|
49
|
+
};
|
|
50
|
+
support: ToolBackgroundSupport;
|
|
51
|
+
trace: DetachedToolTrace;
|
|
52
|
+
reply: () => ToolOperationReply;
|
|
53
|
+
}
|
|
54
|
+
/** The `ask` argument, as the model reads it. */
|
|
55
|
+
export declare function backgroundField(): z.ZodOptional<z.ZodBoolean>;
|
|
56
|
+
/** The call's input without `background`, and whether the model asked for it. */
|
|
57
|
+
export declare function splitBackground(tool: {
|
|
58
|
+
background?: ToolBackground;
|
|
59
|
+
} | undefined, input: unknown): {
|
|
60
|
+
input: unknown;
|
|
61
|
+
asked: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** How this call detaches, or `undefined` when it runs inline. */
|
|
64
|
+
export declare function planDetach(args: {
|
|
65
|
+
tool: {
|
|
66
|
+
background?: ToolBackground;
|
|
67
|
+
name: string;
|
|
68
|
+
} | undefined;
|
|
69
|
+
input: unknown;
|
|
70
|
+
support: ToolBackgroundSupport | undefined;
|
|
71
|
+
base: ToolCallBase;
|
|
72
|
+
labels: Parameters<typeof labelText>[2];
|
|
73
|
+
}): ToolDetach | undefined;
|
|
74
|
+
/** A late result needs a coordinator to keep it. */
|
|
75
|
+
export declare function assertBackgroundCoordinator(service: ToolBackgroundService | undefined, execution: ToolExecutionCoordinator | undefined): void;
|
|
76
|
+
/** A tool that must answer in an open turn cannot detach; only an object input takes `background`. */
|
|
77
|
+
export declare function assertBackgroundSetting(tool: {
|
|
78
|
+
name: string;
|
|
79
|
+
background?: ToolBackground;
|
|
80
|
+
answeredBy?: string;
|
|
81
|
+
}): void;
|