llmz 0.8.0 → 0.9.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/README.md +45 -11
- package/dist/chat.d.ts +6 -6
- package/dist/{common-DdArNQhl.cjs → common-DJkSpeqw.cjs} +239 -22
- package/dist/{common-pgJjFu2Y.js → common-DuEhn6u3.js} +234 -23
- package/dist/compiler/plugins/variable-extraction.d.ts +1 -7
- package/dist/{compiler-C-OI9sim.cjs → compiler-BJJUmNS9.cjs} +34 -68
- package/dist/{compiler-CW1VjQsn.js → compiler-BPl-5CXh.js} +34 -68
- package/dist/{component-BXS8vAwO.cjs → component-CPKXe6Ca.cjs} +2 -2
- package/dist/{component-Dq7ZLdvy.js → component-DGG7d_Mz.js} +1 -1
- package/dist/component.default.d.ts +10 -0
- package/dist/context.d.ts +4 -8
- package/dist/{custom-client-HkM1Sdzv.cjs → custom-client-B_o56CB4.cjs} +22 -19
- package/dist/{custom-client-2V9lmzUf.js → custom-client-C-nDKG37.js} +17 -14
- package/dist/{dual-modes-Cb7ThvoV.cjs → dual-modes-BNHlj2qM.cjs} +1252 -1181
- package/dist/{dual-modes-Cy0_W4O2.js → dual-modes-BNIiNLrR.js} +1257 -1180
- package/dist/example-format.d.ts +8 -0
- package/dist/{execute-COIHOIKR.cjs → execute-0bvqakr7.cjs} +91 -99
- package/dist/{execute-Aw4cbIx-.js → execute-CWFIL5ny.js} +91 -99
- package/dist/{exit-DUM96DN1.cjs → exit-CGLXI0BH.cjs} +2 -2
- package/dist/index.cjs +265 -22
- package/dist/index.js +258 -15
- package/dist/index.workerd.js +8565 -8005
- package/dist/inspect.d.ts +2 -0
- package/dist/isPlainObject-CSxXVKCk.cjs +56 -0
- package/dist/isPlainObject-D39AzPO2.js +51 -0
- package/dist/{jsx-D5Y2cPo-.cjs → jsx-BJ6GWXI2.cjs} +3 -57
- package/dist/{jsx-B0iYyvfr.js → jsx-CIgdGGVs.js} +2 -50
- package/dist/message-stream/instructions.d.ts +8 -0
- package/dist/message-stream/parser.d.ts +6 -0
- package/dist/message-stream/response-parser.d.ts +24 -0
- package/dist/message-stream/response-parser.test.d.ts +1 -0
- package/dist/message-stream/types.d.ts +3 -2
- package/dist/prompts/adherence.test.d.ts +1 -0
- package/dist/prompts/catalogue-examples.test.d.ts +1 -0
- package/dist/prompts/chat-mode/protocol.d.ts +2 -0
- package/dist/prompts/chat-mode/system.d.ts +1 -1
- package/dist/prompts/chat-mode/user.d.ts +1 -1
- package/dist/prompts/code-examples.d.ts +2 -0
- package/dist/prompts/code-examples.test.d.ts +1 -0
- package/dist/prompts/common.d.ts +2 -1
- package/dist/prompts/concrete-patterns.test.d.ts +1 -0
- package/dist/prompts/long-search.test.d.ts +1 -0
- package/dist/prompts/prompt.d.ts +5 -2
- package/dist/prompts/protocol-basics.d.ts +5 -0
- package/dist/prompts/protocol-simple.test.d.ts +1 -0
- package/dist/prompts/protocol.d.ts +13 -0
- package/dist/prompts/sections.test.d.ts +1 -0
- package/dist/prompts/worker-mode/protocol.d.ts +2 -0
- package/dist/prompts/worker-mode/system.d.ts +1 -1
- package/dist/prompts/worker-mode/user.d.ts +1 -1
- package/dist/runtime/citations.test.d.ts +1 -0
- package/dist/runtime/fixtures/long-search.d.ts +19 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +74 -0
- package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +29 -0
- package/dist/runtime/generate.d.ts +2 -9
- package/dist/runtime/generate.test.d.ts +1 -0
- package/dist/runtime/protocol-adherence.test.d.ts +1 -0
- package/dist/runtime/types.d.ts +4 -7
- package/dist/{tool-Bv8N4IPj.js → tool-B6Pmuk6K.js} +35 -49
- package/dist/{tool-Dy6AJpJH.cjs → tool-BLTrA-sL.cjs} +38 -52
- package/dist/tool.d.ts +5 -3
- package/dist/{truncator-DZqEqnpD.js → truncator-CD7QtE84.js} +11 -6
- package/dist/{truncator-CLkouTCO.cjs → truncator-DmCu9M4m.cjs} +13 -8
- package/dist/{typings-3lsqCbkn.cjs → typings-DXJMu59O.cjs} +2 -2
- package/dist/{utils-3ESwP3yg.cjs → utils-DGQ4sRke.cjs} +1 -1
- package/dist/{vm-BLsHw1da.js → vm-Cn3jvZ00.js} +109 -53
- package/dist/{vm-D6s1zF6M.cjs → vm-X0uTj5Aa.cjs} +109 -53
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
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.";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const require_compiler = require("./compiler-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const require_custom_client = require("./custom-client-
|
|
5
|
-
const require_utils = require("./utils-
|
|
6
|
-
const require_jsx = require("./jsx-
|
|
1
|
+
const require_compiler = require("./compiler-BJJUmNS9.cjs");
|
|
2
|
+
const require_dual_modes = require("./dual-modes-BNHlj2qM.cjs");
|
|
3
|
+
const require_common = require("./common-DJkSpeqw.cjs");
|
|
4
|
+
const require_custom_client = require("./custom-client-B_o56CB4.cjs");
|
|
5
|
+
const require_utils = require("./utils-DGQ4sRke.cjs");
|
|
6
|
+
const require_jsx = require("./jsx-BJ6GWXI2.cjs");
|
|
7
7
|
const require_stack_traces = require("./stack-traces-ntw_qhoy.cjs");
|
|
8
8
|
const require_errors = require("./errors-C962uJdS.cjs");
|
|
9
|
-
const require_truncator = require("./truncator-
|
|
10
|
-
const require_vm = require("./vm-
|
|
9
|
+
const require_truncator = require("./truncator-DmCu9M4m.cjs");
|
|
10
|
+
const require_vm = require("./vm-X0uTj5Aa.cjs");
|
|
11
11
|
let _bpinternal_zui = require("@bpinternal/zui");
|
|
12
12
|
let ulid = require("ulid");
|
|
13
13
|
let _botpress_client = require("@botpress/client");
|
|
@@ -126,47 +126,21 @@ const STREAM_INACTIVITY_TIMEOUT = 18e4;
|
|
|
126
126
|
/** A syntactically valid prefix must not execute when generation did not finish successfully. */
|
|
127
127
|
const assertSuccessfulGeneration = (metadata) => {
|
|
128
128
|
if (metadata.provider === "unknown") throw new require_errors.CognitiveError("LLM generation failed: received error metadata with unknown provider");
|
|
129
|
-
if (metadata.stopReason === "max_tokens" || metadata.stopReason === "content_filter") throw new require_errors.CognitiveError(`LLM generation did not complete: stopReason=${metadata.stopReason}`);
|
|
129
|
+
if (metadata.stopReason === "max_tokens" || metadata.stopReason === "content_filter" || metadata.stopReason === "other") throw new require_errors.CognitiveError(`LLM generation did not complete: stopReason=${metadata.stopReason}`);
|
|
130
130
|
};
|
|
131
131
|
const getModelOutputLimit = (inputLength) => clamp(RESPONSE_LENGTH_BUFFER.PERCENTAGE * inputLength, RESPONSE_LENGTH_BUFFER.MIN_TOKENS, RESPONSE_LENGTH_BUFFER.MAX_TOKENS);
|
|
132
|
-
|
|
133
|
-
* Models sometimes wrap their whole response in a code fence. The fence has to
|
|
134
|
-
* be removed before it reaches the incremental parser to avoid a spurious
|
|
135
|
-
* unexpected-text diagnostic. Works on arbitrary chunk boundaries
|
|
136
|
-
* by holding content back until the first newline.
|
|
137
|
-
*/
|
|
138
|
-
var LeadingFenceFilter = class {
|
|
139
|
-
_buffer = "";
|
|
140
|
-
_done = false;
|
|
141
|
-
push(text) {
|
|
142
|
-
if (this._done) return text;
|
|
143
|
-
this._buffer += text;
|
|
144
|
-
const newline = this._buffer.indexOf("\n");
|
|
145
|
-
if (newline === -1) return "";
|
|
146
|
-
this._done = true;
|
|
147
|
-
const firstLine = this._buffer.slice(0, newline);
|
|
148
|
-
const rest = this._buffer.slice(newline + 1);
|
|
149
|
-
this._buffer = "";
|
|
150
|
-
return firstLine.trim().startsWith("```") ? rest : `${firstLine}\n${rest}`;
|
|
151
|
-
}
|
|
152
|
-
flush() {
|
|
153
|
-
if (this._done) return "";
|
|
154
|
-
this._done = true;
|
|
155
|
-
const buffered = this._buffer;
|
|
156
|
-
this._buffer = "";
|
|
157
|
-
return buffered.trim().startsWith("```") ? "" : buffered;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, onSend, onSendDelta, onRunStart, onRunComplete }) => {
|
|
132
|
+
const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, onSend, onSendDelta, onRunStart }) => {
|
|
161
133
|
const startedAt = Date.now();
|
|
162
134
|
const traces = iteration.traces;
|
|
163
|
-
|
|
164
|
-
const
|
|
135
|
+
controller.signal.throwIfAborted();
|
|
136
|
+
const modelRefs = Array.isArray(iteration.model) ? iteration.model : [iteration.model];
|
|
137
|
+
const models = await Promise.all(modelRefs.map((modelRef) => cognitive.getModelDetails(modelRef).catch((thrown) => {
|
|
165
138
|
throw new require_errors.CognitiveError(`Failed to fetch model details for model "${modelRef}": ${require_utils.getErrorMessage(thrown)}`);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
139
|
+
})));
|
|
140
|
+
controller.signal.throwIfAborted();
|
|
141
|
+
const model = models[0];
|
|
142
|
+
const modelLimit = Math.min(...models.map((model) => model.input.maxTokens), ctx.maxTokens ?? Infinity);
|
|
143
|
+
const responseLengthBuffer = Math.min(getModelOutputLimit(modelLimit), Math.floor(modelLimit / 2));
|
|
170
144
|
if (iteration.tokens) iteration.tokens.limit = modelLimit;
|
|
171
145
|
let messages;
|
|
172
146
|
try {
|
|
@@ -220,7 +194,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
220
194
|
const liveContent = /* @__PURE__ */ new Map();
|
|
221
195
|
let codeGenerationTraced = false;
|
|
222
196
|
let runCompleted = false;
|
|
223
|
-
let
|
|
197
|
+
let completions = [];
|
|
224
198
|
const dispatchSends = async (events) => {
|
|
225
199
|
for (const event of events) if (event.type === "item-start") {
|
|
226
200
|
liveItems.set(event.item.id, event.item);
|
|
@@ -234,7 +208,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
234
208
|
}
|
|
235
209
|
} else if (event.type === "body-delta" && onSendDelta) {
|
|
236
210
|
const item = liveItems.get(event.itemId);
|
|
237
|
-
if ((item === null || item === void 0 ? void 0 : item.kind) !== "send" ||
|
|
211
|
+
if ((item === null || item === void 0 ? void 0 : item.kind) !== "send" || runCompleted) continue;
|
|
238
212
|
const content = (liveContent.get(item.id) ?? "") + event.delta;
|
|
239
213
|
liveContent.set(item.id, content);
|
|
240
214
|
const delta = {
|
|
@@ -247,22 +221,19 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
247
221
|
};
|
|
248
222
|
await preview(delta);
|
|
249
223
|
} else if (event.type === "item-complete") {
|
|
250
|
-
if (event.item.kind === "send" && onSend && !
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
onRunComplete === null || onRunComplete === void 0 || onRunComplete(code);
|
|
260
|
-
}
|
|
224
|
+
if (event.item.kind === "send" && onSend && !runCompleted) {
|
|
225
|
+
const send = {
|
|
226
|
+
name: event.item.name,
|
|
227
|
+
props: event.item.props,
|
|
228
|
+
body: event.item.body
|
|
229
|
+
};
|
|
230
|
+
const metadata = messageMetadata(event.item.id);
|
|
231
|
+
completions.push(() => onSend(send, metadata));
|
|
232
|
+
} else if (event.item.kind === "run" && event.item.status === "complete" && !runCompleted) runCompleted = true;
|
|
261
233
|
}
|
|
262
234
|
};
|
|
263
235
|
if (typeof cognitive.generateTextStream === "function") {
|
|
264
|
-
let parser = new require_common.
|
|
265
|
-
let fence = new LeadingFenceFilter();
|
|
236
|
+
let parser = new require_common.ResponseParser();
|
|
266
237
|
const streamController = createJoinedAbortController([controller.signal]);
|
|
267
238
|
const requestedAt = Date.now();
|
|
268
239
|
const stream = cognitive.generateTextStream({
|
|
@@ -290,6 +261,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
290
261
|
};
|
|
291
262
|
raw = "";
|
|
292
263
|
let streamCompleted = false;
|
|
264
|
+
let accepted = false;
|
|
293
265
|
try {
|
|
294
266
|
while (true) {
|
|
295
267
|
var _chunk$value, _chunk$value2, _chunk$value3, _chunk$value4;
|
|
@@ -314,13 +286,13 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
314
286
|
...chunk.value.restart
|
|
315
287
|
});
|
|
316
288
|
raw = "";
|
|
317
|
-
|
|
318
|
-
|
|
289
|
+
completions = [];
|
|
290
|
+
accepted = false;
|
|
291
|
+
parser = new require_common.ResponseParser();
|
|
319
292
|
liveItems.clear();
|
|
320
293
|
liveContent.clear();
|
|
321
294
|
codeGenerationTraced = false;
|
|
322
295
|
runCompleted = false;
|
|
323
|
-
awaitsRunResult = false;
|
|
324
296
|
responseMetadata = void 0;
|
|
325
297
|
attempt = chunk.value.restart.attempt;
|
|
326
298
|
await preview({
|
|
@@ -338,29 +310,63 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
338
310
|
timeToLastToken = Date.now() - requestedAt;
|
|
339
311
|
timeToFirstToken ??= timeToLastToken;
|
|
340
312
|
raw += delta;
|
|
341
|
-
await dispatchSends(parser.push(
|
|
313
|
+
await dispatchSends(parser.push(delta));
|
|
342
314
|
}
|
|
343
315
|
if (!responseMetadata) throw new require_errors.CognitiveError("LLM streaming completed without metadata");
|
|
344
316
|
assertSuccessfulGeneration(responseMetadata);
|
|
345
|
-
|
|
346
|
-
if (
|
|
347
|
-
|
|
317
|
+
await dispatchSends(parser.finish(responseMetadata.stopReason));
|
|
318
|
+
if (parser.valid) {
|
|
319
|
+
for (const complete of completions) await complete();
|
|
320
|
+
accepted = true;
|
|
321
|
+
}
|
|
348
322
|
assistantResponse = require_common.toParsedAssistantResponse(parser.items, raw, parser.diagnostics);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
parser.finish();
|
|
325
|
+
const usage = (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.usage) ?? {
|
|
326
|
+
inputTokens: 0,
|
|
327
|
+
outputTokens: 0,
|
|
328
|
+
inputCost: 0,
|
|
329
|
+
outputCost: 0
|
|
330
|
+
};
|
|
331
|
+
iteration.llm = {
|
|
332
|
+
started_at: startedAt,
|
|
333
|
+
ended_at: Date.now(),
|
|
334
|
+
status: "error",
|
|
335
|
+
cached: (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.cached) ?? false,
|
|
336
|
+
tokens: usage.inputTokens + usage.outputTokens,
|
|
337
|
+
spend: (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.cost) ?? usage.inputCost + usage.outputCost,
|
|
338
|
+
output: raw,
|
|
339
|
+
diagnostics: parser.diagnostics,
|
|
340
|
+
model: (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.model) ?? model.id,
|
|
341
|
+
time_to_first_token: timeToFirstToken,
|
|
342
|
+
time_to_last_token: timeToLastToken,
|
|
343
|
+
usage
|
|
344
|
+
};
|
|
345
|
+
throw error;
|
|
349
346
|
} finally {
|
|
350
347
|
streamController.abort("LLM stream closed");
|
|
351
348
|
if (!streamCompleted) stream.return(void 0).catch((err) => {});
|
|
349
|
+
if (!accepted && liveContent.size) await preview({
|
|
350
|
+
restart: true,
|
|
351
|
+
iterationId: iteration.id,
|
|
352
|
+
attempt: attempt + 1,
|
|
353
|
+
fromModel: model.id,
|
|
354
|
+
toModel: model.id,
|
|
355
|
+
reason: "invalid or incomplete response envelope"
|
|
356
|
+
});
|
|
352
357
|
}
|
|
353
|
-
|
|
358
|
+
controller.signal.throwIfAborted();
|
|
354
359
|
} else {
|
|
355
360
|
const response = await cognitive.generateText(input, { signal: controller.signal }).catch((thrown) => {
|
|
356
361
|
throw new require_errors.CognitiveError(`LLM generation failed: ${require_utils.getErrorMessage(thrown)}`);
|
|
357
362
|
});
|
|
363
|
+
controller.signal.throwIfAborted();
|
|
358
364
|
if (response.error) throw new require_errors.CognitiveError(`LLM generation failed: ${response.error}`);
|
|
359
365
|
if (!response.output) throw new require_errors.CognitiveError("LLM did not return any text output");
|
|
360
366
|
responseMetadata = response.metadata;
|
|
361
367
|
assertSuccessfulGeneration(responseMetadata);
|
|
362
368
|
raw = response.output;
|
|
363
|
-
assistantResponse = ctx.version.parseAssistantResponse(raw);
|
|
369
|
+
assistantResponse = ctx.version.parseAssistantResponse(raw, responseMetadata.stopReason);
|
|
364
370
|
for (const [index, send] of assistantResponse.sends.entries()) await (onSend === null || onSend === void 0 ? void 0 : onSend(send, messageMetadata(`send-${index}`)));
|
|
365
371
|
}
|
|
366
372
|
iteration.code = assistantResponse.code;
|
|
@@ -565,8 +571,10 @@ const finalizeIteration = async ({ iteration, status, controller, onIterationEnd
|
|
|
565
571
|
//#region src/runtime/tool-wrapper.ts
|
|
566
572
|
const SLOW_TOOL_WARNING = (0, ms.default)("15s");
|
|
567
573
|
function wrapTool({ chat, tool, traces, object, iteration, beforeHook, afterHook, controller }) {
|
|
568
|
-
const
|
|
574
|
+
const traceSchema = tool.input ? require_utils.fromJSONSchemaCompat(tool.input) : void 0;
|
|
575
|
+
const getToolInput = (input) => (traceSchema === null || traceSchema === void 0 ? void 0 : traceSchema.safeParse(input).data) ?? input;
|
|
569
576
|
return async function(input) {
|
|
577
|
+
controller.signal.throwIfAborted();
|
|
570
578
|
const toolCallId = `tcall_${(0, ulid.ulid)()}`;
|
|
571
579
|
const originalInput = input;
|
|
572
580
|
let effectiveInput = input;
|
|
@@ -642,6 +650,7 @@ function wrapTool({ chat, tool, traces, object, iteration, beforeHook, afterHook
|
|
|
642
650
|
object,
|
|
643
651
|
toolCallId
|
|
644
652
|
}));
|
|
653
|
+
controller.signal.throwIfAborted();
|
|
645
654
|
if (typeof (beforeRes === null || beforeRes === void 0 ? void 0 : beforeRes.input) !== "undefined") effectiveInput = beforeRes.input;
|
|
646
655
|
output = await tool.execute(effectiveInput, {
|
|
647
656
|
callId: toolCallId,
|
|
@@ -658,9 +667,16 @@ function wrapTool({ chat, tool, traces, object, iteration, beforeHook, afterHook
|
|
|
658
667
|
}));
|
|
659
668
|
if (typeof (afterRes === null || afterRes === void 0 ? void 0 : afterRes.output) !== "undefined") output = afterRes.output;
|
|
660
669
|
} catch (err) {
|
|
661
|
-
|
|
670
|
+
try {
|
|
671
|
+
if (!await handleSignals(err)) {
|
|
672
|
+
success = false;
|
|
673
|
+
error = err;
|
|
674
|
+
output = void 0;
|
|
675
|
+
}
|
|
676
|
+
} catch (hookError) {
|
|
662
677
|
success = false;
|
|
663
|
-
error =
|
|
678
|
+
error = hookError;
|
|
679
|
+
output = void 0;
|
|
664
680
|
}
|
|
665
681
|
} finally {
|
|
666
682
|
clearTimeout(alertSlowTool);
|
|
@@ -960,8 +976,6 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
960
976
|
};
|
|
961
977
|
});
|
|
962
978
|
};
|
|
963
|
-
const canExecuteEarly = typeof onBeforeExecution !== "function" && !ctx.midStreamFallback;
|
|
964
|
-
let earlyExecution;
|
|
965
979
|
await generateCode({
|
|
966
980
|
iteration,
|
|
967
981
|
ctx,
|
|
@@ -969,15 +983,6 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
969
983
|
controller,
|
|
970
984
|
metadata,
|
|
971
985
|
onRunStart: () => require_vm.warmupVM(),
|
|
972
|
-
onRunComplete: canExecuteEarly ? (code) => {
|
|
973
|
-
if (!code.length || controller.signal.aborted || earlyExecution) return;
|
|
974
|
-
iteration.code = code;
|
|
975
|
-
earlyExecution = {
|
|
976
|
-
code,
|
|
977
|
-
started_at: Date.now(),
|
|
978
|
-
promise: runCode(code)
|
|
979
|
-
};
|
|
980
|
-
} : void 0,
|
|
981
986
|
onSend: async (send, messageMetadata) => {
|
|
982
987
|
if (!ctx.chat) return;
|
|
983
988
|
const sendStartedAt = Date.now();
|
|
@@ -1002,7 +1007,6 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
1002
1007
|
},
|
|
1003
1008
|
onSendDelta: ((_ctx$chat = ctx.chat) === null || _ctx$chat === void 0 ? void 0 : _ctx$chat.onMessageDelta) ? (delta) => ctx.chat.onMessageDelta(delta) : void 0
|
|
1004
1009
|
});
|
|
1005
|
-
if (earlyExecution) iteration.code = earlyExecution.code;
|
|
1006
1010
|
if (typeof onBeforeExecution === "function") try {
|
|
1007
1011
|
const hookRes = await onBeforeExecution(iteration, controller);
|
|
1008
1012
|
if (typeof (hookRes === null || hookRes === void 0 ? void 0 : hookRes.code) === "string" && hookRes.code.trim().length > 0) iteration.code = hookRes.code.trim();
|
|
@@ -1040,7 +1044,7 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
1040
1044
|
return;
|
|
1041
1045
|
}
|
|
1042
1046
|
if (!iteration.code) {
|
|
1043
|
-
var _iteration$
|
|
1047
|
+
var _iteration$llm;
|
|
1044
1048
|
if (iteration.next) {
|
|
1045
1049
|
await applyNextExit({
|
|
1046
1050
|
iteration,
|
|
@@ -1049,26 +1053,14 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
1049
1053
|
});
|
|
1050
1054
|
return;
|
|
1051
1055
|
}
|
|
1052
|
-
if (ctx.chat && ((_iteration$sends = iteration.sends) === null || _iteration$sends === void 0 ? void 0 : _iteration$sends.length)) {
|
|
1053
|
-
iteration.next = {
|
|
1054
|
-
name: "listen",
|
|
1055
|
-
props: {}
|
|
1056
|
-
};
|
|
1057
|
-
await applyNextExit({
|
|
1058
|
-
iteration,
|
|
1059
|
-
controller,
|
|
1060
|
-
onExit
|
|
1061
|
-
});
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
1056
|
iteration.end({
|
|
1065
1057
|
type: "invalid_code_error",
|
|
1066
|
-
invalid_code_error: { message: "The response did not include a ■run block or a ■next exit. Reply
|
|
1058
|
+
invalid_code_error: { message: ((_iteration$llm = iteration.llm) === null || _iteration$llm === void 0 || (_iteration$llm = _iteration$llm.diagnostics) === null || _iteration$llm === void 0 || (_iteration$llm = _iteration$llm.find((diagnostic) => diagnostic.code === "invalid-envelope")) === null || _iteration$llm === void 0 ? void 0 : _iteration$llm.message) ?? "The response did not include a ■run block or a ■next exit. Reply with ■start, the required ■ blocks, and ■end." }
|
|
1067
1059
|
});
|
|
1068
1060
|
return;
|
|
1069
1061
|
}
|
|
1070
|
-
const startedAt =
|
|
1071
|
-
const result =
|
|
1062
|
+
const startedAt = Date.now();
|
|
1063
|
+
const result = await runCode(iteration.code);
|
|
1072
1064
|
await interpretVMResult({
|
|
1073
1065
|
iteration,
|
|
1074
1066
|
result,
|