llmz 0.0.30 → 0.0.32
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/{chunk-7POUFE5M.js → chunk-23SY6IDW.js} +63 -9
- package/dist/{chunk-KQPGB6GB.js → chunk-4JN4PPGP.js} +293 -4
- package/dist/{chunk-VADA6DMR.cjs → chunk-4XIOQWVZ.cjs} +301 -12
- package/dist/{chunk-WP4F6KMW.cjs → chunk-5BEKU5MZ.cjs} +2 -2
- package/dist/{chunk-R3LXNE5N.cjs → chunk-5FWOHMO4.cjs} +325 -60
- package/dist/{chunk-HCC76DDO.js → chunk-AAHUDKBY.js} +2 -2
- package/dist/{chunk-DCYSCVQM.js → chunk-G3LSBWJT.js} +304 -39
- package/dist/{chunk-RLOPQZTQ.cjs → chunk-INDOGCAQ.cjs} +2 -2
- package/dist/{chunk-T63Y6GTW.cjs → chunk-PK72FAKD.cjs} +2 -1
- package/dist/{chunk-273DEMEU.cjs → chunk-SOEKWFU2.cjs} +64 -10
- package/dist/{chunk-IUE5BW56.js → chunk-U4HWJLF2.js} +1 -1
- package/dist/{chunk-MYLTD5WT.js → chunk-WSVDMGMR.js} +2 -1
- package/dist/compiler/plugins/html-to-markdown.d.ts +21 -0
- package/dist/compiler/plugins/jsx-undefined-vars.d.ts +14 -0
- package/dist/context.d.ts +20 -0
- package/dist/{dual-modes-DW3KRXT2.js → dual-modes-LEAHGCOF.js} +1 -1
- package/dist/{dual-modes-F4UV5VAZ.cjs → dual-modes-UBHAMQW4.cjs} +2 -2
- package/dist/errors.d.ts +2 -1
- package/dist/exit-parser.d.ts +37 -0
- package/dist/index.cjs +20 -18
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -12
- package/dist/{llmz-N6KWKJ2Q.js → llmz-3E2JM3HM.js} +85 -42
- package/dist/{llmz-DYB74G5C.cjs → llmz-HGUVAYIN.cjs} +105 -62
- package/dist/llmz.d.ts +12 -0
- package/dist/prompts/worker-mode/system.md.d.ts +1 -1
- package/dist/result.d.ts +18 -0
- package/dist/{tool-GEBXW6AQ.js → tool-7QXH6A24.js} +3 -3
- package/dist/{tool-GMYMVXUK.cjs → tool-JVLOALQN.cjs} +4 -4
- package/dist/tool.d.ts +1 -1
- package/dist/{typings-3VYUEACY.js → typings-ALZEKGV6.js} +2 -2
- package/dist/{typings-2RAAZ2YP.cjs → typings-OLI56LGT.cjs} +3 -3
- package/dist/{vm-NGQ6DRS3.cjs → vm-VFORKC54.cjs} +3 -3
- package/dist/{vm-J6UNJGIN.js → vm-Y3WY2627.js} +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PluginObj } from '@babel/core';
|
|
2
|
+
/**
|
|
3
|
+
* This plugin transforms JSX expressions that reference undefined variables
|
|
4
|
+
* into safe fallbacks that display the variable name as a string.
|
|
5
|
+
*
|
|
6
|
+
* For example:
|
|
7
|
+
* <div>{content}</div>
|
|
8
|
+
* becomes:
|
|
9
|
+
* <div>{(() => { try { return content } catch { return 'content' } })()}</div>
|
|
10
|
+
*
|
|
11
|
+
* This prevents "variable is not defined" errors when the LLM generates JSX
|
|
12
|
+
* with variable references that don't exist in the actual execution scope.
|
|
13
|
+
*/
|
|
14
|
+
export declare function jsxUndefinedVarsPlugin(): PluginObj;
|
package/dist/context.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare namespace IterationStatuses {
|
|
|
50
50
|
thinking_requested: {
|
|
51
51
|
reason?: string;
|
|
52
52
|
variables: Record<string, unknown>;
|
|
53
|
+
metadata?: Record<string, unknown>;
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
56
|
type Callback = {
|
|
@@ -351,6 +352,7 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
|
|
|
351
352
|
get tools(): Tool<import("./types.js").ZuiType, import("./types.js").ZuiType>[];
|
|
352
353
|
get objects(): ObjectInstance[];
|
|
353
354
|
get model(): Models | Models[];
|
|
355
|
+
set model(value: Models | Models[]);
|
|
354
356
|
get temperature(): number;
|
|
355
357
|
get exits(): Exit<unknown>[];
|
|
356
358
|
get instructions(): string | undefined;
|
|
@@ -363,6 +365,12 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
|
|
|
363
365
|
spend: number;
|
|
364
366
|
output: string;
|
|
365
367
|
model: string;
|
|
368
|
+
usage: {
|
|
369
|
+
inputCost: number;
|
|
370
|
+
outputCost: number;
|
|
371
|
+
inputTokens: number;
|
|
372
|
+
outputTokens: number;
|
|
373
|
+
};
|
|
366
374
|
};
|
|
367
375
|
hasExited(this: this): this is this & {
|
|
368
376
|
status: IterationStatuses.ExitSuccess;
|
|
@@ -407,6 +415,12 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
|
|
|
407
415
|
spend: number;
|
|
408
416
|
output: string;
|
|
409
417
|
model: string;
|
|
418
|
+
usage: {
|
|
419
|
+
inputCost: number;
|
|
420
|
+
outputCost: number;
|
|
421
|
+
inputTokens: number;
|
|
422
|
+
outputTokens: number;
|
|
423
|
+
};
|
|
410
424
|
} | undefined;
|
|
411
425
|
transcript: Transcript.Message[];
|
|
412
426
|
tools: {
|
|
@@ -517,6 +531,12 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
517
531
|
spend: number;
|
|
518
532
|
output: string;
|
|
519
533
|
model: string;
|
|
534
|
+
usage: {
|
|
535
|
+
inputCost: number;
|
|
536
|
+
outputCost: number;
|
|
537
|
+
inputTokens: number;
|
|
538
|
+
outputTokens: number;
|
|
539
|
+
};
|
|
520
540
|
} | undefined;
|
|
521
541
|
transcript: Transcript.Message[];
|
|
522
542
|
tools: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk5BEKU5MZcjs = require('./chunk-5BEKU5MZ.cjs');
|
|
4
4
|
require('./chunk-KIN7Y247.cjs');
|
|
5
5
|
require('./chunk-ZRCU35UV.cjs');
|
|
6
6
|
require('./chunk-KMZDFWYZ.cjs');
|
|
@@ -9,4 +9,4 @@ require('./chunk-WHNOR4ZU.cjs');
|
|
|
9
9
|
require('./chunk-UQOBUJIQ.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.DualModePrompt =
|
|
12
|
+
exports.DualModePrompt = _chunk5BEKU5MZcjs.DualModePrompt;
|
package/dist/errors.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ export declare class VMLoopSignal extends VMSignal {
|
|
|
40
40
|
export declare class ThinkSignal extends VMLoopSignal {
|
|
41
41
|
reason: string;
|
|
42
42
|
context?: any;
|
|
43
|
-
|
|
43
|
+
metadata?: Record<string, unknown> | undefined;
|
|
44
|
+
constructor(reason: string, context?: any, metadata?: Record<string, unknown> | undefined);
|
|
44
45
|
toString(): string;
|
|
45
46
|
}
|
|
46
47
|
export declare class CodeExecutionError extends Error {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Exit } from './exit.js';
|
|
2
|
+
/**
|
|
3
|
+
* Result of parsing an exit from return value
|
|
4
|
+
*/
|
|
5
|
+
export type ParsedExit = {
|
|
6
|
+
success: true;
|
|
7
|
+
exit: Exit;
|
|
8
|
+
value: unknown;
|
|
9
|
+
} | {
|
|
10
|
+
success: false;
|
|
11
|
+
error: string;
|
|
12
|
+
returnValue: unknown;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Parses and validates a return value against a list of exits.
|
|
16
|
+
* Attempts to intelligently fit the data to the expected schema.
|
|
17
|
+
*
|
|
18
|
+
* @param returnValue - The raw return value from code execution
|
|
19
|
+
* @param exits - Available exits to match against
|
|
20
|
+
* @returns Parsed exit result with validated data or error
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const exits = [
|
|
25
|
+
* new Exit({ name: 'done', schema: z.object({ result: z.string() }) })
|
|
26
|
+
* ]
|
|
27
|
+
*
|
|
28
|
+
* // Returns primitive value - will be smart-wrapped
|
|
29
|
+
* const result = parseExit({ action: 'done', data: 'hello' }, exits)
|
|
30
|
+
* // result.success === true
|
|
31
|
+
* // result.value === { result: 'hello' }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseExit(returnValue: {
|
|
35
|
+
action: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
} | null, exits: Exit[]): ParsedExit;
|
package/dist/index.cjs
CHANGED
|
@@ -8,21 +8,22 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var _chunkVADA6DMRcjs = require('./chunk-VADA6DMR.cjs');
|
|
12
|
-
require('./chunk-WP4F6KMW.cjs');
|
|
13
11
|
|
|
12
|
+
var _chunk4XIOQWVZcjs = require('./chunk-4XIOQWVZ.cjs');
|
|
13
|
+
require('./chunk-5BEKU5MZ.cjs');
|
|
14
14
|
|
|
15
|
-
var _chunk273DEMEUcjs = require('./chunk-273DEMEU.cjs');
|
|
16
15
|
|
|
16
|
+
var _chunkSOEKWFU2cjs = require('./chunk-SOEKWFU2.cjs');
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var _chunkRLOPQZTQcjs = require('./chunk-RLOPQZTQ.cjs');
|
|
20
19
|
|
|
20
|
+
var _chunkINDOGCAQcjs = require('./chunk-INDOGCAQ.cjs');
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
|
|
26
27
|
require('./chunk-KIN7Y247.cjs');
|
|
27
28
|
|
|
28
29
|
|
|
@@ -296,12 +297,12 @@ async function hoistTypings(code, formatOptions) {
|
|
|
296
297
|
} catch (err) {
|
|
297
298
|
console.error(err);
|
|
298
299
|
if (formatOptions.throwOnError) {
|
|
299
|
-
throw new (0,
|
|
300
|
+
throw new (0, _chunkPK72FAKDcjs.CodeFormattingError)(err instanceof Error ? err.message : String(_nullishCoalesce(err, () => ( "Unknown Error"))), code);
|
|
300
301
|
}
|
|
301
302
|
break;
|
|
302
303
|
}
|
|
303
304
|
}
|
|
304
|
-
return
|
|
305
|
+
return _chunkINDOGCAQcjs.formatTypings.call(void 0, code, formatOptions);
|
|
305
306
|
}
|
|
306
307
|
|
|
307
308
|
// src/objects.ts
|
|
@@ -427,7 +428,7 @@ var ObjectInstance = class {
|
|
|
427
428
|
this.description = props.description;
|
|
428
429
|
this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
|
|
429
430
|
this.properties = props.properties;
|
|
430
|
-
this.tools =
|
|
431
|
+
this.tools = _chunkSOEKWFU2cjs.Tool.withUniqueNames(_nullishCoalesce(props.tools, () => ( [])));
|
|
431
432
|
}
|
|
432
433
|
/**
|
|
433
434
|
* Generates TypeScript namespace declarations for this object.
|
|
@@ -508,7 +509,7 @@ function getObjectTypings(obj) {
|
|
|
508
509
|
}
|
|
509
510
|
let type = "unknown";
|
|
510
511
|
if (prop.type) {
|
|
511
|
-
type = await
|
|
512
|
+
type = await _chunkINDOGCAQcjs.getTypings.call(void 0, prop.type, {});
|
|
512
513
|
} else if (prop.value !== void 0) {
|
|
513
514
|
type = typeof prop.value;
|
|
514
515
|
}
|
|
@@ -528,7 +529,7 @@ function getObjectTypings(obj) {
|
|
|
528
529
|
typings.push("");
|
|
529
530
|
for (const tool of obj.tools) {
|
|
530
531
|
const fnType = _zui.z.function(tool.zInput, tool.zOutput).title(tool.name).describe(_nullishCoalesce(tool.description, () => ( "")));
|
|
531
|
-
let temp = await
|
|
532
|
+
let temp = await _chunkINDOGCAQcjs.getTypings.call(void 0, fnType, {
|
|
532
533
|
declaration: true
|
|
533
534
|
});
|
|
534
535
|
temp = temp.replace("declare function ", "function ");
|
|
@@ -551,7 +552,7 @@ function getObjectTypings(obj) {
|
|
|
551
552
|
if ((_a = obj.description) == null ? void 0 : _a.trim().length) {
|
|
552
553
|
header = _chunkWHNOR4ZUcjs.getMultilineComment.call(void 0, obj.description);
|
|
553
554
|
}
|
|
554
|
-
return
|
|
555
|
+
return _chunkINDOGCAQcjs.formatTypings.call(void 0,
|
|
555
556
|
`${header}
|
|
556
557
|
export namespace ${obj.name} {
|
|
557
558
|
${body}
|
|
@@ -1103,20 +1104,20 @@ var utils = {
|
|
|
1103
1104
|
truncateWrappedContent: _chunkGZPN7RGHcjs.truncateWrappedContent
|
|
1104
1105
|
};
|
|
1105
1106
|
var execute = async (props) => {
|
|
1106
|
-
const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-
|
|
1107
|
+
const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-HGUVAYIN.cjs")));
|
|
1107
1108
|
return executeContext(props);
|
|
1108
1109
|
};
|
|
1109
1110
|
var init = async () => {
|
|
1110
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-
|
|
1111
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-HGUVAYIN.cjs")));
|
|
1111
1112
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./component-R4WTW6DZ.cjs")));
|
|
1112
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-
|
|
1113
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-JVLOALQN.cjs")));
|
|
1113
1114
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-XAYKJ6TR.cjs")));
|
|
1114
1115
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./jsx-AJAXBWFE.cjs")));
|
|
1115
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-
|
|
1116
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-VFORKC54.cjs")));
|
|
1116
1117
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-L5QAQXV2.cjs")));
|
|
1117
1118
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-W3NXBLYJ.cjs")));
|
|
1118
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-
|
|
1119
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-
|
|
1119
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-OLI56LGT.cjs")));
|
|
1120
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-UBHAMQW4.cjs")));
|
|
1120
1121
|
};
|
|
1121
1122
|
|
|
1122
1123
|
|
|
@@ -1145,4 +1146,5 @@ var init = async () => {
|
|
|
1145
1146
|
|
|
1146
1147
|
|
|
1147
1148
|
|
|
1148
|
-
|
|
1149
|
+
|
|
1150
|
+
exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkZRCU35UVcjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunk4XIOQWVZcjs.DefaultExit; exports.ErrorExecutionResult = _chunk4XIOQWVZcjs.ErrorExecutionResult; exports.ExecutionResult = _chunk4XIOQWVZcjs.ExecutionResult; exports.Exit = _chunk3G3BS5IAcjs.Exit; exports.ListenExit = _chunk4XIOQWVZcjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunk4XIOQWVZcjs.PartialExecutionResult; exports.Snapshot = _chunk4XIOQWVZcjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunk4XIOQWVZcjs.SuccessExecutionResult; exports.ThinkExit = _chunk4XIOQWVZcjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkSOEKWFU2cjs.Tool; exports.assertValidComponent = _chunkZRCU35UVcjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunk4XIOQWVZcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkZRCU35UVcjs.isAnyComponent; exports.isComponent = _chunkZRCU35UVcjs.isComponent; exports.parseExit = _chunk4XIOQWVZcjs.parseExit; exports.renderToTsx = _chunkZRCU35UVcjs.renderToTsx; exports.utils = utils;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { Tool } from './tool.js';
|
|
|
2
2
|
export { Exit, ExitResult } from './exit.js';
|
|
3
3
|
export { ObjectInstance } from './objects.js';
|
|
4
4
|
export { SnapshotSignal, ThinkSignal, LoopExceededError } from './errors.js';
|
|
5
|
+
export { parseExit, type ParsedExit } from './exit-parser.js';
|
|
5
6
|
export { Component, RenderedComponent, LeafComponentDefinition, ContainerComponentDefinition, DefaultComponentDefinition, ComponentDefinition, assertValidComponent, isComponent, isAnyComponent, renderToTsx, } from './component.js';
|
|
6
7
|
export { Citation, CitationsManager } from './citations.js';
|
|
7
8
|
export { DefaultComponents } from './component.default.js';
|
package/dist/index.js
CHANGED
|
@@ -7,22 +7,23 @@ import {
|
|
|
7
7
|
Snapshot,
|
|
8
8
|
SuccessExecutionResult,
|
|
9
9
|
ThinkExit,
|
|
10
|
-
getValue
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
getValue,
|
|
11
|
+
parseExit
|
|
12
|
+
} from "./chunk-4JN4PPGP.js";
|
|
13
|
+
import "./chunk-AAHUDKBY.js";
|
|
13
14
|
import {
|
|
14
15
|
Tool
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-23SY6IDW.js";
|
|
16
17
|
import {
|
|
17
18
|
formatTypings,
|
|
18
19
|
getTypings
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-U4HWJLF2.js";
|
|
20
21
|
import {
|
|
21
22
|
CodeFormattingError,
|
|
22
23
|
LoopExceededError,
|
|
23
24
|
SnapshotSignal,
|
|
24
25
|
ThinkSignal
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-WSVDMGMR.js";
|
|
26
27
|
import "./chunk-YEAWWJSJ.js";
|
|
27
28
|
import {
|
|
28
29
|
Exit
|
|
@@ -1103,20 +1104,20 @@ var utils = {
|
|
|
1103
1104
|
truncateWrappedContent
|
|
1104
1105
|
};
|
|
1105
1106
|
var execute = async (props) => {
|
|
1106
|
-
const { executeContext } = await import("./llmz-
|
|
1107
|
+
const { executeContext } = await import("./llmz-3E2JM3HM.js");
|
|
1107
1108
|
return executeContext(props);
|
|
1108
1109
|
};
|
|
1109
1110
|
var init = async () => {
|
|
1110
|
-
await import("./llmz-
|
|
1111
|
+
await import("./llmz-3E2JM3HM.js");
|
|
1111
1112
|
await import("./component-WFVDVSDK.js");
|
|
1112
|
-
await import("./tool-
|
|
1113
|
+
await import("./tool-7QXH6A24.js");
|
|
1113
1114
|
await import("./exit-YLO7BY7Z.js");
|
|
1114
1115
|
await import("./jsx-AEHVFB3L.js");
|
|
1115
|
-
await import("./vm-
|
|
1116
|
+
await import("./vm-Y3WY2627.js");
|
|
1116
1117
|
await import("./utils-RQHQ2KOG.js");
|
|
1117
1118
|
await import("./truncator-BSP6PQPC.js");
|
|
1118
|
-
await import("./typings-
|
|
1119
|
-
await import("./dual-modes-
|
|
1119
|
+
await import("./typings-ALZEKGV6.js");
|
|
1120
|
+
await import("./dual-modes-LEAHGCOF.js");
|
|
1120
1121
|
};
|
|
1121
1122
|
export {
|
|
1122
1123
|
Chat,
|
|
@@ -1143,6 +1144,7 @@ export {
|
|
|
1143
1144
|
init,
|
|
1144
1145
|
isAnyComponent,
|
|
1145
1146
|
isComponent,
|
|
1147
|
+
parseExit,
|
|
1146
1148
|
renderToTsx,
|
|
1147
1149
|
utils
|
|
1148
1150
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runAsyncFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-G3LSBWJT.js";
|
|
4
4
|
import {
|
|
5
5
|
Context,
|
|
6
6
|
ErrorExecutionResult,
|
|
7
7
|
PartialExecutionResult,
|
|
8
8
|
Snapshot,
|
|
9
|
-
SuccessExecutionResult
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
9
|
+
SuccessExecutionResult,
|
|
10
|
+
parseExit
|
|
11
|
+
} from "./chunk-4JN4PPGP.js";
|
|
12
|
+
import "./chunk-AAHUDKBY.js";
|
|
13
|
+
import "./chunk-23SY6IDW.js";
|
|
14
|
+
import "./chunk-U4HWJLF2.js";
|
|
14
15
|
import {
|
|
15
16
|
AssignmentError,
|
|
16
17
|
CodeExecutionError,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
SnapshotSignal,
|
|
22
23
|
ThinkSignal,
|
|
23
24
|
VMSignal
|
|
24
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-WSVDMGMR.js";
|
|
25
26
|
import {
|
|
26
27
|
cleanStackTrace
|
|
27
28
|
} from "./chunk-YEAWWJSJ.js";
|
|
@@ -103,7 +104,7 @@ var executeContext = async (props) => {
|
|
|
103
104
|
var _executeContext = async (props) => {
|
|
104
105
|
var _a, _b;
|
|
105
106
|
const controller = createJoinedAbortController([props.signal]);
|
|
106
|
-
const { onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
|
|
107
|
+
const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
|
|
107
108
|
const cognitive = Cognitive.isCognitiveClient(props.client) ? props.client : new Cognitive({ client: props.client });
|
|
108
109
|
const cleanups = [];
|
|
109
110
|
const ctx = new Context({
|
|
@@ -124,6 +125,19 @@ var _executeContext = async (props) => {
|
|
|
124
125
|
return new ErrorExecutionResult(ctx, new LoopExceededError());
|
|
125
126
|
}
|
|
126
127
|
const iteration = await ctx.nextIteration();
|
|
128
|
+
try {
|
|
129
|
+
await executeOnIterationStartHook({
|
|
130
|
+
iteration,
|
|
131
|
+
ctx,
|
|
132
|
+
onIterationStart,
|
|
133
|
+
controller,
|
|
134
|
+
onIterationEnd
|
|
135
|
+
});
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (err instanceof ThinkSignal) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
127
141
|
if (controller.signal.aborted) {
|
|
128
142
|
iteration.end({
|
|
129
143
|
type: "aborted",
|
|
@@ -276,7 +290,8 @@ var executeIteration = async ({
|
|
|
276
290
|
tokens: output.meta.tokens.input + output.meta.tokens.output,
|
|
277
291
|
spend: output.meta.cost.input + output.meta.cost.output,
|
|
278
292
|
output: assistantResponse.raw,
|
|
279
|
-
model: `${output.meta.model.integration}:${output.meta.model.model}
|
|
293
|
+
model: `${output.meta.model.integration}:${output.meta.model.model}`,
|
|
294
|
+
usage: output.output.usage
|
|
280
295
|
};
|
|
281
296
|
traces.push({
|
|
282
297
|
type: "llm_call_success",
|
|
@@ -422,7 +437,8 @@ var executeIteration = async ({
|
|
|
422
437
|
type: "thinking_requested",
|
|
423
438
|
thinking_requested: {
|
|
424
439
|
variables: result.signal.context,
|
|
425
|
-
reason: result.signal.reason
|
|
440
|
+
reason: result.signal.reason,
|
|
441
|
+
metadata: result.signal.metadata
|
|
426
442
|
}
|
|
427
443
|
});
|
|
428
444
|
}
|
|
@@ -434,10 +450,8 @@ var executeIteration = async ({
|
|
|
434
450
|
}
|
|
435
451
|
});
|
|
436
452
|
}
|
|
437
|
-
const validActions = [...iteration.exits.map((x) => x.name.toLowerCase()), "think"];
|
|
438
453
|
let returnValue = result.success && result.return_value ? result.return_value : null;
|
|
439
454
|
const returnAction = returnValue == null ? void 0 : returnValue.action;
|
|
440
|
-
const returnExit = iteration.exits.find((x) => x.name.toLowerCase() === (returnAction == null ? void 0 : returnAction.toLowerCase())) ?? iteration.exits.find((x) => x.aliases.some((a) => a.toLowerCase() === (returnAction == null ? void 0 : returnAction.toLowerCase())));
|
|
441
455
|
if (returnAction === "think") {
|
|
442
456
|
const variables = omit_default(returnValue ?? {}, "action");
|
|
443
457
|
if (isPlainObject_default(variables) && Object.keys(variables).length > 0) {
|
|
@@ -457,40 +471,19 @@ var executeIteration = async ({
|
|
|
457
471
|
}
|
|
458
472
|
});
|
|
459
473
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
type: "exit_error",
|
|
463
|
-
exit_error: {
|
|
464
|
-
exit: "n/a",
|
|
465
|
-
message: `Code did not return an action. Valid actions are: ${validActions.join(", ")}`,
|
|
466
|
-
return_value: returnValue
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
if (!returnExit) {
|
|
474
|
+
const parsedExit = parseExit(returnValue, iteration.exits);
|
|
475
|
+
if (!parsedExit.success) {
|
|
471
476
|
return iteration.end({
|
|
472
477
|
type: "exit_error",
|
|
473
478
|
exit_error: {
|
|
474
|
-
exit:
|
|
475
|
-
message:
|
|
479
|
+
exit: (returnValue == null ? void 0 : returnValue.action) ?? "n/a",
|
|
480
|
+
message: parsedExit.error,
|
|
476
481
|
return_value: returnValue
|
|
477
482
|
}
|
|
478
483
|
});
|
|
479
484
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (!parsed.success) {
|
|
483
|
-
return iteration.end({
|
|
484
|
-
type: "exit_error",
|
|
485
|
-
exit_error: {
|
|
486
|
-
exit: returnExit.name,
|
|
487
|
-
message: `Invalid return value for exit ${returnExit.name}: ${getErrorMessage(parsed.error)}`,
|
|
488
|
-
return_value: returnValue
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
returnValue = { action: returnExit.name, value: parsed.data };
|
|
493
|
-
}
|
|
485
|
+
const returnExit = parsedExit.exit;
|
|
486
|
+
returnValue = { action: returnExit.name, value: parsedExit.value };
|
|
494
487
|
try {
|
|
495
488
|
await (onExit == null ? void 0 : onExit({
|
|
496
489
|
exit: returnExit,
|
|
@@ -567,7 +560,9 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
|
|
|
567
560
|
iteration,
|
|
568
561
|
tool,
|
|
569
562
|
input: input2,
|
|
570
|
-
controller
|
|
563
|
+
controller,
|
|
564
|
+
object,
|
|
565
|
+
toolCallId
|
|
571
566
|
}));
|
|
572
567
|
if (typeof (beforeRes == null ? void 0 : beforeRes.input) !== "undefined") {
|
|
573
568
|
input2 = beforeRes.input;
|
|
@@ -580,7 +575,9 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
|
|
|
580
575
|
tool,
|
|
581
576
|
input: input2,
|
|
582
577
|
output: output2,
|
|
583
|
-
controller
|
|
578
|
+
controller,
|
|
579
|
+
object,
|
|
580
|
+
toolCallId
|
|
584
581
|
}));
|
|
585
582
|
if (typeof (afterRes == null ? void 0 : afterRes.output) !== "undefined") {
|
|
586
583
|
output2 = afterRes.output;
|
|
@@ -593,10 +590,23 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
|
|
|
593
590
|
output = res;
|
|
594
591
|
success = true;
|
|
595
592
|
return res;
|
|
596
|
-
}).catch((err) => {
|
|
593
|
+
}).catch(async (err) => {
|
|
597
594
|
if (!handleSignals(err)) {
|
|
598
595
|
success = false;
|
|
599
596
|
error = err;
|
|
597
|
+
} else {
|
|
598
|
+
const afterRes = await (afterHook == null ? void 0 : afterHook({
|
|
599
|
+
iteration,
|
|
600
|
+
tool,
|
|
601
|
+
input,
|
|
602
|
+
output,
|
|
603
|
+
controller,
|
|
604
|
+
object,
|
|
605
|
+
toolCallId
|
|
606
|
+
}));
|
|
607
|
+
if (typeof (afterRes == null ? void 0 : afterRes.output) !== "undefined") {
|
|
608
|
+
output = afterRes.output;
|
|
609
|
+
}
|
|
600
610
|
}
|
|
601
611
|
throw err;
|
|
602
612
|
}).finally(() => {
|
|
@@ -645,6 +655,39 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
|
|
|
645
655
|
return output;
|
|
646
656
|
};
|
|
647
657
|
}
|
|
658
|
+
var executeOnIterationStartHook = async (props) => {
|
|
659
|
+
const { iteration, ctx, onIterationStart, controller, onIterationEnd } = props;
|
|
660
|
+
try {
|
|
661
|
+
const hookRes = await (onIterationStart == null ? void 0 : onIterationStart(iteration, controller, ctx));
|
|
662
|
+
if (hookRes) {
|
|
663
|
+
Object.assign(iteration, hookRes);
|
|
664
|
+
}
|
|
665
|
+
} catch (err) {
|
|
666
|
+
if (err instanceof ThinkSignal) {
|
|
667
|
+
iteration.end({
|
|
668
|
+
type: "thinking_requested",
|
|
669
|
+
thinking_requested: {
|
|
670
|
+
variables: err.context,
|
|
671
|
+
reason: err.reason
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
try {
|
|
675
|
+
await (onIterationEnd == null ? void 0 : onIterationEnd(iteration, controller));
|
|
676
|
+
} catch (err2) {
|
|
677
|
+
console.error(err2);
|
|
678
|
+
}
|
|
679
|
+
} else {
|
|
680
|
+
iteration.end({
|
|
681
|
+
type: "execution_error",
|
|
682
|
+
execution_error: {
|
|
683
|
+
message: `Error in onIterationStart hook: ${getErrorMessage(err)}`,
|
|
684
|
+
stack: cleanStackTrace(err.stack ?? "No stack trace available")
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
throw err;
|
|
689
|
+
}
|
|
690
|
+
};
|
|
648
691
|
export {
|
|
649
692
|
_executeContext,
|
|
650
693
|
executeContext
|