@theoremjs/agents 0.3.5-next.918.g28ade76 → 0.3.5-next.926.g05c82e3

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 (38) hide show
  1. package/README.md +3 -3
  2. package/esm/mod.d.ts +3 -3
  3. package/esm/mod.js +1 -1
  4. package/esm/src/guardrails/tool-result.d.ts +4 -3
  5. package/esm/src/guardrails/tool-result.js +8 -5
  6. package/esm/src/interface/blocks.js +7 -21
  7. package/esm/src/interface/history.js +38 -34
  8. package/esm/src/interface/mod.d.ts +0 -2
  9. package/esm/src/interface/mod.js +0 -1
  10. package/esm/src/interface/types.d.ts +13 -5
  11. package/esm/src/kernel/engine/runner/stages.js +6 -1
  12. package/esm/src/kernel/engine/runner/steps.js +1 -1
  13. package/esm/src/kernel/engine/session/mod.js +20 -22
  14. package/esm/src/kernel/field-docs.js +2 -2
  15. package/esm/src/kernel/interaction-parts.d.ts +9 -8
  16. package/esm/src/kernel/interaction-parts.js +21 -23
  17. package/esm/src/kernel/mod.d.ts +3 -3
  18. package/esm/src/kernel/mod.js +1 -1
  19. package/esm/src/kernel/schema.js +1 -1
  20. package/esm/src/kernel/stages.d.ts +23 -7
  21. package/esm/src/kernel/stages.js +27 -17
  22. package/esm/src/kernel/tools/agent.js +6 -3
  23. package/esm/src/kernel/tools/execute.d.ts +8 -3
  24. package/esm/src/kernel/tools/execute.js +98 -60
  25. package/esm/src/kernel/tools/image-fetch.d.ts +10 -8
  26. package/esm/src/kernel/tools/image-fetch.js +47 -18
  27. package/esm/src/kernel/tools/operation.js +3 -1
  28. package/esm/src/kernel/tools/remote.d.ts +7 -3
  29. package/esm/src/kernel/tools/remote.js +55 -13
  30. package/esm/src/kernel/tools/stage-run.d.ts +5 -3
  31. package/esm/src/kernel/tools/stage-run.js +4 -3
  32. package/esm/src/kernel/tools/types.d.ts +33 -18
  33. package/esm/src/kernel/turn-events.d.ts +14 -3
  34. package/esm/src/kernel/turn-events.js +9 -1
  35. package/esm/src/kernel/types.d.ts +3 -3
  36. package/package.json +1 -1
  37. package/esm/src/interface/tool-media.d.ts +0 -11
  38. package/esm/src/interface/tool-media.js +0 -113
