@xopcai/xopc 0.0.196 → 0.0.197
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.
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-B1oxPli_.js → agent-avatar-dicebear-C5st7lt5.js} +1 -1
- package/dist/gateway/static/root/assets/agents-Baxfj44y.js +68 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-vmuJ_Z6i.js → app-management-settings-panel-S8LhoD6G.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BMlEoe-G.js → appearance-settings-D8Cd5vDP.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-0uCxKyE5.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BdE4Mati.js → archive-plugin-qL07mwnY.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-CTzaQcLV.js → attachment-load-CqSobpdi.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-XyDat125.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-B25zTNxl.js → binary-plugins-DBRPyLYE.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-Cdrf2awF.js → block-editor-6wG1LU7t.js} +46 -46
- package/dist/gateway/static/root/assets/{browser-settings-page-BMTmGMM6.js → browser-settings-page-CrYNMR4w.js} +4 -4
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BsmHy0ks.js → browser-workflow-inputs-Abil4puY.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-Wx9FrbK-.js → browser-workflows-page-BEu3E0et.js} +1 -1
- package/dist/gateway/static/root/assets/capabilities-settings-panel-CvMcDhGf.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-settings-panel-9T2KXAs1.js → capability-presets-settings-panel-CHJDY-Ih.js} +2 -2
- package/dist/gateway/static/root/assets/{channels-settings-DquD4BPQ.js → channels-settings-Ds9BJbcY.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-api-BC-4ftOM.js → connectors-api-CgWjgPSI.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-NUs-Zf7F.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-BycQlU8Q.js → cron-expression-ZdDBAoqA.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-BvYqHRz0.js → dependency-picker-BGeB1jpn.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-BOb8sEhN.js → desktop-pet-CsLR4pWB.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-DStgPb82.js → desktop-pet-settings-CCjT1bdo.js} +1 -1
- package/dist/gateway/static/root/assets/directory-picker-path-field-C-Te1QN3.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-p83TmZFd.js → extension-debug-page-CD73euAM.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DMQ3ovxA.js → extension-page-DAKjpNwd.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BcSKEU8s.js → extension-settings-page-BLSNdlgd.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-C-MmtCc7.js → gateway-config-api-CQrf0k3D.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-CuaRDWbg.js → gateway-settings-CvgH8IJI.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-Dm8TrfGa.js → heartbeat-settings-SPpnqbjl.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-BFoD6047.js +3 -0
- package/dist/gateway/static/root/assets/index-84ys9u-K.js +152 -0
- package/dist/gateway/static/root/assets/index-D-srnucP.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BQb06_jl.js → keyboard-shortcuts-settings-HMhxgOuD.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-D5uL2_Fd.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-DQtsxjGs.js → local-apps-page-DIWkFa3g.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-CDqIY72S.js → logs-page--6v8qq6y.js} +2 -2
- package/dist/gateway/static/root/assets/{management-settings-D7itDEHl.js → management-settings-DtEuS-kR.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-Db-KrpOQ.js → markdown-split-DvVBewS4.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-CHN66qs0.js → media-plugins-YVj7NVzD.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-CJtKZM0P.js → notes-page-BDzuL2I9.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-IdjuNXvH.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-HXweXqYE.js → page-tabs-7bSEWfSX.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-Dob6Oe2l.js → preview-open-alternatives-tgLbHgcV.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page--RnCc9bb.js → product-open-page-Bwx_CQht.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-DnJXSuM4.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DckZKlBI.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-CfbUHBUH.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-Bg1W2__k.js → runtime-tools-settings-panel-Fe05Nus6.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BI4rVt3u.js → schema-form-CFfyC4CB.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-BCfCh4My.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-Cbi4FvzO.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-C7rzhi7x.js → settings-form-section-gEnEYT_3.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-BS36Mjzz.js → settings-loading-skeleton-BRE_-7Da.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-BDSd7F9Y.js → settings-page-C1zxCpqB.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-CTMmZcwj.js → settings-page-layout-CRpXF_05.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BcHdpmFf.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BeCxg6eb.js → share-preview-page-DU8L68A5.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-CXL1EldF.js → shares-settings-kjTqH9yY.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-QAGpwzIM.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-CyfjEM4D.js → skills-page-lE1-YRdK.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-CnbJncdL.js → skills-page.utils-CYwFWTso.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-CAv0Yk0Y.js → system-settings-panel-CVDsiPKn.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-DsM13-cy.js +1 -0
- package/dist/gateway/static/root/assets/{typed-models-lib-DomX3Szl.js → typed-models-lib-DelyYgoc.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-BLc4gfG0.js → use-autosave-C50Mq5yQ.js} +1 -1
- package/dist/gateway/static/root/assets/{user-context-page-C2kQENTK.js → user-context-page-D-VEOt2A.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-BijmpPjb.js → voice-api-key-field-DYfgTe3Y.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-D7w2JFFq.js → work-discovery-overlay-DPbujsp3.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-D77opady.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BEmugHfL.js → workflow-run-setup-panel-DqIb1oBB.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-B9-PLmlX.js +5 -0
- package/dist/gateway/static/root/index.html +2 -2
- package/dist/package.js +1 -1
- package/dist/src/agent/embedded/execution-context.d.ts +2 -0
- package/dist/src/agent/embedded/execution-context.js +11 -0
- package/dist/src/agent/embedded/index.d.ts +3 -1
- package/dist/src/agent/embedded/index.js +5 -3
- package/dist/src/agent/embedded/run-turn.js +15 -9
- package/dist/src/agent/embedded/session-runner.d.ts +6 -11
- package/dist/src/agent/embedded/session-runner.js +25 -36
- package/dist/src/agent/embedded/transcript-runtime.d.ts +35 -0
- package/dist/src/agent/embedded/transcript-runtime.js +66 -0
- package/dist/src/agent/embedded/types.d.ts +3 -1
- package/dist/src/agent/service.d.ts +15 -0
- package/dist/src/agent/service.js +30 -0
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/gateway/agents-admin.js +1 -1
- package/dist/src/gateway/hono/routes/home.d.ts +1 -1
- package/dist/src/gateway/hono/routes/home.js +2 -2
- package/dist/src/gateway/hono/routes/index.js +2 -0
- package/dist/src/gateway/hono/routes/projects.js +12 -1
- package/dist/src/gateway/hono/routes/side-chats.d.ts +3 -0
- package/dist/src/gateway/hono/routes/side-chats.js +173 -0
- package/dist/src/gateway/service/agent-runner.d.ts +4 -0
- package/dist/src/gateway/service/agent-runner.js +15 -1
- package/dist/src/gateway/service/run-gateway-agent.js +1 -1
- package/dist/src/gateway/service.d.ts +4 -0
- package/dist/src/gateway/service.js +33 -7
- package/dist/src/gateway/side-chat/context-snapshot.d.ts +11 -0
- package/dist/src/gateway/side-chat/context-snapshot.js +108 -0
- package/dist/src/gateway/side-chat/index.d.ts +5 -0
- package/dist/src/gateway/side-chat/index.js +4 -0
- package/dist/src/gateway/side-chat/manager.d.ts +45 -0
- package/dist/src/gateway/side-chat/manager.js +198 -0
- package/dist/src/gateway/side-chat/run-service.d.ts +22 -0
- package/dist/src/gateway/side-chat/run-service.js +110 -0
- package/dist/src/gateway/side-chat/types.d.ts +61 -0
- package/dist/src/gateway/side-chat/types.js +1 -0
- package/dist/src/routing/session-key-utils.d.ts +0 -1
- package/dist/src/routing/session-key-utils.js +1 -6
- package/dist/src/routing/session-key.js +2 -2
- package/dist/src/tasks/home-query-service.d.ts +24 -0
- package/dist/src/tasks/home-query-service.js +284 -5
- package/dist/src/tasks/index.js +3 -3
- package/dist/src/tasks/project-operating-view-service.d.ts +2 -1
- package/dist/src/tasks/project-operating-view-service.js +27 -4
- package/package.json +2 -2
- package/dist/gateway/static/root/assets/agents-VoFNMGL3.js +0 -68
- package/dist/gateway/static/root/assets/apps-page-CsNB6mv_.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-CW1YWgiX.js +0 -6
- package/dist/gateway/static/root/assets/capabilities-settings-panel-C5l85__e.js +0 -7
- package/dist/gateway/static/root/assets/connectors-page-7zUxVHQg.js +0 -2
- package/dist/gateway/static/root/assets/directory-picker-path-field-DUUr9sq0.js +0 -1
- package/dist/gateway/static/root/assets/home-page-BYhDbUvI.js +0 -3
- package/dist/gateway/static/root/assets/index-BzPwnXho.js +0 -150
- package/dist/gateway/static/root/assets/index-CFFYvilx.css +0 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CHk4x0kR.js +0 -2
- package/dist/gateway/static/root/assets/notes-workbench-epHGeKd5.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-BxOD5-zj.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-D-9AhrH5.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CSUNXLKM.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-BxOUBMca.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DAvTIbgw.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-D1v-2Ci-.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BxwkKgVw.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-DGTVJs_N.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-XtoPgPUS.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-D_K2xOWq.js +0 -5
|
@@ -1,3 +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{f as i,t as a}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{t as o}from"./cn-JdwAhgNB.js";import{t as s}from"./messages-DQ5X6cXp.js";import{l as c,n as l}from"./locale-store-Bjvw7jtg.js";import{i as u}from"./vendor-swr-BIWyz7Rc.js";import{$o as d,Au as f,Bo as p,Ds as m,Du as h,Eu as g,Fo as _,Il as v,Io as y,
|
|
1
|
+
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{f as i,t as a}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{t as o}from"./cn-JdwAhgNB.js";import{t as s}from"./messages-DQ5X6cXp.js";import{l as c,n as l}from"./locale-store-Bjvw7jtg.js";import{i as u}from"./vendor-swr-BIWyz7Rc.js";import{$o as d,Au as f,Bo as p,Ds as m,Du as h,Eu as g,Fo as _,Il as v,Io as y,K as b,Kc as x,Lo as S,Mn as C,Os as w,Qo as T,Ro as E,Sc as D,Vo as O,Vs as k,Wl as A,Xo as j,Zo as M,_s as N,et as P,fc as F,is as I,ku as L,nc as R,ol as z,pu as B,rs as V,ws as H,xu as U,yc as W,zo as ee}from"./index-84ys9u-K.js";import{l as G}from"./vendor-codemirror-DRr7hFaD.js";import{t as te}from"./code-editor-dFzqyDXS.js";import{n as ne,r as re}from"./settings-page-layout-CRpXF_05.js";import{n as ie,r as ae}from"./settings-loading-skeleton-BRE_-7Da.js";import{n as K,t as oe}from"./settings-form-section-gEnEYT_3.js";import{a as se,c as ce,i as le,n as ue,o as de,r as fe,s as pe,t as me}from"./capability-presets-api-BoOzFotX.js";import{a as he,i as ge,o as q,s as J,t as _e}from"./typed-models-lib-DelyYgoc.js";var Y=n(),X=e(t(),1),Z=r(),Q=[`deep`,`fast`,`cheap`,`code`,`review`];function ve(e){return Q.includes(e)}function ye(e){let{rows:t,onChange:n,disabled:r,defaultRole:i,chat:a,labels:o}=e,s=(0,X.useRef)([]),c=(0,X.useRef)(0);for(;s.current.length<t.length;)s.current.push(`preset-model-row-${c.current++}`);s.current.length>t.length&&(s.current.length=t.length);let l=i??(t.some(e=>e.id===`deep`)?`deep`:t[0]?.id)??`deep`,u=t.findIndex(e=>e.id===l),d=u>=0?t[u]:void 0,f=t.map((e,t)=>({row:e,index:t})).filter(({index:e})=>e!==u),p=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},m=e=>{if(u>=0){p(u,{model:e});return}s.current.unshift(`preset-model-row-${c.current++}`),n([{id:l,model:e,fallbacks:[],description:ve(l)?o.roleDescriptions[l]:``},...t])},h=e=>{let n=t[e];n&&p(e,{fallbacks:[...n.fallbacks??[],``]})},g=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,p(e,{fallbacks:a})},_=(e,n)=>{let r=t[e];r&&p(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},v=e=>{s.current.splice(e,1),n(t.filter((t,n)=>n!==e))},y=e=>{if(!e)return;let r=e===`__custom__`?``:e;s.current.push(`preset-model-row-${c.current++}`),n([...t,{id:r,model:``,fallbacks:[],description:ve(r)?o.roleDescriptions[r]:``}])},x=[...Q.filter(e=>e!==l&&!t.some(t=>t.id===e)).map(e=>({value:e,label:o.roleNames[e]})),{value:`__custom__`,label:o.customRole}],S=(e,t)=>(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:o.fallbackModels}),(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>h(t),children:[(0,Z.jsx)(D,{className:`size-3.5`,"aria-hidden":!0}),o.addFallback]})]}),(e.fallbacks??[]).length>0?(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:(e.fallbacks??[]).map((e,n)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,Z.jsx)(b,{value:e,disabled:r,placeholder:o.fallbackPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>g(t,n,e)}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":o.removeFallback,onClick:()=>_(t,n),children:(0,Z.jsx)(k,{className:`size-4`,"aria-hidden":!0})})]},`${s.current[t]}-fallback-${n}`))}):(0,Z.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:o.fallbackEmptyHint})]}),(0,Z.jsxs)(`label`,{className:`grid gap-1.5 text-xs font-medium text-fg-muted`,children:[o.description,(0,Z.jsx)(`input`,{type:`text`,className:J(),value:e.description,disabled:r,placeholder:o.descriptionPlaceholder,onChange:e=>p(t,{description:e.target.value})})]})]});return(0,Z.jsxs)(`div`,{className:`grid gap-5`,children:[(0,Z.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:o.defaultTitle}),(0,Z.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:o.defaultBadge})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:o.defaultHint})]}),(0,Z.jsxs)(`span`,{className:`rounded-md bg-surface-panel px-2 py-1 font-mono text-[11px] text-fg-subtle`,children:[o.roleId,`: `,l]})]}),(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:o.primaryModel}),(0,Z.jsx)(b,{value:d?.model??``,disabled:r,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:m})]}),d?(0,Z.jsxs)(`details`,{className:`group mt-3`,children:[(0,Z.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-md text-xs font-medium text-fg-muted hover:text-fg`,children:[o.moreSettings,(0,Z.jsx)(B,{className:`size-3.5 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsx)(`div`,{className:`mt-3`,children:S(d,u)})]}):null]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:o.otherRolesTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:o.otherRolesHint})]}),f.length>0?(0,Z.jsx)(`div`,{className:`mt-3 grid gap-2`,children:f.map(({row:e,index:t})=>{let n=ve(e.id)?e.id:void 0;return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 p-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[minmax(8rem,12rem)_minmax(0,1fr)] md:items-end`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n?o.roleNames[n]:o.customRole}),n?(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:e.id}):(0,Z.jsxs)(`label`,{className:`mt-1 grid gap-1 text-[11px] text-fg-muted`,children:[o.roleId,(0,Z.jsx)(`input`,{type:`text`,className:J(),value:e.id,disabled:r,placeholder:o.roleIdPlaceholder,onChange:e=>p(t,{id:e.target.value.toLowerCase()})})]})]}),(0,Z.jsxs)(`label`,{className:`grid min-w-0 gap-1.5 text-xs font-medium text-fg-muted`,children:[o.primaryModel,(0,Z.jsx)(b,{value:e.model,disabled:r,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>p(t,{model:e})})]})]}),(0,Z.jsxs)(`details`,{className:`group mt-3`,children:[(0,Z.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 text-xs font-medium text-fg-muted hover:text-fg`,children:[o.moreSettings,(0,Z.jsx)(B,{className:`size-3.5 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[S(e,t),(0,Z.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>v(t),children:[(0,Z.jsx)(k,{className:`size-4`,"aria-hidden":!0}),o.removeRole]})})]})]})]},s.current[t])})}):(0,Z.jsx)(`p`,{className:`mt-3 rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:o.otherRolesEmpty}),(0,Z.jsx)(j,{value:``,options:x,placeholder:o.addTaskModel,allowEmpty:!1,disabled:r,triggerClassName:`mt-3 w-fit`,onChange:y})]})]})}var be=G();function xe(e){let t=e.split(`
|
|
2
2
|
`).map(e=>e.trim()).filter(Boolean);return t.length?t:void 0}function Se(e){return e?.join(`
|
|
3
|
-
`)??``}function Ce(e,t,n){return Object.entries(e).find(([e])=>e===t||e.startsWith(`${t}.`))?.[1]??n}function we(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function Te(e){if(!we(e)||[`models`,`tools`,`skills`,`workflows`,`boundaries`,`runtime`].some(t=>e[t]!==void 0&&!we(e[t]))||e.extends!==void 0&&!Array.isArray(e.extends)||e.locks!==void 0&&!Array.isArray(e.locks))return!1;let t=e.skills;if(t&&[`allow`,`deny`].some(e=>t[e]!==void 0&&!Array.isArray(t[e])))return!1;let n=e.workflows;if(n&&[`allowed`,`suggested`].some(e=>n[e]!==void 0&&!Array.isArray(n[e])))return!1;let r=e.boundaries;return!(r&&[`requiresConfirmation`,`forbidden`,`escalation`].some(e=>r[e]!==void 0&&!Array.isArray(r[e])))}function Ee(e){let{extendsIds:t,onExtendsChange:n,presetOptions:r,inherited:i,inheritedSources:a={},mcpServerIds:o,mcpTools:s,workflows:c,policy:l,onPolicyChange:u,rawPolicy:d,onRawPolicyChange:p,disabled:m,labels:h}=e,[_,v]=(0,X.useState)(t.length>1),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(``),[C,T]=(0,X.useState)(``),E=l.mcp??{},D=l.workflows??{},O=l.boundaries??{},A=l.runtime??{},j=l.locks??[],M=[...new Set([...o,...Object.keys(E.servers??{})])].sort(),P=new Map(r.map(e=>[e.id,e])),F=r.filter(e=>!t.includes(e.id)),I=(e,t)=>{u({...l,[e]:t})},L=(e,t)=>{let n={...E.servers??{}};t?n[e]={...n[e],mode:t}:delete n[e],I(`mcp`,De({...E,servers:Object.keys(n).length?n:void 0,tools:Object.keys(E.tools??{}).length?E.tools:void 0}))},R=(e,t)=>{let n={...E.tools??{}};t?n[e]=t:delete n[e],I(`mcp`,De({...E,servers:Object.keys(E.servers??{}).length?E.servers:void 0,tools:Object.keys(n).length?n:void 0}))};return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:h.inheritanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:h.inheritanceHint}),_?(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2`,children:[t.map((e,r)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-surface-panel/70 px-3 py-2.5 shadow-surface`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:P.get(e)?.name??e}),(0,Z.jsx)(`div`,{className:`font-mono text-[11px] text-fg-subtle`,children:e})]}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:m||r===0,"aria-label":h.inheritanceMoveUp,onClick:()=>{let e=[...t];[e[r-1],e[r]]=[e[r],e[r-1]],n(e)},children:(0,Z.jsx)(g,{className:`size-3.5`})}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:m||r===t.length-1,"aria-label":h.inheritanceMoveDown,onClick:()=>{let e=[...t];[e[r],e[r+1]]=[e[r+1],e[r]],n(e)},children:(0,Z.jsx)(f,{className:`size-3.5`})}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:m,"aria-label":h.inheritanceRemove,onClick:()=>n(t.filter(t=>t!==e)),children:(0,Z.jsx)(k,{className:`size-3.5`})})]},e)),F.length?(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[h.inheritanceAdd,(0,Z.jsxs)(N,{value:``,disabled:m,onChange:e=>e.target.value&&n([...t,e.target.value]),children:[(0,Z.jsx)(w,{value:``,children:h.inheritanceAvailable}),F.map(e=>(0,Z.jsx)(w,{value:e.id,children:e.name},e.id))]})]}):null]}):(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-end gap-2`,children:[(0,Z.jsxs)(`label`,{className:`min-w-64 flex-1 text-xs text-fg-muted`,children:[h.inheritanceAvailable,(0,Z.jsxs)(N,{value:t[0]??``,disabled:m,onChange:e=>n(e.target.value?[e.target.value]:[]),children:[(0,Z.jsx)(w,{value:``,children:h.inherit}),r.map(e=>(0,Z.jsx)(w,{value:e.id,children:e.name},e.id))]})]}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,disabled:m,onClick:()=>v(!0),children:h.compose})]}),r.length?null:(0,Z.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:h.inheritanceEmpty})]}),(0,Z.jsx)(Oe,{title:h.mcpTitle,hint:h.mcpHint,source:Ce(a,`tools.mcp`,h.inherit),children:M.length?(0,Z.jsx)(`div`,{className:`grid gap-2`,children:M.map(e=>(0,Z.jsxs)(`details`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,Z.jsxs)(`summary`,{className:`grid cursor-pointer items-center gap-2 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-xs text-fg`,children:e}),(0,Z.jsxs)(N,{value:E.servers?.[e]?.mode??``,disabled:m,onClick:e=>e.stopPropagation(),onChange:t=>L(e,t.target.value),children:[(0,Z.jsx)(w,{value:``,children:i?.tools?.mcp?.servers?.[e]?.mode?`${h.inherit} · ${i.tools.mcp.servers[e].mode}`:h.inherit}),(0,Z.jsx)(w,{value:`allow`,children:h.modeAllow}),(0,Z.jsx)(w,{value:`confirm`,children:h.modeConfirm}),(0,Z.jsx)(w,{value:`deny`,children:h.modeDeny})]})]}),(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3`,children:[E.servers?.[e]?(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:E.servers[e].scope===`readonly`,disabled:m,onChange:t=>{let n=E.servers?.[e];if(!n)return;let r={...E.servers??{},[e]:{...n,scope:t.target.checked?`readonly`:void 0}};I(`mcp`,De({...E,servers:r}))}}),h.readonlyOnly]}):null,s.filter(t=>t.serverId===e).map(e=>{let t=E.tools?.[e.id];return(0,Z.jsxs)(`div`,{className:`grid gap-2 rounded-lg bg-surface-base px-3 py-2 lg:grid-cols-[minmax(0,1fr)_11rem_8rem_8rem] lg:items-end`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.description})]}),(0,Z.jsxs)(N,{value:t?.mode??``,disabled:m,onChange:n=>{let r=n.target.value;R(e.id,r?{...t??{},mode:r}:void 0)},children:[(0,Z.jsx)(w,{value:``,children:h.inherit}),(0,Z.jsx)(w,{value:`allow`,children:h.modeAllow}),(0,Z.jsx)(w,{value:`confirm`,children:h.modeConfirm}),(0,Z.jsx)(w,{value:`deny`,children:h.modeDeny})]}),(0,Z.jsx)(ke,{label:h.maxCalls,value:t?.limits?.maxCallsPerTurn,disabled:!t||m,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,maxCallsPerTurn:n})}:void 0)}),(0,Z.jsx)(ke,{label:h.timeoutMinutes,value:t?.limits?.timeoutMs?t.limits.timeoutMs/6e4:void 0,disabled:!t||m,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,timeoutMs:n?n*6e4:void 0})}:void 0)})]},e.id)})]})]},e))}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h.noMcp})}),(0,Z.jsxs)(Oe,{title:h.workflowsTitle,hint:h.workflowsHint,source:Ce(a,`workflows`,h.inherit),children:[(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[h.defaultWorkflow,(0,Z.jsxs)(N,{value:D.default??``,disabled:m,onChange:e=>I(`workflows`,De({...D,default:e.target.value||void 0})),children:[(0,Z.jsx)(w,{value:``,children:i?.workflows?.default?`${h.inherit} · ${i.workflows.default}`:h.inherit}),c.map(e=>(0,Z.jsx)(w,{value:e.id,children:e.title},e.id))]})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-xs text-fg-muted`,children:h.allowedWorkflows}),(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:c.map(e=>{let t=D.allowed?.includes(e.id)??!1;return(0,Z.jsxs)(`label`,{className:`flex gap-2 rounded-lg bg-surface-panel/70 px-3 py-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:t,disabled:m,onChange:()=>{let n=new Set(D.allowed??[]);t?n.delete(e.id):n.add(e.id),I(`workflows`,De({...D,allowed:n.size?[...n].sort():void 0}))}}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:e.title}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:e.description})]})]},e.id)})})]})]}),(0,Z.jsx)(Oe,{title:h.runtimeTitle,hint:h.runtimeHint,source:Ce(a,`runtime`,h.inherit),children:(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Z.jsx)(ke,{label:h.timeoutMinutes,value:A.timeoutMs?A.timeoutMs/6e4:void 0,placeholder:i?.runtime?.timeoutMs?String(i.runtime.timeoutMs/6e4):void 0,disabled:m,onChange:e=>I(`runtime`,De({...A,timeoutMs:e?e*6e4:void 0}))}),(0,Z.jsx)(ke,{label:h.maxTurns,value:A.maxTurns,placeholder:i?.runtime?.maxTurns?String(i.runtime.maxTurns):void 0,disabled:m,onChange:e=>I(`runtime`,De({...A,maxTurns:e}))}),(0,Z.jsx)(ke,{label:h.maxFailures,value:A.maxToolFailuresPerTurn,placeholder:i?.runtime?.maxToolFailuresPerTurn?String(i.runtime.maxToolFailuresPerTurn):void 0,disabled:m,onChange:e=>I(`runtime`,De({...A,maxToolFailuresPerTurn:e}))})]})}),(0,Z.jsx)(Oe,{title:h.boundariesTitle,hint:h.boundariesHint,source:Ce(a,`boundaries`,h.inherit),children:(0,Z.jsx)(`div`,{className:`grid gap-3 lg:grid-cols-3`,children:[[`requiresConfirmation`,h.confirmRules],[`forbidden`,h.forbiddenRules],[`escalation`,h.escalationRules]].map(([e,t])=>(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[t,(0,Z.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg`,placeholder:h.onePerLine,value:Se(O[e]),disabled:m,onChange:t=>I(`boundaries`,De({...O,[e]:xe(t.target.value)}))})]},e))})}),(0,Z.jsxs)(`details`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-4`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer text-sm font-semibold text-fg`,children:h.governanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:h.governanceHint}),(0,Z.jsxs)(`label`,{className:`mt-3 block text-xs text-fg-muted`,children:[h.locksLabel,(0,Z.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 font-mono text-xs text-fg`,placeholder:h.onePerLine,value:Se(j),disabled:m,onChange:e=>I(`locks`,xe(e.target.value))})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:h.rawTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:h.rawHint}),y?(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`h-72 overflow-hidden rounded-lg border border-edge bg-surface-base`,children:(0,Z.jsx)(te,{initialContent:x,onChange:S,language:be,lineWrap:!0})}),C?(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-red-600 dark:text-red-400`,children:C}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(H,{type:`button`,onClick:()=>{try{let e=JSON.parse(x);if(!Te(e))throw Error(`invalid policy`);p(e),T(``),b(!1)}catch{T(h.rawInvalid)}},children:h.rawApply}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,onClick:()=>b(!1),children:h.cancel})]})]}):(0,Z.jsx)(H,{className:`mt-3`,type:`button`,variant:`secondary`,onClick:()=>{S(JSON.stringify(d,null,2)),T(``),b(!0)},children:h.rawOpen})]})]})}function De(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));return Object.keys(t).length?t:void 0}function Oe(e){let t=(0,Y.c)(17),n;t[0]===e.title?n=t[1]:(n=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:e.title}),t[0]=e.title,t[1]=n);let r;t[2]===e.hint?r=t[3]:(r=(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.hint}),t[2]=e.hint,t[3]=r);let i;t[4]!==n||t[5]!==r?(i=(0,Z.jsxs)(`div`,{children:[n,r]}),t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;t[7]===e.source?a=t[8]:(a=(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] text-fg-muted`,children:e.source}),t[7]=e.source,t[8]=a);let o;t[9]!==i||t[10]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[i,a]}),t[9]=i,t[10]=a,t[11]=o):o=t[11];let s;t[12]===e.children?s=t[13]:(s=(0,Z.jsx)(`div`,{className:`mt-3`,children:e.children}),t[12]=e.children,t[13]=s);let c;return t[14]!==o||t[15]!==s?(c=(0,Z.jsxs)(`section`,{children:[o,s]}),t[14]=o,t[15]=s,t[16]=c):c=t[16],c}function ke(e){let t=(0,Y.c)(10),n=e.value??``,r;t[0]===e?r=t[1]:(r=t=>e.onChange(t.target.value?Number(t.target.value):void 0),t[0]=e,t[1]=r);let i;t[2]!==e.disabled||t[3]!==e.placeholder||t[4]!==n||t[5]!==r?(i=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`mt-1 w-full rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg`,value:n,placeholder:e.placeholder,disabled:e.disabled,onChange:r}),t[2]=e.disabled,t[3]=e.placeholder,t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;return t[7]!==e.label||t[8]!==i?(a=(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[e.label,i]}),t[7]=e.label,t[8]=i,t[9]=a):a=t[9],a}function Ae(e){return e.name||e.directoryId}function je(e){let t=(0,Y.c)(56),{mode:n,selected:r,catalog:i,loading:a,disabled:s,onModeChange:c,onSelectedChange:l,labels:u}=e,d=n===`allowlist`||n===`denylist`,f;t[0]===i?f=t[1]:(f=i.map(Ae).filter(Boolean),t[0]=i,t[1]=f);let p=f,m;bb0:{if(n===`inherit`){m=u.inheritSummary;break bb0}if(n===`all`){m=u.allSummary;break bb0}if(n===`off`){m=u.offSummary;break bb0}let e=n===`allowlist`?u.allowSummary:u.denySummary,i;t[2]!==r.size||t[3]!==e?(i=e.replace(`{{count}}`,String(r.size)),t[2]=r.size,t[3]=e,t[4]=i):i=t[4],m=i}let h=m,g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(U,{className:`size-3.5`,"aria-hidden":!0}),t[5]=g):g=t[5];let _;t[6]===u.overrideSummaryTitle?_=t[7]:(_=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[g,u.overrideSummaryTitle]}),t[6]=u.overrideSummaryTitle,t[7]=_);let v;t[8]===h?v=t[9]:(v=(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:h}),t[8]=h,t[9]=v);let y;t[10]!==_||t[11]!==v?(y=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[_,v]}),t[10]=_,t[11]=v,t[12]=y):y=t[12];let b;t[13]===u.modeLabel?b=t[14]:(b=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.modeLabel}),t[13]=u.modeLabel,t[14]=b);let x;t[15]===u.modeInherit?x=t[16]:(x=[`inherit`,u.modeInherit],t[15]=u.modeInherit,t[16]=x);let S;t[17]===u.modeAll?S=t[18]:(S=[`all`,u.modeAll],t[17]=u.modeAll,t[18]=S);let C;t[19]===u.modeAllowlist?C=t[20]:(C=[`allowlist`,u.modeAllowlist],t[19]=u.modeAllowlist,t[20]=C);let w;t[21]===u.modeDenylist?w=t[22]:(w=[`denylist`,u.modeDenylist],t[21]=u.modeDenylist,t[22]=w);let T;t[23]===u.modeOff?T=t[24]:(T=[`off`,u.modeOff],t[23]=u.modeOff,t[24]=T);let E;t[25]!==w||t[26]!==T||t[27]!==x||t[28]!==S||t[29]!==C?(E=[x,S,C,w,T],t[25]=w,t[26]=T,t[27]=x,t[28]=S,t[29]=C,t[30]=E):E=t[30];let D=E,O;t[31]!==s||t[32]!==n||t[33]!==c||t[34]!==D?(O=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:D.map(e=>{let[t,r]=e;return(0,Z.jsx)(`button`,{type:`button`,className:o(`rounded-lg px-3 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,n===t?`bg-accent-soft text-accent-fg`:`bg-surface-panel text-fg hover:bg-surface-hover/55`),disabled:s,onClick:()=>c(t),children:r},t)})}),t[31]=s,t[32]=n,t[33]=c,t[34]=D,t[35]=O):O=t[35];let k;t[36]!==O||t[37]!==b?(k=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,O]}),t[36]=O,t[37]=b,t[38]=k):k=t[38];let A;t[39]!==i||t[40]!==p||t[41]!==s||t[42]!==u.emptyCatalog||t[43]!==u.noDescription||t[44]!==u.quickActionsLabel||t[45]!==u.quickClear||t[46]!==u.quickSelectAll||t[47]!==a||t[48]!==l||t[49]!==d||t[50]!==r?(A=d?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.quickActionsLabel}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:s||a||p.length===0,onClick:()=>l(new Set(p)),children:u.quickSelectAll}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:s||a||r.size===0,onClick:()=>l(new Set),children:u.quickClear})]})]}),a?(0,Z.jsx)(ae,{rows:3}):i.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.emptyCatalog}):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:i.map(e=>{let t=Ae(e),n=r.has(t),i=typeof e.description==`string`?e.description.trim():``,a=i||u.noDescription;return(0,Z.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl bg-surface-panel/70 px-3 shadow-surface`,children:(0,Z.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:n,disabled:s,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),l(e)},"aria-label":t}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,Z.jsx)(`p`,{className:o(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!i&&`italic text-fg-subtle`),title:a,children:a})]})]})},t)})})]}):null,t[39]=i,t[40]=p,t[41]=s,t[42]=u.emptyCatalog,t[43]=u.noDescription,t[44]=u.quickActionsLabel,t[45]=u.quickClear,t[46]=u.quickSelectAll,t[47]=a,t[48]=l,t[49]=d,t[50]=r,t[51]=A):A=t[51];let j;return t[52]!==k||t[53]!==A||t[54]!==y?(j=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[y,k,A]}),t[52]=k,t[53]=A,t[54]=y,t[55]=j):j=t[55],j}var Me=[`write_file`,`apply_patch`,`exec_command`,`execute_code`],Ne=[`exec_command`,`execute_code`,`automation`,`extensions`,`bundle-mcp`,`skill_manage`],$=[`send_message`,`send_media`,`text_to_speech`,`create_share`],Pe=[`read_file`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`,`web_extract`],Fe=[...Me,...$],Ie=[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`],Le=[`send_message`,`send_media`];function Re(e,t){let n={};for(let[r,i]of t)for(let t of r)e.has(t)&&(n[t]={mode:i});return n}function ze(e){let t=(0,Y.c)(100),{builtinToolIds:n,toolPolicies:r,onChange:i,disabled:a,getToolDescription:s,getGroupTitle:c,labels:l}=e,u;t[0]===n?u=t[1]:(u=new Set(n),t[0]=n,t[1]=u);let d=u,f;t[2]!==d||t[3]!==r?(f=Object.entries(r).filter(e=>{let[t]=e;return d.has(t)}).toSorted(Be),t[2]=d,t[3]=r,t[4]=f):f=t[4];let p=f,m;if(t[5]!==d||t[6]!==n){m=[];for(let e of pe){let t=e.toolIds.filter(e=>d.has(e));t.length>0&&m.push({key:e.key,ids:[...t]})}let e;t[8]===n?e=t[9]:(e=ce(n),t[8]=n,t[9]=e);let r=e;if(r.length>0){let e;t[10]===r?e=t[11]:(e={key:`misc`,ids:r},t[10]=r,t[11]=e),m.push(e)}t[5]=d,t[6]=n,t[7]=m}else m=t[7];let h=m,g;t[12]!==i||t[13]!==r?(g=(e,t)=>{let n={...r};t===`inherit`?delete n[e]:n[e]={...n[e],mode:t},i(n)},t[12]=i,t[13]=r,t[14]=g):g=t[14];let _=g,v;t[15]!==i||t[16]!==r?(v=(e,t)=>{let n=r[e];n&&i({...r,[e]:t(n)})},t[15]=i,t[16]=r,t[17]=v):v=t[17];let y=v,b;t[18]!==d||t[19]!==i?(b=e=>{i(Re(d,e))},t[18]=d,t[19]=i,t[20]=b):b=t[20];let x=b;if(n.length===0){let e;return t[21]===l.emptyBuiltin?e=t[22]:(e=(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.emptyBuiltin}),t[21]=l.emptyBuiltin,t[22]=e),e}let S;t[23]===l.quickActionsLabel?S=t[24]:(S=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.quickActionsLabel}),t[23]=l.quickActionsLabel,t[24]=S);let C;t[25]===i?C=t[26]:(C=()=>i({}),t[25]=i,t[26]=C);let w;t[27]!==a||t[28]!==l.quickClearOverrides||t[29]!==C?(w=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:C,children:l.quickClearOverrides}),t[27]=a,t[28]=l.quickClearOverrides,t[29]=C,t[30]=w):w=t[30];let T;t[31]===x?T=t[32]:(T=()=>x([[Me,`deny`]]),t[31]=x,t[32]=T);let E;t[33]!==a||t[34]!==l.quickReadOnlyWorkspace||t[35]!==T?(E=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:T,children:l.quickReadOnlyWorkspace}),t[33]=a,t[34]=l.quickReadOnlyWorkspace,t[35]=T,t[36]=E):E=t[36];let D;t[37]===x?D=t[38]:(D=()=>x([[Ne,`deny`]]),t[37]=x,t[38]=D);let O;t[39]!==a||t[40]!==l.quickHighRiskOff||t[41]!==D?(O=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:D,children:l.quickHighRiskOff}),t[39]=a,t[40]=l.quickHighRiskOff,t[41]=D,t[42]=O):O=t[42];let k;t[43]===x?k=t[44]:(k=()=>x([[$,`deny`]]),t[43]=x,t[44]=k);let A;t[45]!==a||t[46]!==l.quickNoOutbound||t[47]!==k?(A=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:k,children:l.quickNoOutbound}),t[45]=a,t[46]=l.quickNoOutbound,t[47]=k,t[48]=A):A=t[48];let j;t[49]===x?j=t[50]:(j=()=>x([[Pe,`allow`],[Fe,`deny`]]),t[49]=x,t[50]=j);let M;t[51]!==a||t[52]!==l.quickResearchMode||t[53]!==j?(M=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:j,children:l.quickResearchMode}),t[51]=a,t[52]=l.quickResearchMode,t[53]=j,t[54]=M):M=t[54];let N;t[55]===x?N=t[56]:(N=()=>x([[Ie,`allow`],[Le,`deny`]]),t[55]=x,t[56]=N);let P;t[57]!==a||t[58]!==l.quickCodingMode||t[59]!==N?(P=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:N,children:l.quickCodingMode}),t[57]=a,t[58]=l.quickCodingMode,t[59]=N,t[60]=P):P=t[60];let F;t[61]!==O||t[62]!==A||t[63]!==M||t[64]!==P||t[65]!==w||t[66]!==E?(F=(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[w,E,O,A,M,P]}),t[61]=O,t[62]=A,t[63]=M,t[64]=P,t[65]=w,t[66]=E,t[67]=F):F=t[67];let I;t[68]!==F||t[69]!==S?(I=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[S,F]}),t[68]=F,t[69]=S,t[70]=I):I=t[70];let L;t[71]===l.overrideSummaryTitle?L=t[72]:(L=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:l.overrideSummaryTitle}),t[71]=l.overrideSummaryTitle,t[72]=L);let R;t[73]!==l.modeAllow||t[74]!==l.modeConfirm||t[75]!==l.modeDeny||t[76]!==l.noOverrides||t[77]!==p?(R=p.length>0?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:p.map(e=>{let[t,n]=e;return(0,Z.jsxs)(`span`,{className:o(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,n.mode===`deny`&&`border-red-500/25 bg-red-500/10 text-red-700 dark:text-red-300`,n.mode===`confirm`&&`border-amber-500/25 bg-amber-500/10 text-amber-700 dark:text-amber-300`,n.mode===`allow`&&`border-accent/25 bg-accent/10 text-accent`),children:[t,(0,Z.jsx)(`span`,{className:`font-sans opacity-80`,children:n.mode===`allow`?l.modeAllow:n.mode===`confirm`?l.modeConfirm:l.modeDeny})]},t)})}):(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:l.noOverrides}),t[73]=l.modeAllow,t[74]=l.modeConfirm,t[75]=l.modeDeny,t[76]=l.noOverrides,t[77]=p,t[78]=R):R=t[78];let z;t[79]!==L||t[80]!==R?(z=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[L,R]}),t[79]=L,t[80]=R,t[81]=z):z=t[81];let B;t[82]!==a||t[83]!==c||t[84]!==s||t[85]!==h||t[86]!==l.inheritedMode||t[87]!==l.maxCallsLabel||t[88]!==l.modeAllow||t[89]!==l.modeConfirm||t[90]!==l.modeDeny||t[91]!==l.timeoutLabel||t[92]!==_||t[93]!==r||t[94]!==y?(B=(0,Z.jsx)(`div`,{className:`flex flex-col gap-5`,children:h.map(e=>{let{key:t,ids:n}=e;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:c(t)}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=s(e),n=r[e],i=n?n.mode:`inherit`;return(0,Z.jsxs)(`li`,{className:o(`rounded-xl px-3 py-2.5 shadow-surface transition-colors`,i===`inherit`?`bg-surface-panel/50`:`bg-surface-panel`),children:[(0,Z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-xs font-medium text-fg`,children:e}),t?(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:t}):null]}),(0,Z.jsx)(`div`,{className:`inline-flex w-fit rounded-lg border border-edge-subtle bg-surface-base p-0.5`,children:[`inherit`,`allow`,`confirm`,`deny`].map(t=>(0,Z.jsx)(`button`,{type:`button`,className:o(`rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,i===t?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:text-fg`),disabled:a,onClick:()=>_(e,t),children:t===`inherit`?l.inheritedMode:t===`allow`?l.modeAllow:t===`confirm`?l.modeConfirm:l.modeDeny},t))})]}),n?(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3 sm:grid-cols-2 dark:border-edge`,children:[(0,Z.jsx)(He,{label:l.maxCallsLabel,value:n.limits?.maxCallsPerTurn,disabled:a,onChange:t=>y(e,e=>Ve(e,`maxCallsPerTurn`,t))}),(0,Z.jsx)(He,{label:l.timeoutLabel,value:n.limits?.timeoutMs,disabled:a,onChange:t=>y(e,e=>Ve(e,`timeoutMs`,t))})]}):null]},e)})})]},t)})}),t[82]=a,t[83]=c,t[84]=s,t[85]=h,t[86]=l.inheritedMode,t[87]=l.maxCallsLabel,t[88]=l.modeAllow,t[89]=l.modeConfirm,t[90]=l.modeDeny,t[91]=l.timeoutLabel,t[92]=_,t[93]=r,t[94]=y,t[95]=B):B=t[95];let V;return t[96]!==I||t[97]!==z||t[98]!==B?(V=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[I,z,B]}),t[96]=I,t[97]=z,t[98]=B,t[99]=V):V=t[99],V}function Be(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function Ve(e,t,n){let r={...e.limits};if(n===void 0?delete r[t]:r[t]=n,Object.keys(r).length===0){let{limits:t,...n}=e;return n}return{...e,limits:r}}function He(e){let t=(0,Y.c)(9),n=e.value??``,r;t[0]===e?r=t[1]:(r=t=>{let n=t.target.value.trim();e.onChange(n?Number(n):void 0)},t[0]=e,t[1]=r);let i;t[2]!==e.disabled||t[3]!==n||t[4]!==r?(i=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:border-edge-strong focus:outline-none`,value:n,disabled:e.disabled,onChange:r}),t[2]=e.disabled,t[3]=n,t[4]=r,t[5]=i):i=t[5];let a;return t[6]!==e.label||t[7]!==i?(a=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[e.label,i]}),t[6]=e.label,t[7]=i,t[8]=a):a=t[8],a}var Ue=[`blank`,`safe-coder`,`read-only`,`low-cost`],We=[{id:`overview`,icon:j},{id:`models`,icon:z},{id:`tools`,icon:C},{id:`skills`,icon:W},{id:`advanced`,icon:R},{id:`impact`,icon:v}];function Ge(e){return ge(Object.entries(e?.models?.roles??{}).map(([e,t])=>({id:e,model:t.model,fallbacks:t.fallbacks??[],description:t.description})))}function Ke(e){return structuredClone(e?.tools?.builtin??{})}function qe(e){let t=e?.skills;if(!t)return new Set;let n=t.mode===`denylist`?t.deny:t.allow;return new Set(n??[])}function Je(){return{primary:``,fallbacks:[],timeoutMs:``,autoProviderFallback:``}}function Ye(e){return{primary:e?.primary??``,fallbacks:[...e?.fallbacks??[]],timeoutMs:e?.timeoutMs?String(e.timeoutMs):``,autoProviderFallback:e?.autoProviderFallback===void 0?``:e.autoProviderFallback?`true`:`false`}}function Xe(){return{imageModel:Je(),imageGenerationModel:Je(),allowFallbacks:``,maxCostTier:``}}function Ze(e){return{imageModel:Ye(e?.models?.imageModel),imageGenerationModel:Ye(e?.models?.imageGenerationModel),allowFallbacks:e?.models?.policy?.allowFallbacks===void 0?``:e.models.policy.allowFallbacks?`true`:`false`,maxCostTier:e?.models?.policy?.maxCostTier??``}}function Qe(e){return{mcp:structuredClone(e?.tools?.mcp),workflows:structuredClone(e?.workflows),boundaries:structuredClone(e?.boundaries),runtime:structuredClone(e?.runtime),locks:structuredClone(e?.locks)}}function $e(e){return{id:e?.id??``,name:e?.name??``,description:e?.description??``,modelRows:Ge(e),modelAdvanced:Ze(e),toolPolicies:Ke(e),skillMode:e?.skills?.mode??`inherit`,skillPick:qe(e),extendsIds:[...e?.extends??[]],advancedPolicy:Qe(e)}}function et(e,t){let n={id:e.id,name:e.name,version:1,usage:[],inherited:{},inheritedSources:{},...t};return{...e,modelRows:Ge(n),modelAdvanced:Ze(n),toolPolicies:Ke(n),skillMode:n.skills?.mode??`inherit`,skillPick:qe(n),extendsIds:[...n.extends??[]],advancedPolicy:Qe(n)}}function tt(e){let t=e.primary.trim();if(!t)return;let n=e.fallbacks.map(e=>e.trim()).filter(Boolean),r=e.timeoutMs.trim()?Number(e.timeoutMs):void 0,i=e.autoProviderFallback===``?void 0:e.autoProviderFallback===`true`;return{primary:t,...n.length>0?{fallbacks:n}:{},...r?{timeoutMs:r}:{},...i===void 0?{}:{autoProviderFallback:i}}}function nt(e,t){let n=_e(e.modelRows),r=tt(e.modelAdvanced.imageModel),i=tt(e.modelAdvanced.imageGenerationModel),a=e.modelAdvanced.allowFallbacks||e.modelAdvanced.maxCostTier?{...e.modelAdvanced.allowFallbacks?{allowFallbacks:e.modelAdvanced.allowFallbacks===`true`}:{},...e.modelAdvanced.maxCostTier?{maxCostTier:e.modelAdvanced.maxCostTier}:{}}:void 0,o={...t?.models?.defaultRole?{defaultRole:t.models.defaultRole}:{},...n?.roles?{roles:n.roles}:{},...r?{imageModel:r}:{},...i?{imageGenerationModel:i}:{},...a?{policy:a}:{}};return Object.keys(o).length>0?o:null}function rt(e){let t=Object.fromEntries(Object.entries(e.toolPolicies).toSorted(([e],[t])=>e.localeCompare(t))),n=e.advancedPolicy.mcp;return Object.keys(t).length>0||n?{builtin:t,...n?{mcp:n}:{}}:null}function it(e){return Object.fromEntries(Object.entries(e??{}).toSorted(([e],[t])=>e.localeCompare(t)))}function at(e){if(e.skillMode===`inherit`)return null;let t=[...e.skillPick].toSorted((e,t)=>e.localeCompare(t));return e.skillMode===`allowlist`?{mode:`allowlist`,allow:t}:e.skillMode===`denylist`?{mode:`denylist`,deny:t}:{mode:e.skillMode}}function ot(e,t){return{id:e.id.trim(),name:e.name.trim(),description:e.description.trim(),models:nt(e,t),tools:{builtin:it(e.toolPolicies),mcp:e.advancedPolicy.mcp},skills:at(e),extends:[...e.extendsIds].toSorted(),workflows:e.advancedPolicy.workflows,boundaries:e.advancedPolicy.boundaries,runtime:e.advancedPolicy.runtime,locks:e.advancedPolicy.locks}}function st(e){return e?{id:e.id,name:e.name,description:e.description??``,models:e.models??null,tools:{builtin:it(e.tools?.builtin),mcp:e.tools?.mcp},skills:e.skills??null,extends:[...e.extends??[]].toSorted(),workflows:e.workflows,boundaries:e.boundaries,runtime:e.runtime,locks:e.locks}:null}function ct(e,t){return[e.models?.roles?t.summaryModels.replace(`{{count}}`,String(Object.keys(e.models.roles).length)):``,e.tools?.builtin?t.summaryTools.replace(`{{count}}`,String(Object.keys(e.tools.builtin).length)):``,e.skills?t.summarySkills.replace(`{{mode}}`,t.skillModeLabels[e.skills.mode]):``].filter(Boolean).join(` · `)||t.summaryEmpty}function lt(e){return e===void 0?`—`:typeof e==`string`?e:JSON.stringify(e)}function ut(){return{modelAdvanced:Xe(),extendsIds:[],advancedPolicy:{}}}function dt(e,t){return{extends:[...e.extendsIds],models:nt(e,t)??void 0,tools:rt(e)??void 0,skills:at(e)??void 0,workflows:e.advancedPolicy.workflows,boundaries:e.advancedPolicy.boundaries,runtime:e.advancedPolicy.runtime,locks:e.advancedPolicy.locks}}function ft(e,t){return e===`safe-coder`?{id:`safe-coder`,name:t.starters[`safe-coder`].title,description:t.starters[`safe-coder`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`code`,model:``,fallbacks:[],description:t.modelRoleDescriptions.code},{id:`review`,model:``,fallbacks:[],description:t.modelRoleDescriptions.review}],toolPolicies:{exec_command:{mode:`deny`},send_message:{mode:`deny`},send_media:{mode:`deny`}},skillMode:`allowlist`,skillPick:new Set([`diagnose`,`tdd`]),...ut()}:e===`read-only`?{id:`read-only-research`,name:t.starters[`read-only`].title,description:t.starters[`read-only`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`fast`,model:``,fallbacks:[],description:t.modelRoleDescriptions.fast}],toolPolicies:{write_file:{mode:`deny`},apply_patch:{mode:`deny`},exec_command:{mode:`deny`},send_message:{mode:`deny`},send_media:{mode:`deny`}},skillMode:`all`,skillPick:new Set,...ut()}:e===`low-cost`?{id:`low-cost-assistant`,name:t.starters[`low-cost`].title,description:t.starters[`low-cost`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`fast`,model:``,fallbacks:[],description:t.modelRoleDescriptions.fast},{id:`cheap`,model:``,fallbacks:[],description:t.modelRoleDescriptions.cheap}],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...ut()}:{id:``,name:``,description:``,modelRows:[],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...ut()}}function pt(){let e=s(l(e=>e.language)),t=e.capabilityPresetsSettings,n=(0,Z.jsx)(H,{asChild:!0,type:`button`,variant:`secondary`,children:(0,Z.jsxs)(a,{to:`/agents`,children:[t.manageAgents,(0,Z.jsx)(h,{className:`size-4`,"aria-hidden":!0})]})}),r=!!c(e=>e.token),{data:f,error:g,isLoading:S,mutate:w}=u(r?`settings-capability-presets`:null,le,{revalidateOnFocus:!1}),{data:A=[],isLoading:M}=u(r?`settings-capability-presets-skills-catalog`:null,D,{revalidateOnFocus:!1}),N=f?.mcpServerIds??[],{data:B=[]}=u(r&&N.length?[`capability-preset-mcp-tools`,...N]:null,()=>fe(N),{revalidateOnFocus:!1}),[U,G]=i(),[te,ce]=(0,X.useState)(``),[pe,ge]=(0,X.useState)(`overview`),[q,J]=(0,X.useState)(()=>ft(`blank`,t)),[_e,Y]=(0,X.useState)(null),[Q,ve]=(0,X.useState)(!1),[be,xe]=(0,X.useState)(null),[Se,Ce]=(0,X.useState)(!1),[we,Te]=(0,X.useState)(null),[De,Oe]=(0,X.useState)(null),ke=f?.presets??[],Ae=f?.defaultPresetId??`default`,Me=ke.find(e=>e.id===Ae)??null,Ne=ke.filter(e=>e.id!==Ae),$=(0,X.useMemo)(()=>ke.find(e=>e.id===te)??ke[0]??null,[ke,te]),Pe=!$||q.id.trim()!==$.id,Fe=!!($&&$.id===Ae),Ie=JSON.stringify(ot(q,$))!==JSON.stringify(st($)),Le=ot(q,$),Re=st($),Be=[Le.id!==Re?.id||Le.name!==Re?.name||Le.description!==Re?.description?t.tabs.overview:``,JSON.stringify(Le.models)===JSON.stringify(Re?.models)?``:t.tabs.models,JSON.stringify(Le.tools)===JSON.stringify(Re?.tools)?``:t.tabs.tools,JSON.stringify(Le.skills)===JSON.stringify(Re?.skills)?``:t.tabs.skills,JSON.stringify({extends:Le.extends,workflows:Le.workflows,boundaries:Le.boundaries,runtime:Le.runtime,locks:Le.locks})===JSON.stringify({extends:Re?.extends,workflows:Re?.workflows,boundaries:Re?.boundaries,runtime:Re?.runtime,locks:Re?.locks})?``:t.tabs.advanced].filter(Boolean),Ve=(0,X.useMemo)(()=>{if(!$||Pe)return null;let e=dt(q,$);return{name:q.name.trim(),description:q.description.trim()||null,extends:e.extends??null,models:e.models??null,tools:e.tools??null,skills:e.skills??null,workflows:e.workflows??null,boundaries:e.boundaries??null,runtime:e.runtime??null,locks:e.locks??null}},[q,Pe,$]),{data:He,error:Ge,isLoading:Ke}=u(pe===`impact`&&$&&Ve?[`capability-preset-impact-preview`,$.id,JSON.stringify(Ve)]:null,()=>se($.id,Ve),{revalidateOnFocus:!1}),qe=be??(g instanceof Error?g.message:null),Je=U.get(`action`)===`new`||!!U.get(`preset`),Ye=U.get(`action`)===`new`&&_e===null,Xe=Pe?t.newPreset:$?.name??t.editorTitle,Ze=t=>e.agentsSettings.toolsDisableGroups[t],Qe=t=>t in e.agentsSettings.toolDescriptions?e.agentsSettings.toolDescriptions[t]:``;(0,X.useEffect)(()=>{if(!f||Q)return;if(U.get(`action`)===`new`){ce(``),J(ft(`blank`,t)),ge(`overview`);return}let e=U.get(`preset`)?.trim(),n=e?f.presets.find(t=>t.id===e):null;if(n){ce(n.id),J($e(n)),ge(U.get(`tab`)??`overview`);return}$&&(ce($.id),J(e=>e.id===$.id?e:$e($)))},[Q,f,U,$]);function tt(e){Y(null),ce(e.id),J($e(e)),G({preset:e.id},{replace:!0}),ge(`overview`)}function nt(){Y(null),ce(``),J(ft(`blank`,t)),xe(null),G({action:`new`},{replace:!0}),ge(`overview`)}function rt(e){Y(e),J(ft(e,t)),xe(null),ge(`overview`)}function it(){if(_e){let e=ft(_e,t);if(JSON.stringify(ot(q,null))!==JSON.stringify(ot(e,null))&&!window.confirm(t.changeTemplateConfirm))return}Y(null),xe(null)}function at(){!Ye&&Ie&&!window.confirm(t.discardConfirm)||(Ce(!1),Te(null),G({},{replace:!0}),Y(null),xe(null),J($e($)),ge(`overview`))}async function ut(){let e=he(q.modelRows,{invalidId:t.invalidModelRoleId,duplicateId:t.duplicateModelRoleId,invalidModel:t.invalidModelRef});if(e){xe(e),ge(`models`);return}for(let e of[q.modelAdvanced.imageModel,q.modelAdvanced.imageGenerationModel]){if([e.primary,...e.fallbacks].map(e=>e.trim()).filter(Boolean).some(e=>!/^[^/\s]+\/.+/.test(e))){xe(t.invalidModelRef),ge(`models`);return}if(e.timeoutMs.trim()&&(!Number.isInteger(Number(e.timeoutMs))||Number(e.timeoutMs)<=0)){xe(t.advancedPositiveIntegerError),ge(`models`);return}}for(let e of Object.values(q.toolPolicies))if([e.limits?.maxCallsPerTurn,e.limits?.timeoutMs].filter(e=>e!==void 0).some(e=>!Number.isInteger(e)||e<=0)){xe(t.advancedPositiveIntegerError),ge(`tools`);return}ve(!0),xe(null);try{let e=dt(q,$);if(Pe){let t=await me({id:q.id.trim(),name:q.name.trim(),...q.description.trim()?{description:q.description.trim()}:{},...e});await w(t.presets,{revalidate:!1}),ce(t.presetId),Y(null),G({preset:t.presetId},{replace:!0})}else $&&await w(await de($.id,{name:q.name.trim(),description:q.description.trim()||null,extends:e.extends??null,models:e.models??null,tools:e.tools??null,skills:e.skills??null,workflows:e.workflows??null,boundaries:e.boundaries??null,runtime:e.runtime??null,locks:e.locks??null}),{revalidate:!1})}catch(e){xe(e instanceof Error?e.message:t.saveError)}finally{ve(!1)}}async function pt(){if($){ve(!0),xe(null),Te(null);try{await w(await ue($.id),{revalidate:!1}),Ce(!1),ce(``),Y(null),J(ft(`blank`,t)),ge(`overview`),G({},{replace:!0})}catch(e){Te(e instanceof Error?e.message:t.deleteError)}finally{ve(!1)}}}return r?(0,Z.jsxs)(re,{gap:`gap-5`,className:`pb-24`,children:[(0,Z.jsx)(ne,{title:t.title,subtitle:t.subtitle,actions:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n,(0,Z.jsxs)(H,{type:`button`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(E,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]})}),qe?(0,Z.jsx)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:qe}):null,S?(0,Z.jsx)(ie,{sections:2}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[Me?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:z,title:t.globalDefaultsTitle,subtitle:t.globalDefaultsHint}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>tt(Me),className:`group rounded-lg bg-accent/5 px-4 py-3 text-left text-fg shadow-surface transition-colors hover:bg-accent/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:Me.name}),(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.globalDefaultsBadge})]}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:Me.id})]}),(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:t.globalDefaultsInherited})]}),Me.description?(0,Z.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:Me.description}):null,(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-fg-subtle`,children:ct(Me,t)})]})]}):null,(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:z,title:t.listTitle,subtitle:t.listHint}),Ne.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg bg-surface-panel/70 px-3 py-4 text-sm text-fg-muted shadow-surface`,children:[(0,Z.jsx)(`p`,{children:t.empty}),(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(E,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]}):(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:Ne.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>tt(e),className:`group min-h-36 rounded-lg bg-surface-panel/80 px-4 py-3 text-left text-fg shadow-surface transition-colors hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:e.id})]}),(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:e.usage.length})]}),e.description?(0,Z.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:e.description}):null,(0,Z.jsx)(`div`,{className:`mt-3 truncate text-xs text-fg-subtle`,children:ct(e,t)})]},e.id))})]})]}),(0,Z.jsx)(_,{open:Je,onOpenChange:e=>{e||at()},children:(0,Z.jsxs)(p,{children:[(0,Z.jsx)(ee,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim`,I)}),(0,Z.jsx)(x,{ref:Oe,className:o(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(90vh,760px)] w-[min(100%-2rem,64rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,V),onOpenAutoFocus:e=>e.preventDefault(),children:(0,Z.jsxs)(d,{layer:`modal`,portalContainer:De,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[!Ye&&Pe&&_e?(0,Z.jsx)(`button`,{type:`button`,className:o(P,`shrink-0 p-1.5 hover:bg-surface-base`),onClick:it,"aria-label":t.changeTemplate,title:t.changeTemplate,children:(0,Z.jsx)(L,{className:`size-4`,"aria-hidden":!0})}):null,(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(O,{className:`truncate text-base font-semibold text-fg`,children:Xe}),(0,Z.jsx)(T,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:Ye?t.templatePickerSubtitle:Pe&&_e?`${t.editorHint} · ${t.basedOnTemplate.replace(`{{template}}`,t.starters[_e].title)}`:Pe?t.editorHint:q.id})]})]}),(0,Z.jsx)(y,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:o(P,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,Z.jsx)(m,{className:`size-4`,"aria-hidden":!0})})})]}),Ye?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 sm:p-5`,children:(0,Z.jsx)(`div`,{className:`mx-auto grid max-w-3xl gap-3 sm:grid-cols-2`,children:Ue.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`group min-h-32 rounded-xl border border-edge-subtle bg-surface-base px-4 py-4 text-left text-fg transition-colors hover:border-edge hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>rt(e),children:[(0,Z.jsxs)(`span`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t.starters[e].title}),e===`blank`?(0,Z.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[11px] font-medium text-accent-fg`,children:t.templateRecommended}):null]}),(0,Z.jsx)(`span`,{className:`mt-2 block text-xs leading-relaxed text-fg-muted`,children:t.starters[e].description})]},e))})}),(0,Z.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:(0,Z.jsx)(H,{type:`button`,variant:`secondary`,onClick:at,children:t.cancel})})]}):(0,Z.jsxs)(Z.Fragment,{children:[qe?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:qe}):null,(0,Z.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-2 border-b border-edge-subtle bg-surface-base px-4 py-2 dark:border-edge`,children:We.map(({id:e,icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,className:o(`inline-flex 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`,pe===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>ge(e),children:[(0,Z.jsx)(n,{className:`size-4`,"aria-hidden":!0}),t.tabs[e]]},e))}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:(0,Z.jsxs)(`div`,{className:`w-full`,children:[pe===`overview`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:j,title:t.overviewTitle,subtitle:t.overviewHint}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.idLabel}),(0,Z.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:q.id,disabled:Q||!Pe,onChange:e=>J(t=>({...t,id:e.target.value.toLowerCase()})),placeholder:`safe-coder`})]}),!Pe&&$?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.versionLabel}),(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg-muted`,children:t.versionAutomatic.replace(`{{version}}`,String($.version))})]}):null,(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.nameLabel}),(0,Z.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:q.name,disabled:Q,onChange:e=>J(t=>({...t,name:e.target.value})),placeholder:t.namePlaceholder})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.descriptionLabel}),(0,Z.jsx)(`textarea`,{className:`min-h-24 w-full resize-y rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:q.description,disabled:Q,onChange:e=>J(t=>({...t,description:e.target.value})),placeholder:t.descriptionPlaceholder})]})]}),(0,Z.jsxs)(`div`,{className:`mt-5 grid gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(mt,{icon:z,label:t.modelsTitle,value:String(q.modelRows.length)}),(0,Z.jsx)(mt,{icon:C,label:t.toolsTitle,value:String(Object.keys(q.toolPolicies).length)}),(0,Z.jsx)(mt,{icon:W,label:t.skillsTitle,value:t.skillModeLabels[q.skillMode]})]})]}):null,pe===`models`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:z,title:t.modelsTitle,subtitle:t.modelsHint}),(0,Z.jsx)(ye,{rows:q.modelRows,onChange:e=>J(t=>({...t,modelRows:e})),disabled:Q,defaultRole:$?.models?.defaultRole,chat:e.chat,labels:{defaultTitle:t.modelDefaultTitle,defaultHint:t.modelDefaultHint,defaultBadge:t.modelDefaultBadge,roleId:t.modelRoleIdLabel,description:t.modelRoleDescriptionLabel,descriptionPlaceholder:t.modelRoleDescriptionPlaceholder,primaryModel:t.modelPrimaryModelLabel,fallbackModels:t.modelFallbackModelsLabel,addFallback:t.modelAddFallback,removeFallback:t.modelRemoveFallback,fallbackPlaceholder:t.modelFallbackPlaceholder,fallbackEmptyHint:t.modelFallbackEmptyHint,moreSettings:t.modelMoreSettings,otherRolesTitle:t.modelOtherRolesTitle,otherRolesHint:t.modelOtherRolesHint,otherRolesEmpty:t.modelOtherRolesEmpty,addTaskModel:t.modelAddTaskModel,customRole:t.modelCustomRole,removeRole:t.removeModelRole,roleIdPlaceholder:`custom-role`,roleNames:t.modelRoleNames,roleDescriptions:t.modelRoleDescriptions}}),(0,Z.jsx)(ht,{value:q.modelAdvanced,onChange:e=>J(t=>({...t,modelAdvanced:e})),disabled:Q,cp:t,chat:e.chat})]}):null,pe===`tools`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:C,title:t.toolsTitle,subtitle:t.toolsHint}),(0,Z.jsx)(ze,{builtinToolIds:f?.builtinToolIds??[],toolPolicies:q.toolPolicies,onChange:e=>J(t=>({...t,toolPolicies:e})),disabled:Q,getToolDescription:Qe,getGroupTitle:Ze,labels:{quickActionsLabel:t.toolsQuickActionsLabel,quickClearOverrides:t.toolsQuickClearOverrides,quickReadOnlyWorkspace:t.toolsQuickReadOnlyWorkspace,quickHighRiskOff:t.toolsQuickHighRiskOff,quickNoOutbound:t.toolsQuickNoOutbound,quickResearchMode:t.toolsQuickResearchMode,quickCodingMode:t.toolsQuickCodingMode,emptyBuiltin:t.toolsEmptyBuiltin,overrideSummaryTitle:t.toolsOverrideSummaryTitle,noOverrides:t.toolsNoOverrides,inheritedMode:t.toolModes.inherit,modeAllow:t.toolModes.allow,modeConfirm:t.toolModes.confirm,modeDeny:t.toolModes.deny,maxCallsLabel:t.toolMaxCallsLabel,timeoutLabel:t.toolTimeoutLabel}})]}):null,pe===`skills`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:W,title:t.skillsTitle,subtitle:t.skillsHint}),(0,Z.jsx)(je,{mode:q.skillMode,selected:q.skillPick,catalog:A,loading:M,disabled:Q,onModeChange:e=>J(t=>({...t,skillMode:e})),onSelectedChange:e=>J(t=>({...t,skillPick:e})),labels:{modeLabel:t.skillsModeLabel,modeInherit:t.skillsModeInherit,modeAll:t.skillsModeAll,modeAllowlist:t.skillsModeAllowlist,modeDenylist:t.skillsModeDenylist,modeOff:t.skillsModeOff,quickActionsLabel:t.skillsQuickActionsLabel,quickSelectAll:t.skillsQuickSelectAll,quickClear:t.skillsQuickClear,catalogLoading:t.skillsCatalogLoading,emptyCatalog:t.skillsEmptyCatalog,noDescription:t.skillsNoDescription,overrideSummaryTitle:t.skillsOverrideSummaryTitle,inheritSummary:t.skillsInheritSummary,allSummary:t.skillsAllSummary,offSummary:t.skillsOffSummary,allowSummary:t.skillsAllowSummary,denySummary:t.skillsDenySummary}})]}):null,pe===`advanced`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:R,title:t.advancedTitle,subtitle:t.advancedHint}),(0,Z.jsx)(Ee,{extendsIds:q.extendsIds,onExtendsChange:e=>J(t=>({...t,extendsIds:e})),presetOptions:ke.filter(e=>e.id!==$?.id&&e.id!==Ae),inherited:JSON.stringify(q.extendsIds)===JSON.stringify($?.extends??[])?$?.inherited:void 0,inheritedSources:JSON.stringify(q.extendsIds)===JSON.stringify($?.extends??[])?$?.inheritedSources:void 0,mcpServerIds:f?.mcpServerIds??[],mcpTools:B,workflows:f?.workflows??[],policy:q.advancedPolicy,onPolicyChange:e=>J(t=>({...t,advancedPolicy:e})),rawPolicy:dt(q,$),onRawPolicyChange:e=>J(t=>et(t,e)),disabled:Q,labels:{inheritanceTitle:t.advancedInheritanceTitle,inheritanceHint:t.advancedInheritanceHint,inheritanceEmpty:t.advancedInheritanceEmpty,inheritanceAvailable:t.advancedInheritanceAvailable,inheritanceAdd:t.advancedInheritanceAdd,inheritanceRemove:t.advancedInheritanceRemove,inheritanceMoveUp:t.advancedInheritanceMoveUp,inheritanceMoveDown:t.advancedInheritanceMoveDown,compose:t.advancedCompose,inherit:t.advancedInherit,cancel:t.cancel,mcpTitle:t.advancedMcpTitle,mcpHint:t.advancedMcpHint,noMcp:t.advancedNoMcp,workflowsTitle:t.advancedWorkflowsTitle,workflowsHint:t.advancedWorkflowsHint,defaultWorkflow:t.advancedDefaultWorkflow,allowedWorkflows:t.advancedAllowedWorkflows,runtimeTitle:t.advancedRuntimeTitle,runtimeHint:t.advancedRuntimeHint,timeoutMinutes:t.advancedTimeoutMinutes,maxTurns:t.advancedMaxTurns,maxFailures:t.advancedMaxFailures,maxCalls:t.toolMaxCallsLabel,boundariesTitle:t.advancedBoundariesTitle,boundariesHint:t.advancedBoundariesHint,confirmRules:t.advancedConfirmRules,forbiddenRules:t.advancedForbiddenRules,escalationRules:t.advancedEscalationRules,onePerLine:t.advancedOnePerLine,governanceTitle:t.advancedGovernanceTitle,governanceHint:t.advancedGovernanceHint,locksLabel:t.advancedLocksLabel,rawTitle:t.advancedRawTitle,rawHint:t.advancedRawHint,rawOpen:t.advancedRawOpen,rawApply:t.advancedRawApply,rawInvalid:t.advancedRawInvalid,modeAllow:t.toolModes.allow,modeConfirm:t.toolModes.confirm,modeDeny:t.toolModes.deny,readonlyOnly:t.toolScopeReadonly}})]}):null,pe===`impact`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:v,title:t.usageTitle,subtitle:t.usageHint}),(0,Z.jsxs)(`div`,{className:`mb-4 rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:t.changePreviewTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:Be.length>0?t.changePreviewSections.replace(`{{sections}}`,Be.join(`、`)):t.changePreviewEmpty})]}),Pe?null:(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:t.effectiveChangePreviewTitle}),Ke?(0,Z.jsx)(ae,{rows:2}):Ge?(0,Z.jsx)(`p`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-red-600 shadow-surface dark:text-red-400`,children:t.effectiveChangePreviewError}):He?.agents.length?(0,Z.jsx)(`div`,{className:`grid gap-3`,children:He.agents.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,Z.jsx)(`div`,{className:`mt-2 grid gap-2`,children:e.diffs.map(e=>(0,Z.jsxs)(`div`,{className:`grid gap-1 text-xs sm:grid-cols-[minmax(0,12rem)_minmax(0,1fr)]`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-fg-muted`,children:e.path}),(0,Z.jsxs)(`div`,{className:`min-w-0 text-fg`,children:[(0,Z.jsx)(`span`,{className:`break-all text-fg-muted`,children:lt(e.before)}),(0,Z.jsx)(`span`,{className:`px-1.5 text-fg-subtle`,"aria-hidden":!0,children:`→`}),(0,Z.jsx)(`span`,{className:`break-all`,children:lt(e.after)})]})]},e.path))})]},e.agentId))}):(0,Z.jsx)(`p`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:t.effectiveChangePreviewEmpty})]}),$?.usage.length?(0,Z.jsx)(`div`,{className:`grid gap-2`,children:$.usage.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-muted`,children:e.agentId}),(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-fg-subtle`,children:e.direct?t.usageDirect:t.usageIndirect})]},e.agentId))}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUsage})]}):null]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3 border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-fg`,children:Ie?t.unsavedTitle:t.noUnsavedTitle}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:Ie?($?.usage.length??0)>0?t.unsavedImpact.replace(`{{count}}`,String($?.usage.length??0)):t.unsavedNoImpact:t.noUnsavedHint})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[Ie?(0,Z.jsx)(H,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>J($e($)),children:t.discard}):null,$&&!Fe?(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>{Te(null),Ce(!0)},children:[(0,Z.jsx)(k,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,Z.jsxs)(H,{type:`button`,disabled:Q||!q.id.trim()||!q.name.trim()||!Ie,onClick:()=>void ut(),children:[(0,Z.jsx)(F,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})]})})]})}),(0,Z.jsx)(_,{open:Se,onOpenChange:e=>{Q||(Ce(e),e||Te(null))},children:(0,Z.jsxs)(p,{children:[(0,Z.jsx)(ee,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim`,I)}),(0,Z.jsxs)(x,{className:o(`xopc-dialog-content fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2 overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,V),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsx)(O,{className:`text-base font-semibold text-fg`,children:t.deleteDialogTitle}),(0,Z.jsx)(T,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:$?t.deleteConfirm.replace(`{{name}}`,$.name):t.deleteConfirmFallback})]}),we?(0,Z.jsx)(`div`,{className:`mx-4 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:we}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-3`,children:[(0,Z.jsx)(H,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>Ce(!1),children:t.cancel}),(0,Z.jsxs)(H,{type:`button`,disabled:Q||!$,className:`bg-red-600 text-white shadow-surface hover:bg-red-700 focus-visible:ring-red-600 dark:bg-red-500 dark:hover:bg-red-600`,onClick:()=>void pt(),children:[Q?(0,Z.jsx)(b,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(k,{className:`size-4`,"aria-hidden":!0}),Q?t.deleting:t.delete]})]})]})]})})]}):(0,Z.jsxs)(re,{gap:`gap-3`,children:[(0,Z.jsx)(ne,{title:t.title,actions:n}),(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})]})}function mt(e){let t=(0,Y.c)(10),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.jsx)(n,{className:`size-3.5`,"aria-hidden":!0}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[a,r]}),t[2]=r,t[3]=a,t[4]=o):o=t[4];let s;t[5]===i?s=t[6]:(s=(0,Z.jsx)(`div`,{className:`mt-1 text-sm font-medium text-fg`,children:i}),t[5]=i,t[6]=s);let c;return t[7]!==o||t[8]!==s?(c=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function ht(e){let t=(0,Y.c)(121),{value:n,onChange:r,disabled:i,cp:a,chat:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},t[0]=s):s=t[0];let{data:c,isLoading:l,error:d}=u(`capability-preset-image-generation-models`,A,s),f;t[1]===c?f=t[2]:(f=(c??[]).filter(vt).flatMap(_t),t[1]=c,t[2]=f);let p=f,m;t[3]===p?m=t[4]:(m=new Set(p.map(gt)),t[3]=p,t[4]=m);let h=m,g,_;t[5]!==h||t[6]!==c||t[7]!==r||t[8]!==n?(g=()=>{if(!c)return;let e=n.imageGenerationModel,t=h.has(e.primary)?e.primary:``,i=e.fallbacks.filter(e=>h.has(e));t===e.primary&&i.length===e.fallbacks.length||r({...n,imageGenerationModel:{...e,primary:t,fallbacks:i}})},_=[h,c,r,n],t[5]=h,t[6]=c,t[7]=r,t[8]=n,t[9]=g,t[10]=_):(g=t[9],_=t[10]),(0,X.useEffect)(g,_);let v;t[11]!==r||t[12]!==n?(v=(e,t)=>{r({...n,[e]:t})},t[11]=r,t[12]=n,t[13]=v):v=t[13];let y=v,b;t[14]===a.modelSpecializedTitle?b=t[15]:(b=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelSpecializedTitle}),t[14]=a.modelSpecializedTitle,t[15]=b);let x;t[16]!==a.modelNotSet||t[17]!==a.modelSpecializedSummary||t[18]!==n.imageGenerationModel.primary||t[19]!==n.imageModel.primary?(x=a.modelSpecializedSummary.replace(`{{image}}`,n.imageModel.primary||a.modelNotSet).replace(`{{generation}}`,n.imageGenerationModel.primary||a.modelNotSet),t[16]=a.modelNotSet,t[17]=a.modelSpecializedSummary,t[18]=n.imageGenerationModel.primary,t[19]=n.imageModel.primary,t[20]=x):x=t[20];let S;t[21]===x?S=t[22]:(S=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:x}),t[21]=x,t[22]=S);let C;t[23]!==b||t[24]!==S?(C=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[b,S]}),t[23]=b,t[24]=S,t[25]=C):C=t[25];let T;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,Z.jsx)(B,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[26]=T):T=t[26];let E;t[27]===C?E=t[28]:(E=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[C,T]}),t[27]=C,t[28]=E);let D;t[29]===y?D=t[30]:(D=e=>y(`imageModel`,e),t[29]=y,t[30]=D);let O;t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==D||t[35]!==n.imageModel?(O=(0,Z.jsx)(yt,{title:a.imageUnderstandingTitle,value:n.imageModel,onChange:D,disabled:i,cp:a,chat:o,capabilitiesFilter:`vision`}),t[31]=o,t[32]=a,t[33]=i,t[34]=D,t[35]=n.imageModel,t[36]=O):O=t[36];let k;t[37]===y?k=t[38]:(k=e=>y(`imageGenerationModel`,e),t[37]=y,t[38]=k);let j;t[39]===a.modelImageSettingsLink?j=t[40]:(j={label:a.modelImageSettingsLink,path:`/settings/capabilities/image`},t[39]=a.modelImageSettingsLink,t[40]=j);let M;t[41]!==o||t[42]!==a||t[43]!==i||t[44]!==p||t[45]!==d||t[46]!==l||t[47]!==k||t[48]!==j||t[49]!==n.imageGenerationModel?(M=(0,Z.jsx)(yt,{title:a.imageGenerationTitle,value:n.imageGenerationModel,onChange:k,disabled:i,cp:a,chat:o,models:p,modelsLoading:l,modelsError:d,noMatches:a.modelNoConfiguredImageModels,settingsFooterLink:j}),t[41]=o,t[42]=a,t[43]=i,t[44]=p,t[45]=d,t[46]=l,t[47]=k,t[48]=j,t[49]=n.imageGenerationModel,t[50]=M):M=t[50];let P;t[51]!==O||t[52]!==M?(P=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge lg:grid-cols-2`,children:[O,M]}),t[51]=O,t[52]=M,t[53]=P):P=t[53];let F;t[54]!==E||t[55]!==P?(F=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[E,P]}),t[54]=E,t[55]=P,t[56]=F):F=t[56];let I;t[57]===a.modelAdvancedTitle?I=t[58]:(I=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelAdvancedTitle}),t[57]=a.modelAdvancedTitle,t[58]=I);let L;t[59]===a.modelAdvancedHint?L=t[60]:(L=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:a.modelAdvancedHint}),t[59]=a.modelAdvancedHint,t[60]=L);let R;t[61]!==I||t[62]!==L?(R=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[I,L]}),t[61]=I,t[62]=L,t[63]=R):R=t[63];let z;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Z.jsx)(B,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[64]=z):z=t[64];let V;t[65]===R?V=t[66]:(V=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[R,z]}),t[65]=R,t[66]=V);let H;t[67]===a.modelAllowFallbacksLabel?H=t[68]:(H=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelAllowFallbacksLabel}),t[67]=a.modelAllowFallbacksLabel,t[68]=H);let U;t[69]!==r||t[70]!==n?(U=e=>r({...n,allowFallbacks:e.target.value}),t[69]=r,t[70]=n,t[71]=U):U=t[71];let W;t[72]===a.policyInherit?W=t[73]:(W=(0,Z.jsx)(w,{value:``,children:a.policyInherit}),t[72]=a.policyInherit,t[73]=W);let ee;t[74]===a.policyEnabled?ee=t[75]:(ee=(0,Z.jsx)(w,{value:`true`,children:a.policyEnabled}),t[74]=a.policyEnabled,t[75]=ee);let G;t[76]===a.policyDisabled?G=t[77]:(G=(0,Z.jsx)(w,{value:`false`,children:a.policyDisabled}),t[76]=a.policyDisabled,t[77]=G);let te;t[78]!==i||t[79]!==U||t[80]!==W||t[81]!==ee||t[82]!==G||t[83]!==n.allowFallbacks?(te=(0,Z.jsxs)(N,{value:n.allowFallbacks,disabled:i,side:`top`,onChange:U,children:[W,ee,G]}),t[78]=i,t[79]=U,t[80]=W,t[81]=ee,t[82]=G,t[83]=n.allowFallbacks,t[84]=te):te=t[84];let ne;t[85]!==H||t[86]!==te?(ne=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[H,te]}),t[85]=H,t[86]=te,t[87]=ne):ne=t[87];let re;t[88]===a.modelMaxCostTierLabel?re=t[89]:(re=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelMaxCostTierLabel}),t[88]=a.modelMaxCostTierLabel,t[89]=re);let ie;t[90]!==r||t[91]!==n?(ie=e=>r({...n,maxCostTier:e.target.value}),t[90]=r,t[91]=n,t[92]=ie):ie=t[92];let ae;t[93]===a.policyInherit?ae=t[94]:(ae=(0,Z.jsx)(w,{value:``,children:a.policyInherit}),t[93]=a.policyInherit,t[94]=ae);let K;t[95]===a.costTierLow?K=t[96]:(K=(0,Z.jsx)(w,{value:`low`,children:a.costTierLow}),t[95]=a.costTierLow,t[96]=K);let oe;t[97]===a.costTierMedium?oe=t[98]:(oe=(0,Z.jsx)(w,{value:`medium`,children:a.costTierMedium}),t[97]=a.costTierMedium,t[98]=oe);let se;t[99]===a.costTierHigh?se=t[100]:(se=(0,Z.jsx)(w,{value:`high`,children:a.costTierHigh}),t[99]=a.costTierHigh,t[100]=se);let ce;t[101]!==i||t[102]!==ie||t[103]!==ae||t[104]!==K||t[105]!==oe||t[106]!==se||t[107]!==n.maxCostTier?(ce=(0,Z.jsxs)(N,{value:n.maxCostTier,disabled:i,side:`top`,onChange:ie,children:[ae,K,oe,se]}),t[101]=i,t[102]=ie,t[103]=ae,t[104]=K,t[105]=oe,t[106]=se,t[107]=n.maxCostTier,t[108]=ce):ce=t[108];let le;t[109]!==re||t[110]!==ce?(le=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[re,ce]}),t[109]=re,t[110]=ce,t[111]=le):le=t[111];let ue;t[112]!==ne||t[113]!==le?(ue=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge sm:grid-cols-2`,children:[ne,le]}),t[112]=ne,t[113]=le,t[114]=ue):ue=t[114];let de;t[115]!==V||t[116]!==ue?(de=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[V,ue]}),t[115]=V,t[116]=ue,t[117]=de):de=t[117];let fe;return t[118]!==F||t[119]!==de?(fe=(0,Z.jsxs)(`div`,{className:`mt-5 grid gap-3 border-t border-edge-subtle pt-5 dark:border-edge`,children:[F,de]}),t[118]=F,t[119]=de,t[120]=fe):fe=t[120],fe}function gt(e){return e.id}function _t(e){return e.models.map(t=>({id:`${e.id}/${t}`,name:t,provider:e.label}))}function vt(e){return e.configured||e.credentialMode!==`api-key`}function yt(e){let t=(0,Y.c)(109),{title:n,value:r,onChange:i,disabled:a,cp:o,chat:s,capabilitiesFilter:c,models:l,modelsLoading:u,modelsError:d,noMatches:f,settingsFooterLink:p}=e,h;t[0]!==i||t[1]!==r?(h=(e,t)=>{i({...r,fallbacks:r.fallbacks.map((n,r)=>r===e?t:n)})},t[0]=i,t[1]=r,t[2]=h):h=t[2];let g=h,_;t[3]===n?_=t[4]:(_=(0,Z.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n}),t[3]=n,t[4]=_);let v=r.primary||o.modelNotSet,y;t[5]===v?y=t[6]:(y=(0,Z.jsx)(`span`,{className:`max-w-48 truncate font-mono text-xs text-fg-muted`,children:v}),t[5]=v,t[6]=y);let b;t[7]!==_||t[8]!==y?(b=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2.5`,children:[_,y]}),t[7]=_,t[8]=y,t[9]=b):b=t[9];let x;t[10]===o.modelToolPrimaryLabel?x=t[11]:(x=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolPrimaryLabel}),t[10]=o.modelToolPrimaryLabel,t[11]=x);let C=f??s.modelNoMatches,T;t[12]!==i||t[13]!==r?(T=e=>i({...r,primary:e}),t[12]=i,t[13]=r,t[14]=T):T=t[14];let D;t[15]!==c||t[16]!==s.modelPlaceholder||t[17]!==s.modelSearchPlaceholder||t[18]!==a||t[19]!==l||t[20]!==d||t[21]!==u||t[22]!==p||t[23]!==C||t[24]!==T||t[25]!==r.primary?(D=(0,Z.jsx)(S,{value:r.primary,disabled:a,placeholder:s.modelPlaceholder,searchPlaceholder:s.modelSearchPlaceholder,noMatches:C,models:l,modelsLoading:u,modelsError:d,settingsFooterLink:p,capabilitiesFilter:c,className:`w-full max-w-none`,contentAlign:`start`,onChange:T}),t[15]=c,t[16]=s.modelPlaceholder,t[17]=s.modelSearchPlaceholder,t[18]=a,t[19]=l,t[20]=d,t[21]=u,t[22]=p,t[23]=C,t[24]=T,t[25]=r.primary,t[26]=D):D=t[26];let O;t[27]!==o.modelClearSelection||t[28]!==a||t[29]!==i||t[30]!==r?(O=r.primary?(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelClearSelection,onClick:()=>i({...r,primary:``}),children:(0,Z.jsx)(m,{className:`size-4`,strokeWidth:1.75})}):null,t[27]=o.modelClearSelection,t[28]=a,t[29]=i,t[30]=r,t[31]=O):O=t[31];let A;t[32]!==D||t[33]!==O?(A=(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[D,O]}),t[32]=D,t[33]=O,t[34]=A):A=t[34];let j;t[35]!==A||t[36]!==x?(j=(0,Z.jsxs)(`div`,{className:`grid gap-1`,children:[x,A]}),t[35]=A,t[36]=x,t[37]=j):j=t[37];let M;t[38]===o.modelToolFallbacksLabel?M=t[39]:(M=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolFallbacksLabel}),t[38]=o.modelToolFallbacksLabel,t[39]=M);let P;t[40]!==i||t[41]!==r?(P=()=>i({...r,fallbacks:[...r.fallbacks,``]}),t[40]=i,t[41]=r,t[42]=P):P=t[42];let F;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,Z.jsx)(E,{className:`size-3.5`,strokeWidth:1.75}),t[43]=F):F=t[43];let I;t[44]!==o.modelAddFallback||t[45]!==a||t[46]!==P?(I=(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:a,onClick:P,children:[F,o.modelAddFallback]}),t[44]=o.modelAddFallback,t[45]=a,t[46]=P,t[47]=I):I=t[47];let L;t[48]!==M||t[49]!==I?(L=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[M,I]}),t[48]=M,t[49]=I,t[50]=L):L=t[50];let R;t[51]!==c||t[52]!==s.modelNoMatches||t[53]!==s.modelSearchPlaceholder||t[54]!==o.modelFallbackEmptyHint||t[55]!==o.modelFallbackPlaceholder||t[56]!==o.modelRemoveFallback||t[57]!==a||t[58]!==l||t[59]!==d||t[60]!==u||t[61]!==f||t[62]!==i||t[63]!==p||t[64]!==g||t[65]!==r?(R=r.fallbacks.length>0?(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:r.fallbacks.map((e,t)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,Z.jsx)(S,{value:e,disabled:a,placeholder:o.modelFallbackPlaceholder,searchPlaceholder:s.modelSearchPlaceholder,noMatches:f??s.modelNoMatches,models:l,modelsLoading:u,modelsError:d,settingsFooterLink:p,capabilitiesFilter:c,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>g(t,e)}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelRemoveFallback,onClick:()=>i({...r,fallbacks:r.fallbacks.filter((e,n)=>n!==t)}),children:(0,Z.jsx)(k,{className:`size-4`,strokeWidth:1.75})})]},`fallback-${t}`))}):(0,Z.jsx)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 text-xs text-fg-muted`,children:o.modelFallbackEmptyHint}),t[51]=c,t[52]=s.modelNoMatches,t[53]=s.modelSearchPlaceholder,t[54]=o.modelFallbackEmptyHint,t[55]=o.modelFallbackPlaceholder,t[56]=o.modelRemoveFallback,t[57]=a,t[58]=l,t[59]=d,t[60]=u,t[61]=f,t[62]=i,t[63]=p,t[64]=g,t[65]=r,t[66]=R):R=t[66];let z;t[67]!==L||t[68]!==R?(z=(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[L,R]}),t[67]=L,t[68]=R,t[69]=z):z=t[69];let B;t[70]!==i||t[71]!==r?(B=e=>i({...r,timeoutMs:e.target.value}),t[70]=i,t[71]=r,t[72]=B):B=t[72];let V;t[73]!==a||t[74]!==B||t[75]!==r.timeoutMs?(V=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:r.timeoutMs,disabled:a,onChange:B}),t[73]=a,t[74]=B,t[75]=r.timeoutMs,t[76]=V):V=t[76];let U;t[77]!==o.toolTimeoutLabel||t[78]!==V?(U=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.toolTimeoutLabel,V]}),t[77]=o.toolTimeoutLabel,t[78]=V,t[79]=U):U=t[79];let W;t[80]!==i||t[81]!==r?(W=e=>i({...r,autoProviderFallback:e.target.value}),t[80]=i,t[81]=r,t[82]=W):W=t[82];let ee;t[83]===o.policyInherit?ee=t[84]:(ee=(0,Z.jsx)(w,{value:``,children:o.policyInherit}),t[83]=o.policyInherit,t[84]=ee);let G;t[85]===o.policyEnabled?G=t[86]:(G=(0,Z.jsx)(w,{value:`true`,children:o.policyEnabled}),t[85]=o.policyEnabled,t[86]=G);let te;t[87]===o.policyDisabled?te=t[88]:(te=(0,Z.jsx)(w,{value:`false`,children:o.policyDisabled}),t[87]=o.policyDisabled,t[88]=te);let ne;t[89]!==a||t[90]!==W||t[91]!==ee||t[92]!==G||t[93]!==te||t[94]!==r.autoProviderFallback?(ne=(0,Z.jsxs)(N,{value:r.autoProviderFallback,disabled:a,side:`top`,onChange:W,children:[ee,G,te]}),t[89]=a,t[90]=W,t[91]=ee,t[92]=G,t[93]=te,t[94]=r.autoProviderFallback,t[95]=ne):ne=t[95];let re;t[96]!==o.modelAutoProviderFallbackLabel||t[97]!==ne?(re=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.modelAutoProviderFallbackLabel,ne]}),t[96]=o.modelAutoProviderFallbackLabel,t[97]=ne,t[98]=re):re=t[98];let ie;t[99]!==U||t[100]!==re?(ie=(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[U,re]}),t[99]=U,t[100]=re,t[101]=ie):ie=t[101];let ae;t[102]!==j||t[103]!==z||t[104]!==ie?(ae=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-3 dark:border-edge`,children:[j,z,ie]}),t[102]=j,t[103]=z,t[104]=ie,t[105]=ae):ae=t[105];let K;return t[106]!==ae||t[107]!==b?(K=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 shadow-surface`,children:[b,ae]}),t[106]=ae,t[107]=b,t[108]=K):K=t[108],K}export{pt as CapabilityPresetsSettingsPanel};
|
|
3
|
+
`)??``}function Ce(e,t,n){return Object.entries(e).find(([e])=>e===t||e.startsWith(`${t}.`))?.[1]??n}function we(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function Te(e){if(!we(e)||[`models`,`tools`,`skills`,`workflows`,`boundaries`,`runtime`].some(t=>e[t]!==void 0&&!we(e[t]))||e.extends!==void 0&&!Array.isArray(e.extends)||e.locks!==void 0&&!Array.isArray(e.locks))return!1;let t=e.skills;if(t&&[`allow`,`deny`].some(e=>t[e]!==void 0&&!Array.isArray(t[e])))return!1;let n=e.workflows;if(n&&[`allowed`,`suggested`].some(e=>n[e]!==void 0&&!Array.isArray(n[e])))return!1;let r=e.boundaries;return!(r&&[`requiresConfirmation`,`forbidden`,`escalation`].some(e=>r[e]!==void 0&&!Array.isArray(r[e])))}function Ee(e){let{extendsIds:t,onExtendsChange:n,presetOptions:r,inherited:i,inheritedSources:a={},mcpServerIds:o,mcpTools:s,workflows:c,policy:l,onPolicyChange:u,rawPolicy:d,onRawPolicyChange:p,disabled:m,labels:h}=e,[_,v]=(0,X.useState)(t.length>1),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(``),[C,w]=(0,X.useState)(``),E=l.mcp??{},D=l.workflows??{},O=l.boundaries??{},A=l.runtime??{},j=l.locks??[],N=[...new Set([...o,...Object.keys(E.servers??{})])].sort(),P=new Map(r.map(e=>[e.id,e])),F=r.filter(e=>!t.includes(e.id)),I=(e,t)=>{u({...l,[e]:t})},L=(e,t)=>{let n={...E.servers??{}};t?n[e]={...n[e],mode:t}:delete n[e],I(`mcp`,De({...E,servers:Object.keys(n).length?n:void 0,tools:Object.keys(E.tools??{}).length?E.tools:void 0}))},R=(e,t)=>{let n={...E.tools??{}};t?n[e]=t:delete n[e],I(`mcp`,De({...E,servers:Object.keys(E.servers??{}).length?E.servers:void 0,tools:Object.keys(n).length?n:void 0}))};return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:h.inheritanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:h.inheritanceHint}),_?(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2`,children:[t.map((e,r)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-surface-panel/70 px-3 py-2.5 shadow-surface`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:P.get(e)?.name??e}),(0,Z.jsx)(`div`,{className:`font-mono text-[11px] text-fg-subtle`,children:e})]}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:m||r===0,"aria-label":h.inheritanceMoveUp,onClick:()=>{let e=[...t];[e[r-1],e[r]]=[e[r],e[r-1]],n(e)},children:(0,Z.jsx)(g,{className:`size-3.5`})}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:m||r===t.length-1,"aria-label":h.inheritanceMoveDown,onClick:()=>{let e=[...t];[e[r],e[r+1]]=[e[r+1],e[r]],n(e)},children:(0,Z.jsx)(f,{className:`size-3.5`})}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:m,"aria-label":h.inheritanceRemove,onClick:()=>n(t.filter(t=>t!==e)),children:(0,Z.jsx)(k,{className:`size-3.5`})})]},e)),F.length?(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[h.inheritanceAdd,(0,Z.jsxs)(M,{value:``,disabled:m,onChange:e=>e.target.value&&n([...t,e.target.value]),children:[(0,Z.jsx)(T,{value:``,children:h.inheritanceAvailable}),F.map(e=>(0,Z.jsx)(T,{value:e.id,children:e.name},e.id))]})]}):null]}):(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-end gap-2`,children:[(0,Z.jsxs)(`label`,{className:`min-w-64 flex-1 text-xs text-fg-muted`,children:[h.inheritanceAvailable,(0,Z.jsxs)(M,{value:t[0]??``,disabled:m,onChange:e=>n(e.target.value?[e.target.value]:[]),children:[(0,Z.jsx)(T,{value:``,children:h.inherit}),r.map(e=>(0,Z.jsx)(T,{value:e.id,children:e.name},e.id))]})]}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,disabled:m,onClick:()=>v(!0),children:h.compose})]}),r.length?null:(0,Z.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:h.inheritanceEmpty})]}),(0,Z.jsx)(Oe,{title:h.mcpTitle,hint:h.mcpHint,source:Ce(a,`tools.mcp`,h.inherit),children:N.length?(0,Z.jsx)(`div`,{className:`grid gap-2`,children:N.map(e=>(0,Z.jsxs)(`details`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,Z.jsxs)(`summary`,{className:`grid cursor-pointer items-center gap-2 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-xs text-fg`,children:e}),(0,Z.jsxs)(M,{value:E.servers?.[e]?.mode??``,disabled:m,onClick:e=>e.stopPropagation(),onChange:t=>L(e,t.target.value),children:[(0,Z.jsx)(T,{value:``,children:i?.tools?.mcp?.servers?.[e]?.mode?`${h.inherit} · ${i.tools.mcp.servers[e].mode}`:h.inherit}),(0,Z.jsx)(T,{value:`allow`,children:h.modeAllow}),(0,Z.jsx)(T,{value:`confirm`,children:h.modeConfirm}),(0,Z.jsx)(T,{value:`deny`,children:h.modeDeny})]})]}),(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3`,children:[E.servers?.[e]?(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:E.servers[e].scope===`readonly`,disabled:m,onChange:t=>{let n=E.servers?.[e];if(!n)return;let r={...E.servers??{},[e]:{...n,scope:t.target.checked?`readonly`:void 0}};I(`mcp`,De({...E,servers:r}))}}),h.readonlyOnly]}):null,s.filter(t=>t.serverId===e).map(e=>{let t=E.tools?.[e.id];return(0,Z.jsxs)(`div`,{className:`grid gap-2 rounded-lg bg-surface-base px-3 py-2 lg:grid-cols-[minmax(0,1fr)_11rem_8rem_8rem] lg:items-end`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.description})]}),(0,Z.jsxs)(M,{value:t?.mode??``,disabled:m,onChange:n=>{let r=n.target.value;R(e.id,r?{...t??{},mode:r}:void 0)},children:[(0,Z.jsx)(T,{value:``,children:h.inherit}),(0,Z.jsx)(T,{value:`allow`,children:h.modeAllow}),(0,Z.jsx)(T,{value:`confirm`,children:h.modeConfirm}),(0,Z.jsx)(T,{value:`deny`,children:h.modeDeny})]}),(0,Z.jsx)(ke,{label:h.maxCalls,value:t?.limits?.maxCallsPerTurn,disabled:!t||m,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,maxCallsPerTurn:n})}:void 0)}),(0,Z.jsx)(ke,{label:h.timeoutMinutes,value:t?.limits?.timeoutMs?t.limits.timeoutMs/6e4:void 0,disabled:!t||m,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,timeoutMs:n?n*6e4:void 0})}:void 0)})]},e.id)})]})]},e))}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h.noMcp})}),(0,Z.jsxs)(Oe,{title:h.workflowsTitle,hint:h.workflowsHint,source:Ce(a,`workflows`,h.inherit),children:[(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[h.defaultWorkflow,(0,Z.jsxs)(M,{value:D.default??``,disabled:m,onChange:e=>I(`workflows`,De({...D,default:e.target.value||void 0})),children:[(0,Z.jsx)(T,{value:``,children:i?.workflows?.default?`${h.inherit} · ${i.workflows.default}`:h.inherit}),c.map(e=>(0,Z.jsx)(T,{value:e.id,children:e.title},e.id))]})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-xs text-fg-muted`,children:h.allowedWorkflows}),(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:c.map(e=>{let t=D.allowed?.includes(e.id)??!1;return(0,Z.jsxs)(`label`,{className:`flex gap-2 rounded-lg bg-surface-panel/70 px-3 py-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:t,disabled:m,onChange:()=>{let n=new Set(D.allowed??[]);t?n.delete(e.id):n.add(e.id),I(`workflows`,De({...D,allowed:n.size?[...n].sort():void 0}))}}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:e.title}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:e.description})]})]},e.id)})})]})]}),(0,Z.jsx)(Oe,{title:h.runtimeTitle,hint:h.runtimeHint,source:Ce(a,`runtime`,h.inherit),children:(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Z.jsx)(ke,{label:h.timeoutMinutes,value:A.timeoutMs?A.timeoutMs/6e4:void 0,placeholder:i?.runtime?.timeoutMs?String(i.runtime.timeoutMs/6e4):void 0,disabled:m,onChange:e=>I(`runtime`,De({...A,timeoutMs:e?e*6e4:void 0}))}),(0,Z.jsx)(ke,{label:h.maxTurns,value:A.maxTurns,placeholder:i?.runtime?.maxTurns?String(i.runtime.maxTurns):void 0,disabled:m,onChange:e=>I(`runtime`,De({...A,maxTurns:e}))}),(0,Z.jsx)(ke,{label:h.maxFailures,value:A.maxToolFailuresPerTurn,placeholder:i?.runtime?.maxToolFailuresPerTurn?String(i.runtime.maxToolFailuresPerTurn):void 0,disabled:m,onChange:e=>I(`runtime`,De({...A,maxToolFailuresPerTurn:e}))})]})}),(0,Z.jsx)(Oe,{title:h.boundariesTitle,hint:h.boundariesHint,source:Ce(a,`boundaries`,h.inherit),children:(0,Z.jsx)(`div`,{className:`grid gap-3 lg:grid-cols-3`,children:[[`requiresConfirmation`,h.confirmRules],[`forbidden`,h.forbiddenRules],[`escalation`,h.escalationRules]].map(([e,t])=>(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[t,(0,Z.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg`,placeholder:h.onePerLine,value:Se(O[e]),disabled:m,onChange:t=>I(`boundaries`,De({...O,[e]:xe(t.target.value)}))})]},e))})}),(0,Z.jsxs)(`details`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-4`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer text-sm font-semibold text-fg`,children:h.governanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:h.governanceHint}),(0,Z.jsxs)(`label`,{className:`mt-3 block text-xs text-fg-muted`,children:[h.locksLabel,(0,Z.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 font-mono text-xs text-fg`,placeholder:h.onePerLine,value:Se(j),disabled:m,onChange:e=>I(`locks`,xe(e.target.value))})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:h.rawTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:h.rawHint}),y?(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`h-72 overflow-hidden rounded-lg border border-edge bg-surface-base`,children:(0,Z.jsx)(te,{initialContent:x,onChange:S,language:be,lineWrap:!0})}),C?(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-red-600 dark:text-red-400`,children:C}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(H,{type:`button`,onClick:()=>{try{let e=JSON.parse(x);if(!Te(e))throw Error(`invalid policy`);p(e),w(``),b(!1)}catch{w(h.rawInvalid)}},children:h.rawApply}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,onClick:()=>b(!1),children:h.cancel})]})]}):(0,Z.jsx)(H,{className:`mt-3`,type:`button`,variant:`secondary`,onClick:()=>{S(JSON.stringify(d,null,2)),w(``),b(!0)},children:h.rawOpen})]})]})}function De(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));return Object.keys(t).length?t:void 0}function Oe(e){let t=(0,Y.c)(17),n;t[0]===e.title?n=t[1]:(n=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:e.title}),t[0]=e.title,t[1]=n);let r;t[2]===e.hint?r=t[3]:(r=(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.hint}),t[2]=e.hint,t[3]=r);let i;t[4]!==n||t[5]!==r?(i=(0,Z.jsxs)(`div`,{children:[n,r]}),t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;t[7]===e.source?a=t[8]:(a=(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] text-fg-muted`,children:e.source}),t[7]=e.source,t[8]=a);let o;t[9]!==i||t[10]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[i,a]}),t[9]=i,t[10]=a,t[11]=o):o=t[11];let s;t[12]===e.children?s=t[13]:(s=(0,Z.jsx)(`div`,{className:`mt-3`,children:e.children}),t[12]=e.children,t[13]=s);let c;return t[14]!==o||t[15]!==s?(c=(0,Z.jsxs)(`section`,{children:[o,s]}),t[14]=o,t[15]=s,t[16]=c):c=t[16],c}function ke(e){let t=(0,Y.c)(10),n=e.value??``,r;t[0]===e?r=t[1]:(r=t=>e.onChange(t.target.value?Number(t.target.value):void 0),t[0]=e,t[1]=r);let i;t[2]!==e.disabled||t[3]!==e.placeholder||t[4]!==n||t[5]!==r?(i=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`mt-1 w-full rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg`,value:n,placeholder:e.placeholder,disabled:e.disabled,onChange:r}),t[2]=e.disabled,t[3]=e.placeholder,t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;return t[7]!==e.label||t[8]!==i?(a=(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[e.label,i]}),t[7]=e.label,t[8]=i,t[9]=a):a=t[9],a}function Ae(e){return e.name||e.directoryId}function je(e){let t=(0,Y.c)(56),{mode:n,selected:r,catalog:i,loading:a,disabled:s,onModeChange:c,onSelectedChange:l,labels:u}=e,d=n===`allowlist`||n===`denylist`,f;t[0]===i?f=t[1]:(f=i.map(Ae).filter(Boolean),t[0]=i,t[1]=f);let p=f,m;bb0:{if(n===`inherit`){m=u.inheritSummary;break bb0}if(n===`all`){m=u.allSummary;break bb0}if(n===`off`){m=u.offSummary;break bb0}let e=n===`allowlist`?u.allowSummary:u.denySummary,i;t[2]!==r.size||t[3]!==e?(i=e.replace(`{{count}}`,String(r.size)),t[2]=r.size,t[3]=e,t[4]=i):i=t[4],m=i}let h=m,g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(U,{className:`size-3.5`,"aria-hidden":!0}),t[5]=g):g=t[5];let _;t[6]===u.overrideSummaryTitle?_=t[7]:(_=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[g,u.overrideSummaryTitle]}),t[6]=u.overrideSummaryTitle,t[7]=_);let v;t[8]===h?v=t[9]:(v=(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:h}),t[8]=h,t[9]=v);let y;t[10]!==_||t[11]!==v?(y=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[_,v]}),t[10]=_,t[11]=v,t[12]=y):y=t[12];let b;t[13]===u.modeLabel?b=t[14]:(b=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.modeLabel}),t[13]=u.modeLabel,t[14]=b);let x;t[15]===u.modeInherit?x=t[16]:(x=[`inherit`,u.modeInherit],t[15]=u.modeInherit,t[16]=x);let S;t[17]===u.modeAll?S=t[18]:(S=[`all`,u.modeAll],t[17]=u.modeAll,t[18]=S);let C;t[19]===u.modeAllowlist?C=t[20]:(C=[`allowlist`,u.modeAllowlist],t[19]=u.modeAllowlist,t[20]=C);let w;t[21]===u.modeDenylist?w=t[22]:(w=[`denylist`,u.modeDenylist],t[21]=u.modeDenylist,t[22]=w);let T;t[23]===u.modeOff?T=t[24]:(T=[`off`,u.modeOff],t[23]=u.modeOff,t[24]=T);let E;t[25]!==w||t[26]!==T||t[27]!==x||t[28]!==S||t[29]!==C?(E=[x,S,C,w,T],t[25]=w,t[26]=T,t[27]=x,t[28]=S,t[29]=C,t[30]=E):E=t[30];let D=E,O;t[31]!==s||t[32]!==n||t[33]!==c||t[34]!==D?(O=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:D.map(e=>{let[t,r]=e;return(0,Z.jsx)(`button`,{type:`button`,className:o(`rounded-lg px-3 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,n===t?`bg-accent-soft text-accent-fg`:`bg-surface-panel text-fg hover:bg-surface-hover/55`),disabled:s,onClick:()=>c(t),children:r},t)})}),t[31]=s,t[32]=n,t[33]=c,t[34]=D,t[35]=O):O=t[35];let k;t[36]!==O||t[37]!==b?(k=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,O]}),t[36]=O,t[37]=b,t[38]=k):k=t[38];let A;t[39]!==i||t[40]!==p||t[41]!==s||t[42]!==u.emptyCatalog||t[43]!==u.noDescription||t[44]!==u.quickActionsLabel||t[45]!==u.quickClear||t[46]!==u.quickSelectAll||t[47]!==a||t[48]!==l||t[49]!==d||t[50]!==r?(A=d?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.quickActionsLabel}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:s||a||p.length===0,onClick:()=>l(new Set(p)),children:u.quickSelectAll}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:s||a||r.size===0,onClick:()=>l(new Set),children:u.quickClear})]})]}),a?(0,Z.jsx)(ae,{rows:3}):i.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.emptyCatalog}):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:i.map(e=>{let t=Ae(e),n=r.has(t),i=typeof e.description==`string`?e.description.trim():``,a=i||u.noDescription;return(0,Z.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl bg-surface-panel/70 px-3 shadow-surface`,children:(0,Z.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:n,disabled:s,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),l(e)},"aria-label":t}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,Z.jsx)(`p`,{className:o(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!i&&`italic text-fg-subtle`),title:a,children:a})]})]})},t)})})]}):null,t[39]=i,t[40]=p,t[41]=s,t[42]=u.emptyCatalog,t[43]=u.noDescription,t[44]=u.quickActionsLabel,t[45]=u.quickClear,t[46]=u.quickSelectAll,t[47]=a,t[48]=l,t[49]=d,t[50]=r,t[51]=A):A=t[51];let j;return t[52]!==k||t[53]!==A||t[54]!==y?(j=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[y,k,A]}),t[52]=k,t[53]=A,t[54]=y,t[55]=j):j=t[55],j}var Me=[`write_file`,`apply_patch`,`exec_command`,`execute_code`],Ne=[`exec_command`,`execute_code`,`automation`,`extensions`,`bundle-mcp`,`skill_manage`],$=[`send_message`,`send_media`,`text_to_speech`,`create_share`],Pe=[`read_file`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`,`web_extract`],Fe=[...Me,...$],Ie=[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`],Le=[`send_message`,`send_media`];function Re(e,t){let n={};for(let[r,i]of t)for(let t of r)e.has(t)&&(n[t]={mode:i});return n}function ze(e){let t=(0,Y.c)(100),{builtinToolIds:n,toolPolicies:r,onChange:i,disabled:a,getToolDescription:s,getGroupTitle:c,labels:l}=e,u;t[0]===n?u=t[1]:(u=new Set(n),t[0]=n,t[1]=u);let d=u,f;t[2]!==d||t[3]!==r?(f=Object.entries(r).filter(e=>{let[t]=e;return d.has(t)}).toSorted(Be),t[2]=d,t[3]=r,t[4]=f):f=t[4];let p=f,m;if(t[5]!==d||t[6]!==n){m=[];for(let e of pe){let t=e.toolIds.filter(e=>d.has(e));t.length>0&&m.push({key:e.key,ids:[...t]})}let e;t[8]===n?e=t[9]:(e=ce(n),t[8]=n,t[9]=e);let r=e;if(r.length>0){let e;t[10]===r?e=t[11]:(e={key:`misc`,ids:r},t[10]=r,t[11]=e),m.push(e)}t[5]=d,t[6]=n,t[7]=m}else m=t[7];let h=m,g;t[12]!==i||t[13]!==r?(g=(e,t)=>{let n={...r};t===`inherit`?delete n[e]:n[e]={...n[e],mode:t},i(n)},t[12]=i,t[13]=r,t[14]=g):g=t[14];let _=g,v;t[15]!==i||t[16]!==r?(v=(e,t)=>{let n=r[e];n&&i({...r,[e]:t(n)})},t[15]=i,t[16]=r,t[17]=v):v=t[17];let y=v,b;t[18]!==d||t[19]!==i?(b=e=>{i(Re(d,e))},t[18]=d,t[19]=i,t[20]=b):b=t[20];let x=b;if(n.length===0){let e;return t[21]===l.emptyBuiltin?e=t[22]:(e=(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.emptyBuiltin}),t[21]=l.emptyBuiltin,t[22]=e),e}let S;t[23]===l.quickActionsLabel?S=t[24]:(S=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.quickActionsLabel}),t[23]=l.quickActionsLabel,t[24]=S);let C;t[25]===i?C=t[26]:(C=()=>i({}),t[25]=i,t[26]=C);let w;t[27]!==a||t[28]!==l.quickClearOverrides||t[29]!==C?(w=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:C,children:l.quickClearOverrides}),t[27]=a,t[28]=l.quickClearOverrides,t[29]=C,t[30]=w):w=t[30];let T;t[31]===x?T=t[32]:(T=()=>x([[Me,`deny`]]),t[31]=x,t[32]=T);let E;t[33]!==a||t[34]!==l.quickReadOnlyWorkspace||t[35]!==T?(E=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:T,children:l.quickReadOnlyWorkspace}),t[33]=a,t[34]=l.quickReadOnlyWorkspace,t[35]=T,t[36]=E):E=t[36];let D;t[37]===x?D=t[38]:(D=()=>x([[Ne,`deny`]]),t[37]=x,t[38]=D);let O;t[39]!==a||t[40]!==l.quickHighRiskOff||t[41]!==D?(O=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:D,children:l.quickHighRiskOff}),t[39]=a,t[40]=l.quickHighRiskOff,t[41]=D,t[42]=O):O=t[42];let k;t[43]===x?k=t[44]:(k=()=>x([[$,`deny`]]),t[43]=x,t[44]=k);let A;t[45]!==a||t[46]!==l.quickNoOutbound||t[47]!==k?(A=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:k,children:l.quickNoOutbound}),t[45]=a,t[46]=l.quickNoOutbound,t[47]=k,t[48]=A):A=t[48];let j;t[49]===x?j=t[50]:(j=()=>x([[Pe,`allow`],[Fe,`deny`]]),t[49]=x,t[50]=j);let M;t[51]!==a||t[52]!==l.quickResearchMode||t[53]!==j?(M=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:j,children:l.quickResearchMode}),t[51]=a,t[52]=l.quickResearchMode,t[53]=j,t[54]=M):M=t[54];let N;t[55]===x?N=t[56]:(N=()=>x([[Ie,`allow`],[Le,`deny`]]),t[55]=x,t[56]=N);let P;t[57]!==a||t[58]!==l.quickCodingMode||t[59]!==N?(P=(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:N,children:l.quickCodingMode}),t[57]=a,t[58]=l.quickCodingMode,t[59]=N,t[60]=P):P=t[60];let F;t[61]!==O||t[62]!==A||t[63]!==M||t[64]!==P||t[65]!==w||t[66]!==E?(F=(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[w,E,O,A,M,P]}),t[61]=O,t[62]=A,t[63]=M,t[64]=P,t[65]=w,t[66]=E,t[67]=F):F=t[67];let I;t[68]!==F||t[69]!==S?(I=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[S,F]}),t[68]=F,t[69]=S,t[70]=I):I=t[70];let L;t[71]===l.overrideSummaryTitle?L=t[72]:(L=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:l.overrideSummaryTitle}),t[71]=l.overrideSummaryTitle,t[72]=L);let R;t[73]!==l.modeAllow||t[74]!==l.modeConfirm||t[75]!==l.modeDeny||t[76]!==l.noOverrides||t[77]!==p?(R=p.length>0?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:p.map(e=>{let[t,n]=e;return(0,Z.jsxs)(`span`,{className:o(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,n.mode===`deny`&&`border-red-500/25 bg-red-500/10 text-red-700 dark:text-red-300`,n.mode===`confirm`&&`border-amber-500/25 bg-amber-500/10 text-amber-700 dark:text-amber-300`,n.mode===`allow`&&`border-accent/25 bg-accent/10 text-accent`),children:[t,(0,Z.jsx)(`span`,{className:`font-sans opacity-80`,children:n.mode===`allow`?l.modeAllow:n.mode===`confirm`?l.modeConfirm:l.modeDeny})]},t)})}):(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:l.noOverrides}),t[73]=l.modeAllow,t[74]=l.modeConfirm,t[75]=l.modeDeny,t[76]=l.noOverrides,t[77]=p,t[78]=R):R=t[78];let z;t[79]!==L||t[80]!==R?(z=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[L,R]}),t[79]=L,t[80]=R,t[81]=z):z=t[81];let B;t[82]!==a||t[83]!==c||t[84]!==s||t[85]!==h||t[86]!==l.inheritedMode||t[87]!==l.maxCallsLabel||t[88]!==l.modeAllow||t[89]!==l.modeConfirm||t[90]!==l.modeDeny||t[91]!==l.timeoutLabel||t[92]!==_||t[93]!==r||t[94]!==y?(B=(0,Z.jsx)(`div`,{className:`flex flex-col gap-5`,children:h.map(e=>{let{key:t,ids:n}=e;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:c(t)}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=s(e),n=r[e],i=n?n.mode:`inherit`;return(0,Z.jsxs)(`li`,{className:o(`rounded-xl px-3 py-2.5 shadow-surface transition-colors`,i===`inherit`?`bg-surface-panel/50`:`bg-surface-panel`),children:[(0,Z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-xs font-medium text-fg`,children:e}),t?(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:t}):null]}),(0,Z.jsx)(`div`,{className:`inline-flex w-fit rounded-lg border border-edge-subtle bg-surface-base p-0.5`,children:[`inherit`,`allow`,`confirm`,`deny`].map(t=>(0,Z.jsx)(`button`,{type:`button`,className:o(`rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,i===t?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:text-fg`),disabled:a,onClick:()=>_(e,t),children:t===`inherit`?l.inheritedMode:t===`allow`?l.modeAllow:t===`confirm`?l.modeConfirm:l.modeDeny},t))})]}),n?(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3 sm:grid-cols-2 dark:border-edge`,children:[(0,Z.jsx)(He,{label:l.maxCallsLabel,value:n.limits?.maxCallsPerTurn,disabled:a,onChange:t=>y(e,e=>Ve(e,`maxCallsPerTurn`,t))}),(0,Z.jsx)(He,{label:l.timeoutLabel,value:n.limits?.timeoutMs,disabled:a,onChange:t=>y(e,e=>Ve(e,`timeoutMs`,t))})]}):null]},e)})})]},t)})}),t[82]=a,t[83]=c,t[84]=s,t[85]=h,t[86]=l.inheritedMode,t[87]=l.maxCallsLabel,t[88]=l.modeAllow,t[89]=l.modeConfirm,t[90]=l.modeDeny,t[91]=l.timeoutLabel,t[92]=_,t[93]=r,t[94]=y,t[95]=B):B=t[95];let V;return t[96]!==I||t[97]!==z||t[98]!==B?(V=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[I,z,B]}),t[96]=I,t[97]=z,t[98]=B,t[99]=V):V=t[99],V}function Be(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function Ve(e,t,n){let r={...e.limits};if(n===void 0?delete r[t]:r[t]=n,Object.keys(r).length===0){let{limits:t,...n}=e;return n}return{...e,limits:r}}function He(e){let t=(0,Y.c)(9),n=e.value??``,r;t[0]===e?r=t[1]:(r=t=>{let n=t.target.value.trim();e.onChange(n?Number(n):void 0)},t[0]=e,t[1]=r);let i;t[2]!==e.disabled||t[3]!==n||t[4]!==r?(i=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:border-edge-strong focus:outline-none`,value:n,disabled:e.disabled,onChange:r}),t[2]=e.disabled,t[3]=n,t[4]=r,t[5]=i):i=t[5];let a;return t[6]!==e.label||t[7]!==i?(a=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[e.label,i]}),t[6]=e.label,t[7]=i,t[8]=a):a=t[8],a}var Ue=[`blank`,`safe-coder`,`read-only`,`low-cost`],We=[{id:`overview`,icon:A},{id:`models`,icon:z},{id:`tools`,icon:w},{id:`skills`,icon:W},{id:`advanced`,icon:R},{id:`impact`,icon:v}];function Ge(e){return ge(Object.entries(e?.models?.roles??{}).map(([e,t])=>({id:e,model:t.model,fallbacks:t.fallbacks??[],description:t.description})))}function Ke(e){return structuredClone(e?.tools?.builtin??{})}function qe(e){let t=e?.skills;if(!t)return new Set;let n=t.mode===`denylist`?t.deny:t.allow;return new Set(n??[])}function Je(){return{primary:``,fallbacks:[],timeoutMs:``,autoProviderFallback:``}}function Ye(e){return{primary:e?.primary??``,fallbacks:[...e?.fallbacks??[]],timeoutMs:e?.timeoutMs?String(e.timeoutMs):``,autoProviderFallback:e?.autoProviderFallback===void 0?``:e.autoProviderFallback?`true`:`false`}}function Xe(){return{imageModel:Je(),imageGenerationModel:Je(),allowFallbacks:``,maxCostTier:``}}function Ze(e){return{imageModel:Ye(e?.models?.imageModel),imageGenerationModel:Ye(e?.models?.imageGenerationModel),allowFallbacks:e?.models?.policy?.allowFallbacks===void 0?``:e.models.policy.allowFallbacks?`true`:`false`,maxCostTier:e?.models?.policy?.maxCostTier??``}}function Qe(e){return{mcp:structuredClone(e?.tools?.mcp),workflows:structuredClone(e?.workflows),boundaries:structuredClone(e?.boundaries),runtime:structuredClone(e?.runtime),locks:structuredClone(e?.locks)}}function $e(e){return{id:e?.id??``,name:e?.name??``,description:e?.description??``,modelRows:Ge(e),modelAdvanced:Ze(e),toolPolicies:Ke(e),skillMode:e?.skills?.mode??`inherit`,skillPick:qe(e),extendsIds:[...e?.extends??[]],advancedPolicy:Qe(e)}}function et(e,t){let n={id:e.id,name:e.name,version:1,usage:[],inherited:{},inheritedSources:{},...t};return{...e,modelRows:Ge(n),modelAdvanced:Ze(n),toolPolicies:Ke(n),skillMode:n.skills?.mode??`inherit`,skillPick:qe(n),extendsIds:[...n.extends??[]],advancedPolicy:Qe(n)}}function tt(e){let t=e.primary.trim();if(!t)return;let n=e.fallbacks.map(e=>e.trim()).filter(Boolean),r=e.timeoutMs.trim()?Number(e.timeoutMs):void 0,i=e.autoProviderFallback===``?void 0:e.autoProviderFallback===`true`;return{primary:t,...n.length>0?{fallbacks:n}:{},...r?{timeoutMs:r}:{},...i===void 0?{}:{autoProviderFallback:i}}}function nt(e,t){let n=_e(e.modelRows),r=tt(e.modelAdvanced.imageModel),i=tt(e.modelAdvanced.imageGenerationModel),a=e.modelAdvanced.allowFallbacks||e.modelAdvanced.maxCostTier?{...e.modelAdvanced.allowFallbacks?{allowFallbacks:e.modelAdvanced.allowFallbacks===`true`}:{},...e.modelAdvanced.maxCostTier?{maxCostTier:e.modelAdvanced.maxCostTier}:{}}:void 0,o={...t?.models?.defaultRole?{defaultRole:t.models.defaultRole}:{},...n?.roles?{roles:n.roles}:{},...r?{imageModel:r}:{},...i?{imageGenerationModel:i}:{},...a?{policy:a}:{}};return Object.keys(o).length>0?o:null}function rt(e){let t=Object.fromEntries(Object.entries(e.toolPolicies).toSorted(([e],[t])=>e.localeCompare(t))),n=e.advancedPolicy.mcp;return Object.keys(t).length>0||n?{builtin:t,...n?{mcp:n}:{}}:null}function it(e){return Object.fromEntries(Object.entries(e??{}).toSorted(([e],[t])=>e.localeCompare(t)))}function at(e){if(e.skillMode===`inherit`)return null;let t=[...e.skillPick].toSorted((e,t)=>e.localeCompare(t));return e.skillMode===`allowlist`?{mode:`allowlist`,allow:t}:e.skillMode===`denylist`?{mode:`denylist`,deny:t}:{mode:e.skillMode}}function ot(e,t){return{id:e.id.trim(),name:e.name.trim(),description:e.description.trim(),models:nt(e,t),tools:{builtin:it(e.toolPolicies),mcp:e.advancedPolicy.mcp},skills:at(e),extends:[...e.extendsIds].toSorted(),workflows:e.advancedPolicy.workflows,boundaries:e.advancedPolicy.boundaries,runtime:e.advancedPolicy.runtime,locks:e.advancedPolicy.locks}}function st(e){return e?{id:e.id,name:e.name,description:e.description??``,models:e.models??null,tools:{builtin:it(e.tools?.builtin),mcp:e.tools?.mcp},skills:e.skills??null,extends:[...e.extends??[]].toSorted(),workflows:e.workflows,boundaries:e.boundaries,runtime:e.runtime,locks:e.locks}:null}function ct(e,t){return[e.models?.roles?t.summaryModels.replace(`{{count}}`,String(Object.keys(e.models.roles).length)):``,e.tools?.builtin?t.summaryTools.replace(`{{count}}`,String(Object.keys(e.tools.builtin).length)):``,e.skills?t.summarySkills.replace(`{{mode}}`,t.skillModeLabels[e.skills.mode]):``].filter(Boolean).join(` · `)||t.summaryEmpty}function lt(e){return e===void 0?`—`:typeof e==`string`?e:JSON.stringify(e)}function ut(){return{modelAdvanced:Xe(),extendsIds:[],advancedPolicy:{}}}function dt(e,t){return{extends:[...e.extendsIds],models:nt(e,t)??void 0,tools:rt(e)??void 0,skills:at(e)??void 0,workflows:e.advancedPolicy.workflows,boundaries:e.advancedPolicy.boundaries,runtime:e.advancedPolicy.runtime,locks:e.advancedPolicy.locks}}function ft(e,t){return e===`safe-coder`?{id:`safe-coder`,name:t.starters[`safe-coder`].title,description:t.starters[`safe-coder`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`code`,model:``,fallbacks:[],description:t.modelRoleDescriptions.code},{id:`review`,model:``,fallbacks:[],description:t.modelRoleDescriptions.review}],toolPolicies:{exec_command:{mode:`deny`},send_message:{mode:`deny`},send_media:{mode:`deny`}},skillMode:`allowlist`,skillPick:new Set([`diagnose`,`tdd`]),...ut()}:e===`read-only`?{id:`read-only-research`,name:t.starters[`read-only`].title,description:t.starters[`read-only`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`fast`,model:``,fallbacks:[],description:t.modelRoleDescriptions.fast}],toolPolicies:{write_file:{mode:`deny`},apply_patch:{mode:`deny`},exec_command:{mode:`deny`},send_message:{mode:`deny`},send_media:{mode:`deny`}},skillMode:`all`,skillPick:new Set,...ut()}:e===`low-cost`?{id:`low-cost-assistant`,name:t.starters[`low-cost`].title,description:t.starters[`low-cost`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`fast`,model:``,fallbacks:[],description:t.modelRoleDescriptions.fast},{id:`cheap`,model:``,fallbacks:[],description:t.modelRoleDescriptions.cheap}],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...ut()}:{id:``,name:``,description:``,modelRows:[],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...ut()}}function pt(){let e=s(l(e=>e.language)),t=e.capabilityPresetsSettings,n=(0,Z.jsx)(H,{asChild:!0,type:`button`,variant:`secondary`,children:(0,Z.jsxs)(a,{to:`/agents`,children:[t.manageAgents,(0,Z.jsx)(h,{className:`size-4`,"aria-hidden":!0})]})}),r=!!c(e=>e.token),{data:f,error:g,isLoading:b,mutate:T}=u(r?`settings-capability-presets`:null,le,{revalidateOnFocus:!1}),{data:j=[],isLoading:M}=u(r?`settings-capability-presets-skills-catalog`:null,C,{revalidateOnFocus:!1}),P=f?.mcpServerIds??[],{data:B=[]}=u(r&&P.length?[`capability-preset-mcp-tools`,...P]:null,()=>fe(P),{revalidateOnFocus:!1}),[U,G]=i(),[te,ce]=(0,X.useState)(``),[pe,ge]=(0,X.useState)(`overview`),[q,J]=(0,X.useState)(()=>ft(`blank`,t)),[_e,Y]=(0,X.useState)(null),[Q,ve]=(0,X.useState)(!1),[be,xe]=(0,X.useState)(null),[Se,Ce]=(0,X.useState)(!1),[we,Te]=(0,X.useState)(null),[De,Oe]=(0,X.useState)(null),ke=f?.presets??[],Ae=f?.defaultPresetId??`default`,Me=ke.find(e=>e.id===Ae)??null,Ne=ke.filter(e=>e.id!==Ae),$=(0,X.useMemo)(()=>ke.find(e=>e.id===te)??ke[0]??null,[ke,te]),Pe=!$||q.id.trim()!==$.id,Fe=!!($&&$.id===Ae),Ie=JSON.stringify(ot(q,$))!==JSON.stringify(st($)),Le=ot(q,$),Re=st($),Be=[Le.id!==Re?.id||Le.name!==Re?.name||Le.description!==Re?.description?t.tabs.overview:``,JSON.stringify(Le.models)===JSON.stringify(Re?.models)?``:t.tabs.models,JSON.stringify(Le.tools)===JSON.stringify(Re?.tools)?``:t.tabs.tools,JSON.stringify(Le.skills)===JSON.stringify(Re?.skills)?``:t.tabs.skills,JSON.stringify({extends:Le.extends,workflows:Le.workflows,boundaries:Le.boundaries,runtime:Le.runtime,locks:Le.locks})===JSON.stringify({extends:Re?.extends,workflows:Re?.workflows,boundaries:Re?.boundaries,runtime:Re?.runtime,locks:Re?.locks})?``:t.tabs.advanced].filter(Boolean),Ve=(0,X.useMemo)(()=>{if(!$||Pe)return null;let e=dt(q,$);return{name:q.name.trim(),description:q.description.trim()||null,extends:e.extends??null,models:e.models??null,tools:e.tools??null,skills:e.skills??null,workflows:e.workflows??null,boundaries:e.boundaries??null,runtime:e.runtime??null,locks:e.locks??null}},[q,Pe,$]),{data:He,error:Ge,isLoading:Ke}=u(pe===`impact`&&$&&Ve?[`capability-preset-impact-preview`,$.id,JSON.stringify(Ve)]:null,()=>se($.id,Ve),{revalidateOnFocus:!1}),qe=be??(g instanceof Error?g.message:null),Je=U.get(`action`)===`new`||!!U.get(`preset`),Ye=U.get(`action`)===`new`&&_e===null,Xe=Pe?t.newPreset:$?.name??t.editorTitle,Ze=t=>e.agentsSettings.toolsDisableGroups[t],Qe=t=>t in e.agentsSettings.toolDescriptions?e.agentsSettings.toolDescriptions[t]:``;(0,X.useEffect)(()=>{if(!f||Q)return;if(U.get(`action`)===`new`){ce(``),J(ft(`blank`,t)),ge(`overview`);return}let e=U.get(`preset`)?.trim(),n=e?f.presets.find(t=>t.id===e):null;if(n){ce(n.id),J($e(n)),ge(U.get(`tab`)??`overview`);return}$&&(ce($.id),J(e=>e.id===$.id?e:$e($)))},[Q,f,U,$]);function tt(e){Y(null),ce(e.id),J($e(e)),G({preset:e.id},{replace:!0}),ge(`overview`)}function nt(){Y(null),ce(``),J(ft(`blank`,t)),xe(null),G({action:`new`},{replace:!0}),ge(`overview`)}function rt(e){Y(e),J(ft(e,t)),xe(null),ge(`overview`)}function it(){if(_e){let e=ft(_e,t);if(JSON.stringify(ot(q,null))!==JSON.stringify(ot(e,null))&&!window.confirm(t.changeTemplateConfirm))return}Y(null),xe(null)}function at(){!Ye&&Ie&&!window.confirm(t.discardConfirm)||(Ce(!1),Te(null),G({},{replace:!0}),Y(null),xe(null),J($e($)),ge(`overview`))}async function ut(){let e=he(q.modelRows,{invalidId:t.invalidModelRoleId,duplicateId:t.duplicateModelRoleId,invalidModel:t.invalidModelRef});if(e){xe(e),ge(`models`);return}for(let e of[q.modelAdvanced.imageModel,q.modelAdvanced.imageGenerationModel]){if([e.primary,...e.fallbacks].map(e=>e.trim()).filter(Boolean).some(e=>!/^[^/\s]+\/.+/.test(e))){xe(t.invalidModelRef),ge(`models`);return}if(e.timeoutMs.trim()&&(!Number.isInteger(Number(e.timeoutMs))||Number(e.timeoutMs)<=0)){xe(t.advancedPositiveIntegerError),ge(`models`);return}}for(let e of Object.values(q.toolPolicies))if([e.limits?.maxCallsPerTurn,e.limits?.timeoutMs].filter(e=>e!==void 0).some(e=>!Number.isInteger(e)||e<=0)){xe(t.advancedPositiveIntegerError),ge(`tools`);return}ve(!0),xe(null);try{let e=dt(q,$);if(Pe){let t=await me({id:q.id.trim(),name:q.name.trim(),...q.description.trim()?{description:q.description.trim()}:{},...e});await T(t.presets,{revalidate:!1}),ce(t.presetId),Y(null),G({preset:t.presetId},{replace:!0})}else $&&await T(await de($.id,{name:q.name.trim(),description:q.description.trim()||null,extends:e.extends??null,models:e.models??null,tools:e.tools??null,skills:e.skills??null,workflows:e.workflows??null,boundaries:e.boundaries??null,runtime:e.runtime??null,locks:e.locks??null}),{revalidate:!1})}catch(e){xe(e instanceof Error?e.message:t.saveError)}finally{ve(!1)}}async function pt(){if($){ve(!0),xe(null),Te(null);try{await T(await ue($.id),{revalidate:!1}),Ce(!1),ce(``),Y(null),J(ft(`blank`,t)),ge(`overview`),G({},{replace:!0})}catch(e){Te(e instanceof Error?e.message:t.deleteError)}finally{ve(!1)}}}return r?(0,Z.jsxs)(re,{gap:`gap-5`,className:`pb-24`,children:[(0,Z.jsx)(ne,{title:t.title,subtitle:t.subtitle,actions:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n,(0,Z.jsxs)(H,{type:`button`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(D,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]})}),qe?(0,Z.jsx)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:qe}):null,b?(0,Z.jsx)(ie,{sections:2}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[Me?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:z,title:t.globalDefaultsTitle,subtitle:t.globalDefaultsHint}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>tt(Me),className:`group rounded-lg bg-accent/5 px-4 py-3 text-left text-fg shadow-surface transition-colors hover:bg-accent/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:Me.name}),(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.globalDefaultsBadge})]}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:Me.id})]}),(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:t.globalDefaultsInherited})]}),Me.description?(0,Z.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:Me.description}):null,(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-fg-subtle`,children:ct(Me,t)})]})]}):null,(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:z,title:t.listTitle,subtitle:t.listHint}),Ne.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg bg-surface-panel/70 px-3 py-4 text-sm text-fg-muted shadow-surface`,children:[(0,Z.jsx)(`p`,{children:t.empty}),(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(D,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]}):(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:Ne.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>tt(e),className:`group min-h-36 rounded-lg bg-surface-panel/80 px-4 py-3 text-left text-fg shadow-surface transition-colors hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:e.id})]}),(0,Z.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:e.usage.length})]}),e.description?(0,Z.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:e.description}):null,(0,Z.jsx)(`div`,{className:`mt-3 truncate text-xs text-fg-subtle`,children:ct(e,t)})]},e.id))})]})]}),(0,Z.jsx)(_,{open:Je,onOpenChange:e=>{e||at()},children:(0,Z.jsxs)(p,{children:[(0,Z.jsx)(ee,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim`,I)}),(0,Z.jsx)(S,{ref:Oe,className:o(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(90vh,760px)] w-[min(100%-2rem,64rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,V),onOpenAutoFocus:e=>e.preventDefault(),children:(0,Z.jsxs)(d,{layer:`modal`,portalContainer:De,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[!Ye&&Pe&&_e?(0,Z.jsx)(`button`,{type:`button`,className:o(N,`shrink-0 p-1.5 hover:bg-surface-base`),onClick:it,"aria-label":t.changeTemplate,title:t.changeTemplate,children:(0,Z.jsx)(L,{className:`size-4`,"aria-hidden":!0})}):null,(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(O,{className:`truncate text-base font-semibold text-fg`,children:Xe}),(0,Z.jsx)(E,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:Ye?t.templatePickerSubtitle:Pe&&_e?`${t.editorHint} · ${t.basedOnTemplate.replace(`{{template}}`,t.starters[_e].title)}`:Pe?t.editorHint:q.id})]})]}),(0,Z.jsx)(y,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:o(N,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,Z.jsx)(m,{className:`size-4`,"aria-hidden":!0})})})]}),Ye?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 sm:p-5`,children:(0,Z.jsx)(`div`,{className:`mx-auto grid max-w-3xl gap-3 sm:grid-cols-2`,children:Ue.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`group min-h-32 rounded-xl border border-edge-subtle bg-surface-base px-4 py-4 text-left text-fg transition-colors hover:border-edge hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>rt(e),children:[(0,Z.jsxs)(`span`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t.starters[e].title}),e===`blank`?(0,Z.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[11px] font-medium text-accent-fg`,children:t.templateRecommended}):null]}),(0,Z.jsx)(`span`,{className:`mt-2 block text-xs leading-relaxed text-fg-muted`,children:t.starters[e].description})]},e))})}),(0,Z.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:(0,Z.jsx)(H,{type:`button`,variant:`secondary`,onClick:at,children:t.cancel})})]}):(0,Z.jsxs)(Z.Fragment,{children:[qe?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:qe}):null,(0,Z.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-2 border-b border-edge-subtle bg-surface-base px-4 py-2 dark:border-edge`,children:We.map(({id:e,icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,className:o(`inline-flex 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`,pe===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>ge(e),children:[(0,Z.jsx)(n,{className:`size-4`,"aria-hidden":!0}),t.tabs[e]]},e))}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:(0,Z.jsxs)(`div`,{className:`w-full`,children:[pe===`overview`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:A,title:t.overviewTitle,subtitle:t.overviewHint}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.idLabel}),(0,Z.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:q.id,disabled:Q||!Pe,onChange:e=>J(t=>({...t,id:e.target.value.toLowerCase()})),placeholder:`safe-coder`})]}),!Pe&&$?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.versionLabel}),(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg-muted`,children:t.versionAutomatic.replace(`{{version}}`,String($.version))})]}):null,(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.nameLabel}),(0,Z.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:q.name,disabled:Q,onChange:e=>J(t=>({...t,name:e.target.value})),placeholder:t.namePlaceholder})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.descriptionLabel}),(0,Z.jsx)(`textarea`,{className:`min-h-24 w-full resize-y rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:q.description,disabled:Q,onChange:e=>J(t=>({...t,description:e.target.value})),placeholder:t.descriptionPlaceholder})]})]}),(0,Z.jsxs)(`div`,{className:`mt-5 grid gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(mt,{icon:z,label:t.modelsTitle,value:String(q.modelRows.length)}),(0,Z.jsx)(mt,{icon:w,label:t.toolsTitle,value:String(Object.keys(q.toolPolicies).length)}),(0,Z.jsx)(mt,{icon:W,label:t.skillsTitle,value:t.skillModeLabels[q.skillMode]})]})]}):null,pe===`models`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:z,title:t.modelsTitle,subtitle:t.modelsHint}),(0,Z.jsx)(ye,{rows:q.modelRows,onChange:e=>J(t=>({...t,modelRows:e})),disabled:Q,defaultRole:$?.models?.defaultRole,chat:e.chat,labels:{defaultTitle:t.modelDefaultTitle,defaultHint:t.modelDefaultHint,defaultBadge:t.modelDefaultBadge,roleId:t.modelRoleIdLabel,description:t.modelRoleDescriptionLabel,descriptionPlaceholder:t.modelRoleDescriptionPlaceholder,primaryModel:t.modelPrimaryModelLabel,fallbackModels:t.modelFallbackModelsLabel,addFallback:t.modelAddFallback,removeFallback:t.modelRemoveFallback,fallbackPlaceholder:t.modelFallbackPlaceholder,fallbackEmptyHint:t.modelFallbackEmptyHint,moreSettings:t.modelMoreSettings,otherRolesTitle:t.modelOtherRolesTitle,otherRolesHint:t.modelOtherRolesHint,otherRolesEmpty:t.modelOtherRolesEmpty,addTaskModel:t.modelAddTaskModel,customRole:t.modelCustomRole,removeRole:t.removeModelRole,roleIdPlaceholder:`custom-role`,roleNames:t.modelRoleNames,roleDescriptions:t.modelRoleDescriptions}}),(0,Z.jsx)(ht,{value:q.modelAdvanced,onChange:e=>J(t=>({...t,modelAdvanced:e})),disabled:Q,cp:t,chat:e.chat})]}):null,pe===`tools`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:w,title:t.toolsTitle,subtitle:t.toolsHint}),(0,Z.jsx)(ze,{builtinToolIds:f?.builtinToolIds??[],toolPolicies:q.toolPolicies,onChange:e=>J(t=>({...t,toolPolicies:e})),disabled:Q,getToolDescription:Qe,getGroupTitle:Ze,labels:{quickActionsLabel:t.toolsQuickActionsLabel,quickClearOverrides:t.toolsQuickClearOverrides,quickReadOnlyWorkspace:t.toolsQuickReadOnlyWorkspace,quickHighRiskOff:t.toolsQuickHighRiskOff,quickNoOutbound:t.toolsQuickNoOutbound,quickResearchMode:t.toolsQuickResearchMode,quickCodingMode:t.toolsQuickCodingMode,emptyBuiltin:t.toolsEmptyBuiltin,overrideSummaryTitle:t.toolsOverrideSummaryTitle,noOverrides:t.toolsNoOverrides,inheritedMode:t.toolModes.inherit,modeAllow:t.toolModes.allow,modeConfirm:t.toolModes.confirm,modeDeny:t.toolModes.deny,maxCallsLabel:t.toolMaxCallsLabel,timeoutLabel:t.toolTimeoutLabel}})]}):null,pe===`skills`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:W,title:t.skillsTitle,subtitle:t.skillsHint}),(0,Z.jsx)(je,{mode:q.skillMode,selected:q.skillPick,catalog:j,loading:M,disabled:Q,onModeChange:e=>J(t=>({...t,skillMode:e})),onSelectedChange:e=>J(t=>({...t,skillPick:e})),labels:{modeLabel:t.skillsModeLabel,modeInherit:t.skillsModeInherit,modeAll:t.skillsModeAll,modeAllowlist:t.skillsModeAllowlist,modeDenylist:t.skillsModeDenylist,modeOff:t.skillsModeOff,quickActionsLabel:t.skillsQuickActionsLabel,quickSelectAll:t.skillsQuickSelectAll,quickClear:t.skillsQuickClear,catalogLoading:t.skillsCatalogLoading,emptyCatalog:t.skillsEmptyCatalog,noDescription:t.skillsNoDescription,overrideSummaryTitle:t.skillsOverrideSummaryTitle,inheritSummary:t.skillsInheritSummary,allSummary:t.skillsAllSummary,offSummary:t.skillsOffSummary,allowSummary:t.skillsAllowSummary,denySummary:t.skillsDenySummary}})]}):null,pe===`advanced`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:R,title:t.advancedTitle,subtitle:t.advancedHint}),(0,Z.jsx)(Ee,{extendsIds:q.extendsIds,onExtendsChange:e=>J(t=>({...t,extendsIds:e})),presetOptions:ke.filter(e=>e.id!==$?.id&&e.id!==Ae),inherited:JSON.stringify(q.extendsIds)===JSON.stringify($?.extends??[])?$?.inherited:void 0,inheritedSources:JSON.stringify(q.extendsIds)===JSON.stringify($?.extends??[])?$?.inheritedSources:void 0,mcpServerIds:f?.mcpServerIds??[],mcpTools:B,workflows:f?.workflows??[],policy:q.advancedPolicy,onPolicyChange:e=>J(t=>({...t,advancedPolicy:e})),rawPolicy:dt(q,$),onRawPolicyChange:e=>J(t=>et(t,e)),disabled:Q,labels:{inheritanceTitle:t.advancedInheritanceTitle,inheritanceHint:t.advancedInheritanceHint,inheritanceEmpty:t.advancedInheritanceEmpty,inheritanceAvailable:t.advancedInheritanceAvailable,inheritanceAdd:t.advancedInheritanceAdd,inheritanceRemove:t.advancedInheritanceRemove,inheritanceMoveUp:t.advancedInheritanceMoveUp,inheritanceMoveDown:t.advancedInheritanceMoveDown,compose:t.advancedCompose,inherit:t.advancedInherit,cancel:t.cancel,mcpTitle:t.advancedMcpTitle,mcpHint:t.advancedMcpHint,noMcp:t.advancedNoMcp,workflowsTitle:t.advancedWorkflowsTitle,workflowsHint:t.advancedWorkflowsHint,defaultWorkflow:t.advancedDefaultWorkflow,allowedWorkflows:t.advancedAllowedWorkflows,runtimeTitle:t.advancedRuntimeTitle,runtimeHint:t.advancedRuntimeHint,timeoutMinutes:t.advancedTimeoutMinutes,maxTurns:t.advancedMaxTurns,maxFailures:t.advancedMaxFailures,maxCalls:t.toolMaxCallsLabel,boundariesTitle:t.advancedBoundariesTitle,boundariesHint:t.advancedBoundariesHint,confirmRules:t.advancedConfirmRules,forbiddenRules:t.advancedForbiddenRules,escalationRules:t.advancedEscalationRules,onePerLine:t.advancedOnePerLine,governanceTitle:t.advancedGovernanceTitle,governanceHint:t.advancedGovernanceHint,locksLabel:t.advancedLocksLabel,rawTitle:t.advancedRawTitle,rawHint:t.advancedRawHint,rawOpen:t.advancedRawOpen,rawApply:t.advancedRawApply,rawInvalid:t.advancedRawInvalid,modeAllow:t.toolModes.allow,modeConfirm:t.toolModes.confirm,modeDeny:t.toolModes.deny,readonlyOnly:t.toolScopeReadonly}})]}):null,pe===`impact`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:v,title:t.usageTitle,subtitle:t.usageHint}),(0,Z.jsxs)(`div`,{className:`mb-4 rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:t.changePreviewTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:Be.length>0?t.changePreviewSections.replace(`{{sections}}`,Be.join(`、`)):t.changePreviewEmpty})]}),Pe?null:(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:t.effectiveChangePreviewTitle}),Ke?(0,Z.jsx)(ae,{rows:2}):Ge?(0,Z.jsx)(`p`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-red-600 shadow-surface dark:text-red-400`,children:t.effectiveChangePreviewError}):He?.agents.length?(0,Z.jsx)(`div`,{className:`grid gap-3`,children:He.agents.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,Z.jsx)(`div`,{className:`mt-2 grid gap-2`,children:e.diffs.map(e=>(0,Z.jsxs)(`div`,{className:`grid gap-1 text-xs sm:grid-cols-[minmax(0,12rem)_minmax(0,1fr)]`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-fg-muted`,children:e.path}),(0,Z.jsxs)(`div`,{className:`min-w-0 text-fg`,children:[(0,Z.jsx)(`span`,{className:`break-all text-fg-muted`,children:lt(e.before)}),(0,Z.jsx)(`span`,{className:`px-1.5 text-fg-subtle`,"aria-hidden":!0,children:`→`}),(0,Z.jsx)(`span`,{className:`break-all`,children:lt(e.after)})]})]},e.path))})]},e.agentId))}):(0,Z.jsx)(`p`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:t.effectiveChangePreviewEmpty})]}),$?.usage.length?(0,Z.jsx)(`div`,{className:`grid gap-2`,children:$.usage.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-muted`,children:e.agentId}),(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-fg-subtle`,children:e.direct?t.usageDirect:t.usageIndirect})]},e.agentId))}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUsage})]}):null]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3 border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-fg`,children:Ie?t.unsavedTitle:t.noUnsavedTitle}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:Ie?($?.usage.length??0)>0?t.unsavedImpact.replace(`{{count}}`,String($?.usage.length??0)):t.unsavedNoImpact:t.noUnsavedHint})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[Ie?(0,Z.jsx)(H,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>J($e($)),children:t.discard}):null,$&&!Fe?(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>{Te(null),Ce(!0)},children:[(0,Z.jsx)(k,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,Z.jsxs)(H,{type:`button`,disabled:Q||!q.id.trim()||!q.name.trim()||!Ie,onClick:()=>void ut(),children:[(0,Z.jsx)(F,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})]})})]})}),(0,Z.jsx)(_,{open:Se,onOpenChange:e=>{Q||(Ce(e),e||Te(null))},children:(0,Z.jsxs)(p,{children:[(0,Z.jsx)(ee,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim`,I)}),(0,Z.jsxs)(S,{className:o(`xopc-dialog-content fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2 overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,V),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsx)(O,{className:`text-base font-semibold text-fg`,children:t.deleteDialogTitle}),(0,Z.jsx)(E,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:$?t.deleteConfirm.replace(`{{name}}`,$.name):t.deleteConfirmFallback})]}),we?(0,Z.jsx)(`div`,{className:`mx-4 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:we}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-3`,children:[(0,Z.jsx)(H,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>Ce(!1),children:t.cancel}),(0,Z.jsxs)(H,{type:`button`,disabled:Q||!$,className:`bg-red-600 text-white shadow-surface hover:bg-red-700 focus-visible:ring-red-600 dark:bg-red-500 dark:hover:bg-red-600`,onClick:()=>void pt(),children:[Q?(0,Z.jsx)(x,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(k,{className:`size-4`,"aria-hidden":!0}),Q?t.deleting:t.delete]})]})]})]})})]}):(0,Z.jsxs)(re,{gap:`gap-3`,children:[(0,Z.jsx)(ne,{title:t.title,actions:n}),(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})]})}function mt(e){let t=(0,Y.c)(10),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.jsx)(n,{className:`size-3.5`,"aria-hidden":!0}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[a,r]}),t[2]=r,t[3]=a,t[4]=o):o=t[4];let s;t[5]===i?s=t[6]:(s=(0,Z.jsx)(`div`,{className:`mt-1 text-sm font-medium text-fg`,children:i}),t[5]=i,t[6]=s);let c;return t[7]!==o||t[8]!==s?(c=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function ht(e){let t=(0,Y.c)(121),{value:n,onChange:r,disabled:i,cp:a,chat:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},t[0]=s):s=t[0];let{data:c,isLoading:l,error:d}=u(`capability-preset-image-generation-models`,P,s),f;t[1]===c?f=t[2]:(f=(c??[]).filter(vt).flatMap(_t),t[1]=c,t[2]=f);let p=f,m;t[3]===p?m=t[4]:(m=new Set(p.map(gt)),t[3]=p,t[4]=m);let h=m,g,_;t[5]!==h||t[6]!==c||t[7]!==r||t[8]!==n?(g=()=>{if(!c)return;let e=n.imageGenerationModel,t=h.has(e.primary)?e.primary:``,i=e.fallbacks.filter(e=>h.has(e));t===e.primary&&i.length===e.fallbacks.length||r({...n,imageGenerationModel:{...e,primary:t,fallbacks:i}})},_=[h,c,r,n],t[5]=h,t[6]=c,t[7]=r,t[8]=n,t[9]=g,t[10]=_):(g=t[9],_=t[10]),(0,X.useEffect)(g,_);let v;t[11]!==r||t[12]!==n?(v=(e,t)=>{r({...n,[e]:t})},t[11]=r,t[12]=n,t[13]=v):v=t[13];let y=v,b;t[14]===a.modelSpecializedTitle?b=t[15]:(b=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelSpecializedTitle}),t[14]=a.modelSpecializedTitle,t[15]=b);let x;t[16]!==a.modelNotSet||t[17]!==a.modelSpecializedSummary||t[18]!==n.imageGenerationModel.primary||t[19]!==n.imageModel.primary?(x=a.modelSpecializedSummary.replace(`{{image}}`,n.imageModel.primary||a.modelNotSet).replace(`{{generation}}`,n.imageGenerationModel.primary||a.modelNotSet),t[16]=a.modelNotSet,t[17]=a.modelSpecializedSummary,t[18]=n.imageGenerationModel.primary,t[19]=n.imageModel.primary,t[20]=x):x=t[20];let S;t[21]===x?S=t[22]:(S=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:x}),t[21]=x,t[22]=S);let C;t[23]!==b||t[24]!==S?(C=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[b,S]}),t[23]=b,t[24]=S,t[25]=C):C=t[25];let w;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Z.jsx)(B,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[26]=w):w=t[26];let E;t[27]===C?E=t[28]:(E=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[C,w]}),t[27]=C,t[28]=E);let D;t[29]===y?D=t[30]:(D=e=>y(`imageModel`,e),t[29]=y,t[30]=D);let O;t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==D||t[35]!==n.imageModel?(O=(0,Z.jsx)(yt,{title:a.imageUnderstandingTitle,value:n.imageModel,onChange:D,disabled:i,cp:a,chat:o,capabilitiesFilter:`vision`}),t[31]=o,t[32]=a,t[33]=i,t[34]=D,t[35]=n.imageModel,t[36]=O):O=t[36];let k;t[37]===y?k=t[38]:(k=e=>y(`imageGenerationModel`,e),t[37]=y,t[38]=k);let A;t[39]===a.modelImageSettingsLink?A=t[40]:(A={label:a.modelImageSettingsLink,path:`/settings/capabilities/image`},t[39]=a.modelImageSettingsLink,t[40]=A);let j;t[41]!==o||t[42]!==a||t[43]!==i||t[44]!==p||t[45]!==d||t[46]!==l||t[47]!==k||t[48]!==A||t[49]!==n.imageGenerationModel?(j=(0,Z.jsx)(yt,{title:a.imageGenerationTitle,value:n.imageGenerationModel,onChange:k,disabled:i,cp:a,chat:o,models:p,modelsLoading:l,modelsError:d,noMatches:a.modelNoConfiguredImageModels,settingsFooterLink:A}),t[41]=o,t[42]=a,t[43]=i,t[44]=p,t[45]=d,t[46]=l,t[47]=k,t[48]=A,t[49]=n.imageGenerationModel,t[50]=j):j=t[50];let N;t[51]!==O||t[52]!==j?(N=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge lg:grid-cols-2`,children:[O,j]}),t[51]=O,t[52]=j,t[53]=N):N=t[53];let F;t[54]!==E||t[55]!==N?(F=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[E,N]}),t[54]=E,t[55]=N,t[56]=F):F=t[56];let I;t[57]===a.modelAdvancedTitle?I=t[58]:(I=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelAdvancedTitle}),t[57]=a.modelAdvancedTitle,t[58]=I);let L;t[59]===a.modelAdvancedHint?L=t[60]:(L=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:a.modelAdvancedHint}),t[59]=a.modelAdvancedHint,t[60]=L);let R;t[61]!==I||t[62]!==L?(R=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[I,L]}),t[61]=I,t[62]=L,t[63]=R):R=t[63];let z;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Z.jsx)(B,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[64]=z):z=t[64];let V;t[65]===R?V=t[66]:(V=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[R,z]}),t[65]=R,t[66]=V);let H;t[67]===a.modelAllowFallbacksLabel?H=t[68]:(H=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelAllowFallbacksLabel}),t[67]=a.modelAllowFallbacksLabel,t[68]=H);let U;t[69]!==r||t[70]!==n?(U=e=>r({...n,allowFallbacks:e.target.value}),t[69]=r,t[70]=n,t[71]=U):U=t[71];let W;t[72]===a.policyInherit?W=t[73]:(W=(0,Z.jsx)(T,{value:``,children:a.policyInherit}),t[72]=a.policyInherit,t[73]=W);let ee;t[74]===a.policyEnabled?ee=t[75]:(ee=(0,Z.jsx)(T,{value:`true`,children:a.policyEnabled}),t[74]=a.policyEnabled,t[75]=ee);let G;t[76]===a.policyDisabled?G=t[77]:(G=(0,Z.jsx)(T,{value:`false`,children:a.policyDisabled}),t[76]=a.policyDisabled,t[77]=G);let te;t[78]!==i||t[79]!==U||t[80]!==W||t[81]!==ee||t[82]!==G||t[83]!==n.allowFallbacks?(te=(0,Z.jsxs)(M,{value:n.allowFallbacks,disabled:i,side:`top`,onChange:U,children:[W,ee,G]}),t[78]=i,t[79]=U,t[80]=W,t[81]=ee,t[82]=G,t[83]=n.allowFallbacks,t[84]=te):te=t[84];let ne;t[85]!==H||t[86]!==te?(ne=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[H,te]}),t[85]=H,t[86]=te,t[87]=ne):ne=t[87];let re;t[88]===a.modelMaxCostTierLabel?re=t[89]:(re=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelMaxCostTierLabel}),t[88]=a.modelMaxCostTierLabel,t[89]=re);let ie;t[90]!==r||t[91]!==n?(ie=e=>r({...n,maxCostTier:e.target.value}),t[90]=r,t[91]=n,t[92]=ie):ie=t[92];let ae;t[93]===a.policyInherit?ae=t[94]:(ae=(0,Z.jsx)(T,{value:``,children:a.policyInherit}),t[93]=a.policyInherit,t[94]=ae);let K;t[95]===a.costTierLow?K=t[96]:(K=(0,Z.jsx)(T,{value:`low`,children:a.costTierLow}),t[95]=a.costTierLow,t[96]=K);let oe;t[97]===a.costTierMedium?oe=t[98]:(oe=(0,Z.jsx)(T,{value:`medium`,children:a.costTierMedium}),t[97]=a.costTierMedium,t[98]=oe);let se;t[99]===a.costTierHigh?se=t[100]:(se=(0,Z.jsx)(T,{value:`high`,children:a.costTierHigh}),t[99]=a.costTierHigh,t[100]=se);let ce;t[101]!==i||t[102]!==ie||t[103]!==ae||t[104]!==K||t[105]!==oe||t[106]!==se||t[107]!==n.maxCostTier?(ce=(0,Z.jsxs)(M,{value:n.maxCostTier,disabled:i,side:`top`,onChange:ie,children:[ae,K,oe,se]}),t[101]=i,t[102]=ie,t[103]=ae,t[104]=K,t[105]=oe,t[106]=se,t[107]=n.maxCostTier,t[108]=ce):ce=t[108];let le;t[109]!==re||t[110]!==ce?(le=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[re,ce]}),t[109]=re,t[110]=ce,t[111]=le):le=t[111];let ue;t[112]!==ne||t[113]!==le?(ue=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge sm:grid-cols-2`,children:[ne,le]}),t[112]=ne,t[113]=le,t[114]=ue):ue=t[114];let de;t[115]!==V||t[116]!==ue?(de=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[V,ue]}),t[115]=V,t[116]=ue,t[117]=de):de=t[117];let fe;return t[118]!==F||t[119]!==de?(fe=(0,Z.jsxs)(`div`,{className:`mt-5 grid gap-3 border-t border-edge-subtle pt-5 dark:border-edge`,children:[F,de]}),t[118]=F,t[119]=de,t[120]=fe):fe=t[120],fe}function gt(e){return e.id}function _t(e){return e.models.map(t=>({id:`${e.id}/${t}`,name:t,provider:e.label}))}function vt(e){return e.configured||e.credentialMode!==`api-key`}function yt(e){let t=(0,Y.c)(109),{title:n,value:r,onChange:i,disabled:a,cp:o,chat:s,capabilitiesFilter:c,models:l,modelsLoading:u,modelsError:d,noMatches:f,settingsFooterLink:p}=e,h;t[0]!==i||t[1]!==r?(h=(e,t)=>{i({...r,fallbacks:r.fallbacks.map((n,r)=>r===e?t:n)})},t[0]=i,t[1]=r,t[2]=h):h=t[2];let g=h,_;t[3]===n?_=t[4]:(_=(0,Z.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n}),t[3]=n,t[4]=_);let v=r.primary||o.modelNotSet,y;t[5]===v?y=t[6]:(y=(0,Z.jsx)(`span`,{className:`max-w-48 truncate font-mono text-xs text-fg-muted`,children:v}),t[5]=v,t[6]=y);let x;t[7]!==_||t[8]!==y?(x=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2.5`,children:[_,y]}),t[7]=_,t[8]=y,t[9]=x):x=t[9];let S;t[10]===o.modelToolPrimaryLabel?S=t[11]:(S=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolPrimaryLabel}),t[10]=o.modelToolPrimaryLabel,t[11]=S);let C=f??s.modelNoMatches,w;t[12]!==i||t[13]!==r?(w=e=>i({...r,primary:e}),t[12]=i,t[13]=r,t[14]=w):w=t[14];let E;t[15]!==c||t[16]!==s.modelPlaceholder||t[17]!==s.modelSearchPlaceholder||t[18]!==a||t[19]!==l||t[20]!==d||t[21]!==u||t[22]!==p||t[23]!==C||t[24]!==w||t[25]!==r.primary?(E=(0,Z.jsx)(b,{value:r.primary,disabled:a,placeholder:s.modelPlaceholder,searchPlaceholder:s.modelSearchPlaceholder,noMatches:C,models:l,modelsLoading:u,modelsError:d,settingsFooterLink:p,capabilitiesFilter:c,className:`w-full max-w-none`,contentAlign:`start`,onChange:w}),t[15]=c,t[16]=s.modelPlaceholder,t[17]=s.modelSearchPlaceholder,t[18]=a,t[19]=l,t[20]=d,t[21]=u,t[22]=p,t[23]=C,t[24]=w,t[25]=r.primary,t[26]=E):E=t[26];let O;t[27]!==o.modelClearSelection||t[28]!==a||t[29]!==i||t[30]!==r?(O=r.primary?(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelClearSelection,onClick:()=>i({...r,primary:``}),children:(0,Z.jsx)(m,{className:`size-4`,strokeWidth:1.75})}):null,t[27]=o.modelClearSelection,t[28]=a,t[29]=i,t[30]=r,t[31]=O):O=t[31];let A;t[32]!==E||t[33]!==O?(A=(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[E,O]}),t[32]=E,t[33]=O,t[34]=A):A=t[34];let j;t[35]!==A||t[36]!==S?(j=(0,Z.jsxs)(`div`,{className:`grid gap-1`,children:[S,A]}),t[35]=A,t[36]=S,t[37]=j):j=t[37];let N;t[38]===o.modelToolFallbacksLabel?N=t[39]:(N=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolFallbacksLabel}),t[38]=o.modelToolFallbacksLabel,t[39]=N);let P;t[40]!==i||t[41]!==r?(P=()=>i({...r,fallbacks:[...r.fallbacks,``]}),t[40]=i,t[41]=r,t[42]=P):P=t[42];let F;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,Z.jsx)(D,{className:`size-3.5`,strokeWidth:1.75}),t[43]=F):F=t[43];let I;t[44]!==o.modelAddFallback||t[45]!==a||t[46]!==P?(I=(0,Z.jsxs)(H,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:a,onClick:P,children:[F,o.modelAddFallback]}),t[44]=o.modelAddFallback,t[45]=a,t[46]=P,t[47]=I):I=t[47];let L;t[48]!==N||t[49]!==I?(L=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[N,I]}),t[48]=N,t[49]=I,t[50]=L):L=t[50];let R;t[51]!==c||t[52]!==s.modelNoMatches||t[53]!==s.modelSearchPlaceholder||t[54]!==o.modelFallbackEmptyHint||t[55]!==o.modelFallbackPlaceholder||t[56]!==o.modelRemoveFallback||t[57]!==a||t[58]!==l||t[59]!==d||t[60]!==u||t[61]!==f||t[62]!==i||t[63]!==p||t[64]!==g||t[65]!==r?(R=r.fallbacks.length>0?(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:r.fallbacks.map((e,t)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,Z.jsx)(b,{value:e,disabled:a,placeholder:o.modelFallbackPlaceholder,searchPlaceholder:s.modelSearchPlaceholder,noMatches:f??s.modelNoMatches,models:l,modelsLoading:u,modelsError:d,settingsFooterLink:p,capabilitiesFilter:c,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>g(t,e)}),(0,Z.jsx)(H,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelRemoveFallback,onClick:()=>i({...r,fallbacks:r.fallbacks.filter((e,n)=>n!==t)}),children:(0,Z.jsx)(k,{className:`size-4`,strokeWidth:1.75})})]},`fallback-${t}`))}):(0,Z.jsx)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 text-xs text-fg-muted`,children:o.modelFallbackEmptyHint}),t[51]=c,t[52]=s.modelNoMatches,t[53]=s.modelSearchPlaceholder,t[54]=o.modelFallbackEmptyHint,t[55]=o.modelFallbackPlaceholder,t[56]=o.modelRemoveFallback,t[57]=a,t[58]=l,t[59]=d,t[60]=u,t[61]=f,t[62]=i,t[63]=p,t[64]=g,t[65]=r,t[66]=R):R=t[66];let z;t[67]!==L||t[68]!==R?(z=(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[L,R]}),t[67]=L,t[68]=R,t[69]=z):z=t[69];let B;t[70]!==i||t[71]!==r?(B=e=>i({...r,timeoutMs:e.target.value}),t[70]=i,t[71]=r,t[72]=B):B=t[72];let V;t[73]!==a||t[74]!==B||t[75]!==r.timeoutMs?(V=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:r.timeoutMs,disabled:a,onChange:B}),t[73]=a,t[74]=B,t[75]=r.timeoutMs,t[76]=V):V=t[76];let U;t[77]!==o.toolTimeoutLabel||t[78]!==V?(U=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.toolTimeoutLabel,V]}),t[77]=o.toolTimeoutLabel,t[78]=V,t[79]=U):U=t[79];let W;t[80]!==i||t[81]!==r?(W=e=>i({...r,autoProviderFallback:e.target.value}),t[80]=i,t[81]=r,t[82]=W):W=t[82];let ee;t[83]===o.policyInherit?ee=t[84]:(ee=(0,Z.jsx)(T,{value:``,children:o.policyInherit}),t[83]=o.policyInherit,t[84]=ee);let G;t[85]===o.policyEnabled?G=t[86]:(G=(0,Z.jsx)(T,{value:`true`,children:o.policyEnabled}),t[85]=o.policyEnabled,t[86]=G);let te;t[87]===o.policyDisabled?te=t[88]:(te=(0,Z.jsx)(T,{value:`false`,children:o.policyDisabled}),t[87]=o.policyDisabled,t[88]=te);let ne;t[89]!==a||t[90]!==W||t[91]!==ee||t[92]!==G||t[93]!==te||t[94]!==r.autoProviderFallback?(ne=(0,Z.jsxs)(M,{value:r.autoProviderFallback,disabled:a,side:`top`,onChange:W,children:[ee,G,te]}),t[89]=a,t[90]=W,t[91]=ee,t[92]=G,t[93]=te,t[94]=r.autoProviderFallback,t[95]=ne):ne=t[95];let re;t[96]!==o.modelAutoProviderFallbackLabel||t[97]!==ne?(re=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.modelAutoProviderFallbackLabel,ne]}),t[96]=o.modelAutoProviderFallbackLabel,t[97]=ne,t[98]=re):re=t[98];let ie;t[99]!==U||t[100]!==re?(ie=(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[U,re]}),t[99]=U,t[100]=re,t[101]=ie):ie=t[101];let ae;t[102]!==j||t[103]!==z||t[104]!==ie?(ae=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-3 dark:border-edge`,children:[j,z,ie]}),t[102]=j,t[103]=z,t[104]=ie,t[105]=ae):ae=t[105];let K;return t[106]!==ae||t[107]!==x?(K=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 shadow-surface`,children:[x,ae]}),t[106]=ae,t[107]=x,t[108]=K):K=t[108],K}export{pt as CapabilityPresetsSettingsPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{t as o}from"./cn-JdwAhgNB.js";import{t as s}from"./messages-DQ5X6cXp.js";import{l as c,n as l,o as u,r as d,s as f}from"./locale-store-Bjvw7jtg.js";import{i as p}from"./vendor-swr-BIWyz7Rc.js";import{$o as m,Bo as h,Bs as g,Ds as _,Fo as v,Io as y,Ir as b,Kc as x,Ll as S,Lo as C,Lr as w,Ma as T,Na as E,Pa as D,Ro as O,Rr as k,Ua as A,Vo as j,Xo as M,Ys as N,_r as P,_s as F,cc as I,cu as L,dt as R,is as ee,mc as te,rs as z,uu as B,vc as ne,ws as V,zi as re,zo as ie}from"./index-BzPwnXho.js";import{n as ae,r as oe}from"./settings-page-layout-CTMmZcwj.js";import{n as se}from"./settings-loading-skeleton-BS36Mjzz.js";import{t as ce}from"./schema-form-BI4rVt3u.js";import{t as le}from"./browser-BLJWD7WI.js";import{n as ue,t as de}from"./channels-status-swr-DPaJSYX_.js";var H=e(t(),1),U=n();function fe(e){let t=e.actions??{};for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n?.result===`qr`)return[e,n]}let n=Object.entries(t).find(([,e])=>e.result===`qr`);if(n)return n;let r=e.ui?.card?.primaryAction;if(r&&t[r])return[r,t[r]];for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n)return[e,n]}return Object.entries(t).find(([,e])=>e.result===`form`)??null}var pe=e(le(),1),W=r();async function me(e){let t=await u(d(`/api/channels/${encodeURIComponent(e.channelId)}/actions/${encodeURIComponent(e.actionId)}?locale=${encodeURIComponent(e.locale)}`),{method:`POST`,body:JSON.stringify({...e.accountId?{accountId:e.accountId}:{},...e.input===void 0?{}:{input:e.input}})}),n=await t.json().catch(()=>({}));if(!t.ok||n.ok===!1)throw Error(n.error?.message??t.statusText);return n.payload??{type:`ok`}}function G(e){return e?.type===`poll`&&e.phase===`done`}function K(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function q(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function J(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function he({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,H.useMemo)(()=>fe(e),[e]),s=(0,H.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[c,l]=(0,H.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,H.useEffect)(()=>{l({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let u=(0,H.useCallback)(async(n,i)=>{l(e=>({...e,busy:!0,error:null}));try{let a=await me({channelId:e.id,actionId:n,locale:t,input:i});l(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){l(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,H.useEffect)(()=>{let t=q(c.payload,e.id);if(!t){l(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return l(e=>e.generatedQr?{...e,generatedQr:null}:e),pe.toDataURL(t,{width:220,margin:1}).then(e=>{n||l(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,c.payload]),(0,H.useEffect)(()=>{let n=c.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||me({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(l(t=>({...t,payload:e,poll:G(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),G(e)&&window.clearInterval(a))}).catch(e=>{i||l(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,c.poll]);let d=a?.[1].label??(e.configured?n.reconnect:n.connect),f=e.actions?.[`doctor.run`]?.label??n.diagnose,p=K(c.payload),m=q(c.payload,e.id),h=m?c.generatedQr:J(c.payload),g=a?.[1].result===`qr`&&(c.busy||c.payload?.type===`qr`||c.payload?.type===`poll`),_=c.payload?.type===`form`?c.payload:null,v=c.payload?.type===`diagnostics`?c.payload.checks:null;return(0,W.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:o(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,W.jsxs)(V,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(a[0]),children:[c.busy?(0,W.jsx)(x,{className:`size-4 animate-spin`}):(0,W.jsx)(ne,{className:`size-4`}),d]}):null,e.actions?.[`doctor.run`]?(0,W.jsxs)(V,{type:`button`,variant:`secondary`,disabled:c.busy,onClick:()=>void u(`doctor.run`),children:[(0,W.jsx)(N,{className:`size-4`}),f]}):null]})]}),p?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:p}):null,c.error?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:c.error}):null,g?(0,W.jsxs)(`div`,{className:o(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base p-3 shadow-surface`,i?`mt-1 flex-col text-center sm:h-64 sm:flex-row sm:text-left`:`mt-4 flex-col sm:h-64 sm:flex-row`),children:[(0,W.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:h?(0,W.jsx)(`img`,{src:h,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,W.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,W.jsx)(E,{className:`size-48 rounded-md`})})}),(0,W.jsxs)(`div`,{className:o(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[h?(0,W.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,W.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,W.jsx)(E,{className:`h-4 w-48 max-w-full`}),(0,W.jsx)(E,{className:`h-4 w-36 max-w-full`})]}),m?(0,W.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:m,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,W.jsx)(S,{className:`size-3.5`})]}):null]})]}):null,c.payload?.type===`poll`&&c.payload.phase===`done`?(0,W.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg bg-surface-base px-3 py-2 text-sm shadow-surface`,children:[(0,W.jsx)(L,{className:c.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,W.jsx)(`span`,{className:c.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:c.payload.message??(c.payload.ok?n.complete:n.failed)})]}):null,_?(0,W.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,W.jsx)(ce,{schema:_.schema,values:c.formDraft,onChange:e=>l(t=>({...t,formDraft:e})),disabled:c.busy,labels:s}),(0,W.jsx)(V,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(_.submitAction,c.formDraft),children:n.saveSetup})]}):null,v?(0,W.jsx)(`div`,{className:`mt-4 space-y-2`,children:v.map((e,t)=>(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e.status??`unknown`})]}),e.message?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var ge=40;function Y(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function _e(e,t){return e.find(e=>e.id===Y(t))?.agentId?.trim().toLowerCase()??``}function ve(e,t,n){let r=Y(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:ge,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function ye(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function be(e,t,n){let r=ye(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function xe(e,t=!1){return e===`drawer`?o(`xopc-drawer-right fixed right-0 top-0 flex size-full flex-col overflow-hidden border-l border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`,t?`max-w-[36rem]`:`max-w-xl`,z):o(`fixed left-1/2 top-1/2 flex h-[min(calc(100dvh-2rem),52rem)] w-[min(calc(100%-2rem),32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,t&&`h-[min(calc(100dvh-2rem),48rem)] w-[min(calc(100%-2rem),36rem)]`,z,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Se(e){let t=(0,U.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:f,wide:p,headerExtra:g}=e,b=p===void 0?!1:p,x=n===`drawer`,[S,w]=(0,H.useState)(null),T;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,W.jsx)(ie,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),t[0]=T):T=t[0];let E;t[1]!==n||t[2]!==b?(E=xe(n,b),t[1]=n,t[2]=b,t[3]=E):E=t[3];let D;t[4]===c?D=t[5]:(D=c?(0,W.jsx)(j,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=D);let k;t[6]===l?k=t[7]:(k=l?(0,W.jsx)(O,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=k);let A;t[8]!==u||t[9]!==s||t[10]!==g||t[11]!==x||t[12]!==a?(A=x?(0,W.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,W.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,s?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,W.jsx)(y,{asChild:!0,children:(0,W.jsx)(V,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,W.jsx)(_,{className:`size-5`,strokeWidth:1.75})})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(y,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:o(F,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,W.jsx)(_,{className:`size-4`})})}),g]}),t[8]=u,t[9]=s,t[10]=g,t[11]=x,t[12]=a,t[13]=A):A=t[13];let M=x?`p-4`:`p-6`,N;t[14]===M?N=t[15]:(N=o(`min-h-0 flex-1 overflow-y-auto`,M),t[14]=M,t[15]=N);let P;t[16]!==d||t[17]!==N?(P=(0,W.jsx)(`div`,{className:N,children:d}),t[16]=d,t[17]=N,t[18]=P):P=t[18];let I;t[19]!==f||t[20]!==S||t[21]!==D||t[22]!==k||t[23]!==A||t[24]!==P?(I=(0,W.jsxs)(m,{layer:`modal`,portalContainer:S,children:[D,k,A,P,f]}),t[19]=f,t[20]=S,t[21]=D,t[22]=k,t[23]=A,t[24]=P,t[25]=I):I=t[25];let L;t[26]!==I||t[27]!==E?(L=(0,W.jsxs)(h,{children:[T,(0,W.jsx)(C,{ref:w,className:E,onOpenAutoFocus:Ce,children:I})]}),t[26]=I,t[27]=E,t[28]=L):L=t[28];let R;return t[29]!==i||t[30]!==r||t[31]!==L?(R=(0,W.jsx)(v,{open:r,onOpenChange:i,children:L}),t[29]=i,t[30]=r,t[31]=L,t[32]=R):R=t[32],R}function Ce(e){return e.preventDefault()}var we=(0,H.memo)(function(e){let t=(0,U.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,W.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,t[0]=n.saved,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==n.refresh||t[4]!==a||t[5]!==r?(s=(0,W.jsx)(re,{className:`size-9 shrink-0 p-0`,loading:r,label:n.refresh,onClick:a}),t[3]=n.refresh,t[4]=a,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==o||t[8]!==s?(c=(0,W.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-end gap-2`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c});function Te(e){let t=(0,U.c)(24),{ch:n,dirty:r,saving:i,onCancel:a,onDiscard:o,onSave:s,showCancel:c}=e,l=c===void 0?!0:c,u;t[0]!==n.unsavedHint||t[1]!==r?(u=r?(0,W.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,t[0]=n.unsavedHint,t[1]=r,t[2]=u):u=t[2];let d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,W.jsx)(V,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,p;t[7]!==n.discard||t[8]!==o||t[9]!==f?(p=(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=p):p=t[10];let m=!r||i,h;t[11]===s?h=t[12]:(h=()=>void s(),t[11]=s,t[12]=h);let g=i?n.saving:n.save,_;t[13]!==m||t[14]!==h||t[15]!==g?(_=(0,W.jsx)(V,{type:`button`,variant:`primary`,disabled:m,onClick:h,children:g}),t[13]=m,t[14]=h,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==p||t[19]!==_?(v=(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,p,_]}),t[17]=d,t[18]=p,t[19]=_,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==u?(y=(0,W.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}function Ee(e){return d(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function De(e){return(await f(Ee(e))).payload?.channels??[]}function Oe(e,t){let n=(0,U.c)(14),r;n[0]!==e||n[1]!==t?(r=e?Ee(t):null,n[0]=e,n[1]=t,n[2]=r):r=n[2];let i;n[3]===t?i=n[4]:(i=()=>De(t),n[3]=t,n[4]=i);let a;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(a={revalidateOnFocus:!1},n[5]=a):a=n[5];let{data:o,error:s,isLoading:c,isValidating:l,mutate:u}=p(r,i,a),d;n[6]===o?d=n[7]:(d=o??[],n[6]=o,n[7]=d);let f;return n[8]!==s||n[9]!==c||n[10]!==l||n[11]!==u||n[12]!==d?(f={entries:d,isLoading:c,isValidating:l,error:s,mutate:u},n[8]=s,n[9]=c,n[10]=l,n[11]=u,n[12]=d,n[13]=f):f=n[13],f}var ke=`channels-status`;function Ae(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function je(e){let t=t=>e(t.detail);return window.addEventListener(ke,t),()=>window.removeEventListener(ke,t)}function Me(e,t){let n=(0,U.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return je(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,H.useEffect)(i,a)}function Ne(e){return e?d(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Pe(e){return(await f(d(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Fe=[`enabled`];async function Ie(){let e=await f(d(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Le(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Re(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function X(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function ze(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function Be(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Ve(e){return e===`running`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:e===`stopped`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`checking`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:e===`disabled`?`bg-surface-hover text-fg-muted`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`}function He(e){if(!e)return[];let t=e.uiHints??{},n=Z(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=X(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!Z(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Fe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Fe.includes(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ue(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function We(e,t){let n={...Ue(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!Z(r)||!Z(r[n]))break;let o=Z(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Ue(r[n]),properties:{}}),e===t.length-1){o[n]=Ue(r[n]);break}i=r[n],a=o[n]}}return n}function Ge(e){let t=e.properties;if(!Z(t))return!1;for(let[e,n]of Object.entries(t))Z(n)&&n.type===`object`&&Ge(n)&&delete t[e];return Object.keys(t).length===0}function Ke(e,t){let n=Ue(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!Z(i))break;if(e===t.length-1){delete i[n];break}if(!Z(i[n]))break;r=i[n]}}return Ge(n),n}function qe(e){return e.type===`object`&&Z(e.properties)&&Object.keys(e.properties).length>0}function Je(e,t){let n=e;for(let e of t.split(`.`)){if(!Z(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return Z(t)?Object.values(t).filter(e=>Z(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Q(e,t,n){return t==null||t===``?null:e.toLowerCase().includes(`dmpolicy`)&&typeof t==`string`?`${n.dmPolicy}: ${n.policy.dm[t]??t}`:(e.toLowerCase().includes(`stream`)||e.toLowerCase().includes(`streaming`))&&typeof t==`string`?`${n.cardStream}: ${n.policy.stream[t]??t}`:typeof t==`boolean`?t?n.enabledLabel:n.disabledLabel:String(t)}function Xe(e,t,n){let r=[],i=X(e);if(i.issues.length>0&&r.push(et(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Q(e,Je(t,e),n);i&&r.push(i)}let a=Ye(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Ze(e,t){let n=X(e),r=fe(e);return n.state===`needs_setup`?r?.[1].label??t.completeSetup:!n.enabled&&n.ready?t.enableChannel:n.state===`error`?t.diagnose:n.ready?t.manageChannel:r?.[1].label??t.startConfiguration}function Qe(e,t){let n=fe(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function $e(e,t){let n=e.capabilities??{},r=[];return n.login===!0&&r.push(t.cardCapabilityLogin),n.pairing===!0&&r.push(t.cardCapabilityPairing),n.multiAccount===!0&&r.push(t.cardCapabilityMultiAccount),n.streaming===!0&&r.push(t.cardCapabilityStreaming),n.media===!0&&r.push(t.cardCapabilityMedia),n.doctor===!0&&r.push(t.cardCapabilityDoctor),r.slice(0,3)}function et(e,t){return e.code===`telegram.missing_credential`?t.setupIssueTelegramMissingCredential:e.code===`weixin.missing_account`?t.setupIssueWeixinMissingAccount:e.code===`feishu.missing_credentials`?t.setupIssueFeishuMissingCredentials:e.code===`config.missing_required`&&e.fieldPath?t.setupIssueMissingRequired.replace(`{{field}}`,e.fieldPath):e.message}function tt({entry:e}){let t=c(e=>e.token),[n,r]=(0,H.useState)(!1),i=(0,H.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(d(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Le(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,W.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,W.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,W.jsx)(D,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,U.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,s;t[0]===i?s=t[1]:(s=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=s);let c=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,l=r&&`cursor-not-allowed opacity-60`,u;t[2]!==c||t[3]!==l?(u=o(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,c,l),t[2]=c,t[3]=l,t[4]=u):u=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=o(`size-5 rounded-full bg-white shadow-surface transition-transform`,d),t[5]=d,t[6]=f);let p;t[7]===f?p=t[8]:(p=(0,W.jsx)(`span`,{className:f}),t[7]=f,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==s||t[13]!==u||t[14]!==p?(m=(0,W.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:s,className:u,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=s,t[13]=u,t[14]=p,t[15]=m):m=t[15],m}function rt(e){let t=(0,U.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:s,ch:c,onOpen:l,onToggle:u,onRestart:d}=e,f;t[0]===n?f=t[1]:(f=X(n),t[0]=n,t[1]=f);let p=f,m,h,g,_,v,y,b;if(t[2]!==a||t[3]!==c||t[4]!==r||t[5]!==n||t[6]!==l||t[7]!==d||t[8]!==u||t[9]!==i||t[10]!==p.enabled||t[11]!==p.ready){let e=Xe(n,r,c),s=$e(n,c);m=!p.enabled&&p.ready?u:i===`stopped`?d:l,y=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let f;t[19]===n?f=t[20]:(f=(0,W.jsx)(tt,{entry:n}),t[19]=n,t[20]=f);let x;t[21]===n.label?x=t[22]:(x=(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=x);let S;t[23]===i?S=t[24]:(S=o(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Ve(i)),t[23]=i,t[24]=S);let C;t[25]!==c||t[26]!==i?(C=ze(i,c),t[25]=c,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==S||t[29]!==C?(w=(0,W.jsx)(`span`,{className:S,children:C}),t[28]=S,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==x?(T=(0,W.jsxs)(`div`,{className:`min-w-0`,children:[x,w]}),t[31]=w,t[32]=x,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==f?(E=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[f,T]}),t[34]=T,t[35]=f,t[36]=E):E=t[36];let D=p.enabled,O;t[37]!==c.toggleChannel||t[38]!==n.label?(O=c.toggleChannel.replace(`{{channel}}`,n.label),t[37]=c.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==u||t[42]!==p.enabled||t[43]!==O?(k=(0,W.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:u}),t[40]=a,t[41]=u,t[42]=p.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(b=(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=b):b=t[47],h=`button`,g=l,_=`mt-5 min-h-[6.25rem] text-left`,v=p.ready?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,W.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map($)}):null]}):(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:c.cardSetupTitle}),(0,W.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Qe(n,c)}),s.length>0?(0,W.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:s.map(it)}):null]}),t[2]=a,t[3]=c,t[4]=r,t[5]=n,t[6]=l,t[7]=d,t[8]=u,t[9]=i,t[10]=p.enabled,t[11]=p.ready,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b}else m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18];let S;t[48]!==h||t[49]!==g||t[50]!==_||t[51]!==v?(S=(0,W.jsx)(`button`,{type:h,onClick:g,className:_,children:v}),t[48]=h,t[49]=g,t[50]=_,t[51]=v,t[52]=S):S=t[52];let C=a||s,w;t[53]!==a||t[54]!==s?(w=a||s?(0,W.jsx)(x,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=s,t[55]=w):w=t[55];let T;t[56]!==c||t[57]!==n||t[58]!==s||t[59]!==i?(T=s?c.restartingChannel:i===`stopped`?c.restartChannel:Ze(n,c),t[56]=c,t[57]=n,t[58]=s,t[59]=i,t[60]=T):T=t[60];let E;t[61]!==m||t[62]!==w||t[63]!==T||t[64]!==C?(E=(0,W.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:m,disabled:C,children:[w,T]})}),t[61]=m,t[62]=w,t[63]=T,t[64]=C,t[65]=E):E=t[65];let D;return t[66]!==E||t[67]!==y||t[68]!==b||t[69]!==S?(D=(0,W.jsxs)(`article`,{className:y,children:[b,S,E]}),t[66]=E,t[67]=y,t[68]=b,t[69]=S,t[70]=D):D=t[70],D}function it(e){return(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function $(e){return(0,W.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function at(e){let t=(0,U.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:s,ch:c,onRestart:l,onCheck:u,onManageConnection:d}=e,f=n===`running`?L:n===`stopped`||n===`needs_setup`?B:x,p=n===`running`&&`text-emerald-600 dark:text-emerald-400`,m=n===`stopped`&&`text-red-600 dark:text-red-400`,h=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,g=n===`disabled`&&`text-fg-muted`,_=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,v;t[0]!==p||t[1]!==m||t[2]!==h||t[3]!==g||t[4]!==_?(v=o(`mt-0.5 size-5 shrink-0`,p,m,h,g,_),t[0]=p,t[1]=m,t[2]=h,t[3]=g,t[4]=_,t[5]=v):v=t[5];let y;t[6]!==f||t[7]!==v?(y=(0,W.jsx)(f,{className:v}),t[6]=f,t[7]=v,t[8]=y):y=t[8];let b;t[9]===c.connectionStatus?b=t[10]:(b=(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:c.connectionStatus}),t[9]=c.connectionStatus,t[10]=b);let S;t[11]!==c||t[12]!==n?(S=Be(n,c),t[11]=c,t[12]=n,t[13]=S):S=t[13];let C;t[14]===S?C=t[15]:(C=(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:S}),t[14]=S,t[15]=C);let w;t[16]!==C||t[17]!==b?(w=(0,W.jsxs)(`div`,{children:[b,C]}),t[16]=C,t[17]=b,t[18]=w):w=t[18];let T;t[19]!==w||t[20]!==y?(T=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[y,w]}),t[19]=w,t[20]=y,t[21]=T):T=t[21];let E=i||r,D;t[22]===i?D=t[23]:(D=i?(0,W.jsx)(x,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=D);let O=i?c.checkingConnection:c.checkConnection,k;t[24]!==u||t[25]!==E||t[26]!==D||t[27]!==O?(k=(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:E,onClick:u,children:[D,O]}),t[24]=u,t[25]=E,t[26]=D,t[27]=O,t[28]=k):k=t[28];let A;t[29]!==c.restartChannel||t[30]!==c.restartingChannel||t[31]!==i||t[32]!==l||t[33]!==r||t[34]!==n?(A=n===`stopped`?(0,W.jsxs)(V,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:l,children:[r?(0,W.jsx)(x,{className:`size-4 animate-spin`}):(0,W.jsx)(te,{className:`size-4`}),r?c.restartingChannel:c.restartChannel]}):null,t[29]=c.restartChannel,t[30]=c.restartingChannel,t[31]=i,t[32]=l,t[33]=r,t[34]=n,t[35]=A):A=t[35];let j;t[36]!==s||t[37]!==c.connectionOptions||t[38]!==c.hideConnectionOptions||t[39]!==i||t[40]!==d||t[41]!==r||t[42]!==a?(j=s?(0,W.jsx)(V,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:d,children:a?c.hideConnectionOptions:c.connectionOptions}):null,t[36]=s,t[37]=c.connectionOptions,t[38]=c.hideConnectionOptions,t[39]=i,t[40]=d,t[41]=r,t[42]=a,t[43]=j):j=t[43];let M;t[44]!==k||t[45]!==A||t[46]!==j?(M=(0,W.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[k,A,j]}),t[44]=k,t[45]=A,t[46]=j,t[47]=M):M=t[47];let N;return t[48]!==T||t[49]!==M?(N=(0,W.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[T,M]})}),t[48]=T,t[49]=M,t[50]=N):N=t[50],N}function ot(e){let t=(0,U.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=X(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,W.jsx)(g,{className:`mt-0.5 size-4 shrink-0`}),t[11]=u):u=t[11],o=`min-w-0`,t[12]===r.setupReadinessTitle?s=t[13]:(s=(0,W.jsx)(`h3`,{className:`text-sm font-semibold`,children:r.setupReadinessTitle}),t[12]=r.setupReadinessTitle,t[13]=s);let p=e.enabled?r.setupReadinessEnabledBody:r.setupReadinessDisabledBody;t[14]===p?c=t[15]:(c=(0,W.jsx)(`p`,{className:`mt-1 text-sm leading-5 text-amber-900 dark:text-amber-200`,children:p}),t[14]=p,t[15]=c),i=`mt-2 list-disc space-y-1 pl-5 text-sm text-amber-900 dark:text-amber-200`;let m;t[16]===r?m=t[17]:(m=e=>(0,W.jsx)(`li`,{children:et(e,r)},`${e.code}:${e.fieldPath??``}`),t[16]=r,t[17]=m),a=e.issues.map(m)}t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let p;t[18]!==i||t[19]!==a?(p=(0,W.jsx)(`ul`,{className:i,children:a}),t[18]=i,t[19]=a,t[20]=p):p=t[20];let m;t[21]!==p||t[22]!==o||t[23]!==s||t[24]!==c?(m=(0,W.jsxs)(`div`,{className:o,children:[s,c,p]}),t[21]=p,t[22]=o,t[23]=s,t[24]=c,t[25]=m):m=t[25];let h;t[26]!==m||t[27]!==l||t[28]!==u?(h=(0,W.jsxs)(`div`,{className:l,children:[u,m]}),t[26]=m,t[27]=l,t[28]=u,t[29]=h):h=t[29];let _;return t[30]!==h||t[31]!==d?(_=(0,W.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=_):_=t[32],_}function st(){let e=l(e=>e.language),t=s(e),n=c(e=>!!e.token),r=a(),{channelId:f}=i(),m=k(f),h=Oe(n,e),g=h.entries,{data:_,mutate:v,isValidating:y}=p(n?de():null,ue,{revalidateOnFocus:!0}),{data:x,mutate:C}=p(n?`channels-config-map`:null,Ie,{revalidateOnFocus:!1}),E=x?.channels??{},D=x?.bindings??[],{data:O}=p(n?`channel-routing-agents`:null,T,{revalidateOnFocus:!1}),j=A(e=>e.setPageHeader),N=A(e=>e.clearPageHeader),F=(0,H.useMemo)(()=>g.find(e=>e.id===m),[m,g]),L=F?Re(F):null,{data:ee,mutate:te}=p(n&&L?Ne(L):null,()=>Pe(L)),[z,B]=(0,H.useState)(null),[ne,V]=(0,H.useState)(!1),[re,ie]=(0,H.useState)(null),[le,U]=(0,H.useState)(null),[pe,me]=(0,H.useState)(!1),[G,K]=(0,H.useState)(null),[q,J]=(0,H.useState)(null),ge=z??ee??{},Y=t.channelsSettings,ye=(0,H.useMemo)(()=>F?.configSchema??{type:`object`,properties:{}},[F?.configSchema]),xe=(0,H.useMemo)(()=>Ke(ye,Fe),[ye]),Ce=(0,H.useMemo)(()=>He(F),[F]),Ee=(0,H.useMemo)(()=>We(xe,Ce),[Ce,xe]),De=(0,H.useMemo)(()=>Ke(xe,Ce),[Ce,xe]),ke=(0,H.useMemo)(()=>qe(Ee),[Ee]),je=F?q??_e(D,F.id):``,Le=(0,H.useMemo)(()=>(O?.items??[]).map(e=>{let n=P(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[O?.items,t.agentsSettings]),Be=O?.items.find(e=>e.id===O.defaultId),Z=Be?P(Be,t.agentsSettings):O?.defaultId??``,Ue=(0,H.useMemo)(()=>({defaultBooleanLabel:Y.schemaBooleanDefault,unsupportedArrayType:Y.schemaUnsupportedArrayType,arrayAddPlaceholder:Y.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>Y.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[Y]),Ge=(0,H.useMemo)(()=>new Map((_??[]).map(e=>[e.name,e])),[_]),Je=_!==void 0,Ye=(0,H.useCallback)(e=>be(e,Ge.get(e.id),Je),[Ge,Je]),Q=(0,H.useCallback)(async()=>{await Promise.all([h.mutate(),v()])},[h,v]);Me((0,H.useCallback)(e=>{let t=Ae(e);t&&v(t,!1)},[v]),n);let Xe=(0,H.useMemo)(()=>n?(0,W.jsx)(we,{ch:Y,refreshing:h.isValidating||y,saveOk:!1,onRefresh:()=>void Q()}):null,[h.isValidating,Y,n,y,Q]);(0,H.useLayoutEffect)(()=>(j({startExtra:null,main:(0,W.jsx)(`div`,{className:`min-w-0`,children:(0,W.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>N()),[N,Xe,t.settingsSections.channels,j]);let Ze=(0,H.useCallback)(e=>{r(w(e)),B(null),J(null),K(null)},[r]),Qe=(0,H.useCallback)(()=>{r(b),B(null),J(null),K(null)},[r]),$e=(0,H.useCallback)(async e=>{U(e.id),K(null);try{let t=await u(d(`/api/channels/${encodeURIComponent(e.id)}/restart`),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}await Q()}catch(e){K(e instanceof Error?e.message:String(e))}finally{U(null)}},[Q]);(0,H.useEffect)(()=>{J(null),me(!1)},[F?.id]);let et=(0,H.useCallback)(async()=>{if(!F||!z&&q===null)return!1;let e=Re(F);V(!0),K(null);try{let t=await u(d(`/api/config`),{method:`PATCH`,body:JSON.stringify({...z?{channels:{[e]:z}}:{},...q===null?{}:{bindings:ve(D,F.id,q)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return z&&await te(z,!1),await C(),await h.mutate(),B(null),J(null),!0}catch(e){return K(e instanceof Error?e.message:String(e)),!1}finally{V(!1)}},[F,q,D,h,z,C,te]),it=(0,H.useCallback)(async e=>{let t=X(e),n=Re(e),r=F?.id===e.id?z:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}ie(e.id),K(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await u(d(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[n]:i}})});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??a.statusText)}await h.mutate(),await C(),await v(),F?.id===e.id&&(await te(),B(null))}catch(e){K(e instanceof Error?e.message:String(e))}finally{ie(null)}},[F?.id,h,z,C,te,v,Ze]),$=F?.ui?.modal,st=$?.placement!==`replace-config`,ct=F?Ye(F):`checking`,lt=F?!X(F).ready||pe:!1;return n?(0,W.jsxs)(oe,{gap:`gap-4`,children:[h.isLoading?(0,W.jsx)(se,{sections:2}):h.error?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(h.error)}):(0,W.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:g.map(e=>(0,W.jsx)(rt,{entry:e,config:E[Re(e)]?.config,runtime:Ye(e),busy:re===e.id,restarting:le===e.id,ch:Y,onOpen:()=>Ze(e.id),onToggle:()=>void it(e),onRestart:()=>void $e(e)},e.id))}),G?(0,W.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:G}):null,(0,W.jsx)(Se,{presentation:`modal`,open:!!F,onOpenChange:e=>{e||Qe()},closeAriaLabel:Y.close,srTitle:F?.label??Y.selectChannel,srDescription:F?.description,wide:!0,footer:F?(0,W.jsx)(Te,{ch:Y,dirty:!!z||q!==null,saving:ne,onCancel:Qe,onDiscard:()=>{B(null),J(null)},onSave:et}):null,children:F?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,W.jsx)(tt,{entry:F}),(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:F.label}),(0,W.jsx)(`span`,{className:o(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Ve(ct)),children:ze(ct,Y)})]}),(0,W.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-fg-muted`,children:[(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:!X(F).ready&&fe(F)?.[1].result===`qr`?Y.scanLoginHint.replace(`{{channel}}`,F.label):F.description}),F.docsPath?(0,W.jsxs)(`a`,{href:F.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[Y.docs,(0,W.jsx)(S,{className:`size-3.5`})]}):null]})]})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,W.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:X(F).enabled?Y.enabledLabel:Y.disabledLabel}),(0,W.jsx)(nt,{checked:X(F).enabled,disabled:re===F.id,label:Y.toggleChannel.replace(`{{channel}}`,F.label),onToggle:()=>void it(F)})]})]})}),(0,W.jsx)(at,{runtime:ct,restarting:le===F.id,checking:y,showConnectionOptions:pe,canManageConnection:X(F).ready&&$?.placement!==`replace-config`,ch:Y,onRestart:()=>void $e(F),onCheck:()=>void Q(),onManageConnection:()=>me(e=>!e)}),(0,W.jsx)(ot,{entry:F,ch:Y}),lt&&$?.placement!==`replace-config`?(0,W.jsx)(he,{entry:F,locale:e,messages:Y,compact:!0,onChanged:async()=>{await te(),await Q(),await C()}},F.id):null,$?.entrypoint&&$.placement===`before-config`?(0,W.jsx)(R,{extensionId:F.extensionId,extensionName:F.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:F.id,entry:F,config:ge}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,W.jsx)(R,{extensionId:F.extensionId,extensionName:F.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:F.id,entry:F,config:ge}}):null,st&&ke?(0,W.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.basicConfiguration}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.basicConfigurationHint})]}),(0,W.jsx)(ce,{schema:Ee,values:ge,onChange:e=>B(e),disabled:ne,labels:Ue})]}):null,(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(I,{className:`size-4 text-fg-muted`}),Y.messageHandling]}),(0,W.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,W.jsxs)(`div`,{className:`mb-3`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.agentRouting}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.messageHandlingHint})]}),(0,W.jsx)(M,{value:je,options:Le,placeholder:Y.agentRoutingSelect,emptyLabel:Y.agentRoutingDefault.replace(`{{agent}}`,Z||Y.agentRoutingSelect),ariaLabel:Y.agentRouting,disabled:ne||!O,onChange:e=>J(e)})]})]}),st&&qe(De)?(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(I,{className:`size-4 text-fg-muted`}),Y.advancedConfiguration]}),(0,W.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,W.jsx)(ce,{schema:De,values:ge,onChange:e=>B(e),disabled:ne,labels:Ue})})]}):null,G?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:G}):null]}):null})]}):(0,W.jsxs)(oe,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,W.jsx)(ae,{title:t.settingsSections.channels}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:Y.tokenRequired})]})}export{st as ChannelsSettingsPanel};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{t as o}from"./cn-JdwAhgNB.js";import{t as s}from"./messages-DQ5X6cXp.js";import{l as c,n as l,o as u,r as d,s as f}from"./locale-store-Bjvw7jtg.js";import{i as p}from"./vendor-swr-BIWyz7Rc.js";import{$o as m,$r as h,Bo as g,Bs as _,Ds as v,Fo as y,Gn as b,Io as x,Kc as S,Ll as C,Lo as w,Ma as T,Na as E,Pa as D,Ro as O,Ua as k,Un as A,Vo as j,Wn as M,Xo as N,Ys as P,_s as F,cc as I,cu as L,is as ee,mc as R,rs as z,uu as B,vc as te,wn as ne,ws as V,zi as re,zo as ie}from"./index-84ys9u-K.js";import{n as ae,r as oe}from"./settings-page-layout-CRpXF_05.js";import{n as se}from"./settings-loading-skeleton-BRE_-7Da.js";import{t as ce}from"./schema-form-CFfyC4CB.js";import{t as le}from"./browser-BLJWD7WI.js";import{n as ue,t as de}from"./channels-status-swr-DPaJSYX_.js";var H=e(t(),1),U=n();function fe(e){let t=e.actions??{};for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n?.result===`qr`)return[e,n]}let n=Object.entries(t).find(([,e])=>e.result===`qr`);if(n)return n;let r=e.ui?.card?.primaryAction;if(r&&t[r])return[r,t[r]];for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n)return[e,n]}return Object.entries(t).find(([,e])=>e.result===`form`)??null}var pe=e(le(),1),W=r();async function me(e){let t=await u(d(`/api/channels/${encodeURIComponent(e.channelId)}/actions/${encodeURIComponent(e.actionId)}?locale=${encodeURIComponent(e.locale)}`),{method:`POST`,body:JSON.stringify({...e.accountId?{accountId:e.accountId}:{},...e.input===void 0?{}:{input:e.input}})}),n=await t.json().catch(()=>({}));if(!t.ok||n.ok===!1)throw Error(n.error?.message??t.statusText);return n.payload??{type:`ok`}}function G(e){return e?.type===`poll`&&e.phase===`done`}function K(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function q(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function J(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function he({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,H.useMemo)(()=>fe(e),[e]),s=(0,H.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[c,l]=(0,H.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,H.useEffect)(()=>{l({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let u=(0,H.useCallback)(async(n,i)=>{l(e=>({...e,busy:!0,error:null}));try{let a=await me({channelId:e.id,actionId:n,locale:t,input:i});l(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){l(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,H.useEffect)(()=>{let t=q(c.payload,e.id);if(!t){l(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return l(e=>e.generatedQr?{...e,generatedQr:null}:e),pe.toDataURL(t,{width:220,margin:1}).then(e=>{n||l(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,c.payload]),(0,H.useEffect)(()=>{let n=c.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||me({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(l(t=>({...t,payload:e,poll:G(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),G(e)&&window.clearInterval(a))}).catch(e=>{i||l(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,c.poll]);let d=a?.[1].label??(e.configured?n.reconnect:n.connect),f=e.actions?.[`doctor.run`]?.label??n.diagnose,p=K(c.payload),m=q(c.payload,e.id),h=m?c.generatedQr:J(c.payload),g=a?.[1].result===`qr`&&(c.busy||c.payload?.type===`qr`||c.payload?.type===`poll`),_=c.payload?.type===`form`?c.payload:null,v=c.payload?.type===`diagnostics`?c.payload.checks:null;return(0,W.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:o(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,W.jsxs)(V,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(a[0]),children:[c.busy?(0,W.jsx)(S,{className:`size-4 animate-spin`}):(0,W.jsx)(te,{className:`size-4`}),d]}):null,e.actions?.[`doctor.run`]?(0,W.jsxs)(V,{type:`button`,variant:`secondary`,disabled:c.busy,onClick:()=>void u(`doctor.run`),children:[(0,W.jsx)(P,{className:`size-4`}),f]}):null]})]}),p?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:p}):null,c.error?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:c.error}):null,g?(0,W.jsxs)(`div`,{className:o(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base p-3 shadow-surface`,i?`mt-1 flex-col text-center sm:h-64 sm:flex-row sm:text-left`:`mt-4 flex-col sm:h-64 sm:flex-row`),children:[(0,W.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:h?(0,W.jsx)(`img`,{src:h,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,W.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,W.jsx)(E,{className:`size-48 rounded-md`})})}),(0,W.jsxs)(`div`,{className:o(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[h?(0,W.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,W.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,W.jsx)(E,{className:`h-4 w-48 max-w-full`}),(0,W.jsx)(E,{className:`h-4 w-36 max-w-full`})]}),m?(0,W.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:m,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,W.jsx)(C,{className:`size-3.5`})]}):null]})]}):null,c.payload?.type===`poll`&&c.payload.phase===`done`?(0,W.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg bg-surface-base px-3 py-2 text-sm shadow-surface`,children:[(0,W.jsx)(L,{className:c.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,W.jsx)(`span`,{className:c.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:c.payload.message??(c.payload.ok?n.complete:n.failed)})]}):null,_?(0,W.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,W.jsx)(ce,{schema:_.schema,values:c.formDraft,onChange:e=>l(t=>({...t,formDraft:e})),disabled:c.busy,labels:s}),(0,W.jsx)(V,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(_.submitAction,c.formDraft),children:n.saveSetup})]}):null,v?(0,W.jsx)(`div`,{className:`mt-4 space-y-2`,children:v.map((e,t)=>(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e.status??`unknown`})]}),e.message?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var ge=40;function Y(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function _e(e,t){return e.find(e=>e.id===Y(t))?.agentId?.trim().toLowerCase()??``}function ve(e,t,n){let r=Y(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:ge,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function ye(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function be(e,t,n){let r=ye(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function xe(e,t=!1){return e===`drawer`?o(`xopc-drawer-right fixed right-0 top-0 flex size-full flex-col overflow-hidden border-l border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`,t?`max-w-[36rem]`:`max-w-xl`,z):o(`fixed left-1/2 top-1/2 flex h-[min(calc(100dvh-2rem),52rem)] w-[min(calc(100%-2rem),32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,t&&`h-[min(calc(100dvh-2rem),48rem)] w-[min(calc(100%-2rem),36rem)]`,z,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Se(e){let t=(0,U.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:f,wide:p,headerExtra:h}=e,_=p===void 0?!1:p,b=n===`drawer`,[S,C]=(0,H.useState)(null),T;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,W.jsx)(ie,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),t[0]=T):T=t[0];let E;t[1]!==n||t[2]!==_?(E=xe(n,_),t[1]=n,t[2]=_,t[3]=E):E=t[3];let D;t[4]===c?D=t[5]:(D=c?(0,W.jsx)(j,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=D);let k;t[6]===l?k=t[7]:(k=l?(0,W.jsx)(O,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=k);let A;t[8]!==u||t[9]!==s||t[10]!==h||t[11]!==b||t[12]!==a?(A=b?(0,W.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,W.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,s?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,W.jsx)(x,{asChild:!0,children:(0,W.jsx)(V,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,W.jsx)(v,{className:`size-5`,strokeWidth:1.75})})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(x,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:o(F,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,W.jsx)(v,{className:`size-4`})})}),h]}),t[8]=u,t[9]=s,t[10]=h,t[11]=b,t[12]=a,t[13]=A):A=t[13];let M=b?`p-4`:`p-6`,N;t[14]===M?N=t[15]:(N=o(`min-h-0 flex-1 overflow-y-auto`,M),t[14]=M,t[15]=N);let P;t[16]!==d||t[17]!==N?(P=(0,W.jsx)(`div`,{className:N,children:d}),t[16]=d,t[17]=N,t[18]=P):P=t[18];let I;t[19]!==f||t[20]!==S||t[21]!==D||t[22]!==k||t[23]!==A||t[24]!==P?(I=(0,W.jsxs)(m,{layer:`modal`,portalContainer:S,children:[D,k,A,P,f]}),t[19]=f,t[20]=S,t[21]=D,t[22]=k,t[23]=A,t[24]=P,t[25]=I):I=t[25];let L;t[26]!==I||t[27]!==E?(L=(0,W.jsxs)(g,{children:[T,(0,W.jsx)(w,{ref:C,className:E,onOpenAutoFocus:Ce,children:I})]}),t[26]=I,t[27]=E,t[28]=L):L=t[28];let R;return t[29]!==i||t[30]!==r||t[31]!==L?(R=(0,W.jsx)(y,{open:r,onOpenChange:i,children:L}),t[29]=i,t[30]=r,t[31]=L,t[32]=R):R=t[32],R}function Ce(e){return e.preventDefault()}var we=(0,H.memo)(function(e){let t=(0,U.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,W.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,t[0]=n.saved,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==n.refresh||t[4]!==a||t[5]!==r?(s=(0,W.jsx)(re,{className:`size-9 shrink-0 p-0`,loading:r,label:n.refresh,onClick:a}),t[3]=n.refresh,t[4]=a,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==o||t[8]!==s?(c=(0,W.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-end gap-2`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c});function Te(e){let t=(0,U.c)(24),{ch:n,dirty:r,saving:i,onCancel:a,onDiscard:o,onSave:s,showCancel:c}=e,l=c===void 0?!0:c,u;t[0]!==n.unsavedHint||t[1]!==r?(u=r?(0,W.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,t[0]=n.unsavedHint,t[1]=r,t[2]=u):u=t[2];let d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,W.jsx)(V,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,p;t[7]!==n.discard||t[8]!==o||t[9]!==f?(p=(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=p):p=t[10];let m=!r||i,h;t[11]===s?h=t[12]:(h=()=>void s(),t[11]=s,t[12]=h);let g=i?n.saving:n.save,_;t[13]!==m||t[14]!==h||t[15]!==g?(_=(0,W.jsx)(V,{type:`button`,variant:`primary`,disabled:m,onClick:h,children:g}),t[13]=m,t[14]=h,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==p||t[19]!==_?(v=(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,p,_]}),t[17]=d,t[18]=p,t[19]=_,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==u?(y=(0,W.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}function Ee(e){return d(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function De(e){return(await f(Ee(e))).payload?.channels??[]}function Oe(e,t){let n=(0,U.c)(14),r;n[0]!==e||n[1]!==t?(r=e?Ee(t):null,n[0]=e,n[1]=t,n[2]=r):r=n[2];let i;n[3]===t?i=n[4]:(i=()=>De(t),n[3]=t,n[4]=i);let a;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(a={revalidateOnFocus:!1},n[5]=a):a=n[5];let{data:o,error:s,isLoading:c,isValidating:l,mutate:u}=p(r,i,a),d;n[6]===o?d=n[7]:(d=o??[],n[6]=o,n[7]=d);let f;return n[8]!==s||n[9]!==c||n[10]!==l||n[11]!==u||n[12]!==d?(f={entries:d,isLoading:c,isValidating:l,error:s,mutate:u},n[8]=s,n[9]=c,n[10]=l,n[11]=u,n[12]=d,n[13]=f):f=n[13],f}var ke=`channels-status`;function Ae(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function je(e){let t=t=>e(t.detail);return window.addEventListener(ke,t),()=>window.removeEventListener(ke,t)}function Me(e,t){let n=(0,U.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return je(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,H.useEffect)(i,a)}function Ne(e){return e?d(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Pe(e){return(await f(d(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Fe=[`enabled`];async function Ie(){let e=await f(d(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Le(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Re(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function X(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function ze(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function Be(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Ve(e){return e===`running`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:e===`stopped`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`checking`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:e===`disabled`?`bg-surface-hover text-fg-muted`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`}function He(e){if(!e)return[];let t=e.uiHints??{},n=Z(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=X(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!Z(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Fe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Fe.includes(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ue(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function We(e,t){let n={...Ue(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!Z(r)||!Z(r[n]))break;let o=Z(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Ue(r[n]),properties:{}}),e===t.length-1){o[n]=Ue(r[n]);break}i=r[n],a=o[n]}}return n}function Ge(e){let t=e.properties;if(!Z(t))return!1;for(let[e,n]of Object.entries(t))Z(n)&&n.type===`object`&&Ge(n)&&delete t[e];return Object.keys(t).length===0}function Ke(e,t){let n=Ue(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!Z(i))break;if(e===t.length-1){delete i[n];break}if(!Z(i[n]))break;r=i[n]}}return Ge(n),n}function qe(e){return e.type===`object`&&Z(e.properties)&&Object.keys(e.properties).length>0}function Je(e,t){let n=e;for(let e of t.split(`.`)){if(!Z(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return Z(t)?Object.values(t).filter(e=>Z(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Q(e,t,n){return t==null||t===``?null:e.toLowerCase().includes(`dmpolicy`)&&typeof t==`string`?`${n.dmPolicy}: ${n.policy.dm[t]??t}`:(e.toLowerCase().includes(`stream`)||e.toLowerCase().includes(`streaming`))&&typeof t==`string`?`${n.cardStream}: ${n.policy.stream[t]??t}`:typeof t==`boolean`?t?n.enabledLabel:n.disabledLabel:String(t)}function Xe(e,t,n){let r=[],i=X(e);if(i.issues.length>0&&r.push(et(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Q(e,Je(t,e),n);i&&r.push(i)}let a=Ye(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Ze(e,t){let n=X(e),r=fe(e);return n.state===`needs_setup`?r?.[1].label??t.completeSetup:!n.enabled&&n.ready?t.enableChannel:n.state===`error`?t.diagnose:n.ready?t.manageChannel:r?.[1].label??t.startConfiguration}function Qe(e,t){let n=fe(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function $e(e,t){let n=e.capabilities??{},r=[];return n.login===!0&&r.push(t.cardCapabilityLogin),n.pairing===!0&&r.push(t.cardCapabilityPairing),n.multiAccount===!0&&r.push(t.cardCapabilityMultiAccount),n.streaming===!0&&r.push(t.cardCapabilityStreaming),n.media===!0&&r.push(t.cardCapabilityMedia),n.doctor===!0&&r.push(t.cardCapabilityDoctor),r.slice(0,3)}function et(e,t){return e.code===`telegram.missing_credential`?t.setupIssueTelegramMissingCredential:e.code===`weixin.missing_account`?t.setupIssueWeixinMissingAccount:e.code===`feishu.missing_credentials`?t.setupIssueFeishuMissingCredentials:e.code===`config.missing_required`&&e.fieldPath?t.setupIssueMissingRequired.replace(`{{field}}`,e.fieldPath):e.message}function tt({entry:e}){let t=c(e=>e.token),[n,r]=(0,H.useState)(!1),i=(0,H.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(d(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Le(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,W.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,W.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,W.jsx)(D,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,U.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,s;t[0]===i?s=t[1]:(s=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=s);let c=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,l=r&&`cursor-not-allowed opacity-60`,u;t[2]!==c||t[3]!==l?(u=o(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,c,l),t[2]=c,t[3]=l,t[4]=u):u=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=o(`size-5 rounded-full bg-white shadow-surface transition-transform`,d),t[5]=d,t[6]=f);let p;t[7]===f?p=t[8]:(p=(0,W.jsx)(`span`,{className:f}),t[7]=f,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==s||t[13]!==u||t[14]!==p?(m=(0,W.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:s,className:u,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=s,t[13]=u,t[14]=p,t[15]=m):m=t[15],m}function rt(e){let t=(0,U.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:s,ch:c,onOpen:l,onToggle:u,onRestart:d}=e,f;t[0]===n?f=t[1]:(f=X(n),t[0]=n,t[1]=f);let p=f,m,h,g,_,v,y,b;if(t[2]!==a||t[3]!==c||t[4]!==r||t[5]!==n||t[6]!==l||t[7]!==d||t[8]!==u||t[9]!==i||t[10]!==p.enabled||t[11]!==p.ready){let e=Xe(n,r,c),s=$e(n,c);m=!p.enabled&&p.ready?u:i===`stopped`?d:l,y=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let f;t[19]===n?f=t[20]:(f=(0,W.jsx)(tt,{entry:n}),t[19]=n,t[20]=f);let x;t[21]===n.label?x=t[22]:(x=(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=x);let S;t[23]===i?S=t[24]:(S=o(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Ve(i)),t[23]=i,t[24]=S);let C;t[25]!==c||t[26]!==i?(C=ze(i,c),t[25]=c,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==S||t[29]!==C?(w=(0,W.jsx)(`span`,{className:S,children:C}),t[28]=S,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==x?(T=(0,W.jsxs)(`div`,{className:`min-w-0`,children:[x,w]}),t[31]=w,t[32]=x,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==f?(E=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[f,T]}),t[34]=T,t[35]=f,t[36]=E):E=t[36];let D=p.enabled,O;t[37]!==c.toggleChannel||t[38]!==n.label?(O=c.toggleChannel.replace(`{{channel}}`,n.label),t[37]=c.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==u||t[42]!==p.enabled||t[43]!==O?(k=(0,W.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:u}),t[40]=a,t[41]=u,t[42]=p.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(b=(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=b):b=t[47],h=`button`,g=l,_=`mt-5 min-h-[6.25rem] text-left`,v=p.ready?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,W.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map($)}):null]}):(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:c.cardSetupTitle}),(0,W.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Qe(n,c)}),s.length>0?(0,W.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:s.map(it)}):null]}),t[2]=a,t[3]=c,t[4]=r,t[5]=n,t[6]=l,t[7]=d,t[8]=u,t[9]=i,t[10]=p.enabled,t[11]=p.ready,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b}else m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18];let x;t[48]!==h||t[49]!==g||t[50]!==_||t[51]!==v?(x=(0,W.jsx)(`button`,{type:h,onClick:g,className:_,children:v}),t[48]=h,t[49]=g,t[50]=_,t[51]=v,t[52]=x):x=t[52];let C=a||s,w;t[53]!==a||t[54]!==s?(w=a||s?(0,W.jsx)(S,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=s,t[55]=w):w=t[55];let T;t[56]!==c||t[57]!==n||t[58]!==s||t[59]!==i?(T=s?c.restartingChannel:i===`stopped`?c.restartChannel:Ze(n,c),t[56]=c,t[57]=n,t[58]=s,t[59]=i,t[60]=T):T=t[60];let E;t[61]!==m||t[62]!==w||t[63]!==T||t[64]!==C?(E=(0,W.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:m,disabled:C,children:[w,T]})}),t[61]=m,t[62]=w,t[63]=T,t[64]=C,t[65]=E):E=t[65];let D;return t[66]!==E||t[67]!==y||t[68]!==b||t[69]!==x?(D=(0,W.jsxs)(`article`,{className:y,children:[b,x,E]}),t[66]=E,t[67]=y,t[68]=b,t[69]=x,t[70]=D):D=t[70],D}function it(e){return(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function $(e){return(0,W.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function at(e){let t=(0,U.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:s,ch:c,onRestart:l,onCheck:u,onManageConnection:d}=e,f=n===`running`?L:n===`stopped`||n===`needs_setup`?B:S,p=n===`running`&&`text-emerald-600 dark:text-emerald-400`,m=n===`stopped`&&`text-red-600 dark:text-red-400`,h=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,g=n===`disabled`&&`text-fg-muted`,_=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,v;t[0]!==p||t[1]!==m||t[2]!==h||t[3]!==g||t[4]!==_?(v=o(`mt-0.5 size-5 shrink-0`,p,m,h,g,_),t[0]=p,t[1]=m,t[2]=h,t[3]=g,t[4]=_,t[5]=v):v=t[5];let y;t[6]!==f||t[7]!==v?(y=(0,W.jsx)(f,{className:v}),t[6]=f,t[7]=v,t[8]=y):y=t[8];let b;t[9]===c.connectionStatus?b=t[10]:(b=(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:c.connectionStatus}),t[9]=c.connectionStatus,t[10]=b);let x;t[11]!==c||t[12]!==n?(x=Be(n,c),t[11]=c,t[12]=n,t[13]=x):x=t[13];let C;t[14]===x?C=t[15]:(C=(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:x}),t[14]=x,t[15]=C);let w;t[16]!==C||t[17]!==b?(w=(0,W.jsxs)(`div`,{children:[b,C]}),t[16]=C,t[17]=b,t[18]=w):w=t[18];let T;t[19]!==w||t[20]!==y?(T=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[y,w]}),t[19]=w,t[20]=y,t[21]=T):T=t[21];let E=i||r,D;t[22]===i?D=t[23]:(D=i?(0,W.jsx)(S,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=D);let O=i?c.checkingConnection:c.checkConnection,k;t[24]!==u||t[25]!==E||t[26]!==D||t[27]!==O?(k=(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:E,onClick:u,children:[D,O]}),t[24]=u,t[25]=E,t[26]=D,t[27]=O,t[28]=k):k=t[28];let A;t[29]!==c.restartChannel||t[30]!==c.restartingChannel||t[31]!==i||t[32]!==l||t[33]!==r||t[34]!==n?(A=n===`stopped`?(0,W.jsxs)(V,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:l,children:[r?(0,W.jsx)(S,{className:`size-4 animate-spin`}):(0,W.jsx)(R,{className:`size-4`}),r?c.restartingChannel:c.restartChannel]}):null,t[29]=c.restartChannel,t[30]=c.restartingChannel,t[31]=i,t[32]=l,t[33]=r,t[34]=n,t[35]=A):A=t[35];let j;t[36]!==s||t[37]!==c.connectionOptions||t[38]!==c.hideConnectionOptions||t[39]!==i||t[40]!==d||t[41]!==r||t[42]!==a?(j=s?(0,W.jsx)(V,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:d,children:a?c.hideConnectionOptions:c.connectionOptions}):null,t[36]=s,t[37]=c.connectionOptions,t[38]=c.hideConnectionOptions,t[39]=i,t[40]=d,t[41]=r,t[42]=a,t[43]=j):j=t[43];let M;t[44]!==k||t[45]!==A||t[46]!==j?(M=(0,W.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[k,A,j]}),t[44]=k,t[45]=A,t[46]=j,t[47]=M):M=t[47];let N;return t[48]!==T||t[49]!==M?(N=(0,W.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[T,M]})}),t[48]=T,t[49]=M,t[50]=N):N=t[50],N}function ot(e){let t=(0,U.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=X(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,W.jsx)(_,{className:`mt-0.5 size-4 shrink-0`}),t[11]=u):u=t[11],o=`min-w-0`,t[12]===r.setupReadinessTitle?s=t[13]:(s=(0,W.jsx)(`h3`,{className:`text-sm font-semibold`,children:r.setupReadinessTitle}),t[12]=r.setupReadinessTitle,t[13]=s);let p=e.enabled?r.setupReadinessEnabledBody:r.setupReadinessDisabledBody;t[14]===p?c=t[15]:(c=(0,W.jsx)(`p`,{className:`mt-1 text-sm leading-5 text-amber-900 dark:text-amber-200`,children:p}),t[14]=p,t[15]=c),i=`mt-2 list-disc space-y-1 pl-5 text-sm text-amber-900 dark:text-amber-200`;let m;t[16]===r?m=t[17]:(m=e=>(0,W.jsx)(`li`,{children:et(e,r)},`${e.code}:${e.fieldPath??``}`),t[16]=r,t[17]=m),a=e.issues.map(m)}t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let p;t[18]!==i||t[19]!==a?(p=(0,W.jsx)(`ul`,{className:i,children:a}),t[18]=i,t[19]=a,t[20]=p):p=t[20];let m;t[21]!==p||t[22]!==o||t[23]!==s||t[24]!==c?(m=(0,W.jsxs)(`div`,{className:o,children:[s,c,p]}),t[21]=p,t[22]=o,t[23]=s,t[24]=c,t[25]=m):m=t[25];let h;t[26]!==m||t[27]!==l||t[28]!==u?(h=(0,W.jsxs)(`div`,{className:l,children:[u,m]}),t[26]=m,t[27]=l,t[28]=u,t[29]=h):h=t[29];let g;return t[30]!==h||t[31]!==d?(g=(0,W.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function st(){let e=l(e=>e.language),t=s(e),n=c(e=>!!e.token),r=a(),{channelId:f}=i(),m=b(f),g=Oe(n,e),_=g.entries,{data:v,mutate:y,isValidating:x}=p(n?de():null,ue,{revalidateOnFocus:!0}),{data:S,mutate:w}=p(n?`channels-config-map`:null,Ie,{revalidateOnFocus:!1}),E=S?.channels??{},D=S?.bindings??[],{data:O}=p(n?`channel-routing-agents`:null,T,{revalidateOnFocus:!1}),j=k(e=>e.setPageHeader),P=k(e=>e.clearPageHeader),F=(0,H.useMemo)(()=>_.find(e=>e.id===m),[m,_]),L=F?Re(F):null,{data:ee,mutate:R}=p(n&&L?Ne(L):null,()=>Pe(L)),[z,B]=(0,H.useState)(null),[te,V]=(0,H.useState)(!1),[re,ie]=(0,H.useState)(null),[le,U]=(0,H.useState)(null),[pe,me]=(0,H.useState)(!1),[G,K]=(0,H.useState)(null),[q,J]=(0,H.useState)(null),ge=z??ee??{},Y=t.channelsSettings,ye=(0,H.useMemo)(()=>F?.configSchema??{type:`object`,properties:{}},[F?.configSchema]),xe=(0,H.useMemo)(()=>Ke(ye,Fe),[ye]),Ce=(0,H.useMemo)(()=>He(F),[F]),Ee=(0,H.useMemo)(()=>We(xe,Ce),[Ce,xe]),De=(0,H.useMemo)(()=>Ke(xe,Ce),[Ce,xe]),ke=(0,H.useMemo)(()=>qe(Ee),[Ee]),je=F?q??_e(D,F.id):``,Le=(0,H.useMemo)(()=>(O?.items??[]).map(e=>{let n=ne(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[O?.items,t.agentsSettings]),Be=O?.items.find(e=>e.id===O.defaultId),Z=Be?ne(Be,t.agentsSettings):O?.defaultId??``,Ue=(0,H.useMemo)(()=>({defaultBooleanLabel:Y.schemaBooleanDefault,unsupportedArrayType:Y.schemaUnsupportedArrayType,arrayAddPlaceholder:Y.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>Y.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[Y]),Ge=(0,H.useMemo)(()=>new Map((v??[]).map(e=>[e.name,e])),[v]),Je=v!==void 0,Ye=(0,H.useCallback)(e=>be(e,Ge.get(e.id),Je),[Ge,Je]),Q=(0,H.useCallback)(async()=>{await Promise.all([g.mutate(),y()])},[g,y]);Me((0,H.useCallback)(e=>{let t=Ae(e);t&&y(t,!1)},[y]),n);let Xe=(0,H.useMemo)(()=>n?(0,W.jsx)(we,{ch:Y,refreshing:g.isValidating||x,saveOk:!1,onRefresh:()=>void Q()}):null,[g.isValidating,Y,n,x,Q]);(0,H.useLayoutEffect)(()=>(j({startExtra:null,main:(0,W.jsx)(`div`,{className:`min-w-0`,children:(0,W.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>P()),[P,Xe,t.settingsSections.channels,j]);let Ze=(0,H.useCallback)(e=>{r(M(e)),B(null),J(null),K(null)},[r]),Qe=(0,H.useCallback)(()=>{r(A),B(null),J(null),K(null)},[r]),$e=(0,H.useCallback)(async e=>{U(e.id),K(null);try{let t=await u(d(`/api/channels/${encodeURIComponent(e.id)}/restart`),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}await Q()}catch(e){K(e instanceof Error?e.message:String(e))}finally{U(null)}},[Q]);(0,H.useEffect)(()=>{J(null),me(!1)},[F?.id]);let et=(0,H.useCallback)(async()=>{if(!F||!z&&q===null)return!1;let e=Re(F);V(!0),K(null);try{let t=await u(d(`/api/config`),{method:`PATCH`,body:JSON.stringify({...z?{channels:{[e]:z}}:{},...q===null?{}:{bindings:ve(D,F.id,q)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return z&&await R(z,!1),await w(),await g.mutate(),B(null),J(null),!0}catch(e){return K(e instanceof Error?e.message:String(e)),!1}finally{V(!1)}},[F,q,D,g,z,w,R]),it=(0,H.useCallback)(async e=>{let t=X(e),n=Re(e),r=F?.id===e.id?z:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}ie(e.id),K(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await u(d(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[n]:i}})});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??a.statusText)}await g.mutate(),await w(),await y(),F?.id===e.id&&(await R(),B(null))}catch(e){K(e instanceof Error?e.message:String(e))}finally{ie(null)}},[F?.id,g,z,w,R,y,Ze]),$=F?.ui?.modal,st=$?.placement!==`replace-config`,ct=F?Ye(F):`checking`,lt=F?!X(F).ready||pe:!1;return n?(0,W.jsxs)(oe,{gap:`gap-4`,children:[g.isLoading?(0,W.jsx)(se,{sections:2}):g.error?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(g.error)}):(0,W.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:_.map(e=>(0,W.jsx)(rt,{entry:e,config:E[Re(e)]?.config,runtime:Ye(e),busy:re===e.id,restarting:le===e.id,ch:Y,onOpen:()=>Ze(e.id),onToggle:()=>void it(e),onRestart:()=>void $e(e)},e.id))}),G?(0,W.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:G}):null,(0,W.jsx)(Se,{presentation:`modal`,open:!!F,onOpenChange:e=>{e||Qe()},closeAriaLabel:Y.close,srTitle:F?.label??Y.selectChannel,srDescription:F?.description,wide:!0,footer:F?(0,W.jsx)(Te,{ch:Y,dirty:!!z||q!==null,saving:te,onCancel:Qe,onDiscard:()=>{B(null),J(null)},onSave:et}):null,children:F?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,W.jsx)(tt,{entry:F}),(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:F.label}),(0,W.jsx)(`span`,{className:o(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Ve(ct)),children:ze(ct,Y)})]}),(0,W.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-fg-muted`,children:[(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:!X(F).ready&&fe(F)?.[1].result===`qr`?Y.scanLoginHint.replace(`{{channel}}`,F.label):F.description}),F.docsPath?(0,W.jsxs)(`a`,{href:F.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[Y.docs,(0,W.jsx)(C,{className:`size-3.5`})]}):null]})]})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,W.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:X(F).enabled?Y.enabledLabel:Y.disabledLabel}),(0,W.jsx)(nt,{checked:X(F).enabled,disabled:re===F.id,label:Y.toggleChannel.replace(`{{channel}}`,F.label),onToggle:()=>void it(F)})]})]})}),(0,W.jsx)(at,{runtime:ct,restarting:le===F.id,checking:x,showConnectionOptions:pe,canManageConnection:X(F).ready&&$?.placement!==`replace-config`,ch:Y,onRestart:()=>void $e(F),onCheck:()=>void Q(),onManageConnection:()=>me(e=>!e)}),(0,W.jsx)(ot,{entry:F,ch:Y}),lt&&$?.placement!==`replace-config`?(0,W.jsx)(he,{entry:F,locale:e,messages:Y,compact:!0,onChanged:async()=>{await R(),await Q(),await w()}},F.id):null,$?.entrypoint&&$.placement===`before-config`?(0,W.jsx)(h,{extensionId:F.extensionId,extensionName:F.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:F.id,entry:F,config:ge}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,W.jsx)(h,{extensionId:F.extensionId,extensionName:F.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:F.id,entry:F,config:ge}}):null,st&&ke?(0,W.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.basicConfiguration}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.basicConfigurationHint})]}),(0,W.jsx)(ce,{schema:Ee,values:ge,onChange:e=>B(e),disabled:te,labels:Ue})]}):null,(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(I,{className:`size-4 text-fg-muted`}),Y.messageHandling]}),(0,W.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,W.jsxs)(`div`,{className:`mb-3`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.agentRouting}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.messageHandlingHint})]}),(0,W.jsx)(N,{value:je,options:Le,placeholder:Y.agentRoutingSelect,emptyLabel:Y.agentRoutingDefault.replace(`{{agent}}`,Z||Y.agentRoutingSelect),ariaLabel:Y.agentRouting,disabled:te||!O,onChange:e=>J(e)})]})]}),st&&qe(De)?(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(I,{className:`size-4 text-fg-muted`}),Y.advancedConfiguration]}),(0,W.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,W.jsx)(ce,{schema:De,values:ge,onChange:e=>B(e),disabled:te,labels:Ue})})]}):null,G?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:G}):null]}):null})]}):(0,W.jsxs)(oe,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,W.jsx)(ae,{title:t.settingsSections.channels}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:Y.tokenRequired})]})}export{st as ChannelsSettingsPanel};
|