@ramme-io/kernel 7.3.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AiGateway-Bdcl3v8h.js → AiGateway-U28yN4Mf.js} +409 -358
- package/dist/{bodewellAdapter-BzbeTSIP.js → bodewellAdapter-Cw9brU9k.js} +1 -1
- package/dist/deviceReadings-3Z4nql34.js +16 -0
- package/dist/index-BrFe7_2L.js +1614 -0
- package/dist/index.es.js +4340 -4610
- package/dist/kernel/src/agents/roster.d.ts +11 -3
- package/dist/kernel/src/agents/roster.d.ts.map +1 -1
- package/dist/kernel/src/agents/scope.d.ts +21 -0
- package/dist/kernel/src/agents/scope.d.ts.map +1 -0
- package/dist/kernel/src/agents/scope.test.d.ts +2 -0
- package/dist/kernel/src/agents/scope.test.d.ts.map +1 -0
- package/dist/kernel/src/components/AIChatPanel.d.ts +12 -0
- package/dist/kernel/src/components/AIChatPanel.d.ts.map +1 -1
- package/dist/kernel/src/engine/runtime/data-seeder.d.ts +2 -0
- package/dist/kernel/src/engine/runtime/data-seeder.d.ts.map +1 -1
- package/dist/kernel/src/engine/runtime/useSignal.d.ts +15 -0
- package/dist/kernel/src/engine/runtime/useSignal.d.ts.map +1 -1
- package/dist/kernel/src/engine/runtime/useSignal.test.d.ts +2 -0
- package/dist/kernel/src/engine/runtime/useSignal.test.d.ts.map +1 -0
- package/dist/kernel/src/index.d.ts +1 -4
- package/dist/kernel/src/index.d.ts.map +1 -1
- package/dist/kernel/src/renderers/AppDocumentRenderer.d.ts +57 -5
- package/dist/kernel/src/renderers/AppDocumentRenderer.d.ts.map +1 -1
- package/dist/kernel/src/renderers/AppOrientation.test.d.ts +2 -0
- package/dist/kernel/src/renderers/AppOrientation.test.d.ts.map +1 -0
- package/dist/kernel/src/server.d.ts +3 -0
- package/dist/kernel/src/server.d.ts.map +1 -1
- package/dist/kernel/src/services/ai/AiGatewayService.d.ts.map +1 -1
- package/dist/kernel/src/services/ai/providers/GeminiAdapter.d.ts.map +1 -1
- package/dist/kernel/src/services/ai/providers/OllamaAdapter.d.ts +1 -0
- package/dist/kernel/src/services/ai/providers/OllamaAdapter.d.ts.map +1 -1
- package/dist/kernel/src/services/ai/toolPromptGenerator.d.ts +0 -1
- package/dist/kernel/src/services/ai/toolPromptGenerator.d.ts.map +1 -1
- package/dist/kernel/src/signals/deviceReadings.d.ts +9 -0
- package/dist/kernel/src/signals/deviceReadings.d.ts.map +1 -0
- package/dist/kernel/src/signals/deviceReadings.test.d.ts +2 -0
- package/dist/kernel/src/signals/deviceReadings.test.d.ts.map +1 -0
- package/dist/kernel/src/signals/index.d.ts +1 -0
- package/dist/kernel/src/signals/index.d.ts.map +1 -1
- package/dist/server.es.js +47 -44
- package/dist/signals.es.js +12 -10
- package/package.json +4 -4
- package/dist/index-kBkq1FSR.js +0 -1236
- package/dist/kernel/src/events/mockEventSource.d.ts +0 -28
- package/dist/kernel/src/events/mockEventSource.d.ts.map +0 -1
- package/dist/kernel/src/services/MarketDataService.d.ts +0 -29
- package/dist/kernel/src/services/MarketDataService.d.ts.map +0 -1
- package/dist/kernel/src/services/marketSession.d.ts +0 -33
- package/dist/kernel/src/services/marketSession.d.ts.map +0 -1
- package/dist/kernel/src/services/marketSession.test.d.ts +0 -14
- package/dist/kernel/src/services/marketSession.test.d.ts.map +0 -1
- package/dist/kernel/src/stores/useMarketDataStore.d.ts +0 -50
- package/dist/kernel/src/stores/useMarketDataStore.d.ts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as x, j as O, k as
|
|
2
|
-
const
|
|
1
|
+
import { i as x, j as O, k as F, l as M } from "./index-BrFe7_2L.js";
|
|
2
|
+
const se = {
|
|
3
3
|
// ── ROOM 1: STRATEGY OFFICE ──────────────────────────────────────
|
|
4
4
|
strategist: {
|
|
5
5
|
id: "strategist",
|
|
@@ -113,7 +113,16 @@ Provide a structured audit report with:
|
|
|
113
113
|
- 💡 Suggestions (improvements not required but recommended)
|
|
114
114
|
`.trim()
|
|
115
115
|
}
|
|
116
|
-
}
|
|
116
|
+
};
|
|
117
|
+
function lt(n, e) {
|
|
118
|
+
const r = se[n];
|
|
119
|
+
if (!r) throw new Error(`scopePatch: unknown agent role "${String(n)}"`);
|
|
120
|
+
const t = new Set(r.scope), o = {}, a = [];
|
|
121
|
+
for (const [s, c] of Object.entries(e ?? {}))
|
|
122
|
+
t.has(s) ? o[s] = c : a.push(s);
|
|
123
|
+
return { patch: o, dropped: a };
|
|
124
|
+
}
|
|
125
|
+
const G = {
|
|
117
126
|
// May 2026 stable series — gemini-2.0-flash is deprecated (404)
|
|
118
127
|
"google-gemini": ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-preview-05-20", "gemini-1.5-flash"],
|
|
119
128
|
openai: ["gpt-4o", "gpt-4o-mini", "gpt-4-turbo", "gpt-3.5-turbo"],
|
|
@@ -136,20 +145,20 @@ Provide a structured audit report with:
|
|
|
136
145
|
// (core/ai_router.py's DEFAULT_MODELS) — llama3.2 (3B) was found live
|
|
137
146
|
// to mis-trigger tool calls on plain greetings.
|
|
138
147
|
ollama: ["llama3.3", "qwen2.5:32b", "qwen2.5-coder:32b", "qwen2.5-coder:14b", "qwen2.5-coder:7b", "llama3.2"]
|
|
139
|
-
},
|
|
148
|
+
}, ut = {
|
|
140
149
|
"google-gemini": "Google Gemini",
|
|
141
150
|
openai: "OpenAI",
|
|
142
151
|
anthropic: "Anthropic (Claude)",
|
|
143
152
|
grok: "xAI Grok",
|
|
144
153
|
deepseek: "DeepSeek",
|
|
145
154
|
ollama: "Ollama (Local)"
|
|
146
|
-
},
|
|
155
|
+
}, dt = {
|
|
147
156
|
"google-gemini": "AIzaSy…",
|
|
148
157
|
openai: "sk-…",
|
|
149
158
|
anthropic: "sk-ant-…",
|
|
150
159
|
grok: "xai-…",
|
|
151
160
|
deepseek: "sk-…"
|
|
152
|
-
},
|
|
161
|
+
}, ie = Symbol("Let zodToJsonSchema decide on which parser to use"), V = {
|
|
153
162
|
name: void 0,
|
|
154
163
|
$refStrategy: "root",
|
|
155
164
|
basePath: ["#"],
|
|
@@ -172,14 +181,14 @@ Provide a structured audit report with:
|
|
|
172
181
|
base64Strategy: "contentEncoding:base64",
|
|
173
182
|
nameStrategy: "ref",
|
|
174
183
|
openAiAnyTypeName: "OpenAiAnyType"
|
|
175
|
-
},
|
|
176
|
-
...
|
|
184
|
+
}, ce = (n) => typeof n == "string" ? {
|
|
185
|
+
...V,
|
|
177
186
|
name: n
|
|
178
187
|
} : {
|
|
179
|
-
...
|
|
188
|
+
...V,
|
|
180
189
|
...n
|
|
181
|
-
},
|
|
182
|
-
const e =
|
|
190
|
+
}, le = (n) => {
|
|
191
|
+
const e = ce(n), r = e.name !== void 0 ? [...e.basePath, e.definitionPath, e.name] : e.basePath;
|
|
183
192
|
return {
|
|
184
193
|
...e,
|
|
185
194
|
flags: { hasReferencedOpenAiAnyType: !1 },
|
|
@@ -196,16 +205,16 @@ Provide a structured audit report with:
|
|
|
196
205
|
]))
|
|
197
206
|
};
|
|
198
207
|
};
|
|
199
|
-
function
|
|
208
|
+
function Q(n, e, r, t) {
|
|
200
209
|
t != null && t.errorMessages && r && (n.errorMessage = {
|
|
201
210
|
...n.errorMessage,
|
|
202
211
|
[e]: r
|
|
203
212
|
});
|
|
204
213
|
}
|
|
205
|
-
function
|
|
206
|
-
n[e] = r,
|
|
214
|
+
function k(n, e, r, t, o) {
|
|
215
|
+
n[e] = r, Q(n, e, t, o);
|
|
207
216
|
}
|
|
208
|
-
const
|
|
217
|
+
const ee = (n, e) => {
|
|
209
218
|
let r = 0;
|
|
210
219
|
for (; r < n.length && r < e.length && n[r] === e[r]; r++)
|
|
211
220
|
;
|
|
@@ -224,10 +233,10 @@ function P(n) {
|
|
|
224
233
|
n.openAiAnyTypeName
|
|
225
234
|
];
|
|
226
235
|
return n.flags.hasReferencedOpenAiAnyType = !0, {
|
|
227
|
-
$ref: n.$refStrategy === "relative" ?
|
|
236
|
+
$ref: n.$refStrategy === "relative" ? ee(e, n.currentPath) : e.join("/")
|
|
228
237
|
};
|
|
229
238
|
}
|
|
230
|
-
function
|
|
239
|
+
function ue(n, e) {
|
|
231
240
|
var t, o, a;
|
|
232
241
|
const r = {
|
|
233
242
|
type: "array"
|
|
@@ -235,9 +244,9 @@ function ie(n, e) {
|
|
|
235
244
|
return (t = n.type) != null && t._def && ((a = (o = n.type) == null ? void 0 : o._def) == null ? void 0 : a.typeName) !== f.ZodAny && (r.items = b(n.type._def, {
|
|
236
245
|
...e,
|
|
237
246
|
currentPath: [...e.currentPath, "items"]
|
|
238
|
-
})), n.minLength &&
|
|
247
|
+
})), n.minLength && k(r, "minItems", n.minLength.value, n.minLength.message, e), n.maxLength && k(r, "maxItems", n.maxLength.value, n.maxLength.message, e), n.exactLength && (k(r, "minItems", n.exactLength.value, n.exactLength.message, e), k(r, "maxItems", n.exactLength.value, n.exactLength.message, e)), r;
|
|
239
248
|
}
|
|
240
|
-
function
|
|
249
|
+
function de(n, e) {
|
|
241
250
|
const r = {
|
|
242
251
|
type: "integer",
|
|
243
252
|
format: "int64"
|
|
@@ -247,31 +256,31 @@ function ce(n, e) {
|
|
|
247
256
|
for (const t of n.checks)
|
|
248
257
|
switch (t.kind) {
|
|
249
258
|
case "min":
|
|
250
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
259
|
+
e.target === "jsonSchema7" ? t.inclusive ? k(r, "minimum", t.value, t.message, e) : k(r, "exclusiveMinimum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMinimum = !0), k(r, "minimum", t.value, t.message, e));
|
|
251
260
|
break;
|
|
252
261
|
case "max":
|
|
253
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
262
|
+
e.target === "jsonSchema7" ? t.inclusive ? k(r, "maximum", t.value, t.message, e) : k(r, "exclusiveMaximum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMaximum = !0), k(r, "maximum", t.value, t.message, e));
|
|
254
263
|
break;
|
|
255
264
|
case "multipleOf":
|
|
256
|
-
|
|
265
|
+
k(r, "multipleOf", t.value, t.message, e);
|
|
257
266
|
break;
|
|
258
267
|
}
|
|
259
268
|
return r;
|
|
260
269
|
}
|
|
261
|
-
function
|
|
270
|
+
function me() {
|
|
262
271
|
return {
|
|
263
272
|
type: "boolean"
|
|
264
273
|
};
|
|
265
274
|
}
|
|
266
|
-
function
|
|
275
|
+
function te(n, e) {
|
|
267
276
|
return b(n.type._def, e);
|
|
268
277
|
}
|
|
269
|
-
const
|
|
270
|
-
function
|
|
278
|
+
const pe = (n, e) => b(n.innerType._def, e);
|
|
279
|
+
function re(n, e, r) {
|
|
271
280
|
const t = r ?? e.dateStrategy;
|
|
272
281
|
if (Array.isArray(t))
|
|
273
282
|
return {
|
|
274
|
-
anyOf: t.map((o, a) =>
|
|
283
|
+
anyOf: t.map((o, a) => re(n, e, o))
|
|
275
284
|
};
|
|
276
285
|
switch (t) {
|
|
277
286
|
case "string":
|
|
@@ -286,10 +295,10 @@ function ee(n, e, r) {
|
|
|
286
295
|
format: "date"
|
|
287
296
|
};
|
|
288
297
|
case "integer":
|
|
289
|
-
return
|
|
298
|
+
return he(n, e);
|
|
290
299
|
}
|
|
291
300
|
}
|
|
292
|
-
const
|
|
301
|
+
const he = (n, e) => {
|
|
293
302
|
const r = {
|
|
294
303
|
type: "integer",
|
|
295
304
|
format: "unix-time"
|
|
@@ -299,7 +308,7 @@ const ue = (n, e) => {
|
|
|
299
308
|
for (const t of n.checks)
|
|
300
309
|
switch (t.kind) {
|
|
301
310
|
case "min":
|
|
302
|
-
|
|
311
|
+
k(
|
|
303
312
|
r,
|
|
304
313
|
"minimum",
|
|
305
314
|
t.value,
|
|
@@ -309,7 +318,7 @@ const ue = (n, e) => {
|
|
|
309
318
|
);
|
|
310
319
|
break;
|
|
311
320
|
case "max":
|
|
312
|
-
|
|
321
|
+
k(
|
|
313
322
|
r,
|
|
314
323
|
"maximum",
|
|
315
324
|
t.value,
|
|
@@ -321,23 +330,23 @@ const ue = (n, e) => {
|
|
|
321
330
|
}
|
|
322
331
|
return r;
|
|
323
332
|
};
|
|
324
|
-
function
|
|
333
|
+
function ge(n, e) {
|
|
325
334
|
return {
|
|
326
335
|
...b(n.innerType._def, e),
|
|
327
336
|
default: n.defaultValue()
|
|
328
337
|
};
|
|
329
338
|
}
|
|
330
|
-
function
|
|
339
|
+
function fe(n, e) {
|
|
331
340
|
return e.effectStrategy === "input" ? b(n.schema._def, e) : P(e);
|
|
332
341
|
}
|
|
333
|
-
function
|
|
342
|
+
function ye(n) {
|
|
334
343
|
return {
|
|
335
344
|
type: "string",
|
|
336
345
|
enum: Array.from(n.values)
|
|
337
346
|
};
|
|
338
347
|
}
|
|
339
|
-
const
|
|
340
|
-
function
|
|
348
|
+
const we = (n) => "type" in n && n.type === "string" ? !1 : "allOf" in n;
|
|
349
|
+
function be(n, e) {
|
|
341
350
|
const r = [
|
|
342
351
|
b(n.left._def, {
|
|
343
352
|
...e,
|
|
@@ -351,7 +360,7 @@ function fe(n, e) {
|
|
|
351
360
|
let t = e.target === "jsonSchema2019-09" ? { unevaluatedProperties: !1 } : void 0;
|
|
352
361
|
const o = [];
|
|
353
362
|
return r.forEach((a) => {
|
|
354
|
-
if (
|
|
363
|
+
if (we(a))
|
|
355
364
|
o.push(...a.allOf), a.unevaluatedProperties === void 0 && (t = void 0);
|
|
356
365
|
else {
|
|
357
366
|
let s = a;
|
|
@@ -367,7 +376,7 @@ function fe(n, e) {
|
|
|
367
376
|
...t
|
|
368
377
|
} : void 0;
|
|
369
378
|
}
|
|
370
|
-
function
|
|
379
|
+
function Ee(n, e) {
|
|
371
380
|
const r = typeof n.value;
|
|
372
381
|
return r !== "bigint" && r !== "number" && r !== "boolean" && r !== "string" ? {
|
|
373
382
|
type: Array.isArray(n.value) ? "array" : "object"
|
|
@@ -379,7 +388,7 @@ function ye(n, e) {
|
|
|
379
388
|
const: n.value
|
|
380
389
|
};
|
|
381
390
|
}
|
|
382
|
-
let
|
|
391
|
+
let U;
|
|
383
392
|
const R = {
|
|
384
393
|
/**
|
|
385
394
|
* `c` was changed to `[cC]` to replicate /i flag
|
|
@@ -402,7 +411,7 @@ const R = {
|
|
|
402
411
|
* Fix in Zod:
|
|
403
412
|
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
404
413
|
*/
|
|
405
|
-
emoji: () => (
|
|
414
|
+
emoji: () => (U === void 0 && (U = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u")), U),
|
|
406
415
|
/**
|
|
407
416
|
* Unused
|
|
408
417
|
*/
|
|
@@ -422,7 +431,7 @@ const R = {
|
|
|
422
431
|
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
423
432
|
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
424
433
|
};
|
|
425
|
-
function
|
|
434
|
+
function ne(n, e) {
|
|
426
435
|
const r = {
|
|
427
436
|
type: "string"
|
|
428
437
|
};
|
|
@@ -430,10 +439,10 @@ function te(n, e) {
|
|
|
430
439
|
for (const t of n.checks)
|
|
431
440
|
switch (t.kind) {
|
|
432
441
|
case "min":
|
|
433
|
-
|
|
442
|
+
k(r, "minLength", typeof r.minLength == "number" ? Math.max(r.minLength, t.value) : t.value, t.message, e);
|
|
434
443
|
break;
|
|
435
444
|
case "max":
|
|
436
|
-
|
|
445
|
+
k(r, "maxLength", typeof r.maxLength == "number" ? Math.min(r.maxLength, t.value) : t.value, t.message, e);
|
|
437
446
|
break;
|
|
438
447
|
case "email":
|
|
439
448
|
switch (e.emailStrategy) {
|
|
@@ -464,10 +473,10 @@ function te(n, e) {
|
|
|
464
473
|
_(r, R.cuid2, t.message, e);
|
|
465
474
|
break;
|
|
466
475
|
case "startsWith":
|
|
467
|
-
_(r, RegExp(`^${
|
|
476
|
+
_(r, RegExp(`^${z(t.value, e)}`), t.message, e);
|
|
468
477
|
break;
|
|
469
478
|
case "endsWith":
|
|
470
|
-
_(r, RegExp(`${
|
|
479
|
+
_(r, RegExp(`${z(t.value, e)}$`), t.message, e);
|
|
471
480
|
break;
|
|
472
481
|
case "datetime":
|
|
473
482
|
$(r, "date-time", t.message, e);
|
|
@@ -482,10 +491,10 @@ function te(n, e) {
|
|
|
482
491
|
$(r, "duration", t.message, e);
|
|
483
492
|
break;
|
|
484
493
|
case "length":
|
|
485
|
-
|
|
494
|
+
k(r, "minLength", typeof r.minLength == "number" ? Math.max(r.minLength, t.value) : t.value, t.message, e), k(r, "maxLength", typeof r.maxLength == "number" ? Math.min(r.maxLength, t.value) : t.value, t.message, e);
|
|
486
495
|
break;
|
|
487
496
|
case "includes": {
|
|
488
|
-
_(r, RegExp(
|
|
497
|
+
_(r, RegExp(z(t.value, e)), t.message, e);
|
|
489
498
|
break;
|
|
490
499
|
}
|
|
491
500
|
case "ip": {
|
|
@@ -516,7 +525,7 @@ function te(n, e) {
|
|
|
516
525
|
break;
|
|
517
526
|
}
|
|
518
527
|
case "contentEncoding:base64": {
|
|
519
|
-
|
|
528
|
+
k(r, "contentEncoding", "base64", t.message, e);
|
|
520
529
|
break;
|
|
521
530
|
}
|
|
522
531
|
case "pattern:zod": {
|
|
@@ -531,14 +540,14 @@ function te(n, e) {
|
|
|
531
540
|
}
|
|
532
541
|
return r;
|
|
533
542
|
}
|
|
534
|
-
function
|
|
535
|
-
return e.patternStrategy === "escape" ?
|
|
543
|
+
function z(n, e) {
|
|
544
|
+
return e.patternStrategy === "escape" ? ke(n) : n;
|
|
536
545
|
}
|
|
537
|
-
const
|
|
538
|
-
function
|
|
546
|
+
const Ae = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
547
|
+
function ke(n) {
|
|
539
548
|
let e = "";
|
|
540
549
|
for (let r = 0; r < n.length; r++)
|
|
541
|
-
|
|
550
|
+
Ae.has(n[r]) || (e += "\\"), e += n[r];
|
|
542
551
|
return e;
|
|
543
552
|
}
|
|
544
553
|
function $(n, e, r, t) {
|
|
@@ -551,7 +560,7 @@ function $(n, e, r, t) {
|
|
|
551
560
|
}), delete n.format, n.errorMessage && (delete n.errorMessage.format, Object.keys(n.errorMessage).length === 0 && delete n.errorMessage)), n.anyOf.push({
|
|
552
561
|
format: e,
|
|
553
562
|
...r && t.errorMessages && { errorMessage: { format: r } }
|
|
554
|
-
})) :
|
|
563
|
+
})) : k(n, "format", e, r, t);
|
|
555
564
|
}
|
|
556
565
|
function _(n, e, r, t) {
|
|
557
566
|
var o;
|
|
@@ -561,11 +570,11 @@ function _(n, e, r, t) {
|
|
|
561
570
|
errorMessage: { pattern: n.errorMessage.pattern }
|
|
562
571
|
}
|
|
563
572
|
}), delete n.pattern, n.errorMessage && (delete n.errorMessage.pattern, Object.keys(n.errorMessage).length === 0 && delete n.errorMessage)), n.allOf.push({
|
|
564
|
-
pattern:
|
|
573
|
+
pattern: K(e, t),
|
|
565
574
|
...r && t.errorMessages && { errorMessage: { pattern: r } }
|
|
566
|
-
})) :
|
|
575
|
+
})) : k(n, "pattern", K(e, t), r, t);
|
|
567
576
|
}
|
|
568
|
-
function
|
|
577
|
+
function K(n, e) {
|
|
569
578
|
var i;
|
|
570
579
|
if (!e.applyRegexFlags || !n.flags)
|
|
571
580
|
return n.source;
|
|
@@ -618,17 +627,17 @@ function H(n, e) {
|
|
|
618
627
|
}
|
|
619
628
|
return o;
|
|
620
629
|
}
|
|
621
|
-
function
|
|
630
|
+
function oe(n, e) {
|
|
622
631
|
var t, o, a, s, c, i;
|
|
623
632
|
if (e.target === "openAi" && console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."), e.target === "openApi3" && ((t = n.keyType) == null ? void 0 : t._def.typeName) === f.ZodEnum)
|
|
624
633
|
return {
|
|
625
634
|
type: "object",
|
|
626
635
|
required: n.keyType._def.values,
|
|
627
|
-
properties: n.keyType._def.values.reduce((l,
|
|
636
|
+
properties: n.keyType._def.values.reduce((l, u) => ({
|
|
628
637
|
...l,
|
|
629
|
-
[
|
|
638
|
+
[u]: b(n.valueType._def, {
|
|
630
639
|
...e,
|
|
631
|
-
currentPath: [...e.currentPath, "properties",
|
|
640
|
+
currentPath: [...e.currentPath, "properties", u]
|
|
632
641
|
}) ?? P(e)
|
|
633
642
|
}), {}),
|
|
634
643
|
additionalProperties: e.rejectedAdditionalProperties
|
|
@@ -643,10 +652,10 @@ function re(n, e) {
|
|
|
643
652
|
if (e.target === "openApi3")
|
|
644
653
|
return r;
|
|
645
654
|
if (((o = n.keyType) == null ? void 0 : o._def.typeName) === f.ZodString && ((a = n.keyType._def.checks) != null && a.length)) {
|
|
646
|
-
const { type: l, ...
|
|
655
|
+
const { type: l, ...u } = ne(n.keyType._def, e);
|
|
647
656
|
return {
|
|
648
657
|
...r,
|
|
649
|
-
propertyNames:
|
|
658
|
+
propertyNames: u
|
|
650
659
|
};
|
|
651
660
|
} else {
|
|
652
661
|
if (((s = n.keyType) == null ? void 0 : s._def.typeName) === f.ZodEnum)
|
|
@@ -657,18 +666,18 @@ function re(n, e) {
|
|
|
657
666
|
}
|
|
658
667
|
};
|
|
659
668
|
if (((c = n.keyType) == null ? void 0 : c._def.typeName) === f.ZodBranded && n.keyType._def.type._def.typeName === f.ZodString && ((i = n.keyType._def.type._def.checks) != null && i.length)) {
|
|
660
|
-
const { type: l, ...
|
|
669
|
+
const { type: l, ...u } = te(n.keyType._def, e);
|
|
661
670
|
return {
|
|
662
671
|
...r,
|
|
663
|
-
propertyNames:
|
|
672
|
+
propertyNames: u
|
|
664
673
|
};
|
|
665
674
|
}
|
|
666
675
|
}
|
|
667
676
|
return r;
|
|
668
677
|
}
|
|
669
|
-
function
|
|
678
|
+
function ve(n, e) {
|
|
670
679
|
if (e.mapStrategy === "record")
|
|
671
|
-
return
|
|
680
|
+
return oe(n, e);
|
|
672
681
|
const r = b(n.keyType._def, {
|
|
673
682
|
...e,
|
|
674
683
|
currentPath: [...e.currentPath, "items", "items", "0"]
|
|
@@ -687,14 +696,14 @@ function ke(n, e) {
|
|
|
687
696
|
}
|
|
688
697
|
};
|
|
689
698
|
}
|
|
690
|
-
function
|
|
699
|
+
function Se(n) {
|
|
691
700
|
const e = n.values, t = Object.keys(n.values).filter((a) => typeof e[e[a]] != "number").map((a) => e[a]), o = Array.from(new Set(t.map((a) => typeof a)));
|
|
692
701
|
return {
|
|
693
702
|
type: o.length === 1 ? o[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
694
703
|
enum: t
|
|
695
704
|
};
|
|
696
705
|
}
|
|
697
|
-
function
|
|
706
|
+
function xe(n) {
|
|
698
707
|
return n.target === "openAi" ? void 0 : {
|
|
699
708
|
not: P({
|
|
700
709
|
...n,
|
|
@@ -702,7 +711,7 @@ function Ee(n) {
|
|
|
702
711
|
})
|
|
703
712
|
};
|
|
704
713
|
}
|
|
705
|
-
function
|
|
714
|
+
function Oe(n) {
|
|
706
715
|
return n.target === "openApi3" ? {
|
|
707
716
|
enum: ["null"],
|
|
708
717
|
nullable: !0
|
|
@@ -717,9 +726,9 @@ const L = {
|
|
|
717
726
|
ZodBoolean: "boolean",
|
|
718
727
|
ZodNull: "null"
|
|
719
728
|
};
|
|
720
|
-
function
|
|
729
|
+
function _e(n, e) {
|
|
721
730
|
if (e.target === "openApi3")
|
|
722
|
-
return
|
|
731
|
+
return X(n, e);
|
|
723
732
|
const r = n.options instanceof Map ? Array.from(n.options.values()) : n.options;
|
|
724
733
|
if (r.every((t) => t._def.typeName in L && (!t._def.checks || !t._def.checks.length))) {
|
|
725
734
|
const t = r.reduce((o, a) => {
|
|
@@ -764,16 +773,16 @@ function Se(n, e) {
|
|
|
764
773
|
...o._def.values.filter((a) => !t.includes(a))
|
|
765
774
|
], [])
|
|
766
775
|
};
|
|
767
|
-
return
|
|
776
|
+
return X(n, e);
|
|
768
777
|
}
|
|
769
|
-
const
|
|
778
|
+
const X = (n, e) => {
|
|
770
779
|
const r = (n.options instanceof Map ? Array.from(n.options.values()) : n.options).map((t, o) => b(t._def, {
|
|
771
780
|
...e,
|
|
772
781
|
currentPath: [...e.currentPath, "anyOf", `${o}`]
|
|
773
782
|
})).filter((t) => !!t && (!e.strictUnions || typeof t == "object" && Object.keys(t).length > 0));
|
|
774
783
|
return r.length ? { anyOf: r } : void 0;
|
|
775
784
|
};
|
|
776
|
-
function
|
|
785
|
+
function Pe(n, e) {
|
|
777
786
|
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(n.innerType._def.typeName) && (!n.innerType._def.checks || !n.innerType._def.checks.length))
|
|
778
787
|
return e.target === "openApi3" ? {
|
|
779
788
|
type: L[n.innerType._def.typeName],
|
|
@@ -797,7 +806,7 @@ function xe(n, e) {
|
|
|
797
806
|
});
|
|
798
807
|
return r && { anyOf: [r, { type: "null" }] };
|
|
799
808
|
}
|
|
800
|
-
function
|
|
809
|
+
function Te(n, e) {
|
|
801
810
|
const r = {
|
|
802
811
|
type: "number"
|
|
803
812
|
};
|
|
@@ -806,21 +815,21 @@ function Oe(n, e) {
|
|
|
806
815
|
for (const t of n.checks)
|
|
807
816
|
switch (t.kind) {
|
|
808
817
|
case "int":
|
|
809
|
-
r.type = "integer",
|
|
818
|
+
r.type = "integer", Q(r, "type", t.message, e);
|
|
810
819
|
break;
|
|
811
820
|
case "min":
|
|
812
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
821
|
+
e.target === "jsonSchema7" ? t.inclusive ? k(r, "minimum", t.value, t.message, e) : k(r, "exclusiveMinimum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMinimum = !0), k(r, "minimum", t.value, t.message, e));
|
|
813
822
|
break;
|
|
814
823
|
case "max":
|
|
815
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
824
|
+
e.target === "jsonSchema7" ? t.inclusive ? k(r, "maximum", t.value, t.message, e) : k(r, "exclusiveMaximum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMaximum = !0), k(r, "maximum", t.value, t.message, e));
|
|
816
825
|
break;
|
|
817
826
|
case "multipleOf":
|
|
818
|
-
|
|
827
|
+
k(r, "multipleOf", t.value, t.message, e);
|
|
819
828
|
break;
|
|
820
829
|
}
|
|
821
830
|
return r;
|
|
822
831
|
}
|
|
823
|
-
function
|
|
832
|
+
function Re(n, e) {
|
|
824
833
|
const r = e.target === "openAi", t = {
|
|
825
834
|
type: "object",
|
|
826
835
|
properties: {}
|
|
@@ -829,20 +838,20 @@ function _e(n, e) {
|
|
|
829
838
|
let i = a[c];
|
|
830
839
|
if (i === void 0 || i._def === void 0)
|
|
831
840
|
continue;
|
|
832
|
-
let l =
|
|
841
|
+
let l = Ie(i);
|
|
833
842
|
l && r && (i._def.typeName === "ZodOptional" && (i = i._def.innerType), i.isNullable() || (i = i.nullable()), l = !1);
|
|
834
|
-
const
|
|
843
|
+
const u = b(i._def, {
|
|
835
844
|
...e,
|
|
836
845
|
currentPath: [...e.currentPath, "properties", c],
|
|
837
846
|
propertyPath: [...e.currentPath, "properties", c]
|
|
838
847
|
});
|
|
839
|
-
|
|
848
|
+
u !== void 0 && (t.properties[c] = u, l || o.push(c));
|
|
840
849
|
}
|
|
841
850
|
o.length && (t.required = o);
|
|
842
|
-
const s =
|
|
851
|
+
const s = $e(n, e);
|
|
843
852
|
return s !== void 0 && (t.additionalProperties = s), t;
|
|
844
853
|
}
|
|
845
|
-
function
|
|
854
|
+
function $e(n, e) {
|
|
846
855
|
if (n.catchall._def.typeName !== "ZodNever")
|
|
847
856
|
return b(n.catchall._def, {
|
|
848
857
|
...e,
|
|
@@ -857,14 +866,14 @@ function Pe(n, e) {
|
|
|
857
866
|
return e.removeAdditionalStrategy === "strict" ? e.allowedAdditionalProperties : e.rejectedAdditionalProperties;
|
|
858
867
|
}
|
|
859
868
|
}
|
|
860
|
-
function
|
|
869
|
+
function Ie(n) {
|
|
861
870
|
try {
|
|
862
871
|
return n.isOptional();
|
|
863
872
|
} catch {
|
|
864
873
|
return !0;
|
|
865
874
|
}
|
|
866
875
|
}
|
|
867
|
-
const
|
|
876
|
+
const Ne = (n, e) => {
|
|
868
877
|
var t;
|
|
869
878
|
if (e.currentPath.toString() === ((t = e.propertyPath) == null ? void 0 : t.toString()))
|
|
870
879
|
return b(n.innerType._def, e);
|
|
@@ -880,7 +889,7 @@ const Re = (n, e) => {
|
|
|
880
889
|
r
|
|
881
890
|
]
|
|
882
891
|
} : P(e);
|
|
883
|
-
},
|
|
892
|
+
}, je = (n, e) => {
|
|
884
893
|
if (e.pipeStrategy === "input")
|
|
885
894
|
return b(n.in._def, e);
|
|
886
895
|
if (e.pipeStrategy === "output")
|
|
@@ -896,10 +905,10 @@ const Re = (n, e) => {
|
|
|
896
905
|
allOf: [r, t].filter((o) => o !== void 0)
|
|
897
906
|
};
|
|
898
907
|
};
|
|
899
|
-
function
|
|
908
|
+
function De(n, e) {
|
|
900
909
|
return b(n.type._def, e);
|
|
901
910
|
}
|
|
902
|
-
function
|
|
911
|
+
function Ce(n, e) {
|
|
903
912
|
const t = {
|
|
904
913
|
type: "array",
|
|
905
914
|
uniqueItems: !0,
|
|
@@ -908,9 +917,9 @@ function Ie(n, e) {
|
|
|
908
917
|
currentPath: [...e.currentPath, "items"]
|
|
909
918
|
})
|
|
910
919
|
};
|
|
911
|
-
return n.minSize &&
|
|
920
|
+
return n.minSize && k(t, "minItems", n.minSize.value, n.minSize.message, e), n.maxSize && k(t, "maxItems", n.maxSize.value, n.maxSize.message, e), t;
|
|
912
921
|
}
|
|
913
|
-
function
|
|
922
|
+
function Me(n, e) {
|
|
914
923
|
return n.rest ? {
|
|
915
924
|
type: "array",
|
|
916
925
|
minItems: n.items.length,
|
|
@@ -932,80 +941,80 @@ function je(n, e) {
|
|
|
932
941
|
})).reduce((r, t) => t === void 0 ? r : [...r, t], [])
|
|
933
942
|
};
|
|
934
943
|
}
|
|
935
|
-
function
|
|
944
|
+
function Ze(n) {
|
|
936
945
|
return {
|
|
937
946
|
not: P(n)
|
|
938
947
|
};
|
|
939
948
|
}
|
|
940
|
-
function
|
|
949
|
+
function qe(n) {
|
|
941
950
|
return P(n);
|
|
942
951
|
}
|
|
943
|
-
const
|
|
952
|
+
const Le = (n, e) => b(n.innerType._def, e), Ue = (n, e, r) => {
|
|
944
953
|
switch (e) {
|
|
945
954
|
case f.ZodString:
|
|
946
|
-
return
|
|
955
|
+
return ne(n, r);
|
|
947
956
|
case f.ZodNumber:
|
|
948
|
-
return
|
|
957
|
+
return Te(n, r);
|
|
949
958
|
case f.ZodObject:
|
|
950
|
-
return
|
|
959
|
+
return Re(n, r);
|
|
951
960
|
case f.ZodBigInt:
|
|
952
|
-
return
|
|
961
|
+
return de(n, r);
|
|
953
962
|
case f.ZodBoolean:
|
|
954
|
-
return
|
|
963
|
+
return me();
|
|
955
964
|
case f.ZodDate:
|
|
956
|
-
return
|
|
965
|
+
return re(n, r);
|
|
957
966
|
case f.ZodUndefined:
|
|
958
|
-
return
|
|
967
|
+
return Ze(r);
|
|
959
968
|
case f.ZodNull:
|
|
960
|
-
return
|
|
969
|
+
return Oe(r);
|
|
961
970
|
case f.ZodArray:
|
|
962
|
-
return
|
|
971
|
+
return ue(n, r);
|
|
963
972
|
case f.ZodUnion:
|
|
964
973
|
case f.ZodDiscriminatedUnion:
|
|
965
|
-
return
|
|
974
|
+
return _e(n, r);
|
|
966
975
|
case f.ZodIntersection:
|
|
967
|
-
return
|
|
976
|
+
return be(n, r);
|
|
968
977
|
case f.ZodTuple:
|
|
969
|
-
return
|
|
978
|
+
return Me(n, r);
|
|
970
979
|
case f.ZodRecord:
|
|
971
|
-
return
|
|
980
|
+
return oe(n, r);
|
|
972
981
|
case f.ZodLiteral:
|
|
973
|
-
return
|
|
982
|
+
return Ee(n, r);
|
|
974
983
|
case f.ZodEnum:
|
|
975
|
-
return
|
|
984
|
+
return ye(n);
|
|
976
985
|
case f.ZodNativeEnum:
|
|
977
|
-
return
|
|
986
|
+
return Se(n);
|
|
978
987
|
case f.ZodNullable:
|
|
979
|
-
return
|
|
988
|
+
return Pe(n, r);
|
|
980
989
|
case f.ZodOptional:
|
|
981
|
-
return
|
|
990
|
+
return Ne(n, r);
|
|
982
991
|
case f.ZodMap:
|
|
983
|
-
return
|
|
992
|
+
return ve(n, r);
|
|
984
993
|
case f.ZodSet:
|
|
985
|
-
return
|
|
994
|
+
return Ce(n, r);
|
|
986
995
|
case f.ZodLazy:
|
|
987
996
|
return () => n.getter()._def;
|
|
988
997
|
case f.ZodPromise:
|
|
989
|
-
return
|
|
998
|
+
return De(n, r);
|
|
990
999
|
case f.ZodNaN:
|
|
991
1000
|
case f.ZodNever:
|
|
992
|
-
return
|
|
1001
|
+
return xe(r);
|
|
993
1002
|
case f.ZodEffects:
|
|
994
|
-
return
|
|
1003
|
+
return fe(n, r);
|
|
995
1004
|
case f.ZodAny:
|
|
996
1005
|
return P(r);
|
|
997
1006
|
case f.ZodUnknown:
|
|
998
|
-
return
|
|
1007
|
+
return qe(r);
|
|
999
1008
|
case f.ZodDefault:
|
|
1000
|
-
return
|
|
1009
|
+
return ge(n, r);
|
|
1001
1010
|
case f.ZodBranded:
|
|
1002
|
-
return
|
|
1011
|
+
return te(n, r);
|
|
1003
1012
|
case f.ZodReadonly:
|
|
1004
|
-
return
|
|
1013
|
+
return Le(n, r);
|
|
1005
1014
|
case f.ZodCatch:
|
|
1006
|
-
return
|
|
1015
|
+
return pe(n, r);
|
|
1007
1016
|
case f.ZodPipeline:
|
|
1008
|
-
return
|
|
1017
|
+
return je(n, r);
|
|
1009
1018
|
case f.ZodFunction:
|
|
1010
1019
|
case f.ZodVoid:
|
|
1011
1020
|
case f.ZodSymbol:
|
|
@@ -1020,38 +1029,38 @@ function b(n, e, r = !1) {
|
|
|
1020
1029
|
const t = e.seen.get(n);
|
|
1021
1030
|
if (e.override) {
|
|
1022
1031
|
const i = (c = e.override) == null ? void 0 : c.call(e, n, e, t, r);
|
|
1023
|
-
if (i !==
|
|
1032
|
+
if (i !== ie)
|
|
1024
1033
|
return i;
|
|
1025
1034
|
}
|
|
1026
1035
|
if (t && !r) {
|
|
1027
|
-
const i =
|
|
1036
|
+
const i = ze(t, e);
|
|
1028
1037
|
if (i !== void 0)
|
|
1029
1038
|
return i;
|
|
1030
1039
|
}
|
|
1031
1040
|
const o = { def: n, path: e.currentPath, jsonSchema: void 0 };
|
|
1032
1041
|
e.seen.set(n, o);
|
|
1033
|
-
const a =
|
|
1034
|
-
if (s &&
|
|
1042
|
+
const a = Ue(n, n.typeName, e), s = typeof a == "function" ? b(a(), e) : a;
|
|
1043
|
+
if (s && Be(n, e, s), e.postProcess) {
|
|
1035
1044
|
const i = e.postProcess(s, n, e);
|
|
1036
1045
|
return o.jsonSchema = s, i;
|
|
1037
1046
|
}
|
|
1038
1047
|
return o.jsonSchema = s, s;
|
|
1039
1048
|
}
|
|
1040
|
-
const
|
|
1049
|
+
const ze = (n, e) => {
|
|
1041
1050
|
switch (e.$refStrategy) {
|
|
1042
1051
|
case "root":
|
|
1043
1052
|
return { $ref: n.path.join("/") };
|
|
1044
1053
|
case "relative":
|
|
1045
|
-
return { $ref:
|
|
1054
|
+
return { $ref: ee(e.currentPath, n.path) };
|
|
1046
1055
|
case "none":
|
|
1047
1056
|
case "seen":
|
|
1048
1057
|
return n.path.length < e.currentPath.length && n.path.every((r, t) => e.currentPath[t] === r) ? (console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`), P(e)) : e.$refStrategy === "seen" ? P(e) : void 0;
|
|
1049
1058
|
}
|
|
1050
|
-
},
|
|
1051
|
-
const r =
|
|
1052
|
-
let t = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((i, [l,
|
|
1059
|
+
}, Be = (n, e, r) => (n.description && (r.description = n.description, e.markdownDescription && (r.markdownDescription = n.description)), r), Je = (n, e) => {
|
|
1060
|
+
const r = le(e);
|
|
1061
|
+
let t = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((i, [l, u]) => ({
|
|
1053
1062
|
...i,
|
|
1054
|
-
[l]: b(
|
|
1063
|
+
[l]: b(u._def, {
|
|
1055
1064
|
...r,
|
|
1056
1065
|
currentPath: [...r.basePath, r.definitionPath, l]
|
|
1057
1066
|
}, !0) ?? P(r)
|
|
@@ -1087,21 +1096,28 @@ const Le = (n, e) => {
|
|
|
1087
1096
|
};
|
|
1088
1097
|
return r.target === "jsonSchema7" ? c.$schema = "http://json-schema.org/draft-07/schema#" : (r.target === "jsonSchema2019-09" || r.target === "openAi") && (c.$schema = "https://json-schema.org/draft/2019-09/schema#"), r.target === "openAi" && ("anyOf" in c || "oneOf" in c || "allOf" in c || "type" in c && Array.isArray(c.type)) && console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."), c;
|
|
1089
1098
|
};
|
|
1090
|
-
function
|
|
1091
|
-
const e =
|
|
1099
|
+
function mt(n) {
|
|
1100
|
+
const e = Je(n.parameters, { target: "jsonSchema7", $refStrategy: "none" });
|
|
1092
1101
|
return {
|
|
1093
1102
|
name: n.name,
|
|
1094
1103
|
description: n.description,
|
|
1095
1104
|
parameters: e
|
|
1096
1105
|
};
|
|
1097
1106
|
}
|
|
1098
|
-
function
|
|
1107
|
+
function Ge(n) {
|
|
1099
1108
|
const e = /* @__PURE__ */ new Set(["$schema", "additionalProperties", "default"]), r = (t) => Array.isArray(t) ? t.map(r) : t && typeof t == "object" ? Object.fromEntries(
|
|
1100
1109
|
Object.entries(t).filter(([o]) => !e.has(o)).map(([o, a]) => [o, r(a)])
|
|
1101
1110
|
) : t;
|
|
1102
1111
|
return r(n);
|
|
1103
1112
|
}
|
|
1104
|
-
|
|
1113
|
+
const Z = (n) => {
|
|
1114
|
+
try {
|
|
1115
|
+
return JSON.parse(n);
|
|
1116
|
+
} catch {
|
|
1117
|
+
return { error: { message: n } };
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
class Ye {
|
|
1105
1121
|
async *streamChat(e, r, t) {
|
|
1106
1122
|
var p, h, w, g;
|
|
1107
1123
|
const { apiKey: o, model: a = x["google-gemini"] } = r;
|
|
@@ -1110,7 +1126,7 @@ class Be {
|
|
|
1110
1126
|
functionDeclarations: t.map((y) => ({
|
|
1111
1127
|
name: y.name,
|
|
1112
1128
|
description: y.description,
|
|
1113
|
-
parameters:
|
|
1129
|
+
parameters: Ge(y.parameters)
|
|
1114
1130
|
}))
|
|
1115
1131
|
}] : void 0, l = await fetch(
|
|
1116
1132
|
`https://generativelanguage.googleapis.com/v1beta/models/${a}:streamGenerateContent?alt=sse`,
|
|
@@ -1126,28 +1142,28 @@ class Be {
|
|
|
1126
1142
|
);
|
|
1127
1143
|
if (!l.ok) {
|
|
1128
1144
|
const y = await l.text();
|
|
1129
|
-
throw
|
|
1145
|
+
throw this.normalizeError(l.status, Z(y));
|
|
1130
1146
|
}
|
|
1131
|
-
const
|
|
1132
|
-
if (!
|
|
1133
|
-
const
|
|
1147
|
+
const u = (p = l.body) == null ? void 0 : p.getReader();
|
|
1148
|
+
if (!u) throw new Error("No response body");
|
|
1149
|
+
const d = new TextDecoder();
|
|
1134
1150
|
let m = "";
|
|
1135
1151
|
for (; ; ) {
|
|
1136
|
-
const { done: y, value: A } = await
|
|
1152
|
+
const { done: y, value: A } = await u.read();
|
|
1137
1153
|
if (y) break;
|
|
1138
|
-
m +=
|
|
1154
|
+
m += d.decode(A, { stream: !0 });
|
|
1139
1155
|
const S = m.split(`
|
|
1140
1156
|
`);
|
|
1141
1157
|
m = S.pop() || "";
|
|
1142
1158
|
for (const v of S) {
|
|
1143
|
-
const
|
|
1144
|
-
if (!(!
|
|
1159
|
+
const E = v.trim();
|
|
1160
|
+
if (!(!E || !E.startsWith("data: ")))
|
|
1145
1161
|
try {
|
|
1146
|
-
const j = ((g = (w = (h = JSON.parse(
|
|
1147
|
-
for (const
|
|
1148
|
-
|
|
1162
|
+
const j = ((g = (w = (h = JSON.parse(E.slice(6)).candidates) == null ? void 0 : h[0]) == null ? void 0 : w.content) == null ? void 0 : g.parts) ?? [];
|
|
1163
|
+
for (const N of j)
|
|
1164
|
+
N.text && (yield { type: "text-delta", text: N.text }), N.functionCall && (yield {
|
|
1149
1165
|
type: "tool-call",
|
|
1150
|
-
toolCall: { name:
|
|
1166
|
+
toolCall: { name: N.functionCall.name, arguments: N.functionCall.args ?? {} }
|
|
1151
1167
|
});
|
|
1152
1168
|
} catch {
|
|
1153
1169
|
}
|
|
@@ -1155,7 +1171,7 @@ class Be {
|
|
|
1155
1171
|
}
|
|
1156
1172
|
}
|
|
1157
1173
|
async generateText(e, r) {
|
|
1158
|
-
var i, l,
|
|
1174
|
+
var i, l, u, d, m;
|
|
1159
1175
|
const { apiKey: t, model: o = x["google-gemini"], temperature: a = 0.7 } = r;
|
|
1160
1176
|
if (!t) throw new Error("Gemini API key required");
|
|
1161
1177
|
if (!o) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
@@ -1175,12 +1191,12 @@ class Be {
|
|
|
1175
1191
|
);
|
|
1176
1192
|
if (!s.ok) {
|
|
1177
1193
|
const p = await s.text();
|
|
1178
|
-
throw
|
|
1194
|
+
throw this.normalizeError(s.status, Z(p));
|
|
1179
1195
|
}
|
|
1180
|
-
return ((m = (
|
|
1196
|
+
return ((m = (d = (u = (l = (i = (await s.json()).candidates) == null ? void 0 : i[0]) == null ? void 0 : l.content) == null ? void 0 : u.parts) == null ? void 0 : d[0]) == null ? void 0 : m.text) || "";
|
|
1181
1197
|
}
|
|
1182
1198
|
async *streamText(e, r) {
|
|
1183
|
-
var l,
|
|
1199
|
+
var l, u, d, m, p, h;
|
|
1184
1200
|
const { apiKey: t, model: o = x["google-gemini"] } = r;
|
|
1185
1201
|
if (!t) throw new Error("Gemini API key required");
|
|
1186
1202
|
if (!o) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
@@ -1199,7 +1215,7 @@ class Be {
|
|
|
1199
1215
|
);
|
|
1200
1216
|
if (!a.ok) {
|
|
1201
1217
|
const w = await a.text();
|
|
1202
|
-
throw
|
|
1218
|
+
throw this.normalizeError(a.status, Z(w));
|
|
1203
1219
|
}
|
|
1204
1220
|
const s = (l = a.body) == null ? void 0 : l.getReader();
|
|
1205
1221
|
if (!s) throw new Error("No response body");
|
|
@@ -1216,8 +1232,8 @@ class Be {
|
|
|
1216
1232
|
const S = A.trim();
|
|
1217
1233
|
if (!(!S || !S.startsWith("data: ")))
|
|
1218
1234
|
try {
|
|
1219
|
-
const
|
|
1220
|
-
|
|
1235
|
+
const E = (h = (p = (m = (d = (u = JSON.parse(S.slice(6)).candidates) == null ? void 0 : u[0]) == null ? void 0 : d.content) == null ? void 0 : m.parts) == null ? void 0 : p[0]) == null ? void 0 : h.text;
|
|
1236
|
+
E && (yield E);
|
|
1221
1237
|
} catch {
|
|
1222
1238
|
continue;
|
|
1223
1239
|
}
|
|
@@ -1225,7 +1241,7 @@ class Be {
|
|
|
1225
1241
|
}
|
|
1226
1242
|
}
|
|
1227
1243
|
async generateObject(e, r, t) {
|
|
1228
|
-
var l,
|
|
1244
|
+
var l, u, d, m, p;
|
|
1229
1245
|
const { apiKey: o, model: a = x["google-gemini"] } = t;
|
|
1230
1246
|
if (!o) throw new Error("Gemini API key required");
|
|
1231
1247
|
if (!a) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
@@ -1248,9 +1264,9 @@ class Be {
|
|
|
1248
1264
|
);
|
|
1249
1265
|
if (!s.ok) {
|
|
1250
1266
|
const h = await s.json();
|
|
1251
|
-
throw this.normalizeError(
|
|
1267
|
+
throw this.normalizeError(s.status, h);
|
|
1252
1268
|
}
|
|
1253
|
-
const i = ((p = (m = (
|
|
1269
|
+
const i = ((p = (m = (d = (u = (l = (await s.json()).candidates) == null ? void 0 : l[0]) == null ? void 0 : u.content) == null ? void 0 : d.parts) == null ? void 0 : m[0]) == null ? void 0 : p.text) || "{}";
|
|
1254
1270
|
return JSON.parse(i);
|
|
1255
1271
|
}
|
|
1256
1272
|
async listModels(e) {
|
|
@@ -1262,24 +1278,39 @@ class Be {
|
|
|
1262
1278
|
headers: { "x-goog-api-key": e }
|
|
1263
1279
|
}
|
|
1264
1280
|
);
|
|
1265
|
-
if (!r.ok)
|
|
1266
|
-
|
|
1281
|
+
if (!r.ok) {
|
|
1282
|
+
const a = await r.text();
|
|
1283
|
+
throw this.normalizeError(r.status, Z(a));
|
|
1284
|
+
}
|
|
1267
1285
|
return ((o = (await r.json()).models) == null ? void 0 : o.map((a) => a.name)) || [];
|
|
1268
1286
|
}
|
|
1269
1287
|
normalizeError(e, r) {
|
|
1270
|
-
var
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1288
|
+
var a;
|
|
1289
|
+
const t = ((a = r == null ? void 0 : r.error) == null ? void 0 : a.message) || (r == null ? void 0 : r.message) || "Gemini request failed";
|
|
1290
|
+
if (e === 429) {
|
|
1291
|
+
const s = new Error(`Rate limit exceeded: ${t}`);
|
|
1292
|
+
return s.code = "RATE_LIMIT_EXCEEDED", s.status = 429, s;
|
|
1274
1293
|
}
|
|
1275
|
-
if (
|
|
1276
|
-
const
|
|
1277
|
-
return
|
|
1294
|
+
if (e === 401 || e === 403) {
|
|
1295
|
+
const s = new Error(`Authentication failed: ${t}`);
|
|
1296
|
+
return s.code = "AUTH_ERROR", s.status = e, s;
|
|
1278
1297
|
}
|
|
1279
|
-
|
|
1298
|
+
if (e === 400) {
|
|
1299
|
+
const s = new Error(`Bad request: ${t}`);
|
|
1300
|
+
return s.code = "INVALID_REQUEST", s.status = 400, s;
|
|
1301
|
+
}
|
|
1302
|
+
const o = new Error(t);
|
|
1303
|
+
return o.code = "API_ERROR", o.status = e, o;
|
|
1280
1304
|
}
|
|
1281
1305
|
}
|
|
1282
|
-
|
|
1306
|
+
const B = (n) => {
|
|
1307
|
+
try {
|
|
1308
|
+
return JSON.parse(n);
|
|
1309
|
+
} catch {
|
|
1310
|
+
return { error: n };
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
class We {
|
|
1283
1314
|
/**
|
|
1284
1315
|
* Tool calling requires /api/chat, not /api/generate (which has no tool
|
|
1285
1316
|
* support at all). Tool support itself is model-dependent (llama3.1+,
|
|
@@ -1288,7 +1319,7 @@ class Je {
|
|
|
1288
1319
|
* this degrades gracefully rather than special-casing it.
|
|
1289
1320
|
*/
|
|
1290
1321
|
async *streamChat(e, r, t) {
|
|
1291
|
-
var
|
|
1322
|
+
var d, m, p, h, w;
|
|
1292
1323
|
const { baseUrl: o = "http://localhost:11434", model: a = x.ollama } = r, s = t != null && t.length ? t.map((g) => ({ type: "function", function: { name: g.name, description: g.description, parameters: g.parameters } })) : void 0, c = await fetch(`${o}/api/chat`, {
|
|
1293
1324
|
method: "POST",
|
|
1294
1325
|
headers: { "Content-Type": "application/json" },
|
|
@@ -1301,29 +1332,29 @@ class Je {
|
|
|
1301
1332
|
});
|
|
1302
1333
|
if (!c.ok) {
|
|
1303
1334
|
const g = await c.text();
|
|
1304
|
-
throw
|
|
1335
|
+
throw this.normalizeError(c.status, B(g));
|
|
1305
1336
|
}
|
|
1306
|
-
const i = (
|
|
1337
|
+
const i = (d = c.body) == null ? void 0 : d.getReader();
|
|
1307
1338
|
if (!i) throw new Error("No response body");
|
|
1308
1339
|
const l = new TextDecoder();
|
|
1309
|
-
let
|
|
1340
|
+
let u = "";
|
|
1310
1341
|
for (; ; ) {
|
|
1311
1342
|
const { done: g, value: y } = await i.read();
|
|
1312
1343
|
if (g) break;
|
|
1313
|
-
|
|
1314
|
-
const A =
|
|
1344
|
+
u += l.decode(y, { stream: !0 });
|
|
1345
|
+
const A = u.split(`
|
|
1315
1346
|
`);
|
|
1316
|
-
|
|
1347
|
+
u = A.pop() || "";
|
|
1317
1348
|
for (const S of A) {
|
|
1318
1349
|
const v = S.trim();
|
|
1319
1350
|
if (v)
|
|
1320
1351
|
try {
|
|
1321
|
-
const
|
|
1322
|
-
if ((m =
|
|
1323
|
-
for (const
|
|
1352
|
+
const E = JSON.parse(v);
|
|
1353
|
+
if ((m = E.message) != null && m.content && (yield { type: "text-delta", text: E.message.content }), (p = E.message) != null && p.tool_calls)
|
|
1354
|
+
for (const I of E.message.tool_calls)
|
|
1324
1355
|
yield {
|
|
1325
1356
|
type: "tool-call",
|
|
1326
|
-
toolCall: { name: (h =
|
|
1357
|
+
toolCall: { name: (h = I.function) == null ? void 0 : h.name, arguments: ((w = I.function) == null ? void 0 : w.arguments) ?? {} }
|
|
1327
1358
|
};
|
|
1328
1359
|
} catch {
|
|
1329
1360
|
}
|
|
@@ -1342,7 +1373,7 @@ class Je {
|
|
|
1342
1373
|
});
|
|
1343
1374
|
if (!a.ok) {
|
|
1344
1375
|
const c = await a.text();
|
|
1345
|
-
throw
|
|
1376
|
+
throw this.normalizeError(a.status, B(c));
|
|
1346
1377
|
}
|
|
1347
1378
|
return (await a.json()).response;
|
|
1348
1379
|
}
|
|
@@ -1358,17 +1389,17 @@ class Je {
|
|
|
1358
1389
|
})
|
|
1359
1390
|
});
|
|
1360
1391
|
if (!a.ok) {
|
|
1361
|
-
const
|
|
1362
|
-
throw
|
|
1392
|
+
const u = await a.text();
|
|
1393
|
+
throw this.normalizeError(a.status, B(u));
|
|
1363
1394
|
}
|
|
1364
1395
|
const s = (l = a.body) == null ? void 0 : l.getReader();
|
|
1365
1396
|
if (!s) throw new Error("No response body");
|
|
1366
1397
|
const c = new TextDecoder();
|
|
1367
1398
|
let i = "";
|
|
1368
1399
|
for (; ; ) {
|
|
1369
|
-
const { done:
|
|
1370
|
-
if (
|
|
1371
|
-
i += c.decode(
|
|
1400
|
+
const { done: u, value: d } = await s.read();
|
|
1401
|
+
if (u) break;
|
|
1402
|
+
i += c.decode(d, { stream: !0 });
|
|
1372
1403
|
const m = i.split(`
|
|
1373
1404
|
`);
|
|
1374
1405
|
i = m.pop() || "";
|
|
@@ -1397,17 +1428,36 @@ Do not include any explanation, only the raw JSON object.`, a = await this.gener
|
|
|
1397
1428
|
var a;
|
|
1398
1429
|
const t = await fetch(`${r}/api/tags`);
|
|
1399
1430
|
if (!t.ok)
|
|
1400
|
-
throw
|
|
1431
|
+
throw this.normalizeError(t.status, {
|
|
1432
|
+
error: `Failed to fetch Ollama models. Is Ollama running at ${r}?`
|
|
1433
|
+
});
|
|
1401
1434
|
return ((a = (await t.json()).models) == null ? void 0 : a.map((s) => s.name)) || [];
|
|
1402
1435
|
}
|
|
1436
|
+
normalizeError(e, r) {
|
|
1437
|
+
const t = (r == null ? void 0 : r.error) || (r == null ? void 0 : r.message) || "Ollama request failed";
|
|
1438
|
+
if (e === 429) {
|
|
1439
|
+
const a = new Error(`Rate limit exceeded: ${t}`);
|
|
1440
|
+
return a.code = "RATE_LIMIT_EXCEEDED", a.status = 429, a;
|
|
1441
|
+
}
|
|
1442
|
+
if (e === 401 || e === 403) {
|
|
1443
|
+
const a = new Error(`Authentication failed: ${t}`);
|
|
1444
|
+
return a.code = "AUTH_ERROR", a.status = e, a;
|
|
1445
|
+
}
|
|
1446
|
+
if (e === 400) {
|
|
1447
|
+
const a = new Error(`Bad request: ${t}`);
|
|
1448
|
+
return a.code = "INVALID_REQUEST", a.status = 400, a;
|
|
1449
|
+
}
|
|
1450
|
+
const o = new Error(t);
|
|
1451
|
+
return o.code = "API_ERROR", o.status = e, o;
|
|
1452
|
+
}
|
|
1403
1453
|
}
|
|
1404
|
-
const
|
|
1454
|
+
const q = (n) => {
|
|
1405
1455
|
try {
|
|
1406
1456
|
return JSON.parse(n);
|
|
1407
1457
|
} catch {
|
|
1408
1458
|
return { error: { message: n } };
|
|
1409
1459
|
}
|
|
1410
|
-
},
|
|
1460
|
+
}, J = (n) => typeof n == "string" ? n ? [{ type: "text", text: n }] : [] : n, He = (n) => {
|
|
1411
1461
|
var r;
|
|
1412
1462
|
const e = [];
|
|
1413
1463
|
for (const t of n) {
|
|
@@ -1419,7 +1469,7 @@ const Z = (n) => {
|
|
|
1419
1469
|
} : t.role === "assistant" && ((r = t.toolCalls) != null && r.length) ? o = {
|
|
1420
1470
|
role: "assistant",
|
|
1421
1471
|
content: [
|
|
1422
|
-
...
|
|
1472
|
+
...J(t.content),
|
|
1423
1473
|
...t.toolCalls.map((s) => ({
|
|
1424
1474
|
type: "tool_use",
|
|
1425
1475
|
id: s.id ?? "",
|
|
@@ -1429,11 +1479,11 @@ const Z = (n) => {
|
|
|
1429
1479
|
]
|
|
1430
1480
|
} : o = { role: t.role, content: t.content };
|
|
1431
1481
|
const a = e[e.length - 1];
|
|
1432
|
-
a && a.role === o.role ? a.content = [...
|
|
1482
|
+
a && a.role === o.role ? a.content = [...J(a.content), ...J(o.content)] : e.push(o);
|
|
1433
1483
|
}
|
|
1434
1484
|
return e;
|
|
1435
1485
|
};
|
|
1436
|
-
class
|
|
1486
|
+
class Fe {
|
|
1437
1487
|
async *streamChat(e, r, t) {
|
|
1438
1488
|
var y, A, S;
|
|
1439
1489
|
const {
|
|
@@ -1444,7 +1494,7 @@ class Ye {
|
|
|
1444
1494
|
baseUrl: i = "https://api.anthropic.com/v1"
|
|
1445
1495
|
} = r;
|
|
1446
1496
|
if (!o) throw new Error("Anthropic API key required");
|
|
1447
|
-
const l = e.find((v) => v.role === "system"),
|
|
1497
|
+
const l = e.find((v) => v.role === "system"), u = He(e), d = t != null && t.length ? t.map((v) => ({ name: v.name, description: v.description, input_schema: v.parameters })) : void 0, m = await fetch(`${i}/messages`, {
|
|
1448
1498
|
method: "POST",
|
|
1449
1499
|
headers: {
|
|
1450
1500
|
"Content-Type": "application/json",
|
|
@@ -1454,34 +1504,34 @@ class Ye {
|
|
|
1454
1504
|
},
|
|
1455
1505
|
body: JSON.stringify({
|
|
1456
1506
|
model: a,
|
|
1457
|
-
messages:
|
|
1507
|
+
messages: u,
|
|
1458
1508
|
...l && { system: l.content },
|
|
1459
1509
|
max_tokens: c,
|
|
1460
1510
|
temperature: s,
|
|
1461
1511
|
stream: !0,
|
|
1462
|
-
...
|
|
1512
|
+
...d && { tools: d }
|
|
1463
1513
|
})
|
|
1464
1514
|
});
|
|
1465
1515
|
if (!m.ok) {
|
|
1466
1516
|
const v = await m.text();
|
|
1467
|
-
throw this.normalizeError(m.status,
|
|
1517
|
+
throw this.normalizeError(m.status, q(v));
|
|
1468
1518
|
}
|
|
1469
1519
|
if (!m.body) throw new Error("No response body for streaming");
|
|
1470
1520
|
const p = m.body.getReader(), h = new TextDecoder();
|
|
1471
1521
|
let w = "", g = null;
|
|
1472
1522
|
try {
|
|
1473
1523
|
for (; ; ) {
|
|
1474
|
-
const { done: v, value:
|
|
1524
|
+
const { done: v, value: E } = await p.read();
|
|
1475
1525
|
if (v) break;
|
|
1476
|
-
w += h.decode(
|
|
1477
|
-
const
|
|
1526
|
+
w += h.decode(E, { stream: !0 });
|
|
1527
|
+
const I = w.split(`
|
|
1478
1528
|
`);
|
|
1479
|
-
w =
|
|
1480
|
-
for (const j of
|
|
1481
|
-
const
|
|
1482
|
-
if (!(!
|
|
1529
|
+
w = I.pop() || "";
|
|
1530
|
+
for (const j of I) {
|
|
1531
|
+
const N = j.trim();
|
|
1532
|
+
if (!(!N || !N.startsWith("data: ")))
|
|
1483
1533
|
try {
|
|
1484
|
-
const T = JSON.parse(
|
|
1534
|
+
const T = JSON.parse(N.slice(6));
|
|
1485
1535
|
if (T.type === "content_block_start" && ((y = T.content_block) == null ? void 0 : y.type) === "tool_use")
|
|
1486
1536
|
g = { id: T.content_block.id, name: T.content_block.name, argsBuf: "" };
|
|
1487
1537
|
else if (T.type === "content_block_delta")
|
|
@@ -1509,7 +1559,7 @@ class Ye {
|
|
|
1509
1559
|
}
|
|
1510
1560
|
}
|
|
1511
1561
|
async generateText(e, r) {
|
|
1512
|
-
var
|
|
1562
|
+
var u, d;
|
|
1513
1563
|
const {
|
|
1514
1564
|
apiKey: t,
|
|
1515
1565
|
model: o = x.anthropic,
|
|
@@ -1537,9 +1587,9 @@ class Ye {
|
|
|
1537
1587
|
});
|
|
1538
1588
|
if (!i.ok) {
|
|
1539
1589
|
const m = await i.text();
|
|
1540
|
-
throw console.error("🔴 RAW ANTHROPIC ERROR:", i.status, m), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", o), this.normalizeError(i.status,
|
|
1590
|
+
throw console.error("🔴 RAW ANTHROPIC ERROR:", i.status, m), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", o), this.normalizeError(i.status, q(m));
|
|
1541
1591
|
}
|
|
1542
|
-
return ((
|
|
1592
|
+
return ((d = (u = (await i.json()).content) == null ? void 0 : u[0]) == null ? void 0 : d.text) || "";
|
|
1543
1593
|
}
|
|
1544
1594
|
async *streamText(e, r) {
|
|
1545
1595
|
var m;
|
|
@@ -1571,19 +1621,19 @@ class Ye {
|
|
|
1571
1621
|
});
|
|
1572
1622
|
if (!i.ok) {
|
|
1573
1623
|
const p = await i.text();
|
|
1574
|
-
throw console.error("🔴 RAW ANTHROPIC STREAM ERROR:", i.status, p), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", o), this.normalizeError(i.status,
|
|
1624
|
+
throw console.error("🔴 RAW ANTHROPIC STREAM ERROR:", i.status, p), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", o), this.normalizeError(i.status, q(p));
|
|
1575
1625
|
}
|
|
1576
1626
|
if (!i.body) throw new Error("No response body for streaming");
|
|
1577
|
-
const l = i.body.getReader(),
|
|
1578
|
-
let
|
|
1627
|
+
const l = i.body.getReader(), u = new TextDecoder();
|
|
1628
|
+
let d = "";
|
|
1579
1629
|
try {
|
|
1580
1630
|
for (; ; ) {
|
|
1581
1631
|
const { done: p, value: h } = await l.read();
|
|
1582
1632
|
if (p) break;
|
|
1583
|
-
|
|
1584
|
-
const w =
|
|
1633
|
+
d += u.decode(h, { stream: !0 });
|
|
1634
|
+
const w = d.split(`
|
|
1585
1635
|
`);
|
|
1586
|
-
|
|
1636
|
+
d = w.pop() || "";
|
|
1587
1637
|
for (const g of w) {
|
|
1588
1638
|
const y = g.trim();
|
|
1589
1639
|
if (!y || !y.startsWith("data: ")) continue;
|
|
@@ -1629,9 +1679,9 @@ class Ye {
|
|
|
1629
1679
|
const l = r ? `
|
|
1630
1680
|
|
|
1631
1681
|
It must match this shape:
|
|
1632
|
-
${JSON.stringify(r)}` : "",
|
|
1682
|
+
${JSON.stringify(r)}` : "", u = `${e}${l}
|
|
1633
1683
|
|
|
1634
|
-
IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the JSON object.`,
|
|
1684
|
+
IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the JSON object.`, d = await fetch(`${i}/messages`, {
|
|
1635
1685
|
method: "POST",
|
|
1636
1686
|
headers: {
|
|
1637
1687
|
"Content-Type": "application/json",
|
|
@@ -1641,21 +1691,21 @@ IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the J
|
|
|
1641
1691
|
},
|
|
1642
1692
|
body: JSON.stringify({
|
|
1643
1693
|
model: a,
|
|
1644
|
-
messages: [{ role: "user", content:
|
|
1694
|
+
messages: [{ role: "user", content: u }],
|
|
1645
1695
|
max_tokens: c,
|
|
1646
1696
|
// REQUIRED by Anthropic
|
|
1647
1697
|
temperature: s
|
|
1648
1698
|
})
|
|
1649
1699
|
});
|
|
1650
|
-
if (!
|
|
1651
|
-
const A = await
|
|
1652
|
-
throw console.error("🔴 RAW ANTHROPIC OBJECT ERROR:",
|
|
1700
|
+
if (!d.ok) {
|
|
1701
|
+
const A = await d.text();
|
|
1702
|
+
throw console.error("🔴 RAW ANTHROPIC OBJECT ERROR:", d.status, A), console.error("🔴 Request was made to:", `${i}/messages`), console.error("🔴 Model requested:", a), this.normalizeError(d.status, q(A));
|
|
1653
1703
|
}
|
|
1654
|
-
const p = ((y = (g = (await
|
|
1704
|
+
const p = ((y = (g = (await d.json()).content) == null ? void 0 : g[0]) == null ? void 0 : y.text) || "{}", h = p.match(/\{[\s\S]*\}/), w = h ? h[0] : p;
|
|
1655
1705
|
return JSON.parse(w);
|
|
1656
1706
|
}
|
|
1657
1707
|
async listModels(e, r) {
|
|
1658
|
-
return [...
|
|
1708
|
+
return [...G.anthropic];
|
|
1659
1709
|
}
|
|
1660
1710
|
normalizeError(e, r) {
|
|
1661
1711
|
var a;
|
|
@@ -1676,15 +1726,15 @@ IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the J
|
|
|
1676
1726
|
return o.code = "API_ERROR", o.status = e, o;
|
|
1677
1727
|
}
|
|
1678
1728
|
}
|
|
1679
|
-
function
|
|
1729
|
+
function C(n) {
|
|
1680
1730
|
if (!(!n || n.length === 0))
|
|
1681
1731
|
return n.map((e) => ({
|
|
1682
1732
|
type: "function",
|
|
1683
1733
|
function: { name: e.name, description: e.description, parameters: e.parameters }
|
|
1684
1734
|
}));
|
|
1685
1735
|
}
|
|
1686
|
-
async function*
|
|
1687
|
-
var l,
|
|
1736
|
+
async function* Y(n, e, r, t) {
|
|
1737
|
+
var l, u, d, m;
|
|
1688
1738
|
const o = await fetch(n, {
|
|
1689
1739
|
method: "POST",
|
|
1690
1740
|
headers: e,
|
|
@@ -1712,12 +1762,12 @@ async function* J(n, e, r, t) {
|
|
|
1712
1762
|
const A = y.slice(6);
|
|
1713
1763
|
if (A !== "[DONE]")
|
|
1714
1764
|
try {
|
|
1715
|
-
const v = (
|
|
1765
|
+
const v = (u = (l = JSON.parse(A).choices) == null ? void 0 : l[0]) == null ? void 0 : u.delta;
|
|
1716
1766
|
if (!v) continue;
|
|
1717
1767
|
if (v.content && (yield { type: "text-delta", text: v.content }), v.tool_calls)
|
|
1718
|
-
for (const
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1768
|
+
for (const E of v.tool_calls) {
|
|
1769
|
+
const I = E.index ?? 0, j = i.get(I) ?? { name: "", args: "" };
|
|
1770
|
+
E.id && (j.id = E.id), (d = E.function) != null && d.name && (j.name += E.function.name), (m = E.function) != null && m.arguments && (j.args += E.function.arguments), i.set(I, j);
|
|
1721
1771
|
}
|
|
1722
1772
|
} catch {
|
|
1723
1773
|
}
|
|
@@ -1740,28 +1790,28 @@ async function* J(n, e, r, t) {
|
|
|
1740
1790
|
} catch {
|
|
1741
1791
|
}
|
|
1742
1792
|
}
|
|
1743
|
-
function
|
|
1793
|
+
function W(n) {
|
|
1744
1794
|
return n.map((e) => ({ role: e.role, content: e.content }));
|
|
1745
1795
|
}
|
|
1746
|
-
class
|
|
1796
|
+
class Ve {
|
|
1747
1797
|
async *streamChat(e, r, t) {
|
|
1748
1798
|
const { apiKey: o, model: a = x.openai, temperature: s = 0.7, baseUrl: c = "https://api.openai.com/v1" } = r;
|
|
1749
1799
|
if (!o) throw new Error("OpenAI API key required");
|
|
1750
|
-
yield*
|
|
1800
|
+
yield* Y(
|
|
1751
1801
|
`${c}/chat/completions`,
|
|
1752
1802
|
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
1753
1803
|
{
|
|
1754
1804
|
model: a,
|
|
1755
|
-
messages:
|
|
1805
|
+
messages: W(e),
|
|
1756
1806
|
temperature: s,
|
|
1757
1807
|
stream: !0,
|
|
1758
|
-
...
|
|
1808
|
+
...C(t) && { tools: C(t), tool_choice: "auto" }
|
|
1759
1809
|
},
|
|
1760
1810
|
this.normalizeError
|
|
1761
1811
|
);
|
|
1762
1812
|
}
|
|
1763
1813
|
async generateText(e, r) {
|
|
1764
|
-
var l,
|
|
1814
|
+
var l, u, d;
|
|
1765
1815
|
const { apiKey: t, model: o = x.openai, temperature: a = 0.7, baseUrl: s = "https://api.openai.com/v1" } = r;
|
|
1766
1816
|
if (!t) throw new Error("OpenAI API key required");
|
|
1767
1817
|
const c = await fetch(`${s}/chat/completions`, {
|
|
@@ -1780,10 +1830,10 @@ class We {
|
|
|
1780
1830
|
const m = await c.json();
|
|
1781
1831
|
throw this.normalizeError(c.status, m);
|
|
1782
1832
|
}
|
|
1783
|
-
return ((
|
|
1833
|
+
return ((d = (u = (l = (await c.json()).choices) == null ? void 0 : l[0]) == null ? void 0 : u.message) == null ? void 0 : d.content) || "";
|
|
1784
1834
|
}
|
|
1785
1835
|
async *streamText(e, r) {
|
|
1786
|
-
var
|
|
1836
|
+
var d, m, p;
|
|
1787
1837
|
const { apiKey: t, model: o = x.openai, temperature: a = 0.7, baseUrl: s = "https://api.openai.com/v1" } = r;
|
|
1788
1838
|
if (!t) throw new Error("OpenAI API key required");
|
|
1789
1839
|
const c = await fetch(`${s}/chat/completions`, {
|
|
@@ -1805,23 +1855,23 @@ class We {
|
|
|
1805
1855
|
}
|
|
1806
1856
|
if (!c.body) throw new Error("No response body for streaming");
|
|
1807
1857
|
const i = c.body.getReader(), l = new TextDecoder();
|
|
1808
|
-
let
|
|
1858
|
+
let u = "";
|
|
1809
1859
|
try {
|
|
1810
1860
|
for (; ; ) {
|
|
1811
1861
|
const { done: h, value: w } = await i.read();
|
|
1812
1862
|
if (h) break;
|
|
1813
|
-
|
|
1814
|
-
const g =
|
|
1863
|
+
u += l.decode(w, { stream: !0 });
|
|
1864
|
+
const g = u.split(`
|
|
1815
1865
|
`);
|
|
1816
|
-
|
|
1866
|
+
u = g.pop() || "";
|
|
1817
1867
|
for (const y of g) {
|
|
1818
1868
|
const A = y.trim();
|
|
1819
1869
|
if (!A || !A.startsWith("data: ")) continue;
|
|
1820
1870
|
const S = A.slice(6);
|
|
1821
1871
|
if (S !== "[DONE]")
|
|
1822
1872
|
try {
|
|
1823
|
-
const
|
|
1824
|
-
|
|
1873
|
+
const E = (p = (m = (d = JSON.parse(S).choices) == null ? void 0 : d[0]) == null ? void 0 : m.delta) == null ? void 0 : p.content;
|
|
1874
|
+
E && (yield E);
|
|
1825
1875
|
} catch {
|
|
1826
1876
|
}
|
|
1827
1877
|
}
|
|
@@ -1831,7 +1881,7 @@ class We {
|
|
|
1831
1881
|
}
|
|
1832
1882
|
}
|
|
1833
1883
|
async generateObject(e, r, t) {
|
|
1834
|
-
var
|
|
1884
|
+
var d, m, p;
|
|
1835
1885
|
const { apiKey: o, model: a = x.openai, temperature: s = 0.7, baseUrl: c = "https://api.openai.com/v1" } = t;
|
|
1836
1886
|
if (!o) throw new Error("OpenAI API key required");
|
|
1837
1887
|
const i = await fetch(`${c}/chat/completions`, {
|
|
@@ -1851,8 +1901,8 @@ class We {
|
|
|
1851
1901
|
const h = await i.json();
|
|
1852
1902
|
throw this.normalizeError(i.status, h);
|
|
1853
1903
|
}
|
|
1854
|
-
const
|
|
1855
|
-
return JSON.parse(
|
|
1904
|
+
const u = ((p = (m = (d = (await i.json()).choices) == null ? void 0 : d[0]) == null ? void 0 : m.message) == null ? void 0 : p.content) || "{}";
|
|
1905
|
+
return JSON.parse(u);
|
|
1856
1906
|
}
|
|
1857
1907
|
async listModels(e, r) {
|
|
1858
1908
|
var s, c;
|
|
@@ -1884,25 +1934,25 @@ class We {
|
|
|
1884
1934
|
return o.code = "API_ERROR", o.status = e, o;
|
|
1885
1935
|
}
|
|
1886
1936
|
}
|
|
1887
|
-
class
|
|
1937
|
+
class Ke {
|
|
1888
1938
|
async *streamChat(e, r, t) {
|
|
1889
1939
|
const { apiKey: o, model: a = x.grok, temperature: s = 0.7, baseUrl: c = "https://api.x.ai/v1" } = r;
|
|
1890
1940
|
if (!o) throw new Error("Grok API key required");
|
|
1891
|
-
yield*
|
|
1941
|
+
yield* Y(
|
|
1892
1942
|
`${c}/chat/completions`,
|
|
1893
1943
|
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
1894
1944
|
{
|
|
1895
1945
|
model: a,
|
|
1896
|
-
messages:
|
|
1946
|
+
messages: W(e),
|
|
1897
1947
|
temperature: s,
|
|
1898
1948
|
stream: !0,
|
|
1899
|
-
...
|
|
1949
|
+
...C(t) && { tools: C(t), tool_choice: "auto" }
|
|
1900
1950
|
},
|
|
1901
1951
|
this.normalizeError
|
|
1902
1952
|
);
|
|
1903
1953
|
}
|
|
1904
1954
|
async generateText(e, r) {
|
|
1905
|
-
var l,
|
|
1955
|
+
var l, u, d;
|
|
1906
1956
|
const { apiKey: t, model: o = x.grok, temperature: a = 0.7, baseUrl: s = "https://api.x.ai/v1" } = r;
|
|
1907
1957
|
if (!t) throw new Error("Grok API key required");
|
|
1908
1958
|
const c = await fetch(`${s}/chat/completions`, {
|
|
@@ -1921,10 +1971,10 @@ class Fe {
|
|
|
1921
1971
|
const m = await c.json();
|
|
1922
1972
|
throw this.normalizeError(c.status, m);
|
|
1923
1973
|
}
|
|
1924
|
-
return ((
|
|
1974
|
+
return ((d = (u = (l = (await c.json()).choices) == null ? void 0 : l[0]) == null ? void 0 : u.message) == null ? void 0 : d.content) || "";
|
|
1925
1975
|
}
|
|
1926
1976
|
async *streamText(e, r) {
|
|
1927
|
-
var
|
|
1977
|
+
var d, m, p;
|
|
1928
1978
|
const { apiKey: t, model: o = x.grok, temperature: a = 0.7, baseUrl: s = "https://api.x.ai/v1" } = r;
|
|
1929
1979
|
if (!t) throw new Error("Grok API key required");
|
|
1930
1980
|
const c = await fetch(`${s}/chat/completions`, {
|
|
@@ -1946,23 +1996,23 @@ class Fe {
|
|
|
1946
1996
|
}
|
|
1947
1997
|
if (!c.body) throw new Error("No response body for streaming");
|
|
1948
1998
|
const i = c.body.getReader(), l = new TextDecoder();
|
|
1949
|
-
let
|
|
1999
|
+
let u = "";
|
|
1950
2000
|
try {
|
|
1951
2001
|
for (; ; ) {
|
|
1952
2002
|
const { done: h, value: w } = await i.read();
|
|
1953
2003
|
if (h) break;
|
|
1954
|
-
|
|
1955
|
-
const g =
|
|
2004
|
+
u += l.decode(w, { stream: !0 });
|
|
2005
|
+
const g = u.split(`
|
|
1956
2006
|
`);
|
|
1957
|
-
|
|
2007
|
+
u = g.pop() || "";
|
|
1958
2008
|
for (const y of g) {
|
|
1959
2009
|
const A = y.trim();
|
|
1960
2010
|
if (!A || !A.startsWith("data: ")) continue;
|
|
1961
2011
|
const S = A.slice(6);
|
|
1962
2012
|
if (S !== "[DONE]")
|
|
1963
2013
|
try {
|
|
1964
|
-
const
|
|
1965
|
-
|
|
2014
|
+
const E = (p = (m = (d = JSON.parse(S).choices) == null ? void 0 : d[0]) == null ? void 0 : m.delta) == null ? void 0 : p.content;
|
|
2015
|
+
E && (yield E);
|
|
1966
2016
|
} catch {
|
|
1967
2017
|
}
|
|
1968
2018
|
}
|
|
@@ -1993,11 +2043,11 @@ Respond with valid JSON only.`, l = await fetch(`${c}/chat/completions`, {
|
|
|
1993
2043
|
const y = await l.json();
|
|
1994
2044
|
throw this.normalizeError(l.status, y);
|
|
1995
2045
|
}
|
|
1996
|
-
const
|
|
2046
|
+
const d = ((g = (w = (h = (await l.json()).choices) == null ? void 0 : h[0]) == null ? void 0 : w.message) == null ? void 0 : g.content) || "{}", m = d.match(/\{[\s\S]*\}/), p = m ? m[0] : d;
|
|
1997
2047
|
return JSON.parse(p);
|
|
1998
2048
|
}
|
|
1999
2049
|
async listModels(e, r) {
|
|
2000
|
-
return [...
|
|
2050
|
+
return [...G.grok];
|
|
2001
2051
|
}
|
|
2002
2052
|
normalizeError(e, r) {
|
|
2003
2053
|
var a;
|
|
@@ -2014,25 +2064,25 @@ Respond with valid JSON only.`, l = await fetch(`${c}/chat/completions`, {
|
|
|
2014
2064
|
return o.code = "API_ERROR", o.status = e, o;
|
|
2015
2065
|
}
|
|
2016
2066
|
}
|
|
2017
|
-
class
|
|
2067
|
+
class Xe {
|
|
2018
2068
|
async *streamChat(e, r, t) {
|
|
2019
2069
|
const { apiKey: o, model: a = x.deepseek, temperature: s = 0.7, baseUrl: c = "https://api.deepseek.com/v1" } = r;
|
|
2020
2070
|
if (!o) throw new Error("DeepSeek API key required");
|
|
2021
|
-
yield*
|
|
2071
|
+
yield* Y(
|
|
2022
2072
|
`${c}/chat/completions`,
|
|
2023
2073
|
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
2024
2074
|
{
|
|
2025
2075
|
model: a,
|
|
2026
|
-
messages:
|
|
2076
|
+
messages: W(e),
|
|
2027
2077
|
temperature: s,
|
|
2028
2078
|
stream: !0,
|
|
2029
|
-
...
|
|
2079
|
+
...C(t) && { tools: C(t), tool_choice: "auto" }
|
|
2030
2080
|
},
|
|
2031
2081
|
this.normalizeError
|
|
2032
2082
|
);
|
|
2033
2083
|
}
|
|
2034
2084
|
async generateText(e, r) {
|
|
2035
|
-
var l,
|
|
2085
|
+
var l, u, d;
|
|
2036
2086
|
const { apiKey: t, model: o = x.deepseek, temperature: a = 0.7, baseUrl: s = "https://api.deepseek.com/v1" } = r;
|
|
2037
2087
|
if (!t) throw new Error("DeepSeek API key required");
|
|
2038
2088
|
const c = await fetch(`${s}/chat/completions`, {
|
|
@@ -2051,10 +2101,10 @@ class He {
|
|
|
2051
2101
|
const m = await c.json();
|
|
2052
2102
|
throw this.normalizeError(c.status, m);
|
|
2053
2103
|
}
|
|
2054
|
-
return ((
|
|
2104
|
+
return ((d = (u = (l = (await c.json()).choices) == null ? void 0 : l[0]) == null ? void 0 : u.message) == null ? void 0 : d.content) || "";
|
|
2055
2105
|
}
|
|
2056
2106
|
async *streamText(e, r) {
|
|
2057
|
-
var
|
|
2107
|
+
var d, m, p;
|
|
2058
2108
|
const { apiKey: t, model: o = x.deepseek, temperature: a = 0.7, baseUrl: s = "https://api.deepseek.com/v1" } = r;
|
|
2059
2109
|
if (!t) throw new Error("DeepSeek API key required");
|
|
2060
2110
|
const c = await fetch(`${s}/chat/completions`, {
|
|
@@ -2076,23 +2126,23 @@ class He {
|
|
|
2076
2126
|
}
|
|
2077
2127
|
if (!c.body) throw new Error("No response body for streaming");
|
|
2078
2128
|
const i = c.body.getReader(), l = new TextDecoder();
|
|
2079
|
-
let
|
|
2129
|
+
let u = "";
|
|
2080
2130
|
try {
|
|
2081
2131
|
for (; ; ) {
|
|
2082
2132
|
const { done: h, value: w } = await i.read();
|
|
2083
2133
|
if (h) break;
|
|
2084
|
-
|
|
2085
|
-
const g =
|
|
2134
|
+
u += l.decode(w, { stream: !0 });
|
|
2135
|
+
const g = u.split(`
|
|
2086
2136
|
`);
|
|
2087
|
-
|
|
2137
|
+
u = g.pop() || "";
|
|
2088
2138
|
for (const y of g) {
|
|
2089
2139
|
const A = y.trim();
|
|
2090
2140
|
if (!A || !A.startsWith("data: ")) continue;
|
|
2091
2141
|
const S = A.slice(6);
|
|
2092
2142
|
if (S !== "[DONE]")
|
|
2093
2143
|
try {
|
|
2094
|
-
const
|
|
2095
|
-
|
|
2144
|
+
const E = (p = (m = (d = JSON.parse(S).choices) == null ? void 0 : d[0]) == null ? void 0 : m.delta) == null ? void 0 : p.content;
|
|
2145
|
+
E && (yield E);
|
|
2096
2146
|
} catch {
|
|
2097
2147
|
}
|
|
2098
2148
|
}
|
|
@@ -2102,7 +2152,7 @@ class He {
|
|
|
2102
2152
|
}
|
|
2103
2153
|
}
|
|
2104
2154
|
async generateObject(e, r, t) {
|
|
2105
|
-
var
|
|
2155
|
+
var d, m, p;
|
|
2106
2156
|
const { apiKey: o, model: a = x.deepseek, temperature: s = 0.7, baseUrl: c = "https://api.deepseek.com/v1" } = t;
|
|
2107
2157
|
if (!o) throw new Error("DeepSeek API key required");
|
|
2108
2158
|
const i = await fetch(`${c}/chat/completions`, {
|
|
@@ -2122,11 +2172,11 @@ class He {
|
|
|
2122
2172
|
const h = await i.json();
|
|
2123
2173
|
throw this.normalizeError(i.status, h);
|
|
2124
2174
|
}
|
|
2125
|
-
const
|
|
2126
|
-
return JSON.parse(
|
|
2175
|
+
const u = ((p = (m = (d = (await i.json()).choices) == null ? void 0 : d[0]) == null ? void 0 : m.message) == null ? void 0 : p.content) || "{}";
|
|
2176
|
+
return JSON.parse(u);
|
|
2127
2177
|
}
|
|
2128
2178
|
async listModels(e, r) {
|
|
2129
|
-
return [...
|
|
2179
|
+
return [...G.deepseek];
|
|
2130
2180
|
}
|
|
2131
2181
|
normalizeError(e, r) {
|
|
2132
2182
|
var a;
|
|
@@ -2143,7 +2193,7 @@ class He {
|
|
|
2143
2193
|
return o.code = "API_ERROR", o.status = e, o;
|
|
2144
2194
|
}
|
|
2145
2195
|
}
|
|
2146
|
-
let
|
|
2196
|
+
let Qe = class {
|
|
2147
2197
|
constructor(e) {
|
|
2148
2198
|
this.requests = [], this.config = e;
|
|
2149
2199
|
}
|
|
@@ -2161,16 +2211,16 @@ let Ke = class {
|
|
|
2161
2211
|
};
|
|
2162
2212
|
class D {
|
|
2163
2213
|
constructor() {
|
|
2164
|
-
this.rateLimiter = new
|
|
2214
|
+
this.rateLimiter = new Qe({
|
|
2165
2215
|
maxRequests: 10,
|
|
2166
2216
|
windowMs: 6e4
|
|
2167
2217
|
}), this.adapters = /* @__PURE__ */ new Map([
|
|
2168
|
-
["google-gemini", new
|
|
2169
|
-
["ollama", new
|
|
2170
|
-
["anthropic", new
|
|
2171
|
-
["openai", new
|
|
2172
|
-
["grok", new
|
|
2173
|
-
["deepseek", new
|
|
2218
|
+
["google-gemini", new Ye()],
|
|
2219
|
+
["ollama", new We()],
|
|
2220
|
+
["anthropic", new Fe()],
|
|
2221
|
+
["openai", new Ve()],
|
|
2222
|
+
["grok", new Ke()],
|
|
2223
|
+
["deepseek", new Xe()]
|
|
2174
2224
|
]);
|
|
2175
2225
|
}
|
|
2176
2226
|
static getInstance() {
|
|
@@ -2251,8 +2301,8 @@ class D {
|
|
|
2251
2301
|
return o.listModels(r, t);
|
|
2252
2302
|
}
|
|
2253
2303
|
}
|
|
2254
|
-
const
|
|
2255
|
-
class
|
|
2304
|
+
const ht = D.getInstance();
|
|
2305
|
+
class gt {
|
|
2256
2306
|
/**
|
|
2257
2307
|
* Resolve configuration with 3-tier priority:
|
|
2258
2308
|
* 1. User's localStorage override (highest priority)
|
|
@@ -2343,10 +2393,10 @@ class mt {
|
|
|
2343
2393
|
} : {};
|
|
2344
2394
|
}
|
|
2345
2395
|
}
|
|
2346
|
-
const
|
|
2396
|
+
const et = ([n, e, r]) => n >> 3 << 11 | e >> 2 << 5 | r >> 3, tt = (n) => {
|
|
2347
2397
|
const e = n >> 11 & 31, r = n >> 5 & 63, t = n & 31;
|
|
2348
2398
|
return [e << 3 | e >> 2, r << 2 | r >> 4, t << 3 | t >> 2];
|
|
2349
|
-
},
|
|
2399
|
+
}, H = (n) => Math.ceil(n / 2), ae = (n, e, r) => O.headerBytes + r * 2 + H(n) * e, ft = (n) => {
|
|
2350
2400
|
const { width: e, height: r, palette: t, indices: o } = n;
|
|
2351
2401
|
if (!Number.isInteger(e) || !Number.isInteger(r) || e < 1 || r < 1 || e > 65535 || r > 65535)
|
|
2352
2402
|
throw new RangeError(`encodeSpr: bad size ${e}x${r}`);
|
|
@@ -2354,52 +2404,52 @@ const Ve = ([n, e, r]) => n >> 3 << 11 | e >> 2 << 5 | r >> 3, Xe = (n) => {
|
|
|
2354
2404
|
throw new RangeError(`encodeSpr: ${t.length} colours; 1 to ${O.maxColors} allowed`);
|
|
2355
2405
|
if (o.length !== e * r)
|
|
2356
2406
|
throw new RangeError(`encodeSpr: ${o.length} indices for ${e}x${r}`);
|
|
2357
|
-
const a = new Uint8Array(
|
|
2407
|
+
const a = new Uint8Array(ae(e, r, t.length)), s = new DataView(a.buffer);
|
|
2358
2408
|
a.set(O.magic, 0), a[4] = O.version, s.setUint16(5, e, !0), s.setUint16(7, r, !0), a[9] = O.bitsPerPixel, a[10] = t.length;
|
|
2359
2409
|
let c = O.headerBytes;
|
|
2360
2410
|
for (const l of t)
|
|
2361
|
-
s.setUint16(c,
|
|
2362
|
-
const i =
|
|
2411
|
+
s.setUint16(c, et(l), !0), c += 2;
|
|
2412
|
+
const i = H(e);
|
|
2363
2413
|
for (let l = 0; l < r; l++)
|
|
2364
|
-
for (let
|
|
2365
|
-
const
|
|
2366
|
-
if (!Number.isInteger(
|
|
2367
|
-
throw new RangeError(`encodeSpr: index ${
|
|
2368
|
-
const m = c + l * i + (
|
|
2369
|
-
a[m] |=
|
|
2414
|
+
for (let u = 0; u < e; u++) {
|
|
2415
|
+
const d = o[l * e + u];
|
|
2416
|
+
if (!Number.isInteger(d) || d < 0 || d >= t.length)
|
|
2417
|
+
throw new RangeError(`encodeSpr: index ${d} at ${u},${l} is outside a ${t.length}-colour palette`);
|
|
2418
|
+
const m = c + l * i + (u >> 1);
|
|
2419
|
+
a[m] |= u & 1 ? d : d << 4;
|
|
2370
2420
|
}
|
|
2371
2421
|
return a;
|
|
2372
|
-
},
|
|
2422
|
+
}, yt = (n) => {
|
|
2373
2423
|
const e = (m) => ({ ok: !1, reason: m });
|
|
2374
2424
|
if (n.length < O.headerBytes) return e("shorter than the header");
|
|
2375
|
-
if (n.length >
|
|
2425
|
+
if (n.length > F) return e(`${n.length} bytes; at most ${F}`);
|
|
2376
2426
|
if (!O.magic.every((m, p) => n[p] === m)) return e("not an .spr file");
|
|
2377
2427
|
if (n[4] !== O.version) return e(`version ${n[4]}; this reads ${O.version}`);
|
|
2378
2428
|
const r = new DataView(n.buffer, n.byteOffset, n.byteLength), t = r.getUint16(5, !0), o = r.getUint16(7, !0), a = n[9], s = n[10];
|
|
2379
2429
|
if (t < 1 || o < 1) return e(`empty image ${t}x${o}`);
|
|
2380
2430
|
if (a !== O.bitsPerPixel) return e(`${a} bits a pixel; only ${O.bitsPerPixel} is read`);
|
|
2381
2431
|
if (s < 1 || s > O.maxColors) return e(`${s} colours; 1 to ${O.maxColors} allowed`);
|
|
2382
|
-
const c =
|
|
2432
|
+
const c = ae(t, o, s);
|
|
2383
2433
|
if (n.length !== c) return e(`${n.length} bytes; ${t}x${o} with ${s} colours is ${c}`);
|
|
2384
2434
|
const i = [];
|
|
2385
2435
|
let l = O.headerBytes;
|
|
2386
|
-
for (let m = 0; m < s; m++, l += 2) i.push(
|
|
2387
|
-
const
|
|
2436
|
+
for (let m = 0; m < s; m++, l += 2) i.push(tt(r.getUint16(l, !0)));
|
|
2437
|
+
const u = H(t), d = new Uint8Array(t * o);
|
|
2388
2438
|
for (let m = 0; m < o; m++)
|
|
2389
2439
|
for (let p = 0; p < t; p++) {
|
|
2390
|
-
const h = n[l + m *
|
|
2391
|
-
|
|
2440
|
+
const h = n[l + m * u + (p >> 1)], w = p & 1 ? h & 15 : h >> 4;
|
|
2441
|
+
d[m * t + p] = w < s ? w : 0;
|
|
2392
2442
|
}
|
|
2393
|
-
return { ok: !0, image: { width: t, height: o, palette: i, indices:
|
|
2394
|
-
},
|
|
2443
|
+
return { ok: !0, image: { width: t, height: o, palette: i, indices: d } };
|
|
2444
|
+
}, rt = (n) => {
|
|
2395
2445
|
let e = "";
|
|
2396
2446
|
for (const r of n) e += String.fromCharCode(r);
|
|
2397
2447
|
return btoa(e);
|
|
2398
|
-
},
|
|
2448
|
+
}, nt = (n) => Uint8Array.from(atob(n), (e) => e.charCodeAt(0)), ot = (n) => {
|
|
2399
2449
|
if (n === "." || n === " " || n === "_") return 0;
|
|
2400
2450
|
const e = parseInt(n, 16);
|
|
2401
2451
|
return Number.isNaN(e) ? -1 : e;
|
|
2402
|
-
},
|
|
2452
|
+
}, at = (n, e) => {
|
|
2403
2453
|
if (e.length === 0) return { ok: !1, error: "palette is empty" };
|
|
2404
2454
|
if (e.length > 16)
|
|
2405
2455
|
return { ok: !1, error: `palette has ${e.length} colours and a sprite holds at most 16` };
|
|
@@ -2407,10 +2457,10 @@ const Ve = ([n, e, r]) => n >> 3 << 11 | e >> 2 << 5 | r >> 3, Xe = (n) => {
|
|
|
2407
2457
|
`).map((i) => i.trim()).filter((i) => i.length > 0);
|
|
2408
2458
|
if (r.length === 0) return { ok: !1, error: "grid has no rows" };
|
|
2409
2459
|
const t = r.length, o = r[0].length;
|
|
2410
|
-
if (o >
|
|
2460
|
+
if (o > M || t > M)
|
|
2411
2461
|
return {
|
|
2412
2462
|
ok: !1,
|
|
2413
|
-
error: `grid is ${o}x${t} and the largest sprite is ${
|
|
2463
|
+
error: `grid is ${o}x${t} and the largest sprite is ${M}x${M}`
|
|
2414
2464
|
};
|
|
2415
2465
|
const a = r.map((i, l) => ({ i: l, len: i.length })).filter((i) => i.len !== o);
|
|
2416
2466
|
if (a.length > 0) {
|
|
@@ -2423,23 +2473,23 @@ const Ve = ([n, e, r]) => n >> 3 << 11 | e >> 2 << 5 | r >> 3, Xe = (n) => {
|
|
|
2423
2473
|
const s = Math.ceil(o / 2), c = new Uint8Array(s * t);
|
|
2424
2474
|
for (let i = 0; i < t; i++)
|
|
2425
2475
|
for (let l = 0; l < o; l++) {
|
|
2426
|
-
const
|
|
2427
|
-
if (
|
|
2476
|
+
const u = ot(r[i][l]);
|
|
2477
|
+
if (u < 0)
|
|
2428
2478
|
return {
|
|
2429
2479
|
ok: !1,
|
|
2430
2480
|
error: `row ${i + 1}, column ${l + 1}: '${r[i][l]}' is not a hex digit 0-f`
|
|
2431
2481
|
};
|
|
2432
|
-
if (
|
|
2482
|
+
if (u >= e.length)
|
|
2433
2483
|
return {
|
|
2434
2484
|
ok: !1,
|
|
2435
|
-
error: `row ${i + 1}, column ${l + 1}: index ${
|
|
2485
|
+
error: `row ${i + 1}, column ${l + 1}: index ${u.toString(16)} but the palette has ${e.length} colour(s), so the highest is ${(e.length - 1).toString(16)}`
|
|
2436
2486
|
};
|
|
2437
|
-
const
|
|
2438
|
-
c[
|
|
2487
|
+
const d = i * s + (l >> 1);
|
|
2488
|
+
c[d] |= l & 1 ? u : u << 4;
|
|
2439
2489
|
}
|
|
2440
|
-
return { ok: !0, sprite: { width: o, height: t, palette: e, pixels:
|
|
2441
|
-
},
|
|
2442
|
-
const e =
|
|
2490
|
+
return { ok: !0, sprite: { width: o, height: t, palette: e, pixels: rt(c) } };
|
|
2491
|
+
}, wt = (n) => {
|
|
2492
|
+
const e = nt(n.pixels), r = Math.ceil(n.width / 2), t = [];
|
|
2443
2493
|
for (let o = 0; o < n.height; o++) {
|
|
2444
2494
|
let a = "";
|
|
2445
2495
|
for (let s = 0; s < n.width; s++) {
|
|
@@ -2450,7 +2500,7 @@ const Ve = ([n, e, r]) => n >> 3 << 11 | e >> 2 << 5 | r >> 3, Xe = (n) => {
|
|
|
2450
2500
|
}
|
|
2451
2501
|
return t.join(`
|
|
2452
2502
|
`);
|
|
2453
|
-
},
|
|
2503
|
+
}, bt = (n) => {
|
|
2454
2504
|
const e = [];
|
|
2455
2505
|
if (!n || typeof n != "object") return { value: n, issues: e };
|
|
2456
2506
|
const r = n.blocks;
|
|
@@ -2459,20 +2509,20 @@ const Ve = ([n, e, r]) => n >> 3 << 11 | e >> 2 << 5 | r >> 3, Xe = (n) => {
|
|
|
2459
2509
|
if (!o || typeof o != "object") return o;
|
|
2460
2510
|
const s = o;
|
|
2461
2511
|
if (Array.isArray(s.children))
|
|
2462
|
-
return { ...s, children: s.children.map((
|
|
2512
|
+
return { ...s, children: s.children.map((d, m) => t(d, [...a, "children", m])) };
|
|
2463
2513
|
if (s.type !== "sprite" || typeof s.grid != "string") return o;
|
|
2464
|
-
const c = Array.isArray(s.palette) ? s.palette : [], i =
|
|
2514
|
+
const c = Array.isArray(s.palette) ? s.palette : [], i = at(s.grid, c);
|
|
2465
2515
|
if (!i.ok)
|
|
2466
2516
|
return e.push({ path: [...a, "grid"], message: i.error }), o;
|
|
2467
|
-
const { grid: l, ...
|
|
2468
|
-
return { ...
|
|
2517
|
+
const { grid: l, ...u } = s;
|
|
2518
|
+
return { ...u, ...i.sprite };
|
|
2469
2519
|
};
|
|
2470
2520
|
return {
|
|
2471
2521
|
value: { ...n, blocks: r.map((o, a) => t(o, ["blocks", a])) },
|
|
2472
2522
|
issues: e
|
|
2473
2523
|
};
|
|
2474
2524
|
};
|
|
2475
|
-
class
|
|
2525
|
+
class st {
|
|
2476
2526
|
constructor(e) {
|
|
2477
2527
|
this.requests = [], this.config = e;
|
|
2478
2528
|
}
|
|
@@ -2488,9 +2538,9 @@ class nt {
|
|
|
2488
2538
|
return this.requests.length === 0 ? 0 : this.requests[0] + this.config.windowMs;
|
|
2489
2539
|
}
|
|
2490
2540
|
}
|
|
2491
|
-
class
|
|
2541
|
+
class it {
|
|
2492
2542
|
constructor(e = { maxRequests: 10, windowMs: 6e4 }) {
|
|
2493
|
-
this.rateLimiter = new
|
|
2543
|
+
this.rateLimiter = new st(e);
|
|
2494
2544
|
}
|
|
2495
2545
|
async makeRequest(e, r) {
|
|
2496
2546
|
if (!this.rateLimiter.checkLimit()) {
|
|
@@ -2503,32 +2553,33 @@ class ot {
|
|
|
2503
2553
|
return this.rateLimiter.getRemainingRequests();
|
|
2504
2554
|
}
|
|
2505
2555
|
}
|
|
2506
|
-
const
|
|
2556
|
+
const Et = new it({ maxRequests: 10, windowMs: 6e4 });
|
|
2507
2557
|
export {
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2558
|
+
se as A,
|
|
2559
|
+
Xe as D,
|
|
2560
|
+
Ye as G,
|
|
2561
|
+
Qe as I,
|
|
2562
|
+
We as O,
|
|
2563
|
+
G as P,
|
|
2514
2564
|
D as a,
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2565
|
+
ht as b,
|
|
2566
|
+
gt as c,
|
|
2567
|
+
Fe as d,
|
|
2568
|
+
Ve as e,
|
|
2569
|
+
Ke as f,
|
|
2570
|
+
it as g,
|
|
2571
|
+
Et as h,
|
|
2572
|
+
yt as i,
|
|
2573
|
+
ft as j,
|
|
2574
|
+
ae as k,
|
|
2575
|
+
ut as l,
|
|
2576
|
+
at as m,
|
|
2577
|
+
bt as n,
|
|
2578
|
+
wt as o,
|
|
2579
|
+
et as p,
|
|
2580
|
+
tt as q,
|
|
2581
|
+
dt as r,
|
|
2582
|
+
lt as s,
|
|
2583
|
+
mt as t,
|
|
2584
|
+
Ge as u
|
|
2534
2585
|
};
|