@theoremjs/agents 0.3.4-next.677.g14b70fe → 0.3.4-next.693.g4ab1526

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 (61) hide show
  1. package/README.md +4 -3
  2. package/esm/mod.d.ts +3 -1
  3. package/esm/mod.js +2 -0
  4. package/esm/src/cli/commands/bench.js +4 -10
  5. package/esm/src/cli/commands/profile.js +4 -1
  6. package/esm/src/guardrails/labels.d.ts +1 -1
  7. package/esm/src/guardrails/labels.js +3 -0
  8. package/esm/src/interface/blocks.js +19 -0
  9. package/esm/src/interface/from-profile.d.ts +2 -2
  10. package/esm/src/interface/from-profile.js +7 -0
  11. package/esm/src/interface/mod.d.ts +1 -1
  12. package/esm/src/interface/profile-interface.js +14 -4
  13. package/esm/src/interface/types.d.ts +6 -4
  14. package/esm/src/kernel/api-catalog.js +5 -5
  15. package/esm/src/kernel/auth/oauth.js +3 -1
  16. package/esm/src/kernel/engine/runner/mod.js +1 -0
  17. package/esm/src/kernel/engine/session/mod.js +1 -0
  18. package/esm/src/kernel/engine/session/session-trace.js +1 -0
  19. package/esm/src/kernel/mod.d.ts +3 -1
  20. package/esm/src/kernel/mod.js +2 -0
  21. package/esm/src/kernel/profile-presence.js +1 -0
  22. package/esm/src/kernel/profile-scope.js +23 -21
  23. package/esm/src/kernel/protocols/protocol.d.ts +1 -1
  24. package/esm/src/kernel/protocols/protocol.js +1 -0
  25. package/esm/src/kernel/registry/catalog.js +4 -1
  26. package/esm/src/kernel/registry/ingress.d.ts +3 -1
  27. package/esm/src/kernel/registry/ingress.js +12 -1
  28. package/esm/src/kernel/registry/profile-outputs.js +2 -1
  29. package/esm/src/kernel/registry/profiles.d.ts +12 -2
  30. package/esm/src/kernel/registry/profiles.js +37 -7
  31. package/esm/src/kernel/registry/resolve.js +9 -5
  32. package/esm/src/kernel/registry/system-prompt.d.ts +6 -1
  33. package/esm/src/kernel/registry/system-prompt.js +20 -13
  34. package/esm/src/kernel/schema.d.ts +1 -1
  35. package/esm/src/kernel/schema.js +12 -8
  36. package/esm/src/kernel/system-lines.d.ts +22 -0
  37. package/esm/src/kernel/system-lines.js +162 -0
  38. package/esm/src/kernel/tools/activity-label.d.ts +15 -0
  39. package/esm/src/kernel/tools/activity-label.js +12 -7
  40. package/esm/src/kernel/tools/agent.js +1 -1
  41. package/esm/src/kernel/tools/call-order.d.ts +16 -0
  42. package/esm/src/kernel/tools/call-order.js +48 -0
  43. package/esm/src/kernel/tools/registry.js +9 -6
  44. package/esm/src/kernel/tools/resolve.js +11 -0
  45. package/esm/src/kernel/tools/stage-run.d.ts +1 -1
  46. package/esm/src/kernel/tools/stage-run.js +57 -55
  47. package/esm/src/kernel/tools/types.d.ts +3 -0
  48. package/esm/src/kernel/types.d.ts +31 -4
  49. package/esm/src/observability/trace-catalog.js +3 -0
  50. package/esm/src/providers/google/interactions/steps.js +14 -3
  51. package/esm/src/providers/mod.d.ts +2 -0
  52. package/esm/src/providers/mod.js +1 -0
  53. package/esm/src/providers/openrouter/protocol.d.ts +26 -0
  54. package/esm/src/providers/openrouter/protocol.js +58 -2
  55. package/esm/src/providers/openrouter/provider.d.ts +1 -1
  56. package/esm/src/providers/openrouter/provider.js +3 -1
  57. package/esm/src/providers/openrouter/transcriptions-protocol.d.ts +10 -0
  58. package/esm/src/providers/openrouter/transcriptions-protocol.js +87 -0
  59. package/package.json +1 -1
  60. package/esm/src/kernel/registry/system-role.d.ts +0 -3
  61. package/esm/src/kernel/registry/system-role.js +0 -9
package/README.md CHANGED
@@ -188,6 +188,7 @@ Use the `type` field to choose what the agent does. The type sets the shape of t
188
188
  | `text` | `runTurn` | text, attachments, voice notes, slots, history | text, thoughts, validated JSON, tool calls | `geminiInteractions`, `openRouterOpenAi`, `openAi` |
189
189
  | `image` | `runTurn` | prompt + reference images | images, optionally with interleaved text | `geminiInteractions`, `openRouterImages` |
190
190
  | `speech` | `runTurn` | text | audio (WAV, or MP3 on OpenRouter) | `geminiInteractions`, `openRouterOpenAi`, `openAi` |
191
+ | `transcription` | `runTurn` | one voice clip | the words in the clip, as text | `openRouterTranscriptions` |
191
192
  | `live` | `runSession` | realtime mic audio, camera frames, typed text | streamed audio, transcripts, tool calls | `geminiLive` |
192
193
  | `host` | `invokeTool`, `invokeToolStep`, `runTool`, `runToolStep` | tool calls from your own code, one at a time or as a step; the `run` pair gives how each call ended | guarded tool results | none; it never calls a model |
193
194
  | `decision` | `runDecision` | non-null JSON state plus declared questions | typed choices, probabilities, scores, boxes, or `noul` | `systemOne`, `openRouterDecisions` |
@@ -317,7 +318,7 @@ The binding under `models` names the protocol, the registered provider ID, and t
317
318
  | Provider | ID | Protocols |
318
319
  | :--- | :--- | :--- |
319
320
  | `geminiProvider` | `gemini` | `geminiInteractions` (text, image, speech), `geminiLive` (live), `geminiEmbeddings` (embedding) |
320
- | `openRouterProvider` | `openrouter` | `openRouterOpenAi` (text, speech), `openRouterImages` (image), `openRouterDecisions` (decision), `openRouterEmbeddings` (embedding) |
321
+ | `openRouterProvider` | `openrouter` | `openRouterOpenAi` (text, speech), `openRouterImages` (image), `openRouterTranscriptions` (transcription), `openRouterDecisions` (decision), `openRouterEmbeddings` (embedding) |
321
322
  | `typesafeProvider` | `typesafe` | `systemOne` (decision) |
322
323
  | `localProvider` | `local` | `openAi` (text, speech), `ollamaEmbeddings` (embedding), for a server such as Ollama |
323
324
 
