@flaxia/node 0.6.1 → 0.7.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.
Files changed (37) hide show
  1. package/README.md +2 -0
  2. package/dist/assets/ai-inference.js +83 -183
  3. package/dist/assets/ai-model-registry.js +127 -0
  4. package/dist/assets/cc-extract.js +5166 -0
  5. package/dist/assets/decision.js +142 -0
  6. package/dist/assets/embed-gemma.js +97 -0
  7. package/dist/assets/transformers.web.js +2 -2
  8. package/dist/assets/vector-embed.js +136 -26
  9. package/dist/assets/webgpuProbe.js +83 -66
  10. package/dist/client/SignalingClient.d.ts.map +1 -1
  11. package/dist/client/light-preloader.d.ts +6 -1
  12. package/dist/client/light-preloader.d.ts.map +1 -1
  13. package/dist/consent/notice.d.ts +3 -1
  14. package/dist/consent/notice.d.ts.map +1 -1
  15. package/dist/executor/WorkerPool.d.ts +1 -0
  16. package/dist/executor/WorkerPool.d.ts.map +1 -1
  17. package/dist/index.js +371 -364
  18. package/dist/worker.js +129 -120
  19. package/dist/workloads/__tests__/cc-extract.test.d.ts +2 -0
  20. package/dist/workloads/__tests__/cc-extract.test.d.ts.map +1 -0
  21. package/dist/workloads/__tests__/decision.test.d.ts +2 -0
  22. package/dist/workloads/__tests__/decision.test.d.ts.map +1 -0
  23. package/dist/workloads/__tests__/embed-gemma.test.d.ts +2 -0
  24. package/dist/workloads/__tests__/embed-gemma.test.d.ts.map +1 -0
  25. package/dist/workloads/__tests__/wasm-threads.test.d.ts.map +1 -1
  26. package/dist/workloads/ai-inference.d.ts +21 -2
  27. package/dist/workloads/ai-inference.d.ts.map +1 -1
  28. package/dist/workloads/ai-model-registry.d.ts.map +1 -1
  29. package/dist/workloads/cc-extract.d.ts +11 -0
  30. package/dist/workloads/cc-extract.d.ts.map +1 -0
  31. package/dist/workloads/decision.d.ts +21 -0
  32. package/dist/workloads/decision.d.ts.map +1 -0
  33. package/dist/workloads/embed-gemma.d.ts +8 -0
  34. package/dist/workloads/embed-gemma.d.ts.map +1 -0
  35. package/dist/workloads/vector-embed.d.ts +10 -0
  36. package/dist/workloads/vector-embed.d.ts.map +1 -1
  37. package/package.json +4 -3
package/README.md CHANGED
@@ -170,6 +170,8 @@ initFlaxiaNode({ /* ... */ })
170
170
  | `image-process` | `workloads/image-process.ts` | OffscreenCanvas API |
171
171
  | `container` | `workloads/container.ts` | container2wasm + WASI |
172
172
  | `nudenet` | `workloads/nudenet.ts` | NSFW(成人向け)画像判定 |
173
+ | `cc-extract` | `workloads/cc-extract.ts` | Common Crawl WARC の range 取得 + parse5 本文抽出 |
174
+ | `embed-gemma` | `workloads/embed-gemma.ts` | EmbeddingGemma 2(text-only, MRL) |
173
175
 
174
176
  ## フロー
175
177
 
@@ -1,122 +1,8 @@
1
1
  import { t as e } from "./chunk.js";
2
- import { E as t, x as n } from "./webgpuProbe.js";
2
+ import { L as t, y as n } from "./webgpuProbe.js";
3
3
  import { n as r, r as i, t as a } from "./transformers.web.js";
