@xopcai/xopc 0.0.119 → 0.0.120
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-CU8J6zou.js → agent-avatar-dicebear-APTlX9Sq.js} +1 -1
- package/dist/gateway/static/root/assets/agents-CFW_FS_V.js +2 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-B9vfYoEr.js → app-management-settings-panel-DTKc5HHT.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-ClOzIO24.js → appearance-settings-BTciFrE9.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-DU0dz9Zo.js → apps-page-DT52OrbM.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BkVIgZzA.js → archive-plugin-CiHaUMII.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-CaCMWh1D.js → attachment-load-t4gSrNjL.js} +1 -1
- package/dist/gateway/static/root/assets/{automation-suggestion-card-DhGDpKP3.js → automation-suggestion-card-CtysjSoQ.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-CTedroVo.js → automations-page-B2YvT3ES.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-B4TO_bsn.js → binary-plugins-BAbSldW5.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-DJRWwWNI.js → block-editor-BNr_82xl.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-FCDwOOBK.js → browser-settings-page-BQEXPhDU.js} +3 -3
- package/dist/gateway/static/root/assets/{capability-presets-api-Befi89CL.js → capability-presets-api-tzD702Gg.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-settings-panel-_G8eb2vJ.js → capability-presets-settings-panel-AGhTueAc.js} +1 -1
- package/dist/gateway/static/root/assets/{channel-recipient-api-BNSuJb5f.js → channel-recipient-api-DL_KzwGE.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-C3d5JBJX.js → channels-settings-DRTutLlN.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-yaUNvt5u.js → connectors-page-DneJVuge.js} +2 -2
- package/dist/gateway/static/root/assets/dreaming-settings-BEwWA1yf.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DYh402XV.js → extension-debug-page-Dl2kO0Sf.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-Cr_TizrN.js → extension-page-DmbLPsx_.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BU1KoKRj.js → extension-settings-page-BS2rx40e.js} +1 -1
- package/dist/gateway/static/root/assets/{fetch-Y7AEX4H3.js → fetch-B3ME5Eri.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-RbMmAOpX.js → gateway-config-api-DI9_BBTo.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-C79wkXef.js → gateway-settings-DAFI_T0W.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DiD_Tx4N.js → gateway-startup-retry-CSZQTz6K.js} +1 -1
- package/dist/gateway/static/root/assets/goal-detail-page-DLuz4jC9.js +1 -0
- package/dist/gateway/static/root/assets/{goals-config-api-DqxVi0p5.js → goals-config-api-Bhzqrp2w.js} +1 -1
- package/dist/gateway/static/root/assets/{goals-page-CS0R-Af2.js → goals-page-DTAfv9Ft.js} +2 -2
- package/dist/gateway/static/root/assets/{goals-settings-CSuzZ8Ae.js → goals-settings-CWN2iirQ.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-DXPaYJm3.js → heartbeat-settings-CkkkHvOi.js} +1 -1
- package/dist/gateway/static/root/assets/index-CnjzMw5i.js +191 -0
- package/dist/gateway/static/root/assets/index-E1QinYKp.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-Dvg53qnd.js → keyboard-shortcuts-settings-kMp08SlX.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-DjbfSsfA.js → locale-store-Ba72bFmP.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-DLXPcksQ.js → logs-page-CDXDlS_W.js} +2 -2
- package/dist/gateway/static/root/assets/{markdown-split-CpHxbtWJ.js → markdown-split-Bc0w40vz.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-SFPQRSxq.js → media-plugins-DJ_HvgIy.js} +1 -1
- package/dist/gateway/static/root/assets/messages-CISb1HLv.js +3 -0
- package/dist/gateway/static/root/assets/models-hub-panel-BTwxMIgZ.js +2 -0
- package/dist/gateway/static/root/assets/note-detail-page-BBfOeB0m.js +2 -0
- package/dist/gateway/static/root/assets/{note-image-lightbox-BUYURRgn.js → note-image-lightbox-4zntqpZq.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-BsIBSFyZ.js → notes-page-VocWOjoK.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-BHz9iWYA.js → preview-open-alternatives-BbA7sRd_.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CXwjuD_Q.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-CefkOlRg.js → save-bar-controls-Dividh61.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-CmTRoOcE.js → schedule-field-pRheF2CO.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-FMKv1vGu.js → schema-form-D6PiPxfr.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-CpcVySQK.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-BVy_TawT.js +1 -0
- package/dist/gateway/static/root/assets/{settings-collapsible-section-BouO6JTi.js → settings-collapsible-section-BMCOfuE_.js} +1 -1
- package/dist/gateway/static/root/assets/settings-form-section-DBkGwpIN.js +1 -0
- package/dist/gateway/static/root/assets/settings-page-CZpNyCWn.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-layout-BJ4Gsef5.js → settings-page-layout-NxoW5Y57.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-MVHLLu_a.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BDy2btRN.js → share-preview-page-B0suFCfj.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-B18OBmH5.js → shares-settings-C6DBbQGo.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-6hJmhwSn.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-Bm2ebkwl.js → skills-page-Im1MA0Iw.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-CRngrlnZ.js → system-settings-panel-CrmEnyX4.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-CD2wtgZV.js → theme-store-Bt6vAkSB.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-BltBc0b-.js → typed-models-lib-BAsGn25g.js} +1 -1
- package/dist/gateway/static/root/assets/{use-channel-catalog-CjN-51e6.js → use-channel-catalog-C7vcAoGb.js} +1 -1
- package/dist/gateway/static/root/assets/{user-profile-settings-panel-DJ1dKwZy.js → user-profile-settings-panel-QAQWGelF.js} +1 -1
- package/dist/gateway/static/root/assets/{utils-B5M5-YvK.js → utils-Dl9efgnV.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-CeEevm7z.js → voice-api-key-field-D-6XueTv.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-player-store-B7ykUlHM.js → voice-player-store-CMC5NOJp.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-C4PzUQjB.js → workflow-run-setup-panel-DVPllR4k.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-BL84_-Ky.js → workflows-page-B94WISTW.js} +2 -2
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/context/workspace-templates/AGENTS.md +3 -2
- package/dist/src/agent/memory/builtin-memory-store.d.ts +1 -1
- package/dist/src/agent/memory/builtin-memory-store.js +1 -1
- package/dist/src/agent/memory/builtin-memory-store.js.map +1 -1
- package/dist/src/agent/memory/builtin-provider.d.ts +2 -2
- package/dist/src/agent/memory/builtin-provider.js +2 -2
- package/dist/src/agent/memory/builtin-provider.js.map +1 -1
- package/dist/src/agent/memory/dreaming/light-sweep.d.ts +0 -7
- package/dist/src/agent/memory/dreaming/light-sweep.js +16 -277
- package/dist/src/agent/memory/dreaming/light-sweep.js.map +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.d.ts +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.js.map +1 -1
- package/dist/src/agent/memory/dreaming/short-term-store.d.ts +3 -3
- package/dist/src/agent/memory/dreaming/short-term-store.js +5 -5
- package/dist/src/agent/memory/dreaming/short-term-store.js.map +1 -1
- package/dist/src/agent/memory/dreaming/utils.d.ts +2 -2
- package/dist/src/agent/memory/dreaming/utils.js +2 -2
- package/dist/src/agent/memory/dreaming/utils.js.map +1 -1
- package/dist/src/agent/memory/index.d.ts +0 -2
- package/dist/src/agent/memory/index.js +1 -2
- package/dist/src/agent/prompt/sections/memory-skills.js +11 -10
- package/dist/src/agent/prompt/sections/memory-skills.js.map +1 -1
- package/dist/src/agent/prompt/sections/tooling.js +2 -2
- package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
- package/dist/src/agent/reply/startup-context.js +6 -105
- package/dist/src/agent/reply/startup-context.js.map +1 -1
- package/dist/src/agent/service.d.ts +0 -3
- package/dist/src/agent/service.js +0 -41
- package/dist/src/agent/service.js.map +1 -1
- package/dist/src/agent/tools/memory-tool.js +2 -2
- package/dist/src/agent/tools/memory-tool.js.map +1 -1
- package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
- package/dist/src/cli/commands/init.js +1 -1
- package/dist/src/cli/commands/init.js.map +1 -1
- package/dist/src/cli/templates.js +3 -2
- package/dist/src/cli/templates.js.map +1 -1
- package/dist/src/config/schema.d.ts +2 -2
- package/dist/src/config/schema.js +2 -2
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +4 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js.map +1 -1
- package/dist/src/infra/update-restart.js +1 -1
- package/dist/src/storage/sqlite/row-mappers.js +3 -1
- package/dist/src/storage/sqlite/row-mappers.js.map +1 -1
- package/dist/src/tui/backends/embedded-backend.js +1 -2
- package/dist/src/tui/backends/embedded-backend.js.map +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agents-B0hkpLhP.js +0 -2
- package/dist/gateway/static/root/assets/dreaming-settings-DNrdg1Ve.js +0 -1
- package/dist/gateway/static/root/assets/goal-detail-page-9paXuHdo.js +0 -1
- package/dist/gateway/static/root/assets/index-BoKafJIZ.js +0 -191
- package/dist/gateway/static/root/assets/index-CArhCcYn.css +0 -1
- package/dist/gateway/static/root/assets/messages-CrDHEbss.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-panel-BDF2iyRk.js +0 -2
- package/dist/gateway/static/root/assets/note-detail-page-CSb_hwig.js +0 -2
- package/dist/gateway/static/root/assets/remote-access-hub-CwzSovcS.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-PHmX-NmA.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BRAeKJN4.js +0 -1
- package/dist/gateway/static/root/assets/settings-form-section-D-4lBl6X.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-KKrbFjy8.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-CrUjHPQo.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-C28-2uKQ.js +0 -1
- package/dist/src/agent/memory/memory-flush.d.ts +0 -27
- package/dist/src/agent/memory/memory-flush.js +0 -124
- package/dist/src/agent/memory/memory-flush.js.map +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-CrDHEbss.js";import{t as o}from"./locale-store-DjbfSsfA.js";import{c as s,i as c,n as l,t as u}from"./fetch-Y7AEX4H3.js";import{i as d}from"./vendor-swr-BIWyz7Rc.js";import{Ai as f,Ba as p,Dr as m,Fn as h,Mi as g,Ni as _,Nn as v,Oa as y,Oi as b,Pi as x,Pn as S,Qa as C,Qn as w,So as T,V as E,Xs as D,Ys as O,Zn as k,ea as A,ji as j,ki as M,la as N,sa as P,si as F,ts as I,ws as L,ya as R,zi as ee}from"./index-BoKafJIZ.js";import{t as te}from"./schema-form-FMKv1vGu.js";import{t as z}from"./browser-BLJWD7WI.js";import{n as ne,t as re}from"./settings-page-layout-BJ4Gsef5.js";import{t as ie}from"./use-channel-catalog-CjN-51e6.js";var B=n(),ae=e(z(),1),V=e(t(),1),H=r();function U(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 W(e){let t=await u(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 G(e){return e?.type===`poll`&&e.phase===`done`}function K(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function q(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function oe(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function se({entry:e,locale:t,messages:n,onChanged:r,autoStartPrimary:a=!1,compact:o=!1}){let s=(0,V.useMemo)(()=>U(e),[e]),c=(0,V.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[l,u]=(0,V.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,V.useEffect)(()=>{u({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let d=(0,V.useCallback)(async(n,i)=>{u(e=>({...e,busy:!0,error:null}));try{let a=await W({channelId:e.id,actionId:n,locale:t,input:i});u(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){u(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,V.useEffect)(()=>{!a||!s||s[1].result!==`qr`||l.payload||l.busy||l.error||d(s[0])},[a,s,d,l.busy,l.error,l.payload]),(0,V.useEffect)(()=>{let t=q(l.payload,e.id);if(!t){u(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return u(e=>e.generatedQr?{...e,generatedQr:null}:e),ae.toDataURL(t,{width:220,margin:1}).then(e=>{n||u(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,l.payload]),(0,V.useEffect)(()=>{let n=l.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||W({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(u(t=>({...t,payload:e,poll:G(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),G(e)&&window.clearInterval(a))}).catch(e=>{i||u(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,l.poll]);let f=s?.[1].label??(e.configured?n.reconnect:n.connect),p=e.actions?.[`doctor.run`]?.label??n.diagnose,m=K(l.payload),h=q(l.payload,e.id),g=h?l.generatedQr:oe(l.payload),_=s?.[1].result===`qr`&&(a||l.busy||l.payload?.type===`qr`||l.payload?.type===`poll`),v=l.busy||!!(h&&!g),b=l.payload?.type===`form`?l.payload:null,x=l.payload?.type===`diagnostics`?l.payload.checks:null;return(0,H.jsxs)(`div`,{className:o?`space-y-3`:`rounded-lg border border-edge-subtle bg-surface-panel p-4`,children:[(0,H.jsxs)(`div`,{className:i(`flex flex-wrap items-start gap-3`,o?`justify-end`:`justify-between`),children:[o?null:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[s?(0,H.jsxs)(P,{type:`button`,variant:`primary`,disabled:l.busy,onClick:()=>void d(s[0]),children:[l.busy?(0,H.jsx)(T,{className:`size-4 animate-spin`}):(0,H.jsx)(C,{className:`size-4`}),f]}):null,e.actions?.[`doctor.run`]?(0,H.jsxs)(P,{type:`button`,variant:`secondary`,disabled:l.busy,onClick:()=>void d(`doctor.run`),children:[(0,H.jsx)(y,{className:`size-4`}),p]}):null]})]}),m?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:m}):null,l.error?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:l.error}):null,_?(0,H.jsxs)(`div`,{className:i(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg border border-edge-subtle bg-surface-base px-3 py-3`,o?`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,H.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:g?(0,H.jsx)(`img`,{src:g,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,H.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base text-fg-muted`,children:(0,H.jsx)(T,{className:i(`size-6`,v&&`animate-spin`)})})}),(0,H.jsxs)(`div`,{className:i(`min-w-0 max-w-sm text-sm text-fg-muted`,o&&`w-full sm:w-auto`),children:[(0,H.jsx)(`p`,{className:`line-clamp-3`,children:g?n.waitingConfirmation:n.loading}),h?(0,H.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,H.jsx)(I,{className:`size-3.5`})]}):null]})]}):null,l.payload?.type===`poll`&&l.payload.phase===`done`?(0,H.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2 text-sm`,children:[(0,H.jsx)(L,{className:l.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,H.jsx)(`span`,{className:l.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:l.payload.message??(l.payload.ok?n.complete:n.failed)})]}):null,b?(0,H.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,H.jsx)(te,{schema:b.schema,values:l.formDraft,onChange:e=>u(t=>({...t,formDraft:e})),disabled:l.busy,labels:c}),(0,H.jsx)(P,{type:`button`,variant:`primary`,disabled:l.busy,onClick:()=>void d(b.submitAction,l.formDraft),children:n.saveSetup})]}):null,x?(0,H.jsx)(`div`,{className:`mt-4 space-y-2`,children:x.map((e,t)=>(0,H.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,H.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,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}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`,k):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)]`,k,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function le(e){let t=(0,B.c)(30),{presentation:n,open:r,onOpenChange:a,title:o,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:p,wide:m,headerExtra:h}=e,v=m===void 0?!1:m,y=n===`drawer`,S;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,H.jsx)(j,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,w)}),t[0]=S):S=t[0];let C;t[1]!==n||t[2]!==v?(C=ce(n,v),t[1]=n,t[2]=v,t[3]=C):C=t[3];let T;t[4]===c?T=t[5]:(T=c?(0,H.jsx)(x,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=T);let E;t[6]===l?E=t[7]:(E=l?(0,H.jsx)(f,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=E);let D;t[8]!==u||t[9]!==s||t[10]!==h||t[11]!==y||t[12]!==o?(D=y?(0,H.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[o?(0,H.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:o}):null,s?(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,H.jsx)(b,{asChild:!0,children:(0,H.jsx)(P,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,H.jsx)(N,{className:`size-5`,strokeWidth:1.75})})})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(b,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:i(A,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,H.jsx)(N,{className:`size-4`})})}),h]}),t[8]=u,t[9]=s,t[10]=h,t[11]=y,t[12]=o,t[13]=D):D=t[13];let O=y?`px-4 py-4`:`p-6`,k;t[14]===O?k=t[15]:(k=i(`min-h-0 flex-1 overflow-y-auto`,O),t[14]=O,t[15]=k);let F;t[16]!==d||t[17]!==k?(F=(0,H.jsx)(`div`,{className:k,children:d}),t[16]=d,t[17]=k,t[18]=F):F=t[18];let I;t[19]!==p||t[20]!==C||t[21]!==T||t[22]!==E||t[23]!==D||t[24]!==F?(I=(0,H.jsxs)(g,{children:[S,(0,H.jsxs)(M,{className:C,onOpenAutoFocus:ue,children:[T,E,D,F,p]})]}),t[19]=p,t[20]=C,t[21]=T,t[22]=E,t[23]=D,t[24]=F,t[25]=I):I=t[25];let L;return t[26]!==a||t[27]!==r||t[28]!==I?(L=(0,H.jsx)(_,{open:r,onOpenChange:a,children:I}),t[26]=a,t[27]=r,t[28]=I,t[29]=L):L=t[29],L}function ue(e){return e.preventDefault()}var de=(0,V.memo)(function(e){let t=(0,B.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,H.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,H.jsx)(m,{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,H.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 fe(e){let t=(0,B.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,H.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,H.jsx)(P,{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,H.jsx)(P,{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,H.jsx)(P,{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,H.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,H.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}function pe(e){return e?c(`/api/channels/${encodeURIComponent(e)}/config`):null}async function me(e){return(await l(c(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var he=[`enabled`];async function ge(){return(await l(c(`/api/config`))).payload?.config?.channels??{}}function J(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Y(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function X(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function _e(e,t){let n=X(e);return n.state===`needs_setup`?t.hubStatusNeedsSetup:n.state===`error`?t.hubStatusError:n.enabled&&n.ready&&e.runtime===`loaded`?t.hubStatusRunning:n.enabled&&n.ready?t.hubStatusEnabled:n.ready?t.hubStatusConfigured:t.hubStatusNotConfigured}function ve(e){let t=X(e);return t.state===`needs_setup`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:t.state===`error`?`bg-red-500/10 text-red-700 dark:text-red-300`:t.enabled&&t.ready&&e.runtime===`loaded`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:t.enabled||t.ready?`bg-accent-soft text-accent`:`bg-surface-hover text-fg-muted`}function ye(e){if(!e)return[];let t=e.uiHints??{},n=Z(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=X(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!Z(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!he.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!he.includes(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function be(e,t){let n={...Q(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!Z(r)||!Z(r[n]))break;let o=Z(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Q(r[n]),properties:{}}),e===t.length-1){o[n]=Q(r[n]);break}i=r[n],a=o[n]}}return n}function xe(e){let t=e.properties;if(!Z(t))return!1;for(let[e,n]of Object.entries(t))Z(n)&&n.type===`object`&&xe(n)&&delete t[e];return Object.keys(t).length===0}function Se(e,t){let n=Q(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!Z(i))break;if(e===t.length-1){delete i[n];break}if(!Z(i[n]))break;r=i[n]}}return xe(n),n}function Ce(e){return e.type===`object`&&Z(e.properties)&&Object.keys(e.properties).length>0}function $(e,t){let n=e;for(let e of t.split(`.`)){if(!Z(n))return;n=n[e]}return n}function we(e){let t=e.accounts;return Z(t)?Object.values(t).filter(e=>Z(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Te(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 Ee(e,t,n){let r=[],i=X(e);if(i.issues.length>0&&r.push(Ae(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Te(e,$(t,e),n);i&&r.push(i)}let a=we(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function De(e,t){let n=X(e),r=U(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 Oe(e,t){let n=U(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function ke(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 Ae(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 je({entry:e}){let t=s(e=>e.token),[n,r]=(0,V.useState)(!1),i=(0,V.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(c(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${J(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,H.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,H.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,H.jsx)(F,{sourceChannel:e.id,className:`size-7`})})}function Me(e){let t=(0,B.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,H.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,H.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 Ne(e){let t=(0,B.c)(70),{entry:n,config:r,busy:a,ch:o,onOpen:s,onToggle:c}=e,l;t[0]===n?l=t[1]:(l=X(n),t[0]=n,t[1]=l);let u=l,d,f,p,m,h,g,_;if(t[2]!==a||t[3]!==o||t[4]!==r||t[5]!==n||t[6]!==s||t[7]!==c||t[8]!==u.enabled||t[9]!==u.ready){let e=Ee(n,r,o),l=ke(n,o);d=!u.enabled&&u.ready,g=`flex min-h-[15.5rem] flex-col rounded-xl border border-edge-subtle bg-surface-panel p-4 shadow-surface transition-colors hover:border-edge`;let v;t[17]===n?v=t[18]:(v=(0,H.jsx)(je,{entry:n}),t[17]=n,t[18]=v);let y;t[19]===n.label?y=t[20]:(y=(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[19]=n.label,t[20]=y);let b;t[21]===n?b=t[22]:(b=i(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,ve(n)),t[21]=n,t[22]=b);let x;t[23]!==o||t[24]!==n?(x=_e(n,o),t[23]=o,t[24]=n,t[25]=x):x=t[25];let S;t[26]!==b||t[27]!==x?(S=(0,H.jsx)(`span`,{className:b,children:x}),t[26]=b,t[27]=x,t[28]=S):S=t[28];let C;t[29]!==S||t[30]!==y?(C=(0,H.jsxs)(`div`,{className:`min-w-0`,children:[y,S]}),t[29]=S,t[30]=y,t[31]=C):C=t[31];let w;t[32]!==C||t[33]!==v?(w=(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[v,C]}),t[32]=C,t[33]=v,t[34]=w):w=t[34];let T=u.enabled,E;t[35]!==o.toggleChannel||t[36]!==n.label?(E=o.toggleChannel.replace(`{{channel}}`,n.label),t[35]=o.toggleChannel,t[36]=n.label,t[37]=E):E=t[37];let D;t[38]!==a||t[39]!==c||t[40]!==u.enabled||t[41]!==E?(D=(0,H.jsx)(Me,{checked:T,disabled:a,label:E,onToggle:c}),t[38]=a,t[39]=c,t[40]=u.enabled,t[41]=E,t[42]=D):D=t[42],t[43]!==w||t[44]!==D?(_=(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[w,D]}),t[43]=w,t[44]=D,t[45]=_):_=t[45],f=`button`,p=s,m=`mt-5 min-h-[6.25rem] text-left`,h=u.ready?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,H.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map(Fe)}):null]}):(0,H.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.cardSetupTitle}),(0,H.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Oe(n,o)}),l.length>0?(0,H.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:l.map(Pe)}):null]}),t[2]=a,t[3]=o,t[4]=r,t[5]=n,t[6]=s,t[7]=c,t[8]=u.enabled,t[9]=u.ready,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_}else d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16];let v;t[46]!==o.cardAdapterLabel||t[47]!==n.description||t[48]!==u.ready?(v=!u.ready&&n.description?(0,H.jsxs)(`p`,{className:`mt-3 truncate text-xs text-fg-subtle`,title:n.description,children:[o.cardAdapterLabel,`: `,n.description]}):null,t[46]=o.cardAdapterLabel,t[47]=n.description,t[48]=u.ready,t[49]=v):v=t[49];let y;t[50]!==f||t[51]!==p||t[52]!==m||t[53]!==h||t[54]!==v?(y=(0,H.jsxs)(`button`,{type:f,onClick:p,className:m,children:[h,v]}),t[50]=f,t[51]=p,t[52]=m,t[53]=h,t[54]=v,t[55]=y):y=t[55];let b=d?c:s,x;t[56]===a?x=t[57]:(x=a?(0,H.jsx)(T,{className:`size-4 animate-spin`}):null,t[56]=a,t[57]=x);let S;t[58]!==o||t[59]!==n?(S=De(n,o),t[58]=o,t[59]=n,t[60]=S):S=t[60];let C;t[61]!==b||t[62]!==x||t[63]!==S?(C=(0,H.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,H.jsxs)(P,{type:`button`,variant:`primary`,className:`w-full rounded-2xl py-2.5`,onClick:b,children:[x,S]})}),t[61]=b,t[62]=x,t[63]=S,t[64]=C):C=t[64];let w;return t[65]!==C||t[66]!==g||t[67]!==_||t[68]!==y?(w=(0,H.jsxs)(`article`,{className:g,children:[_,y,C]}),t[65]=C,t[66]=g,t[67]=_,t[68]=y,t[69]=w):w=t[69],w}function Pe(e){return(0,H.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function Fe(e){return(0,H.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function Ie(e){let t=(0,B.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=X(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,H.jsx)(R,{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,H.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,H.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,H.jsx)(`li`,{children:Ae(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,H.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,H.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,H.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,H.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function Le(){let e=o(e=>e.language),t=a(e),n=s(e=>!!e.token),r=O(),{channelId:l}=D(),f=h(l),m=ie(n,e),g=m.entries,{data:_={},mutate:y}=d(n?`channels-config-map`:null,ge,{revalidateOnFocus:!1}),b=ee(e=>e.setPageHeader),x=ee(e=>e.clearPageHeader),C=(0,V.useMemo)(()=>g.find(e=>e.id===f),[f,g]),w=C?Y(C):null,{data:T,mutate:k}=d(n&&w?pe(w):null,()=>me(w)),[A,j]=(0,V.useState)(null),[M,N]=(0,V.useState)(!1),[P,F]=(0,V.useState)(null),[L,R]=(0,V.useState)(null),z=A??T??{},B=t.channelsSettings,ae=(0,V.useMemo)(()=>C?.configSchema??{type:`object`,properties:{}},[C?.configSchema]),W=(0,V.useMemo)(()=>Se(ae,he),[ae]),G=(0,V.useMemo)(()=>ye(C),[C]),K=(0,V.useMemo)(()=>be(W,G),[G,W]),q=(0,V.useMemo)(()=>Se(W,G),[G,W]),oe=(0,V.useMemo)(()=>Ce(K),[K]),ce=(0,V.useMemo)(()=>({defaultBooleanLabel:B.schemaBooleanDefault,unsupportedArrayType:B.schemaUnsupportedArrayType,arrayAddPlaceholder:B.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>B.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[B]),ue=(0,V.useMemo)(()=>n?(0,H.jsx)(de,{ch:B,refreshing:m.isValidating,saveOk:!1,onRefresh:()=>void m.mutate()}):null,[m,B,n]);(0,V.useLayoutEffect)(()=>(b({startExtra:null,main:(0,H.jsx)(`div`,{className:`min-w-0`,children:(0,H.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:ue}),()=>x()),[x,ue,t.settingsSections.channels,b]);let J=(0,V.useCallback)(e=>{r(S(e)),j(null),R(null)},[r]),Z=(0,V.useCallback)(()=>{r(v),j(null),R(null)},[r]),Q=(0,V.useCallback)(async()=>{if(!C||!A)return!1;let e=Y(C);N(!0),R(null);try{let t=await u(c(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[e]:A}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return await k(A,!1),await y(),await m.mutate(),j(null),!0}catch(e){return R(e instanceof Error?e.message:String(e)),!1}finally{N(!1)}},[C,m,A,y,k]),xe=(0,V.useCallback)(async e=>{let t=X(e),n=Y(e),r=C?.id===e.id?A:null;if(!t.enabled&&!t.ready&&!r){J(e.id);return}F(e.id),R(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await u(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 y(),C?.id===e.id&&(await k(),j(null))}catch(e){R(e instanceof Error?e.message:String(e))}finally{F(null)}},[C?.id,m,A,y,k,J]),$=C?.ui?.modal,we=$?.placement!==`replace-config`;return n?(0,H.jsxs)(re,{gap:`gap-4`,children:[m.isLoading?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:B.loadingChannels}):m.error?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(m.error)}):(0,H.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:g.map(e=>(0,H.jsx)(Ne,{entry:e,config:_[Y(e)]?.config,busy:P===e.id,ch:B,onOpen:()=>J(e.id),onToggle:()=>void xe(e)},e.id))}),L?(0,H.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:L}):null,(0,H.jsx)(le,{presentation:`modal`,open:!!C,onOpenChange:e=>{e||Z()},closeAriaLabel:B.close,srTitle:C?.label??B.selectChannel,srDescription:C?.description,wide:!0,footer:C?(0,H.jsx)(fe,{ch:B,dirty:!!A,saving:M,onCancel:Z,onDiscard:()=>j(null),onSave:Q}):null,children:C?(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-3`,children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,H.jsx)(je,{entry:C}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:C.label}),(0,H.jsx)(`span`,{className:i(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,ve(C)),children:_e(C,B)})]}),(0,H.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,H.jsx)(`span`,{className:`min-w-0 truncate`,children:U(C)?.[1].result===`qr`?B.scanLoginHint.replace(`{{channel}}`,C.label):C.description}),C.docsPath?(0,H.jsxs)(`a`,{href:C.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[B.docs,(0,H.jsx)(I,{className:`size-3.5`})]}):null]})]})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,H.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:B.enabledLabel}),(0,H.jsx)(Me,{checked:X(C).enabled,disabled:P===C.id,label:B.toggleChannel.replace(`{{channel}}`,C.label),onToggle:()=>void xe(C)})]})]})}),(0,H.jsx)(Ie,{entry:C,ch:B}),$?.entrypoint&&$.placement===`before-config`?(0,H.jsx)(E,{extensionId:C.extensionId,extensionName:C.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:C.id,entry:C,config:z}}):null,$?.placement===`replace-config`?null:(0,H.jsx)(se,{entry:C,locale:e,messages:B,autoStartPrimary:!0,compact:!0,onChanged:async()=>{await k(),await m.mutate(),await y()}},C.id),$?.entrypoint&&$.placement!==`before-config`?(0,H.jsx)(E,{extensionId:C.extensionId,extensionName:C.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:C.id,entry:C,config:z}}):null,we&&oe?(0,H.jsxs)(`section`,{className:`rounded-xl border border-edge-subtle bg-surface-panel p-4`,children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:B.basicConfiguration}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:B.basicConfigurationHint})]}),(0,H.jsx)(te,{schema:K,values:z,onChange:e=>j(e),disabled:M,labels:ce})]}):null,we&&Ce(q)?(0,H.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-panel`,children:[(0,H.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,H.jsx)(p,{className:`size-4 text-fg-muted`}),B.advancedConfiguration]}),(0,H.jsx)(`div`,{className:`border-t border-edge-subtle p-4`,children:(0,H.jsx)(te,{schema:q,values:z,onChange:e=>j(e),disabled:M,labels:ce})})]}):null,L?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:L}):null]}):null})]}):(0,H.jsxs)(re,{gap:`gap-3`,padding:`px-4 py-8`,children:[(0,H.jsx)(ne,{title:t.settingsSections.channels}),(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:B.tokenRequired})]})}export{Le 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-CISb1HLv.js";import{n as o}from"./locale-store-Ba72bFmP.js";import{c as s,i as c,n as l,t as u}from"./fetch-B3ME5Eri.js";import{i as d}from"./vendor-swr-BIWyz7Rc.js";import{Ai as f,Ba as p,Dr as m,Fn as h,Mi as g,Ni as _,Nn as v,Oa as y,Oi as b,Pi as x,Pn as S,Qa as C,Qn as w,So as T,V as E,Xs as D,Zn as O,Zs as k,ea as A,ji as j,ki as M,la as N,sa as P,si as F,ts as I,ws as L,ya as R,zi as ee}from"./index-CnjzMw5i.js";import{t as te}from"./schema-form-D6PiPxfr.js";import{t as z}from"./browser-BLJWD7WI.js";import{n as ne,t as re}from"./settings-page-layout-NxoW5Y57.js";import{t as ie}from"./use-channel-catalog-C7vcAoGb.js";var B=n(),ae=e(z(),1),V=e(t(),1),H=r();function U(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 W(e){let t=await u(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 G(e){return e?.type===`poll`&&e.phase===`done`}function K(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function q(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function oe(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function se({entry:e,locale:t,messages:n,onChanged:r,autoStartPrimary:a=!1,compact:o=!1}){let s=(0,V.useMemo)(()=>U(e),[e]),c=(0,V.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[l,u]=(0,V.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,V.useEffect)(()=>{u({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let d=(0,V.useCallback)(async(n,i)=>{u(e=>({...e,busy:!0,error:null}));try{let a=await W({channelId:e.id,actionId:n,locale:t,input:i});u(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){u(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,V.useEffect)(()=>{!a||!s||s[1].result!==`qr`||l.payload||l.busy||l.error||d(s[0])},[a,s,d,l.busy,l.error,l.payload]),(0,V.useEffect)(()=>{let t=q(l.payload,e.id);if(!t){u(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return u(e=>e.generatedQr?{...e,generatedQr:null}:e),ae.toDataURL(t,{width:220,margin:1}).then(e=>{n||u(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,l.payload]),(0,V.useEffect)(()=>{let n=l.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||W({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(u(t=>({...t,payload:e,poll:G(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),G(e)&&window.clearInterval(a))}).catch(e=>{i||u(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,l.poll]);let f=s?.[1].label??(e.configured?n.reconnect:n.connect),p=e.actions?.[`doctor.run`]?.label??n.diagnose,m=K(l.payload),h=q(l.payload,e.id),g=h?l.generatedQr:oe(l.payload),_=s?.[1].result===`qr`&&(a||l.busy||l.payload?.type===`qr`||l.payload?.type===`poll`),v=l.busy||!!(h&&!g),b=l.payload?.type===`form`?l.payload:null,x=l.payload?.type===`diagnostics`?l.payload.checks:null;return(0,H.jsxs)(`div`,{className:o?`space-y-3`:`rounded-lg border border-edge-subtle bg-surface-panel p-4`,children:[(0,H.jsxs)(`div`,{className:i(`flex flex-wrap items-start gap-3`,o?`justify-end`:`justify-between`),children:[o?null:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[s?(0,H.jsxs)(P,{type:`button`,variant:`primary`,disabled:l.busy,onClick:()=>void d(s[0]),children:[l.busy?(0,H.jsx)(T,{className:`size-4 animate-spin`}):(0,H.jsx)(C,{className:`size-4`}),f]}):null,e.actions?.[`doctor.run`]?(0,H.jsxs)(P,{type:`button`,variant:`secondary`,disabled:l.busy,onClick:()=>void d(`doctor.run`),children:[(0,H.jsx)(y,{className:`size-4`}),p]}):null]})]}),m?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:m}):null,l.error?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:l.error}):null,_?(0,H.jsxs)(`div`,{className:i(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg border border-edge-subtle bg-surface-base px-3 py-3`,o?`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,H.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:g?(0,H.jsx)(`img`,{src:g,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,H.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base text-fg-muted`,children:(0,H.jsx)(T,{className:i(`size-6`,v&&`animate-spin`)})})}),(0,H.jsxs)(`div`,{className:i(`min-w-0 max-w-sm text-sm text-fg-muted`,o&&`w-full sm:w-auto`),children:[(0,H.jsx)(`p`,{className:`line-clamp-3`,children:g?n.waitingConfirmation:n.loading}),h?(0,H.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,H.jsx)(I,{className:`size-3.5`})]}):null]})]}):null,l.payload?.type===`poll`&&l.payload.phase===`done`?(0,H.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2 text-sm`,children:[(0,H.jsx)(L,{className:l.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,H.jsx)(`span`,{className:l.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:l.payload.message??(l.payload.ok?n.complete:n.failed)})]}):null,b?(0,H.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,H.jsx)(te,{schema:b.schema,values:l.formDraft,onChange:e=>u(t=>({...t,formDraft:e})),disabled:l.busy,labels:c}),(0,H.jsx)(P,{type:`button`,variant:`primary`,disabled:l.busy,onClick:()=>void d(b.submitAction,l.formDraft),children:n.saveSetup})]}):null,x?(0,H.jsx)(`div`,{className:`mt-4 space-y-2`,children:x.map((e,t)=>(0,H.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,H.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,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}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`,O):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)]`,O,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function le(e){let t=(0,B.c)(30),{presentation:n,open:r,onOpenChange:a,title:o,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:p,wide:m,headerExtra:h}=e,v=m===void 0?!1:m,y=n===`drawer`,S;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,H.jsx)(j,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,w)}),t[0]=S):S=t[0];let C;t[1]!==n||t[2]!==v?(C=ce(n,v),t[1]=n,t[2]=v,t[3]=C):C=t[3];let T;t[4]===c?T=t[5]:(T=c?(0,H.jsx)(x,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=T);let E;t[6]===l?E=t[7]:(E=l?(0,H.jsx)(f,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=E);let D;t[8]!==u||t[9]!==s||t[10]!==h||t[11]!==y||t[12]!==o?(D=y?(0,H.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[o?(0,H.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:o}):null,s?(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,H.jsx)(b,{asChild:!0,children:(0,H.jsx)(P,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,H.jsx)(N,{className:`size-5`,strokeWidth:1.75})})})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(b,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:i(A,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,H.jsx)(N,{className:`size-4`})})}),h]}),t[8]=u,t[9]=s,t[10]=h,t[11]=y,t[12]=o,t[13]=D):D=t[13];let O=y?`px-4 py-4`:`p-6`,k;t[14]===O?k=t[15]:(k=i(`min-h-0 flex-1 overflow-y-auto`,O),t[14]=O,t[15]=k);let F;t[16]!==d||t[17]!==k?(F=(0,H.jsx)(`div`,{className:k,children:d}),t[16]=d,t[17]=k,t[18]=F):F=t[18];let I;t[19]!==p||t[20]!==C||t[21]!==T||t[22]!==E||t[23]!==D||t[24]!==F?(I=(0,H.jsxs)(g,{children:[S,(0,H.jsxs)(M,{className:C,onOpenAutoFocus:ue,children:[T,E,D,F,p]})]}),t[19]=p,t[20]=C,t[21]=T,t[22]=E,t[23]=D,t[24]=F,t[25]=I):I=t[25];let L;return t[26]!==a||t[27]!==r||t[28]!==I?(L=(0,H.jsx)(_,{open:r,onOpenChange:a,children:I}),t[26]=a,t[27]=r,t[28]=I,t[29]=L):L=t[29],L}function ue(e){return e.preventDefault()}var de=(0,V.memo)(function(e){let t=(0,B.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,H.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,H.jsx)(m,{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,H.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 fe(e){let t=(0,B.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,H.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,H.jsx)(P,{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,H.jsx)(P,{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,H.jsx)(P,{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,H.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,H.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}function pe(e){return e?c(`/api/channels/${encodeURIComponent(e)}/config`):null}async function me(e){return(await l(c(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var he=[`enabled`];async function ge(){return(await l(c(`/api/config`))).payload?.config?.channels??{}}function J(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Y(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function X(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function _e(e,t){let n=X(e);return n.state===`needs_setup`?t.hubStatusNeedsSetup:n.state===`error`?t.hubStatusError:n.enabled&&n.ready&&e.runtime===`loaded`?t.hubStatusRunning:n.enabled&&n.ready?t.hubStatusEnabled:n.ready?t.hubStatusConfigured:t.hubStatusNotConfigured}function ve(e){let t=X(e);return t.state===`needs_setup`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:t.state===`error`?`bg-red-500/10 text-red-700 dark:text-red-300`:t.enabled&&t.ready&&e.runtime===`loaded`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:t.enabled||t.ready?`bg-accent-soft text-accent`:`bg-surface-hover text-fg-muted`}function ye(e){if(!e)return[];let t=e.uiHints??{},n=Z(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=X(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!Z(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!he.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!he.includes(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function be(e,t){let n={...Q(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!Z(r)||!Z(r[n]))break;let o=Z(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Q(r[n]),properties:{}}),e===t.length-1){o[n]=Q(r[n]);break}i=r[n],a=o[n]}}return n}function xe(e){let t=e.properties;if(!Z(t))return!1;for(let[e,n]of Object.entries(t))Z(n)&&n.type===`object`&&xe(n)&&delete t[e];return Object.keys(t).length===0}function Se(e,t){let n=Q(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!Z(i))break;if(e===t.length-1){delete i[n];break}if(!Z(i[n]))break;r=i[n]}}return xe(n),n}function Ce(e){return e.type===`object`&&Z(e.properties)&&Object.keys(e.properties).length>0}function $(e,t){let n=e;for(let e of t.split(`.`)){if(!Z(n))return;n=n[e]}return n}function we(e){let t=e.accounts;return Z(t)?Object.values(t).filter(e=>Z(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Te(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 Ee(e,t,n){let r=[],i=X(e);if(i.issues.length>0&&r.push(Ae(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Te(e,$(t,e),n);i&&r.push(i)}let a=we(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function De(e,t){let n=X(e),r=U(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 Oe(e,t){let n=U(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function ke(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 Ae(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 je({entry:e}){let t=s(e=>e.token),[n,r]=(0,V.useState)(!1),i=(0,V.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(c(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${J(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,H.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,H.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,H.jsx)(F,{sourceChannel:e.id,className:`size-7`})})}function Me(e){let t=(0,B.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,H.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,H.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 Ne(e){let t=(0,B.c)(70),{entry:n,config:r,busy:a,ch:o,onOpen:s,onToggle:c}=e,l;t[0]===n?l=t[1]:(l=X(n),t[0]=n,t[1]=l);let u=l,d,f,p,m,h,g,_;if(t[2]!==a||t[3]!==o||t[4]!==r||t[5]!==n||t[6]!==s||t[7]!==c||t[8]!==u.enabled||t[9]!==u.ready){let e=Ee(n,r,o),l=ke(n,o);d=!u.enabled&&u.ready,g=`flex min-h-[15.5rem] flex-col rounded-xl border border-edge-subtle bg-surface-panel p-4 shadow-surface transition-colors hover:border-edge`;let v;t[17]===n?v=t[18]:(v=(0,H.jsx)(je,{entry:n}),t[17]=n,t[18]=v);let y;t[19]===n.label?y=t[20]:(y=(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[19]=n.label,t[20]=y);let b;t[21]===n?b=t[22]:(b=i(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,ve(n)),t[21]=n,t[22]=b);let x;t[23]!==o||t[24]!==n?(x=_e(n,o),t[23]=o,t[24]=n,t[25]=x):x=t[25];let S;t[26]!==b||t[27]!==x?(S=(0,H.jsx)(`span`,{className:b,children:x}),t[26]=b,t[27]=x,t[28]=S):S=t[28];let C;t[29]!==S||t[30]!==y?(C=(0,H.jsxs)(`div`,{className:`min-w-0`,children:[y,S]}),t[29]=S,t[30]=y,t[31]=C):C=t[31];let w;t[32]!==C||t[33]!==v?(w=(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[v,C]}),t[32]=C,t[33]=v,t[34]=w):w=t[34];let T=u.enabled,E;t[35]!==o.toggleChannel||t[36]!==n.label?(E=o.toggleChannel.replace(`{{channel}}`,n.label),t[35]=o.toggleChannel,t[36]=n.label,t[37]=E):E=t[37];let D;t[38]!==a||t[39]!==c||t[40]!==u.enabled||t[41]!==E?(D=(0,H.jsx)(Me,{checked:T,disabled:a,label:E,onToggle:c}),t[38]=a,t[39]=c,t[40]=u.enabled,t[41]=E,t[42]=D):D=t[42],t[43]!==w||t[44]!==D?(_=(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[w,D]}),t[43]=w,t[44]=D,t[45]=_):_=t[45],f=`button`,p=s,m=`mt-5 min-h-[6.25rem] text-left`,h=u.ready?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,H.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map(Fe)}):null]}):(0,H.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.cardSetupTitle}),(0,H.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Oe(n,o)}),l.length>0?(0,H.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:l.map(Pe)}):null]}),t[2]=a,t[3]=o,t[4]=r,t[5]=n,t[6]=s,t[7]=c,t[8]=u.enabled,t[9]=u.ready,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_}else d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16];let v;t[46]!==o.cardAdapterLabel||t[47]!==n.description||t[48]!==u.ready?(v=!u.ready&&n.description?(0,H.jsxs)(`p`,{className:`mt-3 truncate text-xs text-fg-subtle`,title:n.description,children:[o.cardAdapterLabel,`: `,n.description]}):null,t[46]=o.cardAdapterLabel,t[47]=n.description,t[48]=u.ready,t[49]=v):v=t[49];let y;t[50]!==f||t[51]!==p||t[52]!==m||t[53]!==h||t[54]!==v?(y=(0,H.jsxs)(`button`,{type:f,onClick:p,className:m,children:[h,v]}),t[50]=f,t[51]=p,t[52]=m,t[53]=h,t[54]=v,t[55]=y):y=t[55];let b=d?c:s,x;t[56]===a?x=t[57]:(x=a?(0,H.jsx)(T,{className:`size-4 animate-spin`}):null,t[56]=a,t[57]=x);let S;t[58]!==o||t[59]!==n?(S=De(n,o),t[58]=o,t[59]=n,t[60]=S):S=t[60];let C;t[61]!==b||t[62]!==x||t[63]!==S?(C=(0,H.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,H.jsxs)(P,{type:`button`,variant:`primary`,className:`w-full rounded-2xl py-2.5`,onClick:b,children:[x,S]})}),t[61]=b,t[62]=x,t[63]=S,t[64]=C):C=t[64];let w;return t[65]!==C||t[66]!==g||t[67]!==_||t[68]!==y?(w=(0,H.jsxs)(`article`,{className:g,children:[_,y,C]}),t[65]=C,t[66]=g,t[67]=_,t[68]=y,t[69]=w):w=t[69],w}function Pe(e){return(0,H.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function Fe(e){return(0,H.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function Ie(e){let t=(0,B.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=X(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,H.jsx)(R,{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,H.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,H.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,H.jsx)(`li`,{children:Ae(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,H.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,H.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,H.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,H.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function Le(){let e=o(e=>e.language),t=a(e),n=s(e=>!!e.token),r=D(),{channelId:l}=k(),f=h(l),m=ie(n,e),g=m.entries,{data:_={},mutate:y}=d(n?`channels-config-map`:null,ge,{revalidateOnFocus:!1}),b=ee(e=>e.setPageHeader),x=ee(e=>e.clearPageHeader),C=(0,V.useMemo)(()=>g.find(e=>e.id===f),[f,g]),w=C?Y(C):null,{data:T,mutate:O}=d(n&&w?pe(w):null,()=>me(w)),[A,j]=(0,V.useState)(null),[M,N]=(0,V.useState)(!1),[P,F]=(0,V.useState)(null),[L,R]=(0,V.useState)(null),z=A??T??{},B=t.channelsSettings,ae=(0,V.useMemo)(()=>C?.configSchema??{type:`object`,properties:{}},[C?.configSchema]),W=(0,V.useMemo)(()=>Se(ae,he),[ae]),G=(0,V.useMemo)(()=>ye(C),[C]),K=(0,V.useMemo)(()=>be(W,G),[G,W]),q=(0,V.useMemo)(()=>Se(W,G),[G,W]),oe=(0,V.useMemo)(()=>Ce(K),[K]),ce=(0,V.useMemo)(()=>({defaultBooleanLabel:B.schemaBooleanDefault,unsupportedArrayType:B.schemaUnsupportedArrayType,arrayAddPlaceholder:B.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>B.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[B]),ue=(0,V.useMemo)(()=>n?(0,H.jsx)(de,{ch:B,refreshing:m.isValidating,saveOk:!1,onRefresh:()=>void m.mutate()}):null,[m,B,n]);(0,V.useLayoutEffect)(()=>(b({startExtra:null,main:(0,H.jsx)(`div`,{className:`min-w-0`,children:(0,H.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:ue}),()=>x()),[x,ue,t.settingsSections.channels,b]);let J=(0,V.useCallback)(e=>{r(S(e)),j(null),R(null)},[r]),Z=(0,V.useCallback)(()=>{r(v),j(null),R(null)},[r]),Q=(0,V.useCallback)(async()=>{if(!C||!A)return!1;let e=Y(C);N(!0),R(null);try{let t=await u(c(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[e]:A}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return await O(A,!1),await y(),await m.mutate(),j(null),!0}catch(e){return R(e instanceof Error?e.message:String(e)),!1}finally{N(!1)}},[C,m,A,y,O]),xe=(0,V.useCallback)(async e=>{let t=X(e),n=Y(e),r=C?.id===e.id?A:null;if(!t.enabled&&!t.ready&&!r){J(e.id);return}F(e.id),R(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await u(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 y(),C?.id===e.id&&(await O(),j(null))}catch(e){R(e instanceof Error?e.message:String(e))}finally{F(null)}},[C?.id,m,A,y,O,J]),$=C?.ui?.modal,we=$?.placement!==`replace-config`;return n?(0,H.jsxs)(re,{gap:`gap-4`,children:[m.isLoading?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:B.loadingChannels}):m.error?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(m.error)}):(0,H.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:g.map(e=>(0,H.jsx)(Ne,{entry:e,config:_[Y(e)]?.config,busy:P===e.id,ch:B,onOpen:()=>J(e.id),onToggle:()=>void xe(e)},e.id))}),L?(0,H.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:L}):null,(0,H.jsx)(le,{presentation:`modal`,open:!!C,onOpenChange:e=>{e||Z()},closeAriaLabel:B.close,srTitle:C?.label??B.selectChannel,srDescription:C?.description,wide:!0,footer:C?(0,H.jsx)(fe,{ch:B,dirty:!!A,saving:M,onCancel:Z,onDiscard:()=>j(null),onSave:Q}):null,children:C?(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-3`,children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,H.jsx)(je,{entry:C}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:C.label}),(0,H.jsx)(`span`,{className:i(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,ve(C)),children:_e(C,B)})]}),(0,H.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,H.jsx)(`span`,{className:`min-w-0 truncate`,children:U(C)?.[1].result===`qr`?B.scanLoginHint.replace(`{{channel}}`,C.label):C.description}),C.docsPath?(0,H.jsxs)(`a`,{href:C.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[B.docs,(0,H.jsx)(I,{className:`size-3.5`})]}):null]})]})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,H.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:B.enabledLabel}),(0,H.jsx)(Me,{checked:X(C).enabled,disabled:P===C.id,label:B.toggleChannel.replace(`{{channel}}`,C.label),onToggle:()=>void xe(C)})]})]})}),(0,H.jsx)(Ie,{entry:C,ch:B}),$?.entrypoint&&$.placement===`before-config`?(0,H.jsx)(E,{extensionId:C.extensionId,extensionName:C.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:C.id,entry:C,config:z}}):null,$?.placement===`replace-config`?null:(0,H.jsx)(se,{entry:C,locale:e,messages:B,autoStartPrimary:!0,compact:!0,onChanged:async()=>{await O(),await m.mutate(),await y()}},C.id),$?.entrypoint&&$.placement!==`before-config`?(0,H.jsx)(E,{extensionId:C.extensionId,extensionName:C.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:C.id,entry:C,config:z}}):null,we&&oe?(0,H.jsxs)(`section`,{className:`rounded-xl border border-edge-subtle bg-surface-panel p-4`,children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:B.basicConfiguration}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:B.basicConfigurationHint})]}),(0,H.jsx)(te,{schema:K,values:z,onChange:e=>j(e),disabled:M,labels:ce})]}):null,we&&Ce(q)?(0,H.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-panel`,children:[(0,H.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,H.jsx)(p,{className:`size-4 text-fg-muted`}),B.advancedConfiguration]}),(0,H.jsx)(`div`,{className:`border-t border-edge-subtle p-4`,children:(0,H.jsx)(te,{schema:q,values:z,onChange:e=>j(e),disabled:M,labels:ce})})]}):null,L?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:L}):null]}):null})]}):(0,H.jsxs)(re,{gap:`gap-3`,padding:`px-4 py-8`,children:[(0,H.jsx)(ne,{title:t.settingsSections.channels}),(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:B.tokenRequired})]})}export{Le as ChannelsSettingsPanel};
|
package/dist/gateway/static/root/assets/{connectors-page-yaUNvt5u.js → connectors-page-DneJVuge.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
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-CrDHEbss.js";import{t as o}from"./locale-store-DjbfSsfA.js";import{c as s,i as c,n as l}from"./fetch-Y7AEX4H3.js";import{r as u}from"./toast-z0toXu32.js";import{Ai as d,Dr as f,Jo as p,La as m,Mi as h,Ni as g,Oi as _,Pi as v,Po as y,Qi as b,Qn as x,So as S,Ua as C,Xi as w,Zn as T,Zo as E,Zs as D,as as O,ba as k,do as A,hs as j,io as M,ji as N,ki as P,ks as F,la as ee,ni as I,no as te,oa as L,sa as R,so as ne,ta as re,ti as z,to as ie,ua as ae,ws as B,zi as oe}from"./index-BoKafJIZ.js";import{n as se,t as ce}from"./settings-form-section-D-4lBl6X.js";import{i as le,n as ue,o as de,r as fe,t as pe}from"./dist-By6Rh2ee.js";var V=e(t(),1),H=n(),U=r(),W=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`,me=[`c0`,`c1`,`c2`,`c3`,`c4`,`c5`];function he(e,t){return t.some(t=>t.connectorId===e.id)}function G(e,t){return t[e]??e}function K(e,t){return t.connectorCategoryTemplate.replace(`{{category}}`,G(e,t.connectorCategoryLabels))}function ge(){let e=(0,H.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,U.jsx)(`div`,{className:`flex h-full min-h-[9.5rem] flex-col rounded-xl border border-edge-subtle bg-surface-base p-4 dark:border-edge-subtle`,"aria-hidden":!0,children:(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 items-start gap-3`,children:(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,U.jsx)(`div`,{className:i(`h-4 min-w-0 flex-1`,W)}),(0,U.jsx)(`div`,{className:i(`h-8 w-[4.5rem] shrink-0 rounded-lg`,W)})]}),(0,U.jsx)(`div`,{className:i(`h-3 w-full`,W)}),(0,U.jsx)(`div`,{className:i(`h-3 w-[88%]`,W)})]})})}),e[0]=t):t=e[0],t}function _e(){let e=(0,H.c)(3),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,U.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,U.jsx)(`div`,{className:i(`h-4 w-48 max-w-full`,W)}),(0,U.jsx)(`div`,{className:i(`h-3 w-72 max-w-full`,W)})]}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[t,(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,U.jsx)(`div`,{className:i(`h-9 w-20 rounded-lg`,W)}),(0,U.jsx)(`div`,{className:i(`h-9 w-20 rounded-lg`,W)})]})]}),e[1]=n):n=e[1];let r;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,"aria-hidden":!0,children:[n,(0,U.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,U.jsx)(`div`,{className:i(`h-8 w-20 rounded-md`,W)}),(0,U.jsx)(`div`,{className:i(`h-8 w-24 rounded-md`,W)}),(0,U.jsx)(`div`,{className:i(`h-8 w-28 rounded-md`,W)})]}),(0,U.jsx)(`div`,{className:i(`mt-3 h-20 rounded-xl`,W)})]}),e[2]=r):r=e[2],r}function ve(e){let t=(0,H.c)(52),{connector:n,installed:r,onInstall:a,t:o}=e,s;t[0]!==n.category||t[1]!==o?(s=K(n.category,o),t[0]=n.category,t[1]=o,t[2]=s):s=t[2];let c=s,l,u,d,f,p,m;if(t[3]!==c||t[4]!==n||t[5]!==r||t[6]!==a||t[7]!==o.install||t[8]!==o.installedBadge){let e=n.capabilities.slice(0,4),s=Math.max(0,n.capabilities.length-e.length),h;t[15]!==n||t[16]!==a||t[17]!==o.install?(h=e=>(0,U.jsxs)(R,{type:`button`,variant:`primary`,className:i(`h-8 justify-center px-2.5 text-xs font-medium`,e),onClick:()=>a(n),children:[(0,U.jsx)(A,{className:`size-4`}),o.install]}),t[15]=n,t[16]=a,t[17]=o.install,t[18]=h):h=t[18],l=h,m=`group flex min-h-[9.5rem] flex-col rounded-lg border border-edge bg-surface-panel p-4 shadow-surface transition-colors hover:border-accent/50 focus-within:border-accent/50`,u=`flex min-w-0 flex-1 flex-col`;let g;t[19]===n.displayName?g=t[20]:(g=(0,U.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:n.displayName}),t[19]=n.displayName,t[20]=g);let _;t[21]===c?_=t[22]:(_=(0,U.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-subtle`,children:c}),t[21]=c,t[22]=_);let v;t[23]!==g||t[24]!==_?(v=(0,U.jsx)(`div`,{className:`flex min-w-0 items-start gap-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[g,_]})}),t[23]=g,t[24]=_,t[25]=v):v=t[25];let y;t[26]!==r||t[27]!==l?(y=r?null:(0,U.jsx)(`div`,{className:`hidden shrink-0 items-center gap-1 transition-opacity sm:pointer-events-none sm:flex sm:opacity-0 sm:group-hover:pointer-events-auto sm:group-hover:opacity-100 sm:group-focus-within:pointer-events-auto sm:group-focus-within:opacity-100`,children:l()}),t[26]=r,t[27]=l,t[28]=y):y=t[28];let b;t[29]!==r||t[30]!==o.installedBadge?(b=r?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,U.jsx)(B,{className:`size-3`,"aria-hidden":!0}),o.installedBadge]}):null,t[29]=r,t[30]=o.installedBadge,t[31]=b):b=t[31];let x;t[32]!==y||t[33]!==b?(x=(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2`,children:[y,b]}),t[32]=y,t[33]=b,t[34]=x):x=t[34],t[35]!==v||t[36]!==x?(d=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[v,x]}),t[35]=v,t[36]=x,t[37]=d):d=t[37],t[38]===n.description?f=t[39]:(f=(0,U.jsx)(`p`,{className:`mt-4 line-clamp-2 text-sm leading-6 text-fg-muted`,title:n.description,children:n.description}),t[38]=n.description,t[39]=f),p=e.length>0?(0,U.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-1.5`,children:[e.map(q),s>0?(0,U.jsxs)(`span`,{className:`rounded-md border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-subtle`,children:[`+`,s]}):null]}):null,t[3]=c,t[4]=n,t[5]=r,t[6]=a,t[7]=o.install,t[8]=o.installedBadge,t[9]=l,t[10]=u,t[11]=d,t[12]=f,t[13]=p,t[14]=m}else l=t[9],u=t[10],d=t[11],f=t[12],p=t[13],m=t[14];let h;t[40]!==u||t[41]!==d||t[42]!==f||t[43]!==p?(h=(0,U.jsxs)(`div`,{className:u,children:[d,f,p]}),t[40]=u,t[41]=d,t[42]=f,t[43]=p,t[44]=h):h=t[44];let g;t[45]!==r||t[46]!==l?(g=r?null:(0,U.jsx)(`div`,{className:`mt-4 flex items-center justify-end border-t border-edge pt-3 sm:hidden`,children:l(`w-full`)}),t[45]=r,t[46]=l,t[47]=g):g=t[47];let _;return t[48]!==m||t[49]!==h||t[50]!==g?(_=(0,U.jsxs)(`div`,{className:m,children:[h,g]}),t[48]=m,t[49]=h,t[50]=g,t[51]=_):_=t[51],_}function q(e){return(0,U.jsx)(`span`,{className:`rounded-md border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:e},e)}var ye=(0,V.memo)(function(e){let t=(0,H.c)(19),{loading:n,searchQuery:r,setSearchQuery:i,onReloadClick:a,onAddCustomServer:o,searchPlaceholder:s,addLabel:c,reloadLabel:l}=e,u;t[0]!==n||t[1]!==a||t[2]!==l?(u=(0,U.jsx)(f,{className:`size-9 shrink-0 p-0`,loading:n,label:l,title:l,onClick:a}),t[0]=n,t[1]=a,t[2]=l,t[3]=u):u=t[3];let d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,U.jsx)(C,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),t[4]=d):d=t[4];let p;t[5]===i?p=t[6]:(p=e=>i(e.currentTarget.value),t[5]=i,t[6]=p);let m;t[7]!==s||t[8]!==r||t[9]!==p?(m=(0,U.jsxs)(`label`,{className:`relative flex min-h-9 min-w-0 max-w-sm cursor-text items-center rounded-pill border border-edge bg-surface-base py-1.5 pl-9 pr-3 shadow-surface dark:bg-surface-hover/40 sm:max-w-md`,children:[d,(0,U.jsx)(`input`,{type:`search`,enterKeyHint:`search`,value:r,onChange:p,placeholder:s,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 appearance-none border-0 bg-transparent py-0.5 text-sm leading-normal text-fg caret-current placeholder:text-fg-disabled focus:border-0 focus:shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none`})]}),t[7]=s,t[8]=r,t[9]=p,t[10]=m):m=t[10];let h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(ie,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[11]=h):h=t[11];let g;t[12]!==c||t[13]!==o?(g=(0,U.jsxs)(R,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,onClick:o,children:[h,c]}),t[12]=c,t[13]=o,t[14]=g):g=t[14];let _;return t[15]!==u||t[16]!==m||t[17]!==g?(_=(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:[u,m,g]}),t[15]=u,t[16]=m,t[17]=g,t[18]=_):_=t[18],_}),J=/^([^:=]+)[:=](.*)$/;function be(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}))}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=J.exec(t);r&&n.push({key:r[1].trim(),value:r[2].trim()})}return n.length>0?n:null}function xe(e){let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return Object.keys(t).length>0?t:void 0}function Y(e){if(!e||typeof e!=`object`)return[{key:``,value:``}];let t=Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}));return t.length>0?t:[{key:``,value:``}]}function Se(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.xopcConnector;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&t.managed===!0)}function Ce(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=(t&&typeof t==`object`?t:{}).servers,r={};if(!n||typeof n!=`object`||Array.isArray(n))return r;for(let[e,t]of Object.entries(n))!t||typeof t!=`object`||Array.isArray(t)||Se(t)&&(r[e]=t);return r}function we(e){let t=e.trim();if(t)return t.split(/\s+/).filter(Boolean)}function Te(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Ee(e){if(e.transport===`stdio`){let t={command:e.command.trim()},n=we(e.argsText);return n?.length&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envJson.trim()&&(t.env=Te(e.envJson)),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}let t={url:e.url.trim(),transport:e.transport},n=xe(e.headers);return n&&(t.headers=n),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}function De(e,t){let n=typeof t.url==`string`&&t.url.trim().length>0,r=typeof t.transport==`string`?t.transport.trim().toLowerCase():``,i=n?r===`sse`?`sse`:`streamable-http`:`stdio`,a=t.headers&&typeof t.headers==`object`&&!Array.isArray(t.headers)?t.headers:void 0;return{clientKey:e,id:e,transport:i,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?t.args.map(String).join(` `):``,envJson:t.env&&typeof t.env==`object`?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:typeof t.workingDirectory==`string`?t.workingDirectory:``,url:typeof t.url==`string`?t.url:``,headers:Y(a),connectionTimeoutMs:typeof t.connectionTimeoutMs==`number`&&Number.isFinite(t.connectionTimeoutMs)?t.connectionTimeoutMs:void 0}}function Oe(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`stdio`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[{key:`Authorization`,value:``}],connectionTimeoutMs:void 0}}function ke(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=t&&typeof t==`object`?t:{},r=n.servers,i=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).flatMap(([e,t])=>!t||typeof t!=`object`||Array.isArray(t)||Se(t)?[]:[De(e,t)]).sort((e,t)=>e.id.localeCompare(t.id)):[],a=typeof n.sessionIdleTtlMs==`number`?n.sessionIdleTtlMs:void 0;return{sessionIdleTtlMinutes:a==null?void 0:a===0?0:Math.round(a/6e4),servers:i}}function Ae(e){return Ee(e)}async function je(e,t={}){let n={};for(let r of e.servers){let e=r.id.trim();if(e){if(t[e])throw Error(`Server id "${e}" is reserved by an installed connector.`);n[e]=Ee(r)}}let r={servers:{...t,...n}};e.sessionIdleTtlMinutes!=null&&Number.isFinite(e.sessionIdleTtlMinutes)&&(r.sessionIdleTtlMs=e.sessionIdleTtlMinutes===0?0:Math.round(e.sessionIdleTtlMinutes*6e4)),await l(c(`/api/config`),{method:`PATCH`,body:JSON.stringify({mcp:r})}),z()}function Me(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){let e=n.trim();e&&t.push({name:e});continue}if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();if(!r)continue;let i=typeof e.shortName==`string`&&e.shortName.trim()?e.shortName.trim():void 0,a=typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0;t.push({name:r,shortName:i,description:a})}return t}function Ne(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.uri!=`string`||typeof e.name!=`string`)continue;let r=e.uri.trim(),i=e.name.trim();!r||!i||t.push({uri:r,name:i,title:typeof e.title==`string`&&e.title.trim()?e.title.trim():void 0,description:typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0,mimeType:typeof e.mimeType==`string`&&e.mimeType.trim()?e.mimeType.trim():void 0})}return t}function Pe(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();r&&t.push({name:r,title:typeof e.title==`string`&&e.title.trim()?e.title.trim():void 0,description:typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0,argumentCount:typeof e.argumentCount==`number`?e.argumentCount:0})}return t}async function Fe(e,t){let n=await l(c(`/api/mcp/servers/${encodeURIComponent(e)}/test`),{method:`POST`,body:t?JSON.stringify({server:t}):void 0});if(!n.payload)throw Error(n.error??`MCP test failed`);let r=Me(n.payload.tools),i=Ne(n.payload.resources),a=Pe(n.payload.prompts);return{serverId:n.payload.serverId??e,toolCount:typeof n.payload.toolCount==`number`?n.payload.toolCount:r.length,resourceCount:typeof n.payload.resourceCount==`number`?n.payload.resourceCount:i.length,promptCount:typeof n.payload.promptCount==`number`?n.payload.promptCount:a.length,tools:r,resources:i,prompts:a}}function Ie(e){return e.connectionTimeoutMs==null||!Number.isFinite(e.connectionTimeoutMs)?``:String(Math.round(e.connectionTimeoutMs/1e3))}function Le(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>600))return n*1e3}function Re(e){if(e.transport===`stdio`){let t=e.command.trim();if(!t)return``;let n=e.argsText.trim();return n?`${t} ${n}`:t}return e.url.trim()}function X(e,t){return Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{{${t}}}`,n),e)}function ze({row:e,t,cs:n,onEdit:r,onRemove:i}){let[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(null),p=Re(e),m=(0,V.useCallback)(async()=>{o(!0),f(null);try{let t=await Fe(e.id.trim());u({toolCount:t.toolCount,resourceCount:t.resourceCount,promptCount:t.promptCount})}catch(e){f(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e.id]),h=(0,V.useCallback)(async()=>{c(!0),f(null);try{await i()}catch(e){f(e instanceof Error?e.message:String(e)),c(!1)}},[i]);return(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.id.trim()||t.cardUntitled}),(0,U.jsx)(`span`,{className:`rounded-full border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:n.customBadge}),(0,U.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:t.transportLabels[e.transport]})]}),p?(0,U.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-subtle`,title:p,children:p}):null]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(R,{variant:`secondary`,disabled:a,onClick:()=>void m(),children:[a?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),t.testConnection]}),(0,U.jsxs)(R,{variant:`secondary`,onClick:r,children:[(0,U.jsx)(ne,{className:`size-4`}),n.editCustomServer]}),(0,U.jsxs)(R,{variant:`ghost`,disabled:s,onClick:()=>void h(),children:[s?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(k,{className:`size-4`}),t.removeServer]})]})]}),d?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:d}):null,l?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:X(n.customCapabilitySummary,{tools:String(l.toolCount),resources:String(l.resourceCount),prompts:String(l.promptCount)})}):null]})}function Z(e,t){if(!e.payload)throw Error(e.error??t);return e.payload}async function Be(){return Z(await l(c(`/api/connectors/catalog`)),`Could not load connector catalog.`).connectors}async function Ve(){return Z(await l(c(`/api/connectors/catalog`)),`Could not load connector registries.`).registries??[]}async function He(){return Z(await l(c(`/api/connectors/installed`)),`Could not load installed connectors.`).instances}var Ue=new Map,We=300*1e3;async function Ge(e,t=`all`,n){let r=e.trim(),i=t.trim()||`all`,a=n?.browse??!1,o=Math.max(n?.page??1,1),s=Math.max(n?.pageSize??24,1),u=`${i}:${r}:${a?`browse`:`search`}:${o}:${s}`,d=Date.now(),f=Ue.get(u);if(f&&f.expiresAt>d)return f.promise;let p=new URLSearchParams;r&&p.set(`q`,r),i!==`all`&&p.set(`source`,i),a&&p.set(`browse`,`1`),p.set(`page`,String(o)),p.set(`pageSize`,String(s));let m=l(c(`/api/connectors/registry/search?${p.toString()}`)).then(e=>{let t=Z(e,`Could not search connector registries.`),n=Math.max(0,...(t.results??[]).map(e=>e.totalPages??0))||void 0;return{connectors:t.connectors,totalPages:n}});Ue.set(u,{expiresAt:d+We,promise:m});try{return await m}catch(e){throw Ue.delete(u),e}}async function Ke(e){return Z(await l(c(`/api/connectors/${encodeURIComponent(e)}/oauth/start`),{method:`POST`}),`Could not start connector OAuth.`).oauth}async function qe(e,t){return Z(await l(c(`/api/connectors/${encodeURIComponent(e)}/oauth/complete`),{method:`POST`,body:JSON.stringify({deviceCode:t})}),`Could not complete connector OAuth.`).oauth}async function Je(e,t){let n=await l(c(`/api/connectors/${encodeURIComponent(e)}/install`),{method:`POST`,body:JSON.stringify(t)});return z(),Z(n,`Could not install connector.`).instance}async function Ye(e){await l(c(`/api/connectors/${encodeURIComponent(e)}`),{method:`DELETE`}),z()}async function Xe(e){return Z(await l(c(`/api/connectors/${encodeURIComponent(e)}/test`),{method:`POST`}),`Connector test failed.`)}async function Ze(){return Z(await l(c(`/api/connectors/composio/connections`)),`Could not load Composio connections.`).connections}async function Qe(e){return Z(await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/authorize`),{method:`POST`}),`Could not start Composio authorization.`).oauth}async function $e(e){return Z(await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/scope`)),`Could not load Composio scope.`).scope}async function et(e,t){let n=await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/scope`),{method:`POST`,body:JSON.stringify({scope:t})});return z(),Z(n,`Could not update Composio scope.`).scope}async function tt(e){return Z(await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/tools`)),`Could not load Composio tools.`).tools}async function nt(e=50){return Z(await l(c(`/api/connectors/composio/triggers?limit=${encodeURIComponent(String(e))}`)),`Could not load Composio trigger events.`).events}function rt(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function it(e,t,n){let r=t.trim().toLowerCase();if(!r)return!0;let i=e.shortName||rt(e.name,n);return[e.name,i,e.description].filter(Boolean).join(`
|
|
2
|
-
`).toLowerCase().includes(r)}function at(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function ot(e){let t=(0,H.c)(29),{tools:n,stripPrefix:r,searchPlaceholder:a,searchEmptyLabel:o}=e,[s,c]=(0,V.useState)(``),l;if(t[0]!==s||t[1]!==r||t[2]!==n){let e;t[4]!==s||t[5]!==r?(e=e=>it(e,s,r),t[4]=s,t[5]=r,t[6]=e):e=t[6],l=n.filter(e),t[0]=s,t[1]=r,t[2]=n,t[3]=l}else l=t[3];let u=l,d;t[7]===s?d=t[8]:(d=s.trim(),t[7]=s,t[8]=d);let f=d.length>0,p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,U.jsx)(C,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,"aria-hidden":!0}),t[9]=p):p=t[9];let m,h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=i(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-9 pr-3 text-sm text-fg`,`placeholder:text-fg-subtle`,L),h=e=>c(e.target.value),t[10]=m,t[11]=h):(m=t[10],h=t[11]);let g;t[12]!==s||t[13]!==a?(g=(0,U.jsxs)(`div`,{className:`relative`,children:[p,(0,U.jsx)(`input`,{type:`search`,value:s,placeholder:a,"aria-label":a,className:m,onChange:h})]}),t[12]=s,t[13]=a,t[14]=g):g=t[14];let _;t[15]!==u.length||t[16]!==f||t[17]!==n.length?(_=f?(0,U.jsxs)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:[u.length,` / `,n.length]}):null,t[15]=u.length,t[16]=f,t[17]=n.length,t[18]=_):_=t[18];let v;t[19]!==g||t[20]!==_?(v=(0,U.jsxs)(`div`,{className:`border-b border-edge px-5 py-3`,children:[g,_]}),t[19]=g,t[20]=_,t[21]=v):v=t[21];let y;t[22]!==u||t[23]!==o||t[24]!==r?(y=(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:u.length===0?(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:o}):(0,U.jsx)(`ul`,{className:`flex flex-col gap-2`,children:u.map((e,t)=>{let n=e.shortName||at(e.name,r)||e.name||`?`,i=e.name||`tool-${t}`;return(0,U.jsxs)(`li`,{className:`min-w-0 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:[(0,U.jsx)(`div`,{className:`truncate font-mono text-sm font-medium text-fg`,title:e.name===n?n:e.name,children:n}),e.description?(0,U.jsx)(`p`,{className:`mt-1 truncate text-xs leading-relaxed text-fg-muted`,title:e.description,children:e.description}):null]},i)})})}),t[22]=u,t[23]=o,t[24]=r,t[25]=y):y=t[25];let b;return t[26]!==v||t[27]!==y?(b=(0,U.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[v,y]}),t[26]=v,t[27]=y,t[28]=b):b=t[28],b}function st(e){let t=(0,H.c)(38),{open:n,onOpenChange:r,serverId:a,title:o,subtitle:s,searchPlaceholder:c,searchEmptyLabel:l,emptyLabel:u,closeLabel:f,tools:p,stripPrefix:m}=e,y;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,U.jsx)(N,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,x)}),t[0]=y):y=t[0];let b;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(b=i(`fixed left-1/2 top-1/2 flex max-h-[min(88vh,40rem)] w-[min(100%-2rem,min(92vw,36rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,T,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`),t[1]=b):b=t[1];let S;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,U.jsx)(ae,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[2]=S):S=t[2];let C;t[3]===o?C=t[4]:(C=(0,U.jsxs)(v,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[S,o]}),t[3]=o,t[4]=C);let w;t[5]!==a||t[6]!==s||t[7]!==p.length?(w=s.replace(`{{serverId}}`,a).replace(`{{count}}`,String(p.length)),t[5]=a,t[6]=s,t[7]=p.length,t[8]=w):w=t[8];let E;t[9]===w?E=t[10]:(E=(0,U.jsx)(d,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[9]=w,t[10]=E);let D;t[11]!==C||t[12]!==E?(D=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[C,E]}),t[11]=C,t[12]=E,t[13]=D):D=t[13];let O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,U.jsx)(ee,{className:`size-4`,"aria-hidden":!0}),t[14]=O):O=t[14];let k;t[15]===f?k=t[16]:(k=(0,U.jsx)(_,{asChild:!0,children:(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 px-0`,"aria-label":f,children:O})}),t[15]=f,t[16]=k);let A;t[17]!==D||t[18]!==k?(A=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[D,k]}),t[17]=D,t[18]=k,t[19]=A):A=t[19];let j;t[20]!==u||t[21]!==n||t[22]!==l||t[23]!==c||t[24]!==a||t[25]!==m||t[26]!==p?(j=p.length>0?(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,U.jsx)(ot,{tools:p,stripPrefix:m,searchPlaceholder:c,searchEmptyLabel:l},`${a}-${n?`open`:`closed`}`)}):(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u})}),t[20]=u,t[21]=n,t[22]=l,t[23]=c,t[24]=a,t[25]=m,t[26]=p,t[27]=j):j=t[27];let M;t[28]===f?M=t[29]:(M=(0,U.jsx)(`div`,{className:`flex justify-end border-t border-edge px-5 py-3`,children:(0,U.jsx)(_,{asChild:!0,children:(0,U.jsx)(R,{type:`button`,variant:`secondary`,children:f})})}),t[28]=f,t[29]=M);let F;t[30]!==A||t[31]!==j||t[32]!==M?(F=(0,U.jsxs)(h,{children:[y,(0,U.jsxs)(P,{className:b,children:[A,j,M]})]}),t[30]=A,t[31]=j,t[32]=M,t[33]=F):F=t[33];let I;return t[34]!==r||t[35]!==n||t[36]!==F?(I=(0,U.jsx)(g,{open:n,onOpenChange:r,children:F}),t[34]=r,t[35]=n,t[36]=F,t[37]=I):I=t[37],I}var ct=i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L);function lt(e){return e.materialized.type===`composio`?e.connectorId.replace(/^composio-/,``):null}function ut(e,t){return e===`write`?t.composioScopeWrite:e===`admin`?t.composioScopeAdmin:t.composioScopeRead}function dt({instance:e,t}){let n=lt(e),[r,a]=(0,V.useState)([]),[o,s]=(0,V.useState)([]),[c,l]=(0,V.useState)([]),[u,d]=(0,V.useState)(`read`),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(null),g=(0,V.useCallback)(async()=>{if(!(!n||n===`api-key`)){p(!0),h(null);try{let[e,t,r,i]=await Promise.all([Ze().catch(()=>[]),tt(n).catch(()=>[]),nt(20).catch(()=>[]),$e(n).catch(()=>`read`)]);a(e.filter(e=>e.toolkit.toLowerCase()===n.toLowerCase())),s(t),l(r.filter(e=>!e.toolkit||e.toolkit.toLowerCase()===n.toLowerCase())),d(i)}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[n]);(0,V.useEffect)(()=>{g()},[g]);let _=(0,V.useCallback)(async()=>{if(n){p(!0),h(null);try{let e=await Qe(n);window.open(e.connectUrl,`_blank`,`noopener,noreferrer`)}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[n]),v=(0,V.useCallback)(async e=>{if(n){d(e);try{await et(n,e),await g()}catch(e){h(e instanceof Error?e.message:String(e))}}},[g,n]);return n?n===`api-key`?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:t.composioApiKeyStored}):(0,U.jsxs)(`div`,{className:`mt-4 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`font-medium text-fg`,children:X(t.composioToolkitTitle,{toolkit:n})}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.composioScopeHint})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(`select`,{className:i(ct,`h-9 w-28 py-1`),value:u,onChange:e=>void v(e.currentTarget.value),children:[(0,U.jsx)(`option`,{value:`read`,children:t.composioScopeRead}),(0,U.jsx)(`option`,{value:`write`,children:t.composioScopeWrite}),(0,U.jsx)(`option`,{value:`admin`,children:t.composioScopeAdmin})]}),(0,U.jsxs)(R,{variant:`secondary`,disabled:f,onClick:()=>void _(),children:[f?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(y,{className:`size-4`}),t.connectOAuth]}),(0,U.jsx)(R,{variant:`ghost`,disabled:f,onClick:()=>void g(),children:t.refresh})]})]}),m?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:m}):null,(0,U.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioConnections}),r.length?r.map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel p-2`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.accountEmail??e.username??e.workspace??e.id}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.status})]},e.id)):(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioConnectionsEmpty})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioAgentTools}),o.length?o.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel p-2`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.slug}),(0,U.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[ut(e.scope,t),e.curated?``:` ${t.composioUncuratedSuffix}`]})]},e.slug)):(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioToolsEmpty})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioRecentTriggers}),c.length?c.slice(0,5).map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel p-2`,children:[(0,U.jsx)(`p`,{className:`truncate text-xs text-fg`,children:e.trigger??e.id}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:new Date(e.at).toLocaleString()})]},`${e.id}-${e.at}`)):(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioTriggersEmpty})]})]})]}):null}function ft(e,t){return e?t.healthStatusLabels[e]??e:t.healthNotTested}function pt({instance:e,onChanged:t,t:n,mcp:r}){let[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(`health`),[p,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(null),v=(0,V.useCallback)(async()=>{o(!0),_(null);try{let n=await Xe(e.instanceId);u(n),n.toolCount>0&&f(`tools`),await t()}catch(e){_(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e.instanceId,t]),b=(0,V.useCallback)(async()=>{c(!0),_(null);try{await Ye(e.instanceId),await t()}catch(e){_(e instanceof Error?e.message:String(e)),c(!1)}},[e.instanceId,t]),x=l?l.toolCount:e.usage.lastToolCount;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.displayName}),(0,U.jsx)(`span`,{className:`rounded-full border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:n.catalogBadge})]}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.materialized.type===`mcp`?X(n.mcpServerRuntime,{serverId:e.materialized.serverId}):X(n.runtimeLabel,{runtime:e.materialized.type})})]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[e.materialized.type===`mcp`?(0,U.jsxs)(R,{variant:`secondary`,disabled:a,onClick:()=>void v(),children:[a?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),n.test]}):null,(0,U.jsxs)(R,{variant:`ghost`,disabled:s,onClick:()=>void b(),children:[s?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(k,{className:`size-4`}),n.remove]})]})]}),g?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:g}):null,(0,U.jsx)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[[`health`,m,n.detailHealth],[`tools`,ae,`${n.detailTools} ${l?l.toolCount:e.usage.lastToolCount??``}`],[`resources`,O,`${n.detailResources} ${l?l.resourceCount:e.usage.lastResourceCount??``}`],[`prompts`,E,`${n.detailPrompts} ${l?l.promptCount:e.usage.lastPromptCount??``}`],[`permissions`,y,n.detailPermissions]].map(([e,t,n])=>(0,U.jsxs)(`button`,{type:`button`,className:i(`inline-flex h-8 items-center gap-1.5 rounded-md border px-2.5 text-xs`,d===e?`border-accent bg-accent-soft text-accent-fg`:`border-edge bg-surface-base text-fg-muted hover:text-fg`),onClick:()=>f(e),children:[(0,U.jsx)(t,{className:`size-3.5`,"aria-hidden":!0}),n]},e))}),(0,U.jsxs)(`div`,{className:`mt-3 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[d===`health`?(0,U.jsxs)(`div`,{className:`space-y-1 text-fg-muted`,children:[(0,U.jsxs)(`p`,{children:[n.statusLabel,` `,(0,U.jsx)(`span`,{className:l?.ok?`font-medium text-emerald-700 dark:text-emerald-300`:`font-medium text-fg`,children:ft(l?.status??e.usage.lastHealthStatus,n)})]}),(0,U.jsxs)(`p`,{children:[n.lastCheckLabel,` `,e.usage.lastHealthCheckAt?new Date(e.usage.lastHealthCheckAt).toLocaleString():n.never]}),l?.action?(0,U.jsx)(`p`,{children:l.action}):null]}):null,d===`tools`?l?.tools.length?(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:X(n.toolsAvailable,{count:String(l.tools.length)})}),(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>h(!0),children:r.viewAllTools})]}),l.tools.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.shortName??e.name}),e.description?(0,U.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.description}):null]},e.name))]}):(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`p`,{className:`text-fg-muted`,children:x?X(n.toolsLastCheckSummary,{count:String(x)}):n.toolsRunTestHint}),(0,U.jsxs)(R,{type:`button`,variant:`secondary`,disabled:a,onClick:()=>void v(),children:[a?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),n.test]})]}):null,d===`resources`?l?.resources.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:l.resources.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.title??e.name}),(0,U.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.uri})]},e.uri))}):(0,U.jsx)(`p`,{className:`text-fg-muted`,children:n.resourcesRunTestHint}):null,d===`prompts`?l?.prompts.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:l.prompts.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.title??e.name}),e.description?(0,U.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.description}):null]},e.name))}):(0,U.jsx)(`p`,{className:`text-fg-muted`,children:n.promptsRunTestHint}):null,d===`permissions`?(0,U.jsxs)(`div`,{className:`space-y-1 text-fg-muted`,children:[(0,U.jsx)(`p`,{children:X(n.secretsConfigured,{count:String(Object.values(e.secretStatus).filter(Boolean).length)})}),(0,U.jsx)(`p`,{children:e.materialized.type===`mcp`?X(n.runtimeServerLabel,{runtime:e.materialized.type.toUpperCase(),serverId:e.materialized.serverId}):X(n.runtimeLabel,{runtime:e.materialized.type.toUpperCase()})}),(0,U.jsx)(`p`,{children:e.materialized.type===`mcp`?n.mcpPolicyHint:n.connectorPolicyHint})]}):null]}),e.materialized.type===`composio`?(0,U.jsx)(dt,{instance:e,t:n}):null]}),e.materialized.type===`mcp`?(0,U.jsx)(st,{open:p,onOpenChange:h,serverId:e.materialized.serverId,title:X(n.installedToolsDialogTitle,{name:e.displayName}),subtitle:n.installedToolsDialogSubtitle,searchPlaceholder:r.toolsDialogSearchPlaceholder,searchEmptyLabel:r.toolsDialogSearchEmpty,emptyLabel:n.toolsRunTestHint,closeLabel:r.toolsDialogClose,tools:l?.tools??[],stripPrefix:`${e.materialized.serverId}__`}):null]})}var mt=i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L),ht=i(mt,`min-h-28 font-mono`);function gt(e,t){return e?t.healthStatusLabels[e]??e:t.healthStatusPending}function _t(e,t){let n=t.trim();return e===`json`?n?JSON.parse(n):void 0:e===`number`?n?Number(n):void 0:e===`boolean`?n===`true`:n||void 0}function vt(e){let t={};for(let n of e.setup.secrets??[])t[n.key]=``;let n={};for(let t of e.setup.config??[])n[t.key]=t.defaultValue===void 0?``:typeof t.defaultValue==`string`?t.defaultValue:JSON.stringify(t.defaultValue,null,2);return{connector:e,secrets:t,config:n,installing:!1,error:null,result:null,health:null,oauth:{flow:null,connected:e.auth.mode!==`oauth`}}}function yt({draft:e,onChange:t,onClose:n,onInstalled:r,t:a}){let{connector:o}=e,s=e.result?`complete`:e.installing?`health`:`configure`,c=[{id:`configure`,label:a.installStepConfigure},{id:`health`,label:a.installStepHealth},{id:`complete`,label:a.installStepComplete}],l=(0,V.useCallback)(async()=>{t({...e,installing:!0,error:null});try{let n=await Ke(o.id);window.open(n.verificationUri,`_blank`,`noopener,noreferrer`),t({...e,installing:!1,error:null,oauth:{flow:n,connected:!1}})}catch(n){t({...e,installing:!1,error:n instanceof Error?n.message:String(n)})}},[o.id,e,t]),u=(0,V.useCallback)(async()=>{if(e.oauth.flow){t({...e,installing:!0,error:null});try{await qe(o.id,e.oauth.flow.deviceCode),t({...e,installing:!1,error:null,oauth:{...e.oauth,connected:!0}})}catch(n){t({...e,installing:!1,error:n instanceof Error?n.message:String(n)})}}},[o.id,e,t]),f=(0,V.useCallback)(async()=>{t({...e,installing:!0,error:null,result:null,health:null});try{if(o.auth.mode===`oauth`&&!e.oauth.connected)throw Error(a.oauthRequiredBeforeInstall);let n={};for(let t of o.setup.config??[]){let r=_t(t.type,e.config[t.key]??``);r!==void 0&&(n[t.key]=r)}let i=await Je(o.id,{secrets:e.secrets,config:n,definition:o.source===`registry`?o:void 0}),s=null;try{s=await Xe(i.instanceId)}catch{s=null}t({...e,installing:!1,result:i,health:s}),await r()}catch(n){t({...e,installing:!1,error:n instanceof Error?n.message:String(n)})}},[o,e,t,r,a.oauthRequiredBeforeInstall]);return(0,U.jsx)(g,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(h,{children:[(0,U.jsx)(N,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,U.jsxs)(P,{className:i(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex max-h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,48rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float dark:border-edge`),children:[(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(v,{className:`text-base font-semibold text-fg`,children:X(a.installDialogTitle,{name:o.displayName})}),(0,U.jsx)(d,{className:`mt-1 line-clamp-3 text-sm text-fg-muted`,children:o.description})]}),(0,U.jsx)(_,{asChild:!0,children:(0,U.jsxs)(`button`,{type:`button`,className:i(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,re.focusRingPanel),"aria-label":a.modalClose,children:[(0,U.jsx)(ee,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,U.jsx)(`span`,{className:`sr-only`,children:a.modalClose})]})})]}),(0,U.jsxs)(`div`,{className:`min-h-0 overflow-y-auto px-6 py-5`,children:[(0,U.jsx)(`div`,{className:`mb-5 grid grid-cols-3 gap-2`,"aria-label":a.installProgressAria,children:c.map((e,t)=>{let n=c.findIndex(e=>e.id===s);return(0,U.jsxs)(`div`,{className:i(`rounded-xl border px-3 py-2 text-xs font-medium`,t===n?`border-accent bg-accent-soft text-accent-fg`:t<n?`border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900/40 dark:bg-emerald-950/40 dark:text-emerald-200`:`border-edge bg-surface-base text-fg-muted`),children:[(0,U.jsxs)(`span`,{className:`mr-1 tabular-nums`,children:[t+1,`.`]}),e.label]},e.id)})}),(0,U.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o.auth.mode===`oauth`?(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4`,children:[(0,U.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:a.oauthTitle}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:a.oauthHint}),e.oauth.flow?(0,U.jsxs)(`div`,{className:`mt-3 rounded-xl bg-surface-base p-3 text-sm text-fg-muted`,children:[(0,U.jsx)(`p`,{children:X(a.oauthOpenCodePrefix,{url:e.oauth.flow.verificationUri})}),(0,U.jsx)(`p`,{className:`mt-2 font-mono text-lg font-semibold tracking-widest text-fg`,children:e.oauth.flow.userCode})]}):null,e.oauth.connected?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700`,children:a.oauthConnected}):null,(0,U.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,U.jsxs)(R,{variant:`secondary`,disabled:e.installing,onClick:()=>void l(),children:[e.installing&&!e.oauth.flow?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),a.oauthConnectButton]}),(0,U.jsxs)(R,{variant:`primary`,disabled:e.installing||!e.oauth.flow,onClick:()=>void u(),children:[e.installing&&e.oauth.flow?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(B,{className:`size-4`}),a.oauthAuthorizedButton]})]})]}):null,(o.setup.secrets??[]).map(n=>(0,U.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.label}),n.description?(0,U.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.description}):null,(0,U.jsx)(w,{value:e.secrets[n.key]??``,onChange:r=>t({...e,secrets:{...e.secrets,[n.key]:r},error:null}),labels:a.secretInputLabels,placeholder:n.required?a.requiredPlaceholder:a.optionalPlaceholder})]},n.key)),(o.setup.config??[]).map(n=>(0,U.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.label}),n.type===`json`?(0,U.jsx)(`textarea`,{className:ht,value:e.config[n.key]??``,placeholder:n.placeholder,onChange:r=>t({...e,config:{...e.config,[n.key]:r.currentTarget.value},error:null})}):(0,U.jsx)(`input`,{className:mt,value:e.config[n.key]??``,placeholder:n.placeholder,onChange:r=>t({...e,config:{...e.config,[n.key]:r.currentTarget.value},error:null})})]},n.key)),e.installing?(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-fg`,children:[(0,U.jsx)(S,{className:`size-4 animate-spin text-accent`,"aria-hidden":!0}),a.installingTitle]}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:a.installingHint})]}):null,e.error?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:e.error}):null,e.result?(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`font-medium text-fg`,children:X(a.installedAs,{target:e.result.materialized.type===`mcp`?e.result.materialized.serverId:e.result.instanceId})}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:X(a.runtimeLabel,{runtime:e.result.materialized.type.toUpperCase()})})]}),(0,U.jsx)(`span`,{className:i(`rounded-full px-2 py-0.5 text-xs font-medium`,e.health?.ok?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:e.health?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:`bg-surface-hover text-fg-muted`),children:e.health?.ok?a.healthStatusHealthy:gt(e.health?.status,a)})]}),e.health?(0,U.jsxs)(`div`,{className:`mt-3 grid gap-2 text-xs sm:grid-cols-3`,children:[(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-fg`,children:e.health.toolCount}),(0,U.jsx)(`div`,{children:a.toolsMetric})]}),(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-fg`,children:e.health.resourceCount}),(0,U.jsx)(`div`,{children:a.resourcesMetric})]}),(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-fg`,children:e.health.promptCount}),(0,U.jsx)(`div`,{children:a.promptsMetric})]})]}):(0,U.jsx)(`p`,{className:`mt-3`,children:a.installedWithoutHealth}),e.health?.action?(0,U.jsx)(`p`,{className:`mt-3 text-xs text-fg-subtle`,children:e.health.action}):null]}):null]})]}),(0,U.jsx)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:(0,U.jsxs)(R,{variant:`primary`,disabled:!!e.result||e.installing||o.auth.mode===`oauth`&&!e.oauth.connected,onClick:()=>void f(),children:[e.installing?(0,U.jsx)(S,{className:`size-4 animate-spin`}):e.result?(0,U.jsx)(B,{className:`size-4`}):(0,U.jsx)(A,{className:`size-4`}),e.result?a.installedBadge:a.install]})})]})]})})}function bt(e,t){let n=e.length+1,r=`server-${n}`,i=new Set([...e.map(e=>e.id.trim()),...t]);for(;i.has(r);)n+=1,r=`server-${n}`;return Oe(r)}function xt(e,t){let n=t.trim().toLowerCase();return n?[e.displayName,e.description,e.category,e.kind,e.source,...e.tags??[]].some(e=>e.toLowerCase().includes(n)):!0}function St(e,t,n){return e.filter(e=>xt(e,t)).toSorted((e,t)=>n===`source`&&e.source!==t.source?e.source.localeCompare(t.source):e.displayName.localeCompare(t.displayName))}function Ct(e,t){let n=t.trim().toLowerCase();return n?[e.displayName,e.connectorId,e.instanceId,e.status,e.connectionStatus??``,e.materialized.type,e.materialized.type===`mcp`?e.materialized.serverId:e.materialized.id].some(e=>e.toLowerCase().includes(n)):!0}function wt(e,t){let n=t.trim().toLowerCase();return n?[e.id,e.command??``,e.url??``,e.transport].some(e=>e.toLowerCase().includes(n)):!0}function Tt(e,t,n){let r=e.key.trim();if(r)return`key:${r}`;let i=e.value.trim();return i?`value:${i}`:`empty:${n.slice(0,t).filter(e=>!e.key.trim()&&!e.value.trim()).length}`}function Et(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L)}function Dt({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:a,pasteFailed:o,keyPlaceholder:s,valuePlaceholder:c,headers:l,onChange:u}){let d=(e,t)=>{u(l.map((n,r)=>r===e?{...n,...t}:n))},f=()=>{u([...l,{key:``,value:``}])},p=e=>{let t=l.filter((t,n)=>n!==e);u(t.length>0?t:[{key:``,value:``}])},m=async()=>{try{let e=await b();if(!e){window.alert(o);return}let t=be(e);if(!t?.length){window.alert(o);return}u(t)}catch{window.alert(o)}};return(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,U.jsx)(`span`,{children:e}),t?(0,U.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),(0,U.jsxs)(R,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void m(),children:[(0,U.jsx)(j,{className:`size-3.5`,"aria-hidden":!0}),a]})]}),(0,U.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map((e,t)=>(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{className:i(Et(),`min-w-0 flex-1 font-mono text-xs`),value:e.key,placeholder:s,onChange:e=>d(t,{key:e.target.value})}),(0,U.jsx)(`input`,{className:i(Et(),`min-w-0 flex-[1.4] font-mono text-xs`),value:e.value,placeholder:c,onChange:e=>d(t,{value:e.target.value})}),(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:l.length<=1&&!e.key&&!e.value,onClick:()=>p(t),"aria-label":r,children:(0,U.jsx)(k,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})})]},Tt(e,t,l)))}),(0,U.jsxs)(`button`,{type:`button`,className:i(`self-start text-sm text-accent hover:underline`,re.press),onClick:f,children:[`+ `,n]})]})}var Ot=[`stdio`,`sse`,`streamable-http`];function Q(e){let t=(0,H.c)(11),{label:n,description:r,required:i,children:a}=e,o;t[0]===i?o=t[1]:(o=i?(0,U.jsx)(`span`,{className:`ml-0.5 text-danger`,children:`*`}):null,t[0]=i,t[1]=o);let s;t[2]!==n||t[3]!==o?(s=(0,U.jsxs)(`div`,{className:`text-sm font-medium text-fg`,children:[n,o]}),t[2]=n,t[3]=o,t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=r?(0,U.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}):null,t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==s||t[9]!==c?(l=(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[s,a,c]}),t[7]=a,t[8]=s,t[9]=c,t[10]=l):l=t[10],l}function $(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L)}function kt(e){let t=(0,H.c)(67),{row:n,t:r,onUpdate:a,idConflictMessage:o}=e,s=r.transportLabel,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=$(),t[0]=c):c=t[0];let l=n.transport,u;t[1]===a?u=t[2]:(u=e=>a({transport:e.target.value}),t[1]=a,t[2]=u);let d;t[3]===r.transportLabels?d=t[4]:(d=Ot.map(e=>(0,U.jsx)(`option`,{value:e,children:r.transportLabels[e]},e)),t[3]=r.transportLabels,t[4]=d);let f;t[5]!==n.transport||t[6]!==u||t[7]!==d?(f=(0,U.jsx)(`select`,{className:c,value:l,onChange:u,children:d}),t[5]=n.transport,t[6]=u,t[7]=d,t[8]=f):f=t[8];let p;t[9]!==r.transportLabel||t[10]!==f?(p=(0,U.jsx)(Q,{label:s,required:!0,children:f}),t[9]=r.transportLabel,t[10]=f,t[11]=p):p=t[11];let m=r.serverIdLabel,h;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(h=$(),t[12]=h):h=t[12];let g;t[13]===a?g=t[14]:(g=e=>a({id:e.target.value}),t[13]=a,t[14]=g);let _;t[15]!==n.id||t[16]!==r.serverIdPlaceholder||t[17]!==g?(_=(0,U.jsx)(`input`,{className:h,value:n.id,placeholder:r.serverIdPlaceholder,onChange:g}),t[15]=n.id,t[16]=r.serverIdPlaceholder,t[17]=g,t[18]=_):_=t[18];let v;t[19]===o?v=t[20]:(v=o?(0,U.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-300`,children:o}):null,t[19]=o,t[20]=v);let y;t[21]!==r.serverIdLabel||t[22]!==_||t[23]!==v?(y=(0,U.jsxs)(Q,{label:m,required:!0,children:[_,v]}),t[21]=r.serverIdLabel,t[22]=_,t[23]=v,t[24]=y):y=t[24];let b;t[25]!==a||t[26]!==n.argsText||t[27]!==n.command||t[28]!==n.cwd||t[29]!==n.envJson||t[30]!==n.headers||t[31]!==n.transport||t[32]!==n.url||t[33]!==r.addHeader||t[34]!==r.argsHint||t[35]!==r.argsLabel||t[36]!==r.commandLabel||t[37]!==r.cwdLabel||t[38]!==r.envHint||t[39]!==r.envLabel||t[40]!==r.headerKeyPlaceholder||t[41]!==r.headerValuePlaceholder||t[42]!==r.headersLabel||t[43]!==r.optionalSuffix||t[44]!==r.pasteHeaders||t[45]!==r.pasteHeadersFailed||t[46]!==r.removeHeader||t[47]!==r.urlLabel?(b=n.transport===`stdio`?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Q,{label:r.commandLabel,required:!0,children:(0,U.jsx)(`input`,{className:$(),value:n.command,onChange:e=>a({command:e.target.value})})}),(0,U.jsx)(Q,{label:r.argsLabel,description:r.argsHint,children:(0,U.jsx)(`input`,{className:$(),value:n.argsText,onChange:e=>a({argsText:e.target.value})})}),(0,U.jsx)(Q,{label:r.cwdLabel,children:(0,U.jsx)(`input`,{className:$(),value:n.cwd,onChange:e=>a({cwd:e.target.value})})}),(0,U.jsx)(Q,{label:r.envLabel,description:r.envHint,children:(0,U.jsx)(`textarea`,{className:i($(),`min-h-[4rem] font-mono text-xs`),value:n.envJson,onChange:e=>a({envJson:e.target.value})})})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`md:col-span-2`,children:(0,U.jsx)(Q,{label:r.urlLabel,required:!0,children:(0,U.jsx)(`input`,{className:i($(),`font-mono text-xs`),value:n.url,placeholder:`https://example.com/mcp`,onChange:e=>a({url:e.target.value})})})}),(0,U.jsx)(Dt,{label:r.headersLabel,optionalLabel:r.optionalSuffix,addLabel:r.addHeader,removeHeaderAria:r.removeHeader,pasteLabel:r.pasteHeaders,pasteFailed:r.pasteHeadersFailed,keyPlaceholder:r.headerKeyPlaceholder,valuePlaceholder:r.headerValuePlaceholder,headers:n.headers,onChange:e=>a({headers:e})})]}),t[25]=a,t[26]=n.argsText,t[27]=n.command,t[28]=n.cwd,t[29]=n.envJson,t[30]=n.headers,t[31]=n.transport,t[32]=n.url,t[33]=r.addHeader,t[34]=r.argsHint,t[35]=r.argsLabel,t[36]=r.commandLabel,t[37]=r.cwdLabel,t[38]=r.envHint,t[39]=r.envLabel,t[40]=r.headerKeyPlaceholder,t[41]=r.headerValuePlaceholder,t[42]=r.headersLabel,t[43]=r.optionalSuffix,t[44]=r.pasteHeaders,t[45]=r.pasteHeadersFailed,t[46]=r.removeHeader,t[47]=r.urlLabel,t[48]=b):b=t[48];let x=r.timeoutLabel,S=r.timeoutHint,C;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(C=$(),t[49]=C):C=t[49];let w;t[50]===n?w=t[51]:(w=Ie(n),t[50]=n,t[51]=w);let T;t[52]===a?T=t[53]:(T=e=>a({connectionTimeoutMs:Le(e.target.value)}),t[52]=a,t[53]=T);let E;t[54]!==r.timeoutPlaceholder||t[55]!==w||t[56]!==T?(E=(0,U.jsx)(`input`,{type:`number`,min:1,max:600,className:C,value:w,placeholder:r.timeoutPlaceholder,onChange:T}),t[54]=r.timeoutPlaceholder,t[55]=w,t[56]=T,t[57]=E):E=t[57];let D;t[58]!==r.timeoutHint||t[59]!==r.timeoutLabel||t[60]!==E?(D=(0,U.jsx)(Q,{label:x,description:S,children:E}),t[58]=r.timeoutHint,t[59]=r.timeoutLabel,t[60]=E,t[61]=D):D=t[61];let O;return t[62]!==y||t[63]!==b||t[64]!==D||t[65]!==p?(O=(0,U.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[p,y,b,D]}),t[62]=y,t[63]=b,t[64]=D,t[65]=p,t[66]=O):O=t[66],O}function At({open:e,mode:t,initialRow:n,existingCustomServers:r,sessionIdleTtlMinutes:a,config:o,managedServerIds:s,t:c,cs:l,onClose:u,onSaved:f}){let[p,m]=(0,V.useState)(n),[y,b]=(0,V.useState)(!1),[x,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)({status:`idle`}),[O,k]=(0,V.useState)(null),A=n.id.trim(),j=p.id.trim()!==A&&s.has(p.id.trim())||s.has(p.id.trim())&&t===`add`?c.reservedServerId:void 0,F=p.id.trim()&&r.some(e=>e.clientKey!==n.clientKey&&e.id.trim()===p.id.trim())?l.duplicateServerId:void 0,I=p.id.trim().length>0&&!j&&!F&&(p.transport===`stdio`?p.command.trim().length>0:p.url.trim().length>0),te=(0,V.useCallback)(async()=>{if(p.id.trim()){C(!0),T(null),D({status:`loading`});try{D({status:`ok`,tools:(await Fe(p.id.trim(),Ae(p))).tools})}catch(e){D({status:`error`,message:e instanceof Error?e.message:String(e)})}finally{C(!1)}}},[p]),L=(0,V.useCallback)(async()=>{if(!(!I||y)){b(!0),T(null);try{let e=r.filter(e=>!(t===`edit`&&e.clientKey===n.clientKey));e.push(p),await je({sessionIdleTtlMinutes:a,servers:e.sort((e,t)=>e.id.localeCompare(t.id))},Ce(o)),await f(),u()}catch(e){T(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[I,o,r,n.clientKey,t,u,f,A,p,y,a]);return e?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(g,{open:e,onOpenChange:e=>{e||u()},children:(0,U.jsxs)(h,{children:[(0,U.jsx)(N,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,U.jsxs)(P,{className:i(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,48rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float dark:border-edge`),children:[(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(v,{className:`text-base font-semibold text-fg`,children:t===`add`?l.addCustomServerTitle:l.editCustomServerTitle}),(0,U.jsx)(d,{className:`mt-1 text-sm text-fg-muted`,children:t===`add`?l.addCustomServerHint:l.editCustomServerHint})]}),(0,U.jsx)(_,{asChild:!0,children:(0,U.jsxs)(`button`,{type:`button`,className:i(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,re.focusRingPanel),"aria-label":l.modalClose,children:[(0,U.jsx)(ee,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,U.jsx)(`span`,{className:`sr-only`,children:l.modalClose})]})})]}),(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:(0,U.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,U.jsx)(kt,{row:p,t:c,onUpdate:e=>{m(t=>({...t,...e})),T(null)},idConflictMessage:j??F}),E.status===`ok`?(0,U.jsx)(`div`,{className:`rounded-xl border border-edge bg-surface-base px-3 py-2.5`,children:(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,U.jsx)(ae,{className:`size-4 text-accent`,"aria-hidden":!0}),E.tools.length===0?c.toolsEmpty:c.toolsTitle.replace(`{{count}}`,String(E.tools.length))]}),E.tools.length>0?(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:()=>k(E.tools),children:c.viewAllTools}):null]})}):null,E.status===`error`?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:E.message}):null,w?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:w}):null]})}),(0,U.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,U.jsxs)(R,{variant:`secondary`,disabled:!p.id.trim()||x,onClick:()=>void te(),children:[x?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),c.testConnection]}),(0,U.jsx)(_,{asChild:!0,children:(0,U.jsx)(R,{variant:`secondary`,children:l.modalCancel})}),(0,U.jsxs)(R,{variant:`primary`,disabled:!I||y,onClick:()=>void L(),children:[y?(0,U.jsx)(S,{className:`size-4 animate-spin`}):(0,U.jsx)(B,{className:`size-4`}),y?c.saving:l.modalSave]})]})]})]})}),O?(0,U.jsx)(st,{open:!0,onOpenChange:e=>{e||k(null)},serverId:p.id,title:c.toolsDialogTitle,subtitle:c.toolsDialogSubtitle,searchPlaceholder:c.toolsDialogSearchPlaceholder,searchEmptyLabel:c.toolsDialogSearchEmpty,emptyLabel:c.toolsEmpty,closeLabel:c.toolsDialogClose,tools:O,stripPrefix:`${p.id.trim()}__`}):null]}):null}var jt=`mprov`,Mt=`smithery`,Nt=i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L);function Pt(){let e=a(o(e=>e.language)),t=e.connectorsSettings,n=e.mcpSettings,r=s(e=>e.token),c=!!r,[l,d]=D(),f=l.get(jt)?.trim()||Mt,[m,h]=(0,V.useState)(`marketplace`),[g,_]=(0,V.useState)({catalog:[],registryCatalog:[],instances:[],registries:[],loading:!0,error:null}),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)(1),[C,w]=(0,V.useState)(void 0),[T,E]=(0,V.useState)(``),[O,k]=(0,V.useState)(f),[A,j]=(0,V.useState)(`name`),[M,N]=(0,V.useState)(null),[P,ee]=(0,V.useState)(null),[L,ne]=(0,V.useState)(void 0),[z,ie]=(0,V.useState)(!1),[ae,B]=(0,V.useState)(!1),{data:H,mutate:W}=I(c),G=H?.payload?.config,K=(0,V.useMemo)(()=>G===void 0?null:ke(G),[G]),q=K?.servers??[];(0,V.useEffect)(()=>{K&&ne(K.sessionIdleTtlMinutes)},[K]);let J=(0,V.useCallback)(async()=>{if(!r){_({catalog:[],registryCatalog:[],instances:[],registries:[],loading:!1,error:null});return}_(e=>({...e,loading:!0,error:null}));try{let[e,t,n]=await Promise.all([Be(),He(),Ve()]);_(r=>({catalog:e,registryCatalog:r.registryCatalog,instances:t,registries:n,loading:!1,error:null}))}catch(e){_({catalog:[],registryCatalog:[],instances:[],registries:[],loading:!1,error:e instanceof Error?e.message:String(e)})}},[r]);(0,V.useEffect)(()=>{J()},[J]);let be=l.toString(),xe=(0,V.useRef)(be);(0,V.useEffect)(()=>{xe.current!==be&&(xe.current=be,k(l.get(jt)?.trim()||Mt))},[l,be]);let Y=(0,V.useMemo)(()=>g.registries.map(e=>e.id),[g.registries]);(0,V.useEffect)(()=>{if(Y.length===0||Y.includes(O))return;let e=Y.includes(Mt)?Mt:Y[0];e&&k(e)},[O,Y]),(0,V.useEffect)(()=>{if(!O||O===l.get(jt))return;let e=new URLSearchParams(l);e.set(jt,O),xe.current=e.toString(),d(e,{replace:!0})},[O,l,d]);let Se=(0,V.useCallback)(async e=>{let t=T.trim(),n=e?.browse??!1,r=Math.max(e?.page??1,1),i=e?.append??!1;if(!(!c||!t&&!n)){y(!0),i?_(e=>({...e,error:null})):(x(1),w(void 0),_(e=>({...e,registryCatalog:[],error:null})));try{let e=await Ge(t,O,{browse:n,page:r});x(r),w(e.totalPages),_(t=>({...t,registryCatalog:i?[...t.registryCatalog,...e.connectors].filter((e,t,n)=>n.findIndex(t=>t.id===e.id)===t):e.connectors}))}catch(e){_(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}},[c,T,O]);(0,V.useEffect)(()=>{if(m!==`marketplace`)return;let e=window.setTimeout(()=>{T.trim()?Se():O&&Se({browse:!0})},T.trim()?350:0);return()=>window.clearTimeout(e)},[O,T,Se,g.loading,m]);let we=(0,V.useMemo)(()=>new Set(g.instances.map(e=>e.connectorId)),[g.instances]),Te=(0,V.useMemo)(()=>new Set(g.instances.flatMap(e=>e.materialized.type===`mcp`?[e.materialized.serverId]:[])),[g.instances]),Ee=(0,V.useCallback)(async e=>{if(!K||G===void 0)return;let t=q.filter(t=>t.clientKey!==e.clientKey);await je({sessionIdleTtlMinutes:K.sessionIdleTtlMinutes,servers:t},Ce(G)),await W(),await J()},[G,q,J,K,W]),De=(0,V.useCallback)(()=>{ee({mode:`add`,row:bt(q,Te)})},[q,Te]),Oe=(0,V.useCallback)(async()=>{if(!(!K||G===void 0||z)){ie(!0),B(!1);try{await je({sessionIdleTtlMinutes:L,servers:q},Ce(G)),await W(),B(!0),u({type:`success`,title:n.saved})}finally{ie(!1)}}},[G,q,K,W,L,z]),Ae=oe(e=>e.setPageHeader),Me=oe(e=>e.clearPageHeader),Ne=(0,V.useMemo)(()=>(0,U.jsx)(ye,{loading:g.loading||v,searchQuery:T,setSearchQuery:E,onReloadClick:J,onAddCustomServer:De,searchPlaceholder:m===`marketplace`?t.marketplaceSearchPlaceholder:m===`builtin`?t.builtinSearchPlaceholder:m===`user`?t.userSearchPlaceholder:t.configSearchPlaceholder,addLabel:t.addCustomServer,reloadLabel:t.reload}),[t,J,De,v,T,g.loading,m]);(0,V.useLayoutEffect)(()=>(Ae({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.title})}),end:Ne}),()=>Me()),[Me,t.title,Ne,Ae]);let Pe=g.instances.length+q.length,Fe=(0,V.useMemo)(()=>St(g.catalog.filter(e=>e.source===`builtin`),T,A),[A,T,g.catalog]),Ie=(0,V.useMemo)(()=>St(g.registryCatalog,T,A),[A,T,g.registryCatalog]),Le=m===`marketplace`&&!!(C&&b<C),Re=(0,V.useMemo)(()=>g.instances.filter(e=>Ct(e,T)),[T,g.instances]),X=(0,V.useMemo)(()=>q.filter(e=>wt(e,T)),[q,T]),Z=Re.length+X.length;return(0,U.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:(0,U.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6 sm:px-8`,children:[c?null:(0,U.jsx)(`p`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3 text-sm text-fg-muted`,children:t.tokenHint}),(0,U.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,U.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-edge-subtle pb-3 sm:flex-row sm:items-center sm:justify-between dark:border-edge-subtle`,children:[(0,U.jsx)(`div`,{className:`flex flex-wrap gap-x-1 gap-y-1`,role:`tablist`,"aria-label":t.navAria,children:[`marketplace`,`builtin`,`user`,`config`].map(e=>(0,U.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":m===e,className:i(`relative max-w-full rounded-md px-3 py-2 text-left text-sm font-medium transition-colors sm:text-center`,m===e?`text-fg after:absolute after:bottom-0 after:left-1/2 after:h-0.5 after:w-9 after:-translate-x-1/2 after:rounded-full after:bg-accent`:`text-fg-muted hover:text-fg`),onClick:()=>h(e),children:[e===`marketplace`?t.tabMarketplace:e===`builtin`?t.tabBuiltin:e===`user`?t.tabUser:t.tabConfig,e===`builtin`?(0,U.jsxs)(`span`,{className:`ml-1 tabular-nums text-fg-muted`,children:[`(`,Fe.length,`)`]}):null,e===`user`?(0,U.jsxs)(`span`,{className:`ml-1 tabular-nums text-fg-muted`,children:[`(`,Pe,`)`]}):null]},e))}),(0,U.jsxs)(`div`,{className:`flex min-h-9 min-w-0 flex-wrap items-center gap-2 sm:justify-end`,children:[m===`marketplace`?(0,U.jsx)(`div`,{className:`inline-flex h-9 max-w-full shrink-0 overflow-x-auto rounded-lg border border-edge bg-surface-panel p-0.5 shadow-surface`,role:`group`,"aria-label":t.registrySourceAria,children:g.registries.map(e=>(0,U.jsx)(`button`,{type:`button`,className:i(`shrink-0 rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors`,re.focusRingPanel,O===e.id?`bg-fg text-surface-panel dark:bg-fg dark:text-surface-base`:`text-fg-muted hover:text-fg`),"aria-pressed":O===e.id,onClick:()=>k(e.id),children:e.displayName},e.id))}):null,m!==`user`&&m!==`config`?(0,U.jsxs)(le,{children:[(0,U.jsx)(de,{asChild:!0,children:(0,U.jsxs)(`button`,{type:`button`,className:i(`inline-flex h-9 min-h-9 min-w-[9rem] shrink-0 items-center gap-1.5 rounded-lg border border-edge bg-surface-panel px-2.5 text-xs font-medium text-fg shadow-surface`,re.transition,re.focusRingPanel),children:[(0,U.jsx)(p,{className:`size-3.5 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),(0,U.jsx)(`span`,{children:A===`name`?t.sortName:t.sortSource}),(0,U.jsx)(F,{className:`size-3.5 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0})]})}),(0,U.jsx)(fe,{children:(0,U.jsxs)(pe,{className:`z-50 min-w-[10rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[(0,U.jsx)(ue,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>j(`name`),children:t.sortName}),(0,U.jsx)(ue,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>j(`source`),children:t.sortSource})]})})]}):null]})]}),g.error?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:g.error}):null,m===`user`&&c?(0,U.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.installedTitle}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.installedHint})]}),g.loading?(0,U.jsx)(`div`,{className:`grid gap-3`,"aria-busy":`true`,"aria-label":t.loading,children:me.slice(0,3).map(e=>(0,U.jsx)(_e,{},e))}):Pe===0||Z===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:Pe===0?t.installedEmpty:t.userEmpty}):(0,U.jsxs)(`div`,{className:`grid gap-3`,children:[Re.map(e=>(0,U.jsx)(pt,{instance:e,onChanged:J,t,mcp:n},e.instanceId)),X.map(e=>(0,U.jsx)(ze,{row:e,t:n,cs:t,onEdit:()=>ee({mode:`edit`,row:structuredClone(e)}),onRemove:async()=>Ee(e)},e.clientKey))]}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.disableHint})]}):null,m===`config`&&c?(0,U.jsx)(`div`,{className:`flex flex-col gap-4`,children:(0,U.jsxs)(ce,{children:[(0,U.jsx)(se,{icon:te,title:n.globalTitle,subtitle:n.globalHint}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.idleTtlLabel}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`input`,{type:`number`,min:0,className:i(Nt,`w-40 flex-none`),value:L??``,placeholder:n.idleTtlPlaceholder,onChange:e=>{let t=e.target.value.trim();ne(t===``?void 0:Number.parseInt(t,10)),B(!1)}}),(0,U.jsxs)(R,{variant:`secondary`,disabled:z,onClick:()=>void Oe(),children:[z?(0,U.jsx)(S,{className:`size-4 animate-spin`}):null,n.save]})]}),(0,U.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.idleTtlHint})]})})]})}):null,m===`marketplace`&&c?(0,U.jsx)(`div`,{className:`flex flex-col gap-4`,children:v&&Ie.length===0?(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":t.loading,children:me.map(e=>(0,U.jsx)(ge,{},e))}):T.trim()&&Ie.length===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.marketplaceEmpty}):!T.trim()&&Ie.length===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.marketplaceStartHint}):(0,U.jsxs)(`div`,{className:`relative`,children:[v?(0,U.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[1] flex justify-center bg-surface-panel/40 pt-[min(28vh,7.5rem)] backdrop-blur-[1px] motion-reduce:backdrop-blur-none dark:bg-surface-base/35`,"aria-busy":`true`,"aria-label":t.loading,children:(0,U.jsx)(S,{className:`size-8 shrink-0 animate-spin text-accent motion-reduce:animate-none`,strokeWidth:2,"aria-hidden":!0})}):null,(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:Ie.map(e=>(0,U.jsx)(ve,{connector:e,installed:we.has(e.id)||he(e,g.instances),onInstall:e=>N(vt(e)),t},e.id))}),Le?(0,U.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,U.jsxs)(R,{type:`button`,variant:`secondary`,disabled:v,onClick:()=>void Se({browse:!T.trim(),page:b+1,append:!0}),children:[v?(0,U.jsx)(S,{className:`size-4 animate-spin`}):null,t.loadMore]})}):null]})}):null,m===`builtin`&&c?(0,U.jsx)(`div`,{className:`flex flex-col gap-4`,children:g.loading?(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":t.loading,children:me.map(e=>(0,U.jsx)(ge,{},e))}):Fe.length===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.builtinEmpty}):(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:Fe.map(e=>(0,U.jsx)(ve,{connector:e,installed:we.has(e.id)||he(e,g.instances),onInstall:e=>N(vt(e)),t},e.id))})}):null]}),M?(0,U.jsx)(yt,{draft:M,onChange:N,onClose:()=>N(null),t,onInstalled:async()=>{await J(),await W(),h(`user`)}}):null,P?(0,U.jsx)(At,{open:!0,mode:P.mode,initialRow:P.row,existingCustomServers:q,sessionIdleTtlMinutes:L,config:G,managedServerIds:Te,t:n,cs:t,onClose:()=>ee(null),onSaved:async()=>{await W(),await J(),h(`user`)}},`${P.mode}-${P.row.clientKey}`):null]})})}export{Pt as ConnectorsPage};
|
|
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-CISb1HLv.js";import{n as o}from"./locale-store-Ba72bFmP.js";import{c as s,i as c,n as l}from"./fetch-B3ME5Eri.js";import{r as u}from"./toast-z0toXu32.js";import{Ai as d,Dr as f,Jo as p,La as m,Mi as h,Ni as g,Oi as _,Pi as v,Po as y,Qi as b,Qn as x,Qs as S,So as C,Ua as w,Xi as T,Zn as E,Zo as D,as as O,ba as k,do as A,hs as j,io as M,ji as N,ki as P,ks as F,la as ee,ni as I,no as te,oa as L,sa as R,so as ne,ta as re,ti as z,to as ie,ua as ae,ws as B,zi as oe}from"./index-CnjzMw5i.js";import{n as se,t as ce}from"./settings-form-section-DBkGwpIN.js";import{i as le,n as ue,o as de,r as fe,t as pe}from"./dist-By6Rh2ee.js";var V=e(t(),1),H=n(),U=r(),W=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`,me=[`c0`,`c1`,`c2`,`c3`,`c4`,`c5`];function he(e,t){return t.some(t=>t.connectorId===e.id)}function G(e,t){return t[e]??e}function K(e,t){return t.connectorCategoryTemplate.replace(`{{category}}`,G(e,t.connectorCategoryLabels))}function ge(){let e=(0,H.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,U.jsx)(`div`,{className:`flex h-full min-h-[9.5rem] flex-col rounded-xl border border-edge-subtle bg-surface-base p-4 dark:border-edge-subtle`,"aria-hidden":!0,children:(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 items-start gap-3`,children:(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,U.jsx)(`div`,{className:i(`h-4 min-w-0 flex-1`,W)}),(0,U.jsx)(`div`,{className:i(`h-8 w-[4.5rem] shrink-0 rounded-lg`,W)})]}),(0,U.jsx)(`div`,{className:i(`h-3 w-full`,W)}),(0,U.jsx)(`div`,{className:i(`h-3 w-[88%]`,W)})]})})}),e[0]=t):t=e[0],t}function _e(){let e=(0,H.c)(3),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,U.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,U.jsx)(`div`,{className:i(`h-4 w-48 max-w-full`,W)}),(0,U.jsx)(`div`,{className:i(`h-3 w-72 max-w-full`,W)})]}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[t,(0,U.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,U.jsx)(`div`,{className:i(`h-9 w-20 rounded-lg`,W)}),(0,U.jsx)(`div`,{className:i(`h-9 w-20 rounded-lg`,W)})]})]}),e[1]=n):n=e[1];let r;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,"aria-hidden":!0,children:[n,(0,U.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,U.jsx)(`div`,{className:i(`h-8 w-20 rounded-md`,W)}),(0,U.jsx)(`div`,{className:i(`h-8 w-24 rounded-md`,W)}),(0,U.jsx)(`div`,{className:i(`h-8 w-28 rounded-md`,W)})]}),(0,U.jsx)(`div`,{className:i(`mt-3 h-20 rounded-xl`,W)})]}),e[2]=r):r=e[2],r}function ve(e){let t=(0,H.c)(52),{connector:n,installed:r,onInstall:a,t:o}=e,s;t[0]!==n.category||t[1]!==o?(s=K(n.category,o),t[0]=n.category,t[1]=o,t[2]=s):s=t[2];let c=s,l,u,d,f,p,m;if(t[3]!==c||t[4]!==n||t[5]!==r||t[6]!==a||t[7]!==o.install||t[8]!==o.installedBadge){let e=n.capabilities.slice(0,4),s=Math.max(0,n.capabilities.length-e.length),h;t[15]!==n||t[16]!==a||t[17]!==o.install?(h=e=>(0,U.jsxs)(R,{type:`button`,variant:`primary`,className:i(`h-8 justify-center px-2.5 text-xs font-medium`,e),onClick:()=>a(n),children:[(0,U.jsx)(A,{className:`size-4`}),o.install]}),t[15]=n,t[16]=a,t[17]=o.install,t[18]=h):h=t[18],l=h,m=`group flex min-h-[9.5rem] flex-col rounded-lg border border-edge bg-surface-panel p-4 shadow-surface transition-colors hover:border-accent/50 focus-within:border-accent/50`,u=`flex min-w-0 flex-1 flex-col`;let g;t[19]===n.displayName?g=t[20]:(g=(0,U.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:n.displayName}),t[19]=n.displayName,t[20]=g);let _;t[21]===c?_=t[22]:(_=(0,U.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-subtle`,children:c}),t[21]=c,t[22]=_);let v;t[23]!==g||t[24]!==_?(v=(0,U.jsx)(`div`,{className:`flex min-w-0 items-start gap-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[g,_]})}),t[23]=g,t[24]=_,t[25]=v):v=t[25];let y;t[26]!==r||t[27]!==l?(y=r?null:(0,U.jsx)(`div`,{className:`hidden shrink-0 items-center gap-1 transition-opacity sm:pointer-events-none sm:flex sm:opacity-0 sm:group-hover:pointer-events-auto sm:group-hover:opacity-100 sm:group-focus-within:pointer-events-auto sm:group-focus-within:opacity-100`,children:l()}),t[26]=r,t[27]=l,t[28]=y):y=t[28];let b;t[29]!==r||t[30]!==o.installedBadge?(b=r?(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,U.jsx)(B,{className:`size-3`,"aria-hidden":!0}),o.installedBadge]}):null,t[29]=r,t[30]=o.installedBadge,t[31]=b):b=t[31];let x;t[32]!==y||t[33]!==b?(x=(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2`,children:[y,b]}),t[32]=y,t[33]=b,t[34]=x):x=t[34],t[35]!==v||t[36]!==x?(d=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[v,x]}),t[35]=v,t[36]=x,t[37]=d):d=t[37],t[38]===n.description?f=t[39]:(f=(0,U.jsx)(`p`,{className:`mt-4 line-clamp-2 text-sm leading-6 text-fg-muted`,title:n.description,children:n.description}),t[38]=n.description,t[39]=f),p=e.length>0?(0,U.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-1.5`,children:[e.map(q),s>0?(0,U.jsxs)(`span`,{className:`rounded-md border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-subtle`,children:[`+`,s]}):null]}):null,t[3]=c,t[4]=n,t[5]=r,t[6]=a,t[7]=o.install,t[8]=o.installedBadge,t[9]=l,t[10]=u,t[11]=d,t[12]=f,t[13]=p,t[14]=m}else l=t[9],u=t[10],d=t[11],f=t[12],p=t[13],m=t[14];let h;t[40]!==u||t[41]!==d||t[42]!==f||t[43]!==p?(h=(0,U.jsxs)(`div`,{className:u,children:[d,f,p]}),t[40]=u,t[41]=d,t[42]=f,t[43]=p,t[44]=h):h=t[44];let g;t[45]!==r||t[46]!==l?(g=r?null:(0,U.jsx)(`div`,{className:`mt-4 flex items-center justify-end border-t border-edge pt-3 sm:hidden`,children:l(`w-full`)}),t[45]=r,t[46]=l,t[47]=g):g=t[47];let _;return t[48]!==m||t[49]!==h||t[50]!==g?(_=(0,U.jsxs)(`div`,{className:m,children:[h,g]}),t[48]=m,t[49]=h,t[50]=g,t[51]=_):_=t[51],_}function q(e){return(0,U.jsx)(`span`,{className:`rounded-md border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:e},e)}var ye=(0,V.memo)(function(e){let t=(0,H.c)(19),{loading:n,searchQuery:r,setSearchQuery:i,onReloadClick:a,onAddCustomServer:o,searchPlaceholder:s,addLabel:c,reloadLabel:l}=e,u;t[0]!==n||t[1]!==a||t[2]!==l?(u=(0,U.jsx)(f,{className:`size-9 shrink-0 p-0`,loading:n,label:l,title:l,onClick:a}),t[0]=n,t[1]=a,t[2]=l,t[3]=u):u=t[3];let d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,U.jsx)(w,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),t[4]=d):d=t[4];let p;t[5]===i?p=t[6]:(p=e=>i(e.currentTarget.value),t[5]=i,t[6]=p);let m;t[7]!==s||t[8]!==r||t[9]!==p?(m=(0,U.jsxs)(`label`,{className:`relative flex min-h-9 min-w-0 max-w-sm cursor-text items-center rounded-pill border border-edge bg-surface-base py-1.5 pl-9 pr-3 shadow-surface dark:bg-surface-hover/40 sm:max-w-md`,children:[d,(0,U.jsx)(`input`,{type:`search`,enterKeyHint:`search`,value:r,onChange:p,placeholder:s,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 appearance-none border-0 bg-transparent py-0.5 text-sm leading-normal text-fg caret-current placeholder:text-fg-disabled focus:border-0 focus:shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none`})]}),t[7]=s,t[8]=r,t[9]=p,t[10]=m):m=t[10];let h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(ie,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[11]=h):h=t[11];let g;t[12]!==c||t[13]!==o?(g=(0,U.jsxs)(R,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,onClick:o,children:[h,c]}),t[12]=c,t[13]=o,t[14]=g):g=t[14];let _;return t[15]!==u||t[16]!==m||t[17]!==g?(_=(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:[u,m,g]}),t[15]=u,t[16]=m,t[17]=g,t[18]=_):_=t[18],_}),J=/^([^:=]+)[:=](.*)$/;function be(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}))}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=J.exec(t);r&&n.push({key:r[1].trim(),value:r[2].trim()})}return n.length>0?n:null}function xe(e){let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return Object.keys(t).length>0?t:void 0}function Y(e){if(!e||typeof e!=`object`)return[{key:``,value:``}];let t=Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}));return t.length>0?t:[{key:``,value:``}]}function Se(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.xopcConnector;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&t.managed===!0)}function Ce(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=(t&&typeof t==`object`?t:{}).servers,r={};if(!n||typeof n!=`object`||Array.isArray(n))return r;for(let[e,t]of Object.entries(n))!t||typeof t!=`object`||Array.isArray(t)||Se(t)&&(r[e]=t);return r}function we(e){let t=e.trim();if(t)return t.split(/\s+/).filter(Boolean)}function Te(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Ee(e){if(e.transport===`stdio`){let t={command:e.command.trim()},n=we(e.argsText);return n?.length&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envJson.trim()&&(t.env=Te(e.envJson)),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}let t={url:e.url.trim(),transport:e.transport},n=xe(e.headers);return n&&(t.headers=n),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}function De(e,t){let n=typeof t.url==`string`&&t.url.trim().length>0,r=typeof t.transport==`string`?t.transport.trim().toLowerCase():``,i=n?r===`sse`?`sse`:`streamable-http`:`stdio`,a=t.headers&&typeof t.headers==`object`&&!Array.isArray(t.headers)?t.headers:void 0;return{clientKey:e,id:e,transport:i,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?t.args.map(String).join(` `):``,envJson:t.env&&typeof t.env==`object`?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:typeof t.workingDirectory==`string`?t.workingDirectory:``,url:typeof t.url==`string`?t.url:``,headers:Y(a),connectionTimeoutMs:typeof t.connectionTimeoutMs==`number`&&Number.isFinite(t.connectionTimeoutMs)?t.connectionTimeoutMs:void 0}}function Oe(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`stdio`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[{key:`Authorization`,value:``}],connectionTimeoutMs:void 0}}function ke(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=t&&typeof t==`object`?t:{},r=n.servers,i=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).flatMap(([e,t])=>!t||typeof t!=`object`||Array.isArray(t)||Se(t)?[]:[De(e,t)]).sort((e,t)=>e.id.localeCompare(t.id)):[],a=typeof n.sessionIdleTtlMs==`number`?n.sessionIdleTtlMs:void 0;return{sessionIdleTtlMinutes:a==null?void 0:a===0?0:Math.round(a/6e4),servers:i}}function Ae(e){return Ee(e)}async function je(e,t={}){let n={};for(let r of e.servers){let e=r.id.trim();if(e){if(t[e])throw Error(`Server id "${e}" is reserved by an installed connector.`);n[e]=Ee(r)}}let r={servers:{...t,...n}};e.sessionIdleTtlMinutes!=null&&Number.isFinite(e.sessionIdleTtlMinutes)&&(r.sessionIdleTtlMs=e.sessionIdleTtlMinutes===0?0:Math.round(e.sessionIdleTtlMinutes*6e4)),await l(c(`/api/config`),{method:`PATCH`,body:JSON.stringify({mcp:r})}),z()}function Me(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){let e=n.trim();e&&t.push({name:e});continue}if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();if(!r)continue;let i=typeof e.shortName==`string`&&e.shortName.trim()?e.shortName.trim():void 0,a=typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0;t.push({name:r,shortName:i,description:a})}return t}function Ne(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.uri!=`string`||typeof e.name!=`string`)continue;let r=e.uri.trim(),i=e.name.trim();!r||!i||t.push({uri:r,name:i,title:typeof e.title==`string`&&e.title.trim()?e.title.trim():void 0,description:typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0,mimeType:typeof e.mimeType==`string`&&e.mimeType.trim()?e.mimeType.trim():void 0})}return t}function Pe(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();r&&t.push({name:r,title:typeof e.title==`string`&&e.title.trim()?e.title.trim():void 0,description:typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0,argumentCount:typeof e.argumentCount==`number`?e.argumentCount:0})}return t}async function Fe(e,t){let n=await l(c(`/api/mcp/servers/${encodeURIComponent(e)}/test`),{method:`POST`,body:t?JSON.stringify({server:t}):void 0});if(!n.payload)throw Error(n.error??`MCP test failed`);let r=Me(n.payload.tools),i=Ne(n.payload.resources),a=Pe(n.payload.prompts);return{serverId:n.payload.serverId??e,toolCount:typeof n.payload.toolCount==`number`?n.payload.toolCount:r.length,resourceCount:typeof n.payload.resourceCount==`number`?n.payload.resourceCount:i.length,promptCount:typeof n.payload.promptCount==`number`?n.payload.promptCount:a.length,tools:r,resources:i,prompts:a}}function Ie(e){return e.connectionTimeoutMs==null||!Number.isFinite(e.connectionTimeoutMs)?``:String(Math.round(e.connectionTimeoutMs/1e3))}function Le(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>600))return n*1e3}function Re(e){if(e.transport===`stdio`){let t=e.command.trim();if(!t)return``;let n=e.argsText.trim();return n?`${t} ${n}`:t}return e.url.trim()}function X(e,t){return Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{{${t}}}`,n),e)}function ze({row:e,t,cs:n,onEdit:r,onRemove:i}){let[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(null),p=Re(e),m=(0,V.useCallback)(async()=>{o(!0),f(null);try{let t=await Fe(e.id.trim());u({toolCount:t.toolCount,resourceCount:t.resourceCount,promptCount:t.promptCount})}catch(e){f(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e.id]),h=(0,V.useCallback)(async()=>{c(!0),f(null);try{await i()}catch(e){f(e instanceof Error?e.message:String(e)),c(!1)}},[i]);return(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.id.trim()||t.cardUntitled}),(0,U.jsx)(`span`,{className:`rounded-full border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:n.customBadge}),(0,U.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:t.transportLabels[e.transport]})]}),p?(0,U.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-subtle`,title:p,children:p}):null]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(R,{variant:`secondary`,disabled:a,onClick:()=>void m(),children:[a?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),t.testConnection]}),(0,U.jsxs)(R,{variant:`secondary`,onClick:r,children:[(0,U.jsx)(ne,{className:`size-4`}),n.editCustomServer]}),(0,U.jsxs)(R,{variant:`ghost`,disabled:s,onClick:()=>void h(),children:[s?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(k,{className:`size-4`}),t.removeServer]})]})]}),d?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:d}):null,l?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:X(n.customCapabilitySummary,{tools:String(l.toolCount),resources:String(l.resourceCount),prompts:String(l.promptCount)})}):null]})}function Z(e,t){if(!e.payload)throw Error(e.error??t);return e.payload}async function Be(){return Z(await l(c(`/api/connectors/catalog`)),`Could not load connector catalog.`).connectors}async function Ve(){return Z(await l(c(`/api/connectors/catalog`)),`Could not load connector registries.`).registries??[]}async function He(){return Z(await l(c(`/api/connectors/installed`)),`Could not load installed connectors.`).instances}var Ue=new Map,We=300*1e3;async function Ge(e,t=`all`,n){let r=e.trim(),i=t.trim()||`all`,a=n?.browse??!1,o=Math.max(n?.page??1,1),s=Math.max(n?.pageSize??24,1),u=`${i}:${r}:${a?`browse`:`search`}:${o}:${s}`,d=Date.now(),f=Ue.get(u);if(f&&f.expiresAt>d)return f.promise;let p=new URLSearchParams;r&&p.set(`q`,r),i!==`all`&&p.set(`source`,i),a&&p.set(`browse`,`1`),p.set(`page`,String(o)),p.set(`pageSize`,String(s));let m=l(c(`/api/connectors/registry/search?${p.toString()}`)).then(e=>{let t=Z(e,`Could not search connector registries.`),n=Math.max(0,...(t.results??[]).map(e=>e.totalPages??0))||void 0;return{connectors:t.connectors,totalPages:n}});Ue.set(u,{expiresAt:d+We,promise:m});try{return await m}catch(e){throw Ue.delete(u),e}}async function Ke(e){return Z(await l(c(`/api/connectors/${encodeURIComponent(e)}/oauth/start`),{method:`POST`}),`Could not start connector OAuth.`).oauth}async function qe(e,t){return Z(await l(c(`/api/connectors/${encodeURIComponent(e)}/oauth/complete`),{method:`POST`,body:JSON.stringify({deviceCode:t})}),`Could not complete connector OAuth.`).oauth}async function Je(e,t){let n=await l(c(`/api/connectors/${encodeURIComponent(e)}/install`),{method:`POST`,body:JSON.stringify(t)});return z(),Z(n,`Could not install connector.`).instance}async function Ye(e){await l(c(`/api/connectors/${encodeURIComponent(e)}`),{method:`DELETE`}),z()}async function Xe(e){return Z(await l(c(`/api/connectors/${encodeURIComponent(e)}/test`),{method:`POST`}),`Connector test failed.`)}async function Ze(){return Z(await l(c(`/api/connectors/composio/connections`)),`Could not load Composio connections.`).connections}async function Qe(e){return Z(await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/authorize`),{method:`POST`}),`Could not start Composio authorization.`).oauth}async function $e(e){return Z(await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/scope`)),`Could not load Composio scope.`).scope}async function et(e,t){let n=await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/scope`),{method:`POST`,body:JSON.stringify({scope:t})});return z(),Z(n,`Could not update Composio scope.`).scope}async function tt(e){return Z(await l(c(`/api/connectors/composio/${encodeURIComponent(e)}/tools`)),`Could not load Composio tools.`).tools}async function nt(e=50){return Z(await l(c(`/api/connectors/composio/triggers?limit=${encodeURIComponent(String(e))}`)),`Could not load Composio trigger events.`).events}function rt(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function it(e,t,n){let r=t.trim().toLowerCase();if(!r)return!0;let i=e.shortName||rt(e.name,n);return[e.name,i,e.description].filter(Boolean).join(`
|
|
2
|
+
`).toLowerCase().includes(r)}function at(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function ot(e){let t=(0,H.c)(29),{tools:n,stripPrefix:r,searchPlaceholder:a,searchEmptyLabel:o}=e,[s,c]=(0,V.useState)(``),l;if(t[0]!==s||t[1]!==r||t[2]!==n){let e;t[4]!==s||t[5]!==r?(e=e=>it(e,s,r),t[4]=s,t[5]=r,t[6]=e):e=t[6],l=n.filter(e),t[0]=s,t[1]=r,t[2]=n,t[3]=l}else l=t[3];let u=l,d;t[7]===s?d=t[8]:(d=s.trim(),t[7]=s,t[8]=d);let f=d.length>0,p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,U.jsx)(w,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,"aria-hidden":!0}),t[9]=p):p=t[9];let m,h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=i(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-9 pr-3 text-sm text-fg`,`placeholder:text-fg-subtle`,L),h=e=>c(e.target.value),t[10]=m,t[11]=h):(m=t[10],h=t[11]);let g;t[12]!==s||t[13]!==a?(g=(0,U.jsxs)(`div`,{className:`relative`,children:[p,(0,U.jsx)(`input`,{type:`search`,value:s,placeholder:a,"aria-label":a,className:m,onChange:h})]}),t[12]=s,t[13]=a,t[14]=g):g=t[14];let _;t[15]!==u.length||t[16]!==f||t[17]!==n.length?(_=f?(0,U.jsxs)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:[u.length,` / `,n.length]}):null,t[15]=u.length,t[16]=f,t[17]=n.length,t[18]=_):_=t[18];let v;t[19]!==g||t[20]!==_?(v=(0,U.jsxs)(`div`,{className:`border-b border-edge px-5 py-3`,children:[g,_]}),t[19]=g,t[20]=_,t[21]=v):v=t[21];let y;t[22]!==u||t[23]!==o||t[24]!==r?(y=(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:u.length===0?(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:o}):(0,U.jsx)(`ul`,{className:`flex flex-col gap-2`,children:u.map((e,t)=>{let n=e.shortName||at(e.name,r)||e.name||`?`,i=e.name||`tool-${t}`;return(0,U.jsxs)(`li`,{className:`min-w-0 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:[(0,U.jsx)(`div`,{className:`truncate font-mono text-sm font-medium text-fg`,title:e.name===n?n:e.name,children:n}),e.description?(0,U.jsx)(`p`,{className:`mt-1 truncate text-xs leading-relaxed text-fg-muted`,title:e.description,children:e.description}):null]},i)})})}),t[22]=u,t[23]=o,t[24]=r,t[25]=y):y=t[25];let b;return t[26]!==v||t[27]!==y?(b=(0,U.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[v,y]}),t[26]=v,t[27]=y,t[28]=b):b=t[28],b}function st(e){let t=(0,H.c)(38),{open:n,onOpenChange:r,serverId:a,title:o,subtitle:s,searchPlaceholder:c,searchEmptyLabel:l,emptyLabel:u,closeLabel:f,tools:p,stripPrefix:m}=e,y;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,U.jsx)(N,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,x)}),t[0]=y):y=t[0];let b;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(b=i(`fixed left-1/2 top-1/2 flex max-h-[min(88vh,40rem)] w-[min(100%-2rem,min(92vw,36rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,E,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`),t[1]=b):b=t[1];let S;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,U.jsx)(ae,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[2]=S):S=t[2];let C;t[3]===o?C=t[4]:(C=(0,U.jsxs)(v,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[S,o]}),t[3]=o,t[4]=C);let w;t[5]!==a||t[6]!==s||t[7]!==p.length?(w=s.replace(`{{serverId}}`,a).replace(`{{count}}`,String(p.length)),t[5]=a,t[6]=s,t[7]=p.length,t[8]=w):w=t[8];let T;t[9]===w?T=t[10]:(T=(0,U.jsx)(d,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[9]=w,t[10]=T);let D;t[11]!==C||t[12]!==T?(D=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[C,T]}),t[11]=C,t[12]=T,t[13]=D):D=t[13];let O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,U.jsx)(ee,{className:`size-4`,"aria-hidden":!0}),t[14]=O):O=t[14];let k;t[15]===f?k=t[16]:(k=(0,U.jsx)(_,{asChild:!0,children:(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 px-0`,"aria-label":f,children:O})}),t[15]=f,t[16]=k);let A;t[17]!==D||t[18]!==k?(A=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[D,k]}),t[17]=D,t[18]=k,t[19]=A):A=t[19];let j;t[20]!==u||t[21]!==n||t[22]!==l||t[23]!==c||t[24]!==a||t[25]!==m||t[26]!==p?(j=p.length>0?(0,U.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,U.jsx)(ot,{tools:p,stripPrefix:m,searchPlaceholder:c,searchEmptyLabel:l},`${a}-${n?`open`:`closed`}`)}):(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u})}),t[20]=u,t[21]=n,t[22]=l,t[23]=c,t[24]=a,t[25]=m,t[26]=p,t[27]=j):j=t[27];let M;t[28]===f?M=t[29]:(M=(0,U.jsx)(`div`,{className:`flex justify-end border-t border-edge px-5 py-3`,children:(0,U.jsx)(_,{asChild:!0,children:(0,U.jsx)(R,{type:`button`,variant:`secondary`,children:f})})}),t[28]=f,t[29]=M);let F;t[30]!==A||t[31]!==j||t[32]!==M?(F=(0,U.jsxs)(h,{children:[y,(0,U.jsxs)(P,{className:b,children:[A,j,M]})]}),t[30]=A,t[31]=j,t[32]=M,t[33]=F):F=t[33];let I;return t[34]!==r||t[35]!==n||t[36]!==F?(I=(0,U.jsx)(g,{open:n,onOpenChange:r,children:F}),t[34]=r,t[35]=n,t[36]=F,t[37]=I):I=t[37],I}var ct=i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L);function lt(e){return e.materialized.type===`composio`?e.connectorId.replace(/^composio-/,``):null}function ut(e,t){return e===`write`?t.composioScopeWrite:e===`admin`?t.composioScopeAdmin:t.composioScopeRead}function dt({instance:e,t}){let n=lt(e),[r,a]=(0,V.useState)([]),[o,s]=(0,V.useState)([]),[c,l]=(0,V.useState)([]),[u,d]=(0,V.useState)(`read`),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(null),g=(0,V.useCallback)(async()=>{if(!(!n||n===`api-key`)){p(!0),h(null);try{let[e,t,r,i]=await Promise.all([Ze().catch(()=>[]),tt(n).catch(()=>[]),nt(20).catch(()=>[]),$e(n).catch(()=>`read`)]);a(e.filter(e=>e.toolkit.toLowerCase()===n.toLowerCase())),s(t),l(r.filter(e=>!e.toolkit||e.toolkit.toLowerCase()===n.toLowerCase())),d(i)}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[n]);(0,V.useEffect)(()=>{g()},[g]);let _=(0,V.useCallback)(async()=>{if(n){p(!0),h(null);try{let e=await Qe(n);window.open(e.connectUrl,`_blank`,`noopener,noreferrer`)}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[n]),v=(0,V.useCallback)(async e=>{if(n){d(e);try{await et(n,e),await g()}catch(e){h(e instanceof Error?e.message:String(e))}}},[g,n]);return n?n===`api-key`?(0,U.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:t.composioApiKeyStored}):(0,U.jsxs)(`div`,{className:`mt-4 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`font-medium text-fg`,children:X(t.composioToolkitTitle,{toolkit:n})}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.composioScopeHint})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,U.jsxs)(`select`,{className:i(ct,`h-9 w-28 py-1`),value:u,onChange:e=>void v(e.currentTarget.value),children:[(0,U.jsx)(`option`,{value:`read`,children:t.composioScopeRead}),(0,U.jsx)(`option`,{value:`write`,children:t.composioScopeWrite}),(0,U.jsx)(`option`,{value:`admin`,children:t.composioScopeAdmin})]}),(0,U.jsxs)(R,{variant:`secondary`,disabled:f,onClick:()=>void _(),children:[f?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(y,{className:`size-4`}),t.connectOAuth]}),(0,U.jsx)(R,{variant:`ghost`,disabled:f,onClick:()=>void g(),children:t.refresh})]})]}),m?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:m}):null,(0,U.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioConnections}),r.length?r.map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel p-2`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.accountEmail??e.username??e.workspace??e.id}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.status})]},e.id)):(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioConnectionsEmpty})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioAgentTools}),o.length?o.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel p-2`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.slug}),(0,U.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[ut(e.scope,t),e.curated?``:` ${t.composioUncuratedSuffix}`]})]},e.slug)):(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioToolsEmpty})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioRecentTriggers}),c.length?c.slice(0,5).map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel p-2`,children:[(0,U.jsx)(`p`,{className:`truncate text-xs text-fg`,children:e.trigger??e.id}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:new Date(e.at).toLocaleString()})]},`${e.id}-${e.at}`)):(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioTriggersEmpty})]})]})]}):null}function ft(e,t){return e?t.healthStatusLabels[e]??e:t.healthNotTested}function pt({instance:e,onChanged:t,t:n,mcp:r}){let[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(`health`),[p,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(null),v=(0,V.useCallback)(async()=>{o(!0),_(null);try{let n=await Xe(e.instanceId);u(n),n.toolCount>0&&f(`tools`),await t()}catch(e){_(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e.instanceId,t]),b=(0,V.useCallback)(async()=>{c(!0),_(null);try{await Ye(e.instanceId),await t()}catch(e){_(e instanceof Error?e.message:String(e)),c(!1)}},[e.instanceId,t]),x=l?l.toolCount:e.usage.lastToolCount;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.displayName}),(0,U.jsx)(`span`,{className:`rounded-full border border-edge bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:n.catalogBadge})]}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.materialized.type===`mcp`?X(n.mcpServerRuntime,{serverId:e.materialized.serverId}):X(n.runtimeLabel,{runtime:e.materialized.type})})]}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[e.materialized.type===`mcp`?(0,U.jsxs)(R,{variant:`secondary`,disabled:a,onClick:()=>void v(),children:[a?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),n.test]}):null,(0,U.jsxs)(R,{variant:`ghost`,disabled:s,onClick:()=>void b(),children:[s?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(k,{className:`size-4`}),n.remove]})]})]}),g?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:g}):null,(0,U.jsx)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[[`health`,m,n.detailHealth],[`tools`,ae,`${n.detailTools} ${l?l.toolCount:e.usage.lastToolCount??``}`],[`resources`,O,`${n.detailResources} ${l?l.resourceCount:e.usage.lastResourceCount??``}`],[`prompts`,D,`${n.detailPrompts} ${l?l.promptCount:e.usage.lastPromptCount??``}`],[`permissions`,y,n.detailPermissions]].map(([e,t,n])=>(0,U.jsxs)(`button`,{type:`button`,className:i(`inline-flex h-8 items-center gap-1.5 rounded-md border px-2.5 text-xs`,d===e?`border-accent bg-accent-soft text-accent-fg`:`border-edge bg-surface-base text-fg-muted hover:text-fg`),onClick:()=>f(e),children:[(0,U.jsx)(t,{className:`size-3.5`,"aria-hidden":!0}),n]},e))}),(0,U.jsxs)(`div`,{className:`mt-3 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[d===`health`?(0,U.jsxs)(`div`,{className:`space-y-1 text-fg-muted`,children:[(0,U.jsxs)(`p`,{children:[n.statusLabel,` `,(0,U.jsx)(`span`,{className:l?.ok?`font-medium text-emerald-700 dark:text-emerald-300`:`font-medium text-fg`,children:ft(l?.status??e.usage.lastHealthStatus,n)})]}),(0,U.jsxs)(`p`,{children:[n.lastCheckLabel,` `,e.usage.lastHealthCheckAt?new Date(e.usage.lastHealthCheckAt).toLocaleString():n.never]}),l?.action?(0,U.jsx)(`p`,{children:l.action}):null]}):null,d===`tools`?l?.tools.length?(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:X(n.toolsAvailable,{count:String(l.tools.length)})}),(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>h(!0),children:r.viewAllTools})]}),l.tools.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.shortName??e.name}),e.description?(0,U.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.description}):null]},e.name))]}):(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`p`,{className:`text-fg-muted`,children:x?X(n.toolsLastCheckSummary,{count:String(x)}):n.toolsRunTestHint}),(0,U.jsxs)(R,{type:`button`,variant:`secondary`,disabled:a,onClick:()=>void v(),children:[a?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),n.test]})]}):null,d===`resources`?l?.resources.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:l.resources.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.title??e.name}),(0,U.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.uri})]},e.uri))}):(0,U.jsx)(`p`,{className:`text-fg-muted`,children:n.resourcesRunTestHint}):null,d===`prompts`?l?.prompts.length?(0,U.jsx)(`div`,{className:`grid gap-2`,children:l.prompts.slice(0,8).map(e=>(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.title??e.name}),e.description?(0,U.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.description}):null]},e.name))}):(0,U.jsx)(`p`,{className:`text-fg-muted`,children:n.promptsRunTestHint}):null,d===`permissions`?(0,U.jsxs)(`div`,{className:`space-y-1 text-fg-muted`,children:[(0,U.jsx)(`p`,{children:X(n.secretsConfigured,{count:String(Object.values(e.secretStatus).filter(Boolean).length)})}),(0,U.jsx)(`p`,{children:e.materialized.type===`mcp`?X(n.runtimeServerLabel,{runtime:e.materialized.type.toUpperCase(),serverId:e.materialized.serverId}):X(n.runtimeLabel,{runtime:e.materialized.type.toUpperCase()})}),(0,U.jsx)(`p`,{children:e.materialized.type===`mcp`?n.mcpPolicyHint:n.connectorPolicyHint})]}):null]}),e.materialized.type===`composio`?(0,U.jsx)(dt,{instance:e,t:n}):null]}),e.materialized.type===`mcp`?(0,U.jsx)(st,{open:p,onOpenChange:h,serverId:e.materialized.serverId,title:X(n.installedToolsDialogTitle,{name:e.displayName}),subtitle:n.installedToolsDialogSubtitle,searchPlaceholder:r.toolsDialogSearchPlaceholder,searchEmptyLabel:r.toolsDialogSearchEmpty,emptyLabel:n.toolsRunTestHint,closeLabel:r.toolsDialogClose,tools:l?.tools??[],stripPrefix:`${e.materialized.serverId}__`}):null]})}var mt=i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L),ht=i(mt,`min-h-28 font-mono`);function gt(e,t){return e?t.healthStatusLabels[e]??e:t.healthStatusPending}function _t(e,t){let n=t.trim();return e===`json`?n?JSON.parse(n):void 0:e===`number`?n?Number(n):void 0:e===`boolean`?n===`true`:n||void 0}function vt(e){let t={};for(let n of e.setup.secrets??[])t[n.key]=``;let n={};for(let t of e.setup.config??[])n[t.key]=t.defaultValue===void 0?``:typeof t.defaultValue==`string`?t.defaultValue:JSON.stringify(t.defaultValue,null,2);return{connector:e,secrets:t,config:n,installing:!1,error:null,result:null,health:null,oauth:{flow:null,connected:e.auth.mode!==`oauth`}}}function yt({draft:e,onChange:t,onClose:n,onInstalled:r,t:a}){let{connector:o}=e,s=e.result?`complete`:e.installing?`health`:`configure`,c=[{id:`configure`,label:a.installStepConfigure},{id:`health`,label:a.installStepHealth},{id:`complete`,label:a.installStepComplete}],l=(0,V.useCallback)(async()=>{t({...e,installing:!0,error:null});try{let n=await Ke(o.id);window.open(n.verificationUri,`_blank`,`noopener,noreferrer`),t({...e,installing:!1,error:null,oauth:{flow:n,connected:!1}})}catch(n){t({...e,installing:!1,error:n instanceof Error?n.message:String(n)})}},[o.id,e,t]),u=(0,V.useCallback)(async()=>{if(e.oauth.flow){t({...e,installing:!0,error:null});try{await qe(o.id,e.oauth.flow.deviceCode),t({...e,installing:!1,error:null,oauth:{...e.oauth,connected:!0}})}catch(n){t({...e,installing:!1,error:n instanceof Error?n.message:String(n)})}}},[o.id,e,t]),f=(0,V.useCallback)(async()=>{t({...e,installing:!0,error:null,result:null,health:null});try{if(o.auth.mode===`oauth`&&!e.oauth.connected)throw Error(a.oauthRequiredBeforeInstall);let n={};for(let t of o.setup.config??[]){let r=_t(t.type,e.config[t.key]??``);r!==void 0&&(n[t.key]=r)}let i=await Je(o.id,{secrets:e.secrets,config:n,definition:o.source===`registry`?o:void 0}),s=null;try{s=await Xe(i.instanceId)}catch{s=null}t({...e,installing:!1,result:i,health:s}),await r()}catch(n){t({...e,installing:!1,error:n instanceof Error?n.message:String(n)})}},[o,e,t,r,a.oauthRequiredBeforeInstall]);return(0,U.jsx)(g,{open:!0,onOpenChange:e=>{e||n()},children:(0,U.jsxs)(h,{children:[(0,U.jsx)(N,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,U.jsxs)(P,{className:i(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex max-h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,48rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float dark:border-edge`),children:[(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(v,{className:`text-base font-semibold text-fg`,children:X(a.installDialogTitle,{name:o.displayName})}),(0,U.jsx)(d,{className:`mt-1 line-clamp-3 text-sm text-fg-muted`,children:o.description})]}),(0,U.jsx)(_,{asChild:!0,children:(0,U.jsxs)(`button`,{type:`button`,className:i(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,re.focusRingPanel),"aria-label":a.modalClose,children:[(0,U.jsx)(ee,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,U.jsx)(`span`,{className:`sr-only`,children:a.modalClose})]})})]}),(0,U.jsxs)(`div`,{className:`min-h-0 overflow-y-auto px-6 py-5`,children:[(0,U.jsx)(`div`,{className:`mb-5 grid grid-cols-3 gap-2`,"aria-label":a.installProgressAria,children:c.map((e,t)=>{let n=c.findIndex(e=>e.id===s);return(0,U.jsxs)(`div`,{className:i(`rounded-xl border px-3 py-2 text-xs font-medium`,t===n?`border-accent bg-accent-soft text-accent-fg`:t<n?`border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900/40 dark:bg-emerald-950/40 dark:text-emerald-200`:`border-edge bg-surface-base text-fg-muted`),children:[(0,U.jsxs)(`span`,{className:`mr-1 tabular-nums`,children:[t+1,`.`]}),e.label]},e.id)})}),(0,U.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o.auth.mode===`oauth`?(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-panel p-4`,children:[(0,U.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:a.oauthTitle}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:a.oauthHint}),e.oauth.flow?(0,U.jsxs)(`div`,{className:`mt-3 rounded-xl bg-surface-base p-3 text-sm text-fg-muted`,children:[(0,U.jsx)(`p`,{children:X(a.oauthOpenCodePrefix,{url:e.oauth.flow.verificationUri})}),(0,U.jsx)(`p`,{className:`mt-2 font-mono text-lg font-semibold tracking-widest text-fg`,children:e.oauth.flow.userCode})]}):null,e.oauth.connected?(0,U.jsx)(`p`,{className:`mt-3 rounded-xl bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700`,children:a.oauthConnected}):null,(0,U.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,U.jsxs)(R,{variant:`secondary`,disabled:e.installing,onClick:()=>void l(),children:[e.installing&&!e.oauth.flow?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),a.oauthConnectButton]}),(0,U.jsxs)(R,{variant:`primary`,disabled:e.installing||!e.oauth.flow,onClick:()=>void u(),children:[e.installing&&e.oauth.flow?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(B,{className:`size-4`}),a.oauthAuthorizedButton]})]})]}):null,(o.setup.secrets??[]).map(n=>(0,U.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.label}),n.description?(0,U.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.description}):null,(0,U.jsx)(T,{value:e.secrets[n.key]??``,onChange:r=>t({...e,secrets:{...e.secrets,[n.key]:r},error:null}),labels:a.secretInputLabels,placeholder:n.required?a.requiredPlaceholder:a.optionalPlaceholder})]},n.key)),(o.setup.config??[]).map(n=>(0,U.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.label}),n.type===`json`?(0,U.jsx)(`textarea`,{className:ht,value:e.config[n.key]??``,placeholder:n.placeholder,onChange:r=>t({...e,config:{...e.config,[n.key]:r.currentTarget.value},error:null})}):(0,U.jsx)(`input`,{className:mt,value:e.config[n.key]??``,placeholder:n.placeholder,onChange:r=>t({...e,config:{...e.config,[n.key]:r.currentTarget.value},error:null})})]},n.key)),e.installing?(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-fg`,children:[(0,U.jsx)(C,{className:`size-4 animate-spin text-accent`,"aria-hidden":!0}),a.installingTitle]}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:a.installingHint})]}):null,e.error?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:e.error}):null,e.result?(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`font-medium text-fg`,children:X(a.installedAs,{target:e.result.materialized.type===`mcp`?e.result.materialized.serverId:e.result.instanceId})}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:X(a.runtimeLabel,{runtime:e.result.materialized.type.toUpperCase()})})]}),(0,U.jsx)(`span`,{className:i(`rounded-full px-2 py-0.5 text-xs font-medium`,e.health?.ok?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:e.health?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:`bg-surface-hover text-fg-muted`),children:e.health?.ok?a.healthStatusHealthy:gt(e.health?.status,a)})]}),e.health?(0,U.jsxs)(`div`,{className:`mt-3 grid gap-2 text-xs sm:grid-cols-3`,children:[(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-fg`,children:e.health.toolCount}),(0,U.jsx)(`div`,{children:a.toolsMetric})]}),(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-fg`,children:e.health.resourceCount}),(0,U.jsx)(`div`,{children:a.resourcesMetric})]}),(0,U.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`font-semibold text-fg`,children:e.health.promptCount}),(0,U.jsx)(`div`,{children:a.promptsMetric})]})]}):(0,U.jsx)(`p`,{className:`mt-3`,children:a.installedWithoutHealth}),e.health?.action?(0,U.jsx)(`p`,{className:`mt-3 text-xs text-fg-subtle`,children:e.health.action}):null]}):null]})]}),(0,U.jsx)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:(0,U.jsxs)(R,{variant:`primary`,disabled:!!e.result||e.installing||o.auth.mode===`oauth`&&!e.oauth.connected,onClick:()=>void f(),children:[e.installing?(0,U.jsx)(C,{className:`size-4 animate-spin`}):e.result?(0,U.jsx)(B,{className:`size-4`}):(0,U.jsx)(A,{className:`size-4`}),e.result?a.installedBadge:a.install]})})]})]})})}function bt(e,t){let n=e.length+1,r=`server-${n}`,i=new Set([...e.map(e=>e.id.trim()),...t]);for(;i.has(r);)n+=1,r=`server-${n}`;return Oe(r)}function xt(e,t){let n=t.trim().toLowerCase();return n?[e.displayName,e.description,e.category,e.kind,e.source,...e.tags??[]].some(e=>e.toLowerCase().includes(n)):!0}function St(e,t,n){return e.filter(e=>xt(e,t)).toSorted((e,t)=>n===`source`&&e.source!==t.source?e.source.localeCompare(t.source):e.displayName.localeCompare(t.displayName))}function Ct(e,t){let n=t.trim().toLowerCase();return n?[e.displayName,e.connectorId,e.instanceId,e.status,e.connectionStatus??``,e.materialized.type,e.materialized.type===`mcp`?e.materialized.serverId:e.materialized.id].some(e=>e.toLowerCase().includes(n)):!0}function wt(e,t){let n=t.trim().toLowerCase();return n?[e.id,e.command??``,e.url??``,e.transport].some(e=>e.toLowerCase().includes(n)):!0}function Tt(e,t,n){let r=e.key.trim();if(r)return`key:${r}`;let i=e.value.trim();return i?`value:${i}`:`empty:${n.slice(0,t).filter(e=>!e.key.trim()&&!e.value.trim()).length}`}function Et(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L)}function Dt({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:a,pasteFailed:o,keyPlaceholder:s,valuePlaceholder:c,headers:l,onChange:u}){let d=(e,t)=>{u(l.map((n,r)=>r===e?{...n,...t}:n))},f=()=>{u([...l,{key:``,value:``}])},p=e=>{let t=l.filter((t,n)=>n!==e);u(t.length>0?t:[{key:``,value:``}])},m=async()=>{try{let e=await b();if(!e){window.alert(o);return}let t=be(e);if(!t?.length){window.alert(o);return}u(t)}catch{window.alert(o)}};return(0,U.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,U.jsx)(`span`,{children:e}),t?(0,U.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),(0,U.jsxs)(R,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void m(),children:[(0,U.jsx)(j,{className:`size-3.5`,"aria-hidden":!0}),a]})]}),(0,U.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map((e,t)=>(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{className:i(Et(),`min-w-0 flex-1 font-mono text-xs`),value:e.key,placeholder:s,onChange:e=>d(t,{key:e.target.value})}),(0,U.jsx)(`input`,{className:i(Et(),`min-w-0 flex-[1.4] font-mono text-xs`),value:e.value,placeholder:c,onChange:e=>d(t,{value:e.target.value})}),(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:l.length<=1&&!e.key&&!e.value,onClick:()=>p(t),"aria-label":r,children:(0,U.jsx)(k,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})})]},Tt(e,t,l)))}),(0,U.jsxs)(`button`,{type:`button`,className:i(`self-start text-sm text-accent hover:underline`,re.press),onClick:f,children:[`+ `,n]})]})}var Ot=[`stdio`,`sse`,`streamable-http`];function Q(e){let t=(0,H.c)(11),{label:n,description:r,required:i,children:a}=e,o;t[0]===i?o=t[1]:(o=i?(0,U.jsx)(`span`,{className:`ml-0.5 text-danger`,children:`*`}):null,t[0]=i,t[1]=o);let s;t[2]!==n||t[3]!==o?(s=(0,U.jsxs)(`div`,{className:`text-sm font-medium text-fg`,children:[n,o]}),t[2]=n,t[3]=o,t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=r?(0,U.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}):null,t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==s||t[9]!==c?(l=(0,U.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[s,a,c]}),t[7]=a,t[8]=s,t[9]=c,t[10]=l):l=t[10],l}function $(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L)}function kt(e){let t=(0,H.c)(67),{row:n,t:r,onUpdate:a,idConflictMessage:o}=e,s=r.transportLabel,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=$(),t[0]=c):c=t[0];let l=n.transport,u;t[1]===a?u=t[2]:(u=e=>a({transport:e.target.value}),t[1]=a,t[2]=u);let d;t[3]===r.transportLabels?d=t[4]:(d=Ot.map(e=>(0,U.jsx)(`option`,{value:e,children:r.transportLabels[e]},e)),t[3]=r.transportLabels,t[4]=d);let f;t[5]!==n.transport||t[6]!==u||t[7]!==d?(f=(0,U.jsx)(`select`,{className:c,value:l,onChange:u,children:d}),t[5]=n.transport,t[6]=u,t[7]=d,t[8]=f):f=t[8];let p;t[9]!==r.transportLabel||t[10]!==f?(p=(0,U.jsx)(Q,{label:s,required:!0,children:f}),t[9]=r.transportLabel,t[10]=f,t[11]=p):p=t[11];let m=r.serverIdLabel,h;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(h=$(),t[12]=h):h=t[12];let g;t[13]===a?g=t[14]:(g=e=>a({id:e.target.value}),t[13]=a,t[14]=g);let _;t[15]!==n.id||t[16]!==r.serverIdPlaceholder||t[17]!==g?(_=(0,U.jsx)(`input`,{className:h,value:n.id,placeholder:r.serverIdPlaceholder,onChange:g}),t[15]=n.id,t[16]=r.serverIdPlaceholder,t[17]=g,t[18]=_):_=t[18];let v;t[19]===o?v=t[20]:(v=o?(0,U.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-300`,children:o}):null,t[19]=o,t[20]=v);let y;t[21]!==r.serverIdLabel||t[22]!==_||t[23]!==v?(y=(0,U.jsxs)(Q,{label:m,required:!0,children:[_,v]}),t[21]=r.serverIdLabel,t[22]=_,t[23]=v,t[24]=y):y=t[24];let b;t[25]!==a||t[26]!==n.argsText||t[27]!==n.command||t[28]!==n.cwd||t[29]!==n.envJson||t[30]!==n.headers||t[31]!==n.transport||t[32]!==n.url||t[33]!==r.addHeader||t[34]!==r.argsHint||t[35]!==r.argsLabel||t[36]!==r.commandLabel||t[37]!==r.cwdLabel||t[38]!==r.envHint||t[39]!==r.envLabel||t[40]!==r.headerKeyPlaceholder||t[41]!==r.headerValuePlaceholder||t[42]!==r.headersLabel||t[43]!==r.optionalSuffix||t[44]!==r.pasteHeaders||t[45]!==r.pasteHeadersFailed||t[46]!==r.removeHeader||t[47]!==r.urlLabel?(b=n.transport===`stdio`?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Q,{label:r.commandLabel,required:!0,children:(0,U.jsx)(`input`,{className:$(),value:n.command,onChange:e=>a({command:e.target.value})})}),(0,U.jsx)(Q,{label:r.argsLabel,description:r.argsHint,children:(0,U.jsx)(`input`,{className:$(),value:n.argsText,onChange:e=>a({argsText:e.target.value})})}),(0,U.jsx)(Q,{label:r.cwdLabel,children:(0,U.jsx)(`input`,{className:$(),value:n.cwd,onChange:e=>a({cwd:e.target.value})})}),(0,U.jsx)(Q,{label:r.envLabel,description:r.envHint,children:(0,U.jsx)(`textarea`,{className:i($(),`min-h-[4rem] font-mono text-xs`),value:n.envJson,onChange:e=>a({envJson:e.target.value})})})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`md:col-span-2`,children:(0,U.jsx)(Q,{label:r.urlLabel,required:!0,children:(0,U.jsx)(`input`,{className:i($(),`font-mono text-xs`),value:n.url,placeholder:`https://example.com/mcp`,onChange:e=>a({url:e.target.value})})})}),(0,U.jsx)(Dt,{label:r.headersLabel,optionalLabel:r.optionalSuffix,addLabel:r.addHeader,removeHeaderAria:r.removeHeader,pasteLabel:r.pasteHeaders,pasteFailed:r.pasteHeadersFailed,keyPlaceholder:r.headerKeyPlaceholder,valuePlaceholder:r.headerValuePlaceholder,headers:n.headers,onChange:e=>a({headers:e})})]}),t[25]=a,t[26]=n.argsText,t[27]=n.command,t[28]=n.cwd,t[29]=n.envJson,t[30]=n.headers,t[31]=n.transport,t[32]=n.url,t[33]=r.addHeader,t[34]=r.argsHint,t[35]=r.argsLabel,t[36]=r.commandLabel,t[37]=r.cwdLabel,t[38]=r.envHint,t[39]=r.envLabel,t[40]=r.headerKeyPlaceholder,t[41]=r.headerValuePlaceholder,t[42]=r.headersLabel,t[43]=r.optionalSuffix,t[44]=r.pasteHeaders,t[45]=r.pasteHeadersFailed,t[46]=r.removeHeader,t[47]=r.urlLabel,t[48]=b):b=t[48];let x=r.timeoutLabel,S=r.timeoutHint,C;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(C=$(),t[49]=C):C=t[49];let w;t[50]===n?w=t[51]:(w=Ie(n),t[50]=n,t[51]=w);let T;t[52]===a?T=t[53]:(T=e=>a({connectionTimeoutMs:Le(e.target.value)}),t[52]=a,t[53]=T);let E;t[54]!==r.timeoutPlaceholder||t[55]!==w||t[56]!==T?(E=(0,U.jsx)(`input`,{type:`number`,min:1,max:600,className:C,value:w,placeholder:r.timeoutPlaceholder,onChange:T}),t[54]=r.timeoutPlaceholder,t[55]=w,t[56]=T,t[57]=E):E=t[57];let D;t[58]!==r.timeoutHint||t[59]!==r.timeoutLabel||t[60]!==E?(D=(0,U.jsx)(Q,{label:x,description:S,children:E}),t[58]=r.timeoutHint,t[59]=r.timeoutLabel,t[60]=E,t[61]=D):D=t[61];let O;return t[62]!==y||t[63]!==b||t[64]!==D||t[65]!==p?(O=(0,U.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[p,y,b,D]}),t[62]=y,t[63]=b,t[64]=D,t[65]=p,t[66]=O):O=t[66],O}function At({open:e,mode:t,initialRow:n,existingCustomServers:r,sessionIdleTtlMinutes:a,config:o,managedServerIds:s,t:c,cs:l,onClose:u,onSaved:f}){let[p,m]=(0,V.useState)(n),[y,b]=(0,V.useState)(!1),[x,S]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)({status:`idle`}),[O,k]=(0,V.useState)(null),A=n.id.trim(),j=p.id.trim()!==A&&s.has(p.id.trim())||s.has(p.id.trim())&&t===`add`?c.reservedServerId:void 0,F=p.id.trim()&&r.some(e=>e.clientKey!==n.clientKey&&e.id.trim()===p.id.trim())?l.duplicateServerId:void 0,I=p.id.trim().length>0&&!j&&!F&&(p.transport===`stdio`?p.command.trim().length>0:p.url.trim().length>0),te=(0,V.useCallback)(async()=>{if(p.id.trim()){S(!0),T(null),D({status:`loading`});try{D({status:`ok`,tools:(await Fe(p.id.trim(),Ae(p))).tools})}catch(e){D({status:`error`,message:e instanceof Error?e.message:String(e)})}finally{S(!1)}}},[p]),L=(0,V.useCallback)(async()=>{if(!(!I||y)){b(!0),T(null);try{let e=r.filter(e=>!(t===`edit`&&e.clientKey===n.clientKey));e.push(p),await je({sessionIdleTtlMinutes:a,servers:e.sort((e,t)=>e.id.localeCompare(t.id))},Ce(o)),await f(),u()}catch(e){T(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[I,o,r,n.clientKey,t,u,f,A,p,y,a]);return e?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(g,{open:e,onOpenChange:e=>{e||u()},children:(0,U.jsxs)(h,{children:[(0,U.jsx)(N,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,U.jsxs)(P,{className:i(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,48rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float dark:border-edge`),children:[(0,U.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(v,{className:`text-base font-semibold text-fg`,children:t===`add`?l.addCustomServerTitle:l.editCustomServerTitle}),(0,U.jsx)(d,{className:`mt-1 text-sm text-fg-muted`,children:t===`add`?l.addCustomServerHint:l.editCustomServerHint})]}),(0,U.jsx)(_,{asChild:!0,children:(0,U.jsxs)(`button`,{type:`button`,className:i(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,re.focusRingPanel),"aria-label":l.modalClose,children:[(0,U.jsx)(ee,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,U.jsx)(`span`,{className:`sr-only`,children:l.modalClose})]})})]}),(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:(0,U.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,U.jsx)(kt,{row:p,t:c,onUpdate:e=>{m(t=>({...t,...e})),T(null)},idConflictMessage:j??F}),E.status===`ok`?(0,U.jsx)(`div`,{className:`rounded-xl border border-edge bg-surface-base px-3 py-2.5`,children:(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,U.jsx)(ae,{className:`size-4 text-accent`,"aria-hidden":!0}),E.tools.length===0?c.toolsEmpty:c.toolsTitle.replace(`{{count}}`,String(E.tools.length))]}),E.tools.length>0?(0,U.jsx)(R,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:()=>k(E.tools),children:c.viewAllTools}):null]})}):null,E.status===`error`?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:E.message}):null,w?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:w}):null]})}),(0,U.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,U.jsxs)(R,{variant:`secondary`,disabled:!p.id.trim()||x,onClick:()=>void te(),children:[x?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(M,{className:`size-4`}),c.testConnection]}),(0,U.jsx)(_,{asChild:!0,children:(0,U.jsx)(R,{variant:`secondary`,children:l.modalCancel})}),(0,U.jsxs)(R,{variant:`primary`,disabled:!I||y,onClick:()=>void L(),children:[y?(0,U.jsx)(C,{className:`size-4 animate-spin`}):(0,U.jsx)(B,{className:`size-4`}),y?c.saving:l.modalSave]})]})]})]})}),O?(0,U.jsx)(st,{open:!0,onOpenChange:e=>{e||k(null)},serverId:p.id,title:c.toolsDialogTitle,subtitle:c.toolsDialogSubtitle,searchPlaceholder:c.toolsDialogSearchPlaceholder,searchEmptyLabel:c.toolsDialogSearchEmpty,emptyLabel:c.toolsEmpty,closeLabel:c.toolsDialogClose,tools:O,stripPrefix:`${p.id.trim()}__`}):null]}):null}var jt=`mprov`,Mt=`smithery`,Nt=i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,L);function Pt(){let e=a(o(e=>e.language)),t=e.connectorsSettings,n=e.mcpSettings,r=s(e=>e.token),c=!!r,[l,d]=S(),f=l.get(jt)?.trim()||Mt,[m,h]=(0,V.useState)(`marketplace`),[g,_]=(0,V.useState)({catalog:[],registryCatalog:[],instances:[],registries:[],loading:!0,error:null}),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)(1),[w,T]=(0,V.useState)(void 0),[E,D]=(0,V.useState)(``),[O,k]=(0,V.useState)(f),[A,j]=(0,V.useState)(`name`),[M,N]=(0,V.useState)(null),[P,ee]=(0,V.useState)(null),[L,ne]=(0,V.useState)(void 0),[z,ie]=(0,V.useState)(!1),[ae,B]=(0,V.useState)(!1),{data:H,mutate:W}=I(c),G=H?.payload?.config,K=(0,V.useMemo)(()=>G===void 0?null:ke(G),[G]),q=K?.servers??[];(0,V.useEffect)(()=>{K&&ne(K.sessionIdleTtlMinutes)},[K]);let J=(0,V.useCallback)(async()=>{if(!r){_({catalog:[],registryCatalog:[],instances:[],registries:[],loading:!1,error:null});return}_(e=>({...e,loading:!0,error:null}));try{let[e,t,n]=await Promise.all([Be(),He(),Ve()]);_(r=>({catalog:e,registryCatalog:r.registryCatalog,instances:t,registries:n,loading:!1,error:null}))}catch(e){_({catalog:[],registryCatalog:[],instances:[],registries:[],loading:!1,error:e instanceof Error?e.message:String(e)})}},[r]);(0,V.useEffect)(()=>{J()},[J]);let be=l.toString(),xe=(0,V.useRef)(be);(0,V.useEffect)(()=>{xe.current!==be&&(xe.current=be,k(l.get(jt)?.trim()||Mt))},[l,be]);let Y=(0,V.useMemo)(()=>g.registries.map(e=>e.id),[g.registries]);(0,V.useEffect)(()=>{if(Y.length===0||Y.includes(O))return;let e=Y.includes(Mt)?Mt:Y[0];e&&k(e)},[O,Y]),(0,V.useEffect)(()=>{if(!O||O===l.get(jt))return;let e=new URLSearchParams(l);e.set(jt,O),xe.current=e.toString(),d(e,{replace:!0})},[O,l,d]);let Se=(0,V.useCallback)(async e=>{let t=E.trim(),n=e?.browse??!1,r=Math.max(e?.page??1,1),i=e?.append??!1;if(!(!c||!t&&!n)){y(!0),i?_(e=>({...e,error:null})):(x(1),T(void 0),_(e=>({...e,registryCatalog:[],error:null})));try{let e=await Ge(t,O,{browse:n,page:r});x(r),T(e.totalPages),_(t=>({...t,registryCatalog:i?[...t.registryCatalog,...e.connectors].filter((e,t,n)=>n.findIndex(t=>t.id===e.id)===t):e.connectors}))}catch(e){_(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}},[c,E,O]);(0,V.useEffect)(()=>{if(m!==`marketplace`)return;let e=window.setTimeout(()=>{E.trim()?Se():O&&Se({browse:!0})},E.trim()?350:0);return()=>window.clearTimeout(e)},[O,E,Se,g.loading,m]);let we=(0,V.useMemo)(()=>new Set(g.instances.map(e=>e.connectorId)),[g.instances]),Te=(0,V.useMemo)(()=>new Set(g.instances.flatMap(e=>e.materialized.type===`mcp`?[e.materialized.serverId]:[])),[g.instances]),Ee=(0,V.useCallback)(async e=>{if(!K||G===void 0)return;let t=q.filter(t=>t.clientKey!==e.clientKey);await je({sessionIdleTtlMinutes:K.sessionIdleTtlMinutes,servers:t},Ce(G)),await W(),await J()},[G,q,J,K,W]),De=(0,V.useCallback)(()=>{ee({mode:`add`,row:bt(q,Te)})},[q,Te]),Oe=(0,V.useCallback)(async()=>{if(!(!K||G===void 0||z)){ie(!0),B(!1);try{await je({sessionIdleTtlMinutes:L,servers:q},Ce(G)),await W(),B(!0),u({type:`success`,title:n.saved})}finally{ie(!1)}}},[G,q,K,W,L,z]),Ae=oe(e=>e.setPageHeader),Me=oe(e=>e.clearPageHeader),Ne=(0,V.useMemo)(()=>(0,U.jsx)(ye,{loading:g.loading||v,searchQuery:E,setSearchQuery:D,onReloadClick:J,onAddCustomServer:De,searchPlaceholder:m===`marketplace`?t.marketplaceSearchPlaceholder:m===`builtin`?t.builtinSearchPlaceholder:m===`user`?t.userSearchPlaceholder:t.configSearchPlaceholder,addLabel:t.addCustomServer,reloadLabel:t.reload}),[t,J,De,v,E,g.loading,m]);(0,V.useLayoutEffect)(()=>(Ae({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.title})}),end:Ne}),()=>Me()),[Me,t.title,Ne,Ae]);let Pe=g.instances.length+q.length,Fe=(0,V.useMemo)(()=>St(g.catalog.filter(e=>e.source===`builtin`),E,A),[A,E,g.catalog]),Ie=(0,V.useMemo)(()=>St(g.registryCatalog,E,A),[A,E,g.registryCatalog]),Le=m===`marketplace`&&!!(w&&b<w),Re=(0,V.useMemo)(()=>g.instances.filter(e=>Ct(e,E)),[E,g.instances]),X=(0,V.useMemo)(()=>q.filter(e=>wt(e,E)),[q,E]),Z=Re.length+X.length;return(0,U.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:(0,U.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6 sm:px-8`,children:[c?null:(0,U.jsx)(`p`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3 text-sm text-fg-muted`,children:t.tokenHint}),(0,U.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,U.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-edge-subtle pb-3 sm:flex-row sm:items-center sm:justify-between dark:border-edge-subtle`,children:[(0,U.jsx)(`div`,{className:`flex flex-wrap gap-x-1 gap-y-1`,role:`tablist`,"aria-label":t.navAria,children:[`marketplace`,`builtin`,`user`,`config`].map(e=>(0,U.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":m===e,className:i(`relative max-w-full rounded-md px-3 py-2 text-left text-sm font-medium transition-colors sm:text-center`,m===e?`text-fg after:absolute after:bottom-0 after:left-1/2 after:h-0.5 after:w-9 after:-translate-x-1/2 after:rounded-full after:bg-accent`:`text-fg-muted hover:text-fg`),onClick:()=>h(e),children:[e===`marketplace`?t.tabMarketplace:e===`builtin`?t.tabBuiltin:e===`user`?t.tabUser:t.tabConfig,e===`builtin`?(0,U.jsxs)(`span`,{className:`ml-1 tabular-nums text-fg-muted`,children:[`(`,Fe.length,`)`]}):null,e===`user`?(0,U.jsxs)(`span`,{className:`ml-1 tabular-nums text-fg-muted`,children:[`(`,Pe,`)`]}):null]},e))}),(0,U.jsxs)(`div`,{className:`flex min-h-9 min-w-0 flex-wrap items-center gap-2 sm:justify-end`,children:[m===`marketplace`?(0,U.jsx)(`div`,{className:`inline-flex h-9 max-w-full shrink-0 overflow-x-auto rounded-lg border border-edge bg-surface-panel p-0.5 shadow-surface`,role:`group`,"aria-label":t.registrySourceAria,children:g.registries.map(e=>(0,U.jsx)(`button`,{type:`button`,className:i(`shrink-0 rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors`,re.focusRingPanel,O===e.id?`bg-fg text-surface-panel dark:bg-fg dark:text-surface-base`:`text-fg-muted hover:text-fg`),"aria-pressed":O===e.id,onClick:()=>k(e.id),children:e.displayName},e.id))}):null,m!==`user`&&m!==`config`?(0,U.jsxs)(le,{children:[(0,U.jsx)(de,{asChild:!0,children:(0,U.jsxs)(`button`,{type:`button`,className:i(`inline-flex h-9 min-h-9 min-w-[9rem] shrink-0 items-center gap-1.5 rounded-lg border border-edge bg-surface-panel px-2.5 text-xs font-medium text-fg shadow-surface`,re.transition,re.focusRingPanel),children:[(0,U.jsx)(p,{className:`size-3.5 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),(0,U.jsx)(`span`,{children:A===`name`?t.sortName:t.sortSource}),(0,U.jsx)(F,{className:`size-3.5 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0})]})}),(0,U.jsx)(fe,{children:(0,U.jsxs)(pe,{className:`z-50 min-w-[10rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[(0,U.jsx)(ue,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>j(`name`),children:t.sortName}),(0,U.jsx)(ue,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>j(`source`),children:t.sortSource})]})})]}):null]})]}),g.error?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:g.error}):null,m===`user`&&c?(0,U.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.installedTitle}),(0,U.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.installedHint})]}),g.loading?(0,U.jsx)(`div`,{className:`grid gap-3`,"aria-busy":`true`,"aria-label":t.loading,children:me.slice(0,3).map(e=>(0,U.jsx)(_e,{},e))}):Pe===0||Z===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:Pe===0?t.installedEmpty:t.userEmpty}):(0,U.jsxs)(`div`,{className:`grid gap-3`,children:[Re.map(e=>(0,U.jsx)(pt,{instance:e,onChanged:J,t,mcp:n},e.instanceId)),X.map(e=>(0,U.jsx)(ze,{row:e,t:n,cs:t,onEdit:()=>ee({mode:`edit`,row:structuredClone(e)}),onRemove:async()=>Ee(e)},e.clientKey))]}),(0,U.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.disableHint})]}):null,m===`config`&&c?(0,U.jsx)(`div`,{className:`flex flex-col gap-4`,children:(0,U.jsxs)(ce,{children:[(0,U.jsx)(se,{icon:te,title:n.globalTitle,subtitle:n.globalHint}),(0,U.jsx)(`div`,{className:`max-w-xl`,children:(0,U.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,U.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.idleTtlLabel}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`input`,{type:`number`,min:0,className:i(Nt,`w-40 flex-none`),value:L??``,placeholder:n.idleTtlPlaceholder,onChange:e=>{let t=e.target.value.trim();ne(t===``?void 0:Number.parseInt(t,10)),B(!1)}}),(0,U.jsxs)(R,{variant:`secondary`,disabled:z,onClick:()=>void Oe(),children:[z?(0,U.jsx)(C,{className:`size-4 animate-spin`}):null,n.save]})]}),(0,U.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.idleTtlHint})]})})]})}):null,m===`marketplace`&&c?(0,U.jsx)(`div`,{className:`flex flex-col gap-4`,children:v&&Ie.length===0?(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":t.loading,children:me.map(e=>(0,U.jsx)(ge,{},e))}):E.trim()&&Ie.length===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.marketplaceEmpty}):!E.trim()&&Ie.length===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.marketplaceStartHint}):(0,U.jsxs)(`div`,{className:`relative`,children:[v?(0,U.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[1] flex justify-center bg-surface-panel/40 pt-[min(28vh,7.5rem)] backdrop-blur-[1px] motion-reduce:backdrop-blur-none dark:bg-surface-base/35`,"aria-busy":`true`,"aria-label":t.loading,children:(0,U.jsx)(C,{className:`size-8 shrink-0 animate-spin text-accent motion-reduce:animate-none`,strokeWidth:2,"aria-hidden":!0})}):null,(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:Ie.map(e=>(0,U.jsx)(ve,{connector:e,installed:we.has(e.id)||he(e,g.instances),onInstall:e=>N(vt(e)),t},e.id))}),Le?(0,U.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,U.jsxs)(R,{type:`button`,variant:`secondary`,disabled:v,onClick:()=>void Se({browse:!E.trim(),page:b+1,append:!0}),children:[v?(0,U.jsx)(C,{className:`size-4 animate-spin`}):null,t.loadMore]})}):null]})}):null,m===`builtin`&&c?(0,U.jsx)(`div`,{className:`flex flex-col gap-4`,children:g.loading?(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":t.loading,children:me.map(e=>(0,U.jsx)(ge,{},e))}):Fe.length===0?(0,U.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.builtinEmpty}):(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:Fe.map(e=>(0,U.jsx)(ve,{connector:e,installed:we.has(e.id)||he(e,g.instances),onInstall:e=>N(vt(e)),t},e.id))})}):null]}),M?(0,U.jsx)(yt,{draft:M,onChange:N,onClose:()=>N(null),t,onInstalled:async()=>{await J(),await W(),h(`user`)}}):null,P?(0,U.jsx)(At,{open:!0,mode:P.mode,initialRow:P.row,existingCustomServers:q,sessionIdleTtlMinutes:L,config:G,managedServerIds:Te,t:n,cs:t,onClose:()=>ee(null),onSaved:async()=>{await W(),await J(),h(`user`)}},`${P.mode}-${P.row.clientKey}`):null]})})}export{Pt as ConnectorsPage};
|
|
@@ -0,0 +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-CISb1HLv.js";import{n as o}from"./locale-store-Ba72bFmP.js";import{c as s,i as c,n as l}from"./fetch-B3ME5Eri.js";import{i as u}from"./vendor-swr-BIWyz7Rc.js";import{Ba as d,Ga as f,Io as p,Ks as m,Na as h,Qs as g,So as _,Ta as v,Ya as y,ba as b,ct as x,po as S,ra as C,ro as w,sa as T,ti as E,ua as D,xo as O}from"./index-CnjzMw5i.js";import{n as k,t as A}from"./settings-form-section-DBkGwpIN.js";import{i as j,n as M,r as N,t as ee}from"./settings-page-layout-NxoW5Y57.js";import{n as P,t as F}from"./schedule-field-pRheF2CO.js";import{t as I}from"./format-cron-label-arqgGlVV.js";var L=e(t(),1),R=n();function z(){return c(`/api/dreaming`)}async function te(){let e=await l(z());if(!e.payload)throw Error(`Missing payload`);return e.payload}async function ne(e){await l(c(`/api/dreaming/action`),{method:`POST`,body:JSON.stringify({action:e})})}async function re(e=`deep`){let t=await l(c(`/api/dreaming/run`),{method:`POST`,body:JSON.stringify({phase:e})});if(t.ok===!1||!t.payload)throw Error(`Failed to run dreaming phase`);let n=t.payload.phase;return{phase:n===`light`||n===`deep`||n===`rem`?n:e,result:t.payload.result}}async function ie(e){let t=await l(c(`/api/dreaming/preview${typeof e==`number`&&Number.isFinite(e)?`?limit=${encodeURIComponent(String(e))}`:``}`));if(!t.payload)throw Error(`Missing payload`);return t.payload}async function ae(e=50){return(await l(c(`/api/dreaming/events${`?limit=${encodeURIComponent(String(e))}`}`))).payload?.events??[]}function B(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var V={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},H={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},U={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},W={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:V,deep:H,rem:U};function G(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function K(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function q(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function oe(e){let t=B(e)?e:{},n=B(t.memory)?t.memory:{},r=B(t.dreaming)?t.dreaming:{},i=typeof t.enabled==`boolean`||typeof t.frequency==`string`||B(t.phases)?t:{},a=B(n.dreaming)?n.dreaming:Object.keys(r).length>0?r:i,o=B(a.phases)?a.phases:{},s=B(o.light)?o.light:{},c=B(o.deep)?o.deep:{},l=B(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():W.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:G(typeof c.minScore==`number`?c.minScore:Number(c.minScore),W.minScore),minRecallCount:Math.max(1,K(c.minRecallCount,W.minRecallCount)),limit:K(c.limit,W.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():V.cron,lookbackDays:Math.max(1,K(s.lookbackDays,V.lookbackDays)),limit:K(s.limit,V.limit),dedupeSimilarity:G(q(s.dedupeSimilarity,V.dedupeSimilarity),V.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():H.cron,minScore:G(q(c.minScore,H.minScore),H.minScore),minRecallCount:Math.max(1,K(c.minRecallCount,H.minRecallCount)),limit:K(c.limit,H.limit),recencyHalfLifeDays:Math.max(1,q(c.recencyHalfLifeDays,H.recencyHalfLifeDays)),maxAgeDays:Math.max(1,q(c.maxAgeDays,H.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():U.cron,lookbackDays:Math.max(1,K(l.lookbackDays,U.lookbackDays)),limit:K(l.limit,U.limit),minPatternStrength:G(q(l.minPatternStrength,U.minPatternStrength),U.minPatternStrength)}}}async function se(e,t,n){let r=t.frequency.trim(),i=t.timezone.trim();await l(c(`/api/agents/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify({memory:{...n??{},mode:t.enabled?`confirmWrite`:typeof n?.mode==`string`?n.mode:`off`,sources:Array.isArray(n?.sources)?n.sources:[`session`,`curated`,`workspace`],writePolicy:B(n?.writePolicy)?n.writePolicy:{curated:`confirm`,workspace:`confirm`},dreaming:{enabled:!!t.enabled,...r?{frequency:r}:{},...i?{timezone:i}:{},phases:{light:{enabled:!!t.light.enabled,...t.light.cron.trim()?{cron:t.light.cron.trim()}:{},lookbackDays:Math.max(1,Math.floor(t.light.lookbackDays)),limit:Math.max(0,Math.floor(t.light.limit)),dedupeSimilarity:G(t.light.dedupeSimilarity,V.dedupeSimilarity)},deep:{enabled:!!t.deep.enabled,...t.deep.cron.trim()?{cron:t.deep.cron.trim()}:{},minScore:G(t.deep.minScore,H.minScore),minRecallCount:Math.max(1,Math.floor(t.deep.minRecallCount)),limit:Math.max(0,Math.floor(t.deep.limit)),recencyHalfLifeDays:Math.max(1,t.deep.recencyHalfLifeDays),maxAgeDays:Math.max(1,t.deep.maxAgeDays)},rem:{enabled:!!t.rem.enabled,...t.rem.cron.trim()?{cron:t.rem.cron.trim()}:{},lookbackDays:Math.max(1,Math.floor(t.rem.lookbackDays)),limit:Math.max(0,Math.floor(t.rem.limit)),minPatternStrength:G(t.rem.minPatternStrength,U.minPatternStrength)}}}}})}),E()}var ce=`p-4 sm:px-5`,le=`mb-3`,J=`rounded-xl border border-edge-subtle bg-surface-panel/30 p-3 sm:p-4`,Y=i(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,C);function ue(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function X(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function de(e,t){return e.locked?{text:t.lockValueLocked,className:`text-amber-600 dark:text-amber-400`}:{text:t.lockValueUnlocked,className:`text-emerald-600 dark:text-emerald-400`}}var Z=r(),fe=`text-xs font-medium text-fg-muted`,pe=`text-sm font-medium text-fg`;function Q(e){let t=(0,R.c)(6),{label:n,children:r,className:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.jsx)(`span`,{className:fe,children:n}),t[0]=n,t[1]=a);let o;return t[2]!==r||t[3]!==i||t[4]!==a?(o=(0,Z.jsxs)(`div`,{className:i,children:[a,r]}),t[2]=r,t[3]=i,t[4]=a,t[5]=o):o=t[5],o}function $(e){let t=(0,R.c)(11),{label:n,children:r,className:a}=e,o;t[0]===a?o=t[1]:(o=i(`min-w-0`,a),t[0]=a,t[1]=o);let s;t[2]===n?s=t[3]:(s=(0,Z.jsx)(`dt`,{className:fe,children:n}),t[2]=n,t[3]=s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=i(pe,`mt-0.5`),t[4]=c):c=t[4];let l;t[5]===r?l=t[6]:(l=(0,Z.jsx)(`dd`,{className:c,children:r}),t[5]=r,t[6]=l);let u;return t[7]!==o||t[8]!==s||t[9]!==l?(u=(0,Z.jsxs)(`div`,{className:o,children:[s,l]}),t[7]=o,t[8]=s,t[9]=l,t[10]=u):u=t[10],u}function me(e){let t=(0,R.c)(5),{label:n,className:r}=e,a;t[0]===r?a=t[1]:(a=i(`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,r),t[0]=r,t[1]=a);let o;return t[2]!==n||t[3]!==a?(o=(0,Z.jsx)(`h3`,{className:a,children:n}),t[2]=n,t[3]=a,t[4]=o):o=t[4],o}function he(e){let t=(0,R.c)(39),{icon:n,title:r,hint:i,enabled:a,onEnabledChange:o,cron:s,onCronChange:c,scheduleLabels:l,disabled:u,showEnabledControl:d,actions:f,status:p,enabledLabel:m,onLabel:h,offLabel:g,cronLabel:_,children:v}=e,y=d===void 0?!0:d,b;t[0]===n?b=t[1]:(b=(0,Z.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:n}),t[0]=n,t[1]=b);let x;t[2]===r?x=t[3]:(x=(0,Z.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=x);let S;t[4]!==p||t[5]!==x?(S=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[x,p]}),t[4]=p,t[5]=x,t[6]=S):S=t[6];let C;t[7]===i?C=t[8]:(C=(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs leading-snug text-fg-muted`,children:i}),t[7]=i,t[8]=C);let w;t[9]!==S||t[10]!==C?(w=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[S,C]}),t[9]=S,t[10]=C,t[11]=w):w=t[11];let T;t[12]!==b||t[13]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[b,w]}),t[12]=b,t[13]=w,t[14]=T):T=t[14];let E;t[15]!==f||t[16]!==u||t[17]!==a||t[18]!==m||t[19]!==g||t[20]!==o||t[21]!==h||t[22]!==y?(E=f||y?(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[f,y?(0,Z.jsxs)(`label`,{className:`inline-flex shrink-0 items-center gap-2 text-xs text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:a,disabled:u,onChange:e=>o(e.target.checked)}),(0,Z.jsx)(`span`,{children:m??(a?h:g)})]}):null]}):null,t[15]=f,t[16]=u,t[17]=a,t[18]=m,t[19]=g,t[20]=o,t[21]=h,t[22]=y,t[23]=E):E=t[23];let D;t[24]!==T||t[25]!==E?(D=(0,Z.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-start justify-between gap-2 border-b border-edge-subtle/80 pb-2.5`,children:[T,E]}),t[24]=T,t[25]=E,t[26]=D):D=t[26];let O;t[27]!==s||t[28]!==_||t[29]!==u||t[30]!==c||t[31]!==l?(O=(0,Z.jsx)(F,{kind:`cron`,className:`mb-2.5`,label:_,value:s,onChange:c,labels:l,disabled:u}),t[27]=s,t[28]=_,t[29]=u,t[30]=c,t[31]=l,t[32]=O):O=t[32];let k;t[33]===v?k=t[34]:(k=(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4`,children:v}),t[33]=v,t[34]=k);let A;return t[35]!==O||t[36]!==k||t[37]!==D?(A=(0,Z.jsxs)(`div`,{className:J,children:[D,O,k]}),t[35]=O,t[36]=k,t[37]=D,t[38]=A):A=t[38],A}function ge(e){let t=(0,R.c)(23),{icon:n,label:r,enabled:a,cron:o,scheduleSummary:s,details:c,t:l}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=i(J,`space-y-1`),t[0]=u):u=t[0];let d;t[1]===r?d=t[2]:(d=(0,Z.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r}),t[1]=r,t[2]=d);let f=a?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`,p;t[3]===f?p=t[4]:(p=i(`ml-auto text-xs font-medium`,f),t[3]=f,t[4]=p);let m=a?l.on:l.off,h;t[5]!==p||t[6]!==m?(h=(0,Z.jsx)(`span`,{className:p,children:m}),t[5]=p,t[6]=m,t[7]=h):h=t[7];let g;t[8]!==n||t[9]!==d||t[10]!==h?(g=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,d,h]}),t[8]=n,t[9]=d,t[10]=h,t[11]=g):g=t[11];let _;t[12]===s?_=t[13]:(_=(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:s}),t[12]=s,t[13]=_);let v;t[14]===o?v=t[15]:(v=(0,Z.jsx)(`p`,{className:`truncate font-mono text-[0.65rem] text-fg-subtle`,title:o,children:o}),t[14]=o,t[15]=v);let y;t[16]===c?y=t[17]:(y=(0,Z.jsx)(`p`,{className:`text-[0.65rem] leading-snug text-fg-muted`,children:c}),t[16]=c,t[17]=y);let b;return t[18]!==y||t[19]!==g||t[20]!==_||t[21]!==v?(b=(0,Z.jsxs)(`div`,{className:u,children:[g,_,v,y]}),t[18]=y,t[19]=g,t[20]=_,t[21]=v,t[22]=b):b=t[22],b}function _e(e){let t=(0,R.c)(9),{label:n,lastRun:r,t:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.jsx)(me,{label:n,className:`mb-2`}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==i.lastRunRaw||t[4]!==i.phaseLastRunEmpty?(o=r?.exists?(0,Z.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Z.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:i.lastRunRaw})}),(0,Z.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.raw,null,2)})]}):(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.phaseLastRunEmpty}),t[2]=r,t[3]=i.lastRunRaw,t[4]=i.phaseLastRunEmpty,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,Z.jsxs)(`div`,{className:`border-t border-edge-subtle/80 pt-3`,children:[a,o]}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s}function ve(e){let t=(0,R.c)(39),{t:n,r}=e,i=r.deep?.skipped,a=r.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`,o=r.ok?n.lastRunSuccess:n.lastRunFailure,s;t[0]!==a||t[1]!==o?(s=(0,Z.jsx)(`span`,{className:a,children:o}),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c;t[3]!==n.lastRunStatus||t[4]!==s?(c=(0,Z.jsx)($,{label:n.lastRunStatus,children:s}),t[3]=n.lastRunStatus,t[4]=s,t[5]=c):c=t[5];let l=n.lastRunDuration,u;t[6]===r.durationMs?u=t[7]:(u=X(r.durationMs),t[6]=r.durationMs,t[7]=u);let d;t[8]!==n.lastRunDuration||t[9]!==u?(d=(0,Z.jsx)($,{label:l,children:u}),t[8]=n.lastRunDuration,t[9]=u,t[10]=d):d=t[10];let f=n.lastRunRanked,p=String(r.deep?.candidatesRanked??`—`),m;t[11]!==n.lastRunRanked||t[12]!==p?(m=(0,Z.jsx)($,{label:f,children:p}),t[11]=n.lastRunRanked,t[12]=p,t[13]=m):m=t[13];let h=n.lastRunApplied,g=String(r.deep?.applied??`—`),_;t[14]!==n.lastRunApplied||t[15]!==g?(_=(0,Z.jsx)($,{label:h,children:g}),t[14]=n.lastRunApplied,t[15]=g,t[16]=_):_=t[16];let v;t[17]===r.reason?v=t[18]:(v=(0,Z.jsx)(`span`,{className:`block text-pretty`,children:r.reason}),t[17]=r.reason,t[18]=v);let y;t[19]!==r.errorMessage||t[20]!==n.lastRunError?(y=r.errorMessage?(0,Z.jsx)(`span`,{className:`mt-1 block text-xs text-amber-600 dark:text-amber-400`,children:`${n.lastRunError}: ${r.errorMessage}`}):null,t[19]=r.errorMessage,t[20]=n.lastRunError,t[21]=y):y=t[21];let b;t[22]!==n.lastRunReason||t[23]!==v||t[24]!==y?(b=(0,Z.jsxs)($,{label:n.lastRunReason,className:`col-span-2 sm:col-span-3 lg:col-span-4`,children:[v,y]}),t[22]=n.lastRunReason,t[23]=v,t[24]=y,t[25]=b):b=t[25];let x;t[26]!==i||t[27]!==n.lastRunSkipContaminated||t[28]!==n.lastRunSkipHash||t[29]!==n.lastRunSkipKey||t[30]!==n.lastRunSkipRehydrate?(x=i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($,{label:n.lastRunSkipKey,children:String(i.alreadyPromotedKey)}),(0,Z.jsx)($,{label:n.lastRunSkipRehydrate,children:String(i.rehydrateFailed)}),(0,Z.jsx)($,{label:n.lastRunSkipContaminated,children:String(i.contaminated)}),(0,Z.jsx)($,{label:n.lastRunSkipHash,children:String(i.hashDuplicate)})]}):null,t[26]=i,t[27]=n.lastRunSkipContaminated,t[28]=n.lastRunSkipHash,t[29]=n.lastRunSkipKey,t[30]=n.lastRunSkipRehydrate,t[31]=x):x=t[31];let S;return t[32]!==m||t[33]!==_||t[34]!==b||t[35]!==x||t[36]!==c||t[37]!==d?(S=(0,Z.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-3 lg:grid-cols-4`,children:[c,d,m,_,b,x]}),t[32]=m,t[33]=_,t[34]=b,t[35]=x,t[36]=c,t[37]=d,t[38]=S):S=t[38],S}function ye(e){let t=(0,R.c)(56),{t:n,schedulePickerLabels:r,hasToken:a,cfgForm:o,cfgBaseline:s,cfgDirty:c,cfgSaving:l,runPhase:u,setRunPhase:d,runBusy:f,setCfgForm:m,doRunNow:g}=e,_;t[0]!==c||t[1]!==o?.enabled||t[2]!==l||t[3]!==g||t[4]!==a||t[5]!==f||t[6]!==u||t[7]!==d||t[8]!==n?(_=(e,t)=>o?.enabled?(0,Z.jsx)(Se,{t:n,busy:f&&u===e,disabled:!a||l||f||!t||c,title:c?n.runNowSaveFirstHint:n.runNowHint,onClick:()=>{d(e),g(e)}}):null,t[0]=c,t[1]=o?.enabled,t[2]=l,t[3]=g,t[4]=a,t[5]=f,t[6]=u,t[7]=d,t[8]=n,t[9]=_):_=t[9];let y=_,b;t[10]!==s||t[11]!==o||t[12]!==n.phasePendingSave||t[13]!==n.phaseWillDisable||t[14]!==n.phaseWillEnable?(b=e=>{if(!o||!s)return null;let t=o[e],r=s[e];return JSON.stringify(t)===JSON.stringify(r)?null:t.enabled===r.enabled?n.phasePendingSave:t.enabled?n.phaseWillEnable:n.phaseWillDisable},t[10]=s,t[11]=o,t[12]=n.phasePendingSave,t[13]=n.phaseWillDisable,t[14]=n.phaseWillEnable,t[15]=b):b=t[15];let x=b,C;return t[16]!==c||t[17]!==o||t[18]!==l||t[19]!==a||t[20]!==x||t[21]!==y||t[22]!==r||t[23]!==m||t[24]!==n.configDeepHalfLife||t[25]!==n.configDeepLimit||t[26]!==n.configDeepMaxAge||t[27]!==n.configDeepMinRecallCount||t[28]!==n.configDeepMinScore||t[29]!==n.configFrequency||t[30]!==n.configLightDedupe||t[31]!==n.configLightLimit||t[32]!==n.configLightLookbackDays||t[33]!==n.configLoading||t[34]!==n.configPhaseCron||t[35]!==n.configPhaseDeep||t[36]!==n.configPhaseDeepHint||t[37]!==n.configPhaseLight||t[38]!==n.configPhaseLightHint||t[39]!==n.configPhaseRem||t[40]!==n.configPhaseRemHint||t[41]!==n.configRemLimit||t[42]!==n.configRemLookbackDays||t[43]!==n.configRemMinStrength||t[44]!==n.configTimezone||t[45]!==n.masterHint||t[46]!==n.masterOff||t[47]!==n.masterOn||t[48]!==n.masterTitle||t[49]!==n.off||t[50]!==n.on||t[51]!==n.phasesTitle||t[52]!==n.scheduleTitle||t[53]!==n.unsavedConfigHint||t[54]!==n.unsavedConfigTitle?(C=(0,Z.jsx)(A,{className:`min-w-0 !p-0`,children:o?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:i(J,`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`),children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.masterTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.masterHint})]}),(0,Z.jsxs)(`label`,{className:i(`inline-flex w-fit cursor-pointer items-center gap-2 rounded-xl border px-3 py-1.5 text-sm transition-colors`,o.enabled?`border-emerald-500/30 bg-emerald-500/5 text-fg`:`border-edge-subtle bg-surface-panel/50 text-fg-muted`),children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:o.enabled,disabled:!a||l,onChange:e=>m(t=>t&&{...t,enabled:e.target.checked})}),(0,Z.jsx)(`span`,{className:i(`text-xs font-semibold`,o.enabled?`text-emerald-600 dark:text-emerald-400`:``),children:o.enabled?n.masterOn:n.masterOff})]})]}),c?(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 rounded-xl border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-xs text-amber-900 dark:text-amber-100`,children:[(0,Z.jsx)(p,{className:`mt-0.5 size-3.5 shrink-0`,"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-semibold`,children:n.unsavedConfigTitle}),(0,Z.jsx)(`p`,{className:`mt-0.5 leading-snug text-amber-800/90 dark:text-amber-100/80`,children:n.unsavedConfigHint})]})]}):null,(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(be,{title:n.scheduleTitle}),(0,Z.jsx)(`div`,{className:J,children:(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-12`,children:[(0,Z.jsx)(`div`,{className:`lg:col-span-9`,children:(0,Z.jsx)(F,{kind:`cron`,label:n.configFrequency,value:o.frequency,onChange:e=>m(t=>t&&{...t,frequency:e}),labels:r,disabled:!a||l})}),(0,Z.jsx)(Q,{label:n.configTimezone,className:`lg:col-span-3`,children:(0,Z.jsx)(`input`,{className:Y,value:o.timezone,disabled:!a||l,onChange:e=>m(t=>t&&{...t,timezone:e.target.value}),placeholder:`Asia/Shanghai`})})]})})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(be,{title:n.phasesTitle}),(0,Z.jsxs)(he,{icon:(0,Z.jsx)(v,{className:`size-4 text-amber-500`}),title:n.configPhaseLight,hint:n.configPhaseLightHint,enabled:o.light.enabled,onEnabledChange:e=>m(t=>t&&{...t,light:{...t.light,enabled:e}}),cron:o.light.cron,onCronChange:e=>m(t=>t&&{...t,light:{...t.light,cron:e}}),scheduleLabels:r,disabled:!a||l,showEnabledControl:o.enabled,actions:y(`light`,o.light.enabled),status:x(`light`)?(0,Z.jsx)(xe,{label:x(`light`)??``}):null,enabledLabel:x(`light`)??void 0,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,Z.jsx)(Q,{label:n.configLightLookbackDays,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Y,value:o.light.lookbackDays,disabled:!a||l,onChange:e=>m(t=>t&&{...t,light:{...t.light,lookbackDays:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configLightLimit,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:0,className:Y,value:o.light.limit,disabled:!a||l,onChange:e=>m(t=>t&&{...t,light:{...t.light,limit:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configLightDedupe,children:(0,Z.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:Y,value:o.light.dedupeSimilarity,disabled:!a||l,onChange:e=>m(t=>t&&{...t,light:{...t.light,dedupeSimilarity:Number(e.target.value)}})})})]}),(0,Z.jsxs)(he,{icon:(0,Z.jsx)(S,{className:`size-4 text-indigo-500`}),title:n.configPhaseDeep,hint:n.configPhaseDeepHint,enabled:o.deep.enabled,onEnabledChange:e=>m(t=>t&&{...t,deep:{...t.deep,enabled:e}}),cron:o.deep.cron,onCronChange:e=>m(t=>t&&{...t,deep:{...t.deep,cron:e}}),scheduleLabels:r,disabled:!a||l,showEnabledControl:o.enabled,actions:y(`deep`,o.deep.enabled),status:x(`deep`)?(0,Z.jsx)(xe,{label:x(`deep`)??``}):null,enabledLabel:x(`deep`)??void 0,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,Z.jsx)(Q,{label:n.configDeepMinScore,children:(0,Z.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:Y,value:o.deep.minScore,disabled:!a||l,onChange:e=>m(t=>t&&{...t,deep:{...t.deep,minScore:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configDeepMinRecallCount,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Y,value:o.deep.minRecallCount,disabled:!a||l,onChange:e=>m(t=>t&&{...t,deep:{...t.deep,minRecallCount:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configDeepLimit,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:0,className:Y,value:o.deep.limit,disabled:!a||l,onChange:e=>m(t=>t&&{...t,deep:{...t.deep,limit:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configDeepHalfLife,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Y,value:o.deep.recencyHalfLifeDays,disabled:!a||l,onChange:e=>m(t=>t&&{...t,deep:{...t.deep,recencyHalfLifeDays:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configDeepMaxAge,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Y,value:o.deep.maxAgeDays,disabled:!a||l,onChange:e=>m(t=>t&&{...t,deep:{...t.deep,maxAgeDays:Number(e.target.value)}})})})]}),(0,Z.jsxs)(he,{icon:(0,Z.jsx)(h,{className:`size-4 text-purple-500`}),title:n.configPhaseRem,hint:n.configPhaseRemHint,enabled:o.rem.enabled,onEnabledChange:e=>m(t=>t&&{...t,rem:{...t.rem,enabled:e}}),cron:o.rem.cron,onCronChange:e=>m(t=>t&&{...t,rem:{...t.rem,cron:e}}),scheduleLabels:r,disabled:!a||l,showEnabledControl:o.enabled,actions:y(`rem`,o.rem.enabled),status:x(`rem`)?(0,Z.jsx)(xe,{label:x(`rem`)??``}):null,enabledLabel:x(`rem`)??void 0,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,Z.jsx)(Q,{label:n.configRemLookbackDays,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Y,value:o.rem.lookbackDays,disabled:!a||l,onChange:e=>m(t=>t&&{...t,rem:{...t.rem,lookbackDays:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configRemLimit,children:(0,Z.jsx)(`input`,{type:`number`,step:`1`,min:0,className:Y,value:o.rem.limit,disabled:!a||l,onChange:e=>m(t=>t&&{...t,rem:{...t.rem,limit:Number(e.target.value)}})})}),(0,Z.jsx)(Q,{label:n.configRemMinStrength,children:(0,Z.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:Y,value:o.rem.minPatternStrength,disabled:!a||l,onChange:e=>m(t=>t&&{...t,rem:{...t.rem,minPatternStrength:Number(e.target.value)}})})})]})]})]}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.configLoading})}),t[16]=c,t[17]=o,t[18]=l,t[19]=a,t[20]=x,t[21]=y,t[22]=r,t[23]=m,t[24]=n.configDeepHalfLife,t[25]=n.configDeepLimit,t[26]=n.configDeepMaxAge,t[27]=n.configDeepMinRecallCount,t[28]=n.configDeepMinScore,t[29]=n.configFrequency,t[30]=n.configLightDedupe,t[31]=n.configLightLimit,t[32]=n.configLightLookbackDays,t[33]=n.configLoading,t[34]=n.configPhaseCron,t[35]=n.configPhaseDeep,t[36]=n.configPhaseDeepHint,t[37]=n.configPhaseLight,t[38]=n.configPhaseLightHint,t[39]=n.configPhaseRem,t[40]=n.configPhaseRemHint,t[41]=n.configRemLimit,t[42]=n.configRemLookbackDays,t[43]=n.configRemMinStrength,t[44]=n.configTimezone,t[45]=n.masterHint,t[46]=n.masterOff,t[47]=n.masterOn,t[48]=n.masterTitle,t[49]=n.off,t[50]=n.on,t[51]=n.phasesTitle,t[52]=n.scheduleTitle,t[53]=n.unsavedConfigHint,t[54]=n.unsavedConfigTitle,t[55]=C):C=t[55],C}function be(e){let t=(0,R.c)(2),{title:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Z.jsx)(`div`,{className:`px-0.5 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n}),t[0]=n,t[1]=r),r}function xe(e){let t=(0,R.c)(2),{label:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Z.jsx)(`span`,{className:`inline-flex shrink-0 rounded-md border border-amber-500/25 bg-amber-500/10 px-1.5 py-0.5 text-[0.65rem] font-semibold text-amber-800 dark:text-amber-200`,children:n}),t[0]=n,t[1]=r),r}function Se(e){let t=(0,R.c)(8),{t:n,busy:r,disabled:i,title:a,onClick:o}=e,s;t[0]===r?s=t[1]:(s=r?(0,Z.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(w,{className:`size-3.5`,"aria-hidden":!0}),t[0]=r,t[1]=s);let c;return t[2]!==i||t[3]!==o||t[4]!==n.runNow||t[5]!==s||t[6]!==a?(c=(0,Z.jsxs)(T,{type:`button`,variant:`secondary`,className:`h-7 gap-1.5 rounded-lg px-2 text-xs`,disabled:i,title:a,onClick:o,children:[s,n.runNow]}),t[2]=i,t[3]=o,t[4]=n.runNow,t[5]=s,t[6]=a,t[7]=c):c=t[7],c}function Ce(e){let t=(0,R.c)(20),{t:n,hasToken:r,eventsLoading:i,events:a,loadEvents:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,Z.jsx)(_,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.eventsLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,Z.jsxs)(T,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.eventsLoad]}),t[4]=n.eventsLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.eventsHint||t[10]!==n.eventsTitle||t[11]!==u?(d=(0,Z.jsx)(k,{className:le,icon:m,title:n.eventsTitle,subtitle:n.eventsHint,trailing:u}),t[9]=n.eventsHint,t[10]=n.eventsTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.eventsEmpty||t[15]!==n.eventsNotLoaded?(f=a?a.length>0?(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:a.map(we)}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsEmpty}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsNotLoaded}),t[13]=a,t[14]=n.eventsEmpty,t[15]=n.eventsNotLoaded,t[16]=f):f=t[16];let p;return t[17]!==d||t[18]!==f?(p=(0,Z.jsxs)(A,{className:ce,children:[d,f]}),t[17]=d,t[18]=f,t[19]=p):p=t[19],p}function we(e){let t=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,n=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,Z.jsx)(`span`,{children:t}),(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Z.jsx)(`span`,{className:i(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Z.jsx)(`span`,{className:`text-fg-muted`,children:n}),(0,Z.jsx)(`span`,{className:`text-fg-muted`,children:X(e.durationMs)}),(0,Z.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:ue(e.timestamp)})]},`${e.timestamp}:${e.phase}`)}function Te(e){let t=(0,R.c)(23),{t:n,hasToken:r,cfgForm:i,cfgSaving:a,cfgDirty:o,saveConfig:s,doRefresh:c}=e,l=!r||!i||a||!o,u;t[0]===s?u=t[1]:(u=()=>void s(),t[0]=s,t[1]=u);let d;t[2]===a?d=t[3]:(d=a?(0,Z.jsx)(_,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=a,t[3]=d);let f;t[4]!==n.saveConfig||t[5]!==l||t[6]!==u||t[7]!==d?(f=(0,Z.jsxs)(T,{type:`button`,variant:`primary`,disabled:l,onClick:u,children:[d,n.saveConfig]}),t[4]=n.saveConfig,t[5]=l,t[6]=u,t[7]=d,t[8]=f):f=t[8];let p=!r,m;t[9]===c?m=t[10]:(m=()=>void c(),t[9]=c,t[10]=m);let h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsx)(y,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[11]=h):h=t[11];let g;t[12]!==n.refresh||t[13]!==p||t[14]!==m?(g=(0,Z.jsx)(T,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,disabled:p,title:n.refresh,"aria-label":n.refresh,onClick:m,children:h}),t[12]=n.refresh,t[13]=p,t[14]=m,t[15]=g):g=t[15];let v;t[16]!==f||t[17]!==g?(v=(0,Z.jsxs)(Z.Fragment,{children:[f,g]}),t[16]=f,t[17]=g,t[18]=v):v=t[18];let b;return t[19]!==n.subtitle||t[20]!==n.title||t[21]!==v?(b=(0,Z.jsx)(M,{title:n.title,subtitle:n.subtitle,actions:v}),t[19]=n.subtitle,t[20]=n.title,t[21]=v,t[22]=b):b=t[22],b}function Ee(e){let t=(0,R.c)(30),{t:n,disabled:r,actionBusy:a,doAction:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=i(`max-w-2xl`,ce),t[0]=s):s=t[0];let c;t[1]!==n.maintenanceHint||t[2]!==n.maintenanceTitle?(c=(0,Z.jsx)(k,{className:le,icon:D,title:n.maintenanceTitle,subtitle:n.maintenanceHint}),t[1]=n.maintenanceHint,t[2]=n.maintenanceTitle,t[3]=c):c=t[3];let l;t[4]!==o||t[5]!==n.confirmResetStore?(l=()=>{confirm(n.confirmResetStore)&&o(`reset_store`)},t[4]=o,t[5]=n.confirmResetStore,t[6]=l):l=t[6];let u;t[7]===a?u=t[8]:(u=a===`reset_store`?(0,Z.jsx)(_,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(b,{className:`mr-2 size-4`,"aria-hidden":!0}),t[7]=a,t[8]=u);let d;t[9]!==r||t[10]!==n.resetStore||t[11]!==l||t[12]!==u?(d=(0,Z.jsxs)(T,{variant:`secondary`,disabled:r,onClick:l,children:[u,n.resetStore]}),t[9]=r,t[10]=n.resetStore,t[11]=l,t[12]=u,t[13]=d):d=t[13];let f;t[14]!==o||t[15]!==n.confirmClearLock?(f=()=>{confirm(n.confirmClearLock)&&o(`clear_lock`)},t[14]=o,t[15]=n.confirmClearLock,t[16]=f):f=t[16];let p;t[17]===a?p=t[18]:(p=a===`clear_lock`?(0,Z.jsx)(_,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(O,{className:`mr-2 size-4`,"aria-hidden":!0}),t[17]=a,t[18]=p);let m;t[19]!==r||t[20]!==n.clearLock||t[21]!==f||t[22]!==p?(m=(0,Z.jsxs)(T,{variant:`secondary`,disabled:r,onClick:f,children:[p,n.clearLock]}),t[19]=r,t[20]=n.clearLock,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;t[24]!==d||t[25]!==m?(h=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[d,m]}),t[24]=d,t[25]=m,t[26]=h):h=t[26];let g;return t[27]!==c||t[28]!==h?(g=(0,Z.jsxs)(A,{className:s,children:[c,h]}),t[27]=c,t[28]=h,t[29]=g):g=t[29],g}function De(e){let t=(0,R.c)(21),{t:n,hasToken:r,previewLoading:i,previewItems:a,loadPreview:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,Z.jsx)(_,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.previewLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,Z.jsxs)(T,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.previewLoad]}),t[4]=n.previewLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.previewHint||t[10]!==n.previewTitle||t[11]!==u?(d=(0,Z.jsx)(k,{className:le,icon:f,title:n.previewTitle,subtitle:n.previewHint,trailing:u}),t[9]=n.previewHint,t[10]=n.previewTitle,t[11]=u,t[12]=d):d=t[12];let p;t[13]!==a||t[14]!==n.previewEligible||t[15]!==n.previewEmpty||t[16]!==n.previewNotLoaded?(p=a?a.length>0?(0,Z.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>{let t=`${e.path}:${e.startLine}-${e.endLine}`,r=e.skippedReason;return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 px-2.5 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t}),(0,Z.jsxs)(`span`,{children:[`score=`,e.score.toFixed(3)]}),(0,Z.jsxs)(`span`,{children:[`recalls=`,e.recallCount]}),(0,Z.jsxs)(`span`,{children:[`avg=`,e.avgScore.toFixed(3)]}),(0,Z.jsxs)(`span`,{children:[`decay=`,e.recencyDecay?.toFixed(3)??`—`]}),r?(0,Z.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Z.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:n.previewEligible})]}),e.snippet?(0,Z.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:e.snippet}):null]},`${e.key}:${e.hash}:${t}`)})}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewEmpty}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewNotLoaded}),t[13]=a,t[14]=n.previewEligible,t[15]=n.previewEmpty,t[16]=n.previewNotLoaded,t[17]=p):p=t[17];let m;return t[18]!==d||t[19]!==p?(m=(0,Z.jsxs)(A,{className:ce,children:[d,p]}),t[18]=d,t[19]=p,t[20]=m):m=t[20],m}function Oe(e,t){switch(e){case 3e4:return t.every30s;case 6e4:return t.every1min;case 3e5:return t.every5min;case 6e5:return t.every10min;case 9e5:return t.every15min;case 18e5:return t.every30min;case 36e5:return t.every1h;case 72e5:return t.every2h;default:return null}}var ke={second:new Intl.NumberFormat(`en-US`,{style:`unit`,unit:`second`,unitDisplay:`long`}),minute:new Intl.NumberFormat(`en-US`,{style:`unit`,unit:`minute`,unitDisplay:`long`}),hour:new Intl.NumberFormat(`en-US`,{style:`unit`,unit:`hour`,unitDisplay:`long`})},Ae={second:new Intl.NumberFormat(`zh-CN`,{style:`unit`,unit:`second`,unitDisplay:`long`}),minute:new Intl.NumberFormat(`zh-CN`,{style:`unit`,unit:`minute`,unitDisplay:`long`}),hour:new Intl.NumberFormat(`zh-CN`,{style:`unit`,unit:`hour`,unitDisplay:`long`})};function je(e,t){return e.startsWith(`zh`)?Ae[t]:ke[t]}function Me(e,t,n){let r=Math.max(1e3,Math.round(e));if(n&&P.has(r)){let e=Oe(r,n);if(e)return e}let i=Math.max(1,Math.round(r/1e3));if(i<120)return je(t,`second`).format(i);let a=Math.round(i/60);if(a<120)return je(t,`minute`).format(a);let o=Math.round(a/60);return je(t,`hour`).format(o)}function Ne(e){let t=(0,R.c)(12),n;t[0]!==e.expression||t[1]!==e.kind||t[2]!==e.labels||t[3]!==e.locale||t[4]!==e.nextRun||t[5]!==e.presetLabels||t[6]!==e.timezone||t[7]!==e.valueMs?(n=e.kind===`cron`?I(e.expression,e.locale,e.labels,{timezone:e.timezone,nextRun:e.nextRun}):Me(e.valueMs,e.locale,e.presetLabels),t[0]=e.expression,t[1]=e.kind,t[2]=e.labels,t[3]=e.locale,t[4]=e.nextRun,t[5]=e.presetLabels,t[6]=e.timezone,t[7]=e.valueMs,t[8]=n):n=t[8];let r=n,i;return t[9]!==e.className||t[10]!==r?(i=(0,Z.jsx)(`span`,{className:e.className,children:r}),t[9]=e.className,t[10]=r,t[11]=i):i=t[11],i}function Pe(e){let t=(0,R.c)(100),{t:n,data:r,isLoading:a,localeTag:o,scheduleBadgeLabels:s}=e,c;t[0]!==r||t[1]!==n?(c=r?de(r.lock,n):null,t[0]=r,t[1]=n,t[2]=c):c=t[2];let l=c,u;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(u=i(`min-w-0`,ce),t[3]=u):u=t[3];let d;t[4]===a?d=t[5]:(d=a?(0,Z.jsx)(_,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null,t[4]=a,t[5]=d);let f;t[6]!==n.runtimeHint||t[7]!==n.runtimeTitle||t[8]!==d?(f=(0,Z.jsx)(k,{className:le,icon:m,title:n.runtimeTitle,subtitle:n.runtimeHint,trailing:d}),t[6]=n.runtimeHint,t[7]=n.runtimeTitle,t[8]=d,t[9]=f):f=t[9];let p;t[10]===n.subsectionSchedule?p=t[11]:(p=(0,Z.jsx)(me,{label:n.subsectionSchedule,className:`mb-2`}),t[10]=n.subsectionSchedule,t[11]=p);let g=r?r.config.enabled?n.on:n.off:`—`,y;t[12]!==n.enabled||t[13]!==g?(y=(0,Z.jsx)($,{label:n.enabled,children:g}),t[12]=n.enabled,t[13]=g,t[14]=y):y=t[14];let b=l?.className,x=l?l.text:`—`,C;t[15]!==b||t[16]!==x?(C=(0,Z.jsx)(`span`,{className:b,children:x}),t[15]=b,t[16]=x,t[17]=C):C=t[17];let w;t[18]!==n.lock||t[19]!==C?(w=(0,Z.jsx)($,{label:n.lock,children:C}),t[18]=n.lock,t[19]=C,t[20]=w):w=t[20];let T=r&&r.config.timezone||`—`,E;t[21]!==n.timezone||t[22]!==T?(E=(0,Z.jsx)($,{label:n.timezone,children:T}),t[21]=n.timezone,t[22]=T,t[23]=E):E=t[23];let D;t[24]!==r||t[25]!==o||t[26]!==s?(D=r?(0,Z.jsx)(Ne,{kind:`cron`,expression:r.config.frequency,locale:o,labels:s,timezone:r.config.timezone||void 0}):`—`,t[24]=r,t[25]=o,t[26]=s,t[27]=D):D=t[27];let O;t[28]===r?O=t[29]:(O=r?.config.frequency?(0,Z.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[0.65rem] text-fg-subtle`,title:r.config.frequency,children:r.config.frequency}):null,t[28]=r,t[29]=O);let j;t[30]!==n.schedule||t[31]!==D||t[32]!==O?(j=(0,Z.jsxs)($,{label:n.schedule,className:`col-span-2 sm:col-span-2`,children:[D,O]}),t[30]=n.schedule,t[31]=D,t[32]=O,t[33]=j):j=t[33];let M;t[34]!==w||t[35]!==E||t[36]!==j||t[37]!==y?(M=(0,Z.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[y,w,E,j]}),t[34]=w,t[35]=E,t[36]=j,t[37]=y,t[38]=M):M=t[38];let N;t[39]!==M||t[40]!==p?(N=(0,Z.jsxs)(`div`,{className:J,children:[p,M]}),t[39]=M,t[40]=p,t[41]=N):N=t[41];let ee;t[42]===n.subsectionStore?ee=t[43]:(ee=(0,Z.jsx)(me,{label:n.subsectionStore,className:`mb-2`}),t[42]=n.subsectionStore,t[43]=ee);let P=r?String(r.store.entryCount):`—`,F;t[44]!==n.storeEntries||t[45]!==P?(F=(0,Z.jsx)($,{label:n.storeEntries,children:P}),t[44]=n.storeEntries,t[45]=P,t[46]=F):F=t[46];let L=r?String(r.store.promotedCount):`—`,z;t[47]!==n.storePromoted||t[48]!==L?(z=(0,Z.jsx)($,{label:n.storePromoted,children:L}),t[47]=n.storePromoted,t[48]=L,t[49]=z):z=t[49];let te;t[50]===r?te=t[51]:(te=r?ue(r.store.updatedAt):`—`,t[50]=r,t[51]=te);let ne;t[52]!==n.storeUpdatedAt||t[53]!==te?(ne=(0,Z.jsx)($,{label:n.storeUpdatedAt,children:te}),t[52]=n.storeUpdatedAt,t[53]=te,t[54]=ne):ne=t[54];let re;t[55]===r?re=t[56]:(re=r?ue(r.store.lastPromotedAt):`—`,t[55]=r,t[56]=re);let ie;t[57]!==n.storeLastPromotedAt||t[58]!==re?(ie=(0,Z.jsx)($,{label:n.storeLastPromotedAt,children:re}),t[57]=n.storeLastPromotedAt,t[58]=re,t[59]=ie):ie=t[59];let ae;t[60]!==F||t[61]!==z||t[62]!==ne||t[63]!==ie?(ae=(0,Z.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[F,z,ne,ie]}),t[60]=F,t[61]=z,t[62]=ne,t[63]=ie,t[64]=ae):ae=t[64];let B;t[65]!==ee||t[66]!==ae?(B=(0,Z.jsxs)(`div`,{className:J,children:[ee,ae]}),t[65]=ee,t[66]=ae,t[67]=B):B=t[67];let V;t[68]!==r||t[69]!==o||t[70]!==s||t[71]!==n?(V=r?.config?.phases?(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(me,{label:n.subsectionPhases,className:`mb-2`}),(0,Z.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(ge,{icon:(0,Z.jsx)(v,{className:`size-4 text-amber-500`}),label:`Light`,enabled:r.config.phases.light.enabled,cron:r.config.phases.light.cron,scheduleSummary:I(r.config.phases.light.cron,o,s,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.light.lookbackDays}d, limit=${r.config.phases.light.limit}, dedupe=${r.config.phases.light.dedupeSimilarity}`,t:n}),(0,Z.jsx)(ge,{icon:(0,Z.jsx)(S,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:r.config.phases.deep.enabled,cron:r.config.phases.deep.cron,scheduleSummary:I(r.config.phases.deep.cron,o,s,{timezone:r.config.timezone||void 0}),details:`minScore=${r.config.phases.deep.minScore}, recalls≥${r.config.phases.deep.minRecallCount}, limit=${r.config.phases.deep.limit}, halfLife=${r.config.phases.deep.recencyHalfLifeDays}d`,t:n}),(0,Z.jsx)(ge,{icon:(0,Z.jsx)(h,{className:`size-4 text-purple-500`}),label:`REM`,enabled:r.config.phases.rem.enabled,cron:r.config.phases.rem.cron,scheduleSummary:I(r.config.phases.rem.cron,o,s,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.rem.lookbackDays}d, limit=${r.config.phases.rem.limit}, strength≥${r.config.phases.rem.minPatternStrength}`,t:n})]})]}):null,t[68]=r,t[69]=o,t[70]=s,t[71]=n,t[72]=V):V=t[72];let H;t[73]===n.subsectionLastRun?H=t[74]:(H=(0,Z.jsx)(me,{label:n.subsectionLastRun,className:`mb-2`}),t[73]=n.subsectionLastRun,t[74]=H);let U;t[75]===n.lastRunBlockHint?U=t[76]:(U=(0,Z.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:n.lastRunBlockHint}),t[75]=n.lastRunBlockHint,t[76]=U);let W;t[77]!==r||t[78]!==n?(W=r?.lastRun?.exists?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[r.lastRun.parseError?(0,Z.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[n.lastRunParseError,`: `,r.lastRun.parseError]}):null,r.lastRun.record?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge-subtle/80 bg-surface-panel/50 p-2.5`,children:(0,Z.jsx)(ve,{t:n,r:r.lastRun.record})}):null,r.lastRun.raw!==void 0&&r.lastRun.raw!==null?(0,Z.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Z.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Z.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.lastRun.raw,null,2)})]}):null]}):(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.lastRunEmpty}),t[77]=r,t[78]=n,t[79]=W):W=t[79];let G;t[80]!==H||t[81]!==U||t[82]!==W?(G=(0,Z.jsxs)(`div`,{className:J,children:[H,U,W]}),t[80]=H,t[81]=U,t[82]=W,t[83]=G):G=t[83];let K=r?.lightLastRun,q;t[84]!==n||t[85]!==K?(q=(0,Z.jsx)(_e,{label:n.subsectionLightLastRun,lastRun:K,t:n}),t[84]=n,t[85]=K,t[86]=q):q=t[86];let oe=r?.remLastRun,se;t[87]!==n||t[88]!==oe?(se=(0,Z.jsx)(_e,{label:n.subsectionRemLastRun,lastRun:oe,t:n}),t[87]=n,t[88]=oe,t[89]=se):se=t[89];let Y;t[90]!==N||t[91]!==B||t[92]!==V||t[93]!==G||t[94]!==q||t[95]!==se?(Y=(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[N,B,V,G,q,se]}),t[90]=N,t[91]=B,t[92]=V,t[93]=G,t[94]=q,t[95]=se,t[96]=Y):Y=t[96];let X;return t[97]!==Y||t[98]!==f?(X=(0,Z.jsxs)(A,{className:u,children:[f,Y]}),t[97]=Y,t[98]=f,t[99]=X):X=t[99],X}var Fe=[`config`,`runtime`,`insights`,`maintenance`],Ie={config:d,runtime:m,insights:f,maintenance:D};function Le(e){return e&&Fe.includes(e)?e:`config`}function Re(e,t){return t===`config`?e.tabConfig:t===`runtime`?e.tabRuntime:t===`insights`?e.tabInsights:e.tabMaintenance}function ze(e,t){return t===`config`?e.configTabHint:t===`runtime`?e.runtimeTabHint:t===`insights`?e.insightsTabHint:e.maintenanceTabHint}function Be(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:return{form:t.value,baseline:t.value};case`set`:return{...e,form:t.value};case`saved`:return{form:t.value,baseline:t.value}}}var Ve={actionBusy:null,actionError:null,actionOk:!1,runBusy:!1,runOk:!1,runError:null,runPhase:`deep`,cfgSaving:!1,cfgOk:!1,cfgError:null,previewLoading:!1,previewError:null,previewItems:null,eventsLoading:!1,eventsError:null,events:null};function He(){let e=o(e=>e.language),t=a(e),n=t.dreamingSettings,r=t.cron.schedulePicker,i=t.cron.scheduleBadge,c=e===`zh`?`zh-CN`:`en-US`,l=!!s(e=>e.token),[d,f]=g(),p=Le(d.get(`tab`)),m=(0,L.useCallback)(e=>{f(t=>{let n=new URLSearchParams(t);return e===`config`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[f]),[h,_]=(0,L.useReducer)(x,Ve),{actionBusy:v,actionError:y,runBusy:b,runError:S,runPhase:C,cfgSaving:w,cfgError:T,previewLoading:E,previewError:D,previewItems:O,eventsLoading:k,eventsError:A,events:j}=h,[M,N]=(0,L.useReducer)(Be,{form:null,baseline:null}),P=M.form,F=M.baseline,I=(0,L.useRef)(!1),{data:R,error:B,isLoading:V,mutate:H}=u(l?z():null,te,{revalidateOnFocus:!1}),U=(0,L.useMemo)(()=>{let e=[];return B&&e.push(B instanceof Error?B.message:String(B)),y&&e.push(y),S&&e.push(S),D&&e.push(D),A&&e.push(A),T&&e.push(T),e},[B,y,S,D,A,T]),W=(0,L.useCallback)(async()=>{_({type:`patch`,patch:{actionOk:!1,actionError:null,runOk:!1,runError:null,cfgOk:!1,cfgError:null,previewError:null}}),await H()},[H]),G=(0,L.useCallback)(async()=>{_({type:`patch`,patch:{previewLoading:!0,previewError:null}});try{_({type:`patch`,patch:{previewItems:(await ie(20)).items??[]}})}catch(e){_({type:`patch`,patch:{previewError:e instanceof Error?e.message:String(e)}})}finally{_({type:`patch`,patch:{previewLoading:!1}})}},[]),K=(0,L.useCallback)(async()=>{_({type:`patch`,patch:{eventsLoading:!0,eventsError:null}});try{_({type:`patch`,patch:{events:await ae(50)}})}catch(e){_({type:`patch`,patch:{eventsError:e instanceof Error?e.message:String(e)}})}finally{_({type:`patch`,patch:{eventsLoading:!1}})}},[]),q=(0,L.useCallback)(async(e=`deep`)=>{_({type:`patch`,patch:{runBusy:!0,runOk:!1,runError:null}});try{await re(e),_({type:`patch`,patch:{runOk:!0}}),await H()}catch(e){_({type:`patch`,patch:{runError:e instanceof Error?e.message:String(e)}})}finally{_({type:`patch`,patch:{runBusy:!1}})}},[H]),ce=(0,L.useCallback)(async e=>{_({type:`patch`,patch:{actionBusy:e,actionError:null,actionOk:!1}});try{await ne(e),_({type:`patch`,patch:{actionOk:!0}}),await H()}catch(e){_({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{_({type:`patch`,patch:{actionBusy:null}})}},[H]),le=!l||V||!!v,J=(0,L.useMemo)(()=>{let e=R?.config;return oe(e??{})},[R]),Y=R?.agentId??`main`,ue=R?.memory;(0,L.useEffect)(()=>{if(!l){N({type:`reset`}),I.current=!1;return}I.current||N({type:`sync`,value:J})},[J,l]);let X=(0,L.useMemo)(()=>!P||!F?!1:JSON.stringify(P)!==JSON.stringify(F),[P,F]);return(0,Z.jsxs)(ee,{children:[(0,Z.jsx)(Te,{t:n,hasToken:l,cfgForm:P,cfgSaving:w,cfgDirty:X,saveConfig:(0,L.useCallback)(async()=>{if(P){_({type:`patch`,patch:{cfgSaving:!0,cfgOk:!1,cfgError:null}});try{await se(Y,P,ue),N({type:`saved`,value:P}),I.current=!1,_({type:`patch`,patch:{cfgOk:!0}}),await H()}catch(e){_({type:`patch`,patch:{cfgError:e instanceof Error?e.message:String(e)}})}finally{_({type:`patch`,patch:{cfgSaving:!1}})}}},[Y,ue,P,H]),doRefresh:W}),U.length>0?(0,Z.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:U.map(e=>(0,Z.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},e))}):null,(0,Z.jsx)(Ue,{t:n,activeTab:p,onChange:m}),(0,Z.jsx)(We,{t:n,id:`config`,activeTab:p,children:(0,Z.jsx)(ye,{t:n,schedulePickerLabels:r,hasToken:l,cfgForm:P,cfgBaseline:F,cfgDirty:X,cfgSaving:w,runPhase:C,setRunPhase:e=>_({type:`patch`,patch:{runPhase:e}}),runBusy:b,setCfgForm:e=>{I.current=!0;let t=typeof e==`function`?e(P):e;t&&N({type:`set`,value:t})},doRunNow:q})}),(0,Z.jsx)(We,{t:n,id:`runtime`,activeTab:p,children:(0,Z.jsx)(Pe,{t:n,data:R,isLoading:V,localeTag:c,scheduleBadgeLabels:i})}),(0,Z.jsx)(We,{t:n,id:`insights`,activeTab:p,children:(0,Z.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,Z.jsx)(De,{t:n,hasToken:l,previewLoading:E,previewItems:O,loadPreview:G}),(0,Z.jsx)(Ce,{t:n,hasToken:l,eventsLoading:k,events:j,loadEvents:K})]})}),(0,Z.jsx)(We,{t:n,id:`maintenance`,activeTab:p,children:(0,Z.jsx)(Ee,{t:n,disabled:le,actionBusy:v,doAction:ce})})]})}function Ue(e){let t=(0,R.c)(7),{t:n,activeTab:r,onChange:i}=e,a;t[0]===n?a=t[1]:(a=Fe.map(e=>({id:e,label:Re(n,e),icon:Ie[e]})),t[0]=n,t[1]=a);let o=a,s;return t[2]!==r||t[3]!==o||t[4]!==i||t[5]!==n.tabsAriaLabel?(s=(0,Z.jsx)(j,{items:o,activeTab:r,onChange:i,ariaLabel:n.tabsAriaLabel,tabIdPrefix:`dreaming-settings-tab`,panelIdPrefix:`dreaming-settings-panel`}),t[2]=r,t[3]=o,t[4]=i,t[5]=n.tabsAriaLabel,t[6]=s):s=t[6],s}function We(e){let t=(0,R.c)(13),{t:n,id:r,activeTab:i,children:a}=e,o=r!==`config`,s;t[0]!==r||t[1]!==n?(s=Re(n,r),t[0]=r,t[1]=n,t[2]=s):s=t[2];let c;t[3]!==r||t[4]!==n?(c=ze(n,r),t[3]=r,t[4]=n,t[5]=c):c=t[5];let l;return t[6]!==i||t[7]!==a||t[8]!==r||t[9]!==o||t[10]!==s||t[11]!==c?(l=(0,Z.jsx)(N,{id:r,activeTab:i,tabIdPrefix:`dreaming-settings-tab`,panelIdPrefix:`dreaming-settings-panel`,title:s,hint:c,showHeading:o,children:a}),t[6]=i,t[7]=a,t[8]=r,t[9]=o,t[10]=s,t[11]=c,t[12]=l):l=t[12],l}export{He as DreamingSettingsPanel};
|