llmz 1.0.1 → 1.0.3
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/DOCS.md +8 -4
- package/ERRORS.md +5 -2
- package/dist/{component-BpMVZYOa.cjs → component-CMFoCHyu.cjs} +3 -3
- package/dist/{component-C27qu6Zv.js → component-DncqP4fB.js} +3 -3
- package/dist/context.d.ts +1 -1
- package/dist/{custom-client-MytucGI-.cjs → custom-client-BwRYQ4Oa.cjs} +37 -13
- package/dist/{custom-client-BDkgBR2w.js → custom-client-JcdoH-47.js} +37 -13
- package/dist/errors/catalog.d.ts +7 -0
- package/dist/{errors-IhnTKUp7.cjs → errors-C6ppQUZX.cjs} +22 -0
- package/dist/{errors-H4JJFH3S.js → errors-Crk5P8jo.js} +17 -1
- package/dist/errors.d.ts +6 -0
- package/dist/{execute-DLas4V2n.cjs → execute-DJBNrA2H.cjs} +209 -79
- package/dist/{execute-BYI_U5sR.js → execute-DoN74Exa.js} +209 -79
- package/dist/{exit-BUgJ5qi5.cjs → exit-BOtKWPuT.cjs} +2 -2
- package/dist/{exit-CPNk3vbz.js → exit-DMPwCSba.js} +2 -2
- package/dist/index.cjs +18 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -18
- package/dist/index.workerd.js +404 -88
- package/dist/inspection.d.ts +2 -0
- package/dist/{native-DvTH9vFe.js → native-BGW5kBlv.js} +136 -10
- package/dist/{native-Bm6L9zOb.cjs → native-sbuzbLbY.cjs} +136 -10
- package/dist/prompts/native-examples.d.ts +10 -0
- package/dist/prompts/native-examples.test.d.ts +1 -0
- package/dist/prompts/reasoning.d.ts +2 -0
- package/dist/prompts/reasoning.test.d.ts +1 -0
- package/dist/{quickjs-variant-DJwYDSsb.cjs → quickjs-variant-21IO97PF.cjs} +15 -8
- package/dist/{quickjs-variant-DlPi9-Sx.js → quickjs-variant-CtuGagsb.js} +10 -9
- package/dist/runtime/chat-completion.test.d.ts +1 -0
- package/dist/runtime/chat-last-speaker.test.d.ts +1 -0
- package/dist/runtime/empty-completion.test.d.ts +1 -0
- package/dist/runtime/execution-report.d.ts +3 -0
- package/dist/runtime/forced-inspection.d.ts +13 -0
- package/dist/runtime/forced-inspection.test.d.ts +1 -0
- package/dist/runtime/javascript-api.d.ts +3 -0
- package/dist/runtime/think-signal.test.d.ts +1 -0
- package/dist/runtime/tool-wrapper.d.ts +4 -2
- package/dist/runtime/types.d.ts +8 -0
- package/dist/{schema-DBkjo0b7.cjs → schema-CXlnbb3n.cjs} +1 -1
- package/dist/{schema-Aer_W7Al.js → schema-GE4ISPCR.js} +1 -1
- package/dist/session/messages.d.ts +2 -0
- package/dist/session/serialization.d.ts +2 -0
- package/dist/session/session.d.ts +4 -0
- package/dist/session/speaker.test.d.ts +1 -0
- package/dist/{tool--gK91eez.js → tool-DstssiAs.js} +4 -4
- package/dist/{tool-Da_F-N-5.cjs → tool-_wK9hQOb.cjs} +4 -4
- package/dist/{truncate-BSoH2-nY.js → truncate-BEKbdo3t.js} +1 -1
- package/dist/{truncate-nV3Mxr6-.cjs → truncate-uomAMGPs.cjs} +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/{typings-C1ihexWE.cjs → typings-BA_XxAcY.cjs} +1 -1
- package/dist/{typings-D9_aC8aq.js → typings-BEVDvtuk.js} +1 -1
- package/dist/vm/types.d.ts +2 -0
- package/dist/{vm-8jxt8PTK.js → vm-C7SfutHn.js} +28 -3
- package/dist/{vm-XuVPuW3Y.cjs → vm-gmekHc0i.cjs} +28 -2
- package/package.json +2 -1
package/dist/inspection.d.ts
CHANGED
|
@@ -36,3 +36,5 @@ export type InspectionOptions = {
|
|
|
36
36
|
export type Inspector = (value: unknown, options: InspectionOptions) => string;
|
|
37
37
|
/** The shared boundary for values displayed in prompts, reports, and memory inventories. */
|
|
38
38
|
export declare function createInspector(onInspect?: OnInspect): Inspector;
|
|
39
|
+
/** Isolate evidence from subsequent guest mutations without invoking getters. */
|
|
40
|
+
export declare function snapshotInspectionValue(value: unknown, copies?: WeakMap<object, unknown>): unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Y as __exportAll, i as getMultilineComment } from "./utils-BOFzb8Ok.js";
|
|
2
|
-
import { b as InvalidConfigurationError } from "./errors-
|
|
3
|
-
import { i as formatTypings, t as getTypings } from "./typings-
|
|
2
|
+
import { b as InvalidConfigurationError } from "./errors-Crk5P8jo.js";
|
|
3
|
+
import { i as formatTypings, t as getTypings } from "./typings-BEVDvtuk.js";
|
|
4
4
|
//#region src/chat/response.ts
|
|
5
5
|
const presets = {
|
|
6
6
|
markdown: { instructions: "Write natural Markdown directly in the assistant response. Use paragraphs, lists, links, and code blocks where useful. Do not wrap the entire response in JSON or a Markdown fence." },
|
|
@@ -32,15 +32,20 @@ function resolveResponse(response = "markdown") {
|
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/runtime/native-tools.ts
|
|
34
34
|
const WORKER_RESPONSE_INSTRUCTION = "You are running in worker mode. Respond only with a run_javascript tool call. Keep assistant text empty: do not send messages, preambles, progress updates, explanations, acknowledgements such as \"Done\", Markdown, or JSON outside the tool call. This applies before and after tools, during recovery, and when completing the task.";
|
|
35
|
+
const EXECUTION_DESCRIPTION = "Execute a JavaScript program in the sandbox. This is the only native tool; business functions are called INSIDE its code, using their documented signatures. It is not a search engine: never submit search terms, user questions, answers, or business tool names as code. Await business calls, then return inspect(value) to read their results, or return exit(name, payload) to select a registered outcome. See \"run_javascript syntax\" and the examples.";
|
|
35
36
|
const RUN_JAVASCRIPT_TOOL = {
|
|
36
37
|
name: "run_javascript",
|
|
37
|
-
description:
|
|
38
|
+
description: `${EXECUTION_DESCRIPTION} For a requested text message plus an action or component, include the assistant text AND this tool call in the same response. A plain assistant reply needs no tool call when no action remains.`,
|
|
38
39
|
parameters: {
|
|
39
40
|
type: "object",
|
|
40
41
|
properties: { code: {
|
|
41
42
|
type: "string",
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
description: [
|
|
44
|
+
"The body of an async JavaScript program. Top-level await and return are supported. No Markdown fences, XML wrappers, imports, or TypeScript annotations.",
|
|
45
|
+
"Call business functions using the actual API declarations. A string parameter takes a string; an object parameter takes its documented fields. Do not put a query or reply here instead of a program.",
|
|
46
|
+
"<example purpose=\"JavaScript syntax only\">const total = 17 + 25; return inspect(total);</example>",
|
|
47
|
+
"The example tags are documentation only. The code value must contain only executable JavaScript. End with return inspect(value), or return exit(\"registered_name\", payload) with the actual outcome name and required payload. These are JavaScript functions, not separate native tools."
|
|
48
|
+
].join("\n\n")
|
|
44
49
|
} },
|
|
45
50
|
required: ["code"],
|
|
46
51
|
additionalProperties: false
|
|
@@ -51,7 +56,7 @@ function getRunJavaScriptTool(chat) {
|
|
|
51
56
|
if (chat) return RUN_JAVASCRIPT_TOOL;
|
|
52
57
|
return {
|
|
53
58
|
...RUN_JAVASCRIPT_TOOL,
|
|
54
|
-
description: `${WORKER_RESPONSE_INSTRUCTION}
|
|
59
|
+
description: `${WORKER_RESPONSE_INSTRUCTION} ${EXECUTION_DESCRIPTION}`
|
|
55
60
|
};
|
|
56
61
|
}
|
|
57
62
|
/** Validate the entire response before any delivery or business action begins. */
|
|
@@ -88,6 +93,118 @@ function validateNativeToolCalls(calls) {
|
|
|
88
93
|
};
|
|
89
94
|
}
|
|
90
95
|
//#endregion
|
|
96
|
+
//#region src/prompts/native-examples.ts
|
|
97
|
+
/** Documentation only. These strings never become session messages or native tool calls. */
|
|
98
|
+
const call = (code) => `<native_tool_call name="run_javascript">
|
|
99
|
+
<arguments>
|
|
100
|
+
${JSON.stringify({ code }, null, 2)}
|
|
101
|
+
</arguments>
|
|
102
|
+
</native_tool_call>`;
|
|
103
|
+
const turn = (content) => `<assistant_turn>
|
|
104
|
+
${content}
|
|
105
|
+
</assistant_turn>`;
|
|
106
|
+
const example = (name, content) => `<example name="${name}">
|
|
107
|
+
${content}
|
|
108
|
+
</example>`;
|
|
109
|
+
/** Static examples teach syntax without guessing inputs for arbitrary application schemas. */
|
|
110
|
+
function getNativeExamples(capabilities) {
|
|
111
|
+
const examples = [];
|
|
112
|
+
if (capabilities.chat) examples.push(example("answer_without_actions", `<situation>
|
|
113
|
+
The user asks for the opening time. The task instructions already say the shop opens at 9 AM. No action is needed.
|
|
114
|
+
</situation>
|
|
115
|
+
${turn(`<assistant_text>
|
|
116
|
+
We open at 9 AM.
|
|
117
|
+
</assistant_text>`)}
|
|
118
|
+
<explanation>
|
|
119
|
+
This is an ordinary assistant reply, with no native tool call. Its end gives the turn back to the user.
|
|
120
|
+
</explanation>`));
|
|
121
|
+
examples.push(example("execute_and_inspect", `<situation>
|
|
122
|
+
Compute the total of 17 and 25, and inspect the computed value before continuing.
|
|
123
|
+
</situation>
|
|
124
|
+
${turn(call("const total = 17 + 25; return inspect(total);"))}
|
|
125
|
+
<tool_result>
|
|
126
|
+
42
|
|
127
|
+
</tool_result>
|
|
128
|
+
<explanation>
|
|
129
|
+
The code property contains executable JavaScript. Returning inspect(total) makes the result visible in the next response. The variable total is retained; do not recompute it just to read it.
|
|
130
|
+
</explanation>`));
|
|
131
|
+
if (capabilities.tools) {
|
|
132
|
+
examples.push(example("search_then_use_the_result", `<fictional_api>
|
|
133
|
+
exampleSearch(query: string): Promise<string>
|
|
134
|
+
</fictional_api>
|
|
135
|
+
<situation>
|
|
136
|
+
Find whether blue mugs are available. Availability must come from a search.
|
|
137
|
+
</situation>
|
|
138
|
+
${turn(call("const products = await exampleSearch('blue mugs'); return inspect(products);"))}
|
|
139
|
+
<tool_result>
|
|
140
|
+
Blue mugs are available. Price: $12 each.
|
|
141
|
+
</tool_result>
|
|
142
|
+
${capabilities.chat ? turn(`<assistant_text>
|
|
143
|
+
Blue mugs are available for $12 each.
|
|
144
|
+
</assistant_text>`) : `<next_step>
|
|
145
|
+
Use the inspected facts and retained products variable to continue the task. Do not repeat the successful search.
|
|
146
|
+
</next_step>`}
|
|
147
|
+
<explanation>
|
|
148
|
+
The search phrase is a string argument to the business function. It is not executable JavaScript by itself. Await the function, then return inspect with its actual result. Do not write an answer before seeing that result.
|
|
149
|
+
</explanation>`));
|
|
150
|
+
examples.push(example("object_arguments_and_independent_calls", `<fictional_api>
|
|
151
|
+
exampleReadStock(input: { itemId: string }): Promise<{ count: number }>
|
|
152
|
+
exampleReadPrice(input: { itemId: string }): Promise<{ amount: number }>
|
|
153
|
+
</fictional_api>
|
|
154
|
+
<situation>
|
|
155
|
+
Read stock and price for the same item. Neither read depends on the other.
|
|
156
|
+
</situation>
|
|
157
|
+
${turn(call("const [stock, price] = await Promise.all([exampleReadStock({ itemId: 'MUG-7' }), exampleReadPrice({ itemId: 'MUG-7' })]); return inspect({ stock, price });"))}
|
|
158
|
+
<explanation>
|
|
159
|
+
These functions accept objects, unlike exampleSearch which accepts a string. Match the declared arguments. Both calls are awaited inside one program and their results are inspected together.
|
|
160
|
+
</explanation>`));
|
|
161
|
+
examples.push(example("repair_a_search_phrase_submitted_as_code", `<fictional_api>
|
|
162
|
+
exampleSearch(query: string): Promise<string>
|
|
163
|
+
</fictional_api>
|
|
164
|
+
<situation>
|
|
165
|
+
The user asked about red mugs. The previous attempt submitted the words red mugs as JavaScript and failed to parse. No business tool ran.
|
|
166
|
+
</situation>
|
|
167
|
+
${turn(call("const matches = await exampleSearch('red mugs'); return inspect(matches);"))}
|
|
168
|
+
<explanation>
|
|
169
|
+
Repair the program by calling the actual business function. Do not resubmit the bare search phrase, quote the phrase as the entire program, or answer without retrieving the facts.
|
|
170
|
+
</explanation>`));
|
|
171
|
+
}
|
|
172
|
+
if (capabilities.exits) examples.push(example("complete_with_a_typed_result", `<fictional_api>
|
|
173
|
+
exit(name: "example_complete", payload: { total: number }): never
|
|
174
|
+
</fictional_api>
|
|
175
|
+
<situation>
|
|
176
|
+
The required work is complete. The computed total, already inspected, is 42. Complete through the declared example_complete outcome.
|
|
177
|
+
</situation>
|
|
178
|
+
${turn(call("return exit('example_complete', { total: 42 });"))}
|
|
179
|
+
<explanation>
|
|
180
|
+
The first argument is the outcome name string. The second argument is its payload, matching the declaration. Do not pass one object containing name and payload. Do not submit the outcome name alone as code or report completion as prose.
|
|
181
|
+
</explanation>`));
|
|
182
|
+
if (capabilities.chat && capabilities.components && capabilities.listen) examples.push(example("text_and_buttons_in_the_same_response", `<fictional_api>
|
|
183
|
+
chat.exampleChoices(props: { options: Array<{ label: string, value: string }> }): void
|
|
184
|
+
</fictional_api>
|
|
185
|
+
<situation>
|
|
186
|
+
The user requests an introduction in a text message, followed by buttons to shop or track an order.
|
|
187
|
+
</situation>
|
|
188
|
+
${turn(`<assistant_text>
|
|
189
|
+
Hi, I'm your shopping assistant. I can help you shop or track an order.
|
|
190
|
+
</assistant_text>
|
|
191
|
+
${call("chat.exampleChoices({ options: [{ label: 'Shop', value: 'shop' }, { label: 'Track order', value: 'track' }] }); return exit('listen');")}`)}
|
|
192
|
+
<explanation>
|
|
193
|
+
Both the assistant text and the native tool call belong to ONE response. The text introduces the assistant; the program sends the buttons. Buttons alone would omit the requested text message. Text alone would omit the buttons. The component returns void and does not need inspection.
|
|
194
|
+
</explanation>`));
|
|
195
|
+
return [
|
|
196
|
+
"<examples>",
|
|
197
|
+
"These are hypothetical demonstrations, NOT live conversation, task history, or evidence. Do not perform their tasks or copy their facts.",
|
|
198
|
+
"Names beginning with example are fictional and unavailable. Use the actual names and signatures under JavaScript API for your task.",
|
|
199
|
+
"The XML tags are documentation boundaries only. NEVER emit these tags, a serialized assistant_turn, or a textual native_tool_call. Use your actual native tool-calling interface.",
|
|
200
|
+
"Each assistant_turn shows one response. arguments contains the exact JSON shape to send to run_javascript; its code string is JavaScript. tool_result illustrates what the runtime reports afterward; never generate it yourself.",
|
|
201
|
+
capabilities.chat ? "assistant_text means ordinary user-facing text, outside tool arguments. When text and a call appear in the same assistant_turn, produce both in that response. Follow the real task’s language, style and silence requirements." : "This is worker mode. Every demonstrated assistant_turn contains a native tool call and NO assistant text. Continue using calls after inspection as well.",
|
|
202
|
+
...examples,
|
|
203
|
+
"Apply the demonstrated syntax to your actual task. The real API and task instructions are authoritative; fictional functions and facts are not available.",
|
|
204
|
+
"</examples>"
|
|
205
|
+
].join("\n\n");
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
91
208
|
//#region src/prompts/native.ts
|
|
92
209
|
var native_exports = /* @__PURE__ */ __exportAll({ getNativeSystemMessage: () => getNativeSystemMessage });
|
|
93
210
|
const runJavaScriptSyntax = [
|
|
@@ -122,7 +239,7 @@ function runtimeRules(props, chat) {
|
|
|
122
239
|
}
|
|
123
240
|
rules.push("Execution may overlap the remaining response stream. The runtime waits for the stream, code, and queued message deliveries before the next response.", "# Memory", "Declare retained variables at top level with const or let. Bare assignment only updates a variable already declared in this program or listed in Memory. Named variables survive transcript compaction; assignment age records when they were set, not when the underlying data was fetched.", "Object properties are immutable snapshots. Replace a writable property completely, such as account.profile = { ...account.profile, age: 42 }; nested edits are forbidden and replacements are schema-validated.", "$return is the latest successful inspection result. $iterations is read-only retained history, newest first: [0] is the last settled iteration and [1] the preceding one. The current execution is not included. Entries without results still occupy indexes; check hasResult. Compaction prunes automatic results. Assign useful data to named variables to retain it independently.", "# Recovery", "Execution reports identify completed actions, inspected values, memory changes, and errors. Reuse preserved variables and completed actions; retry only failed work. Build completion payloads from those values, not by calling successful tools again. An inspection has already run the recorded calls; it is not a dry run.", "An operational error does not by itself finish the task. Inspect the actual error, repair its cause when safe and authorized, then retry. Unchanged retries do not establish that recovery is exhausted. If another response must diagnose the error, return inspect({ errors, completed }) or let the error reach the runtime. Honor task instructions defining terminal failure outcomes.");
|
|
124
241
|
if (hasExits) rules.push("Use a failure exit only when recovery is unavailable, unsafe, forbidden, its budget is exhausted, or task instructions make the failure terminal. Do not select failure in advance for an unseen error. Do not turn an unexpected exception or rejected Promise.allSettled entry directly into failure completion: first expose it with inspect or let it reach the runtime, then diagnose the actual cause and available recovery tools. Explicit task instructions may define an error as terminal.");
|
|
125
|
-
rules.push("A
|
|
242
|
+
rules.push("A tool may request forced inspection through ThinkSignal. The tool succeeded and its context is returned to JavaScript. Other calls and assignments continue normally. At the end of the program, forced inspection takes precedence over completion: review the reported results as an inspect() call, then continue from retained values without repeating successful calls.", "Respect tool-attempt limits separately from the model-response budget. An empty successful inspection result is not a failure.");
|
|
126
243
|
return rules.join("\n\n");
|
|
127
244
|
}
|
|
128
245
|
async function describeRuntimeAPI(props, chat) {
|
|
@@ -152,8 +269,16 @@ async function getNativeSystemMessage(props) {
|
|
|
152
269
|
const protocol = [
|
|
153
270
|
runJavaScriptSyntax,
|
|
154
271
|
runtimeRules(props, chat),
|
|
155
|
-
...chat ? ["# Assistant response", (props.response ?? resolveResponse()).instructions] : []
|
|
272
|
+
...chat ? ["# Assistant response", (props.response ?? resolveResponse()).instructions] : [],
|
|
273
|
+
getNativeExamples({
|
|
274
|
+
chat,
|
|
275
|
+
tools: declarations.length > 0,
|
|
276
|
+
components: props.components.size > 0,
|
|
277
|
+
exits: props.exits.length > 0,
|
|
278
|
+
listen: props.exits.some((exit) => exit.name === "listen")
|
|
279
|
+
})
|
|
156
280
|
].join("\n\n");
|
|
281
|
+
const delivery = chat ? ["# Assistant text delivery", "When answering, write only the final user-facing answer, once. Do not output private thinking, drafts, or thinking tags. This governs assistant text only: still call required tools, send requested components, and provide requested progress updates. Preserve literal text or code the user explicitly asks you to reproduce."].join("\n\n") : "";
|
|
157
282
|
return {
|
|
158
283
|
message: {
|
|
159
284
|
role: "system",
|
|
@@ -163,13 +288,14 @@ async function getNativeSystemMessage(props) {
|
|
|
163
288
|
"These TypeScript declarations describe functions inside run_javascript. Object properties, their types, values, and read/write rules are listed in Memory.",
|
|
164
289
|
tools,
|
|
165
290
|
"# Task instructions",
|
|
166
|
-
instructions
|
|
291
|
+
instructions,
|
|
292
|
+
...delivery ? [delivery] : []
|
|
167
293
|
].join("\n\n")
|
|
168
294
|
},
|
|
169
295
|
parts: {
|
|
170
296
|
instructions,
|
|
171
297
|
tools,
|
|
172
|
-
protocol
|
|
298
|
+
protocol: [protocol, delivery].filter(Boolean).join("\n\n")
|
|
173
299
|
}
|
|
174
300
|
};
|
|
175
301
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_utils = require("./utils-CTlsXvdj.cjs");
|
|
2
|
-
const require_errors = require("./errors-
|
|
3
|
-
const require_typings = require("./typings-
|
|
2
|
+
const require_errors = require("./errors-C6ppQUZX.cjs");
|
|
3
|
+
const require_typings = require("./typings-BA_XxAcY.cjs");
|
|
4
4
|
//#region src/chat/response.ts
|
|
5
5
|
const presets = {
|
|
6
6
|
markdown: { instructions: "Write natural Markdown directly in the assistant response. Use paragraphs, lists, links, and code blocks where useful. Do not wrap the entire response in JSON or a Markdown fence." },
|
|
@@ -32,15 +32,20 @@ function resolveResponse(response = "markdown") {
|
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/runtime/native-tools.ts
|
|
34
34
|
const WORKER_RESPONSE_INSTRUCTION = "You are running in worker mode. Respond only with a run_javascript tool call. Keep assistant text empty: do not send messages, preambles, progress updates, explanations, acknowledgements such as \"Done\", Markdown, or JSON outside the tool call. This applies before and after tools, during recovery, and when completing the task.";
|
|
35
|
+
const EXECUTION_DESCRIPTION = "Execute a JavaScript program in the sandbox. This is the only native tool; business functions are called INSIDE its code, using their documented signatures. It is not a search engine: never submit search terms, user questions, answers, or business tool names as code. Await business calls, then return inspect(value) to read their results, or return exit(name, payload) to select a registered outcome. See \"run_javascript syntax\" and the examples.";
|
|
35
36
|
const RUN_JAVASCRIPT_TOOL = {
|
|
36
37
|
name: "run_javascript",
|
|
37
|
-
description:
|
|
38
|
+
description: `${EXECUTION_DESCRIPTION} For a requested text message plus an action or component, include the assistant text AND this tool call in the same response. A plain assistant reply needs no tool call when no action remains.`,
|
|
38
39
|
parameters: {
|
|
39
40
|
type: "object",
|
|
40
41
|
properties: { code: {
|
|
41
42
|
type: "string",
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
description: [
|
|
44
|
+
"The body of an async JavaScript program. Top-level await and return are supported. No Markdown fences, XML wrappers, imports, or TypeScript annotations.",
|
|
45
|
+
"Call business functions using the actual API declarations. A string parameter takes a string; an object parameter takes its documented fields. Do not put a query or reply here instead of a program.",
|
|
46
|
+
"<example purpose=\"JavaScript syntax only\">const total = 17 + 25; return inspect(total);</example>",
|
|
47
|
+
"The example tags are documentation only. The code value must contain only executable JavaScript. End with return inspect(value), or return exit(\"registered_name\", payload) with the actual outcome name and required payload. These are JavaScript functions, not separate native tools."
|
|
48
|
+
].join("\n\n")
|
|
44
49
|
} },
|
|
45
50
|
required: ["code"],
|
|
46
51
|
additionalProperties: false
|
|
@@ -51,7 +56,7 @@ function getRunJavaScriptTool(chat) {
|
|
|
51
56
|
if (chat) return RUN_JAVASCRIPT_TOOL;
|
|
52
57
|
return {
|
|
53
58
|
...RUN_JAVASCRIPT_TOOL,
|
|
54
|
-
description: `${WORKER_RESPONSE_INSTRUCTION}
|
|
59
|
+
description: `${WORKER_RESPONSE_INSTRUCTION} ${EXECUTION_DESCRIPTION}`
|
|
55
60
|
};
|
|
56
61
|
}
|
|
57
62
|
/** Validate the entire response before any delivery or business action begins. */
|
|
@@ -88,6 +93,118 @@ function validateNativeToolCalls(calls) {
|
|
|
88
93
|
};
|
|
89
94
|
}
|
|
90
95
|
//#endregion
|
|
96
|
+
//#region src/prompts/native-examples.ts
|
|
97
|
+
/** Documentation only. These strings never become session messages or native tool calls. */
|
|
98
|
+
const call = (code) => `<native_tool_call name="run_javascript">
|
|
99
|
+
<arguments>
|
|
100
|
+
${JSON.stringify({ code }, null, 2)}
|
|
101
|
+
</arguments>
|
|
102
|
+
</native_tool_call>`;
|
|
103
|
+
const turn = (content) => `<assistant_turn>
|
|
104
|
+
${content}
|
|
105
|
+
</assistant_turn>`;
|
|
106
|
+
const example = (name, content) => `<example name="${name}">
|
|
107
|
+
${content}
|
|
108
|
+
</example>`;
|
|
109
|
+
/** Static examples teach syntax without guessing inputs for arbitrary application schemas. */
|
|
110
|
+
function getNativeExamples(capabilities) {
|
|
111
|
+
const examples = [];
|
|
112
|
+
if (capabilities.chat) examples.push(example("answer_without_actions", `<situation>
|
|
113
|
+
The user asks for the opening time. The task instructions already say the shop opens at 9 AM. No action is needed.
|
|
114
|
+
</situation>
|
|
115
|
+
${turn(`<assistant_text>
|
|
116
|
+
We open at 9 AM.
|
|
117
|
+
</assistant_text>`)}
|
|
118
|
+
<explanation>
|
|
119
|
+
This is an ordinary assistant reply, with no native tool call. Its end gives the turn back to the user.
|
|
120
|
+
</explanation>`));
|
|
121
|
+
examples.push(example("execute_and_inspect", `<situation>
|
|
122
|
+
Compute the total of 17 and 25, and inspect the computed value before continuing.
|
|
123
|
+
</situation>
|
|
124
|
+
${turn(call("const total = 17 + 25; return inspect(total);"))}
|
|
125
|
+
<tool_result>
|
|
126
|
+
42
|
|
127
|
+
</tool_result>
|
|
128
|
+
<explanation>
|
|
129
|
+
The code property contains executable JavaScript. Returning inspect(total) makes the result visible in the next response. The variable total is retained; do not recompute it just to read it.
|
|
130
|
+
</explanation>`));
|
|
131
|
+
if (capabilities.tools) {
|
|
132
|
+
examples.push(example("search_then_use_the_result", `<fictional_api>
|
|
133
|
+
exampleSearch(query: string): Promise<string>
|
|
134
|
+
</fictional_api>
|
|
135
|
+
<situation>
|
|
136
|
+
Find whether blue mugs are available. Availability must come from a search.
|
|
137
|
+
</situation>
|
|
138
|
+
${turn(call("const products = await exampleSearch('blue mugs'); return inspect(products);"))}
|
|
139
|
+
<tool_result>
|
|
140
|
+
Blue mugs are available. Price: $12 each.
|
|
141
|
+
</tool_result>
|
|
142
|
+
${capabilities.chat ? turn(`<assistant_text>
|
|
143
|
+
Blue mugs are available for $12 each.
|
|
144
|
+
</assistant_text>`) : `<next_step>
|
|
145
|
+
Use the inspected facts and retained products variable to continue the task. Do not repeat the successful search.
|
|
146
|
+
</next_step>`}
|
|
147
|
+
<explanation>
|
|
148
|
+
The search phrase is a string argument to the business function. It is not executable JavaScript by itself. Await the function, then return inspect with its actual result. Do not write an answer before seeing that result.
|
|
149
|
+
</explanation>`));
|
|
150
|
+
examples.push(example("object_arguments_and_independent_calls", `<fictional_api>
|
|
151
|
+
exampleReadStock(input: { itemId: string }): Promise<{ count: number }>
|
|
152
|
+
exampleReadPrice(input: { itemId: string }): Promise<{ amount: number }>
|
|
153
|
+
</fictional_api>
|
|
154
|
+
<situation>
|
|
155
|
+
Read stock and price for the same item. Neither read depends on the other.
|
|
156
|
+
</situation>
|
|
157
|
+
${turn(call("const [stock, price] = await Promise.all([exampleReadStock({ itemId: 'MUG-7' }), exampleReadPrice({ itemId: 'MUG-7' })]); return inspect({ stock, price });"))}
|
|
158
|
+
<explanation>
|
|
159
|
+
These functions accept objects, unlike exampleSearch which accepts a string. Match the declared arguments. Both calls are awaited inside one program and their results are inspected together.
|
|
160
|
+
</explanation>`));
|
|
161
|
+
examples.push(example("repair_a_search_phrase_submitted_as_code", `<fictional_api>
|
|
162
|
+
exampleSearch(query: string): Promise<string>
|
|
163
|
+
</fictional_api>
|
|
164
|
+
<situation>
|
|
165
|
+
The user asked about red mugs. The previous attempt submitted the words red mugs as JavaScript and failed to parse. No business tool ran.
|
|
166
|
+
</situation>
|
|
167
|
+
${turn(call("const matches = await exampleSearch('red mugs'); return inspect(matches);"))}
|
|
168
|
+
<explanation>
|
|
169
|
+
Repair the program by calling the actual business function. Do not resubmit the bare search phrase, quote the phrase as the entire program, or answer without retrieving the facts.
|
|
170
|
+
</explanation>`));
|
|
171
|
+
}
|
|
172
|
+
if (capabilities.exits) examples.push(example("complete_with_a_typed_result", `<fictional_api>
|
|
173
|
+
exit(name: "example_complete", payload: { total: number }): never
|
|
174
|
+
</fictional_api>
|
|
175
|
+
<situation>
|
|
176
|
+
The required work is complete. The computed total, already inspected, is 42. Complete through the declared example_complete outcome.
|
|
177
|
+
</situation>
|
|
178
|
+
${turn(call("return exit('example_complete', { total: 42 });"))}
|
|
179
|
+
<explanation>
|
|
180
|
+
The first argument is the outcome name string. The second argument is its payload, matching the declaration. Do not pass one object containing name and payload. Do not submit the outcome name alone as code or report completion as prose.
|
|
181
|
+
</explanation>`));
|
|
182
|
+
if (capabilities.chat && capabilities.components && capabilities.listen) examples.push(example("text_and_buttons_in_the_same_response", `<fictional_api>
|
|
183
|
+
chat.exampleChoices(props: { options: Array<{ label: string, value: string }> }): void
|
|
184
|
+
</fictional_api>
|
|
185
|
+
<situation>
|
|
186
|
+
The user requests an introduction in a text message, followed by buttons to shop or track an order.
|
|
187
|
+
</situation>
|
|
188
|
+
${turn(`<assistant_text>
|
|
189
|
+
Hi, I'm your shopping assistant. I can help you shop or track an order.
|
|
190
|
+
</assistant_text>
|
|
191
|
+
${call("chat.exampleChoices({ options: [{ label: 'Shop', value: 'shop' }, { label: 'Track order', value: 'track' }] }); return exit('listen');")}`)}
|
|
192
|
+
<explanation>
|
|
193
|
+
Both the assistant text and the native tool call belong to ONE response. The text introduces the assistant; the program sends the buttons. Buttons alone would omit the requested text message. Text alone would omit the buttons. The component returns void and does not need inspection.
|
|
194
|
+
</explanation>`));
|
|
195
|
+
return [
|
|
196
|
+
"<examples>",
|
|
197
|
+
"These are hypothetical demonstrations, NOT live conversation, task history, or evidence. Do not perform their tasks or copy their facts.",
|
|
198
|
+
"Names beginning with example are fictional and unavailable. Use the actual names and signatures under JavaScript API for your task.",
|
|
199
|
+
"The XML tags are documentation boundaries only. NEVER emit these tags, a serialized assistant_turn, or a textual native_tool_call. Use your actual native tool-calling interface.",
|
|
200
|
+
"Each assistant_turn shows one response. arguments contains the exact JSON shape to send to run_javascript; its code string is JavaScript. tool_result illustrates what the runtime reports afterward; never generate it yourself.",
|
|
201
|
+
capabilities.chat ? "assistant_text means ordinary user-facing text, outside tool arguments. When text and a call appear in the same assistant_turn, produce both in that response. Follow the real task’s language, style and silence requirements." : "This is worker mode. Every demonstrated assistant_turn contains a native tool call and NO assistant text. Continue using calls after inspection as well.",
|
|
202
|
+
...examples,
|
|
203
|
+
"Apply the demonstrated syntax to your actual task. The real API and task instructions are authoritative; fictional functions and facts are not available.",
|
|
204
|
+
"</examples>"
|
|
205
|
+
].join("\n\n");
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
91
208
|
//#region src/prompts/native.ts
|
|
92
209
|
var native_exports = /* @__PURE__ */ require_utils.__exportAll({ getNativeSystemMessage: () => getNativeSystemMessage });
|
|
93
210
|
const runJavaScriptSyntax = [
|
|
@@ -122,7 +239,7 @@ function runtimeRules(props, chat) {
|
|
|
122
239
|
}
|
|
123
240
|
rules.push("Execution may overlap the remaining response stream. The runtime waits for the stream, code, and queued message deliveries before the next response.", "# Memory", "Declare retained variables at top level with const or let. Bare assignment only updates a variable already declared in this program or listed in Memory. Named variables survive transcript compaction; assignment age records when they were set, not when the underlying data was fetched.", "Object properties are immutable snapshots. Replace a writable property completely, such as account.profile = { ...account.profile, age: 42 }; nested edits are forbidden and replacements are schema-validated.", "$return is the latest successful inspection result. $iterations is read-only retained history, newest first: [0] is the last settled iteration and [1] the preceding one. The current execution is not included. Entries without results still occupy indexes; check hasResult. Compaction prunes automatic results. Assign useful data to named variables to retain it independently.", "# Recovery", "Execution reports identify completed actions, inspected values, memory changes, and errors. Reuse preserved variables and completed actions; retry only failed work. Build completion payloads from those values, not by calling successful tools again. An inspection has already run the recorded calls; it is not a dry run.", "An operational error does not by itself finish the task. Inspect the actual error, repair its cause when safe and authorized, then retry. Unchanged retries do not establish that recovery is exhausted. If another response must diagnose the error, return inspect({ errors, completed }) or let the error reach the runtime. Honor task instructions defining terminal failure outcomes.");
|
|
124
241
|
if (hasExits) rules.push("Use a failure exit only when recovery is unavailable, unsafe, forbidden, its budget is exhausted, or task instructions make the failure terminal. Do not select failure in advance for an unseen error. Do not turn an unexpected exception or rejected Promise.allSettled entry directly into failure completion: first expose it with inspect or let it reach the runtime, then diagnose the actual cause and available recovery tools. Explicit task instructions may define an error as terminal.");
|
|
125
|
-
rules.push("A
|
|
242
|
+
rules.push("A tool may request forced inspection through ThinkSignal. The tool succeeded and its context is returned to JavaScript. Other calls and assignments continue normally. At the end of the program, forced inspection takes precedence over completion: review the reported results as an inspect() call, then continue from retained values without repeating successful calls.", "Respect tool-attempt limits separately from the model-response budget. An empty successful inspection result is not a failure.");
|
|
126
243
|
return rules.join("\n\n");
|
|
127
244
|
}
|
|
128
245
|
async function describeRuntimeAPI(props, chat) {
|
|
@@ -152,8 +269,16 @@ async function getNativeSystemMessage(props) {
|
|
|
152
269
|
const protocol = [
|
|
153
270
|
runJavaScriptSyntax,
|
|
154
271
|
runtimeRules(props, chat),
|
|
155
|
-
...chat ? ["# Assistant response", (props.response ?? resolveResponse()).instructions] : []
|
|
272
|
+
...chat ? ["# Assistant response", (props.response ?? resolveResponse()).instructions] : [],
|
|
273
|
+
getNativeExamples({
|
|
274
|
+
chat,
|
|
275
|
+
tools: declarations.length > 0,
|
|
276
|
+
components: props.components.size > 0,
|
|
277
|
+
exits: props.exits.length > 0,
|
|
278
|
+
listen: props.exits.some((exit) => exit.name === "listen")
|
|
279
|
+
})
|
|
156
280
|
].join("\n\n");
|
|
281
|
+
const delivery = chat ? ["# Assistant text delivery", "When answering, write only the final user-facing answer, once. Do not output private thinking, drafts, or thinking tags. This governs assistant text only: still call required tools, send requested components, and provide requested progress updates. Preserve literal text or code the user explicitly asks you to reproduce."].join("\n\n") : "";
|
|
157
282
|
return {
|
|
158
283
|
message: {
|
|
159
284
|
role: "system",
|
|
@@ -163,13 +288,14 @@ async function getNativeSystemMessage(props) {
|
|
|
163
288
|
"These TypeScript declarations describe functions inside run_javascript. Object properties, their types, values, and read/write rules are listed in Memory.",
|
|
164
289
|
tools,
|
|
165
290
|
"# Task instructions",
|
|
166
|
-
instructions
|
|
291
|
+
instructions,
|
|
292
|
+
...delivery ? [delivery] : []
|
|
167
293
|
].join("\n\n")
|
|
168
294
|
},
|
|
169
295
|
parts: {
|
|
170
296
|
instructions,
|
|
171
297
|
tools,
|
|
172
|
-
protocol
|
|
298
|
+
protocol: [protocol, delivery].filter(Boolean).join("\n\n")
|
|
173
299
|
}
|
|
174
300
|
};
|
|
175
301
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Capabilities = {
|
|
2
|
+
chat: boolean;
|
|
3
|
+
tools: boolean;
|
|
4
|
+
components: boolean;
|
|
5
|
+
exits: boolean;
|
|
6
|
+
listen: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Static examples teach syntax without guessing inputs for arbitrary application schemas. */
|
|
9
|
+
export declare function getNativeExamples(capabilities: Capabilities): string;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_utils = require("./utils-CTlsXvdj.cjs");
|
|
2
|
-
const require_errors = require("./errors-
|
|
3
|
-
const require_schema = require("./schema-
|
|
4
|
-
const require_truncate = require("./truncate-
|
|
5
|
-
const require_typings = require("./typings-
|
|
2
|
+
const require_errors = require("./errors-C6ppQUZX.cjs");
|
|
3
|
+
const require_schema = require("./schema-CXlnbb3n.cjs");
|
|
4
|
+
const require_truncate = require("./truncate-uomAMGPs.cjs");
|
|
5
|
+
const require_typings = require("./typings-BA_XxAcY.cjs");
|
|
6
6
|
//#region src/inspect.ts
|
|
7
7
|
const SUBTITLE_LN = "--------------";
|
|
8
8
|
const TRUNCATION_MARKER = "[truncated]";
|
|
@@ -401,7 +401,7 @@ function createInspector(onInspect) {
|
|
|
401
401
|
if (onInspect) try {
|
|
402
402
|
const budget = resolveInspectionBudget(value, formatting);
|
|
403
403
|
const output = onInspect(Object.freeze({
|
|
404
|
-
value:
|
|
404
|
+
value: snapshotInspectionValue(value),
|
|
405
405
|
purpose: options.purpose,
|
|
406
406
|
maxTokens: budget.tokens,
|
|
407
407
|
preserve: budget.preserve,
|
|
@@ -413,12 +413,13 @@ function createInspector(onInspect) {
|
|
|
413
413
|
return inspect(value, void 0, formatting);
|
|
414
414
|
};
|
|
415
415
|
}
|
|
416
|
-
|
|
416
|
+
/** Isolate evidence from subsequent guest mutations without invoking getters. */
|
|
417
|
+
function snapshotInspectionValue(value, copies = /* @__PURE__ */ new WeakMap()) {
|
|
417
418
|
if (!value || typeof value !== "object") return typeof value === "function" ? "[Function]" : value;
|
|
418
419
|
if (copies.has(value)) return copies.get(value);
|
|
419
420
|
if (require_truncate.isTruncated(value)) {
|
|
420
421
|
copies.set(value, "[Circular]");
|
|
421
|
-
const copy =
|
|
422
|
+
const copy = snapshotInspectionValue(value.value, copies);
|
|
422
423
|
copies.set(value, copy);
|
|
423
424
|
return copy;
|
|
424
425
|
}
|
|
@@ -429,7 +430,7 @@ function snapshot(value, copies = /* @__PURE__ */ new WeakMap()) {
|
|
|
429
430
|
if (Array.isArray(value) && key === "length") continue;
|
|
430
431
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
431
432
|
if (descriptor) Object.defineProperty(copy, key, {
|
|
432
|
-
value: "value" in descriptor ?
|
|
433
|
+
value: "value" in descriptor ? snapshotInspectionValue(descriptor.value, copies) : "[Getter]",
|
|
433
434
|
enumerable: descriptor.enumerable
|
|
434
435
|
});
|
|
435
436
|
}
|
|
@@ -1071,3 +1072,9 @@ Object.defineProperty(exports, "resolveInspectionBudget", {
|
|
|
1071
1072
|
return resolveInspectionBudget;
|
|
1072
1073
|
}
|
|
1073
1074
|
});
|
|
1075
|
+
Object.defineProperty(exports, "snapshotInspectionValue", {
|
|
1076
|
+
enumerable: true,
|
|
1077
|
+
get: function() {
|
|
1078
|
+
return snapshotInspectionValue;
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as getTokenizer } from "./utils-BOFzb8Ok.js";
|
|
2
|
-
import { A as MemoryValueError,
|
|
3
|
-
import { i as toModelSchema } from "./schema-
|
|
4
|
-
import { n as isTruncated } from "./truncate-
|
|
5
|
-
import { t as getTypings } from "./typings-
|
|
2
|
+
import { A as MemoryValueError, P as ReservedIdentifierError, b as InvalidConfigurationError, k as MemoryCapacityError, o as AssignmentError } from "./errors-Crk5P8jo.js";
|
|
3
|
+
import { i as toModelSchema } from "./schema-GE4ISPCR.js";
|
|
4
|
+
import { n as isTruncated } from "./truncate-BEKbdo3t.js";
|
|
5
|
+
import { t as getTypings } from "./typings-BEVDvtuk.js";
|
|
6
6
|
//#region src/inspect.ts
|
|
7
7
|
const SUBTITLE_LN = "--------------";
|
|
8
8
|
const TRUNCATION_MARKER = "[truncated]";
|
|
@@ -401,7 +401,7 @@ function createInspector(onInspect) {
|
|
|
401
401
|
if (onInspect) try {
|
|
402
402
|
const budget = resolveInspectionBudget(value, formatting);
|
|
403
403
|
const output = onInspect(Object.freeze({
|
|
404
|
-
value:
|
|
404
|
+
value: snapshotInspectionValue(value),
|
|
405
405
|
purpose: options.purpose,
|
|
406
406
|
maxTokens: budget.tokens,
|
|
407
407
|
preserve: budget.preserve,
|
|
@@ -413,12 +413,13 @@ function createInspector(onInspect) {
|
|
|
413
413
|
return inspect(value, void 0, formatting);
|
|
414
414
|
};
|
|
415
415
|
}
|
|
416
|
-
|
|
416
|
+
/** Isolate evidence from subsequent guest mutations without invoking getters. */
|
|
417
|
+
function snapshotInspectionValue(value, copies = /* @__PURE__ */ new WeakMap()) {
|
|
417
418
|
if (!value || typeof value !== "object") return typeof value === "function" ? "[Function]" : value;
|
|
418
419
|
if (copies.has(value)) return copies.get(value);
|
|
419
420
|
if (isTruncated(value)) {
|
|
420
421
|
copies.set(value, "[Circular]");
|
|
421
|
-
const copy =
|
|
422
|
+
const copy = snapshotInspectionValue(value.value, copies);
|
|
422
423
|
copies.set(value, copy);
|
|
423
424
|
return copy;
|
|
424
425
|
}
|
|
@@ -429,7 +430,7 @@ function snapshot(value, copies = /* @__PURE__ */ new WeakMap()) {
|
|
|
429
430
|
if (Array.isArray(value) && key === "length") continue;
|
|
430
431
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
431
432
|
if (descriptor) Object.defineProperty(copy, key, {
|
|
432
|
-
value: "value" in descriptor ?
|
|
433
|
+
value: "value" in descriptor ? snapshotInspectionValue(descriptor.value, copies) : "[Getter]",
|
|
433
434
|
enumerable: descriptor.enumerable
|
|
434
435
|
});
|
|
435
436
|
}
|
|
@@ -981,4 +982,4 @@ const configureQuickJS = (variant) => {
|
|
|
981
982
|
};
|
|
982
983
|
const getQuickJSVariant = () => _activeVariant;
|
|
983
984
|
//#endregion
|
|
984
|
-
export { cloneMemoryValue as a, freezeMemoryValue as c, TERMINATION_BINDING_NAMES as d, createInspector as f, resolveInspectionBudget as h, renderMemory as i, RESERVED_RUNTIME_NAMES as l,
|
|
985
|
+
export { cloneMemoryValue as a, freezeMemoryValue as c, TERMINATION_BINDING_NAMES as d, createInspector as f, resolveInspectionBudget as g, limitInspectionOutput as h, renderMemory as i, RESERVED_RUNTIME_NAMES as l, inspect as m, getQuickJSVariant as n, decodeMemoryValue as o, snapshotInspectionValue as p, Memory as r, encodeMemoryValue as s, configureQuickJS as t, RUNTIME_BINDING_NAMES as u };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,12 +2,15 @@ import { type InspectionPolicyLookup } from '../inspect.js';
|
|
|
2
2
|
import { type InspectionIdentity, type Inspector } from '../inspection.js';
|
|
3
3
|
import type { MemoryReport } from '../session/memory.js';
|
|
4
4
|
import { type ExecutionActivity } from './execution-activity.js';
|
|
5
|
+
import { type ForcedInspection } from './forced-inspection.js';
|
|
5
6
|
export { renderMessageDeliveries } from './execution-activity.js';
|
|
6
7
|
export type ExecutionOutcome = {
|
|
7
8
|
type: 'inspect';
|
|
8
9
|
value: unknown;
|
|
9
10
|
available: boolean;
|
|
10
11
|
explicit: boolean;
|
|
12
|
+
forcedInspections?: readonly ForcedInspection[];
|
|
13
|
+
downstreamError?: unknown;
|
|
11
14
|
} | {
|
|
12
15
|
type: 'exit';
|
|
13
16
|
name: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type InspectionPolicyLookup } from '../inspect.js';
|
|
2
|
+
import type { InspectionIdentity, Inspector } from '../inspection.js';
|
|
3
|
+
/** A successful business result that must be shown before this turn may complete. */
|
|
4
|
+
export type ForcedInspection = {
|
|
5
|
+
tool: string;
|
|
6
|
+
toolCallId: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
reason: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
/** Keep attribution and content together, using the same display budgets as inspect(). */
|
|
13
|
+
export declare function renderForcedInspection(inspections: readonly ForcedInspection[], inspector: Inspector, identity: InspectionIdentity, maxTokens: number, policies?: InspectionPolicyLookup): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,6 +2,7 @@ import type { ComponentRegistry, RenderedComponent } from '../chat/component.js'
|
|
|
2
2
|
import type { Iteration } from '../context.js';
|
|
3
3
|
import { ThinkSignal } from '../errors.js';
|
|
4
4
|
import type { Exit } from '../exit.js';
|
|
5
|
+
import type { ForcedInspection } from './forced-inspection.js';
|
|
5
6
|
/** A child message keeps its identity from preparation through acknowledged delivery. */
|
|
6
7
|
export type PreparedMessage = {
|
|
7
8
|
id: string;
|
|
@@ -33,6 +34,8 @@ export type JavaScriptApi = {
|
|
|
33
34
|
getTerminalOutcome(): TerminalOutcome | undefined;
|
|
34
35
|
/** The first host interruption closes execution before guest handlers can consume it. */
|
|
35
36
|
getInterruption(): ThinkSignal | undefined;
|
|
37
|
+
requestInspection(inspection: ForcedInspection): void;
|
|
38
|
+
getForcedInspections(): readonly ForcedInspection[];
|
|
36
39
|
throwIfTerminated(): void;
|
|
37
40
|
track<T>(operation: () => Promise<T>): Promise<T>;
|
|
38
41
|
assertOpen(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|