4
- //#region src/workloads/ai-model-registry.ts
5
- var o = 512 * 1024 * 1024, s = 4 * 1024 ** 3, c = new Map(Object.entries({
6
- "Xenova/bert-base-multilingual-uncased-sentiment": {
7
- repo: "Xenova/bert-base-multilingual-uncased-sentiment",
8
- revision: "main",
9
- maxBytes: o
10
- },
11
- "onnx-community/Qwen3-Embedding-0.6B-ONNX": {
12
- repo: "onnx-community/Qwen3-Embedding-0.6B-ONNX",
13
- revision: "main",
14
- maxBytes: o
15
- },
16
- "Xenova/m2m100_418M": {
17
- repo: "Xenova/m2m100_418M",
18
- revision: "main",
19
- maxBytes: o
20
- },
21
- "TeamFlaxia/plamo-3-translate-0.8b-onnx": {
22
- repo: "TeamFlaxia/plamo-3-translate-0.8b-onnx",
23
- revision: "1c8417ee1a72442440ad515b02f99186c81fd08a",
24
- maxBytes: 2 * 1024 ** 3
25
- }
26
- }).map(([e, t]) => [e, { ...t }])), l = [
27
- "wasm",
28
- "cpu",
29
- "webgpu"
30
- ], u = [
31
- "q4",
32
- "q4f16",
33
- "q8",
34
- "int8",
35
- "uint8"
36
- ], d = {
37
- max_new_tokens: {
38
- min: 1,
39
- max: 1024
40
- },
41
- temperature: {
42
- min: 0,
43
- max: 4
44
- },
45
- top_p: {
46
- min: 0,
47
- max: 1
48
- },
49
- top_k: {
50
- min: 0,
51
- max: 1e3
52
- },
53
- repetition_penalty: {
54
- min: 0,
55
- max: 4
56
- }
57
- }, f = 1e5;
58
- function p() {
59
- return [...c.keys()];
60
- }
61
- function m(e) {
62
- if (typeof e != "string" || !e) throw Error(`ai-inference: model must be a non-empty string, got ${JSON.stringify(e)}`);
63
- let t = c.get(e);
64
- if (!t) throw Error(`ai-inference: model not allowed: ${e} (allowed: ${p().join(", ") || "none"})`);
65
- return t;
66
- }
67
- function h(e) {
68
- if (e != null) {
69
- if (typeof e != "string" || !l.includes(e)) throw Error(`ai-inference: device not allowed: ${JSON.stringify(e)} (allowed: ${l.join(", ")})`);
70
- return e;
71
- }
72
- }
73
- function g(e) {
74
- if (e != null) {
75
- if (typeof e != "string" || !u.includes(e)) throw Error(`ai-inference: dtype not allowed: ${JSON.stringify(e)} (allowed: ${u.join(", ")})`);
76
- return e;
77
- }
78
- }
79
- function _(e) {
80
- if (e == null) return !1;
81
- if (typeof e != "boolean") throw Error(`ai-inference: option ondeviceOnly must be a boolean, got ${JSON.stringify(e)}`);
82
- return e;
83
- }
84
- function v(e) {
85
- if (typeof e == "string") {
86
- if (e.length > 1e5) throw Error(`ai-inference: input exceeds ${f} characters`);
87
- return e;
88
- }
89
- if (Array.isArray(e)) {
90
- if (e.length === 0 || e.length > 64) throw Error("ai-inference: input array must hold 1..64 items");
91
- for (let t of e) {
92
- if (typeof t != "string") throw Error("ai-inference: input array items must be strings");
93
- if (t.length > 1e5) throw Error(`ai-inference: input exceeds ${f} characters`);
94
- }
95
- return e;
96
- }
97
- throw Error("ai-inference: input must be a string or an array of strings");
98
- }
99
- function y(e, t) {
100
- for (let [n, r] of Object.entries(d)) {
101
- let i = t[n];
102
- if (i != null) {
103
- if (typeof i != "number" || !Number.isFinite(i) || i < r.min || i > r.max) throw Error(`ai-inference: option ${n} must be a number within ${r.min}..${r.max}, got ${JSON.stringify(i)}`);
104
- e[n] = i;
105
- }
106
- }
107
- if (t.do_sample !== void 0) {
108
- if (typeof t.do_sample != "boolean") throw Error("ai-inference: option do_sample must be a boolean");
109
- e.do_sample = t.do_sample;
110
- }
111
- for (let n of ["src_lang", "tgt_lang"]) {
112
- let r = t[n];
113
- if (r != null) {
114
- if (typeof r != "string" || !/^[a-z]{2,3}(_[A-Za-z0-9]{2,8})?$/.test(r)) throw Error(`ai-inference: option ${n} must be a language code like 'en_XX'`);
115
- e[n] = r;
116
- }
117
- }
118
- }
119
- var b = class {
4
+ import { a as o, i as s, n as c, o as l, r as u, s as d, t as f } from "./ai-model-registry.js";
5
+ var p = class {
120
6
  constructor(e = {}) {
121
7
  this.options = e, this.entries = /* @__PURE__ */ new Map();
122
8
  }
@@ -236,7 +122,7 @@ var b = class {
236
122
  return Math.max(1, this.options.ttlMs ?? 18e5);
237
123
  }
238
124
  };
239
- function x(e) {
125
+ function m(e) {
240
126
  return JSON.stringify([
241
127
  e.task,
242
128
  e.modelId,
@@ -248,24 +134,24 @@ function x(e) {
248
134
  }
249
135
  //#endregion
250
136
  //#region src/workloads/ai-inference.ts
251
- var S = /* @__PURE__ */ e({
252
- DEFAULT_AI_MODEL_MAX_BYTES: () => o,
253
- LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE: () => M,
254
- LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL: () => A,
255
- LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK: () => j,
256
- LIGHT_INFERENCE_TRANSLATE_DTYPE: () => k,
257
- LIGHT_INFERENCE_TRANSLATE_MODEL: () => D,
258
- LIGHT_INFERENCE_TRANSLATE_TASK: () => O,
259
- MAX_AI_INPUT_CHARS: () => f,
137
+ var h = /* @__PURE__ */ e({
138
+ DEFAULT_AI_MODEL_MAX_BYTES: () => DEFAULT_AI_MODEL_MAX_BYTES,
139
+ LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE: () => T,
140
+ LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL: () => C,
141
+ LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK: () => w,
142
+ LIGHT_INFERENCE_TRANSLATE_DTYPE: () => S,
143
+ LIGHT_INFERENCE_TRANSLATE_MODEL: () => b,
144
+ LIGHT_INFERENCE_TRANSLATE_TASK: () => x,
145
+ MAX_AI_INPUT_CHARS: () => MAX_AI_INPUT_CHARS,
260
146
  MAX_AI_INPUT_ITEMS: () => 64,
261
147
  MAX_PENDING_TOKEN_CALLBACKS: () => 64,
262
- MAX_PENDING_TOKEN_CHARS: () => T,
263
- getModelCacheSnapshot: () => P,
264
- handleAiInference: () => L,
265
- isAiModelPreloaded: () => E,
266
- preloadAiModel: () => R,
267
- releaseCache: () => N
268
- }), C = [
148
+ MAX_PENDING_TOKEN_CHARS: () => v,
149
+ getModelCacheSnapshot: () => D,
150
+ handleAiInference: () => A,
151
+ isAiModelPreloaded: () => y,
152
+ preloadAiModel: () => j,
153
+ releaseCache: () => E
154
+ }), g = [
269
155
  "text-classification",
270
156
  "token-classification",
271
157
  "question-answering",
@@ -291,9 +177,12 @@ var S = /* @__PURE__ */ e({
291
177
  "depth-estimation",
292
178
  "feature-extraction",
293
179
  "image-feature-extraction"
294
- ], w = new b(), T = 256 * 1024, E = (e) => P().entries.some((t) => t.modelId === e && t.state === "ready"), D = "Xenova/m2m100_418M", O = "translation", k = "q4f16", A = "TeamFlaxia/plamo-3-translate-0.8b-onnx", j = "text-generation", M = "q4f16", N = () => {
295
- w.releaseAll();
296
- }, P = () => w.getSnapshot(), F = (e, t) => {
180
+ ], _ = new p(), v = 256 * 1024, y = (e) => {
181
+ let t = D();
182
+ return typeof e == "string" ? t.entries.some((t) => t.modelId === e && t.state === "ready") : t.entries.some((t) => t.modelId === e.modelId && t.revision === e.revision && t.dtype === e.dtype && t.backend === e.backend && t.state === "ready");
183
+ }, b = "Xenova/m2m100_418M", x = "translation", S = "q4f16", C = "TeamFlaxia/plamo-3-translate-0.8b-onnx", w = "text-generation", T = "q4f16", E = () => {
184
+ _.releaseAll();
185
+ }, D = () => _.getSnapshot(), O = (e, t) => {
297
186
  let n = "", r = null, i = Promise.resolve(), a = 0, o = 0, s, c = !1, l = !1, u = (t) => {
298
187
  if (a >= 64 || o + t.length > 262144) throw c = !0, s = /* @__PURE__ */ Error("ai-inference token consumer is too slow; generation stopped at the bounded stream buffer"), s;
299
188
  a++, o += t.length, i = i.then(() => {
@@ -332,95 +221,106 @@ var S = /* @__PURE__ */ e({
332
221
  cancel: () => p(!1)
333
222
  };
334
223
  };
335
- function I() {
224
+ function k() {
336
225
  let e = globalThis.fetch.bind(globalThis);
337
226
  r.fetch = async (t, n) => {
338
227
  let r = new URL(String(t));
339
228
  if (!/(^|\.)huggingface\.co$/.test(r.hostname) && !/(^|\.)hf\.co$/.test(r.hostname)) throw Error(`ai-inference: model download blocked from ${r.hostname}`);
340
229
  let i = await e(r, n), a = Number(i.headers.get("content-length"));
341
- if (Number.isFinite(a) && a > s) throw Error(`ai-inference: model file too large (${a} bytes > ${s})`);
230
+ if (Number.isFinite(a) && a > f) throw Error(`ai-inference: model file too large (${a} bytes > ${f})`);
342
231
  return i;
343
232
  };
344
233
  }
345
- I(), r.backends?.onnx?.wasm && (r.backends.onnx.wasm.numThreads = 1, r.backends.onnx.wasm.proxy = !1);
346
- var L = async (e, n) => {
347
- let { task: r, model: o, input: s, options: c = {} } = e;
348
- if (!C.includes(r)) throw Error(`Invalid or unsupported task: ${r}. Supported tasks are: ${C.join(", ")}`);
349
- let l = m(o), u = h(c.device), d = g(c.dtype), f = _(c.ondeviceOnly), p = v(s), b = {};
350
- if (y(b, c), f && !E(o)) throw new t(`ondeviceOnly: model ${o} is not preloaded on this device`, "preloading");
351
- let S = d ?? "q4f16", T = u ?? "wasm", D = x({
234
+ k(), r.backends?.onnx?.wasm && (r.backends.onnx.wasm.numThreads = 1, r.backends.onnx.wasm.proxy = !1);
235
+ var A = async (e, n) => {
236
+ let { task: r, model: f, input: p, options: h = {} } = e;
237
+ if (e.decision) {
238
+ let { handleDecision: t } = await import("./decision.js");
239
+ return await t(e);
240
+ }
241
+ if (!g.includes(r)) throw Error(`Invalid or unsupported task: ${r}. Supported tasks are: ${g.join(", ")}`);
242
+ let v = l(f), b = s(h.device), x = o(h.dtype), S = d(h.ondeviceOnly), C = u(p), w = {};
243
+ c(w, h);
244
+ let T = x ?? "q4f16", E = b ?? "wasm";
245
+ if (S && !y({
246
+ modelId: f,
247
+ revision: v.revision,
248
+ dtype: T,
249
+ backend: E
250
+ })) throw new t(`ondeviceOnly: model ${f} is not preloaded on this device`, "preloading");
251
+ let D = m({
352
252
  task: r,
353
- modelId: o,
354
- revision: l.revision,
355
- dtype: S,
356
- backend: T
357
- }), O = performance.now(), k = await w.acquire(D, {
358
- modelId: o,
359
- revision: l.revision,
360
- dtype: S,
361
- backend: T
253
+ modelId: f,
254
+ revision: v.revision,
255
+ dtype: T,
256
+ backend: E
257
+ }), k = performance.now(), A = await _.acquire(D, {
258
+ modelId: f,
259
+ revision: v.revision,
260
+ dtype: T,
261
+ backend: E
362
262
  }, async () => {
363
263
  let e = {
364
- dtype: S,
365
- device: u,
366
- revision: l.revision
264
+ dtype: T,
265
+ device: b,
266
+ revision: v.revision
367
267
  };
368
- console.log(`[flaxia-node] ai-inference: loading pipeline task=${r} model=${l.repo} revision=${l.revision} dtype=${e.dtype} device=${u ?? "wasm"}`);
268
+ console.log(`[flaxia-node] ai-inference: loading pipeline task=${r} model=${v.repo} revision=${v.revision} dtype=${e.dtype} device=${b ?? "wasm"}`);
369
269
  let t;
370
270
  try {
371
- t = await i(r, l.repo, e);
271
+ t = await i(r, v.repo, e);
372
272
  } catch (n) {
373
- if (u && u !== "wasm") console.warn(`[AiInference] ${u} failed, falling back to wasm:`, n), e.device = "wasm", t = await i(r, l.repo, e);
374
- else throw console.error(`[flaxia-node] ai-inference: pipeline load FAILED task=${r} model=${l.repo} error=${n instanceof Error ? n.message : String(n)}`), n;
273
+ if (b && b !== "wasm") console.warn(`[AiInference] ${b} failed, falling back to wasm:`, n), e.device = "wasm", t = await i(r, v.repo, e);
274
+ else throw console.error(`[flaxia-node] ai-inference: pipeline load FAILED task=${r} model=${v.repo} error=${n instanceof Error ? n.message : String(n)}`), n;
375
275
  }
376
- return console.log(`[flaxia-node] ai-inference: pipeline ready task=${r} model=${l.repo} loadMs=${Math.round(performance.now() - O)}`), {
276
+ return console.log(`[flaxia-node] ai-inference: pipeline ready task=${r} model=${v.repo} loadMs=${Math.round(performance.now() - k)}`), {
377
277
  value: t,
378
278
  descriptor: { backend: e.device ?? "wasm" }
379
279
  };
380
- }, (e) => e.dispose?.()), A = k.value;
280
+ }, (e) => e.dispose?.()), j = A.value;
381
281
  try {
382
282
  let e = {
383
- max_new_tokens: b.max_new_tokens ?? 128,
384
- do_sample: b.do_sample ?? !1
283
+ max_new_tokens: w.max_new_tokens ?? 128,
284
+ do_sample: w.do_sample ?? !1
385
285
  };
386
- for (let [t, n] of Object.entries(b)) t === "max_new_tokens" || t === "do_sample" || (e[t] = n);
387
- let t = n && A.tokenizer ? F(n, c) : null;
388
- t && (e.streamer = new a(A.tokenizer, {
286
+ for (let [t, n] of Object.entries(w)) t === "max_new_tokens" || t === "do_sample" || (e[t] = n);
287
+ let t = n && j.tokenizer ? O(n, h) : null;
288
+ t && (e.streamer = new a(j.tokenizer, {
389
289
  skip_prompt: !0,
390
290
  skip_special_tokens: !0,
391
291
  callback_function: t.callback
392
292
  }));
393
293
  let i = performance.now(), o;
394
294
  try {
395
- o = await A(p, e);
295
+ o = await j(C, e);
396
296
  } catch (e) {
397
- throw /out of memory|oom|allocation failed|could not allocate/i.test(e instanceof Error ? e.message : String(e)) && k.invalidate(), t && await t.cancel(), e;
297
+ throw /out of memory|oom|allocation failed|could not allocate/i.test(e instanceof Error ? e.message : String(e)) && A.invalidate(), t && await t.cancel(), e;
398
298
  }
399
- return await t?.finish(), console.log(`[flaxia-node] ai-inference: done task=${r} model=${l.repo} execMs=${Math.round(performance.now() - i)} inputLen=${String(p).length}`), { output: o };
299
+ return await t?.finish(), console.log(`[flaxia-node] ai-inference: done task=${r} model=${v.repo} execMs=${Math.round(performance.now() - i)} inputLen=${String(C).length}`), { output: o };
400
300
  } finally {
401
- await k.release();
301
+ await A.release();
402
302
  }
403
- }, R = async (e) => {
404
- let { task: t, model: n } = e, r = m(n), a = h(e.device), o = g(e.dtype) ?? "q4f16", s = a ?? "wasm", c = x({
303
+ }, j = async (e) => {
304
+ let { task: t, model: n } = e, r = l(n), a = s(e.device), c = o(e.dtype) ?? "q4f16", u = a ?? "wasm", d = m({
405
305
  task: t,
406
306
  modelId: n,
407
307
  revision: r.revision,
408
- dtype: o,
409
- backend: s
308
+ dtype: c,
309
+ backend: u
410
310
  });
411
- await (await w.acquire(c, {
311
+ await (await _.acquire(d, {
412
312
  modelId: n,
413
313
  revision: r.revision,
414
- dtype: o,
415
- backend: s
314
+ dtype: c,
315
+ backend: u
416
316
  }, async () => (console.log(`[flaxia-node] ai-inference: preloading task=${t} model=${r.repo}`), {
417
317
  value: await i(t, r.repo, {
418
- dtype: o,
318
+ dtype: c,
419
319
  device: a,
420
320
  revision: r.revision
421
321
  }),
422
- descriptor: { backend: s }
322
+ descriptor: { backend: u }
423
323
  }), (e) => e.dispose?.())).release();
424
324
  };
425
325
  //#endregion
426
- export { D as a, E as c, k as i, R as l, A as n, O as o, j as r, S as s, M as t };
326
+ export { b as a, y as c, S as i, j as l, C as n, x as o, w as r, h as s, T as t };
@@ -0,0 +1,127 @@
1
+ //#region src/workloads/ai-model-registry.ts
2
+ var e = 512 * 1024 * 1024, t = 4 * 1024 ** 3, n = new Map(Object.entries({
3
+ "Xenova/bert-base-multilingual-uncased-sentiment": {
4
+ repo: "Xenova/bert-base-multilingual-uncased-sentiment",
5
+ revision: "main",
6
+ maxBytes: e
7
+ },
8
+ "onnx-community/Qwen3-Embedding-0.6B-ONNX": {
9
+ repo: "onnx-community/Qwen3-Embedding-0.6B-ONNX",
10
+ revision: "main",
11
+ maxBytes: e
12
+ },
13
+ "LiquidAI/d1-omni-600M": {
14
+ repo: "LiquidAI/d1-omni-600M",
15
+ revision: "02b55d7076f15129e59ab3f94783f32c4b088674",
16
+ maxBytes: 3 * 1024 ** 3
17
+ },
18
+ "onnx-community/embeddinggemma-2-ONNX": {
19
+ repo: "onnx-community/embeddinggemma-2-ONNX",
20
+ revision: "main",
21
+ maxBytes: 1024 * 1024 * 1024
22
+ },
23
+ "Xenova/m2m100_418M": {
24
+ repo: "Xenova/m2m100_418M",
25
+ revision: "main",
26
+ maxBytes: e
27
+ },
28
+ "TeamFlaxia/plamo-3-translate-0.8b-onnx": {
29
+ repo: "TeamFlaxia/plamo-3-translate-0.8b-onnx",
30
+ revision: "1c8417ee1a72442440ad515b02f99186c81fd08a",
31
+ maxBytes: 2 * 1024 ** 3
32
+ }
33
+ }).map(([e, t]) => [e, { ...t }])), r = [
34
+ "wasm",
35
+ "cpu",
36
+ "webgpu"
37
+ ], i = [
38
+ "q4",
39
+ "q4f16",
40
+ "q8",
41
+ "int8",
42
+ "uint8"
43
+ ], a = {
44
+ max_new_tokens: {
45
+ min: 1,
46
+ max: 1024
47
+ },
48
+ temperature: {
49
+ min: 0,
50
+ max: 4
51
+ },
52
+ top_p: {
53
+ min: 0,
54
+ max: 1
55
+ },
56
+ top_k: {
57
+ min: 0,
58
+ max: 1e3
59
+ },
60
+ repetition_penalty: {
61
+ min: 0,
62
+ max: 4
63
+ }
64
+ }, o = 1e5;
65
+ function s() {
66
+ return [...n.keys()];
67
+ }
68
+ function c(e) {
69
+ if (typeof e != "string" || !e) throw Error(`ai-inference: model must be a non-empty string, got ${JSON.stringify(e)}`);
70
+ let t = n.get(e);
71
+ if (!t) throw Error(`ai-inference: model not allowed: ${e} (allowed: ${s().join(", ") || "none"})`);
72
+ return t;
73
+ }
74
+ function l(e) {
75
+ if (e != null) {
76
+ if (typeof e != "string" || !r.includes(e)) throw Error(`ai-inference: device not allowed: ${JSON.stringify(e)} (allowed: ${r.join(", ")})`);
77
+ return e;
78
+ }
79
+ }
80
+ function u(e) {
81
+ if (e != null) {
82
+ if (typeof e != "string" || !i.includes(e)) throw Error(`ai-inference: dtype not allowed: ${JSON.stringify(e)} (allowed: ${i.join(", ")})`);
83
+ return e;
84
+ }
85
+ }
86
+ function d(e) {
87
+ if (e == null) return !1;
88
+ if (typeof e != "boolean") throw Error(`ai-inference: option ondeviceOnly must be a boolean, got ${JSON.stringify(e)}`);
89
+ return e;
90
+ }
91
+ function f(e) {
92
+ if (typeof e == "string") {
93
+ if (e.length > 1e5) throw Error(`ai-inference: input exceeds ${o} characters`);
94
+ return e;
95
+ }
96
+ if (Array.isArray(e)) {
97
+ if (e.length === 0 || e.length > 64) throw Error("ai-inference: input array must hold 1..64 items");
98
+ for (let t of e) {
99
+ if (typeof t != "string") throw Error("ai-inference: input array items must be strings");
100
+ if (t.length > 1e5) throw Error(`ai-inference: input exceeds ${o} characters`);
101
+ }
102
+ return e;
103
+ }
104
+ throw Error("ai-inference: input must be a string or an array of strings");
105
+ }
106
+ function p(e, t) {
107
+ for (let [n, r] of Object.entries(a)) {
108
+ let i = t[n];
109
+ if (i != null) {
110
+ if (typeof i != "number" || !Number.isFinite(i) || i < r.min || i > r.max) throw Error(`ai-inference: option ${n} must be a number within ${r.min}..${r.max}, got ${JSON.stringify(i)}`);
111
+ e[n] = i;
112
+ }
113
+ }
114
+ if (t.do_sample !== void 0) {
115
+ if (typeof t.do_sample != "boolean") throw Error("ai-inference: option do_sample must be a boolean");
116
+ e.do_sample = t.do_sample;
117
+ }
118
+ for (let n of ["src_lang", "tgt_lang"]) {
119
+ let r = t[n];
120
+ if (r != null) {
121
+ if (typeof r != "string" || !/^[a-z]{2,3}(_[A-Za-z0-9]{2,8})?$/.test(r)) throw Error(`ai-inference: option ${n} must be a language code like 'en_XX'`);
122
+ e[n] = r;
123
+ }
124
+ }
125
+ }
126
+ //#endregion
127
+ export { u as a, l as i, p as n, c as o, f as r, d as s, t };