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/README.md
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "llmz",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "LLMz – An LLM-native Typescript VM built on top of Zui",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.7",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"generate": "pnpm build:markdown",
|
|
15
15
|
"build": "tsup && pnpm tsc --emitDeclarationOnly",
|
|
16
|
+
"check:type": "tsc --noEmit",
|
|
16
17
|
"watch": "tsup --watch",
|
|
17
18
|
"test": "vitest run --config vitest.config.ts",
|
|
18
19
|
"test:update": "vitest -u run --config vitest.config.ts",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@types/babel__standalone": "^7.1.9",
|
|
50
51
|
"@types/babel__traverse": "^7.20.6",
|
|
51
52
|
"@types/bytes": "^3.1.5",
|
|
53
|
+
"@types/json-schema": "^7.0.12",
|
|
52
54
|
"@types/lodash-es": "^4.17.12",
|
|
53
55
|
"@types/ms": "^0.7.34",
|
|
54
56
|
"@types/node": "^18.19.67",
|
|
@@ -63,9 +65,9 @@
|
|
|
63
65
|
"tsx": "^4.19.2"
|
|
64
66
|
},
|
|
65
67
|
"peerDependencies": {
|
|
66
|
-
"@botpress/cognitive": "0.1.
|
|
68
|
+
"@botpress/cognitive": "0.1.25",
|
|
67
69
|
"@bpinternal/thicktoken": "^1.0.5",
|
|
68
|
-
"@bpinternal/zui": "^0.
|
|
70
|
+
"@bpinternal/zui": "^1.0.0"
|
|
69
71
|
},
|
|
70
72
|
"dependenciesMeta": {
|
|
71
73
|
"@bpinternal/zui": {
|
package/dist/chat.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Component, RenderedComponent } from './component.js';
|
|
2
|
-
import { Context } from './context.js';
|
|
3
|
-
import { ValueOrGetter } from './getter.js';
|
|
4
|
-
import { ExecutionResult } from './result.js';
|
|
5
|
-
import { TranscriptArray, TranscriptMessage } from './transcript.js';
|
|
6
|
-
export type MessageHandler = (input: RenderedComponent) => Promise<void> | void;
|
|
7
|
-
export declare class Chat {
|
|
8
|
-
readonly handler: MessageHandler;
|
|
9
|
-
readonly transcript: ValueOrGetter<TranscriptArray, Context>;
|
|
10
|
-
readonly components: ValueOrGetter<Component[], Context>;
|
|
11
|
-
constructor(props: {
|
|
12
|
-
handler: MessageHandler;
|
|
13
|
-
components: ValueOrGetter<Component[], Context>;
|
|
14
|
-
transcript?: ValueOrGetter<TranscriptMessage[], Context>;
|
|
15
|
-
});
|
|
16
|
-
onExecutionDone(_result: ExecutionResult): void;
|
|
17
|
-
}
|
package/dist/chunk-4I7UPBLN.cjs
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkP7J2WCBBcjs = require('./chunk-P7J2WCBB.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
|
|
8
|
-
|
|
9
|
-
// src/exit.ts
|
|
10
|
-
var _zui = require('@bpinternal/zui');
|
|
11
|
-
var Exit = (_class = class _Exit {
|
|
12
|
-
|
|
13
|
-
__init() {this.aliases = []}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
get zSchema() {
|
|
18
|
-
return this.schema ? _zui.z.fromJsonSchema(this.schema) : void 0;
|
|
19
|
-
}
|
|
20
|
-
rename(name) {
|
|
21
|
-
const before = this.name;
|
|
22
|
-
if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, name)) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
`Invalid name for exit ${name}. An exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
this.name = name;
|
|
28
|
-
this.aliases = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
clone() {
|
|
32
|
-
return new _Exit({
|
|
33
|
-
name: this.name,
|
|
34
|
-
aliases: [...this.aliases],
|
|
35
|
-
description: this.description,
|
|
36
|
-
metadata: JSON.parse(JSON.stringify(this.metadata)),
|
|
37
|
-
schema: this.zSchema
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
is(exit) {
|
|
41
|
-
return this.name === exit.name;
|
|
42
|
-
}
|
|
43
|
-
match(result) {
|
|
44
|
-
return result.exit instanceof _Exit && this.name === result.exit.name;
|
|
45
|
-
}
|
|
46
|
-
constructor(props) {;_class.prototype.__init.call(this);
|
|
47
|
-
if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, props.name)) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`Invalid name for exit ${props.name}. A exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
if (typeof props.description !== "string" || props.description.trim().length === 0) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Invalid description for exit ${props.name}. Expected a non-empty string, but got type "${typeof props.description}"`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
if (props.metadata !== void 0 && typeof props.metadata !== "object") {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Invalid metadata for exit ${props.name}. Expected an object, but got type "${typeof props.metadata}"`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (props.aliases !== void 0 && !Array.isArray(props.aliases)) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`Invalid aliases for exit ${props.name}. Expected an array, but got type "${typeof props.aliases}"`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
if (props.aliases && props.aliases.some((alias) => !_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, alias))) {
|
|
68
|
-
throw new Error(`Invalid aliases for exit ${props.name}. Expected an array of valid identifiers.`);
|
|
69
|
-
}
|
|
70
|
-
if (typeof props.schema !== "undefined") {
|
|
71
|
-
if (props.schema && "toJsonSchema" in props.schema && typeof props.schema.toJsonSchema === "function") {
|
|
72
|
-
this.schema = props.schema.toJsonSchema();
|
|
73
|
-
} else if (_chunkP7J2WCBBcjs.isJsonSchema.call(void 0, props.schema)) {
|
|
74
|
-
this.schema = props.schema;
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error(
|
|
77
|
-
`Invalid input schema for exit ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.schema}"`
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
this.name = props.name;
|
|
82
|
-
this.aliases = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [props.name, ..._nullishCoalesce(props.aliases, () => ( []))]);
|
|
83
|
-
this.description = props.description;
|
|
84
|
-
this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
|
|
85
|
-
}
|
|
86
|
-
static __initStatic() {this.withUniqueNames = (exits) => {
|
|
87
|
-
const names = /* @__PURE__ */ new Set();
|
|
88
|
-
return exits.map((exit) => {
|
|
89
|
-
if (exits.filter((t) => t.name === exit.name).length === 1) {
|
|
90
|
-
return exit;
|
|
91
|
-
}
|
|
92
|
-
let counter = 1;
|
|
93
|
-
let exitName = exit.name + counter;
|
|
94
|
-
while (names.has(exitName)) {
|
|
95
|
-
exitName = `${exit.name}${++counter}`;
|
|
96
|
-
}
|
|
97
|
-
return exit.rename(exitName);
|
|
98
|
-
});
|
|
99
|
-
}}
|
|
100
|
-
}, _class.__initStatic(), _class);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
exports.Exit = Exit;
|
package/dist/chunk-4QTK5ALH.cjs
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
|
-
|
|
3
|
-
var _chunkHYVKY3W6cjs = require('./chunk-HYVKY3W6.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkP7J2WCBBcjs = require('./chunk-P7J2WCBB.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
|
|
13
|
-
|
|
14
|
-
// src/tool.ts
|
|
15
|
-
var _zui = require('@bpinternal/zui');
|
|
16
|
-
var Tool = (_class = class _Tool {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
__init() {this.aliases = []}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
__init2() {this.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 ? _zui.z.fromJsonSchema(this.input) : _zui.z.any();
|
|
32
|
-
if (input instanceof _zui.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 _zui.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 ? _zui.z.fromJsonSchema(this.input) : _zui.z.any();
|
|
47
|
-
if (!_chunkUQOBUJIQcjs.isEmpty_default.call(void 0, this._staticInputValues)) {
|
|
48
|
-
const inputExtensions = _chunkP7J2WCBBcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
|
|
49
|
-
if (input instanceof _zui.z.ZodObject) {
|
|
50
|
-
input = input.extend(inputExtensions);
|
|
51
|
-
} else if (input instanceof _zui.z.ZodArray) {
|
|
52
|
-
input = _zui.z.array(input.element.extend(inputExtensions));
|
|
53
|
-
} else {
|
|
54
|
-
input = inputExtensions;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return input;
|
|
58
|
-
}
|
|
59
|
-
get zOutput() {
|
|
60
|
-
return this.output ? _zui.z.fromJsonSchema(this.output) : _zui.z.void();
|
|
61
|
-
}
|
|
62
|
-
rename(name) {
|
|
63
|
-
const before = this.name;
|
|
64
|
-
if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, 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 = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [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 ? _zui.z.fromJsonSchema(this.input) : void 0;
|
|
77
|
-
const zOutput = this.output ? _zui.z.fromJsonSchema(this.output) : void 0;
|
|
78
|
-
return new _Tool({
|
|
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)));
|
|
88
|
-
} catch (e) {
|
|
89
|
-
throw new Error(`Failed to clone tool "${this.name}": ${e}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
constructor(props) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
94
|
-
if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, 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) => !_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, 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 (_chunkP7J2WCBBcjs.isJsonSchema.call(void 0, 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 (_chunkP7J2WCBBcjs.isJsonSchema.call(void 0, 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 = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [props.name, ..._nullishCoalesce(props.aliases, () => ( []))]);
|
|
146
|
-
this.description = props.description;
|
|
147
|
-
this.metadata = _nullishCoalesce(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 ? _zui.z.fromJsonSchema(this.input) : void 0;
|
|
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
|
-
}
|
|
188
|
-
const fnType = _zui.z.function(input, _zui.z.promise(output)).title(this.name).describe(_nullishCoalesce(this.description, () => ( "")));
|
|
189
|
-
return _chunkHYVKY3W6cjs.getTypings.call(void 0, fnType, {
|
|
190
|
-
declaration: true
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
static __initStatic() {this.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
|
-
}, _class.__initStatic(), _class);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
exports.Tool = Tool;
|
package/dist/chunk-5TRUJES5.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
camelCase_default,
|
|
3
|
-
deburr_default,
|
|
4
|
-
isPlainObject_default,
|
|
5
|
-
pickBy_default,
|
|
6
|
-
startCase_default
|
|
7
|
-
} from "./chunk-7WRN4E42.js";
|
|
8
|
-
|
|
9
|
-
// src/utils.ts
|
|
10
|
-
import { getWasmTokenizer } from "@bpinternal/thicktoken";
|
|
11
|
-
import { z } from "@bpinternal/zui";
|
|
12
|
-
var tokenizer = null;
|
|
13
|
-
var init = async () => {
|
|
14
|
-
if (tokenizer) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
while (typeof getWasmTokenizer !== "function") {
|
|
18
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
19
|
-
}
|
|
20
|
-
tokenizer = await getWasmTokenizer();
|
|
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 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 = 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 = (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 = deburr_default(str);
|
|
102
|
-
name = name.replace(/[^a-zA-Z0-9_$]/g, "");
|
|
103
|
-
if (!/^[a-zA-Z_$]/.test(name)) {
|
|
104
|
-
name = `_${name}`;
|
|
105
|
-
}
|
|
106
|
-
return camelCase_default(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 (isPlainObject_default(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 = deburr_default(str);
|
|
126
|
-
name = name.split(/[^a-zA-Z0-9_$]/g).map(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 pickBy_default(object, (__, key) => Identifier.safeParse(key).success);
|
|
140
|
-
};
|
|
141
|
-
var convertObjectToZuiLiterals = (obj, nested = false) => {
|
|
142
|
-
if (typeof obj === "string") {
|
|
143
|
-
return z.literal(obj).catch(() => obj);
|
|
144
|
-
}
|
|
145
|
-
if (typeof obj === "number") {
|
|
146
|
-
return z.literal(obj).catch(() => obj);
|
|
147
|
-
}
|
|
148
|
-
if (typeof obj === "boolean") {
|
|
149
|
-
return z.literal(obj).catch(() => obj);
|
|
150
|
-
}
|
|
151
|
-
if (Array.isArray(obj)) {
|
|
152
|
-
if (obj.length === 0) {
|
|
153
|
-
return z.tuple([]).catch(() => obj);
|
|
154
|
-
}
|
|
155
|
-
return 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 z.object(shape).catch(() => shape);
|
|
168
|
-
}
|
|
169
|
-
return shape;
|
|
170
|
-
}
|
|
171
|
-
if (obj === void 0) {
|
|
172
|
-
return z.undefined().catch(() => void 0);
|
|
173
|
-
}
|
|
174
|
-
if (obj === null) {
|
|
175
|
-
return z.null().catch(() => null);
|
|
176
|
-
}
|
|
177
|
-
throw new Error(`Unsupported object type ${typeof obj}, ${obj})`);
|
|
178
|
-
};
|
|
179
|
-
var isValidSchema = (schema) => {
|
|
180
|
-
try {
|
|
181
|
-
z.fromJsonSchema(schema);
|
|
182
|
-
return typeof schema.type === "string";
|
|
183
|
-
} catch {
|
|
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
|
-
export {
|
|
204
|
-
init,
|
|
205
|
-
getTokenizer,
|
|
206
|
-
Tokens,
|
|
207
|
-
Identifier,
|
|
208
|
-
escapeString,
|
|
209
|
-
toPropertyKey,
|
|
210
|
-
getMultilineComment,
|
|
211
|
-
toValidFunctionName,
|
|
212
|
-
awaitObject,
|
|
213
|
-
toValidObjectName,
|
|
214
|
-
stripInvalidIdentifiers,
|
|
215
|
-
convertObjectToZuiLiterals,
|
|
216
|
-
isValidSchema,
|
|
217
|
-
isJsonSchema,
|
|
218
|
-
isValidIdentifier,
|
|
219
|
-
isValidMessageName
|
|
220
|
-
};
|