@theoremjs/agents 0.3.4-next.757.gde44a4d → 0.3.4-next.759.g46e0e27
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 +3 -3
- package/esm/src/guardrails/boundaries.d.ts +2 -2
- package/esm/src/guardrails/boundaries.js +2 -2
- package/esm/src/guardrails/corpus/fuzz-inbound.js +4 -4
- package/esm/src/guardrails/corpus/live-attacks.d.ts +1 -1
- package/esm/src/guardrails/corpus/live-attacks.js +13 -9
- package/esm/src/guardrails/detect-at.js +1 -1
- package/esm/src/guardrails/sanitize.js +7 -7
- package/esm/src/guardrails/types.d.ts +1 -1
- package/esm/src/interface/from-profile.js +3 -1
- package/esm/src/interface/inputs.js +2 -3
- package/esm/src/interface/profile-interface.js +10 -11
- package/esm/src/interface/types.d.ts +3 -3
- package/esm/src/kernel/api-catalog.js +6 -5
- package/esm/src/kernel/engine/runner/gates.js +5 -4
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +1 -1
- package/esm/src/kernel/engine/runner/schema-validation.js +9 -9
- package/esm/src/kernel/engine/session/mod.js +6 -6
- package/esm/src/kernel/mod.d.ts +1 -1
- package/esm/src/kernel/mod.js +1 -1
- package/esm/src/kernel/profile-presence.js +3 -3
- package/esm/src/kernel/profile-scope.js +12 -12
- package/esm/src/kernel/registry/ingress.d.ts +1 -2
- package/esm/src/kernel/registry/ingress.js +1 -18
- package/esm/src/kernel/registry/options.d.ts +18 -0
- package/esm/src/kernel/registry/options.js +98 -0
- package/esm/src/kernel/registry/profiles.js +16 -20
- package/esm/src/kernel/registry/resolve.js +6 -5
- package/esm/src/kernel/registry/system-prompt.js +7 -7
- package/esm/src/kernel/schema.js +20 -14
- package/esm/src/kernel/system-lines.d.ts +6 -8
- package/esm/src/kernel/system-lines.js +25 -68
- package/esm/src/kernel/tools/agent.d.ts +1 -1
- package/esm/src/kernel/tools/agent.js +11 -11
- package/esm/src/kernel/tools/resolve.js +1 -1
- package/esm/src/kernel/tools/types.d.ts +2 -2
- package/esm/src/kernel/types.d.ts +25 -30
- package/esm/src/providers/shared/upstream-tape.js +17 -1
- package/package.json +1 -1
- package/esm/src/kernel/registry/slot-fill.d.ts +0 -7
- package/esm/src/kernel/registry/slot-fill.js +0 -22
- package/esm/src/kernel/registry/slots.d.ts +0 -13
- package/esm/src/kernel/registry/slots.js +0 -31
|
@@ -25,12 +25,12 @@ const MODEL_PROFILE_TYPES = [
|
|
|
25
25
|
'embedding',
|
|
26
26
|
];
|
|
27
27
|
const TURN_TYPES = ['text', 'image', 'speech', 'live'];
|
|
28
|
-
/** Types whose `inputs` are turn inputs (text, files,
|
|
28
|
+
/** Types whose `inputs` are turn inputs (text, files, options) rather than decision state. */
|
|
29
29
|
const TURN_INPUT_TYPES = ['text', 'image'];
|
|
30
30
|
const TURN_INPUT_REASON = 'a decision takes JSON state, live takes its input through live.ingress, and transcription takes only a clip';
|
|
31
|
-
/** Types that take
|
|
32
|
-
const
|
|
33
|
-
const
|
|
31
|
+
/** Types that take options and context: the turn types, and a call. */
|
|
32
|
+
const OPTION_TYPES = ['text', 'image', 'live'];
|
|
33
|
+
const OPTION_REASON = 'a decision takes JSON state, and transcription and embedding calls take their input alone';
|
|
34
34
|
/** Guardrails a host profile may set keep `host`; the rest guard a model turn. */
|
|
35
35
|
function turnGuardrailTypes(key) {
|
|
36
36
|
return HOST_GUARDRAIL_FIELDS.includes(key)
|
|
@@ -79,7 +79,7 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
79
79
|
profileTypes: MODEL_PROFILE_TYPES,
|
|
80
80
|
reason: 'a host profile has no agent identity — it runs no model',
|
|
81
81
|
},
|
|
82
|
-
'identity.
|
|
82
|
+
'identity.options': {
|
|
83
83
|
profileTypes: ['text', 'image', 'live'],
|
|
84
84
|
reason: 'speech has no system channel (the input text is the transcript), a decision is asked only through its questions, and an embedding call embeds its input alone',
|
|
85
85
|
},
|
|
@@ -160,21 +160,21 @@ export const PROFILE_FIELD_SCOPE = {
|
|
|
160
160
|
profileTypes: [...TURN_INPUT_TYPES, 'transcription', 'embedding'],
|
|
161
161
|
reason: TURN_INPUT_REASON,
|
|
162
162
|
},
|
|
163
|
-
'inputs.
|
|
164
|
-
profileTypes:
|
|
165
|
-
reason:
|
|
163
|
+
'inputs.options': {
|
|
164
|
+
profileTypes: OPTION_TYPES,
|
|
165
|
+
reason: OPTION_REASON,
|
|
166
166
|
},
|
|
167
167
|
'inputs.context': {
|
|
168
|
-
profileTypes:
|
|
169
|
-
reason:
|
|
168
|
+
profileTypes: OPTION_TYPES,
|
|
169
|
+
reason: OPTION_REASON,
|
|
170
170
|
},
|
|
171
171
|
'inputs.state': {
|
|
172
172
|
profileTypes: ['decision'],
|
|
173
|
-
reason: 'only a decision reads JSON state; a turn takes text, files, and
|
|
173
|
+
reason: 'only a decision reads JSON state; a turn takes text, files, and options',
|
|
174
174
|
},
|
|
175
175
|
'inputs.maxStateBytes': {
|
|
176
176
|
profileTypes: ['decision'],
|
|
177
|
-
reason: 'only a decision reads JSON state; a turn takes text, files, and
|
|
177
|
+
reason: 'only a decision reads JSON state; a turn takes text, files, and options',
|
|
178
178
|
},
|
|
179
179
|
outputs: {
|
|
180
180
|
profileTypes: ['text', 'image', 'speech'],
|
|
@@ -8,7 +8,6 @@ declare function assertTranscriptionRole(profile: Profile, req: TurnRequest): vo
|
|
|
8
8
|
declare function resolveSpeech(profile: Profile, req: TurnRequest): ProfileSpeechSpec | undefined;
|
|
9
9
|
declare function resolveImageFormat(profile: Profile): ImageResponseFormat | null;
|
|
10
10
|
declare function resolveInputParts(profile: Profile, req: TurnRequest): InteractionPart[];
|
|
11
|
-
declare function assertTurnSlots(profile: Profile, req: TurnRequest): void;
|
|
12
11
|
/** Refuses context from a sender the profile's `inputs.context` does not list, and a package over its `maxChars`. */
|
|
13
12
|
declare function assertTurnContext(profile: Profile, req: TurnRequest): void;
|
|
14
|
-
export { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext,
|
|
13
|
+
export { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, resolveImageFormat, resolveInputParts, resolveSpeech, };
|
|
@@ -7,7 +7,6 @@ import { CONTEXT_SENDERS } from '../schema.js';
|
|
|
7
7
|
import { CONTINUE_INSTRUCTION_TYPES } from '../stop.js';
|
|
8
8
|
import { isTurnMediaRef } from './attachments.js';
|
|
9
9
|
import { mediaKindForMime, mimeEssence, profileInputs } from './catalog.js';
|
|
10
|
-
import { slotValues } from './slots.js';
|
|
11
10
|
function activePrimaryOutputModes(profile, structuredId) {
|
|
12
11
|
const modes = [];
|
|
13
12
|
if (structuredId) {
|
|
@@ -155,22 +154,6 @@ function resolveInputParts(profile, req) {
|
|
|
155
154
|
parts.push(...extractMediaParts(profile, req));
|
|
156
155
|
return parts;
|
|
157
156
|
}
|
|
158
|
-
function assertTurnSlots(profile, req) {
|
|
159
|
-
const slots = req.input?.slots;
|
|
160
|
-
if (!slots)
|
|
161
|
-
return;
|
|
162
|
-
const declared = profileInputs(profile)?.slots ?? {};
|
|
163
|
-
for (const [key, value] of Object.entries(slots)) {
|
|
164
|
-
const decl = Object.hasOwn(declared, key) ? declared[key] : undefined;
|
|
165
|
-
if (!decl) {
|
|
166
|
-
throw new TheoremError('request', `Profile ${profile.id} has no slot '${key}'`);
|
|
167
|
-
}
|
|
168
|
-
const choices = slotValues(decl);
|
|
169
|
-
if (!choices.includes(value)) {
|
|
170
|
-
throw new TheoremError('request', `Profile ${profile.id}: slot '${key}' takes ${choices.join(', ')}, not '${value}'`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
157
|
/** Refuses context from a sender the profile's `inputs.context` does not list, and a package over its `maxChars`. */
|
|
175
158
|
function assertTurnContext(profile, req) {
|
|
176
159
|
const context = req.input?.context;
|
|
@@ -189,4 +172,4 @@ function assertTurnContext(profile, req) {
|
|
|
189
172
|
}
|
|
190
173
|
}
|
|
191
174
|
}
|
|
192
|
-
export { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext,
|
|
175
|
+
export { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, resolveImageFormat, resolveInputParts, resolveSpeech, };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OptionDecl, Profile, ProfileOptions, TurnRequest } from '../types.js';
|
|
2
|
+
/** The values one option can take. */
|
|
3
|
+
export declare function optionValues(decl: OptionDecl): string[];
|
|
4
|
+
/** One option of the profile, whichever object holds it. */
|
|
5
|
+
export declare function profileOption(profile: Profile, name: string): OptionDecl | undefined;
|
|
6
|
+
/** What is wrong with a profile's options, or undefined. */
|
|
7
|
+
export declare function optionsProblem(code: ProfileOptions | undefined, person: ProfileOptions | undefined): string | undefined;
|
|
8
|
+
/** Refuses a value the profile doesn't list, and one sent through the other door. */
|
|
9
|
+
export declare function assertTurnOptions(profile: Profile, req: TurnRequest): void;
|
|
10
|
+
/** The value of each option the turn set, from either door. */
|
|
11
|
+
export declare function turnFacts(profile: Profile, req: TurnRequest): Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Prints each `{name}` that names one of the profile's options. A `{name}` that is no option stays
|
|
14
|
+
* as written. Text that prints an option the turn left unset has a hole in it, so it gives
|
|
15
|
+
* undefined and the caller sends none of it. Every value is one the profile lists, so no free text
|
|
16
|
+
* is written.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fillOptions(profile: Profile, text: string, facts: Readonly<Record<string, string>>): string | undefined;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options: the named values a turn can hold. One on `identity.options` is the host's code to state
|
|
3
|
+
* on `TurnRequest.options`; one on `inputs.options` is the person's to pick on
|
|
4
|
+
* `TurnRequest.input.options`. Nothing else differs: either one chooses prompt lines with `when`
|
|
5
|
+
* and prints with `{name}`, and either one can go unset.
|
|
6
|
+
*/
|
|
7
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
8
|
+
import { profileInputs } from './catalog.js';
|
|
9
|
+
const OPTION_NAME = /^[A-Za-z_][\w-]*$/;
|
|
10
|
+
const OPTION_REF = /\{([A-Za-z_][\w-]*)\}/g;
|
|
11
|
+
const RESERVED_NAMES = ['input', 'output'];
|
|
12
|
+
/** The values one option can take. */
|
|
13
|
+
export function optionValues(decl) {
|
|
14
|
+
return decl.choices.map((choice) => choice.value);
|
|
15
|
+
}
|
|
16
|
+
/** The options the host's code states. */
|
|
17
|
+
function codeOptions(profile) {
|
|
18
|
+
const takesOptions = profile.type === 'text' || profile.type === 'image' || profile.type === 'live';
|
|
19
|
+
return (takesOptions ? profile.identity.options : undefined) ?? {};
|
|
20
|
+
}
|
|
21
|
+
/** The options a person picks. */
|
|
22
|
+
function personOptions(profile) {
|
|
23
|
+
return profileInputs(profile)?.options ?? {};
|
|
24
|
+
}
|
|
25
|
+
/** One option of the profile, whichever object holds it. */
|
|
26
|
+
export function profileOption(profile, name) {
|
|
27
|
+
const declared = { ...codeOptions(profile), ...personOptions(profile) };
|
|
28
|
+
return Object.hasOwn(declared, name) ? declared[name] : undefined;
|
|
29
|
+
}
|
|
30
|
+
function optionProblem(name, decl) {
|
|
31
|
+
if (!OPTION_NAME.test(name))
|
|
32
|
+
return `Option "${name}" needs a plain name.`; // labels-exempt: developer contract error
|
|
33
|
+
if (RESERVED_NAMES.includes(name))
|
|
34
|
+
return `Option "${name}" is a reserved name.`; // labels-exempt: developer contract error
|
|
35
|
+
const values = Array.isArray(decl.choices) ? optionValues(decl) : [];
|
|
36
|
+
if (values.length === 0)
|
|
37
|
+
return `Option "${name}" lists no values.`; // labels-exempt: developer contract error
|
|
38
|
+
const bad = values.find((value) => !value.trim() || value === 'null');
|
|
39
|
+
return bad === undefined ? undefined : `Option "${name}" can't take the value "${bad}".`; // labels-exempt: developer contract error
|
|
40
|
+
}
|
|
41
|
+
/** What is wrong with a profile's options, or undefined. */
|
|
42
|
+
export function optionsProblem(code, person) {
|
|
43
|
+
for (const [name, decl] of Object.entries({ ...code, ...person })) {
|
|
44
|
+
if (code && person && Object.hasOwn(code, name) && Object.hasOwn(person, name)) {
|
|
45
|
+
return `"${name}" is on both identity.options and inputs.options.`; // labels-exempt: developer contract error
|
|
46
|
+
}
|
|
47
|
+
const problem = optionProblem(name, decl);
|
|
48
|
+
if (problem)
|
|
49
|
+
return problem;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
function assertValues(id, declared, where, values) {
|
|
54
|
+
for (const [name, value] of Object.entries(values ?? {})) {
|
|
55
|
+
const decl = Object.hasOwn(declared, name) ? declared[name] : undefined;
|
|
56
|
+
if (!decl)
|
|
57
|
+
throw new TheoremError('request', `Profile ${id} has no option '${name}' on ${where}`); // labels-exempt: developer contract error
|
|
58
|
+
const choices = optionValues(decl);
|
|
59
|
+
if (!choices.includes(value)) {
|
|
60
|
+
throw new TheoremError('request', `Profile ${id}: option '${name}' takes ${choices.join(', ')}, not '${value}'`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The turn's own path, as the `path` option holds it, if the profile declares one. */
|
|
65
|
+
function statedPath(code, req) {
|
|
66
|
+
return Object.hasOwn(code, 'path') && req.path !== undefined ? { path: req.path } : {};
|
|
67
|
+
}
|
|
68
|
+
/** Refuses a value the profile doesn't list, and one sent through the other door. */
|
|
69
|
+
export function assertTurnOptions(profile, req) {
|
|
70
|
+
const code = codeOptions(profile);
|
|
71
|
+
if (req.options && Object.hasOwn(req.options, 'path')) {
|
|
72
|
+
throw new TheoremError('request', `Profile ${profile.id}: the turn's own path states path`); // labels-exempt: developer contract error
|
|
73
|
+
}
|
|
74
|
+
assertValues(profile.id, code, 'identity.options', { ...req.options, ...statedPath(code, req) });
|
|
75
|
+
assertValues(profile.id, personOptions(profile), 'inputs.options', req.input?.options);
|
|
76
|
+
}
|
|
77
|
+
/** The value of each option the turn set, from either door. */
|
|
78
|
+
export function turnFacts(profile, req) {
|
|
79
|
+
return { ...req.options, ...statedPath(codeOptions(profile), req), ...req.input?.options };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Prints each `{name}` that names one of the profile's options. A `{name}` that is no option stays
|
|
83
|
+
* as written. Text that prints an option the turn left unset has a hole in it, so it gives
|
|
84
|
+
* undefined and the caller sends none of it. Every value is one the profile lists, so no free text
|
|
85
|
+
* is written.
|
|
86
|
+
*/
|
|
87
|
+
export function fillOptions(profile, text, facts) {
|
|
88
|
+
let isWhole = true;
|
|
89
|
+
const filled = text.replace(OPTION_REF, (whole, name) => {
|
|
90
|
+
if (!profileOption(profile, name))
|
|
91
|
+
return whole;
|
|
92
|
+
const value = Object.hasOwn(facts, name) ? facts[name] : undefined;
|
|
93
|
+
if (value === undefined)
|
|
94
|
+
isWhole = false;
|
|
95
|
+
return value ?? whole;
|
|
96
|
+
});
|
|
97
|
+
return isWhole ? filled : undefined;
|
|
98
|
+
}
|
|
@@ -15,7 +15,7 @@ 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';
|
|
18
|
-
import {
|
|
18
|
+
import { optionValues, profileOption } from './options.js';
|
|
19
19
|
import { soleModelId } from './sole-model.js';
|
|
20
20
|
function assertModelRoute(_profileId, _modelId, binding, _type) {
|
|
21
21
|
if (!binding.provider?.trim() || !binding.apiId?.trim())
|
|
@@ -265,7 +265,7 @@ function assertRequiredFields(input) {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
|
-
/** `inputs` is optional on a live profile only, where it holds
|
|
268
|
+
/** `inputs` is optional on a live profile only, where it holds options and context and nothing else. */
|
|
269
269
|
function assertInputsSet(input) {
|
|
270
270
|
const { id, type } = input;
|
|
271
271
|
if (type === 'live' || !profileTypesForField('inputs').includes(type))
|
|
@@ -365,14 +365,10 @@ function assertIdentitySystem(input) {
|
|
|
365
365
|
input.type === 'transcription' ||
|
|
366
366
|
input.type === 'embedding')
|
|
367
367
|
return;
|
|
368
|
-
const {
|
|
369
|
-
const slots = {};
|
|
370
|
-
for (const [name, decl] of Object.entries(normalizeProfileInputsSlots(input.inputs)?.slots ?? {})) {
|
|
371
|
-
slots[name] = slotValues(decl);
|
|
372
|
-
}
|
|
368
|
+
const { options, system } = input.identity;
|
|
373
369
|
const prompt = system ?? '';
|
|
374
370
|
assertSystemLines(prompt, `Profile ${input.id} identity.system`);
|
|
375
|
-
const problem = systemLinesProblem(prompt,
|
|
371
|
+
const problem = systemLinesProblem(prompt, options, input.inputs?.options);
|
|
376
372
|
if (problem)
|
|
377
373
|
throw new TheoremError('config', `Profile ${input.id} identity.system: ${problem}`); // labels-exempt: developer contract error
|
|
378
374
|
}
|
|
@@ -428,7 +424,7 @@ function validatedProfile(input) {
|
|
|
428
424
|
? { handle: input.identity.handle }
|
|
429
425
|
: {
|
|
430
426
|
handle: input.identity.handle,
|
|
431
|
-
|
|
427
|
+
options: input.identity.options,
|
|
432
428
|
system: input.identity.system,
|
|
433
429
|
};
|
|
434
430
|
const guardrails = input.guardrails;
|
|
@@ -444,7 +440,7 @@ function validatedProfile(input) {
|
|
|
444
440
|
identity,
|
|
445
441
|
...modelFields,
|
|
446
442
|
tools: input.tools,
|
|
447
|
-
inputs:
|
|
443
|
+
inputs: input.inputs,
|
|
448
444
|
outputs: input.outputs,
|
|
449
445
|
turnBehaviour: input.turnBehaviour,
|
|
450
446
|
guardrails,
|
|
@@ -460,7 +456,7 @@ function validatedProfile(input) {
|
|
|
460
456
|
...modelFields,
|
|
461
457
|
image: input.image,
|
|
462
458
|
tools: input.tools,
|
|
463
|
-
inputs:
|
|
459
|
+
inputs: input.inputs,
|
|
464
460
|
outputs: input.outputs,
|
|
465
461
|
turnBehaviour: input.turnBehaviour,
|
|
466
462
|
guardrails,
|
|
@@ -491,7 +487,7 @@ function validatedProfile(input) {
|
|
|
491
487
|
identity,
|
|
492
488
|
...modelFields,
|
|
493
489
|
live: input.live,
|
|
494
|
-
inputs: input.inputs
|
|
490
|
+
inputs: input.inputs,
|
|
495
491
|
tools: { allow: input.tools.allow, ...optionalParallel(input.tools.parallel) },
|
|
496
492
|
turnBehaviour: input.turnBehaviour,
|
|
497
493
|
guardrails,
|
|
@@ -508,7 +504,7 @@ function validatedProfile(input) {
|
|
|
508
504
|
throw new TheoremError('config', `Unknown profile type '${String(_exhaustive)}'`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
509
505
|
}
|
|
510
506
|
}
|
|
511
|
-
|
|
507
|
+
assertStructuredOption(profile);
|
|
512
508
|
assertMaxSteps(profile);
|
|
513
509
|
assertAnswerStep(profile);
|
|
514
510
|
return profile;
|
|
@@ -528,21 +524,21 @@ function assertAnswerStep(profile) {
|
|
|
528
524
|
return;
|
|
529
525
|
throw new TheoremError('config', `Profile ${profile.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`);
|
|
530
526
|
}
|
|
531
|
-
/** A turn can pass no value outside the
|
|
532
|
-
function
|
|
527
|
+
/** A turn can pass no value outside the option's choices, so any other mapped key is dead. */
|
|
528
|
+
function assertStructuredOption(profile) {
|
|
533
529
|
if (profile.type === 'live')
|
|
534
530
|
return;
|
|
535
531
|
const structured = profile.outputs?.structured;
|
|
536
532
|
if (!structured || typeof structured === 'string')
|
|
537
533
|
return;
|
|
538
|
-
const decl =
|
|
534
|
+
const decl = profileOption(profile, structured.by);
|
|
539
535
|
if (!decl) {
|
|
540
|
-
throw new TheoremError('config', `Profile ${profile.id}: outputs.structured.by '${structured.by}' is not
|
|
536
|
+
throw new TheoremError('config', `Profile ${profile.id}: outputs.structured.by '${structured.by}' is not one of the profile's options`);
|
|
541
537
|
}
|
|
542
|
-
const choices =
|
|
538
|
+
const choices = optionValues(decl);
|
|
543
539
|
const unknown = Object.keys(structured.map).filter((value) => !choices.includes(value));
|
|
544
540
|
if (unknown.length) {
|
|
545
|
-
throw new TheoremError('config', `Profile ${profile.id}: outputs.structured.map maps ${unknown.join(', ')}, not a choice of
|
|
541
|
+
throw new TheoremError('config', `Profile ${profile.id}: outputs.structured.map maps ${unknown.join(', ')}, not a choice of option '${structured.by}'`);
|
|
546
542
|
}
|
|
547
543
|
}
|
|
548
544
|
const IMAGE_PIN_RULES = {
|
|
@@ -694,7 +690,7 @@ function assertModelBuiltInTools(tools, profile) {
|
|
|
694
690
|
}
|
|
695
691
|
}
|
|
696
692
|
}
|
|
697
|
-
/** The schema ids `outputs.structured` can pick, by
|
|
693
|
+
/** The schema ids `outputs.structured` can pick, by option and fallback. */
|
|
698
694
|
function structuredIds(profile) {
|
|
699
695
|
const structured = profile.type === 'text' ? profile.outputs?.structured : undefined;
|
|
700
696
|
if (!structured)
|
|
@@ -11,7 +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, assertTranscriptionRole, assertTurnContext,
|
|
14
|
+
import { assertOutputMode, assertSpeechRole, assertTranscriptionRole, assertTurnContext, resolveImageFormat, resolveInputParts, resolveSpeech, } from './ingress.js';
|
|
15
|
+
import { assertTurnOptions, turnFacts } from './options.js';
|
|
15
16
|
import { resolveTurnSystem } from './system-prompt.js';
|
|
16
17
|
function isModelProfile(profile) {
|
|
17
18
|
return profile.type !== 'host' && profile.type !== 'decision' && profile.type !== 'embedding';
|
|
@@ -72,7 +73,7 @@ function resolveSummaries(binding) {
|
|
|
72
73
|
}
|
|
73
74
|
return undefined;
|
|
74
75
|
}
|
|
75
|
-
function resolveStructured(profile,
|
|
76
|
+
function resolveStructured(profile, facts) {
|
|
76
77
|
if (profile.type === 'live') {
|
|
77
78
|
return null;
|
|
78
79
|
}
|
|
@@ -83,7 +84,7 @@ function resolveStructured(profile, slots) {
|
|
|
83
84
|
if (typeof structured === 'string') {
|
|
84
85
|
return structured;
|
|
85
86
|
}
|
|
86
|
-
const value =
|
|
87
|
+
const value = facts[structured.by];
|
|
87
88
|
if (value) {
|
|
88
89
|
const mapped = structured.map[value];
|
|
89
90
|
if (mapped) {
|
|
@@ -163,7 +164,7 @@ function resolveBuiltInArgs(profile, model, binding, args) {
|
|
|
163
164
|
/** `model` names the binding to resolve, past the profile's own selection rule. */
|
|
164
165
|
function resolveTurnInRegistry(registry, req, model) {
|
|
165
166
|
const profile = requireModelProfile(registry.profiles.get(req.profile), 'resolveTurn');
|
|
166
|
-
|
|
167
|
+
assertTurnOptions(profile, req);
|
|
167
168
|
assertTurnContext(profile, req);
|
|
168
169
|
const safe = sanitizeTurnRequest(req, profile);
|
|
169
170
|
const input = safe.input ?? {};
|
|
@@ -172,7 +173,7 @@ function resolveTurnInRegistry(registry, req, model) {
|
|
|
172
173
|
const binding = requireModelBinding(profile, picked);
|
|
173
174
|
const toolSnapshot = resolveTurnTools(registry.tools, profile, safe, picked);
|
|
174
175
|
const builtins = toolSnapshot.builtins;
|
|
175
|
-
const structuredId = resolveStructured(profile,
|
|
176
|
+
const structuredId = resolveStructured(profile, turnFacts(profile, safe));
|
|
176
177
|
assertOutputMode(profile, structuredId);
|
|
177
178
|
if (structuredId && toolSnapshot.wire.some((tool) => tool.name === ANSWER_TOOL)) {
|
|
178
179
|
throw new TheoremError('config', `Profile ${profile.id}: a structured turn answers through '${ANSWER_TOOL}', so no tool of its own may take that name`);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { pickSystemLines
|
|
1
|
+
import { pickSystemLines } from '../system-lines.js';
|
|
2
2
|
import { joinSystemPieces, systemPieces } from '../system-parts.js';
|
|
3
|
-
import {
|
|
3
|
+
import { fillOptions, turnFacts } from './options.js';
|
|
4
4
|
/**
|
|
5
5
|
* `identity.system` is trusted author-time copy and crosses no boundary: no detector reads it.
|
|
6
|
-
* A `{
|
|
6
|
+
* A `{name}` in it becomes the value the request set, 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,
|
|
9
|
+
function systemFromProfile(profile, req) {
|
|
10
10
|
if (profile.type === 'speech' || profile.type === 'transcription') {
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
@@ -14,8 +14,8 @@ function systemFromProfile(profile, slots, req) {
|
|
|
14
14
|
if (!prompt) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
|
-
const facts = turnFacts(profile
|
|
18
|
-
return pickSystemLines(prompt, facts, (text) =>
|
|
17
|
+
const facts = turnFacts(profile, req);
|
|
18
|
+
return pickSystemLines(prompt, facts, (text) => fillOptions(profile, text, facts));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Synchronous: snapshotted in `resolveTurn` before any async work. Each source
|
|
@@ -23,7 +23,7 @@ function systemFromProfile(profile, slots, req) {
|
|
|
23
23
|
* profile's prompt as private as it was written.
|
|
24
24
|
*/
|
|
25
25
|
function resolveTurnSystem(profile, req) {
|
|
26
|
-
const kept = systemFromProfile(profile, req
|
|
26
|
+
const kept = systemFromProfile(profile, req);
|
|
27
27
|
return {
|
|
28
28
|
pieces: joinSystemPieces([
|
|
29
29
|
...kept.map(({ pieces }) => pieces),
|
package/esm/src/kernel/schema.js
CHANGED
|
@@ -278,7 +278,8 @@ export const DYNAMIC_FIELD_PARENTS = new Set([
|
|
|
278
278
|
'models',
|
|
279
279
|
'models.*.efforts',
|
|
280
280
|
'labels',
|
|
281
|
-
'inputs.
|
|
281
|
+
'inputs.options',
|
|
282
|
+
'identity.options',
|
|
282
283
|
'inputs.limitsByMime',
|
|
283
284
|
'outputs.validation.fields',
|
|
284
285
|
'outputs.validation.items',
|
|
@@ -504,9 +505,14 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
504
505
|
embedding: 'For when your app needs vectors from text or provider-supported media.',
|
|
505
506
|
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.',
|
|
506
507
|
}),
|
|
507
|
-
identity: field('{ handle,
|
|
508
|
+
identity: field('{ handle, options?, system? }', "The agent's display name and the system instruction it is given."),
|
|
508
509
|
'identity.handle': field('string', 'The name hosts and users see for this agent, at most 32 characters; the model never sees it.'),
|
|
509
|
-
'identity.
|
|
510
|
+
'identity.options': field('Record<string, OptionDecl>', 'The options the host\'s code sets on runTurn, which a person never sees. A line of identity.system reads one as "when plan is free: …" and prints it as {plan}. One named path holds the turn\'s path.'),
|
|
511
|
+
'identity.options.*': field('OptionDecl', '{ label?, choices: { value, description? }[] }, the same shape as inputs.options.*.'),
|
|
512
|
+
'identity.options.*.label': field('string', "A person-readable title. Omit to show the option's name."),
|
|
513
|
+
'identity.options.*.choices': field('OptionChoice[]', 'The values this option can take.'),
|
|
514
|
+
'identity.options.*.choices.*.value': field('string', 'The value the code sets, which `when` reads and {name} prints.'),
|
|
515
|
+
'identity.options.*.choices.*.description': field('string', 'What this value means. It is never sent to the model.'),
|
|
510
516
|
'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
517
|
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
518
|
'models.*': field('ModelBinding | DecisionModelBinding', 'One model: how to reach it and the settings sent with it.'),
|
|
@@ -585,12 +591,12 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
585
591
|
'inputs.maxTurnBytes': field('number', 'The most bytes one turn or embedding request may send inline across all its files and clips.'),
|
|
586
592
|
'inputs.limitsByMime': field('Record<string, number>', 'Size limits by file type that replace maxBytes for those types.'),
|
|
587
593
|
'inputs.limitsByMime.*': field('number', 'The largest file of this type (or type/* family), in bytes, a turn or embedding request may send inline.'),
|
|
588
|
-
'inputs.
|
|
589
|
-
'inputs.
|
|
590
|
-
'inputs.
|
|
591
|
-
'inputs.
|
|
592
|
-
'inputs.
|
|
593
|
-
'inputs.
|
|
594
|
+
'inputs.options': field('Record<string, OptionDecl>', 'The options a person picks, each shown as a picker. A prompt reads one as "when reader is student: …" and prints it as {reader}.'),
|
|
595
|
+
'inputs.options.*': field('OptionDecl', '{ label?, choices: { value, description? }[] }. Value is what the turn sends and what {name} prints.'),
|
|
596
|
+
'inputs.options.*.label': field('string', "Visitor-facing title for this option in the composer (for example Source Bias). Omit to show the option's name."),
|
|
597
|
+
'inputs.options.*.choices': field('OptionChoice[]', 'The values this option can take, each with an optional UI description.'),
|
|
598
|
+
'inputs.options.*.choices.*.value': field('string', 'The value the turn sends for this choice, which `when` reads and {name} prints.'),
|
|
599
|
+
'inputs.options.*.choices.*.description': field('string', 'Visitor-facing blurb for this choice in the composer. Never substituted into prompts.'),
|
|
594
600
|
'inputs.context': field('{ from: ContextSender[]; maxChars: number }', 'Lets the page or the host send the agent one package of things to know, read at the context boundary.'),
|
|
595
601
|
'inputs.context.from': field("Array<'client' | 'server'>", 'Who may send context; context from anyone else is refused.', CONTEXT_SENDERS, {
|
|
596
602
|
client: 'The browser. A visitor can change it, so it is untrusted.',
|
|
@@ -598,7 +604,7 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
598
604
|
}),
|
|
599
605
|
'inputs.context.maxChars': field('number', 'The longest package, in characters of its JSON, each sender may send.'),
|
|
600
606
|
outputs: field('ProfileOutputsSpec', 'The shape of the reply, how it is checked, and how it streams.'),
|
|
601
|
-
'outputs.structured': field('StructuredSchemaId |
|
|
607
|
+
'outputs.structured': field('StructuredSchemaId | StructuredByOption | null', 'The registered JSON schema the reply must follow, which can vary by option; register it before the profile.'),
|
|
602
608
|
image: field('ProfileImageSpec', 'How the images this profile generates are shaped and made: size, format, quality and references. Each setting is sent only where the provider has it; one it lacks is refused or ignored, as that setting says.'),
|
|
603
609
|
'image.aspectRatio': field('string', 'The shape of generated images, such as 16:9.'),
|
|
604
610
|
'image.resolution': field('string', 'How detailed generated images are, such as 1K, 2K or 4K.'),
|
|
@@ -640,9 +646,9 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
640
646
|
'live.vad.prefixPaddingMs': field('number', 'How long speech must last, in milliseconds, before it counts as the user starting to speak.'),
|
|
641
647
|
'live.vad.silenceDurationMs': field('number', "How long a silence, in milliseconds, ends the user's speech."),
|
|
642
648
|
'live.sessionResumption': field('boolean', 'Whether the provider sends resume handles, which the host can pass to a new session to carry this one on.'),
|
|
643
|
-
'live.greeting': field('string', 'A prompt the call sends itself when it opens new, so the agent speaks first. The visitor does not see it. It may use {
|
|
649
|
+
'live.greeting': field('string', 'A prompt the call sends itself when it opens new, so the agent speaks first. The visitor does not see it. It may use {name}, and is not sent when an option it prints is unset.'),
|
|
644
650
|
'live.resumed': field('{ prompt: string; afterMs?: number }', 'What happens when a call comes back after a drop. It needs live.sessionResumption.'),
|
|
645
|
-
'live.resumed.prompt': field('string', 'A prompt the call sends itself when it resumes, so the agent says it is back. The visitor does not see it. It may use {
|
|
651
|
+
'live.resumed.prompt': field('string', 'A prompt the call sends itself when it resumes, so the agent says it is back. The visitor does not see it. It may use {name}, and is not sent when an option it prints is unset.'),
|
|
646
652
|
'live.resumed.afterMs': field('number', 'The shortest time away, in milliseconds, that earns the prompt; a shorter drop resumes silently.'),
|
|
647
653
|
'live.contextCompression': field('LiveContextCompressionSpec', "Trims the session's context once it grows past the trigger."),
|
|
648
654
|
'live.contextCompression.triggerTokens': field('number', 'The context size, in tokens, that starts trimming.'),
|
|
@@ -653,7 +659,7 @@ export const PROFILE_FIELDS = withScopeAndPresence({
|
|
|
653
659
|
'live.transcription.output': field('boolean', "Whether the model's speech is transcribed; always on while a detector reads live_reply, since it reads the transcript."),
|
|
654
660
|
'outputs.validation': field('ProfileValidationSpec', 'Your checks on a structured reply, and how many rewrites a failure gets.'),
|
|
655
661
|
'outputs.validation.fields': field('Record<string, ProfileValidator>', 'Your checks, each keyed by a dotted path into the structured reply, such as diagram.mermaid; a path no structured schema reaches is refused when the profile registers.'),
|
|
656
|
-
'outputs.validation.fields.*': field('(candidate: unknown,
|
|
662
|
+
'outputs.validation.fields.*': field('(candidate: unknown, options?: Record<string, string>) => ValidationResult | Promise<ValidationResult>', 'Your check on this part of the reply, reached through object properties only; a failure sends its error back to the model to rewrite while retries remain.'),
|
|
657
663
|
'outputs.validation.items': field('Record<string, ProfileItemRule>', 'Your checks on the items of a list, each keyed by the dotted path of that list in the structured reply, such as claims; a path no structured schema reaches as a list is refused when the profile registers.'),
|
|
658
664
|
'outputs.validation.items.*': field('ProfileItemRule', 'Your check on each item of this list. A refused item never fails the reply and the rest of the reply is kept.'),
|
|
659
665
|
'outputs.validation.items.*.check': field('(item: unknown, turn: ItemCheckTurn) => ValidationResult | Promise<ValidationResult>', 'Your check on one item, given what the tools of the turn returned (turn.toolResults); its error is the reason the model reads on a rewrite and the host reads on the removed item.'),
|
|
@@ -830,7 +836,7 @@ export const EXTRA_FIELDS = {
|
|
|
830
836
|
unset: 'The input is only what the profile takes',
|
|
831
837
|
},
|
|
832
838
|
'registerTool.hostOnly': {
|
|
833
|
-
...field("Array<'attachments' | 'voice' | '
|
|
839
|
+
...field("Array<'attachments' | 'voice' | 'options'>", 'Channels the called profile takes that the calling model cannot fill on an agent tool; only onAgentCall sends them. A channel the profile does not take is refused when the tool registers.'),
|
|
834
840
|
unset: 'The model can fill every channel the profile takes',
|
|
835
841
|
},
|
|
836
842
|
'registerTool.auth': {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/** What is wrong with a prompt's
|
|
3
|
-
export declare function systemLinesProblem(prompt: ProfileSystem,
|
|
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>;
|
|
1
|
+
import type { ProfileOptions, ProfileSystem, SystemPiece } from './types.js';
|
|
2
|
+
/** What is wrong with a prompt's options and lines, or undefined. */
|
|
3
|
+
export declare function systemLinesProblem(prompt: ProfileSystem, code: ProfileOptions | undefined, person: ProfileOptions | undefined): string | undefined;
|
|
6
4
|
/** A line that fit a turn: its number in the prompt as written, from 1, and its pieces. */
|
|
7
5
|
export type KeptSystemLine = {
|
|
8
6
|
line: number;
|
|
@@ -12,11 +10,11 @@ export type KeptSystemLine = {
|
|
|
12
10
|
* Every line that fits. Whether plain text is shareable is settled on the prompt as written, so a
|
|
13
11
|
* line dropped on this turn never changes the marks of one that stayed.
|
|
14
12
|
*/
|
|
15
|
-
export declare function pickSystemLines(prompt: ProfileSystem, facts: Record<string, string>, fill: (text: string) => string): KeptSystemLine[];
|
|
13
|
+
export declare function pickSystemLines(prompt: ProfileSystem, facts: Record<string, string>, fill: (text: string) => string | undefined): KeptSystemLine[];
|
|
16
14
|
/** `where` names the prompt in the error. A bare `{ private }` must sit inside a line's own list. */
|
|
17
15
|
export declare function assertSystemLines(prompt: unknown, where: string): asserts prompt is ProfileSystem;
|
|
18
|
-
/** The first tool in `tools` with a path `
|
|
19
|
-
export declare function toolPathProblem(
|
|
16
|
+
/** The first tool in `tools` with a path `options.path` does not list, as a sentence. */
|
|
17
|
+
export declare function toolPathProblem(options: ProfileOptions | undefined, tools: readonly {
|
|
20
18
|
name: string;
|
|
21
19
|
paths?: readonly string[];
|
|
22
20
|
}[]): string | undefined;
|