llmz 1.0.2 → 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/dist/{custom-client-Cgt9_0r1.cjs → custom-client-BwRYQ4Oa.cjs} +1 -1
- package/dist/{custom-client-C-WXvLD9.js → custom-client-JcdoH-47.js} +1 -1
- package/dist/{execute-DTTfacsi.cjs → execute-DJBNrA2H.cjs} +15 -3
- package/dist/{execute-CiYvPs5Q.js → execute-DoN74Exa.js} +15 -3
- package/dist/index.cjs +5 -5
- package/dist/index.js +5 -5
- package/dist/index.workerd.js +153 -10
- package/dist/{native-n_718Z-T.js → native-BGW5kBlv.js} +133 -7
- package/dist/{native-0bq5ATZM.cjs → native-sbuzbLbY.cjs} +133 -7
- 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/package.json +2 -1
|
@@ -5,7 +5,7 @@ const require_tool = require("./tool-_wK9hQOb.cjs");
|
|
|
5
5
|
const require_exit = require("./exit-BOtKWPuT.cjs");
|
|
6
6
|
const require_truncate = require("./truncate-uomAMGPs.cjs");
|
|
7
7
|
const require_quickjs_variant = require("./quickjs-variant-21IO97PF.cjs");
|
|
8
|
-
const require_native = require("./native-
|
|
8
|
+
const require_native = require("./native-sbuzbLbY.cjs");
|
|
9
9
|
let _bpinternal_zui = require("@bpinternal/zui");
|
|
10
10
|
let ulid = require("ulid");
|
|
11
11
|
let _botpress_cognitive = require("@botpress/cognitive");
|
|
@@ -5,7 +5,7 @@ import { t as Tool } from "./tool-DstssiAs.js";
|
|
|
5
5
|
import { t as Exit } from "./exit-DMPwCSba.js";
|
|
6
6
|
import { t as DEFAULT_TOOL_RESULT_MAX_TOKENS } from "./truncate-BEKbdo3t.js";
|
|
7
7
|
import { a as cloneMemoryValue, c as freezeMemoryValue, f as createInspector, i as renderMemory, l as RESERVED_RUNTIME_NAMES, o as decodeMemoryValue, r as Memory, s as encodeMemoryValue } from "./quickjs-variant-CtuGagsb.js";
|
|
8
|
-
import { o as resolveResponse, t as getNativeSystemMessage } from "./native-
|
|
8
|
+
import { o as resolveResponse, t as getNativeSystemMessage } from "./native-BGW5kBlv.js";
|
|
9
9
|
import { z } from "@bpinternal/zui";
|
|
10
10
|
import { ulid } from "ulid";
|
|
11
11
|
import { Cognitive } from "@botpress/cognitive";
|
|
@@ -5,8 +5,8 @@ const require_schema = require("./schema-CXlnbb3n.cjs");
|
|
|
5
5
|
const require_truncate = require("./truncate-uomAMGPs.cjs");
|
|
6
6
|
const require_quickjs_variant = require("./quickjs-variant-21IO97PF.cjs");
|
|
7
7
|
const require_typings = require("./typings-BA_XxAcY.cjs");
|
|
8
|
-
const require_custom_client = require("./custom-client-
|
|
9
|
-
const require_native = require("./native-
|
|
8
|
+
const require_custom_client = require("./custom-client-BwRYQ4Oa.cjs");
|
|
9
|
+
const require_native = require("./native-sbuzbLbY.cjs");
|
|
10
10
|
const require_vm = require("./vm-gmekHc0i.cjs");
|
|
11
11
|
let _bpinternal_zui = require("@bpinternal/zui");
|
|
12
12
|
let ulid = require("ulid");
|
|
@@ -415,6 +415,12 @@ function renderChanges(label, changes, name) {
|
|
|
415
415
|
return lines.join("\n");
|
|
416
416
|
}
|
|
417
417
|
//#endregion
|
|
418
|
+
//#region src/prompts/reasoning.ts
|
|
419
|
+
/** Supplement explicit reasoning disablement consistently across providers and fallbacks. */
|
|
420
|
+
function getReasoningHint(reasoningEffort) {
|
|
421
|
+
return reasoningEffort === "none" ? "/no_think" : void 0;
|
|
422
|
+
}
|
|
423
|
+
//#endregion
|
|
418
424
|
//#region src/runtime/generate.ts
|
|
419
425
|
const STREAM_IDLE_TIMEOUT = 18e4;
|
|
420
426
|
const STATIC_TOKEN_PARTS = [
|
|
@@ -511,7 +517,13 @@ async function prepareNativeRequest({ iteration, ctx, cognitive, controller, met
|
|
|
511
517
|
const model = models[0];
|
|
512
518
|
const { limit, output: reserve } = require_custom_client.resolveTokenBudget(models, ctx.maxTokens);
|
|
513
519
|
const tools = [require_native.getRunJavaScriptTool(!!ctx.chat)];
|
|
514
|
-
const
|
|
520
|
+
const systemMessage = structuredClone(iteration.systemMessage);
|
|
521
|
+
const reasoningHint = getReasoningHint(iteration.reasoningEffort);
|
|
522
|
+
if (reasoningHint) systemMessage.content = typeof systemMessage.content === "string" ? `${systemMessage.content}\n\n${reasoningHint}` : [...systemMessage.content ?? [], {
|
|
523
|
+
type: "text",
|
|
524
|
+
text: reasoningHint
|
|
525
|
+
}];
|
|
526
|
+
const system = [systemMessage];
|
|
515
527
|
const budgetInstruction = getBudgetInstruction(ctx, iteration);
|
|
516
528
|
const budget = `\n\nExecution budget: response ${ctx.iterations.length} of ${ctx.loop}. ${budgetInstruction}`;
|
|
517
529
|
const buildMessages = (retainedIds, summary) => {
|
|
@@ -5,8 +5,8 @@ import { n as parseSchemaSync } from "./schema-GE4ISPCR.js";
|
|
|
5
5
|
import { i as unwrapTruncated, n as isTruncated, t as DEFAULT_TOOL_RESULT_MAX_TOKENS } from "./truncate-BEKbdo3t.js";
|
|
6
6
|
import { a as cloneMemoryValue, f as createInspector, g as resolveInspectionBudget, h as limitInspectionOutput, p as snapshotInspectionValue } from "./quickjs-variant-CtuGagsb.js";
|
|
7
7
|
import { n as schemaToTypeScript } from "./typings-BEVDvtuk.js";
|
|
8
|
-
import { a as Context, d as prepareAutoCompaction, f as countNativeRequestTokens, i as SuccessExecutionResult, n as ErrorExecutionResult, p as resolveTokenBudget, s as ListenExit, t as _CustomModelClient, u as stableJSON } from "./custom-client-
|
|
9
|
-
import { a as validateNativeToolCalls, i as getRunJavaScriptTool, r as WORKER_RESPONSE_INSTRUCTION } from "./native-
|
|
8
|
+
import { a as Context, d as prepareAutoCompaction, f as countNativeRequestTokens, i as SuccessExecutionResult, n as ErrorExecutionResult, p as resolveTokenBudget, s as ListenExit, t as _CustomModelClient, u as stableJSON } from "./custom-client-JcdoH-47.js";
|
|
9
|
+
import { a as validateNativeToolCalls, i as getRunJavaScriptTool, r as WORKER_RESPONSE_INSTRUCTION } from "./native-BGW5kBlv.js";
|
|
10
10
|
import { a as VM_TERMINATION, i as VM_PROGRAM_COMPLETE, n as VM_CALL_SITE, o as compile, r as VM_ON_ERROR, runAsyncFunction, t as withMissingMember } from "./vm-C7SfutHn.js";
|
|
11
11
|
import { z } from "@bpinternal/zui";
|
|
12
12
|
import { ulid } from "ulid";
|
|
@@ -414,6 +414,12 @@ function renderChanges(label, changes, name) {
|
|
|
414
414
|
return lines.join("\n");
|
|
415
415
|
}
|
|
416
416
|
//#endregion
|
|
417
|
+
//#region src/prompts/reasoning.ts
|
|
418
|
+
/** Supplement explicit reasoning disablement consistently across providers and fallbacks. */
|
|
419
|
+
function getReasoningHint(reasoningEffort) {
|
|
420
|
+
return reasoningEffort === "none" ? "/no_think" : void 0;
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
417
423
|
//#region src/runtime/generate.ts
|
|
418
424
|
const STREAM_IDLE_TIMEOUT = 18e4;
|
|
419
425
|
const STATIC_TOKEN_PARTS = [
|
|
@@ -510,7 +516,13 @@ async function prepareNativeRequest({ iteration, ctx, cognitive, controller, met
|
|
|
510
516
|
const model = models[0];
|
|
511
517
|
const { limit, output: reserve } = resolveTokenBudget(models, ctx.maxTokens);
|
|
512
518
|
const tools = [getRunJavaScriptTool(!!ctx.chat)];
|
|
513
|
-
const
|
|
519
|
+
const systemMessage = structuredClone(iteration.systemMessage);
|
|
520
|
+
const reasoningHint = getReasoningHint(iteration.reasoningEffort);
|
|
521
|
+
if (reasoningHint) systemMessage.content = typeof systemMessage.content === "string" ? `${systemMessage.content}\n\n${reasoningHint}` : [...systemMessage.content ?? [], {
|
|
522
|
+
type: "text",
|
|
523
|
+
text: reasoningHint
|
|
524
|
+
}];
|
|
525
|
+
const system = [systemMessage];
|
|
514
526
|
const budgetInstruction = getBudgetInstruction(ctx, iteration);
|
|
515
527
|
const budget = `\n\nExecution budget: response ${ctx.iterations.length} of ${ctx.loop}. ${budgetInstruction}`;
|
|
516
528
|
const buildMessages = (retainedIds, summary) => {
|
package/dist/index.cjs
CHANGED
|
@@ -7,10 +7,10 @@ const require_exit = require("./exit-BOtKWPuT.cjs");
|
|
|
7
7
|
const require_truncate = require("./truncate-uomAMGPs.cjs");
|
|
8
8
|
const require_quickjs_variant = require("./quickjs-variant-21IO97PF.cjs");
|
|
9
9
|
const require_typings = require("./typings-BA_XxAcY.cjs");
|
|
10
|
-
const require_custom_client = require("./custom-client-
|
|
10
|
+
const require_custom_client = require("./custom-client-BwRYQ4Oa.cjs");
|
|
11
11
|
let _bpinternal_zui = require("@bpinternal/zui");
|
|
12
12
|
//#region package.json
|
|
13
|
-
var version = "1.0.
|
|
13
|
+
var version = "1.0.3";
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/objects.ts
|
|
16
16
|
/**
|
|
@@ -619,7 +619,7 @@ const utils = {
|
|
|
619
619
|
* })
|
|
620
620
|
*/
|
|
621
621
|
const execute = async (props) => {
|
|
622
|
-
const { executeContext } = await Promise.resolve().then(() => require("./execute-
|
|
622
|
+
const { executeContext } = await Promise.resolve().then(() => require("./execute-DJBNrA2H.cjs"));
|
|
623
623
|
return executeContext(props);
|
|
624
624
|
};
|
|
625
625
|
/**
|
|
@@ -628,14 +628,14 @@ const execute = async (props) => {
|
|
|
628
628
|
* It's recommended to call this function at the beginning of your application without awaiting it (void init())
|
|
629
629
|
*/
|
|
630
630
|
const init = async () => {
|
|
631
|
-
await Promise.resolve().then(() => require("./execute-
|
|
631
|
+
await Promise.resolve().then(() => require("./execute-DJBNrA2H.cjs"));
|
|
632
632
|
await Promise.resolve().then(() => require("./component-CMFoCHyu.cjs")).then((n) => n.component_exports);
|
|
633
633
|
await Promise.resolve().then(() => require("./tool-_wK9hQOb.cjs")).then((n) => n.tool_exports);
|
|
634
634
|
await Promise.resolve().then(() => require("./exit-BOtKWPuT.cjs")).then((n) => n.exit_exports);
|
|
635
635
|
await Promise.resolve().then(() => require("./vm-gmekHc0i.cjs"));
|
|
636
636
|
await Promise.resolve().then(() => require("./utils-CTlsXvdj.cjs")).then((n) => n.utils_exports);
|
|
637
637
|
await Promise.resolve().then(() => require("./typings-BA_XxAcY.cjs")).then((n) => n.typings_exports);
|
|
638
|
-
await Promise.resolve().then(() => require("./native-
|
|
638
|
+
await Promise.resolve().then(() => require("./native-sbuzbLbY.cjs")).then((n) => n.native_exports);
|
|
639
639
|
};
|
|
640
640
|
//#endregion
|
|
641
641
|
exports.AssignmentError = require_errors.AssignmentError;
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,10 @@ import { t as Exit } from "./exit-DMPwCSba.js";
|
|
|
6
6
|
import { r as truncate } from "./truncate-BEKbdo3t.js";
|
|
7
7
|
import { f as createInspector, m as inspect, r as Memory, t as configureQuickJS } from "./quickjs-variant-CtuGagsb.js";
|
|
8
8
|
import { i as formatTypings } from "./typings-BEVDvtuk.js";
|
|
9
|
-
import { c as getValue, i as SuccessExecutionResult, l as Session, n as ErrorExecutionResult, o as DefaultExit, r as ExecutionResult, s as ListenExit, t as _CustomModelClient } from "./custom-client-
|
|
9
|
+
import { c as getValue, i as SuccessExecutionResult, l as Session, n as ErrorExecutionResult, o as DefaultExit, r as ExecutionResult, s as ListenExit, t as _CustomModelClient } from "./custom-client-JcdoH-47.js";
|
|
10
10
|
import { z } from "@bpinternal/zui";
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "1.0.
|
|
12
|
+
var version = "1.0.3";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/objects.ts
|
|
15
15
|
/**
|
|
@@ -618,7 +618,7 @@ const utils = {
|
|
|
618
618
|
* })
|
|
619
619
|
*/
|
|
620
620
|
const execute = async (props) => {
|
|
621
|
-
const { executeContext } = await import("./execute-
|
|
621
|
+
const { executeContext } = await import("./execute-DoN74Exa.js");
|
|
622
622
|
return executeContext(props);
|
|
623
623
|
};
|
|
624
624
|
/**
|
|
@@ -627,14 +627,14 @@ const execute = async (props) => {
|
|
|
627
627
|
* It's recommended to call this function at the beginning of your application without awaiting it (void init())
|
|
628
628
|
*/
|
|
629
629
|
const init = async () => {
|
|
630
|
-
await import("./execute-
|
|
630
|
+
await import("./execute-DoN74Exa.js");
|
|
631
631
|
await import("./component-DncqP4fB.js").then((n) => n.r);
|
|
632
632
|
await import("./tool-DstssiAs.js").then((n) => n.n);
|
|
633
633
|
await import("./exit-DMPwCSba.js").then((n) => n.n);
|
|
634
634
|
await import("./vm-C7SfutHn.js");
|
|
635
635
|
await import("./utils-BOFzb8Ok.js").then((n) => n.m);
|
|
636
636
|
await import("./typings-BEVDvtuk.js").then((n) => n.r);
|
|
637
|
-
await import("./native-
|
|
637
|
+
await import("./native-BGW5kBlv.js").then((n) => n.n);
|
|
638
638
|
};
|
|
639
639
|
//#endregion
|
|
640
640
|
export { AssignmentError, Chat, CitationsManager, CodeExecutionError, CodeFormattingError, CognitiveError, CompactionError, Component, ComponentInputError, DefaultComponents, DefaultExit, DeliveryError, ErrorExecutionResult, ExecutionAbortedError, ExecutionResult, Exit, ExitInputError, HookError, HostOperationError, InternalError, InvalidCodeError, InvalidComponentError, InvalidConfigurationError, InvalidEventError, InvalidExitError, InvalidMessageError, InvalidObjectError, InvalidSessionError, InvalidToolError, LLMzError, ListenExit, LoopExceededError, Memory, MemoryCapacityError, MemoryValueError, MissingChatResponseError, NativeProtocolError, ObjectInstance, ObjectPropertyError, ReservedIdentifierError, Session, SessionStateError, SuccessExecutionResult, ThinkSignal, TokenOverflowError, Tool, ToolExecutionError, ToolInputError, UnknownComponentError, UnknownExitError, UnknownToolError, _CustomModelClient, assertValidComponent, configureQuickJS, configureTokenizer, createInspector, execute, getValue, init, inspect, isAnyComponent, isComponent, isCriticalError, isLLMzError, truncate, utils, version };
|
package/dist/index.workerd.js
CHANGED
|
@@ -49,7 +49,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
49
49
|
}) : target, mod));
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region package.json
|
|
52
|
-
var version = "1.0.
|
|
52
|
+
var version = "1.0.3";
|
|
53
53
|
//#endregion
|
|
54
54
|
//#region src/errors/catalog.ts
|
|
55
55
|
function validationMessage(subject, issues, expectedInput) {
|
|
@@ -9652,7 +9652,7 @@ function getRunJavaScriptTool(chat) {
|
|
|
9652
9652
|
if (chat) return RUN_JAVASCRIPT_TOOL;
|
|
9653
9653
|
return {
|
|
9654
9654
|
...RUN_JAVASCRIPT_TOOL,
|
|
9655
|
-
description: `${WORKER_RESPONSE_INSTRUCTION}
|
|
9655
|
+
description: `${WORKER_RESPONSE_INSTRUCTION} ${EXECUTION_DESCRIPTION}`
|
|
9656
9656
|
};
|
|
9657
9657
|
}
|
|
9658
9658
|
/** Validate the entire response before any delivery or business action begins. */
|
|
@@ -9688,18 +9688,23 @@ function validateNativeToolCalls(calls) {
|
|
|
9688
9688
|
}
|
|
9689
9689
|
};
|
|
9690
9690
|
}
|
|
9691
|
-
var WORKER_RESPONSE_INSTRUCTION, RUN_JAVASCRIPT_TOOL;
|
|
9691
|
+
var WORKER_RESPONSE_INSTRUCTION, EXECUTION_DESCRIPTION, RUN_JAVASCRIPT_TOOL;
|
|
9692
9692
|
var init_native_tools = __esmMin((() => {
|
|
9693
9693
|
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.";
|
|
9694
|
+
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.";
|
|
9694
9695
|
RUN_JAVASCRIPT_TOOL = {
|
|
9695
9696
|
name: "run_javascript",
|
|
9696
|
-
description:
|
|
9697
|
+
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.`,
|
|
9697
9698
|
parameters: {
|
|
9698
9699
|
type: "object",
|
|
9699
9700
|
properties: { code: {
|
|
9700
9701
|
type: "string",
|
|
9701
|
-
|
|
9702
|
-
|
|
9702
|
+
description: [
|
|
9703
|
+
"The body of an async JavaScript program. Top-level await and return are supported. No Markdown fences, XML wrappers, imports, or TypeScript annotations.",
|
|
9704
|
+
"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.",
|
|
9705
|
+
"<example purpose=\"JavaScript syntax only\">const total = 17 + 25; return inspect(total);</example>",
|
|
9706
|
+
"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."
|
|
9707
|
+
].join("\n\n")
|
|
9703
9708
|
} },
|
|
9704
9709
|
required: ["code"],
|
|
9705
9710
|
additionalProperties: false
|
|
@@ -9707,6 +9712,120 @@ var init_native_tools = __esmMin((() => {
|
|
|
9707
9712
|
};
|
|
9708
9713
|
}));
|
|
9709
9714
|
//#endregion
|
|
9715
|
+
//#region src/prompts/native-examples.ts
|
|
9716
|
+
/** Static examples teach syntax without guessing inputs for arbitrary application schemas. */
|
|
9717
|
+
function getNativeExamples(capabilities) {
|
|
9718
|
+
const examples = [];
|
|
9719
|
+
if (capabilities.chat) examples.push(example("answer_without_actions", `<situation>
|
|
9720
|
+
The user asks for the opening time. The task instructions already say the shop opens at 9 AM. No action is needed.
|
|
9721
|
+
</situation>
|
|
9722
|
+
${turn(`<assistant_text>
|
|
9723
|
+
We open at 9 AM.
|
|
9724
|
+
</assistant_text>`)}
|
|
9725
|
+
<explanation>
|
|
9726
|
+
This is an ordinary assistant reply, with no native tool call. Its end gives the turn back to the user.
|
|
9727
|
+
</explanation>`));
|
|
9728
|
+
examples.push(example("execute_and_inspect", `<situation>
|
|
9729
|
+
Compute the total of 17 and 25, and inspect the computed value before continuing.
|
|
9730
|
+
</situation>
|
|
9731
|
+
${turn(call("const total = 17 + 25; return inspect(total);"))}
|
|
9732
|
+
<tool_result>
|
|
9733
|
+
42
|
|
9734
|
+
</tool_result>
|
|
9735
|
+
<explanation>
|
|
9736
|
+
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.
|
|
9737
|
+
</explanation>`));
|
|
9738
|
+
if (capabilities.tools) {
|
|
9739
|
+
examples.push(example("search_then_use_the_result", `<fictional_api>
|
|
9740
|
+
exampleSearch(query: string): Promise<string>
|
|
9741
|
+
</fictional_api>
|
|
9742
|
+
<situation>
|
|
9743
|
+
Find whether blue mugs are available. Availability must come from a search.
|
|
9744
|
+
</situation>
|
|
9745
|
+
${turn(call("const products = await exampleSearch('blue mugs'); return inspect(products);"))}
|
|
9746
|
+
<tool_result>
|
|
9747
|
+
Blue mugs are available. Price: $12 each.
|
|
9748
|
+
</tool_result>
|
|
9749
|
+
${capabilities.chat ? turn(`<assistant_text>
|
|
9750
|
+
Blue mugs are available for $12 each.
|
|
9751
|
+
</assistant_text>`) : `<next_step>
|
|
9752
|
+
Use the inspected facts and retained products variable to continue the task. Do not repeat the successful search.
|
|
9753
|
+
</next_step>`}
|
|
9754
|
+
<explanation>
|
|
9755
|
+
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.
|
|
9756
|
+
</explanation>`));
|
|
9757
|
+
examples.push(example("object_arguments_and_independent_calls", `<fictional_api>
|
|
9758
|
+
exampleReadStock(input: { itemId: string }): Promise<{ count: number }>
|
|
9759
|
+
exampleReadPrice(input: { itemId: string }): Promise<{ amount: number }>
|
|
9760
|
+
</fictional_api>
|
|
9761
|
+
<situation>
|
|
9762
|
+
Read stock and price for the same item. Neither read depends on the other.
|
|
9763
|
+
</situation>
|
|
9764
|
+
${turn(call("const [stock, price] = await Promise.all([exampleReadStock({ itemId: 'MUG-7' }), exampleReadPrice({ itemId: 'MUG-7' })]); return inspect({ stock, price });"))}
|
|
9765
|
+
<explanation>
|
|
9766
|
+
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.
|
|
9767
|
+
</explanation>`));
|
|
9768
|
+
examples.push(example("repair_a_search_phrase_submitted_as_code", `<fictional_api>
|
|
9769
|
+
exampleSearch(query: string): Promise<string>
|
|
9770
|
+
</fictional_api>
|
|
9771
|
+
<situation>
|
|
9772
|
+
The user asked about red mugs. The previous attempt submitted the words red mugs as JavaScript and failed to parse. No business tool ran.
|
|
9773
|
+
</situation>
|
|
9774
|
+
${turn(call("const matches = await exampleSearch('red mugs'); return inspect(matches);"))}
|
|
9775
|
+
<explanation>
|
|
9776
|
+
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.
|
|
9777
|
+
</explanation>`));
|
|
9778
|
+
}
|
|
9779
|
+
if (capabilities.exits) examples.push(example("complete_with_a_typed_result", `<fictional_api>
|
|
9780
|
+
exit(name: "example_complete", payload: { total: number }): never
|
|
9781
|
+
</fictional_api>
|
|
9782
|
+
<situation>
|
|
9783
|
+
The required work is complete. The computed total, already inspected, is 42. Complete through the declared example_complete outcome.
|
|
9784
|
+
</situation>
|
|
9785
|
+
${turn(call("return exit('example_complete', { total: 42 });"))}
|
|
9786
|
+
<explanation>
|
|
9787
|
+
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.
|
|
9788
|
+
</explanation>`));
|
|
9789
|
+
if (capabilities.chat && capabilities.components && capabilities.listen) examples.push(example("text_and_buttons_in_the_same_response", `<fictional_api>
|
|
9790
|
+
chat.exampleChoices(props: { options: Array<{ label: string, value: string }> }): void
|
|
9791
|
+
</fictional_api>
|
|
9792
|
+
<situation>
|
|
9793
|
+
The user requests an introduction in a text message, followed by buttons to shop or track an order.
|
|
9794
|
+
</situation>
|
|
9795
|
+
${turn(`<assistant_text>
|
|
9796
|
+
Hi, I'm your shopping assistant. I can help you shop or track an order.
|
|
9797
|
+
</assistant_text>
|
|
9798
|
+
${call("chat.exampleChoices({ options: [{ label: 'Shop', value: 'shop' }, { label: 'Track order', value: 'track' }] }); return exit('listen');")}`)}
|
|
9799
|
+
<explanation>
|
|
9800
|
+
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.
|
|
9801
|
+
</explanation>`));
|
|
9802
|
+
return [
|
|
9803
|
+
"<examples>",
|
|
9804
|
+
"These are hypothetical demonstrations, NOT live conversation, task history, or evidence. Do not perform their tasks or copy their facts.",
|
|
9805
|
+
"Names beginning with example are fictional and unavailable. Use the actual names and signatures under JavaScript API for your task.",
|
|
9806
|
+
"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.",
|
|
9807
|
+
"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.",
|
|
9808
|
+
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.",
|
|
9809
|
+
...examples,
|
|
9810
|
+
"Apply the demonstrated syntax to your actual task. The real API and task instructions are authoritative; fictional functions and facts are not available.",
|
|
9811
|
+
"</examples>"
|
|
9812
|
+
].join("\n\n");
|
|
9813
|
+
}
|
|
9814
|
+
var call, turn, example;
|
|
9815
|
+
var init_native_examples = __esmMin((() => {
|
|
9816
|
+
call = (code) => `<native_tool_call name="run_javascript">
|
|
9817
|
+
<arguments>
|
|
9818
|
+
${JSON.stringify({ code }, null, 2)}
|
|
9819
|
+
</arguments>
|
|
9820
|
+
</native_tool_call>`;
|
|
9821
|
+
turn = (content) => `<assistant_turn>
|
|
9822
|
+
${content}
|
|
9823
|
+
</assistant_turn>`;
|
|
9824
|
+
example = (name, content) => `<example name="${name}">
|
|
9825
|
+
${content}
|
|
9826
|
+
</example>`;
|
|
9827
|
+
}));
|
|
9828
|
+
//#endregion
|
|
9710
9829
|
//#region src/prompts/native.ts
|
|
9711
9830
|
var native_exports = /* @__PURE__ */ __exportAll({ getNativeSystemMessage: () => getNativeSystemMessage });
|
|
9712
9831
|
function runtimeRules(props, chat) {
|
|
@@ -9759,8 +9878,16 @@ async function getNativeSystemMessage(props) {
|
|
|
9759
9878
|
const protocol = [
|
|
9760
9879
|
runJavaScriptSyntax,
|
|
9761
9880
|
runtimeRules(props, chat),
|
|
9762
|
-
...chat ? ["# Assistant response", (props.response ?? resolveResponse()).instructions] : []
|
|
9881
|
+
...chat ? ["# Assistant response", (props.response ?? resolveResponse()).instructions] : [],
|
|
9882
|
+
getNativeExamples({
|
|
9883
|
+
chat,
|
|
9884
|
+
tools: declarations.length > 0,
|
|
9885
|
+
components: props.components.size > 0,
|
|
9886
|
+
exits: props.exits.length > 0,
|
|
9887
|
+
listen: props.exits.some((exit) => exit.name === "listen")
|
|
9888
|
+
})
|
|
9763
9889
|
].join("\n\n");
|
|
9890
|
+
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") : "";
|
|
9764
9891
|
return {
|
|
9765
9892
|
message: {
|
|
9766
9893
|
role: "system",
|
|
@@ -9770,13 +9897,14 @@ async function getNativeSystemMessage(props) {
|
|
|
9770
9897
|
"These TypeScript declarations describe functions inside run_javascript. Object properties, their types, values, and read/write rules are listed in Memory.",
|
|
9771
9898
|
tools,
|
|
9772
9899
|
"# Task instructions",
|
|
9773
|
-
instructions
|
|
9900
|
+
instructions,
|
|
9901
|
+
...delivery ? [delivery] : []
|
|
9774
9902
|
].join("\n\n")
|
|
9775
9903
|
},
|
|
9776
9904
|
parts: {
|
|
9777
9905
|
instructions,
|
|
9778
9906
|
tools,
|
|
9779
|
-
protocol
|
|
9907
|
+
protocol: [protocol, delivery].filter(Boolean).join("\n\n")
|
|
9780
9908
|
}
|
|
9781
9909
|
};
|
|
9782
9910
|
}
|
|
@@ -9787,6 +9915,7 @@ var init_native = __esmMin((() => {
|
|
|
9787
9915
|
init_native_tools();
|
|
9788
9916
|
init_typings();
|
|
9789
9917
|
init_utils$1();
|
|
9918
|
+
init_native_examples();
|
|
9790
9919
|
runJavaScriptSyntax = [
|
|
9791
9920
|
"# run_javascript syntax",
|
|
9792
9921
|
"run_javascript is the only native tool. Call it with a JSON object containing exactly one property: \"code\", a non-empty string of JavaScript source.",
|
|
@@ -15269,6 +15398,13 @@ var init_execution_report = __esmMin((() => {
|
|
|
15269
15398
|
MAX_OVERRIDE_SOURCE_LENGTH = 3e3;
|
|
15270
15399
|
}));
|
|
15271
15400
|
//#endregion
|
|
15401
|
+
//#region src/prompts/reasoning.ts
|
|
15402
|
+
/** Supplement explicit reasoning disablement consistently across providers and fallbacks. */
|
|
15403
|
+
function getReasoningHint(reasoningEffort) {
|
|
15404
|
+
return reasoningEffort === "none" ? "/no_think" : void 0;
|
|
15405
|
+
}
|
|
15406
|
+
var init_reasoning = __esmMin((() => {}));
|
|
15407
|
+
//#endregion
|
|
15272
15408
|
//#region src/runtime/generate.ts
|
|
15273
15409
|
function assertSuccessfulGeneration(metadata) {
|
|
15274
15410
|
if (!metadata || metadata.provider === "unknown") throw new CognitiveError("LLM generation failed: missing successful provider metadata");
|
|
@@ -15352,7 +15488,13 @@ async function prepareNativeRequest({ iteration, ctx, cognitive, controller, met
|
|
|
15352
15488
|
const model = models[0];
|
|
15353
15489
|
const { limit, output: reserve } = resolveTokenBudget(models, ctx.maxTokens);
|
|
15354
15490
|
const tools = [getRunJavaScriptTool(!!ctx.chat)];
|
|
15355
|
-
const
|
|
15491
|
+
const systemMessage = structuredClone(iteration.systemMessage);
|
|
15492
|
+
const reasoningHint = getReasoningHint(iteration.reasoningEffort);
|
|
15493
|
+
if (reasoningHint) systemMessage.content = typeof systemMessage.content === "string" ? `${systemMessage.content}\n\n${reasoningHint}` : [...systemMessage.content ?? [], {
|
|
15494
|
+
type: "text",
|
|
15495
|
+
text: reasoningHint
|
|
15496
|
+
}];
|
|
15497
|
+
const system = [systemMessage];
|
|
15356
15498
|
const budgetInstruction = getBudgetInstruction(ctx, iteration);
|
|
15357
15499
|
const budget = `\n\nExecution budget: response ${ctx.iterations.length} of ${ctx.loop}. ${budgetInstruction}`;
|
|
15358
15500
|
const buildMessages = (retainedIds, summary) => {
|
|
@@ -15661,6 +15803,7 @@ var init_generate = __esmMin((() => {
|
|
|
15661
15803
|
init_abort_signal();
|
|
15662
15804
|
init_hooks();
|
|
15663
15805
|
init_errors$1();
|
|
15806
|
+
init_reasoning();
|
|
15664
15807
|
init_compactor();
|
|
15665
15808
|
init_json();
|
|
15666
15809
|
init_utils$1();
|
|
@@ -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 = [
|
|
@@ -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
|
}
|
|
@@ -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 = [
|
|
@@ -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 {};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "llmz",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "LLMz - An LLM-native Typescript VM built on top of Zui",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.3",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
8
|
"DOCS.md",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"watch": "tsdown --watch",
|
|
31
31
|
"test": "vitest --run",
|
|
32
32
|
"test:e2e": "pnpm check:e2e:type && vitest run --config vitest.e2e.config.ts",
|
|
33
|
+
"test:e2e:quarantine": "vitest run --config vitest.quarantine.config.ts production-chat",
|
|
33
34
|
"test:e2e:update": "vitest -u run --config vitest.e2e.config.ts",
|
|
34
35
|
"test:e2e:watch": "vitest --config vitest.e2e.config.ts",
|
|
35
36
|
"check:format": "oxfmt --check .",
|