@xopcai/xopc 0.0.53 → 0.0.54

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.
Files changed (162) hide show
  1. package/dist/extensions/dingtalk/src/plugin.js +1 -1
  2. package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
  3. package/dist/extensions/telegram/src/plugin.js +1 -1
  4. package/dist/extensions/telegram/src/routing-integration.js +2 -2
  5. package/dist/extensions/telegram/xopc.extension.json +1 -1
  6. package/dist/extensions/weixin/src/api/api.js +2 -2
  7. package/dist/extensions/weixin/src/auth/accounts.js +1 -1
  8. package/dist/extensions/weixin/src/cdn/upload.js +1 -1
  9. package/dist/extensions/weixin/src/media/data-url.js +1 -1
  10. package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
  11. package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
  12. package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
  13. package/dist/extensions/weixin/src/plugin.js +1 -1
  14. package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
  15. package/dist/gateway/static/root/assets/{agents-Dk8idifM.js → agents-Cccit5xQ.js} +2 -2
  16. package/dist/gateway/static/root/assets/{agents-Dk8idifM.js.map → agents-Cccit5xQ.js.map} +1 -1
  17. package/dist/gateway/static/root/assets/{apps-page-C4_ekFnF.js → apps-page-JMpsr3yK.js} +2 -2
  18. package/dist/gateway/static/root/assets/{apps-page-C4_ekFnF.js.map → apps-page-JMpsr3yK.js.map} +1 -1
  19. package/dist/gateway/static/root/assets/{channels-settings-BoRUNSby.js → channels-settings-jJX9xOyE.js} +2 -2
  20. package/dist/gateway/static/root/assets/{channels-settings-BoRUNSby.js.map → channels-settings-jJX9xOyE.js.map} +1 -1
  21. package/dist/gateway/static/root/assets/{cron-dreaming-jobs-DjK4YEV9.js → cron-dreaming-jobs-DousYqF2.js} +2 -2
  22. package/dist/gateway/static/root/assets/{cron-dreaming-jobs-DjK4YEV9.js.map → cron-dreaming-jobs-DousYqF2.js.map} +1 -1
  23. package/dist/gateway/static/root/assets/{cron-page-wQAlt7WL.js → cron-page-CdYb690n.js} +2 -2
  24. package/dist/gateway/static/root/assets/{cron-page-wQAlt7WL.js.map → cron-page-CdYb690n.js.map} +1 -1
  25. package/dist/gateway/static/root/assets/{dist-DfWs1l6V.js → dist-D8QibYZR.js} +2 -2
  26. package/dist/gateway/static/root/assets/{dist-DfWs1l6V.js.map → dist-D8QibYZR.js.map} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-debug-page-DKpIM74M.js → extension-debug-page-DJ-puhUh.js} +2 -2
  28. package/dist/gateway/static/root/assets/{extension-debug-page-DKpIM74M.js.map → extension-debug-page-DJ-puhUh.js.map} +1 -1
  29. package/dist/gateway/static/root/assets/{extension-page-DR980mtQ.js → extension-page-DgDGH7uc.js} +2 -2
  30. package/dist/gateway/static/root/assets/{extension-page-DR980mtQ.js.map → extension-page-DgDGH7uc.js.map} +1 -1
  31. package/dist/gateway/static/root/assets/{extension-settings-page-CZWcC3OA.js → extension-settings-page-BnQ2f4Fq.js} +2 -2
  32. package/dist/gateway/static/root/assets/{extension-settings-page-CZWcC3OA.js.map → extension-settings-page-BnQ2f4Fq.js.map} +1 -1
  33. package/dist/gateway/static/root/assets/{heartbeat-config-api-D4vLbsOG.js → heartbeat-config-api-B9hxMalj.js} +2 -2
  34. package/dist/gateway/static/root/assets/{heartbeat-config-api-D4vLbsOG.js.map → heartbeat-config-api-B9hxMalj.js.map} +1 -1
  35. package/dist/gateway/static/root/assets/{index-DZLKmP08.js → index-8IFT6i7x.js} +4 -4
  36. package/dist/gateway/static/root/assets/{index-DZLKmP08.js.map → index-8IFT6i7x.js.map} +1 -1
  37. package/dist/gateway/static/root/assets/{logs-page-f_viqgaf.js → logs-page-DNHn8mTk.js} +2 -2
  38. package/dist/gateway/static/root/assets/{logs-page-f_viqgaf.js.map → logs-page-DNHn8mTk.js.map} +1 -1
  39. package/dist/gateway/static/root/assets/{sessions-page-DW2-c8fv.js → sessions-page-D3kE1tob.js} +2 -2
  40. package/dist/gateway/static/root/assets/{sessions-page-DW2-c8fv.js.map → sessions-page-D3kE1tob.js.map} +1 -1
  41. package/dist/gateway/static/root/assets/{settings-page-D7-piKSc.js → settings-page-B4tuVOtd.js} +2 -2
  42. package/dist/gateway/static/root/assets/{settings-page-D7-piKSc.js.map → settings-page-B4tuVOtd.js.map} +1 -1
  43. package/dist/gateway/static/root/assets/{skills-page-ChpOJZM1.js → skills-page-Dgd20nUt.js} +2 -2
  44. package/dist/gateway/static/root/assets/{skills-page-ChpOJZM1.js.map → skills-page-Dgd20nUt.js.map} +1 -1
  45. package/dist/gateway/static/root/assets/{use-image-provider-credentials-131rA-SV.js → use-image-provider-credentials-CqMkyIiU.js} +2 -2
  46. package/dist/gateway/static/root/assets/{use-image-provider-credentials-131rA-SV.js.map → use-image-provider-credentials-CqMkyIiU.js.map} +1 -1
  47. package/dist/gateway/static/root/index.html +1 -1
  48. package/dist/package.js +1 -1
  49. package/dist/src/agent/agent-manager.js +6 -6
  50. package/dist/src/agent/context/workspace-seed.js +2 -2
  51. package/dist/src/agent/goals/post-turn.js +1 -1
  52. package/dist/src/agent/image/load-image-media.js +1 -1
  53. package/dist/src/agent/ipc/bus.js +1 -1
  54. package/dist/src/agent/ipc/inbox.js +2 -2
  55. package/dist/src/agent/ipc/socket.js +1 -1
  56. package/dist/src/agent/memory/builtin-memory-store.js +1 -1
  57. package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
  58. package/dist/src/agent/memory/dreaming/events.js +1 -1
  59. package/dist/src/agent/memory/dreaming/last-run.js +1 -1
  60. package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
  61. package/dist/src/agent/memory/dreaming/preview.js +1 -1
  62. package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
  63. package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
  64. package/dist/src/agent/memory/dreaming/utils.js +1 -1
  65. package/dist/src/agent/memory/plugin-discovery.js +1 -1
  66. package/dist/src/agent/models/manager.js +1 -1
  67. package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
  68. package/dist/src/agent/service.js +5 -5
  69. package/dist/src/agent/skills/config.js +1 -1
  70. package/dist/src/agent/skills/hub-hash.js +2 -2
  71. package/dist/src/agent/skills/hub-lock.js +1 -1
  72. package/dist/src/agent/skills/hub-pull.js +1 -1
  73. package/dist/src/agent/skills/index.js +1 -1
  74. package/dist/src/agent/skills/managed-store.js +1 -1
  75. package/dist/src/agent/skills/scanner.js +1 -1
  76. package/dist/src/agent/skills/skill-manage-ops.js +1 -1
  77. package/dist/src/agent/skills/skill-manager.js +1 -1
  78. package/dist/src/agent/tools/dreaming-tool.js +1 -1
  79. package/dist/src/agent/tools/factory.js +1 -1
  80. package/dist/src/agent/tools/image-generate-tool.js +1 -1
  81. package/dist/src/agent/tools/send-media.js +1 -1
  82. package/dist/src/agent/tools/skill-manage-tool.js +1 -1
  83. package/dist/src/agent/tools/write.js +1 -1
  84. package/dist/src/auth/credentials.js +3 -3
  85. package/dist/src/auth/profiles/store.js +1 -1
  86. package/dist/src/auth/sync-provider-auth.js +1 -1
  87. package/dist/src/channels/attachments/inbound-persist.js +1 -1
  88. package/dist/src/channels/attachments/outbound-tts-persist.js +1 -1
  89. package/dist/src/channels/outbound/persist-store.js +1 -1
  90. package/dist/src/channels/pairing/allow-from-file.js +1 -1
  91. package/dist/src/channels/pairing/pairing-store.js +2 -2
  92. package/dist/src/chat-commands/builtins/config.js +2 -2
  93. package/dist/src/chat-commands/context.js +1 -1
  94. package/dist/src/cli/commands/agent.js +1 -1
  95. package/dist/src/cli/commands/config.js +1 -1
  96. package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
  97. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  98. package/dist/src/cli/commands/doctor/checks/session-integrity.js +1 -1
  99. package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
  100. package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
  101. package/dist/src/cli/commands/extension-dev.js +1 -1
  102. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  103. package/dist/src/cli/commands/extension-pack.js +1 -1
  104. package/dist/src/cli/commands/image.js +1 -1
  105. package/dist/src/cli/commands/init.js +4 -4
  106. package/dist/src/cli/utils/init-workspace.js +2 -2
  107. package/dist/src/config/index.js +3 -3
  108. package/dist/src/config/loader.js +2 -2
  109. package/dist/src/config/models-json.js +2 -2
  110. package/dist/src/config/profile.js +2 -2
  111. package/dist/src/cron/executor.js +2 -2
  112. package/dist/src/cron/persistence.js +1 -1
  113. package/dist/src/cron/run-log-store.js +1 -1
  114. package/dist/src/daemon/launchd.js +2 -2
  115. package/dist/src/daemon/systemd.js +2 -2
  116. package/dist/src/extensions/health.js +1 -1
  117. package/dist/src/extensions/loader.js +1 -1
  118. package/dist/src/extensions/lockfile.js +2 -2
  119. package/dist/src/gateway/agents-admin.js +2 -2
  120. package/dist/src/gateway/hono/lib/extension-store.js +1 -1
  121. package/dist/src/gateway/hono/lib/static-ui.js +1 -1
  122. package/dist/src/gateway/hono/oauth.js +1 -1
  123. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
  124. package/dist/src/gateway/hono/routes/config.js +1 -1
  125. package/dist/src/gateway/hono/routes/dreaming.js +1 -1
  126. package/dist/src/gateway/hono/routes/host-fs.js +1 -1
  127. package/dist/src/gateway/hono/routes/models.js +1 -1
  128. package/dist/src/gateway/hono/routes/workspace.js +3 -3
  129. package/dist/src/gateway/hono/sse.js +2 -2
  130. package/dist/src/gateway/lock.js +2 -2
  131. package/dist/src/gateway/security/csp.d.ts +1 -0
  132. package/dist/src/gateway/security/csp.js +2 -0
  133. package/dist/src/gateway/security/csp.js.map +1 -1
  134. package/dist/src/gateway/service/run-gateway-agent.js +2 -2
  135. package/dist/src/gateway/service.js +5 -5
  136. package/dist/src/gateway/workspace-fs-file-list.js +1 -1
  137. package/dist/src/gateway/workspace-heartbeat-path.js +1 -1
  138. package/dist/src/infra/update-check.js +1 -1
  139. package/dist/src/infra/update-lock.js +3 -3
  140. package/dist/src/infra/update-runner.js +1 -1
  141. package/dist/src/infra/update-startup.js +2 -2
  142. package/dist/src/infra/write-file-atomic.js +2 -2
  143. package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
  144. package/dist/src/providers/index.js +2 -2
  145. package/dist/src/providers/model-registry.js +1 -1
  146. package/dist/src/session/config-store.js +2 -2
  147. package/dist/src/session/parity/jsonl-transcript-io.js +2 -2
  148. package/dist/src/session/parity/sessions-json-file.js +1 -1
  149. package/dist/src/session/parity/transcript-file-lock.js +2 -2
  150. package/dist/src/session/parity/transcript-paths.js +1 -1
  151. package/dist/src/session/search-index-cache.js +1 -1
  152. package/dist/src/session/search-index.js +1 -1
  153. package/dist/src/session/session-title.js +1 -1
  154. package/dist/src/session/store.js +4 -4
  155. package/dist/src/tui/backends/embedded-backend.js +1 -1
  156. package/dist/src/tui/tui.js +1 -1
  157. package/dist/src/utils/logger/audit.js +1 -1
  158. package/dist/src/utils/logger/log-store.js +1 -1
  159. package/dist/src/utils/logger/rotation.js +1 -1
  160. package/dist/src/voice/tts/audio.js +1 -1
  161. package/dist/src/voice/tts/providers/edge-speech.js +1 -1
  162. package/package.json +1 -1
