llmz 0.9.0 → 1.0.2
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 +232 -1794
- package/ERRORS.md +101 -0
- package/README.md +96 -582
- package/dist/chat/chat.d.ts +63 -0
- package/dist/chat/component.d.ts +31 -0
- package/dist/chat/component.default.d.ts +58 -0
- package/dist/chat/response.d.ts +15 -0
- package/dist/compiler/compiler.d.ts +2 -7
- package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
- package/dist/compiler/plugins/replace-comment.d.ts +2 -3
- package/dist/compiler/plugins/return-async.d.ts +5 -4
- package/dist/compiler/plugins/termination.d.ts +8 -0
- package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
- package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
- package/dist/component-CMFoCHyu.cjs +649 -0
- package/dist/component-DncqP4fB.js +614 -0
- package/dist/context.d.ts +71 -378
- package/dist/custom-client-C-WXvLD9.js +1655 -0
- package/dist/custom-client-Cgt9_0r1.cjs +1732 -0
- package/dist/custom-client.d.ts +12 -2
- package/dist/errors/catalog.d.ts +294 -0
- package/dist/errors/hooks.d.ts +2 -0
- package/dist/errors-C6ppQUZX.cjs +893 -0
- package/dist/errors-Crk5P8jo.js +636 -0
- package/dist/errors.d.ts +24 -36
- package/dist/execute-CiYvPs5Q.js +2061 -0
- package/dist/execute-DTTfacsi.cjs +2062 -0
- package/dist/{exit-DUM96DN1.cjs → exit-BOtKWPuT.cjs} +38 -28
- package/dist/{exit-CDdxDBRT.js → exit-DMPwCSba.js} +37 -27
- package/dist/exit.d.ts +19 -16
- package/dist/index.cjs +177 -1237
- package/dist/index.d.ts +25 -28
- package/dist/index.js +137 -1213
- package/dist/index.workerd.js +8974 -11145
- package/dist/inspect.d.ts +18 -4
- package/dist/inspection.d.ts +40 -0
- package/dist/native-0bq5ATZM.cjs +212 -0
- package/dist/native-n_718Z-T.js +177 -0
- package/dist/objects.d.ts +2 -57
- package/dist/prompts/native.d.ts +2 -0
- package/dist/prompts/prompt.d.ts +10 -101
- package/dist/quickjs-variant-21IO97PF.cjs +1080 -0
- package/dist/quickjs-variant-CtuGagsb.js +985 -0
- package/dist/result.d.ts +30 -861
- package/dist/runtime/execute.d.ts +3 -2
- package/dist/runtime/execution-activity.d.ts +11 -0
- package/dist/runtime/execution-diagnostics.d.ts +11 -0
- package/dist/runtime/execution-report.d.ts +51 -0
- package/dist/runtime/fixtures/chat.d.ts +8 -0
- package/dist/runtime/fixtures/long-search.d.ts +1 -1
- package/dist/runtime/fixtures/native-client.d.ts +33 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +1 -1
- package/dist/runtime/forced-inspection.d.ts +13 -0
- package/dist/runtime/forced-inspection.test.d.ts +1 -0
- package/dist/runtime/generate.d.ts +23 -20
- package/dist/runtime/generate.test.d.ts +1 -0
- package/dist/runtime/hook-provenance.test.d.ts +1 -0
- package/dist/runtime/inspection-hook.test.d.ts +1 -0
- package/dist/runtime/inspection-values.d.ts +14 -0
- package/dist/runtime/inspection-values.test.d.ts +1 -0
- package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
- package/dist/runtime/interruption-settings.test.d.ts +1 -0
- package/dist/runtime/javascript-api.d.ts +62 -0
- package/dist/runtime/javascript-api.test.d.ts +1 -0
- package/dist/runtime/native-review.test.d.ts +1 -0
- package/dist/runtime/native-tools.d.ts +18 -0
- package/dist/runtime/native-tools.test.d.ts +1 -0
- package/dist/runtime/object-memory.test.d.ts +1 -0
- package/dist/runtime/single-tool.test.d.ts +1 -0
- package/dist/runtime/think-signal.test.d.ts +1 -0
- package/dist/runtime/token-budget.d.ts +22 -0
- package/dist/runtime/token-budget.test.d.ts +1 -0
- package/dist/runtime/tool-wrapper.d.ts +6 -5
- package/dist/runtime/traces.test.d.ts +1 -0
- package/dist/runtime/truncation.test.d.ts +1 -0
- package/dist/runtime/types.d.ts +47 -31
- package/dist/runtime/variable-recovery.test.d.ts +1 -0
- package/dist/runtime/vm-context.d.ts +6 -1
- package/dist/runtime/worker-completion.test.d.ts +1 -0
- package/dist/runtime-names.d.ts +4 -0
- package/dist/schema-CXlnbb3n.cjs +68 -0
- package/dist/schema-GE4ISPCR.js +45 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.test.d.ts +1 -0
- package/dist/session/compactor.d.ts +51 -0
- package/dist/session/compactor.test.d.ts +1 -0
- package/dist/session/history.d.ts +36 -0
- package/dist/session/history.test.d.ts +1 -0
- package/dist/session/json.d.ts +3 -0
- package/dist/session/json.test.d.ts +1 -0
- package/dist/session/memory-codec.d.ts +9 -0
- package/dist/session/memory-codec.test.d.ts +1 -0
- package/dist/session/memory-render.d.ts +15 -0
- package/dist/session/memory-render.test.d.ts +1 -0
- package/dist/session/memory.d.ts +112 -0
- package/dist/session/memory.test.d.ts +1 -0
- package/dist/session/messages.d.ts +19 -0
- package/dist/session/messages.test.d.ts +1 -0
- package/dist/session/serialization.d.ts +36 -0
- package/dist/session/serialization.test.d.ts +1 -0
- package/dist/session/session-memory.test.d.ts +1 -0
- package/dist/session/session.d.ts +121 -0
- package/dist/session/session.test.d.ts +1 -0
- package/dist/session/speaker.test.d.ts +1 -0
- package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
- package/dist/session/transcript.test.d.ts +1 -0
- package/dist/{tool-Bv8N4IPj.js → tool-DstssiAs.js} +144 -92
- package/dist/{tool-Dy6AJpJH.cjs → tool-_wK9hQOb.cjs} +146 -94
- package/dist/tool.d.ts +25 -17
- package/dist/truncate-BEKbdo3t.js +79 -0
- package/dist/truncate-uomAMGPs.cjs +102 -0
- package/dist/truncate.d.ts +24 -0
- package/dist/truncate.test.d.ts +1 -0
- package/dist/types.d.ts +33 -9
- package/dist/{typings-3lsqCbkn.cjs → typings-BA_XxAcY.cjs} +38 -193
- package/dist/{typings-CrBa7Tyy.js → typings-BEVDvtuk.js} +38 -175
- package/dist/typings-formatter.d.ts +1 -1
- package/dist/typings.d.ts +3 -0
- package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
- package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
- package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
- package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
- package/dist/vm/drivers/node.d.ts +1 -1
- package/dist/vm/drivers/quickjs.d.ts +1 -1
- package/dist/vm/errors.d.ts +4 -4
- package/dist/vm/index.d.ts +3 -4
- package/dist/vm/instrument.d.ts +14 -6
- package/dist/vm/member-proxy.d.ts +4 -0
- package/dist/vm/member-proxy.test.d.ts +1 -0
- package/dist/vm/memory.test.d.ts +1 -0
- package/dist/vm/return-semantics.test.d.ts +1 -0
- package/dist/vm/types.d.ts +20 -3
- package/dist/{vm-BLsHw1da.js → vm-C7SfutHn.js} +1187 -180
- package/dist/{vm-D6s1zF6M.cjs → vm-gmekHc0i.cjs} +1221 -207
- package/package.json +13 -6
- package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
- package/dist/_baseForOwn-CFhWe_W6.js +0 -48
- package/dist/_getPrototype-CG7Dxrrz.js +0 -6
- package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
- package/dist/_overArg-C5Hy7oCi.cjs +0 -196
- package/dist/_overArg-CRYbj1NH.js +0 -155
- package/dist/chat.d.ts +0 -401
- package/dist/common-BlRFtdf2.js +0 -807
- package/dist/common-BnvrDnIT.cjs +0 -860
- package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
- package/dist/compiler-C-OI9sim.cjs +0 -547
- package/dist/compiler-CW1VjQsn.js +0 -473
- package/dist/component-C6Agl2ns.cjs +0 -73
- package/dist/component-DGG7d_Mz.js +0 -44
- package/dist/component.d.ts +0 -88
- package/dist/component.default.d.ts +0 -278
- package/dist/custom-client-ChuZ63zp.js +0 -2658
- package/dist/custom-client-DAsGRnYc.cjs +0 -2729
- package/dist/dual-modes-DDkoCp3R.js +0 -3006
- package/dist/dual-modes-DPXiuvNe.cjs +0 -3090
- package/dist/errors-C962uJdS.cjs +0 -220
- package/dist/errors-Cg1G0Awu.js +0 -161
- package/dist/example-format.d.ts +0 -8
- package/dist/example.d.ts +0 -45
- package/dist/execute-BWcdv9so.js +0 -1059
- package/dist/execute-DM2-7y86.cjs +0 -1060
- package/dist/exit-parser.d.ts +0 -39
- package/dist/handlers.d.ts +0 -10
- package/dist/hoist.d.ts +0 -2
- package/dist/isEmpty-BhJRCqIF.js +0 -52
- package/dist/isEmpty-LY533Wmh.cjs +0 -57
- package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
- package/dist/isPlainObject-D39AzPO2.js +0 -51
- package/dist/jsx-CIgdGGVs.js +0 -52
- package/dist/jsx-owqxrquU.cjs +0 -75
- package/dist/jsx.d.ts +0 -11
- package/dist/message-stream/index.d.ts +0 -9
- package/dist/message-stream/instructions.d.ts +0 -30
- package/dist/message-stream/normalizer.d.ts +0 -21
- package/dist/message-stream/parser.d.ts +0 -89
- package/dist/message-stream/registry.d.ts +0 -14
- package/dist/message-stream/replayable.d.ts +0 -27
- package/dist/message-stream/response-parser.d.ts +0 -24
- package/dist/message-stream/sanitize.d.ts +0 -10
- package/dist/message-stream/stream.d.ts +0 -54
- package/dist/message-stream/types.d.ts +0 -97
- package/dist/message-stream/validator.d.ts +0 -23
- package/dist/prompts/chat-mode/protocol.d.ts +0 -2
- package/dist/prompts/chat-mode/system.d.ts +0 -2
- package/dist/prompts/chat-mode/system.md.d.ts +0 -2
- package/dist/prompts/chat-mode/user.d.ts +0 -2
- package/dist/prompts/chat-mode/user.md.d.ts +0 -2
- package/dist/prompts/code-examples.d.ts +0 -2
- package/dist/prompts/common.d.ts +0 -7
- package/dist/prompts/dual-modes.d.ts +0 -2
- package/dist/prompts/execution-history.d.ts +0 -6
- package/dist/prompts/execution-state.d.ts +0 -3
- package/dist/prompts/protocol-basics.d.ts +0 -5
- package/dist/prompts/protocol.d.ts +0 -31
- package/dist/prompts/worker-mode/protocol.d.ts +0 -2
- package/dist/prompts/worker-mode/system.d.ts +0 -2
- package/dist/prompts/worker-mode/system.md.d.ts +0 -2
- package/dist/prompts/worker-mode/user.d.ts +0 -2
- package/dist/prompts/worker-mode/user.md.d.ts +0 -2
- package/dist/quickjs-variant-BYhMBpwU.js +0 -45
- package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
- package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
- package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +0 -29
- package/dist/runtime/interpret-result.d.ts +0 -22
- package/dist/snapshots.d.ts +0 -249
- package/dist/stack-traces-BIE_5Xwf.js +0 -21
- package/dist/stack-traces-ntw_qhoy.cjs +0 -26
- package/dist/truncator-CLkouTCO.cjs +0 -276
- package/dist/truncator-DZqEqnpD.js +0 -253
- package/dist/truncator.d.ts +0 -118
- package/dist/utils-3ESwP3yg.cjs +0 -1075
- package/dist/utils-UBeAFeEI.js +0 -950
- /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
- /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
- /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
- /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
- /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
- /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
- /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
- /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
- /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
- /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
- /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
- /package/dist/{message-stream/response-parser.test.d.ts → result.test.d.ts} +0 -0
- /package/dist/{message-stream/stream.test.d.ts → runtime/chat-completion.test.d.ts} +0 -0
- /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
- /package/dist/{prompts/adherence.test.d.ts → runtime/chat-last-speaker.test.d.ts} +0 -0
- /package/dist/{prompts/catalogue-examples.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
- /package/dist/{prompts/code-examples.test.d.ts → runtime/context-registration.test.d.ts} +0 -0
- /package/dist/{prompts/common.test.d.ts → runtime/empty-completion.test.d.ts} +0 -0
- /package/dist/{prompts/concrete-patterns.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
- /package/dist/{prompts/long-search.test.d.ts → runtime/errors.test.d.ts} +0 -0
- /package/dist/{prompts/protocol-simple.test.d.ts → runtime/execution-activity.test.d.ts} +0 -0
- /package/dist/{prompts/protocol.test.d.ts → runtime/execution-diagnostics.test.d.ts} +0 -0
- /package/dist/{prompts/sections.test.d.ts → runtime/execution-report.test.d.ts} +0 -0
- /package/dist/runtime/{interpret-result.test.d.ts → execution-safety.test.d.ts} +0 -0
- /package/dist/{transcript.test.d.ts → runtime/exit-control-flow.test.d.ts} +0 -0
- /package/dist/{truncator.test.d.ts → runtime/fixtures/long-search.test.d.ts} +0 -0
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
//#region src/errors/catalog.ts
|
|
2
|
+
const ERROR_BRAND = Symbol.for("llmz.error.v1");
|
|
3
|
+
/** Stable library failures. Control-flow signals (such as ThinkSignal) are not errors. */
|
|
4
|
+
var LLMzError = class extends Error {
|
|
5
|
+
critical;
|
|
6
|
+
constructor(message, critical, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.critical = critical;
|
|
9
|
+
this.name = new.target.name;
|
|
10
|
+
}
|
|
11
|
+
/** Shared across independently loaded copies of the library. */
|
|
12
|
+
get [ERROR_BRAND]() {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
static is = (value) => isLLMzError(value);
|
|
16
|
+
};
|
|
17
|
+
function validationMessage(subject, issues, expectedInput) {
|
|
18
|
+
return `${subject} received invalid input:\n${issues.map((issue) => `- ${issue.path.join(".") || "input"}: ${issue.message}`).join("\n")}\n\nExpected input (TypeScript):\n${expectedInput}`;
|
|
19
|
+
}
|
|
20
|
+
var CodeExecutionError = class extends LLMzError {
|
|
21
|
+
source;
|
|
22
|
+
stacktrace;
|
|
23
|
+
originalErrorName;
|
|
24
|
+
static is = (value) => isLLMzError(value, "EXECUTION_FAILED");
|
|
25
|
+
code = "EXECUTION_FAILED";
|
|
26
|
+
constructor(message, source, stacktrace, originalErrorName, cause) {
|
|
27
|
+
super(message, isCriticalError(cause), { cause });
|
|
28
|
+
this.source = source;
|
|
29
|
+
this.stacktrace = stacktrace;
|
|
30
|
+
this.originalErrorName = originalErrorName;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var InvalidCodeError = class extends LLMzError {
|
|
34
|
+
source;
|
|
35
|
+
static is = (value) => isLLMzError(value, "INVALID_CODE");
|
|
36
|
+
code = "INVALID_CODE";
|
|
37
|
+
constructor(message, source, options) {
|
|
38
|
+
super(message, false, options);
|
|
39
|
+
this.source = source;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var CodeFormattingError = class extends LLMzError {
|
|
43
|
+
source;
|
|
44
|
+
static is = (value) => isLLMzError(value, "CODE_FORMATTING_FAILED");
|
|
45
|
+
code = "CODE_FORMATTING_FAILED";
|
|
46
|
+
constructor(message, source) {
|
|
47
|
+
super(message, true);
|
|
48
|
+
this.source = source;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var ToolInputError = class extends LLMzError {
|
|
52
|
+
toolName;
|
|
53
|
+
issues;
|
|
54
|
+
expectedInput;
|
|
55
|
+
static is = (value) => isLLMzError(value, "INVALID_TOOL_INPUT");
|
|
56
|
+
code = "INVALID_TOOL_INPUT";
|
|
57
|
+
constructor(toolName, issues, expectedInput) {
|
|
58
|
+
super(validationMessage(`Tool "${toolName}"`, issues, expectedInput), false);
|
|
59
|
+
this.toolName = toolName;
|
|
60
|
+
this.issues = issues;
|
|
61
|
+
this.expectedInput = expectedInput;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var ExitInputError = class extends LLMzError {
|
|
65
|
+
exitName;
|
|
66
|
+
issues;
|
|
67
|
+
expectedInput;
|
|
68
|
+
static is = (value) => isLLMzError(value, "INVALID_EXIT_INPUT");
|
|
69
|
+
code = "INVALID_EXIT_INPUT";
|
|
70
|
+
constructor(exitName, issues, expectedInput) {
|
|
71
|
+
super(validationMessage(`Exit "${exitName}"`, issues, expectedInput), false);
|
|
72
|
+
this.exitName = exitName;
|
|
73
|
+
this.issues = issues;
|
|
74
|
+
this.expectedInput = expectedInput;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var ObjectPropertyError = class extends LLMzError {
|
|
78
|
+
objectName;
|
|
79
|
+
propertyName;
|
|
80
|
+
issues;
|
|
81
|
+
expectedInput;
|
|
82
|
+
static is = (value) => isLLMzError(value, "INVALID_OBJECT_PROPERTY");
|
|
83
|
+
code = "INVALID_OBJECT_PROPERTY";
|
|
84
|
+
constructor(objectName, propertyName, issues, expectedInput) {
|
|
85
|
+
super(validationMessage(`Object property ${objectName}.${propertyName}`, issues, expectedInput), false);
|
|
86
|
+
this.objectName = objectName;
|
|
87
|
+
this.propertyName = propertyName;
|
|
88
|
+
this.issues = issues;
|
|
89
|
+
this.expectedInput = expectedInput;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var ComponentInputError = class extends LLMzError {
|
|
93
|
+
componentName;
|
|
94
|
+
issues;
|
|
95
|
+
expectedInput;
|
|
96
|
+
static is = (value) => isLLMzError(value, "INVALID_COMPONENT_INPUT");
|
|
97
|
+
code = "INVALID_COMPONENT_INPUT";
|
|
98
|
+
constructor(componentName, issues, expectedInput) {
|
|
99
|
+
super(validationMessage(`Component "${componentName}"`, issues, expectedInput), false);
|
|
100
|
+
this.componentName = componentName;
|
|
101
|
+
this.issues = issues;
|
|
102
|
+
this.expectedInput = expectedInput;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var UnknownToolError = class extends LLMzError {
|
|
106
|
+
toolName;
|
|
107
|
+
availableTools;
|
|
108
|
+
static is = (value) => isLLMzError(value, "UNKNOWN_TOOL");
|
|
109
|
+
code = "UNKNOWN_TOOL";
|
|
110
|
+
constructor(toolName, availableTools = [], message) {
|
|
111
|
+
super(message ?? `Tool "${toolName}" is not available. Use a documented tool from the JavaScript API.`, false);
|
|
112
|
+
this.toolName = toolName;
|
|
113
|
+
this.availableTools = availableTools;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var UnknownComponentError = class extends LLMzError {
|
|
117
|
+
componentName;
|
|
118
|
+
availableComponents;
|
|
119
|
+
static is = (value) => isLLMzError(value, "UNKNOWN_COMPONENT");
|
|
120
|
+
code = "UNKNOWN_COMPONENT";
|
|
121
|
+
constructor(componentName, availableComponents) {
|
|
122
|
+
super(`Component "chat.${componentName}" is not available. Available components: ${availableComponents.map((name) => `chat.${name}`).join(", ") || "(none)"}. Use native assistant text for ordinary replies.`, false);
|
|
123
|
+
this.componentName = componentName;
|
|
124
|
+
this.availableComponents = availableComponents;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var UnknownExitError = class extends LLMzError {
|
|
128
|
+
exitName;
|
|
129
|
+
availableExits;
|
|
130
|
+
static is = (value) => isLLMzError(value, "UNKNOWN_EXIT");
|
|
131
|
+
code = "UNKNOWN_EXIT";
|
|
132
|
+
constructor(exitName, availableExits) {
|
|
133
|
+
super(`Exit "${exitName}" is not available. Use a registered exit name. Available exits: ${availableExits.join(", ")}.`, false);
|
|
134
|
+
this.exitName = exitName;
|
|
135
|
+
this.availableExits = availableExits;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var ReservedIdentifierError = class extends LLMzError {
|
|
139
|
+
identifier;
|
|
140
|
+
kind;
|
|
141
|
+
static is = (value) => isLLMzError(value, "RESERVED_IDENTIFIER");
|
|
142
|
+
code = "RESERVED_IDENTIFIER";
|
|
143
|
+
constructor(identifier, kind, critical = kind !== "variable", message = `Runtime name "${identifier}" is reserved.`) {
|
|
144
|
+
super(message, critical);
|
|
145
|
+
this.identifier = identifier;
|
|
146
|
+
this.kind = kind;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var ToolExecutionError = class extends LLMzError {
|
|
150
|
+
toolName;
|
|
151
|
+
static is = (value) => isLLMzError(value, "TOOL_EXECUTION_FAILED");
|
|
152
|
+
code = "TOOL_EXECUTION_FAILED";
|
|
153
|
+
constructor(toolName, cause) {
|
|
154
|
+
super(cause instanceof Error ? cause.message : String(cause), false, { cause });
|
|
155
|
+
this.toolName = toolName;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var LoopExceededError = class extends LLMzError {
|
|
159
|
+
limit;
|
|
160
|
+
static is = (value) => isLLMzError(value, "ITERATION_LIMIT");
|
|
161
|
+
code = "ITERATION_LIMIT";
|
|
162
|
+
constructor(limit) {
|
|
163
|
+
super("Loop exceeded error", true);
|
|
164
|
+
this.limit = limit;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var TokenOverflowError = class extends LLMzError {
|
|
168
|
+
tokens;
|
|
169
|
+
limit;
|
|
170
|
+
phase;
|
|
171
|
+
static is = (value) => isLLMzError(value, "TOKEN_OVERFLOW");
|
|
172
|
+
code = "TOKEN_OVERFLOW";
|
|
173
|
+
constructor(message, tokens, limit, phase = "input") {
|
|
174
|
+
super(message, true);
|
|
175
|
+
this.tokens = tokens;
|
|
176
|
+
this.limit = limit;
|
|
177
|
+
this.phase = phase;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var MemoryCapacityError = class extends LLMzError {
|
|
181
|
+
maxBytes;
|
|
182
|
+
static is = (value) => isLLMzError(value, "MEMORY_CAPACITY");
|
|
183
|
+
code = "MEMORY_CAPACITY";
|
|
184
|
+
constructor(maxBytes) {
|
|
185
|
+
super(`Memory limit exceeded (${maxBytes} bytes). Compact retained iterations before continuing.`, true);
|
|
186
|
+
this.maxBytes = maxBytes;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/** A generated program tried to change read-only runtime state. */
|
|
190
|
+
var AssignmentError = class extends LLMzError {
|
|
191
|
+
static is = (value) => isLLMzError(value, "INVALID_ASSIGNMENT");
|
|
192
|
+
code = "INVALID_ASSIGNMENT";
|
|
193
|
+
constructor(message, options) {
|
|
194
|
+
super(message, false, options);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
/** The provider failed, or returned an incomplete or malformed generation. */
|
|
198
|
+
var CognitiveError = class extends LLMzError {
|
|
199
|
+
static is = (value) => isLLMzError(value, "GENERATION_FAILED");
|
|
200
|
+
code = "GENERATION_FAILED";
|
|
201
|
+
constructor(message, options) {
|
|
202
|
+
super(message, true, options);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
/** Summarization failed; canonical history is preserved. */
|
|
206
|
+
var CompactionError = class extends LLMzError {
|
|
207
|
+
static is = (value) => isLLMzError(value, "COMPACTION_FAILED");
|
|
208
|
+
code = "COMPACTION_FAILED";
|
|
209
|
+
constructor(message, options) {
|
|
210
|
+
super(message, true, options);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
/** Invalid tool definition. */
|
|
214
|
+
var InvalidToolError = class extends LLMzError {
|
|
215
|
+
static is = (value) => isLLMzError(value, "INVALID_TOOL");
|
|
216
|
+
code = "INVALID_TOOL";
|
|
217
|
+
constructor(message, options) {
|
|
218
|
+
super(message, true, options);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
/** Invalid object definition. */
|
|
222
|
+
var InvalidObjectError = class extends LLMzError {
|
|
223
|
+
static is = (value) => isLLMzError(value, "INVALID_OBJECT");
|
|
224
|
+
code = "INVALID_OBJECT";
|
|
225
|
+
constructor(message, options) {
|
|
226
|
+
super(message, true, options);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
/** Invalid exit definition. */
|
|
230
|
+
var InvalidExitError = class extends LLMzError {
|
|
231
|
+
static is = (value) => isLLMzError(value, "INVALID_EXIT");
|
|
232
|
+
code = "INVALID_EXIT";
|
|
233
|
+
constructor(message, options) {
|
|
234
|
+
super(message, true, options);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
/** Invalid chat component definition. */
|
|
238
|
+
var InvalidComponentError = class extends LLMzError {
|
|
239
|
+
static is = (value) => isLLMzError(value, "INVALID_COMPONENT");
|
|
240
|
+
code = "INVALID_COMPONENT";
|
|
241
|
+
constructor(message, options) {
|
|
242
|
+
super(message, true, options);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
/** Invalid execution, chat, or library configuration. */
|
|
246
|
+
var InvalidConfigurationError = class extends LLMzError {
|
|
247
|
+
static is = (value) => isLLMzError(value, "INVALID_CONFIG");
|
|
248
|
+
code = "INVALID_CONFIG";
|
|
249
|
+
constructor(message, options) {
|
|
250
|
+
super(message, true, options);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/** Invalid session input message. */
|
|
254
|
+
var InvalidMessageError = class extends LLMzError {
|
|
255
|
+
static is = (value) => isLLMzError(value, "INVALID_MESSAGE");
|
|
256
|
+
code = "INVALID_MESSAGE";
|
|
257
|
+
constructor(message, options) {
|
|
258
|
+
super(message, true, options);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
/** Invalid external event name or payload. */
|
|
262
|
+
var InvalidEventError = class extends LLMzError {
|
|
263
|
+
static is = (value) => isLLMzError(value, "INVALID_EVENT");
|
|
264
|
+
code = "INVALID_EVENT";
|
|
265
|
+
constructor(message, options) {
|
|
266
|
+
super(message, true, options);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
/** Invalid persisted session or native history. */
|
|
270
|
+
var InvalidSessionError = class extends LLMzError {
|
|
271
|
+
static is = (value) => isLLMzError(value, "INVALID_SESSION");
|
|
272
|
+
code = "INVALID_SESSION";
|
|
273
|
+
constructor(message, options) {
|
|
274
|
+
super(message, true, options);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
/** The operation is not allowed in the current session state. */
|
|
278
|
+
var SessionStateError = class extends LLMzError {
|
|
279
|
+
static is = (value) => isLLMzError(value, "SESSION_STATE");
|
|
280
|
+
code = "SESSION_STATE";
|
|
281
|
+
constructor(message, options) {
|
|
282
|
+
super(message, true, options);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
/** A value cannot be retained in session memory. */
|
|
286
|
+
var MemoryValueError = class extends LLMzError {
|
|
287
|
+
static is = (value) => isLLMzError(value, "INVALID_MEMORY_VALUE");
|
|
288
|
+
code = "INVALID_MEMORY_VALUE";
|
|
289
|
+
constructor(message, options) {
|
|
290
|
+
super(message, false, options);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
/** The model returned an invalid native tool call. */
|
|
294
|
+
var NativeProtocolError = class extends LLMzError {
|
|
295
|
+
static is = (value) => isLLMzError(value, "INVALID_NATIVE_CALL");
|
|
296
|
+
code = "INVALID_NATIVE_CALL";
|
|
297
|
+
constructor(message, options) {
|
|
298
|
+
super(message, false, options);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
/** Generated code used a closed or unawaited host operation. */
|
|
302
|
+
var HostOperationError = class extends LLMzError {
|
|
303
|
+
static is = (value) => isLLMzError(value, "HOST_OPERATION_FAILED");
|
|
304
|
+
code = "HOST_OPERATION_FAILED";
|
|
305
|
+
constructor(message, options) {
|
|
306
|
+
super(message, false, options);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
/** Chat tried to wait for the user without delivering any message. */
|
|
310
|
+
var MissingChatResponseError = class extends LLMzError {
|
|
311
|
+
static is = (value) => isLLMzError(value, "MISSING_CHAT_RESPONSE");
|
|
312
|
+
code = "MISSING_CHAT_RESPONSE";
|
|
313
|
+
constructor(message, options) {
|
|
314
|
+
super(message, false, options);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
/** Message delivery failed; external delivery may have partially completed. */
|
|
318
|
+
var DeliveryError = class extends LLMzError {
|
|
319
|
+
static is = (value) => isLLMzError(value, "DELIVERY_FAILED");
|
|
320
|
+
code = "DELIVERY_FAILED";
|
|
321
|
+
constructor(message, options) {
|
|
322
|
+
super(message, false, options);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
/** An execution hook failed; its external effects may be incomplete. */
|
|
326
|
+
var HookError = class extends LLMzError {
|
|
327
|
+
static is = (value) => isLLMzError(value, "HOOK_FAILED");
|
|
328
|
+
code = "HOOK_FAILED";
|
|
329
|
+
constructor(message, options) {
|
|
330
|
+
super(message, false, options);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
/** Execution was cancelled or timed out. */
|
|
334
|
+
var ExecutionAbortedError = class extends LLMzError {
|
|
335
|
+
static is = (value) => isLLMzError(value, "EXECUTION_ABORTED");
|
|
336
|
+
code = "EXECUTION_ABORTED";
|
|
337
|
+
constructor(message, options) {
|
|
338
|
+
super(message, true, options);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
/** An unexpected library failure; inspect cause for the original exception. */
|
|
342
|
+
var InternalError = class extends LLMzError {
|
|
343
|
+
static is = (value) => isLLMzError(value, "INTERNAL_ERROR");
|
|
344
|
+
code = "INTERNAL_ERROR";
|
|
345
|
+
constructor(message, options) {
|
|
346
|
+
super(message, true, options);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
/** @internal Constructor registry for VM diagnostics. */
|
|
350
|
+
const errorClasses$1 = {
|
|
351
|
+
CodeExecutionError,
|
|
352
|
+
InvalidCodeError,
|
|
353
|
+
CodeFormattingError,
|
|
354
|
+
ToolInputError,
|
|
355
|
+
ExitInputError,
|
|
356
|
+
ObjectPropertyError,
|
|
357
|
+
ComponentInputError,
|
|
358
|
+
UnknownToolError,
|
|
359
|
+
UnknownExitError,
|
|
360
|
+
UnknownComponentError,
|
|
361
|
+
ReservedIdentifierError,
|
|
362
|
+
ToolExecutionError,
|
|
363
|
+
LoopExceededError,
|
|
364
|
+
TokenOverflowError,
|
|
365
|
+
MemoryCapacityError,
|
|
366
|
+
AssignmentError,
|
|
367
|
+
CognitiveError,
|
|
368
|
+
CompactionError,
|
|
369
|
+
InvalidToolError,
|
|
370
|
+
InvalidObjectError,
|
|
371
|
+
InvalidExitError,
|
|
372
|
+
InvalidComponentError,
|
|
373
|
+
InvalidConfigurationError,
|
|
374
|
+
InvalidMessageError,
|
|
375
|
+
InvalidEventError,
|
|
376
|
+
InvalidSessionError,
|
|
377
|
+
SessionStateError,
|
|
378
|
+
MemoryValueError,
|
|
379
|
+
NativeProtocolError,
|
|
380
|
+
HostOperationError,
|
|
381
|
+
DeliveryError,
|
|
382
|
+
MissingChatResponseError,
|
|
383
|
+
HookError,
|
|
384
|
+
ExecutionAbortedError,
|
|
385
|
+
InternalError
|
|
386
|
+
};
|
|
387
|
+
const ERROR_CODES = /* @__PURE__ */ new Set([
|
|
388
|
+
"EXECUTION_FAILED",
|
|
389
|
+
"INVALID_CODE",
|
|
390
|
+
"CODE_FORMATTING_FAILED",
|
|
391
|
+
"INVALID_TOOL_INPUT",
|
|
392
|
+
"INVALID_EXIT_INPUT",
|
|
393
|
+
"INVALID_OBJECT_PROPERTY",
|
|
394
|
+
"INVALID_COMPONENT_INPUT",
|
|
395
|
+
"UNKNOWN_TOOL",
|
|
396
|
+
"UNKNOWN_COMPONENT",
|
|
397
|
+
"UNKNOWN_EXIT",
|
|
398
|
+
"RESERVED_IDENTIFIER",
|
|
399
|
+
"TOOL_EXECUTION_FAILED",
|
|
400
|
+
"ITERATION_LIMIT",
|
|
401
|
+
"TOKEN_OVERFLOW",
|
|
402
|
+
"MEMORY_CAPACITY",
|
|
403
|
+
"INVALID_ASSIGNMENT",
|
|
404
|
+
"GENERATION_FAILED",
|
|
405
|
+
"COMPACTION_FAILED",
|
|
406
|
+
"INVALID_TOOL",
|
|
407
|
+
"INVALID_OBJECT",
|
|
408
|
+
"INVALID_EXIT",
|
|
409
|
+
"INVALID_COMPONENT",
|
|
410
|
+
"INVALID_CONFIG",
|
|
411
|
+
"INVALID_MESSAGE",
|
|
412
|
+
"INVALID_EVENT",
|
|
413
|
+
"INVALID_SESSION",
|
|
414
|
+
"SESSION_STATE",
|
|
415
|
+
"INVALID_MEMORY_VALUE",
|
|
416
|
+
"INVALID_NATIVE_CALL",
|
|
417
|
+
"HOST_OPERATION_FAILED",
|
|
418
|
+
"DELIVERY_FAILED",
|
|
419
|
+
"MISSING_CHAT_RESPONSE",
|
|
420
|
+
"HOOK_FAILED",
|
|
421
|
+
"EXECUTION_ABORTED",
|
|
422
|
+
"INTERNAL_ERROR"
|
|
423
|
+
]);
|
|
424
|
+
function isLLMzError(error, code) {
|
|
425
|
+
if (!error || typeof error !== "object") return false;
|
|
426
|
+
try {
|
|
427
|
+
const value = error;
|
|
428
|
+
return value[ERROR_BRAND] === true && typeof value.message === "string" && typeof value.name === "string" && typeof value.critical === "boolean" && typeof value.code === "string" && ERROR_CODES.has(value.code) && (code === void 0 || value.code === code);
|
|
429
|
+
} catch {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** Critical errors end execution; they are never sent back to the model for retry. */
|
|
434
|
+
function isCriticalError(error) {
|
|
435
|
+
return isLLMzError(error) && error.critical;
|
|
436
|
+
}
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/stack-traces.ts
|
|
439
|
+
const isInternalLine = (line) => {
|
|
440
|
+
return line.includes("/llmz/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
|
|
441
|
+
};
|
|
442
|
+
function cleanStackTrace(stack, cleanInternal = true) {
|
|
443
|
+
let lines = stack.split("\n");
|
|
444
|
+
const until = lines.findIndex((line) => isInternalLine(line));
|
|
445
|
+
if (cleanInternal && until >= 0) lines = lines.slice(0, until);
|
|
446
|
+
else lines = lines.map((line) => {
|
|
447
|
+
let llmzIndex = line.indexOf("/llmz/");
|
|
448
|
+
if (llmzIndex === -1) llmzIndex = line.indexOf("\\llmz\\");
|
|
449
|
+
if (llmzIndex === -1) return line;
|
|
450
|
+
let lastSpaceIndex = line.lastIndexOf(" ", llmzIndex);
|
|
451
|
+
if (lastSpaceIndex === -1) lastSpaceIndex = 0;
|
|
452
|
+
const maybeParen = line[lastSpaceIndex + 1] === "(" ? "(" : "";
|
|
453
|
+
return line.slice(0, lastSpaceIndex + 1) + maybeParen + line.slice(llmzIndex);
|
|
454
|
+
});
|
|
455
|
+
return lines.join("\n");
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/errors.ts
|
|
459
|
+
const errorClasses = { ...errorClasses$1 };
|
|
460
|
+
/** @internal Serialize diagnostics without losing non-enumerable Error fields. */
|
|
461
|
+
function describeError(error, seen = /* @__PURE__ */ new Set()) {
|
|
462
|
+
const value = Signals.maybeDeserializeError(error);
|
|
463
|
+
const details = {
|
|
464
|
+
...diagnosticProperties(value),
|
|
465
|
+
name: value.name === "Error" ? value.constructor.name : value.name,
|
|
466
|
+
message: value.message,
|
|
467
|
+
stack: value.stack
|
|
468
|
+
};
|
|
469
|
+
delete details.cause;
|
|
470
|
+
seen.add(error);
|
|
471
|
+
if (value.cause instanceof Error && !seen.has(value.cause)) details.cause = describeError(value.cause, seen);
|
|
472
|
+
else if (value.cause !== void 0 && !(value.cause instanceof Error)) details.cause = {
|
|
473
|
+
name: "ThrownValue",
|
|
474
|
+
message: String(value.cause),
|
|
475
|
+
value: diagnosticValue(value.cause)
|
|
476
|
+
};
|
|
477
|
+
return details;
|
|
478
|
+
}
|
|
479
|
+
/** User-supplied exceptions can carry cycles, bigint metadata, or throwing accessors. */
|
|
480
|
+
function diagnosticValue(value) {
|
|
481
|
+
if (value === void 0) return;
|
|
482
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
483
|
+
try {
|
|
484
|
+
const encoded = JSON.stringify(value, (_key, item) => {
|
|
485
|
+
if (typeof item === "bigint") return item.toString();
|
|
486
|
+
if (item && typeof item === "object") {
|
|
487
|
+
if (seen.has(item)) return "[Circular]";
|
|
488
|
+
seen.add(item);
|
|
489
|
+
}
|
|
490
|
+
return item;
|
|
491
|
+
});
|
|
492
|
+
return encoded === void 0 ? String(value) : JSON.parse(encoded);
|
|
493
|
+
} catch {
|
|
494
|
+
return "[Unserializable]";
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function diagnosticProperties(error) {
|
|
498
|
+
const entries = Object.entries(Object.getOwnPropertyDescriptors(error)).filter(([key, descriptor]) => key !== "cause" && descriptor.enumerable && "value" in descriptor).map(([key, descriptor]) => [key, diagnosticValue(descriptor.value)]);
|
|
499
|
+
return Object.fromEntries(entries);
|
|
500
|
+
}
|
|
501
|
+
function registerErrorClass(name, errorClass) {
|
|
502
|
+
errorClasses[name] = errorClass;
|
|
503
|
+
}
|
|
504
|
+
const tryParseMessage = (str) => {
|
|
505
|
+
try {
|
|
506
|
+
return JSON.parse(str);
|
|
507
|
+
} catch {
|
|
508
|
+
return str;
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
let Signals;
|
|
512
|
+
(function(_Signals) {
|
|
513
|
+
function isWrappedError(error) {
|
|
514
|
+
var _error$message, _error$message2;
|
|
515
|
+
return error.name === "Error" && (error === null || error === void 0 || (_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.startsWith("{")) && (error === null || error === void 0 || (_error$message2 = error.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.endsWith("}"));
|
|
516
|
+
}
|
|
517
|
+
_Signals.isWrappedError = isWrappedError;
|
|
518
|
+
function serializeError(error, seen = /* @__PURE__ */ new Set()) {
|
|
519
|
+
seen.add(error);
|
|
520
|
+
const properties = diagnosticProperties(error);
|
|
521
|
+
if (error.cause instanceof Error && !seen.has(error.cause)) Object.assign(properties, { cause: serializeError(error.cause, seen) });
|
|
522
|
+
else if (error.cause !== void 0 && !(error.cause instanceof Error)) properties.cause = { value: diagnosticValue(error.cause) };
|
|
523
|
+
if (isWrappedError(error)) {
|
|
524
|
+
const msg = tryParseMessage(error.message);
|
|
525
|
+
return JSON.stringify({
|
|
526
|
+
...typeof msg === "object" ? msg : { message: msg },
|
|
527
|
+
properties
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
return JSON.stringify({
|
|
531
|
+
name: error.constructor.name,
|
|
532
|
+
message: error.message,
|
|
533
|
+
stack: cleanStackTrace(error.stack ?? ""),
|
|
534
|
+
properties
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
_Signals.serializeError = serializeError;
|
|
538
|
+
function maybeDeserializeError(error) {
|
|
539
|
+
if (isLLMzError(error) || error instanceof Error && !!errorClasses[error.name] && error instanceof errorClasses[error.name]) return error;
|
|
540
|
+
let serializedError = (error === null || error === void 0 ? void 0 : error.toString()) ?? "";
|
|
541
|
+
if (error instanceof Error) serializedError = error.message;
|
|
542
|
+
else if (typeof error === "string") serializedError = error;
|
|
543
|
+
try {
|
|
544
|
+
const parsed = JSON.parse(serializedError);
|
|
545
|
+
if (parsed && typeof parsed.name === "string" && typeof parsed.message === "string") {
|
|
546
|
+
const { name, message, properties = {} } = parsed;
|
|
547
|
+
const ErrorClass = Object.values(errorClasses$1).find((candidate) => candidate.is({
|
|
548
|
+
...properties,
|
|
549
|
+
name,
|
|
550
|
+
message,
|
|
551
|
+
[Symbol.for("llmz.error.v1")]: true
|
|
552
|
+
})) ?? (Object.hasOwn(errorClasses, name) ? errorClasses[name] : Error);
|
|
553
|
+
const errorInstance = Object.setPrototypeOf(new Error(message), ErrorClass.prototype);
|
|
554
|
+
errorInstance.message = message;
|
|
555
|
+
errorInstance.name = name;
|
|
556
|
+
errorInstance.stack = cleanStackTrace((error === null || error === void 0 ? void 0 : error.stack) ?? "");
|
|
557
|
+
Object.assign(errorInstance, properties);
|
|
558
|
+
if (typeof properties.cause === "string") errorInstance.cause = maybeDeserializeError(properties.cause);
|
|
559
|
+
else if (properties.cause && typeof properties.cause === "object" && "value" in properties.cause) errorInstance.cause = properties.cause.value;
|
|
560
|
+
if (isWrappedError(errorInstance)) return maybeDeserializeError(errorInstance);
|
|
561
|
+
return errorInstance;
|
|
562
|
+
}
|
|
563
|
+
} catch {}
|
|
564
|
+
return error;
|
|
565
|
+
}
|
|
566
|
+
_Signals.maybeDeserializeError = maybeDeserializeError;
|
|
567
|
+
})(Signals || (Signals = {}));
|
|
568
|
+
const SIGNAL_BRAND = Symbol.for("llmz.signal.v1");
|
|
569
|
+
function isSignal(value) {
|
|
570
|
+
if (!value || typeof value !== "object") return false;
|
|
571
|
+
try {
|
|
572
|
+
return value[SIGNAL_BRAND] === true;
|
|
573
|
+
} catch {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
var VMSignal = class extends Error {
|
|
578
|
+
message;
|
|
579
|
+
get [SIGNAL_BRAND]() {
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
signalKind = "vm";
|
|
583
|
+
static is = (value) => isSignal(value);
|
|
584
|
+
/**
|
|
585
|
+
* The code that was executed by the VM up to the point of the signal
|
|
586
|
+
*/
|
|
587
|
+
truncatedCode = "";
|
|
588
|
+
/**
|
|
589
|
+
* Contains all the declared and executed variables during the VM execution
|
|
590
|
+
* See file plugins/variable-extraction.ts for more details
|
|
591
|
+
*/
|
|
592
|
+
variables = {};
|
|
593
|
+
constructor(message) {
|
|
594
|
+
super(message);
|
|
595
|
+
this.message = message;
|
|
596
|
+
this.message = Signals.serializeError(this);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
/** Loop means LLMz will continue the execution (unless it exhausted its iterations) */
|
|
600
|
+
var VMLoopSignal = class extends VMSignal {
|
|
601
|
+
signalKind = "loop";
|
|
602
|
+
static is = (value) => isSignal(value) && (value.signalKind === "loop" || value.signalKind === "think");
|
|
603
|
+
constructor(message) {
|
|
604
|
+
super(message);
|
|
605
|
+
this.message = Signals.serializeError(this);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* A successful tool result that requires model inspection before completion.
|
|
610
|
+
* Tools may throw or return this signal. Its context becomes the JavaScript
|
|
611
|
+
* return value; calls and assignments continue, and inspection overrides any
|
|
612
|
+
* attempted exit at iteration settlement. Cancellation and critical errors still stop execution.
|
|
613
|
+
*/
|
|
614
|
+
var ThinkSignal = class extends VMLoopSignal {
|
|
615
|
+
reason;
|
|
616
|
+
context;
|
|
617
|
+
metadata;
|
|
618
|
+
signalKind = "think";
|
|
619
|
+
static is = (value) => isSignal(value) && value.signalKind === "think";
|
|
620
|
+
constructor(reason, context, metadata) {
|
|
621
|
+
super("Think signal received: " + reason);
|
|
622
|
+
this.reason = reason;
|
|
623
|
+
this.context = context;
|
|
624
|
+
this.metadata = metadata;
|
|
625
|
+
this.message = Signals.serializeError(this);
|
|
626
|
+
this.stack = "";
|
|
627
|
+
}
|
|
628
|
+
toString() {
|
|
629
|
+
return Signals.serializeError(this);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
registerErrorClass("VMSignal", VMSignal);
|
|
633
|
+
registerErrorClass("VMLoopSignal", VMLoopSignal);
|
|
634
|
+
registerErrorClass("ThinkSignal", ThinkSignal);
|
|
635
|
+
//#endregion
|
|
636
|
+
Object.defineProperty(exports, "AssignmentError", {
|
|
637
|
+
enumerable: true,
|
|
638
|
+
get: function() {
|
|
639
|
+
return AssignmentError;
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
Object.defineProperty(exports, "CodeExecutionError", {
|
|
643
|
+
enumerable: true,
|
|
644
|
+
get: function() {
|
|
645
|
+
return CodeExecutionError;
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
Object.defineProperty(exports, "CodeFormattingError", {
|
|
649
|
+
enumerable: true,
|
|
650
|
+
get: function() {
|
|
651
|
+
return CodeFormattingError;
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
Object.defineProperty(exports, "CognitiveError", {
|
|
655
|
+
enumerable: true,
|
|
656
|
+
get: function() {
|
|
657
|
+
return CognitiveError;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
Object.defineProperty(exports, "CompactionError", {
|
|
661
|
+
enumerable: true,
|
|
662
|
+
get: function() {
|
|
663
|
+
return CompactionError;
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
Object.defineProperty(exports, "ComponentInputError", {
|
|
667
|
+
enumerable: true,
|
|
668
|
+
get: function() {
|
|
669
|
+
return ComponentInputError;
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
Object.defineProperty(exports, "DeliveryError", {
|
|
673
|
+
enumerable: true,
|
|
674
|
+
get: function() {
|
|
675
|
+
return DeliveryError;
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
Object.defineProperty(exports, "ExecutionAbortedError", {
|
|
679
|
+
enumerable: true,
|
|
680
|
+
get: function() {
|
|
681
|
+
return ExecutionAbortedError;
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
Object.defineProperty(exports, "ExitInputError", {
|
|
685
|
+
enumerable: true,
|
|
686
|
+
get: function() {
|
|
687
|
+
return ExitInputError;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
Object.defineProperty(exports, "HookError", {
|
|
691
|
+
enumerable: true,
|
|
692
|
+
get: function() {
|
|
693
|
+
return HookError;
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
Object.defineProperty(exports, "HostOperationError", {
|
|
697
|
+
enumerable: true,
|
|
698
|
+
get: function() {
|
|
699
|
+
return HostOperationError;
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
Object.defineProperty(exports, "InternalError", {
|
|
703
|
+
enumerable: true,
|
|
704
|
+
get: function() {
|
|
705
|
+
return InternalError;
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
Object.defineProperty(exports, "InvalidCodeError", {
|
|
709
|
+
enumerable: true,
|
|
710
|
+
get: function() {
|
|
711
|
+
return InvalidCodeError;
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
Object.defineProperty(exports, "InvalidComponentError", {
|
|
715
|
+
enumerable: true,
|
|
716
|
+
get: function() {
|
|
717
|
+
return InvalidComponentError;
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
Object.defineProperty(exports, "InvalidConfigurationError", {
|
|
721
|
+
enumerable: true,
|
|
722
|
+
get: function() {
|
|
723
|
+
return InvalidConfigurationError;
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
Object.defineProperty(exports, "InvalidEventError", {
|
|
727
|
+
enumerable: true,
|
|
728
|
+
get: function() {
|
|
729
|
+
return InvalidEventError;
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
Object.defineProperty(exports, "InvalidExitError", {
|
|
733
|
+
enumerable: true,
|
|
734
|
+
get: function() {
|
|
735
|
+
return InvalidExitError;
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
Object.defineProperty(exports, "InvalidMessageError", {
|
|
739
|
+
enumerable: true,
|
|
740
|
+
get: function() {
|
|
741
|
+
return InvalidMessageError;
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
Object.defineProperty(exports, "InvalidObjectError", {
|
|
745
|
+
enumerable: true,
|
|
746
|
+
get: function() {
|
|
747
|
+
return InvalidObjectError;
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
Object.defineProperty(exports, "InvalidSessionError", {
|
|
751
|
+
enumerable: true,
|
|
752
|
+
get: function() {
|
|
753
|
+
return InvalidSessionError;
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
Object.defineProperty(exports, "InvalidToolError", {
|
|
757
|
+
enumerable: true,
|
|
758
|
+
get: function() {
|
|
759
|
+
return InvalidToolError;
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
Object.defineProperty(exports, "LLMzError", {
|
|
763
|
+
enumerable: true,
|
|
764
|
+
get: function() {
|
|
765
|
+
return LLMzError;
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
Object.defineProperty(exports, "LoopExceededError", {
|
|
769
|
+
enumerable: true,
|
|
770
|
+
get: function() {
|
|
771
|
+
return LoopExceededError;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
Object.defineProperty(exports, "MemoryCapacityError", {
|
|
775
|
+
enumerable: true,
|
|
776
|
+
get: function() {
|
|
777
|
+
return MemoryCapacityError;
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
Object.defineProperty(exports, "MemoryValueError", {
|
|
781
|
+
enumerable: true,
|
|
782
|
+
get: function() {
|
|
783
|
+
return MemoryValueError;
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
Object.defineProperty(exports, "MissingChatResponseError", {
|
|
787
|
+
enumerable: true,
|
|
788
|
+
get: function() {
|
|
789
|
+
return MissingChatResponseError;
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
Object.defineProperty(exports, "NativeProtocolError", {
|
|
793
|
+
enumerable: true,
|
|
794
|
+
get: function() {
|
|
795
|
+
return NativeProtocolError;
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
Object.defineProperty(exports, "ObjectPropertyError", {
|
|
799
|
+
enumerable: true,
|
|
800
|
+
get: function() {
|
|
801
|
+
return ObjectPropertyError;
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
Object.defineProperty(exports, "ReservedIdentifierError", {
|
|
805
|
+
enumerable: true,
|
|
806
|
+
get: function() {
|
|
807
|
+
return ReservedIdentifierError;
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
Object.defineProperty(exports, "SessionStateError", {
|
|
811
|
+
enumerable: true,
|
|
812
|
+
get: function() {
|
|
813
|
+
return SessionStateError;
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
Object.defineProperty(exports, "Signals", {
|
|
817
|
+
enumerable: true,
|
|
818
|
+
get: function() {
|
|
819
|
+
return Signals;
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
Object.defineProperty(exports, "ThinkSignal", {
|
|
823
|
+
enumerable: true,
|
|
824
|
+
get: function() {
|
|
825
|
+
return ThinkSignal;
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
Object.defineProperty(exports, "TokenOverflowError", {
|
|
829
|
+
enumerable: true,
|
|
830
|
+
get: function() {
|
|
831
|
+
return TokenOverflowError;
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
Object.defineProperty(exports, "ToolExecutionError", {
|
|
835
|
+
enumerable: true,
|
|
836
|
+
get: function() {
|
|
837
|
+
return ToolExecutionError;
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
Object.defineProperty(exports, "ToolInputError", {
|
|
841
|
+
enumerable: true,
|
|
842
|
+
get: function() {
|
|
843
|
+
return ToolInputError;
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
Object.defineProperty(exports, "UnknownComponentError", {
|
|
847
|
+
enumerable: true,
|
|
848
|
+
get: function() {
|
|
849
|
+
return UnknownComponentError;
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
Object.defineProperty(exports, "UnknownExitError", {
|
|
853
|
+
enumerable: true,
|
|
854
|
+
get: function() {
|
|
855
|
+
return UnknownExitError;
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
Object.defineProperty(exports, "UnknownToolError", {
|
|
859
|
+
enumerable: true,
|
|
860
|
+
get: function() {
|
|
861
|
+
return UnknownToolError;
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
Object.defineProperty(exports, "VMSignal", {
|
|
865
|
+
enumerable: true,
|
|
866
|
+
get: function() {
|
|
867
|
+
return VMSignal;
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
Object.defineProperty(exports, "cleanStackTrace", {
|
|
871
|
+
enumerable: true,
|
|
872
|
+
get: function() {
|
|
873
|
+
return cleanStackTrace;
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
Object.defineProperty(exports, "describeError", {
|
|
877
|
+
enumerable: true,
|
|
878
|
+
get: function() {
|
|
879
|
+
return describeError;
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
Object.defineProperty(exports, "isCriticalError", {
|
|
883
|
+
enumerable: true,
|
|
884
|
+
get: function() {
|
|
885
|
+
return isCriticalError;
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
Object.defineProperty(exports, "isLLMzError", {
|
|
889
|
+
enumerable: true,
|
|
890
|
+
get: function() {
|
|
891
|
+
return isLLMzError;
|
|
892
|
+
}
|
|
893
|
+
});
|