llmz 0.9.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.
Files changed (231) hide show
  1. package/DOCS.md +230 -1796
  2. package/ERRORS.md +98 -0
  3. package/README.md +96 -582
  4. package/dist/chat/chat.d.ts +63 -0
  5. package/dist/chat/component.d.ts +31 -0
  6. package/dist/chat/component.default.d.ts +58 -0
  7. package/dist/chat/response.d.ts +15 -0
  8. package/dist/compiler/compiler.d.ts +2 -7
  9. package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
  10. package/dist/compiler/plugins/replace-comment.d.ts +2 -3
  11. package/dist/compiler/plugins/return-async.d.ts +5 -4
  12. package/dist/compiler/plugins/termination.d.ts +8 -0
  13. package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
  14. package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
  15. package/dist/component-BpMVZYOa.cjs +649 -0
  16. package/dist/component-C27qu6Zv.js +614 -0
  17. package/dist/context.d.ts +70 -377
  18. package/dist/custom-client-BDkgBR2w.js +1631 -0
  19. package/dist/custom-client-MytucGI-.cjs +1708 -0
  20. package/dist/custom-client.d.ts +12 -2
  21. package/dist/errors/catalog.d.ts +287 -0
  22. package/dist/errors/hooks.d.ts +2 -0
  23. package/dist/errors-H4JJFH3S.js +620 -0
  24. package/dist/errors-IhnTKUp7.cjs +871 -0
  25. package/dist/errors.d.ts +18 -36
  26. package/dist/execute-BYI_U5sR.js +1943 -0
  27. package/dist/execute-DLas4V2n.cjs +1944 -0
  28. package/dist/{exit-DUM96DN1.cjs → exit-BUgJ5qi5.cjs} +38 -28
  29. package/dist/{exit-CDdxDBRT.js → exit-CPNk3vbz.js} +37 -27
  30. package/dist/exit.d.ts +19 -16
  31. package/dist/index.cjs +176 -1237
  32. package/dist/index.d.ts +25 -28
  33. package/dist/index.js +137 -1213
  34. package/dist/index.workerd.js +8427 -10771
  35. package/dist/inspect.d.ts +18 -4
  36. package/dist/inspection.d.ts +38 -0
  37. package/dist/native-Bm6L9zOb.cjs +212 -0
  38. package/dist/native-DvTH9vFe.js +177 -0
  39. package/dist/objects.d.ts +2 -57
  40. package/dist/prompts/native.d.ts +2 -0
  41. package/dist/prompts/prompt.d.ts +10 -101
  42. package/dist/quickjs-variant-DJwYDSsb.cjs +1073 -0
  43. package/dist/quickjs-variant-DlPi9-Sx.js +984 -0
  44. package/dist/result.d.ts +30 -861
  45. package/dist/runtime/execute.d.ts +3 -2
  46. package/dist/runtime/execution-activity.d.ts +11 -0
  47. package/dist/runtime/execution-diagnostics.d.ts +11 -0
  48. package/dist/runtime/execution-report.d.ts +48 -0
  49. package/dist/runtime/fixtures/chat.d.ts +8 -0
  50. package/dist/runtime/fixtures/long-search.d.ts +1 -1
  51. package/dist/runtime/fixtures/native-client.d.ts +33 -0
  52. package/dist/runtime/fixtures/protocol-languages.d.ts +1 -1
  53. package/dist/runtime/generate.d.ts +23 -20
  54. package/dist/runtime/inspection-values.d.ts +14 -0
  55. package/dist/runtime/inspection-values.test.d.ts +1 -0
  56. package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
  57. package/dist/runtime/interruption-settings.test.d.ts +1 -0
  58. package/dist/runtime/javascript-api.d.ts +59 -0
  59. package/dist/runtime/javascript-api.test.d.ts +1 -0
  60. package/dist/runtime/native-review.test.d.ts +1 -0
  61. package/dist/runtime/native-tools.d.ts +18 -0
  62. package/dist/runtime/native-tools.test.d.ts +1 -0
  63. package/dist/runtime/object-memory.test.d.ts +1 -0
  64. package/dist/runtime/single-tool.test.d.ts +1 -0
  65. package/dist/runtime/token-budget.d.ts +22 -0
  66. package/dist/runtime/token-budget.test.d.ts +1 -0
  67. package/dist/runtime/tool-wrapper.d.ts +4 -5
  68. package/dist/runtime/traces.test.d.ts +1 -0
  69. package/dist/runtime/truncation.test.d.ts +1 -0
  70. package/dist/runtime/types.d.ts +39 -31
  71. package/dist/runtime/variable-recovery.test.d.ts +1 -0
  72. package/dist/runtime/vm-context.d.ts +6 -1
  73. package/dist/runtime/worker-completion.test.d.ts +1 -0
  74. package/dist/runtime-names.d.ts +4 -0
  75. package/dist/schema-Aer_W7Al.js +45 -0
  76. package/dist/schema-DBkjo0b7.cjs +68 -0
  77. package/dist/schema.d.ts +10 -0
  78. package/dist/schema.test.d.ts +1 -0
  79. package/dist/session/compactor.d.ts +51 -0
  80. package/dist/session/compactor.test.d.ts +1 -0
  81. package/dist/session/history.d.ts +36 -0
  82. package/dist/session/history.test.d.ts +1 -0
  83. package/dist/session/json.d.ts +3 -0
  84. package/dist/session/json.test.d.ts +1 -0
  85. package/dist/session/memory-codec.d.ts +9 -0
  86. package/dist/session/memory-codec.test.d.ts +1 -0
  87. package/dist/session/memory-render.d.ts +15 -0
  88. package/dist/session/memory-render.test.d.ts +1 -0
  89. package/dist/session/memory.d.ts +112 -0
  90. package/dist/session/memory.test.d.ts +1 -0
  91. package/dist/session/messages.d.ts +17 -0
  92. package/dist/session/messages.test.d.ts +1 -0
  93. package/dist/session/serialization.d.ts +34 -0
  94. package/dist/session/serialization.test.d.ts +1 -0
  95. package/dist/session/session-memory.test.d.ts +1 -0
  96. package/dist/session/session.d.ts +117 -0
  97. package/dist/session/session.test.d.ts +1 -0
  98. package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
  99. package/dist/session/transcript.test.d.ts +1 -0
  100. package/dist/{tool-Bv8N4IPj.js → tool--gK91eez.js} +144 -92
  101. package/dist/{tool-Dy6AJpJH.cjs → tool-Da_F-N-5.cjs} +146 -94
  102. package/dist/tool.d.ts +25 -17
  103. package/dist/truncate-BSoH2-nY.js +79 -0
  104. package/dist/truncate-nV3Mxr6-.cjs +102 -0
  105. package/dist/truncate.d.ts +24 -0
  106. package/dist/truncate.test.d.ts +1 -0
  107. package/dist/types.d.ts +27 -9
  108. package/dist/{typings-3lsqCbkn.cjs → typings-C1ihexWE.cjs} +38 -193
  109. package/dist/{typings-CrBa7Tyy.js → typings-D9_aC8aq.js} +38 -175
  110. package/dist/typings-formatter.d.ts +1 -1
  111. package/dist/typings.d.ts +3 -0
  112. package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
  113. package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
  114. package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
  115. package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
  116. package/dist/vm/drivers/node.d.ts +1 -1
  117. package/dist/vm/drivers/quickjs.d.ts +1 -1
  118. package/dist/vm/errors.d.ts +4 -4
  119. package/dist/vm/index.d.ts +3 -4
  120. package/dist/vm/instrument.d.ts +14 -6
  121. package/dist/vm/member-proxy.d.ts +4 -0
  122. package/dist/vm/member-proxy.test.d.ts +1 -0
  123. package/dist/vm/memory.test.d.ts +1 -0
  124. package/dist/vm/return-semantics.test.d.ts +1 -0
  125. package/dist/vm/types.d.ts +18 -3
  126. package/dist/{vm-BLsHw1da.js → vm-8jxt8PTK.js} +1162 -180
  127. package/dist/{vm-D6s1zF6M.cjs → vm-XuVPuW3Y.cjs} +1195 -207
  128. package/package.json +13 -6
  129. package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
  130. package/dist/_baseForOwn-CFhWe_W6.js +0 -48
  131. package/dist/_getPrototype-CG7Dxrrz.js +0 -6
  132. package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
  133. package/dist/_overArg-C5Hy7oCi.cjs +0 -196
  134. package/dist/_overArg-CRYbj1NH.js +0 -155
  135. package/dist/chat.d.ts +0 -401
  136. package/dist/common-BlRFtdf2.js +0 -807
  137. package/dist/common-BnvrDnIT.cjs +0 -860
  138. package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
  139. package/dist/compiler-C-OI9sim.cjs +0 -547
  140. package/dist/compiler-CW1VjQsn.js +0 -473
  141. package/dist/component-C6Agl2ns.cjs +0 -73
  142. package/dist/component-DGG7d_Mz.js +0 -44
  143. package/dist/component.d.ts +0 -88
  144. package/dist/component.default.d.ts +0 -278
  145. package/dist/custom-client-ChuZ63zp.js +0 -2658
  146. package/dist/custom-client-DAsGRnYc.cjs +0 -2729
  147. package/dist/dual-modes-DDkoCp3R.js +0 -3006
  148. package/dist/dual-modes-DPXiuvNe.cjs +0 -3090
  149. package/dist/errors-C962uJdS.cjs +0 -220
  150. package/dist/errors-Cg1G0Awu.js +0 -161
  151. package/dist/example-format.d.ts +0 -8
  152. package/dist/example.d.ts +0 -45
  153. package/dist/execute-BWcdv9so.js +0 -1059
  154. package/dist/execute-DM2-7y86.cjs +0 -1060
  155. package/dist/exit-parser.d.ts +0 -39
  156. package/dist/handlers.d.ts +0 -10
  157. package/dist/hoist.d.ts +0 -2
  158. package/dist/isEmpty-BhJRCqIF.js +0 -52
  159. package/dist/isEmpty-LY533Wmh.cjs +0 -57
  160. package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
  161. package/dist/isPlainObject-D39AzPO2.js +0 -51
  162. package/dist/jsx-CIgdGGVs.js +0 -52
  163. package/dist/jsx-owqxrquU.cjs +0 -75
  164. package/dist/jsx.d.ts +0 -11
  165. package/dist/message-stream/index.d.ts +0 -9
  166. package/dist/message-stream/instructions.d.ts +0 -30
  167. package/dist/message-stream/normalizer.d.ts +0 -21
  168. package/dist/message-stream/parser.d.ts +0 -89
  169. package/dist/message-stream/registry.d.ts +0 -14
  170. package/dist/message-stream/replayable.d.ts +0 -27
  171. package/dist/message-stream/response-parser.d.ts +0 -24
  172. package/dist/message-stream/sanitize.d.ts +0 -10
  173. package/dist/message-stream/stream.d.ts +0 -54
  174. package/dist/message-stream/types.d.ts +0 -97
  175. package/dist/message-stream/validator.d.ts +0 -23
  176. package/dist/prompts/chat-mode/protocol.d.ts +0 -2
  177. package/dist/prompts/chat-mode/system.d.ts +0 -2
  178. package/dist/prompts/chat-mode/system.md.d.ts +0 -2
  179. package/dist/prompts/chat-mode/user.d.ts +0 -2
  180. package/dist/prompts/chat-mode/user.md.d.ts +0 -2
  181. package/dist/prompts/code-examples.d.ts +0 -2
  182. package/dist/prompts/common.d.ts +0 -7
  183. package/dist/prompts/dual-modes.d.ts +0 -2
  184. package/dist/prompts/execution-history.d.ts +0 -6
  185. package/dist/prompts/execution-state.d.ts +0 -3
  186. package/dist/prompts/protocol-basics.d.ts +0 -5
  187. package/dist/prompts/protocol.d.ts +0 -31
  188. package/dist/prompts/worker-mode/protocol.d.ts +0 -2
  189. package/dist/prompts/worker-mode/system.d.ts +0 -2
  190. package/dist/prompts/worker-mode/system.md.d.ts +0 -2
  191. package/dist/prompts/worker-mode/user.d.ts +0 -2
  192. package/dist/prompts/worker-mode/user.md.d.ts +0 -2
  193. package/dist/quickjs-variant-BYhMBpwU.js +0 -45
  194. package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
  195. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  196. package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +0 -29
  197. package/dist/runtime/interpret-result.d.ts +0 -22
  198. package/dist/snapshots.d.ts +0 -249
  199. package/dist/stack-traces-BIE_5Xwf.js +0 -21
  200. package/dist/stack-traces-ntw_qhoy.cjs +0 -26
  201. package/dist/truncator-CLkouTCO.cjs +0 -276
  202. package/dist/truncator-DZqEqnpD.js +0 -253
  203. package/dist/truncator.d.ts +0 -118
  204. package/dist/utils-3ESwP3yg.cjs +0 -1075
  205. package/dist/utils-UBeAFeEI.js +0 -950
  206. /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
  207. /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
  208. /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
  209. /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
  210. /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
  211. /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
  212. /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
  213. /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
  214. /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
  215. /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
  216. /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
  217. /package/dist/{message-stream/response-parser.test.d.ts → result.test.d.ts} +0 -0
  218. /package/dist/{message-stream/stream.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
  219. /package/dist/{message-stream/validator.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
  220. /package/dist/{prompts/adherence.test.d.ts → runtime/context-registration.test.d.ts} +0 -0
  221. /package/dist/{prompts/catalogue-examples.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
  222. /package/dist/{prompts/code-examples.test.d.ts → runtime/errors.test.d.ts} +0 -0
  223. /package/dist/{prompts/common.test.d.ts → runtime/execution-activity.test.d.ts} +0 -0
  224. /package/dist/{prompts/concrete-patterns.test.d.ts → runtime/execution-diagnostics.test.d.ts} +0 -0
  225. /package/dist/{prompts/long-search.test.d.ts → runtime/execution-report.test.d.ts} +0 -0
  226. /package/dist/{prompts/protocol-simple.test.d.ts → runtime/execution-safety.test.d.ts} +0 -0
  227. /package/dist/{prompts/protocol.test.d.ts → runtime/exit-control-flow.test.d.ts} +0 -0
  228. /package/dist/{prompts/sections.test.d.ts → runtime/fixtures/long-search.test.d.ts} +0 -0
  229. /package/dist/runtime/{interpret-result.test.d.ts → generate.test.d.ts} +0 -0
  230. /package/dist/{transcript.test.d.ts → runtime/hook-provenance.test.d.ts} +0 -0
  231. /package/dist/{truncator.test.d.ts → runtime/inspection-hook.test.d.ts} +0 -0
@@ -1,220 +0,0 @@
1
- const require_stack_traces = require("./stack-traces-ntw_qhoy.cjs");
2
- //#region src/errors.ts
3
- const errorClasses = {};
4
- function registerErrorClass(name, errorClass) {
5
- errorClasses[name] = errorClass;
6
- }
7
- const tryParseMessage = (str) => {
8
- try {
9
- return JSON.parse(str);
10
- } catch {
11
- return str;
12
- }
13
- };
14
- let Signals;
15
- (function(_Signals) {
16
- function isWrappedError(error) {
17
- var _error$message, _error$message2;
18
- 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("}"));
19
- }
20
- _Signals.isWrappedError = isWrappedError;
21
- function serializeError(error) {
22
- if (isWrappedError(error)) {
23
- const msg = tryParseMessage(error.message);
24
- return JSON.stringify({
25
- ...typeof msg === "object" ? msg : { message: msg },
26
- properties: { ...error }
27
- });
28
- }
29
- return JSON.stringify({
30
- name: error.constructor.name,
31
- message: error.message,
32
- stack: require_stack_traces.cleanStackTrace(error.stack ?? ""),
33
- properties: { ...error }
34
- });
35
- }
36
- _Signals.serializeError = serializeError;
37
- function maybeDeserializeError(error) {
38
- if (error instanceof Error && error.name in errorClasses) return error;
39
- const serializedError = error instanceof Error ? error.message : typeof error === "string" ? error : (error === null || error === void 0 ? void 0 : error.toString()) ?? "";
40
- try {
41
- const parsed = JSON.parse(serializedError);
42
- if (parsed && parsed.name && parsed.message) {
43
- const { name, message, properties = {} } = parsed;
44
- const errorInstance = new (errorClasses[name] || Error)(message);
45
- errorInstance.message = message;
46
- errorInstance.name = name;
47
- errorInstance.stack = require_stack_traces.cleanStackTrace((error === null || error === void 0 ? void 0 : error.stack) ?? "");
48
- Object.assign(errorInstance, properties);
49
- if (isWrappedError(errorInstance)) return maybeDeserializeError(errorInstance);
50
- return errorInstance;
51
- }
52
- } catch {}
53
- return error;
54
- }
55
- _Signals.maybeDeserializeError = maybeDeserializeError;
56
- })(Signals || (Signals = {}));
57
- var VMSignal = class extends Error {
58
- message;
59
- /**
60
- * The code that was executed by the VM up to the point of the signal
61
- */
62
- truncatedCode = "";
63
- /** The current tool call, if any */
64
- toolCall;
65
- /**
66
- * Contains all the declared and executed variables during the VM execution
67
- * See file plugins/variable-extraction.ts for more details
68
- */
69
- variables = {};
70
- constructor(message) {
71
- super(message);
72
- this.message = message;
73
- this.message = Signals.serializeError(this);
74
- }
75
- };
76
- /** Request a snapshot from inside a tool call */
77
- var SnapshotSignal = class extends VMSignal {
78
- constructor(message) {
79
- super(message);
80
- this.message = Signals.serializeError(this);
81
- }
82
- };
83
- /** Loop means LLMz will continue the execution (unless it exhausted its iterations) */
84
- var VMLoopSignal = class extends VMSignal {
85
- constructor(message) {
86
- super(message);
87
- this.message = Signals.serializeError(this);
88
- }
89
- };
90
- var ThinkSignal = class extends VMLoopSignal {
91
- reason;
92
- context;
93
- metadata;
94
- constructor(reason, context, metadata) {
95
- super("Think signal received: " + reason);
96
- this.reason = reason;
97
- this.context = context;
98
- this.metadata = metadata;
99
- this.message = Signals.serializeError(this);
100
- this.stack = "";
101
- }
102
- toString() {
103
- return Signals.serializeError(this);
104
- }
105
- };
106
- var CodeExecutionError = class extends Error {
107
- code;
108
- stacktrace;
109
- constructor(message, code, stacktrace) {
110
- super(message);
111
- this.code = code;
112
- this.stacktrace = stacktrace;
113
- this.message = Signals.serializeError(this);
114
- }
115
- };
116
- var InvalidCodeError = class extends Error {
117
- code;
118
- constructor(message, code) {
119
- super(message);
120
- this.code = code;
121
- this.message = Signals.serializeError(this);
122
- this.stack = "";
123
- }
124
- };
125
- var LoopExceededError = class extends Error {
126
- constructor() {
127
- super("Loop exceeded error");
128
- this.message = Signals.serializeError(this);
129
- this.stack = "";
130
- }
131
- };
132
- var CodeFormattingError = class extends Error {
133
- code;
134
- constructor(message, code) {
135
- super(message, { cause: "Code formatting error" });
136
- this.code = code;
137
- this.stack = "";
138
- }
139
- };
140
- var AssignmentError = class extends Error {
141
- constructor(message) {
142
- super(message);
143
- this.message = Signals.serializeError(this);
144
- }
145
- };
146
- var CognitiveError = class extends Error {
147
- constructor(message) {
148
- super(message);
149
- this.message = Signals.serializeError(this);
150
- this.stack = "";
151
- }
152
- };
153
- registerErrorClass("VMSignal", VMSignal);
154
- registerErrorClass("SnapshotSignal", SnapshotSignal);
155
- registerErrorClass("VMLoopSignal", VMLoopSignal);
156
- registerErrorClass("ThinkSignal", ThinkSignal);
157
- registerErrorClass("CodeExecutionError", CodeExecutionError);
158
- registerErrorClass("AssignmentError", AssignmentError);
159
- registerErrorClass("CognitiveError", CognitiveError);
160
- //#endregion
161
- Object.defineProperty(exports, "AssignmentError", {
162
- enumerable: true,
163
- get: function() {
164
- return AssignmentError;
165
- }
166
- });
167
- Object.defineProperty(exports, "CodeExecutionError", {
168
- enumerable: true,
169
- get: function() {
170
- return CodeExecutionError;
171
- }
172
- });
173
- Object.defineProperty(exports, "CodeFormattingError", {
174
- enumerable: true,
175
- get: function() {
176
- return CodeFormattingError;
177
- }
178
- });
179
- Object.defineProperty(exports, "CognitiveError", {
180
- enumerable: true,
181
- get: function() {
182
- return CognitiveError;
183
- }
184
- });
185
- Object.defineProperty(exports, "InvalidCodeError", {
186
- enumerable: true,
187
- get: function() {
188
- return InvalidCodeError;
189
- }
190
- });
191
- Object.defineProperty(exports, "LoopExceededError", {
192
- enumerable: true,
193
- get: function() {
194
- return LoopExceededError;
195
- }
196
- });
197
- Object.defineProperty(exports, "Signals", {
198
- enumerable: true,
199
- get: function() {
200
- return Signals;
201
- }
202
- });
203
- Object.defineProperty(exports, "SnapshotSignal", {
204
- enumerable: true,
205
- get: function() {
206
- return SnapshotSignal;
207
- }
208
- });
209
- Object.defineProperty(exports, "ThinkSignal", {
210
- enumerable: true,
211
- get: function() {
212
- return ThinkSignal;
213
- }
214
- });
215
- Object.defineProperty(exports, "VMSignal", {
216
- enumerable: true,
217
- get: function() {
218
- return VMSignal;
219
- }
220
- });
@@ -1,161 +0,0 @@
1
- import { t as cleanStackTrace } from "./stack-traces-BIE_5Xwf.js";
2
- //#region src/errors.ts
3
- const errorClasses = {};
4
- function registerErrorClass(name, errorClass) {
5
- errorClasses[name] = errorClass;
6
- }
7
- const tryParseMessage = (str) => {
8
- try {
9
- return JSON.parse(str);
10
- } catch {
11
- return str;
12
- }
13
- };
14
- let Signals;
15
- (function(_Signals) {
16
- function isWrappedError(error) {
17
- var _error$message, _error$message2;
18
- 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("}"));
19
- }
20
- _Signals.isWrappedError = isWrappedError;
21
- function serializeError(error) {
22
- if (isWrappedError(error)) {
23
- const msg = tryParseMessage(error.message);
24
- return JSON.stringify({
25
- ...typeof msg === "object" ? msg : { message: msg },
26
- properties: { ...error }
27
- });
28
- }
29
- return JSON.stringify({
30
- name: error.constructor.name,
31
- message: error.message,
32
- stack: cleanStackTrace(error.stack ?? ""),
33
- properties: { ...error }
34
- });
35
- }
36
- _Signals.serializeError = serializeError;
37
- function maybeDeserializeError(error) {
38
- if (error instanceof Error && error.name in errorClasses) return error;
39
- const serializedError = error instanceof Error ? error.message : typeof error === "string" ? error : (error === null || error === void 0 ? void 0 : error.toString()) ?? "";
40
- try {
41
- const parsed = JSON.parse(serializedError);
42
- if (parsed && parsed.name && parsed.message) {
43
- const { name, message, properties = {} } = parsed;
44
- const errorInstance = new (errorClasses[name] || Error)(message);
45
- errorInstance.message = message;
46
- errorInstance.name = name;
47
- errorInstance.stack = cleanStackTrace((error === null || error === void 0 ? void 0 : error.stack) ?? "");
48
- Object.assign(errorInstance, properties);
49
- if (isWrappedError(errorInstance)) return maybeDeserializeError(errorInstance);
50
- return errorInstance;
51
- }
52
- } catch {}
53
- return error;
54
- }
55
- _Signals.maybeDeserializeError = maybeDeserializeError;
56
- })(Signals || (Signals = {}));
57
- var VMSignal = class extends Error {
58
- message;
59
- /**
60
- * The code that was executed by the VM up to the point of the signal
61
- */
62
- truncatedCode = "";
63
- /** The current tool call, if any */
64
- toolCall;
65
- /**
66
- * Contains all the declared and executed variables during the VM execution
67
- * See file plugins/variable-extraction.ts for more details
68
- */
69
- variables = {};
70
- constructor(message) {
71
- super(message);
72
- this.message = message;
73
- this.message = Signals.serializeError(this);
74
- }
75
- };
76
- /** Request a snapshot from inside a tool call */
77
- var SnapshotSignal = class extends VMSignal {
78
- constructor(message) {
79
- super(message);
80
- this.message = Signals.serializeError(this);
81
- }
82
- };
83
- /** Loop means LLMz will continue the execution (unless it exhausted its iterations) */
84
- var VMLoopSignal = class extends VMSignal {
85
- constructor(message) {
86
- super(message);
87
- this.message = Signals.serializeError(this);
88
- }
89
- };
90
- var ThinkSignal = class extends VMLoopSignal {
91
- reason;
92
- context;
93
- metadata;
94
- constructor(reason, context, metadata) {
95
- super("Think signal received: " + reason);
96
- this.reason = reason;
97
- this.context = context;
98
- this.metadata = metadata;
99
- this.message = Signals.serializeError(this);
100
- this.stack = "";
101
- }
102
- toString() {
103
- return Signals.serializeError(this);
104
- }
105
- };
106
- var CodeExecutionError = class extends Error {
107
- code;
108
- stacktrace;
109
- constructor(message, code, stacktrace) {
110
- super(message);
111
- this.code = code;
112
- this.stacktrace = stacktrace;
113
- this.message = Signals.serializeError(this);
114
- }
115
- };
116
- var InvalidCodeError = class extends Error {
117
- code;
118
- constructor(message, code) {
119
- super(message);
120
- this.code = code;
121
- this.message = Signals.serializeError(this);
122
- this.stack = "";
123
- }
124
- };
125
- var LoopExceededError = class extends Error {
126
- constructor() {
127
- super("Loop exceeded error");
128
- this.message = Signals.serializeError(this);
129
- this.stack = "";
130
- }
131
- };
132
- var CodeFormattingError = class extends Error {
133
- code;
134
- constructor(message, code) {
135
- super(message, { cause: "Code formatting error" });
136
- this.code = code;
137
- this.stack = "";
138
- }
139
- };
140
- var AssignmentError = class extends Error {
141
- constructor(message) {
142
- super(message);
143
- this.message = Signals.serializeError(this);
144
- }
145
- };
146
- var CognitiveError = class extends Error {
147
- constructor(message) {
148
- super(message);
149
- this.message = Signals.serializeError(this);
150
- this.stack = "";
151
- }
152
- };
153
- registerErrorClass("VMSignal", VMSignal);
154
- registerErrorClass("SnapshotSignal", SnapshotSignal);
155
- registerErrorClass("VMLoopSignal", VMLoopSignal);
156
- registerErrorClass("ThinkSignal", ThinkSignal);
157
- registerErrorClass("CodeExecutionError", CodeExecutionError);
158
- registerErrorClass("AssignmentError", AssignmentError);
159
- registerErrorClass("CognitiveError", CognitiveError);
160
- //#endregion
161
- export { InvalidCodeError as a, SnapshotSignal as c, CognitiveError as i, ThinkSignal as l, CodeExecutionError as n, LoopExceededError as o, CodeFormattingError as r, Signals as s, AssignmentError as t, VMSignal as u };
@@ -1,8 +0,0 @@
1
- /** Documentation boundaries only; never part of the response protocol. */
2
- export declare const quoteExample: (output: string) => string;
3
- /** A single block excerpt; the omitted response is not part of this example. */
4
- export declare const quotePartialExample: (output: string) => string;
5
- export declare const exampleBoundaryInstructions = "Triple quotes (\"\"\") mark the beginning and end of examples only. Do NOT emit these delimiters in your response.";
6
- /** A complete response example, unlike individual block/syntax examples. */
7
- export declare const quoteResponseExample: (output: string) => string;
8
- export declare const responseEnvelopeInstructions = "Every response starts with \u25A0start on its own line and ends with \u25A0end on its own line. Between them write only the documented protocol blocks. Nothing goes before \u25A0start or after \u25A0end. The envelope is protocol, not a code fence.";
package/dist/example.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { Component } from './component.js';
2
- import type { Exit } from './exit.js';
3
- export type ExampleMessage = {
4
- component: Component | string;
5
- props?: Record<string, unknown>;
6
- body?: string;
7
- };
8
- /** Exactly one model response: messages followed by code or an exit. */
9
- type ExampleResponse = {
10
- messages?: ExampleMessage[];
11
- } & ({
12
- code: string;
13
- exit?: never;
14
- props?: never;
15
- } | {
16
- exit: Exit | string;
17
- props?: Record<string, unknown>;
18
- code?: never;
19
- });
20
- /** One hypothetical situation and the single response to produce in it. */
21
- export type ExampleDefinition = {
22
- /** Include the request, known facts, or previous tool results needed to understand this response. */
23
- situation: string;
24
- /** Optional explanation of why this response is appropriate. Context for the model, not generated output. */
25
- reason?: string;
26
- } & ExampleResponse;
27
- /**
28
- * Builds one protocol-correct response to one hypothetical situation.
29
- *
30
- * @example
31
- * new Example({
32
- * situation: 'The user asks a question that needs a knowledge-base search.',
33
- * reason: 'Search first so the answer can use actual evidence.',
34
- * code: 'return await searchKnowledge({ query: "reset password" })',
35
- * })
36
- */
37
- export declare class Example {
38
- readonly situation: string;
39
- readonly reason?: string;
40
- readonly output: string;
41
- constructor(definition: ExampleDefinition);
42
- }
43
- /** Internal prompt renderer. Checks examples against this iteration's component/exit catalog. */
44
- export declare const renderExamples: (examples: readonly Example[], components: Component[], exits: Exit[]) => Promise<string>;
45
- export {};