@xopcai/xopc 0.0.133 → 0.0.134
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-Ab81VpCx.js → agent-avatar-dicebear-mQ4lbZRf.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-HCGFJG8I.js → agents-BP0iRtiu.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-DMI_sbnc.js → app-management-settings-panel-Bj2YJiQe.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-oQiCWQIQ.js → appearance-settings-B93olV5Z.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-CRYuPIdb.js → apps-page-12_2SDFq.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BaKuWJws.js → archive-plugin-D_yymKFJ.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-DYCFtbAA.js → attachment-load-kfyH3HV-.js} +1 -1
- package/dist/gateway/static/root/assets/{automation-suggestion-card-C6ZIz_B1.js → automation-suggestion-card-DyGBB2WH.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-DjbtV2VP.js → automations-page-V-tw6y1o.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-Bdg1hfhV.js → binary-plugins-BX1AXf98.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-CEgvbzpG.js → block-editor-D-WEVNHU.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-KcwlS_iE.js → browser-settings-page-aMPnxWXi.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-api-CC3vmrm5.js → capability-presets-api-CsaY2Z8B.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-settings-panel-Di4uiKbv.js → capability-presets-settings-panel-CHExb90z.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-DMa0BEWf.js → channels-settings-N8NujD--.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-DIZKYaMj.js → connectors-page-zBJbFgnK.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-CNnlqbkx.js → desktop-pet-DfA-hVlt.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-ukJCc0LA.js → desktop-pet-settings-C3JDiXSu.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-8hoieEyt.js → directory-picker-path-field-MT71cjgl.js} +1 -1
- package/dist/gateway/static/root/assets/{dreaming-settings-BOrBSNLL.js → dreaming-settings-Cfx_Qg4R.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-D6Jc0hYZ.js → extension-debug-page-Wp23cLkf.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-CJMhBASX.js → extension-page-B5HRNtVY.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-Dt-FWyMN.js → extension-settings-page-zPfMpsYi.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-CyYi-a3k.js → gateway-config-api-CsS_3Ii6.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-yJvCmOBC.js → gateway-settings-DOxh0hei.js} +1 -1
- package/dist/gateway/static/root/assets/{goal-create-dialog-B3PLFUAl.js → goal-create-dialog-BOWSTGB-.js} +1 -1
- package/dist/gateway/static/root/assets/{goal-detail-page-BQXW29kk.js → goal-detail-page-CCLgkqj1.js} +1 -1
- package/dist/gateway/static/root/assets/{goals-config-api-FU_bdYvR.js → goals-config-api--3Vzceq-.js} +1 -1
- package/dist/gateway/static/root/assets/{goals-page-BmppU6mC.js → goals-page-CsfIp8Vl.js} +1 -1
- package/dist/gateway/static/root/assets/{goals-settings-BsXWV6CN.js → goals-settings-Dg_hQNVC.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-BqwSCZLD.js → heartbeat-settings-CecoDTZJ.js} +1 -1
- package/dist/gateway/static/root/assets/{index-DqFBdoK-.js → index-BOme955B.js} +29 -29
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D8J0hkTt.js → keyboard-shortcuts-settings-BWMLAFxf.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-Cr5ptDtc.js → logs-page-CW7AMYhN.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-w-hIAZ9S.js → markdown-split-5tvDwUMS.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-DjFnDy3R.js → media-plugins-RSjPG4B0.js} +1 -1
- package/dist/gateway/static/root/assets/{models-hub-panel-DEsMnITi.js → models-hub-panel-mKfeyGVq.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-D7bHXaeR.js → notes-page-DYw5zPeJ.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-workbench-DiuG4Ov7.js → notes-workbench-SPdKpvSN.js} +2 -2
- package/dist/gateway/static/root/assets/{page-tabs-smjfSAwc.js → page-tabs-DYNWfN6S.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-v02THugE.js → preview-open-alternatives-B50PdIc8.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-Us3zDRE6.js → project-detail-page-D3yP4K3k.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-BcvW8R0Z.js → projects-page-B6EV45NR.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-Bun2k0V-.js → remote-access-hub-9foX60FQ.js} +1 -1
- package/dist/gateway/static/root/assets/{save-bar-controls-CD7LPbLU.js → save-bar-controls-DggNb0SF.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-Cf3p_M0z.js → schedule-field-T4ti2C8S.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-D8XdvcNH.js → schema-form-D6wGEfEa.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-Bh44TVld.js → sessions-page-BReBhxWd.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DNDBN4nT.js +1 -0
- package/dist/gateway/static/root/assets/{settings-collapsible-section-BVpPSgMs.js → settings-collapsible-section-Cgd_aLBV.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-form-section-GAwBG9Vp.js → settings-form-section-DnDrLMWZ.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-CGxa3aCb.js → settings-loading-skeleton-A2OshMK8.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-bZKl6uRR.js → settings-page-CXMK9Vb3.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-DfbMLJgN.js → settings-page-layout-Da_LNPDS.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-DBIruh16.js → setup-status-panel-C8UtBMJ_.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-BglBMvA0.js → share-preview-page-BGZV-PCJ.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-C0fR-Oto.js → shares-settings-xXAMKlc7.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-CurjHfEM.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-CwwZOoCH.js → skills-page-BRR7NQkL.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-CTT0BkbS.js → system-settings-panel-D8uzXP0Y.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-Fa9PjI0-.js → typed-models-lib-DQxv2BHa.js} +1 -1
- package/dist/gateway/static/root/assets/{user-profile-settings-panel-pCK-aMqu.js → user-profile-settings-panel-DkZSHsIs.js} +1 -1
- package/dist/gateway/static/root/assets/{utils-aleluS3U.js → utils-ivGpUrZi.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-Fh4mqUIK.js → voice-api-key-field-DCiECZN1.js} +1 -1
- package/dist/gateway/static/root/assets/{work-item-detail-page-C0_3nId3.js → work-item-detail-page-DAel5CHH.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-r969H1r2.js → workflow-run-setup-panel-2w0zj9eJ.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-start-dialog-C1GbcWN0.js → workflow-start-dialog-B5xdDFV-.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-DsPM3HEI.js → workflows-page-DRhiSwuU.js} +1 -1
- package/dist/gateway/static/root/index.html +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BhyLZ0IW.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BG-FEo9B.js +0 -1
|
@@ -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-BQ_8x0bT.js";import{t as a}from"./messages-DR9ODkb8.js";import{a as o}from"./fetch-6HXXdO77.js";import{n as s}from"./locale-store-Ba72bFmP.js";import{i as c}from"./vendor-swr-BIWyz7Rc.js";import{Ba as l,Do as u,Ec as d,El as f,Ha as p,Nc as m,Oo as h,Ra as g,Ua as _,Va as v,Wa as y,_o as b,bs as x,ds as S,io as C,ll as w,no as T,ro as E,tc as D,tr as O,vs as k,wo as A,za as j,zo as M}from"./index-DqFBdoK-.js";import{n as N,t as P}from"./settings-page-layout-DfbMLJgN.js";import{n as F,t as I}from"./settings-loading-skeleton-CGxa3aCb.js";import{n as L,t as R}from"./settings-form-section-GAwBG9Vp.js";import{a as z,i as B,o as V,t as ee}from"./typed-models-lib-Fa9PjI0-.js";import{a as H,i as te,n as ne,o as re,r as ie,s as ae,t as oe}from"./capability-presets-api-CC3vmrm5.js";var se=n(),U=e(t(),1),W=r();function G(e){return e.name||e.directoryId}function ce(e){let t=(0,se.c)(56),{mode:n,selected:r,catalog:a,loading:o,disabled:s,onModeChange:c,onSelectedChange:l,labels:u}=e,d=n===`allowlist`||n===`denylist`,f;t[0]===a?f=t[1]:(f=a.map(G).filter(Boolean),t[0]=a,t[1]=f);let p=f,m;bb0:{if(n===`inherit`){m=u.inheritSummary;break bb0}if(n===`all`){m=u.allSummary;break bb0}if(n===`off`){m=u.offSummary;break bb0}let e=n===`allowlist`?u.allowSummary:u.denySummary,i;t[2]!==r.size||t[3]!==e?(i=e.replace(`{{count}}`,String(r.size)),t[2]=r.size,t[3]=e,t[4]=i):i=t[4],m=i}let h=m,g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,W.jsx)(w,{className:`size-3.5`,"aria-hidden":!0}),t[5]=g):g=t[5];let _;t[6]===u.overrideSummaryTitle?_=t[7]:(_=(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[g,u.overrideSummaryTitle]}),t[6]=u.overrideSummaryTitle,t[7]=_);let v;t[8]===h?v=t[9]:(v=(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:h}),t[8]=h,t[9]=v);let y;t[10]!==_||t[11]!==v?(y=(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[_,v]}),t[10]=_,t[11]=v,t[12]=y):y=t[12];let b;t[13]===u.modeLabel?b=t[14]:(b=(0,W.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.modeLabel}),t[13]=u.modeLabel,t[14]=b);let x;t[15]===u.modeInherit?x=t[16]:(x=[`inherit`,u.modeInherit],t[15]=u.modeInherit,t[16]=x);let S;t[17]===u.modeAll?S=t[18]:(S=[`all`,u.modeAll],t[17]=u.modeAll,t[18]=S);let C;t[19]===u.modeAllowlist?C=t[20]:(C=[`allowlist`,u.modeAllowlist],t[19]=u.modeAllowlist,t[20]=C);let T;t[21]===u.modeDenylist?T=t[22]:(T=[`denylist`,u.modeDenylist],t[21]=u.modeDenylist,t[22]=T);let E;t[23]===u.modeOff?E=t[24]:(E=[`off`,u.modeOff],t[23]=u.modeOff,t[24]=E);let D;t[25]!==T||t[26]!==E||t[27]!==x||t[28]!==S||t[29]!==C?(D=[x,S,C,T,E],t[25]=T,t[26]=E,t[27]=x,t[28]=S,t[29]=C,t[30]=D):D=t[30];let O=D,k;t[31]!==s||t[32]!==n||t[33]!==c||t[34]!==O?(k=(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:O.map(e=>{let[t,r]=e;return(0,W.jsx)(`button`,{type:`button`,className:i(`rounded-lg px-3 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,n===t?`bg-accent-soft text-accent-fg`:`bg-surface-panel text-fg hover:bg-surface-hover/55`),disabled:s,onClick:()=>c(t),children:r},t)})}),t[31]=s,t[32]=n,t[33]=c,t[34]=O,t[35]=k):k=t[35];let j;t[36]!==k||t[37]!==b?(j=(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,k]}),t[36]=k,t[37]=b,t[38]=j):j=t[38];let M;t[39]!==a||t[40]!==p||t[41]!==s||t[42]!==u.emptyCatalog||t[43]!==u.noDescription||t[44]!==u.quickActionsLabel||t[45]!==u.quickClear||t[46]!==u.quickSelectAll||t[47]!==o||t[48]!==l||t[49]!==d||t[50]!==r?(M=d?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.quickActionsLabel}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:s||o||p.length===0,onClick:()=>l(new Set(p)),children:u.quickSelectAll}),(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:s||o||r.size===0,onClick:()=>l(new Set),children:u.quickClear})]})]}),o?(0,W.jsx)(I,{rows:3}):a.length===0?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.emptyCatalog}):(0,W.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:a.map(e=>{let t=G(e),n=r.has(t),a=typeof e.description==`string`?e.description.trim():``,o=a||u.noDescription;return(0,W.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl bg-surface-panel/70 px-3 shadow-surface`,children:(0,W.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:n,disabled:s,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),l(e)},"aria-label":t}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,W.jsx)(`p`,{className:i(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!a&&`italic text-fg-subtle`),title:o,children:o})]})]})},t)})})]}):null,t[39]=a,t[40]=p,t[41]=s,t[42]=u.emptyCatalog,t[43]=u.noDescription,t[44]=u.quickActionsLabel,t[45]=u.quickClear,t[46]=u.quickSelectAll,t[47]=o,t[48]=l,t[49]=d,t[50]=r,t[51]=M):M=t[51];let N;return t[52]!==j||t[53]!==M||t[54]!==y?(N=(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[y,j,M]}),t[52]=j,t[53]=M,t[54]=y,t[55]=N):N=t[55],N}var K=[`write_file`,`apply_patch`,`exec_command`,`execute_code`],q=[`exec_command`,`execute_code`,`automation`,`extensions`,`bundle-mcp`,`skill_manage`],J=[`send_message`,`send_media`,`text_to_speech`,`create_share`],Y=[`read_file`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`,`web_extract`],X=[...K,...J],le=[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`],ue=[`send_message`,`send_media`];function Z(e,t){let n={};for(let[r,i]of t)for(let t of r)e.has(t)&&(n[t]=i);return n}function de(e){let t=(0,se.c)(92),{builtinToolIds:n,toolModes:r,onChange:a,disabled:o,getToolDescription:s,getGroupTitle:c,labels:l}=e,u;t[0]===n?u=t[1]:(u=new Set(n),t[0]=n,t[1]=u);let d=u,f;t[2]!==d||t[3]!==r?(f=Object.entries(r).filter(e=>{let[t]=e;return d.has(t)}).toSorted(fe),t[2]=d,t[3]=r,t[4]=f):f=t[4];let p=f,m;if(t[5]!==d||t[6]!==n){m=[];for(let e of H){let t=e.toolIds.filter(e=>d.has(e));t.length>0&&m.push({key:e.key,ids:[...t]})}let e;t[8]===n?e=t[9]:(e=re(n),t[8]=n,t[9]=e);let r=e;if(r.length>0){let e;t[10]===r?e=t[11]:(e={key:`misc`,ids:r},t[10]=r,t[11]=e),m.push(e)}t[5]=d,t[6]=n,t[7]=m}else m=t[7];let h=m,g;t[12]!==a||t[13]!==r?(g=(e,t)=>{let n={...r};t===`inherit`?delete n[e]:n[e]=t,a(n)},t[12]=a,t[13]=r,t[14]=g):g=t[14];let _=g,v;t[15]!==d||t[16]!==a?(v=e=>{a(Z(d,e))},t[15]=d,t[16]=a,t[17]=v):v=t[17];let y=v;if(n.length===0){let e;return t[18]===l.emptyBuiltin?e=t[19]:(e=(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.emptyBuiltin}),t[18]=l.emptyBuiltin,t[19]=e),e}let b;t[20]===l.quickActionsLabel?b=t[21]:(b=(0,W.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.quickActionsLabel}),t[20]=l.quickActionsLabel,t[21]=b);let x;t[22]===a?x=t[23]:(x=()=>a({}),t[22]=a,t[23]=x);let S;t[24]!==o||t[25]!==l.quickClearOverrides||t[26]!==x?(S=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:x,children:l.quickClearOverrides}),t[24]=o,t[25]=l.quickClearOverrides,t[26]=x,t[27]=S):S=t[27];let C;t[28]===y?C=t[29]:(C=()=>y([[K,`deny`]]),t[28]=y,t[29]=C);let w;t[30]!==o||t[31]!==l.quickReadOnlyWorkspace||t[32]!==C?(w=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:C,children:l.quickReadOnlyWorkspace}),t[30]=o,t[31]=l.quickReadOnlyWorkspace,t[32]=C,t[33]=w):w=t[33];let T;t[34]===y?T=t[35]:(T=()=>y([[q,`deny`]]),t[34]=y,t[35]=T);let E;t[36]!==o||t[37]!==l.quickHighRiskOff||t[38]!==T?(E=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:T,children:l.quickHighRiskOff}),t[36]=o,t[37]=l.quickHighRiskOff,t[38]=T,t[39]=E):E=t[39];let D;t[40]===y?D=t[41]:(D=()=>y([[J,`deny`]]),t[40]=y,t[41]=D);let O;t[42]!==o||t[43]!==l.quickNoOutbound||t[44]!==D?(O=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:D,children:l.quickNoOutbound}),t[42]=o,t[43]=l.quickNoOutbound,t[44]=D,t[45]=O):O=t[45];let k;t[46]===y?k=t[47]:(k=()=>y([[Y,`allow`],[X,`deny`]]),t[46]=y,t[47]=k);let j;t[48]!==o||t[49]!==l.quickResearchMode||t[50]!==k?(j=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:k,children:l.quickResearchMode}),t[48]=o,t[49]=l.quickResearchMode,t[50]=k,t[51]=j):j=t[51];let M;t[52]===y?M=t[53]:(M=()=>y([[le,`allow`],[ue,`deny`]]),t[52]=y,t[53]=M);let N;t[54]!==o||t[55]!==l.quickCodingMode||t[56]!==M?(N=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:M,children:l.quickCodingMode}),t[54]=o,t[55]=l.quickCodingMode,t[56]=M,t[57]=N):N=t[57];let P;t[58]!==E||t[59]!==O||t[60]!==j||t[61]!==N||t[62]!==S||t[63]!==w?(P=(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[S,w,E,O,j,N]}),t[58]=E,t[59]=O,t[60]=j,t[61]=N,t[62]=S,t[63]=w,t[64]=P):P=t[64];let F;t[65]!==P||t[66]!==b?(F=(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,P]}),t[65]=P,t[66]=b,t[67]=F):F=t[67];let I;t[68]===l.overrideSummaryTitle?I=t[69]:(I=(0,W.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:l.overrideSummaryTitle}),t[68]=l.overrideSummaryTitle,t[69]=I);let L;t[70]!==l.modeAllow||t[71]!==l.modeDeny||t[72]!==l.noOverrides||t[73]!==p?(L=p.length>0?(0,W.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:p.map(e=>{let[t,n]=e;return(0,W.jsxs)(`span`,{className:i(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,n===`deny`&&`border-red-500/25 bg-red-500/10 text-red-700 dark:text-red-300`,n===`allow`&&`border-accent/25 bg-accent/10 text-accent`),children:[t,(0,W.jsx)(`span`,{className:`font-sans opacity-80`,children:n===`allow`?l.modeAllow:l.modeDeny})]},t)})}):(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:l.noOverrides}),t[70]=l.modeAllow,t[71]=l.modeDeny,t[72]=l.noOverrides,t[73]=p,t[74]=L):L=t[74];let R;t[75]!==I||t[76]!==L?(R=(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[I,L]}),t[75]=I,t[76]=L,t[77]=R):R=t[77];let z;t[78]!==o||t[79]!==c||t[80]!==s||t[81]!==h||t[82]!==l.inheritedMode||t[83]!==l.modeAllow||t[84]!==l.modeDeny||t[85]!==_||t[86]!==r?(z=(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:h.map(e=>{let{key:t,ids:n}=e;return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:c(t)}),(0,W.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=s(e),n=Object.prototype.hasOwnProperty.call(r,e)?r[e]:`inherit`;return(0,W.jsx)(`li`,{className:i(`rounded-xl px-3 py-2.5 shadow-surface transition-colors`,n===`inherit`?`bg-surface-panel/50`:`bg-surface-panel`),children:(0,W.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`font-mono text-xs font-medium text-fg`,children:e}),t?(0,W.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:t}):null]}),(0,W.jsx)(`div`,{className:`inline-flex w-fit rounded-lg border border-edge-subtle bg-surface-base p-0.5`,children:[`inherit`,`allow`,`deny`].map(t=>(0,W.jsx)(`button`,{type:`button`,className:i(`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`,n===t?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:text-fg`),disabled:o,onClick:()=>_(e,t),children:t===`inherit`?l.inheritedMode:t===`allow`?l.modeAllow:l.modeDeny},t))})]})},e)})})]},t)})}),t[78]=o,t[79]=c,t[80]=s,t[81]=h,t[82]=l.inheritedMode,t[83]=l.modeAllow,t[84]=l.modeDeny,t[85]=_,t[86]=r,t[87]=z):z=t[87];let B;return t[88]!==F||t[89]!==R||t[90]!==z?(B=(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[F,R,z]}),t[88]=F,t[89]=R,t[90]=z,t[91]=B):B=t[91],B}function fe(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}var pe=[{id:`overview`,icon:m},{id:`models`,icon:D},{id:`tools`,icon:h},{id:`skills`,icon:k},{id:`impact`,icon:d}];function me(e){return B(Object.entries(e?.models?.roles??{}).map(([e,t])=>({id:e,model:t.model,fallbacks:t.fallbacks??[],description:t.description})))}function he(e){return Object.fromEntries(Object.entries(e?.tools?.builtin??{}).map(([e,t])=>[e,t.mode===`allow`?`allow`:`deny`]))}function ge(e){let t=e?.skills;if(!t)return new Set;let n=t.mode===`denylist`?t.deny:t.allow;return new Set(n??[])}function _e(e){return{id:e?.id??``,name:e?.name??``,description:e?.description??``,version:String(e?.version??1),modelRows:me(e),toolModes:he(e),skillMode:e?.skills?.mode??`inherit`,skillPick:ge(e)}}function Q(e,t){let n=ee(e.modelRows);return n?.roles?{...t?.models?.defaultRole?{defaultRole:t.models.defaultRole}:{},roles:n.roles}:null}function ve(e){let t=Object.fromEntries(Object.entries(e.toolModes).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,{mode:t}]));return Object.keys(t).length>0?{builtin:t}:null}function $(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 ye(e,t){return{id:e.id.trim(),name:e.name.trim(),description:e.description.trim(),version:Number(e.version),models:Q(e,t),tools:ve(e),skills:$(e)}}function be(e){return e?{id:e.id,name:e.name,description:e.description??``,version:e.version,models:e.models?.roles?{...e.models.defaultRole?{defaultRole:e.models.defaultRole}:{},roles:e.models.roles}:null,tools:e.tools?.builtin&&Object.keys(e.tools.builtin).length>0?{builtin:e.tools.builtin}:null,skills:e.skills??{mode:`all`}}:null}function xe(e){return[e.models?.roles?`${Object.keys(e.models.roles).length} model roles`:``,e.tools?.builtin?`${Object.keys(e.tools.builtin).length} tool access settings`:``,e.skills?`skills: ${e.skills.mode}`:``].filter(Boolean).join(` · `)||`No shared settings yet`}function Se(e){return e===`safe-coder`?{id:`safe-coder`,name:`Safe Coder`,description:`Shared settings for coding agents: code-oriented model roles, careful command execution, and focused engineering skills.`,version:`1`,modelRows:[{id:`deep`,model:``,fallbacks:[],description:`Complex implementation and planning`},{id:`code`,model:``,fallbacks:[],description:`Code edits and tests`},{id:`review`,model:``,fallbacks:[],description:`Review and risk checks`}],toolModes:{exec_command:`deny`,send_message:`deny`,send_media:`deny`},skillMode:`allowlist`,skillPick:new Set([`diagnose`,`tdd`])}:e===`read-only`?{id:`read-only-research`,name:`Read-only Research`,description:`Shared settings for reading, searching, and summarizing without modifying files or running commands.`,version:`1`,modelRows:[{id:`deep`,model:``,fallbacks:[],description:`Synthesis and long-context reading`},{id:`fast`,model:``,fallbacks:[],description:`Quick summaries`}],toolModes:{write_file:`deny`,apply_patch:`deny`,exec_command:`deny`,send_message:`deny`,send_media:`deny`},skillMode:`all`,skillPick:new Set}:e===`low-cost`?{id:`low-cost-assistant`,name:`Low-cost Assistant`,description:`Shared settings for lightweight agents that should prefer faster or cheaper model roles.`,version:`1`,modelRows:[{id:`deep`,model:``,fallbacks:[],description:`Default low-cost model`},{id:`fast`,model:``,fallbacks:[],description:`Low-latency replies`},{id:`cheap`,model:``,fallbacks:[],description:`Batch or summary work`}],toolModes:{},skillMode:`inherit`,skillPick:new Set}:{id:``,name:``,description:``,version:`1`,modelRows:[],toolModes:{},skillMode:`inherit`,skillPick:new Set}}function Ce(){let e=a(s(e=>e.language)),t=e.capabilityPresetsSettings,n=!!o(e=>e.token),{data:r,error:w,isLoading:I,mutate:B}=c(n?`settings-capability-presets`:null,ie,{revalidateOnFocus:!1}),{data:V=[],isLoading:ee}=c(n?`settings-capability-presets-skills-catalog`:null,O,{revalidateOnFocus:!1}),[H,re]=f(),[se,G]=(0,U.useState)(``),[K,q]=(0,U.useState)(`overview`),[J,Y]=(0,U.useState)(()=>Se(`blank`)),[X,le]=(0,U.useState)(!1),[ue,Z]=(0,U.useState)(null),[fe,me]=(0,U.useState)(null),he=r?.presets??[],ge=r?.defaultPresetId??`default`,Q=he.find(e=>e.id===ge)??null,ve=he.filter(e=>e.id!==ge),$=(0,U.useMemo)(()=>he.find(e=>e.id===se)??he[0]??null,[he,se]),Ce=!$||J.id.trim()!==$.id,Te=!!($&&$.id===ge),Ee=JSON.stringify(ye(J,$))!==JSON.stringify(be($)),De=ue??(w instanceof Error?w.message:null),Oe=H.get(`action`)===`new`||!!H.get(`preset`),ke=Ce?t.newPreset:$?.name??t.editorTitle,Ae=t=>e.agentsSettings.toolsDisableGroups[t],je=t=>t in e.agentsSettings.toolDescriptions?e.agentsSettings.toolDescriptions[t]:``;(0,U.useEffect)(()=>{if(!r||X)return;if(H.get(`action`)===`new`){let e=H.get(`starter`);G(``),Y(Se(e===`safe-coder`||e===`read-only`||e===`low-cost`?e:`blank`)),q(`overview`);return}let e=H.get(`preset`)?.trim(),t=e?r.presets.find(t=>t.id===e):null;if(t){G(t.id),Y(_e(t)),q(H.get(`tab`)??`overview`);return}$&&(G($.id),Y(e=>e.id===$.id?e:_e($)))},[X,r,H,$]);function Me(e){G(e.id),Y(_e(e)),re({preset:e.id},{replace:!0}),q(`overview`)}function Ne(e){let t=Se(e);G(``),Y(t),Z(null),re(e===`blank`?{action:`new`}:{action:`new`,starter:e},{replace:!0}),q(`overview`)}function Pe(){re({},{replace:!0}),Z(null),Y(_e($)),q(`overview`)}async function Fe(){let e=z(J.modelRows,{invalidId:t.invalidModelRoleId,duplicateId:t.duplicateModelRoleId,invalidModel:t.invalidModelRef});if(e){Z(e),q(`models`);return}le(!0),Z(null);try{if(Ce){let e=await oe({id:J.id.trim(),name:J.name.trim(),...J.description.trim()?{description:J.description.trim()}:{}}),t=e.presets,n=ye(J,null);(n.models||n.tools||n.skills)&&(t=await te(e.presetId,{version:n.version,models:n.models,tools:n.tools,skills:n.skills})),await B(t,{revalidate:!1}),G(e.presetId),re({preset:e.presetId},{replace:!0})}else if($){let e=ye(J,$);await B(await te($.id,{name:e.name,description:e.description||null,version:e.version,models:e.models,tools:e.tools,skills:e.skills}),{revalidate:!1})}}catch(e){Z(e instanceof Error?e.message:t.saveError)}finally{le(!1)}}async function Ie(){if($){le(!0),Z(null);try{let e=await ne($.id);await B(e,{revalidate:!1});let t=e.presets[0]??null;G(t?.id??``),Y(_e(t)),re(t?{preset:t.id}:{},{replace:!0})}catch(e){Z(e instanceof Error?e.message:t.saveError)}finally{le(!1)}}}return n?(0,W.jsxs)(P,{gap:`gap-5`,className:`pb-24`,children:[(0,W.jsx)(N,{title:t.title,subtitle:t.subtitle,actions:(0,W.jsxs)(A,{type:`button`,onClick:()=>Ne(`blank`),disabled:X,children:[(0,W.jsx)(x,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})}),De?(0,W.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:De}):null,I?(0,W.jsx)(F,{sections:2}):(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:x,title:t.newPreset,subtitle:t.editorHint}),(0,W.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:[`blank`,`safe-coder`,`read-only`,`low-cost`].map(e=>(0,W.jsxs)(`button`,{type:`button`,className:`min-h-28 rounded-lg bg-surface-panel/80 px-4 py-3 text-left text-sm text-fg shadow-surface transition-colors hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>Ne(e),children:[(0,W.jsx)(`span`,{className:`font-medium`,children:t.starters[e].title}),(0,W.jsx)(`span`,{className:`mt-2 block text-xs leading-relaxed text-fg-muted`,children:t.starters[e].description})]},e))})]}),Q?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:D,title:t.globalDefaultsTitle,subtitle:t.globalDefaultsHint}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>Me(Q),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,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:Q.name}),(0,W.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.globalDefaultsBadge})]}),(0,W.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:Q.id})]}),(0,W.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})]}),Q.description?(0,W.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:Q.description}):null,(0,W.jsx)(`div`,{className:`mt-3 text-xs text-fg-subtle`,children:xe(Q)})]})]}):null,(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:D,title:t.listTitle,subtitle:t.listHint}),ve.length===0?(0,W.jsx)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-4 text-sm text-fg-muted shadow-surface`,children:t.empty}):(0,W.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:ve.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>Me(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,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:e.name}),(0,W.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:e.id})]}),(0,W.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,W.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:e.description}):null,(0,W.jsx)(`div`,{className:`mt-3 truncate text-xs text-fg-subtle`,children:xe(e)})]},e.id))})]})]}),(0,W.jsx)(_,{open:Oe,onOpenChange:e=>{e||Pe()},children:(0,W.jsxs)(p,{children:[(0,W.jsx)(v,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim`,C)}),(0,W.jsx)(j,{ref:me,className:i(`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`,E),onOpenAutoFocus:e=>e.preventDefault(),children:(0,W.jsxs)(T,{layer:`modal`,portalContainer:fe,children:[(0,W.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,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(y,{className:`truncate text-base font-semibold text-fg`,children:ke}),(0,W.jsx)(l,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:Ce?t.editorHint:J.id})]}),(0,W.jsx)(g,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:i(b,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,W.jsx)(u,{className:`size-4`,"aria-hidden":!0})})})]}),De?(0,W.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:De}):null,(0,W.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:pe.map(({id:e,icon:n})=>(0,W.jsxs)(`button`,{type:`button`,className:i(`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`,K===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>q(e),children:[(0,W.jsx)(n,{className:`size-4`,"aria-hidden":!0}),t.tabs[e]]},e))}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[K===`overview`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:m,title:t.overviewTitle,subtitle:t.overviewHint}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.idLabel}),(0,W.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:J.id,disabled:X||!Ce,onChange:e=>Y(t=>({...t,id:e.target.value.toLowerCase()})),placeholder:`safe-coder`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.versionLabel}),(0,W.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:J.version,disabled:X,inputMode:`numeric`,onChange:e=>Y(t=>({...t,version:e.target.value}))})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.nameLabel}),(0,W.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:J.name,disabled:X,onChange:e=>Y(t=>({...t,name:e.target.value})),placeholder:t.namePlaceholder})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.descriptionLabel}),(0,W.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:J.description,disabled:X,onChange:e=>Y(t=>({...t,description:e.target.value})),placeholder:t.descriptionPlaceholder})]})]}),(0,W.jsxs)(`div`,{className:`mt-5 grid gap-2 sm:grid-cols-3`,children:[(0,W.jsx)(we,{icon:D,label:t.modelsTitle,value:String(J.modelRows.length)}),(0,W.jsx)(we,{icon:h,label:t.toolsTitle,value:String(Object.keys(J.toolModes).length)}),(0,W.jsx)(we,{icon:k,label:t.skillsTitle,value:t.skillModeLabels[J.skillMode]})]})]}):null,K===`models`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:D,title:t.modelsTitle,subtitle:t.modelsHint}),(0,W.jsx)(ae,{rows:J.modelRows,onChange:e=>Y(t=>({...t,modelRows:e})),disabled:X,defaultRole:$?.models?.defaultRole,chat:e.chat,labels:{id:t.modelRoleIdLabel,description:t.modelRoleDescriptionLabel,primaryModel:t.modelPrimaryModelLabel,fallbackModels:t.modelFallbackModelsLabel,addFallback:t.modelAddFallback,removeFallback:t.modelRemoveFallback,fallbackPlaceholder:t.modelFallbackPlaceholder,fallbackEmptyHint:t.modelFallbackEmptyHint,add:t.addModelRole,remove:t.removeModelRole,recommendedTitle:t.modelRecommendedTitle,customTitle:t.modelCustomTitle,defaultBadge:t.modelDefaultBadge,addPurpose:t.addModelPurpose,noCustomRoles:t.noCustomModelRoles,idPlaceholder:`deep`,descriptionPlaceholder:t.modelRoleDescriptionPlaceholder,roleNames:t.modelRoleNames,roleDescriptions:t.modelRoleDescriptions}})]}):null,K===`tools`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:h,title:t.toolsTitle,subtitle:t.toolsHint}),(0,W.jsx)(de,{builtinToolIds:r?.builtinToolIds??[],toolModes:J.toolModes,onChange:e=>Y(t=>({...t,toolModes:e})),disabled:X,getToolDescription:je,getGroupTitle:Ae,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,modeDeny:t.toolModes.deny}})]}):null,K===`skills`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:k,title:t.skillsTitle,subtitle:t.skillsHint}),(0,W.jsx)(ce,{mode:J.skillMode,selected:J.skillPick,catalog:V,loading:ee,disabled:X,onModeChange:e=>Y(t=>({...t,skillMode:e})),onSelectedChange:e=>Y(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,K===`impact`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:d,title:t.usageTitle,subtitle:t.usageHint}),$?.usage.length?(0,W.jsx)(`div`,{className:`grid gap-2`,children:$.usage.map(e=>(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,W.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-muted`,children:e.agentId})]},e.agentId))}):(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUsage})]}):null]})}),(0,W.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,W.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,W.jsx)(`div`,{className:`font-medium text-fg`,children:Ee?t.unsavedTitle:t.noUnsavedTitle}),(0,W.jsx)(`div`,{className:`text-xs text-fg-muted`,children:Ee?($?.usage.length??0)>0?t.unsavedImpact.replace(`{{count}}`,String($?.usage.length??0)):t.unsavedNoImpact:t.noUnsavedHint})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[Ee?(0,W.jsx)(A,{type:`button`,variant:`secondary`,disabled:X,onClick:()=>Y(_e($)),children:t.discard}):null,$&&!Te?(0,W.jsxs)(A,{type:`button`,variant:`secondary`,disabled:X,onClick:()=>void Ie(),children:[(0,W.jsx)(M,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,W.jsxs)(A,{type:`button`,disabled:X||!J.id.trim()||!J.name.trim()||!Ee,onClick:()=>void Fe(),children:[(0,W.jsx)(S,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})})]})})]}):(0,W.jsxs)(P,{gap:`gap-3`,children:[(0,W.jsx)(N,{title:t.title}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})]})}function we(e){let t=(0,se.c)(10),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,W.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,W.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,W.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,W.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}export{Ce as CapabilityPresetsSettingsPanel};
|
|
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-BQ_8x0bT.js";import{t as a}from"./messages-DR9ODkb8.js";import{a as o}from"./fetch-6HXXdO77.js";import{n as s}from"./locale-store-Ba72bFmP.js";import{i as c}from"./vendor-swr-BIWyz7Rc.js";import{Ba as l,Do as u,Ec as d,El as f,Ha as p,Nc as m,Oo as h,Ra as g,Ua as _,Va as v,Wa as y,_o as b,bs as x,ds as S,io as C,ll as w,no as T,ro as E,tc as D,tr as O,vs as k,wo as A,za as j,zo as M}from"./index-BOme955B.js";import{n as N,t as P}from"./settings-page-layout-Da_LNPDS.js";import{n as F,t as I}from"./settings-loading-skeleton-A2OshMK8.js";import{n as L,t as R}from"./settings-form-section-DnDrLMWZ.js";import{a as z,i as B,o as V,t as ee}from"./typed-models-lib-DQxv2BHa.js";import{a as H,i as te,n as ne,o as re,r as ie,s as ae,t as oe}from"./capability-presets-api-CsaY2Z8B.js";var se=n(),U=e(t(),1),W=r();function G(e){return e.name||e.directoryId}function ce(e){let t=(0,se.c)(56),{mode:n,selected:r,catalog:a,loading:o,disabled:s,onModeChange:c,onSelectedChange:l,labels:u}=e,d=n===`allowlist`||n===`denylist`,f;t[0]===a?f=t[1]:(f=a.map(G).filter(Boolean),t[0]=a,t[1]=f);let p=f,m;bb0:{if(n===`inherit`){m=u.inheritSummary;break bb0}if(n===`all`){m=u.allSummary;break bb0}if(n===`off`){m=u.offSummary;break bb0}let e=n===`allowlist`?u.allowSummary:u.denySummary,i;t[2]!==r.size||t[3]!==e?(i=e.replace(`{{count}}`,String(r.size)),t[2]=r.size,t[3]=e,t[4]=i):i=t[4],m=i}let h=m,g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,W.jsx)(w,{className:`size-3.5`,"aria-hidden":!0}),t[5]=g):g=t[5];let _;t[6]===u.overrideSummaryTitle?_=t[7]:(_=(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[g,u.overrideSummaryTitle]}),t[6]=u.overrideSummaryTitle,t[7]=_);let v;t[8]===h?v=t[9]:(v=(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:h}),t[8]=h,t[9]=v);let y;t[10]!==_||t[11]!==v?(y=(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[_,v]}),t[10]=_,t[11]=v,t[12]=y):y=t[12];let b;t[13]===u.modeLabel?b=t[14]:(b=(0,W.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.modeLabel}),t[13]=u.modeLabel,t[14]=b);let x;t[15]===u.modeInherit?x=t[16]:(x=[`inherit`,u.modeInherit],t[15]=u.modeInherit,t[16]=x);let S;t[17]===u.modeAll?S=t[18]:(S=[`all`,u.modeAll],t[17]=u.modeAll,t[18]=S);let C;t[19]===u.modeAllowlist?C=t[20]:(C=[`allowlist`,u.modeAllowlist],t[19]=u.modeAllowlist,t[20]=C);let T;t[21]===u.modeDenylist?T=t[22]:(T=[`denylist`,u.modeDenylist],t[21]=u.modeDenylist,t[22]=T);let E;t[23]===u.modeOff?E=t[24]:(E=[`off`,u.modeOff],t[23]=u.modeOff,t[24]=E);let D;t[25]!==T||t[26]!==E||t[27]!==x||t[28]!==S||t[29]!==C?(D=[x,S,C,T,E],t[25]=T,t[26]=E,t[27]=x,t[28]=S,t[29]=C,t[30]=D):D=t[30];let O=D,k;t[31]!==s||t[32]!==n||t[33]!==c||t[34]!==O?(k=(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:O.map(e=>{let[t,r]=e;return(0,W.jsx)(`button`,{type:`button`,className:i(`rounded-lg px-3 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,n===t?`bg-accent-soft text-accent-fg`:`bg-surface-panel text-fg hover:bg-surface-hover/55`),disabled:s,onClick:()=>c(t),children:r},t)})}),t[31]=s,t[32]=n,t[33]=c,t[34]=O,t[35]=k):k=t[35];let j;t[36]!==k||t[37]!==b?(j=(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,k]}),t[36]=k,t[37]=b,t[38]=j):j=t[38];let M;t[39]!==a||t[40]!==p||t[41]!==s||t[42]!==u.emptyCatalog||t[43]!==u.noDescription||t[44]!==u.quickActionsLabel||t[45]!==u.quickClear||t[46]!==u.quickSelectAll||t[47]!==o||t[48]!==l||t[49]!==d||t[50]!==r?(M=d?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.quickActionsLabel}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:s||o||p.length===0,onClick:()=>l(new Set(p)),children:u.quickSelectAll}),(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:s||o||r.size===0,onClick:()=>l(new Set),children:u.quickClear})]})]}),o?(0,W.jsx)(I,{rows:3}):a.length===0?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.emptyCatalog}):(0,W.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:a.map(e=>{let t=G(e),n=r.has(t),a=typeof e.description==`string`?e.description.trim():``,o=a||u.noDescription;return(0,W.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl bg-surface-panel/70 px-3 shadow-surface`,children:(0,W.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:n,disabled:s,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),l(e)},"aria-label":t}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,W.jsx)(`p`,{className:i(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!a&&`italic text-fg-subtle`),title:o,children:o})]})]})},t)})})]}):null,t[39]=a,t[40]=p,t[41]=s,t[42]=u.emptyCatalog,t[43]=u.noDescription,t[44]=u.quickActionsLabel,t[45]=u.quickClear,t[46]=u.quickSelectAll,t[47]=o,t[48]=l,t[49]=d,t[50]=r,t[51]=M):M=t[51];let N;return t[52]!==j||t[53]!==M||t[54]!==y?(N=(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[y,j,M]}),t[52]=j,t[53]=M,t[54]=y,t[55]=N):N=t[55],N}var K=[`write_file`,`apply_patch`,`exec_command`,`execute_code`],q=[`exec_command`,`execute_code`,`automation`,`extensions`,`bundle-mcp`,`skill_manage`],J=[`send_message`,`send_media`,`text_to_speech`,`create_share`],Y=[`read_file`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`,`web_extract`],X=[...K,...J],le=[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`],ue=[`send_message`,`send_media`];function Z(e,t){let n={};for(let[r,i]of t)for(let t of r)e.has(t)&&(n[t]=i);return n}function de(e){let t=(0,se.c)(92),{builtinToolIds:n,toolModes:r,onChange:a,disabled:o,getToolDescription:s,getGroupTitle:c,labels:l}=e,u;t[0]===n?u=t[1]:(u=new Set(n),t[0]=n,t[1]=u);let d=u,f;t[2]!==d||t[3]!==r?(f=Object.entries(r).filter(e=>{let[t]=e;return d.has(t)}).toSorted(fe),t[2]=d,t[3]=r,t[4]=f):f=t[4];let p=f,m;if(t[5]!==d||t[6]!==n){m=[];for(let e of H){let t=e.toolIds.filter(e=>d.has(e));t.length>0&&m.push({key:e.key,ids:[...t]})}let e;t[8]===n?e=t[9]:(e=re(n),t[8]=n,t[9]=e);let r=e;if(r.length>0){let e;t[10]===r?e=t[11]:(e={key:`misc`,ids:r},t[10]=r,t[11]=e),m.push(e)}t[5]=d,t[6]=n,t[7]=m}else m=t[7];let h=m,g;t[12]!==a||t[13]!==r?(g=(e,t)=>{let n={...r};t===`inherit`?delete n[e]:n[e]=t,a(n)},t[12]=a,t[13]=r,t[14]=g):g=t[14];let _=g,v;t[15]!==d||t[16]!==a?(v=e=>{a(Z(d,e))},t[15]=d,t[16]=a,t[17]=v):v=t[17];let y=v;if(n.length===0){let e;return t[18]===l.emptyBuiltin?e=t[19]:(e=(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.emptyBuiltin}),t[18]=l.emptyBuiltin,t[19]=e),e}let b;t[20]===l.quickActionsLabel?b=t[21]:(b=(0,W.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.quickActionsLabel}),t[20]=l.quickActionsLabel,t[21]=b);let x;t[22]===a?x=t[23]:(x=()=>a({}),t[22]=a,t[23]=x);let S;t[24]!==o||t[25]!==l.quickClearOverrides||t[26]!==x?(S=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:x,children:l.quickClearOverrides}),t[24]=o,t[25]=l.quickClearOverrides,t[26]=x,t[27]=S):S=t[27];let C;t[28]===y?C=t[29]:(C=()=>y([[K,`deny`]]),t[28]=y,t[29]=C);let w;t[30]!==o||t[31]!==l.quickReadOnlyWorkspace||t[32]!==C?(w=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:C,children:l.quickReadOnlyWorkspace}),t[30]=o,t[31]=l.quickReadOnlyWorkspace,t[32]=C,t[33]=w):w=t[33];let T;t[34]===y?T=t[35]:(T=()=>y([[q,`deny`]]),t[34]=y,t[35]=T);let E;t[36]!==o||t[37]!==l.quickHighRiskOff||t[38]!==T?(E=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:T,children:l.quickHighRiskOff}),t[36]=o,t[37]=l.quickHighRiskOff,t[38]=T,t[39]=E):E=t[39];let D;t[40]===y?D=t[41]:(D=()=>y([[J,`deny`]]),t[40]=y,t[41]=D);let O;t[42]!==o||t[43]!==l.quickNoOutbound||t[44]!==D?(O=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:D,children:l.quickNoOutbound}),t[42]=o,t[43]=l.quickNoOutbound,t[44]=D,t[45]=O):O=t[45];let k;t[46]===y?k=t[47]:(k=()=>y([[Y,`allow`],[X,`deny`]]),t[46]=y,t[47]=k);let j;t[48]!==o||t[49]!==l.quickResearchMode||t[50]!==k?(j=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:k,children:l.quickResearchMode}),t[48]=o,t[49]=l.quickResearchMode,t[50]=k,t[51]=j):j=t[51];let M;t[52]===y?M=t[53]:(M=()=>y([[le,`allow`],[ue,`deny`]]),t[52]=y,t[53]=M);let N;t[54]!==o||t[55]!==l.quickCodingMode||t[56]!==M?(N=(0,W.jsx)(A,{type:`button`,variant:`secondary`,className:V,disabled:o,onClick:M,children:l.quickCodingMode}),t[54]=o,t[55]=l.quickCodingMode,t[56]=M,t[57]=N):N=t[57];let P;t[58]!==E||t[59]!==O||t[60]!==j||t[61]!==N||t[62]!==S||t[63]!==w?(P=(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[S,w,E,O,j,N]}),t[58]=E,t[59]=O,t[60]=j,t[61]=N,t[62]=S,t[63]=w,t[64]=P):P=t[64];let F;t[65]!==P||t[66]!==b?(F=(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,P]}),t[65]=P,t[66]=b,t[67]=F):F=t[67];let I;t[68]===l.overrideSummaryTitle?I=t[69]:(I=(0,W.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:l.overrideSummaryTitle}),t[68]=l.overrideSummaryTitle,t[69]=I);let L;t[70]!==l.modeAllow||t[71]!==l.modeDeny||t[72]!==l.noOverrides||t[73]!==p?(L=p.length>0?(0,W.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:p.map(e=>{let[t,n]=e;return(0,W.jsxs)(`span`,{className:i(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,n===`deny`&&`border-red-500/25 bg-red-500/10 text-red-700 dark:text-red-300`,n===`allow`&&`border-accent/25 bg-accent/10 text-accent`),children:[t,(0,W.jsx)(`span`,{className:`font-sans opacity-80`,children:n===`allow`?l.modeAllow:l.modeDeny})]},t)})}):(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:l.noOverrides}),t[70]=l.modeAllow,t[71]=l.modeDeny,t[72]=l.noOverrides,t[73]=p,t[74]=L):L=t[74];let R;t[75]!==I||t[76]!==L?(R=(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[I,L]}),t[75]=I,t[76]=L,t[77]=R):R=t[77];let z;t[78]!==o||t[79]!==c||t[80]!==s||t[81]!==h||t[82]!==l.inheritedMode||t[83]!==l.modeAllow||t[84]!==l.modeDeny||t[85]!==_||t[86]!==r?(z=(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:h.map(e=>{let{key:t,ids:n}=e;return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:c(t)}),(0,W.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=s(e),n=Object.prototype.hasOwnProperty.call(r,e)?r[e]:`inherit`;return(0,W.jsx)(`li`,{className:i(`rounded-xl px-3 py-2.5 shadow-surface transition-colors`,n===`inherit`?`bg-surface-panel/50`:`bg-surface-panel`),children:(0,W.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`font-mono text-xs font-medium text-fg`,children:e}),t?(0,W.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:t}):null]}),(0,W.jsx)(`div`,{className:`inline-flex w-fit rounded-lg border border-edge-subtle bg-surface-base p-0.5`,children:[`inherit`,`allow`,`deny`].map(t=>(0,W.jsx)(`button`,{type:`button`,className:i(`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`,n===t?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:text-fg`),disabled:o,onClick:()=>_(e,t),children:t===`inherit`?l.inheritedMode:t===`allow`?l.modeAllow:l.modeDeny},t))})]})},e)})})]},t)})}),t[78]=o,t[79]=c,t[80]=s,t[81]=h,t[82]=l.inheritedMode,t[83]=l.modeAllow,t[84]=l.modeDeny,t[85]=_,t[86]=r,t[87]=z):z=t[87];let B;return t[88]!==F||t[89]!==R||t[90]!==z?(B=(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[F,R,z]}),t[88]=F,t[89]=R,t[90]=z,t[91]=B):B=t[91],B}function fe(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}var pe=[{id:`overview`,icon:m},{id:`models`,icon:D},{id:`tools`,icon:h},{id:`skills`,icon:k},{id:`impact`,icon:d}];function me(e){return B(Object.entries(e?.models?.roles??{}).map(([e,t])=>({id:e,model:t.model,fallbacks:t.fallbacks??[],description:t.description})))}function he(e){return Object.fromEntries(Object.entries(e?.tools?.builtin??{}).map(([e,t])=>[e,t.mode===`allow`?`allow`:`deny`]))}function ge(e){let t=e?.skills;if(!t)return new Set;let n=t.mode===`denylist`?t.deny:t.allow;return new Set(n??[])}function _e(e){return{id:e?.id??``,name:e?.name??``,description:e?.description??``,version:String(e?.version??1),modelRows:me(e),toolModes:he(e),skillMode:e?.skills?.mode??`inherit`,skillPick:ge(e)}}function Q(e,t){let n=ee(e.modelRows);return n?.roles?{...t?.models?.defaultRole?{defaultRole:t.models.defaultRole}:{},roles:n.roles}:null}function ve(e){let t=Object.fromEntries(Object.entries(e.toolModes).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,{mode:t}]));return Object.keys(t).length>0?{builtin:t}:null}function $(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 ye(e,t){return{id:e.id.trim(),name:e.name.trim(),description:e.description.trim(),version:Number(e.version),models:Q(e,t),tools:ve(e),skills:$(e)}}function be(e){return e?{id:e.id,name:e.name,description:e.description??``,version:e.version,models:e.models?.roles?{...e.models.defaultRole?{defaultRole:e.models.defaultRole}:{},roles:e.models.roles}:null,tools:e.tools?.builtin&&Object.keys(e.tools.builtin).length>0?{builtin:e.tools.builtin}:null,skills:e.skills??{mode:`all`}}:null}function xe(e){return[e.models?.roles?`${Object.keys(e.models.roles).length} model roles`:``,e.tools?.builtin?`${Object.keys(e.tools.builtin).length} tool access settings`:``,e.skills?`skills: ${e.skills.mode}`:``].filter(Boolean).join(` · `)||`No shared settings yet`}function Se(e){return e===`safe-coder`?{id:`safe-coder`,name:`Safe Coder`,description:`Shared settings for coding agents: code-oriented model roles, careful command execution, and focused engineering skills.`,version:`1`,modelRows:[{id:`deep`,model:``,fallbacks:[],description:`Complex implementation and planning`},{id:`code`,model:``,fallbacks:[],description:`Code edits and tests`},{id:`review`,model:``,fallbacks:[],description:`Review and risk checks`}],toolModes:{exec_command:`deny`,send_message:`deny`,send_media:`deny`},skillMode:`allowlist`,skillPick:new Set([`diagnose`,`tdd`])}:e===`read-only`?{id:`read-only-research`,name:`Read-only Research`,description:`Shared settings for reading, searching, and summarizing without modifying files or running commands.`,version:`1`,modelRows:[{id:`deep`,model:``,fallbacks:[],description:`Synthesis and long-context reading`},{id:`fast`,model:``,fallbacks:[],description:`Quick summaries`}],toolModes:{write_file:`deny`,apply_patch:`deny`,exec_command:`deny`,send_message:`deny`,send_media:`deny`},skillMode:`all`,skillPick:new Set}:e===`low-cost`?{id:`low-cost-assistant`,name:`Low-cost Assistant`,description:`Shared settings for lightweight agents that should prefer faster or cheaper model roles.`,version:`1`,modelRows:[{id:`deep`,model:``,fallbacks:[],description:`Default low-cost model`},{id:`fast`,model:``,fallbacks:[],description:`Low-latency replies`},{id:`cheap`,model:``,fallbacks:[],description:`Batch or summary work`}],toolModes:{},skillMode:`inherit`,skillPick:new Set}:{id:``,name:``,description:``,version:`1`,modelRows:[],toolModes:{},skillMode:`inherit`,skillPick:new Set}}function Ce(){let e=a(s(e=>e.language)),t=e.capabilityPresetsSettings,n=!!o(e=>e.token),{data:r,error:w,isLoading:I,mutate:B}=c(n?`settings-capability-presets`:null,ie,{revalidateOnFocus:!1}),{data:V=[],isLoading:ee}=c(n?`settings-capability-presets-skills-catalog`:null,O,{revalidateOnFocus:!1}),[H,re]=f(),[se,G]=(0,U.useState)(``),[K,q]=(0,U.useState)(`overview`),[J,Y]=(0,U.useState)(()=>Se(`blank`)),[X,le]=(0,U.useState)(!1),[ue,Z]=(0,U.useState)(null),[fe,me]=(0,U.useState)(null),he=r?.presets??[],ge=r?.defaultPresetId??`default`,Q=he.find(e=>e.id===ge)??null,ve=he.filter(e=>e.id!==ge),$=(0,U.useMemo)(()=>he.find(e=>e.id===se)??he[0]??null,[he,se]),Ce=!$||J.id.trim()!==$.id,Te=!!($&&$.id===ge),Ee=JSON.stringify(ye(J,$))!==JSON.stringify(be($)),De=ue??(w instanceof Error?w.message:null),Oe=H.get(`action`)===`new`||!!H.get(`preset`),ke=Ce?t.newPreset:$?.name??t.editorTitle,Ae=t=>e.agentsSettings.toolsDisableGroups[t],je=t=>t in e.agentsSettings.toolDescriptions?e.agentsSettings.toolDescriptions[t]:``;(0,U.useEffect)(()=>{if(!r||X)return;if(H.get(`action`)===`new`){let e=H.get(`starter`);G(``),Y(Se(e===`safe-coder`||e===`read-only`||e===`low-cost`?e:`blank`)),q(`overview`);return}let e=H.get(`preset`)?.trim(),t=e?r.presets.find(t=>t.id===e):null;if(t){G(t.id),Y(_e(t)),q(H.get(`tab`)??`overview`);return}$&&(G($.id),Y(e=>e.id===$.id?e:_e($)))},[X,r,H,$]);function Me(e){G(e.id),Y(_e(e)),re({preset:e.id},{replace:!0}),q(`overview`)}function Ne(e){let t=Se(e);G(``),Y(t),Z(null),re(e===`blank`?{action:`new`}:{action:`new`,starter:e},{replace:!0}),q(`overview`)}function Pe(){re({},{replace:!0}),Z(null),Y(_e($)),q(`overview`)}async function Fe(){let e=z(J.modelRows,{invalidId:t.invalidModelRoleId,duplicateId:t.duplicateModelRoleId,invalidModel:t.invalidModelRef});if(e){Z(e),q(`models`);return}le(!0),Z(null);try{if(Ce){let e=await oe({id:J.id.trim(),name:J.name.trim(),...J.description.trim()?{description:J.description.trim()}:{}}),t=e.presets,n=ye(J,null);(n.models||n.tools||n.skills)&&(t=await te(e.presetId,{version:n.version,models:n.models,tools:n.tools,skills:n.skills})),await B(t,{revalidate:!1}),G(e.presetId),re({preset:e.presetId},{replace:!0})}else if($){let e=ye(J,$);await B(await te($.id,{name:e.name,description:e.description||null,version:e.version,models:e.models,tools:e.tools,skills:e.skills}),{revalidate:!1})}}catch(e){Z(e instanceof Error?e.message:t.saveError)}finally{le(!1)}}async function Ie(){if($){le(!0),Z(null);try{let e=await ne($.id);await B(e,{revalidate:!1});let t=e.presets[0]??null;G(t?.id??``),Y(_e(t)),re(t?{preset:t.id}:{},{replace:!0})}catch(e){Z(e instanceof Error?e.message:t.saveError)}finally{le(!1)}}}return n?(0,W.jsxs)(P,{gap:`gap-5`,className:`pb-24`,children:[(0,W.jsx)(N,{title:t.title,subtitle:t.subtitle,actions:(0,W.jsxs)(A,{type:`button`,onClick:()=>Ne(`blank`),disabled:X,children:[(0,W.jsx)(x,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})}),De?(0,W.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:De}):null,I?(0,W.jsx)(F,{sections:2}):(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:x,title:t.newPreset,subtitle:t.editorHint}),(0,W.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:[`blank`,`safe-coder`,`read-only`,`low-cost`].map(e=>(0,W.jsxs)(`button`,{type:`button`,className:`min-h-28 rounded-lg bg-surface-panel/80 px-4 py-3 text-left text-sm text-fg shadow-surface transition-colors hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>Ne(e),children:[(0,W.jsx)(`span`,{className:`font-medium`,children:t.starters[e].title}),(0,W.jsx)(`span`,{className:`mt-2 block text-xs leading-relaxed text-fg-muted`,children:t.starters[e].description})]},e))})]}),Q?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:D,title:t.globalDefaultsTitle,subtitle:t.globalDefaultsHint}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>Me(Q),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,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:Q.name}),(0,W.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.globalDefaultsBadge})]}),(0,W.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:Q.id})]}),(0,W.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})]}),Q.description?(0,W.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:Q.description}):null,(0,W.jsx)(`div`,{className:`mt-3 text-xs text-fg-subtle`,children:xe(Q)})]})]}):null,(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:D,title:t.listTitle,subtitle:t.listHint}),ve.length===0?(0,W.jsx)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-4 text-sm text-fg-muted shadow-surface`,children:t.empty}):(0,W.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:ve.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>Me(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,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:e.name}),(0,W.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:e.id})]}),(0,W.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,W.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:e.description}):null,(0,W.jsx)(`div`,{className:`mt-3 truncate text-xs text-fg-subtle`,children:xe(e)})]},e.id))})]})]}),(0,W.jsx)(_,{open:Oe,onOpenChange:e=>{e||Pe()},children:(0,W.jsxs)(p,{children:[(0,W.jsx)(v,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim`,C)}),(0,W.jsx)(j,{ref:me,className:i(`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`,E),onOpenAutoFocus:e=>e.preventDefault(),children:(0,W.jsxs)(T,{layer:`modal`,portalContainer:fe,children:[(0,W.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,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(y,{className:`truncate text-base font-semibold text-fg`,children:ke}),(0,W.jsx)(l,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:Ce?t.editorHint:J.id})]}),(0,W.jsx)(g,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:i(b,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,W.jsx)(u,{className:`size-4`,"aria-hidden":!0})})})]}),De?(0,W.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:De}):null,(0,W.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:pe.map(({id:e,icon:n})=>(0,W.jsxs)(`button`,{type:`button`,className:i(`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`,K===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>q(e),children:[(0,W.jsx)(n,{className:`size-4`,"aria-hidden":!0}),t.tabs[e]]},e))}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[K===`overview`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:m,title:t.overviewTitle,subtitle:t.overviewHint}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.idLabel}),(0,W.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:J.id,disabled:X||!Ce,onChange:e=>Y(t=>({...t,id:e.target.value.toLowerCase()})),placeholder:`safe-coder`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.versionLabel}),(0,W.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:J.version,disabled:X,inputMode:`numeric`,onChange:e=>Y(t=>({...t,version:e.target.value}))})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.nameLabel}),(0,W.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:J.name,disabled:X,onChange:e=>Y(t=>({...t,name:e.target.value})),placeholder:t.namePlaceholder})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.descriptionLabel}),(0,W.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:J.description,disabled:X,onChange:e=>Y(t=>({...t,description:e.target.value})),placeholder:t.descriptionPlaceholder})]})]}),(0,W.jsxs)(`div`,{className:`mt-5 grid gap-2 sm:grid-cols-3`,children:[(0,W.jsx)(we,{icon:D,label:t.modelsTitle,value:String(J.modelRows.length)}),(0,W.jsx)(we,{icon:h,label:t.toolsTitle,value:String(Object.keys(J.toolModes).length)}),(0,W.jsx)(we,{icon:k,label:t.skillsTitle,value:t.skillModeLabels[J.skillMode]})]})]}):null,K===`models`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:D,title:t.modelsTitle,subtitle:t.modelsHint}),(0,W.jsx)(ae,{rows:J.modelRows,onChange:e=>Y(t=>({...t,modelRows:e})),disabled:X,defaultRole:$?.models?.defaultRole,chat:e.chat,labels:{id:t.modelRoleIdLabel,description:t.modelRoleDescriptionLabel,primaryModel:t.modelPrimaryModelLabel,fallbackModels:t.modelFallbackModelsLabel,addFallback:t.modelAddFallback,removeFallback:t.modelRemoveFallback,fallbackPlaceholder:t.modelFallbackPlaceholder,fallbackEmptyHint:t.modelFallbackEmptyHint,add:t.addModelRole,remove:t.removeModelRole,recommendedTitle:t.modelRecommendedTitle,customTitle:t.modelCustomTitle,defaultBadge:t.modelDefaultBadge,addPurpose:t.addModelPurpose,noCustomRoles:t.noCustomModelRoles,idPlaceholder:`deep`,descriptionPlaceholder:t.modelRoleDescriptionPlaceholder,roleNames:t.modelRoleNames,roleDescriptions:t.modelRoleDescriptions}})]}):null,K===`tools`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:h,title:t.toolsTitle,subtitle:t.toolsHint}),(0,W.jsx)(de,{builtinToolIds:r?.builtinToolIds??[],toolModes:J.toolModes,onChange:e=>Y(t=>({...t,toolModes:e})),disabled:X,getToolDescription:je,getGroupTitle:Ae,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,modeDeny:t.toolModes.deny}})]}):null,K===`skills`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:k,title:t.skillsTitle,subtitle:t.skillsHint}),(0,W.jsx)(ce,{mode:J.skillMode,selected:J.skillPick,catalog:V,loading:ee,disabled:X,onModeChange:e=>Y(t=>({...t,skillMode:e})),onSelectedChange:e=>Y(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,K===`impact`?(0,W.jsxs)(R,{children:[(0,W.jsx)(L,{icon:d,title:t.usageTitle,subtitle:t.usageHint}),$?.usage.length?(0,W.jsx)(`div`,{className:`grid gap-2`,children:$.usage.map(e=>(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,W.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-muted`,children:e.agentId})]},e.agentId))}):(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUsage})]}):null]})}),(0,W.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,W.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,W.jsx)(`div`,{className:`font-medium text-fg`,children:Ee?t.unsavedTitle:t.noUnsavedTitle}),(0,W.jsx)(`div`,{className:`text-xs text-fg-muted`,children:Ee?($?.usage.length??0)>0?t.unsavedImpact.replace(`{{count}}`,String($?.usage.length??0)):t.unsavedNoImpact:t.noUnsavedHint})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[Ee?(0,W.jsx)(A,{type:`button`,variant:`secondary`,disabled:X,onClick:()=>Y(_e($)),children:t.discard}):null,$&&!Te?(0,W.jsxs)(A,{type:`button`,variant:`secondary`,disabled:X,onClick:()=>void Ie(),children:[(0,W.jsx)(M,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,W.jsxs)(A,{type:`button`,disabled:X||!J.id.trim()||!J.name.trim()||!Ee,onClick:()=>void Fe(),children:[(0,W.jsx)(S,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})})]})})]}):(0,W.jsxs)(P,{gap:`gap-3`,children:[(0,W.jsx)(N,{title:t.title}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})]})}function we(e){let t=(0,se.c)(10),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,W.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,W.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,W.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,W.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}export{Ce 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{t as i}from"./cn-BQ_8x0bT.js";import{t as a}from"./messages-DR9ODkb8.js";import{a as o,n as s,o as c,t as l}from"./fetch-6HXXdO77.js";import{n as u}from"./locale-store-Ba72bFmP.js";import{i as d}from"./vendor-swr-BIWyz7Rc.js";import{Ba as f,Dc as p,Do as m,Ga as h,Ha as g,Qa as _,Qc as v,Ra as y,Ro as b,Tl as x,Ua as S,Us as C,Va as w,Wa as T,Xc as E,_i as D,_o as O,_s as k,as as A,da as j,ga as M,gr as N,ha as P,hr as F,io as I,mr as L,no as R,ps as z,qn as ee,qo as te,ro as ne,rt as re,wl as ie,wo as B,za as ae}from"./index-DqFBdoK-.js";import{n as oe,t as se}from"./settings-page-layout-DfbMLJgN.js";import{n as ce}from"./settings-loading-skeleton-CGxa3aCb.js";import{t as le}from"./schema-form-D8XdvcNH.js";import{t as ue}from"./browser-BLJWD7WI.js";import{n as de,t as fe}from"./channels-status-swr-BG_j4Ci-.js";import{t as pe}from"./use-channel-catalog-BCBfSoHx.js";var V=n(),me=e(ue(),1),H=e(t(),1),U=r();function he(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}async function ge(e){let t=await l(c(`/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 _e({entry:e,locale:t,messages:n,onChanged:r,compact:a=!1}){let o=(0,H.useMemo)(()=>he(e),[e]),s=(0,H.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[c,l]=(0,H.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,H.useEffect)(()=>{l({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let u=(0,H.useCallback)(async(n,i)=>{l(e=>({...e,busy:!0,error:null}));try{let a=await ge({channelId:e.id,actionId:n,locale:t,input:i});l(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){l(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,H.useEffect)(()=>{let t=K(c.payload,e.id);if(!t){l(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return l(e=>e.generatedQr?{...e,generatedQr:null}:e),me.toDataURL(t,{width:220,margin:1}).then(e=>{n||l(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,c.payload]),(0,H.useEffect)(()=>{let n=c.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||ge({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(l(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||l(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,c.poll]);let d=o?.[1].label??(e.configured?n.reconnect:n.connect),f=e.actions?.[`doctor.run`]?.label??n.diagnose,m=G(c.payload),h=K(c.payload,e.id),g=h?c.generatedQr:q(c.payload),_=o?.[1].result===`qr`&&(c.busy||c.payload?.type===`qr`||c.payload?.type===`poll`),v=c.payload?.type===`form`?c.payload:null,y=c.payload?.type===`diagnostics`?c.payload.checks:null;return(0,U.jsxs)(`div`,{className:a?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:i(`flex flex-wrap items-start gap-3`,a?`justify-end`:`justify-between`),children:[a?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:[o?(0,U.jsxs)(B,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(o[0]),children:[c.busy?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(k,{className:`size-4`}),d]}):null,e.actions?.[`doctor.run`]?(0,U.jsxs)(B,{type:`button`,variant:`secondary`,disabled:c.busy,onClick:()=>void u(`doctor.run`),children:[(0,U.jsx)(te,{className:`size-4`}),f]}):null]})]}),m?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:m}):null,c.error?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:c.error}):null,_?(0,U.jsxs)(`div`,{className:i(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base px-3 py-3 shadow-surface`,a?`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:g?(0,U.jsx)(`img`,{src:g,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)(P,{className:`size-48 rounded-md`})})}),(0,U.jsxs)(`div`,{className:i(`min-w-0 max-w-sm text-sm text-fg-muted`,a&&`w-full sm:w-auto`),children:[g?(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)(P,{className:`h-4 w-48 max-w-full`}),(0,U.jsx)(P,{className:`h-4 w-36 max-w-full`})]}),h?(0,U.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:h,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,U.jsx)(p,{className:`size-3.5`})]}):null]})]}):null,c.payload?.type===`poll`&&c.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)(E,{className:c.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,U.jsx)(`span`,{className:c.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:c.payload.message??(c.payload.ok?n.complete:n.failed)})]}):null,v?(0,U.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,U.jsx)(le,{schema:v.schema,values:c.formDraft,onChange:e=>l(t=>({...t,formDraft:e})),disabled:c.busy,labels:s}),(0,U.jsx)(B,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(v.submitAction,c.formDraft),children:n.saveSetup})]}):null,y?(0,U.jsx)(`div`,{className:`mt-4 space-y-2`,children:y.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 ve=40;function J(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function ye(e,t){return e.find(e=>e.id===J(t))?.agentId?.trim().toLowerCase()??``}function be(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:ve,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function xe(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 Se(e,t,n){let r=xe(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function Ce(e,t=!1){return e===`drawer`?i(`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`,ne):i(`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)]`,ne,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function we(e){let t=(0,V.c)(33),{presentation:n,open:r,onOpenChange:a,title:o,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:p,wide:h,headerExtra:_}=e,v=h===void 0?!1:h,b=n===`drawer`,[x,C]=(0,H.useState)(null),E;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,U.jsx)(w,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,I)}),t[0]=E):E=t[0];let D;t[1]!==n||t[2]!==v?(D=Ce(n,v),t[1]=n,t[2]=v,t[3]=D):D=t[3];let k;t[4]===c?k=t[5]:(k=c?(0,U.jsx)(T,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=k);let A;t[6]===l?A=t[7]:(A=l?(0,U.jsx)(f,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=A);let j;t[8]!==u||t[9]!==s||t[10]!==_||t[11]!==b||t[12]!==o?(j=b?(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:[o?(0,U.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:o}):null,s?(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,U.jsx)(y,{asChild:!0,children:(0,U.jsx)(B,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,U.jsx)(m,{className:`size-5`,strokeWidth:1.75})})})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(y,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,className:i(O,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,U.jsx)(m,{className:`size-4`})})}),_]}),t[8]=u,t[9]=s,t[10]=_,t[11]=b,t[12]=o,t[13]=j):j=t[13];let M=b?`px-4 py-4`:`p-6`,N;t[14]===M?N=t[15]:(N=i(`min-h-0 flex-1 overflow-y-auto`,M),t[14]=M,t[15]=N);let P;t[16]!==d||t[17]!==N?(P=(0,U.jsx)(`div`,{className:N,children:d}),t[16]=d,t[17]=N,t[18]=P):P=t[18];let F;t[19]!==p||t[20]!==x||t[21]!==k||t[22]!==A||t[23]!==j||t[24]!==P?(F=(0,U.jsxs)(R,{layer:`modal`,portalContainer:x,children:[k,A,j,P,p]}),t[19]=p,t[20]=x,t[21]=k,t[22]=A,t[23]=j,t[24]=P,t[25]=F):F=t[25];let L;t[26]!==F||t[27]!==D?(L=(0,U.jsxs)(g,{children:[E,(0,U.jsx)(ae,{ref:C,className:D,onOpenAutoFocus:Te,children:F})]}),t[26]=F,t[27]=D,t[28]=L):L=t[28];let z;return t[29]!==a||t[30]!==r||t[31]!==L?(z=(0,U.jsx)(S,{open:r,onOpenChange:a,children:L}),t[29]=a,t[30]=r,t[31]=L,t[32]=z):z=t[32],z}function Te(e){return e.preventDefault()}var Ee=(0,H.memo)(function(e){let t=(0,V.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)(D,{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 De(e){let t=(0,V.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 d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,U.jsx)(B,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,p;t[7]!==n.discard||t[8]!==o||t[9]!==f?(p=(0,U.jsx)(B,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=p):p=t[10];let m=!r||i,h;t[11]===s?h=t[12]:(h=()=>void s(),t[11]=s,t[12]=h);let g=i?n.saving:n.save,_;t[13]!==m||t[14]!==h||t[15]!==g?(_=(0,U.jsx)(B,{type:`button`,variant:`primary`,disabled:m,onClick:h,children:g}),t[13]=m,t[14]=h,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==p||t[19]!==_?(v=(0,U.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,p,_]}),t[17]=d,t[18]=p,t[19]=_,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==u?(y=(0,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,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}var Oe=`channels-status`;function ke(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function Ae(e){let t=t=>e(t.detail);return window.addEventListener(Oe,t),()=>window.removeEventListener(Oe,t)}function je(e,t){let n=(0,V.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return Ae(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,H.useEffect)(i,a)}function Me(e){return e?c(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Ne(e){return(await s(c(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Pe=[`enabled`];async function Fe(){let e=await s(c(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Ie(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Le(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 Re(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function ze(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Be(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 Ve(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=>!Pe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Pe.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 He(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 Ue(e){let t=e.properties;if(!X(t))return!1;for(let[e,n]of Object.entries(t))X(n)&&n.type===`object`&&Ue(n)&&delete t[e];return Object.keys(t).length===0}function We(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 Ue(n),n}function Ge(e){return e.type===`object`&&X(e.properties)&&Object.keys(e.properties).length>0}function Ke(e,t){let n=e;for(let e of t.split(`.`)){if(!X(n))return;n=n[e]}return n}function qe(e){let t=e.accounts;return X(t)?Object.values(t).filter(e=>X(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Je(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 Ye(e,t,n){let r=[],i=Y(e);if(i.issues.length>0&&r.push(Qe(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Je(e,Ke(t,e),n);i&&r.push(i)}let a=qe(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Q(e,t){let n=Y(e),r=he(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 Xe(e,t){let n=he(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function Ze(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 Qe(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 $e({entry:e}){let t=o(e=>e.token),[n,r]=(0,H.useState)(!1),i=(0,H.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(c(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Ie(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)(M,{sourceChannel:e.id,className:`size-7`})})}function et(e){let t=(0,V.c)(16),{checked:n,disabled:r,onToggle:a,label:o}=e,s;t[0]===a?s=t[1]:(s=e=>{e.stopPropagation(),a()},t[0]=a,t[1]=s);let c=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,l=r&&`cursor-not-allowed opacity-60`,u;t[2]!==c||t[3]!==l?(u=i(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,c,l),t[2]=c,t[3]=l,t[4]=u):u=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=i(`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]!==o||t[12]!==s||t[13]!==u||t[14]!==p?(m=(0,U.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":o,disabled:r,onClick:s,className:u,children:p}),t[9]=n,t[10]=r,t[11]=o,t[12]=s,t[13]=u,t[14]=p,t[15]=m):m=t[15],m}function tt(e){let t=(0,V.c)(71),{entry:n,config:r,runtime:a,busy:o,restarting:s,ch:c,onOpen:l,onToggle:u,onRestart:d}=e,f;t[0]===n?f=t[1]:(f=Y(n),t[0]=n,t[1]=f);let p=f,m,h,g,_,v,y,b;if(t[2]!==o||t[3]!==c||t[4]!==r||t[5]!==n||t[6]!==l||t[7]!==d||t[8]!==u||t[9]!==a||t[10]!==p.enabled||t[11]!==p.ready){let e=Ye(n,r,c),s=Ze(n,c);m=!p.enabled&&p.ready?u:a===`stopped`?d:l,y=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let f;t[19]===n?f=t[20]:(f=(0,U.jsx)($e,{entry:n}),t[19]=n,t[20]=f);let x;t[21]===n.label?x=t[22]:(x=(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=x);let S;t[23]===a?S=t[24]:(S=i(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Be(a)),t[23]=a,t[24]=S);let C;t[25]!==c||t[26]!==a?(C=Re(a,c),t[25]=c,t[26]=a,t[27]=C):C=t[27];let w;t[28]!==S||t[29]!==C?(w=(0,U.jsx)(`span`,{className:S,children:C}),t[28]=S,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==x?(T=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[x,w]}),t[31]=w,t[32]=x,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==f?(E=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[f,T]}),t[34]=T,t[35]=f,t[36]=E):E=t[36];let D=p.enabled,O;t[37]!==c.toggleChannel||t[38]!==n.label?(O=c.toggleChannel.replace(`{{channel}}`,n.label),t[37]=c.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==o||t[41]!==u||t[42]!==p.enabled||t[43]!==O?(k=(0,U.jsx)(et,{checked:D,disabled:o,label:O,onToggle:u}),t[40]=o,t[41]=u,t[42]=p.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(b=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=b):b=t[47],h=`button`,g=l,_=`mt-5 min-h-[6.25rem] text-left`,v=p.ready?(0,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(rt)}):null]}):(0,U.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-3`,children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:c.cardSetupTitle}),(0,U.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Xe(n,c)}),s.length>0?(0,U.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:s.map(nt)}):null]}),t[2]=o,t[3]=c,t[4]=r,t[5]=n,t[6]=l,t[7]=d,t[8]=u,t[9]=a,t[10]=p.enabled,t[11]=p.ready,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b}else m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18];let x;t[48]!==h||t[49]!==g||t[50]!==_||t[51]!==v?(x=(0,U.jsx)(`button`,{type:h,onClick:g,className:_,children:v}),t[48]=h,t[49]=g,t[50]=_,t[51]=v,t[52]=x):x=t[52];let S=o||s,w;t[53]!==o||t[54]!==s?(w=o||s?(0,U.jsx)(C,{className:`size-4 animate-spin`}):null,t[53]=o,t[54]=s,t[55]=w):w=t[55];let T;t[56]!==c||t[57]!==n||t[58]!==s||t[59]!==a?(T=s?c.restartingChannel:a===`stopped`?c.restartChannel:Q(n,c),t[56]=c,t[57]=n,t[58]=s,t[59]=a,t[60]=T):T=t[60];let E;t[61]!==m||t[62]!==w||t[63]!==T||t[64]!==S?(E=(0,U.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,U.jsxs)(B,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:m,disabled:S,children:[w,T]})}),t[61]=m,t[62]=w,t[63]=T,t[64]=S,t[65]=E):E=t[65];let D;return t[66]!==E||t[67]!==y||t[68]!==b||t[69]!==x?(D=(0,U.jsxs)(`article`,{className:y,children:[b,x,E]}),t[66]=E,t[67]=y,t[68]=b,t[69]=x,t[70]=D):D=t[70],D}function nt(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 rt(e){return(0,U.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function it(e){let t=(0,V.c)(51),{runtime:n,restarting:r,checking:a,showConnectionOptions:o,canManageConnection:s,ch:c,onRestart:l,onCheck:u,onManageConnection:d}=e,f=n===`running`?E:n===`stopped`||n===`needs_setup`?v:C,p=n===`running`&&`text-emerald-600 dark:text-emerald-400`,m=n===`stopped`&&`text-red-600 dark:text-red-400`,h=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,g=n===`disabled`&&`text-fg-muted`,_=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,y;t[0]!==p||t[1]!==m||t[2]!==h||t[3]!==g||t[4]!==_?(y=i(`mt-0.5 size-5 shrink-0`,p,m,h,g,_),t[0]=p,t[1]=m,t[2]=h,t[3]=g,t[4]=_,t[5]=y):y=t[5];let b;t[6]!==f||t[7]!==y?(b=(0,U.jsx)(f,{className:y}),t[6]=f,t[7]=y,t[8]=b):b=t[8];let x;t[9]===c.connectionStatus?x=t[10]:(x=(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:c.connectionStatus}),t[9]=c.connectionStatus,t[10]=x);let S;t[11]!==c||t[12]!==n?(S=ze(n,c),t[11]=c,t[12]=n,t[13]=S):S=t[13];let w;t[14]===S?w=t[15]:(w=(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:S}),t[14]=S,t[15]=w);let T;t[16]!==w||t[17]!==x?(T=(0,U.jsxs)(`div`,{children:[x,w]}),t[16]=w,t[17]=x,t[18]=T):T=t[18];let D;t[19]!==T||t[20]!==b?(D=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[b,T]}),t[19]=T,t[20]=b,t[21]=D):D=t[21];let O=a||r,k;t[22]===a?k=t[23]:(k=a?(0,U.jsx)(C,{className:`size-4 animate-spin`}):null,t[22]=a,t[23]=k);let A=a?c.checkingConnection:c.checkConnection,j;t[24]!==u||t[25]!==O||t[26]!==k||t[27]!==A?(j=(0,U.jsxs)(B,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:O,onClick:u,children:[k,A]}),t[24]=u,t[25]=O,t[26]=k,t[27]=A,t[28]=j):j=t[28];let M;t[29]!==c.restartChannel||t[30]!==c.restartingChannel||t[31]!==a||t[32]!==l||t[33]!==r||t[34]!==n?(M=n===`stopped`?(0,U.jsxs)(B,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||a,onClick:l,children:[r?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(z,{className:`size-4`}),r?c.restartingChannel:c.restartChannel]}):null,t[29]=c.restartChannel,t[30]=c.restartingChannel,t[31]=a,t[32]=l,t[33]=r,t[34]=n,t[35]=M):M=t[35];let N;t[36]!==s||t[37]!==c.connectionOptions||t[38]!==c.hideConnectionOptions||t[39]!==a||t[40]!==d||t[41]!==r||t[42]!==o?(N=s?(0,U.jsx)(B,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:a||r,onClick:d,children:o?c.hideConnectionOptions:c.connectionOptions}):null,t[36]=s,t[37]=c.connectionOptions,t[38]=c.hideConnectionOptions,t[39]=a,t[40]=d,t[41]=r,t[42]=o,t[43]=N):N=t[43];let P;t[44]!==j||t[45]!==M||t[46]!==N?(P=(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[j,M,N]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P):P=t[47];let F;return t[48]!==D||t[49]!==P?(F=(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:[D,P]})}),t[48]=D,t[49]=P,t[50]=F):F=t[50],F}function at(e){let t=(0,V.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)(b,{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:Qe(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 ot(){let e=u(e=>e.language),t=a(e),n=o(e=>!!e.token),r=ie(),{channelId:s}=x(),f=N(s),m=pe(n,e),g=m.entries,{data:v,mutate:y,isValidating:b}=d(n?fe():null,de,{revalidateOnFocus:!0}),{data:S,mutate:C}=d(n?`channels-config-map`:null,Fe,{revalidateOnFocus:!1}),w=S?.channels??{},T=S?.bindings??[],{data:E}=d(n?`channel-routing-agents`:null,j,{revalidateOnFocus:!1}),D=h(e=>e.setPageHeader),O=h(e=>e.clearPageHeader),k=(0,H.useMemo)(()=>g.find(e=>e.id===f),[f,g]),M=k?Le(k):null,{data:P,mutate:I}=d(n&&M?Me(M):null,()=>Ne(M)),[R,z]=(0,H.useState)(null),[te,ne]=(0,H.useState)(!1),[B,ae]=(0,H.useState)(null),[ue,V]=(0,H.useState)(null),[me,ge]=(0,H.useState)(!1),[W,G]=(0,H.useState)(null),[K,q]=(0,H.useState)(null),ve=R??P??{},J=t.channelsSettings,xe=(0,H.useMemo)(()=>k?.configSchema??{type:`object`,properties:{}},[k?.configSchema]),Ce=(0,H.useMemo)(()=>We(xe,Pe),[xe]),Te=(0,H.useMemo)(()=>Ve(k),[k]),Oe=(0,H.useMemo)(()=>He(Ce,Te),[Te,Ce]),Ae=(0,H.useMemo)(()=>We(Ce,Te),[Te,Ce]),Ie=(0,H.useMemo)(()=>Ge(Oe),[Oe]),ze=k?K??ye(T,k.id):``,X=(0,H.useMemo)(()=>(E?.items??[]).map(e=>{let n=ee(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[E?.items,t.agentsSettings]),Z=E?.items.find(e=>e.id===E.defaultId),Ue=Z?ee(Z,t.agentsSettings):E?.defaultId??``,Ke=(0,H.useMemo)(()=>({defaultBooleanLabel:J.schemaBooleanDefault,unsupportedArrayType:J.schemaUnsupportedArrayType,arrayAddPlaceholder:J.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>J.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[J]),qe=(0,H.useMemo)(()=>new Map((v??[]).map(e=>[e.name,e])),[v]),Je=v!==void 0,Ye=(0,H.useCallback)(e=>Se(e,qe.get(e.id),Je),[qe,Je]),Q=(0,H.useCallback)(async()=>{await Promise.all([m.mutate(),y()])},[m,y]);je((0,H.useCallback)(e=>{let t=ke(e);t&&y(t,!1)},[y]),n);let Xe=(0,H.useMemo)(()=>n?(0,U.jsx)(Ee,{ch:J,refreshing:m.isValidating||b,saveOk:!1,onRefresh:()=>void Q()}):null,[m.isValidating,J,n,b,Q]);(0,H.useLayoutEffect)(()=>(D({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}),()=>O()),[O,Xe,t.settingsSections.channels,D]);let Ze=(0,H.useCallback)(e=>{r(F(e)),z(null),q(null),G(null)},[r]),Qe=(0,H.useCallback)(()=>{r(L),z(null),q(null),G(null)},[r]),nt=(0,H.useCallback)(async e=>{V(e.id),G(null);try{let t=await l(c(`/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{V(null)}},[Q]);(0,H.useEffect)(()=>{q(null),ge(!1)},[k?.id]);let rt=(0,H.useCallback)(async()=>{if(!k||!R&&K===null)return!1;let e=Le(k);ne(!0),G(null);try{let t=await l(c(`/api/config`),{method:`PATCH`,body:JSON.stringify({...R?{channels:{[e]:R}}:{},...K===null?{}:{bindings:be(T,k.id,K)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return R&&await I(R,!1),await C(),await m.mutate(),z(null),q(null),!0}catch(e){return G(e instanceof Error?e.message:String(e)),!1}finally{ne(!1)}},[k,K,T,m,R,C,I]),ot=(0,H.useCallback)(async e=>{let t=Y(e),n=Le(e),r=k?.id===e.id?R: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 l(c(`/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 m.mutate(),await C(),await y(),k?.id===e.id&&(await I(),z(null))}catch(e){G(e instanceof Error?e.message:String(e))}finally{ae(null)}},[k?.id,m,R,C,I,y,Ze]),$=k?.ui?.modal,st=$?.placement!==`replace-config`,ct=k?Ye(k):`checking`,lt=k?!Y(k).ready||me:!1;return n?(0,U.jsxs)(se,{gap:`gap-4`,children:[m.isLoading?(0,U.jsx)(ce,{sections:2}):m.error?(0,U.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(m.error)}):(0,U.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:g.map(e=>(0,U.jsx)(tt,{entry:e,config:w[Le(e)]?.config,runtime:Ye(e),busy:B===e.id,restarting:ue===e.id,ch:J,onOpen:()=>Ze(e.id),onToggle:()=>void ot(e),onRestart:()=>void nt(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)(we,{presentation:`modal`,open:!!k,onOpenChange:e=>{e||Qe()},closeAriaLabel:J.close,srTitle:k?.label??J.selectChannel,srDescription:k?.description,wide:!0,footer:k?(0,U.jsx)(De,{ch:J,dirty:!!R||K!==null,saving:te,onCancel:Qe,onDiscard:()=>{z(null),q(null)},onSave:rt}):null,children:k?(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 px-3 py-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)($e,{entry:k}),(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:k.label}),(0,U.jsx)(`span`,{className:i(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Be(ct)),children:Re(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(k).ready&&he(k)?.[1].result===`qr`?J.scanLoginHint.replace(`{{channel}}`,k.label):k.description}),k.docsPath?(0,U.jsxs)(`a`,{href:k.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[J.docs,(0,U.jsx)(p,{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(k).enabled?J.enabledLabel:J.disabledLabel}),(0,U.jsx)(et,{checked:Y(k).enabled,disabled:B===k.id,label:J.toggleChannel.replace(`{{channel}}`,k.label),onToggle:()=>void ot(k)})]})]})}),(0,U.jsx)(it,{runtime:ct,restarting:ue===k.id,checking:b,showConnectionOptions:me,canManageConnection:Y(k).ready&&$?.placement!==`replace-config`,ch:J,onRestart:()=>void nt(k),onCheck:()=>void Q(),onManageConnection:()=>ge(e=>!e)}),(0,U.jsx)(at,{entry:k,ch:J}),lt&&$?.placement!==`replace-config`?(0,U.jsx)(_e,{entry:k,locale:e,messages:J,compact:!0,onChanged:async()=>{await I(),await Q(),await C()}},k.id):null,$?.entrypoint&&$.placement===`before-config`?(0,U.jsx)(re,{extensionId:k.extensionId,extensionName:k.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:k.id,entry:k,config:ve}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,U.jsx)(re,{extensionId:k.extensionId,extensionName:k.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:k.id,entry:k,config:ve}}):null,st&&Ie?(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:Oe,values:ve,onChange:e=>z(e),disabled:te,labels:Ke})]}):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)(_,{value:ze,options:X,placeholder:J.agentRoutingSelect,emptyLabel:J.agentRoutingDefault.replace(`{{agent}}`,Ue||J.agentRoutingSelect),ariaLabel:J.agentRouting,disabled:te||!E,onChange:e=>q(e)})]})]}),st&&Ge(Ae)?(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:Ae,values:ve,onChange:e=>z(e),disabled:te,labels:Ke})})]}):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{ot 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{t as i}from"./cn-BQ_8x0bT.js";import{t as a}from"./messages-DR9ODkb8.js";import{a as o,n as s,o as c,t as l}from"./fetch-6HXXdO77.js";import{n as u}from"./locale-store-Ba72bFmP.js";import{i as d}from"./vendor-swr-BIWyz7Rc.js";import{Ba as f,Dc as p,Do as m,Ga as h,Ha as g,Qa as _,Qc as v,Ra as y,Ro as b,Tl as x,Ua as S,Us as C,Va as w,Wa as T,Xc as E,_i as D,_o as O,_s as k,as as A,da as j,ga as M,gr as N,ha as P,hr as F,io as I,mr as L,no as R,ps as z,qn as ee,qo as te,ro as ne,rt as re,wl as ie,wo as B,za as ae}from"./index-BOme955B.js";import{n as oe,t as se}from"./settings-page-layout-Da_LNPDS.js";import{n as ce}from"./settings-loading-skeleton-A2OshMK8.js";import{t as le}from"./schema-form-D6wGEfEa.js";import{t as ue}from"./browser-BLJWD7WI.js";import{n as de,t as fe}from"./channels-status-swr-BG_j4Ci-.js";import{t as pe}from"./use-channel-catalog-BCBfSoHx.js";var V=n(),me=e(ue(),1),H=e(t(),1),U=r();function he(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}async function ge(e){let t=await l(c(`/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 _e({entry:e,locale:t,messages:n,onChanged:r,compact:a=!1}){let o=(0,H.useMemo)(()=>he(e),[e]),s=(0,H.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[c,l]=(0,H.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,H.useEffect)(()=>{l({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let u=(0,H.useCallback)(async(n,i)=>{l(e=>({...e,busy:!0,error:null}));try{let a=await ge({channelId:e.id,actionId:n,locale:t,input:i});l(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){l(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,H.useEffect)(()=>{let t=K(c.payload,e.id);if(!t){l(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return l(e=>e.generatedQr?{...e,generatedQr:null}:e),me.toDataURL(t,{width:220,margin:1}).then(e=>{n||l(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,c.payload]),(0,H.useEffect)(()=>{let n=c.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||ge({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(l(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||l(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,c.poll]);let d=o?.[1].label??(e.configured?n.reconnect:n.connect),f=e.actions?.[`doctor.run`]?.label??n.diagnose,m=G(c.payload),h=K(c.payload,e.id),g=h?c.generatedQr:q(c.payload),_=o?.[1].result===`qr`&&(c.busy||c.payload?.type===`qr`||c.payload?.type===`poll`),v=c.payload?.type===`form`?c.payload:null,y=c.payload?.type===`diagnostics`?c.payload.checks:null;return(0,U.jsxs)(`div`,{className:a?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:i(`flex flex-wrap items-start gap-3`,a?`justify-end`:`justify-between`),children:[a?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:[o?(0,U.jsxs)(B,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(o[0]),children:[c.busy?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(k,{className:`size-4`}),d]}):null,e.actions?.[`doctor.run`]?(0,U.jsxs)(B,{type:`button`,variant:`secondary`,disabled:c.busy,onClick:()=>void u(`doctor.run`),children:[(0,U.jsx)(te,{className:`size-4`}),f]}):null]})]}),m?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:m}):null,c.error?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:c.error}):null,_?(0,U.jsxs)(`div`,{className:i(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base px-3 py-3 shadow-surface`,a?`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:g?(0,U.jsx)(`img`,{src:g,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)(P,{className:`size-48 rounded-md`})})}),(0,U.jsxs)(`div`,{className:i(`min-w-0 max-w-sm text-sm text-fg-muted`,a&&`w-full sm:w-auto`),children:[g?(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)(P,{className:`h-4 w-48 max-w-full`}),(0,U.jsx)(P,{className:`h-4 w-36 max-w-full`})]}),h?(0,U.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:h,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,U.jsx)(p,{className:`size-3.5`})]}):null]})]}):null,c.payload?.type===`poll`&&c.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)(E,{className:c.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,U.jsx)(`span`,{className:c.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:c.payload.message??(c.payload.ok?n.complete:n.failed)})]}):null,v?(0,U.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,U.jsx)(le,{schema:v.schema,values:c.formDraft,onChange:e=>l(t=>({...t,formDraft:e})),disabled:c.busy,labels:s}),(0,U.jsx)(B,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(v.submitAction,c.formDraft),children:n.saveSetup})]}):null,y?(0,U.jsx)(`div`,{className:`mt-4 space-y-2`,children:y.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 ve=40;function J(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function ye(e,t){return e.find(e=>e.id===J(t))?.agentId?.trim().toLowerCase()??``}function be(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:ve,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function xe(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 Se(e,t,n){let r=xe(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function Ce(e,t=!1){return e===`drawer`?i(`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`,ne):i(`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)]`,ne,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function we(e){let t=(0,V.c)(33),{presentation:n,open:r,onOpenChange:a,title:o,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:p,wide:h,headerExtra:_}=e,v=h===void 0?!1:h,b=n===`drawer`,[x,C]=(0,H.useState)(null),E;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,U.jsx)(w,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,I)}),t[0]=E):E=t[0];let D;t[1]!==n||t[2]!==v?(D=Ce(n,v),t[1]=n,t[2]=v,t[3]=D):D=t[3];let k;t[4]===c?k=t[5]:(k=c?(0,U.jsx)(T,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=k);let A;t[6]===l?A=t[7]:(A=l?(0,U.jsx)(f,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=A);let j;t[8]!==u||t[9]!==s||t[10]!==_||t[11]!==b||t[12]!==o?(j=b?(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:[o?(0,U.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:o}):null,s?(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,U.jsx)(y,{asChild:!0,children:(0,U.jsx)(B,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,U.jsx)(m,{className:`size-5`,strokeWidth:1.75})})})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(y,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,className:i(O,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,U.jsx)(m,{className:`size-4`})})}),_]}),t[8]=u,t[9]=s,t[10]=_,t[11]=b,t[12]=o,t[13]=j):j=t[13];let M=b?`px-4 py-4`:`p-6`,N;t[14]===M?N=t[15]:(N=i(`min-h-0 flex-1 overflow-y-auto`,M),t[14]=M,t[15]=N);let P;t[16]!==d||t[17]!==N?(P=(0,U.jsx)(`div`,{className:N,children:d}),t[16]=d,t[17]=N,t[18]=P):P=t[18];let F;t[19]!==p||t[20]!==x||t[21]!==k||t[22]!==A||t[23]!==j||t[24]!==P?(F=(0,U.jsxs)(R,{layer:`modal`,portalContainer:x,children:[k,A,j,P,p]}),t[19]=p,t[20]=x,t[21]=k,t[22]=A,t[23]=j,t[24]=P,t[25]=F):F=t[25];let L;t[26]!==F||t[27]!==D?(L=(0,U.jsxs)(g,{children:[E,(0,U.jsx)(ae,{ref:C,className:D,onOpenAutoFocus:Te,children:F})]}),t[26]=F,t[27]=D,t[28]=L):L=t[28];let z;return t[29]!==a||t[30]!==r||t[31]!==L?(z=(0,U.jsx)(S,{open:r,onOpenChange:a,children:L}),t[29]=a,t[30]=r,t[31]=L,t[32]=z):z=t[32],z}function Te(e){return e.preventDefault()}var Ee=(0,H.memo)(function(e){let t=(0,V.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)(D,{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 De(e){let t=(0,V.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 d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,U.jsx)(B,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,p;t[7]!==n.discard||t[8]!==o||t[9]!==f?(p=(0,U.jsx)(B,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=p):p=t[10];let m=!r||i,h;t[11]===s?h=t[12]:(h=()=>void s(),t[11]=s,t[12]=h);let g=i?n.saving:n.save,_;t[13]!==m||t[14]!==h||t[15]!==g?(_=(0,U.jsx)(B,{type:`button`,variant:`primary`,disabled:m,onClick:h,children:g}),t[13]=m,t[14]=h,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==p||t[19]!==_?(v=(0,U.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,p,_]}),t[17]=d,t[18]=p,t[19]=_,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==u?(y=(0,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,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}var Oe=`channels-status`;function ke(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function Ae(e){let t=t=>e(t.detail);return window.addEventListener(Oe,t),()=>window.removeEventListener(Oe,t)}function je(e,t){let n=(0,V.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return Ae(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,H.useEffect)(i,a)}function Me(e){return e?c(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Ne(e){return(await s(c(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Pe=[`enabled`];async function Fe(){let e=await s(c(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Ie(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Le(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 Re(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function ze(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Be(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 Ve(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=>!Pe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Pe.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 He(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 Ue(e){let t=e.properties;if(!X(t))return!1;for(let[e,n]of Object.entries(t))X(n)&&n.type===`object`&&Ue(n)&&delete t[e];return Object.keys(t).length===0}function We(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 Ue(n),n}function Ge(e){return e.type===`object`&&X(e.properties)&&Object.keys(e.properties).length>0}function Ke(e,t){let n=e;for(let e of t.split(`.`)){if(!X(n))return;n=n[e]}return n}function qe(e){let t=e.accounts;return X(t)?Object.values(t).filter(e=>X(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Je(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 Ye(e,t,n){let r=[],i=Y(e);if(i.issues.length>0&&r.push(Qe(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Je(e,Ke(t,e),n);i&&r.push(i)}let a=qe(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Q(e,t){let n=Y(e),r=he(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 Xe(e,t){let n=he(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function Ze(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 Qe(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 $e({entry:e}){let t=o(e=>e.token),[n,r]=(0,H.useState)(!1),i=(0,H.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(c(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Ie(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)(M,{sourceChannel:e.id,className:`size-7`})})}function et(e){let t=(0,V.c)(16),{checked:n,disabled:r,onToggle:a,label:o}=e,s;t[0]===a?s=t[1]:(s=e=>{e.stopPropagation(),a()},t[0]=a,t[1]=s);let c=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,l=r&&`cursor-not-allowed opacity-60`,u;t[2]!==c||t[3]!==l?(u=i(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,c,l),t[2]=c,t[3]=l,t[4]=u):u=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=i(`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]!==o||t[12]!==s||t[13]!==u||t[14]!==p?(m=(0,U.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":o,disabled:r,onClick:s,className:u,children:p}),t[9]=n,t[10]=r,t[11]=o,t[12]=s,t[13]=u,t[14]=p,t[15]=m):m=t[15],m}function tt(e){let t=(0,V.c)(71),{entry:n,config:r,runtime:a,busy:o,restarting:s,ch:c,onOpen:l,onToggle:u,onRestart:d}=e,f;t[0]===n?f=t[1]:(f=Y(n),t[0]=n,t[1]=f);let p=f,m,h,g,_,v,y,b;if(t[2]!==o||t[3]!==c||t[4]!==r||t[5]!==n||t[6]!==l||t[7]!==d||t[8]!==u||t[9]!==a||t[10]!==p.enabled||t[11]!==p.ready){let e=Ye(n,r,c),s=Ze(n,c);m=!p.enabled&&p.ready?u:a===`stopped`?d:l,y=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let f;t[19]===n?f=t[20]:(f=(0,U.jsx)($e,{entry:n}),t[19]=n,t[20]=f);let x;t[21]===n.label?x=t[22]:(x=(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=x);let S;t[23]===a?S=t[24]:(S=i(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Be(a)),t[23]=a,t[24]=S);let C;t[25]!==c||t[26]!==a?(C=Re(a,c),t[25]=c,t[26]=a,t[27]=C):C=t[27];let w;t[28]!==S||t[29]!==C?(w=(0,U.jsx)(`span`,{className:S,children:C}),t[28]=S,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==x?(T=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[x,w]}),t[31]=w,t[32]=x,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==f?(E=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[f,T]}),t[34]=T,t[35]=f,t[36]=E):E=t[36];let D=p.enabled,O;t[37]!==c.toggleChannel||t[38]!==n.label?(O=c.toggleChannel.replace(`{{channel}}`,n.label),t[37]=c.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==o||t[41]!==u||t[42]!==p.enabled||t[43]!==O?(k=(0,U.jsx)(et,{checked:D,disabled:o,label:O,onToggle:u}),t[40]=o,t[41]=u,t[42]=p.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(b=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=b):b=t[47],h=`button`,g=l,_=`mt-5 min-h-[6.25rem] text-left`,v=p.ready?(0,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(rt)}):null]}):(0,U.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-3`,children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:c.cardSetupTitle}),(0,U.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Xe(n,c)}),s.length>0?(0,U.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:s.map(nt)}):null]}),t[2]=o,t[3]=c,t[4]=r,t[5]=n,t[6]=l,t[7]=d,t[8]=u,t[9]=a,t[10]=p.enabled,t[11]=p.ready,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b}else m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18];let x;t[48]!==h||t[49]!==g||t[50]!==_||t[51]!==v?(x=(0,U.jsx)(`button`,{type:h,onClick:g,className:_,children:v}),t[48]=h,t[49]=g,t[50]=_,t[51]=v,t[52]=x):x=t[52];let S=o||s,w;t[53]!==o||t[54]!==s?(w=o||s?(0,U.jsx)(C,{className:`size-4 animate-spin`}):null,t[53]=o,t[54]=s,t[55]=w):w=t[55];let T;t[56]!==c||t[57]!==n||t[58]!==s||t[59]!==a?(T=s?c.restartingChannel:a===`stopped`?c.restartChannel:Q(n,c),t[56]=c,t[57]=n,t[58]=s,t[59]=a,t[60]=T):T=t[60];let E;t[61]!==m||t[62]!==w||t[63]!==T||t[64]!==S?(E=(0,U.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,U.jsxs)(B,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:m,disabled:S,children:[w,T]})}),t[61]=m,t[62]=w,t[63]=T,t[64]=S,t[65]=E):E=t[65];let D;return t[66]!==E||t[67]!==y||t[68]!==b||t[69]!==x?(D=(0,U.jsxs)(`article`,{className:y,children:[b,x,E]}),t[66]=E,t[67]=y,t[68]=b,t[69]=x,t[70]=D):D=t[70],D}function nt(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 rt(e){return(0,U.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function it(e){let t=(0,V.c)(51),{runtime:n,restarting:r,checking:a,showConnectionOptions:o,canManageConnection:s,ch:c,onRestart:l,onCheck:u,onManageConnection:d}=e,f=n===`running`?E:n===`stopped`||n===`needs_setup`?v:C,p=n===`running`&&`text-emerald-600 dark:text-emerald-400`,m=n===`stopped`&&`text-red-600 dark:text-red-400`,h=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,g=n===`disabled`&&`text-fg-muted`,_=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,y;t[0]!==p||t[1]!==m||t[2]!==h||t[3]!==g||t[4]!==_?(y=i(`mt-0.5 size-5 shrink-0`,p,m,h,g,_),t[0]=p,t[1]=m,t[2]=h,t[3]=g,t[4]=_,t[5]=y):y=t[5];let b;t[6]!==f||t[7]!==y?(b=(0,U.jsx)(f,{className:y}),t[6]=f,t[7]=y,t[8]=b):b=t[8];let x;t[9]===c.connectionStatus?x=t[10]:(x=(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:c.connectionStatus}),t[9]=c.connectionStatus,t[10]=x);let S;t[11]!==c||t[12]!==n?(S=ze(n,c),t[11]=c,t[12]=n,t[13]=S):S=t[13];let w;t[14]===S?w=t[15]:(w=(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:S}),t[14]=S,t[15]=w);let T;t[16]!==w||t[17]!==x?(T=(0,U.jsxs)(`div`,{children:[x,w]}),t[16]=w,t[17]=x,t[18]=T):T=t[18];let D;t[19]!==T||t[20]!==b?(D=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[b,T]}),t[19]=T,t[20]=b,t[21]=D):D=t[21];let O=a||r,k;t[22]===a?k=t[23]:(k=a?(0,U.jsx)(C,{className:`size-4 animate-spin`}):null,t[22]=a,t[23]=k);let A=a?c.checkingConnection:c.checkConnection,j;t[24]!==u||t[25]!==O||t[26]!==k||t[27]!==A?(j=(0,U.jsxs)(B,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:O,onClick:u,children:[k,A]}),t[24]=u,t[25]=O,t[26]=k,t[27]=A,t[28]=j):j=t[28];let M;t[29]!==c.restartChannel||t[30]!==c.restartingChannel||t[31]!==a||t[32]!==l||t[33]!==r||t[34]!==n?(M=n===`stopped`?(0,U.jsxs)(B,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||a,onClick:l,children:[r?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(z,{className:`size-4`}),r?c.restartingChannel:c.restartChannel]}):null,t[29]=c.restartChannel,t[30]=c.restartingChannel,t[31]=a,t[32]=l,t[33]=r,t[34]=n,t[35]=M):M=t[35];let N;t[36]!==s||t[37]!==c.connectionOptions||t[38]!==c.hideConnectionOptions||t[39]!==a||t[40]!==d||t[41]!==r||t[42]!==o?(N=s?(0,U.jsx)(B,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:a||r,onClick:d,children:o?c.hideConnectionOptions:c.connectionOptions}):null,t[36]=s,t[37]=c.connectionOptions,t[38]=c.hideConnectionOptions,t[39]=a,t[40]=d,t[41]=r,t[42]=o,t[43]=N):N=t[43];let P;t[44]!==j||t[45]!==M||t[46]!==N?(P=(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[j,M,N]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P):P=t[47];let F;return t[48]!==D||t[49]!==P?(F=(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:[D,P]})}),t[48]=D,t[49]=P,t[50]=F):F=t[50],F}function at(e){let t=(0,V.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)(b,{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:Qe(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 ot(){let e=u(e=>e.language),t=a(e),n=o(e=>!!e.token),r=ie(),{channelId:s}=x(),f=N(s),m=pe(n,e),g=m.entries,{data:v,mutate:y,isValidating:b}=d(n?fe():null,de,{revalidateOnFocus:!0}),{data:S,mutate:C}=d(n?`channels-config-map`:null,Fe,{revalidateOnFocus:!1}),w=S?.channels??{},T=S?.bindings??[],{data:E}=d(n?`channel-routing-agents`:null,j,{revalidateOnFocus:!1}),D=h(e=>e.setPageHeader),O=h(e=>e.clearPageHeader),k=(0,H.useMemo)(()=>g.find(e=>e.id===f),[f,g]),M=k?Le(k):null,{data:P,mutate:I}=d(n&&M?Me(M):null,()=>Ne(M)),[R,z]=(0,H.useState)(null),[te,ne]=(0,H.useState)(!1),[B,ae]=(0,H.useState)(null),[ue,V]=(0,H.useState)(null),[me,ge]=(0,H.useState)(!1),[W,G]=(0,H.useState)(null),[K,q]=(0,H.useState)(null),ve=R??P??{},J=t.channelsSettings,xe=(0,H.useMemo)(()=>k?.configSchema??{type:`object`,properties:{}},[k?.configSchema]),Ce=(0,H.useMemo)(()=>We(xe,Pe),[xe]),Te=(0,H.useMemo)(()=>Ve(k),[k]),Oe=(0,H.useMemo)(()=>He(Ce,Te),[Te,Ce]),Ae=(0,H.useMemo)(()=>We(Ce,Te),[Te,Ce]),Ie=(0,H.useMemo)(()=>Ge(Oe),[Oe]),ze=k?K??ye(T,k.id):``,X=(0,H.useMemo)(()=>(E?.items??[]).map(e=>{let n=ee(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[E?.items,t.agentsSettings]),Z=E?.items.find(e=>e.id===E.defaultId),Ue=Z?ee(Z,t.agentsSettings):E?.defaultId??``,Ke=(0,H.useMemo)(()=>({defaultBooleanLabel:J.schemaBooleanDefault,unsupportedArrayType:J.schemaUnsupportedArrayType,arrayAddPlaceholder:J.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>J.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[J]),qe=(0,H.useMemo)(()=>new Map((v??[]).map(e=>[e.name,e])),[v]),Je=v!==void 0,Ye=(0,H.useCallback)(e=>Se(e,qe.get(e.id),Je),[qe,Je]),Q=(0,H.useCallback)(async()=>{await Promise.all([m.mutate(),y()])},[m,y]);je((0,H.useCallback)(e=>{let t=ke(e);t&&y(t,!1)},[y]),n);let Xe=(0,H.useMemo)(()=>n?(0,U.jsx)(Ee,{ch:J,refreshing:m.isValidating||b,saveOk:!1,onRefresh:()=>void Q()}):null,[m.isValidating,J,n,b,Q]);(0,H.useLayoutEffect)(()=>(D({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}),()=>O()),[O,Xe,t.settingsSections.channels,D]);let Ze=(0,H.useCallback)(e=>{r(F(e)),z(null),q(null),G(null)},[r]),Qe=(0,H.useCallback)(()=>{r(L),z(null),q(null),G(null)},[r]),nt=(0,H.useCallback)(async e=>{V(e.id),G(null);try{let t=await l(c(`/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{V(null)}},[Q]);(0,H.useEffect)(()=>{q(null),ge(!1)},[k?.id]);let rt=(0,H.useCallback)(async()=>{if(!k||!R&&K===null)return!1;let e=Le(k);ne(!0),G(null);try{let t=await l(c(`/api/config`),{method:`PATCH`,body:JSON.stringify({...R?{channels:{[e]:R}}:{},...K===null?{}:{bindings:be(T,k.id,K)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return R&&await I(R,!1),await C(),await m.mutate(),z(null),q(null),!0}catch(e){return G(e instanceof Error?e.message:String(e)),!1}finally{ne(!1)}},[k,K,T,m,R,C,I]),ot=(0,H.useCallback)(async e=>{let t=Y(e),n=Le(e),r=k?.id===e.id?R: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 l(c(`/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 m.mutate(),await C(),await y(),k?.id===e.id&&(await I(),z(null))}catch(e){G(e instanceof Error?e.message:String(e))}finally{ae(null)}},[k?.id,m,R,C,I,y,Ze]),$=k?.ui?.modal,st=$?.placement!==`replace-config`,ct=k?Ye(k):`checking`,lt=k?!Y(k).ready||me:!1;return n?(0,U.jsxs)(se,{gap:`gap-4`,children:[m.isLoading?(0,U.jsx)(ce,{sections:2}):m.error?(0,U.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(m.error)}):(0,U.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:g.map(e=>(0,U.jsx)(tt,{entry:e,config:w[Le(e)]?.config,runtime:Ye(e),busy:B===e.id,restarting:ue===e.id,ch:J,onOpen:()=>Ze(e.id),onToggle:()=>void ot(e),onRestart:()=>void nt(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)(we,{presentation:`modal`,open:!!k,onOpenChange:e=>{e||Qe()},closeAriaLabel:J.close,srTitle:k?.label??J.selectChannel,srDescription:k?.description,wide:!0,footer:k?(0,U.jsx)(De,{ch:J,dirty:!!R||K!==null,saving:te,onCancel:Qe,onDiscard:()=>{z(null),q(null)},onSave:rt}):null,children:k?(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 px-3 py-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)($e,{entry:k}),(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:k.label}),(0,U.jsx)(`span`,{className:i(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Be(ct)),children:Re(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(k).ready&&he(k)?.[1].result===`qr`?J.scanLoginHint.replace(`{{channel}}`,k.label):k.description}),k.docsPath?(0,U.jsxs)(`a`,{href:k.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[J.docs,(0,U.jsx)(p,{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(k).enabled?J.enabledLabel:J.disabledLabel}),(0,U.jsx)(et,{checked:Y(k).enabled,disabled:B===k.id,label:J.toggleChannel.replace(`{{channel}}`,k.label),onToggle:()=>void ot(k)})]})]})}),(0,U.jsx)(it,{runtime:ct,restarting:ue===k.id,checking:b,showConnectionOptions:me,canManageConnection:Y(k).ready&&$?.placement!==`replace-config`,ch:J,onRestart:()=>void nt(k),onCheck:()=>void Q(),onManageConnection:()=>ge(e=>!e)}),(0,U.jsx)(at,{entry:k,ch:J}),lt&&$?.placement!==`replace-config`?(0,U.jsx)(_e,{entry:k,locale:e,messages:J,compact:!0,onChanged:async()=>{await I(),await Q(),await C()}},k.id):null,$?.entrypoint&&$.placement===`before-config`?(0,U.jsx)(re,{extensionId:k.extensionId,extensionName:k.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:k.id,entry:k,config:ve}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,U.jsx)(re,{extensionId:k.extensionId,extensionName:k.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:k.id,entry:k,config:ve}}):null,st&&Ie?(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:Oe,values:ve,onChange:e=>z(e),disabled:te,labels:Ke})]}):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)(_,{value:ze,options:X,placeholder:J.agentRoutingSelect,emptyLabel:J.agentRoutingDefault.replace(`{{agent}}`,Ue||J.agentRoutingSelect),ariaLabel:J.agentRouting,disabled:te||!E,onChange:e=>q(e)})]})]}),st&&Ge(Ae)?(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:Ae,values:ve,onChange:e=>z(e),disabled:te,labels:Ke})})]}):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{ot as ChannelsSettingsPanel};
|