@@ -461,7 +462,7 @@ Named exports from the root barrel (same symbols hosts get from `@theoremjs/agen
461
462
  | Catalog | `clampThinkingLevel`, `clampThinkingLevelForApiId`, `mediaChannelForMime`, `MediaInputChannel`, `mediaKindForMime`, `mimeAllowed`, `mimeEssence`, `modelEntryByApiId`, `requireModelBinding` |
462
463
  | Schema | `PROFILE_FIELDS`, `PROFILE_GRAPH`, `PROFILE_TYPES`, `PROFILE_ID_MAX_CHARS`, `PROFILE_HANDLE_MAX_CHARS`, `EXTRA_FIELDS`, `REQUEST_FIELDS`, `API_EXPORTS`, `fieldMeta`, `catalogPathFor`, `DYNAMIC_FIELD_PARENTS`, `spineFacetsForProfileType`, `profileGraphFacet`, `ProfileGraphFacet`, `ProfileGraphFacetId`, `ProfileGraphEditor`, `ProfileGraphRole`, `THINKING_LEVELS`, `KEY_SLOT_NAME`, `isKeySlotName`, `MEDIA_INPUT_KINDS`, `MEDIA_INPUT_KIND_VALUES`, `MEDIA_WILDCARDS`, `ATTACHMENT_ACCEPT_MIMES`, `IMAGE_ATTACHMENT_ACCEPT_MIMES`, `VOICE_ACCEPT_MIMES`, `SUMMARY_MODES`, `STREAM_MODES`, `SPEECH_AUDIO_FORMATS`, `COMPACTION_METERS`, `COMPACTION_OUTCOMES`, `COMPACTION_TIMINGS`, `CACHE_MODES`, `CACHE_TTLS`, `TURN_STAGES`, `TURN_INJECT_STAGES`, `TURN_STOP_KINDS`, `CONTINUE_STOP_KINDS`, `TOOL_GATE_KINDS`, `AWAITING_USER_INPUT_KINDS`, `AWAITING_USER_INPUT_STATUS`, `TOOL_LOAD_TIERS`, `TOOL_ACCESS`, `TOOL_PERMISSION`, `TOOL_TYPES`, `AUTH_UNAUTHENTICATED_POLICIES`, `HTTP_METHODS`, `STUDIO_AUTH_TYPES`, `TOOL_AUTH_TYPES`, `AuthUnauthenticatedPolicy`, `CustomToolType`, `HttpMethod`, `StudioAuthType`, `ToolAccess`, `ToolAuthType`, `ToolPermission`, `ToolType`, `LIVE_ACTIVITY_HANDLINGS`, `LIVE_START_SENSITIVITIES`, `LIVE_END_SENSITIVITIES` |
463
464
  | Scope | `KernelScope`, `createKernelScope`, `defaultKernelScope`, `KernelRegistry`, `createKernelRegistry` |
464
- | Profiles | `ProfileDefinition`, `ProfileDefinitionBase`, `TextProfileDefinition`, `ImageProfileDefinition`, `SpeechProfileDefinition`, `LiveProfileDefinition`, `HostProfileDefinition`, `DecisionProfileDefinition`, `EmbeddingProfileDefinition`, `ProfileRegistry`, `createProfileRegistry`, `clearProfiles`, `defineProfile`, `getProfile`, `hasProfile`, `listProfiles`, `registerProfile`, `registerProfiles`, `projectProfile`, `resolveTurn`, `pickModel` |
465
+ | Profiles | `ProfileDefinition`, `ProfileDefinitionBase`, `TextProfileDefinition`, `ImageProfileDefinition`, `SpeechProfileDefinition`, `TranscriptionProfileDefinition`, `LiveProfileDefinition`, `HostProfileDefinition`, `DecisionProfileDefinition`, `EmbeddingProfileDefinition`, `ProfileRegistry`, `createProfileRegistry`, `clearProfiles`, `defineProfile`, `getProfile`, `hasProfile`, `listProfiles`, `registerProfile`, `registerProfiles`, `projectProfile`, `resolveTurn`, `pickModel`, `resolveTurnSystemPrompt`, `systemLinesProblem` |
465
466
  | Tools | `ToolContext`, `GateReference`, `gateReferenceSchema`, `ToolRegistry`, `createToolRegistry`, `registerTool`, `registerTools`, `invokeTool`, `invokeToolStep`, `runTool`, `runToolStep`, `SettledToolCall`, `ToolCallResult`, `ToolStepCallResult`, `GATE_DECISIONS`, `GateDecision`, `askUserTool`, `registerHarnessTools`, `getTool`, `hasTool`, `requireTool`, `listTools`, `resetTools`, `formatToolResult`, `prepareTurnToolSnapshot`, `buildHttpToolTarget`, `executeHttpTool`, `executeMcpTool`, `parseMcpRpcResponse`, `isUnsupportedMcpProtocolError`, `MCP_PROTOCOL_VERSIONS`, `mcpRequestMeta`, `McpProtocolVersion`, `resolveToolAuth`, `credentialPlacement`, `withCredentialQuery`, `CredentialQuery`, `uncheckedOutput`, `UncheckedOutput`, `McpRpcResponse`, `ModelToolResult`, `PageAnswer` |
466
467
  | Tool execution | `ToolExecutionCoordinator`, `createMemoryToolExecution`, `MemoryToolExecutionOptions`, `authorizeToolReplay`, `BeginToolOperationResult`, `ToolOperationClaim`, `ToolOperationIdentity`, `ToolOperationOutcome`, `ToolOperationUncertainty`, `toolOperationOutcomeSchema`, `SavedToolInvocation`, `savedToolInvocationSchema`, `toolInvocationHash`, `TerminalToolEvent`, `PageToolDispatch`, `PageToolExecution` |
467
468
  | Structured | `SchemaRegistry`, `createSchemaRegistry`, `getStructured`, `registerStructured` |
@@ -471,7 +472,7 @@ Named exports from the root barrel (same symbols hosts get from `@theoremjs/agen
471
472
  | Observability | `memorySink`, `noopSink`, `readTraceparent`, `writeTrace`, `buildRecord`, `traceRecordSchema`, `contentOf`, `inlineContent`, `toOtlpJson`, `startTrace`, `traceContent`, `traceBytes`, `traceJson`, `registerTraceDestination`, `requireTraceDestination`, `getTraceDestination`, `listTraceDestinationIds`, `clearTraceDestinations`, `isTraceSink`, `resolveTraceWriter`, `resolveObservabilityPolicy`, `traceSpanMeta`, `traceAttributeMeta`, `traceEventMeta`, `traceEventAttributeMeta`, `TRACE_ATTRIBUTE_GROUPS`, `TRACE_STATUS`, `TRACE_FIELDS`, `TRACE_SPAN_TYPES`, `TraceSpanMeta`, `TraceSpanType`, `TraceAttributeMeta`, `TraceEventMeta`, `TraceOptionMeta`, `TraceAttributeGroup`, `TraceValueFormat`, `TraceRecord`, `TraceSink`, `TraceWriteContext`, `TraceSpan`, `TraceSpanEvent`, `TraceSpanKind`, `TraceSpanLink`, `TraceSpanStatus`, `TraceAttributes`, `TraceAttributeValue`, `TraceContent`, `TraceBytes`, `TraceJson`, `TraceTree`, `SpanHandle`, `SpanOptions`, `SpanLinkInput`, `TraceClock`, `ProfileObservabilitySpec`, `ResolvedObservabilityPolicy`, `ResolvedTraceInclude`, `ResolvedTraceScrub`, `TraceIncludeSpec`, `TraceScrubSpec`, `ScrubSwitch`, `ResolvedScrubSwitch`, `OtlpTraceRequest`, `OtlpSpan`, `OtlpKeyValue`, `OtlpAnyValue` (file sink: `@theoremjs/agents/observability/jsonl` → `jsonlSink`, `JsonlSinkOptions`) |
472
473
  | Providers | `registerProvider`, `getProvider`, `listProviders`, `listProtocols`, `createProviderRegistry`, `defineProvider`, `Provider`, `ProviderDefinition`, `Registration`, `RegisteredProvider`, `ProviderRegistry`, `geminiProvider`, `openRouterProvider`, `typesafeProvider`, `localProvider` |
473
474
  | Provider sign-in | `bearer`, `header`, `query`, `Authorize`, `Signer`, `Outgoing`, `Serve`, `endpointUrlSchema` |
474
- | Protocols | `defineProtocol`, `extendProtocol`, `carriesTo`, `modelOptions`, `geminiInteractions`, `geminiLive`, `geminiEmbeddings`, `openAi`, `openRouterOpenAi`, `openRouterImages`, `openRouterDecisions`, `openRouterEmbeddings`, `ollamaEmbeddings`, `systemOne`, `Protocol`, `ProtocolDefinition`, `ProtocolExtension`, `ExtensionBodyAt`, `ExtensionReader`, `ModelProfileType` |
475
+ | Protocols | `defineProtocol`, `extendProtocol`, `carriesTo`, `modelOptions`, `geminiInteractions`, `geminiLive`, `geminiEmbeddings`, `openAi`, `openRouterOpenAi`, `openRouterImages`, `openRouterTranscriptions`, `openRouterDecisions`, `openRouterEmbeddings`, `ollamaEmbeddings`, `systemOne`, `Protocol`, `ProtocolDefinition`, `ProtocolExtension`, `ExtensionBodyAt`, `ExtensionReader`, `ModelProfileType` |
475
476
  | Protocol operations | `ProtocolContext`, `ProtocolOperations`, `ProtocolRequest`, `ProtocolSession`, `ProtocolSocket`, `ProtocolEvent`, `ProtocolContentEvent`, `SendInit`, `UpstreamFailure`, `Continuation`, `DecisionCall`, `EmbeddingCall`, `LiveToolResult`, `callProtocol`, `ProtocolCall`, `CallSetup` |
476
477
  | Model bindings | `ModelBinding`, `DecisionModelBinding`, `modelBindingSchema`, `decisionModelBindingSchema`, `commonModelSettingsSchema`, `keySlotSchema`, `checkBinding`, `keySlotsOf`, `RuntimeAbilities` |
477
478
  | Provider data | `JsonValue`, `JsonObject`, `jsonValueSchema`, `jsonObjectSchema`, `PriceTable`, `ModelPrice`, `Rates` |
package/esm/mod.d.ts CHANGED
@@ -50,11 +50,12 @@ export type { EmbeddingRules } from './src/kernel/registry/embedding-rules.js';
50
50
  export { embeddingMediaIssues, embeddingRules } from './src/kernel/registry/embedding-rules.js';
51
51
  export type { KernelRegistry } from './src/kernel/registry/kernel-registry.js';
52
52
  export { createKernelRegistry } from './src/kernel/registry/kernel-registry.js';
53
- export type { EmbeddingProfileDefinition, ImageProfileDefinition, LiveProfileDefinition, ProfileDefinition, ProfileDefinitionBase, ProfileRegistry, SpeechProfileDefinition, TextProfileDefinition, } from './src/kernel/registry/profiles.js';
53
+ export type { EmbeddingProfileDefinition, ImageProfileDefinition, LiveProfileDefinition, ProfileDefinition, ProfileDefinitionBase, ProfileRegistry, SpeechProfileDefinition, TextProfileDefinition, TranscriptionProfileDefinition, } from './src/kernel/registry/profiles.js';
54
54
  export { createProfileRegistry, defineProfile } from './src/kernel/registry/profiles.js';
55
55
  export { pickModel } from './src/kernel/registry/resolve.js';
56
56
  export type { SchemaRegistry } from './src/kernel/registry/schemas.js';
57
57
  export { createSchemaRegistry } from './src/kernel/registry/schemas.js';
58
+ export { resolveTurnSystemPrompt } from './src/kernel/registry/system-prompt.js';
58
59
  export type { AuthUnauthenticatedPolicy, ContinueStopKind, CustomToolType, HttpMethod, StepLimitMode, StudioAuthType, ToolAccess, ToolAuthType, ToolPermission, ToolType, TurnStopKind, } from './src/kernel/schema.js';
59
60
  export { API_EXPORTS, ATTACHMENT_ACCEPT_MIMES, AUTH_UNAUTHENTICATED_POLICIES, AWAITING_USER_INPUT_KINDS, AWAITING_USER_INPUT_STATUS, COMPACTION_METERS, COMPACTION_OUTCOMES, COMPACTION_TIMINGS, CONTINUE_STOP_KINDS, catalogPathFor, DYNAMIC_FIELD_PARENTS, EXTRA_FIELDS, fieldMeta, HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, isKeySlotName, isToolGateKind, isTurnInjectStage, isTurnStage, KEY_SLOT_NAME, LIVE_ACTIVITY_HANDLINGS, LIVE_END_SENSITIVITIES, LIVE_START_SENSITIVITIES, MEDIA_INPUT_KIND_VALUES, MEDIA_INPUT_KINDS, MEDIA_WILDCARDS, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, REQUEST_FIELDS, SPEECH_AUDIO_FORMATS, STREAM_MODES, STUDIO_AUTH_TYPES, SUMMARY_MODES, THINKING_LEVELS, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_GATE_KINDS, TOOL_LOAD_TIERS, TOOL_PERMISSION, TOOL_TYPES, TURN_INJECT_STAGES, TURN_STAGES, TURN_STOP_KINDS, VOICE_ACCEPT_MIMES, } from './src/kernel/schema.js';
60
61
  export type { KernelScope } from './src/kernel/scope.js';
@@ -63,6 +64,7 @@ export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOut
63
64
  export { applyStageResult, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './src/kernel/stages.js';
64
65
  export type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './src/kernel/stop.js';
65
66
  export { AUTO_CONTINUE_DELAY_MS, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenAiFinishReason, } from './src/kernel/stop.js';
67
+ export { systemLinesProblem } from './src/kernel/system-lines.js';
66
68
  export { authorizeToolReplay } from './src/kernel/tools/execute.js';
67
69
  export { GATE_DECISIONS, type GateDecision } from './src/kernel/tools/gate-answer.js';
68
70
  export type { MemoryToolExecutionOptions } from './src/kernel/tools/memory-execution.js';
package/esm/mod.js CHANGED
@@ -35,10 +35,12 @@ export { createKernelRegistry } from './src/kernel/registry/kernel-registry.js';
35
35
  export { createProfileRegistry, defineProfile } from './src/kernel/registry/profiles.js';
36
36
  export { pickModel } from './src/kernel/registry/resolve.js';
37
37
  export { createSchemaRegistry } from './src/kernel/registry/schemas.js';
38
+ export { resolveTurnSystemPrompt } from './src/kernel/registry/system-prompt.js';
38
39
  export { API_EXPORTS, ATTACHMENT_ACCEPT_MIMES, AUTH_UNAUTHENTICATED_POLICIES, AWAITING_USER_INPUT_KINDS, AWAITING_USER_INPUT_STATUS, COMPACTION_METERS, COMPACTION_OUTCOMES, COMPACTION_TIMINGS, CONTINUE_STOP_KINDS, catalogPathFor, DYNAMIC_FIELD_PARENTS, EXTRA_FIELDS, fieldMeta, HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, isKeySlotName, isToolGateKind, isTurnInjectStage, isTurnStage, KEY_SLOT_NAME, LIVE_ACTIVITY_HANDLINGS, LIVE_END_SENSITIVITIES, LIVE_START_SENSITIVITIES, MEDIA_INPUT_KIND_VALUES, MEDIA_INPUT_KINDS, MEDIA_WILDCARDS, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, REQUEST_FIELDS, SPEECH_AUDIO_FORMATS, STREAM_MODES, STUDIO_AUTH_TYPES, SUMMARY_MODES, THINKING_LEVELS, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_GATE_KINDS, TOOL_LOAD_TIERS, TOOL_PERMISSION, TOOL_TYPES, TURN_INJECT_STAGES, TURN_STAGES, TURN_STOP_KINDS, VOICE_ACCEPT_MIMES, } from './src/kernel/schema.js';
39
40
  export { createKernelScope, defaultKernelScope } from './src/kernel/scope.js';
40
41
  export { applyStageResult, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './src/kernel/stages.js';
41
42
  export { AUTO_CONTINUE_DELAY_MS, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenAiFinishReason, } from './src/kernel/stop.js';
43
+ export { systemLinesProblem } from './src/kernel/system-lines.js';
42
44
  export { authorizeToolReplay } from './src/kernel/tools/execute.js';
43
45
  export { GATE_DECISIONS } from './src/kernel/tools/gate-answer.js';
44
46
  export { createMemoryToolExecution } from './src/kernel/tools/memory-execution.js';
@@ -8,7 +8,6 @@ import { sanitizeTurnRequest } from '../../guardrails/sanitize.js';
8
8
  import { clearProfiles, getProfile, getProvider, registerProfile, registerProvider, resolveTurn, runTurn, } from '../../kernel/default-scope.js';
9
9
  import { startCallUsage } from '../../kernel/engine/runner/usage.js';
10
10
  import { startCallTrace } from '../../kernel/engine/turn-trace.js';
11
- import { pickSystemRole } from '../../kernel/registry/system-role.js';
12
11
  import { bindSystem } from '../../kernel/system-parts.js';
13
12
  import { resolveObservabilityPolicy } from '../../observability/resolve-policy.js';
14
13
  import { buildRecord } from '../../observability/trace-record.js';
@@ -247,18 +246,15 @@ function measureSetupPhases() {
247
246
  const t0 = performance.now();
248
247
  const safe = sanitizeTurnRequest(req, getProfile(req.profile));
249
248
  const t1 = performance.now();
250
- const { profile, generation } = resolveTurn(safe);
249
+ const { generation } = resolveTurn(safe);
251
250
  const t2 = performance.now();
252
- pickSystemRole(profile, safe.input?.role);
253
- const t3 = performance.now();
254
251
  bindSystem(generation.resolvedSystem, [canaryNote(generation.canary)]);
255
- const t4 = performance.now();
252
+ const t3 = performance.now();
256
253
  return {
257
254
  sanitizeMs: t1 - t0,
258
255
  resolveMs: t2 - t1,
259
- systemMs: t3 - t2,
260
- canaryMs: t4 - t3,
261
- totalSetupMs: t4 - t0,
256
+ canaryMs: t3 - t2,
257
+ totalSetupMs: t3 - t0,
262
258
  };
263
259
  }
264
260
  function printPhaseBreakdown(iterations) {
@@ -272,14 +268,12 @@ function printPhaseBreakdown(iterations) {
272
268
  };
273
269
  const sanitize = median(results.map((r) => r.sanitizeMs));
274
270
  const resolve = median(results.map((r) => r.resolveMs));
275
- const system = median(results.map((r) => r.systemMs));
276
271
  const canary = median(results.map((r) => r.canaryMs));
277
272
  const total = median(results.map((r) => r.totalSetupMs));
278
273
  console.log('\nSetup Phase Breakdown (median)');
279
274
  console.log('─'.repeat(72));
280
275
  console.log(` sanitizeTurnRequest ${fmtMs(sanitize).padStart(10)}`);
281
276
  console.log(` resolveTurn ${fmtMs(resolve).padStart(10)}`);
282
- console.log(` pickSystemRole ${fmtMs(system).padStart(10)}`);
283
277
  console.log(` bindSystem ${fmtMs(canary).padStart(10)}`);
284
278
  console.log(` ─────────────────────────────`);
285
279
  console.log(` Total setup ${fmtMs(total).padStart(10)}`);
@@ -7,6 +7,9 @@ function formatProfileInputs(p) {
7
7
  if (p.type === 'live') {
8
8
  return 'audio/video (live)';
9
9
  }
10
+ if (p.type === 'transcription') {
11
+ return 'voice';
12
+ }
10
13
  const inputs = [];
11
14
  const { inputs: spec } = p;
12
15
  if (!spec) {
@@ -41,7 +44,7 @@ function printProfileCard(p) {
41
44
  return;
42
45
  }
43
46
  const models = Object.keys(p.models).join(', ') || 'default';
44
- const structured = p.type === 'live' || p.type === 'speech' || p.type === 'embedding'
47
+ const structured = p.type === 'live' || p.type === 'speech' || p.type === 'transcription' || p.type === 'embedding'
45
48
  ? undefined
46
49
  : p.outputs?.structured;
47
50
  const structuredLabel = typeof structured === 'string' ? structured : structured ? 'custom' : 'none';
@@ -1,7 +1,7 @@
1
1
  /** Values that fill a label template's `{param}` placeholders. */
2
2
  export type LabelParams = Record<string, string | number>;
3
3
  /** Keys are stable API. */
4
- export declare const LABEL_KEYS: readonly ["provider.decision_failed", "provider.decision_unavailable", "provider.decision_model_missing", "provider.decision_ended", "provider.decision_images_off", "provider.decision_box_model", "provider.budget_exhausted", "provider.adapter_version", "provider.adapter_methods", "provider.adapter_schemas", "provider.fallback_slot", "provider.model_fallback_slot", "provider.host_model", "provider.turn_profile", "provider.model_binding_missing", "provider.session_closed", "provider.settled_call", "provider.session_unavailable", "provider.live_input", "provider.tool_cancel_missing", "provider.kernel_gate", "provider.event_invalid", "provider.response_identity", "provider.credential_resolution", "provider.credential_shape", "provider.stored_continuation", "provider.continuation_mismatch", "provider.continuation_contract", "provider.stateless_history", "provider.events_after_completion", "provider.duplicate_call", "provider.tool_cancel_live", "provider.complete_unavailable", "provider.parallel_tools", "provider.binding_identity", "provider.profile_type", "provider.event_type", "provider.feature", "provider.input_kind", "provider.output_kind", "provider.builtin", "provider.credential_missing", "provider.profile_configuration", "continue.instruction", "canary.bind_note", "user_data.note", "context.note", "taint.blocked", "taint.reason_steered", "taint.reason_tainted", "taint.destination_blocked", "taint.destination_confirm", "advisory.notice_elevated", "advisory.notice_high", "advisory.guidance", "attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "attachments.limits_unconfigured", "quota.exhausted", "quota.busy", "error.config", "error.request", "error.conflict", "error.not_found", "error.input", "error.action", "error.auth", "error.rate_limit", "error.busy", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "repair.default_guidance", "repair.items_guidance", "repair.prompt_header", "repair.prompt_intro", "repair.prompt_instructions", "repair.history_heading", "repair.section_previous_output", "repair.section_validator_rejection", "repair.section_repair_guidance", "repair.section_instructions", "structured.answer_tool", "structured.answer_missing", "structured.cut_off", "structured.not_json", "compaction.request", "compaction.tool_call", "compaction.tool_result", "compaction.tool_files", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.injection", "detect.hint.tool_instructions", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.full", "session.busy", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
4
+ export declare const LABEL_KEYS: readonly ["provider.decision_failed", "provider.decision_unavailable", "provider.decision_model_missing", "provider.decision_ended", "provider.decision_images_off", "provider.decision_box_model", "provider.budget_exhausted", "provider.adapter_version", "provider.adapter_methods", "provider.adapter_schemas", "provider.fallback_slot", "provider.model_fallback_slot", "provider.host_model", "provider.turn_profile", "provider.model_binding_missing", "provider.session_closed", "provider.settled_call", "provider.session_unavailable", "provider.live_input", "provider.tool_cancel_missing", "provider.kernel_gate", "provider.event_invalid", "provider.response_identity", "provider.credential_resolution", "provider.credential_shape", "provider.stored_continuation", "provider.continuation_mismatch", "provider.continuation_contract", "provider.stateless_history", "provider.events_after_completion", "provider.duplicate_call", "provider.tool_cancel_live", "provider.complete_unavailable", "provider.parallel_tools", "provider.binding_identity", "provider.profile_type", "provider.event_type", "provider.feature", "provider.input_kind", "provider.output_kind", "provider.builtin", "provider.credential_missing", "provider.profile_configuration", "continue.instruction", "canary.bind_note", "user_data.note", "context.note", "taint.blocked", "taint.reason_steered", "taint.reason_tainted", "taint.destination_blocked", "taint.destination_confirm", "advisory.notice_elevated", "advisory.notice_high", "advisory.guidance", "attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "attachments.limits_unconfigured", "quota.exhausted", "quota.busy", "error.config", "error.request", "error.conflict", "error.not_found", "error.input", "error.action", "error.auth", "error.rate_limit", "error.busy", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "repair.default_guidance", "repair.items_guidance", "repair.prompt_header", "repair.prompt_intro", "repair.prompt_instructions", "repair.history_heading", "repair.section_previous_output", "repair.section_validator_rejection", "repair.section_repair_guidance", "repair.section_instructions", "structured.answer_tool", "structured.answer_missing", "structured.cut_off", "structured.not_json", "compaction.request", "compaction.tool_call", "compaction.tool_result", "compaction.tool_files", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.injection", "detect.hint.tool_instructions", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.full", "session.busy", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.after_field", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
5
5
  /** One of {@linkcode LABEL_KEYS}. */
6
6
  export type LabelKey = (typeof LABEL_KEYS)[number];
7
7
  /**
@@ -183,6 +183,7 @@ export const LABEL_KEYS = [
183
183
  'tool.not_loaded_t2',
184
184
  'tool.wait_unknown',
185
185
  'tool.wait_cycle',
186
+ 'tool.after_field',
186
187
  'tool.not_visible',
187
188
  'tool.builtin_not_enabled',
188
189
  'tool.provider_native',
@@ -516,6 +517,7 @@ const DEFAULTS = {
516
517
  'tool.not_loaded_t2': "Tool '{tool}' is not loaded — call {loader} to load it first",
517
518
  'tool.wait_unknown': "Tool '{tool}' waits for calls that are not in this step: {calls}",
518
519
  'tool.wait_cycle': "Tool '{tool}' waits for calls that cannot finish before it: {calls}",
520
+ 'tool.after_field': 'Tools you are calling in this same step that must finish before this call starts. Leave out to set no order.',
519
521
  'tool.not_visible': "Tool '{tool}' is not visible this turn",
520
522
  'tool.builtin_not_enabled': "Builtin '{tool}' is not enabled this turn",
521
523
  'tool.provider_native': "Tool '{tool}' is a provider builtin — execution is handled by the model provider, not the kernel",
@@ -735,6 +737,7 @@ export const LABEL_NOTES = {
735
737
  'tool.not_loaded_t2': 'Told to the model when it calls a T2 tool the T2 loader has not loaded yet. Takes {tool} and {loader}, the loader tool.',
736
738
  'tool.wait_unknown': "Told to the model when a call's pre_tool waitFor names calls that are not in its step. Takes {tool} and {calls}.",
737
739
  'tool.wait_cycle': "Told to the model when a call's pre_tool waitFor names calls that cannot settle before it, because they wait for it or run after it. Takes {tool} and {calls}.",
740
+ 'tool.after_field': "What the model reads on the after field of a tool that sets registerTool.after. Read when the tool registers, so a profile's labels do not change it.",
738
741
  'tool.not_visible': 'Told to the model when it calls a tool it cannot see this turn. Takes {tool}.',
739
742
  'tool.builtin_not_enabled': 'Told to the model when it calls a provider builtin not turned on this turn. Takes {tool}.',
740
743
  'tool.provider_native': 'Told to the model when the kernel is asked to run a provider builtin, which the provider runs itself. Takes {tool}.',
@@ -248,6 +248,24 @@ function standaloneBlock(event, idPrefix) {
248
248
  return undefined;
249
249
  }
250
250
  }
251
+ /**
252
+ * The media a tool returned beside its output, where the call stands in the reply.
253
+ * why: a tool sends a picture when it runs, so the picture comes before what the model says next.
254
+ */
255
+ function appendToolParts(blocks, tool, idPrefix) {
256
+ if (tool.phase !== 'complete')
257
+ return;
258
+ for (const part of tool.parts ?? []) {
259
+ if (part.type === 'text')
260
+ continue;
261
+ blocks.push({
262
+ id: nextBlockId(idPrefix),
263
+ kind: 'media',
264
+ mimeType: part.mimeType,
265
+ ...('data' in part ? { data: part.data } : { url: part.uri }),
266
+ });
267
+ }
268
+ }
251
269
  /** Resets only the turn id sequence, so streaming refolds keep stable `turn-*` keys. */
252
270
  function foldTurnEvents(events, options = {}) {
253
271
  const idPrefix = options.idPrefix ?? 'turn';
@@ -273,6 +291,7 @@ function foldTurnEvents(events, options = {}) {
273
291
  case 'tool':
274
292
  upsertToolBlock(blocks, event.tool);
275
293
  appendPromotedToolMedia(blocks, event.tool, idPrefix, promotedMediaUrls);
294
+ appendToolParts(blocks, event.tool, idPrefix);
276
295
  break;
277
296
  case 'structured_draft':
278
297
  upsertStructuredDraft(blocks, event.text, idPrefix);
@@ -13,8 +13,8 @@ declare function interfaceFromProfile(input: Profile, tools: ToolRegistry): Prof
13
13
  /** The interface for a profile the host has already projected, without resolving its tools again. */
14
14
  declare function interfaceFromProjected(projected: ProjectedProfile): ProfileInterface;
15
15
  /**
16
- * The interface a browser may read: {@linkcode interfaceFromProfile} without `identity.system` and
17
- * `systemByRole`, which stay on the server. Labels, turn behaviour, guardrails, and observability are kept.
16
+ * The interface a browser may read: {@linkcode interfaceFromProfile} without `identity.system`, which
17
+ * stays on the server. Labels, turn behaviour, guardrails, and observability are kept.
18
18
  */
19
19
  declare function clientProfileInterface(input: LiveProfile, tools: ToolRegistry): LiveProfileInterface;
20
20
  /** The client-safe interface for a profile that is not live. */
@@ -147,6 +147,13 @@ function enrich(projected, profile) {
147
147
  turnBehaviour: profile?.type === 'speech' ? profile.turnBehaviour : undefined,
148
148
  canStop: true,
149
149
  });
150
+ case 'transcription':
151
+ return profileInterfaceSchema.parse({
152
+ ...shared,
153
+ type: 'transcription',
154
+ inputs,
155
+ canStop: true,
156
+ });
150
157
  case 'live':
151
158
  return profileInterfaceSchema.parse({
152
159
  ...shared,
@@ -29,5 +29,5 @@ export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from '.
29
29
  export { promotedToolIdsFromEvents, toolSnapshotFromEvents } from './tool-invoke.js';
30
30
  export type { PromotedToolMedia } from './tool-media.js';
31
31
  export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
32
- export type { AttachmentValidationResult, ComposerInterfaceFields, ComposerProfileInterface, FoldTurnEventsOptions, ImageProfileInterface, LiveProfileInterface, ModelBindingView, PendingAttachment, ProfileGuardrailsView, ProfileInputsInterface, ProfileInterface, ProfileObservabilityView, ProfileOutputsView, ProfileToolsView, SpeechProfileInterface, TextProfileInterface, TranscriptBlock, TranscriptBlockKind, UserTurnDraft, } from './types.js';
32
+ export type { AttachmentValidationResult, ComposerInterfaceFields, ComposerProfileInterface, FoldTurnEventsOptions, ImageProfileInterface, LiveProfileInterface, ModelBindingView, PendingAttachment, ProfileGuardrailsView, ProfileInputsInterface, ProfileInterface, ProfileObservabilityView, ProfileOutputsView, ProfileToolsView, SpeechProfileInterface, TextProfileInterface, TranscriptBlock, TranscriptBlockKind, TranscriptionProfileInterface, UserTurnDraft, } from './types.js';
33
33
  export { streamThoughtsEnabled } from './types.js';
@@ -143,17 +143,18 @@ const common = {
143
143
  guardrails: guardrails.optional(),
144
144
  observability: observability.optional(),
145
145
  };
146
- const systemPrompt = z.union([
146
+ const systemPart = z.union([z.string(), z.strictObject({ private: z.string().min(1) })]);
147
+ const profileSystem = z.union([
147
148
  z.string(),
148
149
  z
149
- .array(z.union([z.string(), z.strictObject({ private: z.string().min(1) })]))
150
+ .array(z.union([z.string(), z.array(systemPart).readonly()]))
150
151
  .min(1)
151
152
  .readonly(),
152
153
  ]);
153
154
  const identity = z.object({
154
155
  handle: z.string(),
155
- system: systemPrompt.optional(),
156
- systemByRole: z.record(z.string(), systemPrompt).optional(),
156
+ conditions: z.record(z.string(), z.array(z.string()).readonly()).readonly().optional(),
157
+ system: profileSystem.optional(),
157
158
  });
158
159
  const profileInterface = z.discriminatedUnion('type', [
159
160
  z.object({
@@ -200,6 +201,15 @@ const profileInterface = z.discriminatedUnion('type', [
200
201
  turnBehaviour: mediaTurnBehaviour.optional(),
201
202
  canStop: z.literal(true),
202
203
  }),
204
+ z.object({
205
+ ...common,
206
+ type: z.literal('transcription'),
207
+ identity: z.object({ handle: z.string() }),
208
+ maxSteps: z.undefined().optional(),
209
+ outputs: outputs.optional(),
210
+ inputs,
211
+ canStop: z.literal(true),
212
+ }),
203
213
  z.object({
204
214
  ...common,
205
215
  type: z.literal('speech'),
@@ -5,7 +5,7 @@ import type { LabelOverrides } from '../guardrails/labels.js';
5
5
  import type { ResolvedGuardrailPolicy } from '../guardrails/types.js';
6
6
  import type { ProfileToolsSpec, ToolCallEdit, ToolPhaseEvent } from '../kernel/tools/types.js';
7
7
  import type { ReasoningPart } from '../kernel/turn-events.js';
8
- import type { AttachmentValidationIssue, CompactionSpec, GroundingEvent, ImageProfile, LiveProfile, ModelBinding, ModelId, ProfileContextSpec, ProfileOutputsSpec, ProviderEvidence, SlotDecl, Source, SpeechProfile, TextProfile, TurnStop, TurnTokens } from '../kernel/types.js';
8
+ import type { AttachmentValidationIssue, CompactionSpec, GroundingEvent, ImageProfile, LiveProfile, ModelBinding, ModelId, ProfileContextSpec, ProfileOutputsSpec, ProviderEvidence, SlotDecl, Source, SpeechProfile, TextProfile, TranscriptionProfile, TurnStop, TurnTokens } from '../kernel/types.js';
9
9
  import type { ResolvedObservabilityPolicy } from '../observability/types.js';
10
10
  /** What a URL detector lets through besides the given URLs, with its defaults applied. */
11
11
  export interface UrlAllowView {
@@ -103,6 +103,8 @@ export type ImageProfileInterface = Omit<ImageProfile, 'inputs' | 'tools' | 'gua
103
103
  };
104
104
  /** A speech profile as a client sees it, without its server-only fields. */
105
105
  export type SpeechProfileInterface = Omit<SpeechProfile, 'guardrails' | 'observability' | 'labels' | 'models' | 'outputs'> & ComposerInterfaceFields;
106
+ /** A transcription profile as a client sees it, without its server-only fields. */
107
+ export type TranscriptionProfileInterface = Omit<TranscriptionProfile, 'guardrails' | 'observability' | 'labels' | 'models' | 'outputs' | 'inputs'> & ComposerInterfaceFields;
106
108
  /** A live profile as a client sees it, without its server-only fields. */
107
109
  export type LiveProfileInterface = Omit<LiveProfile, 'tools' | 'guardrails' | 'observability' | 'labels' | 'models' | 'live'> & {
108
110
  /** Without `greeting` and `resumed`: the prompts stay on the host. */
@@ -115,7 +117,7 @@ export type LiveProfileInterface = Omit<LiveProfile, 'tools' | 'guardrails' | 'o
115
117
  observability?: ProfileObservabilityView;
116
118
  };
117
119
  /** Any profile as a client sees it. */
118
- export type ProfileInterface = TextProfileInterface | ImageProfileInterface | SpeechProfileInterface | LiveProfileInterface;
120
+ export type ProfileInterface = TextProfileInterface | ImageProfileInterface | SpeechProfileInterface | TranscriptionProfileInterface | LiveProfileInterface;
119
121
  /** Turn/chat composer profiles — excludes live (realtime streams, no turn inputs block). */
120
122
  export type ComposerProfileInterface = Exclude<ProfileInterface, LiveProfileInterface>;
121
123
  /** The kinds of block a transcript holds. */
@@ -202,9 +204,9 @@ export interface StructuredBlock extends TranscriptBlockBase {
202
204
  export interface MediaBlock extends TranscriptBlockBase {
203
205
  kind: 'media';
204
206
  mimeType: string;
205
- /** Base64 for model-generated or attached media. Absent when `url` is set. */
207
+ /** Base64 for media a model generated, a tool returned or a person attached. Absent when `url` is set. */
206
208
  data?: string;
207
- /** Remote http(s) URL promoted from completed tool output. Absent when `data` is set. */
209
+ /** Remote URL from completed tool output or a tool's media part. Absent when `data` is set. */
208
210
  url?: string;
209
211
  /** A smaller copy of `url` for previews, when the tool output offered one. */
210
212
  previewUrl?: string;
@@ -20,11 +20,6 @@ export const REQUEST_FIELDS = {
20
20
  },
21
21
  'runTurn.input': { type: 'TurnInput', doc: 'What the user sent for the turn.' },
22
22
  'runTurn.input.text': { type: 'string', doc: "The user's message." },
23
- 'runTurn.input.role': {
24
- type: 'string',
25
- doc: 'Picks the instruction of that name from identity.systemByRole.',
26
- unset: 'The profile instruction',
27
- },
28
23
  'runTurn.input.slots': {
29
24
  type: 'Record<string, string>',
30
25
  doc: 'The choice the turn makes for each slot the profile declares in inputs.slots; a slot or a value the profile does not declare is refused.',
@@ -79,6 +74,11 @@ export const REQUEST_FIELDS = {
79
74
  type: 'SystemPrompt',
80
75
  doc: "An instruction for this request only, added to the profile's own.",
81
76
  },
77
+ 'runTurn.conditions': {
78
+ type: 'Record<string, string>',
79
+ doc: "This turn's facts, one value for each of identity.conditions but path.",
80
+ unset: 'The profile declares none',
81
+ },
82
82
  'runTurn.path': {
83
83
  type: 'string',
84
84
  doc: 'The channel the turn comes from; only tools whose paths name it, or *, are offered.',
@@ -342,7 +342,9 @@ function scopeTokens(scope) {
342
342
  function assertGrantWithin(granted, requested, tokenEndpoint) {
343
343
  if (requested.length === 0)
344
344
  return;
345
- const beyond = scopeTokens(granted).filter((scope) => !requested.includes(scope));
345
+ // why: Some servers join scopes with commas. A comma may also sit inside a scope, so a token
346
+ // that was asked for stands, and only an unknown one is read as a list, part by part.
347
+ const beyond = scopeTokens(granted).flatMap((scope) => requested.includes(scope) ? [] : scope.split(',').filter((part) => !requested.includes(part)));
346
348
  if (beyond.length > 0) {
347
349
  throw new Error(`Token response from ${tokenEndpoint} grants scopes that were not asked for: ${beyond.join(', ')}`);
348
350
  }
@@ -461,6 +461,7 @@ async function* runTurnBody(ctx, provider) {
461
461
  if (gen.canary)
462
462
  gen.canary = await profileCanary(profile.id, gen.resolvedSystem);
463
463
  ctx.generation = gen;
464
+ ctx.root.set({ 'theorem.turn.system_lines': [...gen.systemLines] });
464
465
  ctx.canary = gen.canary;
465
466
  ctx.canaries.push(gen.canary);
466
467
  const binding = profile.models[gen.model];
@@ -116,6 +116,7 @@ function toTurnRequest(req) {
116
116
  system: req.system,
117
117
  builtInArgs: req.builtInArgs,
118
118
  path: req.path,
119
+ conditions: req.conditions,
119
120
  sessionPermissions: req.sessionPermissions,
120
121
  signal: req.signal,
121
122
  metadata: req.metadata,
@@ -143,6 +143,7 @@ class LiveTrace {
143
143
  /** Attach the resolved request; frames are recorded from here on. */
144
144
  bind(binding) {
145
145
  this.bound = binding;
146
+ this.root.set({ 'theorem.turn.system_lines': [...binding.generation.systemLines] });
146
147
  }
147
148
  /** The adapter's `tapUpstream`: every frame sent, as it is sent. */
148
149
  sent = (row) => {
@@ -43,12 +43,13 @@ export type { MediaInputChannel } from './registry/catalog.js';
43
43
  export { clampThinkingLevel, clampThinkingLevelForApiId, mediaChannelForMime, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, requireModelBinding, } from './registry/catalog.js';
44
44
  export type { KernelRegistry } from './registry/kernel-registry.js';
45
45
  export { createKernelRegistry } from './registry/kernel-registry.js';
46
- export type { DecisionProfileDefinition, EmbeddingProfileDefinition, HostProfileDefinition, ImageProfileDefinition, LiveProfileDefinition, ProfileDefinition, ProfileDefinitionBase, ProfileRegistry, SpeechProfileDefinition, TextProfileDefinition, } from './registry/profiles.js';
46
+ export type { DecisionProfileDefinition, EmbeddingProfileDefinition, HostProfileDefinition, ImageProfileDefinition, LiveProfileDefinition, ProfileDefinition, ProfileDefinitionBase, ProfileRegistry, SpeechProfileDefinition, TextProfileDefinition, TranscriptionProfileDefinition, } from './registry/profiles.js';
47
47
  export { createProfileRegistry, defineProfile } from './registry/profiles.js';
48
48
  export { projectProfileObject, requireModelProfile } from './registry/resolve.js';
49
49
  export type { SchemaRegistry } from './registry/schemas.js';
50
50
  export { createSchemaRegistry } from './registry/schemas.js';
51
51
  export { normalizeProfileInputsSlots, normalizeSlotDecl, normalizeSlots, slotValues, } from './registry/slots.js';
52
+ export { resolveTurnSystemPrompt } from './registry/system-prompt.js';
52
53
  export type { CredentialContext, CredentialResolver, KeyCredential } from './registry/vault.js';
53
54
  export type { AuthUnauthenticatedPolicy, CustomToolType, HttpMethod, StudioAuthType, ToolAccess, ToolAuthType, ToolPermission, ToolType, } from './schema.js';
54
55
  export { API_EXPORTS, ATTACHMENT_ACCEPT_MIMES, AUTH_UNAUTHENTICATED_POLICIES, AWAITING_USER_INPUT_KINDS, AWAITING_USER_INPUT_STATUS, CACHE_MODES, CACHE_TTLS, COMPACTION_METERS, COMPACTION_OUTCOMES, COMPACTION_TIMINGS, CONTINUE_STOP_KINDS, catalogPathFor, EXTRA_FIELDS, fieldMeta, HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, isKeySlotName, isToolGateKind, isTurnInjectStage, isTurnStage, KEY_SLOT_NAME, MEDIA_INPUT_KIND_VALUES, MEDIA_INPUT_KINDS, MEDIA_WILDCARDS, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, REQUEST_FIELDS, SPEECH_AUDIO_FORMATS, STREAM_MODES, STUDIO_AUTH_TYPES, SUMMARY_MODES, THINKING_LEVELS, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_GATE_KINDS, TOOL_LOAD_TIERS, TOOL_PERMISSION, TOOL_TYPES, TURN_INJECT_STAGES, TURN_STAGES, TURN_STOP_KINDS, VOICE_ACCEPT_MIMES, } from './schema.js';
@@ -58,6 +59,7 @@ export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOut
58
59
  export { applyStageResult, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './stages.js';
59
60
  export type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './stop.js';
60
61
  export { AUTO_CONTINUE_DELAY_MS, CONTINUE_INSTRUCTION_TYPES, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenAiFinishReason, } from './stop.js';
62
+ export { systemLinesProblem } from './system-lines.js';
61
63
  export { systemPromptProblem } from './system-parts.js';
62
64
  export { activityLabelProblem } from './tools/activity-label.js';
63
65
  export { agentToolInputFor, agentToolOutput } from './tools/agent.js';
@@ -30,10 +30,12 @@ export { createProfileRegistry, defineProfile } from './registry/profiles.js';
30
30
  export { projectProfileObject, requireModelProfile } from './registry/resolve.js';
31
31
  export { createSchemaRegistry } from './registry/schemas.js';
32
32
  export { normalizeProfileInputsSlots, normalizeSlotDecl, normalizeSlots, slotValues, } from './registry/slots.js';
33
+ export { resolveTurnSystemPrompt } from './registry/system-prompt.js';
33
34
  export { API_EXPORTS, ATTACHMENT_ACCEPT_MIMES, AUTH_UNAUTHENTICATED_POLICIES, AWAITING_USER_INPUT_KINDS, AWAITING_USER_INPUT_STATUS, CACHE_MODES, CACHE_TTLS, COMPACTION_METERS, COMPACTION_OUTCOMES, COMPACTION_TIMINGS, CONTINUE_STOP_KINDS, catalogPathFor, EXTRA_FIELDS, fieldMeta, HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, isKeySlotName, isToolGateKind, isTurnInjectStage, isTurnStage, KEY_SLOT_NAME, MEDIA_INPUT_KIND_VALUES, MEDIA_INPUT_KINDS, MEDIA_WILDCARDS, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, REQUEST_FIELDS, SPEECH_AUDIO_FORMATS, STREAM_MODES, STUDIO_AUTH_TYPES, SUMMARY_MODES, THINKING_LEVELS, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_GATE_KINDS, TOOL_LOAD_TIERS, TOOL_PERMISSION, TOOL_TYPES, TURN_INJECT_STAGES, TURN_STAGES, TURN_STOP_KINDS, VOICE_ACCEPT_MIMES, } from './schema.js';
34
35
  export { createKernelScope, defaultKernelScope } from './scope.js';
35
36
  export { applyStageResult, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './stages.js';
36
37
  export { AUTO_CONTINUE_DELAY_MS, CONTINUE_INSTRUCTION_TYPES, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenAiFinishReason, } from './stop.js';
38
+ export { systemLinesProblem } from './system-lines.js';
37
39
  export { systemPromptProblem } from './system-parts.js';
38
40
  export { activityLabelProblem } from './tools/activity-label.js';
39
41
  export { agentToolInputFor, agentToolOutput } from './tools/agent.js';
@@ -6,6 +6,7 @@ export const PROFILE_FIELD_PRESENCE = {
6
6
  'profile.type': { required: true },
7
7
  identity: { required: true },
8
8
  'identity.handle': { required: true },
9
+ 'identity.conditions': { unset: 'The turn states no conditions' },
9
10
  'identity.system': { unset: "Only the kernel's notes" },
10
11
  tools: { required: true },
11
12
  'tools.allow': { required: true },