@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.
Files changed (43) hide show
  1. package/README.md +3 -3
  2. package/esm/src/guardrails/boundaries.d.ts +2 -2
  3. package/esm/src/guardrails/boundaries.js +2 -2
  4. package/esm/src/guardrails/corpus/fuzz-inbound.js +4 -4
  5. package/esm/src/guardrails/corpus/live-attacks.d.ts +1 -1
  6. package/esm/src/guardrails/corpus/live-attacks.js +13 -9
  7. package/esm/src/guardrails/detect-at.js +1 -1
  8. package/esm/src/guardrails/sanitize.js +7 -7
  9. package/esm/src/guardrails/types.d.ts +1 -1
  10. package/esm/src/interface/from-profile.js +3 -1
  11. package/esm/src/interface/inputs.js +2 -3
  12. package/esm/src/interface/profile-interface.js +10 -11
  13. package/esm/src/interface/types.d.ts +3 -3
  14. package/esm/src/kernel/api-catalog.js +6 -5
  15. package/esm/src/kernel/engine/runner/gates.js +5 -4
  16. package/esm/src/kernel/engine/runner/schema-validation.d.ts +1 -1
  17. package/esm/src/kernel/engine/runner/schema-validation.js +9 -9
  18. package/esm/src/kernel/engine/session/mod.js +6 -6
  19. package/esm/src/kernel/mod.d.ts +1 -1
  20. package/esm/src/kernel/mod.js +1 -1
  21. package/esm/src/kernel/profile-presence.js +3 -3
  22. package/esm/src/kernel/profile-scope.js +12 -12
  23. package/esm/src/kernel/registry/ingress.d.ts +1 -2
  24. package/esm/src/kernel/registry/ingress.js +1 -18
  25. package/esm/src/kernel/registry/options.d.ts +18 -0
  26. package/esm/src/kernel/registry/options.js +98 -0
  27. package/esm/src/kernel/registry/profiles.js +16 -20
  28. package/esm/src/kernel/registry/resolve.js +6 -5
  29. package/esm/src/kernel/registry/system-prompt.js +7 -7
  30. package/esm/src/kernel/schema.js +20 -14
  31. package/esm/src/kernel/system-lines.d.ts +6 -8
  32. package/esm/src/kernel/system-lines.js +25 -68
  33. package/esm/src/kernel/tools/agent.d.ts +1 -1
  34. package/esm/src/kernel/tools/agent.js +11 -11
  35. package/esm/src/kernel/tools/resolve.js +1 -1
  36. package/esm/src/kernel/tools/types.d.ts +2 -2
  37. package/esm/src/kernel/types.d.ts +25 -30
  38. package/esm/src/providers/shared/upstream-tape.js +17 -1
  39. package/package.json +1 -1
  40. package/esm/src/kernel/registry/slot-fill.d.ts +0 -7
  41. package/esm/src/kernel/registry/slot-fill.js +0 -22
  42. package/esm/src/kernel/registry/slots.d.ts +0 -13
  43. package/esm/src/kernel/registry/slots.js +0 -31
@@ -1,8 +1,7 @@
1
1
  import { TheoremError } from '../guardrails/error.js';
2
+ import { optionsProblem, optionValues } from './registry/options.js';
2
3
  import { assertSystemPrompt } from './system-parts.js';
3
4
  import { checkHolds, checkProblem, splitWhen } from './tools/activity-label.js';
