@nextclaw/ui 0.25.1 → 0.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/.vite/manifest.json +190 -190
  3. package/dist/assets/{account-panel-QhOMbAQP.js → account-panel-BXTCFv7d.js} +1 -1
  4. package/dist/assets/{api-BWFOIoUm.js → api-DqzQ-_3w.js} +1 -1
  5. package/dist/assets/{app-data-BnrEdmg2.js → app-data-C54N2p8b.js} +1 -1
  6. package/dist/assets/app-presenter-provider-V0xnU_Wb.js +115 -0
  7. package/dist/assets/{appearance-settings-page-C5z5sOkC.js → appearance-settings-page-83T2AtVm.js} +1 -1
  8. package/dist/assets/{channels-list-page-CzXYZZtK.js → channels-list-page-Bv7CVSqV.js} +1 -1
  9. package/dist/assets/{config-split-page-CxLWGwdt.js → config-split-page-DqAXKLmG.js} +1 -1
  10. package/dist/assets/{confirm-dialog-BWS7gA_z.js → confirm-dialog-BTKCWMn6.js} +1 -1
  11. package/dist/assets/{desktop-capabilities-page-BJNGkq4q.js → desktop-capabilities-page-zLzCSB7A.js} +1 -1
  12. package/dist/assets/{desktop-update-config-7tBum3MA.js → desktop-update-config-PmofcFf6.js} +1 -1
  13. package/dist/assets/{doc-browser-BNiqa-zm.js → doc-browser-BJrre2S_.js} +1 -1
  14. package/dist/assets/doc-browser-BPqA-zQx.js +1 -0
  15. package/dist/assets/{doc-browser-context-Dp0dEMyT.js → doc-browser-context-TILuCY5c.js} +1 -1
  16. package/dist/assets/{extensions-WWEYpaUh.js → extensions-CVUFK6Jj.js} +1 -1
  17. package/dist/assets/{i18n-ClHx6jwj.js → i18n-20rSH40D.js} +2 -2
  18. package/dist/assets/{i18n-provider-C1NxogO4.js → i18n-provider-BPRq6S7O.js} +1 -1
  19. package/dist/assets/{keyboard-shortcuts-settings-page-CS9BFOBW.js → keyboard-shortcuts-settings-page-CkQbSKwI.js} +1 -1
  20. package/dist/assets/login-page-Dlyvp-81.js +1 -0
  21. package/dist/assets/{login-page-CL0SrBCf.js → login-page-f8qQ4xKY.js} +1 -1
  22. package/dist/assets/main-D2dWy8fM.css +1 -0
  23. package/dist/assets/main-i18n-catalog.config-DZ-5ollN.js +1 -0
  24. package/dist/assets/{main-CvVBCOlN.js → main-ky5Efhq1.js} +2 -2
  25. package/dist/assets/{mcp-marketplace-page-D75hPmzO.js → mcp-marketplace-page-FfIfEo6w.js} +1 -1
  26. package/dist/assets/mcp-marketplace-page-sH7VptN_.js +1 -0
  27. package/dist/assets/{model-config-page-DFfcV9lu.js → model-config-page-Bcm6-pCX.js} +1 -1
  28. package/dist/assets/panel-app-i18n-catalog.config-p3qAY_Eq.js +1 -0
  29. package/dist/assets/{panelStandalone-D2CqTyi_.js → panelStandalone-By-6dDXS.js} +2 -2
  30. package/dist/assets/{privacy-settings-page-CE-xF9bo.js → privacy-settings-page-B1sHLAc1.js} +1 -1
  31. package/dist/assets/{projects-BF0wpY4X.js → projects-O3GTERwP.js} +1 -1
  32. package/dist/assets/{provider-scoped-model-input-BvZitHkT.js → provider-scoped-model-input-BQsugx1v.js} +1 -1
  33. package/dist/assets/{providers-config-page-cDeyluVG.js → providers-config-page-BDEdHJbw.js} +1 -1
  34. package/dist/assets/{pwa-dXn0s_lD.js → pwa-D_nZUwG0.js} +1 -1
  35. package/dist/assets/remote-CFWp4wyH.js +1 -0
  36. package/dist/assets/{runtime-config-page-DNo4dzS1.js → runtime-config-page-BHTKwgDi.js} +1 -1
  37. package/dist/assets/{search-config-page-CA0HxVy0.js → search-config-page-DWKlMHgH.js} +1 -1
  38. package/dist/assets/{secrets-config-page-iT1wamQp.js → secrets-config-page-DiQL088Y.js} +1 -1
  39. package/dist/assets/security-config-DmTDKKY4.js +1 -0
  40. package/dist/assets/{service-apps-panel-CU0tFrqT.js → service-apps-panel-CEnyYsQp.js} +1 -1
  41. package/dist/assets/{tag-chip-CY0Hqk_l.js → tag-chip-B1AYPOKL.js} +1 -1
  42. package/dist/assets/{theme-provider-BvpXGXWH.js → theme-provider-DzvAi3pe.js} +1 -1
  43. package/dist/assets/{use-config-C8ZkQiTc.js → use-config-BEdbtpD4.js} +1 -1
  44. package/dist/assets/{use-desktop-capabilities-DR9snbeo.js → use-desktop-capabilities-BkuRd2cY.js} +1 -1
  45. package/dist/index.html +18 -18
  46. package/dist/panel-standalone.html +5 -5
  47. package/package.json +4 -4
  48. package/src/features/chat/features/conversation/components/__tests__/session-voice-input.test-utils.ts +18 -5
  49. package/src/features/chat/features/conversation/components/chat-voice-input-panel.tsx +37 -14
  50. package/src/features/chat/features/conversation/components/session-conversation-input.tsx +3 -3
  51. package/src/features/chat/features/conversation/hooks/__tests__/use-chat-voice-input.test.tsx +116 -10
  52. package/src/features/chat/features/conversation/hooks/use-chat-voice-input.ts +15 -2
  53. package/src/features/chat/managers/chat-voice-input.manager.ts +26 -4
  54. package/src/features/chat/utils/chat-voice-permissions.utils.test.ts +36 -0
  55. package/src/features/chat/utils/chat-voice-permissions.utils.ts +31 -0
  56. package/src/shared/lib/i18n/locales/en-US/chat.json +18 -3
  57. package/src/shared/lib/i18n/locales/zh-CN/chat.json +18 -3
  58. package/dist/assets/app-presenter-provider-CDRBc_lQ.js +0 -115
  59. package/dist/assets/doc-browser-DZDqghNc.js +0 -1
  60. package/dist/assets/login-page-Dq5nPUCU.js +0 -1
  61. package/dist/assets/main-CLwCjK9U.css +0 -1
  62. package/dist/assets/main-i18n-catalog.config-D4qFo4OB.js +0 -1
  63. package/dist/assets/mcp-marketplace-page-CATnpZ2Q.js +0 -1
  64. package/dist/assets/panel-app-i18n-catalog.config-oUwmxoE7.js +0 -1
  65. package/dist/assets/remote-CV5wQVVj.js +0 -1
  66. package/dist/assets/security-config-B38PLI3M.js +0 -1
