@xopcai/xopc 0.0.85 → 0.0.86

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 (60) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/telegram/xopc.extension.json +1 -1
  3. package/dist/gateway/static/root/assets/{agents-D3_-kNlZ.js → agents-mS3_HpRI.js} +10 -10
  4. package/dist/gateway/static/root/assets/{apps-page-D7v7649T.js → apps-page-DrfytjOb.js} +1 -1
  5. package/dist/gateway/static/root/assets/{channels-settings-nCaMb0a7.js → channels-settings-BG6b9KrW.js} +1 -1
  6. package/dist/gateway/static/root/assets/{channels-status-swr-C1gZBcJV.js → channels-status-swr-Bs5kMCMI.js} +1 -1
  7. package/dist/gateway/static/root/assets/{cron-api-CoYK0hlm.js → cron-api-BuVcZ5zR.js} +1 -1
  8. package/dist/gateway/static/root/assets/{cron-page-DeGo-Vjc.js → cron-page-BMrloeFH.js} +1 -1
  9. package/dist/gateway/static/root/assets/{dist-DaK4dsss.js → dist-CKU1OOTf.js} +1 -1
  10. package/dist/gateway/static/root/assets/{extension-debug-page-BZngZWbO.js → extension-debug-page-BdW_46sN.js} +1 -1
  11. package/dist/gateway/static/root/assets/{extension-page-D6JSyV27.js → extension-page-DW47KI82.js} +1 -1
  12. package/dist/gateway/static/root/assets/extension-settings-page-B-W4x2xP.js +1 -0
  13. package/dist/gateway/static/root/assets/{field-primitives-Zzl22MvN.js → field-primitives-DPG-oJmx.js} +1 -1
  14. package/dist/gateway/static/root/assets/{heartbeat-config-api-BtIcpG0O.js → heartbeat-config-api-C8dNts9i.js} +1 -1
  15. package/dist/gateway/static/root/assets/{index-D4vM3-P7.js → index-BmVYculr.js} +20 -20
  16. package/dist/gateway/static/root/assets/{logs-page-_d4UJ-qQ.js → logs-page-sTsVWz0X.js} +1 -1
  17. package/dist/gateway/static/root/assets/{sessions-page-5N4aF2Wk.js → sessions-page-FaG_Vlkb.js} +1 -1
  18. package/dist/gateway/static/root/assets/settings-form-section-DuvRQW--.js +1 -0
  19. package/dist/gateway/static/root/assets/settings-page-Bet1OerL.js +3 -0
  20. package/dist/gateway/static/root/assets/{share-preview-page-D4EG_vM1.js → share-preview-page-BtG2kLDh.js} +1 -1
  21. package/dist/gateway/static/root/assets/{skills-page-sPAXhh8w.js → skills-page-DhUO235y.js} +1 -1
  22. package/dist/gateway/static/root/assets/{utils-CYO9eTCM.js → utils-BY7bU1DT.js} +1 -1
  23. package/dist/gateway/static/root/assets/{voice-api-key-field-Ds51havm.js → voice-api-key-field-CGEydndO.js} +1 -1
  24. package/dist/gateway/static/root/index.html +1 -1
  25. package/dist/package.js +1 -1
  26. package/dist/src/agent/tools/workflow-tool.js +3 -3
  27. package/dist/src/agent/tools/workflow-tool.js.map +1 -1
  28. package/dist/src/agent/workflow/builtins/audit-repo.d.ts +5 -1
  29. package/dist/src/agent/workflow/builtins/audit-repo.js +52 -11
  30. package/dist/src/agent/workflow/builtins/audit-repo.js.map +1 -1
  31. package/dist/src/agent/workflow/builtins/debug-incident.d.ts +13 -0
  32. package/dist/src/agent/workflow/builtins/debug-incident.js +155 -0
  33. package/dist/src/agent/workflow/builtins/debug-incident.js.map +1 -0
  34. package/dist/src/agent/workflow/builtins/index.d.ts +3 -1
  35. package/dist/src/agent/workflow/builtins/index.js +11 -1
  36. package/dist/src/agent/workflow/builtins/index.js.map +1 -1
  37. package/dist/src/agent/workflow/builtins/multi-perspective-review.d.ts +6 -1
  38. package/dist/src/agent/workflow/builtins/multi-perspective-review.js +66 -30
  39. package/dist/src/agent/workflow/builtins/multi-perspective-review.js.map +1 -1
  40. package/dist/src/agent/workflow/builtins/pr-review.d.ts +12 -0
  41. package/dist/src/agent/workflow/builtins/pr-review.js +156 -0
  42. package/dist/src/agent/workflow/builtins/pr-review.js.map +1 -0
  43. package/dist/src/agent/workflow/builtins/research.d.ts +5 -1
  44. package/dist/src/agent/workflow/builtins/research.js +37 -6
  45. package/dist/src/agent/workflow/builtins/research.js.map +1 -1
  46. package/dist/src/agent/workflow/catalog.d.ts +5 -0
  47. package/dist/src/agent/workflow/catalog.js +6 -2
  48. package/dist/src/agent/workflow/catalog.js.map +1 -1
  49. package/dist/src/agent/workflow/index.d.ts +1 -1
  50. package/dist/src/agent/workflow/parser.js +9 -0
  51. package/dist/src/agent/workflow/parser.js.map +1 -1
  52. package/dist/src/agent/workflow/types.d.ts +8 -0
  53. package/dist/src/chat-commands/builtins/workflow.js +7 -2
  54. package/dist/src/chat-commands/builtins/workflow.js.map +1 -1
  55. package/dist/src/gateway/heartbeat/service.js +1 -1
  56. package/dist/src/heartbeat/index.js +1 -1
  57. package/package.json +1 -1
  58. package/dist/gateway/static/root/assets/extension-settings-page-8PZcmWI7.js +0 -1
  59. package/dist/gateway/static/root/assets/settings-form-section-D_tgb8r2.js +0 -1
  60. package/dist/gateway/static/root/assets/settings-page-C18xBt4X.js +0 -3
@@ -0,0 +1,3 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{a as i,i as a,n as o,o as s,r as c,t as l}from"./url-BwNL6Rgk.js";import{a as u,i as d,o as f}from"./vendor-swr-BIWyz7Rc.js";import{a as p,i as m,n as h,o as g,r as _,s as v,t as y}from"./dist-BTWC-BTN.js";import{i as b}from"./theme-store-DryYl3qD.js";import{a as x,n as S,t as C}from"./fetch-B2MYHbWg.js";import{$n as w,$r as T,A as E,Ai as D,An as O,Ar as k,At as A,Br as j,C as M,Ci as N,Cr as P,Ct as F,D as I,Dr as L,Dt as R,E as z,Er as B,Et as V,Fi as H,Fr as U,Ft as W,Gi as G,Gn as ee,Gt as K,H as te,Hr as ne,Ir as re,It as ie,Ji as ae,Jr as oe,Kn as se,Kt as ce,Li as le,Lr as ue,M as de,Mn as fe,Mr as pe,Mt as me,Nn as he,Nt as ge,O as _e,On as ve,Ot as ye,Pi as be,Pn as xe,Pt as Se,Qi as Ce,Qn as we,Qr as Te,Rr as Ee,Rt as De,S as Oe,Sr as ke,St as Ae,T as je,Ti as Me,Tt as Ne,Ui as Pe,Ur as Fe,Vi as Ie,Vn as Le,Vr as Re,Wi as ze,Wn as Be,Wt as Ve,Xn as He,Xr as Ue,Yi as We,Yn as Ge,Yr as Ke,Zi as qe,Zn as Je,_ as Ye,_i as Xe,_n as Ze,_r as Qe,_t as $e,a as et,aa as tt,ar as nt,b as rt,bi as it,bt as at,da as ot,dt as st,ea as ct,er as lt,fr as ut,ft as dt,g as ft,gi as pt,gn as mt,gr as ht,gt,h as _t,hi as vt,hr as yt,ht as bt,ii as q,ir as xt,j as St,jn as Ct,jr as wt,jt as Tt,k as Et,ki as Dt,kn as Ot,kt,mi as At,mt as jt,ni as Mt,nr as J,nt as Nt,o as Pt,oa as Ft,pi as It,pr as Lt,pt as Rt,qi as zt,qn as Bt,qr as Vt,r as Ht,ri as Ut,rr as Wt,s as Gt,sa as Kt,sr as qt,t as Jt,ti as Yt,tr as Y,u as Xt,ua as Zt,vt as Qt,w as $t,wi as en,wn as tn,wr as nn,wt as rn,x as an,xi as on,xt as sn,yt as cn,zt as X}from"./index-BmVYculr.js";import{a as ln,c as un,d as dn,l as fn,n as pn,o as mn,r as hn,s as gn,t as _n,u as vn}from"./voice-api-key-field-CGEydndO.js";import{a as yn,i as bn,r as xn}from"./utils-BY7bU1DT.js";import{n as Sn,r as Cn,t as wn}from"./settings-form-section-DuvRQW--.js";import{c as Tn,f as En,r as Dn}from"./cron-dreaming-jobs-DueM3rBz.js";import{l as On}from"./cron-api-BuVcZ5zR.js";import{a as kn,c as An,i as jn,l as Mn,n as Nn,o as Pn,r as Fn,s as In,t as Ln}from"./agents-mS3_HpRI.js";import{m as Rn,n as zn,r as Bn,t as Vn}from"./channels-status-swr-Bs5kMCMI.js";import{a as Hn,i as Un,n as Wn,o as Gn,r as Kn,s as qn,t as Jn}from"./heartbeat-config-api-C8dNts9i.js";var Z=e(t(),1),Q=n(),Yn=[{id:`lightChat`,steps:[{path:`/settings/credentials`,labelKey:`stepProviders`},{path:`/settings/agent-defaults?tab=chat`,labelKey:`stepDefaultModel`}]},{id:`multiChannel`,steps:[{path:`/settings/credentials`,labelKey:`stepProviders`},{path:`/settings/agent-defaults?tab=chat`,labelKey:`stepDefaultModel`},{path:`/channels`,labelKey:`stepChannel`},{path:`/agents`,labelKey:`stepPresets`}]},{id:`automation`,steps:[{path:`/settings/credentials`,labelKey:`stepProviders`},{path:`/skills`,labelKey:`stepSkills`},{path:`/cron`,labelKey:`stepCron`}]}],Xn=`xopc-scenario-presets-dismissed`;function Zn(){try{return localStorage.getItem(Xn)===`true`}catch{return!1}}function Qn(){try{localStorage.setItem(Xn,`true`)}catch{}}var $=r();function $n(e,t){return t[e.labelKey]??e.labelKey}function er(){let e=(0,Q.c)(5),t=s(a(tr)).setupStatus.scenarios,[n,r]=(0,Z.useState)(Zn);if(n)return null;let i,o,c;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=J(`inline-flex shrink-0 items-center gap-1 rounded-lg px-2 py-1.5 text-xs font-medium text-fg-muted`,`hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press),o=()=>{Qn(),r(!0)},c=(0,$.jsx)(xt,{className:`size-3.5`,"aria-hidden":!0}),e[0]=i,e[1]=o,e[2]=c):(i=e[0],o=e[1],c=e[2]);let l=Yn.map(e=>{let n=t.presets[e.id];return(0,$.jsxs)(`article`,{className:`flex flex-col rounded-xl border border-edge-subtle bg-surface-panel p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.title}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:n.description}),(0,$.jsx)(`ol`,{className:`mt-3 flex flex-col gap-1`,children:e.steps.map((n,r)=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(Ft,{to:n.path,className:J(`text-xs font-medium text-accent-fg hover:underline`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent rounded`),children:[r+1,`. `,$n(n,t.steps)]})},`${e.id}-${n.labelKey}`))})]},e.id)}),u;return e[3]===l?u=e[4]:(u=(0,$.jsx)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-3`,children:l}),e[3]=l,e[4]=u),(0,$.jsxs)(wn,{children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsx)(Sn,{icon:ke,title:t.title,subtitle:t.subtitle}),(0,$.jsxs)(`button`,{type:`button`,className:i,onClick:o,children:[c,t.dismiss]})]}),u]})}function tr(e){return e.language}function nr(e){if(!e||typeof e!=`object`)return 0;let t=e.providers;return!t||typeof t!=`object`||Array.isArray(t)?0:Object.values(t).filter(e=>e===`***`).length}function rr(e){if(!e||typeof e!=`object`)return``;let t=e.agents;if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=t.defaults;if(!n||typeof n!=`object`||Array.isArray(n))return``;let r=n.model;return typeof r==`string`?r.trim():``}function ir(e){let t=Rn(e);return t.telegram.enabled&&bn(t.telegram)||t.weixin.enabled&&yn(t.weixin)||t.feishu.enabled&&xn(t.feishu)||bn(t.telegram)||yn(t.weixin)||xn(t.feishu)}function ar(e){let t=nr(e.config),n=e.providerMeta?.configured??t,r=e.providerMeta?.total??0,i=n>0||t>0,a=rr(e.config),o=a.length>0,s=e.hasToken&&e.sseConnected,c=ir(e.config),l=e.skillCount>0,u=[{id:`gateway`,done:s,detail:s?e.labels.gatewayOnline:e.labels.gatewayOffline},{id:`provider`,done:i,detail:i?e.providerMeta&&e.providerMeta.total>0?e.labels.providersMetaReady(n,r):e.labels.providersConfigured(t):e.labels.providersMissing},{id:`defaultModel`,done:o,detail:o?e.labels.modelConfigured(a):e.labels.modelMissing},{id:`channel`,done:c,optional:!0,detail:c?e.labels.channelConfigured:e.labels.channelMissing},{id:`skill`,done:l,optional:!0,detail:l?e.labels.skillsConfigured(e.skillCount):e.labels.skillsMissing},{id:`presets`,done:e.presetsDone,optional:!0,detail:e.presetsDone?e.labels.presetsConfigured:e.labels.presetsMissing}],d=u.filter(e=>!e.optional).every(e=>e.done),f=u.every(e=>e.done);return{gatewayConnected:s,providerConfigured:i,providerCount:t,providerMetaConfigured:n,providerMetaTotal:r,defaultModel:a,defaultModelConfigured:o,channelConfigured:c,skillInstalled:l,skillCount:e.skillCount,presetsDone:e.presetsDone,agentCount:e.agentCount,checklist:u,requiredComplete:d,allComplete:f}}function or(){try{return localStorage.getItem(An)===`true`}catch{return!1}}function sr(e,t){return or()?!0:!e||e.length===0?!1:!(e.length<=1&&e.every(e=>e.id===t))}function cr(){let e=(0,Q.c)(50),t=x(fr),n=a(dr),r;e[0]===n?r=e[1]:(r=s(n),e[0]=n,e[1]=r);let i=r.setupStatus.labels,o=de(ur),{data:c,error:l,isLoading:u,mutate:f}=Ze(!!t),p;e[2]!==n||e[3]!==t?(p=t?[`setup-checklist-skills`,n]:null,e[2]=n,e[3]=t,e[4]=p):p=e[4];let m;e[5]===n?m=e[6]:(m=()=>Nt(n),e[5]=n,e[6]=m);let h;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(h={revalidateOnFocus:!1},e[7]=h):h=e[7];let{data:g,error:_,isLoading:v,mutate:y}=d(p,m,h),b;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(b={revalidateOnFocus:!1},e[8]=b):b=e[8];let{data:S,error:C,isLoading:w,mutate:T}=d(t?`setup-checklist-provider-meta`:null,an,b),D;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(D={revalidateOnFocus:!1},e[9]=D):D=e[9];let{data:O,error:k,isLoading:A,mutate:j}=d(t?`setup-checklist-agents`:null,te,D),M;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(M={revalidateOnFocus:!1},e[10]=M):M=e[10],d(t?E:null,St,M);let N=!t||!u&&!v&&!w&&!A,P=!!(l||_||C||k),F;bb0:{if(!t||!N){F=null;break bb0}let n=g?.catalog?.length??0,r;if(e[11]!==O?.agents||e[12]!==O?.defaultId||e[13]!==c?.payload?.config||e[14]!==i.channelConfigured||e[15]!==i.channelMissing||e[16]!==i.gatewayOffline||e[17]!==i.gatewayOnline||e[18]!==i.modelConfigured||e[19]!==i.modelMissing||e[20]!==i.presetsConfigured||e[21]!==i.presetsMissing||e[22]!==i.providersConfigured||e[23]!==i.providersMetaReady||e[24]!==i.providersMissing||e[25]!==i.skillsConfigured||e[26]!==i.skillsMissing||e[27]!==S||e[28]!==n||e[29]!==o||e[30]!==t){let a=S?.filter(lr).length??0,s=S?.length??0,l=O?.agents.length??0,u=sr(O?.agents,O?.defaultId),d;e[32]===i.providersConfigured?d=e[33]:(d=e=>i.providersConfigured.replace(`{{count}}`,String(e)),e[32]=i.providersConfigured,e[33]=d);let f;e[34]===i.providersMetaReady?f=e[35]:(f=(e,t)=>i.providersMetaReady.replace(`{{configured}}`,String(e)).replace(`{{total}}`,String(t)),e[34]=i.providersMetaReady,e[35]=f);let p;e[36]===i.modelConfigured?p=e[37]:(p=e=>i.modelConfigured.replace(`{{model}}`,e),e[36]=i.modelConfigured,e[37]=p);let m;e[38]===i.skillsConfigured?m=e[39]:(m=e=>i.skillsConfigured.replace(`{{count}}`,String(e)),e[38]=i.skillsConfigured,e[39]=m),r=ar({hasToken:!!t,sseConnected:o,config:c?.payload?.config,skillCount:n,providerMeta:s>0?{configured:a,total:s}:null,presetsDone:u,agentCount:l,labels:{gatewayOnline:i.gatewayOnline,gatewayOffline:i.gatewayOffline,providersConfigured:d,providersMetaReady:f,providersMissing:i.providersMissing,modelConfigured:p,modelMissing:i.modelMissing,channelConfigured:i.channelConfigured,channelMissing:i.channelMissing,skillsConfigured:m,skillsMissing:i.skillsMissing,presetsConfigured:i.presetsConfigured.replace(`{{count}}`,String(l)),presetsMissing:i.presetsMissing}}),e[11]=O?.agents,e[12]=O?.defaultId,e[13]=c?.payload?.config,e[14]=i.channelConfigured,e[15]=i.channelMissing,e[16]=i.gatewayOffline,e[17]=i.gatewayOnline,e[18]=i.modelConfigured,e[19]=i.modelMissing,e[20]=i.presetsConfigured,e[21]=i.presetsMissing,e[22]=i.providersConfigured,e[23]=i.providersMetaReady,e[24]=i.providersMissing,e[25]=i.skillsConfigured,e[26]=i.skillsMissing,e[27]=S,e[28]=n,e[29]=o,e[30]=t,e[31]=r}else r=e[31];F=r}let I=F,L;e[40]!==j||e[41]!==f||e[42]!==T||e[43]!==y?(L=async()=>{await Promise.all([f(),y(),T(),j()])},e[40]=j,e[41]=f,e[42]=T,e[43]=y,e[44]=L):L=e[44];let R=L,z;return e[45]!==P||e[46]!==N||e[47]!==R||e[48]!==I?(z={ready:N,error:P,snapshot:I,refresh:R},e[45]=P,e[46]=N,e[47]=R,e[48]=I,e[49]=z):z=e[49],z}function lr(e){return e.configured}function ur(e){return e.connectionState===`connected`}function dr(e){return e.language}function fr(e){return e.token}var pr={gateway:`/settings/gateway`,provider:`/settings/credentials`,defaultModel:`/settings/agent-defaults?tab=chat`,channel:`/channels`,skill:`/skills`,presets:`/agents`};function mr(e){let t=(0,Q.c)(5),{ok:n,label:r}=e,i=n?`bg-success-soft text-success`:`bg-surface-hover text-fg-muted`,a;t[0]===i?a=t[1]:(a=J(`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium`,i),t[0]=i,t[1]=a);let o;return t[2]!==r||t[3]!==a?(o=(0,$.jsx)(`span`,{className:a,children:r}),t[2]=r,t[3]=a,t[4]=o):o=t[4],o}function hr(){let e=(0,Q.c)(7),t=s(a(gr)).setupStatus,{ready:n,error:r,snapshot:i,refresh:o}=cr(),c;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`inline-flex shrink-0 items-center gap-2 rounded-lg border border-edge px-3 py-2 text-sm font-medium text-fg`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press),e[0]=c):c=e[0];let l;e[1]===o?l=e[2]:(l=()=>void o(),e[1]=o,e[2]=l);let u=!n&&`animate-spin`,d;e[3]===u?d=e[4]:(d=J(`size-4`,u),e[3]=u,e[4]=d);let f;return e[5]===d?f=e[6]:(f=(0,$.jsx)(Ee,{className:d,"aria-hidden":!0}),e[5]=d,e[6]=f),(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.subtitle})]}),(0,$.jsxs)(`button`,{type:`button`,className:c,onClick:l,disabled:!n,children:[f,t.refresh]})]}),r?(0,$.jsx)(`p`,{className:`rounded-xl border border-red-300/40 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/30 dark:text-red-300`,children:t.loadError}):null,!n||!i?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,"aria-busy":!0,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}),t.loading]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:ae,title:t.summaryTitle,subtitle:t.summarySubtitle}),(0,$.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-3`,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.summaryGateway}),(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(mr,{ok:i.gatewayConnected,label:i.gatewayConnected?t.statusOnline:t.statusOffline})})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.summaryProviders}),(0,$.jsx)(`p`,{className:`mt-2 truncate text-sm font-medium text-fg`,children:i.providerConfigured?i.providerMetaTotal>0?t.labels.providersMetaReady.replace(`{{configured}}`,String(i.providerMetaConfigured)).replace(`{{total}}`,String(i.providerMetaTotal)):t.labels.providersConfigured.replace(`{{count}}`,String(i.providerCount)):t.labels.providersMissing})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.summaryModel}),(0,$.jsx)(`p`,{className:`mt-2 truncate text-sm font-medium text-fg`,children:i.defaultModelConfigured?i.defaultModel:t.labels.modelMissing})]})]}),i.requiredComplete?(0,$.jsx)(`p`,{className:`mt-4 text-sm text-success`,children:t.requiredCompleteMessage}):(0,$.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.requiredIncompleteMessage})]}),(0,$.jsx)(er,{}),(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:le,title:t.checklistTitle,subtitle:t.checklistSubtitle}),(0,$.jsx)(`ul`,{className:`mt-4 flex flex-col gap-1`,children:i.checklist.map(e=>{let n=t.items[e.id];return(0,$.jsx)(`li`,{children:(0,$.jsxs)(Ft,{to:pr[e.id],className:J(`flex items-center gap-3 rounded-xl px-3 py-3 transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:[(0,$.jsx)(`span`,{className:J(`flex size-6 shrink-0 items-center justify-center rounded-full border`,e.done?`border-success/40 bg-success-soft text-success`:`border-edge bg-surface-panel text-fg-subtle`),"aria-hidden":!0,children:e.done?(0,$.jsx)(ae,{className:`size-3.5`,strokeWidth:2.5}):null}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.title}),e.optional?(0,$.jsx)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:t.optionalBadge}):null]}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-muted`,children:n.description}),e.detail?(0,$.jsx)(`span`,{className:`mt-1 block truncate text-xs text-fg-subtle`,children:e.detail}):null]}),(0,$.jsx)(G,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]})},e.id)})})]})]})]})}function gr(e){return e.language}function _r(e,t){let n=!1,r=0,i=t;for(let t of e.values())t.dirty&&(n=!0,r+=1),t.saving&&(i=!0);return{anyDirty:n,dirtyCount:r,anySaving:i}}var vr=i((e,t)=>({sections:new Map,saveAllInFlight:!1,anyDirty:!1,dirtyCount:0,anySaving:!1,registerSection:t=>{e(e=>{let n=new Map(e.sections);return n.set(t.id,t),{sections:n,..._r(n,e.saveAllInFlight)}})},unregisterSection:t=>{e(e=>{if(!e.sections.has(t))return e;let n=new Map(e.sections);return n.delete(t),{sections:n,..._r(n,e.saveAllInFlight)}})},saveAll:async()=>{let n=Array.from(t().sections.values()).filter(e=>e.dirty);if(n.length===0)return{ok:!0,saved:0,failures:[]};e(e=>({saveAllInFlight:!0,..._r(e.sections,!0)}));let r=[],i=0;try{let e=await Promise.all(n.map(async e=>{try{let t=await e.save();return{id:e.id,result:t}}catch(t){return{id:e.id,result:{ok:!1,error:t instanceof Error?t.message:String(t)}}}}));for(let{id:t,result:n}of e)n.ok?i+=1:r.push({id:t,error:n.error??`Save failed`})}finally{e(e=>({saveAllInFlight:!1,..._r(e.sections,!1)}))}return{ok:r.length===0,saved:i,failures:r}},discardAll:()=>{for(let e of t().sections.values())e.dirty&&e.discard()}}));function yr({id:e,dirty:t,saving:n,save:r,discard:i}){let a=(0,Z.useRef)(r),o=(0,Z.useRef)(i);a.current=r,o.current=i;let s=vr(e=>e.registerSection),c=vr(e=>e.unregisterSection);(0,Z.useEffect)(()=>(s({id:e,dirty:t,saving:n,save:async()=>{try{return await a.current(),{ok:!0}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},discard:()=>o.current()}),()=>c(e)),[e,t,n,s,c])}function br(e){let t=(0,Q.c)(24),{showLabel:n,hideLabel:r,icon:i,hint:a,children:o,className:s,defaultOpen:c}=e,[l,u]=(0,Z.useState)(c??!1),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>u(e.currentTarget.open),t[0]=d):d=t[0];let f;t[1]===s?f=t[2]:(f=J(`group rounded-2xl bg-surface-base open:pb-1`,s),t[1]=s,t[2]=f);let p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(zt,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[3]=p):p=t[3];let m;t[4]===i?m=t[5]:(m=i?(0,$.jsx)(i,{className:`size-4 shrink-0 text-accent`,strokeWidth:1.75,"aria-hidden":!0}):null,t[4]=i,t[5]=m);let h;t[6]===n?h=t[7]:(h=(0,$.jsx)(`span`,{className:`group-open:hidden`,children:n}),t[6]=n,t[7]=h);let g;t[8]===r?g=t[9]:(g=(0,$.jsx)(`span`,{className:`hidden group-open:inline`,children:r}),t[8]=r,t[9]=g);let _;t[10]!==m||t[11]!==h||t[12]!==g?(_=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 rounded-2xl px-4 py-3.5 text-sm font-medium text-fg transition-colors hover:text-fg group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:[p,m,h,g]}),t[10]=m,t[11]=h,t[12]=g,t[13]=_):_=t[13];let v;t[14]===a?v=t[15]:(v=a?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:a}):null,t[14]=a,t[15]=v);let y;t[16]!==o||t[17]!==v?(y=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4 pt-1`,children:[v,o]}),t[16]=o,t[17]=v,t[18]=y):y=t[18];let b;return t[19]!==l||t[20]!==f||t[21]!==_||t[22]!==y?(b=(0,$.jsxs)(`details`,{open:l,onToggle:d,className:f,children:[_,y]}),t[19]=l,t[20]=f,t[21]=_,t[22]=y,t[23]=b):b=t[23],b}async function xr(){let e=await C(l(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function Sr(e){let t=new Set,n=[];for(let r of e){let e=r.models.length>0?r.models:r.defaultModel?[r.defaultModel]:[];for(let i of e){let e=`${r.id}/${i}`;t.has(e)||(t.add(e),n.push(e))}}return n}function Cr(e,t){let n=Sr(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function wr(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=n.split(/[/\s]+/).filter(Boolean);return e.filter(e=>{let t=e.toLowerCase();return r.every(e=>t.includes(e))})}var Tr=`image-generation-providers`;function Er(e){let t=(0,Q.c)(80),{value:n,disabled:r,placeholder:i,searchPlaceholder:a,noMatches:o,registryEmptyHint:s,outOfFilterNote:c,className:l,onChange:u}=e,[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(``),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g={revalidateOnFocus:!1},t[0]=g):g=t[0];let{data:_,isLoading:v,error:y}=d(Tr,xr,g),b;t[1]===n?b=t[2]:(b=n.trim(),t[1]=n,t[2]=b);let x=b,S;t[3]===_?S=t[4]:(S=Sr((_??[]).filter(kr)),t[3]=_,t[4]=S);let C=S,w;t[5]===_?w=t[6]:(w=_??[],t[5]=_,t[6]=w);let T;t[7]!==w||t[8]!==x?(T=Cr(w,x),t[7]=w,t[8]=x,t[9]=T):T=t[9];let E=T,D;t[10]!==E||t[11]!==m?(D=wr(E,m),t[10]=E,t[11]=m,t[12]=D):D=t[12];let O=D,k;t[13]!==C||t[14]!==c||t[15]!==x?(k=!!c&&!!x&&!C.includes(x),t[13]=C,t[14]=c,t[15]=x,t[16]=k):k=t[16];let A=k,j;t[17]!==i||t[18]!==n?(j=n.trim()?n:i,t[17]=i,t[18]=n,t[19]=j):j=t[19];let M=j,N;t[20]!==i||t[21]!==n?(N=n.trim()||i,t[20]=i,t[21]=n,t[22]=N):N=t[22];let P=N,F;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>{p(e),e||h(``)},t[23]=F):F=t[23];let I=F,L=r||v,R=v?`…`:P,z;t[24]===l?z=t[25]:(z=J(Ge,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-left text-sm font-normal text-fg`,X.transition,X.press,`hover:border-edge hover:bg-surface-hover/45`,we,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,l),t[24]=l,t[25]=z);let B=v?`…`:M,V;t[26]===B?V=t[27]:(V=(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:B}),t[26]=B,t[27]=V);let H;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(ze,{className:`size-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0}),t[28]=H):H=t[28];let U;t[29]!==f||t[30]!==L||t[31]!==R||t[32]!==z||t[33]!==V?(U=(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,disabled:L,title:R,className:z,"aria-haspopup":`listbox`,"aria-expanded":f,children:[V,H]})}),t[29]=f,t[30]=L,t[31]=R,t[32]=z,t[33]=V,t[34]=U):U=t[34];let W;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(W=J(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,Ye),t[35]=W):W=t[35];let G;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(G=J(`mb-1 w-full rounded-lg border border-edge-subtle bg-surface-base px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-disabled dark:bg-surface-hover/40`,He),t[36]=G):G=t[36];let ee;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ee=e=>h(e.target.value),t[37]=ee):ee=t[37];let K;t[38]!==m||t[39]!==a?(K=(0,$.jsx)(`input`,{type:`search`,className:G,placeholder:a,value:m,onChange:ee,onKeyDown:Dr}),t[38]=m,t[39]=a,t[40]=K):K=t[40];let te;t[41]===y?te=t[42]:(te=y?(0,$.jsx)(`div`,{className:`p-2 text-xs text-red-600 dark:text-red-400`,children:y instanceof Error?y.message:`Failed to load image providers`}):null,t[41]=y,t[42]=te);let ne;t[43]!==E||t[44]!==y||t[45]!==v||t[46]!==o||t[47]!==s?(ne=!y&&E.length===0&&!v?(0,$.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:s??o}):null,t[43]=E,t[44]=y,t[45]=v,t[46]=o,t[47]=s,t[48]=ne):ne=t[48];let re;t[49]!==E||t[50]!==y||t[51]!==O.length||t[52]!==o?(re=!y&&E.length>0&&O.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,t[49]=E,t[50]=y,t[51]=O.length,t[52]=o,t[53]=re):re=t[53];let ie;if(t[54]!==O||t[55]!==u||t[56]!==n){let e;t[58]!==u||t[59]!==n?(e=e=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":e===n,className:J(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,X.press,e===n&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{u(e),p(!1),h(``)},children:[(0,$.jsx)(ae,{className:J(`size-4 shrink-0`,e!==n&&`invisible`),"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e})]},e),t[58]=u,t[59]=n,t[60]=e):e=t[60],ie=O.map(e),t[54]=O,t[55]=u,t[56]=n,t[57]=ie}else ie=t[57];let oe;t[61]!==a||t[62]!==te||t[63]!==ne||t[64]!==re||t[65]!==ie?(oe=(0,$.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":a,children:[te,ne,re,ie]}),t[61]=a,t[62]=te,t[63]=ne,t[64]=re,t[65]=ie,t[66]=oe):oe=t[66];let se;t[67]!==K||t[68]!==oe?(se=(0,$.jsx)(fe,{children:(0,$.jsxs)(Ct,{className:W,side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:Or,children:[K,oe]})}),t[67]=K,t[68]=oe,t[69]=se):se=t[69];let ce;t[70]!==f||t[71]!==U||t[72]!==se?(ce=(0,$.jsxs)(he,{open:f,onOpenChange:I,modal:!1,children:[U,se]}),t[70]=f,t[71]=U,t[72]=se,t[73]=ce):ce=t[73];let le;t[74]!==c||t[75]!==A?(le=A?(0,$.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:c}):null,t[74]=c,t[75]=A,t[76]=le):le=t[76];let ue;return t[77]!==ce||t[78]!==le?(ue=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[ce,le]}),t[77]=ce,t[78]=le,t[79]=ue):ue=t[79],ue}function Dr(e){return e.stopPropagation()}function Or(e){return e.preventDefault()}function kr(e){return e.configured===!0}function Ar(e,t,n){let r=e.trim();return r?`model:${r}`:`empty:${n.slice(0,t).filter(e=>!e.trim()).length}`}function jr(e){let t=(0,Q.c)(37),{a:n,chat:r,form:i,update:a}=e,o;t[0]!==n.cardModelsSubtitle||t[1]!==n.cardModelsTitle?(o=(0,$.jsx)(Sn,{icon:vt,title:n.cardModelsTitle,subtitle:n.cardModelsSubtitle}),t[0]=n.cardModelsSubtitle,t[1]=n.cardModelsTitle,t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=e=>a({imageModel:e}),t[3]=a,t[4]=s);let c;t[5]!==n.visionOutOfFilterNote||t[6]!==n.visionRegistryEmpty||t[7]!==r.modelNoMatches||t[8]!==r.modelPlaceholder||t[9]!==r.modelSearchPlaceholder||t[10]!==i.imageModel||t[11]!==s?(c=(0,$.jsx)(Xt,{value:i.imageModel,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:n.visionRegistryEmpty,outOfFilterNote:n.visionOutOfFilterNote,onChange:s}),t[5]=n.visionOutOfFilterNote,t[6]=n.visionRegistryEmpty,t[7]=r.modelNoMatches,t[8]=r.modelPlaceholder,t[9]=r.modelSearchPlaceholder,t[10]=i.imageModel,t[11]=s,t[12]=c):c=t[12];let l;t[13]!==n.desc.imageModel||t[14]!==n.label.imageModel||t[15]!==c?(l=(0,$.jsx)(jn,{label:n.label.imageModel,description:n.desc.imageModel,children:c}),t[13]=n.desc.imageModel,t[14]=n.label.imageModel,t[15]=c,t[16]=l):l=t[16];let u;t[17]===a?u=t[18]:(u=e=>a({imageGenerationModel:e}),t[17]=a,t[18]=u);let d;t[19]!==n.imageGenOutOfFilterNote||t[20]!==n.imageGenRegistryEmpty||t[21]!==r.modelNoMatches||t[22]!==r.modelPlaceholder||t[23]!==r.modelSearchPlaceholder||t[24]!==i.imageGenerationModel||t[25]!==u?(d=(0,$.jsx)(Er,{value:i.imageGenerationModel,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,registryEmptyHint:n.imageGenRegistryEmpty,outOfFilterNote:n.imageGenOutOfFilterNote,onChange:u}),t[19]=n.imageGenOutOfFilterNote,t[20]=n.imageGenRegistryEmpty,t[21]=r.modelNoMatches,t[22]=r.modelPlaceholder,t[23]=r.modelSearchPlaceholder,t[24]=i.imageGenerationModel,t[25]=u,t[26]=d):d=t[26];let f;t[27]!==n.desc.imageGenerationModel||t[28]!==n.label.imageGenerationModel||t[29]!==d?(f=(0,$.jsx)(jn,{label:n.label.imageGenerationModel,description:n.desc.imageGenerationModel,children:d}),t[27]=n.desc.imageGenerationModel,t[28]=n.label.imageGenerationModel,t[29]=d,t[30]=f):f=t[30];let p;t[31]!==l||t[32]!==f?(p=(0,$.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[l,f]}),t[31]=l,t[32]=f,t[33]=p):p=t[33];let m;return t[34]!==o||t[35]!==p?(m=(0,$.jsxs)(wn,{children:[o,p]}),t[34]=o,t[35]=p,t[36]=m):m=t[36],m}function Mr(e){let t=(0,Q.c)(45),{a:n,chat:r,form:i,update:a}=e,o=n.label.imageModelFallbacks,s=n.desc.imageModelFallbacks,c;t[0]!==n.removeModelFallback||t[1]!==n.visionOutOfFilterNote||t[2]!==n.visionRegistryEmpty||t[3]!==r||t[4]!==i.imageModelFallbacks||t[5]!==a?(c=i.imageModelFallbacks.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(Xt,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:n.visionRegistryEmpty,outOfFilterNote:n.visionOutOfFilterNote,onChange:e=>{let n=[...i.imageModelFallbacks];n[t]=e,a({imageModelFallbacks:n})}})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({imageModelFallbacks:i.imageModelFallbacks.filter((e,n)=>n!==t)}),children:(0,$.jsx)(Lt,{className:`size-4`,strokeWidth:1.75})})]},Ar(e,t,i.imageModelFallbacks))),t[0]=n.removeModelFallback,t[1]=n.visionOutOfFilterNote,t[2]=n.visionRegistryEmpty,t[3]=r,t[4]=i.imageModelFallbacks,t[5]=a,t[6]=c):c=t[6];let l;t[7]!==i.imageModelFallbacks||t[8]!==a?(l=()=>a({imageModelFallbacks:[...i.imageModelFallbacks,``]}),t[7]=i.imageModelFallbacks,t[8]=a,t[9]=l):l=t[9];let u;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Re,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[10]=u):u=t[10];let d;t[11]!==n.addModelFallback||t[12]!==l?(d=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:l,children:[u,n.addModelFallback]}),t[11]=n.addModelFallback,t[12]=l,t[13]=d):d=t[13];let f;t[14]!==c||t[15]!==d?(f=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[c,d]}),t[14]=c,t[15]=d,t[16]=f):f=t[16];let p;t[17]!==n.desc.imageModelFallbacks||t[18]!==n.label.imageModelFallbacks||t[19]!==f?(p=(0,$.jsx)(jn,{label:o,description:s,children:f}),t[17]=n.desc.imageModelFallbacks,t[18]=n.label.imageModelFallbacks,t[19]=f,t[20]=p):p=t[20];let m=n.label.imageGenerationModelFallbacks,h=n.desc.imageGenerationModelFallbacks,g;t[21]!==n.imageGenOutOfFilterNote||t[22]!==n.imageGenRegistryEmpty||t[23]!==n.removeModelFallback||t[24]!==r||t[25]!==i.imageGenerationModelFallbacks||t[26]!==a?(g=i.imageGenerationModelFallbacks.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(Er,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,registryEmptyHint:n.imageGenRegistryEmpty,outOfFilterNote:n.imageGenOutOfFilterNote,onChange:e=>{let n=[...i.imageGenerationModelFallbacks];n[t]=e,a({imageGenerationModelFallbacks:n})}})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({imageGenerationModelFallbacks:i.imageGenerationModelFallbacks.filter((e,n)=>n!==t)}),children:(0,$.jsx)(Lt,{className:`size-4`,strokeWidth:1.75})})]},Ar(e,t,i.imageGenerationModelFallbacks))),t[21]=n.imageGenOutOfFilterNote,t[22]=n.imageGenRegistryEmpty,t[23]=n.removeModelFallback,t[24]=r,t[25]=i.imageGenerationModelFallbacks,t[26]=a,t[27]=g):g=t[27];let _;t[28]!==i.imageGenerationModelFallbacks||t[29]!==a?(_=()=>a({imageGenerationModelFallbacks:[...i.imageGenerationModelFallbacks,``]}),t[28]=i.imageGenerationModelFallbacks,t[29]=a,t[30]=_):_=t[30];let v;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Re,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[31]=v):v=t[31];let y;t[32]!==n.addModelFallback||t[33]!==_?(y=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:_,children:[v,n.addModelFallback]}),t[32]=n.addModelFallback,t[33]=_,t[34]=y):y=t[34];let b;t[35]!==g||t[36]!==y?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[g,y]}),t[35]=g,t[36]=y,t[37]=b):b=t[37];let x;t[38]!==n.desc.imageGenerationModelFallbacks||t[39]!==n.label.imageGenerationModelFallbacks||t[40]!==b?(x=(0,$.jsx)(jn,{label:m,description:h,children:b}),t[38]=n.desc.imageGenerationModelFallbacks,t[39]=n.label.imageGenerationModelFallbacks,t[40]=b,t[41]=x):x=t[41];let S;return t[42]!==x||t[43]!==p?(S=(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p,x]}),t[42]=x,t[43]=p,t[44]=S):S=t[44],S}function Nr(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt)}var Pr=()=>l(dn);function Fr(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Ir(e){return{credentialsIntro:e.credentialsIntro,regionHint:e.regionHint,endpointPresetsHint:e.endpointPresetsHint,apiKeyLabel:e.apiKeyLabel,optionalPlaceholder:e.optionalPlaceholder,regionLabel:e.regionLabel,baseUrlLabel:e.baseUrlLabel,imageBaseUrlLabel:e.imageBaseUrlLabel,saveCredentials:e.saveCredentials,savingCredentials:e.savingCredentials,credentialsSaved:e.credentialsSaved,discardCredentials:e.discardCredentials,credentialsNothingToSave:e.credentialsNothingToSave,credentialsSaveError:e.credentialsSaveError,regionPresetDefault:e.regionPresetDefault,regionPresetCustom:e.regionPresetCustom,baseUrlPresetDefault:e.baseUrlPresetDefault,baseUrlPresetCustom:e.baseUrlPresetCustom,openExtensionSettings:e.openExtensionSettings,openImageModelsPage:e.openImageModelsPage,extensionSettingsLinkTitle:e.extensionSettingsLinkTitle,imageModelsLinkTitle:e.imageModelsLinkTitle,configured:e.configured,missingKey:e.missingKey,unsavedChanges:e.unsavedChanges,expandProvider:e.expandProvider,collapseProvider:e.collapseProvider,defaultModel:e.defaultModel,modelsLabel:e.modelsLabel,modelCountOne:e.modelCountOne,modelCountMany:e.modelCountMany,imageBaseUrlPresetHint:e.imageBaseUrlPresetHint,dashscopeRegion_beijing:e.dashscopeRegion_beijing,dashscopeRegion_singapore:e.dashscopeRegion_singapore,dashscopeRegion_us:e.dashscopeRegion_us,apiKeyMaskedHelp:e.apiKeyMaskedHelp,apiKeyCopy:e.apiKeyCopy,apiKeyCopied:e.apiKeyCopied,apiKeyShow:e.apiKeyShow,apiKeyHide:e.apiKeyHide,apiKeyNotInConfigFile:e.apiKeyNotInConfigFile,apiKeyRevealFailed:e.apiKeyRevealFailed,minimaxClusterLabel:e.minimaxClusterLabel,minimaxClusterHint:e.minimaxClusterHint,falQueueBaseLabel:e.falQueueBaseLabel,falQueueBaseHint:e.falQueueBaseHint}}var Lr=et(),Rr={loading:!0,saving:!1,savedFlash:!1,error:void 0};function zr({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.imageModelsSettings,i=!!x(e=>e.token),[o,c]=(0,Z.useReducer)(Lr,{form:null,baseline:null}),l=o.form,u=o.baseline,[f,p]=(0,Z.useReducer)(Gt,Rr),{loading:m,saving:h,savedFlash:g,error:_}=f,v=tn(),y=(0,Z.useMemo)(()=>new Set(v.map(e=>e.id)),[v]),b=(0,Z.useCallback)(async()=>{if(i){p({type:`patch`,patch:{loading:!0,error:void 0}});try{let e=await kn();c({type:`sync`,value:structuredClone(e)})}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:String(e)}})}finally{p({type:`patch`,patch:{loading:!1}})}}},[i]);(0,Z.useEffect)(()=>{b()},[b]);let S=(0,Z.useCallback)(e=>{c({type:`patch`,patch:e})},[]),{data:C=[]}=d(i?Pr():null,vn,{revalidateOnFocus:!1}),w=C.some(e=>e.configured),T=Ze(i),E=un(C),D=(0,Z.useMemo)(()=>!l||!u?!1:JSON.stringify(Fr(l))!==JSON.stringify(Fr(u)),[l,u]),O=D||E.credDirty;(0,Z.useEffect)(()=>{if(!O)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[O]);let k=(0,Z.useCallback)(async()=>{if(l){p({type:`patch`,patch:{saving:!0,error:void 0}});try{try{Pn(l.paramsJson)}catch(e){p({type:`patch`,patch:{error:e instanceof SyntaxError?n.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:n.agentSettings.advanced.paramsInvalidJson}});return}let e=[];D&&e.push(In(l).then(()=>{c({type:`saved`,value:structuredClone(l)}),T.mutate?.()})),E.credDirty&&e.push(E.saveCredentials(r.credentialsSaveError)),await Promise.all(e),p({type:`patch`,patch:{savedFlash:!0}}),window.setTimeout(()=>p({type:`patch`,patch:{savedFlash:!1}}),1500)}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:String(e)}})}finally{p({type:`patch`,patch:{saving:!1}})}}},[l,D,T,n.agentSettings,E,r.credentialsSaveError]),A=(0,Z.useCallback)(()=>{u&&(c({type:`discard`}),E.credDirty&&E.onDiscardCredentials(),p({type:`patch`,patch:{error:void 0,savedFlash:!1}}))},[u,E]);yr({id:`image-models`,dirty:O,saving:h,save:k,discard:A});let j=(0,Z.useMemo)(()=>Ir(r),[r]),M=(0,Z.useMemo)(()=>({getApiKey:n.providersSettings.getApiKey,getApiKeyIntl:n.providersSettings.getApiKeyIntl,getApiKeyCn:n.providersSettings.getApiKeyCn}),[n.providersSettings]),N=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,P=e?`w-full text-sm text-fg-muted`:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,F=e?`flex w-full items-center gap-2 text-sm text-fg-muted`:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`;return i?m||!l?(0,$.jsxs)(`div`,{className:F,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),` Loading…`]}):(0,$.jsxs)(`div`,{className:N,children:[e?null:(0,$.jsxs)(`header`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:r.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:A,disabled:!O||h,children:r.discard}),(0,$.jsxs)(Y,{type:`button`,variant:`primary`,onClick:()=>void k(),disabled:!O||h,children:[h?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(re,{className:`size-3.5`}),(0,$.jsx)(`span`,{className:`ml-1.5`,children:h?r.saving:r.save})]})]})]}),_?(0,$.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:_}):null,(0,$.jsx)(jr,{form:l,update:S,a:n.agentSettings,chat:n.chat}),(0,$.jsx)(br,{showLabel:r.fallbackChainsTitle,hideLabel:r.fallbackChainsTitle,children:(0,$.jsx)(Mr,{form:l,update:S,a:n.agentSettings,chat:n.chat})}),(0,$.jsx)(br,{showLabel:r.runtimeTuningTitle,hideLabel:r.runtimeTuningTitle,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:r.timeoutLabel}),(0,$.jsx)(`input`,{type:`number`,min:0,step:1e3,className:J(Nr(),`max-w-48`),value:l.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));S({imageGenerationModelTimeoutMs:n&&n>0?n:null})}}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.timeoutHint})]}),(0,$.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:l.imageGenerationModelAutoProviderFallback,onChange:e=>S({imageGenerationModelAutoProviderFallback:e.target.checked}),"aria-label":r.autoFallbackLabel}),(0,$.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:r.autoFallbackLabel}),(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:r.autoFallbackHint})]})]})]})}),(0,$.jsx)(br,{icon:wt,showLabel:r.providersTitle,hideLabel:r.providersTitle,defaultOpen:w,children:C.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.providersEmpty}):(0,$.jsx)(fn,{summaries:C,credDraft:E.credDraft,credBaseline:E.credBaseline,credDirty:E.credDirty,credSaving:E.credSaving,credError:E.credError,credSavedFlash:E.credSavedFlash,credNoopFlash:E.credNoopFlash,updateCredRow:E.updateCredRow,onDiscardCredentials:E.onDiscardCredentials,onSaveCredentials:()=>void E.saveCredentials(r.credentialsSaveError),extensionIds:y,showExtensionLinks:!0,showImageModelsLink:!1,hideActions:!0,language:t,apiKeyLinkLabels:M,messages:j})})]}):(0,$.jsx)(`div`,{className:P,children:t===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var Br=[{value:`openai-completions`,label:`OpenAI Completions`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic-messages`,label:`Anthropic Messages`},{value:`google-generative-ai`,label:`Google Generative AI`},{value:`azure-openai-responses`,label:`Azure OpenAI`},{value:`bedrock-converse-stream`,label:`AWS Bedrock`},{value:`openai-codex-responses`,label:`OpenAI Codex`},{value:`google-gemini-cli`,label:`Google Gemini CLI`},{value:`google-vertex`,label:`Google Vertex AI`}];function Vr(e){if(!e||typeof e!=`object`)return;let t=e;if(typeof t.error==`string`)return t.error;if(t.error&&typeof t.error==`object`&&`message`in t.error){let e=t.error.message;return typeof e==`string`?e:void 0}}function Hr(e){if(!e||typeof e!=`object`)return{providers:{}};let t=e,n=t.providers;return n&&typeof n==`object`&&!Array.isArray(n)?e:{...t,providers:{}}}async function Ur(){let e=await C(l(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Vr(t)||`HTTP ${e.status}`);return{...t.payload,config:Hr(t.payload.config)}}async function Wr(e){let t=await C(l(`/api/models-json/validate`),{method:`POST`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Vr(n)||`HTTP ${t.status}`);return n.payload}async function Gr(e){let t=await C(l(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Vr(n)||`HTTP ${t.status}`);return n.payload}async function Kr(){let e=await C(l(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Vr(t)||`HTTP ${e.status}`);return t.payload}async function qr(e){let t=await C(l(`/api/models-json/test-api-key`),{method:`POST`,body:JSON.stringify({value:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Vr(n)||`HTTP ${t.status}`);return n.payload}function Jr(e,t,n){return{id:e,name:t||e,input:[`text`],contextWindow:128e3,maxTokens:16384,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},...n}}function Yr(e){return e.startsWith(`!`)}function Xr(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Zr(e){return Yr(e)?`shell`:Xr(e)?`env`:`literal`}function Qr(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}var $r={ollama:{baseUrl:`http://localhost:11434/v1`,api:`openai-completions`,apiKey:`ollama`},lmstudio:{baseUrl:`http://localhost:1234/v1`,api:`openai-completions`,apiKey:`lmstudio`},openrouter:{baseUrl:`https://openrouter.ai/api/v1`,api:`openai-completions`,apiKey:``},zhipuCn:{baseUrl:`https://open.bigmodel.cn/api/coding/paas/v4`,api:`openai-completions`,apiKey:`ZHIPU_API_KEY`},zaiGeneral:{baseUrl:`https://api.z.ai/api/paas/v4`,api:`openai-completions`,apiKey:`ZAI_API_KEY`}};function ei(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var ti=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function ni(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function ri(){return J(w,Je)}function ii(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function ai(e){return e===`text,image`?[`text`,`image`]:[`text`]}function oi(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function si(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function ci(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function li(e){let t=(0,Q.c)(156),{model:n,isNew:r,providerId:i,onSave:a,onClose:o,m:s}=e,c;t[0]===n?c=t[1]:(c=()=>n?{...n}:Jr(``),t[0]=n,t[1]=c);let[l,u]=(0,Z.useState)(c),[d,f]=(0,Z.useState)(ui),p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(p=(e,t)=>{u(n=>({...n,[e]:t})),f(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=p):p=t[2];let m=p,h;t[3]!==l.contextWindow||t[4]!==l.id||t[5]!==l.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(h=()=>{let e=new Map;return(l.id||``).trim()||e.set(`id`,s.modelIdRequired),l.contextWindow!==void 0&&l.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),l.maxTokens!==void 0&&l.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),f(e),e.size===0},t[3]=l.contextWindow,t[4]=l.id,t[5]=l.maxTokens,t[6]=s.modelIdRequired,t[7]=s.mustBePositive,t[8]=h):h=t[8];let g=h,_;t[9]!==l||t[10]!==o||t[11]!==a||t[12]!==g?(_=()=>{if(!g())return;let e=(l.id||``).trim();a({...l,id:e,name:l.name?.trim()||e,reasoning:l.reasoning||!1,input:l.input||[`text`],contextWindow:l.contextWindow??128e3,maxTokens:l.maxTokens??16384,cost:{input:l.cost?.input??0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}}),o()},t[9]=l,t[10]=o,t[11]=a,t[12]=g,t[13]=_):_=t[13];let b=_,x=l,S;t[14]===x?S=t[15]:(S=ii(x),t[14]=x,t[15]=S);let C=S,w=r?s.addModelTitle:s.editModelTitle,T;t[16]===w?T=t[17]:(T=(0,$.jsx)(v,{className:`text-base font-semibold text-fg`,children:w}),t[16]=w,t[17]=T);let E;t[18]!==s.modelProviderLabel||t[19]!==i?(E=i?(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,i]}):null,t[18]=s.modelProviderLabel,t[19]=i,t[20]=E):E=t[20];let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(`div`,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(O=J(De,`p-1.5 hover:bg-surface-base`),t[24]=O):O=t[24];let k;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(xt,{className:`size-4`}),t[25]=k):k=t[25];let A;t[26]===s.close?A=t[27]:(A=(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:O,"aria-label":s.close,children:k})}),t[26]=s.close,t[27]=A);let j;t[28]!==D||t[29]!==A?(j=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[D,A]}),t[28]=D,t[29]=A,t[30]=j):j=t[30];let M;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=M):M=t[31];let N;t[32]===s.modelId?N=t[33]:(N=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,M]}),t[32]=s.modelId,t[33]=N);let P;t[34]===d?P=t[35]:(P=J(ni(),d.has(`id`)&&`border-red-500`),t[34]=d,t[35]=P);let F=l.id||``,I;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(I=e=>m(`id`,e.target.value),t[36]=I):I=t[36];let L=!r,R;t[37]!==P||t[38]!==F||t[39]!==L?(R=(0,$.jsx)(`input`,{className:P,value:F,onChange:I,placeholder:`e.g. llama3.1:8b`,disabled:L}),t[37]=P,t[38]=F,t[39]=L,t[40]=R):R=t[40];let z;t[41]===d?z=t[42]:(z=d.has(`id`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`id`)}):null,t[41]=d,t[42]=z);let B;t[43]!==N||t[44]!==R||t[45]!==z?(B=(0,$.jsxs)(`div`,{children:[N,R,z]}),t[43]=N,t[44]=R,t[45]=z,t[46]=B):B=t[46];let V;t[47]===s.displayName?V=t[48]:(V=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=V);let H;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(H=ni(),t[49]=H):H=t[49];let U=l.name||``,W;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(W=e=>m(`name`,e.target.value),t[50]=W):W=t[50];let G;t[51]===U?G=t[52]:(G=(0,$.jsx)(`input`,{className:H,value:U,onChange:W}),t[51]=U,t[52]=G);let ee;t[53]!==V||t[54]!==G?(ee=(0,$.jsxs)(`div`,{children:[V,G]}),t[53]=V,t[54]=G,t[55]=ee):ee=t[55];let K;t[56]===s.inputTypes?K=t[57]:(K=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=K);let te;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(te=ri(),t[58]=te):te=t[58];let ne;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>m(`input`,ai(e.target.value)),t[59]=ne):ne=t[59];let re;t[60]===s?re=t[61]:(re=ti.map(e=>(0,$.jsx)(`option`,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=re);let ie;t[62]!==C||t[63]!==re?(ie=(0,$.jsx)(`select`,{className:te,value:C,onChange:ne,children:re}),t[62]=C,t[63]=re,t[64]=ie):ie=t[64];let ae;t[65]!==K||t[66]!==ie?(ae=(0,$.jsxs)(`div`,{children:[K,ie]}),t[65]=K,t[66]=ie,t[67]=ae):ae=t[67];let oe=l.reasoning||!1,se;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(se=e=>m(`reasoning`,e.target.checked),t[68]=se):se=t[68];let ce;t[69]===oe?ce=t[70]:(ce=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:oe,onChange:se}),t[69]=oe,t[70]=ce);let le;t[71]!==s.reasoning||t[72]!==ce?(le=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[ce,s.reasoning]}),t[71]=s.reasoning,t[72]=ce,t[73]=le):le=t[73];let ue;t[74]!==ae||t[75]!==le?(ue=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ae,le]}),t[74]=ae,t[75]=le,t[76]=ue):ue=t[76];let de;t[77]===s.contextWindow?de=t[78]:(de=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=de);let fe;t[79]===d?fe=t[80]:(fe=J(ni(),d.has(`contextWindow`)&&`border-red-500`),t[79]=d,t[80]=fe);let pe=l.contextWindow??128e3,me;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(me=e=>m(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=me):me=t[81];let he;t[82]!==fe||t[83]!==pe?(he=(0,$.jsx)(`input`,{type:`number`,min:1,className:fe,value:pe,onChange:me}),t[82]=fe,t[83]=pe,t[84]=he):he=t[84];let ge;t[85]===d?ge=t[86]:(ge=d.has(`contextWindow`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`contextWindow`)}):null,t[85]=d,t[86]=ge);let _e;t[87]!==de||t[88]!==he||t[89]!==ge?(_e=(0,$.jsxs)(`div`,{children:[de,he,ge]}),t[87]=de,t[88]=he,t[89]=ge,t[90]=_e):_e=t[90];let ve;t[91]===s.maxOutputTokens?ve=t[92]:(ve=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=ve);let ye;t[93]===d?ye=t[94]:(ye=J(ni(),d.has(`maxTokens`)&&`border-red-500`),t[93]=d,t[94]=ye);let be=l.maxTokens??16384,xe;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(xe=e=>m(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=xe):xe=t[95];let Se;t[96]!==ye||t[97]!==be?(Se=(0,$.jsx)(`input`,{type:`number`,min:1,className:ye,value:be,onChange:xe}),t[96]=ye,t[97]=be,t[98]=Se):Se=t[98];let Ce;t[99]===d?Ce=t[100]:(Ce=d.has(`maxTokens`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`maxTokens`)}):null,t[99]=d,t[100]=Ce);let we;t[101]!==ve||t[102]!==Se||t[103]!==Ce?(we=(0,$.jsxs)(`div`,{children:[ve,Se,Ce]}),t[101]=ve,t[102]=Se,t[103]=Ce,t[104]=we):we=t[104];let Te;t[105]!==_e||t[106]!==we?(Te=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[_e,we]}),t[105]=_e,t[106]=we,t[107]=Te):Te=t[107];let Ee;t[108]===s.costSection?Ee=t[109]:(Ee=(0,$.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.costSection}),t[108]=s.costSection,t[109]=Ee);let Oe;t[110]===s.costInput?Oe=t[111]:(Oe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costInput}),t[110]=s.costInput,t[111]=Oe);let ke;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(ke=ni(),t[112]=ke):ke=t[112];let Ae=l.cost?.input??0,je;t[113]===l.cost?je=t[114]:(je=e=>m(`cost`,{...l.cost,input:parseFloat(e.target.value)||0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[113]=l.cost,t[114]=je);let Me;t[115]!==Ae||t[116]!==je?(Me=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:ke,value:Ae,onChange:je}),t[115]=Ae,t[116]=je,t[117]=Me):Me=t[117];let Ne;t[118]!==Oe||t[119]!==Me?(Ne=(0,$.jsxs)(`div`,{children:[Oe,Me]}),t[118]=Oe,t[119]=Me,t[120]=Ne):Ne=t[120];let Pe;t[121]===s.costOutput?Pe=t[122]:(Pe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Pe);let Fe;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Fe=ni(),t[123]=Fe):Fe=t[123];let Ie=l.cost?.output??0,Le;t[124]===l.cost?Le=t[125]:(Le=e=>m(`cost`,{...l.cost,input:l.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[124]=l.cost,t[125]=Le);let Re;t[126]!==Ie||t[127]!==Le?(Re=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Fe,value:Ie,onChange:Le}),t[126]=Ie,t[127]=Le,t[128]=Re):Re=t[128];let ze;t[129]!==Pe||t[130]!==Re?(ze=(0,$.jsxs)(`div`,{children:[Pe,Re]}),t[129]=Pe,t[130]=Re,t[131]=ze):ze=t[131];let Be;t[132]!==Ne||t[133]!==ze?(Be=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Ne,ze]}),t[132]=Ne,t[133]=ze,t[134]=Be):Be=t[134];let Ve;t[135]!==Ee||t[136]!==Be?(Ve=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[Ee,Be]}),t[135]=Ee,t[136]=Be,t[137]=Ve):Ve=t[137];let He;t[138]!==B||t[139]!==ee||t[140]!==ue||t[141]!==Te||t[142]!==Ve?(He=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[B,ee,ue,Te,Ve]}),t[138]=B,t[139]=ee,t[140]=ue,t[141]=Te,t[142]=Ve,t[143]=He):He=t[143];let Ue;t[144]===s.cancel?Ue=t[145]:(Ue=(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=Ue);let We=r?s.addModelConfirm:s.saveModelConfirm,Ge;t[146]!==b||t[147]!==We?(Ge=(0,$.jsx)(Y,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:b,children:We}),t[146]=b,t[147]=We,t[148]=Ge):Ge=t[148];let Ke;t[149]!==Ue||t[150]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Ue,Ge]}),t[149]=Ue,t[150]=Ge,t[151]=Ke):Ke=t[151];let qe;return t[152]!==j||t[153]!==He||t[154]!==Ke?(qe=(0,$.jsxs)($.Fragment,{children:[j,He,Ke]}),t[152]=j,t[153]=He,t[154]=Ke,t[155]=qe):qe=t[155],qe}function ui(){return new Map}function di(e){let t=(0,Q.c)(16),{open:n,onOpenChange:r,providerId:i,model:a,isNew:o,onSave:s,m:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(m,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim`,ft)}),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,_t,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[1]=u):u=t[1];let d;t[2]!==o||t[3]!==c||t[4]!==a||t[5]!==r||t[6]!==s||t[7]!==n||t[8]!==i?(d=n?(0,$.jsx)(li,{model:a,isNew:o,providerId:i,onSave:s,onClose:()=>r(!1),m:c},`${i??`none`}-${a?.id??`new`}`):null,t[2]=o,t[3]=c,t[4]=a,t[5]=r,t[6]=s,t[7]=n,t[8]=i,t[9]=d):d=t[9];let f;t[10]===d?f=t[11]:(f=(0,$.jsxs)(p,{children:[l,(0,$.jsx)(h,{className:u,onOpenAutoFocus:fi,children:d})]}),t[10]=d,t[11]=f);let _;return t[12]!==r||t[13]!==n||t[14]!==f?(_=(0,$.jsx)(g,{open:n,onOpenChange:r,children:f}),t[12]=r,t[13]=n,t[14]=f,t[15]=_):_=t[15],_}function fi(e){return e.preventDefault()}function pi(e){let t=e||null;if(t&&$r[t]){let e=$r[t];return{preset:t,baseUrl:e.baseUrl||``,api:e.api||`openai-completions`,apiKey:e.apiKey??``,providerId:ei(t),error:null}}return{preset:`custom`,providerId:``,baseUrl:``,api:`openai-completions`,apiKey:``,error:null}}function mi(e,t){switch(t.type){case`reset`:return pi(t.presetKey);case`applyPreset`:{if(t.key===`custom`)return{...e,preset:`custom`,error:null};let n=$r[t.key];return n?{...e,preset:t.key,baseUrl:n.baseUrl||``,api:n.api||`openai-completions`,apiKey:n.apiKey??``,providerId:ei(t.key),error:null}:e}case`setProviderId`:return{...e,providerId:t.value};case`setBaseUrl`:return{...e,baseUrl:t.value};case`setApi`:return{...e,api:t.value};case`setApiKey`:return{...e,apiKey:t.value};case`setError`:return{...e,error:t.value}}}function hi({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,Z.useReducer)(mi,void 0,()=>pi(n)),s=e?n??`custom`:``,c=(0,Z.useRef)(``);e&&c.current!==s&&(c.current=s,o({type:`reset`,presetKey:n})),!e&&c.current!==``&&(c.current=``);let{providerId:l,preset:u,baseUrl:d,api:f,apiKey:_,error:b}=a;return(0,$.jsx)(g,{open:e,onOpenChange:t,children:(0,$.jsxs)(p,{children:[(0,$.jsx)(m,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim`,ft)}),(0,$.jsxs)(h,{className:J(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,_t,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(v,{className:`text-base font-semibold text-fg`,children:i.addProviderTitle}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.addProviderSubtitle})]}),(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(De,`p-1.5 hover:bg-surface-base`),"aria-label":i.close,children:(0,$.jsx)(xt,{className:`size-4`})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.presetLabel}),(0,$.jsxs)(`select`,{className:ri(),value:u,onChange:e=>o({type:`applyPreset`,key:e.target.value}),children:[(0,$.jsx)(`option`,{value:`custom`,children:i.presetCustom}),(0,$.jsx)(`option`,{value:`ollama`,children:i.presetOllama}),(0,$.jsx)(`option`,{value:`lmstudio`,children:i.presetLmStudio}),(0,$.jsx)(`option`,{value:`openrouter`,children:i.presetOpenRouter}),(0,$.jsx)(`option`,{value:`zhipuCn`,children:i.presetZhipuCn}),(0,$.jsx)(`option`,{value:`zaiGeneral`,children:i.presetZaiGeneral})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[i.providerIdLabel,(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,$.jsx)(`input`,{className:ni(),value:l,onChange:e=>o({type:`setProviderId`,value:e.target.value}),placeholder:i.providerIdPlaceholder})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,$.jsx)(`input`,{className:ni(),value:d,onChange:e=>o({type:`setBaseUrl`,value:e.target.value}),placeholder:`https://…`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,$.jsx)(`select`,{className:ri(),value:f,onChange:e=>o({type:`setApi`,value:e.target.value}),children:Br.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiKey}),(0,$.jsx)(`input`,{className:ni(),value:_,onChange:e=>o({type:`setApiKey`,value:e.target.value}),placeholder:i.apiKeyPlaceholder})]}),b?(0,$.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,$.jsx)(Pe,{className:`size-3.5 shrink-0`}),b]}):null]}),(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,$.jsx)(Y,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=l.trim();if(!e){o({type:`setError`,value:i.providerIdRequired});return}o({type:`setError`,value:null}),r(e,{baseUrl:d.trim()||void 0,api:f,apiKey:_.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function gi(e){let t=(0,Q.c)(27),{config:n,setConfig:r,expanded:i,toggleExpand:a,showPw:o,toggleShowPw:s,testResults:c,runTestKey:l,ms:u,removeProv:d,openModelDialog:f,setTestResults:p}=e,m;if(t[0]!==n.providers||t[1]!==i||t[2]!==u||t[3]!==f||t[4]!==d||t[5]!==l||t[6]!==r||t[7]!==p||t[8]!==o||t[9]!==c||t[10]!==a||t[11]!==s){let e;t[13]!==i||t[14]!==u||t[15]!==f||t[16]!==d||t[17]!==l||t[18]!==r||t[19]!==p||t[20]!==o||t[21]!==c||t[22]!==a||t[23]!==s?(e=e=>{let[t,n]=e,m=i.has(t),h=n.models?.length??0,g=n.apiKey?Zr(n.apiKey):null,_=c.get(t),v=o.has(t);return(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle bg-surface-hover/35 px-3 py-2 dark:border-edge-subtle`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-left text-sm font-semibold text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 transition-transform duration-150 ease-out active:scale-[0.99] motion-reduce:transition-none motion-reduce:active:scale-100`,onClick:()=>a(t),children:[m?(0,$.jsx)(zt,{className:`size-4 shrink-0 text-fg-muted`}):(0,$.jsx)(G,{className:`size-4 shrink-0 text-fg-muted`}),(0,$.jsx)(`span`,{className:`truncate`,children:t}),h>0?(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:h}):null,g?(0,$.jsx)(`span`,{className:J(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,g===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,g===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,g===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:g===`shell`?u.badgeShell:g===`env`?u.badgeEnv:u.badgeLiteral}):null]}),(0,$.jsx)(`button`,{type:`button`,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-red-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 dark:hover:text-red-400`,X.press),onClick:()=>d(t),"aria-label":u.removeProvider,children:(0,$.jsx)(Lt,{className:`size-4`})})]}),m?(0,$.jsxs)(`div`,{className:`space-y-4 p-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.baseUrl}),(0,$.jsx)(`input`,{className:ni(),value:n.baseUrl||``,onChange:e=>r(n=>oi(n,t,{baseUrl:e.target.value}))})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiType}),(0,$.jsx)(`select`,{className:ri(),value:n.api||`openai-completions`,onChange:e=>r(n=>oi(n,t,{api:e.target.value})),children:Br.map(_i)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiKey}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(`input`,{className:J(ni(),`min-w-0 flex-1`),type:v?`text`:`password`,autoComplete:`off`,value:n.apiKey||``,onChange:e=>{let n=e.target.value;r(e=>oi(e,t,{apiKey:n})),p(e=>{let n=new Map(e);return n.delete(t),n})},placeholder:u.apiKeyPlaceholder}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(t),children:v?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(en,{className:`mr-1 size-3.5`}),u.hide]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`mr-1 size-3.5`}),u.show]})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>l(t,n.apiKey||``),children:u.testKey})]}),_?(0,$.jsx)(`p`,{className:J(`mt-1 text-xs`,_.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:_.error?`${u.testError}: ${_.error}`:`${u.testOk} (${_.type}): ${Qr(_.resolved||``)}`}):null,(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u.apiKeyHint})]}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.authHeader||!1,onChange:e=>r(n=>oi(n,t,{authHeader:e.target.checked}))}),u.authHeader]}),(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:u.modelsSection}),(0,$.jsxs)(Y,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>f(t,null,!0),children:[(0,$.jsx)(Re,{className:`mr-1 size-3.5`}),u.addModel]})]}),(n.models||[]).length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:u.modelsEmpty}):(0,$.jsx)(`ul`,{className:`space-y-2`,children:(n.models||[]).map(e=>(0,$.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2 dark:border-edge`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:e.id}),e.name&&e.name!==e.id?(0,$.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.name}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,X.press),onClick:()=>f(t,e,!1),"aria-label":u.editModel,children:(0,$.jsx)(Vt,{className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-red-600 dark:hover:text-red-400`,X.press),onClick:()=>{window.confirm(u.removeModelConfirm.replace(`{{id}}`,e.id))&&r(n=>{let r=n.providers[t];return r?oi(n,t,{models:(r.models||[]).filter(t=>t.id!==e.id)}):n})},"aria-label":u.removeModel,children:(0,$.jsx)(Lt,{className:`size-4`})})]})]},e.id))})]})]}):null]},t)},t[13]=i,t[14]=u,t[15]=f,t[16]=d,t[17]=l,t[18]=r,t[19]=p,t[20]=o,t[21]=c,t[22]=a,t[23]=s,t[24]=e):e=t[24],m=Object.entries(n.providers).sort(vi).map(e),t[0]=n.providers,t[1]=i,t[2]=u,t[3]=f,t[4]=d,t[5]=l,t[6]=r,t[7]=p,t[8]=o,t[9]=c,t[10]=a,t[11]=s,t[12]=m}else m=t[12];let h;return t[25]===m?h=t[26]:(h=(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:m}),t[25]=m,t[26]=h),h}function _i(e){return(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value)}function vi(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function yi(e){let t=(0,Q.c)(57),{ms:n,openAddProvider:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`div`,{className:`mb-4 flex size-14 items-center justify-center rounded-full border border-edge bg-surface-base dark:border-edge`,children:(0,$.jsx)(Dt,{className:`size-7 text-accent`,strokeWidth:1.5})}),t[0]=i):i=t[0];let a;t[1]===n.emptyTitle?a=t[2]:(a=(0,$.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:n.emptyTitle}),t[1]=n.emptyTitle,t[2]=a);let o;t[3]===n.emptyDesc?o=t[4]:(o=(0,$.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:n.emptyDesc}),t[3]=n.emptyDesc,t[4]=o);let s;t[5]===r?s=t[6]:(s=()=>r(null),t[5]=r,t[6]=s);let c;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(Re,{className:`mr-1 size-4`}),t[7]=c):c=t[7];let l;t[8]!==n.emptyCta||t[9]!==s?(l=(0,$.jsxs)(Y,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:s,children:[c,n.emptyCta]}),t[8]=n.emptyCta,t[9]=s,t[10]=l):l=t[10];let u;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,X.transition,X.focusRingBase,X.press),t[11]=u):u=t[11];let d;t[12]===r?d=t[13]:(d=()=>r(`ollama`),t[12]=r,t[13]=d);let f;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(Wt,{className:`size-3.5`,"aria-hidden":!0}),t[14]=f):f=t[14];let p;t[15]!==n.presetOllama||t[16]!==d?(p=(0,$.jsxs)(`button`,{type:`button`,className:u,onClick:d,children:[f,n.presetOllama]}),t[15]=n.presetOllama,t[16]=d,t[17]=p):p=t[17];let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=J(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,X.transition,X.focusRingBase,X.press),t[18]=m):m=t[18];let h;t[19]===r?h=t[20]:(h=()=>r(`openrouter`),t[19]=r,t[20]=h);let g;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(qe,{className:`size-3.5`,"aria-hidden":!0}),t[21]=g):g=t[21];let _;t[22]!==n.presetOpenRouter||t[23]!==h?(_=(0,$.jsxs)(`button`,{type:`button`,className:m,onClick:h,children:[g,n.presetOpenRouter]}),t[22]=n.presetOpenRouter,t[23]=h,t[24]=_):_=t[24];let v;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(v=J(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,X.transition,X.focusRingBase,X.press),t[25]=v):v=t[25];let y;t[26]===r?y=t[27]:(y=()=>r(`lmstudio`),t[26]=r,t[27]=y);let b;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Dt,{className:`size-3.5`,"aria-hidden":!0}),t[28]=b):b=t[28];let x;t[29]!==n.presetLmStudio||t[30]!==y?(x=(0,$.jsxs)(`button`,{type:`button`,className:v,onClick:y,children:[b,n.presetLmStudio]}),t[29]=n.presetLmStudio,t[30]=y,t[31]=x):x=t[31];let S;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(S=J(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,X.transition,X.focusRingBase,X.press),t[32]=S):S=t[32];let C;t[33]===r?C=t[34]:(C=()=>r(`zhipuCn`),t[33]=r,t[34]=C);let w;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(Wt,{className:`size-3.5`,"aria-hidden":!0}),t[35]=w):w=t[35];let T;t[36]!==n.presetZhipuCn||t[37]!==C?(T=(0,$.jsxs)(`button`,{type:`button`,className:S,onClick:C,children:[w,n.presetZhipuCn]}),t[36]=n.presetZhipuCn,t[37]=C,t[38]=T):T=t[38];let E;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(E=J(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,X.transition,X.focusRingBase,X.press),t[39]=E):E=t[39];let D;t[40]===r?D=t[41]:(D=()=>r(`zaiGeneral`),t[40]=r,t[41]=D);let O;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(qe,{className:`size-3.5`,"aria-hidden":!0}),t[42]=O):O=t[42];let k;t[43]!==n.presetZaiGeneral||t[44]!==D?(k=(0,$.jsxs)(`button`,{type:`button`,className:E,onClick:D,children:[O,n.presetZaiGeneral]}),t[43]=n.presetZaiGeneral,t[44]=D,t[45]=k):k=t[45];let A;t[46]!==p||t[47]!==_||t[48]!==x||t[49]!==T||t[50]!==k?(A=(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[p,_,x,T,k]}),t[46]=p,t[47]=_,t[48]=x,t[49]=T,t[50]=k,t[51]=A):A=t[51];let j;return t[52]!==a||t[53]!==A||t[54]!==o||t[55]!==l?(j=(0,$.jsxs)(`div`,{className:`flex flex-col items-center rounded-xl border-2 border-dashed border-edge-subtle bg-surface-panel px-6 py-12 text-center dark:border-edge`,children:[i,a,o,l,A]}),t[52]=a,t[53]=A,t[54]=o,t[55]=l,t[56]=j):j=t[56],j}var bi=et(),xi={path:``,loadMetaError:void 0,loading:!0,saving:!1,validating:!1,reloading:!1,error:null,saveOk:!1,validation:null,expanded:new Set,editorMode:`guided`,rawText:``,rawError:null,showPw:new Set,testResults:new Map,providerDialogOpen:!1,providerPreset:null,modelDialogOpen:!1,modelDialogCtx:null};function Si({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.modelsSettings,i=Fn(n.agentSettings),o=!!x(e=>e.token),[c,l]=(0,Z.useReducer)(bi,{form:{providers:{}},baseline:{providers:{}}}),u=c.form??{providers:{}},d=c.baseline??{providers:{}},[f,p]=(0,Z.useReducer)(Gt,xi),{path:m,loadMetaError:h,loading:g,saving:_,validating:v,reloading:y,error:b,saveOk:S,validation:C,expanded:w,editorMode:T,rawText:E,rawError:D,showPw:O,testResults:k,providerDialogOpen:A,providerPreset:j,modelDialogOpen:M,modelDialogCtx:N}=f,P=(0,Z.useCallback)(e=>{l({type:`set-form`,updater:t=>typeof e==`function`?e(t):e})},[]),F=(0,Z.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&p({type:`patch`,patch:{loading:!0}}),p({type:`patch`,patch:{error:null}});try{let e=await Ur();l({type:`sync`,value:Hr(e.config)}),p({type:`patch`,patch:{path:e.path,loadMetaError:e.loadError,validation:null,saveOk:!1}})}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:r.loadError}}),l({type:`sync`,value:{providers:{}}})}finally{t&&p({type:`patch`,patch:{loading:!1}})}},[r.loadError]);(0,Z.useEffect)(()=>{if(!o){p({type:`patch`,patch:{loading:!1}});return}F()},[o,F]);let I=(0,Z.useMemo)(()=>JSON.stringify(u)!==JSON.stringify(d),[u,d]),L=I||i.dirty,R=(0,Z.useMemo)(()=>{let e=Object.keys(u.providers),t=0;for(let e of Object.values(u.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[u.providers]),z=e=>{let t=new Set(w);t.has(e)?t.delete(e):t.add(e),p({type:`patch`,patch:{expanded:t}})},B=e=>{let t=new Set(O);t.has(e)?t.delete(e):t.add(e),p({type:`patch`,patch:{showPw:t}})},V=(0,Z.useCallback)(()=>{p({type:`patch`,patch:{rawText:JSON.stringify(u,null,2),rawError:null}})},[u]),H=(0,Z.useCallback)(e=>{p({type:`patch`,patch:e===`expert`?{editorMode:e,rawText:JSON.stringify(u,null,2),rawError:null}:{editorMode:e}})},[u]),U=()=>{try{P(Hr(JSON.parse(E))),p({type:`patch`,patch:{rawError:null}})}catch{p({type:`patch`,patch:{rawError:r.jsonParseError}})}},W=async()=>{p({type:`patch`,patch:{validating:!0,error:null}});try{p({type:`patch`,patch:{validation:await Wr(u)}})}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:r.validateError}})}finally{p({type:`patch`,patch:{validating:!1}})}},G=async()=>{if(_||i.saving)return;let e=I,t=i.dirty;if(!(!e&&!t)){p({type:`patch`,patch:{error:null,saveOk:!1}});try{if(e){p({type:`patch`,patch:{saving:!0}});try{await Gr(u),l({type:`saved`,value:structuredClone(u)}),p({type:`patch`,patch:{validation:null}})}finally{p({type:`patch`,patch:{saving:!1}})}}if(t&&i.form&&!await i.save())throw Error(n.agentSettings.saveError);p({type:`patch`,patch:{saveOk:!0}})}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:r.saveError}})}}},ee=(0,Z.useCallback)(()=>{l({type:`discard`}),p({type:`patch`,patch:{validation:null,saveOk:!1,error:null,...T===`expert`?{rawText:JSON.stringify(d,null,2),rawError:null}:{}}}),i.discard()},[d,T,i]);yr({id:`models`,dirty:L,saving:_||i.saving,save:G,discard:ee});let K=async()=>{p({type:`patch`,patch:{reloading:!0,error:null}});try{await Kr(),await F({skipFullPageLoading:!0})}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:r.reloadError}})}finally{p({type:`patch`,patch:{reloading:!1}})}},te=async(e,t)=>{try{let n=await qr(t),r=new Map(k);r.set(e,n),p({type:`patch`,patch:{testResults:r}})}catch(t){let n=new Map(k);n.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),p({type:`patch`,patch:{testResults:n}})}},ne=(e=null)=>{p({type:`patch`,patch:{providerPreset:e,providerDialogOpen:!0}})},re=(e,t)=>{P(n=>ci(n,e,t)),p({type:`patch`,patch:{expanded:new Set(w).add(e)}})},ie=e=>{if(!window.confirm(r.removeProviderConfirm.replace(`{{id}}`,e)))return;P(t=>si(t,e));let t=new Map(k);t.delete(e),p({type:`patch`,patch:{testResults:t}})},ae=(e,t,n)=>{p({type:`patch`,patch:{modelDialogCtx:{providerId:e,model:t,isNew:n},modelDialogOpen:!0}})},oe=(0,Z.useCallback)(e=>{p({type:`patch`,patch:{testResults:typeof e==`function`?e(k):e}})},[k]),se=e=>{if(!N)return;let{providerId:t,isNew:n}=N;P(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?oi(r,t,{models:[...a,e]}):oi(r,t,{models:a.map(t=>t.id===e.id?e:t)})})},ce=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,le=e?`flex flex-col gap-3`:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`;return o?(0,$.jsxs)(`div`,{className:ce,children:[e?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.settingsSections.models}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.subtitle}),(0,$.jsxs)(`a`,{href:Be(t,`models`),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[r.docsLink,(0,$.jsx)(Me,{className:`size-3.5`})]})]}),h?(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,role:`status`,children:[(0,$.jsx)(Pe,{className:`mt-0.5 size-4 shrink-0`}),(0,$.jsxs)(`span`,{children:[r.loadFileWarning,`: `,h]})]}):null,m?(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[r.filePath,`: `,(0,$.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:m})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`div`,{className:`inline-flex rounded-lg border border-edge-subtle bg-surface-panel p-0.5`,role:`tablist`,"aria-label":r.modeGuided,children:[`guided`,`expert`].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":T===e,className:J(`rounded-md px-3 py-1.5 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press,T===e?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>{H(e),p({type:`patch`,patch:{rawError:null}})},children:e===`guided`?r.modeGuided:r.modeExpert},e))}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:T===`guided`?r.modeGuidedHint:r.modeExpertHint})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ne(null),disabled:g,children:[(0,$.jsx)(Re,{className:`mr-1 size-4`}),r.addProvider]}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:W,disabled:g||v,children:v?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(q,{className:`mr-1 size-4 animate-spin`}),r.validating]}):r.validate}),e?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ee,disabled:g||_||i.saving||!L,children:r.discard}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void G(),disabled:g||_||i.saving||!L,children:_||i.saving?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(q,{className:`mr-1 size-4 animate-spin`}),r.saving]}):r.save})]}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:K,disabled:g||y,children:y?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(q,{className:`mr-1 size-4 animate-spin`}),r.reloading]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ee,{className:`mr-1 size-4`}),r.reload]})}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-1.5 text-sm dark:border-edge`,children:[(0,$.jsx)(`span`,{className:`text-fg-muted`,children:r.statsProviders.replace(`{{count}}`,String(R.providers))}),(0,$.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,$.jsx)(`span`,{className:`text-fg-muted`,children:r.statsModels.replace(`{{count}}`,String(R.models))})]})]}),L&&!e?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:r.unsavedHint}):null,S||i.saveOk?(0,$.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:r.saved}):null,b?(0,$.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,$.jsx)(Pe,{className:`size-4 shrink-0`}),b]}):null,i.error?(0,$.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,$.jsx)(Pe,{className:`size-4 shrink-0`}),i.error]}):null,C&&C.errors.length>0?(0,$.jsxs)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50/80 px-3 py-2 dark:border-amber-800 dark:bg-amber-950/30`,role:`status`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:C.valid?r.validationWarnings:r.validationErrors}),(0,$.jsx)(`ul`,{className:`list-inside list-disc space-y-0.5 text-xs text-amber-900 dark:text-amber-200`,children:C.errors.map(e=>(0,$.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${e.severity}-${e.message}`))})]}):null,g?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),r.loading]}):T===`expert`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`textarea`,{className:J(ni(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:E,onChange:e=>p({type:`patch`,patch:{rawText:e.target.value}}),spellCheck:!1}),D?(0,$.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:D}):null,(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:V,children:r.jsonReset}),(0,$.jsx)(Y,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:U,children:r.jsonApply})]})]}):Object.keys(u.providers).length===0?(0,$.jsx)(yi,{ms:r,openAddProvider:ne}):(0,$.jsx)(gi,{config:u,setConfig:P,expanded:w,toggleExpand:z,showPw:O,toggleShowPw:B,testResults:k,runTestKey:te,ms:r,removeProv:ie,openModelDialog:ae,setTestResults:oe}),(0,$.jsx)(hi,{open:A,onOpenChange:e=>p({type:`patch`,patch:{providerDialogOpen:e}}),presetKey:j,onConfirm:re,m:r}),(0,$.jsx)(di,{open:M,onOpenChange:e=>{p({type:`patch`,patch:{modelDialogOpen:e,...e?{}:{modelDialogCtx:null}}})},providerId:N?.providerId??null,model:N?.model??null,isNew:N?.isNew??!1,onSave:se,m:r})]}):(0,$.jsxs)(`div`,{className:le,children:[e?null:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.settingsSections.models}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})]})}async function Ci(e){let t=await C(l(`/api/auth/oauth-async/start`),{method:`POST`,body:JSON.stringify({provider:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`OAuth start failed: ${t.status}`)}return(await t.json()).payload}async function wi(e){let t=await C(l(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function Ti(e,t){let n=await C(l(`/api/auth/oauth-async/${encodeURIComponent(e)}/code`),{method:`POST`,body:JSON.stringify({code:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Submit code failed: ${n.status}`)}}async function Ei(e){let t=await C(l(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function Di(e){let t=await C(l(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function Oi(e){let t=await C(l(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function ki(e){let t=(0,Q.c)(37),{providerId:n,language:r}=e,i=I[n];if(!i)return null;let a=r===`zh`,o=a&&i.descriptionZh?i.descriptionZh:i.description;if(!o)return null;let s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=J(De,`rounded p-0.5`),t[0]=s):s=t[0];let c=a?`${n} 详情`:`${n} info`,l;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(At,{className:`size-3.5`,"aria-hidden":!0}),t[1]=l):l=t[1];let u;t[2]===c?u=t[3]:(u=(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:s,"aria-label":c,children:l})}),t[2]=c,t[3]=u);let d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=J(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,Ye,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),t[4]=d):d=t[4];let f;t[5]===n?f=t[6]:(f=(0,$.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:n}),t[5]=n,t[6]=f);let p;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=J(De,`shrink-0 rounded p-0.5`),t[7]=p):p=t[7];let m=a?`关闭`:`Close`,h;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(xt,{className:`size-3.5`,"aria-hidden":!0}),t[8]=h):h=t[8];let g;t[9]===m?g=t[10]:(g=(0,$.jsx)(O,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:p,"aria-label":m,children:h})}),t[9]=m,t[10]=g);let _;t[11]!==g||t[12]!==f?(_=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[f,g]}),t[11]=g,t[12]=f,t[13]=_):_=t[13];let v;t[14]===o?v=t[15]:(v=(0,$.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:o}),t[14]=o,t[15]=v);let y;t[16]!==i.bestFor||t[17]!==a?(y=i.bestFor&&i.bestFor.length>0?(0,$.jsxs)(`div`,{className:`mt-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:a?`适合场景`:`Best for`}),(0,$.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:i.bestFor.map(Ai)})]}):null,t[16]=i.bestFor,t[17]=a,t[18]=y):y=t[18];let b;t[19]!==i.freeTier||t[20]!==i.freeTierNote||t[21]!==a?(b=i.freeTier===void 0?null:(0,$.jsxs)(`div`,{className:`mt-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:a?`免费额度`:`Free tier`}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.freeTier?i.freeTierNote??(a?`有免费额度`:`Available`):a?`无免费额度(按量付费)`:`None (pay-as-you-go)`})]}),t[19]=i.freeTier,t[20]=i.freeTierNote,t[21]=a,t[22]=b):b=t[22];let x;t[23]!==i.docsUrl||t[24]!==i.pricingUrl||t[25]!==a?(x=i.pricingUrl||i.docsUrl?(0,$.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[i.pricingUrl?(0,$.jsxs)(`a`,{href:i.pricingUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[a?`定价`:`Pricing`,(0,$.jsx)(Me,{className:`size-3`,"aria-hidden":!0})]}):null,i.docsUrl?(0,$.jsxs)(`a`,{href:i.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[a?`文档`:`Docs`,(0,$.jsx)(Me,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,t[23]=i.docsUrl,t[24]=i.pricingUrl,t[25]=a,t[26]=x):x=t[26];let S;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(Ot,{className:`fill-edge`}),t[27]=S):S=t[27];let C;t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(C=(0,$.jsx)(fe,{children:(0,$.jsxs)(Ct,{side:`right`,align:`start`,sideOffset:6,className:d,children:[_,v,y,b,x,S]})}),t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=C):C=t[33];let w;return t[34]!==C||t[35]!==u?(w=(0,$.jsxs)(he,{children:[u,C]}),t[34]=C,t[35]=u,t[36]=w):w=t[36],w}function Ai(e){return(0,$.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-muted`,children:e},e)}var ji=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Mi(e){let t=new Map;for(let e of ji)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function Ni(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Pi(e,t){switch(t){case`agent`:return e.sourceAgent;case`gateway`:return e.sourceGateway;case`oauth`:return e.sourceOauth;case`env`:return e.sourceEnv;case`models_json`:return e.sourceModelsJson;case`extension`:return e.sourceExtension;default:return e.sourceNone}}function Fi(e){let t=(0,Q.c)(17),{envVar:n,labels:r}=e,[i,a]=(0,Z.useState)(!1),o;t[0]===n?o=t[1]:(o=async()=>{await K(n)&&(a(!0),window.setTimeout(()=>a(!1),2e3))},t[0]=n,t[1]=o);let s=o,c;t[2]===n?c=t[3]:(c=(0,$.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:n}),t[2]=n,t[3]=c);let l;t[4]===s?l=t[5]:(l=()=>void s(),t[4]=s,t[5]=l);let u;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,X.press),t[6]=u):u=t[6];let d=i?r.copied:r.copy,f=i?r.copied:r.copy,p;t[7]===i?p=t[8]:(p=i?(0,$.jsx)(Ie,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,$.jsx)(D,{className:`size-3.5`,"aria-hidden":!0}),t[7]=i,t[8]=p);let m;t[9]!==l||t[10]!==d||t[11]!==f||t[12]!==p?(m=(0,$.jsx)(`button`,{type:`button`,onClick:l,className:u,title:d,"aria-label":f,children:p}),t[9]=l,t[10]=d,t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==c||t[15]!==m?(h=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,m]}),t[14]=c,t[15]=m,t[16]=h):h=t[16],h}var Ii={loading:!1,codeInput:``};function Li(e,t){switch(t.type){case`start`:return{loading:!0,status:`waiting`,message:t.message,codeInput:``,sessionId:void 0,authUrl:void 0,instructions:void 0};case`session`:return{...e,sessionId:t.sessionId};case`poll`:return{...e,message:t.message??e.message,authUrl:t.authUrl,instructions:t.instructions,status:t.status};case`complete`:return{...e,loading:!1,status:`success`,message:t.message??e.message};case`fail`:return{...e,loading:!1,status:`error`,message:t.message};case`cancel`:return Ii;case`setCode`:return{...e,codeInput:t.value};case`clearCode`:return{...e,codeInput:``}}}var Ri={showKey:!1,copied:!1,revokeError:null,removeLoading:!1,removeMessage:null,removeConfirmOpen:!1,testLoading:!1,testMessage:null,testOk:null};function zi(e,t){switch(t.type){case`toggleShowKey`:return{...e,showKey:!e.showKey};case`copied`:return{...e,copied:!0};case`clearCopied`:return{...e,copied:!1};case`revokeError`:return{...e,revokeError:t.message};case`removeStart`:return{...e,removeLoading:!0,removeMessage:null,removeConfirmOpen:!1};case`removeDone`:return{...e,removeLoading:!1,removeMessage:t.message};case`removeConfirm`:return{...e,removeConfirmOpen:t.open};case`testStart`:return{...e,testLoading:!0,testMessage:null,testOk:null};case`testDone`:return{...e,testLoading:!1,testOk:t.ok,testMessage:t.message}}}function Bi(e){let t=(0,Q.c)(17),{label:n,children:r}=e,[i,a]=(0,Z.useState)(!1),o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>a(Vi),t[0]=o):o=t[0];let s=o,c=i&&`rotate-180`,l;t[1]===c?l=t[2]:(l=J(`size-3 transition-transform`,c),t[1]=c,t[2]=l);let u;t[3]===l?u=t[4]:(u=(0,$.jsx)(zt,{className:l,"aria-hidden":!0}),t[3]=l,t[4]=u);let d;t[5]!==n||t[6]!==u?(d=(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[u,n]}),t[5]=n,t[6]=u,t[7]=d):d=t[7];let f;t[8]!==i||t[9]!==d?(f=(0,$.jsx)(`button`,{type:`button`,onClick:s,"aria-expanded":i,className:`cursor-pointer select-none text-xs text-fg-subtle hover:text-fg-muted`,children:d}),t[8]=i,t[9]=d,t[10]=f):f=t[10];let p;t[11]!==r||t[12]!==i?(p=i?(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-2 pl-4`,children:r}):null,t[11]=r,t[12]=i,t[13]=p):p=t[13];let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(`div`,{className:`rounded-md`,children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m}function Vi(e){return!e}function Hi({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:o,justSaved:s,availableModels:c,autoExpand:l=!1,autoFocusInput:u=!1}){let[d,f]=(0,Z.useState)(!1),p=(0,Z.useRef)(null),m=(0,Z.useRef)(l);l&&!m.current&&!d?(m.current=l,f(!0)):l!==m.current&&(m.current=l);let h=(0,Z.useCallback)(e=>{p.current=e,u&&d&&e&&e.focus()},[u,d]),[g,_]=(0,Z.useReducer)(zi,Ri),{showKey:v,copied:y,revokeError:b,removeLoading:x,removeMessage:S,removeConfirmOpen:C,testLoading:w,testMessage:T,testOk:E}=g,[O,k]=(0,Z.useReducer)(Li,Ii),{loading:A,sessionId:j,status:M,message:P,authUrl:F,instructions:L,codeInput:R}=O,B=(0,Z.useRef)(void 0);B.current=j;let V=Oe(t),H=V&&!v?``:t,U=e.configured&&!V&&!!t,W=e.activeKeySource??`none`,G=(0,Z.useMemo)(()=>_e(e.id,i),[e.id,i]);(0,Z.useEffect)(()=>()=>{let e=B.current;e&&Di(e).catch(()=>{})},[]);let ee=(0,Z.useEffectEvent)(()=>{o()});(0,Z.useEffect)(()=>{if(!j||!A)return;let e=window.setInterval(()=>{(async()=>{try{let t=await wi(j);t.status===`waiting_auth`||t.status===`waiting_code`?k({type:`poll`,message:t.message,authUrl:t.authUrl,instructions:t.instructions,status:t.status===`waiting_code`?`waiting_code`:`waiting`}):t.status===`completed`?(window.clearInterval(e),k({type:`complete`,message:t.message}),window.setTimeout(()=>ee(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),k({type:`fail`,message:t.error||t.message||`OAuth failed`}))}catch{}})()},1e3);return()=>window.clearInterval(e)},[j,A]);let te=async()=>{k({type:`start`,message:r.oauthStarting});try{k({type:`session`,sessionId:(await Ci(e.id)).sessionId})}catch(e){k({type:`fail`,message:e instanceof Error?e.message:`OAuth failed`})}},ne=async()=>{let e=j;if(e){try{await Ei(e)}catch{}k({type:`cancel`})}},re=async()=>{let e=j;if(!(!e||!R.trim()))try{await Ti(e,R.trim()),k({type:`clearCode`}),k({type:`poll`,message:r.oauthProcessingCode,status:M===`waiting_code`?`waiting_code`:`waiting`})}catch(e){k({type:`fail`,message:e instanceof Error?e.message:`Failed`})}},ie=()=>{window.confirm(Ni(r.revokeConfirm,{name:e.name}))&&(_({type:`revokeError`,message:null}),Oi(e.id).then(()=>o()).catch(e=>_({type:`revokeError`,message:e instanceof Error?e.message:r.revokeFailed})))},ae=async()=>{_({type:`removeStart`});try{await rt(e.id),_({type:`removeDone`,message:r.removeKeySuccess}),a(e.id,``),window.setTimeout(()=>o(),600)}catch(e){_({type:`removeDone`,message:e instanceof Error?e.message:r.removeKeyFailed})}},oe=e.configured&&V&&W!==`env`&&W!==`extension`&&W!==`models_json`,se=async()=>{!t||V||await K(t)&&(_({type:`copied`}),window.setTimeout(()=>_({type:`clearCopied`}),2e3))},ce=async()=>{let e=t.trim();if(!(!e||Oe(e))){_({type:`testStart`});try{let t=await z(e);if(t.error){_({type:`testDone`,ok:!1,message:`${r.testFailed} ${t.error}`});return}_({type:`testDone`,ok:!0,message:t.type===`env`?r.testOkEnv:t.type===`command`?r.testOkCommand:r.testOkLiteral})}catch(e){_({type:`testDone`,ok:!1,message:e instanceof Error?e.message:r.testFailed})}}},le=n?r.metaWillSave:e.configured?V?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Pi(r,W)}`:`${r.runtimeLabelPrefix} ${Pi(r,W)}`:r.metaNotConfigured,ue=`provider-details-${e.id}`;return(0,$.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-3 sm:px-4`,children:[(0,$.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-surface-hover/80 dark:bg-surface-hover/50`,"aria-hidden":!0,children:e.configured?(0,$.jsx)(Ie,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,$.jsx)(It,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,$.jsx)(ki,{providerId:e.id,language:i}),(0,$.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.id})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:le})]}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-expanded":d,"aria-controls":ue,"aria-label":r.expandRowDetails,onClick:()=>f(e=>!e),children:(0,$.jsx)(zt,{className:J(`size-4 transition-transform`,d&&`rotate-180`),"aria-hidden":!0})})]}),d?(0,$.jsxs)(`div`,{id:ue,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 p-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,$.jsx)(`input`,{ref:h,type:v||!V?`text`:`password`,className:J(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-3 pr-20 font-mono text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`),value:H,placeholder:V?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:A,onChange:t=>a(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,$.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!V?(0,$.jsx)(`button`,{type:`button`,className:J(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,X.transition,X.press,X.focusRingPanel),title:y?r.copied:r.copy,"aria-label":y?r.copied:r.copy,onClick:()=>void se(),children:y?(0,$.jsx)(Ie,{className:`size-4`}):(0,$.jsx)(D,{className:`size-4`})}):null,(0,$.jsx)(`button`,{type:`button`,className:J(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,X.transition,X.press,X.focusRingPanel),title:v?r.hide:r.show,"aria-label":v?r.hide:r.show,disabled:V,onClick:()=>_({type:`toggleShowKey`}),children:v?(0,$.jsx)(en,{className:`size-4`}):(0,$.jsx)(N,{className:`size-4`})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:A||w||!t.trim()||Oe(t),onClick:()=>void ce(),children:[w?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,w?r.testingKey:r.testKey]}),e.supportsOAuth?U?(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:ie,children:[(0,$.jsx)(Yt,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:A,"data-oauth-session":j??``,onClick:()=>void te(),children:[A?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Mt,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null]})]}),T?(0,$.jsx)(`p`,{className:J(`text-xs`,E===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:T}):null]}),P?(0,$.jsxs)(`div`,{className:J(`flex gap-2 rounded-md px-3 py-2 text-xs`,M===`error`?`border border-red-200 bg-red-50 text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`:`bg-surface-base text-fg-muted`),children:[M===`error`?(0,$.jsx)(Pe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):M===`success`?(0,$.jsx)(Ie,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,$.jsx)(At,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:P})]}):null,b?(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:[(0,$.jsx)(Pe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:b})]}):null,S?(0,$.jsxs)(`div`,{className:J(`flex gap-2 rounded-md px-3 py-2 text-xs`,S===r.removeKeySuccess?`bg-surface-hover/60 text-fg-muted dark:bg-surface-hover/40`:`border border-red-200 bg-red-50 text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`),role:`status`,children:[S===r.removeKeySuccess?(0,$.jsx)(Ie,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,$.jsx)(Pe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:S})]}):null,(M===`waiting`||M===`waiting_code`)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[F?(0,$.jsxs)(`a`,{href:F,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[(0,$.jsx)(Me,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ne(),children:[(0,$.jsx)(xt,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),L?(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,$.jsx)(At,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:L})]}):null,M===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,className:J(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,lt,`dark:border-edge`),value:R,placeholder:r.pasteRedirectUrl,onChange:e=>k({type:`setCode`,value:e.target.value}),onKeyDown:e=>e.key===`Enter`&&void re()}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void re(),children:r.submitCode})]}):null,V?(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,$.jsx)(At,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:W===`env`?r.envHint:r.maskedStoredHint})]}):null,s?(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,$.jsx)(Ie,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:(()=>{let t=c.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(()=>{let t=I[e.id]?.envVars??[];return G.length>0||t.length>0||oe?(0,$.jsxs)(Bi,{label:r.moreOptions??r.envVarAlt,children:[G.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:G.map(e=>(0,$.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[Et(e.kind,r),(0,$.jsx)(Me,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null,t.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r.envVarAlt}),t.map(e=>(0,$.jsx)(Fi,{envVar:e,labels:r},e))]}):null,oe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`gap-1 self-start text-red-600 dark:text-red-400`,disabled:x,onClick:()=>_({type:`removeConfirm`,open:!0}),children:[x?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Lt,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,$.jsx)(Jt,{open:C,title:r.removeKey,description:Ni(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void ae(),onCancel:()=>_({type:`removeConfirm`,open:!1})})]}):null]}):null})()]}):null]})}function Ui(e,t){switch(t.type){case`reset`:return{draft:{},baseline:{}};case`sync`:{let e={};for(let n of t.rows)e[n.id]=n.apiKey;return{draft:e,baseline:{...e}}}case`patch`:return{...e,draft:{...e.draft,[t.id]:t.value}};case`discard`:return{...e,draft:{...e.baseline}};case`commitDraft`:return{...e,baseline:{...e.draft}};case`saved`:{let e={};for(let n of t.rows)e[n.id]=n.apiKey;return{draft:e,baseline:{...e}}}}}var Wi={saving:!1,error:null,saveNotice:null,expandedCats:new Set([`common`]),searchQuery:``,unconfiguredOnly:!1,savedProviderIds:new Set,quickStartProviderId:null};function Gi({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.providersSettings,i=!!x(e=>e.token),[o,c]=(0,Z.useReducer)(Ui,{draft:{},baseline:{}}),u=o.draft,f=o.baseline,[p,m]=(0,Z.useReducer)(Gt,Wi),{saving:h,error:g,saveNotice:_,expandedCats:v,searchQuery:y,unconfiguredOnly:b,savedProviderIds:C,quickStartProviderId:w}=p,T=(0,Z.useRef)(!1),D=l(`/api/providers/meta`),O=(0,Z.useCallback)(async e=>(await S(e)).payload?.providers??[],[]),{data:k,error:A,isLoading:j,mutate:N}=Ze(i),{data:P,error:F,isLoading:L,mutate:R}=d(i?D:null,O,{revalidateOnFocus:!1}),{data:z,mutate:B}=d(i?E:null,()=>St(),{revalidateOnFocus:!1}),V=(0,Z.useMemo)(()=>!P||k===void 0?null:M(P,je(k.payload?.config),z??[]),[P,k,z]),H=A instanceof Error?A.message:A?String(A):F instanceof Error?F.message:F?String(F):null,U=!!(i&&V===null&&(j||L)&&!H),W=(0,Z.useMemo)(()=>JSON.stringify(u)!==JSON.stringify(f),[u,f]);(0,Z.useEffect)(()=>{if(!W)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[W]),(0,Z.useEffect)(()=>{!i||V===null||T.current||c({type:`sync`,rows:V})},[i,V]);let G=V??[],ee=(0,Z.useMemo)(()=>{let e=G,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=I[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),b&&(e=e.filter(e=>!e.configured)),e},[G,y,b]),K=(0,Z.useMemo)(()=>Mi(ee),[ee]),te=y.trim(),ne=(0,Z.useMemo)(()=>{if(te){let e=new Set;for(let t of ji)(K.get(t)??[]).length>0&&e.add(t);return e}return v},[te,K,v]),re=(0,Z.useCallback)(async()=>{if(h)return;let e={};for(let t of Object.keys(u)){let n=u[t]?.trim()??``;!n||Oe(n)||(e[t]=n)}if(Object.keys(e).length===0){c({type:`commitDraft`}),T.current=!1,m({type:`patch`,patch:{saveNotice:`noChanges`}}),window.setTimeout(()=>m({type:`patch`,patch:{saveNotice:null}}),2500);return}m({type:`patch`,patch:{saving:!0,error:null,saveNotice:null}});try{await $t(e),m({type:`patch`,patch:{savedProviderIds:new Set(Object.keys(e))}});let t=await B(St(!0))??z??[],[n,r]=await Promise.all([N(),R()]),i=Array.isArray(r)?r:P??[],a=n??k;a?.payload&&(c({type:`saved`,rows:M(i,je(a.payload.config),t)}),T.current=!1),m({type:`patch`,patch:{saveNotice:`saved`}}),window.setTimeout(()=>m({type:`patch`,patch:{saveNotice:null}}),2500)}catch(e){m({type:`patch`,patch:{error:e instanceof Error?e.message:r.saveError}})}finally{m({type:`patch`,patch:{saving:!1}})}},[k,u,P,z,N,R,B,r.saveError,h]),ie=(0,Z.useCallback)(()=>{T.current=!1,c({type:`discard`}),m({type:`patch`,patch:{error:null,saveNotice:null,savedProviderIds:new Set}})},[f]);yr({id:`providers`,dirty:W,saving:h,save:re,discard:ie});let ae=e=>{let t=new Set(v);t.has(e)?t.delete(e):t.add(e),m({type:`patch`,patch:{expandedCats:t}})},oe=(0,Z.useCallback)(()=>{N(),R()},[N,R]),se=!!(y.trim()||b),ce=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,le=e?`flex flex-col gap-3`:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,ue=e?`w-full`:`mx-auto w-full max-w-app-main px-4 py-8`;return i?U?(0,$.jsxs)(`div`,{className:ue,children:[(0,$.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,$.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,$.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.logs.loading})]}):G.length===0?(0,$.jsxs)(`div`,{className:le,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:r.loadError}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:g??H??r.empty})]}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>{N(),R()},children:n.logs.refresh})]}):(0,$.jsxs)(`div`,{className:ce,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[e?(0,$.jsx)(`div`,{className:`min-w-0`,"aria-hidden":!0}):(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.settingsSections.providers}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:r.rotateHint})]}),e?null:(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[_===`saved`?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,_===`noChanges`?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.noChangesSaved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!W||h,onClick:ie,children:r.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!W||h,onClick:()=>void re(),children:h?r.saving:r.save})]})]}),W&&!e?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:r.unsavedHint}):null,G.length>0&&G.every(e=>!e.configured)?(0,$.jsx)(Ki,{intro:r.quickStartIntro??r.intro,recommended:[`deepseek`,`openai`,`anthropic`,`google`],metaRows:G,onPick:e=>{m({type:`patch`,patch:{searchQuery:e,quickStartProviderId:e}});let t=G.find(t=>t.id===e);if(t){let e=t.category||`specialty`;m({type:`patch`,patch:{expandedCats:new Set([...v,e])}})}}}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,$.jsx)(pe,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`input`,{type:`search`,value:y,onChange:e=>m({type:`patch`,patch:{searchQuery:e.target.value}}),placeholder:r.searchPlaceholder,autoComplete:`off`,className:J(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,lt,`dark:border-edge`),"aria-label":r.searchPlaceholder})]}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>m({type:`patch`,patch:{unconfiguredOnly:e.target.checked}}),className:`size-4 rounded border-edge text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),r.unconfiguredOnly]}),se?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{m({type:`patch`,patch:{searchQuery:``,unconfiguredOnly:!1}})},children:r.clearFilters}):null]}),g?(0,$.jsx)(`div`,{className:`rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:g}):null,ee.length===0?(0,$.jsxs)(`div`,{className:`rounded-xl border border-dashed border-edge-subtle bg-surface-base px-4 py-8 text-center text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{children:r.noMatches}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{m({type:`patch`,patch:{searchQuery:``,unconfiguredOnly:!1}})},children:r.clearFilters})]}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:ji.map(e=>{let n=K.get(e)??[];if(n.length===0)return null;let i=ne.has(e),a=n.filter(e=>e.configured).length,o=`providers-cat-${e}`;return(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,$.jsxs)(`button`,{type:`button`,id:`${o}-trigger`,"aria-expanded":i,"aria-controls":o,className:J(`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,X.pressCard),onClick:()=>ae(e),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:r.categories[e]}),(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:n.length})]}),(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[a>0?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,$.jsx)(Ie,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),Ni(r.configuredCount,{count:String(a)})]}):null,(0,$.jsx)(zt,{className:J(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,$.jsx)(`div`,{id:o,role:`region`,"aria-labelledby":`${o}-trigger`,className:`divide-y divide-edge-subtle`,children:n.map(e=>{let n=w===e.id;return(0,$.jsx)(`div`,{id:`provider-row-${e.id}`,children:(0,$.jsx)(Hi,{row:e,value:u[e.id]??``,rowDirty:(u[e.id]??``)!==(f[e.id]??``),labels:r,language:t,onChange:(e,t)=>{T.current=!0,c({type:`patch`,id:e,value:t})},onReload:oe,justSaved:C.has(e.id),availableModels:z??[],autoExpand:n,autoFocusInput:n})},e.id)})}):null]},e)})})]}):(0,$.jsx)(`div`,{className:le,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,$.jsx)(It,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,$.jsxs)(`div`,{children:[e?null:(0,$.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:n.settingsSections.providers}),(0,$.jsx)(`p`,{className:J(`text-sm text-fg-muted`,!e&&`mt-1`),children:r.needToken})]})]})})}function Ki(e){let t=(0,Q.c)(25),{intro:n,recommended:r,metaRows:i,onPick:a}=e,o,s,c,l,u;if(t[0]!==n||t[1]!==i||t[2]!==a||t[3]!==r){u=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[9]===i?e=t[10]:(e=e=>i.some(t=>t.id===e),t[9]=i,t[10]=e);let d=r.filter(e);if(d.length===0){u=null;break bb0}let f;t[11]===i?f=t[12]:(f=new Map(i.map(qi)),t[11]=i,t[12]=f);let p=f;c=`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,t[13]===n?l=t[14]:(l=(0,$.jsx)(`p`,{className:`mb-3 text-sm text-fg-muted`,children:n}),t[13]=n,t[14]=l),o=`grid gap-2 sm:grid-cols-2 lg:grid-cols-4`;let m;t[15]!==p||t[16]!==a?(m=e=>(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`justify-start`,onClick:()=>a(e),children:(0,$.jsx)(`span`,{className:`truncate`,children:p.get(e)?.name??e})},e),t[15]=p,t[16]=a,t[17]=m):m=t[17],s=d.map(m)}t[0]=n,t[1]=i,t[2]=a,t[3]=r,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8];if(u!==Symbol.for(`react.early_return_sentinel`))return u;let d;t[18]!==o||t[19]!==s?(d=(0,$.jsx)(`div`,{className:o,children:s}),t[18]=o,t[19]=s,t[20]=d):d=t[20];let f;return t[21]!==c||t[22]!==l||t[23]!==d?(f=(0,$.jsxs)(`div`,{className:c,children:[l,d]}),t[21]=c,t[22]=l,t[23]=d,t[24]=f):f=t[24],f}function qi(e){return[e.id,e]}function Ji(){let e=(0,Q.c)(26),t=s(a(ea)).modelsHub.saveBar,n=vr($i),r=vr(Qi),i=vr(Zi),o=vr(Xi),c=vr(Yi),l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],e[0]=l):l=e[0];let[u,d]=(0,Z.useState)(l),[f,p]=(0,Z.useState)(!1);if(!n&&u.length===0&&!f)return null;let m;e[1]===o?m=e[2]:(m=async()=>{d([]),p(!1);let e=await o();e.ok&&e.saved>0?(p(!0),window.setTimeout(()=>p(!1),2500)):e.ok||d(e.failures)},e[1]=o,e[2]=m);let h=m,g;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=J(`sticky top-0 z-10 -mx-4 flex flex-col gap-2 border-b border-edge-subtle bg-surface-base/85 px-4 py-2 backdrop-blur`,`sm:flex-row sm:items-center sm:justify-between`),e[3]=g):g=e[3];let _=u.length>0?(0,$.jsx)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,role:`alert`,children:t.failuresSummary.replace(`{{count}}`,String(u.length))}):null,v=!n||r,y;e[4]===c?y=e[5]:(y=()=>c(),e[4]=c,e[5]=y);let b;e[6]!==t.discardAll||e[7]!==v||e[8]!==y?(b=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:v,onClick:y,children:t.discardAll}),e[6]=t.discardAll,e[7]=v,e[8]=y,e[9]=b):b=e[9];let x=!n||r,S;e[10]===h?S=e[11]:(S=()=>void h(),e[10]=h,e[11]=S);let C;e[12]===r?C=e[13]:(C=r?(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,e[12]=r,e[13]=C);let w=r?`ml-1.5`:void 0,T;e[14]!==t.saveAll||e[15]!==w?(T=(0,$.jsx)(`span`,{className:w,children:t.saveAll}),e[14]=t.saveAll,e[15]=w,e[16]=T):T=e[16];let E;e[17]!==C||e[18]!==T||e[19]!==x||e[20]!==S?(E=(0,$.jsxs)(Y,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:x,onClick:S,children:[C,T]}),e[17]=C,e[18]=T,e[19]=x,e[20]=S,e[21]=E):E=e[21];let D;return e[22]!==E||e[23]!==_||e[24]!==b?(D=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[_,b,E]}),e[22]=E,e[23]=_,e[24]=b,e[25]=D):D=e[25],(0,$.jsxs)(`div`,{className:g,role:`region`,"aria-label":t.title,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n?t.dirtySummary.replace(`{{count}}`,String(i)):f?t.savedSummary:t.cleanSummary}),D]})}function Yi(e){return e.discardAll}function Xi(e){return e.saveAll}function Zi(e){return e.dirtyCount}function Qi(e){return e.anySaving}function $i(e){return e.anyDirty}function ea(e){return e.language}var ta=Je;function na(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`groq`:return`(GROQ_API_KEY)`;default:return``}}function ra(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`minimax`:return`(MINIMAX_API_KEY)`;default:return``}}function ia(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function aa(){return J(w,Je)}var oa=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],sa=[{id:`whisper-1`,name:`Whisper-1`}],ca=[{id:`whisper-large-v3-turbo`,name:`Whisper Large v3 Turbo`},{id:`whisper-large-v3`,name:`Whisper Large v3`}],la=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],ua=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],da=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],fa=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],pa=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],ma=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],ha=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}],ga=[{id:`openai`,aliases:[],configured:!1},{id:`alibaba`,aliases:[],configured:!1},{id:`minimax`,aliases:[],configured:!1},{id:`edge`,aliases:[],configured:!1},{id:`tts-local-cli`,aliases:[`cli`,`local-cli`],configured:!1}],_a=[{id:`alibaba`,aliases:[`dashscope`,`paraformer`],configured:!1},{id:`openai`,aliases:[],configured:!1}];function va(e,t){switch(e){case`openai`:return t.stt.openai;case`alibaba`:return t.stt.alibaba;case`groq`:return`Groq`;default:return e}}function ya(e,t){switch(e){case`openai`:return t.tts.providerOpenai;case`alibaba`:return t.stt.alibaba;case`edge`:return t.tts.providerEdge;case`tts-local-cli`:return t.tts.providerLocalCli;case`minimax`:return`MiniMax`;default:return e}}function ba(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function xa(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function Sa({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.voiceSettings,i=!!x(e=>e.token),[o,c]=(0,Z.useReducer)(xa,{form:null,baseline:null}),u=o.form,f=o.baseline,[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),S=(0,Z.useRef)(!1),C=(0,Z.useRef)({parsed:null,models:void 0}),{data:w,error:T,isLoading:E,mutate:D}=Ze(i),{data:O,error:k,isLoading:A,mutate:j}=d(i?l(`/api/voice/models`):null,pn,{revalidateOnFocus:!1}),{data:M,error:N,isLoading:P}=d(i?l(`/api/voice/providers`):null,hn,{revalidateOnFocus:!1}),{data:F,error:I,isLoading:L}=d(i?l(`/api/voice/stt-providers`):null,ln,{revalidateOnFocus:!1}),R=(0,Z.useMemo)(()=>M?.providers??ga,[M]),z=(0,Z.useMemo)(()=>F?.providers??_a,[F]),B=(0,Z.useMemo)(()=>w?.payload?.config===void 0?null:mn(w.payload.config),[w]),V=(0,Z.useMemo)(()=>!u||!f?!1:JSON.stringify(u)!==JSON.stringify(f),[u,f]);i?B!==null&&O!==void 0&&!S.current&&(C.current.parsed!==B||C.current.models!==O)&&(C.current={parsed:B,models:O},c({type:`sync`,value:B}),m(O),b(!1)):(C.current.parsed!==null||C.current.models!==void 0)&&(C.current={parsed:null,models:void 0},c({type:`reset`}),m(null),S.current=!1);let H=!!(i&&(B===null||O===void 0||M===void 0||F===void 0)&&(E||A||P||L)),U=T instanceof Error?T.message:T?String(T):k instanceof Error?k.message:k?String(k):N instanceof Error?N.message:N?String(N):I instanceof Error?I.message:I?String(I):null,W=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),G=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null})},[]),ee=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null})},[]),K=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}}})},[]),te=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),ne=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null})},[]),re=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null})},[]),ie=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null})},[]),ae=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null})},[]),oe=(0,Z.useCallback)(e=>{S.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null})},[]),se=(0,Z.useCallback)(async()=>{if(!(!u||h)){g(!0),v(null),b(!1);try{await gn(u),c({type:`saved`,value:u}),S.current=!1,b(!0),window.setTimeout(()=>b(!1),2500)}catch(e){v(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}},[u,h,r.saveError]),ce=(0,Z.useCallback)(()=>{f&&(S.current=!1,c({type:`discard`}),v(null),b(!1))},[f]);yr({id:`voice`,dirty:V,saving:h,save:se,discard:ce});let le=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,ue=e?`flex flex-col gap-3`:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`;if(!i)return(0,$.jsxs)(`div`,{className:ue,children:[e?null:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.settingsSections.voice}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})]});if(H)return(0,$.jsx)(`div`,{className:ue,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),r.loading]})});if(!u||p===null)return(0,$.jsxs)(`div`,{className:ue,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:_??U??r.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>{D(),j()},children:r.retry})]});let de=u.stt,fe=u.tts,pe=ba(r);return(0,$.jsxs)(`div`,{className:le,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[e?(0,$.jsx)(`div`,{className:`min-w-0`,"aria-hidden":!0}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.settingsSections.voice}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),(0,$.jsxs)(`a`,{href:Be(t,`voice`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[r.docsLink,(0,$.jsx)(Me,{className:`size-3.5`})]})]}),e?null:(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[y?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!V||h,onClick:ce,children:r.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!V||h,onClick:()=>void se(),children:h?r.saving:r.save})]})]}),V&&!e?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:r.unsavedHint}):null,_?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:_}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(Ca,{v:r,apiKeyLabels:pe,stt:de,models:p,sttProviders:z,updateStt:W,updateSttAlibaba:G,updateSttOpenai:ee,updateSttFallback:K}),(0,$.jsx)(Da,{v:r,apiKeyLabels:pe,tts:fe,models:p,ttsProviders:R,updateTts:te,updateTtsAlibaba:ne,updateTtsOpenai:re,updateTtsEdge:ie,updateTtsMinimax:ae,updateTtsLocalCli:oe})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,$.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,$.jsx)(`strong`,{className:`text-accent`,children:r.notes.title}),` `,r.notes.duration]}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:r.notes.envVars})]})]})}function Ca(e){let t=(0,Q.c)(59),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,updateStt:s,updateSttAlibaba:c,updateSttOpenai:l,updateSttFallback:u}=e,d=a?.stt?.alibaba?.length?a.stt.alibaba:oa,f=a?.stt?.openai?.length?a.stt.openai:sa,p;if(t[0]!==i.provider||t[1]!==o){let e=new Set;p=[];for(let t of o)e.has(t.id)||(e.add(t.id),p.push(t));if(i.provider&&!e.has(i.provider)){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3];let n;t[4]===i.provider?n=t[5]:(n={id:i.provider,aliases:e,configured:!1},t[4]=i.provider,t[5]=n),p.push(n)}t[0]=i.provider,t[1]=o,t[2]=p}else p=t[2];let m=p,h=i.providers?.[i.provider],g=typeof h?.apiKey==`string`?h.apiKey:``,_=typeof h?.model==`string`?h.model:``,v;t[6]!==i.provider||t[7]!==i.providers||t[8]!==s?(v=e=>{s({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[6]=i.provider,t[7]=i.providers,t[8]=s,t[9]=v):v=t[9];let y=v,b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Te,{className:`size-4 text-accent`,strokeWidth:1.75}),t[10]=b):b=t[10];let x;t[11]===n.stt.title?x=t[12]:(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[b,n.stt.title]}),t[11]=n.stt.title,t[12]=x);let S;t[13]===n.stt.description?S=t[14]:(S=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[13]=n.stt.description,t[14]=S);let C;t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{className:`mb-4`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17];let w;t[18]===n.stt.enable?w=t[19]:(w=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.enable}),t[18]=n.stt.enable,t[19]=w);let T;t[20]===n.stt.enableDesc?T=t[21]:(T=(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.enableDesc}),t[20]=n.stt.enableDesc,t[21]=T);let E;t[22]!==w||t[23]!==T?(E=(0,$.jsxs)(`div`,{children:[w,T]}),t[22]=w,t[23]=T,t[24]=E):E=t[24];let D;t[25]===s?D=t[26]:(D=e=>s({enabled:e.target.checked}),t[25]=s,t[26]=D);let O;t[27]!==i.enabled||t[28]!==D?(O=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.enabled,onChange:D}),t[27]=i.enabled,t[28]=D,t[29]=O):O=t[29];let k;t[30]!==O||t[31]!==E?(k=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[E,O]}),t[30]=O,t[31]=E,t[32]=k):k=t[32];let A;t[33]!==d||t[34]!==r||t[35]!==g||t[36]!==_||t[37]!==f||t[38]!==m||t[39]!==i.alibaba?.apiKey||t[40]!==i.alibaba?.model||t[41]!==i.enabled||t[42]!==i.fallback?.enabled||t[43]!==i.openai?.apiKey||t[44]!==i.openai?.model||t[45]!==i.provider||t[46]!==y||t[47]!==s||t[48]!==c||t[49]!==u||t[50]!==l||t[51]!==n?(A=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.stt.provider}),(0,$.jsx)(`select`,{className:aa(),value:i.provider,onChange:e=>s({provider:e.target.value}),children:m.map(e=>(0,$.jsxs)(`option`,{value:e.id,children:[va(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.stt.model}),i.provider===`alibaba`?(0,$.jsx)(`select`,{className:aa(),value:i.alibaba?.model??``,onChange:e=>c({model:e.target.value}),children:d.map(Ea)}):i.provider===`openai`?(0,$.jsx)(`select`,{className:aa(),value:i.openai?.model??``,onChange:e=>l({model:e.target.value}),children:f.map(Ta)}):i.provider===`groq`?(0,$.jsx)(`select`,{className:aa(),value:_||ca[0].id,onChange:e=>y({model:e.target.value}),children:ca.map(wa)}):(0,$.jsx)(`input`,{className:ia(),value:_,onChange:e=>y({model:e.target.value}),placeholder:i.provider})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.stt.apiKey}),(0,$.jsx)(_n,{kind:`stt`,providerId:i.provider,fieldId:`voice-stt-${i.provider}-api-key`,value:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.provider===`openai`?i.openai?.apiKey??``:g,onChange:e=>{i.provider===`alibaba`?c({apiKey:e}):i.provider===`openai`?l({apiKey:e}):y({apiKey:e})},labels:r,placeholder:i.provider===`groq`?`gsk_...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,na(i.provider)?` ${na(i.provider)}`:``]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.fallback?.enabled??!0,onChange:e=>u({enabled:e.target.checked})})]})]}):null,t[33]=d,t[34]=r,t[35]=g,t[36]=_,t[37]=f,t[38]=m,t[39]=i.alibaba?.apiKey,t[40]=i.alibaba?.model,t[41]=i.enabled,t[42]=i.fallback?.enabled,t[43]=i.openai?.apiKey,t[44]=i.openai?.model,t[45]=i.provider,t[46]=y,t[47]=s,t[48]=c,t[49]=u,t[50]=l,t[51]=n,t[52]=A):A=t[52];let j;t[53]!==k||t[54]!==A?(j=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[k,A]}),t[53]=k,t[54]=A,t[55]=j):j=t[55];let M;return t[56]!==j||t[57]!==C?(M=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[C,j]}),t[56]=j,t[57]=C,t[58]=M):M=t[58],M}function wa(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function Ta(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function Ea(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function Da(e){let t=(0,Q.c)(56),{v:n,apiKeyLabels:r,tts:i,models:a,ttsProviders:o,updateTts:s,updateTtsAlibaba:c,updateTtsOpenai:l,updateTtsEdge:u,updateTtsMinimax:d,updateTtsLocalCli:f}=e,p;t[0]===n?p=t[1]:(p=e=>e===`off`?n.tts.triggerDescOff:e===`always`?n.tts.triggerDescAlways:e===`inbound`?n.tts.triggerDescInbound:e===`tagged`?n.tts.triggerDescTagged:``,t[0]=n,t[1]=p);let m=p,h=a?.tts?.openai?.length?a.tts.openai:la,g=a?.ttsVoices?.openai?.length?a.ttsVoices.openai:ua,_=a?.tts?.alibaba?.length?a.tts.alibaba:da,v=a?.ttsVoices?.alibaba?.length?a.ttsVoices.alibaba:fa,y=a?.ttsVoices?.edge?.length?a.ttsVoices.edge:pa,b=a?.tts?.minimax?.length?a.tts.minimax:ma,x=a?.ttsVoices?.minimax?.length?a.ttsVoices.minimax:ha,S;if(t[2]!==i.provider||t[3]!==o){let e=new Set;S=[];for(let t of o)e.has(t.id)||(e.add(t.id),S.push(t));if(i.provider&&!e.has(i.provider)){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5];let n;t[6]===i.provider?n=t[7]:(n={id:i.provider,aliases:e,configured:!1},t[6]=i.provider,t[7]=n),S.push(n)}t[2]=i.provider,t[3]=o,t[4]=S}else S=t[4];let C=S,w;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(qt,{className:`size-4 text-accent`,strokeWidth:1.75}),t[8]=w):w=t[8];let T;t[9]===n.tts.title?T=t[10]:(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[w,n.tts.title]}),t[9]=n.tts.title,t[10]=T);let E;t[11]===n.tts.description?E=t[12]:(E=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.tts.description}),t[11]=n.tts.description,t[12]=E);let D;t[13]!==T||t[14]!==E?(D=(0,$.jsxs)(`div`,{className:`mb-4`,children:[T,E]}),t[13]=T,t[14]=E,t[15]=D):D=t[15];let O;t[16]===n.tts.enable?O=t[17]:(O=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.tts.enable}),t[16]=n.tts.enable,t[17]=O);let k;t[18]===n.tts.enableDesc?k=t[19]:(k=(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.tts.enableDesc}),t[18]=n.tts.enableDesc,t[19]=k);let A;t[20]!==O||t[21]!==k?(A=(0,$.jsxs)(`div`,{children:[O,k]}),t[20]=O,t[21]=k,t[22]=A):A=t[22];let j;t[23]===s?j=t[24]:(j=e=>s({enabled:e.target.checked}),t[23]=s,t[24]=j);let M;t[25]!==j||t[26]!==i.enabled?(M=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.enabled,onChange:j}),t[25]=j,t[26]=i.enabled,t[27]=M):M=t[27];let N;t[28]!==M||t[29]!==A?(N=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[A,M]}),t[28]=M,t[29]=A,t[30]=N):N=t[30];let P;t[31]!==r||t[32]!==C||t[33]!==m||t[34]!==i||t[35]!==_||t[36]!==b||t[37]!==h||t[38]!==v||t[39]!==y||t[40]!==x||t[41]!==g||t[42]!==s||t[43]!==c||t[44]!==u||t[45]!==f||t[46]!==d||t[47]!==l||t[48]!==n?(P=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.tts.trigger}),(0,$.jsxs)(`select`,{className:aa(),value:i.trigger,onChange:e=>s({trigger:e.target.value}),children:[(0,$.jsx)(`option`,{value:`off`,children:n.tts.triggerOff}),(0,$.jsx)(`option`,{value:`always`,children:n.tts.triggerAlways}),(0,$.jsx)(`option`,{value:`inbound`,children:n.tts.triggerInbound}),(0,$.jsx)(`option`,{value:`tagged`,children:n.tts.triggerTagged})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:m(i.trigger)})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.tts.provider}),(0,$.jsx)(`select`,{className:aa(),value:i.provider,onChange:e=>s({provider:e.target.value}),children:C.map(e=>(0,$.jsx)(`option`,{value:e.id,children:ya(e.id,n)},e.id))})]})]}),i.provider===`openai`||i.provider===`alibaba`||i.provider===`minimax`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.stt.apiKey}),(0,$.jsx)(_n,{kind:`tts`,providerId:i.provider,fieldId:`voice-tts-${i.provider}-api-key`,value:i.provider===`openai`?i.openai?.apiKey??``:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.minimax?.apiKey??``,onChange:e=>{i.provider===`openai`?l({apiKey:e}):i.provider===`alibaba`?c({apiKey:e}):d({apiKey:e})},labels:r,placeholder:i.provider===`minimax`?`eyJ...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,ra(i.provider)?` ${ra(i.provider)}`:``]})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.stt.model}),(0,$.jsx)(`select`,{className:aa(),value:i.provider===`openai`?i.openai?.model??``:i.provider===`alibaba`?i.alibaba?.model??``:i.minimax?.model??``,onChange:e=>{i.provider===`openai`?l({model:e.target.value}):i.provider===`alibaba`?c({model:e.target.value}):d({model:e.target.value})},children:(i.provider===`openai`?h:i.provider===`alibaba`?_:b).map(Aa)})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.tts.voice}),(0,$.jsx)(`select`,{className:aa(),value:i.provider===`openai`?i.openai?.voice??``:i.provider===`alibaba`?i.alibaba?.voice??``:i.minimax?.voice??``,onChange:e=>{i.provider===`openai`?l({voice:e.target.value}):i.provider===`alibaba`?c({voice:e.target.value}):d({voice:e.target.value})},children:(i.provider===`openai`?g:i.provider===`alibaba`?v:x).map(ka)})]})]}):null,i.provider===`edge`?(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,ta),children:[(0,$.jsx)(ja,{children:n.tts.voice}),(0,$.jsx)(`select`,{className:aa(),value:i.edge?.voice??``,onChange:e=>u({voice:e.target.value}),children:y.map(Oa)}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.edgeHint})]}):null,i.provider===`tts-local-cli`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(ja,{children:n.tts.localCli.command}),(0,$.jsx)(`input`,{className:J(ia(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:i[`tts-local-cli`]?.command??``,onChange:e=>f({command:e.target.value}),placeholder:n.tts.localCli.commandPlaceholder}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.commandDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(ja,{children:n.tts.localCli.cwd}),(0,$.jsx)(`input`,{className:J(ia(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:i[`tts-local-cli`]?.cwd??``,onChange:e=>f({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.cwdDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(ja,{children:n.tts.localCli.outputFormat}),(0,$.jsxs)(`select`,{className:aa(),value:i[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>f({outputFormat:e.target.value}),children:[(0,$.jsx)(`option`,{value:`wav`,children:`wav`}),(0,$.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,$.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.outputFormatDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(ja,{children:n.tts.localCli.timeoutMs}),(0,$.jsx)(`input`,{className:ia(),type:`number`,min:0,step:1e3,value:typeof i[`tts-local-cli`]?.timeoutMs==`number`?String(i[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){f({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&f({timeoutMs:n})},placeholder:`30000`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.timeoutMsDesc})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:n.tts.localCli.hint})]}):null]}):null,t[31]=r,t[32]=C,t[33]=m,t[34]=i,t[35]=_,t[36]=b,t[37]=h,t[38]=v,t[39]=y,t[40]=x,t[41]=g,t[42]=s,t[43]=c,t[44]=u,t[45]=f,t[46]=d,t[47]=l,t[48]=n,t[49]=P):P=t[49];let F;t[50]!==N||t[51]!==P?(F=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[N,P]}),t[50]=N,t[51]=P,t[52]=F):F=t[52];let I;return t[53]!==F||t[54]!==D?(I=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[D,F]}),t[53]=F,t[54]=D,t[55]=I):I=t[55],I}function Oa(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function ka(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function Aa(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function ja(e){let t=(0,Q.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function Ma(e){let t=e&&typeof e==`object`&&`tools`in e?e.tools:void 0,n=t&&typeof t==`object`&&`web`in t?t.web:void 0,r=n&&typeof n==`object`&&`region`in n?n.region:void 0,i=r===`cn`||r===`global`?r:`auto`,a=n&&typeof n==`object`&&`search`in n?n.search:void 0,o=a&&typeof a==`object`?a:{},s=typeof o.maxResults==`number`&&Number.isFinite(o.maxResults)?Math.floor(o.maxResults):5,c=n&&typeof n==`object`&&`blocklist`in n?n.blocklist:void 0,l=c&&typeof c==`object`?c:{},u=Array.isArray(l.domains)?l.domains.filter(e=>typeof e==`string`&&e.trim().length>0):[],d=o.providers;return{regionMode:i,maxResults:s,providers:Array.isArray(d)?d.map(e=>{let t=e&&typeof e==`object`?e:{},n=t.type;return{type:n===`brave`||n===`tavily`||n===`bing`||n===`searxng`?n:`brave`,apiKey:typeof t.apiKey==`string`?t.apiKey:``,url:typeof t.url==`string`?t.url:``,disabled:t.disabled===!0}}):[],blocklistEnabled:l.enabled===!0,blocklistDomains:u}}async function Na(e){let t=e.regionMode===`auto`?`auto`:e.regionMode===`cn`?`cn`:`global`,n={maxResults:e.maxResults,providers:e.providers.map(e=>{let t={type:e.type,apiKey:e.apiKey};return e.type===`searxng`&&e.url.trim()&&(t.url=e.url.trim().replace(/\/+$/,``)),e.disabled&&(t.disabled=!0),t})};await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),mt()}function Pa(e){let t=(0,Q.c)(8),{label:n,description:r,children:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}),t[2]=r,t[3]=o);let s;return t[4]!==i||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a,i,o]}),t[4]=i,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function Fa(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function Ia(){return J(w,Je)}var La=[`brave`,`tavily`,`bing`,`searxng`];function Ra(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var za=et();function Ba({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.webSearchSettings,i=n.logs,o=!!x(e=>e.token),[c,l]=(0,Z.useReducer)(za,{form:null,baseline:null}),u=c.form,d=c.baseline,[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(!1),y=(0,Z.useRef)(null),{data:b,error:S,isLoading:C,mutate:w}=Ze(o);Pt({enabled:o,parsed:(0,Z.useMemo)(()=>b?.payload?.config===void 0?null:Ma(b.payload.config),[b]),dirty:v.current,trackedParsedRef:y,dispatch:l,onResetDirty:()=>{v.current=!1}});let T=!!(o&&C&&b===void 0&&!S),E=S instanceof Error?S.message:S?String(S):null,D=(0,Z.useMemo)(()=>!u||!d?!1:JSON.stringify(u)!==JSON.stringify(d),[u,d]),O=(0,Z.useCallback)(e=>{v.current=!0,l({type:`patch`,patch:e})},[]),k=(0,Z.useCallback)(async()=>{if(!(!u||f)){p(!0),h(null),_(!1);try{await Na(u),v.current=!1,l({type:`saved`,value:u}),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:r.saveError)}finally{p(!1)}}},[u,f,r.saveError]),A=(0,Z.useCallback)(()=>{d&&(v.current=!1,l({type:`discard`}),h(null),_(!1))},[d]);yr({id:`search`,dirty:D,saving:f,save:k,discard:A});let j=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,M=e?`flex flex-col gap-3`:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`;return o?T?(0,$.jsxs)(`div`,{className:J(M,`items-center`),children:[(0,$.jsx)(q,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.loading})]}):u?(0,$.jsxs)(`div`,{className:j,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[e?(0,$.jsx)(`div`,{className:`min-w-0`,"aria-hidden":!0}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:r.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),(0,$.jsxs)(`a`,{href:Be(t,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[r.docsLink,(0,$.jsx)(Me,{className:`size-3.5`})]})]}),e?null:(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!D||f,onClick:A,children:r.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!D||f,onClick:()=>void k(),children:f?r.saving:r.save})]})]}),D&&!e?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:r.unsavedHint}):null,m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:pe,title:r.sectionRegion,subtitle:r.sectionRegionHint}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Pa,{label:r.regionLabel,description:r.regionDesc,children:(0,$.jsxs)(`select`,{className:Ia(),value:u.regionMode,onChange:e=>O({regionMode:e.target.value}),children:[(0,$.jsx)(`option`,{value:`auto`,children:r.regionAuto}),(0,$.jsx)(`option`,{value:`cn`,children:r.regionCn}),(0,$.jsx)(`option`,{value:`global`,children:r.regionGlobal})]})})})]}),(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:ct,title:r.sectionBlocklist,subtitle:r.sectionBlocklistHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:u.blocklistEnabled,onChange:e=>O({blocklistEnabled:e.target.checked})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:r.blocklistEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:r.blocklistEnabledDesc})]})]}),(0,$.jsx)(Pa,{label:r.blocklistDomains,description:r.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:J(Fa(),`min-h-[6rem] font-mono text-xs`),value:u.blocklistDomains.join(`
2
+ `),placeholder:r.blocklistDomainsPlaceholder,disabled:!u.blocklistEnabled,onChange:e=>{O({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]}),(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:pe,title:r.sectionSearch,subtitle:r.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Pa,{label:r.maxResultsLabel,description:r.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:Fa(),value:u.maxResults,onChange:e=>O({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.providersTitle}),u.providers.map((e,t)=>(0,$.jsx)(Va,{row:e,labels:r,onChange:e=>{let n=[...u.providers];n[t]=e,O({providers:n})},onRemove:()=>{O({providers:u.providers.filter((e,n)=>n!==t)})}},`${e.type}:${e.url}:${e.apiKey}:${e.disabled}`)),(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...u.providers,Ra()]}),children:[(0,$.jsx)(Re,{className:`size-4`}),r.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r.footerHint})]}):(0,$.jsxs)(`div`,{className:M,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??E??r.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>void w(),children:i.refresh})]}):(0,$.jsxs)(`div`,{className:M,children:[e?null:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})]})}function Va(e){let t=(0,Q.c)(49),{row:n,labels:r,onChange:i,onRemove:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=J(Ia(),`min-w-[8rem]`),t[0]=o):o=t[0];let s=n.type,c;t[1]!==i||t[2]!==n?(c=e=>i({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[1]=i,t[2]=n,t[3]=c):c=t[3];let l;t[4]===r.providerTypes?l=t[5]:(l=La.map(e=>(0,$.jsx)(`option`,{value:e,children:r.providerTypes[e]},e)),t[4]=r.providerTypes,t[5]=l);let u;t[6]!==n.type||t[7]!==c||t[8]!==l?(u=(0,$.jsx)(`select`,{className:o,value:s,onChange:c,children:l}),t[6]=n.type,t[7]=c,t[8]=l,t[9]=u):u=t[9];let d;t[10]!==i||t[11]!==n?(d=e=>i({...n,disabled:e.target.checked}),t[10]=i,t[11]=n,t[12]=d):d=t[12];let f;t[13]!==n.disabled||t[14]!==d?(f=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:d}),t[13]=n.disabled,t[14]=d,t[15]=f):f=t[15];let p;t[16]!==r.disabled||t[17]!==f?(p=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[f,r.disabled]}),t[16]=r.disabled,t[17]=f,t[18]=p):p=t[18];let m;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Lt,{className:`size-4`}),t[19]=m):m=t[19];let h;t[20]===a?h=t[21]:(h=(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:a,children:m}),t[20]=a,t[21]=h);let g;t[22]!==h||t[23]!==p?(g=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p,h]}),t[22]=h,t[23]=p,t[24]=g):g=t[24];let _;t[25]!==g||t[26]!==u?(_=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[u,g]}),t[25]=g,t[26]=u,t[27]=_):_=t[27];let v;t[28]!==r.urlDesc||t[29]!==r.urlLabel||t[30]!==i||t[31]!==n?(v=n.type===`searxng`?(0,$.jsx)(Pa,{label:r.urlLabel,description:r.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:Fa(),value:n.url,placeholder:`http://localhost:8080`,onChange:e=>i({...n,url:e.target.value})})}):null,t[28]=r.urlDesc,t[29]=r.urlLabel,t[30]=i,t[31]=n,t[32]=v):v=t[32];let y=r.apiKeyLabel,b=r.apiKeyDesc,x;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(x=Fa(),t[33]=x):x=t[33];let S=Oe(n.apiKey)?``:n.apiKey,C=Oe(n.apiKey)?r.keyPlaceholderMasked:r.keyPlaceholder,w;t[34]!==i||t[35]!==n?(w=e=>i({...n,apiKey:e.target.value}),t[34]=i,t[35]=n,t[36]=w):w=t[36];let T;t[37]!==S||t[38]!==C||t[39]!==w?(T=(0,$.jsx)(`input`,{type:`password`,autoComplete:`off`,className:x,value:S,placeholder:C,onChange:w}),t[37]=S,t[38]=C,t[39]=w,t[40]=T):T=t[40];let E;t[41]!==r.apiKeyDesc||t[42]!==r.apiKeyLabel||t[43]!==T?(E=(0,$.jsx)(Pa,{label:y,description:b,children:T}),t[41]=r.apiKeyDesc,t[42]=r.apiKeyLabel,t[43]=T,t[44]=E):E=t[44];let D;return t[45]!==_||t[46]!==v||t[47]!==E?(D=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[_,v,E]}),t[45]=_,t[46]=v,t[47]=E,t[48]=D):D=t[48],D}var Ha=[`providers`,`models`,`image-models`,`voice`,`search`];function Ua(e){let t=(e??``).trim();return Ha.includes(t)?t:`providers`}var Wa=[{id:`providers`,icon:It,labelKey:`providers`,hintKey:`providersHint`},{id:`models`,icon:Ce,labelKey:`models`,hintKey:`modelsHint`},{id:`image-models`,icon:vt,labelKey:`image-models`,hintKey:`imageHint`},{id:`voice`,icon:Te,labelKey:`voice`,hintKey:`voiceHint`},{id:`search`,icon:pe,labelKey:`search`,hintKey:`searchHint`}];function Ga(){let e=(0,Q.c)(60),t=a(Ka),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n,i=r.settingsSections,o=r.modelsHub,[c,l]=ot(),u;e[2]===c?u=e[3]:(u=Ua(c.get(`tab`)),e[2]=c,e[3]=u);let d=u,f;e[4]===l?f=e[5]:(f=e=>{l(t=>{let n=new URLSearchParams(t);return e===`providers`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},e[4]=l,e[5]=f);let p=f,m;e[6]===i.credentials?m=e[7]:(m=(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:i.credentials}),e[6]=i.credentials,e[7]=m);let h;e[8]===o.subtitle?h=e[9]:(h=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:o.subtitle}),e[8]=o.subtitle,e[9]=h);let g;e[10]===t?g=e[11]:(g=Be(t,`configuration`),e[10]=t,e[11]=g);let _;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(Me,{className:`size-3.5`}),e[12]=_):_=e[12];let v;e[13]!==o.docsLink||e[14]!==g?(v=(0,$.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[o.docsLink,_]}),e[13]=o.docsLink,e[14]=g,e[15]=v):v=e[15];let y;e[16]!==m||e[17]!==h||e[18]!==v?(y=(0,$.jsx)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[m,h,v]})}),e[16]=m,e[17]=h,e[18]=v,e[19]=y):y=e[19];let b;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Ji,{}),e[20]=b):b=e[20];let x=o.tabsAria,S;e[21]!==d||e[22]!==p?(S=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=Ha.indexOf(d),n=e.key===`ArrowRight`?1:-1,r=Ha.length;p(Ha[(t+n+r)%r])},e[21]=d,e[22]=p,e[23]=S):S=e[23];let C;e[24]!==d||e[25]!==i||e[26]!==p?(C=Wa.map(e=>{let{id:t,icon:n,labelKey:r}=e,a=t===d;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,id:`hub-tab-${t}`,"aria-controls":`hub-panel-${t}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>p(t),children:[(0,$.jsx)(n,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:i[r]})]},t)}),e[24]=d,e[25]=i,e[26]=p,e[27]=C):C=e[27];let w;e[28]!==o.tabsAria||e[29]!==S||e[30]!==C?(w=(0,$.jsx)(`div`,{className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,"aria-label":x,onKeyDown:S,children:C}),e[28]=o.tabsAria,e[29]=S,e[30]=C,e[31]=w):w=e[31];let T;e[32]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Gi,{embedded:!0}),e[32]=T):T=e[32];let E;e[33]!==d||e[34]!==o.providersHint?(E=(0,$.jsx)(qa,{id:`providers`,activeTab:d,hint:o.providersHint,children:T}),e[33]=d,e[34]=o.providersHint,e[35]=E):E=e[35];let D;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(Si,{embedded:!0}),e[36]=D):D=e[36];let O;e[37]!==d||e[38]!==o.modelsHint?(O=(0,$.jsx)(qa,{id:`models`,activeTab:d,hint:o.modelsHint,children:D}),e[37]=d,e[38]=o.modelsHint,e[39]=O):O=e[39];let k;e[40]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(zr,{embedded:!0}),e[40]=k):k=e[40];let A;e[41]!==d||e[42]!==o.imageHint?(A=(0,$.jsx)(qa,{id:`image-models`,activeTab:d,hint:o.imageHint,children:k}),e[41]=d,e[42]=o.imageHint,e[43]=A):A=e[43];let j;e[44]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(Sa,{embedded:!0}),e[44]=j):j=e[44];let M;e[45]!==d||e[46]!==o.voiceHint?(M=(0,$.jsx)(qa,{id:`voice`,activeTab:d,hint:o.voiceHint,children:j}),e[45]=d,e[46]=o.voiceHint,e[47]=M):M=e[47];let N;e[48]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(Ba,{embedded:!0}),e[48]=N):N=e[48];let P;e[49]!==d||e[50]!==o.searchHint?(P=(0,$.jsx)(qa,{id:`search`,activeTab:d,hint:o.searchHint,children:N}),e[49]=d,e[50]=o.searchHint,e[51]=P):P=e[51];let F;return e[52]!==w||e[53]!==E||e[54]!==O||e[55]!==A||e[56]!==M||e[57]!==P||e[58]!==y?(F=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[y,b,w,E,O,A,M,P]}),e[52]=w,e[53]=E,e[54]=O,e[55]=A,e[56]=M,e[57]=P,e[58]=y,e[59]=F):F=e[59],F}function Ka(e){return e.language}function qa({id:e,activeTab:t,hint:n,children:r}){let i=e===t,a=(0,Z.useRef)(i);return i&&(a.current=!0),a.current?(0,$.jsxs)(`div`,{role:`tabpanel`,id:`hub-panel-${e}`,"aria-labelledby":`hub-tab-${e}`,hidden:!i,className:J(i?`flex min-w-0 flex-col gap-3`:void 0),children:[i?(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n}):null,r]}):null}function Ja(){return J(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var Ya={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}},clay:{light:{canvas:`#fffaf0`,panel:`#ffffff`,accent:`#1a3a3a`,fg:`#0a0a0a`,muted:`#e5e5e5`},dark:{canvas:`#0a1a1a`,panel:`#1a2a2a`,accent:`#ffb084`,fg:`#fffaf0`,muted:`#2a3a3a`}}};function Xa(e){let t=(0,Q.c)(24),{canvas:n,panel:r,accent:i,fg:a,muted:o}=e,s;t[0]===n?s=t[1]:(s={backgroundColor:n},t[0]=n,t[1]=s);let c;t[2]!==o||t[3]!==r?(c={backgroundColor:r,borderColor:o},t[2]=o,t[3]=r,t[4]=c):c=t[4];let l;t[5]===i?l=t[6]:(l=(0,$.jsx)(`div`,{className:`size-1 shrink-0 rounded-full`,style:{backgroundColor:i}}),t[5]=i,t[6]=l);let u;t[7]===a?u=t[8]:(u=(0,$.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:a,opacity:.85}}),t[7]=a,t[8]=u);let d;t[9]!==l||t[10]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11];let f;t[12]===o?f=t[13]:(f=(0,$.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:o}}),t[12]=o,t[13]=f);let p;t[14]===o?p=t[15]:(p=(0,$.jsx)(`div`,{className:`size-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:o}}),t[14]=o,t[15]=p);let m;t[16]!==c||t[17]!==d||t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:c,children:[d,f,p]}),t[16]=c,t[17]=d,t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==s||t[22]!==m?(h=(0,$.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:s,children:m}),t[21]=s,t[22]=m,t[23]=h):h=t[23],h}function Za(e){let t=(0,Q.c)(8),{scheme:n}=e,{light:r,dark:i}=Ya[n],a;t[0]===r?a=t[1]:(a=(0,$.jsx)(Xa,{...r}),t[0]=r,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),t[2]=o):o=t[2];let s;t[3]===i?s=t[4]:(s=(0,$.jsx)(Xa,{...i}),t[3]=i,t[4]=s);let c;return t[5]!==a||t[6]!==s?(c=(0,$.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[a,o,s]}),t[5]=a,t[6]=s,t[7]=c):c=t[7],c}var Qa=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`},{value:`clay`,labelKey:`colorSchemeClay`}];function $a(){let e=(0,Q.c)(18),t=a(no),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i=b(to),o=b(eo),c;e[2]===r.colorSchemeTitle?c=e[3]:(c=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r.colorSchemeTitle}),e[2]=r.colorSchemeTitle,e[3]=c);let l;e[4]===r.colorSchemeDescription?l=e[5]:(l=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:r.colorSchemeDescription}),e[4]=r.colorSchemeDescription,e[5]=l);let u;e[6]!==c||e[7]!==l?(u=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[c,l]}),e[6]=c,e[7]=l,e[8]=u):u=e[8];let d;e[9]!==r||e[10]!==i||e[11]!==o?(d=Qa.map(e=>{let{value:t,labelKey:n}=e,a=i===t;return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>o(t),className:J(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow,transform] duration-150`,X.pressCard,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,$.jsx)(Za,{scheme:t}),(0,$.jsx)(`span`,{className:J(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:r[n]})]},t)}),e[9]=r,e[10]=i,e[11]=o,e[12]=d):d=e[12];let f;e[13]===d?f=e[14]:(f=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:d}),e[13]=d,e[14]=f);let p;return e[15]!==u||e[16]!==f?(p=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-edge-subtle py-3.5 last:border-b-0 sm:py-4`,children:[u,f]}),e[15]=u,e[16]=f,e[17]=p):p=e[17],p}function eo(e){return e.setColorScheme}function to(e){return e.colorScheme}function no(e){return e.language}function ro(){let e=(0,Q.c)(27),t=a(oo),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i=Ht(ao),o=Ht(io),c;e[2]===r.developerGroupTitle?c=e[3]:(c=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r.developerGroupTitle}),e[2]=r.developerGroupTitle,e[3]=c);let l;e[4]===r.developerGroupDescription?l=e[5]:(l=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:r.developerGroupDescription}),e[4]=r.developerGroupDescription,e[5]=l);let u;e[6]!==c||e[7]!==l?(u=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[c,l]}),e[6]=c,e[7]=l,e[8]=u):u=e[8];let d;e[9]===r.showRawToolDataTitle?d=e[10]:(d=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.showRawToolDataTitle}),e[9]=r.showRawToolDataTitle,e[10]=d);let f;e[11]===r.showRawToolDataDescription?f=e[12]:(f=(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.showRawToolDataDescription}),e[11]=r.showRawToolDataDescription,e[12]=f);let p;e[13]!==d||e[14]!==f?(p=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[d,f]}),e[13]=d,e[14]=f,e[15]=p):p=e[15];let m;e[16]===o?m=e[17]:(m=e=>o(e.target.checked),e[16]=o,e[17]=m);let h;e[18]!==i||e[19]!==m?(h=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i,onChange:m}),e[18]=i,e[19]=m,e[20]=h):h=e[20];let g;e[21]!==p||e[22]!==h?(g=(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[p,h]}),e[21]=p,e[22]=h,e[23]=g):g=e[23];let _;return e[24]!==u||e[25]!==g?(_=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 py-3.5 sm:py-4`,children:[u,g]}),e[24]=u,e[25]=g,e[26]=_):_=e[26],_}function io(e){return e.setShowRawToolData}function ao(e){return e.showRawToolData}function oo(e){return e.language}function so(){let e=(0,Q.c)(33),t=a(co),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i;e[2]===r.pageTitle?i=e[3]:(i=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.pageTitle}),e[2]=r.pageTitle,e[3]=i);let o;e[4]===r.subtitle?o=e[5]:(o=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=o);let c;e[6]!==i||e[7]!==o?(c=(0,$.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[i,o]}),e[6]=i,e[7]=o,e[8]=c):c=e[8];let l;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=Ja(),e[9]=l):l=e[9];let u;e[10]===r.languageTitle?u=e[11]:(u=(0,$.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:r.languageTitle}),e[10]=r.languageTitle,e[11]=u);let d;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(Bt,{variant:`page`,sections:[`language`]}),e[12]=d):d=e[12];let f;e[13]===u?f=e[14]:(f=(0,$.jsxs)(`section`,{className:l,"aria-labelledby":`pref-language-heading`,children:[u,d]}),e[13]=u,e[14]=f);let p;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(p=Ja(),e[15]=p):p=e[15];let m;e[16]===r.themeTitle?m=e[17]:(m=(0,$.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:r.themeTitle}),e[16]=r.themeTitle,e[17]=m);let h,g;e[18]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Bt,{variant:`page`,sections:[`theme`,`font`]}),g=(0,$.jsx)($a,{}),e[18]=h,e[19]=g):(h=e[18],g=e[19]);let _;e[20]===m?_=e[21]:(_=(0,$.jsxs)(`section`,{className:p,"aria-labelledby":`pref-appearance-heading`,children:[m,h,g]}),e[20]=m,e[21]=_);let v;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(v=Ja(),e[22]=v):v=e[22];let y;e[23]===r.developerGroupTitle?y=e[24]:(y=(0,$.jsx)(`h2`,{id:`pref-developer-heading`,className:`sr-only`,children:r.developerGroupTitle}),e[23]=r.developerGroupTitle,e[24]=y);let b;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(ro,{}),e[25]=b):b=e[25];let x;e[26]===y?x=e[27]:(x=(0,$.jsxs)(`section`,{className:v,"aria-labelledby":`pref-developer-heading`,children:[y,b]}),e[26]=y,e[27]=x);let S;return e[28]!==_||e[29]!==x||e[30]!==c||e[31]!==f?(S=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[c,f,_,x]}),e[28]=_,e[29]=x,e[30]=c,e[31]=f,e[32]=S):S=e[32],S}function co(e){return e.language}function lo(){return l(`/api/dreaming`)}async function uo(){let e=await S(lo());if(!e.payload)throw Error(`Missing payload`);return e.payload}async function fo(e){await S(l(`/api/dreaming/action`),{method:`POST`,body:JSON.stringify({action:e})})}async function po(e=`deep`){let t=await S(l(`/api/dreaming/run`),{method:`POST`,body:JSON.stringify({phase:e})}),n=!!t.payload?.triggered,r=typeof t.payload?.jobId==`string`?t.payload.jobId:``;if(!n||!r)throw Error(`Failed to trigger`);return{triggered:n,jobId:r,phase:e}}async function mo(e){let t=await S(l(`/api/dreaming/preview${typeof e==`number`&&Number.isFinite(e)?`?limit=${encodeURIComponent(String(e))}`:``}`));if(!t.payload)throw Error(`Missing payload`);return t.payload}async function ho(e=50){return(await S(l(`/api/dreaming/events${`?limit=${encodeURIComponent(String(e))}`}`))).payload?.events??[]}function go(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var _o={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},vo={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},yo={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},bo={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:_o,deep:vo,rem:yo};function xo(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function So(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Co(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function wo(e){let t=go(e)?e:{},n=go(t.agents)?t.agents:{},r=go(n.defaults)?n.defaults:{},i=go(r.memory)?r.memory:{},a=go(i.dreaming)?i.dreaming:{},o=go(a.phases)?a.phases:{},s=go(o.light)?o.light:{},c=go(o.deep)?o.deep:{},l=go(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():bo.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:xo(typeof c.minScore==`number`?c.minScore:Number(c.minScore),bo.minScore),minRecallCount:Math.max(1,So(c.minRecallCount,bo.minRecallCount)),limit:So(c.limit,bo.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():_o.cron,lookbackDays:Math.max(1,So(s.lookbackDays,_o.lookbackDays)),limit:So(s.limit,_o.limit),dedupeSimilarity:xo(Co(s.dedupeSimilarity,_o.dedupeSimilarity),_o.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():vo.cron,minScore:xo(Co(c.minScore,vo.minScore),vo.minScore),minRecallCount:Math.max(1,So(c.minRecallCount,vo.minRecallCount)),limit:So(c.limit,vo.limit),recencyHalfLifeDays:Math.max(1,Co(c.recencyHalfLifeDays,vo.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Co(c.maxAgeDays,vo.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():yo.cron,lookbackDays:Math.max(1,So(l.lookbackDays,yo.lookbackDays)),limit:So(l.limit,yo.limit),minPatternStrength:xo(Co(l.minPatternStrength,yo.minPatternStrength),yo.minPatternStrength)}}}async function To(e){let t=e.frequency.trim(),n=e.timezone.trim();await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:{memory:{dreaming:{enabled:!!e.enabled,frequency:t||null,timezone:n||null,phases:{light:{enabled:!!e.light.enabled,cron:e.light.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.light.lookbackDays)),limit:Math.max(0,Math.floor(e.light.limit)),dedupeSimilarity:xo(e.light.dedupeSimilarity,_o.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:xo(e.deep.minScore,vo.minScore),minRecallCount:Math.max(1,Math.floor(e.deep.minRecallCount)),limit:Math.max(0,Math.floor(e.deep.limit)),recencyHalfLifeDays:Math.max(1,e.deep.recencyHalfLifeDays),maxAgeDays:Math.max(1,e.deep.maxAgeDays)},rem:{enabled:!!e.rem.enabled,cron:e.rem.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.rem.lookbackDays)),limit:Math.max(0,Math.floor(e.rem.limit)),minPatternStrength:xo(e.rem.minPatternStrength,yo.minPatternStrength)}}}}}}})}),mt()}var Eo=`p-4 sm:px-5`,Do=`mb-3`,Oo=`rounded-xl border border-edge-subtle bg-surface-panel/30 p-3 sm:p-4`,ko=J(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,He);function Ao(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function jo(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Mo(e,t){return e.locked?{text:t.lockValueLocked,className:`text-amber-600 dark:text-amber-400`}:{text:t.lockValueUnlocked,className:`text-emerald-600 dark:text-emerald-400`}}var No=J(`h-9 min-w-0 flex-1 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm tabular-nums text-fg`,He),Po=J(w,`h-9 max-w-[11rem] shrink-0 text-xs sm:max-w-[12rem]`);function Fo(e,t){switch(e){case 3e4:return t.every30s;case 6e4:return t.every1min;case 3e5:return t.every5min;case 6e5:return t.every10min;case 9e5:return t.every15min;case 18e5:return t.every30min;case 36e5:return t.every1h;case 72e5:return t.every2h;default:return String(e)}}function Io({valueMs:e,onChangeMs:t,labels:n,disabled:r,presets:i=Dn,minSeconds:a=1}){let o=(0,Z.useMemo)(()=>new Set(i),[i]),s=(0,Z.useMemo)(()=>o.has(e)?String(e):``,[o,e]),[c,l]=(0,Z.useState)(null),u=(0,Z.useRef)(e);u.current!==e&&(u.current=e,l(null));let d=Math.max(a,Math.round(e/1e3)),f=c===null?String(d):c;return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.secondsLabel}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`number`,min:a,step:1,disabled:r,className:No,value:f,onChange:e=>{let n=e.target.value;l(n);let r=parseInt(n,10);Number.isFinite(r)&&r>=a&&t(r*1e3)},onBlur:()=>{if(c===null)return;let e=parseInt(c,10);t(!Number.isFinite(e)||e<a?a*1e3:e*1e3),l(null)}}),(0,$.jsxs)(`select`,{className:Po,disabled:r,value:s,onChange:e=>{let n=e.target.value;n&&(t(parseInt(n,10)),l(null))},children:[(0,$.jsx)(`option`,{value:``,children:n.presets.custom}),i.map(e=>(0,$.jsx)(`option`,{value:String(e),children:Fo(e,n.presets)},e))]})]})]})}var Lo=J(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,He),Ro=()=>({start:`09:00`,end:`22:00`,timezone:``});function zo(e){let t=(0,Q.c)(55),{value:n,onChange:r,labels:i,disabled:a}=e;if(!n){let e;t[0]===r?e=t[1]:(e=()=>r(Ro()),t[0]=r,t[1]=e);let n;return t[2]!==a||t[3]!==i.add||t[4]!==e?(n=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`text-sm`,disabled:a,onClick:e,children:i.add}),t[2]=a,t[3]=i.add,t[4]=e,t[5]=n):n=t[5],n}let o;t[6]===i.start?o=t[7]:(o=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.start}),t[6]=i.start,t[7]=o);let s;t[8]!==r||t[9]!==n?(s=e=>r({...n,start:e.target.value}),t[8]=r,t[9]=n,t[10]=s):s=t[10];let c;t[11]!==a||t[12]!==s||t[13]!==n.start?(c=(0,$.jsx)(`input`,{type:`time`,step:60,disabled:a,className:Lo,value:n.start,onChange:s}),t[11]=a,t[12]=s,t[13]=n.start,t[14]=c):c=t[14];let l;t[15]!==o||t[16]!==c?(l=(0,$.jsxs)(`label`,{className:`block min-w-0`,children:[o,c]}),t[15]=o,t[16]=c,t[17]=l):l=t[17];let u;t[18]===i.end?u=t[19]:(u=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.end}),t[18]=i.end,t[19]=u);let d;t[20]!==r||t[21]!==n?(d=e=>r({...n,end:e.target.value}),t[20]=r,t[21]=n,t[22]=d):d=t[22];let f;t[23]!==a||t[24]!==d||t[25]!==n.end?(f=(0,$.jsx)(`input`,{type:`time`,step:60,disabled:a,className:Lo,value:n.end,onChange:d}),t[23]=a,t[24]=d,t[25]=n.end,t[26]=f):f=t[26];let p;t[27]!==u||t[28]!==f?(p=(0,$.jsxs)(`label`,{className:`block min-w-0`,children:[u,f]}),t[27]=u,t[28]=f,t[29]=p):p=t[29];let m;t[30]===i.timezone?m=t[31]:(m=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.timezone}),t[30]=i.timezone,t[31]=m);let h;t[32]!==r||t[33]!==n?(h=e=>r({...n,timezone:e.target.value}),t[32]=r,t[33]=n,t[34]=h):h=t[34];let g;t[35]!==a||t[36]!==h||t[37]!==n.timezone?(g=(0,$.jsx)(`input`,{type:`text`,disabled:a,className:Lo,value:n.timezone,onChange:h,placeholder:`Asia/Shanghai`,autoComplete:`off`}),t[35]=a,t[36]=h,t[37]=n.timezone,t[38]=g):g=t[38];let _;t[39]!==g||t[40]!==m?(_=(0,$.jsxs)(`label`,{className:`block min-w-0`,children:[m,g]}),t[39]=g,t[40]=m,t[41]=_):_=t[41];let v;t[42]!==_||t[43]!==l||t[44]!==p?(v=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[l,p,_]}),t[42]=_,t[43]=l,t[44]=p,t[45]=v):v=t[45];let y;t[46]===r?y=t[47]:(y=()=>r(null),t[46]=r,t[47]=y);let b;t[48]!==a||t[49]!==i.clear||t[50]!==y?(b=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:a,onClick:y,children:i.clear}),t[48]=a,t[49]=i.clear,t[50]=y,t[51]=b):b=t[51];let x;return t[52]!==v||t[53]!==b?(x=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[v,b]}),t[52]=v,t[53]=b,t[54]=x):x=t[54],x}function Bo(e){let t=(0,Q.c)(34),{disabled:n,label:r,hint:i,className:a}=e,o;t[0]===a?o=t[1]:(o=J(`flex flex-col gap-2`,a),t[0]=a,t[1]=o);let s;t[2]===r?s=t[3]:(s=r?(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r}):null,t[2]=r,t[3]=s);let c;t[4]!==n||t[5]!==r||t[6]!==e.kind||t[7]!==e.labels||t[8]!==e.onChange||t[9]!==e.value?(c=e.kind===`cron`?(0,$.jsx)(qn,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:n,showHeading:!r}):null,t[4]=n,t[5]=r,t[6]=e.kind,t[7]=e.labels,t[8]=e.onChange,t[9]=e.value,t[10]=c):c=t[10];let l;t[11]!==n||t[12]!==e.kind||t[13]!==e.labels||t[14]!==e.minSeconds||t[15]!==e.onChangeMs||t[16]!==e.presets||t[17]!==e.valueMs?(l=e.kind===`interval`?(0,$.jsx)(Io,{valueMs:e.valueMs,onChangeMs:e.onChangeMs,labels:e.labels,disabled:n,presets:e.presets??Dn,minSeconds:e.minSeconds}):null,t[11]=n,t[12]=e.kind,t[13]=e.labels,t[14]=e.minSeconds,t[15]=e.onChangeMs,t[16]=e.presets,t[17]=e.valueMs,t[18]=l):l=t[18];let u;t[19]!==n||t[20]!==e.kind||t[21]!==e.labels||t[22]!==e.onChange||t[23]!==e.value?(u=e.kind===`active-hours`?(0,$.jsx)(zo,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:n}):null,t[19]=n,t[20]=e.kind,t[21]=e.labels,t[22]=e.onChange,t[23]=e.value,t[24]=u):u=t[24];let d;t[25]===i?d=t[26]:(d=i?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:i}):null,t[25]=i,t[26]=d);let f;return t[27]!==o||t[28]!==s||t[29]!==c||t[30]!==l||t[31]!==u||t[32]!==d?(f=(0,$.jsxs)(`div`,{className:o,children:[s,c,l,u,d]}),t[27]=o,t[28]=s,t[29]=c,t[30]=l,t[31]=u,t[32]=d,t[33]=f):f=t[33],f}var Vo=`text-xs font-medium text-fg-muted`,Ho=`text-sm font-medium text-fg`;function Uo(e){let t=(0,Q.c)(6),{label:n,children:r,className:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{className:Vo,children:n}),t[0]=n,t[1]=a);let o;return t[2]!==r||t[3]!==i||t[4]!==a?(o=(0,$.jsxs)(`div`,{className:i,children:[a,r]}),t[2]=r,t[3]=i,t[4]=a,t[5]=o):o=t[5],o}function Wo(e){let t=(0,Q.c)(11),{label:n,children:r,className:i}=e,a;t[0]===i?a=t[1]:(a=J(`min-w-0`,i),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=(0,$.jsx)(`dt`,{className:Vo,children:n}),t[2]=n,t[3]=o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=J(Ho,`mt-0.5`),t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=(0,$.jsx)(`dd`,{className:s,children:r}),t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==o||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:a,children:[o,c]}),t[7]=a,t[8]=o,t[9]=c,t[10]=l):l=t[10],l}function Go(e){let t=(0,Q.c)(5),{label:n,className:r}=e,i;t[0]===r?i=t[1]:(i=J(`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`h3`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function Ko(e){let t=(0,Q.c)(38),{icon:n,title:r,hint:i,enabled:a,onEnabledChange:o,cron:s,onCronChange:c,scheduleLabels:l,disabled:u,onLabel:d,offLabel:f,cronLabel:p,children:m}=e,h;t[0]===n?h=t[1]:(h=(0,$.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:n}),t[0]=n,t[1]=h);let g;t[2]===r?g=t[3]:(g=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=g);let _;t[4]===i?_=t[5]:(_=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs leading-snug text-fg-muted`,children:i}),t[4]=i,t[5]=_);let v;t[6]!==g||t[7]!==_?(v=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[g,_]}),t[6]=g,t[7]=_,t[8]=v):v=t[8];let y;t[9]!==h||t[10]!==v?(y=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[h,v]}),t[9]=h,t[10]=v,t[11]=y):y=t[11];let b;t[12]===o?b=t[13]:(b=e=>o(e.target.checked),t[12]=o,t[13]=b);let x;t[14]!==u||t[15]!==a||t[16]!==b?(x=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:a,disabled:u,onChange:b}),t[14]=u,t[15]=a,t[16]=b,t[17]=x):x=t[17];let S=a?d:f,C;t[18]===S?C=t[19]:(C=(0,$.jsx)(`span`,{children:S}),t[18]=S,t[19]=C);let w;t[20]!==x||t[21]!==C?(w=(0,$.jsxs)(`label`,{className:`inline-flex shrink-0 items-center gap-2 text-xs text-fg`,children:[x,C]}),t[20]=x,t[21]=C,t[22]=w):w=t[22];let T;t[23]!==w||t[24]!==y?(T=(0,$.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-start justify-between gap-2 border-b border-edge-subtle/80 pb-2.5`,children:[y,w]}),t[23]=w,t[24]=y,t[25]=T):T=t[25];let E;t[26]!==s||t[27]!==p||t[28]!==u||t[29]!==c||t[30]!==l?(E=(0,$.jsx)(Bo,{kind:`cron`,className:`mb-2.5`,label:p,value:s,onChange:c,labels:l,disabled:u}),t[26]=s,t[27]=p,t[28]=u,t[29]=c,t[30]=l,t[31]=E):E=t[31];let D;t[32]===m?D=t[33]:(D=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4`,children:m}),t[32]=m,t[33]=D);let O;return t[34]!==T||t[35]!==E||t[36]!==D?(O=(0,$.jsxs)(`div`,{className:Oo,children:[T,E,D]}),t[34]=T,t[35]=E,t[36]=D,t[37]=O):O=t[37],O}function qo(e){let t=(0,Q.c)(23),{icon:n,label:r,enabled:i,cron:a,scheduleSummary:o,details:s,t:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(Oo,`space-y-1`),t[0]=l):l=t[0];let u;t[1]===r?u=t[2]:(u=(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r}),t[1]=r,t[2]=u);let d=i?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`,f;t[3]===d?f=t[4]:(f=J(`ml-auto text-xs font-medium`,d),t[3]=d,t[4]=f);let p=i?c.on:c.off,m;t[5]!==f||t[6]!==p?(m=(0,$.jsx)(`span`,{className:f,children:p}),t[5]=f,t[6]=p,t[7]=m):m=t[7];let h;t[8]!==n||t[9]!==u||t[10]!==m?(h=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,u,m]}),t[8]=n,t[9]=u,t[10]=m,t[11]=h):h=t[11];let g;t[12]===o?g=t[13]:(g=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:o}),t[12]=o,t[13]=g);let _;t[14]===a?_=t[15]:(_=(0,$.jsx)(`p`,{className:`truncate font-mono text-[0.65rem] text-fg-subtle`,title:a,children:a}),t[14]=a,t[15]=_);let v;t[16]===s?v=t[17]:(v=(0,$.jsx)(`p`,{className:`text-[0.65rem] leading-snug text-fg-muted`,children:s}),t[16]=s,t[17]=v);let y;return t[18]!==v||t[19]!==h||t[20]!==g||t[21]!==_?(y=(0,$.jsxs)(`div`,{className:l,children:[h,g,_,v]}),t[18]=v,t[19]=h,t[20]=g,t[21]=_,t[22]=y):y=t[22],y}function Jo(e){let t=(0,Q.c)(9),{label:n,lastRun:r,t:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(Go,{label:n,className:`mb-2`}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==i.lastRunRaw||t[4]!==i.phaseLastRunEmpty?(o=r?.exists?(0,$.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,$.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:i.lastRunRaw})}),(0,$.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.raw,null,2)})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.phaseLastRunEmpty}),t[2]=r,t[3]=i.lastRunRaw,t[4]=i.phaseLastRunEmpty,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle/80 pt-3`,children:[a,o]}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s}function Yo(e){let t=(0,Q.c)(39),{t:n,r}=e,i=r.deep?.skipped,a=r.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`,o=r.ok?n.lastRunSuccess:n.lastRunFailure,s;t[0]!==a||t[1]!==o?(s=(0,$.jsx)(`span`,{className:a,children:o}),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c;t[3]!==n.lastRunStatus||t[4]!==s?(c=(0,$.jsx)(Wo,{label:n.lastRunStatus,children:s}),t[3]=n.lastRunStatus,t[4]=s,t[5]=c):c=t[5];let l=n.lastRunDuration,u;t[6]===r.durationMs?u=t[7]:(u=jo(r.durationMs),t[6]=r.durationMs,t[7]=u);let d;t[8]!==n.lastRunDuration||t[9]!==u?(d=(0,$.jsx)(Wo,{label:l,children:u}),t[8]=n.lastRunDuration,t[9]=u,t[10]=d):d=t[10];let f=n.lastRunRanked,p=String(r.deep?.candidatesRanked??`—`),m;t[11]!==n.lastRunRanked||t[12]!==p?(m=(0,$.jsx)(Wo,{label:f,children:p}),t[11]=n.lastRunRanked,t[12]=p,t[13]=m):m=t[13];let h=n.lastRunApplied,g=String(r.deep?.applied??`—`),_;t[14]!==n.lastRunApplied||t[15]!==g?(_=(0,$.jsx)(Wo,{label:h,children:g}),t[14]=n.lastRunApplied,t[15]=g,t[16]=_):_=t[16];let v;t[17]===r.reason?v=t[18]:(v=(0,$.jsx)(`span`,{className:`block text-pretty`,children:r.reason}),t[17]=r.reason,t[18]=v);let y;t[19]!==r.errorMessage||t[20]!==n.lastRunError?(y=r.errorMessage?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-amber-600 dark:text-amber-400`,children:`${n.lastRunError}: ${r.errorMessage}`}):null,t[19]=r.errorMessage,t[20]=n.lastRunError,t[21]=y):y=t[21];let b;t[22]!==n.lastRunReason||t[23]!==v||t[24]!==y?(b=(0,$.jsxs)(Wo,{label:n.lastRunReason,className:`col-span-2 sm:col-span-3 lg:col-span-4`,children:[v,y]}),t[22]=n.lastRunReason,t[23]=v,t[24]=y,t[25]=b):b=t[25];let x;t[26]!==i||t[27]!==n.lastRunSkipContaminated||t[28]!==n.lastRunSkipHash||t[29]!==n.lastRunSkipKey||t[30]!==n.lastRunSkipRehydrate?(x=i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Wo,{label:n.lastRunSkipKey,children:String(i.alreadyPromotedKey)}),(0,$.jsx)(Wo,{label:n.lastRunSkipRehydrate,children:String(i.rehydrateFailed)}),(0,$.jsx)(Wo,{label:n.lastRunSkipContaminated,children:String(i.contaminated)}),(0,$.jsx)(Wo,{label:n.lastRunSkipHash,children:String(i.hashDuplicate)})]}):null,t[26]=i,t[27]=n.lastRunSkipContaminated,t[28]=n.lastRunSkipHash,t[29]=n.lastRunSkipKey,t[30]=n.lastRunSkipRehydrate,t[31]=x):x=t[31];let S;return t[32]!==m||t[33]!==_||t[34]!==b||t[35]!==x||t[36]!==c||t[37]!==d?(S=(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-3 lg:grid-cols-4`,children:[c,d,m,_,b,x]}),t[32]=m,t[33]=_,t[34]=b,t[35]=x,t[36]=c,t[37]=d,t[38]=S):S=t[38],S}function Xo(e){let t=(0,Q.c)(58),{t:n,schedulePickerLabels:r,hasToken:i,cfgForm:a,cfgBaseline:o,cfgSaving:s,cfgDirty:c,setCfgForm:l,setCfgOk:u,setCfgError:d,saveConfig:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=J(`min-w-0`,Eo),t[0]=p):p=t[0];let m=!i||!a||s||!c,h;t[1]===f?h=t[2]:(h=()=>void f(),t[1]=f,t[2]=h);let g;t[3]===s?g=t[4]:(g=s?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[3]=s,t[4]=g);let _;t[5]!==n.saveConfig||t[6]!==m||t[7]!==h||t[8]!==g?(_=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:m,onClick:h,children:[g,n.saveConfig]}),t[5]=n.saveConfig,t[6]=m,t[7]=h,t[8]=g,t[9]=_):_=t[9];let v=!i||!a||s||!c,y;t[10]!==o||t[11]!==d||t[12]!==l||t[13]!==u?(y=()=>{u(!1),d(null),l(o)},t[10]=o,t[11]=d,t[12]=l,t[13]=u,t[14]=y):y=t[14];let b;t[15]!==n.resetConfig||t[16]!==v||t[17]!==y?(b=(0,$.jsx)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:v,onClick:y,children:n.resetConfig}),t[15]=n.resetConfig,t[16]=v,t[17]=y,t[18]=b):b=t[18];let x;t[19]!==_||t[20]!==b?(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_,b]}),t[19]=_,t[20]=b,t[21]=x):x=t[21];let S;t[22]!==n.configHint||t[23]!==n.configTitle||t[24]!==x?(S=(0,$.jsx)(Sn,{className:Do,icon:k,title:n.configTitle,subtitle:n.configHint,trailing:x}),t[22]=n.configHint,t[23]=n.configTitle,t[24]=x,t[25]=S):S=t[25];let C;t[26]!==a||t[27]!==s||t[28]!==i||t[29]!==r||t[30]!==l||t[31]!==n.configDeepHalfLife||t[32]!==n.configDeepLimit||t[33]!==n.configDeepMaxAge||t[34]!==n.configDeepMinRecallCount||t[35]!==n.configDeepMinScore||t[36]!==n.configFrequency||t[37]!==n.configLightDedupe||t[38]!==n.configLightLimit||t[39]!==n.configLightLookbackDays||t[40]!==n.configLoading||t[41]!==n.configPhaseCron||t[42]!==n.configPhaseDeep||t[43]!==n.configPhaseDeepHint||t[44]!==n.configPhaseLight||t[45]!==n.configPhaseLightHint||t[46]!==n.configPhaseRem||t[47]!==n.configPhaseRemHint||t[48]!==n.configRemLimit||t[49]!==n.configRemLookbackDays||t[50]!==n.configRemMinStrength||t[51]!==n.configTimezone||t[52]!==n.off||t[53]!==n.on?(C=a?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`div`,{className:Oo,children:(0,$.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-12`,children:[(0,$.jsx)(`div`,{className:`lg:col-span-9`,children:(0,$.jsx)(Bo,{kind:`cron`,label:n.configFrequency,value:a.frequency,onChange:e=>l(t=>t&&{...t,frequency:e}),labels:r,disabled:!i||s})}),(0,$.jsx)(Uo,{label:n.configTimezone,className:`lg:col-span-3`,children:(0,$.jsx)(`input`,{className:ko,value:a.timezone,disabled:!i||s,onChange:e=>l(t=>t&&{...t,timezone:e.target.value}),placeholder:`Asia/Shanghai`})})]})}),(0,$.jsxs)(Ko,{icon:(0,$.jsx)(Qe,{className:`size-4 text-amber-500`}),title:n.configPhaseLight,hint:n.configPhaseLightHint,enabled:a.light.enabled,onEnabledChange:e=>l(t=>t&&{...t,light:{...t.light,enabled:e}}),cron:a.light.cron,onCronChange:e=>l(t=>t&&{...t,light:{...t.light,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,$.jsx)(Uo,{label:n.configLightLookbackDays,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:ko,value:a.light.lookbackDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,lookbackDays:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configLightLimit,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:0,className:ko,value:a.light.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,limit:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configLightDedupe,children:(0,$.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:ko,value:a.light.dedupeSimilarity,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,dedupeSimilarity:Number(e.target.value)}})})})]}),(0,$.jsxs)(Ko,{icon:(0,$.jsx)(Ue,{className:`size-4 text-indigo-500`}),title:n.configPhaseDeep,hint:n.configPhaseDeepHint,enabled:a.deep.enabled,onEnabledChange:e=>l(t=>t&&{...t,deep:{...t.deep,enabled:e}}),cron:a.deep.cron,onCronChange:e=>l(t=>t&&{...t,deep:{...t.deep,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,$.jsx)(Uo,{label:n.configDeepMinScore,children:(0,$.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:ko,value:a.deep.minScore,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,minScore:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configDeepMinRecallCount,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:ko,value:a.deep.minRecallCount,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,minRecallCount:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configDeepLimit,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:0,className:ko,value:a.deep.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,limit:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configDeepHalfLife,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:ko,value:a.deep.recencyHalfLifeDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,recencyHalfLifeDays:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configDeepMaxAge,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:ko,value:a.deep.maxAgeDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,maxAgeDays:Number(e.target.value)}})})})]}),(0,$.jsxs)(Ko,{icon:(0,$.jsx)(ke,{className:`size-4 text-purple-500`}),title:n.configPhaseRem,hint:n.configPhaseRemHint,enabled:a.rem.enabled,onEnabledChange:e=>l(t=>t&&{...t,rem:{...t.rem,enabled:e}}),cron:a.rem.cron,onCronChange:e=>l(t=>t&&{...t,rem:{...t.rem,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,$.jsx)(Uo,{label:n.configRemLookbackDays,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:ko,value:a.rem.lookbackDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,lookbackDays:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configRemLimit,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:0,className:ko,value:a.rem.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,limit:Number(e.target.value)}})})}),(0,$.jsx)(Uo,{label:n.configRemMinStrength,children:(0,$.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:ko,value:a.rem.minPatternStrength,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,minPatternStrength:Number(e.target.value)}})})})]})]}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.configLoading}),t[26]=a,t[27]=s,t[28]=i,t[29]=r,t[30]=l,t[31]=n.configDeepHalfLife,t[32]=n.configDeepLimit,t[33]=n.configDeepMaxAge,t[34]=n.configDeepMinRecallCount,t[35]=n.configDeepMinScore,t[36]=n.configFrequency,t[37]=n.configLightDedupe,t[38]=n.configLightLimit,t[39]=n.configLightLookbackDays,t[40]=n.configLoading,t[41]=n.configPhaseCron,t[42]=n.configPhaseDeep,t[43]=n.configPhaseDeepHint,t[44]=n.configPhaseLight,t[45]=n.configPhaseLightHint,t[46]=n.configPhaseRem,t[47]=n.configPhaseRemHint,t[48]=n.configRemLimit,t[49]=n.configRemLookbackDays,t[50]=n.configRemMinStrength,t[51]=n.configTimezone,t[52]=n.off,t[53]=n.on,t[54]=C):C=t[54];let w;return t[55]!==S||t[56]!==C?(w=(0,$.jsxs)(wn,{className:p,children:[S,C]}),t[55]=S,t[56]=C,t[57]=w):w=t[57],w}function Zo(e){let t=(0,Q.c)(20),{t:n,hasToken:r,eventsLoading:i,events:a,loadEvents:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.eventsLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.eventsLoad]}),t[4]=n.eventsLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.eventsHint||t[10]!==n.eventsTitle||t[11]!==u?(d=(0,$.jsx)(Sn,{className:Do,icon:tt,title:n.eventsTitle,subtitle:n.eventsHint,trailing:u}),t[9]=n.eventsHint,t[10]=n.eventsTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.eventsEmpty||t[15]!==n.eventsNotLoaded?(f=a?a.length>0?(0,$.jsx)(`div`,{className:`space-y-1.5`,children:a.map(Qo)}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsEmpty}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsNotLoaded}),t[13]=a,t[14]=n.eventsEmpty,t[15]=n.eventsNotLoaded,t[16]=f):f=t[16];let p;return t[17]!==d||t[18]!==f?(p=(0,$.jsxs)(wn,{className:Eo,children:[d,f]}),t[17]=d,t[18]=f,t[19]=p):p=t[19],p}function Qo(e){let t=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,n=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,$.jsx)(`span`,{children:t}),(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,$.jsx)(`span`,{className:J(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,$.jsx)(`span`,{className:`text-fg-muted`,children:n}),(0,$.jsx)(`span`,{className:`text-fg-muted`,children:jo(e.durationMs)}),(0,$.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Ao(e.timestamp)})]},`${e.timestamp}:${e.phase}`)}function $o(e){let t=(0,Q.c)(40),{t:n,cfgForm:r,dreamingEnabled:i,hasToken:a,cfgSaving:o,enableSaving:s,runPhase:c,setRunPhase:l,runBusy:u,doRunNow:d,doRefresh:f,setDreamingEnabled:p}=e,m;t[0]===n.title?m=t[1]:(m=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),t[0]=n.title,t[1]=m);let h;t[2]===n.subtitle?h=t[3]:(h=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),t[2]=n.subtitle,t[3]=h);let g;t[4]!==m||t[5]!==h?(g=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[m,h]}),t[4]=m,t[5]=h,t[6]=g):g=t[6];let _;t[7]!==r||t[8]!==o||t[9]!==i||t[10]!==s||t[11]!==a||t[12]!==p||t[13]!==n.configEnabled||t[14]!==n.off||t[15]!==n.on?(_=r?(0,$.jsxs)(`label`,{className:J(`inline-flex cursor-pointer items-center gap-2 rounded-xl border px-3 py-1.5 text-sm transition-colors`,i?`border-emerald-500/30 bg-emerald-500/5 text-fg`:`border-edge-subtle bg-surface-panel/50 text-fg-muted`),children:[(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:n.configEnabled}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,disabled:!a||o||s,onChange:e=>void p(e.target.checked)}),s?(0,$.jsx)(q,{className:`size-3.5 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,$.jsx)(`span`,{className:J(`text-xs font-semibold`,i?`text-emerald-600 dark:text-emerald-400`:``),children:r.enabled?n.on:n.off})]}):null,t[7]=r,t[8]=o,t[9]=i,t[10]=s,t[11]=a,t[12]=p,t[13]=n.configEnabled,t[14]=n.off,t[15]=n.on,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==i||t[19]!==a||t[20]!==u||t[21]!==c||t[22]!==l||t[23]!==n.runNow||t[24]!==n.runNowHint?(v=i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:c,onChange:e=>l(e.target.value),disabled:!a||u,children:[(0,$.jsx)(`option`,{value:`light`,children:`Light`}),(0,$.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,$.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!a||u,onClick:()=>void d(c),title:n.runNowHint,children:[u?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Fe,{className:`mr-2 size-4`,"aria-hidden":!0}),n.runNow]})]}):null,t[17]=d,t[18]=i,t[19]=a,t[20]=u,t[21]=c,t[22]=l,t[23]=n.runNow,t[24]=n.runNowHint,t[25]=v):v=t[25];let y=!a,b;t[26]===f?b=t[27]:(b=()=>void f(),t[26]=f,t[27]=b);let x;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(Ee,{className:`mr-2 size-4`,"aria-hidden":!0}),t[28]=x):x=t[28];let S;t[29]!==n.refresh||t[30]!==y||t[31]!==b?(S=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:y,onClick:b,children:[x,n.refresh]}),t[29]=n.refresh,t[30]=y,t[31]=b,t[32]=S):S=t[32];let C;t[33]!==_||t[34]!==v||t[35]!==S?(C=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[_,v,S]}),t[33]=_,t[34]=v,t[35]=S,t[36]=C):C=t[36];let w;return t[37]!==C||t[38]!==g?(w=(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[g,C]}),t[37]=C,t[38]=g,t[39]=w):w=t[39],w}function es(e){let t=(0,Q.c)(30),{t:n,disabled:r,actionBusy:i,doAction:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=J(`max-w-2xl`,Eo),t[0]=o):o=t[0];let s;t[1]!==n.maintenanceHint||t[2]!==n.maintenanceTitle?(s=(0,$.jsx)(Sn,{className:Do,icon:nt,title:n.maintenanceTitle,subtitle:n.maintenanceHint}),t[1]=n.maintenanceHint,t[2]=n.maintenanceTitle,t[3]=s):s=t[3];let c;t[4]!==a||t[5]!==n.confirmResetStore?(c=()=>{confirm(n.confirmResetStore)&&a(`reset_store`)},t[4]=a,t[5]=n.confirmResetStore,t[6]=c):c=t[6];let l;t[7]===i?l=t[8]:(l=i===`reset_store`?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Lt,{className:`mr-2 size-4`,"aria-hidden":!0}),t[7]=i,t[8]=l);let u;t[9]!==r||t[10]!==n.resetStore||t[11]!==c||t[12]!==l?(u=(0,$.jsxs)(Y,{variant:`secondary`,disabled:r,onClick:c,children:[l,n.resetStore]}),t[9]=r,t[10]=n.resetStore,t[11]=c,t[12]=l,t[13]=u):u=t[13];let d;t[14]!==a||t[15]!==n.confirmClearLock?(d=()=>{confirm(n.confirmClearLock)&&a(`clear_lock`)},t[14]=a,t[15]=n.confirmClearLock,t[16]=d):d=t[16];let f;t[17]===i?f=t[18]:(f=i===`clear_lock`?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ut,{className:`mr-2 size-4`,"aria-hidden":!0}),t[17]=i,t[18]=f);let p;t[19]!==r||t[20]!==n.clearLock||t[21]!==d||t[22]!==f?(p=(0,$.jsxs)(Y,{variant:`secondary`,disabled:r,onClick:d,children:[f,n.clearLock]}),t[19]=r,t[20]=n.clearLock,t[21]=d,t[22]=f,t[23]=p):p=t[23];let m;t[24]!==u||t[25]!==p?(m=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[u,p]}),t[24]=u,t[25]=p,t[26]=m):m=t[26];let h;return t[27]!==s||t[28]!==m?(h=(0,$.jsxs)(wn,{className:o,children:[s,m]}),t[27]=s,t[28]=m,t[29]=h):h=t[29],h}function ts(e){let t=(0,Q.c)(21),{t:n,hasToken:r,previewLoading:i,previewItems:a,loadPreview:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.previewLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.previewLoad]}),t[4]=n.previewLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.previewHint||t[10]!==n.previewTitle||t[11]!==u?(d=(0,$.jsx)(Sn,{className:Do,icon:U,title:n.previewTitle,subtitle:n.previewHint,trailing:u}),t[9]=n.previewHint,t[10]=n.previewTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.previewEligible||t[15]!==n.previewEmpty||t[16]!==n.previewNotLoaded?(f=a?a.length>0?(0,$.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>{let t=`${e.path}:${e.startLine}-${e.endLine}`,r=e.skippedReason;return(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 px-2.5 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:t}),(0,$.jsxs)(`span`,{children:[`score=`,e.score.toFixed(3)]}),(0,$.jsxs)(`span`,{children:[`recalls=`,e.recallCount]}),(0,$.jsxs)(`span`,{children:[`avg=`,e.avgScore.toFixed(3)]}),(0,$.jsxs)(`span`,{children:[`decay=`,e.recencyDecay?.toFixed(3)??`—`]}),r?(0,$.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,$.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:n.previewEligible})]}),e.snippet?(0,$.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:e.snippet}):null]},`${e.key}:${e.hash}:${t}`)})}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewEmpty}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewNotLoaded}),t[13]=a,t[14]=n.previewEligible,t[15]=n.previewEmpty,t[16]=n.previewNotLoaded,t[17]=f):f=t[17];let p;return t[18]!==d||t[19]!==f?(p=(0,$.jsxs)(wn,{className:Eo,children:[d,f]}),t[18]=d,t[19]=f,t[20]=p):p=t[20],p}function ns(e){let t=(0,Q.c)(100),{t:n,data:r,isLoading:i,localeTag:a,scheduleBadgeLabels:o}=e,s;t[0]!==r||t[1]!==n?(s=r?Mo(r.lock,n):null,t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=s,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(`min-w-0`,Eo),t[3]=l):l=t[3];let u;t[4]===i?u=t[5]:(u=i?(0,$.jsx)(q,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null,t[4]=i,t[5]=u);let d;t[6]!==n.runtimeHint||t[7]!==n.runtimeTitle||t[8]!==u?(d=(0,$.jsx)(Sn,{className:Do,icon:tt,title:n.runtimeTitle,subtitle:n.runtimeHint,trailing:u}),t[6]=n.runtimeHint,t[7]=n.runtimeTitle,t[8]=u,t[9]=d):d=t[9];let f;t[10]===n.subsectionSchedule?f=t[11]:(f=(0,$.jsx)(Go,{label:n.subsectionSchedule,className:`mb-2`}),t[10]=n.subsectionSchedule,t[11]=f);let p=r?r.config.enabled?n.on:n.off:`—`,m;t[12]!==n.enabled||t[13]!==p?(m=(0,$.jsx)(Wo,{label:n.enabled,children:p}),t[12]=n.enabled,t[13]=p,t[14]=m):m=t[14];let h=c?.className,g=c?c.text:`—`,_;t[15]!==h||t[16]!==g?(_=(0,$.jsx)(`span`,{className:h,children:g}),t[15]=h,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==n.lock||t[19]!==_?(v=(0,$.jsx)(Wo,{label:n.lock,children:_}),t[18]=n.lock,t[19]=_,t[20]=v):v=t[20];let y=r&&r.config.timezone||`—`,b;t[21]!==n.timezone||t[22]!==y?(b=(0,$.jsx)(Wo,{label:n.timezone,children:y}),t[21]=n.timezone,t[22]=y,t[23]=b):b=t[23];let x;t[24]!==r||t[25]!==a||t[26]!==o?(x=r?(0,$.jsx)(Mn,{kind:`cron`,expression:r.config.frequency,locale:a,labels:o,timezone:r.config.timezone||void 0}):`—`,t[24]=r,t[25]=a,t[26]=o,t[27]=x):x=t[27];let S;t[28]===r?S=t[29]:(S=r?.config.frequency?(0,$.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[0.65rem] text-fg-subtle`,title:r.config.frequency,children:r.config.frequency}):null,t[28]=r,t[29]=S);let C;t[30]!==n.schedule||t[31]!==x||t[32]!==S?(C=(0,$.jsxs)(Wo,{label:n.schedule,className:`col-span-2 sm:col-span-2`,children:[x,S]}),t[30]=n.schedule,t[31]=x,t[32]=S,t[33]=C):C=t[33];let w;t[34]!==v||t[35]!==b||t[36]!==C||t[37]!==m?(w=(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[m,v,b,C]}),t[34]=v,t[35]=b,t[36]=C,t[37]=m,t[38]=w):w=t[38];let T;t[39]!==w||t[40]!==f?(T=(0,$.jsxs)(`div`,{className:Oo,children:[f,w]}),t[39]=w,t[40]=f,t[41]=T):T=t[41];let E;t[42]===n.subsectionStore?E=t[43]:(E=(0,$.jsx)(Go,{label:n.subsectionStore,className:`mb-2`}),t[42]=n.subsectionStore,t[43]=E);let D=r?String(r.store.entryCount):`—`,O;t[44]!==n.storeEntries||t[45]!==D?(O=(0,$.jsx)(Wo,{label:n.storeEntries,children:D}),t[44]=n.storeEntries,t[45]=D,t[46]=O):O=t[46];let k=r?String(r.store.promotedCount):`—`,A;t[47]!==n.storePromoted||t[48]!==k?(A=(0,$.jsx)(Wo,{label:n.storePromoted,children:k}),t[47]=n.storePromoted,t[48]=k,t[49]=A):A=t[49];let j;t[50]===r?j=t[51]:(j=r?Ao(r.store.updatedAt):`—`,t[50]=r,t[51]=j);let M;t[52]!==n.storeUpdatedAt||t[53]!==j?(M=(0,$.jsx)(Wo,{label:n.storeUpdatedAt,children:j}),t[52]=n.storeUpdatedAt,t[53]=j,t[54]=M):M=t[54];let N;t[55]===r?N=t[56]:(N=r?Ao(r.store.lastPromotedAt):`—`,t[55]=r,t[56]=N);let P;t[57]!==n.storeLastPromotedAt||t[58]!==N?(P=(0,$.jsx)(Wo,{label:n.storeLastPromotedAt,children:N}),t[57]=n.storeLastPromotedAt,t[58]=N,t[59]=P):P=t[59];let F;t[60]!==O||t[61]!==A||t[62]!==M||t[63]!==P?(F=(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[O,A,M,P]}),t[60]=O,t[61]=A,t[62]=M,t[63]=P,t[64]=F):F=t[64];let I;t[65]!==E||t[66]!==F?(I=(0,$.jsxs)(`div`,{className:Oo,children:[E,F]}),t[65]=E,t[66]=F,t[67]=I):I=t[67];let L;t[68]!==r||t[69]!==a||t[70]!==o||t[71]!==n?(L=r?.config?.phases?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Go,{label:n.subsectionPhases,className:`mb-2`}),(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,$.jsx)(qo,{icon:(0,$.jsx)(Qe,{className:`size-4 text-amber-500`}),label:`Light`,enabled:r.config.phases.light.enabled,cron:r.config.phases.light.cron,scheduleSummary:En(r.config.phases.light.cron,a,o,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.light.lookbackDays}d, limit=${r.config.phases.light.limit}, dedupe=${r.config.phases.light.dedupeSimilarity}`,t:n}),(0,$.jsx)(qo,{icon:(0,$.jsx)(Ue,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:r.config.phases.deep.enabled,cron:r.config.phases.deep.cron,scheduleSummary:En(r.config.phases.deep.cron,a,o,{timezone:r.config.timezone||void 0}),details:`minScore=${r.config.phases.deep.minScore}, recalls≥${r.config.phases.deep.minRecallCount}, limit=${r.config.phases.deep.limit}, halfLife=${r.config.phases.deep.recencyHalfLifeDays}d`,t:n}),(0,$.jsx)(qo,{icon:(0,$.jsx)(ke,{className:`size-4 text-purple-500`}),label:`REM`,enabled:r.config.phases.rem.enabled,cron:r.config.phases.rem.cron,scheduleSummary:En(r.config.phases.rem.cron,a,o,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.rem.lookbackDays}d, limit=${r.config.phases.rem.limit}, strength≥${r.config.phases.rem.minPatternStrength}`,t:n})]})]}):null,t[68]=r,t[69]=a,t[70]=o,t[71]=n,t[72]=L):L=t[72];let R;t[73]===n.subsectionLastRun?R=t[74]:(R=(0,$.jsx)(Go,{label:n.subsectionLastRun,className:`mb-2`}),t[73]=n.subsectionLastRun,t[74]=R);let z;t[75]===n.lastRunBlockHint?z=t[76]:(z=(0,$.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:n.lastRunBlockHint}),t[75]=n.lastRunBlockHint,t[76]=z);let B;t[77]!==r||t[78]!==n?(B=r?.lastRun?.exists?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[r.lastRun.parseError?(0,$.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[n.lastRunParseError,`: `,r.lastRun.parseError]}):null,r.lastRun.record?(0,$.jsx)(`div`,{className:`rounded-lg border border-edge-subtle/80 bg-surface-panel/50 p-2.5`,children:(0,$.jsx)(Yo,{t:n,r:r.lastRun.record})}):null,r.lastRun.raw!==void 0&&r.lastRun.raw!==null?(0,$.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,$.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,$.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.lastRun.raw,null,2)})]}):null]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.lastRunEmpty}),t[77]=r,t[78]=n,t[79]=B):B=t[79];let V;t[80]!==R||t[81]!==z||t[82]!==B?(V=(0,$.jsxs)(`div`,{className:Oo,children:[R,z,B]}),t[80]=R,t[81]=z,t[82]=B,t[83]=V):V=t[83];let H=r?.lightLastRun,U;t[84]!==n||t[85]!==H?(U=(0,$.jsx)(Jo,{label:n.subsectionLightLastRun,lastRun:H,t:n}),t[84]=n,t[85]=H,t[86]=U):U=t[86];let W=r?.remLastRun,G;t[87]!==n||t[88]!==W?(G=(0,$.jsx)(Jo,{label:n.subsectionRemLastRun,lastRun:W,t:n}),t[87]=n,t[88]=W,t[89]=G):G=t[89];let ee;t[90]!==T||t[91]!==I||t[92]!==L||t[93]!==V||t[94]!==U||t[95]!==G?(ee=(0,$.jsxs)(`div`,{className:`space-y-3`,children:[T,I,L,V,U,G]}),t[90]=T,t[91]=I,t[92]=L,t[93]=V,t[94]=U,t[95]=G,t[96]=ee):ee=t[96];let K;return t[97]!==ee||t[98]!==d?(K=(0,$.jsxs)(wn,{className:l,children:[d,ee]}),t[97]=ee,t[98]=d,t[99]=K):K=t[99],K}var rs=[`config`,`runtime`,`insights`,`maintenance`],is={config:k,runtime:tt,insights:U,maintenance:nt};function as(e){return e&&rs.includes(e)?e:`config`}function os(e,t){return t===`config`?e.tabConfig:t===`runtime`?e.tabRuntime:t===`insights`?e.tabInsights:e.tabMaintenance}function ss(e,t){return t===`config`?e.configTabHint:t===`runtime`?e.runtimeTabHint:t===`insights`?e.insightsTabHint:e.maintenanceTabHint}function cs(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:return{form:t.value,baseline:t.value};case`set`:return{...e,form:t.value};case`saved`:return{form:t.value,baseline:t.value}}}var ls={actionBusy:null,actionError:null,actionOk:!1,runBusy:!1,runOk:!1,runError:null,runPhase:`deep`,cfgSaving:!1,enableSaving:!1,cfgOk:!1,cfgError:null,previewLoading:!1,previewError:null,previewItems:null,eventsLoading:!1,eventsError:null,events:null};function us(){let e=a(e=>e.language),t=s(e),n=t.dreamingSettings,r=t.cron.schedulePicker,i=t.cron.scheduleBadge,o=e===`zh`?`zh-CN`:`en-US`,c=!!x(e=>e.token),[l,u]=ot(),f=as(l.get(`tab`)),p=(0,Z.useCallback)(e=>{u(t=>{let n=new URLSearchParams(t);return e===`config`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[u]),{data:m}=Ze(c),[h,g]=(0,Z.useReducer)(Gt,ls),{actionBusy:_,actionError:v,actionOk:y,runBusy:b,runOk:S,runError:C,runPhase:w,cfgSaving:T,enableSaving:E,cfgOk:D,cfgError:O,previewLoading:k,previewError:A,previewItems:j,eventsLoading:M,eventsError:N,events:P}=h,[F,I]=(0,Z.useReducer)(cs,{form:null,baseline:null}),L=F.form,R=F.baseline,z=(0,Z.useRef)(!1),{data:B,error:V,isLoading:H,mutate:U}=d(c?lo():null,uo,{revalidateOnFocus:!1}),W=(0,Z.useMemo)(()=>{let e=[];return V&&e.push(V instanceof Error?V.message:String(V)),v&&e.push(v),C&&e.push(C),A&&e.push(A),N&&e.push(N),O&&e.push(O),e},[V,v,C,A,N,O]),G=(0,Z.useMemo)(()=>{let e=[];return D&&e.push(n.configSaved),S&&e.push(n.runQueued),y&&e.push(n.actionOk),e},[D,S,y,n]),ee=(0,Z.useCallback)(async()=>{g({type:`patch`,patch:{actionOk:!1,actionError:null,runOk:!1,runError:null,cfgOk:!1,cfgError:null,previewError:null}}),await U()},[U]),K=(0,Z.useCallback)(async()=>{g({type:`patch`,patch:{previewLoading:!0,previewError:null}});try{g({type:`patch`,patch:{previewItems:(await mo(20)).items??[]}})}catch(e){g({type:`patch`,patch:{previewError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{previewLoading:!1}})}},[]),te=(0,Z.useCallback)(async()=>{g({type:`patch`,patch:{eventsLoading:!0,eventsError:null}});try{g({type:`patch`,patch:{events:await ho(50)}})}catch(e){g({type:`patch`,patch:{eventsError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{eventsLoading:!1}})}},[]),ne=(0,Z.useCallback)(async(e=`deep`)=>{g({type:`patch`,patch:{runBusy:!0,runOk:!1,runError:null}});try{await po(e),g({type:`patch`,patch:{runOk:!0}}),await U()}catch(e){g({type:`patch`,patch:{runError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{runBusy:!1}})}},[U]),re=(0,Z.useCallback)(async e=>{g({type:`patch`,patch:{actionBusy:e,actionError:null,actionOk:!1}});try{await fo(e),g({type:`patch`,patch:{actionOk:!0}}),await U()}catch(e){g({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{actionBusy:null}})}},[U]),ie=!c||H||!!_,ae=(0,Z.useMemo)(()=>{let e=m?.payload?.config;return wo(e??{})},[m]);(0,Z.useEffect)(()=>{if(!c){I({type:`reset`}),z.current=!1;return}z.current||I({type:`sync`,value:ae})},[ae,c]);let oe=(0,Z.useMemo)(()=>!L||!R?!1:JSON.stringify(L)!==JSON.stringify(R),[L,R]),se=(0,Z.useCallback)(async()=>{if(L){g({type:`patch`,patch:{cfgSaving:!0,cfgOk:!1,cfgError:null}});try{await To(L),I({type:`saved`,value:L}),z.current=!1,g({type:`patch`,patch:{cfgOk:!0}}),await U()}catch(e){g({type:`patch`,patch:{cfgError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{cfgSaving:!1}})}}},[L,U]),ce=(0,Z.useCallback)(async e=>{if(!L||!c)return;let t={...L,enabled:e},n=L;z.current=!0,I({type:`set`,value:t}),g({type:`patch`,patch:{enableSaving:!0,cfgOk:!1,cfgError:null}});try{await To(t),I({type:`saved`,value:t}),z.current=!1,g({type:`patch`,patch:{cfgOk:!0}}),await U()}catch(e){I({type:`set`,value:n}),g({type:`patch`,patch:{cfgError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{enableSaving:!1}})}},[L,c,U]);return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,$.jsx)($o,{t:n,cfgForm:L,dreamingEnabled:L?.enabled??ae.enabled,hasToken:c,cfgSaving:T,enableSaving:E,runPhase:w,setRunPhase:e=>g({type:`patch`,patch:{runPhase:e}}),runBusy:b,doRunNow:ne,doRefresh:ee,setDreamingEnabled:ce}),W.length>0?(0,$.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:W.map(e=>(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},e))}):null,G.length>0?(0,$.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:G.map(e=>(0,$.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},e))}):null,(0,$.jsx)(ds,{t:n,activeTab:f,onChange:p}),(0,$.jsx)(fs,{t:n,id:`config`,activeTab:f,children:(0,$.jsx)(Xo,{t:n,schedulePickerLabels:r,hasToken:c,cfgForm:L,cfgBaseline:R,cfgSaving:T,cfgDirty:oe,setCfgForm:e=>{z.current=!0;let t=typeof e==`function`?e(L):e;t&&I({type:`set`,value:t})},setCfgOk:e=>g({type:`patch`,patch:{cfgOk:e}}),setCfgError:e=>g({type:`patch`,patch:{cfgError:e}}),saveConfig:se})}),(0,$.jsx)(fs,{t:n,id:`runtime`,activeTab:f,children:(0,$.jsx)(ns,{t:n,data:B,isLoading:H,localeTag:o,scheduleBadgeLabels:i})}),(0,$.jsx)(fs,{t:n,id:`insights`,activeTab:f,children:(0,$.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,$.jsx)(ts,{t:n,hasToken:c,previewLoading:k,previewItems:j,loadPreview:K}),(0,$.jsx)(Zo,{t:n,hasToken:c,eventsLoading:M,events:P,loadEvents:te})]})}),(0,$.jsx)(fs,{t:n,id:`maintenance`,activeTab:f,children:(0,$.jsx)(es,{t:n,disabled:ie,actionBusy:_,doAction:re})})]})}function ds(e){let t=(0,Q.c)(11),{t:n,activeTab:r,onChange:i}=e,a=n.tabsAriaLabel,o;t[0]!==r||t[1]!==i?(o=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),i(rs[(rs.indexOf(r)+(e.key===`ArrowRight`?1:-1)+rs.length)%rs.length]))},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==i||t[5]!==n?(s=rs.map(e=>{let t=is[e],a=e===r;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,id:`dreaming-settings-tab-${e}`,"aria-controls":`dreaming-settings-panel-${e}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>i(e),children:[(0,$.jsx)(t,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:os(n,e)})]},e)}),t[3]=r,t[4]=i,t[5]=n,t[6]=s):s=t[6];let c;return t[7]!==n.tabsAriaLabel||t[8]!==o||t[9]!==s?(c=(0,$.jsx)(`nav`,{"aria-label":a,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,onKeyDown:o,children:s}),t[7]=n.tabsAriaLabel,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function fs(e){let t=(0,Q.c)(18),{t:n,id:r,activeTab:i,children:a}=e;if(i!==r)return null;let o=`dreaming-settings-panel-${r}`,s=`dreaming-settings-tab-${r}`,c;t[0]!==r||t[1]!==n?(c=os(n,r),t[0]=r,t[1]=n,t[2]=c):c=t[2];let l;t[3]===c?l=t[4]:(l=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:c}),t[3]=c,t[4]=l);let u;t[5]!==r||t[6]!==n?(u=ss(n,r),t[5]=r,t[6]=n,t[7]=u):u=t[7];let d;t[8]===u?d=t[9]:(d=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u}),t[8]=u,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:`mb-5`,children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==a||t[14]!==o||t[15]!==s||t[16]!==f?(p=(0,$.jsxs)(`section`,{id:o,role:`tabpanel`,"aria-labelledby":s,className:`rounded-2xl border border-edge bg-surface-base px-4 py-5 sm:px-5`,children:[f,a]}),t[13]=a,t[14]=o,t[15]=s,t[16]=f,t[17]=p):p=t[17],p}var ps={enabled:!0,maxConcurrentJobs:5,defaultTimezone:`UTC`,historyRetentionDays:7,enableMetrics:!0};function ms(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function hs(e){let t=ms(e)?e:{},n=ms(t.cron)?t.cron:{};return{enabled:n.enabled!==!1,maxConcurrentJobs:typeof n.maxConcurrentJobs==`number`&&Number.isFinite(n.maxConcurrentJobs)?Math.max(1,Math.min(100,Math.floor(n.maxConcurrentJobs))):ps.maxConcurrentJobs,defaultTimezone:typeof n.defaultTimezone==`string`&&n.defaultTimezone.trim()?n.defaultTimezone.trim():ps.defaultTimezone,historyRetentionDays:typeof n.historyRetentionDays==`number`&&Number.isFinite(n.historyRetentionDays)?Math.max(1,Math.min(365,Math.floor(n.historyRetentionDays))):ps.historyRetentionDays,enableMetrics:n.enableMetrics!==!1}}async function gs(e){await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({cron:e})}),mt()}function _s(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,lt,`dark:border-edge`)}function vs(){return{form:null,baseline:null,saving:!1,error:null,saveOk:!1,dirty:!1}}function ys(e,t){switch(t.type){case`sync`:return{...e,form:structuredClone(t.parsed),baseline:structuredClone(t.parsed),saveOk:!1,dirty:!1};case`patch`:return e.form?{...e,form:{...e.form,...t.patch},dirty:!0,saveOk:!1}:e;case`discard`:return e.baseline?{...e,form:structuredClone(e.baseline),dirty:!1}:e;case`saveStart`:return{...e,saving:!0,error:null};case`saveSuccess`:return e.form?{...e,saving:!1,baseline:structuredClone(e.form),dirty:!1,saveOk:!0}:{...e,saving:!1};case`saveError`:return{...e,saving:!1,error:t.error};case`clearSaveOk`:return{...e,saveOk:!1}}}function bs({hasToken:e}){let t=s(a(e=>e.language)).cron.globals,{data:n,isLoading:r}=Ze(e),i=(0,Z.useMemo)(()=>n?.payload?.config===void 0?null:structuredClone(hs(n.payload.config)),[n]),[o,c]=(0,Z.useReducer)(ys,void 0,vs),l=(0,Z.useRef)(i);e&&i!==null&&!o.dirty&&l.current!==i&&(l.current=i,c({type:`sync`,parsed:i}));let u=(0,Z.useMemo)(()=>!!(o.form&&o.baseline&&JSON.stringify(o.form)!==JSON.stringify(o.baseline)),[o.form,o.baseline]),d=(0,Z.useCallback)(e=>{c({type:`patch`,patch:e})},[]),f=(0,Z.useCallback)(async()=>{if(!(!o.form||o.saving)){c({type:`saveStart`});try{await gs(o.form),c({type:`saveSuccess`}),window.setTimeout(()=>c({type:`clearSaveOk`}),2500)}catch(e){c({type:`saveError`,error:e instanceof Error?e.message:t.saveError})}}},[t.saveError,o.form,o.saving]);return!e||!o.form?r?(0,$.jsx)(wn,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),t.loading]})}):null:(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:be,title:t.title,subtitle:t.hint}),(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-end gap-2`,children:[o.saveOk?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:t.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!u||o.saving,onClick:()=>c({type:`discard`}),children:t.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!u||o.saving,onClick:()=>void f(),children:o.saving?t.saving:t.save})]}),o.error?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:o.error}):null,(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg sm:col-span-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:o.form.enabled,onChange:e=>d({enabled:e.target.checked})}),t.enabled]}),(0,$.jsx)(xs,{label:t.maxConcurrent,value:o.form.maxConcurrentJobs,min:1,max:100,disabled:!o.form.enabled,onChange:e=>d({maxConcurrentJobs:e})}),(0,$.jsx)(xs,{label:t.timezone,text:!0,value:o.form.defaultTimezone,disabled:!o.form.enabled,onTextChange:e=>d({defaultTimezone:e})}),(0,$.jsx)(xs,{label:t.retentionDays,value:o.form.historyRetentionDays,min:1,max:365,disabled:!o.form.enabled,onChange:e=>d({historyRetentionDays:e})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:o.form.enableMetrics,disabled:!o.form.enabled,onChange:e=>d({enableMetrics:e.target.checked})}),t.metrics]})]})]})}function xs(e){let t=(0,Q.c)(13),{label:n,value:r,min:i,max:a,disabled:o,text:s,onChange:c,onTextChange:l}=e,u;t[0]===n?u=t[1]:(u=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=u);let d;t[2]!==o||t[3]!==a||t[4]!==i||t[5]!==c||t[6]!==l||t[7]!==s||t[8]!==r?(d=s?(0,$.jsx)(`input`,{className:J(_s(),`font-mono text-xs`),value:String(r),disabled:o,onChange:e=>l?.(e.target.value)}):(0,$.jsx)(`input`,{type:`number`,min:i,max:a,disabled:o,className:J(_s(),`max-w-xs font-mono text-xs`),value:typeof r==`number`?r:0,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&c&&i!==void 0&&a!==void 0&&c(Math.max(i,Math.min(a,Math.floor(t))))}}),t[2]=o,t[3]=a,t[4]=i,t[5]=c,t[6]=l,t[7]=s,t[8]=r,t[9]=d):d=t[9];let f;return t[10]!==u||t[11]!==d?(f=(0,$.jsxs)(`div`,{children:[u,d]}),t[10]=u,t[11]=d,t[12]=f):f=t[12],f}function Ss(){let e=(0,Q.c)(18),t=a(ws),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.cronSettingsPage,i=!!x(Cs),o;e[2]===r.title?o=e[3]:(o=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.title}),e[2]=r.title,e[3]=o);let c;e[4]===r.subtitle?c=e[5]:(c=(0,$.jsx)(`p`,{className:`max-w-2xl text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=c);let l;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(l=ee(`cron`),e[6]=l):l=e[6];let u;e[7]===r.tasksLink?u=e[8]:(u=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:(0,$.jsx)(Ft,{to:l,className:`font-medium text-accent-fg hover:underline`,children:r.tasksLink})}),e[7]=r.tasksLink,e[8]=u);let d;e[9]!==o||e[10]!==c||e[11]!==u?(d=(0,$.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[o,c,u]}),e[9]=o,e[10]=c,e[11]=u,e[12]=d):d=e[12];let f;e[13]===i?f=e[14]:(f=(0,$.jsx)(bs,{hasToken:i}),e[13]=i,e[14]=f);let p;return e[15]!==d||e[16]!==f?(p=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6 sm:px-8`,children:[d,f]}),e[15]=d,e[16]=f,e[17]=p):p=e[17],p}function Cs(e){return e.token}function ws(e){return e.language}var Ts={maxTurns:20,judgeModelRef:``,checklistMode:!0,maxConsecutiveParseFailures:3,judgeTimeoutSec:60,checklistHistoryChars:24e3};function Es(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ds(e){let t=Es(e)?e:{},n=Es(t.goals)?t.goals:{};return{maxTurns:typeof n.maxTurns==`number`&&Number.isFinite(n.maxTurns)?Math.max(1,Math.min(500,Math.floor(n.maxTurns))):Ts.maxTurns,judgeModelRef:typeof n.judgeModelRef==`string`?n.judgeModelRef:``,checklistMode:n.checklistMode!==!1,maxConsecutiveParseFailures:typeof n.maxConsecutiveParseFailures==`number`&&Number.isFinite(n.maxConsecutiveParseFailures)?Math.max(1,Math.min(20,Math.floor(n.maxConsecutiveParseFailures))):Ts.maxConsecutiveParseFailures,judgeTimeoutSec:typeof n.judgeTimeoutMs==`number`&&Number.isFinite(n.judgeTimeoutMs)?Math.max(5,Math.min(120,Math.round(n.judgeTimeoutMs/1e3))):Ts.judgeTimeoutSec,checklistHistoryChars:typeof n.checklistHistoryChars==`number`&&Number.isFinite(n.checklistHistoryChars)?Math.max(0,Math.min(1e5,Math.floor(n.checklistHistoryChars))):Ts.checklistHistoryChars}}async function Os(e){await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({goals:{maxTurns:e.maxTurns,...e.judgeModelRef.trim()?{judgeModelRef:e.judgeModelRef.trim()}:{judgeModelRef:null},checklistMode:e.checklistMode,maxConsecutiveParseFailures:e.maxConsecutiveParseFailures,judgeTimeoutMs:e.judgeTimeoutSec*1e3,checklistHistoryChars:e.checklistHistoryChars}})}),mt()}function ks(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,lt,`dark:border-edge`)}function As(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`patch`:return{...e,form:e.form?{...e.form,...t.patch}:null};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function js({hasToken:e}){let t=a(e=>e.language),n=s(t).goalsSettings,r=s(t).chat,{data:i,isLoading:o}=Ze(e),c=(0,Z.useMemo)(()=>i?.payload?.config===void 0?null:Ds(i.payload.config),[i]),[l,u]=(0,Z.useReducer)(As,{form:null,baseline:null}),d=l.form,f=l.baseline,[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(null),_=(0,Z.useRef)(!1),v=(0,Z.useRef)(null);e?c!==null&&!_.current&&v.current!==c&&(v.current=c,u({type:`sync`,value:c})):v.current!==null&&(v.current=null,u({type:`reset`}),_.current=!1);let y=d&&f&&JSON.stringify(d)!==JSON.stringify(f),b=(0,Z.useCallback)(e=>{_.current=!0,u({type:`patch`,patch:e})},[]);return!e||!d?o?(0,$.jsx)(wn,{children:(0,$.jsx)(q,{className:`size-4 animate-spin text-fg-muted`})}):null:(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:ht,title:n.title,subtitle:n.hint}),(0,$.jsxs)(`div`,{className:`mb-4 flex justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!y||p,onClick:()=>u({type:`discard`}),children:n.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!y||p,onClick:()=>{(async()=>{m(!0),g(null);try{await Os(d),_.current=!1,u({type:`saved`,value:d})}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}})()},children:p?n.saving:n.save})]}),h?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.maxTurns}),(0,$.jsx)(`input`,{type:`number`,min:1,max:500,className:ks(),value:d.maxTurns,onChange:e=>b({maxTurns:Number(e.target.value)||20})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.judgeModelRef}),(0,$.jsx)(Xt,{value:d.judgeModelRef,placeholder:n.judgeModelRefPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,className:`w-full max-w-none min-w-0`,onChange:e=>b({judgeModelRef:e})}),d.judgeModelRef.trim()?(0,$.jsx)(`button`,{type:`button`,className:`mt-1 text-xs text-accent hover:underline`,onClick:()=>b({judgeModelRef:``}),children:n.judgeModelRefUseDefault}):(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.judgeModelRefHint})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg sm:col-span-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:d.checklistMode,onChange:e=>b({checklistMode:e.target.checked})}),n.checklistMode]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.parseFailures}),(0,$.jsx)(`input`,{type:`number`,min:1,max:20,className:ks(),value:d.maxConsecutiveParseFailures,onChange:e=>b({maxConsecutiveParseFailures:Number(e.target.value)||3})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.judgeTimeoutSec}),(0,$.jsx)(`input`,{type:`number`,min:5,max:120,className:ks(),value:d.judgeTimeoutSec,onChange:e=>b({judgeTimeoutSec:Number(e.target.value)||60})})]}),(0,$.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.checklistHistoryChars}),(0,$.jsx)(`input`,{type:`number`,min:0,max:1e5,className:ks(),value:d.checklistHistoryChars,onChange:e=>b({checklistHistoryChars:Math.max(0,Math.min(1e5,Math.floor(Number(e.target.value)||0)))})}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.checklistHistoryCharsHint})]})]})]})}function Ms(){let e=(0,Q.c)(14),t=a(Ps),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.goalsSettingsPage,i=!!x(Ns),o;e[2]===r.title?o=e[3]:(o=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.title}),e[2]=r.title,e[3]=o);let c;e[4]===r.subtitle?c=e[5]:(c=(0,$.jsx)(`p`,{className:`max-w-2xl text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=c);let l;e[6]!==o||e[7]!==c?(l=(0,$.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[o,c]}),e[6]=o,e[7]=c,e[8]=l):l=e[8];let u;e[9]===i?u=e[10]:(u=(0,$.jsx)(js,{hasToken:i}),e[9]=i,e[10]=u);let d;return e[11]!==l||e[12]!==u?(d=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6 sm:px-8`,children:[l,u]}),e[11]=l,e[12]=u,e[13]=d):d=e[13],d}function Ns(e){return e.token}function Ps(e){return e.language}var Fs=18790,Is={enabled:!0,maxAttempts:5,windowMs:9e5,blockDurationMs:3e5,exemptLoopback:!0};function Ls(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Rs(e){return e===`***`||e===`••••••••••••`}function zs(e){return Rs(e)?``:e.trim()}function Bs(e){return[...e].map(e=>e.trim()).sort()}function Vs(e){return JSON.stringify({bind:e.bind,customBindHost:e.customBindHost.trim(),port:e.port,auth:{mode:e.auth.mode,token:zs(e.auth.token),password:zs(e.auth.password),rateLimit:e.auth.rateLimit,trustedProxy:{userHeader:e.auth.trustedProxy.userHeader.trim(),requiredHeaders:Bs(e.auth.trustedProxy.requiredHeaders),allowUsers:Bs(e.auth.trustedProxy.allowUsers),allowLoopback:e.auth.trustedProxy.allowLoopback}},corsOrigins:Bs(e.corsOrigins),trustedProxies:Bs(e.trustedProxies),allowRealIpFallback:e.allowRealIpFallback,dangerouslyAllowHostHeaderOriginFallback:e.dangerouslyAllowHostHeaderOriginFallback})}function Hs(e,t){return Vs(e)!==Vs(t)}function Us(e){return e===`none`||e===`token`||e===`password`||e===`trusted-proxy`?e:`token`}function Ws(e){let t=Ls(e)?e:{};return{enabled:t.enabled!==!1,maxAttempts:typeof t.maxAttempts==`number`&&Number.isFinite(t.maxAttempts)?Math.max(1,Math.floor(t.maxAttempts)):Is.maxAttempts,windowMs:typeof t.windowMs==`number`&&Number.isFinite(t.windowMs)&&t.windowMs>0?Math.floor(t.windowMs):Is.windowMs,blockDurationMs:typeof t.blockDurationMs==`number`&&Number.isFinite(t.blockDurationMs)&&t.blockDurationMs>0?Math.floor(t.blockDurationMs):typeof t.lockoutMs==`number`&&Number.isFinite(t.lockoutMs)&&t.lockoutMs>0?Math.floor(t.lockoutMs):Is.blockDurationMs,exemptLoopback:t.exemptLoopback!==!1}}function Gs(e){let t=Ls(e)?e:{};return{userHeader:typeof t.userHeader==`string`?t.userHeader:``,requiredHeaders:qs(t.requiredHeaders,32),allowUsers:qs(t.allowUsers,128),allowLoopback:t.allowLoopback===!0}}function Ks(e){return e===`auto`||e===`off`||e===`explicit`?e:`auto`}function qs(e,t=24){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()).slice(0,t):[]}function Js(e){return e===`auto`||e===`loopback`||e===`lan`||e===`tailnet`||e===`custom`?e:`loopback`}function Ys(e){if(e.bind===`loopback`)return!1;if(e.bind===`lan`)return!0;if(e.bind===`custom`){let t=e.customBindHost.trim().toLowerCase();return t?t!==`127.0.0.1`&&t!==`localhost`&&t!==`::1`:!0}return!0}function Xs(e){let t=Ys(e);return t&&e.auth.mode===`none`?`Network-accessible gateway requires authentication (token, password, or trusted-proxy).`:t&&e.auth.mode===`trusted-proxy`&&e.trustedProxies.length===0?`Trusted-proxy auth on a network bind requires at least one gateway.trustedProxies entry.`:e.auth.mode===`trusted-proxy`&&!e.auth.trustedProxy.userHeader.trim()?`Trusted-proxy auth requires gateway.auth.trustedProxy.userHeader.`:t&&e.corsOrigins.includes(`*`)?`CORS wildcard "*" is not allowed on network-accessible binds.`:e.bind===`custom`&&!e.customBindHost.trim()?`Custom bind mode requires a bind address.`:null}function Zs(e){let t=Ls(e)?e:{},n=Ls(t.gateway)?t.gateway:{},r=Ls(n.auth)?n.auth:{},i=Ls(n.security)?n.security:{},a=Ls(t.update)?t.update:{},o=Ls(a.auto)?a.auto:{},s=a.channel,c=s===`beta`||s===`dev`||s===`stable`?s:`stable`,l=Array.isArray(n.corsOrigins)?n.corsOrigins.filter(e=>typeof e==`string`&&e.trim().length>0):[];return{bind:Js(n.bind),customBindHost:typeof n.customBindHost==`string`&&n.customBindHost.trim()?n.customBindHost.trim():``,port:typeof n.port==`number`&&Number.isFinite(n.port)?Math.floor(n.port):Fs,auth:{mode:Us(r.mode),token:typeof r.token==`string`?r.token:``,password:typeof r.password==`string`?r.password:``,rateLimit:Ws(r.rateLimit),trustedProxy:Gs(r.trustedProxy)},corsOrigins:l,trustedProxies:qs(n.trustedProxies,64),allowRealIpFallback:n.allowRealIpFallback===!0,dangerouslyAllowHostHeaderOriginFallback:n.dangerouslyAllowHostHeaderOriginFallback===!0,securityStrict:i.strict===!0,maxSseConnections:typeof n.maxSseConnections==`number`&&Number.isFinite(n.maxSseConnections)?Math.max(1,Math.floor(n.maxSseConnections)):100,channelConnectDeferMode:Ks(n.channelConnectDeferMode),channelConnectDeferIds:qs(n.channelConnectDeferIds),channelConnectDeferSkipIds:qs(n.channelConnectDeferSkipIds),updateChannel:c,updateCheckOnStart:a.checkOnStart!==!1,updateAutoEnabled:o.enabled===!0,updateAutoStableDelayHours:typeof o.stableDelayHours==`number`&&Number.isFinite(o.stableDelayHours)?Math.max(0,Math.floor(o.stableDelayHours)):6,updateAutoStableJitterHours:typeof o.stableJitterHours==`number`&&Number.isFinite(o.stableJitterHours)?Math.max(0,Math.floor(o.stableJitterHours)):12,updateAutoBetaCheckIntervalHours:typeof o.betaCheckIntervalHours==`number`&&Number.isFinite(o.betaCheckIntervalHours)?Math.max(.25,o.betaCheckIntervalHours):1}}function Qs(e){let t={mode:e.auth.mode,rateLimit:e.auth.rateLimit};if(e.auth.mode===`token`){let n=e.auth.token.trim();n.length>0&&!Rs(n)&&(t.token=e.auth.token),t.password=null,t.trustedProxy=null}else if(e.auth.mode===`password`){let n=e.auth.password.trim();n.length>0&&!Rs(n)&&(t.password=e.auth.password),t.token=null,t.trustedProxy=null}else if(e.auth.mode===`trusted-proxy`){t.token=null,t.password=null;let n=e.auth.trustedProxy;t.trustedProxy={userHeader:n.userHeader.trim(),...n.requiredHeaders.length>0?{requiredHeaders:n.requiredHeaders}:{},...n.allowUsers.length>0?{allowUsers:n.allowUsers}:{},...n.allowLoopback?{allowLoopback:!0}:{}}}else t.token=null,t.password=null,t.trustedProxy=null;return t}async function $s(e){let t=Xs(e);if(t)throw Error(t);await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{bind:e.bind,...e.bind===`custom`?{customBindHost:e.customBindHost.trim()}:{},port:e.port,auth:Qs(e),corsOrigins:e.corsOrigins,trustedProxies:e.trustedProxies,allowRealIpFallback:e.allowRealIpFallback,dangerouslyAllowHostHeaderOriginFallback:e.dangerouslyAllowHostHeaderOriginFallback,security:{strict:e.securityStrict},maxSseConnections:e.maxSseConnections,channelConnectDeferMode:e.channelConnectDeferMode,channelConnectDeferIds:e.channelConnectDeferIds,channelConnectDeferSkipIds:e.channelConnectDeferSkipIds},update:{channel:e.updateChannel,checkOnStart:e.updateCheckOnStart,auto:{enabled:e.updateAutoEnabled,stableDelayHours:e.updateAutoStableDelayHours,stableJitterHours:e.updateAutoStableJitterHours,betaCheckIntervalHours:e.updateAutoBetaCheckIntervalHours}}})}),mt()}var ec={critical:3,warn:2,info:1};function tc(){return l(`/api/doctor?security=true`)}function nc(e){return e.toSorted((e,t)=>ec[t.severity]-ec[e.severity]||e.checkId.localeCompare(t.checkId))}function rc(e){let t=e?.checks?.find(e=>e.id===`security-audit`);if(!t)return{status:`skip`,message:`Security audit unavailable.`,hints:[],findings:[]};let n=nc((t.findings??[]).filter(e=>typeof e.checkId==`string`&&(e.severity===`critical`||e.severity===`warn`||e.severity===`info`)&&typeof e.title==`string`&&typeof e.detail==`string`));return{status:t.status,message:t.message,hints:Array.isArray(t.hints)?t.hints.filter(e=>typeof e==`string`):[],findings:n}}async function ic(){return rc(await S(tc()))}function ac(e){let t=(0,Q.c)(40),{enabled:n,refreshToken:r}=e,i=r===void 0?0:r,o=a(sc),c;t[0]===o?c=t[1]:(c=s(o),t[0]=o,t[1]=c);let l=c.gatewaySettings,u;t[2]!==n||t[3]!==i?(u=n?[tc(),i]:null,t[2]=n,t[3]=i,t[4]=u):u=t[4];let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p={revalidateOnFocus:!1},t[5]=p):p=t[5];let{data:m,error:h,isLoading:g,isValidating:_,mutate:v}=d(u,oc,p),y=m??null,b=h instanceof Error?h.message:h?String(h):null,x=g||_,S;t[6]===v?S=t[7]:(S=()=>{v(),f(tc())},t[6]=v,t[7]=S);let C=S,w=!n||x,T;t[8]===x?T=t[9]:(T=x?(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ee,{className:`size-3.5`,"aria-hidden":!0}),t[8]=x,t[9]=T);let E;t[10]===l.securityAuditRefresh?E=t[11]:(E=(0,$.jsx)(`span`,{className:`ml-1.5`,children:l.securityAuditRefresh}),t[10]=l.securityAuditRefresh,t[11]=E);let D;t[12]!==C||t[13]!==w||t[14]!==T||t[15]!==E?(D=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:w,onClick:C,children:[T,E]}),t[12]=C,t[13]=w,t[14]=T,t[15]=E,t[16]=D):D=t[16];let O;t[17]!==l.securityAuditSubtitle||t[18]!==l.securityAuditTitle||t[19]!==D?(O=(0,$.jsx)(Sn,{icon:L,title:l.securityAuditTitle,subtitle:l.securityAuditSubtitle,trailing:D}),t[17]=l.securityAuditSubtitle,t[18]=l.securityAuditTitle,t[19]=D,t[20]=O):O=t[20];let k;t[21]===l.securityAuditSavedConfigHint?k=t[22]:(k=(0,$.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:l.securityAuditSavedConfigHint}),t[21]=l.securityAuditSavedConfigHint,t[22]=k);let A;t[23]!==b||t[24]!==l.securityAuditLoadError?(A=b?(0,$.jsxs)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[l.securityAuditLoadError,`: `,b]}):null,t[23]=b,t[24]=l.securityAuditLoadError,t[25]=A):A=t[25];let j;t[26]!==y||t[27]!==b||t[28]!==l.securityAuditLoading||t[29]!==x?(j=!b&&x&&!y?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}),l.securityAuditLoading]}):null,t[26]=y,t[27]=b,t[28]=l.securityAuditLoading,t[29]=x,t[30]=j):j=t[30];let M;t[31]!==y||t[32]!==l?(M=y?(0,$.jsx)(cc,{g:l,audit:y}):null,t[31]=y,t[32]=l,t[33]=M):M=t[33];let N;return t[34]!==O||t[35]!==k||t[36]!==A||t[37]!==j||t[38]!==M?(N=(0,$.jsxs)(wn,{children:[O,k,A,j,M]}),t[34]=O,t[35]=k,t[36]=A,t[37]=j,t[38]=M,t[39]=N):N=t[39],N}function oc(){return ic()}function sc(e){return e.language}function cc(e){let t=(0,Q.c)(40),{g:n,audit:r}=e,i,a,o,s,c,l,u;t[0]!==r.findings||t[1]!==r.status||t[2]!==n?(a=fc(n,r.status,r.findings),u=`space-y-4`,c=J(`rounded-lg border px-3 py-2.5 text-sm`,a.bannerClass),l=`status`,s=`flex items-start gap-2`,i=a.icon,o=J(`mt-0.5 size-4 shrink-0`,a.iconClass),t[0]=r.findings,t[1]=r.status,t[2]=n,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u):(i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9]);let d;t[10]!==i||t[11]!==o?(d=(0,$.jsx)(i,{className:o,"aria-hidden":!0}),t[10]=i,t[11]=o,t[12]=d):d=t[12];let f;t[13]===a.title?f=t[14]:(f=(0,$.jsx)(`p`,{className:`font-medium`,children:a.title}),t[13]=a.title,t[14]=f);let p;t[15]===r.message?p=t[16]:(p=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs opacity-90`,children:r.message}),t[15]=r.message,t[16]=p);let m;t[17]!==f||t[18]!==p?(m=(0,$.jsxs)(`div`,{children:[f,p]}),t[17]=f,t[18]=p,t[19]=m):m=t[19];let h;t[20]!==s||t[21]!==d||t[22]!==m?(h=(0,$.jsxs)(`div`,{className:s,children:[d,m]}),t[20]=s,t[21]=d,t[22]=m,t[23]=h):h=t[23];let g;t[24]!==h||t[25]!==c||t[26]!==l?(g=(0,$.jsx)(`div`,{className:c,role:l,children:h}),t[24]=h,t[25]=c,t[26]=l,t[27]=g):g=t[27];let _;t[28]!==r.findings||t[29]!==r.status||t[30]!==n?(_=r.findings.length>0?(0,$.jsx)(`ul`,{className:`space-y-2`,children:r.findings.map(e=>(0,$.jsx)(uc,{g:n,finding:e},e.checkId))}):r.status===`pass`||r.status===`skip`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.securityAuditNoFindings}):null,t[28]=r.findings,t[29]=r.status,t[30]=n,t[31]=_):_=t[31];let v;t[32]!==r.hints||t[33]!==n?(v=r.hints.length>0?(0,$.jsxs)(`div`,{className:`space-y-1 border-t border-edge pt-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:n.securityAuditHintsTitle}),(0,$.jsx)(`ul`,{className:`space-y-1 text-xs text-fg-subtle`,children:r.hints.map(lc)})]}):null,t[32]=r.hints,t[33]=n,t[34]=v):v=t[34];let y;return t[35]!==g||t[36]!==_||t[37]!==v||t[38]!==u?(y=(0,$.jsxs)(`div`,{className:u,children:[g,_,v]}),t[35]=g,t[36]=_,t[37]=v,t[38]=u,t[39]=y):y=t[39],y}function lc(e){return(0,$.jsx)(`li`,{className:`font-mono`,children:e},e)}function uc(e){let t=(0,Q.c)(31),{g:n,finding:r}=e,i,a,o,s;if(t[0]!==r.severity){let e=dc(r.severity);s=`rounded-lg border border-edge bg-surface-panel/50 px-3 py-2.5`,o=`flex items-start gap-2`,i=e.icon,a=J(`mt-0.5 size-4 shrink-0`,e.iconClass),t[0]=r.severity,t[1]=i,t[2]=a,t[3]=o,t[4]=s}else i=t[1],a=t[2],o=t[3],s=t[4];let c;t[5]!==i||t[6]!==a?(c=(0,$.jsx)(i,{className:a,"aria-hidden":!0}),t[5]=i,t[6]=a,t[7]=c):c=t[7];let l;t[8]===r.title?l=t[9]:(l=(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.title}),t[8]=r.title,t[9]=l);let u;t[10]===r.checkId?u=t[11]:(u=(0,$.jsx)(`span`,{className:`font-mono text-[0.65rem] text-fg-subtle`,children:r.checkId}),t[10]=r.checkId,t[11]=u);let d;t[12]!==l||t[13]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[l,u]}),t[12]=l,t[13]=u,t[14]=d):d=t[14];let f;t[15]===r.detail?f=t[16]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:r.detail}),t[15]=r.detail,t[16]=f);let p;t[17]!==r.remediation||t[18]!==n?(p=r.remediation?(0,$.jsxs)(`p`,{className:`mt-1.5 text-xs text-fg-subtle`,children:[(0,$.jsx)(`span`,{className:`text-fg-muted`,children:n.securityAuditRemediation}),` `,r.remediation]}):null,t[17]=r.remediation,t[18]=n,t[19]=p):p=t[19];let m;t[20]!==d||t[21]!==f||t[22]!==p?(m=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[d,f,p]}),t[20]=d,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;t[24]!==m||t[25]!==o||t[26]!==c?(h=(0,$.jsxs)(`div`,{className:o,children:[c,m]}),t[24]=m,t[25]=o,t[26]=c,t[27]=h):h=t[27];let g;return t[28]!==h||t[29]!==s?(g=(0,$.jsx)(`li`,{className:s,children:h}),t[28]=h,t[29]=s,t[30]=g):g=t[30],g}function dc(e){switch(e){case`critical`:return{icon:Pe,iconClass:`text-red-600 dark:text-red-400`};case`warn`:return{icon:ut,iconClass:`text-amber-600 dark:text-amber-400`};default:return{icon:At,iconClass:`text-fg-muted`}}}function fc(e,t,n){let r=n.filter(e=>e.severity===`critical`).length,i=n.filter(e=>e.severity===`warn`).length;return t===`fail`||r>0?{icon:Pe,iconClass:`text-red-600 dark:text-red-400`,title:e.securityAuditStatusFail,bannerClass:`border-red-200 bg-red-50 text-red-950 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-100`}:t===`warn`||i>0?{icon:ut,iconClass:`text-amber-600 dark:text-amber-400`,title:e.securityAuditStatusWarn,bannerClass:`border-amber-200 bg-amber-50 text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`}:t===`skip`?{icon:At,iconClass:`text-fg-muted`,title:e.securityAuditStatusSkip,bannerClass:`border-edge bg-surface-panel/60 text-fg`}:{icon:L,iconClass:`text-emerald-600 dark:text-emerald-400`,title:e.securityAuditStatusPass,bannerClass:`border-emerald-200 bg-emerald-50 text-emerald-950 dark:border-emerald-900/50 dark:bg-emerald-950/40 dark:text-emerald-100`}}function pc(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}var mc=[`network`,`access`,`updates`,`security`,`advanced`],hc={network:Ke,access:It,updates:Ee,security:B,advanced:nn};function gc(e){return e&&mc.includes(e)?e:`network`}function _c(e,t){return t===`network`?e.tabNetwork:t===`access`?e.tabAccess:t===`updates`?e.tabUpdates:t===`security`?e.tabSecurity:e.tabAdvanced}function vc(e,t){return t===`network`?e.networkTabHint:t===`access`?e.accessTabHint:t===`updates`?e.updatesTabHint:t===`security`?e.securitySectionHint:e.advancedSectionHint}function yc(e,t){switch(t.type){case`reset`:return{form:null,baseline:null,appliedBaseline:null};case`init-applied`:return{...e,appliedBaseline:structuredClone(t.value)};case`sync`:{let n=structuredClone(t.value);return{form:n,baseline:structuredClone(n),appliedBaseline:e.appliedBaseline}}case`set-form`:return e.form?{...e,form:t.updater(e.form)}:e;case`discard`:return e.baseline?{...e,form:structuredClone(e.baseline)}:e;case`saved`:{let n=structuredClone(t.value);return{form:n,baseline:structuredClone(n),appliedBaseline:e.appliedBaseline}}}}var bc={saving:!1,error:null,saveOk:!1,showAccessToken:!1,showPassword:!1,copied:!1,auditRefreshToken:0,restarting:!1,restartConfirmOpen:!1};function xc(){let e=a(e=>e.language),t=s(e),n=t.gatewaySettings,[r,i]=ot(),o=gc(r.get(`tab`)),c=(0,Z.useCallback)(e=>{i(t=>{let n=new URLSearchParams(t);return e===`network`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[i]),l=x(e=>e.token),u=x(e=>e.tokenExpired),d=x(e=>e.openTokenDialog),f=!!l,[p,m]=(0,Z.useReducer)(yc,{form:null,baseline:null,appliedBaseline:null}),h=p.form,g=p.baseline,_=p.appliedBaseline,[v,y]=(0,Z.useReducer)(Gt,bc),{saving:b,error:S,saveOk:C,showAccessToken:w,showPassword:T,copied:E,auditRefreshToken:D,restarting:O,restartConfirmOpen:k}=v,A=(0,Z.useRef)(!1),j=(0,Z.useRef)(null),M=(0,Z.useRef)(!1),{data:N,error:P,isLoading:F,mutate:I}=Ze(f),L=(0,Z.useMemo)(()=>N?.payload?.config===void 0?null:structuredClone(Zs(N.payload.config)),[N]);f?L!==null&&(M.current||(M.current=!0,m({type:`init-applied`,value:L})),!A.current&&j.current!==L&&(j.current=L,m({type:`sync`,value:L}),y({type:`patch`,patch:{saveOk:!1}}))):(j.current!==null||M.current)&&(j.current=null,M.current=!1,m({type:`reset`}),A.current=!1);let R=!!(f&&F&&N===void 0&&!P),z=P instanceof Error?P.message:P?String(P):null,B=(0,Z.useMemo)(()=>!h||!g?!1:JSON.stringify(h)!==JSON.stringify(g),[h,g]),V=(0,Z.useMemo)(()=>!g||!_?!1:Hs(_,g),[_,g]),H=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,auth:{...t.auth,...e}})})},[]),U=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,updateChannel:e})})},[]),W=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,corsOrigins:e})})},[]),G=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,bind:e})})},[]),ee=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,customBindHost:e,bind:`custom`})})},[]),te=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,port:e})})},[]),ne=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,auth:{...t.auth,rateLimit:{...t.auth.rateLimit,...e}}})})},[]),re=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,maxSseConnections:e})})},[]),ie=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,channelConnectDeferMode:e})})},[]),ae=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,channelConnectDeferIds:e})})},[]),oe=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,channelConnectDeferSkipIds:e})})},[]),se=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,trustedProxies:e})})},[]),ce=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,auth:{...t.auth,trustedProxy:{...t.auth.trustedProxy,...e}}})})},[]),le=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,securityStrict:e})})},[]),de=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,allowRealIpFallback:e})})},[]),fe=(0,Z.useCallback)(e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,dangerouslyAllowHostHeaderOriginFallback:e})})},[]),pe=(0,Z.useCallback)(async()=>{if(!h||b)return;let e=Xs(h);if(e){y({type:`patch`,patch:{error:e}});return}y({type:`patch`,patch:{saving:!0,error:null,saveOk:!1}});try{await $s(h),A.current=!1,m({type:`saved`,value:h}),y({type:`patch`,patch:{saveOk:!0,auditRefreshToken:D+1}}),window.setTimeout(()=>y({type:`patch`,patch:{saveOk:!1}}),2500)}catch(e){y({type:`patch`,patch:{error:e instanceof Error?e.message:n.saveError}})}finally{y({type:`patch`,patch:{saving:!1}})}},[h,b,n.saveError]),me=(0,Z.useCallback)(()=>{g&&(A.current=!1,m({type:`discard`}),y({type:`patch`,patch:{error:null,saveOk:!1}}))},[g]),he=(0,Z.useCallback)(async()=>{let e=h?.auth.token;e&&await K(e)&&(y({type:`patch`,patch:{copied:!0}}),window.setTimeout(()=>y({type:`patch`,patch:{copied:!1}}),2e3))},[h?.auth.token]),ge=(0,Z.useCallback)(async()=>{if(!O){y({type:`patch`,patch:{restarting:!0,restartConfirmOpen:!1}});try{let e=await st();e.ok?window.dispatchEvent(new Event(`gateway-restart-initiated`)):window.dispatchEvent(new CustomEvent(`extension-notification`,{detail:{type:`error`,title:n.restartGatewayFailed,message:e.message??``}}))}catch(e){window.dispatchEvent(new CustomEvent(`extension-notification`,{detail:{type:`error`,title:n.restartGatewayFailed,message:e instanceof Error?e.message:String(e)}}))}finally{y({type:`patch`,patch:{restarting:!1}})}}},[O,n.restartGatewayFailed]);return f?R?(0,$.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),n.loading]})}):h?(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,$.jsxs)(`a`,{href:Be(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,$.jsx)(Me,{className:`size-3.5`})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[C?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!B||b,onClick:me,children:n.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!B||b,onClick:()=>void pe(),children:b?n.saving:n.save})]})]}),u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 dark:border-red-900/50 dark:bg-red-950/40`,role:`alert`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Pe,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,$.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,$.jsx)(`div`,{children:(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>d(),children:n.updateToken})})]}):null,B?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,S?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null,V?(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 dark:border-amber-800 dark:bg-amber-950/40`,children:[(0,$.jsx)(`p`,{className:`text-xs text-amber-950 dark:text-amber-100`,children:n.restartHint}),(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`shrink-0 gap-1.5 border-red-300 bg-red-50 text-xs text-red-700 hover:bg-red-100 dark:border-red-800 dark:bg-red-950/50 dark:text-red-300 dark:hover:bg-red-900/60`,disabled:O,onClick:()=>y({type:`patch`,patch:{restartConfirmOpen:!0}}),children:[O?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(ue,{className:`size-3.5`}),n.restartGatewayButton]})]}):null,(0,$.jsx)(Jt,{open:k,title:n.restartGatewayButton,description:n.restartGatewayConfirm,confirmLabel:n.restartGatewayButton,cancelLabel:n.discard,destructive:!0,onConfirm:()=>void ge(),onCancel:()=>y({type:`patch`,patch:{restartConfirmOpen:!1}})}),(0,$.jsx)(Sc,{g:n,activeTab:o,onChange:c}),(0,$.jsxs)(Cc,{g:n,id:`network`,activeTab:o,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-bind-mode`,children:n.bindMode}),(0,$.jsxs)(`select`,{id:`gateway-bind-mode`,className:pc(),value:h.bind,onChange:e=>G(e.target.value),children:[(0,$.jsx)(`option`,{value:`loopback`,children:n.bindLoopback}),(0,$.jsx)(`option`,{value:`lan`,children:n.bindLan}),(0,$.jsx)(`option`,{value:`auto`,children:n.bindAuto}),(0,$.jsx)(`option`,{value:`custom`,children:n.bindCustom}),(0,$.jsx)(`option`,{value:`tailnet`,children:n.bindTailnet})]})]}),h.bind===`custom`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-custom-bind-host`,children:n.customBindHost}),(0,$.jsx)(`input`,{id:`gateway-custom-bind-host`,className:J(pc(),`font-mono text-xs`),value:h.customBindHost,onChange:e=>ee(e.target.value),placeholder:n.customBindHostPlaceholder,autoComplete:`off`})]}):null,(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-listen-port`,children:n.listenPort}),(0,$.jsx)(`input`,{id:`gateway-listen-port`,type:`number`,min:1,max:65535,className:J(pc(),`font-mono text-xs`),value:h.port,onChange:e=>{let t=Number(e.target.value);te(Number.isFinite(t)?Math.max(1,Math.min(65535,Math.floor(t))):h.port)}})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:n.listenHint})]}),(0,$.jsx)(Oc,{g:n,origins:h.corsOrigins,onChange:W})]}),(0,$.jsxs)(Cc,{g:n,id:`access`,activeTab:o,children:[h.auth.mode===`none`?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-auth-mode`,children:n.authMode}),(0,$.jsxs)(`select`,{id:`gateway-auth-mode`,value:h.auth.mode,onChange:e=>H({mode:e.target.value}),className:pc(),children:[(0,$.jsx)(`option`,{value:`token`,children:n.authModeToken}),(0,$.jsx)(`option`,{value:`password`,children:n.authModePassword}),(0,$.jsx)(`option`,{value:`trusted-proxy`,children:n.authModeTrustedProxy}),(0,$.jsx)(`option`,{value:`none`,children:n.authModeNoneLabel})]})]}),h.auth.mode===`trusted-proxy`?(0,$.jsx)(Tc,{g:n,form:h,onTrustedProxyChange:ce,onTrustedProxiesChange:se,onAllowRealIpFallbackChange:de}):null,h.auth.mode===`token`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ac,{g:n,id:`gateway-access-token`,label:n.accessToken,help:n.tokenHelp,placeholder:n.tokenPlaceholder,value:h.auth.token,show:w,copied:E,onToggleShow:()=>y({type:`patch`,patch:{showAccessToken:!w}}),onCopy:()=>void he(),onChange:e=>H({token:e})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>d(),children:n.changeToken})]}):null,h.auth.mode===`password`?(0,$.jsx)(Ac,{g:n,id:`gateway-auth-password`,label:n.authPassword,help:n.authPasswordHelp,placeholder:n.authPasswordPlaceholder,value:h.auth.password,show:T,onToggleShow:()=>y({type:`patch`,patch:{showPassword:!T}}),onChange:e=>H({password:e})}):null,h.auth.mode===`none`?null:(0,$.jsx)(kc,{g:n,rateLimit:h.auth.rateLimit,onChange:ne})]}),(0,$.jsxs)(Cc,{g:n,id:`updates`,activeTab:o,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,$.jsxs)(`select`,{id:`gateway-update-channel`,value:h.updateChannel,onChange:e=>U(e.target.value),className:pc(),children:[(0,$.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,$.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,$.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]}),(0,$.jsxs)(`div`,{className:`space-y-4 border-t border-edge pt-4`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.updateAutoSection}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateAutoSectionHint}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:h.updateCheckOnStart,onChange:e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,updateCheckOnStart:e.target.checked})})}}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:n.updateCheckOnStart}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.updateCheckOnStartHint})]})]}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:h.updateAutoEnabled,onChange:e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoEnabled:e.target.checked})})}}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:n.updateAutoEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.updateAutoEnabledHint})]})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`update-auto-stable-delay`,children:n.updateAutoStableDelayHours}),(0,$.jsx)(`input`,{id:`update-auto-stable-delay`,type:`number`,min:0,disabled:!h.updateAutoEnabled,className:pc(),value:h.updateAutoStableDelayHours,onChange:e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoStableDelayHours:Math.max(0,Math.floor(Number(e.target.value)||0))})})}}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.updateAutoStableDelayHoursHint})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`update-auto-stable-jitter`,children:n.updateAutoStableJitterHours}),(0,$.jsx)(`input`,{id:`update-auto-stable-jitter`,type:`number`,min:0,disabled:!h.updateAutoEnabled,className:pc(),value:h.updateAutoStableJitterHours,onChange:e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoStableJitterHours:Math.max(0,Math.floor(Number(e.target.value)||0))})})}}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.updateAutoStableJitterHoursHint})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`update-auto-beta-interval`,children:n.updateAutoBetaCheckIntervalHours}),(0,$.jsx)(`input`,{id:`update-auto-beta-interval`,type:`number`,min:.25,step:.25,disabled:!h.updateAutoEnabled,className:pc(),value:h.updateAutoBetaCheckIntervalHours,onChange:e=>{A.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoBetaCheckIntervalHours:Math.max(.25,Number(e.target.value)||1)})})}}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.updateAutoBetaCheckIntervalHoursHint})]})]})]})]}),(0,$.jsxs)(Cc,{g:n,id:`security`,activeTab:o,children:[(0,$.jsx)(ac,{enabled:f,refreshToken:D}),(0,$.jsx)(wc,{g:n,form:h,onSecurityStrictChange:le,onDangerouslyAllowHostHeaderOriginFallbackChange:fe})]}),(0,$.jsx)(Cc,{g:n,id:`advanced`,activeTab:o,children:(0,$.jsx)(Ec,{g:n,form:h,onMaxSseConnectionsChange:re,onDeferModeChange:ie,onDeferIdsChange:ae,onSkipIdsChange:oe})})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:S??z??n.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>void I(),children:n.retry})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Sc(e){let t=(0,Q.c)(11),{g:n,activeTab:r,onChange:i}=e,a=n.tabsAriaLabel,o;t[0]!==r||t[1]!==i?(o=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),i(mc[(mc.indexOf(r)+(e.key===`ArrowRight`?1:-1)+mc.length)%mc.length]))},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==n||t[5]!==i?(s=mc.map(e=>{let t=hc[e],a=e===r;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,"aria-controls":`gateway-settings-panel-${e}`,id:`gateway-settings-tab-${e}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>i(e),children:[(0,$.jsx)(t,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:_c(n,e)})]},e)}),t[3]=r,t[4]=n,t[5]=i,t[6]=s):s=t[6];let c;return t[7]!==n.tabsAriaLabel||t[8]!==o||t[9]!==s?(c=(0,$.jsx)(`nav`,{"aria-label":a,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,onKeyDown:o,children:s}),t[7]=n.tabsAriaLabel,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Cc(e){let t=(0,Q.c)(20),{g:n,id:r,activeTab:i,children:a}=e;if(i!==r)return null;let o=`gateway-settings-panel-${r}`,s=`gateway-settings-tab-${r}`,c;t[0]!==n||t[1]!==r?(c=_c(n,r),t[0]=n,t[1]=r,t[2]=c):c=t[2];let l;t[3]===c?l=t[4]:(l=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:c}),t[3]=c,t[4]=l);let u;t[5]!==n||t[6]!==r?(u=vc(n,r),t[5]=n,t[6]=r,t[7]=u):u=t[7];let d;t[8]===u?d=t[9]:(d=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u}),t[8]=u,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:`mb-5`,children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;t[13]===a?p=t[14]:(p=(0,$.jsx)(`div`,{className:`space-y-4`,children:a}),t[13]=a,t[14]=p);let m;return t[15]!==o||t[16]!==s||t[17]!==f||t[18]!==p?(m=(0,$.jsxs)(`section`,{id:o,role:`tabpanel`,"aria-labelledby":s,className:`rounded-2xl border border-edge bg-surface-base px-4 py-5 sm:px-5`,children:[f,p]}),t[15]=o,t[16]=s,t[17]=f,t[18]=p,t[19]=m):m=t[19],m}function wc(e){let t=(0,Q.c)(37),{g:n,form:r,onSecurityStrictChange:i,onDangerouslyAllowHostHeaderOriginFallbackChange:a}=e,o;t[0]===i?o=t[1]:(o=e=>i(e.target.checked),t[0]=i,t[1]=o);let s;t[2]!==r.securityStrict||t[3]!==o?(s=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.securityStrict,onChange:o}),t[2]=r.securityStrict,t[3]=o,t[4]=s):s=t[4];let c;t[5]===n.securityStrict?c=t[6]:(c=(0,$.jsx)(`span`,{className:`font-medium`,children:n.securityStrict}),t[5]=n.securityStrict,t[6]=c);let l;t[7]===n.securityStrictHint?l=t[8]:(l=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.securityStrictHint}),t[7]=n.securityStrictHint,t[8]=l);let u;t[9]!==c||t[10]!==l?(u=(0,$.jsxs)(`span`,{children:[c,l]}),t[9]=c,t[10]=l,t[11]=u):u=t[11];let d;t[12]!==s||t[13]!==u?(d=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[s,u]}),t[12]=s,t[13]=u,t[14]=d):d=t[14];let f;t[15]===a?f=t[16]:(f=e=>a(e.target.checked),t[15]=a,t[16]=f);let p;t[17]!==r.dangerouslyAllowHostHeaderOriginFallback||t[18]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.dangerouslyAllowHostHeaderOriginFallback,onChange:f}),t[17]=r.dangerouslyAllowHostHeaderOriginFallback,t[18]=f,t[19]=p):p=t[19];let m;t[20]===n.dangerouslyAllowHostHeaderOriginFallback?m=t[21]:(m=(0,$.jsx)(`span`,{className:`font-medium`,children:n.dangerouslyAllowHostHeaderOriginFallback}),t[20]=n.dangerouslyAllowHostHeaderOriginFallback,t[21]=m);let h;t[22]===n.dangerouslyAllowHostHeaderOriginFallbackHint?h=t[23]:(h=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.dangerouslyAllowHostHeaderOriginFallbackHint}),t[22]=n.dangerouslyAllowHostHeaderOriginFallbackHint,t[23]=h);let g;t[24]!==h||t[25]!==m?(g=(0,$.jsxs)(`span`,{children:[m,h]}),t[24]=h,t[25]=m,t[26]=g):g=t[26];let _;t[27]!==g||t[28]!==p?(_=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[p,g]}),t[27]=g,t[28]=p,t[29]=_):_=t[29];let v;t[30]!==r.dangerouslyAllowHostHeaderOriginFallback||t[31]!==n.dangerouslyAllowHostHeaderOriginFallbackWarning?(v=r.dangerouslyAllowHostHeaderOriginFallback?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.dangerouslyAllowHostHeaderOriginFallbackWarning}):null,t[30]=r.dangerouslyAllowHostHeaderOriginFallback,t[31]=n.dangerouslyAllowHostHeaderOriginFallbackWarning,t[32]=v):v=t[32];let y;return t[33]!==_||t[34]!==v||t[35]!==d?(y=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[d,_,v]}),t[33]=_,t[34]=v,t[35]=d,t[36]=y):y=t[36],y}function Tc(e){let t=(0,Q.c)(80),{g:n,form:r,onTrustedProxyChange:i,onTrustedProxiesChange:a,onAllowRealIpFallbackChange:o}=e,s=r.auth.trustedProxy,c;t[0]===n.authModeTrustedProxyHint?c=t[1]:(c=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.authModeTrustedProxyHint}),t[0]=n.authModeTrustedProxyHint,t[1]=c);let l;t[2]===n.trustedProxyUserHeader?l=t[3]:(l=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-trusted-proxy-user-header`,children:n.trustedProxyUserHeader}),t[2]=n.trustedProxyUserHeader,t[3]=l);let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(pc(),`font-mono text-xs`),t[4]=u):u=t[4];let d;t[5]===i?d=t[6]:(d=e=>i({userHeader:e.target.value}),t[5]=i,t[6]=d);let f;t[7]!==n.trustedProxyUserHeaderPlaceholder||t[8]!==d||t[9]!==s.userHeader?(f=(0,$.jsx)(`input`,{id:`gateway-trusted-proxy-user-header`,className:u,value:s.userHeader,onChange:d,placeholder:n.trustedProxyUserHeaderPlaceholder,autoComplete:`off`}),t[7]=n.trustedProxyUserHeaderPlaceholder,t[8]=d,t[9]=s.userHeader,t[10]=f):f=t[10];let p;t[11]===n.trustedProxyUserHeaderHint?p=t[12]:(p=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.trustedProxyUserHeaderHint}),t[11]=n.trustedProxyUserHeaderHint,t[12]=p);let m;t[13]!==l||t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(`div`,{children:[l,f,p]}),t[13]=l,t[14]=f,t[15]=p,t[16]=m):m=t[16];let h;t[17]===i?h=t[18]:(h=e=>i({requiredHeaders:e}),t[17]=i,t[18]=h);let g;t[19]!==n.channelIdListEmpty||t[20]!==n.trustedProxyRequiredHeaders||t[21]!==n.trustedProxyRequiredHeadersHint||t[22]!==n.trustedProxyUserHeaderPlaceholder||t[23]!==h||t[24]!==s.requiredHeaders?(g=(0,$.jsx)(Dc,{title:n.trustedProxyRequiredHeaders,hint:n.trustedProxyRequiredHeadersHint,emptyText:n.channelIdListEmpty,placeholder:n.trustedProxyUserHeaderPlaceholder,values:s.requiredHeaders,maxItems:32,onChange:h}),t[19]=n.channelIdListEmpty,t[20]=n.trustedProxyRequiredHeaders,t[21]=n.trustedProxyRequiredHeadersHint,t[22]=n.trustedProxyUserHeaderPlaceholder,t[23]=h,t[24]=s.requiredHeaders,t[25]=g):g=t[25];let _;t[26]===i?_=t[27]:(_=e=>i({allowUsers:e}),t[26]=i,t[27]=_);let v;t[28]!==n.channelIdListEmpty||t[29]!==n.trustedProxyAllowUsers||t[30]!==n.trustedProxyAllowUsersHint||t[31]!==n.trustedProxyUserHeaderPlaceholder||t[32]!==_||t[33]!==s.allowUsers?(v=(0,$.jsx)(Dc,{title:n.trustedProxyAllowUsers,hint:n.trustedProxyAllowUsersHint,emptyText:n.channelIdListEmpty,placeholder:n.trustedProxyUserHeaderPlaceholder,values:s.allowUsers,maxItems:128,onChange:_}),t[28]=n.channelIdListEmpty,t[29]=n.trustedProxyAllowUsers,t[30]=n.trustedProxyAllowUsersHint,t[31]=n.trustedProxyUserHeaderPlaceholder,t[32]=_,t[33]=s.allowUsers,t[34]=v):v=t[34];let y;t[35]===i?y=t[36]:(y=e=>i({allowLoopback:e.target.checked}),t[35]=i,t[36]=y);let b;t[37]!==y||t[38]!==s.allowLoopback?(b=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:s.allowLoopback,onChange:y}),t[37]=y,t[38]=s.allowLoopback,t[39]=b):b=t[39];let x;t[40]===n.trustedProxyAllowLoopback?x=t[41]:(x=(0,$.jsx)(`span`,{className:`font-medium`,children:n.trustedProxyAllowLoopback}),t[40]=n.trustedProxyAllowLoopback,t[41]=x);let S;t[42]===n.trustedProxyAllowLoopbackHint?S=t[43]:(S=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.trustedProxyAllowLoopbackHint}),t[42]=n.trustedProxyAllowLoopbackHint,t[43]=S);let C;t[44]!==x||t[45]!==S?(C=(0,$.jsxs)(`span`,{children:[x,S]}),t[44]=x,t[45]=S,t[46]=C):C=t[46];let w;t[47]!==b||t[48]!==C?(w=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[b,C]}),t[47]=b,t[48]=C,t[49]=w):w=t[49];let T;t[50]!==r.trustedProxies||t[51]!==n.trustedProxies||t[52]!==n.trustedProxiesEmpty||t[53]!==n.trustedProxiesHint||t[54]!==n.trustedProxiesPlaceholder||t[55]!==a?(T=(0,$.jsx)(Dc,{title:n.trustedProxies,hint:n.trustedProxiesHint,emptyText:n.trustedProxiesEmpty,placeholder:n.trustedProxiesPlaceholder,values:r.trustedProxies,maxItems:64,onChange:a}),t[50]=r.trustedProxies,t[51]=n.trustedProxies,t[52]=n.trustedProxiesEmpty,t[53]=n.trustedProxiesHint,t[54]=n.trustedProxiesPlaceholder,t[55]=a,t[56]=T):T=t[56];let E;t[57]===o?E=t[58]:(E=e=>o(e.target.checked),t[57]=o,t[58]=E);let D;t[59]!==r.allowRealIpFallback||t[60]!==E?(D=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.allowRealIpFallback,onChange:E}),t[59]=r.allowRealIpFallback,t[60]=E,t[61]=D):D=t[61];let O;t[62]===n.allowRealIpFallback?O=t[63]:(O=(0,$.jsx)(`span`,{className:`font-medium`,children:n.allowRealIpFallback}),t[62]=n.allowRealIpFallback,t[63]=O);let k;t[64]===n.allowRealIpFallbackHint?k=t[65]:(k=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.allowRealIpFallbackHint}),t[64]=n.allowRealIpFallbackHint,t[65]=k);let A;t[66]!==O||t[67]!==k?(A=(0,$.jsxs)(`span`,{children:[O,k]}),t[66]=O,t[67]=k,t[68]=A):A=t[68];let j;t[69]!==D||t[70]!==A?(j=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[D,A]}),t[69]=D,t[70]=A,t[71]=j):j=t[71];let M;return t[72]!==c||t[73]!==v||t[74]!==w||t[75]!==T||t[76]!==j||t[77]!==m||t[78]!==g?(M=(0,$.jsxs)(`div`,{className:`space-y-4 border-t border-edge pt-4`,children:[c,m,g,v,w,T,j]}),t[72]=c,t[73]=v,t[74]=w,t[75]=T,t[76]=j,t[77]=m,t[78]=g,t[79]=M):M=t[79],M}function Ec(e){let t=(0,Q.c)(58),{g:n,form:r,onMaxSseConnectionsChange:i,onDeferModeChange:a,onDeferIdsChange:o,onSkipIdsChange:s}=e,c;t[0]===n.maxSseConnections?c=t[1]:(c=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-max-sse`,children:n.maxSseConnections}),t[0]=n.maxSseConnections,t[1]=c);let l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(pc(),`max-w-xs font-mono text-xs`),t[2]=l):l=t[2];let u;t[3]===i?u=t[4]:(u=e=>{let t=Number(e.target.value);Number.isFinite(t)&&i(Math.max(1,Math.floor(t)))},t[3]=i,t[4]=u);let d;t[5]!==r.maxSseConnections||t[6]!==u?(d=(0,$.jsx)(`input`,{id:`gateway-max-sse`,type:`number`,min:1,className:l,value:r.maxSseConnections,onChange:u}),t[5]=r.maxSseConnections,t[6]=u,t[7]=d):d=t[7];let f;t[8]===n.maxSseConnectionsHint?f=t[9]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.maxSseConnectionsHint}),t[8]=n.maxSseConnectionsHint,t[9]=f);let p;t[10]!==c||t[11]!==d||t[12]!==f?(p=(0,$.jsxs)(`div`,{children:[c,d,f]}),t[10]=c,t[11]=d,t[12]=f,t[13]=p):p=t[13];let m;t[14]===n.channelConnectDeferMode?m=t[15]:(m=(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-channel-defer-mode`,children:n.channelConnectDeferMode}),t[14]=n.channelConnectDeferMode,t[15]=m);let h=r.channelConnectDeferMode,g;t[16]===a?g=t[17]:(g=e=>a(e.target.value),t[16]=a,t[17]=g);let _;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(_=pc(),t[18]=_):_=t[18];let v;t[19]===n.channelConnectDeferModeAuto?v=t[20]:(v=(0,$.jsx)(`option`,{value:`auto`,children:n.channelConnectDeferModeAuto}),t[19]=n.channelConnectDeferModeAuto,t[20]=v);let y;t[21]===n.channelConnectDeferModeOff?y=t[22]:(y=(0,$.jsx)(`option`,{value:`off`,children:n.channelConnectDeferModeOff}),t[21]=n.channelConnectDeferModeOff,t[22]=y);let b;t[23]===n.channelConnectDeferModeExplicit?b=t[24]:(b=(0,$.jsx)(`option`,{value:`explicit`,children:n.channelConnectDeferModeExplicit}),t[23]=n.channelConnectDeferModeExplicit,t[24]=b);let x;t[25]!==r.channelConnectDeferMode||t[26]!==v||t[27]!==y||t[28]!==b||t[29]!==g?(x=(0,$.jsxs)(`select`,{id:`gateway-channel-defer-mode`,value:h,onChange:g,className:_,children:[v,y,b]}),t[25]=r.channelConnectDeferMode,t[26]=v,t[27]=y,t[28]=b,t[29]=g,t[30]=x):x=t[30];let S;t[31]===n.channelConnectDeferModeHint?S=t[32]:(S=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.channelConnectDeferModeHint}),t[31]=n.channelConnectDeferModeHint,t[32]=S);let C;t[33]!==x||t[34]!==S||t[35]!==m?(C=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[m,x,S]}),t[33]=x,t[34]=S,t[35]=m,t[36]=C):C=t[36];let w;t[37]!==r.channelConnectDeferIds||t[38]!==r.channelConnectDeferMode||t[39]!==n.channelConnectDeferIds||t[40]!==n.channelConnectDeferIdsHint||t[41]!==n.channelIdListEmpty||t[42]!==n.channelIdListPlaceholder||t[43]!==o?(w=r.channelConnectDeferMode===`explicit`?(0,$.jsx)(Dc,{title:n.channelConnectDeferIds,hint:n.channelConnectDeferIdsHint,emptyText:n.channelIdListEmpty,placeholder:n.channelIdListPlaceholder,values:r.channelConnectDeferIds,maxItems:24,onChange:o}):null,t[37]=r.channelConnectDeferIds,t[38]=r.channelConnectDeferMode,t[39]=n.channelConnectDeferIds,t[40]=n.channelConnectDeferIdsHint,t[41]=n.channelIdListEmpty,t[42]=n.channelIdListPlaceholder,t[43]=o,t[44]=w):w=t[44];let T;t[45]!==r.channelConnectDeferMode||t[46]!==r.channelConnectDeferSkipIds||t[47]!==n.channelConnectDeferSkipIds||t[48]!==n.channelConnectDeferSkipIdsHint||t[49]!==n.channelIdListEmpty||t[50]!==n.channelIdListPlaceholder||t[51]!==s?(T=r.channelConnectDeferMode===`off`?null:(0,$.jsx)(Dc,{title:n.channelConnectDeferSkipIds,hint:n.channelConnectDeferSkipIdsHint,emptyText:n.channelIdListEmpty,placeholder:n.channelIdListPlaceholder,values:r.channelConnectDeferSkipIds,maxItems:24,onChange:s}),t[45]=r.channelConnectDeferMode,t[46]=r.channelConnectDeferSkipIds,t[47]=n.channelConnectDeferSkipIds,t[48]=n.channelConnectDeferSkipIdsHint,t[49]=n.channelIdListEmpty,t[50]=n.channelIdListPlaceholder,t[51]=s,t[52]=T):T=t[52];let E;return t[53]!==C||t[54]!==w||t[55]!==T||t[56]!==p?(E=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[p,C,w,T]}),t[53]=C,t[54]=w,t[55]=T,t[56]=p,t[57]=E):E=t[57],E}function Dc(e){let t=(0,Q.c)(25),{title:n,hint:r,emptyText:i,placeholder:a,values:o,maxItems:s,onChange:c,children:l}=e,u;t[0]!==s||t[1]!==c||t[2]!==o?(u=e=>{let t=e.trim();!t||o.includes(t)||o.length>=s||c([...o,t])},t[0]=s,t[1]=c,t[2]=o,t[3]=u):u=t[3];let d=u,f;t[4]===n?f=t[5]:(f=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[4]=n,t[5]=f);let p;t[6]===r?p=t[7]:(p=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r}),t[6]=r,t[7]=p);let m;t[8]!==i||t[9]!==c||t[10]!==o?(m=o.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i}):(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:o.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-panel px-2 py-0.5 font-mono text-xs text-fg`,children:[e,(0,$.jsx)(`button`,{type:`button`,className:J(`text-fg-muted hover:text-fg`,X.press),"aria-label":`Remove ${e}`,onClick:()=>c(o.filter(t=>t!==e)),children:`×`})]},e))}),t[8]=i,t[9]=c,t[10]=o,t[11]=m):m=t[11];let h;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(h=J(pc(),`font-mono text-xs`),t[12]=h):h=t[12];let g=o.length>=s,_;t[13]===d?_=t[14]:(_=e=>{e.key===`Enter`&&(e.preventDefault(),d(e.target.value),e.target.value=``)},t[13]=d,t[14]=_);let v;t[15]!==a||t[16]!==g||t[17]!==_?(v=(0,$.jsx)(`input`,{className:h,placeholder:a,disabled:g,onKeyDown:_}),t[15]=a,t[16]=g,t[17]=_,t[18]=v):v=t[18];let y;return t[19]!==l||t[20]!==f||t[21]!==p||t[22]!==m||t[23]!==v?(y=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[f,p,m,v,l]}),t[19]=l,t[20]=f,t[21]=p,t[22]=m,t[23]=v,t[24]=y):y=t[24],y}function Oc(e){let t=(0,Q.c)(13),{g:n,origins:r,onChange:i}=e,a;t[0]===r?a=t[1]:(a=r.includes(`*`),t[0]=r,t[1]=a);let o=a,s;t[2]!==n.corsOriginsWildcardWarning||t[3]!==o?(s=o?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.corsOriginsWildcardWarning}):null,t[2]=n.corsOriginsWildcardWarning,t[3]=o,t[4]=s):s=t[4];let c;return t[5]!==n.corsOrigins||t[6]!==n.corsOriginsEmpty||t[7]!==n.corsOriginsHint||t[8]!==n.corsOriginsPlaceholder||t[9]!==i||t[10]!==r||t[11]!==s?(c=(0,$.jsx)(Dc,{title:n.corsOrigins,hint:n.corsOriginsHint,emptyText:n.corsOriginsEmpty,placeholder:n.corsOriginsPlaceholder,values:r,maxItems:128,onChange:i,children:s}),t[5]=n.corsOrigins,t[6]=n.corsOriginsEmpty,t[7]=n.corsOriginsHint,t[8]=n.corsOriginsPlaceholder,t[9]=i,t[10]=r,t[11]=s,t[12]=c):c=t[12],c}function kc(e){let t=(0,Q.c)(73),{g:n,rateLimit:r,onChange:i}=e,a;t[0]===n.rateLimitTitle?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.rateLimitTitle}),t[0]=n.rateLimitTitle,t[1]=a);let o;t[2]===n.rateLimitHint?o=t[3]:(o=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.rateLimitHint}),t[2]=n.rateLimitHint,t[3]=o);let s;t[4]!==a||t[5]!==o?(s=(0,$.jsxs)(`div`,{children:[a,o]}),t[4]=a,t[5]=o,t[6]=s):s=t[6];let c;t[7]===i?c=t[8]:(c=e=>i({enabled:e.target.checked}),t[7]=i,t[8]=c);let l;t[9]!==r.enabled||t[10]!==c?(l=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:c}),t[9]=r.enabled,t[10]=c,t[11]=l):l=t[11];let u;t[12]!==n.rateLimitEnabled||t[13]!==l?(u=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[l,n.rateLimitEnabled]}),t[12]=n.rateLimitEnabled,t[13]=l,t[14]=u):u=t[14];let d=!r.enabled,f;t[15]===i?f=t[16]:(f=e=>i({exemptLoopback:e.target.checked}),t[15]=i,t[16]=f);let p;t[17]!==r.exemptLoopback||t[18]!==d||t[19]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.exemptLoopback,disabled:d,onChange:f}),t[17]=r.exemptLoopback,t[18]=d,t[19]=f,t[20]=p):p=t[20];let m;t[21]!==n.rateLimitExemptLoopback||t[22]!==p?(m=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[p,n.rateLimitExemptLoopback]}),t[21]=n.rateLimitExemptLoopback,t[22]=p,t[23]=m):m=t[23];let h;t[24]===n.rateLimitMaxAttempts?h=t[25]:(h=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-max`,children:n.rateLimitMaxAttempts}),t[24]=n.rateLimitMaxAttempts,t[25]=h);let g;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(g=pc(),t[26]=g):g=t[26];let _=!r.enabled,v;t[27]===i?v=t[28]:(v=e=>{let t=Number(e.target.value);Number.isFinite(t)&&i({maxAttempts:Math.max(1,Math.floor(t))})},t[27]=i,t[28]=v);let y;t[29]!==r.maxAttempts||t[30]!==_||t[31]!==v?(y=(0,$.jsx)(`input`,{id:`gateway-rate-max`,type:`number`,min:1,className:g,value:r.maxAttempts,disabled:_,onChange:v}),t[29]=r.maxAttempts,t[30]=_,t[31]=v,t[32]=y):y=t[32];let b;t[33]!==h||t[34]!==y?(b=(0,$.jsxs)(`div`,{children:[h,y]}),t[33]=h,t[34]=y,t[35]=b):b=t[35];let x;t[36]===n.rateLimitWindowMinutes?x=t[37]:(x=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-window`,children:n.rateLimitWindowMinutes}),t[36]=n.rateLimitWindowMinutes,t[37]=x);let S;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(S=pc(),t[38]=S):S=t[38];let C;t[39]===r.windowMs?C=t[40]:(C=Math.round(r.windowMs/6e4),t[39]=r.windowMs,t[40]=C);let w=!r.enabled,T;t[41]===i?T=t[42]:(T=e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>0&&i({windowMs:Math.floor(t)*6e4})},t[41]=i,t[42]=T);let E;t[43]!==C||t[44]!==w||t[45]!==T?(E=(0,$.jsx)(`input`,{id:`gateway-rate-window`,type:`number`,min:1,className:S,value:C,disabled:w,onChange:T}),t[43]=C,t[44]=w,t[45]=T,t[46]=E):E=t[46];let D;t[47]!==x||t[48]!==E?(D=(0,$.jsxs)(`div`,{children:[x,E]}),t[47]=x,t[48]=E,t[49]=D):D=t[49];let O;t[50]===n.rateLimitBlockMinutes?O=t[51]:(O=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-block`,children:n.rateLimitBlockMinutes}),t[50]=n.rateLimitBlockMinutes,t[51]=O);let k;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(k=pc(),t[52]=k):k=t[52];let A;t[53]===r.blockDurationMs?A=t[54]:(A=Math.round(r.blockDurationMs/6e4),t[53]=r.blockDurationMs,t[54]=A);let j=!r.enabled,M;t[55]===i?M=t[56]:(M=e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>0&&i({blockDurationMs:Math.floor(t)*6e4})},t[55]=i,t[56]=M);let N;t[57]!==A||t[58]!==j||t[59]!==M?(N=(0,$.jsx)(`input`,{id:`gateway-rate-block`,type:`number`,min:1,className:k,value:A,disabled:j,onChange:M}),t[57]=A,t[58]=j,t[59]=M,t[60]=N):N=t[60];let P;t[61]!==O||t[62]!==N?(P=(0,$.jsxs)(`div`,{children:[O,N]}),t[61]=O,t[62]=N,t[63]=P):P=t[63];let F;t[64]!==b||t[65]!==D||t[66]!==P?(F=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[b,D,P]}),t[64]=b,t[65]=D,t[66]=P,t[67]=F):F=t[67];let I;return t[68]!==m||t[69]!==s||t[70]!==F||t[71]!==u?(I=(0,$.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[s,u,m,F]}),t[68]=m,t[69]=s,t[70]=F,t[71]=u,t[72]=I):I=t[72],I}function Ac(e){let t=(0,Q.c)(34),{g:n,id:r,label:i,help:a,placeholder:o,value:s,show:c,copied:l,onToggleShow:u,onCopy:d,onChange:f}=e,p;t[0]!==r||t[1]!==i?(p=(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:r,children:i}),t[0]=r,t[1]=i,t[2]=p):p=t[2];let m;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=J(pc(),`min-w-0 flex-1 font-mono text-xs`),t[3]=m):m=t[3];let h=c?`text`:`password`,g;t[4]===f?g=t[5]:(g=e=>f(e.target.value),t[4]=f,t[5]=g);let _;t[6]!==r||t[7]!==o||t[8]!==h||t[9]!==g||t[10]!==s?(_=(0,$.jsx)(`input`,{id:r,className:m,type:h,autoComplete:`off`,value:s,onChange:g,placeholder:o}),t[6]=r,t[7]=o,t[8]=h,t[9]=g,t[10]=s,t[11]=_):_=t[11];let v;t[12]!==l||t[13]!==n.copied||t[14]!==n.copy||t[15]!==d||t[16]!==s?(v=s&&d?(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:d,children:[l?(0,$.jsx)(ae,{className:`size-3.5`}):(0,$.jsx)(D,{className:`size-3.5`}),l?n.copied:n.copy]}):null,t[12]=l,t[13]=n.copied,t[14]=n.copy,t[15]=d,t[16]=s,t[17]=v):v=t[17];let y;t[18]===c?y=t[19]:(y=c?(0,$.jsx)(en,{className:`size-3.5`}):(0,$.jsx)(N,{className:`size-3.5`}),t[18]=c,t[19]=y);let b=c?n.hide:n.show,x;t[20]!==u||t[21]!==y||t[22]!==b?(x=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:u,children:[y,b]}),t[20]=u,t[21]=y,t[22]=b,t[23]=x):x=t[23];let S;t[24]!==_||t[25]!==v||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[_,v,x]}),t[24]=_,t[25]=v,t[26]=x,t[27]=S):S=t[27];let C;t[28]===a?C=t[29]:(C=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:a}),t[28]=a,t[29]=C);let w;return t[30]!==p||t[31]!==S||t[32]!==C?(w=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[p,S,C]}),t[30]=p,t[31]=S,t[32]=C,t[33]=w):w=t[33],w}function jc(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function Mc(){return J(w,Je)}var Nc=[`schedule`,`delivery`,`prompt`,`document`],Pc={schedule:be,delivery:T,prompt:pt,document:on};function Fc(e){return e&&Nc.includes(e)?e:`schedule`}function Ic(e,t){return t===`schedule`?e.tabSchedule:t===`delivery`?e.tabDelivery:t===`prompt`?e.tabPrompt:e.tabDocument}function Lc(e,t){return t===`schedule`?e.scheduleTabHint:t===`delivery`?e.deliveryTabHint:t===`prompt`?e.promptTabHint:e.documentTabHint}function Rc(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`patch`:return{...e,form:e.form?{...e.form,...t.patch}:null};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function zc(e,t){switch(t.type){case`reset`:return{doc:``,baseline:``};case`sync`:return{doc:t.value,baseline:t.value};case`set`:return{...e,doc:t.value};case`discard`:return{...e,doc:e.baseline};case`saved`:return{doc:t.value,baseline:t.value}}}function Bc(e){if(!e||typeof e!=`object`||Array.isArray(e))return``;let t=e.agents;if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=t.defaults;if(!n||typeof n!=`object`||Array.isArray(n))return``;let r=n.workspace;return typeof r==`string`?r:``}var Vc={saving:!1,error:null,triggerLoading:!1,triggerOk:!1,triggerError:null};function Hc(){let e=a(e=>e.language),t=s(e),n=t.heartbeatSettings,r=!!x(e=>e.token),[i,o]=ot(),c=Fc(i.get(`tab`)),l=(0,Z.useCallback)(e=>{o(t=>{let n=new URLSearchParams(t);return e===`schedule`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[o]),[u,f]=(0,Z.useReducer)(Rc,{form:null,baseline:null}),p=u.form,m=u.baseline,[h,g]=(0,Z.useReducer)(zc,{doc:``,baseline:``}),_=h.doc,v=h.baseline,[y,b]=(0,Z.useReducer)(Gt,Vc),{saving:S,error:C,triggerLoading:w,triggerOk:T,triggerError:E}=y,D=(0,Z.useRef)(!1),O=(0,Z.useRef)(!1),{data:k,error:A,isLoading:j,mutate:M}=Ze(r),{data:N,error:P,isLoading:F,mutate:I}=d(r?Gn():null,Hn,{revalidateOnFocus:!1}),{data:L=[]}=d(r?Vn():null,zn,{revalidateOnFocus:!1}),R=(0,Z.useMemo)(()=>Bc(k?.payload?.config),[k]),z=(0,Z.useMemo)(()=>Jn(k?.payload?.config??{}),[k]),B=(0,Z.useMemo)(()=>!p||!m?!1:JSON.stringify(p)!==JSON.stringify(m),[p,m]),V=_!==v;(0,Z.useEffect)(()=>{if(!r){f({type:`reset`}),D.current=!1;return}k!==void 0&&(D.current||f({type:`sync`,value:z}))},[r,k,z]),(0,Z.useEffect)(()=>{if(!r){g({type:`reset`}),O.current=!1;return}N!==void 0&&(O.current||g({type:`sync`,value:N}))},[r,N]);let H=A instanceof Error?A.message:A?String(A):P instanceof Error?P.message:P?String(P):null,U=!!(r&&(k===void 0||N===void 0)&&!H&&(j||F)),W=p?.target.trim()??``,{data:G,setData:ee}=ve(()=>On(W),[r,W],{enabled:r&&W.length>0,initial:[],errorData:[]}),K=(0,Z.useCallback)(()=>{W&&On(W).then(ee)},[W,ee]),te=(0,Z.useCallback)(async()=>{b({type:`patch`,patch:{triggerLoading:!0,triggerOk:!1,triggerError:null}});try{await Un(),b({type:`patch`,patch:{triggerOk:!0}}),window.setTimeout(()=>b({type:`patch`,patch:{triggerOk:!1}}),3e3)}catch(e){b({type:`patch`,patch:{triggerError:e instanceof Error?e.message:n.triggerError}})}finally{b({type:`patch`,patch:{triggerLoading:!1}})}},[n.triggerError]),ne=(0,Z.useCallback)(e=>{D.current=!0,f({type:`patch`,patch:e})},[]),re=B||V,ie=(0,Z.useCallback)(()=>{f({type:`discard`}),g({type:`discard`}),D.current=!1,O.current=!1,b({type:`patch`,patch:{error:null}})},[]);return yr({id:`heartbeat`,dirty:re,saving:S,save:(0,Z.useCallback)(async()=>{if(!(!p||S)){b({type:`patch`,patch:{saving:!0,error:null}});try{B&&(await Wn(p),f({type:`saved`,value:p}),D.current=!1),V&&(await Kn(_),g({type:`saved`,value:_}),O.current=!1)}catch(e){let t=B?n.saveConfigError:n.saveDocError,r=e instanceof Error?e.message:t;throw b({type:`patch`,patch:{error:r}}),Error(r)}finally{b({type:`patch`,patch:{saving:!1}})}}},[B,V,_,p,n.saveConfigError,n.saveDocError,S]),discard:ie}),r?U?(0,$.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),n.loading]})}):p?(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,"aria-busy":S,"data-has-baseline":m?`1`:`0`,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,$.jsxs)(`a`,{href:Be(e,`heartbeat`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,$.jsx)(Me,{className:`size-3.5`})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:w,onClick:()=>void te(),children:[w?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Fe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),w?n.triggering:n.triggerNow]}),T?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,$.jsx)(Ji,{}),R?(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,$.jsx)(`span`,{className:`font-mono text-fg-muted`,children:R})]}):null,C?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:C}):null,E?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:E}):null,(0,$.jsx)(Uc,{h:n,activeTab:c,onChange:l}),(0,$.jsx)(Wc,{h:n,id:`schedule`,activeTab:c,children:(0,$.jsx)(Gc,{h:n,form:p,update:ne})}),(0,$.jsx)(Wc,{h:n,id:`delivery`,activeTab:c,children:(0,$.jsx)(Kc,{h:n,cron:t.cron,form:p,channels:L,sessionChatIds:G,onRefreshChatIds:K,update:ne,inputClassName:jc,selectClassName:Mc})}),(0,$.jsx)(Wc,{h:n,id:`prompt`,activeTab:c,children:(0,$.jsx)(Yc,{h:n,form:p,update:ne,inputClassName:jc})}),(0,$.jsxs)(Wc,{h:n,id:`document`,activeTab:c,children:[(0,$.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,$.jsx)(`textarea`,{className:J(jc(),`min-h-72 resize-y font-mono text-xs leading-relaxed`),value:_,onChange:e=>{O.current=!0,g({type:`set`,value:e.target.value})},spellCheck:!1,"aria-label":n.docSection,"data-doc-in-sync":_===v?`true`:`false`})]})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:C??H??n.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>{M(),I()},children:n.retry})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Uc(e){let t=(0,Q.c)(11),{h:n,activeTab:r,onChange:i}=e,a=n.tabsAriaLabel,o;t[0]!==r||t[1]!==i?(o=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),i(Nc[(Nc.indexOf(r)+(e.key===`ArrowRight`?1:-1)+Nc.length)%Nc.length]))},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==n||t[5]!==i?(s=Nc.map(e=>{let t=Pc[e],a=e===r;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,id:`heartbeat-settings-tab-${e}`,"aria-controls":`heartbeat-settings-panel-${e}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>i(e),children:[(0,$.jsx)(t,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:Ic(n,e)})]},e)}),t[3]=r,t[4]=n,t[5]=i,t[6]=s):s=t[6];let c;return t[7]!==n.tabsAriaLabel||t[8]!==o||t[9]!==s?(c=(0,$.jsx)(`nav`,{"aria-label":a,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,onKeyDown:o,children:s}),t[7]=n.tabsAriaLabel,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Wc(e){let t=(0,Q.c)(20),{h:n,id:r,activeTab:i,children:a}=e;if(i!==r)return null;let o=`heartbeat-settings-panel-${r}`,s=`heartbeat-settings-tab-${r}`,c;t[0]!==n||t[1]!==r?(c=Ic(n,r),t[0]=n,t[1]=r,t[2]=c):c=t[2];let l;t[3]===c?l=t[4]:(l=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:c}),t[3]=c,t[4]=l);let u;t[5]!==n||t[6]!==r?(u=Lc(n,r),t[5]=n,t[6]=r,t[7]=u):u=t[7];let d;t[8]===u?d=t[9]:(d=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u}),t[8]=u,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:`mb-5`,children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;t[13]===a?p=t[14]:(p=(0,$.jsx)(`div`,{className:`space-y-4`,children:a}),t[13]=a,t[14]=p);let m;return t[15]!==o||t[16]!==s||t[17]!==f||t[18]!==p?(m=(0,$.jsxs)(`section`,{id:o,role:`tabpanel`,"aria-labelledby":s,className:`rounded-2xl border border-edge bg-surface-base px-4 py-5 sm:px-5`,children:[f,p]}),t[15]=o,t[16]=s,t[17]=f,t[18]=p,t[19]=m):m=t[19],m}function Gc(e){let t=(0,Q.c)(37),{h:n,form:r,update:i}=e,a;t[0]===i?a=t[1]:(a=e=>i({enabled:e.target.checked}),t[0]=i,t[1]=a);let o;t[2]!==r.enabled||t[3]!==a?(o=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:a}),t[2]=r.enabled,t[3]=a,t[4]=o):o=t[4];let s;t[5]!==n.enable||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[o,n.enable]}),t[5]=n.enable,t[6]=o,t[7]=s):s=t[7];let c;t[8]===i?c=t[9]:(c=e=>i({intervalMs:e}),t[8]=i,t[9]=c);let l;t[10]!==n.intervalPresets||t[11]!==n.intervalSecondsLabel?(l={secondsLabel:n.intervalSecondsLabel,presets:n.intervalPresets},t[10]=n.intervalPresets,t[11]=n.intervalSecondsLabel,t[12]=l):l=t[12];let u=`${n.intervalHintPreset} ${n.intervalHint}`,d;t[13]!==r.intervalMs||t[14]!==n.interval||t[15]!==c||t[16]!==l||t[17]!==u?(d=(0,$.jsx)(Bo,{kind:`interval`,label:n.interval,valueMs:r.intervalMs,onChangeMs:c,labels:l,hint:u}),t[13]=r.intervalMs,t[14]=n.interval,t[15]=c,t[16]=l,t[17]=u,t[18]=d):d=t[18];let f;t[19]===i?f=t[20]:(f=e=>i({activeHours:e}),t[19]=i,t[20]=f);let p;t[21]!==n.activeEnd||t[22]!==n.activeStart||t[23]!==n.activeTimezone||t[24]!==n.addActiveHours||t[25]!==n.clearActiveHours?(p={start:n.activeStart,end:n.activeEnd,timezone:n.activeTimezone,add:n.addActiveHours,clear:n.clearActiveHours},t[21]=n.activeEnd,t[22]=n.activeStart,t[23]=n.activeTimezone,t[24]=n.addActiveHours,t[25]=n.clearActiveHours,t[26]=p):p=t[26];let m;t[27]!==r.activeHours||t[28]!==n.activeHoursHint||t[29]!==n.activeHoursTitle||t[30]!==f||t[31]!==p?(m=(0,$.jsx)(Bo,{kind:`active-hours`,label:n.activeHoursTitle,value:r.activeHours,onChange:f,labels:p,hint:n.activeHoursHint}),t[27]=r.activeHours,t[28]=n.activeHoursHint,t[29]=n.activeHoursTitle,t[30]=f,t[31]=p,t[32]=m):m=t[32];let h;return t[33]!==m||t[34]!==s||t[35]!==d?(h=(0,$.jsxs)($.Fragment,{children:[s,d,m]}),t[33]=m,t[34]=s,t[35]=d,t[36]=h):h=t[36],h}function Kc(e){let t=(0,Q.c)(51),{h:n,cron:r,form:i,channels:a,sessionChatIds:o,onRefreshChatIds:s,update:c,inputClassName:l,selectClassName:u}=e,d;t[0]===a?d=t[1]:(d=new Set(a.map(Jc)),t[0]=a,t[1]=d);let f=d,p;t[2]===i.target?p=t[3]:(p=i.target.trim(),t[2]=i.target,t[3]=p);let m=p,h=!!(m&&!f.has(m)),g;t[4]===n.deliveryHint?g=t[5]:(g=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.deliveryHint}),t[4]=n.deliveryHint,t[5]=g);let _;t[6]===r.channel?_=t[7]:(_=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r.channel}),t[6]=r.channel,t[7]=_);let v;t[8]===u?v=t[9]:(v=u(),t[8]=u,t[9]=v);let y;t[10]===c?y=t[11]:(y=e=>{c({target:e.target.value.trim(),targetChatId:``})},t[10]=c,t[11]=y);let b;t[12]===n.channelNone?b=t[13]:(b=(0,$.jsx)(`option`,{value:``,children:n.channelNone}),t[12]=n.channelNone,t[13]=b);let x;t[14]!==n.customChannelSuffix||t[15]!==h||t[16]!==m?(x=h?(0,$.jsxs)(`option`,{value:m,children:[m,` (`,n.customChannelSuffix,`)`]}):null,t[14]=n.customChannelSuffix,t[15]=h,t[16]=m,t[17]=x):x=t[17];let S;t[18]===a?S=t[19]:(S=a.map(qc),t[18]=a,t[19]=S);let C;t[20]!==v||t[21]!==y||t[22]!==b||t[23]!==x||t[24]!==S||t[25]!==m?(C=(0,$.jsxs)(`select`,{className:v,value:m,onChange:y,children:[b,x,S]}),t[20]=v,t[21]=y,t[22]=b,t[23]=x,t[24]=S,t[25]=m,t[26]=C):C=t[26];let w;t[27]!==C||t[28]!==_?(w=(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[_,C]}),t[27]=C,t[28]=_,t[29]=w):w=t[29];let T;t[30]!==r.enterManuallyOrSelect||t[31]!==r.lastActiveLabels||t[32]!==r.noRecentChats||t[33]!==r.noRecentChatsOption||t[34]!==r.recipient||t[35]!==r.recipientPlaceholder||t[36]!==r.refreshList||t[37]!==r.refreshRecipientHint||t[38]!==r.selectRecipient||t[39]!==i.targetChatId||t[40]!==l||t[41]!==s||t[42]!==u||t[43]!==o||t[44]!==m||t[45]!==c?(T=m?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r.recipient}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:r.refreshRecipientHint,onClick:s,children:[(0,$.jsx)(Ee,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),r.refreshList]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,className:J(l(),`min-w-0 flex-1`),value:i.targetChatId,onChange:e=>c({targetChatId:e.target.value}),placeholder:r.recipientPlaceholder,autoComplete:`off`}),(0,$.jsxs)(`select`,{className:J(u(),`max-w-40 shrink-0 text-xs`),value:i.targetChatId,onChange:e=>{let t=e.target.value;t&&c({targetChatId:t})},children:[(0,$.jsx)(`option`,{value:``,children:r.selectRecipient}),o.length>0?o.map(e=>(0,$.jsx)(`option`,{value:e.chatId,children:Tn(e,r.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,$.jsx)(`option`,{value:``,disabled:!0,children:r.noRecentChatsOption})]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.length>0?r.enterManuallyOrSelect:r.noRecentChats})]}):null,t[30]=r.enterManuallyOrSelect,t[31]=r.lastActiveLabels,t[32]=r.noRecentChats,t[33]=r.noRecentChatsOption,t[34]=r.recipient,t[35]=r.recipientPlaceholder,t[36]=r.refreshList,t[37]=r.refreshRecipientHint,t[38]=r.selectRecipient,t[39]=i.targetChatId,t[40]=l,t[41]=s,t[42]=u,t[43]=o,t[44]=m,t[45]=c,t[46]=T):T=t[46];let E;return t[47]!==w||t[48]!==T||t[49]!==g?(E=(0,$.jsxs)($.Fragment,{children:[g,w,T]}),t[47]=w,t[48]=T,t[49]=g,t[50]=E):E=t[50],E}function qc(e){return(0,$.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name)}function Jc(e){return e.name}function Yc(e){let t=(0,Q.c)(65),{h:n,form:r,update:i,inputClassName:a}=e,o;t[0]===i?o=t[1]:(o=e=>i({includeSystemPromptSection:e.target.checked}),t[0]=i,t[1]=o);let s;t[2]!==r.includeSystemPromptSection||t[3]!==o?(s=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.includeSystemPromptSection,onChange:o}),t[2]=r.includeSystemPromptSection,t[3]=o,t[4]=s):s=t[4];let c;t[5]===n.includeSystemPromptSectionHint?c=t[6]:(c=(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:n.includeSystemPromptSectionHint}),t[5]=n.includeSystemPromptSectionHint,t[6]=c);let l;t[7]!==n.includeSystemPromptSection||t[8]!==c?(l=(0,$.jsxs)(`span`,{children:[n.includeSystemPromptSection,c]}),t[7]=n.includeSystemPromptSection,t[8]=c,t[9]=l):l=t[9];let u;t[10]!==s||t[11]!==l?(u=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[s,l]}),t[10]=s,t[11]=l,t[12]=u):u=t[12];let d;t[13]===n.prompt?d=t[14]:(d=(0,$.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.prompt}),t[13]=n.prompt,t[14]=d);let f;t[15]===a?f=t[16]:(f=J(a(),`min-h-36 resize-y font-mono text-xs`),t[15]=a,t[16]=f);let p;t[17]===i?p=t[18]:(p=e=>i({prompt:e.target.value}),t[17]=i,t[18]=p);let m;t[19]!==r.prompt||t[20]!==n.promptPlaceholder||t[21]!==f||t[22]!==p?(m=(0,$.jsx)(`textarea`,{className:f,value:r.prompt,onChange:p,placeholder:n.promptPlaceholder}),t[19]=r.prompt,t[20]=n.promptPlaceholder,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;t[24]===n.promptHint?h=t[25]:(h=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.promptHint}),t[24]=n.promptHint,t[25]=h);let g;t[26]!==h||t[27]!==d||t[28]!==m?(g=(0,$.jsxs)(`div`,{children:[d,m,h]}),t[26]=h,t[27]=d,t[28]=m,t[29]=g):g=t[29];let _;t[30]===n.ackMaxChars?_=t[31]:(_=(0,$.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.ackMaxChars}),t[30]=n.ackMaxChars,t[31]=_);let v;t[32]===a?v=t[33]:(v=a(),t[32]=a,t[33]=v);let y=r.ackMaxChars===``?``:r.ackMaxChars,b;t[34]===i?b=t[35]:(b=e=>{let t=e.target.value;if(t===``){i({ackMaxChars:``});return}let n=parseInt(t,10);i({ackMaxChars:Number.isFinite(n)?n:``})},t[34]=i,t[35]=b);let x;t[36]!==n.ackDefaultPlaceholder||t[37]!==v||t[38]!==y||t[39]!==b?(x=(0,$.jsx)(`input`,{type:`number`,min:1,className:v,value:y,onChange:b,placeholder:n.ackDefaultPlaceholder}),t[36]=n.ackDefaultPlaceholder,t[37]=v,t[38]=y,t[39]=b,t[40]=x):x=t[40];let S;t[41]===n.ackMaxCharsHint?S=t[42]:(S=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.ackMaxCharsHint}),t[41]=n.ackMaxCharsHint,t[42]=S);let C;t[43]!==_||t[44]!==x||t[45]!==S?(C=(0,$.jsxs)(`div`,{children:[_,x,S]}),t[43]=_,t[44]=x,t[45]=S,t[46]=C):C=t[46];let w;t[47]===i?w=t[48]:(w=e=>i({isolatedSession:e.target.checked}),t[47]=i,t[48]=w);let T;t[49]!==r.isolatedSession||t[50]!==w?(T=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.isolatedSession,onChange:w}),t[49]=r.isolatedSession,t[50]=w,t[51]=T):T=t[51];let E;t[52]===n.isolatedSessionHint?E=t[53]:(E=(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:n.isolatedSessionHint}),t[52]=n.isolatedSessionHint,t[53]=E);let D;t[54]!==n.isolatedSession||t[55]!==E?(D=(0,$.jsxs)(`span`,{children:[n.isolatedSession,E]}),t[54]=n.isolatedSession,t[55]=E,t[56]=D):D=t[56];let O;t[57]!==T||t[58]!==D?(O=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[T,D]}),t[57]=T,t[58]=D,t[59]=O):O=t[59];let k;return t[60]!==g||t[61]!==C||t[62]!==O||t[63]!==u?(k=(0,$.jsxs)($.Fragment,{children:[u,g,C,O]}),t[60]=g,t[61]=C,t[62]=O,t[63]=u,t[64]=k):k=t[64],k}function Xc(e,t){let{mutate:n}=u(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),l=(0,Z.useCallback)(async()=>{await Promise.all([n(`tunnel-pair-context`),n(`tunnel-pair`),n(`tunnel-status`),mt()])},[n]);return{busy:r,error:a,confirmOpen:s,setConfirmOpen:c,runEnableLanPairing:(0,Z.useCallback)(async()=>{if(!(!e||r)){i(!0),o(null);try{let n=await bt();if(!n.ok)throw Error(`Failed to enable LAN pairing`);if(n.requiresRestart){let t=await st();if(!t.ok)throw Error(t.message??`Gateway restart failed`);if(!await dt(e))throw Error(`Gateway did not come back online in time`)}let r=n.requiresRestart?await Rt():n.context;if(!r?.pairingReady)throw Error(`LAN pairing is still not ready after restart`);return await l(),t?.(r),c(!1),r}catch(e){return o(e instanceof Error?e.message:`Enable LAN pairing failed`),null}finally{i(!1)}}},[r,e,t,l]),clearError:()=>o(null)}}function Zc(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function Qc(e){let t=(0,Q.c)(122),{pairQr:n,gatewayToken:r,streamlined:i,lanOnly:o,onRefreshQr:c}=e,l=i===void 0?!1:i,u=o===void 0?!1:o,d=a(tl),f;t[0]===d?f=t[1]:(f=s(d),t[0]=d,t[1]=f);let p=f,m=p.tunnelSettings,h=u?p.remoteAccess.lan:null,g;t[2]!==p.clipboard.copyFailed||t[3]!==m.pairCopied||t[4]!==m.pairCopyLink?(g={copy:m.pairCopyLink,copied:m.pairCopied,copyFailed:p.clipboard.copyFailed},t[2]=p.clipboard.copyFailed,t[3]=m.pairCopied,t[4]=m.pairCopyLink,t[5]=g):g=t[5];let _=g,{tunnelActive:v,tunnelStatus:y,tunnelQr:b,pairContext:x,pairBaseUrl:S,setPairBaseUrl:C,applySuggestedPairUrl:w,applyCandidateUrl:T,resetPairBaseFromContext:E,baseOk:D,localhostWarn:O,pairingBlocked:k,deepLink:A,qrPayload:j,qrDataUrl:M,qrGenFailed:N,encoding:F}=n,I;t[6]===E?I=t[7]:(I=e=>{E(e.recommended.url)},t[6]=E,t[7]=I);let L=Xc(r,I),R,z,B,V,H;if(t[8]!==T||t[9]!==w||t[10]!==D||t[11]!==L||t[12]!==r||t[13]!==h||t[14]!==u||t[15]!==O||t[16]!==c||t[17]!==S||t[18]!==x?.candidates||t[19]!==x?.recommended||t[20]!==k||t[21]!==C||t[22]!==l||t[23]!==m.pairBaseUrlHint||t[24]!==m.pairBaseUrlLabel||t[25]!==m.pairBaseUrlPlaceholder||t[26]!==m.pairBlockedLoopbackBody||t[27]!==m.pairBlockedNextSteps||t[28]!==m.pairBlockedTitle||t[29]!==m.pairCandidatesTitle||t[30]!==m.pairEnableLanButton||t[31]!==m.pairEnableLanEnabling||t[32]!==m.pairEnableLanSecurityAuditLink||t[33]!==m.pairInvalidBaseUrl||t[34]!==m.pairLocalhostWarning||t[35]!==m.pairSelectCandidateHint||t[36]!==m.pairSelectCandidateTitle||t[37]!==m.pairSubtitle||t[38]!==m.pairSuggestedLanLabel||t[39]!==m.pairTitle||t[40]!==m.pairTunnelActive||t[41]!==m.pairTunnelLanUrl||t[42]!==m.pairTunnelPublicUrl||t[43]!==m.pairUseSuggestedUrl||t[44]!==m.pairWaitingForTunnel||t[45]!==m.refreshQr||t[46]!==v||t[47]!==b||t[48]!==y?.publicUrl){H=Symbol.for(`react.early_return_sentinel`);bb0:{let e=x?.candidates.filter(el)??[],n=u?(e.find($c)?.url??e[0]?.url??``).trim():x?.recommended.url?.trim()??``,i=(u||!v)&&e.length>1,a=function(t){if(e.length===0)return null;let n=t===`amber`?`text-amber-950 dark:text-amber-100`:`text-fg`,r=t===`amber`?`text-amber-950/80 dark:text-amber-200/90`:`text-fg-muted`;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:J(`text-xs font-medium`,r),children:i?m.pairSelectCandidateTitle:m.pairCandidatesTitle}),(0,$.jsx)(`ul`,{className:`mt-1 space-y-1`,children:e.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,className:J(`w-full rounded-md border px-2 py-1.5 text-left font-mono text-[11px] transition-colors`,t===`amber`?`border-amber-300/70 hover:bg-amber-100/80 dark:border-amber-800 dark:hover:bg-amber-950/50`:`border-edge hover:bg-surface-panel`,S.trim()===e.url&&`border-accent bg-accent/5`,n),onClick:()=>T(e.url),children:[e.label?`${e.label}: `:``,e.url]})},e.url))}),i?(0,$.jsx)(`p`,{className:J(`mt-1 text-[11px] leading-relaxed`,r),children:m.pairSelectCandidateHint}):null]})};if(R=l&&!u,R&&!v){let e;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(P,{className:`size-4 text-accent`,strokeWidth:1.75}),t[54]=e):e=t[54];let n;t[55]===m.pairTitle?n=t[56]:(n=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[e,m.pairTitle]}),t[55]=m.pairTitle,t[56]=n);let r;t[57]===m.pairWaitingForTunnel?r=t[58]:(r=(0,$.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:m.pairWaitingForTunnel}),t[57]=m.pairWaitingForTunnel,t[58]=r);let i;t[59]!==n||t[60]!==r?(i=(0,$.jsxs)(wn,{children:[n,r]}),t[59]=n,t[60]=r,t[61]=i):i=t[61],H=i;break bb0}let o=h?.pairTitle??m.pairTitle,s=u?h?.pairSubtitle??m.pairSubtitle:v?m.pairTunnelActive:m.pairSubtitle,d=!!(c&&(u||l&&v)),f=R?`mb-2`:`mb-3`,p;t[62]===f?p=t[63]:(p=J(`flex flex-wrap items-start justify-between gap-2`,f),t[62]=f,t[63]=p);let g;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(P,{className:`size-4 text-accent`,strokeWidth:1.75}),t[64]=g):g=t[64];let _;t[65]===o?_=t[66]:(_=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[g,o]}),t[65]=o,t[66]=_);let E;t[67]!==R||t[68]!==s||t[69]!==m.pairSubtitle?(E=R?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:m.pairSubtitle}):(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:s}),t[67]=R,t[68]=s,t[69]=m.pairSubtitle,t[70]=E):E=t[70];let A;t[71]!==_||t[72]!==E?(A=(0,$.jsxs)(`div`,{children:[_,E]}),t[71]=_,t[72]=E,t[73]=A):A=t[73];let j;t[74]!==c||t[75]!==d||t[76]!==m.refreshQr?(j=d?(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`shrink-0`,onClick:()=>void c(),children:[(0,$.jsx)(Ee,{className:`size-4`}),m.refreshQr]}):null,t[74]=c,t[75]=d,t[76]=m.refreshQr,t[77]=j):j=t[77],t[78]!==p||t[79]!==A||t[80]!==j?(z=(0,$.jsxs)(`div`,{className:p,children:[A,j]}),t[78]=p,t[79]=A,t[80]=j,t[81]=z):z=t[81],B=k?(0,$.jsxs)(`div`,{className:`mb-3 space-y-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-3 dark:border-amber-900/50 dark:bg-amber-950/30`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-amber-950 dark:text-amber-100`,children:m.pairBlockedTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-amber-900 dark:text-amber-200`,children:m.pairBlockedLoopbackBody})]}),n?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-amber-950/80 dark:text-amber-200/90`,children:m.pairSuggestedLanLabel}),(0,$.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-amber-950 dark:text-amber-100`,children:n})]}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:w,children:m.pairUseSuggestedUrl})]}):null,e.length>0?a(`amber`):null,(0,$.jsx)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:flex-wrap`,children:(0,$.jsxs)(Y,{type:`button`,className:`w-full sm:w-auto`,disabled:L.busy||!r,onClick:()=>L.setConfirmOpen(!0),children:[L.busy?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):null,L.busy?m.pairEnableLanEnabling:m.pairEnableLanButton]})}),L.error?(0,$.jsx)(`p`,{className:`text-xs text-red-800 dark:text-red-200`,children:L.error}):null,(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-amber-900 dark:text-amber-200`,children:u?h?.pairBlockedNextSteps??m.pairBlockedNextSteps:m.pairBlockedNextSteps}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(Ft,{to:`/settings/gateway`,className:`inline-block text-xs font-medium text-accent hover:underline`,children:m.pairEnableLanSecurityAuditLink}),u&&h?.pairPublicTabLink?(0,$.jsx)(Ft,{to:`/settings/remote-access?tab=public`,className:`inline-block text-xs font-medium text-accent hover:underline`,children:h.pairPublicTabLink}):null]})]}):null,V=v&&!u?R?null:(0,$.jsxs)(`div`,{className:`mb-3 space-y-2 rounded-lg border border-edge bg-surface-panel px-3 py-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.pairTunnelPublicUrl}),(0,$.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-fg`,children:y?.publicUrl})]}),b?.lanUrl?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.pairTunnelLanUrl}),(0,$.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-fg`,children:b.lanUrl})]}):null]}):(0,$.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`tunnel-mobile-pair-base`,children:m.pairBaseUrlLabel}),(0,$.jsx)(`input`,{id:`tunnel-mobile-pair-base`,className:J(Zc(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:n||m.pairBaseUrlPlaceholder,value:S,onChange:e=>C(e.target.value)}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:m.pairBaseUrlHint}),!D&&S.trim()?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:m.pairInvalidBaseUrl}):null,O?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:m.pairLocalhostWarning}):null,i?a(`neutral`):null]})}t[8]=T,t[9]=w,t[10]=D,t[11]=L,t[12]=r,t[13]=h,t[14]=u,t[15]=O,t[16]=c,t[17]=S,t[18]=x?.candidates,t[19]=x?.recommended,t[20]=k,t[21]=C,t[22]=l,t[23]=m.pairBaseUrlHint,t[24]=m.pairBaseUrlLabel,t[25]=m.pairBaseUrlPlaceholder,t[26]=m.pairBlockedLoopbackBody,t[27]=m.pairBlockedNextSteps,t[28]=m.pairBlockedTitle,t[29]=m.pairCandidatesTitle,t[30]=m.pairEnableLanButton,t[31]=m.pairEnableLanEnabling,t[32]=m.pairEnableLanSecurityAuditLink,t[33]=m.pairInvalidBaseUrl,t[34]=m.pairLocalhostWarning,t[35]=m.pairSelectCandidateHint,t[36]=m.pairSelectCandidateTitle,t[37]=m.pairSubtitle,t[38]=m.pairSuggestedLanLabel,t[39]=m.pairTitle,t[40]=m.pairTunnelActive,t[41]=m.pairTunnelLanUrl,t[42]=m.pairTunnelPublicUrl,t[43]=m.pairUseSuggestedUrl,t[44]=m.pairWaitingForTunnel,t[45]=m.refreshQr,t[46]=v,t[47]=b,t[48]=y?.publicUrl,t[49]=R,t[50]=z,t[51]=B,t[52]=V,t[53]=H}else R=t[49],z=t[50],B=t[51],V=t[52],H=t[53];if(H!==Symbol.for(`react.early_return_sentinel`))return H;let U;t[82]===m.pairSecurityNote?U=t[83]:(U=(0,$.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:m.pairSecurityNote}),t[82]=m.pairSecurityNote,t[83]=U);let W;t[84]!==_||t[85]!==A||t[86]!==F||t[87]!==k||t[88]!==M||t[89]!==N||t[90]!==m.pairEncoding||t[91]!==m.pairImageError||t[92]!==m.pairQrDisabled?(W=A?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[M&&!N?(0,$.jsx)(`img`,{src:M,alt:``,className:`size-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,F?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m.pairEncoding}):null,N?(0,$.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:m.pairImageError}):null,(0,$.jsx)(ie,{text:A,labels:_})]}):k?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m.pairQrDisabled}):null,t[84]=_,t[85]=A,t[86]=F,t[87]=k,t[88]=M,t[89]=N,t[90]=m.pairEncoding,t[91]=m.pairImageError,t[92]=m.pairQrDisabled,t[93]=W):W=t[93];let G;t[94]!==R||t[95]!==j||t[96]!==m.deeplinkTitle?(G=j&&!R?(0,$.jsxs)(`details`,{className:`mt-3 rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-muted`,children:m.deeplinkTitle}),(0,$.jsx)(`p`,{className:`mt-2 break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:j})]}):null,t[94]=R,t[95]=j,t[96]=m.deeplinkTitle,t[97]=G):G=t[97];let ee;t[98]!==R||t[99]!==m.pairMobileProbeHint||t[100]!==m.pairSchemeHint?(ee=R?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-3 break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:m.pairSchemeHint}),(0,$.jsx)(`p`,{className:`mt-1 text-[10px] leading-relaxed text-fg-subtle`,children:m.pairMobileProbeHint})]}),t[98]=R,t[99]=m.pairMobileProbeHint,t[100]=m.pairSchemeHint,t[101]=ee):ee=t[101];let K,te;t[102]===L?(K=t[103],te=t[104]):(K=()=>void L.runEnableLanPairing(),te=()=>{L.busy||L.setConfirmOpen(!1)},t[102]=L,t[103]=K,t[104]=te);let ne;t[105]!==L.confirmOpen||t[106]!==m.consentCancel||t[107]!==m.pairEnableLanButton||t[108]!==m.pairEnableLanConfirmBody||t[109]!==m.pairEnableLanConfirmTitle||t[110]!==K||t[111]!==te?(ne=(0,$.jsx)(Jt,{open:L.confirmOpen,title:m.pairEnableLanConfirmTitle,description:m.pairEnableLanConfirmBody,confirmLabel:m.pairEnableLanButton,cancelLabel:m.consentCancel,onConfirm:K,onCancel:te}),t[105]=L.confirmOpen,t[106]=m.consentCancel,t[107]=m.pairEnableLanButton,t[108]=m.pairEnableLanConfirmBody,t[109]=m.pairEnableLanConfirmTitle,t[110]=K,t[111]=te,t[112]=ne):ne=t[112];let re;return t[113]!==U||t[114]!==W||t[115]!==G||t[116]!==ee||t[117]!==ne||t[118]!==z||t[119]!==B||t[120]!==V?(re=(0,$.jsx)(wn,{children:(0,$.jsxs)($.Fragment,{children:[z,B,V,U,W,G,ee,ne]})}),t[113]=U,t[114]=W,t[115]=G,t[116]=ee,t[117]=ne,t[118]=z,t[119]=B,t[120]=V,t[121]=re):re=t[121],re}function $c(e){return e.reachable}function el(e){return e.kind===`lan`}function tl(e){return e.language}function nl(e){let t=(0,Q.c)(40),{open:n,title:r,intro:i,bullets:a,checkboxLabel:o,confirmLabel:s,cancelLabel:c,onConfirm:l,onCancel:u}=e,[d,f]=(0,Z.useState)(!1),y;t[0]===u?y=t[1]:(y=e=>{e||(f(!1),u())},t[0]=u,t[1]=y);let b;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(m,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ft)}),t[2]=b):b=t[2];let x;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(x=J(`fixed left-1/2 top-1/2 max-h-[min(90vh,40rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`,_t),t[3]=x):x=t[3];let S;t[4]===r?S=t[5]:(S=(0,$.jsx)(v,{className:`text-base font-semibold text-fg`,children:r}),t[4]=r,t[5]=S);let C;t[6]===i?C=t[7]:(C=(0,$.jsx)(_,{className:`mt-2 text-sm text-fg-muted`,children:i}),t[6]=i,t[7]=C);let w;t[8]===a?w=t[9]:(w=a.map(rl),t[8]=a,t[9]=w);let T;t[10]===w?T=t[11]:(T=(0,$.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5 text-sm text-fg-muted`,children:w}),t[10]=w,t[11]=T);let E;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(E=e=>f(e.target.checked),t[12]=E):E=t[12];let D;t[13]===d?D=t[14]:(D=(0,$.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 shrink-0 rounded border-edge accent-accent`,checked:d,onChange:E}),t[13]=d,t[14]=D);let O;t[15]===o?O=t[16]:(O=(0,$.jsx)(`span`,{children:o}),t[15]=o,t[16]=O);let k;t[17]!==O||t[18]!==D?(k=(0,$.jsxs)(`label`,{className:`mt-5 flex cursor-pointer items-start gap-3 text-sm text-fg`,children:[D,O]}),t[17]=O,t[18]=D,t[19]=k):k=t[19];let A;t[20]!==c||t[21]!==u?(A=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:u,children:c}),t[20]=c,t[21]=u,t[22]=A):A=t[22];let j=!d,M;t[23]!==s||t[24]!==l||t[25]!==j?(M=(0,$.jsx)(Y,{type:`button`,disabled:j,onClick:l,children:s}),t[23]=s,t[24]=l,t[25]=j,t[26]=M):M=t[26];let N;t[27]!==A||t[28]!==M?(N=(0,$.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[A,M]}),t[27]=A,t[28]=M,t[29]=N):N=t[29];let P;t[30]!==k||t[31]!==N||t[32]!==S||t[33]!==C||t[34]!==T?(P=(0,$.jsxs)(p,{children:[b,(0,$.jsxs)(h,{className:x,onOpenAutoFocus:il,children:[S,C,T,k,N]})]}),t[30]=k,t[31]=N,t[32]=S,t[33]=C,t[34]=T,t[35]=P):P=t[35];let F;return t[36]!==n||t[37]!==y||t[38]!==P?(F=(0,$.jsx)(g,{open:n,onOpenChange:y,children:P}),t[36]=n,t[37]=y,t[38]=P,t[39]=F):F=t[39],F}function rl(e){return(0,$.jsx)(`li`,{children:e},e)}function il(e){return e.preventDefault()}function al(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}var ol=[`preparing_frpc`,`registering`,`starting_frpc`];function sl(e){return e?e===`reconnecting_frpc`?ol.indexOf(`starting_frpc`):ol.indexOf(e):-1}function cl(e,t){if(t.state===`connected`)return`done`;let n=t.startProgress?.phase,r=ol.indexOf(e),i=sl(n);return i<0?t.state===`connecting`||t.state===`reconnecting`?`active`:`pending`:r<i?`done`:r===i?`active`:`pending`}function ll(e,t,n){let r=n.startProgress;return cl(t,n)===`active`?t===`preparing_frpc`&&n.frpcDownload?n.frpcDownload.phase===`extracting`?e.frpcExtracting:n.frpcDownload.percent==null?e.frpcDownloading:e.frpcDownloadingPercent.replace(`{{percent}}`,String(n.frpcDownload.percent)):t===`registering`&&r?.publicUrl?e.stepRegisterDetail:t===`starting_frpc`?r?.phase===`reconnecting_frpc`?e.stepReconnectDetail:e.stepFrpcDetail:null:null}function ul(e,t){switch(t){case`preparing_frpc`:return e.stepPrepareFrpc;case`registering`:return e.stepRegister;case`starting_frpc`:return e.stepFrpcLogin}}function dl(e){if(!e)return null;let t=Math.max(0,Math.floor((Date.now()-new Date(e).getTime())/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function fl(e){let t=(0,Q.c)(31),{status:n,t:r}=e,[,i]=(0,Z.useState)(0),a;t[0]!==i||t[1]!==n.state?(a=()=>{if(n.state!==`connecting`&&n.state!==`reconnecting`)return;let e=window.setInterval(()=>i(pl),1e3);return()=>window.clearInterval(e)},t[0]=i,t[1]=n.state,t[2]=a):a=t[2];let o=n.startProgress?.startedAt,s;if(t[3]!==n.state||t[4]!==o?(s=[n.state,o],t[3]=n.state,t[4]=o,t[5]=s):s=t[5],(0,Z.useEffect)(a,s),!(n.state===`connecting`||n.state===`reconnecting`||n.state===`connected`&&n.startProgress))return null;let c,l,u,d,f;if(t[6]!==n||t[7]!==r){let e=dl(n.startProgress?.startedAt);c=!!n.publicUrl&&n.state!==`connected`&&n.startProgress?.phase!==`registering`,l=`mt-3 space-y-3 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-3`;let i;t[13]===r.startProgressTitle?i=t[14]:(i=(0,$.jsx)(`p`,{className:`text-xs font-medium text-fg`,children:r.startProgressTitle}),t[13]=r.startProgressTitle,t[14]=i);let a;t[15]===r.startProgressHint?a=t[16]:(a=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:r.startProgressHint}),t[15]=r.startProgressHint,t[16]=a),t[17]!==i||t[18]!==a?(u=(0,$.jsxs)(`div`,{children:[i,a]}),t[17]=i,t[18]=a,t[19]=u):u=t[19];let o=ol.map(e=>{let t=cl(e,n),i=ll(r,e,n);return(0,$.jsxs)(`li`,{className:`flex gap-2 text-xs`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 shrink-0 text-fg-subtle`,"aria-hidden":!0,children:t===`done`?(0,$.jsx)(ae,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`}):t===`active`?(0,$.jsx)(q,{className:`size-3.5 animate-spin text-accent`}):(0,$.jsx)(le,{className:`size-3.5`})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:J(`font-medium`,t===`active`?`text-fg`:t===`done`?`text-fg-muted`:`text-fg-subtle`),children:ul(r,e)}),i?(0,$.jsx)(`div`,{className:`mt-0.5 text-fg-muted`,children:i}):null,e===`preparing_frpc`&&t===`active`&&n.frpcDownload&&n.frpcDownload.phase===`downloading`?(0,$.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,$.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-surface-panel`,children:(0,$.jsx)(`div`,{className:J(`h-full rounded-full bg-accent transition-[width] duration-300`,n.frpcDownload.percent==null&&`w-1/3 animate-pulse`),style:n.frpcDownload.percent==null?void 0:{width:`${n.frpcDownload.percent}%`}})}),n.frpcDownload.bytesReceived!=null&&n.frpcDownload.totalBytes?(0,$.jsxs)(`p`,{className:`text-fg-subtle`,children:[al(n.frpcDownload.bytesReceived),` /`,` `,al(n.frpcDownload.totalBytes)]}):null]}):null,e===`preparing_frpc`&&t===`active`&&n.frpcDownload?.url?(0,$.jsxs)(`p`,{className:`mt-2 text-fg-subtle`,children:[(0,$.jsxs)(`span`,{className:`font-sans`,children:[r.frpcDownloadingUrlLabel,`: `]}),(0,$.jsx)(`a`,{href:n.frpcDownload.url,target:`_blank`,rel:`noopener noreferrer`,className:`break-all font-mono text-[11px] text-accent hover:underline`,children:n.frpcDownload.url})]}):null]})]},e)});t[20]===o?d=t[21]:(d=(0,$.jsx)(`ol`,{className:`space-y-2`,children:o}),t[20]=o,t[21]=d),f=e&&n.startProgress?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.startProgressElapsed.replace(`{{elapsed}}`,e)}):null,t[6]=n,t[7]=r,t[8]=c,t[9]=l,t[10]=u,t[11]=d,t[12]=f}else c=t[8],l=t[9],u=t[10],d=t[11],f=t[12];let p;t[22]!==c||t[23]!==r.publicUrlPendingNotice?(p=c?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.publicUrlPendingNotice}):null,t[22]=c,t[23]=r.publicUrlPendingNotice,t[24]=p):p=t[24];let m;return t[25]!==l||t[26]!==u||t[27]!==d||t[28]!==f||t[29]!==p?(m=(0,$.jsxs)(`div`,{className:l,children:[u,d,f,p]}),t[25]=l,t[26]=u,t[27]=d,t[28]=f,t[29]=p,t[30]=m):m=t[30],m}function pl(e){return e+1}function ml(e,t){return t.state===`connected`?e.statusConnected:t.state===`error`?e.statusError:t.startProgress?.phase===`reconnecting_frpc`?e.statusReconnecting:t.startProgress?.phase===`starting_frpc`?e.statusStartingFrpc:t.startProgress?.phase===`registering`?e.statusRegistering:t.startProgress?.phase===`preparing_frpc`||t.frpcDownload?e.statusPreparingFrpc:t.state===`connecting`||t.state===`reconnecting`?e.statusConnecting:e.statusOff}function hl(e){return e.state===`connected`?`connected`:e.state===`error`?`error`:e.state===`connecting`||e.state===`reconnecting`||e.startProgress||e.frpcDownload?`progress`:`off`}function gl(e){switch(e){case`connected`:return`bg-emerald-500/15 text-emerald-700 dark:text-emerald-400`;case`progress`:return`bg-amber-500/15 text-amber-700 dark:text-amber-400`;case`error`:return`bg-red-500/15 text-red-700 dark:text-red-400`;default:return`bg-surface-hover text-fg-muted`}}function _l(e){if(!e)return`—`;let t=Date.now()-new Date(e).getTime();if(t<0)return`—`;let n=Math.floor(t/6e4);return n<60?`${n}m`:`${Math.floor(n/60)}h ${n%60}m`}function vl(e){let t=(0,Q.c)(61),{t:n,status:r,isLoading:i,statusErr:a,starting:o,stopping:s,showConsentExpired:c,copyLabels:l,startDisabled:u,startDisabledReason:d,stepLabel:f,onStart:p,onStop:m}=e,h=u===void 0?!1:u,g,_,v,y,b,x,S;t[0]!==r||t[1]!==o?(S=hl(r),g=r.enabled||o,_=o||r.state===`connecting`||r.state===`reconnecting`||!!r.startProgress||!!r.frpcDownload,t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=J(Cn(),`space-y-4`),t[9]=x):x=t[9],b=`flex flex-wrap items-start justify-between gap-3`,y=`flex items-center gap-2`,v=J(`inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium`,gl(S)),t[0]=r,t[1]=o,t[2]=g,t[3]=_,t[4]=v,t[5]=y,t[6]=b,t[7]=x,t[8]=S):(g=t[2],_=t[3],v=t[4],y=t[5],b=t[6],x=t[7],S=t[8]);let C=S===`connected`&&`bg-emerald-500`,w=S===`progress`&&`bg-amber-500 animate-pulse`,T=S===`error`&&`bg-red-500`,E=S===`off`&&`bg-fg-subtle`,D;t[10]!==C||t[11]!==w||t[12]!==T||t[13]!==E?(D=J(`size-1.5 rounded-full`,C,w,T,E),t[10]=C,t[11]=w,t[12]=T,t[13]=E,t[14]=D):D=t[14];let O;t[15]===D?O=t[16]:(O=(0,$.jsx)(`span`,{className:D,"aria-hidden":!0}),t[15]=D,t[16]=O);let k;t[17]!==i||t[18]!==r||t[19]!==n?(k=i&&!r.enabled?n.loading:ml(n,r),t[17]=i,t[18]=r,t[19]=n,t[20]=k):k=t[20];let A;t[21]!==O||t[22]!==k||t[23]!==v?(A=(0,$.jsxs)(`span`,{className:v,children:[O,k]}),t[21]=O,t[22]=k,t[23]=v,t[24]=A):A=t[24];let M;t[25]!==r.connectedSince||t[26]!==r.state||t[27]!==n.uptime?(M=r.connectedSince&&r.state===`connected`?(0,$.jsxs)(`span`,{className:`text-xs text-fg-subtle`,children:[n.uptime,` `,_l(r.connectedSince)]}):null,t[25]=r.connectedSince,t[26]=r.state,t[27]=n.uptime,t[28]=M):M=t[28];let N;t[29]!==A||t[30]!==M||t[31]!==y?(N=(0,$.jsxs)(`div`,{className:y,children:[A,M]}),t[29]=A,t[30]=M,t[31]=y,t[32]=N):N=t[32];let P;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(Xe,{className:`size-4 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[33]=P):P=t[33];let F;t[34]!==N||t[35]!==b?(F=(0,$.jsxs)(`div`,{className:b,children:[N,P]}),t[34]=N,t[35]=b,t[36]=F):F=t[36];let I;t[37]===a?I=t[38]:(I=a?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:a instanceof Error?a.message:String(a)}):null,t[37]=a,t[38]=I);let L;t[39]!==c||t[40]!==n.consentExpiredBanner?(L=c?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-xs text-fg-muted`,children:n.consentExpiredBanner}):null,t[39]=c,t[40]=n.consentExpiredBanner,t[41]=L):L=t[41];let R;t[42]!==g||t[43]!==l||t[44]!==p||t[45]!==m||t[46]!==_||t[47]!==r||t[48]!==h||t[49]!==d||t[50]!==o||t[51]!==f||t[52]!==s||t[53]!==n?(R=g?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[r.publicUrl?(0,$.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-3`,children:(0,$.jsx)(ie,{label:n.publicUrlLabel,text:r.publicUrl,labels:l})}):null,_?(0,$.jsx)(fl,{status:r,t:n}):null,r.lastError&&r.state===`error`?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:r.lastError}):null,(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.enabled?(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:s,onClick:m,children:[s?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,n.stop]}):(0,$.jsxs)(Y,{type:`button`,disabled:o,onClick:p,children:[o?(0,$.jsx)(q,{className:`size-4 animate-spin`}):(0,$.jsx)(j,{className:`size-4`}),n.start]})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[f?(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:f}):null,(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:n.emptyStateTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:n.emptyStateBody})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-500/25 bg-amber-500/5 px-3 py-2.5 text-xs text-fg-muted`,children:[(0,$.jsx)(ut,{className:`mt-0.5 size-4 shrink-0 text-amber-600 dark:text-amber-400`}),(0,$.jsx)(`p`,{children:n.riskBannerBody})]}),h&&d?(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:d}):null,(0,$.jsxs)(Y,{type:`button`,disabled:o||h,onClick:p,className:`w-full sm:w-auto`,children:[o?(0,$.jsx)(q,{className:`size-4 animate-spin`}):(0,$.jsx)(j,{className:`size-4`}),n.start]})]}),t[42]=g,t[43]=l,t[44]=p,t[45]=m,t[46]=_,t[47]=r,t[48]=h,t[49]=d,t[50]=o,t[51]=f,t[52]=s,t[53]=n,t[54]=R):R=t[54];let z;return t[55]!==F||t[56]!==I||t[57]!==L||t[58]!==R||t[59]!==x?(z=(0,$.jsxs)(`section`,{className:x,children:[F,I,L,R]}),t[55]=F,t[56]=I,t[57]=L,t[58]=R,t[59]=x,t[60]=z):z=t[60],z}var yl=`https://console.xopc.ai/keys/tunnel`,bl={reconfiguring:!1,showKey:!1,revealed:void 0,revealLoading:!1,revealErr:null,copied:!1};function xl({t:e,brokerSecretFromEnv:t,brokerSecretMissing:n,brokerSecretConfiguredInConfig:r,brokerSecretMaskedValue:i,brokerSecretDraft:a,savingBrokerSecret:o,brokerSecretNotice:s,copyFailedLabel:c,onDraftChange:l,onSave:u,onClear:d,sectionRef:f}){let p=(0,Z.useId)(),m=n&&!t,h=!m,[g,_]=(0,Z.useReducer)(Gt,bl),{reconfiguring:v,showKey:y,revealed:b,revealLoading:x,revealErr:S,copied:C}=g,w=r&&!t&&!v&&!a.trim(),T=(0,Z.useRef)(r);!r&&T.current&&_({type:`patch`,patch:{reconfiguring:!1,revealed:void 0,revealErr:null,showKey:!1}}),T.current=r;let E=(0,Z.useRef)(s);s&&s!==E.current&&_({type:`patch`,patch:{reconfiguring:!1}}),E.current=s;let O=(0,Z.useCallback)(async()=>{let e=typeof b==`string`?b:``;if(e){if(!await K(e)){_({type:`patch`,patch:{revealErr:c}});return}_({type:`patch`,patch:{copied:!0}}),window.setTimeout(()=>_({type:`patch`,patch:{copied:!1}}),2e3)}},[c,b]),k=(0,Z.useCallback)(async()=>{if(_({type:`patch`,patch:{revealErr:null}}),b!==void 0){_({type:`patch`,patch:{showKey:!y}});return}_({type:`patch`,patch:{revealLoading:!0}});try{_({type:`patch`,patch:{revealed:(await sn()).registrationSecret??null,showKey:!0}})}catch(t){_({type:`patch`,patch:{revealErr:t instanceof Error?t.message:e.brokerSecretRevealFailed,revealed:null}})}finally{_({type:`patch`,patch:{revealLoading:!1}})}},[b,e.brokerSecretRevealFailed]),A=a.trim().length>0&&!Oe(a.trim());return(0,$.jsx)(`div`,{ref:f,id:`tunnel-broker-secret-setup`,children:(0,$.jsx)(wn,{className:J(m&&`ring-1 ring-amber-500/30`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`span`,{className:J(`flex size-9 shrink-0 items-center justify-center rounded-lg`,h?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:m?`bg-amber-500/10 text-amber-700 dark:text-amber-400`:`bg-surface-hover text-fg-muted`),children:h?(0,$.jsx)(ae,{className:`size-4`,strokeWidth:2,"aria-hidden":!0}):(0,$.jsx)(It,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:h?e.brokerSecretReadyTitle:e.brokerSecretStepTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:h?e.brokerSecretReadyHint:e.brokerSecretHint}),m?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-amber-800 dark:text-amber-200`,children:e.brokerSecretMissingHint}):null]}),(0,$.jsxs)(`a`,{href:yl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[e.brokerSecretConsoleLink,(0,$.jsx)(Me,{className:`size-3`,"aria-hidden":!0})]}),t?(0,$.jsx)(`p`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-xs text-fg-muted`,children:e.brokerSecretEnvHint}):null,w?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`text-[11px] text-fg-subtle`,children:e.brokerSecretMaskedHelp}),(0,$.jsx)(`label`,{className:`sr-only`,htmlFor:p,children:e.brokerSecretTitle}),(0,$.jsxs)(`div`,{className:`relative min-w-0`,children:[(0,$.jsx)(`input`,{id:p,type:y&&typeof b==`string`?`text`:`password`,readOnly:!0,autoComplete:`off`,spellCheck:!1,className:`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-3 pr-24 font-mono text-sm text-fg`,value:y&&typeof b==`string`?b:i}),(0,$.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[y&&typeof b==`string`&&b.length>0?(0,$.jsx)(`button`,{type:`button`,className:J(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,X.transition,X.press,X.focusRingPanel),title:C?e.copied:e.copyKey,"aria-label":C?e.copied:e.copyKey,onClick:()=>void O(),children:C?(0,$.jsx)(Ie,{className:`size-4`}):(0,$.jsx)(D,{className:`size-4`})}):null,(0,$.jsx)(`button`,{type:`button`,className:J(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,X.transition,X.press,X.focusRingPanel),title:y?e.hideKey:e.showKey,"aria-label":y?e.hideKey:e.showKey,disabled:x,onClick:()=>void k(),children:x?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):y?(0,$.jsx)(en,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(N,{className:`size-4`,"aria-hidden":!0})})]})]}),y&&b===null&&!S?(0,$.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:e.brokerSecretNotInConfigFile}):null,S?(0,$.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:S}):null,(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:o,onClick:()=>{_({type:`patch`,patch:{revealErr:null,reconfiguring:!0}})},children:e.brokerSecretReconfigure}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:o,onClick:d,children:e.brokerSecretClear})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`label`,{className:`sr-only`,htmlFor:p,children:e.brokerSecretTitle}),(0,$.jsx)(`input`,{id:p,type:`password`,autoComplete:`off`,spellCheck:!1,className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-subtle`,placeholder:e.brokerSecretPlaceholder,value:a,disabled:o,onChange:e=>l(e.target.value)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,disabled:o||!A,onClick:u,children:[o?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,m?e.brokerSecretSaveAndContinue:e.brokerSecretSave]}),r||t?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:o,onClick:d,children:e.brokerSecretClear}):null,v?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:o,onClick:()=>{_({type:`patch`,patch:{reconfiguring:!1,revealErr:null}}),l(``)},children:e.brokerSecretCancelReconfigure}):null]})]}),s?(0,$.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,children:s}):null]})]})})})}function Sl(e){let t=(0,Q.c)(10),{language:n,label:r,section:i,className:a}=e,o;t[0]!==n||t[1]!==i?(o=se(n,i),t[0]=n,t[1]=i,t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=J(`inline-flex items-center gap-1 text-sm font-medium text-accent hover:underline`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,a),t[3]=a,t[4]=s);let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(Me,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[5]=c):c=t[5];let l;return t[6]!==r||t[7]!==o||t[8]!==s?(l=(0,$.jsxs)(`a`,{href:o,target:`_blank`,rel:`noreferrer`,className:s,children:[r,c]}),t[6]=r,t[7]=o,t[8]=s,t[9]=l):l=t[9],l}var Cl=e(Bn(),1),wl={width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}};async function Tl(e){return Cl.toDataURL(e,wl)}function El(e){let t=e?.candidates??[],n=t.find(e=>e.kind===`lan`&&e.reachable),r=t.find(e=>e.kind===`lan`);return(n??r)?.url?.trim()??``}function Dl(e,t){let n=t.trim();return!n||!e?!1:e.candidates.some(e=>e.kind===`tunnel`&&e.url.trim()===n)}function Ol(e,t){return e?t?El(e)||e.recommended.url?.trim()||``:e.recommended.url?.trim()||``:``}function kl(e,t){let n=t?.preferLan===!0,r=!!e,{mutate:i}=u(),a=(0,Z.useRef)(!1),{data:s}=d(r?`tunnel-status`:null,Qt,{refreshInterval:6e4}),{data:l,mutate:f}=d(r?`tunnel-pair-context`:null,gt,{refreshInterval:6e4});(0,Z.useEffect)(()=>{let e=()=>{i(`tunnel-status`),i(`tunnel-qr`),i(`tunnel-pair`),i(`tunnel-pair-context`)};return window.addEventListener(`tunnel-status`,e),()=>window.removeEventListener(`tunnel-status`,e)},[i]);let p=s?.state===`connected`&&!!s.publicUrl?.trim(),m=p&&!n,{data:h,mutate:g}=d(m&&r?`tunnel-qr`:null,$e,{refreshInterval:4*6e4}),{data:_,mutate:v}=d(!m&&r&&l?.pairingReady?`tunnel-pair`:null,jt,{refreshInterval:4*6e4}),[y,b]=(0,Z.useState)(``),[x,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)({pairContext:void 0,preferLan:n});if(!a.current&&(l!==C.pairContext||n!==C.preferLan)){w({pairContext:l,preferLan:n});let e=Ol(l,n);y!==e&&b(e)}let T=(0,Z.useCallback)(e=>{a.current=!0,b(e)},[]),E=(0,Z.useCallback)(()=>{let e=Ol(l,n);e&&(a.current=!0,b(e))},[l,n]),D=(0,Z.useCallback)(e=>{let t=e.trim();t&&(a.current=!0,b(t))},[]),O=(0,Z.useCallback)(e=>{a.current=!1,b(e?.trim()||Ol(l,n))},[l,n]),k=y.trim(),A=(0,Z.useMemo)(()=>{try{let e=new URL(k);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[k]),j=A&&c(k),M=!m&&!!(l&&!l.pairingReady&&l.blockReason===`GATEWAY_LOOPBACK_ONLY`),N=!m&&A&&!j&&!!_?.pairingSecret&&(l?.pairingReady===!0||!M),P=(0,Z.useMemo)(()=>{let e=El(l);return n?e||(k&&!Dl(l,k)?k:``):k},[l,n,k]),F=(0,Z.useMemo)(()=>{if(!e)return``;if(x.trim())return x.trim();if(m&&h?.qrPayload?.trim())return h.qrPayload.trim();if(!N||!_?.pairingSecret)return``;let t=l?.candidates.find(e=>e.kind===`tunnel`&&e.reachable),r=l?.candidates.find(e=>e.kind===`lan`&&e.reachable),i=n?P:t?.url??k;return i?o({baseUrl:i,pairingSecret:_.pairingSecret,lanUrl:n?null:t&&r?r.url:null}):``},[e,P,_?.pairingSecret,N,x,n,k,m,h?.qrPayload,l?.candidates]),I=ve(()=>Tl(F),[F],{enabled:!!F,initial:null,errorData:null}),L=F?I.data:null,R=!!(F&&I.error!==null&&!I.loading);return{tunnelActive:p,tunnelStatus:s,tunnelQr:h,pairContext:l,pairBaseUrl:y,setPairBaseUrl:T,applySuggestedPairUrl:E,applyCandidateUrl:D,baseOk:A,localhostWarn:j,pairingBlocked:M,deepLink:F,qrPayload:F,qrDataUrl:L,qrGenFailed:R,encoding:!!(F&&!L&&!R),refreshQr:(0,Z.useCallback)(async e=>{if(e?.trim()){S(e.trim()),g({qrPayload:e.trim(),publicUrl:s?.publicUrl??``,lanUrl:h?.lanUrl??null},!1);return}S(``),await f(),m?await g():l?.pairingReady&&await v()},[v,f,g,l?.pairingReady,h?.lanUrl,s?.publicUrl,m]),resetPairBaseFromContext:O}}var Al={actionError:null,starting:!1,stopping:!1,savingAutoStart:!1,consentOpen:!1,autoStartConfirmOpen:!1,releaseConfirmOpen:!1,releasing:!1,brokerSecretDraft:``,savingBrokerSecret:!1,brokerSecretNotice:null};function jl({embedded:e=!1}){let t=a(e=>e.language),n=s(t).tunnelSettings,r=x(e=>e.token),i=!!r,[o,c]=(0,Z.useReducer)(Gt,Al),{actionError:l,starting:u,stopping:f,savingAutoStart:p,consentOpen:m,autoStartConfirmOpen:h,releaseConfirmOpen:g,releasing:_,brokerSecretDraft:v,savingBrokerSecret:y,brokerSecretNotice:b}=o,S=(0,Z.useRef)(null),C=kl(r??``),{data:w}=Ze(i),{data:T,error:E,isLoading:D,mutate:O}=d(i?`tunnel-status`:null,Qt,{refreshInterval:e=>u?1e3:e?.frpcDownload||e?.state===`connecting`||e?.state===`reconnecting`?2e3:6e4}),k=(0,Z.useMemo)(()=>{let e=w?.payload?.config;if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.tunnel;if(t&&typeof t==`object`&&!Array.isArray(t)&&t.autoStart===!0)return!0}return T?.config?.autoStart===!0},[w,T?.config?.autoStart]),A=(0,Z.useMemo)(()=>{let e=w?.payload?.config;if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.tunnel;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.registrationSecret;if(typeof e==`string`)return e}}return``},[w]),j=Oe(A),M=T?.registrationSecret?.source===`env`,N=T?.registrationSecret?.source===`missing`,P=T?.registrationSecret?.configured===!0;(0,Z.useEffect)(()=>{let e=()=>{O()};return window.addEventListener(`tunnel-status`,e),()=>window.removeEventListener(`tunnel-status`,e)},[O]);let I=(0,Z.useMemo)(()=>[n.consentBullet1,n.consentBullet2,n.consentBullet3],[n.consentBullet1,n.consentBullet2,n.consentBullet3]),L=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{actionError:null}}),c({type:`patch`,patch:{starting:!0}});try{let e=await Ae();await O(),mt(),await C.refreshQr(e.qrPayload)}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{starting:!1}})}},[O,C.refreshQr]),R=(0,Z.useCallback)(()=>{if(!P){c({type:`patch`,patch:{actionError:n.brokerSecretRequiredBeforeStart}}),S.current?.scrollIntoView({behavior:`smooth`,block:`start`});return}if(T?.consentRequired){c({type:`patch`,patch:{consentOpen:!0}});return}L()},[P,T?.consentRequired,L,n.brokerSecretRequiredBeforeStart]),z=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{consentOpen:!1}}),c({type:`patch`,patch:{actionError:null}});try{await at(),await Promise.all([O(),L()])}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}},[O,L]),B=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{actionError:null}}),c({type:`patch`,patch:{stopping:!0}});try{await F(),await Promise.all([C.refreshQr(),O()]),mt()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{stopping:!1}})}},[O,C.refreshQr]),V=(0,Z.useCallback)(async e=>{c({type:`patch`,patch:{savingAutoStart:!0}}),c({type:`patch`,patch:{actionError:null}});try{await cn({autoStart:e}),mt()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{savingAutoStart:!1}})}},[]),H=(0,Z.useCallback)(()=>{if(k){V(!1);return}if(T?.consentRequired){c({type:`patch`,patch:{actionError:n.consentExpiredBanner}});return}if(!T?.canAutoStart){c({type:`patch`,patch:{actionError:n.autoStartHint}});return}c({type:`patch`,patch:{autoStartConfirmOpen:!0}})},[V,T?.canAutoStart,T?.consentRequired,n,k]),U=(0,Z.useCallback)(async()=>{let e=v.trim();if(e){c({type:`patch`,patch:{savingBrokerSecret:!0,actionError:null,brokerSecretNotice:null}});try{await cn({registrationSecret:e}),c({type:`patch`,patch:{brokerSecretDraft:``,brokerSecretNotice:n.brokerSecretSaved}}),mt(),await O(),c({type:`patch`,patch:{actionError:null}})}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{savingBrokerSecret:!1}})}}},[v,O,n.brokerSecretSaved]),W=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{savingBrokerSecret:!0,actionError:null,brokerSecretNotice:null}});try{await cn({registrationSecret:null}),c({type:`patch`,patch:{brokerSecretDraft:``,brokerSecretNotice:n.brokerSecretCleared}}),mt(),await O()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{savingBrokerSecret:!1}})}},[O,n.brokerSecretCleared]),G=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{releaseConfirmOpen:!1,actionError:null,releasing:!0}});try{await F({release:!0}),await Promise.all([C.refreshQr(),O()]),mt()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{releasing:!1}})}},[O,C.refreshQr]),ee=(0,Z.useMemo)(()=>({copy:n.copyUrl,copied:n.copied,copyFailed:s(t).clipboard.copyFailed}),[t,n.copyUrl,n.copied]);if(!i)return(0,$.jsx)(`div`,{className:e?void 0:`mx-auto w-full max-w-app-main px-4 py-8`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})});let K=T??{enabled:!1,state:`disconnected`,subdomain:null,publicUrl:null,connectedSince:null,frpcPid:null,lastHeartbeatAt:null,lastError:null,consentRequired:!0,config:{autoStart:k,brokerUrl:`https://frp.xopc.ai/api`}},te=T?.consentRequired&&(K.enabled||k||T?.consent?.acceptedAt),ne=(0,$.jsx)(xl,{t:n,brokerSecretFromEnv:M,brokerSecretMissing:N,brokerSecretConfiguredInConfig:j,brokerSecretMaskedValue:j?A:``,brokerSecretDraft:v,savingBrokerSecret:y,brokerSecretNotice:b,copyFailedLabel:s(t).clipboard.copyFailed,onDraftChange:e=>c({type:`patch`,patch:{brokerSecretDraft:e}}),onSave:()=>void U(),onClear:()=>void W(),sectionRef:S}),re=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(nl,{open:m,title:n.consentTitle,intro:n.consentIntro,bullets:I,checkboxLabel:n.consentCheckbox,confirmLabel:te?n.consentReconfirm:n.consentConfirm,cancelLabel:n.consentCancel,onConfirm:()=>void z(),onCancel:()=>c({type:`patch`,patch:{consentOpen:!1}})},m?`consent-open`:`consent-closed`),(0,$.jsx)(Jt,{open:h,title:n.autoStartConfirmTitle,description:n.autoStartConfirmBody,confirmLabel:n.autoStartConfirmLabel,cancelLabel:n.consentCancel,onConfirm:()=>{c({type:`patch`,patch:{autoStartConfirmOpen:!1}}),V(!0)},onCancel:()=>c({type:`patch`,patch:{autoStartConfirmOpen:!1}})}),(0,$.jsx)(Jt,{open:g,title:n.releaseConfirmTitle,description:n.releaseConfirmBody,confirmLabel:n.releaseConfirmLabel,cancelLabel:n.consentCancel,destructive:!0,onConfirm:()=>void G(),onCancel:()=>c({type:`patch`,patch:{releaseConfirmOpen:!1}})})]});return e?(0,$.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,children:[l?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:l}):null,ne,(0,$.jsx)(vl,{t:n,status:K,isLoading:D,statusErr:E,starting:u,stopping:f,showConsentExpired:!!te,copyLabels:ee,startDisabled:!P,startDisabledReason:P?void 0:n.brokerSecretRequiredBeforeStart,stepLabel:n.flowStepStart,onStart:R,onStop:()=>void B()}),(0,$.jsx)(Qc,{pairQr:C,gatewayToken:r??``,streamlined:!0,onRefreshQr:()=>void C.refreshQr()}),(0,$.jsxs)(br,{showLabel:n.showOptions,hideLabel:n.hideOptions,children:[(0,$.jsxs)(`label`,{className:J(`flex items-center gap-3 text-sm text-fg`,!k&&!T?.canAutoStart?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 rounded border-edge accent-accent`,checked:k,disabled:p||!k&&!T?.canAutoStart,onChange:H}),n.autoStart]}),!T?.canAutoStart&&!k?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.autoStartHint}):null,K.subdomain||K.publicUrl?(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge-subtle pt-4`,children:[(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:_||f,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>c({type:`patch`,patch:{releaseConfirmOpen:!0}}),children:[_?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,n.release]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.releaseHint})]}):null]}),(0,$.jsx)(br,{showLabel:n.showAdvanced,hideLabel:n.hideAdvanced,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-edge-subtle pt-4 text-xs text-fg-subtle`,children:[(0,$.jsxs)(`p`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Xe,{className:`mt-0.5 size-4 shrink-0 text-accent`}),(0,$.jsx)(`span`,{children:n.brokerNote})]}),(0,$.jsx)(Sl,{language:t,label:n.brokerDocsLink,section:`public-tunnel`,className:`text-xs`})]})}),re]}):(0,$.jsxs)(`div`,{className:e?`flex w-full flex-col gap-6`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[e?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),l?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:l}):null,ne,(0,$.jsx)(vl,{t:n,status:K,isLoading:D,statusErr:E,starting:u,stopping:f,showConsentExpired:!!te,copyLabels:ee,startDisabled:!P,startDisabledReason:P?void 0:n.brokerSecretRequiredBeforeStart,onStart:R,onStop:()=>void B()}),(0,$.jsx)(Qc,{pairQr:C,gatewayToken:r??``}),K.subdomain||K.publicUrl?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:_||f,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>c({type:`patch`,patch:{releaseConfirmOpen:!0}}),children:[_?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,n.release]})}):null,K.subdomain||K.publicUrl?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.releaseHint}):null,(0,$.jsxs)(wn,{children:[(0,$.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-fg`,children:n.optionsTitle}),(0,$.jsxs)(`label`,{className:J(`flex items-center gap-3 text-sm text-fg`,!k&&!T?.canAutoStart?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 rounded border-edge accent-accent`,checked:k,disabled:p||!k&&!T?.canAutoStart,onChange:H}),n.autoStart]}),!T?.canAutoStart&&!k?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.autoStartHint}):null]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-xs text-fg-subtle`,children:[(0,$.jsxs)(`p`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Xe,{className:`mt-0.5 size-4 shrink-0 text-accent`}),(0,$.jsx)(`span`,{children:n.brokerNote})]}),(0,$.jsx)(Sl,{language:t,label:n.brokerDocsLink,section:`public-tunnel`,className:`text-xs`})]}),re]})}async function Ml(){let e=await C(`/api/exposure/status`);if(!e.ok)throw Error(`Failed to load exposure status (${e.status})`);return await e.json()}async function Nl(e=`serve`){let t=await C(`/api/exposure/tailscale/start`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Start failed (${t.status})`)}return await t.json()}async function Pl(){let e=await C(`/api/exposure/tailscale/stop`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Stop failed (${e.status})`)}return await e.json()}var Fl=`https://tailscale.com/download`;function Il(e){let t=(0,Q.c)(2),{label:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`a`,{href:Fl,target:`_blank`,rel:`noreferrer`,className:`font-medium text-accent hover:underline`,children:n}),t[0]=n,t[1]=r),r}function Ll({embedded:e=!1}){let t=a(e=>e.language),n=s(t).remoteAccess.tailscale,r=(0,Z.useMemo)(()=>({copy:n.copyUrl,copied:n.copied,copyFailed:s(t).clipboard.copyFailed}),[t,n.copyUrl,n.copied]),i=!!x(e=>e.token),[o,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),{data:f,mutate:p,isLoading:m}=d(i?`exposure-status`:null,Ml,{refreshInterval:3e4}),h=f?.tailscale.hostname,g=f?.tailscale.active===!0,_=f?.tailscale.cliAvailable!==!1,v=h?`https://${h}/`:null,y=(0,Z.useCallback)(async()=>{c(!0),u(null);try{await Nl(`serve`),await p()}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}},[p]),b=(0,Z.useCallback)(async()=>{c(!0),u(null);try{await Pl(),await p()}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}},[p]);if(!i)return null;let S=(0,$.jsxs)(`div`,{className:e?`space-y-4`:`mt-4 space-y-3`,children:[e?(0,$.jsxs)(`ol`,{className:`space-y-3 text-sm text-fg-muted`,children:[(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-hover text-xs font-semibold text-fg`,children:`1`}),(0,$.jsxs)(`span`,{children:[n.stepInstallBefore,(0,$.jsx)(Il,{label:n.stepInstallLink}),n.stepInstallAfter]})]}),(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-hover text-xs font-semibold text-fg`,children:`2`}),(0,$.jsx)(`span`,{children:n.stepEnable})]}),(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-hover text-xs font-semibold text-fg`,children:`3`}),(0,$.jsx)(`span`,{children:n.stepCopy})]})]}):null,e&&f?.tailscale.cliAvailable===!1?(0,$.jsxs)(`p`,{className:`rounded-lg border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-sm text-fg-muted`,children:[n.cliMissingIntro,` `,(0,$.jsx)(Il,{label:n.cliMissingDownloadLink}),n.cliMissingSuffix]}):null,m&&!f?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(wn,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.statusLabel}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:g?n.statusActive:n.statusOff}),v?(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(ie,{text:v,labels:r})}):null,l?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-red-600 dark:text-red-400`,children:l}):null,(0,$.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:g?(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:o,onClick:()=>void b(),children:[o?(0,$.jsx)(q,{className:`mr-1 h-4 w-4 animate-spin`}):null,n.disableServe]}):(0,$.jsxs)(Y,{type:`button`,disabled:o||!_,onClick:()=>void y(),children:[o?(0,$.jsx)(q,{className:`mr-1 h-4 w-4 animate-spin`}):(0,$.jsx)(j,{className:`mr-1 h-4 w-4`}),n.enableServe]})})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.hint}),(0,$.jsx)(Sl,{language:t,label:n.docsLink,section:`tailscale-serve`,className:`mt-2`})]})]});return e?S:(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:Xe,title:n.title,subtitle:n.subtitle}),S]})}function Rl(){let e=(0,Q.c)(26),t=a(Bl),n=x(zl),r;e[0]===t?r=e[1]:(r=s(t),e[0]=t,e[1]=r);let i=r.remoteAccess.lan,o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o={preferLan:!0},e[2]=o):o=e[2];let c=kl(n??``,o),l;e[3]!==i.subtitle||e[4]!==i.title?(l=(0,$.jsx)(Sn,{icon:wt,title:i.title,subtitle:i.subtitle}),e[3]=i.subtitle,e[4]=i.title,e[5]=l):l=e[5];let u;e[6]===i.body?u=e[7]:(u=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:i.body}),e[6]=i.body,e[7]=u);let d;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(Me,{className:`size-3.5`,"aria-hidden":!0}),e[8]=d):d=e[8];let f;e[9]===i.link?f=e[10]:(f=(0,$.jsxs)(Ft,{to:`/settings/gateway`,className:`inline-flex items-center gap-1.5 text-sm font-medium text-accent hover:underline`,children:[i.link,d]}),e[9]=i.link,e[10]=f);let p;e[11]!==u||e[12]!==f?(p=(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[u,f]}),e[11]=u,e[12]=f,e[13]=p):p=e[13];let m;e[14]!==l||e[15]!==p?(m=(0,$.jsxs)(wn,{children:[l,p]}),e[14]=l,e[15]=p,e[16]=m):m=e[16];let h=n??``,g;e[17]===c?g=e[18]:(g=()=>void c.refreshQr(),e[17]=c,e[18]=g);let _;e[19]!==c||e[20]!==h||e[21]!==g?(_=(0,$.jsx)(Qc,{pairQr:c,gatewayToken:h,lanOnly:!0,onRefreshQr:g}),e[19]=c,e[20]=h,e[21]=g,e[22]=_):_=e[22];let v;return e[23]!==_||e[24]!==m?(v=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[m,_]}),e[23]=_,e[24]=m,e[25]=v):v=e[25],v}function zl(e){return e.token}function Bl(e){return e.language}function Vl(e){let t=(0,Q.c)(30),{embedded:n}=e,r=n===void 0?!1:n,i=a(Hl),o;t[0]===i?o=t[1]:(o=s(i),t[0]=i,t[1]=o);let c=o.remoteAccess.ssh,[l,u]=(0,Z.useState)(!1),d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=async()=>{await K(`xopc gateway ssh-tunnel --target user@your-host --local-port 18790 --remote-port 18790`)&&(u(!0),setTimeout(()=>u(!1),2e3))},t[2]=d):d=t[2];let f=d,p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border border-edge bg-surface px-3 py-2 text-xs text-fg-muted`,children:`xopc gateway ssh-tunnel --target user@your-host --local-port 18790 --remote-port 18790`}),t[3]=p):p=t[3];let m,h;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>void f(),h=(0,$.jsx)(D,{className:`mr-1 h-4 w-4`}),t[4]=m,t[5]=h):(m=t[4],h=t[5]);let g=l?c.copied:c.copy,_;t[6]===g?_=t[7]:(_=(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,onClick:m,children:[h,g]})}),t[6]=g,t[7]=_);let v;t[8]!==r||t[9]!==c.hint?(v=r?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:c.hint}):null,t[8]=r,t[9]=c.hint,t[10]=v):v=t[10];let y;t[11]!==_||t[12]!==v?(y=(0,$.jsxs)($.Fragment,{children:[p,_,v]}),t[11]=_,t[12]=v,t[13]=y):y=t[13];let b=y;if(r){let e;t[14]!==c.subtitle||t[15]!==c.title?(e=(0,$.jsx)(Sn,{icon:yt,title:c.title,subtitle:c.subtitle}),t[14]=c.subtitle,t[15]=c.title,t[16]=e):e=t[16];let n;t[17]===b?n=t[18]:(n=(0,$.jsx)(`div`,{className:`mt-4 space-y-2`,children:b}),t[17]=b,t[18]=n);let r;return t[19]!==e||t[20]!==n?(r=(0,$.jsxs)(wn,{children:[e,n]}),t[19]=e,t[20]=n,t[21]=r):r=t[21],r}let x;t[22]!==c.subtitle||t[23]!==c.title?(x=(0,$.jsx)(Sn,{icon:yt,title:c.title,subtitle:c.subtitle}),t[22]=c.subtitle,t[23]=c.title,t[24]=x):x=t[24];let S;t[25]===b?S=t[26]:(S=(0,$.jsx)(`div`,{className:`mt-4`,children:b}),t[25]=b,t[26]=S);let C;return t[27]!==x||t[28]!==S?(C=(0,$.jsxs)(wn,{children:[x,S]}),t[27]=x,t[28]=S,t[29]=C):C=t[29],C}function Hl(e){return e.language}function Ul(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Vl,{embedded:!0}),e[0]=t):t=e[0],t}function Wl(e){switch(e){case`active`:return`bg-emerald-500/15 text-emerald-700 dark:text-emerald-400`;case`connecting`:return`bg-amber-500/15 text-amber-700 dark:text-amber-400`;default:return`bg-surface-hover text-fg-muted`}}function Gl(e){let t=(0,Q.c)(5),{label:n,kind:r}=e,i;t[0]===r?i=t[1]:(i=J(`rounded-full px-2 py-0.5 text-[11px] font-medium`,Wl(r)),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`span`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function Kl(e){let t=(0,Q.c)(32),{onOpenTab:n}=e,r=a(Yl),i;t[0]===r?i=t[1]:(i=s(r),t[0]=r,t[1]=i);let o=i.remoteAccess.guide,c=!!x(Jl),l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l={refreshInterval:3e4},t[2]=l):l=t[2];let{data:u}=d(c?`exposure-status`:null,Ml,l),f;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(f={refreshInterval:15e3},t[3]=f):f=t[3];let{data:p}=d(c?`tunnel-status`:null,Qt,f),m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m={refreshInterval:6e4},t[4]=m):m=t[4];let{data:h}=d(c?`tunnel-pair-context`:null,gt,m);if(!c)return null;let g=u?.tailscale.active===!0,_=p?.state,v=p?.enabled&&_===`connected`,y=p?.enabled&&(_===`connecting`||_===`reconnecting`||!!p?.startProgress||!!p?.frpcDownload),b=(h?.candidates??[]).some(ql),S=g?`active`:`off`,C=g?o.statusActive:o.statusOff,w;t[5]!==o.tailscaleCardTitle||t[6]!==S||t[7]!==C?(w={tab:`tailscale`,icon:Xe,title:o.tailscaleCardTitle,kind:S,statusLabel:C},t[5]=o.tailscaleCardTitle,t[6]=S,t[7]=C,t[8]=w):w=t[8];let T=v?`active`:y?`connecting`:`off`,E=v?o.statusActive:y?o.statusConnecting:o.statusOff,D;t[9]!==o.publicCardTitle||t[10]!==T||t[11]!==E?(D={tab:`public`,icon:Ke,title:o.publicCardTitle,kind:T,statusLabel:E},t[9]=o.publicCardTitle,t[10]=T,t[11]=E,t[12]=D):D=t[12];let O=b?`active`:`off`,k=b?o.statusActive:o.statusOff,A;t[13]!==o.reverseProxyCardTitle||t[14]!==O||t[15]!==k?(A={tab:`reverse-proxy`,icon:B,title:o.reverseProxyCardTitle,kind:O,statusLabel:k},t[13]=o.reverseProxyCardTitle,t[14]=O,t[15]=k,t[16]=A):A=t[16];let j;t[17]!==o.sshCardStatus||t[18]!==o.sshCardTitle?(j={tab:`ssh`,icon:yt,title:o.sshCardTitle,kind:`off`,statusLabel:o.sshCardStatus},t[17]=o.sshCardStatus,t[18]=o.sshCardTitle,t[19]=j):j=t[19];let M;t[20]!==o.lanCardStatus||t[21]!==o.lanCardTitle?(M={tab:`lan`,icon:wt,title:o.lanCardTitle,kind:`off`,statusLabel:o.lanCardStatus},t[20]=o.lanCardStatus,t[21]=o.lanCardTitle,t[22]=M):M=t[22];let N;t[23]!==D||t[24]!==A||t[25]!==j||t[26]!==M||t[27]!==w?(N=[w,D,A,j,M],t[23]=D,t[24]=A,t[25]=j,t[26]=M,t[27]=w,t[28]=N):N=t[28];let P=N,F;return t[29]!==P||t[30]!==n?(F=(0,$.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5`,children:P.map(e=>{let t=e.icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(e.tab),className:J(`flex items-start gap-3 rounded-xl border border-edge-subtle bg-surface-base px-3 py-2.5 text-left transition-colors`,`hover:border-edge hover:bg-surface-hover/50`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:[(0,$.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-hover/90 text-fg-muted`,children:(0,$.jsx)(t,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-medium text-fg`,children:e.title}),(0,$.jsx)(Gl,{label:e.statusLabel,kind:e.kind})]})]},`${e.tab}-${e.title}`)})}),t[29]=P,t[30]=n,t[31]=F):F=t[31],F}function ql(e){return e.kind===`reverse-proxy`}function Jl(e){return e.token}function Yl(e){return e.language}function Xl(e){let t=(0,Q.c)(26),{title:n,description:r,recommended:i,icon:a,onOpen:o,openLabel:s,recommendedLabel:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(`group flex w-full flex-col rounded-2xl bg-surface-base px-4 py-4 text-left transition-colors`,`hover:bg-surface-hover/40`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),t[0]=l):l=t[0];let u;t[1]===a?u=t[2]:(u=(0,$.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-surface-hover/90 text-fg-muted`,children:(0,$.jsx)(a,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})}),t[1]=a,t[2]=u);let d;t[3]===n?d=t[4]:(d=(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n}),t[3]=n,t[4]=d);let f;t[5]!==i||t[6]!==c?(f=i&&c?(0,$.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[11px] font-medium text-accent-fg`,children:c}):null,t[5]=i,t[6]=c,t[7]=f):f=t[7];let p;t[8]!==d||t[9]!==f?(p=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d,f]}),t[8]=d,t[9]=f,t[10]=p):p=t[10];let m;t[11]===r?m=t[12]:(m=(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:r}),t[11]=r,t[12]=m);let h;t[13]!==p||t[14]!==m?(h=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p,m]}),t[13]=p,t[14]=m,t[15]=h):h=t[15];let g;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(G,{className:`mt-0.5 size-4 shrink-0 text-fg-subtle transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0}),t[16]=g):g=t[16];let _;t[17]!==u||t[18]!==h?(_=(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[u,h,g]}),t[17]=u,t[18]=h,t[19]=_):_=t[19];let v;t[20]===s?v=t[21]:(v=(0,$.jsx)(`span`,{className:`mt-3 text-xs font-medium text-accent`,children:s}),t[20]=s,t[21]=v);let y;return t[22]!==o||t[23]!==v||t[24]!==_?(y=(0,$.jsxs)(`button`,{type:`button`,onClick:o,className:l,children:[_,v]}),t[22]=o,t[23]=v,t[24]=_,t[25]=y):y=t[25],y}function Zl(e){let t=(0,Q.c)(83),{onOpenTab:n}=e,r=a(eu),i;t[0]===r?i=t[1]:(i=s(r),t[0]=r,t[1]=i);let o=i.remoteAccess,c=o.guide,l=!!x($l),u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u={refreshInterval:3e4},t[2]=u):u=t[2];let{data:f}=d(l?`exposure-status`:null,Ml,u),p;t[3]===f?.conflicts?p=t[4]:(p=f?.conflicts??[],t[3]=f?.conflicts,t[4]=p);let m=p;if(!l){let e;return t[5]===c.needToken?e=t[6]:(e=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c.needToken}),t[5]=c.needToken,t[6]=e),e}let h;t[7]===n?h=t[8]:(h=(0,$.jsx)(Kl,{onOpenTab:n}),t[7]=n,t[8]=h);let g;t[9]!==m||t[10]!==c.conflictsHint||t[11]!==c.conflictsTitle?(g=m.length>0?(0,$.jsxs)(`div`,{className:`rounded-xl border border-amber-500/30 bg-amber-500/5 px-4 py-3 text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:c.conflictsTitle}),(0,$.jsx)(`p`,{className:`mt-1`,children:c.conflictsHint}),(0,$.jsx)(`ul`,{className:`mt-2 list-inside list-disc text-xs`,children:m.map(Ql)})]}):null,t[9]=m,t[10]=c.conflictsHint,t[11]=c.conflictsTitle,t[12]=g):g=t[12];let _;t[13]===c.pickMethod?_=t[14]:(_=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:c.pickMethod}),t[13]=c.pickMethod,t[14]=_);let v;t[15]===n?v=t[16]:(v=()=>n(`tailscale`),t[15]=n,t[16]=v);let y;t[17]!==c.configure||t[18]!==c.recommended||t[19]!==c.tailscaleCardDesc||t[20]!==c.tailscaleCardTitle||t[21]!==v?(y=(0,$.jsx)(Xl,{icon:Xe,title:c.tailscaleCardTitle,description:c.tailscaleCardDesc,recommended:!0,recommendedLabel:c.recommended,openLabel:c.configure,onOpen:v}),t[17]=c.configure,t[18]=c.recommended,t[19]=c.tailscaleCardDesc,t[20]=c.tailscaleCardTitle,t[21]=v,t[22]=y):y=t[22];let b;t[23]===n?b=t[24]:(b=()=>n(`public`),t[23]=n,t[24]=b);let S;t[25]!==c.configure||t[26]!==c.publicCardDesc||t[27]!==c.publicCardTitle||t[28]!==b?(S=(0,$.jsx)(Xl,{icon:Ke,title:c.publicCardTitle,description:c.publicCardDesc,openLabel:c.configure,onOpen:b}),t[25]=c.configure,t[26]=c.publicCardDesc,t[27]=c.publicCardTitle,t[28]=b,t[29]=S):S=t[29];let C;t[30]===n?C=t[31]:(C=()=>n(`reverse-proxy`),t[30]=n,t[31]=C);let w;t[32]!==c.configure||t[33]!==c.reverseProxyCardDesc||t[34]!==c.reverseProxyCardTitle||t[35]!==C?(w=(0,$.jsx)(Xl,{icon:B,title:c.reverseProxyCardTitle,description:c.reverseProxyCardDesc,openLabel:c.configure,onOpen:C}),t[32]=c.configure,t[33]=c.reverseProxyCardDesc,t[34]=c.reverseProxyCardTitle,t[35]=C,t[36]=w):w=t[36];let T;t[37]===n?T=t[38]:(T=()=>n(`ssh`),t[37]=n,t[38]=T);let E;t[39]!==c.configure||t[40]!==c.sshCardDesc||t[41]!==c.sshCardTitle||t[42]!==T?(E=(0,$.jsx)(Xl,{icon:yt,title:c.sshCardTitle,description:c.sshCardDesc,openLabel:c.configure,onOpen:T}),t[39]=c.configure,t[40]=c.sshCardDesc,t[41]=c.sshCardTitle,t[42]=T,t[43]=E):E=t[43];let D;t[44]===n?D=t[45]:(D=()=>n(`lan`),t[44]=n,t[45]=D);let O;t[46]!==c.configure||t[47]!==c.lanCardDesc||t[48]!==c.lanCardTitle||t[49]!==D?(O=(0,$.jsx)(Xl,{icon:wt,title:c.lanCardTitle,description:c.lanCardDesc,openLabel:c.configure,onOpen:D}),t[46]=c.configure,t[47]=c.lanCardDesc,t[48]=c.lanCardTitle,t[49]=D,t[50]=O):O=t[50];let k;t[51]!==S||t[52]!==w||t[53]!==E||t[54]!==O||t[55]!==y?(k=(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 lg:grid-cols-2`,children:[y,S,w,E,O]}),t[51]=S,t[52]=w,t[53]=E,t[54]=O,t[55]=y,t[56]=k):k=t[56];let A;t[57]!==k||t[58]!==_?(A=(0,$.jsxs)(`div`,{children:[_,k]}),t[57]=k,t[58]=_,t[59]=A):A=t[59];let j;t[60]===c.oneAtATimeHint?j=t[61]:(j=(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:c.oneAtATimeHint}),t[60]=c.oneAtATimeHint,t[61]=j);let M;t[62]===o.advanced.proxyTitle?M=t[63]:(M=(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:o.advanced.proxyTitle}),t[62]=o.advanced.proxyTitle,t[63]=M);let N;t[64]===o.advanced.proxyBody?N=t[65]:(N=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:o.advanced.proxyBody}),t[64]=o.advanced.proxyBody,t[65]=N);let P;t[66]!==r||t[67]!==o.advanced.proxyDocs?(P=(0,$.jsx)(Sl,{language:r,label:o.advanced.proxyDocs,section:`advanced`,className:`mt-2`}),t[66]=r,t[67]=o.advanced.proxyDocs,t[68]=P):P=t[68];let F;t[69]!==M||t[70]!==N||t[71]!==P?(F=(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[M,N,P]}),t[69]=M,t[70]=N,t[71]=P,t[72]=F):F=t[72];let I;t[73]!==c.docsLink||t[74]!==r?(I=(0,$.jsx)(Sl,{language:r,label:c.docsLink}),t[73]=c.docsLink,t[74]=r,t[75]=I):I=t[75];let L;return t[76]!==A||t[77]!==j||t[78]!==F||t[79]!==I||t[80]!==h||t[81]!==g?(L=(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[h,g,A,j,F,I]}),t[76]=A,t[77]=j,t[78]=F,t[79]=I,t[80]=h,t[81]=g,t[82]=L):L=t[82],L}function Ql(e){return(0,$.jsx)(`li`,{children:e.message},e.code)}function $l(e){return e.token}function eu(e){return e.language}async function tu(e){let t=await C(l(`/api/tunnel/pair/probe-public`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e})});if(!t.ok&&t.status!==400)throw Error(`Probe failed (${t.status})`);return await t.json()}async function nu(e){await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{publicUrl:e??null}})})}function ru(e){let t=e.split(`.`).map(e=>Number.parseInt(e,10));if(t.length!==4||t.some(e=>!Number.isFinite(e)))return!1;let[n,r]=t;return n===10||n===127||n===169&&r===254||n===172&&r>=16&&r<=31||n===192&&r===168||n===100&&r>=64&&r<=127}function iu(){return(0,Z.useMemo)(()=>{if(typeof window>`u`)return null;let{protocol:e,hostname:t,origin:n}=window.location;if(e!==`https:`&&e!==`http:`)return null;let r=t.toLowerCase();return!r||r===`localhost`||r===`127.0.0.1`||r===`::1`||r===`[::1]`||r.endsWith(`.local`)||r.endsWith(`.localhost`)||ru(r)?null:n.toLowerCase().replace(/\/+$/,``)},[])}function au(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function ou(e){return(e?.candidates.find(e=>e.kind===`reverse-proxy`))?.url?.trim()||null}function su(e){return(e?.candidates.find(e=>e.kind===`lan`&&e.reachable))?.url?.trim()||null}function cu(){let e=a(e=>e.language),t=s(e).remoteAccess.reverseProxy,n=!!x(e=>e.token),r=iu(),{mutate:i}=u(),{data:c,mutate:l}=d(n?`tunnel-pair-context`:null,gt,{refreshInterval:6e4}),f=ou(c),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)({busy:!1,result:null}),[_,v]=(0,Z.useState)({busy:!1,error:null});(0,Z.useEffect)(()=>{p||(f?m(f):r&&m(r))},[f,r,p]);let y=(0,Z.useMemo)(()=>p.trim()||(f??r??``),[f,r,p]),b=!f&&!!r&&y===r,S=su(c),{data:C,mutate:w}=d(n&&y?[`reverse-proxy-pair`,y]:null,()=>jt(),{refreshInterval:4*6e4,revalidateOnFocus:!1}),T=(0,Z.useMemo)(()=>!y||!C?.pairingSecret?``:o({baseUrl:y,pairingSecret:C.pairingSecret,lanUrl:S}),[y,S,C?.pairingSecret]),E=ve(()=>Tl(T),[T],{enabled:!!T,initial:null,errorData:null}),D=(0,Z.useCallback)(async()=>{let e=p.trim()||y;if(e){g({busy:!0,result:null});try{g({busy:!1,result:await tu(e)})}catch(e){g({busy:!1,result:{ok:!1,code:`NETWORK_ERROR`,message:e instanceof Error?e.message:String(e)}})}}},[p,y]),O=(0,Z.useCallback)(async()=>{let e=y.trim();if(e){v({busy:!0,error:null});try{await nu(e),await l(),await i(`tunnel-pair-context`),v({busy:!1,error:null})}catch(e){v({busy:!1,error:e instanceof Error?e.message:String(e)})}}},[y,i,l]),k=(0,Z.useCallback)(async()=>{v({busy:!0,error:null});try{await nu(null),await l(),await i(`tunnel-pair-context`),m(``),g({busy:!1,result:null}),v({busy:!1,error:null})}catch(e){v({busy:!1,error:e instanceof Error?e.message:String(e)})}},[i,l]),A=(0,Z.useCallback)(async()=>{await w()},[w]);return n?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:Xe,title:t.title,subtitle:t.subtitle}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`reverse-proxy-url`,children:t.urlLabel}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-stretch`,children:[(0,$.jsx)(`input`,{id:`reverse-proxy-url`,className:J(au(),`font-mono text-xs sm:flex-1 sm:min-w-0 sm:w-auto`),type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:t.urlPlaceholder,value:p,onChange:e=>{m(e.target.value),g({busy:!1,result:null})}}),(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`shrink-0 whitespace-nowrap`,onClick:()=>void D(),disabled:h.busy||!p.trim(),children:[h.busy?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):null,h.busy?t.probing:t.probeButton]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.urlHint}),b&&r?(0,$.jsxs)(`div`,{className:`rounded-lg border border-accent/40 bg-accent-soft/50 px-3 py-2 text-xs leading-relaxed text-accent-fg`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:t.autoDetectedTitle}),(0,$.jsx)(`div`,{className:`mt-1 break-all font-mono text-[11px]`,children:r}),(0,$.jsx)(`p`,{className:`mt-1`,children:t.autoDetectedHint})]}):null,h.result?(0,$.jsx)(lu,{result:h.result,labels:t.probeStatus}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:flex-wrap`,children:[y&&f!==y?(0,$.jsxs)(Y,{type:`button`,onClick:()=>void O(),disabled:_.busy,children:[_.busy?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):null,_.busy?t.saving:t.saveAsDefault]}):null,f?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,onClick:()=>void k(),disabled:_.busy,children:t.clear}):null]}),_.error?(0,$.jsx)(`p`,{className:`text-xs text-red-800 dark:text-red-200`,children:_.error}):null,(0,$.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs leading-relaxed text-amber-950 dark:border-amber-800/60 dark:bg-amber-950/30 dark:text-amber-100`,children:t.certWarning})]})]}),(0,$.jsxs)(wn,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:t.qrTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:t.qrSubtitle})]}),T?(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`shrink-0`,onClick:()=>void A(),children:[(0,$.jsx)(Ee,{className:`size-4`}),t.refreshQr]}):null]}),y?C?.pairingSecret?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[(0,$.jsxs)(`div`,{className:`break-all font-mono text-[11px] text-fg-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:`baseUrl:`}),` `,y,S?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`br`,{}),(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:`lanUrl:`}),` `,S]}):null]}),E.data?(0,$.jsx)(`img`,{src:E.data,alt:``,className:`size-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):E.loading?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.encoding}):null,(0,$.jsx)(ie,{text:T,labels:{copy:t.copyLink,copied:t.copied,copyFailed:s(e).clipboard.copyFailed}})]}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.mintingSecret}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUrlYet})]})]}):null}function lu(e){let t=(0,Q.c)(18),{result:n,labels:r}=e;if(n.ok){let e;t[0]===r.ok?e=t[1]:(e=(0,$.jsx)(`span`,{className:`font-medium`,children:r.ok}),t[0]=r.ok,t[1]=e);let i;t[2]===n.latencyMs?i=t[3]:(i=(0,$.jsxs)(`span`,{className:`font-mono`,children:[n.latencyMs,`ms`]}),t[2]=n.latencyMs,t[3]=i);let a;t[4]!==r.mobileReady||t[5]!==n.mobilePairing?(a=n.mobilePairing?(0,$.jsxs)($.Fragment,{children:[` · `,(0,$.jsx)(`span`,{children:r.mobileReady})]}):null,t[4]=r.mobileReady,t[5]=n.mobilePairing,t[6]=a):a=t[6];let o;return t[7]!==e||t[8]!==i||t[9]!==a?(o=(0,$.jsxs)(`div`,{className:`rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-900 dark:border-emerald-800/60 dark:bg-emerald-950/30 dark:text-emerald-100`,children:[e,` · `,i,a]}),t[7]=e,t[8]=i,t[9]=a,t[10]=o):o=t[10],o}let i=r[`code_${n.code}`]??r.codeUnknown,a;t[11]===i?a=t[12]:(a=(0,$.jsx)(`span`,{className:`font-medium`,children:i}),t[11]=i,t[12]=a);let o;t[13]===n.message?o=t[14]:(o=n.message?(0,$.jsxs)($.Fragment,{children:[` — `,(0,$.jsx)(`span`,{className:`font-mono break-all`,children:n.message})]}):null,t[13]=n.message,t[14]=o);let s;return t[15]!==a||t[16]!==o?(s=(0,$.jsxs)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-900 dark:border-red-800/60 dark:bg-red-950/30 dark:text-red-100`,children:[a,o]}),t[15]=a,t[16]=o,t[17]=s):s=t[17],s}var uu=[`guide`,`tailscale`,`public`,`reverse-proxy`,`ssh`,`lan`];function du(e){return e&&uu.includes(e)?e:`guide`}function fu(e,t){return e.tabs[t]}function pu(e,t){return e.tabIntro[t]}function mu(e){switch(e){case`tailscale`:return`tailscale-serve`;case`public`:return`public-tunnel`;case`reverse-proxy`:return`reverse-proxy`;case`ssh`:return`ssh-tunnel`;case`lan`:return`lan`;default:return}}function hu(e){let t=(0,Q.c)(7),{tab:n,onOpenTab:r}=e;switch(n){case`guide`:{let e;return t[0]===r?e=t[1]:(e=(0,$.jsx)(Zl,{onOpenTab:r}),t[0]=r,t[1]=e),e}case`tailscale`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ll,{embedded:!0}),t[2]=e):e=t[2],e}case`public`:{let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(jl,{embedded:!0}),t[3]=e):e=t[3],e}case`reverse-proxy`:{let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(cu,{}),t[4]=e):e=t[4],e}case`ssh`:{let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ul,{}),t[5]=e):e=t[5],e}case`lan`:{let e;return t[6]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Rl,{}),t[6]=e):e=t[6],e}}}function gu(){let e=(0,Q.c)(2),t=a(vu),n=s(t).remoteAccess,r=!!x(_u),[i,o]=ot(),c=du(i.get(`tab`)),l;e[0]===o?l=e[1]:(l=e=>{o(t=>{let n=new URLSearchParams(t);return e===`guide`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},e[0]=o,e[1]=l);let u=l,d=pu(n,c);return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-5 px-4 py-8`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.pageTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.pageSubtitle}),(0,$.jsx)(Sl,{language:t,label:n.docsLink,section:mu(c),className:`mt-1`})]}),r?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,role:`tablist`,"aria-label":n.tabsAria,onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=uu[(uu.indexOf(c)+(e.key===`ArrowRight`?1:-1)+uu.length)%uu.length];u(t)},children:[(0,$.jsx)(`div`,{className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:uu.map(e=>{let t=e===c;return(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,id:`remote-access-tab-${e}`,"aria-controls":`remote-access-panel-${e}`,className:J(`shrink-0 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,t?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>u(e),children:fu(n,e)},e)})}),c===`public`?null:(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:d}),(0,$.jsx)(`div`,{role:`tabpanel`,id:`remote-access-panel-${c}`,"aria-labelledby":`remote-access-tab-${c}`,className:`min-w-0`,children:(0,$.jsx)(hu,{tab:c,onOpenTab:u})})]}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.guide.needToken})]})}function _u(e){return e.token}function vu(e){return e.language}var yu={enabled:!0,defaultTtlHours:24,maxTtlDays:7,maxActiveShares:100,maxFileSizeMb:100,inlinePreviewMimes:[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`application/pdf`,`text/html`,`text/markdown`,`text/plain`,`application/json`]},bu=36e5,xu=864e5,Su=1048576;function Cu(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wu(e,t=32){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()).slice(0,t):[]}function Tu(e){let t=Cu(e)?e:{},n=Cu(t.gateway)?t.gateway:{},r=Cu(n.share)?n.share:{},i=typeof r.defaultTtlMs==`number`&&Number.isFinite(r.defaultTtlMs)?Math.floor(r.defaultTtlMs):yu.defaultTtlHours*bu,a=typeof r.maxTtlMs==`number`&&Number.isFinite(r.maxTtlMs)?Math.floor(r.maxTtlMs):yu.maxTtlDays*xu,o=typeof r.maxFileSize==`number`&&Number.isFinite(r.maxFileSize)?Math.floor(r.maxFileSize):yu.maxFileSizeMb*Su;return{enabled:r.enabled!==!1,defaultTtlHours:Math.max(1,Math.round(i/bu)),maxTtlDays:Math.max(1,Math.round(a/xu)),maxActiveShares:typeof r.maxActiveShares==`number`&&Number.isFinite(r.maxActiveShares)?Math.max(1,Math.min(1e4,Math.floor(r.maxActiveShares))):yu.maxActiveShares,maxFileSizeMb:Math.max(1,Math.round(o/Su)),inlinePreviewMimes:wu(r.inlinePreviewMimes,32).length?wu(r.inlinePreviewMimes,32):[...yu.inlinePreviewMimes]}}function Eu(e){let t=e.defaultTtlHours*bu,n=e.maxTtlDays*xu;return t<6e4||t>6048e5?`Default share TTL must be between 1 minute and 7 days.`:n<6e4||n>2592e6?`Maximum share TTL must be between 1 minute and 30 days.`:t>n?`Default TTL cannot exceed maximum TTL.`:e.maxFileSizeMb<1||e.maxFileSizeMb>10240?`Maximum file size must be between 1 MB and 10 GB.`:null}async function Du(e){let t=Eu(e);if(t)throw Error(t);await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{share:{enabled:e.enabled,defaultTtlMs:e.defaultTtlHours*bu,maxTtlMs:e.maxTtlDays*xu,maxActiveShares:e.maxActiveShares,maxFileSize:e.maxFileSizeMb*Su,inlinePreviewMimes:e.inlinePreviewMimes}}})}),mt()}function Ou(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt,`dark:border-edge`)}function ku({hasToken:e}){let t=s(a(e=>e.language)).sharesSettings,{data:n,isLoading:r}=Ze(e),i=(0,Z.useMemo)(()=>n?.payload?.config===void 0?null:structuredClone(Tu(n.payload.config)),[n]),o=(0,Z.useRef)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),g=c??i,_=i,v=(0,Z.useMemo)(()=>!g||!_?!1:JSON.stringify(g)!==JSON.stringify(_),[g,_]),y=(0,Z.useCallback)(e=>{o.current=!0,l(t=>{let n=t??_;return n?{...n,...e}:null})},[_]),b=(0,Z.useCallback)(async()=>{if(!(!g||u)){d(!0),p(null),h(!1);try{await Du(g),o.current=!1,l(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:t.policySaveError)}finally{d(!1)}}},[g,u,t.policySaveError]),x=(0,Z.useCallback)(()=>{o.current=!1,l(null),p(null),h(!1)},[]);return!e||!g?r?(0,$.jsx)(wn,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),t.policyLoading]})}):null:(0,$.jsxs)(wn,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.policyTitle}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:t.policyHint})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[m?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:t.policySaved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!v||u,onClick:x,children:t.policyDiscard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!v||u,onClick:()=>void b(),children:u?t.policySaving:t.policySave})]})]}),v?(0,$.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:t.policyUnsaved}):null,f?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,$.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:t.policyRestartHint}),(0,$.jsx)(Au,{t,form:g,onChange:y})]})}function Au(e){let t=(0,Q.c)(56),{t:n,form:r,onChange:i}=e,a;t[0]===i?a=t[1]:(a=e=>i({enabled:e.target.checked}),t[0]=i,t[1]=a);let o;t[2]!==r.enabled||t[3]!==a?(o=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:a}),t[2]=r.enabled,t[3]=a,t[4]=o):o=t[4];let s;t[5]!==n.policyEnabled||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[o,n.policyEnabled]}),t[5]=n.policyEnabled,t[6]=o,t[7]=s):s=t[7];let c=!r.enabled,l;t[8]===i?l=t[9]:(l=e=>i({defaultTtlHours:e}),t[8]=i,t[9]=l);let u;t[10]!==r.defaultTtlHours||t[11]!==n.policyDefaultTtlHint||t[12]!==n.policyDefaultTtlHours||t[13]!==c||t[14]!==l?(u=(0,$.jsx)(ju,{id:`share-default-ttl-hours`,label:n.policyDefaultTtlHours,hint:n.policyDefaultTtlHint,value:r.defaultTtlHours,min:1,max:168,disabled:c,onChange:l}),t[10]=r.defaultTtlHours,t[11]=n.policyDefaultTtlHint,t[12]=n.policyDefaultTtlHours,t[13]=c,t[14]=l,t[15]=u):u=t[15];let d=!r.enabled,f;t[16]===i?f=t[17]:(f=e=>i({maxTtlDays:e}),t[16]=i,t[17]=f);let p;t[18]!==r.maxTtlDays||t[19]!==n.policyMaxTtlDays||t[20]!==n.policyMaxTtlHint||t[21]!==d||t[22]!==f?(p=(0,$.jsx)(ju,{id:`share-max-ttl-days`,label:n.policyMaxTtlDays,hint:n.policyMaxTtlHint,value:r.maxTtlDays,min:1,max:30,disabled:d,onChange:f}),t[18]=r.maxTtlDays,t[19]=n.policyMaxTtlDays,t[20]=n.policyMaxTtlHint,t[21]=d,t[22]=f,t[23]=p):p=t[23];let m=!r.enabled,h;t[24]===i?h=t[25]:(h=e=>i({maxActiveShares:e}),t[24]=i,t[25]=h);let g;t[26]!==r.maxActiveShares||t[27]!==n.policyMaxActiveShares||t[28]!==n.policyMaxActiveSharesHint||t[29]!==m||t[30]!==h?(g=(0,$.jsx)(ju,{id:`share-max-active`,label:n.policyMaxActiveShares,hint:n.policyMaxActiveSharesHint,value:r.maxActiveShares,min:1,max:1e4,disabled:m,onChange:h}),t[26]=r.maxActiveShares,t[27]=n.policyMaxActiveShares,t[28]=n.policyMaxActiveSharesHint,t[29]=m,t[30]=h,t[31]=g):g=t[31];let _=!r.enabled,v;t[32]===i?v=t[33]:(v=e=>i({maxFileSizeMb:e}),t[32]=i,t[33]=v);let y;t[34]!==r.maxFileSizeMb||t[35]!==n.policyMaxFileSizeHint||t[36]!==n.policyMaxFileSizeMb||t[37]!==_||t[38]!==v?(y=(0,$.jsx)(ju,{id:`share-max-file-mb`,label:n.policyMaxFileSizeMb,hint:n.policyMaxFileSizeHint,value:r.maxFileSizeMb,min:1,max:10240,disabled:_,onChange:v}),t[34]=r.maxFileSizeMb,t[35]=n.policyMaxFileSizeHint,t[36]=n.policyMaxFileSizeMb,t[37]=_,t[38]=v,t[39]=y):y=t[39];let b;t[40]!==g||t[41]!==y||t[42]!==u||t[43]!==p?(b=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[u,p,g,y]}),t[40]=g,t[41]=y,t[42]=u,t[43]=p,t[44]=b):b=t[44];let x=!r.enabled,S;t[45]===i?S=t[46]:(S=e=>i({inlinePreviewMimes:e}),t[45]=i,t[46]=S);let C;t[47]!==r.inlinePreviewMimes||t[48]!==n||t[49]!==x||t[50]!==S?(C=(0,$.jsx)(Mu,{t:n,values:r.inlinePreviewMimes,disabled:x,onChange:S}),t[47]=r.inlinePreviewMimes,t[48]=n,t[49]=x,t[50]=S,t[51]=C):C=t[51];let w;return t[52]!==b||t[53]!==C||t[54]!==s?(w=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[s,b,C]}),t[52]=b,t[53]=C,t[54]=s,t[55]=w):w=t[55],w}function ju(e){let t=(0,Q.c)(21),{id:n,label:r,hint:i,value:a,min:o,max:s,disabled:c,onChange:l}=e,u;t[0]!==n||t[1]!==r?(u=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:n,children:r}),t[0]=n,t[1]=r,t[2]=u):u=t[2];let d;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(d=J(Ou(),`max-w-xs font-mono text-xs`),t[3]=d):d=t[3];let f;t[4]!==s||t[5]!==o||t[6]!==l?(f=e=>{let t=Number(e.target.value);Number.isFinite(t)&&l(Math.max(o,Math.min(s,Math.floor(t))))},t[4]=s,t[5]=o,t[6]=l,t[7]=f):f=t[7];let p;t[8]!==c||t[9]!==n||t[10]!==s||t[11]!==o||t[12]!==f||t[13]!==a?(p=(0,$.jsx)(`input`,{id:n,type:`number`,min:o,max:s,disabled:c,className:d,value:a,onChange:f}),t[8]=c,t[9]=n,t[10]=s,t[11]=o,t[12]=f,t[13]=a,t[14]=p):p=t[14];let m;t[15]===i?m=t[16]:(m=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:i}),t[15]=i,t[16]=m);let h;return t[17]!==u||t[18]!==p||t[19]!==m?(h=(0,$.jsxs)(`div`,{children:[u,p,m]}),t[17]=u,t[18]=p,t[19]=m,t[20]=h):h=t[20],h}function Mu(e){let t=(0,Q.c)(25),{t:n,values:r,disabled:i,onChange:a}=e,o;t[0]!==a||t[1]!==r?(o=e=>{let t=e.trim();!t||r.includes(t)||r.length>=32||a([...r,t])},t[0]=a,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===n.policyInlinePreviewMimes?c=t[4]:(c=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.policyInlinePreviewMimes}),t[3]=n.policyInlinePreviewMimes,t[4]=c);let l;t[5]===n.policyInlinePreviewMimesHint?l=t[6]:(l=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.policyInlinePreviewMimesHint}),t[5]=n.policyInlinePreviewMimesHint,t[6]=l);let u;t[7]!==i||t[8]!==a||t[9]!==r?(u=r.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-panel px-2 py-0.5 font-mono text-xs text-fg`,children:[e,i?null:(0,$.jsx)(`button`,{type:`button`,className:`text-fg-muted hover:text-fg`,"aria-label":`Remove ${e}`,onClick:()=>a(r.filter(t=>t!==e)),children:`×`})]},e)),t[7]=i,t[8]=a,t[9]=r,t[10]=u):u=t[10];let d;t[11]===u?d=t[12]:(d=(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u}),t[11]=u,t[12]=d);let f;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(f=J(Ou(),`font-mono text-xs`),t[13]=f):f=t[13];let p=i||r.length>=32,m;t[14]===s?m=t[15]:(m=e=>{e.key===`Enter`&&(e.preventDefault(),s(e.target.value),e.target.value=``)},t[14]=s,t[15]=m);let h;t[16]!==n.policyMimePlaceholder||t[17]!==p||t[18]!==m?(h=(0,$.jsx)(`input`,{className:f,placeholder:n.policyMimePlaceholder,disabled:p,onKeyDown:m}),t[16]=n.policyMimePlaceholder,t[17]=p,t[18]=m,t[19]=h):h=t[19];let g;return t[20]!==c||t[21]!==l||t[22]!==d||t[23]!==h?(g=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[c,l,d,h]}),t[20]=c,t[21]=l,t[22]=d,t[23]=h,t[24]=g):g=t[24],g}function Nu(e){let t=(0,Q.c)(99),{open:n,onOpenChange:r,onConfirm:i,initialPath:o,selectKind:c,sessionKey:l,agentId:u}=e,f=c===void 0?`any`:c,_=a(Iu),b;t[0]===_?b=t[1]:(b=s(_),t[0]=_,t[1]=b);let S=b,C=S.workspace,w=S.sharesSettings,T=V(Fu),{data:E}=d(x(Pu)?`picker-agents-list`:null,te),D;bb0:{let e;t[2]===u?e=t[3]:(e=u?.trim(),t[2]=u,t[3]=e);let n=e;if(n){D=n;break bb0}let r;t[4]===T?r=t[5]:(r=T.trim(),t[4]=T,t[5]=r);let i=r;if(i){D=i;break bb0}if(E?.defaultId){D=E.defaultId;break bb0}if(E?.agents?.[0]?.id){D=E.agents[0].id;break bb0}D=``}let O=D,[k,A]=(0,Z.useState)(O),j,M;t[6]===O?(j=t[7],M=t[8]):(j=()=>{A(O)},M=[O],t[6]=O,t[7]=j,t[8]=M),(0,Z.useEffect)(j,M);let{tree:N,loading:P,error:F,loadRoot:I,loadChildren:L,reset:z}=R(k,l??null),B;t[9]===o?B=t[10]:(B=o?{path:o,isDirectory:!1}:null,t[9]=o,t[10]=B);let[H,U]=(0,Z.useState)(B),W;t[11]!==o||t[12]!==I||t[13]!==n||t[14]!==z?(W=()=>{if(!n){z(),U(o?{path:o,isDirectory:!1}:null);return}I()},t[11]=o,t[12]=I,t[13]=n,t[14]=z,t[15]=W):W=t[15];let G;t[16]!==o||t[17]!==I||t[18]!==n||t[19]!==k||t[20]!==z||t[21]!==l?(G=[n,k,l,I,z,o],t[16]=o,t[17]=I,t[18]=n,t[19]=k,t[20]=z,t[21]=l,t[22]=G):G=t[22],(0,Z.useEffect)(W,G);let ee;t[23]===L?ee=t[24]:(ee=e=>{L(e)},t[23]=L,t[24]=ee);let K=ee,ne=H!==null&&(f===`any`||f===`file`&&!H.isDirectory||f===`directory`&&H.isDirectory),re;bb1:{if(!H){re=w.pickerHintNone;break bb1}if(f===`file`&&H.isDirectory){re=w.pickerHintNeedsFile;break bb1}if(f===`directory`&&!H.isDirectory){re=w.pickerHintNeedsDirectory;break bb1}re=`${H.isDirectory?`📁`:`📄`} ${H.path}`}let ie=re,ae;t[25]===E?.agents?ae=t[26]:(ae=E?.agents??[],t[25]=E?.agents,t[26]=ae);let oe=ae,se;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(se=(0,$.jsx)(m,{className:`fixed inset-0 z-[70] bg-scrim backdrop-blur-[2px]`}),t[27]=se):se=t[27];let ce;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(ce=J(`fixed left-1/2 top-1/2 z-[71] w-[min(34rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2`,`flex h-[min(28rem,calc(100vh-3rem))] flex-col overflow-hidden rounded-lg border border-edge bg-surface-panel shadow-popover outline-none`),t[28]=ce):ce=t[28];let le;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(it,{className:`size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),t[29]=le):le=t[29];let ue;t[30]===w.pickerTitle?ue=t[31]:(ue=(0,$.jsx)(v,{className:`min-w-0 flex-1 truncate text-base font-semibold text-fg`,children:w.pickerTitle}),t[30]=w.pickerTitle,t[31]=ue);let de=S.cron.refresh,fe=S.cron.refresh,pe;t[32]===I?pe=t[33]:(pe=()=>void I(),t[32]=I,t[33]=pe);let me=P&&`animate-spin`,he;t[34]===me?he=t[35]:(he=J(`size-4`,me),t[34]=me,t[35]=he);let ge;t[36]===he?ge=t[37]:(ge=(0,$.jsx)(Ee,{className:he,"aria-hidden":!0}),t[36]=he,t[37]=ge);let _e;t[38]!==P||t[39]!==S.cron.refresh||t[40]!==pe||t[41]!==ge?(_e=(0,$.jsx)(`button`,{type:`button`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-md text-fg-muted hover:bg-surface-hover hover:text-fg disabled:opacity-50`,title:de,"aria-label":fe,disabled:P,onClick:pe,children:ge}),t[38]=P,t[39]=S.cron.refresh,t[40]=pe,t[41]=ge,t[42]=_e):_e=t[42];let ve;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(0,$.jsx)(xt,{className:`size-4`}),t[43]=ve):ve=t[43];let ye;t[44]===C.close?ye=t[45]:(ye=(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-md text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":C.close,children:ve})}),t[44]=C.close,t[45]=ye);let be;t[46]!==ue||t[47]!==_e||t[48]!==ye?(be=(0,$.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b border-edge px-4`,children:[le,ue,_e,ye]}),t[46]=ue,t[47]=_e,t[48]=ye,t[49]=be):be=t[49];let xe;t[50]!==oe||t[51]!==E?.defaultId||t[52]!==k||t[53]!==w.pickerAgentLabel?(xe=oe.length>0?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-edge px-4 py-2`,children:[(0,$.jsx)(`label`,{className:`text-xs text-fg-muted`,htmlFor:`picker-agent-select`,children:w.pickerAgentLabel}),(0,$.jsx)(`select`,{id:`picker-agent-select`,className:`min-w-0 flex-1 rounded-md border border-edge bg-surface-panel px-2 py-1 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:k,onChange:e=>{A(e.target.value),U(null)},children:oe.map(e=>(0,$.jsxs)(`option`,{value:e.id,children:[e.name||e.id,e.id===E?.defaultId?` ★`:``]},e.id))})]}):null,t[50]=oe,t[51]=E?.defaultId,t[52]=k,t[53]=w.pickerAgentLabel,t[54]=xe):xe=t[54];let Se;t[55]!==F||t[56]!==C.loadError?(Se=F?(0,$.jsxs)(`p`,{className:`shrink-0 px-4 py-2 text-xs text-red-600 dark:text-red-400`,children:[C.loadError,`: `,F]}):null,t[55]=F,t[56]=C.loadError,t[57]=Se):Se=t[57];let Ce;t[58]!==K||t[59]!==P||t[60]!==H?.path||t[61]!==C.emptyDir||t[62]!==C.title||t[63]!==N?(Ce=P&&N.length===0?(0,$.jsxs)(`p`,{className:`flex shrink-0 items-center gap-2 px-4 py-3 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),C.title,`…`]}):(0,$.jsx)(Ve,{tree:N,selectedPath:H?.path??null,onSelectFile:e=>U({path:e,isDirectory:!1}),onSelectEntry:(e,t)=>U({path:e,isDirectory:t}),onExpandDir:K,onAction:void 0,emptyHint:C.emptyDir}),t[58]=K,t[59]=P,t[60]=H?.path,t[61]=C.emptyDir,t[62]=C.title,t[63]=N,t[64]=Ce):Ce=t[64];let we;t[65]!==Se||t[66]!==Ce?(we=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[Se,Ce]}),t[65]=Se,t[66]=Ce,t[67]=we):we=t[67];let Te;t[68]===ie?Te=t[69]:(Te=(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-fg-muted`,children:ie}),t[68]=ie,t[69]=Te);let De;t[70]===r?De=t[71]:(De=()=>r(!1),t[70]=r,t[71]=De);let Oe;t[72]!==w.cancel||t[73]!==De?(Oe=(0,$.jsx)(Y,{type:`button`,variant:`ghost`,onClick:De,children:w.cancel}),t[72]=w.cancel,t[73]=De,t[74]=Oe):Oe=t[74];let ke=!ne,Ae;t[75]!==i||t[76]!==r||t[77]!==k||t[78]!==H?(Ae=()=>{H&&(i({...H,agentId:k}),r(!1))},t[75]=i,t[76]=r,t[77]=k,t[78]=H,t[79]=Ae):Ae=t[79];let je;t[80]!==w.pickerConfirm||t[81]!==ke||t[82]!==Ae?(je=(0,$.jsx)(Y,{type:`button`,disabled:ke,onClick:Ae,children:w.pickerConfirm}),t[80]=w.pickerConfirm,t[81]=ke,t[82]=Ae,t[83]=je):je=t[83];let Me;t[84]!==Oe||t[85]!==je?(Me=(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[Oe,je]}),t[84]=Oe,t[85]=je,t[86]=Me):Me=t[86];let Ne;t[87]!==Te||t[88]!==Me?(Ne=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-edge px-4 py-3`,children:[Te,Me]}),t[87]=Te,t[88]=Me,t[89]=Ne):Ne=t[89];let Pe;t[90]!==be||t[91]!==xe||t[92]!==we||t[93]!==Ne?(Pe=(0,$.jsxs)(p,{children:[se,(0,$.jsxs)(h,{className:ce,children:[be,xe,we,Ne]})]}),t[90]=be,t[91]=xe,t[92]=we,t[93]=Ne,t[94]=Pe):Pe=t[94];let Fe;return t[95]!==r||t[96]!==n||t[97]!==Pe?(Fe=(0,$.jsx)(g,{open:n,onOpenChange:r,children:Pe}),t[95]=r,t[96]=n,t[97]=Pe,t[98]=Fe):Fe=t[98],Fe}function Pu(e){return e.token}function Fu(e){return e.agentId}function Iu(e){return e.language}var Lu=[`shares`,`policy`];function Ru(e){let t=(e??``).trim();return Lu.includes(t)?t:`shares`}function zu(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function Bu(e,t){let n=new Date(e).getTime()-Date.now(),r=Math.abs(n),i=n<0;if(r<6e4)return t===`zh`?`刚刚`:`just now`;let a=Math.floor(r/6e4);if(a<60){let e=t===`zh`?`${a} 分钟`:`${a}m`;return i?t===`zh`?`${e}前`:`${e} ago`:e}let o=Math.floor(a/60);if(o<24){let e=t===`zh`?`${o} 小时`:`${o}h`;return i?t===`zh`?`${e}前`:`${e} ago`:e}let s=Math.floor(o/24),c=t===`zh`?`${s} 天`:`${s}d`;return i?t===`zh`?`${c}前`:`${c} ago`:c}var Vu=[{value:36e5,key:`1h`},{value:216e5,key:`6h`},{value:864e5,key:`24h`},{value:2592e5,key:`3d`},{value:6048e5,key:`7d`}];function Hu(){let e=(0,Q.c)(44),t=a(Wu),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.sharesSettings,i=!!x(Uu),[o,c]=ot(),l;e[2]===o?l=e[3]:(l=Ru(o.get(`tab`)),e[2]=o,e[3]=l);let u=l,d;e[4]===c?d=e[5]:(d=e=>{c(t=>{let n=new URLSearchParams(t);return e===`shares`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},e[4]=c,e[5]=d);let f=d;if(!i){let t;return e[6]===r.needToken?t=e[7]:(t=(0,$.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})}),e[6]=r.needToken,e[7]=t),t}let p;e[8]!==r.tabPolicy||e[9]!==r.tabShares?(p={shares:r.tabShares,policy:r.tabPolicy},e[8]=r.tabPolicy,e[9]=r.tabShares,e[10]=p):p=e[10];let m=p,h;e[11]===r.title?h=e[12]:(h=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title}),e[11]=r.title,e[12]=h);let g;e[13]===r.subtitle?g=e[14]:(g=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),e[13]=r.subtitle,e[14]=g);let _;e[15]!==h||e[16]!==g?(_=(0,$.jsxs)(`div`,{children:[h,g]}),e[15]=h,e[16]=g,e[17]=_):_=e[17];let v=r.tabsAria,y;e[18]!==u||e[19]!==f?(y=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=Lu[(Lu.indexOf(u)+(e.key===`ArrowRight`?1:-1)+Lu.length)%Lu.length];f(t)},e[18]=u,e[19]=f,e[20]=y):y=e[20];let b;e[21]!==u||e[22]!==f||e[23]!==m?(b=Lu.map(e=>{let t=e===u;return(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,id:`shares-tab-${e}`,"aria-controls":`shares-panel-${e}`,className:J(`shrink-0 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,X.press,t?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>f(e),children:m[e]},e)}),e[21]=u,e[22]=f,e[23]=m,e[24]=b):b=e[24];let S;e[25]===b?S=e[26]:(S=(0,$.jsx)(`div`,{className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:b}),e[25]=b,e[26]=S);let C=`shares-panel-${u}`,w=`shares-tab-${u}`,T;e[27]!==u||e[28]!==i||e[29]!==t||e[30]!==r?(T=u===`shares`?(0,$.jsx)(Gu,{t:r,language:t}):(0,$.jsx)(ku,{hasToken:i}),e[27]=u,e[28]=i,e[29]=t,e[30]=r,e[31]=T):T=e[31];let E;e[32]!==C||e[33]!==w||e[34]!==T?(E=(0,$.jsx)(`div`,{role:`tabpanel`,id:C,"aria-labelledby":w,className:`min-w-0`,children:T}),e[32]=C,e[33]=w,e[34]=T,e[35]=E):E=e[35];let D;e[36]!==r.tabsAria||e[37]!==S||e[38]!==E||e[39]!==y?(D=(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,role:`tablist`,"aria-label":v,onKeyDown:y,children:[S,E]}),e[36]=r.tabsAria,e[37]=S,e[38]=E,e[39]=y,e[40]=D):D=e[40];let O;return e[41]!==D||e[42]!==_?(O=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[_,D]}),e[41]=D,e[42]=_,e[43]=O):O=e[43],O}function Uu(e){return e.token}function Wu(e){return e.language}function Gu(e){let t=(0,Q.c)(60),{t:n,language:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={refreshInterval:3e4},t[0]=i):i=t[0];let{data:a,error:o,isLoading:s,mutate:c}=d(`shares-list`,Tt,i),l;t[1]===a?.payload?.shares?l=t[2]:(l=a?.payload?.shares??[],t[1]=a?.payload?.shares,t[2]=l);let u=l,[f,p]=(0,Z.useState)(!1),m;bb0:{if(f){m=u;break bb0}let e;t[3]===u?e=t[4]:(e=u.filter(Yu),t[3]=u,t[4]=e),m=e}let h=m,g;t[5]===u?g=t[6]:(g=u.filter(Ju),t[5]=u,t[6]=g);let _=g.length,v;t[7]===u?v=t[8]:(v=u.filter(qu),t[7]=u,t[8]=v);let y=v.length,b;t[9]===c?b=t[10]:(b=()=>void c(),t[9]=c,t[10]=b);let x;t[11]!==n||t[12]!==b?(x=(0,$.jsx)(Zu,{t:n,onCreated:b}),t[11]=n,t[12]=b,t[13]=x):x=t[13];let S=f?n.allSharesTitle:n.listTitle,C;t[14]===_?C=t[15]:(C=_>0&&(0,$.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:[`(`,_,`)`]}),t[14]=_,t[15]=C);let w;t[16]!==S||t[17]!==C?(w=(0,$.jsxs)(`h2`,{className:`text-sm font-semibold text-fg`,children:[S,C]}),t[16]=S,t[17]=C,t[18]=w):w=t[18];let T;t[19]===c?T=t[20]:(T=()=>void c(),t[19]=c,t[20]=T);let E=s&&`animate-spin`,D;t[21]===E?D=t[22]:(D=J(`size-3.5`,E),t[21]=E,t[22]=D);let O;t[23]===D?O=t[24]:(O=(0,$.jsx)(Ee,{className:D}),t[23]=D,t[24]=O);let k;t[25]!==s||t[26]!==T||t[27]!==O?(k=(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1`,onClick:T,disabled:s,children:O}),t[25]=s,t[26]=T,t[27]=O,t[28]=k):k=t[28];let A;t[29]!==y||t[30]!==f||t[31]!==n.hideExpired||t[32]!==n.showExpired?(A=y>0&&(0,$.jsx)(`button`,{type:`button`,className:`text-xs text-accent hover:underline`,onClick:()=>p(Ku),children:f?n.hideExpired:n.showExpired}),t[29]=y,t[30]=f,t[31]=n.hideExpired,t[32]=n.showExpired,t[33]=A):A=t[33];let j;t[34]!==k||t[35]!==A?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[k,A]}),t[34]=k,t[35]=A,t[36]=j):j=t[36];let M;t[37]!==w||t[38]!==j?(M=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[w,j]}),t[37]=w,t[38]=j,t[39]=M):M=t[39];let N;t[40]!==a||t[41]!==o||t[42]!==h||t[43]!==s||t[44]!==r||t[45]!==c||t[46]!==n?(N=s&&!a?(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),n.loading]}):o?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-red-600 dark:text-red-400`,children:[(0,$.jsx)(`span`,{children:n.error}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1 text-xs`,onClick:()=>void c(),children:n.retry})]}):h.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.emptyState}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:h.map(e=>(0,$.jsx)($u,{share:e,t:n,language:r,onRevoked:()=>void c(),onExtended:()=>void c()},e.id))}),t[40]=a,t[41]=o,t[42]=h,t[43]=s,t[44]=r,t[45]=c,t[46]=n,t[47]=N):N=t[47];let P;t[48]!==y||t[49]!==c||t[50]!==f||t[51]!==n?(P=y>0&&f&&(0,$.jsx)(ed,{t:n,onCleaned:()=>void c()}),t[48]=y,t[49]=c,t[50]=f,t[51]=n,t[52]=P):P=t[52];let F;t[53]!==M||t[54]!==N||t[55]!==P?(F=(0,$.jsxs)(wn,{children:[M,N,P]}),t[53]=M,t[54]=N,t[55]=P,t[56]=F):F=t[56];let I;return t[57]!==F||t[58]!==x?(I=(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[x,F]}),t[57]=F,t[58]=x,t[59]=I):I=t[59],I}function Ku(e){return!e}function qu(e){return e.expired||e.revoked}function Ju(e){return!e.expired&&!e.revoked}function Yu(e){return!e.expired&&!e.revoked}var Xu={expanded:!0,path:``,isDirectory:!1,agentId:``,ttlMs:864e5,maxViews:null,description:``,directoryMode:`browse`,creating:!1,result:null,errorMsg:null,resultDialogOpen:!1,pickerOpen:!1};function Zu({t:e,onCreated:t}){let[n,r]=(0,Z.useReducer)(Gt,Xu),{expanded:i,path:a,isDirectory:o,agentId:s,ttlMs:c,maxViews:l,description:u,directoryMode:d,creating:f,result:p,errorMsg:m,resultDialogOpen:h,pickerOpen:g}=n,_=(0,Z.useCallback)(async()=>{if(a.trim()){r({type:`patch`,patch:{creating:!0,errorMsg:null,result:null}});try{r({type:`patch`,patch:{result:(await kt({path:a.trim(),ttlMs:c,maxViews:l,description:u.trim()||void 0,...s?{agentId:s}:{},...o?{kind:`directory`,directoryMode:d}:{}})).payload,resultDialogOpen:!0}}),t()}catch(e){r({type:`patch`,patch:{errorMsg:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{creating:!1}})}}},[a,o,s,c,l,u,d,t]),v=(0,Z.useCallback)(()=>{r({type:`patch`,patch:{path:``,isDirectory:!1,agentId:``,description:``,maxViews:null,ttlMs:864e5,directoryMode:`browse`,result:null,errorMsg:null}})},[]);return i?(0,$.jsxs)(wn,{children:[(0,$.jsx)(`h2`,{className:`mb-1 text-sm font-semibold text-fg`,children:e.createTitle}),(0,$.jsx)(`p`,{className:`mb-4 text-xs text-fg-muted`,children:e.createHint}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.pathLabel}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:J(`flex min-w-0 flex-1 items-center gap-2 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm`,a?`text-fg`:`text-fg-subtle`),children:a?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:o?`📁`:`📄`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:a,children:a})]}):(0,$.jsx)(`span`,{className:`truncate`,children:e.pathPlaceholder})}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,onClick:()=>r({type:`patch`,patch:{pickerOpen:!0}}),children:[(0,$.jsx)(on,{className:`size-4`}),a?e.pathBrowseChange:e.pathBrowse]})]})]}),o?(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.directoryModeLabel}),(0,$.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:d,onChange:e=>r({type:`patch`,patch:{directoryMode:e.target.value===`zip-only`?`zip-only`:`browse`}}),children:[(0,$.jsx)(`option`,{value:`browse`,children:e.directoryModeBrowse}),(0,$.jsx)(`option`,{value:`zip-only`,children:e.directoryModeZipOnly})]})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.ttlLabel}),(0,$.jsx)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:c,onChange:e=>r({type:`patch`,patch:{ttlMs:Number(e.target.value)}}),children:Vu.map(t=>(0,$.jsx)(`option`,{value:t.value,children:e.ttlOptions[t.key]},t.key))})]}),(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.maxViewsLabel}),(0,$.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:l??`unlimited`,onChange:e=>r({type:`patch`,patch:{maxViews:e.target.value===`unlimited`?null:Number(e.target.value)}}),children:[(0,$.jsx)(`option`,{value:`unlimited`,children:e.maxViewsUnlimited}),(0,$.jsx)(`option`,{value:`1`,children:`1`}),(0,$.jsx)(`option`,{value:`5`,children:`5`}),(0,$.jsx)(`option`,{value:`10`,children:`10`}),(0,$.jsx)(`option`,{value:`50`,children:`50`}),(0,$.jsx)(`option`,{value:`100`,children:`100`})]})]})]}),(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.descriptionLabel}),(0,$.jsx)(`input`,{type:`text`,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:outline-none focus:ring-2 focus:ring-accent`,placeholder:e.descriptionPlaceholder,value:u,onChange:e=>r({type:`patch`,patch:{description:e.target.value}})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,$.jsxs)(Y,{type:`button`,disabled:f||!a.trim(),onClick:()=>void _(),children:[f?(0,$.jsx)(q,{className:`size-4 animate-spin`}):(0,$.jsx)(Re,{className:`size-4`}),f?e.creating:e.createButton]}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,onClick:()=>{v(),r({type:`patch`,patch:{expanded:!1}})},children:e.cancel})]}),m&&(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m})]}),(0,$.jsx)(Se,{open:h,onOpenChange:e=>{r({type:`patch`,patch:{resultDialogOpen:e,...e?{}:{result:null}}})},result:p}),(0,$.jsx)(Nu,{open:g,onOpenChange:e=>r({type:`patch`,patch:{pickerOpen:e}}),initialPath:a||void 0,selectKind:`any`,onConfirm:e=>r({type:`patch`,patch:{path:e.path,isDirectory:e.isDirectory,agentId:e.agentId,directoryMode:`browse`}})})]}):(0,$.jsxs)(Y,{type:`button`,onClick:()=>r({type:`patch`,patch:{expanded:!0}}),className:`self-start`,children:[(0,$.jsx)(Re,{className:`size-4`}),e.createTitle]})}var Qu={revokeOpen:!1,revoking:!1,linksOpen:!1,urlCopied:!1,copyFailed:!1,extending:!1};function $u({share:e,t,language:n,onRevoked:r,onExtended:i}){let[a,o]=(0,Z.useReducer)(Gt,Qu),{revokeOpen:s,revoking:c,linksOpen:l,urlCopied:u,copyFailed:d,extending:f}=a,p=!e.expired&&!e.revoked,m=e.revoked?t.statusRevoked:e.expired?t.statusExpired:t.statusActive,h=e.revoked?`text-red-600 dark:text-red-400`:e.expired?`text-fg-subtle`:`text-emerald-600 dark:text-emerald-400`,g=(0,Z.useCallback)(async()=>{o({type:`patch`,patch:{revokeOpen:!1,revoking:!0}});try{await me(e.id),r()}catch{}finally{o({type:`patch`,patch:{revoking:!1}})}},[e.id,r]),_=(0,Z.useCallback)(async()=>{if(o({type:`patch`,patch:{linksOpen:!0,copyFailed:!1}}),!await K(e.shareUrl)){o({type:`patch`,patch:{copyFailed:!0}}),window.setTimeout(()=>o({type:`patch`,patch:{copyFailed:!1}}),2500);return}o({type:`patch`,patch:{urlCopied:!0}}),window.setTimeout(()=>o({type:`patch`,patch:{urlCopied:!1}}),2e3)},[e.shareUrl]),v=(0,Z.useCallback)(async()=>{o({type:`patch`,patch:{extending:!0}});try{await A(e.id,864e5),i()}catch{}finally{o({type:`patch`,patch:{extending:!1}})}},[e.id,i]),y=`share-links-${e.id}`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsxs)(`button`,{type:`button`,className:J(`flex min-w-0 flex-1 items-start gap-3 rounded-md text-left`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),"aria-expanded":l,"aria-controls":y,onClick:()=>o({type:`patch`,patch:{linksOpen:!l}}),children:[(0,$.jsx)(zt,{className:J(`mt-0.5 size-4 shrink-0 text-fg-muted transition-transform`,l?`rotate-0`:`-rotate-90`),"aria-hidden":!0}),(0,$.jsx)(on,{className:`mt-0.5 size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:e.fileName}),(0,$.jsx)(`span`,{className:J(`text-xs font-medium`,h),children:m})]}),(0,$.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.workspaceRelativePath}),(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,$.jsx)(`span`,{children:zu(e.fileSize)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(be,{className:`size-3`}),e.expired?n===`zh`?`已过期`:`expired`:Bu(e.expiresAt,n)]}),(0,$.jsxs)(`span`,{children:[t.views,`: `,e.downloadCount,e.maxViews!==null&&` ${t.viewsOf} ${e.maxViews}`]}),e.description&&(0,$.jsx)(`span`,{className:`italic text-fg-subtle`,children:e.description})]})]})]}),(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1`,title:t.copyUrl,onClick:()=>void _(),children:u?(0,$.jsx)(ae,{className:`size-3.5 text-emerald-500`}):(0,$.jsx)(D,{className:`size-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1`,onClick:()=>void v(),disabled:f,title:t.extend,children:f?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(be,{className:`size-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400`,onClick:()=>o({type:`patch`,patch:{revokeOpen:!0}}),disabled:c,children:c?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(Lt,{className:`size-3.5`})})]})})]}),p&&l?(0,$.jsxs)(`div`,{id:y,className:`mt-3 border-t border-edge-subtle pt-3 pl-7`,children:[(0,$.jsx)(W,{shareUrl:e.shareUrl,lanUrl:e.lanUrl,reachability:e.reachability,compact:!0}),d?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-red-600 dark:text-red-400`,children:t.copyFailed}):null,(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(ge,{reachability:e.reachability})})]}):null]}),(0,$.jsx)(Jt,{open:s,title:t.revokeConfirmTitle,description:t.revokeConfirmBody,confirmLabel:t.revokeConfirmLabel,cancelLabel:t.cancel,destructive:!0,onConfirm:()=>void g(),onCancel:()=>o({type:`patch`,patch:{revokeOpen:!1}})})]})}function ed({t:e,onCleaned:t}){let[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),o=(0,Z.useCallback)(async()=>{r(!1),a(!0);try{await ye(),t()}catch{}finally{a(!1)}},[t]);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>r(!0),className:`border-danger/40 px-2 py-1 text-xs text-danger hover:bg-danger/10`,children:[i?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(Lt,{className:`size-3.5`}),e.cleanExpired]})}),(0,$.jsx)(Jt,{open:n,title:e.cleanExpiredConfirmTitle,description:e.cleanExpiredConfirmBody,confirmLabel:e.cleanExpiredConfirmLabel,cancelLabel:e.cancel,destructive:!0,onConfirm:()=>void o(),onCancel:()=>r(!1)})]})}function td(e,t){return e==null?t:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function nd(e,t){return e===`PENDING_UPDATE`?t.pendingUpdate??t.generic:e===`UNINSTALLER_NOT_FOUND`?t.uninstallerNotFound??t.generic:e===`NOT_PACKAGED`?t.notPackaged??t.generic:t.generic}function rd(e,t){if(e.platform===`darwin`)return t.uninstallDescDarwin;if(e.platform===`win32`)return t.uninstallDescWin;if(e.platform===`linux`){if(e.linuxPackageKind===`appimage`)return t.uninstallDescLinuxAppImage;if(e.linuxPackageKind===`deb`){let n=e.linuxDebPackageName??`xopc`;return t.uninstallDescLinuxDeb.replace(/\{\{package\}\}/g,n)}return t.uninstallDescLinuxUnknown}return t.uninstallDescLinuxUnknown}var id={info:null,loadError:null,actionError:null,copiedField:null,clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``,uninstallDialogOpen:!1,removeUserDataOnUninstall:!1,busy:!1};function ad({api:e,messages:t,embedded:n=!0}){let[r,i]=(0,Z.useReducer)(Gt,id),{info:a,loadError:o,actionError:s,copiedField:c,clearDialogOpen:l,clearConfirmChecked:u,clearConfirmText:d,uninstallDialogOpen:f,removeUserDataOnUninstall:y,busy:b}=r,x=(0,Z.useCallback)(async()=>{if(e?.getUninstallInfo){i({type:`patch`,patch:{loadError:null}});try{i({type:`patch`,patch:{info:await e.getUninstallInfo()}})}catch(e){i({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}}},[e]);(0,Z.useEffect)(()=>{x()},[x]);let S=async(e,n)=>{if(await K(e)){i({type:`patch`,patch:{actionError:null,copiedField:n}}),window.setTimeout(()=>i({type:`patch`,patch:{copiedField:null}}),2e3);return}i({type:`patch`,patch:{actionError:t.copyFailed}})},C=async e=>{let t=window.electronAPI?.shell;if(!t)return;let n=await t.openPath(e);n.error&&i({type:`patch`,patch:{actionError:n.error}})},w=async()=>{if(e?.clearUserData){i({type:`patch`,patch:{busy:!0,actionError:null}});try{let n=await e.clearUserData();n.ok||i({type:`patch`,patch:{actionError:nd(n.error,t.errors)}})}catch(e){i({type:`patch`,patch:{actionError:e instanceof Error?e.message:t.errors.generic}})}finally{i({type:`patch`,patch:{busy:!1,clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``}})}}},T=async()=>{if(e?.uninstallApp){i({type:`patch`,patch:{busy:!0,actionError:null}});try{let n=await e.uninstallApp({removeUserData:y});n.ok||i({type:`patch`,patch:{actionError:nd(n.error,t.errors)}})}catch(e){i({type:`patch`,patch:{actionError:e instanceof Error?e.message:t.errors.generic}})}finally{i({type:`patch`,patch:{busy:!1,uninstallDialogOpen:!1}})}}};if(o)return(0,$.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o});if(!a)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading});let E=!a.packaged,O=b||a.pendingUpdate||E,k=!E&&a.uninstallMode!==`unsupported`,A=rd(a,t),j=u&&d.trim()===t.clearDataConfirmPhrase;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(wn,{children:[n?(0,$.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(oe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.title]}):null,s?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:s}):null,E?(0,$.jsxs)(`div`,{className:`mb-4 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-2.5`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.devOnlyTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:t.devOnlyBody})]}):null,a.pendingUpdate?(0,$.jsx)(`p`,{className:`mb-3 rounded-xl border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,children:t.pendingUpdateBlocked}):null,a.hasSeparateCliData&&a.cliDataPath?(0,$.jsxs)(`div`,{className:`mb-4 rounded-xl border border-amber-500/30 bg-amber-500/10 px-3 py-2.5`,children:[(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:t.cliDataWarning}),(0,$.jsxs)(`button`,{type:`button`,className:J(`mt-2 inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,X.press),onClick:()=>void C(a.cliDataPath),children:[(0,$.jsx)(it,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.openCliData]})]}):null,(0,$.jsxs)(`dl`,{className:`space-y-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-fg-muted`,children:t.appPath}),(0,$.jsxs)(`dd`,{className:`mt-1 flex items-start justify-between gap-2`,children:[(0,$.jsx)(`code`,{className:`break-all text-xs text-fg`,children:a.appPath}),(0,$.jsxs)(`button`,{type:`button`,className:J(`inline-flex shrink-0 items-center gap-1 rounded-lg border border-edge px-2 py-1 text-xs text-fg hover:bg-surface-hover`,X.press),onClick:()=>void S(a.appPath,`app`),children:[(0,$.jsx)(D,{className:`size-3`,"aria-hidden":!0}),c===`app`?t.copied:t.copyPath]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-fg-muted`,children:t.dataPath}),(0,$.jsxs)(`dd`,{className:`mt-1 flex items-start justify-between gap-2`,children:[(0,$.jsx)(`code`,{className:`break-all text-xs text-fg`,children:a.userDataPath}),(0,$.jsxs)(`button`,{type:`button`,className:J(`inline-flex shrink-0 items-center gap-1 rounded-lg border border-edge px-2 py-1 text-xs text-fg hover:bg-surface-hover`,X.press),onClick:()=>void S(a.userDataPath,`data`),children:[(0,$.jsx)(D,{className:`size-3`,"aria-hidden":!0}),c===`data`?t.copied:t.copyPath]})]}),(0,$.jsxs)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:[t.dataSize,`: `,td(a.userDataSizeBytes,t.dataSizeUnknown)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.clearData}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:t.clearDataDesc})]}),(0,$.jsx)(`button`,{type:`button`,disabled:O,className:J(`inline-flex shrink-0 items-center justify-center rounded-lg border border-danger/40 bg-danger px-3 py-1.5 text-sm font-medium text-white hover:bg-danger/90 disabled:opacity-50`,X.press),onClick:()=>{i({type:`patch`,patch:{clearConfirmChecked:!1,clearConfirmText:``,clearDialogOpen:!0}})},children:t.clearData})]}),k?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.uninstall}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:A})]}),(0,$.jsx)(`button`,{type:`button`,disabled:O,className:J(`inline-flex shrink-0 items-center justify-center rounded-lg border border-edge bg-surface-base px-3 py-1.5 text-sm font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,X.press),onClick:()=>{i({type:`patch`,patch:{removeUserDataOnUninstall:!1,uninstallDialogOpen:!0}})},children:t.uninstall})]}):null]})]}),(0,$.jsx)(g,{open:l,onOpenChange:e=>{e||i({type:`patch`,patch:{clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``}})},children:(0,$.jsxs)(p,{children:[(0,$.jsx)(m,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ft)}),(0,$.jsxs)(h,{className:J(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,_t,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsx)(v,{className:`text-base font-semibold text-fg`,children:t.clearDataConfirmTitle}),(0,$.jsx)(_,{className:`mt-2 text-sm text-fg-muted`,children:t.clearDataConfirmDesc}),(0,$.jsxs)(`label`,{className:`mt-4 flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:u,onChange:e=>i({type:`patch`,patch:{clearConfirmChecked:e.target.checked}})}),(0,$.jsx)(`span`,{children:t.clearDataConfirmCheckbox})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,$.jsx)(`label`,{className:`block text-sm font-medium text-fg`,htmlFor:`clear-data-confirm`,children:t.clearDataConfirmLabel}),(0,$.jsx)(`input`,{id:`clear-data-confirm`,type:`text`,autoComplete:`off`,spellCheck:!1,className:J(`w-full rounded-md border border-edge bg-surface-panel px-3 py-1.5 font-mono text-xs text-fg`,`placeholder:text-fg-subtle`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,`dark:border-edge`),placeholder:t.clearDataConfirmPhrase,value:d,onChange:e=>i({type:`patch`,patch:{clearConfirmText:e.target.value}})}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.clearDataConfirmHint})]}),(0,$.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:b,onClick:()=>{i({type:`patch`,patch:{clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``}})},children:t.cancel}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:b||!j,onClick:()=>void w(),children:t.confirmClear})]})]})]})}),k?(0,$.jsx)(g,{open:f,onOpenChange:e=>{e||i({type:`patch`,patch:{uninstallDialogOpen:!1}})},children:(0,$.jsxs)(p,{children:[(0,$.jsx)(m,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ft)}),(0,$.jsxs)(h,{className:J(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,_t,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsx)(v,{className:`text-base font-semibold text-fg`,children:t.uninstallConfirmTitle}),(0,$.jsx)(_,{className:`mt-2 text-sm text-fg-muted`,children:A}),(0,$.jsxs)(`label`,{className:`mt-4 flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:y,onChange:e=>i({type:`patch`,patch:{removeUserDataOnUninstall:e.target.checked}})}),(0,$.jsx)(`span`,{children:t.removeUserDataCheckbox})]}),y?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.clearDataConfirmDesc}):null,(0,$.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:b,onClick:()=>i({type:`patch`,patch:{uninstallDialogOpen:!1}}),children:t.cancel}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:b,onClick:()=>void T(),children:t.confirmUninstall})]})]})]})}):null]})}function od(){let e=(0,Q.c)(22),t=a(sd),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.systemSettings,i=r.appManagement,o=typeof window<`u`?window.electronAPI?.system:void 0;if(!Le()||!o){let t;e[2]===i.title?t=e[3]:(t=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i.title}),e[2]=i.title,e[3]=t);let n;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(n=Cn(),e[4]=n):n=e[4];let a;e[5]===r.desktopOnlyTitle?a=e[6]:(a=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:r.desktopOnlyTitle}),e[5]=r.desktopOnlyTitle,e[6]=a);let o;e[7]===r.desktopOnlyBody?o=e[8]:(o=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.desktopOnlyBody}),e[7]=r.desktopOnlyBody,e[8]=o);let s;e[9]!==a||e[10]!==o?(s=(0,$.jsxs)(`div`,{className:n,children:[a,o]}),e[9]=a,e[10]=o,e[11]=s):s=e[11];let c;return e[12]!==t||e[13]!==s?(c=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[t,s]}),e[12]=t,e[13]=s,e[14]=c):c=e[14],c}let c;e[15]===i.title?c=e[16]:(c=(0,$.jsx)(`div`,{children:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i.title})}),e[15]=i.title,e[16]=c);let l;e[17]===i?l=e[18]:(l=(0,$.jsx)(ad,{api:o,messages:i,embedded:!1}),e[17]=i,e[18]=l);let u;return e[19]!==c||e[20]!==l?(u=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[c,l]}),e[19]=c,e[20]=l,e[21]=u):u=e[21],u}function sd(e){return e.language}async function cd(){if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia)return!1;try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});for(let t of e.getTracks())t.stop();return!0}catch{return!1}}function ld(e,t,n){return e.outcome===`opened-settings`?n.openedSettings:e.status===`granted`&&t?e.outcome===`already-granted`?n.alreadyGranted:n.granted:t?e.status===`denied`?n.denied:n.prompted:n.rendererDenied}function ud(e,t){return e.outcome===`opened-settings`?t.openedSettings:e.status===`granted`?e.outcome===`already-granted`?t.alreadyGranted:t.granted:t.denied}function dd(e,t){return e.outcome===`opened-settings`?t.openedSettings:e.status===`granted`?e.outcome===`already-granted`?t.alreadyGranted:t.granted:e.status===`denied`?t.denied:t.prompted}function fd(e,t){return e.outcome===`opened-settings`?t.openedSettings:e.status===`granted`?e.outcome===`already-granted`?t.alreadyGranted:t.granted:e.status===`denied`?t.denied:t.prompted}var pd=new Set([`microphone`,`accessibility`,`notifications`,`screen`]);function md(e,t,n){return t===`granted`?!1:e===`accessibility`&&(n===`darwin`||n===`win32`||n===`linux`)||e===`screen`&&(n===`darwin`||n===`win32`)||pd.has(e)?t===`unknown`:!1}function hd(e,t,n){return e===`accessibility`?!1:e===`screen`&&n===`linux`?!0:pd.has(e)?t===`denied`:!0}var gd=[{key:`fullDisk`,pane:`fullDisk`,platforms:[`darwin`]},{key:`screen`,pane:`screen`},{key:`microphone`,pane:`microphone`},{key:`accessibility`,pane:`accessibility`},{key:`automation`,pane:`automation`},{key:`notifications`,pane:`notifications`},{key:`location`,pane:`location`}];function _d(e){return e===`linux`?gd:gd.filter(t=>!t.platforms||t.platforms.includes(e))}function vd(e,t){let n=s(e).systemSettings.status;return t===`granted`?{label:n.granted,className:`text-emerald-600 dark:text-emerald-400`}:t===`denied`?{label:n.denied,className:`text-amber-600 dark:text-amber-400`}:{label:n.unknown,className:`text-fg-muted`}}function yd(e,t,n){let r=s(e).systemSettings.permUnknown?.[t];return r?n===`darwin`&&r.darwin?r.darwin:n===`win32`&&r.win32?r.win32:n===`linux`&&r.linux?r.linux:null:null}var bd={behavior:null,perms:null,loadError:null,permFeedback:null,permBusy:!1,refreshing:!1};function xd(){let e=a(e=>e.language),t=s(e).systemSettings,[n,r]=(0,Z.useReducer)(Gt,bd),{behavior:i,perms:o,loadError:c,permFeedback:l,permBusy:u,refreshing:d}=n,f=typeof window<`u`?window.electronAPI?.system:void 0,p=(0,Z.useCallback)(async e=>{if(f){r({type:`patch`,patch:{loadError:null}});try{r({type:`patch`,patch:{behavior:await f.getBehavior(),perms:await f.getPermissions({probe:e?.showRefreshFeedback}),...e?.showRefreshFeedback?{permFeedback:t.refreshDone}:{}}})}catch(t){r({type:`patch`,patch:{loadError:t instanceof Error?t.message:String(t),...e?.showRefreshFeedback?{permFeedback:null}:{}}})}}},[f,t.refreshDone]),m=(0,Z.useCallback)(async()=>{if(!(d||u)){r({type:`patch`,patch:{refreshing:!0}});try{await p({showRefreshFeedback:!0})}finally{r({type:`patch`,patch:{refreshing:!1}})}}},[p,u,d]);if((0,Z.useEffect)(()=>{let e=new Set([t.refreshDone,t.openSettingsDone,t.openSettingsFailed,t.desktopNotify.testShown]);if(!l||!e.has(l))return;let n=window.setTimeout(()=>{r({type:`patch`,patch:{permFeedback:null}})},3e3);return()=>window.clearTimeout(n)},[l,t.openSettingsDone,t.openSettingsFailed,t.refreshDone,t.desktopNotify.testShown]),(0,Z.useEffect)(()=>{Le()&&f&&p()},[f,p]),!Le()||!f)return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,$.jsxs)(`div`,{className:Cn(),children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let h=async e=>{try{let{behavior:t}=await f.setBehavior(e);r({type:`patch`,patch:{behavior:t}}),(e.notifyEnabled!==void 0||e.notifySoundEnabled!==void 0)&&rn()}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}},g=async e=>{if(!e){await h({notifyEnabled:!1});return}r({type:`patch`,patch:{permBusy:!0,permFeedback:null}});try{let e=await Ne(t.desktopNotify.testTitle,t.desktopNotify.testBody);if(e===`unsupported`){r({type:`patch`,patch:{permFeedback:t.notificationsFeedback.unsupported}});return}if(e===`denied`){r({type:`patch`,patch:{permFeedback:t.desktopNotify.denied}});return}if(e===`default`){r({type:`patch`,patch:{permFeedback:t.notificationsFeedback.default}});return}await h({notifyEnabled:!0}),r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:t.desktopNotify.testShown}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}},_=async e=>{r({type:`patch`,patch:{permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{(await f.openPrivacy(e)).ok?r({type:`patch`,patch:{permFeedback:t.openSettingsDone}}):r({type:`patch`,patch:{permFeedback:t.openSettingsFailed}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}},v=async()=>{r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestMicrophone(),n=await cd();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:ld(e,n,t.permFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}},y=async()=>{if(f.requestAccessibility){r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestAccessibility();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:ud(e,t.accessibilityFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}}},b=async()=>{if(f.requestNotifications){r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestNotifications();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:dd(e,t.notificationsFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}}},x=async()=>{if(f.requestScreen){r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestScreen();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:fd(e,t.screenFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}}},S=i?i.platform===`win32`?t.permissionsHintWin:i.platform===`linux`?t.permissionsHintLinux:i.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,$.jsx)(`div`,{children:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),c?(0,$.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:c}):null,l?(0,$.jsx)(`p`,{className:J(`text-sm`,l===t.refreshDone||l===t.openSettingsDone||l===t.permFeedback.granted||l===t.permFeedback.alreadyGranted||l===t.accessibilityFeedback.granted||l===t.accessibilityFeedback.alreadyGranted||l===t.notificationsFeedback.granted||l===t.notificationsFeedback.alreadyGranted||l===t.screenFeedback.granted||l===t.screenFeedback.alreadyGranted||l===t.desktopNotify.testShown?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),role:`status`,"aria-live":`polite`,children:l}):null,(0,$.jsxs)(wn,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(B,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i,checked:!!i?.openAtLogin,onChange:e=>{h({openAtLogin:e.target.checked})}})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i,checked:!!i?.keepAwakePreferred,onChange:e=>{h({keepAwakePreferred:e.target.checked})}})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i||u,checked:!!i?.notifyEnabled,onChange:e=>{g(e.target.checked)}})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i,checked:!!i?.notifySoundEnabled,onChange:e=>{h({notifySoundEnabled:e.target.checked})}})]})]})]}),i&&o?(0,$.jsxs)(`section`,{className:Cn(),children:[(0,$.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:S}),i.platform===`darwin`&&!i.packaged?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:t.permissionsHintDevDarwin}):null]}),(0,$.jsxs)(`button`,{type:`button`,disabled:d||u,"aria-busy":d,className:J(`mt-2 inline-flex max-w-full items-center justify-center gap-1.5 rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover disabled:opacity-50 sm:mt-0`,X.press),onClick:()=>void m(),children:[(0,$.jsx)(Ee,{className:J(`size-3.5`,d&&`animate-spin`),strokeWidth:1.75,"aria-hidden":!0}),d?t.refreshing:t.refresh]})]}),(0,$.jsx)(`ul`,{className:`space-y-3`,children:_d(i.platform).map(({key:n,pane:r})=>{let a=vd(e,o[n]),s=t.perm[n],c=o[n]===`unknown`?yd(e,n,i.platform):null;return s?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:s.title}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:s.desc}),(0,$.jsx)(`p`,{className:`mt-1 text-xs font-medium ${a.className}`,children:a.label}),c?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:c}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[n===`notifications`&&md(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,X.press),onClick:()=>void b(),children:t.requestAccess}):null,n===`microphone`&&md(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,X.press),onClick:()=>void v(),children:t.requestAccess}):null,n===`accessibility`&&md(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,X.press),onClick:()=>void y(),children:t.requestAccess}):null,n===`screen`&&md(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,X.press),onClick:()=>void x(),children:t.requestAccess}):null,hd(n,o[n],i.platform)?(0,$.jsxs)(`button`,{type:`button`,className:J(`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,X.press),onClick:()=>void _(r),children:[t.openSettings,(0,$.jsx)(Me,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]}):null]})]},n):null})})]}):null]})}var Sd=/^([^:=]+)[:=](.*)$/;function Cd(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}))}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=Sd.exec(t);r&&n.push({key:r[1].trim(),value:r[2].trim()})}return n.length>0?n:null}function wd(e){let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return Object.keys(t).length>0?t:void 0}function Td(e){if(!e||typeof e!=`object`)return[{key:``,value:``}];let t=Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}));return t.length>0?t:[{key:``,value:``}]}function Ed(e){let t=e.trim();if(t)return t.split(/\s+/).filter(Boolean)}function Dd(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Od(e){if(e.transport===`stdio`){let t={command:e.command.trim()},n=Ed(e.argsText);return n?.length&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envJson.trim()&&(t.env=Dd(e.envJson)),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}let t={url:e.url.trim(),transport:e.transport},n=wd(e.headers);return n&&(t.headers=n),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}function kd(e,t){let n=typeof t.url==`string`&&t.url.trim().length>0,r=typeof t.transport==`string`?t.transport.trim().toLowerCase():``,i=n?r===`sse`?`sse`:`streamable-http`:`stdio`,a=t.headers&&typeof t.headers==`object`&&!Array.isArray(t.headers)?t.headers:void 0;return{clientKey:e,id:e,transport:i,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?t.args.map(String).join(` `):``,envJson:t.env&&typeof t.env==`object`?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:typeof t.workingDirectory==`string`?t.workingDirectory:``,url:typeof t.url==`string`?t.url:``,headers:Td(a),connectionTimeoutMs:typeof t.connectionTimeoutMs==`number`&&Number.isFinite(t.connectionTimeoutMs)?t.connectionTimeoutMs:void 0}}function Ad(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`stdio`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[{key:`Authorization`,value:``}],connectionTimeoutMs:void 0}}function jd(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=t&&typeof t==`object`?t:{},r=n.servers,i=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).flatMap(([e,t])=>!t||typeof t!=`object`?[]:[kd(e,t)]).sort((e,t)=>e.id.localeCompare(t.id)):[],a=typeof n.sessionIdleTtlMs==`number`?n.sessionIdleTtlMs:void 0;return{sessionIdleTtlMinutes:a==null?void 0:a===0?0:Math.round(a/6e4),servers:i}}function Md(e){return Od(e)}async function Nd(e){let t={};for(let n of e.servers){let e=n.id.trim();e&&(t[e]=Od(n))}let n={servers:t};e.sessionIdleTtlMinutes!=null&&Number.isFinite(e.sessionIdleTtlMinutes)&&(n.sessionIdleTtlMs=e.sessionIdleTtlMinutes===0?0:Math.round(e.sessionIdleTtlMinutes*6e4)),await S(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({mcp:n})}),mt()}function Pd(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){let e=n.trim();e&&t.push({name:e});continue}if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();if(!r)continue;let i=typeof e.shortName==`string`&&e.shortName.trim()?e.shortName.trim():void 0,a=typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0;t.push({name:r,shortName:i,description:a})}return t}async function Fd(e,t){let n=await S(l(`/api/mcp/servers/${encodeURIComponent(e)}/test`),{method:`POST`,body:t?JSON.stringify({server:t}):void 0});if(!n.payload)throw Error(n.error??`MCP test failed`);let r=Pd(n.payload.tools);return{serverId:n.payload.serverId??e,toolCount:typeof n.payload.toolCount==`number`?n.payload.toolCount:r.length,tools:r}}function Id(e){return e.connectionTimeoutMs==null||!Number.isFinite(e.connectionTimeoutMs)?``:String(Math.round(e.connectionTimeoutMs/1e3))}function Ld(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>600))return n*1e3}function Rd(e,t){return e.clientKey}function zd(e,t,n){let r=e.key.trim();if(r)return`key:${r}`;let i=e.value.trim();return i?`value:${i}`:`empty:${n.slice(0,t).filter(e=>!e.key.trim()&&!e.value.trim()).length}`}function Bd(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt)}function Vd({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,keyPlaceholder:o,valuePlaceholder:s,headers:c,onChange:l}){let u=(e,t)=>{l(c.map((n,r)=>r===e?{...n,...t}:n))},d=()=>{l([...c,{key:``,value:``}])},f=e=>{let t=c.filter((t,n)=>n!==e);l(t.length>0?t:[{key:``,value:``}])},p=async()=>{try{let e=await ce();if(!e){window.alert(a);return}let t=Cd(e);if(!t?.length){window.alert(a);return}l(t)}catch{window.alert(a)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,$.jsx)(`span`,{children:e}),t?(0,$.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void p(),children:[(0,$.jsx)(H,{className:`size-3.5`,"aria-hidden":!0}),i]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{className:J(Bd(),`min-w-0 flex-1 font-mono text-xs`),value:e.key,placeholder:o,onChange:e=>u(t,{key:e.target.value})}),(0,$.jsx)(`input`,{className:J(Bd(),`min-w-0 flex-[1.4] font-mono text-xs`),value:e.value,placeholder:s,onChange:e=>u(t,{value:e.target.value})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:c.length<=1&&!e.key&&!e.value,onClick:()=>f(t),"aria-label":r,children:(0,$.jsx)(Lt,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})})]},zd(e,t,c)))}),(0,$.jsxs)(`button`,{type:`button`,className:J(`self-start text-sm text-accent hover:underline`,X.press),onClick:d,children:[`+ `,n]})]})}var Hd=[`stdio`,`sse`,`streamable-http`];function Ud(e){let t=(0,Q.c)(11),{label:n,description:r,required:i,children:a}=e,o;t[0]===i?o=t[1]:(o=i?(0,$.jsx)(`span`,{className:`ml-0.5 text-danger`,children:`*`}):null,t[0]=i,t[1]=o);let s;t[2]!==n||t[3]!==o?(s=(0,$.jsxs)(`div`,{className:`text-sm font-medium text-fg`,children:[n,o]}),t[2]=n,t[3]=o,t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=r?(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}):null,t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==s||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[s,a,c]}),t[7]=a,t[8]=s,t[9]=c,t[10]=l):l=t[10],l}function Wd(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt)}function Gd(e){if(e.transport===`stdio`){let t=e.command.trim();if(!t)return``;let n=e.argsText.trim();return n?`${t} ${n}`:t}return e.url.trim()}function Kd(e){let t=(0,Q.c)(100),{row:n,expanded:r,onToggle:i,t:a,testing:o,toolState:s,onUpdate:c,onRemove:l,onTest:u,onViewTools:d}=e,f;t[0]!==n.id||t[1]!==a.cardUntitled?(f=n.id.trim()||a.cardUntitled,t[0]=n.id,t[1]=a.cardUntitled,t[2]=f):f=t[2];let p=f,m;t[3]===n?m=t[4]:(m=Gd(n),t[3]=n,t[4]=m);let h=m,g=a.transportLabels[n.transport],_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=J(`flex min-w-0 flex-1 items-start gap-2 rounded-lg text-left hover:opacity-90`,X.press),t[5]=_):_=t[5];let v=r?a.cardCollapseAria:a.cardExpandAria,y=r&&`rotate-180`,b;t[6]===y?b=t[7]:(b=J(`mt-0.5 size-4 shrink-0 text-fg-subtle transition-transform`,y),t[6]=y,t[7]=b);let x;t[8]===b?x=t[9]:(x=(0,$.jsx)(zt,{className:b,"aria-hidden":!0}),t[8]=b,t[9]=x);let S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(ne,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[10]=S):S=t[10];let C;t[11]===p?C=t[12]:(C=(0,$.jsx)(`span`,{className:`truncate font-medium text-fg`,children:p}),t[11]=p,t[12]=C);let w;t[13]===g?w=t[14]:(w=(0,$.jsx)(`span`,{className:`rounded-md border border-edge bg-surface-base px-1.5 py-0.5 text-[11px] text-fg-muted`,children:g}),t[13]=g,t[14]=w);let T;t[15]!==s.status||t[16]!==s.tools?(T=s.status===`ok`&&s.tools.length>0?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-base px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[(0,$.jsx)(nt,{className:`size-3`,"aria-hidden":!0}),s.tools.length]}):null,t[15]=s.status,t[16]=s.tools,t[17]=T):T=t[17];let E;t[18]!==w||t[19]!==T||t[20]!==C?(E=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[S,C,w,T]}),t[18]=w,t[19]=T,t[20]=C,t[21]=E):E=t[21];let D;t[22]!==r||t[23]!==h?(D=!r&&h?(0,$.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-subtle`,title:h,children:h}):null,t[22]=r,t[23]=h,t[24]=D):D=t[24];let O;t[25]!==r||t[26]!==s.message||t[27]!==s.status?(O=!r&&s.status===`error`?(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-red-600 dark:text-red-300`,title:s.message,children:s.message}):null,t[25]=r,t[26]=s.message,t[27]=s.status,t[28]=O):O=t[28];let k;t[29]!==E||t[30]!==D||t[31]!==O?(k=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[E,D,O]}),t[29]=E,t[30]=D,t[31]=O,t[32]=k):k=t[32];let A;t[33]!==r||t[34]!==i||t[35]!==k||t[36]!==v||t[37]!==x?(A=(0,$.jsxs)(`button`,{type:`button`,className:_,"aria-expanded":r,"aria-label":v,onClick:i,children:[x,k]}),t[33]=r,t[34]=i,t[35]=k,t[36]=v,t[37]=x,t[38]=A):A=t[38];let j;t[39]!==n.id||t[40]!==o?(j=!n.id.trim()||o,t[39]=n.id,t[40]=o,t[41]=j):j=t[41];let M;t[42]===u?M=t[43]:(M=e=>{e.stopPropagation(),u()},t[42]=u,t[43]=M);let N;t[44]===o?N=t[45]:(N=o?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Wt,{className:`size-4`,"aria-hidden":!0}),t[44]=o,t[45]=N);let P;t[46]!==a.testConnection||t[47]!==j||t[48]!==M||t[49]!==N?(P=(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-xs`,disabled:j,onClick:M,children:[N,a.testConnection]}),t[46]=a.testConnection,t[47]=j,t[48]=M,t[49]=N,t[50]=P):P=t[50];let F;t[51]===l?F=t[52]:(F=e=>{e.stopPropagation(),l()},t[51]=l,t[52]=F);let I;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(Lt,{className:`size-4`,"aria-hidden":!0}),t[53]=I):I=t[53];let L;t[54]!==a.removeServer||t[55]!==F?(L=(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-xs`,onClick:F,children:[I,a.removeServer]}),t[54]=a.removeServer,t[55]=F,t[56]=L):L=t[56];let R;t[57]!==P||t[58]!==L?(R=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[P,L]}),t[57]=P,t[58]=L,t[59]=R):R=t[59];let z;t[60]!==A||t[61]!==R?(z=(0,$.jsxs)(`div`,{className:`flex items-start gap-2 p-4`,children:[A,R]}),t[60]=A,t[61]=R,t[62]=z):z=t[62];let B;t[63]!==r||t[64]!==c||t[65]!==d||t[66]!==n||t[67]!==a.addHeader||t[68]!==a.argsHint||t[69]!==a.argsLabel||t[70]!==a.commandLabel||t[71]!==a.cwdLabel||t[72]!==a.envHint||t[73]!==a.envLabel||t[74]!==a.headerKeyPlaceholder||t[75]!==a.headerValuePlaceholder||t[76]!==a.headersLabel||t[77]!==a.optionalSuffix||t[78]!==a.pasteHeaders||t[79]!==a.pasteHeadersFailed||t[80]!==a.removeHeader||t[81]!==a.serverIdLabel||t[82]!==a.serverIdPlaceholder||t[83]!==a.timeoutHint||t[84]!==a.timeoutLabel||t[85]!==a.timeoutPlaceholder||t[86]!==a.toolsEmpty||t[87]!==a.toolsLoading||t[88]!==a.toolsTitle||t[89]!==a.transportLabel||t[90]!==a.transportLabels||t[91]!==a.urlLabel||t[92]!==a.viewAllTools||t[93]!==s.message||t[94]!==s.status||t[95]!==s.tools?(B=r?(0,$.jsxs)(`div`,{className:`border-t border-edge px-4 pb-4 pt-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsx)(Ud,{label:a.transportLabel,required:!0,children:(0,$.jsx)(`select`,{className:Wd(),value:n.transport,onChange:e=>c({transport:e.target.value}),children:Hd.map(e=>(0,$.jsx)(`option`,{value:e,children:a.transportLabels[e]},e))})}),(0,$.jsx)(Ud,{label:a.serverIdLabel,required:!0,children:(0,$.jsx)(`input`,{className:Wd(),value:n.id,placeholder:a.serverIdPlaceholder,onChange:e=>c({id:e.target.value})})}),n.transport===`stdio`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ud,{label:a.commandLabel,children:(0,$.jsx)(`input`,{className:Wd(),value:n.command,onChange:e=>c({command:e.target.value})})}),(0,$.jsx)(Ud,{label:a.argsLabel,description:a.argsHint,children:(0,$.jsx)(`input`,{className:Wd(),value:n.argsText,onChange:e=>c({argsText:e.target.value})})}),(0,$.jsx)(Ud,{label:a.cwdLabel,children:(0,$.jsx)(`input`,{className:Wd(),value:n.cwd,onChange:e=>c({cwd:e.target.value})})}),(0,$.jsx)(Ud,{label:a.envLabel,description:a.envHint,children:(0,$.jsx)(`textarea`,{className:J(Wd(),`min-h-[4rem] font-mono text-xs`),value:n.envJson,onChange:e=>c({envJson:e.target.value})})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`md:col-span-2`,children:(0,$.jsx)(Ud,{label:a.urlLabel,required:!0,children:(0,$.jsx)(`input`,{className:J(Wd(),`font-mono text-xs`),value:n.url,placeholder:`https://example.com/mcp`,onChange:e=>c({url:e.target.value})})})}),(0,$.jsx)(Vd,{label:a.headersLabel,optionalLabel:a.optionalSuffix,addLabel:a.addHeader,removeHeaderAria:a.removeHeader,pasteLabel:a.pasteHeaders,pasteFailed:a.pasteHeadersFailed,keyPlaceholder:a.headerKeyPlaceholder,valuePlaceholder:a.headerValuePlaceholder,headers:n.headers,onChange:e=>c({headers:e})})]}),(0,$.jsx)(Ud,{label:a.timeoutLabel,description:a.timeoutHint,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:600,className:Wd(),value:Id(n),placeholder:a.timeoutPlaceholder,onChange:e=>c({connectionTimeoutMs:Ld(e.target.value)})})})]}),s.status===`loading`?(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}),a.toolsLoading]}):null,s.status===`error`?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-xs text-red-600 dark:text-red-300`,children:s.message}):null,s.status===`ok`?(0,$.jsx)(`div`,{className:`mt-4 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,$.jsx)(nt,{className:`size-4 text-accent`,"aria-hidden":!0}),s.tools.length===0?a.toolsEmpty:a.toolsTitle.replace(`{{count}}`,String(s.tools.length))]}),s.tools.length>0?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:()=>d(s.tools),children:a.viewAllTools}):null]})}):null]}):null,t[63]=r,t[64]=c,t[65]=d,t[66]=n,t[67]=a.addHeader,t[68]=a.argsHint,t[69]=a.argsLabel,t[70]=a.commandLabel,t[71]=a.cwdLabel,t[72]=a.envHint,t[73]=a.envLabel,t[74]=a.headerKeyPlaceholder,t[75]=a.headerValuePlaceholder,t[76]=a.headersLabel,t[77]=a.optionalSuffix,t[78]=a.pasteHeaders,t[79]=a.pasteHeadersFailed,t[80]=a.removeHeader,t[81]=a.serverIdLabel,t[82]=a.serverIdPlaceholder,t[83]=a.timeoutHint,t[84]=a.timeoutLabel,t[85]=a.timeoutPlaceholder,t[86]=a.toolsEmpty,t[87]=a.toolsLoading,t[88]=a.toolsTitle,t[89]=a.transportLabel,t[90]=a.transportLabels,t[91]=a.urlLabel,t[92]=a.viewAllTools,t[93]=s.message,t[94]=s.status,t[95]=s.tools,t[96]=B):B=t[96];let V;return t[97]!==z||t[98]!==B?(V=(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel`,children:[z,B]}),t[97]=z,t[98]=B,t[99]=V):V=t[99],V}function qd(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function Jd(e,t,n){let r=t.trim().toLowerCase();if(!r)return!0;let i=e.shortName||qd(e.name,n);return[e.name,i,e.description].filter(Boolean).join(`
3
+ `).toLowerCase().includes(r)}function Yd(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function Xd(e){let t=(0,Q.c)(29),{tools:n,stripPrefix:r,searchPlaceholder:i,searchEmptyLabel:a}=e,[o,s]=(0,Z.useState)(``),c;if(t[0]!==o||t[1]!==r||t[2]!==n){let e;t[4]!==o||t[5]!==r?(e=e=>Jd(e,o,r),t[4]=o,t[5]=r,t[6]=e):e=t[6],c=n.filter(e),t[0]=o,t[1]=r,t[2]=n,t[3]=c}else c=t[3];let l=c,u;t[7]===o?u=t[8]:(u=o.trim(),t[7]=o,t[8]=u);let d=u.length>0,f;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(pe,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,"aria-hidden":!0}),t[9]=f):f=t[9];let p,m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=J(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-9 pr-3 text-sm text-fg`,`placeholder:text-fg-subtle`,lt),m=e=>s(e.target.value),t[10]=p,t[11]=m):(p=t[10],m=t[11]);let h;t[12]!==o||t[13]!==i?(h=(0,$.jsxs)(`div`,{className:`relative`,children:[f,(0,$.jsx)(`input`,{type:`search`,value:o,placeholder:i,"aria-label":i,className:p,onChange:m})]}),t[12]=o,t[13]=i,t[14]=h):h=t[14];let g;t[15]!==l.length||t[16]!==d||t[17]!==n.length?(g=d?(0,$.jsxs)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:[l.length,` / `,n.length]}):null,t[15]=l.length,t[16]=d,t[17]=n.length,t[18]=g):g=t[18];let _;t[19]!==h||t[20]!==g?(_=(0,$.jsxs)(`div`,{className:`border-b border-edge px-5 py-3`,children:[h,g]}),t[19]=h,t[20]=g,t[21]=_):_=t[21];let v;t[22]!==l||t[23]!==a||t[24]!==r?(v=(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:l.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:a}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:l.map((e,t)=>{let n=e.shortName||Yd(e.name,r)||e.name||`?`,i=e.name||`tool-${t}`;return(0,$.jsxs)(`li`,{className:`min-w-0 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`truncate font-mono text-sm font-medium text-fg`,title:e.name===n?n:e.name,children:n}),e.description?(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs leading-relaxed text-fg-muted`,title:e.description,children:e.description}):null]},i)})})}),t[22]=l,t[23]=a,t[24]=r,t[25]=v):v=t[25];let y;return t[26]!==_||t[27]!==v?(y=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[_,v]}),t[26]=_,t[27]=v,t[28]=y):y=t[28],y}function Zd(e){let t=(0,Q.c)(38),{open:n,onOpenChange:r,serverId:i,title:a,subtitle:o,searchPlaceholder:s,searchEmptyLabel:c,emptyLabel:l,closeLabel:u,tools:d,stripPrefix:f}=e,b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(m,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ft)}),t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x=J(`fixed left-1/2 top-1/2 flex max-h-[min(88vh,40rem)] w-[min(100%-2rem,min(92vw,36rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,_t,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`),t[1]=x):x=t[1];let S;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(nt,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[2]=S):S=t[2];let C;t[3]===a?C=t[4]:(C=(0,$.jsxs)(v,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[S,a]}),t[3]=a,t[4]=C);let w;t[5]!==i||t[6]!==o||t[7]!==d.length?(w=o.replace(`{{serverId}}`,i).replace(`{{count}}`,String(d.length)),t[5]=i,t[6]=o,t[7]=d.length,t[8]=w):w=t[8];let T;t[9]===w?T=t[10]:(T=(0,$.jsx)(_,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[9]=w,t[10]=T);let E;t[11]!==C||t[12]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[C,T]}),t[11]=C,t[12]=T,t[13]=E):E=t[13];let D;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(xt,{className:`size-4`,"aria-hidden":!0}),t[14]=D):D=t[14];let O;t[15]===u?O=t[16]:(O=(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 px-0`,"aria-label":u,children:D})}),t[15]=u,t[16]=O);let k;t[17]!==E||t[18]!==O?(k=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[E,O]}),t[17]=E,t[18]=O,t[19]=k):k=t[19];let A;t[20]!==l||t[21]!==n||t[22]!==c||t[23]!==s||t[24]!==i||t[25]!==f||t[26]!==d?(A=d.length>0?(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,$.jsx)(Xd,{tools:d,stripPrefix:f,searchPlaceholder:s,searchEmptyLabel:c},`${i}-${n?`open`:`closed`}`)}):(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l})}),t[20]=l,t[21]=n,t[22]=c,t[23]=s,t[24]=i,t[25]=f,t[26]=d,t[27]=A):A=t[27];let j;t[28]===u?j=t[29]:(j=(0,$.jsx)(`div`,{className:`flex justify-end border-t border-edge px-5 py-3`,children:(0,$.jsx)(y,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`secondary`,children:u})})}),t[28]=u,t[29]=j);let M;t[30]!==k||t[31]!==A||t[32]!==j?(M=(0,$.jsxs)(p,{children:[b,(0,$.jsxs)(h,{className:x,children:[k,A,j]})]}),t[30]=k,t[31]=A,t[32]=j,t[33]=M):M=t[33];let N;return t[34]!==r||t[35]!==n||t[36]!==M?(N=(0,$.jsx)(g,{open:n,onOpenChange:r,children:M}),t[34]=r,t[35]=n,t[36]=M,t[37]=N):N=t[37],N}function Qd(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,lt)}function $d(e,t){switch(t.type){case`reset`:return{form:null,baseline:null,expandedKeys:new Set};case`sync`:return{form:t.value,baseline:t.value,expandedKeys:new Set};case`set-form`:return e.form?{...e,form:t.updater(e.form)}:e;case`saved`:return{form:t.value,baseline:t.value,expandedKeys:new Set};case`toggle-expanded`:{let n=new Set(e.expandedKeys);return n.has(t.key)?n.delete(t.key):n.add(t.key),{...e,expandedKeys:n}}case`set-expanded`:return{...e,expandedKeys:t.keys}}}var ef={saving:!1,error:null,saveOk:!1,testingId:null,serverTools:{},toolsDialog:null};function tf(){let e=s(a(e=>e.language)),t=e.mcpSettings,n=!!x(e=>e.token),[r,i]=(0,Z.useReducer)($d,{form:null,baseline:null,expandedKeys:new Set}),o=r.form,c=r.baseline,l=r.expandedKeys,[u,d]=(0,Z.useReducer)(Gt,ef),{saving:f,error:p,saveOk:m,testingId:h,serverTools:g,toolsDialog:_}=u,v=(0,Z.useRef)(!1),{data:y,error:b,isLoading:S,mutate:C}=Ze(n),w=(0,Z.useMemo)(()=>y?.payload?.config===void 0?null:jd(y.payload.config),[y]);(0,Z.useEffect)(()=>{if(!n){i({type:`reset`}),v.current=!1;return}w===null||v.current||i({type:`sync`,value:w})},[n,w]);let T=!!(n&&S&&y===void 0&&!b),E=b instanceof Error?b.message:b?String(b):null,D=(0,Z.useMemo)(()=>!o||!c?!1:JSON.stringify(o)!==JSON.stringify(c),[o,c]),O=(0,Z.useCallback)(e=>{i({type:`toggle-expanded`,key:e})},[]),k=(0,Z.useCallback)((e,t)=>{v.current=!0,i({type:`set-form`,updater:n=>{let r=[...n.servers],i=r[e];return i?(r[e]={...i,...t},t.id&&t.id!==i.id&&i.id&&d({type:`patch`,patch:{serverTools:(()=>{let e={...g};return delete e[i.id],e})()}}),{...n,servers:r}):n}})},[]),A=(0,Z.useCallback)(()=>{v.current=!0,i({type:`set-form`,updater:e=>{let t=e.servers.length,n=Ad(`server-${t+1}`),r=Rd(n,t);return i({type:`set-expanded`,keys:new Set(l).add(r)}),{...e,servers:[...e.servers,n]}}})},[l]),j=(0,Z.useCallback)(e=>{v.current=!0,i({type:`set-form`,updater:t=>{let n=t.servers[e];if(n){let t=Rd(n,e),r=new Set(l);r.delete(t),i({type:`set-expanded`,keys:r}),n.id&&d({type:`patch`,patch:{serverTools:(()=>{let e={...g};return delete e[n.id],e})()}})}return{...t,servers:t.servers.filter((t,n)=>n!==e)}}})},[l]),M=(0,Z.useCallback)(async()=>{if(!(!o||f)){d({type:`patch`,patch:{saving:!0,error:null,saveOk:!1}});try{await Nd(o);let e=structuredClone(o);v.current=!1,i({type:`saved`,value:e}),d({type:`patch`,patch:{saveOk:!0}}),C()}catch(e){d({type:`patch`,patch:{error:e instanceof Error?e.message:String(e)}})}finally{d({type:`patch`,patch:{saving:!1}})}}},[o,C,f]),N=(0,Z.useCallback)(async(e,t)=>{if(e.trim()){d({type:`patch`,patch:{testingId:e,error:null,serverTools:{...g,[e]:{status:`loading`}}}});try{let n=t?Md(t):void 0,r=await Fd(e.trim(),n);d({type:`patch`,patch:{serverTools:{...g,[e]:{status:`ok`,tools:r.tools}}}})}catch(t){let n=t instanceof Error?t.message:String(t);d({type:`patch`,patch:{serverTools:{...g,[e]:{status:`error`,message:n}}}})}finally{d({type:`patch`,patch:{testingId:null}})}}},[]);return n?T||!o?(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle})]}),(E||p)&&(0,$.jsx)(`p`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-300`,children:p??E}),m&&(0,$.jsx)(`p`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg-muted`,children:t.saved}),(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:We,title:t.globalTitle,subtitle:t.globalHint}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.idleTtlLabel}),(0,$.jsx)(`input`,{type:`number`,min:0,className:Qd(),value:o.sessionIdleTtlMinutes??``,placeholder:t.idleTtlPlaceholder,onChange:e=>{v.current=!0;let t=e.target.value.trim();i({type:`set-form`,updater:e=>({...e,sessionIdleTtlMinutes:t===``?void 0:Number.parseInt(t,10)})})}}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.idleTtlHint})]})]}),(0,$.jsxs)(wn,{children:[(0,$.jsx)(Sn,{icon:ne,title:t.serversTitle,subtitle:t.serversHint}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[o.servers.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.serversEmpty}):null,o.servers.map((e,n)=>{let r=Rd(e,n),i=g[e.id]??{status:`idle`};return(0,$.jsx)(Kd,{row:e,expanded:l.has(r),onToggle:()=>O(r),t,testing:h===e.id,toolState:i,onUpdate:e=>k(n,e),onRemove:()=>j(n),onTest:()=>void N(e.id,e),onViewTools:t=>d({type:`patch`,patch:{toolsDialog:{serverId:e.id,tools:t}}})},r)}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`self-start`,onClick:A,children:[(0,$.jsx)(Re,{className:`size-4`,"aria-hidden":!0}),t.addServer]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,disabled:!D||f,onClick:()=>void M(),children:[f?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,f?t.saving:t.save]}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:!D||f,onClick:()=>{c&&(v.current=!1,i({type:`sync`,value:structuredClone(c)}),d({type:`patch`,patch:{saveOk:!1,error:null,serverTools:{}}}))},children:t.discard})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.disableHint}),_?(0,$.jsx)(Zd,{open:!0,onOpenChange:e=>{e||d({type:`patch`,patch:{toolsDialog:null}})},serverId:_.serverId,title:t.toolsDialogTitle,subtitle:t.toolsDialogSubtitle,searchPlaceholder:t.toolsDialogSearchPlaceholder,searchEmptyLabel:t.toolsDialogSearchEmpty,emptyLabel:t.toolsEmpty,closeLabel:t.toolsDialogClose,tools:_.tools,stripPrefix:`${_.serverId.trim()}__`}):null]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.token.description})]})}var nf=[`overview`,`appearance`,`system`,`app-management`,`agent-defaults`,`agent-browser`,`agent-mcp`,`credentials`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`tunnel`,`remote-access`,`shares`,`search`,`cron`,`goals`,`dreams`];function rf(){let e=(0,Q.c)(34),{section:t}=Zt(),n=a(af),r,i,o,c,l;if(e[0]!==n||e[1]!==t){l=Symbol.for(`react.early_return_sentinel`);bb0:{let a=s(n);if(t===`agent`||t===`agents`){let t;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Kt,{to:`/agents`,replace:!0}),e[7]=t):t=e[7],l=t;break bb0}if(!t||!nf.includes(t)){let t;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Kt,{to:`/settings/overview`,replace:!0}),e[8]=t):t=e[8],l=t;break bb0}if(t===`tunnel`){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Kt,{to:`/settings/remote-access`,replace:!0}),e[9]=t):t=e[9],l=t;break bb0}if(t===`providers`||t===`models`||t===`image-models`||t===`voice`||t===`search`){let n=`/settings/credentials${t===`providers`?``:`?tab=${t}`}`,r;e[10]===n?r=e[11]:(r=(0,$.jsx)(Kt,{to:n,replace:!0}),e[10]=n,e[11]=r),l=r;break bb0}let u=t;if(u===`overview`){let t;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(hr,{}),e[12]=t):t=e[12],l=t;break bb0}let d=a.settingsSections[u];if(u===`agent-defaults`){let t;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ln,{}),e[13]=t):t=e[13],l=t;break bb0}if(u===`agent-browser`){let t;e[14]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Nn,{}),e[14]=t):t=e[14],l=t;break bb0}if(u===`agent-mcp`){let t;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(tf,{}),e[15]=t):t=e[15],l=t;break bb0}if(u===`appearance`){let t;e[16]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(so,{}),e[16]=t):t=e[16],l=t;break bb0}if(u===`system`){let t;e[17]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(xd,{}),e[17]=t):t=e[17],l=t;break bb0}if(u===`app-management`){let t;e[18]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(od,{}),e[18]=t):t=e[18],l=t;break bb0}if(u===`credentials`){let t;e[19]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ga,{}),e[19]=t):t=e[19],l=t;break bb0}if(u===`gateway`){let t;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(xc,{}),e[20]=t):t=e[20],l=t;break bb0}if(u===`heartbeat`){let t;e[21]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Hc,{}),e[21]=t):t=e[21],l=t;break bb0}if(u===`tunnel`||u===`remote-access`){let t;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(gu,{}),e[22]=t):t=e[22],l=t;break bb0}if(u===`shares`){let t;e[23]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Hu,{}),e[23]=t):t=e[23],l=t;break bb0}if(u===`dreams`){let t;e[24]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(us,{}),e[24]=t):t=e[24],l=t;break bb0}if(u===`cron`){let t;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ss,{}),e[25]=t):t=e[25],l=t;break bb0}if(u===`goals`){let t;e[26]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ms,{}),e[26]=t):t=e[26],l=t;break bb0}o=`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,c=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:d}),r=`text-sm text-fg-muted`,i=a.settingsPage.comingSoon.replace(`{{title}}`,d)}e[0]=n,e[1]=t,e[2]=r,e[3]=i,e[4]=o,e[5]=c,e[6]=l}else r=e[2],i=e[3],o=e[4],c=e[5],l=e[6];if(l!==Symbol.for(`react.early_return_sentinel`))return l;let u;e[27]!==r||e[28]!==i?(u=(0,$.jsx)(`p`,{className:r,children:i}),e[27]=r,e[28]=i,e[29]=u):u=e[29];let d;return e[30]!==o||e[31]!==c||e[32]!==u?(d=(0,$.jsxs)(`div`,{className:o,children:[c,u]}),e[30]=o,e[31]=c,e[32]=u,e[33]=d):d=e[33],d}function af(e){return e.language}export{rf as SettingsPage};