4
- const CONDITION_NAME = /^[A-Za-z_][\w-]*$/;
5
- const CONDITION_VALUE = /^\S+$/;
6
5
  function linesOf(prompt) {
7
6
  if (typeof prompt === 'string')
8
7
  return [[prompt]];
@@ -14,29 +13,13 @@ function textOf(part) {
14
13
  function headOf(parts) {
15
14
  return splitWhen(parts[0] === undefined ? '' : textOf(parts[0]));
16
15
  }
17
- function factsSchema(conditions, slots) {
16
+ function factsSchema(options) {
18
17
  const properties = {};
19
- for (const [name, values] of Object.entries({ ...conditions, ...slots })) {
20
- properties[name] = { type: 'string', enum: [...values] };
18
+ for (const [name, decl] of Object.entries(options)) {
19
+ properties[name] = { type: 'string', enum: optionValues(decl) };
21
20
  }
22
21
  return { type: 'object', properties };
23
22
  }
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
23
  function lineProblem(parts, schema) {
41
24
  if (parts.length === 0)
42
25
  return 'It has no wording to send.'; // labels-exempt: developer contract error
@@ -44,14 +27,14 @@ function lineProblem(parts, schema) {
44
27
  if (line.joined)
45
28
  return 'A prompt line can\'t start with "+"; every line that fits is sent.'; // labels-exempt: developer contract error
46
29
  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
30
+ return 'A line that opens with "when" needs an option and a colon, like "when path is web: …".'; // labels-exempt: developer contract error
48
31
  }
49
32
  for (const check of line.when) {
50
33
  if (check.path.includes('.'))
51
- return `"${check.path}" isn't one condition or slot.`; // labels-exempt: developer contract error
34
+ return `"${check.path}" isn't one option.`; // labels-exempt: developer contract error
52
35
  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');
36
+ return 'An option has no null value, so "is null" never fits.'; // labels-exempt: developer contract error
37
+ const problem = checkProblem(check, schema, 'this profile’s options');
55
38
  if (problem)
56
39
  return problem;
57
40
  }
@@ -60,12 +43,12 @@ function lineProblem(parts, schema) {
60
43
  }
61
44
  return undefined;
62
45
  }
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);
46
+ /** What is wrong with a prompt's options and lines, or undefined. */
47
+ export function systemLinesProblem(prompt, code, person) {
48
+ const declared = optionsProblem(code, person);
66
49
  if (declared)
67
50
  return declared;
68
- const schema = factsSchema(conditions, slots);
51
+ const schema = factsSchema({ ...code, ...person });
69
52
  for (const [at, parts] of linesOf(prompt).entries()) {
70
53
  const problem = lineProblem(parts, schema);
71
54
  if (problem)
@@ -73,35 +56,6 @@ export function systemLinesProblem(prompt, conditions, slots) {
73
56
  }
74
57
  return undefined;
75
58
  }
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
59
  function lineFits(line, facts) {
106
60
  if (line.when === 'unreadable')
107
61
  return false;
@@ -119,12 +73,14 @@ export function pickSystemLines(prompt, facts, fill) {
119
73
  const line = headOf(parts);
120
74
  if (!lineFits(line, facts))
121
75
  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
- }
76
+ const texts = parts.map((part, partAt) => fill(partAt === 0 ? line.text : textOf(part)));
77
+ // why: a part that prints an unset option has a hole, and half a line says something else.
78
+ if (texts.includes(undefined))
79
+ continue;
80
+ const pieces = parts.flatMap((part, partAt) => {
81
+ const text = texts[partAt];
82
+ return text ? [{ text, private: typeof part === 'string' ? !marked : true }] : [];
83
+ });
128
84
  kept.push({ line: at + 1, pieces });
129
85
  }
130
86
  return kept;
@@ -147,11 +103,12 @@ export function assertSystemLines(prompt, where) {
147
103
  assertSystemPrompt(line, `${where}[${at}]`);
148
104
  }
149
105
  }
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)
106
+ /** The first tool in `tools` with a path `options.path` does not list, as a sentence. */
107
+ export function toolPathProblem(options, tools) {
108
+ const path = options?.path;
109
+ if (!path)
154
110
  return undefined;
111
+ const known = optionValues(path);
155
112
  for (const tool of tools) {
156
113
  const bad = tool.paths?.find((path) => path !== '*' && !known.includes(path));
157
114
  if (bad !== undefined) {
@@ -43,7 +43,7 @@ declare function splitHostInput(tool: Pick<AgentToolDef, 'hostFields'>, input: A
43
43
  * called turn's own ingress checks MIME types and sizes.
44
44
  */
45
45
  declare function agentToolInputFor(agent: Pick<Profile, 'type'> & {
46
- inputs?: Pick<ProfileInputsSpec, 'attachments' | 'voice' | 'slots'>;
46
+ inputs?: Pick<ProfileInputsSpec, 'attachments' | 'voice' | 'options'>;
47
47
  }, tool?: Pick<AgentToolDef, 'name' | 'fieldText' | 'hostFields' | 'hostOnly'>): z.ZodType<AgentToolInput>;
48
48
  declare const agentToolOutput: z.ZodType<AgentToolOutput>;
49
49
  /** Why `profile` can't be run by an agent tool, or `undefined` when it can. */
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { TheoremError } from '../../guardrails/error.js';
3
- import { slotValues } from '../registry/slots.js';
3
+ import { optionValues } from '../registry/options.js';
4
4
  import { interactionPartSchema, keptReply, sourceSchema } from '../turn-events.js';
5
5
  import { findLast } from '../util/find-last.js';
6
6
  import { profileToolAllow } from './resolve.js';
@@ -31,11 +31,11 @@ const speechInput = z.strictObject({
31
31
  style: z.string().optional(),
32
32
  speed: z.number().positive().optional(),
33
33
  });
34
- /** One choice per declared slot; a slot or a value the profile does not declare is refused. */
35
- function slotsInput(slots) {
36
- return z.strictObject(Object.fromEntries(Object.entries(slots).map(([slot, decl]) => {
37
- const choices = slotValues(decl);
38
- return [slot, z.enum(choices).optional()];
34
+ /** One value per declared option; an option or a value the profile does not declare is refused. */
35
+ function optionsInput(options) {
36
+ return z.strictObject(Object.fromEntries(Object.entries(options).map(([name, decl]) => {
37
+ const choices = optionValues(decl);
38
+ return [name, z.enum(choices).optional()];
39
39
  })));
40
40
  }
41
41
  /** The fields an agent tool's input can carry to the called agent; a host field takes none of these names. */
@@ -43,7 +43,7 @@ const AGENT_INPUT_FIELDS = new Set([
43
43
  'text',
44
44
  'attachments',
45
45
  'voice',
46
- 'slots',
46
+ 'options',
47
47
  'speech',
48
48
  ]);
49
49
  /**
@@ -60,13 +60,13 @@ function splitHostInput(tool, input) {
60
60
  if (all[field] !== undefined)
61
61
  hostInput[field] = all[field];
62
62
  }
63
- const { text, attachments, voice, slots, speech } = input;
63
+ const { text, attachments, voice, options, speech } = input;
64
64
  return {
65
65
  sent: {
66
66
  text,
67
67
  ...(attachments ? { attachments } : {}),
68
68
  ...(voice ? { voice } : {}),
69
- ...(slots ? { slots } : {}),
69
+ ...(options ? { options } : {}),
70
70
  ...(speech ? { speech } : {}),
71
71
  },
72
72
  hostInput,
@@ -85,8 +85,8 @@ function agentToolInputFor(agent, tool) {
85
85
  }
86
86
  if (inputs?.voice)
87
87
  shape.voice = z.array(blobInput).optional();
88
- if (inputs?.slots)
89
- shape.slots = slotsInput(inputs.slots).optional();
88
+ if (inputs?.options)
89
+ shape.options = optionsInput(inputs.options).optional();
90
90
  if (agent.type === 'speech')
91
91
  shape.speech = speechInput.optional();
92
92
  for (const channel of tool?.hostOnly ?? []) {
@@ -125,7 +125,7 @@ function assertToolPathsDeclared(tools, profile) {
125
125
  if (profile.type !== 'text' && profile.type !== 'image' && profile.type !== 'live')
126
126
  return;
127
127
  const allowed = profileToolAllow(profile).flatMap((id) => tools.get(id) ?? []);
128
- const problem = toolPathProblem(profile.identity.conditions, allowed);
128
+ const problem = toolPathProblem(profile.identity.options, allowed);
129
129
  if (problem)
130
130
  throw new TheoremError('config', `Profile ${profile.id}: ${problem}`); // labels-exempt: developer contract error
131
131
  }
@@ -283,7 +283,7 @@ export interface McpSessionLimits {
283
283
  * What an agent tool call carries: the text, and whatever else the called
284
284
  * profile's `inputs` declares. `speech` is for a speech profile.
285
285
  */
286
- export interface AgentToolInput extends Pick<TurnInput, 'slots' | 'attachments' | 'voice'> {
286
+ export interface AgentToolInput extends Pick<TurnInput, 'options' | 'attachments' | 'voice'> {
287
287
  text: string;
288
288
  speech?: TurnSpeech;
289
289
  }
@@ -299,7 +299,7 @@ export interface AgentToolOutput {
299
299
  sources?: Source[];
300
300
  }
301
301
  /** A channel of an agent tool's input that the called profile's `inputs` declares. */
302
- export type AgentToolChannel = 'attachments' | 'voice' | 'slots';
302
+ export type AgentToolChannel = 'attachments' | 'voice' | 'options';
303
303
  /**
304
304
  * A tool whose call runs one turn of another registered agent. That agent is a
305
305
  * standalone profile; the tool is how another agent's model calls it. Its input
@@ -180,8 +180,8 @@ export interface AttachmentValidationIssue {
180
180
  params?: AttachmentValidationParams;
181
181
  fileName?: string;
182
182
  }
183
- /** Picks the structured-output schema by the value of a turn slot, with a fallback. */
184
- export interface StructuredBySlot {
183
+ /** Picks the structured-output schema by the value of a turn's option, with a fallback. */
184
+ export interface StructuredByOption {
185
185
  by: string;
186
186
  map: Record<string, string>;
187
187
  fallback: string;
@@ -194,7 +194,7 @@ export interface ValidationResult {
194
194
  data?: Record<string, unknown>;
195
195
  }
196
196
  /** A host function that checks one structured-output field. */
197
- export type ProfileValidator = (candidate: unknown, slots?: Record<string, string>) => ValidationResult | Promise<ValidationResult>;
197
+ export type ProfileValidator = (candidate: unknown, options?: Readonly<Record<string, string>>) => ValidationResult | Promise<ValidationResult>;
198
198
  /** A tool call the turn completed, as an item check reads it. */
199
199
  export interface TurnToolResult {
200
200
  tool: string;
@@ -203,7 +203,8 @@ export interface TurnToolResult {
203
203
  }
204
204
  /** What an item check reads of the turn whose reply it is checking. */
205
205
  export interface ItemCheckTurn {
206
- slots?: Record<string, string>;
206
+ /** The value of each option the turn set. */
207
+ options?: Readonly<Record<string, string>>;
207
208
  /** Every tool call the turn completed, in order, across its attempts. */
208
209
  toolResults: readonly TurnToolResult[];
209
210
  }
@@ -336,24 +337,18 @@ export interface ProfileModelFields {
336
337
  /** Tool-loop ceiling. Omit = `DEFAULT_MAX_STEPS`; `1` = one-shot; `> 1` = hard cap. */
337
338
  maxSteps?: number;
338
339
  }
339
- /**
340
- * One allowed value for an `inputs.slots` entry. `value` is what the turn sends and what
341
- * `{name}` fills; optional `description` is visitor-facing UI copy only.
342
- */
343
- export interface SlotChoice {
340
+ /** One value an option can take. `description` is what a picker shows beside it. */
341
+ export interface OptionChoice {
344
342
  value: string;
345
343
  description?: string;
346
344
  }
347
- /**
348
- * One named slot: optional group `label` for the UI, and its choices. A bare `string[]` is
349
- * still accepted on define and normalized to `{ choices: [{ value }] }`.
350
- */
351
- export interface SlotDecl {
345
+ /** One named option: its `label` for a picker, and the values it can take. */
346
+ export interface OptionDecl {
352
347
  label?: string;
353
- choices: SlotChoice[];
348
+ choices: OptionChoice[];
354
349
  }
355
- /** Authoring form for one slot: legacy value list, or a labeled declaration. */
356
- export type SlotDeclInput = string[] | SlotDecl;
350
+ /** A profile's options by name. Which object holds them says who drives them. */
351
+ export type ProfileOptions = Readonly<Record<string, OptionDecl>>;
357
352
  /** What a profile accepts as input. */
358
353
  export interface ProfileInputsSpec {
359
354
  text?: boolean;
@@ -367,11 +362,12 @@ export interface ProfileInputsSpec {
367
362
  maxBytes?: number;
368
363
  maxTurnBytes?: number;
369
364
  limitsByMime?: Record<string, number>;
370
- slots?: Record<string, SlotDeclInput>;
365
+ /** The options a person picks: a host shows each one as a picker. */
366
+ options?: ProfileOptions;
371
367
  context?: ProfileContextSpec;
372
368
  }
373
369
  /** What a live profile declares beside its ingress channels. */
374
- export type LiveInputsSpec = Pick<ProfileInputsSpec, 'slots' | 'context'>;
370
+ export type LiveInputsSpec = Pick<ProfileInputsSpec, 'options' | 'context'>;
375
371
  /** Who may send a turn its context, and how much. */
376
372
  export interface ProfileContextSpec {
377
373
  from: ContextSender[];
@@ -381,7 +377,7 @@ export interface ProfileContextSpec {
381
377
  export type TurnContext = Partial<Record<ContextSender, unknown>>;
382
378
  /** What a profile returns: its structured schema, validation, and streaming. */
383
379
  export interface ProfileOutputsSpec {
384
- structured?: StructuredSchemaId | StructuredBySlot | null;
380
+ structured?: StructuredSchemaId | StructuredByOption | null;
385
381
  validation?: ProfileValidationSpec;
386
382
  streaming?: ProfileStreamingSpec;
387
383
  }
@@ -401,8 +397,6 @@ export type SystemPrompt = string | readonly SystemPart[];
401
397
  export type SystemLine = string | readonly SystemPart[];
402
398
  /** A profile's prompt: a string, or lines. Every line that fits is sent, a blank line apart. */
403
399
  export type ProfileSystem = string | readonly SystemLine[];
404
- /** The facts a host states on each turn, by name, each with the values it can take. */
405
- export type ProfileConditions = Readonly<Record<string, readonly string[]>>;
406
400
  /** A stretch of the system prompt as sent, and whether a reply may repeat it. */
407
401
  export interface SystemPiece {
408
402
  text: string;
@@ -411,8 +405,8 @@ export interface SystemPiece {
411
405
  /** A profile's handle and system prompt. */
412
406
  export interface ProfileIdentity {
413
407
  handle: string;
414
- /** The facts this agent's turns state, by name, with the values each can take. */
415
- conditions?: ProfileConditions;
408
+ /** The options the host's code states. A person never sees them. */
409
+ options?: ProfileOptions;
416
410
  system?: ProfileSystem;
417
411
  }
418
412
  /** The fields every profile type shares. */
@@ -728,10 +722,11 @@ export interface TurnRepairRequest {
728
722
  rejection: string;
729
723
  guidance?: string;
730
724
  }
731
- /** What the user sent for a turn: text, slots, attachments, voice, and history. */
725
+ /** What the user sent for a turn: text, options, attachments, voice, and history. */
732
726
  export interface TurnInput {
733
727
  text?: string;
734
- slots?: Record<string, string>;
728
+ /** The value picked for each of the profile's `inputs.options`. */
729
+ options?: Readonly<Record<string, string>>;
735
730
  /** What the page or the host wants the model to know, by sender; the profile's `inputs.context` allows it. */
736
731
  context?: TurnContext;
737
732
  attachments?: Array<TurnBlob | TurnMediaRef>;
@@ -785,8 +780,8 @@ export interface AgentRunRequest extends RunControls, ModelChoice {
785
780
  sessionPermissions?: string[];
786
781
  /** Host channel/path for catalog `paths` filtering. */
787
782
  path?: string;
788
- /** This run's facts, one value for each of `profile.identity.conditions` but `path`. */
789
- conditions?: Readonly<Record<string, string>>;
783
+ /** This run's value for each of `profile.identity.options` it sets; `path` is the run's own. */
784
+ options?: Readonly<Record<string, string>>;
790
785
  /**
791
786
  * Opaque application context handed to tool `handler` / `preTool` and
792
787
  * `tools.t1Policy` as `ctx.host`. The kernel never reads, logs, traces, or
@@ -971,8 +966,8 @@ export interface SessionRequest extends AgentRunRequest {
971
966
  /** Override `profile.live.voice` for this session. */
972
967
  voice?: string;
973
968
  history?: TurnHistoryMessage[];
974
- /** The value chosen for each of the profile's `inputs.slots`. */
975
- slots?: Record<string, string>;
969
+ /** The value picked for each of the profile's `inputs.options`. */
970
+ inputOptions?: Record<string, string>;
976
971
  /** What the page and the host tell the agent as the call opens; `sendContext` replaces it later. */
977
972
  context?: TurnContext;
978
973
  /** How long the caller was away before this resume, in milliseconds. The session keeps no clock across calls. */
@@ -12,6 +12,11 @@ import { mapStrings } from '../../kernel/engine/tree.js';
12
12
  * - `{ b64_json, media_type }`: OpenRouter `/images` `data[]` entries.
13
13
  * - a `data:<mime>;base64,<bytes>` string: OpenRouter chat
14
14
  * `message.images[].image_url.url`.
15
+ * - a part that names its own bytes by `type`, with no mime: Interactions
16
+ * `image` deltas (`data`, probed 30/10/2026), its signatures (`signature` on
17
+ * a `thought_signature` delta, a `thought` or a `function_call`; 1 000 384
18
+ * characters on one image call, 02/11/2026), and OpenRouter's
19
+ * `reasoning.encrypted` (`data`).
15
20
  *
16
21
  * The hash covers the raw bytes, the same hash a trace blob part carries. A
17
22
  * record whose bytes were hashed carries `dataKind: 'sha256'`; a hashed data
@@ -19,6 +24,15 @@ import { mapStrings } from '../../kernel/engine/tree.js';
19
24
  * hashed as text and says so: `dataKind: 'text_sha256'`, `data:<mime>;text_sha256,<hex>`.
20
25
  */
21
26
  const DATA_URL = /^data:([^;,]+);base64,/;
27
+ /** Where a part with no mime holds its bytes, by its `type`. */
28
+ const BYTES_KEY_BY_TYPE = new Map([
29
+ ['image', 'data'],
30
+ ['audio', 'data'],
31
+ ['thought_signature', 'signature'],
32
+ ['thought', 'signature'],
33
+ ['function_call', 'signature'],
34
+ ['reasoning.encrypted', 'data'],
35
+ ]);
22
36
  export function inlineBytesKey(rec) {
23
37
  const mime = rec.mime_type ?? rec.mimeType;
24
38
  if (typeof mime === 'string' && typeof rec.data === 'string') {
@@ -27,7 +41,9 @@ export function inlineBytesKey(rec) {
27
41
  if (typeof rec.media_type === 'string' && typeof rec.b64_json === 'string') {
28
42
  return 'b64_json';
29
43
  }
30
- return undefined;
44
+ const key = typeof rec.type === 'string' ? BYTES_KEY_BY_TYPE.get(rec.type) : undefined;
45
+ // why: A call carries an empty `signature` when its thought held the real one; that is no bytes.
46
+ return key && typeof rec[key] === 'string' && rec[key] !== '' ? key : undefined;
31
47
  }
32
48
  const BYTES_SHA256 = 'sha256';
33
49
  const TEXT_SHA256 = 'text_sha256';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/agents",
3
- "version": "0.3.4-next.757.gde44a4d",
3
+ "version": "0.3.4-next.759.g46e0e27",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
5
5
  "keywords": [
6
6
  "agent",
@@ -1,7 +0,0 @@
1
- import type { Profile } from '../types.js';
2
- /**
3
- * Replaces each `{name}` that names one of the profile's slots with the value the request chose.
4
- * A `{name}` that is no slot stays as written. A prompt that uses a slot the request left
5
- * unfilled is a request error. Every value is one the profile lists, so no free text is written.
6
- */
7
- export declare function fillSlots(profile: Profile, text: string, slots: Record<string, string> | undefined, where: string): string;
@@ -1,22 +0,0 @@
1
- import { TheoremError } from '../../guardrails/error.js';
2
- import { profileInputs } from './catalog.js';
3
- const SLOT_REF = /\{([A-Za-z_][\w-]*)\}/g;
4
- /**
5
- * Replaces each `{name}` that names one of the profile's slots with the value the request chose.
6
- * A `{name}` that is no slot stays as written. A prompt that uses a slot the request left
7
- * unfilled is a request error. Every value is one the profile lists, so no free text is written.
8
- */
9
- export function fillSlots(profile, text, slots, where) {
10
- const declared = profileInputs(profile)?.slots;
11
- if (!declared)
12
- return text;
13
- return text.replace(SLOT_REF, (whole, name) => {
14
- if (!Object.hasOwn(declared, name))
15
- return whole;
16
- const value = slots && Object.hasOwn(slots, name) ? slots[name] : undefined;
17
- if (value === undefined) {
18
- throw new TheoremError('request', `Profile ${profile.id}: ${where} uses slot '${name}', and the request chose no value for it`);
19
- }
20
- return value;
21
- });
22
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Slot declaration helpers: normalize authoring forms and read choice values for
3
- * validation and fillSlots. Descriptions and labels are UI-only.
4
- */
5
- import type { ProfileInputsSpec, SlotDecl, SlotDeclInput } from '../types.js';
6
- /** The allowed values of one slot declaration (legacy list or labeled form). */
7
- export declare function slotValues(decl: SlotDeclInput): string[];
8
- /** Canonical slot declaration: always `{ choices }`, optional `label`. */
9
- export declare function normalizeSlotDecl(decl: SlotDeclInput): SlotDecl;
10
- /** Canonical `inputs.slots`, or undefined when none. */
11
- export declare function normalizeSlots(slots: Record<string, SlotDeclInput> | undefined): Record<string, SlotDecl> | undefined;
12
- /** Profile inputs with every slot normalized (labels/descriptions preserved). */
13
- export declare function normalizeProfileInputsSlots<T extends ProfileInputsSpec | undefined>(inputs: T): T;
@@ -1,31 +0,0 @@
1
- /** The allowed values of one slot declaration (legacy list or labeled form). */
2
- export function slotValues(decl) {
3
- return Array.isArray(decl) ? [...decl] : decl.choices.map((choice) => choice.value);
4
- }
5
- /** Canonical slot declaration: always `{ choices }`, optional `label`. */
6
- export function normalizeSlotDecl(decl) {
7
- if (Array.isArray(decl)) {
8
- return { choices: decl.map((value) => ({ value })) };
9
- }
10
- return {
11
- ...(decl.label !== undefined && decl.label !== '' ? { label: decl.label } : {}),
12
- choices: decl.choices.map((choice) => ({
13
- value: choice.value,
14
- ...(choice.description !== undefined && choice.description !== ''
15
- ? { description: choice.description }
16
- : {}),
17
- })),
18
- };
19
- }
20
- /** Canonical `inputs.slots`, or undefined when none. */
21
- export function normalizeSlots(slots) {
22
- if (!slots)
23
- return undefined;
24
- return Object.fromEntries(Object.entries(slots).map(([name, decl]) => [name, normalizeSlotDecl(decl)]));
25
- }
26
- /** Profile inputs with every slot normalized (labels/descriptions preserved). */
27
- export function normalizeProfileInputsSlots(inputs) {
28
- if (!inputs?.slots)
29
- return inputs;
30
- return { ...inputs, slots: normalizeSlots(inputs.slots) };
31
- }