@@ -1 +1 @@
1
- import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n,t as r}from"./utils-CBZPzC_b.js";import{Gt as i,Qt as a,Ut as o,Wt as s,Yt as c,hn as l,jn as u,vn as d}from"./api-BWFOIoUm.js";import{l as f,s as p}from"./i18n-ClHx6jwj.js";import{n as m,t as h}from"./logo-badge-C-5-zim6.js";import{t as g}from"./createLucideIcon-BNKf0_kc.js";import{t as _}from"./search-CUe41wjm.js";import{t as v}from"./chevron-down-BL-yMYcX.js";import{n as y,t as b}from"./ellipsis-C5YXdOUx.js";import{a as x,i as S,n as C,r as w,t as T}from"./select-CG5YWnwe.js";import{t as E}from"./circle-alert-lSa3LRvS.js";import{t as D}from"./eye-C84inPcV.js";import{i as O,t as k}from"./use-viewport-layout-BS18drMT.js";import{t as A}from"./loader-circle-K1BDdHR5.js";import{t as j}from"./plus-LA8-jpxP.js";import{t as M}from"./refresh-cw-h9Xq3LY3.js";import{t as N}from"./settings-2-CE3ELQyk.js";import{n as P,t as F}from"./confirm-dialog-BWS7gA_z.js";import{t as I}from"./trash-2-BPPYt2NV.js";import{t as L}from"./x-DdXOqLnX.js";import{t as R}from"./host-capabilities-B107nwS3.js";import{i as z,r as B,t as V}from"./popover-NkrFlWHp.js";import{a as H,c as ee,l as U,o as W,t as te}from"./provider-models-hrHMcHqg.js";import{a as G,c as K,d as q,f as ne,h as re,i as ie,l as ae,m as oe,o as se,p as ce,r as le,y as ue}from"./use-config-C8ZkQiTc.js";import{t as de}from"./form-actions-BRESe-m_.js";import{t as J}from"./config-hints-B_C9DAp5.js";import{a as fe,c as pe,i as me,l as he,n as ge,o as _e,r as ve,s as ye}from"./config-split-page-CxLWGwdt.js";var be=g(`CircleDotDashed`,[[`path`,{d:`M10.1 2.18a9.93 9.93 0 0 1 3.8 0`,key:`1qdqn0`}],[`path`,{d:`M17.6 3.71a9.95 9.95 0 0 1 2.69 2.7`,key:`1bq7p6`}],[`path`,{d:`M21.82 10.1a9.93 9.93 0 0 1 0 3.8`,key:`1rlaqf`}],[`path`,{d:`M20.29 17.6a9.95 9.95 0 0 1-2.7 2.69`,key:`1xk03u`}],[`path`,{d:`M13.9 21.82a9.94 9.94 0 0 1-3.8 0`,key:`l7re25`}],[`path`,{d:`M6.4 20.29a9.95 9.95 0 0 1-2.69-2.7`,key:`1v18p6`}],[`path`,{d:`M2.18 13.9a9.93 9.93 0 0 1 0-3.8`,key:`xdo6bj`}],[`path`,{d:`M3.71 6.4a9.95 9.95 0 0 1 2.7-2.69`,key:`1jjmaz`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),xe=g(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),Y=e(n(),1),Se={providerId:``,providerType:null,isBuiltInType:!1,isCustom:!0,enabled:!0,displayName:``,apiKeySet:!1,apiKeyMasked:void 0,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelConfig:{}};function X(e){if(!e)return null;let t=Object.entries(e).map(([e,t])=>[e.trim(),t]).filter(([e])=>e.length>0);return t.length===0?null:Object.fromEntries(t)}function Ce(e,t){let n=X(e),r=X(t);if(n===null&&r===null)return!0;if(!n||!r)return!1;let i=Object.entries(n).sort(([e],[t])=>e.localeCompare(t)),a=Object.entries(r).sort(([e],[t])=>e.localeCompare(t));return i.length===a.length?i.every(([e,t],n)=>e===a[n][0]&&t===a[n][1]):!1}function Z(e){if(!e||e.length===0)return[];let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function we(e,t){let n=e.trim();if(!n||!t.trim())return n;let r=`${t.trim()}/`;return n.startsWith(r)?n.slice(r.length):n}function Q(e,t){let n=e.trim();if(!n)return``;for(let e of t){let t=e.trim();t&&(n=we(n,t))}return n.trim()}function Te(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}function Ee(e,t){return Z(t)}function De(e,t){return Z(e).map(e=>{let n=e.trim();return!n||n.startsWith(`${t}/`)?n:`${t}/${n}`})}function Oe(e,t){let n=new Set(t.map(e=>e.trim()).filter(Boolean)),r={};for(let[t,i]of Object.entries(e)){if(!n.has(t))continue;let e={},a=ee(i.thinking?.supported);if(a.length>0){let t=U(i.thinking?.default);e.thinking=t&&a.includes(t)?{supported:a,default:t}:{supported:a}}i.vision===!0&&(e.vision=!0),(e.thinking||e.vision===!0)&&(r[t]=e)}return r}function ke(e,t,n){return{...W(e,n),...W(t,n)}}function Ae(e,t){let n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;for(let i=0;i<n.length;i+=1){let a=n[i];if(a!==r[i])return!1;let o=e[a],s=t[a];if(!o||!s||!Te([...o.thinking?.supported??[]].sort(),[...s.thinking?.supported??[]].sort())||(o.thinking?.default??null)!==(s.thinking?.default??null)||(o.vision??!1)!==(s.vision??!1))return!1}return!0}function je(e){return e.providerName?e.apiKey.trim().length>0||e.apiBase.trim()!==e.currentApiBase.trim()||!Ce(e.extraHeaders,e.currentHeaders)||e.supportsWireApi&&e.wireApi!==e.currentWireApi||!Te(e.models,e.currentEditableModels)||!Ae(e.modelConfig,e.currentModelConfig)||e.providerDisplayName.trim()!==e.effectiveDisplayName:!1}function Me(e){let t={},n=e.apiKey.trim(),r=e.apiBase.trim(),i=X(e.extraHeaders),a=e.providerDisplayName.trim();return a!==e.effectiveDisplayName&&(t.displayName=a.length>0?a:null),n.length>0&&(t.apiKey=n),r!==e.currentApiBase.trim()&&(t.apiBase=r.length>0&&r!==e.defaultApiBase?r:null),Ce(i,e.currentHeaders)||(t.extraHeaders=i),e.supportsWireApi&&e.wireApi!==e.currentWireApi&&(t.wireApi=e.wireApi),Te(e.models,e.currentEditableModels)||(t.models=De(e.models,e.providerName??``)),Ae(e.modelConfig,e.currentModelConfig)||(t.modelConfig=Oe(e.modelConfig,e.models)),t}function Ne(e){let t=Q(e.models.find(e=>e.trim().length>0)??``,e.providerModelAliases),n={...Pe(e),model:t||null};return e.supportsWireApi&&(n.wireApi=e.wireApi),n}function Pe(e){let t={apiBase:e.apiBase.trim(),extraHeaders:X(e.extraHeaders)};return e.apiKey.trim().length>0&&(t.apiKey=e.apiKey.trim()),t}function Fe(e){return p(e===`off`?`chatThinkingLevelOff`:e===`minimal`?`chatThinkingLevelMinimal`:e===`low`?`chatThinkingLevelLow`:e===`medium`?`chatThinkingLevelMedium`:e===`high`?`chatThinkingLevelHigh`:e===`adaptive`?`chatThinkingLevelAdaptive`:`chatThinkingLevelXhigh`)}function Ie(e){let{providerName:t,methods:n,defaultMethodId:r,language:i}=e;if(n.length===0)return``;let a=new Map;for(let e of n){let t=e.id.trim();t&&a.set(t.toLowerCase(),t)}let o=(...e)=>{for(let t of e){let e=a.get(t.toLowerCase());if(e)return e}},s=r?.trim();if(t===`minimax-portal`){if(i===`zh`)return o(`cn`,`china-mainland`)??o(s??``)??n[0]?.id??``;if(i===`en`)return o(`global`,`intl`,`international`)??o(s??``)??n[0]?.id??``}if(s){let e=o(s);if(e)return e}return i===`zh`?o(`cn`)??n[0]?.id??``:i===`en`?o(`global`)??n[0]?.id??``:n[0]?.id??``}function Le(e){let{required:t,hasDefault:n,optionCount:r}=e;return t&&n&&r>1&&r<=3}function Re(e,t,n){let r=Q(t,n);return r?e.includes(r)?{models:e,draft:``}:{models:[...e,r],draft:``}:{models:e,draft:t}}function ze(e,t,n){let r=[...e],i=new Set(e);for(let e of t){let t=Q(e,n);t&&!i.has(t)&&(i.add(t),r.push(t))}return{models:r,addedCount:r.length-e.length}}function Be(e,t,n){return ze(e,t,n).models.slice(e.length)}function Ve(e,t,n){let r={...t};return delete r[n],{models:e.filter(e=>e!==n),modelConfig:r}}function He(e,t,n){let r=e[t],i=r?.thinking?.supported??[],a=i.includes(n)?i.filter(e=>e!==n):te.filter(e=>e===n||i.includes(e)),o=r?.thinking?.default&&a.includes(r.thinking.default)?r.thinking.default:void 0,s={...r,thinking:a.length>0?o?{supported:a,default:o}:{supported:a}:void 0},c={...e};return s.thinking||s.vision===!0?c[t]=s:delete c[t],c}function Ue(e,t,n){let r=e[t],i=r?.thinking;return!i||i.supported.length===0||n&&!i.supported.includes(n)?e:{...e,[t]:{...r,thinking:n?{supported:i.supported,default:n}:{supported:i.supported}}}}function We(e,t,n){let r={...e[t],vision:n?!0:void 0},i={...e};return r.thinking||r.vision===!0?i[t]=r:delete i[t],i}function Ge(e){let{providerName:t,providerSpec:n,language:r}=e,i=n?.auth,a=i?.methods??[];return{providerAuth:i,providerAuthMethodOptions:a.map(e=>({value:e.id,label:e.label?.[r]||e.label?.en||e.id})),providerAuthMethods:a,preferredAuthMethodId:Ie({providerName:n?.providerType??t,methods:a,defaultMethodId:i?.defaultMethodId,language:r}),shouldUseAuthMethodPills:Le({required:i?.kind===`device_code`,hasDefault:!!i?.defaultMethodId?.trim(),optionCount:a.length})}}function Ke(e,t){let n=!!e?.supportsWireApi||t,r=(e?.wireApiOptions||[`auto`,`chat`,`responses`]).map(e=>({value:e,label:p(e===`chat`?`wireApiChat`:e===`responses`?`wireApiResponses`:`wireApiAuto`)}));return{shouldUseWireApiPills:Le({required:n,hasDefault:typeof e?.defaultWireApi==`string`&&e.defaultWireApi.length>0,optionCount:r.length}),supportsWireApi:n,wireApiSelectOptions:r}}function qe(e){let{providerName:t,providersView:n,templatesView:r,schema:i,language:a}=e,o=t?n?.providers[t]:null,s=r?.providerTemplates.find(e=>e.providerType===o?.providerType),c=o??Se,l=i?.uiHints,u=!!o?.isCustom,d=t?J(`providers.${t}.apiKey`,l):void 0,f=t?J(`providers.${t}.apiBase`,l):void 0,m=t?J(`providers.${t}.extraHeaders`,l):void 0,h=t?J(`providers.${t}.wireApi`,l):void 0,g=s?.displayName||o?.displayName||t||``,_=(c.displayName||``).trim()||g,v=c.enabled!==!1,y=u||s?.supportsModelDiscovery===!0,b=Z([s?.modelPrefix||s?.providerType||``,t||``]),x=s?.defaultApiBase||``,S=c.apiBase||x,C=X(c.extraHeaders||null),w=c.wireApi||s?.defaultWireApi||`auto`,T=Ee(Z((s?.defaultModels??[]).map(e=>Q(e,b))),Z((c.models??[]).map(e=>Q(e,b)))),E=Oe(ke(s?.modelConfig,c.modelConfig,b),T),D=s?.apiBaseHelp?.[a]||s?.apiBaseHelp?.en||f?.help||p(`providerApiBaseHelp`),O=Ge({providerName:t,providerSpec:s,language:a}),k=Ke(s,u);return{apiBaseHelpText:D,apiBaseHint:f,apiKeyHint:d,currentApiBase:S,currentEditableModels:T,currentEnabled:v,currentHeaders:C,currentModelConfig:E,currentWireApi:w,defaultApiBase:x,defaultDisplayName:g,effectiveDisplayName:_,extraHeadersHint:m,...O,providerConfig:o,providerModelAliases:b,resolvedProviderConfig:c,supportsModelDiscovery:y,wireApiHint:h,...k}}function Je(e){let{providerName:t,providerAuth:n,resolvedAuthMethodId:r}=e,i=u(),a=oe(),o=ae(),s=K(),[c,l]=(0,Y.useState)(``),[f,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),_=(0,Y.useRef)(null),v=(0,Y.useCallback)(()=>{_.current!==null&&(window.clearTimeout(_.current),_.current=null)},[]),y=(0,Y.useCallback)((e,n)=>{v(),_.current=window.setTimeout(()=>{(async()=>{if(t)try{let r=await o.mutateAsync({provider:t,data:{sessionId:e}});if(r.status===`pending`){g(p(`providerAuthWaitingBrowser`)),y(e,r.nextPollMs??n);return}if(r.status===`authorized`){m(null),v(),g(p(`providerAuthCompleted`)),d.success(p(`providerAuthCompleted`)),i.invalidateQueries({queryKey:[`config`]}),i.invalidateQueries({queryKey:[`providers`]});return}m(null),v(),g(r.message||`Authorization ${r.status}.`),d.error(r.message||`Authorization ${r.status}.`)}catch(e){m(null),v();let t=e instanceof Error?e.message:String(e);g(t),d.error(`Authorization failed: ${t}`)}})()},Math.max(1e3,n))},[v,o,t,i]),b=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{l(t),g(``);let e=await a.mutateAsync({provider:t,data:r?{methodId:r}:{}});if(!e.sessionId||!e.verificationUri)throw Error(p(`providerAuthStartFailed`));m(e.sessionId),g(`${p(`providerAuthOpenPrompt`)}${e.userCode}${p(`providerAuthOpenPromptSuffix`)}`),await R.openExternalUrl(e.verificationUri),y(e.sessionId,e.intervalMs)}catch(e){let t=e instanceof Error?e.message:String(e);m(null),v(),g(t),d.error(`${p(`providerAuthStartFailed`)}: ${t}`)}},[v,n?.kind,t,r,y,a]),x=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{l(t),v(),m(null);let e=await s.mutateAsync({provider:t});g(`${p(`providerAuthImportStatusPrefix`)}${e.expiresAt?` (expires: ${e.expiresAt})`:``}`),d.success(p(`providerAuthImportSuccess`)),i.invalidateQueries({queryKey:[`config`]}),i.invalidateQueries({queryKey:[`providers`]})}catch(e){let t=e instanceof Error?e.message:String(e);g(t),d.error(`${p(`providerAuthImportFailed`)}: ${t}`)}},[v,s,n?.kind,t,i]);return(0,Y.useEffect)(()=>{v()},[v,t]),(0,Y.useEffect)(()=>()=>v(),[v]),{authSessionId:c===t?f:null,authStatusMessage:c===t?h:``,importAuthFromCli:x,importPending:s.isPending,startAuth:b,startPending:a.isPending}}function Ye(e){let{providerName:t,apiKey:n,apiKeyRequired:r,apiKeySet:i,apiBase:a,extraHeaders:o,supportsWireApi:s,wireApi:c,models:u,providerModelAliases:f}=e,m=re(),h=se(),g=(0,Y.useMemo)(()=>JSON.stringify({providerName:t,apiKey:n,apiBase:a,extraHeaders:o}),[a,n,o,t]),[_,v]=(0,Y.useState)(null),y=(0,Y.useCallback)(async()=>{if(t)try{let e=await m.mutateAsync({provider:t,data:Ne({apiKey:n,apiBase:a,extraHeaders:o,supportsWireApi:s,wireApi:c,models:u,providerModelAliases:f})});if(e.success){d.success(`${p(`providerTestConnectionSuccess`)} (${e.latencyMs}ms)`);return}let r=[`provider=${e.provider}`,`latency=${e.latencyMs}ms`];e.model&&r.push(`model=${e.model}`),d.error(`${p(`providerTestConnectionFailed`)}: ${e.message} | ${r.join(` | `)}`)}catch(e){let t=e instanceof Error?e.message:String(e);d.error(`${p(`providerTestConnectionFailed`)}: ${t}`)}},[a,n,o,u,f,t,s,m,c]);return{discoverModels:(0,Y.useCallback)(async()=>{if(!t)return null;if(r&&!n.trim()&&!i)return d.error(p(`providerModelsApiKeyRequired`)),null;try{let e=await h.mutateAsync({provider:t,data:Pe({apiKey:n,apiBase:a,extraHeaders:o})});return v({key:g,models:e.models}),d.success(p(`providerModelsFetchSuccess`)),e.models}catch(e){if(e instanceof l&&(e.details?.upstreamStatus===401||e.details?.upstreamStatus===403))return d.error(p(`providerModelsAuthorizationFailed`)),null;let t=e instanceof Error?e.message:String(e);return d.error(`${p(`providerModelsFetchFailed`)}: ${t}`),null}},[a,n,r,i,h,g,o,t]),fetchedModels:_?.key===g?_.models:[],isDiscoveringModels:h.isPending,isTestPending:m.isPending,testConnection:y}}var $=t();function Xe({value:e,onChange:t,className:n}){let a=e?Object.entries(e):[],o=(e,n,r)=>{let i=[...a];i[e]=[n,r],t(Object.fromEntries(i))},s=()=>{t({...e,"":``})},l=e=>{let n=a.filter((t,n)=>n!==e);t(Object.fromEntries(n))};return(0,$.jsxs)(`div`,{className:r(`space-y-2`,n),children:[a.map(([e,t],n)=>(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(i,{type:`text`,value:e,onChange:e=>o(n,e.target.value,t),placeholder:p(`headerName`),className:`flex-1`}),(0,$.jsx)(i,{type:`text`,value:t,onChange:t=>o(n,e,t.target.value),placeholder:p(`headerValue`),className:`flex-1`}),(0,$.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>l(n),children:(0,$.jsx)(I,{className:`h-4 w-4 text-red-500`})})]},n)),(0,$.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:[(0,$.jsx)(j,{className:`h-4 w-4 mr-2`}),p(`add`)]})]})}function Ze(e){let{value:t,onChange:n,options:r}=e;return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map(e=>{let r=e.value===t;return(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.value),"aria-pressed":r,className:`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${r?`border-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:e.label},e.value)})})}function Qe(e){let{showAdvanced:t,onShowAdvancedChange:n,supportsWireApi:r,wireApiLabel:i,wireApi:a,onWireApiChange:o,shouldUseWireApiPills:c,wireApiSelectOptions:l,extraHeadersLabel:u,extraHeaders:d,onExtraHeadersChange:f}=e;return(0,$.jsxs)(`div`,{className:`border-t border-border/70 pt-4`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(N,{className:`h-3.5 w-3.5`}),p(`providerAdvancedSettings`)]}),(0,$.jsx)(v,{className:`h-4 w-4 transition-transform ${t?`rotate-180`:``}`})]}),t?(0,$.jsxs)(`div`,{className:`mt-4 space-y-5`,children:[r?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`wireApi`,className:`text-sm font-medium text-foreground`,children:i}),c?(0,$.jsx)(Ze,{value:a,onChange:e=>o(e),options:l}):(0,$.jsxs)(T,{value:a,onValueChange:e=>o(e),children:[(0,$.jsx)(S,{className:`rounded-xl`,children:(0,$.jsx)(x,{})}),(0,$.jsx)(C,{children:l.map(e=>(0,$.jsx)(w,{value:e.value,children:e.label},e.value))})]})]}):null,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{className:`text-sm font-medium text-foreground`,children:u}),(0,$.jsx)(Xe,{value:d,onChange:f}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerExtraHeadersHelpShort`)})]})]}):null]})}function $e({isSet:e,className:t,value:n,onChange:a,placeholder:o,...s}){let[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=typeof n==`string`&&n.length>0;return(0,$.jsxs)(`div`,{className:`relative`,children:[e&&!p&&!d?(0,$.jsx)(`div`,{onClick:()=>f(!0),className:r(`flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-500 cursor-text items-center pr-12`,t),children:`••••••••••••`}):(0,$.jsx)(i,{type:l?`text`:`password`,className:r(`pr-12`,t),value:n,onChange:a,onBlur:()=>{p||f(!1)},placeholder:o,autoFocus:d,...s}),(0,$.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex gap-1`,children:(e||p)&&(0,$.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>u(!l),children:l?(0,$.jsx)(xe,{className:`h-4 w-4`}):(0,$.jsx)(D,{className:`h-4 w-4`})})})]})}function et(e){let{apiKey:t,apiKeyRequired:n,apiKeySet:r,apiKeyPlaceholder:i,providerAuth:a,providerAuthNote:o,providerAuthMethodOptions:l,providerAuthMethodsCount:u,selectedAuthMethodHint:d,shouldUseAuthMethodPills:f,resolvedAuthMethodId:m,onAuthMethodChange:h,onStartProviderAuth:g,onImportProviderAuthFromCli:_,startPending:v,importPending:y,authSessionId:b,authStatusMessage:E,onApiKeyChange:D}=e,O=n?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`apiKey`,className:`text-sm font-medium text-foreground`,children:p(`apiKey`)}),(0,$.jsx)($e,{id:`apiKey`,value:t,isSet:r,onChange:e=>D(e.target.value),placeholder:i,className:`rounded-xl`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`leaveBlankToKeepUnchanged`)})]}):null;return a?.kind===`device_code`?(0,$.jsxs)($.Fragment,{children:[O,(0,$.jsxs)(`div`,{className:`space-y-2 rounded-xl bg-muted/45 p-3`,children:[(0,$.jsx)(s,{className:`text-sm font-medium text-foreground`,children:a.displayName||p(`providerAuthSectionTitle`)}),o?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null,u>1?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{className:`text-xs font-medium text-foreground`,children:p(`providerAuthMethodLabel`)}),f?(0,$.jsx)(Ze,{value:m,onChange:h,options:l}):(0,$.jsxs)(T,{value:m,onValueChange:h,children:[(0,$.jsx)(S,{className:`h-8 rounded-lg`,children:(0,$.jsx)(x,{placeholder:p(`providerAuthMethodPlaceholder`)})}),(0,$.jsx)(C,{children:l.map(e=>(0,$.jsx)(w,{value:e.value,children:e.label},e.value))})]}),d?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d}):null]}):null,(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:g,disabled:v||!!b,children:p(v?`providerAuthStarting`:b?`providerAuthAuthorizing`:`providerAuthAuthorizeInBrowser`)}),a.supportsCliImport?(0,$.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:_,disabled:y,children:p(y?`providerAuthImporting`:`providerAuthImportFromCli`)}):null,b?(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p(`providerAuthSessionLabel`),`: `,b.slice(0,8),`…`]}):null]}),E?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:E}):null]})]}):O}function tt(e){let{providerName:t,models:n,aliases:r,fetchedModels:i=[],onModelsChange:a}=e,o=q({pollWhileRefreshing:!0,refreshOnMount:!0}),s=t?o.data?.providers[t]:void 0,c=i.length>0?`fetched`:`background`,l=(0,Y.useMemo)(()=>Be(n,c===`fetched`?i:s?.models??[],r),[r,s?.models,i,n,c]);return{addSuggestedModels:(0,Y.useCallback)(e=>{let t=ze(n,e,r);t.addedCount>0&&a(t.models)},[r,n,a]),hasSuggestionError:!!(s?.lastError&&!s.fetchedAt),isCheckingSuggestions:!!(t&&(o.isLoading||o.data?.refreshing&&!s)),suggestedModels:l,suggestionSource:c}}function nt(e){let{models:t,modelConfig:n,onModelsChange:r,onRemoveModel:i,onToggleModelThinkingLevel:a,onSetModelThinkingDefault:c,onSetModelVision:l,thinkingLevels:u,formatThinkingLevelLabel:d}=e,[f,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(()=>new Set),_=(0,Y.useMemo)(()=>t.filter(e=>h.has(e)),[t,h]),v=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},y=()=>{m(!1),g(new Set)};return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`flex min-h-7 flex-wrap items-center justify-end gap-2`,children:f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`mr-auto text-xs text-muted-foreground`,children:p(`providerModelsSuggestionsSelected`).replace(`{count}`,String(_.length))}),(0,$.jsx)(`button`,{type:`button`,className:`text-xs font-medium text-primary hover:text-primary/80`,onClick:()=>g(_.length===t.length?new Set:new Set(t)),children:p(_.length===t.length?`providerModelsClearSelection`:`providerModelsSelectAll`)}),(0,$.jsx)(`button`,{type:`button`,className:`text-xs font-medium text-muted-foreground hover:text-foreground`,onClick:y,children:p(`cancel`)}),(0,$.jsxs)(`button`,{type:`button`,disabled:_.length===0,className:`inline-flex items-center gap-1 rounded-md bg-destructive/10 px-2 py-1 text-xs font-medium text-destructive transition-colors hover:bg-destructive/15 disabled:cursor-not-allowed disabled:opacity-45`,onClick:()=>{_.length!==0&&(r(t.filter(e=>!h.has(e))),y())},children:[(0,$.jsx)(I,{className:`h-3 w-3`}),p(`providerModelsRemoveSelected`)]})]}):(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground`,onClick:()=>m(!0),children:[(0,$.jsx)(I,{className:`h-3 w-3`}),p(`providerModelsBulkRemove`)]})}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>{if(f)return(0,$.jsxs)(`label`,{className:`inline-flex max-w-full cursor-pointer items-center gap-2 rounded-full border border-border/55 bg-muted/45 px-3 py-1.5 hover:bg-muted/70`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:h.has(e),onChange:()=>v(e),"aria-label":p(`providerModelsSuggestionSelect`).replace(`{model}`,e),className:`h-3.5 w-3.5 shrink-0 accent-primary`}),(0,$.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-foreground sm:max-w-[220px]`,children:e})]},e);let t=n[e],r=t?.thinking,m=r?.supported??[],g=r?.default??null,_=t?.vision===!0;return(0,$.jsxs)(`div`,{className:`group inline-flex max-w-full items-center gap-1 rounded-full border border-border/55 bg-muted/45 px-3 py-1.5`,children:[(0,$.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-foreground sm:max-w-[220px]`,children:e}),(0,$.jsxs)(V,{children:[(0,$.jsx)(z,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":p(`providerModelThinkingTitle`),title:p(`providerModelThinkingTitle`),children:(0,$.jsx)(N,{className:`h-3 w-3`})})}),(0,$.jsxs)(B,{className:`w-80 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted/50 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:p(`providerModelVisionTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelVisionHint`)})]}),(0,$.jsx)(o,{checked:_,onCheckedChange:t=>l(e,t)})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:p(`providerModelThinkingTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelThinkingHint`)})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(t=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(e,t),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${m.includes(t)?`border-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:d(t)},t))}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(s,{className:`text-xs font-medium text-foreground`,children:p(`providerModelThinkingDefault`)}),(0,$.jsxs)(T,{value:g??`__none__`,onValueChange:t=>c(e,t===`__none__`?null:t),disabled:m.length===0,children:[(0,$.jsx)(S,{className:`h-8 rounded-lg text-xs`,children:(0,$.jsx)(x,{})}),(0,$.jsxs)(C,{children:[(0,$.jsx)(w,{value:`__none__`,children:p(`providerModelThinkingDefaultNone`)}),m.map(e=>(0,$.jsx)(w,{value:e,children:d(e)},e))]})]}),m.length===0?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelThinkingNoSupported`)}):null]})]})]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":p(`remove`),children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e)})}),f?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelsRemoveSaveHint`)}):null]})}var rt=20,it=50,at=50;function ot(e){let{expanded:t,fetchedTotal:n,models:r,source:a,onExpandedChange:o,onAddModels:s}=e,[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(()=>new Set),f=(0,Y.useMemo)(()=>{let e=c.trim().toLowerCase();return e?r.filter(t=>t.toLowerCase().includes(e)):r},[r,c]),m=f.slice(0,at),h=(0,Y.useMemo)(()=>r.filter(e=>u.has(e)),[r,u]),g=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=e=>{e.length!==0&&(s(e),l(``),d(new Set))},b=a===`fetched`?`providerModelsFetchedSuggestionsSummary`:`providerModelsSuggestionsSummary`;return a===`fetched`&&r.length===0?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-xl bg-muted/35 px-3 py-2 text-xs text-muted-foreground`,role:`status`,children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,$.jsx)(`span`,{children:p(`providerModelsFetchedAllConfigured`).replace(`{count}`,String(n))})]}):(0,$.jsxs)(`div`,{className:`rounded-xl bg-muted/35 p-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":t,className:`flex min-w-0 flex-1 items-center gap-1.5 rounded-lg px-2 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground`,onClick:()=>o(!t),children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:p(b).replace(`{count}`,String(r.length))}),(0,$.jsx)(y,{className:`h-3.5 w-3.5 shrink-0 transition-transform ${t?`rotate-90`:``}`})]}),r.length<=it?(0,$.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-lg px-2 py-1.5 text-xs font-medium text-primary transition-colors hover:bg-primary/10`,onClick:()=>v(r),children:p(`providerModelsSuggestionsAddAll`)}):null]}),t?(0,$.jsxs)(`div`,{className:`px-1 pb-1`,children:[r.length>rt?(0,$.jsxs)(`div`,{className:`relative px-2 pb-1 pt-1.5`,children:[(0,$.jsx)(_,{className:`pointer-events-none absolute left-4 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(i,{value:c,onChange:e=>l(e.target.value),placeholder:p(`providerModelsSuggestionsSearchPlaceholder`),className:`h-8 rounded-lg pl-8 text-xs`})]}):null,(0,$.jsxs)(`div`,{className:`custom-scrollbar max-h-44 overflow-y-auto overscroll-contain`,children:[m.map(e=>(0,$.jsxs)(`label`,{className:`grid min-w-0 cursor-pointer grid-cols-[auto_minmax(0,1fr)] items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-muted/70`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:u.has(e),onChange:()=>g(e),"aria-label":p(`providerModelsSuggestionSelect`).replace(`{model}`,e),className:`h-3.5 w-3.5 shrink-0 accent-primary`}),(0,$.jsx)(`span`,{className:`block min-w-0 truncate text-xs text-foreground`,title:e,children:e})]},e)),f.length===0?(0,$.jsx)(`p`,{className:`px-2 py-4 text-center text-xs text-muted-foreground`,children:p(`providerModelsSuggestionsSearchEmpty`)}):null]}),f.length>m.length?(0,$.jsx)(`p`,{className:`px-2 pt-1 text-[11px] text-muted-foreground`,children:p(`providerModelsSuggestionsShowing`).replace(`{visible}`,String(m.length)).replace(`{count}`,String(f.length))}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 pt-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`providerModelsSuggestionsSelected`).replace(`{count}`,String(h.length))}),(0,$.jsx)(`button`,{type:`button`,disabled:h.length===0,className:`shrink-0 rounded-md bg-primary/10 px-2 py-1 text-[11px] font-medium text-primary transition-colors hover:bg-primary/15 disabled:cursor-not-allowed disabled:opacity-45`,onClick:()=>v(h),children:p(`providerModelsSuggestionsAddSelected`)})]}),(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] text-muted-foreground`,children:p(`providerModelsSuggestionsSaveHint`)})]}):null]})}function st({hasFetchedCatalog:e,hasSuggestionError:t,supportsModelDiscovery:n}){return!n||!t||e?null:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-xl bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,$.jsx)(E,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),p(`providerModelsSuggestionsFailed`)]})}function ct(e){let{providerName:t,providerModelAliases:n,models:r,modelConfig:a,modelDraft:o,showModelInput:l,onModelDraftChange:u,onShowModelInputChange:d,onAddModel:f,onModelsChange:m,supportsModelDiscovery:h,onDiscoverModels:g,isDiscoveringModels:_,fetchedModels:v,onRemoveModel:y,onToggleModelThinkingLevel:b,onSetModelThinkingDefault:x,onSetModelVision:S,thinkingLevels:C,formatThinkingLevelLabel:w}=e,[T,E]=(0,Y.useState)(!1),D=(0,Y.useRef)(null),{addSuggestedModels:O,hasSuggestionError:k,isCheckingSuggestions:N,suggestedModels:P,suggestionSource:F}=tt({providerName:t,models:r,aliases:n,fetchedModels:v,onModelsChange:m}),I=async()=>{await g()&&(E(!0),window.requestAnimationFrame(()=>{let e=D.current;e?.scrollIntoView?.({behavior:`smooth`,block:`center`}),e?.focus({preventScroll:!0})}))},R=v.length>0;return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(s,{className:`text-sm font-medium text-foreground`,children:p(`providerModelsTitle`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[h?(0,$.jsxs)(`button`,{type:`button`,onClick:I,disabled:_,className:`flex items-center gap-1 text-xs font-medium text-primary transition-colors hover:text-primary/80 disabled:cursor-wait disabled:opacity-60`,children:[(0,$.jsx)(M,{className:`h-3 w-3 ${_?`animate-spin`:``}`}),p(_?`providerModelsFetching`:`providerModelsFetch`)]}):null,l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),className:`flex items-center gap-1 text-xs font-medium text-primary hover:text-primary/80`,children:[(0,$.jsx)(j,{className:`h-3 w-3`}),p(`providerAddModel`)]})]})]}),l?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{value:o,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f()),e.key===`Escape`&&(d(!1),u(``))},placeholder:p(`providerModelInputPlaceholder`),className:`flex-1 rounded-xl`,autoFocus:!0}),(0,$.jsx)(c,{type:`button`,size:`sm`,onClick:f,disabled:o.trim().length===0,children:p(`add`)}),(0,$.jsx)(c,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{d(!1),u(``)},children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}):null,(0,$.jsx)(st,{hasFetchedCatalog:R,hasSuggestionError:k,supportsModelDiscovery:h}),h&&N&&!R?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-xl bg-muted/35 px-3 py-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(A,{className:`h-3.5 w-3.5 animate-spin`}),p(`providerModelsSuggestionsChecking`)]}):h&&(P.length>0||R)?(0,$.jsx)(`div`,{ref:D,tabIndex:-1,"aria-live":`polite`,className:`scroll-m-4 outline-none`,children:(0,$.jsx)(ot,{expanded:T,fetchedTotal:v.length,models:P,source:F,onExpandedChange:E,onAddModels:O})}):null,r.length===0?(0,$.jsxs)(`div`,{className:`rounded-xl bg-muted/35 px-4 py-6 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:p(`providerModelsEmptyShort`)}),l?null:(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:`mt-2 text-sm font-medium text-primary hover:text-primary/80`,children:p(`providerAddFirstModel`)})]}):(0,$.jsx)(nt,{models:r,modelConfig:a,onModelsChange:m,onRemoveModel:y,onToggleModelThinkingLevel:b,onSetModelThinkingDefault:x,onSetModelVision:S,thinkingLevels:C,formatThinkingLevelLabel:w})]})}function lt({apiKeyRequired:e=!0,apiKeySet:t,className:n,enabled:r}){if(!r)return(0,$.jsx)(m,{status:`inactive`,label:p(`disabled`),className:n});let i=!e||t;return(0,$.jsx)(m,{status:i?`ready`:`setup`,label:p(i?`statusReady`:`statusSetup`),className:n})}function ut(e){let{context:t,language:n,providerTitle:r,providerDisplayName:a,apiKey:o,apiBase:l,extraHeaders:u,wireApi:d,models:f,modelConfig:m,modelDraft:h,showAdvanced:g,showModelInput:_,resolvedAuthMethodId:v,authSessionId:y,authStatusMessage:b,hasChanges:x,isDeletePending:S,isUpdatePending:C,connectivity:w,startPending:T,importPending:E,onProviderDisplayNameChange:D,onApiKeyChange:O,onApiBaseChange:k,onAuthMethodChange:A,onStartProviderAuth:j,onImportProviderAuthFromCli:M,onModelDraftChange:N,onShowModelInputChange:P,onAddModel:F,onModelsChange:L,onRemoveModel:R,onToggleModelThinkingLevel:z,onSetModelThinkingDefault:B,onSetModelVision:V,onShowAdvancedChange:H,onWireApiChange:ee,onExtraHeadersChange:U,onDeleteProvider:W,onSubmit:G,onTestConnection:K}=e,q=t.providerAuthMethods.find(e=>e.id===v);return(0,$.jsxs)(ge,{children:[(0,$.jsx)(pe,{className:`px-5 py-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`truncate text-lg font-semibold text-foreground`,children:r}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:W,disabled:S,className:`text-muted-foreground/70 transition-colors hover:text-red-500`,title:p(`providerDelete`),children:(0,$.jsx)(I,{className:`h-4 w-4`})}),(0,$.jsx)(lt,{enabled:t.currentEnabled,apiKeyRequired:t.resolvedProviderConfig.apiKeyRequired,apiKeySet:t.resolvedProviderConfig.apiKeySet})]})]})}),(0,$.jsxs)(`form`,{onSubmit:G,className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(_e,{className:`space-y-4 px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`providerDisplayName`,className:`text-sm font-medium text-foreground`,children:p(`providerDisplayName`)}),(0,$.jsx)(i,{id:`providerDisplayName`,type:`text`,value:a,onChange:e=>D(e.target.value),placeholder:t.defaultDisplayName||p(`providerDisplayNamePlaceholder`),className:`rounded-xl`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerDisplayNameHelpShort`)})]}),(0,$.jsx)(et,{apiKey:o,apiKeyRequired:t.resolvedProviderConfig.apiKeyRequired!==!1,apiKeySet:t.resolvedProviderConfig.apiKeySet,apiKeyPlaceholder:t.apiKeyHint?.placeholder??p(`enterApiKey`),providerAuth:t.providerAuth,providerAuthNote:t.providerAuth?.note?.[n]||t.providerAuth?.note?.en||t.providerAuth?.displayName||``,providerAuthMethodOptions:t.providerAuthMethodOptions,providerAuthMethodsCount:t.providerAuthMethods.length,selectedAuthMethodHint:q?.hint?.[n]||q?.hint?.en||``,shouldUseAuthMethodPills:t.shouldUseAuthMethodPills,resolvedAuthMethodId:v,onAuthMethodChange:A,onStartProviderAuth:j,onImportProviderAuthFromCli:M,startPending:T,importPending:E,authSessionId:y,authStatusMessage:b,onApiKeyChange:O}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`apiBase`,className:`text-sm font-medium text-foreground`,children:p(`apiBase`)}),(0,$.jsx)(i,{id:`apiBase`,type:`text`,value:l,onChange:e=>k(e.target.value),placeholder:t.defaultApiBase||t.apiBaseHint?.placeholder||`https://api.example.com`,className:`rounded-xl`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.apiBaseHelpText})]}),(0,$.jsx)(ct,{providerName:t.providerConfig?.providerId??``,providerModelAliases:t.providerModelAliases,models:f,modelConfig:m,modelDraft:h,showModelInput:_,onModelDraftChange:N,onShowModelInputChange:P,onAddModel:F,onModelsChange:L,supportsModelDiscovery:t.supportsModelDiscovery,onDiscoverModels:w.discoverModels,isDiscoveringModels:w.isDiscoveringModels,fetchedModels:w.fetchedModels,onRemoveModel:R,onToggleModelThinkingLevel:z,onSetModelThinkingDefault:B,onSetModelVision:V,thinkingLevels:te,formatThinkingLevelLabel:Fe},t.providerConfig?.providerId),(0,$.jsx)(Qe,{showAdvanced:g,onShowAdvancedChange:H,supportsWireApi:t.supportsWireApi,wireApiLabel:p(`wireApi`),wireApi:d,onWireApiChange:ee,shouldUseWireApiPills:t.shouldUseWireApiPills,wireApiSelectOptions:t.wireApiSelectOptions,extraHeadersLabel:p(`extraHeaders`),extraHeaders:u,onExtraHeadersChange:U})]}),(0,$.jsx)(ye,{children:(0,$.jsxs)(de,{align:`between`,children:[(0,$.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:K,disabled:w.isTestPending,children:[(0,$.jsx)(be,{className:`mr-1.5 h-3.5 w-3.5`}),w.isTestPending?p(`providerTestingConnection`):p(`providerTestConnection`)]}),(0,$.jsx)(c,{type:`submit`,size:`sm`,disabled:C||!x,children:p(C?`saving`:x?`save`:`unchanged`)})]})})]})]})}function dt({providerName:e,onProviderDeleted:t}){let{data:n}=ce(),{data:r}=ne(),{data:i}=le(),a=f(),o=(0,Y.useMemo)(()=>qe({providerName:e,providersView:n,templatesView:r,schema:i,language:a}),[a,e,n,i,r]);if(!e||!o.providerConfig)return(0,$.jsx)(ve,{children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:p(`providersSelectTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:p(`providersSelectDescription`)})]})});let s=JSON.stringify({providerConfig:o.providerConfig,currentApiBase:o.currentApiBase,currentEditableModels:o.currentEditableModels,currentModelConfig:o.currentModelConfig,currentWireApi:o.currentWireApi,effectiveDisplayName:o.effectiveDisplayName,preferredAuthMethodId:o.preferredAuthMethodId});return(0,$.jsx)(ft,{providerName:e,onProviderDeleted:t,context:o,language:a},s)}function ft({providerName:e,onProviderDeleted:t,context:n,language:r}){let i=ue(),a=G(),{currentApiBase:o,currentEditableModels:s,currentHeaders:c,currentModelConfig:l,currentWireApi:u,defaultApiBase:d,effectiveDisplayName:f,providerAuth:m,providerAuthMethods:h,providerModelAliases:g,resolvedProviderConfig:_,preferredAuthMethodId:v,supportsWireApi:y}=n,[b,x]=(0,Y.useState)(``),[S,C]=(0,Y.useState)(o),[w,T]=(0,Y.useState)(_.extraHeaders||null),[E,D]=(0,Y.useState)(u),[O,k]=(0,Y.useState)(s),[A,j]=(0,Y.useState)(l),[M,N]=(0,Y.useState)(``),[P,F]=(0,Y.useState)(f),[I,L]=(0,Y.useState)(!1),[R,z]=(0,Y.useState)(!1),[B,V]=(0,Y.useState)(v),H=Ye({providerName:e,apiKey:b,apiKeyRequired:_.apiKeyRequired!==!1,apiKeySet:_.apiKeySet,apiBase:S,extraHeaders:w,supportsWireApi:y,wireApi:E,models:O,providerModelAliases:g}),ee=P.trim()||f||e||p(`providersSelectPlaceholder`),U=(0,Y.useMemo)(()=>{if(!h.length)return``;let e=B.trim();return e&&h.some(t=>t.id===e)?e:v||h[0]?.id||``},[B,v,h]),{authSessionId:W,authStatusMessage:te,importAuthFromCli:K,importPending:q,startAuth:ne,startPending:re}=Je({providerName:e,providerAuth:m,resolvedAuthMethodId:U}),ie=(0,Y.useMemo)(()=>je({providerName:e,apiKey:b,apiBase:S,currentApiBase:o,extraHeaders:w,currentHeaders:c,supportsWireApi:y,wireApi:E,currentWireApi:u,models:O,currentEditableModels:s,modelConfig:A,currentModelConfig:l,providerDisplayName:P,effectiveDisplayName:f}),[e,b,S,o,w,c,y,E,u,O,s,A,l,P,f]),ae=e=>{k(e),j(t=>Oe(t,e))};return(0,$.jsx)(ut,{context:n,language:r,providerTitle:ee,providerDisplayName:P,apiKey:b,apiBase:S,extraHeaders:w,wireApi:E,models:O,modelConfig:A,modelDraft:M,showAdvanced:I,showModelInput:R,resolvedAuthMethodId:U,authSessionId:W,authStatusMessage:te,hasChanges:ie,isDeletePending:a.isPending,isUpdatePending:i.isPending,connectivity:H,startPending:re,importPending:q,onProviderDisplayNameChange:F,onApiKeyChange:x,onApiBaseChange:C,onAuthMethodChange:V,onStartProviderAuth:ne,onImportProviderAuthFromCli:K,onModelDraftChange:N,onShowModelInputChange:z,onAddModel:()=>{let e=Re(O,M,g);ae(e.models),N(e.draft)},onModelsChange:ae,onRemoveModel:e=>{let t=Ve(O,A,e);k(t.models),j(t.modelConfig)},onToggleModelThinkingLevel:(e,t)=>{j(n=>He(n,e,t))},onSetModelThinkingDefault:(e,t)=>{j(n=>Ue(n,e,t))},onSetModelVision:(e,t)=>{j(n=>We(n,e,t))},onShowAdvancedChange:L,onWireApiChange:D,onExtraHeadersChange:T,onDeleteProvider:async()=>{if(e&&window.confirm(p(`providerDeleteConfirm`)))try{await a.mutateAsync({provider:e}),t?.(e)}catch{}},onSubmit:t=>{t.preventDefault(),e&&i.mutate({provider:e,data:Me({providerName:e,apiKey:b,apiBase:S,currentApiBase:o,defaultApiBase:d,extraHeaders:w,currentHeaders:c,supportsWireApi:y,wireApi:E,currentWireApi:u,models:O,currentEditableModels:s,modelConfig:A,currentModelConfig:l,providerDisplayName:P,effectiveDisplayName:f})})},onTestConnection:H.testConnection})}function pt(e){if(!e)return null;try{let t=new URL(e);return`${t.host}${t.pathname&&t.pathname!==`/`?t.pathname:``}`}catch{return e.replace(/^https?:\/\//,``)}}function mt(e,t=[]){let n=new Map(t.map((e,t)=>[e,t]));return e.map((e,t)=>({provider:e,index:t})).sort((e,t)=>{let r=n.get(e.provider.providerId),i=n.get(t.provider.providerId);if(r!==void 0||i!==void 0)return(r??2**53-1)-(i??2**53-1);let a=e.provider.providerType===`nextclaw`?1:0,o=t.provider.providerType===`nextclaw`?1:0;return a===o?e.index-t.index:a-o}).map(({provider:e})=>e)}function ht(e){let t=e.findIndex(e=>e.providerType===`zhipu`),n=e.findIndex(e=>e.providerType===`dashscope-coding-plan`);return e.map((e,t)=>({template:e,index:t})).sort((e,r)=>{let i=({template:e,index:r})=>e.providerType===`nextclaw`?2**53-1:e.providerType===`deepseek`&&n>=0?n-.5:e.providerType===`mimo`&&t>=0?t+.5:r;return i(e)-i(r)}).map(({template:e})=>e)}function gt(){let{isMobile:e}=k(),{data:t}=ce(),{data:n}=ne(),s=ie(),l=G(),u=ue(),[d,f]=(0,Y.useState)(null),[g,v]=(0,Y.useState)(null),[y,x]=(0,Y.useState)(!1),[S,C]=(0,Y.useState)([]),[w,T]=(0,Y.useState)(``),E=(0,Y.useMemo)(()=>mt(Object.values(t?.providers??{}),S),[t?.providers,S]),D=(0,Y.useMemo)(()=>n?.providerTemplates??[],[n?.providerTemplates]),A=(0,Y.useMemo)(()=>ht(D),[D]),M=(0,Y.useMemo)(()=>new Map(D.map(e=>[e.providerType,e])),[D]),N=(0,Y.useMemo)(()=>{let e=w.trim().toLowerCase();return E.filter(t=>{if(!e)return!0;let n=t.providerType?M.get(t.providerType):null;return(t.displayName?.trim()||n?.displayName||t.providerId).toLowerCase().includes(e)||t.providerId.toLowerCase().includes(e)})},[E,w,M]),P=(0,Y.useMemo)(()=>d&&N.some(e=>e.providerId===d)?d:e?null:N[0]?.providerId??null,[N,e,d]);return!t||!n?(0,$.jsx)(a,{title:p(`providersPageTitle`),description:p(`providersPageDescription`),layout:`split`,children:(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:p(`providersLoading`)})}):(0,$.jsxs)(a,{title:p(`providersPageTitle`),description:p(`providersPageDescription`),layout:`split`,children:[(0,$.jsxs)(fe,{className:`md:min-h-0`,compactView:d?`detail`:`list`,onMobileBack:()=>f(null),mobileListLabel:p(`providersPageTitle`),children:[(0,$.jsxs)(he,{children:[(0,$.jsx)(pe,{className:`space-y-3 px-4 pb-3 pt-4`,children:(0,$.jsxs)(V,{open:y,onOpenChange:x,children:[(0,$.jsx)(z,{asChild:!0,children:(0,$.jsxs)(c,{type:`button`,variant:`outline`,className:`w-full justify-center`,disabled:s.isPending,children:[(0,$.jsx)(j,{className:`mr-2 h-4 w-4`}),s.isPending?p(`saving`):p(`providerAdd`)]})}),(0,$.jsxs)(B,{className:`w-[42rem] max-w-[calc(100vw-2rem)] p-3`,align:`start`,children:[(0,$.jsx)(`div`,{className:`mb-2 px-1 text-xs font-semibold text-muted-foreground`,children:p(`providerTemplatePickerTitle`)}),(0,$.jsxs)(`div`,{className:`grid max-h-[24rem] grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-3`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-dashed border-border/70 bg-muted/20 px-3 py-2 text-left transition-colors hover:border-border hover:bg-muted/45`,onClick:async()=>{try{let e=await s.mutateAsync({data:{providerType:null}});T(``),f(e.providerId),C(t=>[e.providerId,...t.filter(t=>t!==e.providerId)]),x(!1)}catch{}},children:[(0,$.jsx)(h,{name:`custom`,className:`h-8 w-8 rounded-lg border border-border/60 bg-muted/50`}),(0,$.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:p(`providerAddCustom`)})]}),A.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-border/55 bg-muted/15 px-3 py-2 text-left transition-colors hover:border-border/80 hover:bg-muted/40`,onClick:async()=>{try{let t=await s.mutateAsync({data:{providerType:e.providerType}});T(``),f(t.providerId),C(e=>[t.providerId,...e.filter(e=>e!==t.providerId)]),x(!1)}catch{}},children:[(0,$.jsx)(h,{name:e.providerType,src:e.logo?`/logos/${e.logo}`:null,className:`h-8 w-8 rounded-lg border border-border/55 bg-background`,imgClassName:`h-4 w-4 object-contain`}),(0,$.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:e.displayName||e.providerType})]},e.providerType))]})]})]})}),(0,$.jsx)(`div`,{className:`border-b border-border/70 px-4 py-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(_,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/70`}),(0,$.jsx)(i,{value:w,onChange:e=>T(e.target.value),placeholder:p(`providersFilterPlaceholder`),className:`h-10 rounded-xl pl-9`})]})}),(0,$.jsxs)(_e,{className:`space-y-2 p-3`,children:[N.map(e=>{let t=e.providerType?M.get(e.providerType):null,n=e.enabled!==!1,i=H(e),a=e.displayName?.trim()||t?.displayName||e.providerId,s=pt(e.apiBase||t?.defaultApiBase||``)||p(`providersDefaultDescription`);return(0,$.jsx)(`div`,{onClick:()=>f(e.providerId),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),f(e.providerId))},role:`button`,tabIndex:0,className:r(`group w-full rounded-xl p-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40`,P===e.providerId?`bg-background/95 text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-background/65 hover:text-foreground`),children:(0,$.jsxs)(`div`,{className:`relative min-h-10`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 pr-20`,children:[(0,$.jsx)(h,{name:e.providerType??e.providerId,src:t?.logo?`/logos/${t.logo}`:null,className:`h-10 w-10 rounded-lg bg-background/80`,imgClassName:`h-5 w-5 object-contain`,fallback:(0,$.jsx)(`span`,{className:`text-sm font-semibold uppercase text-muted-foreground`,children:e.providerId[0]})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`truncate text-sm font-semibold text-foreground`,children:a}),(0,$.jsx)(`p`,{className:`truncate font-mono text-[10px] text-muted-foreground/65`,children:e.providerId}),(0,$.jsxs)(`p`,{className:`line-clamp-1 text-[11px] text-muted-foreground`,children:[s,` · `,e.models?.length??0]})]})]}),(0,$.jsxs)(`div`,{className:`absolute right-0 top-0 flex items-center gap-1.5 opacity-70 transition-opacity group-hover:opacity-100`,children:[(0,$.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(o,{checked:n,disabled:u.isPending,title:p(n?`disabled`:`enabled`),className:`h-[18px] w-8`,thumbClassName:`h-4 w-4 data-[state=checked]:translate-x-4`,onCheckedChange:t=>{u.mutateAsync({provider:e.providerId,data:{enabled:t},silentSuccess:!0})}})}),(0,$.jsxs)(V,{children:[(0,$.jsx)(z,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted hover:text-foreground`,onClick:e=>e.stopPropagation(),title:p(`more`),children:(0,$.jsx)(b,{className:`h-4 w-4`})})}),(0,$.jsx)(B,{className:`w-40 p-1`,align:`end`,onClick:e=>e.stopPropagation(),children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-2 text-sm text-red-600 hover:bg-red-50`,onClick:()=>v(e.providerId),children:[(0,$.jsx)(I,{className:`h-4 w-4`}),p(`providerDelete`)]})})]})]}),(0,$.jsx)(m,{status:n?i?`ready`:`setup`:`inactive`,label:p(n?i?`statusReady`:`statusSetup`:`disabled`),className:`absolute bottom-0 right-0 justify-end`})]})},e.providerId)}),N.length===0?(0,$.jsx)(me,{icon:O,title:p(`providersNoMatch`)}):null]})]}),(0,$.jsx)(dt,{providerName:P??void 0,onProviderDeleted:e=>{C(t=>t.filter(t=>t!==e)),e===P&&f(null)}})]}),(0,$.jsx)(F,{open:!!g,onOpenChange:e=>{e||v(null)},title:p(`providerDelete`),description:g??void 0,confirmLabel:p(`delete`),variant:`destructive`,onCancel:()=>v(null),onConfirm:()=>{g&&l.mutateAsync({provider:g}).then(()=>{C(e=>e.filter(e=>e!==g)),g===P&&f(null),v(null)})}})]})}export{gt as ProvidersConfigPage};
1
+ import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n,t as r}from"./utils-CBZPzC_b.js";import{Gt as i,Qt as a,Ut as o,Wt as s,Yt as c,hn as l,jn as u,vn as d}from"./api-DqzQ-_3w.js";import{l as f,s as p}from"./i18n-20rSH40D.js";import{n as m,t as h}from"./logo-badge-C-5-zim6.js";import{t as g}from"./createLucideIcon-BNKf0_kc.js";import{t as _}from"./search-CUe41wjm.js";import{t as v}from"./chevron-down-BL-yMYcX.js";import{n as y,t as b}from"./ellipsis-C5YXdOUx.js";import{a as x,i as S,n as C,r as w,t as T}from"./select-CG5YWnwe.js";import{t as E}from"./circle-alert-lSa3LRvS.js";import{t as D}from"./eye-C84inPcV.js";import{i as O,t as k}from"./use-viewport-layout-BS18drMT.js";import{t as A}from"./loader-circle-K1BDdHR5.js";import{t as j}from"./plus-LA8-jpxP.js";import{t as M}from"./refresh-cw-h9Xq3LY3.js";import{t as N}from"./settings-2-CE3ELQyk.js";import{n as P,t as F}from"./confirm-dialog-BTKCWMn6.js";import{t as I}from"./trash-2-BPPYt2NV.js";import{t as L}from"./x-DdXOqLnX.js";import{t as R}from"./host-capabilities-B107nwS3.js";import{i as z,r as B,t as V}from"./popover-NkrFlWHp.js";import{a as H,c as ee,l as U,o as W,t as te}from"./provider-models-hrHMcHqg.js";import{a as G,c as K,d as q,f as ne,h as re,i as ie,l as ae,m as oe,o as se,p as ce,r as le,y as ue}from"./use-config-BEdbtpD4.js";import{t as de}from"./form-actions-BRESe-m_.js";import{t as J}from"./config-hints-B_C9DAp5.js";import{a as fe,c as pe,i as me,l as he,n as ge,o as _e,r as ve,s as ye}from"./config-split-page-DqAXKLmG.js";var be=g(`CircleDotDashed`,[[`path`,{d:`M10.1 2.18a9.93 9.93 0 0 1 3.8 0`,key:`1qdqn0`}],[`path`,{d:`M17.6 3.71a9.95 9.95 0 0 1 2.69 2.7`,key:`1bq7p6`}],[`path`,{d:`M21.82 10.1a9.93 9.93 0 0 1 0 3.8`,key:`1rlaqf`}],[`path`,{d:`M20.29 17.6a9.95 9.95 0 0 1-2.7 2.69`,key:`1xk03u`}],[`path`,{d:`M13.9 21.82a9.94 9.94 0 0 1-3.8 0`,key:`l7re25`}],[`path`,{d:`M6.4 20.29a9.95 9.95 0 0 1-2.69-2.7`,key:`1v18p6`}],[`path`,{d:`M2.18 13.9a9.93 9.93 0 0 1 0-3.8`,key:`xdo6bj`}],[`path`,{d:`M3.71 6.4a9.95 9.95 0 0 1 2.7-2.69`,key:`1jjmaz`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),xe=g(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),Y=e(n(),1),Se={providerId:``,providerType:null,isBuiltInType:!1,isCustom:!0,enabled:!0,displayName:``,apiKeySet:!1,apiKeyMasked:void 0,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelConfig:{}};function X(e){if(!e)return null;let t=Object.entries(e).map(([e,t])=>[e.trim(),t]).filter(([e])=>e.length>0);return t.length===0?null:Object.fromEntries(t)}function Ce(e,t){let n=X(e),r=X(t);if(n===null&&r===null)return!0;if(!n||!r)return!1;let i=Object.entries(n).sort(([e],[t])=>e.localeCompare(t)),a=Object.entries(r).sort(([e],[t])=>e.localeCompare(t));return i.length===a.length?i.every(([e,t],n)=>e===a[n][0]&&t===a[n][1]):!1}function Z(e){if(!e||e.length===0)return[];let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function we(e,t){let n=e.trim();if(!n||!t.trim())return n;let r=`${t.trim()}/`;return n.startsWith(r)?n.slice(r.length):n}function Q(e,t){let n=e.trim();if(!n)return``;for(let e of t){let t=e.trim();t&&(n=we(n,t))}return n.trim()}function Te(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}function Ee(e,t){return Z(t)}function De(e,t){return Z(e).map(e=>{let n=e.trim();return!n||n.startsWith(`${t}/`)?n:`${t}/${n}`})}function Oe(e,t){let n=new Set(t.map(e=>e.trim()).filter(Boolean)),r={};for(let[t,i]of Object.entries(e)){if(!n.has(t))continue;let e={},a=ee(i.thinking?.supported);if(a.length>0){let t=U(i.thinking?.default);e.thinking=t&&a.includes(t)?{supported:a,default:t}:{supported:a}}i.vision===!0&&(e.vision=!0),(e.thinking||e.vision===!0)&&(r[t]=e)}return r}function ke(e,t,n){return{...W(e,n),...W(t,n)}}function Ae(e,t){let n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;for(let i=0;i<n.length;i+=1){let a=n[i];if(a!==r[i])return!1;let o=e[a],s=t[a];if(!o||!s||!Te([...o.thinking?.supported??[]].sort(),[...s.thinking?.supported??[]].sort())||(o.thinking?.default??null)!==(s.thinking?.default??null)||(o.vision??!1)!==(s.vision??!1))return!1}return!0}function je(e){return e.providerName?e.apiKey.trim().length>0||e.apiBase.trim()!==e.currentApiBase.trim()||!Ce(e.extraHeaders,e.currentHeaders)||e.supportsWireApi&&e.wireApi!==e.currentWireApi||!Te(e.models,e.currentEditableModels)||!Ae(e.modelConfig,e.currentModelConfig)||e.providerDisplayName.trim()!==e.effectiveDisplayName:!1}function Me(e){let t={},n=e.apiKey.trim(),r=e.apiBase.trim(),i=X(e.extraHeaders),a=e.providerDisplayName.trim();return a!==e.effectiveDisplayName&&(t.displayName=a.length>0?a:null),n.length>0&&(t.apiKey=n),r!==e.currentApiBase.trim()&&(t.apiBase=r.length>0&&r!==e.defaultApiBase?r:null),Ce(i,e.currentHeaders)||(t.extraHeaders=i),e.supportsWireApi&&e.wireApi!==e.currentWireApi&&(t.wireApi=e.wireApi),Te(e.models,e.currentEditableModels)||(t.models=De(e.models,e.providerName??``)),Ae(e.modelConfig,e.currentModelConfig)||(t.modelConfig=Oe(e.modelConfig,e.models)),t}function Ne(e){let t=Q(e.models.find(e=>e.trim().length>0)??``,e.providerModelAliases),n={...Pe(e),model:t||null};return e.supportsWireApi&&(n.wireApi=e.wireApi),n}function Pe(e){let t={apiBase:e.apiBase.trim(),extraHeaders:X(e.extraHeaders)};return e.apiKey.trim().length>0&&(t.apiKey=e.apiKey.trim()),t}function Fe(e){return p(e===`off`?`chatThinkingLevelOff`:e===`minimal`?`chatThinkingLevelMinimal`:e===`low`?`chatThinkingLevelLow`:e===`medium`?`chatThinkingLevelMedium`:e===`high`?`chatThinkingLevelHigh`:e===`adaptive`?`chatThinkingLevelAdaptive`:`chatThinkingLevelXhigh`)}function Ie(e){let{providerName:t,methods:n,defaultMethodId:r,language:i}=e;if(n.length===0)return``;let a=new Map;for(let e of n){let t=e.id.trim();t&&a.set(t.toLowerCase(),t)}let o=(...e)=>{for(let t of e){let e=a.get(t.toLowerCase());if(e)return e}},s=r?.trim();if(t===`minimax-portal`){if(i===`zh`)return o(`cn`,`china-mainland`)??o(s??``)??n[0]?.id??``;if(i===`en`)return o(`global`,`intl`,`international`)??o(s??``)??n[0]?.id??``}if(s){let e=o(s);if(e)return e}return i===`zh`?o(`cn`)??n[0]?.id??``:i===`en`?o(`global`)??n[0]?.id??``:n[0]?.id??``}function Le(e){let{required:t,hasDefault:n,optionCount:r}=e;return t&&n&&r>1&&r<=3}function Re(e,t,n){let r=Q(t,n);return r?e.includes(r)?{models:e,draft:``}:{models:[...e,r],draft:``}:{models:e,draft:t}}function ze(e,t,n){let r=[...e],i=new Set(e);for(let e of t){let t=Q(e,n);t&&!i.has(t)&&(i.add(t),r.push(t))}return{models:r,addedCount:r.length-e.length}}function Be(e,t,n){return ze(e,t,n).models.slice(e.length)}function Ve(e,t,n){let r={...t};return delete r[n],{models:e.filter(e=>e!==n),modelConfig:r}}function He(e,t,n){let r=e[t],i=r?.thinking?.supported??[],a=i.includes(n)?i.filter(e=>e!==n):te.filter(e=>e===n||i.includes(e)),o=r?.thinking?.default&&a.includes(r.thinking.default)?r.thinking.default:void 0,s={...r,thinking:a.length>0?o?{supported:a,default:o}:{supported:a}:void 0},c={...e};return s.thinking||s.vision===!0?c[t]=s:delete c[t],c}function Ue(e,t,n){let r=e[t],i=r?.thinking;return!i||i.supported.length===0||n&&!i.supported.includes(n)?e:{...e,[t]:{...r,thinking:n?{supported:i.supported,default:n}:{supported:i.supported}}}}function We(e,t,n){let r={...e[t],vision:n?!0:void 0},i={...e};return r.thinking||r.vision===!0?i[t]=r:delete i[t],i}function Ge(e){let{providerName:t,providerSpec:n,language:r}=e,i=n?.auth,a=i?.methods??[];return{providerAuth:i,providerAuthMethodOptions:a.map(e=>({value:e.id,label:e.label?.[r]||e.label?.en||e.id})),providerAuthMethods:a,preferredAuthMethodId:Ie({providerName:n?.providerType??t,methods:a,defaultMethodId:i?.defaultMethodId,language:r}),shouldUseAuthMethodPills:Le({required:i?.kind===`device_code`,hasDefault:!!i?.defaultMethodId?.trim(),optionCount:a.length})}}function Ke(e,t){let n=!!e?.supportsWireApi||t,r=(e?.wireApiOptions||[`auto`,`chat`,`responses`]).map(e=>({value:e,label:p(e===`chat`?`wireApiChat`:e===`responses`?`wireApiResponses`:`wireApiAuto`)}));return{shouldUseWireApiPills:Le({required:n,hasDefault:typeof e?.defaultWireApi==`string`&&e.defaultWireApi.length>0,optionCount:r.length}),supportsWireApi:n,wireApiSelectOptions:r}}function qe(e){let{providerName:t,providersView:n,templatesView:r,schema:i,language:a}=e,o=t?n?.providers[t]:null,s=r?.providerTemplates.find(e=>e.providerType===o?.providerType),c=o??Se,l=i?.uiHints,u=!!o?.isCustom,d=t?J(`providers.${t}.apiKey`,l):void 0,f=t?J(`providers.${t}.apiBase`,l):void 0,m=t?J(`providers.${t}.extraHeaders`,l):void 0,h=t?J(`providers.${t}.wireApi`,l):void 0,g=s?.displayName||o?.displayName||t||``,_=(c.displayName||``).trim()||g,v=c.enabled!==!1,y=u||s?.supportsModelDiscovery===!0,b=Z([s?.modelPrefix||s?.providerType||``,t||``]),x=s?.defaultApiBase||``,S=c.apiBase||x,C=X(c.extraHeaders||null),w=c.wireApi||s?.defaultWireApi||`auto`,T=Ee(Z((s?.defaultModels??[]).map(e=>Q(e,b))),Z((c.models??[]).map(e=>Q(e,b)))),E=Oe(ke(s?.modelConfig,c.modelConfig,b),T),D=s?.apiBaseHelp?.[a]||s?.apiBaseHelp?.en||f?.help||p(`providerApiBaseHelp`),O=Ge({providerName:t,providerSpec:s,language:a}),k=Ke(s,u);return{apiBaseHelpText:D,apiBaseHint:f,apiKeyHint:d,currentApiBase:S,currentEditableModels:T,currentEnabled:v,currentHeaders:C,currentModelConfig:E,currentWireApi:w,defaultApiBase:x,defaultDisplayName:g,effectiveDisplayName:_,extraHeadersHint:m,...O,providerConfig:o,providerModelAliases:b,resolvedProviderConfig:c,supportsModelDiscovery:y,wireApiHint:h,...k}}function Je(e){let{providerName:t,providerAuth:n,resolvedAuthMethodId:r}=e,i=u(),a=oe(),o=ae(),s=K(),[c,l]=(0,Y.useState)(``),[f,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),_=(0,Y.useRef)(null),v=(0,Y.useCallback)(()=>{_.current!==null&&(window.clearTimeout(_.current),_.current=null)},[]),y=(0,Y.useCallback)((e,n)=>{v(),_.current=window.setTimeout(()=>{(async()=>{if(t)try{let r=await o.mutateAsync({provider:t,data:{sessionId:e}});if(r.status===`pending`){g(p(`providerAuthWaitingBrowser`)),y(e,r.nextPollMs??n);return}if(r.status===`authorized`){m(null),v(),g(p(`providerAuthCompleted`)),d.success(p(`providerAuthCompleted`)),i.invalidateQueries({queryKey:[`config`]}),i.invalidateQueries({queryKey:[`providers`]});return}m(null),v(),g(r.message||`Authorization ${r.status}.`),d.error(r.message||`Authorization ${r.status}.`)}catch(e){m(null),v();let t=e instanceof Error?e.message:String(e);g(t),d.error(`Authorization failed: ${t}`)}})()},Math.max(1e3,n))},[v,o,t,i]),b=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{l(t),g(``);let e=await a.mutateAsync({provider:t,data:r?{methodId:r}:{}});if(!e.sessionId||!e.verificationUri)throw Error(p(`providerAuthStartFailed`));m(e.sessionId),g(`${p(`providerAuthOpenPrompt`)}${e.userCode}${p(`providerAuthOpenPromptSuffix`)}`),await R.openExternalUrl(e.verificationUri),y(e.sessionId,e.intervalMs)}catch(e){let t=e instanceof Error?e.message:String(e);m(null),v(),g(t),d.error(`${p(`providerAuthStartFailed`)}: ${t}`)}},[v,n?.kind,t,r,y,a]),x=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{l(t),v(),m(null);let e=await s.mutateAsync({provider:t});g(`${p(`providerAuthImportStatusPrefix`)}${e.expiresAt?` (expires: ${e.expiresAt})`:``}`),d.success(p(`providerAuthImportSuccess`)),i.invalidateQueries({queryKey:[`config`]}),i.invalidateQueries({queryKey:[`providers`]})}catch(e){let t=e instanceof Error?e.message:String(e);g(t),d.error(`${p(`providerAuthImportFailed`)}: ${t}`)}},[v,s,n?.kind,t,i]);return(0,Y.useEffect)(()=>{v()},[v,t]),(0,Y.useEffect)(()=>()=>v(),[v]),{authSessionId:c===t?f:null,authStatusMessage:c===t?h:``,importAuthFromCli:x,importPending:s.isPending,startAuth:b,startPending:a.isPending}}function Ye(e){let{providerName:t,apiKey:n,apiKeyRequired:r,apiKeySet:i,apiBase:a,extraHeaders:o,supportsWireApi:s,wireApi:c,models:u,providerModelAliases:f}=e,m=re(),h=se(),g=(0,Y.useMemo)(()=>JSON.stringify({providerName:t,apiKey:n,apiBase:a,extraHeaders:o}),[a,n,o,t]),[_,v]=(0,Y.useState)(null),y=(0,Y.useCallback)(async()=>{if(t)try{let e=await m.mutateAsync({provider:t,data:Ne({apiKey:n,apiBase:a,extraHeaders:o,supportsWireApi:s,wireApi:c,models:u,providerModelAliases:f})});if(e.success){d.success(`${p(`providerTestConnectionSuccess`)} (${e.latencyMs}ms)`);return}let r=[`provider=${e.provider}`,`latency=${e.latencyMs}ms`];e.model&&r.push(`model=${e.model}`),d.error(`${p(`providerTestConnectionFailed`)}: ${e.message} | ${r.join(` | `)}`)}catch(e){let t=e instanceof Error?e.message:String(e);d.error(`${p(`providerTestConnectionFailed`)}: ${t}`)}},[a,n,o,u,f,t,s,m,c]);return{discoverModels:(0,Y.useCallback)(async()=>{if(!t)return null;if(r&&!n.trim()&&!i)return d.error(p(`providerModelsApiKeyRequired`)),null;try{let e=await h.mutateAsync({provider:t,data:Pe({apiKey:n,apiBase:a,extraHeaders:o})});return v({key:g,models:e.models}),d.success(p(`providerModelsFetchSuccess`)),e.models}catch(e){if(e instanceof l&&(e.details?.upstreamStatus===401||e.details?.upstreamStatus===403))return d.error(p(`providerModelsAuthorizationFailed`)),null;let t=e instanceof Error?e.message:String(e);return d.error(`${p(`providerModelsFetchFailed`)}: ${t}`),null}},[a,n,r,i,h,g,o,t]),fetchedModels:_?.key===g?_.models:[],isDiscoveringModels:h.isPending,isTestPending:m.isPending,testConnection:y}}var $=t();function Xe({value:e,onChange:t,className:n}){let a=e?Object.entries(e):[],o=(e,n,r)=>{let i=[...a];i[e]=[n,r],t(Object.fromEntries(i))},s=()=>{t({...e,"":``})},l=e=>{let n=a.filter((t,n)=>n!==e);t(Object.fromEntries(n))};return(0,$.jsxs)(`div`,{className:r(`space-y-2`,n),children:[a.map(([e,t],n)=>(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(i,{type:`text`,value:e,onChange:e=>o(n,e.target.value,t),placeholder:p(`headerName`),className:`flex-1`}),(0,$.jsx)(i,{type:`text`,value:t,onChange:t=>o(n,e,t.target.value),placeholder:p(`headerValue`),className:`flex-1`}),(0,$.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>l(n),children:(0,$.jsx)(I,{className:`h-4 w-4 text-red-500`})})]},n)),(0,$.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:[(0,$.jsx)(j,{className:`h-4 w-4 mr-2`}),p(`add`)]})]})}function Ze(e){let{value:t,onChange:n,options:r}=e;return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map(e=>{let r=e.value===t;return(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.value),"aria-pressed":r,className:`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${r?`border-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:e.label},e.value)})})}function Qe(e){let{showAdvanced:t,onShowAdvancedChange:n,supportsWireApi:r,wireApiLabel:i,wireApi:a,onWireApiChange:o,shouldUseWireApiPills:c,wireApiSelectOptions:l,extraHeadersLabel:u,extraHeaders:d,onExtraHeadersChange:f}=e;return(0,$.jsxs)(`div`,{className:`border-t border-border/70 pt-4`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(N,{className:`h-3.5 w-3.5`}),p(`providerAdvancedSettings`)]}),(0,$.jsx)(v,{className:`h-4 w-4 transition-transform ${t?`rotate-180`:``}`})]}),t?(0,$.jsxs)(`div`,{className:`mt-4 space-y-5`,children:[r?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`wireApi`,className:`text-sm font-medium text-foreground`,children:i}),c?(0,$.jsx)(Ze,{value:a,onChange:e=>o(e),options:l}):(0,$.jsxs)(T,{value:a,onValueChange:e=>o(e),children:[(0,$.jsx)(S,{className:`rounded-xl`,children:(0,$.jsx)(x,{})}),(0,$.jsx)(C,{children:l.map(e=>(0,$.jsx)(w,{value:e.value,children:e.label},e.value))})]})]}):null,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{className:`text-sm font-medium text-foreground`,children:u}),(0,$.jsx)(Xe,{value:d,onChange:f}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerExtraHeadersHelpShort`)})]})]}):null]})}function $e({isSet:e,className:t,value:n,onChange:a,placeholder:o,...s}){let[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=typeof n==`string`&&n.length>0;return(0,$.jsxs)(`div`,{className:`relative`,children:[e&&!p&&!d?(0,$.jsx)(`div`,{onClick:()=>f(!0),className:r(`flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-500 cursor-text items-center pr-12`,t),children:`••••••••••••`}):(0,$.jsx)(i,{type:l?`text`:`password`,className:r(`pr-12`,t),value:n,onChange:a,onBlur:()=>{p||f(!1)},placeholder:o,autoFocus:d,...s}),(0,$.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex gap-1`,children:(e||p)&&(0,$.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>u(!l),children:l?(0,$.jsx)(xe,{className:`h-4 w-4`}):(0,$.jsx)(D,{className:`h-4 w-4`})})})]})}function et(e){let{apiKey:t,apiKeyRequired:n,apiKeySet:r,apiKeyPlaceholder:i,providerAuth:a,providerAuthNote:o,providerAuthMethodOptions:l,providerAuthMethodsCount:u,selectedAuthMethodHint:d,shouldUseAuthMethodPills:f,resolvedAuthMethodId:m,onAuthMethodChange:h,onStartProviderAuth:g,onImportProviderAuthFromCli:_,startPending:v,importPending:y,authSessionId:b,authStatusMessage:E,onApiKeyChange:D}=e,O=n?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`apiKey`,className:`text-sm font-medium text-foreground`,children:p(`apiKey`)}),(0,$.jsx)($e,{id:`apiKey`,value:t,isSet:r,onChange:e=>D(e.target.value),placeholder:i,className:`rounded-xl`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`leaveBlankToKeepUnchanged`)})]}):null;return a?.kind===`device_code`?(0,$.jsxs)($.Fragment,{children:[O,(0,$.jsxs)(`div`,{className:`space-y-2 rounded-xl bg-muted/45 p-3`,children:[(0,$.jsx)(s,{className:`text-sm font-medium text-foreground`,children:a.displayName||p(`providerAuthSectionTitle`)}),o?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null,u>1?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{className:`text-xs font-medium text-foreground`,children:p(`providerAuthMethodLabel`)}),f?(0,$.jsx)(Ze,{value:m,onChange:h,options:l}):(0,$.jsxs)(T,{value:m,onValueChange:h,children:[(0,$.jsx)(S,{className:`h-8 rounded-lg`,children:(0,$.jsx)(x,{placeholder:p(`providerAuthMethodPlaceholder`)})}),(0,$.jsx)(C,{children:l.map(e=>(0,$.jsx)(w,{value:e.value,children:e.label},e.value))})]}),d?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d}):null]}):null,(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:g,disabled:v||!!b,children:p(v?`providerAuthStarting`:b?`providerAuthAuthorizing`:`providerAuthAuthorizeInBrowser`)}),a.supportsCliImport?(0,$.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:_,disabled:y,children:p(y?`providerAuthImporting`:`providerAuthImportFromCli`)}):null,b?(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p(`providerAuthSessionLabel`),`: `,b.slice(0,8),`…`]}):null]}),E?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:E}):null]})]}):O}function tt(e){let{providerName:t,models:n,aliases:r,fetchedModels:i=[],onModelsChange:a}=e,o=q({pollWhileRefreshing:!0,refreshOnMount:!0}),s=t?o.data?.providers[t]:void 0,c=i.length>0?`fetched`:`background`,l=(0,Y.useMemo)(()=>Be(n,c===`fetched`?i:s?.models??[],r),[r,s?.models,i,n,c]);return{addSuggestedModels:(0,Y.useCallback)(e=>{let t=ze(n,e,r);t.addedCount>0&&a(t.models)},[r,n,a]),hasSuggestionError:!!(s?.lastError&&!s.fetchedAt),isCheckingSuggestions:!!(t&&(o.isLoading||o.data?.refreshing&&!s)),suggestedModels:l,suggestionSource:c}}function nt(e){let{models:t,modelConfig:n,onModelsChange:r,onRemoveModel:i,onToggleModelThinkingLevel:a,onSetModelThinkingDefault:c,onSetModelVision:l,thinkingLevels:u,formatThinkingLevelLabel:d}=e,[f,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(()=>new Set),_=(0,Y.useMemo)(()=>t.filter(e=>h.has(e)),[t,h]),v=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},y=()=>{m(!1),g(new Set)};return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`flex min-h-7 flex-wrap items-center justify-end gap-2`,children:f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`mr-auto text-xs text-muted-foreground`,children:p(`providerModelsSuggestionsSelected`).replace(`{count}`,String(_.length))}),(0,$.jsx)(`button`,{type:`button`,className:`text-xs font-medium text-primary hover:text-primary/80`,onClick:()=>g(_.length===t.length?new Set:new Set(t)),children:p(_.length===t.length?`providerModelsClearSelection`:`providerModelsSelectAll`)}),(0,$.jsx)(`button`,{type:`button`,className:`text-xs font-medium text-muted-foreground hover:text-foreground`,onClick:y,children:p(`cancel`)}),(0,$.jsxs)(`button`,{type:`button`,disabled:_.length===0,className:`inline-flex items-center gap-1 rounded-md bg-destructive/10 px-2 py-1 text-xs font-medium text-destructive transition-colors hover:bg-destructive/15 disabled:cursor-not-allowed disabled:opacity-45`,onClick:()=>{_.length!==0&&(r(t.filter(e=>!h.has(e))),y())},children:[(0,$.jsx)(I,{className:`h-3 w-3`}),p(`providerModelsRemoveSelected`)]})]}):(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground`,onClick:()=>m(!0),children:[(0,$.jsx)(I,{className:`h-3 w-3`}),p(`providerModelsBulkRemove`)]})}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>{if(f)return(0,$.jsxs)(`label`,{className:`inline-flex max-w-full cursor-pointer items-center gap-2 rounded-full border border-border/55 bg-muted/45 px-3 py-1.5 hover:bg-muted/70`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:h.has(e),onChange:()=>v(e),"aria-label":p(`providerModelsSuggestionSelect`).replace(`{model}`,e),className:`h-3.5 w-3.5 shrink-0 accent-primary`}),(0,$.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-foreground sm:max-w-[220px]`,children:e})]},e);let t=n[e],r=t?.thinking,m=r?.supported??[],g=r?.default??null,_=t?.vision===!0;return(0,$.jsxs)(`div`,{className:`group inline-flex max-w-full items-center gap-1 rounded-full border border-border/55 bg-muted/45 px-3 py-1.5`,children:[(0,$.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-foreground sm:max-w-[220px]`,children:e}),(0,$.jsxs)(V,{children:[(0,$.jsx)(z,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":p(`providerModelThinkingTitle`),title:p(`providerModelThinkingTitle`),children:(0,$.jsx)(N,{className:`h-3 w-3`})})}),(0,$.jsxs)(B,{className:`w-80 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted/50 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:p(`providerModelVisionTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelVisionHint`)})]}),(0,$.jsx)(o,{checked:_,onCheckedChange:t=>l(e,t)})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:p(`providerModelThinkingTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelThinkingHint`)})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(t=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(e,t),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${m.includes(t)?`border-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:d(t)},t))}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(s,{className:`text-xs font-medium text-foreground`,children:p(`providerModelThinkingDefault`)}),(0,$.jsxs)(T,{value:g??`__none__`,onValueChange:t=>c(e,t===`__none__`?null:t),disabled:m.length===0,children:[(0,$.jsx)(S,{className:`h-8 rounded-lg text-xs`,children:(0,$.jsx)(x,{})}),(0,$.jsxs)(C,{children:[(0,$.jsx)(w,{value:`__none__`,children:p(`providerModelThinkingDefaultNone`)}),m.map(e=>(0,$.jsx)(w,{value:e,children:d(e)},e))]})]}),m.length===0?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelThinkingNoSupported`)}):null]})]})]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":p(`remove`),children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e)})}),f?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerModelsRemoveSaveHint`)}):null]})}var rt=20,it=50,at=50;function ot(e){let{expanded:t,fetchedTotal:n,models:r,source:a,onExpandedChange:o,onAddModels:s}=e,[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(()=>new Set),f=(0,Y.useMemo)(()=>{let e=c.trim().toLowerCase();return e?r.filter(t=>t.toLowerCase().includes(e)):r},[r,c]),m=f.slice(0,at),h=(0,Y.useMemo)(()=>r.filter(e=>u.has(e)),[r,u]),g=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=e=>{e.length!==0&&(s(e),l(``),d(new Set))},b=a===`fetched`?`providerModelsFetchedSuggestionsSummary`:`providerModelsSuggestionsSummary`;return a===`fetched`&&r.length===0?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-xl bg-muted/35 px-3 py-2 text-xs text-muted-foreground`,role:`status`,children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,$.jsx)(`span`,{children:p(`providerModelsFetchedAllConfigured`).replace(`{count}`,String(n))})]}):(0,$.jsxs)(`div`,{className:`rounded-xl bg-muted/35 p-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":t,className:`flex min-w-0 flex-1 items-center gap-1.5 rounded-lg px-2 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground`,onClick:()=>o(!t),children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:p(b).replace(`{count}`,String(r.length))}),(0,$.jsx)(y,{className:`h-3.5 w-3.5 shrink-0 transition-transform ${t?`rotate-90`:``}`})]}),r.length<=it?(0,$.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-lg px-2 py-1.5 text-xs font-medium text-primary transition-colors hover:bg-primary/10`,onClick:()=>v(r),children:p(`providerModelsSuggestionsAddAll`)}):null]}),t?(0,$.jsxs)(`div`,{className:`px-1 pb-1`,children:[r.length>rt?(0,$.jsxs)(`div`,{className:`relative px-2 pb-1 pt-1.5`,children:[(0,$.jsx)(_,{className:`pointer-events-none absolute left-4 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(i,{value:c,onChange:e=>l(e.target.value),placeholder:p(`providerModelsSuggestionsSearchPlaceholder`),className:`h-8 rounded-lg pl-8 text-xs`})]}):null,(0,$.jsxs)(`div`,{className:`custom-scrollbar max-h-44 overflow-y-auto overscroll-contain`,children:[m.map(e=>(0,$.jsxs)(`label`,{className:`grid min-w-0 cursor-pointer grid-cols-[auto_minmax(0,1fr)] items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-muted/70`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:u.has(e),onChange:()=>g(e),"aria-label":p(`providerModelsSuggestionSelect`).replace(`{model}`,e),className:`h-3.5 w-3.5 shrink-0 accent-primary`}),(0,$.jsx)(`span`,{className:`block min-w-0 truncate text-xs text-foreground`,title:e,children:e})]},e)),f.length===0?(0,$.jsx)(`p`,{className:`px-2 py-4 text-center text-xs text-muted-foreground`,children:p(`providerModelsSuggestionsSearchEmpty`)}):null]}),f.length>m.length?(0,$.jsx)(`p`,{className:`px-2 pt-1 text-[11px] text-muted-foreground`,children:p(`providerModelsSuggestionsShowing`).replace(`{visible}`,String(m.length)).replace(`{count}`,String(f.length))}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 pt-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`providerModelsSuggestionsSelected`).replace(`{count}`,String(h.length))}),(0,$.jsx)(`button`,{type:`button`,disabled:h.length===0,className:`shrink-0 rounded-md bg-primary/10 px-2 py-1 text-[11px] font-medium text-primary transition-colors hover:bg-primary/15 disabled:cursor-not-allowed disabled:opacity-45`,onClick:()=>v(h),children:p(`providerModelsSuggestionsAddSelected`)})]}),(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] text-muted-foreground`,children:p(`providerModelsSuggestionsSaveHint`)})]}):null]})}function st({hasFetchedCatalog:e,hasSuggestionError:t,supportsModelDiscovery:n}){return!n||!t||e?null:(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-xl bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,$.jsx)(E,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),p(`providerModelsSuggestionsFailed`)]})}function ct(e){let{providerName:t,providerModelAliases:n,models:r,modelConfig:a,modelDraft:o,showModelInput:l,onModelDraftChange:u,onShowModelInputChange:d,onAddModel:f,onModelsChange:m,supportsModelDiscovery:h,onDiscoverModels:g,isDiscoveringModels:_,fetchedModels:v,onRemoveModel:y,onToggleModelThinkingLevel:b,onSetModelThinkingDefault:x,onSetModelVision:S,thinkingLevels:C,formatThinkingLevelLabel:w}=e,[T,E]=(0,Y.useState)(!1),D=(0,Y.useRef)(null),{addSuggestedModels:O,hasSuggestionError:k,isCheckingSuggestions:N,suggestedModels:P,suggestionSource:F}=tt({providerName:t,models:r,aliases:n,fetchedModels:v,onModelsChange:m}),I=async()=>{await g()&&(E(!0),window.requestAnimationFrame(()=>{let e=D.current;e?.scrollIntoView?.({behavior:`smooth`,block:`center`}),e?.focus({preventScroll:!0})}))},R=v.length>0;return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(s,{className:`text-sm font-medium text-foreground`,children:p(`providerModelsTitle`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[h?(0,$.jsxs)(`button`,{type:`button`,onClick:I,disabled:_,className:`flex items-center gap-1 text-xs font-medium text-primary transition-colors hover:text-primary/80 disabled:cursor-wait disabled:opacity-60`,children:[(0,$.jsx)(M,{className:`h-3 w-3 ${_?`animate-spin`:``}`}),p(_?`providerModelsFetching`:`providerModelsFetch`)]}):null,l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),className:`flex items-center gap-1 text-xs font-medium text-primary hover:text-primary/80`,children:[(0,$.jsx)(j,{className:`h-3 w-3`}),p(`providerAddModel`)]})]})]}),l?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{value:o,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f()),e.key===`Escape`&&(d(!1),u(``))},placeholder:p(`providerModelInputPlaceholder`),className:`flex-1 rounded-xl`,autoFocus:!0}),(0,$.jsx)(c,{type:`button`,size:`sm`,onClick:f,disabled:o.trim().length===0,children:p(`add`)}),(0,$.jsx)(c,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{d(!1),u(``)},children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}):null,(0,$.jsx)(st,{hasFetchedCatalog:R,hasSuggestionError:k,supportsModelDiscovery:h}),h&&N&&!R?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-xl bg-muted/35 px-3 py-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(A,{className:`h-3.5 w-3.5 animate-spin`}),p(`providerModelsSuggestionsChecking`)]}):h&&(P.length>0||R)?(0,$.jsx)(`div`,{ref:D,tabIndex:-1,"aria-live":`polite`,className:`scroll-m-4 outline-none`,children:(0,$.jsx)(ot,{expanded:T,fetchedTotal:v.length,models:P,source:F,onExpandedChange:E,onAddModels:O})}):null,r.length===0?(0,$.jsxs)(`div`,{className:`rounded-xl bg-muted/35 px-4 py-6 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:p(`providerModelsEmptyShort`)}),l?null:(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:`mt-2 text-sm font-medium text-primary hover:text-primary/80`,children:p(`providerAddFirstModel`)})]}):(0,$.jsx)(nt,{models:r,modelConfig:a,onModelsChange:m,onRemoveModel:y,onToggleModelThinkingLevel:b,onSetModelThinkingDefault:x,onSetModelVision:S,thinkingLevels:C,formatThinkingLevelLabel:w})]})}function lt({apiKeyRequired:e=!0,apiKeySet:t,className:n,enabled:r}){if(!r)return(0,$.jsx)(m,{status:`inactive`,label:p(`disabled`),className:n});let i=!e||t;return(0,$.jsx)(m,{status:i?`ready`:`setup`,label:p(i?`statusReady`:`statusSetup`),className:n})}function ut(e){let{context:t,language:n,providerTitle:r,providerDisplayName:a,apiKey:o,apiBase:l,extraHeaders:u,wireApi:d,models:f,modelConfig:m,modelDraft:h,showAdvanced:g,showModelInput:_,resolvedAuthMethodId:v,authSessionId:y,authStatusMessage:b,hasChanges:x,isDeletePending:S,isUpdatePending:C,connectivity:w,startPending:T,importPending:E,onProviderDisplayNameChange:D,onApiKeyChange:O,onApiBaseChange:k,onAuthMethodChange:A,onStartProviderAuth:j,onImportProviderAuthFromCli:M,onModelDraftChange:N,onShowModelInputChange:P,onAddModel:F,onModelsChange:L,onRemoveModel:R,onToggleModelThinkingLevel:z,onSetModelThinkingDefault:B,onSetModelVision:V,onShowAdvancedChange:H,onWireApiChange:ee,onExtraHeadersChange:U,onDeleteProvider:W,onSubmit:G,onTestConnection:K}=e,q=t.providerAuthMethods.find(e=>e.id===v);return(0,$.jsxs)(ge,{children:[(0,$.jsx)(pe,{className:`px-5 py-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`truncate text-lg font-semibold text-foreground`,children:r}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:W,disabled:S,className:`text-muted-foreground/70 transition-colors hover:text-red-500`,title:p(`providerDelete`),children:(0,$.jsx)(I,{className:`h-4 w-4`})}),(0,$.jsx)(lt,{enabled:t.currentEnabled,apiKeyRequired:t.resolvedProviderConfig.apiKeyRequired,apiKeySet:t.resolvedProviderConfig.apiKeySet})]})]})}),(0,$.jsxs)(`form`,{onSubmit:G,className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(_e,{className:`space-y-4 px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`providerDisplayName`,className:`text-sm font-medium text-foreground`,children:p(`providerDisplayName`)}),(0,$.jsx)(i,{id:`providerDisplayName`,type:`text`,value:a,onChange:e=>D(e.target.value),placeholder:t.defaultDisplayName||p(`providerDisplayNamePlaceholder`),className:`rounded-xl`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p(`providerDisplayNameHelpShort`)})]}),(0,$.jsx)(et,{apiKey:o,apiKeyRequired:t.resolvedProviderConfig.apiKeyRequired!==!1,apiKeySet:t.resolvedProviderConfig.apiKeySet,apiKeyPlaceholder:t.apiKeyHint?.placeholder??p(`enterApiKey`),providerAuth:t.providerAuth,providerAuthNote:t.providerAuth?.note?.[n]||t.providerAuth?.note?.en||t.providerAuth?.displayName||``,providerAuthMethodOptions:t.providerAuthMethodOptions,providerAuthMethodsCount:t.providerAuthMethods.length,selectedAuthMethodHint:q?.hint?.[n]||q?.hint?.en||``,shouldUseAuthMethodPills:t.shouldUseAuthMethodPills,resolvedAuthMethodId:v,onAuthMethodChange:A,onStartProviderAuth:j,onImportProviderAuthFromCli:M,startPending:T,importPending:E,authSessionId:y,authStatusMessage:b,onApiKeyChange:O}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(s,{htmlFor:`apiBase`,className:`text-sm font-medium text-foreground`,children:p(`apiBase`)}),(0,$.jsx)(i,{id:`apiBase`,type:`text`,value:l,onChange:e=>k(e.target.value),placeholder:t.defaultApiBase||t.apiBaseHint?.placeholder||`https://api.example.com`,className:`rounded-xl`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.apiBaseHelpText})]}),(0,$.jsx)(ct,{providerName:t.providerConfig?.providerId??``,providerModelAliases:t.providerModelAliases,models:f,modelConfig:m,modelDraft:h,showModelInput:_,onModelDraftChange:N,onShowModelInputChange:P,onAddModel:F,onModelsChange:L,supportsModelDiscovery:t.supportsModelDiscovery,onDiscoverModels:w.discoverModels,isDiscoveringModels:w.isDiscoveringModels,fetchedModels:w.fetchedModels,onRemoveModel:R,onToggleModelThinkingLevel:z,onSetModelThinkingDefault:B,onSetModelVision:V,thinkingLevels:te,formatThinkingLevelLabel:Fe},t.providerConfig?.providerId),(0,$.jsx)(Qe,{showAdvanced:g,onShowAdvancedChange:H,supportsWireApi:t.supportsWireApi,wireApiLabel:p(`wireApi`),wireApi:d,onWireApiChange:ee,shouldUseWireApiPills:t.shouldUseWireApiPills,wireApiSelectOptions:t.wireApiSelectOptions,extraHeadersLabel:p(`extraHeaders`),extraHeaders:u,onExtraHeadersChange:U})]}),(0,$.jsx)(ye,{children:(0,$.jsxs)(de,{align:`between`,children:[(0,$.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:K,disabled:w.isTestPending,children:[(0,$.jsx)(be,{className:`mr-1.5 h-3.5 w-3.5`}),w.isTestPending?p(`providerTestingConnection`):p(`providerTestConnection`)]}),(0,$.jsx)(c,{type:`submit`,size:`sm`,disabled:C||!x,children:p(C?`saving`:x?`save`:`unchanged`)})]})})]})]})}function dt({providerName:e,onProviderDeleted:t}){let{data:n}=ce(),{data:r}=ne(),{data:i}=le(),a=f(),o=(0,Y.useMemo)(()=>qe({providerName:e,providersView:n,templatesView:r,schema:i,language:a}),[a,e,n,i,r]);if(!e||!o.providerConfig)return(0,$.jsx)(ve,{children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:p(`providersSelectTitle`)}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:p(`providersSelectDescription`)})]})});let s=JSON.stringify({providerConfig:o.providerConfig,currentApiBase:o.currentApiBase,currentEditableModels:o.currentEditableModels,currentModelConfig:o.currentModelConfig,currentWireApi:o.currentWireApi,effectiveDisplayName:o.effectiveDisplayName,preferredAuthMethodId:o.preferredAuthMethodId});return(0,$.jsx)(ft,{providerName:e,onProviderDeleted:t,context:o,language:a},s)}function ft({providerName:e,onProviderDeleted:t,context:n,language:r}){let i=ue(),a=G(),{currentApiBase:o,currentEditableModels:s,currentHeaders:c,currentModelConfig:l,currentWireApi:u,defaultApiBase:d,effectiveDisplayName:f,providerAuth:m,providerAuthMethods:h,providerModelAliases:g,resolvedProviderConfig:_,preferredAuthMethodId:v,supportsWireApi:y}=n,[b,x]=(0,Y.useState)(``),[S,C]=(0,Y.useState)(o),[w,T]=(0,Y.useState)(_.extraHeaders||null),[E,D]=(0,Y.useState)(u),[O,k]=(0,Y.useState)(s),[A,j]=(0,Y.useState)(l),[M,N]=(0,Y.useState)(``),[P,F]=(0,Y.useState)(f),[I,L]=(0,Y.useState)(!1),[R,z]=(0,Y.useState)(!1),[B,V]=(0,Y.useState)(v),H=Ye({providerName:e,apiKey:b,apiKeyRequired:_.apiKeyRequired!==!1,apiKeySet:_.apiKeySet,apiBase:S,extraHeaders:w,supportsWireApi:y,wireApi:E,models:O,providerModelAliases:g}),ee=P.trim()||f||e||p(`providersSelectPlaceholder`),U=(0,Y.useMemo)(()=>{if(!h.length)return``;let e=B.trim();return e&&h.some(t=>t.id===e)?e:v||h[0]?.id||``},[B,v,h]),{authSessionId:W,authStatusMessage:te,importAuthFromCli:K,importPending:q,startAuth:ne,startPending:re}=Je({providerName:e,providerAuth:m,resolvedAuthMethodId:U}),ie=(0,Y.useMemo)(()=>je({providerName:e,apiKey:b,apiBase:S,currentApiBase:o,extraHeaders:w,currentHeaders:c,supportsWireApi:y,wireApi:E,currentWireApi:u,models:O,currentEditableModels:s,modelConfig:A,currentModelConfig:l,providerDisplayName:P,effectiveDisplayName:f}),[e,b,S,o,w,c,y,E,u,O,s,A,l,P,f]),ae=e=>{k(e),j(t=>Oe(t,e))};return(0,$.jsx)(ut,{context:n,language:r,providerTitle:ee,providerDisplayName:P,apiKey:b,apiBase:S,extraHeaders:w,wireApi:E,models:O,modelConfig:A,modelDraft:M,showAdvanced:I,showModelInput:R,resolvedAuthMethodId:U,authSessionId:W,authStatusMessage:te,hasChanges:ie,isDeletePending:a.isPending,isUpdatePending:i.isPending,connectivity:H,startPending:re,importPending:q,onProviderDisplayNameChange:F,onApiKeyChange:x,onApiBaseChange:C,onAuthMethodChange:V,onStartProviderAuth:ne,onImportProviderAuthFromCli:K,onModelDraftChange:N,onShowModelInputChange:z,onAddModel:()=>{let e=Re(O,M,g);ae(e.models),N(e.draft)},onModelsChange:ae,onRemoveModel:e=>{let t=Ve(O,A,e);k(t.models),j(t.modelConfig)},onToggleModelThinkingLevel:(e,t)=>{j(n=>He(n,e,t))},onSetModelThinkingDefault:(e,t)=>{j(n=>Ue(n,e,t))},onSetModelVision:(e,t)=>{j(n=>We(n,e,t))},onShowAdvancedChange:L,onWireApiChange:D,onExtraHeadersChange:T,onDeleteProvider:async()=>{if(e&&window.confirm(p(`providerDeleteConfirm`)))try{await a.mutateAsync({provider:e}),t?.(e)}catch{}},onSubmit:t=>{t.preventDefault(),e&&i.mutate({provider:e,data:Me({providerName:e,apiKey:b,apiBase:S,currentApiBase:o,defaultApiBase:d,extraHeaders:w,currentHeaders:c,supportsWireApi:y,wireApi:E,currentWireApi:u,models:O,currentEditableModels:s,modelConfig:A,currentModelConfig:l,providerDisplayName:P,effectiveDisplayName:f})})},onTestConnection:H.testConnection})}function pt(e){if(!e)return null;try{let t=new URL(e);return`${t.host}${t.pathname&&t.pathname!==`/`?t.pathname:``}`}catch{return e.replace(/^https?:\/\//,``)}}function mt(e,t=[]){let n=new Map(t.map((e,t)=>[e,t]));return e.map((e,t)=>({provider:e,index:t})).sort((e,t)=>{let r=n.get(e.provider.providerId),i=n.get(t.provider.providerId);if(r!==void 0||i!==void 0)return(r??2**53-1)-(i??2**53-1);let a=e.provider.providerType===`nextclaw`?1:0,o=t.provider.providerType===`nextclaw`?1:0;return a===o?e.index-t.index:a-o}).map(({provider:e})=>e)}function ht(e){let t=e.findIndex(e=>e.providerType===`zhipu`),n=e.findIndex(e=>e.providerType===`dashscope-coding-plan`);return e.map((e,t)=>({template:e,index:t})).sort((e,r)=>{let i=({template:e,index:r})=>e.providerType===`nextclaw`?2**53-1:e.providerType===`deepseek`&&n>=0?n-.5:e.providerType===`mimo`&&t>=0?t+.5:r;return i(e)-i(r)}).map(({template:e})=>e)}function gt(){let{isMobile:e}=k(),{data:t}=ce(),{data:n}=ne(),s=ie(),l=G(),u=ue(),[d,f]=(0,Y.useState)(null),[g,v]=(0,Y.useState)(null),[y,x]=(0,Y.useState)(!1),[S,C]=(0,Y.useState)([]),[w,T]=(0,Y.useState)(``),E=(0,Y.useMemo)(()=>mt(Object.values(t?.providers??{}),S),[t?.providers,S]),D=(0,Y.useMemo)(()=>n?.providerTemplates??[],[n?.providerTemplates]),A=(0,Y.useMemo)(()=>ht(D),[D]),M=(0,Y.useMemo)(()=>new Map(D.map(e=>[e.providerType,e])),[D]),N=(0,Y.useMemo)(()=>{let e=w.trim().toLowerCase();return E.filter(t=>{if(!e)return!0;let n=t.providerType?M.get(t.providerType):null;return(t.displayName?.trim()||n?.displayName||t.providerId).toLowerCase().includes(e)||t.providerId.toLowerCase().includes(e)})},[E,w,M]),P=(0,Y.useMemo)(()=>d&&N.some(e=>e.providerId===d)?d:e?null:N[0]?.providerId??null,[N,e,d]);return!t||!n?(0,$.jsx)(a,{title:p(`providersPageTitle`),description:p(`providersPageDescription`),layout:`split`,children:(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:p(`providersLoading`)})}):(0,$.jsxs)(a,{title:p(`providersPageTitle`),description:p(`providersPageDescription`),layout:`split`,children:[(0,$.jsxs)(fe,{className:`md:min-h-0`,compactView:d?`detail`:`list`,onMobileBack:()=>f(null),mobileListLabel:p(`providersPageTitle`),children:[(0,$.jsxs)(he,{children:[(0,$.jsx)(pe,{className:`space-y-3 px-4 pb-3 pt-4`,children:(0,$.jsxs)(V,{open:y,onOpenChange:x,children:[(0,$.jsx)(z,{asChild:!0,children:(0,$.jsxs)(c,{type:`button`,variant:`outline`,className:`w-full justify-center`,disabled:s.isPending,children:[(0,$.jsx)(j,{className:`mr-2 h-4 w-4`}),s.isPending?p(`saving`):p(`providerAdd`)]})}),(0,$.jsxs)(B,{className:`w-[42rem] max-w-[calc(100vw-2rem)] p-3`,align:`start`,children:[(0,$.jsx)(`div`,{className:`mb-2 px-1 text-xs font-semibold text-muted-foreground`,children:p(`providerTemplatePickerTitle`)}),(0,$.jsxs)(`div`,{className:`grid max-h-[24rem] grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-3`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-dashed border-border/70 bg-muted/20 px-3 py-2 text-left transition-colors hover:border-border hover:bg-muted/45`,onClick:async()=>{try{let e=await s.mutateAsync({data:{providerType:null}});T(``),f(e.providerId),C(t=>[e.providerId,...t.filter(t=>t!==e.providerId)]),x(!1)}catch{}},children:[(0,$.jsx)(h,{name:`custom`,className:`h-8 w-8 rounded-lg border border-border/60 bg-muted/50`}),(0,$.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:p(`providerAddCustom`)})]}),A.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-border/55 bg-muted/15 px-3 py-2 text-left transition-colors hover:border-border/80 hover:bg-muted/40`,onClick:async()=>{try{let t=await s.mutateAsync({data:{providerType:e.providerType}});T(``),f(t.providerId),C(e=>[t.providerId,...e.filter(e=>e!==t.providerId)]),x(!1)}catch{}},children:[(0,$.jsx)(h,{name:e.providerType,src:e.logo?`/logos/${e.logo}`:null,className:`h-8 w-8 rounded-lg border border-border/55 bg-background`,imgClassName:`h-4 w-4 object-contain`}),(0,$.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:e.displayName||e.providerType})]},e.providerType))]})]})]})}),(0,$.jsx)(`div`,{className:`border-b border-border/70 px-4 py-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(_,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/70`}),(0,$.jsx)(i,{value:w,onChange:e=>T(e.target.value),placeholder:p(`providersFilterPlaceholder`),className:`h-10 rounded-xl pl-9`})]})}),(0,$.jsxs)(_e,{className:`space-y-2 p-3`,children:[N.map(e=>{let t=e.providerType?M.get(e.providerType):null,n=e.enabled!==!1,i=H(e),a=e.displayName?.trim()||t?.displayName||e.providerId,s=pt(e.apiBase||t?.defaultApiBase||``)||p(`providersDefaultDescription`);return(0,$.jsx)(`div`,{onClick:()=>f(e.providerId),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),f(e.providerId))},role:`button`,tabIndex:0,className:r(`group w-full rounded-xl p-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40`,P===e.providerId?`bg-background/95 text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-background/65 hover:text-foreground`),children:(0,$.jsxs)(`div`,{className:`relative min-h-10`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 pr-20`,children:[(0,$.jsx)(h,{name:e.providerType??e.providerId,src:t?.logo?`/logos/${t.logo}`:null,className:`h-10 w-10 rounded-lg bg-background/80`,imgClassName:`h-5 w-5 object-contain`,fallback:(0,$.jsx)(`span`,{className:`text-sm font-semibold uppercase text-muted-foreground`,children:e.providerId[0]})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`truncate text-sm font-semibold text-foreground`,children:a}),(0,$.jsx)(`p`,{className:`truncate font-mono text-[10px] text-muted-foreground/65`,children:e.providerId}),(0,$.jsxs)(`p`,{className:`line-clamp-1 text-[11px] text-muted-foreground`,children:[s,` · `,e.models?.length??0]})]})]}),(0,$.jsxs)(`div`,{className:`absolute right-0 top-0 flex items-center gap-1.5 opacity-70 transition-opacity group-hover:opacity-100`,children:[(0,$.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(o,{checked:n,disabled:u.isPending,title:p(n?`disabled`:`enabled`),className:`h-[18px] w-8`,thumbClassName:`h-4 w-4 data-[state=checked]:translate-x-4`,onCheckedChange:t=>{u.mutateAsync({provider:e.providerId,data:{enabled:t},silentSuccess:!0})}})}),(0,$.jsxs)(V,{children:[(0,$.jsx)(z,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted hover:text-foreground`,onClick:e=>e.stopPropagation(),title:p(`more`),children:(0,$.jsx)(b,{className:`h-4 w-4`})})}),(0,$.jsx)(B,{className:`w-40 p-1`,align:`end`,onClick:e=>e.stopPropagation(),children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-2 text-sm text-red-600 hover:bg-red-50`,onClick:()=>v(e.providerId),children:[(0,$.jsx)(I,{className:`h-4 w-4`}),p(`providerDelete`)]})})]})]}),(0,$.jsx)(m,{status:n?i?`ready`:`setup`:`inactive`,label:p(n?i?`statusReady`:`statusSetup`:`disabled`),className:`absolute bottom-0 right-0 justify-end`})]})},e.providerId)}),N.length===0?(0,$.jsx)(me,{icon:O,title:p(`providersNoMatch`)}):null]})]}),(0,$.jsx)(dt,{providerName:P??void 0,onProviderDeleted:e=>{C(t=>t.filter(t=>t!==e)),e===P&&f(null)}})]}),(0,$.jsx)(F,{open:!!g,onOpenChange:e=>{e||v(null)},title:p(`providerDelete`),description:g??void 0,confirmLabel:p(`delete`),variant:`destructive`,onCancel:()=>v(null),onConfirm:()=>{g&&l.mutateAsync({provider:g}).then(()=>{C(e=>e.filter(e=>e!==g)),g===P&&f(null),v(null)})}})]})}export{gt as ProvidersConfigPage};
@@ -1 +1 @@
1
- import{A as e,i as t,t as n}from"./utils-CBZPzC_b.js";import{Jt as r,Yt as i,qt as a,vn as o}from"./api-BWFOIoUm.js";import{ut as s}from"./app-presenter-provider-CDRBc_lQ.js";import{s as c}from"./i18n-ClHx6jwj.js";import{t as l}from"./createLucideIcon-BNKf0_kc.js";import{a as u,o as d}from"./theme-provider-BvpXGXWH.js";import{t as f}from"./x-DdXOqLnX.js";var p=l(`Smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),m=`nextclaw-pwa-install-banner-dismissed`,h=`nextclaw-pwa-install-banner-dismissed-until`;function g(){let e=y();return e?e.getItem(`nextclaw-pwa-install-banner-dismissed`)===`1`?!0:b(e):!1}function _(){let e=y();e?.setItem(m,`1`),e?.removeItem(h)}function v(){let e=y();e?.removeItem(m),e?.removeItem(h)}function y(){if(typeof window>`u`)return null;try{return window.localStorage}catch{return null}}function b(e){let t=e.getItem(h);if(!t)return!1;let n=Number.parseInt(t,10);return e.removeItem(h),!Number.isFinite(n)||n<=Date.now()?!1:(e.setItem(m,`1`),!0)}function x(){return{initialized:!1,installability:`unsupported`,installMethod:`none`,blockedReason:`missing-browser-support`,dismissedInstallPrompt:g()}}var S=t(()=>x()),C=new class{constructor(){this.started=!1,this.deferredPrompt=null,this.displayModeMediaQuery=null,this.start=()=>{this.started||typeof window>`u`||(this.started=!0,window.addEventListener(`beforeinstallprompt`,this.handleBeforeInstallPrompt),window.addEventListener(`appinstalled`,this.handleAppInstalled),typeof window.matchMedia==`function`&&(this.displayModeMediaQuery=window.matchMedia(`(display-mode: standalone)`),this.bindDisplayModeListener(this.displayModeMediaQuery,this.handleDisplayModeChanged)),this.refreshState())},this.stop=()=>{!this.started||typeof window>`u`||(window.removeEventListener(`beforeinstallprompt`,this.handleBeforeInstallPrompt),window.removeEventListener(`appinstalled`,this.handleAppInstalled),this.displayModeMediaQuery&&=(this.unbindDisplayModeListener(this.displayModeMediaQuery,this.handleDisplayModeChanged),null),this.deferredPrompt=null,this.started=!1)},this.resetForTests=()=>{this.stop(),S.setState(x())},this.refreshState=()=>{let e=this.resolveInstallability();S.setState(t=>({...t,initialized:!0,installability:e.installability,installMethod:e.installMethod,blockedReason:e.blockedReason,dismissedInstallPrompt:g()}))},this.dismissInstallPrompt=()=>{_(),S.setState({dismissedInstallPrompt:!0})},this.promptInstall=async()=>{let e=this.resolveInstallability();if(e.installability!==`available`)return`unavailable`;if(e.installMethod===`manual`||!this.deferredPrompt)return`manual`;this.deferredPrompt.prompt();let t=await this.deferredPrompt.userChoice;return this.deferredPrompt=null,t.outcome===`accepted`?(v(),this.refreshState(),o.success(c(`pwaInstallAccepted`)),`accepted`):(this.dismissInstallPrompt(),this.refreshState(),`dismissed`)},this.handleBeforeInstallPrompt=e=>{e.preventDefault(),this.deferredPrompt=e,this.refreshState()},this.handleAppInstalled=()=>{this.deferredPrompt=null,v(),S.setState({dismissedInstallPrompt:!0}),o.success(c(`pwaInstalledToast`)),this.refreshState()},this.handleDisplayModeChanged=()=>{this.refreshState()},this.resolveInstallability=()=>this.isDevelopmentServer()?{installability:`unsupported`,installMethod:`none`,blockedReason:`dev-server`}:this.hasDesktopHost()?{installability:`suppressed`,installMethod:`none`,blockedReason:`desktop-host`}:this.isStandalone()?{installability:`installed`,installMethod:`none`,blockedReason:null}:this.hasInstallSurfaceSupport()?this.isEligibleInstallContext()?{installability:`available`,installMethod:this.deferredPrompt?`prompt`:`manual`,blockedReason:null}:{installability:`unsupported`,installMethod:`none`,blockedReason:`insecure-context`}:{installability:`unsupported`,installMethod:`none`,blockedReason:`missing-browser-support`},this.hasDesktopHost=()=>typeof window<`u`&&!!window.nextclawDesktop,this.hasInstallSurfaceSupport=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&`serviceWorker`in navigator,this.isEligibleInstallContext=()=>typeof window>`u`?!1:window.isSecureContext||this.isTrustedLocalhost(window.location.hostname),this.isTrustedLocalhost=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`||e===`[::1]`,this.isDevelopmentServer=()=>typeof window<`u`&&!1,this.isStandalone=()=>{if(typeof window>`u`)return!1;let e=window.navigator;return typeof window.matchMedia==`function`&&window.matchMedia(`(display-mode: standalone)`).matches||e.standalone===!0},this.bindDisplayModeListener=(e,t)=>{if(`addEventListener`in e){e.addEventListener(`change`,t);return}e.addListener?.(t)},this.unbindDisplayModeListener=(e,t)=>{if(`removeEventListener`in e){e.removeEventListener(`change`,t);return}e.removeListener?.(t)}}},w=e();function T(){let e=S(e=>e.installability);return(0,w.jsx)(`span`,{className:n(`inline-flex items-center rounded-full border px-3 py-1 text-xs font-medium`,e===`installed`?`bg-emerald-50 text-emerald-700 border-emerald-200`:e===`available`?`bg-amber-50 text-amber-700 border-amber-200`:`bg-gray-100 text-gray-600 border-gray-200`),children:E(e)})}function E(e){return c(e===`available`?`pwaInstallStatusAvailable`:e===`installed`?`pwaInstallStatusInstalled`:e===`suppressed`?`pwaInstallStatusDesktopHost`:`pwaInstallStatusUnavailable`)}function D(e,t,n){return c(e===`installed`?`pwaInstallCardInstalled`:e===`suppressed`?`pwaInstallCardSuppressed`:e===`available`&&t===`prompt`?`pwaInstallCardPrompt`:e===`available`?`pwaInstallCardManual`:n===`insecure-context`?`pwaInstallCardInsecureContext`:n===`dev-server`?`pwaInstallCardDevServer`:`pwaInstallCardUnsupported`)}function O(){let e=S(e=>e.installability),t=S(e=>e.installMethod),n=S(e=>e.blockedReason);return(0,w.jsx)(r,{title:c(`pwaInstallTitle`),description:c(`pwaInstallDescription`),actions:(0,w.jsx)(T,{}),children:(0,w.jsx)(a,{children:(0,w.jsxs)(`div`,{className:`space-y-4 p-4`,children:[(0,w.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:D(e,t,n)}),e===`available`&&t===`prompt`?(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,w.jsxs)(i,{type:`button`,className:`gap-2`,onClick:()=>void C.promptInstall(),children:[(0,w.jsx)(s,{className:`h-4 w-4`}),c(`pwaInstallAction`)]}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`pwaInstallPromptHint`)})]}):null,e===`available`&&t===`manual`?(0,w.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-background/65 p-4`,children:[(0,w.jsx)(p,{className:`mt-0.5 h-4 w-4 text-muted-foreground`}),(0,w.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:c(`pwaInstallManualHint`)})]}):null]})})})}function k(){let e=S(e=>e.installability),t=S(e=>e.installMethod),n=S(e=>e.dismissedInstallPrompt);return e!==`available`||t!==`prompt`||n?null:(0,w.jsxs)(`div`,{className:`fixed bottom-5 right-5 z-50 w-[min(420px,calc(100vw-2rem))] rounded-[26px] border border-gray-200 bg-white/95 p-5 shadow-2xl backdrop-blur-xl`,children:[(0,w.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,w.jsxs)(`div`,{className:`space-y-1`,children:[(0,w.jsx)(`p`,{className:`text-sm font-semibold text-gray-900`,children:c(`pwaInstallBannerTitle`)}),(0,w.jsx)(`p`,{className:`text-sm leading-6 text-gray-600`,children:c(`pwaInstallBannerDescription`)})]}),(0,w.jsx)(`button`,{type:`button`,"aria-label":c(`pwaInstallDismiss`),className:`rounded-full p-1 text-gray-400 transition hover:bg-gray-100 hover:text-gray-600`,onClick:()=>{C.dismissInstallPrompt()},children:(0,w.jsx)(f,{className:`h-4 w-4`})})]}),(0,w.jsxs)(`div`,{className:`mt-4 flex items-center gap-3`,children:[(0,w.jsxs)(i,{type:`button`,size:`sm`,className:`gap-2`,onClick:()=>{C.promptInstall()},children:[(0,w.jsx)(s,{className:`h-4 w-4`}),c(`pwaInstallAction`)]}),(0,w.jsx)(i,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{C.dismissInstallPrompt()},children:c(`pwaInstallDismiss`)})]})]})}var A=new class{constructor(){this.started=!1,this.registration=null,this.start=async()=>{if(!(this.started||typeof window>`u`)&&(this.started=!0,!(!(`serviceWorker`in navigator)||!this.isEligibleInstallContext()))){if(this.isDevelopmentServer()){await this.cleanupDevelopmentRegistrations();return}try{this.registration=await navigator.serviceWorker.register(`/sw.js`)}catch{return}}},this.stop=()=>{!this.started||typeof window>`u`||!(`serviceWorker`in navigator)||(this.started=!1,this.registration=null)},this.isEligibleInstallContext=()=>window.isSecureContext||this.isTrustedLocalhost(window.location.hostname),this.isTrustedLocalhost=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`||e===`[::1]`,this.isDevelopmentServer=()=>!1,this.cleanupDevelopmentRegistrations=async()=>{if(typeof navigator.serviceWorker.getRegistrations!=`function`)return;let e=(await navigator.serviceWorker.getRegistrations()).filter(e=>[e.active?.scriptURL,e.installing?.scriptURL,e.waiting?.scriptURL].filter(e=>!!e).some(e=>e.endsWith(`/sw.js`)));await Promise.all(e.map(async e=>await e.unregister())),e.length>0&&await this.clearNextClawCaches()},this.clearNextClawCaches=async()=>{if(typeof window>`u`||!(`caches`in window)||typeof caches.keys!=`function`)return;let e=await caches.keys();await Promise.all(e.filter(e=>e.startsWith(`nextclaw-ui-`)).map(async e=>await caches.delete(e)))}}},j=!1;function M(){j||typeof window>`u`||(j=!0,C.start(),A.start())}var N={natural:`#FAF9F7`,work:`#FFFFFF`,minimal:`#FFFFFF`,warm:`#FAF8F4`,cool:`#F8FAFC`,dawn:`#FAF7F4`,graphite:`#F8F8F7`,night:`#101318`,charcoal:`#1C1C1C`,island:`#FBF8ED`,probe:`#FEFCF6`},P=new class{constructor(){this.syncTheme=e=>{if(typeof document>`u`)return;let t=N[e];this.updateThemeMeta(t),this.updateSurfaceBackgrounds(t),document.documentElement.style.colorScheme=u(e)},this.syncCurrentTheme=()=>{if(typeof document>`u`)return;let e=document.documentElement.getAttribute(`data-theme`);this.syncTheme(d(e)??`work`)},this.updateThemeMeta=e=>{let t=document.querySelector(`meta[name="theme-color"]`);t instanceof HTMLMetaElement&&(t.content=e)},this.updateSurfaceBackgrounds=e=>{document.documentElement.style.backgroundColor=e,document.body.style.backgroundColor=e;let t=document.getElementById(`root`);t&&(t.style.backgroundColor=e)}}};export{O as i,M as n,k as r,P as t};
1
+ import{A as e,i as t,t as n}from"./utils-CBZPzC_b.js";import{Jt as r,Yt as i,qt as a,vn as o}from"./api-DqzQ-_3w.js";import{ut as s}from"./app-presenter-provider-V0xnU_Wb.js";import{s as c}from"./i18n-20rSH40D.js";import{t as l}from"./createLucideIcon-BNKf0_kc.js";import{a as u,o as d}from"./theme-provider-DzvAi3pe.js";import{t as f}from"./x-DdXOqLnX.js";var p=l(`Smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),m=`nextclaw-pwa-install-banner-dismissed`,h=`nextclaw-pwa-install-banner-dismissed-until`;function g(){let e=y();return e?e.getItem(`nextclaw-pwa-install-banner-dismissed`)===`1`?!0:b(e):!1}function _(){let e=y();e?.setItem(m,`1`),e?.removeItem(h)}function v(){let e=y();e?.removeItem(m),e?.removeItem(h)}function y(){if(typeof window>`u`)return null;try{return window.localStorage}catch{return null}}function b(e){let t=e.getItem(h);if(!t)return!1;let n=Number.parseInt(t,10);return e.removeItem(h),!Number.isFinite(n)||n<=Date.now()?!1:(e.setItem(m,`1`),!0)}function x(){return{initialized:!1,installability:`unsupported`,installMethod:`none`,blockedReason:`missing-browser-support`,dismissedInstallPrompt:g()}}var S=t(()=>x()),C=new class{constructor(){this.started=!1,this.deferredPrompt=null,this.displayModeMediaQuery=null,this.start=()=>{this.started||typeof window>`u`||(this.started=!0,window.addEventListener(`beforeinstallprompt`,this.handleBeforeInstallPrompt),window.addEventListener(`appinstalled`,this.handleAppInstalled),typeof window.matchMedia==`function`&&(this.displayModeMediaQuery=window.matchMedia(`(display-mode: standalone)`),this.bindDisplayModeListener(this.displayModeMediaQuery,this.handleDisplayModeChanged)),this.refreshState())},this.stop=()=>{!this.started||typeof window>`u`||(window.removeEventListener(`beforeinstallprompt`,this.handleBeforeInstallPrompt),window.removeEventListener(`appinstalled`,this.handleAppInstalled),this.displayModeMediaQuery&&=(this.unbindDisplayModeListener(this.displayModeMediaQuery,this.handleDisplayModeChanged),null),this.deferredPrompt=null,this.started=!1)},this.resetForTests=()=>{this.stop(),S.setState(x())},this.refreshState=()=>{let e=this.resolveInstallability();S.setState(t=>({...t,initialized:!0,installability:e.installability,installMethod:e.installMethod,blockedReason:e.blockedReason,dismissedInstallPrompt:g()}))},this.dismissInstallPrompt=()=>{_(),S.setState({dismissedInstallPrompt:!0})},this.promptInstall=async()=>{let e=this.resolveInstallability();if(e.installability!==`available`)return`unavailable`;if(e.installMethod===`manual`||!this.deferredPrompt)return`manual`;this.deferredPrompt.prompt();let t=await this.deferredPrompt.userChoice;return this.deferredPrompt=null,t.outcome===`accepted`?(v(),this.refreshState(),o.success(c(`pwaInstallAccepted`)),`accepted`):(this.dismissInstallPrompt(),this.refreshState(),`dismissed`)},this.handleBeforeInstallPrompt=e=>{e.preventDefault(),this.deferredPrompt=e,this.refreshState()},this.handleAppInstalled=()=>{this.deferredPrompt=null,v(),S.setState({dismissedInstallPrompt:!0}),o.success(c(`pwaInstalledToast`)),this.refreshState()},this.handleDisplayModeChanged=()=>{this.refreshState()},this.resolveInstallability=()=>this.isDevelopmentServer()?{installability:`unsupported`,installMethod:`none`,blockedReason:`dev-server`}:this.hasDesktopHost()?{installability:`suppressed`,installMethod:`none`,blockedReason:`desktop-host`}:this.isStandalone()?{installability:`installed`,installMethod:`none`,blockedReason:null}:this.hasInstallSurfaceSupport()?this.isEligibleInstallContext()?{installability:`available`,installMethod:this.deferredPrompt?`prompt`:`manual`,blockedReason:null}:{installability:`unsupported`,installMethod:`none`,blockedReason:`insecure-context`}:{installability:`unsupported`,installMethod:`none`,blockedReason:`missing-browser-support`},this.hasDesktopHost=()=>typeof window<`u`&&!!window.nextclawDesktop,this.hasInstallSurfaceSupport=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&`serviceWorker`in navigator,this.isEligibleInstallContext=()=>typeof window>`u`?!1:window.isSecureContext||this.isTrustedLocalhost(window.location.hostname),this.isTrustedLocalhost=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`||e===`[::1]`,this.isDevelopmentServer=()=>typeof window<`u`&&!1,this.isStandalone=()=>{if(typeof window>`u`)return!1;let e=window.navigator;return typeof window.matchMedia==`function`&&window.matchMedia(`(display-mode: standalone)`).matches||e.standalone===!0},this.bindDisplayModeListener=(e,t)=>{if(`addEventListener`in e){e.addEventListener(`change`,t);return}e.addListener?.(t)},this.unbindDisplayModeListener=(e,t)=>{if(`removeEventListener`in e){e.removeEventListener(`change`,t);return}e.removeListener?.(t)}}},w=e();function T(){let e=S(e=>e.installability);return(0,w.jsx)(`span`,{className:n(`inline-flex items-center rounded-full border px-3 py-1 text-xs font-medium`,e===`installed`?`bg-emerald-50 text-emerald-700 border-emerald-200`:e===`available`?`bg-amber-50 text-amber-700 border-amber-200`:`bg-gray-100 text-gray-600 border-gray-200`),children:E(e)})}function E(e){return c(e===`available`?`pwaInstallStatusAvailable`:e===`installed`?`pwaInstallStatusInstalled`:e===`suppressed`?`pwaInstallStatusDesktopHost`:`pwaInstallStatusUnavailable`)}function D(e,t,n){return c(e===`installed`?`pwaInstallCardInstalled`:e===`suppressed`?`pwaInstallCardSuppressed`:e===`available`&&t===`prompt`?`pwaInstallCardPrompt`:e===`available`?`pwaInstallCardManual`:n===`insecure-context`?`pwaInstallCardInsecureContext`:n===`dev-server`?`pwaInstallCardDevServer`:`pwaInstallCardUnsupported`)}function O(){let e=S(e=>e.installability),t=S(e=>e.installMethod),n=S(e=>e.blockedReason);return(0,w.jsx)(r,{title:c(`pwaInstallTitle`),description:c(`pwaInstallDescription`),actions:(0,w.jsx)(T,{}),children:(0,w.jsx)(a,{children:(0,w.jsxs)(`div`,{className:`space-y-4 p-4`,children:[(0,w.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:D(e,t,n)}),e===`available`&&t===`prompt`?(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,w.jsxs)(i,{type:`button`,className:`gap-2`,onClick:()=>void C.promptInstall(),children:[(0,w.jsx)(s,{className:`h-4 w-4`}),c(`pwaInstallAction`)]}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`pwaInstallPromptHint`)})]}):null,e===`available`&&t===`manual`?(0,w.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-background/65 p-4`,children:[(0,w.jsx)(p,{className:`mt-0.5 h-4 w-4 text-muted-foreground`}),(0,w.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:c(`pwaInstallManualHint`)})]}):null]})})})}function k(){let e=S(e=>e.installability),t=S(e=>e.installMethod),n=S(e=>e.dismissedInstallPrompt);return e!==`available`||t!==`prompt`||n?null:(0,w.jsxs)(`div`,{className:`fixed bottom-5 right-5 z-50 w-[min(420px,calc(100vw-2rem))] rounded-[26px] border border-gray-200 bg-white/95 p-5 shadow-2xl backdrop-blur-xl`,children:[(0,w.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,w.jsxs)(`div`,{className:`space-y-1`,children:[(0,w.jsx)(`p`,{className:`text-sm font-semibold text-gray-900`,children:c(`pwaInstallBannerTitle`)}),(0,w.jsx)(`p`,{className:`text-sm leading-6 text-gray-600`,children:c(`pwaInstallBannerDescription`)})]}),(0,w.jsx)(`button`,{type:`button`,"aria-label":c(`pwaInstallDismiss`),className:`rounded-full p-1 text-gray-400 transition hover:bg-gray-100 hover:text-gray-600`,onClick:()=>{C.dismissInstallPrompt()},children:(0,w.jsx)(f,{className:`h-4 w-4`})})]}),(0,w.jsxs)(`div`,{className:`mt-4 flex items-center gap-3`,children:[(0,w.jsxs)(i,{type:`button`,size:`sm`,className:`gap-2`,onClick:()=>{C.promptInstall()},children:[(0,w.jsx)(s,{className:`h-4 w-4`}),c(`pwaInstallAction`)]}),(0,w.jsx)(i,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{C.dismissInstallPrompt()},children:c(`pwaInstallDismiss`)})]})]})}var A=new class{constructor(){this.started=!1,this.registration=null,this.start=async()=>{if(!(this.started||typeof window>`u`)&&(this.started=!0,!(!(`serviceWorker`in navigator)||!this.isEligibleInstallContext()))){if(this.isDevelopmentServer()){await this.cleanupDevelopmentRegistrations();return}try{this.registration=await navigator.serviceWorker.register(`/sw.js`)}catch{return}}},this.stop=()=>{!this.started||typeof window>`u`||!(`serviceWorker`in navigator)||(this.started=!1,this.registration=null)},this.isEligibleInstallContext=()=>window.isSecureContext||this.isTrustedLocalhost(window.location.hostname),this.isTrustedLocalhost=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`||e===`[::1]`,this.isDevelopmentServer=()=>!1,this.cleanupDevelopmentRegistrations=async()=>{if(typeof navigator.serviceWorker.getRegistrations!=`function`)return;let e=(await navigator.serviceWorker.getRegistrations()).filter(e=>[e.active?.scriptURL,e.installing?.scriptURL,e.waiting?.scriptURL].filter(e=>!!e).some(e=>e.endsWith(`/sw.js`)));await Promise.all(e.map(async e=>await e.unregister())),e.length>0&&await this.clearNextClawCaches()},this.clearNextClawCaches=async()=>{if(typeof window>`u`||!(`caches`in window)||typeof caches.keys!=`function`)return;let e=await caches.keys();await Promise.all(e.filter(e=>e.startsWith(`nextclaw-ui-`)).map(async e=>await caches.delete(e)))}}},j=!1;function M(){j||typeof window>`u`||(j=!0,C.start(),A.start())}var N={natural:`#FAF9F7`,work:`#FFFFFF`,minimal:`#FFFFFF`,warm:`#FAF8F4`,cool:`#F8FAFC`,dawn:`#FAF7F4`,graphite:`#F8F8F7`,night:`#101318`,charcoal:`#1C1C1C`,island:`#FBF8ED`,probe:`#FEFCF6`},P=new class{constructor(){this.syncTheme=e=>{if(typeof document>`u`)return;let t=N[e];this.updateThemeMeta(t),this.updateSurfaceBackgrounds(t),document.documentElement.style.colorScheme=u(e)},this.syncCurrentTheme=()=>{if(typeof document>`u`)return;let e=document.documentElement.getAttribute(`data-theme`);this.syncTheme(d(e)??`work`)},this.updateThemeMeta=e=>{let t=document.querySelector(`meta[name="theme-color"]`);t instanceof HTMLMetaElement&&(t.content=e)},this.updateSurfaceBackgrounds=e=>{document.documentElement.style.backgroundColor=e,document.body.style.backgroundColor=e;let t=document.getElementById(`root`);t&&(t.style.backgroundColor=e)}}};export{O as i,M as n,k as r,P as t};
@@ -0,0 +1 @@
1
+ import{et as e}from"./app-presenter-provider-V0xnU_Wb.js";export{e as RemoteAccessPage};
@@ -1 +1 @@
1
- import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n}from"./utils-CBZPzC_b.js";import{Gt as r,Jt as i,Kt as a,Qt as o,Ut as s,Yt as c,cn as l,fn as u,pn as d,qt as f,un as p,vn as m}from"./api-BWFOIoUm.js";import{S as h}from"./mcp-marketplace-page-D75hPmzO.js";import{rt as g,tt as _,v,y}from"./app-presenter-provider-CDRBc_lQ.js";import{s as b}from"./i18n-ClHx6jwj.js";import{a as x,i as S,n as C,r as w,t as T}from"./select-CG5YWnwe.js";import{t as E}from"./loader-circle-K1BDdHR5.js";import{t as D}from"./plus-LA8-jpxP.js";import{t as O}from"./rotate-cw-B6xm41Wn.js";import{t as k}from"./save-fff_WpY2.js";import{i as A}from"./pwa-dXn0s_lD.js";import{t as j}from"./trash-2-BPPYt2NV.js";import{b as M,t as ee}from"./use-config-C8ZkQiTc.js";import{t as N}from"./form-actions-BRESe-m_.js";var P=e(n(),1),F=t(),I={healthy:`runtimeControlHealthy`,"starting-service":`runtimeControlStartingService`,"restarting-service":`runtimeControlRestartingService`,"stopping-service":`runtimeControlStoppingService`,"restarting-app":`runtimeControlRestartingApp`,recovering:`runtimeControlRecovering`,failed:`runtimeControlFailed`},L={running:`runtimeControlServiceRunning`,stopped:`runtimeControlServiceStopped`,starting:`runtimeControlServiceStarting`,stopping:`runtimeControlServiceStopping`,restarting:`runtimeControlServiceRestarting`},R={"desktop-embedded":`runtimeControlEnvironmentDesktop`,"managed-local-service":`runtimeControlEnvironmentManagedService`,"self-hosted-web":`runtimeControlEnvironmentSelfHosted`,"shared-web":`runtimeControlEnvironmentSharedWeb`};function z(e){return b(I[e]??`runtimeControlUnavailable`)}function B(e){return b(L[e]??`runtimeControlServiceUnknown`)}function V(e){return b(R[e.environment])}function H(e,t){return t===`start-service`?e?.canStartService:t===`stop-service`?e?.canStopService:e?.canRestartService}function U(e){return e?[{action:`start-service`,capability:e.canStartService,label:b(`runtimeControlStartService`),icon:`play`},{action:`restart-service`,capability:e.canRestartService,label:b(`runtimeControlRestartService`),icon:`rotate`},{action:`stop-service`,capability:e.canStopService,label:b(`runtimeControlStopService`),icon:`square`,variant:`destructive`},{action:`restart-app`,capability:e.canRestartApp,label:b(`runtimeControlRestartApp`),icon:`rotate`,variant:`secondary`}].filter(e=>e.capability.available||!!e.capability.reasonIfUnavailable):[]}function W(e){let{busy:t,icon:n}=e;return t?(0,F.jsx)(E,{className:`mr-2 h-4 w-4 animate-spin`}):n===`play`?(0,F.jsx)(g,{className:`mr-2 h-4 w-4`}):n===`square`?(0,F.jsx)(_,{className:`mr-2 h-4 w-4`}):(0,F.jsx)(O,{className:`mr-2 h-4 w-4`})}function G(){let{busy:e,busyAction:t,controlView:n,errorMessage:r,pendingRestart:a,visibleLifecycle:o,visibleMessage:s,visibleServiceState:p}=l(),h=U(n??void 0),g=async e=>{let t=H(n,e);if(!t?.available){m.error(d(t?.reasonIfUnavailable)??b(`runtimeControlLoadFailed`));return}if(!(e===`stop-service`&&t.requiresConfirmation&&!window.confirm(b(`runtimeControlStopServiceConfirm`))))try{let t=await u.runRuntimeControlAction(e);m.success(d(t.message)??t.message)}catch(e){let t=e instanceof Error?e.message:b(`runtimeControlActionFailed`);m.error(`${b(`runtimeControlActionFailed`)}: ${t}`)}},_=async()=>{if(!n?.canRestartApp.available){m.error(d(n?.canRestartApp.reasonIfUnavailable)??b(`runtimeRestartAppUnavailable`));return}if(window.confirm(b(`runtimeControlRestartAppConfirm`)))try{let e=await u.runRuntimeControlAction(`restart-app`);m.success(d(e.message)??e.message)}catch(e){let t=e instanceof Error?e.message:b(`runtimeControlActionFailed`);m.error(`${b(`runtimeControlActionFailed`)}: ${t}`)}};return(0,F.jsx)(i,{title:b(`runtimeControlTitle`),description:b(`runtimeControlDescription`),children:(0,F.jsxs)(f,{children:[(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 md:flex-row md:items-center md:justify-between`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:B(p)}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:n?V(n):b(`runtimeControlLoading`)})]}),(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:z(o)}),n?.managementHint?(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d(n.managementHint)}):null,r&&!e?(0,F.jsx)(`p`,{className:`text-sm text-amber-700`,children:r}):null]}),a?(0,F.jsxs)(`div`,{className:`space-y-3 bg-amber-50/75 p-4 dark:bg-amber-950/20`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-amber-900`,children:b(`runtimeControlPendingRestartTitle`)}),(0,F.jsx)(`p`,{className:`text-sm text-amber-800`,children:b(`runtimeControlPendingRestartDescription`)}),a.changedPaths.length>0?(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-[0.08em] text-amber-700`,children:b(`runtimeControlPendingRestartPaths`)}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:a.changedPaths.map(e=>(0,F.jsx)(`span`,{className:`rounded-full bg-background/80 px-2.5 py-1 text-xs text-amber-800 dark:text-amber-300`,children:e},e))})]}):null]}):null,(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsx)(`div`,{className:`flex flex-col gap-3 md:flex-row md:flex-wrap`,children:h.map(n=>(0,F.jsxs)(c,{type:`button`,variant:n.variant??`default`,onClick:()=>{if(n.action===`restart-app`){_();return}g(n.action)},disabled:!n.capability.available||e,children:[(0,F.jsx)(W,{icon:n.icon,busy:t===n.action}),n.label]},n.action))}),h.filter(e=>!e.capability.available&&e.capability.reasonIfUnavailable).map(e=>(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d(e.capability.reasonIfUnavailable)},`${e.action}-reason`))]})]})})}function K(e){let{description:t,title:n}=e;return(0,F.jsx)(h,{tone:`neutral`,title:n,description:t})}function q(e){let{children:t}=e;return(0,F.jsx)(i,{title:b(`runtimePresenceTitle`),description:b(`runtimePresenceDescription`),children:(0,F.jsx)(f,{children:t})})}function J(){let e=p().runtimeControlView?.environment,t=y(e=>e.supported),n=y(e=>e.initialized),r=y(e=>e.busyAction),i=y(e=>e.snapshot);return(0,P.useEffect)(()=>{if(e===`desktop-embedded`){v.start();return}v.markUnsupported()},[e]),e===`desktop-embedded`?(0,F.jsxs)(q,{children:[(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(h,{tone:`neutral`,title:b(`runtimePresenceBehaviorLabel`),description:i?.closeToBackground?b(`runtimePresenceBehaviorBackground`):b(`runtimePresenceBehaviorQuit`),className:`rounded-xl`})}),!n||t&&!i?(0,F.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:b(`runtimePresenceLoading`)}):null,i?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(a,{title:b(`runtimePresenceCloseToBackground`),description:b(`runtimePresenceCloseToBackgroundHelp`),control:(0,F.jsx)(s,{id:`runtime-presence-close-background`,"aria-label":b(`runtimePresenceCloseToBackground`),checked:i.closeToBackground,disabled:r===`saving-preferences`,onCheckedChange:e=>{v.updatePreferences({closeToBackground:e})}})}),(0,F.jsx)(a,{title:b(`runtimePresenceLaunchAtLogin`),description:i.supportsLaunchAtLogin?b(`runtimePresenceLaunchAtLoginHelp`):i.launchAtLoginReason??b(`runtimePresenceLaunchAtLoginUnavailable`),control:(0,F.jsx)(s,{id:`runtime-presence-launch-login`,"aria-label":b(`runtimePresenceLaunchAtLogin`),checked:i.launchAtLogin,disabled:!i.supportsLaunchAtLogin||r===`saving-preferences`,onCheckedChange:e=>{v.updatePreferences({launchAtLogin:e})}})})]}):null]}):e===`managed-local-service`?(0,F.jsx)(q,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(K,{title:b(`runtimePresenceManagedLocalTitle`),description:b(`runtimePresenceManagedLocalDescription`)})})}):e===`self-hosted-web`?(0,F.jsx)(q,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(K,{title:b(`runtimePresenceSelfHostedTitle`),description:b(`runtimePresenceSelfHostedDescription`)})})}):e===`shared-web`?(0,F.jsx)(q,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(K,{title:b(`runtimePresenceSharedTitle`),description:b(`runtimePresenceSharedDescription`)})})}):(0,F.jsx)(q,{children:(0,F.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:b(`runtimePresenceLoading`)})})}function te(){return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(G,{}),(0,F.jsx)(J,{}),(0,F.jsx)(A,{})]})}var Y={wireDialect:`acp`,processScope:`per-session`,command:``,args:[`acp`],env:{},cwd:``,startupTimeoutMs:8e3,probeTimeoutMs:3e3,requestTimeoutMs:12e4};function X(){return{id:``,default:!1,workspace:``,model:``,runtime:``,contextTokens:void 0}}function Z(){return{agentId:``,match:{channel:``,accountId:``}}}function Q(){return{id:``,enabled:!0,label:``,type:`narp-stdio`,config:Y,configText:JSON.stringify(Y,null,2)}}function ne(e){return{id:e.id??``,default:!!e.default,displayName:e.displayName??``,description:e.description??``,avatar:e.avatar??``,workspace:e.workspace??``,model:e.model??``,runtime:e.runtime??e.engine??``,contextTokens:e.contextTokens}}function re(e){return{agentId:e.agentId??``,match:{channel:e.match?.channel??``,accountId:e.match?.accountId??``,peer:e.match?.peer?{kind:e.match.peer.kind,id:e.match.peer.id}:void 0}}}function ie(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:void 0}function ae(e){return{companionEnabled:e.companion?.enabled===!0,agents:(e.agents.list??[]).map(ne),bindings:(e.bindings??[]).map(re),runtimeEntries:Object.entries(e.agents.runtimes?.entries??{}).map(([e,t])=>({id:e,enabled:t.enabled!==!1,label:t.label??``,type:t.type,config:t.config??{},configText:JSON.stringify(t.config??{},null,2)})),dmScope:e.session?.dmScope??`per-channel-peer`,defaultContextTokens:e.agents.defaults.contextTokens??2e5,defaultEngine:e.agents.defaults.engine??`native`}}function oe(e){let t={id:e.id.trim()};e.default&&(t.default=!0),e.displayName?.trim()&&(t.displayName=e.displayName.trim()),e.description?.trim()&&(t.description=e.description.trim()),e.avatar?.trim()&&(t.avatar=e.avatar.trim()),e.workspace?.trim()&&(t.workspace=e.workspace.trim()),e.model?.trim()&&(t.model=e.model.trim());let n=e.runtime?.trim()??e.engine?.trim();return n&&(t.engine=n),typeof e.contextTokens==`number`&&(t.contextTokens=Math.max(1e3,e.contextTokens)),t}function $(e){let t=e.agents.map((e,t)=>{if(!e.id.trim())throw Error(b(`agentIdRequiredError`).replace(`{index}`,String(t)));return oe(e)}),n=t.map(e=>e.id).filter((e,t,n)=>n.indexOf(e)!==t);if(n.length>0)throw Error(`${b(`duplicateAgentId`)}: ${n[0]}`);let r=e.bindings.map((t,n)=>{let r=t.agentId.trim(),i=t.match.channel.trim(),a=t.match.accountId?.trim()??``,o=t.match.peer?.kind,s=t.match.peer?.id?.trim()??``;if(!r)throw Error(b(`bindingAgentIdRequired`).replace(`{index}`,String(n)));if(!e.knownAgentIds.has(r))throw Error(`${b(`bindingAgentIdNotFound`).replace(`{index}`,String(n))}: ${r}`);if(!i)throw Error(b(`bindingChannelRequired`).replace(`{index}`,String(n)));let c={agentId:r,match:{channel:i}};if(a&&(c.match.accountId=a),o){if(!s)throw Error(b(`bindingPeerIdRequired`).replace(`{index}`,String(n)));c.match.peer={kind:o,id:s}}return c}),i=e.runtimeEntries.reduce((e,t,n)=>{let r=t.id.trim(),i=t.type.trim();if(!r)throw Error(b(`runtimeEntryIdRequired`).replace(`{index}`,String(n)));if(!i)throw Error(b(`runtimeEntryTypeRequired`).replace(`{id}`,r));if(e[r])throw Error(`${b(`runtimeEntryDuplicate`)}: ${r}`);let a=t.configText.trim()?JSON.parse(t.configText):{};if(a&&(typeof a!=`object`||Array.isArray(a)))throw Error(b(`runtimeEntryConfigObjectRequired`).replace(`{id}`,r));return e[r]={enabled:t.enabled!==!1,...t.label?.trim()?{label:t.label.trim()}:{},type:i,config:a??{}},e},{});return{companion:{enabled:e.companionEnabled},agents:{defaults:{contextTokens:Math.max(1e3,e.defaultContextTokens),engine:e.defaultEngine.trim()||`native`},list:t,runtimes:{entries:i}},bindings:r,session:{dmScope:e.dmScope}}}function se({agents:e,onAddAgent:t,onRemoveAgent:n,onSetDefaultAgent:a,onUpdateAgent:o}){return(0,F.jsx)(i,{title:b(`agentList`),description:b(`agentListHelp`),actions:(0,F.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:[(0,F.jsx)(D,{className:`mr-2 h-4 w-4`}),b(`addAgent`)]}),children:(0,F.jsx)(f,{children:e.map((e,t)=>(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,F.jsx)(r,{value:e.id,onChange:e=>o(t,{id:e.target.value}),placeholder:b(`agentIdPlaceholder`)}),(0,F.jsx)(r,{value:e.workspace??``,onChange:e=>o(t,{workspace:e.target.value}),placeholder:b(`workspaceOverridePlaceholder`)}),(0,F.jsx)(r,{value:e.model??``,onChange:e=>o(t,{model:e.target.value}),placeholder:b(`modelOverridePlaceholder`)}),(0,F.jsx)(r,{value:e.runtime??e.engine??``,onChange:e=>o(t,{runtime:e.target.value}),placeholder:b(`engineOverridePlaceholder`)}),(0,F.jsx)(r,{type:`number`,min:1e3,step:1e3,value:e.contextTokens??``,onChange:e=>o(t,{contextTokens:ie(e.target.value)}),placeholder:b(`contextTokensPlaceholder`)})]}),(0,F.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,F.jsx)(s,{checked:!!e.default,onCheckedChange:e=>a(t,e)}),(0,F.jsx)(`span`,{children:b(`defaultAgent`)})]}),(0,F.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(t),children:[(0,F.jsx)(j,{className:`h-4 w-4 mr-1`}),b(`remove`)]})]})]},`${t}-${e.id}`))})})}function ce({bindings:e,onAddBinding:t,onRemoveBinding:n,onUpdateBinding:a}){return(0,F.jsx)(i,{title:b(`bindings`),description:b(`bindingsHelp`),actions:(0,F.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:[(0,F.jsx)(D,{className:`mr-2 h-4 w-4`}),b(`addBinding`)]}),children:(0,F.jsx)(f,{children:e.map((e,t)=>{let i=e.match.peer?.kind??``;return(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[(0,F.jsx)(r,{value:e.agentId,onChange:n=>a(t,{...e,agentId:n.target.value}),placeholder:b(`targetAgentIdPlaceholder`)}),(0,F.jsx)(r,{value:e.match.channel,onChange:n=>a(t,{...e,match:{...e.match,channel:n.target.value}}),placeholder:b(`channelPlaceholder`)}),(0,F.jsx)(r,{value:e.match.accountId??``,onChange:n=>a(t,{...e,match:{...e.match,accountId:n.target.value}}),placeholder:b(`accountIdOptionalPlaceholder`)}),(0,F.jsxs)(T,{value:i||`__none__`,onValueChange:n=>{let r=n===`__none__`?``:n;a(t,r?{...e,match:{...e.match,peer:{kind:r,id:e.match.peer?.id??``}}}:{...e,match:{...e.match,peer:void 0}})},children:[(0,F.jsx)(S,{children:(0,F.jsx)(x,{})}),(0,F.jsxs)(C,{children:[(0,F.jsx)(w,{value:`__none__`,children:b(`peerKindOptional`)}),(0,F.jsx)(w,{value:`direct`,children:b(`peerKindDirect`)}),(0,F.jsx)(w,{value:`group`,children:b(`peerKindGroup`)}),(0,F.jsx)(w,{value:`channel`,children:b(`peerKindChannel`)})]})]}),(0,F.jsx)(r,{value:e.match.peer?.id??``,onChange:n=>a(t,{...e,match:{...e.match,peer:i?{kind:i,id:n.target.value}:void 0}}),placeholder:b(`peerIdPlaceholder`)})]}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(t),children:[(0,F.jsx)(j,{className:`h-4 w-4 mr-1`}),b(`remove`)]})})]},`${t}-${e.agentId}`)})})})}function le({entries:e,onAddEntry:t,onRemoveEntry:n,onUpdateEntry:a}){return(0,F.jsx)(i,{title:b(`runtimeEntries`),description:b(`runtimeEntriesHelp`),actions:(0,F.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:[(0,F.jsx)(D,{className:`mr-2 h-4 w-4`}),b(`addRuntimeEntry`)]}),children:(0,F.jsx)(f,{children:e.map((e,t)=>(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,F.jsx)(r,{value:e.id,onChange:e=>a(t,{id:e.target.value}),placeholder:b(`runtimeEntryIdPlaceholder`)}),(0,F.jsx)(r,{value:e.label??``,onChange:e=>a(t,{label:e.target.value}),placeholder:b(`runtimeEntryLabelPlaceholder`)}),(0,F.jsx)(r,{value:e.type,onChange:e=>a(t,{type:e.target.value}),placeholder:b(`runtimeEntryTypePlaceholder`)}),(0,F.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg bg-background/65 px-3 py-2`,children:[(0,F.jsx)(`span`,{className:`text-sm text-foreground`,children:b(`enabled`)}),(0,F.jsx)(s,{checked:e.enabled!==!1,onCheckedChange:e=>a(t,{enabled:e})})]})]}),(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`label`,{className:`text-sm font-medium text-foreground`,children:b(`runtimeEntryConfigJson`)}),(0,F.jsx)(`textarea`,{className:`min-h-32 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-sm`,value:e.configText,onChange:e=>a(t,{configText:e.target.value}),spellCheck:!1})]}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsxs)(c,{type:`button`,variant:`outline`,onClick:()=>n(t),children:[(0,F.jsx)(j,{className:`mr-2 h-4 w-4`}),b(`delete`)]})})]},`${t}-${e.id||`runtime-entry`}`))})})}var ue=[{value:`main`,labelKey:`dmScopeMain`},{value:`per-peer`,labelKey:`dmScopePerPeer`},{value:`per-channel-peer`,labelKey:`dmScopePerChannelPeer`},{value:`per-account-channel-peer`,labelKey:`dmScopePerAccountChannelPeer`}];function de({companionEnabled:e,defaultContextTokens:t,defaultEngine:n,dmScope:o,onCompanionEnabledChange:c,onDefaultContextTokensChange:l,onDefaultEngineChange:u,onDmScopeChange:d}){return(0,F.jsx)(i,{title:b(`dmScope`),description:b(`dmScopeHelp`),children:(0,F.jsxs)(f,{children:[(0,F.jsx)(a,{title:b(`runtimeCompanionEnabled`),description:b(`runtimeCompanionEnabledHelp`),control:(0,F.jsx)(s,{checked:e,onCheckedChange:c})}),(0,F.jsx)(a,{title:b(`defaultContextTokens`),description:b(`defaultContextTokensHelp`),control:(0,F.jsx)(r,{type:`number`,min:1e3,step:1e3,value:t,onChange:e=>l(Math.max(1e3,Number.parseInt(e.target.value,10)||1e3)),className:`w-36`})}),(0,F.jsx)(a,{title:b(`defaultEngine`),description:b(`defaultEngineHelp`),control:(0,F.jsx)(r,{value:n,onChange:e=>u(e.target.value),placeholder:b(`defaultEnginePlaceholder`),className:`w-56`})}),(0,F.jsx)(a,{title:b(`dmScope`),control:(0,F.jsxs)(T,{value:o,onValueChange:e=>d(e),children:[(0,F.jsx)(S,{className:`w-56`,children:(0,F.jsx)(x,{})}),(0,F.jsx)(C,{children:ue.map(e=>(0,F.jsx)(w,{value:e.value,children:b(e.labelKey)},e.value))})]})})]})})}function fe({config:e,updateRuntime:t}){let n=(0,P.useMemo)(()=>ae(e),[e]),[r,i]=(0,P.useState)(n.agents),[a,s]=(0,P.useState)(n.bindings),[l,u]=(0,P.useState)(n.runtimeEntries),[d,f]=(0,P.useState)(n.dmScope),[p,h]=(0,P.useState)(n.companionEnabled),[g,_]=(0,P.useState)(n.defaultContextTokens),[v,y]=(0,P.useState)(n.defaultEngine),x=(0,P.useMemo)(()=>{let e=new Set([`main`]);return r.forEach(t=>{let n=t.id.trim();n&&e.add(n)}),e},[r]);return(0,F.jsxs)(o,{title:b(`runtimePageTitle`),description:b(`runtimePageDescription`),children:[(0,F.jsx)(te,{}),(0,F.jsx)(de,{companionEnabled:p,dmScope:d,defaultContextTokens:g,defaultEngine:v,onCompanionEnabledChange:h,onDmScopeChange:f,onDefaultContextTokensChange:_,onDefaultEngineChange:y}),(0,F.jsx)(le,{entries:l,onUpdateEntry:(e,t)=>u(n=>n.map((n,r)=>r===e?{...n,...t}:n)),onRemoveEntry:e=>u(t=>t.filter((t,n)=>n!==e)),onAddEntry:()=>u(e=>[...e,Q()])}),(0,F.jsx)(se,{agents:r,onUpdateAgent:(e,t)=>{i(n=>n.map((n,r)=>r===e?{...n,...t}:n))},onRemoveAgent:e=>i(t=>t.filter((t,n)=>n!==e)),onAddAgent:()=>i(e=>[...e,X()]),onSetDefaultAgent:(e,t)=>i(n=>t?n.map((t,n)=>({...t,default:n===e})):n.map((t,n)=>n===e?{...t,default:!1}:t))}),(0,F.jsx)(ce,{bindings:a,onUpdateBinding:(e,t)=>{s(n=>n.map((n,r)=>r===e?t:n))},onRemoveBinding:e=>s(t=>t.filter((t,n)=>n!==e)),onAddBinding:()=>s(e=>[...e,Z()])}),(0,F.jsx)(N,{children:(0,F.jsxs)(c,{type:`button`,size:`sm`,onClick:()=>{try{let e=$({companionEnabled:p,agents:r,bindings:a,runtimeEntries:l,dmScope:d,defaultContextTokens:g,defaultEngine:v,knownAgentIds:x});t.mutate({data:e})}catch(e){m.error(e instanceof Error?e.message:String(e))}},disabled:t.isPending,children:[(0,F.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5`}),t.isPending?b(`saving`):b(`saveRuntimeSettings`)]})})]})}function pe(){let{data:e,isLoading:t}=ee(),n=M();return t||!e?(0,F.jsx)(o,{title:b(`runtimePageTitle`),description:b(`runtimePageDescription`),children:(0,F.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:b(`runtimeLoading`)})}):(0,F.jsx)(fe,{config:e,updateRuntime:n})}export{pe as RuntimeConfig};
1
+ import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n}from"./utils-CBZPzC_b.js";import{Gt as r,Jt as i,Kt as a,Qt as o,Ut as s,Yt as c,cn as l,fn as u,pn as d,qt as f,un as p,vn as m}from"./api-DqzQ-_3w.js";import{S as h}from"./mcp-marketplace-page-FfIfEo6w.js";import{rt as g,tt as _,v,y}from"./app-presenter-provider-V0xnU_Wb.js";import{s as b}from"./i18n-20rSH40D.js";import{a as x,i as S,n as C,r as w,t as T}from"./select-CG5YWnwe.js";import{t as E}from"./loader-circle-K1BDdHR5.js";import{t as D}from"./plus-LA8-jpxP.js";import{t as O}from"./rotate-cw-B6xm41Wn.js";import{t as k}from"./save-fff_WpY2.js";import{i as A}from"./pwa-D_nZUwG0.js";import{t as j}from"./trash-2-BPPYt2NV.js";import{b as M,t as ee}from"./use-config-BEdbtpD4.js";import{t as N}from"./form-actions-BRESe-m_.js";var P=e(n(),1),F=t(),I={healthy:`runtimeControlHealthy`,"starting-service":`runtimeControlStartingService`,"restarting-service":`runtimeControlRestartingService`,"stopping-service":`runtimeControlStoppingService`,"restarting-app":`runtimeControlRestartingApp`,recovering:`runtimeControlRecovering`,failed:`runtimeControlFailed`},L={running:`runtimeControlServiceRunning`,stopped:`runtimeControlServiceStopped`,starting:`runtimeControlServiceStarting`,stopping:`runtimeControlServiceStopping`,restarting:`runtimeControlServiceRestarting`},R={"desktop-embedded":`runtimeControlEnvironmentDesktop`,"managed-local-service":`runtimeControlEnvironmentManagedService`,"self-hosted-web":`runtimeControlEnvironmentSelfHosted`,"shared-web":`runtimeControlEnvironmentSharedWeb`};function z(e){return b(I[e]??`runtimeControlUnavailable`)}function B(e){return b(L[e]??`runtimeControlServiceUnknown`)}function V(e){return b(R[e.environment])}function H(e,t){return t===`start-service`?e?.canStartService:t===`stop-service`?e?.canStopService:e?.canRestartService}function U(e){return e?[{action:`start-service`,capability:e.canStartService,label:b(`runtimeControlStartService`),icon:`play`},{action:`restart-service`,capability:e.canRestartService,label:b(`runtimeControlRestartService`),icon:`rotate`},{action:`stop-service`,capability:e.canStopService,label:b(`runtimeControlStopService`),icon:`square`,variant:`destructive`},{action:`restart-app`,capability:e.canRestartApp,label:b(`runtimeControlRestartApp`),icon:`rotate`,variant:`secondary`}].filter(e=>e.capability.available||!!e.capability.reasonIfUnavailable):[]}function W(e){let{busy:t,icon:n}=e;return t?(0,F.jsx)(E,{className:`mr-2 h-4 w-4 animate-spin`}):n===`play`?(0,F.jsx)(g,{className:`mr-2 h-4 w-4`}):n===`square`?(0,F.jsx)(_,{className:`mr-2 h-4 w-4`}):(0,F.jsx)(O,{className:`mr-2 h-4 w-4`})}function G(){let{busy:e,busyAction:t,controlView:n,errorMessage:r,pendingRestart:a,visibleLifecycle:o,visibleMessage:s,visibleServiceState:p}=l(),h=U(n??void 0),g=async e=>{let t=H(n,e);if(!t?.available){m.error(d(t?.reasonIfUnavailable)??b(`runtimeControlLoadFailed`));return}if(!(e===`stop-service`&&t.requiresConfirmation&&!window.confirm(b(`runtimeControlStopServiceConfirm`))))try{let t=await u.runRuntimeControlAction(e);m.success(d(t.message)??t.message)}catch(e){let t=e instanceof Error?e.message:b(`runtimeControlActionFailed`);m.error(`${b(`runtimeControlActionFailed`)}: ${t}`)}},_=async()=>{if(!n?.canRestartApp.available){m.error(d(n?.canRestartApp.reasonIfUnavailable)??b(`runtimeRestartAppUnavailable`));return}if(window.confirm(b(`runtimeControlRestartAppConfirm`)))try{let e=await u.runRuntimeControlAction(`restart-app`);m.success(d(e.message)??e.message)}catch(e){let t=e instanceof Error?e.message:b(`runtimeControlActionFailed`);m.error(`${b(`runtimeControlActionFailed`)}: ${t}`)}};return(0,F.jsx)(i,{title:b(`runtimeControlTitle`),description:b(`runtimeControlDescription`),children:(0,F.jsxs)(f,{children:[(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 md:flex-row md:items-center md:justify-between`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:B(p)}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:n?V(n):b(`runtimeControlLoading`)})]}),(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:z(o)}),n?.managementHint?(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d(n.managementHint)}):null,r&&!e?(0,F.jsx)(`p`,{className:`text-sm text-amber-700`,children:r}):null]}),a?(0,F.jsxs)(`div`,{className:`space-y-3 bg-amber-50/75 p-4 dark:bg-amber-950/20`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-amber-900`,children:b(`runtimeControlPendingRestartTitle`)}),(0,F.jsx)(`p`,{className:`text-sm text-amber-800`,children:b(`runtimeControlPendingRestartDescription`)}),a.changedPaths.length>0?(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-[0.08em] text-amber-700`,children:b(`runtimeControlPendingRestartPaths`)}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:a.changedPaths.map(e=>(0,F.jsx)(`span`,{className:`rounded-full bg-background/80 px-2.5 py-1 text-xs text-amber-800 dark:text-amber-300`,children:e},e))})]}):null]}):null,(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsx)(`div`,{className:`flex flex-col gap-3 md:flex-row md:flex-wrap`,children:h.map(n=>(0,F.jsxs)(c,{type:`button`,variant:n.variant??`default`,onClick:()=>{if(n.action===`restart-app`){_();return}g(n.action)},disabled:!n.capability.available||e,children:[(0,F.jsx)(W,{icon:n.icon,busy:t===n.action}),n.label]},n.action))}),h.filter(e=>!e.capability.available&&e.capability.reasonIfUnavailable).map(e=>(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d(e.capability.reasonIfUnavailable)},`${e.action}-reason`))]})]})})}function K(e){let{description:t,title:n}=e;return(0,F.jsx)(h,{tone:`neutral`,title:n,description:t})}function q(e){let{children:t}=e;return(0,F.jsx)(i,{title:b(`runtimePresenceTitle`),description:b(`runtimePresenceDescription`),children:(0,F.jsx)(f,{children:t})})}function J(){let e=p().runtimeControlView?.environment,t=y(e=>e.supported),n=y(e=>e.initialized),r=y(e=>e.busyAction),i=y(e=>e.snapshot);return(0,P.useEffect)(()=>{if(e===`desktop-embedded`){v.start();return}v.markUnsupported()},[e]),e===`desktop-embedded`?(0,F.jsxs)(q,{children:[(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(h,{tone:`neutral`,title:b(`runtimePresenceBehaviorLabel`),description:i?.closeToBackground?b(`runtimePresenceBehaviorBackground`):b(`runtimePresenceBehaviorQuit`),className:`rounded-xl`})}),!n||t&&!i?(0,F.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:b(`runtimePresenceLoading`)}):null,i?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(a,{title:b(`runtimePresenceCloseToBackground`),description:b(`runtimePresenceCloseToBackgroundHelp`),control:(0,F.jsx)(s,{id:`runtime-presence-close-background`,"aria-label":b(`runtimePresenceCloseToBackground`),checked:i.closeToBackground,disabled:r===`saving-preferences`,onCheckedChange:e=>{v.updatePreferences({closeToBackground:e})}})}),(0,F.jsx)(a,{title:b(`runtimePresenceLaunchAtLogin`),description:i.supportsLaunchAtLogin?b(`runtimePresenceLaunchAtLoginHelp`):i.launchAtLoginReason??b(`runtimePresenceLaunchAtLoginUnavailable`),control:(0,F.jsx)(s,{id:`runtime-presence-launch-login`,"aria-label":b(`runtimePresenceLaunchAtLogin`),checked:i.launchAtLogin,disabled:!i.supportsLaunchAtLogin||r===`saving-preferences`,onCheckedChange:e=>{v.updatePreferences({launchAtLogin:e})}})})]}):null]}):e===`managed-local-service`?(0,F.jsx)(q,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(K,{title:b(`runtimePresenceManagedLocalTitle`),description:b(`runtimePresenceManagedLocalDescription`)})})}):e===`self-hosted-web`?(0,F.jsx)(q,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(K,{title:b(`runtimePresenceSelfHostedTitle`),description:b(`runtimePresenceSelfHostedDescription`)})})}):e===`shared-web`?(0,F.jsx)(q,{children:(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(K,{title:b(`runtimePresenceSharedTitle`),description:b(`runtimePresenceSharedDescription`)})})}):(0,F.jsx)(q,{children:(0,F.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:b(`runtimePresenceLoading`)})})}function te(){return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(G,{}),(0,F.jsx)(J,{}),(0,F.jsx)(A,{})]})}var Y={wireDialect:`acp`,processScope:`per-session`,command:``,args:[`acp`],env:{},cwd:``,startupTimeoutMs:8e3,probeTimeoutMs:3e3,requestTimeoutMs:12e4};function X(){return{id:``,default:!1,workspace:``,model:``,runtime:``,contextTokens:void 0}}function Z(){return{agentId:``,match:{channel:``,accountId:``}}}function Q(){return{id:``,enabled:!0,label:``,type:`narp-stdio`,config:Y,configText:JSON.stringify(Y,null,2)}}function ne(e){return{id:e.id??``,default:!!e.default,displayName:e.displayName??``,description:e.description??``,avatar:e.avatar??``,workspace:e.workspace??``,model:e.model??``,runtime:e.runtime??e.engine??``,contextTokens:e.contextTokens}}function re(e){return{agentId:e.agentId??``,match:{channel:e.match?.channel??``,accountId:e.match?.accountId??``,peer:e.match?.peer?{kind:e.match.peer.kind,id:e.match.peer.id}:void 0}}}function ie(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:void 0}function ae(e){return{companionEnabled:e.companion?.enabled===!0,agents:(e.agents.list??[]).map(ne),bindings:(e.bindings??[]).map(re),runtimeEntries:Object.entries(e.agents.runtimes?.entries??{}).map(([e,t])=>({id:e,enabled:t.enabled!==!1,label:t.label??``,type:t.type,config:t.config??{},configText:JSON.stringify(t.config??{},null,2)})),dmScope:e.session?.dmScope??`per-channel-peer`,defaultContextTokens:e.agents.defaults.contextTokens??2e5,defaultEngine:e.agents.defaults.engine??`native`}}function oe(e){let t={id:e.id.trim()};e.default&&(t.default=!0),e.displayName?.trim()&&(t.displayName=e.displayName.trim()),e.description?.trim()&&(t.description=e.description.trim()),e.avatar?.trim()&&(t.avatar=e.avatar.trim()),e.workspace?.trim()&&(t.workspace=e.workspace.trim()),e.model?.trim()&&(t.model=e.model.trim());let n=e.runtime?.trim()??e.engine?.trim();return n&&(t.engine=n),typeof e.contextTokens==`number`&&(t.contextTokens=Math.max(1e3,e.contextTokens)),t}function $(e){let t=e.agents.map((e,t)=>{if(!e.id.trim())throw Error(b(`agentIdRequiredError`).replace(`{index}`,String(t)));return oe(e)}),n=t.map(e=>e.id).filter((e,t,n)=>n.indexOf(e)!==t);if(n.length>0)throw Error(`${b(`duplicateAgentId`)}: ${n[0]}`);let r=e.bindings.map((t,n)=>{let r=t.agentId.trim(),i=t.match.channel.trim(),a=t.match.accountId?.trim()??``,o=t.match.peer?.kind,s=t.match.peer?.id?.trim()??``;if(!r)throw Error(b(`bindingAgentIdRequired`).replace(`{index}`,String(n)));if(!e.knownAgentIds.has(r))throw Error(`${b(`bindingAgentIdNotFound`).replace(`{index}`,String(n))}: ${r}`);if(!i)throw Error(b(`bindingChannelRequired`).replace(`{index}`,String(n)));let c={agentId:r,match:{channel:i}};if(a&&(c.match.accountId=a),o){if(!s)throw Error(b(`bindingPeerIdRequired`).replace(`{index}`,String(n)));c.match.peer={kind:o,id:s}}return c}),i=e.runtimeEntries.reduce((e,t,n)=>{let r=t.id.trim(),i=t.type.trim();if(!r)throw Error(b(`runtimeEntryIdRequired`).replace(`{index}`,String(n)));if(!i)throw Error(b(`runtimeEntryTypeRequired`).replace(`{id}`,r));if(e[r])throw Error(`${b(`runtimeEntryDuplicate`)}: ${r}`);let a=t.configText.trim()?JSON.parse(t.configText):{};if(a&&(typeof a!=`object`||Array.isArray(a)))throw Error(b(`runtimeEntryConfigObjectRequired`).replace(`{id}`,r));return e[r]={enabled:t.enabled!==!1,...t.label?.trim()?{label:t.label.trim()}:{},type:i,config:a??{}},e},{});return{companion:{enabled:e.companionEnabled},agents:{defaults:{contextTokens:Math.max(1e3,e.defaultContextTokens),engine:e.defaultEngine.trim()||`native`},list:t,runtimes:{entries:i}},bindings:r,session:{dmScope:e.dmScope}}}function se({agents:e,onAddAgent:t,onRemoveAgent:n,onSetDefaultAgent:a,onUpdateAgent:o}){return(0,F.jsx)(i,{title:b(`agentList`),description:b(`agentListHelp`),actions:(0,F.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:[(0,F.jsx)(D,{className:`mr-2 h-4 w-4`}),b(`addAgent`)]}),children:(0,F.jsx)(f,{children:e.map((e,t)=>(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,F.jsx)(r,{value:e.id,onChange:e=>o(t,{id:e.target.value}),placeholder:b(`agentIdPlaceholder`)}),(0,F.jsx)(r,{value:e.workspace??``,onChange:e=>o(t,{workspace:e.target.value}),placeholder:b(`workspaceOverridePlaceholder`)}),(0,F.jsx)(r,{value:e.model??``,onChange:e=>o(t,{model:e.target.value}),placeholder:b(`modelOverridePlaceholder`)}),(0,F.jsx)(r,{value:e.runtime??e.engine??``,onChange:e=>o(t,{runtime:e.target.value}),placeholder:b(`engineOverridePlaceholder`)}),(0,F.jsx)(r,{type:`number`,min:1e3,step:1e3,value:e.contextTokens??``,onChange:e=>o(t,{contextTokens:ie(e.target.value)}),placeholder:b(`contextTokensPlaceholder`)})]}),(0,F.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,F.jsx)(s,{checked:!!e.default,onCheckedChange:e=>a(t,e)}),(0,F.jsx)(`span`,{children:b(`defaultAgent`)})]}),(0,F.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(t),children:[(0,F.jsx)(j,{className:`h-4 w-4 mr-1`}),b(`remove`)]})]})]},`${t}-${e.id}`))})})}function ce({bindings:e,onAddBinding:t,onRemoveBinding:n,onUpdateBinding:a}){return(0,F.jsx)(i,{title:b(`bindings`),description:b(`bindingsHelp`),actions:(0,F.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:[(0,F.jsx)(D,{className:`mr-2 h-4 w-4`}),b(`addBinding`)]}),children:(0,F.jsx)(f,{children:e.map((e,t)=>{let i=e.match.peer?.kind??``;return(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[(0,F.jsx)(r,{value:e.agentId,onChange:n=>a(t,{...e,agentId:n.target.value}),placeholder:b(`targetAgentIdPlaceholder`)}),(0,F.jsx)(r,{value:e.match.channel,onChange:n=>a(t,{...e,match:{...e.match,channel:n.target.value}}),placeholder:b(`channelPlaceholder`)}),(0,F.jsx)(r,{value:e.match.accountId??``,onChange:n=>a(t,{...e,match:{...e.match,accountId:n.target.value}}),placeholder:b(`accountIdOptionalPlaceholder`)}),(0,F.jsxs)(T,{value:i||`__none__`,onValueChange:n=>{let r=n===`__none__`?``:n;a(t,r?{...e,match:{...e.match,peer:{kind:r,id:e.match.peer?.id??``}}}:{...e,match:{...e.match,peer:void 0}})},children:[(0,F.jsx)(S,{children:(0,F.jsx)(x,{})}),(0,F.jsxs)(C,{children:[(0,F.jsx)(w,{value:`__none__`,children:b(`peerKindOptional`)}),(0,F.jsx)(w,{value:`direct`,children:b(`peerKindDirect`)}),(0,F.jsx)(w,{value:`group`,children:b(`peerKindGroup`)}),(0,F.jsx)(w,{value:`channel`,children:b(`peerKindChannel`)})]})]}),(0,F.jsx)(r,{value:e.match.peer?.id??``,onChange:n=>a(t,{...e,match:{...e.match,peer:i?{kind:i,id:n.target.value}:void 0}}),placeholder:b(`peerIdPlaceholder`)})]}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(t),children:[(0,F.jsx)(j,{className:`h-4 w-4 mr-1`}),b(`remove`)]})})]},`${t}-${e.agentId}`)})})})}function le({entries:e,onAddEntry:t,onRemoveEntry:n,onUpdateEntry:a}){return(0,F.jsx)(i,{title:b(`runtimeEntries`),description:b(`runtimeEntriesHelp`),actions:(0,F.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:[(0,F.jsx)(D,{className:`mr-2 h-4 w-4`}),b(`addRuntimeEntry`)]}),children:(0,F.jsx)(f,{children:e.map((e,t)=>(0,F.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,F.jsx)(r,{value:e.id,onChange:e=>a(t,{id:e.target.value}),placeholder:b(`runtimeEntryIdPlaceholder`)}),(0,F.jsx)(r,{value:e.label??``,onChange:e=>a(t,{label:e.target.value}),placeholder:b(`runtimeEntryLabelPlaceholder`)}),(0,F.jsx)(r,{value:e.type,onChange:e=>a(t,{type:e.target.value}),placeholder:b(`runtimeEntryTypePlaceholder`)}),(0,F.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg bg-background/65 px-3 py-2`,children:[(0,F.jsx)(`span`,{className:`text-sm text-foreground`,children:b(`enabled`)}),(0,F.jsx)(s,{checked:e.enabled!==!1,onCheckedChange:e=>a(t,{enabled:e})})]})]}),(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`label`,{className:`text-sm font-medium text-foreground`,children:b(`runtimeEntryConfigJson`)}),(0,F.jsx)(`textarea`,{className:`min-h-32 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-sm`,value:e.configText,onChange:e=>a(t,{configText:e.target.value}),spellCheck:!1})]}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsxs)(c,{type:`button`,variant:`outline`,onClick:()=>n(t),children:[(0,F.jsx)(j,{className:`mr-2 h-4 w-4`}),b(`delete`)]})})]},`${t}-${e.id||`runtime-entry`}`))})})}var ue=[{value:`main`,labelKey:`dmScopeMain`},{value:`per-peer`,labelKey:`dmScopePerPeer`},{value:`per-channel-peer`,labelKey:`dmScopePerChannelPeer`},{value:`per-account-channel-peer`,labelKey:`dmScopePerAccountChannelPeer`}];function de({companionEnabled:e,defaultContextTokens:t,defaultEngine:n,dmScope:o,onCompanionEnabledChange:c,onDefaultContextTokensChange:l,onDefaultEngineChange:u,onDmScopeChange:d}){return(0,F.jsx)(i,{title:b(`dmScope`),description:b(`dmScopeHelp`),children:(0,F.jsxs)(f,{children:[(0,F.jsx)(a,{title:b(`runtimeCompanionEnabled`),description:b(`runtimeCompanionEnabledHelp`),control:(0,F.jsx)(s,{checked:e,onCheckedChange:c})}),(0,F.jsx)(a,{title:b(`defaultContextTokens`),description:b(`defaultContextTokensHelp`),control:(0,F.jsx)(r,{type:`number`,min:1e3,step:1e3,value:t,onChange:e=>l(Math.max(1e3,Number.parseInt(e.target.value,10)||1e3)),className:`w-36`})}),(0,F.jsx)(a,{title:b(`defaultEngine`),description:b(`defaultEngineHelp`),control:(0,F.jsx)(r,{value:n,onChange:e=>u(e.target.value),placeholder:b(`defaultEnginePlaceholder`),className:`w-56`})}),(0,F.jsx)(a,{title:b(`dmScope`),control:(0,F.jsxs)(T,{value:o,onValueChange:e=>d(e),children:[(0,F.jsx)(S,{className:`w-56`,children:(0,F.jsx)(x,{})}),(0,F.jsx)(C,{children:ue.map(e=>(0,F.jsx)(w,{value:e.value,children:b(e.labelKey)},e.value))})]})})]})})}function fe({config:e,updateRuntime:t}){let n=(0,P.useMemo)(()=>ae(e),[e]),[r,i]=(0,P.useState)(n.agents),[a,s]=(0,P.useState)(n.bindings),[l,u]=(0,P.useState)(n.runtimeEntries),[d,f]=(0,P.useState)(n.dmScope),[p,h]=(0,P.useState)(n.companionEnabled),[g,_]=(0,P.useState)(n.defaultContextTokens),[v,y]=(0,P.useState)(n.defaultEngine),x=(0,P.useMemo)(()=>{let e=new Set([`main`]);return r.forEach(t=>{let n=t.id.trim();n&&e.add(n)}),e},[r]);return(0,F.jsxs)(o,{title:b(`runtimePageTitle`),description:b(`runtimePageDescription`),children:[(0,F.jsx)(te,{}),(0,F.jsx)(de,{companionEnabled:p,dmScope:d,defaultContextTokens:g,defaultEngine:v,onCompanionEnabledChange:h,onDmScopeChange:f,onDefaultContextTokensChange:_,onDefaultEngineChange:y}),(0,F.jsx)(le,{entries:l,onUpdateEntry:(e,t)=>u(n=>n.map((n,r)=>r===e?{...n,...t}:n)),onRemoveEntry:e=>u(t=>t.filter((t,n)=>n!==e)),onAddEntry:()=>u(e=>[...e,Q()])}),(0,F.jsx)(se,{agents:r,onUpdateAgent:(e,t)=>{i(n=>n.map((n,r)=>r===e?{...n,...t}:n))},onRemoveAgent:e=>i(t=>t.filter((t,n)=>n!==e)),onAddAgent:()=>i(e=>[...e,X()]),onSetDefaultAgent:(e,t)=>i(n=>t?n.map((t,n)=>({...t,default:n===e})):n.map((t,n)=>n===e?{...t,default:!1}:t))}),(0,F.jsx)(ce,{bindings:a,onUpdateBinding:(e,t)=>{s(n=>n.map((n,r)=>r===e?t:n))},onRemoveBinding:e=>s(t=>t.filter((t,n)=>n!==e)),onAddBinding:()=>s(e=>[...e,Z()])}),(0,F.jsx)(N,{children:(0,F.jsxs)(c,{type:`button`,size:`sm`,onClick:()=>{try{let e=$({companionEnabled:p,agents:r,bindings:a,runtimeEntries:l,dmScope:d,defaultContextTokens:g,defaultEngine:v,knownAgentIds:x});t.mutate({data:e})}catch(e){m.error(e instanceof Error?e.message:String(e))}},disabled:t.isPending,children:[(0,F.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5`}),t.isPending?b(`saving`):b(`saveRuntimeSettings`)]})})]})}function pe(){let{data:e,isLoading:t}=ee(),n=M();return t||!e?(0,F.jsx)(o,{title:b(`runtimePageTitle`),description:b(`runtimePageDescription`),children:(0,F.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:b(`runtimeLoading`)})}):(0,F.jsx)(fe,{config:e,updateRuntime:n})}export{pe as RuntimeConfig};
@@ -1 +1 @@
1
- import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n}from"./utils-CBZPzC_b.js";import{t as r}from"./navigation-link-BAQjgx2F.js";import{Gt as i,Qt as a,Wt as o,Yt as s}from"./api-BWFOIoUm.js";import{s as c}from"./i18n-ClHx6jwj.js";import{t as l}from"./search-CUe41wjm.js";import{a as u,i as d,n as f,r as p,t as m}from"./select-CG5YWnwe.js";import{i as h,t as g}from"./use-viewport-layout-BS18drMT.js";import{n as _,t as v,x as y}from"./use-config-C8ZkQiTc.js";import{t as b}from"./form-actions-BRESe-m_.js";import{a as x,c as S,l as C,n as w,o as T,r as E,s as D,t as O}from"./config-split-page-CxLWGwdt.js";var k=e(n(),1),A=t(),j=[{value:`noLimit`,label:`searchFreshnessNoLimit`},{value:`oneDay`,label:`searchFreshnessOneDay`},{value:`oneWeek`,label:`searchFreshnessOneWeek`},{value:`oneMonth`,label:`searchFreshnessOneMonth`},{value:`oneYear`,label:`searchFreshnessOneYear`}],M=[{value:`basic`,label:`searchDepthBasic`},{value:`advanced`,label:`searchDepthAdvanced`}],N=[{value:`true`,label:`enabled`},{value:`false`,label:`disabled`}],P={bocha:`searchProviderBochaDescription`,tavily:`searchProviderTavilyDescription`,brave:`searchProviderBraveDescription`,exa:`searchProviderExaDescription`};function F(e){return{activeProvider:e.provider,enabledProviders:e.enabledProviders,maxResults:String(e.defaults.maxResults),providers:{bocha:{apiKey:``,baseUrl:e.providers.bocha.baseUrl,summary:!!e.providers.bocha.summary,freshness:e.providers.bocha.freshness??`noLimit`},tavily:{apiKey:``,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth??`basic`,includeAnswer:!!e.providers.tavily.includeAnswer},brave:{apiKey:``,baseUrl:e.providers.brave.baseUrl},exa:{apiKey:``,baseUrl:e.providers.exa.baseUrl}}}}function I(e){return{provider:e.activeProvider,enabledProviders:e.enabledProviders,defaults:{maxResults:Number(e.maxResults)||10},providers:{bocha:{apiKey:e.providers.bocha.apiKey||void 0,baseUrl:e.providers.bocha.baseUrl,summary:e.providers.bocha.summary,freshness:e.providers.bocha.freshness},tavily:{apiKey:e.providers.tavily.apiKey||void 0,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth,includeAnswer:e.providers.tavily.includeAnswer},brave:{apiKey:e.providers.brave.apiKey||void 0,baseUrl:e.providers.brave.baseUrl},exa:{apiKey:e.providers.exa.apiKey||void 0,baseUrl:e.providers.exa.baseUrl}}}}function L(e){let{label:t,value:n,onChange:r,placeholder:a,type:s=`text`,inputMode:c}=e;return(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(o,{children:t}),(0,A.jsx)(i,{type:s,value:n,onChange:e=>r(e.target.value),placeholder:a,inputMode:c,className:`rounded-xl`})]})}function R(e){let{label:t,value:n,options:r,onChange:i}=e;return(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(o,{children:t}),(0,A.jsxs)(m,{value:n,onValueChange:i,children:[(0,A.jsx)(d,{className:`rounded-xl`,children:(0,A.jsx)(u,{})}),(0,A.jsx)(f,{children:r.map(e=>(0,A.jsx)(p,{value:e.value,children:c(e.label)},e.value))})]})]})}function z({docsUrl:e}){return e?(0,A.jsx)(r,{href:e,external:!0,children:c(`searchProviderOpenDocs`)}):null}function B(e){let{draft:t,provider:n,search:r,selectedDocsUrl:i,updateProviderDraft:a}=e;if(n===`bocha`){let{bocha:e}=t.providers;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(L,{label:c(`apiKey`),value:e.apiKey,onChange:e=>a(`bocha`,{apiKey:e}),placeholder:r.providers.bocha.apiKeyMasked||c(`enterApiKey`),type:`password`}),(0,A.jsx)(L,{label:c(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>a(`bocha`,{baseUrl:e})}),(0,A.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,A.jsx)(R,{label:c(`searchProviderSummary`),value:e.summary?`true`:`false`,options:N,onChange:e=>a(`bocha`,{summary:e===`true`})}),(0,A.jsx)(R,{label:c(`searchProviderFreshness`),value:e.freshness,options:j,onChange:e=>a(`bocha`,{freshness:e})})]}),(0,A.jsx)(z,{docsUrl:i??`https://open.bocha.cn`})]})}if(n===`tavily`){let{tavily:e}=t.providers;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(L,{label:c(`apiKey`),value:e.apiKey,onChange:e=>a(`tavily`,{apiKey:e}),placeholder:r.providers.tavily.apiKeyMasked||c(`enterApiKey`),type:`password`}),(0,A.jsx)(L,{label:c(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>a(`tavily`,{baseUrl:e})}),(0,A.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,A.jsx)(R,{label:c(`searchProviderSearchDepth`),value:e.searchDepth,options:M,onChange:e=>a(`tavily`,{searchDepth:e})}),(0,A.jsx)(R,{label:c(`searchProviderIncludeAnswer`),value:e.includeAnswer?`true`:`false`,options:N,onChange:e=>a(`tavily`,{includeAnswer:e===`true`})})]}),(0,A.jsx)(z,{docsUrl:i})]})}let o=t.providers[n],s=r.providers[n];return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(L,{label:c(`apiKey`),value:o.apiKey,onChange:e=>a(n,{apiKey:e}),placeholder:s.apiKeyMasked||c(`enterApiKey`),type:`password`}),(0,A.jsx)(L,{label:c(`searchProviderBaseUrl`),value:o.baseUrl,onChange:e=>a(n,{baseUrl:e})}),(0,A.jsx)(z,{docsUrl:i})]})}function V(e){let{draft:t,providers:n,search:r,selectedProvider:i,onSelect:a}=e;return(0,A.jsxs)(C,{children:[(0,A.jsx)(S,{className:`px-4 py-4`,children:(0,A.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-[0.16em] text-muted-foreground`,children:c(`searchChannels`)})}),(0,A.jsx)(T,{className:`space-y-2 p-3`,children:n.map(e=>{let n=r.providers[e.name],o=t.enabledProviders.includes(e.name);return(0,A.jsx)(O,{onClick:()=>a(e.name),active:i===e.name,className:`p-3`,children:(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`p`,{className:`truncate text-sm font-semibold text-foreground`,children:e.displayName}),(0,A.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-muted-foreground`,children:c(P[e.name])})]}),(0,A.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[(0,A.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground`,children:n.apiKeySet?c(`searchStatusConfigured`):c(`searchStatusNeedsSetup`)}),o?(0,A.jsx)(`span`,{className:`rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700`,children:c(`searchProviderActivated`)}):null]})]})},e.name)})})]})}function H(e){let{initialDraft:t,providers:n,search:r,onSubmit:i,isPending:a}=e,{isMobile:o}=g(),[u,d]=(0,k.useState)(null),[f,p]=(0,k.useState)(t),m=u&&n.some(e=>e.name===u)?u:o?null:r.provider,_=n.find(e=>e.name===m)??null,v=m?r.providers[m]:null,y=m?f.enabledProviders.includes(m):!1,C=v?.docsUrl??_?.docsUrl;return(0,A.jsxs)(x,{className:`md:min-h-0`,compactView:u?`detail`:`list`,onMobileBack:()=>d(null),mobileListLabel:c(`searchPageTitle`),children:[(0,A.jsx)(V,{draft:f,providers:n,search:r,selectedProvider:m??r.provider,onSelect:d}),_?(0,A.jsx)(w,{children:(0,A.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i(f)},className:`flex min-h-0 flex-1 flex-col`,children:[(0,A.jsx)(S,{className:`px-5 py-4`,children:(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,A.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-primary-foreground`,children:(0,A.jsx)(l,{className:`h-5 w-5`})}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:_.displayName}),(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(P[_.name])})]})]}),(0,A.jsx)(s,{type:`button`,variant:y?`secondary`:`outline`,className:`rounded-xl`,onClick:()=>{let e=y?f.enabledProviders.filter(e=>e!==m):m?[...f.enabledProviders,m]:f.enabledProviders,t={...f,enabledProviders:e};p(t),i(t)},children:c(y?`searchProviderDeactivate`:`searchProviderActivate`)})]})}),(0,A.jsxs)(T,{className:`space-y-5 px-5 py-4`,children:[(0,A.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,A.jsx)(R,{label:c(`searchActiveProvider`),value:f.activeProvider,options:n.map(e=>({value:e.name,label:e.displayName})),onChange:e=>p({...f,activeProvider:e})}),(0,A.jsx)(L,{label:c(`searchDefaultMaxResults`),value:f.maxResults,onChange:e=>p({...f,maxResults:e}),inputMode:`numeric`})]}),(0,A.jsx)(B,{draft:f,provider:m,search:r,selectedDocsUrl:C,updateProviderDraft:(e,t)=>{p(n=>({...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}}))}})]}),(0,A.jsx)(D,{children:(0,A.jsx)(b,{children:(0,A.jsxs)(s,{type:`submit`,size:`sm`,disabled:a,children:[(0,A.jsx)(h,{className:`mr-1.5 h-3.5 w-3.5`}),c(a?`saving`:`saveChanges`)]})})})]})}):(0,A.jsx)(E,{children:(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`searchNoProviderSelected`)})})]})}function U(){let{data:e}=v(),{data:t}=_(),n=y(),r=t?.search??[],i=e?.search;return!i||r.length===0?(0,A.jsx)(a,{title:c(`searchPageTitle`),description:c(`searchPageDescription`),layout:`split`,children:(0,A.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:c(`loading`)})}):(0,A.jsx)(a,{title:c(`searchPageTitle`),description:c(`searchPageDescription`),layout:`split`,children:(0,A.jsx)(H,{initialDraft:F(i),providers:r,search:i,onSubmit:e=>n.mutate({data:I(e)}),isPending:n.isPending},JSON.stringify(i))})}export{U as SearchConfigPage};
1
+ import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n}from"./utils-CBZPzC_b.js";import{t as r}from"./navigation-link-BAQjgx2F.js";import{Gt as i,Qt as a,Wt as o,Yt as s}from"./api-DqzQ-_3w.js";import{s as c}from"./i18n-20rSH40D.js";import{t as l}from"./search-CUe41wjm.js";import{a as u,i as d,n as f,r as p,t as m}from"./select-CG5YWnwe.js";import{i as h,t as g}from"./use-viewport-layout-BS18drMT.js";import{n as _,t as v,x as y}from"./use-config-BEdbtpD4.js";import{t as b}from"./form-actions-BRESe-m_.js";import{a as x,c as S,l as C,n as w,o as T,r as E,s as D,t as O}from"./config-split-page-DqAXKLmG.js";var k=e(n(),1),A=t(),j=[{value:`noLimit`,label:`searchFreshnessNoLimit`},{value:`oneDay`,label:`searchFreshnessOneDay`},{value:`oneWeek`,label:`searchFreshnessOneWeek`},{value:`oneMonth`,label:`searchFreshnessOneMonth`},{value:`oneYear`,label:`searchFreshnessOneYear`}],M=[{value:`basic`,label:`searchDepthBasic`},{value:`advanced`,label:`searchDepthAdvanced`}],N=[{value:`true`,label:`enabled`},{value:`false`,label:`disabled`}],P={bocha:`searchProviderBochaDescription`,tavily:`searchProviderTavilyDescription`,brave:`searchProviderBraveDescription`,exa:`searchProviderExaDescription`};function F(e){return{activeProvider:e.provider,enabledProviders:e.enabledProviders,maxResults:String(e.defaults.maxResults),providers:{bocha:{apiKey:``,baseUrl:e.providers.bocha.baseUrl,summary:!!e.providers.bocha.summary,freshness:e.providers.bocha.freshness??`noLimit`},tavily:{apiKey:``,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth??`basic`,includeAnswer:!!e.providers.tavily.includeAnswer},brave:{apiKey:``,baseUrl:e.providers.brave.baseUrl},exa:{apiKey:``,baseUrl:e.providers.exa.baseUrl}}}}function I(e){return{provider:e.activeProvider,enabledProviders:e.enabledProviders,defaults:{maxResults:Number(e.maxResults)||10},providers:{bocha:{apiKey:e.providers.bocha.apiKey||void 0,baseUrl:e.providers.bocha.baseUrl,summary:e.providers.bocha.summary,freshness:e.providers.bocha.freshness},tavily:{apiKey:e.providers.tavily.apiKey||void 0,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth,includeAnswer:e.providers.tavily.includeAnswer},brave:{apiKey:e.providers.brave.apiKey||void 0,baseUrl:e.providers.brave.baseUrl},exa:{apiKey:e.providers.exa.apiKey||void 0,baseUrl:e.providers.exa.baseUrl}}}}function L(e){let{label:t,value:n,onChange:r,placeholder:a,type:s=`text`,inputMode:c}=e;return(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(o,{children:t}),(0,A.jsx)(i,{type:s,value:n,onChange:e=>r(e.target.value),placeholder:a,inputMode:c,className:`rounded-xl`})]})}function R(e){let{label:t,value:n,options:r,onChange:i}=e;return(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(o,{children:t}),(0,A.jsxs)(m,{value:n,onValueChange:i,children:[(0,A.jsx)(d,{className:`rounded-xl`,children:(0,A.jsx)(u,{})}),(0,A.jsx)(f,{children:r.map(e=>(0,A.jsx)(p,{value:e.value,children:c(e.label)},e.value))})]})]})}function z({docsUrl:e}){return e?(0,A.jsx)(r,{href:e,external:!0,children:c(`searchProviderOpenDocs`)}):null}function B(e){let{draft:t,provider:n,search:r,selectedDocsUrl:i,updateProviderDraft:a}=e;if(n===`bocha`){let{bocha:e}=t.providers;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(L,{label:c(`apiKey`),value:e.apiKey,onChange:e=>a(`bocha`,{apiKey:e}),placeholder:r.providers.bocha.apiKeyMasked||c(`enterApiKey`),type:`password`}),(0,A.jsx)(L,{label:c(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>a(`bocha`,{baseUrl:e})}),(0,A.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,A.jsx)(R,{label:c(`searchProviderSummary`),value:e.summary?`true`:`false`,options:N,onChange:e=>a(`bocha`,{summary:e===`true`})}),(0,A.jsx)(R,{label:c(`searchProviderFreshness`),value:e.freshness,options:j,onChange:e=>a(`bocha`,{freshness:e})})]}),(0,A.jsx)(z,{docsUrl:i??`https://open.bocha.cn`})]})}if(n===`tavily`){let{tavily:e}=t.providers;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(L,{label:c(`apiKey`),value:e.apiKey,onChange:e=>a(`tavily`,{apiKey:e}),placeholder:r.providers.tavily.apiKeyMasked||c(`enterApiKey`),type:`password`}),(0,A.jsx)(L,{label:c(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>a(`tavily`,{baseUrl:e})}),(0,A.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,A.jsx)(R,{label:c(`searchProviderSearchDepth`),value:e.searchDepth,options:M,onChange:e=>a(`tavily`,{searchDepth:e})}),(0,A.jsx)(R,{label:c(`searchProviderIncludeAnswer`),value:e.includeAnswer?`true`:`false`,options:N,onChange:e=>a(`tavily`,{includeAnswer:e===`true`})})]}),(0,A.jsx)(z,{docsUrl:i})]})}let o=t.providers[n],s=r.providers[n];return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(L,{label:c(`apiKey`),value:o.apiKey,onChange:e=>a(n,{apiKey:e}),placeholder:s.apiKeyMasked||c(`enterApiKey`),type:`password`}),(0,A.jsx)(L,{label:c(`searchProviderBaseUrl`),value:o.baseUrl,onChange:e=>a(n,{baseUrl:e})}),(0,A.jsx)(z,{docsUrl:i})]})}function V(e){let{draft:t,providers:n,search:r,selectedProvider:i,onSelect:a}=e;return(0,A.jsxs)(C,{children:[(0,A.jsx)(S,{className:`px-4 py-4`,children:(0,A.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-[0.16em] text-muted-foreground`,children:c(`searchChannels`)})}),(0,A.jsx)(T,{className:`space-y-2 p-3`,children:n.map(e=>{let n=r.providers[e.name],o=t.enabledProviders.includes(e.name);return(0,A.jsx)(O,{onClick:()=>a(e.name),active:i===e.name,className:`p-3`,children:(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`p`,{className:`truncate text-sm font-semibold text-foreground`,children:e.displayName}),(0,A.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-muted-foreground`,children:c(P[e.name])})]}),(0,A.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[(0,A.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground`,children:n.apiKeySet?c(`searchStatusConfigured`):c(`searchStatusNeedsSetup`)}),o?(0,A.jsx)(`span`,{className:`rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700`,children:c(`searchProviderActivated`)}):null]})]})},e.name)})})]})}function H(e){let{initialDraft:t,providers:n,search:r,onSubmit:i,isPending:a}=e,{isMobile:o}=g(),[u,d]=(0,k.useState)(null),[f,p]=(0,k.useState)(t),m=u&&n.some(e=>e.name===u)?u:o?null:r.provider,_=n.find(e=>e.name===m)??null,v=m?r.providers[m]:null,y=m?f.enabledProviders.includes(m):!1,C=v?.docsUrl??_?.docsUrl;return(0,A.jsxs)(x,{className:`md:min-h-0`,compactView:u?`detail`:`list`,onMobileBack:()=>d(null),mobileListLabel:c(`searchPageTitle`),children:[(0,A.jsx)(V,{draft:f,providers:n,search:r,selectedProvider:m??r.provider,onSelect:d}),_?(0,A.jsx)(w,{children:(0,A.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i(f)},className:`flex min-h-0 flex-1 flex-col`,children:[(0,A.jsx)(S,{className:`px-5 py-4`,children:(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,A.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-primary-foreground`,children:(0,A.jsx)(l,{className:`h-5 w-5`})}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h3`,{className:`text-lg font-semibold text-foreground`,children:_.displayName}),(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(P[_.name])})]})]}),(0,A.jsx)(s,{type:`button`,variant:y?`secondary`:`outline`,className:`rounded-xl`,onClick:()=>{let e=y?f.enabledProviders.filter(e=>e!==m):m?[...f.enabledProviders,m]:f.enabledProviders,t={...f,enabledProviders:e};p(t),i(t)},children:c(y?`searchProviderDeactivate`:`searchProviderActivate`)})]})}),(0,A.jsxs)(T,{className:`space-y-5 px-5 py-4`,children:[(0,A.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,A.jsx)(R,{label:c(`searchActiveProvider`),value:f.activeProvider,options:n.map(e=>({value:e.name,label:e.displayName})),onChange:e=>p({...f,activeProvider:e})}),(0,A.jsx)(L,{label:c(`searchDefaultMaxResults`),value:f.maxResults,onChange:e=>p({...f,maxResults:e}),inputMode:`numeric`})]}),(0,A.jsx)(B,{draft:f,provider:m,search:r,selectedDocsUrl:C,updateProviderDraft:(e,t)=>{p(n=>({...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}}))}})]}),(0,A.jsx)(D,{children:(0,A.jsx)(b,{children:(0,A.jsxs)(s,{type:`submit`,size:`sm`,disabled:a,children:[(0,A.jsx)(h,{className:`mr-1.5 h-3.5 w-3.5`}),c(a?`saving`:`saveChanges`)]})})})]})}):(0,A.jsx)(E,{children:(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`searchNoProviderSelected`)})})]})}function U(){let{data:e}=v(),{data:t}=_(),n=y(),r=t?.search??[],i=e?.search;return!i||r.length===0?(0,A.jsx)(a,{title:c(`searchPageTitle`),description:c(`searchPageDescription`),layout:`split`,children:(0,A.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:c(`loading`)})}):(0,A.jsx)(a,{title:c(`searchPageTitle`),description:c(`searchPageDescription`),layout:`split`,children:(0,A.jsx)(H,{initialDraft:F(i),providers:r,search:i,onSubmit:e=>n.mutate({data:I(e)}),isPending:n.isPending},JSON.stringify(i))})}export{U as SearchConfigPage};
@@ -1,3 +1,3 @@
1
- import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n}from"./utils-CBZPzC_b.js";import{Gt as r,Jt as i,Kt as a,Qt as o,Ut as s,Yt as c,qt as l,vn as u}from"./api-BWFOIoUm.js";import{s as d}from"./i18n-ClHx6jwj.js";import{a as f,i as p,n as m,r as h,t as g}from"./select-CG5YWnwe.js";import{t as _}from"./plus-LA8-jpxP.js";import{t as v}from"./save-fff_WpY2.js";import{t as y}from"./trash-2-BPPYt2NV.js";import{S as b,t as x}from"./use-config-C8ZkQiTc.js";import{t as S}from"./form-actions-BRESe-m_.js";var C=e(n(),1),w=[`env`,`file`,`exec`];function T(e=``){return{alias:e,source:`env`,prefix:``,path:``,command:``,argsText:``,cwd:``,timeoutMs:5e3}}function E(){return{path:``,source:`env`,provider:``,id:``}}function D(e,t){return t.source===`env`?{...T(e),source:`env`,prefix:t.prefix??``}:t.source===`file`?{...T(e),source:`file`,path:t.path}:{...T(e),source:`exec`,command:t.command,argsText:(t.args??[]).join(`
1
+ import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n}from"./utils-CBZPzC_b.js";import{Gt as r,Jt as i,Kt as a,Qt as o,Ut as s,Yt as c,qt as l,vn as u}from"./api-DqzQ-_3w.js";import{s as d}from"./i18n-20rSH40D.js";import{a as f,i as p,n as m,r as h,t as g}from"./select-CG5YWnwe.js";import{t as _}from"./plus-LA8-jpxP.js";import{t as v}from"./save-fff_WpY2.js";import{t as y}from"./trash-2-BPPYt2NV.js";import{S as b,t as x}from"./use-config-BEdbtpD4.js";import{t as S}from"./form-actions-BRESe-m_.js";var C=e(n(),1),w=[`env`,`file`,`exec`];function T(e=``){return{alias:e,source:`env`,prefix:``,path:``,command:``,argsText:``,cwd:``,timeoutMs:5e3}}function E(){return{path:``,source:`env`,provider:``,id:``}}function D(e,t){return t.source===`env`?{...T(e),source:`env`,prefix:t.prefix??``}:t.source===`file`?{...T(e),source:`file`,path:t.path}:{...T(e),source:`exec`,command:t.command,argsText:(t.args??[]).join(`
2
2
  `),cwd:t.cwd??``,timeoutMs:t.timeoutMs??5e3}}function O(e){return e.source===`env`?{source:`env`,...e.prefix.trim()?{prefix:e.prefix.trim()}:{}}:e.source===`file`?{source:`file`,path:e.path.trim(),format:`json`}:{source:`exec`,command:e.command.trim(),args:e.argsText.split(`
3
3
  `).map(e=>e.trim()).filter(Boolean),...e.cwd.trim()?{cwd:e.cwd.trim()}:{},timeoutMs:Math.max(1,Math.trunc(e.timeoutMs||5e3))}}function k(e){return e?{enabled:!!e.enabled,defaultEnv:e.defaults.env??``,defaultFile:e.defaults.file??``,defaultExec:e.defaults.exec??``,providers:Object.entries(e.providers).map(([e,t])=>D(e,t)),refs:Object.entries(e.refs).map(([e,t])=>({path:e,source:t.source,provider:t.provider??``,id:t.id}))}:{enabled:!0,defaultEnv:``,defaultFile:``,defaultExec:``,providers:[],refs:[]}}function A(e){let t={};for(let[n,r]of e.providers.entries()){let e=r.alias.trim();if(!e)throw Error(`${d(`providerAlias`)} #${n+1} ${d(`isRequired`)}`);if(t[e])throw Error(`${d(`providerAlias`)}: ${e} (${d(`duplicate`)})`);if(r.source===`file`&&!r.path.trim())throw Error(`${d(`secretFilePath`)} #${n+1} ${d(`isRequired`)}`);if(r.source===`exec`&&!r.command.trim())throw Error(`${d(`secretExecCommand`)} #${n+1} ${d(`isRequired`)}`);t[e]=O(r)}let n={};for(let[r,i]of e.refs.entries()){let e=i.path.trim(),a=i.id.trim();if(!e)throw Error(`${d(`secretConfigPath`)} #${r+1} ${d(`isRequired`)}`);if(!a)throw Error(`${d(`secretId`)} #${r+1} ${d(`isRequired`)}`);let o=i.provider.trim();if(o&&!t[o])throw Error(`${d(`secretProviderAlias`)}: ${o} ${d(`notFound`)}`);n[e]={source:i.source,...o?{provider:o}:{},id:a}}return{enabled:e.enabled,defaultEnv:e.defaultEnv.trim(),defaultFile:e.defaultFile.trim(),defaultExec:e.defaultExec.trim(),providers:Object.entries(t).map(([e,t])=>D(e,t)),refs:Object.entries(n).map(([e,t])=>({path:e,source:t.source,provider:t.provider??``,id:t.id}))}}function j(e){return{enabled:e.enabled,defaults:{env:e.defaultEnv||null,file:e.defaultFile||null,exec:e.defaultExec||null},providers:Object.fromEntries(e.providers.map(e=>[e.alias.trim(),O(e)]).filter(([e])=>e)),refs:Object.fromEntries(e.refs.map(e=>[e.path.trim(),{source:e.source,...e.provider.trim()?{provider:e.provider.trim()}:{},id:e.id.trim()}]).filter(([e,t])=>e&&t.id))}}var M=t();function N(e){let{defaultEnv:t,defaultFile:n,defaultExec:r,providerAliases:i,onChange:o}=e;return(0,M.jsx)(M.Fragment,{children:[{label:d(`defaultEnvProvider`),value:t,key:`defaultEnv`},{label:d(`defaultFileProvider`),value:n,key:`defaultFile`},{label:d(`defaultExecProvider`),value:r,key:`defaultExec`}].map(e=>(0,M.jsx)(a,{title:e.label,control:(0,M.jsxs)(g,{value:e.value||`__none__`,onValueChange:t=>o(e.key,t===`__none__`?``:t),children:[(0,M.jsx)(p,{className:`w-56`,children:(0,M.jsx)(f,{placeholder:d(`noneOption`)})}),(0,M.jsxs)(m,{children:[(0,M.jsx)(h,{value:`__none__`,children:d(`noneOption`)}),i.map(e=>(0,M.jsx)(h,{value:e,children:e},e))]})]})},e.key))})}function P(e){let{providers:t,onUpdate:n,onRemove:a,onAdd:o}=e;return(0,M.jsx)(i,{title:d(`secretProvidersTitle`),description:d(`secretProvidersDescription`),actions:(0,M.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[(0,M.jsx)(_,{className:`mr-2 h-4 w-4`}),d(`addSecretProvider`)]}),children:(0,M.jsx)(l,{children:t.map((e,t)=>(0,M.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-3`,children:[(0,M.jsx)(r,{value:e.alias,onChange:e=>n(t,{alias:e.target.value}),placeholder:d(`providerAlias`)}),(0,M.jsxs)(g,{value:e.source,onValueChange:e=>n(t,{source:e}),children:[(0,M.jsx)(p,{children:(0,M.jsx)(f,{})}),(0,M.jsx)(m,{children:w.map(e=>(0,M.jsx)(h,{value:e,children:e},e))})]}),(0,M.jsxs)(c,{type:`button`,variant:`outline`,onClick:()=>a(t),children:[(0,M.jsx)(y,{className:`mr-2 h-4 w-4`}),d(`removeProvider`)]})]}),e.source===`env`?(0,M.jsx)(r,{value:e.prefix,onChange:e=>n(t,{prefix:e.target.value}),placeholder:d(`envPrefix`)}):null,e.source===`file`?(0,M.jsx)(r,{value:e.path,onChange:e=>n(t,{path:e.target.value}),placeholder:d(`secretFilePath`)}):null,e.source===`exec`?(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsx)(r,{value:e.command,onChange:e=>n(t,{command:e.target.value}),placeholder:d(`secretExecCommand`)}),(0,M.jsx)(`textarea`,{className:`min-h-[84px] w-full rounded-lg border border-input bg-background px-3 py-2 font-mono text-xs`,value:e.argsText,onChange:e=>n(t,{argsText:e.target.value}),placeholder:d(`secretExecArgs`)}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 md:grid-cols-2`,children:[(0,M.jsx)(r,{value:e.cwd,onChange:e=>n(t,{cwd:e.target.value}),placeholder:d(`secretExecCwd`)}),(0,M.jsx)(r,{type:`number`,min:1,value:e.timeoutMs,onChange:e=>n(t,{timeoutMs:Number.parseInt(e.target.value,10)||5e3}),placeholder:d(`secretExecTimeoutMs`)})]})]}):null]},`provider-${t}`))})})}function F(e){let{refs:t,providerAliases:n,onUpdate:a,onRemove:o,onAdd:s}=e;return(0,M.jsx)(i,{title:d(`secretRefsTitle`),description:d(`secretRefsDescription`),actions:(0,M.jsxs)(c,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[(0,M.jsx)(_,{className:`mr-2 h-4 w-4`}),d(`addSecretRef`)]}),children:(0,M.jsx)(l,{children:t.map((e,t)=>(0,M.jsx)(`div`,{className:`space-y-3 p-4`,children:(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:[(0,M.jsx)(r,{value:e.path,onChange:e=>a(t,{path:e.target.value}),placeholder:d(`secretConfigPath`)}),(0,M.jsx)(r,{value:e.id,onChange:e=>a(t,{id:e.target.value}),placeholder:d(`secretId`)}),(0,M.jsxs)(g,{value:e.source,onValueChange:e=>a(t,{source:e}),children:[(0,M.jsx)(p,{children:(0,M.jsx)(f,{})}),(0,M.jsx)(m,{children:w.map(e=>(0,M.jsx)(h,{value:e,children:e},e))})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2`,children:[(0,M.jsxs)(g,{value:e.provider||`__none__`,onValueChange:e=>a(t,{provider:e===`__none__`?``:e}),children:[(0,M.jsx)(p,{children:(0,M.jsx)(f,{placeholder:d(`secretProviderAlias`)})}),(0,M.jsxs)(m,{children:[(0,M.jsx)(h,{value:`__none__`,children:d(`noneOption`)}),n.map(e=>(0,M.jsx)(h,{value:e,children:e},e))]})]}),(0,M.jsx)(c,{type:`button`,variant:`outline`,onClick:()=>o(t),children:(0,M.jsx)(y,{className:`h-4 w-4`})})]})]})},`ref-${t}`))})})}function I(e){let{initialState:t,isPending:n,onSubmit:r}=e,[f,p]=(0,C.useState)(t),m=(0,C.useMemo)(()=>{let e=f.providers.map(e=>e.alias.trim()).filter(Boolean);return Array.from(new Set(e))},[f.providers]);return(0,M.jsxs)(o,{title:d(`secretsPageTitle`),description:d(`secretsPageDescription`),children:[(0,M.jsx)(i,{title:d(`secrets`),description:d(`secretsEnabledHelp`),children:(0,M.jsxs)(l,{children:[(0,M.jsx)(a,{title:d(`enabled`),description:d(`secretsEnabledHelp`),control:(0,M.jsx)(s,{checked:f.enabled,onCheckedChange:e=>p(t=>({...t,enabled:e}))})}),(0,M.jsx)(N,{defaultEnv:f.defaultEnv,defaultFile:f.defaultFile,defaultExec:f.defaultExec,providerAliases:m,onChange:(e,t)=>p(n=>({...n,[e]:t}))})]})}),(0,M.jsx)(P,{providers:f.providers,onUpdate:(e,t)=>{p(n=>({...n,providers:n.providers.map((n,r)=>r===e?{...n,...t}:n)}))},onRemove:e=>p(t=>({...t,providers:t.providers.filter((t,n)=>n!==e)})),onAdd:()=>p(e=>({...e,providers:[...e.providers,T()]}))}),(0,M.jsx)(F,{refs:f.refs,providerAliases:m,onUpdate:(e,t)=>{p(n=>({...n,refs:n.refs.map((n,r)=>r===e?{...n,...t}:n)}))},onRemove:e=>p(t=>({...t,refs:t.refs.filter((t,n)=>n!==e)})),onAdd:()=>p(e=>({...e,refs:[...e.refs,E()]}))}),(0,M.jsx)(S,{children:(0,M.jsxs)(c,{type:`button`,size:`sm`,onClick:()=>{try{r(A(f))}catch(e){u.error(e instanceof Error?e.message:String(e))}},disabled:n,children:[(0,M.jsx)(v,{className:`mr-1.5 h-3.5 w-3.5`}),d(n?`saving`:`save`)]})})]})}function L(){let{data:e,isLoading:t}=x(),n=b();return t?(0,M.jsx)(o,{title:d(`secretsPageTitle`),description:d(`secretsPageDescription`),children:(0,M.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:d(`loading`)})}):(0,M.jsx)(I,{initialState:k(e?.secrets),isPending:n.isPending,onSubmit:e=>n.mutate({data:j(e)})},JSON.stringify(e?.secrets??null))}export{L as SecretsConfigPage};
@@ -0,0 +1 @@
1
+ import{zt as e}from"./api-DqzQ-_3w.js";export{e as SecurityConfig};
@@ -1 +1 @@
1
- import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n,t as r}from"./utils-CBZPzC_b.js";import{Lt as i,Yt as a,bn as o,jn as s,yn as c}from"./api-BWFOIoUm.js";import{s as l}from"./i18n-ClHx6jwj.js";import{t as u}from"./createLucideIcon-BNKf0_kc.js";import{d,f,g as p,h as m,i as h,o as g,p as _,r as v,s as y,u as b}from"./app-data-BnrEdmg2.js";import{t as x}from"./boxes-D6uPnkGo.js";import{t as S}from"./chevron-down-BL-yMYcX.js";import{t as C}from"./circle-dashed-CU3yApvP.js";import{i as w,n as T,r as E,t as D,u as O}from"./tooltip-DYcuWhuP.js";import{t as k}from"./loader-circle-K1BDdHR5.js";import{t as A}from"./refresh-cw-h9Xq3LY3.js";import{t as j}from"./trash-2-BPPYt2NV.js";import{a as M,i as N,n as P,o as F,r as I,t as L}from"./dialog-Xe73hpQz.js";import{i as R,r as z,t as B}from"./popover-NkrFlWHp.js";var V=u(`CirclePause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),H=u(`Radar`,[[`path`,{d:`M19.07 4.93A10 10 0 0 0 6.99 3.34`,key:`z3du51`}],[`path`,{d:`M4 6h.01`,key:`oypzma`}],[`path`,{d:`M2.29 9.62A10 10 0 1 0 21.31 8.35`,key:`qzzz0`}],[`path`,{d:`M16.24 7.76A6 6 0 1 0 8.23 16.67`,key:`1yjesh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M17.99 11.66A6 6 0 0 1 15.77 16.67`,key:`1u2y91`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`m13.41 10.59 5.66-5.66`,key:`mhq4k0`}]]),U=u(`ShieldPlus`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9 12h6`,key:`1c52cq`}],[`path`,{d:`M12 9v6`,key:`199k2o`}]]),ee=u(`Unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),W=e(n(),1),G=t();function te({appId:e,appTitle:t,dataEntry:n,dataLoading:r,deleteError:i,deletePending:o,open:s,purgeData:c,onDelete:u,onOpenChange:d,onPurgeDataChange:f}){let p=(0,W.useRef)(null);(0,W.useEffect)(()=>{i&&p.current?.focus()},[i]);let m=()=>d(!1);return(0,G.jsx)(L,{open:s,onOpenChange:e=>!o&&d(e),children:(0,G.jsxs)(P,{className:`max-w-md [&>:last-child]:hidden`,onEscapeKeyDown:e=>o&&e.preventDefault(),onInteractOutside:e=>o&&e.preventDefault(),children:[(0,G.jsxs)(M,{children:[(0,G.jsx)(F,{children:l(`serviceAppsDeleteConfirmTitle`)}),(0,G.jsxs)(I,{children:[l(`serviceAppsDeleteConfirmDescription`),` `,t]})]}),(0,G.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,G.jsx)(g,{checked:!c,description:l(`serviceAppsKeepDataDescription`),label:l(`appPackagesKeepData`),onClick:()=>f(!1)}),(0,G.jsx)(g,{checked:c,destructive:!0,disabled:!n||r,description:l(`serviceAppsDeleteDataDescription`),label:l(`appPackagesDeleteData`),onClick:()=>f(!0)})]}),n?(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(h,{storage:n.storage,usage:n.usage})}):(0,G.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-muted-foreground`,children:l(r?`appPackagesLoading`:`serviceAppsDataUnavailable`)}),i?(0,G.jsx)(`p`,{ref:p,role:`alert`,tabIndex:-1,className:`mt-3 text-xs text-destructive`,children:i instanceof Error?i.message:l(`appPackagesActionFailed`)}):null,(0,G.jsxs)(N,{className:`mt-5 gap-2 sm:gap-0`,children:[(0,G.jsx)(a,{autoFocus:!0,type:`button`,variant:`outline`,disabled:o,onClick:m,children:l(`cancel`)}),(0,G.jsxs)(a,{type:`button`,variant:c?`destructive`:`default`,disabled:o||c&&!n,onClick:()=>u(e,c,m),children:[o?(0,G.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):null,l(c?`appDataDeletePermanently`:`serviceAppsDelete`)]})]})]})})}function ne({action:e,grants:t,agents:n,grantAgentPending:r,onGrantAgent:i,onRevoke:a}){let[o,s]=(0,W.useState)(!1),c=new Set(t.flatMap(e=>e.caller.surface===`agent`?[e.caller.agentId]:[])),u=n.filter(e=>!c.has(e.id));return(0,G.jsxs)(`div`,{className:`py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`flex h-6 w-6 shrink-0 items-center justify-center text-muted-foreground`,children:(0,G.jsx)(b,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`truncate text-xs font-medium text-foreground`,children:e.title??e.name}),e.description?(0,G.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.description}):null]})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[e.runtimeState?(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:l(`serviceAppsRuntimeState_${e.runtimeState}`)}):null,(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e.risk}),(0,G.jsxs)(B,{open:o,onOpenChange:s,children:[(0,G.jsx)(R,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,disabled:r||u.length===0,className:`ml-1 rounded-md p-1 text-muted-foreground/70 transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border disabled:cursor-not-allowed disabled:opacity-40`,title:l(`serviceAppsGrantToAgent`),"aria-label":l(`serviceAppsGrantToAgent`),children:(0,G.jsx)(U,{className:`h-3.5 w-3.5`})})}),(0,G.jsxs)(z,{align:`end`,className:`w-56 rounded-xl p-1.5`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1.5 text-[11px] font-medium text-muted-foreground`,children:l(`serviceAppsGrantToAgent`)}),u.map(t=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{i(e.id,t.id),s(!1)},className:`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border`,children:[(0,G.jsx)(p,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`min-w-0 truncate`,children:t.displayName?.trim()||t.id})]},t.id))]})]})]})]}),t.map(e=>(0,G.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 pl-8`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,G.jsx)(f,{className:`h-3 w-3 shrink-0 text-emerald-500`}),(0,G.jsxs)(`span`,{className:`truncate`,children:[l(`serviceAppsGrantedTo`),` `,K(e)]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:`rounded-md p-1 text-muted-foreground/70 transition-colors hover:bg-muted hover:text-rose-600 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border`,title:l(`serviceAppsRevokeGrant`),"aria-label":l(`serviceAppsRevokeGrant`),children:(0,G.jsx)(j,{className:`h-3 w-3`})})]},`${e.caller.surface}:${K(e)}:${e.actionId}`))]})}function K(e){return e.caller.surface===`panel-app`?e.caller.appId:e.caller.agentId}function q({app:e,actions:t,actionsOpen:n,grants:i,agents:a,deletePending:o,deleteError:s,dataEntry:c,dataLoading:u,isDiscovering:d,onActionsOpenChange:f,onDiscover:p,onManagePackage:m,onDelete:h,onResetDelete:g,onRestart:v,onRevoke:y,onGrantAgent:b,grantAgentPending:C}){let[A,M]=(0,W.useState)(!1),[N,P]=(0,W.useState)(!1),[F,I]=(0,W.useState)(!1),[L,V]=(0,W.useState)(!1),U=e.status!==`starting`&&e.status!==`stopped`,K=e.status===`running`||e.status===`failed`,q=e.sourceKind===`package`?e.packageId:void 0,J=ie(e),X=()=>{M(!1),V(!1),g(),P(!0)};return(0,G.jsx)(E,{delayDuration:250,children:(0,G.jsxs)(`section`,{className:`group bg-card transition-colors hover:bg-muted/25`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 px-4 py-3.5`,children:[(0,G.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground`,children:(0,G.jsx)(_,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.title}),(0,G.jsx)(re,{status:e.status})]}),e.description?(0,G.jsx)(`div`,{className:`mt-1 truncate text-xs leading-5 text-muted-foreground`,children:e.description}):null,e.lastError?(0,G.jsx)(`div`,{className:`mt-1.5 truncate text-xs text-rose-600`,title:e.lastError,children:e.lastError}):null]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[U?(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsxs)(`button`,{type:`button`,disabled:d,className:`inline-flex h-7 items-center gap-1.5 rounded-md bg-foreground px-2.5 text-xs font-medium text-background transition-colors hover:bg-foreground/85 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/40 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":l(`serviceAppsDiscoverActions`),onClick:()=>p(e.id),children:[d?(0,G.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}):(0,G.jsx)(H,{className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:l(`serviceAppsConnect`)})]})}),(0,G.jsx)(T,{side:`bottom`,className:`max-w-56 text-xs`,children:l(`serviceAppsDiscoverActionsHint`)})]}):null,(0,G.jsxs)(B,{open:A,onOpenChange:M,children:[(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsx)(R,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border disabled:opacity-50`,"aria-label":l(`serviceAppsMoreActions`),disabled:o,children:(0,G.jsx)(O,{className:`h-3.5 w-3.5`})})})}),(0,G.jsx)(T,{side:`bottom`,className:`text-xs`,children:l(`serviceAppsMoreActions`)})]}),(0,G.jsxs)(z,{align:`end`,className:`w-48 rounded-xl p-1.5`,children:[(0,G.jsx)(Y,{disabled:!K,icon:ee,label:l(`serviceAppsDisconnectRuntime`),onClick:()=>{M(!1),v(e.id)}}),q?(0,G.jsx)(Y,{icon:x,label:l(`serviceAppsManagePackage`),onClick:()=>{M(!1),m(q)}}):(0,G.jsx)(Y,{destructive:!0,disabled:o,icon:j,label:l(`serviceAppsDelete`),onClick:X})]})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-border/60`,children:[(0,G.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>f(!n),className:`flex min-w-0 flex-1 items-center justify-between gap-2 px-4 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border`,"aria-expanded":n,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{children:l(`serviceAppsActionsSection`)}),(0,G.jsx)(`span`,{className:`tabular-nums text-muted-foreground/70`,children:t.length})]}),(0,G.jsx)(S,{className:r(`h-3.5 w-3.5 shrink-0 text-muted-foreground/70 transition-transform`,n&&`rotate-180`)})]}),J.length>0?(0,G.jsxs)(`button`,{type:`button`,onClick:()=>I(e=>!e),className:`flex shrink-0 items-center gap-1 border-l border-border/60 px-3 text-xs text-muted-foreground transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border`,"aria-expanded":F,children:[(0,G.jsx)(`span`,{children:l(`serviceAppsDetails`)}),(0,G.jsx)(S,{className:r(`h-3.5 w-3.5 transition-transform`,F&&`rotate-180`)})]}):null]}),n?(0,G.jsx)(`div`,{className:`border-t border-border/60 px-4 py-2.5`,children:t.length===0?(0,G.jsx)(`div`,{className:`py-1 text-xs text-muted-foreground`,children:l(`serviceAppsActionsEmpty`)}):(0,G.jsx)(`div`,{className:`divide-y divide-border/50`,children:t.map(e=>(0,G.jsx)(ne,{action:e,grants:i.filter(t=>t.actionId===e.id),agents:a,grantAgentPending:C,onGrantAgent:b,onRevoke:y},e.id))})}):null,F?(0,G.jsx)(ae,{rows:J}):null]}),e.sourceKind===`package`?null:(0,G.jsx)(te,{appId:e.id,appTitle:e.title,dataEntry:c,dataLoading:u,deleteError:s,deletePending:o,open:N,purgeData:L,onDelete:h,onOpenChange:P,onPurgeDataChange:V})]})})}function re({status:e}){let t=J(e),n=t.icon;return(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsxs)(`span`,{className:r(`inline-flex shrink-0 items-center gap-1 text-xs`,t.className),"aria-label":t.label,children:[(0,G.jsx)(n,{className:r(`h-3 w-3`,t.iconClassName)}),(0,G.jsx)(`span`,{children:t.label})]})}),(0,G.jsx)(T,{side:`bottom`,className:`text-xs`,children:t.tooltip})]})}function J(e){switch(e){case`running`:return{className:`text-emerald-700`,icon:m,label:l(`serviceAppsStatus_running`),tooltip:l(`serviceAppsStatusHint_running`)};case`starting`:return{className:`text-blue-700`,icon:k,iconClassName:`animate-spin`,label:l(`serviceAppsStatus_starting`),tooltip:l(`serviceAppsStatusHint_starting`)};case`failed`:return{className:`text-rose-700`,icon:d,label:l(`serviceAppsStatus_failed`),tooltip:l(`serviceAppsStatusHint_failed`)};case`stopped`:return{className:`text-muted-foreground`,icon:V,label:l(`serviceAppsStatus_stopped`),tooltip:l(`serviceAppsStatusHint_stopped`)};default:return{className:`text-muted-foreground`,icon:C,label:l(`serviceAppsStatus_idle`),tooltip:l(`serviceAppsStatusHint_idle`)}}}function Y({destructive:e=!1,disabled:t=!1,icon:n,label:i,onClick:a}){return(0,G.jsxs)(`button`,{type:`button`,className:r(`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border disabled:cursor-not-allowed disabled:opacity-50`,e?`text-destructive hover:bg-destructive/10`:`text-muted-foreground hover:bg-[var(--interaction-hover)] hover:text-accent-foreground`),disabled:t,onClick:a,children:[(0,G.jsx)(n,{className:`h-4 w-4 shrink-0`}),(0,G.jsx)(`span`,{children:i})]})}function ie(e){let t=[e.command,...e.args??[]].filter(e=>!!e?.trim()).join(` `);return[{label:l(`serviceAppsCommand`),value:t},{label:l(`serviceAppsCwd`),value:e.cwd},{label:l(`serviceAppsManifest`),value:e.manifestPath},{label:l(`serviceAppsLastStarted`),value:e.lastStartedAt},{label:l(`serviceAppsLastReady`),value:e.lastReadyAt},{label:l(`serviceAppsLastFailed`),value:e.lastFailedAt}].filter(e=>e.value)}function ae({rows:e}){return(0,G.jsx)(`div`,{className:`border-t border-border/60 px-4 py-2.5`,children:(0,G.jsx)(`dl`,{className:`grid grid-cols-[4.75rem_minmax(0,1fr)] gap-x-3 gap-y-1.5 text-xs`,children:e.map(e=>(0,G.jsx)(X,{label:e.label,value:e.value},e.label))})})}function X({label:e,value:t}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-muted-foreground/70`,children:e}),(0,G.jsx)(`dd`,{className:`min-w-0 truncate font-mono text-muted-foreground`,title:t,children:t})]})}var Z=[`service-apps`],Q=[`service-actions`],$=[`service-action-grants`],oe=[`app-data`];function se(){return o({queryKey:Z,queryFn:()=>i.serviceApps.listServiceApps()})}function ce(){return o({queryKey:Q,queryFn:()=>i.serviceApps.listServiceActions()})}function le(){return o({queryKey:$,queryFn:()=>i.serviceApps.listServiceActionGrants()})}function ue(){let e=s();return c({mutationFn:e=>i.serviceApps.restartServiceApp(e),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Z}),e.invalidateQueries({queryKey:Q})])}})}function de(){let e=s();return c({mutationFn:e=>i.serviceApps.deleteServiceApp(e.appId,e.purgeData),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Z}),e.invalidateQueries({queryKey:Q}),e.invalidateQueries({queryKey:$}),e.invalidateQueries({queryKey:oe})])}})}function fe(){let e=s();return c({mutationFn:e=>i.serviceApps.discoverServiceAppActions(e),onSuccess:async()=>{await e.invalidateQueries({queryKey:Z})}})}function pe(){let e=s();return c({mutationFn:e=>i.serviceApps.revokeServiceActionGrant(e),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Q}),e.invalidateQueries({queryKey:$})])}})}function me(){let e=s();return c({mutationFn:e=>i.serviceApps.grantAgentServiceActions(e.agentId,e.actionIds),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Q}),e.invalidateQueries({queryKey:$})])}})}function he({onManagePackage:e}){let t=se(),n=v(),r=ce(),i=le(),a=y(),o=de(),s=ue(),c=fe(),u=pe(),d=me(),[f,p]=(0,W.useState)({}),[m,h]=(0,W.useState)({}),g=()=>{t.refetch(),r.refetch(),i.refetch(),n.refetch()};if(t.isLoading||r.isLoading||i.isLoading)return(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:l(`serviceAppsLoading`)});if(t.isError||r.isError||i.isError){let e=t.error??r.error??i.error;return(0,G.jsx)(`div`,{className:`p-4 text-sm text-rose-600`,children:e instanceof Error?e.message:l(`serviceAppsLoadFailed`)})}let b=t.data?.entries??[],x=t.data?.diagnostics??[],S=r.data?.actions??[],C=i.data?.grants??[],O=e=>{c.mutateAsync(e).then(t=>{p(n=>({...n,[e]:t.actions})),h(t=>({...t,[e]:!0}))})},k=(n.data?.entries??[]).filter(e=>e.source===`workspace-service`&&e.lifecycle===`active`);return(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-card text-card-foreground`,children:[(0,G.jsx)(`div`,{className:`flex min-h-12 shrink-0 items-center justify-end border-b border-border/60 px-4 py-2`,children:(0,G.jsx)(E,{delayDuration:250,children:(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border`,"aria-label":l(`serviceAppsRefresh`),onClick:g,children:(0,G.jsx)(A,{className:`h-3.5 w-3.5`})})}),(0,G.jsx)(T,{side:`bottom`,className:`text-xs`,children:l(`serviceAppsRefresh`)})]})})}),x.length>0?(0,G.jsxs)(`div`,{role:`alert`,className:`mx-3 mt-3 rounded-xl border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive sm:mx-4`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:l(`serviceAppsLoadFailed`)}),(0,G.jsx)(`ul`,{className:`mt-1 space-y-1`,children:x.map(e=>(0,G.jsxs)(`li`,{className:`break-words`,children:[e.appId,`: `,e.message]},e.stagedPath))})]}):null,b.length===0?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 py-8 text-center`,children:(0,G.jsxs)(`div`,{className:`w-full max-w-xs`,children:[(0,G.jsx)(`div`,{className:`mx-auto flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground`,children:(0,G.jsx)(_,{className:`h-5 w-5`})}),(0,G.jsx)(`h2`,{className:`mt-3 text-sm font-semibold text-foreground`,children:l(`serviceAppsEmptyTitle`)}),(0,G.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:l(`serviceAppsEmptyDescription`)})]})}):(0,G.jsx)(`div`,{className:`custom-scrollbar min-h-0 flex-1 overflow-y-auto p-3 sm:p-4`,children:(0,G.jsx)(`div`,{className:`overflow-hidden rounded-xl border border-border/70 bg-card`,children:b.map(t=>(0,G.jsx)(q,{app:t,actions:f[t.id]??S.filter(e=>e.appId===t.id),actionsOpen:!!m[t.id],grants:C,agents:a.data?.agents??[],deletePending:o.isPending,deleteError:o.error,dataEntry:k.find(e=>e.appId===t.id),dataLoading:n.isLoading,isDiscovering:c.isPending,onActionsOpenChange:e=>h(n=>({...n,[t.id]:e})),onDiscover:O,onManagePackage:e,onDelete:(e,t,n)=>void o.mutate({appId:e,purgeData:t},{onSuccess:n}),onResetDelete:o.reset,onRestart:e=>void s.mutate(e),onRevoke:e=>void u.mutate({actionId:e.actionId,caller:e.caller}),onGrantAgent:(e,t)=>void d.mutate({actionIds:[e],agentId:t}),grantAgentPending:d.isPending},t.id))})})]})}export{he as ServiceAppsPanel};
1
+ import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n,t as r}from"./utils-CBZPzC_b.js";import{Lt as i,Yt as a,bn as o,jn as s,yn as c}from"./api-DqzQ-_3w.js";import{s as l}from"./i18n-20rSH40D.js";import{t as u}from"./createLucideIcon-BNKf0_kc.js";import{d,f,g as p,h as m,i as h,o as g,p as _,r as v,s as y,u as b}from"./app-data-C54N2p8b.js";import{t as x}from"./boxes-D6uPnkGo.js";import{t as S}from"./chevron-down-BL-yMYcX.js";import{t as C}from"./circle-dashed-CU3yApvP.js";import{i as w,n as T,r as E,t as D,u as O}from"./tooltip-DYcuWhuP.js";import{t as k}from"./loader-circle-K1BDdHR5.js";import{t as A}from"./refresh-cw-h9Xq3LY3.js";import{t as j}from"./trash-2-BPPYt2NV.js";import{a as M,i as N,n as P,o as F,r as I,t as L}from"./dialog-Xe73hpQz.js";import{i as R,r as z,t as B}from"./popover-NkrFlWHp.js";var V=u(`CirclePause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),H=u(`Radar`,[[`path`,{d:`M19.07 4.93A10 10 0 0 0 6.99 3.34`,key:`z3du51`}],[`path`,{d:`M4 6h.01`,key:`oypzma`}],[`path`,{d:`M2.29 9.62A10 10 0 1 0 21.31 8.35`,key:`qzzz0`}],[`path`,{d:`M16.24 7.76A6 6 0 1 0 8.23 16.67`,key:`1yjesh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M17.99 11.66A6 6 0 0 1 15.77 16.67`,key:`1u2y91`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`m13.41 10.59 5.66-5.66`,key:`mhq4k0`}]]),U=u(`ShieldPlus`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9 12h6`,key:`1c52cq`}],[`path`,{d:`M12 9v6`,key:`199k2o`}]]),ee=u(`Unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),W=e(n(),1),G=t();function te({appId:e,appTitle:t,dataEntry:n,dataLoading:r,deleteError:i,deletePending:o,open:s,purgeData:c,onDelete:u,onOpenChange:d,onPurgeDataChange:f}){let p=(0,W.useRef)(null);(0,W.useEffect)(()=>{i&&p.current?.focus()},[i]);let m=()=>d(!1);return(0,G.jsx)(L,{open:s,onOpenChange:e=>!o&&d(e),children:(0,G.jsxs)(P,{className:`max-w-md [&>:last-child]:hidden`,onEscapeKeyDown:e=>o&&e.preventDefault(),onInteractOutside:e=>o&&e.preventDefault(),children:[(0,G.jsxs)(M,{children:[(0,G.jsx)(F,{children:l(`serviceAppsDeleteConfirmTitle`)}),(0,G.jsxs)(I,{children:[l(`serviceAppsDeleteConfirmDescription`),` `,t]})]}),(0,G.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,G.jsx)(g,{checked:!c,description:l(`serviceAppsKeepDataDescription`),label:l(`appPackagesKeepData`),onClick:()=>f(!1)}),(0,G.jsx)(g,{checked:c,destructive:!0,disabled:!n||r,description:l(`serviceAppsDeleteDataDescription`),label:l(`appPackagesDeleteData`),onClick:()=>f(!0)})]}),n?(0,G.jsx)(`div`,{className:`mt-3`,children:(0,G.jsx)(h,{storage:n.storage,usage:n.usage})}):(0,G.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-muted-foreground`,children:l(r?`appPackagesLoading`:`serviceAppsDataUnavailable`)}),i?(0,G.jsx)(`p`,{ref:p,role:`alert`,tabIndex:-1,className:`mt-3 text-xs text-destructive`,children:i instanceof Error?i.message:l(`appPackagesActionFailed`)}):null,(0,G.jsxs)(N,{className:`mt-5 gap-2 sm:gap-0`,children:[(0,G.jsx)(a,{autoFocus:!0,type:`button`,variant:`outline`,disabled:o,onClick:m,children:l(`cancel`)}),(0,G.jsxs)(a,{type:`button`,variant:c?`destructive`:`default`,disabled:o||c&&!n,onClick:()=>u(e,c,m),children:[o?(0,G.jsx)(k,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):null,l(c?`appDataDeletePermanently`:`serviceAppsDelete`)]})]})]})})}function ne({action:e,grants:t,agents:n,grantAgentPending:r,onGrantAgent:i,onRevoke:a}){let[o,s]=(0,W.useState)(!1),c=new Set(t.flatMap(e=>e.caller.surface===`agent`?[e.caller.agentId]:[])),u=n.filter(e=>!c.has(e.id));return(0,G.jsxs)(`div`,{className:`py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`flex h-6 w-6 shrink-0 items-center justify-center text-muted-foreground`,children:(0,G.jsx)(b,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`truncate text-xs font-medium text-foreground`,children:e.title??e.name}),e.description?(0,G.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.description}):null]})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[e.runtimeState?(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:l(`serviceAppsRuntimeState_${e.runtimeState}`)}):null,(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e.risk}),(0,G.jsxs)(B,{open:o,onOpenChange:s,children:[(0,G.jsx)(R,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,disabled:r||u.length===0,className:`ml-1 rounded-md p-1 text-muted-foreground/70 transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border disabled:cursor-not-allowed disabled:opacity-40`,title:l(`serviceAppsGrantToAgent`),"aria-label":l(`serviceAppsGrantToAgent`),children:(0,G.jsx)(U,{className:`h-3.5 w-3.5`})})}),(0,G.jsxs)(z,{align:`end`,className:`w-56 rounded-xl p-1.5`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1.5 text-[11px] font-medium text-muted-foreground`,children:l(`serviceAppsGrantToAgent`)}),u.map(t=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{i(e.id,t.id),s(!1)},className:`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border`,children:[(0,G.jsx)(p,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`min-w-0 truncate`,children:t.displayName?.trim()||t.id})]},t.id))]})]})]})]}),t.map(e=>(0,G.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 pl-8`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,G.jsx)(f,{className:`h-3 w-3 shrink-0 text-emerald-500`}),(0,G.jsxs)(`span`,{className:`truncate`,children:[l(`serviceAppsGrantedTo`),` `,K(e)]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:`rounded-md p-1 text-muted-foreground/70 transition-colors hover:bg-muted hover:text-rose-600 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border`,title:l(`serviceAppsRevokeGrant`),"aria-label":l(`serviceAppsRevokeGrant`),children:(0,G.jsx)(j,{className:`h-3 w-3`})})]},`${e.caller.surface}:${K(e)}:${e.actionId}`))]})}function K(e){return e.caller.surface===`panel-app`?e.caller.appId:e.caller.agentId}function q({app:e,actions:t,actionsOpen:n,grants:i,agents:a,deletePending:o,deleteError:s,dataEntry:c,dataLoading:u,isDiscovering:d,onActionsOpenChange:f,onDiscover:p,onManagePackage:m,onDelete:h,onResetDelete:g,onRestart:v,onRevoke:y,onGrantAgent:b,grantAgentPending:C}){let[A,M]=(0,W.useState)(!1),[N,P]=(0,W.useState)(!1),[F,I]=(0,W.useState)(!1),[L,V]=(0,W.useState)(!1),U=e.status!==`starting`&&e.status!==`stopped`,K=e.status===`running`||e.status===`failed`,q=e.sourceKind===`package`?e.packageId:void 0,J=ie(e),X=()=>{M(!1),V(!1),g(),P(!0)};return(0,G.jsx)(E,{delayDuration:250,children:(0,G.jsxs)(`section`,{className:`group bg-card transition-colors hover:bg-muted/25`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 px-4 py-3.5`,children:[(0,G.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground`,children:(0,G.jsx)(_,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.title}),(0,G.jsx)(re,{status:e.status})]}),e.description?(0,G.jsx)(`div`,{className:`mt-1 truncate text-xs leading-5 text-muted-foreground`,children:e.description}):null,e.lastError?(0,G.jsx)(`div`,{className:`mt-1.5 truncate text-xs text-rose-600`,title:e.lastError,children:e.lastError}):null]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[U?(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsxs)(`button`,{type:`button`,disabled:d,className:`inline-flex h-7 items-center gap-1.5 rounded-md bg-foreground px-2.5 text-xs font-medium text-background transition-colors hover:bg-foreground/85 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/40 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":l(`serviceAppsDiscoverActions`),onClick:()=>p(e.id),children:[d?(0,G.jsx)(k,{className:`h-3.5 w-3.5 animate-spin`}):(0,G.jsx)(H,{className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:l(`serviceAppsConnect`)})]})}),(0,G.jsx)(T,{side:`bottom`,className:`max-w-56 text-xs`,children:l(`serviceAppsDiscoverActionsHint`)})]}):null,(0,G.jsxs)(B,{open:A,onOpenChange:M,children:[(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsx)(R,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border disabled:opacity-50`,"aria-label":l(`serviceAppsMoreActions`),disabled:o,children:(0,G.jsx)(O,{className:`h-3.5 w-3.5`})})})}),(0,G.jsx)(T,{side:`bottom`,className:`text-xs`,children:l(`serviceAppsMoreActions`)})]}),(0,G.jsxs)(z,{align:`end`,className:`w-48 rounded-xl p-1.5`,children:[(0,G.jsx)(Y,{disabled:!K,icon:ee,label:l(`serviceAppsDisconnectRuntime`),onClick:()=>{M(!1),v(e.id)}}),q?(0,G.jsx)(Y,{icon:x,label:l(`serviceAppsManagePackage`),onClick:()=>{M(!1),m(q)}}):(0,G.jsx)(Y,{destructive:!0,disabled:o,icon:j,label:l(`serviceAppsDelete`),onClick:X})]})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-border/60`,children:[(0,G.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>f(!n),className:`flex min-w-0 flex-1 items-center justify-between gap-2 px-4 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border`,"aria-expanded":n,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`span`,{children:l(`serviceAppsActionsSection`)}),(0,G.jsx)(`span`,{className:`tabular-nums text-muted-foreground/70`,children:t.length})]}),(0,G.jsx)(S,{className:r(`h-3.5 w-3.5 shrink-0 text-muted-foreground/70 transition-transform`,n&&`rotate-180`)})]}),J.length>0?(0,G.jsxs)(`button`,{type:`button`,onClick:()=>I(e=>!e),className:`flex shrink-0 items-center gap-1 border-l border-border/60 px-3 text-xs text-muted-foreground transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border`,"aria-expanded":F,children:[(0,G.jsx)(`span`,{children:l(`serviceAppsDetails`)}),(0,G.jsx)(S,{className:r(`h-3.5 w-3.5 transition-transform`,F&&`rotate-180`)})]}):null]}),n?(0,G.jsx)(`div`,{className:`border-t border-border/60 px-4 py-2.5`,children:t.length===0?(0,G.jsx)(`div`,{className:`py-1 text-xs text-muted-foreground`,children:l(`serviceAppsActionsEmpty`)}):(0,G.jsx)(`div`,{className:`divide-y divide-border/50`,children:t.map(e=>(0,G.jsx)(ne,{action:e,grants:i.filter(t=>t.actionId===e.id),agents:a,grantAgentPending:C,onGrantAgent:b,onRevoke:y},e.id))})}):null,F?(0,G.jsx)(ae,{rows:J}):null]}),e.sourceKind===`package`?null:(0,G.jsx)(te,{appId:e.id,appTitle:e.title,dataEntry:c,dataLoading:u,deleteError:s,deletePending:o,open:N,purgeData:L,onDelete:h,onOpenChange:P,onPurgeDataChange:V})]})})}function re({status:e}){let t=J(e),n=t.icon;return(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsxs)(`span`,{className:r(`inline-flex shrink-0 items-center gap-1 text-xs`,t.className),"aria-label":t.label,children:[(0,G.jsx)(n,{className:r(`h-3 w-3`,t.iconClassName)}),(0,G.jsx)(`span`,{children:t.label})]})}),(0,G.jsx)(T,{side:`bottom`,className:`text-xs`,children:t.tooltip})]})}function J(e){switch(e){case`running`:return{className:`text-emerald-700`,icon:m,label:l(`serviceAppsStatus_running`),tooltip:l(`serviceAppsStatusHint_running`)};case`starting`:return{className:`text-blue-700`,icon:k,iconClassName:`animate-spin`,label:l(`serviceAppsStatus_starting`),tooltip:l(`serviceAppsStatusHint_starting`)};case`failed`:return{className:`text-rose-700`,icon:d,label:l(`serviceAppsStatus_failed`),tooltip:l(`serviceAppsStatusHint_failed`)};case`stopped`:return{className:`text-muted-foreground`,icon:V,label:l(`serviceAppsStatus_stopped`),tooltip:l(`serviceAppsStatusHint_stopped`)};default:return{className:`text-muted-foreground`,icon:C,label:l(`serviceAppsStatus_idle`),tooltip:l(`serviceAppsStatusHint_idle`)}}}function Y({destructive:e=!1,disabled:t=!1,icon:n,label:i,onClick:a}){return(0,G.jsxs)(`button`,{type:`button`,className:r(`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border disabled:cursor-not-allowed disabled:opacity-50`,e?`text-destructive hover:bg-destructive/10`:`text-muted-foreground hover:bg-[var(--interaction-hover)] hover:text-accent-foreground`),disabled:t,onClick:a,children:[(0,G.jsx)(n,{className:`h-4 w-4 shrink-0`}),(0,G.jsx)(`span`,{children:i})]})}function ie(e){let t=[e.command,...e.args??[]].filter(e=>!!e?.trim()).join(` `);return[{label:l(`serviceAppsCommand`),value:t},{label:l(`serviceAppsCwd`),value:e.cwd},{label:l(`serviceAppsManifest`),value:e.manifestPath},{label:l(`serviceAppsLastStarted`),value:e.lastStartedAt},{label:l(`serviceAppsLastReady`),value:e.lastReadyAt},{label:l(`serviceAppsLastFailed`),value:e.lastFailedAt}].filter(e=>e.value)}function ae({rows:e}){return(0,G.jsx)(`div`,{className:`border-t border-border/60 px-4 py-2.5`,children:(0,G.jsx)(`dl`,{className:`grid grid-cols-[4.75rem_minmax(0,1fr)] gap-x-3 gap-y-1.5 text-xs`,children:e.map(e=>(0,G.jsx)(X,{label:e.label,value:e.value},e.label))})})}function X({label:e,value:t}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-muted-foreground/70`,children:e}),(0,G.jsx)(`dd`,{className:`min-w-0 truncate font-mono text-muted-foreground`,title:t,children:t})]})}var Z=[`service-apps`],Q=[`service-actions`],$=[`service-action-grants`],oe=[`app-data`];function se(){return o({queryKey:Z,queryFn:()=>i.serviceApps.listServiceApps()})}function ce(){return o({queryKey:Q,queryFn:()=>i.serviceApps.listServiceActions()})}function le(){return o({queryKey:$,queryFn:()=>i.serviceApps.listServiceActionGrants()})}function ue(){let e=s();return c({mutationFn:e=>i.serviceApps.restartServiceApp(e),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Z}),e.invalidateQueries({queryKey:Q})])}})}function de(){let e=s();return c({mutationFn:e=>i.serviceApps.deleteServiceApp(e.appId,e.purgeData),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Z}),e.invalidateQueries({queryKey:Q}),e.invalidateQueries({queryKey:$}),e.invalidateQueries({queryKey:oe})])}})}function fe(){let e=s();return c({mutationFn:e=>i.serviceApps.discoverServiceAppActions(e),onSuccess:async()=>{await e.invalidateQueries({queryKey:Z})}})}function pe(){let e=s();return c({mutationFn:e=>i.serviceApps.revokeServiceActionGrant(e),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Q}),e.invalidateQueries({queryKey:$})])}})}function me(){let e=s();return c({mutationFn:e=>i.serviceApps.grantAgentServiceActions(e.agentId,e.actionIds),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Q}),e.invalidateQueries({queryKey:$})])}})}function he({onManagePackage:e}){let t=se(),n=v(),r=ce(),i=le(),a=y(),o=de(),s=ue(),c=fe(),u=pe(),d=me(),[f,p]=(0,W.useState)({}),[m,h]=(0,W.useState)({}),g=()=>{t.refetch(),r.refetch(),i.refetch(),n.refetch()};if(t.isLoading||r.isLoading||i.isLoading)return(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:l(`serviceAppsLoading`)});if(t.isError||r.isError||i.isError){let e=t.error??r.error??i.error;return(0,G.jsx)(`div`,{className:`p-4 text-sm text-rose-600`,children:e instanceof Error?e.message:l(`serviceAppsLoadFailed`)})}let b=t.data?.entries??[],x=t.data?.diagnostics??[],S=r.data?.actions??[],C=i.data?.grants??[],O=e=>{c.mutateAsync(e).then(t=>{p(n=>({...n,[e]:t.actions})),h(t=>({...t,[e]:!0}))})},k=(n.data?.entries??[]).filter(e=>e.source===`workspace-service`&&e.lifecycle===`active`);return(0,G.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-card text-card-foreground`,children:[(0,G.jsx)(`div`,{className:`flex min-h-12 shrink-0 items-center justify-end border-b border-border/60 px-4 py-2`,children:(0,G.jsx)(E,{delayDuration:250,children:(0,G.jsxs)(D,{children:[(0,G.jsx)(w,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border`,"aria-label":l(`serviceAppsRefresh`),onClick:g,children:(0,G.jsx)(A,{className:`h-3.5 w-3.5`})})}),(0,G.jsx)(T,{side:`bottom`,className:`text-xs`,children:l(`serviceAppsRefresh`)})]})})}),x.length>0?(0,G.jsxs)(`div`,{role:`alert`,className:`mx-3 mt-3 rounded-xl border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive sm:mx-4`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:l(`serviceAppsLoadFailed`)}),(0,G.jsx)(`ul`,{className:`mt-1 space-y-1`,children:x.map(e=>(0,G.jsxs)(`li`,{className:`break-words`,children:[e.appId,`: `,e.message]},e.stagedPath))})]}):null,b.length===0?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-6 py-8 text-center`,children:(0,G.jsxs)(`div`,{className:`w-full max-w-xs`,children:[(0,G.jsx)(`div`,{className:`mx-auto flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground`,children:(0,G.jsx)(_,{className:`h-5 w-5`})}),(0,G.jsx)(`h2`,{className:`mt-3 text-sm font-semibold text-foreground`,children:l(`serviceAppsEmptyTitle`)}),(0,G.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:l(`serviceAppsEmptyDescription`)})]})}):(0,G.jsx)(`div`,{className:`custom-scrollbar min-h-0 flex-1 overflow-y-auto p-3 sm:p-4`,children:(0,G.jsx)(`div`,{className:`overflow-hidden rounded-xl border border-border/70 bg-card`,children:b.map(t=>(0,G.jsx)(q,{app:t,actions:f[t.id]??S.filter(e=>e.appId===t.id),actionsOpen:!!m[t.id],grants:C,agents:a.data?.agents??[],deletePending:o.isPending,deleteError:o.error,dataEntry:k.find(e=>e.appId===t.id),dataLoading:n.isLoading,isDiscovering:c.isPending,onActionsOpenChange:e=>h(n=>({...n,[t.id]:e})),onDiscover:O,onManagePackage:e,onDelete:(e,t,n)=>void o.mutate({appId:e,purgeData:t},{onSuccess:n}),onResetDelete:o.reset,onRestart:e=>void s.mutate(e),onRevoke:e=>void u.mutate({actionId:e.actionId,caller:e.caller}),onGrantAgent:(e,t)=>void d.mutate({actionIds:[e],agentId:t}),grantAgentPending:d.isPending},t.id))})})]})}export{he as ServiceAppsPanel};
@@ -1 +1 @@
1
- import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n,t as r}from"./utils-CBZPzC_b.js";import{Zt as i}from"./api-BWFOIoUm.js";var a=e(n(),1),o=t(),s=i(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium`,{variants:{tone:{subtle:`border-gray-200 bg-gray-50 text-gray-600`,neutral:`border-gray-200 bg-white text-gray-600`,success:`border-emerald-200 bg-emerald-50 text-emerald-700`,warning:`border-amber-200 bg-amber-50 text-amber-800`,danger:`border-rose-200 bg-rose-50 text-rose-600`,info:`border-primary/20 bg-primary/10 text-primary`}},defaultVariants:{tone:`subtle`}}),c=a.forwardRef(({className:e,tone:t,...n},i)=>(0,o.jsx)(`span`,{ref:i,className:r(s({tone:t}),e),...n}));c.displayName=`TagChip`;export{c as t};
1
+ import{i as e}from"./chunk-DF37yw5_.js";import{A as t,M as n,t as r}from"./utils-CBZPzC_b.js";import{Zt as i}from"./api-DqzQ-_3w.js";var a=e(n(),1),o=t(),s=i(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium`,{variants:{tone:{subtle:`border-gray-200 bg-gray-50 text-gray-600`,neutral:`border-gray-200 bg-white text-gray-600`,success:`border-emerald-200 bg-emerald-50 text-emerald-700`,warning:`border-amber-200 bg-amber-50 text-amber-800`,danger:`border-rose-200 bg-rose-50 text-rose-600`,info:`border-primary/20 bg-primary/10 text-primary`}},defaultVariants:{tone:`subtle`}}),c=a.forwardRef(({className:e,tone:t,...n},i)=>(0,o.jsx)(`span`,{ref:i,className:r(s({tone:t}),e),...n}));c.displayName=`TagChip`;export{c as t};