@xopcai/xopc 0.0.43 → 0.0.45
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/README.md +138 -102
- package/README.zh-CN.md +155 -67
- package/dist/extensions/dingtalk/src/plugin.js +1 -1
- package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
- package/dist/extensions/telegram/src/plugin.js +1 -1
- package/dist/extensions/telegram/src/routing-integration.js +2 -2
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/api/api.js +2 -2
- package/dist/extensions/weixin/src/auth/accounts.js +1 -1
- package/dist/extensions/weixin/src/cdn/upload.js +1 -1
- package/dist/extensions/weixin/src/media/data-url.js +1 -1
- package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
- package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
- package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
- package/dist/extensions/weixin/src/plugin.js +1 -1
- package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
- package/dist/gateway/static/root/assets/agents-Bk2uuFvC.js +216 -0
- package/dist/gateway/static/root/assets/agents-Bk2uuFvC.js.map +1 -0
- package/dist/gateway/static/root/assets/{apps-page-Bco3oZzd.js → apps-page-CbSr8cvX.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-Bco3oZzd.js.map → apps-page-CbSr8cvX.js.map} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-Dn-hIRl1.js +2 -0
- package/dist/gateway/static/root/assets/{channels-settings-CpTZxCKG.js.map → channels-settings-Dn-hIRl1.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-api-YLqLzMDN.js → cron-dreaming-jobs-D460WnXB.js} +3 -3
- package/dist/gateway/static/root/assets/cron-dreaming-jobs-D460WnXB.js.map +1 -0
- package/dist/gateway/static/root/assets/cron-page-Df6AyXfn.js +2 -0
- package/dist/gateway/static/root/assets/cron-page-Df6AyXfn.js.map +1 -0
- package/dist/gateway/static/root/assets/dist-DN37Fw0E.js +2 -0
- package/dist/gateway/static/root/assets/{dist-4ClCuR-G.js.map → dist-DN37Fw0E.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-yNO3rwBQ.js → extension-debug-page-CqdKfBv_.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-yNO3rwBQ.js.map → extension-debug-page-CqdKfBv_.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-D0vOu9eC.js → extension-page-DhxjnfDf.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-D0vOu9eC.js.map → extension-page-DhxjnfDf.js.map} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-B3uhrA_f.js +2 -0
- package/dist/gateway/static/root/assets/{extension-settings-page-DqaNWoo7.js.map → extension-settings-page-B3uhrA_f.js.map} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-config-api-z1kl5_rE.js +2 -0
- package/dist/gateway/static/root/assets/heartbeat-config-api-z1kl5_rE.js.map +1 -0
- package/dist/gateway/static/root/assets/{index-K0ZDwzeJ.css → index-B8G4Y9YY.css} +1 -1
- package/dist/gateway/static/root/assets/{index-KxjI2fjF.js → index-BUYGk2UT.js} +93 -93
- package/dist/gateway/static/root/assets/{index-KxjI2fjF.js.map → index-BUYGk2UT.js.map} +1 -1
- package/dist/gateway/static/root/assets/logs-page-Z9KRHWeO.js +2 -0
- package/dist/gateway/static/root/assets/{logs-page-DSdKuyeD.js.map → logs-page-Z9KRHWeO.js.map} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-TlMYZxuv.js +2 -0
- package/dist/gateway/static/root/assets/{sessions-page-Bfb-hZJb.js.map → sessions-page-TlMYZxuv.js.map} +1 -1
- package/dist/gateway/static/root/assets/settings-page-X8vVcB8e.js +2 -0
- package/dist/gateway/static/root/assets/settings-page-X8vVcB8e.js.map +1 -0
- package/dist/gateway/static/root/assets/skills-page-B-tO9-I7.js +3 -0
- package/dist/gateway/static/root/assets/skills-page-B-tO9-I7.js.map +1 -0
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-Cu5zeVdn.js → use-image-provider-credentials-DsYECmye.js} +2 -2
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-Cu5zeVdn.js.map → use-image-provider-credentials-DsYECmye.js.map} +1 -1
- package/dist/gateway/static/root/index.html +2 -2
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +6 -6
- package/dist/src/agent/context/workspace-seed.js +2 -2
- package/dist/src/agent/goals/post-turn.js +1 -1
- package/dist/src/agent/image/load-image-media.js +1 -1
- package/dist/src/agent/ipc/bus.js +1 -1
- package/dist/src/agent/ipc/inbox.js +2 -2
- package/dist/src/agent/ipc/socket.js +1 -1
- package/dist/src/agent/memory/builtin-memory-store.js +1 -1
- package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
- package/dist/src/agent/memory/dreaming/events.js +1 -1
- package/dist/src/agent/memory/dreaming/last-run.js +1 -1
- package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
- package/dist/src/agent/memory/dreaming/preview.js +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
- package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
- package/dist/src/agent/memory/dreaming/utils.js +1 -1
- package/dist/src/agent/memory/plugin-discovery.js +1 -1
- package/dist/src/agent/models/manager.js +1 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
- package/dist/src/agent/service.js +5 -5
- package/dist/src/agent/skills/config.js +1 -1
- package/dist/src/agent/skills/hub-hash.js +2 -2
- package/dist/src/agent/skills/hub-lock.js +1 -1
- package/dist/src/agent/skills/hub-pull.js +1 -1
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/scanner.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/skills/skill-manager.js +1 -1
- package/dist/src/agent/tools/dreaming-tool.js +1 -1
- package/dist/src/agent/tools/factory.js +1 -1
- package/dist/src/agent/tools/image-generate-tool.js +1 -1
- package/dist/src/agent/tools/send-media.js +1 -1
- package/dist/src/agent/tools/skill-manage-tool.js +1 -1
- package/dist/src/agent/tools/write.js +1 -1
- package/dist/src/auth/credentials.js +3 -3
- package/dist/src/auth/profiles/store.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/channels/attachments/inbound-persist.js +1 -1
- package/dist/src/channels/attachments/outbound-tts-persist.js +1 -1
- package/dist/src/channels/outbound/persist-store.js +1 -1
- package/dist/src/channels/pairing/allow-from-file.js +1 -1
- package/dist/src/channels/pairing/pairing-store.js +2 -2
- package/dist/src/chat-commands/builtins/config.js +2 -2
- package/dist/src/chat-commands/context.js +1 -1
- package/dist/src/cli/commands/agent.js +1 -1
- package/dist/src/cli/commands/agents.js +1 -1
- package/dist/src/cli/commands/config.js +1 -1
- package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/doctor/checks/session-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
- package/dist/src/cli/commands/extension-dev.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/extension-pack.js +1 -1
- package/dist/src/cli/commands/image.js +1 -1
- package/dist/src/cli/commands/init.js +4 -4
- package/dist/src/cli/utils/init-workspace.js +2 -2
- package/dist/src/config/index.js +2 -2
- package/dist/src/config/loader.js +2 -2
- package/dist/src/config/models-json.js +2 -2
- package/dist/src/config/profile.js +2 -2
- package/dist/src/cron/executor.js +2 -2
- package/dist/src/cron/persistence.js +1 -1
- package/dist/src/cron/run-log-store.js +1 -1
- package/dist/src/daemon/launchd.js +2 -2
- package/dist/src/daemon/systemd.js +2 -2
- package/dist/src/extensions/health.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/lockfile.js +2 -2
- package/dist/src/gateway/agents-admin.js +2 -2
- package/dist/src/gateway/hono/lib/extension-store.js +1 -1
- package/dist/src/gateway/hono/lib/static-ui.js +1 -1
- package/dist/src/gateway/hono/oauth.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config.js +1 -1
- package/dist/src/gateway/hono/routes/dreaming.js +1 -1
- package/dist/src/gateway/hono/routes/host-fs.js +1 -1
- package/dist/src/gateway/hono/routes/models.js +1 -1
- package/dist/src/gateway/hono/routes/workspace.js +3 -3
- package/dist/src/gateway/hono/sse.js +2 -2
- package/dist/src/gateway/lock.js +2 -2
- package/dist/src/gateway/service/run-gateway-agent.js +2 -2
- package/dist/src/gateway/service.js +5 -5
- package/dist/src/gateway/workspace-fs-file-list.js +1 -1
- package/dist/src/gateway/workspace-heartbeat-path.js +1 -1
- package/dist/src/infra/update-check.js +1 -1
- package/dist/src/infra/update-lock.js +3 -3
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/infra/update-startup.js +2 -2
- package/dist/src/infra/write-file-atomic.js +2 -2
- package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
- package/dist/src/providers/index.js +2 -2
- package/dist/src/providers/model-registry.js +1 -1
- package/dist/src/session/config-store.js +2 -2
- package/dist/src/session/search-index-cache.js +1 -1
- package/dist/src/session/search-index.js +1 -1
- package/dist/src/session/session-title.js +1 -1
- package/dist/src/session/store.js +5 -5
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tui/tui.js +1 -1
- package/dist/src/utils/logger/audit.js +1 -1
- package/dist/src/utils/logger/log-store.js +1 -1
- package/dist/src/utils/logger/rotation.js +1 -1
- package/dist/src/voice/tts/audio.js +1 -1
- package/dist/src/voice/tts/providers/edge-speech.js +1 -1
- package/package.json +2 -2
- package/dist/gateway/static/root/assets/agents-BDhkkT2o.js +0 -216
- package/dist/gateway/static/root/assets/agents-BDhkkT2o.js.map +0 -1
- package/dist/gateway/static/root/assets/channels-settings-CpTZxCKG.js +0 -2
- package/dist/gateway/static/root/assets/cron-api-YLqLzMDN.js.map +0 -1
- package/dist/gateway/static/root/assets/cron-page-aiDeJtJ-.js +0 -2
- package/dist/gateway/static/root/assets/cron-page-aiDeJtJ-.js.map +0 -1
- package/dist/gateway/static/root/assets/dist-4ClCuR-G.js +0 -2
- package/dist/gateway/static/root/assets/extension-settings-page-DqaNWoo7.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-DSdKuyeD.js +0 -2
- package/dist/gateway/static/root/assets/sessions-page-Bfb-hZJb.js +0 -2
- package/dist/gateway/static/root/assets/settings-page-B7NZPSpO.js +0 -2
- package/dist/gateway/static/root/assets/settings-page-B7NZPSpO.js.map +0 -1
- package/dist/gateway/static/root/assets/skills-page-D-AJTEVx.js +0 -3
- package/dist/gateway/static/root/assets/skills-page-D-AJTEVx.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r}from"./vendor-swr-B5fPo7KK.js";import{An as i,At as a,Cr as o,Dt as s,En as c,Et as l,Fn as u,Jr as d,Ln as f,Mt as p,On as m,Ot as h,Sn as g,Wn as _,Xr as v,Yr as y,_ as b,_n as x,_r as S,bt as C,ei as w,hn as T,ir as E,jn as D,jt as O,kn as k,kt as A,mi as j,pi as M,qr as N,un as P,v as ee,vn as te,w as ne,xr as re,xt as ie,y as ae,yt as oe}from"./index-KxjI2fjF.js";import{a as se,i as ce,n as F,r as le,t as ue}from"./dist-4ClCuR-G.js";import{t as de}from"./browser-DNXWYwzc.js";var I=n();function fe({icon:e,title:t,subtitle:n,configured:r,enabled:i,onToggle:a,toggleDisabled:o,onConfigure:s,onEdit:c,onRemove:l,ch:d}){return(0,I.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-2xl border border-edge bg-surface-base px-4 py-4 dark:border-edge sm:flex-row sm:items-center sm:gap-4`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,I.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,I.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:d.hubConnectedBadge}):null]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,I.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,I.jsxs)(ce,{children:[(0,I.jsx)(se,{asChild:!0,children:(0,I.jsx)(D,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":d.menuMoreAria,children:(0,I.jsx)(v,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,I.jsx)(le,{children:(0,I.jsxs)(ue,{className:u(`min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,ae),sideOffset:6,align:`end`,children:[(0,I.jsx)(F,{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:()=>c(),children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(S,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),d.menuEditConfig]})}),(0,I.jsx)(F,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-danger outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>l(),children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(_,{className:`size-4 shrink-0`,strokeWidth:1.75}),d.menuRemoveConfig]})})]})})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} — ${d.enableChannelAria}`,disabled:o,className:u(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,i?`justify-end bg-accent`:`justify-start bg-surface-hover`,o&&`cursor-not-allowed opacity-50`),onClick:()=>void a(!i),children:(0,I.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,I.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,I.jsx)(D,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:s,children:d.hubConfigureButton})})]})}function pe({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:i,saving:o,onConfirmRemove:c}){return(0,I.jsx)(O,{open:e,onOpenChange:t,children:(0,I.jsxs)(a,{children:[(0,I.jsx)(A,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(s,{className:u(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,b,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(p,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,I.jsx)(h,{className:`mt-2 text-sm text-fg-muted`,children:r?n.removeChannelConfirm.replace(`{{name}}`,r===`weixin`?n.weixinTitle:r===`telegram`?n.telegramTitle:r===`feishu`?n.feishuTitle:n.dingtalkTitle):`\xA0`}),(0,I.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,I.jsx)(D,{type:`button`,variant:`secondary`,onClick:i,children:n.modalCancel}),(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:o,onClick:c,children:o?n.saving:n.removeChannelAction})]})]})]})})}function L(e){return(e??``).trim().toLowerCase()}function R(e){let t=e.match;return!(!t?.channel||!t.accountId||t.peerId||t.peerKind||t.guildId||t.teamId||t.memberRoleIds&&t.memberRoleIds.length>0)}function me(e){return Object.keys(e.accounts??{}).sort()}function z(e){return Object.keys(e.accounts??{}).sort()}function B(e){let t=Object.keys(e.accounts??{});return t.length>0?[...t].sort():typeof e.appId==`string`&&e.appId.trim()&&typeof e.appSecret==`string`&&e.appSecret.trim()?[`default`]:[]}function he(e){let t=Object.keys(e.accounts??{});return t.length>0?[...t].sort():typeof e.clientId==`string`&&e.clientId.trim()&&typeof e.clientSecret==`string`&&e.clientSecret.trim()?[`default`]:[]}function V(e,t,n,r,i,a){let o={},s={},c={},l={};for(let n of t)o[n]=(e.find(e=>L(e.match?.channel)===`telegram`&&L(e.match?.accountId)===L(n)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of n)s[t]=(e.find(e=>L(e.match?.channel)===`weixin`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of r)c[t]=(e.find(e=>L(e.match?.channel)===`feishu`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of i)l[t]=(e.find(e=>L(e.match?.channel)===`dingtalk`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();return{telegram:o,weixin:s,feishu:c,dingtalk:l}}function ge(e,t,n,r,i,a,o){let s=new Set(n.map(L)),c=new Set(r.map(L)),l=new Set(i.map(L)),u=new Set(a.map(L)),d=e.filter(e=>{if(e.id?.startsWith(`ui:route:account:`))return!1;if(!R(e))return!0;let t=L(e.match.channel),n=L(e.match.accountId);return!n||n===`*`?!0:!(t===`telegram`&&s.has(n)||t===`weixin`&&c.has(n)||t===`feishu`&&l.has(n)||t===`dingtalk`&&u.has(n))}),f=[];for(let e of n){let n=(t.telegram[e]??t.telegram[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:telegram:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`telegram`,accountId:e}})}for(let e of r){let n=(t.weixin[e]??t.weixin[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:weixin:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`weixin`,accountId:e}})}for(let e of i){let n=(t.feishu[e]??t.feishu[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:feishu:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`feishu`,accountId:e}})}for(let e of a){let n=(t.dingtalk[e]??t.dingtalk[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:dingtalk:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`dingtalk`,accountId:e}})}return[...d,...f]}function H(){return u(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,k,`dark:border-edge`)}function _e(){return u(m,c)}function U(e){return e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean).map(e=>/^-?\d+$/.test(e)?Number(e):e)}function W(e){return e.map(String).join(`, `)}function ve(e){let t=e.accounts?.default?.botToken;return typeof t==`string`?t:``}function ye(e){return Object.values(e.accounts??{}).some(e=>typeof e.botToken==`string`&&e.botToken.trim().length>0)}function be(e){return Object.keys(e.accounts??{}).length>0||e.allowFrom.length>0}function G(e){return!!(e.appId?.trim()&&e.appSecret?.trim())||Object.keys(e.accounts??{}).length>0}function xe(e){return!!(e.clientId?.trim()&&e.clientSecret?.trim())||Object.keys(e.accounts??{}).length>0}function K({children:e}){return(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e}),(0,I.jsx)(`select`,{className:_e(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Se({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:a,onChange:o,ch:s}){let l=i(g(e=>e.language)).agentsSettings;if(e.length===0)return null;let d=r.length>0?r:[{id:n}];return(0,I.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(K,{children:s.agentRoutingTitle}),(0,I.jsx)(q,{children:s.agentRoutingHint})]}),(0,I.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 sm:grid-cols-2 sm:items-center dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,I.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,I.jsx)(`select`,{id:`agent-route-${e}`,className:u(H(),c),disabled:a,value:(t[e]??n).toLowerCase(),onChange:t=>o(e,t.target.value),children:d.map(e=>(0,I.jsx)(`option`,{value:e.id,children:`${ne(e,l)} (${e.id})`},e.id))})]})]},e))})]})}function Ce({ch:e,form:t,baseline:n,showDingtalkSecret:r,setShowDingtalkSecret:i,dingtalkCopied:a,copyDingtalkSecret:o,updateDingtalk:s,updateChannelAgentRoute:c,dingtalkAccountsDraft:l,setDingtalkAccountsDraft:f,dingtalkAccountsError:p,onDingtalkAccountsBlur:m,dmOpts:h,groupOpts:g,chatAgents:_,saving:v,dirty:y,save:b,discard:x}){let S=H,C=t.dingtalk,T=n?.dingtalk?.clientSecret??``,E=!r&&!!String(T).trim()&&C.clientSecret===T;return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(M,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:C.enabled,onChange:e=>s({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.dingtalkClientId,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsx)(`input`,{className:u(S(),`min-w-0 flex-1 font-mono text-xs`),value:C.clientId,onChange:e=>s({clientId:e.target.value}),placeholder:`dingxxx`}),(0,I.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.dingtalkClientSecret,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(S(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:E,value:E?`*`.repeat(Math.max(1,C.clientSecret.length)):C.clientSecret,onChange:e=>{E||s({clientSecret:e.target.value})},placeholder:`••••••••`}),C.clientSecret?(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void o(),children:[a?(0,I.jsx)(j,{className:`size-3.5`}):(0,I.jsx)(w,{className:`size-3.5`}),a?e.copied:e.copy]}):null,(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(N,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,I.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dingtalkEndpoint}),(0,I.jsx)(`input`,{className:u(S(),`min-w-0 flex-1 font-mono text-xs`),value:C.endpoint,onChange:e=>s({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,I.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:C.debug,onChange:e=>s({debug:e.target.checked})}),e.dingtalkDebug]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dmPolicy}),(0,I.jsx)(`select`,{className:S(),value:C.dmPolicy,onChange:e=>s({dmPolicy:e.target.value}),children:h.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.groupPolicy}),(0,I.jsx)(`select`,{className:S(),value:C.groupPolicy,onChange:e=>s({groupPolicy:e.target.value}),children:g.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:C.requireMention,onChange:e=>s({requireMention:e.target.checked})}),e.requireMention]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(S(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:W(C.allowFrom),onChange:e=>s({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromDmDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(S(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:W(C.groupAllowFrom),onChange:e=>s({groupAllowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.historyLimit}),(0,I.jsx)(`input`,{className:u(S(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(C.historyLimit),onChange:e=>s({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.textChunkLimit}),(0,I.jsx)(`input`,{className:u(S(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(C.textChunkLimit),onChange:e=>s({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,I.jsx)(Se,{accountIds:he(C),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:_?.items??[],disabled:v,onChange:(e,t)=>c(`dingtalk`,e,t),ch:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(S(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:l,onChange:e=>f(e.target.value),onBlur:m,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),p?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:p}):(0,I.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!y||v,onClick:x,children:e.discard}),(0,I.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!y||v,onClick:async()=>{await b()},children:v?e.saving:e.save})]})]})]})}var Y=e(t(),1),X=e(de(),1);function Z(e){return{accountId:e,name:``,enabled:!0,botToken:``,allowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,apiRoot:``,proxy:``,historyLimit:50,textChunkLimit:4e3,streamMode:`partial`}}function we(){return{bindingsFull:[],channelAgentRoutes:{telegram:{},weixin:{},feishu:{},dingtalk:{}},defaultAgentId:`main`,telegram:{enabled:!1,apiRoot:``,debug:!1,allowFrom:[],groupAllowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,streamMode:`partial`,historyLimit:50,textChunkLimit:4e3,proxy:``,accounts:{default:Z(`default`)}},weixin:{enabled:!1,dmPolicy:`pairing`,allowFrom:[],debug:!1,streamMode:`partial`,historyLimit:50,textChunkLimit:4e3,routeTag:``,accounts:{}},feishu:{enabled:!1,defaultAccount:``,appId:``,appSecret:``,domain:`feishu`,connectionMode:`websocket`,verificationToken:``,encryptKey:``,webhookHost:`127.0.0.1`,webhookPort:3e3,webhookPath:`/feishu/events`,dmPolicy:`pairing`,groupPolicy:`allowlist`,allowFrom:[],groupAllowFrom:[],requireMention:!0,historyLimit:50,textChunkLimit:4e3,renderMode:`auto`,streaming:!1,reactionNotifications:`own`,tools:{doc:!0,wiki:!0,drive:!0,scopes:!0,bitable:!0,perm:!1},actions:{reactions:!0},accounts:{}},dingtalk:{enabled:!1,defaultAccount:``,clientId:``,clientSecret:``,dmPolicy:`pairing`,groupPolicy:`open`,allowFrom:[],groupAllowFrom:[],requireMention:!1,debug:!1,endpoint:`https://api.dingtalk.com`,historyLimit:50,textChunkLimit:4e3,accounts:{}}}}function Te(e){let t=e&&typeof e==`object`?e.channels:void 0,n=t&&typeof t==`object`?t:{},r=n.telegram,i=n.weixin,a=n.feishu,o=n.dingtalk,s=r?.accounts,c=s&&typeof s==`object`&&!Array.isArray(s)?{...s}:{},l=typeof r?.botToken==`string`?r.botToken.trim():``,u=c.default?.botToken?.trim()??``;l&&!u&&(c={...c,default:{...c.default??Z(`default`),accountId:`default`,botToken:l}}),c.default||(c={...c,default:Z(`default`)});let d=i?.accounts,f=d&&typeof d==`object`&&!Array.isArray(d)?d:{},p=(()=>{let t=(e&&typeof e==`object`?e:{}).bindings;return Array.isArray(t)?t:[]})(),m=(()=>{let t=(e&&typeof e==`object`?e:{}).agents;return t&&typeof t==`object`?t:{}})(),h=typeof m.defaultId==`string`&&m.defaultId.trim()?m.defaultId.trim().toLowerCase():`main`,g={telegram:{enabled:!!r?.enabled,apiRoot:typeof r?.apiRoot==`string`?r.apiRoot:``,debug:!!r?.debug,allowFrom:Array.isArray(r?.allowFrom)?[...r.allowFrom]:[],groupAllowFrom:Array.isArray(r?.groupAllowFrom)?[...r.groupAllowFrom]:[],dmPolicy:r?.dmPolicy||`pairing`,groupPolicy:r?.groupPolicy||`open`,replyToMode:r?.replyToMode||`off`,streamMode:r?.streamMode??`partial`,historyLimit:typeof r?.historyLimit==`number`?r.historyLimit:50,textChunkLimit:typeof r?.textChunkLimit==`number`?r.textChunkLimit:4e3,proxy:typeof r?.proxy==`string`?r.proxy:``,accounts:{...c}},weixin:{enabled:!!i?.enabled,dmPolicy:i?.dmPolicy||`pairing`,allowFrom:Array.isArray(i?.allowFrom)?[...i.allowFrom]:[],debug:!!i?.debug,streamMode:i?.streamMode??`partial`,historyLimit:typeof i?.historyLimit==`number`?i.historyLimit:50,textChunkLimit:typeof i?.textChunkLimit==`number`?i.textChunkLimit:4e3,routeTag:i?.routeTag==null?``:String(i.routeTag),accounts:{...f}},feishu:{enabled:!!a?.enabled,defaultAccount:typeof a?.defaultAccount==`string`?a.defaultAccount:``,appId:typeof a?.appId==`string`?a.appId:``,appSecret:typeof a?.appSecret==`string`?a.appSecret:``,domain:typeof a?.domain==`string`&&a.domain||`feishu`,connectionMode:a?.connectionMode||`websocket`,verificationToken:typeof a?.verificationToken==`string`?a.verificationToken:``,encryptKey:typeof a?.encryptKey==`string`?a.encryptKey:``,webhookHost:typeof a?.webhookHost==`string`?a.webhookHost:`127.0.0.1`,webhookPort:typeof a?.webhookPort==`number`?a.webhookPort:3e3,webhookPath:typeof a?.webhookPath==`string`?a.webhookPath:`/feishu/events`,dmPolicy:a?.dmPolicy||`pairing`,groupPolicy:a?.groupPolicy||`allowlist`,allowFrom:Array.isArray(a?.allowFrom)?[...a.allowFrom]:[],groupAllowFrom:Array.isArray(a?.groupAllowFrom)?[...a.groupAllowFrom]:[],requireMention:a?.requireMention===void 0?!0:!!a.requireMention,historyLimit:typeof a?.historyLimit==`number`?a.historyLimit:50,textChunkLimit:typeof a?.textChunkLimit==`number`?a.textChunkLimit:4e3,renderMode:a?.renderMode||`auto`,streaming:a?.streaming===void 0?!1:!!a.streaming,reactionNotifications:a?.reactionNotifications||`own`,tools:a?.tools&&typeof a.tools==`object`&&!Array.isArray(a.tools)?{...a.tools}:void 0,actions:a?.actions&&typeof a.actions==`object`&&!Array.isArray(a.actions)?{...a.actions}:void 0,accounts:a?.accounts&&typeof a.accounts==`object`&&!Array.isArray(a.accounts)?{...a.accounts}:{}},dingtalk:{enabled:!!o?.enabled,defaultAccount:typeof o?.defaultAccount==`string`?o.defaultAccount:``,clientId:typeof o?.clientId==`string`?o.clientId:``,clientSecret:typeof o?.clientSecret==`string`?o.clientSecret:``,dmPolicy:o?.dmPolicy||`pairing`,groupPolicy:o?.groupPolicy||`open`,allowFrom:Array.isArray(o?.allowFrom)?[...o.allowFrom]:[],groupAllowFrom:Array.isArray(o?.groupAllowFrom)?[...o.groupAllowFrom]:[],requireMention:o?.requireMention===!0,debug:!!o?.debug,endpoint:typeof o?.endpoint==`string`&&o.endpoint.trim()?o.endpoint.trim():`https://api.dingtalk.com`,historyLimit:typeof o?.historyLimit==`number`?o.historyLimit:50,textChunkLimit:typeof o?.textChunkLimit==`number`?o.textChunkLimit:4e3,accounts:o?.accounts&&typeof o.accounts==`object`&&!Array.isArray(o.accounts)?{...o.accounts}:{}}},_=V(p,me(g.telegram),z(g.weixin),B(g.feishu),he(g.dingtalk),h);return{...g,bindingsFull:p.map(e=>({...e})),channelAgentRoutes:_,defaultAgentId:h}}async function Ee(e){return(await T(P(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Q(e){return(await T(P(`/api/channels/weixin/login/${encodeURIComponent(e)}`))).payload.status}async function De(e){let t=e.telegram,n=e.weixin,r=e.feishu,i=e.dingtalk,a=ge(e.bindingsFull,e.channelAgentRoutes,me(t),z(n),B(r),he(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await T(P(`/api/config`),{method:`PATCH`,body:JSON.stringify({bindings:a,channels:{telegram:{enabled:t.enabled,apiRoot:t.apiRoot||void 0,debug:t.debug,allowFrom:t.allowFrom,groupAllowFrom:t.groupAllowFrom.length?t.groupAllowFrom:void 0,dmPolicy:t.dmPolicy,groupPolicy:t.groupPolicy,replyToMode:t.replyToMode,streamMode:t.streamMode,historyLimit:t.historyLimit,textChunkLimit:t.textChunkLimit,proxy:t.proxy||void 0,accounts:t.accounts},weixin:{enabled:n.enabled,dmPolicy:n.dmPolicy,allowFrom:n.allowFrom,debug:n.debug,streamMode:n.streamMode,historyLimit:n.historyLimit,textChunkLimit:n.textChunkLimit,routeTag:o,accounts:n.accounts},feishu:{enabled:r.enabled,defaultAccount:r.defaultAccount||void 0,appId:r.appId,appSecret:r.appSecret||void 0,domain:r.domain||void 0,connectionMode:r.connectionMode,verificationToken:r.verificationToken?.trim()?r.verificationToken:void 0,encryptKey:r.encryptKey?.trim()?r.encryptKey:void 0,webhookHost:r.webhookHost?.trim()?r.webhookHost:void 0,webhookPort:typeof r.webhookPort==`number`?r.webhookPort:void 0,webhookPath:r.webhookPath?.trim()?r.webhookPath:void 0,dmPolicy:r.dmPolicy,groupPolicy:r.groupPolicy,allowFrom:r.allowFrom,groupAllowFrom:r.groupAllowFrom.length?r.groupAllowFrom:void 0,requireMention:r.requireMention,historyLimit:r.historyLimit,textChunkLimit:r.textChunkLimit,renderMode:r.renderMode,streaming:r.streaming,reactionNotifications:r.reactionNotifications,tools:r.tools,actions:r.actions,accounts:r.accounts},dingtalk:{enabled:i.enabled,defaultAccount:i.defaultAccount||void 0,clientId:i.clientId,clientSecret:i.clientSecret||void 0,dmPolicy:i.dmPolicy,groupPolicy:i.groupPolicy,allowFrom:i.allowFrom,groupAllowFrom:i.groupAllowFrom.length?i.groupAllowFrom:void 0,requireMention:i.requireMention,debug:i.debug,endpoint:i.endpoint?.trim()?i.endpoint:void 0,historyLimit:i.historyLimit,textChunkLimit:i.textChunkLimit,accounts:i.accounts}}})})).payload?.config;return C(),s?Te(s):{...e,bindingsFull:a}}async function Oe(e){return(await T(P(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function ke(e){return(await T(P(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function Ae(){return(await T(P(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function je(e){return(await T(P(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Me({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(null),[v,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)(!1),E=(0,Y.useCallback)(async()=>{x(null),m(null),_(null),c(!0);try{let e=await Ae();_(e.qrUrl),m(e.sessionKey)}catch(e){x(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){m(null),_(null),x(null),C(null),T(!1),c(!1);return}E()},[e,E]),(0,Y.useEffect)(()=>{if(!d)return;let e=!1,n,i=async()=>{try{let i=await je(d);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),m(null),i.ok?(_(null),t(!1),r({clientId:i.clientId})):(x(i.message),_(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),x(i.message),m(null),_(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),x(t instanceof Error?t.message:`Request failed`),m(null),_(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[d,t,r]),(0,Y.useEffect)(()=>{if(!g){C(null),T(!1);return}let e=!1;return T(!1),X.toDataURL(g,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||C(t)}).catch(()=>{e||(T(!0),C(null))}),()=>{e=!0}},[g]);let k=!!(g&&d),j=e&&!v&&!k;return(0,I.jsx)(O,{open:e,onOpenChange:t,children:(0,I.jsxs)(a,{children:[(0,I.jsx)(A,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(s,{className:u(`fixed left-1/2 top-1/2 max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,b,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.dingtalkQrCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(p,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,I.jsx)(h,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[v?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:v}):null,!v&&(k||j)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:j?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,j&&`bg-surface-muted/40 dark:bg-surface-base`),children:[j?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,k&&g&&!v&&S&&!w?(0,I.jsx)(`img`,{src:S,alt:``,className:`relative z-[1] size-full object-contain`}):null,k&&g&&!v&&!S&&!w&&!j?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,k&&g&&!v&&w?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,I.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(y,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void E(),children:o?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function Ne({ch:e,form:t,baseline:n,showFeishuSecret:r,setShowFeishuSecret:i,showFeishuWebhookSecrets:a,setShowFeishuWebhookSecrets:o,feishuCopied:s,feishuWebhookCopied:c,copyFeishuSecret:l,copyFeishuWebhookConfig:f,updateFeishu:p,updateChannelAgentRoute:m,feishuAccountsDraft:h,setFeishuAccountsDraft:g,feishuAccountsError:_,onFeishuAccountsBlur:v,dmOpts:y,groupOpts:b,chatAgents:x,saving:S,dirty:C,save:T,discard:E}){let O=H,k=t.feishu,A=n?.feishu?.appSecret??``,P=!r&&!!String(A).trim()&&k.appSecret===A;return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(M,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:k.enabled,onChange:e=>p({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.feishuAppId,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.appId,onChange:e=>p({appId:e.target.value}),placeholder:`cli_xxx`}),(0,I.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.feishuAppSecret,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:P,value:P?`*`.repeat(Math.max(1,k.appSecret.length)):k.appSecret,onChange:e=>{P||p({appSecret:e.target.value})},placeholder:`••••••••`}),k.appSecret?(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void l(),children:[s?(0,I.jsx)(j,{className:`size-3.5`}):(0,I.jsx)(w,{className:`size-3.5`}),s?e.copied:e.copy]}):null,(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(N,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,I.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.feishuDomain}),(0,I.jsxs)(`select`,{className:O(),value:String(k.domain||`feishu`),onChange:e=>p({domain:e.target.value}),children:[(0,I.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,I.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.connectionMode}),(0,I.jsxs)(`select`,{className:O(),value:k.connectionMode,onChange:e=>p({connectionMode:e.target.value}),children:[(0,I.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,I.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,I.jsx)(q,{children:e.connectionModeDesc})]})]}),k.connectionMode===`webhook`?(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e=>!e),children:[a?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(N,{className:`size-3.5`}),a?e.hide:e.show]}),(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void f(),children:[c?(0,I.jsx)(j,{className:`size-3.5`}):(0,I.jsx)(w,{className:`size-3.5`}),c?e.copied:e.copy]})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.verificationToken}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:k.verificationToken??``,onChange:e=>p({verificationToken:e.target.value})}),(0,I.jsx)(q,{children:e.verificationTokenDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.encryptKey}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:k.encryptKey??``,onChange:e=>p({encryptKey:e.target.value})}),(0,I.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,I.jsx)(K,{children:e.webhookHost}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.webhookHost??``,onChange:e=>p({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.webhookPort}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.webhookPort??``),onChange:e=>p({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.webhookPath}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.webhookPath??``,onChange:e=>p({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,I.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.renderMode}),(0,I.jsxs)(`select`,{className:O(),value:k.renderMode,onChange:e=>p({renderMode:e.target.value}),children:[(0,I.jsx)(`option`,{value:`auto`,children:`auto`}),(0,I.jsx)(`option`,{value:`raw`,children:`raw`}),(0,I.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.reactionNotifications}),(0,I.jsxs)(`select`,{className:O(),value:k.reactionNotifications,onChange:e=>p({reactionNotifications:e.target.value}),children:[(0,I.jsx)(`option`,{value:`off`,children:`off`}),(0,I.jsx)(`option`,{value:`own`,children:`own`}),(0,I.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:k.streaming,onChange:e=>p({streaming:e.target.checked})}),e.enableStreaming]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dmPolicy}),(0,I.jsx)(`select`,{className:O(),value:k.dmPolicy,onChange:e=>p({dmPolicy:e.target.value}),children:y.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.groupPolicy}),(0,I.jsx)(`select`,{className:O(),value:k.groupPolicy,onChange:e=>p({groupPolicy:e.target.value}),children:b.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:k.requireMention,onChange:e=>p({requireMention:e.target.checked})}),e.requireMention]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:W(k.allowFrom),onChange:e=>p({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromDmDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:W(k.groupAllowFrom),onChange:e=>p({groupAllowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.historyLimit}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.historyLimit),onChange:e=>p({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.textChunkLimit}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.textChunkLimit),onChange:e=>p({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,I.jsx)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:[[`doc`,e.feishuToolDoc],[`wiki`,e.feishuToolWiki],[`drive`,e.feishuToolDrive],[`perm`,e.feishuToolPerm],[`bitable`,e.feishuToolBitable],[`scopes`,e.feishuToolScopes]].map(([e,t])=>(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!k.tools?.[e],onChange:t=>p({tools:{...k.tools,[e]:t.target.checked}})}),t]},e))}),(0,I.jsx)(`div`,{className:`mt-2`,children:(0,I.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,I.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!k.actions?.reactions,onChange:e=>p({actions:{...k.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,I.jsx)(Se,{accountIds:B(k),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:x?.items??[],disabled:S,onChange:(e,t)=>m(`feishu`,e,t),ch:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:h,onChange:e=>g(e.target.value),onBlur:v,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),_?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:_}):(0,I.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!C||S,onClick:E,children:e.discard}),(0,I.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!C||S,onClick:async()=>{await T()},children:S?e.saving:e.save})]})]})]})}function Pe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(`feishu`),[g,_]=(0,Y.useState)(null),[v,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)(null),[E,k]=(0,Y.useState)(!1),j=(0,Y.useCallback)(async e=>{m(e),C(null),_(null),x(null),c(!0);try{let t=await Oe({domain:e});x(t.qrUrl),_(t.sessionKey)}catch(e){C(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){_(null),x(null),C(null),T(null),k(!1),m(`feishu`),c(!1);return}j(`feishu`)},[e,j]),(0,Y.useEffect)(()=>{if(!g)return;let e=!1,n,i=async()=>{try{let i=await ke(g);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),_(null),i.ok?(x(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(C(i.message),x(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),C(i.message),_(null),x(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),C(t instanceof Error?t.message:`Request failed`),_(null),x(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[g,t,r]),(0,Y.useEffect)(()=>{if(!v){T(null),k(!1);return}let e=!1;return k(!1),X.toDataURL(v,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||T(t)}).catch(()=>{e||(k(!0),T(null))}),()=>{e=!0}},[v]);let M=!!(v&&g),N=e,P=e&&!S&&!M;return(0,I.jsx)(O,{open:e,onOpenChange:t,children:(0,I.jsxs)(a,{children:[(0,I.jsx)(A,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(s,{className:u(`fixed left-1/2 top-1/2 max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,b,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.feishuQrCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(p,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,I.jsx)(h,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[S?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:S}):null,!S&&(M||P)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:P?n.feishuQrStarting:n.feishuQrScanHint}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,P&&`bg-surface-muted/40 dark:bg-surface-base`),children:[P?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,M&&v&&!S&&w&&!E?(0,I.jsx)(`img`,{src:w,alt:``,className:`relative z-[1] size-full object-contain`}):null,M&&v&&!S&&!w&&!E&&!P?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,M&&v&&!S&&E?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,I.jsxs)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(y,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),N?(0,I.jsx)(`div`,{className:`mx-auto mt-4 flex w-full max-w-[20rem] justify-center px-1`,role:`group`,"aria-label":n.feishuRegionSwitchAria,children:(0,I.jsxs)(`div`,{className:`inline-flex w-full rounded-full border border-edge bg-surface-muted/60 p-1 dark:border-edge dark:bg-surface-base`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:o,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,d===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void j(`feishu`),children:n.feishuRegionChina}),(0,I.jsx)(`button`,{type:`button`,disabled:o,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,d===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void j(`lark`),children:n.feishuRegionInternational})]})}):null,(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void j(d),children:o?n.feishuQrStarting:n.feishuQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function $({tg:e,updateTelegram:t,ch:n,dmOpts:r,groupOpts:i,replyOpts:a,streamOpts:o,tgAccountsDraft:s,setTgAccountsDraft:c,tgAccountsError:l,onTgAccountsBlur:d}){let f=H;return(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.apiRoot}),(0,I.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.proxy}),(0,I.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,I.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,I.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:i}),(0,I.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:a}),(0,I.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:o}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(f(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`-1001234567890`,value:W(e.groupAllowFrom),onChange:e=>t({groupAllowFrom:U(e.target.value)})})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.historyLimit}),(0,I.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.textChunkLimit}),(0,I.jsx)(`input`,{type:`number`,min:1e3,max:1e4,step:100,className:f(),value:e.textChunkLimit,onChange:e=>t({textChunkLimit:parseInt(e.target.value,10)||4e3})})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(f(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:s,onChange:e=>c(e.target.value),onBlur:d,placeholder:`{ "personal": { "accountId": "personal", "botToken": "...", ... } }`}),l?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l}):(0,I.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Fe({open:e,onOpenChange:t,ch:n,form:r,baseline:i,tgAdvanced:o,setTgAdvanced:c,showToken:m,setShowToken:g,copied:_,copyToken:v,updateTelegram:y,updateChannelAgentRoute:x,tgAccountsDraft:S,setTgAccountsDraft:C,tgAccountsError:T,onTgAccountsBlur:E,dmOpts:k,groupOpts:P,replyOpts:te,streamOpts:ne,chatAgents:re,saving:ie,dirty:ae,save:oe,discard:se}){let ce=H,F=r.telegram,le=i?ve(i.telegram):``,ue=ve(F),de=!m&&!!String(le).trim()&&ue===le;return(0,I.jsx)(O,{open:e,onOpenChange:t,children:(0,I.jsxs)(a,{children:[(0,I.jsx)(A,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(s,{className:u(`fixed left-1/2 top-1/2 max-h-[min(90vh,48rem)] w-[min(100%-2rem,36rem)] -translate-x-1/2 -translate-y-1/2`,b,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(p,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,I.jsx)(h,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.modalCancel,children:(0,I.jsx)(f,{className:`size-4`})})})]}),(0,I.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:F.enabled,onChange:e=>y({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,I.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[n.telegramToken,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(ce(),`min-w-0 flex-1 font-mono text-xs`),type:m?`text`:`password`,autoComplete:`off`,readOnly:de,value:de?`*`.repeat(Math.max(1,le.length)):ue,onChange:e=>{if(de)return;let t=F.accounts?.default??Z(`default`);y({accounts:{...F.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),ue?(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void v(),children:[_?(0,I.jsx)(j,{className:`size-3.5`}):(0,I.jsx)(w,{className:`size-3.5`}),_?n.copied:n.copy]}):null,(0,I.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>g(e=>!e),children:[m?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(N,{className:`size-3.5`}),m?n.hide:n.show]})]}),(0,I.jsx)(q,{children:n.telegramTokenDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(ce(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:W(F.allowFrom),onChange:e=>y({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:n.allowFromDmDesc})]}),(0,I.jsx)(Se,{accountIds:me(F),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:re?.items??[],disabled:ie,onChange:(e,t)=>x(`telegram`,e,t),ch:n}),(0,I.jsxs)(D,{type:`button`,variant:`ghost`,className:`-ml-2 h-auto justify-start px-2 py-1 text-sm text-fg-muted hover:text-fg`,onClick:()=>c(e=>!e),children:[(0,I.jsx)(M,{className:u(`mr-1 size-4 transition-transform`,o&&`rotate-180`)}),o?n.advancedHide:n.advancedShow]}),o?(0,I.jsx)($,{tg:F,updateTelegram:y,ch:n,dmOpts:k,groupOpts:P,replyOpts:te,streamOpts:ne,tgAccountsDraft:S,setTgAccountsDraft:C,tgAccountsError:T,onTgAccountsBlur:E}):null]}),(0,I.jsxs)(`div`,{className:`mt-8 flex flex-wrap justify-end gap-2 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:[(0,I.jsx)(D,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,I.jsx)(D,{type:`button`,variant:`secondary`,disabled:!ae||ie,onClick:se,children:n.discard}),(0,I.jsx)(D,{type:`button`,variant:`primary`,disabled:!ae||ie,onClick:async()=>{await oe()&&t(!1)},children:ie?n.saving:n.save})]})]})]})})}function Ie(){let e=g(e=>e.language),t=i(e),n=t.channelsSettings,a=!!x(e=>e.token),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(!1),[S,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(null),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)(null),[P,ee]=(0,Y.useState)(!1),[te,ne]=(0,Y.useState)(!1),[re,ae]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(!1),[F,le]=(0,Y.useState)(!1),[ue,de]=(0,Y.useState)(!1),[I,fe]=(0,Y.useState)(!1),[pe,L]=(0,Y.useState)(!1),[R,me]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)(``),[he,V]=(0,Y.useState)(``),[ge,H]=(0,Y.useState)(``),[_e,U]=(0,Y.useState)(``),[W,ye]=(0,Y.useState)(``),[be,G]=(0,Y.useState)(``),[xe,K]=(0,Y.useState)(``),[q,J]=(0,Y.useState)(``),{data:Se}=r(a?`gateway-chat-agents-ch`:null,oe,{revalidateOnFocus:!1}),{data:Ce,error:X,isLoading:Z,mutate:Ee}=ie(a),Q=(0,Y.useMemo)(()=>Ce?.payload?.config===void 0?null:Te(Ce.payload.config),[Ce]),Oe=(0,Y.useMemo)(()=>!o||!c?!1:JSON.stringify(o)!==JSON.stringify(c),[o,c]);(0,Y.useEffect)(()=>{if(!a){s(null),l(null);return}Q!==null&&(Oe||(s(Q),l(structuredClone(Q)),B(JSON.stringify(Q.telegram.accounts??{},null,2)),V(``),H(JSON.stringify(Q.weixin.accounts??{},null,2)),U(``),ye(JSON.stringify(Q.feishu?.accounts??{},null,2)),G(``),K(JSON.stringify(Q.dingtalk?.accounts??{},null,2)),J(``),h(!1)))},[a,Q,Oe]);let ke=!!(a&&Z&&Ce===void 0&&!X),Ae=X instanceof Error?X.message:X?String(X):null,je=(0,Y.useCallback)((e,t,n)=>{s(r=>{if(!r)return null;let i=e===`telegram`?`telegram`:e===`weixin`?`weixin`:e===`feishu`?`feishu`:`dingtalk`;return{...r,channelAgentRoutes:{...r.channelAgentRoutes,[i]:{...r.channelAgentRoutes[i],[t]:n.trim().toLowerCase()}}}})},[]),Me=(0,Y.useCallback)(e=>{s(t=>t?{...t,telegram:{...t.telegram,...e}}:null)},[]),Ne=(0,Y.useCallback)(e=>{s(t=>t?{...t,weixin:{...t.weixin,...e}}:null)},[]),Pe=(0,Y.useCallback)(e=>{s(t=>t?{...t,feishu:{...t.feishu,...e}}:null)},[]),$=(0,Y.useCallback)(e=>{s(t=>t?{...t,dingtalk:{...t.dingtalk,...e}}:null)},[]),Fe=(0,Y.useCallback)(async()=>{if(!o||u)return!1;d(!0),p(null),h(!1);try{let e=await De(o);s(e);let t=structuredClone(e);return l(t),B(JSON.stringify(t.telegram.accounts??{},null,2)),V(``),H(JSON.stringify(t.weixin.accounts??{},null,2)),U(``),ye(JSON.stringify(t.feishu?.accounts??{},null,2)),G(``),K(JSON.stringify(t.dingtalk?.accounts??{},null,2)),J(``),h(!0),window.setTimeout(()=>h(!1),2500),!0}catch(e){return p(e instanceof Error?e.message:n.saveError),!1}finally{d(!1)}},[o,u,n.saveError]),Ie=(0,Y.useCallback)(()=>{if(!c)return;let e=structuredClone(c);s(e),B(JSON.stringify(e.telegram.accounts??{},null,2)),V(``),H(JSON.stringify(e.weixin.accounts??{},null,2)),U(``),ye(JSON.stringify(e.feishu?.accounts??{},null,2)),G(``),K(JSON.stringify(e.dingtalk?.accounts??{},null,2)),J(``),p(null),h(!1)},[c]),Le=(0,Y.useCallback)(async(e,t)=>{if(!o||u)return;let r=o,i=e===`weixin`?{...o,weixin:{...o.weixin,enabled:t}}:e===`telegram`?{...o,telegram:{...o.telegram,enabled:t}}:e===`feishu`?{...o,feishu:{...o.feishu,enabled:t}}:{...o,dingtalk:{...o.dingtalk,enabled:t}};s(i),d(!0),p(null);try{let e=await De(i);s(e);let t=structuredClone(e);l(t),B(JSON.stringify(t.telegram.accounts??{},null,2)),H(JSON.stringify(t.weixin.accounts??{},null,2)),ye(JSON.stringify(t.feishu?.accounts??{},null,2)),K(JSON.stringify(t.dingtalk?.accounts??{},null,2))}catch(e){p(e instanceof Error?e.message:n.saveError),s(r)}finally{d(!1)}},[o,u,n.saveError]),Re=(0,Y.useCallback)(async()=>{if(!o||!E||u)return;let e=we(),t=E===`weixin`?{...o,weixin:e.weixin}:E===`telegram`?{...o,telegram:e.telegram}:E===`feishu`?{...o,feishu:e.feishu}:{...o,dingtalk:e.dingtalk};d(!0),p(null);try{let e=await De(t);s(e);let n=structuredClone(e);l(n),B(JSON.stringify(n.telegram.accounts??{},null,2)),H(JSON.stringify(n.weixin.accounts??{},null,2)),V(``),U(``),ye(JSON.stringify(n.feishu?.accounts??{},null,2)),G(``),K(JSON.stringify(n.dingtalk?.accounts??{},null,2)),J(``),D(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[o,E,u,n.saveError]),ze=(0,Y.useCallback)(async()=>{let e=o?ve(o.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),de(!0),window.setTimeout(()=>de(!1),2e3))},[o]),Be=(0,Y.useCallback)(e=>{Pe({appId:e.appId,domain:e.domain,enabled:!0}),Ee(),j(n.feishuQrSetupSuccess),window.setTimeout(()=>j(null),4e3)},[Pe,Ee,n.feishuQrSetupSuccess]),Ve=(0,Y.useCallback)(e=>{$({clientId:e.clientId,enabled:!0}),Ee(),N(n.dingtalkQrSetupSuccess),window.setTimeout(()=>N(null),4e3)},[$,Ee,n.dingtalkQrSetupSuccess]),He=(0,Y.useCallback)(async()=>{let e=o?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),L(!0),window.setTimeout(()=>L(!1),2e3))},[o]);return{language:e,m:t,ch:n,hasToken:a,loading:ke,fetchError:Ae,mutate:Ee,form:o,baseline:c,dirty:Oe,saving:u,error:f,saveOk:m,weixinModalOpen:_,setWeixinModalOpen:v,telegramModalOpen:y,setTelegramModalOpen:b,feishuModalOpen:S,setFeishuModalOpen:C,dingtalkModalOpen:w,setDingtalkModalOpen:T,removeTarget:E,setRemoveTarget:D,weixinSuccessBanner:O,setWeixinSuccessBanner:k,feishuSetupSuccessBanner:A,dingtalkSetupSuccessBanner:M,tgAdvanced:P,setTgAdvanced:ee,showToken:te,setShowToken:ne,showFeishuSecret:re,setShowFeishuSecret:ae,showFeishuWebhookSecrets:se,setShowFeishuWebhookSecrets:ce,showDingtalkSecret:F,setShowDingtalkSecret:le,copied:ue,feishuCopied:I,dingtalkCopied:pe,feishuWebhookCopied:R,tgAccountsDraft:z,setTgAccountsDraft:B,tgAccountsError:he,wxAccountsDraft:ge,setWxAccountsDraft:H,wxAccountsError:_e,feishuAccountsDraft:W,setFeishuAccountsDraft:ye,feishuAccountsError:be,dingtalkAccountsDraft:xe,setDingtalkAccountsDraft:K,dingtalkAccountsError:q,chatAgents:Se,updateChannelAgentRoute:je,updateTelegram:Me,updateWeixin:Ne,updateFeishu:Pe,updateDingtalk:$,save:Fe,discard:Ie,toggleChannelEnabled:Le,removeChannel:Re,copyToken:ze,handleFeishuQrSetupSuccess:Be,handleDingtalkQrSetupSuccess:Ve,copyFeishuSecret:(0,Y.useCallback)(async()=>{let e=o?.feishu?.appSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),fe(!0),window.setTimeout(()=>fe(!1),2e3))},[o]),copyDingtalkSecret:He,copyFeishuWebhookConfig:(0,Y.useCallback)(async()=>{let e=o?.feishu;if(!e)return;let t={connectionMode:e.connectionMode,verificationToken:e.verificationToken||``,encryptKey:e.encryptKey||``,webhookHost:e.webhookHost||``,webhookPort:e.webhookPort||0,webhookPath:e.webhookPath||``};await navigator.clipboard.writeText(JSON.stringify(t,null,2)).catch(()=>{}),me(!0),window.setTimeout(()=>me(!1),2e3)},[o]),onTgAccountsBlur:(0,Y.useCallback)(()=>{if(!o)return;let e=z.trim();if(!e){Me({accounts:{}}),V(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Me({accounts:t}),V(``)}catch(e){V(e instanceof Error?e.message:n.jsonInvalid)}},[o,z,Me,n.jsonObjectAccounts,n.jsonInvalid]),onWxAccountsBlur:(0,Y.useCallback)(()=>{if(!o)return;let e=ge.trim();if(!e){Ne({accounts:{}}),U(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Ne({accounts:t}),U(``)}catch(e){U(e instanceof Error?e.message:n.jsonInvalid)}},[o,ge,Ne,n.jsonObjectAccounts,n.jsonInvalid]),onFeishuAccountsBlur:(0,Y.useCallback)(()=>{if(!o)return;let e=W.trim();if(!e){Pe({accounts:{}}),G(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Pe({accounts:t}),G(``)}catch(e){G(e instanceof Error?e.message:n.jsonInvalid)}},[o,W,Pe,n.jsonObjectAccounts,n.jsonInvalid]),onDingtalkAccountsBlur:(0,Y.useCallback)(()=>{if(!o)return;let e=xe.trim();if(!e){$({accounts:{}}),J(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);$({accounts:t}),J(``)}catch(e){J(e instanceof Error?e.message:n.jsonInvalid)}},[o,xe,$,n.jsonObjectAccounts,n.jsonInvalid]),dmOpts:(0,Y.useMemo)(()=>[`pairing`,`allowlist`,`open`,`disabled`].map(e=>({value:e,label:n.policy.dm[e]})),[n.policy.dm]),groupOpts:(0,Y.useMemo)(()=>[`open`,`disabled`,`allowlist`].map(e=>({value:e,label:n.policy.group[e]})),[n.policy.group]),replyOpts:(0,Y.useMemo)(()=>[`off`,`first`,`all`].map(e=>({value:e,label:n.policy.reply[e]})),[n.policy.reply]),streamOpts:(0,Y.useMemo)(()=>[`off`,`partial`,`block`].map(e=>({value:e,label:n.policy.stream[e]})),[n.policy.stream])}}function Le({open:e,onOpenChange:t,ch:n,onLoginSuccess:r,moreSettings:i}){let[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(null),[v,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)(null),[E,k]=(0,Y.useState)(!1),j=(0,Y.useCallback)(async()=>{x(null),C(null),m(null),c(!0);try{let e=await Ee();_(e.qrcodeUrl),m(e.sessionKey)}catch(e){x(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){m(null),_(null),x(null),T(null),k(!1),C(null);return}j()},[e,j]),(0,Y.useEffect)(()=>{if(!d)return;let e=!1,i,a=async()=>{try{let a=await Q(d);if(e)return;if(a.phase===`polling`){_(a.qrcodeUrl),a.qrStatus===`scaned`?C(n.weixinQrLoginScanned):C(null);return}if(a.phase===`done`){i!==void 0&&(window.clearInterval(i),i=void 0),m(null),a.ok?(_(null),t(!1),await r()):(x(a.message),_(null));return}a.phase===`unknown`&&C(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),x(t instanceof Error?t.message:`Request failed`),m(null),_(null))}};return i=window.setInterval(()=>void a(),2e3),a(),()=>{e=!0,i!==void 0&&window.clearInterval(i)}},[d,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,Y.useEffect)(()=>{if(!g){T(null),k(!1);return}let e=!1;return k(!1),X.toDataURL(g,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||T(t)}).catch(()=>{e||(k(!0),T(null))}),()=>{e=!0}},[g]);let M=!!(g&&d),N=e&&!v&&!M;return(0,I.jsx)(O,{open:e,onOpenChange:t,children:(0,I.jsxs)(a,{children:[(0,I.jsx)(A,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(s,{className:u(`fixed left-1/2 top-1/2 max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,b,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.weixinQrModalCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(p,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,I.jsx)(h,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[v?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:v}):null,!v&&(M||N)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:u(`min-h-[1.25rem] text-center text-sm`,S&&!N?`text-accent`:`text-fg-muted`),children:N?n.weixinQrLoginBusy:S??`\xA0`}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,N&&`bg-surface-muted/40 dark:bg-surface-base`),children:[N?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,M&&g&&!v&&w&&!E?(0,I.jsx)(`img`,{src:w,alt:``,className:`relative z-[1] size-full object-contain`}):null,M&&g&&!v&&!w&&!E&&!N?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,M&&g&&!v&&E?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,I.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(y,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void j(),children:o?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function Re({wx:e,updateWeixin:t,ch:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,channelAgentRoutesWx:l,defaultAgentId:d,agentItems:f,onAgentRouteChange:p,routingDisabled:m}){let h=H;return(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinAllowFrom}),(0,I.jsx)(`textarea`,{className:u(h(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`wxid_..., openid_...`,value:e.allowFrom.join(`, `),onChange:e=>t({allowFrom:e.target.value.split(/[,\n]/).map(e=>e.trim()).filter(Boolean)})}),(0,I.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,I.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,I.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:i}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.historyLimit}),(0,I.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.textChunkLimit}),(0,I.jsx)(`input`,{type:`number`,min:1e3,max:1e4,step:100,className:h(),value:e.textChunkLimit,onChange:e=>t({textChunkLimit:parseInt(e.target.value,10)||4e3})})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinRouteTag}),(0,I.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,I.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,I.jsx)(q,{children:n.weixinDebugDesc}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinAccountsJson}),(0,I.jsx)(`textarea`,{className:u(h(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:a,onChange:e=>o(e.target.value),onBlur:c,placeholder:`{ "personal": { "name": "...", "cdnBaseUrl": "...", "enabled": true } }`}),s?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}):(0,I.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,I.jsx)(Se,{accountIds:z(e),routes:l,defaultAgentId:d,agentItems:f,disabled:m,onChange:p,ch:n})]})}function ze({ch:e,wx:t,updateWeixin:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,form:l,chatAgents:u,onAgentRouteChange:d,saving:f,dirty:p,save:m,discard:h}){return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(M,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,I.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,I.jsx)(Re,{wx:t,updateWeixin:n,ch:e,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,channelAgentRoutesWx:l.channelAgentRoutes.weixin,defaultAgentId:l.defaultAgentId,agentItems:u?.items??[],onAgentRouteChange:d,routingDisabled:f})}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:h,children:e.discard}),(0,I.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:async()=>{await m()},children:f?e.saving:e.save})]})]})]})}function Be(){let{language:e,m:t,ch:n,hasToken:r,loading:i,fetchError:a,mutate:s,form:c,baseline:l,dirty:u,saving:d,error:f,saveOk:p,weixinModalOpen:m,setWeixinModalOpen:h,telegramModalOpen:g,setTelegramModalOpen:_,feishuModalOpen:v,setFeishuModalOpen:b,removeTarget:x,setRemoveTarget:S,weixinSuccessBanner:C,setWeixinSuccessBanner:w,dingtalkModalOpen:T,setDingtalkModalOpen:O,feishuSetupSuccessBanner:k,dingtalkSetupSuccessBanner:A,tgAdvanced:j,setTgAdvanced:M,showToken:N,setShowToken:P,showFeishuSecret:ee,setShowFeishuSecret:ne,showFeishuWebhookSecrets:ie,setShowFeishuWebhookSecrets:ae,showDingtalkSecret:oe,setShowDingtalkSecret:se,copied:ce,feishuCopied:F,dingtalkCopied:le,feishuWebhookCopied:ue,tgAccountsDraft:de,setTgAccountsDraft:L,tgAccountsError:R,wxAccountsDraft:me,setWxAccountsDraft:z,wxAccountsError:B,feishuAccountsDraft:he,setFeishuAccountsDraft:V,feishuAccountsError:ge,dingtalkAccountsDraft:H,setDingtalkAccountsDraft:_e,dingtalkAccountsError:U,chatAgents:W,updateChannelAgentRoute:ve,updateTelegram:K,updateWeixin:q,updateFeishu:J,updateDingtalk:Se,save:Y,discard:X,toggleChannelEnabled:Z,removeChannel:we,copyToken:Te,handleFeishuQrSetupSuccess:Ee,handleDingtalkQrSetupSuccess:Q,copyFeishuSecret:De,copyDingtalkSecret:Oe,copyFeishuWebhookConfig:ke,onTgAccountsBlur:Ae,onWxAccountsBlur:je,onFeishuAccountsBlur:$,onDingtalkAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue}=Ie();if(!r)return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,I.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,I.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,I.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,I.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!c)return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,I.jsx)(D,{type:`button`,variant:`secondary`,onClick:()=>void s(),children:n.retry})]});let We=c.weixin,Ge=c.telegram,Ke=c.feishu,qe=c.dingtalk,Je=be(We),Ye=ye(Ge),Xe=G(Ke),Ze=xe(qe),Qe=(0,I.jsx)(Ne,{ch:n,form:c,baseline:l,showFeishuSecret:ee,setShowFeishuSecret:ne,showFeishuWebhookSecrets:ie,setShowFeishuWebhookSecrets:ae,feishuCopied:F,feishuWebhookCopied:ue,copyFeishuSecret:De,copyFeishuWebhookConfig:ke,updateFeishu:J,updateChannelAgentRoute:ve,feishuAccountsDraft:he,setFeishuAccountsDraft:V,feishuAccountsError:ge,onFeishuAccountsBlur:$,dmOpts:Be,groupOpts:Ve,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),$e=(0,I.jsx)(Ce,{ch:n,form:c,baseline:l,showDingtalkSecret:oe,setShowDingtalkSecret:se,dingtalkCopied:le,copyDingtalkSecret:Oe,updateDingtalk:Se,updateChannelAgentRoute:ve,dingtalkAccountsDraft:H,setDingtalkAccountsDraft:_e,dingtalkAccountsError:U,onDingtalkAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),et=(0,I.jsx)(ze,{ch:n,wx:We,updateWeixin:q,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:me,setWxAccountsDraft:z,wxAccountsError:B,onWxAccountsBlur:je,form:c,chatAgents:W,onAgentRouteChange:(e,t)=>ve(`weixin`,e,t),saving:d,dirty:u,save:Y,discard:X});return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,I.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,I.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,I.jsxs)(`a`,{href:te(e,`channels`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,I.jsx)(y,{className:`size-3.5`})]})]}),u?(0,I.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,I.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,I.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,C?(0,I.jsx)(`p`,{className:`text-xs text-accent`,children:C}):null,k?(0,I.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:k}):null,A?(0,I.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:A}):null,(0,I.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,I.jsx)(fe,{icon:(0,I.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.weixinTitle,subtitle:n.weixinSubtitle,configured:Je,enabled:We.enabled,toggleDisabled:d,onToggle:e=>void Z(`weixin`,e),onConfigure:()=>h(!0),onEdit:()=>h(!0),onRemove:()=>S(`weixin`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(E,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.telegramTitle,subtitle:n.telegramSubtitle,configured:Ye,enabled:Ge.enabled,toggleDisabled:d,onToggle:e=>void Z(`telegram`,e),onConfigure:()=>_(!0),onEdit:()=>_(!0),onRemove:()=>S(`telegram`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.feishuTitle,subtitle:n.feishuSubtitle,configured:Xe,enabled:Ke.enabled,toggleDisabled:d,onToggle:e=>void Z(`feishu`,e),onConfigure:()=>b(!0),onEdit:()=>b(!0),onRemove:()=>S(`feishu`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(o,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.dingtalkTitle,subtitle:n.dingtalkSubtitle,configured:Ze,enabled:qe.enabled,toggleDisabled:d,onToggle:e=>void Z(`dingtalk`,e),onConfigure:()=>O(!0),onEdit:()=>O(!0),onRemove:()=>S(`dingtalk`),ch:n})]}),(0,I.jsx)(Le,{open:m,onOpenChange:h,ch:n,onLoginSuccess:async()=>{await s(),w(n.weixinQrLoginSuccess),window.setTimeout(()=>w(null),4e3)},moreSettings:et}),(0,I.jsx)(Fe,{open:g,onOpenChange:_,ch:n,form:c,baseline:l,tgAdvanced:j,setTgAdvanced:M,showToken:N,setShowToken:P,copied:ce,copyToken:Te,updateTelegram:K,updateChannelAgentRoute:ve,tgAccountsDraft:de,setTgAccountsDraft:L,tgAccountsError:R,onTgAccountsBlur:Ae,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),(0,I.jsx)(Pe,{open:v,onOpenChange:b,ch:n,onSetupSuccess:Ee,moreSettings:Qe}),(0,I.jsx)(Me,{open:T,onOpenChange:O,ch:n,onSetupSuccess:Q,moreSettings:$e}),(0,I.jsx)(pe,{open:x!==null,onOpenChange:e=>{e||S(null)},ch:n,removeTarget:x,onCancel:()=>S(null),saving:d,onConfirmRemove:()=>void we()})]})}export{Be as ChannelsSettingsPanel};
|
|
2
|
-
//# sourceMappingURL=channels-settings-CpTZxCKG.js.map
|