llmz 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat.d.ts +17 -0
- package/dist/chunk-3U57H7GT.js +608 -0
- package/dist/{chunk-LVKZYKTP.cjs → chunk-4I7UPBLN.cjs} +2 -2
- package/dist/{chunk-W6U2VXSF.cjs → chunk-6WT5VZBG.cjs} +348 -12
- package/dist/{chunk-JK2LZW2G.cjs → chunk-EJRCDWBA.cjs} +45 -6
- package/dist/{chunk-ZCPQ3QOW.js → chunk-HP7RKM25.js} +45 -6
- package/dist/chunk-MU4LFVY7.cjs +608 -0
- package/dist/{chunk-S6WICIDW.js → chunk-S6FOL2HY.js} +2 -2
- package/dist/{chunk-TJQVC4CE.js → chunk-WLUVY5QU.js} +341 -5
- package/dist/{component-LQDU72LX.js → component-R2Y74VUI.js} +3 -1
- package/dist/component-TSNW3SC7.cjs +16 -0
- package/dist/component.d.ts +6 -19
- package/dist/component.default.d.ts +131 -151
- package/dist/context.d.ts +6 -5
- package/dist/{dual-modes-YE4S2AIL.cjs → dual-modes-UHNDHNIF.cjs} +3 -4
- package/dist/{dual-modes-QHBOFWHM.js → dual-modes-ZUQKPJFH.js} +2 -3
- package/dist/{exit-IDKGZD7M.cjs → exit-KJ4COC5N.cjs} +2 -2
- package/dist/{exit-F6ZUL2NV.js → exit-OIYZLBVJ.js} +1 -1
- package/dist/exit.d.ts +5 -1
- package/dist/getter.d.ts +1 -1
- package/dist/index.cjs +72 -127
- package/dist/index.d.ts +7 -5
- package/dist/index.js +67 -122
- package/dist/llmz-VDA4M42R.cjs +604 -0
- package/dist/llmz-YE5N54IU.js +604 -0
- package/dist/llmz.d.ts +6 -9
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunk-4KB5WXHR.js +0 -92
- package/dist/chunk-6YWYCVAB.cjs +0 -92
- package/dist/chunk-EFGXTO64.js +0 -344
- package/dist/chunk-VAF2H6UD.cjs +0 -344
- package/dist/component-HQ5YQNRX.cjs +0 -14
- package/dist/llmz-AS5TGCQS.js +0 -1108
- package/dist/llmz-R6XZG3JQ.cjs +0 -1108
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk6WT5VZBGcjs = require('./chunk-6WT5VZBG.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk4QTK5ALHcjs = require('./chunk-4QTK5ALH.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkJDABP4SDcjs = require('./chunk-JDABP4SD.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunk4I7UPBLNcjs = require('./chunk-4I7UPBLN.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkEJRCDWBAcjs = require('./chunk-EJRCDWBA.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkFIVFS4HGcjs = require('./chunk-FIVFS4HG.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
|
|
25
|
+
|
|
26
|
+
// src/snapshots.ts
|
|
27
|
+
var _ulid = require('ulid');
|
|
28
|
+
var MAX_SNAPSHOT_SIZE_BYTES = 4e3;
|
|
29
|
+
var Snapshot = class _Snapshot {
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
#status;
|
|
36
|
+
get status() {
|
|
37
|
+
return Object.freeze({ ...this.#status });
|
|
38
|
+
}
|
|
39
|
+
constructor(props) {
|
|
40
|
+
this.id = props.id;
|
|
41
|
+
this.stack = props.stack;
|
|
42
|
+
this.reason = props.reason;
|
|
43
|
+
this.variables = props.variables;
|
|
44
|
+
this.toolCall = props.toolCall;
|
|
45
|
+
this.#status = props.status;
|
|
46
|
+
}
|
|
47
|
+
static fromSignal(signal) {
|
|
48
|
+
const variables = Object.entries(signal.variables).map(([name, value]) => {
|
|
49
|
+
const type = _chunk6WT5VZBGcjs.extractType.call(void 0, value);
|
|
50
|
+
const bytes = JSON.stringify(value || "").length;
|
|
51
|
+
const truncated = bytes > MAX_SNAPSHOT_SIZE_BYTES;
|
|
52
|
+
return truncated ? { name, type, bytes, truncated: true, preview: _nullishCoalesce(_chunk6WT5VZBGcjs.inspect.call(void 0, value, name), () => ( "N/A")) } : { name, type, bytes, truncated: false, value };
|
|
53
|
+
});
|
|
54
|
+
return new _Snapshot({
|
|
55
|
+
id: "snapshot_" + _ulid.ulid.call(void 0, ),
|
|
56
|
+
reason: signal.message,
|
|
57
|
+
stack: signal.truncatedCode,
|
|
58
|
+
variables,
|
|
59
|
+
toolCall: signal.toolCall,
|
|
60
|
+
status: { type: "pending" }
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
toJSON() {
|
|
64
|
+
return {
|
|
65
|
+
id: this.id,
|
|
66
|
+
reason: this.reason,
|
|
67
|
+
stack: this.stack,
|
|
68
|
+
variables: this.variables,
|
|
69
|
+
toolCall: this.toolCall,
|
|
70
|
+
status: this.#status
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
static fromJSON(json) {
|
|
74
|
+
return new _Snapshot({
|
|
75
|
+
id: json.id,
|
|
76
|
+
reason: json.reason,
|
|
77
|
+
stack: json.stack,
|
|
78
|
+
variables: json.variables,
|
|
79
|
+
toolCall: json.toolCall,
|
|
80
|
+
status: json.status
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
clone() {
|
|
84
|
+
return new _Snapshot({
|
|
85
|
+
id: this.id,
|
|
86
|
+
reason: this.reason,
|
|
87
|
+
stack: this.stack,
|
|
88
|
+
variables: this.variables,
|
|
89
|
+
toolCall: this.toolCall,
|
|
90
|
+
status: this.#status
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
reset() {
|
|
94
|
+
this.#status = { type: "pending" };
|
|
95
|
+
}
|
|
96
|
+
resolve(value) {
|
|
97
|
+
if (this.#status.type !== "pending") {
|
|
98
|
+
throw new Error(`Cannot resolve snapshot because it is already settled: ${this.#status.type}`);
|
|
99
|
+
}
|
|
100
|
+
this.#status = { type: "resolved", value };
|
|
101
|
+
}
|
|
102
|
+
reject(error) {
|
|
103
|
+
if (this.#status.type !== "pending") {
|
|
104
|
+
throw new Error(`Cannot reject snapshot because it is already settled: ${this.#status.type}`);
|
|
105
|
+
}
|
|
106
|
+
this.#status = { type: "rejected", error };
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/getter.ts
|
|
111
|
+
var getValue = async (valueOrGetter, ctx) => {
|
|
112
|
+
if (typeof valueOrGetter === "function") {
|
|
113
|
+
try {
|
|
114
|
+
return await valueOrGetter(ctx);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
throw new Error(`Error while getting value for ${valueOrGetter}: ${e}`);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
return valueOrGetter;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/context.ts
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// src/handlers.ts
|
|
127
|
+
var Emitter = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
|
|
128
|
+
__init() {this._handlers = []}
|
|
129
|
+
__init2() {this.subscribe = (fn) => {
|
|
130
|
+
this._handlers.push(fn);
|
|
131
|
+
return () => {
|
|
132
|
+
this._handlers = this._handlers.filter((handler) => handler !== fn);
|
|
133
|
+
};
|
|
134
|
+
}}
|
|
135
|
+
emit(event) {
|
|
136
|
+
this._handlers.forEach((handler) => handler(event));
|
|
137
|
+
}
|
|
138
|
+
}, _class);
|
|
139
|
+
var HookedArray = class extends Array {
|
|
140
|
+
#listeners = new Emitter();
|
|
141
|
+
constructor(...items) {
|
|
142
|
+
super(...items);
|
|
143
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
144
|
+
}
|
|
145
|
+
push(...items) {
|
|
146
|
+
try {
|
|
147
|
+
this.#listeners.emit(items);
|
|
148
|
+
} finally {
|
|
149
|
+
return super.push(...items);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
onPush(fn) {
|
|
153
|
+
return this.#listeners.subscribe(fn);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/transcript.ts
|
|
158
|
+
var MAX_MESSAGE_LENGTH = 5e3;
|
|
159
|
+
var TranscriptArray = class extends Array {
|
|
160
|
+
constructor(items = []) {
|
|
161
|
+
items = Array.isArray(items) ? items : [];
|
|
162
|
+
super(...items);
|
|
163
|
+
items.forEach((item) => {
|
|
164
|
+
if (!["user", "assistant"].includes(item.role)) {
|
|
165
|
+
throw new Error(`Invalid role "${item.role}" in transcript message`);
|
|
166
|
+
}
|
|
167
|
+
if (item.name && typeof item.name !== "string") {
|
|
168
|
+
throw new Error(`Invalid name for transcript message. Expected a string, but got type "${typeof item.name}"`);
|
|
169
|
+
}
|
|
170
|
+
if (typeof item.content !== "string") {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`Invalid content for transcript message. Expected a string, but got type "${typeof item.content}"`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
177
|
+
}
|
|
178
|
+
toString() {
|
|
179
|
+
if (!this.length) {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
return this.map((item, idx) => {
|
|
183
|
+
var _a;
|
|
184
|
+
const msgIdx = "message-" + String(idx + 1).padStart(3, "0");
|
|
185
|
+
const shouldTruncate = item.content.length > MAX_MESSAGE_LENGTH;
|
|
186
|
+
const preview = shouldTruncate ? item.content.slice(0, MAX_MESSAGE_LENGTH) + "\n... (truncated)" : item.content;
|
|
187
|
+
const tags = [];
|
|
188
|
+
tags.push({ key: "role", value: item.role });
|
|
189
|
+
if ((_a = item.name) == null ? void 0 : _a.length) {
|
|
190
|
+
tags.push({ key: "name", value: item.name });
|
|
191
|
+
}
|
|
192
|
+
const tagsString = tags.map(({ key, value }) => `${key}="${value}"`).join(" ");
|
|
193
|
+
return `<${msgIdx} ${tagsString}>
|
|
194
|
+
${preview.trim()}
|
|
195
|
+
</${msgIdx}>`;
|
|
196
|
+
}).join("\n");
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/context.ts
|
|
201
|
+
var ThinkExit = new (0, _chunk4I7UPBLNcjs.Exit)({
|
|
202
|
+
name: "think",
|
|
203
|
+
description: "Think about the current situation and provide a response"
|
|
204
|
+
});
|
|
205
|
+
var ListenExit = new (0, _chunk4I7UPBLNcjs.Exit)({
|
|
206
|
+
name: "listen",
|
|
207
|
+
description: "Listen to the user and provide a response"
|
|
208
|
+
});
|
|
209
|
+
var Iteration = class {
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
get mutations() {
|
|
220
|
+
return [...this._mutations.values()];
|
|
221
|
+
}
|
|
222
|
+
trackMutation(mutation) {
|
|
223
|
+
this._mutations.set(`${_nullishCoalesce(mutation.object, () => ( "global"))}:${mutation.property}`, mutation);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
get transcript() {
|
|
227
|
+
return this._parameters.transcript;
|
|
228
|
+
}
|
|
229
|
+
get tools() {
|
|
230
|
+
return this._parameters.tools;
|
|
231
|
+
}
|
|
232
|
+
get objects() {
|
|
233
|
+
return this._parameters.objects;
|
|
234
|
+
}
|
|
235
|
+
get exits() {
|
|
236
|
+
const exits = [...this._parameters.exits, ThinkExit];
|
|
237
|
+
if (this.isChatEnabled) {
|
|
238
|
+
exits.push(ListenExit);
|
|
239
|
+
}
|
|
240
|
+
return exits;
|
|
241
|
+
}
|
|
242
|
+
get instructions() {
|
|
243
|
+
return this._parameters.instructions;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
hasExited() {
|
|
247
|
+
return ["exit_success"].includes(this.status.type);
|
|
248
|
+
}
|
|
249
|
+
hasExitedWith(exit) {
|
|
250
|
+
return this.status.type === "exit_success" && this.status.exit_success.exit_name === exit.name;
|
|
251
|
+
}
|
|
252
|
+
isSuccessful() {
|
|
253
|
+
return ["callback_requested", "exit_success", "thinking_requested"].includes(
|
|
254
|
+
this.status.type
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
isFailed() {
|
|
258
|
+
return [
|
|
259
|
+
"generation_error",
|
|
260
|
+
"invalid_code_error",
|
|
261
|
+
"execution_error",
|
|
262
|
+
"exit_error",
|
|
263
|
+
"aborted"
|
|
264
|
+
].includes(this.status.type);
|
|
265
|
+
}
|
|
266
|
+
get duration() {
|
|
267
|
+
const ms = (_nullishCoalesce(this.ended_ts, () => ( Date.now()))) - this.started_ts;
|
|
268
|
+
const trailing = this.ended_ts ? "" : " (still running)";
|
|
269
|
+
return ms.toLocaleString("en-US", { style: "unit", unit: "millisecond" }) + trailing;
|
|
270
|
+
}
|
|
271
|
+
get error() {
|
|
272
|
+
if (this.status.type === "generation_error") {
|
|
273
|
+
return `CodeGenerationError: ${this.status.generation_error.message}`;
|
|
274
|
+
}
|
|
275
|
+
if (this.status.type === "invalid_code_error") {
|
|
276
|
+
return `InvalidCodeError: ${this.status.invalid_code_error.message}`;
|
|
277
|
+
}
|
|
278
|
+
if (this.status.type === "execution_error") {
|
|
279
|
+
return `CodeExecutionError: ${this.status.execution_error.message}`;
|
|
280
|
+
}
|
|
281
|
+
if (this.status.type === "exit_error") {
|
|
282
|
+
return `ExitError: ${this.status.exit_error.message}`;
|
|
283
|
+
}
|
|
284
|
+
if (this.status.type === "aborted") {
|
|
285
|
+
return `Aborted: ${this.status.aborted.reason}`;
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
get isChatEnabled() {
|
|
290
|
+
return this._parameters.tools.find((x) => x.name.toLowerCase() === "message") !== void 0;
|
|
291
|
+
}
|
|
292
|
+
constructor(props) {
|
|
293
|
+
this.id = props.id;
|
|
294
|
+
this.status = { type: "pending" };
|
|
295
|
+
this.traces = new HookedArray();
|
|
296
|
+
this._mutations = /* @__PURE__ */ new Map();
|
|
297
|
+
this.messages = props.messages;
|
|
298
|
+
this.variables = props.variables;
|
|
299
|
+
this._parameters = props.parameters;
|
|
300
|
+
this.started_ts = Date.now();
|
|
301
|
+
}
|
|
302
|
+
end(status) {
|
|
303
|
+
if (this.status.type !== "pending") {
|
|
304
|
+
throw new Error(`Iteration ${this.id} has already ended with status ${this.status.type}`);
|
|
305
|
+
}
|
|
306
|
+
this.ended_ts = Date.now();
|
|
307
|
+
this.status = status;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
var Context = (_class2 = class {
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
__init3() {this.version = _chunk6WT5VZBGcjs.DualModePrompt}
|
|
318
|
+
__init4() {this.timeout = 6e4}
|
|
319
|
+
// Default timeout of 60 seconds
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
__init5() {this.iteration = 0}
|
|
326
|
+
|
|
327
|
+
async nextIteration() {
|
|
328
|
+
if (this.iterations.length >= this.loop) {
|
|
329
|
+
throw new (0, _chunkJDABP4SDcjs.LoopExceededError)();
|
|
330
|
+
}
|
|
331
|
+
if (this.snapshot && this.snapshot.status.type === "pending") {
|
|
332
|
+
throw new Error(
|
|
333
|
+
`Cannot resume execution from a snapshot that is still pending: ${this.snapshot.id}. Please resolve() or reject() it first.`
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
const parameters = await this._refreshIterationParameters();
|
|
337
|
+
const messages = await this._getIterationMessages(parameters);
|
|
338
|
+
const iteration = new Iteration({
|
|
339
|
+
id: `${this.id}_${this.iterations.length + 1}`,
|
|
340
|
+
variables: this._getIterationVariables(),
|
|
341
|
+
parameters,
|
|
342
|
+
messages
|
|
343
|
+
});
|
|
344
|
+
this.iterations.push(iteration);
|
|
345
|
+
this.iteration = this.iterations.length;
|
|
346
|
+
this.snapshot = void 0;
|
|
347
|
+
return iteration;
|
|
348
|
+
}
|
|
349
|
+
_getIterationVariables() {
|
|
350
|
+
const lastIteration = this.iterations.at(-1);
|
|
351
|
+
const variables = {};
|
|
352
|
+
if ((lastIteration == null ? void 0 : lastIteration.status.type) === "thinking_requested") {
|
|
353
|
+
const lastThinkingVariables = lastIteration.status.thinking_requested.variables;
|
|
354
|
+
if (_chunkUQOBUJIQcjs.isPlainObject_default.call(void 0, lastThinkingVariables)) {
|
|
355
|
+
Object.assign(variables, _chunkUQOBUJIQcjs.cloneDeep_default.call(void 0, lastThinkingVariables));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (_chunkUQOBUJIQcjs.isPlainObject_default.call(void 0, lastIteration == null ? void 0 : lastIteration.variables)) {
|
|
359
|
+
Object.assign(variables, _chunkUQOBUJIQcjs.cloneDeep_default.call(void 0, _nullishCoalesce((lastIteration == null ? void 0 : lastIteration.variables), () => ( {}))));
|
|
360
|
+
}
|
|
361
|
+
return variables;
|
|
362
|
+
}
|
|
363
|
+
async _getIterationMessages(parameters) {
|
|
364
|
+
var _a, _b, _c, _d, _e, _f;
|
|
365
|
+
const lastIteration = this.iterations.at(-1);
|
|
366
|
+
if (((_a = this.snapshot) == null ? void 0 : _a.status.type) === "resolved") {
|
|
367
|
+
return [
|
|
368
|
+
await this.version.getSystemMessage({
|
|
369
|
+
globalTools: parameters.tools,
|
|
370
|
+
objects: parameters.objects,
|
|
371
|
+
instructions: parameters.instructions,
|
|
372
|
+
transcript: parameters.transcript,
|
|
373
|
+
exits: parameters.exits,
|
|
374
|
+
components: parameters.components
|
|
375
|
+
}),
|
|
376
|
+
this.version.getSnapshotResolvedMessage({
|
|
377
|
+
snapshot: this.snapshot
|
|
378
|
+
})
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
if (((_b = this.snapshot) == null ? void 0 : _b.status.type) === "rejected") {
|
|
382
|
+
return [
|
|
383
|
+
await this.version.getSystemMessage({
|
|
384
|
+
globalTools: parameters.tools,
|
|
385
|
+
objects: parameters.objects,
|
|
386
|
+
instructions: parameters.instructions,
|
|
387
|
+
transcript: parameters.transcript,
|
|
388
|
+
exits: parameters.exits,
|
|
389
|
+
components: parameters.components
|
|
390
|
+
}),
|
|
391
|
+
this.version.getSnapshotRejectedMessage({
|
|
392
|
+
snapshot: this.snapshot
|
|
393
|
+
})
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
if (!lastIteration) {
|
|
397
|
+
return [
|
|
398
|
+
await this.version.getSystemMessage({
|
|
399
|
+
globalTools: parameters.tools,
|
|
400
|
+
objects: parameters.objects,
|
|
401
|
+
instructions: parameters.instructions,
|
|
402
|
+
transcript: parameters.transcript,
|
|
403
|
+
exits: parameters.exits,
|
|
404
|
+
components: parameters.components
|
|
405
|
+
}),
|
|
406
|
+
await this.version.getInitialUserMessage({
|
|
407
|
+
globalTools: parameters.tools,
|
|
408
|
+
objects: parameters.objects,
|
|
409
|
+
instructions: parameters.instructions,
|
|
410
|
+
transcript: parameters.transcript,
|
|
411
|
+
exits: parameters.exits,
|
|
412
|
+
components: parameters.components
|
|
413
|
+
})
|
|
414
|
+
];
|
|
415
|
+
}
|
|
416
|
+
const lastIterationMessages = [
|
|
417
|
+
await this.version.getSystemMessage({
|
|
418
|
+
globalTools: parameters.tools,
|
|
419
|
+
objects: parameters.objects,
|
|
420
|
+
instructions: parameters.instructions,
|
|
421
|
+
transcript: parameters.transcript,
|
|
422
|
+
exits: parameters.exits,
|
|
423
|
+
components: parameters.components
|
|
424
|
+
}),
|
|
425
|
+
...lastIteration.messages.filter((x) => x.role !== "system")
|
|
426
|
+
];
|
|
427
|
+
if ((lastIteration == null ? void 0 : lastIteration.status.type) === "thinking_requested") {
|
|
428
|
+
return [
|
|
429
|
+
...lastIterationMessages,
|
|
430
|
+
{
|
|
431
|
+
role: "assistant",
|
|
432
|
+
content: _chunkFIVFS4HGcjs.wrapContent.call(void 0, _nullishCoalesce(((_c = lastIteration.llm) == null ? void 0 : _c.output), () => ( "")), { preserve: "top", flex: 4, minTokens: 25 })
|
|
433
|
+
},
|
|
434
|
+
await this.version.getThinkingMessage({
|
|
435
|
+
reason: lastIteration.status.thinking_requested.reason,
|
|
436
|
+
variables: lastIteration.status.thinking_requested.variables
|
|
437
|
+
})
|
|
438
|
+
];
|
|
439
|
+
}
|
|
440
|
+
if ((lastIteration == null ? void 0 : lastIteration.status.type) === "exit_error") {
|
|
441
|
+
return [
|
|
442
|
+
...lastIterationMessages,
|
|
443
|
+
{
|
|
444
|
+
role: "assistant",
|
|
445
|
+
content: _chunkFIVFS4HGcjs.wrapContent.call(void 0, _nullishCoalesce(((_d = lastIteration.llm) == null ? void 0 : _d.output), () => ( "")), { preserve: "top", flex: 4, minTokens: 25 })
|
|
446
|
+
},
|
|
447
|
+
await this.version.getInvalidCodeMessage({
|
|
448
|
+
code: _nullishCoalesce(lastIteration.code, () => ( "// No code generated")),
|
|
449
|
+
message: `Invalid return statement (action: ${lastIteration.status.exit_error.exit}): ${lastIteration.status.exit_error.message}`
|
|
450
|
+
})
|
|
451
|
+
];
|
|
452
|
+
}
|
|
453
|
+
if ((lastIteration == null ? void 0 : lastIteration.status.type) === "invalid_code_error") {
|
|
454
|
+
return [
|
|
455
|
+
...lastIterationMessages,
|
|
456
|
+
{
|
|
457
|
+
role: "assistant",
|
|
458
|
+
content: _chunkFIVFS4HGcjs.wrapContent.call(void 0, _nullishCoalesce(((_e = lastIteration.llm) == null ? void 0 : _e.output), () => ( "")), { preserve: "top", flex: 4, minTokens: 25 })
|
|
459
|
+
},
|
|
460
|
+
await this.version.getInvalidCodeMessage({
|
|
461
|
+
code: _nullishCoalesce(lastIteration.code, () => ( "// No code generated")),
|
|
462
|
+
message: lastIteration.status.invalid_code_error.message
|
|
463
|
+
})
|
|
464
|
+
];
|
|
465
|
+
}
|
|
466
|
+
if ((lastIteration == null ? void 0 : lastIteration.status.type) === "execution_error") {
|
|
467
|
+
return [
|
|
468
|
+
...lastIterationMessages,
|
|
469
|
+
{
|
|
470
|
+
role: "assistant",
|
|
471
|
+
content: _chunkFIVFS4HGcjs.wrapContent.call(void 0, _nullishCoalesce(((_f = lastIteration.llm) == null ? void 0 : _f.output), () => ( "")), { preserve: "top", flex: 4, minTokens: 25 })
|
|
472
|
+
},
|
|
473
|
+
await this.version.getCodeExecutionErrorMessage({
|
|
474
|
+
message: lastIteration.status.execution_error.message,
|
|
475
|
+
stacktrace: lastIteration.status.execution_error.stack
|
|
476
|
+
})
|
|
477
|
+
];
|
|
478
|
+
}
|
|
479
|
+
throw new Error(
|
|
480
|
+
`Unexpected iteration status: ${lastIteration == null ? void 0 : lastIteration.status.type}. This is likely a bug, please report it.`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
async _refreshIterationParameters() {
|
|
484
|
+
var _a, _b;
|
|
485
|
+
const instructions = await getValue(this.instructions, this);
|
|
486
|
+
const transcript = new TranscriptArray(await getValue(_nullishCoalesce(((_a = this.chat) == null ? void 0 : _a.transcript), () => ( [])), this));
|
|
487
|
+
const tools = _chunk4QTK5ALHcjs.Tool.withUniqueNames(await _asyncNullishCoalesce(await getValue(this.tools, this), async () => ( [])));
|
|
488
|
+
const objects = await _asyncNullishCoalesce(await getValue(this.objects, this), async () => ( []));
|
|
489
|
+
const exits = await _asyncNullishCoalesce(await getValue(this.exits, this), async () => ( []));
|
|
490
|
+
const components = await getValue(_nullishCoalesce(((_b = this.chat) == null ? void 0 : _b.components), () => ( [])), this);
|
|
491
|
+
if (objects && objects.length > 100) {
|
|
492
|
+
throw new Error("Too many objects. Expected at most 100 objects.");
|
|
493
|
+
}
|
|
494
|
+
if (tools && tools.length > 100) {
|
|
495
|
+
throw new Error("Too many tools. Expected at most 100 tools.");
|
|
496
|
+
}
|
|
497
|
+
for (const component of components) {
|
|
498
|
+
_chunkEJRCDWBAcjs.assertValidComponent.call(void 0, component.definition);
|
|
499
|
+
}
|
|
500
|
+
const ReservedToolNames = [
|
|
501
|
+
"think",
|
|
502
|
+
"listen",
|
|
503
|
+
"return",
|
|
504
|
+
"exit",
|
|
505
|
+
"action",
|
|
506
|
+
"function",
|
|
507
|
+
"callback",
|
|
508
|
+
"code",
|
|
509
|
+
"execute",
|
|
510
|
+
"jsx",
|
|
511
|
+
"object",
|
|
512
|
+
"string",
|
|
513
|
+
"number",
|
|
514
|
+
"boolean",
|
|
515
|
+
"array"
|
|
516
|
+
];
|
|
517
|
+
const MessageTool = this.chat && components.length ? new (0, _chunk4QTK5ALHcjs.Tool)({
|
|
518
|
+
name: "Message",
|
|
519
|
+
description: "Send a message to the user",
|
|
520
|
+
aliases: Array.from(
|
|
521
|
+
/* @__PURE__ */ new Set(["message", ...components.flatMap((x) => [x.definition.name, ..._nullishCoalesce(x.definition.aliases, () => ( []))])])
|
|
522
|
+
),
|
|
523
|
+
handler: async (message) => {
|
|
524
|
+
var _a2, _b2;
|
|
525
|
+
return await ((_b2 = (_a2 = this.chat) == null ? void 0 : _a2.handler) == null ? void 0 : _b2.call(_a2, message));
|
|
526
|
+
}
|
|
527
|
+
}) : null;
|
|
528
|
+
const allTools = MessageTool ? [MessageTool, ...tools] : tools;
|
|
529
|
+
for (const tool of tools) {
|
|
530
|
+
for (let name of [...tool.aliases, tool.name]) {
|
|
531
|
+
name = name.toLowerCase();
|
|
532
|
+
if (ReservedToolNames.includes(name)) {
|
|
533
|
+
throw new Error(`Tool name "${name}" (${tool.name}) is reserved. Please choose a different name.`);
|
|
534
|
+
}
|
|
535
|
+
if (components.find(
|
|
536
|
+
(x) => {
|
|
537
|
+
var _a2;
|
|
538
|
+
return x.definition.name.toLowerCase() === name || ((_a2 = x.definition.aliases) == null ? void 0 : _a2.map((x2) => x2.toLowerCase()).includes(name));
|
|
539
|
+
}
|
|
540
|
+
)) {
|
|
541
|
+
throw new Error(
|
|
542
|
+
`Tool name "${name}" (${tool.name}) is already used by a component. Please choose a different name.`
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
if (exits.find((x) => x.name.toLowerCase() === name) || exits.find((x) => {
|
|
546
|
+
var _a2;
|
|
547
|
+
return (_a2 = x.aliases) == null ? void 0 : _a2.map((x2) => x2.toLowerCase()).includes(name);
|
|
548
|
+
})) {
|
|
549
|
+
throw new Error(
|
|
550
|
+
`Tool name "${name}" (${tool.name}) is already used by an exit. Please choose a different name.`
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (exits && exits.length > 100) {
|
|
556
|
+
throw new Error("Too many exits. Expected at most 100 exits.");
|
|
557
|
+
}
|
|
558
|
+
if (components && components.length > 100) {
|
|
559
|
+
throw new Error("Too many components. Expected at most 100 components.");
|
|
560
|
+
}
|
|
561
|
+
if (instructions && instructions.length > 1e6) {
|
|
562
|
+
throw new Error("Instructions are too long. Expected at most 1,000,000 characters.");
|
|
563
|
+
}
|
|
564
|
+
if (transcript && transcript.length > 250) {
|
|
565
|
+
throw new Error("Too many transcript messages. Expected at most 250 messages.");
|
|
566
|
+
}
|
|
567
|
+
if (!components.length && !exits.length) {
|
|
568
|
+
throw new Error("When no components are provided, at least one exit is required.");
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
transcript,
|
|
572
|
+
tools: allTools,
|
|
573
|
+
objects,
|
|
574
|
+
exits,
|
|
575
|
+
instructions,
|
|
576
|
+
components
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
constructor(props) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
|
|
580
|
+
this.id = `llmz_${_ulid.ulid.call(void 0, )}`;
|
|
581
|
+
this.instructions = props.instructions;
|
|
582
|
+
this.objects = props.objects;
|
|
583
|
+
this.tools = props.tools;
|
|
584
|
+
this.exits = props.exits;
|
|
585
|
+
this.chat = props.chat;
|
|
586
|
+
this.timeout = Math.min(999999999, Math.max(0, _nullishCoalesce(props.timeout, () => ( 6e4))));
|
|
587
|
+
this.loop = _nullishCoalesce(props.loop, () => ( 3));
|
|
588
|
+
this.temperature = _nullishCoalesce(props.temperature, () => ( 0.7));
|
|
589
|
+
this.model = props.model;
|
|
590
|
+
this.iterations = [];
|
|
591
|
+
this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
|
|
592
|
+
this.snapshot = props.snapshot;
|
|
593
|
+
if (this.loop < 1 || this.loop > 100) {
|
|
594
|
+
throw new Error("Invalid loop. Expected a number between 1 and 100.");
|
|
595
|
+
}
|
|
596
|
+
if (this.temperature < 0 || this.temperature > 2) {
|
|
597
|
+
throw new Error("Invalid temperature. Expected a number between 0 and 2.");
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}, _class2);
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
exports.Snapshot = Snapshot; exports.getValue = getValue; exports.ThinkExit = ThinkExit; exports.ListenExit = ListenExit; exports.Context = Context;
|
|
@@ -40,8 +40,8 @@ var Exit = class _Exit {
|
|
|
40
40
|
is(exit) {
|
|
41
41
|
return this.name === exit.name;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
return
|
|
43
|
+
match(result) {
|
|
44
|
+
return result.exit instanceof _Exit && this.name === result.exit.name;
|
|
45
45
|
}
|
|
46
46
|
constructor(props) {
|
|
47
47
|
if (!isValidIdentifier(props.name)) {
|