@omote/core 0.3.1 → 0.3.25

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.
@@ -1,1099 +1,9 @@
1
1
  import {
2
- __export,
3
2
  __publicField
4
- } from "./chunk-6W7G6WE7.mjs";
5
-
6
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/index.js
7
- var esm_exports = {};
8
- __export(esm_exports, {
9
- InferenceSession: () => InferenceSession2,
10
- TRACE: () => TRACE,
11
- TRACE_FUNC_BEGIN: () => TRACE_FUNC_BEGIN,
12
- TRACE_FUNC_END: () => TRACE_FUNC_END,
13
- Tensor: () => Tensor2,
14
- env: () => env2,
15
- registerBackend: () => registerBackend
16
- });
17
-
18
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/backend-impl.js
19
- var backends = /* @__PURE__ */ new Map();
20
- var backendsSortedByPriority = [];
21
- var registerBackend = (name, backend, priority) => {
22
- if (backend && typeof backend.init === "function" && typeof backend.createInferenceSessionHandler === "function") {
23
- const currentBackend = backends.get(name);
24
- if (currentBackend === void 0) {
25
- backends.set(name, { backend, priority });
26
- } else if (currentBackend.priority > priority) {
27
- return;
28
- } else if (currentBackend.priority === priority) {
29
- if (currentBackend.backend !== backend) {
30
- throw new Error(`cannot register backend "${name}" using priority ${priority}`);
31
- }
32
- }
33
- if (priority >= 0) {
34
- const i = backendsSortedByPriority.indexOf(name);
35
- if (i !== -1) {
36
- backendsSortedByPriority.splice(i, 1);
37
- }
38
- for (let i2 = 0; i2 < backendsSortedByPriority.length; i2++) {
39
- if (backends.get(backendsSortedByPriority[i2]).priority <= priority) {
40
- backendsSortedByPriority.splice(i2, 0, name);
41
- return;
42
- }
43
- }
44
- backendsSortedByPriority.push(name);
45
- }
46
- return;
47
- }
48
- throw new TypeError("not a valid backend");
49
- };
50
- var tryResolveAndInitializeBackend = async (backendName) => {
51
- const backendInfo = backends.get(backendName);
52
- if (!backendInfo) {
53
- return "backend not found.";
54
- }
55
- if (backendInfo.initialized) {
56
- return backendInfo.backend;
57
- } else if (backendInfo.aborted) {
58
- return backendInfo.error;
59
- } else {
60
- const isInitializing = !!backendInfo.initPromise;
61
- try {
62
- if (!isInitializing) {
63
- backendInfo.initPromise = backendInfo.backend.init(backendName);
64
- }
65
- await backendInfo.initPromise;
66
- backendInfo.initialized = true;
67
- return backendInfo.backend;
68
- } catch (e) {
69
- if (!isInitializing) {
70
- backendInfo.error = `${e}`;
71
- backendInfo.aborted = true;
72
- }
73
- return backendInfo.error;
74
- } finally {
75
- delete backendInfo.initPromise;
76
- }
77
- }
78
- };
79
- var resolveBackendAndExecutionProviders = async (options) => {
80
- const eps = options.executionProviders || [];
81
- const backendHints = eps.map((i) => typeof i === "string" ? i : i.name);
82
- const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
83
- let backend;
84
- const errors = [];
85
- const availableBackendNames = /* @__PURE__ */ new Set();
86
- for (const backendName of backendNames) {
87
- const resolveResult = await tryResolveAndInitializeBackend(backendName);
88
- if (typeof resolveResult === "string") {
89
- errors.push({ name: backendName, err: resolveResult });
90
- } else {
91
- if (!backend) {
92
- backend = resolveResult;
93
- }
94
- if (backend === resolveResult) {
95
- availableBackendNames.add(backendName);
96
- }
97
- }
98
- }
99
- if (!backend) {
100
- throw new Error(`no available backend found. ERR: ${errors.map((e) => `[${e.name}] ${e.err}`).join(", ")}`);
101
- }
102
- for (const { name, err } of errors) {
103
- if (backendHints.includes(name)) {
104
- console.warn(`removing requested execution provider "${name}" from session options because it is not available: ${err}`);
105
- }
106
- }
107
- const filteredEps = eps.filter((i) => availableBackendNames.has(typeof i === "string" ? i : i.name));
108
- return [
109
- backend,
110
- new Proxy(options, {
111
- get: (target, prop) => {
112
- if (prop === "executionProviders") {
113
- return filteredEps;
114
- }
115
- return Reflect.get(target, prop);
116
- }
117
- })
118
- ];
119
- };
120
-
121
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/version.js
122
- var version = "1.21.0";
123
-
124
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/env-impl.js
125
- var logLevelValue = "warning";
126
- var env = {
127
- wasm: {},
128
- webgl: {},
129
- webgpu: {},
130
- versions: { common: version },
131
- set logLevel(value) {
132
- if (value === void 0) {
133
- return;
134
- }
135
- if (typeof value !== "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(value) === -1) {
136
- throw new Error(`Unsupported logging level: ${value}`);
137
- }
138
- logLevelValue = value;
139
- },
140
- get logLevel() {
141
- return logLevelValue;
142
- }
143
- };
144
- Object.defineProperty(env, "logLevel", { enumerable: true });
145
-
146
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/env.js
147
- var env2 = env;
148
-
149
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js
150
- var tensorToDataURL = (tensor, options) => {
151
- const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
152
- canvas.width = tensor.dims[3];
153
- canvas.height = tensor.dims[2];
154
- const pixels2DContext = canvas.getContext("2d");
155
- if (pixels2DContext != null) {
156
- let width;
157
- let height;
158
- if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
159
- width = tensor.dims[2];
160
- height = tensor.dims[3];
161
- } else {
162
- width = tensor.dims[3];
163
- height = tensor.dims[2];
164
- }
165
- const inputformat = options?.format !== void 0 ? options.format : "RGB";
166
- const norm = options?.norm;
167
- let normMean;
168
- let normBias;
169
- if (norm === void 0 || norm.mean === void 0) {
170
- normMean = [255, 255, 255, 255];
171
- } else {
172
- if (typeof norm.mean === "number") {
173
- normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
174
- } else {
175
- normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 0];
176
- if (norm.mean[3] !== void 0) {
177
- normMean[3] = norm.mean[3];
178
- }
179
- }
180
- }
181
- if (norm === void 0 || norm.bias === void 0) {
182
- normBias = [0, 0, 0, 0];
183
- } else {
184
- if (typeof norm.bias === "number") {
185
- normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
186
- } else {
187
- normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
188
- if (norm.bias[3] !== void 0) {
189
- normBias[3] = norm.bias[3];
190
- }
191
- }
192
- }
193
- const stride = height * width;
194
- let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
195
- if (inputformat === "RGBA") {
196
- rTensorPointer = 0;
197
- gTensorPointer = stride;
198
- bTensorPointer = stride * 2;
199
- aTensorPointer = stride * 3;
200
- } else if (inputformat === "RGB") {
201
- rTensorPointer = 0;
202
- gTensorPointer = stride;
203
- bTensorPointer = stride * 2;
204
- } else if (inputformat === "RBG") {
205
- rTensorPointer = 0;
206
- bTensorPointer = stride;
207
- gTensorPointer = stride * 2;
208
- }
209
- for (let i = 0; i < height; i++) {
210
- for (let j = 0; j < width; j++) {
211
- const R = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
212
- const G = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
213
- const B = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
214
- const A = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
215
- pixels2DContext.fillStyle = "rgba(" + R + "," + G + "," + B + "," + A + ")";
216
- pixels2DContext.fillRect(j, i, 1, 1);
217
- }
218
- }
219
- if ("toDataURL" in canvas) {
220
- return canvas.toDataURL();
221
- } else {
222
- throw new Error("toDataURL is not supported");
223
- }
224
- } else {
225
- throw new Error("Can not access image data");
226
- }
227
- };
228
- var tensorToImageData = (tensor, options) => {
229
- const pixels2DContext = typeof document !== "undefined" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d");
230
- let image;
231
- if (pixels2DContext != null) {
232
- let width;
233
- let height;
234
- let channels;
235
- if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
236
- width = tensor.dims[2];
237
- height = tensor.dims[1];
238
- channels = tensor.dims[3];
239
- } else {
240
- width = tensor.dims[3];
241
- height = tensor.dims[2];
242
- channels = tensor.dims[1];
243
- }
244
- const inputformat = options !== void 0 ? options.format !== void 0 ? options.format : "RGB" : "RGB";
245
- const norm = options?.norm;
246
- let normMean;
247
- let normBias;
248
- if (norm === void 0 || norm.mean === void 0) {
249
- normMean = [255, 255, 255, 255];
250
- } else {
251
- if (typeof norm.mean === "number") {
252
- normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
253
- } else {
254
- normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 255];
255
- if (norm.mean[3] !== void 0) {
256
- normMean[3] = norm.mean[3];
257
- }
258
- }
259
- }
260
- if (norm === void 0 || norm.bias === void 0) {
261
- normBias = [0, 0, 0, 0];
262
- } else {
263
- if (typeof norm.bias === "number") {
264
- normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
265
- } else {
266
- normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
267
- if (norm.bias[3] !== void 0) {
268
- normBias[3] = norm.bias[3];
269
- }
270
- }
271
- }
272
- const stride = height * width;
273
- if (options !== void 0) {
274
- if (options.format !== void 0 && channels === 4 && options.format !== "RGBA" || channels === 3 && options.format !== "RGB" && options.format !== "BGR") {
275
- throw new Error("Tensor format doesn't match input tensor dims");
276
- }
277
- }
278
- const step = 4;
279
- let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
280
- let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
281
- if (inputformat === "RGBA") {
282
- rTensorPointer = 0;
283
- gTensorPointer = stride;
284
- bTensorPointer = stride * 2;
285
- aTensorPointer = stride * 3;
286
- } else if (inputformat === "RGB") {
287
- rTensorPointer = 0;
288
- gTensorPointer = stride;
289
- bTensorPointer = stride * 2;
290
- } else if (inputformat === "RBG") {
291
- rTensorPointer = 0;
292
- bTensorPointer = stride;
293
- gTensorPointer = stride * 2;
294
- }
295
- image = pixels2DContext.createImageData(width, height);
296
- for (let i = 0; i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) {
297
- image.data[rImagePointer] = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
298
- image.data[gImagePointer] = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
299
- image.data[bImagePointer] = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
300
- image.data[aImagePointer] = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
301
- }
302
- } else {
303
- throw new Error("Can not access image data");
304
- }
305
- return image;
306
- };
307
-
308
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js
309
- var bufferToTensor = (buffer, options) => {
310
- if (buffer === void 0) {
311
- throw new Error("Image buffer must be defined");
312
- }
313
- if (options.height === void 0 || options.width === void 0) {
314
- throw new Error("Image height and width must be defined");
315
- }
316
- if (options.tensorLayout === "NHWC") {
317
- throw new Error("NHWC Tensor layout is not supported yet");
318
- }
319
- const { height, width } = options;
320
- const norm = options.norm ?? { mean: 255, bias: 0 };
321
- let normMean;
322
- let normBias;
323
- if (typeof norm.mean === "number") {
324
- normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
325
- } else {
326
- normMean = [norm.mean[0], norm.mean[1], norm.mean[2], norm.mean[3] ?? 255];
327
- }
328
- if (typeof norm.bias === "number") {
329
- normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
330
- } else {
331
- normBias = [norm.bias[0], norm.bias[1], norm.bias[2], norm.bias[3] ?? 0];
332
- }
333
- const inputformat = options.format !== void 0 ? options.format : "RGBA";
334
- const outputformat = options.tensorFormat !== void 0 ? options.tensorFormat !== void 0 ? options.tensorFormat : "RGB" : "RGB";
335
- const stride = height * width;
336
- const float32Data = outputformat === "RGBA" ? new Float32Array(stride * 4) : new Float32Array(stride * 3);
337
- let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
338
- let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
339
- if (inputformat === "RGB") {
340
- step = 3;
341
- rImagePointer = 0;
342
- gImagePointer = 1;
343
- bImagePointer = 2;
344
- aImagePointer = -1;
345
- }
346
- if (outputformat === "RGBA") {
347
- aTensorPointer = stride * 3;
348
- } else if (outputformat === "RBG") {
349
- rTensorPointer = 0;
350
- bTensorPointer = stride;
351
- gTensorPointer = stride * 2;
352
- } else if (outputformat === "BGR") {
353
- bTensorPointer = 0;
354
- gTensorPointer = stride;
355
- rTensorPointer = stride * 2;
356
- }
357
- for (let i = 0; i < stride; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) {
358
- float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias[0]) / normMean[0];
359
- float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias[1]) / normMean[1];
360
- float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias[2]) / normMean[2];
361
- if (aTensorPointer !== -1 && aImagePointer !== -1) {
362
- float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
363
- }
364
- }
365
- const outputTensor = outputformat === "RGBA" ? new Tensor("float32", float32Data, [1, 4, height, width]) : new Tensor("float32", float32Data, [1, 3, height, width]);
366
- return outputTensor;
367
- };
368
- var tensorFromImage = async (image, options) => {
369
- const isHTMLImageEle = typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement;
370
- const isImageDataEle = typeof ImageData !== "undefined" && image instanceof ImageData;
371
- const isImageBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
372
- const isString = typeof image === "string";
373
- let data;
374
- let bufferToTensorOptions = options ?? {};
375
- const createCanvas = () => {
376
- if (typeof document !== "undefined") {
377
- return document.createElement("canvas");
378
- } else if (typeof OffscreenCanvas !== "undefined") {
379
- return new OffscreenCanvas(1, 1);
380
- } else {
381
- throw new Error("Canvas is not supported");
382
- }
383
- };
384
- const createCanvasContext = (canvas) => {
385
- if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
386
- return canvas.getContext("2d");
387
- } else if (canvas instanceof OffscreenCanvas) {
388
- return canvas.getContext("2d");
389
- } else {
390
- return null;
391
- }
392
- };
393
- if (isHTMLImageEle) {
394
- const canvas = createCanvas();
395
- canvas.width = image.width;
396
- canvas.height = image.height;
397
- const pixels2DContext = createCanvasContext(canvas);
398
- if (pixels2DContext != null) {
399
- let height = image.height;
400
- let width = image.width;
401
- if (options !== void 0 && options.resizedHeight !== void 0 && options.resizedWidth !== void 0) {
402
- height = options.resizedHeight;
403
- width = options.resizedWidth;
404
- }
405
- if (options !== void 0) {
406
- bufferToTensorOptions = options;
407
- if (options.tensorFormat !== void 0) {
408
- throw new Error("Image input config format must be RGBA for HTMLImageElement");
409
- } else {
410
- bufferToTensorOptions.tensorFormat = "RGBA";
411
- }
412
- bufferToTensorOptions.height = height;
413
- bufferToTensorOptions.width = width;
414
- } else {
415
- bufferToTensorOptions.tensorFormat = "RGBA";
416
- bufferToTensorOptions.height = height;
417
- bufferToTensorOptions.width = width;
418
- }
419
- pixels2DContext.drawImage(image, 0, 0);
420
- data = pixels2DContext.getImageData(0, 0, width, height).data;
421
- } else {
422
- throw new Error("Can not access image data");
423
- }
424
- } else if (isImageDataEle) {
425
- let height;
426
- let width;
427
- if (options !== void 0 && options.resizedWidth !== void 0 && options.resizedHeight !== void 0) {
428
- height = options.resizedHeight;
429
- width = options.resizedWidth;
430
- } else {
431
- height = image.height;
432
- width = image.width;
433
- }
434
- if (options !== void 0) {
435
- bufferToTensorOptions = options;
436
- }
437
- bufferToTensorOptions.format = "RGBA";
438
- bufferToTensorOptions.height = height;
439
- bufferToTensorOptions.width = width;
440
- if (options !== void 0) {
441
- const tempCanvas = createCanvas();
442
- tempCanvas.width = width;
443
- tempCanvas.height = height;
444
- const pixels2DContext = createCanvasContext(tempCanvas);
445
- if (pixels2DContext != null) {
446
- pixels2DContext.putImageData(image, 0, 0);
447
- data = pixels2DContext.getImageData(0, 0, width, height).data;
448
- } else {
449
- throw new Error("Can not access image data");
450
- }
451
- } else {
452
- data = image.data;
453
- }
454
- } else if (isImageBitmap) {
455
- if (options === void 0) {
456
- throw new Error("Please provide image config with format for Imagebitmap");
457
- }
458
- const canvas = createCanvas();
459
- canvas.width = image.width;
460
- canvas.height = image.height;
461
- const pixels2DContext = createCanvasContext(canvas);
462
- if (pixels2DContext != null) {
463
- const height = image.height;
464
- const width = image.width;
465
- pixels2DContext.drawImage(image, 0, 0, width, height);
466
- data = pixels2DContext.getImageData(0, 0, width, height).data;
467
- bufferToTensorOptions.height = height;
468
- bufferToTensorOptions.width = width;
469
- return bufferToTensor(data, bufferToTensorOptions);
470
- } else {
471
- throw new Error("Can not access image data");
472
- }
473
- } else if (isString) {
474
- return new Promise((resolve, reject) => {
475
- const canvas = createCanvas();
476
- const context = createCanvasContext(canvas);
477
- if (!image || !context) {
478
- return reject();
479
- }
480
- const newImage = new Image();
481
- newImage.crossOrigin = "Anonymous";
482
- newImage.src = image;
483
- newImage.onload = () => {
484
- canvas.width = newImage.width;
485
- canvas.height = newImage.height;
486
- context.drawImage(newImage, 0, 0, canvas.width, canvas.height);
487
- const img = context.getImageData(0, 0, canvas.width, canvas.height);
488
- bufferToTensorOptions.height = canvas.height;
489
- bufferToTensorOptions.width = canvas.width;
490
- resolve(bufferToTensor(img.data, bufferToTensorOptions));
491
- };
492
- });
493
- } else {
494
- throw new Error("Input data provided is not supported - aborted tensor creation");
495
- }
496
- if (data !== void 0) {
497
- return bufferToTensor(data, bufferToTensorOptions);
498
- } else {
499
- throw new Error("Input data provided is not supported - aborted tensor creation");
500
- }
501
- };
502
- var tensorFromTexture = (texture, options) => {
503
- const { width, height, download, dispose } = options;
504
- const dims = [1, height, width, 4];
505
- return new Tensor({ location: "texture", type: "float32", texture, dims, download, dispose });
506
- };
507
- var tensorFromGpuBuffer = (gpuBuffer, options) => {
508
- const { dataType, dims, download, dispose } = options;
509
- return new Tensor({ location: "gpu-buffer", type: dataType ?? "float32", gpuBuffer, dims, download, dispose });
510
- };
511
- var tensorFromMLTensor = (mlTensor, options) => {
512
- const { dataType, dims, download, dispose } = options;
513
- return new Tensor({ location: "ml-tensor", type: dataType ?? "float32", mlTensor, dims, download, dispose });
514
- };
515
- var tensorFromPinnedBuffer = (type, buffer, dims) => new Tensor({ location: "cpu-pinned", type, data: buffer, dims: dims ?? [buffer.length] });
516
-
517
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js
518
- var NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = /* @__PURE__ */ new Map([
519
- ["float32", Float32Array],
520
- ["uint8", Uint8Array],
521
- ["int8", Int8Array],
522
- ["uint16", Uint16Array],
523
- ["int16", Int16Array],
524
- ["int32", Int32Array],
525
- ["bool", Uint8Array],
526
- ["float64", Float64Array],
527
- ["uint32", Uint32Array],
528
- ["int4", Uint8Array],
529
- ["uint4", Uint8Array]
530
- ]);
531
- var NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = /* @__PURE__ */ new Map([
532
- [Float32Array, "float32"],
533
- [Uint8Array, "uint8"],
534
- [Int8Array, "int8"],
535
- [Uint16Array, "uint16"],
536
- [Int16Array, "int16"],
537
- [Int32Array, "int32"],
538
- [Float64Array, "float64"],
539
- [Uint32Array, "uint32"]
540
- ]);
541
- var isTypedArrayChecked = false;
542
- var checkTypedArray = () => {
543
- if (!isTypedArrayChecked) {
544
- isTypedArrayChecked = true;
545
- const isBigInt64ArrayAvailable = typeof BigInt64Array !== "undefined" && BigInt64Array.from;
546
- const isBigUint64ArrayAvailable = typeof BigUint64Array !== "undefined" && BigUint64Array.from;
547
- const Float16Array2 = globalThis.Float16Array;
548
- const isFloat16ArrayAvailable = typeof Float16Array2 !== "undefined" && Float16Array2.from;
549
- if (isBigInt64ArrayAvailable) {
550
- NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64", BigInt64Array);
551
- NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, "int64");
552
- }
553
- if (isBigUint64ArrayAvailable) {
554
- NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64", BigUint64Array);
555
- NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, "uint64");
556
- }
557
- if (isFloat16ArrayAvailable) {
558
- NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Float16Array2);
559
- NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array2, "float16");
560
- } else {
561
- NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Uint16Array);
562
- }
563
- }
564
- };
565
-
566
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/tensor-utils-impl.js
567
- var calculateSize = (dims) => {
568
- let size = 1;
569
- for (let i = 0; i < dims.length; i++) {
570
- const dim = dims[i];
571
- if (typeof dim !== "number" || !Number.isSafeInteger(dim)) {
572
- throw new TypeError(`dims[${i}] must be an integer, got: ${dim}`);
573
- }
574
- if (dim < 0) {
575
- throw new RangeError(`dims[${i}] must be a non-negative integer, got: ${dim}`);
576
- }
577
- size *= dim;
578
- }
579
- return size;
580
- };
581
- var tensorReshape = (tensor, dims) => {
582
- switch (tensor.location) {
583
- case "cpu":
584
- return new Tensor(tensor.type, tensor.data, dims);
585
- case "cpu-pinned":
586
- return new Tensor({
587
- location: "cpu-pinned",
588
- data: tensor.data,
589
- type: tensor.type,
590
- dims
591
- });
592
- case "texture":
593
- return new Tensor({
594
- location: "texture",
595
- texture: tensor.texture,
596
- type: tensor.type,
597
- dims
598
- });
599
- case "gpu-buffer":
600
- return new Tensor({
601
- location: "gpu-buffer",
602
- gpuBuffer: tensor.gpuBuffer,
603
- type: tensor.type,
604
- dims
605
- });
606
- case "ml-tensor":
607
- return new Tensor({
608
- location: "ml-tensor",
609
- mlTensor: tensor.mlTensor,
610
- type: tensor.type,
611
- dims
612
- });
613
- default:
614
- throw new Error(`tensorReshape: tensor location ${tensor.location} is not supported`);
615
- }
616
- };
617
-
618
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/tensor-impl.js
619
- var Tensor = class {
620
- /**
621
- * implementation.
622
- */
623
- constructor(arg0, arg1, arg2) {
624
- checkTypedArray();
625
- let type;
626
- let dims;
627
- if (typeof arg0 === "object" && "location" in arg0) {
628
- this.dataLocation = arg0.location;
629
- type = arg0.type;
630
- dims = arg0.dims;
631
- switch (arg0.location) {
632
- case "cpu-pinned": {
633
- const expectedTypedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
634
- if (!expectedTypedArrayConstructor) {
635
- throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
636
- }
637
- if (!(arg0.data instanceof expectedTypedArrayConstructor)) {
638
- throw new TypeError(`buffer should be of type ${expectedTypedArrayConstructor.name}`);
639
- }
640
- this.cpuData = arg0.data;
641
- break;
642
- }
643
- case "texture": {
644
- if (type !== "float32") {
645
- throw new TypeError(`unsupported type "${type}" to create tensor from texture`);
646
- }
647
- this.gpuTextureData = arg0.texture;
648
- this.downloader = arg0.download;
649
- this.disposer = arg0.dispose;
650
- break;
651
- }
652
- case "gpu-buffer": {
653
- if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") {
654
- throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
655
- }
656
- this.gpuBufferData = arg0.gpuBuffer;
657
- this.downloader = arg0.download;
658
- this.disposer = arg0.dispose;
659
- break;
660
- }
661
- case "ml-tensor": {
662
- if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint64" && type !== "int8" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") {
663
- throw new TypeError(`unsupported type "${type}" to create tensor from MLTensor`);
664
- }
665
- this.mlTensorData = arg0.mlTensor;
666
- this.downloader = arg0.download;
667
- this.disposer = arg0.dispose;
668
- break;
669
- }
670
- default:
671
- throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
672
- }
673
- } else {
674
- let data;
675
- let maybeDims;
676
- if (typeof arg0 === "string") {
677
- type = arg0;
678
- maybeDims = arg2;
679
- if (arg0 === "string") {
680
- if (!Array.isArray(arg1)) {
681
- throw new TypeError("A string tensor's data must be a string array.");
682
- }
683
- data = arg1;
684
- } else {
685
- const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
686
- if (typedArrayConstructor === void 0) {
687
- throw new TypeError(`Unsupported tensor type: ${arg0}.`);
688
- }
689
- if (Array.isArray(arg1)) {
690
- if (arg0 === "float16" && typedArrayConstructor === Uint16Array || arg0 === "uint4" || arg0 === "int4") {
691
- throw new TypeError(`Creating a ${arg0} tensor from number array is not supported. Please use ${typedArrayConstructor.name} as data.`);
692
- } else if (arg0 === "uint64" || arg0 === "int64") {
693
- data = typedArrayConstructor.from(arg1, BigInt);
694
- } else {
695
- data = typedArrayConstructor.from(arg1);
696
- }
697
- } else if (arg1 instanceof typedArrayConstructor) {
698
- data = arg1;
699
- } else if (arg1 instanceof Uint8ClampedArray) {
700
- if (arg0 === "uint8") {
701
- data = Uint8Array.from(arg1);
702
- } else {
703
- throw new TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);
704
- }
705
- } else if (arg0 === "float16" && arg1 instanceof Uint16Array && typedArrayConstructor !== Uint16Array) {
706
- data = new globalThis.Float16Array(arg1.buffer, arg1.byteOffset, arg1.length);
707
- } else {
708
- throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
709
- }
710
- }
711
- } else {
712
- maybeDims = arg1;
713
- if (Array.isArray(arg0)) {
714
- if (arg0.length === 0) {
715
- throw new TypeError("Tensor type cannot be inferred from an empty array.");
716
- }
717
- const firstElementType = typeof arg0[0];
718
- if (firstElementType === "string") {
719
- type = "string";
720
- data = arg0;
721
- } else if (firstElementType === "boolean") {
722
- type = "bool";
723
- data = Uint8Array.from(arg0);
724
- } else {
725
- throw new TypeError(`Invalid element type of data array: ${firstElementType}.`);
726
- }
727
- } else if (arg0 instanceof Uint8ClampedArray) {
728
- type = "uint8";
729
- data = Uint8Array.from(arg0);
730
- } else {
731
- const mappedType = NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
732
- if (mappedType === void 0) {
733
- throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
734
- }
735
- type = mappedType;
736
- data = arg0;
737
- }
738
- }
739
- if (maybeDims === void 0) {
740
- maybeDims = [data.length];
741
- } else if (!Array.isArray(maybeDims)) {
742
- throw new TypeError("A tensor's dims must be a number array");
743
- }
744
- dims = maybeDims;
745
- this.cpuData = data;
746
- this.dataLocation = "cpu";
747
- }
748
- const size = calculateSize(dims);
749
- if (this.cpuData && size !== this.cpuData.length) {
750
- if ((type === "uint4" || type === "int4") && Math.ceil(size / 2) === this.cpuData.length) {
751
- } else {
752
- throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
753
- }
754
- }
755
- this.type = type;
756
- this.dims = dims;
757
- this.size = size;
758
- }
759
- // #endregion
760
- // #region factory
761
- static async fromImage(image, options) {
762
- return tensorFromImage(image, options);
763
- }
764
- static fromTexture(texture, options) {
765
- return tensorFromTexture(texture, options);
766
- }
767
- static fromGpuBuffer(gpuBuffer, options) {
768
- return tensorFromGpuBuffer(gpuBuffer, options);
769
- }
770
- static fromMLTensor(mlTensor, options) {
771
- return tensorFromMLTensor(mlTensor, options);
772
- }
773
- static fromPinnedBuffer(type, buffer, dims) {
774
- return tensorFromPinnedBuffer(type, buffer, dims);
775
- }
776
- // #endregion
777
- // #region conversions
778
- toDataURL(options) {
779
- return tensorToDataURL(this, options);
780
- }
781
- toImageData(options) {
782
- return tensorToImageData(this, options);
783
- }
784
- // #endregion
785
- // #region properties
786
- get data() {
787
- this.ensureValid();
788
- if (!this.cpuData) {
789
- throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");
790
- }
791
- return this.cpuData;
792
- }
793
- get location() {
794
- return this.dataLocation;
795
- }
796
- get texture() {
797
- this.ensureValid();
798
- if (!this.gpuTextureData) {
799
- throw new Error("The data is not stored as a WebGL texture.");
800
- }
801
- return this.gpuTextureData;
802
- }
803
- get gpuBuffer() {
804
- this.ensureValid();
805
- if (!this.gpuBufferData) {
806
- throw new Error("The data is not stored as a WebGPU buffer.");
807
- }
808
- return this.gpuBufferData;
809
- }
810
- get mlTensor() {
811
- this.ensureValid();
812
- if (!this.mlTensorData) {
813
- throw new Error("The data is not stored as a WebNN MLTensor.");
814
- }
815
- return this.mlTensorData;
816
- }
817
- // #endregion
818
- // #region methods
819
- async getData(releaseData) {
820
- this.ensureValid();
821
- switch (this.dataLocation) {
822
- case "cpu":
823
- case "cpu-pinned":
824
- return this.data;
825
- case "texture":
826
- case "gpu-buffer":
827
- case "ml-tensor": {
828
- if (!this.downloader) {
829
- throw new Error("The current tensor is not created with a specified data downloader.");
830
- }
831
- if (this.isDownloading) {
832
- throw new Error("The current tensor is being downloaded.");
833
- }
834
- try {
835
- this.isDownloading = true;
836
- const data = await this.downloader();
837
- this.downloader = void 0;
838
- this.dataLocation = "cpu";
839
- this.cpuData = data;
840
- if (releaseData && this.disposer) {
841
- this.disposer();
842
- this.disposer = void 0;
843
- }
844
- return data;
845
- } finally {
846
- this.isDownloading = false;
847
- }
848
- }
849
- default:
850
- throw new Error(`cannot get data from location: ${this.dataLocation}`);
851
- }
852
- }
853
- dispose() {
854
- if (this.isDownloading) {
855
- throw new Error("The current tensor is being downloaded.");
856
- }
857
- if (this.disposer) {
858
- this.disposer();
859
- this.disposer = void 0;
860
- }
861
- this.cpuData = void 0;
862
- this.gpuTextureData = void 0;
863
- this.gpuBufferData = void 0;
864
- this.mlTensorData = void 0;
865
- this.downloader = void 0;
866
- this.isDownloading = void 0;
867
- this.dataLocation = "none";
868
- }
869
- // #endregion
870
- // #region tensor utilities
871
- ensureValid() {
872
- if (this.dataLocation === "none") {
873
- throw new Error("The tensor is disposed.");
874
- }
875
- }
876
- reshape(dims) {
877
- this.ensureValid();
878
- if (this.downloader || this.disposer) {
879
- throw new Error("Cannot reshape a tensor that owns GPU resource.");
880
- }
881
- return tensorReshape(this, dims);
882
- }
883
- };
884
-
885
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/tensor.js
886
- var Tensor2 = Tensor;
887
-
888
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/trace.js
889
- var TRACE = (deviceType, label) => {
890
- if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
891
- return;
892
- }
893
- console.timeStamp(`${deviceType}::ORT::${label}`);
894
- };
895
- var TRACE_FUNC = (msg, extraMsg) => {
896
- const stack = new Error().stack?.split(/\r\n|\r|\n/g) || [];
897
- let hasTraceFunc = false;
898
- for (let i = 0; i < stack.length; i++) {
899
- if (hasTraceFunc && !stack[i].includes("TRACE_FUNC")) {
900
- let label = `FUNC_${msg}::${stack[i].trim().split(" ")[1]}`;
901
- if (extraMsg) {
902
- label += `::${extraMsg}`;
903
- }
904
- TRACE("CPU", label);
905
- return;
906
- }
907
- if (stack[i].includes("TRACE_FUNC")) {
908
- hasTraceFunc = true;
909
- }
910
- }
911
- };
912
- var TRACE_FUNC_BEGIN = (extraMsg) => {
913
- if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
914
- return;
915
- }
916
- TRACE_FUNC("BEGIN", extraMsg);
917
- };
918
- var TRACE_FUNC_END = (extraMsg) => {
919
- if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
920
- return;
921
- }
922
- TRACE_FUNC("END", extraMsg);
923
- };
924
-
925
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/inference-session-impl.js
926
- var InferenceSession = class _InferenceSession {
927
- constructor(handler) {
928
- this.handler = handler;
929
- }
930
- async run(feeds, arg1, arg2) {
931
- TRACE_FUNC_BEGIN();
932
- const fetches = {};
933
- let options = {};
934
- if (typeof feeds !== "object" || feeds === null || feeds instanceof Tensor2 || Array.isArray(feeds)) {
935
- throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
936
- }
937
- let isFetchesEmpty = true;
938
- if (typeof arg1 === "object") {
939
- if (arg1 === null) {
940
- throw new TypeError("Unexpected argument[1]: cannot be null.");
941
- }
942
- if (arg1 instanceof Tensor2) {
943
- throw new TypeError("'fetches' cannot be a Tensor");
944
- }
945
- if (Array.isArray(arg1)) {
946
- if (arg1.length === 0) {
947
- throw new TypeError("'fetches' cannot be an empty array.");
948
- }
949
- isFetchesEmpty = false;
950
- for (const name of arg1) {
951
- if (typeof name !== "string") {
952
- throw new TypeError("'fetches' must be a string array or an object.");
953
- }
954
- if (this.outputNames.indexOf(name) === -1) {
955
- throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
956
- }
957
- fetches[name] = null;
958
- }
959
- if (typeof arg2 === "object" && arg2 !== null) {
960
- options = arg2;
961
- } else if (typeof arg2 !== "undefined") {
962
- throw new TypeError("'options' must be an object.");
963
- }
964
- } else {
965
- let isFetches = false;
966
- const arg1Keys = Object.getOwnPropertyNames(arg1);
967
- for (const name of this.outputNames) {
968
- if (arg1Keys.indexOf(name) !== -1) {
969
- const v = arg1[name];
970
- if (v === null || v instanceof Tensor2) {
971
- isFetches = true;
972
- isFetchesEmpty = false;
973
- fetches[name] = v;
974
- }
975
- }
976
- }
977
- if (isFetches) {
978
- if (typeof arg2 === "object" && arg2 !== null) {
979
- options = arg2;
980
- } else if (typeof arg2 !== "undefined") {
981
- throw new TypeError("'options' must be an object.");
982
- }
983
- } else {
984
- options = arg1;
985
- }
986
- }
987
- } else if (typeof arg1 !== "undefined") {
988
- throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
989
- }
990
- for (const name of this.inputNames) {
991
- if (typeof feeds[name] === "undefined") {
992
- throw new Error(`input '${name}' is missing in 'feeds'.`);
993
- }
994
- }
995
- if (isFetchesEmpty) {
996
- for (const name of this.outputNames) {
997
- fetches[name] = null;
998
- }
999
- }
1000
- const results = await this.handler.run(feeds, fetches, options);
1001
- const returnValue = {};
1002
- for (const key in results) {
1003
- if (Object.hasOwnProperty.call(results, key)) {
1004
- const result = results[key];
1005
- if (result instanceof Tensor2) {
1006
- returnValue[key] = result;
1007
- } else {
1008
- returnValue[key] = new Tensor2(result.type, result.data, result.dims);
1009
- }
1010
- }
1011
- }
1012
- TRACE_FUNC_END();
1013
- return returnValue;
1014
- }
1015
- async release() {
1016
- return this.handler.dispose();
1017
- }
1018
- static async create(arg0, arg1, arg2, arg3) {
1019
- TRACE_FUNC_BEGIN();
1020
- let filePathOrUint8Array;
1021
- let options = {};
1022
- if (typeof arg0 === "string") {
1023
- filePathOrUint8Array = arg0;
1024
- if (typeof arg1 === "object" && arg1 !== null) {
1025
- options = arg1;
1026
- } else if (typeof arg1 !== "undefined") {
1027
- throw new TypeError("'options' must be an object.");
1028
- }
1029
- } else if (arg0 instanceof Uint8Array) {
1030
- filePathOrUint8Array = arg0;
1031
- if (typeof arg1 === "object" && arg1 !== null) {
1032
- options = arg1;
1033
- } else if (typeof arg1 !== "undefined") {
1034
- throw new TypeError("'options' must be an object.");
1035
- }
1036
- } else if (arg0 instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && arg0 instanceof SharedArrayBuffer) {
1037
- const buffer = arg0;
1038
- let byteOffset = 0;
1039
- let byteLength = arg0.byteLength;
1040
- if (typeof arg1 === "object" && arg1 !== null) {
1041
- options = arg1;
1042
- } else if (typeof arg1 === "number") {
1043
- byteOffset = arg1;
1044
- if (!Number.isSafeInteger(byteOffset)) {
1045
- throw new RangeError("'byteOffset' must be an integer.");
1046
- }
1047
- if (byteOffset < 0 || byteOffset >= buffer.byteLength) {
1048
- throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`);
1049
- }
1050
- byteLength = arg0.byteLength - byteOffset;
1051
- if (typeof arg2 === "number") {
1052
- byteLength = arg2;
1053
- if (!Number.isSafeInteger(byteLength)) {
1054
- throw new RangeError("'byteLength' must be an integer.");
1055
- }
1056
- if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) {
1057
- throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`);
1058
- }
1059
- if (typeof arg3 === "object" && arg3 !== null) {
1060
- options = arg3;
1061
- } else if (typeof arg3 !== "undefined") {
1062
- throw new TypeError("'options' must be an object.");
1063
- }
1064
- } else if (typeof arg2 !== "undefined") {
1065
- throw new TypeError("'byteLength' must be a number.");
1066
- }
1067
- } else if (typeof arg1 !== "undefined") {
1068
- throw new TypeError("'options' must be an object.");
1069
- }
1070
- filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength);
1071
- } else {
1072
- throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
1073
- }
1074
- const [backend, optionsWithValidatedEPs] = await resolveBackendAndExecutionProviders(options);
1075
- const handler = await backend.createInferenceSessionHandler(filePathOrUint8Array, optionsWithValidatedEPs);
1076
- TRACE_FUNC_END();
1077
- return new _InferenceSession(handler);
1078
- }
1079
- startProfiling() {
1080
- this.handler.startProfiling();
1081
- }
1082
- endProfiling() {
1083
- this.handler.endProfiling();
1084
- }
1085
- get inputNames() {
1086
- return this.handler.inputNames;
1087
- }
1088
- get outputNames() {
1089
- return this.handler.outputNames;
1090
- }
1091
- };
1092
-
1093
- // node_modules/@huggingface/transformers/node_modules/onnxruntime-common/dist/esm/inference-session.js
1094
- var InferenceSession2 = InferenceSession;
3
+ } from "./chunk-NSSMTXJJ.mjs";
1095
4
 