package/README.md CHANGED
@@ -463,12 +463,12 @@ Named exports from the root barrel (same symbols hosts get from `@theoremjs/agen
463
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`, `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` |
464
464
  | Scope | `KernelScope`, `createKernelScope`, `defaultKernelScope`, `KernelRegistry`, `createKernelRegistry` |
465
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` |
466
- | Tools | `ToolContext`, `GateReference`, `gateReferenceSchema`, `ToolRegistry`, `assertToolSettings`, `createToolRegistry`, `registerTool`, `registerTools`, `invokeTool`, `invokeToolStep`, `runTool`, `runToolStep`, `SettledToolCall`, `ToolCallResult`, `ToolStepCallResult`, `GATE_DECISIONS`, `GateDecision`, `askUserTool`, `registerHarnessTools`, `getTool`, `hasTool`, `requireTool`, `listTools`, `resetTools`, `formatToolResult`, `formatToolFailureForModel`, `prepareTurnToolSnapshot`, `buildHttpToolTarget`, `executeHttpTool`, `executeMcpTool`, `parseMcpRpcResponse`, `isUnsupportedMcpProtocolError`, `MCP_PROTOCOL_VERSIONS`, `mcpRequestMeta`, `McpProtocolVersion`, `resolveToolAuth`, `credentialPlacement`, `withCredentialQuery`, `CredentialQuery`, `uncheckedOutput`, `UncheckedOutput`, `ToolFailed`, `StatedToolFailure`, `McpRpcResponse`, `ModelToolResult`, `PageAnswer` |
466
+ | Tools | `ToolContext`, `GateReference`, `gateReferenceSchema`, `ToolRegistry`, `assertToolSettings`, `createToolRegistry`, `registerTool`, `registerTools`, `invokeTool`, `invokeToolStep`, `runTool`, `runToolStep`, `SettledToolCall`, `ToolCallResult`, `ToolStepCallResult`, `GATE_DECISIONS`, `GateDecision`, `askUserTool`, `registerHarnessTools`, `getTool`, `hasTool`, `requireTool`, `listTools`, `resetTools`, `formatToolResult`, `formatToolFailureForModel`, `prepareTurnToolSnapshot`, `buildHttpToolTarget`, `executeHttpTool`, `executeMcpTool`, `parseMcpRpcResponse`, `isUnsupportedMcpProtocolError`, `MCP_PROTOCOL_VERSIONS`, `mcpRequestMeta`, `McpProtocolVersion`, `resolveToolAuth`, `credentialPlacement`, `withCredentialQuery`, `CredentialQuery`, `uncheckedOutput`, `UncheckedOutput`, `ToolFailed`, `StatedToolFailure`, `McpRpcResponse`, `ModelToolResult`, `PageAnswer`, `ToolMediaEntry` (one entry of an HTTP or MCP tool's media hook) |
467
467
  | Tool execution | `ToolBackground`, `ToolBackgroundCall`, `ToolBackgroundHandle`, `ToolBackgroundService`, `ToolBackgroundSettled`, `ToolSteerReceipt`, `ToolSteerRefusal`, `ToolOperationReply`, `toolOperationReplySchema`, `BackgroundToolEvent`, `ToolExecutionCoordinator`, `createMemoryToolExecution`, `MemoryToolExecutionOptions`, `authorizeToolReplay`, `BeginToolOperationResult`, `ToolOperationClaim`, `ToolOperationIdentity`, `ToolOperationOutcome`, `ToolOperationUncertainty`, `toolOperationOutcomeSchema`, `SavedToolInvocation`, `savedToolInvocationSchema`, `toolInvocationHash`, `TerminalToolEvent`, `PageToolDispatch`, `PageToolExecution` |
468
468
  | Structured | `SchemaRegistry`, `createSchemaRegistry`, `getStructured`, `registerStructured` |
469
469
  | Stop / resume | `ProfileTurnBehaviourSpec`, `MediaTurnBehaviourSpec`, `ProfileTurnResumptionSpec`, `TurnContinueFrom`, `TurnStop`, `TurnStopKind`, `ContinueStopKind`, `StepLimitMode`, `CONTINUE_STOP_KINDS`, `AUTO_CONTINUE_DELAY_MS`, `DEFAULT_ALLOW_CONTINUE`, `DEFAULT_AUTO_CONTINUE`, `GenerationStopError`, `isContinueStopKind`, `isGenerationStopError`, `isResumeableStop`, `isUserCancelledStop`, `profileAllowsSteering`, `profileAllowsInject`, `profileTurnResumption`, `shouldAutoContinue`, `turnStopFromClientStreamEnd` |
470
- | Stages (target foundation) | `TURN_STAGES`, `TURN_INJECT_STAGES`, `STAGE_AFFORDANCES`, `STAGE_AFFORDANCE_MATRIX`, `TOOL_GATE_KINDS`, `AWAITING_USER_INPUT_KINDS`, `AWAITING_USER_INPUT_STATUS`, `applyStageResult`, `awaitingUserInputSchema`, `toolGateSchema`, `isTurnStage`, `isTurnInjectStage`, `isToolGateKind`, `isAwaitingUserInput`, `stageAllowsAffordance`, `stageEventFields`, `profileAllowsInject`, `StageAffordance`, `StageContext`, `StageResult`, `StageMutate`, `StageHandler`, `StageApplyInput`, `StageApplyOutput`, `StageApplyWarning`, `StageApplyWarningCode`, `StageEventExtra`, `AwaitingUserInput`, `ToolGate` — contract [`docs/contracts/stages.md`](https://github.com/masudl-hub/theoremai/blob/main/docs/contracts/stages.md) |
471
- | Turn events | `TURN_EVENT_SCHEMAS` (each kind's schema, for a wire parser), `turnEventSchema`, `turnHistoryMessageSchema`, `turnToolSnapshotSchema`, `reasoningPartSchema`, `historyHash`, `turnDoneOf`, `keptReply` (a turn's events without the replies a retry threw away), `z` (the zod these schemas are built with; compose them with it, since two copies of zod do not mix) — the event types themselves come through `export type *` from `src/kernel/types.ts` |
470
+ | Stages (target foundation) | `TURN_STAGES`, `TURN_INJECT_STAGES`, `STAGE_AFFORDANCES`, `STAGE_AFFORDANCE_MATRIX`, `TOOL_GATE_KINDS`, `AWAITING_USER_INPUT_KINDS`, `AWAITING_USER_INPUT_STATUS`, `applyStageResult`, `awaitingUserInputSchema`, `toolGateSchema`, `isTurnStage`, `isTurnInjectStage`, `isToolGateKind`, `isAwaitingUserInput`, `stageAllowsAffordance`, `stageEventFields`, `profileAllowsInject`, `StageAffordance`, `StageContext`, `StageResult`, `StageMutate`, `StageMutateSubject`, `StageHandler`, `StageApplyInput`, `StageApplyOutput`, `StageApplyWarning`, `StageApplyWarningCode`, `StageEventExtra`, `AwaitingUserInput`, `ToolGate` — contract [`docs/contracts/stages.md`](https://github.com/masudl-hub/theoremai/blob/main/docs/contracts/stages.md) |
471
+ | Turn events | `TURN_EVENT_SCHEMAS` (each kind's schema, for a wire parser), `turnEventSchema`, `ToolOutputPart` and `toolOutputPartSchema` (a tool's output parts: what the model reads, what is sent, and references), `turnHistoryMessageSchema`, `turnToolSnapshotSchema`, `reasoningPartSchema`, `historyHash`, `turnDoneOf`, `keptReply` (a turn's events without the replies a retry threw away), `z` (the zod these schemas are built with; compose them with it, since two copies of zod do not mix) — the event types themselves come through `export type *` from `src/kernel/types.ts` |
472
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`) |
473
473
  | Providers | `registerProvider`, `getProvider`, `listProviders`, `listProtocols`, `createProviderRegistry`, `defineProvider`, `Provider`, `ProviderDefinition`, `Registration`, `RegisteredProvider`, `ProviderRegistry`, `geminiProvider`, `openRouterProvider`, `typesafeProvider`, `localProvider` |
474
474
  | Provider sign-in | `bearer`, `header`, `query`, `Authorize`, `Signer`, `Outgoing`, `Serve`, `endpointUrlSchema` |
