@xopcai/xopc 0.0.201 → 0.0.202
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-D8Cw0Mve.js → agent-avatar-dicebear-CAjfa48Q.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-ANavi648.js → agents-Cke8EF5Z.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BubrReXg.js → app-management-settings-panel-GNT3iv0V.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BY5Az2p4.js → appearance-settings-BFond2ll.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-CFh9MBxc.js → apps-page-B9D-6sJt.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BY8843mB.js → archive-plugin-C6qpchzp.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-DG45KScf.js → attachment-load-B4CcSDdV.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-751CeNI3.js → automations-page-BFS3dH43.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-DGIF2ZAv.js → binary-plugins-xYL_41XP.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-C1Qktr1g.js → block-editor-nYiJQItv.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-CGAWs-TT.js → browser-settings-page-ELV-Y8rz.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-DyIRvPaq.js → browser-workflows-page-pT7Hvwwh.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-CghUK68J.js → capabilities-settings-panel-Dbx_nPAI.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-settings-panel-XsTfkvUn.js → capability-presets-settings-panel-DHg_JMUz.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-DkoAZZMe.js → channels-settings-DjHOlPq-.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-api-FBOe9SWC.js → connectors-api-X5ukNasZ.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-e4vekkAu.js → connectors-page-RY-W6CQt.js} +1 -1
- package/dist/gateway/static/root/assets/{cron-expression-Q4QaYjpI.js → cron-expression-DHY0LrLq.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-Dtn7e6TW.js → date-picker-CGm8EH8G.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-Br6nPaM6.js → dependency-picker-DDECr6Hj.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-DzTM6aH8.js → desktop-pet-BoEIRgm2.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-FDmaty3P.js → desktop-pet-settings-s4kmnf-W.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-X2e8xn8j.js → directory-picker-path-field-DmfFg4Gq.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-Dx4MBfga.js → extension-debug-page-DrLEK8GU.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-Bf_FEDhM.js → extension-page-DtyFPtMR.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-CrOgZxkf.js → extension-settings-page-Xok6T2KD.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-CZ4r-7qT.js → gateway-config-api-DwSpEYiw.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-DpWmVi0w.js → gateway-settings-B5Zh2rx9.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-DSQZhSvT.js → heartbeat-settings-C2RxqeK0.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-L0uHiu0T.js → home-page-DPhkqxEb.js} +1 -1
- package/dist/gateway/static/root/assets/{index-DRrjYYzZ.js → index-CKSplmFw.js} +12 -12
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-Bc3Quw42.js → keyboard-shortcuts-settings-BN3p-1wI.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-Copi3sdP.js → local-app-workbench-page-D7FmunJF.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-CP9X_vtz.js → local-apps-page-C7H807zd.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-DMKq6e29.js → logs-page-vrjf-JTk.js} +1 -1
- package/dist/gateway/static/root/assets/{management-settings-CJmcaVje.js → management-settings-CTIaHfgU.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-AcuFp0TH.js → markdown-split-C0iKadAm.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BvFgsiJL.js → media-plugins-DcM72GSJ.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-IW7IQ9nJ.js → notes-page-By_EzRhP.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-workbench-Zb8U0anO.js → notes-workbench-Cp1ierS_.js} +2 -2
- package/dist/gateway/static/root/assets/{preview-open-alternatives-C-b34dgQ.js → preview-open-alternatives-CpblfmWk.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CWEzLykF.js → product-open-page-dQ2_5PLu.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-BuIbLnan.js → project-detail-page-Cp_jfZJj.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-BwUfRqNV.js → projects-page-DYbmweGw.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-BTaXxcEi.js → remote-access-hub-U2qXVyLH.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-DAohEZrX.js → runtime-tools-settings-panel-DiPj9FLN.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-C_OBW8A5.js → schema-form-BDLYItBP.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-BnHoTCD3.js → sessions-page-CtNKNhCi.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-B6IMzhWo.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-C7w2WS-A.js → settings-form-section-Dr4Uf_CY.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-zwibve4m.js → settings-loading-skeleton-Bqi7tsXj.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-B9W03dSW.js → settings-page-BbookgxJ.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-C8Hec2Af.js → setup-status-panel-mUu0iDlD.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-6e3ks2be.js → share-preview-page-1M79esSO.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-Bwc5HfLI.js → shares-settings-DadcMA8y.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-reload-api-D7kunhqy.js → skill-reload-api-C3ZzYCz0.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-WgkaNzpc.js → skills-page-B3kqZ-ke.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-D9QT5cxj.js → skills-page.utils-b9byH-KL.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-c1HVtv1Y.js → system-settings-panel-CL_AXjw1.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-CjP-6WVU.js → task-detail-page-Bnjpkl4v.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-D6UkH_Ga.js → use-autosave-CUI3q_I-.js} +1 -1
- package/dist/gateway/static/root/assets/{user-context-page-D8ZhPDNF.js → user-context-page-CBgAAZiB.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-BOxkKbGh.js → voice-api-key-field-DLXOB1jw.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-Dd19yK9t.js → work-discovery-overlay-BvlvyVJX.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-page-DUkdJl1e.js → work-discovery-page-BBpnnnrs.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-ZA3bP65I.js → workflow-run-setup-panel-DKpUxB-i.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-C2b5W5bw.js → workflows-page-Dd_9p9ji.js} +1 -1
- package/dist/gateway/static/root/index.html +1 -1
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +1 -1
- package/dist/src/agent/memory/create-memory-manager.js +1 -1
- package/dist/src/agent-runtime/index.js +1 -1
- package/dist/src/agent-runtime/runtime-profile.js +1 -1
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/oauth-async.d.ts +1 -0
- package/dist/src/gateway/hono/oauth-async.js +14 -2
- package/dist/src/gateway/service.js +5 -5
- package/dist/src/heartbeat/index.js +1 -1
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/settings-advanced-gate-BTB_fxjt.js +0 -1
|
@@ -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{i as o,n as s,r as c,t as l}from"./popover-select-BzdnTy3h.js";import{t as u}from"./copy-Dv6d4Dvw.js";import{t as d}from"./loader-circle-CifKLtgG.js";import{t as f}from"./cn-JdwAhgNB.js";import{t as p}from"./button-CSEbl4zT.js";import{t as m}from"./interaction-BmQogeqz.js";import{t as h}from"./messages-D7kOD_o_.js";import{l as g,n as _}from"./locale-store-CnamlR07.js";import{i as v,o as y}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"./dist-BPoKqzeH.js";import{i as D}from"./vendor-swr-BIWyz7Rc.js";import{Al as O,Dc as k,Gl as A,Jl as j,Ps as M,Rn as N,Vs as P,Wl as F,Ws as I,X as L,Xo as R,Yo as ee,it as te,ls as z,ql as B,tl as ne,ws as re,zl as V}from"./index-
|
|
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{i as o,n as s,r as c,t as l}from"./popover-select-BzdnTy3h.js";import{t as u}from"./copy-Dv6d4Dvw.js";import{t as d}from"./loader-circle-CifKLtgG.js";import{t as f}from"./cn-JdwAhgNB.js";import{t as p}from"./button-CSEbl4zT.js";import{t as m}from"./interaction-BmQogeqz.js";import{t as h}from"./messages-D7kOD_o_.js";import{l as g,n as _}from"./locale-store-CnamlR07.js";import{i as v,o as y}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"./dist-BPoKqzeH.js";import{i as D}from"./vendor-swr-BIWyz7Rc.js";import{Al as O,Dc as k,Gl as A,Jl as j,Ps as M,Rn as N,Vs as P,Wl as F,Ws as I,X as L,Xo as R,Yo as ee,it as te,ls as z,ql as B,tl as ne,ws as re,zl as V}from"./index-CKSplmFw.js";import{l as H}from"./vendor-codemirror-DRr7hFaD.js";import{t as U}from"./code-editor-dFzqyDXS.js";import{n as W,r as G}from"./settings-page-layout-BRQNel6r.js";import{n as ie,r as ae}from"./settings-loading-skeleton-Bqi7tsXj.js";import{n as K,t as oe}from"./settings-form-section-Dr4Uf_CY.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--tz0mGLY.js";import{a as he,i as ge,o as q,s as J,t as _e}from"./typed-models-lib-q5-Vfqd8.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 u=i??(t.some(e=>e.id===`deep`)?`deep`:t[0]?.id)??`deep`,d=t.findIndex(e=>e.id===u),f=d>=0?t[d]:void 0,m=t.map((e,t)=>({row:e,index:t})).filter(({index:e})=>e!==d),h=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},g=e=>{if(d>=0){h(d,{model:e});return}s.current.unshift(`preset-model-row-${c.current++}`),n([{id:u,model:e,fallbacks:[],description:ve(u)?o.roleDescriptions[u]:``},...t])},_=e=>{let n=t[e];n&&h(e,{fallbacks:[...n.fallbacks??[],``]})},v=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,h(e,{fallbacks:a})},y=(e,n)=>{let r=t[e];r&&h(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},b=e=>{s.current.splice(e,1),n(t.filter((t,n)=>n!==e))},x=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]:``}])},S=[...Q.filter(e=>e!==u&&!t.some(t=>t.id===e)).map(e=>({value:e,label:o.roleNames[e]})),{value:`__custom__`,label:o.customRole}],C=(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)(p,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>_(t),children:[(0,Z.jsx)(I,{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)(L,{value:e,disabled:r,placeholder:o.fallbackPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>v(t,n,e)}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":o.removeFallback,onClick:()=>y(t,n),children:(0,Z.jsx)(z,{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=>h(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,`: `,u]})]}),(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)(L,{value:f?.model??``,disabled:r,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:g})]}),f?(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)(O,{className:`size-3.5 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsx)(`div`,{className:`mt-3`,children:C(f,d)})]}):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})]}),m.length>0?(0,Z.jsx)(`div`,{className:`mt-3 grid gap-2`,children:m.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=>h(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)(L,{value:e.model,disabled:r,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>h(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)(O,{className:`size-3.5 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[C(e,t),(0,Z.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>b(t),children:[(0,Z.jsx)(z,{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)(l,{value:``,options:S,placeholder:o.addTaskModel,allowEmpty:!1,disabled:r,triggerClassName:`mt-3 w-fit`,onChange:x})]})]})}var be=H();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
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:l,workflows:u,policy:d,onPolicyChange:f,rawPolicy:m,onRawPolicyChange:h,disabled:g,labels:_}=e,[v,y]=(0,X.useState)(t.length>1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(``),E=d.mcp??{},D=d.workflows??{},O=d.boundaries??{},k=d.runtime??{},A=d.locks??[],M=[...new Set([...o,...Object.keys(E.servers??{})])].sort(),N=new Map(r.map(e=>[e.id,e])),P=r.filter(e=>!t.includes(e.id)),I=(e,t)=>{f({...d,[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:_.inheritanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:_.inheritanceHint}),v?(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:N.get(e)?.name??e}),(0,Z.jsx)(`div`,{className:`font-mono text-[11px] text-fg-subtle`,children:e})]}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:g||r===0,"aria-label":_.inheritanceMoveUp,onClick:()=>{let e=[...t];[e[r-1],e[r]]=[e[r],e[r-1]],n(e)},children:(0,Z.jsx)(F,{className:`size-3.5`})}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:g||r===t.length-1,"aria-label":_.inheritanceMoveDown,onClick:()=>{let e=[...t];[e[r],e[r+1]]=[e[r+1],e[r]],n(e)},children:(0,Z.jsx)(j,{className:`size-3.5`})}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:g,"aria-label":_.inheritanceRemove,onClick:()=>n(t.filter(t=>t!==e)),children:(0,Z.jsx)(z,{className:`size-3.5`})})]},e)),P.length?(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[_.inheritanceAdd,(0,Z.jsxs)(s,{value:``,disabled:g,onChange:e=>e.target.value&&n([...t,e.target.value]),children:[(0,Z.jsx)(c,{value:``,children:_.inheritanceAvailable}),P.map(e=>(0,Z.jsx)(c,{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:[_.inheritanceAvailable,(0,Z.jsxs)(s,{value:t[0]??``,disabled:g,onChange:e=>n(e.target.value?[e.target.value]:[]),children:[(0,Z.jsx)(c,{value:``,children:_.inherit}),r.map(e=>(0,Z.jsx)(c,{value:e.id,children:e.name},e.id))]})]}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,disabled:g,onClick:()=>y(!0),children:_.compose})]}),r.length?null:(0,Z.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:_.inheritanceEmpty})]}),(0,Z.jsx)(Oe,{title:_.mcpTitle,hint:_.mcpHint,source:Ce(a,`tools.mcp`,_.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)(s,{value:E.servers?.[e]?.mode??``,disabled:g,onClick:e=>e.stopPropagation(),onChange:t=>L(e,t.target.value),children:[(0,Z.jsx)(c,{value:``,children:i?.tools?.mcp?.servers?.[e]?.mode?`${_.inherit} · ${i.tools.mcp.servers[e].mode}`:_.inherit}),(0,Z.jsx)(c,{value:`allow`,children:_.modeAllow}),(0,Z.jsx)(c,{value:`confirm`,children:_.modeConfirm}),(0,Z.jsx)(c,{value:`deny`,children:_.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:g,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}))}}),_.readonlyOnly]}):null,l.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)(s,{value:t?.mode??``,disabled:g,onChange:n=>{let r=n.target.value;R(e.id,r?{...t??{},mode:r}:void 0)},children:[(0,Z.jsx)(c,{value:``,children:_.inherit}),(0,Z.jsx)(c,{value:`allow`,children:_.modeAllow}),(0,Z.jsx)(c,{value:`confirm`,children:_.modeConfirm}),(0,Z.jsx)(c,{value:`deny`,children:_.modeDeny})]}),(0,Z.jsx)(ke,{label:_.maxCalls,value:t?.limits?.maxCallsPerTurn,disabled:!t||g,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,maxCallsPerTurn:n})}:void 0)}),(0,Z.jsx)(ke,{label:_.timeoutMinutes,value:t?.limits?.timeoutMs?t.limits.timeoutMs/6e4:void 0,disabled:!t||g,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:_.noMcp})}),(0,Z.jsxs)(Oe,{title:_.workflowsTitle,hint:_.workflowsHint,source:Ce(a,`workflows`,_.inherit),children:[(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[_.defaultWorkflow,(0,Z.jsxs)(s,{value:D.default??``,disabled:g,onChange:e=>I(`workflows`,De({...D,default:e.target.value||void 0})),children:[(0,Z.jsx)(c,{value:``,children:i?.workflows?.default?`${_.inherit} · ${i.workflows.default}`:_.inherit}),u.map(e=>(0,Z.jsx)(c,{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:_.allowedWorkflows}),(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:u.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:g,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:_.runtimeTitle,hint:_.runtimeHint,source:Ce(a,`runtime`,_.inherit),children:(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Z.jsx)(ke,{label:_.timeoutMinutes,value:k.timeoutMs?k.timeoutMs/6e4:void 0,placeholder:i?.runtime?.timeoutMs?String(i.runtime.timeoutMs/6e4):void 0,disabled:g,onChange:e=>I(`runtime`,De({...k,timeoutMs:e?e*6e4:void 0}))}),(0,Z.jsx)(ke,{label:_.maxTurns,value:k.maxTurns,placeholder:i?.runtime?.maxTurns?String(i.runtime.maxTurns):void 0,disabled:g,onChange:e=>I(`runtime`,De({...k,maxTurns:e}))}),(0,Z.jsx)(ke,{label:_.maxFailures,value:k.maxToolFailuresPerTurn,placeholder:i?.runtime?.maxToolFailuresPerTurn?String(i.runtime.maxToolFailuresPerTurn):void 0,disabled:g,onChange:e=>I(`runtime`,De({...k,maxToolFailuresPerTurn:e}))})]})}),(0,Z.jsx)(Oe,{title:_.boundariesTitle,hint:_.boundariesHint,source:Ce(a,`boundaries`,_.inherit),children:(0,Z.jsx)(`div`,{className:`grid gap-3 lg:grid-cols-3`,children:[[`requiresConfirmation`,_.confirmRules],[`forbidden`,_.forbiddenRules],[`escalation`,_.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:_.onePerLine,value:Se(O[e]),disabled:g,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:_.governanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_.governanceHint}),(0,Z.jsxs)(`label`,{className:`mt-3 block text-xs text-fg-muted`,children:[_.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:_.onePerLine,value:Se(A),disabled:g,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:_.rawTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_.rawHint}),b?(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)(U,{initialContent:S,onChange:C,language:be,lineWrap:!0})}),w?(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-red-600 dark:text-red-400`,children:w}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(p,{type:`button`,onClick:()=>{try{let e=JSON.parse(S);if(!Te(e))throw Error(`invalid policy`);h(e),T(``),x(!1)}catch{T(_.rawInvalid)}},children:_.rawApply}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,onClick:()=>x(!1),children:_.cancel})]})]}):(0,Z.jsx)(p,{className:`mt-3`,type:`button`,variant:`secondary`,onClick:()=>{C(JSON.stringify(m,null,2)),T(``),x(!0)},children:_.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:o,onModeChange:s,onSelectedChange:c,labels:l}=e,u=n===`allowlist`||n===`denylist`,d;t[0]===i?d=t[1]:(d=i.map(Ae).filter(Boolean),t[0]=i,t[1]=d);let m=d,h;bb0:{if(n===`inherit`){h=l.inheritSummary;break bb0}if(n===`all`){h=l.allSummary;break bb0}if(n===`off`){h=l.offSummary;break bb0}let e=n===`allowlist`?l.allowSummary:l.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],h=i}let g=h,_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Z.jsx)(V,{className:`size-3.5`,"aria-hidden":!0}),t[5]=_):_=t[5];let v;t[6]===l.overrideSummaryTitle?v=t[7]:(v=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[_,l.overrideSummaryTitle]}),t[6]=l.overrideSummaryTitle,t[7]=v);let y;t[8]===g?y=t[9]:(y=(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:g}),t[8]=g,t[9]=y);let b;t[10]!==v||t[11]!==y?(b=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[v,y]}),t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===l.modeLabel?x=t[14]:(x=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.modeLabel}),t[13]=l.modeLabel,t[14]=x);let S;t[15]===l.modeInherit?S=t[16]:(S=[`inherit`,l.modeInherit],t[15]=l.modeInherit,t[16]=S);let C;t[17]===l.modeAll?C=t[18]:(C=[`all`,l.modeAll],t[17]=l.modeAll,t[18]=C);let w;t[19]===l.modeAllowlist?w=t[20]:(w=[`allowlist`,l.modeAllowlist],t[19]=l.modeAllowlist,t[20]=w);let T;t[21]===l.modeDenylist?T=t[22]:(T=[`denylist`,l.modeDenylist],t[21]=l.modeDenylist,t[22]=T);let E;t[23]===l.modeOff?E=t[24]:(E=[`off`,l.modeOff],t[23]=l.modeOff,t[24]=E);let D;t[25]!==T||t[26]!==E||t[27]!==S||t[28]!==C||t[29]!==w?(D=[S,C,w,T,E],t[25]=T,t[26]=E,t[27]=S,t[28]=C,t[29]=w,t[30]=D):D=t[30];let O=D,k;t[31]!==o||t[32]!==n||t[33]!==s||t[34]!==O?(k=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:O.map(e=>{let[t,r]=e;return(0,Z.jsx)(`button`,{type:`button`,className:f(`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:o,onClick:()=>s(t),children:r},t)})}),t[31]=o,t[32]=n,t[33]=s,t[34]=O,t[35]=k):k=t[35];let A;t[36]!==k||t[37]!==x?(A=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[x,k]}),t[36]=k,t[37]=x,t[38]=A):A=t[38];let j;t[39]!==i||t[40]!==m||t[41]!==o||t[42]!==l.emptyCatalog||t[43]!==l.noDescription||t[44]!==l.quickActionsLabel||t[45]!==l.quickClear||t[46]!==l.quickSelectAll||t[47]!==a||t[48]!==c||t[49]!==u||t[50]!==r?(j=u?(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:l.quickActionsLabel}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:o||a||m.length===0,onClick:()=>c(new Set(m)),children:l.quickSelectAll}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:o||a||r.size===0,onClick:()=>c(new Set),children:l.quickClear})]})]}),a?(0,Z.jsx)(ae,{rows:3}):i.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.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||l.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:o,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),c(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:f(`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]=m,t[41]=o,t[42]=l.emptyCatalog,t[43]=l.noDescription,t[44]=l.quickActionsLabel,t[45]=l.quickClear,t[46]=l.quickSelectAll,t[47]=a,t[48]=c,t[49]=u,t[50]=r,t[51]=j):j=t[51];let M;return t[52]!==A||t[53]!==j||t[54]!==b?(M=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[b,A,j]}),t[52]=A,t[53]=j,t[54]=b,t[55]=M):M=t[55],M}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:o,getGroupTitle:s,labels:c}=e,l;t[0]===n?l=t[1]:(l=new Set(n),t[0]=n,t[1]=l);let u=l,d;t[2]!==u||t[3]!==r?(d=Object.entries(r).filter(e=>{let[t]=e;return u.has(t)}).toSorted(Be),t[2]=u,t[3]=r,t[4]=d):d=t[4];let m=d,h;if(t[5]!==u||t[6]!==n){h=[];for(let e of pe){let t=e.toolIds.filter(e=>u.has(e));t.length>0&&h.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),h.push(e)}t[5]=u,t[6]=n,t[7]=h}else h=t[7];let g=h,_;t[12]!==i||t[13]!==r?(_=(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]=_):_=t[14];let v=_,y;t[15]!==i||t[16]!==r?(y=(e,t)=>{let n=r[e];n&&i({...r,[e]:t(n)})},t[15]=i,t[16]=r,t[17]=y):y=t[17];let b=y,x;t[18]!==u||t[19]!==i?(x=e=>{i(Re(u,e))},t[18]=u,t[19]=i,t[20]=x):x=t[20];let S=x;if(n.length===0){let e;return t[21]===c.emptyBuiltin?e=t[22]:(e=(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c.emptyBuiltin}),t[21]=c.emptyBuiltin,t[22]=e),e}let C;t[23]===c.quickActionsLabel?C=t[24]:(C=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:c.quickActionsLabel}),t[23]=c.quickActionsLabel,t[24]=C);let w;t[25]===i?w=t[26]:(w=()=>i({}),t[25]=i,t[26]=w);let T;t[27]!==a||t[28]!==c.quickClearOverrides||t[29]!==w?(T=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:w,children:c.quickClearOverrides}),t[27]=a,t[28]=c.quickClearOverrides,t[29]=w,t[30]=T):T=t[30];let E;t[31]===S?E=t[32]:(E=()=>S([[Me,`deny`]]),t[31]=S,t[32]=E);let D;t[33]!==a||t[34]!==c.quickReadOnlyWorkspace||t[35]!==E?(D=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:E,children:c.quickReadOnlyWorkspace}),t[33]=a,t[34]=c.quickReadOnlyWorkspace,t[35]=E,t[36]=D):D=t[36];let O;t[37]===S?O=t[38]:(O=()=>S([[Ne,`deny`]]),t[37]=S,t[38]=O);let k;t[39]!==a||t[40]!==c.quickHighRiskOff||t[41]!==O?(k=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:O,children:c.quickHighRiskOff}),t[39]=a,t[40]=c.quickHighRiskOff,t[41]=O,t[42]=k):k=t[42];let A;t[43]===S?A=t[44]:(A=()=>S([[$,`deny`]]),t[43]=S,t[44]=A);let j;t[45]!==a||t[46]!==c.quickNoOutbound||t[47]!==A?(j=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:A,children:c.quickNoOutbound}),t[45]=a,t[46]=c.quickNoOutbound,t[47]=A,t[48]=j):j=t[48];let M;t[49]===S?M=t[50]:(M=()=>S([[Pe,`allow`],[Fe,`deny`]]),t[49]=S,t[50]=M);let N;t[51]!==a||t[52]!==c.quickResearchMode||t[53]!==M?(N=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:M,children:c.quickResearchMode}),t[51]=a,t[52]=c.quickResearchMode,t[53]=M,t[54]=N):N=t[54];let P;t[55]===S?P=t[56]:(P=()=>S([[Ie,`allow`],[Le,`deny`]]),t[55]=S,t[56]=P);let F;t[57]!==a||t[58]!==c.quickCodingMode||t[59]!==P?(F=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:P,children:c.quickCodingMode}),t[57]=a,t[58]=c.quickCodingMode,t[59]=P,t[60]=F):F=t[60];let I;t[61]!==k||t[62]!==j||t[63]!==N||t[64]!==F||t[65]!==T||t[66]!==D?(I=(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[T,D,k,j,N,F]}),t[61]=k,t[62]=j,t[63]=N,t[64]=F,t[65]=T,t[66]=D,t[67]=I):I=t[67];let L;t[68]!==I||t[69]!==C?(L=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[C,I]}),t[68]=I,t[69]=C,t[70]=L):L=t[70];let R;t[71]===c.overrideSummaryTitle?R=t[72]:(R=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:c.overrideSummaryTitle}),t[71]=c.overrideSummaryTitle,t[72]=R);let ee;t[73]!==c.modeAllow||t[74]!==c.modeConfirm||t[75]!==c.modeDeny||t[76]!==c.noOverrides||t[77]!==m?(ee=m.length>0?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:m.map(e=>{let[t,n]=e;return(0,Z.jsxs)(`span`,{className:f(`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`?c.modeAllow:n.mode===`confirm`?c.modeConfirm:c.modeDeny})]},t)})}):(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:c.noOverrides}),t[73]=c.modeAllow,t[74]=c.modeConfirm,t[75]=c.modeDeny,t[76]=c.noOverrides,t[77]=m,t[78]=ee):ee=t[78];let te;t[79]!==R||t[80]!==ee?(te=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[R,ee]}),t[79]=R,t[80]=ee,t[81]=te):te=t[81];let z;t[82]!==a||t[83]!==s||t[84]!==o||t[85]!==g||t[86]!==c.inheritedMode||t[87]!==c.maxCallsLabel||t[88]!==c.modeAllow||t[89]!==c.modeConfirm||t[90]!==c.modeDeny||t[91]!==c.timeoutLabel||t[92]!==v||t[93]!==r||t[94]!==b?(z=(0,Z.jsx)(`div`,{className:`flex flex-col gap-5`,children:g.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:s(t)}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=o(e),n=r[e],i=n?n.mode:`inherit`;return(0,Z.jsxs)(`li`,{className:f(`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:f(`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:()=>v(e,t),children:t===`inherit`?c.inheritedMode:t===`allow`?c.modeAllow:t===`confirm`?c.modeConfirm:c.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:c.maxCallsLabel,value:n.limits?.maxCallsPerTurn,disabled:a,onChange:t=>b(e,e=>Ve(e,`maxCallsPerTurn`,t))}),(0,Z.jsx)(He,{label:c.timeoutLabel,value:n.limits?.timeoutMs,disabled:a,onChange:t=>b(e,e=>Ve(e,`timeoutMs`,t))})]}):null]},e)})})]},t)})}),t[82]=a,t[83]=s,t[84]=o,t[85]=g,t[86]=c.inheritedMode,t[87]=c.maxCallsLabel,t[88]=c.modeAllow,t[89]=c.modeConfirm,t[90]=c.modeDeny,t[91]=c.timeoutLabel,t[92]=v,t[93]=r,t[94]=b,t[95]=z):z=t[95];let B;return t[96]!==L||t[97]!==te||t[98]!==z?(B=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[L,te,z]}),t[96]=L,t[97]=te,t[98]=z,t[99]=B):B=t[99],B}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:u},{id:`models`,icon:k},{id:`tools`,icon:R},{id:`skills`,icon:P},{id:`advanced`,icon:re},{id:`impact`,icon:ne}];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=h(_(e=>e.language)),t=e.capabilityPresetsSettings,n=(0,Z.jsx)(p,{asChild:!0,type:`button`,variant:`secondary`,children:(0,Z.jsxs)(a,{to:`/agents`,children:[t.manageAgents,(0,Z.jsx)(A,{className:`size-4`,"aria-hidden":!0})]})}),r=!!g(e=>e.token),{data:s,error:c,isLoading:l,mutate:O}=D(r?`settings-capability-presets`:null,le,{revalidateOnFocus:!1}),{data:j=[],isLoading:F}=D(r?`settings-capability-presets-skills-catalog`:null,N,{revalidateOnFocus:!1}),L=s?.mcpServerIds??[],{data:te=[]}=D(r&&L.length?[`capability-preset-mcp-tools`,...L]:null,()=>fe(L),{revalidateOnFocus:!1}),[V,H]=i(),[U,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=s?.presets??[],Ae=s?.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===U)??ke[0]??null,[ke,U]),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}=D(pe===`impact`&&$&&Ve?[`capability-preset-impact-preview`,$.id,JSON.stringify(Ve)]:null,()=>se($.id,Ve),{revalidateOnFocus:!1}),qe=be??(c instanceof Error?c.message:null),Je=V.get(`action`)===`new`||!!V.get(`preset`),Ye=V.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(!s||Q)return;if(V.get(`action`)===`new`){ce(``),J(ft(`blank`,t)),ge(`overview`);return}let e=V.get(`preset`)?.trim(),n=e?s.presets.find(t=>t.id===e):null;if(n){ce(n.id),J($e(n)),ge(V.get(`tab`)??`overview`);return}$&&(ce($.id),J(e=>e.id===$.id?e:$e($)))},[Q,s,V,$]);function tt(e){Y(null),ce(e.id),J($e(e)),H({preset:e.id},{replace:!0}),ge(`overview`)}function nt(){Y(null),ce(``),J(ft(`blank`,t)),xe(null),H({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),H({},{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 O(t.presets,{revalidate:!1}),ce(t.presetId),Y(null),H({preset:t.presetId},{replace:!0})}else $&&await O(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 O(await ue($.id),{revalidate:!1}),Ce(!1),ce(``),Y(null),J(ft(`blank`,t)),ge(`overview`),H({},{replace:!0})}catch(e){Te(e instanceof Error?e.message:t.deleteError)}finally{ve(!1)}}}return r?(0,Z.jsxs)(G,{gap:`gap-5`,className:`pb-24`,children:[(0,Z.jsx)(W,{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)(p,{type:`button`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(I,{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,l?(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:k,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:k,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)(p,{type:`button`,variant:`secondary`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(I,{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)(E,{open:Je,onOpenChange:e=>{e||at()},children:(0,Z.jsxs)(C,{children:[(0,Z.jsx)(b,{className:f(`xopc-dialog-overlay fixed inset-0 bg-scrim`,y)}),(0,Z.jsx)(w,{ref:Oe,className:f(`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)(o,{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:f(m,`shrink-0 p-1.5 hover:bg-surface-base`),onClick:it,"aria-label":t.changeTemplate,title:t.changeTemplate,children:(0,Z.jsx)(B,{className:`size-4`,"aria-hidden":!0})}):null,(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(T,{className:`truncate text-base font-semibold text-fg`,children:Xe}),(0,Z.jsx)(x,{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)(S,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:f(m,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,Z.jsx)(ee,{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)(p,{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:f(`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:u,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:k,label:t.modelsTitle,value:String(q.modelRows.length)}),(0,Z.jsx)(mt,{icon:R,label:t.toolsTitle,value:String(Object.keys(q.toolPolicies).length)}),(0,Z.jsx)(mt,{icon:P,label:t.skillsTitle,value:t.skillModeLabels[q.skillMode]})]})]}):null,pe===`models`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:k,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:R,title:t.toolsTitle,subtitle:t.toolsHint}),(0,Z.jsx)(ze,{builtinToolIds:s?.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:P,title:t.skillsTitle,subtitle:t.skillsHint}),(0,Z.jsx)(je,{mode:q.skillMode,selected:q.skillPick,catalog:j,loading:F,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:re,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:s?.mcpServerIds??[],mcpTools:te,workflows:s?.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:ne,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)(p,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>J($e($)),children:t.discard}):null,$&&!Fe?(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>{Te(null),Ce(!0)},children:[(0,Z.jsx)(z,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,Z.jsxs)(p,{type:`button`,disabled:Q||!q.id.trim()||!q.name.trim()||!Ie,onClick:()=>void ut(),children:[(0,Z.jsx)(M,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})]})})]})}),(0,Z.jsx)(E,{open:Se,onOpenChange:e=>{Q||(Ce(e),e||Te(null))},children:(0,Z.jsxs)(C,{children:[(0,Z.jsx)(b,{className:f(`xopc-dialog-overlay fixed inset-0 bg-scrim`,y)}),(0,Z.jsxs)(w,{className:f(`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)(T,{className:`text-base font-semibold text-fg`,children:t.deleteDialogTitle}),(0,Z.jsx)(x,{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)(p,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>Ce(!1),children:t.cancel}),(0,Z.jsxs)(p,{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)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(z,{className:`size-4`,"aria-hidden":!0}),Q?t.deleting:t.delete]})]})]})]})})]}):(0,Z.jsxs)(G,{gap:`gap-3`,children:[(0,Z.jsx)(W,{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,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l={revalidateOnFocus:!1},t[0]=l):l=t[0];let{data:u,isLoading:d,error:f}=D(`capability-preset-image-generation-models`,te,l),p;t[1]===u?p=t[2]:(p=(u??[]).filter(vt).flatMap(_t),t[1]=u,t[2]=p);let m=p,h;t[3]===m?h=t[4]:(h=new Set(m.map(gt)),t[3]=m,t[4]=h);let g=h,_,v;t[5]!==g||t[6]!==u||t[7]!==r||t[8]!==n?(_=()=>{if(!u)return;let e=n.imageGenerationModel,t=g.has(e.primary)?e.primary:``,i=e.fallbacks.filter(e=>g.has(e));t===e.primary&&i.length===e.fallbacks.length||r({...n,imageGenerationModel:{...e,primary:t,fallbacks:i}})},v=[g,u,r,n],t[5]=g,t[6]=u,t[7]=r,t[8]=n,t[9]=_,t[10]=v):(_=t[9],v=t[10]),(0,X.useEffect)(_,v);let y;t[11]!==r||t[12]!==n?(y=(e,t)=>{r({...n,[e]:t})},t[11]=r,t[12]=n,t[13]=y):y=t[13];let b=y,x;t[14]===a.modelSpecializedTitle?x=t[15]:(x=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelSpecializedTitle}),t[14]=a.modelSpecializedTitle,t[15]=x);let S;t[16]!==a.modelNotSet||t[17]!==a.modelSpecializedSummary||t[18]!==n.imageGenerationModel.primary||t[19]!==n.imageModel.primary?(S=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]=S):S=t[20];let C;t[21]===S?C=t[22]:(C=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:S}),t[21]=S,t[22]=C);let w;t[23]!==x||t[24]!==C?(w=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[x,C]}),t[23]=x,t[24]=C,t[25]=w):w=t[25];let T;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,Z.jsx)(O,{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]===w?E=t[28]:(E=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[w,T]}),t[27]=w,t[28]=E);let k;t[29]===b?k=t[30]:(k=e=>b(`imageModel`,e),t[29]=b,t[30]=k);let A;t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==k||t[35]!==n.imageModel?(A=(0,Z.jsx)(yt,{title:a.imageUnderstandingTitle,value:n.imageModel,onChange:k,disabled:i,cp:a,chat:o,capabilitiesFilter:`vision`}),t[31]=o,t[32]=a,t[33]=i,t[34]=k,t[35]=n.imageModel,t[36]=A):A=t[36];let j;t[37]===b?j=t[38]:(j=e=>b(`imageGenerationModel`,e),t[37]=b,t[38]=j);let M;t[39]===a.modelImageSettingsLink?M=t[40]:(M={label:a.modelImageSettingsLink,path:`/settings/capabilities/image`},t[39]=a.modelImageSettingsLink,t[40]=M);let N;t[41]!==o||t[42]!==a||t[43]!==i||t[44]!==m||t[45]!==f||t[46]!==d||t[47]!==j||t[48]!==M||t[49]!==n.imageGenerationModel?(N=(0,Z.jsx)(yt,{title:a.imageGenerationTitle,value:n.imageGenerationModel,onChange:j,disabled:i,cp:a,chat:o,models:m,modelsLoading:d,modelsError:f,noMatches:a.modelNoConfiguredImageModels,settingsFooterLink:M}),t[41]=o,t[42]=a,t[43]=i,t[44]=m,t[45]=f,t[46]=d,t[47]=j,t[48]=M,t[49]=n.imageGenerationModel,t[50]=N):N=t[50];let P;t[51]!==A||t[52]!==N?(P=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge lg:grid-cols-2`,children:[A,N]}),t[51]=A,t[52]=N,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 ee;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,Z.jsx)(O,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[64]=ee):ee=t[64];let z;t[65]===R?z=t[66]:(z=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[R,ee]}),t[65]=R,t[66]=z);let B;t[67]===a.modelAllowFallbacksLabel?B=t[68]:(B=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelAllowFallbacksLabel}),t[67]=a.modelAllowFallbacksLabel,t[68]=B);let ne;t[69]!==r||t[70]!==n?(ne=e=>r({...n,allowFallbacks:e.target.value}),t[69]=r,t[70]=n,t[71]=ne):ne=t[71];let re;t[72]===a.policyInherit?re=t[73]:(re=(0,Z.jsx)(c,{value:``,children:a.policyInherit}),t[72]=a.policyInherit,t[73]=re);let V;t[74]===a.policyEnabled?V=t[75]:(V=(0,Z.jsx)(c,{value:`true`,children:a.policyEnabled}),t[74]=a.policyEnabled,t[75]=V);let H;t[76]===a.policyDisabled?H=t[77]:(H=(0,Z.jsx)(c,{value:`false`,children:a.policyDisabled}),t[76]=a.policyDisabled,t[77]=H);let U;t[78]!==i||t[79]!==ne||t[80]!==re||t[81]!==V||t[82]!==H||t[83]!==n.allowFallbacks?(U=(0,Z.jsxs)(s,{value:n.allowFallbacks,disabled:i,side:`top`,onChange:ne,children:[re,V,H]}),t[78]=i,t[79]=ne,t[80]=re,t[81]=V,t[82]=H,t[83]=n.allowFallbacks,t[84]=U):U=t[84];let W;t[85]!==B||t[86]!==U?(W=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[B,U]}),t[85]=B,t[86]=U,t[87]=W):W=t[87];let G;t[88]===a.modelMaxCostTierLabel?G=t[89]:(G=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelMaxCostTierLabel}),t[88]=a.modelMaxCostTierLabel,t[89]=G);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)(c,{value:``,children:a.policyInherit}),t[93]=a.policyInherit,t[94]=ae);let K;t[95]===a.costTierLow?K=t[96]:(K=(0,Z.jsx)(c,{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)(c,{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)(c,{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)(s,{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]!==G||t[110]!==ce?(le=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[G,ce]}),t[109]=G,t[110]=ce,t[111]=le):le=t[111];let ue;t[112]!==W||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:[W,le]}),t[112]=W,t[113]=le,t[114]=ue):ue=t[114];let de;t[115]!==z||t[116]!==ue?(de=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[z,ue]}),t[115]=z,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:l,capabilitiesFilter:u,models:d,modelsLoading:f,modelsError:m,noMatches:h,settingsFooterLink:g}=e,_;t[0]!==i||t[1]!==r?(_=(e,t)=>{i({...r,fallbacks:r.fallbacks.map((n,r)=>r===e?t:n)})},t[0]=i,t[1]=r,t[2]=_):_=t[2];let v=_,y;t[3]===n?y=t[4]:(y=(0,Z.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n}),t[3]=n,t[4]=y);let b=r.primary||o.modelNotSet,x;t[5]===b?x=t[6]:(x=(0,Z.jsx)(`span`,{className:`max-w-48 truncate font-mono text-xs text-fg-muted`,children:b}),t[5]=b,t[6]=x);let S;t[7]!==y||t[8]!==x?(S=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2.5`,children:[y,x]}),t[7]=y,t[8]=x,t[9]=S):S=t[9];let C;t[10]===o.modelToolPrimaryLabel?C=t[11]:(C=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolPrimaryLabel}),t[10]=o.modelToolPrimaryLabel,t[11]=C);let w=h??l.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 E;t[15]!==u||t[16]!==l.modelPlaceholder||t[17]!==l.modelSearchPlaceholder||t[18]!==a||t[19]!==d||t[20]!==m||t[21]!==f||t[22]!==g||t[23]!==w||t[24]!==T||t[25]!==r.primary?(E=(0,Z.jsx)(L,{value:r.primary,disabled:a,placeholder:l.modelPlaceholder,searchPlaceholder:l.modelSearchPlaceholder,noMatches:w,models:d,modelsLoading:f,modelsError:m,settingsFooterLink:g,capabilitiesFilter:u,className:`w-full max-w-none`,contentAlign:`start`,onChange:T}),t[15]=u,t[16]=l.modelPlaceholder,t[17]=l.modelSearchPlaceholder,t[18]=a,t[19]=d,t[20]=m,t[21]=f,t[22]=g,t[23]=w,t[24]=T,t[25]=r.primary,t[26]=E):E=t[26];let D;t[27]!==o.modelClearSelection||t[28]!==a||t[29]!==i||t[30]!==r?(D=r.primary?(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelClearSelection,onClick:()=>i({...r,primary:``}),children:(0,Z.jsx)(ee,{className:`size-4`,strokeWidth:1.75})}):null,t[27]=o.modelClearSelection,t[28]=a,t[29]=i,t[30]=r,t[31]=D):D=t[31];let O;t[32]!==E||t[33]!==D?(O=(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[E,D]}),t[32]=E,t[33]=D,t[34]=O):O=t[34];let k;t[35]!==O||t[36]!==C?(k=(0,Z.jsxs)(`div`,{className:`grid gap-1`,children:[C,O]}),t[35]=O,t[36]=C,t[37]=k):k=t[37];let A;t[38]===o.modelToolFallbacksLabel?A=t[39]:(A=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolFallbacksLabel}),t[38]=o.modelToolFallbacksLabel,t[39]=A);let j;t[40]!==i||t[41]!==r?(j=()=>i({...r,fallbacks:[...r.fallbacks,``]}),t[40]=i,t[41]=r,t[42]=j):j=t[42];let M;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Z.jsx)(I,{className:`size-3.5`,strokeWidth:1.75}),t[43]=M):M=t[43];let N;t[44]!==o.modelAddFallback||t[45]!==a||t[46]!==j?(N=(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:a,onClick:j,children:[M,o.modelAddFallback]}),t[44]=o.modelAddFallback,t[45]=a,t[46]=j,t[47]=N):N=t[47];let P;t[48]!==A||t[49]!==N?(P=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[A,N]}),t[48]=A,t[49]=N,t[50]=P):P=t[50];let F;t[51]!==u||t[52]!==l.modelNoMatches||t[53]!==l.modelSearchPlaceholder||t[54]!==o.modelFallbackEmptyHint||t[55]!==o.modelFallbackPlaceholder||t[56]!==o.modelRemoveFallback||t[57]!==a||t[58]!==d||t[59]!==m||t[60]!==f||t[61]!==h||t[62]!==i||t[63]!==g||t[64]!==v||t[65]!==r?(F=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)(L,{value:e,disabled:a,placeholder:o.modelFallbackPlaceholder,searchPlaceholder:l.modelSearchPlaceholder,noMatches:h??l.modelNoMatches,models:d,modelsLoading:f,modelsError:m,settingsFooterLink:g,capabilitiesFilter:u,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>v(t,e)}),(0,Z.jsx)(p,{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)(z,{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]=u,t[52]=l.modelNoMatches,t[53]=l.modelSearchPlaceholder,t[54]=o.modelFallbackEmptyHint,t[55]=o.modelFallbackPlaceholder,t[56]=o.modelRemoveFallback,t[57]=a,t[58]=d,t[59]=m,t[60]=f,t[61]=h,t[62]=i,t[63]=g,t[64]=v,t[65]=r,t[66]=F):F=t[66];let R;t[67]!==P||t[68]!==F?(R=(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[P,F]}),t[67]=P,t[68]=F,t[69]=R):R=t[69];let te;t[70]!==i||t[71]!==r?(te=e=>i({...r,timeoutMs:e.target.value}),t[70]=i,t[71]=r,t[72]=te):te=t[72];let B;t[73]!==a||t[74]!==te||t[75]!==r.timeoutMs?(B=(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:te}),t[73]=a,t[74]=te,t[75]=r.timeoutMs,t[76]=B):B=t[76];let ne;t[77]!==o.toolTimeoutLabel||t[78]!==B?(ne=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.toolTimeoutLabel,B]}),t[77]=o.toolTimeoutLabel,t[78]=B,t[79]=ne):ne=t[79];let re;t[80]!==i||t[81]!==r?(re=e=>i({...r,autoProviderFallback:e.target.value}),t[80]=i,t[81]=r,t[82]=re):re=t[82];let V;t[83]===o.policyInherit?V=t[84]:(V=(0,Z.jsx)(c,{value:``,children:o.policyInherit}),t[83]=o.policyInherit,t[84]=V);let H;t[85]===o.policyEnabled?H=t[86]:(H=(0,Z.jsx)(c,{value:`true`,children:o.policyEnabled}),t[85]=o.policyEnabled,t[86]=H);let U;t[87]===o.policyDisabled?U=t[88]:(U=(0,Z.jsx)(c,{value:`false`,children:o.policyDisabled}),t[87]=o.policyDisabled,t[88]=U);let W;t[89]!==a||t[90]!==re||t[91]!==V||t[92]!==H||t[93]!==U||t[94]!==r.autoProviderFallback?(W=(0,Z.jsxs)(s,{value:r.autoProviderFallback,disabled:a,side:`top`,onChange:re,children:[V,H,U]}),t[89]=a,t[90]=re,t[91]=V,t[92]=H,t[93]=U,t[94]=r.autoProviderFallback,t[95]=W):W=t[95];let G;t[96]!==o.modelAutoProviderFallbackLabel||t[97]!==W?(G=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.modelAutoProviderFallbackLabel,W]}),t[96]=o.modelAutoProviderFallbackLabel,t[97]=W,t[98]=G):G=t[98];let ie;t[99]!==ne||t[100]!==G?(ie=(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ne,G]}),t[99]=ne,t[100]=G,t[101]=ie):ie=t[101];let ae;t[102]!==k||t[103]!==R||t[104]!==ie?(ae=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-3 dark:border-edge`,children:[k,R,ie]}),t[102]=k,t[103]=R,t[104]=ie,t[105]=ae):ae=t[105];let K;return t[106]!==ae||t[107]!==S?(K=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 shadow-surface`,children:[S,ae]}),t[106]=ae,t[107]=S,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{i as o,t as s}from"./popover-select-BzdnTy3h.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./loader-circle-CifKLtgG.js";import{t as u}from"./cn-JdwAhgNB.js";import{t as d}from"./button-CSEbl4zT.js";import{t as f}from"./interaction-BmQogeqz.js";import{t as p}from"./messages-D7kOD_o_.js";import{l as m,n as h,o as g,r as _,s as v}from"./locale-store-CnamlR07.js";import{i as y,o as b}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as x,i as S,n as C,o as w,r as T,s as E,t as D}from"./dist-BPoKqzeH.js";import{i as O}from"./vendor-swr-BIWyz7Rc.js";import{An as k,As as A,Bs as j,Dl as M,Is as N,Ma as P,Na as F,Pa as I,Ri as L,Tl as R,Wa as z,Xn as B,Yn as ee,Yo as te,Zn as ne,_s as re,ai as ie,cs as ae}from"./index-DRrjYYzZ.js";import{n as oe,r as se}from"./settings-page-layout-BRQNel6r.js";import{n as ce}from"./settings-loading-skeleton-zwibve4m.js";import{t as le}from"./schema-form-C_OBW8A5.js";import{t as ue}from"./browser-BLJWD7WI.js";import{n as de,t as fe}from"./channels-status-swr-DNDvMWpl.js";var V=e(t(),1),H=n();function pe(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 me=e(ue(),1),U=r();async function he(e){let t=await g(_(`/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 W(e){return e?.type===`poll`&&e.phase===`done`}function G(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function K(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function q(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function ge({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,V.useMemo)(()=>pe(e),[e]),o=(0,V.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[s,f]=(0,V.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,V.useEffect)(()=>{f({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let p=(0,V.useCallback)(async(n,i)=>{f(e=>({...e,busy:!0,error:null}));try{let a=await he({channelId:e.id,actionId:n,locale:t,input:i});f(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){f(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,V.useEffect)(()=>{let t=K(s.payload,e.id);if(!t){f(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return f(e=>e.generatedQr?{...e,generatedQr:null}:e),me.toDataURL(t,{width:220,margin:1}).then(e=>{n||f(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,s.payload]),(0,V.useEffect)(()=>{let n=s.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||he({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(f(t=>({...t,payload:e,poll:W(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),W(e)&&window.clearInterval(a))}).catch(e=>{i||f(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,s.poll]);let m=a?.[1].label??(e.configured?n.reconnect:n.connect),h=e.actions?.[`doctor.run`]?.label??n.diagnose,g=G(s.payload),_=K(s.payload,e.id),v=_?s.generatedQr:q(s.payload),y=a?.[1].result===`qr`&&(s.busy||s.payload?.type===`qr`||s.payload?.type===`poll`),b=s.payload?.type===`form`?s.payload:null,x=s.payload?.type===`diagnostics`?s.payload.checks:null;return(0,U.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:u(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,U.jsxs)(d,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void p(a[0]),children:[s.busy?(0,U.jsx)(l,{className:`size-4 animate-spin`}):(0,U.jsx)(j,{className:`size-4`}),m]}):null,e.actions?.[`doctor.run`]?(0,U.jsxs)(d,{type:`button`,variant:`secondary`,disabled:s.busy,onClick:()=>void p(`doctor.run`),children:[(0,U.jsx)(re,{className:`size-4`}),h]}):null]})]}),g?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:g}):null,s.error?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:s.error}):null,y?(0,U.jsxs)(`div`,{className:u(`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,U.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:v?(0,U.jsx)(`img`,{src:v,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,U.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,U.jsx)(F,{className:`size-48 rounded-md`})})}),(0,U.jsxs)(`div`,{className:u(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[v?(0,U.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,U.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,U.jsx)(F,{className:`h-4 w-48 max-w-full`}),(0,U.jsx)(F,{className:`h-4 w-36 max-w-full`})]}),_?(0,U.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:_,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,U.jsx)(c,{className:`size-3.5`})]}):null]})]}):null,s.payload?.type===`poll`&&s.payload.phase===`done`?(0,U.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,U.jsx)(R,{className:s.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,U.jsx)(`span`,{className:s.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:s.payload.message??(s.payload.ok?n.complete:n.failed)})]}):null,b?(0,U.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,U.jsx)(le,{schema:b.schema,values:s.formDraft,onChange:e=>f(t=>({...t,formDraft:e})),disabled:s.busy,labels:o}),(0,U.jsx)(d,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void p(b.submitAction,s.formDraft),children:n.saveSetup})]}):null,x?(0,U.jsx)(`div`,{className:`mt-4 space-y-2`,children:x.map((e,t)=>(0,U.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,U.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,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var _e=40;function J(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function ve(e,t){return e.find(e=>e.id===J(t))?.agentId?.trim().toLowerCase()??``}function ye(e,t,n){let r=J(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:_e,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function be(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 xe(e,t,n){let r=be(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function Se(e,t=!1){return e===`drawer`?u(`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`,y):u(`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)]`,y,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Ce(e){let t=(0,H.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:s,srTitle:c,srDescription:l,closeAriaLabel:p,children:m,footer:h,wide:g,headerExtra:_}=e,v=g===void 0?!1:g,y=n===`drawer`,[O,k]=(0,V.useState)(null),A;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,U.jsx)(x,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,b)}),t[0]=A):A=t[0];let j;t[1]!==n||t[2]!==v?(j=Se(n,v),t[1]=n,t[2]=v,t[3]=j):j=t[3];let M;t[4]===c?M=t[5]:(M=c?(0,U.jsx)(E,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=M);let N;t[6]===l?N=t[7]:(N=l?(0,U.jsx)(S,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=N);let P;t[8]!==p||t[9]!==s||t[10]!==_||t[11]!==y||t[12]!==a?(P=y?(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,U.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,s?(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,U.jsx)(C,{asChild:!0,children:(0,U.jsx)(d,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":p,children:(0,U.jsx)(te,{className:`size-5`,strokeWidth:1.75})})})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(C,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,className:u(f,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":p,children:(0,U.jsx)(te,{className:`size-4`})})}),_]}),t[8]=p,t[9]=s,t[10]=_,t[11]=y,t[12]=a,t[13]=P):P=t[13];let F=y?`p-4`:`p-6`,I;t[14]===F?I=t[15]:(I=u(`min-h-0 flex-1 overflow-y-auto`,F),t[14]=F,t[15]=I);let L;t[16]!==m||t[17]!==I?(L=(0,U.jsx)(`div`,{className:I,children:m}),t[16]=m,t[17]=I,t[18]=L):L=t[18];let R;t[19]!==h||t[20]!==O||t[21]!==M||t[22]!==N||t[23]!==P||t[24]!==L?(R=(0,U.jsxs)(o,{layer:`modal`,portalContainer:O,children:[M,N,P,L,h]}),t[19]=h,t[20]=O,t[21]=M,t[22]=N,t[23]=P,t[24]=L,t[25]=R):R=t[25];let z;t[26]!==R||t[27]!==j?(z=(0,U.jsxs)(w,{children:[A,(0,U.jsx)(T,{ref:k,className:j,onOpenAutoFocus:we,children:R})]}),t[26]=R,t[27]=j,t[28]=z):z=t[28];let B;return t[29]!==i||t[30]!==r||t[31]!==z?(B=(0,U.jsx)(D,{open:r,onOpenChange:i,children:z}),t[29]=i,t[30]=r,t[31]=z,t[32]=B):B=t[32],B}function we(e){return e.preventDefault()}var Te=(0,V.memo)(function(e){let t=(0,H.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,U.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,U.jsx)(L,{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,U.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 Ee(e){let t=(0,H.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,U.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 f;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(f=l?(0,U.jsx)(d,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=f):f=t[6];let p=!r||i,m;t[7]!==n.discard||t[8]!==o||t[9]!==p?(m=(0,U.jsx)(d,{type:`button`,variant:`secondary`,disabled:p,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=p,t[10]=m):m=t[10];let h=!r||i,g;t[11]===s?g=t[12]:(g=()=>void s(),t[11]=s,t[12]=g);let _=i?n.saving:n.save,v;t[13]!==h||t[14]!==g||t[15]!==_?(v=(0,U.jsx)(d,{type:`button`,variant:`primary`,disabled:h,onClick:g,children:_}),t[13]=h,t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==f||t[18]!==m||t[19]!==v?(y=(0,U.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[f,m,v]}),t[17]=f,t[18]=m,t[19]=v,t[20]=y):y=t[20];let b;return t[21]!==y||t[22]!==u?(b=(0,U.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,y]}),t[21]=y,t[22]=u,t[23]=b):b=t[23],b}function De(e){return _(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function Oe(e){return(await v(De(e))).payload?.channels??[]}function ke(e,t){let n=(0,H.c)(14),r;n[0]!==e||n[1]!==t?(r=e?De(t):null,n[0]=e,n[1]=t,n[2]=r):r=n[2];let i;n[3]===t?i=n[4]:(i=()=>Oe(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}=O(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 Ae=`channels-status`;function je(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function Me(e){let t=t=>e(t.detail);return window.addEventListener(Ae,t),()=>window.removeEventListener(Ae,t)}function Ne(e,t){let n=(0,H.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return Me(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,V.useEffect)(i,a)}function Pe(e){return e?_(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Fe(e){return(await v(_(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Ie=[`enabled`];async function Le(){let e=await v(_(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Re(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function ze(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function Y(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){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function Ve(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function He(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 Ue(e){if(!e)return[];let t=e.uiHints??{},n=X(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=Y(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!X(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Ie.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Ie.includes(e))}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function We(e,t){let n={...Z(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(!X(r)||!X(r[n]))break;let o=X(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Z(r[n]),properties:{}}),e===t.length-1){o[n]=Z(r[n]);break}i=r[n],a=o[n]}}return n}function Ge(e){let t=e.properties;if(!X(t))return!1;for(let[e,n]of Object.entries(t))X(n)&&n.type===`object`&&Ge(n)&&delete t[e];return Object.keys(t).length===0}function Ke(e,t){let n=Z(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!X(i))break;if(e===t.length-1){delete i[n];break}if(!X(i[n]))break;r=i[n]}}return Ge(n),n}function qe(e){return e.type===`object`&&X(e.properties)&&Object.keys(e.properties).length>0}function Je(e,t){let n=e;for(let e of t.split(`.`)){if(!X(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return X(t)?Object.values(t).filter(e=>X(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=Y(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=Y(e),r=pe(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=pe(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=m(e=>e.token),[n,r]=(0,V.useState)(!1),i=(0,V.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(_(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Re(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,U.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,U.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,U.jsx)(I,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,H.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,o;t[0]===i?o=t[1]:(o=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=o);let s=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,c=r&&`cursor-not-allowed opacity-60`,l;t[2]!==s||t[3]!==c?(l=u(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,s,c),t[2]=s,t[3]=c,t[4]=l):l=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=u(`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,U.jsx)(`span`,{className:f}),t[7]=f,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==o||t[13]!==l||t[14]!==p?(m=(0,U.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:o,className:l,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=o,t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function rt(e){let t=(0,H.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:o,ch:s,onOpen:c,onToggle:f,onRestart:p}=e,m;t[0]===n?m=t[1]:(m=Y(n),t[0]=n,t[1]=m);let h=m,g,_,v,y,b,x,S;if(t[2]!==a||t[3]!==s||t[4]!==r||t[5]!==n||t[6]!==c||t[7]!==p||t[8]!==f||t[9]!==i||t[10]!==h.enabled||t[11]!==h.ready){let e=Xe(n,r,s),o=$e(n,s);g=!h.enabled&&h.ready?f:i===`stopped`?p:c,x=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let l;t[19]===n?l=t[20]:(l=(0,U.jsx)(tt,{entry:n}),t[19]=n,t[20]=l);let d;t[21]===n.label?d=t[22]:(d=(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=d);let m;t[23]===i?m=t[24]:(m=u(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,He(i)),t[23]=i,t[24]=m);let C;t[25]!==s||t[26]!==i?(C=Be(i,s),t[25]=s,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==m||t[29]!==C?(w=(0,U.jsx)(`span`,{className:m,children:C}),t[28]=m,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==d?(T=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[d,w]}),t[31]=w,t[32]=d,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==l?(E=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[l,T]}),t[34]=T,t[35]=l,t[36]=E):E=t[36];let D=h.enabled,O;t[37]!==s.toggleChannel||t[38]!==n.label?(O=s.toggleChannel.replace(`{{channel}}`,n.label),t[37]=s.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==f||t[42]!==h.enabled||t[43]!==O?(k=(0,U.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:f}),t[40]=a,t[41]=f,t[42]=h.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(S=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=S):S=t[47],_=`button`,v=c,y=`mt-5 min-h-[6.25rem] text-left`,b=h.ready?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,U.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map($)}):null]}):(0,U.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:s.cardSetupTitle}),(0,U.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Qe(n,s)}),o.length>0?(0,U.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:o.map(it)}):null]}),t[2]=a,t[3]=s,t[4]=r,t[5]=n,t[6]=c,t[7]=p,t[8]=f,t[9]=i,t[10]=h.enabled,t[11]=h.ready,t[12]=g,t[13]=_,t[14]=v,t[15]=y,t[16]=b,t[17]=x,t[18]=S}else g=t[12],_=t[13],v=t[14],y=t[15],b=t[16],x=t[17],S=t[18];let C;t[48]!==_||t[49]!==v||t[50]!==y||t[51]!==b?(C=(0,U.jsx)(`button`,{type:_,onClick:v,className:y,children:b}),t[48]=_,t[49]=v,t[50]=y,t[51]=b,t[52]=C):C=t[52];let w=a||o,T;t[53]!==a||t[54]!==o?(T=a||o?(0,U.jsx)(l,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=o,t[55]=T):T=t[55];let E;t[56]!==s||t[57]!==n||t[58]!==o||t[59]!==i?(E=o?s.restartingChannel:i===`stopped`?s.restartChannel:Ze(n,s),t[56]=s,t[57]=n,t[58]=o,t[59]=i,t[60]=E):E=t[60];let D;t[61]!==g||t[62]!==T||t[63]!==E||t[64]!==w?(D=(0,U.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,U.jsxs)(d,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:g,disabled:w,children:[T,E]})}),t[61]=g,t[62]=T,t[63]=E,t[64]=w,t[65]=D):D=t[65];let O;return t[66]!==D||t[67]!==x||t[68]!==S||t[69]!==C?(O=(0,U.jsxs)(`article`,{className:x,children:[S,C,D]}),t[66]=D,t[67]=x,t[68]=S,t[69]=C,t[70]=O):O=t[70],O}function it(e){return(0,U.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,U.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function at(e){let t=(0,H.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:o,ch:s,onRestart:c,onCheck:f,onManageConnection:p}=e,m=n===`running`?R:n===`stopped`||n===`needs_setup`?M:l,h=n===`running`&&`text-emerald-600 dark:text-emerald-400`,g=n===`stopped`&&`text-red-600 dark:text-red-400`,_=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,v=n===`disabled`&&`text-fg-muted`,y=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,b;t[0]!==h||t[1]!==g||t[2]!==_||t[3]!==v||t[4]!==y?(b=u(`mt-0.5 size-5 shrink-0`,h,g,_,v,y),t[0]=h,t[1]=g,t[2]=_,t[3]=v,t[4]=y,t[5]=b):b=t[5];let x;t[6]!==m||t[7]!==b?(x=(0,U.jsx)(m,{className:b}),t[6]=m,t[7]=b,t[8]=x):x=t[8];let S;t[9]===s.connectionStatus?S=t[10]:(S=(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:s.connectionStatus}),t[9]=s.connectionStatus,t[10]=S);let C;t[11]!==s||t[12]!==n?(C=Ve(n,s),t[11]=s,t[12]=n,t[13]=C):C=t[13];let w;t[14]===C?w=t[15]:(w=(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:C}),t[14]=C,t[15]=w);let T;t[16]!==w||t[17]!==S?(T=(0,U.jsxs)(`div`,{children:[S,w]}),t[16]=w,t[17]=S,t[18]=T):T=t[18];let E;t[19]!==T||t[20]!==x?(E=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[x,T]}),t[19]=T,t[20]=x,t[21]=E):E=t[21];let D=i||r,O;t[22]===i?O=t[23]:(O=i?(0,U.jsx)(l,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=O);let k=i?s.checkingConnection:s.checkConnection,A;t[24]!==f||t[25]!==D||t[26]!==O||t[27]!==k?(A=(0,U.jsxs)(d,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:D,onClick:f,children:[O,k]}),t[24]=f,t[25]=D,t[26]=O,t[27]=k,t[28]=A):A=t[28];let j;t[29]!==s.restartChannel||t[30]!==s.restartingChannel||t[31]!==i||t[32]!==c||t[33]!==r||t[34]!==n?(j=n===`stopped`?(0,U.jsxs)(d,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:c,children:[r?(0,U.jsx)(l,{className:`size-4 animate-spin`}):(0,U.jsx)(N,{className:`size-4`}),r?s.restartingChannel:s.restartChannel]}):null,t[29]=s.restartChannel,t[30]=s.restartingChannel,t[31]=i,t[32]=c,t[33]=r,t[34]=n,t[35]=j):j=t[35];let P;t[36]!==o||t[37]!==s.connectionOptions||t[38]!==s.hideConnectionOptions||t[39]!==i||t[40]!==p||t[41]!==r||t[42]!==a?(P=o?(0,U.jsx)(d,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:p,children:a?s.hideConnectionOptions:s.connectionOptions}):null,t[36]=o,t[37]=s.connectionOptions,t[38]=s.hideConnectionOptions,t[39]=i,t[40]=p,t[41]=r,t[42]=a,t[43]=P):P=t[43];let F;t[44]!==A||t[45]!==j||t[46]!==P?(F=(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[A,j,P]}),t[44]=A,t[45]=j,t[46]=P,t[47]=F):F=t[47];let I;return t[48]!==E||t[49]!==F?(I=(0,U.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[E,F]})}),t[48]=E,t[49]=F,t[50]=I):I=t[50],I}function ot(e){let t=(0,H.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=Y(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,U.jsx)(ae,{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,U.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,U.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,U.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,U.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,U.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,U.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,U.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function st(){let e=h(e=>e.language),t=p(e),n=m(e=>!!e.token),r=a(),{channelId:o}=i(),l=ne(o),d=ke(n,e),f=d.entries,{data:v,mutate:y,isValidating:b}=O(n?fe():null,de,{revalidateOnFocus:!0}),{data:x,mutate:S}=O(n?`channels-config-map`:null,Le,{revalidateOnFocus:!1}),C=x?.channels??{},w=x?.bindings??[],{data:T}=O(n?`channel-routing-agents`:null,P,{revalidateOnFocus:!1}),E=z(e=>e.setPageHeader),D=z(e=>e.clearPageHeader),j=(0,V.useMemo)(()=>f.find(e=>e.id===l),[l,f]),M=j?ze(j):null,{data:N,mutate:F}=O(n&&M?Pe(M):null,()=>Fe(M)),[I,L]=(0,V.useState)(null),[R,te]=(0,V.useState)(!1),[re,ae]=(0,V.useState)(null),[ue,H]=(0,V.useState)(null),[me,he]=(0,V.useState)(!1),[W,G]=(0,V.useState)(null),[K,q]=(0,V.useState)(null),_e=I??N??{},J=t.channelsSettings,be=(0,V.useMemo)(()=>j?.configSchema??{type:`object`,properties:{}},[j?.configSchema]),Se=(0,V.useMemo)(()=>Ke(be,Ie),[be]),we=(0,V.useMemo)(()=>Ue(j),[j]),De=(0,V.useMemo)(()=>We(Se,we),[we,Se]),Oe=(0,V.useMemo)(()=>Ke(Se,we),[we,Se]),Ae=(0,V.useMemo)(()=>qe(De),[De]),Me=j?K??ve(w,j.id):``,Re=(0,V.useMemo)(()=>(T?.items??[]).map(e=>{let n=k(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[T?.items,t.agentsSettings]),Ve=T?.items.find(e=>e.id===T.defaultId),X=Ve?k(Ve,t.agentsSettings):T?.defaultId??``,Z=(0,V.useMemo)(()=>({defaultBooleanLabel:J.schemaBooleanDefault,unsupportedArrayType:J.schemaUnsupportedArrayType,arrayAddPlaceholder:J.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>J.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[J]),Ge=(0,V.useMemo)(()=>new Map((v??[]).map(e=>[e.name,e])),[v]),Je=v!==void 0,Ye=(0,V.useCallback)(e=>xe(e,Ge.get(e.id),Je),[Ge,Je]),Q=(0,V.useCallback)(async()=>{await Promise.all([d.mutate(),y()])},[d,y]);Ne((0,V.useCallback)(e=>{let t=je(e);t&&y(t,!1)},[y]),n);let Xe=(0,V.useMemo)(()=>n?(0,U.jsx)(Te,{ch:J,refreshing:d.isValidating||b,saveOk:!1,onRefresh:()=>void Q()}):null,[d.isValidating,J,n,b,Q]);(0,V.useLayoutEffect)(()=>(E({startExtra:null,main:(0,U.jsx)(`div`,{className:`min-w-0`,children:(0,U.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>D()),[D,Xe,t.settingsSections.channels,E]);let Ze=(0,V.useCallback)(e=>{r(B(e)),L(null),q(null),G(null)},[r]),Qe=(0,V.useCallback)(()=>{r(ee),L(null),q(null),G(null)},[r]),$e=(0,V.useCallback)(async e=>{H(e.id),G(null);try{let t=await g(_(`/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){G(e instanceof Error?e.message:String(e))}finally{H(null)}},[Q]);(0,V.useEffect)(()=>{q(null),he(!1)},[j?.id]);let et=(0,V.useCallback)(async()=>{if(!j||!I&&K===null)return!1;let e=ze(j);te(!0),G(null);try{let t=await g(_(`/api/config`),{method:`PATCH`,body:JSON.stringify({...I?{channels:{[e]:I}}:{},...K===null?{}:{bindings:ye(w,j.id,K)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return I&&await F(I,!1),await S(),await d.mutate(),L(null),q(null),!0}catch(e){return G(e instanceof Error?e.message:String(e)),!1}finally{te(!1)}},[j,K,w,d,I,S,F]),it=(0,V.useCallback)(async e=>{let t=Y(e),n=ze(e),r=j?.id===e.id?I:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}ae(e.id),G(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await g(_(`/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 d.mutate(),await S(),await y(),j?.id===e.id&&(await F(),L(null))}catch(e){G(e instanceof Error?e.message:String(e))}finally{ae(null)}},[j?.id,d,I,S,F,y,Ze]),$=j?.ui?.modal,st=$?.placement!==`replace-config`,ct=j?Ye(j):`checking`,lt=j?!Y(j).ready||me:!1;return n?(0,U.jsxs)(se,{gap:`gap-4`,children:[d.isLoading?(0,U.jsx)(ce,{sections:2}):d.error?(0,U.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(d.error)}):(0,U.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:f.map(e=>(0,U.jsx)(rt,{entry:e,config:C[ze(e)]?.config,runtime:Ye(e),busy:re===e.id,restarting:ue===e.id,ch:J,onOpen:()=>Ze(e.id),onToggle:()=>void it(e),onRestart:()=>void $e(e)},e.id))}),W?(0,U.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:W}):null,(0,U.jsx)(Ce,{presentation:`modal`,open:!!j,onOpenChange:e=>{e||Qe()},closeAriaLabel:J.close,srTitle:j?.label??J.selectChannel,srDescription:j?.description,wide:!0,footer:j?(0,U.jsx)(Ee,{ch:J,dirty:!!I||K!==null,saving:R,onCancel:Qe,onDiscard:()=>{L(null),q(null)},onSave:et}):null,children:j?(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,U.jsx)(tt,{entry:j}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:j.label}),(0,U.jsx)(`span`,{className:u(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,He(ct)),children:Be(ct,J)})]}),(0,U.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,U.jsx)(`span`,{className:`min-w-0 truncate`,children:!Y(j).ready&&pe(j)?.[1].result===`qr`?J.scanLoginHint.replace(`{{channel}}`,j.label):j.description}),j.docsPath?(0,U.jsxs)(`a`,{href:j.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[J.docs,(0,U.jsx)(c,{className:`size-3.5`})]}):null]})]})]}),(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,U.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:Y(j).enabled?J.enabledLabel:J.disabledLabel}),(0,U.jsx)(nt,{checked:Y(j).enabled,disabled:re===j.id,label:J.toggleChannel.replace(`{{channel}}`,j.label),onToggle:()=>void it(j)})]})]})}),(0,U.jsx)(at,{runtime:ct,restarting:ue===j.id,checking:b,showConnectionOptions:me,canManageConnection:Y(j).ready&&$?.placement!==`replace-config`,ch:J,onRestart:()=>void $e(j),onCheck:()=>void Q(),onManageConnection:()=>he(e=>!e)}),(0,U.jsx)(ot,{entry:j,ch:J}),lt&&$?.placement!==`replace-config`?(0,U.jsx)(ge,{entry:j,locale:e,messages:J,compact:!0,onChanged:async()=>{await F(),await Q(),await S()}},j.id):null,$?.entrypoint&&$.placement===`before-config`?(0,U.jsx)(ie,{extensionId:j.extensionId,extensionName:j.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:j.id,entry:j,config:_e}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,U.jsx)(ie,{extensionId:j.extensionId,extensionName:j.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:j.id,entry:j,config:_e}}):null,st&&Ae?(0,U.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`mb-4`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:J.basicConfiguration}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:J.basicConfigurationHint})]}),(0,U.jsx)(le,{schema:De,values:_e,onChange:e=>L(e),disabled:R,labels:Z})]}):null,(0,U.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,U.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,U.jsx)(A,{className:`size-4 text-fg-muted`}),J.messageHandling]}),(0,U.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,U.jsxs)(`div`,{className:`mb-3`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:J.agentRouting}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:J.messageHandlingHint})]}),(0,U.jsx)(s,{value:Me,options:Re,placeholder:J.agentRoutingSelect,emptyLabel:J.agentRoutingDefault.replace(`{{agent}}`,X||J.agentRoutingSelect),ariaLabel:J.agentRouting,disabled:R||!T,onChange:e=>q(e)})]})]}),st&&qe(Oe)?(0,U.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,U.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,U.jsx)(A,{className:`size-4 text-fg-muted`}),J.advancedConfiguration]}),(0,U.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,U.jsx)(le,{schema:Oe,values:_e,onChange:e=>L(e),disabled:R,labels:Z})})]}):null,W?(0,U.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:W}):null]}):null})]}):(0,U.jsxs)(se,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,U.jsx)(oe,{title:t.settingsSections.channels}),(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:J.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{i as o,t as s}from"./popover-select-BzdnTy3h.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./loader-circle-CifKLtgG.js";import{t as u}from"./cn-JdwAhgNB.js";import{t as d}from"./button-CSEbl4zT.js";import{t as f}from"./interaction-BmQogeqz.js";import{t as p}from"./messages-D7kOD_o_.js";import{l as m,n as h,o as g,r as _,s as v}from"./locale-store-CnamlR07.js";import{i as y,o as b}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as x,i as S,n as C,o as w,r as T,s as E,t as D}from"./dist-BPoKqzeH.js";import{i as O}from"./vendor-swr-BIWyz7Rc.js";import{An as k,As as A,Bs as j,Dl as M,Is as N,Ma as P,Na as F,Pa as I,Ri as L,Tl as R,Wa as z,Xn as B,Yn as ee,Yo as te,Zn as ne,_s as re,ai as ie,cs as ae}from"./index-CKSplmFw.js";import{n as oe,r as se}from"./settings-page-layout-BRQNel6r.js";import{n as ce}from"./settings-loading-skeleton-Bqi7tsXj.js";import{t as le}from"./schema-form-BDLYItBP.js";import{t as ue}from"./browser-BLJWD7WI.js";import{n as de,t as fe}from"./channels-status-swr-DNDvMWpl.js";var V=e(t(),1),H=n();function pe(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 me=e(ue(),1),U=r();async function he(e){let t=await g(_(`/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 W(e){return e?.type===`poll`&&e.phase===`done`}function G(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function K(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function q(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function ge({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,V.useMemo)(()=>pe(e),[e]),o=(0,V.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[s,f]=(0,V.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,V.useEffect)(()=>{f({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let p=(0,V.useCallback)(async(n,i)=>{f(e=>({...e,busy:!0,error:null}));try{let a=await he({channelId:e.id,actionId:n,locale:t,input:i});f(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){f(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,V.useEffect)(()=>{let t=K(s.payload,e.id);if(!t){f(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return f(e=>e.generatedQr?{...e,generatedQr:null}:e),me.toDataURL(t,{width:220,margin:1}).then(e=>{n||f(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,s.payload]),(0,V.useEffect)(()=>{let n=s.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||he({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(f(t=>({...t,payload:e,poll:W(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),W(e)&&window.clearInterval(a))}).catch(e=>{i||f(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,s.poll]);let m=a?.[1].label??(e.configured?n.reconnect:n.connect),h=e.actions?.[`doctor.run`]?.label??n.diagnose,g=G(s.payload),_=K(s.payload,e.id),v=_?s.generatedQr:q(s.payload),y=a?.[1].result===`qr`&&(s.busy||s.payload?.type===`qr`||s.payload?.type===`poll`),b=s.payload?.type===`form`?s.payload:null,x=s.payload?.type===`diagnostics`?s.payload.checks:null;return(0,U.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:u(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,U.jsxs)(d,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void p(a[0]),children:[s.busy?(0,U.jsx)(l,{className:`size-4 animate-spin`}):(0,U.jsx)(j,{className:`size-4`}),m]}):null,e.actions?.[`doctor.run`]?(0,U.jsxs)(d,{type:`button`,variant:`secondary`,disabled:s.busy,onClick:()=>void p(`doctor.run`),children:[(0,U.jsx)(re,{className:`size-4`}),h]}):null]})]}),g?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:g}):null,s.error?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:s.error}):null,y?(0,U.jsxs)(`div`,{className:u(`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,U.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:v?(0,U.jsx)(`img`,{src:v,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,U.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,U.jsx)(F,{className:`size-48 rounded-md`})})}),(0,U.jsxs)(`div`,{className:u(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[v?(0,U.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,U.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,U.jsx)(F,{className:`h-4 w-48 max-w-full`}),(0,U.jsx)(F,{className:`h-4 w-36 max-w-full`})]}),_?(0,U.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:_,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,U.jsx)(c,{className:`size-3.5`})]}):null]})]}):null,s.payload?.type===`poll`&&s.payload.phase===`done`?(0,U.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,U.jsx)(R,{className:s.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,U.jsx)(`span`,{className:s.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:s.payload.message??(s.payload.ok?n.complete:n.failed)})]}):null,b?(0,U.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,U.jsx)(le,{schema:b.schema,values:s.formDraft,onChange:e=>f(t=>({...t,formDraft:e})),disabled:s.busy,labels:o}),(0,U.jsx)(d,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void p(b.submitAction,s.formDraft),children:n.saveSetup})]}):null,x?(0,U.jsx)(`div`,{className:`mt-4 space-y-2`,children:x.map((e,t)=>(0,U.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,U.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,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var _e=40;function J(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function ve(e,t){return e.find(e=>e.id===J(t))?.agentId?.trim().toLowerCase()??``}function ye(e,t,n){let r=J(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:_e,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function be(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 xe(e,t,n){let r=be(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function Se(e,t=!1){return e===`drawer`?u(`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`,y):u(`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)]`,y,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Ce(e){let t=(0,H.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:s,srTitle:c,srDescription:l,closeAriaLabel:p,children:m,footer:h,wide:g,headerExtra:_}=e,v=g===void 0?!1:g,y=n===`drawer`,[O,k]=(0,V.useState)(null),A;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,U.jsx)(x,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,b)}),t[0]=A):A=t[0];let j;t[1]!==n||t[2]!==v?(j=Se(n,v),t[1]=n,t[2]=v,t[3]=j):j=t[3];let M;t[4]===c?M=t[5]:(M=c?(0,U.jsx)(E,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=M);let N;t[6]===l?N=t[7]:(N=l?(0,U.jsx)(S,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=N);let P;t[8]!==p||t[9]!==s||t[10]!==_||t[11]!==y||t[12]!==a?(P=y?(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,U.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,s?(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,U.jsx)(C,{asChild:!0,children:(0,U.jsx)(d,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":p,children:(0,U.jsx)(te,{className:`size-5`,strokeWidth:1.75})})})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(C,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,className:u(f,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":p,children:(0,U.jsx)(te,{className:`size-4`})})}),_]}),t[8]=p,t[9]=s,t[10]=_,t[11]=y,t[12]=a,t[13]=P):P=t[13];let F=y?`p-4`:`p-6`,I;t[14]===F?I=t[15]:(I=u(`min-h-0 flex-1 overflow-y-auto`,F),t[14]=F,t[15]=I);let L;t[16]!==m||t[17]!==I?(L=(0,U.jsx)(`div`,{className:I,children:m}),t[16]=m,t[17]=I,t[18]=L):L=t[18];let R;t[19]!==h||t[20]!==O||t[21]!==M||t[22]!==N||t[23]!==P||t[24]!==L?(R=(0,U.jsxs)(o,{layer:`modal`,portalContainer:O,children:[M,N,P,L,h]}),t[19]=h,t[20]=O,t[21]=M,t[22]=N,t[23]=P,t[24]=L,t[25]=R):R=t[25];let z;t[26]!==R||t[27]!==j?(z=(0,U.jsxs)(w,{children:[A,(0,U.jsx)(T,{ref:k,className:j,onOpenAutoFocus:we,children:R})]}),t[26]=R,t[27]=j,t[28]=z):z=t[28];let B;return t[29]!==i||t[30]!==r||t[31]!==z?(B=(0,U.jsx)(D,{open:r,onOpenChange:i,children:z}),t[29]=i,t[30]=r,t[31]=z,t[32]=B):B=t[32],B}function we(e){return e.preventDefault()}var Te=(0,V.memo)(function(e){let t=(0,H.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,U.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,U.jsx)(L,{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,U.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 Ee(e){let t=(0,H.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,U.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 f;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(f=l?(0,U.jsx)(d,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=f):f=t[6];let p=!r||i,m;t[7]!==n.discard||t[8]!==o||t[9]!==p?(m=(0,U.jsx)(d,{type:`button`,variant:`secondary`,disabled:p,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=p,t[10]=m):m=t[10];let h=!r||i,g;t[11]===s?g=t[12]:(g=()=>void s(),t[11]=s,t[12]=g);let _=i?n.saving:n.save,v;t[13]!==h||t[14]!==g||t[15]!==_?(v=(0,U.jsx)(d,{type:`button`,variant:`primary`,disabled:h,onClick:g,children:_}),t[13]=h,t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==f||t[18]!==m||t[19]!==v?(y=(0,U.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[f,m,v]}),t[17]=f,t[18]=m,t[19]=v,t[20]=y):y=t[20];let b;return t[21]!==y||t[22]!==u?(b=(0,U.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,y]}),t[21]=y,t[22]=u,t[23]=b):b=t[23],b}function De(e){return _(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function Oe(e){return(await v(De(e))).payload?.channels??[]}function ke(e,t){let n=(0,H.c)(14),r;n[0]!==e||n[1]!==t?(r=e?De(t):null,n[0]=e,n[1]=t,n[2]=r):r=n[2];let i;n[3]===t?i=n[4]:(i=()=>Oe(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}=O(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 Ae=`channels-status`;function je(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function Me(e){let t=t=>e(t.detail);return window.addEventListener(Ae,t),()=>window.removeEventListener(Ae,t)}function Ne(e,t){let n=(0,H.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return Me(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,V.useEffect)(i,a)}function Pe(e){return e?_(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Fe(e){return(await v(_(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Ie=[`enabled`];async function Le(){let e=await v(_(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Re(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function ze(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function Y(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){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function Ve(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function He(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 Ue(e){if(!e)return[];let t=e.uiHints??{},n=X(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=Y(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!X(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Ie.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Ie.includes(e))}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function We(e,t){let n={...Z(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(!X(r)||!X(r[n]))break;let o=X(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Z(r[n]),properties:{}}),e===t.length-1){o[n]=Z(r[n]);break}i=r[n],a=o[n]}}return n}function Ge(e){let t=e.properties;if(!X(t))return!1;for(let[e,n]of Object.entries(t))X(n)&&n.type===`object`&&Ge(n)&&delete t[e];return Object.keys(t).length===0}function Ke(e,t){let n=Z(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!X(i))break;if(e===t.length-1){delete i[n];break}if(!X(i[n]))break;r=i[n]}}return Ge(n),n}function qe(e){return e.type===`object`&&X(e.properties)&&Object.keys(e.properties).length>0}function Je(e,t){let n=e;for(let e of t.split(`.`)){if(!X(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return X(t)?Object.values(t).filter(e=>X(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=Y(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=Y(e),r=pe(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=pe(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=m(e=>e.token),[n,r]=(0,V.useState)(!1),i=(0,V.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(_(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Re(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,U.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,U.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,U.jsx)(I,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,H.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,o;t[0]===i?o=t[1]:(o=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=o);let s=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,c=r&&`cursor-not-allowed opacity-60`,l;t[2]!==s||t[3]!==c?(l=u(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,s,c),t[2]=s,t[3]=c,t[4]=l):l=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=u(`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,U.jsx)(`span`,{className:f}),t[7]=f,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==o||t[13]!==l||t[14]!==p?(m=(0,U.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:o,className:l,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=o,t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function rt(e){let t=(0,H.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:o,ch:s,onOpen:c,onToggle:f,onRestart:p}=e,m;t[0]===n?m=t[1]:(m=Y(n),t[0]=n,t[1]=m);let h=m,g,_,v,y,b,x,S;if(t[2]!==a||t[3]!==s||t[4]!==r||t[5]!==n||t[6]!==c||t[7]!==p||t[8]!==f||t[9]!==i||t[10]!==h.enabled||t[11]!==h.ready){let e=Xe(n,r,s),o=$e(n,s);g=!h.enabled&&h.ready?f:i===`stopped`?p:c,x=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let l;t[19]===n?l=t[20]:(l=(0,U.jsx)(tt,{entry:n}),t[19]=n,t[20]=l);let d;t[21]===n.label?d=t[22]:(d=(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=d);let m;t[23]===i?m=t[24]:(m=u(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,He(i)),t[23]=i,t[24]=m);let C;t[25]!==s||t[26]!==i?(C=Be(i,s),t[25]=s,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==m||t[29]!==C?(w=(0,U.jsx)(`span`,{className:m,children:C}),t[28]=m,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==d?(T=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[d,w]}),t[31]=w,t[32]=d,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==l?(E=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[l,T]}),t[34]=T,t[35]=l,t[36]=E):E=t[36];let D=h.enabled,O;t[37]!==s.toggleChannel||t[38]!==n.label?(O=s.toggleChannel.replace(`{{channel}}`,n.label),t[37]=s.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==f||t[42]!==h.enabled||t[43]!==O?(k=(0,U.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:f}),t[40]=a,t[41]=f,t[42]=h.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(S=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=S):S=t[47],_=`button`,v=c,y=`mt-5 min-h-[6.25rem] text-left`,b=h.ready?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,U.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map($)}):null]}):(0,U.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:s.cardSetupTitle}),(0,U.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Qe(n,s)}),o.length>0?(0,U.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:o.map(it)}):null]}),t[2]=a,t[3]=s,t[4]=r,t[5]=n,t[6]=c,t[7]=p,t[8]=f,t[9]=i,t[10]=h.enabled,t[11]=h.ready,t[12]=g,t[13]=_,t[14]=v,t[15]=y,t[16]=b,t[17]=x,t[18]=S}else g=t[12],_=t[13],v=t[14],y=t[15],b=t[16],x=t[17],S=t[18];let C;t[48]!==_||t[49]!==v||t[50]!==y||t[51]!==b?(C=(0,U.jsx)(`button`,{type:_,onClick:v,className:y,children:b}),t[48]=_,t[49]=v,t[50]=y,t[51]=b,t[52]=C):C=t[52];let w=a||o,T;t[53]!==a||t[54]!==o?(T=a||o?(0,U.jsx)(l,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=o,t[55]=T):T=t[55];let E;t[56]!==s||t[57]!==n||t[58]!==o||t[59]!==i?(E=o?s.restartingChannel:i===`stopped`?s.restartChannel:Ze(n,s),t[56]=s,t[57]=n,t[58]=o,t[59]=i,t[60]=E):E=t[60];let D;t[61]!==g||t[62]!==T||t[63]!==E||t[64]!==w?(D=(0,U.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,U.jsxs)(d,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:g,disabled:w,children:[T,E]})}),t[61]=g,t[62]=T,t[63]=E,t[64]=w,t[65]=D):D=t[65];let O;return t[66]!==D||t[67]!==x||t[68]!==S||t[69]!==C?(O=(0,U.jsxs)(`article`,{className:x,children:[S,C,D]}),t[66]=D,t[67]=x,t[68]=S,t[69]=C,t[70]=O):O=t[70],O}function it(e){return(0,U.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,U.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function at(e){let t=(0,H.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:o,ch:s,onRestart:c,onCheck:f,onManageConnection:p}=e,m=n===`running`?R:n===`stopped`||n===`needs_setup`?M:l,h=n===`running`&&`text-emerald-600 dark:text-emerald-400`,g=n===`stopped`&&`text-red-600 dark:text-red-400`,_=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,v=n===`disabled`&&`text-fg-muted`,y=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,b;t[0]!==h||t[1]!==g||t[2]!==_||t[3]!==v||t[4]!==y?(b=u(`mt-0.5 size-5 shrink-0`,h,g,_,v,y),t[0]=h,t[1]=g,t[2]=_,t[3]=v,t[4]=y,t[5]=b):b=t[5];let x;t[6]!==m||t[7]!==b?(x=(0,U.jsx)(m,{className:b}),t[6]=m,t[7]=b,t[8]=x):x=t[8];let S;t[9]===s.connectionStatus?S=t[10]:(S=(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:s.connectionStatus}),t[9]=s.connectionStatus,t[10]=S);let C;t[11]!==s||t[12]!==n?(C=Ve(n,s),t[11]=s,t[12]=n,t[13]=C):C=t[13];let w;t[14]===C?w=t[15]:(w=(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:C}),t[14]=C,t[15]=w);let T;t[16]!==w||t[17]!==S?(T=(0,U.jsxs)(`div`,{children:[S,w]}),t[16]=w,t[17]=S,t[18]=T):T=t[18];let E;t[19]!==T||t[20]!==x?(E=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[x,T]}),t[19]=T,t[20]=x,t[21]=E):E=t[21];let D=i||r,O;t[22]===i?O=t[23]:(O=i?(0,U.jsx)(l,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=O);let k=i?s.checkingConnection:s.checkConnection,A;t[24]!==f||t[25]!==D||t[26]!==O||t[27]!==k?(A=(0,U.jsxs)(d,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:D,onClick:f,children:[O,k]}),t[24]=f,t[25]=D,t[26]=O,t[27]=k,t[28]=A):A=t[28];let j;t[29]!==s.restartChannel||t[30]!==s.restartingChannel||t[31]!==i||t[32]!==c||t[33]!==r||t[34]!==n?(j=n===`stopped`?(0,U.jsxs)(d,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:c,children:[r?(0,U.jsx)(l,{className:`size-4 animate-spin`}):(0,U.jsx)(N,{className:`size-4`}),r?s.restartingChannel:s.restartChannel]}):null,t[29]=s.restartChannel,t[30]=s.restartingChannel,t[31]=i,t[32]=c,t[33]=r,t[34]=n,t[35]=j):j=t[35];let P;t[36]!==o||t[37]!==s.connectionOptions||t[38]!==s.hideConnectionOptions||t[39]!==i||t[40]!==p||t[41]!==r||t[42]!==a?(P=o?(0,U.jsx)(d,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:p,children:a?s.hideConnectionOptions:s.connectionOptions}):null,t[36]=o,t[37]=s.connectionOptions,t[38]=s.hideConnectionOptions,t[39]=i,t[40]=p,t[41]=r,t[42]=a,t[43]=P):P=t[43];let F;t[44]!==A||t[45]!==j||t[46]!==P?(F=(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[A,j,P]}),t[44]=A,t[45]=j,t[46]=P,t[47]=F):F=t[47];let I;return t[48]!==E||t[49]!==F?(I=(0,U.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[E,F]})}),t[48]=E,t[49]=F,t[50]=I):I=t[50],I}function ot(e){let t=(0,H.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=Y(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,U.jsx)(ae,{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,U.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,U.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,U.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,U.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,U.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,U.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,U.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function st(){let e=h(e=>e.language),t=p(e),n=m(e=>!!e.token),r=a(),{channelId:o}=i(),l=ne(o),d=ke(n,e),f=d.entries,{data:v,mutate:y,isValidating:b}=O(n?fe():null,de,{revalidateOnFocus:!0}),{data:x,mutate:S}=O(n?`channels-config-map`:null,Le,{revalidateOnFocus:!1}),C=x?.channels??{},w=x?.bindings??[],{data:T}=O(n?`channel-routing-agents`:null,P,{revalidateOnFocus:!1}),E=z(e=>e.setPageHeader),D=z(e=>e.clearPageHeader),j=(0,V.useMemo)(()=>f.find(e=>e.id===l),[l,f]),M=j?ze(j):null,{data:N,mutate:F}=O(n&&M?Pe(M):null,()=>Fe(M)),[I,L]=(0,V.useState)(null),[R,te]=(0,V.useState)(!1),[re,ae]=(0,V.useState)(null),[ue,H]=(0,V.useState)(null),[me,he]=(0,V.useState)(!1),[W,G]=(0,V.useState)(null),[K,q]=(0,V.useState)(null),_e=I??N??{},J=t.channelsSettings,be=(0,V.useMemo)(()=>j?.configSchema??{type:`object`,properties:{}},[j?.configSchema]),Se=(0,V.useMemo)(()=>Ke(be,Ie),[be]),we=(0,V.useMemo)(()=>Ue(j),[j]),De=(0,V.useMemo)(()=>We(Se,we),[we,Se]),Oe=(0,V.useMemo)(()=>Ke(Se,we),[we,Se]),Ae=(0,V.useMemo)(()=>qe(De),[De]),Me=j?K??ve(w,j.id):``,Re=(0,V.useMemo)(()=>(T?.items??[]).map(e=>{let n=k(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[T?.items,t.agentsSettings]),Ve=T?.items.find(e=>e.id===T.defaultId),X=Ve?k(Ve,t.agentsSettings):T?.defaultId??``,Z=(0,V.useMemo)(()=>({defaultBooleanLabel:J.schemaBooleanDefault,unsupportedArrayType:J.schemaUnsupportedArrayType,arrayAddPlaceholder:J.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>J.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[J]),Ge=(0,V.useMemo)(()=>new Map((v??[]).map(e=>[e.name,e])),[v]),Je=v!==void 0,Ye=(0,V.useCallback)(e=>xe(e,Ge.get(e.id),Je),[Ge,Je]),Q=(0,V.useCallback)(async()=>{await Promise.all([d.mutate(),y()])},[d,y]);Ne((0,V.useCallback)(e=>{let t=je(e);t&&y(t,!1)},[y]),n);let Xe=(0,V.useMemo)(()=>n?(0,U.jsx)(Te,{ch:J,refreshing:d.isValidating||b,saveOk:!1,onRefresh:()=>void Q()}):null,[d.isValidating,J,n,b,Q]);(0,V.useLayoutEffect)(()=>(E({startExtra:null,main:(0,U.jsx)(`div`,{className:`min-w-0`,children:(0,U.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>D()),[D,Xe,t.settingsSections.channels,E]);let Ze=(0,V.useCallback)(e=>{r(B(e)),L(null),q(null),G(null)},[r]),Qe=(0,V.useCallback)(()=>{r(ee),L(null),q(null),G(null)},[r]),$e=(0,V.useCallback)(async e=>{H(e.id),G(null);try{let t=await g(_(`/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){G(e instanceof Error?e.message:String(e))}finally{H(null)}},[Q]);(0,V.useEffect)(()=>{q(null),he(!1)},[j?.id]);let et=(0,V.useCallback)(async()=>{if(!j||!I&&K===null)return!1;let e=ze(j);te(!0),G(null);try{let t=await g(_(`/api/config`),{method:`PATCH`,body:JSON.stringify({...I?{channels:{[e]:I}}:{},...K===null?{}:{bindings:ye(w,j.id,K)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return I&&await F(I,!1),await S(),await d.mutate(),L(null),q(null),!0}catch(e){return G(e instanceof Error?e.message:String(e)),!1}finally{te(!1)}},[j,K,w,d,I,S,F]),it=(0,V.useCallback)(async e=>{let t=Y(e),n=ze(e),r=j?.id===e.id?I:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}ae(e.id),G(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await g(_(`/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 d.mutate(),await S(),await y(),j?.id===e.id&&(await F(),L(null))}catch(e){G(e instanceof Error?e.message:String(e))}finally{ae(null)}},[j?.id,d,I,S,F,y,Ze]),$=j?.ui?.modal,st=$?.placement!==`replace-config`,ct=j?Ye(j):`checking`,lt=j?!Y(j).ready||me:!1;return n?(0,U.jsxs)(se,{gap:`gap-4`,children:[d.isLoading?(0,U.jsx)(ce,{sections:2}):d.error?(0,U.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(d.error)}):(0,U.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:f.map(e=>(0,U.jsx)(rt,{entry:e,config:C[ze(e)]?.config,runtime:Ye(e),busy:re===e.id,restarting:ue===e.id,ch:J,onOpen:()=>Ze(e.id),onToggle:()=>void it(e),onRestart:()=>void $e(e)},e.id))}),W?(0,U.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:W}):null,(0,U.jsx)(Ce,{presentation:`modal`,open:!!j,onOpenChange:e=>{e||Qe()},closeAriaLabel:J.close,srTitle:j?.label??J.selectChannel,srDescription:j?.description,wide:!0,footer:j?(0,U.jsx)(Ee,{ch:J,dirty:!!I||K!==null,saving:R,onCancel:Qe,onDiscard:()=>{L(null),q(null)},onSave:et}):null,children:j?(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,U.jsx)(tt,{entry:j}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:j.label}),(0,U.jsx)(`span`,{className:u(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,He(ct)),children:Be(ct,J)})]}),(0,U.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,U.jsx)(`span`,{className:`min-w-0 truncate`,children:!Y(j).ready&&pe(j)?.[1].result===`qr`?J.scanLoginHint.replace(`{{channel}}`,j.label):j.description}),j.docsPath?(0,U.jsxs)(`a`,{href:j.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[J.docs,(0,U.jsx)(c,{className:`size-3.5`})]}):null]})]})]}),(0,U.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,U.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:Y(j).enabled?J.enabledLabel:J.disabledLabel}),(0,U.jsx)(nt,{checked:Y(j).enabled,disabled:re===j.id,label:J.toggleChannel.replace(`{{channel}}`,j.label),onToggle:()=>void it(j)})]})]})}),(0,U.jsx)(at,{runtime:ct,restarting:ue===j.id,checking:b,showConnectionOptions:me,canManageConnection:Y(j).ready&&$?.placement!==`replace-config`,ch:J,onRestart:()=>void $e(j),onCheck:()=>void Q(),onManageConnection:()=>he(e=>!e)}),(0,U.jsx)(ot,{entry:j,ch:J}),lt&&$?.placement!==`replace-config`?(0,U.jsx)(ge,{entry:j,locale:e,messages:J,compact:!0,onChanged:async()=>{await F(),await Q(),await S()}},j.id):null,$?.entrypoint&&$.placement===`before-config`?(0,U.jsx)(ie,{extensionId:j.extensionId,extensionName:j.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:j.id,entry:j,config:_e}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,U.jsx)(ie,{extensionId:j.extensionId,extensionName:j.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:j.id,entry:j,config:_e}}):null,st&&Ae?(0,U.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`mb-4`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:J.basicConfiguration}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:J.basicConfigurationHint})]}),(0,U.jsx)(le,{schema:De,values:_e,onChange:e=>L(e),disabled:R,labels:Z})]}):null,(0,U.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,U.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,U.jsx)(A,{className:`size-4 text-fg-muted`}),J.messageHandling]}),(0,U.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,U.jsxs)(`div`,{className:`mb-3`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:J.agentRouting}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:J.messageHandlingHint})]}),(0,U.jsx)(s,{value:Me,options:Re,placeholder:J.agentRoutingSelect,emptyLabel:J.agentRoutingDefault.replace(`{{agent}}`,X||J.agentRoutingSelect),ariaLabel:J.agentRouting,disabled:R||!T,onChange:e=>q(e)})]})]}),st&&qe(Oe)?(0,U.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,U.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,U.jsx)(A,{className:`size-4 text-fg-muted`}),J.advancedConfiguration]}),(0,U.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,U.jsx)(le,{schema:Oe,values:_e,onChange:e=>L(e),disabled:R,labels:Z})})]}):null,W?(0,U.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:W}):null]}):null})]}):(0,U.jsxs)(se,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,U.jsx)(oe,{title:t.settingsSections.channels}),(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:J.tokenRequired})]})}export{st as ChannelsSettingsPanel};
|
package/dist/gateway/static/root/assets/{connectors-api-FBOe9SWC.js → connectors-api-X5ukNasZ.js}
RENAMED
|
@@ -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{t as i}from"./cn-JdwAhgNB.js";import{r as a,s as o}from"./locale-store-CnamlR07.js";import{n as s}from"./gateway-config-swr-Cv2ywpdb.js";import{nc as c}from"./index-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./cn-JdwAhgNB.js";import{r as a,s as o}from"./locale-store-CnamlR07.js";import{n as s}from"./gateway-config-swr-Cv2ywpdb.js";import{nc as c}from"./index-CKSplmFw.js";var l=n(),u=e(t(),1),d=r(),f={sm:{frame:`size-9 rounded-lg`,image:`size-6`,fallback:`size-4`},md:{frame:`size-10 rounded-xl`,image:`size-7`,fallback:`size-5`},lg:{frame:`size-12 rounded-xl`,image:`size-8`,fallback:`size-5`}};function p(e){let t=(0,l.c)(18),{connector:n,size:r,className:a}=e,o=r===void 0?`md`:r,s=n?.branding?.logoUrl,[p,m]=(0,u.useState)(!1),h=f[o],g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{m(!1)},t[0]=g):g=t[0];let _;t[1]===s?_=t[2]:(_=[s],t[1]=s,t[2]=_),(0,u.useEffect)(g,_);let v;t[3]!==a||t[4]!==h.frame?(v=i(`flex shrink-0 items-center justify-center overflow-hidden border border-edge bg-surface-base`,h.frame,a),t[3]=a,t[4]=h.frame,t[5]=v):v=t[5];let y;t[6]===n?y=t[7]:(y=n?.branding?.backgroundColor?{backgroundColor:n.branding.backgroundColor}:void 0,t[6]=n,t[7]=y);let b=n?.displayName,x;t[8]!==h.fallback||t[9]!==h.image||t[10]!==p||t[11]!==s?(x=s&&!p?(0,d.jsx)(`img`,{src:s,alt:``,loading:`lazy`,draggable:!1,className:i(`object-contain`,h.image),onError:()=>m(!0)}):(0,d.jsx)(c,{className:i(`text-fg-muted`,h.fallback),"aria-hidden":!0}),t[8]=h.fallback,t[9]=h.image,t[10]=p,t[11]=s,t[12]=x):x=t[12];let S;return t[13]!==v||t[14]!==y||t[15]!==b||t[16]!==x?(S=(0,d.jsx)(`span`,{className:v,style:y,title:b,children:x}),t[13]=v,t[14]=y,t[15]=b,t[16]=x,t[17]=S):S=t[17],S}function m(e,t){if(!e.payload)throw Error(e.error??t);return e.payload}async function h(){return m(await o(a(`/api/connectors/catalog`)),`Could not load connector catalog.`).connectors}async function g(e){let t=new URLSearchParams;return e?.q?.trim()&&t.set(`q`,e.q.trim()),e?.page&&t.set(`page`,String(e.page)),e?.pageSize&&t.set(`pageSize`,String(e.pageSize)),e?.refresh&&t.set(`refresh`,`1`),e?.verification&&t.set(`verification`,e.verification),m(await o(a(`/api/connectors/composio/catalog${t.size?`?${t.toString()}`:``}`)),`Could not load Composio catalog.`)}async function _(e){let t=new URLSearchParams;return e?.q?.trim()&&t.set(`q`,e.q.trim()),e?.page&&t.set(`page`,String(e.page)),e?.pageSize&&t.set(`pageSize`,String(e.pageSize)),e?.category?.trim()&&t.set(`category`,e.category.trim()),e?.sort&&t.set(`sort`,e.sort),m(await o(a(`/api/capabilities/connectors${t.size?`?${t.toString()}`:``}`)),`Could not load Store connector capabilities.`)}async function v(e,t){return m(await o(a(`/api/capabilities/connectors/${encodeURIComponent(e)}/install-plan`),{method:`POST`,body:JSON.stringify({version:t})}),`Could not prepare connector installation.`).plan}async function y(e,t,n){let r=await o(a(`/api/capabilities/connectors/${encodeURIComponent(e)}/install`),{method:`POST`,body:JSON.stringify({...t,version:n})});return s(),m(r,`Could not install Store connector.`).instance}async function b(){return m(await o(a(`/api/connectors/installed`)),`Could not load installed connectors.`).instances}async function x(e){return m(await o(a(`/api/connectors/${encodeURIComponent(e)}/auth/start`),{method:`POST`}),`Could not start connector authorization.`).authorization}async function S(){return m(await o(a(`/api/connectors/composio/setup-status`)),`Could not check the connection service.`)}async function C(e){m(await o(a(`/api/connectors/composio/setup`),{method:`POST`,body:JSON.stringify({apiKey:e})}),`Could not enable the connection service.`)}async function w(e,t){let n=await o(a(`/api/connectors/${encodeURIComponent(e)}/install`),{method:`POST`,body:JSON.stringify(t)});return s(),m(n,`Could not install connector.`).instance}async function T(e,t={}){return m(await o(a(`/api/connectors/preview`),{method:`POST`,body:JSON.stringify({...t,definition:e})}),`Could not preview connector capabilities.`).preview}async function E(e,t){return m(await o(a(`/api/connectors/${encodeURIComponent(e)}/config`),{method:`POST`,body:JSON.stringify(t)}),`Could not update connector config.`).instance}async function D(e){await o(a(`/api/connectors/${encodeURIComponent(e)}`),{method:`DELETE`}),s()}async function O(e){return m(await o(a(`/api/connectors/${encodeURIComponent(e)}/test`),{method:`POST`}),`Connector test failed.`)}async function k(){return m(await o(a(`/api/connectors/composio/connections`)),`Could not load Composio connections.`).connections}async function A(e,t,n=12e4){let r=Date.now()+n;for(;Date.now()<r;){let n=(await k().catch(()=>[])).find(n=>n.toolkit.toLowerCase()===e.toLowerCase()&&n.status===`active`&&(!t||n.providerConnectionId===t));if(n)return n;await new Promise(e=>window.setTimeout(e,2e3))}throw Error(`Connection authorization timed out.`)}async function j(e,t){return m(await o(a(`/api/connectors/composio/connections/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify(t)}),`Could not update Composio connection.`).connection}async function M(e){return m(await o(a(`/api/connectors/composio/${encodeURIComponent(e)}/health`)),`Could not check Composio connector health.`).health}async function N(e){await o(a(`/api/connectors/composio/connections/${encodeURIComponent(e)}/refresh`),{method:`POST`})}async function P(e){await o(a(`/api/connectors/composio/connections/${encodeURIComponent(e)}`),{method:`DELETE`})}async function F(e){return m(await o(a(`/api/connectors/composio/${encodeURIComponent(e)}/scope`)),`Could not load Composio scope.`).scope}async function I(e,t){let n=await o(a(`/api/connectors/composio/${encodeURIComponent(e)}/scope`),{method:`POST`,body:JSON.stringify({scope:t})});return s(),m(n,`Could not update Composio scope.`).scope}async function L(e){return m(await o(a(`/api/connectors/composio/${encodeURIComponent(e)}/policy`)),`Could not load Composio policy.`)}async function R(e,t){return m(await o(a(`/api/connectors/composio/${encodeURIComponent(e)}/policy`),{method:`PATCH`,body:JSON.stringify(t)}),`Could not update Composio policy.`).policy}async function z(e){return m(await o(a(`/api/connectors/composio/${encodeURIComponent(e)}/tools`)),`Could not load Composio tools.`).tools}async function B(e=50){return m(await o(a(`/api/connectors/composio/triggers?limit=${encodeURIComponent(String(e))}`)),`Could not load Composio trigger events.`).events}async function V(e){return m(await o(a(`/api/connectors/composio/accounts/${encodeURIComponent(e)}/learning`),{method:`POST`}),`Could not start learning from this connection.`).job}async function H(){return m(await o(a(`/api/connectors/learning`)),`Could not load connector learning jobs.`).jobs}async function U(e){return m(await o(a(`/api/connectors/composio/accounts/${encodeURIComponent(e)}/sync-policy`)),`Could not load connector sync policy.`).policy}async function W(e,t){return m(await o(a(`/api/connectors/composio/accounts/${encodeURIComponent(e)}/sync-policy`),{method:`PATCH`,body:JSON.stringify(t)}),`Could not update connector sync policy.`).policy}async function G(e){return m(await o(a(`/api/connectors/${encodeURIComponent(e)}/source-sync`),{method:`POST`}),`Could not sync connector source.`)}async function K(e=``,t=100){return m(await o(a(`/api/connectors/people?${new URLSearchParams({q:e,limit:String(t)}).toString()}`)),`Could not load the connected people graph.`)}async function q(e=`pending`){return m(await o(a(`/api/connectors/approvals?status=${encodeURIComponent(e)}`)),`Could not load connector approvals.`).approvals}async function J(e,t){return m(await o(a(`/api/connectors/approvals/respond`),{method:`POST`,body:JSON.stringify({id:e,decision:t})}),`Could not update connector approval.`).approval}export{j as A,J as C,x as D,V as E,p as F,E as M,W as N,G as O,A as P,D as S,I as T,B as _,b as a,T as b,M as c,S as d,U as f,z as g,k as h,h as i,R as j,O as k,L as l,y as m,g as n,_ as o,w as p,K as r,v as s,C as t,F as u,q as v,P as w,N as x,H as y};
|