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
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
const require_utils = require("./utils-CTlsXvdj.cjs");
|
|
2
|
+
const require_errors = require("./errors-C6ppQUZX.cjs");
|
|
3
|
+
const require_uniq = require("./uniq-DiXgysNV.cjs");
|
|
4
|
+
const require_schema = require("./schema-CXlnbb3n.cjs");
|
|
5
5
|
//#region src/exit.ts
|
|
6
|
-
var exit_exports = /* @__PURE__ */
|
|
6
|
+
var exit_exports = /* @__PURE__ */ require_utils.__exportAll({ Exit: () => Exit });
|
|
7
7
|
/**
|
|
8
8
|
* Defines how LLMz agent execution can terminate.
|
|
9
9
|
*
|
|
10
10
|
* Exits are the primary mechanism for controlling how and when agent execution completes.
|
|
11
11
|
* They define the possible outcomes of an execution and provide type-safe result handling.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* The model returns `exit(name, payload)` from JavaScript to finish with a validated
|
|
13
|
+
* payload. Ordinary returned values remain nonterminal inspection results.
|
|
14
14
|
*
|
|
15
15
|
* ## Core Concepts
|
|
16
16
|
*
|
|
@@ -24,7 +24,7 @@ var exit_exports = /* @__PURE__ */ require_compiler.__exportAll({ Exit: () => Ex
|
|
|
24
24
|
* **Flow Control**: Different exits allow for different execution paths and result
|
|
25
25
|
* handling, enabling complex decision-making and branching logic.
|
|
26
26
|
*
|
|
27
|
-
* **Built-in vs Custom**: LLMz provides built-in exits (
|
|
27
|
+
* **Built-in vs Custom**: LLMz provides built-in exits (ListenExit, DefaultExit)
|
|
28
28
|
* for common patterns, while custom exits enable domain-specific termination logic.
|
|
29
29
|
*
|
|
30
30
|
* ## Usage Patterns
|
|
@@ -39,7 +39,7 @@ var exit_exports = /* @__PURE__ */ require_compiler.__exportAll({ Exit: () => Ex
|
|
|
39
39
|
* description: 'When the user wants to exit the program',
|
|
40
40
|
* })
|
|
41
41
|
*
|
|
42
|
-
* //
|
|
42
|
+
* // Inside run_javascript: return exit('exit')
|
|
43
43
|
*
|
|
44
44
|
* // Result handling
|
|
45
45
|
* if (result.is(exit)) {
|
|
@@ -63,7 +63,8 @@ var exit_exports = /* @__PURE__ */ require_compiler.__exportAll({ Exit: () => Ex
|
|
|
63
63
|
* }),
|
|
64
64
|
* })
|
|
65
65
|
*
|
|
66
|
-
* //
|
|
66
|
+
* // Inside run_javascript:
|
|
67
|
+
* // return exit('escalation', { reason: 'Technical issue', details: '...' })
|
|
67
68
|
*
|
|
68
69
|
* // Type-safe result handling
|
|
69
70
|
* if (result.is(escalation)) {
|
|
@@ -113,7 +114,7 @@ var exit_exports = /* @__PURE__ */ require_compiler.__exportAll({ Exit: () => Ex
|
|
|
113
114
|
*
|
|
114
115
|
* ### Exit Aliases
|
|
115
116
|
*
|
|
116
|
-
*
|
|
117
|
+
* Alternative names for the same exit:
|
|
117
118
|
*
|
|
118
119
|
* ```typescript
|
|
119
120
|
* const exit = new Exit({
|
|
@@ -122,7 +123,8 @@ var exit_exports = /* @__PURE__ */ require_compiler.__exportAll({ Exit: () => Ex
|
|
|
122
123
|
* description: 'Task completed successfully',
|
|
123
124
|
* })
|
|
124
125
|
*
|
|
125
|
-
* //
|
|
126
|
+
* // JavaScript can return exit('complete'), exit('done'), or another registered alias.
|
|
127
|
+
* // These all select the same exit without creating additional native tools.
|
|
126
128
|
* ```
|
|
127
129
|
*
|
|
128
130
|
* ### Exit Metadata for Orchestration
|
|
@@ -200,27 +202,27 @@ var exit_exports = /* @__PURE__ */ require_compiler.__exportAll({ Exit: () => Ex
|
|
|
200
202
|
* @template T - The type of data this exit returns (inferred from schema)
|
|
201
203
|
*
|
|
202
204
|
* @see {@link ExecutionResult} For result handling
|
|
203
|
-
* @see {@link ThinkExit} Built-in thinking exit
|
|
204
205
|
* @see {@link ListenExit} Built-in chat listening exit
|
|
205
206
|
* @see {@link DefaultExit} Built-in completion exit
|
|
206
207
|
*/
|
|
207
208
|
var Exit = class Exit {
|
|
208
|
-
/** The primary name of the exit (used
|
|
209
|
+
/** The primary name of the exit (used by its native exit tool) */
|
|
209
210
|
name;
|
|
210
|
-
/**
|
|
211
|
+
/** Host-side aliases; the native tool uses only the primary name */
|
|
211
212
|
aliases = [];
|
|
212
213
|
/** Human-readable description of when this exit should be used */
|
|
213
214
|
description;
|
|
214
215
|
/** Additional metadata for orchestration and custom logic */
|
|
215
216
|
metadata;
|
|
216
|
-
/**
|
|
217
|
+
/** Model-facing payload description. The original validator is retained in zSchema. */
|
|
217
218
|
schema;
|
|
219
|
+
_schema;
|
|
218
220
|
/**
|
|
219
|
-
* Returns the
|
|
221
|
+
* Returns the original runtime validator, preserving transforms and refinements.
|
|
220
222
|
* Used internally for validation and type inference.
|
|
221
223
|
*/
|
|
222
224
|
get zSchema() {
|
|
223
|
-
return this.schema ? require_utils.fromJSONSchemaCompat(this.schema) : void 0;
|
|
225
|
+
return this._schema ?? (this.schema ? require_utils.fromJSONSchemaCompat(this.schema) : void 0);
|
|
224
226
|
}
|
|
225
227
|
/**
|
|
226
228
|
* Renames the exit and updates aliases accordingly.
|
|
@@ -237,7 +239,7 @@ var Exit = class Exit {
|
|
|
237
239
|
*/
|
|
238
240
|
rename(name) {
|
|
239
241
|
const before = this.name;
|
|
240
|
-
if (!require_utils.isValidIdentifier(name)) throw new
|
|
242
|
+
if (!require_utils.isValidIdentifier(name)) throw new require_errors.InvalidExitError(`Invalid name for exit ${name}. An exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`);
|
|
241
243
|
this.name = name;
|
|
242
244
|
this.aliases = require_uniq.uniq([name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
243
245
|
return this;
|
|
@@ -292,7 +294,7 @@ var Exit = class Exit {
|
|
|
292
294
|
return result.exit instanceof Exit && this.name === result.exit.name;
|
|
293
295
|
}
|
|
294
296
|
/**
|
|
295
|
-
* Serializes
|
|
297
|
+
* Serializes the model-facing description. JavaScript validators cannot be serialized; use clone() to retain them.
|
|
296
298
|
*
|
|
297
299
|
* @returns JSON representation of the exit
|
|
298
300
|
*
|
|
@@ -368,15 +370,23 @@ var Exit = class Exit {
|
|
|
368
370
|
* ```
|
|
369
371
|
*/
|
|
370
372
|
constructor(props) {
|
|
371
|
-
if (!
|
|
372
|
-
if (
|
|
373
|
-
if (props.
|
|
374
|
-
if (props.
|
|
375
|
-
if (props.aliases
|
|
373
|
+
if (!props || typeof props !== "object" || Array.isArray(props)) throw new require_errors.InvalidExitError("Exit definition must be an object.");
|
|
374
|
+
if (!require_utils.isValidIdentifier(props.name)) throw new require_errors.InvalidExitError(`Invalid name for exit ${props.name}. A exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`);
|
|
375
|
+
if (typeof props.description !== "string" || props.description.trim().length === 0) throw new require_errors.InvalidExitError(`Invalid description for exit ${props.name}. Expected a non-empty string, but got type "${typeof props.description}"`);
|
|
376
|
+
if (props.metadata !== void 0 && typeof props.metadata !== "object") throw new require_errors.InvalidExitError(`Invalid metadata for exit ${props.name}. Expected an object, but got type "${typeof props.metadata}"`);
|
|
377
|
+
if (props.aliases !== void 0 && !Array.isArray(props.aliases)) throw new require_errors.InvalidExitError(`Invalid aliases for exit ${props.name}. Expected an array, but got type "${typeof props.aliases}"`);
|
|
378
|
+
if (props.aliases && props.aliases.some((alias) => !require_utils.isValidIdentifier(alias))) throw new require_errors.InvalidExitError(`Invalid aliases for exit ${props.name}. Expected an array of valid identifiers.`);
|
|
376
379
|
if (typeof props.schema !== "undefined") {
|
|
377
|
-
if (require_utils.isZuiSchema(props.schema))
|
|
378
|
-
|
|
379
|
-
|
|
380
|
+
if (require_utils.isZuiSchema(props.schema)) {
|
|
381
|
+
if (["ZodUndefined", "ZodVoid"].includes(props.schema._def.typeName)) throw new require_errors.InvalidExitError(`Exit ${props.name} must use a JSON-compatible payload schema. Omit schema for an exit without data, or use z.null() for an explicit null payload.`);
|
|
382
|
+
try {
|
|
383
|
+
this.schema = require_schema.toModelSchema(props.schema);
|
|
384
|
+
this._schema = props.schema;
|
|
385
|
+
} catch (cause) {
|
|
386
|
+
throw new require_errors.InvalidExitError(`Cannot describe schema for exit ${props.name}: ${String(cause)}`, { cause });
|
|
387
|
+
}
|
|
388
|
+
} else if (require_utils.isJsonSchema(props.schema)) this.schema = props.schema;
|
|
389
|
+
else throw new require_errors.InvalidExitError(`Invalid input schema for exit ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.schema}"`);
|
|
380
390
|
}
|
|
381
391
|
this.name = props.name;
|
|
382
392
|
this.aliases = require_uniq.uniq([props.name, ...props.aliases ?? []]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Y as __exportAll, c as isValidIdentifier, l as isZuiSchema, n as fromJSONSchemaCompat, s as isJsonSchema } from "./utils-BOFzb8Ok.js";
|
|
2
|
+
import { S as InvalidExitError } from "./errors-Crk5P8jo.js";
|
|
3
|
+
import { t as uniq } from "./uniq-DfUeSNaX.js";
|
|
4
|
+
import { i as toModelSchema } from "./schema-GE4ISPCR.js";
|
|
5
5
|
//#region src/exit.ts
|
|
6
6
|
var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
7
7
|
/**
|
|
@@ -9,8 +9,8 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
9
9
|
*
|
|
10
10
|
* Exits are the primary mechanism for controlling how and when agent execution completes.
|
|
11
11
|
* They define the possible outcomes of an execution and provide type-safe result handling.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* The model returns `exit(name, payload)` from JavaScript to finish with a validated
|
|
13
|
+
* payload. Ordinary returned values remain nonterminal inspection results.
|
|
14
14
|
*
|
|
15
15
|
* ## Core Concepts
|
|
16
16
|
*
|
|
@@ -24,7 +24,7 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
24
24
|
* **Flow Control**: Different exits allow for different execution paths and result
|
|
25
25
|
* handling, enabling complex decision-making and branching logic.
|
|
26
26
|
*
|
|
27
|
-
* **Built-in vs Custom**: LLMz provides built-in exits (
|
|
27
|
+
* **Built-in vs Custom**: LLMz provides built-in exits (ListenExit, DefaultExit)
|
|
28
28
|
* for common patterns, while custom exits enable domain-specific termination logic.
|
|
29
29
|
*
|
|
30
30
|
* ## Usage Patterns
|
|
@@ -39,7 +39,7 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
39
39
|
* description: 'When the user wants to exit the program',
|
|
40
40
|
* })
|
|
41
41
|
*
|
|
42
|
-
* //
|
|
42
|
+
* // Inside run_javascript: return exit('exit')
|
|
43
43
|
*
|
|
44
44
|
* // Result handling
|
|
45
45
|
* if (result.is(exit)) {
|
|
@@ -63,7 +63,8 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
63
63
|
* }),
|
|
64
64
|
* })
|
|
65
65
|
*
|
|
66
|
-
* //
|
|
66
|
+
* // Inside run_javascript:
|
|
67
|
+
* // return exit('escalation', { reason: 'Technical issue', details: '...' })
|
|
67
68
|
*
|
|
68
69
|
* // Type-safe result handling
|
|
69
70
|
* if (result.is(escalation)) {
|
|
@@ -113,7 +114,7 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
113
114
|
*
|
|
114
115
|
* ### Exit Aliases
|
|
115
116
|
*
|
|
116
|
-
*
|
|
117
|
+
* Alternative names for the same exit:
|
|
117
118
|
*
|
|
118
119
|
* ```typescript
|
|
119
120
|
* const exit = new Exit({
|
|
@@ -122,7 +123,8 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
122
123
|
* description: 'Task completed successfully',
|
|
123
124
|
* })
|
|
124
125
|
*
|
|
125
|
-
* //
|
|
126
|
+
* // JavaScript can return exit('complete'), exit('done'), or another registered alias.
|
|
127
|
+
* // These all select the same exit without creating additional native tools.
|
|
126
128
|
* ```
|
|
127
129
|
*
|
|
128
130
|
* ### Exit Metadata for Orchestration
|
|
@@ -200,27 +202,27 @@ var exit_exports = /* @__PURE__ */ __exportAll({ Exit: () => Exit });
|
|
|
200
202
|
* @template T - The type of data this exit returns (inferred from schema)
|
|
201
203
|
*
|
|
202
204
|
* @see {@link ExecutionResult} For result handling
|
|
203
|
-
* @see {@link ThinkExit} Built-in thinking exit
|
|
204
205
|
* @see {@link ListenExit} Built-in chat listening exit
|
|
205
206
|
* @see {@link DefaultExit} Built-in completion exit
|
|
206
207
|
*/
|
|
207
208
|
var Exit = class Exit {
|
|
208
|
-
/** The primary name of the exit (used
|
|
209
|
+
/** The primary name of the exit (used by its native exit tool) */
|
|
209
210
|
name;
|
|
210
|
-
/**
|
|
211
|
+
/** Host-side aliases; the native tool uses only the primary name */
|
|
211
212
|
aliases = [];
|
|
212
213
|
/** Human-readable description of when this exit should be used */
|
|
213
214
|
description;
|
|
214
215
|
/** Additional metadata for orchestration and custom logic */
|
|
215
216
|
metadata;
|
|
216
|
-
/**
|
|
217
|
+
/** Model-facing payload description. The original validator is retained in zSchema. */
|
|
217
218
|
schema;
|
|
219
|
+
_schema;
|
|
218
220
|
/**
|
|
219
|
-
* Returns the
|
|
221
|
+
* Returns the original runtime validator, preserving transforms and refinements.
|
|
220
222
|
* Used internally for validation and type inference.
|
|
221
223
|
*/
|
|
222
224
|
get zSchema() {
|
|
223
|
-
return this.schema ? fromJSONSchemaCompat(this.schema) : void 0;
|
|
225
|
+
return this._schema ?? (this.schema ? fromJSONSchemaCompat(this.schema) : void 0);
|
|
224
226
|
}
|
|
225
227
|
/**
|
|
226
228
|
* Renames the exit and updates aliases accordingly.
|
|
@@ -237,7 +239,7 @@ var Exit = class Exit {
|
|
|
237
239
|
*/
|
|
238
240
|
rename(name) {
|
|
239
241
|
const before = this.name;
|
|
240
|
-
if (!isValidIdentifier(name)) throw new
|
|
242
|
+
if (!isValidIdentifier(name)) throw new InvalidExitError(`Invalid name for exit ${name}. An exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`);
|
|
241
243
|
this.name = name;
|
|
242
244
|
this.aliases = uniq([name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
243
245
|
return this;
|
|
@@ -292,7 +294,7 @@ var Exit = class Exit {
|
|
|
292
294
|
return result.exit instanceof Exit && this.name === result.exit.name;
|
|
293
295
|
}
|
|
294
296
|
/**
|
|
295
|
-
* Serializes
|
|
297
|
+
* Serializes the model-facing description. JavaScript validators cannot be serialized; use clone() to retain them.
|
|
296
298
|
*
|
|
297
299
|
* @returns JSON representation of the exit
|
|
298
300
|
*
|
|
@@ -368,15 +370,23 @@ var Exit = class Exit {
|
|
|
368
370
|
* ```
|
|
369
371
|
*/
|
|
370
372
|
constructor(props) {
|
|
371
|
-
if (!
|
|
372
|
-
if (
|
|
373
|
-
if (props.
|
|
374
|
-
if (props.
|
|
375
|
-
if (props.aliases && props.aliases
|
|
373
|
+
if (!props || typeof props !== "object" || Array.isArray(props)) throw new InvalidExitError("Exit definition must be an object.");
|
|
374
|
+
if (!isValidIdentifier(props.name)) throw new InvalidExitError(`Invalid name for exit ${props.name}. A exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`);
|
|
375
|
+
if (typeof props.description !== "string" || props.description.trim().length === 0) throw new InvalidExitError(`Invalid description for exit ${props.name}. Expected a non-empty string, but got type "${typeof props.description}"`);
|
|
376
|
+
if (props.metadata !== void 0 && typeof props.metadata !== "object") throw new InvalidExitError(`Invalid metadata for exit ${props.name}. Expected an object, but got type "${typeof props.metadata}"`);
|
|
377
|
+
if (props.aliases !== void 0 && !Array.isArray(props.aliases)) throw new InvalidExitError(`Invalid aliases for exit ${props.name}. Expected an array, but got type "${typeof props.aliases}"`);
|
|
378
|
+
if (props.aliases && props.aliases.some((alias) => !isValidIdentifier(alias))) throw new InvalidExitError(`Invalid aliases for exit ${props.name}. Expected an array of valid identifiers.`);
|
|
376
379
|
if (typeof props.schema !== "undefined") {
|
|
377
|
-
if (isZuiSchema(props.schema))
|
|
378
|
-
|
|
379
|
-
|
|
380
|
+
if (isZuiSchema(props.schema)) {
|
|
381
|
+
if (["ZodUndefined", "ZodVoid"].includes(props.schema._def.typeName)) throw new InvalidExitError(`Exit ${props.name} must use a JSON-compatible payload schema. Omit schema for an exit without data, or use z.null() for an explicit null payload.`);
|
|
382
|
+
try {
|
|
383
|
+
this.schema = toModelSchema(props.schema);
|
|
384
|
+
this._schema = props.schema;
|
|
385
|
+
} catch (cause) {
|
|
386
|
+
throw new InvalidExitError(`Cannot describe schema for exit ${props.name}: ${String(cause)}`, { cause });
|
|
387
|
+
}
|
|
388
|
+
} else if (isJsonSchema(props.schema)) this.schema = props.schema;
|
|
389
|
+
else throw new InvalidExitError(`Invalid input schema for exit ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.schema}"`);
|
|
380
390
|
}
|
|
381
391
|
this.name = props.name;
|
|
382
392
|
this.aliases = uniq([props.name, ...props.aliases ?? []]);
|
package/dist/exit.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from '@bpinternal/zui';
|
|
1
2
|
import { JSONSchema7 } from 'json-schema';
|
|
2
3
|
import { Serializable, ZuiType } from './types.js';
|
|
3
4
|
/**
|
|
@@ -25,8 +26,8 @@ export declare namespace Exit {
|
|
|
25
26
|
*
|
|
26
27
|
* Exits are the primary mechanism for controlling how and when agent execution completes.
|
|
27
28
|
* They define the possible outcomes of an execution and provide type-safe result handling.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* The model returns `exit(name, payload)` from JavaScript to finish with a validated
|
|
30
|
+
* payload. Ordinary returned values remain nonterminal inspection results.
|
|
30
31
|
*
|
|
31
32
|
* ## Core Concepts
|
|
32
33
|
*
|
|
@@ -40,7 +41,7 @@ export declare namespace Exit {
|
|
|
40
41
|
* **Flow Control**: Different exits allow for different execution paths and result
|
|
41
42
|
* handling, enabling complex decision-making and branching logic.
|
|
42
43
|
*
|
|
43
|
-
* **Built-in vs Custom**: LLMz provides built-in exits (
|
|
44
|
+
* **Built-in vs Custom**: LLMz provides built-in exits (ListenExit, DefaultExit)
|
|
44
45
|
* for common patterns, while custom exits enable domain-specific termination logic.
|
|
45
46
|
*
|
|
46
47
|
* ## Usage Patterns
|
|
@@ -55,7 +56,7 @@ export declare namespace Exit {
|
|
|
55
56
|
* description: 'When the user wants to exit the program',
|
|
56
57
|
* })
|
|
57
58
|
*
|
|
58
|
-
* //
|
|
59
|
+
* // Inside run_javascript: return exit('exit')
|
|
59
60
|
*
|
|
60
61
|
* // Result handling
|
|
61
62
|
* if (result.is(exit)) {
|
|
@@ -79,7 +80,8 @@ export declare namespace Exit {
|
|
|
79
80
|
* }),
|
|
80
81
|
* })
|
|
81
82
|
*
|
|
82
|
-
* //
|
|
83
|
+
* // Inside run_javascript:
|
|
84
|
+
* // return exit('escalation', { reason: 'Technical issue', details: '...' })
|
|
83
85
|
*
|
|
84
86
|
* // Type-safe result handling
|
|
85
87
|
* if (result.is(escalation)) {
|
|
@@ -129,7 +131,7 @@ export declare namespace Exit {
|
|
|
129
131
|
*
|
|
130
132
|
* ### Exit Aliases
|
|
131
133
|
*
|
|
132
|
-
*
|
|
134
|
+
* Alternative names for the same exit:
|
|
133
135
|
*
|
|
134
136
|
* ```typescript
|
|
135
137
|
* const exit = new Exit({
|
|
@@ -138,7 +140,8 @@ export declare namespace Exit {
|
|
|
138
140
|
* description: 'Task completed successfully',
|
|
139
141
|
* })
|
|
140
142
|
*
|
|
141
|
-
* //
|
|
143
|
+
* // JavaScript can return exit('complete'), exit('done'), or another registered alias.
|
|
144
|
+
* // These all select the same exit without creating additional native tools.
|
|
142
145
|
* ```
|
|
143
146
|
*
|
|
144
147
|
* ### Exit Metadata for Orchestration
|
|
@@ -216,26 +219,26 @@ export declare namespace Exit {
|
|
|
216
219
|
* @template T - The type of data this exit returns (inferred from schema)
|
|
217
220
|
*
|
|
218
221
|
* @see {@link ExecutionResult} For result handling
|
|
219
|
-
* @see {@link ThinkExit} Built-in thinking exit
|
|
220
222
|
* @see {@link ListenExit} Built-in chat listening exit
|
|
221
223
|
* @see {@link DefaultExit} Built-in completion exit
|
|
222
224
|
*/
|
|
223
225
|
export declare class Exit<T = unknown> implements Serializable<Exit.JSON> {
|
|
224
|
-
/** The primary name of the exit (used
|
|
226
|
+
/** The primary name of the exit (used by its native exit tool) */
|
|
225
227
|
name: string;
|
|
226
|
-
/**
|
|
228
|
+
/** Host-side aliases; the native tool uses only the primary name */
|
|
227
229
|
aliases: string[];
|
|
228
230
|
/** Human-readable description of when this exit should be used */
|
|
229
231
|
description: string;
|
|
230
232
|
/** Additional metadata for orchestration and custom logic */
|
|
231
233
|
metadata: Record<string, unknown>;
|
|
232
|
-
/**
|
|
234
|
+
/** Model-facing payload description. The original validator is retained in zSchema. */
|
|
233
235
|
schema?: JSONSchema7;
|
|
236
|
+
private _schema?;
|
|
234
237
|
/**
|
|
235
|
-
* Returns the
|
|
238
|
+
* Returns the original runtime validator, preserving transforms and refinements.
|
|
236
239
|
* Used internally for validation and type inference.
|
|
237
240
|
*/
|
|
238
|
-
get zSchema():
|
|
241
|
+
get zSchema(): z.ZodType<T, any, unknown> | undefined;
|
|
239
242
|
/**
|
|
240
243
|
* Renames the exit and updates aliases accordingly.
|
|
241
244
|
*
|
|
@@ -270,7 +273,7 @@ export declare class Exit<T = unknown> implements Serializable<Exit.JSON> {
|
|
|
270
273
|
* // customExit is independent of originalExit
|
|
271
274
|
* ```
|
|
272
275
|
*/
|
|
273
|
-
clone(): Exit<
|
|
276
|
+
clone(): Exit<T>;
|
|
274
277
|
/**
|
|
275
278
|
* Type guard to check if this exit matches another exit by name.
|
|
276
279
|
*
|
|
@@ -288,7 +291,7 @@ export declare class Exit<T = unknown> implements Serializable<Exit.JSON> {
|
|
|
288
291
|
*/
|
|
289
292
|
match(result: ExitResult): result is ExitResult<T>;
|
|
290
293
|
/**
|
|
291
|
-
* Serializes
|
|
294
|
+
* Serializes the model-facing description. JavaScript validators cannot be serialized; use clone() to retain them.
|
|
292
295
|
*
|
|
293
296
|
* @returns JSON representation of the exit
|
|
294
297
|
*
|
|
@@ -368,7 +371,7 @@ export declare class Exit<T = unknown> implements Serializable<Exit.JSON> {
|
|
|
368
371
|
aliases?: string[];
|
|
369
372
|
description: string;
|
|
370
373
|
metadata?: Record<string, unknown>;
|
|
371
|
-
schema?: ZuiType<T>;
|
|
374
|
+
schema?: ZuiType<T, unknown>;
|
|
372
375
|
});
|
|
373
376
|
/**
|
|
374
377
|
* Ensures all exits in an array have unique names by renaming duplicates.
|