semantic-golfer 0.0.0 → 1.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.
@@ -0,0 +1,2072 @@
1
+ import { fileURLToPath as Hr } from "node:url";
2
+ import M from "node:path";
3
+ import { app as P, shell as It, dialog as Wr, ipcMain as xt, Menu as Se, BrowserWindow as kr, nativeTheme as pe } from "electron";
4
+ import re, { readFile as Qr } from "node:fs/promises";
5
+ import { createHash as Yr, randomUUID as Kr } from "node:crypto";
6
+ import { State as Jr, withLock as se, AsyncDisposeAggregator as Zr, LongTimeout as kt, isLockActive as Dr } from "lifecycle-utils";
7
+ import { getLlama as en, LlamaLogLevel as tn, createModelDownloader as rn } from "node-llama-cpp";
8
+ import { execFile as nn } from "node:child_process";
9
+ import { promisify as sn } from "node:util";
10
+ import on from "electron-updater";
11
+ const de = [
12
+ {
13
+ id: "gemma-q8",
14
+ name: "Gemma 4",
15
+ parameters: "5B E2B",
16
+ quant: "Q8_0",
17
+ size: "5.0 GB",
18
+ uri: "hf:giladgd/gemma-4-E2B-it-GGUF:Q8_0"
19
+ },
20
+ {
21
+ id: "gemma-q6",
22
+ name: "Gemma 4",
23
+ parameters: "5B E2B",
24
+ quant: "Q6_K",
25
+ size: "3.9 GB",
26
+ uri: "hf:giladgd/gemma-4-E2B-it-GGUF:Q6_K"
27
+ },
28
+ {
29
+ id: "qwen-2b",
30
+ name: "Qwen 3.5",
31
+ parameters: "2B",
32
+ quant: "Q4_K_M",
33
+ size: "1.3 GB",
34
+ uri: "hf:unsloth/Qwen3.5-2B-GGUF:Q4_K_M"
35
+ },
36
+ {
37
+ id: "qwen-0.8b",
38
+ name: "Qwen 3.5",
39
+ parameters: "0.8B",
40
+ quant: "Q8_0",
41
+ size: "0.8 GB",
42
+ uri: "hf:unsloth/Qwen3.5-0.8B-GGUF:Q8_0"
43
+ }
44
+ ];
45
+ function Re(e) {
46
+ const r = de.find((i) => i.id === e);
47
+ if (r == null)
48
+ throw new Error("Unknown model");
49
+ return r;
50
+ }
51
+ const an = ["noul", "choice", "score"], Dt = { noul: 2, choice: 50, score: 10 };
52
+ function ln(e) {
53
+ const r = vt(e?.input);
54
+ if (r != null)
55
+ return r;
56
+ if (e.additionalInputs != null) {
57
+ if (!Array.isArray(e.additionalInputs) || e.additionalInputs.length > 6)
58
+ return "Use at most seven questions per document.";
59
+ for (const i of e.additionalInputs) {
60
+ const t = vt(i);
61
+ if (t != null)
62
+ return t;
63
+ if (i.document !== e.input.document)
64
+ return "All questions must use the same document.";
65
+ }
66
+ }
67
+ }
68
+ function cn(e, r) {
69
+ return typeof e == "string" && e.length <= 1e3 && (r === "noul" || e.trim().length > 0);
70
+ }
71
+ function Pr({ type: e, criteria: r }) {
72
+ if (e === "noul")
73
+ return r;
74
+ let i = r.length;
75
+ for (; i > 0; ) {
76
+ const t = r[i - 1];
77
+ if (typeof t != "string" || t.length > 1e3 || t.trim())
78
+ break;
79
+ i--;
80
+ }
81
+ return i === r.length ? r : r.slice(0, i);
82
+ }
83
+ function vt(e) {
84
+ if (e == null || !an.includes(e.type))
85
+ return "Choose a decision type.";
86
+ if (typeof e.document != "string" || e.document.length > 32e3)
87
+ return "Keep the document under 32,000 characters.";
88
+ if (typeof e.instruction != "string" || !e.instruction.trim() || e.instruction.length > 1e3)
89
+ return "Enter a question (up to 1,000 characters).";
90
+ if (!Array.isArray(e.criteria) || e.criteria.length < 2 || e.criteria.length > Dt[e.type])
91
+ return e.type === "noul" ? "Use exactly two criteria." : `Use between 2 and ${Dt[e.type]} criteria.`;
92
+ const r = Pr(e);
93
+ if (r.length < 2)
94
+ return "Enter at least two nonempty criteria.";
95
+ if (r.some((i) => !cn(i, e.type)))
96
+ return e.type === "noul" ? "Use text of up to 1,000 characters for each criterion." : "Fill in each criterion (up to 1,000 characters).";
97
+ }
98
+ function un(e) {
99
+ const r = vt(e);
100
+ if (r != null)
101
+ throw new Error(r);
102
+ const { type: i, instruction: t } = e, s = Pr(e);
103
+ return i === "noul" ? { type: i, instruction: t, criteria: { true: s[0], false: s[1] } } : i === "choice" ? { type: i, instruction: t, criteria: Object.fromEntries(s.map((l, a) => [String(a), l])) } : { type: i, instruction: t, criteria: s };
104
+ }
105
+ const dn = { models: {}, localModels: [], scores: [] }, v = new Jr(dn);
106
+ let Pt, ve, ce, ge;
107
+ const we = /* @__PURE__ */ new Map(), Cr = /* @__PURE__ */ new Map(), $t = [v, "inference"];
108
+ function Et() {
109
+ return M.join(P.getPath("userData"), "models");
110
+ }
111
+ function oe(e) {
112
+ const r = Cr.get(e);
113
+ return r ?? (Re(e), M.join(Et(), `${e}.gguf`));
114
+ }
115
+ function Y(e, r) {
116
+ v.state = {
117
+ ...v.state,
118
+ models: { ...v.state.models, [e]: { downloaded: !1, ...v.state.models[e], ...r } }
119
+ };
120
+ }
121
+ async function hn() {
122
+ await Promise.all(de.map(async ({ id: e }) => {
123
+ const r = await re.stat(oe(e)).catch(() => {
124
+ });
125
+ Y(e, { downloaded: r != null && r.isFile() && r.size > 0 });
126
+ }));
127
+ }
128
+ function fn(e) {
129
+ const r = Re(e);
130
+ if (we.has(e) || v.state.models[e]?.downloaded || v.state.models[e]?.deleting)
131
+ return;
132
+ const i = new AbortController();
133
+ we.set(e, i), Y(e, { error: void 0, download: { status: "downloading", downloadedSize: 0, totalSize: 0 } }), (async () => {
134
+ let t;
135
+ try {
136
+ let s = 0;
137
+ t = await rn({
138
+ modelUri: r.uri,
139
+ dirPath: M.dirname(oe(e)),
140
+ fileName: M.basename(oe(e)),
141
+ onProgress({ downloadedSize: l, totalSize: a, estimatedTimeLeft: u, averageSpeed: o }) {
142
+ i.signal.aborted || Date.now() - s < 100 && l < a || (s = Date.now(), Y(e, { download: {
143
+ status: "downloading",
144
+ downloadedSize: l,
145
+ totalSize: a,
146
+ speed: Number.isFinite(o) && o >= 0 ? o : void 0,
147
+ eta: o > 0 && Number.isFinite(u) ? u : void 0
148
+ } }));
149
+ }
150
+ }), i.signal.throwIfAborted(), await t.download({ signal: i.signal }), i.signal.throwIfAborted(), Y(e, { downloaded: !0, download: void 0 }), v.state.loadedModelId == null && v.state.loading == null && _r(e);
151
+ } catch (s) {
152
+ await t?.cancel().catch(console.error), Y(e, { download: void 0, error: i.signal.aborted ? void 0 : String(s) });
153
+ } finally {
154
+ we.delete(e);
155
+ }
156
+ })();
157
+ }
158
+ function pn(e) {
159
+ Re(e);
160
+ const r = v.state.models[e]?.download;
161
+ r != null && (Y(e, { download: { ...r, status: "canceling" } }), we.get(e)?.abort());
162
+ }
163
+ function _r(e) {
164
+ const r = oe(e);
165
+ if (!v.state.models[e]?.downloaded)
166
+ throw new Error("Download the model first.");
167
+ if (!(v.state.models[e]?.deleting || v.state.loading != null || v.state.loadedModelId === e))
168
+ return v.state = { ...v.state, loadedModelId: void 0, loading: { modelId: e, progress: 0, stage: "model" }, error: void 0 }, se($t, async () => {
169
+ try {
170
+ await yt(), Pt ??= await en({ logLevel: tn.error }), ve = await Pt.loadModel({
171
+ modelPath: r,
172
+ onLoadProgress(i) {
173
+ v.state = { ...v.state, loading: { modelId: e, progress: i, stage: "model" } };
174
+ }
175
+ }), v.state = { ...v.state, loading: { modelId: e, progress: 1, stage: "context" } }, ce = await ve.createDecisionContext({ contextSize: { max: 4096 }, parallelQuestions: 3 }), v.state = { ...v.state, loading: { modelId: e, progress: 1, stage: "warmup" } }, await ce.warmup(), v.state = { ...v.state, loadedModelId: e, loading: void 0 };
176
+ } catch (i) {
177
+ await yt().catch((t) => {
178
+ i = t;
179
+ }), v.state = { ...v.state, loading: void 0, error: String(i) };
180
+ }
181
+ });
182
+ }
183
+ async function yt() {
184
+ v.state = { ...v.state, loadedModelId: void 0 }, ge ??= new Zr().add(async () => {
185
+ await ce?.dispose();
186
+ }).add(async () => {
187
+ await ve?.dispose();
188
+ }).dispose().catch((e) => {
189
+ throw new Error(`Could not fully unload the model. Restart the app before loading another model. ${String(e)}`);
190
+ }), await ge, ce = void 0, ve = void 0, ge = void 0;
191
+ }
192
+ async function mn(e) {
193
+ oe(e?.modelId);
194
+ const r = ln(e);
195
+ if (r != null)
196
+ throw new Error(r);
197
+ const i = [e.input, ...e.additionalInputs ?? []], t = Object.fromEntries(i.map((s, l) => [String(l), un(s)]));
198
+ return await se($t, async () => {
199
+ if (ce == null || v.state.loadedModelId !== e.modelId)
200
+ throw new Error("The selected model is no longer loaded.");
201
+ const s = performance.now(), l = await ce.decide(e.input.document, t);
202
+ return {
203
+ answer: l[0],
204
+ additionalAnswers: e.additionalInputs == null ? void 0 : i.slice(1).map((a, u) => l[String(u + 1)]),
205
+ duration: performance.now() - s
206
+ };
207
+ });
208
+ }
209
+ async function gn(e) {
210
+ const { canceled: r, filePaths: i } = await Wr.showOpenDialog(e, {
211
+ title: "Select a model",
212
+ filters: [{ name: "GGUF models", extensions: ["gguf"] }],
213
+ properties: ["openFile"]
214
+ });
215
+ if (r || i[0] == null)
216
+ return;
217
+ const t = await re.realpath(i[0]), s = await re.stat(t);
218
+ if (!s.isFile() || s.size === 0 || M.extname(t).toLowerCase() !== ".gguf")
219
+ throw new Error("Select a nonempty GGUF model file.");
220
+ const l = de.find(({ id: u }) => oe(u) === t);
221
+ if (l != null)
222
+ return Y(l.id, { downloaded: !0 }), l.id;
223
+ const a = `local:${Yr("sha256").update(`${t}\0${s.size}\0${s.mtimeMs}`).digest("hex")}`;
224
+ return Cr.set(a, t), v.state.localModels.some((u) => u.id === a) || (v.state = { ...v.state, localModels: [...v.state.localModels, { id: a, name: M.basename(t) }] }), Y(a, { downloaded: !0 }), a;
225
+ }
226
+ async function wn() {
227
+ await re.mkdir(Et(), { recursive: !0 });
228
+ const e = await It.openPath(Et());
229
+ if (e)
230
+ throw new Error(e);
231
+ }
232
+ async function vn(e) {
233
+ if (Re(e), v.state.models[e]?.deleting || !v.state.models[e]?.downloaded || v.state.loading != null)
234
+ return;
235
+ const r = v.state.loadedModelId === e;
236
+ Y(e, { deleting: !0, error: void 0 });
237
+ try {
238
+ await se($t, async () => {
239
+ (r || ge != null) && await yt(), await re.rm(oe(e), { force: !0 }), Y(e, { downloaded: !1 });
240
+ });
241
+ } catch (i) {
242
+ throw Y(e, { error: String(i) }), i;
243
+ } finally {
244
+ Y(e, { deleting: !1 });
245
+ }
246
+ }
247
+ function En() {
248
+ let e, r;
249
+ return {
250
+ promise: new Promise((i, t) => {
251
+ e = i, r = t;
252
+ }),
253
+ resolve: e,
254
+ reject: r
255
+ };
256
+ }
257
+ const yn = Math.random.bind(Math), Rn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
258
+ function Tn(e = 21) {
259
+ let r = "", i = e;
260
+ for (; i--; ) r += Rn[yn() * 64 | 0];
261
+ return r;
262
+ }
263
+ const In = 6e4, Gr = (e) => e, $n = Gr, { clearTimeout: Ct, setTimeout: An } = globalThis;
264
+ function Sn(e, r) {
265
+ const { post: i, on: t, off: s = () => {
266
+ }, eventNames: l = [], serialize: a = Gr, deserialize: u = $n, resolver: o, bind: g = "rpc", timeout: n = In, proxify: c = !0 } = r;
267
+ let d = !1;
268
+ const p = /* @__PURE__ */ new Map();
269
+ let A, h;
270
+ async function q(E, S, L, w) {
271
+ if (d) throw new Error(`[birpc] rpc is closed, cannot call "${E}"`);
272
+ const C = {
273
+ m: E,
274
+ a: S,
275
+ t: "q"
276
+ };
277
+ w && (C.o = !0);
278
+ const K = async (m) => i(a(m));
279
+ if (L) {
280
+ await K(C);
281
+ return;
282
+ }
283
+ if (A) try {
284
+ await A;
285
+ } finally {
286
+ A = void 0;
287
+ }
288
+ let { promise: B, resolve: X, reject: ee } = En();
289
+ const F = Tn();
290
+ C.i = F;
291
+ let te;
292
+ async function le(m = C) {
293
+ return n >= 0 && (te = An(() => {
294
+ try {
295
+ if (r.onTimeoutError?.call(h, E, S) !== !0) throw new Error(`[birpc] timeout on calling "${E}"`);
296
+ } catch (f) {
297
+ ee(f);
298
+ }
299
+ p.delete(F);
300
+ }, n), typeof te == "object" && (te = te.unref?.())), p.set(F, {
301
+ resolve: X,
302
+ reject: ee,
303
+ timeoutId: te,
304
+ method: E
305
+ }), await K(m), B;
306
+ }
307
+ try {
308
+ r.onRequest ? await r.onRequest.call(h, C, le, X) : await le();
309
+ } catch (m) {
310
+ if (r.onGeneralError?.call(h, m) !== !0) throw m;
311
+ return;
312
+ } finally {
313
+ Ct(te), p.delete(F);
314
+ }
315
+ return B;
316
+ }
317
+ const x = {
318
+ $call: (E, ...S) => q(E, S, !1),
319
+ $callOptional: (E, ...S) => q(E, S, !1, !0),
320
+ $callEvent: (E, ...S) => q(E, S, !0),
321
+ $callRaw: (E) => q(E.method, E.args, E.event, E.optional),
322
+ $rejectPendingCalls: U,
323
+ get $closed() {
324
+ return d;
325
+ },
326
+ get $meta() {
327
+ return r.meta;
328
+ },
329
+ $close: _,
330
+ $functions: e
331
+ };
332
+ c ? h = new Proxy({}, { get(E, S) {
333
+ if (Object.hasOwn(x, S)) return x[S];
334
+ if (S === "then" && !l.includes("then") && !("then" in e)) return;
335
+ const L = (...C) => q(S, C, !0);
336
+ if (l.includes(S))
337
+ return L.asEvent = L, L;
338
+ const w = (...C) => q(S, C, !1);
339
+ return w.asEvent = L, w;
340
+ } }) : h = x;
341
+ function _(E) {
342
+ d = !0, p.forEach(({ reject: S, method: L }) => {
343
+ const w = /* @__PURE__ */ new Error(`[birpc] rpc is closed, cannot call "${L}"`);
344
+ if (E)
345
+ return E.cause ??= w, S(E);
346
+ S(w);
347
+ }), p.clear(), s(j);
348
+ }
349
+ function U(E) {
350
+ const S = Array.from(p.values()).map(({ method: L, reject: w }) => E ? E({
351
+ method: L,
352
+ reject: w
353
+ }) : w(/* @__PURE__ */ new Error(`[birpc]: rejected pending call "${L}".`)));
354
+ return p.clear(), S;
355
+ }
356
+ async function j(E, ...S) {
357
+ let L;
358
+ try {
359
+ L = u(E);
360
+ } catch (w) {
361
+ if (r.onGeneralError?.call(h, w) !== !0) throw w;
362
+ return;
363
+ }
364
+ if (L.t === "q") {
365
+ const { m: w, a: C, o: K } = L;
366
+ let B, X, ee = await (o ? o.call(h, w, e[w]) : e[w]);
367
+ if (K && (ee ||= () => {
368
+ }), !ee) X = /* @__PURE__ */ new Error(`[birpc] function "${w}" not found`);
369
+ else try {
370
+ B = await ee.apply(g === "rpc" ? h : e, C);
371
+ } catch (F) {
372
+ X = F;
373
+ }
374
+ if (L.i) {
375
+ if (X && r.onFunctionError && r.onFunctionError.call(h, X, w, C) === !0)
376
+ return;
377
+ if (!X) try {
378
+ await i(a({
379
+ t: "s",
380
+ i: L.i,
381
+ r: B
382
+ }), ...S);
383
+ return;
384
+ } catch (F) {
385
+ if (X = F, r.onGeneralError?.call(h, F, w, C) !== !0) throw F;
386
+ }
387
+ try {
388
+ await i(a({
389
+ t: "s",
390
+ i: L.i,
391
+ e: X
392
+ }), ...S);
393
+ } catch (F) {
394
+ if (r.onGeneralError?.call(h, F, w, C) !== !0) throw F;
395
+ }
396
+ }
397
+ } else {
398
+ const { i: w, r: C, e: K } = L, B = p.get(w);
399
+ B && (Ct(B.timeoutId), K ? B.reject(K) : B.resolve(C)), p.delete(w);
400
+ }
401
+ }
402
+ return A = t(j), h;
403
+ }
404
+ function bn(e, r, i, t) {
405
+ let s;
406
+ return Sn(t, {
407
+ post: (l) => i.webContents.send(e, l),
408
+ on: (l) => {
409
+ s = (a, u) => {
410
+ a.sender === i.webContents && l(u);
411
+ }, xt.on(r, s);
412
+ },
413
+ off: () => {
414
+ s != null && xt.off(r, s);
415
+ },
416
+ serialize: (l) => JSON.stringify(l, (a, u) => u instanceof Error ? String(u) : u),
417
+ deserialize: (l) => JSON.parse(l)
418
+ });
419
+ }
420
+ const _t = {
421
+ animal: ["Names an animal", "Does the text contain an actual animal name? A category label is not an animal name.", "An animal name like cat, dog, or fox appears in the text.", "No animal name appears in the text."],
422
+ help: ["Asks for help", "Does the writer ask someone for help?", "The writer requests assistance or asks someone to help."],
423
+ urgent: ["Needs action now", "Does the text explicitly call for immediate action?", "The message requests action now, immediately, or describes an emergency."],
424
+ apology: ["Apologizes", "Does the writer apologize?", "The writer expresses regret for something and says sorry or apologizes."],
425
+ weather: ["Names bad weather", "Does the text name a bad-weather condition?", "A concrete condition is named, such as rain, snow, or a storm. The generic phrase bad weather alone does not count. Do not infer unfinished words."],
426
+ alternative: ["Proposes another plan", "Does the writer propose a replacement plan?", "The writer suggests doing something else instead of the original plan."],
427
+ food: ["Names a food", "Does the text name a food?", "The text names a food such as pizza, bread, soup, or rice. The generic word food alone does not count. Do not infer unfinished words."],
428
+ question: ["Asks a question", "Does the quoted Text contain an interrogative sentence? Judge only the quoted Text. Unfinished words do not count; do not guess what comes next.", "The text contains a question.", "The text contains no questions."],
429
+ excited: ["Shows excitement", "Does the writer express excitement?", "The writer expresses enthusiasm, delight, or eagerness about something."],
430
+ thanks: ["Expresses thanks", "Does the writer thank someone?", "The text includes thanks, thank you, or another expression of gratitude."],
431
+ time: ["Gives a time", "Does the text mention a time or day?", "A specific time or day is mentioned, such as noon, six, Friday, or tomorrow."],
432
+ place: ["Names a location", "Does the text mention a place or location?", "A concrete place is named, such as a house, river, bridge, park, kitchen, or office."],
433
+ invite: ["Invites someone", "Does the writer invite someone to take part?", "The writer invites the reader to join an activity or come somewhere."],
434
+ warning: ["Warns of a risk", "Does the message warn someone about a danger or problem?", "The writer warns of a specific risk or harmful possibility."],
435
+ reason: ["Explains why", "Does the message give a reason for a situation, action, or request?", "A reason is given for a situation, request, or action, for example using because or so."],
436
+ condition: ["Sets a condition", "Does the message make an action depend on a condition?", "An action or outcome depends on an explicit condition, for example if or unless something happens."],
437
+ offer: ["Offers assistance", "Does the writer offer to help someone?", "The writer offers their own help or assistance."],
438
+ promise: ["Makes a commitment", "Does the writer commit to a future action?", "The writer states something they will do or promises to do it."],
439
+ contrast: ["Contrasts two facts", "Does the text contrast two facts or qualities?", "The text presents contrasting preferences or facts, often joined by but, although, or despite."],
440
+ refuse: ["Declines a request", "Does the writer decline or refuse something?", "The writer clearly says they cannot or will not accept, attend, or do something."],
441
+ repair: ["Offers to make amends", "Does the writer offer to put right something that went wrong?", "The writer proposes a concrete repair, replacement, repayment, or corrective action."],
442
+ quantity: ["Gives a quantity", "Does the message state how many or how much?", "There is a count of things, people, or payments, expressed in digits or words."],
443
+ transport: ["Names a vehicle", "Does the text name a vehicle?", "The text names a vehicle, such as a train, bus, bike, car, or boat. Do not infer unfinished words."],
444
+ sequence: ["Orders two actions", "Does the message explicitly put two actions in order?", "The message says one action should happen before or after another, or gives a first step and then a second."],
445
+ compare: ["Makes a comparison", "Does the message contain an explicit comparison?", "A comparison is made, for example saying one thing is cheaper, faster, higher, or lower than another."],
446
+ consequence: ["States a consequence", "Does the message state what will result from an action or event?", "The message explicitly connects an action or event to a resulting outcome."],
447
+ permission: ["Asks permission", "Does the writer ask permission to do something?", "The writer asks whether they may do a specific action."],
448
+ compromise: ["Proposes a compromise", "Does the writer propose meeting someone halfway?", "The writer proposes a middle ground or concession that accommodates two different needs or preferences."],
449
+ choice: ["Offers a choice", "Does the writer give the reader a choice between alternatives?", "The reader is offered two or more specific alternatives to choose from."],
450
+ money: ["Mentions a price", "Does the text mention an amount of money?", "The text mentions a sum of money, such as $5 or ten dollars."],
451
+ reassure: ["Reassures someone", "Does the writer reassure someone who might worry?", "The writer explicitly offers reassurance that a situation is safe, manageable, or will be taken care of."],
452
+ credit: ["Credits someone else", "Does the writer give someone else credit for a contribution?", "Another person or group is acknowledged for a helpful action, idea, or achievement."],
453
+ instructions: ["Gives an instruction", "Does the message tell the reader to do a specific action?", "The writer directly instructs the reader to do something concrete."]
454
+ };
455
+ function I(e, r, i, ...t) {
456
+ const s = t.map((l) => _t[l]);
457
+ return {
458
+ id: e,
459
+ title: r,
460
+ limit: i,
461
+ labels: s.map(([l]) => l),
462
+ questions: t.map((l) => {
463
+ const [, a, u, o] = _t[l];
464
+ return o != null ? {
465
+ type: "noul",
466
+ instruction: a,
467
+ criteria: [u, o]
468
+ } : {
469
+ type: "noul",
470
+ instruction: `${a} Answer yes if ${u[0].toLowerCase()}${u.slice(1)} Answer no otherwise.`,
471
+ criteria: ["Yes", "No"]
472
+ };
473
+ })
474
+ };
475
+ }
476
+ const qn = [
477
+ { id: 1, title: "Make yourself understood", skill: "Combine a topic, a purpose, and a tone.", rounds: [
478
+ I("1-1", "A small emergency", 120, "animal", "help", "urgent"),
479
+ I("1-2", "Change of plans", 110, "apology", "weather", "alternative"),
480
+ I("1-3", "A bright idea", 100, "food", "question", "excited")
481
+ ] },
482
+ { id: 2, title: "Say what you need", skill: "Make requests and invitations precise.", rounds: [
483
+ I("2-1", "Lunch is on me", 100, "food", "invite", "time"),
484
+ I("2-2", "A helpful neighbor", 100, "thanks", "animal", "offer"),
485
+ I("2-3", "A clear handoff", 95, "instructions", "place", "time")
486
+ ] },
487
+ { id: 3, title: "Give it a reason", skill: "Connect a request or change to its cause.", rounds: [
488
+ I("3-1", "The rainy picnic", 125, "weather", "alternative", "reason", "invite"),
489
+ I("3-2", "Running late", 120, "apology", "transport", "reason", "time"),
490
+ I("3-3", "A hungry guest", 115, "food", "help", "reason", "thanks")
491
+ ] },
492
+ { id: 4, title: "Plan ahead", skill: "Use conditions and sequences without losing clarity.", rounds: [
493
+ I("4-1", "Weather permitting", 120, "condition", "weather", "invite", "place"),
494
+ I("4-2", "Dinner in order", 115, "food", "sequence", "instructions", "time"),
495
+ I("4-3", "The early train", 115, "transport", "condition", "promise", "time"),
496
+ I("4-4", "A careful crossing", 115, "warning", "sequence", "instructions", "reason")
497
+ ] },
498
+ { id: 5, title: "Small repairs", skill: "Take responsibility and propose a useful next step.", rounds: [
499
+ I("5-1", "The broken mug", 140, "apology", "repair", "promise", "time", "reason"),
500
+ I("5-2", "Dinner went wrong", 135, "food", "apology", "repair", "choice", "time"),
501
+ I("5-3", "Sorry I can't make it", 130, "refuse", "apology", "reason", "alternative", "time"),
502
+ I("5-4", "A borrowed bicycle", 130, "transport", "thanks", "promise", "time", "place")
503
+ ] },
504
+ { id: 6, title: "Make room for both", skill: "Compare choices and balance different needs.", rounds: [
505
+ I("6-1", "A quieter dinner", 135, "food", "contrast", "compare", "choice", "question"),
506
+ I("6-2", "Meet halfway", 130, "compromise", "place", "time", "invite", "reason"),
507
+ I("6-3", "The cheaper journey", 125, "transport", "compare", "money", "choice", "question"),
508
+ I("6-4", "A little reassurance", 125, "animal", "warning", "reassure", "offer", "condition")
509
+ ] },
510
+ { id: 7, title: "Useful details", skill: "Fit six pieces of useful information into one message.", rounds: [
511
+ I("7-1", "Soup for the team", 155, "food", "quantity", "time", "place", "invite", "question"),
512
+ I("7-2", "A rescue plan", 150, "animal", "help", "urgent", "place", "warning", "instructions"),
513
+ I("7-3", "A missed delivery", 145, "apology", "repair", "promise", "time", "choice", "place"),
514
+ I("7-4", "The last bus", 140, "transport", "warning", "condition", "consequence", "alternative", "time"),
515
+ I("7-5", "A generous offer", 140, "thanks", "credit", "offer", "time", "place", "question")
516
+ ] },
517
+ { id: 8, title: "Tact and tradeoffs", skill: "Keep the relationship intact while changing the plan.", rounds: [
518
+ I("8-1", "A fair split", 150, "compromise", "money", "quantity", "reason", "choice", "time"),
519
+ I("8-2", "Not tonight", 145, "refuse", "apology", "reason", "alternative", "invite", "time"),
520
+ I("8-3", "A safer outing", 145, "weather", "warning", "alternative", "reason", "invite", "place"),
521
+ I("8-4", "A careful favor", 140, "permission", "animal", "condition", "promise", "place", "time"),
522
+ I("8-5", "Dinner, revised", 140, "food", "contrast", "compromise", "choice", "time", "question")
523
+ ] },
524
+ { id: 9, title: "Seven moving parts", skill: "Combine seven conditions in a coherent message.", rounds: [
525
+ I("9-1", "The surprise picnic", 175, "food", "excited", "invite", "quantity", "time", "place", "question"),
526
+ I("9-2", "A wet-weather rescue", 170, "animal", "weather", "help", "urgent", "place", "warning", "instructions"),
527
+ I("9-3", "Make it right", 165, "apology", "repair", "promise", "time", "money", "choice", "reason"),
528
+ I("9-4", "Two ways home", 165, "transport", "compare", "money", "time", "choice", "condition", "question"),
529
+ I("9-5", "A team effort", 160, "thanks", "credit", "offer", "promise", "time", "place", "reason"),
530
+ I("9-6", "A safe sequence", 160, "food", "warning", "sequence", "instructions", "condition", "consequence", "reason")
531
+ ] },
532
+ { id: 10, title: "Every word earns its place", skill: "Keep the same meaning while trimming seven-part messages.", rounds: [
533
+ I("10-1", "The short invitation", 135, "food", "invite", "time", "place", "quantity", "excited", "question"),
534
+ I("10-2", "The short apology", 135, "apology", "refuse", "reason", "alternative", "invite", "time", "place"),
535
+ I("10-3", "The short rescue", 130, "animal", "help", "urgent", "place", "warning", "instructions", "reason"),
536
+ I("10-4", "The short bargain", 130, "compromise", "compare", "money", "choice", "condition", "promise", "time"),
537
+ I("10-5", "The short handoff", 130, "instructions", "sequence", "time", "place", "quantity", "food", "thanks"),
538
+ I("10-6", "The short reassurance", 130, "animal", "reassure", "offer", "condition", "promise", "time", "place")
539
+ ] },
540
+ { id: 11, title: "The final edit", skill: "Eight different situations. Seven conditions. Make each message count.", rounds: [
541
+ I("11-1", "The gathering", 145, "food", "invite", "excited", "quantity", "time", "place", "question"),
542
+ I("11-2", "The setback", 140, "weather", "apology", "reason", "alternative", "invite", "time", "place"),
543
+ I("11-3", "The emergency", 140, "animal", "help", "urgent", "warning", "place", "instructions", "reason"),
544
+ I("11-4", "The repair", 140, "apology", "repair", "promise", "time", "choice", "money", "reason"),
545
+ I("11-5", "The negotiation", 140, "compromise", "refuse", "reason", "alternative", "condition", "promise", "money"),
546
+ I("11-6", "The journey", 135, "transport", "compare", "choice", "money", "time", "condition", "question"),
547
+ I("11-7", "The handover", 135, "food", "sequence", "instructions", "warning", "reason", "time", "thanks"),
548
+ I("11-8", "The thank-you", 135, "thanks", "credit", "offer", "promise", "invite", "time", "place")
549
+ ] }
550
+ ], Gt = {
551
+ praise: ["Praise", "Does the quoted Text contain any praise or compliment, even if it also contains criticism?"],
552
+ complaint: ["Complaint", "Does the quoted Text complain about a problem the writer has experienced? A warning about a possible danger is not a complaint."],
553
+ question: ["Question", "Does the quoted Text contain an interrogative sentence?"],
554
+ apology: ["Apology", "Does the writer explicitly apologize, such as saying sorry or I apologize?"],
555
+ invitation: ["Invitation", "Does the quoted Text directly ask another person to join the writer in an activity?"],
556
+ warning: ["Warning", "Does the text warn of a danger?"],
557
+ thanks: ["Gratitude", "Is there an expression of gratitude anywhere in the quoted Text?"],
558
+ offer: ["Offer of help", 'Does the quoted Text explicitly volunteer help to another person, such as "I can help you"?'],
559
+ request: ["Request for help", "Does the writer ask the reader to provide help? Offering help is different."],
560
+ promise: ["Promise", "Does the writer explicitly commit to a future action, such as saying I promise or I will? Describing a current activity is not a promise."],
561
+ refusal: ["Refusal", "Does the writer turn down an invitation, offer, or request?"],
562
+ food: ["Food", "Is a food item or ingredient named anywhere in the text?"],
563
+ nature: ["Nature", "Does the text mention wild animals, wild plants, or a natural landscape?"],
564
+ pets: ["Pets", "Does the text mention a pet?"],
565
+ travel: ["Travel", "Does the text describe a person taking a journey or visiting a different place? Mentioning a location alone is not travel."],
566
+ work: ["Work", "Does the text explicitly mention a paid job, employment, or professional duties?"],
567
+ leisure: ["Leisure", "Does the text explicitly say an activity is done for fun, pleasure, or as a hobby? Performing an activity alone does not say it is recreation."],
568
+ shopping: ["Shopping", "Does the text explicitly describe buying, selling, or ordering goods?"],
569
+ learning: ["Learning", "Does the text explicitly describe someone learning, studying, or being taught? Performing an activity alone is not evidence of learning."],
570
+ science: ["Science", "Does the text mention a scientific fact, scientific process, experiment, or scientific study?"],
571
+ music: ["Music", "Does the text mention singing or playing music?"],
572
+ sport: ["Sport", "Does the text mention a sport or physical exercise?"],
573
+ art: ["Art", "Does the text mention drawing, painting, or sculpture?"],
574
+ technology: ["Technology", "Does the text mention computers, software, or electronic devices?"],
575
+ health: ["Health", "Does the text describe an illness, injury, or medical treatment?"],
576
+ gardening: ["Gardening", "Does the text describe cultivating plants in a garden? Look for an actual gardening action, such as planting seeds or watering flowers."],
577
+ cooking: ["Cooking", "Does the text explicitly describe preparing or cooking food, such as chopping, mixing, baking, or boiling? Eating or tasting food alone does not count."],
578
+ repair: ["Repair", "Does the quoted Text identify a broken object and describe repairing it? Do not infer or complete missing text."],
579
+ transport: ["Transport", "Does the text mention a vehicle?"],
580
+ weather: ["Weather", "Does the text mention a weather condition?"],
581
+ celebration: ["Celebration", "Does the text describe celebrating a special occasion?"],
582
+ family: ["Family", "Does the text mention a family member?"],
583
+ history: ["History", "Does the quoted Text name a particular ancient civilization or a specific historical event?"]
584
+ }, jt = {
585
+ question: ["The text contains a question.", "The text contains no questions."],
586
+ praise: ["The writer gives a compliment or positive feedback.", "The writer gives no compliment or positive feedback."],
587
+ complaint: ["An actual complaint about a bad experience.", "No complaint about a bad experience."],
588
+ learning: ["Someone is explicitly learning, studying, or receiving a lesson.", "No learning, study, or lesson is described."],
589
+ offer: ["An explicit offer to help another person.", "A personal activity or other message without an offer of help."],
590
+ leisure: ["An activity is explicitly done for fun or as a hobby.", "No recreational purpose is stated. This includes unrelated text or fragments without enough information."],
591
+ shopping: ["Goods are bought, sold, or ordered.", "No goods are bought, sold, or ordered."],
592
+ apology: ["The writer explicitly apologizes.", "The writer does not apologize."],
593
+ invitation: ["A direct invitation addressed to another person.", "No direct invitation is addressed to another person."],
594
+ warning: ["The text warns someone about a specific danger.", "The text does not warn of a danger."],
595
+ thanks: ["Thanks, thank you, or being grateful is expressed.", "No expression of gratitude is present."],
596
+ promise: ["The writer commits to a future action.", "No commitment to a future action is made."],
597
+ refusal: ["The writer says no to an invitation, offer, or request.", "The writer does not turn down an invitation, offer, or request."],
598
+ request: ["The writer asks someone else for assistance.", "The writer does not ask for assistance."],
599
+ food: ["A food or ingredient is named, such as bread, rice, cake, or lemon.", "No actual food or ingredient is named; the text may be unrelated or unfinished."],
600
+ nature: ["Wild animals, wild plants, or a natural landscape are mentioned.", "No wild animals, wild plants, or natural landscape are mentioned."],
601
+ pets: ["The text mentions an animal kept as a pet.", "No pet is mentioned."],
602
+ travel: ["Someone is traveling or visiting a place.", "No one is traveling or visiting a place."],
603
+ work: ["The text explicitly describes paid work, employment, or professional duties.", "The text does not describe paid work, employment, or professional duties."],
604
+ science: ["A scientific process, finding, experiment, or study is described.", "No scientific process, finding, experiment, or study is described."],
605
+ music: ["Singing, playing music, or a musical instrument is mentioned.", "No singing, music, or musical instrument is mentioned."],
606
+ sport: ["A sport or physical exercise is mentioned.", "No sport or physical exercise is mentioned."],
607
+ art: ["Drawing, painting, or sculpture is mentioned.", "No drawing, painting, or sculpture is mentioned."],
608
+ technology: ["Computers, software, or electronic devices are mentioned.", "No computers, software, or electronic devices are mentioned. This includes unrelated text or fragments without enough information."],
609
+ health: ["An illness, injury, or medical treatment is described.", "No illness, injury, or medical treatment is described."],
610
+ gardening: ["An actual gardening action is described.", "No gardening action is described."],
611
+ cooking: ["Preparing or cooking food is described.", "No preparation or cooking of food is described."],
612
+ repair: ["The text identifies a broken object and describes a repair.", "No specific broken object and repair are described; the text may be unrelated or unfinished."],
613
+ transport: ["The text names a vehicle, such as a car, bus, bicycle, or train.", "No vehicle is named."],
614
+ weather: ["A specific weather condition is mentioned.", "No weather condition is mentioned."],
615
+ celebration: ["Someone celebrates a special occasion.", "No celebration of a special occasion is described."],
616
+ family: ["A family member is mentioned.", "No family member is mentioned."],
617
+ history: ["The text names an ancient civilization or a historical event.", "No ancient civilization or historical event is named in the text."]
618
+ };
619
+ function $(e, r, i, ...t) {
620
+ const s = t.map((l) => Gt[l]);
621
+ return {
622
+ id: e,
623
+ title: r,
624
+ limit: i,
625
+ labels: s.map(([l]) => l),
626
+ questions: t.map((l) => ({
627
+ type: "choice",
628
+ instruction: Gt[l][1],
629
+ // Absence first reduces false matches on ambiguous, unfinished input.
630
+ criteria: [jt[l][1], jt[l][0]]
631
+ }))
632
+ };
633
+ }
634
+ const Nn = [
635
+ { id: 1, title: "Two meanings at once", skill: "Blend two clear meanings and avoid the distractions.", rounds: [
636
+ $("1-1", "Praise and criticism", 120, "praise", "complaint", "question", "apology"),
637
+ $("1-2", "Work can be fun", 110, "work", "leisure", "shopping", "warning"),
638
+ $("1-3", "An invitation with a catch", 110, "invitation", "warning", "apology", "refusal")
639
+ ] },
640
+ { id: 2, title: "Cross the topics", skill: "Make one activity connect two different subjects.", rounds: [
641
+ $("2-1", "Edible experiments", 110, "food", "science", "shopping", "complaint"),
642
+ $("2-2", "A musical lesson", 100, "music", "learning", "work", "shopping"),
643
+ $("2-3", "The active pet", 100, "pets", "sport", "shopping", "warning")
644
+ ] },
645
+ { id: 3, title: "Purpose and subject", skill: "Give a familiar topic a distinct purpose.", rounds: [
646
+ $("3-1", "A helpful meal", 110, "food", "offer", "request", "apology", "shopping"),
647
+ $("3-2", "A digital question", 105, "technology", "question", "complaint", "shopping", "promise"),
648
+ $("3-3", "A grateful patient", 105, "health", "thanks", "complaint", "question", "warning")
649
+ ] },
650
+ { id: 4, title: "The obvious wrong answer", skill: "Make the distinction that the distractor tries to blur.", rounds: [
651
+ $("4-1", "Making it, not buying it", 105, "cooking", "leisure", "shopping", "work", "request"),
652
+ $("4-2", "Practice without a paycheck", 100, "learning", "technology", "work", "shopping", "complaint"),
653
+ $("4-3", "A stroll through time", 100, "travel", "history", "shopping", "work", "sport"),
654
+ $("4-4", "Helping, not asking", 100, "repair", "offer", "request", "shopping", "apology")
655
+ ] },
656
+ { id: 5, title: "Mixed feelings", skill: "Combine two intentions without accidentally adding a third.", rounds: [
657
+ $("5-1", "A grateful critic", 105, "thanks", "complaint", "apology", "request", "question"),
658
+ $("5-2", "No, but thank you", 100, "refusal", "thanks", "apology", "question", "promise"),
659
+ $("5-3", "Sorry, let me help", 100, "apology", "offer", "request", "warning", "promise"),
660
+ $("5-4", "A promise of praise", 100, "promise", "praise", "invitation", "question", "thanks")
661
+ ] },
662
+ { id: 6, title: "Find the connection", skill: "Connect subjects through one concrete detail.", rounds: [
663
+ $("6-1", "A living laboratory", 105, "gardening", "science", "shopping", "work", "food", "warning"),
664
+ $("6-2", "A painted past", 100, "art", "history", "shopping", "travel", "work", "music"),
665
+ $("6-3", "A family melody", 100, "family", "music", "shopping", "work", "question", "complaint"),
666
+ $("6-4", "Recover through movement", 100, "health", "sport", "shopping", "work", "warning", "complaint")
667
+ ] },
668
+ { id: 7, title: "Six-way distinction", skill: "Keep two signals strong among four plausible alternatives.", rounds: [
669
+ $("7-1", "A scientific repair", 105, "repair", "science", "shopping", "work", "question", "request"),
670
+ $("7-2", "The birthday recipe", 100, "cooking", "celebration", "shopping", "work", "invitation", "question"),
671
+ $("7-3", "A wildlife lesson", 100, "nature", "learning", "travel", "sport", "gardening", "work"),
672
+ $("7-4", "Rain on the route", 100, "weather", "transport", "travel", "warning", "shopping", "question"),
673
+ $("7-5", "An artistic hobby", 95, "art", "leisure", "shopping", "work", "learning", "question")
674
+ ] },
675
+ { id: 8, title: "Close neighbors", skill: "Separate related meanings with carefully chosen details.", rounds: [
676
+ $("8-1", "Wild, not a pet", 100, "nature", "science", "pets", "gardening", "travel", "shopping"),
677
+ $("8-2", "Enjoying, not cooking", 95, "food", "praise", "cooking", "shopping", "thanks", "question"),
678
+ $("8-3", "Teach, don't take over", 95, "learning", "repair", "offer", "request", "work", "shopping"),
679
+ $("8-4", "Praise without gratitude", 95, "praise", "art", "thanks", "shopping", "question", "offer"),
680
+ $("8-5", "A plan, not an invitation", 95, "promise", "transport", "invitation", "offer", "question", "warning")
681
+ ] },
682
+ { id: 9, title: "Seven signals", skill: "Keep five distracting meanings out of a two-topic message.", rounds: [
683
+ $("9-1", "The singing family", 110, "family", "music", "work", "shopping", "invitation", "learning", "complaint"),
684
+ $("9-2", "The kitchen experiment", 105, "cooking", "science", "shopping", "work", "health", "question", "warning"),
685
+ $("9-3", "The outdoor painting", 105, "art", "nature", "gardening", "pets", "travel", "shopping", "work"),
686
+ $("9-4", "A polite no", 105, "refusal", "thanks", "apology", "promise", "question", "complaint", "offer"),
687
+ $("9-5", "The recovery routine", 100, "health", "sport", "work", "shopping", "complaint", "warning", "request"),
688
+ $("9-6", "A promised repair", 100, "repair", "promise", "apology", "request", "shopping", "question", "warning")
689
+ ] },
690
+ { id: 10, title: "Distill the meaning", skill: "Keep two meanings and lose the spare words.", rounds: [
691
+ $("10-1", "A concise review", 80, "praise", "complaint", "thanks", "apology", "question", "request", "warning"),
692
+ $("10-2", "A concise invitation", 80, "invitation", "warning", "apology", "refusal", "complaint", "promise", "thanks"),
693
+ $("10-3", "A concise lesson", 80, "music", "learning", "work", "shopping", "invitation", "question", "promise"),
694
+ $("10-4", "A concise offer", 80, "offer", "food", "request", "shopping", "apology", "question", "warning"),
695
+ $("10-5", "A concise connection", 80, "gardening", "technology", "shopping", "work", "food", "question", "warning"),
696
+ $("10-6", "A concise experiment", 80, "pets", "science", "work", "shopping", "health", "warning", "question")
697
+ ] },
698
+ { id: 11, title: "Perfectly mixed", skill: "Eight blends, with five distractions to avoid in each.", rounds: [
699
+ $("11-1", "The balanced verdict", 85, "praise", "complaint", "thanks", "apology", "question", "request", "warning"),
700
+ $("11-2", "The cautious welcome", 85, "invitation", "warning", "apology", "refusal", "complaint", "promise", "thanks"),
701
+ $("11-3", "The playful profession", 85, "work", "leisure", "shopping", "learning", "apology", "question", "offer"),
702
+ $("11-4", "The ancient canvas", 85, "art", "history", "travel", "shopping", "work", "learning", "question"),
703
+ $("11-5", "The growing gadget", 85, "gardening", "technology", "shopping", "work", "food", "question", "warning"),
704
+ $("11-6", "The family feast", 85, "family", "celebration", "invitation", "shopping", "question", "thanks", "promise"),
705
+ $("11-7", "The scientific snack", 85, "food", "science", "shopping", "work", "health", "question", "warning"),
706
+ $("11-8", "The gracious exit", 85, "refusal", "thanks", "apology", "promise", "question", "complaint", "offer")
707
+ ] }
708
+ ], Ee = {
709
+ lock: { name: "Semantic Golfing", description: "Write a short message that matches every condition within the character limit.", levels: qn },
710
+ signalMixing: { name: "Signal Mixing", description: "Blend two meanings in a short message while keeping the other categories out.", levels: Nn }
711
+ };
712
+ function Ln(e, r) {
713
+ if (!Number.isInteger(r) || r < 1 || r > e.limit)
714
+ throw new Error("The answer must fit the round's character limit.");
715
+ return Math.max(1, Math.round(1e3 * (1 - r / e.limit)));
716
+ }
717
+ function On(e, r) {
718
+ if (r.length !== e.rounds.length)
719
+ throw new Error("Finish every round before saving a level score.");
720
+ return e.rounds.reduce((i, t, s) => i + Ln(t, r[s]), 0);
721
+ }
722
+ function xn(e, r, i, t) {
723
+ return e.find((s) => s.modelId === r && s.game === i && s.level === t);
724
+ }
725
+ function kn(e, r, i) {
726
+ if (r == null || !Object.hasOwn(Ee, r.game) || !Number.isInteger(r.level) || typeof r.modelId != "string" || !Array.isArray(r.characters))
727
+ throw new Error("Invalid level score.");
728
+ const t = Ee[r.game].levels.find(({ id: a }) => a === r.level);
729
+ if (t == null)
730
+ throw new Error("Unknown level.");
731
+ const s = On(t, r.characters), l = xn(e, r.modelId, r.game, r.level)?.best ?? 0;
732
+ return { previousBest: l, record: {
733
+ modelId: r.modelId,
734
+ modelName: i,
735
+ game: r.game,
736
+ level: r.level,
737
+ latest: s,
738
+ best: Math.max(l, s),
739
+ completedAt: (/* @__PURE__ */ new Date()).toISOString()
740
+ } };
741
+ }
742
+ function Dn(e) {
743
+ if (e == null || typeof e != "object" || !("version" in e) || e.version !== 1 || !("records" in e) || !Array.isArray(e.records))
744
+ throw new Error("The saved score file has an unsupported format.");
745
+ const r = /* @__PURE__ */ new Set(), i = e.records.map((t) => t?.game === "camouflage" ? { ...t, game: "signalMixing" } : t);
746
+ for (const t of i) {
747
+ const s = t != null && Object.hasOwn(Ee, t.game) ? Ee[t.game].levels.find(({ id: a }) => a === t.level) : void 0;
748
+ if (s == null || typeof t.modelId != "string" || !(de.some(({ id: a }) => a === t.modelId) || /^local:[a-f0-9]{64}$/.test(t.modelId)) || typeof t.modelName != "string" || !t.modelName.trim() || t.modelName.length > 512 || !Number.isInteger(t.latest) || !Number.isInteger(t.best) || t.latest < s.rounds.length || t.best < t.latest || t.best > s.rounds.length * 1e3 || typeof t.completedAt != "string" || !Number.isFinite(Date.parse(t.completedAt)))
749
+ throw new Error("The saved score file contains an invalid score.");
750
+ const l = `${t.modelId}/${t.game}/${t.level}`;
751
+ if (r.has(l))
752
+ throw new Error("The saved score file contains duplicate scores.");
753
+ r.add(l);
754
+ }
755
+ return i;
756
+ }
757
+ const jr = () => M.join(P.getPath("userData"), "scores.json");
758
+ async function Pn() {
759
+ try {
760
+ const e = Dn(JSON.parse(await re.readFile(jr(), "utf8")));
761
+ v.state = { ...v.state, scores: e };
762
+ } catch (e) {
763
+ e.code !== "ENOENT" && (v.state = { ...v.state, scoreError: `Unable to read saved scores: ${String(e)}` });
764
+ }
765
+ }
766
+ async function Cn(e) {
767
+ return await se([v, "scores"], async () => {
768
+ if (v.state.scoreError != null)
769
+ throw new Error("Saved scores could not be read. The existing score file has been left untouched.");
770
+ const r = de.find(({ id: u }) => u === e?.modelId), i = r == null ? v.state.localModels.find(({ id: u }) => u === e?.modelId)?.name : `${r.name} ${r.parameters} ${r.quant}`;
771
+ if (i == null)
772
+ throw new Error("Unknown model for this score.");
773
+ const t = kn(v.state.scores, e, i), s = v.state.scores.filter((u) => u.modelId !== e.modelId || u.game !== e.game || u.level !== e.level).concat(t.record), l = jr(), a = `${l}.${Kr()}.tmp`;
774
+ await re.mkdir(M.dirname(l), { recursive: !0 });
775
+ try {
776
+ await re.writeFile(a, JSON.stringify({ version: 1, records: s }, null, 2), { encoding: "utf8", mode: 384 }), await re.rename(a, l);
777
+ } finally {
778
+ await re.rm(a, { force: !0 });
779
+ }
780
+ return v.state = { ...v.state, scores: s }, t;
781
+ });
782
+ }
783
+ var me = { exports: {} }, be, Mt;
784
+ function he() {
785
+ if (Mt) return be;
786
+ Mt = 1;
787
+ const e = "2.0.0", r = 256, i = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
788
+ 9007199254740991, t = 16, s = r - 6;
789
+ return be = {
790
+ MAX_LENGTH: r,
791
+ MAX_SAFE_COMPONENT_LENGTH: t,
792
+ MAX_SAFE_BUILD_LENGTH: s,
793
+ MAX_SAFE_INTEGER: i,
794
+ RELEASE_TYPES: [
795
+ "major",
796
+ "premajor",
797
+ "minor",
798
+ "preminor",
799
+ "patch",
800
+ "prepatch",
801
+ "prerelease"
802
+ ],
803
+ SEMVER_SPEC_VERSION: e,
804
+ FLAG_INCLUDE_PRERELEASE: 1,
805
+ FLAG_LOOSE: 2
806
+ }, be;
807
+ }
808
+ var qe, Ut;
809
+ function Te() {
810
+ return Ut || (Ut = 1, qe = typeof process == "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...r) => console.error("SEMVER", ...r) : () => {
811
+ }), qe;
812
+ }
813
+ var Ft;
814
+ function fe() {
815
+ return Ft || (Ft = 1, (function(e, r) {
816
+ const {
817
+ MAX_SAFE_COMPONENT_LENGTH: i,
818
+ MAX_SAFE_BUILD_LENGTH: t,
819
+ MAX_LENGTH: s
820
+ } = he(), l = Te();
821
+ r = e.exports = {};
822
+ const a = r.re = [], u = r.safeRe = [], o = r.src = [], g = r.safeSrc = [], n = r.t = {};
823
+ let c = 0;
824
+ const d = "[a-zA-Z0-9-]", p = [
825
+ ["\\s", 1],
826
+ ["\\d", s],
827
+ [d, t]
828
+ ], A = (q) => {
829
+ for (const [x, _] of p)
830
+ q = q.split(`${x}*`).join(`${x}{0,${_}}`).split(`${x}+`).join(`${x}{1,${_}}`);
831
+ return q;
832
+ }, h = (q, x, _) => {
833
+ const U = A(x), j = c++;
834
+ l(q, j, x), n[q] = j, o[j] = x, g[j] = U, a[j] = new RegExp(x, _ ? "g" : void 0), u[j] = new RegExp(U, _ ? "g" : void 0);
835
+ };
836
+ h("NUMERICIDENTIFIER", "0|[1-9]\\d*"), h("NUMERICIDENTIFIERLOOSE", "\\d+"), h("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${d}*`), h("MAINVERSION", `(${o[n.NUMERICIDENTIFIER]})\\.(${o[n.NUMERICIDENTIFIER]})\\.(${o[n.NUMERICIDENTIFIER]})`), h("MAINVERSIONLOOSE", `(${o[n.NUMERICIDENTIFIERLOOSE]})\\.(${o[n.NUMERICIDENTIFIERLOOSE]})\\.(${o[n.NUMERICIDENTIFIERLOOSE]})`), h("PRERELEASEIDENTIFIER", `(?:${o[n.NONNUMERICIDENTIFIER]}|${o[n.NUMERICIDENTIFIER]})`), h("PRERELEASEIDENTIFIERLOOSE", `(?:${o[n.NONNUMERICIDENTIFIER]}|${o[n.NUMERICIDENTIFIERLOOSE]})`), h("PRERELEASE", `(?:-(${o[n.PRERELEASEIDENTIFIER]}(?:\\.${o[n.PRERELEASEIDENTIFIER]})*))`), h("PRERELEASELOOSE", `(?:-?(${o[n.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${o[n.PRERELEASEIDENTIFIERLOOSE]})*))`), h("BUILDIDENTIFIER", `${d}+`), h("BUILD", `(?:\\+(${o[n.BUILDIDENTIFIER]}(?:\\.${o[n.BUILDIDENTIFIER]})*))`), h("FULLPLAIN", `v?${o[n.MAINVERSION]}${o[n.PRERELEASE]}?${o[n.BUILD]}?`), h("FULL", `^${o[n.FULLPLAIN]}$`), h("LOOSEPLAIN", `[v=\\s]*${o[n.MAINVERSIONLOOSE]}${o[n.PRERELEASELOOSE]}?${o[n.BUILD]}?`), h("LOOSE", `^${o[n.LOOSEPLAIN]}$`), h("GTLT", "((?:<|>)?=?)"), h("XRANGEIDENTIFIERLOOSE", `${o[n.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`), h("XRANGEIDENTIFIER", `${o[n.NUMERICIDENTIFIER]}|x|X|\\*`), h("XRANGEPLAIN", `[v=\\s]*(${o[n.XRANGEIDENTIFIER]})(?:\\.(${o[n.XRANGEIDENTIFIER]})(?:\\.(${o[n.XRANGEIDENTIFIER]})(?:${o[n.PRERELEASE]})?${o[n.BUILD]}?)?)?`), h("XRANGEPLAINLOOSE", `[v=\\s]*(${o[n.XRANGEIDENTIFIERLOOSE]})(?:\\.(${o[n.XRANGEIDENTIFIERLOOSE]})(?:\\.(${o[n.XRANGEIDENTIFIERLOOSE]})(?:${o[n.PRERELEASELOOSE]})?${o[n.BUILD]}?)?)?`), h("XRANGE", `^${o[n.GTLT]}\\s*${o[n.XRANGEPLAIN]}$`), h("XRANGELOOSE", `^${o[n.GTLT]}\\s*${o[n.XRANGEPLAINLOOSE]}$`), h("COERCEPLAIN", `(^|[^\\d])(\\d{1,${i}})(?:\\.(\\d{1,${i}}))?(?:\\.(\\d{1,${i}}))?`), h("COERCE", `${o[n.COERCEPLAIN]}(?:$|[^\\d])`), h("COERCEFULL", o[n.COERCEPLAIN] + `(?:${o[n.PRERELEASE]})?(?:${o[n.BUILD]})?(?:$|[^\\d])`), h("COERCERTL", o[n.COERCE], !0), h("COERCERTLFULL", o[n.COERCEFULL], !0), h("LONETILDE", "(?:~>?)"), h("TILDETRIM", `(\\s*)${o[n.LONETILDE]}\\s+`, !0), r.tildeTrimReplace = "$1~", h("TILDE", `^${o[n.LONETILDE]}${o[n.XRANGEPLAIN]}$`), h("TILDELOOSE", `^${o[n.LONETILDE]}${o[n.XRANGEPLAINLOOSE]}$`), h("LONECARET", "(?:\\^)"), h("CARETTRIM", `(\\s*)${o[n.LONECARET]}\\s+`, !0), r.caretTrimReplace = "$1^", h("CARET", `^${o[n.LONECARET]}${o[n.XRANGEPLAIN]}$`), h("CARETLOOSE", `^${o[n.LONECARET]}${o[n.XRANGEPLAINLOOSE]}$`), h("COMPARATORLOOSE", `^${o[n.GTLT]}\\s*(${o[n.LOOSEPLAIN]})$|^$`), h("COMPARATOR", `^${o[n.GTLT]}\\s*(${o[n.FULLPLAIN]})$|^$`), h("COMPARATORTRIM", `(\\s*)${o[n.GTLT]}\\s*(${o[n.LOOSEPLAIN]}|${o[n.XRANGEPLAIN]})`, !0), r.comparatorTrimReplace = "$1$2$3", h("HYPHENRANGE", `^\\s*(${o[n.XRANGEPLAIN]})\\s+-\\s+(${o[n.XRANGEPLAIN]})\\s*$`), h("HYPHENRANGELOOSE", `^\\s*(${o[n.XRANGEPLAINLOOSE]})\\s+-\\s+(${o[n.XRANGEPLAINLOOSE]})\\s*$`), h("STAR", "(<|>)?=?\\s*\\*"), h("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$"), h("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
837
+ })(me, me.exports)), me.exports;
838
+ }
839
+ var Ne, Vt;
840
+ function At() {
841
+ if (Vt) return Ne;
842
+ Vt = 1;
843
+ const e = Object.freeze({ loose: !0 }), r = Object.freeze({});
844
+ return Ne = (t) => t ? typeof t != "object" ? e : t : r, Ne;
845
+ }
846
+ var Le, Bt;
847
+ function Mr() {
848
+ if (Bt) return Le;
849
+ Bt = 1;
850
+ const e = /^[0-9]+$/, r = (t, s) => {
851
+ if (typeof t == "number" && typeof s == "number")
852
+ return t === s ? 0 : t < s ? -1 : 1;
853
+ const l = e.test(t), a = e.test(s);
854
+ return l && a && (t = +t, s = +s), t === s ? 0 : l && !a ? -1 : a && !l ? 1 : t < s ? -1 : 1;
855
+ };
856
+ return Le = {
857
+ compareIdentifiers: r,
858
+ rcompareIdentifiers: (t, s) => r(s, t)
859
+ }, Le;
860
+ }
861
+ var Oe, Xt;
862
+ function V() {
863
+ if (Xt) return Oe;
864
+ Xt = 1;
865
+ const e = Te(), { MAX_LENGTH: r, MAX_SAFE_INTEGER: i } = he(), { safeRe: t, t: s } = fe(), l = At(), { compareIdentifiers: a } = Mr(), u = (g, n) => {
866
+ const c = n.split(".");
867
+ if (c.length > g.length)
868
+ return !1;
869
+ for (let d = 0; d < c.length; d++)
870
+ if (a(g[d], c[d]) !== 0)
871
+ return !1;
872
+ return !0;
873
+ };
874
+ class o {
875
+ constructor(n, c) {
876
+ if (c = l(c), n instanceof o) {
877
+ if (n.loose === !!c.loose && n.includePrerelease === !!c.includePrerelease)
878
+ return n;
879
+ n = n.version;
880
+ } else if (typeof n != "string")
881
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof n}".`);
882
+ if (n.length > r)
883
+ throw new TypeError(
884
+ `version is longer than ${r} characters`
885
+ );
886
+ e("SemVer", n, c), this.options = c, this.loose = !!c.loose, this.includePrerelease = !!c.includePrerelease;
887
+ const d = n.trim().match(c.loose ? t[s.LOOSE] : t[s.FULL]);
888
+ if (!d)
889
+ throw new TypeError(`Invalid Version: ${n}`);
890
+ if (this.raw = n, this.major = +d[1], this.minor = +d[2], this.patch = +d[3], this.major > i || this.major < 0)
891
+ throw new TypeError("Invalid major version");
892
+ if (this.minor > i || this.minor < 0)
893
+ throw new TypeError("Invalid minor version");
894
+ if (this.patch > i || this.patch < 0)
895
+ throw new TypeError("Invalid patch version");
896
+ d[4] ? this.prerelease = d[4].split(".").map((p) => {
897
+ if (/^[0-9]+$/.test(p)) {
898
+ const A = +p;
899
+ if (A >= 0 && A < i)
900
+ return A;
901
+ }
902
+ return p;
903
+ }) : this.prerelease = [], this.build = d[5] ? d[5].split(".") : [], this.format();
904
+ }
905
+ format() {
906
+ return this.version = `${this.major}.${this.minor}.${this.patch}`, this.prerelease.length && (this.version += `-${this.prerelease.join(".")}`), this.version;
907
+ }
908
+ toString() {
909
+ return this.version;
910
+ }
911
+ compare(n) {
912
+ if (e("SemVer.compare", this.version, this.options, n), !(n instanceof o)) {
913
+ if (typeof n == "string" && n === this.version)
914
+ return 0;
915
+ n = new o(n, this.options);
916
+ }
917
+ return n.version === this.version ? 0 : this.compareMain(n) || this.comparePre(n);
918
+ }
919
+ compareMain(n) {
920
+ return n instanceof o || (n = new o(n, this.options)), this.major < n.major ? -1 : this.major > n.major ? 1 : this.minor < n.minor ? -1 : this.minor > n.minor ? 1 : this.patch < n.patch ? -1 : this.patch > n.patch ? 1 : 0;
921
+ }
922
+ comparePre(n) {
923
+ if (n instanceof o || (n = new o(n, this.options)), this.prerelease.length && !n.prerelease.length)
924
+ return -1;
925
+ if (!this.prerelease.length && n.prerelease.length)
926
+ return 1;
927
+ if (!this.prerelease.length && !n.prerelease.length)
928
+ return 0;
929
+ let c = 0;
930
+ do {
931
+ const d = this.prerelease[c], p = n.prerelease[c];
932
+ if (e("prerelease compare", c, d, p), d === void 0 && p === void 0)
933
+ return 0;
934
+ if (p === void 0)
935
+ return 1;
936
+ if (d === void 0)
937
+ return -1;
938
+ if (d === p)
939
+ continue;
940
+ return a(d, p);
941
+ } while (++c);
942
+ }
943
+ compareBuild(n) {
944
+ n instanceof o || (n = new o(n, this.options));
945
+ let c = 0;
946
+ do {
947
+ const d = this.build[c], p = n.build[c];
948
+ if (e("build compare", c, d, p), d === void 0 && p === void 0)
949
+ return 0;
950
+ if (p === void 0)
951
+ return 1;
952
+ if (d === void 0)
953
+ return -1;
954
+ if (d === p)
955
+ continue;
956
+ return a(d, p);
957
+ } while (++c);
958
+ }
959
+ // preminor will bump the version up to the next minor release, and immediately
960
+ // down to pre-release. premajor and prepatch work the same way.
961
+ inc(n, c, d) {
962
+ if (n.startsWith("pre")) {
963
+ if (!c && d === !1)
964
+ throw new Error("invalid increment argument: identifier is empty");
965
+ if (c) {
966
+ const p = `-${c}`.match(this.options.loose ? t[s.PRERELEASELOOSE] : t[s.PRERELEASE]);
967
+ if (!p || p[1] !== c)
968
+ throw new Error(`invalid identifier: ${c}`);
969
+ }
970
+ }
971
+ switch (n) {
972
+ case "premajor":
973
+ this.prerelease.length = 0, this.patch = 0, this.minor = 0, this.major++, this.inc("pre", c, d);
974
+ break;
975
+ case "preminor":
976
+ this.prerelease.length = 0, this.patch = 0, this.minor++, this.inc("pre", c, d);
977
+ break;
978
+ case "prepatch":
979
+ this.prerelease.length = 0, this.inc("patch", c, d), this.inc("pre", c, d);
980
+ break;
981
+ // If the input is a non-prerelease version, this acts the same as
982
+ // prepatch.
983
+ case "prerelease":
984
+ this.prerelease.length === 0 && this.inc("patch", c, d), this.inc("pre", c, d);
985
+ break;
986
+ case "release":
987
+ if (this.prerelease.length === 0)
988
+ throw new Error(`version ${this.raw} is not a prerelease`);
989
+ this.prerelease.length = 0;
990
+ break;
991
+ case "major":
992
+ (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) && this.major++, this.minor = 0, this.patch = 0, this.prerelease = [];
993
+ break;
994
+ case "minor":
995
+ (this.patch !== 0 || this.prerelease.length === 0) && this.minor++, this.patch = 0, this.prerelease = [];
996
+ break;
997
+ case "patch":
998
+ this.prerelease.length === 0 && this.patch++, this.prerelease = [];
999
+ break;
1000
+ // This probably shouldn't be used publicly.
1001
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
1002
+ case "pre": {
1003
+ const p = Number(d) ? 1 : 0;
1004
+ if (this.prerelease.length === 0)
1005
+ this.prerelease = [p];
1006
+ else {
1007
+ let A = this.prerelease.length;
1008
+ for (; --A >= 0; )
1009
+ typeof this.prerelease[A] == "number" && (this.prerelease[A]++, A = -2);
1010
+ if (A === -1) {
1011
+ if (c === this.prerelease.join(".") && d === !1)
1012
+ throw new Error("invalid increment argument: identifier already exists");
1013
+ this.prerelease.push(p);
1014
+ }
1015
+ }
1016
+ if (c) {
1017
+ let A = [c, p];
1018
+ if (d === !1 && (A = [c]), u(this.prerelease, c)) {
1019
+ const h = this.prerelease[c.split(".").length];
1020
+ isNaN(h) && (this.prerelease = A);
1021
+ } else
1022
+ this.prerelease = A;
1023
+ }
1024
+ break;
1025
+ }
1026
+ default:
1027
+ throw new Error(`invalid increment argument: ${n}`);
1028
+ }
1029
+ return this.raw = this.format(), this.build.length && (this.raw += `+${this.build.join(".")}`), this;
1030
+ }
1031
+ }
1032
+ return Oe = o, Oe;
1033
+ }
1034
+ var xe, zt;
1035
+ function ae() {
1036
+ if (zt) return xe;
1037
+ zt = 1;
1038
+ const e = V();
1039
+ return xe = (i, t, s = !1) => {
1040
+ if (i instanceof e)
1041
+ return i;
1042
+ try {
1043
+ return new e(i, t);
1044
+ } catch (l) {
1045
+ if (!s)
1046
+ return null;
1047
+ throw l;
1048
+ }
1049
+ }, xe;
1050
+ }
1051
+ var ke, Ht;
1052
+ function _n() {
1053
+ if (Ht) return ke;
1054
+ Ht = 1;
1055
+ const e = ae();
1056
+ return ke = (i, t) => {
1057
+ const s = e(i, t);
1058
+ return s ? s.version : null;
1059
+ }, ke;
1060
+ }
1061
+ var De, Wt;
1062
+ function Gn() {
1063
+ if (Wt) return De;
1064
+ Wt = 1;
1065
+ const e = ae();
1066
+ return De = (i, t) => {
1067
+ const s = e(i.trim().replace(/^[=v]+/, ""), t);
1068
+ return s ? s.version : null;
1069
+ }, De;
1070
+ }
1071
+ var Pe, Qt;
1072
+ function jn() {
1073
+ if (Qt) return Pe;
1074
+ Qt = 1;
1075
+ const e = V();
1076
+ return Pe = (i, t, s, l, a) => {
1077
+ typeof s == "string" && (a = l, l = s, s = void 0);
1078
+ try {
1079
+ return new e(
1080
+ i instanceof e ? i.version : i,
1081
+ s
1082
+ ).inc(t, l, a).version;
1083
+ } catch {
1084
+ return null;
1085
+ }
1086
+ }, Pe;
1087
+ }
1088
+ var Ce, Yt;
1089
+ function Mn() {
1090
+ if (Yt) return Ce;
1091
+ Yt = 1;
1092
+ const e = ae();
1093
+ return Ce = (i, t) => {
1094
+ const s = e(i, null, !0), l = e(t, null, !0), a = s.compare(l);
1095
+ if (a === 0)
1096
+ return null;
1097
+ const u = a > 0, o = u ? s : l, g = u ? l : s, n = !!o.prerelease.length;
1098
+ if (!!g.prerelease.length && !n) {
1099
+ if (!g.patch && !g.minor)
1100
+ return "major";
1101
+ if (g.compareMain(o) === 0)
1102
+ return g.minor && !g.patch ? "minor" : "patch";
1103
+ }
1104
+ const d = n ? "pre" : "";
1105
+ return s.major !== l.major ? d + "major" : s.minor !== l.minor ? d + "minor" : s.patch !== l.patch ? d + "patch" : "prerelease";
1106
+ }, Ce;
1107
+ }
1108
+ var _e, Kt;
1109
+ function Un() {
1110
+ if (Kt) return _e;
1111
+ Kt = 1;
1112
+ const e = V();
1113
+ return _e = (i, t) => new e(i, t).major, _e;
1114
+ }
1115
+ var Ge, Jt;
1116
+ function Fn() {
1117
+ if (Jt) return Ge;
1118
+ Jt = 1;
1119
+ const e = V();
1120
+ return Ge = (i, t) => new e(i, t).minor, Ge;
1121
+ }
1122
+ var je, Zt;
1123
+ function Vn() {
1124
+ if (Zt) return je;
1125
+ Zt = 1;
1126
+ const e = V();
1127
+ return je = (i, t) => new e(i, t).patch, je;
1128
+ }
1129
+ var Me, er;
1130
+ function Bn() {
1131
+ if (er) return Me;
1132
+ er = 1;
1133
+ const e = ae();
1134
+ return Me = (i, t) => {
1135
+ const s = e(i, t);
1136
+ return s && s.prerelease.length ? s.prerelease : null;
1137
+ }, Me;
1138
+ }
1139
+ var Ue, tr;
1140
+ function J() {
1141
+ if (tr) return Ue;
1142
+ tr = 1;
1143
+ const e = V();
1144
+ return Ue = (i, t, s) => new e(i, s).compare(new e(t, s)), Ue;
1145
+ }
1146
+ var Fe, rr;
1147
+ function Xn() {
1148
+ if (rr) return Fe;
1149
+ rr = 1;
1150
+ const e = J();
1151
+ return Fe = (i, t, s) => e(t, i, s), Fe;
1152
+ }
1153
+ var Ve, nr;
1154
+ function zn() {
1155
+ if (nr) return Ve;
1156
+ nr = 1;
1157
+ const e = J();
1158
+ return Ve = (i, t) => e(i, t, !0), Ve;
1159
+ }
1160
+ var Be, ir;
1161
+ function St() {
1162
+ if (ir) return Be;
1163
+ ir = 1;
1164
+ const e = V();
1165
+ return Be = (i, t, s) => {
1166
+ const l = new e(i, s), a = new e(t, s);
1167
+ return l.compare(a) || l.compareBuild(a);
1168
+ }, Be;
1169
+ }
1170
+ var Xe, sr;
1171
+ function Hn() {
1172
+ if (sr) return Xe;
1173
+ sr = 1;
1174
+ const e = St();
1175
+ return Xe = (i, t) => i.sort((s, l) => e(s, l, t)), Xe;
1176
+ }
1177
+ var ze, or;
1178
+ function Wn() {
1179
+ if (or) return ze;
1180
+ or = 1;
1181
+ const e = St();
1182
+ return ze = (i, t) => i.sort((s, l) => e(l, s, t)), ze;
1183
+ }
1184
+ var He, ar;
1185
+ function Ie() {
1186
+ if (ar) return He;
1187
+ ar = 1;
1188
+ const e = J();
1189
+ return He = (i, t, s) => e(i, t, s) > 0, He;
1190
+ }
1191
+ var We, lr;
1192
+ function bt() {
1193
+ if (lr) return We;
1194
+ lr = 1;
1195
+ const e = J();
1196
+ return We = (i, t, s) => e(i, t, s) < 0, We;
1197
+ }
1198
+ var Qe, cr;
1199
+ function Ur() {
1200
+ if (cr) return Qe;
1201
+ cr = 1;
1202
+ const e = J();
1203
+ return Qe = (i, t, s) => e(i, t, s) === 0, Qe;
1204
+ }
1205
+ var Ye, ur;
1206
+ function Fr() {
1207
+ if (ur) return Ye;
1208
+ ur = 1;
1209
+ const e = J();
1210
+ return Ye = (i, t, s) => e(i, t, s) !== 0, Ye;
1211
+ }
1212
+ var Ke, dr;
1213
+ function qt() {
1214
+ if (dr) return Ke;
1215
+ dr = 1;
1216
+ const e = J();
1217
+ return Ke = (i, t, s) => e(i, t, s) >= 0, Ke;
1218
+ }
1219
+ var Je, hr;
1220
+ function Nt() {
1221
+ if (hr) return Je;
1222
+ hr = 1;
1223
+ const e = J();
1224
+ return Je = (i, t, s) => e(i, t, s) <= 0, Je;
1225
+ }
1226
+ var Ze, fr;
1227
+ function Vr() {
1228
+ if (fr) return Ze;
1229
+ fr = 1;
1230
+ const e = Ur(), r = Fr(), i = Ie(), t = qt(), s = bt(), l = Nt();
1231
+ return Ze = (u, o, g, n) => {
1232
+ switch (o) {
1233
+ case "===":
1234
+ return typeof u == "object" && (u = u.version), typeof g == "object" && (g = g.version), u === g;
1235
+ case "!==":
1236
+ return typeof u == "object" && (u = u.version), typeof g == "object" && (g = g.version), u !== g;
1237
+ case "":
1238
+ case "=":
1239
+ case "==":
1240
+ return e(u, g, n);
1241
+ case "!=":
1242
+ return r(u, g, n);
1243
+ case ">":
1244
+ return i(u, g, n);
1245
+ case ">=":
1246
+ return t(u, g, n);
1247
+ case "<":
1248
+ return s(u, g, n);
1249
+ case "<=":
1250
+ return l(u, g, n);
1251
+ default:
1252
+ throw new TypeError(`Invalid operator: ${o}`);
1253
+ }
1254
+ }, Ze;
1255
+ }
1256
+ var et, pr;
1257
+ function Qn() {
1258
+ if (pr) return et;
1259
+ pr = 1;
1260
+ const e = V(), r = ae(), { safeRe: i, t } = fe();
1261
+ return et = (l, a) => {
1262
+ if (l instanceof e)
1263
+ return l;
1264
+ if (typeof l == "number" && (l = String(l)), typeof l != "string")
1265
+ return null;
1266
+ a = a || {};
1267
+ let u = null;
1268
+ if (!a.rtl)
1269
+ u = l.match(a.includePrerelease ? i[t.COERCEFULL] : i[t.COERCE]);
1270
+ else {
1271
+ const p = a.includePrerelease ? i[t.COERCERTLFULL] : i[t.COERCERTL];
1272
+ let A;
1273
+ for (; (A = p.exec(l)) && (!u || u.index + u[0].length !== l.length); )
1274
+ (!u || A.index + A[0].length !== u.index + u[0].length) && (u = A), p.lastIndex = A.index + A[1].length + A[2].length;
1275
+ p.lastIndex = -1;
1276
+ }
1277
+ if (u === null)
1278
+ return null;
1279
+ const o = u[2], g = u[3] || "0", n = u[4] || "0", c = a.includePrerelease && u[5] ? `-${u[5]}` : "", d = a.includePrerelease && u[6] ? `+${u[6]}` : "";
1280
+ return r(`${o}.${g}.${n}${c}${d}`, a);
1281
+ }, et;
1282
+ }
1283
+ var tt, mr;
1284
+ function Yn() {
1285
+ if (mr) return tt;
1286
+ mr = 1;
1287
+ const e = ae(), r = he(), i = V(), t = (u, o, g) => {
1288
+ if (!r.RELEASE_TYPES.includes(o))
1289
+ return null;
1290
+ const n = s(u, g);
1291
+ return n && l(n, o);
1292
+ }, s = (u, o) => {
1293
+ const g = u instanceof i ? u.version : u;
1294
+ return e(g, o);
1295
+ }, l = (u, o) => {
1296
+ if (a(o))
1297
+ return u.version;
1298
+ switch (u.prerelease = [], o) {
1299
+ case "major":
1300
+ u.minor = 0, u.patch = 0;
1301
+ break;
1302
+ case "minor":
1303
+ u.patch = 0;
1304
+ break;
1305
+ }
1306
+ return u.format();
1307
+ }, a = (u) => u.startsWith("pre");
1308
+ return tt = t, tt;
1309
+ }
1310
+ var rt, gr;
1311
+ function Kn() {
1312
+ if (gr) return rt;
1313
+ gr = 1;
1314
+ class e {
1315
+ constructor() {
1316
+ this.max = 1e3, this.map = /* @__PURE__ */ new Map();
1317
+ }
1318
+ get(i) {
1319
+ const t = this.map.get(i);
1320
+ if (t !== void 0)
1321
+ return this.map.delete(i), this.map.set(i, t), t;
1322
+ }
1323
+ delete(i) {
1324
+ return this.map.delete(i);
1325
+ }
1326
+ set(i, t) {
1327
+ if (!this.delete(i) && t !== void 0) {
1328
+ if (this.map.size >= this.max) {
1329
+ const l = this.map.keys().next().value;
1330
+ this.delete(l);
1331
+ }
1332
+ this.map.set(i, t);
1333
+ }
1334
+ return this;
1335
+ }
1336
+ }
1337
+ return rt = e, rt;
1338
+ }
1339
+ var nt, wr;
1340
+ function Z() {
1341
+ if (wr) return nt;
1342
+ wr = 1;
1343
+ const e = /\s+/g;
1344
+ class r {
1345
+ constructor(f, T) {
1346
+ if (T = s(T), f instanceof r)
1347
+ return f.loose === !!T.loose && f.includePrerelease === !!T.includePrerelease ? f : new r(f.raw, T);
1348
+ if (f instanceof l)
1349
+ return this.raw = f.value, this.set = [[f]], this.formatted = void 0, this;
1350
+ if (this.options = T, this.loose = !!T.loose, this.includePrerelease = !!T.includePrerelease, this.raw = f.trim().replace(e, " "), this.set = this.raw.split("||").map((R) => this.parseRange(R.trim())).filter((R) => R.length), !this.set.length)
1351
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`);
1352
+ if (this.set.length > 1) {
1353
+ const R = this.set[0];
1354
+ if (this.set = this.set.filter((N) => !x(N[0])), this.set.length === 0)
1355
+ this.set = [R];
1356
+ else if (this.set.length > 1) {
1357
+ for (const N of this.set)
1358
+ if (N.length === 1 && _(N[0])) {
1359
+ this.set = [N];
1360
+ break;
1361
+ }
1362
+ }
1363
+ }
1364
+ this.formatted = void 0;
1365
+ }
1366
+ get range() {
1367
+ if (this.formatted === void 0) {
1368
+ this.formatted = "";
1369
+ for (let f = 0; f < this.set.length; f++) {
1370
+ f > 0 && (this.formatted += "||");
1371
+ const T = this.set[f];
1372
+ for (let R = 0; R < T.length; R++)
1373
+ R > 0 && (this.formatted += " "), this.formatted += T[R].toString().trim();
1374
+ }
1375
+ }
1376
+ return this.formatted;
1377
+ }
1378
+ format() {
1379
+ return this.range;
1380
+ }
1381
+ toString() {
1382
+ return this.range;
1383
+ }
1384
+ parseRange(f) {
1385
+ f = f.replace(q, "");
1386
+ const R = ((this.options.includePrerelease && A) | (this.options.loose && h)) + ":" + f, N = t.get(R);
1387
+ if (N)
1388
+ return N;
1389
+ const y = this.options.loose, b = y ? o[n.HYPHENRANGELOOSE] : o[n.HYPHENRANGE];
1390
+ f = f.replace(b, te(this.options.includePrerelease)), a("hyphen replace", f), f = f.replace(o[n.COMPARATORTRIM], c), a("comparator trim", f), f = f.replace(o[n.TILDETRIM], d), a("tilde trim", f), f = f.replace(o[n.CARETTRIM], p), a("caret trim", f);
1391
+ let k = f.split(" ").map((G) => j(G, this.options)).join(" ").split(/\s+/).map((G) => F(G, this.options));
1392
+ y && (k = k.filter((G) => (a("loose invalid filter", G, this.options), !!G.match(o[n.COMPARATORLOOSE])))), a("range list", k);
1393
+ const O = /* @__PURE__ */ new Map(), D = k.map((G) => new l(G, this.options));
1394
+ for (const G of D) {
1395
+ if (x(G))
1396
+ return [G];
1397
+ O.set(G.value, G);
1398
+ }
1399
+ O.size > 1 && O.has("") && O.delete("");
1400
+ const H = [...O.values()];
1401
+ return t.set(R, H), H;
1402
+ }
1403
+ intersects(f, T) {
1404
+ if (!(f instanceof r))
1405
+ throw new TypeError("a Range is required");
1406
+ return this.set.some((R) => U(R, T) && f.set.some((N) => U(N, T) && R.every((y) => N.every((b) => y.intersects(b, T)))));
1407
+ }
1408
+ // if ANY of the sets match ALL of its comparators, then pass
1409
+ test(f) {
1410
+ if (!f)
1411
+ return !1;
1412
+ if (typeof f == "string")
1413
+ try {
1414
+ f = new u(f, this.options);
1415
+ } catch {
1416
+ return !1;
1417
+ }
1418
+ for (let T = 0; T < this.set.length; T++)
1419
+ if (le(this.set[T], f, this.options))
1420
+ return !0;
1421
+ return !1;
1422
+ }
1423
+ }
1424
+ nt = r;
1425
+ const i = Kn(), t = new i(), s = At(), l = $e(), a = Te(), u = V(), {
1426
+ safeRe: o,
1427
+ src: g,
1428
+ t: n,
1429
+ comparatorTrimReplace: c,
1430
+ tildeTrimReplace: d,
1431
+ caretTrimReplace: p
1432
+ } = fe(), { FLAG_INCLUDE_PRERELEASE: A, FLAG_LOOSE: h } = he(), q = new RegExp(g[n.BUILD], "g"), x = (m) => m.value === "<0.0.0-0", _ = (m) => m.value === "", U = (m, f) => {
1433
+ let T = !0;
1434
+ const R = m.slice();
1435
+ let N = R.pop();
1436
+ for (; T && R.length; )
1437
+ T = R.every((y) => N.intersects(y, f)), N = R.pop();
1438
+ return T;
1439
+ }, j = (m, f) => (m = m.replace(o[n.BUILD], ""), a("comp", m, f), m = C(m, f), a("caret", m), m = L(m, f), a("tildes", m), m = B(m, f), a("xrange", m), m = ee(m, f), a("stars", m), m), E = (m) => !m || m.toLowerCase() === "x" || m === "*", S = (m, f, T) => E(m) && !E(f) || E(f) && T && !E(T), L = (m, f) => m.trim().split(/\s+/).map((T) => w(T, f)).join(" "), w = (m, f) => {
1440
+ const T = f.loose ? o[n.TILDELOOSE] : o[n.TILDE], R = f.includePrerelease ? "-0" : "";
1441
+ return m.replace(T, (N, y, b, k, O) => {
1442
+ a("tilde", m, N, y, b, k, O);
1443
+ let D;
1444
+ return E(y) ? D = "" : E(b) ? D = `>=${y}.0.0${R} <${+y + 1}.0.0-0` : E(k) ? D = `>=${y}.${b}.0${R} <${y}.${+b + 1}.0-0` : O ? (a("replaceTilde pr", O), D = `>=${y}.${b}.${k}-${O} <${y}.${+b + 1}.0-0`) : D = `>=${y}.${b}.${k} <${y}.${+b + 1}.0-0`, a("tilde return", D), D;
1445
+ });
1446
+ }, C = (m, f) => m.trim().split(/\s+/).map((T) => K(T, f)).join(" "), K = (m, f) => {
1447
+ a("caret", m, f);
1448
+ const T = f.loose ? o[n.CARETLOOSE] : o[n.CARET], R = f.includePrerelease ? "-0" : "";
1449
+ return m.replace(T, (N, y, b, k, O) => {
1450
+ a("caret", m, N, y, b, k, O);
1451
+ let D;
1452
+ return E(y) ? D = "" : E(b) ? D = `>=${y}.0.0${R} <${+y + 1}.0.0-0` : E(k) ? y === "0" ? D = `>=${y}.${b}.0${R} <${y}.${+b + 1}.0-0` : D = `>=${y}.${b}.0${R} <${+y + 1}.0.0-0` : O ? (a("replaceCaret pr", O), y === "0" ? b === "0" ? D = `>=${y}.${b}.${k}-${O} <${y}.${b}.${+k + 1}-0` : D = `>=${y}.${b}.${k}-${O} <${y}.${+b + 1}.0-0` : D = `>=${y}.${b}.${k}-${O} <${+y + 1}.0.0-0`) : (a("no pr"), y === "0" ? b === "0" ? D = `>=${y}.${b}.${k} <${y}.${b}.${+k + 1}-0` : D = `>=${y}.${b}.${k} <${y}.${+b + 1}.0-0` : D = `>=${y}.${b}.${k} <${+y + 1}.0.0-0`), a("caret return", D), D;
1453
+ });
1454
+ }, B = (m, f) => (a("replaceXRanges", m, f), m.split(/\s+/).map((T) => X(T, f)).join(" ")), X = (m, f) => {
1455
+ m = m.trim();
1456
+ const T = f.loose ? o[n.XRANGELOOSE] : o[n.XRANGE];
1457
+ return m.replace(T, (R, N, y, b, k, O) => {
1458
+ if (a("xRange", m, R, N, y, b, k, O), S(y, b, k))
1459
+ return m;
1460
+ const D = E(y), H = D || E(b), G = H || E(k), ue = G;
1461
+ return N === "=" && ue && (N = ""), O = f.includePrerelease ? "-0" : "", D ? N === ">" || N === "<" ? R = "<0.0.0-0" : R = "*" : N && ue ? (H && (b = 0), k = 0, N === ">" ? (N = ">=", H ? (y = +y + 1, b = 0, k = 0) : (b = +b + 1, k = 0)) : N === "<=" && (N = "<", H ? y = +y + 1 : b = +b + 1), N === "<" && (O = "-0"), R = `${N + y}.${b}.${k}${O}`) : H ? R = `>=${y}.0.0${O} <${+y + 1}.0.0-0` : G && (R = `>=${y}.${b}.0${O} <${y}.${+b + 1}.0-0`), a("xRange return", R), R;
1462
+ });
1463
+ }, ee = (m, f) => (a("replaceStars", m, f), m.trim().replace(o[n.STAR], "")), F = (m, f) => (a("replaceGTE0", m, f), m.trim().replace(o[f.includePrerelease ? n.GTE0PRE : n.GTE0], "")), te = (m) => (f, T, R, N, y, b, k, O, D, H, G, ue) => (E(R) ? T = "" : E(N) ? T = `>=${R}.0.0${m ? "-0" : ""}` : E(y) ? T = `>=${R}.${N}.0${m ? "-0" : ""}` : b ? T = `>=${T}` : T = `>=${T}${m ? "-0" : ""}`, E(D) ? O = "" : E(H) ? O = `<${+D + 1}.0.0-0` : E(G) ? O = `<${D}.${+H + 1}.0-0` : ue ? O = `<=${D}.${H}.${G}-${ue}` : m ? O = `<${D}.${H}.${+G + 1}-0` : O = `<=${O}`, `${T} ${O}`.trim()), le = (m, f, T) => {
1464
+ for (let R = 0; R < m.length; R++)
1465
+ if (!m[R].test(f))
1466
+ return !1;
1467
+ if (f.prerelease.length && !T.includePrerelease) {
1468
+ for (let R = 0; R < m.length; R++)
1469
+ if (a(m[R].semver), m[R].semver !== l.ANY && m[R].semver.prerelease.length > 0) {
1470
+ const N = m[R].semver;
1471
+ if (N.major === f.major && N.minor === f.minor && N.patch === f.patch)
1472
+ return !0;
1473
+ }
1474
+ return !1;
1475
+ }
1476
+ return !0;
1477
+ };
1478
+ return nt;
1479
+ }
1480
+ var it, vr;
1481
+ function $e() {
1482
+ if (vr) return it;
1483
+ vr = 1;
1484
+ const e = /* @__PURE__ */ Symbol("SemVer ANY");
1485
+ class r {
1486
+ static get ANY() {
1487
+ return e;
1488
+ }
1489
+ constructor(n, c) {
1490
+ if (c = i(c), n instanceof r) {
1491
+ if (n.loose === !!c.loose)
1492
+ return n;
1493
+ n = n.value;
1494
+ }
1495
+ n = n.trim().split(/\s+/).join(" "), a("comparator", n, c), this.options = c, this.loose = !!c.loose, this.parse(n), this.semver === e ? this.value = "" : this.value = this.operator + this.semver.version, a("comp", this);
1496
+ }
1497
+ parse(n) {
1498
+ const c = this.options.loose ? t[s.COMPARATORLOOSE] : t[s.COMPARATOR], d = n.match(c);
1499
+ if (!d)
1500
+ throw new TypeError(`Invalid comparator: ${n}`);
1501
+ this.operator = d[1] !== void 0 ? d[1] : "", this.operator === "=" && (this.operator = ""), d[2] ? this.semver = new u(d[2], this.options.loose) : this.semver = e;
1502
+ }
1503
+ toString() {
1504
+ return this.value;
1505
+ }
1506
+ test(n) {
1507
+ if (a("Comparator.test", n, this.options.loose), this.semver === e || n === e)
1508
+ return !0;
1509
+ if (typeof n == "string")
1510
+ try {
1511
+ n = new u(n, this.options);
1512
+ } catch {
1513
+ return !1;
1514
+ }
1515
+ return l(n, this.operator, this.semver, this.options);
1516
+ }
1517
+ intersects(n, c) {
1518
+ if (!(n instanceof r))
1519
+ throw new TypeError("a Comparator is required");
1520
+ return this.operator === "" ? this.value === "" ? !0 : new o(n.value, c).test(this.value) : n.operator === "" ? n.value === "" ? !0 : new o(this.value, c).test(n.semver) : (c = i(c), c.includePrerelease && (this.value === "<0.0.0-0" || n.value === "<0.0.0-0") || !c.includePrerelease && (this.value.startsWith("<0.0.0") || n.value.startsWith("<0.0.0")) ? !1 : !!(this.operator.startsWith(">") && n.operator.startsWith(">") || this.operator.startsWith("<") && n.operator.startsWith("<") || this.semver.version === n.semver.version && this.operator.includes("=") && n.operator.includes("=") || l(this.semver, "<", n.semver, c) && this.operator.startsWith(">") && n.operator.startsWith("<") || l(this.semver, ">", n.semver, c) && this.operator.startsWith("<") && n.operator.startsWith(">")));
1521
+ }
1522
+ }
1523
+ it = r;
1524
+ const i = At(), { safeRe: t, t: s } = fe(), l = Vr(), a = Te(), u = V(), o = Z();
1525
+ return it;
1526
+ }
1527
+ var st, Er;
1528
+ function Ae() {
1529
+ if (Er) return st;
1530
+ Er = 1;
1531
+ const e = Z();
1532
+ return st = (i, t, s) => {
1533
+ try {
1534
+ t = new e(t, s);
1535
+ } catch {
1536
+ return !1;
1537
+ }
1538
+ return t.test(i);
1539
+ }, st;
1540
+ }
1541
+ var ot, yr;
1542
+ function Jn() {
1543
+ if (yr) return ot;
1544
+ yr = 1;
1545
+ const e = Z();
1546
+ return ot = (i, t) => new e(i, t).set.map((s) => s.map((l) => l.value).join(" ").trim().split(" ")), ot;
1547
+ }
1548
+ var at, Rr;
1549
+ function Zn() {
1550
+ if (Rr) return at;
1551
+ Rr = 1;
1552
+ const e = V(), r = Z();
1553
+ return at = (t, s, l) => {
1554
+ let a = null, u = null, o = null;
1555
+ try {
1556
+ o = new r(s, l);
1557
+ } catch {
1558
+ return null;
1559
+ }
1560
+ return t.forEach((g) => {
1561
+ o.test(g) && (!a || u.compare(g) === -1) && (a = g, u = new e(a, l));
1562
+ }), a;
1563
+ }, at;
1564
+ }
1565
+ var lt, Tr;
1566
+ function ei() {
1567
+ if (Tr) return lt;
1568
+ Tr = 1;
1569
+ const e = V(), r = Z();
1570
+ return lt = (t, s, l) => {
1571
+ let a = null, u = null, o = null;
1572
+ try {
1573
+ o = new r(s, l);
1574
+ } catch {
1575
+ return null;
1576
+ }
1577
+ return t.forEach((g) => {
1578
+ o.test(g) && (!a || u.compare(g) === 1) && (a = g, u = new e(a, l));
1579
+ }), a;
1580
+ }, lt;
1581
+ }
1582
+ var ct, Ir;
1583
+ function ti() {
1584
+ if (Ir) return ct;
1585
+ Ir = 1;
1586
+ const e = V(), r = Z(), i = Ie();
1587
+ return ct = (s, l) => {
1588
+ s = new r(s, l);
1589
+ let a = new e("0.0.0");
1590
+ if (s.test(a) || (a = new e("0.0.0-0"), s.test(a)))
1591
+ return a;
1592
+ a = null;
1593
+ for (let u = 0; u < s.set.length; ++u) {
1594
+ const o = s.set[u];
1595
+ let g = null;
1596
+ o.forEach((n) => {
1597
+ const c = new e(n.semver.version);
1598
+ switch (n.operator) {
1599
+ case ">":
1600
+ c.prerelease.length === 0 ? c.patch++ : c.prerelease.push(0), c.raw = c.format();
1601
+ /* fallthrough */
1602
+ case "":
1603
+ case ">=":
1604
+ (!g || i(c, g)) && (g = c);
1605
+ break;
1606
+ case "<":
1607
+ case "<=":
1608
+ break;
1609
+ /* istanbul ignore next */
1610
+ default:
1611
+ throw new Error(`Unexpected operation: ${n.operator}`);
1612
+ }
1613
+ }), g && (!a || i(a, g)) && (a = g);
1614
+ }
1615
+ return a && s.test(a) ? a : null;
1616
+ }, ct;
1617
+ }
1618
+ var ut, $r;
1619
+ function ri() {
1620
+ if ($r) return ut;
1621
+ $r = 1;
1622
+ const e = Z();
1623
+ return ut = (i, t) => {
1624
+ try {
1625
+ return new e(i, t).range || "*";
1626
+ } catch {
1627
+ return null;
1628
+ }
1629
+ }, ut;
1630
+ }
1631
+ var dt, Ar;
1632
+ function Lt() {
1633
+ if (Ar) return dt;
1634
+ Ar = 1;
1635
+ const e = V(), r = $e(), { ANY: i } = r, t = Z(), s = Ae(), l = Ie(), a = bt(), u = Nt(), o = qt();
1636
+ return dt = (n, c, d, p) => {
1637
+ n = new e(n, p), c = new t(c, p);
1638
+ let A, h, q, x, _;
1639
+ switch (d) {
1640
+ case ">":
1641
+ A = l, h = u, q = a, x = ">", _ = ">=";
1642
+ break;
1643
+ case "<":
1644
+ A = a, h = o, q = l, x = "<", _ = "<=";
1645
+ break;
1646
+ default:
1647
+ throw new TypeError('Must provide a hilo val of "<" or ">"');
1648
+ }
1649
+ if (s(n, c, p))
1650
+ return !1;
1651
+ for (let U = 0; U < c.set.length; ++U) {
1652
+ const j = c.set[U];
1653
+ let E = null, S = null;
1654
+ if (j.forEach((L) => {
1655
+ L.semver === i && (L = new r(">=0.0.0")), E = E || L, S = S || L, A(L.semver, E.semver, p) ? E = L : q(L.semver, S.semver, p) && (S = L);
1656
+ }), E.operator === x || E.operator === _ || (!S.operator || S.operator === x) && h(n, S.semver))
1657
+ return !1;
1658
+ if (S.operator === _ && q(n, S.semver))
1659
+ return !1;
1660
+ }
1661
+ return !0;
1662
+ }, dt;
1663
+ }
1664
+ var ht, Sr;
1665
+ function ni() {
1666
+ if (Sr) return ht;
1667
+ Sr = 1;
1668
+ const e = Lt();
1669
+ return ht = (i, t, s) => e(i, t, ">", s), ht;
1670
+ }
1671
+ var ft, br;
1672
+ function ii() {
1673
+ if (br) return ft;
1674
+ br = 1;
1675
+ const e = Lt();
1676
+ return ft = (i, t, s) => e(i, t, "<", s), ft;
1677
+ }
1678
+ var pt, qr;
1679
+ function si() {
1680
+ if (qr) return pt;
1681
+ qr = 1;
1682
+ const e = Z();
1683
+ return pt = (i, t, s) => (i = new e(i, s), t = new e(t, s), i.intersects(t, s)), pt;
1684
+ }
1685
+ var mt, Nr;
1686
+ function oi() {
1687
+ if (Nr) return mt;
1688
+ Nr = 1;
1689
+ const e = Ae(), r = J();
1690
+ return mt = (i, t, s) => {
1691
+ const l = [];
1692
+ let a = null, u = null;
1693
+ const o = i.sort((d, p) => r(d, p, s));
1694
+ for (const d of o)
1695
+ e(d, t, s) ? (u = d, a || (a = d)) : (u && l.push([a, u]), u = null, a = null);
1696
+ a && l.push([a, null]);
1697
+ const g = [];
1698
+ for (const [d, p] of l)
1699
+ d === p ? g.push(d) : !p && d === o[0] ? g.push("*") : p ? d === o[0] ? g.push(`<=${p}`) : g.push(`${d} - ${p}`) : g.push(`>=${d}`);
1700
+ const n = g.join(" || "), c = typeof t.raw == "string" ? t.raw : String(t);
1701
+ return n.length < c.length ? n : t;
1702
+ }, mt;
1703
+ }
1704
+ var gt, Lr;
1705
+ function ai() {
1706
+ if (Lr) return gt;
1707
+ Lr = 1;
1708
+ const e = Z(), r = $e(), { ANY: i } = r, t = Ae(), s = J(), l = (c, d, p = {}) => {
1709
+ if (c === d)
1710
+ return !0;
1711
+ c = new e(c, p), d = new e(d, p);
1712
+ let A = !1;
1713
+ e: for (const h of c.set) {
1714
+ for (const q of d.set) {
1715
+ const x = o(h, q, p);
1716
+ if (A = A || x !== null, x)
1717
+ continue e;
1718
+ }
1719
+ if (A)
1720
+ return !1;
1721
+ }
1722
+ return !0;
1723
+ }, a = [new r(">=0.0.0-0")], u = [new r(">=0.0.0")], o = (c, d, p) => {
1724
+ if (c === d)
1725
+ return !0;
1726
+ if (c.length === 1 && c[0].semver === i) {
1727
+ if (d.length === 1 && d[0].semver === i)
1728
+ return !0;
1729
+ p.includePrerelease ? c = a : c = u;
1730
+ }
1731
+ if (d.length === 1 && d[0].semver === i) {
1732
+ if (p.includePrerelease)
1733
+ return !0;
1734
+ d = u;
1735
+ }
1736
+ const A = /* @__PURE__ */ new Set();
1737
+ let h, q;
1738
+ for (const w of c)
1739
+ w.operator === ">" || w.operator === ">=" ? h = g(h, w, p) : w.operator === "<" || w.operator === "<=" ? q = n(q, w, p) : A.add(w.semver);
1740
+ if (A.size > 1)
1741
+ return null;
1742
+ let x;
1743
+ if (h && q) {
1744
+ if (x = s(h.semver, q.semver, p), x > 0)
1745
+ return null;
1746
+ if (x === 0 && (h.operator !== ">=" || q.operator !== "<="))
1747
+ return null;
1748
+ }
1749
+ for (const w of A) {
1750
+ if (h && !t(w, String(h), p) || q && !t(w, String(q), p))
1751
+ return null;
1752
+ for (const C of d)
1753
+ if (!t(w, String(C), p))
1754
+ return !1;
1755
+ return !0;
1756
+ }
1757
+ let _, U, j, E, S = q && !p.includePrerelease && q.semver.prerelease.length ? q.semver : !1, L = h && !p.includePrerelease && h.semver.prerelease.length ? h.semver : !1;
1758
+ S && S.prerelease.length === 1 && q.operator === "<" && S.prerelease[0] === 0 && (S = !1);
1759
+ for (const w of d) {
1760
+ if (E = E || w.operator === ">" || w.operator === ">=", j = j || w.operator === "<" || w.operator === "<=", h) {
1761
+ if (L && w.semver.prerelease && w.semver.prerelease.length && w.semver.major === L.major && w.semver.minor === L.minor && w.semver.patch === L.patch && (L = !1), w.operator === ">" || w.operator === ">=") {
1762
+ if (_ = g(h, w, p), _ === w && _ !== h)
1763
+ return !1;
1764
+ } else if (h.operator === ">=" && !w.test(h.semver))
1765
+ return !1;
1766
+ }
1767
+ if (q) {
1768
+ if (S && w.semver.prerelease && w.semver.prerelease.length && w.semver.major === S.major && w.semver.minor === S.minor && w.semver.patch === S.patch && (S = !1), w.operator === "<" || w.operator === "<=") {
1769
+ if (U = n(q, w, p), U === w && U !== q)
1770
+ return !1;
1771
+ } else if (q.operator === "<=" && !w.test(q.semver))
1772
+ return !1;
1773
+ }
1774
+ if (!w.operator && (q || h) && x !== 0)
1775
+ return !1;
1776
+ }
1777
+ return !(h && j && !q && x !== 0 || q && E && !h && x !== 0 || L || S);
1778
+ }, g = (c, d, p) => {
1779
+ if (!c)
1780
+ return d;
1781
+ const A = s(c.semver, d.semver, p);
1782
+ return A > 0 ? c : A < 0 || d.operator === ">" && c.operator === ">=" ? d : c;
1783
+ }, n = (c, d, p) => {
1784
+ if (!c)
1785
+ return d;
1786
+ const A = s(c.semver, d.semver, p);
1787
+ return A < 0 ? c : A > 0 || d.operator === "<" && c.operator === "<=" ? d : c;
1788
+ };
1789
+ return gt = l, gt;
1790
+ }
1791
+ var wt, Or;
1792
+ function li() {
1793
+ if (Or) return wt;
1794
+ Or = 1;
1795
+ const e = fe(), r = he(), i = V(), t = Mr(), s = ae(), l = _n(), a = Gn(), u = jn(), o = Mn(), g = Un(), n = Fn(), c = Vn(), d = Bn(), p = J(), A = Xn(), h = zn(), q = St(), x = Hn(), _ = Wn(), U = Ie(), j = bt(), E = Ur(), S = Fr(), L = qt(), w = Nt(), C = Vr(), K = Qn(), B = Yn(), X = $e(), ee = Z(), F = Ae(), te = Jn(), le = Zn(), m = ei(), f = ti(), T = ri(), R = Lt(), N = ni(), y = ii(), b = si(), k = oi(), O = ai();
1796
+ return wt = {
1797
+ parse: s,
1798
+ valid: l,
1799
+ clean: a,
1800
+ inc: u,
1801
+ diff: o,
1802
+ major: g,
1803
+ minor: n,
1804
+ patch: c,
1805
+ prerelease: d,
1806
+ compare: p,
1807
+ rcompare: A,
1808
+ compareLoose: h,
1809
+ compareBuild: q,
1810
+ sort: x,
1811
+ rsort: _,
1812
+ gt: U,
1813
+ lt: j,
1814
+ eq: E,
1815
+ neq: S,
1816
+ gte: L,
1817
+ lte: w,
1818
+ cmp: C,
1819
+ coerce: K,
1820
+ truncate: B,
1821
+ Comparator: X,
1822
+ Range: ee,
1823
+ satisfies: F,
1824
+ toComparators: te,
1825
+ maxSatisfying: le,
1826
+ minSatisfying: m,
1827
+ minVersion: f,
1828
+ validRange: T,
1829
+ outside: R,
1830
+ gtr: N,
1831
+ ltr: y,
1832
+ intersects: b,
1833
+ simplifyRange: k,
1834
+ subset: O,
1835
+ SemVer: i,
1836
+ re: e.re,
1837
+ src: e.src,
1838
+ tokens: e.t,
1839
+ SEMVER_SPEC_VERSION: r.SEMVER_SPEC_VERSION,
1840
+ RELEASE_TYPES: r.RELEASE_TYPES,
1841
+ compareIdentifiers: t.compareIdentifiers,
1842
+ rcompareIdentifiers: t.rcompareIdentifiers
1843
+ }, wt;
1844
+ }
1845
+ var ie = li();
1846
+ const xr = "https://github.com/giladgd/semantic-golfer";
1847
+ function ci(e, r) {
1848
+ if (!ie.valid(r))
1849
+ throw new Error("The current app version is invalid.");
1850
+ const i = ie.prerelease(r) != null, t = Array.isArray(e) ? e : [e], s = [];
1851
+ for (const l of t) {
1852
+ if (l == null || typeof l != "object" || l.draft !== !1 || l.prerelease !== i || typeof l.tag_name != "string")
1853
+ continue;
1854
+ const a = ie.valid(l.tag_name);
1855
+ a && ie.prerelease(a) != null === i && ie.gt(a, r) && s.push({ version: a, tag: l.tag_name });
1856
+ }
1857
+ return s.sort((l, a) => ie.rcompare(l.version, a.version))[0];
1858
+ }
1859
+ async function ui(e) {
1860
+ const r = ie.prerelease(e) != null;
1861
+ let i = `https://api.github.com/repos/giladgd/semantic-golfer/releases${r ? "?per_page=100" : "/latest"}`;
1862
+ for (; i; ) {
1863
+ const t = await fetch(i, {
1864
+ headers: { Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28" },
1865
+ signal: AbortSignal.timeout(15e3)
1866
+ });
1867
+ if (t.status === 404)
1868
+ return;
1869
+ if (!t.ok)
1870
+ throw new Error(`GitHub update check failed (${t.status}). Try again later.`);
1871
+ const s = await t.json(), l = ci(s, e);
1872
+ if (l || !r)
1873
+ return l;
1874
+ const a = t.headers.get("link")?.match(/<([^>]+)>; rel="next"/)?.[1];
1875
+ i = a?.startsWith("https://api.github.com/repos/giladgd/semantic-golfer/releases?") ? a : void 0;
1876
+ }
1877
+ }
1878
+ const ye = [v, "updates"];
1879
+ let ne, Q;
1880
+ function z(e) {
1881
+ v.state = { ...v.state, update: e };
1882
+ }
1883
+ function di() {
1884
+ const e = v.state.update;
1885
+ e && z({ ...e, dismissed: !0 });
1886
+ }
1887
+ async function hi() {
1888
+ if (process.env.SEMANTIC_GOLFER_LAUNCHER === "1")
1889
+ return process.connected && process.env.npm_execpath ? void 0 : "Run npx semantic-golfer@latest to update this installation.";
1890
+ if (!P.isPackaged)
1891
+ return "Update the source checkout to use a newer development build.";
1892
+ if (process.platform === "darwin") {
1893
+ const e = await sn(nn)("/usr/bin/codesign", ["-dv", "--verbose=2", P.getPath("exe")]).catch(() => ({ stderr: "" }));
1894
+ if (!/^TeamIdentifier=(?!not set$)\S+$/m.test(e.stderr))
1895
+ return "This unsigned macOS build needs to be replaced with the downloaded app.";
1896
+ }
1897
+ if (process.platform === "linux" && !process.env.APPIMAGE && (await Qr(M.join(process.resourcesPath, "package-type"), "utf8").catch(() => "")).trim() !== "deb")
1898
+ return process.env.SNAP ? "Update this installation through Snap." : "Replace this installation with the downloaded app.";
1899
+ }
1900
+ function fi() {
1901
+ return Q || (Q = on.autoUpdater, Q.autoDownload = !1, Q.autoInstallOnAppQuit = !1, Q.autoRunAppAfterInstall = !0, Q.allowDowngrade = !1, Q.allowPrerelease = ie.prerelease(P.getVersion()) != null, Q.disableWebInstaller = !0, Q.on("error", (e) => {
1902
+ console.error("App update:", e), ["downloading", "installing"].includes(v.state.update?.status ?? "") && z({ status: "error", version: ne?.version, error: String(e) });
1903
+ }), Q.on("download-progress", ({ percent: e }) => {
1904
+ v.state.update?.status === "downloading" && z({ ...v.state.update, progress: Math.max(0, Math.min(1, e / 100)) });
1905
+ }), Q);
1906
+ }
1907
+ async function Ot(e = !1) {
1908
+ Dr(ye) || ["downloading", "installing"].includes(v.state.update?.status ?? "") || await se(ye, async () => {
1909
+ const r = v.state.update;
1910
+ z({ status: "checking", dismissed: !e });
1911
+ try {
1912
+ if (ne = await ui(P.getVersion()), !ne) {
1913
+ z({ status: "current", dismissed: !e });
1914
+ return;
1915
+ }
1916
+ z({
1917
+ status: "available",
1918
+ version: ne.version,
1919
+ manual: await hi(),
1920
+ dismissed: !e && r?.version === ne.version && r.dismissed
1921
+ });
1922
+ } catch (i) {
1923
+ z({ status: "error", error: String(i), dismissed: !e });
1924
+ }
1925
+ });
1926
+ }
1927
+ function pi() {
1928
+ if (Dr(ye) || !ne || !["available", "error"].includes(v.state.update?.status ?? ""))
1929
+ return;
1930
+ const e = ne, r = v.state.update;
1931
+ if (r.manual) {
1932
+ It.openExternal(`${xr}/releases/tag/${encodeURIComponent(e.tag)}`).catch((i) => {
1933
+ z({ ...r, status: "error", error: String(i), dismissed: !1 });
1934
+ });
1935
+ return;
1936
+ }
1937
+ z({ status: "downloading", version: e.version }), se(ye, async () => {
1938
+ try {
1939
+ if (process.env.SEMANTIC_GOLFER_LAUNCHER === "1") {
1940
+ if (!process.connected || !process.send)
1941
+ throw new Error("The npm launcher is no longer connected. Restart the app and try again.");
1942
+ process.send({ type: "semantic-golfer:update", version: e.version }, (s) => {
1943
+ s && z({ status: "error", version: e.version, error: String(s) });
1944
+ });
1945
+ return;
1946
+ }
1947
+ const i = fi();
1948
+ i.setFeedURL({ provider: "generic", url: `${xr}/releases/download/${encodeURIComponent(e.tag)}/` });
1949
+ const t = await i.checkForUpdates();
1950
+ if (!t?.isUpdateAvailable || t.updateInfo.version !== e.version)
1951
+ throw new Error("The release update files do not match this version. Try again later.");
1952
+ await i.downloadUpdate(), z({ status: "installing", version: e.version, progress: 1 }), await se([v, "scores"], () => {
1953
+ }), i.quitAndInstall(!1, !0);
1954
+ } catch (i) {
1955
+ z({ status: "error", version: e.version, error: String(i) });
1956
+ }
1957
+ });
1958
+ }
1959
+ function mi() {
1960
+ if (process.on("message", (i) => {
1961
+ process.env.SEMANTIC_GOLFER_LAUNCHER !== "1" || v.state.update?.status !== "downloading" || i == null || typeof i != "object" || !("type" in i) || (i.type === "semantic-golfer:update-ready" ? (z({ status: "installing", version: ne?.version, progress: 1 }), se([v, "scores"], () => P.quit())) : i.type === "semantic-golfer:update-error" && "error" in i && typeof i.error == "string" && z({ status: "error", version: ne?.version, error: i.error }));
1962
+ }), !P.isPackaged && process.env.SEMANTIC_GOLFER_LAUNCHER !== "1")
1963
+ return;
1964
+ let e;
1965
+ const r = async () => {
1966
+ await Ot(), e = new kt(r, 14400 * 1e3);
1967
+ };
1968
+ e = new kt(r, 5e3), P.once("will-quit", () => e.dispose());
1969
+ }
1970
+ const gi = (e) => ({
1971
+ getState: () => v.state,
1972
+ checkForUpdates: () => {
1973
+ Ot(!0);
1974
+ },
1975
+ dismissUpdate: di,
1976
+ installUpdate: pi,
1977
+ saveLevelScore: Cn,
1978
+ downloadModel: fn,
1979
+ cancelDownload: pn,
1980
+ loadModel: _r,
1981
+ evaluateDecision: mn,
1982
+ openModelsDirectory: wn,
1983
+ selectModelFile: () => gn(e),
1984
+ deleteModel: vn
1985
+ });
1986
+ function wi(e) {
1987
+ const r = bn("llmRpc", "llmRpc", e, gi(e)), i = v.createChangeListener((t) => {
1988
+ e.isDestroyed() || r.updateState.asEvent(t);
1989
+ });
1990
+ e.once("closed", () => {
1991
+ i.dispose(), r.$close();
1992
+ });
1993
+ }
1994
+ function vi(e) {
1995
+ if (process.platform !== "darwin") {
1996
+ Se.setApplicationMenu(null);
1997
+ return;
1998
+ }
1999
+ Se.setApplicationMenu(Se.buildFromTemplate([
2000
+ { label: P.name, submenu: [
2001
+ { role: "about" },
2002
+ { label: "Check for Updates…", click: () => {
2003
+ e(), Ot(!0);
2004
+ } },
2005
+ { type: "separator" },
2006
+ { role: "services" },
2007
+ { type: "separator" },
2008
+ { role: "hide" },
2009
+ { role: "hideOthers" },
2010
+ { role: "unhide" },
2011
+ { type: "separator" },
2012
+ { role: "quit" }
2013
+ ] },
2014
+ { role: "editMenu" },
2015
+ { role: "viewMenu" },
2016
+ { role: "windowMenu" }
2017
+ ]));
2018
+ }
2019
+ const Br = M.dirname(Hr(import.meta.url));
2020
+ P.getPath("userData") === M.join(P.getPath("appData"), P.getName()) && P.setPath("userData", M.join(P.getPath("appData"), "semantic-golfer"));
2021
+ P.setName("Semantic Golfer");
2022
+ v.state = { ...v.state, appVersion: P.getVersion() };
2023
+ process.env.SEMANTIC_GOLFER_LAUNCHER === "1" && (process.once("disconnect", () => P.quit()), process.connected || P.quit());
2024
+ process.platform === "win32" && P.setAppUserModelId("ai.withcat.semantic-golfer");
2025
+ process.env.APP_ROOT = M.join(Br, "..");
2026
+ const Rt = process.env.VITE_DEV_SERVER_URL, Ni = M.join(process.env.APP_ROOT, "dist-electron"), Xr = M.join(process.env.APP_ROOT, "dist"), zr = M.join(Rt ? M.join(process.env.APP_ROOT, "assets") : Xr, "icon.png");
2027
+ let W;
2028
+ function Tt() {
2029
+ const e = () => ({
2030
+ color: pe.shouldUseDarkColors ? "#1a211c" : "#edf1eb",
2031
+ symbolColor: pe.shouldUseDarkColors ? "#e2eee5" : "#263c32",
2032
+ height: 60
2033
+ });
2034
+ W = new kr({
2035
+ webPreferences: {
2036
+ preload: M.join(Br, "preload.mjs"),
2037
+ scrollBounce: !0
2038
+ },
2039
+ width: 1380,
2040
+ height: 900,
2041
+ minWidth: 760,
2042
+ minHeight: 600,
2043
+ title: "Semantic Golfer",
2044
+ icon: zr,
2045
+ titleBarStyle: "hidden",
2046
+ ...process.platform === "darwin" ? { trafficLightPosition: { x: 20, y: 22 } } : { titleBarOverlay: e() },
2047
+ autoHideMenuBar: !0,
2048
+ backgroundColor: e().color
2049
+ });
2050
+ const r = W;
2051
+ process.platform !== "darwin" && r.removeMenu();
2052
+ const i = () => {
2053
+ r.setBackgroundColor(e().color), process.platform !== "darwin" && r.setTitleBarOverlay(e());
2054
+ };
2055
+ pe.on("updated", i), r.once("closed", () => pe.off("updated", i)), wi(W), W.webContents.setWindowOpenHandler(({ url: t }) => t.startsWith("file://") ? { action: "allow" } : (It.openExternal(t), { action: "deny" })), Rt ? W.loadURL(Rt) : W.loadFile(M.join(Xr, "index.html"));
2056
+ }
2057
+ P.on("window-all-closed", () => {
2058
+ (process.platform !== "darwin" || process.env.SEMANTIC_GOLFER_LAUNCHER === "1") && (P.quit(), W = null);
2059
+ });
2060
+ P.on("activate", () => {
2061
+ kr.getAllWindows().length === 0 && Tt();
2062
+ });
2063
+ P.whenReady().then(async () => {
2064
+ P.isPackaged || P.dock?.setIcon(zr), await Promise.all([hn(), Pn()]), vi(() => {
2065
+ (!W || W.isDestroyed()) && Tt(), W.isMinimized() && W.restore(), W.show(), W.focus();
2066
+ }), Tt(), mi();
2067
+ });
2068
+ export {
2069
+ Ni as MAIN_DIST,
2070
+ Xr as RENDERER_DIST,
2071
+ Rt as VITE_DEV_SERVER_URL
2072
+ };