llmz 0.0.2
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 +41 -0
- package/dist/chunk-3CGLDS5T.cjs +3059 -0
- package/dist/chunk-3T465BEW.js +96 -0
- package/dist/chunk-6QDFMQHA.js +98 -0
- package/dist/chunk-7FIPXMZR.js +33 -0
- package/dist/chunk-7S3UY52U.js +3059 -0
- package/dist/chunk-A7BDFLAE.cjs +30 -0
- package/dist/chunk-BKGPO722.cjs +3079 -0
- package/dist/chunk-BOLDQGES.cjs +33 -0
- package/dist/chunk-C2TSWGYC.cjs +91 -0
- package/dist/chunk-DFZ6GX5C.js +220 -0
- package/dist/chunk-DILHJIMP.js +180 -0
- package/dist/chunk-E2B5DRIC.cjs +419 -0
- package/dist/chunk-E5W3P7EO.cjs +96 -0
- package/dist/chunk-ENFB45AI.cjs +220 -0
- package/dist/chunk-MSTBEKOQ.js +28 -0
- package/dist/chunk-PQN6HW7A.cjs +28 -0
- package/dist/chunk-Q4DEJGXD.js +344 -0
- package/dist/chunk-QPSUMPLP.js +419 -0
- package/dist/chunk-QZGFCB4T.cjs +344 -0
- package/dist/chunk-R2N2UUKC.cjs +98 -0
- package/dist/chunk-RB2L33ZR.js +3079 -0
- package/dist/chunk-RJHDQL4C.js +161 -0
- package/dist/chunk-UG2GCPHF.js +91 -0
- package/dist/chunk-UVSOAH2H.js +152 -0
- package/dist/chunk-VP6WWAE2.cjs +152 -0
- package/dist/chunk-YPOOKE3A.cjs +180 -0
- package/dist/chunk-YSQDPG26.js +30 -0
- package/dist/chunk-YUDUY7XW.cjs +284 -0
- package/dist/chunk-ZSRC3TN4.js +284 -0
- package/dist/chunk-ZUAFUOUR.cjs +161 -0
- package/dist/compiler/compiler.d.ts +28 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/plugins/async-iterator.d.ts +4 -0
- package/dist/compiler/plugins/braces-tsx.d.ts +3 -0
- package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +5 -0
- package/dist/compiler/plugins/line-tracking.d.ts +5 -0
- package/dist/compiler/plugins/replace-comment.d.ts +5 -0
- package/dist/compiler/plugins/return-async.d.ts +4 -0
- package/dist/compiler/plugins/track-tool-calls.d.ts +16 -0
- package/dist/compiler/plugins/variable-extraction.d.ts +5 -0
- package/dist/component-DWBRHLEN.cjs +9 -0
- package/dist/component-R3ZAVXUC.js +9 -0
- package/dist/component.d.ts +51 -0
- package/dist/component.default.d.ts +10 -0
- package/dist/context.d.ts +167 -0
- package/dist/dual-modes-2VDEOJ5D.js +13 -0
- package/dist/dual-modes-3MH5N6RY.cjs +13 -0
- package/dist/errors.d.ts +64 -0
- package/dist/exit-GYMXZZ4I.js +9 -0
- package/dist/exit-PQHMJEOG.cjs +9 -0
- package/dist/exit.d.ts +20 -0
- package/dist/formatting.d.ts +5 -0
- package/dist/getter.d.ts +2 -0
- package/dist/handlers.d.ts +10 -0
- package/dist/hoist.d.ts +2 -0
- package/dist/index.cjs +811 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +811 -0
- package/dist/inspect.d.ts +6 -0
- package/dist/jsx-CJ2RBODH.js +14 -0
- package/dist/jsx-PPLE5YTB.cjs +14 -0
- package/dist/jsx.d.ts +11 -0
- package/dist/llmz-EGTGPSTX.cjs +1049 -0
- package/dist/llmz-WY74UVE3.js +1049 -0
- package/dist/llmz.d.ts +41 -0
- package/dist/objects.d.ts +24 -0
- package/dist/openai.d.ts +8 -0
- package/dist/prompts/chat-mode/system.md.d.ts +2 -0
- package/dist/prompts/chat-mode/user.md.d.ts +2 -0
- package/dist/prompts/common.d.ts +6 -0
- package/dist/prompts/dual-modes.d.ts +2 -0
- package/dist/prompts/prompt.d.ts +50 -0
- package/dist/prompts/worker-mode/system.md.d.ts +2 -0
- package/dist/prompts/worker-mode/user.md.d.ts +2 -0
- package/dist/snapshots.d.ts +61 -0
- package/dist/stack-traces.d.ts +1 -0
- package/dist/tool-AY47ML65.cjs +12 -0
- package/dist/tool-WVIPESKN.js +12 -0
- package/dist/tool.d.ts +30 -0
- package/dist/transcript.d.ts +9 -0
- package/dist/truncator-MTONQESU.js +11 -0
- package/dist/truncator-ZKPOW2I3.cjs +11 -0
- package/dist/truncator.d.ts +21 -0
- package/dist/types.d.ts +131 -0
- package/dist/typings-HTYLRNIC.js +11 -0
- package/dist/typings-QRJGGNUM.cjs +11 -0
- package/dist/typings.d.ts +5 -0
- package/dist/utils-TS23YJPE.js +38 -0
- package/dist/utils-UR4IMUHC.cjs +38 -0
- package/dist/utils.d.ts +21 -0
- package/dist/vm-4JFSZAMR.cjs +13 -0
- package/dist/vm-SMMA664M.js +13 -0
- package/dist/vm.d.ts +3 -0
- package/package.json +85 -0
- package/patches/source-map-js@1.2.1.patch +16 -0
|
@@ -0,0 +1,180 @@
|
|
|
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 _chunkYUDUY7XWcjs = require('./chunk-YUDUY7XW.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkENFB45AIcjs = require('./chunk-ENFB45AI.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunk3CGLDS5Tcjs = require('./chunk-3CGLDS5T.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
|
+
setStaticInputValues(values) {
|
|
25
|
+
if (values === null || values === void 0) {
|
|
26
|
+
this._staticInputValues = void 0;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
const input = this.input ? _zui.z.fromJsonSchema(this.input) : _zui.z.any();
|
|
30
|
+
if (input instanceof _zui.z.ZodObject && typeof values !== "object") {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Invalid static input values for tool ${this.name}. Expected an object, but got type "${typeof values}"`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (input instanceof _zui.z.ZodArray && !Array.isArray(values)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Invalid static input values for tool ${this.name}. Expected an array, but got type "${typeof values}"`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
this._staticInputValues = values;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
get zInput() {
|
|
44
|
+
let input = this.input ? _zui.z.fromJsonSchema(this.input) : _zui.z.any();
|
|
45
|
+
if (!_chunk3CGLDS5Tcjs.isEmpty_default.call(void 0, this._staticInputValues)) {
|
|
46
|
+
const inputExtensions = _chunkENFB45AIcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
|
|
47
|
+
if (input instanceof _zui.z.ZodObject) {
|
|
48
|
+
input = input.extend(inputExtensions);
|
|
49
|
+
} else if (input instanceof _zui.z.ZodArray) {
|
|
50
|
+
input = _zui.z.array(input.element.extend(inputExtensions));
|
|
51
|
+
} else {
|
|
52
|
+
input = inputExtensions;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return input;
|
|
56
|
+
}
|
|
57
|
+
get zOutput() {
|
|
58
|
+
return this.output ? _zui.z.fromJsonSchema(this.output) : _zui.z.void();
|
|
59
|
+
}
|
|
60
|
+
rename(name) {
|
|
61
|
+
const before = this.name;
|
|
62
|
+
if (!_chunkENFB45AIcjs.isValidIdentifier.call(void 0, name)) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`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
|
+
);
|
|
66
|
+
}
|
|
67
|
+
this.name = name;
|
|
68
|
+
this.aliases = _chunk3CGLDS5Tcjs.uniq_default.call(void 0, [name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
clone() {
|
|
72
|
+
try {
|
|
73
|
+
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: this.input ? _zui.z.fromJsonSchema(this.input) : void 0,
|
|
79
|
+
output: this.output ? _zui.z.fromJsonSchema(this.output) : void 0,
|
|
80
|
+
handler: this._handler
|
|
81
|
+
}).setStaticInputValues(this._staticInputValues);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw new Error(`Failed to clone tool "${this.name}": ${e}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
constructor(props) {;_class.prototype.__init.call(this);
|
|
88
|
+
if (!_chunkENFB45AIcjs.isValidIdentifier.call(void 0, props.name)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`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
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (props.description !== void 0 && typeof props.description !== "string") {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Invalid description for tool ${props.name}. Expected a string, but got type "${typeof props.description}"`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (props.metadata !== void 0 && typeof props.metadata !== "object") {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Invalid metadata for tool ${props.name}. Expected an object, but got type "${typeof props.metadata}"`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (typeof props.handler !== "function") {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Invalid handler for tool ${props.name}. Expected a function, but got type "${typeof props.handler}"`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (props.aliases !== void 0 && !Array.isArray(props.aliases)) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Invalid aliases for tool ${props.name}. Expected an array, but got type "${typeof props.aliases}"`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (props.aliases && props.aliases.some((alias) => !_chunkENFB45AIcjs.isValidIdentifier.call(void 0, alias))) {
|
|
114
|
+
throw new Error(`Invalid aliases for tool ${props.name}. Expected an array of valid identifiers.`);
|
|
115
|
+
}
|
|
116
|
+
if (typeof props.input !== "undefined") {
|
|
117
|
+
if (props.input && "toJsonSchema" in props.input && typeof props.input.toJsonSchema === "function") {
|
|
118
|
+
this.input = props.input.toJsonSchema();
|
|
119
|
+
} else if (_chunkENFB45AIcjs.isJsonSchema.call(void 0, props.input)) {
|
|
120
|
+
this.input = props.input;
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Invalid input schema for tool ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.input}"`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (typeof props.output !== "undefined") {
|
|
128
|
+
if (props.output && "toJsonSchema" in props.output && typeof props.output.toJsonSchema === "function") {
|
|
129
|
+
this.output = props.output.toJsonSchema();
|
|
130
|
+
} else if (_chunkENFB45AIcjs.isJsonSchema.call(void 0, props.output)) {
|
|
131
|
+
this.output = props.output;
|
|
132
|
+
} else {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Invalid output schema for tool ${props.name}. Expected a ZodType or JSONSchema, but got type "${typeof props.output}"`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.name = props.name;
|
|
139
|
+
this.aliases = _chunk3CGLDS5Tcjs.uniq_default.call(void 0, [props.name, ..._nullishCoalesce(props.aliases, () => ( []))]);
|
|
140
|
+
this.description = props.description;
|
|
141
|
+
this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
|
|
142
|
+
this._handler = props.handler;
|
|
143
|
+
this.setStaticInputValues(props.staticInputValues);
|
|
144
|
+
}
|
|
145
|
+
async execute(input) {
|
|
146
|
+
const pInput = this.zInput.safeParse(input);
|
|
147
|
+
if (!pInput.success) {
|
|
148
|
+
throw new Error(`Tool "${this.name}" received invalid input: ${pInput.error.message}`);
|
|
149
|
+
}
|
|
150
|
+
const result = await this._handler(pInput.data);
|
|
151
|
+
const pOutput = this.zOutput.safeParse(result);
|
|
152
|
+
return pOutput.success ? pOutput.data : result;
|
|
153
|
+
}
|
|
154
|
+
async getTypings() {
|
|
155
|
+
const input = this.input ? _zui.z.fromJsonSchema(this.input) : void 0;
|
|
156
|
+
const output = this.output ? _zui.z.fromJsonSchema(this.output) : _zui.z.void();
|
|
157
|
+
const fnType = _zui.z.function(input, _zui.z.promise(output)).title(this.name).describe(_nullishCoalesce(this.description, () => ( "")));
|
|
158
|
+
return _chunkYUDUY7XWcjs.getTypings.call(void 0, fnType, {
|
|
159
|
+
declaration: true
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
static __initStatic() {this.withUniqueNames = (tools) => {
|
|
163
|
+
const names = /* @__PURE__ */ new Set();
|
|
164
|
+
return tools.map((tool) => {
|
|
165
|
+
if (tools.filter((t) => t.name === tool.name).length === 1) {
|
|
166
|
+
return tool;
|
|
167
|
+
}
|
|
168
|
+
let counter = 1;
|
|
169
|
+
let toolName = tool.name + counter;
|
|
170
|
+
while (names.has(toolName)) {
|
|
171
|
+
toolName = `${tool.name}${++counter}`;
|
|
172
|
+
}
|
|
173
|
+
return tool.rename(toolName);
|
|
174
|
+
});
|
|
175
|
+
}}
|
|
176
|
+
}, _class.__initStatic(), _class);
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
exports.Tool = Tool;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
__commonJS,
|
|
29
|
+
__toESM
|
|
30
|
+
};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkZUAFUOURcjs = require('./chunk-ZUAFUOUR.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkENFB45AIcjs = require('./chunk-ENFB45AI.cjs');
|
|
9
|
+
|
|
10
|
+
// src/typings.ts
|
|
11
|
+
var _zui = require('@bpinternal/zui');
|
|
12
|
+
|
|
13
|
+
// src/formatting.ts
|
|
14
|
+
var _lrucache = require('lru-cache');
|
|
15
|
+
var _babel = require('prettier/plugins/babel'); var _babel2 = _interopRequireDefault(_babel);
|
|
16
|
+
var _estree = require('prettier/plugins/estree'); var _estree2 = _interopRequireDefault(_estree);
|
|
17
|
+
var _typescript = require('prettier/plugins/typescript'); var _typescript2 = _interopRequireDefault(_typescript);
|
|
18
|
+
var _standalone = require('prettier/standalone');
|
|
19
|
+
var cache = new (0, _lrucache.LRUCache)({ max: 1e3 });
|
|
20
|
+
async function formatTypings(typings, options) {
|
|
21
|
+
if (cache.has(typings)) {
|
|
22
|
+
return cache.get(typings);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
options ??= {};
|
|
26
|
+
options.throwOnError ??= true;
|
|
27
|
+
const result = (await _standalone.format.call(void 0, typings, {
|
|
28
|
+
singleAttributePerLine: true,
|
|
29
|
+
bracketSameLine: true,
|
|
30
|
+
semi: false,
|
|
31
|
+
...options,
|
|
32
|
+
embeddedLanguageFormatting: "off",
|
|
33
|
+
plugins: [_estree2.default, _babel2.default, _typescript2.default],
|
|
34
|
+
parser: "typescript",
|
|
35
|
+
filepath: "tools.d.ts"
|
|
36
|
+
})).trim();
|
|
37
|
+
cache.set(typings, result);
|
|
38
|
+
return result;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (options == null ? void 0 : options.throwOnError) {
|
|
41
|
+
throw new (0, _chunkZUAFUOURcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
|
|
42
|
+
}
|
|
43
|
+
return typings;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/typings.ts
|
|
48
|
+
var Primitives = [
|
|
49
|
+
"string",
|
|
50
|
+
"number",
|
|
51
|
+
"boolean",
|
|
52
|
+
"unknown",
|
|
53
|
+
"void",
|
|
54
|
+
"any",
|
|
55
|
+
"null",
|
|
56
|
+
"undefined",
|
|
57
|
+
"never",
|
|
58
|
+
"bigint",
|
|
59
|
+
"symbol",
|
|
60
|
+
"object"
|
|
61
|
+
];
|
|
62
|
+
var LARGE_DECLARATION_LINES = 5;
|
|
63
|
+
var isPrimitive = (type) => Primitives.includes(type);
|
|
64
|
+
var isArrayOfPrimitives = (type) => Primitives.map((p) => `${p}[]`).includes(type);
|
|
65
|
+
var stripSpaces = (typings) => typings.replace(/ +/g, " ").trim();
|
|
66
|
+
var KeyValue = class {
|
|
67
|
+
constructor(key, value) {
|
|
68
|
+
this.key = key;
|
|
69
|
+
this.value = value;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var FnParameters = class {
|
|
73
|
+
constructor(schema) {
|
|
74
|
+
this.schema = schema;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var FnReturn = class {
|
|
78
|
+
constructor(schema) {
|
|
79
|
+
this.schema = schema;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var Declaration = class {
|
|
83
|
+
constructor(schema, identifier) {
|
|
84
|
+
this.schema = schema;
|
|
85
|
+
this.identifier = identifier;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
async function getTypings(schema, options) {
|
|
89
|
+
options ??= {};
|
|
90
|
+
options.declaration ??= false;
|
|
91
|
+
let wrappedSchema = schema;
|
|
92
|
+
if (options == null ? void 0 : options.declaration) {
|
|
93
|
+
if (schema instanceof _zui.z.Schema) {
|
|
94
|
+
const title = "title" in schema.ui ? schema.ui.title : null;
|
|
95
|
+
if (!title) {
|
|
96
|
+
throw new Error('Only schemas with "title" Zui property can be declared.');
|
|
97
|
+
}
|
|
98
|
+
wrappedSchema = new Declaration(schema, title);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let dts = await sUnwrapZodRecursive(wrappedSchema, { ...options });
|
|
102
|
+
dts = await formatTypings(dts, { throwOnError: false });
|
|
103
|
+
return dts;
|
|
104
|
+
}
|
|
105
|
+
async function sUnwrapZodRecursive(schema, options) {
|
|
106
|
+
return sUnwrapZod(schema, options);
|
|
107
|
+
}
|
|
108
|
+
async function sUnwrapZod(schema, options) {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
const newOptions = {
|
|
111
|
+
...options,
|
|
112
|
+
declaration: false,
|
|
113
|
+
parent: schema
|
|
114
|
+
};
|
|
115
|
+
if (schema instanceof Declaration) {
|
|
116
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema.schema.description);
|
|
117
|
+
const withoutDesc = schema.schema.describe("");
|
|
118
|
+
const typings = await sUnwrapZodRecursive(withoutDesc, { ...newOptions, declaration: true });
|
|
119
|
+
const isLargeDeclaration = typings.split("\n").length >= LARGE_DECLARATION_LINES;
|
|
120
|
+
const closingTag = isLargeDeclaration ? `// end of ${schema.identifier}` : "";
|
|
121
|
+
if (schema.schema instanceof _zui.z.ZodFunction) {
|
|
122
|
+
return stripSpaces(`${description}
|
|
123
|
+
declare function ${schema.identifier}${typings};${closingTag}`);
|
|
124
|
+
}
|
|
125
|
+
return stripSpaces(`${description}
|
|
126
|
+
declare const ${schema.identifier}: ${typings};${closingTag}`);
|
|
127
|
+
}
|
|
128
|
+
if (schema instanceof KeyValue) {
|
|
129
|
+
if (schema.value instanceof _zui.z.ZodOptional) {
|
|
130
|
+
let innerType = schema.value._def.innerType;
|
|
131
|
+
if (innerType instanceof _zui.z.Schema && !innerType.description && schema.value.description) {
|
|
132
|
+
innerType = innerType == null ? void 0 : innerType.describe(schema.value.description);
|
|
133
|
+
}
|
|
134
|
+
const optionalToken = schema.key.endsWith("?") ? "" : "?";
|
|
135
|
+
return sUnwrapZodRecursive(new KeyValue(schema.key + optionalToken, innerType), newOptions);
|
|
136
|
+
}
|
|
137
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema.value._def.description || schema.value.description);
|
|
138
|
+
const delimiter = (description == null ? void 0 : description.trim().length) > 0 ? "\n" : "";
|
|
139
|
+
const withoutDesc = schema.value.describe("");
|
|
140
|
+
return `${delimiter}${description}${delimiter}${schema.key}: ${await sUnwrapZodRecursive(withoutDesc, newOptions)}${delimiter}`;
|
|
141
|
+
}
|
|
142
|
+
if (schema instanceof FnParameters) {
|
|
143
|
+
if (schema.schema instanceof _zui.z.ZodTuple) {
|
|
144
|
+
let args = "";
|
|
145
|
+
for (let i = 0; i < schema.schema.items.length; i++) {
|
|
146
|
+
const argName = _nullishCoalesce(((_b = (_a = schema.schema.items[i]) == null ? void 0 : _a.ui) == null ? void 0 : _b.title), () => ( `arg${i}`));
|
|
147
|
+
const item = schema.schema.items[i];
|
|
148
|
+
args += `${await sUnwrapZodRecursive(new KeyValue(_chunkENFB45AIcjs.toPropertyKey.call(void 0, argName), item), newOptions)}, `;
|
|
149
|
+
}
|
|
150
|
+
return args;
|
|
151
|
+
}
|
|
152
|
+
const typings = (await sUnwrapZodRecursive(schema.schema, newOptions)).trim();
|
|
153
|
+
const startsWithPairs = typings.startsWith("{") && typings.endsWith("}") || typings.startsWith("[") && typings.endsWith("]") || typings.startsWith("(") && typings.endsWith(")") || typings.startsWith("Array<") && typings.endsWith(">") || typings.startsWith("Record<") && typings.endsWith(">") || isArrayOfPrimitives(typings);
|
|
154
|
+
if (startsWithPairs) {
|
|
155
|
+
return `args: ${typings}`;
|
|
156
|
+
} else {
|
|
157
|
+
return typings;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (schema instanceof FnReturn) {
|
|
161
|
+
if (schema.schema instanceof _zui.z.ZodOptional) {
|
|
162
|
+
return `${await sUnwrapZodRecursive(schema.schema.unwrap(), newOptions)} | undefined`;
|
|
163
|
+
}
|
|
164
|
+
return sUnwrapZodRecursive(schema.schema, newOptions);
|
|
165
|
+
}
|
|
166
|
+
if (schema instanceof _zui.z.ZodDefault) {
|
|
167
|
+
return sUnwrapZodRecursive(schema._def.innerType, options);
|
|
168
|
+
}
|
|
169
|
+
if (schema instanceof _zui.z.ZodVoid) {
|
|
170
|
+
return "void";
|
|
171
|
+
}
|
|
172
|
+
if (schema instanceof _zui.z.ZodUnknown) {
|
|
173
|
+
return "unknown";
|
|
174
|
+
}
|
|
175
|
+
if (schema instanceof _zui.z.ZodAny) {
|
|
176
|
+
return "any";
|
|
177
|
+
}
|
|
178
|
+
if (schema instanceof _zui.z.ZodPromise) {
|
|
179
|
+
return `Promise<${await sUnwrapZodRecursive(schema.unwrap(), newOptions)}>`;
|
|
180
|
+
}
|
|
181
|
+
if (schema instanceof _zui.z.ZodFunction) {
|
|
182
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
183
|
+
const input = await sUnwrapZodRecursive(new FnParameters(schema._def.args), newOptions);
|
|
184
|
+
const output = await sUnwrapZodRecursive(new FnReturn(schema._def.returns), newOptions);
|
|
185
|
+
if (options == null ? void 0 : options.declaration) {
|
|
186
|
+
return `${description}
|
|
187
|
+
(${input}): ${output}`;
|
|
188
|
+
}
|
|
189
|
+
return `${description}
|
|
190
|
+
(${input}) => ${output}`;
|
|
191
|
+
}
|
|
192
|
+
if (schema instanceof _zui.z.ZodArray) {
|
|
193
|
+
const item = await sUnwrapZodRecursive(schema._def.type, newOptions);
|
|
194
|
+
if (isPrimitive(item)) {
|
|
195
|
+
return `${item}[]`;
|
|
196
|
+
}
|
|
197
|
+
return `Array<${item}>`;
|
|
198
|
+
}
|
|
199
|
+
if (schema instanceof _zui.z.ZodEnum) {
|
|
200
|
+
const values = schema._def.values.map(_chunkENFB45AIcjs.escapeString);
|
|
201
|
+
return values.join(" | ");
|
|
202
|
+
}
|
|
203
|
+
if (schema instanceof _zui.z.ZodTuple) {
|
|
204
|
+
if (schema.items.length === 0) {
|
|
205
|
+
return "[]";
|
|
206
|
+
}
|
|
207
|
+
const items = await Promise.all(schema.items.map((i) => sUnwrapZodRecursive(i, newOptions)));
|
|
208
|
+
return `[${items.join(", ")}]`;
|
|
209
|
+
}
|
|
210
|
+
if (schema instanceof _zui.z.ZodNullable) {
|
|
211
|
+
return `${await sUnwrapZodRecursive(schema.unwrap(), options)} | null`;
|
|
212
|
+
}
|
|
213
|
+
if (schema instanceof _zui.z.ZodOptional) {
|
|
214
|
+
if ((options == null ? void 0 : options.declaration) || (options == null ? void 0 : options.parent) instanceof _zui.z.ZodRecord) {
|
|
215
|
+
return `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)} | undefined`;
|
|
216
|
+
}
|
|
217
|
+
const optionalToken = options.parent instanceof KeyValue ? "| undefined" : "";
|
|
218
|
+
const val = `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)}${optionalToken}`;
|
|
219
|
+
return val;
|
|
220
|
+
}
|
|
221
|
+
if (schema instanceof _zui.z.ZodObject) {
|
|
222
|
+
const props = await Promise.all(
|
|
223
|
+
Object.entries(schema.shape).map(async ([key, value]) => {
|
|
224
|
+
if (value instanceof _zui.z.Schema) {
|
|
225
|
+
return sUnwrapZodRecursive(new KeyValue(_chunkENFB45AIcjs.toPropertyKey.call(void 0, key), value), newOptions);
|
|
226
|
+
}
|
|
227
|
+
return `${key}: unknown`;
|
|
228
|
+
})
|
|
229
|
+
);
|
|
230
|
+
return `{ ${props.join("; ")} }`;
|
|
231
|
+
}
|
|
232
|
+
if (schema instanceof _zui.z.ZodString) {
|
|
233
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
234
|
+
return `${description} string`.trim();
|
|
235
|
+
}
|
|
236
|
+
if (schema instanceof _zui.z.ZodUnion) {
|
|
237
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
238
|
+
const options2 = await Promise.all(
|
|
239
|
+
schema.options.map(async (option) => {
|
|
240
|
+
return sUnwrapZodRecursive(option, newOptions);
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
return `${description}
|
|
244
|
+
${options2.join(" | ")}`;
|
|
245
|
+
}
|
|
246
|
+
if (schema instanceof _zui.z.ZodLiteral) {
|
|
247
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
248
|
+
return `${description}
|
|
249
|
+
${typeof schema.value === "string" ? _chunkENFB45AIcjs.escapeString.call(void 0, schema.value) : schema.value}`.trim();
|
|
250
|
+
}
|
|
251
|
+
if (schema instanceof _zui.z.ZodNumber) {
|
|
252
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
253
|
+
return `${description} number`.trim();
|
|
254
|
+
}
|
|
255
|
+
if (schema instanceof _zui.z.ZodBoolean) {
|
|
256
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
257
|
+
return `${description} boolean`.trim();
|
|
258
|
+
}
|
|
259
|
+
if (schema instanceof _zui.z.ZodCatch) {
|
|
260
|
+
return sUnwrapZodRecursive(schema.removeCatch(), newOptions);
|
|
261
|
+
}
|
|
262
|
+
if (schema instanceof _zui.z.ZodLazy) {
|
|
263
|
+
return sUnwrapZodRecursive(schema._def.getter(), newOptions);
|
|
264
|
+
}
|
|
265
|
+
if (schema instanceof _zui.z.ZodRecord) {
|
|
266
|
+
const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
|
|
267
|
+
const keyType = await sUnwrapZodRecursive(schema._def.keyType, newOptions);
|
|
268
|
+
const valueType = await sUnwrapZodRecursive(schema._def.valueType, newOptions);
|
|
269
|
+
return `${description} { [key: (${keyType})]: (${valueType}) }`;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
let typings = await (schema == null ? void 0 : schema.toTypescriptAsync());
|
|
273
|
+
typings ??= "unknown";
|
|
274
|
+
return stripSpaces(typings);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.error("Error in sUnwrapZod", { error, schema, parent: options == null ? void 0 : options.parent });
|
|
277
|
+
return "unknown";
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
exports.formatTypings = formatTypings; exports.getTypings = getTypings;
|