(()=>{const stack=new Error().stack;stack&&(globalThis._sentryDebugIds=globalThis._sentryDebugIds||{},globalThis._sentryDebugIds[stack]="563fc973-88ef-54e4-9333-7b41a6b01186",globalThis._sentryDebugIdIdentifier="sentry-dbid-563fc973-88ef-54e4-9333-7b41a6b01186");})();

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------------------------------------------*/
import __module from "module";
import __path from "path";
import __fs from "fs";
const __rootRequire = __module.createRequire(import.meta.url);
const __appPath = __fs.realpathSync(import.meta.dirname);
const __clipboardEntrypoint = __path.join(__appPath, "clipboard", "index.js");
const __foundryEntrypoint = __path.join(__appPath, "foundry-local-sdk", "index.js");
const __pvRecorderEntrypoint = __path.join(__appPath, "pvrecorder", "index.js");
const __napiOopEntrypoint = __path.join(__appPath, "napi-oop-runtime", "index.js");
const __clipboardRequire = __fs.existsSync(__clipboardEntrypoint)
    ? __module.createRequire(__clipboardEntrypoint)
    : __rootRequire;
const __foundryRequire = __fs.existsSync(__foundryEntrypoint)
    ? __module.createRequire(__foundryEntrypoint)
    : __rootRequire;
const __pvRecorderRequire = __fs.existsSync(__pvRecorderEntrypoint)
    ? __module.createRequire(__pvRecorderEntrypoint)
    : __rootRequire;
const __napiOopRequire = __fs.existsSync(__napiOopEntrypoint)
    ? __module.createRequire(__napiOopEntrypoint)
    : __rootRequire;
const __isVendoredNativeModule = (module) =>
    typeof module === "string" &&
    (module.startsWith("@teddyzhu/") || module === "foundry-local-sdk" || module === "@picovoice/pvrecorder-node" || module === "napi-oop-runtime");