@@ -1,2 +1,2 @@
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{$r as i,An as a,At as o,Dt as s,En as c,Er as l,In as u,Kn as d,Mt as f,Nt as p,On as m,Ot as h,Qr as g,Rn as _,Sn as v,St as y,Xr as b,Zr as x,_i as S,_n as C,br as w,c as T,gi as E,hn as D,jn as O,jt as k,kn as A,kt as j,o as M,or as N,ri as P,s as ee,un as F,vn as te,w as ne,wr as re,xt as ie,yt as ae}from"./index-DZLKmP08.js";import{a as oe,i as se,n as I,r as ce,t as le}from"./dist-DfWs1l6V.js";import{t as ue}from"./browser-DNXWYwzc.js";var L=n();function de({icon:e,title:t,subtitle:n,configured:r,enabled:a,onToggle:o,toggleDisabled:s,onConfigure:c,onEdit:l,onRemove:f,ch:p}){return(0,L.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,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,L.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,L.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:p.hubConnectedBadge}):null]}),(0,L.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,L.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,L.jsxs)(se,{children:[(0,L.jsx)(oe,{asChild:!0,children:(0,L.jsx)(O,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":p.menuMoreAria,children:(0,L.jsx)(i,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,L.jsx)(ce,{children:(0,L.jsxs)(le,{className:u(`min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,T),sideOffset:6,align:`end`,children:[(0,L.jsx)(I,{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:()=>l(),children:(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(w,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),p.menuEditConfig]})}),(0,L.jsx)(I,{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:()=>f(),children:(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(d,{className:`size-4 shrink-0`,strokeWidth:1.75}),p.menuRemoveConfig]})})]})})]}),(0,L.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} — ${p.enableChannelAria}`,disabled:s,className:u(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,a?`justify-end bg-accent`:`justify-start bg-surface-hover`,s&&`cursor-not-allowed opacity-50`),onClick:()=>void o(!a),children:(0,L.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,L.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,L.jsx)(O,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:c,children:p.hubConfigureButton})})]})}function fe({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:i,saving:a,onConfirmRemove:s}){return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{className:u(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,M,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,L.jsx)(p,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,L.jsx)(j,{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,L.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,onClick:i,children:n.modalCancel}),(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:a,onClick:s,children:a?n.saving:n.removeChannelAction})]})]})]})})}function R(e){return(e??``).trim().toLowerCase()}function z(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 pe(e){return Object.keys(e.accounts??{}).sort()}function me(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=>R(e.match?.channel)===`telegram`&&R(e.match?.accountId)===R(n)&&z(e))?.agentId??a).trim().toLowerCase();for(let t of n)s[t]=(e.find(e=>R(e.match?.channel)===`weixin`&&R(e.match?.accountId)===R(t)&&z(e))?.agentId??a).trim().toLowerCase();for(let t of r)c[t]=(e.find(e=>R(e.match?.channel)===`feishu`&&R(e.match?.accountId)===R(t)&&z(e))?.agentId??a).trim().toLowerCase();for(let t of i)l[t]=(e.find(e=>R(e.match?.channel)===`dingtalk`&&R(e.match?.accountId)===R(t)&&z(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(R)),c=new Set(r.map(R)),l=new Set(i.map(R)),u=new Set(a.map(R)),d=e.filter(e=>{if(e.id?.startsWith(`ui:route:account:`))return!1;if(!z(e))return!0;let t=R(e.match.channel),n=R(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[R(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[R(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[R(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[R(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`,A,`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,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e}),(0,L.jsx)(`select`,{className:_e(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Se({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:i,onChange:o,ch:s}){let l=a(v(e=>e.language)).agentsSettings;if(e.length===0)return null;let d=r.length>0?r:[{id:n}];return(0,L.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(K,{children:s.agentRoutingTitle}),(0,L.jsx)(q,{children:s.agentRoutingHint})]}),(0,L.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,L.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,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,L.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,L.jsx)(`select`,{id:`agent-route-${e}`,className:u(H(),c),disabled:i,value:(t[e]??n).toLowerCase(),onChange:t=>o(e,t.target.value),children:d.map(e=>(0,L.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:d,dingtalkAccountsError:f,onDingtalkAccountsBlur:p,dmOpts:m,groupOpts:h,chatAgents:g,saving:_,dirty:v,save:y,discard:C}){let w=H,T=t.dingtalk,D=n?.dingtalk?.clientSecret??``,k=!r&&!!String(D).trim()&&T.clientSecret===D;return(0,L.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,L.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,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(E,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:T.enabled,onChange:e=>s({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.dingtalkClientId,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.clientId,onChange:e=>s({clientId:e.target.value}),placeholder:`dingxxx`}),(0,L.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.dingtalkClientSecret,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:k,value:k?`*`.repeat(Math.max(1,T.clientSecret.length)):T.clientSecret,onChange:e=>{k||s({clientSecret:e.target.value})},placeholder:`••••••••`}),T.clientSecret?(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void o(),children:[a?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),a?e.copied:e.copy]}):null,(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,L.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.dingtalkEndpoint}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.endpoint,onChange:e=>s({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,L.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.debug,onChange:e=>s({debug:e.target.checked})}),e.dingtalkDebug]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.dmPolicy}),(0,L.jsx)(`select`,{className:w(),value:T.dmPolicy,onChange:e=>s({dmPolicy:e.target.value}),children:m.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.groupPolicy}),(0,L.jsx)(`select`,{className:w(),value:T.groupPolicy,onChange:e=>s({groupPolicy:e.target.value}),children:h.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.requireMention,onChange:e=>s({requireMention:e.target.checked})}),e.requireMention]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromDm}),(0,L.jsx)(`textarea`,{className:u(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:W(T.allowFrom),onChange:e=>s({allowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromDmDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromGroups}),(0,L.jsx)(`textarea`,{className:u(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:W(T.groupAllowFrom),onChange:e=>s({groupAllowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.historyLimit}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.historyLimit),onChange:e=>s({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.textChunkLimit}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.textChunkLimit),onChange:e=>s({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,L.jsx)(Se,{accountIds:he(T),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:g?.items??[],disabled:_,onChange:(e,t)=>c(`dingtalk`,e,t),ch:e}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.multiAccountJson}),(0,L.jsx)(`textarea`,{className:u(w(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:l,onChange:e=>d(e.target.value),onBlur:p,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),f?(0,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:f}):(0,L.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!v||_,onClick:C,children:e.discard}),(0,L.jsx)(O,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!v||_,onClick:async()=>{await y()},children:_?e.saving:e.save})]})]})]})}var Y=e(t(),1),X=e(ue(),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:`open`,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:`open`,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:`open`,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||`open`,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||`open`,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||`open`,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,pe(g.telegram),me(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 D(F(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Q(e){return(await D(F(`/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,pe(t),me(n),B(r),he(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await D(F(`/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 ie(),s?Te(s):{...e,bindingsFull:a}}async function Oe(e){return(await D(F(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function ke(e){return(await D(F(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function Ae(){return(await D(F(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function je(e){return(await D(F(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Me({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[a,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(null),[m,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(!1),T=(0,Y.useCallback)(async()=>{b(null),d(null),v(null),c(!0);try{let e=await Ae();v(e.qrUrl),d(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),b(null),S(null),w(!1),c(!1);return}T()},[e,T]),(0,Y.useEffect)(()=>{if(!l)return;let e=!1,n,i=async()=>{try{let i=await je(l);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),d(null),i.ok?(v(null),t(!1),r({clientId:i.clientId})):(b(i.message),v(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),b(i.message),d(null),v(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),b(t instanceof Error?t.message:`Request failed`),d(null),v(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[l,t,r]),(0,Y.useEffect)(()=>{if(!m){S(null),w(!1);return}let e=!1;return w(!1),X.toDataURL(m,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||S(t)}).catch(()=>{e||(w(!0),S(null))}),()=>{e=!0}},[m]);let E=!!(m&&l),D=e&&!y&&!E;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})}),(0,L.jsx)(p,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,L.jsx)(j,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,L.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,L.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,L.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(E||D)?(0,L.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:D?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,L.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`,D&&`bg-surface-muted/40 dark:bg-surface-base`),children:[D?(0,L.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,E&&m&&!y&&x&&!C?(0,L.jsx)(`img`,{src:x,alt:``,className:`relative z-[1] size-full object-contain`}):null,E&&m&&!y&&!x&&!C&&!D?(0,L.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,E&&m&&!y&&C?(0,L.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,L.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,L.jsxs)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,L.jsx)(g,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,L.jsx)(`div`,{className:`mt-6`,children:(0,L.jsx)(O,{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:a,onClick:()=>void T(),children:a?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),i?(0,L.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:d,updateFeishu:f,updateChannelAgentRoute:p,feishuAccountsDraft:m,setFeishuAccountsDraft:h,feishuAccountsError:g,onFeishuAccountsBlur:_,dmOpts:v,groupOpts:y,chatAgents:C,saving:w,dirty:T,save:D,discard:k}){let A=H,j=t.feishu,M=n?.feishu?.appSecret??``,N=!r&&!!String(M).trim()&&j.appSecret===M;return(0,L.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,L.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,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(E,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:j.enabled,onChange:e=>f({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.feishuAppId,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.appId,onChange:e=>f({appId:e.target.value}),placeholder:`cli_xxx`}),(0,L.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.feishuAppSecret,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:N,value:N?`*`.repeat(Math.max(1,j.appSecret.length)):j.appSecret,onChange:e=>{N||f({appSecret:e.target.value})},placeholder:`••••••••`}),j.appSecret?(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void l(),children:[s?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),s?e.copied:e.copy]}):null,(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,L.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.feishuDomain}),(0,L.jsxs)(`select`,{className:A(),value:String(j.domain||`feishu`),onChange:e=>f({domain:e.target.value}),children:[(0,L.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,L.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.connectionMode}),(0,L.jsxs)(`select`,{className:A(),value:j.connectionMode,onChange:e=>f({connectionMode:e.target.value}),children:[(0,L.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,L.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,L.jsx)(q,{children:e.connectionModeDesc})]})]}),j.connectionMode===`webhook`?(0,L.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e=>!e),children:[a?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),a?e.hide:e.show]}),(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void d(),children:[c?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),c?e.copied:e.copy]})]})]}),(0,L.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.verificationToken}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:j.verificationToken??``,onChange:e=>f({verificationToken:e.target.value})}),(0,L.jsx)(q,{children:e.verificationTokenDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.encryptKey}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:j.encryptKey??``,onChange:e=>f({encryptKey:e.target.value})}),(0,L.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,L.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,L.jsx)(K,{children:e.webhookHost}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookHost??``,onChange:e=>f({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.webhookPort}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.webhookPort??``),onChange:e=>f({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,L.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.webhookPath}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookPath??``,onChange:e=>f({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,L.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.renderMode}),(0,L.jsxs)(`select`,{className:A(),value:j.renderMode,onChange:e=>f({renderMode:e.target.value}),children:[(0,L.jsx)(`option`,{value:`auto`,children:`auto`}),(0,L.jsx)(`option`,{value:`raw`,children:`raw`}),(0,L.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.reactionNotifications}),(0,L.jsxs)(`select`,{className:A(),value:j.reactionNotifications,onChange:e=>f({reactionNotifications:e.target.value}),children:[(0,L.jsx)(`option`,{value:`off`,children:`off`}),(0,L.jsx)(`option`,{value:`own`,children:`own`}),(0,L.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.streaming,onChange:e=>f({streaming:e.target.checked})}),e.enableStreaming]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.dmPolicy}),(0,L.jsx)(`select`,{className:A(),value:j.dmPolicy,onChange:e=>f({dmPolicy:e.target.value}),children:v.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.groupPolicy}),(0,L.jsx)(`select`,{className:A(),value:j.groupPolicy,onChange:e=>f({groupPolicy:e.target.value}),children:y.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.requireMention,onChange:e=>f({requireMention:e.target.checked})}),e.requireMention]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromDm}),(0,L.jsx)(`textarea`,{className:u(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:W(j.allowFrom),onChange:e=>f({allowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromDmDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromGroups}),(0,L.jsx)(`textarea`,{className:u(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:W(j.groupAllowFrom),onChange:e=>f({groupAllowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.historyLimit}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.historyLimit),onChange:e=>f({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.textChunkLimit}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.textChunkLimit),onChange:e=>f({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,L.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,L.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,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.tools?.[e],onChange:t=>f({tools:{...j.tools,[e]:t.target.checked}})}),t]},e))}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,L.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,L.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.actions?.reactions,onChange:e=>f({actions:{...j.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,L.jsx)(Se,{accountIds:B(j),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:C?.items??[],disabled:w,onChange:(e,t)=>p(`feishu`,e,t),ch:e}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.multiAccountJson}),(0,L.jsx)(`textarea`,{className:u(A(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:m,onChange:e=>h(e.target.value),onBlur:_,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),g?(0,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:g}):(0,L.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:k,children:e.discard}),(0,L.jsx)(O,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:async()=>{await D()},children:w?e.saving:e.save})]})]})]})}function Pe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[a,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(`feishu`),[m,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useCallback)(async e=>{d(e),S(null),v(null),b(null),c(!0);try{let t=await Oe({domain:e});b(t.qrUrl),v(t.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){v(null),b(null),S(null),w(null),E(!1),d(`feishu`),c(!1);return}D(`feishu`)},[e,D]),(0,Y.useEffect)(()=>{if(!m)return;let e=!1,n,i=async()=>{try{let i=await ke(m);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),v(null),i.ok?(b(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(S(i.message),b(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),S(i.message),v(null),b(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),S(t instanceof Error?t.message:`Request failed`),v(null),b(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[m,t,r]),(0,Y.useEffect)(()=>{if(!y){w(null),E(!1);return}let e=!1;return E(!1),X.toDataURL(y,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[y]);let A=!!(y&&m),N=e,P=e&&!x&&!A;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})}),(0,L.jsx)(p,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,L.jsx)(j,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,L.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,L.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[x?(0,L.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:x}):null,!x&&(A||P)?(0,L.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:P?n.feishuQrStarting:n.feishuQrScanHint}),(0,L.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,L.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&y&&!x&&C&&!T?(0,L.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&y&&!x&&!C&&!T&&!P?(0,L.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,A&&y&&!x&&T?(0,L.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,L.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,L.jsxs)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,L.jsx)(g,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),N?(0,L.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,L.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,L.jsx)(`button`,{type:`button`,disabled:a,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,l===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void D(`feishu`),children:n.feishuRegionChina}),(0,L.jsx)(`button`,{type:`button`,disabled:a,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,l===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void D(`lark`),children:n.feishuRegionInternational})]})}):null,(0,L.jsx)(`div`,{className:`mt-6`,children:(0,L.jsx)(O,{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:a,onClick:()=>void D(l),children:a?n.feishuQrStarting:n.feishuQrRegenerate})}),i?(0,L.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,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.apiRoot}),(0,L.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.proxy}),(0,L.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,L.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,L.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:i}),(0,L.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:a}),(0,L.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:o}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.allowFromGroups}),(0,L.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,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.historyLimit}),(0,L.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.textChunkLimit}),(0,L.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,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.multiAccountJson}),(0,L.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,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l}):(0,L.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Fe({open:e,onOpenChange:t,ch:n,form:r,baseline:i,tgAdvanced:a,setTgAdvanced:c,showToken:l,setShowToken:d,copied:m,copyToken:g,updateTelegram:v,updateChannelAgentRoute:y,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:D,dmOpts:A,groupOpts:N,replyOpts:F,streamOpts:te,chatAgents:ne,saving:re,dirty:ie,save:ae,discard:oe}){let se=H,I=r.telegram,ce=i?ve(i.telegram):``,le=ve(I),ue=!l&&!!String(ce).trim()&&le===ce;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(p,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,L.jsx)(j,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})})]}),(0,L.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:I.enabled,onChange:e=>v({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,L.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[n.telegramToken,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(`input`,{className:u(se(),`min-w-0 flex-1 font-mono text-xs`),type:l?`text`:`password`,autoComplete:`off`,readOnly:ue,value:ue?`*`.repeat(Math.max(1,ce.length)):le,onChange:e=>{if(ue)return;let t=I.accounts?.default??Z(`default`);v({accounts:{...I.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),le?(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void g(),children:[m?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),m?n.copied:n.copy]}):null,(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>d(e=>!e),children:[l?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),l?n.hide:n.show]})]}),(0,L.jsx)(q,{children:n.telegramTokenDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.allowFromDm}),(0,L.jsx)(`textarea`,{className:u(se(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:W(I.allowFrom),onChange:e=>v({allowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:n.allowFromDmDesc})]}),(0,L.jsx)(Se,{accountIds:pe(I),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:ne?.items??[],disabled:re,onChange:(e,t)=>y(`telegram`,e,t),ch:n}),(0,L.jsxs)(O,{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,L.jsx)(E,{className:u(`mr-1 size-4 transition-transform`,a&&`rotate-180`)}),a?n.advancedHide:n.advancedShow]}),a?(0,L.jsx)($,{tg:I,updateTelegram:v,ch:n,dmOpts:A,groupOpts:N,replyOpts:F,streamOpts:te,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:D}):null]}),(0,L.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,L.jsx)(O,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,L.jsx)(O,{type:`button`,variant:`secondary`,disabled:!ie||re,onClick:oe,children:n.discard}),(0,L.jsx)(O,{type:`button`,variant:`primary`,disabled:!ie||re,onClick:async()=>{await ae()&&t(!1)},children:re?n.saving:n.save})]})]})]})})}function Ie(){let e=v(e=>e.language),t=a(e),n=t.channelsSettings,i=!!C(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),[g,_]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(!1),[S,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(!1),[D,O]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(null),[j,M]=(0,Y.useState)(null),[N,P]=(0,Y.useState)(null),[ee,F]=(0,Y.useState)(!1),[te,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(!1),[I,ce]=(0,Y.useState)(!1),[le,ue]=(0,Y.useState)(!1),[L,de]=(0,Y.useState)(!1),[fe,R]=(0,Y.useState)(!1),[z,pe]=(0,Y.useState)(!1),[me,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(i?`gateway-chat-agents-ch`:null,ae,{revalidateOnFocus:!1}),{data:Ce,error:X,isLoading:Z,mutate:Ee}=y(i),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(!i){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)))},[i,Q,Oe]);let ke=!!(i&&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||!D||u)return;let e=we(),t=D===`weixin`?{...o,weixin:e.weixin}:D===`telegram`?{...o,telegram:e.telegram}:D===`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(``),O(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[o,D,u,n.saveError]),ze=(0,Y.useCallback)(async()=>{let e=o?ve(o.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),ue(!0),window.setTimeout(()=>ue(!1),2e3))},[o]),Be=(0,Y.useCallback)(e=>{Pe({appId:e.appId,domain:e.domain,enabled:!0}),Ee(),M(n.feishuQrSetupSuccess),window.setTimeout(()=>M(null),4e3)},[Pe,Ee,n.feishuQrSetupSuccess]),Ve=(0,Y.useCallback)(e=>{$({clientId:e.clientId,enabled:!0}),Ee(),P(n.dingtalkQrSetupSuccess),window.setTimeout(()=>P(null),4e3)},[$,Ee,n.dingtalkQrSetupSuccess]),He=(0,Y.useCallback)(async()=>{let e=o?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),R(!0),window.setTimeout(()=>R(!1),2e3))},[o]);return{language:e,m:t,ch:n,hasToken:i,loading:ke,fetchError:Ae,mutate:Ee,form:o,baseline:c,dirty:Oe,saving:u,error:f,saveOk:m,weixinModalOpen:g,setWeixinModalOpen:_,telegramModalOpen:b,setTelegramModalOpen:x,feishuModalOpen:S,setFeishuModalOpen:w,dingtalkModalOpen:T,setDingtalkModalOpen:E,removeTarget:D,setRemoveTarget:O,weixinSuccessBanner:k,setWeixinSuccessBanner:A,feishuSetupSuccessBanner:j,dingtalkSetupSuccessBanner:N,tgAdvanced:ee,setTgAdvanced:F,showToken:te,setShowToken:ne,showFeishuSecret:re,setShowFeishuSecret:ie,showFeishuWebhookSecrets:oe,setShowFeishuWebhookSecrets:se,showDingtalkSecret:I,setShowDingtalkSecret:ce,copied:le,feishuCopied:L,dingtalkCopied:fe,feishuWebhookCopied:z,tgAccountsDraft:me,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(()=>{}),de(!0),window.setTimeout(()=>de(!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(()=>{}),pe(!0),window.setTimeout(()=>pe(!1),2e3)},[o]),onTgAccountsBlur:(0,Y.useCallback)(()=>{if(!o)return;let e=me.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,me,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[a,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(null),[m,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useCallback)(async()=>{b(null),S(null),d(null),c(!0);try{let e=await Ee();v(e.qrcodeUrl),d(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),b(null),w(null),E(!1),S(null);return}D()},[e,D]),(0,Y.useEffect)(()=>{if(!l)return;let e=!1,i,a=async()=>{try{let a=await Q(l);if(e)return;if(a.phase===`polling`){v(a.qrcodeUrl),a.qrStatus===`scaned`?S(n.weixinQrLoginScanned):S(null);return}if(a.phase===`done`){i!==void 0&&(window.clearInterval(i),i=void 0),d(null),a.ok?(v(null),t(!1),await r()):(b(a.message),v(null));return}a.phase===`unknown`&&S(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),b(t instanceof Error?t.message:`Request failed`),d(null),v(null))}};return i=window.setInterval(()=>void a(),2e3),a(),()=>{e=!0,i!==void 0&&window.clearInterval(i)}},[l,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,Y.useEffect)(()=>{if(!m){w(null),E(!1);return}let e=!1;return E(!1),X.toDataURL(m,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[m]);let A=!!(m&&l),N=e&&!y&&!A;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})}),(0,L.jsx)(p,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,L.jsx)(j,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,L.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,L.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,L.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(A||N)?(0,L.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,L.jsx)(`p`,{className:u(`min-h-[1.25rem] text-center text-sm`,x&&!N?`text-accent`:`text-fg-muted`),children:N?n.weixinQrLoginBusy:x??`\xA0`}),(0,L.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,L.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&m&&!y&&C&&!T?(0,L.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&m&&!y&&!C&&!T&&!N?(0,L.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,A&&m&&!y&&T?(0,L.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,L.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,L.jsxs)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,L.jsx)(g,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,L.jsx)(`div`,{className:`mt-6`,children:(0,L.jsx)(O,{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:a,onClick:()=>void D(),children:a?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),i?(0,L.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,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.weixinAllowFrom}),(0,L.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,L.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,L.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,L.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:i}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.historyLimit}),(0,L.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.textChunkLimit}),(0,L.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,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.weixinRouteTag}),(0,L.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,L.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,L.jsx)(q,{children:n.weixinDebugDesc}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.weixinAccountsJson}),(0,L.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,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}):(0,L.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,L.jsx)(Se,{accountIds:me(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,L.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,L.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,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(E,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,L.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,L.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,L.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:h,children:e.discard}),(0,L.jsx)(O,{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:o,form:s,baseline:c,dirty:u,saving:d,error:f,saveOk:p,weixinModalOpen:m,setWeixinModalOpen:h,telegramModalOpen:_,setTelegramModalOpen:v,feishuModalOpen:y,setFeishuModalOpen:b,removeTarget:x,setRemoveTarget:S,weixinSuccessBanner:C,setWeixinSuccessBanner:w,dingtalkModalOpen:T,setDingtalkModalOpen:E,feishuSetupSuccessBanner:D,dingtalkSetupSuccessBanner:k,tgAdvanced:A,setTgAdvanced:j,showToken:M,setShowToken:P,showFeishuSecret:ee,setShowFeishuSecret:F,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,showDingtalkSecret:ae,setShowDingtalkSecret:oe,copied:se,feishuCopied:I,dingtalkCopied:ce,feishuWebhookCopied:le,tgAccountsDraft:ue,setTgAccountsDraft:R,tgAccountsError:z,wxAccountsDraft:pe,setWxAccountsDraft:me,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,L.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,L.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,L.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,L.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,L.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,L.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!s)return(0,L.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,L.jsx)(O,{type:`button`,variant:`secondary`,onClick:()=>void o(),children:n.retry})]});let We=s.weixin,Ge=s.telegram,Ke=s.feishu,qe=s.dingtalk,Je=be(We),Ye=ye(Ge),Xe=G(Ke),Ze=xe(qe),Qe=(0,L.jsx)(Ne,{ch:n,form:s,baseline:c,showFeishuSecret:ee,setShowFeishuSecret:F,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,feishuCopied:I,feishuWebhookCopied:le,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,L.jsx)(Ce,{ch:n,form:s,baseline:c,showDingtalkSecret:ae,setShowDingtalkSecret:oe,dingtalkCopied:ce,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,L.jsx)(ze,{ch:n,wx:We,updateWeixin:q,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:pe,setWxAccountsDraft:me,wxAccountsError:B,onWxAccountsBlur:je,form:s,chatAgents:W,onAgentRouteChange:(e,t)=>ve(`weixin`,e,t),saving:d,dirty:u,save:Y,discard:X});return(0,L.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,L.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,L.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,L.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,L.jsx)(g,{className:`size-3.5`})]})]}),u?(0,L.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,L.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,C?(0,L.jsx)(`p`,{className:`text-xs text-accent`,children:C}):null,D?(0,L.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:D}):null,k?(0,L.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:k}):null,(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(de,{icon:(0,L.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,L.jsx)(de,{icon:(0,L.jsx)(N,{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:()=>v(!0),onEdit:()=>v(!0),onRemove:()=>S(`telegram`),ch:n}),(0,L.jsx)(de,{icon:(0,L.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,L.jsx)(de,{icon:(0,L.jsx)(l,{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:()=>E(!0),onEdit:()=>E(!0),onRemove:()=>S(`dingtalk`),ch:n})]}),(0,L.jsx)(Le,{open:m,onOpenChange:h,ch:n,onLoginSuccess:async()=>{await o(),w(n.weixinQrLoginSuccess),window.setTimeout(()=>w(null),4e3)},moreSettings:et}),(0,L.jsx)(Fe,{open:_,onOpenChange:v,ch:n,form:s,baseline:c,tgAdvanced:A,setTgAdvanced:j,showToken:M,setShowToken:P,copied:se,copyToken:Te,updateTelegram:K,updateChannelAgentRoute:ve,tgAccountsDraft:ue,setTgAccountsDraft:R,tgAccountsError:z,onTgAccountsBlur:Ae,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),(0,L.jsx)(Pe,{open:y,onOpenChange:b,ch:n,onSetupSuccess:Ee,moreSettings:Qe}),(0,L.jsx)(Me,{open:T,onOpenChange:E,ch:n,onSetupSuccess:Q,moreSettings:$e}),(0,L.jsx)(fe,{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-BoRUNSby.js.map
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{$r as i,An as a,At as o,Dt as s,En as c,Er as l,In as u,Kn as d,Mt as f,Nt as p,On as m,Ot as h,Qr as g,Rn as _,Sn as v,St as y,Xr as b,Zr as x,_i as S,_n as C,br as w,c as T,gi as E,hn as D,jn as O,jt as k,kn as A,kt as j,o as M,or as N,ri as P,s as ee,un as F,vn as te,w as ne,wr as re,xt as ie,yt as ae}from"./index-8IFT6i7x.js";import{a as oe,i as se,n as I,r as ce,t as le}from"./dist-D8QibYZR.js";import{t as ue}from"./browser-DNXWYwzc.js";var L=n();function de({icon:e,title:t,subtitle:n,configured:r,enabled:a,onToggle:o,toggleDisabled:s,onConfigure:c,onEdit:l,onRemove:f,ch:p}){return(0,L.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,L.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,L.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,L.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:p.hubConnectedBadge}):null]}),(0,L.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,L.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,L.jsxs)(se,{children:[(0,L.jsx)(oe,{asChild:!0,children:(0,L.jsx)(O,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":p.menuMoreAria,children:(0,L.jsx)(i,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,L.jsx)(ce,{children:(0,L.jsxs)(le,{className:u(`min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,T),sideOffset:6,align:`end`,children:[(0,L.jsx)(I,{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:()=>l(),children:(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(w,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),p.menuEditConfig]})}),(0,L.jsx)(I,{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:()=>f(),children:(0,L.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(d,{className:`size-4 shrink-0`,strokeWidth:1.75}),p.menuRemoveConfig]})})]})})]}),(0,L.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} — ${p.enableChannelAria}`,disabled:s,className:u(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,a?`justify-end bg-accent`:`justify-start bg-surface-hover`,s&&`cursor-not-allowed opacity-50`),onClick:()=>void o(!a),children:(0,L.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,L.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,L.jsx)(O,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:c,children:p.hubConfigureButton})})]})}function fe({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:i,saving:a,onConfirmRemove:s}){return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{className:u(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,M,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,L.jsx)(p,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,L.jsx)(j,{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,L.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,onClick:i,children:n.modalCancel}),(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:a,onClick:s,children:a?n.saving:n.removeChannelAction})]})]})]})})}function R(e){return(e??``).trim().toLowerCase()}function z(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 pe(e){return Object.keys(e.accounts??{}).sort()}function me(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=>R(e.match?.channel)===`telegram`&&R(e.match?.accountId)===R(n)&&z(e))?.agentId??a).trim().toLowerCase();for(let t of n)s[t]=(e.find(e=>R(e.match?.channel)===`weixin`&&R(e.match?.accountId)===R(t)&&z(e))?.agentId??a).trim().toLowerCase();for(let t of r)c[t]=(e.find(e=>R(e.match?.channel)===`feishu`&&R(e.match?.accountId)===R(t)&&z(e))?.agentId??a).trim().toLowerCase();for(let t of i)l[t]=(e.find(e=>R(e.match?.channel)===`dingtalk`&&R(e.match?.accountId)===R(t)&&z(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(R)),c=new Set(r.map(R)),l=new Set(i.map(R)),u=new Set(a.map(R)),d=e.filter(e=>{if(e.id?.startsWith(`ui:route:account:`))return!1;if(!z(e))return!0;let t=R(e.match.channel),n=R(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[R(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[R(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[R(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[R(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`,A,`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,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e}),(0,L.jsx)(`select`,{className:_e(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Se({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:i,onChange:o,ch:s}){let l=a(v(e=>e.language)).agentsSettings;if(e.length===0)return null;let d=r.length>0?r:[{id:n}];return(0,L.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(K,{children:s.agentRoutingTitle}),(0,L.jsx)(q,{children:s.agentRoutingHint})]}),(0,L.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,L.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,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,L.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,L.jsx)(`select`,{id:`agent-route-${e}`,className:u(H(),c),disabled:i,value:(t[e]??n).toLowerCase(),onChange:t=>o(e,t.target.value),children:d.map(e=>(0,L.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:d,dingtalkAccountsError:f,onDingtalkAccountsBlur:p,dmOpts:m,groupOpts:h,chatAgents:g,saving:_,dirty:v,save:y,discard:C}){let w=H,T=t.dingtalk,D=n?.dingtalk?.clientSecret??``,k=!r&&!!String(D).trim()&&T.clientSecret===D;return(0,L.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,L.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,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(E,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:T.enabled,onChange:e=>s({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.dingtalkClientId,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.clientId,onChange:e=>s({clientId:e.target.value}),placeholder:`dingxxx`}),(0,L.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.dingtalkClientSecret,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:k,value:k?`*`.repeat(Math.max(1,T.clientSecret.length)):T.clientSecret,onChange:e=>{k||s({clientSecret:e.target.value})},placeholder:`••••••••`}),T.clientSecret?(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void o(),children:[a?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),a?e.copied:e.copy]}):null,(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,L.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.dingtalkEndpoint}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.endpoint,onChange:e=>s({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,L.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.debug,onChange:e=>s({debug:e.target.checked})}),e.dingtalkDebug]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.dmPolicy}),(0,L.jsx)(`select`,{className:w(),value:T.dmPolicy,onChange:e=>s({dmPolicy:e.target.value}),children:m.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.groupPolicy}),(0,L.jsx)(`select`,{className:w(),value:T.groupPolicy,onChange:e=>s({groupPolicy:e.target.value}),children:h.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.requireMention,onChange:e=>s({requireMention:e.target.checked})}),e.requireMention]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromDm}),(0,L.jsx)(`textarea`,{className:u(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:W(T.allowFrom),onChange:e=>s({allowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromDmDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromGroups}),(0,L.jsx)(`textarea`,{className:u(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:W(T.groupAllowFrom),onChange:e=>s({groupAllowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.historyLimit}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.historyLimit),onChange:e=>s({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.textChunkLimit}),(0,L.jsx)(`input`,{className:u(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.textChunkLimit),onChange:e=>s({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,L.jsx)(Se,{accountIds:he(T),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:g?.items??[],disabled:_,onChange:(e,t)=>c(`dingtalk`,e,t),ch:e}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.multiAccountJson}),(0,L.jsx)(`textarea`,{className:u(w(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:l,onChange:e=>d(e.target.value),onBlur:p,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),f?(0,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:f}):(0,L.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!v||_,onClick:C,children:e.discard}),(0,L.jsx)(O,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!v||_,onClick:async()=>{await y()},children:_?e.saving:e.save})]})]})]})}var Y=e(t(),1),X=e(ue(),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:`open`,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:`open`,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:`open`,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||`open`,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||`open`,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||`open`,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,pe(g.telegram),me(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 D(F(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Q(e){return(await D(F(`/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,pe(t),me(n),B(r),he(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await D(F(`/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 ie(),s?Te(s):{...e,bindingsFull:a}}async function Oe(e){return(await D(F(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function ke(e){return(await D(F(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function Ae(){return(await D(F(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function je(e){return(await D(F(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Me({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[a,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(null),[m,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(!1),T=(0,Y.useCallback)(async()=>{b(null),d(null),v(null),c(!0);try{let e=await Ae();v(e.qrUrl),d(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),b(null),S(null),w(!1),c(!1);return}T()},[e,T]),(0,Y.useEffect)(()=>{if(!l)return;let e=!1,n,i=async()=>{try{let i=await je(l);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),d(null),i.ok?(v(null),t(!1),r({clientId:i.clientId})):(b(i.message),v(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),b(i.message),d(null),v(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),b(t instanceof Error?t.message:`Request failed`),d(null),v(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[l,t,r]),(0,Y.useEffect)(()=>{if(!m){S(null),w(!1);return}let e=!1;return w(!1),X.toDataURL(m,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||S(t)}).catch(()=>{e||(w(!0),S(null))}),()=>{e=!0}},[m]);let E=!!(m&&l),D=e&&!y&&!E;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})}),(0,L.jsx)(p,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,L.jsx)(j,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,L.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,L.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,L.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(E||D)?(0,L.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:D?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,L.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`,D&&`bg-surface-muted/40 dark:bg-surface-base`),children:[D?(0,L.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,E&&m&&!y&&x&&!C?(0,L.jsx)(`img`,{src:x,alt:``,className:`relative z-[1] size-full object-contain`}):null,E&&m&&!y&&!x&&!C&&!D?(0,L.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,E&&m&&!y&&C?(0,L.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,L.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,L.jsxs)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,L.jsx)(g,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,L.jsx)(`div`,{className:`mt-6`,children:(0,L.jsx)(O,{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:a,onClick:()=>void T(),children:a?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),i?(0,L.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:d,updateFeishu:f,updateChannelAgentRoute:p,feishuAccountsDraft:m,setFeishuAccountsDraft:h,feishuAccountsError:g,onFeishuAccountsBlur:_,dmOpts:v,groupOpts:y,chatAgents:C,saving:w,dirty:T,save:D,discard:k}){let A=H,j=t.feishu,M=n?.feishu?.appSecret??``,N=!r&&!!String(M).trim()&&j.appSecret===M;return(0,L.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,L.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,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(E,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:j.enabled,onChange:e=>f({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,L.jsxs)(`div`,{className:`space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.feishuAppId,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.appId,onChange:e=>f({appId:e.target.value}),placeholder:`cli_xxx`}),(0,L.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[e.feishuAppSecret,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:N,value:N?`*`.repeat(Math.max(1,j.appSecret.length)):j.appSecret,onChange:e=>{N||f({appSecret:e.target.value})},placeholder:`••••••••`}),j.appSecret?(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void l(),children:[s?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),s?e.copied:e.copy]}):null,(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,L.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.feishuDomain}),(0,L.jsxs)(`select`,{className:A(),value:String(j.domain||`feishu`),onChange:e=>f({domain:e.target.value}),children:[(0,L.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,L.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.connectionMode}),(0,L.jsxs)(`select`,{className:A(),value:j.connectionMode,onChange:e=>f({connectionMode:e.target.value}),children:[(0,L.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,L.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,L.jsx)(q,{children:e.connectionModeDesc})]})]}),j.connectionMode===`webhook`?(0,L.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,L.jsxs)(`div`,{className:`flex gap-2`,children:[(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e=>!e),children:[a?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),a?e.hide:e.show]}),(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void d(),children:[c?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),c?e.copied:e.copy]})]})]}),(0,L.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.verificationToken}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:j.verificationToken??``,onChange:e=>f({verificationToken:e.target.value})}),(0,L.jsx)(q,{children:e.verificationTokenDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.encryptKey}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:j.encryptKey??``,onChange:e=>f({encryptKey:e.target.value})}),(0,L.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,L.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,L.jsx)(K,{children:e.webhookHost}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookHost??``,onChange:e=>f({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.webhookPort}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.webhookPort??``),onChange:e=>f({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,L.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.webhookPath}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookPath??``,onChange:e=>f({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,L.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.renderMode}),(0,L.jsxs)(`select`,{className:A(),value:j.renderMode,onChange:e=>f({renderMode:e.target.value}),children:[(0,L.jsx)(`option`,{value:`auto`,children:`auto`}),(0,L.jsx)(`option`,{value:`raw`,children:`raw`}),(0,L.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.reactionNotifications}),(0,L.jsxs)(`select`,{className:A(),value:j.reactionNotifications,onChange:e=>f({reactionNotifications:e.target.value}),children:[(0,L.jsx)(`option`,{value:`off`,children:`off`}),(0,L.jsx)(`option`,{value:`own`,children:`own`}),(0,L.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.streaming,onChange:e=>f({streaming:e.target.checked})}),e.enableStreaming]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.dmPolicy}),(0,L.jsx)(`select`,{className:A(),value:j.dmPolicy,onChange:e=>f({dmPolicy:e.target.value}),children:v.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.groupPolicy}),(0,L.jsx)(`select`,{className:A(),value:j.groupPolicy,onChange:e=>f({groupPolicy:e.target.value}),children:y.map(e=>(0,L.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.requireMention,onChange:e=>f({requireMention:e.target.checked})}),e.requireMention]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromDm}),(0,L.jsx)(`textarea`,{className:u(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:W(j.allowFrom),onChange:e=>f({allowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromDmDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.allowFromGroups}),(0,L.jsx)(`textarea`,{className:u(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:W(j.groupAllowFrom),onChange:e=>f({groupAllowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.historyLimit}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.historyLimit),onChange:e=>f({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.textChunkLimit}),(0,L.jsx)(`input`,{className:u(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.textChunkLimit),onChange:e=>f({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,L.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,L.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,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.tools?.[e],onChange:t=>f({tools:{...j.tools,[e]:t.target.checked}})}),t]},e))}),(0,L.jsx)(`div`,{className:`mt-2`,children:(0,L.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,L.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,L.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.actions?.reactions,onChange:e=>f({actions:{...j.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,L.jsx)(Se,{accountIds:B(j),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:C?.items??[],disabled:w,onChange:(e,t)=>p(`feishu`,e,t),ch:e}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:e.multiAccountJson}),(0,L.jsx)(`textarea`,{className:u(A(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:m,onChange:e=>h(e.target.value),onBlur:_,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),g?(0,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:g}):(0,L.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:k,children:e.discard}),(0,L.jsx)(O,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:async()=>{await D()},children:w?e.saving:e.save})]})]})]})}function Pe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[a,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(`feishu`),[m,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useCallback)(async e=>{d(e),S(null),v(null),b(null),c(!0);try{let t=await Oe({domain:e});b(t.qrUrl),v(t.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){v(null),b(null),S(null),w(null),E(!1),d(`feishu`),c(!1);return}D(`feishu`)},[e,D]),(0,Y.useEffect)(()=>{if(!m)return;let e=!1,n,i=async()=>{try{let i=await ke(m);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),v(null),i.ok?(b(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(S(i.message),b(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),S(i.message),v(null),b(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),S(t instanceof Error?t.message:`Request failed`),v(null),b(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[m,t,r]),(0,Y.useEffect)(()=>{if(!y){w(null),E(!1);return}let e=!1;return E(!1),X.toDataURL(y,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[y]);let A=!!(y&&m),N=e,P=e&&!x&&!A;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})}),(0,L.jsx)(p,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,L.jsx)(j,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,L.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,L.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[x?(0,L.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:x}):null,!x&&(A||P)?(0,L.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:P?n.feishuQrStarting:n.feishuQrScanHint}),(0,L.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,L.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&y&&!x&&C&&!T?(0,L.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&y&&!x&&!C&&!T&&!P?(0,L.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,A&&y&&!x&&T?(0,L.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,L.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,L.jsxs)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,L.jsx)(g,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),N?(0,L.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,L.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,L.jsx)(`button`,{type:`button`,disabled:a,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,l===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void D(`feishu`),children:n.feishuRegionChina}),(0,L.jsx)(`button`,{type:`button`,disabled:a,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,l===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void D(`lark`),children:n.feishuRegionInternational})]})}):null,(0,L.jsx)(`div`,{className:`mt-6`,children:(0,L.jsx)(O,{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:a,onClick:()=>void D(l),children:a?n.feishuQrStarting:n.feishuQrRegenerate})}),i?(0,L.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,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.apiRoot}),(0,L.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.proxy}),(0,L.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,L.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,L.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:i}),(0,L.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:a}),(0,L.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:o}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.allowFromGroups}),(0,L.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,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.historyLimit}),(0,L.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.textChunkLimit}),(0,L.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,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.multiAccountJson}),(0,L.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,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l}):(0,L.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Fe({open:e,onOpenChange:t,ch:n,form:r,baseline:i,tgAdvanced:a,setTgAdvanced:c,showToken:l,setShowToken:d,copied:m,copyToken:g,updateTelegram:v,updateChannelAgentRoute:y,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:D,dmOpts:A,groupOpts:N,replyOpts:F,streamOpts:te,chatAgents:ne,saving:re,dirty:ie,save:ae,discard:oe}){let se=H,I=r.telegram,ce=i?ve(i.telegram):``,le=ve(I),ue=!l&&!!String(ce).trim()&&le===ce;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(p,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,L.jsx)(j,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})})]}),(0,L.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:I.enabled,onChange:e=>v({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,L.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsxs)(K,{children:[n.telegramToken,(0,L.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,L.jsx)(`input`,{className:u(se(),`min-w-0 flex-1 font-mono text-xs`),type:l?`text`:`password`,autoComplete:`off`,readOnly:ue,value:ue?`*`.repeat(Math.max(1,ce.length)):le,onChange:e=>{if(ue)return;let t=I.accounts?.default??Z(`default`);v({accounts:{...I.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),le?(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void g(),children:[m?(0,L.jsx)(S,{className:`size-3.5`}):(0,L.jsx)(P,{className:`size-3.5`}),m?n.copied:n.copy]}):null,(0,L.jsxs)(O,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>d(e=>!e),children:[l?(0,L.jsx)(x,{className:`size-3.5`}):(0,L.jsx)(b,{className:`size-3.5`}),l?n.hide:n.show]})]}),(0,L.jsx)(q,{children:n.telegramTokenDesc})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.allowFromDm}),(0,L.jsx)(`textarea`,{className:u(se(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:W(I.allowFrom),onChange:e=>v({allowFrom:U(e.target.value)})}),(0,L.jsx)(q,{children:n.allowFromDmDesc})]}),(0,L.jsx)(Se,{accountIds:pe(I),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:ne?.items??[],disabled:re,onChange:(e,t)=>y(`telegram`,e,t),ch:n}),(0,L.jsxs)(O,{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,L.jsx)(E,{className:u(`mr-1 size-4 transition-transform`,a&&`rotate-180`)}),a?n.advancedHide:n.advancedShow]}),a?(0,L.jsx)($,{tg:I,updateTelegram:v,ch:n,dmOpts:A,groupOpts:N,replyOpts:F,streamOpts:te,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:D}):null]}),(0,L.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,L.jsx)(O,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,L.jsx)(O,{type:`button`,variant:`secondary`,disabled:!ie||re,onClick:oe,children:n.discard}),(0,L.jsx)(O,{type:`button`,variant:`primary`,disabled:!ie||re,onClick:async()=>{await ae()&&t(!1)},children:re?n.saving:n.save})]})]})]})})}function Ie(){let e=v(e=>e.language),t=a(e),n=t.channelsSettings,i=!!C(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),[g,_]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(!1),[S,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(!1),[D,O]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(null),[j,M]=(0,Y.useState)(null),[N,P]=(0,Y.useState)(null),[ee,F]=(0,Y.useState)(!1),[te,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(!1),[I,ce]=(0,Y.useState)(!1),[le,ue]=(0,Y.useState)(!1),[L,de]=(0,Y.useState)(!1),[fe,R]=(0,Y.useState)(!1),[z,pe]=(0,Y.useState)(!1),[me,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(i?`gateway-chat-agents-ch`:null,ae,{revalidateOnFocus:!1}),{data:Ce,error:X,isLoading:Z,mutate:Ee}=y(i),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(!i){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)))},[i,Q,Oe]);let ke=!!(i&&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||!D||u)return;let e=we(),t=D===`weixin`?{...o,weixin:e.weixin}:D===`telegram`?{...o,telegram:e.telegram}:D===`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(``),O(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[o,D,u,n.saveError]),ze=(0,Y.useCallback)(async()=>{let e=o?ve(o.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),ue(!0),window.setTimeout(()=>ue(!1),2e3))},[o]),Be=(0,Y.useCallback)(e=>{Pe({appId:e.appId,domain:e.domain,enabled:!0}),Ee(),M(n.feishuQrSetupSuccess),window.setTimeout(()=>M(null),4e3)},[Pe,Ee,n.feishuQrSetupSuccess]),Ve=(0,Y.useCallback)(e=>{$({clientId:e.clientId,enabled:!0}),Ee(),P(n.dingtalkQrSetupSuccess),window.setTimeout(()=>P(null),4e3)},[$,Ee,n.dingtalkQrSetupSuccess]),He=(0,Y.useCallback)(async()=>{let e=o?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),R(!0),window.setTimeout(()=>R(!1),2e3))},[o]);return{language:e,m:t,ch:n,hasToken:i,loading:ke,fetchError:Ae,mutate:Ee,form:o,baseline:c,dirty:Oe,saving:u,error:f,saveOk:m,weixinModalOpen:g,setWeixinModalOpen:_,telegramModalOpen:b,setTelegramModalOpen:x,feishuModalOpen:S,setFeishuModalOpen:w,dingtalkModalOpen:T,setDingtalkModalOpen:E,removeTarget:D,setRemoveTarget:O,weixinSuccessBanner:k,setWeixinSuccessBanner:A,feishuSetupSuccessBanner:j,dingtalkSetupSuccessBanner:N,tgAdvanced:ee,setTgAdvanced:F,showToken:te,setShowToken:ne,showFeishuSecret:re,setShowFeishuSecret:ie,showFeishuWebhookSecrets:oe,setShowFeishuWebhookSecrets:se,showDingtalkSecret:I,setShowDingtalkSecret:ce,copied:le,feishuCopied:L,dingtalkCopied:fe,feishuWebhookCopied:z,tgAccountsDraft:me,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(()=>{}),de(!0),window.setTimeout(()=>de(!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(()=>{}),pe(!0),window.setTimeout(()=>pe(!1),2e3)},[o]),onTgAccountsBlur:(0,Y.useCallback)(()=>{if(!o)return;let e=me.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,me,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[a,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(null),[m,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useCallback)(async()=>{b(null),S(null),d(null),c(!0);try{let e=await Ee();v(e.qrcodeUrl),d(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),b(null),w(null),E(!1),S(null);return}D()},[e,D]),(0,Y.useEffect)(()=>{if(!l)return;let e=!1,i,a=async()=>{try{let a=await Q(l);if(e)return;if(a.phase===`polling`){v(a.qrcodeUrl),a.qrStatus===`scaned`?S(n.weixinQrLoginScanned):S(null);return}if(a.phase===`done`){i!==void 0&&(window.clearInterval(i),i=void 0),d(null),a.ok?(v(null),t(!1),await r()):(b(a.message),v(null));return}a.phase===`unknown`&&S(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),b(t instanceof Error?t.message:`Request failed`),d(null),v(null))}};return i=window.setInterval(()=>void a(),2e3),a(),()=>{e=!0,i!==void 0&&window.clearInterval(i)}},[l,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,Y.useEffect)(()=>{if(!m){w(null),E(!1);return}let e=!1;return E(!1),X.toDataURL(m,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[m]);let A=!!(m&&l),N=e&&!y&&!A;return(0,L.jsx)(f,{open:e,onOpenChange:t,children:(0,L.jsxs)(k,{children:[(0,L.jsx)(o,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,L.jsxs)(h,{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`,M,`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,L.jsx)(s,{asChild:!0,children:(0,L.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,L.jsx)(_,{className:`size-4`})})}),(0,L.jsx)(p,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,L.jsx)(j,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,L.jsxs)(`div`,{className:`text-center`,children:[(0,L.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,L.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,L.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,L.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(A||N)?(0,L.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,L.jsx)(`p`,{className:u(`min-h-[1.25rem] text-center text-sm`,x&&!N?`text-accent`:`text-fg-muted`),children:N?n.weixinQrLoginBusy:x??`\xA0`}),(0,L.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,L.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&m&&!y&&C&&!T?(0,L.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&m&&!y&&!C&&!T&&!N?(0,L.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,A&&m&&!y&&T?(0,L.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,L.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,L.jsxs)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,L.jsx)(g,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,L.jsx)(`div`,{className:`mt-6`,children:(0,L.jsx)(O,{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:a,onClick:()=>void D(),children:a?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),i?(0,L.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,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.weixinAllowFrom}),(0,L.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,L.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,L.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,L.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:i}),(0,L.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.historyLimit}),(0,L.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.textChunkLimit}),(0,L.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,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.weixinRouteTag}),(0,L.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,L.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,L.jsx)(q,{children:n.weixinDebugDesc}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,L.jsx)(K,{children:n.weixinAccountsJson}),(0,L.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,L.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}):(0,L.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,L.jsx)(Se,{accountIds:me(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,L.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,L.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,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(E,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,L.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,L.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,L.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,L.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,L.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,L.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,L.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,L.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,L.jsx)(O,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:h,children:e.discard}),(0,L.jsx)(O,{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:o,form:s,baseline:c,dirty:u,saving:d,error:f,saveOk:p,weixinModalOpen:m,setWeixinModalOpen:h,telegramModalOpen:_,setTelegramModalOpen:v,feishuModalOpen:y,setFeishuModalOpen:b,removeTarget:x,setRemoveTarget:S,weixinSuccessBanner:C,setWeixinSuccessBanner:w,dingtalkModalOpen:T,setDingtalkModalOpen:E,feishuSetupSuccessBanner:D,dingtalkSetupSuccessBanner:k,tgAdvanced:A,setTgAdvanced:j,showToken:M,setShowToken:P,showFeishuSecret:ee,setShowFeishuSecret:F,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,showDingtalkSecret:ae,setShowDingtalkSecret:oe,copied:se,feishuCopied:I,dingtalkCopied:ce,feishuWebhookCopied:le,tgAccountsDraft:ue,setTgAccountsDraft:R,tgAccountsError:z,wxAccountsDraft:pe,setWxAccountsDraft:me,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,L.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,L.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,L.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,L.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,L.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,L.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!s)return(0,L.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,L.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,L.jsx)(O,{type:`button`,variant:`secondary`,onClick:()=>void o(),children:n.retry})]});let We=s.weixin,Ge=s.telegram,Ke=s.feishu,qe=s.dingtalk,Je=be(We),Ye=ye(Ge),Xe=G(Ke),Ze=xe(qe),Qe=(0,L.jsx)(Ne,{ch:n,form:s,baseline:c,showFeishuSecret:ee,setShowFeishuSecret:F,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,feishuCopied:I,feishuWebhookCopied:le,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,L.jsx)(Ce,{ch:n,form:s,baseline:c,showDingtalkSecret:ae,setShowDingtalkSecret:oe,dingtalkCopied:ce,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,L.jsx)(ze,{ch:n,wx:We,updateWeixin:q,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:pe,setWxAccountsDraft:me,wxAccountsError:B,onWxAccountsBlur:je,form:s,chatAgents:W,onAgentRouteChange:(e,t)=>ve(`weixin`,e,t),saving:d,dirty:u,save:Y,discard:X});return(0,L.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,L.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,L.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,L.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,L.jsx)(g,{className:`size-3.5`})]})]}),u?(0,L.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,L.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,C?(0,L.jsx)(`p`,{className:`text-xs text-accent`,children:C}):null,D?(0,L.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:D}):null,k?(0,L.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:k}):null,(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(de,{icon:(0,L.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,L.jsx)(de,{icon:(0,L.jsx)(N,{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:()=>v(!0),onEdit:()=>v(!0),onRemove:()=>S(`telegram`),ch:n}),(0,L.jsx)(de,{icon:(0,L.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,L.jsx)(de,{icon:(0,L.jsx)(l,{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:()=>E(!0),onEdit:()=>E(!0),onRemove:()=>S(`dingtalk`),ch:n})]}),(0,L.jsx)(Le,{open:m,onOpenChange:h,ch:n,onLoginSuccess:async()=>{await o(),w(n.weixinQrLoginSuccess),window.setTimeout(()=>w(null),4e3)},moreSettings:et}),(0,L.jsx)(Fe,{open:_,onOpenChange:v,ch:n,form:s,baseline:c,tgAdvanced:A,setTgAdvanced:j,showToken:M,setShowToken:P,copied:se,copyToken:Te,updateTelegram:K,updateChannelAgentRoute:ve,tgAccountsDraft:ue,setTgAccountsDraft:R,tgAccountsError:z,onTgAccountsBlur:Ae,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),(0,L.jsx)(Pe,{open:y,onOpenChange:b,ch:n,onSetupSuccess:Ee,moreSettings:Qe}),(0,L.jsx)(Me,{open:T,onOpenChange:E,ch:n,onSetupSuccess:Q,moreSettings:$e}),(0,L.jsx)(fe,{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-jJX9xOyE.js.map