@jixo/cli 0.23.2 → 0.23.4

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.
@@ -0,0 +1,1192 @@
1
+ import { createRequire } from "node:module";
2
+ import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
3
+ import path, { dirname } from "node:path";
4
+ import fs, { realpathSync } from "node:fs";
5
+ import { createHash } from "node:crypto";
6
+ const pathResolve = (specifier, parentURL) => {
7
+ let baseUrl;
8
+ if (parentURL instanceof URL$1) baseUrl = parentURL;
9
+ else {
10
+ const parentHref = String(parentURL);
11
+ if (parentHref.startsWith("file:")) baseUrl = parentHref;
12
+ else baseUrl = pathToFileURL(parentHref).href;
13
+ }
14
+ return new URL$1(specifier, baseUrl).href;
15
+ };
16
+ const import_meta_ponyfill_commonjs = Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ?? (() => {
17
+ const moduleImportMetaWM = /* @__PURE__ */ new WeakMap();
18
+ return (require, module) => {
19
+ let importMetaCache = moduleImportMetaWM.get(module);
20
+ if (importMetaCache == null) {
21
+ const importMeta = Object.assign(Object.create(null), {
22
+ url: pathToFileURL(module.filename).href,
23
+ main: require.main === module,
24
+ nodeResolve(specifier, parentURL = importMeta.url) {
25
+ return pathToFileURL((importMeta.url === parentURL ? require : createRequire(parentURL)).resolve(specifier)).href;
26
+ },
27
+ resolve: function resolve(specifier, parentURL = importMeta.url) {
28
+ if (/^[./]*\/.*/.test(specifier)) return pathResolve(specifier, parentURL);
29
+ try {
30
+ return importMeta.nodeResolve(specifier, parentURL);
31
+ } catch {
32
+ return pathResolve(specifier, parentURL);
33
+ }
34
+ },
35
+ filename: module.filename,
36
+ dirname: module.path
37
+ });
38
+ moduleImportMetaWM.set(module, importMeta);
39
+ importMetaCache = importMeta;
40
+ }
41
+ return importMetaCache;
42
+ };
43
+ })();
44
+ let import_meta_ponyfill_esmodule = Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ?? ((importMeta) => {
45
+ const resolveFunStr = String(importMeta.resolve);
46
+ const importMetaWM = /* @__PURE__ */ new WeakMap();
47
+ const isMain = (filename) => {
48
+ try {
49
+ const entry = process.argv[1];
50
+ return filename === entry || realpathSync(filename) === realpathSync(entry);
51
+ } catch {
52
+ return false;
53
+ }
54
+ };
55
+ const isSupportResolve = resolveFunStr !== "undefined" && !resolveFunStr.startsWith("async");
56
+ import_meta_ponyfill_esmodule = (im) => {
57
+ let importMetaCache = importMetaWM.get(im);
58
+ if (importMetaCache == null) {
59
+ const filename = im.filename ?? fileURLToPath(im.url);
60
+ const dirname$1 = im.dirname ?? dirname(filename);
61
+ const importMeta$1 = {
62
+ url: im.url,
63
+ main: im.main ?? isMain(filename),
64
+ filename,
65
+ dirname: dirname$1,
66
+ nodeResolve: isSupportResolve ? im.resolve : (() => {
67
+ const importMetaUrlRequire = createRequire(im.url);
68
+ return (specifier, parentURL = im.url) => {
69
+ return pathToFileURL((importMeta$1.url === parentURL ? importMetaUrlRequire : createRequire(parentURL)).resolve(specifier)).href;
70
+ };
71
+ })(),
72
+ resolve: function resolve(specifier, parentURL = im.url) {
73
+ if (/^[./]*\/.*/.test(specifier)) return pathResolve(specifier, parentURL);
74
+ try {
75
+ return importMeta$1.nodeResolve(specifier, parentURL);
76
+ } catch {
77
+ return pathResolve(specifier, parentURL);
78
+ }
79
+ }
80
+ };
81
+ importMetaCache = importMeta$1;
82
+ importMetaWM.set(im, importMeta$1);
83
+ }
84
+ return importMetaCache;
85
+ };
86
+ return import_meta_ponyfill_esmodule(importMeta);
87
+ });
88
+ const dntGlobals = {};
89
+ const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
90
+ function createMergeProxy(baseObj, extObj) {
91
+ return new Proxy(baseObj, {
92
+ get(_target, prop, _receiver) {
93
+ if (prop in extObj) return extObj[prop];
94
+ else return baseObj[prop];
95
+ },
96
+ set(_target, prop, value) {
97
+ if (prop in extObj) delete extObj[prop];
98
+ baseObj[prop] = value;
99
+ return true;
100
+ },
101
+ deleteProperty(_target, prop) {
102
+ let success = false;
103
+ if (prop in extObj) {
104
+ delete extObj[prop];
105
+ success = true;
106
+ }
107
+ if (prop in baseObj) {
108
+ delete baseObj[prop];
109
+ success = true;
110
+ }
111
+ return success;
112
+ },
113
+ ownKeys(_target) {
114
+ const baseKeys = Reflect.ownKeys(baseObj);
115
+ const extKeys = Reflect.ownKeys(extObj);
116
+ const extKeysSet = new Set(extKeys);
117
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
118
+ },
119
+ defineProperty(_target, prop, desc) {
120
+ if (prop in extObj) delete extObj[prop];
121
+ Reflect.defineProperty(baseObj, prop, desc);
122
+ return true;
123
+ },
124
+ getOwnPropertyDescriptor(_target, prop) {
125
+ if (prop in extObj) return Reflect.getOwnPropertyDescriptor(extObj, prop);
126
+ else return Reflect.getOwnPropertyDescriptor(baseObj, prop);
127
+ },
128
+ has(_target, prop) {
129
+ return prop in extObj || prop in baseObj;
130
+ }
131
+ });
132
+ }
133
+ const { Deno } = dntGlobalThis;
134
+ const noColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : false;
135
+ let enabled = !noColor;
136
+ function code(open, close) {
137
+ return {
138
+ open: `\x1b[${open.join(";")}m`,
139
+ close: `\x1b[${close}m`,
140
+ regexp: new RegExp(`\\x1b\\[${close}m`, "g")
141
+ };
142
+ }
143
+ function run(str, code$1) {
144
+ return enabled ? `${code$1.open}${str.replace(code$1.regexp, code$1.open)}${code$1.close}` : str;
145
+ }
146
+ function red(str) {
147
+ return run(str, code([31], 39));
148
+ }
149
+ function green(str) {
150
+ return run(str, code([32], 39));
151
+ }
152
+ function blue(str) {
153
+ return run(str, code([34], 39));
154
+ }
155
+ function magenta(str) {
156
+ return run(str, code([35], 39));
157
+ }
158
+ function cyan(str) {
159
+ return run(str, code([36], 39));
160
+ }
161
+ function gray(str) {
162
+ return brightBlack(str);
163
+ }
164
+ function brightBlack(str) {
165
+ return run(str, code([90], 39));
166
+ }
167
+ const ANSI_PATTERN = new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))"].join("|"), "g");
168
+ const obj_assign_props = /* @__NO_SIDE_EFFECTS__ */ (a, b) => {
169
+ const b_props = Object.getOwnPropertyDescriptors(b);
170
+ Object.defineProperties(a, b_props);
171
+ return a;
172
+ };
173
+ const iter_first_not_null = (values, callbackfn) => {
174
+ let index = 0;
175
+ if (callbackfn) for (const value of values) {
176
+ const r = callbackfn(value, index++, values);
177
+ if (r != null) return r;
178
+ }
179
+ else for (const value of values) if (value != null) return value;
180
+ };
181
+ const timmers = {
182
+ timeout: (ms) => {
183
+ return (cb) => {
184
+ const ti = setTimeout(cb, ms);
185
+ return () => clearTimeout(ti);
186
+ };
187
+ },
188
+ raf: ((cb) => {
189
+ const ti = requestAnimationFrame(cb);
190
+ return () => cancelAnimationFrame(ti);
191
+ }),
192
+ microtask: ((cb) => {
193
+ let cancel = false;
194
+ queueMicrotask(() => {
195
+ if (cancel) return;
196
+ cb();
197
+ });
198
+ return () => {
199
+ cancel = true;
200
+ };
201
+ }),
202
+ eventTarget: (target, eventType, filter) => {
203
+ return (resolve) => {
204
+ let cb;
205
+ if (typeof filter === "function") {
206
+ cb = (event) => {
207
+ if (filter(event)) {
208
+ resolve(event);
209
+ target.removeEventListener(eventType, cb);
210
+ }
211
+ };
212
+ target.addEventListener(eventType, cb);
213
+ } else {
214
+ cb = resolve;
215
+ target.addEventListener(eventType, cb, { once: true });
216
+ }
217
+ return () => target.removeEventListener(eventType, cb);
218
+ };
219
+ },
220
+ from: (ms) => {
221
+ return typeof ms === "number" ? ms <= 0 ? timmers.microtask : timmers.timeout(ms) : ms;
222
+ }
223
+ };
224
+ const func_debounce = (fn, wait = 0, options = {}) => {
225
+ if (!Number.isFinite(wait)) throw new TypeError("Expected `wait` to be a finite number");
226
+ const timmer = timmers.from(wait);
227
+ let leadingValue;
228
+ let clear;
229
+ let jobList = [];
230
+ let trigger;
231
+ return /* @__PURE__ */ obj_assign_props(function(...args) {
232
+ const job = Promise.withResolvers();
233
+ const shouldCallNow = options.before && null == clear;
234
+ if (shouldCallNow) {
235
+ leadingValue = fn.apply(this, args);
236
+ job.resolve(leadingValue);
237
+ } else jobList.push(job);
238
+ clear?.();
239
+ clear = timmer(trigger = () => {
240
+ clear = void 0;
241
+ trigger = void 0;
242
+ const result = options.before ? leadingValue : fn.apply(this, args);
243
+ for (const job$1 of jobList) job$1.resolve(result);
244
+ jobList = [];
245
+ }, (reason) => {
246
+ for (const job$1 of jobList) job$1.reject(reason);
247
+ });
248
+ return job.promise;
249
+ }, {
250
+ get isPending() {
251
+ return clear != null;
252
+ },
253
+ cancel() {
254
+ clear?.();
255
+ },
256
+ source: fn,
257
+ flush() {
258
+ if (clear != null) {
259
+ clear();
260
+ trigger?.();
261
+ }
262
+ }
263
+ });
264
+ };
265
+ const NEVER = Object.freeze({ status: "aborted" });
266
+ function $constructor(name, initializer$1, params) {
267
+ function init(inst, def) {
268
+ var _a;
269
+ Object.defineProperty(inst, "_zod", {
270
+ value: inst._zod ?? {},
271
+ enumerable: false
272
+ });
273
+ (_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
274
+ inst._zod.traits.add(name);
275
+ initializer$1(inst, def);
276
+ for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
277
+ inst._zod.constr = _;
278
+ inst._zod.def = def;
279
+ }
280
+ const Parent = params?.Parent ?? Object;
281
+ class Definition extends Parent {}
282
+ Object.defineProperty(Definition, "name", { value: name });
283
+ function _(def) {
284
+ var _a;
285
+ const inst = params?.Parent ? new Definition() : this;
286
+ init(inst, def);
287
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
288
+ for (const fn of inst._zod.deferred) fn();
289
+ return inst;
290
+ }
291
+ Object.defineProperty(_, "init", { value: init });
292
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
293
+ if (params?.Parent && inst instanceof params.Parent) return true;
294
+ return inst?._zod?.traits?.has(name);
295
+ } });
296
+ Object.defineProperty(_, "name", { value: name });
297
+ return _;
298
+ }
299
+ const $brand = Symbol("zod_brand");
300
+ var $ZodAsyncError = class extends Error {
301
+ constructor() {
302
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
303
+ }
304
+ };
305
+ const globalConfig = {};
306
+ function config(newConfig) {
307
+ if (newConfig) Object.assign(globalConfig, newConfig);
308
+ return globalConfig;
309
+ }
310
+ function jsonStringifyReplacer(_, value) {
311
+ if (typeof value === "bigint") return value.toString();
312
+ return value;
313
+ }
314
+ function cached(getter) {
315
+ const set = false;
316
+ return { get value() {
317
+ {
318
+ const value = getter();
319
+ Object.defineProperty(this, "value", { value });
320
+ return value;
321
+ }
322
+ } };
323
+ }
324
+ function cleanRegex(source) {
325
+ const start = source.startsWith("^") ? 1 : 0;
326
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
327
+ return source.slice(start, end);
328
+ }
329
+ function defineLazy(object$1, key, getter) {
330
+ const set = false;
331
+ Object.defineProperty(object$1, key, {
332
+ get() {
333
+ {
334
+ const value = getter();
335
+ object$1[key] = value;
336
+ return value;
337
+ }
338
+ },
339
+ set(v) {
340
+ Object.defineProperty(object$1, key, { value: v });
341
+ },
342
+ configurable: true
343
+ });
344
+ }
345
+ function assignProp(target, prop, value) {
346
+ Object.defineProperty(target, prop, {
347
+ value,
348
+ writable: true,
349
+ enumerable: true,
350
+ configurable: true
351
+ });
352
+ }
353
+ function esc(str) {
354
+ return JSON.stringify(str);
355
+ }
356
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
357
+ function isObject(data) {
358
+ return typeof data === "object" && data !== null && !Array.isArray(data);
359
+ }
360
+ const allowsEval = cached(() => {
361
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
362
+ try {
363
+ const F = Function;
364
+ new F("");
365
+ return true;
366
+ } catch (_) {
367
+ return false;
368
+ }
369
+ });
370
+ function clone(inst, def, params) {
371
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
372
+ if (!def || params?.parent) cl._zod.parent = inst;
373
+ return cl;
374
+ }
375
+ function normalizeParams(_params) {
376
+ const params = _params;
377
+ if (!params) return {};
378
+ if (typeof params === "string") return { error: () => params };
379
+ if (params?.message !== void 0) {
380
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
381
+ params.error = params.message;
382
+ }
383
+ delete params.message;
384
+ if (typeof params.error === "string") return {
385
+ ...params,
386
+ error: () => params.error
387
+ };
388
+ return params;
389
+ }
390
+ function optionalKeys(shape) {
391
+ return Object.keys(shape).filter((k) => {
392
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
393
+ });
394
+ }
395
+ const NUMBER_FORMAT_RANGES = {
396
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
397
+ int32: [-2147483648, 2147483647],
398
+ uint32: [0, 4294967295],
399
+ float32: [-34028234663852886e22, 34028234663852886e22],
400
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
401
+ };
402
+ function aborted(x, startIndex = 0) {
403
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
404
+ return false;
405
+ }
406
+ function prefixIssues(path$1, issues) {
407
+ return issues.map((iss) => {
408
+ var _a;
409
+ (_a = iss).path ?? (_a.path = []);
410
+ iss.path.unshift(path$1);
411
+ return iss;
412
+ });
413
+ }
414
+ function unwrapMessage(message) {
415
+ return typeof message === "string" ? message : message?.message;
416
+ }
417
+ function finalizeIssue(iss, ctx, config$1) {
418
+ const full = {
419
+ ...iss,
420
+ path: iss.path ?? []
421
+ };
422
+ if (!iss.message) {
423
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
424
+ full.message = message;
425
+ }
426
+ delete full.inst;
427
+ delete full.continue;
428
+ if (!ctx?.reportInput) delete full.input;
429
+ return full;
430
+ }
431
+ const initializer = (inst, def) => {
432
+ inst.name = "$ZodError";
433
+ Object.defineProperty(inst, "_zod", {
434
+ value: inst._zod,
435
+ enumerable: false
436
+ });
437
+ Object.defineProperty(inst, "issues", {
438
+ value: def,
439
+ enumerable: false
440
+ });
441
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
442
+ Object.defineProperty(inst, "toString", {
443
+ value: () => inst.message,
444
+ enumerable: false
445
+ });
446
+ };
447
+ const $ZodError = $constructor("$ZodError", initializer);
448
+ const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
449
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
450
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
451
+ const result = schema._zod.run({
452
+ value,
453
+ issues: []
454
+ }, ctx);
455
+ if (result instanceof Promise) throw new $ZodAsyncError();
456
+ if (result.issues.length) {
457
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
458
+ captureStackTrace(e, _params?.callee);
459
+ throw e;
460
+ }
461
+ return result.value;
462
+ };
463
+ const parse = /* @__PURE__ */ _parse($ZodRealError);
464
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
465
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
466
+ let result = schema._zod.run({
467
+ value,
468
+ issues: []
469
+ }, ctx);
470
+ if (result instanceof Promise) result = await result;
471
+ if (result.issues.length) {
472
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
473
+ captureStackTrace(e, params?.callee);
474
+ throw e;
475
+ }
476
+ return result.value;
477
+ };
478
+ const parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
479
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
480
+ const ctx = _ctx ? {
481
+ ..._ctx,
482
+ async: false
483
+ } : { async: false };
484
+ const result = schema._zod.run({
485
+ value,
486
+ issues: []
487
+ }, ctx);
488
+ if (result instanceof Promise) throw new $ZodAsyncError();
489
+ return result.issues.length ? {
490
+ success: false,
491
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
492
+ } : {
493
+ success: true,
494
+ data: result.value
495
+ };
496
+ };
497
+ const safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
498
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
499
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
500
+ let result = schema._zod.run({
501
+ value,
502
+ issues: []
503
+ }, ctx);
504
+ if (result instanceof Promise) result = await result;
505
+ return result.issues.length ? {
506
+ success: false,
507
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
508
+ } : {
509
+ success: true,
510
+ data: result.value
511
+ };
512
+ };
513
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync($ZodRealError);
514
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
515
+ const date = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
516
+ const string$1 = (params) => {
517
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
518
+ return /* @__PURE__ */ new RegExp(`^${regex}$`);
519
+ };
520
+ const number$1 = /^-?\d+(?:\.\d+)?/i;
521
+ const boolean$1 = /true|false/i;
522
+ var Doc = class {
523
+ constructor(args = []) {
524
+ this.content = [];
525
+ this.indent = 0;
526
+ if (this) this.args = args;
527
+ }
528
+ indented(fn) {
529
+ this.indent += 1;
530
+ fn(this);
531
+ this.indent -= 1;
532
+ }
533
+ write(arg) {
534
+ if (typeof arg === "function") {
535
+ arg(this, { execution: "sync" });
536
+ arg(this, { execution: "async" });
537
+ return;
538
+ }
539
+ const content = arg;
540
+ const lines = content.split("\n").filter((x) => x);
541
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
542
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
543
+ for (const line of dedented) this.content.push(line);
544
+ }
545
+ compile() {
546
+ const F = Function;
547
+ const args = this?.args;
548
+ const content = this?.content ?? [``];
549
+ const lines = [...content.map((x) => ` ${x}`)];
550
+ return new F(...args, lines.join("\n"));
551
+ }
552
+ };
553
+ const version = {
554
+ major: 4,
555
+ minor: 0,
556
+ patch: 10
557
+ };
558
+ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
559
+ var _a;
560
+ inst ?? (inst = {});
561
+ inst._zod.def = def;
562
+ inst._zod.bag = inst._zod.bag || {};
563
+ inst._zod.version = version;
564
+ const checks = [...inst._zod.def.checks ?? []];
565
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
566
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
567
+ if (checks.length === 0) {
568
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
569
+ inst._zod.deferred?.push(() => {
570
+ inst._zod.run = inst._zod.parse;
571
+ });
572
+ } else {
573
+ const runChecks = (payload, checks$1, ctx) => {
574
+ let isAborted = aborted(payload);
575
+ let asyncResult;
576
+ for (const ch of checks$1) {
577
+ if (ch._zod.def.when) {
578
+ const shouldRun = ch._zod.def.when(payload);
579
+ if (!shouldRun) continue;
580
+ } else if (isAborted) continue;
581
+ const currLen = payload.issues.length;
582
+ const _ = ch._zod.check(payload);
583
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
584
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
585
+ await _;
586
+ const nextLen = payload.issues.length;
587
+ if (nextLen === currLen) return;
588
+ if (!isAborted) isAborted = aborted(payload, currLen);
589
+ });
590
+ else {
591
+ const nextLen = payload.issues.length;
592
+ if (nextLen === currLen) continue;
593
+ if (!isAborted) isAborted = aborted(payload, currLen);
594
+ }
595
+ }
596
+ if (asyncResult) return asyncResult.then(() => {
597
+ return payload;
598
+ });
599
+ return payload;
600
+ };
601
+ inst._zod.run = (payload, ctx) => {
602
+ const result = inst._zod.parse(payload, ctx);
603
+ if (result instanceof Promise) {
604
+ if (ctx.async === false) throw new $ZodAsyncError();
605
+ return result.then((result$1) => runChecks(result$1, checks, ctx));
606
+ }
607
+ return runChecks(result, checks, ctx);
608
+ };
609
+ }
610
+ inst["~standard"] = {
611
+ validate: (value) => {
612
+ try {
613
+ const r = safeParse(inst, value);
614
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
615
+ } catch (_) {
616
+ return safeParseAsync(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
617
+ }
618
+ },
619
+ vendor: "zod",
620
+ version: 1
621
+ };
622
+ });
623
+ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
624
+ $ZodType.init(inst, def);
625
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
626
+ inst._zod.parse = (payload, _) => {
627
+ if (def.coerce) try {
628
+ payload.value = String(payload.value);
629
+ } catch (_$1) {}
630
+ if (typeof payload.value === "string") return payload;
631
+ payload.issues.push({
632
+ expected: "string",
633
+ code: "invalid_type",
634
+ input: payload.value,
635
+ inst
636
+ });
637
+ return payload;
638
+ };
639
+ });
640
+ const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
641
+ $ZodType.init(inst, def);
642
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
643
+ inst._zod.parse = (payload, _ctx) => {
644
+ if (def.coerce) try {
645
+ payload.value = Number(payload.value);
646
+ } catch (_) {}
647
+ const input = payload.value;
648
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
649
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
650
+ payload.issues.push({
651
+ expected: "number",
652
+ code: "invalid_type",
653
+ input,
654
+ inst,
655
+ ...received ? { received } : {}
656
+ });
657
+ return payload;
658
+ };
659
+ });
660
+ const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
661
+ $ZodType.init(inst, def);
662
+ inst._zod.pattern = boolean$1;
663
+ inst._zod.parse = (payload, _ctx) => {
664
+ if (def.coerce) try {
665
+ payload.value = Boolean(payload.value);
666
+ } catch (_) {}
667
+ const input = payload.value;
668
+ if (typeof input === "boolean") return payload;
669
+ payload.issues.push({
670
+ expected: "boolean",
671
+ code: "invalid_type",
672
+ input,
673
+ inst
674
+ });
675
+ return payload;
676
+ };
677
+ });
678
+ const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
679
+ $ZodType.init(inst, def);
680
+ inst._zod.parse = (payload) => payload;
681
+ });
682
+ function handleArrayResult(result, final, index) {
683
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
684
+ final.value[index] = result.value;
685
+ }
686
+ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
687
+ $ZodType.init(inst, def);
688
+ inst._zod.parse = (payload, ctx) => {
689
+ const input = payload.value;
690
+ if (!Array.isArray(input)) {
691
+ payload.issues.push({
692
+ expected: "array",
693
+ code: "invalid_type",
694
+ input,
695
+ inst
696
+ });
697
+ return payload;
698
+ }
699
+ payload.value = Array(input.length);
700
+ const proms = [];
701
+ for (let i = 0; i < input.length; i++) {
702
+ const item = input[i];
703
+ const result = def.element._zod.run({
704
+ value: item,
705
+ issues: []
706
+ }, ctx);
707
+ if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i)));
708
+ else handleArrayResult(result, payload, i);
709
+ }
710
+ if (proms.length) return Promise.all(proms).then(() => payload);
711
+ return payload;
712
+ };
713
+ });
714
+ function handlePropertyResult(result, final, key, input) {
715
+ if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
716
+ if (result.value === void 0) {
717
+ if (key in input) final.value[key] = void 0;
718
+ } else final.value[key] = result.value;
719
+ }
720
+ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
721
+ $ZodType.init(inst, def);
722
+ const _normalized = cached(() => {
723
+ const keys = Object.keys(def.shape);
724
+ for (const k of keys) if (!(def.shape[k] instanceof $ZodType)) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
725
+ const okeys = optionalKeys(def.shape);
726
+ return {
727
+ shape: def.shape,
728
+ keys,
729
+ keySet: new Set(keys),
730
+ numKeys: keys.length,
731
+ optionalKeys: new Set(okeys)
732
+ };
733
+ });
734
+ defineLazy(inst._zod, "propValues", () => {
735
+ const shape = def.shape;
736
+ const propValues = {};
737
+ for (const key in shape) {
738
+ const field = shape[key]._zod;
739
+ if (field.values) {
740
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
741
+ for (const v of field.values) propValues[key].add(v);
742
+ }
743
+ }
744
+ return propValues;
745
+ });
746
+ const generateFastpass = (shape) => {
747
+ const doc = new Doc([
748
+ "shape",
749
+ "payload",
750
+ "ctx"
751
+ ]);
752
+ const normalized = _normalized.value;
753
+ const parseStr = (key) => {
754
+ const k = esc(key);
755
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
756
+ };
757
+ doc.write(`const input = payload.value;`);
758
+ const ids = Object.create(null);
759
+ let counter = 0;
760
+ for (const key of normalized.keys) ids[key] = `key_${counter++}`;
761
+ doc.write(`const newResult = {}`);
762
+ for (const key of normalized.keys) {
763
+ const id = ids[key];
764
+ const k = esc(key);
765
+ doc.write(`const ${id} = ${parseStr(key)};`);
766
+ doc.write(`
767
+ if (${id}.issues.length) {
768
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
769
+ ...iss,
770
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
771
+ })));
772
+ }
773
+
774
+ if (${id}.value === undefined) {
775
+ if (${k} in input) {
776
+ newResult[${k}] = undefined;
777
+ }
778
+ } else {
779
+ newResult[${k}] = ${id}.value;
780
+ }
781
+ `);
782
+ }
783
+ doc.write(`payload.value = newResult;`);
784
+ doc.write(`return payload;`);
785
+ const fn = doc.compile();
786
+ return (payload, ctx) => fn(shape, payload, ctx);
787
+ };
788
+ let fastpass;
789
+ const isObject$1 = isObject;
790
+ const jit = !globalConfig.jitless;
791
+ const allowsEval$1 = allowsEval;
792
+ const fastEnabled = jit && allowsEval$1.value;
793
+ const catchall = def.catchall;
794
+ let value;
795
+ inst._zod.parse = (payload, ctx) => {
796
+ value ?? (value = _normalized.value);
797
+ const input = payload.value;
798
+ if (!isObject$1(input)) {
799
+ payload.issues.push({
800
+ expected: "object",
801
+ code: "invalid_type",
802
+ input,
803
+ inst
804
+ });
805
+ return payload;
806
+ }
807
+ const proms = [];
808
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
809
+ if (!fastpass) fastpass = generateFastpass(def.shape);
810
+ payload = fastpass(payload, ctx);
811
+ } else {
812
+ payload.value = {};
813
+ const shape = value.shape;
814
+ for (const key of value.keys) {
815
+ const el = shape[key];
816
+ const r = el._zod.run({
817
+ value: input[key],
818
+ issues: []
819
+ }, ctx);
820
+ if (r instanceof Promise) proms.push(r.then((r$1) => handlePropertyResult(r$1, payload, key, input)));
821
+ else handlePropertyResult(r, payload, key, input);
822
+ }
823
+ }
824
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
825
+ const unrecognized = [];
826
+ const keySet = value.keySet;
827
+ const _catchall = catchall._zod;
828
+ const t = _catchall.def.type;
829
+ for (const key of Object.keys(input)) {
830
+ if (keySet.has(key)) continue;
831
+ if (t === "never") {
832
+ unrecognized.push(key);
833
+ continue;
834
+ }
835
+ const r = _catchall.run({
836
+ value: input[key],
837
+ issues: []
838
+ }, ctx);
839
+ if (r instanceof Promise) proms.push(r.then((r$1) => handlePropertyResult(r$1, payload, key, input)));
840
+ else handlePropertyResult(r, payload, key, input);
841
+ }
842
+ if (unrecognized.length) payload.issues.push({
843
+ code: "unrecognized_keys",
844
+ keys: unrecognized,
845
+ input,
846
+ inst
847
+ });
848
+ if (!proms.length) return payload;
849
+ return Promise.all(proms).then(() => {
850
+ return payload;
851
+ });
852
+ };
853
+ });
854
+ function handleUnionResults(results, final, inst, ctx) {
855
+ for (const result of results) if (result.issues.length === 0) {
856
+ final.value = result.value;
857
+ return final;
858
+ }
859
+ const nonaborted = results.filter((r) => !aborted(r));
860
+ if (nonaborted.length === 1) {
861
+ final.value = nonaborted[0].value;
862
+ return nonaborted[0];
863
+ }
864
+ final.issues.push({
865
+ code: "invalid_union",
866
+ input: final.value,
867
+ inst,
868
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
869
+ });
870
+ return final;
871
+ }
872
+ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
873
+ $ZodType.init(inst, def);
874
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
875
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
876
+ defineLazy(inst._zod, "values", () => {
877
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
878
+ return void 0;
879
+ });
880
+ defineLazy(inst._zod, "pattern", () => {
881
+ if (def.options.every((o) => o._zod.pattern)) {
882
+ const patterns = def.options.map((o) => o._zod.pattern);
883
+ return /* @__PURE__ */ new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
884
+ }
885
+ return void 0;
886
+ });
887
+ inst._zod.parse = (payload, ctx) => {
888
+ let async = false;
889
+ const results = [];
890
+ for (const option of def.options) {
891
+ const result = option._zod.run({
892
+ value: payload.value,
893
+ issues: []
894
+ }, ctx);
895
+ if (result instanceof Promise) {
896
+ results.push(result);
897
+ async = true;
898
+ } else {
899
+ if (result.issues.length === 0) return result;
900
+ results.push(result);
901
+ }
902
+ }
903
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
904
+ return Promise.all(results).then((results$1) => {
905
+ return handleUnionResults(results$1, payload, inst, ctx);
906
+ });
907
+ };
908
+ });
909
+ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
910
+ $ZodType.init(inst, def);
911
+ inst._zod.optin = "optional";
912
+ inst._zod.optout = "optional";
913
+ defineLazy(inst._zod, "values", () => {
914
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
915
+ });
916
+ defineLazy(inst._zod, "pattern", () => {
917
+ const pattern = def.innerType._zod.pattern;
918
+ return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
919
+ });
920
+ inst._zod.parse = (payload, ctx) => {
921
+ if (def.innerType._zod.optin === "optional") return def.innerType._zod.run(payload, ctx);
922
+ if (payload.value === void 0) return payload;
923
+ return def.innerType._zod.run(payload, ctx);
924
+ };
925
+ });
926
+ function _string(Class, params) {
927
+ return new Class({
928
+ type: "string",
929
+ ...normalizeParams(params)
930
+ });
931
+ }
932
+ function _number(Class, params) {
933
+ return new Class({
934
+ type: "number",
935
+ checks: [],
936
+ ...normalizeParams(params)
937
+ });
938
+ }
939
+ function _boolean(Class, params) {
940
+ return new Class({
941
+ type: "boolean",
942
+ ...normalizeParams(params)
943
+ });
944
+ }
945
+ function _unknown(Class) {
946
+ return new Class({ type: "unknown" });
947
+ }
948
+ const ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
949
+ if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
950
+ $ZodType.init(inst, def);
951
+ inst.def = def;
952
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
953
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
954
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
955
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
956
+ inst.check = (...checks) => {
957
+ return inst.clone({
958
+ ...def,
959
+ checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
960
+ check: ch,
961
+ def: { check: "custom" },
962
+ onattach: []
963
+ } } : ch)]
964
+ });
965
+ };
966
+ inst.clone = (_def, params) => clone(inst, _def, params);
967
+ inst.brand = () => inst;
968
+ inst.register = ((reg, meta) => {
969
+ reg.add(inst, meta);
970
+ return inst;
971
+ });
972
+ });
973
+ const ZodMiniString = /* @__PURE__ */ $constructor("ZodMiniString", (inst, def) => {
974
+ $ZodString.init(inst, def);
975
+ ZodMiniType.init(inst, def);
976
+ });
977
+ function string(params) {
978
+ return _string(ZodMiniString, params);
979
+ }
980
+ const ZodMiniNumber = /* @__PURE__ */ $constructor("ZodMiniNumber", (inst, def) => {
981
+ $ZodNumber.init(inst, def);
982
+ ZodMiniType.init(inst, def);
983
+ });
984
+ function number(params) {
985
+ return _number(ZodMiniNumber, params);
986
+ }
987
+ const ZodMiniBoolean = /* @__PURE__ */ $constructor("ZodMiniBoolean", (inst, def) => {
988
+ $ZodBoolean.init(inst, def);
989
+ ZodMiniType.init(inst, def);
990
+ });
991
+ function boolean(params) {
992
+ return _boolean(ZodMiniBoolean, params);
993
+ }
994
+ const ZodMiniUnknown = /* @__PURE__ */ $constructor("ZodMiniUnknown", (inst, def) => {
995
+ $ZodUnknown.init(inst, def);
996
+ ZodMiniType.init(inst, def);
997
+ });
998
+ function unknown() {
999
+ return _unknown(ZodMiniUnknown);
1000
+ }
1001
+ const ZodMiniArray = /* @__PURE__ */ $constructor("ZodMiniArray", (inst, def) => {
1002
+ $ZodArray.init(inst, def);
1003
+ ZodMiniType.init(inst, def);
1004
+ });
1005
+ function array(element, params) {
1006
+ return new ZodMiniArray({
1007
+ type: "array",
1008
+ element,
1009
+ ...normalizeParams(params)
1010
+ });
1011
+ }
1012
+ const ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
1013
+ $ZodObject.init(inst, def);
1014
+ ZodMiniType.init(inst, def);
1015
+ defineLazy(inst, "shape", () => def.shape);
1016
+ });
1017
+ function object(shape, params) {
1018
+ const def = {
1019
+ type: "object",
1020
+ get shape() {
1021
+ assignProp(this, "shape", { ...shape });
1022
+ return this.shape;
1023
+ },
1024
+ ...normalizeParams(params)
1025
+ };
1026
+ return new ZodMiniObject(def);
1027
+ }
1028
+ function looseObject(shape, params) {
1029
+ return new ZodMiniObject({
1030
+ type: "object",
1031
+ get shape() {
1032
+ assignProp(this, "shape", { ...shape });
1033
+ return this.shape;
1034
+ },
1035
+ catchall: unknown(),
1036
+ ...normalizeParams(params)
1037
+ });
1038
+ }
1039
+ const ZodMiniUnion = /* @__PURE__ */ $constructor("ZodMiniUnion", (inst, def) => {
1040
+ $ZodUnion.init(inst, def);
1041
+ ZodMiniType.init(inst, def);
1042
+ });
1043
+ function union(options, params) {
1044
+ return new ZodMiniUnion({
1045
+ type: "union",
1046
+ options,
1047
+ ...normalizeParams(params)
1048
+ });
1049
+ }
1050
+ const ZodMiniOptional = /* @__PURE__ */ $constructor("ZodMiniOptional", (inst, def) => {
1051
+ $ZodOptional.init(inst, def);
1052
+ ZodMiniType.init(inst, def);
1053
+ });
1054
+ function optional(innerType) {
1055
+ return new ZodMiniOptional({
1056
+ type: "optional",
1057
+ innerType
1058
+ });
1059
+ }
1060
+ const zContentSchema = looseObject({
1061
+ generationConfiguration: looseObject({
1062
+ includeCodeExecutionTypesImport: boolean(),
1063
+ includeSchemaTypesImport: boolean(),
1064
+ includesRetrievalImport: optional(boolean()),
1065
+ isAudioOutput: boolean(),
1066
+ isStreamingConfigEnabled: boolean(),
1067
+ isColab: boolean(),
1068
+ requiresParts: boolean(),
1069
+ requiresFunctionCalling: boolean(),
1070
+ requiresCodeExecution: boolean()
1071
+ }),
1072
+ generateContentParameters: object({
1073
+ model: string(),
1074
+ contents: array(object({
1075
+ role: string(),
1076
+ parts: array(union([
1077
+ object({ isLast: boolean() }),
1078
+ object({
1079
+ isLast: boolean(),
1080
+ text: string()
1081
+ }),
1082
+ object({
1083
+ isLast: boolean(),
1084
+ functionCall: object({
1085
+ name: string(),
1086
+ parameters: string()
1087
+ })
1088
+ }),
1089
+ object({
1090
+ isLast: boolean(),
1091
+ functionResponse: object({
1092
+ name: string(),
1093
+ response: string()
1094
+ })
1095
+ }),
1096
+ object({
1097
+ isLast: boolean(),
1098
+ inlineData: object({
1099
+ data: string(),
1100
+ splitData: array(string()),
1101
+ mimeType: string()
1102
+ }),
1103
+ fileData: object({
1104
+ mimeType: string(),
1105
+ fileIndex: number(),
1106
+ fileName: string()
1107
+ })
1108
+ })
1109
+ ])),
1110
+ isLast: optional(boolean())
1111
+ })),
1112
+ config: looseObject({
1113
+ thinkingConfig: object({ thinkingBudget: string() }),
1114
+ stopSequences: array(unknown()),
1115
+ responseMimeType: optional(string()),
1116
+ responseModalities: array(unknown()),
1117
+ safetySettings: array(unknown()),
1118
+ tools: array(union([
1119
+ object({ googleSearch: looseObject({}) }),
1120
+ object({ urlContext: looseObject({}) }),
1121
+ object({ functionDeclarations: array(object({
1122
+ name: string(),
1123
+ description: string(),
1124
+ parameters: string(),
1125
+ isLast: boolean()
1126
+ })) })
1127
+ ]))
1128
+ })
1129
+ })
1130
+ });
1131
+ const doGoogleAiStudioAutomation = (dir = process.cwd()) => {
1132
+ const watcher = fs.watch(dir);
1133
+ const handle = func_debounce(async () => {
1134
+ const names = fs.readdirSync(dir);
1135
+ const contentNames = names.filter((name) => name.endsWith(".contents.json"));
1136
+ for (const contentFilename of contentNames) {
1137
+ const contentFilepath = path.join(dir, contentFilename);
1138
+ const basename = contentFilename.replace(".contents.json", "");
1139
+ await parseContent(basename, contentFilepath, names).catch(console.error);
1140
+ }
1141
+ }, 200);
1142
+ const parseContent = async (basename, contentFilepath, filenames) => {
1143
+ console.log(magenta("开始处理文件"), path.relative(process.cwd(), contentFilepath));
1144
+ const fileData = await zContentSchema.parse(JSON.parse(fs.readFileSync(contentFilepath, "utf-8")));
1145
+ const { contents } = fileData.generateContentParameters;
1146
+ const latestContent = contents.at(-1);
1147
+ if (!latestContent) return;
1148
+ if (latestContent.role !== "user") return;
1149
+ const functionResponsePart = latestContent.parts.find((p) => "functionResponse" in p);
1150
+ if (!functionResponsePart) return;
1151
+ if (functionResponsePart.functionResponse.response !== "") return;
1152
+ const modelContent = contents.findLast((content) => {
1153
+ return content.role === "model" && content.parts.find((p) => "functionCall" in p);
1154
+ });
1155
+ if (!modelContent) return;
1156
+ const functionCallPart = modelContent.parts.find((p) => "functionCall" in p)?.functionCall;
1157
+ if (!functionCallPart) return;
1158
+ const modelIndex = contents.indexOf(modelContent);
1159
+ const hash = createHash("sha256").update(`INDEX:${modelIndex}`).update(JSON.stringify(modelContent)).digest("hex").slice(0, 8);
1160
+ const taskFilename = `${basename}.${functionCallPart.name}.${modelIndex}-${hash}.function_call.json`;
1161
+ if (filenames.includes(taskFilename)) return;
1162
+ console.log(blue("收到 functionCallPart 任务请求"), functionCallPart);
1163
+ const scriptFilepath = iter_first_not_null(function* () {
1164
+ for (const scriptFilename of [`${functionCallPart.name}.function_call.js`, `${functionCallPart.name}.function_call.ts`]) yield path.join(dir, scriptFilename);
1165
+ }(), (scriptFilepath$1) => {
1166
+ if (fs.existsSync(scriptFilepath$1)) return scriptFilepath$1;
1167
+ });
1168
+ if (!scriptFilepath) console.warn("找不到任务处理工具");
1169
+ else {
1170
+ const { functionCall } = await import(pathToFileURL(scriptFilepath).href);
1171
+ const input = JSON.parse(functionCallPart.parameters);
1172
+ try {
1173
+ console.log(cyan("开始执行任务"));
1174
+ const output = await functionCall(input);
1175
+ console.log(green("生成任务结果:"), taskFilename);
1176
+ fs.writeFileSync(path.join(dir, taskFilename), JSON.stringify({
1177
+ input,
1178
+ output
1179
+ }, null, 2));
1180
+ } catch (e) {
1181
+ console.log(red("任务执行失败:"), e);
1182
+ }
1183
+ }
1184
+ };
1185
+ watcher.on("change", (eventType) => {
1186
+ if (eventType === "delete" || eventType === "unlink") return;
1187
+ handle();
1188
+ });
1189
+ handle();
1190
+ console.log(gray("\nWatching for file changes... Press Ctrl+C to exit."));
1191
+ };
1192
+ if (import_meta_ponyfill_esmodule(import.meta).main) doGoogleAiStudioAutomation(process.argv[2]);