llmz 0.0.6 → 0.0.7
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 +0 -4
- package/package.json +5 -3
- package/dist/chat.d.ts +0 -17
- package/dist/chunk-4I7UPBLN.cjs +0 -104
- package/dist/chunk-4QTK5ALH.cjs +0 -211
- package/dist/chunk-5TRUJES5.js +0 -220
- package/dist/chunk-6WT5VZBG.cjs +0 -755
- package/dist/chunk-7WRN4E42.js +0 -3087
- package/dist/chunk-BEPRLBPK.cjs +0 -3123
- package/dist/chunk-CH5T6SPC.cjs +0 -694
- package/dist/chunk-D3ESDRLH.js +0 -3123
- package/dist/chunk-EJRCDWBA.cjs +0 -153
- package/dist/chunk-FIVFS4HG.cjs +0 -152
- package/dist/chunk-HP7RKM25.js +0 -153
- package/dist/chunk-HYVKY3W6.cjs +0 -283
- package/dist/chunk-IKSIOIIP.cjs +0 -28
- package/dist/chunk-JDABP4SD.cjs +0 -161
- package/dist/chunk-JKVVQN2P.js +0 -161
- package/dist/chunk-JQBT7UWN.js +0 -28
- package/dist/chunk-KMZDFWYZ.cjs +0 -33
- package/dist/chunk-ORQP26SZ.js +0 -33
- package/dist/chunk-P7J2WCBB.cjs +0 -220
- package/dist/chunk-QBXIE6EY.js +0 -211
- package/dist/chunk-QT4QF3YA.js +0 -152
- package/dist/chunk-S6FOL2HY.js +0 -104
- package/dist/chunk-UNMKB2DA.js +0 -283
- package/dist/chunk-UQOBUJIQ.cjs +0 -3087
- package/dist/chunk-WLUVY5QU.js +0 -755
- package/dist/chunk-XJNRORSK.js +0 -694
- package/dist/citations.d.ts +0 -63
- package/dist/compiler/compiler.d.ts +0 -28
- package/dist/compiler/index.d.ts +0 -2
- package/dist/compiler/plugins/async-iterator.d.ts +0 -4
- package/dist/compiler/plugins/braces-tsx.d.ts +0 -3
- package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +0 -5
- package/dist/compiler/plugins/line-tracking.d.ts +0 -5
- package/dist/compiler/plugins/replace-comment.d.ts +0 -5
- package/dist/compiler/plugins/return-async.d.ts +0 -4
- package/dist/compiler/plugins/track-tool-calls.d.ts +0 -16
- package/dist/compiler/plugins/variable-extraction.d.ts +0 -5
- package/dist/component-R2Y74VUI.js +0 -16
- package/dist/component-TSNW3SC7.cjs +0 -16
- package/dist/component.d.ts +0 -60
- package/dist/component.default.d.ts +0 -316
- package/dist/context.d.ts +0 -177
- package/dist/dual-modes-UHNDHNIF.cjs +0 -12
- package/dist/dual-modes-ZUQKPJFH.js +0 -12
- package/dist/errors.d.ts +0 -64
- package/dist/exit-KJ4COC5N.cjs +0 -8
- package/dist/exit-OIYZLBVJ.js +0 -8
- package/dist/exit.d.ts +0 -26
- package/dist/formatting.d.ts +0 -5
- package/dist/getter.d.ts +0 -2
- package/dist/handlers.d.ts +0 -10
- package/dist/hoist.d.ts +0 -2
- package/dist/index.cjs +0 -919
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -919
- package/dist/inspect.d.ts +0 -6
- package/dist/jsx-AEHVFB3L.js +0 -13
- package/dist/jsx-AJAXBWFE.cjs +0 -13
- package/dist/jsx.d.ts +0 -11
- package/dist/llmz-CPMVYIOJ.cjs +0 -581
- package/dist/llmz-LAN4WDFW.js +0 -581
- package/dist/llmz.d.ts +0 -40
- package/dist/objects.d.ts +0 -24
- package/dist/openai.d.ts +0 -8
- package/dist/prompts/chat-mode/system.md.d.ts +0 -2
- package/dist/prompts/chat-mode/user.md.d.ts +0 -2
- package/dist/prompts/common.d.ts +0 -6
- package/dist/prompts/dual-modes.d.ts +0 -2
- package/dist/prompts/prompt.d.ts +0 -50
- package/dist/prompts/worker-mode/system.md.d.ts +0 -2
- package/dist/prompts/worker-mode/user.md.d.ts +0 -2
- package/dist/result.d.ts +0 -33
- package/dist/snapshots.d.ts +0 -69
- package/dist/stack-traces.d.ts +0 -1
- package/dist/tool-LY77IWV2.js +0 -11
- package/dist/tool-SWJYOR2Z.cjs +0 -11
- package/dist/tool.d.ts +0 -55
- package/dist/transcript.d.ts +0 -9
- package/dist/truncator-NYN7BGKJ.cjs +0 -10
- package/dist/truncator-WAL2GCUY.js +0 -10
- package/dist/truncator.d.ts +0 -21
- package/dist/types.d.ts +0 -105
- package/dist/typings-AIV2OASX.js +0 -10
- package/dist/typings-XR6CYHW4.cjs +0 -10
- package/dist/typings.d.ts +0 -5
- package/dist/utils-L5GLCS3C.js +0 -37
- package/dist/utils-QC4I2L6R.cjs +0 -37
- package/dist/utils.d.ts +0 -21
- package/dist/vm-2DLG7V4G.cjs +0 -12
- package/dist/vm-FLBMZUA2.js +0 -12
- package/dist/vm.d.ts +0 -3
package/dist/chunk-ORQP26SZ.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isPlainObject_default,
|
|
3
|
-
isString_default
|
|
4
|
-
} from "./chunk-7WRN4E42.js";
|
|
5
|
-
|
|
6
|
-
// src/jsx.ts
|
|
7
|
-
import { z } from "@bpinternal/zui";
|
|
8
|
-
function isAnyJsxComponent(component) {
|
|
9
|
-
return typeof component === "object" && component !== null && "__jsx" in component && component.__jsx === true && typeof component.type === "string";
|
|
10
|
-
}
|
|
11
|
-
function isJsxComponent(type, component) {
|
|
12
|
-
return typeof component === "object" && component !== null && "__jsx" in component && component.__jsx === true && typeof component.type === "string" && typeof type === "string" && component.type.toUpperCase().trim() === type.toUpperCase().trim();
|
|
13
|
-
}
|
|
14
|
-
var createJsxComponent = (props) => ({
|
|
15
|
-
__jsx: true,
|
|
16
|
-
type: isString_default(props.type) ? props.type.toUpperCase() : "__unknown__",
|
|
17
|
-
children: Array.isArray(props.children) ? props.children : props.children ? [props.children] : [],
|
|
18
|
-
props: isPlainObject_default(props.props) ? props.props : {}
|
|
19
|
-
});
|
|
20
|
-
var Jsx = z.custom(
|
|
21
|
-
(value) => isAnyJsxComponent(value),
|
|
22
|
-
(value) => ({
|
|
23
|
-
params: { value },
|
|
24
|
-
message: `Invalid JSX component: ${value}`
|
|
25
|
-
})
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
isAnyJsxComponent,
|
|
30
|
-
isJsxComponent,
|
|
31
|
-
createJsxComponent,
|
|
32
|
-
Jsx
|
|
33
|
-
};
|
package/dist/chunk-P7J2WCBB.cjs
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
|
|
8
|
-
|
|
9
|
-
// src/utils.ts
|
|
10
|
-
var _thicktoken = require('@bpinternal/thicktoken');
|
|
11
|
-
var _zui = require('@bpinternal/zui');
|
|
12
|
-
var tokenizer = null;
|
|
13
|
-
var init = async () => {
|
|
14
|
-
if (tokenizer) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
while (typeof _thicktoken.getWasmTokenizer !== "function") {
|
|
18
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
19
|
-
}
|
|
20
|
-
tokenizer = await _thicktoken.getWasmTokenizer.call(void 0, );
|
|
21
|
-
};
|
|
22
|
-
var getTokenizer = () => {
|
|
23
|
-
if (!tokenizer) {
|
|
24
|
-
throw new Error("Tokenizer not initialized, make sure to call init() first and await it");
|
|
25
|
-
}
|
|
26
|
-
return tokenizer;
|
|
27
|
-
};
|
|
28
|
-
var Tokens = (min, max) => {
|
|
29
|
-
return _zui.z.string().superRefine((value, ctx) => {
|
|
30
|
-
const tokens = tokenizer.count(value);
|
|
31
|
-
if (value.length < min) {
|
|
32
|
-
ctx.addIssue({
|
|
33
|
-
code: "too_small",
|
|
34
|
-
minimum: min,
|
|
35
|
-
type: "string",
|
|
36
|
-
message: `Text is ${tokens} but expected at least ${min} tokens`,
|
|
37
|
-
inclusive: true
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (value.length > max) {
|
|
41
|
-
ctx.addIssue({
|
|
42
|
-
code: "too_big",
|
|
43
|
-
maximum: max,
|
|
44
|
-
type: "string",
|
|
45
|
-
message: `Text is ${tokens} tokens but expected at most ${max} tokens`,
|
|
46
|
-
inclusive: true
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return value;
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
var Identifier = _zui.z.string().min(1).max(100).regex(
|
|
53
|
-
/^([a-zA-Z_][a-zA-Z0-9_]*)$/,
|
|
54
|
-
"Identifiers must start with a letter and can only contain letters, numbers and underscores"
|
|
55
|
-
);
|
|
56
|
-
function escapeString(str) {
|
|
57
|
-
if (typeof str !== "string") {
|
|
58
|
-
return "";
|
|
59
|
-
}
|
|
60
|
-
const rawStr = String.raw`${str}`;
|
|
61
|
-
const escapedStr = rawStr.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, '\\"').replace(/'/g, "\\'");
|
|
62
|
-
if (escapedStr.includes("`")) {
|
|
63
|
-
return `"${escapedStr}"`;
|
|
64
|
-
} else if (escapedStr.includes("'")) {
|
|
65
|
-
return `"${escapedStr}"`;
|
|
66
|
-
} else {
|
|
67
|
-
return `'${escapedStr}'`;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
var toPropertyKey = (key) => {
|
|
71
|
-
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {
|
|
72
|
-
return key;
|
|
73
|
-
}
|
|
74
|
-
return escapeString(key);
|
|
75
|
-
};
|
|
76
|
-
var trimEmptyLines = (lines) => {
|
|
77
|
-
var _a;
|
|
78
|
-
while (lines.length && !((_a = lines[0]) == null ? void 0 : _a.trim())) {
|
|
79
|
-
lines.shift();
|
|
80
|
-
}
|
|
81
|
-
while (lines.length && !lines[lines.length - 1].trim()) {
|
|
82
|
-
lines.pop();
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
var getMultilineComment = (description) => {
|
|
86
|
-
description = description == null ? void 0 : description.replace(/(\n(\s*)?){3,}/g, "\n\n");
|
|
87
|
-
const ensureLineStartsWithAsterisk = (line) => line.startsWith("* ") ? ` ${line}` : ` * ${line}`;
|
|
88
|
-
const escapeCommentEnd = (line) => line.replace(/\*\//g, "*\\/");
|
|
89
|
-
const descLines = (_nullishCoalesce(description, () => ( ""))).split("\n").map((line) => line.trim());
|
|
90
|
-
trimEmptyLines(descLines);
|
|
91
|
-
if (descLines.length) {
|
|
92
|
-
descLines[0] = descLines[0].replace(/^\/\*\*?/, "");
|
|
93
|
-
descLines[descLines.length - 1] = descLines[descLines.length - 1].replace(/\*\/$/, "");
|
|
94
|
-
}
|
|
95
|
-
trimEmptyLines(descLines);
|
|
96
|
-
return descLines.length === 0 ? "" : descLines.length === 1 ? `/** ${escapeCommentEnd(descLines[0])} */` : `/**
|
|
97
|
-
${descLines.map(ensureLineStartsWithAsterisk).map(escapeCommentEnd).join("\n")}
|
|
98
|
-
*/`;
|
|
99
|
-
};
|
|
100
|
-
var toValidFunctionName = (str) => {
|
|
101
|
-
let name = _chunkUQOBUJIQcjs.deburr_default.call(void 0, str);
|
|
102
|
-
name = name.replace(/[^a-zA-Z0-9_$]/g, "");
|
|
103
|
-
if (!/^[a-zA-Z_$]/.test(name)) {
|
|
104
|
-
name = `_${name}`;
|
|
105
|
-
}
|
|
106
|
-
return _chunkUQOBUJIQcjs.camelCase_default.call(void 0, name);
|
|
107
|
-
};
|
|
108
|
-
var awaitObject = async (obj) => {
|
|
109
|
-
const newObj = { ...obj };
|
|
110
|
-
const promises = [];
|
|
111
|
-
const setProp = async (key, value) => {
|
|
112
|
-
newObj[key] = await value;
|
|
113
|
-
};
|
|
114
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
115
|
-
if (value instanceof Promise) {
|
|
116
|
-
promises.push(setProp(key, value));
|
|
117
|
-
} else if (_chunkUQOBUJIQcjs.isPlainObject_default.call(void 0, value)) {
|
|
118
|
-
promises.push(setProp(key, await awaitObject(value)));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
await Promise.all(promises);
|
|
122
|
-
return newObj;
|
|
123
|
-
};
|
|
124
|
-
var toValidObjectName = (str) => {
|
|
125
|
-
let name = _chunkUQOBUJIQcjs.deburr_default.call(void 0, str);
|
|
126
|
-
name = name.split(/[^a-zA-Z0-9_$]/g).map(_chunkUQOBUJIQcjs.startCase_default).join("");
|
|
127
|
-
if (!/^[a-zA-Z_$]/.test(name)) {
|
|
128
|
-
name = `_${name}`;
|
|
129
|
-
}
|
|
130
|
-
return name.replaceAll(" ", "");
|
|
131
|
-
};
|
|
132
|
-
var stripInvalidIdentifiers = (object) => {
|
|
133
|
-
if (typeof object !== "object") {
|
|
134
|
-
return object;
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(object)) {
|
|
137
|
-
return object.map(stripInvalidIdentifiers);
|
|
138
|
-
}
|
|
139
|
-
return _chunkUQOBUJIQcjs.pickBy_default.call(void 0, object, (__, key) => Identifier.safeParse(key).success);
|
|
140
|
-
};
|
|
141
|
-
var convertObjectToZuiLiterals = (obj, nested = false) => {
|
|
142
|
-
if (typeof obj === "string") {
|
|
143
|
-
return _zui.z.literal(obj).catch(() => obj);
|
|
144
|
-
}
|
|
145
|
-
if (typeof obj === "number") {
|
|
146
|
-
return _zui.z.literal(obj).catch(() => obj);
|
|
147
|
-
}
|
|
148
|
-
if (typeof obj === "boolean") {
|
|
149
|
-
return _zui.z.literal(obj).catch(() => obj);
|
|
150
|
-
}
|
|
151
|
-
if (Array.isArray(obj)) {
|
|
152
|
-
if (obj.length === 0) {
|
|
153
|
-
return _zui.z.tuple([]).catch(() => obj);
|
|
154
|
-
}
|
|
155
|
-
return _zui.z.tuple([
|
|
156
|
-
// the tuple needs to have at least one element
|
|
157
|
-
convertObjectToZuiLiterals(obj[0]),
|
|
158
|
-
...obj.slice(1).map((child) => convertObjectToZuiLiterals(child))
|
|
159
|
-
]).catch(() => obj);
|
|
160
|
-
}
|
|
161
|
-
if (obj !== null && typeof obj === "object") {
|
|
162
|
-
const shape = {};
|
|
163
|
-
for (const key in obj) {
|
|
164
|
-
shape[key] = convertObjectToZuiLiterals(obj[key], true);
|
|
165
|
-
}
|
|
166
|
-
if (nested) {
|
|
167
|
-
return _zui.z.object(shape).catch(() => shape);
|
|
168
|
-
}
|
|
169
|
-
return shape;
|
|
170
|
-
}
|
|
171
|
-
if (obj === void 0) {
|
|
172
|
-
return _zui.z.undefined().catch(() => void 0);
|
|
173
|
-
}
|
|
174
|
-
if (obj === null) {
|
|
175
|
-
return _zui.z.null().catch(() => null);
|
|
176
|
-
}
|
|
177
|
-
throw new Error(`Unsupported object type ${typeof obj}, ${obj})`);
|
|
178
|
-
};
|
|
179
|
-
var isValidSchema = (schema) => {
|
|
180
|
-
try {
|
|
181
|
-
_zui.z.fromJsonSchema(schema);
|
|
182
|
-
return typeof schema.type === "string";
|
|
183
|
-
} catch (e) {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
function isJsonSchema(schema) {
|
|
188
|
-
return !!schema && typeof schema === "object" && ("$schema" in schema || "type" in schema || "properties" in schema);
|
|
189
|
-
}
|
|
190
|
-
function isValidIdentifier(name) {
|
|
191
|
-
if (typeof name !== "string") {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
return /^[A-Z]{1,}[A-Z0-9_]{0,50}$/i.test(name);
|
|
195
|
-
}
|
|
196
|
-
function isValidMessageName(name) {
|
|
197
|
-
if (typeof name !== "string") {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
return /^[A-Z]{1,50}$/i.test(name);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
exports.init = init; exports.getTokenizer = getTokenizer; exports.Tokens = Tokens; exports.Identifier = Identifier; exports.escapeString = escapeString; exports.toPropertyKey = toPropertyKey; exports.getMultilineComment = getMultilineComment; exports.toValidFunctionName = toValidFunctionName; exports.awaitObject = awaitObject; exports.toValidObjectName = toValidObjectName; exports.stripInvalidIdentifiers = stripInvalidIdentifiers; exports.convertObjectToZuiLiterals = convertObjectToZuiLiterals; exports.isValidSchema = isValidSchema; exports.isJsonSchema = isJsonSchema; exports.isValidIdentifier = isValidIdentifier; exports.isValidMessageName = isValidMessageName;
|
package/dist/chunk-QBXIE6EY.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTypings
|
|
3
|
-
} from "./chunk-UNMKB2DA.js";
|
|
4
|
-
import {
|
|
5
|
-
convertObjectToZuiLiterals,
|
|
6
|
-
isJsonSchema,
|
|
7
|
-
isValidIdentifier
|
|
8
|
-
} from "./chunk-5TRUJES5.js";
|
|
9
|
-
import {
|
|
10
|
-
isEmpty_default,
|
|
11
|
-
uniq_default
|
|
12
|
-
} from "./chunk-7WRN4E42.js";
|
|
13
|
-
|
|
14
|
-
// src/tool.ts
|
|
15
|
-
import { z, ZodObject, ZodType } from "@bpinternal/zui";
|
|
16
|
-
var Tool = class _Tool {
|
|
17
|
-
_staticInputValues;
|
|
18
|
-
name;
|
|
19
|
-
aliases = [];
|
|
20
|
-
description;
|
|
21
|
-
metadata;
|
|
22
|
-
input;
|
|
23
|
-
output;
|
|
24
|
-
retry;
|
|
25
|
-
MAX_RETRIES = 1e3;
|
|
26
|
-
setStaticInputValues(values) {
|
|
27
|
-
if (values === null || values === void 0) {
|
|
28
|
-
this._staticInputValues = void 0;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
const input = this.input ? z.fromJsonSchema(this.input) : z.any();
|
|
32
|
-
if (input instanceof z.ZodObject && typeof values !== "object") {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Invalid static input values for tool ${this.name}. Expected an object, but got type "${typeof values}"`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
if (input instanceof z.ZodArray && !Array.isArray(values)) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Invalid static input values for tool ${this.name}. Expected an array, but got type "${typeof values}"`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
this._staticInputValues = values;
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
get zInput() {
|
|
46
|
-
let input = this.input ? z.fromJsonSchema(this.input) : z.any();
|
|
47
|
-
if (!isEmpty_default(this._staticInputValues)) {
|
|
48
|
-
const inputExtensions = convertObjectToZuiLiterals(this._staticInputValues);
|
|
49
|
-
if (input instanceof z.ZodObject) {
|
|
50
|
-
input = input.extend(inputExtensions);
|
|
51
|
-
} else if (input instanceof z.ZodArray) {
|
|
52
|
-
input = z.array(input.element.extend(inputExtensions));
|
|
53
|
-
} else {
|
|
54
|
-
input = inputExtensions;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return input;
|
|
58
|
-
}
|
|
59
|
-
get zOutput() {
|
|
60
|
-
return this.output ? z.fromJsonSchema(this.output) : z.void();
|
|
61
|
-
}
|
|
62
|
-
rename(name) {
|
|
63
|
-
const before = this.name;
|
|
64
|
-
if (!isValidIdentifier(name)) {
|
|
65
|
-
throw new Error(
|
|
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.`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
this.name = name;
|
|
70
|
-
this.aliases = uniq_default([name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
clone(props = {}) {
|
|
74
|
-
var _a, _b;
|
|
75
|
-
try {
|
|
76
|
-
const zInput = this.input ? z.fromJsonSchema(this.input) : void 0;
|
|
77
|
-
const zOutput = this.output ? z.fromJsonSchema(this.output) : void 0;
|
|
78
|
-
return new _Tool({
|
|
79
|
-
name: props.name ?? this.name,
|
|
80
|
-
aliases: props.aliases ?? [...this.aliases],
|
|
81
|
-
description: props.description ?? this.description,
|
|
82
|
-
metadata: JSON.parse(JSON.stringify(props.metadata ?? this.metadata)),
|
|
83
|
-
input: typeof props.input === "function" ? (_a = props.input) == null ? void 0 : _a.call(props, zInput) : props.input instanceof ZodType ? props.input : zInput,
|
|
84
|
-
output: typeof props.output === "function" ? (_b = props.output) == null ? void 0 : _b.call(props, zOutput) : props.output instanceof ZodType ? props.output : zOutput,
|
|
85
|
-
handler: props.handler ?? this._handler,
|
|
86
|
-
retry: props.retry ?? this.retry
|
|
87
|
-
}).setStaticInputValues(props.staticInputValues ?? this._staticInputValues);
|
|
88
|
-
} catch (e) {
|
|
89
|
-
throw new Error(`Failed to clone tool "${this.name}": ${e}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
_handler;
|
|
93
|
-
constructor(props) {
|
|
94
|
-
if (!isValidIdentifier(props.name)) {
|
|
95
|
-
throw new Error(
|
|
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.`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
if (props.description !== void 0 && typeof props.description !== "string") {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Invalid description for tool ${props.name}. Expected a string, but got type "${typeof props.description}"`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
if (props.metadata !== void 0 && typeof props.metadata !== "object") {
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Invalid metadata for tool ${props.name}. Expected an object, but got type "${typeof props.metadata}"`
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
if (typeof props.handler !== "function") {
|
|
110
|
-
throw new Error(
|
|
111
|
-
`Invalid handler for tool ${props.name}. Expected a function, but got type "${typeof props.handler}"`
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
if (props.aliases !== void 0 && !Array.isArray(props.aliases)) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Invalid aliases for tool ${props.name}. Expected an array, but got type "${typeof props.aliases}"`
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
if (props.aliases && props.aliases.some((alias) => !isValidIdentifier(alias))) {
|
|
120
|
-
throw new Error(`Invalid aliases for tool ${props.name}. Expected an array of valid identifiers.`);
|
|
121
|
-
}
|
|
122
|
-
if (typeof props.input !== "undefined") {
|
|
123
|
-
if (props.input && "toJsonSchema" in props.input && typeof props.input.toJsonSchema === "function") {
|
|
124
|
-
this.input = props.input.toJsonSchema();
|
|
125
|
-
} else if (isJsonSchema(props.input)) {
|
|
126
|
-
this.input = props.input;
|
|
127
|
-
} else {
|
|
128
|
-
throw new Error(
|
|
129
|
-
`Invalid input schema for tool ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.input}"`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (typeof props.output !== "undefined") {
|
|
134
|
-
if (props.output && "toJsonSchema" in props.output && typeof props.output.toJsonSchema === "function") {
|
|
135
|
-
this.output = props.output.toJsonSchema();
|
|
136
|
-
} else if (isJsonSchema(props.output)) {
|
|
137
|
-
this.output = props.output;
|
|
138
|
-
} else {
|
|
139
|
-
throw new Error(
|
|
140
|
-
`Invalid output schema for tool ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.output}"`
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
this.name = props.name;
|
|
145
|
-
this.aliases = uniq_default([props.name, ...props.aliases ?? []]);
|
|
146
|
-
this.description = props.description;
|
|
147
|
-
this.metadata = props.metadata ?? {};
|
|
148
|
-
this._handler = props.handler;
|
|
149
|
-
this.setStaticInputValues(props.staticInputValues);
|
|
150
|
-
this.retry = props.retry;
|
|
151
|
-
}
|
|
152
|
-
async execute(input, ctx) {
|
|
153
|
-
var _a;
|
|
154
|
-
const pInput = this.zInput.safeParse(input);
|
|
155
|
-
if (!pInput.success) {
|
|
156
|
-
throw new Error(`Tool "${this.name}" received invalid input: ${pInput.error.message}`);
|
|
157
|
-
}
|
|
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
|
-
);
|
|
178
|
-
}
|
|
179
|
-
async getTypings() {
|
|
180
|
-
let input = this.input ? z.fromJsonSchema(this.input) : void 0;
|
|
181
|
-
const output = this.output ? z.fromJsonSchema(this.output) : z.void();
|
|
182
|
-
if ((input == null ? void 0 : input.naked()) instanceof ZodObject && typeof this._staticInputValues === "object" && !isEmpty_default(this._staticInputValues)) {
|
|
183
|
-
const inputExtensions = convertObjectToZuiLiterals(this._staticInputValues);
|
|
184
|
-
input = input.extend(inputExtensions);
|
|
185
|
-
} else if (this._staticInputValues !== void 0) {
|
|
186
|
-
input = convertObjectToZuiLiterals(this._staticInputValues);
|
|
187
|
-
}
|
|
188
|
-
const fnType = z.function(input, z.promise(output)).title(this.name).describe(this.description ?? "");
|
|
189
|
-
return getTypings(fnType, {
|
|
190
|
-
declaration: true
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
static withUniqueNames = (tools) => {
|
|
194
|
-
const names = /* @__PURE__ */ new Set();
|
|
195
|
-
return tools.map((tool) => {
|
|
196
|
-
if (tools.filter((t) => t.name === tool.name).length === 1) {
|
|
197
|
-
return tool;
|
|
198
|
-
}
|
|
199
|
-
let counter = 1;
|
|
200
|
-
let toolName = tool.name + counter;
|
|
201
|
-
while (names.has(toolName)) {
|
|
202
|
-
toolName = `${tool.name}${++counter}`;
|
|
203
|
-
}
|
|
204
|
-
return tool.rename(toolName);
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
export {
|
|
210
|
-
Tool
|
|
211
|
-
};
|
package/dist/chunk-QT4QF3YA.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTokenizer
|
|
3
|
-
} from "./chunk-5TRUJES5.js";
|
|
4
|
-
|
|
5
|
-
// src/truncator.ts
|
|
6
|
-
var DEFAULT_REMOVE_CHUNK = 250;
|
|
7
|
-
var WRAP_OPEN_TAG_1 = "\u3010TRUNCATE";
|
|
8
|
-
var WRAP_OPEN_TAG_2 = "\u3011";
|
|
9
|
-
var WRAP_CLOSE_TAG = "\u3010/TRUNCATE\u3011";
|
|
10
|
-
var getRegex = () => new RegExp(`(${WRAP_OPEN_TAG_1}(?:\\s+[\\w:]+)*\\s*${WRAP_OPEN_TAG_2})([\\s\\S]*?)(${WRAP_CLOSE_TAG})`, "g");
|
|
11
|
-
var DEFAULT_TRUNCATE_OPTIONS = {
|
|
12
|
-
preserve: "top",
|
|
13
|
-
flex: 1,
|
|
14
|
-
minTokens: 0
|
|
15
|
-
};
|
|
16
|
-
function wrapContent(content, options) {
|
|
17
|
-
const preserve = (options == null ? void 0 : options.preserve) ?? DEFAULT_TRUNCATE_OPTIONS.preserve;
|
|
18
|
-
const flex = (options == null ? void 0 : options.flex) ?? DEFAULT_TRUNCATE_OPTIONS.flex;
|
|
19
|
-
const minTokens = (options == null ? void 0 : options.minTokens) ?? DEFAULT_TRUNCATE_OPTIONS.minTokens;
|
|
20
|
-
return `${WRAP_OPEN_TAG_1} preserve:${preserve} flex:${flex} min:${minTokens} ${WRAP_OPEN_TAG_2}${content}${WRAP_CLOSE_TAG}`;
|
|
21
|
-
}
|
|
22
|
-
function truncateWrappedContent({
|
|
23
|
-
messages,
|
|
24
|
-
tokenLimit,
|
|
25
|
-
throwOnFailure = true
|
|
26
|
-
}) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
const tokenizer = getTokenizer();
|
|
29
|
-
const parts = [];
|
|
30
|
-
for (const msg of messages) {
|
|
31
|
-
const current = [];
|
|
32
|
-
const content = msg.content;
|
|
33
|
-
let match;
|
|
34
|
-
const regex = getRegex();
|
|
35
|
-
let lastIndex = 0;
|
|
36
|
-
while ((match = regex.exec(content)) !== null) {
|
|
37
|
-
const attributes = match[1].split(/\s+/).slice(1).filter((x) => x !== WRAP_OPEN_TAG_2).map((x) => x.split(":")).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
38
|
-
if (match.index > lastIndex) {
|
|
39
|
-
const nonTruncatableContent = content.slice(lastIndex, match.index);
|
|
40
|
-
current.push({
|
|
41
|
-
content: nonTruncatableContent,
|
|
42
|
-
tokens: tokenizer.count(nonTruncatableContent),
|
|
43
|
-
truncatable: false
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const wrappedContent = match[2];
|
|
47
|
-
current.push({
|
|
48
|
-
content: wrappedContent,
|
|
49
|
-
tokens: tokenizer.count(wrappedContent),
|
|
50
|
-
truncatable: true,
|
|
51
|
-
attributes: {
|
|
52
|
-
preserve: attributes.preserve,
|
|
53
|
-
flex: Number(attributes.flex) || DEFAULT_TRUNCATE_OPTIONS.flex,
|
|
54
|
-
minTokens: Number(attributes.min) || DEFAULT_TRUNCATE_OPTIONS.minTokens
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
lastIndex = regex.lastIndex;
|
|
58
|
-
}
|
|
59
|
-
if (lastIndex < content.length) {
|
|
60
|
-
const remainingContent = content.slice(lastIndex);
|
|
61
|
-
current.push({
|
|
62
|
-
content: remainingContent,
|
|
63
|
-
tokens: tokenizer.count(remainingContent),
|
|
64
|
-
truncatable: false
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
parts.push(current);
|
|
68
|
-
}
|
|
69
|
-
const getCount = () => parts.reduce((acc, x) => acc + x.reduce((acc2, y) => acc2 + y.tokens, 0), 0);
|
|
70
|
-
const getTwoBiggestTruncatables = () => {
|
|
71
|
-
var _a2, _b2;
|
|
72
|
-
let biggest = null;
|
|
73
|
-
let secondBiggest = null;
|
|
74
|
-
for (const part of parts.flat()) {
|
|
75
|
-
if (part.truncatable) {
|
|
76
|
-
const flex = ((_a2 = part.attributes) == null ? void 0 : _a2.flex) ?? DEFAULT_TRUNCATE_OPTIONS.flex;
|
|
77
|
-
const tokens = part.tokens * flex;
|
|
78
|
-
if (part.tokens <= (((_b2 = part.attributes) == null ? void 0 : _b2.minTokens) ?? 0)) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if (!biggest || tokens > biggest.tokens) {
|
|
82
|
-
secondBiggest = biggest;
|
|
83
|
-
biggest = part;
|
|
84
|
-
} else if (!secondBiggest || tokens > secondBiggest.tokens) {
|
|
85
|
-
secondBiggest = part;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return { biggest, secondBiggest };
|
|
90
|
-
};
|
|
91
|
-
let currentCount = getCount();
|
|
92
|
-
while (currentCount > tokenLimit) {
|
|
93
|
-
const { biggest, secondBiggest } = getTwoBiggestTruncatables();
|
|
94
|
-
if (!biggest || !biggest.truncatable || biggest.tokens <= 0) {
|
|
95
|
-
if (throwOnFailure) {
|
|
96
|
-
throw new Error(`Cannot truncate further, current count: ${getCount()}`);
|
|
97
|
-
} else {
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const delta = Math.max(biggest.tokens - ((secondBiggest == null ? void 0 : secondBiggest.tokens) ?? 0), DEFAULT_REMOVE_CHUNK);
|
|
102
|
-
const room = Math.min(delta, biggest.tokens);
|
|
103
|
-
let toRemove = Math.min(room, currentCount - tokenLimit);
|
|
104
|
-
if (toRemove <= 0) {
|
|
105
|
-
if (throwOnFailure) {
|
|
106
|
-
throw new Error(`Cannot truncate further, current count: ${getCount()}`);
|
|
107
|
-
} else {
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (biggest.tokens - toRemove < (((_a = biggest.attributes) == null ? void 0 : _a.minTokens) ?? 0)) {
|
|
112
|
-
toRemove = biggest.tokens - (((_b = biggest.attributes) == null ? void 0 : _b.minTokens) ?? 0);
|
|
113
|
-
}
|
|
114
|
-
const preserve = ((_c = biggest.attributes) == null ? void 0 : _c.preserve) ?? DEFAULT_TRUNCATE_OPTIONS.preserve;
|
|
115
|
-
const split = tokenizer.split(biggest.content);
|
|
116
|
-
if (preserve === "bottom") {
|
|
117
|
-
biggest.content = split.slice(toRemove).join("");
|
|
118
|
-
} else if (preserve === "top") {
|
|
119
|
-
biggest.content = split.slice(0, -toRemove).join("");
|
|
120
|
-
} else {
|
|
121
|
-
const anchor = Math.ceil(split.length / 2);
|
|
122
|
-
const radius = Math.ceil(toRemove / 2);
|
|
123
|
-
const left = anchor - radius;
|
|
124
|
-
const right = anchor + radius;
|
|
125
|
-
biggest.content = split.slice(0, left).join("") + split.slice(right).join("");
|
|
126
|
-
}
|
|
127
|
-
biggest.tokens -= toRemove;
|
|
128
|
-
currentCount -= toRemove;
|
|
129
|
-
}
|
|
130
|
-
const removeRedundantWrappers = (content) => {
|
|
131
|
-
return content.replace(getRegex(), "$2");
|
|
132
|
-
};
|
|
133
|
-
return messages.map((msg, i) => {
|
|
134
|
-
const p = parts[i];
|
|
135
|
-
return {
|
|
136
|
-
...msg,
|
|
137
|
-
content: removeRedundantWrappers(
|
|
138
|
-
p.map((part) => {
|
|
139
|
-
if (part.truncatable) {
|
|
140
|
-
return part.content;
|
|
141
|
-
}
|
|
142
|
-
return part.content;
|
|
143
|
-
}).join("")
|
|
144
|
-
)
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export {
|
|
150
|
-
wrapContent,
|
|
151
|
-
truncateWrappedContent
|
|
152
|
-
};
|