@theoremjs/agents 0.3.4-next.733.g0520b79 → 0.3.4-next.747.g0909061
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/src/guardrails/canary.js +18 -10
- package/esm/src/guardrails/destinations.js +6 -1
- package/esm/src/guardrails/egress-urls.js +3 -1
- package/esm/src/guardrails/labels.d.ts +1 -1
- package/esm/src/guardrails/labels.js +9 -0
- package/esm/src/guardrails/mod.d.ts +2 -1
- package/esm/src/guardrails/mod.js +2 -1
- package/esm/src/guardrails/tool-fence.d.ts +23 -0
- package/esm/src/guardrails/tool-fence.js +38 -0
- package/esm/src/guardrails/tool-result.d.ts +1 -15
- package/esm/src/guardrails/tool-result.js +2 -22
- package/esm/src/host/client-turn.js +8 -1
- package/esm/src/interface/blocks.js +2 -0
- package/esm/src/interface/history.js +10 -0
- package/esm/src/interface/types.d.ts +10 -2
- package/esm/src/kernel/api-catalog.js +1 -1
- package/esm/src/kernel/engine/runner/mod.js +7 -1
- package/esm/src/kernel/engine/runner/refused-media.d.ts +17 -0
- package/esm/src/kernel/engine/runner/refused-media.js +54 -0
- package/esm/src/kernel/engine/runner/state.d.ts +9 -3
- package/esm/src/kernel/engine/runner/state.js +40 -17
- package/esm/src/kernel/engine/runner/steps.js +43 -2
- package/esm/src/kernel/mod.d.ts +1 -1
- package/esm/src/kernel/mod.js +1 -1
- package/esm/src/kernel/profile-scope.d.ts +2 -0
- package/esm/src/kernel/profile-scope.js +1 -1
- package/esm/src/kernel/protocols/binding.js +1 -1
- package/esm/src/kernel/registry/profiles.js +9 -4
- package/esm/src/kernel/schema.d.ts +9 -0
- package/esm/src/kernel/schema.js +107 -1
- package/esm/src/kernel/stop.d.ts +3 -1
- package/esm/src/kernel/tools/background.js +9 -4
- package/esm/src/kernel/tools/coordinate.js +4 -2
- package/esm/src/kernel/tools/execute.js +1 -1
- package/esm/src/kernel/tools/invoke.js +2 -2
- package/esm/src/kernel/tools/mod.d.ts +1 -1
- package/esm/src/kernel/tools/mod.js +1 -1
- package/esm/src/kernel/tools/model-text.d.ts +2 -0
- package/esm/src/kernel/tools/model-text.js +6 -1
- package/esm/src/kernel/tools/registry.d.ts +8 -2
- package/esm/src/kernel/tools/registry.js +38 -22
- package/esm/src/kernel/tools/types.d.ts +2 -11
- package/esm/src/kernel/turn-events.d.ts +23 -0
- package/esm/src/kernel/turn-events.js +8 -0
- package/esm/src/observability/trace-catalog.js +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -463,7 +463,7 @@ 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`, `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` |
|
|
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`, `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
|
+
| 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`, `prepareTurnToolSnapshot`, `buildHttpToolTarget`, `executeHttpTool`, `executeMcpTool`, `parseMcpRpcResponse`, `isUnsupportedMcpProtocolError`, `MCP_PROTOCOL_VERSIONS`, `mcpRequestMeta`, `McpProtocolVersion`, `resolveToolAuth`, `credentialPlacement`, `withCredentialQuery`, `CredentialQuery`, `uncheckedOutput`, `UncheckedOutput`, `McpRpcResponse`, `ModelToolResult`, `PageAnswer` |
|
|
467
467
|
| Tool execution | `ToolBackground`, `ToolBackgroundCall`, `ToolBackgroundHandle`, `ToolBackgroundService`, `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`, `turnStopFromInteractionStatus`, `turnStopFromOpenAiFinishReason` |
|
package/esm/mod.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export { GATE_DECISIONS, type GateDecision } from './src/kernel/tools/gate-answe
|
|
|
71
71
|
export type { MemoryToolExecutionOptions } from './src/kernel/tools/memory-execution.js';
|
|
72
72
|
export { createMemoryToolExecution } from './src/kernel/tools/memory-execution.js';
|
|
73
73
|
export type { CredentialQuery, McpProtocolVersion, McpRpcResponse, ToolRegistry, } from './src/kernel/tools/mod.js';
|
|
74
|
-
export { askUserTool, buildHttpToolTarget, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, formatToolResult, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, resolveToolAuth, UncheckedOutput, uncheckedOutput, withCredentialQuery, } from './src/kernel/tools/mod.js';
|
|
74
|
+
export { askUserTool, assertToolSettings, buildHttpToolTarget, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, formatToolResult, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, resolveToolAuth, UncheckedOutput, uncheckedOutput, withCredentialQuery, } from './src/kernel/tools/mod.js';
|
|
75
75
|
export type { BackgroundToolEvent, BeginToolOperationResult, PageToolDispatch, PageToolExecution, SavedToolInvocation, TerminalToolEvent, ToolExecutionCoordinator, ToolOperationClaim, ToolOperationIdentity, ToolOperationOutcome, ToolOperationReply, ToolOperationUncertainty, } from './src/kernel/tools/operation.js';
|
|
76
76
|
export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './src/kernel/tools/operation.js';
|
|
77
77
|
export type { SettledToolCall, ToolCallResult, ToolStepCallResult, } from './src/kernel/tools/run.js';
|
package/esm/mod.js
CHANGED
|
@@ -44,7 +44,7 @@ export { systemLinesProblem } from './src/kernel/system-lines.js';
|
|
|
44
44
|
export { authorizeToolReplay } from './src/kernel/tools/execute.js';
|
|
45
45
|
export { GATE_DECISIONS } from './src/kernel/tools/gate-answer.js';
|
|
46
46
|
export { createMemoryToolExecution } from './src/kernel/tools/memory-execution.js';
|
|
47
|
-
export { askUserTool, buildHttpToolTarget, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, formatToolResult, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, resolveToolAuth, UncheckedOutput, uncheckedOutput, withCredentialQuery, } from './src/kernel/tools/mod.js';
|
|
47
|
+
export { askUserTool, assertToolSettings, buildHttpToolTarget, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, formatToolResult, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, resolveToolAuth, UncheckedOutput, uncheckedOutput, withCredentialQuery, } from './src/kernel/tools/mod.js';
|
|
48
48
|
export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './src/kernel/tools/operation.js';
|
|
49
49
|
export { awaitingUserInputSchema, gateReferenceSchema, isAwaitingUserInput, keptReply, reasoningPartSchema, TURN_EVENT_SCHEMAS, toolGateSchema, turnDoneOf, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, } from './src/kernel/turn-events.js';
|
|
50
50
|
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';
|
|
@@ -834,12 +834,29 @@ function redactCanaryText(text, canary) {
|
|
|
834
834
|
function isGuardedOutput(event) {
|
|
835
835
|
return event.type !== 'thought';
|
|
836
836
|
}
|
|
837
|
+
const BARE_EVENT_TYPES = new Set([
|
|
838
|
+
'attempt',
|
|
839
|
+
'media',
|
|
840
|
+
'tokens',
|
|
841
|
+
'guardrail',
|
|
842
|
+
'stage',
|
|
843
|
+
'done',
|
|
844
|
+
'response',
|
|
845
|
+
'provider_checkpoint',
|
|
846
|
+
'provider_warning',
|
|
847
|
+
]);
|
|
848
|
+
/** An event that carries nothing to the host. */
|
|
849
|
+
function isBareEvent(event) {
|
|
850
|
+
return BARE_EVENT_TYPES.has(event.type);
|
|
851
|
+
}
|
|
837
852
|
/**
|
|
838
853
|
* What of an event reaches the host as content, field by field: the one list
|
|
839
854
|
* every canary and prompt-leak scan reads. Builder-only fields
|
|
840
855
|
* (`errorInternal`), counts, identities, and media bytes are not content.
|
|
841
856
|
*/
|
|
842
857
|
function hostContentOf(event) {
|
|
858
|
+
if (isBareEvent(event))
|
|
859
|
+
return [];
|
|
843
860
|
switch (event.type) {
|
|
844
861
|
case 'text':
|
|
845
862
|
case 'thought':
|
|
@@ -860,6 +877,7 @@ function hostContentOf(event) {
|
|
|
860
877
|
return [event.tool];
|
|
861
878
|
case 'tool_draft':
|
|
862
879
|
case 'structured_draft':
|
|
880
|
+
case 'late_results':
|
|
863
881
|
return [event.text];
|
|
864
882
|
case 'error':
|
|
865
883
|
return [event.error, event.errorCopy];
|
|
@@ -867,16 +885,6 @@ function hostContentOf(event) {
|
|
|
867
885
|
return [event.data];
|
|
868
886
|
case 'reasoning':
|
|
869
887
|
return [event.text];
|
|
870
|
-
case 'attempt':
|
|
871
|
-
case 'media':
|
|
872
|
-
case 'tokens':
|
|
873
|
-
case 'guardrail':
|
|
874
|
-
case 'stage':
|
|
875
|
-
case 'done':
|
|
876
|
-
case 'response':
|
|
877
|
-
case 'provider_checkpoint':
|
|
878
|
-
case 'provider_warning':
|
|
879
|
-
return [];
|
|
880
888
|
default: {
|
|
881
889
|
const unhandled = event;
|
|
882
890
|
return unhandled;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { labelText } from './labels.js';
|
|
8
8
|
import { TOOL_RULES } from './rules.js';
|
|
9
9
|
import { textForScan } from './serialize.js';
|
|
10
|
+
import { isLateResult } from './tool-fence.js';
|
|
10
11
|
import { isRemoteOrigin } from './tool-result.js';
|
|
11
12
|
function turnDestinations() {
|
|
12
13
|
return { given: new Set(), remote: new Map() };
|
|
@@ -165,8 +166,12 @@ function addGivenDestinations(turn, value) {
|
|
|
165
166
|
function addHistoryDestinations(turn, messages, own) {
|
|
166
167
|
for (const message of messages) {
|
|
167
168
|
// why: An earlier turn's tool result is neither the user's word nor this turn's read.
|
|
168
|
-
if (message.role === 'assistant' ||
|
|
169
|
+
if (message.role === 'assistant' ||
|
|
170
|
+
message.role === 'tool' ||
|
|
171
|
+
own.has(message) ||
|
|
172
|
+
isLateResult(message)) {
|
|
169
173
|
continue;
|
|
174
|
+
}
|
|
170
175
|
addGivenDestinations(turn, textForScan(message).text);
|
|
171
176
|
}
|
|
172
177
|
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
|
17
17
|
import { textForScan } from './serialize.js';
|
|
18
|
+
import { isLateResult } from './tool-fence.js';
|
|
18
19
|
function givenUrlSets() {
|
|
19
20
|
return { request: new Set(), tools: new Set(), own: new WeakSet() };
|
|
20
21
|
}
|
|
@@ -156,7 +157,8 @@ function addHistoryUrls(given, messages) {
|
|
|
156
157
|
for (const message of messages) {
|
|
157
158
|
if (message.role === 'assistant' || given.own.has(message))
|
|
158
159
|
continue;
|
|
159
|
-
|
|
160
|
+
const read = message.role === 'tool' || isLateResult(message);
|
|
161
|
+
addSeenUrls(read ? given.tools : given.request, textForScan(message).text);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
function addRequestUrls(given, request) {
|
|
@@ -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.after_field", "tool.background_field", "tool.background_started", "tool.late_result", "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", "turn.media_refused_image", "turn.media_refused_video", "turn.media_refused_file", "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.background_field", "tool.background_started", "tool.late_result", "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
|
/**
|
|
@@ -16,6 +16,9 @@ export const LABEL_KEYS = [
|
|
|
16
16
|
'provider.fallback_slot',
|
|
17
17
|
'provider.model_fallback_slot',
|
|
18
18
|
'provider.host_model',
|
|
19
|
+
'turn.media_refused_image',
|
|
20
|
+
'turn.media_refused_video',
|
|
21
|
+
'turn.media_refused_file',
|
|
19
22
|
'provider.turn_profile',
|
|
20
23
|
'provider.model_binding_missing',
|
|
21
24
|
'provider.session_closed',
|
|
@@ -339,6 +342,9 @@ const DEFAULTS = {
|
|
|
339
342
|
'provider.fallback_slot': 'Provider fallback slot must differ from its primary slot',
|
|
340
343
|
'provider.model_fallback_slot': 'Fallback credential slot must differ from primary',
|
|
341
344
|
'provider.host_model': 'Host profiles do not call models',
|
|
345
|
+
'turn.media_refused_image': '[The user sent a photo that could not be opened.]',
|
|
346
|
+
'turn.media_refused_video': '[The user sent a video that could not be opened.]',
|
|
347
|
+
'turn.media_refused_file': '[The user sent a file that could not be opened.]',
|
|
342
348
|
'provider.turn_profile': 'Profile does not run model turns',
|
|
343
349
|
'provider.model_binding_missing': 'Unknown model binding',
|
|
344
350
|
'provider.session_closed': 'Provider session closed unexpectedly',
|
|
@@ -576,6 +582,9 @@ export const LABEL_NOTES = {
|
|
|
576
582
|
'provider.fallback_slot': 'Provider validation diagnostic.',
|
|
577
583
|
'provider.model_fallback_slot': 'Provider validation diagnostic.',
|
|
578
584
|
'provider.host_model': 'Provider validation diagnostic.',
|
|
585
|
+
'turn.media_refused_image': 'Model-visible note where a refused photo was.',
|
|
586
|
+
'turn.media_refused_video': 'Model-visible note where a refused video was.',
|
|
587
|
+
'turn.media_refused_file': 'Model-visible note where a refused file was.',
|
|
579
588
|
'provider.turn_profile': 'Provider validation diagnostic.',
|
|
580
589
|
'provider.model_binding_missing': 'Provider validation diagnostic.',
|
|
581
590
|
'provider.session_closed': 'Provider validation diagnostic.',
|
|
@@ -48,7 +48,8 @@ export type { ScanText } from './serialize.js';
|
|
|
48
48
|
export { scanTextOf, textForScan } from './serialize.js';
|
|
49
49
|
export type { Directive, DirectiveSignal } from './tool-directives.js';
|
|
50
50
|
export { advisoryLevel, DIRECTIVE_SIGNALS, directives } from './tool-directives.js';
|
|
51
|
+
export { TOOL_CLOSE } from './tool-fence.js';
|
|
51
52
|
export type { GuardedToolText, InspectedToolArguments } from './tool-result.js';
|
|
52
|
-
export { checkTaintGate, composeToolText, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint,
|
|
53
|
+
export { checkTaintGate, composeToolText, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, toolCallEvent, wrapToolData, } from './tool-result.js';
|
|
53
54
|
export type { AdvisoryLevel, BlockedReplyOnBlock, BlockedReplySpec, DecisionDisclosureEnforcer, DecisionDisclosureVerdict, DecisionGuardrailsSpec, DestinationGate, GuardrailAction, GuardrailContext, GuardrailEvent, GuardrailHit, GuardrailStage, HostGuardrailsSpec, NetworkGuardrailSpec, OutboundPayload, ProfileGuardrailsSpec, Provenance, QuotaGuardrailSpec, ResolvedBlockedReply, ResolvedGuardrailPolicy, Severity, TaintGate, TaintGuardrailSpec, ToolOrigin, TrustLevel, TurnTaint, Verdict, } from './types.js';
|
|
54
55
|
export { ADVISORY_LEVELS, BLOCKED_REPLY_ON_BLOCK, DESTINATION_GATES, GUARDRAIL_STAGES, SEVERITIES, TAINT_GATES, TOOL_ORIGINS, TRUST_LEVELS, } from './types.js';
|
|
@@ -30,5 +30,6 @@ export { sensitiveSpans } from './sensitive.js';
|
|
|
30
30
|
export { SENSITIVE_GROUPS } from './sensitive-groups.js';
|
|
31
31
|
export { scanTextOf, textForScan } from './serialize.js';
|
|
32
32
|
export { advisoryLevel, DIRECTIVE_SIGNALS, directives } from './tool-directives.js';
|
|
33
|
-
export {
|
|
33
|
+
export { TOOL_CLOSE } from './tool-fence.js';
|
|
34
|
+
export { checkTaintGate, composeToolText, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, toolCallEvent, wrapToolData, } from './tool-result.js';
|
|
34
35
|
export { ADVISORY_LEVELS, BLOCKED_REPLY_ON_BLOCK, DESTINATION_GATES, GUARDRAIL_STAGES, SEVERITIES, TAINT_GATES, TOOL_ORIGINS, TRUST_LEVELS, } from './types.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TurnHistoryMessage } from '../kernel/turn-events.js';
|
|
2
|
+
import type { GuardrailHit, Provenance } from './types.js';
|
|
3
|
+
/** The closing tag of the fence a tool result is wrapped in. */
|
|
4
|
+
declare const TOOL_CLOSE = "</tool_data>";
|
|
5
|
+
/** What a fence from `wrapToolData` says of the text inside it. */
|
|
6
|
+
export interface ToolDataRead {
|
|
7
|
+
provenance: Provenance;
|
|
8
|
+
suspicious: GuardrailHit[];
|
|
9
|
+
/** The result as `composeToolText` joined it. */
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads each whole fence in a message. A sign-in note can stand before one, and a late-result
|
|
14
|
+
* message holds one for each result. `stripToolFences` has taken any forged tag out of a body, so
|
|
15
|
+
* what a tag says is the kernel's.
|
|
16
|
+
*/
|
|
17
|
+
declare function readToolData(content: string): ToolDataRead[];
|
|
18
|
+
/**
|
|
19
|
+
* Whether a role `user` message holds tool results that `input.lateResults` opened. It is no one's
|
|
20
|
+
* word to the model. A person who types a fence only makes their own reply stricter.
|
|
21
|
+
*/
|
|
22
|
+
declare function isLateResult(message: TurnHistoryMessage): boolean;
|
|
23
|
+
export { isLateResult, readToolData, TOOL_CLOSE };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DETECT_RULES } from './rules.js';
|
|
2
|
+
/** The closing tag of the fence a tool result is wrapped in. */
|
|
3
|
+
const TOOL_CLOSE = '</tool_data>';
|
|
4
|
+
const FENCE_OPEN = /^<tool_data tool="([^"]*)" origin="([^"]*)"( advisory="[^"]*")?>\n/gm;
|
|
5
|
+
/**
|
|
6
|
+
* Reads each whole fence in a message. A sign-in note can stand before one, and a late-result
|
|
7
|
+
* message holds one for each result. `stripToolFences` has taken any forged tag out of a body, so
|
|
8
|
+
* what a tag says is the kernel's.
|
|
9
|
+
*/
|
|
10
|
+
function readToolData(content) {
|
|
11
|
+
const reads = [];
|
|
12
|
+
for (const open of content.matchAll(FENCE_OPEN)) {
|
|
13
|
+
const [opening, tool = '', origin = '', advised] = open;
|
|
14
|
+
const start = open.index + opening.length;
|
|
15
|
+
const end = content.indexOf(`\n${TOOL_CLOSE}`, start);
|
|
16
|
+
if (end < 0)
|
|
17
|
+
continue;
|
|
18
|
+
const body = content.slice(start, end);
|
|
19
|
+
reads.push({
|
|
20
|
+
provenance: { origin: origin, tool, depth: origin === 'delegated' ? 2 : 1 },
|
|
21
|
+
suspicious: advised
|
|
22
|
+
? [{ rule: DETECT_RULES.tool_instructions, severity: 'high' }]
|
|
23
|
+
: [],
|
|
24
|
+
text: advised ? body.slice(body.indexOf('\n') + 1) : body,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return reads;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a role `user` message holds tool results that `input.lateResults` opened. It is no one's
|
|
31
|
+
* word to the model. A person who types a fence only makes their own reply stricter.
|
|
32
|
+
*/
|
|
33
|
+
function isLateResult(message) {
|
|
34
|
+
return (message.role === 'user' &&
|
|
35
|
+
message.content !== undefined &&
|
|
36
|
+
readToolData(message.content).length > 0);
|
|
37
|
+
}
|
|
38
|
+
export { isLateResult, readToolData, TOOL_CLOSE };
|
|
@@ -2,8 +2,6 @@ import type { ToolBoundary } from './boundaries.js';
|
|
|
2
2
|
import { type DetectScope } from './detect-at.js';
|
|
3
3
|
import { type LabelOverrides } from './labels.js';
|
|
4
4
|
import type { AdvisoryLevel, GuardrailEvent, GuardrailHit, Provenance, ResolvedGuardrailPolicy, ToolOrigin, TurnTaint, Verdict } from './types.js';
|
|
5
|
-
/** The closing tag of the fence a tool result is wrapped in. */
|
|
6
|
-
declare const TOOL_CLOSE = "</tool_data>";
|
|
7
5
|
/** True when the tool's bytes come from outside the host. */
|
|
8
6
|
declare function isRemoteOrigin(origin: ToolOrigin): boolean;
|
|
9
7
|
/**
|
|
@@ -11,18 +9,6 @@ declare function isRemoteOrigin(origin: ToolOrigin): boolean;
|
|
|
11
9
|
* friendlier provenance than it has by writing one into its own body.
|
|
12
10
|
*/
|
|
13
11
|
declare function wrapToolData(text: string, provenance: Provenance, advisory?: AdvisoryLevel, labels?: LabelOverrides): string;
|
|
14
|
-
/** What a fence from `wrapToolData` says of the text inside it. */
|
|
15
|
-
export interface ToolDataRead {
|
|
16
|
-
provenance: Provenance;
|
|
17
|
-
suspicious: GuardrailHit[];
|
|
18
|
-
/** The result as `composeToolText` joined it. */
|
|
19
|
-
text: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Reads the fence at the start of a tool message. `stripToolFences` has taken any forged tag out of
|
|
23
|
-
* the body, so what the tag says is the kernel's. `undefined` when `content` is not one whole fence.
|
|
24
|
-
*/
|
|
25
|
-
declare function readToolData(content: string): ToolDataRead | undefined;
|
|
26
12
|
/** A tool result after the guard: the text the model sees, any event, and the suspicious hits. */
|
|
27
13
|
export interface GuardedToolText {
|
|
28
14
|
/** Absent when a match blocks: the model does not read the text. */
|
|
@@ -101,4 +87,4 @@ declare function isSuspicious(taint: TurnTaint | undefined): boolean;
|
|
|
101
87
|
* or not enforcement is configured, so the risk is visible before a host opts in.
|
|
102
88
|
*/
|
|
103
89
|
declare function checkTaintGate(taint: TurnTaint | undefined, access: string, policy: ResolvedGuardrailPolicy, labels?: LabelOverrides): Verdict;
|
|
104
|
-
export { checkTaintGate, composeToolText, guardShownValue, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted,
|
|
90
|
+
export { checkTaintGate, composeToolText, guardShownValue, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, toolCallEvent, wrapToolData, };
|
|
@@ -5,8 +5,7 @@ import { labelText } from './labels.js';
|
|
|
5
5
|
import { DETECT_RULES, EGRESS_RULES, TOOL_RULES } from './rules.js';
|
|
6
6
|
import { textForScan } from './serialize.js';
|
|
7
7
|
import { advisoryLevel } from './tool-directives.js';
|
|
8
|
-
|
|
9
|
-
const TOOL_CLOSE = '</tool_data>';
|
|
8
|
+
import { TOOL_CLOSE } from './tool-fence.js';
|
|
10
9
|
const TOOL_OPEN = '<tool_data';
|
|
11
10
|
/** Origins whose bytes the host does not author and cannot vouch for. */
|
|
12
11
|
const REMOTE_ORIGINS = new Set(['http', 'mcp', 'delegated']);
|
|
@@ -66,25 +65,6 @@ function wrapToolData(text, provenance, advisory = 'none', labels) {
|
|
|
66
65
|
: `${advisoryNotice(advisory, labels)}${guidance ? ` ${guidance}` : ''}\n`;
|
|
67
66
|
return `<${'tool_data'} ${attrs}>\n${notice}${stripToolFences(text)}\n${TOOL_CLOSE}`;
|
|
68
67
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Reads the fence at the start of a tool message. `stripToolFences` has taken any forged tag out of
|
|
71
|
-
* the body, so what the tag says is the kernel's. `undefined` when `content` is not one whole fence.
|
|
72
|
-
*/
|
|
73
|
-
function readToolData(content) {
|
|
74
|
-
const open = /^<tool_data tool="([^"]*)" origin="([^"]*)"(?: advisory="[^"]*")?>\n/.exec(content);
|
|
75
|
-
if (!(open && content.endsWith(`\n${TOOL_CLOSE}`)))
|
|
76
|
-
return undefined;
|
|
77
|
-
const [opening, tool = '', origin = ''] = open;
|
|
78
|
-
const body = content.slice(opening.length, -TOOL_CLOSE.length - 1);
|
|
79
|
-
const advised = opening.includes(' advisory=');
|
|
80
|
-
return {
|
|
81
|
-
provenance: { origin: origin, tool, depth: origin === 'delegated' ? 2 : 1 },
|
|
82
|
-
suspicious: advised
|
|
83
|
-
? [{ rule: DETECT_RULES.tool_instructions, severity: 'high' }]
|
|
84
|
-
: [],
|
|
85
|
-
text: advised ? body.slice(body.indexOf('\n') + 1) : body,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
68
|
/**
|
|
89
69
|
* Deliberately an observation, not an instruction: what the agent should do about
|
|
90
70
|
* it is product behaviour, supplied by the host as labels `advisory.guidance`. Emitted
|
|
@@ -288,4 +268,4 @@ function checkTaintGate(taint, access, policy, labels) {
|
|
|
288
268
|
rejection: labelText('taint.blocked', { access, sources: read, reason }, labels),
|
|
289
269
|
};
|
|
290
270
|
}
|
|
291
|
-
export { checkTaintGate, composeToolText, guardShownValue, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted,
|
|
271
|
+
export { checkTaintGate, composeToolText, guardShownValue, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, toolCallEvent, wrapToolData, };
|
|
@@ -48,6 +48,13 @@ function stripGuardrailInternal(event) {
|
|
|
48
48
|
const { errorInternal: _internal, errorSummary: _summary, ...guardrail } = event.guardrail;
|
|
49
49
|
return { ...event, guardrail };
|
|
50
50
|
}
|
|
51
|
+
function stripMediaRefused(event) {
|
|
52
|
+
if (event.type !== 'done' || event.mediaRefused === undefined) {
|
|
53
|
+
return event;
|
|
54
|
+
}
|
|
55
|
+
const { mediaRefused: _refused, ...rest } = event;
|
|
56
|
+
return rest;
|
|
57
|
+
}
|
|
51
58
|
function stripEvidenceRaw(event) {
|
|
52
59
|
if (event.type !== 'evidence' || !event.evidence?.raw) {
|
|
53
60
|
return event;
|
|
@@ -62,7 +69,7 @@ function stripEvidenceRaw(event) {
|
|
|
62
69
|
function forClient(event, options) {
|
|
63
70
|
let out = options?.reader === 'builder'
|
|
64
71
|
? builderWording(event)
|
|
65
|
-
: stripCompactionInternal(stripGuardrailInternal(stripErrorInternal(event)));
|
|
72
|
+
: stripMediaRefused(stripCompactionInternal(stripGuardrailInternal(stripErrorInternal(event))));
|
|
66
73
|
if (!options?.includeEvidenceRaw) {
|
|
67
74
|
out = stripEvidenceRaw(out);
|
|
68
75
|
}
|
|
@@ -231,6 +231,8 @@ function standaloneBlock(event, idPrefix) {
|
|
|
231
231
|
return { id: nextBlockId(idPrefix), kind: 'grounding', grounding: event.grounding };
|
|
232
232
|
case 'evidence':
|
|
233
233
|
return { id: nextBlockId(idPrefix), kind: 'evidence', evidence: event.evidence };
|
|
234
|
+
case 'late_results':
|
|
235
|
+
return { id: nextBlockId(idPrefix), kind: 'late-results', text: event.text };
|
|
234
236
|
case 'error':
|
|
235
237
|
return event.error
|
|
236
238
|
? { id: nextBlockId(idPrefix), kind: 'error', message: event.error }
|
|
@@ -168,6 +168,12 @@ function foldAssistantEvents(history, events, gated) {
|
|
|
168
168
|
textBuf += event.text;
|
|
169
169
|
continue;
|
|
170
170
|
}
|
|
171
|
+
if (event.type === 'late_results') {
|
|
172
|
+
flushStep();
|
|
173
|
+
flushText();
|
|
174
|
+
next = [...next, { role: 'user', content: event.text }];
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
171
177
|
if (event.type === 'stage' && event.injected) {
|
|
172
178
|
// why: A steer is a message in the conversation, after what the reply said and did before it.
|
|
173
179
|
flushStep();
|
|
@@ -227,6 +233,10 @@ function historyFromTranscriptBlocks(blocks) {
|
|
|
227
233
|
history = [...history, { role: 'assistant', content: block.text }];
|
|
228
234
|
continue;
|
|
229
235
|
}
|
|
236
|
+
if (block.kind === 'late-results') {
|
|
237
|
+
history = [...history, { role: 'user', content: block.text }];
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
230
240
|
if (block.kind === 'structured') {
|
|
231
241
|
history = [...history, { role: 'assistant', content: JSON.stringify(block.value) }];
|
|
232
242
|
}
|
|
@@ -121,7 +121,7 @@ export type ProfileInterface = TextProfileInterface | ImageProfileInterface | Sp
|
|
|
121
121
|
/** Turn/chat composer profiles — excludes live (realtime streams, no turn inputs block). */
|
|
122
122
|
export type ComposerProfileInterface = Exclude<ProfileInterface, LiveProfileInterface>;
|
|
123
123
|
/** The kinds of block a transcript holds. */
|
|
124
|
-
export type TranscriptBlockKind = 'user-text' | 'user-attachment' | 'user-voice' | 'thought' | 'text' | 'tool' | 'structured' | 'media' | 'grounding' | 'citation' | 'evidence' | 'guardrail' | 'error' | 'turn-done';
|
|
124
|
+
export type TranscriptBlockKind = 'user-text' | 'user-attachment' | 'user-voice' | 'thought' | 'text' | 'tool' | 'structured' | 'media' | 'grounding' | 'citation' | 'evidence' | 'guardrail' | 'late-results' | 'error' | 'turn-done';
|
|
125
125
|
export interface TranscriptBlockBase {
|
|
126
126
|
id: string;
|
|
127
127
|
kind: TranscriptBlockKind;
|
|
@@ -234,6 +234,14 @@ export interface GuardrailBlock extends TranscriptBlockBase {
|
|
|
234
234
|
kind: 'guardrail';
|
|
235
235
|
guardrail: GuardrailEvent;
|
|
236
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* The message `input.lateResults` put in the conversation, as the model read it. Theorem's own
|
|
239
|
+
* transcript shows nothing for it: the block keeps it in a history rebuilt from blocks.
|
|
240
|
+
*/
|
|
241
|
+
export interface LateResultsBlock extends TranscriptBlockBase {
|
|
242
|
+
kind: 'late-results';
|
|
243
|
+
text: string;
|
|
244
|
+
}
|
|
237
245
|
export interface ErrorBlock extends TranscriptBlockBase {
|
|
238
246
|
kind: 'error';
|
|
239
247
|
message: string;
|
|
@@ -253,7 +261,7 @@ export interface TurnDoneBlock extends TranscriptBlockBase {
|
|
|
253
261
|
endedAt?: number;
|
|
254
262
|
}
|
|
255
263
|
/** One block of a transcript: a message, an attachment, a thought, a tool call, or a notice. */
|
|
256
|
-
export type TranscriptBlock = UserTextBlock | UserAttachmentBlock | ThoughtBlock | TextBlock | ToolBlock | StructuredBlock | MediaBlock | GroundingBlock | CitationBlock | EvidenceBlock | GuardrailBlock | ErrorBlock | TurnDoneBlock;
|
|
264
|
+
export type TranscriptBlock = UserTextBlock | UserAttachmentBlock | ThoughtBlock | TextBlock | ToolBlock | StructuredBlock | MediaBlock | GroundingBlock | CitationBlock | EvidenceBlock | GuardrailBlock | LateResultsBlock | ErrorBlock | TurnDoneBlock;
|
|
257
265
|
/** A file the user has picked but not yet sent. */
|
|
258
266
|
export interface PendingAttachment {
|
|
259
267
|
name: string;
|
|
@@ -35,7 +35,7 @@ export const REQUEST_FIELDS = {
|
|
|
35
35
|
},
|
|
36
36
|
'runTurn.input.lateResults': {
|
|
37
37
|
type: 'ToolOperationOutcome[]',
|
|
38
|
-
doc: 'Background tool calls that settled after their turn, as the host stored them. The model reads each as a tool result, and this reply counts it as a remote read when the call was remote. Pass
|
|
38
|
+
doc: 'Background tool calls that settled after their turn, as the host stored them. The model reads each as a tool result, and this reply counts it as a remote read when the call was remote. Pass each one once: the turn emits it as a late_results event, so a history built from events holds it.',
|
|
39
39
|
unset: 'No late results',
|
|
40
40
|
},
|
|
41
41
|
'runTurn.input.attachments': {
|
|
@@ -243,12 +243,17 @@ async function* emitTurn(args) {
|
|
|
243
243
|
tools: args.registry.tools,
|
|
244
244
|
profile,
|
|
245
245
|
generation,
|
|
246
|
-
|
|
246
|
+
request: safe,
|
|
247
247
|
trace: args.trace,
|
|
248
248
|
...(args.agents ? { agents: args.agents } : {}),
|
|
249
249
|
...(args.background ? { background: args.background } : {}),
|
|
250
250
|
});
|
|
251
251
|
args.outState.state = state;
|
|
252
|
+
if (state.lateResults !== undefined) {
|
|
253
|
+
const late = { type: 'late_results', text: state.lateResults };
|
|
254
|
+
state.allEmittedEvents.push(late);
|
|
255
|
+
yield late;
|
|
256
|
+
}
|
|
252
257
|
const pre = yield* applyTurnStage({
|
|
253
258
|
profile,
|
|
254
259
|
generation,
|
|
@@ -285,6 +290,7 @@ async function* emitTurn(args) {
|
|
|
285
290
|
const done = turnDoneOf({
|
|
286
291
|
stop: state.lastStop ?? { kind: 'completed' },
|
|
287
292
|
steps: state.stepCount,
|
|
293
|
+
...(state.mediaRefused ? { mediaRefused: state.mediaRefused } : {}),
|
|
288
294
|
...(state.providerState &&
|
|
289
295
|
!cutConversation(state) &&
|
|
290
296
|
!('providerContinuation' in profile && profile.providerContinuation?.history === 'stateless') &&
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MediaRefused, RefusedMedia } from '../../turn-events.js';
|
|
2
|
+
import type { Profile, TurnHistoryMessage } from '../../types.js';
|
|
3
|
+
import type { StepExecutionState } from './state.js';
|
|
4
|
+
/** The files a retry took out, and how to put them back if the retry fails too. */
|
|
5
|
+
export interface RefusedMediaTry {
|
|
6
|
+
dropped: RefusedMedia[];
|
|
7
|
+
said: string;
|
|
8
|
+
originals: Map<number, TurnHistoryMessage>;
|
|
9
|
+
}
|
|
10
|
+
/** Whether the next call has a file to go without. */
|
|
11
|
+
export declare function canDropMedia(state: StepExecutionState): boolean;
|
|
12
|
+
/** Puts a note where each file was, so the model knows what it could not read. */
|
|
13
|
+
export declare function dropMedia(state: StepExecutionState, said: string, labels: Profile['labels']): RefusedMediaTry;
|
|
14
|
+
/** The retry failed as well, so no file is proven at fault. */
|
|
15
|
+
export declare function restoreMedia(state: StepExecutionState, tried: RefusedMediaTry): void;
|
|
16
|
+
/** What the host reads on `done`. */
|
|
17
|
+
export declare function refusedReport(tried: RefusedMediaTry): MediaRefused;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { labelText } from '../../../guardrails/labels.js';
|
|
2
|
+
function isMedia(part) {
|
|
3
|
+
return part.type !== 'text';
|
|
4
|
+
}
|
|
5
|
+
function holdsMedia(message) {
|
|
6
|
+
return message.parts?.some(isMedia) === true;
|
|
7
|
+
}
|
|
8
|
+
function noteKey(mimeType) {
|
|
9
|
+
if (mimeType.startsWith('image/'))
|
|
10
|
+
return 'turn.media_refused_image';
|
|
11
|
+
if (mimeType.startsWith('video/'))
|
|
12
|
+
return 'turn.media_refused_video';
|
|
13
|
+
return 'turn.media_refused_file';
|
|
14
|
+
}
|
|
15
|
+
/** The messages a refused call could do without: this turn's files, or else the conversation's. */
|
|
16
|
+
function refusedAt(state) {
|
|
17
|
+
const held = state.currentHistory.flatMap((message, at) => (holdsMedia(message) ? [at] : []));
|
|
18
|
+
const thisTurn = held.filter((at) => at >= state.turnStart);
|
|
19
|
+
return thisTurn.length > 0 ? thisTurn : held;
|
|
20
|
+
}
|
|
21
|
+
/** Whether the next call has a file to go without. */
|
|
22
|
+
export function canDropMedia(state) {
|
|
23
|
+
return state.currentHistory.some(holdsMedia);
|
|
24
|
+
}
|
|
25
|
+
/** Puts a note where each file was, so the model knows what it could not read. */
|
|
26
|
+
export function dropMedia(state, said, labels) {
|
|
27
|
+
const tried = { dropped: [], said, originals: new Map() };
|
|
28
|
+
for (const at of refusedAt(state)) {
|
|
29
|
+
const message = state.currentHistory[at];
|
|
30
|
+
if (!message?.parts)
|
|
31
|
+
continue;
|
|
32
|
+
const from = at < state.turnStart ? 'history' : message.role === 'tool' ? 'tool' : 'input';
|
|
33
|
+
tried.originals.set(at, message);
|
|
34
|
+
state.currentHistory[at] = {
|
|
35
|
+
...message,
|
|
36
|
+
parts: message.parts.map((part) => {
|
|
37
|
+
if (part.type === 'text')
|
|
38
|
+
return part;
|
|
39
|
+
tried.dropped.push({ mimeType: part.mimeType, from });
|
|
40
|
+
return { type: 'text', text: labelText(noteKey(part.mimeType), {}, labels) };
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return tried;
|
|
45
|
+
}
|
|
46
|
+
/** The retry failed as well, so no file is proven at fault. */
|
|
47
|
+
export function restoreMedia(state, tried) {
|
|
48
|
+
for (const [at, message] of tried.originals)
|
|
49
|
+
state.currentHistory[at] = message;
|
|
50
|
+
}
|
|
51
|
+
/** What the host reads on `done`. */
|
|
52
|
+
export function refusedReport(tried) {
|
|
53
|
+
return { dropped: tried.dropped, said: tried.said };
|
|
54
|
+
}
|
|
@@ -6,7 +6,8 @@ import type { SpanHandle } from '../../../observability/trace-span.js';
|
|
|
6
6
|
import type { AgentCaller } from '../../tools/agent.js';
|
|
7
7
|
import type { ToolBackgroundSupport } from '../../tools/background.js';
|
|
8
8
|
import type { ToolRegistry } from '../../tools/registry.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { MediaRefused } from '../../turn-events.js';
|
|
10
|
+
import type { InteractionPart, ModelBinding, Profile, ResolvedGeneration, TurnEvent, TurnHistoryMessage, TurnRequest, TurnStop, TurnToolResult } from '../../types.js';
|
|
10
11
|
import type { ItemFailure } from './schema-validation.js';
|
|
11
12
|
import type { CallUsage } from './usage.js';
|
|
12
13
|
interface TurnTraceState {
|
|
@@ -33,6 +34,9 @@ interface StepExecutionState {
|
|
|
33
34
|
stepCount: number;
|
|
34
35
|
/** Model calls sent again this turn under the profile's resumption (`executeResumedStep`). */
|
|
35
36
|
resumes: number;
|
|
37
|
+
/** A refused call was sent without its files this turn; a turn tries that once. */
|
|
38
|
+
triedWithoutMedia?: boolean;
|
|
39
|
+
mediaRefused?: MediaRefused;
|
|
36
40
|
allEmittedEvents: TurnEvent[];
|
|
37
41
|
attemptEvents: TurnEvent[];
|
|
38
42
|
/**
|
|
@@ -55,6 +59,8 @@ interface StepExecutionState {
|
|
|
55
59
|
message: TurnHistoryMessage;
|
|
56
60
|
at: number;
|
|
57
61
|
}[];
|
|
62
|
+
/** The message `input.lateResults` opened, until the run can emit it. */
|
|
63
|
+
lateResults?: string;
|
|
58
64
|
/** The canary opening the last provider call ended on, read in front of the next call's reply. */
|
|
59
65
|
canaryCarry?: string;
|
|
60
66
|
/** What the last provider call's thoughts ended on, read in front of the next call's thoughts. */
|
|
@@ -109,8 +115,8 @@ declare function openTurnState(args: {
|
|
|
109
115
|
tools: ToolRegistry;
|
|
110
116
|
profile: Profile;
|
|
111
117
|
generation: ResolvedGeneration;
|
|
112
|
-
/** The request
|
|
113
|
-
|
|
118
|
+
/** The request, on the run that opens the turn. */
|
|
119
|
+
request?: TurnRequest;
|
|
114
120
|
trace: TurnTraceState;
|
|
115
121
|
allEmittedEvents?: TurnEvent[];
|
|
116
122
|
agents?: AgentCaller;
|