{"version":3,"file":"providers.cjs","names":[],"sources":["../../../src/vision/core/providers.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Execution-provider defaults for ONNX Runtime Web sessions.\n *\n * Unlike Node ORT, the browser ORT cannot enumerate \"available providers\" at\n * runtime — `webgpu` either works or ORT silently falls back to the next\n * provider in the list. We just expose a sensible default order.\n */\n\n/**\n * Default execution provider preference order for browser ORT.\n *\n * `webgpu` is tried first when available; ORT-Web falls back to `wasm`\n * automatically when WebGPU is not supported by the browser or device.\n */\nexport const DEFAULT_PROVIDERS: readonly string[] = [\"webgpu\", \"wasm\"];\n\n/**\n * The provider ORT-Web can always run, whatever the device.\n *\n * Used as the floor when capability detection rules everything else out. Passing\n * ORT a list it cannot satisfy is not a graceful failure — `InferenceSession.create`\n * rejects with \"no available backend found\" and the page gets no inference at\n * all, which is worse than the slow-but-working fallback the warning describes.\n */\nexport const FALLBACK_PROVIDER = \"wasm\";\n\n/**\n * Resolve the execution providers to pass to `InferenceSession.create`.\n *\n * @param requested Explicit provider list in preference order; `undefined` returns the default.\n */\nexport function resolveProviders(requested?: readonly string[]): string[] {\n    if (requested === undefined) {\n        return [...DEFAULT_PROVIDERS];\n    }\n    if (requested.length === 0) {\n        return [...DEFAULT_PROVIDERS];\n    }\n    return [...requested];\n}\n\n/**\n * Narrow a provider list to the ones this browser can actually offer.\n *\n * ORT-Web exposes no equivalent of Node's `session.getProviders()`, so there is\n * no way to ask which provider a session ended up on. What the browser *does*\n * answer is whether the underlying API exists at all — no `navigator.gpu`, or no\n * adapter behind it, means `webgpu` was never going to run — and that covers the\n * case that actually bites: a page asking for WebGPU on a device without it,\n * silently getting WASM, and being several times slower than intended with no\n * error to point at.\n *\n * This is best-effort by construction. A provider that survives here can still\n * fail inside ORT for a reason the browser does not surface (a missing shader\n * feature, an exhausted device), so a surviving entry means \"not ruled out\",\n * not \"confirmed running\". Anything this function does not know how to test is\n * kept rather than dropped: guessing a provider away would be worse than\n * admitting ignorance about it.\n *\n * @param requested Providers in preference order, already resolved.\n * @returns The subset that is not ruled out, in the same order.\n */\nexport async function detectProviders(requested: readonly string[]): Promise<string[]> {\n    const webgpu = await hasWebGpuAdapter();\n    return requested.filter((provider) => {\n        switch (provider) {\n            case \"webgpu\":\n                return webgpu;\n            case \"webnn\":\n                return typeof navigator !== \"undefined\" && \"ml\" in navigator;\n            default:\n                return true;\n        }\n    });\n}\n\n/**\n * Whether this environment exposes a WebGPU adapter.\n *\n * `navigator.gpu` existing is not enough — a browser can ship the API and still\n * hand back no adapter (a blocklisted driver, a headless context, a machine with\n * no suitable GPU), which is exactly the configuration where a page asks for\n * WebGPU and quietly runs on WASM.\n */\nasync function hasWebGpuAdapter(): Promise<boolean> {\n    const gpu = (\n        globalThis.navigator as { gpu?: { requestAdapter(): Promise<unknown> } } | undefined\n    )?.gpu;\n    if (gpu === undefined) {\n        return false;\n    }\n    try {\n        return (await gpu.requestAdapter()) !== null;\n    } catch {\n        return false;\n    }\n}\n"],"mappings":"AAeA,IAAa,EAAuC,CAAC,SAAU,MAAM,EAUxD,EAAoB,OAOjC,SAAgB,EAAiB,EAAyC,CAOtE,OANI,IAAc,IAAA,IAGd,EAAU,SAAW,EACd,CAAC,GAAG,CAAiB,EAEzB,CAAC,GAAG,CAAS,CACxB,CAuBA,eAAsB,EAAgB,EAAiD,CACnF,IAAM,EAAS,MAAM,EAAiB,EACtC,OAAO,EAAU,OAAQ,GAAa,CAClC,OAAQ,EAAR,CACI,IAAK,SACD,OAAO,EACX,IAAK,QACD,OAAO,OAAO,UAAc,KAAe,OAAQ,UACvD,QACI,MAAO,EACf,CACJ,CAAC,CACL,CAUA,eAAe,GAAqC,CAChD,IAAM,EACF,WAAW,WACZ,IACH,GAAI,IAAQ,IAAA,GACR,MAAO,GAEX,GAAI,CACA,OAAQ,MAAM,EAAI,eAAe,IAAO,IAC5C,MAAQ,CACJ,MAAO,EACX,CACJ"}