llmz 0.0.2 → 0.0.4
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-RB2L33ZR.js → chunk-4EWY34YA.js} +24 -24
- package/dist/{chunk-UG2GCPHF.js → chunk-4KB5WXHR.js} +3 -2
- package/dist/{chunk-YPOOKE3A.cjs → chunk-4QTK5ALH.cjs} +59 -28
- package/dist/{chunk-BKGPO722.cjs → chunk-5NVNEEYW.cjs} +55 -55
- package/dist/{chunk-DFZ6GX5C.js → chunk-5TRUJES5.js} +1 -1
- package/dist/{chunk-C2TSWGYC.cjs → chunk-6YWYCVAB.cjs} +5 -4
- package/dist/{chunk-7S3UY52U.js → chunk-7WRN4E42.js} +36 -8
- package/dist/{chunk-Q4DEJGXD.js → chunk-EFGXTO64.js} +2 -2
- package/dist/{chunk-VP6WWAE2.cjs → chunk-FIVFS4HG.cjs} +2 -2
- package/dist/{chunk-YUDUY7XW.cjs → chunk-HYVKY3W6.cjs} +23 -24
- package/dist/{chunk-PQN6HW7A.cjs → chunk-IKSIOIIP.cjs} +3 -3
- package/dist/{chunk-ZUAFUOUR.cjs → chunk-JDABP4SD.cjs} +3 -3
- package/dist/{chunk-E5W3P7EO.cjs → chunk-JK2LZW2G.cjs} +20 -2
- package/dist/{chunk-RJHDQL4C.js → chunk-JKVVQN2P.js} +1 -1
- package/dist/{chunk-MSTBEKOQ.js → chunk-JQBT7UWN.js} +3 -3
- package/dist/{chunk-BOLDQGES.cjs → chunk-KMZDFWYZ.cjs} +3 -3
- package/dist/{chunk-R2N2UUKC.cjs → chunk-LVKZYKTP.cjs} +14 -8
- package/dist/{chunk-7FIPXMZR.js → chunk-ORQP26SZ.js} +1 -1
- package/dist/{chunk-ENFB45AI.cjs → chunk-P7J2WCBB.cjs} +7 -7
- package/dist/{chunk-DILHJIMP.js → chunk-QBXIE6EY.js} +49 -18
- package/dist/{chunk-UVSOAH2H.js → chunk-QT4QF3YA.js} +1 -1
- package/dist/{chunk-6QDFMQHA.js → chunk-S6WICIDW.js} +8 -2
- package/dist/{chunk-QPSUMPLP.js → chunk-TJQVC4CE.js} +6 -6
- package/dist/{chunk-ZSRC3TN4.js → chunk-UNMKB2DA.js} +9 -10
- package/dist/{chunk-3CGLDS5T.cjs → chunk-UQOBUJIQ.cjs} +38 -10
- package/dist/{chunk-QZGFCB4T.cjs → chunk-VAF2H6UD.cjs} +22 -22
- package/dist/{chunk-E2B5DRIC.cjs → chunk-W6U2VXSF.cjs} +25 -25
- package/dist/{chunk-3T465BEW.js → chunk-ZCPQ3QOW.js} +19 -1
- package/dist/citations.d.ts +63 -0
- package/dist/component-HQ5YQNRX.cjs +14 -0
- package/dist/component-LQDU72LX.js +14 -0
- package/dist/component.d.ts +32 -10
- package/dist/component.default.d.ts +334 -8
- package/dist/context.d.ts +3 -1
- package/dist/dual-modes-QHBOFWHM.js +13 -0
- package/dist/dual-modes-YE4S2AIL.cjs +13 -0
- package/dist/exit-F6ZUL2NV.js +8 -0
- package/dist/exit-IDKGZD7M.cjs +8 -0
- package/dist/exit.d.ts +2 -0
- package/dist/index.cjs +209 -58
- package/dist/index.d.ts +3 -2
- package/dist/index.js +193 -42
- package/dist/{jsx-CJ2RBODH.js → jsx-AEHVFB3L.js} +2 -3
- package/dist/jsx-AJAXBWFE.cjs +13 -0
- package/dist/{llmz-WY74UVE3.js → llmz-AS5TGCQS.js} +98 -39
- package/dist/{llmz-EGTGPSTX.cjs → llmz-R6XZG3JQ.cjs} +129 -70
- package/dist/llmz.d.ts +3 -2
- package/dist/snapshots.d.ts +9 -1
- package/dist/tool-LY77IWV2.js +11 -0
- package/dist/tool-SWJYOR2Z.cjs +11 -0
- package/dist/tool.d.ts +34 -9
- package/dist/truncator-NYN7BGKJ.cjs +10 -0
- package/dist/truncator-WAL2GCUY.js +10 -0
- package/dist/types.d.ts +7 -1
- package/dist/typings-AIV2OASX.js +10 -0
- package/dist/typings-XR6CYHW4.cjs +10 -0
- package/dist/{utils-TS23YJPE.js → utils-L5GLCS3C.js} +2 -3
- package/dist/utils-QC4I2L6R.cjs +37 -0
- package/dist/vm-GJ5R72AP.cjs +12 -0
- package/dist/vm-ZUQOSRRM.js +12 -0
- package/dist/vm.d.ts +1 -1
- package/package.json +8 -6
- package/dist/chunk-A7BDFLAE.cjs +0 -30
- package/dist/chunk-YSQDPG26.js +0 -30
- package/dist/component-DWBRHLEN.cjs +0 -9
- package/dist/component-R3ZAVXUC.js +0 -9
- package/dist/dual-modes-2VDEOJ5D.js +0 -13
- package/dist/dual-modes-3MH5N6RY.cjs +0 -13
- package/dist/exit-GYMXZZ4I.js +0 -9
- package/dist/exit-PQHMJEOG.cjs +0 -9
- package/dist/jsx-PPLE5YTB.cjs +0 -14
- package/dist/tool-AY47ML65.cjs +0 -12
- package/dist/tool-WVIPESKN.js +0 -12
- package/dist/truncator-MTONQESU.js +0 -11
- package/dist/truncator-ZKPOW2I3.cjs +0 -11
- package/dist/typings-HTYLRNIC.js +0 -11
- package/dist/typings-QRJGGNUM.cjs +0 -11
- package/dist/utils-UR4IMUHC.cjs +0 -38
- package/dist/vm-4JFSZAMR.cjs +0 -13
- package/dist/vm-SMMA664M.js +0 -13
- package/patches/source-map-js@1.2.1.patch +0 -16
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createJsxComponent
|
|
3
|
-
} from "./chunk-7FIPXMZR.js";
|
|
4
1
|
import {
|
|
5
2
|
AssignmentError,
|
|
6
3
|
CodeExecutionError,
|
|
@@ -8,19 +5,20 @@ import {
|
|
|
8
5
|
Signals,
|
|
9
6
|
SnapshotSignal,
|
|
10
7
|
VMSignal
|
|
11
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-JKVVQN2P.js";
|
|
12
9
|
import {
|
|
13
10
|
cleanStackTrace
|
|
14
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-JQBT7UWN.js";
|
|
12
|
+
import {
|
|
13
|
+
createJsxComponent
|
|
14
|
+
} from "./chunk-ORQP26SZ.js";
|
|
15
15
|
import {
|
|
16
|
+
__commonJS,
|
|
17
|
+
__toESM,
|
|
16
18
|
isFunction_default,
|
|
17
19
|
mapValues_default,
|
|
18
20
|
maxBy_default
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import {
|
|
21
|
-
__commonJS,
|
|
22
|
-
__toESM
|
|
23
|
-
} from "./chunk-YSQDPG26.js";
|
|
21
|
+
} from "./chunk-7WRN4E42.js";
|
|
24
22
|
|
|
25
23
|
// ../../node_modules/.pnpm/source-map-js@1.2.1_patch_hash=h25dep36e76b3zca3v6s2554fi/node_modules/source-map-js/lib/base64.js
|
|
26
24
|
var require_base64 = __commonJS({
|
|
@@ -2148,7 +2146,7 @@ var replaceCommentBabelPlugin = function({
|
|
|
2148
2146
|
return;
|
|
2149
2147
|
}
|
|
2150
2148
|
comments.sort((a, b) => a.start > b.start ? -1 : 1).forEach((comment) => {
|
|
2151
|
-
var
|
|
2149
|
+
var _a3;
|
|
2152
2150
|
if (processed.has(comment.loc)) {
|
|
2153
2151
|
return;
|
|
2154
2152
|
}
|
|
@@ -2156,7 +2154,7 @@ var replaceCommentBabelPlugin = function({
|
|
|
2156
2154
|
const commentCall = t.expressionStatement(
|
|
2157
2155
|
t.callExpression(t.identifier(CommentFnIdentifier), [
|
|
2158
2156
|
t.stringLiteral(comment.value.trim()),
|
|
2159
|
-
t.numericLiteral(((
|
|
2157
|
+
t.numericLiteral(((_a3 = comment.loc) == null ? void 0 : _a3.start.line) ?? 0)
|
|
2160
2158
|
])
|
|
2161
2159
|
);
|
|
2162
2160
|
const isInsideObjectProperty = t.isObjectProperty(node) || path2.findParent((path3) => t.isObjectProperty(path3.node));
|
|
@@ -2183,8 +2181,8 @@ var instrumentLastLinePlugin = function({
|
|
|
2183
2181
|
return {
|
|
2184
2182
|
visitor: {
|
|
2185
2183
|
FunctionDeclaration(path) {
|
|
2186
|
-
var
|
|
2187
|
-
if (((
|
|
2184
|
+
var _a3, _b;
|
|
2185
|
+
if (((_a3 = path.node.id) == null ? void 0 : _a3.name) !== "__fn__") {
|
|
2188
2186
|
return;
|
|
2189
2187
|
}
|
|
2190
2188
|
const statements = path.node.body.body;
|
|
@@ -2270,7 +2268,7 @@ var toolCallTrackingPlugin = (calls = /* @__PURE__ */ new Map()) => function({})
|
|
|
2270
2268
|
skip.clear();
|
|
2271
2269
|
},
|
|
2272
2270
|
CallExpression(path) {
|
|
2273
|
-
var
|
|
2271
|
+
var _a3;
|
|
2274
2272
|
if (skip.has(path.node) || path.findParent((p) => skip.has(p.node))) {
|
|
2275
2273
|
return;
|
|
2276
2274
|
}
|
|
@@ -2285,7 +2283,7 @@ var toolCallTrackingPlugin = (calls = /* @__PURE__ */ new Map()) => function({})
|
|
|
2285
2283
|
(p) => p.isAssignmentExpression()
|
|
2286
2284
|
);
|
|
2287
2285
|
if (declaration) {
|
|
2288
|
-
lval = (
|
|
2286
|
+
lval = (_a3 = declaration.get("declarations")[0]) == null ? void 0 : _a3.get("id");
|
|
2289
2287
|
}
|
|
2290
2288
|
if (assignment) {
|
|
2291
2289
|
const left = assignment.get("left");
|
|
@@ -2614,8 +2612,10 @@ function compile(code) {
|
|
|
2614
2612
|
|
|
2615
2613
|
// src/vm.ts
|
|
2616
2614
|
var IS_NODE = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
2617
|
-
var
|
|
2618
|
-
var
|
|
2615
|
+
var _a;
|
|
2616
|
+
var IS_CI = typeof process !== "undefined" && !!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.CI);
|
|
2617
|
+
var _a2;
|
|
2618
|
+
var VM_DRIVER = (typeof process !== "undefined" && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.VM_DRIVER)) ?? (IS_CI ? "node" : "isolated-vm");
|
|
2619
2619
|
var USE_ISOLATED_VM = IS_NODE && VM_DRIVER === "isolated-vm";
|
|
2620
2620
|
var LINE_OFFSET = USE_ISOLATED_VM ? 3 : 1;
|
|
2621
2621
|
var MAX_VM_EXECUTION_TIME = 6e4;
|
|
@@ -2648,7 +2648,7 @@ function getCompiledCode(code, traces = []) {
|
|
|
2648
2648
|
throw new InvalidCodeError(err.message, code);
|
|
2649
2649
|
}
|
|
2650
2650
|
}
|
|
2651
|
-
async function runAsyncFunction(context, code, traces = [], signal = null) {
|
|
2651
|
+
async function runAsyncFunction(context, code, traces = [], signal = null, timeout = MAX_VM_EXECUTION_TIME) {
|
|
2652
2652
|
const transformed = getCompiledCode(code, traces);
|
|
2653
2653
|
const lines_executed = /* @__PURE__ */ new Map();
|
|
2654
2654
|
const variables = {};
|
|
@@ -2692,12 +2692,12 @@ async function runAsyncFunction(context, code, traces = [], signal = null) {
|
|
|
2692
2692
|
};
|
|
2693
2693
|
let currentToolCall;
|
|
2694
2694
|
context[Identifiers.ToolCallTrackerFnIdentifier] = (callId, type, outputOrError) => {
|
|
2695
|
-
var
|
|
2695
|
+
var _a3;
|
|
2696
2696
|
const temp = Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
|
|
2697
2697
|
if (type === "end" && temp instanceof SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
|
|
2698
2698
|
currentToolCall = {
|
|
2699
2699
|
...temp.toolCall,
|
|
2700
|
-
assignment: (
|
|
2700
|
+
assignment: (_a3 = transformed.toolCalls.get(callId)) == null ? void 0 : _a3.assignment
|
|
2701
2701
|
};
|
|
2702
2702
|
}
|
|
2703
2703
|
};
|
|
@@ -2947,7 +2947,7 @@ do {
|
|
|
2947
2947
|
// TODO: fix getRemainingTimeInMillis ...
|
|
2948
2948
|
// TODO: probably expose a "timeout" option instead
|
|
2949
2949
|
// timeout: clamp(Runtime.getRemainingTimeInMillis() - 10_000, 5_000, MAX_VM_EXECUTION_TIME),
|
|
2950
|
-
timeout
|
|
2950
|
+
timeout,
|
|
2951
2951
|
copy: true,
|
|
2952
2952
|
promise: true
|
|
2953
2953
|
}).then((res) => {
|
|
@@ -2990,7 +2990,7 @@ do {
|
|
|
2990
2990
|
return final;
|
|
2991
2991
|
}
|
|
2992
2992
|
var handleError = (err, code, consumer, traces, variables, lines_executed, currentToolCall) => {
|
|
2993
|
-
var
|
|
2993
|
+
var _a3, _b, _c;
|
|
2994
2994
|
err = Signals.maybeDeserializeError(err);
|
|
2995
2995
|
const lines = code.split("\n");
|
|
2996
2996
|
const stackTrace = err.stack || "";
|
|
@@ -3012,7 +3012,7 @@ var handleError = (err, code, consumer, traces, variables, lines_executed, curre
|
|
|
3012
3012
|
column: Math.min(minColumn, Number(x[2]))
|
|
3013
3013
|
};
|
|
3014
3014
|
});
|
|
3015
|
-
const lastLine = ((
|
|
3015
|
+
const lastLine = ((_a3 = maxBy_default(matches, (x) => x.line ?? 0)) == null ? void 0 : _a3.line) ?? 0;
|
|
3016
3016
|
let debugUserCode = "";
|
|
3017
3017
|
let truncatedCode = "";
|
|
3018
3018
|
let truncated = false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
extractType,
|
|
3
3
|
inspect
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-EFGXTO64.js";
|
|
5
5
|
|
|
6
6
|
// src/snapshots.ts
|
|
7
7
|
import { ulid } from "ulid";
|
|
@@ -46,7 +46,8 @@ var Snapshot = class _Snapshot {
|
|
|
46
46
|
reason: this.reason,
|
|
47
47
|
stack: this.stack,
|
|
48
48
|
variables: this.variables,
|
|
49
|
-
toolCall: this.toolCall
|
|
49
|
+
toolCall: this.toolCall,
|
|
50
|
+
status: this.#status
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
static fromJSON(json) {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHYVKY3W6cjs = require('./chunk-HYVKY3W6.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkP7J2WCBBcjs = require('./chunk-P7J2WCBB.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
|
|
13
13
|
|
|
14
14
|
// src/tool.ts
|
|
15
15
|
var _zui = require('@bpinternal/zui');
|
|
@@ -21,6 +21,8 @@ var Tool = (_class = class _Tool {
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
|
|
25
|
+
__init2() {this.MAX_RETRIES = 1e3}
|
|
24
26
|
setStaticInputValues(values) {
|
|
25
27
|
if (values === null || values === void 0) {
|
|
26
28
|
this._staticInputValues = void 0;
|
|
@@ -42,8 +44,8 @@ var Tool = (_class = class _Tool {
|
|
|
42
44
|
}
|
|
43
45
|
get zInput() {
|
|
44
46
|
let input = this.input ? _zui.z.fromJsonSchema(this.input) : _zui.z.any();
|
|
45
|
-
if (!
|
|
46
|
-
const inputExtensions =
|
|
47
|
+
if (!_chunkUQOBUJIQcjs.isEmpty_default.call(void 0, this._staticInputValues)) {
|
|
48
|
+
const inputExtensions = _chunkP7J2WCBBcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
|
|
47
49
|
if (input instanceof _zui.z.ZodObject) {
|
|
48
50
|
input = input.extend(inputExtensions);
|
|
49
51
|
} else if (input instanceof _zui.z.ZodArray) {
|
|
@@ -59,33 +61,37 @@ var Tool = (_class = class _Tool {
|
|
|
59
61
|
}
|
|
60
62
|
rename(name) {
|
|
61
63
|
const before = this.name;
|
|
62
|
-
if (!
|
|
64
|
+
if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, name)) {
|
|
63
65
|
throw new Error(
|
|
64
66
|
`Invalid name for tool ${name}. A tool name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
|
|
65
67
|
);
|
|
66
68
|
}
|
|
67
69
|
this.name = name;
|
|
68
|
-
this.aliases =
|
|
70
|
+
this.aliases = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
69
71
|
return this;
|
|
70
72
|
}
|
|
71
|
-
clone() {
|
|
73
|
+
clone(props = {}) {
|
|
74
|
+
var _a, _b;
|
|
72
75
|
try {
|
|
76
|
+
const zInput = this.input ? _zui.z.fromJsonSchema(this.input) : void 0;
|
|
77
|
+
const zOutput = this.output ? _zui.z.fromJsonSchema(this.output) : void 0;
|
|
73
78
|
return new _Tool({
|
|
74
|
-
name: this.name,
|
|
75
|
-
aliases: [...this.aliases],
|
|
76
|
-
description: this.description,
|
|
77
|
-
metadata: JSON.parse(JSON.stringify(this.metadata)),
|
|
78
|
-
input:
|
|
79
|
-
output:
|
|
80
|
-
handler: this._handler
|
|
81
|
-
|
|
79
|
+
name: _nullishCoalesce(props.name, () => ( this.name)),
|
|
80
|
+
aliases: _nullishCoalesce(props.aliases, () => ( [...this.aliases])),
|
|
81
|
+
description: _nullishCoalesce(props.description, () => ( this.description)),
|
|
82
|
+
metadata: JSON.parse(JSON.stringify(_nullishCoalesce(props.metadata, () => ( this.metadata)))),
|
|
83
|
+
input: typeof props.input === "function" ? (_a = props.input) == null ? void 0 : _a.call(props, zInput) : props.input instanceof _zui.ZodType ? props.input : zInput,
|
|
84
|
+
output: typeof props.output === "function" ? (_b = props.output) == null ? void 0 : _b.call(props, zOutput) : props.output instanceof _zui.ZodType ? props.output : zOutput,
|
|
85
|
+
handler: _nullishCoalesce(props.handler, () => ( this._handler)),
|
|
86
|
+
retry: _nullishCoalesce(props.retry, () => ( this.retry))
|
|
87
|
+
}).setStaticInputValues(_nullishCoalesce(props.staticInputValues, () => ( this._staticInputValues)));
|
|
82
88
|
} catch (e) {
|
|
83
89
|
throw new Error(`Failed to clone tool "${this.name}": ${e}`);
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
constructor(props) {;_class.prototype.__init.call(this);
|
|
88
|
-
if (!
|
|
93
|
+
constructor(props) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
94
|
+
if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, props.name)) {
|
|
89
95
|
throw new Error(
|
|
90
96
|
`Invalid name for tool ${props.name}. A tool name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
|
|
91
97
|
);
|
|
@@ -110,13 +116,13 @@ var Tool = (_class = class _Tool {
|
|
|
110
116
|
`Invalid aliases for tool ${props.name}. Expected an array, but got type "${typeof props.aliases}"`
|
|
111
117
|
);
|
|
112
118
|
}
|
|
113
|
-
if (props.aliases && props.aliases.some((alias) => !
|
|
119
|
+
if (props.aliases && props.aliases.some((alias) => !_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, alias))) {
|
|
114
120
|
throw new Error(`Invalid aliases for tool ${props.name}. Expected an array of valid identifiers.`);
|
|
115
121
|
}
|
|
116
122
|
if (typeof props.input !== "undefined") {
|
|
117
123
|
if (props.input && "toJsonSchema" in props.input && typeof props.input.toJsonSchema === "function") {
|
|
118
124
|
this.input = props.input.toJsonSchema();
|
|
119
|
-
} else if (
|
|
125
|
+
} else if (_chunkP7J2WCBBcjs.isJsonSchema.call(void 0, props.input)) {
|
|
120
126
|
this.input = props.input;
|
|
121
127
|
} else {
|
|
122
128
|
throw new Error(
|
|
@@ -127,7 +133,7 @@ var Tool = (_class = class _Tool {
|
|
|
127
133
|
if (typeof props.output !== "undefined") {
|
|
128
134
|
if (props.output && "toJsonSchema" in props.output && typeof props.output.toJsonSchema === "function") {
|
|
129
135
|
this.output = props.output.toJsonSchema();
|
|
130
|
-
} else if (
|
|
136
|
+
} else if (_chunkP7J2WCBBcjs.isJsonSchema.call(void 0, props.output)) {
|
|
131
137
|
this.output = props.output;
|
|
132
138
|
} else {
|
|
133
139
|
throw new Error(
|
|
@@ -136,26 +142,51 @@ var Tool = (_class = class _Tool {
|
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
this.name = props.name;
|
|
139
|
-
this.aliases =
|
|
145
|
+
this.aliases = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [props.name, ..._nullishCoalesce(props.aliases, () => ( []))]);
|
|
140
146
|
this.description = props.description;
|
|
141
147
|
this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
|
|
142
148
|
this._handler = props.handler;
|
|
143
149
|
this.setStaticInputValues(props.staticInputValues);
|
|
150
|
+
this.retry = props.retry;
|
|
144
151
|
}
|
|
145
|
-
async execute(input) {
|
|
152
|
+
async execute(input, ctx) {
|
|
153
|
+
var _a;
|
|
146
154
|
const pInput = this.zInput.safeParse(input);
|
|
147
155
|
if (!pInput.success) {
|
|
148
156
|
throw new Error(`Tool "${this.name}" received invalid input: ${pInput.error.message}`);
|
|
149
157
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
let attempt = 0;
|
|
159
|
+
while (attempt < this.MAX_RETRIES) {
|
|
160
|
+
try {
|
|
161
|
+
const result = await this._handler(pInput.data, ctx);
|
|
162
|
+
const pOutput = this.zOutput.safeParse(result);
|
|
163
|
+
return pOutput.success ? pOutput.data : result;
|
|
164
|
+
} catch (err) {
|
|
165
|
+
const shouldRetry = await ((_a = this.retry) == null ? void 0 : _a.call(this, {
|
|
166
|
+
input: pInput.data,
|
|
167
|
+
attempt: ++attempt,
|
|
168
|
+
error: err
|
|
169
|
+
}));
|
|
170
|
+
if (!shouldRetry) {
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Tool "${this.name}" failed after ${this.MAX_RETRIES} attempts. Last error: ${JSON.stringify(input)}`
|
|
177
|
+
);
|
|
153
178
|
}
|
|
154
179
|
async getTypings() {
|
|
155
|
-
|
|
180
|
+
let input = this.input ? _zui.z.fromJsonSchema(this.input) : void 0;
|
|
156
181
|
const output = this.output ? _zui.z.fromJsonSchema(this.output) : _zui.z.void();
|
|
182
|
+
if ((input == null ? void 0 : input.naked()) instanceof _zui.ZodObject && typeof this._staticInputValues === "object" && !_chunkUQOBUJIQcjs.isEmpty_default.call(void 0, this._staticInputValues)) {
|
|
183
|
+
const inputExtensions = _chunkP7J2WCBBcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
|
|
184
|
+
input = input.extend(inputExtensions);
|
|
185
|
+
} else if (this._staticInputValues !== void 0) {
|
|
186
|
+
input = _chunkP7J2WCBBcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
|
|
187
|
+
}
|
|
157
188
|
const fnType = _zui.z.function(input, _zui.z.promise(output)).title(this.name).describe(_nullishCoalesce(this.description, () => ( "")));
|
|
158
|
-
return
|
|
189
|
+
return _chunkHYVKY3W6cjs.getTypings.call(void 0, fnType, {
|
|
159
190
|
declaration: true
|
|
160
191
|
});
|
|
161
192
|
}
|