llmz 0.7.1 → 0.9.0
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/{_baseForOwn-buOZDFbK.cjs → _baseForOwn-BfWDTL8L.cjs} +0 -50
- package/dist/chat.d.ts +6 -6
- package/dist/common-BlRFtdf2.js +807 -0
- package/dist/common-BnvrDnIT.cjs +860 -0
- package/dist/compiler-C-OI9sim.cjs +547 -0
- package/dist/compiler-CW1VjQsn.js +473 -0
- package/dist/{component-BwixNVH8.cjs → component-C6Agl2ns.cjs} +3 -3
- package/dist/component.d.ts +4 -4
- package/dist/component.default.d.ts +70 -87
- package/dist/component.default.test.d.ts +1 -0
- package/dist/context.d.ts +14 -8
- package/dist/{custom-client-CMuy7fXU.js → custom-client-ChuZ63zp.js} +128 -30
- package/dist/{custom-client-Bp1TgTKk.cjs → custom-client-DAsGRnYc.cjs} +131 -33
- package/dist/{dual-modes-mNyMThtf.js → dual-modes-DDkoCp3R.js} +1771 -1489
- package/dist/{dual-modes-CfqTk9M8.cjs → dual-modes-DPXiuvNe.cjs} +1767 -1491
- package/dist/example-format.d.ts +8 -0
- package/dist/example.d.ts +45 -0
- package/dist/example.test.d.ts +1 -0
- package/dist/{execute-DP_17lYZ.js → execute-BWcdv9so.js} +77 -85
- package/dist/{execute-msui51b2.cjs → execute-DM2-7y86.cjs} +83 -92
- package/dist/{exit-BGi0Kk0y.cjs → exit-DUM96DN1.cjs} +3 -3
- package/dist/exit-parser.d.ts +2 -0
- package/dist/index.cjs +137 -217
- package/dist/index.d.ts +2 -0
- package/dist/index.js +115 -196
- package/dist/index.workerd.js +16664 -15533
- package/dist/inspect.d.ts +2 -0
- package/dist/{jsx-BWvT6ukg.cjs → jsx-owqxrquU.cjs} +2 -2
- package/dist/message-stream/instructions.d.ts +8 -0
- package/dist/message-stream/parser.d.ts +9 -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 +2 -0
- package/dist/prompts/chat-mode/user.d.ts +2 -0
- 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/execution-history.d.ts +6 -0
- package/dist/prompts/execution-state.d.ts +3 -0
- package/dist/prompts/long-search.test.d.ts +1 -0
- package/dist/prompts/prompt.d.ts +31 -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/protocol.test.d.ts +1 -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 +2 -0
- package/dist/prompts/worker-mode/user.d.ts +2 -0
- 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/protocol-adherence.test.d.ts +1 -0
- package/dist/runtime/types.d.ts +13 -7
- package/dist/{tool-ReA9gxMp.cjs → tool-Dy6AJpJH.cjs} +4 -4
- package/dist/{truncator-B6aaJaN1.cjs → truncator-CLkouTCO.cjs} +3 -3
- package/dist/{typings-BwAz_TM9.cjs → typings-3lsqCbkn.cjs} +3 -3
- package/dist/{utils-ZpJm00ed.cjs → utils-3ESwP3yg.cjs} +2 -2
- package/dist/{vm-C5vf1LH3.js → vm-BLsHw1da.js} +3 -462
- package/dist/{vm-BjkJqSQH.cjs → vm-D6s1zF6M.cjs} +28 -489
- 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.";
|
|
@@ -0,0 +1,45 @@
|
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
1
|
+
import { a as isEqual, l as toNumber } from "./dual-modes-DDkoCp3R.js";
|
|
2
|
+
import { a as ResponseParser, i as toParsedAssistantResponse } from "./common-BlRFtdf2.js";
|
|
3
|
+
import { d as Snapshot, f as parseExit, l as PartialExecutionResult, n as Context, s as ErrorExecutionResult, t as _CustomModelClient, u as SuccessExecutionResult } from "./custom-client-ChuZ63zp.js";
|
|
3
4
|
import { d as stripInvalidIdentifiers, i as getErrorMessage, s as init } from "./utils-UBeAFeEI.js";
|
|
4
5
|
import { t as createJsxComponent } from "./jsx-CIgdGGVs.js";
|
|
5
6
|
import { t as cleanStackTrace } from "./stack-traces-BIE_5Xwf.js";
|
|
6
7
|
import { a as InvalidCodeError, c as SnapshotSignal, i as CognitiveError, l as ThinkSignal, n as CodeExecutionError, o as LoopExceededError, s as Signals, t as AssignmentError } from "./errors-Cg1G0Awu.js";
|
|
7
8
|
import { n as truncateWrappedContent } from "./truncator-DZqEqnpD.js";
|
|
8
|
-
import {
|
|
9
|
+
import { r as hasTopLevelReturn } from "./compiler-CW1VjQsn.js";
|
|
10
|
+
import { runAsyncFunction, warmupVM } from "./vm-BLsHw1da.js";
|
|
9
11
|
import { z } from "@bpinternal/zui";
|
|
10
12
|
import { ulid } from "ulid";
|
|
11
13
|
import { Client } from "@botpress/client";
|
|
@@ -126,35 +128,7 @@ const assertSuccessfulGeneration = (metadata) => {
|
|
|
126
128
|
if (metadata.stopReason === "max_tokens" || metadata.stopReason === "content_filter") throw new CognitiveError(`LLM generation did not complete: stopReason=${metadata.stopReason}`);
|
|
127
129
|
};
|
|
128
130
|
const getModelOutputLimit = (inputLength) => clamp(RESPONSE_LENGTH_BUFFER.PERCENTAGE * inputLength, RESPONSE_LENGTH_BUFFER.MIN_TOKENS, RESPONSE_LENGTH_BUFFER.MAX_TOKENS);
|
|
129
|
-
|
|
130
|
-
* Models sometimes wrap their whole response in a code fence. The fence has to
|
|
131
|
-
* be removed before it reaches the incremental parser to avoid a spurious
|
|
132
|
-
* unexpected-text diagnostic. Works on arbitrary chunk boundaries
|
|
133
|
-
* by holding content back until the first newline.
|
|
134
|
-
*/
|
|
135
|
-
var LeadingFenceFilter = class {
|
|
136
|
-
_buffer = "";
|
|
137
|
-
_done = false;
|
|
138
|
-
push(text) {
|
|
139
|
-
if (this._done) return text;
|
|
140
|
-
this._buffer += text;
|
|
141
|
-
const newline = this._buffer.indexOf("\n");
|
|
142
|
-
if (newline === -1) return "";
|
|
143
|
-
this._done = true;
|
|
144
|
-
const firstLine = this._buffer.slice(0, newline);
|
|
145
|
-
const rest = this._buffer.slice(newline + 1);
|
|
146
|
-
this._buffer = "";
|
|
147
|
-
return firstLine.trim().startsWith("```") ? rest : `${firstLine}\n${rest}`;
|
|
148
|
-
}
|
|
149
|
-
flush() {
|
|
150
|
-
if (this._done) return "";
|
|
151
|
-
this._done = true;
|
|
152
|
-
const buffered = this._buffer;
|
|
153
|
-
this._buffer = "";
|
|
154
|
-
return buffered.trim().startsWith("```") ? "" : buffered;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, onSend, onSendDelta, onRunStart, onRunComplete }) => {
|
|
131
|
+
const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, onSend, onSendDelta, onRunStart }) => {
|
|
158
132
|
const startedAt = Date.now();
|
|
159
133
|
const traces = iteration.traces;
|
|
160
134
|
const modelRef = Array.isArray(iteration.model) ? iteration.model[0] : iteration.model;
|
|
@@ -217,6 +191,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
217
191
|
const liveContent = /* @__PURE__ */ new Map();
|
|
218
192
|
let codeGenerationTraced = false;
|
|
219
193
|
let runCompleted = false;
|
|
194
|
+
let completions = [];
|
|
220
195
|
const dispatchSends = async (events) => {
|
|
221
196
|
for (const event of events) if (event.type === "item-start") {
|
|
222
197
|
liveItems.set(event.item.id, event.item);
|
|
@@ -230,7 +205,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
230
205
|
}
|
|
231
206
|
} else if (event.type === "body-delta" && onSendDelta) {
|
|
232
207
|
const item = liveItems.get(event.itemId);
|
|
233
|
-
if ((item === null || item === void 0 ? void 0 : item.kind) !== "send") continue;
|
|
208
|
+
if ((item === null || item === void 0 ? void 0 : item.kind) !== "send" || runCompleted) continue;
|
|
234
209
|
const content = (liveContent.get(item.id) ?? "") + event.delta;
|
|
235
210
|
liveContent.set(item.id, content);
|
|
236
211
|
const delta = {
|
|
@@ -243,21 +218,19 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
243
218
|
};
|
|
244
219
|
await preview(delta);
|
|
245
220
|
} else if (event.type === "item-complete") {
|
|
246
|
-
if (event.item.kind === "send" && onSend)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
221
|
+
if (event.item.kind === "send" && onSend && !runCompleted) {
|
|
222
|
+
const send = {
|
|
223
|
+
name: event.item.name,
|
|
224
|
+
props: event.item.props,
|
|
225
|
+
body: event.item.body
|
|
226
|
+
};
|
|
227
|
+
const metadata = messageMetadata(event.item.id);
|
|
228
|
+
completions.push(() => onSend(send, metadata));
|
|
229
|
+
} else if (event.item.kind === "run" && event.item.status === "complete" && !runCompleted) runCompleted = true;
|
|
256
230
|
}
|
|
257
231
|
};
|
|
258
232
|
if (typeof cognitive.generateTextStream === "function") {
|
|
259
|
-
let parser = new
|
|
260
|
-
let fence = new LeadingFenceFilter();
|
|
233
|
+
let parser = new ResponseParser();
|
|
261
234
|
const streamController = createJoinedAbortController([controller.signal]);
|
|
262
235
|
const requestedAt = Date.now();
|
|
263
236
|
const stream = cognitive.generateTextStream({
|
|
@@ -285,6 +258,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
285
258
|
};
|
|
286
259
|
raw = "";
|
|
287
260
|
let streamCompleted = false;
|
|
261
|
+
let accepted = false;
|
|
288
262
|
try {
|
|
289
263
|
while (true) {
|
|
290
264
|
var _chunk$value, _chunk$value2, _chunk$value3, _chunk$value4;
|
|
@@ -309,8 +283,9 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
309
283
|
...chunk.value.restart
|
|
310
284
|
});
|
|
311
285
|
raw = "";
|
|
312
|
-
|
|
313
|
-
|
|
286
|
+
completions = [];
|
|
287
|
+
accepted = false;
|
|
288
|
+
parser = new ResponseParser();
|
|
314
289
|
liveItems.clear();
|
|
315
290
|
liveContent.clear();
|
|
316
291
|
codeGenerationTraced = false;
|
|
@@ -332,19 +307,52 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
332
307
|
timeToLastToken = Date.now() - requestedAt;
|
|
333
308
|
timeToFirstToken ??= timeToLastToken;
|
|
334
309
|
raw += delta;
|
|
335
|
-
await dispatchSends(parser.push(
|
|
310
|
+
await dispatchSends(parser.push(delta));
|
|
336
311
|
}
|
|
337
312
|
if (!responseMetadata) throw new CognitiveError("LLM streaming completed without metadata");
|
|
338
313
|
assertSuccessfulGeneration(responseMetadata);
|
|
339
|
-
|
|
340
|
-
if (
|
|
341
|
-
|
|
314
|
+
await dispatchSends(parser.finish(responseMetadata.stopReason));
|
|
315
|
+
if (parser.valid) {
|
|
316
|
+
for (const complete of completions) await complete();
|
|
317
|
+
accepted = true;
|
|
318
|
+
}
|
|
342
319
|
assistantResponse = toParsedAssistantResponse(parser.items, raw, parser.diagnostics);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
parser.finish();
|
|
322
|
+
const usage = (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.usage) ?? {
|
|
323
|
+
inputTokens: 0,
|
|
324
|
+
outputTokens: 0,
|
|
325
|
+
inputCost: 0,
|
|
326
|
+
outputCost: 0
|
|
327
|
+
};
|
|
328
|
+
iteration.llm = {
|
|
329
|
+
started_at: startedAt,
|
|
330
|
+
ended_at: Date.now(),
|
|
331
|
+
status: "error",
|
|
332
|
+
cached: (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.cached) ?? false,
|
|
333
|
+
tokens: usage.inputTokens + usage.outputTokens,
|
|
334
|
+
spend: (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.cost) ?? usage.inputCost + usage.outputCost,
|
|
335
|
+
output: raw,
|
|
336
|
+
diagnostics: parser.diagnostics,
|
|
337
|
+
model: (responseMetadata === null || responseMetadata === void 0 ? void 0 : responseMetadata.model) ?? model.id,
|
|
338
|
+
time_to_first_token: timeToFirstToken,
|
|
339
|
+
time_to_last_token: timeToLastToken,
|
|
340
|
+
usage
|
|
341
|
+
};
|
|
342
|
+
throw error;
|
|
343
343
|
} finally {
|
|
344
344
|
streamController.abort("LLM stream closed");
|
|
345
345
|
if (!streamCompleted) stream.return(void 0).catch((err) => {});
|
|
346
|
+
if (!accepted && liveContent.size) await preview({
|
|
347
|
+
restart: true,
|
|
348
|
+
iterationId: iteration.id,
|
|
349
|
+
attempt: attempt + 1,
|
|
350
|
+
fromModel: model.id,
|
|
351
|
+
toModel: model.id,
|
|
352
|
+
reason: "invalid or incomplete response envelope"
|
|
353
|
+
});
|
|
346
354
|
}
|
|
347
|
-
|
|
355
|
+
controller.signal.throwIfAborted();
|
|
348
356
|
} else {
|
|
349
357
|
const response = await cognitive.generateText(input, { signal: controller.signal }).catch((thrown) => {
|
|
350
358
|
throw new CognitiveError(`LLM generation failed: ${getErrorMessage(thrown)}`);
|
|
@@ -354,7 +362,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
354
362
|
responseMetadata = response.metadata;
|
|
355
363
|
assertSuccessfulGeneration(responseMetadata);
|
|
356
364
|
raw = response.output;
|
|
357
|
-
assistantResponse = ctx.version.parseAssistantResponse(raw);
|
|
365
|
+
assistantResponse = ctx.version.parseAssistantResponse(raw, responseMetadata.stopReason);
|
|
358
366
|
for (const [index, send] of assistantResponse.sends.entries()) await (onSend === null || onSend === void 0 ? void 0 : onSend(send, messageMetadata(`send-${index}`)));
|
|
359
367
|
}
|
|
360
368
|
iteration.code = assistantResponse.code;
|
|
@@ -396,6 +404,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
|
|
|
396
404
|
//#endregion
|
|
397
405
|
//#region src/runtime/interpret-result.ts
|
|
398
406
|
const interpretVMResult = async ({ iteration, result, controller, startedAt, onExit }) => {
|
|
407
|
+
Object.assign(iteration.variables, Object.fromEntries(Object.entries(result.variables ?? {}).filter(([, value]) => value !== "[[non-primitive]]")));
|
|
399
408
|
if (result.error && result.error instanceof InvalidCodeError) {
|
|
400
409
|
iteration.end({
|
|
401
410
|
type: "invalid_code_error",
|
|
@@ -443,7 +452,8 @@ const interpretVMResult = async ({ iteration, result, controller, startedAt, onE
|
|
|
443
452
|
thinking_requested: {
|
|
444
453
|
variables: result.signal.context,
|
|
445
454
|
reason: result.signal.reason,
|
|
446
|
-
metadata: result.signal.metadata
|
|
455
|
+
metadata: result.signal.metadata,
|
|
456
|
+
interrupted: true
|
|
447
457
|
}
|
|
448
458
|
});
|
|
449
459
|
return;
|
|
@@ -504,11 +514,14 @@ const applyNextExit = async ({ iteration, controller, onExit }) => {
|
|
|
504
514
|
value: parsedExit.success ? parsedExit.value : next.props
|
|
505
515
|
};
|
|
506
516
|
if (!parsedExit.success) {
|
|
517
|
+
var _parsedExit$validatio;
|
|
518
|
+
const details = (_parsedExit$validatio = parsedExit.validationErrors) === null || _parsedExit$validatio === void 0 ? void 0 : _parsedExit$validatio.join("; ");
|
|
519
|
+
const error = [parsedExit.error.split("\n")[0], details].filter(Boolean).join(". ");
|
|
507
520
|
iteration.end({
|
|
508
521
|
type: "exit_error",
|
|
509
522
|
exit_error: {
|
|
510
523
|
exit: next.name,
|
|
511
|
-
message:
|
|
524
|
+
message: `${error}. Received props: ${JSON.stringify(next.props)}. Choose an exit from <exits> and supply its required props as ONE JSON object on the SAME LINE as ■next=${next.name}. Do not use a JavaScript return statement or wrap the fields in "value" or "props".`,
|
|
512
525
|
return_value: returnValue
|
|
513
526
|
}
|
|
514
527
|
});
|
|
@@ -748,6 +761,7 @@ const executeContextInternal = async (props) => {
|
|
|
748
761
|
const ctx = new Context({
|
|
749
762
|
chat: props.chat,
|
|
750
763
|
instructions: props.instructions,
|
|
764
|
+
examples: props.examples,
|
|
751
765
|
objects: props.objects,
|
|
752
766
|
tools: props.tools,
|
|
753
767
|
loop: (_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.loop,
|
|
@@ -948,8 +962,6 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
948
962
|
};
|
|
949
963
|
});
|
|
950
964
|
};
|
|
951
|
-
const canExecuteEarly = typeof onBeforeExecution !== "function" && !ctx.midStreamFallback;
|
|
952
|
-
let earlyExecution;
|
|
953
965
|
await generateCode({
|
|
954
966
|
iteration,
|
|
955
967
|
ctx,
|
|
@@ -957,22 +969,15 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
957
969
|
controller,
|
|
958
970
|
metadata,
|
|
959
971
|
onRunStart: () => warmupVM(),
|
|
960
|
-
onRunComplete: canExecuteEarly ? (code) => {
|
|
961
|
-
if (!code.length || controller.signal.aborted || earlyExecution) return;
|
|
962
|
-
iteration.code = code;
|
|
963
|
-
earlyExecution = {
|
|
964
|
-
code,
|
|
965
|
-
started_at: Date.now(),
|
|
966
|
-
promise: runCode(code)
|
|
967
|
-
};
|
|
968
|
-
} : void 0,
|
|
969
972
|
onSend: async (send, messageMetadata) => {
|
|
970
973
|
if (!ctx.chat) return;
|
|
971
974
|
const sendStartedAt = Date.now();
|
|
972
|
-
const
|
|
975
|
+
const registered = iteration.components.find((component) => component.definition.name.toLowerCase() === send.name);
|
|
976
|
+
const children = send.body ? [send.body] : [];
|
|
977
|
+
const component = registered ? registered.render(send.props, children) : createJsxComponent({
|
|
973
978
|
type: send.name,
|
|
974
979
|
props: send.props,
|
|
975
|
-
children
|
|
980
|
+
children
|
|
976
981
|
});
|
|
977
982
|
try {
|
|
978
983
|
await ctx.chat.handler(component, messageMetadata);
|
|
@@ -988,7 +993,6 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
988
993
|
},
|
|
989
994
|
onSendDelta: ((_ctx$chat = ctx.chat) === null || _ctx$chat === void 0 ? void 0 : _ctx$chat.onMessageDelta) ? (delta) => ctx.chat.onMessageDelta(delta) : void 0
|
|
990
995
|
});
|
|
991
|
-
if (earlyExecution) iteration.code = earlyExecution.code;
|
|
992
996
|
if (typeof onBeforeExecution === "function") try {
|
|
993
997
|
const hookRes = await onBeforeExecution(iteration, controller);
|
|
994
998
|
if (typeof (hookRes === null || hookRes === void 0 ? void 0 : hookRes.code) === "string" && hookRes.code.trim().length > 0) iteration.code = hookRes.code.trim();
|
|
@@ -1026,7 +1030,7 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
1026
1030
|
return;
|
|
1027
1031
|
}
|
|
1028
1032
|
if (!iteration.code) {
|
|
1029
|
-
var _iteration$
|
|
1033
|
+
var _iteration$llm;
|
|
1030
1034
|
if (iteration.next) {
|
|
1031
1035
|
await applyNextExit({
|
|
1032
1036
|
iteration,
|
|
@@ -1035,26 +1039,14 @@ const executeIteration = async ({ iteration, ctx, cognitive, controller, onExit,
|
|
|
1035
1039
|
});
|
|
1036
1040
|
return;
|
|
1037
1041
|
}
|
|
1038
|
-
if (ctx.chat && ((_iteration$sends = iteration.sends) === null || _iteration$sends === void 0 ? void 0 : _iteration$sends.length)) {
|
|
1039
|
-
iteration.next = {
|
|
1040
|
-
name: "listen",
|
|
1041
|
-
props: {}
|
|
1042
|
-
};
|
|
1043
|
-
await applyNextExit({
|
|
1044
|
-
iteration,
|
|
1045
|
-
controller,
|
|
1046
|
-
onExit
|
|
1047
|
-
});
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
1042
|
iteration.end({
|
|
1051
1043
|
type: "invalid_code_error",
|
|
1052
|
-
invalid_code_error: { message: "The response did not include a ■run block or a ■next exit. Reply
|
|
1044
|
+
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." }
|
|
1053
1045
|
});
|
|
1054
1046
|
return;
|
|
1055
1047
|
}
|
|
1056
|
-
const startedAt =
|
|
1057
|
-
const result =
|
|
1048
|
+
const startedAt = Date.now();
|
|
1049
|
+
const result = await runCode(iteration.code);
|
|
1058
1050
|
await interpretVMResult({
|
|
1059
1051
|
iteration,
|
|
1060
1052
|
result,
|