1096
5
  // node_modules/@huggingface/transformers/dist/transformers.web.js
6
+ import * as __WEBPACK_EXTERNAL_MODULE_onnxruntime_common_82b39e9f__ from "onnxruntime-common";
1097
7
  import * as __WEBPACK_EXTERNAL_MODULE_onnxruntime_web_74d14b94__ from "onnxruntime-web";
1098
8
  var __webpack_modules__ = {
1099
9
  /***/
@@ -1103,7 +13,7 @@ var __webpack_modules__ = {
1103
13
  \*************************************/
1104
14
  /***/
1105
15
  ((module) => {
1106
- module.exports = esm_exports;
16
+ module.exports = __WEBPACK_EXTERNAL_MODULE_onnxruntime_common_82b39e9f__;
1107
17
  })
1108
18
  ),
1109
19
  /***/
@@ -2828,18 +1738,18 @@ var __webpack_modules__ = {
2828
1738
  }
2829
1739
  }
2830
1740
  };
2831
- function setupGlobals(env3) {
2832
- env3.set("false", false);
2833
- env3.set("true", true);
2834
- env3.set("none", null);
2835
- env3.set("raise_exception", (args) => {
1741
+ function setupGlobals(env) {
1742
+ env.set("false", false);
1743
+ env.set("true", true);
1744
+ env.set("none", null);
1745
+ env.set("raise_exception", (args) => {
2836
1746
  throw new Error(args);
2837
1747
  });
2838
- env3.set("range", range);
2839
- env3.set("strftime_now", strftime_now);
2840
- env3.set("True", true);
2841
- env3.set("False", false);
2842
- env3.set("None", null);
1748
+ env.set("range", range);
1749
+ env.set("strftime_now", strftime_now);
1750
+ env.set("True", true);
1751
+ env.set("False", false);
1752
+ env.set("None", null);
2843
1753
  }
2844
1754
  function getAttributeValue(item, attributePath) {
2845
1755
  const parts = attributePath.split(".");
@@ -2903,9 +1813,9 @@ var __webpack_modules__ = {
2903
1813
  }
2904
1814
  }
2905
1815
  var Interpreter = class {
2906
- constructor(env3) {
1816
+ constructor(env) {
2907
1817
  __publicField(this, "global");
2908
- this.global = env3 ?? new Environment();
1818
+ this.global = env ?? new Environment();
2909
1819
  }
2910
1820
  /**
2911
1821
  * Run the program.
@@ -4003,14 +2913,14 @@ var __webpack_modules__ = {
4003
2913
  this.parsed = parse(tokens);
4004
2914
  }
4005
2915
  render(items) {
4006
- const env3 = new Environment();
4007
- setupGlobals(env3);
2916
+ const env = new Environment();
2917
+ setupGlobals(env);
4008
2918
  if (items) {
4009
2919
  for (const [key, value] of Object.entries(items)) {
4010
- env3.set(key, value);
2920
+ env.set(key, value);
4011
2921
  }
4012
2922
  }
4013
- const interpreter = new Interpreter(env3);
2923
+ const interpreter = new Interpreter(env);
4014
2924
  const result = interpreter.run(this.parsed);
4015
2925
  return result.value;
4016
2926
  }
@@ -4135,7 +3045,7 @@ var __webpack_modules__ = {
4135
3045
  supportedDevices.push("wasm");
4136
3046
  defaultDevices = ["wasm"];
4137
3047
  }
4138
- const InferenceSession3 = ONNX.InferenceSession;
3048
+ const InferenceSession = ONNX.InferenceSession;
4139
3049
  function deviceToExecutionProviders(device = null) {
4140
3050
  if (!device) return defaultDevices;
4141
3051
  switch (device) {
@@ -4156,7 +3066,7 @@ var __webpack_modules__ = {
4156
3066
  if (wasmInitPromise) {
4157
3067
  await wasmInitPromise;
4158
3068
  }
4159
- const sessionPromise = InferenceSession3.create(buffer_or_path, session_options);
3069
+ const sessionPromise = InferenceSession.create(buffer_or_path, session_options);
4160
3070
  wasmInitPromise ?? (wasmInitPromise = sessionPromise);
4161
3071
  const session = await sessionPromise;
4162
3072
  session.config = session_config;
@@ -5524,7 +4434,7 @@ var __webpack_modules__ = {
5524
4434
  /* harmony export */
5525
4435
  env: () => (
5526
4436
  /* binding */
5527
- env3
4437
+ env
5528
4438
  )
5529
4439
  /* harmony export */
5530
4440
  });
@@ -5585,7 +4495,7 @@ var __webpack_modules__ = {
5585
4495
  const DEFAULT_CACHE_DIR = RUNNING_LOCALLY ? node_path__WEBPACK_IMPORTED_MODULE_1__.join(dirname__, "/.cache/") : null;
5586
4496
  const DEFAULT_LOCAL_MODEL_PATH = "/models/";
5587
4497
  const localModelPath = RUNNING_LOCALLY ? node_path__WEBPACK_IMPORTED_MODULE_1__.join(dirname__, DEFAULT_LOCAL_MODEL_PATH) : DEFAULT_LOCAL_MODEL_PATH;
5588
- const env3 = {
4498
+ const env = {
5589
4499
  version: VERSION,
5590
4500
  /////////////////// Backends settings ///////////////////
5591
4501
  // NOTE: These will be populated later by the backends themselves.
@@ -29463,9 +28373,9 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
29463
28373
  );
29464
28374
  } else if (typeof process !== "undefined" && process?.release?.name === "node") {
29465
28375
  const IS_CI = !!process.env?.TESTING_REMOTELY;
29466
- const version2 = _env_js__WEBPACK_IMPORTED_MODULE_2__.env.version;
28376
+ const version = _env_js__WEBPACK_IMPORTED_MODULE_2__.env.version;
29467
28377
  const headers = new Headers();
29468
- headers.set("User-Agent", `transformers.js/${version2}; is_ci/${IS_CI};`);
28378
+ headers.set("User-Agent", `transformers.js/${version}; is_ci/${IS_CI};`);
29469
28379
  const isHFURL = isValidUrl(urlOrPath, ["http:", "https:"], ["huggingface.co", "hf.co"]);
29470
28380
  if (isHFURL) {
29471
28381
  const token = process.env?.HF_TOKEN ?? process.env?.HF_ACCESS_TOKEN;
@@ -31342,7 +30252,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31342
30252
  /* harmony export */
31343
30253
  Tensor: () => (
31344
30254
  /* binding */
31345
- Tensor3
30255
+ Tensor
31346
30256
  ),
31347
30257
  /* harmony export */
31348
30258
  cat: () => (
@@ -31488,7 +30398,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31488
30398
  uint4: Uint8Array,
31489
30399
  int4: Int8Array
31490
30400
  });
31491
- class Tensor3 {
30401
+ class Tensor {
31492
30402
  /**
31493
30403
  * Create a new Tensor or copy an existing Tensor.
31494
30404
  * @param {[DataType, DataArray, number[]]|[ONNXTensor]} args
@@ -31577,7 +30487,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31577
30487
  const iterSize = iterDims.reduce((a, b) => a * b);
31578
30488
  return this._subarray(index, iterSize, iterDims);
31579
30489
  } else {
31580
- return new Tensor3(this.type, [this.data[index]], iterDims);
30490
+ return new Tensor(this.type, [this.data[index]], iterDims);
31581
30491
  }
31582
30492
  }
31583
30493
  /**
@@ -31603,7 +30513,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31603
30513
  const o1 = index * iterSize;
31604
30514
  const o2 = (index + 1) * iterSize;
31605
30515
  const data = "subarray" in this.data ? this.data.subarray(o1, o2) : this.data.slice(o1, o2);
31606
- return new Tensor3(this.type, data, iterDims);
30516
+ return new Tensor(this.type, data, iterDims);
31607
30517
  }
31608
30518
  /**
31609
30519
  * Returns the value of this tensor as a standard JavaScript Number. This only works
@@ -31750,7 +30660,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31750
30660
  * @returns {Tensor} A new Tensor with the same type, data, and dimensions as the original.
31751
30661
  */
31752
30662
  clone() {
31753
- return new Tensor3(this.type, this.data.slice(), this.dims.slice());
30663
+ return new Tensor(this.type, this.data.slice(), this.dims.slice());
31754
30664
  }
31755
30665
  /**
31756
30666
  * Performs a slice operation on the Tensor along specified dimensions.
@@ -31845,7 +30755,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31845
30755
  data[i] = this_data[originalIndex];
31846
30756
  }
31847
30757
  }
31848
- return new Tensor3(this.type, data, newTensorDims);
30758
+ return new Tensor(this.type, data, newTensorDims);
31849
30759
  }
31850
30760
  /**
31851
30761
  * Return a permuted version of this Tensor, according to the provided dimensions.
@@ -31887,7 +30797,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31887
30797
  const fn = (a, b) => a + b ** p;
31888
30798
  if (dim === null) {
31889
30799
  const val = this_data.reduce(fn, 0) ** (1 / p);
31890
- return new Tensor3(this.type, [val], []);
30800
+ return new Tensor(this.type, [val], []);
31891
30801
  }
31892
30802
  const [type, result, resultDims] = reduce_helper(fn, this, dim, keepdim);
31893
30803
  if (p !== 1) {
@@ -31895,7 +30805,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31895
30805
  result[i] = result[i] ** (1 / p);
31896
30806
  }
31897
30807
  }
31898
- return new Tensor3(type, result, resultDims);
30808
+ return new Tensor(type, result, resultDims);
31899
30809
  }
31900
30810
  /**
31901
30811
  * Performs `L_p` normalization of inputs over specified dimension. Operates in place.
@@ -31950,7 +30860,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31950
30860
  * @returns {Tensor} The squeezed tensor
31951
30861
  */
31952
30862
  squeeze(dim = null) {
31953
- return new Tensor3(
30863
+ return new Tensor(
31954
30864
  this.type,
31955
30865
  this.data,
31956
30866
  calc_squeeze_dims(this.dims, dim)
@@ -31972,7 +30882,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
31972
30882
  * @returns {Tensor} The unsqueezed tensor
31973
30883
  */
31974
30884
  unsqueeze(dim = null) {
31975
- return new Tensor3(
30885
+ return new Tensor(
31976
30886
  this.type,
31977
30887
  this.data,
31978
30888
  calc_unsqueeze_dims(this.dims, dim)
@@ -32029,7 +30939,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32029
30939
  }, 1);
32030
30940
  dims[inferredIndex] = this_data.length / productOther;
32031
30941
  }
32032
- return new Tensor3(this.type, this_data, dims);
30942
+ return new Tensor(this.type, this_data, dims);
32033
30943
  }
32034
30944
  neg_() {
32035
30945
  const this_data = this.data;
@@ -32052,7 +30962,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32052
30962
  for (let i = 0; i < this_data.length; ++i) {
32053
30963
  mask[i] = this_data[i] > val ? 1 : 0;
32054
30964
  }
32055
- return new Tensor3("bool", mask, this.dims);
30965
+ return new Tensor("bool", mask, this.dims);
32056
30966
  }
32057
30967
  /**
32058
30968
  * Computes input < val element-wise.
@@ -32065,7 +30975,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32065
30975
  for (let i = 0; i < this_data.length; ++i) {
32066
30976
  mask[i] = this_data[i] < val ? 1 : 0;
32067
30977
  }
32068
- return new Tensor3("bool", mask, this.dims);
30978
+ return new Tensor("bool", mask, this.dims);
32069
30979
  }
32070
30980
  /**
32071
30981
  * In-place version of @see {@link Tensor.clamp}
@@ -32109,36 +31019,36 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32109
31019
  min(dim = null, keepdim = false) {
32110
31020
  if (dim === null) {
32111
31021
  const val = (0, _maths_js__WEBPACK_IMPORTED_MODULE_0__.min)(this.data)[0];
32112
- return new Tensor3(this.type, [val], [
31022
+ return new Tensor(this.type, [val], [
32113
31023
  /* scalar */
32114
31024
  ]);
32115
31025
  }
32116
31026
  const [type, result, resultDims] = reduce_helper((a, b) => Math.min(a, b), this, dim, keepdim, Infinity);
32117
- return new Tensor3(type, result, resultDims);
31027
+ return new Tensor(type, result, resultDims);
32118
31028
  }
32119
31029
  max(dim = null, keepdim = false) {
32120
31030
  if (dim === null) {
32121
31031
  const val = (0, _maths_js__WEBPACK_IMPORTED_MODULE_0__.max)(this.data)[0];
32122
- return new Tensor3(this.type, [val], [
31032
+ return new Tensor(this.type, [val], [
32123
31033
  /* scalar */
32124
31034
  ]);
32125
31035
  }
32126
31036
  const [type, result, resultDims] = reduce_helper((a, b) => Math.max(a, b), this, dim, keepdim, -Infinity);
32127
- return new Tensor3(type, result, resultDims);
31037
+ return new Tensor(type, result, resultDims);
32128
31038
  }
32129
31039
  argmin(dim = null, keepdim = false) {
32130
31040
  if (dim !== null) {
32131
31041
  throw new Error("`dim !== null` not yet implemented.");
32132
31042
  }
32133
31043
  const index = (0, _maths_js__WEBPACK_IMPORTED_MODULE_0__.min)(this.data)[1];
32134
- return new Tensor3("int64", [BigInt(index)], []);
31044
+ return new Tensor("int64", [BigInt(index)], []);
32135
31045
  }
32136
31046
  argmax(dim = null, keepdim = false) {
32137
31047
  if (dim !== null) {
32138
31048
  throw new Error("`dim !== null` not yet implemented.");
32139
31049
  }
32140
31050
  const index = (0, _maths_js__WEBPACK_IMPORTED_MODULE_0__.max)(this.data)[1];
32141
- return new Tensor3("int64", [BigInt(index)], []);
31051
+ return new Tensor("int64", [BigInt(index)], []);
32142
31052
  }
32143
31053
  /**
32144
31054
  * Performs Tensor dtype conversion.
@@ -32162,7 +31072,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32162
31072
  map_fn = BigInt;
32163
31073
  }
32164
31074
  }
32165
- return new Tensor3(type, DataTypeMap[type].from(this.data, map_fn), this.dims);
31075
+ return new Tensor(type, DataTypeMap[type].from(this.data, map_fn), this.dims);
32166
31076
  }
32167
31077
  }
32168
31078
  function reshape(data, dimensions) {
@@ -32187,7 +31097,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32187
31097
  }
32188
31098
  function permute(tensor, axes) {
32189
31099
  const [permutedData, shape] = (0, _maths_js__WEBPACK_IMPORTED_MODULE_0__.permute_data)(tensor.data, tensor.dims, axes);
32190
- return new Tensor3(tensor.type, permutedData, shape);
31100
+ return new Tensor(tensor.type, permutedData, shape);
32191
31101
  }
32192
31102
  function interpolate(input, [out_height, out_width], mode = "bilinear", align_corners = false) {
32193
31103
  const in_channels = input.dims.at(-3) ?? 1;
@@ -32201,7 +31111,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32201
31111
  mode,
32202
31112
  align_corners
32203
31113
  );
32204
- return new Tensor3(input.type, output, [in_channels, out_height, out_width]);
31114
+ return new Tensor(input.type, output, [in_channels, out_height, out_width]);
32205
31115
  }
32206
31116
  async function interpolate_4d(input, {
32207
31117
  size = null,
@@ -32233,7 +31143,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32233
31143
  } else {
32234
31144
  throw new Error(`Unsupported mode: ${mode}`);
32235
31145
  }
32236
- const sizeTensor = new Tensor3("int64", new BigInt64Array(targetDims.map(BigInt)), [targetDims.length]);
31146
+ const sizeTensor = new Tensor("int64", new BigInt64Array(targetDims.map(BigInt)), [targetDims.length]);
32237
31147
  return await op({ x: input, s: sizeTensor });
32238
31148
  }
32239
31149
  async function matmul(a, b) {
@@ -32253,14 +31163,14 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32253
31163
  }
32254
31164
  return await op({
32255
31165
  x,
32256
- k: new Tensor3(
31166
+ k: new Tensor(
32257
31167
  "int64",
32258
31168
  [BigInt(k)],
32259
31169
  [1]
32260
31170
  )
32261
31171
  });
32262
31172
  }
32263
- const arrayToIndexTensor = (array) => new Tensor3("int64", array, [array.length]);
31173
+ const arrayToIndexTensor = (array) => new Tensor("int64", array, [array.length]);
32264
31174
  async function slice(data, starts, ends, axes, steps) {
32265
31175
  const op = await _ops_registry_js__WEBPACK_IMPORTED_MODULE_2__.TensorOpRegistry.slice;
32266
31176
  return await op({
@@ -32294,7 +31204,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32294
31204
  returnedData[outIndex++] = avg;
32295
31205
  }
32296
31206
  }
32297
- return new Tensor3(
31207
+ return new Tensor(
32298
31208
  last_hidden_state.type,
32299
31209
  returnedData,
32300
31210
  shape
@@ -32331,7 +31241,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32331
31241
  returnedData[offset2] = (inputData[offset2] - meanData[i]) / (stdData[i] + eps);
32332
31242
  }
32333
31243
  }
32334
- return new Tensor3(input.type, returnedData, input.dims);
31244
+ return new Tensor(input.type, returnedData, input.dims);
32335
31245
  }
32336
31246
  function calc_squeeze_dims(dims, dim) {
32337
31247
  dims = dims.slice();
@@ -32402,7 +31312,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32402
31312
  currentDim += dims[dim];
32403
31313
  }
32404
31314
  }
32405
- return new Tensor3(resultType, result, resultDims);
31315
+ return new Tensor(resultType, result, resultDims);
32406
31316
  }
32407
31317
  function stack(tensors, dim = 0) {
32408
31318
  return cat(tensors.map((t) => t.unsqueeze(dim)), dim);
@@ -32443,10 +31353,10 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32443
31353
  const sum = inputData.reduce((a, b) => a + b, 0);
32444
31354
  const mean2 = sum / inputData.length;
32445
31355
  const std = Math.sqrt(inputData.reduce((a, b) => a + (b - mean2) ** 2, 0) / (inputData.length - correction));
32446
- const meanTensor2 = new Tensor3(input.type, [mean2], [
31356
+ const meanTensor2 = new Tensor(input.type, [mean2], [
32447
31357
  /* scalar */
32448
31358
  ]);
32449
- const stdTensor2 = new Tensor3(input.type, [std], [
31359
+ const stdTensor2 = new Tensor(input.type, [std], [
32450
31360
  /* scalar */
32451
31361
  ]);
32452
31362
  return [stdTensor2, meanTensor2];
@@ -32458,7 +31368,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32458
31368
  for (let i = 0; i < result.length; ++i) {
32459
31369
  result[i] = Math.sqrt(result[i] / (inputDims[dim] - correction));
32460
31370
  }
32461
- const stdTensor = new Tensor3(type, result, resultDims);
31371
+ const stdTensor = new Tensor(type, result, resultDims);
32462
31372
  return [stdTensor, meanTensor];
32463
31373
  }
32464
31374
  function mean(input, dim = null, keepdim = false) {
@@ -32469,7 +31379,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32469
31379
  );
32470
31380
  if (dim === null) {
32471
31381
  const val = inputData.reduce((a, b) => a + b, 0);
32472
- return new Tensor3(input.type, [val / inputData.length], [
31382
+ return new Tensor(input.type, [val / inputData.length], [
32473
31383
  /* scalar */
32474
31384
  ]);
32475
31385
  }
@@ -32480,7 +31390,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32480
31390
  result[i] /= inputDims[dim];
32481
31391
  }
32482
31392
  }
32483
- return new Tensor3(type, result, resultDims);
31393
+ return new Tensor(type, result, resultDims);
32484
31394
  }
32485
31395
  function dimsToStride(dims) {
32486
31396
  const stride = new Array(dims.length);
@@ -32492,7 +31402,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32492
31402
  }
32493
31403
  function fullHelper(size, fill_value, dtype, cls) {
32494
31404
  const numElements = size.reduce((a, b) => a * b, 1);
32495
- return new Tensor3(
31405
+ return new Tensor(
32496
31406
  dtype,
32497
31407
  new cls(numElements).fill(fill_value),
32498
31408
  size
@@ -32532,7 +31442,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32532
31442
  }
32533
31443
  function rand(size) {
32534
31444
  const length = size.reduce((a, b) => a * b, 1);
32535
- return new Tensor3(
31445
+ return new Tensor(
32536
31446
  "float32",
32537
31447
  Float32Array.from({ length }, () => Math.random()),
32538
31448
  size
@@ -32545,7 +31455,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32545
31455
  const v = 1 - Math.random();
32546
31456
  return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
32547
31457
  }
32548
- return new Tensor3(
31458
+ return new Tensor(
32549
31459
  "float32",
32550
31460
  Float32Array.from({ length }, () => boxMullerRandom()),
32551
31461
  size
@@ -32576,7 +31486,7 @@ ${fake_token_around_image}${global_img_token}` + image_token.repeat(image_seq_le
32576
31486
  }
32577
31487
  }
32578
31488
  ;
32579
- return new Tensor3(dtype, outputData, [tensor.dims[0], tensor.dims[1] / 8]);
31489
+ return new Tensor(dtype, outputData, [tensor.dims[0], tensor.dims[1] / 8]);
32580
31490
  }
32581
31491
  })
32582
31492
  ),
@@ -38866,4 +37776,4 @@ export {
38866
37776
  !*** ./src/transformers.js ***!
38867
37777
  \*****************************)
38868
37778
  */
38869
- //# sourceMappingURL=chunk-T465MTDX.mjs.map
37779
+ //# sourceMappingURL=chunk-B6TIE56N.mjs.map