@jixo/cli 0.26.0 → 4.0.0
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/bundle/{file-replacer-CZhq6MJJ.js → file-replacer-C3H2FqOL.js} +95 -35
- package/bundle/file-replacer-C3H2FqOL.js.map +1 -0
- package/bundle/file-replacer-ajVzZOp7.js +3 -0
- package/bundle/gen-prompt-DF1HOjXb.js +4 -0
- package/bundle/{gen-prompt-3bZp8K__.js → gen-prompt-DxNgl5Cp.js} +2 -2
- package/bundle/{gen-prompt-3bZp8K__.js.map → gen-prompt-DxNgl5Cp.js.map} +1 -1
- package/bundle/index.js +142 -228
- package/bundle/index.js.map +1 -1
- package/dist/commands/google-aistudio.d.ts.map +1 -1
- package/dist/commands/google-aistudio.js +17 -21
- package/dist/commands/google-aistudio.js.map +1 -1
- package/package.json +3 -3
- package/assets/bundle/google-aistudio.browser.js +0 -1750
- package/assets/bundle/google-aistudio.jixo.js +0 -63655
- package/bundle/file-replacer-CQZSjZXb.js +0 -3
- package/bundle/file-replacer-CZhq6MJJ.js.map +0 -1
- package/bundle/gen-prompt-IINGP6mf.js +0 -4
|
@@ -1,1750 +0,0 @@
|
|
|
1
|
-
const obj_assign_props = /* @__NO_SIDE_EFFECTS__ */ (a$1, b$1) => {
|
|
2
|
-
const b_props = Object.getOwnPropertyDescriptors(b$1);
|
|
3
|
-
Object.defineProperties(a$1, b_props);
|
|
4
|
-
return a$1;
|
|
5
|
-
};
|
|
6
|
-
const isPromiseLike = (value) => value !== null && typeof value?.then === "function";
|
|
7
|
-
const func_remember = /* @__NO_SIDE_EFFECTS__ */ (func, key, cacheAwaited) => {
|
|
8
|
-
let result;
|
|
9
|
-
const once_fn = function(...args) {
|
|
10
|
-
const newKey = key?.apply(this, args);
|
|
11
|
-
if (result === void 0 || newKey !== result.key) {
|
|
12
|
-
const res = func.apply(this, args);
|
|
13
|
-
result = {
|
|
14
|
-
key: newKey,
|
|
15
|
-
res,
|
|
16
|
-
awaitedRes: void 0
|
|
17
|
-
};
|
|
18
|
-
if (cacheAwaited) if (typeof res === "object" && res && "then" in res && typeof res.then === "function") res.then((r$1) => {
|
|
19
|
-
if (result && res === result.res) result.awaitedRes = {
|
|
20
|
-
type: "resolved",
|
|
21
|
-
result: r$1
|
|
22
|
-
};
|
|
23
|
-
}, (e$1) => {
|
|
24
|
-
if (result && res === result.res) result.awaitedRes = {
|
|
25
|
-
type: "rejected",
|
|
26
|
-
error: e$1
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
else result.awaitedRes = res;
|
|
30
|
-
}
|
|
31
|
-
return result.res;
|
|
32
|
-
};
|
|
33
|
-
const once_fn_mix = /* @__PURE__ */ obj_assign_props(once_fn, {
|
|
34
|
-
get source() {
|
|
35
|
-
return func;
|
|
36
|
-
},
|
|
37
|
-
get key() {
|
|
38
|
-
return result?.key;
|
|
39
|
-
},
|
|
40
|
-
get runned() {
|
|
41
|
-
return result != null;
|
|
42
|
-
},
|
|
43
|
-
get returnValue() {
|
|
44
|
-
return result?.res;
|
|
45
|
-
},
|
|
46
|
-
get awaitedReturnValue() {
|
|
47
|
-
return result?.awaitedRes;
|
|
48
|
-
},
|
|
49
|
-
reset() {
|
|
50
|
-
result = void 0;
|
|
51
|
-
},
|
|
52
|
-
rerun(...args) {
|
|
53
|
-
once_fn_mix.reset();
|
|
54
|
-
return once_fn_mix(...args);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return once_fn_mix;
|
|
58
|
-
};
|
|
59
|
-
const wrapSuccess = (result) => {
|
|
60
|
-
return Object.defineProperties([void 0, result], {
|
|
61
|
-
success: {
|
|
62
|
-
value: true,
|
|
63
|
-
writable: false,
|
|
64
|
-
enumerable: false,
|
|
65
|
-
configurable: true
|
|
66
|
-
},
|
|
67
|
-
result: {
|
|
68
|
-
value: result,
|
|
69
|
-
writable: false,
|
|
70
|
-
enumerable: false,
|
|
71
|
-
configurable: true
|
|
72
|
-
},
|
|
73
|
-
error: {
|
|
74
|
-
value: void 0,
|
|
75
|
-
writable: false,
|
|
76
|
-
enumerable: false,
|
|
77
|
-
configurable: true
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
const wrapError = (err, errorParser) => {
|
|
82
|
-
const error = errorParser ? errorParser(err) : err;
|
|
83
|
-
return Object.defineProperties([error, void 0], {
|
|
84
|
-
success: {
|
|
85
|
-
value: false,
|
|
86
|
-
writable: false,
|
|
87
|
-
enumerable: false,
|
|
88
|
-
configurable: true
|
|
89
|
-
},
|
|
90
|
-
result: {
|
|
91
|
-
value: void 0,
|
|
92
|
-
writable: false,
|
|
93
|
-
enumerable: false,
|
|
94
|
-
configurable: true
|
|
95
|
-
},
|
|
96
|
-
error: {
|
|
97
|
-
value: error,
|
|
98
|
-
writable: false,
|
|
99
|
-
enumerable: false,
|
|
100
|
-
configurable: true
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const func_catch = /* @__PURE__ */ Object.assign((fn, errorParser) => {
|
|
105
|
-
return Object.assign(function() {
|
|
106
|
-
try {
|
|
107
|
-
const res = fn.apply(this, arguments);
|
|
108
|
-
if (isPromiseLike(res)) return res.then((value) => wrapSuccess(value), (err) => wrapError(err, errorParser));
|
|
109
|
-
return wrapSuccess(res);
|
|
110
|
-
} catch (err) {
|
|
111
|
-
return wrapError(err, errorParser);
|
|
112
|
-
}
|
|
113
|
-
}, { catchType(errorParser$1) {
|
|
114
|
-
return func_catch(fn, errorParser$1);
|
|
115
|
-
} });
|
|
116
|
-
}, {
|
|
117
|
-
wrapSuccess,
|
|
118
|
-
wrapError
|
|
119
|
-
});
|
|
120
|
-
const timmers = {
|
|
121
|
-
timeout: (ms) => {
|
|
122
|
-
return (cb) => {
|
|
123
|
-
const ti = setTimeout(cb, ms);
|
|
124
|
-
return () => clearTimeout(ti);
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
raf: ((cb) => {
|
|
128
|
-
const ti = requestAnimationFrame(cb);
|
|
129
|
-
return () => cancelAnimationFrame(ti);
|
|
130
|
-
}),
|
|
131
|
-
microtask: ((cb) => {
|
|
132
|
-
let cancel = false;
|
|
133
|
-
queueMicrotask(() => {
|
|
134
|
-
if (cancel) return;
|
|
135
|
-
cb();
|
|
136
|
-
});
|
|
137
|
-
return () => {
|
|
138
|
-
cancel = true;
|
|
139
|
-
};
|
|
140
|
-
}),
|
|
141
|
-
eventTarget: (target, eventType, filter) => {
|
|
142
|
-
return (resolve) => {
|
|
143
|
-
let cb;
|
|
144
|
-
if (typeof filter === "function") {
|
|
145
|
-
cb = (event) => {
|
|
146
|
-
if (filter(event)) {
|
|
147
|
-
resolve(event);
|
|
148
|
-
target.removeEventListener(eventType, cb);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
target.addEventListener(eventType, cb);
|
|
152
|
-
} else {
|
|
153
|
-
cb = resolve;
|
|
154
|
-
target.addEventListener(eventType, cb, { once: true });
|
|
155
|
-
}
|
|
156
|
-
return () => target.removeEventListener(eventType, cb);
|
|
157
|
-
};
|
|
158
|
-
},
|
|
159
|
-
from: (ms) => {
|
|
160
|
-
return typeof ms === "number" ? ms <= 0 ? timmers.microtask : timmers.timeout(ms) : ms;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const abort_signal_merge = (..._signals) => {
|
|
164
|
-
const signals = _signals.filter((s$1) => s$1 != null);
|
|
165
|
-
if (signals.length === 0) return;
|
|
166
|
-
if (signals.length === 1) return signals[0];
|
|
167
|
-
const aborted_signals = signals.filter((signal) => signal.aborted);
|
|
168
|
-
if (aborted_signals.length === 1) return aborted_signals[0];
|
|
169
|
-
if (aborted_signals.length > 1) return AbortSignal.abort(new AggregateError(aborted_signals.map((signal) => signal.reason), "multi-signals are aborted"));
|
|
170
|
-
const aborter = new AbortController();
|
|
171
|
-
for (const signal of signals) signal.addEventListener("abort", (reason) => {
|
|
172
|
-
aborter.abort(reason);
|
|
173
|
-
});
|
|
174
|
-
return aborter.signal;
|
|
175
|
-
};
|
|
176
|
-
const func_throttle = (fn, wait = 0, options = {}) => {
|
|
177
|
-
const timmer = timmers.from(wait);
|
|
178
|
-
let clear;
|
|
179
|
-
let jobs = [];
|
|
180
|
-
let target;
|
|
181
|
-
return /* @__PURE__ */ obj_assign_props(function throttled(...args) {
|
|
182
|
-
const job = Promise.withResolvers();
|
|
183
|
-
if (clear == null) {
|
|
184
|
-
clear = timmer(target = async () => {
|
|
185
|
-
target = void 0;
|
|
186
|
-
if (!options.waitPromise) clear = void 0;
|
|
187
|
-
const res = await func_catch(() => fn.apply(this, args))();
|
|
188
|
-
if (options.waitPromise) clear = void 0;
|
|
189
|
-
if (res.success) for (const job$1 of jobs) job$1.resolve(res.result);
|
|
190
|
-
else for (const job$1 of jobs) job$1.reject(res.error);
|
|
191
|
-
jobs = [];
|
|
192
|
-
}, (reason) => {
|
|
193
|
-
for (const job$1 of jobs) job$1.reject(reason);
|
|
194
|
-
});
|
|
195
|
-
if (options.before) (async () => {
|
|
196
|
-
const res = await func_catch(() => fn.apply(this, args))();
|
|
197
|
-
if (res.success) job.resolve(res.result);
|
|
198
|
-
else job.reject(res.error);
|
|
199
|
-
})();
|
|
200
|
-
else jobs.push(job);
|
|
201
|
-
} else jobs.push(job);
|
|
202
|
-
return job.promise;
|
|
203
|
-
}, {
|
|
204
|
-
get isPending() {
|
|
205
|
-
return clear != null;
|
|
206
|
-
},
|
|
207
|
-
cancel() {
|
|
208
|
-
clear?.();
|
|
209
|
-
clear = void 0;
|
|
210
|
-
},
|
|
211
|
-
source: fn,
|
|
212
|
-
flush() {
|
|
213
|
-
clear?.();
|
|
214
|
-
clear = void 0;
|
|
215
|
-
target?.();
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
let restoredDirHandle;
|
|
220
|
-
const pickDirHandle = async () => {
|
|
221
|
-
const ti = setTimeout(() => {
|
|
222
|
-
console.log("%c等待用户动作: 请选择一个文件夹", styles.info);
|
|
223
|
-
}, 100);
|
|
224
|
-
try {
|
|
225
|
-
return await window.showDirectoryPicker({ mode: "readwrite" });
|
|
226
|
-
} catch (e$1) {
|
|
227
|
-
clearTimeout(ti);
|
|
228
|
-
if (e$1 instanceof Error) {
|
|
229
|
-
if (e$1.name === "SecurityError" || e$1.name === "NotAllowedError") {
|
|
230
|
-
console.log("%c请将鼠标聚焦到窗口视图中", styles.info);
|
|
231
|
-
await delay(1e3);
|
|
232
|
-
return pickDirHandle();
|
|
233
|
-
}
|
|
234
|
-
if (e$1.name === "AbortError") throw new DOMException("用户取消了文件夹选择", "AbortError");
|
|
235
|
-
}
|
|
236
|
-
throw e$1;
|
|
237
|
-
} finally {
|
|
238
|
-
clearTimeout(ti);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const prepareDirHandle = /* @__PURE__ */ func_remember(async () => {
|
|
242
|
-
const rootDirHandle = restoredDirHandle ?? await pickDirHandle();
|
|
243
|
-
console.log(`%c✅ 根文件夹已选择,用来作为内容导入导出的协作目录: %c${rootDirHandle.name}`, styles.success, styles.code);
|
|
244
|
-
return rootDirHandle;
|
|
245
|
-
});
|
|
246
|
-
const styles = {
|
|
247
|
-
header: "color: #4CAF50; font-size: 18px; font-weight: bold; border-bottom: 2px solid #4CAF50; padding-bottom: 5px;",
|
|
248
|
-
info: "color: #2196F3; font-style: italic;",
|
|
249
|
-
success: "color: #8BC34A; font-weight: bold;",
|
|
250
|
-
error: "color: #F44336; font-weight: bold;",
|
|
251
|
-
code: "background-color: #f0f0f0; color: #333; padding: 2px 4px; border-radius: 3px; font-family: monospace;",
|
|
252
|
-
warn: "color: #FFC107;"
|
|
253
|
-
};
|
|
254
|
-
const getTargetNamespace = () => location.pathname.split("/").at(-1);
|
|
255
|
-
const delay = (ms, { signal } = {}) => new Promise((resolve, reject) => {
|
|
256
|
-
const ti = setTimeout(resolve, ms);
|
|
257
|
-
signal?.addEventListener("abort", () => {
|
|
258
|
-
clearTimeout(ti);
|
|
259
|
-
reject(signal.reason);
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
const raf = () => new Promise((cb) => requestAnimationFrame(cb));
|
|
263
|
-
const untilRaf = async (condition, { timeout = 3e3, signal } = {}) => {
|
|
264
|
-
const timeoutSignal = createTimeoutSignal(timeout, signal, `untilRaf(${condition.toString()})`);
|
|
265
|
-
while (!await condition()) {
|
|
266
|
-
await raf();
|
|
267
|
-
timeoutSignal?.throwIfAborted();
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
const $ = (selectors) => document.querySelector(selectors);
|
|
271
|
-
const createTimeoutSignal = (timeout, signal, reason) => {
|
|
272
|
-
return abort_signal_merge(signal, timeout > 0 ? (() => {
|
|
273
|
-
const abortController = new AbortController();
|
|
274
|
-
const ti = setTimeout(() => {
|
|
275
|
-
abortController.abort(new Error(reason));
|
|
276
|
-
}, timeout);
|
|
277
|
-
signal?.addEventListener("abort", () => clearTimeout(ti));
|
|
278
|
-
return abortController.signal;
|
|
279
|
-
})() : null);
|
|
280
|
-
};
|
|
281
|
-
const while$ = async (selectors, options = {}) => {
|
|
282
|
-
const { timeout = 3e3, signal } = options;
|
|
283
|
-
const timeoutSignal = createTimeoutSignal(timeout, signal, `while$(${selectors})`);
|
|
284
|
-
while (true) {
|
|
285
|
-
const ele = $(selectors);
|
|
286
|
-
if (ele != null) return ele;
|
|
287
|
-
await raf();
|
|
288
|
-
timeoutSignal?.throwIfAborted();
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
const $$ = (selectors) => document.querySelectorAll(selectors);
|
|
292
|
-
const fillFunctionCall = async (signal) => {
|
|
293
|
-
if (signal?.aborted) return;
|
|
294
|
-
const rootDirHandle = await prepareDirHandle();
|
|
295
|
-
const targetName = getTargetNamespace();
|
|
296
|
-
const keys = await arrayFromAsync(rootDirHandle.keys());
|
|
297
|
-
for (const callTaskname of keys.filter((key) => key.endsWith(".function_call.json") && key.startsWith(targetName))) {
|
|
298
|
-
if (signal?.aborted) return;
|
|
299
|
-
const taskFile = await (await rootDirHandle.getFileHandle(callTaskname)).getFile();
|
|
300
|
-
const taskResponse = JSON.parse(await taskFile.text());
|
|
301
|
-
if (!taskResponse.output) return;
|
|
302
|
-
const lastBtn = [...(await while$("ms-prompt-scrollbar", { signal })).querySelectorAll("button")].at(-1);
|
|
303
|
-
if (lastBtn) {
|
|
304
|
-
lastBtn.click();
|
|
305
|
-
await untilRaf(() => lastBtn.classList.contains("ms-button-active"));
|
|
306
|
-
}
|
|
307
|
-
const functionCallEles = [...$$("ms-function-call-chunk")];
|
|
308
|
-
if (functionCallEles.length === 0) {
|
|
309
|
-
console.error("找不到任何可以进行function-call的输入");
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
const functionCallEle = functionCallEles.find((ele) => ele.querySelector("mat-panel-title")?.textContent?.trim() === `function ${taskResponse.name}` && JSON.stringify(JSON.parse(ele.querySelector("code")?.textContent ?? "{}")) === taskResponse.parameters);
|
|
313
|
-
if (null == functionCallEle) {
|
|
314
|
-
console.warn(`找不到指定的可以进行function-call-ele: ${taskResponse.name}(${taskResponse.parameters})`);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const responseTextEle = functionCallEle.querySelector("input[placeholder=\"Enter function response\"]");
|
|
318
|
-
if (!responseTextEle || responseTextEle.disabled) return;
|
|
319
|
-
responseTextEle.value = typeof taskResponse.output === "string" ? taskResponse.output : JSON.stringify(taskResponse.output, null, 2);
|
|
320
|
-
responseTextEle.dispatchEvent(new Event("input"));
|
|
321
|
-
const buttonEle = functionCallEle.querySelector("form button");
|
|
322
|
-
if (!buttonEle) return;
|
|
323
|
-
await untilRaf(() => buttonEle.ariaDisabled === "false");
|
|
324
|
-
buttonEle.click();
|
|
325
|
-
await rootDirHandle.removeEntry(callTaskname);
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
const syncInput = async (signal, fps = 3) => {
|
|
329
|
-
if (signal?.aborted) {
|
|
330
|
-
console.log("JIXO BROWSER: syncOutput aborted before starting.");
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
signal?.addEventListener("abort", () => {
|
|
334
|
-
console.log("JIXO BROWSER: syncInput aborted.");
|
|
335
|
-
});
|
|
336
|
-
while (!signal?.aborted) {
|
|
337
|
-
await fillFunctionCall(signal);
|
|
338
|
-
await delay(1e3 / fps);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
async function arrayFromAsync(iter) {
|
|
342
|
-
const arr = [];
|
|
343
|
-
for await (const i$1 of iter) arr.push(i$1);
|
|
344
|
-
return arr;
|
|
345
|
-
}
|
|
346
|
-
const t = Symbol.for("@ts-pattern/matcher"), e = Symbol.for("@ts-pattern/isVariadic"), n = "@ts-pattern/anonymous-select-key", r = (t$1) => Boolean(t$1 && "object" == typeof t$1), i = (e$1) => e$1 && !!e$1[t], o = (n$1, s$1, c$1) => {
|
|
347
|
-
if (i(n$1)) {
|
|
348
|
-
const e$1 = n$1[t](), { matched: r$1, selections: i$1 } = e$1.match(s$1);
|
|
349
|
-
return r$1 && i$1 && Object.keys(i$1).forEach((t$1) => c$1(t$1, i$1[t$1])), r$1;
|
|
350
|
-
}
|
|
351
|
-
if (r(n$1)) {
|
|
352
|
-
if (!r(s$1)) return !1;
|
|
353
|
-
if (Array.isArray(n$1)) {
|
|
354
|
-
if (!Array.isArray(s$1)) return !1;
|
|
355
|
-
let t$1 = [], r$1 = [], a$1 = [];
|
|
356
|
-
for (const o$1 of n$1.keys()) {
|
|
357
|
-
const s$2 = n$1[o$1];
|
|
358
|
-
i(s$2) && s$2[e] ? a$1.push(s$2) : a$1.length ? r$1.push(s$2) : t$1.push(s$2);
|
|
359
|
-
}
|
|
360
|
-
if (a$1.length) {
|
|
361
|
-
if (a$1.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
|
|
362
|
-
if (s$1.length < t$1.length + r$1.length) return !1;
|
|
363
|
-
const e$1 = s$1.slice(0, t$1.length), n$2 = 0 === r$1.length ? [] : s$1.slice(-r$1.length), i$1 = s$1.slice(t$1.length, 0 === r$1.length ? Infinity : -r$1.length);
|
|
364
|
-
return t$1.every((t$2, n$3) => o(t$2, e$1[n$3], c$1)) && r$1.every((t$2, e$2) => o(t$2, n$2[e$2], c$1)) && (0 === a$1.length || o(a$1[0], i$1, c$1));
|
|
365
|
-
}
|
|
366
|
-
return n$1.length === s$1.length && n$1.every((t$2, e$1) => o(t$2, s$1[e$1], c$1));
|
|
367
|
-
}
|
|
368
|
-
return Reflect.ownKeys(n$1).every((e$1) => {
|
|
369
|
-
const r$1 = n$1[e$1];
|
|
370
|
-
return (e$1 in s$1 || i(a$1 = r$1) && "optional" === a$1[t]().matcherType) && o(r$1, s$1[e$1], c$1);
|
|
371
|
-
var a$1;
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
return Object.is(s$1, n$1);
|
|
375
|
-
}, s = (e$1) => {
|
|
376
|
-
var n$1, o$1, a$1;
|
|
377
|
-
return r(e$1) ? i(e$1) ? null != (n$1 = null == (o$1 = (a$1 = e$1[t]()).getSelectionKeys) ? void 0 : o$1.call(a$1)) ? n$1 : [] : Array.isArray(e$1) ? c(e$1, s) : c(Object.values(e$1), s) : [];
|
|
378
|
-
}, c = (t$1, e$1) => t$1.reduce((t$2, n$1) => t$2.concat(e$1(n$1)), []);
|
|
379
|
-
function a(...t$1) {
|
|
380
|
-
if (1 === t$1.length) {
|
|
381
|
-
const [e$1] = t$1;
|
|
382
|
-
return (t$2) => o(e$1, t$2, () => {});
|
|
383
|
-
}
|
|
384
|
-
if (2 === t$1.length) {
|
|
385
|
-
const [e$1, n$1] = t$1;
|
|
386
|
-
return o(e$1, n$1, () => {});
|
|
387
|
-
}
|
|
388
|
-
throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t$1.length}.`);
|
|
389
|
-
}
|
|
390
|
-
function u(t$1) {
|
|
391
|
-
return Object.assign(t$1, {
|
|
392
|
-
optional: () => l(t$1),
|
|
393
|
-
and: (e$1) => m(t$1, e$1),
|
|
394
|
-
or: (e$1) => d(t$1, e$1),
|
|
395
|
-
select: (e$1) => void 0 === e$1 ? y(t$1) : y(e$1, t$1)
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
function h(t$1) {
|
|
399
|
-
return Object.assign(((t$2) => Object.assign(t$2, { [Symbol.iterator]() {
|
|
400
|
-
let n$1 = 0;
|
|
401
|
-
const r$1 = [{
|
|
402
|
-
value: Object.assign(t$2, { [e]: !0 }),
|
|
403
|
-
done: !1
|
|
404
|
-
}, {
|
|
405
|
-
done: !0,
|
|
406
|
-
value: void 0
|
|
407
|
-
}];
|
|
408
|
-
return { next: () => {
|
|
409
|
-
var t$3;
|
|
410
|
-
return null != (t$3 = r$1[n$1++]) ? t$3 : r$1.at(-1);
|
|
411
|
-
} };
|
|
412
|
-
} }))(t$1), {
|
|
413
|
-
optional: () => h(l(t$1)),
|
|
414
|
-
select: (e$1) => h(void 0 === e$1 ? y(t$1) : y(e$1, t$1))
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
function l(e$1) {
|
|
418
|
-
return u({ [t]: () => ({
|
|
419
|
-
match: (t$1) => {
|
|
420
|
-
let n$1 = {};
|
|
421
|
-
const r$1 = (t$2, e$2) => {
|
|
422
|
-
n$1[t$2] = e$2;
|
|
423
|
-
};
|
|
424
|
-
return void 0 === t$1 ? (s(e$1).forEach((t$2) => r$1(t$2, void 0)), {
|
|
425
|
-
matched: !0,
|
|
426
|
-
selections: n$1
|
|
427
|
-
}) : {
|
|
428
|
-
matched: o(e$1, t$1, r$1),
|
|
429
|
-
selections: n$1
|
|
430
|
-
};
|
|
431
|
-
},
|
|
432
|
-
getSelectionKeys: () => s(e$1),
|
|
433
|
-
matcherType: "optional"
|
|
434
|
-
}) });
|
|
435
|
-
}
|
|
436
|
-
const f = (t$1, e$1) => {
|
|
437
|
-
for (const n$1 of t$1) if (!e$1(n$1)) return !1;
|
|
438
|
-
return !0;
|
|
439
|
-
}, g = (t$1, e$1) => {
|
|
440
|
-
for (const [n$1, r$1] of t$1.entries()) if (!e$1(r$1, n$1)) return !1;
|
|
441
|
-
return !0;
|
|
442
|
-
};
|
|
443
|
-
function m(...e$1) {
|
|
444
|
-
return u({ [t]: () => ({
|
|
445
|
-
match: (t$1) => {
|
|
446
|
-
let n$1 = {};
|
|
447
|
-
const r$1 = (t$2, e$2) => {
|
|
448
|
-
n$1[t$2] = e$2;
|
|
449
|
-
};
|
|
450
|
-
return {
|
|
451
|
-
matched: e$1.every((e$2) => o(e$2, t$1, r$1)),
|
|
452
|
-
selections: n$1
|
|
453
|
-
};
|
|
454
|
-
},
|
|
455
|
-
getSelectionKeys: () => c(e$1, s),
|
|
456
|
-
matcherType: "and"
|
|
457
|
-
}) });
|
|
458
|
-
}
|
|
459
|
-
function d(...e$1) {
|
|
460
|
-
return u({ [t]: () => ({
|
|
461
|
-
match: (t$1) => {
|
|
462
|
-
let n$1 = {};
|
|
463
|
-
const r$1 = (t$2, e$2) => {
|
|
464
|
-
n$1[t$2] = e$2;
|
|
465
|
-
};
|
|
466
|
-
return c(e$1, s).forEach((t$2) => r$1(t$2, void 0)), {
|
|
467
|
-
matched: e$1.some((e$2) => o(e$2, t$1, r$1)),
|
|
468
|
-
selections: n$1
|
|
469
|
-
};
|
|
470
|
-
},
|
|
471
|
-
getSelectionKeys: () => c(e$1, s),
|
|
472
|
-
matcherType: "or"
|
|
473
|
-
}) });
|
|
474
|
-
}
|
|
475
|
-
function p(e$1) {
|
|
476
|
-
return { [t]: () => ({ match: (t$1) => ({ matched: Boolean(e$1(t$1)) }) }) };
|
|
477
|
-
}
|
|
478
|
-
function y(...e$1) {
|
|
479
|
-
const r$1 = "string" == typeof e$1[0] ? e$1[0] : void 0, i$1 = 2 === e$1.length ? e$1[1] : "string" == typeof e$1[0] ? void 0 : e$1[0];
|
|
480
|
-
return u({ [t]: () => ({
|
|
481
|
-
match: (t$1) => {
|
|
482
|
-
let e$2 = { [null != r$1 ? r$1 : n]: t$1 };
|
|
483
|
-
return {
|
|
484
|
-
matched: void 0 === i$1 || o(i$1, t$1, (t$2, n$1) => {
|
|
485
|
-
e$2[t$2] = n$1;
|
|
486
|
-
}),
|
|
487
|
-
selections: e$2
|
|
488
|
-
};
|
|
489
|
-
},
|
|
490
|
-
getSelectionKeys: () => [null != r$1 ? r$1 : n].concat(void 0 === i$1 ? [] : s(i$1))
|
|
491
|
-
}) });
|
|
492
|
-
}
|
|
493
|
-
function v(t$1) {
|
|
494
|
-
return "number" == typeof t$1;
|
|
495
|
-
}
|
|
496
|
-
function b(t$1) {
|
|
497
|
-
return "string" == typeof t$1;
|
|
498
|
-
}
|
|
499
|
-
function w(t$1) {
|
|
500
|
-
return "bigint" == typeof t$1;
|
|
501
|
-
}
|
|
502
|
-
const S = u(p(function(t$1) {
|
|
503
|
-
return !0;
|
|
504
|
-
})), O = S, j = (t$1) => Object.assign(u(t$1), {
|
|
505
|
-
startsWith: (e$1) => {
|
|
506
|
-
return j(m(t$1, (n$1 = e$1, p((t$2) => b(t$2) && t$2.startsWith(n$1)))));
|
|
507
|
-
var n$1;
|
|
508
|
-
},
|
|
509
|
-
endsWith: (e$1) => {
|
|
510
|
-
return j(m(t$1, (n$1 = e$1, p((t$2) => b(t$2) && t$2.endsWith(n$1)))));
|
|
511
|
-
var n$1;
|
|
512
|
-
},
|
|
513
|
-
minLength: (e$1) => j(m(t$1, ((t$2) => p((e$2) => b(e$2) && e$2.length >= t$2))(e$1))),
|
|
514
|
-
length: (e$1) => j(m(t$1, ((t$2) => p((e$2) => b(e$2) && e$2.length === t$2))(e$1))),
|
|
515
|
-
maxLength: (e$1) => j(m(t$1, ((t$2) => p((e$2) => b(e$2) && e$2.length <= t$2))(e$1))),
|
|
516
|
-
includes: (e$1) => {
|
|
517
|
-
return j(m(t$1, (n$1 = e$1, p((t$2) => b(t$2) && t$2.includes(n$1)))));
|
|
518
|
-
var n$1;
|
|
519
|
-
},
|
|
520
|
-
regex: (e$1) => {
|
|
521
|
-
return j(m(t$1, (n$1 = e$1, p((t$2) => b(t$2) && Boolean(t$2.match(n$1))))));
|
|
522
|
-
var n$1;
|
|
523
|
-
}
|
|
524
|
-
}), K = j(p(b)), x = (t$1) => Object.assign(u(t$1), {
|
|
525
|
-
between: (e$1, n$1) => x(m(t$1, ((t$2, e$2) => p((n$2) => v(n$2) && t$2 <= n$2 && e$2 >= n$2))(e$1, n$1))),
|
|
526
|
-
lt: (e$1) => x(m(t$1, ((t$2) => p((e$2) => v(e$2) && e$2 < t$2))(e$1))),
|
|
527
|
-
gt: (e$1) => x(m(t$1, ((t$2) => p((e$2) => v(e$2) && e$2 > t$2))(e$1))),
|
|
528
|
-
lte: (e$1) => x(m(t$1, ((t$2) => p((e$2) => v(e$2) && e$2 <= t$2))(e$1))),
|
|
529
|
-
gte: (e$1) => x(m(t$1, ((t$2) => p((e$2) => v(e$2) && e$2 >= t$2))(e$1))),
|
|
530
|
-
int: () => x(m(t$1, p((t$2) => v(t$2) && Number.isInteger(t$2)))),
|
|
531
|
-
finite: () => x(m(t$1, p((t$2) => v(t$2) && Number.isFinite(t$2)))),
|
|
532
|
-
positive: () => x(m(t$1, p((t$2) => v(t$2) && t$2 > 0))),
|
|
533
|
-
negative: () => x(m(t$1, p((t$2) => v(t$2) && t$2 < 0)))
|
|
534
|
-
}), E = x(p(v)), A = (t$1) => Object.assign(u(t$1), {
|
|
535
|
-
between: (e$1, n$1) => A(m(t$1, ((t$2, e$2) => p((n$2) => w(n$2) && t$2 <= n$2 && e$2 >= n$2))(e$1, n$1))),
|
|
536
|
-
lt: (e$1) => A(m(t$1, ((t$2) => p((e$2) => w(e$2) && e$2 < t$2))(e$1))),
|
|
537
|
-
gt: (e$1) => A(m(t$1, ((t$2) => p((e$2) => w(e$2) && e$2 > t$2))(e$1))),
|
|
538
|
-
lte: (e$1) => A(m(t$1, ((t$2) => p((e$2) => w(e$2) && e$2 <= t$2))(e$1))),
|
|
539
|
-
gte: (e$1) => A(m(t$1, ((t$2) => p((e$2) => w(e$2) && e$2 >= t$2))(e$1))),
|
|
540
|
-
positive: () => A(m(t$1, p((t$2) => w(t$2) && t$2 > 0))),
|
|
541
|
-
negative: () => A(m(t$1, p((t$2) => w(t$2) && t$2 < 0)))
|
|
542
|
-
}), P = A(p(w)), T = u(p(function(t$1) {
|
|
543
|
-
return "boolean" == typeof t$1;
|
|
544
|
-
})), B = u(p(function(t$1) {
|
|
545
|
-
return "symbol" == typeof t$1;
|
|
546
|
-
})), _ = u(p(function(t$1) {
|
|
547
|
-
return null == t$1;
|
|
548
|
-
})), k = u(p(function(t$1) {
|
|
549
|
-
return null != t$1;
|
|
550
|
-
}));
|
|
551
|
-
var N = {
|
|
552
|
-
__proto__: null,
|
|
553
|
-
matcher: t,
|
|
554
|
-
optional: l,
|
|
555
|
-
array: function(...e$1) {
|
|
556
|
-
return h({ [t]: () => ({
|
|
557
|
-
match: (t$1) => {
|
|
558
|
-
if (!Array.isArray(t$1)) return { matched: !1 };
|
|
559
|
-
if (0 === e$1.length) return { matched: !0 };
|
|
560
|
-
const n$1 = e$1[0];
|
|
561
|
-
let r$1 = {};
|
|
562
|
-
if (0 === t$1.length) return s(n$1).forEach((t$2) => {
|
|
563
|
-
r$1[t$2] = [];
|
|
564
|
-
}), {
|
|
565
|
-
matched: !0,
|
|
566
|
-
selections: r$1
|
|
567
|
-
};
|
|
568
|
-
const i$1 = (t$2, e$2) => {
|
|
569
|
-
r$1[t$2] = (r$1[t$2] || []).concat([e$2]);
|
|
570
|
-
};
|
|
571
|
-
return {
|
|
572
|
-
matched: t$1.every((t$2) => o(n$1, t$2, i$1)),
|
|
573
|
-
selections: r$1
|
|
574
|
-
};
|
|
575
|
-
},
|
|
576
|
-
getSelectionKeys: () => 0 === e$1.length ? [] : s(e$1[0])
|
|
577
|
-
}) });
|
|
578
|
-
},
|
|
579
|
-
set: function(...e$1) {
|
|
580
|
-
return u({ [t]: () => ({
|
|
581
|
-
match: (t$1) => {
|
|
582
|
-
if (!(t$1 instanceof Set)) return { matched: !1 };
|
|
583
|
-
let n$1 = {};
|
|
584
|
-
if (0 === t$1.size) return {
|
|
585
|
-
matched: !0,
|
|
586
|
-
selections: n$1
|
|
587
|
-
};
|
|
588
|
-
if (0 === e$1.length) return { matched: !0 };
|
|
589
|
-
const r$1 = (t$2, e$2) => {
|
|
590
|
-
n$1[t$2] = (n$1[t$2] || []).concat([e$2]);
|
|
591
|
-
}, i$1 = e$1[0];
|
|
592
|
-
return {
|
|
593
|
-
matched: f(t$1, (t$2) => o(i$1, t$2, r$1)),
|
|
594
|
-
selections: n$1
|
|
595
|
-
};
|
|
596
|
-
},
|
|
597
|
-
getSelectionKeys: () => 0 === e$1.length ? [] : s(e$1[0])
|
|
598
|
-
}) });
|
|
599
|
-
},
|
|
600
|
-
map: function(...e$1) {
|
|
601
|
-
return u({ [t]: () => ({
|
|
602
|
-
match: (t$1) => {
|
|
603
|
-
if (!(t$1 instanceof Map)) return { matched: !1 };
|
|
604
|
-
let n$1 = {};
|
|
605
|
-
if (0 === t$1.size) return {
|
|
606
|
-
matched: !0,
|
|
607
|
-
selections: n$1
|
|
608
|
-
};
|
|
609
|
-
const r$1 = (t$2, e$2) => {
|
|
610
|
-
n$1[t$2] = (n$1[t$2] || []).concat([e$2]);
|
|
611
|
-
};
|
|
612
|
-
if (0 === e$1.length) return { matched: !0 };
|
|
613
|
-
var i$1;
|
|
614
|
-
if (1 === e$1.length) throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null == (i$1 = e$1[0]) ? void 0 : i$1.toString()}`);
|
|
615
|
-
const [s$1, c$1] = e$1;
|
|
616
|
-
return {
|
|
617
|
-
matched: g(t$1, (t$2, e$2) => {
|
|
618
|
-
const n$2 = o(s$1, e$2, r$1), i$2 = o(c$1, t$2, r$1);
|
|
619
|
-
return n$2 && i$2;
|
|
620
|
-
}),
|
|
621
|
-
selections: n$1
|
|
622
|
-
};
|
|
623
|
-
},
|
|
624
|
-
getSelectionKeys: () => 0 === e$1.length ? [] : [...s(e$1[0]), ...s(e$1[1])]
|
|
625
|
-
}) });
|
|
626
|
-
},
|
|
627
|
-
intersection: m,
|
|
628
|
-
union: d,
|
|
629
|
-
not: function(e$1) {
|
|
630
|
-
return u({ [t]: () => ({
|
|
631
|
-
match: (t$1) => ({ matched: !o(e$1, t$1, () => {}) }),
|
|
632
|
-
getSelectionKeys: () => [],
|
|
633
|
-
matcherType: "not"
|
|
634
|
-
}) });
|
|
635
|
-
},
|
|
636
|
-
when: p,
|
|
637
|
-
select: y,
|
|
638
|
-
any: S,
|
|
639
|
-
_: O,
|
|
640
|
-
string: K,
|
|
641
|
-
number: E,
|
|
642
|
-
bigint: P,
|
|
643
|
-
boolean: T,
|
|
644
|
-
symbol: B,
|
|
645
|
-
nullish: _,
|
|
646
|
-
nonNullable: k,
|
|
647
|
-
instanceOf: function(t$1) {
|
|
648
|
-
return u(p(function(t$2) {
|
|
649
|
-
return (e$1) => e$1 instanceof t$2;
|
|
650
|
-
}(t$1)));
|
|
651
|
-
},
|
|
652
|
-
shape: function(t$1) {
|
|
653
|
-
return u(p(a(t$1)));
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
var W = class extends Error {
|
|
657
|
-
constructor(t$1) {
|
|
658
|
-
let e$1;
|
|
659
|
-
try {
|
|
660
|
-
e$1 = JSON.stringify(t$1);
|
|
661
|
-
} catch (n$1) {
|
|
662
|
-
e$1 = t$1;
|
|
663
|
-
}
|
|
664
|
-
super(`Pattern matching error: no pattern matches value ${e$1}`), this.input = void 0, this.input = t$1;
|
|
665
|
-
}
|
|
666
|
-
};
|
|
667
|
-
const $$1 = {
|
|
668
|
-
matched: !1,
|
|
669
|
-
value: void 0
|
|
670
|
-
};
|
|
671
|
-
function z(t$1) {
|
|
672
|
-
return new I(t$1, $$1);
|
|
673
|
-
}
|
|
674
|
-
var I = class I {
|
|
675
|
-
constructor(t$1, e$1) {
|
|
676
|
-
this.input = void 0, this.state = void 0, this.input = t$1, this.state = e$1;
|
|
677
|
-
}
|
|
678
|
-
with(...t$1) {
|
|
679
|
-
if (this.state.matched) return this;
|
|
680
|
-
const e$1 = t$1[t$1.length - 1], r$1 = [t$1[0]];
|
|
681
|
-
let i$1;
|
|
682
|
-
3 === t$1.length && "function" == typeof t$1[1] ? i$1 = t$1[1] : t$1.length > 2 && r$1.push(...t$1.slice(1, t$1.length - 1));
|
|
683
|
-
let s$1 = !1, c$1 = {};
|
|
684
|
-
const a$1 = (t$2, e$2) => {
|
|
685
|
-
s$1 = !0, c$1[t$2] = e$2;
|
|
686
|
-
}, u$1 = !r$1.some((t$2) => o(t$2, this.input, a$1)) || i$1 && !Boolean(i$1(this.input)) ? $$1 : {
|
|
687
|
-
matched: !0,
|
|
688
|
-
value: e$1(s$1 ? n in c$1 ? c$1[n] : c$1 : this.input, this.input)
|
|
689
|
-
};
|
|
690
|
-
return new I(this.input, u$1);
|
|
691
|
-
}
|
|
692
|
-
when(t$1, e$1) {
|
|
693
|
-
if (this.state.matched) return this;
|
|
694
|
-
const n$1 = Boolean(t$1(this.input));
|
|
695
|
-
return new I(this.input, n$1 ? {
|
|
696
|
-
matched: !0,
|
|
697
|
-
value: e$1(this.input, this.input)
|
|
698
|
-
} : $$1);
|
|
699
|
-
}
|
|
700
|
-
otherwise(t$1) {
|
|
701
|
-
return this.state.matched ? this.state.value : t$1(this.input);
|
|
702
|
-
}
|
|
703
|
-
exhaustive(t$1 = L) {
|
|
704
|
-
return this.state.matched ? this.state.value : t$1(this.input);
|
|
705
|
-
}
|
|
706
|
-
run() {
|
|
707
|
-
return this.exhaustive();
|
|
708
|
-
}
|
|
709
|
-
returnType() {
|
|
710
|
-
return this;
|
|
711
|
-
}
|
|
712
|
-
narrow() {
|
|
713
|
-
return this;
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
function L(t$1) {
|
|
717
|
-
throw new W(t$1);
|
|
718
|
-
}
|
|
719
|
-
Object.freeze({ status: "aborted" });
|
|
720
|
-
function $constructor(name, initializer$1, params) {
|
|
721
|
-
function init(inst, def) {
|
|
722
|
-
var _a;
|
|
723
|
-
Object.defineProperty(inst, "_zod", {
|
|
724
|
-
value: inst._zod ?? {},
|
|
725
|
-
enumerable: false
|
|
726
|
-
});
|
|
727
|
-
(_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
|
|
728
|
-
inst._zod.traits.add(name);
|
|
729
|
-
initializer$1(inst, def);
|
|
730
|
-
for (const k$1 in _$1.prototype) if (!(k$1 in inst)) Object.defineProperty(inst, k$1, { value: _$1.prototype[k$1].bind(inst) });
|
|
731
|
-
inst._zod.constr = _$1;
|
|
732
|
-
inst._zod.def = def;
|
|
733
|
-
}
|
|
734
|
-
const Parent = params?.Parent ?? Object;
|
|
735
|
-
class Definition extends Parent {}
|
|
736
|
-
Object.defineProperty(Definition, "name", { value: name });
|
|
737
|
-
function _$1(def) {
|
|
738
|
-
var _a;
|
|
739
|
-
const inst = params?.Parent ? new Definition() : this;
|
|
740
|
-
init(inst, def);
|
|
741
|
-
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
742
|
-
for (const fn of inst._zod.deferred) fn();
|
|
743
|
-
return inst;
|
|
744
|
-
}
|
|
745
|
-
Object.defineProperty(_$1, "init", { value: init });
|
|
746
|
-
Object.defineProperty(_$1, Symbol.hasInstance, { value: (inst) => {
|
|
747
|
-
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
748
|
-
return inst?._zod?.traits?.has(name);
|
|
749
|
-
} });
|
|
750
|
-
Object.defineProperty(_$1, "name", { value: name });
|
|
751
|
-
return _$1;
|
|
752
|
-
}
|
|
753
|
-
var $ZodAsyncError = class extends Error {
|
|
754
|
-
constructor() {
|
|
755
|
-
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
756
|
-
}
|
|
757
|
-
};
|
|
758
|
-
const globalConfig = {};
|
|
759
|
-
function config(newConfig) {
|
|
760
|
-
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
761
|
-
return globalConfig;
|
|
762
|
-
}
|
|
763
|
-
function jsonStringifyReplacer(_$1, value) {
|
|
764
|
-
if (typeof value === "bigint") return value.toString();
|
|
765
|
-
return value;
|
|
766
|
-
}
|
|
767
|
-
function cached(getter) {
|
|
768
|
-
return { get value() {
|
|
769
|
-
{
|
|
770
|
-
const value = getter();
|
|
771
|
-
Object.defineProperty(this, "value", { value });
|
|
772
|
-
return value;
|
|
773
|
-
}
|
|
774
|
-
throw new Error("cached value already set");
|
|
775
|
-
} };
|
|
776
|
-
}
|
|
777
|
-
function cleanRegex(source) {
|
|
778
|
-
const start = source.startsWith("^") ? 1 : 0;
|
|
779
|
-
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
780
|
-
return source.slice(start, end);
|
|
781
|
-
}
|
|
782
|
-
const EVALUATING = Symbol("evaluating");
|
|
783
|
-
function defineLazy(object$1, key, getter) {
|
|
784
|
-
let value = void 0;
|
|
785
|
-
Object.defineProperty(object$1, key, {
|
|
786
|
-
get() {
|
|
787
|
-
if (value === EVALUATING) return;
|
|
788
|
-
if (value === void 0) {
|
|
789
|
-
value = EVALUATING;
|
|
790
|
-
value = getter();
|
|
791
|
-
}
|
|
792
|
-
return value;
|
|
793
|
-
},
|
|
794
|
-
set(v$1) {
|
|
795
|
-
Object.defineProperty(object$1, key, { value: v$1 });
|
|
796
|
-
},
|
|
797
|
-
configurable: true
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
function assignProp(target, prop, value) {
|
|
801
|
-
Object.defineProperty(target, prop, {
|
|
802
|
-
value,
|
|
803
|
-
writable: true,
|
|
804
|
-
enumerable: true,
|
|
805
|
-
configurable: true
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
|
|
809
|
-
function isObject(data) {
|
|
810
|
-
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
811
|
-
}
|
|
812
|
-
cached(() => {
|
|
813
|
-
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
814
|
-
try {
|
|
815
|
-
new Function("");
|
|
816
|
-
return true;
|
|
817
|
-
} catch (_$1) {
|
|
818
|
-
return false;
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
function clone(inst, def, params) {
|
|
822
|
-
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
823
|
-
if (!def || params?.parent) cl._zod.parent = inst;
|
|
824
|
-
return cl;
|
|
825
|
-
}
|
|
826
|
-
function normalizeParams(_params) {
|
|
827
|
-
const params = _params;
|
|
828
|
-
if (!params) return {};
|
|
829
|
-
if (typeof params === "string") return { error: () => params };
|
|
830
|
-
if (params?.message !== void 0) {
|
|
831
|
-
if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
|
|
832
|
-
params.error = params.message;
|
|
833
|
-
}
|
|
834
|
-
delete params.message;
|
|
835
|
-
if (typeof params.error === "string") return {
|
|
836
|
-
...params,
|
|
837
|
-
error: () => params.error
|
|
838
|
-
};
|
|
839
|
-
return params;
|
|
840
|
-
}
|
|
841
|
-
function optionalKeys(shape) {
|
|
842
|
-
return Object.keys(shape).filter((k$1) => {
|
|
843
|
-
return shape[k$1]._zod.optin === "optional" && shape[k$1]._zod.optout === "optional";
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, -Number.MAX_VALUE, Number.MAX_VALUE;
|
|
847
|
-
function aborted(x$1, startIndex = 0) {
|
|
848
|
-
if (x$1.aborted === true) return true;
|
|
849
|
-
for (let i$1 = startIndex; i$1 < x$1.issues.length; i$1++) if (x$1.issues[i$1]?.continue !== true) return true;
|
|
850
|
-
return false;
|
|
851
|
-
}
|
|
852
|
-
function prefixIssues(path, issues) {
|
|
853
|
-
return issues.map((iss) => {
|
|
854
|
-
var _a;
|
|
855
|
-
(_a = iss).path ?? (_a.path = []);
|
|
856
|
-
iss.path.unshift(path);
|
|
857
|
-
return iss;
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
function unwrapMessage(message) {
|
|
861
|
-
return typeof message === "string" ? message : message?.message;
|
|
862
|
-
}
|
|
863
|
-
function finalizeIssue(iss, ctx, config$1) {
|
|
864
|
-
const full = {
|
|
865
|
-
...iss,
|
|
866
|
-
path: iss.path ?? []
|
|
867
|
-
};
|
|
868
|
-
if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
|
|
869
|
-
delete full.inst;
|
|
870
|
-
delete full.continue;
|
|
871
|
-
if (!ctx?.reportInput) delete full.input;
|
|
872
|
-
return full;
|
|
873
|
-
}
|
|
874
|
-
const initializer = (inst, def) => {
|
|
875
|
-
inst.name = "$ZodError";
|
|
876
|
-
Object.defineProperty(inst, "_zod", {
|
|
877
|
-
value: inst._zod,
|
|
878
|
-
enumerable: false
|
|
879
|
-
});
|
|
880
|
-
Object.defineProperty(inst, "issues", {
|
|
881
|
-
value: def,
|
|
882
|
-
enumerable: false
|
|
883
|
-
});
|
|
884
|
-
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
885
|
-
Object.defineProperty(inst, "toString", {
|
|
886
|
-
value: () => inst.message,
|
|
887
|
-
enumerable: false
|
|
888
|
-
});
|
|
889
|
-
};
|
|
890
|
-
const $ZodError = $constructor("$ZodError", initializer);
|
|
891
|
-
const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
892
|
-
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
893
|
-
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
894
|
-
const result = schema._zod.run({
|
|
895
|
-
value,
|
|
896
|
-
issues: []
|
|
897
|
-
}, ctx);
|
|
898
|
-
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
899
|
-
if (result.issues.length) {
|
|
900
|
-
const e$1 = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
901
|
-
captureStackTrace(e$1, _params?.callee);
|
|
902
|
-
throw e$1;
|
|
903
|
-
}
|
|
904
|
-
return result.value;
|
|
905
|
-
};
|
|
906
|
-
const parse = /* @__PURE__ */ _parse($ZodRealError);
|
|
907
|
-
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
908
|
-
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
909
|
-
let result = schema._zod.run({
|
|
910
|
-
value,
|
|
911
|
-
issues: []
|
|
912
|
-
}, ctx);
|
|
913
|
-
if (result instanceof Promise) result = await result;
|
|
914
|
-
if (result.issues.length) {
|
|
915
|
-
const e$1 = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
916
|
-
captureStackTrace(e$1, params?.callee);
|
|
917
|
-
throw e$1;
|
|
918
|
-
}
|
|
919
|
-
return result.value;
|
|
920
|
-
};
|
|
921
|
-
const parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
|
|
922
|
-
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
923
|
-
const ctx = _ctx ? {
|
|
924
|
-
..._ctx,
|
|
925
|
-
async: false
|
|
926
|
-
} : { async: false };
|
|
927
|
-
const result = schema._zod.run({
|
|
928
|
-
value,
|
|
929
|
-
issues: []
|
|
930
|
-
}, ctx);
|
|
931
|
-
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
932
|
-
return result.issues.length ? {
|
|
933
|
-
success: false,
|
|
934
|
-
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
935
|
-
} : {
|
|
936
|
-
success: true,
|
|
937
|
-
data: result.value
|
|
938
|
-
};
|
|
939
|
-
};
|
|
940
|
-
const safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
941
|
-
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
942
|
-
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
943
|
-
let result = schema._zod.run({
|
|
944
|
-
value,
|
|
945
|
-
issues: []
|
|
946
|
-
}, ctx);
|
|
947
|
-
if (result instanceof Promise) result = await result;
|
|
948
|
-
return result.issues.length ? {
|
|
949
|
-
success: false,
|
|
950
|
-
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
951
|
-
} : {
|
|
952
|
-
success: true,
|
|
953
|
-
data: result.value
|
|
954
|
-
};
|
|
955
|
-
};
|
|
956
|
-
const safeParseAsync = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
957
|
-
const string$1 = (params) => {
|
|
958
|
-
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
959
|
-
return /* @__PURE__ */ new RegExp(`^${regex}$`);
|
|
960
|
-
};
|
|
961
|
-
const version = {
|
|
962
|
-
major: 4,
|
|
963
|
-
minor: 1,
|
|
964
|
-
patch: 5
|
|
965
|
-
};
|
|
966
|
-
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
967
|
-
var _a;
|
|
968
|
-
inst ?? (inst = {});
|
|
969
|
-
inst._zod.def = def;
|
|
970
|
-
inst._zod.bag = inst._zod.bag || {};
|
|
971
|
-
inst._zod.version = version;
|
|
972
|
-
const checks = [...inst._zod.def.checks ?? []];
|
|
973
|
-
if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
|
|
974
|
-
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
|
|
975
|
-
if (checks.length === 0) {
|
|
976
|
-
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
977
|
-
inst._zod.deferred?.push(() => {
|
|
978
|
-
inst._zod.run = inst._zod.parse;
|
|
979
|
-
});
|
|
980
|
-
} else {
|
|
981
|
-
const runChecks = (payload, checks$1, ctx) => {
|
|
982
|
-
let isAborted = aborted(payload);
|
|
983
|
-
let asyncResult;
|
|
984
|
-
for (const ch of checks$1) {
|
|
985
|
-
if (ch._zod.def.when) {
|
|
986
|
-
if (!ch._zod.def.when(payload)) continue;
|
|
987
|
-
} else if (isAborted) continue;
|
|
988
|
-
const currLen = payload.issues.length;
|
|
989
|
-
const _$1 = ch._zod.check(payload);
|
|
990
|
-
if (_$1 instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
|
|
991
|
-
if (asyncResult || _$1 instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
992
|
-
await _$1;
|
|
993
|
-
if (payload.issues.length === currLen) return;
|
|
994
|
-
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
995
|
-
});
|
|
996
|
-
else {
|
|
997
|
-
if (payload.issues.length === currLen) continue;
|
|
998
|
-
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
if (asyncResult) return asyncResult.then(() => {
|
|
1002
|
-
return payload;
|
|
1003
|
-
});
|
|
1004
|
-
return payload;
|
|
1005
|
-
};
|
|
1006
|
-
const handleCanaryResult = (canary, payload, ctx) => {
|
|
1007
|
-
if (aborted(canary)) {
|
|
1008
|
-
canary.aborted = true;
|
|
1009
|
-
return canary;
|
|
1010
|
-
}
|
|
1011
|
-
const checkResult = runChecks(payload, checks, ctx);
|
|
1012
|
-
if (checkResult instanceof Promise) {
|
|
1013
|
-
if (ctx.async === false) throw new $ZodAsyncError();
|
|
1014
|
-
return checkResult.then((checkResult$1) => inst._zod.parse(checkResult$1, ctx));
|
|
1015
|
-
}
|
|
1016
|
-
return inst._zod.parse(checkResult, ctx);
|
|
1017
|
-
};
|
|
1018
|
-
inst._zod.run = (payload, ctx) => {
|
|
1019
|
-
if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
|
|
1020
|
-
if (ctx.direction === "backward") {
|
|
1021
|
-
const canary = inst._zod.parse({
|
|
1022
|
-
value: payload.value,
|
|
1023
|
-
issues: []
|
|
1024
|
-
}, {
|
|
1025
|
-
...ctx,
|
|
1026
|
-
skipChecks: true
|
|
1027
|
-
});
|
|
1028
|
-
if (canary instanceof Promise) return canary.then((canary$1) => {
|
|
1029
|
-
return handleCanaryResult(canary$1, payload, ctx);
|
|
1030
|
-
});
|
|
1031
|
-
return handleCanaryResult(canary, payload, ctx);
|
|
1032
|
-
}
|
|
1033
|
-
const result = inst._zod.parse(payload, ctx);
|
|
1034
|
-
if (result instanceof Promise) {
|
|
1035
|
-
if (ctx.async === false) throw new $ZodAsyncError();
|
|
1036
|
-
return result.then((result$1) => runChecks(result$1, checks, ctx));
|
|
1037
|
-
}
|
|
1038
|
-
return runChecks(result, checks, ctx);
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
inst["~standard"] = {
|
|
1042
|
-
validate: (value) => {
|
|
1043
|
-
try {
|
|
1044
|
-
const r$1 = safeParse(inst, value);
|
|
1045
|
-
return r$1.success ? { value: r$1.data } : { issues: r$1.error?.issues };
|
|
1046
|
-
} catch (_$1) {
|
|
1047
|
-
return safeParseAsync(inst, value).then((r$1) => r$1.success ? { value: r$1.data } : { issues: r$1.error?.issues });
|
|
1048
|
-
}
|
|
1049
|
-
},
|
|
1050
|
-
vendor: "zod",
|
|
1051
|
-
version: 1
|
|
1052
|
-
};
|
|
1053
|
-
});
|
|
1054
|
-
const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
1055
|
-
$ZodType.init(inst, def);
|
|
1056
|
-
inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
|
|
1057
|
-
inst._zod.parse = (payload, _$1) => {
|
|
1058
|
-
if (def.coerce) try {
|
|
1059
|
-
payload.value = String(payload.value);
|
|
1060
|
-
} catch (_$2) {}
|
|
1061
|
-
if (typeof payload.value === "string") return payload;
|
|
1062
|
-
payload.issues.push({
|
|
1063
|
-
expected: "string",
|
|
1064
|
-
code: "invalid_type",
|
|
1065
|
-
input: payload.value,
|
|
1066
|
-
inst
|
|
1067
|
-
});
|
|
1068
|
-
return payload;
|
|
1069
|
-
};
|
|
1070
|
-
});
|
|
1071
|
-
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
1072
|
-
$ZodType.init(inst, def);
|
|
1073
|
-
inst._zod.parse = (payload) => payload;
|
|
1074
|
-
});
|
|
1075
|
-
function handleArrayResult(result, final, index) {
|
|
1076
|
-
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1077
|
-
final.value[index] = result.value;
|
|
1078
|
-
}
|
|
1079
|
-
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1080
|
-
$ZodType.init(inst, def);
|
|
1081
|
-
inst._zod.parse = (payload, ctx) => {
|
|
1082
|
-
const input = payload.value;
|
|
1083
|
-
if (!Array.isArray(input)) {
|
|
1084
|
-
payload.issues.push({
|
|
1085
|
-
expected: "array",
|
|
1086
|
-
code: "invalid_type",
|
|
1087
|
-
input,
|
|
1088
|
-
inst
|
|
1089
|
-
});
|
|
1090
|
-
return payload;
|
|
1091
|
-
}
|
|
1092
|
-
payload.value = Array(input.length);
|
|
1093
|
-
const proms = [];
|
|
1094
|
-
for (let i$1 = 0; i$1 < input.length; i$1++) {
|
|
1095
|
-
const item = input[i$1];
|
|
1096
|
-
const result = def.element._zod.run({
|
|
1097
|
-
value: item,
|
|
1098
|
-
issues: []
|
|
1099
|
-
}, ctx);
|
|
1100
|
-
if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i$1)));
|
|
1101
|
-
else handleArrayResult(result, payload, i$1);
|
|
1102
|
-
}
|
|
1103
|
-
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1104
|
-
return payload;
|
|
1105
|
-
};
|
|
1106
|
-
});
|
|
1107
|
-
function handlePropertyResult(result, final, key, input) {
|
|
1108
|
-
if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
|
|
1109
|
-
if (result.value === void 0) {
|
|
1110
|
-
if (key in input) final.value[key] = void 0;
|
|
1111
|
-
} else final.value[key] = result.value;
|
|
1112
|
-
}
|
|
1113
|
-
function normalizeDef(def) {
|
|
1114
|
-
const keys = Object.keys(def.shape);
|
|
1115
|
-
for (const k$1 of keys) if (!def.shape[k$1]._zod.traits.has("$ZodType")) throw new Error(`Invalid element at key "${k$1}": expected a Zod schema`);
|
|
1116
|
-
const okeys = optionalKeys(def.shape);
|
|
1117
|
-
return {
|
|
1118
|
-
...def,
|
|
1119
|
-
keys,
|
|
1120
|
-
keySet: new Set(keys),
|
|
1121
|
-
numKeys: keys.length,
|
|
1122
|
-
optionalKeys: new Set(okeys)
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
1126
|
-
const unrecognized = [];
|
|
1127
|
-
const keySet = def.keySet;
|
|
1128
|
-
const _catchall = def.catchall._zod;
|
|
1129
|
-
const t$1 = _catchall.def.type;
|
|
1130
|
-
for (const key of Object.keys(input)) {
|
|
1131
|
-
if (keySet.has(key)) continue;
|
|
1132
|
-
if (t$1 === "never") {
|
|
1133
|
-
unrecognized.push(key);
|
|
1134
|
-
continue;
|
|
1135
|
-
}
|
|
1136
|
-
const r$1 = _catchall.run({
|
|
1137
|
-
value: input[key],
|
|
1138
|
-
issues: []
|
|
1139
|
-
}, ctx);
|
|
1140
|
-
if (r$1 instanceof Promise) proms.push(r$1.then((r$2) => handlePropertyResult(r$2, payload, key, input)));
|
|
1141
|
-
else handlePropertyResult(r$1, payload, key, input);
|
|
1142
|
-
}
|
|
1143
|
-
if (unrecognized.length) payload.issues.push({
|
|
1144
|
-
code: "unrecognized_keys",
|
|
1145
|
-
keys: unrecognized,
|
|
1146
|
-
input,
|
|
1147
|
-
inst
|
|
1148
|
-
});
|
|
1149
|
-
if (!proms.length) return payload;
|
|
1150
|
-
return Promise.all(proms).then(() => {
|
|
1151
|
-
return payload;
|
|
1152
|
-
});
|
|
1153
|
-
}
|
|
1154
|
-
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
1155
|
-
$ZodType.init(inst, def);
|
|
1156
|
-
const _normalized = cached(() => normalizeDef(def));
|
|
1157
|
-
defineLazy(inst._zod, "propValues", () => {
|
|
1158
|
-
const shape = def.shape;
|
|
1159
|
-
const propValues = {};
|
|
1160
|
-
for (const key in shape) {
|
|
1161
|
-
const field = shape[key]._zod;
|
|
1162
|
-
if (field.values) {
|
|
1163
|
-
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
1164
|
-
for (const v$1 of field.values) propValues[key].add(v$1);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
return propValues;
|
|
1168
|
-
});
|
|
1169
|
-
const isObject$1 = isObject;
|
|
1170
|
-
const catchall = def.catchall;
|
|
1171
|
-
let value;
|
|
1172
|
-
inst._zod.parse = (payload, ctx) => {
|
|
1173
|
-
value ?? (value = _normalized.value);
|
|
1174
|
-
const input = payload.value;
|
|
1175
|
-
if (!isObject$1(input)) {
|
|
1176
|
-
payload.issues.push({
|
|
1177
|
-
expected: "object",
|
|
1178
|
-
code: "invalid_type",
|
|
1179
|
-
input,
|
|
1180
|
-
inst
|
|
1181
|
-
});
|
|
1182
|
-
return payload;
|
|
1183
|
-
}
|
|
1184
|
-
payload.value = {};
|
|
1185
|
-
const proms = [];
|
|
1186
|
-
const shape = value.shape;
|
|
1187
|
-
for (const key of value.keys) {
|
|
1188
|
-
const r$1 = shape[key]._zod.run({
|
|
1189
|
-
value: input[key],
|
|
1190
|
-
issues: []
|
|
1191
|
-
}, ctx);
|
|
1192
|
-
if (r$1 instanceof Promise) proms.push(r$1.then((r$2) => handlePropertyResult(r$2, payload, key, input)));
|
|
1193
|
-
else handlePropertyResult(r$1, payload, key, input);
|
|
1194
|
-
}
|
|
1195
|
-
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1196
|
-
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
1197
|
-
};
|
|
1198
|
-
});
|
|
1199
|
-
function handleUnionResults(results, final, inst, ctx) {
|
|
1200
|
-
for (const result of results) if (result.issues.length === 0) {
|
|
1201
|
-
final.value = result.value;
|
|
1202
|
-
return final;
|
|
1203
|
-
}
|
|
1204
|
-
const nonaborted = results.filter((r$1) => !aborted(r$1));
|
|
1205
|
-
if (nonaborted.length === 1) {
|
|
1206
|
-
final.value = nonaborted[0].value;
|
|
1207
|
-
return nonaborted[0];
|
|
1208
|
-
}
|
|
1209
|
-
final.issues.push({
|
|
1210
|
-
code: "invalid_union",
|
|
1211
|
-
input: final.value,
|
|
1212
|
-
inst,
|
|
1213
|
-
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
1214
|
-
});
|
|
1215
|
-
return final;
|
|
1216
|
-
}
|
|
1217
|
-
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
1218
|
-
$ZodType.init(inst, def);
|
|
1219
|
-
defineLazy(inst._zod, "optin", () => def.options.some((o$1) => o$1._zod.optin === "optional") ? "optional" : void 0);
|
|
1220
|
-
defineLazy(inst._zod, "optout", () => def.options.some((o$1) => o$1._zod.optout === "optional") ? "optional" : void 0);
|
|
1221
|
-
defineLazy(inst._zod, "values", () => {
|
|
1222
|
-
if (def.options.every((o$1) => o$1._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
1223
|
-
});
|
|
1224
|
-
defineLazy(inst._zod, "pattern", () => {
|
|
1225
|
-
if (def.options.every((o$1) => o$1._zod.pattern)) {
|
|
1226
|
-
const patterns = def.options.map((o$1) => o$1._zod.pattern);
|
|
1227
|
-
return /* @__PURE__ */ new RegExp(`^(${patterns.map((p$1) => cleanRegex(p$1.source)).join("|")})$`);
|
|
1228
|
-
}
|
|
1229
|
-
});
|
|
1230
|
-
const single = def.options.length === 1;
|
|
1231
|
-
const first = def.options[0]._zod.run;
|
|
1232
|
-
inst._zod.parse = (payload, ctx) => {
|
|
1233
|
-
if (single) return first(payload, ctx);
|
|
1234
|
-
let async = false;
|
|
1235
|
-
const results = [];
|
|
1236
|
-
for (const option of def.options) {
|
|
1237
|
-
const result = option._zod.run({
|
|
1238
|
-
value: payload.value,
|
|
1239
|
-
issues: []
|
|
1240
|
-
}, ctx);
|
|
1241
|
-
if (result instanceof Promise) {
|
|
1242
|
-
results.push(result);
|
|
1243
|
-
async = true;
|
|
1244
|
-
} else {
|
|
1245
|
-
if (result.issues.length === 0) return result;
|
|
1246
|
-
results.push(result);
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
if (!async) return handleUnionResults(results, payload, inst, ctx);
|
|
1250
|
-
return Promise.all(results).then((results$1) => {
|
|
1251
|
-
return handleUnionResults(results$1, payload, inst, ctx);
|
|
1252
|
-
});
|
|
1253
|
-
};
|
|
1254
|
-
});
|
|
1255
|
-
function handleOptionalResult(result, input) {
|
|
1256
|
-
if (result.issues.length && input === void 0) return {
|
|
1257
|
-
issues: [],
|
|
1258
|
-
value: void 0
|
|
1259
|
-
};
|
|
1260
|
-
return result;
|
|
1261
|
-
}
|
|
1262
|
-
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
1263
|
-
$ZodType.init(inst, def);
|
|
1264
|
-
inst._zod.optin = "optional";
|
|
1265
|
-
inst._zod.optout = "optional";
|
|
1266
|
-
defineLazy(inst._zod, "values", () => {
|
|
1267
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
1268
|
-
});
|
|
1269
|
-
defineLazy(inst._zod, "pattern", () => {
|
|
1270
|
-
const pattern = def.innerType._zod.pattern;
|
|
1271
|
-
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
1272
|
-
});
|
|
1273
|
-
inst._zod.parse = (payload, ctx) => {
|
|
1274
|
-
if (def.innerType._zod.optin === "optional") {
|
|
1275
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
1276
|
-
if (result instanceof Promise) return result.then((r$1) => handleOptionalResult(r$1, payload.value));
|
|
1277
|
-
return handleOptionalResult(result, payload.value);
|
|
1278
|
-
}
|
|
1279
|
-
if (payload.value === void 0) return payload;
|
|
1280
|
-
return def.innerType._zod.run(payload, ctx);
|
|
1281
|
-
};
|
|
1282
|
-
});
|
|
1283
|
-
function _string(Class, params) {
|
|
1284
|
-
return new Class({
|
|
1285
|
-
type: "string",
|
|
1286
|
-
...normalizeParams(params)
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
function _any(Class) {
|
|
1290
|
-
return new Class({ type: "any" });
|
|
1291
|
-
}
|
|
1292
|
-
const ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
|
|
1293
|
-
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
|
|
1294
|
-
$ZodType.init(inst, def);
|
|
1295
|
-
inst.def = def;
|
|
1296
|
-
inst.type = def.type;
|
|
1297
|
-
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
1298
|
-
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
1299
|
-
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
1300
|
-
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
1301
|
-
inst.check = (...checks) => {
|
|
1302
|
-
return inst.clone({
|
|
1303
|
-
...def,
|
|
1304
|
-
checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
|
|
1305
|
-
check: ch,
|
|
1306
|
-
def: { check: "custom" },
|
|
1307
|
-
onattach: []
|
|
1308
|
-
} } : ch)]
|
|
1309
|
-
});
|
|
1310
|
-
};
|
|
1311
|
-
inst.clone = (_def, params) => clone(inst, _def, params);
|
|
1312
|
-
inst.brand = () => inst;
|
|
1313
|
-
inst.register = ((reg, meta) => {
|
|
1314
|
-
reg.add(inst, meta);
|
|
1315
|
-
return inst;
|
|
1316
|
-
});
|
|
1317
|
-
});
|
|
1318
|
-
const ZodMiniString = /* @__PURE__ */ $constructor("ZodMiniString", (inst, def) => {
|
|
1319
|
-
$ZodString.init(inst, def);
|
|
1320
|
-
ZodMiniType.init(inst, def);
|
|
1321
|
-
});
|
|
1322
|
-
function string(params) {
|
|
1323
|
-
return _string(ZodMiniString, params);
|
|
1324
|
-
}
|
|
1325
|
-
const ZodMiniAny = /* @__PURE__ */ $constructor("ZodMiniAny", (inst, def) => {
|
|
1326
|
-
$ZodAny.init(inst, def);
|
|
1327
|
-
ZodMiniType.init(inst, def);
|
|
1328
|
-
});
|
|
1329
|
-
function any() {
|
|
1330
|
-
return _any(ZodMiniAny);
|
|
1331
|
-
}
|
|
1332
|
-
const ZodMiniArray = /* @__PURE__ */ $constructor("ZodMiniArray", (inst, def) => {
|
|
1333
|
-
$ZodArray.init(inst, def);
|
|
1334
|
-
ZodMiniType.init(inst, def);
|
|
1335
|
-
});
|
|
1336
|
-
function array(element, params) {
|
|
1337
|
-
return new ZodMiniArray({
|
|
1338
|
-
type: "array",
|
|
1339
|
-
element,
|
|
1340
|
-
...normalizeParams(params)
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
const ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
|
|
1344
|
-
$ZodObject.init(inst, def);
|
|
1345
|
-
ZodMiniType.init(inst, def);
|
|
1346
|
-
defineLazy(inst, "shape", () => def.shape);
|
|
1347
|
-
});
|
|
1348
|
-
function object(shape, params) {
|
|
1349
|
-
const def = {
|
|
1350
|
-
type: "object",
|
|
1351
|
-
get shape() {
|
|
1352
|
-
assignProp(this, "shape", { ...shape });
|
|
1353
|
-
return this.shape;
|
|
1354
|
-
},
|
|
1355
|
-
...normalizeParams(params)
|
|
1356
|
-
};
|
|
1357
|
-
return new ZodMiniObject(def);
|
|
1358
|
-
}
|
|
1359
|
-
const ZodMiniUnion = /* @__PURE__ */ $constructor("ZodMiniUnion", (inst, def) => {
|
|
1360
|
-
$ZodUnion.init(inst, def);
|
|
1361
|
-
ZodMiniType.init(inst, def);
|
|
1362
|
-
});
|
|
1363
|
-
function union(options, params) {
|
|
1364
|
-
return new ZodMiniUnion({
|
|
1365
|
-
type: "union",
|
|
1366
|
-
options,
|
|
1367
|
-
...normalizeParams(params)
|
|
1368
|
-
});
|
|
1369
|
-
}
|
|
1370
|
-
const ZodMiniOptional = /* @__PURE__ */ $constructor("ZodMiniOptional", (inst, def) => {
|
|
1371
|
-
$ZodOptional.init(inst, def);
|
|
1372
|
-
ZodMiniType.init(inst, def);
|
|
1373
|
-
});
|
|
1374
|
-
function optional(innerType) {
|
|
1375
|
-
return new ZodMiniOptional({
|
|
1376
|
-
type: "optional",
|
|
1377
|
-
innerType
|
|
1378
|
-
});
|
|
1379
|
-
}
|
|
1380
|
-
let __TYPE_KEY = "__TYPE_KEY__";
|
|
1381
|
-
let __CONTENT_KEY = "__CONTENT_KEY__";
|
|
1382
|
-
let __BLOB_URL_KEY = "__BLOB_URL_KEY__";
|
|
1383
|
-
let __IMAGE_CONTENT_KEY = "__IMAGE_CONTENT_KEY__";
|
|
1384
|
-
let __IMAGE_INLINE_CONTENT_KEY = "__IMAGE_INLINE_CONTENT_KEY__";
|
|
1385
|
-
let __FILE_CONTENT_KEY = "__FILE_CONTENT_KEY__";
|
|
1386
|
-
let __FC_RESPONSE_KEY = "__FC_RESPONSE_KEY__";
|
|
1387
|
-
let sm = [];
|
|
1388
|
-
const KEYS = {
|
|
1389
|
-
get TYPE_KEY() {
|
|
1390
|
-
if (__TYPE_KEY === "__TYPE_KEY__") {
|
|
1391
|
-
const msg = sm.at(-1);
|
|
1392
|
-
for (const key in msg) {
|
|
1393
|
-
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1394
|
-
const val = msg[key];
|
|
1395
|
-
if (/^(text|image|function_call|file)$/.test(val)) {
|
|
1396
|
-
__TYPE_KEY = key;
|
|
1397
|
-
break;
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
return __TYPE_KEY;
|
|
1402
|
-
},
|
|
1403
|
-
get CONTENT_KEY() {
|
|
1404
|
-
if (__CONTENT_KEY === "__CONTENT_KEY__") msgLabel: for (const msg of sm) {
|
|
1405
|
-
const parts = msg.parts;
|
|
1406
|
-
if (Array.isArray(parts) && parts.length > 0) {
|
|
1407
|
-
const part = parts[0];
|
|
1408
|
-
for (const key in part) {
|
|
1409
|
-
const val = part[key];
|
|
1410
|
-
if (Array.isArray(val)) {
|
|
1411
|
-
__CONTENT_KEY = key;
|
|
1412
|
-
break msgLabel;
|
|
1413
|
-
}
|
|
1414
|
-
break;
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
return __CONTENT_KEY;
|
|
1419
|
-
},
|
|
1420
|
-
get BLOB_URL_KEY() {
|
|
1421
|
-
prepareImageKeys();
|
|
1422
|
-
return __BLOB_URL_KEY;
|
|
1423
|
-
},
|
|
1424
|
-
get IMAGE_CONTENT_KEY() {
|
|
1425
|
-
prepareImageKeys();
|
|
1426
|
-
return __IMAGE_CONTENT_KEY;
|
|
1427
|
-
},
|
|
1428
|
-
get IMAGE_INLINE_CONTENT_KEY() {
|
|
1429
|
-
prepareImageKeys();
|
|
1430
|
-
return __IMAGE_INLINE_CONTENT_KEY;
|
|
1431
|
-
},
|
|
1432
|
-
get FILE_CONTENT_KEY() {
|
|
1433
|
-
if (__FILE_CONTENT_KEY === "__FILE_CONTENT_KEY__") {
|
|
1434
|
-
for (const msg of sm) if ("file" === msg[KEYS.TYPE_KEY]) for (const key in msg) {
|
|
1435
|
-
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1436
|
-
const val = msg[key];
|
|
1437
|
-
if (typeof val === "object" && val && "mimeType" in val) __FILE_CONTENT_KEY = key;
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
return __FILE_CONTENT_KEY;
|
|
1441
|
-
},
|
|
1442
|
-
get FC_RESPONSE_KEY() {
|
|
1443
|
-
if (__FC_RESPONSE_KEY === "__FC_RESPONSE_KEY__") {
|
|
1444
|
-
for (const msg of sm) if ("function_call" === msg[KEYS.TYPE_KEY]) for (const key in msg) {
|
|
1445
|
-
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1446
|
-
const val = msg[key];
|
|
1447
|
-
if (typeof val === "object" && val && "response" in val) __FC_RESPONSE_KEY = key;
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
return __FC_RESPONSE_KEY;
|
|
1451
|
-
}
|
|
1452
|
-
};
|
|
1453
|
-
const prepareImageKeys = () => {
|
|
1454
|
-
if (__BLOB_URL_KEY === "__BLOB_URL_KEY__" || __IMAGE_CONTENT_KEY === "__IMAGE_CONTENT_KEY__" || __IMAGE_INLINE_CONTENT_KEY === "__IMAGE_INLINE_CONTENT_KEY__") {
|
|
1455
|
-
for (const msg of sm) if ("image" === msg[KEYS.TYPE_KEY]) for (const key in msg) {
|
|
1456
|
-
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1457
|
-
const val = msg[key];
|
|
1458
|
-
if (typeof val === "object" && val && "mimeType" in val) if ("id" in val) __IMAGE_CONTENT_KEY = key;
|
|
1459
|
-
else __IMAGE_INLINE_CONTENT_KEY = key;
|
|
1460
|
-
else if (typeof val === "string" && val.startsWith("blob:")) __BLOB_URL_KEY = key;
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
};
|
|
1464
|
-
const prepareKey = (sourceMessages) => {
|
|
1465
|
-
if (sourceMessages.length === 0) return;
|
|
1466
|
-
sm = sourceMessages;
|
|
1467
|
-
};
|
|
1468
|
-
const TargetPartSchema = union([
|
|
1469
|
-
object({ text: string() }),
|
|
1470
|
-
object({ inlineData: object({
|
|
1471
|
-
mimeType: string(),
|
|
1472
|
-
data: string()
|
|
1473
|
-
}) }),
|
|
1474
|
-
object({ functionCall: object({
|
|
1475
|
-
name: string(),
|
|
1476
|
-
parameters: any()
|
|
1477
|
-
}) }),
|
|
1478
|
-
object({ functionResponse: object({
|
|
1479
|
-
name: string(),
|
|
1480
|
-
response: any()
|
|
1481
|
-
}) })
|
|
1482
|
-
]);
|
|
1483
|
-
const TargetMessageSchema = object({
|
|
1484
|
-
id: optional(string()),
|
|
1485
|
-
role: string(),
|
|
1486
|
-
parts: array(TargetPartSchema)
|
|
1487
|
-
});
|
|
1488
|
-
array(TargetMessageSchema);
|
|
1489
|
-
const blobUrlToBase64 = (blobUrl) => {
|
|
1490
|
-
return new Promise(async (resolve, reject) => {
|
|
1491
|
-
try {
|
|
1492
|
-
const response = await fetch(blobUrl);
|
|
1493
|
-
if (!response.ok) throw new Error(`Failed to fetch blob: ${response.statusText}`);
|
|
1494
|
-
const blob = await response.blob();
|
|
1495
|
-
const reader = new FileReader();
|
|
1496
|
-
reader.onloadend = () => {
|
|
1497
|
-
const base64Data = reader.result.split(",")[1];
|
|
1498
|
-
resolve(base64Data);
|
|
1499
|
-
};
|
|
1500
|
-
reader.onerror = (error) => {
|
|
1501
|
-
reject(error);
|
|
1502
|
-
};
|
|
1503
|
-
reader.readAsDataURL(blob);
|
|
1504
|
-
} catch (error) {
|
|
1505
|
-
reject(error);
|
|
1506
|
-
}
|
|
1507
|
-
});
|
|
1508
|
-
};
|
|
1509
|
-
const normalizeNcValue = (ncWrapper) => {
|
|
1510
|
-
const ncArray = ncWrapper[KEYS.CONTENT_KEY];
|
|
1511
|
-
return z(ncArray).with([
|
|
1512
|
-
N.any,
|
|
1513
|
-
N.any,
|
|
1514
|
-
N.any,
|
|
1515
|
-
N.any,
|
|
1516
|
-
{ [KEYS.CONTENT_KEY]: [N.select(N.instanceOf(Map))] }
|
|
1517
|
-
], (innerMap) => {
|
|
1518
|
-
return [
|
|
1519
|
-
null,
|
|
1520
|
-
null,
|
|
1521
|
-
null,
|
|
1522
|
-
null,
|
|
1523
|
-
[normalizeNcMapToCanonicalArray(innerMap)]
|
|
1524
|
-
];
|
|
1525
|
-
}).otherwise(() => ncArray);
|
|
1526
|
-
};
|
|
1527
|
-
const normalizeNcMapToCanonicalArray = (map) => {
|
|
1528
|
-
return Array.from(map.entries()).map(([key, valueWrapper]) => {
|
|
1529
|
-
const canonicalValueArray = normalizeNcValue(valueWrapper);
|
|
1530
|
-
return [key, canonicalValueArray];
|
|
1531
|
-
});
|
|
1532
|
-
};
|
|
1533
|
-
const getCanonicalFunctionCall = (msg) => {
|
|
1534
|
-
return z(msg.parts[0]).with(N.array(), (part) => ({
|
|
1535
|
-
name: part[10][0],
|
|
1536
|
-
argsArray: part[10][1][0]
|
|
1537
|
-
})).with({ [KEYS.CONTENT_KEY]: N.array() }, (part) => {
|
|
1538
|
-
const functionCallData = part[KEYS.CONTENT_KEY][10][KEYS.CONTENT_KEY];
|
|
1539
|
-
const name = functionCallData[0];
|
|
1540
|
-
const argsMap = functionCallData[1][KEYS.CONTENT_KEY][0];
|
|
1541
|
-
return {
|
|
1542
|
-
name,
|
|
1543
|
-
argsArray: normalizeNcMapToCanonicalArray(argsMap)
|
|
1544
|
-
};
|
|
1545
|
-
}).otherwise(() => {
|
|
1546
|
-
throw new Error("Unknown function_call structure encountered.");
|
|
1547
|
-
});
|
|
1548
|
-
};
|
|
1549
|
-
const parseArgValue = (arg) => {
|
|
1550
|
-
if (!Array.isArray(arg)) {
|
|
1551
|
-
if (typeof arg === "object" && arg !== null && KEYS.CONTENT_KEY in arg) return parseArgValue(arg[KEYS.CONTENT_KEY]);
|
|
1552
|
-
return arg;
|
|
1553
|
-
}
|
|
1554
|
-
return z(arg).with([
|
|
1555
|
-
N.any,
|
|
1556
|
-
N.any,
|
|
1557
|
-
N.any,
|
|
1558
|
-
N.any,
|
|
1559
|
-
N.any,
|
|
1560
|
-
{ [KEYS.CONTENT_KEY]: [N.select()] }
|
|
1561
|
-
], (val) => {
|
|
1562
|
-
if (Array.isArray(val)) return val.map(parseArgValue);
|
|
1563
|
-
console.warn("unknown struct 1", val);
|
|
1564
|
-
return null;
|
|
1565
|
-
}).with([
|
|
1566
|
-
N.any,
|
|
1567
|
-
N.any,
|
|
1568
|
-
N.any,
|
|
1569
|
-
N.any,
|
|
1570
|
-
{ [KEYS.CONTENT_KEY]: [N.select(N.instanceOf(Map))] }
|
|
1571
|
-
], (map) => {
|
|
1572
|
-
return Object.fromEntries([...map.entries()].map(([key, valueWrapper]) => {
|
|
1573
|
-
return [key, parseArgValue(valueWrapper)];
|
|
1574
|
-
}));
|
|
1575
|
-
}).with([
|
|
1576
|
-
N.any,
|
|
1577
|
-
N.any,
|
|
1578
|
-
N.any,
|
|
1579
|
-
N.any,
|
|
1580
|
-
N.select(N.array())
|
|
1581
|
-
], (nestedPairs) => parseFunctionArgs(nestedPairs[0])).with([
|
|
1582
|
-
N.any,
|
|
1583
|
-
N.any,
|
|
1584
|
-
N.any,
|
|
1585
|
-
1
|
|
1586
|
-
], () => true).with([
|
|
1587
|
-
N.any,
|
|
1588
|
-
N.any,
|
|
1589
|
-
N.any,
|
|
1590
|
-
0
|
|
1591
|
-
], () => false).with([
|
|
1592
|
-
N.any,
|
|
1593
|
-
N.any,
|
|
1594
|
-
N.select(N.string)
|
|
1595
|
-
], (val) => val).with([N.any, N.select(N.number)], (val) => val).otherwise(() => {
|
|
1596
|
-
console.warn("unknown struct 0", arg);
|
|
1597
|
-
return null;
|
|
1598
|
-
});
|
|
1599
|
-
};
|
|
1600
|
-
const parseFunctionArgs = (argList) => {
|
|
1601
|
-
if (!Array.isArray(argList)) return {};
|
|
1602
|
-
return Object.fromEntries(argList.map(([key, value]) => [key, parseArgValue(value)]));
|
|
1603
|
-
};
|
|
1604
|
-
const convertMessages = async (sourceMessages) => {
|
|
1605
|
-
prepareKey(sourceMessages);
|
|
1606
|
-
const groupedMessages = sourceMessages.reduce((acc, msg) => {
|
|
1607
|
-
const lastGroup = acc[acc.length - 1];
|
|
1608
|
-
const prevMessage = lastGroup?.items[lastGroup.items.length - 1];
|
|
1609
|
-
if (lastGroup && lastGroup.role === msg.role && prevMessage?.[KEYS.TYPE_KEY] !== "function_call") lastGroup.items.push(msg);
|
|
1610
|
-
else acc.push({
|
|
1611
|
-
role: msg.role,
|
|
1612
|
-
items: [msg]
|
|
1613
|
-
});
|
|
1614
|
-
return acc;
|
|
1615
|
-
}, []);
|
|
1616
|
-
const finalMessages = [];
|
|
1617
|
-
for (const group of groupedMessages) {
|
|
1618
|
-
let functionResponseData = null;
|
|
1619
|
-
const partsPromises = group.items.map(async (item) => {
|
|
1620
|
-
return z(item).with({
|
|
1621
|
-
[KEYS.TYPE_KEY]: "text",
|
|
1622
|
-
text: N.string
|
|
1623
|
-
}, (msg) => {
|
|
1624
|
-
return msg.text.length > 0 ? { text: msg.text } : null;
|
|
1625
|
-
}).with({ [KEYS.TYPE_KEY]: "image" }, async (img) => {
|
|
1626
|
-
if (KEYS.IMAGE_INLINE_CONTENT_KEY in img) {
|
|
1627
|
-
const inlineContent = img[KEYS.IMAGE_INLINE_CONTENT_KEY];
|
|
1628
|
-
return { inlineData: {
|
|
1629
|
-
mimeType: inlineContent.mimeType,
|
|
1630
|
-
data: inlineContent.Dc
|
|
1631
|
-
} };
|
|
1632
|
-
}
|
|
1633
|
-
if (KEYS.BLOB_URL_KEY in img && KEYS.IMAGE_CONTENT_KEY in img) {
|
|
1634
|
-
const imageConent = img[KEYS.IMAGE_CONTENT_KEY];
|
|
1635
|
-
const blobUrl = img[KEYS.BLOB_URL_KEY];
|
|
1636
|
-
try {
|
|
1637
|
-
const data = await blobUrlToBase64(blobUrl);
|
|
1638
|
-
return { inlineData: {
|
|
1639
|
-
mimeType: imageConent.mimeType,
|
|
1640
|
-
data
|
|
1641
|
-
} };
|
|
1642
|
-
} catch (error) {
|
|
1643
|
-
console.error(`Failed to process blob URL ${blobUrl}:`, error);
|
|
1644
|
-
return null;
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
return null;
|
|
1648
|
-
}).with({ [KEYS.TYPE_KEY]: "function_call" }, (msg) => {
|
|
1649
|
-
try {
|
|
1650
|
-
const { name, argsArray } = getCanonicalFunctionCall(msg);
|
|
1651
|
-
const args = parseFunctionArgs(argsArray);
|
|
1652
|
-
if (typeof msg[KEYS.FC_RESPONSE_KEY]?.response === "string") functionResponseData = {
|
|
1653
|
-
name,
|
|
1654
|
-
response: msg[KEYS.FC_RESPONSE_KEY].response
|
|
1655
|
-
};
|
|
1656
|
-
return { functionCall: {
|
|
1657
|
-
name,
|
|
1658
|
-
parameters: JSON.stringify(args)
|
|
1659
|
-
} };
|
|
1660
|
-
} catch (error) {
|
|
1661
|
-
console.error("Failed to parse function call:", error, item);
|
|
1662
|
-
return null;
|
|
1663
|
-
}
|
|
1664
|
-
}).otherwise(() => null);
|
|
1665
|
-
});
|
|
1666
|
-
const parts = (await Promise.all(partsPromises)).filter((p$1) => p$1 !== null);
|
|
1667
|
-
if (parts.length > 0) finalMessages.push({
|
|
1668
|
-
id: group.id,
|
|
1669
|
-
role: group.role,
|
|
1670
|
-
parts
|
|
1671
|
-
});
|
|
1672
|
-
if (functionResponseData) finalMessages.push({
|
|
1673
|
-
id: group.id,
|
|
1674
|
-
role: "user",
|
|
1675
|
-
parts: [{ functionResponse: {
|
|
1676
|
-
name: functionResponseData.name,
|
|
1677
|
-
response: functionResponseData.response
|
|
1678
|
-
} }]
|
|
1679
|
-
});
|
|
1680
|
-
}
|
|
1681
|
-
finalMessages.push({
|
|
1682
|
-
role: "user",
|
|
1683
|
-
parts: [{ text: "INSERT_INPUT_HERE" }]
|
|
1684
|
-
});
|
|
1685
|
-
return finalMessages;
|
|
1686
|
-
};
|
|
1687
|
-
const syncOutput = async (signal) => {
|
|
1688
|
-
if (signal?.aborted) {
|
|
1689
|
-
console.log("JIXO BROWSER: syncOutput aborted before starting.");
|
|
1690
|
-
return;
|
|
1691
|
-
}
|
|
1692
|
-
const abortController = new AbortController();
|
|
1693
|
-
const internalSignal = abortController.signal;
|
|
1694
|
-
signal?.addEventListener("abort", () => {
|
|
1695
|
-
console.log("JIXO BROWSER: syncOutput aborted.");
|
|
1696
|
-
abortController.abort();
|
|
1697
|
-
}, { once: true });
|
|
1698
|
-
let preRaw = "";
|
|
1699
|
-
const onChange = func_throttle(async (raw) => {
|
|
1700
|
-
if (internalSignal.aborted) return;
|
|
1701
|
-
const newRaw = JSON.stringify(raw);
|
|
1702
|
-
if (preRaw !== newRaw) {
|
|
1703
|
-
preRaw = newRaw;
|
|
1704
|
-
await runFileCreation(await convertMessages(raw));
|
|
1705
|
-
}
|
|
1706
|
-
}, 200, {
|
|
1707
|
-
before: true,
|
|
1708
|
-
waitPromise: true
|
|
1709
|
-
});
|
|
1710
|
-
const arr_push = Array.prototype[Symbol.for("arr_push")] || Array.prototype.push;
|
|
1711
|
-
Array.prototype[Symbol.for("arr_push")] = arr_push;
|
|
1712
|
-
Array.prototype.push = function push(...args) {
|
|
1713
|
-
const a$1 = args[0];
|
|
1714
|
-
let isMatched = false;
|
|
1715
|
-
if (this.length > 1 && a$1 && Object.getPrototypeOf(a$1) === Object.prototype && a$1.role && a$1.id && typeof a$1.text === "string") isMatched = true;
|
|
1716
|
-
const res = arr_push.apply(this, args);
|
|
1717
|
-
if (isMatched && !internalSignal.aborted) try {
|
|
1718
|
-
onChange(structuredClone(this));
|
|
1719
|
-
} catch {}
|
|
1720
|
-
return res;
|
|
1721
|
-
};
|
|
1722
|
-
const findInput = () => $(`textarea[aria-label="Start typing a prompt"]`);
|
|
1723
|
-
while (!internalSignal.aborted) {
|
|
1724
|
-
const input = findInput();
|
|
1725
|
-
if (input) input.dispatchEvent(new Event("input"));
|
|
1726
|
-
await delay(300);
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
async function runFileCreation(b$1, targetFilename = getTargetNamespace() + ".contents.json") {
|
|
1730
|
-
try {
|
|
1731
|
-
const writable = await (await (await prepareDirHandle()).getFileHandle(targetFilename, { create: true })).createWritable();
|
|
1732
|
-
await writable.write(JSON.stringify(b$1));
|
|
1733
|
-
await writable.close();
|
|
1734
|
-
console.log(`%c - ✅ File written: %c${targetFilename}`, styles.success, styles.code);
|
|
1735
|
-
} catch (error) {
|
|
1736
|
-
if (error instanceof Error && error.name === "AbortError") console.warn("%c⚠️ User cancelled folder selection.", styles.warn);
|
|
1737
|
-
else console.error("%c❌ Error writing file:", styles.error, error);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
(async () => {
|
|
1741
|
-
if (await prepareDirHandle().then(() => false, (e$1) => {
|
|
1742
|
-
if (e$1 instanceof Error && e$1.name === "AbortError") return true;
|
|
1743
|
-
})) {
|
|
1744
|
-
console.warn("用户取消了脚本运行");
|
|
1745
|
-
return;
|
|
1746
|
-
}
|
|
1747
|
-
syncOutput();
|
|
1748
|
-
syncInput();
|
|
1749
|
-
})();
|
|
1750
|
-
export {};
|