llmz 0.2.1 → 0.2.3
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/CLAUDE.md +0 -1
- package/dist/{chunk-WWZ2W4WR.cjs → chunk-3UZKLXAD.cjs} +410 -514
- package/dist/{chunk-HM5H556L.js → chunk-72ZWBNZV.js} +1 -1
- package/dist/{chunk-D6PU5YAS.cjs → chunk-DDSJTR6Q.cjs} +8 -7
- package/dist/{chunk-665O7CAN.js → chunk-GDJTKI7J.js} +5 -1
- package/dist/{chunk-YX27XM67.js → chunk-GLXADNTR.js} +13 -1
- package/dist/{chunk-FPLSJF4S.cjs → chunk-GOWPACSK.cjs} +15 -3
- package/dist/{chunk-XVVYNOTX.js → chunk-HB2G32AK.js} +3 -2
- package/dist/{chunk-YQT5G77W.cjs → chunk-HEAQAEFZ.cjs} +2 -2
- package/dist/{chunk-DD4AZSP5.cjs → chunk-HMMM32RG.cjs} +19 -15
- package/dist/{chunk-MY26EAOP.cjs → chunk-KG5E3UZZ.cjs} +20 -20
- package/dist/{chunk-YGKQEVQQ.cjs → chunk-OVRDJMZJ.cjs} +29 -37
- package/dist/{chunk-E5NHK3FS.js → chunk-OXEKAOVI.js} +6 -14
- package/dist/{chunk-ETYFOCWC.cjs → chunk-PZE6PIPG.cjs} +12 -11
- package/dist/chunk-RGUG3UMF.cjs +26 -0
- package/dist/{chunk-GC5IQDGV.js → chunk-TDALRNGL.js} +4 -3
- package/dist/chunk-UGHFNCPD.js +26 -0
- package/dist/{chunk-ZWUWCRHG.js → chunk-XMFQVARN.js} +5 -5
- package/dist/{chunk-DH35WO5G.js → chunk-YRS7KRKP.js} +401 -505
- package/dist/compiler/ast.d.ts +26 -0
- package/dist/compiler/compiler.d.ts +13 -11
- package/dist/compiler/plugins/line-tracking.d.ts +6 -4
- package/dist/compiler/plugins/replace-comment.d.ts +8 -4
- package/dist/compiler/plugins/return-async.d.ts +18 -4
- package/dist/compiler/plugins/track-tool-calls.d.ts +21 -4
- package/dist/compiler/plugins/variable-extraction.d.ts +9 -4
- package/dist/component.default.d.ts +13 -91
- package/dist/{dual-modes-RMF7V7ZQ.js → dual-modes-BYABHBDI.js} +3 -3
- package/dist/dual-modes-HO6RRIZ5.cjs +10 -0
- package/dist/emscripten-module.wasm +0 -0
- package/dist/{execute-LNUBLVMZ.js → execute-DSGJ2UNL.js} +9 -8
- package/dist/{execute-2AGZ5QUN.cjs → execute-MRZZ4AYY.cjs} +41 -40
- package/dist/exit-MX56VN2C.cjs +8 -0
- package/dist/{exit-VJATJTQI.js → exit-UQ3EUX5D.js} +2 -2
- package/dist/exit.d.ts +1 -1
- package/dist/index.cjs +210 -253
- package/dist/index.d.ts +2 -0
- package/dist/index.js +184 -227
- package/dist/index.workerd.js +17328 -0
- package/dist/prompts/chat-mode/system.md.d.ts +1 -1
- package/dist/prompts/worker-mode/system.md.d.ts +1 -1
- package/dist/prompts/worker-mode/user.md.d.ts +1 -1
- package/dist/quickjs-variant.d.ts +22 -0
- package/dist/quickjs-variant.workerd.d.ts +22 -0
- package/dist/{tool-HTAYKIA2.js → tool-KD7FL45V.js} +3 -3
- package/dist/{tool-V55GD2FS.cjs → tool-VE2YHIY2.cjs} +4 -4
- package/dist/{truncator-OZOBNYON.js → truncator-73RCL52Y.js} +2 -2
- package/dist/truncator-FZNLYSDL.cjs +12 -0
- package/dist/{typings-SCKZCAPN.js → typings-E2RROCLT.js} +2 -2
- package/dist/{typings-S6I6IPTG.cjs → typings-LQOBZXSO.cjs} +3 -3
- package/dist/typings-formatter.d.ts +19 -0
- package/dist/{utils-ZEZ66X6Q.js → utils-IATCUNKF.js} +5 -1
- package/dist/utils-ITB4NEL7.cjs +43 -0
- package/dist/utils.d.ts +18 -0
- package/dist/vm-6D3IIIU7.cjs +12 -0
- package/dist/{vm-44H4UKI2.js → vm-QO5FSGPN.js} +2 -1
- package/package.json +8 -14
- package/dist/dual-modes-ZZY6QPYT.cjs +0 -10
- package/dist/exit-LUJY7JIG.cjs +0 -8
- package/dist/truncator-7PGEGCHV.cjs +0 -12
- package/dist/utils-GLZVMRWO.cjs +0 -39
- package/dist/vm-A3OTQVIR.cjs +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export type { ExecutionProps, ExecutionHooks } from './runtime/types.js';
|
|
|
22
22
|
export { type ValueOrGetter, getValue } from './getter.js';
|
|
23
23
|
export * from './message-stream/index.js';
|
|
24
24
|
export * from './custom-client.js';
|
|
25
|
+
export { configureQuickJS } from './quickjs-variant.js';
|
|
26
|
+
export { configureTokenizer } from './utils.js';
|
|
25
27
|
export declare const utils: {
|
|
26
28
|
toValidObjectName: (str: string) => string;
|
|
27
29
|
toValidFunctionName: (str: string) => string;
|
package/dist/index.js
CHANGED
|
@@ -10,21 +10,28 @@ import {
|
|
|
10
10
|
_CustomModelClient,
|
|
11
11
|
getValue,
|
|
12
12
|
parseExit
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-XMFQVARN.js";
|
|
14
14
|
import {
|
|
15
15
|
MARKER,
|
|
16
16
|
NAME_REGEX,
|
|
17
17
|
StreamingMessageParser,
|
|
18
18
|
generateInstructions,
|
|
19
19
|
tryParseJson
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-OXEKAOVI.js";
|
|
21
|
+
import {
|
|
22
|
+
configureQuickJS
|
|
23
|
+
} from "./chunk-UGHFNCPD.js";
|
|
21
24
|
import {
|
|
22
25
|
Tool
|
|
23
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-TDALRNGL.js";
|
|
24
27
|
import {
|
|
25
28
|
formatTypings,
|
|
26
|
-
getTypings
|
|
27
|
-
|
|
29
|
+
getTypings,
|
|
30
|
+
isGroup,
|
|
31
|
+
isPunct,
|
|
32
|
+
parse,
|
|
33
|
+
tokenize
|
|
34
|
+
} from "./chunk-GDJTKI7J.js";
|
|
28
35
|
import {
|
|
29
36
|
CodeFormattingError,
|
|
30
37
|
LoopExceededError,
|
|
@@ -34,7 +41,7 @@ import {
|
|
|
34
41
|
import "./chunk-YEAWWJSJ.js";
|
|
35
42
|
import {
|
|
36
43
|
Exit
|
|
37
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-HB2G32AK.js";
|
|
38
45
|
import {
|
|
39
46
|
Component,
|
|
40
47
|
assertValidComponent,
|
|
@@ -46,8 +53,9 @@ import {
|
|
|
46
53
|
stripTruncationTags,
|
|
47
54
|
truncateWrappedContent,
|
|
48
55
|
wrapContent
|
|
49
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-72ZWBNZV.js";
|
|
50
57
|
import {
|
|
58
|
+
configureTokenizer,
|
|
51
59
|
escapeString,
|
|
52
60
|
getMultilineComment,
|
|
53
61
|
isJsonSchema,
|
|
@@ -55,238 +63,193 @@ import {
|
|
|
55
63
|
isZuiSchema,
|
|
56
64
|
toValidFunctionName,
|
|
57
65
|
toValidObjectName
|
|
58
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-GLXADNTR.js";
|
|
59
67
|
import {
|
|
60
|
-
cloneDeep_default,
|
|
61
68
|
upperFirst_default
|
|
62
69
|
} from "./chunk-34GJUS6U.js";
|
|
63
70
|
|
|
64
71
|
// package.json
|
|
65
|
-
var version = "0.2.
|
|
72
|
+
var version = "0.2.3";
|
|
66
73
|
|
|
67
74
|
// src/objects.ts
|
|
68
75
|
import { z } from "@bpinternal/zui";
|
|
69
76
|
|
|
70
77
|
// src/hoist.ts
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
function printNodes(nodes) {
|
|
79
|
+
let out = "";
|
|
80
|
+
let afterLineComment = false;
|
|
81
|
+
const emit = (n) => {
|
|
82
|
+
const newlines = Math.min(n.nl ?? 0, 2);
|
|
83
|
+
if (newlines > 0) {
|
|
84
|
+
out += "\n".repeat(newlines);
|
|
85
|
+
} else if (afterLineComment) {
|
|
86
|
+
out += "\n";
|
|
87
|
+
} else if (out.length && !out.endsWith("\n")) {
|
|
88
|
+
out += " ";
|
|
89
|
+
}
|
|
90
|
+
afterLineComment = false;
|
|
91
|
+
if (isGroup(n)) {
|
|
92
|
+
out += n.open;
|
|
93
|
+
for (const child of n.children) {
|
|
94
|
+
emit(child);
|
|
95
|
+
}
|
|
96
|
+
if (afterLineComment) {
|
|
97
|
+
out += "\n";
|
|
98
|
+
afterLineComment = false;
|
|
99
|
+
}
|
|
100
|
+
out += n.close;
|
|
101
|
+
} else {
|
|
102
|
+
out += n.text;
|
|
103
|
+
afterLineComment = n.kind === "line-comment";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
for (const n of nodes) {
|
|
107
|
+
emit(n);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
80
110
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
removeBabelComments(val);
|
|
111
|
+
function keyOf(group) {
|
|
112
|
+
const parts = [];
|
|
113
|
+
const visit = (n) => {
|
|
114
|
+
if (isGroup(n)) {
|
|
115
|
+
parts.push(n.open);
|
|
116
|
+
n.children.forEach(visit);
|
|
117
|
+
parts.push(n.close);
|
|
118
|
+
} else if (n.kind === "word" || n.kind === "string" || n.kind === "punct" && n.text !== ";" && n.text !== ",") {
|
|
119
|
+
parts.push(n.text);
|
|
91
120
|
}
|
|
92
|
-
}
|
|
121
|
+
};
|
|
122
|
+
visit(group);
|
|
123
|
+
return parts.join(" ");
|
|
93
124
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const typeString = getTypingsWithoutComments(typeNode.typeAnnotation);
|
|
100
|
-
if (!typeMap.has(typeString)) {
|
|
101
|
-
typeMap.set(typeString, typeNode);
|
|
125
|
+
var prevMeaningful = (siblings, index) => {
|
|
126
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
127
|
+
const n = siblings[i];
|
|
128
|
+
if (isGroup(n) || n.kind !== "block-comment" && n.kind !== "line-comment") {
|
|
129
|
+
return n;
|
|
102
130
|
}
|
|
103
131
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
let
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const { node, parentPath } = currPath;
|
|
121
|
-
if (t.isIdentifier(node) && node.name) {
|
|
122
|
-
parts.add(node.name);
|
|
123
|
-
}
|
|
124
|
-
if (t.isTSMethodSignature(node) && currPath.key === "parameters") {
|
|
125
|
-
parts.add("Input");
|
|
126
|
-
}
|
|
127
|
-
if (currPath.key === "returnType") {
|
|
128
|
-
parts.add("Output");
|
|
129
|
-
const methodName = "id" in parentPath.node && "name" in parentPath.node.id && ((_b = (_a = parentPath == null ? void 0 : parentPath.node) == null ? void 0 : _a.id) == null ? void 0 : _b.name);
|
|
130
|
-
if (methodName) {
|
|
131
|
-
parts.add(methodName);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (((_c = node == null ? void 0 : node.key) == null ? void 0 : _c.type) === "Identifier") {
|
|
135
|
-
parts.add(node.key.name);
|
|
136
|
-
}
|
|
137
|
-
if (t.isTSParameterProperty(node) || t.isTSFunctionType(node)) {
|
|
138
|
-
parts.add("Input");
|
|
139
|
-
}
|
|
140
|
-
if (t.isTSFunctionType(node)) {
|
|
141
|
-
parts.add("Output");
|
|
142
|
-
}
|
|
143
|
-
currPath = parentPath;
|
|
132
|
+
return void 0;
|
|
133
|
+
};
|
|
134
|
+
var asName = (text) => upperFirst_default(text.replace(/['"]/g, "").replace(/[^A-Za-z0-9_$]/g, ""));
|
|
135
|
+
function segmentsAt(siblings, index) {
|
|
136
|
+
var _a;
|
|
137
|
+
const prev = prevMeaningful(siblings, index);
|
|
138
|
+
if (!prev || isGroup(prev)) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
if (isPunct(prev, "=>")) {
|
|
142
|
+
return ["Output"];
|
|
143
|
+
}
|
|
144
|
+
if (isPunct(prev, ":") || isPunct(prev, "<")) {
|
|
145
|
+
let i = siblings.indexOf(prev) - 1;
|
|
146
|
+
while (i >= 0 && !isGroup(siblings[i]) && ((_a = siblings[i].kind) == null ? void 0 : _a.includes("comment"))) {
|
|
147
|
+
i--;
|
|
144
148
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return getTypePaths(path).join("");
|
|
149
|
-
}
|
|
150
|
-
function findNestedTypes(path) {
|
|
151
|
-
const node = path.node;
|
|
152
|
-
if (t.isTSTypeLiteral(node)) {
|
|
153
|
-
const typeString = getTypingsWithoutComments(node);
|
|
154
|
-
typeCounts.set(typeString, (typeCounts.get(typeString) || 0) + 1);
|
|
155
|
-
if (typeMap.has(typeString) && (typeCounts.get(typeString) || 0) > 1) {
|
|
156
|
-
path.replaceWith(t.tsTypeReference(typeMap.get(typeString).id));
|
|
157
|
-
} else if (!typeMap.has(typeString) && (typeCounts.get(typeString) || 0) > 1) {
|
|
158
|
-
const typeName = generateUniqueTypeName(generateTypeName(path));
|
|
159
|
-
const typeAlias = createTypeAlias(typeName, node);
|
|
160
|
-
addTypeToMap(typeAlias);
|
|
161
|
-
path.replaceWith(t.tsTypeReference(t.identifier(typeName)));
|
|
162
|
-
}
|
|
163
|
-
const members = path.get("members");
|
|
164
|
-
const memberPaths = Array.isArray(members) ? members : [members];
|
|
165
|
-
memberPaths.forEach((memberPath) => {
|
|
166
|
-
findNestedTypes(memberPath);
|
|
167
|
-
});
|
|
149
|
+
let q = siblings[i];
|
|
150
|
+
if (q && !isGroup(q) && q.kind === "punct" && q.text === "?") {
|
|
151
|
+
q = siblings[--i];
|
|
168
152
|
}
|
|
169
|
-
if (
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
findNestedTypes(annPath);
|
|
173
|
-
}
|
|
153
|
+
if (q && isGroup(q) && q.open === "(") {
|
|
154
|
+
const fnWord = prevMeaningful(siblings, i);
|
|
155
|
+
return fnWord && !isGroup(fnWord) && fnWord.kind === "word" ? [asName(fnWord.text), "Output"] : ["Output"];
|
|
174
156
|
}
|
|
175
|
-
if (
|
|
176
|
-
|
|
157
|
+
if (q && !isGroup(q) && (q.kind === "word" || q.kind === "string")) {
|
|
158
|
+
return [asName(q.text)];
|
|
177
159
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
160
|
+
}
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
function walkLiterals(siblings, path, visit) {
|
|
164
|
+
var _a;
|
|
165
|
+
for (let i = 0; i < siblings.length; i++) {
|
|
166
|
+
const node = siblings[i];
|
|
167
|
+
if (!isGroup(node)) {
|
|
168
|
+
continue;
|
|
181
169
|
}
|
|
182
|
-
if (
|
|
183
|
-
;
|
|
184
|
-
|
|
170
|
+
if (node.open === "(") {
|
|
171
|
+
const fnWord = prevMeaningful(siblings, i);
|
|
172
|
+
const fnName = fnWord && !isGroup(fnWord) && fnWord.kind === "word" ? [asName(fnWord.text)] : [];
|
|
173
|
+
walkLiterals(node.children, [...path, ...fnName], visit);
|
|
174
|
+
continue;
|
|
185
175
|
}
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
findNestedTypes(returnPath);
|
|
190
|
-
const params = path.get("parameters");
|
|
191
|
-
params.forEach((paramPath) => {
|
|
192
|
-
const ta = paramPath.get("typeAnnotation.typeAnnotation");
|
|
193
|
-
if (ta == null ? void 0 : ta.node)
|
|
194
|
-
findNestedTypes(ta);
|
|
195
|
-
});
|
|
176
|
+
if (node.open === "<" || node.open === "[") {
|
|
177
|
+
walkLiterals(node.children, [...path, ...segmentsAt(siblings, i)], visit);
|
|
178
|
+
continue;
|
|
196
179
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
180
|
+
const prev = prevMeaningful(siblings, i);
|
|
181
|
+
if (prev && isPunct(prev, "=")) {
|
|
182
|
+
const eqIdx = siblings.indexOf(prev);
|
|
183
|
+
const nameTok = siblings[eqIdx - 1];
|
|
184
|
+
const typeTok = siblings[eqIdx - 2];
|
|
185
|
+
const isAlias = nameTok && typeTok && !isGroup(nameTok) && !isGroup(typeTok) && nameTok.kind === "word" && typeTok.kind === "word" && typeTok.text === "type";
|
|
186
|
+
if (!isAlias) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const aliasName = nameTok.text;
|
|
190
|
+
visit({ siblings, index: i, group: node, path: [aliasName], aliasName });
|
|
191
|
+
if (siblings[i] === node) {
|
|
192
|
+
walkLiterals(node.children, [aliasName], visit);
|
|
201
193
|
}
|
|
202
|
-
|
|
203
|
-
params.forEach((paramPath) => {
|
|
204
|
-
const ta = paramPath.get("typeAnnotation.typeAnnotation");
|
|
205
|
-
if (ta == null ? void 0 : ta.node)
|
|
206
|
-
findNestedTypes(ta);
|
|
207
|
-
});
|
|
194
|
+
continue;
|
|
208
195
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
findNestedTypes(returnType);
|
|
196
|
+
const prevIsNamespace = prev && !isGroup(prev) && prev.kind === "word" && ((_a = prevMeaningful(siblings, siblings.indexOf(prev))) == null ? void 0 : _a.kind) === "word";
|
|
197
|
+
const namespaceLike = prevIsNamespace && ["namespace", "module"].includes(prevMeaningful(siblings, siblings.indexOf(prev)).text);
|
|
198
|
+
const segments = segmentsAt(siblings, i);
|
|
199
|
+
const newPath = [...path, ...segments];
|
|
200
|
+
if (!namespaceLike) {
|
|
201
|
+
visit({ siblings, index: i, group: node, path: newPath });
|
|
202
|
+
}
|
|
203
|
+
if (siblings[i] === node) {
|
|
204
|
+
walkLiterals(node.children, namespaceLike ? [...path, asName(prev.text)] : newPath, visit);
|
|
219
205
|
}
|
|
220
206
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
},
|
|
239
|
-
TSFunctionType(path) {
|
|
240
|
-
const returnPath = path.get("typeAnnotation");
|
|
241
|
-
if (returnPath.node)
|
|
242
|
-
findNestedTypes(returnPath);
|
|
243
|
-
const params = path.get("parameters");
|
|
244
|
-
params.forEach((param) => {
|
|
245
|
-
const ta = param.get("typeAnnotation.typeAnnotation");
|
|
246
|
-
if (ta == null ? void 0 : ta.node)
|
|
247
|
-
findNestedTypes(ta);
|
|
248
|
-
});
|
|
249
|
-
},
|
|
250
|
-
TSMethodSignature(path) {
|
|
251
|
-
const returnPath = path.get("typeAnnotation.typeAnnotation");
|
|
252
|
-
if (returnPath == null ? void 0 : returnPath.node) {
|
|
253
|
-
findNestedTypes(returnPath);
|
|
254
|
-
}
|
|
255
|
-
const params = path.get("parameters");
|
|
256
|
-
params.forEach((param) => {
|
|
257
|
-
const ta = param.get("typeAnnotation.typeAnnotation");
|
|
258
|
-
if (ta == null ? void 0 : ta.node)
|
|
259
|
-
findNestedTypes(ta);
|
|
260
|
-
});
|
|
261
|
-
},
|
|
262
|
-
TSDeclareFunction(path) {
|
|
263
|
-
const params = path.get("params");
|
|
264
|
-
params.forEach((p) => {
|
|
265
|
-
const ta = p.get("typeAnnotation.typeAnnotation");
|
|
266
|
-
if (ta == null ? void 0 : ta.node)
|
|
267
|
-
findNestedTypes(ta);
|
|
268
|
-
});
|
|
269
|
-
const returnPath = path.get("returnType.typeAnnotation");
|
|
270
|
-
if (returnPath == null ? void 0 : returnPath.node)
|
|
271
|
-
findNestedTypes(returnPath);
|
|
207
|
+
}
|
|
208
|
+
function extractAndHoistTypes(code) {
|
|
209
|
+
const top = parse(tokenize(code));
|
|
210
|
+
const counts = /* @__PURE__ */ new Map();
|
|
211
|
+
const aliasByKey = /* @__PURE__ */ new Map();
|
|
212
|
+
const usedNames = /* @__PURE__ */ new Set();
|
|
213
|
+
walkLiterals(top, [], ({ group, path, aliasName }) => {
|
|
214
|
+
const key = keyOf(group);
|
|
215
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
216
|
+
if (aliasName && !aliasByKey.has(key)) {
|
|
217
|
+
aliasByKey.set(key, aliasName);
|
|
218
|
+
}
|
|
219
|
+
for (const segment of path) {
|
|
220
|
+
usedNames.add(segment);
|
|
221
|
+
}
|
|
222
|
+
if (aliasName) {
|
|
223
|
+
usedNames.add(aliasName);
|
|
272
224
|
}
|
|
273
225
|
});
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
226
|
+
const uniqueName = (base) => {
|
|
227
|
+
let name = base;
|
|
228
|
+
let counter = 1;
|
|
229
|
+
while (usedNames.has(name)) {
|
|
230
|
+
name = `${base}${counter++}`;
|
|
231
|
+
}
|
|
232
|
+
usedNames.add(name);
|
|
233
|
+
return name;
|
|
234
|
+
};
|
|
235
|
+
const newAliases = [];
|
|
236
|
+
walkLiterals(top, [], ({ siblings, index, group, aliasName, path }) => {
|
|
237
|
+
const key = keyOf(group);
|
|
238
|
+
if ((counts.get(key) ?? 0) < 2 || aliasName) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
let name = aliasByKey.get(key);
|
|
242
|
+
if (!name) {
|
|
243
|
+
const deduped = [...new Set(path)];
|
|
244
|
+
name = uniqueName(deduped.length ? deduped.join("") : "UnnamedType");
|
|
245
|
+
aliasByKey.set(key, name);
|
|
246
|
+
newAliases.push(`type ${name} = ${printNodes([{ ...group, nl: 0 }])}`);
|
|
281
247
|
}
|
|
248
|
+
siblings[index] = { kind: "word", text: name, nl: group.nl };
|
|
282
249
|
});
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
(node) => !hoistedTypes.some((ht) => t.isTSTypeAliasDeclaration(node) && node.id.name === ht.id.name)
|
|
287
|
-
)
|
|
288
|
-
];
|
|
289
|
-
return ast;
|
|
250
|
+
const body = printNodes(top);
|
|
251
|
+
return newAliases.length ? `${newAliases.join("\n")}
|
|
252
|
+
${body}` : body;
|
|
290
253
|
}
|
|
291
254
|
async function hoistTypings(code, formatOptions) {
|
|
292
255
|
formatOptions ??= {};
|
|
@@ -294,15 +257,7 @@ async function hoistTypings(code, formatOptions) {
|
|
|
294
257
|
for (let i = 1; i <= 5; i++) {
|
|
295
258
|
try {
|
|
296
259
|
const initialCode = code;
|
|
297
|
-
|
|
298
|
-
sourceType: "module",
|
|
299
|
-
plugins: ["typescript"]
|
|
300
|
-
});
|
|
301
|
-
const transformedAst = extractAndHoistTypes(ast);
|
|
302
|
-
code = new CodeGenerator(transformedAst, {
|
|
303
|
-
// quotes: 'single',
|
|
304
|
-
compact: false
|
|
305
|
-
}).generate().code;
|
|
260
|
+
code = extractAndHoistTypes(code);
|
|
306
261
|
if (initialCode === code) {
|
|
307
262
|
break;
|
|
308
263
|
}
|
|
@@ -1572,20 +1527,20 @@ var utils = {
|
|
|
1572
1527
|
stripTruncationTags
|
|
1573
1528
|
};
|
|
1574
1529
|
var execute = async (props) => {
|
|
1575
|
-
const { executeContext } = await import("./execute-
|
|
1530
|
+
const { executeContext } = await import("./execute-DSGJ2UNL.js");
|
|
1576
1531
|
return executeContext(props);
|
|
1577
1532
|
};
|
|
1578
1533
|
var init = async () => {
|
|
1579
|
-
await import("./execute-
|
|
1534
|
+
await import("./execute-DSGJ2UNL.js");
|
|
1580
1535
|
await import("./component-ASNZHQUR.js");
|
|
1581
|
-
await import("./tool-
|
|
1582
|
-
await import("./exit-
|
|
1536
|
+
await import("./tool-KD7FL45V.js");
|
|
1537
|
+
await import("./exit-UQ3EUX5D.js");
|
|
1583
1538
|
await import("./jsx-DDZ63UUF.js");
|
|
1584
|
-
await import("./vm-
|
|
1585
|
-
await import("./utils-
|
|
1586
|
-
await import("./truncator-
|
|
1587
|
-
await import("./typings-
|
|
1588
|
-
await import("./dual-modes-
|
|
1539
|
+
await import("./vm-QO5FSGPN.js");
|
|
1540
|
+
await import("./utils-IATCUNKF.js");
|
|
1541
|
+
await import("./truncator-73RCL52Y.js");
|
|
1542
|
+
await import("./typings-E2RROCLT.js");
|
|
1543
|
+
await import("./dual-modes-BYABHBDI.js");
|
|
1589
1544
|
};
|
|
1590
1545
|
export {
|
|
1591
1546
|
BaseResponse,
|
|
@@ -1618,6 +1573,8 @@ export {
|
|
|
1618
1573
|
_CustomModelClient,
|
|
1619
1574
|
assertValidComponent,
|
|
1620
1575
|
collectText,
|
|
1576
|
+
configureQuickJS,
|
|
1577
|
+
configureTokenizer,
|
|
1621
1578
|
execute,
|
|
1622
1579
|
generateInstructions,
|
|
1623
1580
|
getValue,
|