const require = (module) => {
    let req = __rootRequire;
    if (typeof module === "string" && module.startsWith("@teddyzhu/")) {
        req = __clipboardRequire;
    }
    if (module === "foundry-local-sdk") {
        req = __foundryRequire;
    }
    if (module === "@picovoice/pvrecorder-node") {
        req = __pvRecorderRequire;
    }
    if (module === "napi-oop-runtime") {
        req = __napiOopRequire;
    }

    if (typeof module === "string" && (__module.isBuiltin(module) || __isVendoredNativeModule(module))) {
        return req(module);
    }

    const modulePath = __fs.realpathSync(req.resolve(module));
    const relativePath = __path.relative(__appPath, modulePath);

    if (relativePath.startsWith("..")) {
        throw new Error("Requiring module outside of application is a security concern; module: " + modulePath + ", app: " + __appPath);
    }

    return req(module);
};import __url from "url";
const __esmShimFilename = __url.fileURLToPath(import.meta.url);
const __esmShimDirname = __path.dirname(__esmShimFilename);
import{parentPort as F,workerData as B}from"node:worker_threads";var m=class{initialQueue=[];initialQueueResolvers=Promise.withResolvers();logWriter=null;cachedOutputPath;writePromise=this.initialQueueResolvers.promise;setLogWriter(e){this.logWriter=e,this.cachedOutputPath=void 0;for(let t of this.initialQueue)this.writeTo(e,t.method,t.message);this.initialQueue=[],this.initialQueueResolvers.resolve()}async flush(){if(!this.logWriter)return;let e=this.logWriter,t=(async()=>{try{await this.writePromise,await e.flush?.()}catch{}})(),o,n=new Promise(s=>{o=setTimeout(s,5e3),o.unref?.()});try{await Promise.race([t,n])}finally{o&&clearTimeout(o)}}async dispose(){await this.flush()}outputPath(){return this.cachedOutputPath??=this.logWriter?.outputPath()}logToLevel(e,t){this.logWriter?this.writeTo(this.logWriter,e,t):this.initialQueue.push({method:e,message:t})}writeTo(e,t,o){if(e.write&&e.flush){e.write(t,o),this.writePromise=e.flush().catch(()=>{});return}this.writePromise=e.writeLog(t,o).catch(()=>{})}info(e){this.logToLevel("info",e)}debug(e){this.logToLevel("debug",e)}warning(e){this.logToLevel("warning",e)}error(e){this.logToLevel("error",e instanceof Error?e.message:e)}log(e){this.error(e)}isDebug(){return!1}shouldLog(e){return!0}notice(e){this.info(e instanceof Error?e.message:e)}startGroup(e,t){this.info(`--- Start of group: ${e} ---`)}endGroup(e){this.info("--- End of group ---")}},u=new m;import{createRequire as H}from"node:module";import*as i from"node:fs/promises";import*as a from"node:path";import{createHash as W}from"node:crypto";import{join as l,basename as or}from"node:path";import{homedir as h}from"node:os";function A(){return process.env.XDG_CACHE_HOME||l(h(),".cache")}function O(){if(process.platform==="darwin")return l(h(),"Library","Caches","copilot");if(process.platform==="win32"){let r=process.env.LOCALAPPDATA||l(h(),".cache");return l(r,"copilot")}return l(A(),"copilot")}function D(r){if(r.includes("<!DOCTYPE")||r.includes("<html")){let e=Math.min(r.indexOf("<!DOCTYPE")!==-1?r.indexOf("<!DOCTYPE"):1/0,r.indexOf("<html")!==-1?r.indexOf("<html"):1/0),t=r.substring(0,e).trim();return t?`${t} [HTML error page omitted]`:"[HTML error page omitted]"}return r}function y(r){let e;if(r instanceof Error)e=String(r);else if(typeof r=="object"&&r!==null)try{e=JSON.stringify(r)??"[object]"}catch{return"[object with circular reference]"}else e=String(r);return D(e)}var j=1,I=".complete";var v={"win32-x64":"win-x64","win32-arm64":"win-arm64","linux-x64":"linux-x64","darwin-arm64":"osx-arm64"};function C(){return typeof __foundryRequire<"u"&&__foundryRequire||H(import.meta.url)}var f;function U(){if(f)return f;try{let r=C()("foundry-local-sdk/script/install-utils.cjs");if(typeof r.runInstall!="function")throw new Error(`Expected exports {runInstall: function}, got: ${JSON.stringify(Object.fromEntries(Object.entries(r).map(([e,t])=>[e,typeof t])))}`);return f=r,f}catch(r){throw new Error(`Failed to load foundry-local-sdk/script/install-utils.cjs: ${y(r)}. The upstream foundry-local-sdk installer may have changed shape \u2014 re-run the audit checklist in src/cli/voice/foundry/installer/nativeLoader.ts and update accordingly.`)}}var p;function J(){if(p)return p;try{let r=C()("foundry-local-sdk/deps_versions.json");if(typeof r["foundry-local-core"]?.nuget!="string"||typeof r.onnxruntime?.version!="string"||typeof r["onnxruntime-genai"]?.version!="string")throw new Error('deps_versions.json is missing one of the expected version keys: ["foundry-local-core"].nuget, .onnxruntime.version, ["onnxruntime-genai"].version');return p=r,p}catch(r){throw new Error(`Failed to load foundry-local-sdk/deps_versions.json: ${y(r)}. The upstream foundry-local-sdk installer may have changed shape \u2014 re-run the audit checklist in src/cli/voice/foundry/installer/nativeLoader.ts and update accordingly.`)}}function S(r=process.platform){let e=J();return[{name:"Microsoft.AI.Foundry.Local.Core",version:e["foundry-local-core"].nuget},{name:r==="linux"?"Microsoft.ML.OnnxRuntime.Gpu.Linux":"Microsoft.ML.OnnxRuntime.Foundry",version:e.onnxruntime.version},{name:"Microsoft.ML.OnnxRuntimeGenAI.Foundry",version:e["onnxruntime-genai"].version}]}function b(r){return r==="win32"?".dll":r==="darwin"?".dylib":".so"}function V(r,e){return a.join(r,`Microsoft.AI.Foundry.Local.Core${b(e)}`)}function K(r){let e=b(r),t=r==="win32"?"":"lib";return[`Microsoft.AI.Foundry.Local.Core${e}`,`${t}onnxruntime${e}`,`${t}onnxruntime-genai${e}`]}function q(r,e=process.platform,t=process.arch){let o=v[`${e}-${t}`];if(!o)throw new Error(`Voice mode not supported on ${e}-${t}`);let n=r??process.env.COPILOT_CACHE_HOME??O(),s=S(e),c=W("sha256").update(JSON.stringify({schema:j,artifacts:s})).digest("hex").slice(0,12);return a.join(n,"foundry",c,o)}async function _(r={}){let e=r.platform??process.platform,t=r.arch??process.arch,o=`${e}-${t}`;if(!v[o])throw new Error(`Voice mode is not supported on ${o}. Supported platforms: ${Object.keys(v).join(", ")}.`);let s=q(r.cacheRoot,e,t),c=V(s,e),d=K(e);return await T(s,d)?{corePath:c}:(r.onDownloadStart?.(),await G(s,e,d,r.runInstall),{corePath:c})}async function T(r,e){return await w(a.join(r,I))?(await Promise.all(e.map(o=>w(a.join(r,o))))).every(Boolean):!1}async function w(r){try{return await i.access(r),!0}catch{return!1}}async function G(r,e,t,o){let n=a.dirname(r);await i.mkdir(n,{recursive:!0});let s=a.join(n,`.tmp-${a.basename(r)}-${process.pid}-${Date.now()}`);await i.mkdir(s,{recursive:!0});try{let c=o??U().runInstall,d=S(e);await z(()=>c(d,{binDir:s}));for(let k of t)if(!await w(a.join(s,k)))throw new Error(`Foundry runtime download finished but required file is missing: ${k}. RID for ${e} may not be supported by the published packages.`);await i.writeFile(a.join(s,I),""),await Q(s,r,t)}catch(c){throw await i.rm(s,{recursive:!0,force:!0}).catch(()=>{}),c}}async function Q(r,e,t){try{await i.rename(r,e)}catch(o){let n=o.code;if(n==="ENOTEMPTY"||n==="EEXIST"||n==="EPERM"){if(await T(e,t)){await i.rm(r,{recursive:!0,force:!0}).catch(()=>{});return}await i.rm(e,{recursive:!0,force:!0}),await i.rename(r,e);return}throw o}}async function z(r){let e=process.stdout.write.bind(process.stdout),t=process.stderr.write.bind(process.stderr);process.stdout.write=(()=>!0),process.stderr.write=(()=>!0);try{return await r()}finally{process.stdout.write=e,process.stderr.write=t}}var E=class extends Error{constructor(t,o,n){super(t,n);this.code=o;this.name="VoiceBackendError"}code};function M(r){return r instanceof E?{message:r.message,code:r.code}:r instanceof Error?{message:r.message}:{message:String(r)}}function N(r){return r instanceof Error?r:new Error(String(r))}var X=16;function L(r){return R(r,new WeakSet,0)}function R(r,e,t){if(t>=X)return"<cause chain truncated>";if(typeof r=="object"&&r!==null){if(e.has(r))return"<cyclic cause>";e.add(r)}if(!(r instanceof Error))return String(r);let o=r.stack??`${r.name}: ${r.message}`;if(r.cause===void 0)return o;let n=R(r.cause,e,t+1);return`${o}
Caused by: ${n}`}var x=16*1024,P=class{constructor(e){this.port=e}port;writeLog(e,t){let o={kind:"log",level:e,message:Y(t)};try{this.port.postMessage(o)}catch{}return Promise.resolve()}outputPath(){return"<voice-worker>"}};function $(r,e=u){e.setLogWriter(new P(r))}function Y(r){return r.length<=x?r:`${r.slice(0,x)}\u2026 [truncated, ${r.length-x} more chars]`}if(!F)throw new Error("voice-installer.worker.js must be loaded as a worker thread.");var g=F;$(g);var Z=B??{};async function rr(){try{let e={kind:"ok",location:await _({cacheRoot:Z.cacheRoot,onDownloadStart:()=>{let t={kind:"download-started"};g.postMessage(t)}})};g.postMessage(e)}catch(r){let e=N(r);u.error(`[voice-installer worker] install failed: ${L(e)}`);let t={kind:"error",error:M(e)};g.postMessage(t)}finally{setImmediate(()=>process.exit(0))}}rr().catch(r=>{u.error(`[voice-installer worker] fatal: ${L(r)}`),process.exit(1)});//# sourceMappingURL=https://main.vscode-cdn.net/sourcemaps/474a349ad5b745e512ef86b864d1c74f7264dd7a/node_modules/@github/copilot-linux-x64/voice-installer.worker.js.map
