@theoremjs/agents 0.3.4-next.594.g145ceaf → 0.3.4-next.598.gb003e90
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/esm/src/guardrails/labels.d.ts +1 -1
- package/esm/src/guardrails/labels.js +4 -0
- package/esm/src/kernel/engine/compaction.d.ts +2 -1
- package/esm/src/kernel/engine/compaction.js +12 -2
- package/esm/src/providers/openrouter/openai/compat.js +4 -2
- package/esm/src/providers/shared/carried-tool-files.d.ts +6 -0
- package/esm/src/providers/shared/carried-tool-files.js +29 -0
- package/package.json +1 -1
|
@@ -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", "compaction.request", "compaction.tool_call", "compaction.tool_result", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.injection", "detect.hint.tool_instructions", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.full", "session.busy", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
|
|
4
|
+
export declare const LABEL_KEYS: readonly ["provider.decision_failed", "provider.decision_unavailable", "provider.decision_model_missing", "provider.decision_ended", "provider.decision_images_off", "provider.decision_box_model", "provider.budget_exhausted", "provider.adapter_version", "provider.adapter_methods", "provider.adapter_schemas", "provider.fallback_slot", "provider.model_fallback_slot", "provider.host_model", "provider.turn_profile", "provider.model_binding_missing", "provider.session_closed", "provider.settled_call", "provider.session_unavailable", "provider.live_input", "provider.tool_cancel_missing", "provider.kernel_gate", "provider.event_invalid", "provider.response_identity", "provider.credential_resolution", "provider.credential_shape", "provider.stored_continuation", "provider.continuation_mismatch", "provider.continuation_contract", "provider.stateless_history", "provider.events_after_completion", "provider.duplicate_call", "provider.tool_cancel_live", "provider.complete_unavailable", "provider.parallel_tools", "provider.binding_identity", "provider.profile_type", "provider.event_type", "provider.feature", "provider.input_kind", "provider.output_kind", "provider.builtin", "provider.credential_missing", "provider.profile_configuration", "continue.instruction", "canary.bind_note", "user_data.note", "context.note", "taint.blocked", "taint.reason_steered", "taint.reason_tainted", "taint.destination_blocked", "taint.destination_confirm", "advisory.notice_elevated", "advisory.notice_high", "advisory.guidance", "attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "attachments.limits_unconfigured", "quota.exhausted", "quota.busy", "error.config", "error.request", "error.conflict", "error.not_found", "error.input", "error.action", "error.auth", "error.rate_limit", "error.busy", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "repair.default_guidance", "repair.items_guidance", "repair.prompt_header", "repair.prompt_intro", "repair.prompt_instructions", "repair.history_heading", "repair.section_previous_output", "repair.section_validator_rejection", "repair.section_repair_guidance", "repair.section_instructions", "structured.answer_tool", "structured.answer_missing", "compaction.request", "compaction.tool_call", "compaction.tool_result", "compaction.tool_files", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.injection", "detect.hint.tool_instructions", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.full", "session.busy", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
|
|
5
5
|
/** One of {@linkcode LABEL_KEYS}. */
|
|
6
6
|
export type LabelKey = (typeof LABEL_KEYS)[number];
|
|
7
7
|
/**
|
|
@@ -102,6 +102,7 @@ export const LABEL_KEYS = [
|
|
|
102
102
|
'compaction.request',
|
|
103
103
|
'compaction.tool_call',
|
|
104
104
|
'compaction.tool_result',
|
|
105
|
+
'compaction.tool_files',
|
|
105
106
|
'decision.box_image',
|
|
106
107
|
'detect.blocked',
|
|
107
108
|
'detect.call_blocked',
|
|
@@ -426,6 +427,7 @@ const DEFAULTS = {
|
|
|
426
427
|
'compaction.request': 'Summarize the conversation above, including any earlier summary in it. Call the participants the user and the assistant, and keep every name, number, fact, and decision either may need later. Reply with the summary only.',
|
|
427
428
|
'compaction.tool_call': 'Called {tool} with {arguments}',
|
|
428
429
|
'compaction.tool_result': '{tool} returned: {result}',
|
|
430
|
+
'compaction.tool_files': 'Files {tool} returned:',
|
|
429
431
|
'decision.box_image': 'Give the box in {image}.',
|
|
430
432
|
'egress.default_repair_guidance': 'Write the reply again for the user. Keep what was helpful in it, and leave out everything the rejection names.',
|
|
431
433
|
'detect.hint.ids': 'Leave out ID numbers such as an SSN, ITIN, or EIN.',
|
|
@@ -643,6 +645,7 @@ export const LABEL_NOTES = {
|
|
|
643
645
|
'compaction.request': 'Sent to the compactor after the messages it compacts, asking for the summary.',
|
|
644
646
|
'compaction.tool_call': 'How a tool call reads to the compactor. Takes {tool} and {arguments}, the call as JSON.',
|
|
645
647
|
'compaction.tool_result': 'How a tool result reads to the compactor. Takes {tool} and {result}, the output as sent to the model.',
|
|
648
|
+
'compaction.tool_files': "Leads the user message that carries a tool result's files to the compactor, after the result. Takes {tool}.",
|
|
646
649
|
'decision.box_image': "Added to a box question's instructions to say which image the box is in. Takes {image}, a reference such as <ghs02> or a state field in backticks.",
|
|
647
650
|
'detect.blocked': 'Shown to the user when a detector set to block matched something in what they sent, so the turn was refused.',
|
|
648
651
|
'detect.call_blocked': 'Told to the model in place of a tool call a detector set to block stopped at its arguments.',
|
|
@@ -780,6 +783,7 @@ const LABEL_PLACEHOLDERS = {
|
|
|
780
783
|
'structured.answer_missing': TOOL,
|
|
781
784
|
'compaction.tool_call': ['tool', 'arguments'],
|
|
782
785
|
'compaction.tool_result': ['tool', 'result'],
|
|
786
|
+
'compaction.tool_files': ['tool'],
|
|
783
787
|
'decision.box_image': ['image'],
|
|
784
788
|
'detect.hint.own': ['label'],
|
|
785
789
|
'egress.rejection': ['found'],
|
|
@@ -46,7 +46,8 @@ export declare function splitForCompaction(history: TurnHistoryMessage[], spec:
|
|
|
46
46
|
/**
|
|
47
47
|
* `toCompact` as the compactor reads it: media its profile does not accept is
|
|
48
48
|
* left out, and tool calls and results become the assistant's text, so no
|
|
49
|
-
* provider needs the tools declared to read them.
|
|
49
|
+
* provider needs the tools declared to read them. A result's files follow it
|
|
50
|
+
* in a user message.
|
|
50
51
|
*/
|
|
51
52
|
export declare function compactorHistory(toCompact: readonly TurnHistoryMessage[], compactor: Profile): {
|
|
52
53
|
history: TurnHistoryMessage[];
|
|
@@ -119,7 +119,8 @@ function textPart(text) {
|
|
|
119
119
|
/**
|
|
120
120
|
* `toCompact` as the compactor reads it: media its profile does not accept is
|
|
121
121
|
* left out, and tool calls and results become the assistant's text, so no
|
|
122
|
-
* provider needs the tools declared to read them.
|
|
122
|
+
* provider needs the tools declared to read them. A result's files follow it
|
|
123
|
+
* in a user message.
|
|
123
124
|
*/
|
|
124
125
|
export function compactorHistory(toCompact, compactor) {
|
|
125
126
|
const labels = compactor.labels;
|
|
@@ -143,9 +144,18 @@ export function compactorHistory(toCompact, compactor) {
|
|
|
143
144
|
role: 'assistant',
|
|
144
145
|
parts: [
|
|
145
146
|
textPart(labelText('compaction.tool_result', { tool: tool ?? '', result }, labels)),
|
|
146
|
-
...parts,
|
|
147
147
|
],
|
|
148
148
|
});
|
|
149
|
+
// why: Chat Completions takes only text in assistant content, and endpoints that enforce it refuse the call.
|
|
150
|
+
if (parts.length > 0) {
|
|
151
|
+
history.push({
|
|
152
|
+
role: 'user',
|
|
153
|
+
parts: [
|
|
154
|
+
textPart(labelText('compaction.tool_files', { tool: tool ?? '' }, labels)),
|
|
155
|
+
...parts,
|
|
156
|
+
],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
149
159
|
continue;
|
|
150
160
|
}
|
|
151
161
|
const calls = (message.tool_calls ?? []).map((call) => textPart(labelText('compaction.tool_call', { tool: call.function.name, arguments: call.function.arguments }, labels)));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { kindOfHttpStatus, TheoremError, toErrorEvent, } from '../../../guardrails/error.js';
|
|
2
2
|
import { asRecord } from '../../../kernel/engine/record.js';
|
|
3
3
|
import { historyMessageParts, isMediaRefPart } from '../../../kernel/interaction-parts.js';
|
|
4
|
-
import { withCarriedToolFiles } from '../../shared/carried-tool-files.js';
|
|
4
|
+
import { withCarriedAssistantFiles, withCarriedToolFiles, } from '../../shared/carried-tool-files.js';
|
|
5
5
|
import { historyToolIdentity } from '../../shared/tool-args.js';
|
|
6
6
|
/** The fields Chat Completions gives every error; any other field is the provider's own detail. */
|
|
7
7
|
const STANDARD_ERROR_FIELDS = new Set(['message', 'type', 'param', 'code']);
|
|
@@ -127,7 +127,9 @@ function buildChatMessages(req, options) {
|
|
|
127
127
|
if (includeSystem && req.system) {
|
|
128
128
|
messages.push({ role: 'system', content: req.system });
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
// why: Chat Completions takes only text and refusals in assistant content, and endpoints that enforce it refuse the call.
|
|
131
|
+
const history = withCarriedAssistantFiles(req.history ?? []);
|
|
132
|
+
for (const h of withCarriedToolFiles(history, TOOL_MESSAGE_PART_TYPES)) {
|
|
131
133
|
messages.push(wireHistoryMessage(h));
|
|
132
134
|
}
|
|
133
135
|
if (req.input.length > 0) {
|
|
@@ -5,3 +5,9 @@ import type { InteractionPart, TurnHistoryMessage } from '../../kernel/types.js'
|
|
|
5
5
|
* one user message, so the results of a parallel call stay together.
|
|
6
6
|
*/
|
|
7
7
|
export declare function withCarriedToolFiles(messages: readonly TurnHistoryMessage[], holds: ReadonlySet<InteractionPart['type']>): TurnHistoryMessage[];
|
|
8
|
+
/**
|
|
9
|
+
* History for a wire whose assistant content holds only text. An assistant
|
|
10
|
+
* message's files leave a marker in their place and follow it in one user
|
|
11
|
+
* message, after the results of any calls it made.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withCarriedAssistantFiles(messages: readonly TurnHistoryMessage[]): TurnHistoryMessage[];
|
|
@@ -41,3 +41,32 @@ export function withCarriedToolFiles(messages, holds) {
|
|
|
41
41
|
flush();
|
|
42
42
|
return out;
|
|
43
43
|
}
|
|
44
|
+
const ASSISTANT_FILES_LEAD = { type: 'text', text: 'Files the assistant sent:' };
|
|
45
|
+
/**
|
|
46
|
+
* History for a wire whose assistant content holds only text. An assistant
|
|
47
|
+
* message's files leave a marker in their place and follow it in one user
|
|
48
|
+
* message, after the results of any calls it made.
|
|
49
|
+
*/
|
|
50
|
+
export function withCarriedAssistantFiles(messages) {
|
|
51
|
+
const out = [];
|
|
52
|
+
let carried = [];
|
|
53
|
+
for (const msg of messages) {
|
|
54
|
+
if (msg.role !== 'tool' && carried.length > 0) {
|
|
55
|
+
out.push({ role: 'user', parts: carried });
|
|
56
|
+
carried = [];
|
|
57
|
+
}
|
|
58
|
+
const files = msg.role === 'assistant' ? (msg.parts ?? []).filter((p) => p.type !== 'text') : [];
|
|
59
|
+
if (files.length === 0) {
|
|
60
|
+
out.push(msg);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
out.push({
|
|
64
|
+
...msg,
|
|
65
|
+
parts: (msg.parts ?? []).map((part) => part.type === 'text' ? part : carriedFileMarker(part)),
|
|
66
|
+
});
|
|
67
|
+
carried.push(ASSISTANT_FILES_LEAD, ...files);
|
|
68
|
+
}
|
|
69
|
+
if (carried.length > 0)
|
|
70
|
+
out.push({ role: 'user', parts: carried });
|
|
71
|
+
return out;
|
|
72
|
+
}
|
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.598.gb003e90",
|
|
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",
|