import{_ as e,c as t,d as n,f as r,g as i,h as a,n as o,p as ee,v as te,y as s}from"../assets/providers-C9Rmn9DV.js";var ne=[`vision`,`vl`,`omni`,`gpt-4o`,`gpt-4.1`,`gpt-4.5`,`gemini`,`claude-3`,`claude-sonnet-4`,`claude-opus-4`,`llava`,`pixtral`,`qwen-vl`,`mllama`],re=[`reason`,`r1`,`o1`,`o3`,`o4`,`qwq`,`thinking`,`deepseek-r1`],ie=e=>{let t=e.trim().toLowerCase();return ne.some(e=>t.includes(e))?`multimodal`:re.some(e=>t.includes(e))?`reasoning`:`text`},ae=e=>{let t=ie(e);return t===`multimodal`?`[M]`:t===`reasoning`?`[R]`:`[T]`},c=e=>`${ae(e)} ${e}`,l=document.getElementById(`root`),u=null,d=`providers`,f=null,p={},m=[],h=``,g=`Write a short connectivity check response.`,_=``,v=``,y=!1,b=``,x=``,S,C=``,w=``,T=[],E=!1,D=[],O=``,k=new Set,A={},oe=new Set([`application/json`,`application/xml`,`text/csv`,`text/markdown`,`text/plain`,`text/xml`]),se=[`text/*`,`application/json`,`application/pdf`,`image/gif`,`image/jpeg`,`image/png`,`image/webp`,`.csv`,`.json`,`.md`,`.txt`].join(`,`),j={es:`Escribe una respuesta corta para comprobar la conexion.`,en:`Write a short connectivity check response.`,fr:`Reply briefly to check the connection.`,de:`Write a short connectivity check response.`,pt:`Escreve uma resposta curta para verificar a ligacao.`,gl:`Escribe unha resposta curta para comprobar a conexion.`,ca:`Escriu una resposta curta per comprovar la connexio.`,eu:`Idatzi erantzun labur bat konexioa egiaztatzeko.`},ce=/^[a-p]{32}$/,M=e=>String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),N=(t,n)=>e(u?.locale??`en`,t,n),le=()=>Object.values(j),ue=e=>j[e]??j.en,P=e=>{le().includes(g)&&(g=ue(e))},F=e=>m.find(t=>t.provider===e);async function I(e){m=await o(e),await R(m.find(e=>e.provider===`webllm`)?.models??[])}async function L(){let e=!h&&u!==null;e&&(h=N(`loadingCapabilities`),Q()),E=!0;try{T=(await H({type:`runtime.capabilities`,requestId:crypto.randomUUID()})).providers,await R(T.find(e=>e.provider===`webllm`)?.models??[])}catch{T=[]}finally{E=!1,e&&(h=``,Q())}}async function R(e){if(e.length===0||!(`caches`in globalThis)){k=new Set;return}let t=new Set;try{let n=await caches.keys();for(let r of n){let n=await(await caches.open(r)).keys();for(let r of n){let n=decodeURIComponent(r.url),i=e.find(e=>n.includes(e));i&&t.add(i)}}}catch{k=new Set;return}k=t}async function z(e){let t=!h;t&&(h=N(`savingChanges`)),u=e,Q(),f&&!e.auditLog.some(e=>e.id===f)&&(f=null);try{await ee(e),await ye(e),await I(e),await L()}finally{t&&(h=``),Q()}}async function B(e,t){if(!h){h=e,Q();try{return await t()}finally{h=``,Q()}}}function de(){return h?`
    <div class="operation-status" role="status" aria-live="polite">
      <span class="spinner" aria-hidden="true"></span>
      <strong>${M(h)}</strong>
    </div>
  `:``}function V(e,t,n=``){return`
    <div class="field">
      <span>${M(e)}</span>
      ${t}
      ${n?`<small>${M(n)}</small>`:``}
    </div>
  `}function H(e){return new Promise((t,n)=>{try{chrome.runtime.sendMessage({type:`runtime.call`,requestId:e.requestId,app:{id:`options-page`},payload:e},e=>{let r=chrome.runtime.lastError?.message;if(r){n(Error(r));return}if(!e||e.type===`runtime.error`||e.type===`runtime.chat.error`){n(Error(e?.error?.message??`Runtime request failed.`));return}t(e)})}catch(e){n(e instanceof Error?e:Error(`Could not reach the extension runtime.`))}})}var fe=e=>e.type.startsWith(`text/`)||oe.has(e.type),pe=e=>new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`load`,()=>{t(String(r.result??``))}),r.addEventListener(`error`,()=>{n(Error(`Could not read ${e.name}.`))}),r.readAsText(e)}),me=e=>new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`load`,()=>{t(String(r.result??``).split(`,`)[1]??``)}),r.addEventListener(`error`,()=>{n(Error(`Could not read ${e.name}.`))}),r.readAsDataURL(e)});async function he(e){let t=e.type||`application/octet-stream`,n={id:crypto.randomUUID(),name:e.name,mimeType:t,sizeBytes:e.size};return fe(e)?{...n,textContent:await pe(e)}:{...n,base64Data:await me(e)}}async function ge(e){if(O=``,!e?.length)return;let t=!h;t&&(h=N(`loadingFiles`),Q());let n=Array.from(e);try{D=[...D,...await Promise.all(n.map(he))]}catch(e){O=e instanceof Error?e.message:N(`testFileReadError`)}finally{t&&(h=``)}Q()}function U(e,t,n,r=``){return`
    <section class="section">
      <div class="section-head">
        <div>
          <h2>${M(e)}</h2>
          ${t?`<p>${M(t)}</p>`:``}
        </div>
        ${r}
      </div>
      ${n}
    </section>
  `}function W(e,t,n=``){return`
    <label class="field">
      <span>${M(e)}</span>
      ${t}
      ${n?`<small>${M(n)}</small>`:``}
    </label>
  `}function G(e,t=`neutral`){return`<span class="badge ${t}">${M(e)}</span>`}function K(e){return e}function _e(e,t){if(!e)return null;try{let n=JSON.parse(e);return Array.isArray(n)&&n.length===t&&n.every(e=>typeof e==`string`)?n:null}catch{return null}}function q(e){return s.includes(e)}function ve(e){return ce.test(e)}async function ye(e){let t=Object.values(e.originPolicies).map(e=>e.origin).filter(ve);if(!t.length||!chrome.management?.get){A={};return}let n=await Promise.all(Array.from(new Set(t)).map(async e=>{try{return[e,(await chrome.management.get(e)).name]}catch{return null}}));A=Object.fromEntries(n.filter(Boolean))}function be(e){let t=_e(e,2);return{origin:t?.[0]??e,appId:t?.[1]??`unknown-app`}}function xe(e){let t=e.match(/(?:^|[-_])(\d+(?:\.\d+)?)(B|M)(?:[-_]|$)/i);if(!t)return N(`unknownSizeLabel`);let n=Number(t[1])*(t[2]?.toUpperCase()===`M`?.001:1),r=e.toLowerCase(),i=n*(r.includes(`q0f32`)?4:r.includes(`q0f16`)||r.includes(`bf16`)?2:r.includes(`q3`)?.42:r.includes(`q4`)?.55:1)*1.2;return i<1?`~${Math.max(1,Math.round(i*1024))} MB`:`~${i.toFixed(1)} GB`}function Se(e){let t={maximumFractionDigits:e>=1?2:4};return e>0&&e<1&&(t.minimumFractionDigits=2),`$${new Intl.NumberFormat(`en-US`,t).format(e)}`}function Ce(e,t=[]){let n=t.find(t=>t.id===e)?.pricing;if(!n)return``;let r=[n.inputPerMillionUsd===void 0?null:Se(n.inputPerMillionUsd),n.outputPerMillionUsd===void 0?null:Se(n.outputPerMillionUsd)].filter(Boolean);return r.length?`${r.join(`/`)}/1M`:``}function we(e,t=[]){let n=Ce(e,t);return n?`${c(e)} - ${n}`:c(e)}function Te(e,t,n=[]){return e===`webllm`?`${c(t)} · ${xe(t)} · ${k.has(t)?N(`downloadedLabel`):N(`notDownloadedLabel`)}`:we(t,n)}function J(e,t){let n=F(e),r=n?.models??[];return r.length?`
    <select class="input" data-provider-field="${e}:defaultModel">
      <option value="">${M(N(`selectDetectedModel`))}</option>
      ${r.map(r=>`<option value="${M(r)}" ${r===t?`selected`:``}>${M(Te(e,r,n?.modelDetails??[]))}</option>`).join(``)}
    </select>
  `:`<input class="input" data-provider-field="${e}:defaultModel" value="${M(t)}" placeholder="${M(N(`defaultModelPlaceholder`))}" />`}function Y(e,t,n,r){let i=F(e),a=i?.models.length??0,o=i?.available?`${a} model${a===1?``:`s`} detected`:i?.reason??N(`unavailable`);return U(t,n,`<div class="grid">${r}</div>`,G(o,i?.available?`success`:`warning`))}function Ee(e){return u?e===`lmstudio`?u.providers.lmstudio?.enabled===!0:u.providers[e]?.enabled!==!1:!1}function X(e){return`<label class="check-card"><span class="row"><input type="checkbox" data-provider-field="${e}:enabled" ${Ee(e)?`checked`:``}/><strong>${M(N(`enabled`))}</strong></span><small>${M(N(`providerEnabledHint`))}</small></label>`}function De(){return u?`<div class="provider-grid">
    ${Y(`openai`,`OpenAI`,N(`providerCardOpenai`),`${X(`openai`)}
       ${W(N(`apiKey`),`<input class="input" data-provider-field="openai:apiKey" value="${M(u.providers.openai?.apiKey??``)}" placeholder="sk-..." />`,N(`apiKeyStoredHint`))}
       ${W(N(`defaultModel`),J(`openai`,u.providers.openai?.defaultModel??``),N(`openaiDefaultModelHint`))}
       <div class="row"><button data-test-provider="openai">${M(N(`refreshModels`))}</button>${p.openai?`<small>${M(p.openai)}</small>`:``}</div>`)}
    ${Y(`openrouter`,`OpenRouter`,N(`providerCardOpenrouter`),`${X(`openrouter`)}
       ${W(N(`apiKey`),`<input class="input" data-provider-field="openrouter:apiKey" value="${M(u.providers.openrouter?.apiKey??``)}" placeholder="sk-or-v1-..." />`,N(`apiKeyStoredHint`))}
       ${W(N(`defaultModel`),J(`openrouter`,u.providers.openrouter?.defaultModel??``),N(`openrouterDefaultModelHint`))}
       <div class="row"><button data-test-provider="openrouter">${M(N(`refreshModels`))}</button>${p.openrouter?`<small>${M(p.openrouter)}</small>`:``}</div>`)}
    ${Y(`ollama`,`Ollama`,N(`providerCardOllama`),`${X(`ollama`)}
       ${W(N(`baseUrl`),`<input class="input" data-provider-field="ollama:baseUrl" value="${M(u.providers.ollama?.baseUrl??``)}" placeholder="http://localhost:11434" />`,N(`ollamaBaseUrlHint`))}
       ${W(N(`defaultModel`),J(`ollama`,u.providers.ollama?.defaultModel??``),N(`ollamaDefaultModelHint`))}
       <div class="row"><button data-test-provider="ollama">${M(N(`refreshModels`))}</button>${p.ollama?`<small>${M(p.ollama)}</small>`:``}</div>`)}
    ${Y(`lmstudio`,`LM Studio`,N(`providerCardLmstudio`),`${X(`lmstudio`)}
       ${W(N(`baseUrl`),`<input class="input" data-provider-field="lmstudio:baseUrl" value="${M(u.providers.lmstudio?.baseUrl??``)}" placeholder="http://localhost:1234/v1" />`,N(`lmstudioBaseUrlHint`))}
       ${W(N(`defaultModel`),J(`lmstudio`,u.providers.lmstudio?.defaultModel??``),N(`lmstudioDefaultModelHint`))}
       <div class="row"><button data-test-provider="lmstudio">${M(N(`refreshModels`))}</button>${p.lmstudio?`<small>${M(p.lmstudio)}</small>`:``}</div>`)}
    ${Y(`anthropic`,`Anthropic`,N(`providerCardAnthropic`),`${X(`anthropic`)}
       ${W(N(`apiKey`),`<input class="input" data-provider-field="anthropic:apiKey" value="${M(u.providers.anthropic?.apiKey??``)}" placeholder="sk-ant-..." />`,N(`anthropicApiHint`))}
       ${W(N(`defaultModel`),J(`anthropic`,u.providers.anthropic?.defaultModel??``),N(`anthropicModelHint`))}
       <div class="row"><button data-test-provider="anthropic">${M(N(`refreshStatus`))}</button>${p.anthropic?`<small>${M(p.anthropic)}</small>`:``}</div>`)}
    ${Y(`webllm`,`WebLLM`,N(`providerCardWebllm`),`${X(`webllm`)}
       ${W(N(`defaultModel`),J(`webllm`,u.providers.webllm?.defaultModel??``),N(`webllmDefaultModelHint`))}
       <div class="row"><button data-test-provider="webllm">${M(N(`refreshCatalog`))}</button>${p.webllm?`<small>${M(p.webllm)}</small>`:``}</div>`)}
  </div>`:``}function Oe(){if(!u)return``;let e=Object.values(u.originPolicies).sort((e,t)=>e.origin.localeCompare(t.origin)),t=new Set(te.map(r));return U(`${N(`aiTab`)} ${N(`authorizedCallersTitle`)}`,N(`availableProvidersHint`),`<div class="caller-list">
      ${e.map(e=>`
            <article class="caller-row">
              <div class="caller-origin">
                ${We(e.origin)}
                ${Ae(e)}
              </div>
              <div class="caller-actions">
                ${t.has(e.origin)?G(N(`defaultCaller`),`neutral`):``}
                ${ke(e.origin,e.enabled)}
                ${t.has(e.origin)?``:`<button data-delete-policy="${M(e.origin)}">${M(N(`remove`))}</button>`}
              </div>
            </article>
          `).join(``)}
    </div>`,`<button data-add-policy>${M(N(`addCaller`))}</button>`)}function ke(e,t){return`<label class="toggle-inline"><input type="checkbox" data-policy-flag="${M(e)}:enabled" ${t?`checked`:``}/><span>${M(N(`enabled`))}</span></label>`}function Ae(e){let t=new Set(e.allowedProviders),n=s.map(n=>`
      <label class="provider-chip">
        <input type="checkbox" data-policy-provider="${M(JSON.stringify([e.origin,n]))}" ${t.has(n)?`checked`:``}/>
        <span>${M(K(n))}</span>
      </label>
    `).join(``),r=e.allowedProviders.map(t=>`<option value="${M(t)}" ${e.defaultProvider===t?`selected`:``}>${M(K(t))}</option>`).join(``);return`
    <div class="policy-controls ai-policy-controls">
      <div>
        <small>${M(N(`allowedProvidersTitle`))}</small>
        <div class="provider-chip-list">${n}</div>
      </div>
      <label class="field compact-field">
        <span>${M(N(`defaultProvider`))}</span>
        <select class="input" data-policy-default-provider="${M(e.origin)}">
          <option value="">${M(N(`autoProvider`))}</option>
          ${r}
        </select>
      </label>
    </div>
  `}function je(){if(!u)return``;let e=Object.entries(u.appConfigs).map(([e,t])=>({key:e,config:t,...be(e)})).sort((e,t)=>e.origin.localeCompare(t.origin)||e.appId.localeCompare(t.appId)),t=e.length?`<div class="app-config-list">
        ${e.map(e=>`
              <article class="app-config-row">
                <div class="caller-origin">
                  <strong>${M(e.appId)}</strong>
                  <small>${M(e.origin)}</small>
                </div>
                <label class="field compact-field">
                  <span>${M(N(`provider`))}</span>
                  <select class="input" data-app-config-provider="${M(e.key)}">
                    <option value="">${M(N(`noProviderDefault`))}</option>
                    ${s.map(t=>`<option value="${M(t)}" ${e.config.provider===t?`selected`:``}>${M(K(t))}</option>`).join(``)}
                  </select>
                </label>
                <label class="field compact-field">
                  <span>${M(N(`model`))}</span>
                  <input class="input" data-app-config-model="${M(e.key)}" value="${M(e.config.model??``)}" placeholder="${M(N(`defaultModelPlaceholder`))}" />
                </label>
                <button data-delete-app-config="${M(e.key)}">${M(N(`remove`))}</button>
              </article>
            `).join(``)}
      </div>`:`<p>${M(N(`noAppDefaults`))}</p>`;return U(N(`appDefaultsTitle`),N(`appDefaultsDescription`),t)}function Me(){let e=(T.length?T:m).filter(e=>e.available);return U(N(`aiTestTitle`),N(`aiTestDescription`),`<div class="grid">
      ${V(N(`testPromptLabel`),`<textarea class="input textarea" data-test-prompt>${M(g)}</textarea>`)}
      <div class="split-fields">
        ${V(N(`testProviderLabel`),`<select class="input" data-test-provider>
            <option value="">${M(N(`testProviderAuto`))}</option>
            ${e.map(e=>`<option value="${e.provider}" ${e.provider===_?`selected`:``}>${M(K(e.provider))}</option>`).join(``)}
          </select>`,E?N(`loading`):``)}
        ${V(N(`testModelLabel`),Ne(),_?Fe(_):``)}
      </div>
      <div class="split-fields">
        ${V(N(`testAttachmentsLabel`),`<input class="input" type="file" data-test-files multiple accept="${M(se)}" />`,N(`testAttachmentsHint`))}
      </div>
      ${Pe()}
      <div class="row">
        <button data-run-ai-test ${y?`disabled`:``}>${M(N(y?`testRunning`:`testRun`))}</button>
      </div>
      ${y?`<div role="status" aria-live="polite" class="sr-only">${M(N(`testRunning`))}</div>`:``}
      ${O?`<p role="alert" class="error-text">${M(O)}</p>`:``}
      ${x?`<section class="test-panel test-panel-error" role="alert"><h3>${M(N(`testErrorTitle`))}</h3><pre>${M(x)}</pre></section>`:``}
      ${b||C||w?`<section class="test-panel" role="status" aria-live="polite">
              <div class="audit-kv">
                <span>${M(N(`provider`))}</span><strong>${M(C||`auto`)}</strong>
                <span>${M(N(`model`))}</span><strong>${M(w||`auto`)}</strong>
                <span>${M(N(`usageLabel`))}</span><strong>${M(He(S))}</strong>
              </div>
              <pre>${M(b||N(`noResponseBody`))}</pre>
            </section>`:``}
    </div>`)}function Ne(){let e=_?(T.length?T:m).find(e=>e.provider===_):void 0,t=e?.models??[];return t.length?`
    <select class="input" data-test-model>
      <option value="">${M(N(`launcherDefaultModel`))}</option>
      ${t.map(t=>`<option value="${M(t)}" ${t===v?`selected`:``}>${M(Te(_,t,e?.modelDetails??[]))}</option>`).join(``)}
    </select>
  `:`<input class="input" data-test-model value="${M(v)}" placeholder="${M(N(`defaultModelPlaceholder`))}" />`}function Pe(){return D.length?`
    <div class="attachment-list">
      ${D.map(e=>`
            <div class="attachment-row">
              <span>${M(e.name)}</span>
              <small>${M(e.mimeType)} · ${Math.ceil(e.sizeBytes/1024)} KB</small>
              <button data-remove-test-file="${M(e.id)}">${M(N(`remove`))}</button>
            </div>
          `).join(``)}
    </div>
  `:``}function Fe(e){let t=(T.length?T:m).find(t=>t.provider===e)?.models??[];return t.length?t.slice(0,3).join(`, `):``}function Ie(){if(!u)return``;let e=u.auditLog.length>0?u.auditLog.map(e=>{let t=f===e.id,n=e.response;return`
              <article class="audit-item ${t?`expanded`:``}">
                <button class="audit-summary" data-audit-entry="${e.id}" type="button" aria-expanded="${t}">
                  <span class="audit-title">
                    <strong>${M(e.origin)}</strong>
                    <small>${M(e.appId)}</small>
                  </span>
                  <span class="audit-provider">
                    <strong>${M(c(e.model))}</strong>
                    <small>${M(e.provider)} · ${e.cloud?`cloud`:`local`}</small>
                  </span>
                  <span class="audit-stats">
                    ${G(e.status,e.status===`success`?`success`:e.status===`aborted`?`neutral`:`warning`)}
                    <small>${M(Be(n?.durationMs))} · ${e.inputChars.toLocaleString()} / ${(e.outputChars??0).toLocaleString()} chars · ${(n?.charsPerSecond??0).toLocaleString()} c/s</small>
                    <small>${new Date(e.timestamp).toLocaleString()}</small>
                  </span>
                </button>
                ${t?Le(e):``}
              </article>
            `}).join(``):`<p>${M(N(`noCallsRecorded`))}</p>`;return U(N(`auditLogTitle`),N(`auditLogDescription`),`<div class="audit-list">${e}</div>`,`<button data-clear-audit>${M(N(`clearAuditLog`))}</button>`)}function Le(e){let t=e.request,n=e.response;return`
    <div class="audit-details">
      <div class="audit-grid">
        ${Z(N(`status`),G(e.status,e.status===`success`?`success`:e.status===`aborted`?`neutral`:`warning`),!0)}
        ${Z(N(`inputChars`),e.inputChars.toLocaleString())}
        ${Z(N(`outputChars`),(e.outputChars??0).toLocaleString())}
        ${Z(N(`duration`),Be(n?.durationMs))}
        ${Z(N(`speed`),`${(n?.charsPerSecond??0).toLocaleString()} c/s`)}
      </div>
      <div class="audit-panels">
        <section class="audit-panel">
          <h3>${M(N(`requestDetails`))}</h3>
          <div class="audit-kv">
            <span>${M(N(`provider`))}</span><strong>${M(t?.requestedProvider??`auto`)}</strong>
            <span>${M(N(`model`))}</span><strong>${M(t?.requestedModel??`auto`)}</strong>
            <span>${M(N(`messagesLabel`))}</span><strong>${t?.messageCount??0}</strong>
            <span>${M(N(`filesLabel`))}</span><strong>${t?.files.length??0}</strong>
            <span>${M(N(`responseFormatLabel`))}</span><strong>${M(t?.options.responseFormat??`text`)}</strong>
            <span>${M(N(`reasoningLabel`))}</span><strong>${t?.options.reasoning===!0?`true`:`false`}</strong>
          </div>
          ${Re(t?.files??[])}
          <pre>${M(ze(t?.messages??[]))}</pre>
        </section>
        <section class="audit-panel">
          <h3>${M(N(`responseDetails`))}</h3>
          <div class="audit-kv">
            <span>${M(N(`status`))}</span><strong>${M(e.status)}</strong>
            <span>${M(N(`errorCodeLabel`))}</span><strong>${M(e.errorCode??`-`)}</strong>
            <span>${M(N(`errorMessageLabel`))}</span><strong>${M(n?.errorMessage??`-`)}</strong>
            <span>${M(N(`usageLabel`))}</span><strong>${M(He(n?.usage))}</strong>
          </div>
          <pre>${M(n?.text||N(`noResponseBody`))}</pre>
        </section>
      </div>
    </div>
  `}function Z(e,t,n=!1){return`
    <div class="audit-metric">
      <small>${M(e)}</small>
      <strong>${n?String(t):M(t)}</strong>
    </div>
  `}function Re(e){return e.length===0?``:`
    <div class="audit-file-list" aria-label="${M(N(`filesLabel`))}">
      ${e.map(e=>`
            <span class="audit-file">
              <strong>${M(e.name)}</strong>
              <small>${M(e.mimeType||`application/octet-stream`)} · ${Ve(e.sizeBytes)}</small>
            </span>
          `).join(``)}
    </div>
  `}function ze(e){return e.length===0?N(`noRequestBody`):e.map(e=>`${e.role.toUpperCase()}\n${e.content}`).join(`

`)}function Be(e){return e?e<1e3?`${e.toLocaleString()} ms`:`${(e/1e3).toFixed(2)} s`:`-`}function Ve(e){return e<1024?`${e.toLocaleString()} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function He(e){return e?[e.inputTokens===void 0?null:`in ${e.inputTokens}`,e.outputTokens===void 0?null:`out ${e.outputTokens}`,e.totalTokens===void 0?null:`total ${e.totalTokens}`,e.estimatedCostUsd===void 0?null:`$${e.estimatedCostUsd}`].filter(Boolean).join(` | `):`-`}function Ue(){let e=[{id:`providers`,label:N(`providersTab`)},{id:`authorized`,label:N(`authorizedTab`)},{id:`test`,label:N(`testTab`)},{id:`audit`,label:N(`auditTab`)}];return`
    <nav class="subtabs" role="tablist" aria-label="${M(N(`aiTab`))}">
      ${e.map(e=>`<button role="tab" aria-selected="${e.id===d}" data-ai-tab="${e.id}" class="${e.id===d?`active`:``}">${M(e.label)}</button>`).join(``)}
    </nav>
    ${d===`providers`?`<div class="view-actions"><button data-refresh>${M(N(`refreshProviderSnapshot`))}</button></div>${De()}`:``}
    ${d===`authorized`?`${Oe()}${je()}`:``}
    ${d===`test`?Me():``}
    ${d===`audit`?Ie():``}
  `}function Q(){if(!u){l.innerHTML=`<main class="shell">${M(e(`en`,`loading`))}</main>`;return}l.innerHTML=`
    <main class="shell" data-busy="${h?`true`:`false`}" aria-busy="${h?`true`:`false`}">
      <style>${qe}</style>
      <div class="container">
        <header class="hero">
          <h1>${M(N(`runtimeGatewayConfiguration`))}</h1>
          <div class="hero-language">
            <select class="input" data-locale>${i.map(e=>`<option value="${e}" ${e===u.locale?`selected`:``}>${M(a(e))}</option>`).join(``)}</select>
          </div>
        </header>
        ${de()}
        ${Ue()}
      </div>
    </main>
  `}function We(e){if(!ve(e))return`<strong>${M(e)}</strong>`;let t=A[e];return t?`<strong>${M(t)}</strong><small>${M(e)}</small>`:`<strong>${M(e)}</strong><small>Extension ID</small>`}async function $(e,t){if(!u)return;let n=structuredClone(u),i=t(n.originPolicies[e]),a=r(i.origin);delete n.originPolicies[e],n.originPolicies[a]={...i,origin:a},await z(n)}async function Ge(e,t){if(!u)return;let n=structuredClone(u),r=t(n.appConfigs[e]??{});r.provider?n.appConfigs[e]=r:delete n.appConfigs[e],await z(n)}async function Ke(){let e=g.trim();if(!(!e||y)){y=!0,h=N(`testRunning`),x=``,b=``,S=void 0,C=``,w=``,Q();try{let t=await H({type:`runtime.chat`,requestId:crypto.randomUUID(),provider:_||void 0,model:v.trim()||void 0,messages:[{role:`user`,content:e}],files:D.length?D:void 0,options:{responseFormat:`text`}});b=t.text,S=t.usage,C=t.provider,w=t.model}catch(e){x=e instanceof Error?e.message:`Unknown runtime error.`}finally{y=!1,h=``,Q()}}}l.addEventListener(`click`,e=>{let n=e.target.closest(`button`);if(!n||!u)return;let i=n.dataset.aiTab!==void 0||n.dataset.auditEntry!==void 0;if(!(h&&!i)){if(n.dataset.aiTab){d=n.dataset.aiTab,d===`test`&&L().then(Q),Q();return}if(n.dataset.refresh!==void 0){B(N(`refreshingProviders`),async()=>{await I(u)});return}if(n.dataset.auditEntry){f=f===n.dataset.auditEntry?null:n.dataset.auditEntry,Q();return}if(n.dataset.clearAudit!==void 0){f=null,z({...u,auditLog:[]});return}if(n.dataset.testProvider){let e=n.dataset.testProvider;p={...p,[e]:N(`testingProvider`)},B(N(`testingProvider`),async()=>{let t=await o(u,{providerIds:[e]});m=[...m.filter(t=>t.provider!==e),...t];let n=t.find(t=>t.provider===e);p={...p,[e]:n?.available?N(`availableWithModels`,{count:n.models.length}):n?.reason??N(`unavailable`)}});return}if(n.dataset.runAiTest!==void 0){Ke();return}if(n.dataset.removeTestFile){D=D.filter(e=>e.id!==n.dataset.removeTestFile),O=``,Q();return}if(n.dataset.addPolicy!==void 0){let e=window.prompt(N(`addCallerPrompt`)),n=e?r(e):``;if(!n)return;let i=structuredClone(u);i.originPolicies[n]=t(n),z(i);return}if(n.dataset.deletePolicy){let e=structuredClone(u);delete e.originPolicies[n.dataset.deletePolicy],z(e);return}if(n.dataset.deleteAppConfig){let e=structuredClone(u);delete e.appConfigs[n.dataset.deleteAppConfig],z(e);return}}}),l.addEventListener(`change`,e=>{let t=e.target;if(u){if(t.dataset.locale!==void 0){let e=t.value;P(e),z({...u,locale:e});return}if(t.dataset.providerField){let[e,n]=t.dataset.providerField.split(`:`),r=structuredClone(u),i=r.providers[e]??{};i[n]=t instanceof HTMLInputElement&&t.type===`checkbox`?t.checked:t.value,r.providers[e]=i,z(r);return}if(t.dataset.testProvider!==void 0){_=t.value;let e=(T.length?T:m).find(e=>e.provider===_)?.models??[];v&&e.length&&!e.includes(v)&&(v=``),Q();return}if(t.dataset.testModel!==void 0){v=t.value;return}if(t.dataset.testFiles!==void 0){ge(t.files),t.value=``;return}if(t.dataset.policyFlag){let[e,n]=t.dataset.policyFlag.split(`:`);$(e,e=>({...e,[n]:t.checked}));return}if(t.dataset.policyProvider){let e=_e(t.dataset.policyProvider,2),n=e?.[0],r=e?.[1];if(!n||!r||!q(r))return;$(n,e=>{let n=new Set(e.allowedProviders);t.checked?n.add(r):n.delete(r);let i=Array.from(n);return{...e,allowedProviders:i,defaultProvider:e.defaultProvider&&i.includes(e.defaultProvider)?e.defaultProvider:void 0}});return}if(t.dataset.policyDefaultProvider!==void 0){let e=t.dataset.policyDefaultProvider,n=t.value;$(e,e=>({...e,defaultProvider:n&&q(n)&&e.allowedProviders.includes(n)?n:void 0}));return}if(t.dataset.appConfigProvider){let e=t.dataset.appConfigProvider,n=t.value;Ge(e,e=>n&&q(n)?{provider:n,...e.model?{model:e.model}:{}}:{});return}if(t.dataset.appConfigModel){let e=t.dataset.appConfigModel,n=t.value.trim();Ge(e,e=>({...e,...n?{model:n}:{model:void 0}}));return}}}),l.addEventListener(`input`,e=>{let t=e.target;if(t.dataset.testPrompt!==void 0){g=t.value;return}t.dataset.testModel!==void 0&&(v=t.value)});var qe=`
  *{box-sizing:border-box} body{margin:0} .shell{font-family:"Segoe UI","Trebuchet MS",sans-serif;background:#f4f7fb;color:#18212f;min-height:100vh;padding:20px}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.container{max-width:1120px;margin:0 auto}.hero,.section{background:#fff;border:1px solid #d7dee8;border-radius:14px;padding:18px;margin-bottom:16px}.hero{display:flex;justify-content:space-between;align-items:flex-start;gap:16px;flex-wrap:wrap}.hero h1{margin:0;font-size:30px;line-height:1.1}.hero-language{min-width:220px;max-width:280px;width:100%}.operation-status{position:sticky;top:10px;z-index:5;display:flex;align-items:center;gap:10px;width:max-content;max-width:100%;margin:0 0 14px auto;padding:10px 12px;border:1px solid #b8cdf4;border-radius:10px;background:#eef5ff;color:#14366f;box-shadow:0 8px 18px rgba(20,33,61,.12)}.spinner{width:16px;height:16px;border:2px solid #b8cdf4;border-top-color:#1f6feb;border-radius:50%;animation:spin .8s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.shell[data-busy="true"] button:not([role="tab"]):not(.audit-summary){cursor:wait;opacity:.72}.section-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;flex-wrap:wrap;margin-bottom:14px}.section-head p{margin:.35rem 0 0}.field small,.section p,small{color:#5a6576;line-height:1.45}.error-text{margin:0;color:#9a1b1b;font-weight:600}.tabs,.subtabs,.view-actions,.row,.split,.caller-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.tabs{margin-bottom:14px}.subtabs{margin-bottom:12px;padding:10px;border:1px solid #d7dee8;border-radius:12px;background:#fff}.subtabs button{padding:8px 12px}.view-actions{justify-content:flex-end;margin-bottom:16px}.split{justify-content:space-between}.split-fields{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px}.grid{display:grid;gap:14px}.provider-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:16px}.check-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px}.caller-list,.audit-list,.attachment-list{display:grid;gap:8px}.caller-row,.attachment-row{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:12px;align-items:center;padding:10px 12px;border:1px solid #d7dee8;border-radius:10px;background:#fbfcfe}.caller-row{grid-template-columns:minmax(0,1fr) auto}.caller-origin{min-width:0}.caller-origin strong,.caller-origin small,.attachment-row span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attachment-row small{white-space:nowrap}.caller-actions{justify-content:flex-end}.toggle-inline{display:inline-flex;align-items:center;gap:8px;color:#324155;font-size:13px;font-weight:600}.toggle-inline input{margin:0}.audit-item,.test-panel{border:1px solid #d7dee8;border-radius:10px;background:#fbfcfe;overflow:hidden}.test-panel{padding:12px;background:#fff}.test-panel h3{margin:0 0 10px}.test-panel-error{border-color:#e2b4b4;background:#fff7f7}.audit-summary{width:100%;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:12px;align-items:center;padding:12px;background:#fbfcfe;color:#18212f;border:none;border-radius:0;text-align:left}.audit-summary:not(.active){border-color:transparent}.audit-summary-main,.audit-summary-meta,.audit-grid,.audit-panels,.audit-kv{display:grid;gap:6px}.audit-summary-main{min-width:0}.audit-summary-main strong,.audit-summary-main small{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.audit-summary-meta{justify-items:end}.audit-details{padding:0 12px 12px}.audit-grid{grid-template-columns:repeat(auto-fit,minmax(140px,1fr));margin-bottom:12px}.audit-panels{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.audit-panel{display:grid;gap:10px;padding:12px;border:1px solid #d7dee8;border-radius:10px;background:#fff}.audit-panel h3,.section h2{margin:0}.audit-kv{grid-template-columns:max-content minmax(0,1fr);column-gap:10px;align-items:center}.audit-panel pre,.test-panel pre{margin:0;padding:12px;border:1px solid #d7dee8;border-radius:10px;background:#f8fafc;color:#18212f;white-space:pre-wrap;overflow:auto;max-height:280px}.field,.check-card{display:grid;gap:6px}.field>span{font-size:13px;font-weight:700}.input{width:100%;padding:10px 12px;border:1px solid #d7dee8;border-radius:10px;background:#fff;color:#18212f;font-size:14px}.textarea{min-height:180px;resize:vertical;font-family:inherit}button{border:1px solid #1f6feb;border-radius:10px;background:#1f6feb;color:white;padding:10px 14px;cursor:pointer;font-weight:600}button:disabled{cursor:wait;opacity:.7}button:not(.active){background:#edf4ff;color:#1f6feb;border-color:#c5d8fb}button.active{background:#1f6feb;color:#fff;border-color:#1f6feb}.check-card{padding:12px;border:1px solid #d7dee8;border-radius:10px;background:#fbfcfe}.badge{border-radius:999px;padding:5px 10px;font-size:12px;font-weight:600}.badge.success{background:#e8f6ee;color:#17633d}.badge.warning{background:#fff3e5;color:#9a4a0a}.badge.neutral{background:#eef2f7;color:#324155}.code-line{display:block;margin:4px 0}.list-row{border-top:1px solid #d7dee8;padding-top:10px}@media(max-width:760px){.hero{align-items:stretch}.hero-language{max-width:none}.operation-status{width:100%;margin-right:0}.view-actions{justify-content:flex-start}.caller-row,.attachment-row,.audit-summary,.audit-panels{grid-template-columns:1fr}.caller-actions,.audit-summary-meta{justify-content:flex-start}.audit-kv{grid-template-columns:1fr}.section-head{align-items:stretch}}
  .policy-controls{display:grid;grid-template-columns:minmax(0,1fr) minmax(190px,240px);gap:12px;margin-top:10px}.provider-chip-list{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}.provider-chip{display:inline-flex;align-items:center;gap:6px;padding:6px 8px;border:1px solid #d7dee8;border-radius:8px;background:#fff;font-size:13px;font-weight:600;color:#324155}.provider-chip input{margin:0}.compact-field{gap:4px}.compact-field .input{padding:8px 10px}.app-config-list{display:grid;gap:8px}.app-config-row{display:grid;grid-template-columns:minmax(160px,1fr) minmax(140px,190px) minmax(180px,240px) auto;gap:12px;align-items:end;padding:10px 12px;border:1px solid #d7dee8;border-radius:10px;background:#fbfcfe}.app-config-row small{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}@media(max-width:760px){.policy-controls,.app-config-row{grid-template-columns:1fr}.app-config-row{align-items:stretch}}
  .audit-summary{grid-template-columns:minmax(0,1.25fr) minmax(180px,.85fr) minmax(220px,1fr);background:#fff}
  .audit-summary:hover{background:#f6faff}
  .audit-title,.audit-provider,.audit-stats,.audit-grid,.audit-panels,.audit-kv{display:grid;gap:6px}
  .audit-title,.audit-provider,.audit-stats{min-width:0}
  .audit-title strong,.audit-title small,.audit-provider strong,.audit-provider small,.audit-stats small,.audit-file strong,.audit-file small{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .audit-provider small,.audit-stats small{color:#5a6576;font-weight:500}
  .audit-stats{justify-items:end}
  .audit-grid{grid-template-columns:repeat(auto-fit,minmax(128px,1fr))}
  .audit-metric{display:grid;gap:4px;padding:10px;border:1px solid #d7dee8;border-radius:10px;background:#fff}
  .audit-metric strong{font-size:16px;line-height:1.2}
  .audit-metric strong .badge{display:inline-flex;width:max-content}
  .audit-file-list{display:flex;gap:8px;flex-wrap:wrap}
  .audit-file{display:grid;gap:2px;max-width:100%;min-width:160px;padding:8px 10px;border:1px solid #d7dee8;border-radius:10px;background:#f8fafc}
  .audit-file strong{font-size:13px}
  .audit-file small{font-size:12px}
  @media(max-width:760px){.audit-summary{grid-template-columns:1fr}.audit-stats{justify-items:start}}
`;(async()=>{u=await n(),P(u.locale),await ye(u),await I(u),await L(),Q()})();