@theoremjs/agents 0.3.4-next.735.g8d504c6 → 0.3.4-next.753.g176c472
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/labels.d.ts +1 -1
- package/esm/src/guardrails/labels.js +9 -0
- 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 +6 -0
- 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 +6 -0
- package/esm/src/kernel/engine/runner/state.js +14 -4
- 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/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;
|
|
@@ -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,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': {
|
|
@@ -249,6 +249,11 @@ async function* emitTurn(args) {
|
|
|
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,6 +6,7 @@ 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 { MediaRefused } from '../../turn-events.js';
|
|
9
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';
|
|
@@ -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. */
|
|
@@ -4,6 +4,7 @@ import { labelText } from '../../../guardrails/labels.js';
|
|
|
4
4
|
import { isLateResult, readToolData } from '../../../guardrails/tool-fence.js';
|
|
5
5
|
import { isRemoteOrigin, recordTaint, wrapToolData } from '../../../guardrails/tool-result.js';
|
|
6
6
|
import { originOfTool } from '../../tools/execute.js';
|
|
7
|
+
import { isFramedToolFailure } from '../../tools/model-text.js';
|
|
7
8
|
import { ownToolsOf } from '../../tools/project.js';
|
|
8
9
|
function recordStepEvent(event, state) {
|
|
9
10
|
state.allEmittedEvents.push(event);
|
|
@@ -49,7 +50,8 @@ function carryReplyReads(state, history) {
|
|
|
49
50
|
state.taint = recordTaint(state.taint, read.provenance, read.suspicious);
|
|
50
51
|
addFencedDestinations(state.destinations, read.text, read.provenance);
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
// why: A refusal names the address it refused, so its words give nothing.
|
|
54
|
+
if (reads.length > 0 || isFramedToolFailure(message.content))
|
|
53
55
|
continue;
|
|
54
56
|
const tool = message.name ? state.tools.get(message.name) : undefined;
|
|
55
57
|
if (tool && !isRemoteOrigin(originOfTool(tool, state.tools))) {
|
|
@@ -57,7 +59,10 @@ function carryReplyReads(state, history) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* A late result is read as a tool's result, so its message is no one's word to the model.
|
|
64
|
+
* invariant: A history holds a late result once, however often the host passes it. Its marks count on each run.
|
|
65
|
+
*/
|
|
61
66
|
function openLateResults(state, outcomes, labels) {
|
|
62
67
|
if (outcomes.length === 0)
|
|
63
68
|
return;
|
|
@@ -73,9 +78,14 @@ function openLateResults(state, outcomes, labels) {
|
|
|
73
78
|
const fenced = readToolData(readBack).length > 0 ? readBack : wrapToolData(readBack, provenance);
|
|
74
79
|
return `${labelText('tool.late_result', { tool: name }, labels)}\n${fenced}`;
|
|
75
80
|
});
|
|
76
|
-
const
|
|
81
|
+
const unread = blocks.filter((block) => !state.currentHistory.some((message) => isLateResult(message) && message.content?.includes(block)));
|
|
82
|
+
if (unread.length === 0)
|
|
83
|
+
return;
|
|
84
|
+
const text = unread.join('\n\n');
|
|
85
|
+
const message = { role: 'user', content: text };
|
|
77
86
|
state.givenUrls.own.add(message);
|
|
78
87
|
state.currentHistory.push(message);
|
|
88
|
+
state.lateResults = text;
|
|
79
89
|
}
|
|
80
90
|
/**
|
|
81
91
|
* Step state for one turn. A text turn's history grows inside the turn (tool
|
|
@@ -112,9 +122,9 @@ function openTurnState(args) {
|
|
|
112
122
|
if (args.request && continuesReply(args.request)) {
|
|
113
123
|
carryReplyReads(state, args.request.input?.history ?? []);
|
|
114
124
|
}
|
|
115
|
-
openLateResults(state, args.request?.input?.lateResults ?? [], profile.labels);
|
|
116
125
|
appendUserInput(state, generation.input);
|
|
117
126
|
generation.input = [];
|
|
127
|
+
openLateResults(state, args.request?.input?.lateResults ?? [], profile.labels);
|
|
118
128
|
}
|
|
119
129
|
return state;
|
|
120
130
|
}
|
|
@@ -20,6 +20,7 @@ import { profileToolsParallel } from '../../tools/resolve.js';
|
|
|
20
20
|
import { findLast } from '../../util/find-last.js';
|
|
21
21
|
import { startToolTrace } from '../tool-trace.js';
|
|
22
22
|
import { startCallTrace } from '../turn-trace.js';
|
|
23
|
+
import { canDropMedia, dropMedia, refusedReport, restoreMedia, } from './refused-media.js';
|
|
23
24
|
import { applyStageInjects, recordReply } from './stages.js';
|
|
24
25
|
import { modelHistory, recordStepEvent } from './state.js';
|
|
25
26
|
import { inStep, runSideBySide, stepOrder } from './step-order.js';
|
|
@@ -220,6 +221,24 @@ function resumeOf(mayResume, profile, tally) {
|
|
|
220
221
|
return undefined;
|
|
221
222
|
return { stop, failure };
|
|
222
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* The re-send a refused call is due when it carried files.
|
|
226
|
+
*
|
|
227
|
+
* why: One file the provider cannot read refuses every call that replays it. Sent without
|
|
228
|
+
* the files, the call shows whether they were at fault; what it cost was one refused call.
|
|
229
|
+
*/
|
|
230
|
+
function mediaResumeOf(state, profile, tally) {
|
|
231
|
+
const { stop } = tally;
|
|
232
|
+
if (profile.type !== 'text' || state.triedWithoutMedia)
|
|
233
|
+
return undefined;
|
|
234
|
+
if (tally.replied || tally.calls.length > 0 || !stop || !isFailedStopKind(stop.kind)) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
const failure = tally.failures[0];
|
|
238
|
+
if (failure?.errorKind !== 'unsupported' || !resendsFailedCall(profile, stop))
|
|
239
|
+
return undefined;
|
|
240
|
+
return canDropMedia(state) ? { stop, failure, dropMedia: true } : undefined;
|
|
241
|
+
}
|
|
223
242
|
/** Carries what the call's stream guards still hold into the turn's next call. */
|
|
224
243
|
function keepStreamCarry(state, control) {
|
|
225
244
|
state.canaryCarry = control.canaryCarry;
|
|
@@ -293,7 +312,7 @@ async function* executeAutonomousStep(args, state, buffer = {
|
|
|
293
312
|
yield* shown.end();
|
|
294
313
|
yield* showAnswer(shown, tally, { generation, state, control, buffer, call });
|
|
295
314
|
keepStreamCarry(state, control);
|
|
296
|
-
const resume = resumeOf(args.mayResume, profile, tally);
|
|
315
|
+
const resume = resumeOf(args.mayResume, profile, tally) ?? mediaResumeOf(state, profile, tally);
|
|
297
316
|
if (!resume) {
|
|
298
317
|
for (const failure of tally.failures) {
|
|
299
318
|
recordStepEvent(failure, state);
|
|
@@ -322,14 +341,36 @@ async function* executeAutonomousStep(args, state, buffer = {
|
|
|
322
341
|
* lists, having given no reply and no tool call, is sent again in the same turn
|
|
323
342
|
* after a pause, up to `maxContinues` times a turn (once when the profile sets
|
|
324
343
|
* none). The turn's history, its step count, and what it has read stay as they were.
|
|
344
|
+
* A call the provider refused while it carried files goes once more without them, and
|
|
345
|
+
* those files are reported as refused only if that call is accepted.
|
|
325
346
|
*/
|
|
326
347
|
async function* executeResumedStep(args, state, buffer) {
|
|
327
348
|
const limit = profileTurnResumption(args.profile)?.maxContinues ?? 1;
|
|
349
|
+
let tried;
|
|
328
350
|
for (;;) {
|
|
329
351
|
const mayResume = args.profile.type === 'text' && state.resumes < limit;
|
|
330
352
|
const outcome = yield* executeAutonomousStep({ ...args, mayResume }, state, buffer);
|
|
331
|
-
if (!outcome.resume)
|
|
353
|
+
if (!outcome.resume) {
|
|
354
|
+
if (tried && state.lastStop && isFailedStopKind(state.lastStop.kind)) {
|
|
355
|
+
restoreMedia(state, tried);
|
|
356
|
+
}
|
|
357
|
+
else if (tried) {
|
|
358
|
+
state.mediaRefused = refusedReport(tried);
|
|
359
|
+
}
|
|
332
360
|
return outcome;
|
|
361
|
+
}
|
|
362
|
+
if (outcome.resume.dropMedia) {
|
|
363
|
+
const said = outcome.resume.failure?.errorInternal ?? outcome.resume.failure?.error ?? '';
|
|
364
|
+
state.triedWithoutMedia = true;
|
|
365
|
+
tried = dropMedia(state, said, args.profile.labels);
|
|
366
|
+
state.trace.root.event('theorem.step.media_refused', {
|
|
367
|
+
step: state.stepCount,
|
|
368
|
+
files: tried.dropped.length,
|
|
369
|
+
error: said,
|
|
370
|
+
});
|
|
371
|
+
state.lastStop = undefined;
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
333
374
|
state.resumes += 1;
|
|
334
375
|
const detail = outcome.resume.failure?.errorInternal ?? outcome.resume.failure?.error;
|
|
335
376
|
state.trace.root.event('theorem.step.resume', {
|
package/esm/src/kernel/mod.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export { type AnsweredGate, answerGatedCall, GATE_DECISIONS, type GateAnswerRequ
|
|
|
68
68
|
export type { MemoryToolExecutionOptions } from './tools/memory-execution.js';
|
|
69
69
|
export { createMemoryToolExecution } from './tools/memory-execution.js';
|
|
70
70
|
export type { CredentialQuery, McpProtocolVersion, McpRpcResponse, ToolRegistry, } from './tools/mod.js';
|
|
71
|
-
export { askUserTool, authorizeToolReplay, coerceToolResultParts, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, executeRegisteredTool, formatToolResult, isUnsupportedMcpProtocolError, leanToolResultData, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, projectForModel, registerHarnessTools, resolveToolAuth, withCredentialQuery, } from './tools/mod.js';
|
|
71
|
+
export { askUserTool, assertToolSettings, authorizeToolReplay, coerceToolResultParts, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, executeRegisteredTool, formatToolResult, isUnsupportedMcpProtocolError, leanToolResultData, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, projectForModel, registerHarnessTools, resolveToolAuth, withCredentialQuery, } from './tools/mod.js';
|
|
72
72
|
export type { BackgroundToolEvent, BeginToolOperationResult, PageToolDispatch, PageToolExecution, SavedToolInvocation, TerminalToolEvent, ToolExecutionCoordinator, ToolOperationClaim, ToolOperationIdentity, ToolOperationOutcome, ToolOperationReply, ToolOperationUncertainty, } from './tools/operation.js';
|
|
73
73
|
export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './tools/operation.js';
|
|
74
74
|
export { jsonSchemaFromZod } from './tools/schema.js';
|
package/esm/src/kernel/mod.js
CHANGED
|
@@ -41,7 +41,7 @@ export { activityLabelProblem } from './tools/activity-label.js';
|
|
|
41
41
|
export { agentToolInputFor, agentToolOutput } from './tools/agent.js';
|
|
42
42
|
export { answerGatedCall, GATE_DECISIONS, gateExpired, resolveGateTtlMs, sessionPermissionsAfterApproval, } from './tools/gate-answer.js';
|
|
43
43
|
export { createMemoryToolExecution } from './tools/memory-execution.js';
|
|
44
|
-
export { askUserTool, authorizeToolReplay, coerceToolResultParts, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, executeRegisteredTool, formatToolResult, isUnsupportedMcpProtocolError, leanToolResultData, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, projectForModel, registerHarnessTools, resolveToolAuth, withCredentialQuery, } from './tools/mod.js';
|
|
44
|
+
export { askUserTool, assertToolSettings, authorizeToolReplay, coerceToolResultParts, createToolRegistry, credentialPlacement, executeHttpTool, executeMcpTool, executeRegisteredTool, formatToolResult, isUnsupportedMcpProtocolError, leanToolResultData, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, prepareTurnToolSnapshot, projectForModel, registerHarnessTools, resolveToolAuth, withCredentialQuery, } from './tools/mod.js';
|
|
45
45
|
export { savedToolInvocationSchema, toolInvocationHash, toolOperationOutcomeSchema, toolOperationReplySchema, } from './tools/operation.js';
|
|
46
46
|
export { jsonSchemaFromZod } from './tools/schema.js';
|
|
47
47
|
export { CredentialRefusedError } from './tools/signed-in-fetch.js';
|
|
@@ -31,6 +31,8 @@ export interface OutOfScopeField {
|
|
|
31
31
|
path: string;
|
|
32
32
|
scope: ProfileFieldScope;
|
|
33
33
|
}
|
|
34
|
+
/** Every set value under `segments`, keyed by concrete path; `*` walks each key of a map. */
|
|
35
|
+
export declare function valuesAt(root: unknown, segments: readonly string[], at?: string): [string, unknown][];
|
|
34
36
|
/**
|
|
35
37
|
* Every field `profile` sets that its type may not, ancestors before their
|
|
36
38
|
* children. A scope's off value is not reported.
|
|
@@ -247,7 +247,7 @@ export function profileTypesForField(path) {
|
|
|
247
247
|
return profileFieldScope(path)?.profileTypes ?? ALL_PROFILE_TYPES;
|
|
248
248
|
}
|
|
249
249
|
/** Every set value under `segments`, keyed by concrete path; `*` walks each key of a map. */
|
|
250
|
-
function valuesAt(root, segments, at = '') {
|
|
250
|
+
export function valuesAt(root, segments, at = '') {
|
|
251
251
|
if (!segments.length)
|
|
252
252
|
return root === undefined ? [] : [[at, root]];
|
|
253
253
|
if (root === null || typeof root !== 'object')
|
|
@@ -57,7 +57,7 @@ const modelBinding = z.strictObject({
|
|
|
57
57
|
fallbackKeySlot: keySlotSchema
|
|
58
58
|
.optional()
|
|
59
59
|
// labels-exempt: builder field description, read by the studio and docs
|
|
60
|
-
.describe('The slot tried once when the first key is out of quota.'),
|
|
60
|
+
.describe('The slot tried once when the first key is out of quota, rate limited or busy.'),
|
|
61
61
|
options: jsonObjectSchema
|
|
62
62
|
.optional()
|
|
63
63
|
// labels-exempt: builder field description, read by the studio and docs
|
|
@@ -9,7 +9,7 @@ import { assertLiveIngressConfigured } from '../engine/live-ingress.js';
|
|
|
9
9
|
import { itemSchemaAt, schemaReaches } from '../engine/runner/schema-validation.js';
|
|
10
10
|
import { outOfScopeFields, profileKeysOf, profileTypesForField } from '../profile-scope.js';
|
|
11
11
|
import { checkBinding, decisionModelBindingSchema, modelBindingSchema, } from '../protocols/binding.js';
|
|
12
|
-
import { CONTEXT_SENDERS, IMAGE_ATTACHMENT_ACCEPT_MIMES, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, THINKING_LEVELS, } from '../schema.js';
|
|
12
|
+
import { CONTEXT_SENDERS, IMAGE_ATTACHMENT_ACCEPT_MIMES, PROFILE_FIELDS, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, PROFILE_TYPES, profileFieldProblems, THINKING_LEVELS, } from '../schema.js';
|
|
13
13
|
import { isContinueStopKind } from '../stop.js';
|
|
14
14
|
import { assertSystemLines, systemLinesProblem } from '../system-lines.js';
|
|
15
15
|
import { profileToolAllow, profileToolsSpec } from '../tools/resolve.js';
|
|
@@ -378,6 +378,14 @@ function assertIdentitySystem(input) {
|
|
|
378
378
|
}
|
|
379
379
|
/** Validate any definition and return the profile. */
|
|
380
380
|
function defineProfile(input) {
|
|
381
|
+
const profile = validatedProfile(input);
|
|
382
|
+
const [problem] = profileFieldProblems(input);
|
|
383
|
+
if (problem) {
|
|
384
|
+
throw new TheoremError('config', `Profile ${input.id}: ${problem.path} ${problem.message}`); // labels-exempt: developer contract / internal diagnostic
|
|
385
|
+
}
|
|
386
|
+
return profile;
|
|
387
|
+
}
|
|
388
|
+
function validatedProfile(input) {
|
|
381
389
|
assertProfileShape(input);
|
|
382
390
|
for (const field of ['key', 'fallbackKey', 'protocol', 'provider'])
|
|
383
391
|
if (field in input)
|
|
@@ -615,9 +623,6 @@ function assertCompactionSpec(registered, owner, modelId, spec) {
|
|
|
615
623
|
const tag = `Profile ${owner.id} model ${modelId} compaction`; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
616
624
|
assertCompactionBudget(tag, spec);
|
|
617
625
|
assertCompactionRetain(tag, spec);
|
|
618
|
-
if (spec.meter != null && spec.meter !== 'history' && spec.meter !== 'input') {
|
|
619
|
-
throw new TheoremError('config', `${tag}: meter must be 'history' or 'input'`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
620
|
-
}
|
|
621
626
|
if (spec.profile === undefined) {
|
|
622
627
|
if (owner.type !== 'text' || owner.inputs.text === false) {
|
|
623
628
|
throw new TheoremError('config', `${tag}: a profile that compacts itself must be a text profile that takes text`);
|
|
@@ -221,6 +221,15 @@ export declare const PROFILE_FIELDS: Record<string, FieldMeta>;
|
|
|
221
221
|
export declare const EXTRA_FIELDS: Record<string, FieldMeta>;
|
|
222
222
|
/** `labels.<key>` resolves to `labels.*` with that key's own note. */
|
|
223
223
|
export declare function fieldMeta(path: string): FieldMeta | undefined;
|
|
224
|
+
/** A setting the catalog cannot hold: where it is written, and why. */
|
|
225
|
+
export interface FieldProblem {
|
|
226
|
+
path: string;
|
|
227
|
+
message: string;
|
|
228
|
+
}
|
|
229
|
+
/** Every setting in a profile definition that the catalog cannot hold. Nothing here needs a complete profile. */
|
|
230
|
+
export declare function profileFieldProblems(profile: unknown): FieldProblem[];
|
|
231
|
+
/** Every setting in a tool definition that the catalog cannot hold. Nothing here needs a complete tool. */
|
|
232
|
+
export declare function toolFieldProblems(tool: unknown): FieldProblem[];
|
|
224
233
|
export { API_EXPORTS, type ApiExportMeta, REQUEST_FIELDS } from './api-catalog.js';
|
|
225
234
|
export type { ProfileGraphEditor, ProfileGraphFacet, ProfileGraphFacetId, ProfileGraphRole, } from './profile-graph.js';
|
|
226
235
|
export { PROFILE_GRAPH, profileGraphFacet, spineFacetsForProfileType } from './profile-graph.js';
|
package/esm/src/kernel/schema.js
CHANGED
|
@@ -10,7 +10,7 @@ import { DETECT_ACTION_META, DETECT_ACTIONS, DETECT_DEFAULTS, DETECTOR_BOUNDARIE
|
|
|
10
10
|
import { LABEL_NOTES } from '../guardrails/labels.js';
|
|
11
11
|
import { BLOCKED_REPLY_ON_BLOCK, DESTINATION_GATES, TAINT_GATES, } from '../guardrails/types.js';
|
|
12
12
|
import { PROFILE_FIELD_PRESENCE } from './profile-presence.js';
|
|
13
|
-
import { isProfileRootField, profileFieldScope } from './profile-scope.js';
|
|
13
|
+
import { isProfileRootField, profileFieldScope, profileKeysOf, valuesAt } from './profile-scope.js';
|
|
14
14
|
export { BLOCKED_REPLY_ON_BLOCK };
|
|
15
15
|
/** The kinds of profile: each fixes which fields and models a profile may use. */
|
|
16
16
|
export const PROFILE_TYPES = [
|
|
@@ -860,6 +860,7 @@ export const EXTRA_FIELDS = {
|
|
|
860
860
|
}),
|
|
861
861
|
unset: 'gate',
|
|
862
862
|
},
|
|
863
|
+
'registerTool.auth.preResolved': field('Partial<OAuthEndpoints & { resource: string }>', "Named on the auth gate for the host's OAuth flow, so it need not find them."),
|
|
863
864
|
'registerTool.auth.scopes': field('string[]', 'The OAuth scopes the tool needs, shown when a turn stops to ask for a credential. A service asking for any other scope fails the call, with no new sign-in.'),
|
|
864
865
|
'registerTool.auth.clientId': field('string', "Your OAuth client id, kept for the host's sign-in flow; the kernel doesn't read it."),
|
|
865
866
|
'registerTool.auth.redirectUri': field('string', "Your OAuth redirect URI, kept for the host's sign-in flow; the kernel doesn't read it."),
|
|
@@ -887,6 +888,27 @@ export const EXTRA_FIELDS = {
|
|
|
887
888
|
session_consent: 'Asks once; the approval lasts as long as the host keeps passing it back.',
|
|
888
889
|
always_confirm: 'Asks every time.',
|
|
889
890
|
}),
|
|
891
|
+
'registerTool.preTool': field('(input, ctx) => StageResult | undefined', "Runs before the host's pre_tool onStage."),
|
|
892
|
+
'registerTool.exposeToModel': {
|
|
893
|
+
...field('boolean', 'Whether the model can see and call the tool.'),
|
|
894
|
+
unset: 'The model can',
|
|
895
|
+
},
|
|
896
|
+
'registerTool.sources': field('(output) => Source[]', 'The sources a result cites. One that fails sourceSchema, or a throw, is a sources_invalid warning and is not cited.'),
|
|
897
|
+
'registerTool.images': field('(output) => string[]', '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.'),
|
|
898
|
+
'registerTool.imageLimits': {
|
|
899
|
+
...field('ToolImageLimits', 'How many of those pictures the kernel fetches, how large, and how slowly.'),
|
|
900
|
+
unset: 'No limit',
|
|
901
|
+
},
|
|
902
|
+
'registerTool.askInputSchema': field('Record<string, unknown>', '`inputSchema` with the `background` argument. The registry sets it on an `ask` tool.'),
|
|
903
|
+
'registerTool.conflictsWith': field('string[]', 'The built-in tools a builtin tool cannot run beside.'),
|
|
904
|
+
'registerTool.limit': {
|
|
905
|
+
...field('HttpToolLimit', "The service's own limit for one key; the kernel keeps this tool's requests within it."),
|
|
906
|
+
unset: 'No limit',
|
|
907
|
+
},
|
|
908
|
+
'registerTool.timeoutMs': {
|
|
909
|
+
...field('number', 'How long the service may take to answer, its body read included. Past it the call fails timeout and frees its place in the limit.'),
|
|
910
|
+
unset: "As long as the caller's signal lets it",
|
|
911
|
+
},
|
|
890
912
|
'registerTool.after': {
|
|
891
913
|
...field('boolean', 'Gives the model an after field on this tool: the tools called in the same step that must settle before this call starts. The kernel removes the field before the tool, the stages or a gate read the input. A name with no other call in the step fails the call wait_unknown.'),
|
|
892
914
|
unset: 'The model sets no order',
|
|
@@ -937,5 +959,89 @@ export function fieldMeta(path) {
|
|
|
937
959
|
return undefined;
|
|
938
960
|
return { ...wildcard, doc: LABEL_NOTES[key] };
|
|
939
961
|
}
|
|
962
|
+
const isText = (value) => typeof value === 'string';
|
|
963
|
+
const isTextList = (value) => Array.isArray(value) && value.every(isText);
|
|
964
|
+
const PLAIN_KINDS = {
|
|
965
|
+
string: isText,
|
|
966
|
+
ModelId: isText,
|
|
967
|
+
ProfileId: isText,
|
|
968
|
+
ToolId: isText,
|
|
969
|
+
KeySlot: isText,
|
|
970
|
+
number: (value) => typeof value === 'number',
|
|
971
|
+
boolean: (value) => typeof value === 'boolean',
|
|
972
|
+
'string[]': isTextList,
|
|
973
|
+
'ToolId[]': isTextList,
|
|
974
|
+
'BuiltinToolId[]': isTextList,
|
|
975
|
+
};
|
|
976
|
+
/** Why `value` cannot be `meta`'s field. A range or a shape stays with the check that owns it. */
|
|
977
|
+
function valueProblem(meta, value) {
|
|
978
|
+
const { options, type } = meta;
|
|
979
|
+
if (value === null)
|
|
980
|
+
return undefined;
|
|
981
|
+
if (options && (typeof value === 'string' || /^'[^{]*$/.test(type))) {
|
|
982
|
+
if (options.includes(value))
|
|
983
|
+
return undefined;
|
|
984
|
+
return `${JSON.stringify(value)} is not one of ${options.map((option) => `'${option}'`).join(', ')}.`;
|
|
985
|
+
}
|
|
986
|
+
const isKind = PLAIN_KINDS[type];
|
|
987
|
+
return !isKind || isKind(value) ? undefined : `has to be a ${type}.`;
|
|
988
|
+
}
|
|
989
|
+
/** Each object path of the catalog, with the keys it takes. */
|
|
990
|
+
function keysByParent(fields) {
|
|
991
|
+
const children = new Map([['', new Set()]]);
|
|
992
|
+
for (const path of Object.keys(fields)) {
|
|
993
|
+
const parent = path.includes('.') ? path.slice(0, path.lastIndexOf('.')) : '';
|
|
994
|
+
children.set(parent, (children.get(parent) ?? new Set()).add(path.slice(parent.length && parent.length + 1)));
|
|
995
|
+
}
|
|
996
|
+
return children;
|
|
997
|
+
}
|
|
998
|
+
/** What is wrong with the value at `at`, as the object `parent` of the catalog: its form or its keys. */
|
|
999
|
+
function shapeProblems(at, value, parent, keys, meta) {
|
|
1000
|
+
if (value === null)
|
|
1001
|
+
return [];
|
|
1002
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
1003
|
+
if (!parent || /\||\[\]/.test(meta?.type ?? ''))
|
|
1004
|
+
return [];
|
|
1005
|
+
return [{ path: at, message: `has to be an object of ${[...keys].join(', ')}.` }];
|
|
1006
|
+
}
|
|
1007
|
+
return Object.keys(value)
|
|
1008
|
+
.filter((key) => !keys.has(key))
|
|
1009
|
+
.map((key) => ({
|
|
1010
|
+
path: at ? `${at}.${key}` : key,
|
|
1011
|
+
message: `is not a setting; ${at || 'this'} takes ${[...keys].join(', ')}.`,
|
|
1012
|
+
}));
|
|
1013
|
+
}
|
|
1014
|
+
/** The problems of `root` against `fields`, each keyed by the path of keys it names. */
|
|
1015
|
+
function fieldProblems(root, fields) {
|
|
1016
|
+
const problems = [];
|
|
1017
|
+
for (const [parent, keys] of keysByParent(fields)) {
|
|
1018
|
+
// why: A detector's own settings are `detectProblem`'s: which it takes depends on the detector.
|
|
1019
|
+
if (keys.has('*') || parent.startsWith('guardrails.detect'))
|
|
1020
|
+
continue;
|
|
1021
|
+
for (const [at, value] of parent ? valuesAt(root, parent.split('.')) : [['', root]]) {
|
|
1022
|
+
problems.push(...shapeProblems(at, value, parent, keys, fields[parent]));
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
for (const [path, meta] of Object.entries(fields)) {
|
|
1026
|
+
for (const [at, value] of valuesAt(root, path.split('.'))) {
|
|
1027
|
+
const message = valueProblem(meta, value);
|
|
1028
|
+
if (message)
|
|
1029
|
+
problems.push({ path: at, message });
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
return problems;
|
|
1033
|
+
}
|
|
1034
|
+
const PROFILE_CATALOG = Object.fromEntries(Object.entries(PROFILE_FIELDS).map(([path, meta]) => [profileKeysOf(path).join('.'), meta]));
|
|
1035
|
+
/** Every setting in a profile definition that the catalog cannot hold. Nothing here needs a complete profile. */
|
|
1036
|
+
export function profileFieldProblems(profile) {
|
|
1037
|
+
return fieldProblems(profile, PROFILE_CATALOG);
|
|
1038
|
+
}
|
|
1039
|
+
const TOOL_CATALOG = Object.fromEntries(Object.entries(EXTRA_FIELDS)
|
|
1040
|
+
.filter(([path]) => path.startsWith('registerTool.'))
|
|
1041
|
+
.map(([path, meta]) => [path.slice('registerTool.'.length), meta]));
|
|
1042
|
+
/** Every setting in a tool definition that the catalog cannot hold. Nothing here needs a complete tool. */
|
|
1043
|
+
export function toolFieldProblems(tool) {
|
|
1044
|
+
return fieldProblems(tool, TOOL_CATALOG);
|
|
1045
|
+
}
|
|
940
1046
|
export { API_EXPORTS, REQUEST_FIELDS } from './api-catalog.js';
|
|
941
1047
|
export { PROFILE_GRAPH, profileGraphFacet, spineFacetsForProfileType } from './profile-graph.js';
|
package/esm/src/kernel/stop.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ export interface ProfileTurnResumptionSpec {
|
|
|
29
29
|
* `stream_incomplete`) again itself when this list is set and names that stop, and the
|
|
30
30
|
* call gave no reply and no tool call: the turn keeps its history, its step count and
|
|
31
31
|
* what it has read. A failure the same call would meet again (the provider refused the
|
|
32
|
-
* request) is not sent again
|
|
32
|
+
* request) is not sent again, except once without its files when it carried any: accepted
|
|
33
|
+
* that way, the turn goes on and `done.mediaRefused` names them. Omitted, a turn sends
|
|
34
|
+
* nothing again.
|
|
33
35
|
*/
|
|
34
36
|
autoContinue?: ContinueStopKind[];
|
|
35
37
|
/**
|
|
@@ -4,6 +4,10 @@ import { labelText } from '../../guardrails/labels.js';
|
|
|
4
4
|
import { toolEvent } from './events.js';
|
|
5
5
|
import { formatToolResult } from './model-text.js';
|
|
6
6
|
import { operationWireValue, toolOperationReplySchema, } from './operation.js';
|
|
7
|
+
const toolBackgroundSchema = z.union([
|
|
8
|
+
z.enum(['always', 'ask', 'never']),
|
|
9
|
+
z.strictObject({ afterMs: z.number().finite().nonnegative() }),
|
|
10
|
+
]);
|
|
7
11
|
const FIELD = 'background';
|
|
8
12
|
/** The `ask` argument, as the model reads it. */
|
|
9
13
|
export function backgroundField() {
|
|
@@ -63,8 +67,9 @@ export function assertBackgroundSetting(tool) {
|
|
|
63
67
|
if (tool.answeredBy === 'page') {
|
|
64
68
|
throw new TheoremError('config', `Tool '${name}' sets background, which a tool answered by the page cannot`);
|
|
65
69
|
}
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
if (toolBackgroundSchema.safeParse(background).success)
|
|
71
|
+
return;
|
|
72
|
+
throw new TheoremError('config', typeof background === 'object'
|
|
73
|
+
? `Tool '${name}' sets background.afterMs, which must be a time in milliseconds` // labels-exempt: developer contract / internal diagnostic
|
|
74
|
+
: `Tool '${name}' sets background to ${JSON.stringify(background)}; it takes 'always', 'ask', 'never' or { afterMs }`);
|
|
70
75
|
}
|
|
@@ -8,7 +8,7 @@ import { detachedTrace } from '../engine/background.js';
|
|
|
8
8
|
import { invokeAgentCaller } from '../engine/runner/mod.js';
|
|
9
9
|
import { inStep, runSideBySide, stepOrder } from '../engine/runner/step-order.js';
|
|
10
10
|
import { startToolTrace, toolSpanName } from '../engine/tool-trace.js';
|
|
11
|
-
import { endThrownSpan,
|
|
11
|
+
import { endThrownSpan, runIdentity, traceLinks } from '../engine/turn-trace.js';
|
|
12
12
|
import { pickModel } from '../registry/resolve.js';
|
|
13
13
|
import { turnDoneOf } from '../turn-events.js';
|
|
14
14
|
import { assertBackgroundCoordinator, planDetach, } from './background.js';
|
|
@@ -50,7 +50,7 @@ async function* invokeInTrace(registry, request, spanName, sinkOverride, run) {
|
|
|
50
50
|
const tree = startTrace(spanName, {
|
|
51
51
|
attributes: {
|
|
52
52
|
'gen_ai.agent.name': request.profile,
|
|
53
|
-
...
|
|
53
|
+
...runIdentity(request),
|
|
54
54
|
},
|
|
55
55
|
links: traceLinks(request.links),
|
|
56
56
|
...(request.traceparent ? { traceparent: request.traceparent } : {}),
|
|
@@ -2,7 +2,7 @@ export { authorizeToolReplay, coerceToolResultParts, executeRegisteredTool, lean
|
|
|
2
2
|
export { askUserTool, registerHarnessTools } from './harness.js';
|
|
3
3
|
export { formatToolResult } from './model-text.js';
|
|
4
4
|
export type { ToolRegistry } from './registry.js';
|
|
5
|
-
export { createToolRegistry } from './registry.js';
|
|
5
|
+
export { assertToolSettings, createToolRegistry } from './registry.js';
|
|
6
6
|
export type { CredentialQuery, McpProtocolVersion, McpRpcResponse } from './remote.js';
|
|
7
7
|
export { buildHttpToolTarget, credentialPlacement, executeHttpTool, executeMcpTool, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, resolveToolAuth, withCredentialQuery, } from './remote.js';
|
|
8
8
|
export { cloneTurnToolSnapshot, prepareTurnToolSnapshot } from './resolve.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { authorizeToolReplay, coerceToolResultParts, executeRegisteredTool, leanToolResultData, projectForModel, } from './execute.js';
|
|
2
2
|
export { askUserTool, registerHarnessTools } from './harness.js';
|
|
3
3
|
export { formatToolResult } from './model-text.js';
|
|
4
|
-
export { createToolRegistry } from './registry.js';
|
|
4
|
+
export { assertToolSettings, createToolRegistry } from './registry.js';
|
|
5
5
|
export { buildHttpToolTarget, credentialPlacement, executeHttpTool, executeMcpTool, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, mcpRequestMeta, parseMcpRpcResponse, resolveToolAuth, withCredentialQuery, } from './remote.js';
|
|
6
6
|
export { cloneTurnToolSnapshot, prepareTurnToolSnapshot } from './resolve.js';
|
|
7
7
|
export { UncheckedOutput, uncheckedOutput } from './unchecked-output.js';
|
|
@@ -6,6 +6,8 @@ import type { ModelToolResult, ToolFailure } from './types.js';
|
|
|
6
6
|
* matches are replaced.
|
|
7
7
|
*/
|
|
8
8
|
export declare function formatToolResult(result: ModelToolResult): string;
|
|
9
|
+
/** Whether a tool message is a failure the kernel framed, not what the tool returned. */
|
|
10
|
+
export declare function isFramedToolFailure(content: string): boolean;
|
|
9
11
|
/** A failure as the kernel reports it to the model. The message is used as given. */
|
|
10
12
|
export declare function frameToolFailure(failure: Pick<ToolFailure, 'code' | 'message' | 'details'>): ModelToolResult;
|
|
11
13
|
/**
|
|
@@ -13,10 +13,15 @@ export function formatToolResult(result) {
|
|
|
13
13
|
}
|
|
14
14
|
return redactDetectors(composeToolText(result.finding, result.data), DETECTORS);
|
|
15
15
|
}
|
|
16
|
+
const FAILURE_OPEN = 'Tool error (';
|
|
17
|
+
/** Whether a tool message is a failure the kernel framed, not what the tool returned. */
|
|
18
|
+
export function isFramedToolFailure(content) {
|
|
19
|
+
return content.startsWith(FAILURE_OPEN);
|
|
20
|
+
}
|
|
16
21
|
/** A failure as the kernel reports it to the model. The message is used as given. */
|
|
17
22
|
export function frameToolFailure(failure) {
|
|
18
23
|
return {
|
|
19
|
-
finding:
|
|
24
|
+
finding: `${FAILURE_OPEN}${failure.code}): ${failure.message}`,
|
|
20
25
|
// why: The finding already says the code and message; only details are new.
|
|
21
26
|
...(failure.details !== undefined ? { data: { details: failure.details } } : {}),
|
|
22
27
|
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Profile, ProfileId } from '../types.js';
|
|
2
|
+
import { type ToolBackground } from './background.js';
|
|
2
3
|
import { type McpSessionCache } from './mcp-sessions.js';
|
|
3
|
-
import type { RegisteredTool, ToolDefinitionInput } from './types.js';
|
|
4
|
+
import type { FunctionToolDef, HttpToolDef, McpToolDef, RegisteredTool, ToolDefinitionInput } from './types.js';
|
|
5
|
+
/** The settings of a tool's definition that are plain values: every check `register` makes without running or converting anything. */
|
|
6
|
+
declare function assertToolSettings(def: Pick<HttpToolDef, 'name'> & Partial<Pick<HttpToolDef, 'endpoint' | 'auth' | 'mapping' | 'limit' | 'timeoutMs'> & Pick<HttpToolDef, 'maxResponseBytes' | 'imageLimits'> & Pick<McpToolDef, 'session'> & Pick<FunctionToolDef, 'answeredBy'>> & {
|
|
7
|
+
type?: string;
|
|
8
|
+
background?: ToolBackground;
|
|
9
|
+
}): void;
|
|
4
10
|
/** The tools a scope has registered: register, look up, and list them, find a profile for agent tools, and reset. */
|
|
5
11
|
interface ToolRegistry {
|
|
6
12
|
/** Replaces a tool of the same name. */
|
|
@@ -24,4 +30,4 @@ interface ToolRegistry {
|
|
|
24
30
|
*/
|
|
25
31
|
declare function createToolRegistry(findProfile?: (id: ProfileId) => Profile | undefined): ToolRegistry;
|
|
26
32
|
export type { ToolRegistry };
|
|
27
|
-
export { createToolRegistry };
|
|
33
|
+
export { assertToolSettings, createToolRegistry };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TheoremError } from '../../guardrails/error.js';
|
|
2
2
|
import { profileInputs } from '../registry/catalog.js';
|
|
3
|
+
import { toolFieldProblems } from '../schema.js';
|
|
3
4
|
import { activityLabelProblem } from './activity-label.js';
|
|
4
5
|
import { agentToolInputFor, agentToolOutput, agentToolProfile, normalizeAgent } from './agent.js';
|
|
5
6
|
import { assertBackgroundSetting, backgroundField } from './background.js';
|
|
@@ -101,26 +102,47 @@ function assertReadLimits(def) {
|
|
|
101
102
|
assertWhole(def.name, 'imageLimits.totalBytes', images.totalBytes);
|
|
102
103
|
assertTimeout(def.name, images.timeoutMs);
|
|
103
104
|
}
|
|
105
|
+
/** The settings of a tool's definition that are plain values: every check `register` makes without running or converting anything. */
|
|
106
|
+
function assertToolSettings(def) {
|
|
107
|
+
if (def.type !== 'builtin') {
|
|
108
|
+
assertBackgroundSetting({
|
|
109
|
+
name: def.name,
|
|
110
|
+
...(def.background !== undefined ? { background: def.background } : {}),
|
|
111
|
+
...(def.answeredBy ? { answeredBy: def.answeredBy } : {}),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (def.type === 'builtin' || def.type === 'agent')
|
|
115
|
+
return;
|
|
116
|
+
assertAuthService(def.name, def.auth);
|
|
117
|
+
if (def.type === 'http') {
|
|
118
|
+
if (def.endpoint?.trim())
|
|
119
|
+
assertFixedEndpointOrigin(def.endpoint);
|
|
120
|
+
assertQueryParam(def.name, def.auth, def.mapping?.queryParams);
|
|
121
|
+
assertLimit(def.name, def.limit);
|
|
122
|
+
assertTimeout(def.name, def.timeoutMs);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
assertQueryParam(def.name, def.auth);
|
|
126
|
+
}
|
|
127
|
+
if (def.type === 'http' || def.type === 'mcp')
|
|
128
|
+
assertReadLimits(def);
|
|
129
|
+
if (def.type === 'mcp') {
|
|
130
|
+
assertWhole(def.name, 'session.idleMs', def.session?.idleMs);
|
|
131
|
+
assertWhole(def.name, 'session.max', def.session?.max);
|
|
132
|
+
}
|
|
133
|
+
const [problem] = toolFieldProblems(def);
|
|
134
|
+
if (problem) {
|
|
135
|
+
throw new TheoremError('config', `Tool "${def.name}" ${problem.path} ${problem.message}`); // labels-exempt: developer contract / internal diagnostic
|
|
136
|
+
}
|
|
137
|
+
}
|
|
104
138
|
function normalizeHttp(def) {
|
|
105
139
|
assertFixedEndpointOrigin(def.endpoint);
|
|
106
|
-
assertAuthService(def.name, def.auth);
|
|
107
|
-
assertQueryParam(def.name, def.auth, def.mapping?.queryParams);
|
|
108
|
-
assertLimit(def.name, def.limit);
|
|
109
|
-
assertTimeout(def.name, def.timeoutMs);
|
|
110
|
-
assertReadLimits(def);
|
|
111
140
|
return { ...def, type: 'http', ...schemasFromZod(def) };
|
|
112
141
|
}
|
|
113
142
|
function normalizeMcp(def) {
|
|
114
|
-
assertAuthService(def.name, def.auth);
|
|
115
|
-
assertQueryParam(def.name, def.auth);
|
|
116
|
-
assertReadLimits(def);
|
|
117
|
-
assertWhole(def.name, 'session.idleMs', def.session?.idleMs);
|
|
118
|
-
assertWhole(def.name, 'session.max', def.session?.max);
|
|
119
143
|
return { ...def, type: 'mcp', ...schemasFromZod(def) };
|
|
120
144
|
}
|
|
121
145
|
function normalizeFunction(def) {
|
|
122
|
-
assertAuthService(def.name, def.auth);
|
|
123
|
-
assertQueryParam(def.name, def.auth);
|
|
124
146
|
const handler = def.answeredBy === 'page'
|
|
125
147
|
? pageAnswerHandler(def.name)
|
|
126
148
|
: def.handler;
|
|
@@ -129,22 +151,16 @@ function normalizeFunction(def) {
|
|
|
129
151
|
}
|
|
130
152
|
return { ...def, handler, type: 'function', ...schemasFromZod(def) };
|
|
131
153
|
}
|
|
132
|
-
/**
|
|
154
|
+
/** Gives an `ask` tool the schema a turn with the service sends. */
|
|
133
155
|
function withBackground(tool) {
|
|
134
|
-
if (tool.type === 'builtin')
|
|
135
|
-
return tool;
|
|
136
|
-
assertBackgroundSetting({
|
|
137
|
-
name: tool.name,
|
|
138
|
-
...(tool.background !== undefined ? { background: tool.background } : {}),
|
|
139
|
-
...(tool.type === 'function' && tool.answeredBy ? { answeredBy: tool.answeredBy } : {}),
|
|
140
|
-
});
|
|
141
|
-
if (tool.background !== 'ask')
|
|
156
|
+
if (tool.type === 'builtin' || tool.background !== 'ask')
|
|
142
157
|
return tool;
|
|
143
158
|
const input = tool.input;
|
|
144
159
|
const asked = withModelField(tool.name, input, 'background', backgroundField);
|
|
145
160
|
return { ...tool, askInputSchema: checkedSchemas(asked, tool.output).inputSchema };
|
|
146
161
|
}
|
|
147
162
|
function normalizeToolDefinition(def, findProfile, findTool) {
|
|
163
|
+
assertToolSettings(def);
|
|
148
164
|
return withBackground(normalizeDefinition(def, findProfile, findTool));
|
|
149
165
|
}
|
|
150
166
|
function normalizeDefinition(def, findProfile, findTool) {
|
|
@@ -202,4 +218,4 @@ function createToolRegistry(findProfile = () => undefined) {
|
|
|
202
218
|
mcpSessions,
|
|
203
219
|
};
|
|
204
220
|
}
|
|
205
|
-
export { createToolRegistry };
|
|
221
|
+
export { assertToolSettings, createToolRegistry };
|
|
@@ -6,7 +6,7 @@ import type { ToolCredentialSource } from '../auth/credential-source.js';
|
|
|
6
6
|
import type { OAuthEndpoints } from '../auth/types.js';
|
|
7
7
|
import type { AuthUnauthenticatedPolicy, HttpMethod, ToolAccess, ToolAuthType, ToolGateKind, ToolLoadTier, ToolPermission, ToolResumeCause } from '../schema.js';
|
|
8
8
|
import type { RemovedItem, Source, ToolCallEdit, ToolCallEvent, ToolCallRequest, ToolFailure, ToolGate, ToolPhaseEvent, ToolTraceStep, ToolWarning, TurnToolSnapshot, WireFunctionTool } from '../turn-events.js';
|
|
9
|
-
import type { InteractionPart, ModelId, Profile, ProfileId, ToolId, TurnInput, TurnRequest, TurnSpeech
|
|
9
|
+
import type { InteractionPart, ModelId, Profile, ProfileId, RunControls, ToolId, TurnInput, TurnRequest, TurnSpeech } from '../types.js';
|
|
10
10
|
import type { LabelTemplate } from './activity-label.js';
|
|
11
11
|
import type { ToolBackground, ToolBackgroundService } from './background.js';
|
|
12
12
|
import type { PageToolExecution, ToolExecutionCoordinator } from './operation.js';
|
|
@@ -17,7 +17,6 @@ export interface ToolLabels {
|
|
|
17
17
|
activityPast?: LabelTemplate;
|
|
18
18
|
activityFailed?: LabelTemplate;
|
|
19
19
|
request?: LabelTemplate;
|
|
20
|
-
hiddenFromSettings?: boolean;
|
|
21
20
|
}
|
|
22
21
|
export interface ToolBase {
|
|
23
22
|
name: string;
|
|
@@ -404,7 +403,7 @@ export interface ToolLoadContext {
|
|
|
404
403
|
/** Picks which allowed T2 tools to load at turn start. */
|
|
405
404
|
export type ToolPolicy = (ctx: ToolLoadContext) => ToolId[] | Promise<ToolId[]>;
|
|
406
405
|
/** A request to run a held tool call outside a turn. */
|
|
407
|
-
export interface InvokeToolRequest {
|
|
406
|
+
export interface InvokeToolRequest extends RunControls {
|
|
408
407
|
execution?: ToolExecutionCoordinator;
|
|
409
408
|
background?: ToolBackgroundService;
|
|
410
409
|
/** invariant: Only the trusted host restores the kernel-issued identity from saved authority. */
|
|
@@ -430,19 +429,11 @@ export interface InvokeToolRequest {
|
|
|
430
429
|
credentials?: ToolCredentialSource;
|
|
431
430
|
resolveHost?: ResolveHost;
|
|
432
431
|
path?: string;
|
|
433
|
-
signal?: AbortSignal;
|
|
434
432
|
/** Handed to the tool as `ctx.host`; the kernel never reads it. */
|
|
435
433
|
host?: unknown;
|
|
436
434
|
/** The page's answer, when this invoke answers a `page` gate. */
|
|
437
435
|
page?: PageAnswer;
|
|
438
436
|
pageExecution?: PageToolExecution;
|
|
439
|
-
/** W3C `traceparent` of the host span this invoke runs under. */
|
|
440
|
-
traceparent?: string;
|
|
441
|
-
/** Recorded as `gen_ai.conversation.id`. */
|
|
442
|
-
conversationId?: string;
|
|
443
|
-
/** Preserved on the trace record; the kernel does not interpret it. */
|
|
444
|
-
metadata?: Record<string, unknown>;
|
|
445
|
-
links?: TurnTraceLink[];
|
|
446
437
|
/** Receives `pre_tool` / `post_tool` only. */
|
|
447
438
|
onStage?: import('../stages.js').StageHandler;
|
|
448
439
|
/** Runs an agent tool's turn; an agent tool needs it, or `onAgentCall` returning one. */
|
|
@@ -563,6 +563,20 @@ export interface CompactionEvent extends Omit<CompactionResult, 'toCompact'> {
|
|
|
563
563
|
}
|
|
564
564
|
/** Stops that end a turn with tools pending; `done.tools` is present exactly on them. */
|
|
565
565
|
export type ToolSnapshotStopKind = Extract<TurnStopKind, 'tool' | 'gate'>;
|
|
566
|
+
/** One file a provider refused: what it was, and where the turn was carrying it. */
|
|
567
|
+
export interface RefusedMedia {
|
|
568
|
+
mimeType: string;
|
|
569
|
+
from: 'input' | 'history' | 'tool';
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* The turn went on without files the provider refused. Set only when the same call, sent
|
|
573
|
+
* without them, was accepted: that is the proof the files were at fault.
|
|
574
|
+
*/
|
|
575
|
+
export interface MediaRefused {
|
|
576
|
+
dropped: RefusedMedia[];
|
|
577
|
+
/** The provider's own reason, for the builder only: `forClient` strips the whole report. */
|
|
578
|
+
said: string;
|
|
579
|
+
}
|
|
566
580
|
export interface DoneBase {
|
|
567
581
|
providerState?: ProviderCheckpoint;
|
|
568
582
|
/** The turn's summed usage (`sumTokens` over its `tokens` events). */
|
|
@@ -575,6 +589,7 @@ export interface DoneBase {
|
|
|
575
589
|
/** A user utterance interrupted an in-flight live response (barge-in). */
|
|
576
590
|
interrupted?: boolean;
|
|
577
591
|
interactionId?: string;
|
|
592
|
+
mediaRefused?: MediaRefused;
|
|
578
593
|
}
|
|
579
594
|
/**
|
|
580
595
|
* The turn ended. On stop `tool` or `gate` it carries the turn's tool snapshot
|
|
@@ -655,6 +670,14 @@ export type TurnEvent = {
|
|
|
655
670
|
type: 'attempt';
|
|
656
671
|
attempt: number;
|
|
657
672
|
reason: AttemptReason;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* The message `input.lateResults` put in the conversation, role `user`. It enters a history built
|
|
676
|
+
* from events like any other message.
|
|
677
|
+
*/
|
|
678
|
+
| {
|
|
679
|
+
type: 'late_results';
|
|
680
|
+
text: string;
|
|
658
681
|
} | {
|
|
659
682
|
type: 'media';
|
|
660
683
|
media: {
|
|
@@ -364,6 +364,12 @@ const doneBase = {
|
|
|
364
364
|
compaction: compactionSignal.optional(),
|
|
365
365
|
interrupted: z.boolean().optional(),
|
|
366
366
|
interactionId: z.string().optional(),
|
|
367
|
+
mediaRefused: z
|
|
368
|
+
.object({
|
|
369
|
+
dropped: z.array(z.object({ mimeType: z.string(), from: z.enum(['input', 'history', 'tool']) })),
|
|
370
|
+
said: z.string(),
|
|
371
|
+
})
|
|
372
|
+
.optional(),
|
|
367
373
|
};
|
|
368
374
|
const doneEvent = z.union([
|
|
369
375
|
z.object({
|
|
@@ -412,6 +418,7 @@ const TURN_EVENTS = {
|
|
|
412
418
|
attempt: z.number().int().positive(),
|
|
413
419
|
reason: z.enum(['validation', 'egress']),
|
|
414
420
|
}),
|
|
421
|
+
late_results: z.object({ type: z.literal('late_results'), text: z.string() }),
|
|
415
422
|
media: z.object({
|
|
416
423
|
type: z.literal('media'),
|
|
417
424
|
media: z.object({ mimeType: z.string(), data: z.string() }),
|
|
@@ -505,6 +512,7 @@ const turnEvent = z.union([
|
|
|
505
512
|
TURN_EVENTS.citation,
|
|
506
513
|
TURN_EVENTS.compaction,
|
|
507
514
|
TURN_EVENTS.evidence,
|
|
515
|
+
TURN_EVENTS.late_results,
|
|
508
516
|
TURN_EVENTS.tokens,
|
|
509
517
|
TURN_EVENTS.session,
|
|
510
518
|
TURN_EVENTS.guardrail,
|
|
@@ -715,6 +715,15 @@ const TRACE_EVENTS = {
|
|
|
715
715
|
error: attr('error', 'Detail', 'content', "The provider's internal reason."),
|
|
716
716
|
},
|
|
717
717
|
},
|
|
718
|
+
'theorem.step.media_refused': {
|
|
719
|
+
label: 'Sent without files',
|
|
720
|
+
doc: 'The provider refused a model call that carried files, and the turn sent it without them.',
|
|
721
|
+
attributes: {
|
|
722
|
+
step: attr('agent', 'Step', 'number', 'The step whose model call was refused.'),
|
|
723
|
+
files: attr('agent', 'Files', 'number', 'How many files the call went without.'),
|
|
724
|
+
error: attr('error', 'Detail', 'content', "The provider's internal reason."),
|
|
725
|
+
},
|
|
726
|
+
},
|
|
718
727
|
'theorem.compaction': {
|
|
719
728
|
label: 'Compaction',
|
|
720
729
|
doc: 'theorem decided whether to summarize earlier messages.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/agents",
|
|
3
|
-
"version": "0.3.4-next.
|
|
3
|
+
"version": "0.3.4-next.753.g176c472",
|
|
4
4
|
"description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|