Sync from GitHub a1e7660
Browse files- app.py +23 -5
- core/constants.py +40 -0
- core/pdf.py +2 -2
- frontend/index.html +30 -2
- frontend/vendor/onnx/ort-wasm-simd-threaded.mjs +51 -61
- frontend/vendor/onnx/ort-wasm-simd-threaded.wasm +2 -2
- frontend/vendor/onnx/ort.wasm.min.js +2 -2
- models/minicpm_agent.py +72 -18
- pipelines/agent_ask.py +10 -1
- pipelines/mock_ask.py +3 -2
app.py
CHANGED
|
@@ -45,6 +45,7 @@ Module layout:
|
|
| 45 |
|
| 46 |
import base64
|
| 47 |
import io
|
|
|
|
| 48 |
import logging
|
| 49 |
import os
|
| 50 |
import shutil
|
|
@@ -56,6 +57,8 @@ from fastapi.responses import FileResponse, HTMLResponse, Response
|
|
| 56 |
from huggingface_hub import HfApi, snapshot_download
|
| 57 |
|
| 58 |
from core.constants import (
|
|
|
|
|
|
|
| 59 |
DEFAULT_TOP_K,
|
| 60 |
GROUND_ENABLE_THINKING,
|
| 61 |
LIBRARY_DATASET_ID,
|
|
@@ -114,6 +117,8 @@ def _build_libraries():
|
|
| 114 |
|
| 115 |
|
| 116 |
VISUAL_STORE, PARSED_STORE, PIPELINE = _build_libraries()
|
|
|
|
|
|
|
| 117 |
# method -> store, for the picker / pdf lookups. In mock both keys map to the
|
| 118 |
# one MockStore, so every mock manual reads as indexed under both methods.
|
| 119 |
_METHOD_STORES = {"visual": VISUAL_STORE, "parsed": PARSED_STORE}
|
|
@@ -293,6 +298,7 @@ def api_find(
|
|
| 293 |
pages: list = None,
|
| 294 |
history: list = None,
|
| 295 |
think: bool = GROUND_ENABLE_THINKING,
|
|
|
|
| 296 |
) -> dict: # the per-yield type: Server.api infers outputs from this annotation
|
| 297 |
"""One agent turn (one ZeroGPU call), streamed as events (see
|
| 298 |
pipelines/agent_ask.py for the protocol). page/section are what the viewer
|
|
@@ -325,14 +331,19 @@ def api_find(
|
|
| 325 |
)
|
| 326 |
viewer = {"page": int(page or 0), "section": str(section or ""), "pages": shown}
|
| 327 |
options = _router_options(manual, request)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
log.info(
|
| 329 |
-
"find: manual=%s k=%s think=%s viewer=%s hist=%d opts=%d q=%r",
|
| 330 |
-
manual, k, bool(think), viewer, len(history or []),
|
|
|
|
| 331 |
)
|
| 332 |
try:
|
| 333 |
events = PIPELINE.run_find(
|
| 334 |
VISUAL_STORE, PARSED_STORE, request, [manual], int(k), options,
|
| 335 |
-
viewer, history, bool(think),
|
| 336 |
)
|
| 337 |
for ev in events:
|
| 338 |
if ev.get("type") == "tool_result" and "gallery" in ev:
|
|
@@ -367,8 +378,8 @@ _FRONTEND_DIR = os.path.join(os.path.dirname(__file__), "frontend")
|
|
| 367 |
@app.get("/")
|
| 368 |
def index():
|
| 369 |
"""Serve the single-page UI, injecting the small bit of server config the
|
| 370 |
-
frontend needs (default/max k, default grounding-thinking
|
| 371 |
-
extra round-trip on load."""
|
| 372 |
with open(os.path.join(_FRONTEND_DIR, "index.html")) as f:
|
| 373 |
html = f.read()
|
| 374 |
html = (
|
|
@@ -376,6 +387,13 @@ def index():
|
|
| 376 |
.replace("__MAX_K__", str(MAX_TOP_K))
|
| 377 |
# Initial state of the settings-panel "thinking" toggle (a JS bool).
|
| 378 |
.replace("__GROUND_THINK__", "true" if GROUND_ENABLE_THINKING else "false")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
# Cache-bust key for /page images: changing the render DPI changes the
|
| 380 |
# served page size, so it must change the URL too β otherwise a browser
|
| 381 |
# could keep an old-resolution page (cached up to a day) under the same
|
|
|
|
| 45 |
|
| 46 |
import base64
|
| 47 |
import io
|
| 48 |
+
import json
|
| 49 |
import logging
|
| 50 |
import os
|
| 51 |
import shutil
|
|
|
|
| 57 |
from huggingface_hub import HfApi, snapshot_download
|
| 58 |
|
| 59 |
from core.constants import (
|
| 60 |
+
AGENT_MODELS,
|
| 61 |
+
DEFAULT_AGENT_MODEL,
|
| 62 |
DEFAULT_TOP_K,
|
| 63 |
GROUND_ENABLE_THINKING,
|
| 64 |
LIBRARY_DATASET_ID,
|
|
|
|
| 117 |
|
| 118 |
|
| 119 |
VISUAL_STORE, PARSED_STORE, PIPELINE = _build_libraries()
|
| 120 |
+
# Valid agent-brain keys, for validating the per-request `agent_model`.
|
| 121 |
+
_AGENT_MODEL_KEYS = {m["key"] for m in AGENT_MODELS}
|
| 122 |
# method -> store, for the picker / pdf lookups. In mock both keys map to the
|
| 123 |
# one MockStore, so every mock manual reads as indexed under both methods.
|
| 124 |
_METHOD_STORES = {"visual": VISUAL_STORE, "parsed": PARSED_STORE}
|
|
|
|
| 298 |
pages: list = None,
|
| 299 |
history: list = None,
|
| 300 |
think: bool = GROUND_ENABLE_THINKING,
|
| 301 |
+
agent_model: str = DEFAULT_AGENT_MODEL,
|
| 302 |
) -> dict: # the per-yield type: Server.api infers outputs from this annotation
|
| 303 |
"""One agent turn (one ZeroGPU call), streamed as events (see
|
| 304 |
pipelines/agent_ask.py for the protocol). page/section are what the viewer
|
|
|
|
| 331 |
)
|
| 332 |
viewer = {"page": int(page or 0), "section": str(section or ""), "pages": shown}
|
| 333 |
options = _router_options(manual, request)
|
| 334 |
+
# Unknown model key β default (the pipeline falls back too; validate here so
|
| 335 |
+
# the log reflects what actually ran).
|
| 336 |
+
if agent_model not in _AGENT_MODEL_KEYS:
|
| 337 |
+
agent_model = DEFAULT_AGENT_MODEL
|
| 338 |
log.info(
|
| 339 |
+
"find: manual=%s k=%s think=%s model=%s viewer=%s hist=%d opts=%d q=%r",
|
| 340 |
+
manual, k, bool(think), agent_model, viewer, len(history or []),
|
| 341 |
+
len(options), request[:200],
|
| 342 |
)
|
| 343 |
try:
|
| 344 |
events = PIPELINE.run_find(
|
| 345 |
VISUAL_STORE, PARSED_STORE, request, [manual], int(k), options,
|
| 346 |
+
viewer, history, bool(think), agent_model,
|
| 347 |
)
|
| 348 |
for ev in events:
|
| 349 |
if ev.get("type") == "tool_result" and "gallery" in ev:
|
|
|
|
| 378 |
@app.get("/")
|
| 379 |
def index():
|
| 380 |
"""Serve the single-page UI, injecting the small bit of server config the
|
| 381 |
+
frontend needs (default/max k, default grounding-thinking, the agent-model
|
| 382 |
+
list + default) so it needs no extra round-trip on load."""
|
| 383 |
with open(os.path.join(_FRONTEND_DIR, "index.html")) as f:
|
| 384 |
html = f.read()
|
| 385 |
html = (
|
|
|
|
| 387 |
.replace("__MAX_K__", str(MAX_TOP_K))
|
| 388 |
# Initial state of the settings-panel "thinking" toggle (a JS bool).
|
| 389 |
.replace("__GROUND_THINK__", "true" if GROUND_ENABLE_THINKING else "false")
|
| 390 |
+
# Agent-brain picker: the selectable models (key+label) and the default,
|
| 391 |
+
# so the settings dropdown needs no extra round-trip on load.
|
| 392 |
+
.replace(
|
| 393 |
+
"__AGENT_MODELS_JSON__",
|
| 394 |
+
json.dumps([{"key": m["key"], "label": m["label"]} for m in AGENT_MODELS]),
|
| 395 |
+
)
|
| 396 |
+
.replace("__AGENT_MODEL__", DEFAULT_AGENT_MODEL)
|
| 397 |
# Cache-bust key for /page images: changing the render DPI changes the
|
| 398 |
# served page size, so it must change the URL too β otherwise a browser
|
| 399 |
# could keep an old-resolution page (cached up to a day) under the same
|
core/constants.py
CHANGED
|
@@ -42,6 +42,46 @@ GROUND_THINK_MAX_NEW_TOKENS = 512
|
|
| 42 |
# remote code to drift) but overridable; pin a commit before a real deploy.
|
| 43 |
MINICPM_AGENT_MODEL_ID = os.environ.get("MINICPM_AGENT_MODEL_ID", "openbmb/MiniCPM5-1B")
|
| 44 |
MINICPM_AGENT_REVISION = os.environ.get("MINICPM_AGENT_REVISION", "") or None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# A tool-call decision is short JSON; a rerank reply is a single number. 96 was
|
| 46 |
# too tight β the 1B writes verbose search queries and was getting CUT OFF
|
| 47 |
# mid-string (unterminated JSON β parse fail β wasted retry), seen live.
|
|
|
|
| 42 |
# remote code to drift) but overridable; pin a commit before a real deploy.
|
| 43 |
MINICPM_AGENT_MODEL_ID = os.environ.get("MINICPM_AGENT_MODEL_ID", "openbmb/MiniCPM5-1B")
|
| 44 |
MINICPM_AGENT_REVISION = os.environ.get("MINICPM_AGENT_REVISION", "") or None
|
| 45 |
+
|
| 46 |
+
# Selectable agent brains, offered in the UI settings panel. ONE model is
|
| 47 |
+
# resident in VRAM at a time β switching evicts the previous and loads the next
|
| 48 |
+
# (models/minicpm_agent.use_model). All load as a plain AutoModelForCausalLM.
|
| 49 |
+
# `thinking` flags whether the chat template accepts enable_thinking (Qwen3 and
|
| 50 |
+
# MiniCPM do β tool routing passes it False; Cohere's template does not, so the
|
| 51 |
+
# kwarg is omitted there). The FIRST entry is the default at boot and tracks the
|
| 52 |
+
# MINICPM_AGENT_MODEL_ID/REVISION env overrides, so existing config still
|
| 53 |
+
# applies. All four stay well under the hackathon's 32B total-params budget.
|
| 54 |
+
AGENT_MODELS = [
|
| 55 |
+
{
|
| 56 |
+
"key": "minicpm5-1b",
|
| 57 |
+
"label": "MiniCPM5 1B",
|
| 58 |
+
"model_id": MINICPM_AGENT_MODEL_ID,
|
| 59 |
+
"revision": MINICPM_AGENT_REVISION,
|
| 60 |
+
"thinking": True,
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"key": "qwen3-1.7b",
|
| 64 |
+
"label": "Qwen3 1.7B",
|
| 65 |
+
"model_id": "Qwen/Qwen3-1.7B",
|
| 66 |
+
"revision": None,
|
| 67 |
+
"thinking": True,
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"key": "qwen3-0.6b",
|
| 71 |
+
"label": "Qwen3 0.6B",
|
| 72 |
+
"model_id": "Qwen/Qwen3-0.6B",
|
| 73 |
+
"revision": None,
|
| 74 |
+
"thinking": True,
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"key": "tiny-aya",
|
| 78 |
+
"label": "Tiny Aya 3.35B (Cohere)",
|
| 79 |
+
"model_id": "CohereLabs/tiny-aya-global",
|
| 80 |
+
"revision": None,
|
| 81 |
+
"thinking": False,
|
| 82 |
+
},
|
| 83 |
+
]
|
| 84 |
+
DEFAULT_AGENT_MODEL = AGENT_MODELS[0]["key"]
|
| 85 |
# A tool-call decision is short JSON; a rerank reply is a single number. 96 was
|
| 86 |
# too tight β the 1B writes verbose search queries and was getting CUT OFF
|
| 87 |
# mid-string (unterminated JSON β parse fail β wasted retry), seen live.
|
core/pdf.py
CHANGED
|
@@ -57,9 +57,9 @@ def pdf_outline(pdf_path: str) -> list[dict]:
|
|
| 57 |
doc = fitz.open(pdf_path)
|
| 58 |
try:
|
| 59 |
entries = [
|
| 60 |
-
{"title": " ".join(title.split()), "page_start":
|
| 61 |
for _, title, page in doc.get_toc()
|
| 62 |
-
if title.strip()
|
| 63 |
]
|
| 64 |
for i, e in enumerate(entries):
|
| 65 |
e["page_end"] = (
|
|
|
|
| 57 |
doc = fitz.open(pdf_path)
|
| 58 |
try:
|
| 59 |
entries = [
|
| 60 |
+
{"title": " ".join(title.split()), "page_start": page}
|
| 61 |
for _, title, page in doc.get_toc()
|
| 62 |
+
if title.strip() and page >= 1
|
| 63 |
]
|
| 64 |
for i, e in enumerate(entries):
|
| 65 |
e["page_end"] = (
|
frontend/index.html
CHANGED
|
@@ -345,6 +345,21 @@
|
|
| 345 |
class="w-full accent-brand-600">
|
| 346 |
</div>
|
| 347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
<!-- think: let the VLM reason before committing to a circle box -->
|
| 349 |
<div class="mt-5 flex items-start justify-between gap-3">
|
| 350 |
<div>
|
|
@@ -396,6 +411,11 @@ function repairGuy() {
|
|
| 396 |
// helps diagram-callout targets). Sent as `think` with each /find turn;
|
| 397 |
// initialized from the server default.
|
| 398 |
think:__GROUND_THINK__,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
input:'', loading:false, status:'',
|
| 400 |
settingsOpen:false,
|
| 401 |
ICONS,
|
|
@@ -486,7 +506,7 @@ function repairGuy() {
|
|
| 486 |
|
| 487 |
// --- viewer state machine -----------------------------------------
|
| 488 |
sectionTitle(p){ let t=''; for(const s of this.sections){ if(s.page_start<=p) t=s.title; else break; } return t; },
|
| 489 |
-
sectionIndex(p){ let i=-1; this.sections.
|
| 490 |
tocActive(j){ return j===this.sectionIndex(this.viewPage); },
|
| 491 |
|
| 492 |
setPage(p, push=false){
|
|
@@ -645,7 +665,7 @@ function repairGuy() {
|
|
| 645 |
mono:this.history.map((h,i)=>`${i+1}. asked: ${h.request}\n did: ${h.action}`).join('\n')});
|
| 646 |
try{
|
| 647 |
const job = this.client.submit('/find', {
|
| 648 |
-
request:q, manual:this.manual, k:this.k, think:this.think,
|
| 649 |
page: this.viewDoc ? this.viewPage : 0, section: this.sectionTitle(this.viewPage),
|
| 650 |
pages: this.spreadPages, // every page currently on screen β the agent may circle on any
|
| 651 |
history: this.history,
|
|
@@ -776,6 +796,14 @@ function repairGuy() {
|
|
| 776 |
// loaded as injected <script>s so they stay out of initial page load.
|
| 777 |
// Single-threaded β no SharedArrayBuffer, so no cross-origin isolation
|
| 778 |
// is needed inside the HF Spaces iframe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 779 |
await this.loadScript('/vendor/onnx/ort.wasm.min.js');
|
| 780 |
window.ort.env.wasm.numThreads = 1;
|
| 781 |
window.ort.env.wasm.wasmPaths = '/vendor/onnx/';
|
|
|
|
| 345 |
class="w-full accent-brand-600">
|
| 346 |
</div>
|
| 347 |
|
| 348 |
+
<!-- agent brain: which model drives the find-and-point loop -->
|
| 349 |
+
<div class="mt-5">
|
| 350 |
+
<label class="block text-xs font-semibold uppercase tracking-wide text-brand-500/80 mb-1.5">Agent brain</label>
|
| 351 |
+
<div class="relative">
|
| 352 |
+
<select x-model="agentModel"
|
| 353 |
+
class="w-full appearance-none rounded-xl border border-brand-200 bg-brand-50/50 px-3.5 py-2.5 pr-9 text-sm font-medium text-navy focus:border-brand-400 focus:ring-2 focus:ring-brand-100 outline-none transition">
|
| 354 |
+
<template x-for="m in agentModels" :key="m.key">
|
| 355 |
+
<option :value="m.key" x-text="m.label"></option>
|
| 356 |
+
</template>
|
| 357 |
+
</select>
|
| 358 |
+
<i data-lucide="chevron-down" class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-brand-400"></i>
|
| 359 |
+
</div>
|
| 360 |
+
<p class="mt-1 text-xs text-brand-400">The model that finds pages and points. Switching loads it fresh β the first turn after a change is slower.</p>
|
| 361 |
+
</div>
|
| 362 |
+
|
| 363 |
<!-- think: let the VLM reason before committing to a circle box -->
|
| 364 |
<div class="mt-5 flex items-start justify-between gap-3">
|
| 365 |
<div>
|
|
|
|
| 411 |
// helps diagram-callout targets). Sent as `think` with each /find turn;
|
| 412 |
// initialized from the server default.
|
| 413 |
think:__GROUND_THINK__,
|
| 414 |
+
// The agent "brain" picker: the selectable models (key+label) and the
|
| 415 |
+
// current choice, sent as `agent_model` each turn. Switching one in evicts
|
| 416 |
+
// the previous from VRAM server-side (load-on-switch), so the FIRST turn
|
| 417 |
+
// after a change is slower while the new model loads.
|
| 418 |
+
agentModels:__AGENT_MODELS_JSON__, agentModel:'__AGENT_MODEL__',
|
| 419 |
input:'', loading:false, status:'',
|
| 420 |
settingsOpen:false,
|
| 421 |
ICONS,
|
|
|
|
| 506 |
|
| 507 |
// --- viewer state machine -----------------------------------------
|
| 508 |
sectionTitle(p){ let t=''; for(const s of this.sections){ if(s.page_start<=p) t=s.title; else break; } return t; },
|
| 509 |
+
sectionIndex(p){ let i=-1; for(let j=0;j<this.sections.length;j++){ if(this.sections[j].page_start<=p) i=j; else break; } return i; },
|
| 510 |
tocActive(j){ return j===this.sectionIndex(this.viewPage); },
|
| 511 |
|
| 512 |
setPage(p, push=false){
|
|
|
|
| 665 |
mono:this.history.map((h,i)=>`${i+1}. asked: ${h.request}\n did: ${h.action}`).join('\n')});
|
| 666 |
try{
|
| 667 |
const job = this.client.submit('/find', {
|
| 668 |
+
request:q, manual:this.manual, k:this.k, think:this.think, agent_model:this.agentModel,
|
| 669 |
page: this.viewDoc ? this.viewPage : 0, section: this.sectionTitle(this.viewPage),
|
| 670 |
pages: this.spreadPages, // every page currently on screen β the agent may circle on any
|
| 671 |
history: this.history,
|
|
|
|
| 796 |
// loaded as injected <script>s so they stay out of initial page load.
|
| 797 |
// Single-threaded β no SharedArrayBuffer, so no cross-origin isolation
|
| 798 |
// is needed inside the HF Spaces iframe.
|
| 799 |
+
//
|
| 800 |
+
// VERSION COUPLING: vad/bundle.min.js has its OWN onnxruntime-web baked
|
| 801 |
+
// in (currently 1.22.0) and fetches the wasm binary from onnxWASMBasePath
|
| 802 |
+
// below (/vendor/onnx/). The .wasm/.mjs files there MUST match that ORT
|
| 803 |
+
// version β a mismatch dies at session creation with cryptic glue errors
|
| 804 |
+
// ("t.getValue is not a function" was 1.22 JS + 1.19 wasm). If you ever
|
| 805 |
+
// re-vendor vad's bundle, re-pull onnxruntime-web@<same-version>/dist/
|
| 806 |
+
// {ort-wasm-simd-threaded.wasm,ort-wasm-simd-threaded.mjs,ort.wasm.min.js}.
|
| 807 |
await this.loadScript('/vendor/onnx/ort.wasm.min.js');
|
| 808 |
window.ort.env.wasm.numThreads = 1;
|
| 809 |
window.ort.env.wasm.wasmPaths = '/vendor/onnx/';
|
frontend/vendor/onnx/ort-wasm-simd-threaded.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
var ortWasmThreaded = (() => {
|
| 3 |
var _scriptName = import.meta.url;
|
| 4 |
|
|
@@ -6,65 +5,56 @@ var ortWasmThreaded = (() => {
|
|
| 6 |
async function(moduleArg = {}) {
|
| 7 |
var moduleRtn;
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
var
|
| 12 |
-
|
| 13 |
-
a;
|
| 14 |
-
|
| 15 |
-
if(
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
function
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
var
|
| 26 |
-
|
| 27 |
-
var
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
var
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
function
|
| 40 |
-
|
| 41 |
-
function
|
| 42 |
-
|
| 43 |
-
function
|
| 44 |
-
|
| 45 |
-
function
|
| 46 |
-
function
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
function
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
"\x00\x00");for(z in v)c.includes(z)&&(c=c.replace(new RegExp(z,"g"),v[z](d)));c=c.replace(/\0\0/g,"%");z=Jc(c);if(z.length>b)return 0;Kc(z,a);return z.length-1}function Qb(a,b,c,d){return Pb(a>>>0,b>>>0,c>>>0,d>>>0)}C||fc();
|
| 60 |
-
var xc=[Ob,dc,qc,Wa,Xa,Ya,Za,$a,ab,bb,cb,db,eb,fb,gb,hb,sb,tb,Hb,Ib,Kb,Lb,Mb,Nb],Sa,Z=function(){function a(c,d){Z=c.exports;Z=Lc();ec.push(Z.Ea);mc=Z.Fa;Ha.unshift(Z.$);Ea=d;Ka();return Z}var b=va();O++;if(w.instantiateWasm)try{return w.instantiateWasm(b,a)}catch(c){I(`Module.instantiateWasm callback failed with error: ${c}`),x(c)}Na||=w.locateFile?Ma("ort-wasm-simd-threaded.wasm")?"ort-wasm-simd-threaded.wasm":w.locateFile?w.locateFile("ort-wasm-simd-threaded.wasm",F):F+"ort-wasm-simd-threaded.wasm":
|
| 61 |
-
(new URL("ort-wasm-simd-threaded.wasm",import.meta.url)).href;Ra(b,function(c){a(c.instance,c.module)}).catch(x);return{}}();w._OrtInit=(a,b)=>(w._OrtInit=Z.aa)(a,b);w._OrtGetLastError=(a,b)=>(w._OrtGetLastError=Z.ba)(a,b);w._OrtCreateSessionOptions=(a,b,c,d,f,h,k,q,y,v)=>(w._OrtCreateSessionOptions=Z.ca)(a,b,c,d,f,h,k,q,y,v);w._OrtAppendExecutionProvider=(a,b)=>(w._OrtAppendExecutionProvider=Z.da)(a,b);w._OrtAddFreeDimensionOverride=(a,b,c)=>(w._OrtAddFreeDimensionOverride=Z.ea)(a,b,c);
|
| 62 |
-
w._OrtAddSessionConfigEntry=(a,b,c)=>(w._OrtAddSessionConfigEntry=Z.fa)(a,b,c);w._OrtReleaseSessionOptions=a=>(w._OrtReleaseSessionOptions=Z.ga)(a);w._OrtCreateSession=(a,b,c)=>(w._OrtCreateSession=Z.ha)(a,b,c);w._OrtReleaseSession=a=>(w._OrtReleaseSession=Z.ia)(a);w._OrtGetInputOutputCount=(a,b,c)=>(w._OrtGetInputOutputCount=Z.ja)(a,b,c);w._OrtGetInputName=(a,b)=>(w._OrtGetInputName=Z.ka)(a,b);w._OrtGetOutputName=(a,b)=>(w._OrtGetOutputName=Z.la)(a,b);w._OrtFree=a=>(w._OrtFree=Z.ma)(a);
|
| 63 |
-
w._OrtCreateTensor=(a,b,c,d,f,h)=>(w._OrtCreateTensor=Z.na)(a,b,c,d,f,h);w._OrtGetTensorData=(a,b,c,d,f)=>(w._OrtGetTensorData=Z.oa)(a,b,c,d,f);w._OrtReleaseTensor=a=>(w._OrtReleaseTensor=Z.pa)(a);w._OrtCreateRunOptions=(a,b,c,d)=>(w._OrtCreateRunOptions=Z.qa)(a,b,c,d);w._OrtAddRunConfigEntry=(a,b,c)=>(w._OrtAddRunConfigEntry=Z.ra)(a,b,c);w._OrtReleaseRunOptions=a=>(w._OrtReleaseRunOptions=Z.sa)(a);w._OrtCreateBinding=a=>(w._OrtCreateBinding=Z.ta)(a);
|
| 64 |
-
w._OrtBindInput=(a,b,c)=>(w._OrtBindInput=Z.ua)(a,b,c);w._OrtBindOutput=(a,b,c,d)=>(w._OrtBindOutput=Z.va)(a,b,c,d);w._OrtClearBoundOutputs=a=>(w._OrtClearBoundOutputs=Z.wa)(a);w._OrtReleaseBinding=a=>(w._OrtReleaseBinding=Z.xa)(a);w._OrtRunWithBinding=(a,b,c,d,f)=>(w._OrtRunWithBinding=Z.ya)(a,b,c,d,f);w._OrtRun=(a,b,c,d,f,h,k,q)=>(w._OrtRun=Z.za)(a,b,c,d,f,h,k,q);w._OrtEndProfiling=a=>(w._OrtEndProfiling=Z.Aa)(a);var K=()=>(K=Z.Ba)();w._malloc=a=>(w._malloc=Z.Ca)(a);w._free=a=>(w._free=Z.Da)(a);
|
| 65 |
-
var wa=(a,b,c,d,f,h)=>(wa=Z.Ga)(a,b,c,d,f,h),Da=()=>(Da=Z.Ha)(),bc=(a,b,c,d,f)=>(bc=Z.Ia)(a,b,c,d,f),hc=a=>(hc=Z.Ja)(a),Ba=a=>(Ba=Z.Ka)(a),vc=()=>(vc=Z.La)(),kc=(a,b)=>(kc=Z.Ma)(a,b),cc=a=>(cc=Z.Na)(a),ac=a=>(ac=Z.Oa)(a),$b=()=>($b=Z.Pa)();w.___start_em_js=822690;w.___stop_em_js=822751;
|
| 66 |
-
function Lc(){var a=Z;a=Object.assign({},a);var b=d=>()=>d()>>>0,c=d=>f=>d(f)>>>0;a.Ba=b(a.Ba);a.Ca=c(a.Ca);a.emscripten_main_runtime_thread_id=b(a.emscripten_main_runtime_thread_id);a.Oa=c(a.Oa);a.Pa=b(a.Pa);return a}w.stackSave=()=>$b();w.stackRestore=a=>cc(a);w.stackAlloc=a=>ac(a);w.UTF8ToString=Q;w.stringToUTF8=W;w.lengthBytesUTF8=tc;var Mc;P=function Nc(){Mc||Oc();Mc||(P=Nc)};
|
| 67 |
-
function Oc(){0<O||(C?(ha(w),C||jc(Ha),startWorker(w)):(jc(Ga),0<O||Mc||(Mc=!0,w.calledRun=!0,Fa||(C||jc(Ha),ha(w),C||jc(Ia)))))}Oc();moduleRtn=ia;
|
| 68 |
|
| 69 |
|
| 70 |
return moduleRtn;
|
|
@@ -72,7 +62,7 @@ function Oc(){0<O||(C?(ha(w),C||jc(Ha),startWorker(w)):(jc(Ga),0<O||Mc||(Mc=!0,w
|
|
| 72 |
);
|
| 73 |
})();
|
| 74 |
export default ortWasmThreaded;
|
| 75 |
-
var isPthread = globalThis.self?.name
|
| 76 |
var isNode = typeof globalThis.process?.versions?.node == 'string';
|
| 77 |
if (isNode) isPthread = (await import('worker_threads')).workerData === 'em-pthread';
|
| 78 |
|
|
|
|
|
|
|
| 1 |
var ortWasmThreaded = (() => {
|
| 2 |
var _scriptName = import.meta.url;
|
| 3 |
|
|
|
|
| 5 |
async function(moduleArg = {}) {
|
| 6 |
var moduleRtn;
|
| 7 |
|
| 8 |
+
var f=moduleArg,aa,ba,ca=new Promise((a,b)=>{aa=a;ba=b}),da="object"==typeof window,k="undefined"!=typeof WorkerGlobalScope,l="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type,m=k&&self.name?.startsWith("em-pthread");if(l){const {createRequire:a}=await import("module");var require=a(import.meta.url),n=require("worker_threads");global.Worker=n.Worker;m=(k=!n.jb)&&"em-pthread"==n.workerData}
|
| 9 |
+
f.mountExternalData=(a,b)=>{a.startsWith("./")&&(a=a.substring(2));(f.Sa||(f.Sa=new Map)).set(a,b)};f.unmountExternalData=()=>{delete f.Sa};var SharedArrayBuffer=globalThis.SharedArrayBuffer??(new WebAssembly.Memory({initial:0,maximum:0,lb:!0})).buffer.constructor,ea=Object.assign({},f),fa="./this.program",q=(a,b)=>{throw b;},r="",ha,t;
|
| 10 |
+
if(l){var fs=require("fs"),ia=require("path");import.meta.url.startsWith("data:")||(r=ia.dirname(require("url").fileURLToPath(import.meta.url))+"/");t=a=>{a=u(a)?new URL(a):a;return fs.readFileSync(a)};ha=async a=>{a=u(a)?new URL(a):a;return fs.readFileSync(a,void 0)};!f.thisProgram&&1<process.argv.length&&(fa=process.argv[1].replace(/\\/g,"/"));process.argv.slice(2);q=(a,b)=>{process.exitCode=a;throw b;}}else if(da||k)k?r=self.location.href:"undefined"!=typeof document&&document.currentScript&&
|
| 11 |
+
(r=document.currentScript.src),_scriptName&&(r=_scriptName),r.startsWith("blob:")?r="":r=r.slice(0,r.replace(/[?#].*/,"").lastIndexOf("/")+1),l||(k&&(t=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),ha=async a=>{if(u(a))return new Promise((c,d)=>{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";e.onload=()=>{200==e.status||0==e.status&&e.response?c(e.response):d(e.status)};e.onerror=d;e.send(null)});
|
| 12 |
+
var b=await fetch(a,{credentials:"same-origin"});if(b.ok)return b.arrayBuffer();throw Error(b.status+" : "+b.url);});var ja=console.log.bind(console),ka=console.error.bind(console);l&&(ja=(...a)=>fs.writeSync(1,a.join(" ")+"\n"),ka=(...a)=>fs.writeSync(2,a.join(" ")+"\n"));var la=ja,w=ka;Object.assign(f,ea);ea=null;var x=f.wasmBinary,y,ma,z=!1,A,B,na,oa,pa,qa,ra,C,sa,u=a=>a.startsWith("file://");function D(){y.buffer!=B.buffer&&E();return B}function F(){y.buffer!=B.buffer&&E();return na}
|
| 13 |
+
function ta(){y.buffer!=B.buffer&&E();return oa}function G(){y.buffer!=B.buffer&&E();return pa}function H(){y.buffer!=B.buffer&&E();return qa}function va(){y.buffer!=B.buffer&&E();return ra}function I(){y.buffer!=B.buffer&&E();return sa}
|
| 14 |
+
if(m){var wa;if(l){var xa=n.parentPort;xa.on("message",b=>onmessage({data:b}));Object.assign(globalThis,{self:global,postMessage:b=>xa.postMessage(b)})}var ya=!1;w=function(...b){b=b.join(" ");l?fs.writeSync(2,b+"\n"):console.error(b)};self.alert=function(...b){postMessage({Ra:"alert",text:b.join(" "),eb:J()})};self.onunhandledrejection=b=>{throw b.reason||b;};function a(b){try{var c=b.data,d=c.Ra;if("load"===d){let e=[];self.onmessage=g=>e.push(g);self.startWorker=()=>{postMessage({Ra:"loaded"});
|
| 15 |
+
for(let g of e)a(g);self.onmessage=a};for(const g of c.Za)if(!f[g]||f[g].proxy)f[g]=(...h)=>{postMessage({Ra:"callHandler",Ya:g,args:h})},"print"==g&&(la=f[g]),"printErr"==g&&(w=f[g]);y=c.gb;E();wa(c.hb)}else if("run"===d){za(c.Qa);Aa(c.Qa,0,0,1,0,0);Ba();Ca(c.Qa);ya||=!0;try{Da(c.bb,c.Va)}catch(e){if("unwind"!=e)throw e;}}else"setimmediate"!==c.target&&("checkMailbox"===d?ya&&K():d&&(w(`worker: received unknown command ${d}`),w(c)))}catch(e){throw Ea(),e;}}self.onmessage=a}
|
| 16 |
+
function E(){var a=y.buffer;f.HEAP8=B=new Int8Array(a);f.HEAP16=oa=new Int16Array(a);f.HEAPU8=na=new Uint8Array(a);f.HEAPU16=new Uint16Array(a);f.HEAP32=pa=new Int32Array(a);f.HEAPU32=qa=new Uint32Array(a);f.HEAPF32=ra=new Float32Array(a);f.HEAPF64=sa=new Float64Array(a);f.HEAP64=C=new BigInt64Array(a);f.HEAPU64=new BigUint64Array(a)}m||(y=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),E());function Fa(){m?startWorker(f):L.$()}var M=0,N=null;
|
| 17 |
+
function Ga(){M--;if(0==M&&N){var a=N;N=null;a()}}function O(a){a="Aborted("+a+")";w(a);z=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ba(a);throw a;}var Ha;async function Ia(a){if(!x)try{var b=await ha(a);return new Uint8Array(b)}catch{}if(a==Ha&&x)a=new Uint8Array(x);else if(t)a=t(a);else throw"both async and sync fetching of the wasm failed";return a}
|
| 18 |
+
async function Ja(a,b){try{var c=await Ia(a);return await WebAssembly.instantiate(c,b)}catch(d){w(`failed to asynchronously prepare wasm: ${d}`),O(d)}}async function Ka(a){var b=Ha;if(!x&&"function"==typeof WebAssembly.instantiateStreaming&&!u(b)&&!l)try{var c=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(c,a)}catch(d){w(`wasm streaming compile failed: ${d}`),w("falling back to ArrayBuffer instantiation")}return Ja(b,a)}
|
| 19 |
+
function La(){Ma={j:Na,b:Oa,E:Pa,f:Qa,U:Ra,A:Sa,C:Ta,V:Ua,S:Va,L:Wa,R:Xa,n:Ya,B:Za,y:$a,T:ab,z:bb,_:cb,O:db,w:eb,F:fb,t:gb,i:hb,N:Ca,X:ib,I:jb,J:kb,K:lb,G:mb,H:nb,u:ob,q:pb,Z:qb,o:rb,k:sb,Y:tb,d:ub,W:vb,x:wb,c:xb,e:yb,h:zb,v:Ab,s:Bb,r:Cb,P:Db,Q:Eb,D:Fb,g:Gb,m:Hb,M:Ib,l:Jb,a:y,p:Kb};return{a:Ma}}
|
| 20 |
+
var Mb={802156:(a,b,c,d,e)=>{if("undefined"==typeof f||!f.Sa)return 1;a=Lb(Number(a>>>0));a.startsWith("./")&&(a=a.substring(2));a=f.Sa.get(a);if(!a)return 2;b=Number(b>>>0);c=Number(c>>>0);d=Number(d>>>0);if(b+c>a.byteLength)return 3;try{const g=a.subarray(b,b+c);switch(e){case 0:F().set(g,d>>>0);break;case 1:f.ib?f.ib(d,g):f.kb(d,g);break;default:return 4}return 0}catch{return 4}},802980:()=>"undefined"!==typeof wasmOffsetConverter};function Na(){return"undefined"!==typeof wasmOffsetConverter}
|
| 21 |
+
class Nb{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
|
| 22 |
+
var Ob=a=>{a.terminate();a.onmessage=()=>{}},Pb=[],Sb=a=>{0==Q.length&&(Qb(),Rb(Q[0]));var b=Q.pop();if(!b)return 6;R.push(b);S[a.Qa]=b;b.Qa=a.Qa;var c={Ra:"run",bb:a.ab,Va:a.Va,Qa:a.Qa};l&&b.unref();b.postMessage(c,a.Xa);return 0},T=0,V=(a,b,...c)=>{for(var d=2*c.length,e=Tb(),g=Ub(8*d),h=g>>>3,p=0;p<c.length;p++){var v=c[p];"bigint"==typeof v?(C[h+2*p]=1n,C[h+2*p+1]=v):(C[h+2*p]=0n,I()[h+2*p+1>>>0]=v)}a=Vb(a,0,d,g,b);U(e);return a};
|
| 23 |
+
function Kb(a){if(m)return V(0,1,a);A=a;if(!(0<T)){for(var b of R)Ob(b);for(b of Q)Ob(b);Q=[];R=[];S={};z=!0}q(a,new Nb(a))}function Wb(a){if(m)return V(1,0,a);Fb(a)}var Fb=a=>{A=a;if(m)throw Wb(a),"unwind";Kb(a)},Q=[],R=[],Xb=[],S={};function Yb(){for(var a=f.numThreads-1;a--;)Qb();Pb.unshift(()=>{M++;Zb(()=>Ga())})}var ac=a=>{var b=a.Qa;delete S[b];Q.push(a);R.splice(R.indexOf(a),1);a.Qa=0;$b(b)};function Ba(){Xb.forEach(a=>a())}
|
| 24 |
+
var Rb=a=>new Promise(b=>{a.onmessage=g=>{g=g.data;var h=g.Ra;if(g.Ta&&g.Ta!=J()){var p=S[g.Ta];p?p.postMessage(g,g.Xa):w(`Internal error! Worker sent a message "${h}" to target pthread ${g.Ta}, but that thread no longer exists!`)}else if("checkMailbox"===h)K();else if("spawnThread"===h)Sb(g);else if("cleanupThread"===h)ac(S[g.cb]);else if("loaded"===h)a.loaded=!0,l&&!a.Qa&&a.unref(),b(a);else if("alert"===h)alert(`Thread ${g.eb}: ${g.text}`);else if("setimmediate"===g.target)a.postMessage(g);else if("callHandler"===
|
| 25 |
+
h)f[g.Ya](...g.args);else h&&w(`worker sent an unknown command ${h}`)};a.onerror=g=>{w(`${"worker sent an error!"} ${g.filename}:${g.lineno}: ${g.message}`);throw g;};l&&(a.on("message",g=>a.onmessage({data:g})),a.on("error",g=>a.onerror(g)));var c=[],d=[],e;for(e of d)f.propertyIsEnumerable(e)&&c.push(e);a.postMessage({Ra:"load",Za:c,gb:y,hb:ma})});function Zb(a){m?a():Promise.all(Q.map(Rb)).then(a)}
|
| 26 |
+
function Qb(){var a=new Worker(new URL(import.meta.url),{type:"module",workerData:"em-pthread",name:"em-pthread"});Q.push(a)}var za=a=>{E();var b=H()[a+52>>>2>>>0];a=H()[a+56>>>2>>>0];bc(b,b-a);U(b)},W=[],cc,Da=(a,b)=>{T=0;var c=W[a];c||(a>=W.length&&(W.length=a+1),W[a]=c=cc.get(a));a=c(b);0<T?A=a:dc(a)};class ec{constructor(a){this.Ua=a-24}}var fc=0,gc=0;
|
| 27 |
+
function Oa(a,b,c){a>>>=0;var d=new ec(a);b>>>=0;c>>>=0;H()[d.Ua+16>>>2>>>0]=0;H()[d.Ua+4>>>2>>>0]=b;H()[d.Ua+8>>>2>>>0]=c;fc=a;gc++;throw fc;}function hc(a,b,c,d){return m?V(2,1,a,b,c,d):Pa(a,b,c,d)}function Pa(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;if("undefined"==typeof SharedArrayBuffer)return 6;var e=[];if(m&&0===e.length)return hc(a,b,c,d);a={ab:c,Qa:a,Va:d,Xa:e};return m?(a.Ra="spawnThread",postMessage(a,e),0):Sb(a)}
|
| 28 |
+
var ic="undefined"!=typeof TextDecoder?new TextDecoder:void 0,jc=(a,b=0,c=NaN)=>{b>>>=0;var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.buffer&&ic)return ic.decode(a.buffer instanceof ArrayBuffer?a.subarray(b,c):a.slice(b,c));for(d="";b<c;){var e=a[b++];if(e&128){var g=a[b++]&63;if(192==(e&224))d+=String.fromCharCode((e&31)<<6|g);else{var h=a[b++]&63;e=224==(e&240)?(e&15)<<12|g<<6|h:(e&7)<<18|g<<12|h<<6|a[b++]&63;65536>e?d+=String.fromCharCode(e):(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|
|
| 29 |
+
e&1023))}}else d+=String.fromCharCode(e)}return d},Lb=(a,b)=>(a>>>=0)?jc(F(),a,b):"";function Qa(a,b,c){return m?V(3,1,a,b,c):0}function Ra(a,b){if(m)return V(4,1,a,b)}
|
| 30 |
+
var X=(a,b,c)=>{var d=F();b>>>=0;if(0<c){var e=b;c=b+c-1;for(var g=0;g<a.length;++g){var h=a.charCodeAt(g);if(55296<=h&&57343>=h){var p=a.charCodeAt(++g);h=65536+((h&1023)<<10)|p&1023}if(127>=h){if(b>=c)break;d[b++>>>0]=h}else{if(2047>=h){if(b+1>=c)break;d[b++>>>0]=192|h>>6}else{if(65535>=h){if(b+2>=c)break;d[b++>>>0]=224|h>>12}else{if(b+3>=c)break;d[b++>>>0]=240|h>>18;d[b++>>>0]=128|h>>12&63}d[b++>>>0]=128|h>>6&63}d[b++>>>0]=128|h&63}}d[b>>>0]=0;a=b-e}else a=0;return a};
|
| 31 |
+
function Sa(a,b){if(m)return V(5,1,a,b)}function Ta(a,b,c){if(m)return V(6,1,a,b,c)}function Ua(a,b,c){return m?V(7,1,a,b,c):0}function Va(a,b){if(m)return V(8,1,a,b)}function Wa(a,b,c){if(m)return V(9,1,a,b,c)}function Xa(a,b,c,d){if(m)return V(10,1,a,b,c,d)}function Ya(a,b,c,d){if(m)return V(11,1,a,b,c,d)}function Za(a,b,c,d){if(m)return V(12,1,a,b,c,d)}function $a(a){if(m)return V(13,1,a)}function ab(a,b){if(m)return V(14,1,a,b)}function bb(a,b,c){if(m)return V(15,1,a,b,c)}var cb=()=>O("");
|
| 32 |
+
function db(a){Aa(a>>>0,!k,1,!da,131072,!1);Ba()}var kc=a=>{if(!z)try{if(a(),!(0<T))try{m?dc(A):Fb(A)}catch(b){b instanceof Nb||"unwind"==b||q(1,b)}}catch(b){b instanceof Nb||"unwind"==b||q(1,b)}};function Ca(a){a>>>=0;"function"===typeof Atomics.fb&&(Atomics.fb(G(),a>>>2,a).value.then(K),a+=128,Atomics.store(G(),a>>>2,1))}var K=()=>{var a=J();a&&(Ca(a),kc(lc))};function eb(a,b){a>>>=0;a==b>>>0?setTimeout(K):m?postMessage({Ta:a,Ra:"checkMailbox"}):(a=S[a])&&a.postMessage({Ra:"checkMailbox"})}
|
| 33 |
+
var mc=[];function fb(a,b,c,d,e){b>>>=0;d/=2;mc.length=d;c=e>>>0>>>3;for(e=0;e<d;e++)mc[e]=C[c+2*e]?C[c+2*e+1]:I()[c+2*e+1>>>0];return(b?Mb[b]:nc[a])(...mc)}var gb=()=>{T=0};function hb(a){a>>>=0;m?postMessage({Ra:"cleanupThread",cb:a}):ac(S[a])}function ib(a){l&&S[a>>>0].ref()}
|
| 34 |
+
function jb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);G()[b>>>2>>>0]=a.getUTCSeconds();G()[b+4>>>2>>>0]=a.getUTCMinutes();G()[b+8>>>2>>>0]=a.getUTCHours();G()[b+12>>>2>>>0]=a.getUTCDate();G()[b+16>>>2>>>0]=a.getUTCMonth();G()[b+20>>>2>>>0]=a.getUTCFullYear()-1900;G()[b+24>>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;G()[b+28>>>2>>>0]=a}
|
| 35 |
+
var oc=a=>0===a%4&&(0!==a%100||0===a%400),pc=[0,31,60,91,121,152,182,213,244,274,305,335],qc=[0,31,59,90,120,151,181,212,243,273,304,334];
|
| 36 |
+
function kb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);G()[b>>>2>>>0]=a.getSeconds();G()[b+4>>>2>>>0]=a.getMinutes();G()[b+8>>>2>>>0]=a.getHours();G()[b+12>>>2>>>0]=a.getDate();G()[b+16>>>2>>>0]=a.getMonth();G()[b+20>>>2>>>0]=a.getFullYear()-1900;G()[b+24>>>2>>>0]=a.getDay();var c=(oc(a.getFullYear())?pc:qc)[a.getMonth()]+a.getDate()-1|0;G()[b+28>>>2>>>0]=c;G()[b+36>>>2>>>0]=-(60*a.getTimezoneOffset());c=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();
|
| 37 |
+
var d=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();a=(c!=d&&a.getTimezoneOffset()==Math.min(d,c))|0;G()[b+32>>>2>>>0]=a}
|
| 38 |
+
function lb(a){a>>>=0;var b=new Date(G()[a+20>>>2>>>0]+1900,G()[a+16>>>2>>>0],G()[a+12>>>2>>>0],G()[a+8>>>2>>>0],G()[a+4>>>2>>>0],G()[a>>>2>>>0],0),c=G()[a+32>>>2>>>0],d=b.getTimezoneOffset(),e=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),g=(new Date(b.getFullYear(),0,1)).getTimezoneOffset(),h=Math.min(g,e);0>c?G()[a+32>>>2>>>0]=Number(e!=g&&h==d):0<c!=(h==d)&&(e=Math.max(g,e),b.setTime(b.getTime()+6E4*((0<c?h:e)-d)));G()[a+24>>>2>>>0]=b.getDay();c=(oc(b.getFullYear())?pc:qc)[b.getMonth()]+
|
| 39 |
+
b.getDate()-1|0;G()[a+28>>>2>>>0]=c;G()[a>>>2>>>0]=b.getSeconds();G()[a+4>>>2>>>0]=b.getMinutes();G()[a+8>>>2>>>0]=b.getHours();G()[a+12>>>2>>>0]=b.getDate();G()[a+16>>>2>>>0]=b.getMonth();G()[a+20>>>2>>>0]=b.getYear();a=b.getTime();return BigInt(isNaN(a)?-1:a/1E3)}function mb(a,b,c,d,e,g,h){return m?V(16,1,a,b,c,d,e,g,h):-52}function nb(a,b,c,d,e,g){if(m)return V(17,1,a,b,c,d,e,g)}var Y={},xb=()=>performance.timeOrigin+performance.now();
|
| 40 |
+
function ob(a,b){if(m)return V(18,1,a,b);Y[a]&&(clearTimeout(Y[a].id),delete Y[a]);if(!b)return 0;var c=setTimeout(()=>{delete Y[a];kc(()=>rc(a,performance.timeOrigin+performance.now()))},b);Y[a]={id:c,mb:b};return 0}
|
| 41 |
+
function pb(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;var e=(new Date).getFullYear(),g=(new Date(e,0,1)).getTimezoneOffset();e=(new Date(e,6,1)).getTimezoneOffset();var h=Math.max(g,e);H()[a>>>2>>>0]=60*h;G()[b>>>2>>>0]=Number(g!=e);b=p=>{var v=Math.abs(p);return`UTC${0<=p?"-":"+"}${String(Math.floor(v/60)).padStart(2,"0")}${String(v%60).padStart(2,"0")}`};a=b(g);b=b(e);e<g?(X(a,c,17),X(b,d,17)):(X(a,d,17),X(b,c,17))}var tb=()=>Date.now(),sc=1;
|
| 42 |
+
function qb(a,b,c){if(!(0<=a&&3>=a))return 28;if(0===a)a=Date.now();else if(sc)a=performance.timeOrigin+performance.now();else return 52;C[c>>>0>>>3]=BigInt(Math.round(1E6*a));return 0}var tc=[];function rb(a,b,c){a>>>=0;b>>>=0;c>>>=0;tc.length=0;for(var d;d=F()[b++>>>0];){var e=105!=d;e&=112!=d;c+=e&&c%8?4:0;tc.push(112==d?H()[c>>>2>>>0]:106==d?C[c>>>3]:105==d?G()[c>>>2>>>0]:I()[c>>>3>>>0]);c+=e?8:4}return Mb[a](...tc)}var sb=()=>{};function ub(a,b){return w(Lb(a>>>0,b>>>0))}
|
| 43 |
+
var vb=()=>{T+=1;throw"unwind";};function wb(){return 4294901760}var yb=()=>l?require("os").cpus().length:navigator.hardwareConcurrency;function zb(){O("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER");return 0}
|
| 44 |
+
function Ab(a){a>>>=0;var b=F().length;if(a<=b||4294901760<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(4294901760,65536*Math.ceil(Math.max(a,d)/65536))-y.buffer.byteLength+65535)/65536|0;try{y.grow(d);E();var e=1;break a}catch(g){}e=void 0}if(e)return!0}return!1}var uc=()=>{O("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER");return 0},Z={},vc=a=>{a.forEach(b=>{var c=uc();c&&(Z[c]=b)})};
|
| 45 |
+
function Bb(){var a=Error().stack.toString().split("\n");"Error"==a[0]&&a.shift();vc(a);Z.Wa=uc();Z.$a=a;return Z.Wa}function Cb(a,b,c){a>>>=0;b>>>=0;if(Z.Wa==a)var d=Z.$a;else d=Error().stack.toString().split("\n"),"Error"==d[0]&&d.shift(),vc(d);for(var e=3;d[e]&&uc()!=a;)++e;for(a=0;a<c&&d[a+e];++a)G()[b+4*a>>>2>>>0]=uc();return a}
|
| 46 |
+
var wc={},yc=()=>{if(!xc){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:fa||"./this.program"},b;for(b in wc)void 0===wc[b]?delete a[b]:a[b]=wc[b];var c=[];for(b in a)c.push(`${b}=${a[b]}`);xc=c}return xc},xc;
|
| 47 |
+
function Db(a,b){if(m)return V(19,1,a,b);a>>>=0;b>>>=0;var c=0;yc().forEach((d,e)=>{var g=b+c;e=H()[a+4*e>>>2>>>0]=g;for(g=0;g<d.length;++g)D()[e++>>>0]=d.charCodeAt(g);D()[e>>>0]=0;c+=d.length+1});return 0}function Eb(a,b){if(m)return V(20,1,a,b);a>>>=0;b>>>=0;var c=yc();H()[a>>>2>>>0]=c.length;var d=0;c.forEach(e=>d+=e.length+1);H()[b>>>2>>>0]=d;return 0}function Gb(a){return m?V(21,1,a):52}function Hb(a,b,c,d){return m?V(22,1,a,b,c,d):52}function Ib(a,b,c,d){return m?V(23,1,a,b,c,d):70}
|
| 48 |
+
var zc=[null,[],[]];function Jb(a,b,c,d){if(m)return V(24,1,a,b,c,d);b>>>=0;c>>>=0;d>>>=0;for(var e=0,g=0;g<c;g++){var h=H()[b>>>2>>>0],p=H()[b+4>>>2>>>0];b+=8;for(var v=0;v<p;v++){var P=F()[h+v>>>0],ua=zc[a];0===P||10===P?((1===a?la:w)(jc(ua)),ua.length=0):ua.push(P)}e+=p}H()[d>>>2>>>0]=e;return 0}m||Yb();var nc=[Kb,Wb,hc,Qa,Ra,Sa,Ta,Ua,Va,Wa,Xa,Ya,Za,$a,ab,bb,mb,nb,ob,Db,Eb,Gb,Hb,Ib,Jb],Ma,L;
|
| 49 |
+
(async function(){function a(d,e){L=d.exports;L=Ac();Xb.push(L.Da);cc=L.Ea;ma=e;Ga();return L}M++;var b=La();if(f.instantiateWasm)return new Promise(d=>{f.instantiateWasm(b,(e,g)=>{a(e,g);d(e.exports)})});if(m)return new Promise(d=>{wa=e=>{var g=new WebAssembly.Instance(e,La());d(a(g,e))}});Ha??=f.locateFile?f.locateFile?f.locateFile("ort-wasm-simd-threaded.wasm",r):r+"ort-wasm-simd-threaded.wasm":(new URL("ort-wasm-simd-threaded.wasm",import.meta.url)).href;try{var c=await Ka(b);return a(c.instance,
|
| 50 |
+
c.module)}catch(d){return ba(d),Promise.reject(d)}})();f._OrtInit=(a,b)=>(f._OrtInit=L.aa)(a,b);f._OrtGetLastError=(a,b)=>(f._OrtGetLastError=L.ba)(a,b);f._OrtCreateSessionOptions=(a,b,c,d,e,g,h,p,v,P)=>(f._OrtCreateSessionOptions=L.ca)(a,b,c,d,e,g,h,p,v,P);f._OrtAppendExecutionProvider=(a,b,c,d,e)=>(f._OrtAppendExecutionProvider=L.da)(a,b,c,d,e);f._OrtAddFreeDimensionOverride=(a,b,c)=>(f._OrtAddFreeDimensionOverride=L.ea)(a,b,c);
|
| 51 |
+
f._OrtAddSessionConfigEntry=(a,b,c)=>(f._OrtAddSessionConfigEntry=L.fa)(a,b,c);f._OrtReleaseSessionOptions=a=>(f._OrtReleaseSessionOptions=L.ga)(a);f._OrtCreateSession=(a,b,c)=>(f._OrtCreateSession=L.ha)(a,b,c);f._OrtReleaseSession=a=>(f._OrtReleaseSession=L.ia)(a);f._OrtGetInputOutputCount=(a,b,c)=>(f._OrtGetInputOutputCount=L.ja)(a,b,c);f._OrtGetInputOutputMetadata=(a,b,c,d)=>(f._OrtGetInputOutputMetadata=L.ka)(a,b,c,d);f._OrtFree=a=>(f._OrtFree=L.la)(a);
|
| 52 |
+
f._OrtCreateTensor=(a,b,c,d,e,g)=>(f._OrtCreateTensor=L.ma)(a,b,c,d,e,g);f._OrtGetTensorData=(a,b,c,d,e)=>(f._OrtGetTensorData=L.na)(a,b,c,d,e);f._OrtReleaseTensor=a=>(f._OrtReleaseTensor=L.oa)(a);f._OrtCreateRunOptions=(a,b,c,d)=>(f._OrtCreateRunOptions=L.pa)(a,b,c,d);f._OrtAddRunConfigEntry=(a,b,c)=>(f._OrtAddRunConfigEntry=L.qa)(a,b,c);f._OrtReleaseRunOptions=a=>(f._OrtReleaseRunOptions=L.ra)(a);f._OrtCreateBinding=a=>(f._OrtCreateBinding=L.sa)(a);
|
| 53 |
+
f._OrtBindInput=(a,b,c)=>(f._OrtBindInput=L.ta)(a,b,c);f._OrtBindOutput=(a,b,c,d)=>(f._OrtBindOutput=L.ua)(a,b,c,d);f._OrtClearBoundOutputs=a=>(f._OrtClearBoundOutputs=L.va)(a);f._OrtReleaseBinding=a=>(f._OrtReleaseBinding=L.wa)(a);f._OrtRunWithBinding=(a,b,c,d,e)=>(f._OrtRunWithBinding=L.xa)(a,b,c,d,e);f._OrtRun=(a,b,c,d,e,g,h,p)=>(f._OrtRun=L.ya)(a,b,c,d,e,g,h,p);f._OrtEndProfiling=a=>(f._OrtEndProfiling=L.za)(a);var J=()=>(J=L.Aa)();f._free=a=>(f._free=L.Ba)(a);f._malloc=a=>(f._malloc=L.Ca)(a);
|
| 54 |
+
var Aa=(a,b,c,d,e,g)=>(Aa=L.Fa)(a,b,c,d,e,g),Ea=()=>(Ea=L.Ga)(),Vb=(a,b,c,d,e)=>(Vb=L.Ha)(a,b,c,d,e),$b=a=>($b=L.Ia)(a),dc=a=>(dc=L.Ja)(a),rc=(a,b)=>(rc=L.Ka)(a,b),lc=()=>(lc=L.La)(),bc=(a,b)=>(bc=L.Ma)(a,b),U=a=>(U=L.Na)(a),Ub=a=>(Ub=L.Oa)(a),Tb=()=>(Tb=L.Pa)();function Ac(){var a=L;a=Object.assign({},a);var b=d=>()=>d()>>>0,c=d=>e=>d(e)>>>0;a.Aa=b(a.Aa);a.Ca=c(a.Ca);a.Oa=c(a.Oa);a.Pa=b(a.Pa);a.__cxa_get_exception_ptr=c(a.__cxa_get_exception_ptr);return a}f.stackSave=()=>Tb();f.stackRestore=a=>U(a);
|
| 55 |
+
f.stackAlloc=a=>Ub(a);f.setValue=function(a,b,c="i8"){c.endsWith("*")&&(c="*");switch(c){case "i1":D()[a>>>0]=b;break;case "i8":D()[a>>>0]=b;break;case "i16":ta()[a>>>1>>>0]=b;break;case "i32":G()[a>>>2>>>0]=b;break;case "i64":C[a>>>3]=BigInt(b);break;case "float":va()[a>>>2>>>0]=b;break;case "double":I()[a>>>3>>>0]=b;break;case "*":H()[a>>>2>>>0]=b;break;default:O(`invalid type for setValue: ${c}`)}};
|
| 56 |
+
f.getValue=function(a,b="i8"){b.endsWith("*")&&(b="*");switch(b){case "i1":return D()[a>>>0];case "i8":return D()[a>>>0];case "i16":return ta()[a>>>1>>>0];case "i32":return G()[a>>>2>>>0];case "i64":return C[a>>>3];case "float":return va()[a>>>2>>>0];case "double":return I()[a>>>3>>>0];case "*":return H()[a>>>2>>>0];default:O(`invalid type for getValue: ${b}`)}};f.UTF8ToString=Lb;f.stringToUTF8=X;
|
| 57 |
+
f.lengthBytesUTF8=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);127>=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}return b};function Bc(){if(0<M)N=Bc;else if(m)aa(f),Fa();else{for(;0<Pb.length;)Pb.shift()(f);0<M?N=Bc:(f.calledRun=!0,z||(Fa(),aa(f)))}}Bc();f.PTR_SIZE=4;moduleRtn=ca;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
return moduleRtn;
|
|
|
|
| 62 |
);
|
| 63 |
})();
|
| 64 |
export default ortWasmThreaded;
|
| 65 |
+
var isPthread = globalThis.self?.name?.startsWith('em-pthread');
|
| 66 |
var isNode = typeof globalThis.process?.versions?.node == 'string';
|
| 67 |
if (isNode) isPthread = (await import('worker_threads')).workerData === 'em-pthread';
|
| 68 |
|
frontend/vendor/onnx/ort-wasm-simd-threaded.wasm
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71aef04959c5c1b6de461b6538e2058e306610034a85aad2742d0c7fd4533fe4
|
| 3 |
+
size 11210254
|
frontend/vendor/onnx/ort.wasm.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
/*!
|
| 2 |
-
* ONNX Runtime Web v1.
|
| 3 |
* Copyright (c) Microsoft Corporation. All rights reserved.
|
| 4 |
* Licensed under the MIT License.
|
| 5 |
*/
|
| 6 |
-
"use strict";var ort=(()=>{var Ne=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var Ar=Object.getOwnPropertyNames;var Or=Object.prototype.hasOwnProperty;var We=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var w=(t,e)=>()=>(t&&(e=t(t=0)),e);var me=(t,e)=>{for(var r in e)Ne(t,r,{get:e[r],enumerable:!0})},vr=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ar(e))!Or.call(t,n)&&n!==r&&Ne(t,n,{get:()=>e[n],enumerable:!(o=Tr(e,n))||o.enumerable});return t};var $e=t=>vr(Ne({},"__esModule",{value:!0}),t);var he,$,q,xr,ye,we=w(()=>{"use strict";he=new Map,$=[],q=(t,e,r)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let o=he.get(t);if(o===void 0)he.set(t,{backend:e,priority:r});else{if(o.priority>r)return;if(o.priority===r&&o.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${r}`)}if(r>=0){let n=$.indexOf(t);n!==-1&&$.splice(n,1);for(let a=0;a<$.length;a++)if(he.get($[a]).priority<=r){$.splice(a,0,t);return}$.push(t)}return}throw new TypeError("not a valid backend")},xr=async t=>{let e=he.get(t);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init(t)),await e.initPromise,e.initialized=!0,e.backend}catch(o){return r||(e.error=`${o}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},ye=async t=>{let e=t.executionProviders||[],r=e.map(i=>typeof i=="string"?i:i.name),o=r.length===0?$:r,n,a=[],s=new Set;for(let i of o){let u=await xr(i);typeof u=="string"?a.push({name:i,err:u}):(n||(n=u),n===u&&s.add(i))}if(!n)throw new Error(`no available backend found. ERR: ${a.map(i=>`[${i.name}] ${i.err}`).join(", ")}`);for(let{name:i,err:u}of a)r.includes(i)&&console.warn(`removing requested execution provider "${i}" from session options because it is not available: ${u}`);let f=e.filter(i=>s.has(typeof i=="string"?i:i.name));return[n,new Proxy(t,{get:(i,u)=>u==="executionProviders"?f:Reflect.get(i,u)})]}});var ft=w(()=>{"use strict";we()});var ct,dt=w(()=>{"use strict";ct="1.19.2"});var lt,U,Ge=w(()=>{"use strict";dt();lt="warning",U={wasm:{},webgl:{},webgpu:{},versions:{common:ct},set logLevel(t){if(t!==void 0){if(typeof t!="string"||["verbose","info","warning","error","fatal"].indexOf(t)===-1)throw new Error(`Unsupported logging level: ${t}`);lt=t}},get logLevel(){return lt}};Object.defineProperty(U,"logLevel",{enumerable:!0})});var S,pt=w(()=>{"use strict";Ge();S=U});var mt,ht,yt=w(()=>{"use strict";mt=(t,e)=>{let r=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=t.dims[3],r.height=t.dims[2];let o=r.getContext("2d");if(o!=null){let n,a;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(n=t.dims[2],a=t.dims[3]):(n=t.dims[3],a=t.dims[2]);let s=e?.format!==void 0?e.format:"RGB",f=e?.norm,i,u;f===void 0||f.mean===void 0?i=[255,255,255,255]:typeof f.mean=="number"?i=[f.mean,f.mean,f.mean,f.mean]:(i=[f.mean[0],f.mean[1],f.mean[2],0],f.mean[3]!==void 0&&(i[3]=f.mean[3])),f===void 0||f.bias===void 0?u=[0,0,0,0]:typeof f.bias=="number"?u=[f.bias,f.bias,f.bias,f.bias]:(u=[f.bias[0],f.bias[1],f.bias[2],0],f.bias[3]!==void 0&&(u[3]=f.bias[3]));let l=a*n,d=0,c=l,p=l*2,m=-1;s==="RGBA"?(d=0,c=l,p=l*2,m=l*3):s==="RGB"?(d=0,c=l,p=l*2):s==="RBG"&&(d=0,p=l,c=l*2);for(let y=0;y<a;y++)for(let b=0;b<n;b++){let T=(t.data[d++]-u[0])*i[0],h=(t.data[c++]-u[1])*i[1],g=(t.data[p++]-u[2])*i[2],O=m===-1?255:(t.data[m++]-u[3])*i[3];o.fillStyle="rgba("+T+","+h+","+g+","+O+")",o.fillRect(b,y,1,1)}if("toDataURL"in r)return r.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},ht=(t,e)=>{let r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(r!=null){let n,a,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(n=t.dims[2],a=t.dims[1],s=t.dims[3]):(n=t.dims[3],a=t.dims[2],s=t.dims[1]);let f=e!==void 0&&e.format!==void 0?e.format:"RGB",i=e?.norm,u,l;i===void 0||i.mean===void 0?u=[255,255,255,255]:typeof i.mean=="number"?u=[i.mean,i.mean,i.mean,i.mean]:(u=[i.mean[0],i.mean[1],i.mean[2],255],i.mean[3]!==void 0&&(u[3]=i.mean[3])),i===void 0||i.bias===void 0?l=[0,0,0,0]:typeof i.bias=="number"?l=[i.bias,i.bias,i.bias,i.bias]:(l=[i.bias[0],i.bias[1],i.bias[2],0],i.bias[3]!==void 0&&(l[3]=i.bias[3]));let d=a*n;if(e!==void 0&&(e.format!==void 0&&s===4&&e.format!=="RGBA"||s===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let c=4,p=0,m=1,y=2,b=3,T=0,h=d,g=d*2,O=-1;f==="RGBA"?(T=0,h=d,g=d*2,O=d*3):f==="RGB"?(T=0,h=d,g=d*2):f==="RBG"&&(T=0,g=d,h=d*2),o=r.createImageData(n,a);for(let B=0;B<a*n;p+=c,m+=c,y+=c,b+=c,B++)o.data[p]=(t.data[T++]-l[0])*u[0],o.data[m]=(t.data[h++]-l[1])*u[1],o.data[y]=(t.data[g++]-l[2])*u[2],o.data[b]=O===-1?255:(t.data[O++]-l[3])*u[3]}else throw new Error("Can not access image data");return o}});var ze,wt,gt,bt,Et,St=w(()=>{"use strict";ge();ze=(t,e)=>{if(t===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:r,width:o}=e,n=e.norm??{mean:255,bias:0},a,s;typeof n.mean=="number"?a=[n.mean,n.mean,n.mean,n.mean]:a=[n.mean[0],n.mean[1],n.mean[2],n.mean[3]??255],typeof n.bias=="number"?s=[n.bias,n.bias,n.bias,n.bias]:s=[n.bias[0],n.bias[1],n.bias[2],n.bias[3]??0];let f=e.format!==void 0?e.format:"RGBA",i=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",u=r*o,l=i==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),d=4,c=0,p=1,m=2,y=3,b=0,T=u,h=u*2,g=-1;f==="RGB"&&(d=3,c=0,p=1,m=2,y=-1),i==="RGBA"?g=u*3:i==="RBG"?(b=0,h=u,T=u*2):i==="BGR"&&(h=0,T=u,b=u*2);for(let B=0;B<u;B++,c+=d,m+=d,p+=d,y+=d)l[b++]=(t[c]+s[0])/a[0],l[T++]=(t[p]+s[1])/a[1],l[h++]=(t[m]+s[2])/a[2],g!==-1&&y!==-1&&(l[g++]=(t[y]+s[3])/a[3]);return i==="RGBA"?new P("float32",l,[1,4,r,o]):new P("float32",l,[1,3,r,o])},wt=async(t,e)=>{let r=typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement,o=typeof ImageData<"u"&&t instanceof ImageData,n=typeof ImageBitmap<"u"&&t instanceof ImageBitmap,a=typeof t=="string",s,f=e??{},i=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},u=l=>l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas?l.getContext("2d"):null;if(r){let l=i();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,p=t.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(c=e.resizedHeight,p=e.resizedWidth),e!==void 0){if(f=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");f.tensorFormat="RGBA",f.height=c,f.width=p}else f.tensorFormat="RGBA",f.height=c,f.width=p;d.drawImage(t,0,0),s=d.getImageData(0,0,p,c).data}else throw new Error("Can not access image data")}else if(o){let l,d;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(l=e.resizedHeight,d=e.resizedWidth):(l=t.height,d=t.width),e!==void 0&&(f=e),f.format="RGBA",f.height=l,f.width=d,e!==void 0){let c=i();c.width=d,c.height=l;let p=u(c);if(p!=null)p.putImageData(t,0,0),s=p.getImageData(0,0,d,l).data;else throw new Error("Can not access image data")}else s=t.data}else if(n){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let l=i();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,p=t.width;return d.drawImage(t,0,0,p,c),s=d.getImageData(0,0,p,c).data,f.height=c,f.width=p,ze(s,f)}else throw new Error("Can not access image data")}else{if(a)return new Promise((l,d)=>{let c=i(),p=u(c);if(!t||!p)return d();let m=new Image;m.crossOrigin="Anonymous",m.src=t,m.onload=()=>{c.width=m.width,c.height=m.height,p.drawImage(m,0,0,c.width,c.height);let y=p.getImageData(0,0,c.width,c.height);f.height=c.height,f.width=c.width,l(ze(y.data,f))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return ze(s,f);throw new Error("Input data provided is not supported - aborted tensor creation")},gt=(t,e)=>{let{width:r,height:o,download:n,dispose:a}=e,s=[1,o,r,4];return new P({location:"texture",type:"float32",texture:t,dims:s,download:n,dispose:a})},bt=(t,e)=>{let{dataType:r,dims:o,download:n,dispose:a}=e;return new P({location:"gpu-buffer",type:r??"float32",gpuBuffer:t,dims:o,download:n,dispose:a})},Et=(t,e,r)=>new P({location:"cpu-pinned",type:t,data:e,dims:r??[e.length]})});var G,oe,Tt,At,Ot=w(()=>{"use strict";G=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),oe=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Tt=!1,At=()=>{if(!Tt){Tt=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,r=typeof Float16Array<"u"&&Float16Array.from;t&&(G.set("int64",BigInt64Array),oe.set(BigInt64Array,"int64")),e&&(G.set("uint64",BigUint64Array),oe.set(BigUint64Array,"uint64")),r?(G.set("float16",Float16Array),oe.set(Float16Array,"float16")):G.set("float16",Uint16Array)}}});var vt,xt,It=w(()=>{"use strict";ge();vt=t=>{let e=1;for(let r=0;r<t.length;r++){let o=t[r];if(typeof o!="number"||!Number.isSafeInteger(o))throw new TypeError(`dims[${r}] must be an integer, got: ${o}`);if(o<0)throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${o}`);e*=o}return e},xt=(t,e)=>{switch(t.location){case"cpu":return new P(t.type,t.data,e);case"cpu-pinned":return new P({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new P({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new P({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}});var P,ge=w(()=>{"use strict";yt();St();Ot();It();P=class{constructor(e,r,o){At();let n,a;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,n=e.type,a=e.dims,e.location){case"cpu-pinned":{let f=G.get(n);if(!f)throw new TypeError(`unsupported type "${n}" to create tensor from pinned buffer`);if(!(e.data instanceof f))throw new TypeError(`buffer should be of type ${f.name}`);this.cpuData=e.data;break}case"texture":{if(n!=="float32")throw new TypeError(`unsupported type "${n}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(n!=="float32"&&n!=="float16"&&n!=="int32"&&n!=="int64"&&n!=="uint32"&&n!=="uint8"&&n!=="bool")throw new TypeError(`unsupported type "${n}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let f,i;if(typeof e=="string")if(n=e,i=o,e==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");f=r}else{let u=G.get(e);if(u===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(r)){if(e==="float16"&&u===Uint16Array)throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");e==="uint64"||e==="int64"?f=u.from(r,BigInt):f=u.from(r)}else if(r instanceof u)f=r;else throw new TypeError(`A ${n} tensor's data must be type of ${u}`)}else if(i=r,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let u=typeof e[0];if(u==="string")n="string",f=e;else if(u==="boolean")n="bool",f=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${u}.`)}else{let u=oe.get(e.constructor);if(u===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);n=u,f=e}if(i===void 0)i=[f.length];else if(!Array.isArray(i))throw new TypeError("A tensor's dims must be a number array");a=i,this.cpuData=f,this.dataLocation="cpu"}let s=vt(a);if(this.cpuData&&s!==this.cpuData.length)throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=n,this.dims=a,this.size=s}static async fromImage(e,r){return wt(e,r)}static fromTexture(e,r){return gt(e,r)}static fromGpuBuffer(e,r){return bt(e,r)}static fromPinnedBuffer(e,r,o){return Et(e,r,o)}toDataURL(e){return mt(this,e)}toImageData(e){return ht(this,e)}get data(){if(this.ensureValid(),!this.cpuData)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.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,e&&this.disposer&&(this.disposer(),this.disposer=void 0),r}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return xt(this,e)}}});var I,be=w(()=>{"use strict";ge();I=P});var He,Pt,F,N,je=w(()=>{"use strict";Ge();He=(t,e)=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||console.timeStamp(`${t}::ORT::${e}`)},Pt=(t,e)=>{let r=new Error().stack?.split(/\r\n|\r|\n/g)||[],o=!1;for(let n=0;n<r.length;n++){if(o&&!r[n].includes("TRACE_FUNC")){let a=`FUNC_${t}::${r[n].trim().split(" ")[1]}`;e&&(a+=`::${e}`),He("CPU",a);return}r[n].includes("TRACE_FUNC")&&(o=!0)}},F=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Pt("BEGIN",t)},N=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Pt("END",t)}});var Ee,Bt=w(()=>{"use strict";we();be();je();Ee=class t{constructor(e){this.handler=e}async run(e,r,o){F();let n={},a={};if(typeof e!="object"||e===null||e instanceof I||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof I)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let u of r){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);n[u]=null}if(typeof o=="object"&&o!==null)a=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(r);for(let d of this.outputNames)if(l.indexOf(d)!==-1){let c=r[d];(c===null||c instanceof I)&&(u=!0,s=!1,n[d]=c)}if(u){if(typeof o=="object"&&o!==null)a=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else a=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of this.inputNames)if(typeof e[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(s)for(let u of this.outputNames)n[u]=null;let f=await this.handler.run(e,n,a),i={};for(let u in f)if(Object.hasOwnProperty.call(f,u)){let l=f[u];l instanceof I?i[u]=l:i[u]=new I(l.type,l.data,l.dims)}return N(),i}async release(){return this.handler.dispose()}static async create(e,r,o,n){F();let a,s={};if(typeof e=="string"){if(a=e,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(a=e,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let l=e,d=0,c=e.byteLength;if(typeof r=="object"&&r!==null)s=r;else if(typeof r=="number"){if(d=r,!Number.isSafeInteger(d))throw new RangeError("'byteOffset' must be an integer.");if(d<0||d>=l.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${l.byteLength}).`);if(c=e.byteLength-d,typeof o=="number"){if(c=o,!Number.isSafeInteger(c))throw new RangeError("'byteLength' must be an integer.");if(c<=0||d+c>l.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${l.byteLength-d}].`);if(typeof n=="object"&&n!==null)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(typeof o<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");a=new Uint8Array(l,d,c)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[f,i]=await ye(s),u=await f.createInferenceSessionHandler(a,i);return N(),new t(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Lt,Ct=w(()=>{"use strict";Bt();Lt=Ee});var Ut=w(()=>{"use strict"});var Mt=w(()=>{"use strict"});var Dt=w(()=>{"use strict"});var Rt=w(()=>{"use strict"});var Ir,Se,_t=w(()=>{"use strict";we();be();Ir="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",Se=class t{constructor(e,r,o){this.handler=e,this.hasOptimizerModel=r,this.hasEvalModel=o}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,r){let o=e.evalModel||"",n=e.optimizerModel||"",a=r||{},[s,f]=await ye(a);if(s.createTrainingSessionHandler){let i=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,o,n,f);return new t(i,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Ir)}typeNarrowingForRunStep(e,r,o,n,a){let s={},f={};if(typeof o!="object"||o===null||o instanceof I||Array.isArray(o))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof I)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(let u of n){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(r.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);s[u]=null}if(typeof a=="object"&&a!==null)f=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(n);for(let d of r)if(l.indexOf(d)!==-1){let c=n[d];(c===null||c instanceof I)&&(u=!0,i=!1,s[d]=c)}if(u){if(typeof a=="object"&&a!==null)f=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else f=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of e)if(typeof o[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(i)for(let u of r)s[u]=null;return[s,f]}convertHandlerReturnTypeToMapOfTensors(e){let r={};for(let o in e)if(Object.hasOwnProperty.call(e,o)){let n=e[o];n instanceof I?r[o]=n:r[o]=new I(n.type,n.data,n.dims)}return r}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,r,o){let[n,a]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,r,o),s=await this.handler.runTrainStep(e,n,a);return this.convertHandlerReturnTypeToMapOfTensors(s)}async runOptimizerStep(e){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(e||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(e,r,o){if(this.hasEvalModel){let[n,a]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,r,o),s=await this.handler.runEvalStep(e,n,a);return this.convertHandlerReturnTypeToMapOfTensors(s)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(e=!0){return this.handler.getParametersSize(e)}async loadParametersBuffer(e,r=!0){let o=await this.getParametersSize(r);if(e.length!==4*o)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(e,r)}async getContiguousParameters(e=!0){return this.handler.getContiguousParameters(e)}async release(){return this.handler.dispose()}}});var kt,Ft=w(()=>{"use strict";_t();kt=Se});var Ve={};me(Ve,{InferenceSession:()=>Lt,TRACE:()=>He,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>N,Tensor:()=>I,TrainingSession:()=>kt,env:()=>S,registerBackend:()=>q});var z=w(()=>{"use strict";ft();pt();Ct();be();Ut();Mt();je();Dt();Rt();Ft()});var Te=w(()=>{"use strict"});var Gt={};me(Gt,{default:()=>Pr});var Wt,$t,Pr,zt=w(()=>{"use strict";Ye();H();se();Wt="ort-wasm-proxy-worker",$t=globalThis.self?.name===Wt;$t&&(self.onmessage=t=>{let{type:e,in:r}=t.data;try{switch(e){case"init-wasm":Ae(r.wasm).then(()=>{Oe(r).then(()=>{postMessage({type:e})},o=>{postMessage({type:e,err:o})})},o=>{postMessage({type:e,err:o})});break;case"init-ep":{let{epName:o,env:n}=r;ve(n,o).then(()=>{postMessage({type:e})},a=>{postMessage({type:e,err:a})});break}case"copy-from":{let{buffer:o}=r,n=ae(o);postMessage({type:e,out:n});break}case"create":{let{model:o,options:n}=r;xe(o,n).then(a=>{postMessage({type:e,out:a})},a=>{postMessage({type:e,err:a})});break}case"release":Ie(r),postMessage({type:e});break;case"run":{let{sessionId:o,inputIndices:n,inputs:a,outputIndices:s,options:f}=r;Pe(o,n,a,s,new Array(s.length).fill(null),f).then(i=>{i.some(u=>u[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:i},Le([...a,...i]))},i=>{postMessage({type:e,err:i})});break}case"end-profiling":Be(r),postMessage({type:e});break;default:}}catch(o){postMessage({type:e,err:o})}});Pr=$t?null:t=>new Worker(t??D,{type:"classic",name:Wt})});var D,Br,jt,Lr,Cr,Vt,Ur,Ht,Yt,qt,se=w(()=>{"use strict";Te();D=!1?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,Br=!1||typeof location>"u"?void 0:location.origin,jt=(t,e)=>{try{let r=e??D;return(r?new URL(t,r):new URL(t)).origin===Br}catch{return!1}},Lr=(t,e)=>{let r=e??D;try{return(r?new URL(t,r):new URL(t)).href}catch{return}},Cr=(t,e)=>`${e??"./"}${t}`,Vt=async t=>{let r=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(r)},Ur=async t=>(await import(/*webpackIgnore:true*/t)).default,Ht=(zt(),$e(Gt)).default,Yt=async()=>{if(!D)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(jt(D))return[void 0,Ht()];let t=await Vt(D);return[t,Ht(t)]},qt=async(t,e,r)=>{{let o="ort-wasm-simd-threaded.mjs",n=t??Lr(o,e),a=!!1&&r&&n&&!jt(n,e),s=a?await Vt(n):n??Cr(o,e);return[a?s:void 0,await Ur(s)]}}});var qe,Je,Ce,Jt,Mr,Dr,Ae,v,H=w(()=>{"use strict";se();Je=!1,Ce=!1,Jt=!1,Mr=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{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]))}catch{return!1}},Dr=()=>{try{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]))}catch{return!1}},Ae=async t=>{if(Je)return Promise.resolve();if(Ce)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Jt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Ce=!0;let e=t.initTimeout,r=t.numThreads;if(!Dr())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=Mr();r>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", 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."),t.numThreads=r=1);let n=t.wasmPaths,a=typeof n=="string"?n:void 0,s=n?.mjs,f=s?.href??s,i=n?.wasm,u=i?.href??i,l=t.wasmBinary,[d,c]=await qt(f,a,r>1),p=!1,m=[];if(e>0&&m.push(new Promise(y=>{setTimeout(()=>{p=!0,y()},e)})),m.push(new Promise((y,b)=>{let T={numThreads:r};l?T.wasmBinary=l:(u||a)&&(T.locateFile=(h,g)=>u??(a??g)+h),c(T).then(h=>{Ce=!1,Je=!0,qe=h,y(),d&&URL.revokeObjectURL(d)},h=>{Ce=!1,Jt=!0,b(h)})})),await Promise.race(m),p)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},v=()=>{if(Je&&qe)return qe;throw new Error("WebAssembly is not initialized yet.")}});var x,ie,A,Ue=w(()=>{"use strict";H();x=(t,e)=>{let r=v(),o=r.lengthBytesUTF8(t)+1,n=r._malloc(o);return r.stringToUTF8(t,n,o),e.push(n),n},ie=(t,e,r,o)=>{if(typeof t=="object"&&t!==null){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach(([n,a])=>{let s=e?e+n:n;if(typeof a=="object")ie(a,s+".",r,o);else if(typeof a=="string"||typeof a=="number")o(s,a.toString());else if(typeof a=="boolean")o(s,a?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof a}`)})},A=t=>{let e=v(),r=e.stackSave();try{let o=e.stackAlloc(8);e._OrtGetLastError(o,o+4);let n=e.HEAP32[o/4],a=e.HEAPU32[o/4+1],s=a?e.UTF8ToString(a):"";throw new Error(`${t} ERROR_CODE: ${n}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(r)}}});var Xt,Kt=w(()=>{"use strict";H();Ue();Xt=t=>{let e=v(),r=0,o=[],n=t||{};try{if(t?.logSeverityLevel===void 0)n.logSeverityLevel=2;else if(typeof t.logSeverityLevel!="number"||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)n.logVerbosityLevel=0;else if(typeof t.logVerbosityLevel!="number"||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(n.terminate=!1);let a=0;return t?.tag!==void 0&&(a=x(t.tag,o)),r=e._OrtCreateRunOptions(n.logSeverityLevel,n.logVerbosityLevel,!!n.terminate,a),r===0&&A("Can't create run options."),t?.extra!==void 0&&ie(t.extra,"",new WeakSet,(s,f)=>{let i=x(s,o),u=x(f,o);e._OrtAddRunConfigEntry(r,i,u)!==0&&A(`Can't set a run config entry: ${s} - ${f}.`)}),[r,o]}catch(a){throw r!==0&&e._OrtReleaseRunOptions(r),o.forEach(s=>e._free(s)),a}}});var Rr,_r,kr,Fr,Qt,Zt=w(()=>{"use strict";H();Ue();Rr=t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}},_r=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},kr=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(t.enableMemPattern=!1)},Fr=(t,e,r)=>{for(let o of e){let n=typeof o=="string"?o:o.name;switch(n){case"webnn":if(n="WEBNN",typeof o!="string"){let f=o?.deviceType;if(f){let i=x("deviceType",r),u=x(f,r);v()._OrtAddSessionConfigEntry(t,i,u)!==0&&A(`Can't set a session config entry: 'deviceType' - ${f}.`)}}break;case"webgpu":if(n="JS",typeof o!="string"){let s=o;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let f=x("preferredLayout",r),i=x(s.preferredLayout,r);v()._OrtAddSessionConfigEntry(t,f,i)!==0&&A(`Can't set a session config entry: 'preferredLayout' - ${s.preferredLayout}.`)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${n}`)}let a=x(n,r);v()._OrtAppendExecutionProvider(t,a)!==0&&A(`Can't append execution provider: ${n}.`)}},Qt=t=>{let e=v(),r=0,o=[],n=t||{};kr(n);try{let a=Rr(n.graphOptimizationLevel??"all"),s=_r(n.executionMode??"sequential"),f=typeof n.logId=="string"?x(n.logId,o):0,i=n.logSeverityLevel??2;if(!Number.isInteger(i)||i<0||i>4)throw new Error(`log serverity level is not valid: ${i}`);let u=n.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let l=typeof n.optimizedModelFilePath=="string"?x(n.optimizedModelFilePath,o):0;if(r=e._OrtCreateSessionOptions(a,!!n.enableCpuMemArena,!!n.enableMemPattern,s,!!n.enableProfiling,0,f,i,u,l),r===0&&A("Can't create session options."),n.executionProviders&&Fr(r,n.executionProviders,o),n.enableGraphCapture!==void 0){if(typeof n.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${n.enableGraphCapture}`);let d=x("enableGraphCapture",o),c=x(n.enableGraphCapture.toString(),o);e._OrtAddSessionConfigEntry(r,d,c)!==0&&A(`Can't set a session config entry: 'enableGraphCapture' - ${n.enableGraphCapture}.`)}if(n.freeDimensionOverrides)for(let[d,c]of Object.entries(n.freeDimensionOverrides)){if(typeof d!="string")throw new Error(`free dimension override name must be a string: ${d}`);if(typeof c!="number"||!Number.isInteger(c)||c<0)throw new Error(`free dimension override value must be a non-negative integer: ${c}`);let p=x(d,o);e._OrtAddFreeDimensionOverride(r,p,c)!==0&&A(`Can't set a free dimension override: ${d} - ${c}.`)}return n.extra!==void 0&&ie(n.extra,"",new WeakSet,(d,c)=>{let p=x(d,o),m=x(c,o);e._OrtAddSessionConfigEntry(r,p,m)!==0&&A(`Can't set a session config entry: ${d} - ${c}.`)}),[r,o]}catch(a){throw r!==0&&e._OrtReleaseSessionOptions(r),o.forEach(s=>e._free(s)),a}}});var Xe,er,Ke,tr,rr,Me,nr,Qe=w(()=>{"use strict";Xe=t=>{switch(t){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${t}`)}},er=t=>{switch(t){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${t}`)}},Ke=t=>[void 0,4,1,1,2,2,4,8,void 0,1,2,8,4,8,void 0,void 0,void 0][t],tr=t=>{switch(t){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${t}`)}},rr=t=>{switch(t){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${t}`)}},Me=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool",nr=t=>{switch(t){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${t}`)}}});var ue,Ze=w(()=>{"use strict";Te();ue=async t=>{if(typeof t=="string")if(!1)try{let{readFile:e}=We("node:fs/promises");return new Uint8Array(await e(t))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:r}=We("node:fs"),o=r(t),n=[];for await(let a of o)n.push(a);return new Uint8Array(Buffer.concat(n))}throw e}else{let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let r=e.headers.get("Content-Length"),o=r?parseInt(r,10):0;if(o<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let n=e.body.getReader(),a;try{a=new ArrayBuffer(o)}catch(f){if(f instanceof RangeError){let i=Math.ceil(o/65536);a=new WebAssembly.Memory({initial:i,maximum:i}).buffer}else throw f}let s=0;for(;;){let{done:f,value:i}=await n.read();if(f)break;let u=i.byteLength;new Uint8Array(a,s,u).set(i),s+=u}return new Uint8Array(a,0,o)}}else return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}});var Nr,Oe,ve,J,Wr,ae,xe,Ie,or,Pe,Be,Le,Ye=w(()=>{"use strict";Kt();Zt();Qe();H();Ue();Ze();Nr=(t,e)=>{v()._OrtInit(t,e)!==0&&A("Can't initialize onnxruntime.")},Oe=async t=>{Nr(t.wasm.numThreads,rr(t.logLevel))},ve=async(t,e)=>{},J=new Map,Wr=t=>{let e=v(),r=e.stackSave();try{let o=e.stackAlloc(8);return e._OrtGetInputOutputCount(t,o,o+4)!==0&&A("Can't get session input/output count."),[e.HEAP32[o/4],e.HEAP32[o/4+1]]}finally{e.stackRestore(r)}},ae=t=>{let e=v(),r=e._malloc(t.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,r),[r,t.byteLength]},xe=async(t,e)=>{let r,o,n=v();Array.isArray(t)?[r,o]=t:t.buffer===n.HEAPU8.buffer?[r,o]=[t.byteOffset,t.byteLength]:[r,o]=ae(t);let a=0,s=0,f=0,i=[],u=[],l=[];try{if([s,i]=Qt(e),e?.externalData&&n.mountExternalData){let h=[];for(let g of e.externalData){let O=typeof g=="string"?g:g.path;h.push(ue(typeof g=="string"?g:g.data).then(B=>{n.mountExternalData(O,B)}))}await Promise.all(h)}for(let h of e?.executionProviders??[])if((typeof h=="string"?h:h.name)==="webnn"){if(n.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof h!="string"){let O=h,B=O?.context,Q=O?.gpuDevice,ce=O?.deviceType,Z=O?.numThreads,de=O?.powerPreference;B?n.currentContext=B:Q?n.currentContext=await navigator.ml.createContext(Q):n.currentContext=await navigator.ml.createContext({deviceType:ce,numThreads:Z,powerPreference:de})}else n.currentContext=await navigator.ml.createContext();break}a=await n._OrtCreateSession(r,o,s),a===0&&A("Can't create a session."),n.currentContext&&(n.currentContext=void 0);let[d,c]=Wr(a),p=!!e?.enableGraphCapture,m=[],y=[],b=[];for(let h=0;h<d;h++){let g=n._OrtGetInputName(a,h);g===0&&A("Can't get an input name."),u.push(g),m.push(n.UTF8ToString(g))}for(let h=0;h<c;h++){let g=n._OrtGetOutputName(a,h);g===0&&A("Can't get an output name."),l.push(g);let O=n.UTF8ToString(g);y.push(O)}let T=null;return J.set(a,[a,u,l,T,p,!1]),[a,m,y]}catch(d){throw u.forEach(c=>n._OrtFree(c)),l.forEach(c=>n._OrtFree(c)),f!==0&&n._OrtReleaseBinding(f),a!==0&&n._OrtReleaseSession(a),d}finally{n._free(r),s!==0&&n._OrtReleaseSessionOptions(s),i.forEach(d=>n._free(d)),n.unmountExternalData?.()}},Ie=t=>{let e=v(),r=J.get(t);if(!r)throw new Error(`cannot release session. invalid session id: ${t}`);let[o,n,a,s,f]=r;s&&(f&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(t),n.forEach(i=>e._OrtFree(i)),a.forEach(i=>e._OrtFree(i)),e._OrtReleaseSession(o),J.delete(t)},or=(t,e,r,o,n,a=!1)=>{if(!t){e.push(0);return}let s=v(),f=t[0],i=t[1],u=t[3],l,d;if(f==="string"&&u==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");if(a&&u!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${n} when enableGraphCapture is true.`);if(u==="gpu-buffer"){let m=t[2].gpuBuffer,y=Ke(Xe(f));d=i.reduce((T,h)=>T*h,1)*y;let b=s.jsepRegisterBuffer;if(!b)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');l=b(o,n,m,d)}else{let m=t[2];if(Array.isArray(m)){d=4*m.length,l=s._malloc(d),r.push(l);let y=l/4;for(let b=0;b<m.length;b++){if(typeof m[b]!="string")throw new TypeError(`tensor data at index ${b} is not a string`);s.HEAPU32[y++]=x(m[b],r)}}else d=m.byteLength,l=s._malloc(d),r.push(l),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,d),l)}let c=s.stackSave(),p=s.stackAlloc(4*i.length);try{let m=p/4;i.forEach(b=>s.HEAP32[m++]=b);let y=s._OrtCreateTensor(Xe(f),l,d,p,i.length,nr(u));y===0&&A(`Can't create tensor for input/output. session=${o}, index=${n}.`),e.push(y)}finally{s.stackRestore(c)}},Pe=async(t,e,r,o,n,a)=>{let s=v(),f=J.get(t);if(!f)throw new Error(`cannot run inference. invalid session id: ${t}`);let i=f[0],u=f[1],l=f[2],d=f[3],c=f[4],p=f[5],m=e.length,y=o.length,b=0,T=[],h=[],g=[],O=[],B=s.stackSave(),Q=s.stackAlloc(m*4),ce=s.stackAlloc(m*4),Z=s.stackAlloc(y*4),de=s.stackAlloc(y*4);try{[b,T]=Xt(a);for(let E=0;E<m;E++)or(r[E],h,O,t,e[E],c);for(let E=0;E<y;E++)or(n[E],g,O,t,m+o[E],c);let _=Q/4,wr=ce/4,gr=Z/4,br=de/4;for(let E=0;E<m;E++)s.HEAPU32[_++]=h[E],s.HEAPU32[wr++]=u[e[E]];for(let E=0;E<y;E++)s.HEAPU32[gr++]=g[E],s.HEAPU32[br++]=l[o[E]];s.jsepOnRunStart?.(i);let nt;nt=await s._OrtRun(i,ce,Q,m,de,y,Z,b),nt!==0&&A("failed to call OrtRun().");let ee=[];for(let E=0;E<y;E++){let te=s.HEAPU32[Z/4+E];if(te===g[E]){ee.push(n[E]);continue}let ot=s.stackSave(),W=s.stackAlloc(4*4),le=!1,M,k=0;try{s._OrtGetTensorData(te,W,W+4,W+8,W+12)!==0&&A(`Can't access output tensor data on index ${E}.`);let pe=W/4,st=s.HEAPU32[pe++];k=s.HEAPU32[pe++];let at=s.HEAPU32[pe++],Er=s.HEAPU32[pe++],re=[];for(let L=0;L<Er;L++)re.push(s.HEAPU32[at/4+L]);s._OrtFree(at);let ne=re.reduce((L,C)=>L*C,1);M=er(st);let it=d?.outputPreferredLocations[o[E]];if(M==="string"){if(it==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");let L=[],C=k/4;for(let Y=0;Y<ne;Y++){let ut=s.HEAPU32[C++],Sr=Y===ne-1?void 0:s.HEAPU32[C]-ut;L.push(s.UTF8ToString(ut,Sr))}ee.push([M,re,L,"cpu"])}else if(it==="gpu-buffer"&&ne>0){let L=s.jsepGetBuffer;if(!L)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let C=L(k),Y=Ke(st);if(Y===void 0||!Me(M))throw new Error(`Unsupported data type: ${M}`);le=!0,ee.push([M,re,{gpuBuffer:C,download:s.jsepCreateDownloader(C,ne*Y,M),dispose:()=>{s._OrtReleaseTensor(te)}},"gpu-buffer"])}else{let L=tr(M),C=new L(ne);new Uint8Array(C.buffer,C.byteOffset,C.byteLength).set(s.HEAPU8.subarray(k,k+C.byteLength)),ee.push([M,re,C,"cpu"])}}finally{s.stackRestore(ot),M==="string"&&k&&s._free(k),le||s._OrtReleaseTensor(te)}}return d&&!c&&(s._OrtClearBoundOutputs(d.handle),J.set(t,[i,u,l,d,c,!1])),ee}finally{s.stackRestore(B),h.forEach(_=>s._OrtReleaseTensor(_)),g.forEach(_=>s._OrtReleaseTensor(_)),O.forEach(_=>s._free(_)),b!==0&&s._OrtReleaseRunOptions(b),T.forEach(_=>s._free(_))}},Be=t=>{let e=v(),r=J.get(t);if(!r)throw new Error("invalid session id");let o=r[0],n=e._OrtEndProfiling(o);n===0&&A("Can't get an profile file name."),e._OrtFree(n)},Le=t=>{let e=[];for(let r of t){let o=r[2];!Array.isArray(o)&&"buffer"in o&&e.push(o.buffer)}return e}});var V,R,fe,Re,_e,De,et,tt,X,K,Gr,sr,ar,ir,ur,fr,cr,dr,rt=w(()=>{"use strict";z();Ye();H();se();V=()=>!!S.wasm.proxy&&typeof document<"u",fe=!1,Re=!1,_e=!1,tt=new Map,X=(t,e)=>{let r=tt.get(t);r?r.push(e):tt.set(t,[e])},K=()=>{if(fe||!Re||_e||!R)throw new Error("worker not ready")},Gr=t=>{switch(t.data.type){case"init-wasm":fe=!1,t.data.err?(_e=!0,et[1](t.data.err)):(Re=!0,et[0]()),De&&(URL.revokeObjectURL(De),De=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=tt.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},sr=async()=>{if(!Re){if(fe)throw new Error("multiple calls to 'initWasm()' detected.");if(_e)throw new Error("previous call to 'initWasm()' failed.");if(fe=!0,V())return new Promise((t,e)=>{R?.terminate(),Yt().then(([r,o])=>{try{R=o,R.onerror=a=>e(a),R.onmessage=Gr,et=[t,e];let n={type:"init-wasm",in:S};R.postMessage(n),De=r}catch(n){e(n)}},e)});try{await Ae(S.wasm),await Oe(S),Re=!0}catch(t){throw _e=!0,t}finally{fe=!1}}},ar=async t=>{if(V())return K(),new Promise((e,r)=>{X("init-ep",[e,r]);let o={type:"init-ep",in:{epName:t,env:S}};R.postMessage(o)});await ve(S,t)},ir=async t=>V()?(K(),new Promise((e,r)=>{X("copy-from",[e,r]);let o={type:"copy-from",in:{buffer:t}};R.postMessage(o,[t.buffer])})):ae(t),ur=async(t,e)=>{if(V()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return K(),new Promise((r,o)=>{X("create",[r,o]);let n={type:"create",in:{model:t,options:{...e}}},a=[];t instanceof Uint8Array&&a.push(t.buffer),R.postMessage(n,a)})}else return xe(t,e)},fr=async t=>{if(V())return K(),new Promise((e,r)=>{X("release",[e,r]);let o={type:"release",in:t};R.postMessage(o)});Ie(t)},cr=async(t,e,r,o,n,a)=>{if(V()){if(r.some(s=>s[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(n.some(s=>s))throw new Error("pre-allocated output tensor is not supported for proxy.");return K(),new Promise((s,f)=>{X("run",[s,f]);let i=r,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:i,outputIndices:o,options:a}};R.postMessage(u,Le(i))})}else return Pe(t,e,r,o,n,a)},dr=async t=>{if(V())return K(),new Promise((e,r)=>{X("end-profiling",[e,r]);let o={type:"end-profiling",in:t};R.postMessage(o)});Be(t)}});var lr,zr,ke,pr=w(()=>{"use strict";z();rt();Qe();Te();Ze();lr=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},zr=t=>{switch(t[3]){case"cpu":return new I(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!Me(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:r,download:o,dispose:n}=t[2];return I.fromGpuBuffer(r,{dataType:e,dims:t[1],download:o,dispose:n})}default:throw new Error(`invalid data location: ${t[3]}`)}},ke=class{async fetchModelAndCopyToWasmMemory(e){return ir(await ue(e))}async loadModel(e,r){F();let o;typeof e=="string"?!1?o=await ue(e):o=await this.fetchModelAndCopyToWasmMemory(e):o=e,[this.sessionId,this.inputNames,this.outputNames]=await ur(o,r),N()}async dispose(){return fr(this.sessionId)}async run(e,r,o){F();let n=[],a=[];Object.entries(e).forEach(c=>{let p=c[0],m=c[1],y=this.inputNames.indexOf(p);if(y===-1)throw new Error(`invalid input '${p}'`);n.push(m),a.push(y)});let s=[],f=[];Object.entries(r).forEach(c=>{let p=c[0],m=c[1],y=this.outputNames.indexOf(p);if(y===-1)throw new Error(`invalid output '${p}'`);s.push(m),f.push(y)});let i=n.map((c,p)=>lr(c,()=>`input "${this.inputNames[a[p]]}"`)),u=s.map((c,p)=>c?lr(c,()=>`output "${this.outputNames[f[p]]}"`):null),l=await cr(this.sessionId,a,i,f,u,o),d={};for(let c=0;c<l.length;c++)d[this.outputNames[f[c]]]=s[c]??zr(l[c]);return N(),d}startProfiling(){}endProfiling(){dr(this.sessionId)}}});var Hr,Fe,mr=w(()=>{"use strict";z();rt();pr();se();Hr=()=>{if((typeof S.wasm.initTimeout!="number"||S.wasm.initTimeout<0)&&(S.wasm.initTimeout=0),S.wasm.simd===!1&&console.warn('Deprecated property "env.wasm.simd" is set to false. non-SIMD build is no longer provided, and this setting will be ignored.'),typeof S.wasm.proxy!="boolean"&&(S.wasm.proxy=!1),typeof S.wasm.trace!="boolean"&&(S.wasm.trace=!1),typeof S.wasm.numThreads!="number"||!Number.isInteger(S.wasm.numThreads)||S.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)S.wasm.numThreads=1;else{let t=typeof navigator>"u"?We("node:os").cpus().length:navigator.hardwareConcurrency;S.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}S.wasm.wasmPaths===void 0&&D&&D.indexOf("blob:")!==0&&(S.wasm.wasmPaths=D.substring(0,D.lastIndexOf("/")+1))},Fe=class{async init(e){Hr(),await sr(),await ar(e)}async createInferenceSessionHandler(e,r){let o=new ke;return await o.loadModel(e,r),Promise.resolve(o)}}});var hr={};me(hr,{wasmBackend:()=>jr});var jr,yr=w(()=>{"use strict";mr();jr=new Fe});var Yr={};me(Yr,{InferenceSession:()=>Lt,TRACE:()=>He,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>N,Tensor:()=>I,TrainingSession:()=>kt,default:()=>Vr,env:()=>S,registerBackend:()=>q});z();z();z();var Nt="1.19.2";var Vr=Ve;{let t=(yr(),$e(hr)).wasmBackend;q("cpu",t,10),q("wasm",t,10)}Object.defineProperty(S.versions,"web",{value:Nt,enumerable:!0});return $e(Yr);})();
|
| 7 |
typeof exports=="object"&&typeof module=="object"&&(module.exports=ort);
|
| 8 |
//# sourceMappingURL=ort.wasm.min.js.map
|
|
|
|
| 1 |
/*!
|
| 2 |
+
* ONNX Runtime Web v1.22.0
|
| 3 |
* Copyright (c) Microsoft Corporation. All rights reserved.
|
| 4 |
* Licensed under the MIT License.
|
| 5 |
*/
|
| 6 |
+
"use strict";var ort=(()=>{var je=Object.defineProperty;var An=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var In=Object.prototype.hasOwnProperty;var Ve=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var E=(e,t)=>()=>(e&&(t=e(e=0)),t);var be=(e,t)=>{for(var n in t)je(e,n,{get:t[n],enumerable:!0})},Pn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of On(t))!In.call(e,r)&&r!==n&&je(e,r,{get:()=>t[r],enumerable:!(o=An(t,r))||o.enumerable});return e};var Ye=e=>Pn(je({},"__esModule",{value:!0}),e);var ge,J,re,Ln,mt,qe=E(()=>{"use strict";ge=new Map,J=[],re=(e,t,n)=>{if(t&&typeof t.init=="function"&&typeof t.createInferenceSessionHandler=="function"){let o=ge.get(e);if(o===void 0)ge.set(e,{backend:t,priority:n});else{if(o.priority>n)return;if(o.priority===n&&o.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${n}`)}if(n>=0){let r=J.indexOf(e);r!==-1&&J.splice(r,1);for(let i=0;i<J.length;i++)if(ge.get(J[i]).priority<=n){J.splice(i,0,e);return}J.push(e)}return}throw new TypeError("not a valid backend")},Ln=async e=>{let t=ge.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{let n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(o){return n||(t.error=`${o}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},mt=async e=>{let t=e.executionProviders||[],n=t.map(u=>typeof u=="string"?u:u.name),o=n.length===0?J:n,r,i=[],a=new Set;for(let u of o){let f=await Ln(u);typeof f=="string"?i.push({name:u,err:f}):(r||(r=f),r===f&&a.add(u))}if(!r)throw new Error(`no available backend found. ERR: ${i.map(u=>`[${u.name}] ${u.err}`).join(", ")}`);for(let{name:u,err:f}of i)n.includes(u)&&console.warn(`removing requested execution provider "${u}" from session options because it is not available: ${f}`);let s=t.filter(u=>a.has(typeof u=="string"?u:u.name));return[r,new Proxy(e,{get:(u,f)=>f==="executionProviders"?s:Reflect.get(u,f)})]}});var wt=E(()=>{"use strict";qe()});var ht,yt=E(()=>{"use strict";ht="1.22.0"});var bt,C,Je=E(()=>{"use strict";yt();bt="warning",C={wasm:{},webgl:{},webgpu:{},versions:{common:ht},set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);bt=e}},get logLevel(){return bt}};Object.defineProperty(C,"logLevel",{enumerable:!0})});var O,gt=E(()=>{"use strict";Je();O=C});var Et,Tt,St=E(()=>{"use strict";Et=(e,t)=>{let n=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=e.dims[3],n.height=e.dims[2];let o=n.getContext("2d");if(o!=null){let r,i;t?.tensorLayout!==void 0&&t.tensorLayout==="NHWC"?(r=e.dims[2],i=e.dims[3]):(r=e.dims[3],i=e.dims[2]);let a=t?.format!==void 0?t.format:"RGB",s=t?.norm,u,f;s===void 0||s.mean===void 0?u=[255,255,255,255]:typeof s.mean=="number"?u=[s.mean,s.mean,s.mean,s.mean]:(u=[s.mean[0],s.mean[1],s.mean[2],0],s.mean[3]!==void 0&&(u[3]=s.mean[3])),s===void 0||s.bias===void 0?f=[0,0,0,0]:typeof s.bias=="number"?f=[s.bias,s.bias,s.bias,s.bias]:(f=[s.bias[0],s.bias[1],s.bias[2],0],s.bias[3]!==void 0&&(f[3]=s.bias[3]));let c=i*r,l=0,d=c,p=c*2,w=-1;a==="RGBA"?(l=0,d=c,p=c*2,w=c*3):a==="RGB"?(l=0,d=c,p=c*2):a==="RBG"&&(l=0,p=c,d=c*2);for(let b=0;b<i;b++)for(let I=0;I<r;I++){let m=(e.data[l++]-f[0])*u[0],h=(e.data[d++]-f[1])*u[1],P=(e.data[p++]-f[2])*u[2],g=w===-1?255:(e.data[w++]-f[3])*u[3];o.fillStyle="rgba("+m+","+h+","+P+","+g+")",o.fillRect(I,b,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Tt=(e,t)=>{let n=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(n!=null){let r,i,a;t?.tensorLayout!==void 0&&t.tensorLayout==="NHWC"?(r=e.dims[2],i=e.dims[1],a=e.dims[3]):(r=e.dims[3],i=e.dims[2],a=e.dims[1]);let s=t!==void 0&&t.format!==void 0?t.format:"RGB",u=t?.norm,f,c;u===void 0||u.mean===void 0?f=[255,255,255,255]:typeof u.mean=="number"?f=[u.mean,u.mean,u.mean,u.mean]:(f=[u.mean[0],u.mean[1],u.mean[2],255],u.mean[3]!==void 0&&(f[3]=u.mean[3])),u===void 0||u.bias===void 0?c=[0,0,0,0]:typeof u.bias=="number"?c=[u.bias,u.bias,u.bias,u.bias]:(c=[u.bias[0],u.bias[1],u.bias[2],0],u.bias[3]!==void 0&&(c[3]=u.bias[3]));let l=i*r;if(t!==void 0&&(t.format!==void 0&&a===4&&t.format!=="RGBA"||a===3&&t.format!=="RGB"&&t.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let d=4,p=0,w=1,b=2,I=3,m=0,h=l,P=l*2,g=-1;s==="RGBA"?(m=0,h=l,P=l*2,g=l*3):s==="RGB"?(m=0,h=l,P=l*2):s==="RBG"&&(m=0,P=l,h=l*2),o=n.createImageData(r,i);for(let S=0;S<i*r;p+=d,w+=d,b+=d,I+=d,S++)o.data[p]=(e.data[m++]-c[0])*f[0],o.data[w]=(e.data[h++]-c[1])*f[1],o.data[b]=(e.data[P++]-c[2])*f[2],o.data[I]=g===-1?255:(e.data[g++]-c[3])*f[3]}else throw new Error("Can not access image data");return o}});var Ze,At,Ot,It,Pt,Lt,xt=E(()=>{"use strict";Ee();Ze=(e,t)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(t.height===void 0||t.width===void 0)throw new Error("Image height and width must be defined");if(t.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:n,width:o}=t,r=t.norm??{mean:255,bias:0},i,a;typeof r.mean=="number"?i=[r.mean,r.mean,r.mean,r.mean]:i=[r.mean[0],r.mean[1],r.mean[2],r.mean[3]??255],typeof r.bias=="number"?a=[r.bias,r.bias,r.bias,r.bias]:a=[r.bias[0],r.bias[1],r.bias[2],r.bias[3]??0];let s=t.format!==void 0?t.format:"RGBA",u=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:"RGB",f=n*o,c=u==="RGBA"?new Float32Array(f*4):new Float32Array(f*3),l=4,d=0,p=1,w=2,b=3,I=0,m=f,h=f*2,P=-1;s==="RGB"&&(l=3,d=0,p=1,w=2,b=-1),u==="RGBA"?P=f*3:u==="RBG"?(I=0,h=f,m=f*2):u==="BGR"&&(h=0,m=f,I=f*2);for(let S=0;S<f;S++,d+=l,w+=l,p+=l,b+=l)c[I++]=(e[d]+a[0])/i[0],c[m++]=(e[p]+a[1])/i[1],c[h++]=(e[w]+a[2])/i[2],P!==-1&&b!==-1&&(c[P++]=(e[b]+a[3])/i[3]);return u==="RGBA"?new U("float32",c,[1,4,n,o]):new U("float32",c,[1,3,n,o])},At=async(e,t)=>{let n=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,o=typeof ImageData<"u"&&e instanceof ImageData,r=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,i=typeof e=="string",a,s=t??{},u=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},f=c=>typeof HTMLCanvasElement<"u"&&c instanceof HTMLCanvasElement||c instanceof OffscreenCanvas?c.getContext("2d"):null;if(n){let c=u();c.width=e.width,c.height=e.height;let l=f(c);if(l!=null){let d=e.height,p=e.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(d=t.resizedHeight,p=t.resizedWidth),t!==void 0){if(s=t,t.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");s.tensorFormat="RGBA",s.height=d,s.width=p}else s.tensorFormat="RGBA",s.height=d,s.width=p;l.drawImage(e,0,0),a=l.getImageData(0,0,p,d).data}else throw new Error("Can not access image data")}else if(o){let c,l;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(c=t.resizedHeight,l=t.resizedWidth):(c=e.height,l=e.width),t!==void 0&&(s=t),s.format="RGBA",s.height=c,s.width=l,t!==void 0){let d=u();d.width=l,d.height=c;let p=f(d);if(p!=null)p.putImageData(e,0,0),a=p.getImageData(0,0,l,c).data;else throw new Error("Can not access image data")}else a=e.data}else if(r){if(t===void 0)throw new Error("Please provide image config with format for Imagebitmap");let c=u();c.width=e.width,c.height=e.height;let l=f(c);if(l!=null){let d=e.height,p=e.width;return l.drawImage(e,0,0,p,d),a=l.getImageData(0,0,p,d).data,s.height=d,s.width=p,Ze(a,s)}else throw new Error("Can not access image data")}else{if(i)return new Promise((c,l)=>{let d=u(),p=f(d);if(!e||!p)return l();let w=new Image;w.crossOrigin="Anonymous",w.src=e,w.onload=()=>{d.width=w.width,d.height=w.height,p.drawImage(w,0,0,d.width,d.height);let b=p.getImageData(0,0,d.width,d.height);s.height=d.height,s.width=d.width,c(Ze(b.data,s))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(a!==void 0)return Ze(a,s);throw new Error("Input data provided is not supported - aborted tensor creation")},Ot=(e,t)=>{let{width:n,height:o,download:r,dispose:i}=t,a=[1,o,n,4];return new U({location:"texture",type:"float32",texture:e,dims:a,download:r,dispose:i})},It=(e,t)=>{let{dataType:n,dims:o,download:r,dispose:i}=t;return new U({location:"gpu-buffer",type:n??"float32",gpuBuffer:e,dims:o,download:r,dispose:i})},Pt=(e,t)=>{let{dataType:n,dims:o,download:r,dispose:i}=t;return new U({location:"ml-tensor",type:n??"float32",mlTensor:e,dims:o,download:r,dispose:i})},Lt=(e,t,n)=>new U({location:"cpu-pinned",type:e,data:t,dims:n??[t.length]})});var Z,de,vt,Bt,Ut=E(()=>{"use strict";Z=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),de=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),vt=!1,Bt=()=>{if(!vt){vt=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,n=globalThis.Float16Array,o=typeof n<"u"&&n.from;e&&(Z.set("int64",BigInt64Array),de.set(BigInt64Array,"int64")),t&&(Z.set("uint64",BigUint64Array),de.set(BigUint64Array,"uint64")),o?(Z.set("float16",n),de.set(n,"float16")):Z.set("float16",Uint16Array)}}});var _t,Mt,Dt=E(()=>{"use strict";Ee();_t=e=>{let t=1;for(let n=0;n<e.length;n++){let o=e[n];if(typeof o!="number"||!Number.isSafeInteger(o))throw new TypeError(`dims[${n}] must be an integer, got: ${o}`);if(o<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${o}`);t*=o}return t},Mt=(e,t)=>{switch(e.location){case"cpu":return new U(e.type,e.data,t);case"cpu-pinned":return new U({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new U({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new U({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new U({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}});var U,Ee=E(()=>{"use strict";St();xt();Ut();Dt();U=class{constructor(t,n,o){Bt();let r,i;if(typeof t=="object"&&"location"in t)switch(this.dataLocation=t.location,r=t.type,i=t.dims,t.location){case"cpu-pinned":{let s=Z.get(r);if(!s)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(t.data instanceof s))throw new TypeError(`buffer should be of type ${s.name}`);this.cpuData=t.data;break}case"texture":{if(r!=="float32")throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break}case"gpu-buffer":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint8"&&r!=="bool"&&r!=="uint4"&&r!=="int4")throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break}case"ml-tensor":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint64"&&r!=="int8"&&r!=="uint8"&&r!=="bool"&&r!=="uint4"&&r!=="int4")throw new TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=t.mlTensor,this.downloader=t.download,this.disposer=t.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let s,u;if(typeof t=="string")if(r=t,u=o,t==="string"){if(!Array.isArray(n))throw new TypeError("A string tensor's data must be a string array.");s=n}else{let f=Z.get(t);if(f===void 0)throw new TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(n)){if(t==="float16"&&f===Uint16Array||t==="uint4"||t==="int4")throw new TypeError(`Creating a ${t} tensor from number array is not supported. Please use ${f.name} as data.`);t==="uint64"||t==="int64"?s=f.from(n,BigInt):s=f.from(n)}else if(n instanceof f)s=n;else if(n instanceof Uint8ClampedArray)if(t==="uint8")s=Uint8Array.from(n);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(t==="float16"&&n instanceof Uint16Array&&f!==Uint16Array)s=new globalThis.Float16Array(n.buffer,n.byteOffset,n.length);else throw new TypeError(`A ${r} tensor's data must be type of ${f}`)}else if(u=n,Array.isArray(t)){if(t.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let f=typeof t[0];if(f==="string")r="string",s=t;else if(f==="boolean")r="bool",s=Uint8Array.from(t);else throw new TypeError(`Invalid element type of data array: ${f}.`)}else if(t instanceof Uint8ClampedArray)r="uint8",s=Uint8Array.from(t);else{let f=de.get(t.constructor);if(f===void 0)throw new TypeError(`Unsupported type for tensor data: ${t.constructor}.`);r=f,s=t}if(u===void 0)u=[s.length];else if(!Array.isArray(u))throw new TypeError("A tensor's dims must be a number array");i=u,this.cpuData=s,this.dataLocation="cpu"}let a=_t(i);if(this.cpuData&&a!==this.cpuData.length&&!((r==="uint4"||r==="int4")&&Math.ceil(a/2)===this.cpuData.length))throw new Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=i,this.size=a}static async fromImage(t,n){return At(t,n)}static fromTexture(t,n){return Ot(t,n)}static fromGpuBuffer(t,n){return It(t,n)}static fromMLTensor(t,n){return Pt(t,n)}static fromPinnedBuffer(t,n,o){return Lt(t,n,o)}toDataURL(t){return Et(this,t)}toImageData(t){return Tt(this,t)}get data(){if(this.ensureValid(),!this.cpuData)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.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(t){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let n=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=n,t&&this.disposer&&(this.disposer(),this.disposer=void 0),n}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(t){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return Mt(this,t)}}});var N,Xe=E(()=>{"use strict";Ee();N=U});var Ke,Ct,Y,q,Qe=E(()=>{"use strict";Je();Ke=(e,t)=>{(typeof C.trace>"u"?!C.wasm.trace:!C.trace)||console.timeStamp(`${e}::ORT::${t}`)},Ct=(e,t)=>{let n=new Error().stack?.split(/\r\n|\r|\n/g)||[],o=!1;for(let r=0;r<n.length;r++){if(o&&!n[r].includes("TRACE_FUNC")){let i=`FUNC_${e}::${n[r].trim().split(" ")[1]}`;t&&(i+=`::${t}`),Ke("CPU",i);return}n[r].includes("TRACE_FUNC")&&(o=!0)}},Y=e=>{(typeof C.trace>"u"?!C.wasm.trace:!C.trace)||Ct("BEGIN",e)},q=e=>{(typeof C.trace>"u"?!C.wasm.trace:!C.trace)||Ct("END",e)}});var Te,Rt=E(()=>{"use strict";qe();Xe();Qe();Te=class e{constructor(t){this.handler=t}async run(t,n,o){Y();let r={},i={};if(typeof t!="object"||t===null||t instanceof N||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof N)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let f of n){if(typeof f!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(f)===-1)throw new RangeError(`'fetches' contains invalid output name: ${f}.`);r[f]=null}if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let f=!1,c=Object.getOwnPropertyNames(n);for(let l of this.outputNames)if(c.indexOf(l)!==-1){let d=n[l];(d===null||d instanceof N)&&(f=!0,a=!1,r[l]=d)}if(f){if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else i=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let f of this.inputNames)if(typeof t[f]>"u")throw new Error(`input '${f}' is missing in 'feeds'.`);if(a)for(let f of this.outputNames)r[f]=null;let s=await this.handler.run(t,r,i),u={};for(let f in s)if(Object.hasOwnProperty.call(s,f)){let c=s[f];c instanceof N?u[f]=c:u[f]=new N(c.type,c.data,c.dims)}return q(),u}async release(){return this.handler.dispose()}static async create(t,n,o,r){Y();let i,a={};if(typeof t=="string"){if(i=t,typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(i=t,typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer){let c=t,l=0,d=t.byteLength;if(typeof n=="object"&&n!==null)a=n;else if(typeof n=="number"){if(l=n,!Number.isSafeInteger(l))throw new RangeError("'byteOffset' must be an integer.");if(l<0||l>=c.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${c.byteLength}).`);if(d=t.byteLength-l,typeof o=="number"){if(d=o,!Number.isSafeInteger(d))throw new RangeError("'byteLength' must be an integer.");if(d<=0||l+d>c.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${c.byteLength-l}].`);if(typeof r=="object"&&r!==null)a=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(typeof o<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof n<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(c,l,d)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[s,u]=await mt(a),f=await s.createInferenceSessionHandler(i,u);return q(),new e(f)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}});var Ft,kt=E(()=>{"use strict";Rt();Ft=Te});var Nt=E(()=>{"use strict"});var Wt=E(()=>{"use strict"});var Gt=E(()=>{"use strict"});var $t=E(()=>{"use strict"});var et={};be(et,{InferenceSession:()=>Ft,TRACE:()=>Ke,TRACE_FUNC_BEGIN:()=>Y,TRACE_FUNC_END:()=>q,Tensor:()=>N,env:()=>O,registerBackend:()=>re});var X=E(()=>{"use strict";wt();gt();kt();Xe();Nt();Wt();Qe();Gt();$t()});var Se=E(()=>{"use strict"});var Vt={};be(Vt,{default:()=>xn});var Ht,jt,xn,Yt=E(()=>{"use strict";tt();K();Ae();Ht="ort-wasm-proxy-worker",jt=globalThis.self?.name===Ht;jt&&(self.onmessage=e=>{let{type:t,in:n}=e.data;try{switch(t){case"init-wasm":Oe(n.wasm).then(()=>{Ie(n).then(()=>{postMessage({type:t})},o=>{postMessage({type:t,err:o})})},o=>{postMessage({type:t,err:o})});break;case"init-ep":{let{epName:o,env:r}=n;Pe(r,o).then(()=>{postMessage({type:t})},i=>{postMessage({type:t,err:i})});break}case"copy-from":{let{buffer:o}=n,r=le(o);postMessage({type:t,out:r});break}case"create":{let{model:o,options:r}=n;Le(o,r).then(i=>{postMessage({type:t,out:i})},i=>{postMessage({type:t,err:i})});break}case"release":xe(n),postMessage({type:t});break;case"run":{let{sessionId:o,inputIndices:r,inputs:i,outputIndices:a,options:s}=n;ve(o,r,i,a,new Array(a.length).fill(null),s).then(u=>{u.some(f=>f[3]!=="cpu")?postMessage({type:t,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:t,out:u},Ue([...i,...u]))},u=>{postMessage({type:t,err:u})});break}case"end-profiling":Be(n),postMessage({type:t});break;default:}}catch(o){postMessage({type:t,err:o})}});xn=jt?null:e=>new Worker(e??R,{type:"classic",name:Ht})});var vn,Bn,R,_e,nt,Un,_n,Zt,Mn,qt,Xt,Jt,Kt,Ae=E(()=>{"use strict";Se();vn=typeof location>"u"?void 0:location.origin,Bn=()=>{if(!!1)return typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0},R=Bn(),_e=()=>{if(R&&!R.startsWith("blob:"))return R.substring(0,R.lastIndexOf("/")+1)},nt=(e,t)=>{try{let n=t??R;return(n?new URL(e,n):new URL(e)).origin===vn}catch{return!1}},Un=(e,t)=>{let n=t??R;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},_n=(e,t)=>`${t??"./"}${e}`,Zt=async e=>{let n=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},Mn=async e=>(await import(/*webpackIgnore:true*/e)).default,qt=(Yt(),Ye(Vt)).default,Xt=async()=>{if(!R)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(nt(R))return[void 0,qt()];let e=await Zt(R);return[e,qt(e)]},Jt=void 0,Kt=async(e,t,n)=>{if(!e&&!t&&Jt&&R&&nt(R))return[void 0,Jt];{let o="ort-wasm-simd-threaded.mjs",r=e??Un(o,t),i=!!1&&n&&r&&!nt(r,t),a=i?await Zt(r):r??_n(o,t);return[i?a:void 0,await Mn(a)]}}});var rt,ot,Me,Qt,Dn,Cn,Rn,Oe,A,K=E(()=>{"use strict";Ae();ot=!1,Me=!1,Qt=!1,Dn=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{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]))}catch{return!1}},Cn=()=>{try{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]))}catch{return!1}},Rn=()=>{try{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]))}catch{return!1}},Oe=async e=>{if(ot)return Promise.resolve();if(Me)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Qt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Me=!0;let t=e.initTimeout,n=e.numThreads;if(e.simd!==!1){if(e.simd==="relaxed"){if(!Rn())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!Cn())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let o=Dn();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);let r=e.wasmPaths,i=typeof r=="string"?r:void 0,a=r?.mjs,s=a?.href??a,u=r?.wasm,f=u?.href??u,c=e.wasmBinary,[l,d]=await Kt(s,i,n>1),p=!1,w=[];if(t>0&&w.push(new Promise(b=>{setTimeout(()=>{p=!0,b()},t)})),w.push(new Promise((b,I)=>{let m={numThreads:n};if(c)m.wasmBinary=c;else if(f||i)m.locateFile=h=>f??i+h;else if(s&&s.indexOf("blob:")!==0)m.locateFile=h=>new URL(h,s).href;else if(l){let h=_e();h&&(m.locateFile=P=>h+P)}d(m).then(h=>{Me=!1,ot=!0,rt=h,b(),l&&URL.revokeObjectURL(l)},h=>{Me=!1,Qt=!0,I(h)})})),await Promise.race(w),p)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},A=()=>{if(ot&&rt)return rt;throw new Error("WebAssembly is not initialized yet.")}});var F,pe,T,De=E(()=>{"use strict";K();F=(e,t)=>{let n=A(),o=n.lengthBytesUTF8(e)+1,r=n._malloc(o);return n.stringToUTF8(e,r,o),t.push(r),r},pe=(e,t,n,o)=>{if(typeof e=="object"&&e!==null){if(n.has(e))throw new Error("Circular reference in options");n.add(e)}Object.entries(e).forEach(([r,i])=>{let a=t?t+r:r;if(typeof i=="object")pe(i,a+".",n,o);else if(typeof i=="string"||typeof i=="number")o(a,i.toString());else if(typeof i=="boolean")o(a,i?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof i}`)})},T=e=>{let t=A(),n=t.stackSave();try{let o=t.PTR_SIZE,r=t.stackAlloc(2*o);t._OrtGetLastError(r,r+o);let i=Number(t.getValue(r,o===4?"i32":"i64")),a=t.getValue(r+o,"*"),s=a?t.UTF8ToString(a):"";throw new Error(`${e} ERROR_CODE: ${i}, ERROR_MESSAGE: ${s}`)}finally{t.stackRestore(n)}}});var en,tn=E(()=>{"use strict";K();De();en=e=>{let t=A(),n=0,o=[],r=e||{};try{if(e?.logSeverityLevel===void 0)r.logSeverityLevel=2;else if(typeof e.logSeverityLevel!="number"||!Number.isInteger(e.logSeverityLevel)||e.logSeverityLevel<0||e.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${e.logSeverityLevel}`);if(e?.logVerbosityLevel===void 0)r.logVerbosityLevel=0;else if(typeof e.logVerbosityLevel!="number"||!Number.isInteger(e.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);e?.terminate===void 0&&(r.terminate=!1);let i=0;return e?.tag!==void 0&&(i=F(e.tag,o)),n=t._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,i),n===0&&T("Can't create run options."),e?.extra!==void 0&&pe(e.extra,"",new WeakSet,(a,s)=>{let u=F(a,o),f=F(s,o);t._OrtAddRunConfigEntry(n,u,f)!==0&&T(`Can't set a run config entry: ${a} - ${s}.`)}),[n,o]}catch(i){throw n!==0&&t._OrtReleaseRunOptions(n),o.forEach(a=>t._free(a)),i}}});var Fn,kn,Nn,Ce,Wn,nn,rn=E(()=>{"use strict";K();De();Fn=e=>{switch(e){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${e}`)}},kn=e=>{switch(e){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${e}`)}},Nn=e=>{e.extra||(e.extra={}),e.extra.session||(e.extra.session={});let t=e.extra.session;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=!1)},Ce=(e,t,n,o)=>{let r=F(t,o),i=F(n,o);A()._OrtAddSessionConfigEntry(e,r,i)!==0&&T(`Can't set a session config entry: ${t} - ${n}.`)},Wn=async(e,t,n)=>{for(let o of t){let r=typeof o=="string"?o:o.name,i=[];switch(r){case"webnn":if(r="WEBNN",typeof o!="string"){let l=o?.deviceType;l&&Ce(e,"deviceType",l,n)}break;case"webgpu":if(r="JS",typeof o!="string"){let c=o;if(c?.preferredLayout){if(c.preferredLayout!=="NCHW"&&c.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${c.preferredLayout}`);Ce(e,"preferredLayout",c.preferredLayout,n)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${r}`)}let a=F(r,n),s=i.length,u=0,f=0;if(s>0){u=A()._malloc(s*A().PTR_SIZE),n.push(u),f=A()._malloc(s*A().PTR_SIZE),n.push(f);for(let c=0;c<s;c++)A().setValue(u+c*A().PTR_SIZE,i[c][0],"*"),A().setValue(f+c*A().PTR_SIZE,i[c][1],"*")}await A()._OrtAppendExecutionProvider(e,a,u,f,s)!==0&&T(`Can't append execution provider: ${r}.`)}},nn=async e=>{let t=A(),n=0,o=[],r=e||{};Nn(r);try{let i=Fn(r.graphOptimizationLevel??"all"),a=kn(r.executionMode??"sequential"),s=typeof r.logId=="string"?F(r.logId,o):0,u=r.logSeverityLevel??2;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log serverity level is not valid: ${u}`);let f=r.logVerbosityLevel??0;if(!Number.isInteger(f)||f<0||f>4)throw new Error(`log verbosity level is not valid: ${f}`);let c=typeof r.optimizedModelFilePath=="string"?F(r.optimizedModelFilePath,o):0;if(n=t._OrtCreateSessionOptions(i,!!r.enableCpuMemArena,!!r.enableMemPattern,a,!!r.enableProfiling,0,s,u,f,c),n===0&&T("Can't create session options."),r.executionProviders&&await Wn(n,r.executionProviders,o),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);Ce(n,"enableGraphCapture",r.enableGraphCapture.toString(),o)}if(r.freeDimensionOverrides)for(let[l,d]of Object.entries(r.freeDimensionOverrides)){if(typeof l!="string")throw new Error(`free dimension override name must be a string: ${l}`);if(typeof d!="number"||!Number.isInteger(d)||d<0)throw new Error(`free dimension override value must be a non-negative integer: ${d}`);let p=F(l,o);t._OrtAddFreeDimensionOverride(n,p,d)!==0&&T(`Can't set a free dimension override: ${l} - ${d}.`)}return r.extra!==void 0&&pe(r.extra,"",new WeakSet,(l,d)=>{Ce(n,l,d,o)}),[n,o]}catch(i){throw n!==0&&t._OrtReleaseSessionOptions(n)!==0&&T("Can't release session options."),o.forEach(a=>t._free(a)),i}}});var oe,Re,se,on,sn,Fe,ke,an,st=E(()=>{"use strict";oe=e=>{switch(e){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw new Error(`unsupported data type: ${e}`)}},Re=e=>{switch(e){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw new Error(`unsupported data type: ${e}`)}},se=(e,t)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][e],o=typeof t=="number"?t:t.reduce((r,i)=>r*i,1);return n>0?Math.ceil(o*n):void 0},on=e=>{switch(e){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${e}`)}},sn=e=>{switch(e){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${e}`)}},Fe=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",ke=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint64"||e==="int8"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",an=e=>{switch(e){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${e}`)}}});var me,at=E(()=>{"use strict";Se();me=async e=>{if(typeof e=="string")if(!1)try{let{readFile:t}=Ve("node:fs/promises");return new Uint8Array(await t(e))}catch(t){if(t.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=Ve("node:fs"),o=n(e),r=[];for await(let i of o)r.push(i);return new Uint8Array(Buffer.concat(r))}throw t}else{let t=await fetch(e);if(!t.ok)throw new Error(`failed to load external data file: ${e}`);let n=t.headers.get("Content-Length"),o=n?parseInt(n,10):0;if(o<1073741824)return new Uint8Array(await t.arrayBuffer());{if(!t.body)throw new Error(`failed to load external data file: ${e}, no response body.`);let r=t.body.getReader(),i;try{i=new ArrayBuffer(o)}catch(s){if(s instanceof RangeError){let u=Math.ceil(o/65536);i=new WebAssembly.Memory({initial:u,maximum:u}).buffer}else throw s}let a=0;for(;;){let{done:s,value:u}=await r.read();if(s)break;let f=u.byteLength;new Uint8Array(i,a,f).set(u),a+=f}return new Uint8Array(i,0,o)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}});var Gn,Ie,Pe,ae,$n,un,le,Le,xe,fn,ve,Be,Ue,tt=E(()=>{"use strict";tn();rn();st();K();De();at();Gn=(e,t)=>{A()._OrtInit(e,t)!==0&&T("Can't initialize onnxruntime.")},Ie=async e=>{Gn(e.wasm.numThreads,sn(e.logLevel))},Pe=async(e,t)=>{A().asyncInit?.()},ae=new Map,$n=e=>{let t=A(),n=t.stackSave();try{let o=t.PTR_SIZE,r=t.stackAlloc(2*o);t._OrtGetInputOutputCount(e,r,r+o)!==0&&T("Can't get session input/output count.");let a=o===4?"i32":"i64";return[Number(t.getValue(r,a)),Number(t.getValue(r+o,a))]}finally{t.stackRestore(n)}},un=(e,t)=>{let n=A(),o=n.stackSave(),r=0;try{let i=n.PTR_SIZE,a=n.stackAlloc(2*i);n._OrtGetInputOutputMetadata(e,t,a,a+i)!==0&&T("Can't get session input/output metadata.");let u=Number(n.getValue(a,"*"));r=Number(n.getValue(a+i,"*"));let f=n.HEAP32[r/4];if(f===0)return[u,0];let c=n.HEAPU32[r/4+1],l=[];for(let d=0;d<c;d++){let p=Number(n.getValue(r+8+d*i,"*"));l.push(p!==0?n.UTF8ToString(p):Number(n.getValue(r+8+(d+c)*i,"*")))}return[u,f,l]}finally{n.stackRestore(o),r!==0&&n._OrtFree(r)}},le=e=>{let t=A(),n=t._malloc(e.byteLength);if(n===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},Le=async(e,t)=>{let n,o,r=A();Array.isArray(e)?[n,o]=e:e.buffer===r.HEAPU8.buffer?[n,o]=[e.byteOffset,e.byteLength]:[n,o]=le(e);let i=0,a=0,s=0,u=[],f=[],c=[];try{if([a,u]=await nn(t),t?.externalData&&r.mountExternalData){let g=[];for(let S of t.externalData){let B=typeof S=="string"?S:S.path;g.push(me(typeof S=="string"?S:S.data).then(D=>{r.mountExternalData(B,D)}))}await Promise.all(g)}for(let g of t?.executionProviders??[])if((typeof g=="string"?g:g.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,typeof g!="string"){let B=g,D=B?.context,_=B?.gpuDevice,te=B?.deviceType,fe=B?.powerPreference;D?r.currentContext=D:_?r.currentContext=await r.webnnCreateMLContext(_):r.currentContext=await r.webnnCreateMLContext({deviceType:te,powerPreference:fe})}else r.currentContext=await r.webnnCreateMLContext();break}i=await r._OrtCreateSession(n,o,a),r.webgpuOnCreateSession?.(i),i===0&&T("Can't create a session."),r.jsepOnCreateSession?.(),r.currentContext&&(r.webnnRegisterMLContext(i,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[l,d]=$n(i),p=!!t?.enableGraphCapture,w=[],b=[],I=[],m=[],h=[];for(let g=0;g<l;g++){let[S,B,D]=un(i,g);S===0&&T("Can't get an input name."),f.push(S);let _=r.UTF8ToString(S);w.push(_),I.push(B===0?{name:_,isTensor:!1}:{name:_,isTensor:!0,type:Re(B),shape:D})}for(let g=0;g<d;g++){let[S,B,D]=un(i,g+l);S===0&&T("Can't get an output name."),c.push(S);let _=r.UTF8ToString(S);b.push(_),m.push(B===0?{name:_,isTensor:!1}:{name:_,isTensor:!0,type:Re(B),shape:D})}return ae.set(i,[i,f,c,null,p,!1]),[i,w,b,I,m]}catch(l){throw f.forEach(d=>r._OrtFree(d)),c.forEach(d=>r._OrtFree(d)),s!==0&&r._OrtReleaseBinding(s)!==0&&T("Can't release IO binding."),i!==0&&r._OrtReleaseSession(i)!==0&&T("Can't release session."),l}finally{r._free(n),a!==0&&r._OrtReleaseSessionOptions(a)!==0&&T("Can't release session options."),u.forEach(l=>r._free(l)),r.unmountExternalData?.()}},xe=e=>{let t=A(),n=ae.get(e);if(!n)throw new Error(`cannot release session. invalid session id: ${e}`);let[o,r,i,a,s]=n;a&&(s&&t._OrtClearBoundOutputs(a.handle)!==0&&T("Can't clear bound outputs."),t._OrtReleaseBinding(a.handle)!==0&&T("Can't release IO binding.")),t.jsepOnReleaseSession?.(e),t.webnnOnReleaseSession?.(e),t.webgpuOnReleaseSession?.(e),r.forEach(u=>t._OrtFree(u)),i.forEach(u=>t._OrtFree(u)),t._OrtReleaseSession(o)!==0&&T("Can't release session."),ae.delete(e)},fn=async(e,t,n,o,r,i,a=!1)=>{if(!e){t.push(0);return}let s=A(),u=s.PTR_SIZE,f=e[0],c=e[1],l=e[3],d=l,p,w;if(f==="string"&&(l==="gpu-buffer"||l==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(a&&l!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${i} when enableGraphCapture is true.`);if(l==="gpu-buffer"){let m=e[2].gpuBuffer;w=se(oe(f),c);{let h=s.jsepRegisterBuffer;if(!h)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');p=h(o,i,m,w)}}else if(l==="ml-tensor"){let m=e[2].mlTensor;w=se(oe(f),c);let h=s.webnnRegisterMLTensor;if(!h)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');p=h(o,m,oe(f),c)}else{let m=e[2];if(Array.isArray(m)){w=u*m.length,p=s._malloc(w),n.push(p);for(let h=0;h<m.length;h++){if(typeof m[h]!="string")throw new TypeError(`tensor data at index ${h} is not a string`);s.setValue(p+h*u,F(m[h],n),"*")}}else{let h=s.webnnIsGraphInput,P=s.webnnIsGraphOutput;if(f!=="string"&&h&&P){let g=s.UTF8ToString(r);if(h(o,g)||P(o,g)){let S=oe(f);w=se(S,c),d="ml-tensor";let B=s.webnnCreateTemporaryTensor,D=s.webnnUploadTensor;if(!B||!D)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');let _=await B(o,S,c);D(_,new Uint8Array(m.buffer,m.byteOffset,m.byteLength)),p=_}else w=m.byteLength,p=s._malloc(w),n.push(p),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,w),p)}else w=m.byteLength,p=s._malloc(w),n.push(p),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,w),p)}}let b=s.stackSave(),I=s.stackAlloc(4*c.length);try{c.forEach((h,P)=>s.setValue(I+P*u,h,u===4?"i32":"i64"));let m=s._OrtCreateTensor(oe(f),p,w,I,c.length,an(d));m===0&&T(`Can't create tensor for input/output. session=${o}, index=${i}.`),t.push(m)}finally{s.stackRestore(b)}},ve=async(e,t,n,o,r,i)=>{let a=A(),s=a.PTR_SIZE,u=ae.get(e);if(!u)throw new Error(`cannot run inference. invalid session id: ${e}`);let f=u[0],c=u[1],l=u[2],d=u[3],p=u[4],w=u[5],b=t.length,I=o.length,m=0,h=[],P=[],g=[],S=[],B=a.stackSave(),D=a.stackAlloc(b*s),_=a.stackAlloc(b*s),te=a.stackAlloc(I*s),fe=a.stackAlloc(I*s);try{[m,h]=en(i);for(let y=0;y<b;y++)await fn(n[y],P,S,e,c[t[y]],t[y],p);for(let y=0;y<I;y++)await fn(r[y],g,S,e,l[o[y]],b+o[y],p);for(let y=0;y<b;y++)a.setValue(D+y*s,P[y],"*"),a.setValue(_+y*s,c[t[y]],"*");for(let y=0;y<I;y++)a.setValue(te+y*s,g[y],"*"),a.setValue(fe+y*s,l[o[y]],"*");a.jsepOnRunStart?.(f),a.webnnOnRunStart?.(f);let k;k=await a._OrtRun(f,_,D,b,fe,I,te,m),k!==0&&T("failed to call OrtRun().");let $=[],ct=[];for(let y=0;y<I;y++){let z=Number(a.getValue(te+y*s,"*"));if(z===g[y]){$.push(r[y]);continue}let dt=a.stackSave(),G=a.stackAlloc(4*s),ne=!1,x,M=0;try{a._OrtGetTensorData(z,G,G+s,G+2*s,G+3*s)!==0&&T(`Can't access output tensor data on index ${y}.`);let He=s===4?"i32":"i64",he=Number(a.getValue(G,He));M=a.getValue(G+s,"*");let lt=a.getValue(G+s*2,"*"),Sn=Number(a.getValue(G+s*3,He)),H=[];for(let v=0;v<Sn;v++)H.push(Number(a.getValue(lt+v*s,He)));a._OrtFree(lt)!==0&&T("Can't free memory for tensor dims.");let j=H.reduce((v,L)=>v*L,1);x=Re(he);let ce=d?.outputPreferredLocations[o[y]];if(x==="string"){if(ce==="gpu-buffer"||ce==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let v=[];for(let L=0;L<j;L++){let V=a.getValue(M+L*s,"*"),ye=a.getValue(M+(L+1)*s,"*"),pt=L===j-1?void 0:ye-V;v.push(a.UTF8ToString(V,pt))}$.push([x,H,v,"cpu"])}else if(ce==="gpu-buffer"&&j>0){let v=a.jsepGetBuffer;if(!v)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let L=v(M),V=se(he,j);if(V===void 0||!Fe(x))throw new Error(`Unsupported data type: ${x}`);ne=!0,$.push([x,H,{gpuBuffer:L,download:a.jsepCreateDownloader(L,V,x),dispose:()=>{a._OrtReleaseTensor(z)!==0&&T("Can't release tensor.")}},"gpu-buffer"])}else if(ce==="ml-tensor"&&j>0){let v=a.webnnEnsureTensor,L=a.webnnIsGraphInputOutputTypeSupported;if(!v||!L)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(se(he,j)===void 0||!ke(x))throw new Error(`Unsupported data type: ${x}`);if(!L(e,x,!1))throw new Error(`preferredLocation "ml-tensor" for ${x} output is not supported by current WebNN Context.`);let ye=await v(e,M,he,H,!1);ne=!0,$.push([x,H,{mlTensor:ye,download:a.webnnCreateMLTensorDownloader(M,x),dispose:()=>{a.webnnReleaseTensorId(M),a._OrtReleaseTensor(z)}},"ml-tensor"])}else if(ce==="ml-tensor-cpu-output"&&j>0){let v=a.webnnCreateMLTensorDownloader(M,x)(),L=$.length;ne=!0,ct.push((async()=>{let V=[L,await v];return a.webnnReleaseTensorId(M),a._OrtReleaseTensor(z),V})()),$.push([x,H,[],"cpu"])}else{let v=on(x),L=new v(j);new Uint8Array(L.buffer,L.byteOffset,L.byteLength).set(a.HEAPU8.subarray(M,M+L.byteLength)),$.push([x,H,L,"cpu"])}}finally{a.stackRestore(dt),x==="string"&&M&&a._free(M),ne||a._OrtReleaseTensor(z)}}d&&!p&&(a._OrtClearBoundOutputs(d.handle)!==0&&T("Can't clear bound outputs."),ae.set(e,[f,c,l,d,p,!1]));for(let[y,z]of await Promise.all(ct))$[y][2]=z;return $}finally{a.webnnOnRunEnd?.(f),a.stackRestore(B),P.forEach(k=>a._OrtReleaseTensor(k)),g.forEach(k=>a._OrtReleaseTensor(k)),S.forEach(k=>a._free(k)),m!==0&&a._OrtReleaseRunOptions(m),h.forEach(k=>a._free(k))}},Be=e=>{let t=A(),n=ae.get(e);if(!n)throw new Error("invalid session id");let o=n[0],r=t._OrtEndProfiling(o);r===0&&T("Can't get an profile file name."),t._OrtFree(r)},Ue=e=>{let t=[];for(let n of e){let o=n[2];!Array.isArray(o)&&"buffer"in o&&t.push(o.buffer)}return t}});var ee,W,we,We,Ge,Ne,it,ut,ie,ue,Hn,cn,dn,ln,pn,mn,wn,hn,ft=E(()=>{"use strict";X();tt();K();Ae();ee=()=>!!O.wasm.proxy&&typeof document<"u",we=!1,We=!1,Ge=!1,ut=new Map,ie=(e,t)=>{let n=ut.get(e);n?n.push(t):ut.set(e,[t])},ue=()=>{if(we||!We||Ge||!W)throw new Error("worker not ready")},Hn=e=>{switch(e.data.type){case"init-wasm":we=!1,e.data.err?(Ge=!0,it[1](e.data.err)):(We=!0,it[0]()),Ne&&(URL.revokeObjectURL(Ne),Ne=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let t=ut.get(e.data.type);e.data.err?t.shift()[1](e.data.err):t.shift()[0](e.data.out);break}default:}},cn=async()=>{if(!We){if(we)throw new Error("multiple calls to 'initWasm()' detected.");if(Ge)throw new Error("previous call to 'initWasm()' failed.");if(we=!0,ee())return new Promise((e,t)=>{W?.terminate(),Xt().then(([n,o])=>{try{W=o,W.onerror=i=>t(i),W.onmessage=Hn,it=[e,t];let r={type:"init-wasm",in:O};if(!r.in.wasm.wasmPaths&&n){let i=_e();i&&(r.in.wasm.wasmPaths=i)}W.postMessage(r),Ne=n}catch(r){t(r)}},t)});try{await Oe(O.wasm),await Ie(O),We=!0}catch(e){throw Ge=!0,e}finally{we=!1}}},dn=async e=>{if(ee())return ue(),new Promise((t,n)=>{ie("init-ep",[t,n]);let o={type:"init-ep",in:{epName:e,env:O}};W.postMessage(o)});await Pe(O,e)},ln=async e=>ee()?(ue(),new Promise((t,n)=>{ie("copy-from",[t,n]);let o={type:"copy-from",in:{buffer:e}};W.postMessage(o,[e.buffer])})):le(e),pn=async(e,t)=>{if(ee()){if(t?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return ue(),new Promise((n,o)=>{ie("create",[n,o]);let r={type:"create",in:{model:e,options:{...t}}},i=[];e instanceof Uint8Array&&i.push(e.buffer),W.postMessage(r,i)})}else return Le(e,t)},mn=async e=>{if(ee())return ue(),new Promise((t,n)=>{ie("release",[t,n]);let o={type:"release",in:e};W.postMessage(o)});xe(e)},wn=async(e,t,n,o,r,i)=>{if(ee()){if(n.some(a=>a[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(r.some(a=>a))throw new Error("pre-allocated output tensor is not supported for proxy.");return ue(),new Promise((a,s)=>{ie("run",[a,s]);let u=n,f={type:"run",in:{sessionId:e,inputIndices:t,inputs:u,outputIndices:o,options:i}};W.postMessage(f,Ue(u))})}else return ve(e,t,n,o,r,i)},hn=async e=>{if(ee())return ue(),new Promise((t,n)=>{ie("end-profiling",[t,n]);let o={type:"end-profiling",in:e};W.postMessage(o)});Be(e)}});var yn,jn,$e,bn=E(()=>{"use strict";X();ft();st();Se();at();yn=(e,t)=>{switch(e.location){case"cpu":return[e.type,e.dims,e.data,"cpu"];case"gpu-buffer":return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[e.type,e.dims,{mlTensor:e.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},jn=e=>{switch(e[3]){case"cpu":return new N(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!Fe(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=e[2];return N.fromGpuBuffer(n,{dataType:t,dims:e[1],download:o,dispose:r})}case"ml-tensor":{let t=e[0];if(!ke(t))throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:o,dispose:r}=e[2];return N.fromMLTensor(n,{dataType:t,dims:e[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${e[3]}`)}},$e=class{async fetchModelAndCopyToWasmMemory(t){return ln(await me(t))}async loadModel(t,n){Y();let o;typeof t=="string"?o=await this.fetchModelAndCopyToWasmMemory(t):o=t,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await pn(o,n),q()}async dispose(){return mn(this.sessionId)}async run(t,n,o){Y();let r=[],i=[];Object.entries(t).forEach(d=>{let p=d[0],w=d[1],b=this.inputNames.indexOf(p);if(b===-1)throw new Error(`invalid input '${p}'`);r.push(w),i.push(b)});let a=[],s=[];Object.entries(n).forEach(d=>{let p=d[0],w=d[1],b=this.outputNames.indexOf(p);if(b===-1)throw new Error(`invalid output '${p}'`);a.push(w),s.push(b)});let u=r.map((d,p)=>yn(d,()=>`input "${this.inputNames[i[p]]}"`)),f=a.map((d,p)=>d?yn(d,()=>`output "${this.outputNames[s[p]]}"`):null),c=await wn(this.sessionId,i,u,s,f,o),l={};for(let d=0;d<c.length;d++)l[this.outputNames[s[d]]]=a[d]??jn(c[d]);return q(),l}startProfiling(){}endProfiling(){hn(this.sessionId)}}});var En={};be(En,{OnnxruntimeWebAssemblyBackend:()=>ze,initializeFlags:()=>gn,wasmBackend:()=>Vn});var gn,ze,Vn,Tn=E(()=>{"use strict";X();ft();bn();gn=()=>{(typeof O.wasm.initTimeout!="number"||O.wasm.initTimeout<0)&&(O.wasm.initTimeout=0);let e=O.wasm.simd;if(typeof e!="boolean"&&e!==void 0&&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.`),O.wasm.simd=!1),typeof O.wasm.proxy!="boolean"&&(O.wasm.proxy=!1),typeof O.wasm.trace!="boolean"&&(O.wasm.trace=!1),typeof O.wasm.numThreads!="number"||!Number.isInteger(O.wasm.numThreads)||O.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)O.wasm.numThreads=1;else{let t=typeof navigator>"u"?Ve("node:os").cpus().length:navigator.hardwareConcurrency;O.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}},ze=class{async init(t){gn(),await cn(),await dn(t)}async createInferenceSessionHandler(t,n){let o=new $e;return await o.loadModel(t,n),o}},Vn=new ze});var qn={};be(qn,{InferenceSession:()=>Ft,TRACE:()=>Ke,TRACE_FUNC_BEGIN:()=>Y,TRACE_FUNC_END:()=>q,Tensor:()=>N,default:()=>Yn,env:()=>O,registerBackend:()=>re});X();X();X();var zt="1.22.0";var Yn=et;{let e=(Tn(),Ye(En)).wasmBackend;re("cpu",e,10),re("wasm",e,10)}Object.defineProperty(O.versions,"web",{value:zt,enumerable:!0});return Ye(qn);})();
|
| 7 |
typeof exports=="object"&&typeof module=="object"&&(module.exports=ort);
|
| 8 |
//# sourceMappingURL=ort.wasm.min.js.map
|
models/minicpm_agent.py
CHANGED
|
@@ -32,7 +32,9 @@ and the message builders live here so the wording stays with the model.
|
|
| 32 |
|
| 33 |
from __future__ import annotations
|
| 34 |
|
|
|
|
| 35 |
import json
|
|
|
|
| 36 |
import re
|
| 37 |
|
| 38 |
import torch
|
|
@@ -40,10 +42,12 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 40 |
|
| 41 |
from core.constants import (
|
| 42 |
AGENT_MAX_NEW_TOKENS,
|
| 43 |
-
|
| 44 |
-
|
| 45 |
)
|
| 46 |
|
|
|
|
|
|
|
| 47 |
# The tools the agent may emit, and the JSON shape of each. Kept here so the
|
| 48 |
# prompt and the parser can't drift apart.
|
| 49 |
TOOLS = ("search", "find_answer", "go_to_section", "go_to_page", "circle", "done")
|
|
@@ -228,31 +232,81 @@ def assistant_action_message(tool: dict) -> dict:
|
|
| 228 |
return {"role": "assistant", "content": json.dumps(tool, separators=(",", ":"))}
|
| 229 |
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
)
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
)
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
|
| 246 |
def _generate(messages: list[dict], max_new_tokens: int) -> str:
|
| 247 |
-
"""Greedy decode the assistant's next message.
|
| 248 |
-
routing wants a terse decision, not a reasoning trace."""
|
| 249 |
inputs = _TOKENIZER.apply_chat_template(
|
| 250 |
messages,
|
| 251 |
tokenize=True,
|
| 252 |
add_generation_prompt=True,
|
| 253 |
-
enable_thinking=False,
|
| 254 |
return_dict=True,
|
| 255 |
return_tensors="pt",
|
|
|
|
| 256 |
).to(_MODEL.device)
|
| 257 |
# apply_chat_template emits token_type_ids, which this LlamaForCausalLM's
|
| 258 |
# generate() rejects as an unused kwarg.
|
|
@@ -274,7 +328,7 @@ def render_prompt(messages: list[dict]) -> str:
|
|
| 274 |
messages,
|
| 275 |
tokenize=False,
|
| 276 |
add_generation_prompt=True,
|
| 277 |
-
|
| 278 |
)
|
| 279 |
|
| 280 |
|
|
|
|
| 32 |
|
| 33 |
from __future__ import annotations
|
| 34 |
|
| 35 |
+
import gc
|
| 36 |
import json
|
| 37 |
+
import logging
|
| 38 |
import re
|
| 39 |
|
| 40 |
import torch
|
|
|
|
| 42 |
|
| 43 |
from core.constants import (
|
| 44 |
AGENT_MAX_NEW_TOKENS,
|
| 45 |
+
AGENT_MODELS,
|
| 46 |
+
DEFAULT_AGENT_MODEL,
|
| 47 |
)
|
| 48 |
|
| 49 |
+
log = logging.getLogger("repairguy.agent")
|
| 50 |
+
|
| 51 |
# The tools the agent may emit, and the JSON shape of each. Kept here so the
|
| 52 |
# prompt and the parser can't drift apart.
|
| 53 |
TOOLS = ("search", "find_answer", "go_to_section", "go_to_page", "circle", "done")
|
|
|
|
| 232 |
return {"role": "assistant", "content": json.dumps(tool, separators=(",", ":"))}
|
| 233 |
|
| 234 |
|
| 235 |
+
# --- the resident brain: ONE model in VRAM, swapped on demand ---------------
|
| 236 |
+
# The agent model is selectable from the UI (core.constants.AGENT_MODELS). Only
|
| 237 |
+
# one is held on the GPU at a time: use_model() evicts the current one before
|
| 238 |
+
# loading the next ("load-on-switch"), so VRAM stays flat as the user A/Bs
|
| 239 |
+
# models. The model/tokenizer live in module globals for the same ZeroGPU reason
|
| 240 |
+
# as the other models β module-level CUDA tensors are shared with the GPU worker.
|
| 241 |
+
_REGISTRY = {m["key"]: m for m in AGENT_MODELS}
|
| 242 |
+
_active_key: str | None = None
|
| 243 |
+
_MODEL = None
|
| 244 |
+
_TOKENIZER = None
|
| 245 |
+
# Whether the active model's chat template accepts enable_thinking (Qwen3 /
|
| 246 |
+
# MiniCPM yes, Cohere no) β drives whether we pass the kwarg below.
|
| 247 |
+
_THINKING = False
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def _spec(key: str | None) -> dict:
|
| 251 |
+
return _REGISTRY.get(key or "", _REGISTRY[DEFAULT_AGENT_MODEL])
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def use_model(key: str | None = None) -> str:
|
| 255 |
+
"""Make `key` the resident agent brain, loading it (and evicting the
|
| 256 |
+
previous one) when it isn't already active β one model in VRAM at a time.
|
| 257 |
+
Unknown keys fall back to the default. Called once per turn by the pipeline,
|
| 258 |
+
inside the GPU context. Returns the active key. Must run on GPU."""
|
| 259 |
+
global _active_key, _MODEL, _TOKENIZER, _THINKING
|
| 260 |
+
spec = _spec(key)
|
| 261 |
+
if spec["key"] == _active_key and _MODEL is not None:
|
| 262 |
+
return _active_key
|
| 263 |
+
# Drop the current model first so VRAM holds only one brain at a time.
|
| 264 |
+
if _MODEL is not None:
|
| 265 |
+
log.info("agent model: evicting %s", _active_key)
|
| 266 |
+
_MODEL = _TOKENIZER = None
|
| 267 |
+
gc.collect()
|
| 268 |
+
if torch.cuda.is_available():
|
| 269 |
+
torch.cuda.empty_cache()
|
| 270 |
+
log.info("agent model: loading %s (%s)", spec["key"], spec["model_id"])
|
| 271 |
+
_TOKENIZER = AutoTokenizer.from_pretrained(
|
| 272 |
+
spec["model_id"], revision=spec["revision"]
|
| 273 |
)
|
| 274 |
+
_MODEL = (
|
| 275 |
+
AutoModelForCausalLM.from_pretrained(
|
| 276 |
+
spec["model_id"],
|
| 277 |
+
revision=spec["revision"],
|
| 278 |
+
dtype=torch.bfloat16,
|
| 279 |
+
attn_implementation="sdpa",
|
| 280 |
+
)
|
| 281 |
+
.to("cuda")
|
| 282 |
+
.eval()
|
| 283 |
+
)
|
| 284 |
+
_active_key, _THINKING = spec["key"], spec["thinking"]
|
| 285 |
+
return _active_key
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# Load the default brain eagerly at import β same as the other models, so the
|
| 289 |
+
# ZeroGPU startup packing covers it and the common (no-switch) path pays no
|
| 290 |
+
# load cost on the first turn.
|
| 291 |
+
use_model(DEFAULT_AGENT_MODEL)
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def _template_kwargs() -> dict:
|
| 295 |
+
"""Extra apply_chat_template kwargs for the active model. Tool routing wants
|
| 296 |
+
a terse decision, not a reasoning trace, so disable thinking β but only for
|
| 297 |
+
templates that accept the kwarg (others would ignore or choke on it)."""
|
| 298 |
+
return {"enable_thinking": False} if _THINKING else {}
|
| 299 |
|
| 300 |
|
| 301 |
def _generate(messages: list[dict], max_new_tokens: int) -> str:
|
| 302 |
+
"""Greedy decode the assistant's next message."""
|
|
|
|
| 303 |
inputs = _TOKENIZER.apply_chat_template(
|
| 304 |
messages,
|
| 305 |
tokenize=True,
|
| 306 |
add_generation_prompt=True,
|
|
|
|
| 307 |
return_dict=True,
|
| 308 |
return_tensors="pt",
|
| 309 |
+
**_template_kwargs(),
|
| 310 |
).to(_MODEL.device)
|
| 311 |
# apply_chat_template emits token_type_ids, which this LlamaForCausalLM's
|
| 312 |
# generate() rejects as an unused kwarg.
|
|
|
|
| 328 |
messages,
|
| 329 |
tokenize=False,
|
| 330 |
add_generation_prompt=True,
|
| 331 |
+
**_template_kwargs(),
|
| 332 |
)
|
| 333 |
|
| 334 |
|
pipelines/agent_ask.py
CHANGED
|
@@ -88,11 +88,18 @@ def agent_events(
|
|
| 88 |
viewer: dict | None = None,
|
| 89 |
history: list | None = None,
|
| 90 |
ground_thinking: bool | None = None,
|
|
|
|
| 91 |
):
|
| 92 |
"""Yield the events of one agent turn (see module docstring). sections is the
|
| 93 |
numbered table of contents shown to the agent ([{title, page}]); the agent's
|
| 94 |
go_to_section index is 1-based into it. ground_thinking toggles MiniCPM-V's
|
| 95 |
-
reasoning for the circle grounding (None β server default)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
doc_id = doc_ids[0]
|
| 97 |
manual = names[doc_id]
|
| 98 |
viewer = viewer or {}
|
|
@@ -335,6 +342,7 @@ class AgentPipeline:
|
|
| 335 |
viewer: dict | None = None,
|
| 336 |
history: list | None = None,
|
| 337 |
ground_thinking: bool | None = None,
|
|
|
|
| 338 |
):
|
| 339 |
"""One streamed agent turn (the event generator of agent_events)."""
|
| 340 |
request = (request or "").strip()
|
|
@@ -347,4 +355,5 @@ class AgentPipeline:
|
|
| 347 |
return agent_events(
|
| 348 |
request, visual_store, parsed_store, doc_ids or list(names),
|
| 349 |
int(top_k), names, sections, viewer, history, ground_thinking,
|
|
|
|
| 350 |
)
|
|
|
|
| 88 |
viewer: dict | None = None,
|
| 89 |
history: list | None = None,
|
| 90 |
ground_thinking: bool | None = None,
|
| 91 |
+
agent_model: str | None = None,
|
| 92 |
):
|
| 93 |
"""Yield the events of one agent turn (see module docstring). sections is the
|
| 94 |
numbered table of contents shown to the agent ([{title, page}]); the agent's
|
| 95 |
go_to_section index is 1-based into it. ground_thinking toggles MiniCPM-V's
|
| 96 |
+
reasoning for the circle grounding (None β server default); agent_model picks
|
| 97 |
+
which brain drives the loop (None β default), loaded on switch inside this
|
| 98 |
+
GPU window."""
|
| 99 |
+
# Swap in the selected brain (evicts the previous one) before any decide/
|
| 100 |
+
# rerank. Inside this @spaces.GPU window, so the load happens on the GPU.
|
| 101 |
+
active = minicpm_agent.use_model(agent_model)
|
| 102 |
+
log.info("agent brain: %s", active)
|
| 103 |
doc_id = doc_ids[0]
|
| 104 |
manual = names[doc_id]
|
| 105 |
viewer = viewer or {}
|
|
|
|
| 342 |
viewer: dict | None = None,
|
| 343 |
history: list | None = None,
|
| 344 |
ground_thinking: bool | None = None,
|
| 345 |
+
agent_model: str | None = None,
|
| 346 |
):
|
| 347 |
"""One streamed agent turn (the event generator of agent_events)."""
|
| 348 |
request = (request or "").strip()
|
|
|
|
| 355 |
return agent_events(
|
| 356 |
request, visual_store, parsed_store, doc_ids or list(names),
|
| 357 |
int(top_k), names, sections, viewer, history, ground_thinking,
|
| 358 |
+
agent_model,
|
| 359 |
)
|
pipelines/mock_ask.py
CHANGED
|
@@ -144,11 +144,12 @@ class MockAskPipeline:
|
|
| 144 |
viewer: dict | None = None,
|
| 145 |
history: list | None = None,
|
| 146 |
ground_thinking: bool | None = None,
|
|
|
|
| 147 |
):
|
| 148 |
"""Yield the same event sequence as pipelines/agent_ask.py, with a
|
| 149 |
keyword-driven stand-in for the agent's tool choice. Both stores are the
|
| 150 |
-
one MockStore; history and
|
| 151 |
-
(seconds) paces events."""
|
| 152 |
request = (request or "").strip()
|
| 153 |
if not request:
|
| 154 |
raise ValueError("Tell me what to find.")
|
|
|
|
| 144 |
viewer: dict | None = None,
|
| 145 |
history: list | None = None,
|
| 146 |
ground_thinking: bool | None = None,
|
| 147 |
+
agent_model: str | None = None,
|
| 148 |
):
|
| 149 |
"""Yield the same event sequence as pipelines/agent_ask.py, with a
|
| 150 |
keyword-driven stand-in for the agent's tool choice. Both stores are the
|
| 151 |
+
one MockStore; history, ground_thinking and agent_model are ignored.
|
| 152 |
+
MOCK_DELAY (seconds) paces events."""
|
| 153 |
request = (request or "").strip()
|
| 154 |
if not request:
|
| 155 |
raise ValueError("Tell me what to find.")
|