package/esm/mod.d.ts CHANGED
@@ -60,7 +60,7 @@ export type { AuthUnauthenticatedPolicy, ContinueStopKind, CustomToolType, HttpM
60
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';
61
61
  export type { KernelScope } from './src/kernel/scope.js';
62
62
  export { createKernelScope, defaultKernelScope } from './src/kernel/scope.js';
63
- export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOutput, StageApplyWarning, StageApplyWarningCode, StageContext, StageEventExtra, StageHandler, StageMutate, StageResult, } from './src/kernel/stages.js';
63
+ export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOutput, StageApplyWarning, StageApplyWarningCode, StageContext, StageEventExtra, StageHandler, StageMutate, StageMutateSubject, StageResult, } from './src/kernel/stages.js';
64
64
  export { applyStageResult, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './src/kernel/stages.js';
65
65
  export type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './src/kernel/stop.js';
66
66
  export { AUTO_CONTINUE_DELAY_MS, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, } from './src/kernel/stop.js';
@@ -77,8 +77,8 @@ export { askUserTool, assertToolSettings, buildHttpToolTarget, createToolRegistr
77
77
  export type { BackgroundToolEvent, BeginToolOperationResult, PageToolDispatch, PageToolExecution, SavedToolInvocation, TerminalToolEvent, ToolExecutionCoordinator, ToolOperationClaim, ToolOperationIdentity, ToolOperationOutcome, ToolOperationReply, ToolOperationUncertainty, } from './src/kernel/tools/operation.js';
78
78
  export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './src/kernel/tools/operation.js';
79
79
  export type { SettledToolCall, ToolCallResult, ToolStepCallResult, } from './src/kernel/tools/run.js';
80
- export type { ModelToolResult, PageAnswer, ToolContext } from './src/kernel/tools/types.js';
81
- export { awaitingUserInputSchema, type GateReference, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './src/kernel/turn-events.js';
80
+ export type { ModelToolResult, PageAnswer, ToolContext, ToolMediaEntry, } from './src/kernel/tools/types.js';
81
+ export { awaitingUserInputSchema, type GateReference, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, type ToolOutputPart, TURN_EVENT_SCHEMAS, toolGateSchema, toolOutputPartSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './src/kernel/turn-events.js';
82
82
  export type * from './src/kernel/types.js';
83
83
  export type { OtlpAnyValue, OtlpKeyValue, OtlpSpan, OtlpTraceRequest, ProfileObservabilitySpec, ResolvedObservabilityPolicy, ResolvedScrubSwitch, ResolvedTraceInclude, ResolvedTraceScrub, ScrubSwitch, SpanHandle, SpanLinkInput, SpanOptions, TraceAttributeGroup, TraceAttributeMeta, TraceAttributes, TraceAttributeValue, TraceBytes, TraceClock, TraceContent, TraceEventMeta, TraceIncludeSpec, TraceJson, TraceOptionMeta, TraceRecord, TraceScrubSpec, TraceSink, TraceSpan, TraceSpanEvent, TraceSpanKind, TraceSpanLink, TraceSpanMeta, TraceSpanStatus, TraceSpanType, TraceTree, TraceValueFormat, TraceWriteContext, } from './src/observability/mod.js';
84
84
  export { buildRecord, clearTraceDestinations, contentOf, getTraceDestination, inlineContent, isTraceSink, listTraceDestinationIds, memorySink, noopSink, readTraceparent, registerTraceDestination, requireTraceDestination, resolveObservabilityPolicy, resolveTraceWriter, startTrace, TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, toOtlpJson, traceAttributeMeta, traceBytes, traceContent, traceEventAttributeMeta, traceEventMeta, traceJson, traceRecordSchema, traceSpanMeta, writeTrace, } from './src/observability/mod.js';
package/esm/mod.js CHANGED
@@ -47,6 +47,6 @@ export { GATE_DECISIONS } from './src/kernel/tools/gate-answer.js';
47
47
  export { createMemoryToolExecution } from './src/kernel/tools/memory-execution.js';
48
48
  export { askUserTool, assertToolSettings, buildHttpToolTarget, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, formatToolFailureForModel, formatToolResult, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, resolveToolAuth, UncheckedOutput, uncheckedOutput, withCredentialQuery, } from './src/kernel/tools/mod.js';
49
49
  export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './src/kernel/tools/operation.js';
50
- export { awaitingUserInputSchema, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './src/kernel/turn-events.js';
50
+ export { awaitingUserInputSchema, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, toolOutputPartSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './src/kernel/turn-events.js';
51
51
  export { buildRecord, clearTraceDestinations, contentOf, getTraceDestination, inlineContent, isTraceSink, listTraceDestinationIds, memorySink, noopSink, readTraceparent, registerTraceDestination, requireTraceDestination, resolveObservabilityPolicy, resolveTraceWriter, startTrace, TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, toOtlpJson, traceAttributeMeta, traceBytes, traceContent, traceEventAttributeMeta, traceEventMeta, traceJson, traceRecordSchema, traceSpanMeta, writeTrace, } from './src/observability/mod.js';
52
52
  export * from './src/providers/mod.js';
@@ -31,10 +31,11 @@ declare function composeToolText(finding: string, data: unknown): string;
31
31
  * Local host tools are still detected — a host tool reading a database returns
32
32
  * data the host did not write — but only remote origins are fenced, because
33
33
  * fencing a local tool's output would change prompts hosts have already tuned.
34
- * `boundary` is absent for text that crosses none: a provider builtin's, or a
35
- * failure already read at its own boundary, whose findings come in as `carried`.
34
+ * `boundary` is absent for text that crosses none: a provider builtin's. `read` is `'data'` for a
35
+ * failure: its message was read at the boundary already and framed by the kernel, so only its
36
+ * details are read here, and the message's findings come in as `carried`.
36
37
  */
37
- declare function guardToolResult(finding: string, data: unknown, provenance: Provenance, policy: ResolvedGuardrailPolicy, boundary: ToolBoundary | undefined, callableTools?: readonly string[], labels?: LabelOverrides, carried?: GuardrailHit[]): GuardedToolText;
38
+ declare function guardToolResult(finding: string, data: unknown, provenance: Provenance, policy: ResolvedGuardrailPolicy, boundary: ToolBoundary | undefined, callableTools?: readonly string[], labels?: LabelOverrides, carried?: GuardrailHit[], read?: 'all' | 'data'): GuardedToolText;
38
39
  /**
39
40
  * A remote server authors its own error strings, so an unguarded failure message
40
41
  * is the cleanest injection path across this boundary: it reaches the model
@@ -104,12 +104,15 @@ function suspiciousHits(hits, provenance) {
104
104
  * Local host tools are still detected — a host tool reading a database returns
105
105
  * data the host did not write — but only remote origins are fenced, because
106
106
  * fencing a local tool's output would change prompts hosts have already tuned.
107
- * `boundary` is absent for text that crosses none: a provider builtin's, or a
108
- * failure already read at its own boundary, whose findings come in as `carried`.
107
+ * `boundary` is absent for text that crosses none: a provider builtin's. `read` is `'data'` for a
108
+ * failure: its message was read at the boundary already and framed by the kernel, so only its
109
+ * details are read here, and the message's findings come in as `carried`.
109
110
  */
110
- function guardToolResult(finding, data, provenance, policy, boundary, callableTools = [], labels, carried = []) {
111
- const composed = composeToolText(finding, data);
112
- const detected = readAt(composed, boundary, policy.detect, { callable: callableTools });
111
+ function guardToolResult(finding, data, provenance, policy, boundary, callableTools = [], labels, carried = [], read = 'all') {
112
+ const head = read === 'data' ? finding : '';
113
+ const composed = composeToolText(read === 'data' ? '' : finding, data);
114
+ const scanned = readAt(composed, boundary, policy.detect, { callable: callableTools });
115
+ const detected = scanned.text === undefined ? scanned : { ...scanned, text: `${head}${scanned.text}` };
113
116
  const remote = isRemoteOrigin(provenance.origin);
114
117
  const suspicious = [...carried, ...suspiciousHits(detected.hits, provenance)];
115
118
  const event = detected.action === 'allow'
@@ -1,7 +1,6 @@
1
1
  import { keptReply } from '../kernel/turn-events.js';
2
2
  import { partialJsonObject } from '../kernel/util/partial-json.js';
3
3
  import { applyToolDraft, applyToolEvent } from './tool-calls.js';
4
- import { collectPromotedMediaFromToolOutput } from './tool-media.js';
5
4
  let turnBlockCounter = 0;
6
5
  /**
7
6
  * User block ids are random: a counter restarts wherever this module loads
@@ -136,22 +135,6 @@ function foldCitation(blocks, event, idPrefix) {
136
135
  ...(event.callId !== undefined ? { callId: event.callId } : {}),
137
136
  });
138
137
  }
139
- function appendPromotedToolMedia(blocks, tool, idPrefix, seenUrls) {
140
- if (tool.phase !== 'complete' || tool.output === undefined)
141
- return;
142
- for (const media of collectPromotedMediaFromToolOutput(tool.output)) {
143
- if (seenUrls.has(media.url))
144
- continue;
145
- seenUrls.add(media.url);
146
- blocks.push({
147
- id: nextBlockId(idPrefix),
148
- kind: 'media',
149
- mimeType: media.mimeType,
150
- url: media.url,
151
- ...(media.previewUrl ? { previewUrl: media.previewUrl } : {}),
152
- });
153
- }
154
- }
155
138
  /**
156
139
  * A named inject's user messages as the user's own blocks, where the reply took them in: its
157
140
  * text, then a block per file. A message from anyone else (a host's note) is not the user's to show.
@@ -256,7 +239,9 @@ function standaloneBlock(event, idPrefix) {
256
239
  }
257
240
  }
258
241
  /**
259
- * The media a tool returned beside its output, where the call stands in the reply.
242
+ * The media a tool returned beside its output, where the call stands in the reply: bytes, `sent`
243
+ * when the tool sent them to the person, and references, always sent and kept as `uri` for the
244
+ * app's resolver.
260
245
  * why: a tool sends a picture when it runs, so the picture comes before what the model says next.
261
246
  */
262
247
  function appendToolParts(blocks, tool, idPrefix) {
@@ -269,7 +254,10 @@ function appendToolParts(blocks, tool, idPrefix) {
269
254
  id: nextBlockId(idPrefix),
270
255
  kind: 'media',
271
256
  mimeType: part.mimeType,
272
- ...('data' in part ? { data: part.data } : { url: part.uri }),
257
+ fromTool: true,
258
+ ...('data' in part
259
+ ? { data: part.data, ...(part.sent ? { sent: true } : {}) }
260
+ : { uri: part.uri, type: part.type, sent: true }),
273
261
  });
274
262
  }
275
263
  }
@@ -279,7 +267,6 @@ function foldTurnEvents(events, options = {}) {
279
267
  const showThoughts = options.showThoughts ?? true;
280
268
  turnBlockCounter = 0;
281
269
  const blocks = [];
282
- const promotedMediaUrls = new Set();
283
270
  for (const event of keptReply(events)) {
284
271
  switch (event.type) {
285
272
  case 'thought':
@@ -297,7 +284,6 @@ function foldTurnEvents(events, options = {}) {
297
284
  break;
298
285
  case 'tool':
299
286
  upsertToolBlock(blocks, event.tool);
300
- appendPromotedToolMedia(blocks, event.tool, idPrefix, promotedMediaUrls);
301
287
  appendToolParts(blocks, event.tool, idPrefix);
302
288
  break;
303
289
  case 'structured_draft':
@@ -3,6 +3,7 @@
3
3
  import { TheoremError } from '../guardrails/error.js';
4
4
  import { labelText } from '../guardrails/labels.js';
5
5
  import { lateResultsMessage } from '../guardrails/tool-fence.js';
6
+ import { stepReplyMessages } from '../kernel/interaction-parts.js';
6
7
  import { mediaKindForMime } from '../kernel/registry/catalog.js';
7
8
  import { formatToolFailureForModel, formatToolResult } from '../kernel/tools/model-text.js';
8
9
  import { keptReply } from '../kernel/turn-events.js';
@@ -59,27 +60,15 @@ function appendUserDraftToHistory(history, draft, media = {}) {
59
60
  }
60
61
  return [...history, { role: 'user', parts }];
61
62
  }
62
- function toolCallEntry(tool) {
63
- return {
64
- id: tool.callId,
65
- type: 'function',
66
- function: { name: tool.name, arguments: JSON.stringify(tool.arguments) },
67
- };
68
- }
69
- /** The assistant message holding a step's calls, with the reasoning the model wrote before them. */
70
- function assistantCalls(tools) {
71
- const reasoning = tools.flatMap((tool) => tool.reasoning ?? []);
72
- return {
73
- role: 'assistant',
74
- tool_calls: tools.map(toolCallEntry),
75
- ...(reasoning.length ? { reasoning } : {}),
76
- };
77
- }
78
63
  function toolResultMessage(tool, content) {
79
64
  return { role: 'tool', tool_call_id: tool.callId, name: tool.name, content };
80
65
  }
81
66
  function appendToolCallPair(history, tool, content) {
82
- return [...history, assistantCalls([tool]), toolResultMessage(tool, content)];
67
+ return [
68
+ ...history,
69
+ ...stepReplyMessages({ text: '', calls: [tool] }),
70
+ toolResultMessage(tool, content),
71
+ ];
83
72
  }
84
73
  /** The history with a tool call and its result added. */
85
74
  function appendToolExchangeToHistory(history, call) {
@@ -109,12 +98,14 @@ function settledToolContent(call) {
109
98
  : undefined;
110
99
  }
111
100
  /**
112
- * One model step's settled calls: a single assistant message holding every call
113
- * the step made, with the reasoning written before them, then each result, as a provider
114
- * reads a step's calls back. With `gated: 'open'`, a
115
- * call waiting on its gate joins the message too, left without a result.
101
+ * One model step: a single assistant message holding what the step wrote and
102
+ * every settled call it made, with the reasoning written before them, then
103
+ * each result, as a provider reads a step back. With `gated: 'open'`, a call
104
+ * waiting on its gate joins the message too, left without a result. A step
105
+ * whose calls are all left out keeps its words.
116
106
  */
117
- function appendToolStepToHistory(history, calls, gated = 'omit') {
107
+ function appendToolStepToHistory(history, step, gated = 'omit') {
108
+ const { text, calls } = step;
118
109
  const entries = calls.flatMap((call) => {
119
110
  const content = settledToolContent(call);
120
111
  if (content !== undefined)
@@ -123,11 +114,9 @@ function appendToolStepToHistory(history, calls, gated = 'omit') {
123
114
  ? [{ tool: historyToolCall(call) }]
124
115
  : [];
125
116
  });
126
- if (entries.length === 0)
127
- return history;
128
117
  return [
129
118
  ...history,
130
- assistantCalls(entries.map(({ tool }) => tool)),
119
+ ...stepReplyMessages({ text, calls: entries.map(({ tool }) => tool) }),
131
120
  ...entries.flatMap(({ tool, content }) => content === undefined ? [] : [toolResultMessage(tool, content)]),
132
121
  ];
133
122
  }
@@ -160,7 +149,7 @@ function foldAssistantEvents(history, events, gated) {
160
149
  return;
161
150
  }
162
151
  const stepCalls = step.callKeys.flatMap((id) => calls.get(id) ?? []);
163
- next = appendToolStepToHistory(next, stepCalls, gated);
152
+ next = appendToolStepToHistory(next, { text: step.text, calls: stepCalls }, gated);
164
153
  step = undefined;
165
154
  };
166
155
  for (const event of keptReply(events)) {
@@ -200,8 +189,9 @@ function foldAssistantEvents(history, events, gated) {
200
189
  }
201
190
  if (!step || call.stepId === undefined || step.stepId !== call.stepId) {
202
191
  flushStep();
203
- flushText();
204
- step = { stepId: call.stepId, callKeys: [] };
192
+ // why: The words written just before a step's calls are that step's reply: one message.
193
+ step = { stepId: call.stepId, text: textBuf, callKeys: [] };
194
+ textBuf = '';
205
195
  }
206
196
  step.callKeys.push(key);
207
197
  }
@@ -212,26 +202,39 @@ function foldAssistantEvents(history, events, gated) {
212
202
  /** Attachment and voice blocks are omitted: their preview `data` is UI-only. */
213
203
  function historyFromTranscriptBlocks(blocks) {
214
204
  let history = [];
215
- let step = [];
205
+ let text = '';
206
+ let step = { text: '', calls: [] };
207
+ const flushText = () => {
208
+ if (text)
209
+ history = [...history, { role: 'assistant', content: text }];
210
+ text = '';
211
+ };
216
212
  const flushStep = () => {
217
- history = appendToolStepToHistory(history, step);
218
- step = [];
213
+ if (step.calls.length)
214
+ history = appendToolStepToHistory(history, step);
215
+ step = { text: '', calls: [] };
219
216
  };
220
217
  for (const block of blocks) {
221
218
  if (block.kind === 'tool') {
222
- const open = step[0];
219
+ const open = step.calls[0];
223
220
  if (open && (open.stepId === undefined || open.stepId !== block.tool.stepId))
224
221
  flushStep();
225
- step.push(block.tool);
222
+ if (step.calls.length === 0) {
223
+ // why: The words written just before a step's calls are that step's reply: one message.
224
+ step.text = text;
225
+ text = '';
226
+ }
227
+ step.calls.push(block.tool);
226
228
  continue;
227
229
  }
228
230
  flushStep();
231
+ flushText();
229
232
  if (block.kind === 'user-text') {
230
233
  history = appendUserDraftToHistory(history, { text: block.text });
231
234
  continue;
232
235
  }
233
236
  if (block.kind === 'text') {
234
- history = [...history, { role: 'assistant', content: block.text }];
237
+ text = block.text;
235
238
  continue;
236
239
  }
237
240
  if (block.kind === 'late-results') {
@@ -243,6 +246,7 @@ function historyFromTranscriptBlocks(blocks) {
243
246
  }
244
247
  }
245
248
  flushStep();
249
+ flushText();
246
250
  return history;
247
251
  }
248
252
  function lastToolStep(history) {
@@ -27,7 +27,5 @@ export { stopText, WORDED_STOP_KINDS } from './stop.js';
27
27
  export type { SettledToolCallEvent } from './tool-calls.js';
28
28
  export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
29
29
  export { promotedToolIdsFromEvents, type ReplyCarried, replyCarriedFromEvents, toolSnapshotFromEvents, } from './tool-invoke.js';
30
- export type { PromotedToolMedia } from './tool-media.js';
31
- export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
32
30
  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
31
  export { streamThoughtsEnabled } from './types.js';
@@ -18,5 +18,4 @@ export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSessio
18
18
  export { stopText, WORDED_STOP_KINDS } from './stop.js';
19
19
  export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
20
20
  export { promotedToolIdsFromEvents, replyCarriedFromEvents, toolSnapshotFromEvents, } from './tool-invoke.js';
21
- export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
22
21
  export { streamThoughtsEnabled } from './types.js';
@@ -3,6 +3,7 @@ import type { DetectAction, DetectMatrix, Detector, UrlDetector } from '../guard
3
3
  import type { GuardrailEvent } from '../guardrails/event-schemas.js';
4
4
  import type { LabelOverrides } from '../guardrails/labels.js';
5
5
  import type { ResolvedGuardrailPolicy } from '../guardrails/types.js';
6
+ import type { MediaInputKind } from '../kernel/schema.js';
6
7
  import type { ProfileToolsSpec, ToolCallEdit, ToolPhaseEvent } from '../kernel/tools/types.js';
7
8
  import type { ReasoningPart } from '../kernel/turn-events.js';
8
9
  import type { AttachmentValidationIssue, CompactionSpec, GroundingEvent, ImageProfile, LiveProfile, ModelBinding, ModelId, ProfileContextSpec, ProfileOptions, ProfileOutputsSpec, ProviderEvidence, Source, SpeechProfile, TextProfile, TranscriptionProfile, TurnStop, TurnTokens } from '../kernel/types.js';
@@ -203,12 +204,19 @@ export interface StructuredBlock extends TranscriptBlockBase {
203
204
  export interface MediaBlock extends TranscriptBlockBase {
204
205
  kind: 'media';
205
206
  mimeType: string;
206
- /** Base64 for media a model generated, a tool returned or a person attached. Absent when `url` is set. */
207
+ /** Base64 for media a model generated, a tool returned or a person attached. Absent when `uri` is set. */
207
208
  data?: string;
208
- /** Remote URL from completed tool output or a tool's media part. Absent when `data` is set. */
209
- url?: string;
210
- /** A smaller copy of `url` for previews, when the tool output offered one. */
211
- previewUrl?: string;
209
+ /**
210
+ * A reference a tool returned, `{ type, mimeType, uri }`. The model never read it, and it is
211
+ * never a `src` itself: only what the app's own resolver makes of it is shown. Absent when `data` is set.
212
+ */
213
+ uri?: string;
214
+ /** The kind of media `uri` names, as the tool gave it. */
215
+ type?: MediaInputKind;
216
+ /** A tool returned it, rather than a model generating it or a person attaching it. */
217
+ fromTool?: true;
218
+ /** The tool sent it to the person: a reference always is; media bytes when the tool said `sent: true`. */
219
+ sent?: true;
212
220
  }
213
221
  export interface GroundingBlock extends TranscriptBlockBase {
214
222
  kind: 'grounding';
@@ -41,7 +41,8 @@ function withoutTextTail(events, count) {
41
41
  * history messages, from what the attempt gate reads, and from the reply. Returns `released` when
42
42
  * a draft was dropped.
43
43
  *
44
- * invariant: A message that keeps no text leaves history; a call it made stays on its own message.
44
+ * invariant: A message that keeps no text leaves history, unless it made calls: then it stays
45
+ * with its calls and without the words.
45
46
  */
46
47
  function dropDraft(state, released) {
47
48
  if (released === undefined || released >= state.replyText.length)
@@ -62,6 +63,10 @@ function dropDraft(state, released) {
62
63
  state.currentHistory[index] = cut;
63
64
  kept.push({ message: cut, at });
64
65
  }
66
+ else if (message.tool_calls) {
67
+ const { content: _dropped, ...calls } = message;
68
+ state.currentHistory[index] = calls;
69
+ }
65
70
  else
66
71
  state.currentHistory.splice(index, 1);
67
72
  }
@@ -486,7 +486,7 @@ function* applyToolSettlement(settlement, state, call) {
486
486
  }
487
487
  return settlement.ended ? 'ended' : 'continue';
488
488
  }
489
- /** A step's reply as the model reads it back: its text, then its calls with the reasoning before them. */
489
+ /** A step's reply as the model reads it back: one message with its text, its calls, and the reasoning before them. */
490
490
  function stepReply(outcome) {
491
491
  return stepReplyMessages({
492
492
  text: outcome.text,
@@ -11,6 +11,7 @@ import { resolveObservabilityPolicy } from '../../../observability/resolve-polic
11
11
  import { liveToolReadBack } from '../../../providers/live.js';
12
12
  import { memoryCredentialSource } from '../../auth/credential-source.js';
13
13
  import { historyHash } from '../../checkpoint.js';
14
+ import { stepReplyMessages } from '../../interaction-parts.js';
14
15
  import { openRegisteredLiveSession } from '../../provider-live.js';
15
16
  import { assertHistoryKept } from '../../provider-runtime.js';
16
17
  import { assertTurnContext } from '../../registry/ingress.js';
@@ -293,6 +294,23 @@ function finalTranscript(event, kind) {
293
294
  return;
294
295
  return event.text || undefined;
295
296
  }
297
+ /**
298
+ * Adds a live call to history in place. The words the model said just before
299
+ * it are the same reply, so the call joins that message, as every API reads a
300
+ * reply back.
301
+ */
302
+ function joinLiveCall(history, call) {
303
+ const last = history.at(-1);
304
+ const said = last?.role === 'assistant' &&
305
+ !last.tool_calls &&
306
+ !last.parts &&
307
+ typeof last.content === 'string'
308
+ ? last.content
309
+ : undefined;
310
+ if (said !== undefined)
311
+ history.pop();
312
+ history.push(...stepReplyMessages({ text: said ?? '', calls: [call] }));
313
+ }
296
314
  async function sealLiveCheckpoints(events, history, calls, keepsHistory) {
297
315
  const sealed = [];
298
316
  for (const event of events) {
@@ -308,16 +326,7 @@ async function sealLiveCheckpoints(events, history, calls, keepsHistory) {
308
326
  for (const [callId, held] of calls) {
309
327
  if (covered.some((message) => message.tool_calls?.some((call) => call.id === callId)))
310
328
  continue;
311
- covered.push({
312
- role: 'assistant',
313
- tool_calls: [
314
- {
315
- id: callId,
316
- type: 'function',
317
- function: { name: held.name, arguments: JSON.stringify(held.arguments) },
318
- },
319
- ],
320
- });
329
+ joinLiveCall(covered, { callId, name: held.name, arguments: held.arguments });
321
330
  }
322
331
  sealed.push({
323
332
  ...event,
@@ -412,19 +421,8 @@ function buildLiveSession(args) {
412
421
  history.push({ role: 'assistant', content: text });
413
422
  };
414
423
  const recordToolSettle = (tool, readBack, parts) => {
424
+ joinLiveCall(history, tool);
415
425
  history.push({
416
- role: 'assistant',
417
- tool_calls: [
418
- {
419
- id: tool.callId,
420
- type: 'function',
421
- function: {
422
- name: tool.name,
423
- arguments: JSON.stringify(tool.arguments),
424
- },
425
- },
426
- ],
427
- }, {
428
426
  role: 'tool',
429
427
  tool_call_id: tool.callId,
430
428
  name: tool.name,
@@ -323,8 +323,7 @@ export const FIELD_DOCS = {
323
323
  'registerTool.headers': "Headers sent with every request to the tool's own origin, never once a redirect leaves it.",
324
324
  'registerTool.hostFields': 'Fields on an agent tool that only the host reads. The calling model fills them, or the host does when a field is marked exposeToModel: false. onAgentCall gets them as hostInput and turns them into what the agent is sent; the agent never sees them. A name the input already has is refused when the tool registers.',
325
325
  'registerTool.hostOnly': '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.',
326
- 'registerTool.imageLimits': 'How many of those pictures the kernel fetches, how large, and how slowly.',
327
- 'registerTool.images': 'The https addresses of pictures in the output the model should see. The kernel fetches each one through the profile network policy, without the tool credentials.',
326
+ 'registerTool.imageLimits': 'How many of the pictures `media` names the kernel fetches, how large, and how slowly.',
328
327
  'registerTool.input': "The Zod schema for the tool's arguments, sent to the model and checked on every call.",
329
328
  'registerTool.inputSchema': "The tool's arguments as a JSON Schema, sent to the model.",
330
329
  'registerTool.labels': "Transcript text for a call. {path} reads a value from the call. {results.0.name} reads a list item. {path|text} shows the text when the value is unusable. {count hit|hits} shows a number with the word for one or for any other number: '1 hit', '3 hits'. With no fallback, the label is dropped. A label is one line, or a list read top to bottom: the first line that fits is shown. A line fits when each {path} has a value and its condition holds, as in 'when status is archived: archiving {title}'. Neighbouring lines that open with '+ ' show together, joined in words. The last line of a list must always fit.",
@@ -341,6 +340,7 @@ export const FIELD_DOCS = {
341
340
  'registerTool.maxCallsPerTurn': 'How many times one turn of the calling agent may run this tool.',
342
341
  'registerTool.maxResponseBytes': 'The most bytes of a response body an HTTP or MCP tool reads; past it the call fails with response_too_large.',
343
342
  'registerTool.mcpToolName': "The tool's name on the MCP server.",
343
+ 'registerTool.media': 'The media in the output: pictures the model should see, and references the person is shown.',
344
344
  'registerTool.method': 'The HTTP method; every method but GET sends a JSON body.',
345
345
  'registerTool.name': "The tool's id, which profiles list in tools.allow (or a model's builtInTools) and the model calls a custom tool by.",
346
346
  'registerTool.output': "The Zod schema every result the tool returns must match; the kernel's own not-signed-in note is not checked.",
@@ -1,3 +1,4 @@
1
+ import type { ToolCallRequest } from './turn-events.js';
1
2
  import type { InteractionMediaRefPart, InteractionPart, TurnHistoryMessage } from './types.js';
2
3
  /** True for a part that is media referenced by `uri` rather than carried as data. */
3
4
  export declare function isMediaRefPart(part: InteractionPart): part is InteractionMediaRefPart;
@@ -8,16 +9,16 @@ export declare function isMediaRefPart(part: InteractionPart): part is Interacti
8
9
  */
9
10
  export declare function historyMessageParts(msg: TurnHistoryMessage): InteractionPart[];
10
11
  /**
11
- * One model call's reply as the model reads it back later in its turn: what it
12
- * wrote (its structured reply, when it gave one), then the calls it made. Turn
13
- * history and a provider checkpoint both build it here, so the checkpoint
14
- * covers exactly the history the turn's next call sends.
12
+ * One model call's reply as the model reads it back later in its turn: one
13
+ * assistant message with what it wrote (its structured reply, when it gave
14
+ * one), the calls it made, and the reasoning it wrote with them. Every API
15
+ * takes a reply this way, as one message; split in two, the words read as a
16
+ * reply already finished, and the model writes them again. Turn history, a
17
+ * provider checkpoint, a live session, and a client's history all build it
18
+ * here, so the checkpoint covers exactly the history the turn's next call sends.
15
19
  */
16
20
  export declare function stepReplyMessages(reply: {
17
21
  text: string;
18
22
  structured?: unknown;
19
- calls: Parameters<typeof historyToolCalls>[0];
23
+ calls: readonly Pick<ToolCallRequest, 'callId' | 'name' | 'arguments' | 'reasoning'>[];
20
24
  }): TurnHistoryMessage[];
21
- /** One step's calls as the assistant message that made them, with the reasoning written before them. */
22
- declare function historyToolCalls(calls: readonly Pick<import('./turn-events.js').ToolCallRequest, 'callId' | 'name' | 'arguments' | 'reasoning'>[]): TurnHistoryMessage;
23
- export {};
@@ -12,32 +12,30 @@ export function historyMessageParts(msg) {
12
12
  return msg.content ? [{ type: 'text', text: msg.content }, ...parts] : [...parts];
13
13
  }
14
14
  /**
15
- * One model call's reply as the model reads it back later in its turn: what it
16
- * wrote (its structured reply, when it gave one), then the calls it made. Turn
17
- * history and a provider checkpoint both build it here, so the checkpoint
18
- * covers exactly the history the turn's next call sends.
15
+ * One model call's reply as the model reads it back later in its turn: one
16
+ * assistant message with what it wrote (its structured reply, when it gave
17
+ * one), the calls it made, and the reasoning it wrote with them. Every API
18
+ * takes a reply this way, as one message; split in two, the words read as a
19
+ * reply already finished, and the model writes them again. Turn history, a
20
+ * provider checkpoint, a live session, and a client's history all build it
21
+ * here, so the checkpoint covers exactly the history the turn's next call sends.
19
22
  */
20
23
  export function stepReplyMessages(reply) {
21
24
  const content = reply.structured !== undefined ? JSON.stringify(reply.structured) : reply.text;
25
+ if (!content && reply.calls.length === 0)
26
+ return [];
27
+ const reasoning = reply.calls.flatMap((call) => call.reasoning ?? []);
28
+ const tool_calls = reply.calls.map((call) => ({
29
+ id: call.callId,
30
+ type: 'function',
31
+ function: { name: call.name, arguments: JSON.stringify(call.arguments) },
32
+ }));
22
33
  return [
23
- ...(content ? [{ role: 'assistant', content }] : []),
24
- ...(reply.calls.length ? [historyToolCalls(reply.calls)] : []),
34
+ {
35
+ role: 'assistant',
36
+ ...(content ? { content } : {}),
37
+ ...(tool_calls.length ? { tool_calls } : {}),
38
+ ...(reasoning.length ? { reasoning } : {}),
39
+ },
25
40
  ];
26
41
  }
27
- /** One step's calls as the assistant message that made them, with the reasoning written before them. */
28
- function historyToolCalls(calls) {
29
- const reasoning = calls.flatMap((call) => call.reasoning ?? []);
30
- const tool_calls = [];
31
- for (const call of calls) {
32
- tool_calls.push({
33
- id: call.callId,
34
- type: 'function',
35
- function: { name: call.name, arguments: JSON.stringify(call.arguments) },
36
- });
37
- }
38
- return {
39
- role: 'assistant',
40
- tool_calls,
41
- ...(reasoning.length ? { reasoning: [...reasoning] } : {}),
42
- };
43
- }
@@ -55,7 +55,7 @@ export type { AuthUnauthenticatedPolicy, CustomToolType, HttpMethod, StudioAuthT
55
55
  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, 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';
56
56
  export type { KernelScope } from './scope.js';
57
57
  export { createKernelScope, defaultKernelScope } from './scope.js';
58
- export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOutput, StageApplyWarning, StageApplyWarningCode, StageContext, StageEventExtra, StageHandler, StageMutate, StageResult, } from './stages.js';
58
+ export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOutput, StageApplyWarning, StageApplyWarningCode, StageContext, StageEventExtra, StageHandler, StageMutate, StageMutateSubject, StageResult, } from './stages.js';
59
59
  export { applyStageResult, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './stages.js';
60
60
  export type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './stop.js';
61
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, } from './stop.js';
@@ -76,8 +76,8 @@ export type { BackgroundToolEvent, BeginToolOperationResult, PageToolDispatch, P
76
76
  export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './tools/operation.js';
77
77
  export { jsonSchemaFromZod } from './tools/schema.js';
78
78
  export { CredentialRefusedError } from './tools/signed-in-fetch.js';
79
- export type { ModelToolResult, PageAnswer, ToolAuthConfig, ToolContext, ToolLabels, } from './tools/types.js';
80
- export { awaitingUserInputSchema, type GateReference, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './turn-events.js';
79
+ export type { ModelToolResult, PageAnswer, ToolAuthConfig, ToolContext, ToolLabels, ToolMediaEntry, } from './tools/types.js';
80
+ export { awaitingUserInputSchema, type GateReference, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, type ToolOutputPart, TURN_EVENT_SCHEMAS, toolGateSchema, toolOutputPartSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './turn-events.js';
81
81
  export type * from './types.js';
82
82
  export { base64ToBytes, bytesToBase64 } from './util/base64.js';
83
83
  export type { Equals } from './util/exact-type.js';
@@ -46,6 +46,6 @@ export { askUserTool, assertToolSettings, authorizeToolReplay, coerceToolResultP
46
46
  export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './tools/operation.js';
47
47
  export { jsonSchemaFromZod } from './tools/schema.js';
48
48
  export { CredentialRefusedError } from './tools/signed-in-fetch.js';
49
- export { awaitingUserInputSchema, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './turn-events.js';
49
+ export { awaitingUserInputSchema, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, toolOutputPartSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './turn-events.js';
50
50
  export { base64ToBytes, bytesToBase64 } from './util/base64.js';
51
51
  export { isRecord } from './util/record.js';