llmz 0.8.0 → 1.0.1
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 +230 -1796
- package/ERRORS.md +98 -0
- package/README.md +96 -548
- 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-BpMVZYOa.cjs +649 -0
- package/dist/component-C27qu6Zv.js +614 -0
- package/dist/context.d.ts +74 -385
- package/dist/custom-client-BDkgBR2w.js +1631 -0
- package/dist/custom-client-MytucGI-.cjs +1708 -0
- package/dist/custom-client.d.ts +12 -2
- package/dist/errors/catalog.d.ts +287 -0
- package/dist/errors/hooks.d.ts +2 -0
- package/dist/errors-H4JJFH3S.js +620 -0
- package/dist/errors-IhnTKUp7.cjs +871 -0
- package/dist/errors.d.ts +18 -36
- package/dist/execute-BYI_U5sR.js +1943 -0
- package/dist/execute-DLas4V2n.cjs +1944 -0
- package/dist/{exit-DUM96DN1.cjs → exit-BUgJ5qi5.cjs} +38 -28
- package/dist/{exit-CDdxDBRT.js → exit-CPNk3vbz.js} +37 -27
- package/dist/exit.d.ts +19 -16
- package/dist/index.cjs +181 -999
- package/dist/index.d.ts +25 -28
- package/dist/index.js +141 -974
- package/dist/index.workerd.js +7725 -9531
- package/dist/inspect.d.ts +19 -3
- package/dist/inspection.d.ts +38 -0
- package/dist/native-Bm6L9zOb.cjs +212 -0
- package/dist/native-DvTH9vFe.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 -98
- package/dist/quickjs-variant-DJwYDSsb.cjs +1073 -0
- package/dist/quickjs-variant-DlPi9-Sx.js +984 -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-activity.test.d.ts +1 -0
- package/dist/runtime/execution-diagnostics.d.ts +11 -0
- package/dist/runtime/execution-diagnostics.test.d.ts +1 -0
- package/dist/runtime/execution-report.d.ts +48 -0
- package/dist/runtime/execution-report.test.d.ts +1 -0
- package/dist/runtime/execution-safety.test.d.ts +1 -0
- package/dist/runtime/exit-control-flow.test.d.ts +1 -0
- package/dist/runtime/fixtures/chat.d.ts +8 -0
- package/dist/runtime/fixtures/long-search.d.ts +19 -0
- package/dist/runtime/fixtures/long-search.test.d.ts +1 -0
- package/dist/runtime/fixtures/native-client.d.ts +33 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +74 -0
- package/dist/runtime/generate.d.ts +23 -27
- 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 +59 -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/protocol-adherence.test.d.ts +1 -0
- package/dist/runtime/single-tool.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 +4 -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 +41 -36
- 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-Aer_W7Al.js +45 -0
- package/dist/schema-DBkjo0b7.cjs +68 -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 +17 -0
- package/dist/session/messages.test.d.ts +1 -0
- package/dist/session/serialization.d.ts +34 -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 +117 -0
- package/dist/session/session.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--gK91eez.js} +144 -92
- package/dist/{tool-Dy6AJpJH.cjs → tool-Da_F-N-5.cjs} +146 -94
- package/dist/tool.d.ts +25 -17
- package/dist/truncate-BSoH2-nY.js +79 -0
- package/dist/truncate-nV3Mxr6-.cjs +102 -0
- package/dist/truncate.d.ts +24 -0
- package/dist/truncate.test.d.ts +1 -0
- package/dist/types.d.ts +27 -9
- package/dist/{typings-3lsqCbkn.cjs → typings-C1ihexWE.cjs} +38 -193
- package/dist/{typings-CrBa7Tyy.js → typings-D9_aC8aq.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 +18 -3
- package/dist/{vm-BLsHw1da.js → vm-8jxt8PTK.js} +1162 -180
- package/dist/{vm-D6s1zF6M.cjs → vm-XuVPuW3Y.cjs} +1195 -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-DdArNQhl.cjs +0 -643
- package/dist/common-pgJjFu2Y.js +0 -596
- 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-BXS8vAwO.cjs +0 -73
- package/dist/component-Dq7ZLdvy.js +0 -44
- package/dist/component.d.ts +0 -88
- package/dist/component.default.d.ts +0 -268
- package/dist/custom-client-2V9lmzUf.js +0 -2655
- package/dist/custom-client-HkM1Sdzv.cjs +0 -2726
- package/dist/dual-modes-Cb7ThvoV.cjs +0 -3020
- package/dist/dual-modes-Cy0_W4O2.js +0 -2930
- package/dist/errors-C962uJdS.cjs +0 -220
- package/dist/errors-Cg1G0Awu.js +0 -161
- package/dist/example.d.ts +0 -45
- package/dist/execute-Aw4cbIx-.js +0 -1080
- package/dist/execute-COIHOIKR.cjs +0 -1081
- 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/jsx-B0iYyvfr.js +0 -100
- package/dist/jsx-D5Y2cPo-.cjs +0 -129
- package/dist/jsx.d.ts +0 -11
- package/dist/message-stream/index.d.ts +0 -9
- package/dist/message-stream/instructions.d.ts +0 -22
- package/dist/message-stream/normalizer.d.ts +0 -21
- package/dist/message-stream/parser.d.ts +0 -83
- package/dist/message-stream/registry.d.ts +0 -14
- package/dist/message-stream/replayable.d.ts +0 -27
- 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 -96
- package/dist/message-stream/validator.d.ts +0 -23
- 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/common.d.ts +0 -6
- 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.d.ts +0 -18
- 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/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/stream.test.d.ts → result.test.d.ts} +0 -0
- /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
- /package/dist/{prompts/common.test.d.ts → runtime/citations.test.d.ts} +0 -0
- /package/dist/{prompts/protocol.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
- /package/dist/runtime/{interpret-result.test.d.ts → context-registration.test.d.ts} +0 -0
- /package/dist/{transcript.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
- /package/dist/{truncator.test.d.ts → runtime/errors.test.d.ts} +0 -0
package/ERRORS.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Errors and recovery
|
|
2
|
+
|
|
3
|
+
Every library failure has a stable `code`, a readable `message`, and a `critical` flag. Each class exports a detachable `.is(value)` type guard. `isLLMzError(value, code)` narrows the same discriminated union by code. Guards use a shared `Symbol.for` brand plus the error code, so they work across independently loaded copies of LLMz and after the runtime restores a QuickJS exception. They do not rely on `instanceof`, class names, or message matching.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { ToolInputError, isLLMzError, isCriticalError, type Iteration } from 'llmz'
|
|
7
|
+
|
|
8
|
+
function observe(iteration: Iteration) {
|
|
9
|
+
// Includes tool failures that generated JavaScript caught and handled itself.
|
|
10
|
+
for (const error of iteration.errors) {
|
|
11
|
+
if (ToolInputError.is(error)) {
|
|
12
|
+
console.log(error.toolName, error.issues, error.expectedInput)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const error = iteration.exception
|
|
17
|
+
if (isLLMzError(error, 'EXECUTION_FAILED')) {
|
|
18
|
+
// The wrapper retains source location information and the original typed cause.
|
|
19
|
+
console.log(error.source, error.stacktrace)
|
|
20
|
+
if (ToolInputError.is(error.cause)) {
|
|
21
|
+
console.log(error.cause.expectedInput)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isCriticalError(error)) {
|
|
26
|
+
console.error('Execution cannot continue:', error.code)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Pass `observe` as `onIterationEnd`. `iteration.error` remains the readable string summary; `iteration.exception` is the typed failure that ended the iteration. `iteration.errors` also includes observed tool/component/exit failures and memory retention errors, including failures handled inside generated code. A recovered execution keeps the failed iterations in `result.iterations`; a successful iteration can have errors in its diagnostics without an `exception`.
|
|
32
|
+
|
|
33
|
+
`result.isError()` exposes a typed `result.error`. An exhausted iteration budget is a run-level `LoopExceededError`; the last iteration keeps its original exception, and its `errors` list also receives the limit error. This limit is detected after that iteration's end hook. Configuration failures can occur before an iteration exists. Constructors, `session.append()`, and standalone session operations throw directly to their caller.
|
|
34
|
+
|
|
35
|
+
A **non-critical** iteration failure produces feedback and permits another model call within the remaining iteration budget. It does not promise that retrying an external action is safe. Feedback records acknowledged tool results and deliveries, discloses uncertain effects, and tells the model not to repeat completed actions blindly. The model may correct its arguments, choose another tool, or complete through an appropriate exit.
|
|
36
|
+
|
|
37
|
+
Original schema refinements are enforced for tool inputs, exit payloads, component props, and object-property assignments. Their issues use the corresponding input/property error below. Async effects are supported for tool inputs; using them on synchronous exit, component, or property APIs raises critical `InvalidConfigurationError`. A schema callback that throws instead of reporting a validation issue is also a configuration failure. Tool output schemas are documentation only: unexpected tool return values do not produce schema-validation errors.
|
|
38
|
+
|
|
39
|
+
A **critical** failure stops the execution without another model call. Critical tool failures remain fatal even if generated JavaScript catches them; later host operations are closed. Examples include provider failures, token overflow, failed compaction, cancellation, and memory capacity exhaustion. A hook can reject an iteration with an ordinary error (reported as `HookError`), or stop execution with a critical typed error or its abort controller. Observational callbacks remain observational; `onIterationEnd` propagates explicitly critical failures.
|
|
40
|
+
|
|
41
|
+
## Complete catalogue
|
|
42
|
+
|
|
43
|
+
“Recoverable” below means the runtime may continue when the failure occurs in an active iteration. Errors thrown by standalone methods are returned to the caller.
|
|
44
|
+
|
|
45
|
+
| Code | Exported class | Handling and details |
|
|
46
|
+
| ------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `INVALID_CODE` | `InvalidCodeError` | Recoverable. Invalid JavaScript or unsupported dynamic code; `source` retains the program. |
|
|
48
|
+
| `EXECUTION_FAILED` | `CodeExecutionError` | Recoverable unless its cause is critical. `source`, `stacktrace`, `originalErrorName`, and `cause` preserve execution context. |
|
|
49
|
+
| `UNKNOWN_TOOL` | `UnknownToolError` | Recoverable. Missing callable or unrecognized native tool; `toolName`, `availableTools`. |
|
|
50
|
+
| `INVALID_TOOL_INPUT` | `ToolInputError` | Recoverable. Handler never ran; `toolName`, `issues`, `expectedInput`. |
|
|
51
|
+
| `TOOL_EXECUTION_FAILED` | `ToolExecutionError` | Recoverable. Handler failed after its configured retry policy; `toolName`, original `cause`. Effects may have occurred. |
|
|
52
|
+
| `RESERVED_IDENTIFIER` | `ReservedIdentifierError` | Generated variable declarations are recoverable. Registered tools, objects, exits, and components are critical configuration failures. `identifier`, `kind`. The conventional `exit` exit name remains supported. |
|
|
53
|
+
| `INVALID_ASSIGNMENT` | `AssignmentError` | Recoverable. Read-only assignment or generated variable/object namespace collision. |
|
|
54
|
+
| `INVALID_OBJECT_PROPERTY` | `ObjectPropertyError` | Recoverable. Rejected whole-property assignment; `objectName`, `propertyName`, `issues`, `expectedInput`. |
|
|
55
|
+
| `UNKNOWN_EXIT` | `UnknownExitError` | Recoverable. `exitName`, `availableExits`. No exit was applied. |
|
|
56
|
+
| `INVALID_EXIT_INPUT` | `ExitInputError` | Recoverable. `exitName`, `issues`, `expectedInput`. No exit was applied. |
|
|
57
|
+
| `UNKNOWN_COMPONENT` | `UnknownComponentError` | Recoverable. Missing `chat` method, including computed property access; `componentName`, `availableComponents`. No message was sent. |
|
|
58
|
+
| `INVALID_COMPONENT_INPUT` | `ComponentInputError` | Recoverable. `componentName`, `issues`, `expectedInput`. No message was sent. |
|
|
59
|
+
| `INVALID_NATIVE_CALL` | `NativeProtocolError` | Recoverable. Malformed native call, invalid JavaScript envelope, or multiple calls in one response. The rejected batch did not execute. |
|
|
60
|
+
| `HOST_OPERATION_FAILED` | `HostOperationError` | Recoverable. Unawaited tool or operation after JavaScript completion. Started work is joined; feedback distinguishes its effects. |
|
|
61
|
+
| `DELIVERY_FAILED` | `DeliveryError` | Recoverable. Text/component handler failed. Earlier acknowledged sends remain delivered; later queued sends are skipped. Inspect `cause`. |
|
|
62
|
+
| `HOOK_FAILED` | `HookError` | Recoverable. A hook rejected an operation; original `cause` is retained. |
|
|
63
|
+
| `INVALID_MEMORY_VALUE` | `MemoryValueError` | Recoverable. Unsupported/cyclic memory or inspection value. Failed captures also appear in `iteration.errors` and the memory report. |
|
|
64
|
+
| `ITERATION_LIMIT` | `LoopExceededError` | Critical. `limit` is the configured iteration count. |
|
|
65
|
+
| `GENERATION_FAILED` | `CognitiveError` | Critical. Provider failure, malformed generation, content filtering, or incomplete response; original provider failure is retained as `cause` when available. |
|
|
66
|
+
| `TOKEN_OVERFLOW` | `TokenOverflowError` | Critical. `phase` distinguishes input context overflow from output `max_tokens`; `tokens` and `limit` are supplied when known. |
|
|
67
|
+
| `COMPACTION_FAILED` | `CompactionError` | Critical. Summary generation or validation failed; history is preserved. Inspect `cause`. |
|
|
68
|
+
| `MEMORY_CAPACITY` | `MemoryCapacityError` | Critical. Retained memory exceeds `maxBytes`. Completed effects must not be replayed. |
|
|
69
|
+
| `EXECUTION_ABORTED` | `ExecutionAbortedError` | Critical. Cancellation or timeout; `cause` retains the original abort reason. |
|
|
70
|
+
| `INVALID_TOOL` | `InvalidToolError` | Critical. Invalid tool definition or tool configuration. |
|
|
71
|
+
| `INVALID_OBJECT` | `InvalidObjectError` | Critical. Invalid object definition or property registration. |
|
|
72
|
+
| `INVALID_EXIT` | `InvalidExitError` | Critical. Invalid exit definition or exit configuration. |
|
|
73
|
+
| `INVALID_COMPONENT` | `InvalidComponentError` | Critical. Invalid component definition or registration. |
|
|
74
|
+
| `INVALID_CONFIG` | `InvalidConfigurationError` | Critical. Invalid execution/chat/token/compaction settings or conflicting bindings. |
|
|
75
|
+
| `INVALID_MESSAGE` | `InvalidMessageError` | Critical. Invalid user/assistant input or input batch. Nothing is appended. |
|
|
76
|
+
| `INVALID_EVENT` | `InvalidEventError` | Critical. Invalid event name or non-persistable payload. Nothing is appended. |
|
|
77
|
+
| `INVALID_SESSION` | `InvalidSessionError` | Critical. Invalid persisted history, native messages, or serialized session data. |
|
|
78
|
+
| `SESSION_STATE` | `SessionStateError` | Critical. Concurrent execution or an operation incompatible with the current session lifecycle. |
|
|
79
|
+
| `CODE_FORMATTING_FAILED` | `CodeFormattingError` | Critical. Invalid generated API typings; `source` contains the failed type declaration. |
|
|
80
|
+
| `INTERNAL_ERROR` | `InternalError` | Critical. Unexpected library failure outside a recognized boundary; inspect `cause`. |
|
|
81
|
+
|
|
82
|
+
Compaction cannot guarantee that every request fits: instructions, tools, queued input, and mandatory context can exceed the entire budget. Input estimates also cannot predict all provider-specific media usage. Compaction does not prevent an output token limit. These cases must remain detectable by consumers.
|
|
83
|
+
|
|
84
|
+
Validation errors include a path/message list and the expected argument shape as TypeScript. Constraints such as minimum lengths and numeric bounds remain in `issues`; TypeScript shapes alone cannot express them. Error text is for humans and model recovery; use codes and guards for application decisions.
|
|
85
|
+
|
|
86
|
+
`ThinkSignal` is control flow, not a failure. Use `ThinkSignal.is(value)` to detect it across imports. It has no error code and is not collected in `iteration.errors`.
|
|
87
|
+
|
|
88
|
+
## Inspecting recovery prompts
|
|
89
|
+
|
|
90
|
+
[`src/runtime/error-recovery.test.ts`](./src/runtime/error-recovery.test.ts) runs scripted, mocked LLM responses through the real runtime and both VM drivers. Its `.toMatchInlineSnapshot()` assertions show the tool-result feedback actually present in the next model request, including the expected input types. Memory and iteration-budget footers are excluded from the catalogue snapshot so the failure feedback is easy to review. Critical-error tests in [`src/runtime/errors.test.ts`](./src/runtime/errors.test.ts) assert that no additional provider call or business action occurs.
|
|
91
|
+
|
|
92
|
+
Recovery feedback uses XML-style sections: `<error>` contains the specific error code and readable message, `<stack_trace>` shows source-mapped guest code with line numbers and carets, and `<recovery>` explains how to continue. Tool calls, sent messages, memory changes, and inspection results each have their own section. Content containing XML characters is enclosed in CDATA so code examples, entity literals, and retrieval tags stay unchanged without closing a section. Validation messages preserve line breaks and the expected TypeScript shape.
|
|
93
|
+
|
|
94
|
+
Source traces are bounded previews around the failure sites, including failures near the end of long programs. The complete annotated source remains available as `CodeExecutionError.stacktrace`. Node and QuickJS may report different column precision; the inline snapshots cover each. Compiler errors show the invalid source. Host failures outside guest execution retain their original `cause` for consumers; the model is not shown a misleading guest stack or internal host paths.
|
|
95
|
+
|
|
96
|
+
A `ThinkSignal` report separates its reason, guest interruption site (when available), and context. It tells the model to review that context and continue from retained values and acknowledged effects. It does not resume the suspended JavaScript stack.
|
|
97
|
+
|
|
98
|
+
`toJSON()` and `result.diagnostics()` retain codes, messages, criticality, and nested error diagnostics. They are plain data: JSON does not retain the shared symbol brand or Error prototypes, so class guards intentionally do not accept parsed diagnostic JSON. The VM restores typed errors internally before exposing them on iterations.
|