@cortexkit/opencode-magic-context 0.42.4 → 0.42.5
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/features/magic-context/dreamer/curate-category-rotation.d.ts +26 -0
- package/dist/features/magic-context/dreamer/curate-category-rotation.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +7 -5
- package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts +1 -0
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-prompts.d.ts +3 -0
- package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +6 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +5 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +11 -0
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/{index-faay035c.js → index-3wbd8sdq.js} +29 -11
- package/dist/{index-bkg2fdj1.js → index-4wwr6cz0.js} +3 -0
- package/dist/index.js +189 -27
- package/dist/{recomp-orchestrator-c4sa354a.js → recomp-orchestrator-k20sfpm2.js} +1 -1
- package/dist/{task-config-ys0arma5.js → task-config-cv8k9y8r.js} +1 -1
- package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
- package/dist/v2/server.js +530 -2471
- package/package.json +1 -1
- package/src/features/magic-context/dreamer/task-registry.ts +10 -0
package/dist/v2/server.js
CHANGED
|
@@ -514,2086 +514,6 @@ var init_logger = __esm(() => {
|
|
|
514
514
|
}
|
|
515
515
|
});
|
|
516
516
|
|
|
517
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/backend-impl.js
|
|
518
|
-
var backends, backendsSortedByPriority, registerBackend = (name, backend, priority) => {
|
|
519
|
-
if (backend && typeof backend.init === "function" && typeof backend.createInferenceSessionHandler === "function") {
|
|
520
|
-
const currentBackend = backends.get(name);
|
|
521
|
-
if (currentBackend === undefined) {
|
|
522
|
-
backends.set(name, { backend, priority });
|
|
523
|
-
} else if (currentBackend.priority > priority) {
|
|
524
|
-
return;
|
|
525
|
-
} else if (currentBackend.priority === priority) {
|
|
526
|
-
if (currentBackend.backend !== backend) {
|
|
527
|
-
throw new Error(`cannot register backend "${name}" using priority ${priority}`);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (priority >= 0) {
|
|
531
|
-
const i = backendsSortedByPriority.indexOf(name);
|
|
532
|
-
if (i !== -1) {
|
|
533
|
-
backendsSortedByPriority.splice(i, 1);
|
|
534
|
-
}
|
|
535
|
-
for (let i = 0;i < backendsSortedByPriority.length; i++) {
|
|
536
|
-
if (backends.get(backendsSortedByPriority[i]).priority <= priority) {
|
|
537
|
-
backendsSortedByPriority.splice(i, 0, name);
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
backendsSortedByPriority.push(name);
|
|
542
|
-
}
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
throw new TypeError("not a valid backend");
|
|
546
|
-
}, tryResolveAndInitializeBackend = async (backendName) => {
|
|
547
|
-
const backendInfo = backends.get(backendName);
|
|
548
|
-
if (!backendInfo) {
|
|
549
|
-
return "backend not found.";
|
|
550
|
-
}
|
|
551
|
-
if (backendInfo.initialized) {
|
|
552
|
-
return backendInfo.backend;
|
|
553
|
-
} else if (backendInfo.aborted) {
|
|
554
|
-
return backendInfo.error;
|
|
555
|
-
} else {
|
|
556
|
-
const isInitializing = !!backendInfo.initPromise;
|
|
557
|
-
try {
|
|
558
|
-
if (!isInitializing) {
|
|
559
|
-
backendInfo.initPromise = backendInfo.backend.init(backendName);
|
|
560
|
-
}
|
|
561
|
-
await backendInfo.initPromise;
|
|
562
|
-
backendInfo.initialized = true;
|
|
563
|
-
return backendInfo.backend;
|
|
564
|
-
} catch (e) {
|
|
565
|
-
if (!isInitializing) {
|
|
566
|
-
backendInfo.error = `${e}`;
|
|
567
|
-
backendInfo.aborted = true;
|
|
568
|
-
}
|
|
569
|
-
return backendInfo.error;
|
|
570
|
-
} finally {
|
|
571
|
-
delete backendInfo.initPromise;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}, resolveBackendAndExecutionProviders = async (options) => {
|
|
575
|
-
const eps = options.executionProviders || [];
|
|
576
|
-
const backendHints = eps.map((i) => typeof i === "string" ? i : i.name);
|
|
577
|
-
const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
|
|
578
|
-
let backend;
|
|
579
|
-
const errors = [];
|
|
580
|
-
const availableBackendNames = new Set;
|
|
581
|
-
for (const backendName of backendNames) {
|
|
582
|
-
const resolveResult = await tryResolveAndInitializeBackend(backendName);
|
|
583
|
-
if (typeof resolveResult === "string") {
|
|
584
|
-
errors.push({ name: backendName, err: resolveResult });
|
|
585
|
-
} else {
|
|
586
|
-
if (!backend) {
|
|
587
|
-
backend = resolveResult;
|
|
588
|
-
}
|
|
589
|
-
if (backend === resolveResult) {
|
|
590
|
-
availableBackendNames.add(backendName);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
if (!backend) {
|
|
595
|
-
throw new Error(`no available backend found. ERR: ${errors.map((e) => `[${e.name}] ${e.err}`).join(", ")}`);
|
|
596
|
-
}
|
|
597
|
-
for (const { name, err } of errors) {
|
|
598
|
-
if (backendHints.includes(name)) {
|
|
599
|
-
console.warn(`removing requested execution provider "${name}" from session options because it is not available: ${err}`);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
const filteredEps = eps.filter((i) => availableBackendNames.has(typeof i === "string" ? i : i.name));
|
|
603
|
-
return [
|
|
604
|
-
backend,
|
|
605
|
-
new Proxy(options, {
|
|
606
|
-
get: (target, prop) => {
|
|
607
|
-
if (prop === "executionProviders") {
|
|
608
|
-
return filteredEps;
|
|
609
|
-
}
|
|
610
|
-
return Reflect.get(target, prop);
|
|
611
|
-
}
|
|
612
|
-
})
|
|
613
|
-
];
|
|
614
|
-
};
|
|
615
|
-
var init_backend_impl = __esm(() => {
|
|
616
|
-
backends = new Map;
|
|
617
|
-
backendsSortedByPriority = [];
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/backend.js
|
|
621
|
-
var init_backend = __esm(() => {
|
|
622
|
-
init_backend_impl();
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/version.js
|
|
626
|
-
var version2 = "1.24.0-dev.20251116-b39e144322";
|
|
627
|
-
|
|
628
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/env-impl.js
|
|
629
|
-
var logLevelValue = "warning", env;
|
|
630
|
-
var init_env_impl = __esm(() => {
|
|
631
|
-
env = {
|
|
632
|
-
wasm: {},
|
|
633
|
-
webgl: {},
|
|
634
|
-
webgpu: {},
|
|
635
|
-
versions: { common: version2 },
|
|
636
|
-
set logLevel(value) {
|
|
637
|
-
if (value === undefined) {
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
if (typeof value !== "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(value) === -1) {
|
|
641
|
-
throw new Error(`Unsupported logging level: ${value}`);
|
|
642
|
-
}
|
|
643
|
-
logLevelValue = value;
|
|
644
|
-
},
|
|
645
|
-
get logLevel() {
|
|
646
|
-
return logLevelValue;
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
Object.defineProperty(env, "logLevel", { enumerable: true });
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/env.js
|
|
653
|
-
var env2;
|
|
654
|
-
var init_env = __esm(() => {
|
|
655
|
-
init_env_impl();
|
|
656
|
-
env2 = env;
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js
|
|
660
|
-
var tensorToDataURL = (tensor, options) => {
|
|
661
|
-
const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
662
|
-
canvas.width = tensor.dims[3];
|
|
663
|
-
canvas.height = tensor.dims[2];
|
|
664
|
-
const pixels2DContext = canvas.getContext("2d");
|
|
665
|
-
if (pixels2DContext != null) {
|
|
666
|
-
let width;
|
|
667
|
-
let height;
|
|
668
|
-
if (options?.tensorLayout !== undefined && options.tensorLayout === "NHWC") {
|
|
669
|
-
width = tensor.dims[2];
|
|
670
|
-
height = tensor.dims[3];
|
|
671
|
-
} else {
|
|
672
|
-
width = tensor.dims[3];
|
|
673
|
-
height = tensor.dims[2];
|
|
674
|
-
}
|
|
675
|
-
const inputformat = options?.format !== undefined ? options.format : "RGB";
|
|
676
|
-
const norm = options?.norm;
|
|
677
|
-
let normMean;
|
|
678
|
-
let normBias;
|
|
679
|
-
if (norm === undefined || norm.mean === undefined) {
|
|
680
|
-
normMean = [255, 255, 255, 255];
|
|
681
|
-
} else {
|
|
682
|
-
if (typeof norm.mean === "number") {
|
|
683
|
-
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
|
684
|
-
} else {
|
|
685
|
-
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 0];
|
|
686
|
-
if (norm.mean[3] !== undefined) {
|
|
687
|
-
normMean[3] = norm.mean[3];
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
if (norm === undefined || norm.bias === undefined) {
|
|
692
|
-
normBias = [0, 0, 0, 0];
|
|
693
|
-
} else {
|
|
694
|
-
if (typeof norm.bias === "number") {
|
|
695
|
-
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
|
696
|
-
} else {
|
|
697
|
-
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
|
|
698
|
-
if (norm.bias[3] !== undefined) {
|
|
699
|
-
normBias[3] = norm.bias[3];
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
const stride = height * width;
|
|
704
|
-
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
705
|
-
if (inputformat === "RGBA") {
|
|
706
|
-
rTensorPointer = 0;
|
|
707
|
-
gTensorPointer = stride;
|
|
708
|
-
bTensorPointer = stride * 2;
|
|
709
|
-
aTensorPointer = stride * 3;
|
|
710
|
-
} else if (inputformat === "RGB") {
|
|
711
|
-
rTensorPointer = 0;
|
|
712
|
-
gTensorPointer = stride;
|
|
713
|
-
bTensorPointer = stride * 2;
|
|
714
|
-
} else if (inputformat === "RBG") {
|
|
715
|
-
rTensorPointer = 0;
|
|
716
|
-
bTensorPointer = stride;
|
|
717
|
-
gTensorPointer = stride * 2;
|
|
718
|
-
}
|
|
719
|
-
for (let i = 0;i < height; i++) {
|
|
720
|
-
for (let j = 0;j < width; j++) {
|
|
721
|
-
const R = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
|
|
722
|
-
const G = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
|
|
723
|
-
const B = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
|
|
724
|
-
const A = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
|
|
725
|
-
pixels2DContext.fillStyle = "rgba(" + R + "," + G + "," + B + "," + A + ")";
|
|
726
|
-
pixels2DContext.fillRect(j, i, 1, 1);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
if ("toDataURL" in canvas) {
|
|
730
|
-
return canvas.toDataURL();
|
|
731
|
-
} else {
|
|
732
|
-
throw new Error("toDataURL is not supported");
|
|
733
|
-
}
|
|
734
|
-
} else {
|
|
735
|
-
throw new Error("Can not access image data");
|
|
736
|
-
}
|
|
737
|
-
}, tensorToImageData = (tensor, options) => {
|
|
738
|
-
const pixels2DContext = typeof document !== "undefined" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d");
|
|
739
|
-
let image;
|
|
740
|
-
if (pixels2DContext != null) {
|
|
741
|
-
let width;
|
|
742
|
-
let height;
|
|
743
|
-
let channels;
|
|
744
|
-
if (options?.tensorLayout !== undefined && options.tensorLayout === "NHWC") {
|
|
745
|
-
width = tensor.dims[2];
|
|
746
|
-
height = tensor.dims[1];
|
|
747
|
-
channels = tensor.dims[3];
|
|
748
|
-
} else {
|
|
749
|
-
width = tensor.dims[3];
|
|
750
|
-
height = tensor.dims[2];
|
|
751
|
-
channels = tensor.dims[1];
|
|
752
|
-
}
|
|
753
|
-
const inputformat = options !== undefined ? options.format !== undefined ? options.format : "RGB" : "RGB";
|
|
754
|
-
const norm = options?.norm;
|
|
755
|
-
let normMean;
|
|
756
|
-
let normBias;
|
|
757
|
-
if (norm === undefined || norm.mean === undefined) {
|
|
758
|
-
normMean = [255, 255, 255, 255];
|
|
759
|
-
} else {
|
|
760
|
-
if (typeof norm.mean === "number") {
|
|
761
|
-
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
|
762
|
-
} else {
|
|
763
|
-
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 255];
|
|
764
|
-
if (norm.mean[3] !== undefined) {
|
|
765
|
-
normMean[3] = norm.mean[3];
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
if (norm === undefined || norm.bias === undefined) {
|
|
770
|
-
normBias = [0, 0, 0, 0];
|
|
771
|
-
} else {
|
|
772
|
-
if (typeof norm.bias === "number") {
|
|
773
|
-
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
|
774
|
-
} else {
|
|
775
|
-
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
|
|
776
|
-
if (norm.bias[3] !== undefined) {
|
|
777
|
-
normBias[3] = norm.bias[3];
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
const stride = height * width;
|
|
782
|
-
if (options !== undefined) {
|
|
783
|
-
if (options.format !== undefined && channels === 4 && options.format !== "RGBA" || channels === 3 && options.format !== "RGB" && options.format !== "BGR") {
|
|
784
|
-
throw new Error("Tensor format doesn't match input tensor dims");
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
const step = 4;
|
|
788
|
-
let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
|
789
|
-
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
790
|
-
if (inputformat === "RGBA") {
|
|
791
|
-
rTensorPointer = 0;
|
|
792
|
-
gTensorPointer = stride;
|
|
793
|
-
bTensorPointer = stride * 2;
|
|
794
|
-
aTensorPointer = stride * 3;
|
|
795
|
-
} else if (inputformat === "RGB") {
|
|
796
|
-
rTensorPointer = 0;
|
|
797
|
-
gTensorPointer = stride;
|
|
798
|
-
bTensorPointer = stride * 2;
|
|
799
|
-
} else if (inputformat === "RBG") {
|
|
800
|
-
rTensorPointer = 0;
|
|
801
|
-
bTensorPointer = stride;
|
|
802
|
-
gTensorPointer = stride * 2;
|
|
803
|
-
}
|
|
804
|
-
image = pixels2DContext.createImageData(width, height);
|
|
805
|
-
for (let i = 0;i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) {
|
|
806
|
-
image.data[rImagePointer] = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
|
|
807
|
-
image.data[gImagePointer] = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
|
|
808
|
-
image.data[bImagePointer] = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
|
|
809
|
-
image.data[aImagePointer] = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
|
|
810
|
-
}
|
|
811
|
-
} else {
|
|
812
|
-
throw new Error("Can not access image data");
|
|
813
|
-
}
|
|
814
|
-
return image;
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js
|
|
818
|
-
var bufferToTensor = (buffer, options) => {
|
|
819
|
-
if (buffer === undefined) {
|
|
820
|
-
throw new Error("Image buffer must be defined");
|
|
821
|
-
}
|
|
822
|
-
if (options.height === undefined || options.width === undefined) {
|
|
823
|
-
throw new Error("Image height and width must be defined");
|
|
824
|
-
}
|
|
825
|
-
if (options.tensorLayout === "NHWC") {
|
|
826
|
-
throw new Error("NHWC Tensor layout is not supported yet");
|
|
827
|
-
}
|
|
828
|
-
const { height, width } = options;
|
|
829
|
-
const norm = options.norm ?? { mean: 255, bias: 0 };
|
|
830
|
-
let normMean;
|
|
831
|
-
let normBias;
|
|
832
|
-
if (typeof norm.mean === "number") {
|
|
833
|
-
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
|
834
|
-
} else {
|
|
835
|
-
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], norm.mean[3] ?? 255];
|
|
836
|
-
}
|
|
837
|
-
if (typeof norm.bias === "number") {
|
|
838
|
-
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
|
839
|
-
} else {
|
|
840
|
-
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], norm.bias[3] ?? 0];
|
|
841
|
-
}
|
|
842
|
-
const inputformat = options.format !== undefined ? options.format : "RGBA";
|
|
843
|
-
const outputformat = options.tensorFormat !== undefined ? options.tensorFormat !== undefined ? options.tensorFormat : "RGB" : "RGB";
|
|
844
|
-
const stride = height * width;
|
|
845
|
-
const float32Data = outputformat === "RGBA" ? new Float32Array(stride * 4) : new Float32Array(stride * 3);
|
|
846
|
-
let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
|
847
|
-
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
848
|
-
if (inputformat === "RGB") {
|
|
849
|
-
step = 3;
|
|
850
|
-
rImagePointer = 0;
|
|
851
|
-
gImagePointer = 1;
|
|
852
|
-
bImagePointer = 2;
|
|
853
|
-
aImagePointer = -1;
|
|
854
|
-
}
|
|
855
|
-
if (outputformat === "RGBA") {
|
|
856
|
-
aTensorPointer = stride * 3;
|
|
857
|
-
} else if (outputformat === "RBG") {
|
|
858
|
-
rTensorPointer = 0;
|
|
859
|
-
bTensorPointer = stride;
|
|
860
|
-
gTensorPointer = stride * 2;
|
|
861
|
-
} else if (outputformat === "BGR") {
|
|
862
|
-
bTensorPointer = 0;
|
|
863
|
-
gTensorPointer = stride;
|
|
864
|
-
rTensorPointer = stride * 2;
|
|
865
|
-
}
|
|
866
|
-
for (let i = 0;i < stride; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) {
|
|
867
|
-
float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias[0]) / normMean[0];
|
|
868
|
-
float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias[1]) / normMean[1];
|
|
869
|
-
float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias[2]) / normMean[2];
|
|
870
|
-
if (aTensorPointer !== -1 && aImagePointer !== -1) {
|
|
871
|
-
float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
const outputTensor = outputformat === "RGBA" ? new Tensor("float32", float32Data, [1, 4, height, width]) : new Tensor("float32", float32Data, [1, 3, height, width]);
|
|
875
|
-
return outputTensor;
|
|
876
|
-
}, tensorFromImage = async (image, options) => {
|
|
877
|
-
const isHTMLImageEle = typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement;
|
|
878
|
-
const isImageDataEle = typeof ImageData !== "undefined" && image instanceof ImageData;
|
|
879
|
-
const isImageBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
|
|
880
|
-
const isString = typeof image === "string";
|
|
881
|
-
let data;
|
|
882
|
-
let bufferToTensorOptions = options ?? {};
|
|
883
|
-
const createCanvas = () => {
|
|
884
|
-
if (typeof document !== "undefined") {
|
|
885
|
-
return document.createElement("canvas");
|
|
886
|
-
} else if (typeof OffscreenCanvas !== "undefined") {
|
|
887
|
-
return new OffscreenCanvas(1, 1);
|
|
888
|
-
} else {
|
|
889
|
-
throw new Error("Canvas is not supported");
|
|
890
|
-
}
|
|
891
|
-
};
|
|
892
|
-
const createCanvasContext = (canvas) => {
|
|
893
|
-
if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
|
|
894
|
-
return canvas.getContext("2d");
|
|
895
|
-
} else if (canvas instanceof OffscreenCanvas) {
|
|
896
|
-
return canvas.getContext("2d");
|
|
897
|
-
} else {
|
|
898
|
-
return null;
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
if (isHTMLImageEle) {
|
|
902
|
-
const canvas = createCanvas();
|
|
903
|
-
canvas.width = image.width;
|
|
904
|
-
canvas.height = image.height;
|
|
905
|
-
const pixels2DContext = createCanvasContext(canvas);
|
|
906
|
-
if (pixels2DContext != null) {
|
|
907
|
-
let height = image.height;
|
|
908
|
-
let width = image.width;
|
|
909
|
-
if (options !== undefined && options.resizedHeight !== undefined && options.resizedWidth !== undefined) {
|
|
910
|
-
height = options.resizedHeight;
|
|
911
|
-
width = options.resizedWidth;
|
|
912
|
-
}
|
|
913
|
-
if (options !== undefined) {
|
|
914
|
-
bufferToTensorOptions = options;
|
|
915
|
-
if (options.tensorFormat !== undefined) {
|
|
916
|
-
throw new Error("Image input config format must be RGBA for HTMLImageElement");
|
|
917
|
-
} else {
|
|
918
|
-
bufferToTensorOptions.tensorFormat = "RGBA";
|
|
919
|
-
}
|
|
920
|
-
bufferToTensorOptions.height = height;
|
|
921
|
-
bufferToTensorOptions.width = width;
|
|
922
|
-
} else {
|
|
923
|
-
bufferToTensorOptions.tensorFormat = "RGBA";
|
|
924
|
-
bufferToTensorOptions.height = height;
|
|
925
|
-
bufferToTensorOptions.width = width;
|
|
926
|
-
}
|
|
927
|
-
pixels2DContext.drawImage(image, 0, 0);
|
|
928
|
-
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
929
|
-
} else {
|
|
930
|
-
throw new Error("Can not access image data");
|
|
931
|
-
}
|
|
932
|
-
} else if (isImageDataEle) {
|
|
933
|
-
let height;
|
|
934
|
-
let width;
|
|
935
|
-
if (options !== undefined && options.resizedWidth !== undefined && options.resizedHeight !== undefined) {
|
|
936
|
-
height = options.resizedHeight;
|
|
937
|
-
width = options.resizedWidth;
|
|
938
|
-
} else {
|
|
939
|
-
height = image.height;
|
|
940
|
-
width = image.width;
|
|
941
|
-
}
|
|
942
|
-
if (options !== undefined) {
|
|
943
|
-
bufferToTensorOptions = options;
|
|
944
|
-
}
|
|
945
|
-
bufferToTensorOptions.format = "RGBA";
|
|
946
|
-
bufferToTensorOptions.height = height;
|
|
947
|
-
bufferToTensorOptions.width = width;
|
|
948
|
-
if (options !== undefined) {
|
|
949
|
-
const tempCanvas = createCanvas();
|
|
950
|
-
tempCanvas.width = width;
|
|
951
|
-
tempCanvas.height = height;
|
|
952
|
-
const pixels2DContext = createCanvasContext(tempCanvas);
|
|
953
|
-
if (pixels2DContext != null) {
|
|
954
|
-
pixels2DContext.putImageData(image, 0, 0);
|
|
955
|
-
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
956
|
-
} else {
|
|
957
|
-
throw new Error("Can not access image data");
|
|
958
|
-
}
|
|
959
|
-
} else {
|
|
960
|
-
data = image.data;
|
|
961
|
-
}
|
|
962
|
-
} else if (isImageBitmap) {
|
|
963
|
-
if (options === undefined) {
|
|
964
|
-
throw new Error("Please provide image config with format for Imagebitmap");
|
|
965
|
-
}
|
|
966
|
-
const canvas = createCanvas();
|
|
967
|
-
canvas.width = image.width;
|
|
968
|
-
canvas.height = image.height;
|
|
969
|
-
const pixels2DContext = createCanvasContext(canvas);
|
|
970
|
-
if (pixels2DContext != null) {
|
|
971
|
-
const height = image.height;
|
|
972
|
-
const width = image.width;
|
|
973
|
-
pixels2DContext.drawImage(image, 0, 0, width, height);
|
|
974
|
-
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
975
|
-
bufferToTensorOptions.height = height;
|
|
976
|
-
bufferToTensorOptions.width = width;
|
|
977
|
-
return bufferToTensor(data, bufferToTensorOptions);
|
|
978
|
-
} else {
|
|
979
|
-
throw new Error("Can not access image data");
|
|
980
|
-
}
|
|
981
|
-
} else if (isString) {
|
|
982
|
-
return new Promise((resolve, reject) => {
|
|
983
|
-
const canvas = createCanvas();
|
|
984
|
-
const context = createCanvasContext(canvas);
|
|
985
|
-
if (!image || !context) {
|
|
986
|
-
return reject();
|
|
987
|
-
}
|
|
988
|
-
const newImage = new Image;
|
|
989
|
-
newImage.crossOrigin = "Anonymous";
|
|
990
|
-
newImage.src = image;
|
|
991
|
-
newImage.onload = () => {
|
|
992
|
-
canvas.width = newImage.width;
|
|
993
|
-
canvas.height = newImage.height;
|
|
994
|
-
context.drawImage(newImage, 0, 0, canvas.width, canvas.height);
|
|
995
|
-
const img = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
996
|
-
bufferToTensorOptions.height = canvas.height;
|
|
997
|
-
bufferToTensorOptions.width = canvas.width;
|
|
998
|
-
resolve(bufferToTensor(img.data, bufferToTensorOptions));
|
|
999
|
-
};
|
|
1000
|
-
});
|
|
1001
|
-
} else {
|
|
1002
|
-
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
1003
|
-
}
|
|
1004
|
-
if (data !== undefined) {
|
|
1005
|
-
return bufferToTensor(data, bufferToTensorOptions);
|
|
1006
|
-
} else {
|
|
1007
|
-
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
1008
|
-
}
|
|
1009
|
-
}, tensorFromTexture = (texture, options) => {
|
|
1010
|
-
const { width, height, download, dispose } = options;
|
|
1011
|
-
const dims = [1, height, width, 4];
|
|
1012
|
-
return new Tensor({ location: "texture", type: "float32", texture, dims, download, dispose });
|
|
1013
|
-
}, tensorFromGpuBuffer = (gpuBuffer, options) => {
|
|
1014
|
-
const { dataType, dims, download, dispose } = options;
|
|
1015
|
-
return new Tensor({ location: "gpu-buffer", type: dataType ?? "float32", gpuBuffer, dims, download, dispose });
|
|
1016
|
-
}, tensorFromMLTensor = (mlTensor, options) => {
|
|
1017
|
-
const { dataType, dims, download, dispose } = options;
|
|
1018
|
-
return new Tensor({ location: "ml-tensor", type: dataType ?? "float32", mlTensor, dims, download, dispose });
|
|
1019
|
-
}, tensorFromPinnedBuffer = (type, buffer, dims) => new Tensor({ location: "cpu-pinned", type, data: buffer, dims: dims ?? [buffer.length] });
|
|
1020
|
-
var init_tensor_factory_impl = __esm(() => {
|
|
1021
|
-
init_tensor_impl();
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js
|
|
1025
|
-
var NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP, NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP, isTypedArrayChecked = false, checkTypedArray = () => {
|
|
1026
|
-
if (!isTypedArrayChecked) {
|
|
1027
|
-
isTypedArrayChecked = true;
|
|
1028
|
-
const isBigInt64ArrayAvailable = typeof BigInt64Array !== "undefined" && BigInt64Array.from;
|
|
1029
|
-
const isBigUint64ArrayAvailable = typeof BigUint64Array !== "undefined" && BigUint64Array.from;
|
|
1030
|
-
const Float16Array2 = globalThis.Float16Array;
|
|
1031
|
-
const isFloat16ArrayAvailable = typeof Float16Array2 !== "undefined" && Float16Array2.from;
|
|
1032
|
-
if (isBigInt64ArrayAvailable) {
|
|
1033
|
-
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64", BigInt64Array);
|
|
1034
|
-
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, "int64");
|
|
1035
|
-
}
|
|
1036
|
-
if (isBigUint64ArrayAvailable) {
|
|
1037
|
-
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64", BigUint64Array);
|
|
1038
|
-
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, "uint64");
|
|
1039
|
-
}
|
|
1040
|
-
if (isFloat16ArrayAvailable) {
|
|
1041
|
-
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Float16Array2);
|
|
1042
|
-
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array2, "float16");
|
|
1043
|
-
} else {
|
|
1044
|
-
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Uint16Array);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
var init_tensor_impl_type_mapping = __esm(() => {
|
|
1049
|
-
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = new Map([
|
|
1050
|
-
["float32", Float32Array],
|
|
1051
|
-
["uint8", Uint8Array],
|
|
1052
|
-
["int8", Int8Array],
|
|
1053
|
-
["uint16", Uint16Array],
|
|
1054
|
-
["int16", Int16Array],
|
|
1055
|
-
["int32", Int32Array],
|
|
1056
|
-
["bool", Uint8Array],
|
|
1057
|
-
["float64", Float64Array],
|
|
1058
|
-
["uint32", Uint32Array],
|
|
1059
|
-
["int4", Uint8Array],
|
|
1060
|
-
["uint4", Uint8Array]
|
|
1061
|
-
]);
|
|
1062
|
-
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = new Map([
|
|
1063
|
-
[Float32Array, "float32"],
|
|
1064
|
-
[Uint8Array, "uint8"],
|
|
1065
|
-
[Int8Array, "int8"],
|
|
1066
|
-
[Uint16Array, "uint16"],
|
|
1067
|
-
[Int16Array, "int16"],
|
|
1068
|
-
[Int32Array, "int32"],
|
|
1069
|
-
[Float64Array, "float64"],
|
|
1070
|
-
[Uint32Array, "uint32"]
|
|
1071
|
-
]);
|
|
1072
|
-
});
|
|
1073
|
-
|
|
1074
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-utils-impl.js
|
|
1075
|
-
var calculateSize = (dims) => {
|
|
1076
|
-
let size = 1;
|
|
1077
|
-
for (let i = 0;i < dims.length; i++) {
|
|
1078
|
-
const dim = dims[i];
|
|
1079
|
-
if (typeof dim !== "number" || !Number.isSafeInteger(dim)) {
|
|
1080
|
-
throw new TypeError(`dims[${i}] must be an integer, got: ${dim}`);
|
|
1081
|
-
}
|
|
1082
|
-
if (dim < 0) {
|
|
1083
|
-
throw new RangeError(`dims[${i}] must be a non-negative integer, got: ${dim}`);
|
|
1084
|
-
}
|
|
1085
|
-
size *= dim;
|
|
1086
|
-
}
|
|
1087
|
-
return size;
|
|
1088
|
-
}, tensorReshape = (tensor, dims) => {
|
|
1089
|
-
switch (tensor.location) {
|
|
1090
|
-
case "cpu":
|
|
1091
|
-
return new Tensor(tensor.type, tensor.data, dims);
|
|
1092
|
-
case "cpu-pinned":
|
|
1093
|
-
return new Tensor({
|
|
1094
|
-
location: "cpu-pinned",
|
|
1095
|
-
data: tensor.data,
|
|
1096
|
-
type: tensor.type,
|
|
1097
|
-
dims
|
|
1098
|
-
});
|
|
1099
|
-
case "texture":
|
|
1100
|
-
return new Tensor({
|
|
1101
|
-
location: "texture",
|
|
1102
|
-
texture: tensor.texture,
|
|
1103
|
-
type: tensor.type,
|
|
1104
|
-
dims
|
|
1105
|
-
});
|
|
1106
|
-
case "gpu-buffer":
|
|
1107
|
-
return new Tensor({
|
|
1108
|
-
location: "gpu-buffer",
|
|
1109
|
-
gpuBuffer: tensor.gpuBuffer,
|
|
1110
|
-
type: tensor.type,
|
|
1111
|
-
dims
|
|
1112
|
-
});
|
|
1113
|
-
case "ml-tensor":
|
|
1114
|
-
return new Tensor({
|
|
1115
|
-
location: "ml-tensor",
|
|
1116
|
-
mlTensor: tensor.mlTensor,
|
|
1117
|
-
type: tensor.type,
|
|
1118
|
-
dims
|
|
1119
|
-
});
|
|
1120
|
-
default:
|
|
1121
|
-
throw new Error(`tensorReshape: tensor location ${tensor.location} is not supported`);
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
var init_tensor_utils_impl = __esm(() => {
|
|
1125
|
-
init_tensor_impl();
|
|
1126
|
-
});
|
|
1127
|
-
|
|
1128
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-impl.js
|
|
1129
|
-
class Tensor {
|
|
1130
|
-
constructor(arg0, arg1, arg2) {
|
|
1131
|
-
checkTypedArray();
|
|
1132
|
-
let type;
|
|
1133
|
-
let dims;
|
|
1134
|
-
if (typeof arg0 === "object" && "location" in arg0) {
|
|
1135
|
-
this.dataLocation = arg0.location;
|
|
1136
|
-
type = arg0.type;
|
|
1137
|
-
dims = arg0.dims;
|
|
1138
|
-
switch (arg0.location) {
|
|
1139
|
-
case "cpu-pinned": {
|
|
1140
|
-
const expectedTypedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
|
|
1141
|
-
if (!expectedTypedArrayConstructor) {
|
|
1142
|
-
throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
|
|
1143
|
-
}
|
|
1144
|
-
if (!(arg0.data instanceof expectedTypedArrayConstructor)) {
|
|
1145
|
-
throw new TypeError(`buffer should be of type ${expectedTypedArrayConstructor.name}`);
|
|
1146
|
-
}
|
|
1147
|
-
this.cpuData = arg0.data;
|
|
1148
|
-
break;
|
|
1149
|
-
}
|
|
1150
|
-
case "texture": {
|
|
1151
|
-
if (type !== "float32") {
|
|
1152
|
-
throw new TypeError(`unsupported type "${type}" to create tensor from texture`);
|
|
1153
|
-
}
|
|
1154
|
-
this.gpuTextureData = arg0.texture;
|
|
1155
|
-
this.downloader = arg0.download;
|
|
1156
|
-
this.disposer = arg0.dispose;
|
|
1157
|
-
break;
|
|
1158
|
-
}
|
|
1159
|
-
case "gpu-buffer": {
|
|
1160
|
-
if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") {
|
|
1161
|
-
throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
|
|
1162
|
-
}
|
|
1163
|
-
this.gpuBufferData = arg0.gpuBuffer;
|
|
1164
|
-
this.downloader = arg0.download;
|
|
1165
|
-
this.disposer = arg0.dispose;
|
|
1166
|
-
break;
|
|
1167
|
-
}
|
|
1168
|
-
case "ml-tensor": {
|
|
1169
|
-
if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint64" && type !== "int8" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") {
|
|
1170
|
-
throw new TypeError(`unsupported type "${type}" to create tensor from MLTensor`);
|
|
1171
|
-
}
|
|
1172
|
-
this.mlTensorData = arg0.mlTensor;
|
|
1173
|
-
this.downloader = arg0.download;
|
|
1174
|
-
this.disposer = arg0.dispose;
|
|
1175
|
-
break;
|
|
1176
|
-
}
|
|
1177
|
-
default:
|
|
1178
|
-
throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
|
|
1179
|
-
}
|
|
1180
|
-
} else {
|
|
1181
|
-
let data;
|
|
1182
|
-
let maybeDims;
|
|
1183
|
-
if (typeof arg0 === "string") {
|
|
1184
|
-
type = arg0;
|
|
1185
|
-
maybeDims = arg2;
|
|
1186
|
-
if (arg0 === "string") {
|
|
1187
|
-
if (!Array.isArray(arg1)) {
|
|
1188
|
-
throw new TypeError("A string tensor's data must be a string array.");
|
|
1189
|
-
}
|
|
1190
|
-
data = arg1;
|
|
1191
|
-
} else {
|
|
1192
|
-
const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
|
|
1193
|
-
if (typedArrayConstructor === undefined) {
|
|
1194
|
-
throw new TypeError(`Unsupported tensor type: ${arg0}.`);
|
|
1195
|
-
}
|
|
1196
|
-
if (Array.isArray(arg1)) {
|
|
1197
|
-
if (arg0 === "float16" && typedArrayConstructor === Uint16Array || arg0 === "uint4" || arg0 === "int4") {
|
|
1198
|
-
throw new TypeError(`Creating a ${arg0} tensor from number array is not supported. Please use ${typedArrayConstructor.name} as data.`);
|
|
1199
|
-
} else if (arg0 === "uint64" || arg0 === "int64") {
|
|
1200
|
-
data = typedArrayConstructor.from(arg1, BigInt);
|
|
1201
|
-
} else {
|
|
1202
|
-
data = typedArrayConstructor.from(arg1);
|
|
1203
|
-
}
|
|
1204
|
-
} else if (arg1 instanceof typedArrayConstructor) {
|
|
1205
|
-
data = arg1;
|
|
1206
|
-
} else if (arg1 instanceof Uint8ClampedArray) {
|
|
1207
|
-
if (arg0 === "uint8") {
|
|
1208
|
-
data = Uint8Array.from(arg1);
|
|
1209
|
-
} else {
|
|
1210
|
-
throw new TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);
|
|
1211
|
-
}
|
|
1212
|
-
} else if (arg0 === "float16" && arg1 instanceof Uint16Array && typedArrayConstructor !== Uint16Array) {
|
|
1213
|
-
data = new globalThis.Float16Array(arg1.buffer, arg1.byteOffset, arg1.length);
|
|
1214
|
-
} else {
|
|
1215
|
-
throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
} else {
|
|
1219
|
-
maybeDims = arg1;
|
|
1220
|
-
if (Array.isArray(arg0)) {
|
|
1221
|
-
if (arg0.length === 0) {
|
|
1222
|
-
throw new TypeError("Tensor type cannot be inferred from an empty array.");
|
|
1223
|
-
}
|
|
1224
|
-
const firstElementType = typeof arg0[0];
|
|
1225
|
-
if (firstElementType === "string") {
|
|
1226
|
-
type = "string";
|
|
1227
|
-
data = arg0;
|
|
1228
|
-
} else if (firstElementType === "boolean") {
|
|
1229
|
-
type = "bool";
|
|
1230
|
-
data = Uint8Array.from(arg0);
|
|
1231
|
-
} else {
|
|
1232
|
-
throw new TypeError(`Invalid element type of data array: ${firstElementType}.`);
|
|
1233
|
-
}
|
|
1234
|
-
} else if (arg0 instanceof Uint8ClampedArray) {
|
|
1235
|
-
type = "uint8";
|
|
1236
|
-
data = Uint8Array.from(arg0);
|
|
1237
|
-
} else {
|
|
1238
|
-
const mappedType = NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
|
|
1239
|
-
if (mappedType === undefined) {
|
|
1240
|
-
throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
|
|
1241
|
-
}
|
|
1242
|
-
type = mappedType;
|
|
1243
|
-
data = arg0;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
if (maybeDims === undefined) {
|
|
1247
|
-
maybeDims = [data.length];
|
|
1248
|
-
} else if (!Array.isArray(maybeDims)) {
|
|
1249
|
-
throw new TypeError("A tensor's dims must be a number array");
|
|
1250
|
-
}
|
|
1251
|
-
dims = maybeDims;
|
|
1252
|
-
this.cpuData = data;
|
|
1253
|
-
this.dataLocation = "cpu";
|
|
1254
|
-
}
|
|
1255
|
-
const size = calculateSize(dims);
|
|
1256
|
-
if (this.cpuData && size !== this.cpuData.length) {
|
|
1257
|
-
if ((type === "uint4" || type === "int4") && Math.ceil(size / 2) === this.cpuData.length) {} else {
|
|
1258
|
-
throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
this.type = type;
|
|
1262
|
-
this.dims = dims;
|
|
1263
|
-
this.size = size;
|
|
1264
|
-
}
|
|
1265
|
-
static async fromImage(image, options) {
|
|
1266
|
-
return tensorFromImage(image, options);
|
|
1267
|
-
}
|
|
1268
|
-
static fromTexture(texture, options) {
|
|
1269
|
-
return tensorFromTexture(texture, options);
|
|
1270
|
-
}
|
|
1271
|
-
static fromGpuBuffer(gpuBuffer, options) {
|
|
1272
|
-
return tensorFromGpuBuffer(gpuBuffer, options);
|
|
1273
|
-
}
|
|
1274
|
-
static fromMLTensor(mlTensor, options) {
|
|
1275
|
-
return tensorFromMLTensor(mlTensor, options);
|
|
1276
|
-
}
|
|
1277
|
-
static fromPinnedBuffer(type, buffer, dims) {
|
|
1278
|
-
return tensorFromPinnedBuffer(type, buffer, dims);
|
|
1279
|
-
}
|
|
1280
|
-
toDataURL(options) {
|
|
1281
|
-
return tensorToDataURL(this, options);
|
|
1282
|
-
}
|
|
1283
|
-
toImageData(options) {
|
|
1284
|
-
return tensorToImageData(this, options);
|
|
1285
|
-
}
|
|
1286
|
-
get data() {
|
|
1287
|
-
this.ensureValid();
|
|
1288
|
-
if (!this.cpuData) {
|
|
1289
|
-
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.");
|
|
1290
|
-
}
|
|
1291
|
-
return this.cpuData;
|
|
1292
|
-
}
|
|
1293
|
-
get location() {
|
|
1294
|
-
return this.dataLocation;
|
|
1295
|
-
}
|
|
1296
|
-
get texture() {
|
|
1297
|
-
this.ensureValid();
|
|
1298
|
-
if (!this.gpuTextureData) {
|
|
1299
|
-
throw new Error("The data is not stored as a WebGL texture.");
|
|
1300
|
-
}
|
|
1301
|
-
return this.gpuTextureData;
|
|
1302
|
-
}
|
|
1303
|
-
get gpuBuffer() {
|
|
1304
|
-
this.ensureValid();
|
|
1305
|
-
if (!this.gpuBufferData) {
|
|
1306
|
-
throw new Error("The data is not stored as a WebGPU buffer.");
|
|
1307
|
-
}
|
|
1308
|
-
return this.gpuBufferData;
|
|
1309
|
-
}
|
|
1310
|
-
get mlTensor() {
|
|
1311
|
-
this.ensureValid();
|
|
1312
|
-
if (!this.mlTensorData) {
|
|
1313
|
-
throw new Error("The data is not stored as a WebNN MLTensor.");
|
|
1314
|
-
}
|
|
1315
|
-
return this.mlTensorData;
|
|
1316
|
-
}
|
|
1317
|
-
async getData(releaseData) {
|
|
1318
|
-
this.ensureValid();
|
|
1319
|
-
switch (this.dataLocation) {
|
|
1320
|
-
case "cpu":
|
|
1321
|
-
case "cpu-pinned":
|
|
1322
|
-
return this.data;
|
|
1323
|
-
case "texture":
|
|
1324
|
-
case "gpu-buffer":
|
|
1325
|
-
case "ml-tensor": {
|
|
1326
|
-
if (!this.downloader) {
|
|
1327
|
-
throw new Error("The current tensor is not created with a specified data downloader.");
|
|
1328
|
-
}
|
|
1329
|
-
if (this.isDownloading) {
|
|
1330
|
-
throw new Error("The current tensor is being downloaded.");
|
|
1331
|
-
}
|
|
1332
|
-
try {
|
|
1333
|
-
this.isDownloading = true;
|
|
1334
|
-
const data = await this.downloader();
|
|
1335
|
-
this.downloader = undefined;
|
|
1336
|
-
this.dataLocation = "cpu";
|
|
1337
|
-
this.cpuData = data;
|
|
1338
|
-
if (releaseData && this.disposer) {
|
|
1339
|
-
this.disposer();
|
|
1340
|
-
this.disposer = undefined;
|
|
1341
|
-
}
|
|
1342
|
-
return data;
|
|
1343
|
-
} finally {
|
|
1344
|
-
this.isDownloading = false;
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
default:
|
|
1348
|
-
throw new Error(`cannot get data from location: ${this.dataLocation}`);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
dispose() {
|
|
1352
|
-
if (this.isDownloading) {
|
|
1353
|
-
throw new Error("The current tensor is being downloaded.");
|
|
1354
|
-
}
|
|
1355
|
-
if (this.disposer) {
|
|
1356
|
-
this.disposer();
|
|
1357
|
-
this.disposer = undefined;
|
|
1358
|
-
}
|
|
1359
|
-
this.cpuData = undefined;
|
|
1360
|
-
this.gpuTextureData = undefined;
|
|
1361
|
-
this.gpuBufferData = undefined;
|
|
1362
|
-
this.mlTensorData = undefined;
|
|
1363
|
-
this.downloader = undefined;
|
|
1364
|
-
this.isDownloading = undefined;
|
|
1365
|
-
this.dataLocation = "none";
|
|
1366
|
-
}
|
|
1367
|
-
ensureValid() {
|
|
1368
|
-
if (this.dataLocation === "none") {
|
|
1369
|
-
throw new Error("The tensor is disposed.");
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
reshape(dims) {
|
|
1373
|
-
this.ensureValid();
|
|
1374
|
-
if (this.downloader || this.disposer) {
|
|
1375
|
-
throw new Error("Cannot reshape a tensor that owns GPU resource.");
|
|
1376
|
-
}
|
|
1377
|
-
return tensorReshape(this, dims);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
var init_tensor_impl = __esm(() => {
|
|
1381
|
-
init_tensor_factory_impl();
|
|
1382
|
-
init_tensor_impl_type_mapping();
|
|
1383
|
-
init_tensor_utils_impl();
|
|
1384
|
-
});
|
|
1385
|
-
|
|
1386
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor.js
|
|
1387
|
-
var Tensor2;
|
|
1388
|
-
var init_tensor = __esm(() => {
|
|
1389
|
-
init_tensor_impl();
|
|
1390
|
-
Tensor2 = Tensor;
|
|
1391
|
-
});
|
|
1392
|
-
|
|
1393
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/trace.js
|
|
1394
|
-
var TRACE = (deviceType, label) => {
|
|
1395
|
-
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
1396
|
-
return;
|
|
1397
|
-
}
|
|
1398
|
-
console.timeStamp(`${deviceType}::ORT::${label}`);
|
|
1399
|
-
}, TRACE_FUNC = (msg, extraMsg) => {
|
|
1400
|
-
const stack = new Error().stack?.split(/\r\n|\r|\n/g) || [];
|
|
1401
|
-
let hasTraceFunc = false;
|
|
1402
|
-
for (let i = 0;i < stack.length; i++) {
|
|
1403
|
-
if (hasTraceFunc && !stack[i].includes("TRACE_FUNC")) {
|
|
1404
|
-
let label = `FUNC_${msg}::${stack[i].trim().split(" ")[1]}`;
|
|
1405
|
-
if (extraMsg) {
|
|
1406
|
-
label += `::${extraMsg}`;
|
|
1407
|
-
}
|
|
1408
|
-
TRACE("CPU", label);
|
|
1409
|
-
return;
|
|
1410
|
-
}
|
|
1411
|
-
if (stack[i].includes("TRACE_FUNC")) {
|
|
1412
|
-
hasTraceFunc = true;
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}, TRACE_FUNC_BEGIN = (extraMsg) => {
|
|
1416
|
-
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
1417
|
-
return;
|
|
1418
|
-
}
|
|
1419
|
-
TRACE_FUNC("BEGIN", extraMsg);
|
|
1420
|
-
}, TRACE_FUNC_END = (extraMsg) => {
|
|
1421
|
-
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
1422
|
-
return;
|
|
1423
|
-
}
|
|
1424
|
-
TRACE_FUNC("END", extraMsg);
|
|
1425
|
-
}, TRACE_EVENT_BEGIN = (extraMsg) => {
|
|
1426
|
-
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
1427
|
-
return;
|
|
1428
|
-
}
|
|
1429
|
-
console.time(`ORT::${extraMsg}`);
|
|
1430
|
-
}, TRACE_EVENT_END = (extraMsg) => {
|
|
1431
|
-
if (typeof env.trace === "undefined" ? !env.wasm.trace : !env.trace) {
|
|
1432
|
-
return;
|
|
1433
|
-
}
|
|
1434
|
-
console.timeEnd(`ORT::${extraMsg}`);
|
|
1435
|
-
};
|
|
1436
|
-
var init_trace = __esm(() => {
|
|
1437
|
-
init_env_impl();
|
|
1438
|
-
});
|
|
1439
|
-
|
|
1440
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/inference-session-impl.js
|
|
1441
|
-
class InferenceSession {
|
|
1442
|
-
constructor(handler) {
|
|
1443
|
-
this.handler = handler;
|
|
1444
|
-
}
|
|
1445
|
-
async run(feeds, arg1, arg2) {
|
|
1446
|
-
TRACE_FUNC_BEGIN();
|
|
1447
|
-
TRACE_EVENT_BEGIN("InferenceSession.run");
|
|
1448
|
-
const fetches = {};
|
|
1449
|
-
let options = {};
|
|
1450
|
-
if (typeof feeds !== "object" || feeds === null || feeds instanceof Tensor2 || Array.isArray(feeds)) {
|
|
1451
|
-
throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
|
|
1452
|
-
}
|
|
1453
|
-
let isFetchesEmpty = true;
|
|
1454
|
-
if (typeof arg1 === "object") {
|
|
1455
|
-
if (arg1 === null) {
|
|
1456
|
-
throw new TypeError("Unexpected argument[1]: cannot be null.");
|
|
1457
|
-
}
|
|
1458
|
-
if (arg1 instanceof Tensor2) {
|
|
1459
|
-
throw new TypeError("'fetches' cannot be a Tensor");
|
|
1460
|
-
}
|
|
1461
|
-
if (Array.isArray(arg1)) {
|
|
1462
|
-
if (arg1.length === 0) {
|
|
1463
|
-
throw new TypeError("'fetches' cannot be an empty array.");
|
|
1464
|
-
}
|
|
1465
|
-
isFetchesEmpty = false;
|
|
1466
|
-
for (const name of arg1) {
|
|
1467
|
-
if (typeof name !== "string") {
|
|
1468
|
-
throw new TypeError("'fetches' must be a string array or an object.");
|
|
1469
|
-
}
|
|
1470
|
-
if (this.outputNames.indexOf(name) === -1) {
|
|
1471
|
-
throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
|
|
1472
|
-
}
|
|
1473
|
-
fetches[name] = null;
|
|
1474
|
-
}
|
|
1475
|
-
if (typeof arg2 === "object" && arg2 !== null) {
|
|
1476
|
-
options = arg2;
|
|
1477
|
-
} else if (typeof arg2 !== "undefined") {
|
|
1478
|
-
throw new TypeError("'options' must be an object.");
|
|
1479
|
-
}
|
|
1480
|
-
} else {
|
|
1481
|
-
let isFetches = false;
|
|
1482
|
-
const arg1Keys = Object.getOwnPropertyNames(arg1);
|
|
1483
|
-
for (const name of this.outputNames) {
|
|
1484
|
-
if (arg1Keys.indexOf(name) !== -1) {
|
|
1485
|
-
const v = arg1[name];
|
|
1486
|
-
if (v === null || v instanceof Tensor2) {
|
|
1487
|
-
isFetches = true;
|
|
1488
|
-
isFetchesEmpty = false;
|
|
1489
|
-
fetches[name] = v;
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
if (isFetches) {
|
|
1494
|
-
if (typeof arg2 === "object" && arg2 !== null) {
|
|
1495
|
-
options = arg2;
|
|
1496
|
-
} else if (typeof arg2 !== "undefined") {
|
|
1497
|
-
throw new TypeError("'options' must be an object.");
|
|
1498
|
-
}
|
|
1499
|
-
} else {
|
|
1500
|
-
options = arg1;
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
} else if (typeof arg1 !== "undefined") {
|
|
1504
|
-
throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
|
|
1505
|
-
}
|
|
1506
|
-
for (const name of this.inputNames) {
|
|
1507
|
-
if (typeof feeds[name] === "undefined") {
|
|
1508
|
-
throw new Error(`input '${name}' is missing in 'feeds'.`);
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
if (isFetchesEmpty) {
|
|
1512
|
-
for (const name of this.outputNames) {
|
|
1513
|
-
fetches[name] = null;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
const results = await this.handler.run(feeds, fetches, options);
|
|
1517
|
-
const returnValue = {};
|
|
1518
|
-
for (const key in results) {
|
|
1519
|
-
if (Object.hasOwnProperty.call(results, key)) {
|
|
1520
|
-
const result = results[key];
|
|
1521
|
-
if (result instanceof Tensor2) {
|
|
1522
|
-
returnValue[key] = result;
|
|
1523
|
-
} else {
|
|
1524
|
-
returnValue[key] = new Tensor2(result.type, result.data, result.dims);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
TRACE_EVENT_END("InferenceSession.run");
|
|
1529
|
-
TRACE_FUNC_END();
|
|
1530
|
-
return returnValue;
|
|
1531
|
-
}
|
|
1532
|
-
async release() {
|
|
1533
|
-
return this.handler.dispose();
|
|
1534
|
-
}
|
|
1535
|
-
static async create(arg0, arg1, arg2, arg3) {
|
|
1536
|
-
TRACE_FUNC_BEGIN();
|
|
1537
|
-
TRACE_EVENT_BEGIN("InferenceSession.create");
|
|
1538
|
-
let filePathOrUint8Array;
|
|
1539
|
-
let options = {};
|
|
1540
|
-
if (typeof arg0 === "string") {
|
|
1541
|
-
filePathOrUint8Array = arg0;
|
|
1542
|
-
if (typeof arg1 === "object" && arg1 !== null) {
|
|
1543
|
-
options = arg1;
|
|
1544
|
-
} else if (typeof arg1 !== "undefined") {
|
|
1545
|
-
throw new TypeError("'options' must be an object.");
|
|
1546
|
-
}
|
|
1547
|
-
} else if (arg0 instanceof Uint8Array) {
|
|
1548
|
-
filePathOrUint8Array = arg0;
|
|
1549
|
-
if (typeof arg1 === "object" && arg1 !== null) {
|
|
1550
|
-
options = arg1;
|
|
1551
|
-
} else if (typeof arg1 !== "undefined") {
|
|
1552
|
-
throw new TypeError("'options' must be an object.");
|
|
1553
|
-
}
|
|
1554
|
-
} else if (arg0 instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && arg0 instanceof SharedArrayBuffer) {
|
|
1555
|
-
const buffer = arg0;
|
|
1556
|
-
let byteOffset = 0;
|
|
1557
|
-
let byteLength = arg0.byteLength;
|
|
1558
|
-
if (typeof arg1 === "object" && arg1 !== null) {
|
|
1559
|
-
options = arg1;
|
|
1560
|
-
} else if (typeof arg1 === "number") {
|
|
1561
|
-
byteOffset = arg1;
|
|
1562
|
-
if (!Number.isSafeInteger(byteOffset)) {
|
|
1563
|
-
throw new RangeError("'byteOffset' must be an integer.");
|
|
1564
|
-
}
|
|
1565
|
-
if (byteOffset < 0 || byteOffset >= buffer.byteLength) {
|
|
1566
|
-
throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`);
|
|
1567
|
-
}
|
|
1568
|
-
byteLength = arg0.byteLength - byteOffset;
|
|
1569
|
-
if (typeof arg2 === "number") {
|
|
1570
|
-
byteLength = arg2;
|
|
1571
|
-
if (!Number.isSafeInteger(byteLength)) {
|
|
1572
|
-
throw new RangeError("'byteLength' must be an integer.");
|
|
1573
|
-
}
|
|
1574
|
-
if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) {
|
|
1575
|
-
throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`);
|
|
1576
|
-
}
|
|
1577
|
-
if (typeof arg3 === "object" && arg3 !== null) {
|
|
1578
|
-
options = arg3;
|
|
1579
|
-
} else if (typeof arg3 !== "undefined") {
|
|
1580
|
-
throw new TypeError("'options' must be an object.");
|
|
1581
|
-
}
|
|
1582
|
-
} else if (typeof arg2 !== "undefined") {
|
|
1583
|
-
throw new TypeError("'byteLength' must be a number.");
|
|
1584
|
-
}
|
|
1585
|
-
} else if (typeof arg1 !== "undefined") {
|
|
1586
|
-
throw new TypeError("'options' must be an object.");
|
|
1587
|
-
}
|
|
1588
|
-
filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1589
|
-
} else {
|
|
1590
|
-
throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
|
|
1591
|
-
}
|
|
1592
|
-
const [backend, optionsWithValidatedEPs] = await resolveBackendAndExecutionProviders(options);
|
|
1593
|
-
const handler = await backend.createInferenceSessionHandler(filePathOrUint8Array, optionsWithValidatedEPs);
|
|
1594
|
-
TRACE_EVENT_END("InferenceSession.create");
|
|
1595
|
-
TRACE_FUNC_END();
|
|
1596
|
-
return new InferenceSession(handler);
|
|
1597
|
-
}
|
|
1598
|
-
startProfiling() {
|
|
1599
|
-
this.handler.startProfiling();
|
|
1600
|
-
}
|
|
1601
|
-
endProfiling() {
|
|
1602
|
-
this.handler.endProfiling();
|
|
1603
|
-
}
|
|
1604
|
-
get inputNames() {
|
|
1605
|
-
return this.handler.inputNames;
|
|
1606
|
-
}
|
|
1607
|
-
get outputNames() {
|
|
1608
|
-
return this.handler.outputNames;
|
|
1609
|
-
}
|
|
1610
|
-
get inputMetadata() {
|
|
1611
|
-
return this.handler.inputMetadata;
|
|
1612
|
-
}
|
|
1613
|
-
get outputMetadata() {
|
|
1614
|
-
return this.handler.outputMetadata;
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
var init_inference_session_impl = __esm(() => {
|
|
1618
|
-
init_backend_impl();
|
|
1619
|
-
init_tensor();
|
|
1620
|
-
init_trace();
|
|
1621
|
-
});
|
|
1622
|
-
|
|
1623
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/inference-session.js
|
|
1624
|
-
var InferenceSession2;
|
|
1625
|
-
var init_inference_session = __esm(() => {
|
|
1626
|
-
init_inference_session_impl();
|
|
1627
|
-
InferenceSession2 = InferenceSession;
|
|
1628
|
-
});
|
|
1629
|
-
|
|
1630
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-conversion.js
|
|
1631
|
-
var init_tensor_conversion = () => {};
|
|
1632
|
-
|
|
1633
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/tensor-factory.js
|
|
1634
|
-
var init_tensor_factory = () => {};
|
|
1635
|
-
|
|
1636
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/onnx-model.js
|
|
1637
|
-
var init_onnx_model = () => {};
|
|
1638
|
-
|
|
1639
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/onnx-value.js
|
|
1640
|
-
var init_onnx_value = () => {};
|
|
1641
|
-
|
|
1642
|
-
// ../../node_modules/.bun/onnxruntime-common@1.24.0-dev.20251116-b39e144322/node_modules/onnxruntime-common/dist/esm/index.js
|
|
1643
|
-
var exports_esm = {};
|
|
1644
|
-
__export(exports_esm, {
|
|
1645
|
-
InferenceSession: () => InferenceSession2,
|
|
1646
|
-
TRACE: () => TRACE,
|
|
1647
|
-
TRACE_EVENT_BEGIN: () => TRACE_EVENT_BEGIN,
|
|
1648
|
-
TRACE_EVENT_END: () => TRACE_EVENT_END,
|
|
1649
|
-
TRACE_FUNC_BEGIN: () => TRACE_FUNC_BEGIN,
|
|
1650
|
-
TRACE_FUNC_END: () => TRACE_FUNC_END,
|
|
1651
|
-
Tensor: () => Tensor2,
|
|
1652
|
-
env: () => env2,
|
|
1653
|
-
registerBackend: () => registerBackend
|
|
1654
|
-
});
|
|
1655
|
-
var init_esm = __esm(() => {
|
|
1656
|
-
init_backend();
|
|
1657
|
-
init_env();
|
|
1658
|
-
init_inference_session();
|
|
1659
|
-
init_tensor();
|
|
1660
|
-
init_tensor_conversion();
|
|
1661
|
-
init_tensor_factory();
|
|
1662
|
-
init_trace();
|
|
1663
|
-
init_onnx_model();
|
|
1664
|
-
init_onnx_value();
|
|
1665
|
-
});
|
|
1666
|
-
|
|
1667
|
-
// ../../node_modules/.bun/onnxruntime-web@1.26.0-dev.20260416-b7804b056c/node_modules/onnxruntime-web/dist/ort.node.min.mjs
|
|
1668
|
-
var exports_ort_node_min = {};
|
|
1669
|
-
__export(exports_ort_node_min, {
|
|
1670
|
-
InferenceSession: () => InferenceSession2,
|
|
1671
|
-
TRACE: () => TRACE,
|
|
1672
|
-
TRACE_EVENT_BEGIN: () => TRACE_EVENT_BEGIN,
|
|
1673
|
-
TRACE_EVENT_END: () => TRACE_EVENT_END,
|
|
1674
|
-
TRACE_FUNC_BEGIN: () => TRACE_FUNC_BEGIN,
|
|
1675
|
-
TRACE_FUNC_END: () => TRACE_FUNC_END,
|
|
1676
|
-
Tensor: () => Tensor2,
|
|
1677
|
-
default: () => Hr,
|
|
1678
|
-
env: () => env2,
|
|
1679
|
-
registerBackend: () => registerBackend
|
|
1680
|
-
});
|
|
1681
|
-
import { createRequire as createRequire3 } from "module";
|
|
1682
|
-
var require2, pe, Et, St, ht, de, C = (e, t) => () => (e && (t = e(e = 0)), t), Ot = (e, t) => {
|
|
1683
|
-
for (var n in t)
|
|
1684
|
-
pe(e, n, { get: t[n], enumerable: true });
|
|
1685
|
-
}, It = (e, t, n, o) => {
|
|
1686
|
-
if (t && typeof t == "object" || typeof t == "function")
|
|
1687
|
-
for (let r of St(t))
|
|
1688
|
-
!ht.call(e, r) && r !== n && pe(e, r, { get: () => t[r], enumerable: !(o = Et(t, r)) || o.enumerable });
|
|
1689
|
-
return e;
|
|
1690
|
-
}, Tt = (e) => It(pe({}, "__esModule", { value: true }), e), j, re, Ae, Lt, Bt, $, xe, De, _t, Pt, vt, Dt, Ue, Ce, me, be, we, ne, Me, Ut, At, xt, We, E, V, A, K, g, oe, Fe, ke, Ct, Mt, Wt, se, Ft, Re, Ne, J, ae, q, Ge, je, ie, ue, $e, ge, Q, ye, kt, qe, Ye, Y, Rt, Ve, Ee, Ze, Xe, Je, Ke, Qe, et, Se, tt, rt, nt, ot, st, at, it, ut, ct, Oe, pt, Gt, ce, dt, bt, mt, le, jt, wt, ve = "1.26.0-dev.20260416-b7804b056c", Hr;
|
|
1691
|
-
var init_ort_node_min = __esm(() => {
|
|
1692
|
-
init_esm();
|
|
1693
|
-
init_esm();
|
|
1694
|
-
init_esm();
|
|
1695
|
-
init_esm();
|
|
1696
|
-
init_esm();
|
|
1697
|
-
init_esm();
|
|
1698
|
-
init_esm();
|
|
1699
|
-
/*!
|
|
1700
|
-
* ONNX Runtime Web v1.26.0-dev.20260416-b7804b056c
|
|
1701
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1702
|
-
* Licensed under the MIT License.
|
|
1703
|
-
*/
|
|
1704
|
-
require2 = createRequire3(import.meta.url);
|
|
1705
|
-
pe = Object.defineProperty;
|
|
1706
|
-
Et = Object.getOwnPropertyDescriptor;
|
|
1707
|
-
St = Object.getOwnPropertyNames;
|
|
1708
|
-
ht = Object.prototype.hasOwnProperty;
|
|
1709
|
-
de = ((e) => typeof require2 < "u" ? require2 : typeof Proxy < "u" ? new Proxy(e, { get: (t, n) => (typeof require2 < "u" ? require2 : t)[n] }) : e)(function(e) {
|
|
1710
|
-
if (typeof require2 < "u")
|
|
1711
|
-
return require2.apply(this, arguments);
|
|
1712
|
-
throw Error('Dynamic require of "' + e + '" is not supported');
|
|
1713
|
-
});
|
|
1714
|
-
re = C(() => {
|
|
1715
|
-
j = !!(typeof process < "u" && process.versions && process.versions.node);
|
|
1716
|
-
});
|
|
1717
|
-
me = C(() => {
|
|
1718
|
-
re();
|
|
1719
|
-
Ae = j || typeof location > "u" ? undefined : location.origin, Lt = import.meta.url > "file:" && import.meta.url < "file;", Bt = () => {
|
|
1720
|
-
if (!j) {
|
|
1721
|
-
if (Lt) {
|
|
1722
|
-
let e = URL;
|
|
1723
|
-
return new URL(new e("ort.node.min.mjs", import.meta.url).href, Ae).href;
|
|
1724
|
-
}
|
|
1725
|
-
return import.meta.url;
|
|
1726
|
-
}
|
|
1727
|
-
}, $ = Bt(), xe = () => {
|
|
1728
|
-
if ($ && !$.startsWith("blob:"))
|
|
1729
|
-
return $.substring(0, $.lastIndexOf("/") + 1);
|
|
1730
|
-
}, De = (e, t) => {
|
|
1731
|
-
try {
|
|
1732
|
-
let n = t ?? $;
|
|
1733
|
-
return (n ? new URL(e, n) : new URL(e)).origin === Ae;
|
|
1734
|
-
} catch {
|
|
1735
|
-
return false;
|
|
1736
|
-
}
|
|
1737
|
-
}, _t = (e, t) => {
|
|
1738
|
-
let n = t ?? $;
|
|
1739
|
-
try {
|
|
1740
|
-
return (n ? new URL(e, n) : new URL(e)).href;
|
|
1741
|
-
} catch {
|
|
1742
|
-
return;
|
|
1743
|
-
}
|
|
1744
|
-
}, Pt = (e, t) => `${t ?? "./"}${e}`, vt = async (e) => {
|
|
1745
|
-
let n = await (await fetch(e, { credentials: "same-origin" })).blob();
|
|
1746
|
-
return URL.createObjectURL(n);
|
|
1747
|
-
}, Dt = async (e) => (await import(e)).default, Ue = undefined, Ce = async (e, t, n, o) => {
|
|
1748
|
-
let r = Ue && !(e || t);
|
|
1749
|
-
if (r)
|
|
1750
|
-
if ($)
|
|
1751
|
-
r = De($) || o && !n;
|
|
1752
|
-
else if (o && !n)
|
|
1753
|
-
r = true;
|
|
1754
|
-
else
|
|
1755
|
-
throw new Error("cannot determine the script source URL.");
|
|
1756
|
-
if (r)
|
|
1757
|
-
return [undefined, Ue];
|
|
1758
|
-
{
|
|
1759
|
-
let a = "ort-wasm-simd-threaded.mjs", s = e ?? _t(a, t), i = !j && n && s && !De(s, t), u = i ? await vt(s) : s ?? Pt(a, t);
|
|
1760
|
-
return [i ? u : undefined, await Dt(u)];
|
|
1761
|
-
}
|
|
1762
|
-
};
|
|
1763
|
-
});
|
|
1764
|
-
V = C(() => {
|
|
1765
|
-
me();
|
|
1766
|
-
we = false, ne = false, Me = false, Ut = () => {
|
|
1767
|
-
if (typeof SharedArrayBuffer > "u")
|
|
1768
|
-
return false;
|
|
1769
|
-
try {
|
|
1770
|
-
return typeof MessageChannel < "u" && new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)), WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 5, 4, 1, 3, 1, 1, 10, 11, 1, 9, 0, 65, 0, 254, 16, 2, 0, 26, 11]));
|
|
1771
|
-
} catch {
|
|
1772
|
-
return false;
|
|
1773
|
-
}
|
|
1774
|
-
}, At = () => {
|
|
1775
|
-
try {
|
|
1776
|
-
return WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 30, 1, 28, 0, 65, 0, 253, 15, 253, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 253, 186, 1, 26, 11]));
|
|
1777
|
-
} catch {
|
|
1778
|
-
return false;
|
|
1779
|
-
}
|
|
1780
|
-
}, xt = () => {
|
|
1781
|
-
try {
|
|
1782
|
-
return WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 19, 1, 17, 0, 65, 1, 253, 15, 65, 2, 253, 15, 65, 3, 253, 15, 253, 147, 2, 11]));
|
|
1783
|
-
} catch {
|
|
1784
|
-
return false;
|
|
1785
|
-
}
|
|
1786
|
-
}, We = async (e) => {
|
|
1787
|
-
if (we)
|
|
1788
|
-
return Promise.resolve();
|
|
1789
|
-
if (ne)
|
|
1790
|
-
throw new Error("multiple calls to 'initializeWebAssembly()' detected.");
|
|
1791
|
-
if (Me)
|
|
1792
|
-
throw new Error("previous call to 'initializeWebAssembly()' failed.");
|
|
1793
|
-
ne = true;
|
|
1794
|
-
let { initTimeout: t, numThreads: n } = e;
|
|
1795
|
-
if (e.simd !== false) {
|
|
1796
|
-
if (e.simd === "relaxed") {
|
|
1797
|
-
if (!xt())
|
|
1798
|
-
throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.");
|
|
1799
|
-
} else if (!At())
|
|
1800
|
-
throw new Error("WebAssembly SIMD is not supported in the current environment.");
|
|
1801
|
-
}
|
|
1802
|
-
let o = Ut();
|
|
1803
|
-
n > 1 && !o && (typeof self < "u" && !self.crossOriginIsolated && console.warn("env.wasm.numThreads is set to " + n + ", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."), console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."), e.numThreads = n = 1);
|
|
1804
|
-
let r = e.wasmPaths, a = typeof r == "string" ? r : undefined, s = r?.mjs, i = s?.href ?? s, u = r?.wasm, f = u?.href ?? u, w = e.wasmBinary, [l, c] = await Ce(i, a, n > 1, !!w || !!f), p = false, S = [];
|
|
1805
|
-
if (t > 0 && S.push(new Promise((h) => {
|
|
1806
|
-
setTimeout(() => {
|
|
1807
|
-
p = true, h();
|
|
1808
|
-
}, t);
|
|
1809
|
-
})), S.push(new Promise((h, v) => {
|
|
1810
|
-
let m = { numThreads: n };
|
|
1811
|
-
if (w)
|
|
1812
|
-
m.wasmBinary = w, m.locateFile = (b) => b;
|
|
1813
|
-
else if (f || a)
|
|
1814
|
-
m.locateFile = (b) => f ?? a + b;
|
|
1815
|
-
else if (i && i.indexOf("blob:") !== 0)
|
|
1816
|
-
m.locateFile = (b) => new URL(b, i).href;
|
|
1817
|
-
else if (l) {
|
|
1818
|
-
let b = xe();
|
|
1819
|
-
b && (m.locateFile = (M) => b + M);
|
|
1820
|
-
}
|
|
1821
|
-
c(m).then((b) => {
|
|
1822
|
-
ne = false, we = true, be = b, h(), l && URL.revokeObjectURL(l);
|
|
1823
|
-
}, (b) => {
|
|
1824
|
-
ne = false, Me = true, v(b);
|
|
1825
|
-
});
|
|
1826
|
-
})), await Promise.race(S), p)
|
|
1827
|
-
throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`);
|
|
1828
|
-
}, E = () => {
|
|
1829
|
-
if (we && be)
|
|
1830
|
-
return be;
|
|
1831
|
-
throw new Error("WebAssembly is not initialized yet.");
|
|
1832
|
-
};
|
|
1833
|
-
});
|
|
1834
|
-
oe = C(() => {
|
|
1835
|
-
V();
|
|
1836
|
-
A = (e, t) => {
|
|
1837
|
-
let n = E(), o = n.lengthBytesUTF8(e) + 1, r = n._malloc(o);
|
|
1838
|
-
return n.stringToUTF8(e, r, o), t.push(r), r;
|
|
1839
|
-
}, K = (e, t, n, o) => {
|
|
1840
|
-
if (typeof e == "object" && e !== null) {
|
|
1841
|
-
if (n.has(e))
|
|
1842
|
-
throw new Error("Circular reference in options");
|
|
1843
|
-
n.add(e);
|
|
1844
|
-
}
|
|
1845
|
-
Object.entries(e).forEach(([r, a]) => {
|
|
1846
|
-
let s = t ? t + r : r;
|
|
1847
|
-
if (typeof a == "object")
|
|
1848
|
-
K(a, s + ".", n, o);
|
|
1849
|
-
else if (typeof a == "string" || typeof a == "number")
|
|
1850
|
-
o(s, a.toString());
|
|
1851
|
-
else if (typeof a == "boolean")
|
|
1852
|
-
o(s, a ? "1" : "0");
|
|
1853
|
-
else
|
|
1854
|
-
throw new Error(`Can't handle extra config type: ${typeof a}`);
|
|
1855
|
-
});
|
|
1856
|
-
}, g = (e) => {
|
|
1857
|
-
let t = E(), n = t.stackSave();
|
|
1858
|
-
try {
|
|
1859
|
-
let o = t.PTR_SIZE, r = t.stackAlloc(2 * o);
|
|
1860
|
-
t._OrtGetLastError(r, r + o);
|
|
1861
|
-
let a = Number(t.getValue(r, o === 4 ? "i32" : "i64")), s = t.getValue(r + o, "*"), i = s ? t.UTF8ToString(s) : "";
|
|
1862
|
-
throw new Error(`${e} ERROR_CODE: ${a}, ERROR_MESSAGE: ${i}`);
|
|
1863
|
-
} finally {
|
|
1864
|
-
t.stackRestore(n);
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
});
|
|
1868
|
-
ke = C(() => {
|
|
1869
|
-
V();
|
|
1870
|
-
oe();
|
|
1871
|
-
Fe = (e) => {
|
|
1872
|
-
let t = E(), n = 0, o = [], r = e || {};
|
|
1873
|
-
try {
|
|
1874
|
-
if (e?.logSeverityLevel === undefined)
|
|
1875
|
-
r.logSeverityLevel = 2;
|
|
1876
|
-
else if (typeof e.logSeverityLevel != "number" || !Number.isInteger(e.logSeverityLevel) || e.logSeverityLevel < 0 || e.logSeverityLevel > 4)
|
|
1877
|
-
throw new Error(`log severity level is not valid: ${e.logSeverityLevel}`);
|
|
1878
|
-
if (e?.logVerbosityLevel === undefined)
|
|
1879
|
-
r.logVerbosityLevel = 0;
|
|
1880
|
-
else if (typeof e.logVerbosityLevel != "number" || !Number.isInteger(e.logVerbosityLevel))
|
|
1881
|
-
throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);
|
|
1882
|
-
e?.terminate === undefined && (r.terminate = false);
|
|
1883
|
-
let a = 0;
|
|
1884
|
-
return e?.tag !== undefined && (a = A(e.tag, o)), n = t._OrtCreateRunOptions(r.logSeverityLevel, r.logVerbosityLevel, !!r.terminate, a), n === 0 && g("Can't create run options."), e?.extra !== undefined && K(e.extra, "", new WeakSet, (s, i) => {
|
|
1885
|
-
let u = A(s, o), f = A(i, o);
|
|
1886
|
-
t._OrtAddRunConfigEntry(n, u, f) !== 0 && g(`Can't set a run config entry: ${s} - ${i}.`);
|
|
1887
|
-
}), [n, o];
|
|
1888
|
-
} catch (a) {
|
|
1889
|
-
throw n !== 0 && t._OrtReleaseRunOptions(n), o.forEach((s) => t._free(s)), a;
|
|
1890
|
-
}
|
|
1891
|
-
};
|
|
1892
|
-
});
|
|
1893
|
-
Ne = C(() => {
|
|
1894
|
-
V();
|
|
1895
|
-
oe();
|
|
1896
|
-
Ct = (e) => {
|
|
1897
|
-
switch (e) {
|
|
1898
|
-
case "disabled":
|
|
1899
|
-
return 0;
|
|
1900
|
-
case "basic":
|
|
1901
|
-
return 1;
|
|
1902
|
-
case "extended":
|
|
1903
|
-
return 2;
|
|
1904
|
-
case "layout":
|
|
1905
|
-
return 3;
|
|
1906
|
-
case "all":
|
|
1907
|
-
return 99;
|
|
1908
|
-
default:
|
|
1909
|
-
throw new Error(`unsupported graph optimization level: ${e}`);
|
|
1910
|
-
}
|
|
1911
|
-
}, Mt = (e) => {
|
|
1912
|
-
switch (e) {
|
|
1913
|
-
case "sequential":
|
|
1914
|
-
return 0;
|
|
1915
|
-
case "parallel":
|
|
1916
|
-
return 1;
|
|
1917
|
-
default:
|
|
1918
|
-
throw new Error(`unsupported execution mode: ${e}`);
|
|
1919
|
-
}
|
|
1920
|
-
}, Wt = (e) => {
|
|
1921
|
-
e.extra || (e.extra = {}), e.extra.session || (e.extra.session = {});
|
|
1922
|
-
let t = e.extra.session;
|
|
1923
|
-
t.use_ort_model_bytes_directly || (t.use_ort_model_bytes_directly = "1"), e.executionProviders && e.executionProviders.some((n) => (typeof n == "string" ? n : n.name) === "webgpu") && (e.enableMemPattern = false);
|
|
1924
|
-
}, se = (e, t, n, o) => {
|
|
1925
|
-
let r = A(t, o), a = A(n, o);
|
|
1926
|
-
E()._OrtAddSessionConfigEntry(e, r, a) !== 0 && g(`Can't set a session config entry: ${t} - ${n}.`);
|
|
1927
|
-
}, Ft = async (e, t, n) => {
|
|
1928
|
-
let o = t.executionProviders;
|
|
1929
|
-
for (let r of o) {
|
|
1930
|
-
let a = typeof r == "string" ? r : r.name, s = [];
|
|
1931
|
-
switch (a) {
|
|
1932
|
-
case "webnn":
|
|
1933
|
-
if (a = "WEBNN", typeof r != "string") {
|
|
1934
|
-
let c = r?.deviceType;
|
|
1935
|
-
c && se(e, "deviceType", c, n);
|
|
1936
|
-
}
|
|
1937
|
-
break;
|
|
1938
|
-
case "webgpu":
|
|
1939
|
-
if (a = "JS", typeof r != "string") {
|
|
1940
|
-
let l = r;
|
|
1941
|
-
if (l?.preferredLayout) {
|
|
1942
|
-
if (l.preferredLayout !== "NCHW" && l.preferredLayout !== "NHWC")
|
|
1943
|
-
throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${l.preferredLayout}`);
|
|
1944
|
-
se(e, "preferredLayout", l.preferredLayout, n);
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
break;
|
|
1948
|
-
case "wasm":
|
|
1949
|
-
case "cpu":
|
|
1950
|
-
continue;
|
|
1951
|
-
default:
|
|
1952
|
-
throw new Error(`not supported execution provider: ${a}`);
|
|
1953
|
-
}
|
|
1954
|
-
let i = A(a, n), u = s.length, f = 0, w = 0;
|
|
1955
|
-
if (u > 0) {
|
|
1956
|
-
f = E()._malloc(u * E().PTR_SIZE), n.push(f), w = E()._malloc(u * E().PTR_SIZE), n.push(w);
|
|
1957
|
-
for (let l = 0;l < u; l++)
|
|
1958
|
-
E().setValue(f + l * E().PTR_SIZE, s[l][0], "*"), E().setValue(w + l * E().PTR_SIZE, s[l][1], "*");
|
|
1959
|
-
}
|
|
1960
|
-
await E()._OrtAppendExecutionProvider(e, i, f, w, u) !== 0 && g(`Can't append execution provider: ${a}.`);
|
|
1961
|
-
}
|
|
1962
|
-
}, Re = async (e) => {
|
|
1963
|
-
let t = E(), n = 0, o = [], r = e || {};
|
|
1964
|
-
Wt(r);
|
|
1965
|
-
try {
|
|
1966
|
-
let a = Ct(r.graphOptimizationLevel ?? "all"), s = Mt(r.executionMode ?? "sequential"), i = typeof r.logId == "string" ? A(r.logId, o) : 0, u = r.logSeverityLevel ?? 2;
|
|
1967
|
-
if (!Number.isInteger(u) || u < 0 || u > 4)
|
|
1968
|
-
throw new Error(`log severity level is not valid: ${u}`);
|
|
1969
|
-
let f = r.logVerbosityLevel ?? 0;
|
|
1970
|
-
if (!Number.isInteger(f) || f < 0 || f > 4)
|
|
1971
|
-
throw new Error(`log verbosity level is not valid: ${f}`);
|
|
1972
|
-
let w = typeof r.optimizedModelFilePath == "string" ? A(r.optimizedModelFilePath, o) : 0;
|
|
1973
|
-
if (n = t._OrtCreateSessionOptions(a, !!r.enableCpuMemArena, !!r.enableMemPattern, s, !!r.enableProfiling, 0, i, u, f, w), n === 0 && g("Can't create session options."), r.executionProviders && await Ft(n, r, o), r.enableGraphCapture !== undefined) {
|
|
1974
|
-
if (typeof r.enableGraphCapture != "boolean")
|
|
1975
|
-
throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);
|
|
1976
|
-
se(n, "enableGraphCapture", r.enableGraphCapture.toString(), o);
|
|
1977
|
-
}
|
|
1978
|
-
if (r.freeDimensionOverrides)
|
|
1979
|
-
for (let [l, c] of Object.entries(r.freeDimensionOverrides)) {
|
|
1980
|
-
if (typeof l != "string")
|
|
1981
|
-
throw new Error(`free dimension override name must be a string: ${l}`);
|
|
1982
|
-
if (typeof c != "number" || !Number.isInteger(c) || c < 0)
|
|
1983
|
-
throw new Error(`free dimension override value must be a non-negative integer: ${c}`);
|
|
1984
|
-
let p = A(l, o);
|
|
1985
|
-
t._OrtAddFreeDimensionOverride(n, p, c) !== 0 && g(`Can't set a free dimension override: ${l} - ${c}.`);
|
|
1986
|
-
}
|
|
1987
|
-
return r.extra !== undefined && K(r.extra, "", new WeakSet, (l, c) => {
|
|
1988
|
-
se(n, l, c, o);
|
|
1989
|
-
}), [n, o];
|
|
1990
|
-
} catch (a) {
|
|
1991
|
-
throw n !== 0 && t._OrtReleaseSessionOptions(n) !== 0 && g("Can't release session options."), o.forEach((s) => t._free(s)), a;
|
|
1992
|
-
}
|
|
1993
|
-
};
|
|
1994
|
-
});
|
|
1995
|
-
ge = C(() => {
|
|
1996
|
-
J = (e) => {
|
|
1997
|
-
switch (e) {
|
|
1998
|
-
case "int8":
|
|
1999
|
-
return 3;
|
|
2000
|
-
case "uint8":
|
|
2001
|
-
return 2;
|
|
2002
|
-
case "bool":
|
|
2003
|
-
return 9;
|
|
2004
|
-
case "int16":
|
|
2005
|
-
return 5;
|
|
2006
|
-
case "uint16":
|
|
2007
|
-
return 4;
|
|
2008
|
-
case "int32":
|
|
2009
|
-
return 6;
|
|
2010
|
-
case "uint32":
|
|
2011
|
-
return 12;
|
|
2012
|
-
case "float16":
|
|
2013
|
-
return 10;
|
|
2014
|
-
case "float32":
|
|
2015
|
-
return 1;
|
|
2016
|
-
case "float64":
|
|
2017
|
-
return 11;
|
|
2018
|
-
case "string":
|
|
2019
|
-
return 8;
|
|
2020
|
-
case "int64":
|
|
2021
|
-
return 7;
|
|
2022
|
-
case "uint64":
|
|
2023
|
-
return 13;
|
|
2024
|
-
case "int4":
|
|
2025
|
-
return 22;
|
|
2026
|
-
case "uint4":
|
|
2027
|
-
return 21;
|
|
2028
|
-
default:
|
|
2029
|
-
throw new Error(`unsupported data type: ${e}`);
|
|
2030
|
-
}
|
|
2031
|
-
}, ae = (e) => {
|
|
2032
|
-
switch (e) {
|
|
2033
|
-
case 3:
|
|
2034
|
-
return "int8";
|
|
2035
|
-
case 2:
|
|
2036
|
-
return "uint8";
|
|
2037
|
-
case 9:
|
|
2038
|
-
return "bool";
|
|
2039
|
-
case 5:
|
|
2040
|
-
return "int16";
|
|
2041
|
-
case 4:
|
|
2042
|
-
return "uint16";
|
|
2043
|
-
case 6:
|
|
2044
|
-
return "int32";
|
|
2045
|
-
case 12:
|
|
2046
|
-
return "uint32";
|
|
2047
|
-
case 10:
|
|
2048
|
-
return "float16";
|
|
2049
|
-
case 1:
|
|
2050
|
-
return "float32";
|
|
2051
|
-
case 11:
|
|
2052
|
-
return "float64";
|
|
2053
|
-
case 8:
|
|
2054
|
-
return "string";
|
|
2055
|
-
case 7:
|
|
2056
|
-
return "int64";
|
|
2057
|
-
case 13:
|
|
2058
|
-
return "uint64";
|
|
2059
|
-
case 22:
|
|
2060
|
-
return "int4";
|
|
2061
|
-
case 21:
|
|
2062
|
-
return "uint4";
|
|
2063
|
-
default:
|
|
2064
|
-
throw new Error(`unsupported data type: ${e}`);
|
|
2065
|
-
}
|
|
2066
|
-
}, q = (e, t) => {
|
|
2067
|
-
let n = [-1, 4, 1, 1, 2, 2, 4, 8, -1, 1, 2, 8, 4, 8, -1, -1, -1, -1, -1, -1, -1, 0.5, 0.5][e], o = typeof t == "number" ? t : t.reduce((r, a) => r * a, 1);
|
|
2068
|
-
return n > 0 ? Math.ceil(o * n) : undefined;
|
|
2069
|
-
}, Ge = (e) => {
|
|
2070
|
-
switch (e) {
|
|
2071
|
-
case "float16":
|
|
2072
|
-
return typeof Float16Array < "u" && Float16Array.from ? Float16Array : Uint16Array;
|
|
2073
|
-
case "float32":
|
|
2074
|
-
return Float32Array;
|
|
2075
|
-
case "uint8":
|
|
2076
|
-
return Uint8Array;
|
|
2077
|
-
case "int8":
|
|
2078
|
-
return Int8Array;
|
|
2079
|
-
case "uint16":
|
|
2080
|
-
return Uint16Array;
|
|
2081
|
-
case "int16":
|
|
2082
|
-
return Int16Array;
|
|
2083
|
-
case "int32":
|
|
2084
|
-
return Int32Array;
|
|
2085
|
-
case "bool":
|
|
2086
|
-
return Uint8Array;
|
|
2087
|
-
case "float64":
|
|
2088
|
-
return Float64Array;
|
|
2089
|
-
case "uint32":
|
|
2090
|
-
return Uint32Array;
|
|
2091
|
-
case "int64":
|
|
2092
|
-
return BigInt64Array;
|
|
2093
|
-
case "uint64":
|
|
2094
|
-
return BigUint64Array;
|
|
2095
|
-
default:
|
|
2096
|
-
throw new Error(`unsupported type: ${e}`);
|
|
2097
|
-
}
|
|
2098
|
-
}, je = (e) => {
|
|
2099
|
-
switch (e) {
|
|
2100
|
-
case "verbose":
|
|
2101
|
-
return 0;
|
|
2102
|
-
case "info":
|
|
2103
|
-
return 1;
|
|
2104
|
-
case "warning":
|
|
2105
|
-
return 2;
|
|
2106
|
-
case "error":
|
|
2107
|
-
return 3;
|
|
2108
|
-
case "fatal":
|
|
2109
|
-
return 4;
|
|
2110
|
-
default:
|
|
2111
|
-
throw new Error(`unsupported logging level: ${e}`);
|
|
2112
|
-
}
|
|
2113
|
-
}, ie = (e) => e === "float32" || e === "float16" || e === "int32" || e === "int64" || e === "uint32" || e === "uint8" || e === "bool" || e === "uint4" || e === "int4", ue = (e) => e === "float32" || e === "float16" || e === "int32" || e === "int64" || e === "uint32" || e === "uint64" || e === "int8" || e === "uint8" || e === "bool" || e === "uint4" || e === "int4", $e = (e) => {
|
|
2114
|
-
switch (e) {
|
|
2115
|
-
case "none":
|
|
2116
|
-
return 0;
|
|
2117
|
-
case "cpu":
|
|
2118
|
-
return 1;
|
|
2119
|
-
case "cpu-pinned":
|
|
2120
|
-
return 2;
|
|
2121
|
-
case "texture":
|
|
2122
|
-
return 3;
|
|
2123
|
-
case "gpu-buffer":
|
|
2124
|
-
return 4;
|
|
2125
|
-
case "ml-tensor":
|
|
2126
|
-
return 5;
|
|
2127
|
-
default:
|
|
2128
|
-
throw new Error(`unsupported data location: ${e}`);
|
|
2129
|
-
}
|
|
2130
|
-
};
|
|
2131
|
-
});
|
|
2132
|
-
ye = C(() => {
|
|
2133
|
-
re();
|
|
2134
|
-
Q = async (e) => {
|
|
2135
|
-
if (typeof e == "string")
|
|
2136
|
-
if (j)
|
|
2137
|
-
try {
|
|
2138
|
-
let { readFile: t } = de("node:fs/promises");
|
|
2139
|
-
return new Uint8Array(await t(e));
|
|
2140
|
-
} catch (t) {
|
|
2141
|
-
if (t.code === "ERR_FS_FILE_TOO_LARGE") {
|
|
2142
|
-
let { createReadStream: n } = de("node:fs"), o = n(e), r = [];
|
|
2143
|
-
for await (let a of o)
|
|
2144
|
-
r.push(a);
|
|
2145
|
-
return new Uint8Array(Buffer.concat(r));
|
|
2146
|
-
}
|
|
2147
|
-
throw t;
|
|
2148
|
-
}
|
|
2149
|
-
else {
|
|
2150
|
-
let t = await fetch(e);
|
|
2151
|
-
if (!t.ok)
|
|
2152
|
-
throw new Error(`failed to load external data file: ${e}`);
|
|
2153
|
-
let n = t.headers.get("Content-Length"), o = n ? parseInt(n, 10) : 0;
|
|
2154
|
-
if (o < 1073741824)
|
|
2155
|
-
return new Uint8Array(await t.arrayBuffer());
|
|
2156
|
-
{
|
|
2157
|
-
if (!t.body)
|
|
2158
|
-
throw new Error(`failed to load external data file: ${e}, no response body.`);
|
|
2159
|
-
let r = t.body.getReader(), a;
|
|
2160
|
-
try {
|
|
2161
|
-
a = new ArrayBuffer(o);
|
|
2162
|
-
} catch (i) {
|
|
2163
|
-
if (i instanceof RangeError) {
|
|
2164
|
-
let u = Math.ceil(o / 65536);
|
|
2165
|
-
a = new WebAssembly.Memory({ initial: u, maximum: u }).buffer;
|
|
2166
|
-
} else
|
|
2167
|
-
throw i;
|
|
2168
|
-
}
|
|
2169
|
-
let s = 0;
|
|
2170
|
-
for (;; ) {
|
|
2171
|
-
let { done: i, value: u } = await r.read();
|
|
2172
|
-
if (i)
|
|
2173
|
-
break;
|
|
2174
|
-
let f = u.byteLength;
|
|
2175
|
-
new Uint8Array(a, s, f).set(u), s += f;
|
|
2176
|
-
}
|
|
2177
|
-
return new Uint8Array(a, 0, o);
|
|
2178
|
-
}
|
|
2179
|
-
}
|
|
2180
|
-
else
|
|
2181
|
-
return e instanceof Blob ? new Uint8Array(await e.arrayBuffer()) : e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
2182
|
-
};
|
|
2183
|
-
});
|
|
2184
|
-
et = C(() => {
|
|
2185
|
-
ke();
|
|
2186
|
-
Ne();
|
|
2187
|
-
ge();
|
|
2188
|
-
V();
|
|
2189
|
-
oe();
|
|
2190
|
-
ye();
|
|
2191
|
-
kt = (e, t) => {
|
|
2192
|
-
E()._OrtInit(e, t) !== 0 && g("Can't initialize onnxruntime.");
|
|
2193
|
-
}, qe = async (e) => {
|
|
2194
|
-
kt(e.wasm.numThreads, je(e.logLevel));
|
|
2195
|
-
}, Ye = async (e, t) => {
|
|
2196
|
-
E().asyncInit?.();
|
|
2197
|
-
let n = e.webgpu.adapter;
|
|
2198
|
-
if (t === "webgpu") {
|
|
2199
|
-
if (typeof navigator > "u" || !navigator.gpu)
|
|
2200
|
-
throw new Error("WebGPU is not supported in current environment");
|
|
2201
|
-
if (n) {
|
|
2202
|
-
if (typeof n.limits != "object" || typeof n.features != "object" || typeof n.requestDevice != "function")
|
|
2203
|
-
throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.");
|
|
2204
|
-
} else {
|
|
2205
|
-
let o = e.webgpu.powerPreference;
|
|
2206
|
-
if (o !== undefined && o !== "low-power" && o !== "high-performance")
|
|
2207
|
-
throw new Error(`Invalid powerPreference setting: "${o}"`);
|
|
2208
|
-
let r = e.webgpu.forceFallbackAdapter;
|
|
2209
|
-
if (r !== undefined && typeof r != "boolean")
|
|
2210
|
-
throw new Error(`Invalid forceFallbackAdapter setting: "${r}"`);
|
|
2211
|
-
if (n = await navigator.gpu.requestAdapter({ powerPreference: o, forceFallbackAdapter: r }), !n)
|
|
2212
|
-
throw new Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.');
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
if (t === "webnn" && (typeof navigator > "u" || !navigator.ml))
|
|
2216
|
-
throw new Error("WebNN is not supported in current environment");
|
|
2217
|
-
}, Y = new Map, Rt = (e) => {
|
|
2218
|
-
let t = E(), n = t.stackSave();
|
|
2219
|
-
try {
|
|
2220
|
-
let o = t.PTR_SIZE, r = t.stackAlloc(2 * o);
|
|
2221
|
-
t._OrtGetInputOutputCount(e, r, r + o) !== 0 && g("Can't get session input/output count.");
|
|
2222
|
-
let s = o === 4 ? "i32" : "i64";
|
|
2223
|
-
return [Number(t.getValue(r, s)), Number(t.getValue(r + o, s))];
|
|
2224
|
-
} finally {
|
|
2225
|
-
t.stackRestore(n);
|
|
2226
|
-
}
|
|
2227
|
-
}, Ve = (e, t) => {
|
|
2228
|
-
let n = E(), o = n.stackSave(), r = 0;
|
|
2229
|
-
try {
|
|
2230
|
-
let a = n.PTR_SIZE, s = n.stackAlloc(2 * a);
|
|
2231
|
-
n._OrtGetInputOutputMetadata(e, t, s, s + a) !== 0 && g("Can't get session input/output metadata.");
|
|
2232
|
-
let u = Number(n.getValue(s, "*"));
|
|
2233
|
-
r = Number(n.getValue(s + a, "*"));
|
|
2234
|
-
let f = n.HEAP32[r / 4];
|
|
2235
|
-
if (f === 0)
|
|
2236
|
-
return [u, 0];
|
|
2237
|
-
let w = n.HEAPU32[r / 4 + 1], l = [];
|
|
2238
|
-
for (let c = 0;c < w; c++) {
|
|
2239
|
-
let p = Number(n.getValue(r + 8 + c * a, "*"));
|
|
2240
|
-
l.push(p !== 0 ? n.UTF8ToString(p) : Number(n.getValue(r + 8 + (c + w) * a, "*")));
|
|
2241
|
-
}
|
|
2242
|
-
return [u, f, l];
|
|
2243
|
-
} finally {
|
|
2244
|
-
n.stackRestore(o), r !== 0 && n._OrtFree(r);
|
|
2245
|
-
}
|
|
2246
|
-
}, Ee = (e) => {
|
|
2247
|
-
let t = E(), n = t._malloc(e.byteLength);
|
|
2248
|
-
if (n === 0)
|
|
2249
|
-
throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);
|
|
2250
|
-
return t.HEAPU8.set(e, n), [n, e.byteLength];
|
|
2251
|
-
}, Ze = async (e, t) => {
|
|
2252
|
-
let n, o, r = E();
|
|
2253
|
-
Array.isArray(e) ? [n, o] = e : e.buffer === r.HEAPU8.buffer ? [n, o] = [e.byteOffset, e.byteLength] : [n, o] = Ee(e);
|
|
2254
|
-
let a = 0, s = 0, i = 0, u = [], f = [], w = [];
|
|
2255
|
-
try {
|
|
2256
|
-
if ([s, u] = await Re(t), t?.externalData && r.mountExternalData) {
|
|
2257
|
-
let y = [];
|
|
2258
|
-
for (let O of t.externalData) {
|
|
2259
|
-
let B = typeof O == "string" ? O : O.path;
|
|
2260
|
-
y.push(Q(typeof O == "string" ? O : O.data).then((U) => {
|
|
2261
|
-
r.mountExternalData(B, U);
|
|
2262
|
-
}));
|
|
2263
|
-
}
|
|
2264
|
-
await Promise.all(y);
|
|
2265
|
-
}
|
|
2266
|
-
for (let y of t?.executionProviders ?? [])
|
|
2267
|
-
if ((typeof y == "string" ? y : y.name) === "webnn") {
|
|
2268
|
-
if (r.shouldTransferToMLTensor = false, typeof y != "string") {
|
|
2269
|
-
let B = y, U = B?.context, _ = B?.gpuDevice, Z = B?.deviceType, z = B?.powerPreference;
|
|
2270
|
-
U ? r.currentContext = U : _ ? r.currentContext = await r.webnnCreateMLContext(_) : r.currentContext = await r.webnnCreateMLContext({ deviceType: Z, powerPreference: z });
|
|
2271
|
-
} else
|
|
2272
|
-
r.currentContext = await r.webnnCreateMLContext();
|
|
2273
|
-
break;
|
|
2274
|
-
}
|
|
2275
|
-
a = await r._OrtCreateSession(n, o, s), r.webgpuOnCreateSession?.(a), a === 0 && g("Can't create a session."), r.jsepOnCreateSession?.(), r.currentContext && (r.webnnRegisterMLContext(a, r.currentContext), r.currentContext = undefined, r.shouldTransferToMLTensor = true);
|
|
2276
|
-
let [l, c] = Rt(a), p = !!t?.enableGraphCapture, S = [], h = [], v = [], m = [], b = [];
|
|
2277
|
-
for (let y = 0;y < l; y++) {
|
|
2278
|
-
let [O, B, U] = Ve(a, y);
|
|
2279
|
-
O === 0 && g("Can't get an input name."), f.push(O);
|
|
2280
|
-
let _ = r.UTF8ToString(O);
|
|
2281
|
-
S.push(_), v.push(B === 0 ? { name: _, isTensor: false } : { name: _, isTensor: true, type: ae(B), shape: U });
|
|
2282
|
-
}
|
|
2283
|
-
for (let y = 0;y < c; y++) {
|
|
2284
|
-
let [O, B, U] = Ve(a, y + l);
|
|
2285
|
-
O === 0 && g("Can't get an output name."), w.push(O);
|
|
2286
|
-
let _ = r.UTF8ToString(O);
|
|
2287
|
-
h.push(_), m.push(B === 0 ? { name: _, isTensor: false } : { name: _, isTensor: true, type: ae(B), shape: U });
|
|
2288
|
-
}
|
|
2289
|
-
return Y.set(a, [a, f, w, null, p, false]), [a, S, h, v, m];
|
|
2290
|
-
} catch (l) {
|
|
2291
|
-
throw f.forEach((c) => r._OrtFree(c)), w.forEach((c) => r._OrtFree(c)), i !== 0 && r._OrtReleaseBinding(i) !== 0 && g("Can't release IO binding."), a !== 0 && r._OrtReleaseSession(a) !== 0 && g("Can't release session."), l;
|
|
2292
|
-
} finally {
|
|
2293
|
-
r._free(n), s !== 0 && r._OrtReleaseSessionOptions(s) !== 0 && g("Can't release session options."), u.forEach((l) => r._free(l)), r.unmountExternalData?.();
|
|
2294
|
-
}
|
|
2295
|
-
}, Xe = (e) => {
|
|
2296
|
-
let t = E(), n = Y.get(e);
|
|
2297
|
-
if (!n)
|
|
2298
|
-
throw new Error(`cannot release session. invalid session id: ${e}`);
|
|
2299
|
-
let [o, r, a, s, i] = n;
|
|
2300
|
-
s && (i && t._OrtClearBoundOutputs(s.handle) !== 0 && g("Can't clear bound outputs."), t._OrtReleaseBinding(s.handle) !== 0 && g("Can't release IO binding.")), t.jsepOnReleaseSession?.(e), t.webnnOnReleaseSession?.(e), t.webgpuOnReleaseSession?.(e), r.forEach((u) => t._OrtFree(u)), a.forEach((u) => t._OrtFree(u)), t._OrtReleaseSession(o) !== 0 && g("Can't release session."), Y.delete(e);
|
|
2301
|
-
}, Je = async (e, t, n, o, r, a, s = false) => {
|
|
2302
|
-
if (!e) {
|
|
2303
|
-
t.push(0);
|
|
2304
|
-
return;
|
|
2305
|
-
}
|
|
2306
|
-
let i = E(), u = i.PTR_SIZE, f = e[0], w = e[1], l = e[3], c = l, p, S;
|
|
2307
|
-
if (f === "string" && (l === "gpu-buffer" || l === "ml-tensor"))
|
|
2308
|
-
throw new Error("String tensor is not supported on GPU.");
|
|
2309
|
-
if (s && l !== "gpu-buffer")
|
|
2310
|
-
throw new Error(`External buffer must be provided for input/output index ${a} when enableGraphCapture is true.`);
|
|
2311
|
-
if (l === "gpu-buffer") {
|
|
2312
|
-
let m = e[2].gpuBuffer;
|
|
2313
|
-
S = q(J(f), w);
|
|
2314
|
-
{
|
|
2315
|
-
let b = i.jsepRegisterBuffer;
|
|
2316
|
-
if (!b)
|
|
2317
|
-
throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');
|
|
2318
|
-
p = b(o, a, m, S);
|
|
2319
|
-
}
|
|
2320
|
-
} else if (l === "ml-tensor") {
|
|
2321
|
-
let m = e[2].mlTensor;
|
|
2322
|
-
S = q(J(f), w);
|
|
2323
|
-
let b = i.webnnRegisterMLTensor;
|
|
2324
|
-
if (!b)
|
|
2325
|
-
throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
|
|
2326
|
-
p = b(o, m, J(f), w);
|
|
2327
|
-
} else {
|
|
2328
|
-
let m = e[2];
|
|
2329
|
-
if (Array.isArray(m)) {
|
|
2330
|
-
S = u * m.length, p = i._malloc(S), n.push(p);
|
|
2331
|
-
for (let b = 0;b < m.length; b++) {
|
|
2332
|
-
if (typeof m[b] != "string")
|
|
2333
|
-
throw new TypeError(`tensor data at index ${b} is not a string`);
|
|
2334
|
-
i.setValue(p + b * u, A(m[b], n), "*");
|
|
2335
|
-
}
|
|
2336
|
-
} else {
|
|
2337
|
-
let { webnnIsGraphInput: b, webnnIsGraphOutput: M } = i;
|
|
2338
|
-
if (f !== "string" && b && M) {
|
|
2339
|
-
let y = i.UTF8ToString(r);
|
|
2340
|
-
if (b(o, y) || M(o, y)) {
|
|
2341
|
-
let O = J(f);
|
|
2342
|
-
S = q(O, w), c = "ml-tensor";
|
|
2343
|
-
let { webnnCreateTemporaryTensor: B, webnnUploadTensor: U } = i;
|
|
2344
|
-
if (!B || !U)
|
|
2345
|
-
throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
|
|
2346
|
-
let _ = await B(o, O, w);
|
|
2347
|
-
U(_, new Uint8Array(m.buffer, m.byteOffset, m.byteLength)), p = _;
|
|
2348
|
-
} else
|
|
2349
|
-
S = m.byteLength, p = i._malloc(S), n.push(p), i.HEAPU8.set(new Uint8Array(m.buffer, m.byteOffset, S), p);
|
|
2350
|
-
} else
|
|
2351
|
-
S = m.byteLength, p = i._malloc(S), n.push(p), i.HEAPU8.set(new Uint8Array(m.buffer, m.byteOffset, S), p);
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
let h = i.stackSave(), v = i.stackAlloc(4 * w.length);
|
|
2355
|
-
try {
|
|
2356
|
-
w.forEach((b, M) => i.setValue(v + M * u, b, u === 4 ? "i32" : "i64"));
|
|
2357
|
-
let m = i._OrtCreateTensor(J(f), p, S, v, w.length, $e(c));
|
|
2358
|
-
m === 0 && g(`Can't create tensor for input/output. session=${o}, index=${a}.`), t.push(m);
|
|
2359
|
-
} finally {
|
|
2360
|
-
i.stackRestore(h);
|
|
2361
|
-
}
|
|
2362
|
-
}, Ke = async (e, t, n, o, r, a) => {
|
|
2363
|
-
let s = E(), i = s.PTR_SIZE, u = Y.get(e);
|
|
2364
|
-
if (!u)
|
|
2365
|
-
throw new Error(`cannot run inference. invalid session id: ${e}`);
|
|
2366
|
-
let f = u[0], w = u[1], l = u[2], c = u[3], p = u[4], S = u[5], h = t.length, v = o.length, m = 0, b = [], M = [], y = [], O = [], B = [], U = s.stackSave(), _ = s.stackAlloc(h * i), Z = s.stackAlloc(h * i), z = s.stackAlloc(v * i), Te = s.stackAlloc(v * i);
|
|
2367
|
-
try {
|
|
2368
|
-
[m, b] = Fe(a), TRACE_EVENT_BEGIN("wasm prepareInputOutputTensor");
|
|
2369
|
-
for (let d = 0;d < h; d++)
|
|
2370
|
-
await Je(n[d], M, O, e, w[t[d]], t[d], p);
|
|
2371
|
-
for (let d = 0;d < v; d++)
|
|
2372
|
-
await Je(r[d], y, O, e, l[o[d]], h + o[d], p);
|
|
2373
|
-
TRACE_EVENT_END("wasm prepareInputOutputTensor");
|
|
2374
|
-
for (let d = 0;d < h; d++)
|
|
2375
|
-
s.setValue(_ + d * i, M[d], "*"), s.setValue(Z + d * i, w[t[d]], "*");
|
|
2376
|
-
for (let d = 0;d < v; d++)
|
|
2377
|
-
s.setValue(z + d * i, y[d], "*"), s.setValue(Te + d * i, l[o[d]], "*");
|
|
2378
|
-
s.jsepOnRunStart?.(f), s.webnnOnRunStart?.(f);
|
|
2379
|
-
let x;
|
|
2380
|
-
x = await s._OrtRun(f, Z, _, h, Te, v, z, m), x !== 0 && g("failed to call OrtRun().");
|
|
2381
|
-
let k = [], Le = [];
|
|
2382
|
-
TRACE_EVENT_BEGIN("wasm ProcessOutputTensor");
|
|
2383
|
-
for (let d = 0;d < v; d++) {
|
|
2384
|
-
let W = Number(s.getValue(z + d * i, "*"));
|
|
2385
|
-
if (W === y[d] || B.includes(y[d])) {
|
|
2386
|
-
k.push(r[d]), W !== y[d] && s._OrtReleaseTensor(W) !== 0 && g("Can't release tensor.");
|
|
2387
|
-
continue;
|
|
2388
|
-
}
|
|
2389
|
-
let Be = s.stackSave(), F = s.stackAlloc(4 * i), H = false, T, P = 0;
|
|
2390
|
-
try {
|
|
2391
|
-
s._OrtGetTensorData(W, F, F + i, F + 2 * i, F + 3 * i) !== 0 && g(`Can't access output tensor data on index ${d}.`);
|
|
2392
|
-
let fe = i === 4 ? "i32" : "i64", ee = Number(s.getValue(F, fe));
|
|
2393
|
-
P = s.getValue(F + i, "*");
|
|
2394
|
-
let _e = s.getValue(F + i * 2, "*"), yt = Number(s.getValue(F + i * 3, fe)), R = [];
|
|
2395
|
-
for (let L = 0;L < yt; L++)
|
|
2396
|
-
R.push(Number(s.getValue(_e + L * i, fe)));
|
|
2397
|
-
s._OrtFree(_e) !== 0 && g("Can't free memory for tensor dims.");
|
|
2398
|
-
let N = R.reduce((L, I) => L * I, 1);
|
|
2399
|
-
T = ae(ee);
|
|
2400
|
-
let X = c?.outputPreferredLocations[o[d]];
|
|
2401
|
-
if (T === "string") {
|
|
2402
|
-
if (X === "gpu-buffer" || X === "ml-tensor")
|
|
2403
|
-
throw new Error("String tensor is not supported on GPU.");
|
|
2404
|
-
let L = [];
|
|
2405
|
-
for (let I = 0;I < N; I++) {
|
|
2406
|
-
let G = s.getValue(P + I * i, "*"), te = s.getValue(P + (I + 1) * i, "*"), Pe = I === N - 1 ? undefined : te - G;
|
|
2407
|
-
L.push(s.UTF8ToString(G, Pe));
|
|
2408
|
-
}
|
|
2409
|
-
k.push([T, R, L, "cpu"]);
|
|
2410
|
-
} else if (X === "gpu-buffer" && N > 0) {
|
|
2411
|
-
let L = s.jsepGetBuffer;
|
|
2412
|
-
if (!L)
|
|
2413
|
-
throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');
|
|
2414
|
-
let I = L(P), G = q(ee, N);
|
|
2415
|
-
if (G === undefined || !ie(T))
|
|
2416
|
-
throw new Error(`Unsupported data type: ${T}`);
|
|
2417
|
-
H = true, k.push([T, R, { gpuBuffer: I, download: s.jsepCreateDownloader(I, G, T), dispose: () => {
|
|
2418
|
-
s._OrtReleaseTensor(W) !== 0 && g("Can't release tensor.");
|
|
2419
|
-
} }, "gpu-buffer"]);
|
|
2420
|
-
} else if (X === "ml-tensor" && N > 0) {
|
|
2421
|
-
let { webnnEnsureTensor: L, webnnIsGraphInputOutputTypeSupported: I } = s;
|
|
2422
|
-
if (!L || !I)
|
|
2423
|
-
throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');
|
|
2424
|
-
if (q(ee, N) === undefined || !ue(T))
|
|
2425
|
-
throw new Error(`Unsupported data type: ${T}`);
|
|
2426
|
-
if (!I(e, T, false))
|
|
2427
|
-
throw new Error(`preferredLocation "ml-tensor" for ${T} output is not supported by current WebNN Context.`);
|
|
2428
|
-
let te = await L(e, P, ee, R, false);
|
|
2429
|
-
H = true, k.push([T, R, { mlTensor: te, download: s.webnnCreateMLTensorDownloader(P, T), dispose: () => {
|
|
2430
|
-
s.webnnReleaseTensorId(P), s._OrtReleaseTensor(W);
|
|
2431
|
-
} }, "ml-tensor"]);
|
|
2432
|
-
} else if (X === "ml-tensor-cpu-output" && N > 0) {
|
|
2433
|
-
let L = s.webnnCreateMLTensorDownloader(P, T)(), I = k.length;
|
|
2434
|
-
H = true, Le.push((async () => {
|
|
2435
|
-
let G = [I, await L];
|
|
2436
|
-
return s.webnnReleaseTensorId(P), s._OrtReleaseTensor(W), G;
|
|
2437
|
-
})()), k.push([T, R, [], "cpu"]);
|
|
2438
|
-
} else {
|
|
2439
|
-
let L = Ge(T), I = new L(N);
|
|
2440
|
-
new Uint8Array(I.buffer, I.byteOffset, I.byteLength).set(s.HEAPU8.subarray(P, P + I.byteLength)), k.push([T, R, I, "cpu"]);
|
|
2441
|
-
}
|
|
2442
|
-
} finally {
|
|
2443
|
-
s.stackRestore(Be), T === "string" && P && s._free(P), H || s._OrtReleaseTensor(W);
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
c && !p && (s._OrtClearBoundOutputs(c.handle) !== 0 && g("Can't clear bound outputs."), Y.set(e, [f, w, l, c, p, false]));
|
|
2447
|
-
for (let [d, W] of await Promise.all(Le))
|
|
2448
|
-
k[d][2] = W;
|
|
2449
|
-
return TRACE_EVENT_END("wasm ProcessOutputTensor"), k;
|
|
2450
|
-
} finally {
|
|
2451
|
-
s.webnnOnRunEnd?.(f), s.stackRestore(U), M.forEach((x) => s._OrtReleaseTensor(x)), y.forEach((x) => s._OrtReleaseTensor(x)), O.forEach((x) => s._free(x)), m !== 0 && s._OrtReleaseRunOptions(m), b.forEach((x) => s._free(x));
|
|
2452
|
-
}
|
|
2453
|
-
}, Qe = (e) => {
|
|
2454
|
-
let t = E(), n = Y.get(e);
|
|
2455
|
-
if (!n)
|
|
2456
|
-
throw new Error("invalid session id");
|
|
2457
|
-
let o = n[0], r = t._OrtEndProfiling(o);
|
|
2458
|
-
r === 0 && g("Can't get an profile file name."), t._OrtFree(r);
|
|
2459
|
-
};
|
|
2460
|
-
});
|
|
2461
|
-
Oe = C(() => {
|
|
2462
|
-
et();
|
|
2463
|
-
V();
|
|
2464
|
-
me();
|
|
2465
|
-
Se = false, tt = false, rt = false, nt = async () => {
|
|
2466
|
-
if (!tt) {
|
|
2467
|
-
if (Se)
|
|
2468
|
-
throw new Error("multiple calls to 'initWasm()' detected.");
|
|
2469
|
-
if (rt)
|
|
2470
|
-
throw new Error("previous call to 'initWasm()' failed.");
|
|
2471
|
-
Se = true;
|
|
2472
|
-
try {
|
|
2473
|
-
await We(env2.wasm), await qe(env2), tt = true;
|
|
2474
|
-
} catch (e) {
|
|
2475
|
-
throw rt = true, e;
|
|
2476
|
-
} finally {
|
|
2477
|
-
Se = false;
|
|
2478
|
-
}
|
|
2479
|
-
}
|
|
2480
|
-
}, ot = async (e) => {
|
|
2481
|
-
await Ye(env2, e);
|
|
2482
|
-
}, st = async (e) => Ee(e), at = async (e, t) => Ze(e, t), it = async (e) => {
|
|
2483
|
-
Xe(e);
|
|
2484
|
-
}, ut = async (e, t, n, o, r, a) => Ke(e, t, n, o, r, a), ct = async (e) => {
|
|
2485
|
-
Qe(e);
|
|
2486
|
-
};
|
|
2487
|
-
});
|
|
2488
|
-
dt = C(() => {
|
|
2489
|
-
Oe();
|
|
2490
|
-
ge();
|
|
2491
|
-
re();
|
|
2492
|
-
ye();
|
|
2493
|
-
pt = (e, t) => {
|
|
2494
|
-
switch (e.location) {
|
|
2495
|
-
case "cpu":
|
|
2496
|
-
return [e.type, e.dims, e.data, "cpu"];
|
|
2497
|
-
case "gpu-buffer":
|
|
2498
|
-
return [e.type, e.dims, { gpuBuffer: e.gpuBuffer }, "gpu-buffer"];
|
|
2499
|
-
case "ml-tensor":
|
|
2500
|
-
return [e.type, e.dims, { mlTensor: e.mlTensor }, "ml-tensor"];
|
|
2501
|
-
default:
|
|
2502
|
-
throw new Error(`invalid data location: ${e.location} for ${t()}`);
|
|
2503
|
-
}
|
|
2504
|
-
}, Gt = (e) => {
|
|
2505
|
-
switch (e[3]) {
|
|
2506
|
-
case "cpu":
|
|
2507
|
-
return new Tensor2(e[0], e[2], e[1]);
|
|
2508
|
-
case "gpu-buffer": {
|
|
2509
|
-
let t = e[0];
|
|
2510
|
-
if (!ie(t))
|
|
2511
|
-
throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);
|
|
2512
|
-
let { gpuBuffer: n, download: o, dispose: r } = e[2];
|
|
2513
|
-
return Tensor2.fromGpuBuffer(n, { dataType: t, dims: e[1], download: o, dispose: r });
|
|
2514
|
-
}
|
|
2515
|
-
case "ml-tensor": {
|
|
2516
|
-
let t = e[0];
|
|
2517
|
-
if (!ue(t))
|
|
2518
|
-
throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);
|
|
2519
|
-
let { mlTensor: n, download: o, dispose: r } = e[2];
|
|
2520
|
-
return Tensor2.fromMLTensor(n, { dataType: t, dims: e[1], download: o, dispose: r });
|
|
2521
|
-
}
|
|
2522
|
-
default:
|
|
2523
|
-
throw new Error(`invalid data location: ${e[3]}`);
|
|
2524
|
-
}
|
|
2525
|
-
}, ce = class {
|
|
2526
|
-
async fetchModelAndCopyToWasmMemory(t) {
|
|
2527
|
-
return st(await Q(t));
|
|
2528
|
-
}
|
|
2529
|
-
async loadModel(t, n) {
|
|
2530
|
-
TRACE_FUNC_BEGIN();
|
|
2531
|
-
let o;
|
|
2532
|
-
typeof t == "string" ? j ? o = await Q(t) : o = await this.fetchModelAndCopyToWasmMemory(t) : o = t, [this.sessionId, this.inputNames, this.outputNames, this.inputMetadata, this.outputMetadata] = await at(o, n), TRACE_FUNC_END();
|
|
2533
|
-
}
|
|
2534
|
-
async dispose() {
|
|
2535
|
-
return it(this.sessionId);
|
|
2536
|
-
}
|
|
2537
|
-
async run(t, n, o) {
|
|
2538
|
-
TRACE_FUNC_BEGIN();
|
|
2539
|
-
let r = [], a = [];
|
|
2540
|
-
Object.entries(t).forEach((c) => {
|
|
2541
|
-
let p = c[0], S = c[1], h = this.inputNames.indexOf(p);
|
|
2542
|
-
if (h === -1)
|
|
2543
|
-
throw new Error(`invalid input '${p}'`);
|
|
2544
|
-
r.push(S), a.push(h);
|
|
2545
|
-
});
|
|
2546
|
-
let s = [], i = [];
|
|
2547
|
-
Object.entries(n).forEach((c) => {
|
|
2548
|
-
let p = c[0], S = c[1], h = this.outputNames.indexOf(p);
|
|
2549
|
-
if (h === -1)
|
|
2550
|
-
throw new Error(`invalid output '${p}'`);
|
|
2551
|
-
s.push(S), i.push(h);
|
|
2552
|
-
});
|
|
2553
|
-
let u = r.map((c, p) => pt(c, () => `input "${this.inputNames[a[p]]}"`)), f = s.map((c, p) => c ? pt(c, () => `output "${this.outputNames[i[p]]}"`) : null), w = await ut(this.sessionId, a, u, i, f, o), l = {};
|
|
2554
|
-
for (let c = 0;c < w.length; c++)
|
|
2555
|
-
l[this.outputNames[i[c]]] = s[c] ?? Gt(w[c]);
|
|
2556
|
-
return TRACE_FUNC_END(), l;
|
|
2557
|
-
}
|
|
2558
|
-
startProfiling() {}
|
|
2559
|
-
endProfiling() {
|
|
2560
|
-
ct(this.sessionId);
|
|
2561
|
-
}
|
|
2562
|
-
};
|
|
2563
|
-
});
|
|
2564
|
-
bt = {};
|
|
2565
|
-
Ot(bt, { OnnxruntimeWebAssemblyBackend: () => le, initializeFlags: () => mt, wasmBackend: () => jt });
|
|
2566
|
-
wt = C(() => {
|
|
2567
|
-
Oe();
|
|
2568
|
-
dt();
|
|
2569
|
-
mt = () => {
|
|
2570
|
-
(typeof env2.wasm.initTimeout != "number" || env2.wasm.initTimeout < 0) && (env2.wasm.initTimeout = 0);
|
|
2571
|
-
let e = env2.wasm.simd;
|
|
2572
|
-
if (typeof e != "boolean" && e !== undefined && e !== "fixed" && e !== "relaxed" && (console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`), env2.wasm.simd = false), typeof env2.wasm.proxy != "boolean" && (env2.wasm.proxy = false), typeof env2.wasm.trace != "boolean" && (env2.wasm.trace = false), typeof env2.wasm.numThreads != "number" || !Number.isInteger(env2.wasm.numThreads) || env2.wasm.numThreads <= 0)
|
|
2573
|
-
if (typeof self < "u" && !self.crossOriginIsolated)
|
|
2574
|
-
env2.wasm.numThreads = 1;
|
|
2575
|
-
else {
|
|
2576
|
-
let t = typeof navigator > "u" ? de("node:os").cpus().length : navigator.hardwareConcurrency;
|
|
2577
|
-
env2.wasm.numThreads = Math.min(4, Math.ceil((t || 1) / 2));
|
|
2578
|
-
}
|
|
2579
|
-
}, le = class {
|
|
2580
|
-
async init(t) {
|
|
2581
|
-
mt(), await nt(), await ot(t);
|
|
2582
|
-
}
|
|
2583
|
-
async createInferenceSessionHandler(t, n) {
|
|
2584
|
-
let o = new ce;
|
|
2585
|
-
return await o.loadModel(t, n), o;
|
|
2586
|
-
}
|
|
2587
|
-
}, jt = new le;
|
|
2588
|
-
});
|
|
2589
|
-
Hr = exports_esm;
|
|
2590
|
-
{
|
|
2591
|
-
let e = (wt(), Tt(bt)).wasmBackend;
|
|
2592
|
-
registerBackend("cpu", e, 10), registerBackend("wasm", e, 10);
|
|
2593
|
-
}
|
|
2594
|
-
Object.defineProperty(env2.versions, "web", { value: ve, enumerable: true });
|
|
2595
|
-
});
|
|
2596
|
-
|
|
2597
517
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/cjs/backend-impl.js
|
|
2598
518
|
var require_backend_impl = __commonJS(function(exports) {
|
|
2599
519
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -4056,27 +1976,27 @@ var require_dist = __commonJS(function(exports) {
|
|
|
4056
1976
|
});
|
|
4057
1977
|
|
|
4058
1978
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/backend-impl.js
|
|
4059
|
-
var
|
|
4060
|
-
var
|
|
4061
|
-
|
|
1979
|
+
var backends;
|
|
1980
|
+
var init_backend_impl = __esm(() => {
|
|
1981
|
+
backends = new Map;
|
|
4062
1982
|
});
|
|
4063
1983
|
|
|
4064
1984
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/backend.js
|
|
4065
|
-
var
|
|
4066
|
-
|
|
1985
|
+
var init_backend = __esm(() => {
|
|
1986
|
+
init_backend_impl();
|
|
4067
1987
|
});
|
|
4068
1988
|
|
|
4069
1989
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/version.js
|
|
4070
|
-
var
|
|
1990
|
+
var version2 = "1.24.3";
|
|
4071
1991
|
|
|
4072
1992
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/env-impl.js
|
|
4073
|
-
var
|
|
4074
|
-
var
|
|
4075
|
-
|
|
1993
|
+
var logLevelValue = "warning", env;
|
|
1994
|
+
var init_env_impl = __esm(() => {
|
|
1995
|
+
env = {
|
|
4076
1996
|
wasm: {},
|
|
4077
1997
|
webgl: {},
|
|
4078
1998
|
webgpu: {},
|
|
4079
|
-
versions: { common:
|
|
1999
|
+
versions: { common: version2 },
|
|
4080
2000
|
set logLevel(value) {
|
|
4081
2001
|
if (value === undefined) {
|
|
4082
2002
|
return;
|
|
@@ -4084,22 +2004,22 @@ var init_env_impl2 = __esm(() => {
|
|
|
4084
2004
|
if (typeof value !== "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(value) === -1) {
|
|
4085
2005
|
throw new Error(`Unsupported logging level: ${value}`);
|
|
4086
2006
|
}
|
|
4087
|
-
|
|
2007
|
+
logLevelValue = value;
|
|
4088
2008
|
},
|
|
4089
2009
|
get logLevel() {
|
|
4090
|
-
return
|
|
2010
|
+
return logLevelValue;
|
|
4091
2011
|
}
|
|
4092
2012
|
};
|
|
4093
|
-
Object.defineProperty(
|
|
2013
|
+
Object.defineProperty(env, "logLevel", { enumerable: true });
|
|
4094
2014
|
});
|
|
4095
2015
|
|
|
4096
2016
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/env.js
|
|
4097
|
-
var
|
|
4098
|
-
|
|
2017
|
+
var init_env = __esm(() => {
|
|
2018
|
+
init_env_impl();
|
|
4099
2019
|
});
|
|
4100
2020
|
|
|
4101
2021
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js
|
|
4102
|
-
var
|
|
2022
|
+
var tensorToDataURL = (tensor, options) => {
|
|
4103
2023
|
const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
4104
2024
|
canvas.width = tensor.dims[3];
|
|
4105
2025
|
canvas.height = tensor.dims[2];
|
|
@@ -4176,7 +2096,7 @@ var tensorToDataURL2 = (tensor, options) => {
|
|
|
4176
2096
|
} else {
|
|
4177
2097
|
throw new Error("Can not access image data");
|
|
4178
2098
|
}
|
|
4179
|
-
},
|
|
2099
|
+
}, tensorToImageData = (tensor, options) => {
|
|
4180
2100
|
const pixels2DContext = typeof document !== "undefined" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d");
|
|
4181
2101
|
let image;
|
|
4182
2102
|
if (pixels2DContext != null) {
|
|
@@ -4257,7 +2177,7 @@ var tensorToDataURL2 = (tensor, options) => {
|
|
|
4257
2177
|
};
|
|
4258
2178
|
|
|
4259
2179
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js
|
|
4260
|
-
var
|
|
2180
|
+
var bufferToTensor = (buffer, options) => {
|
|
4261
2181
|
if (buffer === undefined) {
|
|
4262
2182
|
throw new Error("Image buffer must be defined");
|
|
4263
2183
|
}
|
|
@@ -4313,9 +2233,9 @@ var bufferToTensor2 = (buffer, options) => {
|
|
|
4313
2233
|
float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
|
|
4314
2234
|
}
|
|
4315
2235
|
}
|
|
4316
|
-
const outputTensor = outputformat === "RGBA" ? new
|
|
2236
|
+
const outputTensor = outputformat === "RGBA" ? new Tensor("float32", float32Data, [1, 4, height, width]) : new Tensor("float32", float32Data, [1, 3, height, width]);
|
|
4317
2237
|
return outputTensor;
|
|
4318
|
-
},
|
|
2238
|
+
}, tensorFromImage = async (image, options) => {
|
|
4319
2239
|
const isHTMLImageEle = typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement;
|
|
4320
2240
|
const isImageDataEle = typeof ImageData !== "undefined" && image instanceof ImageData;
|
|
4321
2241
|
const isImageBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
|
|
@@ -4416,7 +2336,7 @@ var bufferToTensor2 = (buffer, options) => {
|
|
|
4416
2336
|
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
4417
2337
|
bufferToTensorOptions.height = height;
|
|
4418
2338
|
bufferToTensorOptions.width = width;
|
|
4419
|
-
return
|
|
2339
|
+
return bufferToTensor(data, bufferToTensorOptions);
|
|
4420
2340
|
} else {
|
|
4421
2341
|
throw new Error("Can not access image data");
|
|
4422
2342
|
}
|
|
@@ -4437,58 +2357,58 @@ var bufferToTensor2 = (buffer, options) => {
|
|
|
4437
2357
|
const img = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
4438
2358
|
bufferToTensorOptions.height = canvas.height;
|
|
4439
2359
|
bufferToTensorOptions.width = canvas.width;
|
|
4440
|
-
resolve(
|
|
2360
|
+
resolve(bufferToTensor(img.data, bufferToTensorOptions));
|
|
4441
2361
|
};
|
|
4442
2362
|
});
|
|
4443
2363
|
} else {
|
|
4444
2364
|
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
4445
2365
|
}
|
|
4446
2366
|
if (data !== undefined) {
|
|
4447
|
-
return
|
|
2367
|
+
return bufferToTensor(data, bufferToTensorOptions);
|
|
4448
2368
|
} else {
|
|
4449
2369
|
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
4450
2370
|
}
|
|
4451
|
-
},
|
|
2371
|
+
}, tensorFromTexture = (texture, options) => {
|
|
4452
2372
|
const { width, height, download, dispose } = options;
|
|
4453
2373
|
const dims = [1, height, width, 4];
|
|
4454
|
-
return new
|
|
4455
|
-
},
|
|
2374
|
+
return new Tensor({ location: "texture", type: "float32", texture, dims, download, dispose });
|
|
2375
|
+
}, tensorFromGpuBuffer = (gpuBuffer, options) => {
|
|
4456
2376
|
const { dataType, dims, download, dispose } = options;
|
|
4457
|
-
return new
|
|
4458
|
-
},
|
|
2377
|
+
return new Tensor({ location: "gpu-buffer", type: dataType ?? "float32", gpuBuffer, dims, download, dispose });
|
|
2378
|
+
}, tensorFromMLTensor = (mlTensor, options) => {
|
|
4459
2379
|
const { dataType, dims, download, dispose } = options;
|
|
4460
|
-
return new
|
|
4461
|
-
},
|
|
4462
|
-
var
|
|
4463
|
-
|
|
2380
|
+
return new Tensor({ location: "ml-tensor", type: dataType ?? "float32", mlTensor, dims, download, dispose });
|
|
2381
|
+
}, tensorFromPinnedBuffer = (type, buffer, dims) => new Tensor({ location: "cpu-pinned", type, data: buffer, dims: dims ?? [buffer.length] });
|
|
2382
|
+
var init_tensor_factory_impl = __esm(() => {
|
|
2383
|
+
init_tensor_impl();
|
|
4464
2384
|
});
|
|
4465
2385
|
|
|
4466
2386
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js
|
|
4467
|
-
var
|
|
4468
|
-
if (!
|
|
4469
|
-
|
|
2387
|
+
var NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP, NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP, isTypedArrayChecked = false, checkTypedArray = () => {
|
|
2388
|
+
if (!isTypedArrayChecked) {
|
|
2389
|
+
isTypedArrayChecked = true;
|
|
4470
2390
|
const isBigInt64ArrayAvailable = typeof BigInt64Array !== "undefined" && BigInt64Array.from;
|
|
4471
2391
|
const isBigUint64ArrayAvailable = typeof BigUint64Array !== "undefined" && BigUint64Array.from;
|
|
4472
2392
|
const Float16Array2 = globalThis.Float16Array;
|
|
4473
2393
|
const isFloat16ArrayAvailable = typeof Float16Array2 !== "undefined" && Float16Array2.from;
|
|
4474
2394
|
if (isBigInt64ArrayAvailable) {
|
|
4475
|
-
|
|
4476
|
-
|
|
2395
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64", BigInt64Array);
|
|
2396
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, "int64");
|
|
4477
2397
|
}
|
|
4478
2398
|
if (isBigUint64ArrayAvailable) {
|
|
4479
|
-
|
|
4480
|
-
|
|
2399
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64", BigUint64Array);
|
|
2400
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, "uint64");
|
|
4481
2401
|
}
|
|
4482
2402
|
if (isFloat16ArrayAvailable) {
|
|
4483
|
-
|
|
4484
|
-
|
|
2403
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Float16Array2);
|
|
2404
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array2, "float16");
|
|
4485
2405
|
} else {
|
|
4486
|
-
|
|
2406
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Uint16Array);
|
|
4487
2407
|
}
|
|
4488
2408
|
}
|
|
4489
2409
|
};
|
|
4490
|
-
var
|
|
4491
|
-
|
|
2410
|
+
var init_tensor_impl_type_mapping = __esm(() => {
|
|
2411
|
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = new Map([
|
|
4492
2412
|
["float32", Float32Array],
|
|
4493
2413
|
["uint8", Uint8Array],
|
|
4494
2414
|
["int8", Int8Array],
|
|
@@ -4501,7 +2421,7 @@ var init_tensor_impl_type_mapping2 = __esm(() => {
|
|
|
4501
2421
|
["int4", Uint8Array],
|
|
4502
2422
|
["uint4", Uint8Array]
|
|
4503
2423
|
]);
|
|
4504
|
-
|
|
2424
|
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = new Map([
|
|
4505
2425
|
[Float32Array, "float32"],
|
|
4506
2426
|
[Uint8Array, "uint8"],
|
|
4507
2427
|
[Int8Array, "int8"],
|
|
@@ -4514,7 +2434,7 @@ var init_tensor_impl_type_mapping2 = __esm(() => {
|
|
|
4514
2434
|
});
|
|
4515
2435
|
|
|
4516
2436
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-utils-impl.js
|
|
4517
|
-
var
|
|
2437
|
+
var calculateSize = (dims) => {
|
|
4518
2438
|
let size = 1;
|
|
4519
2439
|
for (let i = 0;i < dims.length; i++) {
|
|
4520
2440
|
const dim = dims[i];
|
|
@@ -4527,33 +2447,33 @@ var calculateSize2 = (dims) => {
|
|
|
4527
2447
|
size *= dim;
|
|
4528
2448
|
}
|
|
4529
2449
|
return size;
|
|
4530
|
-
},
|
|
2450
|
+
}, tensorReshape = (tensor, dims) => {
|
|
4531
2451
|
switch (tensor.location) {
|
|
4532
2452
|
case "cpu":
|
|
4533
|
-
return new
|
|
2453
|
+
return new Tensor(tensor.type, tensor.data, dims);
|
|
4534
2454
|
case "cpu-pinned":
|
|
4535
|
-
return new
|
|
2455
|
+
return new Tensor({
|
|
4536
2456
|
location: "cpu-pinned",
|
|
4537
2457
|
data: tensor.data,
|
|
4538
2458
|
type: tensor.type,
|
|
4539
2459
|
dims
|
|
4540
2460
|
});
|
|
4541
2461
|
case "texture":
|
|
4542
|
-
return new
|
|
2462
|
+
return new Tensor({
|
|
4543
2463
|
location: "texture",
|
|
4544
2464
|
texture: tensor.texture,
|
|
4545
2465
|
type: tensor.type,
|
|
4546
2466
|
dims
|
|
4547
2467
|
});
|
|
4548
2468
|
case "gpu-buffer":
|
|
4549
|
-
return new
|
|
2469
|
+
return new Tensor({
|
|
4550
2470
|
location: "gpu-buffer",
|
|
4551
2471
|
gpuBuffer: tensor.gpuBuffer,
|
|
4552
2472
|
type: tensor.type,
|
|
4553
2473
|
dims
|
|
4554
2474
|
});
|
|
4555
2475
|
case "ml-tensor":
|
|
4556
|
-
return new
|
|
2476
|
+
return new Tensor({
|
|
4557
2477
|
location: "ml-tensor",
|
|
4558
2478
|
mlTensor: tensor.mlTensor,
|
|
4559
2479
|
type: tensor.type,
|
|
@@ -4563,14 +2483,14 @@ var calculateSize2 = (dims) => {
|
|
|
4563
2483
|
throw new Error(`tensorReshape: tensor location ${tensor.location} is not supported`);
|
|
4564
2484
|
}
|
|
4565
2485
|
};
|
|
4566
|
-
var
|
|
4567
|
-
|
|
2486
|
+
var init_tensor_utils_impl = __esm(() => {
|
|
2487
|
+
init_tensor_impl();
|
|
4568
2488
|
});
|
|
4569
2489
|
|
|
4570
2490
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-impl.js
|
|
4571
|
-
class
|
|
2491
|
+
class Tensor {
|
|
4572
2492
|
constructor(arg0, arg1, arg2) {
|
|
4573
|
-
|
|
2493
|
+
checkTypedArray();
|
|
4574
2494
|
let type;
|
|
4575
2495
|
let dims;
|
|
4576
2496
|
if (typeof arg0 === "object" && "location" in arg0) {
|
|
@@ -4579,7 +2499,7 @@ class Tensor3 {
|
|
|
4579
2499
|
dims = arg0.dims;
|
|
4580
2500
|
switch (arg0.location) {
|
|
4581
2501
|
case "cpu-pinned": {
|
|
4582
|
-
const expectedTypedArrayConstructor =
|
|
2502
|
+
const expectedTypedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
|
|
4583
2503
|
if (!expectedTypedArrayConstructor) {
|
|
4584
2504
|
throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
|
|
4585
2505
|
}
|
|
@@ -4631,7 +2551,7 @@ class Tensor3 {
|
|
|
4631
2551
|
}
|
|
4632
2552
|
data = arg1;
|
|
4633
2553
|
} else {
|
|
4634
|
-
const typedArrayConstructor =
|
|
2554
|
+
const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
|
|
4635
2555
|
if (typedArrayConstructor === undefined) {
|
|
4636
2556
|
throw new TypeError(`Unsupported tensor type: ${arg0}.`);
|
|
4637
2557
|
}
|
|
@@ -4677,7 +2597,7 @@ class Tensor3 {
|
|
|
4677
2597
|
type = "uint8";
|
|
4678
2598
|
data = Uint8Array.from(arg0);
|
|
4679
2599
|
} else {
|
|
4680
|
-
const mappedType =
|
|
2600
|
+
const mappedType = NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
|
|
4681
2601
|
if (mappedType === undefined) {
|
|
4682
2602
|
throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
|
|
4683
2603
|
}
|
|
@@ -4694,7 +2614,7 @@ class Tensor3 {
|
|
|
4694
2614
|
this.cpuData = data;
|
|
4695
2615
|
this.dataLocation = "cpu";
|
|
4696
2616
|
}
|
|
4697
|
-
const size =
|
|
2617
|
+
const size = calculateSize(dims);
|
|
4698
2618
|
if (this.cpuData && size !== this.cpuData.length) {
|
|
4699
2619
|
if ((type === "uint4" || type === "int4") && Math.ceil(size / 2) === this.cpuData.length) {} else {
|
|
4700
2620
|
throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
|
|
@@ -4705,25 +2625,25 @@ class Tensor3 {
|
|
|
4705
2625
|
this.size = size;
|
|
4706
2626
|
}
|
|
4707
2627
|
static async fromImage(image, options) {
|
|
4708
|
-
return
|
|
2628
|
+
return tensorFromImage(image, options);
|
|
4709
2629
|
}
|
|
4710
2630
|
static fromTexture(texture, options) {
|
|
4711
|
-
return
|
|
2631
|
+
return tensorFromTexture(texture, options);
|
|
4712
2632
|
}
|
|
4713
2633
|
static fromGpuBuffer(gpuBuffer, options) {
|
|
4714
|
-
return
|
|
2634
|
+
return tensorFromGpuBuffer(gpuBuffer, options);
|
|
4715
2635
|
}
|
|
4716
2636
|
static fromMLTensor(mlTensor, options) {
|
|
4717
|
-
return
|
|
2637
|
+
return tensorFromMLTensor(mlTensor, options);
|
|
4718
2638
|
}
|
|
4719
2639
|
static fromPinnedBuffer(type, buffer, dims) {
|
|
4720
|
-
return
|
|
2640
|
+
return tensorFromPinnedBuffer(type, buffer, dims);
|
|
4721
2641
|
}
|
|
4722
2642
|
toDataURL(options) {
|
|
4723
|
-
return
|
|
2643
|
+
return tensorToDataURL(this, options);
|
|
4724
2644
|
}
|
|
4725
2645
|
toImageData(options) {
|
|
4726
|
-
return
|
|
2646
|
+
return tensorToImageData(this, options);
|
|
4727
2647
|
}
|
|
4728
2648
|
get data() {
|
|
4729
2649
|
this.ensureValid();
|
|
@@ -4816,62 +2736,62 @@ class Tensor3 {
|
|
|
4816
2736
|
if (this.downloader || this.disposer) {
|
|
4817
2737
|
throw new Error("Cannot reshape a tensor that owns GPU resource.");
|
|
4818
2738
|
}
|
|
4819
|
-
return
|
|
2739
|
+
return tensorReshape(this, dims);
|
|
4820
2740
|
}
|
|
4821
2741
|
}
|
|
4822
|
-
var
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
2742
|
+
var init_tensor_impl = __esm(() => {
|
|
2743
|
+
init_tensor_factory_impl();
|
|
2744
|
+
init_tensor_impl_type_mapping();
|
|
2745
|
+
init_tensor_utils_impl();
|
|
4826
2746
|
});
|
|
4827
2747
|
|
|
4828
2748
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor.js
|
|
4829
|
-
var
|
|
4830
|
-
var
|
|
4831
|
-
|
|
4832
|
-
|
|
2749
|
+
var Tensor2;
|
|
2750
|
+
var init_tensor = __esm(() => {
|
|
2751
|
+
init_tensor_impl();
|
|
2752
|
+
Tensor2 = Tensor;
|
|
4833
2753
|
});
|
|
4834
2754
|
|
|
4835
2755
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/trace.js
|
|
4836
|
-
var
|
|
4837
|
-
|
|
2756
|
+
var init_trace = __esm(() => {
|
|
2757
|
+
init_env_impl();
|
|
4838
2758
|
});
|
|
4839
2759
|
|
|
4840
2760
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/inference-session-impl.js
|
|
4841
|
-
var
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
2761
|
+
var init_inference_session_impl = __esm(() => {
|
|
2762
|
+
init_backend_impl();
|
|
2763
|
+
init_tensor();
|
|
2764
|
+
init_trace();
|
|
4845
2765
|
});
|
|
4846
2766
|
|
|
4847
2767
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/inference-session.js
|
|
4848
|
-
var
|
|
4849
|
-
|
|
2768
|
+
var init_inference_session = __esm(() => {
|
|
2769
|
+
init_inference_session_impl();
|
|
4850
2770
|
});
|
|
4851
2771
|
|
|
4852
2772
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-conversion.js
|
|
4853
|
-
var
|
|
2773
|
+
var init_tensor_conversion = () => {};
|
|
4854
2774
|
|
|
4855
2775
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/tensor-factory.js
|
|
4856
|
-
var
|
|
2776
|
+
var init_tensor_factory = () => {};
|
|
4857
2777
|
|
|
4858
2778
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/onnx-model.js
|
|
4859
|
-
var
|
|
2779
|
+
var init_onnx_model = () => {};
|
|
4860
2780
|
|
|
4861
2781
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/onnx-value.js
|
|
4862
|
-
var
|
|
2782
|
+
var init_onnx_value = () => {};
|
|
4863
2783
|
|
|
4864
2784
|
// ../../node_modules/.bun/onnxruntime-common@1.24.3/node_modules/onnxruntime-common/dist/esm/index.js
|
|
4865
|
-
var
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
2785
|
+
var init_esm = __esm(() => {
|
|
2786
|
+
init_backend();
|
|
2787
|
+
init_env();
|
|
2788
|
+
init_inference_session();
|
|
2789
|
+
init_tensor();
|
|
2790
|
+
init_tensor_conversion();
|
|
2791
|
+
init_tensor_factory();
|
|
2792
|
+
init_trace();
|
|
2793
|
+
init_onnx_model();
|
|
2794
|
+
init_onnx_value();
|
|
4875
2795
|
});
|
|
4876
2796
|
|
|
4877
2797
|
// ../../node_modules/.bun/sharp@0.34.5/node_modules/sharp/lib/is.js
|
|
@@ -12177,7 +10097,7 @@ __export(exports_transformers_node, {
|
|
|
12177
10097
|
cat: () => cat,
|
|
12178
10098
|
cos_sim: () => cos_sim,
|
|
12179
10099
|
dot: () => dot,
|
|
12180
|
-
env: () =>
|
|
10100
|
+
env: () => env3,
|
|
12181
10101
|
full: () => full,
|
|
12182
10102
|
full_like: () => full_like,
|
|
12183
10103
|
interpolate: () => interpolate,
|
|
@@ -13673,33 +11593,33 @@ function toAbsoluteURL(url2) {
|
|
|
13673
11593
|
}
|
|
13674
11594
|
async function getCache(file_cache_dir = null) {
|
|
13675
11595
|
let cache2 = null;
|
|
13676
|
-
if (
|
|
13677
|
-
if (!
|
|
11596
|
+
if (env3.useCustomCache) {
|
|
11597
|
+
if (!env3.customCache) {
|
|
13678
11598
|
throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");
|
|
13679
11599
|
}
|
|
13680
|
-
if (!
|
|
11600
|
+
if (!env3.customCache.match || !env3.customCache.put) {
|
|
13681
11601
|
throw new Error("`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache");
|
|
13682
11602
|
}
|
|
13683
|
-
cache2 =
|
|
11603
|
+
cache2 = env3.customCache;
|
|
13684
11604
|
}
|
|
13685
|
-
if (!cache2 &&
|
|
11605
|
+
if (!cache2 && env3.experimental_useCrossOriginStorage && CrossOriginStorage.isAvailable()) {
|
|
13686
11606
|
cache2 = new CrossOriginStorage;
|
|
13687
11607
|
}
|
|
13688
|
-
if (!cache2 &&
|
|
11608
|
+
if (!cache2 && env3.useBrowserCache) {
|
|
13689
11609
|
if (typeof caches === "undefined") {
|
|
13690
11610
|
throw Error("Browser cache is not available in this environment.");
|
|
13691
11611
|
}
|
|
13692
11612
|
try {
|
|
13693
|
-
cache2 = await caches.open(
|
|
11613
|
+
cache2 = await caches.open(env3.cacheKey);
|
|
13694
11614
|
} catch (e) {
|
|
13695
11615
|
logger.warn("An error occurred while opening the browser cache:", e);
|
|
13696
11616
|
}
|
|
13697
11617
|
}
|
|
13698
|
-
if (!cache2 &&
|
|
11618
|
+
if (!cache2 && env3.useFSCache) {
|
|
13699
11619
|
if (!apis.IS_FS_AVAILABLE) {
|
|
13700
11620
|
throw Error("File System Cache is not available in this environment.");
|
|
13701
11621
|
}
|
|
13702
|
-
cache2 = new FileCache(file_cache_dir ??
|
|
11622
|
+
cache2 = new FileCache(file_cache_dir ?? env3.cacheDir);
|
|
13703
11623
|
}
|
|
13704
11624
|
return cache2;
|
|
13705
11625
|
}
|
|
@@ -13733,7 +11653,7 @@ async function fetch_file_head(urlOrPath) {
|
|
|
13733
11653
|
}
|
|
13734
11654
|
const headers = getFetchHeaders(urlOrPath);
|
|
13735
11655
|
headers.set("Range", "bytes=0-0");
|
|
13736
|
-
return
|
|
11656
|
+
return env3.fetch(urlOrPath, { method: "GET", headers, cache: "no-store" });
|
|
13737
11657
|
}
|
|
13738
11658
|
function get_file_metadata(path_or_repo_id, filename, options = {}) {
|
|
13739
11659
|
const key = JSON.stringify([
|
|
@@ -13759,7 +11679,7 @@ async function _get_file_metadata(path_or_repo_id, filename, options) {
|
|
|
13759
11679
|
fromCache: true
|
|
13760
11680
|
};
|
|
13761
11681
|
}
|
|
13762
|
-
if (
|
|
11682
|
+
if (env3.allowLocalModels) {
|
|
13763
11683
|
const isURL = isValidUrl(localPath, ["http:", "https:"]);
|
|
13764
11684
|
if (!isURL) {
|
|
13765
11685
|
try {
|
|
@@ -13777,7 +11697,7 @@ async function _get_file_metadata(path_or_repo_id, filename, options) {
|
|
|
13777
11697
|
} catch (e) {}
|
|
13778
11698
|
}
|
|
13779
11699
|
}
|
|
13780
|
-
if (
|
|
11700
|
+
if (env3.allowRemoteModels && !options.local_files_only && validModelId) {
|
|
13781
11701
|
try {
|
|
13782
11702
|
const rangeResponse = await fetch_file_head(remoteURL);
|
|
13783
11703
|
if (rangeResponse && rangeResponse.status >= 200 && rangeResponse.status < 300) {
|
|
@@ -13814,10 +11734,10 @@ async function _get_file_metadata(path_or_repo_id, filename, options) {
|
|
|
13814
11734
|
return { exists: false, fromCache: false };
|
|
13815
11735
|
}
|
|
13816
11736
|
async function getFile(urlOrPath) {
|
|
13817
|
-
if (
|
|
11737
|
+
if (env3.useFS && !isValidUrl(urlOrPath, ["http:", "https:", "blob:"])) {
|
|
13818
11738
|
return new FileResponse(urlOrPath instanceof URL ? urlOrPath.protocol === "file:" ? urlOrPath.pathname : urlOrPath.toString() : urlOrPath);
|
|
13819
11739
|
} else {
|
|
13820
|
-
return
|
|
11740
|
+
return env3.fetch(urlOrPath, {
|
|
13821
11741
|
headers: getFetchHeaders(urlOrPath)
|
|
13822
11742
|
});
|
|
13823
11743
|
}
|
|
@@ -13827,7 +11747,7 @@ function getFetchHeaders(urlOrPath) {
|
|
|
13827
11747
|
const headers = new Headers;
|
|
13828
11748
|
if (isNode) {
|
|
13829
11749
|
const IS_CI = !!process.env?.TESTING_REMOTELY;
|
|
13830
|
-
const version =
|
|
11750
|
+
const version = env3.version;
|
|
13831
11751
|
headers.set("User-Agent", `transformers.js/${version}; is_ci/${IS_CI};`);
|
|
13832
11752
|
const isHFURL = isValidUrl(urlOrPath, ["http:", "https:"], ["huggingface.co", "hf.co"]);
|
|
13833
11753
|
if (isHFURL) {
|
|
@@ -13843,8 +11763,8 @@ function buildResourcePaths(path_or_repo_id, filename, options = {}, cache2 = nu
|
|
|
13843
11763
|
const revision = options.revision ?? "main";
|
|
13844
11764
|
const requestURL = pathJoin(path_or_repo_id, filename);
|
|
13845
11765
|
const validModelId = isValidHfModelId(path_or_repo_id);
|
|
13846
|
-
const localPath = validModelId ? pathJoin(
|
|
13847
|
-
const remoteURL = pathJoin(
|
|
11766
|
+
const localPath = validModelId ? pathJoin(env3.localModelPath, requestURL) : requestURL;
|
|
11767
|
+
const remoteURL = pathJoin(env3.remoteHost, env3.remotePathTemplate.replaceAll("{model}", path_or_repo_id).replaceAll("{revision}", encodeURIComponent(revision)), filename);
|
|
13848
11768
|
const proposedCacheKey = cache2 instanceof FileCache ? revision === "main" ? requestURL : pathJoin(path_or_repo_id, revision, filename) : remoteURL;
|
|
13849
11769
|
return {
|
|
13850
11770
|
requestURL,
|
|
@@ -13892,7 +11812,7 @@ async function loadResourceFile(path_or_repo_id, filename, fatal = true, options
|
|
|
13892
11812
|
if (cacheHit) {
|
|
13893
11813
|
cacheKey = proposedCacheKey;
|
|
13894
11814
|
} else {
|
|
13895
|
-
if (
|
|
11815
|
+
if (env3.allowLocalModels) {
|
|
13896
11816
|
const isURL = isValidUrl(requestURL, ["http:", "https:"]);
|
|
13897
11817
|
if (!isURL) {
|
|
13898
11818
|
try {
|
|
@@ -13903,12 +11823,12 @@ async function loadResourceFile(path_or_repo_id, filename, fatal = true, options
|
|
|
13903
11823
|
}
|
|
13904
11824
|
} else if (options.local_files_only) {
|
|
13905
11825
|
throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${requestURL}.`);
|
|
13906
|
-
} else if (!
|
|
11826
|
+
} else if (!env3.allowRemoteModels) {
|
|
13907
11827
|
throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${requestURL}.`);
|
|
13908
11828
|
}
|
|
13909
11829
|
}
|
|
13910
11830
|
if (response === undefined || typeof response !== "string" && response.status === 404) {
|
|
13911
|
-
if (options.local_files_only || !
|
|
11831
|
+
if (options.local_files_only || !env3.allowRemoteModels) {
|
|
13912
11832
|
if (fatal) {
|
|
13913
11833
|
throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${localPath}".`);
|
|
13914
11834
|
} else {
|
|
@@ -14011,10 +11931,10 @@ async function loadResourceFile(path_or_repo_id, filename, fatal = true, options
|
|
|
14011
11931
|
throw new Error("Unable to get model file path or buffer.");
|
|
14012
11932
|
}
|
|
14013
11933
|
async function getModelFile(path_or_repo_id, filename, fatal = true, options = {}, return_path = false) {
|
|
14014
|
-
if (!
|
|
11934
|
+
if (!env3.allowLocalModels) {
|
|
14015
11935
|
if (options.local_files_only) {
|
|
14016
11936
|
throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");
|
|
14017
|
-
} else if (!
|
|
11937
|
+
} else if (!env3.allowRemoteModels) {
|
|
14018
11938
|
throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.");
|
|
14019
11939
|
}
|
|
14020
11940
|
}
|
|
@@ -16126,7 +14046,7 @@ async function loadAndCacheFile(url2) {
|
|
|
16126
14046
|
} catch (error) {
|
|
16127
14047
|
logger.warn(`Failed to load ${fileName} from cache:`, error);
|
|
16128
14048
|
}
|
|
16129
|
-
const response = await
|
|
14049
|
+
const response = await env3.fetch(url2);
|
|
16130
14050
|
if (!response.ok) {
|
|
16131
14051
|
throw new Error(`Failed to fetch ${fileName}: ${response.status} ${response.statusText}`);
|
|
16132
14052
|
}
|
|
@@ -16198,7 +14118,7 @@ async function ensureWasmLoaded() {
|
|
|
16198
14118
|
if (wasmLoadPromise) {
|
|
16199
14119
|
return wasmLoadPromise;
|
|
16200
14120
|
}
|
|
16201
|
-
const shouldUseWasmCache =
|
|
14121
|
+
const shouldUseWasmCache = env3.useWasmCache && typeof ONNX_ENV?.wasm?.wasmPaths === "object" && ONNX_ENV?.wasm?.wasmPaths?.wasm && ONNX_ENV?.wasm?.wasmPaths?.mjs;
|
|
16202
14122
|
if (!shouldUseWasmCache) {
|
|
16203
14123
|
if (apis.IS_DENO_WEB_RUNTIME) {
|
|
16204
14124
|
throw new Error("env.useWasmCache=false is not supported in Deno's web runtime. Remove the useWasmCache override.");
|
|
@@ -16240,8 +14160,8 @@ async function ensureWasmLoaded() {
|
|
|
16240
14160
|
}
|
|
16241
14161
|
async function createInferenceSession(buffer_or_path, session_options, session_config) {
|
|
16242
14162
|
await ensureWasmLoaded();
|
|
16243
|
-
const logSeverityLevel = getOnnxLogSeverityLevel(
|
|
16244
|
-
const load = () =>
|
|
14163
|
+
const logSeverityLevel = getOnnxLogSeverityLevel(env3.logLevel ?? LogLevel.WARNING);
|
|
14164
|
+
const load = () => InferenceSession2.create(buffer_or_path, {
|
|
16245
14165
|
logSeverityLevel,
|
|
16246
14166
|
...session_options
|
|
16247
14167
|
});
|
|
@@ -18957,7 +16877,7 @@ async function load_video(src, { num_frames = null, fps = null } = {}) {
|
|
|
18957
16877
|
}
|
|
18958
16878
|
await new Promise((resolve) => video.onloadedmetadata = resolve);
|
|
18959
16879
|
if (video.seekable.start(0) === video.seekable.end(0)) {
|
|
18960
|
-
const response = await
|
|
16880
|
+
const response = await env3.fetch(video.src);
|
|
18961
16881
|
const blob = await response.blob();
|
|
18962
16882
|
video.src = URL.createObjectURL(blob);
|
|
18963
16883
|
await new Promise((resolve) => video.onloadedmetadata = resolve);
|
|
@@ -19132,7 +17052,7 @@ var ONNX_NODE, import_sharp, __dirname = "/home/runner/work/magic-context/magic-
|
|
|
19132
17052
|
const isAppleVendor = vendor.indexOf("Apple") > -1;
|
|
19133
17053
|
const notOtherBrowser = !userAgent.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i) && !userAgent.includes("Chrome") && !userAgent.includes("Android");
|
|
19134
17054
|
return isAppleVendor && notOtherBrowser;
|
|
19135
|
-
}, IS_SAFARI, apis, RUNNING_LOCALLY, dirname__ = "./", DEFAULT_CACHE_DIR, DEFAULT_LOCAL_MODEL_PATH = "/models/", localModelPath, DEFAULT_FETCH, LogLevel, logLevel,
|
|
17055
|
+
}, IS_SAFARI, apis, RUNNING_LOCALLY, dirname__ = "./", DEFAULT_CACHE_DIR, DEFAULT_LOCAL_MODEL_PATH = "/models/", localModelPath, DEFAULT_FETCH, LogLevel, logLevel, env3, Callable = class {
|
|
19136
17056
|
constructor() {
|
|
19137
17057
|
let closure = function(...args) {
|
|
19138
17058
|
return closure._call(...args);
|
|
@@ -21413,7 +19333,7 @@ var ONNX_NODE, import_sharp, __dirname = "/home/runner/work/magic-context/magic-
|
|
|
21413
19333
|
transform(out, input) {
|
|
21414
19334
|
this.fft.transform(out, input);
|
|
21415
19335
|
}
|
|
21416
|
-
}, uint16_to_float32, ort_webgpu_bundle_min_exports, jr, zf, Vf, jf,
|
|
19336
|
+
}, uint16_to_float32, ort_webgpu_bundle_min_exports, jr, zf, Vf, jf, Hr, k = (a, r) => () => (a && (r = a(a = 0)), r), At = (a, r) => {
|
|
21417
19337
|
for (var s in r)
|
|
21418
19338
|
jr(a, s, { get: r[s], enumerable: true });
|
|
21419
19339
|
}, Hf = (a, r, s, f) => {
|
|
@@ -21421,7 +19341,7 @@ var ONNX_NODE, import_sharp, __dirname = "/home/runner/work/magic-context/magic-
|
|
|
21421
19341
|
for (let i of Vf(r))
|
|
21422
19342
|
!jf.call(a, i) && i !== s && jr(a, i, { get: () => r[i], enumerable: !(f = zf(r, i)) || f.enumerable });
|
|
21423
19343
|
return a;
|
|
21424
|
-
}, $t = (a) => Hf(jr({}, "__esModule", { value: true }), a), zt,
|
|
19344
|
+
}, $t = (a) => Hf(jr({}, "__esModule", { value: true }), a), zt, Ze, Ke, Yf, Ta, Yr, va, Ea, Sa, Aa, ie, qr, K, Ia, xa, La, Oa, Jr, Ba, Ma, Ca, Ua, Da, Pa, et, It, _a3, Ra, Na, ka, Wa, Fa, le, Vt, Le, Xr, Ga, $a, tt, rt, $e, ze, Qr, jt, za, qf, Va, ja, Ha, Ya, qa, Zr, Ve, Ht, Za, Xa, Qa, Jf, Ka, ts, Xf, Qf, rs, as, tn, Zf, ge, ss, en, Kf, ec, is, tc, ns, us, os2, fs42, Yt, rn, nn, rr, cs, rc, nc, oc, qt, z, je, be, Lt, $, nr, ds, ls, ac, sc, ic, on, ot, uc, ps, ms, He, or, mt, at, Ot, ar, sr, an, st, Bt, sn, hs, ys, fc, cc, bs, ws, gs, dc, pe, un, vs, cn, Es, lc, Ts, pc, Ss, ir, ur, fn, As, Is, xs, fr, mc, dn, Ls, hc, Jt, Xt, it, yc, Os, xt, Qt, Zt, Bs, Kt, er, tr, Kr, ut, Ee, Mt, dr, lr, cr, ln, pn, ht, yt, wc, Ms, Cs, Us, Ds, Ps, _s, Rs, mn, Ns, gc, pr, ks, Fs, Ws, mr, Tc, Gs, Ja = "1.26.0-dev.20260416-b7804b056c", gl, DEVICE_TO_EXECUTION_PROVIDER_MAPPING, ONNX_LOG_LEVEL_NAMES, supportedDevices, defaultDevices, ONNX, ORT_SYMBOL, InferenceSession2, webInitChain, wasmLoadPromise = null, webInferenceChain, ONNX_ENV, wrap = async (session_bytes, session_options, names) => {
|
|
21425
19345
|
const session = await createInferenceSession(new Uint8Array(session_bytes), session_options);
|
|
21426
19346
|
return async (inputs) => {
|
|
21427
19347
|
const proxied = isONNXProxy();
|
|
@@ -22246,7 +20166,7 @@ var ONNX_NODE, import_sharp, __dirname = "/home/runner/work/magic-context/magic-
|
|
|
22246
20166
|
}
|
|
22247
20167
|
};
|
|
22248
20168
|
var init_transformers_node = __esm(() => {
|
|
22249
|
-
|
|
20169
|
+
init_esm();
|
|
22250
20170
|
ONNX_NODE = __toESM(require_dist(), 1);
|
|
22251
20171
|
import_sharp = __toESM(require_lib(), 1);
|
|
22252
20172
|
__defProp2 = Object.defineProperty;
|
|
@@ -22310,7 +20230,7 @@ var init_transformers_node = __esm(() => {
|
|
|
22310
20230
|
NONE: 50
|
|
22311
20231
|
});
|
|
22312
20232
|
logLevel = LogLevel.WARNING;
|
|
22313
|
-
|
|
20233
|
+
env3 = {
|
|
22314
20234
|
version: VERSION,
|
|
22315
20235
|
backends: {
|
|
22316
20236
|
onnx: {}
|
|
@@ -22320,7 +20240,7 @@ var init_transformers_node = __esm(() => {
|
|
|
22320
20240
|
},
|
|
22321
20241
|
set logLevel(level) {
|
|
22322
20242
|
logLevel = level;
|
|
22323
|
-
|
|
20243
|
+
env3.backends.onnx?.setLogLevel?.(level);
|
|
22324
20244
|
},
|
|
22325
20245
|
allowRemoteModels: true,
|
|
22326
20246
|
remoteHost: "https://huggingface.co/",
|
|
@@ -22367,22 +20287,22 @@ var init_transformers_node = __esm(() => {
|
|
|
22367
20287
|
};
|
|
22368
20288
|
logger = {
|
|
22369
20289
|
error(...args) {
|
|
22370
|
-
if (
|
|
20290
|
+
if (env3.logLevel <= LogLevel.ERROR) {
|
|
22371
20291
|
console.error(...args);
|
|
22372
20292
|
}
|
|
22373
20293
|
},
|
|
22374
20294
|
warn(...args) {
|
|
22375
|
-
if (
|
|
20295
|
+
if (env3.logLevel <= LogLevel.WARNING) {
|
|
22376
20296
|
console.warn(...args);
|
|
22377
20297
|
}
|
|
22378
20298
|
},
|
|
22379
20299
|
info(...args) {
|
|
22380
|
-
if (
|
|
20300
|
+
if (env3.logLevel <= LogLevel.INFO) {
|
|
22381
20301
|
console.log(...args);
|
|
22382
20302
|
}
|
|
22383
20303
|
},
|
|
22384
20304
|
debug(...args) {
|
|
22385
|
-
if (
|
|
20305
|
+
if (env3.logLevel <= LogLevel.DEBUG) {
|
|
22386
20306
|
console.log(...args);
|
|
22387
20307
|
}
|
|
22388
20308
|
},
|
|
@@ -24021,26 +21941,26 @@ var init_transformers_node = __esm(() => {
|
|
|
24021
21941
|
__export2(ort_webgpu_bundle_min_exports, {
|
|
24022
21942
|
InferenceSession: () => qf,
|
|
24023
21943
|
TRACE: () => Ga,
|
|
24024
|
-
TRACE_EVENT_BEGIN: () => $
|
|
21944
|
+
TRACE_EVENT_BEGIN: () => $e,
|
|
24025
21945
|
TRACE_EVENT_END: () => ze,
|
|
24026
|
-
TRACE_FUNC_BEGIN: () =>
|
|
24027
|
-
TRACE_FUNC_END: () =>
|
|
21946
|
+
TRACE_FUNC_BEGIN: () => tt,
|
|
21947
|
+
TRACE_FUNC_END: () => rt,
|
|
24028
21948
|
Tensor: () => Le,
|
|
24029
21949
|
default: () => gl,
|
|
24030
|
-
env: () =>
|
|
24031
|
-
registerBackend: () =>
|
|
21950
|
+
env: () => K,
|
|
21951
|
+
registerBackend: () => Ke
|
|
24032
21952
|
});
|
|
24033
21953
|
jr = Object.defineProperty;
|
|
24034
21954
|
zf = Object.getOwnPropertyDescriptor;
|
|
24035
21955
|
Vf = Object.getOwnPropertyNames;
|
|
24036
21956
|
jf = Object.prototype.hasOwnProperty;
|
|
24037
|
-
|
|
21957
|
+
Hr = ((a) => typeof __require2 < "u" ? __require2 : typeof Proxy < "u" ? new Proxy(a, { get: (r, s) => (typeof __require2 < "u" ? __require2 : r)[s] }) : a)(function(a) {
|
|
24038
21958
|
if (typeof __require2 < "u")
|
|
24039
21959
|
return __require2.apply(this, arguments);
|
|
24040
21960
|
throw Error('Dynamic require of "' + a + '" is not supported');
|
|
24041
21961
|
});
|
|
24042
21962
|
Yr = k(() => {
|
|
24043
|
-
zt = /* @__PURE__ */ new Map,
|
|
21963
|
+
zt = /* @__PURE__ */ new Map, Ze = [], Ke = (a, r, s) => {
|
|
24044
21964
|
if (r && typeof r.init == "function" && typeof r.createInferenceSessionHandler == "function") {
|
|
24045
21965
|
let f = zt.get(a);
|
|
24046
21966
|
if (f === undefined)
|
|
@@ -24052,14 +21972,14 @@ var init_transformers_node = __esm(() => {
|
|
|
24052
21972
|
throw new Error(`cannot register backend "${a}" using priority ${s}`);
|
|
24053
21973
|
}
|
|
24054
21974
|
if (s >= 0) {
|
|
24055
|
-
let i =
|
|
24056
|
-
i !== -1 &&
|
|
24057
|
-
for (let d = 0;d <
|
|
24058
|
-
if (zt.get(
|
|
24059
|
-
|
|
21975
|
+
let i = Ze.indexOf(a);
|
|
21976
|
+
i !== -1 && Ze.splice(i, 1);
|
|
21977
|
+
for (let d = 0;d < Ze.length; d++)
|
|
21978
|
+
if (zt.get(Ze[d]).priority <= s) {
|
|
21979
|
+
Ze.splice(d, 0, a);
|
|
24060
21980
|
return;
|
|
24061
21981
|
}
|
|
24062
|
-
|
|
21982
|
+
Ze.push(a);
|
|
24063
21983
|
}
|
|
24064
21984
|
return;
|
|
24065
21985
|
}
|
|
@@ -24083,7 +22003,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24083
22003
|
}
|
|
24084
22004
|
}
|
|
24085
22005
|
}, Ta = async (a) => {
|
|
24086
|
-
let r = a.executionProviders || [], s = r.map((y) => typeof y == "string" ? y : y.name), f = s.length === 0 ?
|
|
22006
|
+
let r = a.executionProviders || [], s = r.map((y) => typeof y == "string" ? y : y.name), f = s.length === 0 ? Ze : s, i, d = [], l = /* @__PURE__ */ new Set;
|
|
24087
22007
|
for (let y of f) {
|
|
24088
22008
|
let w = await Yf(y);
|
|
24089
22009
|
typeof w == "string" ? d.push({ name: y, err: w }) : (i || (i = w), i === w && l.add(y));
|
|
@@ -24104,7 +22024,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24104
22024
|
});
|
|
24105
22025
|
qr = k(() => {
|
|
24106
22026
|
Sa();
|
|
24107
|
-
Aa = "warning",
|
|
22027
|
+
Aa = "warning", ie = { wasm: {}, webgl: {}, webgpu: {}, versions: { common: Ea }, set logLevel(a) {
|
|
24108
22028
|
if (a !== undefined) {
|
|
24109
22029
|
if (typeof a != "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(a) === -1)
|
|
24110
22030
|
throw new Error(`Unsupported logging level: ${a}`);
|
|
@@ -24113,11 +22033,11 @@ var init_transformers_node = __esm(() => {
|
|
|
24113
22033
|
}, get logLevel() {
|
|
24114
22034
|
return Aa;
|
|
24115
22035
|
} };
|
|
24116
|
-
Object.defineProperty(
|
|
22036
|
+
Object.defineProperty(ie, "logLevel", { enumerable: true });
|
|
24117
22037
|
});
|
|
24118
22038
|
Ia = k(() => {
|
|
24119
22039
|
qr();
|
|
24120
|
-
|
|
22040
|
+
K = ie;
|
|
24121
22041
|
});
|
|
24122
22042
|
Oa = k(() => {
|
|
24123
22043
|
xa = (a, r) => {
|
|
@@ -24175,7 +22095,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24175
22095
|
m === "RGB" && (g = 3, v = 0, S = 1, C = 2, R = -1), y === "RGBA" ? Y = w * 3 : y === "RBG" ? (H = 0, M = w, U = w * 2) : y === "BGR" && (M = 0, U = w, H = w * 2);
|
|
24176
22096
|
for (let W = 0;W < w; W++, v += g, C += g, S += g, R += g)
|
|
24177
22097
|
T[H++] = (a[v] + l[0]) / d[0], T[U++] = (a[S] + l[1]) / d[1], T[M++] = (a[C] + l[2]) / d[2], Y !== -1 && R !== -1 && (T[Y++] = (a[R] + l[3]) / d[3]);
|
|
24178
|
-
return y === "RGBA" ? new
|
|
22098
|
+
return y === "RGBA" ? new le("float32", T, [1, 4, s, f]) : new le("float32", T, [1, 3, s, f]);
|
|
24179
22099
|
}, Ba = async (a, r) => {
|
|
24180
22100
|
let s = typeof HTMLImageElement < "u" && a instanceof HTMLImageElement, f = typeof ImageData < "u" && a instanceof ImageData, i = typeof ImageBitmap < "u" && a instanceof ImageBitmap, d = typeof a == "string", l, m = r ?? {}, y = () => {
|
|
24181
22101
|
if (typeof document < "u")
|
|
@@ -24242,21 +22162,21 @@ var init_transformers_node = __esm(() => {
|
|
|
24242
22162
|
throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
24243
22163
|
}, Ma = (a, r) => {
|
|
24244
22164
|
let { width: s, height: f, download: i, dispose: d } = r, l = [1, f, s, 4];
|
|
24245
|
-
return new
|
|
22165
|
+
return new le({ location: "texture", type: "float32", texture: a, dims: l, download: i, dispose: d });
|
|
24246
22166
|
}, Ca = (a, r) => {
|
|
24247
22167
|
let { dataType: s, dims: f, download: i, dispose: d } = r;
|
|
24248
|
-
return new
|
|
22168
|
+
return new le({ location: "gpu-buffer", type: s ?? "float32", gpuBuffer: a, dims: f, download: i, dispose: d });
|
|
24249
22169
|
}, Ua = (a, r) => {
|
|
24250
22170
|
let { dataType: s, dims: f, download: i, dispose: d } = r;
|
|
24251
|
-
return new
|
|
24252
|
-
}, Da = (a, r, s) => new
|
|
22171
|
+
return new le({ location: "ml-tensor", type: s ?? "float32", mlTensor: a, dims: f, download: i, dispose: d });
|
|
22172
|
+
}, Da = (a, r, s) => new le({ location: "cpu-pinned", type: a, data: r, dims: s ?? [r.length] });
|
|
24253
22173
|
});
|
|
24254
22174
|
Na = k(() => {
|
|
24255
|
-
|
|
22175
|
+
et = /* @__PURE__ */ new Map([["float32", Float32Array], ["uint8", Uint8Array], ["int8", Int8Array], ["uint16", Uint16Array], ["int16", Int16Array], ["int32", Int32Array], ["bool", Uint8Array], ["float64", Float64Array], ["uint32", Uint32Array], ["int4", Uint8Array], ["uint4", Uint8Array]]), It = /* @__PURE__ */ new Map([[Float32Array, "float32"], [Uint8Array, "uint8"], [Int8Array, "int8"], [Uint16Array, "uint16"], [Int16Array, "int16"], [Int32Array, "int32"], [Float64Array, "float64"], [Uint32Array, "uint32"]]), _a3 = false, Ra = () => {
|
|
24256
22176
|
if (!_a3) {
|
|
24257
22177
|
_a3 = true;
|
|
24258
22178
|
let a = typeof BigInt64Array < "u" && BigInt64Array.from, r = typeof BigUint64Array < "u" && BigUint64Array.from, s = globalThis.Float16Array, f = typeof s < "u" && s.from;
|
|
24259
|
-
a && (
|
|
22179
|
+
a && (et.set("int64", BigInt64Array), It.set(BigInt64Array, "int64")), r && (et.set("uint64", BigUint64Array), It.set(BigUint64Array, "uint64")), f ? (et.set("float16", s), It.set(s, "float16")) : et.set("float16", Uint16Array);
|
|
24260
22180
|
}
|
|
24261
22181
|
};
|
|
24262
22182
|
});
|
|
@@ -24276,15 +22196,15 @@ var init_transformers_node = __esm(() => {
|
|
|
24276
22196
|
}, Wa = (a, r) => {
|
|
24277
22197
|
switch (a.location) {
|
|
24278
22198
|
case "cpu":
|
|
24279
|
-
return new
|
|
22199
|
+
return new le(a.type, a.data, r);
|
|
24280
22200
|
case "cpu-pinned":
|
|
24281
|
-
return new
|
|
22201
|
+
return new le({ location: "cpu-pinned", data: a.data, type: a.type, dims: r });
|
|
24282
22202
|
case "texture":
|
|
24283
|
-
return new
|
|
22203
|
+
return new le({ location: "texture", texture: a.texture, type: a.type, dims: r });
|
|
24284
22204
|
case "gpu-buffer":
|
|
24285
|
-
return new
|
|
22205
|
+
return new le({ location: "gpu-buffer", gpuBuffer: a.gpuBuffer, type: a.type, dims: r });
|
|
24286
22206
|
case "ml-tensor":
|
|
24287
|
-
return new
|
|
22207
|
+
return new le({ location: "ml-tensor", mlTensor: a.mlTensor, type: a.type, dims: r });
|
|
24288
22208
|
default:
|
|
24289
22209
|
throw new Error(`tensorReshape: tensor location ${a.location} is not supported`);
|
|
24290
22210
|
}
|
|
@@ -24295,14 +22215,14 @@ var init_transformers_node = __esm(() => {
|
|
|
24295
22215
|
Pa();
|
|
24296
22216
|
Na();
|
|
24297
22217
|
Fa();
|
|
24298
|
-
|
|
22218
|
+
le = class {
|
|
24299
22219
|
constructor(r, s, f) {
|
|
24300
22220
|
Ra();
|
|
24301
22221
|
let i, d;
|
|
24302
22222
|
if (typeof r == "object" && "location" in r)
|
|
24303
22223
|
switch (this.dataLocation = r.location, i = r.type, d = r.dims, r.location) {
|
|
24304
22224
|
case "cpu-pinned": {
|
|
24305
|
-
let m =
|
|
22225
|
+
let m = et.get(i);
|
|
24306
22226
|
if (!m)
|
|
24307
22227
|
throw new TypeError(`unsupported type "${i}" to create tensor from pinned buffer`);
|
|
24308
22228
|
if (!(r.data instanceof m))
|
|
@@ -24339,7 +22259,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24339
22259
|
throw new TypeError("A string tensor's data must be a string array.");
|
|
24340
22260
|
m = s;
|
|
24341
22261
|
} else {
|
|
24342
|
-
let w =
|
|
22262
|
+
let w = et.get(r);
|
|
24343
22263
|
if (w === undefined)
|
|
24344
22264
|
throw new TypeError(`Unsupported tensor type: ${r}.`);
|
|
24345
22265
|
if (Array.isArray(s)) {
|
|
@@ -24371,7 +22291,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24371
22291
|
} else if (r instanceof Uint8ClampedArray)
|
|
24372
22292
|
i = "uint8", m = Uint8Array.from(r);
|
|
24373
22293
|
else {
|
|
24374
|
-
let w =
|
|
22294
|
+
let w = It.get(r.constructor);
|
|
24375
22295
|
if (w === undefined)
|
|
24376
22296
|
throw new TypeError(`Unsupported type for tensor data: ${r.constructor}.`);
|
|
24377
22297
|
i = w, m = r;
|
|
@@ -24473,12 +22393,12 @@ var init_transformers_node = __esm(() => {
|
|
|
24473
22393
|
});
|
|
24474
22394
|
Xr = k(() => {
|
|
24475
22395
|
Vt();
|
|
24476
|
-
Le =
|
|
22396
|
+
Le = le;
|
|
24477
22397
|
});
|
|
24478
22398
|
Qr = k(() => {
|
|
24479
22399
|
qr();
|
|
24480
22400
|
Ga = (a, r) => {
|
|
24481
|
-
(typeof
|
|
22401
|
+
(typeof ie.trace > "u" ? !ie.wasm.trace : !ie.trace) || console.timeStamp(`${a}::ORT::${r}`);
|
|
24482
22402
|
}, $a = (a, r) => {
|
|
24483
22403
|
let s = new Error().stack?.split(/\r\n|\r|\n/g) || [], f = false;
|
|
24484
22404
|
for (let i = 0;i < s.length; i++) {
|
|
@@ -24489,26 +22409,26 @@ var init_transformers_node = __esm(() => {
|
|
|
24489
22409
|
}
|
|
24490
22410
|
s[i].includes("TRACE_FUNC") && (f = true);
|
|
24491
22411
|
}
|
|
24492
|
-
},
|
|
24493
|
-
(typeof
|
|
24494
|
-
},
|
|
24495
|
-
(typeof
|
|
24496
|
-
}, $
|
|
24497
|
-
(typeof
|
|
22412
|
+
}, tt = (a) => {
|
|
22413
|
+
(typeof ie.trace > "u" ? !ie.wasm.trace : !ie.trace) || $a("BEGIN", a);
|
|
22414
|
+
}, rt = (a) => {
|
|
22415
|
+
(typeof ie.trace > "u" ? !ie.wasm.trace : !ie.trace) || $a("END", a);
|
|
22416
|
+
}, $e = (a) => {
|
|
22417
|
+
(typeof ie.trace > "u" ? !ie.wasm.trace : !ie.trace) || console.time(`ORT::${a}`);
|
|
24498
22418
|
}, ze = (a) => {
|
|
24499
|
-
(typeof
|
|
22419
|
+
(typeof ie.trace > "u" ? !ie.wasm.trace : !ie.trace) || console.timeEnd(`ORT::${a}`);
|
|
24500
22420
|
};
|
|
24501
22421
|
});
|
|
24502
22422
|
za = k(() => {
|
|
24503
22423
|
Yr();
|
|
24504
22424
|
Xr();
|
|
24505
22425
|
Qr();
|
|
24506
|
-
|
|
22426
|
+
jt = class a {
|
|
24507
22427
|
constructor(r) {
|
|
24508
22428
|
this.handler = r;
|
|
24509
22429
|
}
|
|
24510
22430
|
async run(r, s, f) {
|
|
24511
|
-
|
|
22431
|
+
tt(), $e("InferenceSession.run");
|
|
24512
22432
|
let i = {}, d = {};
|
|
24513
22433
|
if (typeof r != "object" || r === null || r instanceof Le || Array.isArray(r))
|
|
24514
22434
|
throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
|
|
@@ -24562,13 +22482,13 @@ var init_transformers_node = __esm(() => {
|
|
|
24562
22482
|
let T = m[w];
|
|
24563
22483
|
T instanceof Le ? y[w] = T : y[w] = new Le(T.type, T.data, T.dims);
|
|
24564
22484
|
}
|
|
24565
|
-
return ze("InferenceSession.run"),
|
|
22485
|
+
return ze("InferenceSession.run"), rt(), y;
|
|
24566
22486
|
}
|
|
24567
22487
|
async release() {
|
|
24568
22488
|
return this.handler.dispose();
|
|
24569
22489
|
}
|
|
24570
22490
|
static async create(r, s, f, i) {
|
|
24571
|
-
|
|
22491
|
+
tt(), $e("InferenceSession.create");
|
|
24572
22492
|
let d, l = {};
|
|
24573
22493
|
if (typeof r == "string") {
|
|
24574
22494
|
if (d = r, typeof s == "object" && s !== null)
|
|
@@ -24606,7 +22526,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24606
22526
|
} else
|
|
24607
22527
|
throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
|
|
24608
22528
|
let [m, y] = await Ta(l), w = await m.createInferenceSessionHandler(d, y);
|
|
24609
|
-
return ze("InferenceSession.create"),
|
|
22529
|
+
return ze("InferenceSession.create"), rt(), new a(w);
|
|
24610
22530
|
}
|
|
24611
22531
|
startProfiling() {
|
|
24612
22532
|
this.handler.startProfiling();
|
|
@@ -24630,15 +22550,15 @@ var init_transformers_node = __esm(() => {
|
|
|
24630
22550
|
});
|
|
24631
22551
|
Va = k(() => {
|
|
24632
22552
|
za();
|
|
24633
|
-
qf =
|
|
22553
|
+
qf = jt;
|
|
24634
22554
|
});
|
|
24635
22555
|
ja = k(() => {});
|
|
24636
22556
|
Ha = k(() => {});
|
|
24637
22557
|
Ya = k(() => {});
|
|
24638
22558
|
qa = k(() => {});
|
|
24639
22559
|
Zr = {};
|
|
24640
|
-
|
|
24641
|
-
|
|
22560
|
+
At(Zr, { InferenceSession: () => qf, TRACE: () => Ga, TRACE_EVENT_BEGIN: () => $e, TRACE_EVENT_END: () => ze, TRACE_FUNC_BEGIN: () => tt, TRACE_FUNC_END: () => rt, Tensor: () => Le, env: () => K, registerBackend: () => Ke });
|
|
22561
|
+
Ve = k(() => {
|
|
24642
22562
|
va();
|
|
24643
22563
|
Ia();
|
|
24644
22564
|
Va();
|
|
@@ -24651,10 +22571,10 @@ var init_transformers_node = __esm(() => {
|
|
|
24651
22571
|
});
|
|
24652
22572
|
Ht = k(() => {});
|
|
24653
22573
|
Za = {};
|
|
24654
|
-
|
|
22574
|
+
At(Za, { default: () => Jf });
|
|
24655
22575
|
Ka = k(() => {
|
|
24656
22576
|
Kr();
|
|
24657
|
-
|
|
22577
|
+
je();
|
|
24658
22578
|
Yt();
|
|
24659
22579
|
Xa = "ort-wasm-proxy-worker", Qa = globalThis.self?.name === Xa;
|
|
24660
22580
|
Qa && (self.onmessage = (a) => {
|
|
@@ -24682,7 +22602,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24682
22602
|
break;
|
|
24683
22603
|
}
|
|
24684
22604
|
case "copy-from": {
|
|
24685
|
-
let { buffer: f } = s, i =
|
|
22605
|
+
let { buffer: f } = s, i = xt(f);
|
|
24686
22606
|
postMessage({ type: r, out: i });
|
|
24687
22607
|
break;
|
|
24688
22608
|
}
|
|
@@ -24716,10 +22636,10 @@ var init_transformers_node = __esm(() => {
|
|
|
24716
22636
|
postMessage({ type: r, err: f });
|
|
24717
22637
|
}
|
|
24718
22638
|
});
|
|
24719
|
-
Jf = Qa ? null : (a) => new Worker(a ??
|
|
22639
|
+
Jf = Qa ? null : (a) => new Worker(a ?? ge, { type: "module", name: Xa });
|
|
24720
22640
|
});
|
|
24721
22641
|
ts = {};
|
|
24722
|
-
|
|
22642
|
+
At(ts, { default: () => Xf });
|
|
24723
22643
|
rs = k(() => {
|
|
24724
22644
|
Xf = es, Qf = globalThis.self?.name?.startsWith("em-pthread");
|
|
24725
22645
|
Qf && es();
|
|
@@ -24734,18 +22654,18 @@ var init_transformers_node = __esm(() => {
|
|
|
24734
22654
|
}
|
|
24735
22655
|
return import.meta.url;
|
|
24736
22656
|
}
|
|
24737
|
-
},
|
|
24738
|
-
if (
|
|
24739
|
-
return
|
|
22657
|
+
}, ge = Zf(), ss = () => {
|
|
22658
|
+
if (ge && !ge.startsWith("blob:"))
|
|
22659
|
+
return ge.substring(0, ge.lastIndexOf("/") + 1);
|
|
24740
22660
|
}, en = (a, r) => {
|
|
24741
22661
|
try {
|
|
24742
|
-
let s = r ??
|
|
22662
|
+
let s = r ?? ge;
|
|
24743
22663
|
return (s ? new URL(a, s) : new URL(a)).origin === as;
|
|
24744
22664
|
} catch {
|
|
24745
22665
|
return false;
|
|
24746
22666
|
}
|
|
24747
22667
|
}, Kf = (a, r) => {
|
|
24748
|
-
let s = r ??
|
|
22668
|
+
let s = r ?? ge;
|
|
24749
22669
|
try {
|
|
24750
22670
|
return (s ? new URL(a, s) : new URL(a)).href;
|
|
24751
22671
|
} catch {
|
|
@@ -24755,17 +22675,17 @@ var init_transformers_node = __esm(() => {
|
|
|
24755
22675
|
let s = await (await fetch(a, { credentials: "same-origin" })).blob();
|
|
24756
22676
|
return URL.createObjectURL(s);
|
|
24757
22677
|
}, tc = async (a) => (await import(a)).default, ns = (Ka(), $t(Za)).default, us = async () => {
|
|
24758
|
-
if (!
|
|
22678
|
+
if (!ge)
|
|
24759
22679
|
throw new Error("Failed to load proxy worker: cannot determine the script source URL.");
|
|
24760
|
-
if (en(
|
|
22680
|
+
if (en(ge))
|
|
24761
22681
|
return [undefined, ns()];
|
|
24762
|
-
let a = await is(
|
|
22682
|
+
let a = await is(ge);
|
|
24763
22683
|
return [a, ns(a)];
|
|
24764
22684
|
}, os2 = (rs(), $t(ts)).default, fs42 = async (a, r, s, f) => {
|
|
24765
22685
|
let i = os2 && !(a || r);
|
|
24766
22686
|
if (i)
|
|
24767
|
-
if (
|
|
24768
|
-
i = en(
|
|
22687
|
+
if (ge)
|
|
22688
|
+
i = en(ge) || f && !s;
|
|
24769
22689
|
else if (f && !s)
|
|
24770
22690
|
i = true;
|
|
24771
22691
|
else
|
|
@@ -24778,7 +22698,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24778
22698
|
}
|
|
24779
22699
|
};
|
|
24780
22700
|
});
|
|
24781
|
-
|
|
22701
|
+
je = k(() => {
|
|
24782
22702
|
Yt();
|
|
24783
22703
|
nn = false, rr = false, cs = false, rc = () => {
|
|
24784
22704
|
if (typeof SharedArrayBuffer > "u")
|
|
@@ -24849,11 +22769,11 @@ var init_transformers_node = __esm(() => {
|
|
|
24849
22769
|
};
|
|
24850
22770
|
});
|
|
24851
22771
|
nr = k(() => {
|
|
24852
|
-
|
|
24853
|
-
|
|
22772
|
+
je();
|
|
22773
|
+
be = (a, r) => {
|
|
24854
22774
|
let s = z(), f = s.lengthBytesUTF8(a) + 1, i = s._malloc(f);
|
|
24855
22775
|
return s.stringToUTF8(a, i, f), r.push(i), i;
|
|
24856
|
-
},
|
|
22776
|
+
}, Lt = (a, r, s, f) => {
|
|
24857
22777
|
if (typeof a == "object" && a !== null) {
|
|
24858
22778
|
if (s.has(a))
|
|
24859
22779
|
throw new Error("Circular reference in options");
|
|
@@ -24862,7 +22782,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24862
22782
|
Object.entries(a).forEach(([i, d]) => {
|
|
24863
22783
|
let l = r ? r + i : i;
|
|
24864
22784
|
if (typeof d == "object")
|
|
24865
|
-
|
|
22785
|
+
Lt(d, l + ".", s, f);
|
|
24866
22786
|
else if (typeof d == "string" || typeof d == "number")
|
|
24867
22787
|
f(l, d.toString());
|
|
24868
22788
|
else if (typeof d == "boolean")
|
|
@@ -24870,7 +22790,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24870
22790
|
else
|
|
24871
22791
|
throw new Error(`Can't handle extra config type: ${typeof d}`);
|
|
24872
22792
|
});
|
|
24873
|
-
}, $
|
|
22793
|
+
}, $ = (a) => {
|
|
24874
22794
|
let r = z(), s = r.stackSave();
|
|
24875
22795
|
try {
|
|
24876
22796
|
let f = r.PTR_SIZE, i = r.stackAlloc(2 * f);
|
|
@@ -24883,7 +22803,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24883
22803
|
};
|
|
24884
22804
|
});
|
|
24885
22805
|
ls = k(() => {
|
|
24886
|
-
|
|
22806
|
+
je();
|
|
24887
22807
|
nr();
|
|
24888
22808
|
ds = (a) => {
|
|
24889
22809
|
let r = z(), s = 0, f = [], i = a || {};
|
|
@@ -24898,9 +22818,9 @@ var init_transformers_node = __esm(() => {
|
|
|
24898
22818
|
throw new Error(`log verbosity level is not valid: ${a.logVerbosityLevel}`);
|
|
24899
22819
|
a?.terminate === undefined && (i.terminate = false);
|
|
24900
22820
|
let d = 0;
|
|
24901
|
-
return a?.tag !== undefined && (d =
|
|
24902
|
-
let y =
|
|
24903
|
-
r._OrtAddRunConfigEntry(s, y, w) !== 0 && $
|
|
22821
|
+
return a?.tag !== undefined && (d = be(a.tag, f)), s = r._OrtCreateRunOptions(i.logSeverityLevel, i.logVerbosityLevel, !!i.terminate, d), s === 0 && $("Can't create run options."), a?.extra !== undefined && Lt(a.extra, "", /* @__PURE__ */ new WeakSet, (l, m) => {
|
|
22822
|
+
let y = be(l, f), w = be(m, f);
|
|
22823
|
+
r._OrtAddRunConfigEntry(s, y, w) !== 0 && $(`Can't set a run config entry: ${l} - ${m}.`);
|
|
24904
22824
|
}), [s, f];
|
|
24905
22825
|
} catch (d) {
|
|
24906
22826
|
throw s !== 0 && r._OrtReleaseRunOptions(s), f.forEach((l) => r._free(l)), d;
|
|
@@ -24908,7 +22828,7 @@ var init_transformers_node = __esm(() => {
|
|
|
24908
22828
|
};
|
|
24909
22829
|
});
|
|
24910
22830
|
ms = k(() => {
|
|
24911
|
-
|
|
22831
|
+
je();
|
|
24912
22832
|
nr();
|
|
24913
22833
|
ac = (a) => {
|
|
24914
22834
|
switch (a) {
|
|
@@ -24939,10 +22859,10 @@ var init_transformers_node = __esm(() => {
|
|
|
24939
22859
|
let r = a.extra.session;
|
|
24940
22860
|
r.use_ort_model_bytes_directly || (r.use_ort_model_bytes_directly = "1"), a.executionProviders && a.executionProviders.some((s) => (typeof s == "string" ? s : s.name) === "webgpu") && (a.enableMemPattern = false);
|
|
24941
22861
|
}, on = (a, r, s, f) => {
|
|
24942
|
-
let i =
|
|
24943
|
-
z()._OrtAddSessionConfigEntry(a, i, d) !== 0 && $
|
|
24944
|
-
},
|
|
24945
|
-
let i =
|
|
22862
|
+
let i = be(r, f), d = be(s, f);
|
|
22863
|
+
z()._OrtAddSessionConfigEntry(a, i, d) !== 0 && $(`Can't set a session config entry: ${r} - ${s}.`);
|
|
22864
|
+
}, ot = (a, r, s, f) => {
|
|
22865
|
+
let i = be(r, f), d = be(s, f);
|
|
24946
22866
|
a.push([i, d]);
|
|
24947
22867
|
}, uc = async (a, r, s) => {
|
|
24948
22868
|
let f = r.executionProviders;
|
|
@@ -24967,17 +22887,17 @@ var init_transformers_node = __esm(() => {
|
|
|
24967
22887
|
else
|
|
24968
22888
|
throw new Error("Invalid GPU device set in WebGPU EP options.");
|
|
24969
22889
|
let { enableGraphCapture: C } = r;
|
|
24970
|
-
if (typeof C == "boolean" && C &&
|
|
22890
|
+
if (typeof C == "boolean" && C && ot(l, "enableGraphCapture", "1", s), typeof S.preferredLayout == "string" && ot(l, "preferredLayout", S.preferredLayout, s), S.forceCpuNodeNames) {
|
|
24971
22891
|
let R = Array.isArray(S.forceCpuNodeNames) ? S.forceCpuNodeNames : [S.forceCpuNodeNames];
|
|
24972
|
-
|
|
22892
|
+
ot(l, "forceCpuNodeNames", R.join(`
|
|
24973
22893
|
`), s);
|
|
24974
22894
|
}
|
|
24975
|
-
S.validationMode &&
|
|
22895
|
+
S.validationMode && ot(l, "validationMode", S.validationMode, s);
|
|
24976
22896
|
}
|
|
24977
22897
|
let v = z().webgpuRegisterDevice(g);
|
|
24978
22898
|
if (v) {
|
|
24979
22899
|
let [S, C, R] = v;
|
|
24980
|
-
|
|
22900
|
+
ot(l, "deviceId", S.toString(), s), ot(l, "webgpuInstance", C.toString(), s), ot(l, "webgpuDevice", R.toString(), s);
|
|
24981
22901
|
}
|
|
24982
22902
|
}
|
|
24983
22903
|
break;
|
|
@@ -24987,26 +22907,26 @@ var init_transformers_node = __esm(() => {
|
|
|
24987
22907
|
default:
|
|
24988
22908
|
throw new Error(`not supported execution provider: ${d}`);
|
|
24989
22909
|
}
|
|
24990
|
-
let m =
|
|
22910
|
+
let m = be(d, s), y = l.length, w = 0, T = 0;
|
|
24991
22911
|
if (y > 0) {
|
|
24992
22912
|
w = z()._malloc(y * z().PTR_SIZE), s.push(w), T = z()._malloc(y * z().PTR_SIZE), s.push(T);
|
|
24993
22913
|
for (let g = 0;g < y; g++)
|
|
24994
22914
|
z().setValue(w + g * z().PTR_SIZE, l[g][0], "*"), z().setValue(T + g * z().PTR_SIZE, l[g][1], "*");
|
|
24995
22915
|
}
|
|
24996
|
-
await z()._OrtAppendExecutionProvider(a, m, w, T, y) !== 0 && $
|
|
22916
|
+
await z()._OrtAppendExecutionProvider(a, m, w, T, y) !== 0 && $(`Can't append execution provider: ${d}.`);
|
|
24997
22917
|
}
|
|
24998
22918
|
}, ps = async (a) => {
|
|
24999
22919
|
let r = z(), s = 0, f = [], i = a || {};
|
|
25000
22920
|
ic(i);
|
|
25001
22921
|
try {
|
|
25002
|
-
let d = ac(i.graphOptimizationLevel ?? "all"), l = sc(i.executionMode ?? "sequential"), m = typeof i.logId == "string" ?
|
|
22922
|
+
let d = ac(i.graphOptimizationLevel ?? "all"), l = sc(i.executionMode ?? "sequential"), m = typeof i.logId == "string" ? be(i.logId, f) : 0, y = i.logSeverityLevel ?? 2;
|
|
25003
22923
|
if (!Number.isInteger(y) || y < 0 || y > 4)
|
|
25004
22924
|
throw new Error(`log severity level is not valid: ${y}`);
|
|
25005
22925
|
let w = i.logVerbosityLevel ?? 0;
|
|
25006
22926
|
if (!Number.isInteger(w) || w < 0 || w > 4)
|
|
25007
22927
|
throw new Error(`log verbosity level is not valid: ${w}`);
|
|
25008
|
-
let T = typeof i.optimizedModelFilePath == "string" ?
|
|
25009
|
-
if (s = r._OrtCreateSessionOptions(d, !!i.enableCpuMemArena, !!i.enableMemPattern, l, !!i.enableProfiling, 0, m, y, w, T), s === 0 && $
|
|
22928
|
+
let T = typeof i.optimizedModelFilePath == "string" ? be(i.optimizedModelFilePath, f) : 0;
|
|
22929
|
+
if (s = r._OrtCreateSessionOptions(d, !!i.enableCpuMemArena, !!i.enableMemPattern, l, !!i.enableProfiling, 0, m, y, w, T), s === 0 && $("Can't create session options."), i.executionProviders && await uc(s, i, f), i.enableGraphCapture !== undefined) {
|
|
25010
22930
|
if (typeof i.enableGraphCapture != "boolean")
|
|
25011
22931
|
throw new Error(`enableGraphCapture must be a boolean value: ${i.enableGraphCapture}`);
|
|
25012
22932
|
on(s, "enableGraphCapture", i.enableGraphCapture.toString(), f);
|
|
@@ -25017,18 +22937,18 @@ var init_transformers_node = __esm(() => {
|
|
|
25017
22937
|
throw new Error(`free dimension override name must be a string: ${g}`);
|
|
25018
22938
|
if (typeof v != "number" || !Number.isInteger(v) || v < 0)
|
|
25019
22939
|
throw new Error(`free dimension override value must be a non-negative integer: ${v}`);
|
|
25020
|
-
let S =
|
|
25021
|
-
r._OrtAddFreeDimensionOverride(s, S, v) !== 0 && $
|
|
22940
|
+
let S = be(g, f);
|
|
22941
|
+
r._OrtAddFreeDimensionOverride(s, S, v) !== 0 && $(`Can't set a free dimension override: ${g} - ${v}.`);
|
|
25022
22942
|
}
|
|
25023
|
-
return i.extra !== undefined &&
|
|
22943
|
+
return i.extra !== undefined && Lt(i.extra, "", /* @__PURE__ */ new WeakSet, (g, v) => {
|
|
25024
22944
|
on(s, g, v, f);
|
|
25025
22945
|
}), [s, f];
|
|
25026
22946
|
} catch (d) {
|
|
25027
|
-
throw s !== 0 && r._OrtReleaseSessionOptions(s) !== 0 && $
|
|
22947
|
+
throw s !== 0 && r._OrtReleaseSessionOptions(s) !== 0 && $("Can't release session options."), f.forEach((l) => r._free(l)), d;
|
|
25028
22948
|
}
|
|
25029
22949
|
};
|
|
25030
22950
|
});
|
|
25031
|
-
|
|
22951
|
+
st = k(() => {
|
|
25032
22952
|
He = (a) => {
|
|
25033
22953
|
switch (a) {
|
|
25034
22954
|
case "int8":
|
|
@@ -25099,10 +23019,10 @@ var init_transformers_node = __esm(() => {
|
|
|
25099
23019
|
default:
|
|
25100
23020
|
throw new Error(`unsupported data type: ${a}`);
|
|
25101
23021
|
}
|
|
25102
|
-
},
|
|
23022
|
+
}, mt = (a, r) => {
|
|
25103
23023
|
let s = [-1, 4, 1, 1, 2, 2, 4, 8, -1, 1, 2, 8, 4, 8, -1, -1, -1, -1, -1, -1, -1, 0.5, 0.5][a], f = typeof r == "number" ? r : r.reduce((i, d) => i * d, 1);
|
|
25104
23024
|
return s > 0 ? Math.ceil(f * s) : undefined;
|
|
25105
|
-
},
|
|
23025
|
+
}, at = (a) => {
|
|
25106
23026
|
switch (a) {
|
|
25107
23027
|
case "float16":
|
|
25108
23028
|
return typeof Float16Array < "u" && Float16Array.from ? Float16Array : Uint16Array;
|
|
@@ -25131,7 +23051,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25131
23051
|
default:
|
|
25132
23052
|
throw new Error(`unsupported type: ${a}`);
|
|
25133
23053
|
}
|
|
25134
|
-
},
|
|
23054
|
+
}, Ot = (a) => {
|
|
25135
23055
|
switch (a) {
|
|
25136
23056
|
case "verbose":
|
|
25137
23057
|
return 0;
|
|
@@ -25167,7 +23087,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25167
23087
|
});
|
|
25168
23088
|
sn = k(() => {
|
|
25169
23089
|
Ht();
|
|
25170
|
-
|
|
23090
|
+
Bt = async (a) => {
|
|
25171
23091
|
if (typeof a == "string")
|
|
25172
23092
|
if (false)
|
|
25173
23093
|
;
|
|
@@ -25207,24 +23127,24 @@ var init_transformers_node = __esm(() => {
|
|
|
25207
23127
|
};
|
|
25208
23128
|
});
|
|
25209
23129
|
ys = k(() => {
|
|
25210
|
-
|
|
25211
|
-
hs = (a, r) => new (
|
|
23130
|
+
st();
|
|
23131
|
+
hs = (a, r) => new (at(r))(a);
|
|
25212
23132
|
});
|
|
25213
23133
|
un = k(() => {
|
|
25214
|
-
|
|
23134
|
+
st();
|
|
25215
23135
|
fc = ["V", "I", "W", "E", "F"], cc = (a, r) => {
|
|
25216
23136
|
console.log(`[${fc[a]},${(/* @__PURE__ */ new Date()).toISOString()}]${r}`);
|
|
25217
23137
|
}, gs = (a, r) => {
|
|
25218
23138
|
bs = a, ws = r;
|
|
25219
23139
|
}, dc = (a, r) => {
|
|
25220
|
-
let s =
|
|
23140
|
+
let s = Ot(a), f = Ot(bs);
|
|
25221
23141
|
s >= f && cc(s, typeof r == "function" ? r() : r);
|
|
25222
|
-
},
|
|
23142
|
+
}, pe = (...a) => {
|
|
25223
23143
|
ws && dc(...a);
|
|
25224
23144
|
};
|
|
25225
23145
|
});
|
|
25226
23146
|
Is = k(() => {
|
|
25227
|
-
|
|
23147
|
+
st();
|
|
25228
23148
|
un();
|
|
25229
23149
|
vs = /* @__PURE__ */ new Map([["float32", 32], ["float16", 16], ["int32", 32], ["uint32", 32], ["int64", 64], ["uint64", 64], ["int8", 8], ["uint8", 8], ["int4", 4], ["uint4", 4]]), cn = (a, r) => {
|
|
25230
23150
|
if (r === "int32")
|
|
@@ -25235,7 +23155,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25235
23155
|
let f = s / 8;
|
|
25236
23156
|
if (a.byteLength % f !== 0)
|
|
25237
23157
|
throw new Error(`Invalid Uint8Array length - must be a multiple of ${f}.`);
|
|
25238
|
-
let i = a.byteLength / f, d = new (
|
|
23158
|
+
let i = a.byteLength / f, d = new (at(r))(a.buffer, a.byteOffset, i);
|
|
25239
23159
|
switch (r) {
|
|
25240
23160
|
case "int64":
|
|
25241
23161
|
case "uint64": {
|
|
@@ -25323,7 +23243,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25323
23243
|
return Ss(this.dataType, this.tensorShape);
|
|
25324
23244
|
}
|
|
25325
23245
|
destroy() {
|
|
25326
|
-
|
|
23246
|
+
pe("verbose", () => "[WebNN] TensorWrapper.destroy"), this.mlTensor.destroy();
|
|
25327
23247
|
}
|
|
25328
23248
|
write(r) {
|
|
25329
23249
|
this.mlContext.writeTensor(this.mlTensor, r);
|
|
@@ -25361,7 +23281,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25361
23281
|
if (!l?.input.dataTypes.includes(s)) {
|
|
25362
23282
|
if (m = pc.get(s), !m || l?.input.dataTypes.includes(m))
|
|
25363
23283
|
throw new Error(`WebNN backend does not support data type: ${s}`);
|
|
25364
|
-
|
|
23284
|
+
pe("verbose", () => `[WebNN] TensorIdTracker.ensureTensor: fallback dataType from ${s} to ${m}`);
|
|
25365
23285
|
}
|
|
25366
23286
|
if (this.wrapper) {
|
|
25367
23287
|
if (this.wrapper.canReuseTensor(d, s, f))
|
|
@@ -25388,7 +23308,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25388
23308
|
this.wrapper.write(s);
|
|
25389
23309
|
return;
|
|
25390
23310
|
} else
|
|
25391
|
-
|
|
23311
|
+
pe("verbose", () => "Data size does not match tensor size. Releasing tensor."), this.releaseTensor();
|
|
25392
23312
|
}
|
|
25393
23313
|
this.activeUpload ? this.activeUpload.set(s) : this.activeUpload = new Uint8Array(s);
|
|
25394
23314
|
}
|
|
@@ -25430,7 +23350,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25430
23350
|
s && (this.tensorTrackersById.delete(r), s.tensorWrapper && this.releaseTensor(s.tensorWrapper));
|
|
25431
23351
|
}
|
|
25432
23352
|
async ensureTensor(r, s, f, i, d) {
|
|
25433
|
-
|
|
23353
|
+
pe("verbose", () => `[WebNN] TensorManager.ensureTensor {tensorId: ${s}, dataType: ${f}, shape: ${i}, copyOld: ${d}}`);
|
|
25434
23354
|
let l = this.tensorTrackersById.get(s);
|
|
25435
23355
|
if (!l)
|
|
25436
23356
|
throw new Error("Tensor not found.");
|
|
@@ -25443,7 +23363,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25443
23363
|
f.upload(s);
|
|
25444
23364
|
}
|
|
25445
23365
|
async download(r, s) {
|
|
25446
|
-
|
|
23366
|
+
pe("verbose", () => `[WebNN] TensorManager.download {tensorId: ${r}, dstBuffer: ${s?.byteLength}}`);
|
|
25447
23367
|
let f = this.tensorTrackersById.get(r);
|
|
25448
23368
|
if (!f)
|
|
25449
23369
|
throw new Error("Tensor not found.");
|
|
@@ -25462,11 +23382,11 @@ var init_transformers_node = __esm(() => {
|
|
|
25462
23382
|
let y = this.getMLContext(r);
|
|
25463
23383
|
for (let [T, g] of this.freeTensors.entries())
|
|
25464
23384
|
if (g.canReuseTensor(y, s, f)) {
|
|
25465
|
-
|
|
23385
|
+
pe("verbose", () => `[WebNN] Reusing tensor {dataType: ${s}, ${m ? `fallbackDataType: ${m},` : ""} shape: ${f}`);
|
|
25466
23386
|
let v = this.freeTensors.splice(T, 1)[0];
|
|
25467
23387
|
return v.sessionId = r, v;
|
|
25468
23388
|
}
|
|
25469
|
-
|
|
23389
|
+
pe("verbose", () => `[WebNN] MLContext.createTensor {dataType: ${s}, ${m ? `fallbackDataType: ${m},` : ""} shape: ${f}}`);
|
|
25470
23390
|
let w = await y.createTensor({ dataType: m ?? s, shape: f, dimensions: f, usage: i, writable: d, readable: l });
|
|
25471
23391
|
return new ir({ sessionId: r, context: y, tensor: w, dataType: s, shape: f, fallbackDataType: m });
|
|
25472
23392
|
}
|
|
@@ -25476,10 +23396,10 @@ var init_transformers_node = __esm(() => {
|
|
|
25476
23396
|
}, As = (...a) => new fn(...a);
|
|
25477
23397
|
});
|
|
25478
23398
|
xs = {};
|
|
25479
|
-
|
|
23399
|
+
At(xs, { WebNNBackend: () => dn });
|
|
25480
23400
|
Ls = k(() => {
|
|
25481
|
-
|
|
25482
|
-
|
|
23401
|
+
st();
|
|
23402
|
+
je();
|
|
25483
23403
|
ys();
|
|
25484
23404
|
Is();
|
|
25485
23405
|
un();
|
|
@@ -25510,14 +23430,14 @@ var init_transformers_node = __esm(() => {
|
|
|
25510
23430
|
return this.activeSessionId;
|
|
25511
23431
|
}
|
|
25512
23432
|
onRunStart(r) {
|
|
25513
|
-
|
|
23433
|
+
pe("verbose", () => `[WebNN] onRunStart {sessionId: ${r}}`), this.activeSessionId = r;
|
|
25514
23434
|
}
|
|
25515
23435
|
onRunEnd(r) {
|
|
25516
|
-
|
|
23436
|
+
pe("verbose", () => `[WebNN] onRunEnd {sessionId: ${r}}`);
|
|
25517
23437
|
let s = this.temporarySessionTensorIds.get(r);
|
|
25518
23438
|
if (s) {
|
|
25519
23439
|
for (let f of s)
|
|
25520
|
-
|
|
23440
|
+
pe("verbose", () => `[WebNN] releasing temporary tensor {tensorId: ${f}}`), this.tensorManager.releaseTensorId(f);
|
|
25521
23441
|
this.temporarySessionTensorIds.delete(r), this.activeSessionId = undefined;
|
|
25522
23442
|
}
|
|
25523
23443
|
}
|
|
@@ -25575,7 +23495,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25575
23495
|
return this.tensorManager.reserveTensorId();
|
|
25576
23496
|
}
|
|
25577
23497
|
releaseTensorId(r) {
|
|
25578
|
-
|
|
23498
|
+
pe("verbose", () => `[WebNN] releaseTensorId {tensorId: ${r}}`), this.tensorManager.releaseTensorId(r);
|
|
25579
23499
|
}
|
|
25580
23500
|
async ensureTensor(r, s, f, i, d) {
|
|
25581
23501
|
let l = fr.get(f);
|
|
@@ -25584,7 +23504,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25584
23504
|
return this.tensorManager.ensureTensor(r ?? this.currentSessionId, s, l, i, d);
|
|
25585
23505
|
}
|
|
25586
23506
|
async createTemporaryTensor(r, s, f) {
|
|
25587
|
-
|
|
23507
|
+
pe("verbose", () => `[WebNN] createTemporaryTensor {onnxDataType: ${s}, shape: ${f}}`);
|
|
25588
23508
|
let i = fr.get(s);
|
|
25589
23509
|
if (!i)
|
|
25590
23510
|
throw new Error(`Unsupported ONNX data type: ${s}`);
|
|
@@ -25596,7 +23516,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25596
23516
|
uploadTensor(r, s) {
|
|
25597
23517
|
if (!z().shouldTransferToMLTensor)
|
|
25598
23518
|
throw new Error("Trying to upload to a MLTensor while shouldTransferToMLTensor is false");
|
|
25599
|
-
|
|
23519
|
+
pe("verbose", () => `[WebNN] uploadTensor {tensorId: ${r}, data: ${s.byteLength}}`), this.tensorManager.upload(r, s);
|
|
25600
23520
|
}
|
|
25601
23521
|
async downloadTensor(r, s) {
|
|
25602
23522
|
return this.tensorManager.download(r, s);
|
|
@@ -25612,7 +23532,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25612
23532
|
if (!d)
|
|
25613
23533
|
throw new Error(`Unsupported ONNX data type: ${f}`);
|
|
25614
23534
|
let l = this.tensorManager.registerTensor(r, s, d, i);
|
|
25615
|
-
return
|
|
23535
|
+
return pe("verbose", () => `[WebNN] registerMLTensor {tensor: ${s}, dataType: ${d}, dimensions: ${i}} -> {tensorId: ${l}}`), l;
|
|
25616
23536
|
}
|
|
25617
23537
|
registerMLConstant(r, s, f, i, d, l, m = false) {
|
|
25618
23538
|
if (!l)
|
|
@@ -25659,7 +23579,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25659
23579
|
default:
|
|
25660
23580
|
throw new Error(`Unsupported data type: ${d.dataType} in creating WebNN Constant from external data.`);
|
|
25661
23581
|
}
|
|
25662
|
-
return
|
|
23582
|
+
return pe("verbose", () => `[WebNN] registerMLConstant {dataType: ${d.dataType}, shape: ${d.shape}}} ${m ? "(Note: it was int64 data type and registered to int32 as workaround)" : ""}`), i.constant(d, g);
|
|
25663
23583
|
}
|
|
25664
23584
|
registerGraphInput(r) {
|
|
25665
23585
|
this.temporaryGraphInputs.push(r);
|
|
@@ -25683,17 +23603,17 @@ var init_transformers_node = __esm(() => {
|
|
|
25683
23603
|
};
|
|
25684
23604
|
});
|
|
25685
23605
|
Kr = k(() => {
|
|
25686
|
-
|
|
23606
|
+
Ve();
|
|
25687
23607
|
ls();
|
|
25688
23608
|
ms();
|
|
25689
|
-
|
|
25690
|
-
|
|
23609
|
+
st();
|
|
23610
|
+
je();
|
|
25691
23611
|
nr();
|
|
25692
23612
|
sn();
|
|
25693
23613
|
hc = (a, r) => {
|
|
25694
|
-
z()._OrtInit(a, r) !== 0 && $
|
|
23614
|
+
z()._OrtInit(a, r) !== 0 && $("Can't initialize onnxruntime.");
|
|
25695
23615
|
}, Jt = async (a) => {
|
|
25696
|
-
hc(a.wasm.numThreads,
|
|
23616
|
+
hc(a.wasm.numThreads, Ot(a.logLevel));
|
|
25697
23617
|
}, Xt = async (a, r) => {
|
|
25698
23618
|
z().asyncInit?.();
|
|
25699
23619
|
let s = a.webgpu.adapter;
|
|
@@ -25724,11 +23644,11 @@ var init_transformers_node = __esm(() => {
|
|
|
25724
23644
|
f.uploadTensor(i, d);
|
|
25725
23645
|
}, async (i, d) => f.downloadTensor(i, d), (i, d) => f.registerMLContext(i, d), !!a.trace]);
|
|
25726
23646
|
}
|
|
25727
|
-
},
|
|
23647
|
+
}, it = /* @__PURE__ */ new Map, yc = (a) => {
|
|
25728
23648
|
let r = z(), s = r.stackSave();
|
|
25729
23649
|
try {
|
|
25730
23650
|
let f = r.PTR_SIZE, i = r.stackAlloc(2 * f);
|
|
25731
|
-
r._OrtGetInputOutputCount(a, i, i + f) !== 0 && $
|
|
23651
|
+
r._OrtGetInputOutputCount(a, i, i + f) !== 0 && $("Can't get session input/output count.");
|
|
25732
23652
|
let l = f === 4 ? "i32" : "i64";
|
|
25733
23653
|
return [Number(r.getValue(i, l)), Number(r.getValue(i + f, l))];
|
|
25734
23654
|
} finally {
|
|
@@ -25738,7 +23658,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25738
23658
|
let s = z(), f = s.stackSave(), i = 0;
|
|
25739
23659
|
try {
|
|
25740
23660
|
let d = s.PTR_SIZE, l = s.stackAlloc(2 * d);
|
|
25741
|
-
s._OrtGetInputOutputMetadata(a, r, l, l + d) !== 0 && $
|
|
23661
|
+
s._OrtGetInputOutputMetadata(a, r, l, l + d) !== 0 && $("Can't get session input/output metadata.");
|
|
25742
23662
|
let y = Number(s.getValue(l, "*"));
|
|
25743
23663
|
i = Number(s.getValue(l + d, "*"));
|
|
25744
23664
|
let w = s.HEAP32[i / 4];
|
|
@@ -25753,21 +23673,21 @@ var init_transformers_node = __esm(() => {
|
|
|
25753
23673
|
} finally {
|
|
25754
23674
|
s.stackRestore(f), i !== 0 && s._OrtFree(i);
|
|
25755
23675
|
}
|
|
25756
|
-
},
|
|
23676
|
+
}, xt = (a) => {
|
|
25757
23677
|
let r = z(), s = r._malloc(a.byteLength);
|
|
25758
23678
|
if (s === 0)
|
|
25759
23679
|
throw new Error(`Can't create a session. failed to allocate a buffer of size ${a.byteLength}.`);
|
|
25760
23680
|
return r.HEAPU8.set(a, s), [s, a.byteLength];
|
|
25761
23681
|
}, Qt = async (a, r) => {
|
|
25762
23682
|
let s, f, i = z();
|
|
25763
|
-
Array.isArray(a) ? [s, f] = a : a.buffer === i.HEAPU8.buffer ? [s, f] = [a.byteOffset, a.byteLength] : [s, f] =
|
|
23683
|
+
Array.isArray(a) ? [s, f] = a : a.buffer === i.HEAPU8.buffer ? [s, f] = [a.byteOffset, a.byteLength] : [s, f] = xt(a);
|
|
25764
23684
|
let d = 0, l = 0, m = 0, y = [], w = [], T = [];
|
|
25765
23685
|
try {
|
|
25766
23686
|
if ([l, y] = await ps(r), r?.externalData && i.mountExternalData) {
|
|
25767
23687
|
let O = [];
|
|
25768
23688
|
for (let W of r.externalData) {
|
|
25769
23689
|
let oe = typeof W == "string" ? W : W.path;
|
|
25770
|
-
O.push(
|
|
23690
|
+
O.push(Bt(typeof W == "string" ? W : W.data).then((p) => {
|
|
25771
23691
|
i.mountExternalData(oe, p);
|
|
25772
23692
|
}));
|
|
25773
23693
|
}
|
|
@@ -25782,17 +23702,17 @@ var init_transformers_node = __esm(() => {
|
|
|
25782
23702
|
i.currentContext = await i.webnnCreateMLContext();
|
|
25783
23703
|
break;
|
|
25784
23704
|
}
|
|
25785
|
-
d = await i._OrtCreateSession(s, f, l), i.webgpuOnCreateSession?.(d), d === 0 && $
|
|
23705
|
+
d = await i._OrtCreateSession(s, f, l), i.webgpuOnCreateSession?.(d), d === 0 && $("Can't create a session."), i.jsepOnCreateSession?.(), i.currentContext && (i.webnnRegisterMLContext(d, i.currentContext), i.currentContext = undefined, i.shouldTransferToMLTensor = true);
|
|
25786
23706
|
let [g, v] = yc(d), S = !!r?.enableGraphCapture, C = [], R = [], H = [], U = [], M = [];
|
|
25787
23707
|
for (let O = 0;O < g; O++) {
|
|
25788
23708
|
let [W, oe, p] = Os(d, O);
|
|
25789
|
-
W === 0 && $
|
|
23709
|
+
W === 0 && $("Can't get an input name."), w.push(W);
|
|
25790
23710
|
let ne = i.UTF8ToString(W);
|
|
25791
23711
|
C.push(ne), H.push(oe === 0 ? { name: ne, isTensor: false } : { name: ne, isTensor: true, type: or(oe), shape: p });
|
|
25792
23712
|
}
|
|
25793
23713
|
for (let O = 0;O < v; O++) {
|
|
25794
23714
|
let [W, oe, p] = Os(d, O + g);
|
|
25795
|
-
W === 0 && $
|
|
23715
|
+
W === 0 && $("Can't get an output name."), T.push(W);
|
|
25796
23716
|
let ne = i.UTF8ToString(W);
|
|
25797
23717
|
R.push(ne), U.push(oe === 0 ? { name: ne, isTensor: false } : { name: ne, isTensor: true, type: or(oe), shape: p });
|
|
25798
23718
|
{
|
|
@@ -25813,18 +23733,18 @@ var init_transformers_node = __esm(() => {
|
|
|
25813
23733
|
}
|
|
25814
23734
|
}
|
|
25815
23735
|
let Y = null;
|
|
25816
|
-
return M.some((O) => O === "gpu-buffer" || O === "ml-tensor" || O === "ml-tensor-cpu-output") && (m = i._OrtCreateBinding(d), m === 0 && $
|
|
23736
|
+
return M.some((O) => O === "gpu-buffer" || O === "ml-tensor" || O === "ml-tensor-cpu-output") && (m = i._OrtCreateBinding(d), m === 0 && $("Can't create IO binding."), Y = { handle: m, outputPreferredLocations: M, outputPreferredLocationsEncoded: M.map((O) => O === "ml-tensor-cpu-output" ? "ml-tensor" : O).map((O) => an(O)) }), it.set(d, [d, w, T, Y, S, false]), [d, C, R, H, U];
|
|
25817
23737
|
} catch (g) {
|
|
25818
|
-
throw w.forEach((v) => i._OrtFree(v)), T.forEach((v) => i._OrtFree(v)), m !== 0 && i._OrtReleaseBinding(m) !== 0 && $
|
|
23738
|
+
throw w.forEach((v) => i._OrtFree(v)), T.forEach((v) => i._OrtFree(v)), m !== 0 && i._OrtReleaseBinding(m) !== 0 && $("Can't release IO binding."), d !== 0 && i._OrtReleaseSession(d) !== 0 && $("Can't release session."), g;
|
|
25819
23739
|
} finally {
|
|
25820
|
-
i._free(s), l !== 0 && i._OrtReleaseSessionOptions(l) !== 0 && $
|
|
23740
|
+
i._free(s), l !== 0 && i._OrtReleaseSessionOptions(l) !== 0 && $("Can't release session options."), y.forEach((g) => i._free(g)), i.unmountExternalData?.();
|
|
25821
23741
|
}
|
|
25822
23742
|
}, Zt = (a) => {
|
|
25823
|
-
let r = z(), s =
|
|
23743
|
+
let r = z(), s = it.get(a);
|
|
25824
23744
|
if (!s)
|
|
25825
23745
|
throw new Error(`cannot release session. invalid session id: ${a}`);
|
|
25826
23746
|
let [f, i, d, l, m] = s;
|
|
25827
|
-
l && (m && r._OrtClearBoundOutputs(l.handle) !== 0 && $
|
|
23747
|
+
l && (m && r._OrtClearBoundOutputs(l.handle) !== 0 && $("Can't clear bound outputs."), r._OrtReleaseBinding(l.handle) !== 0 && $("Can't release IO binding.")), r.jsepOnReleaseSession?.(a), r.webnnOnReleaseSession?.(a), r.webgpuOnReleaseSession?.(a), i.forEach((y) => r._OrtFree(y)), d.forEach((y) => r._OrtFree(y)), r._OrtReleaseSession(f) !== 0 && $("Can't release session."), it.delete(a);
|
|
25828
23748
|
}, Bs = async (a, r, s, f, i, d, l = false) => {
|
|
25829
23749
|
if (!a) {
|
|
25830
23750
|
r.push(0);
|
|
@@ -25837,7 +23757,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25837
23757
|
throw new Error(`External buffer must be provided for input/output index ${d} when enableGraphCapture is true.`);
|
|
25838
23758
|
if (g === "gpu-buffer") {
|
|
25839
23759
|
let U = a[2].gpuBuffer;
|
|
25840
|
-
C =
|
|
23760
|
+
C = mt(He(w), T);
|
|
25841
23761
|
{
|
|
25842
23762
|
let M = m.webgpuRegisterBuffer;
|
|
25843
23763
|
if (!M)
|
|
@@ -25846,7 +23766,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25846
23766
|
}
|
|
25847
23767
|
} else if (g === "ml-tensor") {
|
|
25848
23768
|
let U = a[2].mlTensor;
|
|
25849
|
-
C =
|
|
23769
|
+
C = mt(He(w), T);
|
|
25850
23770
|
let M = m.webnnRegisterMLTensor;
|
|
25851
23771
|
if (!M)
|
|
25852
23772
|
throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
|
|
@@ -25858,7 +23778,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25858
23778
|
for (let M = 0;M < U.length; M++) {
|
|
25859
23779
|
if (typeof U[M] != "string")
|
|
25860
23780
|
throw new TypeError(`tensor data at index ${M} is not a string`);
|
|
25861
|
-
m.setValue(S + M * y,
|
|
23781
|
+
m.setValue(S + M * y, be(U[M], s), "*");
|
|
25862
23782
|
}
|
|
25863
23783
|
} else {
|
|
25864
23784
|
let { webnnIsGraphInput: M, webnnIsGraphOutput: Y } = m;
|
|
@@ -25866,7 +23786,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25866
23786
|
let O = m.UTF8ToString(i);
|
|
25867
23787
|
if (M(f, O) || Y(f, O)) {
|
|
25868
23788
|
let W = He(w);
|
|
25869
|
-
C =
|
|
23789
|
+
C = mt(W, T), v = "ml-tensor";
|
|
25870
23790
|
let { webnnCreateTemporaryTensor: oe, webnnUploadTensor: p } = m;
|
|
25871
23791
|
if (!oe || !p)
|
|
25872
23792
|
throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
|
|
@@ -25882,17 +23802,17 @@ var init_transformers_node = __esm(() => {
|
|
|
25882
23802
|
try {
|
|
25883
23803
|
T.forEach((M, Y) => m.setValue(H + Y * y, M, y === 4 ? "i32" : "i64"));
|
|
25884
23804
|
let U = m._OrtCreateTensor(He(w), S, C, H, T.length, an(v));
|
|
25885
|
-
U === 0 && $
|
|
23805
|
+
U === 0 && $(`Can't create tensor for input/output. session=${f}, index=${d}.`), r.push(U);
|
|
25886
23806
|
} finally {
|
|
25887
23807
|
m.stackRestore(R);
|
|
25888
23808
|
}
|
|
25889
23809
|
}, Kt = async (a, r, s, f, i, d) => {
|
|
25890
|
-
let l = z(), m = l.PTR_SIZE, y =
|
|
23810
|
+
let l = z(), m = l.PTR_SIZE, y = it.get(a);
|
|
25891
23811
|
if (!y)
|
|
25892
23812
|
throw new Error(`cannot run inference. invalid session id: ${a}`);
|
|
25893
23813
|
let w = y[0], T = y[1], g = y[2], v = y[3], S = y[4], C = y[5], R = r.length, H = f.length, U = 0, M = [], Y = [], O = [], W = [], oe = [], p = l.stackSave(), ne = l.stackAlloc(R * m), X = l.stackAlloc(R * m), J = l.stackAlloc(H * m), Ue = l.stackAlloc(H * m);
|
|
25894
23814
|
try {
|
|
25895
|
-
[U, M] = ds(d), $
|
|
23815
|
+
[U, M] = ds(d), $e("wasm prepareInputOutputTensor");
|
|
25896
23816
|
for (let _ = 0;_ < R; _++)
|
|
25897
23817
|
await Bs(s[_], Y, W, a, T[r[_]], r[_], S);
|
|
25898
23818
|
for (let _ = 0;_ < H; _++)
|
|
@@ -25906,37 +23826,37 @@ var init_transformers_node = __esm(() => {
|
|
|
25906
23826
|
let { handle: _, outputPreferredLocations: ae, outputPreferredLocationsEncoded: me } = v;
|
|
25907
23827
|
if (T.length !== R)
|
|
25908
23828
|
throw new Error(`input count from feeds (${R}) is expected to be always equal to model's input count (${T.length}).`);
|
|
25909
|
-
$
|
|
23829
|
+
$e("wasm bindInputsOutputs");
|
|
25910
23830
|
for (let q = 0;q < R; q++) {
|
|
25911
23831
|
let we = r[q];
|
|
25912
|
-
await l._OrtBindInput(_, T[we], Y[q]) !== 0 && $
|
|
23832
|
+
await l._OrtBindInput(_, T[we], Y[q]) !== 0 && $(`Can't bind input[${q}] for session=${a}.`);
|
|
25913
23833
|
}
|
|
25914
23834
|
for (let q = 0;q < H; q++) {
|
|
25915
23835
|
let we = f[q];
|
|
25916
|
-
i[q]?.[3] ? (oe.push(O[q]), l._OrtBindOutput(_, g[we], O[q], 0) !== 0 && $
|
|
23836
|
+
i[q]?.[3] ? (oe.push(O[q]), l._OrtBindOutput(_, g[we], O[q], 0) !== 0 && $(`Can't bind pre-allocated output[${q}] for session=${a}.`)) : l._OrtBindOutput(_, g[we], 0, me[we]) !== 0 && $(`Can't bind output[${q}] to ${ae[q]} for session=${a}.`);
|
|
25917
23837
|
}
|
|
25918
|
-
ze("wasm bindInputsOutputs"),
|
|
23838
|
+
ze("wasm bindInputsOutputs"), it.set(a, [w, T, g, v, S, true]);
|
|
25919
23839
|
}
|
|
25920
23840
|
l.jsepOnRunStart?.(w), l.webnnOnRunStart?.(w);
|
|
25921
23841
|
let Q;
|
|
25922
|
-
v ? Q = await l._OrtRunWithBinding(w, v.handle, H, J, U) : Q = await l._OrtRun(w, X, ne, R, Ue, H, J, U), Q !== 0 && $
|
|
23842
|
+
v ? Q = await l._OrtRunWithBinding(w, v.handle, H, J, U) : Q = await l._OrtRun(w, X, ne, R, Ue, H, J, U), Q !== 0 && $("failed to call OrtRun().");
|
|
25923
23843
|
let x = [], A = [];
|
|
25924
|
-
$
|
|
23844
|
+
$e("wasm ProcessOutputTensor");
|
|
25925
23845
|
for (let _ = 0;_ < H; _++) {
|
|
25926
23846
|
let ae = Number(l.getValue(J + _ * m, "*"));
|
|
25927
23847
|
if (ae === O[_] || oe.includes(O[_])) {
|
|
25928
|
-
x.push(i[_]), ae !== O[_] && l._OrtReleaseTensor(ae) !== 0 && $
|
|
23848
|
+
x.push(i[_]), ae !== O[_] && l._OrtReleaseTensor(ae) !== 0 && $("Can't release tensor.");
|
|
25929
23849
|
continue;
|
|
25930
23850
|
}
|
|
25931
23851
|
let me = l.stackSave(), q = l.stackAlloc(4 * m), we = false, re, se = 0;
|
|
25932
23852
|
try {
|
|
25933
|
-
l._OrtGetTensorData(ae, q, q + m, q + 2 * m, q + 3 * m) !== 0 && $
|
|
23853
|
+
l._OrtGetTensorData(ae, q, q + m, q + 2 * m, q + 3 * m) !== 0 && $(`Can't access output tensor data on index ${_}.`);
|
|
25934
23854
|
let Te = m === 4 ? "i32" : "i64", Ye = Number(l.getValue(q, Te));
|
|
25935
23855
|
se = l.getValue(q + m, "*");
|
|
25936
23856
|
let bt = l.getValue(q + m * 2, "*"), wt = Number(l.getValue(q + m * 3, Te)), Se = [];
|
|
25937
23857
|
for (let ee = 0;ee < wt; ee++)
|
|
25938
23858
|
Se.push(Number(l.getValue(bt + ee * m, Te)));
|
|
25939
|
-
l._OrtFree(bt) !== 0 && $
|
|
23859
|
+
l._OrtFree(bt) !== 0 && $("Can't free memory for tensor dims.");
|
|
25940
23860
|
let Ae = Se.reduce((ee, Z) => ee * Z, 1);
|
|
25941
23861
|
re = or(Ye);
|
|
25942
23862
|
let Oe = v?.outputPreferredLocations[f[_]];
|
|
@@ -25953,7 +23873,7 @@ var init_transformers_node = __esm(() => {
|
|
|
25953
23873
|
let ee = l.webgpuGetBuffer;
|
|
25954
23874
|
if (!ee)
|
|
25955
23875
|
throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');
|
|
25956
|
-
let Z = ee(se), G =
|
|
23876
|
+
let Z = ee(se), G = mt(Ye, Ae);
|
|
25957
23877
|
if (G === undefined || !ar(re))
|
|
25958
23878
|
throw new Error(`Unsupported data type: ${re}`);
|
|
25959
23879
|
we = true;
|
|
@@ -25962,16 +23882,16 @@ var init_transformers_node = __esm(() => {
|
|
|
25962
23882
|
let V = l.webgpuCreateDownloader(Z, G, a);
|
|
25963
23883
|
x.push([re, Se, { gpuBuffer: Z, download: async () => {
|
|
25964
23884
|
let qe = await V();
|
|
25965
|
-
return new (
|
|
23885
|
+
return new (at(re))(qe);
|
|
25966
23886
|
}, dispose: () => {
|
|
25967
|
-
l._OrtReleaseTensor(ae) !== 0 && $
|
|
23887
|
+
l._OrtReleaseTensor(ae) !== 0 && $("Can't release tensor.");
|
|
25968
23888
|
} }, "gpu-buffer"]);
|
|
25969
23889
|
}
|
|
25970
23890
|
} else if (Oe === "ml-tensor" && Ae > 0) {
|
|
25971
23891
|
let { webnnEnsureTensor: ee, webnnIsGraphInputOutputTypeSupported: Z } = l;
|
|
25972
23892
|
if (!ee || !Z)
|
|
25973
23893
|
throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');
|
|
25974
|
-
if (
|
|
23894
|
+
if (mt(Ye, Ae) === undefined || !sr(re))
|
|
25975
23895
|
throw new Error(`Unsupported data type: ${re}`);
|
|
25976
23896
|
if (!Z(a, re, false))
|
|
25977
23897
|
throw new Error(`preferredLocation "ml-tensor" for ${re} output is not supported by current WebNN Context.`);
|
|
@@ -25986,14 +23906,14 @@ var init_transformers_node = __esm(() => {
|
|
|
25986
23906
|
return l.webnnReleaseTensorId(se), l._OrtReleaseTensor(ae), G;
|
|
25987
23907
|
})()), x.push([re, Se, [], "cpu"]);
|
|
25988
23908
|
} else {
|
|
25989
|
-
let ee =
|
|
23909
|
+
let ee = at(re), Z = new ee(Ae);
|
|
25990
23910
|
new Uint8Array(Z.buffer, Z.byteOffset, Z.byteLength).set(l.HEAPU8.subarray(se, se + Z.byteLength)), x.push([re, Se, Z, "cpu"]);
|
|
25991
23911
|
}
|
|
25992
23912
|
} finally {
|
|
25993
23913
|
l.stackRestore(me), re === "string" && se && l._free(se), we || l._OrtReleaseTensor(ae);
|
|
25994
23914
|
}
|
|
25995
23915
|
}
|
|
25996
|
-
v && !S && (l._OrtClearBoundOutputs(v.handle) !== 0 && $
|
|
23916
|
+
v && !S && (l._OrtClearBoundOutputs(v.handle) !== 0 && $("Can't clear bound outputs."), it.set(a, [w, T, g, v, S, false]));
|
|
25997
23917
|
for (let [_, ae] of await Promise.all(A))
|
|
25998
23918
|
x[_][2] = ae;
|
|
25999
23919
|
return ze("wasm ProcessOutputTensor"), x;
|
|
@@ -26005,11 +23925,11 @@ var init_transformers_node = __esm(() => {
|
|
|
26005
23925
|
}), Y.forEach((Q) => l._OrtReleaseTensor(Q)), O.forEach((Q) => l._OrtReleaseTensor(Q)), W.forEach((Q) => l._free(Q)), U !== 0 && l._OrtReleaseRunOptions(U), M.forEach((Q) => l._free(Q));
|
|
26006
23926
|
}
|
|
26007
23927
|
}, er = (a) => {
|
|
26008
|
-
let r = z(), s =
|
|
23928
|
+
let r = z(), s = it.get(a);
|
|
26009
23929
|
if (!s)
|
|
26010
23930
|
throw new Error("invalid session id");
|
|
26011
23931
|
let f = s[0], i = r._OrtEndProfiling(f);
|
|
26012
|
-
i === 0 && $
|
|
23932
|
+
i === 0 && $("Can't get an profile file name."), r._OrtFree(i);
|
|
26013
23933
|
}, tr = (a) => {
|
|
26014
23934
|
let r = [];
|
|
26015
23935
|
for (let s of a) {
|
|
@@ -26020,20 +23940,20 @@ var init_transformers_node = __esm(() => {
|
|
|
26020
23940
|
};
|
|
26021
23941
|
});
|
|
26022
23942
|
mn = k(() => {
|
|
26023
|
-
|
|
23943
|
+
Ve();
|
|
26024
23944
|
Kr();
|
|
26025
|
-
|
|
23945
|
+
je();
|
|
26026
23946
|
Yt();
|
|
26027
|
-
|
|
23947
|
+
ut = () => !!K.wasm.proxy && typeof document < "u", Mt = false, dr = false, lr = false, pn = /* @__PURE__ */ new Map, ht = (a, r) => {
|
|
26028
23948
|
let s = pn.get(a);
|
|
26029
23949
|
s ? s.push(r) : pn.set(a, [r]);
|
|
26030
23950
|
}, yt = () => {
|
|
26031
|
-
if (
|
|
23951
|
+
if (Mt || !dr || lr || !Ee)
|
|
26032
23952
|
throw new Error("worker not ready");
|
|
26033
23953
|
}, wc = (a) => {
|
|
26034
23954
|
switch (a.data.type) {
|
|
26035
23955
|
case "init-wasm":
|
|
26036
|
-
|
|
23956
|
+
Mt = false, a.data.err ? (lr = true, ln[1](a.data.err)) : (dr = true, ln[0]()), cr && (URL.revokeObjectURL(cr), cr = undefined);
|
|
26037
23957
|
break;
|
|
26038
23958
|
case "init-ep":
|
|
26039
23959
|
case "copy-from":
|
|
@@ -26049,88 +23969,88 @@ var init_transformers_node = __esm(() => {
|
|
|
26049
23969
|
}
|
|
26050
23970
|
}, Ms = async () => {
|
|
26051
23971
|
if (!dr) {
|
|
26052
|
-
if (
|
|
23972
|
+
if (Mt)
|
|
26053
23973
|
throw new Error("multiple calls to 'initWasm()' detected.");
|
|
26054
23974
|
if (lr)
|
|
26055
23975
|
throw new Error("previous call to 'initWasm()' failed.");
|
|
26056
|
-
if (
|
|
23976
|
+
if (Mt = true, ut())
|
|
26057
23977
|
return new Promise((a, r) => {
|
|
26058
|
-
|
|
23978
|
+
Ee?.terminate(), us().then(([s, f]) => {
|
|
26059
23979
|
try {
|
|
26060
|
-
|
|
26061
|
-
let i = { type: "init-wasm", in:
|
|
26062
|
-
!i.in.wasm.wasmPaths && (s || tn) && (i.in.wasm.wasmPaths = { wasm: new URL("ort-wasm-simd-threaded.asyncify.wasm", import.meta.url).href }),
|
|
23980
|
+
Ee = f, Ee.onerror = (d) => r(d), Ee.onmessage = wc, ln = [a, r];
|
|
23981
|
+
let i = { type: "init-wasm", in: K };
|
|
23982
|
+
!i.in.wasm.wasmPaths && (s || tn) && (i.in.wasm.wasmPaths = { wasm: new URL("ort-wasm-simd-threaded.asyncify.wasm", import.meta.url).href }), Ee.postMessage(i), cr = s;
|
|
26063
23983
|
} catch (i) {
|
|
26064
23984
|
r(i);
|
|
26065
23985
|
}
|
|
26066
23986
|
}, r);
|
|
26067
23987
|
});
|
|
26068
23988
|
try {
|
|
26069
|
-
await qt(
|
|
23989
|
+
await qt(K.wasm), await Jt(K), dr = true;
|
|
26070
23990
|
} catch (a) {
|
|
26071
23991
|
throw lr = true, a;
|
|
26072
23992
|
} finally {
|
|
26073
|
-
|
|
23993
|
+
Mt = false;
|
|
26074
23994
|
}
|
|
26075
23995
|
}
|
|
26076
23996
|
}, Cs = async (a) => {
|
|
26077
|
-
if (
|
|
23997
|
+
if (ut())
|
|
26078
23998
|
return yt(), new Promise((r, s) => {
|
|
26079
|
-
|
|
26080
|
-
let f = { type: "init-ep", in: { epName: a, env:
|
|
26081
|
-
|
|
23999
|
+
ht("init-ep", [r, s]);
|
|
24000
|
+
let f = { type: "init-ep", in: { epName: a, env: K } };
|
|
24001
|
+
Ee.postMessage(f);
|
|
26082
24002
|
});
|
|
26083
|
-
await Xt(
|
|
26084
|
-
}, Us = async (a) =>
|
|
26085
|
-
|
|
24003
|
+
await Xt(K, a);
|
|
24004
|
+
}, Us = async (a) => ut() ? (yt(), new Promise((r, s) => {
|
|
24005
|
+
ht("copy-from", [r, s]);
|
|
26086
24006
|
let f = { type: "copy-from", in: { buffer: a } };
|
|
26087
|
-
|
|
26088
|
-
})) :
|
|
26089
|
-
if (
|
|
24007
|
+
Ee.postMessage(f, [a.buffer]);
|
|
24008
|
+
})) : xt(a), Ds = async (a, r) => {
|
|
24009
|
+
if (ut()) {
|
|
26090
24010
|
if (r?.preferredOutputLocation)
|
|
26091
24011
|
throw new Error('session option "preferredOutputLocation" is not supported for proxy.');
|
|
26092
24012
|
return yt(), new Promise((s, f) => {
|
|
26093
|
-
|
|
24013
|
+
ht("create", [s, f]);
|
|
26094
24014
|
let i = { type: "create", in: { model: a, options: { ...r } } }, d = [];
|
|
26095
|
-
a instanceof Uint8Array && d.push(a.buffer),
|
|
24015
|
+
a instanceof Uint8Array && d.push(a.buffer), Ee.postMessage(i, d);
|
|
26096
24016
|
});
|
|
26097
24017
|
} else
|
|
26098
24018
|
return Qt(a, r);
|
|
26099
24019
|
}, Ps = async (a) => {
|
|
26100
|
-
if (
|
|
24020
|
+
if (ut())
|
|
26101
24021
|
return yt(), new Promise((r, s) => {
|
|
26102
|
-
|
|
24022
|
+
ht("release", [r, s]);
|
|
26103
24023
|
let f = { type: "release", in: a };
|
|
26104
|
-
|
|
24024
|
+
Ee.postMessage(f);
|
|
26105
24025
|
});
|
|
26106
24026
|
Zt(a);
|
|
26107
24027
|
}, _s = async (a, r, s, f, i, d) => {
|
|
26108
|
-
if (
|
|
24028
|
+
if (ut()) {
|
|
26109
24029
|
if (s.some((l) => l[3] !== "cpu"))
|
|
26110
24030
|
throw new Error("input tensor on GPU is not supported for proxy.");
|
|
26111
24031
|
if (i.some((l) => l))
|
|
26112
24032
|
throw new Error("pre-allocated output tensor is not supported for proxy.");
|
|
26113
24033
|
return yt(), new Promise((l, m) => {
|
|
26114
|
-
|
|
24034
|
+
ht("run", [l, m]);
|
|
26115
24035
|
let y = s, w = { type: "run", in: { sessionId: a, inputIndices: r, inputs: y, outputIndices: f, options: d } };
|
|
26116
|
-
|
|
24036
|
+
Ee.postMessage(w, tr(y));
|
|
26117
24037
|
});
|
|
26118
24038
|
} else
|
|
26119
24039
|
return Kt(a, r, s, f, i, d);
|
|
26120
24040
|
}, Rs = async (a) => {
|
|
26121
|
-
if (
|
|
24041
|
+
if (ut())
|
|
26122
24042
|
return yt(), new Promise((r, s) => {
|
|
26123
|
-
|
|
24043
|
+
ht("end-profiling", [r, s]);
|
|
26124
24044
|
let f = { type: "end-profiling", in: a };
|
|
26125
|
-
|
|
24045
|
+
Ee.postMessage(f);
|
|
26126
24046
|
});
|
|
26127
24047
|
er(a);
|
|
26128
24048
|
};
|
|
26129
24049
|
});
|
|
26130
24050
|
ks = k(() => {
|
|
26131
|
-
|
|
24051
|
+
Ve();
|
|
26132
24052
|
mn();
|
|
26133
|
-
|
|
24053
|
+
st();
|
|
26134
24054
|
Ht();
|
|
26135
24055
|
sn();
|
|
26136
24056
|
Ns = (a, r) => {
|
|
@@ -26167,18 +24087,18 @@ var init_transformers_node = __esm(() => {
|
|
|
26167
24087
|
}
|
|
26168
24088
|
}, pr = class {
|
|
26169
24089
|
async fetchModelAndCopyToWasmMemory(r) {
|
|
26170
|
-
return Us(await
|
|
24090
|
+
return Us(await Bt(r));
|
|
26171
24091
|
}
|
|
26172
24092
|
async loadModel(r, s) {
|
|
26173
|
-
|
|
24093
|
+
tt();
|
|
26174
24094
|
let f;
|
|
26175
|
-
typeof r == "string" ? f = await this.fetchModelAndCopyToWasmMemory(r) : f = r, [this.sessionId, this.inputNames, this.outputNames, this.inputMetadata, this.outputMetadata] = await Ds(f, s),
|
|
24095
|
+
typeof r == "string" ? f = await this.fetchModelAndCopyToWasmMemory(r) : f = r, [this.sessionId, this.inputNames, this.outputNames, this.inputMetadata, this.outputMetadata] = await Ds(f, s), rt();
|
|
26176
24096
|
}
|
|
26177
24097
|
async dispose() {
|
|
26178
24098
|
return Ps(this.sessionId);
|
|
26179
24099
|
}
|
|
26180
24100
|
async run(r, s, f) {
|
|
26181
|
-
|
|
24101
|
+
tt();
|
|
26182
24102
|
let i = [], d = [];
|
|
26183
24103
|
Object.entries(r).forEach((v) => {
|
|
26184
24104
|
let S = v[0], C = v[1], R = this.inputNames.indexOf(S);
|
|
@@ -26196,7 +24116,7 @@ var init_transformers_node = __esm(() => {
|
|
|
26196
24116
|
let y = i.map((v, S) => Ns(v, () => `input "${this.inputNames[d[S]]}"`)), w = l.map((v, S) => v ? Ns(v, () => `output "${this.outputNames[m[S]]}"`) : null), T = await _s(this.sessionId, d, y, m, w, f), g = {};
|
|
26197
24117
|
for (let v = 0;v < T.length; v++)
|
|
26198
24118
|
g[this.outputNames[m[v]]] = l[v] ?? gc(T[v]);
|
|
26199
|
-
return
|
|
24119
|
+
return rt(), g;
|
|
26200
24120
|
}
|
|
26201
24121
|
startProfiling() {}
|
|
26202
24122
|
endProfiling() {
|
|
@@ -26205,20 +24125,20 @@ var init_transformers_node = __esm(() => {
|
|
|
26205
24125
|
};
|
|
26206
24126
|
});
|
|
26207
24127
|
Fs = {};
|
|
26208
|
-
|
|
24128
|
+
At(Fs, { OnnxruntimeWebAssemblyBackend: () => mr, initializeFlags: () => Ws, wasmBackend: () => Tc });
|
|
26209
24129
|
Gs = k(() => {
|
|
26210
|
-
|
|
24130
|
+
Ve();
|
|
26211
24131
|
mn();
|
|
26212
24132
|
ks();
|
|
26213
24133
|
Ws = () => {
|
|
26214
|
-
(typeof
|
|
26215
|
-
let a =
|
|
26216
|
-
if (typeof a != "boolean" && a !== undefined && a !== "fixed" && a !== "relaxed" && (console.warn(`Property "env.wasm.simd" is set to unknown value "${a}". Reset it to \`false\` and ignore SIMD feature checking.`),
|
|
24134
|
+
(typeof K.wasm.initTimeout != "number" || K.wasm.initTimeout < 0) && (K.wasm.initTimeout = 0);
|
|
24135
|
+
let a = K.wasm.simd;
|
|
24136
|
+
if (typeof a != "boolean" && a !== undefined && a !== "fixed" && a !== "relaxed" && (console.warn(`Property "env.wasm.simd" is set to unknown value "${a}". Reset it to \`false\` and ignore SIMD feature checking.`), K.wasm.simd = false), typeof K.wasm.proxy != "boolean" && (K.wasm.proxy = false), typeof K.wasm.trace != "boolean" && (K.wasm.trace = false), typeof K.wasm.numThreads != "number" || !Number.isInteger(K.wasm.numThreads) || K.wasm.numThreads <= 0)
|
|
26217
24137
|
if (typeof self < "u" && !self.crossOriginIsolated)
|
|
26218
|
-
|
|
24138
|
+
K.wasm.numThreads = 1;
|
|
26219
24139
|
else {
|
|
26220
|
-
let r = typeof navigator > "u" ?
|
|
26221
|
-
|
|
24140
|
+
let r = typeof navigator > "u" ? Hr("node:os").cpus().length : navigator.hardwareConcurrency;
|
|
24141
|
+
K.wasm.numThreads = Math.min(4, Math.ceil((r || 1) / 2));
|
|
26222
24142
|
}
|
|
26223
24143
|
}, mr = class {
|
|
26224
24144
|
async init(r) {
|
|
@@ -26230,15 +24150,15 @@ var init_transformers_node = __esm(() => {
|
|
|
26230
24150
|
}
|
|
26231
24151
|
}, Tc = new mr;
|
|
26232
24152
|
});
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
|
|
24153
|
+
Ve();
|
|
24154
|
+
Ve();
|
|
24155
|
+
Ve();
|
|
26236
24156
|
gl = Zr;
|
|
26237
24157
|
{
|
|
26238
24158
|
let a = (Gs(), $t(Fs)).wasmBackend;
|
|
26239
|
-
|
|
24159
|
+
Ke("webgpu", a, 5), Ke("webnn", a, 5), Ke("cpu", a, 10), Ke("wasm", a, 10);
|
|
26240
24160
|
}
|
|
26241
|
-
Object.defineProperty(
|
|
24161
|
+
Object.defineProperty(K.versions, "web", { value: Ja, enumerable: true });
|
|
26242
24162
|
DEVICE_TO_EXECUTION_PROVIDER_MAPPING = Object.freeze({
|
|
26243
24163
|
auto: null,
|
|
26244
24164
|
gpu: null,
|
|
@@ -26293,7 +24213,7 @@ var init_transformers_node = __esm(() => {
|
|
|
26293
24213
|
supportedDevices.push("wasm");
|
|
26294
24214
|
defaultDevices = ["wasm"];
|
|
26295
24215
|
}
|
|
26296
|
-
|
|
24216
|
+
InferenceSession2 = ONNX.InferenceSession;
|
|
26297
24217
|
webInitChain = Promise.resolve();
|
|
26298
24218
|
webInferenceChain = Promise.resolve();
|
|
26299
24219
|
ONNX_ENV = ONNX?.env;
|
|
@@ -26318,8 +24238,8 @@ var init_transformers_node = __esm(() => {
|
|
|
26318
24238
|
if (ONNX_ENV.webgpu) {
|
|
26319
24239
|
ONNX_ENV.webgpu.powerPreference = "high-performance";
|
|
26320
24240
|
}
|
|
26321
|
-
setLogLevel(
|
|
26322
|
-
|
|
24241
|
+
setLogLevel(env3.logLevel ?? LogLevel.WARNING);
|
|
24242
|
+
env3.backends.onnx = {
|
|
26323
24243
|
...ONNX_ENV,
|
|
26324
24244
|
setLogLevel
|
|
26325
24245
|
};
|
|
@@ -27429,7 +25349,7 @@ var init_transformers_node = __esm(() => {
|
|
|
27429
25349
|
if (isONNXTensor(args[0])) {
|
|
27430
25350
|
this.ort_tensor = args[0];
|
|
27431
25351
|
} else {
|
|
27432
|
-
this.ort_tensor = new
|
|
25352
|
+
this.ort_tensor = new Tensor2(args[0], args[1], args[2]);
|
|
27433
25353
|
}
|
|
27434
25354
|
return new Proxy(this, {
|
|
27435
25355
|
get: (obj, key) => {
|
|
@@ -38259,7 +36179,7 @@ ${this.boa_token}${this.audio_token.repeat(this._compute_audio_num_tokens(audio_
|
|
|
38259
36179
|
}
|
|
38260
36180
|
async _prepare_speaker_embeddings(speaker_embeddings, batch_size) {
|
|
38261
36181
|
if (typeof speaker_embeddings === "string" || speaker_embeddings instanceof URL) {
|
|
38262
|
-
speaker_embeddings = new Float32Array(await (await
|
|
36182
|
+
speaker_embeddings = new Float32Array(await (await env3.fetch(speaker_embeddings)).arrayBuffer());
|
|
38263
36183
|
}
|
|
38264
36184
|
if (speaker_embeddings instanceof Float32Array) {
|
|
38265
36185
|
speaker_embeddings = new Tensor22("float32", speaker_embeddings, [speaker_embeddings.length]);
|
|
@@ -66915,7 +64835,7 @@ function memoizedContent(kind, content) {
|
|
|
66915
64835
|
return cached;
|
|
66916
64836
|
const measured = {
|
|
66917
64837
|
hash: fnv1a32(key),
|
|
66918
|
-
tokens: kind === "excluded" ? 0 :
|
|
64838
|
+
tokens: kind === "excluded" ? 0 : undefined,
|
|
66919
64839
|
keyBytes: key.length * 2 + 32
|
|
66920
64840
|
};
|
|
66921
64841
|
contentMemo.set(key, measured);
|
|
@@ -66931,6 +64851,13 @@ function memoizedContent(kind, content) {
|
|
|
66931
64851
|
}
|
|
66932
64852
|
return measured;
|
|
66933
64853
|
}
|
|
64854
|
+
function memoizedTokens(kind, content) {
|
|
64855
|
+
const measured = memoizedContent(kind, content);
|
|
64856
|
+
if (measured.tokens === undefined) {
|
|
64857
|
+
measured.tokens = estimateTokens(content);
|
|
64858
|
+
}
|
|
64859
|
+
return measured.tokens;
|
|
64860
|
+
}
|
|
66934
64861
|
function safeStableStringify(value) {
|
|
66935
64862
|
if (value === undefined || value === null)
|
|
66936
64863
|
return "";
|
|
@@ -67233,8 +65160,8 @@ function fileContentAndTokens(part) {
|
|
|
67233
65160
|
};
|
|
67234
65161
|
}
|
|
67235
65162
|
const content = firstString(part, ["content", "text", "source", "url"]);
|
|
67236
|
-
const
|
|
67237
|
-
return { content, tokens
|
|
65163
|
+
const tokens = memoizedTokens("file", content);
|
|
65164
|
+
return { content, tokens };
|
|
67238
65165
|
}
|
|
67239
65166
|
function contentSignature(parts) {
|
|
67240
65167
|
return fnv1a32(parts.map((part) => `${part.key}:${part.contentHash}`).join("\x00"));
|
|
@@ -67319,13 +65246,13 @@ function measureTailHygiene(input) {
|
|
|
67319
65246
|
parts.push(excludedSnapshot(`${key}\x00excluded`, part));
|
|
67320
65247
|
continue;
|
|
67321
65248
|
}
|
|
67322
|
-
const
|
|
65249
|
+
const tokens = memoizedTokens("text", content);
|
|
67323
65250
|
const tag = attribution.messageTags.get(`${message.info.id}:p${partIndex}`);
|
|
67324
65251
|
const measured = snapshot({
|
|
67325
65252
|
key: `${key}\x00text`,
|
|
67326
65253
|
kind: "text",
|
|
67327
65254
|
content,
|
|
67328
|
-
tokens
|
|
65255
|
+
tokens,
|
|
67329
65256
|
tag,
|
|
67330
65257
|
protectedNumbers: attribution.protectedNumbers,
|
|
67331
65258
|
pendingDropTagNumbers
|
|
@@ -67366,12 +65293,12 @@ function measureTailHygiene(input) {
|
|
|
67366
65293
|
const tag = attribution.toolTagsByPart.get(part);
|
|
67367
65294
|
const inputText = toolInputText(part);
|
|
67368
65295
|
if (inputText !== null) {
|
|
67369
|
-
const
|
|
65296
|
+
const tokens = memoizedTokens("toolInput", inputText);
|
|
67370
65297
|
const measured = snapshot({
|
|
67371
65298
|
key: `${key}\x00toolInput`,
|
|
67372
65299
|
kind: "toolInput",
|
|
67373
65300
|
content: inputText,
|
|
67374
|
-
tokens
|
|
65301
|
+
tokens,
|
|
67375
65302
|
tag,
|
|
67376
65303
|
protectedNumbers: attribution.protectedNumbers,
|
|
67377
65304
|
pendingDropTagNumbers
|
|
@@ -67386,12 +65313,12 @@ function measureTailHygiene(input) {
|
|
|
67386
65313
|
if (isDropSentinel(output)) {
|
|
67387
65314
|
parts.push(excludedSnapshot(`${key}\x00excludedOutput`, output));
|
|
67388
65315
|
} else {
|
|
67389
|
-
const
|
|
65316
|
+
const tokens = memoizedTokens("toolOutput", output);
|
|
67390
65317
|
const measured = snapshot({
|
|
67391
65318
|
key: `${key}\x00toolOutput`,
|
|
67392
65319
|
kind: "toolOutput",
|
|
67393
65320
|
content: output,
|
|
67394
|
-
tokens
|
|
65321
|
+
tokens,
|
|
67395
65322
|
tag,
|
|
67396
65323
|
protectedNumbers: attribution.protectedNumbers,
|
|
67397
65324
|
pendingDropTagNumbers
|
|
@@ -83324,16 +81251,27 @@ function startLockHeartbeat(lockPath) {
|
|
|
83324
81251
|
timer.unref?.();
|
|
83325
81252
|
return () => clearInterval(timer);
|
|
83326
81253
|
}
|
|
81254
|
+
var ONNX_RUNTIME_WEB_SPECIFIER = "onnxruntime-web";
|
|
83327
81255
|
var localEmbeddingRuntimeMode = "native";
|
|
83328
81256
|
var localEmbeddingProcessFailure = null;
|
|
83329
81257
|
var wasmRuntimeInjected = false;
|
|
83330
81258
|
var localEmbeddingHostForRuntime = currentLocalEmbeddingHost;
|
|
81259
|
+
var resolveWasmOrtForRuntime = () => {
|
|
81260
|
+
try {
|
|
81261
|
+
return typeof import.meta.resolve === "function" ? import.meta.resolve(ONNX_RUNTIME_WEB_SPECIFIER) : undefined;
|
|
81262
|
+
} catch {
|
|
81263
|
+
return;
|
|
81264
|
+
}
|
|
81265
|
+
};
|
|
81266
|
+
var importWasmOrtModule = async (specifier) => await import(specifier);
|
|
81267
|
+
var importWasmOrtModuleForRuntime = importWasmOrtModule;
|
|
83331
81268
|
var importWasmOrtForRuntime = async () => {
|
|
83332
81269
|
const { createRequire: createRequireFn } = await import("node:module");
|
|
83333
81270
|
const requireFn = createRequireFn(import.meta.url);
|
|
83334
|
-
const ortEntry = requireFn.resolve(
|
|
81271
|
+
const ortEntry = requireFn.resolve(ONNX_RUNTIME_WEB_SPECIFIER);
|
|
81272
|
+
const ortSpecifier = resolveWasmOrtForRuntime() ?? ONNX_RUNTIME_WEB_SPECIFIER;
|
|
83335
81273
|
return {
|
|
83336
|
-
module: await
|
|
81274
|
+
module: await importWasmOrtModuleForRuntime(ortSpecifier),
|
|
83337
81275
|
entryPath: ortEntry
|
|
83338
81276
|
};
|
|
83339
81277
|
};
|
|
@@ -89891,6 +87829,7 @@ function toRow(r) {
|
|
|
89891
87829
|
lastStatus: r.last_status ?? null,
|
|
89892
87830
|
lastError: r.last_error,
|
|
89893
87831
|
retryCount: r.retry_count ?? 0,
|
|
87832
|
+
taskStateJson: r.last_checked_commit ?? null,
|
|
89894
87833
|
lastCheckedCommit: r.last_checked_commit ?? null,
|
|
89895
87834
|
lastBroadRunAt: r.last_broad_run_at ?? null,
|
|
89896
87835
|
retrospectiveWatermarkMs: r.retrospective_watermark_ms ?? null
|
|
@@ -89925,7 +87864,12 @@ function writeTaskScheduleState(db, row) {
|
|
|
89925
87864
|
retry_count = excluded.retry_count,
|
|
89926
87865
|
last_checked_commit = COALESCE(excluded.last_checked_commit, task_schedule_state.last_checked_commit),
|
|
89927
87866
|
${broadCycleUpdate},
|
|
89928
|
-
retrospective_watermark_ms = COALESCE(excluded.retrospective_watermark_ms, task_schedule_state.retrospective_watermark_ms)`).run(row.projectPath, row.task, row.lastRunAt, row.nextDueAt, row.schedule, row.lastStatus, row.lastError, row.retryCount, row.lastCheckedCommit ?? null, row.lastBroadRunAt ?? null, row.retrospectiveWatermarkMs ?? null);
|
|
87867
|
+
retrospective_watermark_ms = COALESCE(excluded.retrospective_watermark_ms, task_schedule_state.retrospective_watermark_ms)`).run(row.projectPath, row.task, row.lastRunAt, row.nextDueAt, row.schedule, row.lastStatus, row.lastError, row.retryCount, row.taskStateJson ?? row.lastCheckedCommit ?? null, row.lastBroadRunAt ?? null, row.retrospectiveWatermarkMs ?? null);
|
|
87868
|
+
}
|
|
87869
|
+
function writeTaskStateJson(db, projectPath, task, taskStateJson) {
|
|
87870
|
+
db.prepare(`INSERT INTO task_schedule_state (project_path, task, last_checked_commit)
|
|
87871
|
+
VALUES (?, ?, ?)
|
|
87872
|
+
ON CONFLICT(project_path, task) DO UPDATE SET last_checked_commit = excluded.last_checked_commit`).run(projectPath, task, taskStateJson);
|
|
89929
87873
|
}
|
|
89930
87874
|
function isRetrospectiveWindowProcessed(db, projectPath, windowKey) {
|
|
89931
87875
|
const row = db.prepare("SELECT 1 AS one FROM retrospective_processed_windows WHERE project_path = ? AND window_key = ?").get(projectPath, windowKey);
|
|
@@ -89935,6 +87879,88 @@ function recordRetrospectiveWindowProcessed(db, projectPath, windowKey) {
|
|
|
89935
87879
|
db.prepare("INSERT INTO retrospective_processed_windows (project_path, window_key, processed_at) VALUES (?, ?, ?) ON CONFLICT(project_path, window_key) DO NOTHING").run(projectPath, windowKey, Date.now());
|
|
89936
87880
|
}
|
|
89937
87881
|
|
|
87882
|
+
// src/features/magic-context/dreamer/curate-category-rotation.ts
|
|
87883
|
+
var CURATE_MEMORY_CATEGORIES = [
|
|
87884
|
+
"PROJECT_RULES",
|
|
87885
|
+
"ARCHITECTURE",
|
|
87886
|
+
"CONSTRAINTS",
|
|
87887
|
+
"CONFIG_VALUES",
|
|
87888
|
+
"NAMING"
|
|
87889
|
+
];
|
|
87890
|
+
var LEGACY_CURATE_CATEGORY_BUCKETS = {
|
|
87891
|
+
ARCHITECTURE_DECISIONS: "ARCHITECTURE",
|
|
87892
|
+
CONFIG_DEFAULTS: "CONFIG_VALUES",
|
|
87893
|
+
ENVIRONMENT: "CONFIG_VALUES",
|
|
87894
|
+
KNOWN_ISSUES: "CONSTRAINTS",
|
|
87895
|
+
USER_DIRECTIVES: "PROJECT_RULES",
|
|
87896
|
+
USER_PREFERENCES: "PROJECT_RULES",
|
|
87897
|
+
WORKFLOW_RULES: "PROJECT_RULES"
|
|
87898
|
+
};
|
|
87899
|
+
function curateCategoryForMemoryCategory(category) {
|
|
87900
|
+
return isCurateMemoryCategory(category) ? category : LEGACY_CURATE_CATEGORY_BUCKETS[category] ?? null;
|
|
87901
|
+
}
|
|
87902
|
+
function isCurateMemoryCategory(value) {
|
|
87903
|
+
return CURATE_MEMORY_CATEGORIES.includes(value);
|
|
87904
|
+
}
|
|
87905
|
+
function parseTaskState(raw) {
|
|
87906
|
+
if (!raw)
|
|
87907
|
+
return {};
|
|
87908
|
+
try {
|
|
87909
|
+
const parsed = JSON.parse(raw);
|
|
87910
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
87911
|
+
} catch {
|
|
87912
|
+
return {};
|
|
87913
|
+
}
|
|
87914
|
+
}
|
|
87915
|
+
function normalizedCursor(value) {
|
|
87916
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value % CURATE_MEMORY_CATEGORIES.length : 0;
|
|
87917
|
+
}
|
|
87918
|
+
function readState(db, projectIdentity) {
|
|
87919
|
+
return parseTaskState(getTaskScheduleState(db, projectIdentity, "curate")?.taskStateJson);
|
|
87920
|
+
}
|
|
87921
|
+
function categoryStartIndex(state, populated) {
|
|
87922
|
+
const active = state.curate?.activeCategory;
|
|
87923
|
+
if (isCurateMemoryCategory(active)) {
|
|
87924
|
+
const activeIndex = CURATE_MEMORY_CATEGORIES.indexOf(active);
|
|
87925
|
+
return populated.has(active) ? activeIndex : (activeIndex + 1) % CURATE_MEMORY_CATEGORIES.length;
|
|
87926
|
+
}
|
|
87927
|
+
return normalizedCursor(state.curate?.cursor);
|
|
87928
|
+
}
|
|
87929
|
+
function peekCurateCategoryScope(db, projectIdentity, memories) {
|
|
87930
|
+
const populated = new Set(memories.map((memory) => curateCategoryForMemoryCategory(memory.category)).filter((category) => category !== null));
|
|
87931
|
+
const start = categoryStartIndex(readState(db, projectIdentity), populated);
|
|
87932
|
+
for (let offset = 0;offset < CURATE_MEMORY_CATEGORIES.length; offset += 1) {
|
|
87933
|
+
const category = CURATE_MEMORY_CATEGORIES[(start + offset) % CURATE_MEMORY_CATEGORIES.length];
|
|
87934
|
+
const scoped = memories.filter((memory) => curateCategoryForMemoryCategory(memory.category) === category);
|
|
87935
|
+
if (scoped.length > 0)
|
|
87936
|
+
return { category, memories: scoped };
|
|
87937
|
+
}
|
|
87938
|
+
return null;
|
|
87939
|
+
}
|
|
87940
|
+
function beginCurateCategoryRun(db, projectIdentity, memories) {
|
|
87941
|
+
const scope = peekCurateCategoryScope(db, projectIdentity, memories);
|
|
87942
|
+
if (!scope)
|
|
87943
|
+
return null;
|
|
87944
|
+
const state = readState(db, projectIdentity);
|
|
87945
|
+
writeTaskStateJson(db, projectIdentity, "curate", JSON.stringify({
|
|
87946
|
+
...state,
|
|
87947
|
+
curate: {
|
|
87948
|
+
cursor: normalizedCursor(state.curate?.cursor),
|
|
87949
|
+
activeCategory: scope.category
|
|
87950
|
+
}
|
|
87951
|
+
}));
|
|
87952
|
+
return scope;
|
|
87953
|
+
}
|
|
87954
|
+
function curateTaskStateAfterSuccess(db, projectIdentity, category) {
|
|
87955
|
+
const state = readState(db, projectIdentity);
|
|
87956
|
+
return JSON.stringify({
|
|
87957
|
+
...state,
|
|
87958
|
+
curate: {
|
|
87959
|
+
cursor: (CURATE_MEMORY_CATEGORIES.indexOf(category) + 1) % CURATE_MEMORY_CATEGORIES.length
|
|
87960
|
+
}
|
|
87961
|
+
});
|
|
87962
|
+
}
|
|
87963
|
+
|
|
89938
87964
|
// src/features/magic-context/dreamer/task-registry.ts
|
|
89939
87965
|
var CANONICAL_DREAM_TASKS = [
|
|
89940
87966
|
"map-memories",
|
|
@@ -90014,12 +88040,13 @@ function countActiveMemories(db, projectPath) {
|
|
|
90014
88040
|
}
|
|
90015
88041
|
function countLiveMemories(db, projectPath, options = {}) {
|
|
90016
88042
|
const unclassified = options.unclassifiedOnly && hasMemoryClassifiedAtColumn(db);
|
|
90017
|
-
const
|
|
90018
|
-
|
|
90019
|
-
|
|
90020
|
-
|
|
90021
|
-
|
|
90022
|
-
|
|
88043
|
+
const sql = `SELECT COUNT(*) AS cnt
|
|
88044
|
+
FROM memories
|
|
88045
|
+
WHERE project_path = ?
|
|
88046
|
+
AND status IN ('active','permanent')
|
|
88047
|
+
AND (expires_at IS NULL OR expires_at > ?)
|
|
88048
|
+
${unclassified ? "AND classified_at IS NULL" : ""}`;
|
|
88049
|
+
const row = options.category ? db.prepare(`${sql} AND category = ?`).get(projectPath, Date.now(), options.category) : db.prepare(sql).get(projectPath, Date.now());
|
|
90023
88050
|
return row?.cnt ?? 0;
|
|
90024
88051
|
}
|
|
90025
88052
|
function countUnmappedActiveMemories(db, projectPath) {
|
|
@@ -90130,8 +88157,13 @@ function getDreamTaskBacklog(db, projectPath, task, options = {}) {
|
|
|
90130
88157
|
return { pending, total };
|
|
90131
88158
|
}
|
|
90132
88159
|
case "curate": {
|
|
90133
|
-
const
|
|
90134
|
-
|
|
88160
|
+
const categories = db.prepare(`SELECT category FROM memories
|
|
88161
|
+
WHERE project_path = ?
|
|
88162
|
+
AND status IN ('active','permanent')
|
|
88163
|
+
AND (expires_at IS NULL OR expires_at > ?)`).all(projectPath, Date.now());
|
|
88164
|
+
const scope = peekCurateCategoryScope(db, projectPath, categories);
|
|
88165
|
+
const total = scope?.memories.length ?? 0;
|
|
88166
|
+
return scope ? { pending: total, total, category: scope.category } : { pending: 0, total: 0 };
|
|
90135
88167
|
}
|
|
90136
88168
|
case "compress-cues": {
|
|
90137
88169
|
const total = countLiveMemories(db, projectPath);
|
|
@@ -111988,9 +110020,11 @@ function buildCuratePrompt(args) {
|
|
|
111988
110020
|
|
|
111989
110021
|
**Project:** ${args.projectPath}
|
|
111990
110022
|
|
|
110023
|
+
This run covers the whole of the \`${args.category}\` category (the other categories run in later windows).
|
|
110024
|
+
|
|
111991
110025
|
The memories below are assumed ACCURATE (a separate verify task keeps them true). Your job is pool QUALITY: remove duplicates, tighten wording, and consolidate redundant entries that waste the ~6000-token injection budget. Explain each action in one line first. Do NOT mint new facts (that is the historian's job).
|
|
111992
110026
|
|
|
111993
|
-
Work ALL THREE phases below in order (A → B → C) over
|
|
110027
|
+
Work ALL THREE phases below in order (A → B → C) over this category. Do NOT stop after consolidating — a run that only merges and never improves or archives is incomplete.
|
|
111994
110028
|
|
|
111995
110029
|
### Phase A — Consolidate duplicates
|
|
111996
110030
|
Group by category, then merge near-identical / superset-subset / same-fact-different-angle clusters into one canonical memory with \`ctx_memory(action="merge", ids=[...], content="...", category="...")\`. Preserve every unique detail; terse present tense; paths/keys verbatim. Every id in a merge MUST share the same category — the system rejects cross-category merges. If two similar memories sit in different categories they are NOT duplicates; do not archive either as a consolidation. One fact per memory.
|
|
@@ -112210,6 +110244,7 @@ function buildDreamTaskPrompt(task, args) {
|
|
|
112210
110244
|
case "curate":
|
|
112211
110245
|
return buildCuratePrompt({
|
|
112212
110246
|
projectPath: args.projectPath,
|
|
110247
|
+
category: args.curate?.category ?? "PROJECT_RULES",
|
|
112213
110248
|
memories: args.curate?.memories ?? []
|
|
112214
110249
|
});
|
|
112215
110250
|
case "maintain-docs":
|
|
@@ -116881,6 +114916,7 @@ function createDreamTaskExecutor(deps) {
|
|
|
116881
114916
|
processed: Math.max(0, processed),
|
|
116882
114917
|
total: backlogAtStart.pending,
|
|
116883
114918
|
startedAt,
|
|
114919
|
+
...backlogAtStart.category ? { category: backlogAtStart.category } : {},
|
|
116884
114920
|
...refused === undefined ? {} : { refused: Math.max(0, refused) }
|
|
116885
114921
|
});
|
|
116886
114922
|
};
|
|
@@ -116933,7 +114969,8 @@ function createDreamTaskExecutor(deps) {
|
|
|
116933
114969
|
totalAtStart: backlogAtStart.total,
|
|
116934
114970
|
pendingAtEnd: end.pending,
|
|
116935
114971
|
totalAtEnd: end.total,
|
|
116936
|
-
processed
|
|
114972
|
+
processed,
|
|
114973
|
+
...backlogAtStart.category ? { category: backlogAtStart.category } : {}
|
|
116937
114974
|
};
|
|
116938
114975
|
return value;
|
|
116939
114976
|
})()
|
|
@@ -117539,6 +115576,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
117539
115576
|
let expiredArchived = 0;
|
|
117540
115577
|
try {
|
|
117541
115578
|
let curateMemories;
|
|
115579
|
+
let curateCategory;
|
|
117542
115580
|
if (task === "curate") {
|
|
117543
115581
|
expiredArchived = await archiveExpiredMemories({
|
|
117544
115582
|
db,
|
|
@@ -117550,10 +115588,12 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
117550
115588
|
});
|
|
117551
115589
|
if (leaseLost)
|
|
117552
115590
|
throw new Error("Dream lease lost during expired-memory archive");
|
|
117553
|
-
|
|
117554
|
-
|
|
117555
|
-
|
|
117556
|
-
|
|
115591
|
+
const scope = beginCurateCategoryRun(db, projectIdentity, loadActiveMemoryPromptMemories(db, projectIdentity));
|
|
115592
|
+
curateMemories = scope?.memories ?? [];
|
|
115593
|
+
curateCategory = scope?.category;
|
|
115594
|
+
log(`[dreamer] curate pool: category=${curateCategory ?? "none"} in_scope=${curateMemories.length} expired_archived=${expiredArchived}`);
|
|
115595
|
+
if (curateMemories.length === 0) {
|
|
115596
|
+
const progress = expiredArchived > 0 ? formatExpiredArchiveProgress(expiredArchived) : "curate: no populated project-memory category";
|
|
117557
115597
|
helpers.recordRun("completed", null, {
|
|
117558
115598
|
memoryChanges: helpers.computeMemoryDelta(memoryBefore),
|
|
117559
115599
|
progress
|
|
@@ -117565,7 +115605,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
117565
115605
|
projectPath: projectIdentity,
|
|
117566
115606
|
lastDreamAt: lastRunAt ? String(lastRunAt) : null,
|
|
117567
115607
|
existingDocs,
|
|
117568
|
-
curate: curateMemories ? { memories: curateMemories } : undefined
|
|
115608
|
+
curate: curateMemories && curateCategory ? { category: curateCategory, memories: curateMemories } : undefined
|
|
117569
115609
|
});
|
|
117570
115610
|
const createResponse = await createChildSessionWithFence({
|
|
117571
115611
|
client: requireDreamClient(deps.client),
|
|
@@ -117657,16 +115697,34 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
117657
115697
|
}
|
|
117658
115698
|
}
|
|
117659
115699
|
const curateOutput = task === "curate" ? run.validated : undefined;
|
|
115700
|
+
const curateScopeProgress = task === "curate" && curateCategory && curateMemories ? `curate: ${curateCategory} (${curateMemories.length})` : null;
|
|
117660
115701
|
const progress = [
|
|
115702
|
+
curateScopeProgress,
|
|
117661
115703
|
expiredArchived > 0 ? formatExpiredArchiveProgress(expiredArchived) : null,
|
|
117662
115704
|
curateOutput && curateOutput.memoryOperations.completedActions.length > 0 ? formatCurateMemoryOperations(curateOutput.memoryOperations.completedActions) : null,
|
|
117663
115705
|
curateRefused > 0 ? `curate: refused ${curateRefused} unsafe mutation(s)` : null
|
|
117664
115706
|
].filter((value) => Boolean(value)).join("; ");
|
|
115707
|
+
const curateCount = task === "curate" && curateCategory ? loadActiveMemoryPromptMemories(db, projectIdentity).filter((memory) => curateCategoryForMemoryCategory(memory.category) === curateCategory).length : undefined;
|
|
115708
|
+
const curateBacklog = curateCount !== undefined && curateCategory ? {
|
|
115709
|
+
pending: curateCount,
|
|
115710
|
+
total: curateCount,
|
|
115711
|
+
category: curateCategory
|
|
115712
|
+
} : undefined;
|
|
117665
115713
|
helpers.recordRun("completed", null, {
|
|
117666
115714
|
memoryChanges: helpers.computeMemoryDelta(memoryBefore),
|
|
117667
|
-
progress: progress || null
|
|
115715
|
+
progress: progress || null,
|
|
115716
|
+
backlogAfter: curateBacklog
|
|
117668
115717
|
});
|
|
117669
|
-
return {
|
|
115718
|
+
return {
|
|
115719
|
+
status: "completed",
|
|
115720
|
+
...progress ? { detail: progress } : {},
|
|
115721
|
+
...curateBacklog ? { backlog: curateBacklog } : {},
|
|
115722
|
+
...curateCategory ? {
|
|
115723
|
+
schedulePatch: {
|
|
115724
|
+
taskStateJson: curateTaskStateAfterSuccess(db, projectIdentity, curateCategory)
|
|
115725
|
+
}
|
|
115726
|
+
} : {}
|
|
115727
|
+
};
|
|
117670
115728
|
} finally {
|
|
117671
115729
|
heartbeat.stop();
|
|
117672
115730
|
if (childSessionId)
|
|
@@ -117742,6 +115800,7 @@ function advanceAfterRun(db, projectIdentity, due, finishedAt, status, error, sc
|
|
|
117742
115800
|
lastStatus: status,
|
|
117743
115801
|
lastError: error,
|
|
117744
115802
|
retryCount: 0,
|
|
115803
|
+
taskStateJson: schedulePatch?.taskStateJson,
|
|
117745
115804
|
retrospectiveWatermarkMs: schedulePatch?.retrospectiveWatermarkMs
|
|
117746
115805
|
});
|
|
117747
115806
|
}
|
|
@@ -117833,7 +115892,7 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
117833
115892
|
const finishedAt = Date.now();
|
|
117834
115893
|
if (outcome.status === "completed") {
|
|
117835
115894
|
advanceAfterRun(db, projectIdentity, due, finishedAt, "completed", null, outcome.schedulePatch);
|
|
117836
|
-
cb?.onRan?.(due.config.task, outcome.detail);
|
|
115895
|
+
cb?.onRan?.(due.config.task, outcome.detail, outcome.backlog);
|
|
117837
115896
|
} else if (outcome.transient) {
|
|
117838
115897
|
recordTransientFailure(db, projectIdentity, due, finishedAt, outcome.error ?? null);
|
|
117839
115898
|
cb?.onFailed?.(due.config.task, outcome.failureDetail ?? outcome.error);
|