@xopcai/xopc 0.0.40 → 0.0.41

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 (34) hide show
  1. package/dist/extensions/telegram/xopc.extension.json +1 -1
  2. package/dist/gateway/static/root/assets/{agents-DcHp6W8S.js → agents-Cg_LGzbv.js} +2 -2
  3. package/dist/gateway/static/root/assets/{agents-DcHp6W8S.js.map → agents-Cg_LGzbv.js.map} +1 -1
  4. package/dist/gateway/static/root/assets/{apps-page-W9XwqSi7.js → apps-page-CW1VZ5L2.js} +2 -2
  5. package/dist/gateway/static/root/assets/{apps-page-W9XwqSi7.js.map → apps-page-CW1VZ5L2.js.map} +1 -1
  6. package/dist/gateway/static/root/assets/{channels-settings-m10wg_Lg.js → channels-settings-BDkP3YdO.js} +2 -2
  7. package/dist/gateway/static/root/assets/{channels-settings-m10wg_Lg.js.map → channels-settings-BDkP3YdO.js.map} +1 -1
  8. package/dist/gateway/static/root/assets/{cron-api-DIzlYLdG.js → cron-api-BF3i6fQ6.js} +2 -2
  9. package/dist/gateway/static/root/assets/{cron-api-DIzlYLdG.js.map → cron-api-BF3i6fQ6.js.map} +1 -1
  10. package/dist/gateway/static/root/assets/{cron-page-B5nTa2u4.js → cron-page-C82UvjSi.js} +2 -2
  11. package/dist/gateway/static/root/assets/{cron-page-B5nTa2u4.js.map → cron-page-C82UvjSi.js.map} +1 -1
  12. package/dist/gateway/static/root/assets/{dist-DL8vJx7B.js → dist-KXNTFU5L.js} +2 -2
  13. package/dist/gateway/static/root/assets/{dist-DL8vJx7B.js.map → dist-KXNTFU5L.js.map} +1 -1
  14. package/dist/gateway/static/root/assets/{extension-debug-page-DMkgbZXH.js → extension-debug-page-Cb1TVFq8.js} +2 -2
  15. package/dist/gateway/static/root/assets/{extension-debug-page-DMkgbZXH.js.map → extension-debug-page-Cb1TVFq8.js.map} +1 -1
  16. package/dist/gateway/static/root/assets/{extension-page-D5iyUHNi.js → extension-page-ClpFl3ym.js} +2 -2
  17. package/dist/gateway/static/root/assets/{extension-page-D5iyUHNi.js.map → extension-page-ClpFl3ym.js.map} +1 -1
  18. package/dist/gateway/static/root/assets/{extension-settings-page-DXYuT-Dq.js → extension-settings-page-AawKA54u.js} +2 -2
  19. package/dist/gateway/static/root/assets/{extension-settings-page-DXYuT-Dq.js.map → extension-settings-page-AawKA54u.js.map} +1 -1
  20. package/dist/gateway/static/root/assets/{index-Cir8fqd7.js → index-DFgsyQna.js} +5 -5
  21. package/dist/gateway/static/root/assets/{index-Cir8fqd7.js.map → index-DFgsyQna.js.map} +1 -1
  22. package/dist/gateway/static/root/assets/{logs-page-BuugMrI_.js → logs-page-DCH6aatp.js} +2 -2
  23. package/dist/gateway/static/root/assets/{logs-page-BuugMrI_.js.map → logs-page-DCH6aatp.js.map} +1 -1
  24. package/dist/gateway/static/root/assets/{sessions-page-CaRD3IvA.js → sessions-page-DgAIvstc.js} +2 -2
  25. package/dist/gateway/static/root/assets/{sessions-page-CaRD3IvA.js.map → sessions-page-DgAIvstc.js.map} +1 -1
  26. package/dist/gateway/static/root/assets/{settings-page-DYOSuaHt.js → settings-page-CyQrYfl-.js} +2 -2
  27. package/dist/gateway/static/root/assets/{settings-page-DYOSuaHt.js.map → settings-page-CyQrYfl-.js.map} +1 -1
  28. package/dist/gateway/static/root/assets/{skills-page-CN7HsYLQ.js → skills-page-BR5vm_QN.js} +2 -2
  29. package/dist/gateway/static/root/assets/{skills-page-CN7HsYLQ.js.map → skills-page-BR5vm_QN.js.map} +1 -1
  30. package/dist/gateway/static/root/assets/{use-image-provider-credentials-DPIDwada.js → use-image-provider-credentials-DGrrG5oe.js} +2 -2
  31. package/dist/gateway/static/root/assets/{use-image-provider-credentials-DPIDwada.js.map → use-image-provider-credentials-DGrrG5oe.js.map} +1 -1
  32. package/dist/gateway/static/root/index.html +1 -1
  33. package/dist/package.js +1 -1
  34. 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-DKvYJ-LI.js";import{An as i,At as a,Cn as o,Cr as s,Dn as c,Dt as l,Fn as u,Jr as d,Ln as f,Mn as p,Mt as m,Nt as h,Ot as g,St as _,Wn as v,Xr as y,Yr as b,_ as x,_r as S,bt as C,dn as w,ei as T,gn as E,ir as D,jn as O,jt as k,kn as A,kt as j,mi as M,pi as N,qr as P,v as ee,vn as te,w as ne,xr as re,xt as ie,y as ae,yn as oe}from"./index-Cir8fqd7.js";import{a as se,i as ce,n as F,r as le,t as ue}from"./dist-DL8vJx7B.js";import{t as de}from"./browser-DNXWYwzc.js";var I=n();function fe({icon:e,title:t,subtitle:n,configured:r,enabled:i,onToggle:a,toggleDisabled:o,onConfigure:s,onEdit:c,onRemove:l,ch:d}){return(0,I.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-2xl border border-edge bg-surface-base px-4 py-4 dark:border-edge sm:flex-row sm:items-center sm:gap-4`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,I.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,I.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:d.hubConnectedBadge}):null]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,I.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,I.jsxs)(ce,{children:[(0,I.jsx)(se,{asChild:!0,children:(0,I.jsx)(p,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":d.menuMoreAria,children:(0,I.jsx)(y,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,I.jsx)(le,{children:(0,I.jsxs)(ue,{className:u(`min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,ae),sideOffset:6,align:`end`,children:[(0,I.jsx)(F,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>c(),children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(S,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),d.menuEditConfig]})}),(0,I.jsx)(F,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-danger outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>l(),children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(v,{className:`size-4 shrink-0`,strokeWidth:1.75}),d.menuRemoveConfig]})})]})})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} — ${d.enableChannelAria}`,disabled:o,className:u(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,i?`justify-end bg-accent`:`justify-start bg-surface-hover`,o&&`cursor-not-allowed opacity-50`),onClick:()=>void a(!i),children:(0,I.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,I.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:s,children:d.hubConfigureButton})})]})}function pe({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:i,saving:o,onConfirmRemove:s}){return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{className:u(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,x,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(h,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,I.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,I.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,onClick:i,children:n.modalCancel}),(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:o,onClick:s,children:o?n.saving:n.removeChannelAction})]})]})]})})}function L(e){return(e??``).trim().toLowerCase()}function R(e){let t=e.match;return!(!t?.channel||!t.accountId||t.peerId||t.peerKind||t.guildId||t.teamId||t.memberRoleIds&&t.memberRoleIds.length>0)}function me(e){return Object.keys(e.accounts??{}).sort()}function z(e){return Object.keys(e.accounts??{}).sort()}function B(e){let t=Object.keys(e.accounts??{});return t.length>0?[...t].sort():typeof e.appId==`string`&&e.appId.trim()&&typeof e.appSecret==`string`&&e.appSecret.trim()?[`default`]:[]}function he(e){let t=Object.keys(e.accounts??{});return t.length>0?[...t].sort():typeof e.clientId==`string`&&e.clientId.trim()&&typeof e.clientSecret==`string`&&e.clientSecret.trim()?[`default`]:[]}function V(e,t,n,r,i,a){let o={},s={},c={},l={};for(let n of t)o[n]=(e.find(e=>L(e.match?.channel)===`telegram`&&L(e.match?.accountId)===L(n)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of n)s[t]=(e.find(e=>L(e.match?.channel)===`weixin`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of r)c[t]=(e.find(e=>L(e.match?.channel)===`feishu`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of i)l[t]=(e.find(e=>L(e.match?.channel)===`dingtalk`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();return{telegram:o,weixin:s,feishu:c,dingtalk:l}}function ge(e,t,n,r,i,a,o){let s=new Set(n.map(L)),c=new Set(r.map(L)),l=new Set(i.map(L)),u=new Set(a.map(L)),d=e.filter(e=>{if(e.id?.startsWith(`ui:route:account:`))return!1;if(!R(e))return!0;let t=L(e.match.channel),n=L(e.match.accountId);return!n||n===`*`?!0:!(t===`telegram`&&s.has(n)||t===`weixin`&&c.has(n)||t===`feishu`&&l.has(n)||t===`dingtalk`&&u.has(n))}),f=[];for(let e of n){let n=(t.telegram[e]??t.telegram[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:telegram:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`telegram`,accountId:e}})}for(let e of r){let n=(t.weixin[e]??t.weixin[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:weixin:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`weixin`,accountId:e}})}for(let e of i){let n=(t.feishu[e]??t.feishu[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:feishu:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`feishu`,accountId:e}})}for(let e of a){let n=(t.dingtalk[e]??t.dingtalk[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:dingtalk:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`dingtalk`,accountId:e}})}return[...d,...f]}function H(){return u(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,i,`dark:border-edge`)}function _e(){return u(A,c)}function U(e){return e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean).map(e=>/^-?\d+$/.test(e)?Number(e):e)}function W(e){return e.map(String).join(`, `)}function ve(e){let t=e.accounts?.default?.botToken;return typeof t==`string`?t:``}function ye(e){return Object.values(e.accounts??{}).some(e=>typeof e.botToken==`string`&&e.botToken.trim().length>0)}function be(e){return Object.keys(e.accounts??{}).length>0||e.allowFrom.length>0}function G(e){return!!(e.appId?.trim()&&e.appSecret?.trim())||Object.keys(e.accounts??{}).length>0}function xe(e){return!!(e.clientId?.trim()&&e.clientSecret?.trim())||Object.keys(e.accounts??{}).length>0}function K({children:e}){return(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e}),(0,I.jsx)(`select`,{className:_e(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Se({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:i,onChange:a,ch:s}){let l=O(o(e=>e.language)).agentsSettings;if(e.length===0)return null;let d=r.length>0?r:[{id:n}];return(0,I.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(K,{children:s.agentRoutingTitle}),(0,I.jsx)(q,{children:s.agentRoutingHint})]}),(0,I.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 sm:grid-cols-2 sm:items-center dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,I.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,I.jsx)(`select`,{id:`agent-route-${e}`,className:u(H(),c),disabled:i,value:(t[e]??n).toLowerCase(),onChange:t=>a(e,t.target.value),children:d.map(e=>(0,I.jsx)(`option`,{value:e.id,children:`${ne(e,l)} (${e.id})`},e.id))})]})]},e))})]})}function Ce({ch:e,form:t,baseline:n,showDingtalkSecret:r,setShowDingtalkSecret:i,dingtalkCopied:a,copyDingtalkSecret:o,updateDingtalk:s,updateChannelAgentRoute:c,dingtalkAccountsDraft:l,setDingtalkAccountsDraft:f,dingtalkAccountsError:m,onDingtalkAccountsBlur:h,dmOpts:g,groupOpts:_,chatAgents:v,saving:y,dirty:b,save:x,discard:S}){let C=H,w=t.dingtalk,E=n?.dingtalk?.clientSecret??``,D=!r&&!!String(E).trim()&&w.clientSecret===E;return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(N,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:w.enabled,onChange:e=>s({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.dingtalkClientId,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),value:w.clientId,onChange:e=>s({clientId:e.target.value}),placeholder:`dingxxx`}),(0,I.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.dingtalkClientSecret,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:D,value:D?`*`.repeat(Math.max(1,w.clientSecret.length)):w.clientSecret,onChange:e=>{D||s({clientSecret:e.target.value})},placeholder:`••••••••`}),w.clientSecret?(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void o(),children:[a?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),a?e.copied:e.copy]}):null,(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,I.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dingtalkEndpoint}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),value:w.endpoint,onChange:e=>s({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,I.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:w.debug,onChange:e=>s({debug:e.target.checked})}),e.dingtalkDebug]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dmPolicy}),(0,I.jsx)(`select`,{className:C(),value:w.dmPolicy,onChange:e=>s({dmPolicy:e.target.value}),children:g.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.groupPolicy}),(0,I.jsx)(`select`,{className:C(),value:w.groupPolicy,onChange:e=>s({groupPolicy:e.target.value}),children:_.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:w.requireMention,onChange:e=>s({requireMention:e.target.checked})}),e.requireMention]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(C(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:W(w.allowFrom),onChange:e=>s({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromDmDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(C(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:W(w.groupAllowFrom),onChange:e=>s({groupAllowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.historyLimit}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(w.historyLimit),onChange:e=>s({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.textChunkLimit}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(w.textChunkLimit),onChange:e=>s({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,I.jsx)(Se,{accountIds:he(w),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:v?.items??[],disabled:y,onChange:(e,t)=>c(`dingtalk`,e,t),ch:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(C(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:l,onChange:e=>f(e.target.value),onBlur:h,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),m?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:m}):(0,I.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!b||y,onClick:S,children:e.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!b||y,onClick:async()=>{await x()},children:y?e.saving:e.save})]})]})]})}var Y=e(t(),1),X=e(de(),1);function Z(e){return{accountId:e,name:``,enabled:!0,botToken:``,allowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,apiRoot:``,proxy:``,historyLimit:50,textChunkLimit:4e3,streamMode:`partial`}}function we(){return{bindingsFull:[],channelAgentRoutes:{telegram:{},weixin:{},feishu:{},dingtalk:{}},defaultAgentId:`main`,telegram:{enabled:!1,apiRoot:``,debug:!1,allowFrom:[],groupAllowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,streamMode:`partial`,historyLimit:50,textChunkLimit:4e3,proxy:``,accounts:{default:Z(`default`)}},weixin:{enabled:!1,dmPolicy:`pairing`,allowFrom:[],debug:!1,streamMode:`partial`,historyLimit:50,textChunkLimit:4e3,routeTag:``,accounts:{}},feishu:{enabled:!1,defaultAccount:``,appId:``,appSecret:``,domain:`feishu`,connectionMode:`websocket`,verificationToken:``,encryptKey:``,webhookHost:`127.0.0.1`,webhookPort:3e3,webhookPath:`/feishu/events`,dmPolicy:`pairing`,groupPolicy:`allowlist`,allowFrom:[],groupAllowFrom:[],requireMention:!0,historyLimit:50,textChunkLimit:4e3,renderMode:`auto`,streaming:!1,reactionNotifications:`own`,tools:{doc:!0,wiki:!0,drive:!0,scopes:!0,bitable:!0,perm:!1},actions:{reactions:!0},accounts:{}},dingtalk:{enabled:!1,defaultAccount:``,clientId:``,clientSecret:``,dmPolicy:`pairing`,groupPolicy:`open`,allowFrom:[],groupAllowFrom:[],requireMention:!1,debug:!1,endpoint:`https://api.dingtalk.com`,historyLimit:50,textChunkLimit:4e3,accounts:{}}}}function Te(e){let t=e&&typeof e==`object`?e.channels:void 0,n=t&&typeof t==`object`?t:{},r=n.telegram,i=n.weixin,a=n.feishu,o=n.dingtalk,s=r?.accounts,c=s&&typeof s==`object`&&!Array.isArray(s)?{...s}:{},l=typeof r?.botToken==`string`?r.botToken.trim():``,u=c.default?.botToken?.trim()??``;l&&!u&&(c={...c,default:{...c.default??Z(`default`),accountId:`default`,botToken:l}}),c.default||(c={...c,default:Z(`default`)});let d=i?.accounts,f=d&&typeof d==`object`&&!Array.isArray(d)?d:{},p=(()=>{let t=(e&&typeof e==`object`?e:{}).bindings;return Array.isArray(t)?t:[]})(),m=(()=>{let t=(e&&typeof e==`object`?e:{}).agents;return t&&typeof t==`object`?t:{}})(),h=typeof m.defaultId==`string`&&m.defaultId.trim()?m.defaultId.trim().toLowerCase():`main`,g={telegram:{enabled:!!r?.enabled,apiRoot:typeof r?.apiRoot==`string`?r.apiRoot:``,debug:!!r?.debug,allowFrom:Array.isArray(r?.allowFrom)?[...r.allowFrom]:[],groupAllowFrom:Array.isArray(r?.groupAllowFrom)?[...r.groupAllowFrom]:[],dmPolicy:r?.dmPolicy||`pairing`,groupPolicy:r?.groupPolicy||`open`,replyToMode:r?.replyToMode||`off`,streamMode:r?.streamMode??`partial`,historyLimit:typeof r?.historyLimit==`number`?r.historyLimit:50,textChunkLimit:typeof r?.textChunkLimit==`number`?r.textChunkLimit:4e3,proxy:typeof r?.proxy==`string`?r.proxy:``,accounts:{...c}},weixin:{enabled:!!i?.enabled,dmPolicy:i?.dmPolicy||`pairing`,allowFrom:Array.isArray(i?.allowFrom)?[...i.allowFrom]:[],debug:!!i?.debug,streamMode:i?.streamMode??`partial`,historyLimit:typeof i?.historyLimit==`number`?i.historyLimit:50,textChunkLimit:typeof i?.textChunkLimit==`number`?i.textChunkLimit:4e3,routeTag:i?.routeTag==null?``:String(i.routeTag),accounts:{...f}},feishu:{enabled:!!a?.enabled,defaultAccount:typeof a?.defaultAccount==`string`?a.defaultAccount:``,appId:typeof a?.appId==`string`?a.appId:``,appSecret:typeof a?.appSecret==`string`?a.appSecret:``,domain:typeof a?.domain==`string`&&a.domain||`feishu`,connectionMode:a?.connectionMode||`websocket`,verificationToken:typeof a?.verificationToken==`string`?a.verificationToken:``,encryptKey:typeof a?.encryptKey==`string`?a.encryptKey:``,webhookHost:typeof a?.webhookHost==`string`?a.webhookHost:`127.0.0.1`,webhookPort:typeof a?.webhookPort==`number`?a.webhookPort:3e3,webhookPath:typeof a?.webhookPath==`string`?a.webhookPath:`/feishu/events`,dmPolicy:a?.dmPolicy||`pairing`,groupPolicy:a?.groupPolicy||`allowlist`,allowFrom:Array.isArray(a?.allowFrom)?[...a.allowFrom]:[],groupAllowFrom:Array.isArray(a?.groupAllowFrom)?[...a.groupAllowFrom]:[],requireMention:a?.requireMention===void 0?!0:!!a.requireMention,historyLimit:typeof a?.historyLimit==`number`?a.historyLimit:50,textChunkLimit:typeof a?.textChunkLimit==`number`?a.textChunkLimit:4e3,renderMode:a?.renderMode||`auto`,streaming:a?.streaming===void 0?!1:!!a.streaming,reactionNotifications:a?.reactionNotifications||`own`,tools:a?.tools&&typeof a.tools==`object`&&!Array.isArray(a.tools)?{...a.tools}:void 0,actions:a?.actions&&typeof a.actions==`object`&&!Array.isArray(a.actions)?{...a.actions}:void 0,accounts:a?.accounts&&typeof a.accounts==`object`&&!Array.isArray(a.accounts)?{...a.accounts}:{}},dingtalk:{enabled:!!o?.enabled,defaultAccount:typeof o?.defaultAccount==`string`?o.defaultAccount:``,clientId:typeof o?.clientId==`string`?o.clientId:``,clientSecret:typeof o?.clientSecret==`string`?o.clientSecret:``,dmPolicy:o?.dmPolicy||`pairing`,groupPolicy:o?.groupPolicy||`open`,allowFrom:Array.isArray(o?.allowFrom)?[...o.allowFrom]:[],groupAllowFrom:Array.isArray(o?.groupAllowFrom)?[...o.groupAllowFrom]:[],requireMention:o?.requireMention===!0,debug:!!o?.debug,endpoint:typeof o?.endpoint==`string`&&o.endpoint.trim()?o.endpoint.trim():`https://api.dingtalk.com`,historyLimit:typeof o?.historyLimit==`number`?o.historyLimit:50,textChunkLimit:typeof o?.textChunkLimit==`number`?o.textChunkLimit:4e3,accounts:o?.accounts&&typeof o.accounts==`object`&&!Array.isArray(o.accounts)?{...o.accounts}:{}}},_=V(p,me(g.telegram),z(g.weixin),B(g.feishu),he(g.dingtalk),h);return{...g,bindingsFull:p.map(e=>({...e})),channelAgentRoutes:_,defaultAgentId:h}}async function Ee(e){return(await E(w(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Q(e){return(await E(w(`/api/channels/weixin/login/${encodeURIComponent(e)}`))).payload.status}async function De(e){let t=e.telegram,n=e.weixin,r=e.feishu,i=e.dingtalk,a=ge(e.bindingsFull,e.channelAgentRoutes,me(t),z(n),B(r),he(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await E(w(`/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 E(w(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function ke(e){return(await E(w(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function Ae(){return(await E(w(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function je(e){return(await E(w(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Me({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[o,s]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null),[y,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useCallback)(async()=>{S(null),d(null),v(null),s(!0);try{let e=await Ae();v(e.qrUrl),d(e.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{s(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),S(null),w(null),E(!1),s(!1);return}D()},[e,D]),(0,Y.useEffect)(()=>{if(!c)return;let e=!1,n,i=async()=>{try{let i=await je(c);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})):(S(i.message),v(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),S(i.message),d(null),v(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),S(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)}},[c,t,r]),(0,Y.useEffect)(()=>{if(!_){w(null),E(!1);return}let e=!1;return E(!1),X.toDataURL(_,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[_]);let O=!!(_&&c),A=e&&!y&&!O;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.dingtalkQrCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(h,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,I.jsx)(j,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(O||A)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:A?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,A&&`bg-surface-muted/40 dark:bg-surface-base`),children:[A?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,O&&_&&!y&&C&&!T?(0,I.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,O&&_&&!y&&!C&&!T&&!A?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,O&&_&&!y&&T?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,I.jsxs)(`a`,{href:_,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(b,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void D(),children:o?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function Ne({ch:e,form:t,baseline:n,showFeishuSecret:r,setShowFeishuSecret:i,showFeishuWebhookSecrets:a,setShowFeishuWebhookSecrets:o,feishuCopied:s,feishuWebhookCopied:c,copyFeishuSecret:l,copyFeishuWebhookConfig:f,updateFeishu:m,updateChannelAgentRoute:h,feishuAccountsDraft:g,setFeishuAccountsDraft:_,feishuAccountsError:v,onFeishuAccountsBlur:y,dmOpts:b,groupOpts:x,chatAgents:S,saving:C,dirty:w,save:E,discard:D}){let O=H,k=t.feishu,A=n?.feishu?.appSecret??``,j=!r&&!!String(A).trim()&&k.appSecret===A;return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(N,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:k.enabled,onChange:e=>m({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.feishuAppId,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.appId,onChange:e=>m({appId:e.target.value}),placeholder:`cli_xxx`}),(0,I.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.feishuAppSecret,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:j,value:j?`*`.repeat(Math.max(1,k.appSecret.length)):k.appSecret,onChange:e=>{j||m({appSecret:e.target.value})},placeholder:`••••••••`}),k.appSecret?(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void l(),children:[s?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),s?e.copied:e.copy]}):null,(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,I.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.feishuDomain}),(0,I.jsxs)(`select`,{className:O(),value:String(k.domain||`feishu`),onChange:e=>m({domain:e.target.value}),children:[(0,I.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,I.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.connectionMode}),(0,I.jsxs)(`select`,{className:O(),value:k.connectionMode,onChange:e=>m({connectionMode:e.target.value}),children:[(0,I.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,I.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,I.jsx)(q,{children:e.connectionModeDesc})]})]}),k.connectionMode===`webhook`?(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e=>!e),children:[a?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),a?e.hide:e.show]}),(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void f(),children:[c?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),c?e.copied:e.copy]})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.verificationToken}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:k.verificationToken??``,onChange:e=>m({verificationToken:e.target.value})}),(0,I.jsx)(q,{children:e.verificationTokenDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.encryptKey}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:k.encryptKey??``,onChange:e=>m({encryptKey:e.target.value})}),(0,I.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,I.jsx)(K,{children:e.webhookHost}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.webhookHost??``,onChange:e=>m({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.webhookPort}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.webhookPort??``),onChange:e=>m({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.webhookPath}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.webhookPath??``,onChange:e=>m({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,I.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.renderMode}),(0,I.jsxs)(`select`,{className:O(),value:k.renderMode,onChange:e=>m({renderMode:e.target.value}),children:[(0,I.jsx)(`option`,{value:`auto`,children:`auto`}),(0,I.jsx)(`option`,{value:`raw`,children:`raw`}),(0,I.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.reactionNotifications}),(0,I.jsxs)(`select`,{className:O(),value:k.reactionNotifications,onChange:e=>m({reactionNotifications:e.target.value}),children:[(0,I.jsx)(`option`,{value:`off`,children:`off`}),(0,I.jsx)(`option`,{value:`own`,children:`own`}),(0,I.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:k.streaming,onChange:e=>m({streaming:e.target.checked})}),e.enableStreaming]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dmPolicy}),(0,I.jsx)(`select`,{className:O(),value:k.dmPolicy,onChange:e=>m({dmPolicy:e.target.value}),children:b.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.groupPolicy}),(0,I.jsx)(`select`,{className:O(),value:k.groupPolicy,onChange:e=>m({groupPolicy:e.target.value}),children:x.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:k.requireMention,onChange:e=>m({requireMention:e.target.checked})}),e.requireMention]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:W(k.allowFrom),onChange:e=>m({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromDmDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:W(k.groupAllowFrom),onChange:e=>m({groupAllowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.historyLimit}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.historyLimit),onChange:e=>m({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.textChunkLimit}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.textChunkLimit),onChange:e=>m({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,I.jsx)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:[[`doc`,e.feishuToolDoc],[`wiki`,e.feishuToolWiki],[`drive`,e.feishuToolDrive],[`perm`,e.feishuToolPerm],[`bitable`,e.feishuToolBitable],[`scopes`,e.feishuToolScopes]].map(([e,t])=>(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!k.tools?.[e],onChange:t=>m({tools:{...k.tools,[e]:t.target.checked}})}),t]},e))}),(0,I.jsx)(`div`,{className:`mt-2`,children:(0,I.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,I.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!k.actions?.reactions,onChange:e=>m({actions:{...k.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,I.jsx)(Se,{accountIds:B(k),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:S?.items??[],disabled:C,onChange:(e,t)=>h(`feishu`,e,t),ch:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:g,onChange:e=>_(e.target.value),onBlur:y,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),v?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:v}):(0,I.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!w||C,onClick:D,children:e.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!w||C,onClick:async()=>{await E()},children:C?e.saving:e.save})]})]})]})}function Pe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[o,s]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(`feishu`),[_,v]=(0,Y.useState)(null),[y,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(!1),A=(0,Y.useCallback)(async e=>{d(e),w(null),v(null),S(null),s(!0);try{let t=await Oe({domain:e});S(t.qrUrl),v(t.sessionKey)}catch(e){w(e instanceof Error?e.message:`Start failed`)}finally{s(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){v(null),S(null),w(null),E(null),O(!1),d(`feishu`),s(!1);return}A(`feishu`)},[e,A]),(0,Y.useEffect)(()=>{if(!_)return;let e=!1,n,i=async()=>{try{let i=await ke(_);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),v(null),i.ok?(S(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(w(i.message),S(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),w(i.message),v(null),S(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),w(t instanceof Error?t.message:`Request failed`),v(null),S(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[_,t,r]),(0,Y.useEffect)(()=>{if(!y){E(null),O(!1);return}let e=!1;return O(!1),X.toDataURL(y,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||E(t)}).catch(()=>{e||(O(!0),E(null))}),()=>{e=!0}},[y]);let M=!!(y&&_),N=e,P=e&&!C&&!M;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.feishuQrCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(h,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,I.jsx)(j,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[C?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:C}):null,!C&&(M||P)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:P?n.feishuQrStarting:n.feishuQrScanHint}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,P&&`bg-surface-muted/40 dark:bg-surface-base`),children:[P?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,M&&y&&!C&&T&&!D?(0,I.jsx)(`img`,{src:T,alt:``,className:`relative z-[1] size-full object-contain`}):null,M&&y&&!C&&!T&&!D&&!P?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,M&&y&&!C&&D?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,I.jsxs)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(b,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),N?(0,I.jsx)(`div`,{className:`mx-auto mt-4 flex w-full max-w-[20rem] justify-center px-1`,role:`group`,"aria-label":n.feishuRegionSwitchAria,children:(0,I.jsxs)(`div`,{className:`inline-flex w-full rounded-full border border-edge bg-surface-muted/60 p-1 dark:border-edge dark:bg-surface-base`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:o,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,c===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void A(`feishu`),children:n.feishuRegionChina}),(0,I.jsx)(`button`,{type:`button`,disabled:o,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,c===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void A(`lark`),children:n.feishuRegionInternational})]})}):null,(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void A(c),children:o?n.feishuQrStarting:n.feishuQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function $({tg:e,updateTelegram:t,ch:n,dmOpts:r,groupOpts:i,replyOpts:a,streamOpts:o,tgAccountsDraft:s,setTgAccountsDraft:c,tgAccountsError:l,onTgAccountsBlur:d}){let f=H;return(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.apiRoot}),(0,I.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.proxy}),(0,I.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,I.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,I.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:i}),(0,I.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:a}),(0,I.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:o}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(f(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`-1001234567890`,value:W(e.groupAllowFrom),onChange:e=>t({groupAllowFrom:U(e.target.value)})})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.historyLimit}),(0,I.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.textChunkLimit}),(0,I.jsx)(`input`,{type:`number`,min:1e3,max:1e4,step:100,className:f(),value:e.textChunkLimit,onChange:e=>t({textChunkLimit:parseInt(e.target.value,10)||4e3})})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(f(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:s,onChange:e=>c(e.target.value),onBlur:d,placeholder:`{ "personal": { "accountId": "personal", "botToken": "...", ... } }`}),l?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l}):(0,I.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Fe({open:e,onOpenChange:t,ch:n,form:r,baseline:i,tgAdvanced:o,setTgAdvanced:s,showToken:c,setShowToken:_,copied:v,copyToken:y,updateTelegram:b,updateChannelAgentRoute:S,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:E,onTgAccountsBlur:D,dmOpts:O,groupOpts:A,replyOpts:te,streamOpts:ne,chatAgents:re,saving:ie,dirty:ae,save:oe,discard:se}){let ce=H,F=r.telegram,le=i?ve(i.telegram):``,ue=ve(F),de=!c&&!!String(le).trim()&&ue===le;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(h,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,I.jsx)(j,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.modalCancel,children:(0,I.jsx)(f,{className:`size-4`})})})]}),(0,I.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:F.enabled,onChange:e=>b({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,I.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[n.telegramToken,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(ce(),`min-w-0 flex-1 font-mono text-xs`),type:c?`text`:`password`,autoComplete:`off`,readOnly:de,value:de?`*`.repeat(Math.max(1,le.length)):ue,onChange:e=>{if(de)return;let t=F.accounts?.default??Z(`default`);b({accounts:{...F.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),ue?(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void y(),children:[v?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),v?n.copied:n.copy]}):null,(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>_(e=>!e),children:[c?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),c?n.hide:n.show]})]}),(0,I.jsx)(q,{children:n.telegramTokenDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(ce(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:W(F.allowFrom),onChange:e=>b({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:n.allowFromDmDesc})]}),(0,I.jsx)(Se,{accountIds:me(F),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:re?.items??[],disabled:ie,onChange:(e,t)=>S(`telegram`,e,t),ch:n}),(0,I.jsxs)(p,{type:`button`,variant:`ghost`,className:`-ml-2 h-auto justify-start px-2 py-1 text-sm text-fg-muted hover:text-fg`,onClick:()=>s(e=>!e),children:[(0,I.jsx)(N,{className:u(`mr-1 size-4 transition-transform`,o&&`rotate-180`)}),o?n.advancedHide:n.advancedShow]}),o?(0,I.jsx)($,{tg:F,updateTelegram:b,ch:n,dmOpts:O,groupOpts:A,replyOpts:te,streamOpts:ne,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:E,onTgAccountsBlur:D}):null]}),(0,I.jsxs)(`div`,{className:`mt-8 flex flex-wrap justify-end gap-2 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,I.jsx)(p,{type:`button`,variant:`secondary`,disabled:!ae||ie,onClick:se,children:n.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,disabled:!ae||ie,onClick:async()=>{await oe()&&t(!1)},children:ie?n.saving:n.save})]})]})]})})}function Ie(){let e=o(e=>e.language),t=O(e),n=t.channelsSettings,i=!!te(e=>e.token),[a,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,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(null),[j,M]=(0,Y.useState)(null),[N,P]=(0,Y.useState)(null),[ee,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(!1),[F,le]=(0,Y.useState)(!1),[ue,de]=(0,Y.useState)(!1),[I,fe]=(0,Y.useState)(!1),[pe,L]=(0,Y.useState)(!1),[R,me]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)(``),[he,V]=(0,Y.useState)(``),[ge,H]=(0,Y.useState)(``),[_e,U]=(0,Y.useState)(``),[W,ye]=(0,Y.useState)(``),[be,G]=(0,Y.useState)(``),[xe,K]=(0,Y.useState)(``),[q,J]=(0,Y.useState)(``),{data:Se}=r(i?`gateway-chat-agents-ch`:null,C,{revalidateOnFocus:!1}),{data:Ce,error:X,isLoading:Z,mutate:Ee}=_(i),Q=(0,Y.useMemo)(()=>Ce?.payload?.config===void 0?null:Te(Ce.payload.config),[Ce]),Oe=(0,Y.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,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(!a||u)return!1;d(!0),p(null),h(!1);try{let e=await De(a);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)}},[a,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(!a||u)return;let r=a,i=e===`weixin`?{...a,weixin:{...a.weixin,enabled:t}}:e===`telegram`?{...a,telegram:{...a.telegram,enabled:t}}:e===`feishu`?{...a,feishu:{...a.feishu,enabled:t}}:{...a,dingtalk:{...a.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)}},[a,u,n.saveError]),Re=(0,Y.useCallback)(async()=>{if(!a||!E||u)return;let e=we(),t=E===`weixin`?{...a,weixin:e.weixin}:E===`telegram`?{...a,telegram:e.telegram}:E===`feishu`?{...a,feishu:e.feishu}:{...a,dingtalk:e.dingtalk};d(!0),p(null);try{let e=await De(t);s(e);let n=structuredClone(e);l(n),B(JSON.stringify(n.telegram.accounts??{},null,2)),H(JSON.stringify(n.weixin.accounts??{},null,2)),V(``),U(``),ye(JSON.stringify(n.feishu?.accounts??{},null,2)),G(``),K(JSON.stringify(n.dingtalk?.accounts??{},null,2)),J(``),D(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[a,E,u,n.saveError]),ze=(0,Y.useCallback)(async()=>{let e=a?ve(a.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),de(!0),window.setTimeout(()=>de(!1),2e3))},[a]),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=a?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),L(!0),window.setTimeout(()=>L(!1),2e3))},[a]);return{language:e,m:t,ch:n,hasToken:i,loading:ke,fetchError:Ae,mutate:Ee,form:a,baseline:c,dirty:Oe,saving:u,error:f,saveOk:m,weixinModalOpen:g,setWeixinModalOpen:v,telegramModalOpen:y,setTelegramModalOpen:b,feishuModalOpen:x,setFeishuModalOpen:S,dingtalkModalOpen:w,setDingtalkModalOpen:T,removeTarget:E,setRemoveTarget:D,weixinSuccessBanner:k,setWeixinSuccessBanner:A,feishuSetupSuccessBanner:j,dingtalkSetupSuccessBanner:N,tgAdvanced:ee,setTgAdvanced:ne,showToken:re,setShowToken:ie,showFeishuSecret:ae,setShowFeishuSecret:oe,showFeishuWebhookSecrets:se,setShowFeishuWebhookSecrets:ce,showDingtalkSecret:F,setShowDingtalkSecret:le,copied:ue,feishuCopied:I,dingtalkCopied:pe,feishuWebhookCopied:R,tgAccountsDraft:z,setTgAccountsDraft:B,tgAccountsError:he,wxAccountsDraft:ge,setWxAccountsDraft:H,wxAccountsError:_e,feishuAccountsDraft:W,setFeishuAccountsDraft:ye,feishuAccountsError:be,dingtalkAccountsDraft:xe,setDingtalkAccountsDraft:K,dingtalkAccountsError:q,chatAgents:Se,updateChannelAgentRoute:je,updateTelegram:Me,updateWeixin:Ne,updateFeishu:Pe,updateDingtalk:$,save:Fe,discard:Ie,toggleChannelEnabled:Le,removeChannel:Re,copyToken:ze,handleFeishuQrSetupSuccess:Be,handleDingtalkQrSetupSuccess:Ve,copyFeishuSecret:(0,Y.useCallback)(async()=>{let e=a?.feishu?.appSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),fe(!0),window.setTimeout(()=>fe(!1),2e3))},[a]),copyDingtalkSecret:He,copyFeishuWebhookConfig:(0,Y.useCallback)(async()=>{let e=a?.feishu;if(!e)return;let t={connectionMode:e.connectionMode,verificationToken:e.verificationToken||``,encryptKey:e.encryptKey||``,webhookHost:e.webhookHost||``,webhookPort:e.webhookPort||0,webhookPath:e.webhookPath||``};await navigator.clipboard.writeText(JSON.stringify(t,null,2)).catch(()=>{}),me(!0),window.setTimeout(()=>me(!1),2e3)},[a]),onTgAccountsBlur:(0,Y.useCallback)(()=>{if(!a)return;let e=z.trim();if(!e){Me({accounts:{}}),V(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Me({accounts:t}),V(``)}catch(e){V(e instanceof Error?e.message:n.jsonInvalid)}},[a,z,Me,n.jsonObjectAccounts,n.jsonInvalid]),onWxAccountsBlur:(0,Y.useCallback)(()=>{if(!a)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)}},[a,ge,Ne,n.jsonObjectAccounts,n.jsonInvalid]),onFeishuAccountsBlur:(0,Y.useCallback)(()=>{if(!a)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)}},[a,W,Pe,n.jsonObjectAccounts,n.jsonInvalid]),onDingtalkAccountsBlur:(0,Y.useCallback)(()=>{if(!a)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)}},[a,xe,$,n.jsonObjectAccounts,n.jsonInvalid]),dmOpts:(0,Y.useMemo)(()=>[`pairing`,`allowlist`,`open`,`disabled`].map(e=>({value:e,label:n.policy.dm[e]})),[n.policy.dm]),groupOpts:(0,Y.useMemo)(()=>[`open`,`disabled`,`allowlist`].map(e=>({value:e,label:n.policy.group[e]})),[n.policy.group]),replyOpts:(0,Y.useMemo)(()=>[`off`,`first`,`all`].map(e=>({value:e,label:n.policy.reply[e]})),[n.policy.reply]),streamOpts:(0,Y.useMemo)(()=>[`off`,`partial`,`block`].map(e=>({value:e,label:n.policy.stream[e]})),[n.policy.stream])}}function Le({open:e,onOpenChange:t,ch:n,onLoginSuccess:r,moreSettings:i}){let[o,s]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null),[y,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(!1),A=(0,Y.useCallback)(async()=>{S(null),w(null),d(null),s(!0);try{let e=await Ee();v(e.qrcodeUrl),d(e.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{s(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),S(null),E(null),O(!1),w(null);return}A()},[e,A]),(0,Y.useEffect)(()=>{if(!c)return;let e=!1,i,a=async()=>{try{let a=await Q(c);if(e)return;if(a.phase===`polling`){v(a.qrcodeUrl),a.qrStatus===`scaned`?w(n.weixinQrLoginScanned):w(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()):(S(a.message),v(null));return}a.phase===`unknown`&&w(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),S(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)}},[c,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,Y.useEffect)(()=>{if(!_){E(null),O(!1);return}let e=!1;return O(!1),X.toDataURL(_,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||E(t)}).catch(()=>{e||(O(!0),E(null))}),()=>{e=!0}},[_]);let M=!!(_&&c),N=e&&!y&&!M;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.weixinQrModalCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(h,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,I.jsx)(j,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(M||N)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:u(`min-h-[1.25rem] text-center text-sm`,C&&!N?`text-accent`:`text-fg-muted`),children:N?n.weixinQrLoginBusy:C??`\xA0`}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,N&&`bg-surface-muted/40 dark:bg-surface-base`),children:[N?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,M&&_&&!y&&T&&!D?(0,I.jsx)(`img`,{src:T,alt:``,className:`relative z-[1] size-full object-contain`}):null,M&&_&&!y&&!T&&!D&&!N?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,M&&_&&!y&&D?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,I.jsxs)(`a`,{href:_,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(b,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void A(),children:o?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function Re({wx:e,updateWeixin:t,ch:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,channelAgentRoutesWx:l,defaultAgentId:d,agentItems:f,onAgentRouteChange:p,routingDisabled:m}){let h=H;return(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinAllowFrom}),(0,I.jsx)(`textarea`,{className:u(h(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`wxid_..., openid_...`,value:e.allowFrom.join(`, `),onChange:e=>t({allowFrom:e.target.value.split(/[,\n]/).map(e=>e.trim()).filter(Boolean)})}),(0,I.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,I.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,I.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:i}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.historyLimit}),(0,I.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.textChunkLimit}),(0,I.jsx)(`input`,{type:`number`,min:1e3,max:1e4,step:100,className:h(),value:e.textChunkLimit,onChange:e=>t({textChunkLimit:parseInt(e.target.value,10)||4e3})})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinRouteTag}),(0,I.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,I.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,I.jsx)(q,{children:n.weixinDebugDesc}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinAccountsJson}),(0,I.jsx)(`textarea`,{className:u(h(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:a,onChange:e=>o(e.target.value),onBlur:c,placeholder:`{ "personal": { "name": "...", "cdnBaseUrl": "...", "enabled": true } }`}),s?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}):(0,I.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,I.jsx)(Se,{accountIds:z(e),routes:l,defaultAgentId:d,agentItems:f,disabled:m,onChange:p,ch:n})]})}function ze({ch:e,wx:t,updateWeixin:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,form:l,chatAgents:u,onAgentRouteChange:d,saving:f,dirty:m,save:h,discard:g}){return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(N,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,I.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,I.jsx)(Re,{wx:t,updateWeixin:n,ch:e,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,channelAgentRoutesWx:l.channelAgentRoutes.weixin,defaultAgentId:l.defaultAgentId,agentItems:u?.items??[],onAgentRouteChange:d,routingDisabled:f})}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!m||f,onClick:g,children:e.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!m||f,onClick:async()=>{await h()},children:f?e.saving:e.save})]})]})]})}function Be(){let{language:e,m:t,ch:n,hasToken:r,loading:i,fetchError:a,mutate:o,form:c,baseline:l,dirty:u,saving:d,error:f,saveOk:m,weixinModalOpen:h,setWeixinModalOpen:g,telegramModalOpen:_,setTelegramModalOpen:v,feishuModalOpen:y,setFeishuModalOpen:x,removeTarget:S,setRemoveTarget:C,weixinSuccessBanner:w,setWeixinSuccessBanner:T,dingtalkModalOpen:E,setDingtalkModalOpen:O,feishuSetupSuccessBanner:k,dingtalkSetupSuccessBanner:A,tgAdvanced:j,setTgAdvanced:M,showToken:N,setShowToken:P,showFeishuSecret:ee,setShowFeishuSecret:te,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,showDingtalkSecret:ae,setShowDingtalkSecret:se,copied:ce,feishuCopied:F,dingtalkCopied:le,feishuWebhookCopied:ue,tgAccountsDraft:de,setTgAccountsDraft:L,tgAccountsError:R,wxAccountsDraft:me,setWxAccountsDraft:z,wxAccountsError:B,feishuAccountsDraft:he,setFeishuAccountsDraft:V,feishuAccountsError:ge,dingtalkAccountsDraft:H,setDingtalkAccountsDraft:_e,dingtalkAccountsError:U,chatAgents:W,updateChannelAgentRoute:ve,updateTelegram:K,updateWeixin:q,updateFeishu:J,updateDingtalk:Se,save:Y,discard:X,toggleChannelEnabled:Z,removeChannel:we,copyToken:Te,handleFeishuQrSetupSuccess:Ee,handleDingtalkQrSetupSuccess:Q,copyFeishuSecret:De,copyDingtalkSecret:Oe,copyFeishuWebhookConfig:ke,onTgAccountsBlur:Ae,onWxAccountsBlur:je,onFeishuAccountsBlur:$,onDingtalkAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue}=Ie();if(!r)return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,I.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,I.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,I.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,I.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!c)return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,I.jsx)(p,{type:`button`,variant:`secondary`,onClick:()=>void o(),children:n.retry})]});let We=c.weixin,Ge=c.telegram,Ke=c.feishu,qe=c.dingtalk,Je=be(We),Ye=ye(Ge),Xe=G(Ke),Ze=xe(qe),Qe=(0,I.jsx)(Ne,{ch:n,form:c,baseline:l,showFeishuSecret:ee,setShowFeishuSecret:te,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,feishuCopied:F,feishuWebhookCopied:ue,copyFeishuSecret:De,copyFeishuWebhookConfig:ke,updateFeishu:J,updateChannelAgentRoute:ve,feishuAccountsDraft:he,setFeishuAccountsDraft:V,feishuAccountsError:ge,onFeishuAccountsBlur:$,dmOpts:Be,groupOpts:Ve,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),$e=(0,I.jsx)(Ce,{ch:n,form:c,baseline:l,showDingtalkSecret:ae,setShowDingtalkSecret:se,dingtalkCopied:le,copyDingtalkSecret:Oe,updateDingtalk:Se,updateChannelAgentRoute:ve,dingtalkAccountsDraft:H,setDingtalkAccountsDraft:_e,dingtalkAccountsError:U,onDingtalkAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),et=(0,I.jsx)(ze,{ch:n,wx:We,updateWeixin:q,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:me,setWxAccountsDraft:z,wxAccountsError:B,onWxAccountsBlur:je,form:c,chatAgents:W,onAgentRouteChange:(e,t)=>ve(`weixin`,e,t),saving:d,dirty:u,save:Y,discard:X});return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,I.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,I.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,I.jsxs)(`a`,{href:oe(e,`channels`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,I.jsx)(b,{className:`size-3.5`})]})]}),u?(0,I.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,I.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,I.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,w?(0,I.jsx)(`p`,{className:`text-xs text-accent`,children:w}):null,k?(0,I.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:k}):null,A?(0,I.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:A}):null,(0,I.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,I.jsx)(fe,{icon:(0,I.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.weixinTitle,subtitle:n.weixinSubtitle,configured:Je,enabled:We.enabled,toggleDisabled:d,onToggle:e=>void Z(`weixin`,e),onConfigure:()=>g(!0),onEdit:()=>g(!0),onRemove:()=>C(`weixin`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(D,{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:()=>C(`telegram`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.feishuTitle,subtitle:n.feishuSubtitle,configured:Xe,enabled:Ke.enabled,toggleDisabled:d,onToggle:e=>void Z(`feishu`,e),onConfigure:()=>x(!0),onEdit:()=>x(!0),onRemove:()=>C(`feishu`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(s,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.dingtalkTitle,subtitle:n.dingtalkSubtitle,configured:Ze,enabled:qe.enabled,toggleDisabled:d,onToggle:e=>void Z(`dingtalk`,e),onConfigure:()=>O(!0),onEdit:()=>O(!0),onRemove:()=>C(`dingtalk`),ch:n})]}),(0,I.jsx)(Le,{open:h,onOpenChange:g,ch:n,onLoginSuccess:async()=>{await o(),T(n.weixinQrLoginSuccess),window.setTimeout(()=>T(null),4e3)},moreSettings:et}),(0,I.jsx)(Fe,{open:_,onOpenChange:v,ch:n,form:c,baseline:l,tgAdvanced:j,setTgAdvanced:M,showToken:N,setShowToken:P,copied:ce,copyToken:Te,updateTelegram:K,updateChannelAgentRoute:ve,tgAccountsDraft:de,setTgAccountsDraft:L,tgAccountsError:R,onTgAccountsBlur:Ae,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),(0,I.jsx)(Pe,{open:y,onOpenChange:x,ch:n,onSetupSuccess:Ee,moreSettings:Qe}),(0,I.jsx)(Me,{open:E,onOpenChange:O,ch:n,onSetupSuccess:Q,moreSettings:$e}),(0,I.jsx)(pe,{open:S!==null,onOpenChange:e=>{e||C(null)},ch:n,removeTarget:S,onCancel:()=>C(null),saving:d,onConfirmRemove:()=>void we()})]})}export{Be as ChannelsSettingsPanel};
2
- //# sourceMappingURL=channels-settings-m10wg_Lg.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-DKvYJ-LI.js";import{An as i,At as a,Cn as o,Cr as s,Dn as c,Dt as l,Fn as u,Jr as d,Ln as f,Mn as p,Mt as m,Nt as h,Ot as g,St as _,Wn as v,Xr as y,Yr as b,_ as x,_r as S,bt as C,dn as w,ei as T,gn as E,ir as D,jn as O,jt as k,kn as A,kt as j,mi as M,pi as N,qr as P,v as ee,vn as te,w as ne,xr as re,xt as ie,y as ae,yn as oe}from"./index-DFgsyQna.js";import{a as se,i as ce,n as F,r as le,t as ue}from"./dist-KXNTFU5L.js";import{t as de}from"./browser-DNXWYwzc.js";var I=n();function fe({icon:e,title:t,subtitle:n,configured:r,enabled:i,onToggle:a,toggleDisabled:o,onConfigure:s,onEdit:c,onRemove:l,ch:d}){return(0,I.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-2xl border border-edge bg-surface-base px-4 py-4 dark:border-edge sm:flex-row sm:items-center sm:gap-4`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,I.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,I.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:d.hubConnectedBadge}):null]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,I.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,I.jsxs)(ce,{children:[(0,I.jsx)(se,{asChild:!0,children:(0,I.jsx)(p,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":d.menuMoreAria,children:(0,I.jsx)(y,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,I.jsx)(le,{children:(0,I.jsxs)(ue,{className:u(`min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,ae),sideOffset:6,align:`end`,children:[(0,I.jsx)(F,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>c(),children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(S,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),d.menuEditConfig]})}),(0,I.jsx)(F,{className:`cursor-pointer rounded-lg px-3 py-2 text-sm text-danger outline-none hover:bg-surface-hover data-[highlighted]:bg-surface-hover`,onSelect:()=>l(),children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(v,{className:`size-4 shrink-0`,strokeWidth:1.75}),d.menuRemoveConfig]})})]})})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} — ${d.enableChannelAria}`,disabled:o,className:u(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,i?`justify-end bg-accent`:`justify-start bg-surface-hover`,o&&`cursor-not-allowed opacity-50`),onClick:()=>void a(!i),children:(0,I.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,I.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:s,children:d.hubConfigureButton})})]})}function pe({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:i,saving:o,onConfirmRemove:s}){return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{className:u(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,x,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(h,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,I.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,I.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,onClick:i,children:n.modalCancel}),(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:o,onClick:s,children:o?n.saving:n.removeChannelAction})]})]})]})})}function L(e){return(e??``).trim().toLowerCase()}function R(e){let t=e.match;return!(!t?.channel||!t.accountId||t.peerId||t.peerKind||t.guildId||t.teamId||t.memberRoleIds&&t.memberRoleIds.length>0)}function me(e){return Object.keys(e.accounts??{}).sort()}function z(e){return Object.keys(e.accounts??{}).sort()}function B(e){let t=Object.keys(e.accounts??{});return t.length>0?[...t].sort():typeof e.appId==`string`&&e.appId.trim()&&typeof e.appSecret==`string`&&e.appSecret.trim()?[`default`]:[]}function he(e){let t=Object.keys(e.accounts??{});return t.length>0?[...t].sort():typeof e.clientId==`string`&&e.clientId.trim()&&typeof e.clientSecret==`string`&&e.clientSecret.trim()?[`default`]:[]}function V(e,t,n,r,i,a){let o={},s={},c={},l={};for(let n of t)o[n]=(e.find(e=>L(e.match?.channel)===`telegram`&&L(e.match?.accountId)===L(n)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of n)s[t]=(e.find(e=>L(e.match?.channel)===`weixin`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of r)c[t]=(e.find(e=>L(e.match?.channel)===`feishu`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();for(let t of i)l[t]=(e.find(e=>L(e.match?.channel)===`dingtalk`&&L(e.match?.accountId)===L(t)&&R(e))?.agentId??a).trim().toLowerCase();return{telegram:o,weixin:s,feishu:c,dingtalk:l}}function ge(e,t,n,r,i,a,o){let s=new Set(n.map(L)),c=new Set(r.map(L)),l=new Set(i.map(L)),u=new Set(a.map(L)),d=e.filter(e=>{if(e.id?.startsWith(`ui:route:account:`))return!1;if(!R(e))return!0;let t=L(e.match.channel),n=L(e.match.accountId);return!n||n===`*`?!0:!(t===`telegram`&&s.has(n)||t===`weixin`&&c.has(n)||t===`feishu`&&l.has(n)||t===`dingtalk`&&u.has(n))}),f=[];for(let e of n){let n=(t.telegram[e]??t.telegram[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:telegram:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`telegram`,accountId:e}})}for(let e of r){let n=(t.weixin[e]??t.weixin[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:weixin:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`weixin`,accountId:e}})}for(let e of i){let n=(t.feishu[e]??t.feishu[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:feishu:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`feishu`,accountId:e}})}for(let e of a){let n=(t.dingtalk[e]??t.dingtalk[L(e)]??o).trim().toLowerCase();f.push({id:`ui:route:account:dingtalk:${e}`,agentId:n,priority:45,enabled:!0,match:{channel:`dingtalk`,accountId:e}})}return[...d,...f]}function H(){return u(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,i,`dark:border-edge`)}function _e(){return u(A,c)}function U(e){return e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean).map(e=>/^-?\d+$/.test(e)?Number(e):e)}function W(e){return e.map(String).join(`, `)}function ve(e){let t=e.accounts?.default?.botToken;return typeof t==`string`?t:``}function ye(e){return Object.values(e.accounts??{}).some(e=>typeof e.botToken==`string`&&e.botToken.trim().length>0)}function be(e){return Object.keys(e.accounts??{}).length>0||e.allowFrom.length>0}function G(e){return!!(e.appId?.trim()&&e.appSecret?.trim())||Object.keys(e.accounts??{}).length>0}function xe(e){return!!(e.clientId?.trim()&&e.clientSecret?.trim())||Object.keys(e.accounts??{}).length>0}function K({children:e}){return(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e}),(0,I.jsx)(`select`,{className:_e(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Se({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:i,onChange:a,ch:s}){let l=O(o(e=>e.language)).agentsSettings;if(e.length===0)return null;let d=r.length>0?r:[{id:n}];return(0,I.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(K,{children:s.agentRoutingTitle}),(0,I.jsx)(q,{children:s.agentRoutingHint})]}),(0,I.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 sm:grid-cols-2 sm:items-center dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,I.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,I.jsx)(`select`,{id:`agent-route-${e}`,className:u(H(),c),disabled:i,value:(t[e]??n).toLowerCase(),onChange:t=>a(e,t.target.value),children:d.map(e=>(0,I.jsx)(`option`,{value:e.id,children:`${ne(e,l)} (${e.id})`},e.id))})]})]},e))})]})}function Ce({ch:e,form:t,baseline:n,showDingtalkSecret:r,setShowDingtalkSecret:i,dingtalkCopied:a,copyDingtalkSecret:o,updateDingtalk:s,updateChannelAgentRoute:c,dingtalkAccountsDraft:l,setDingtalkAccountsDraft:f,dingtalkAccountsError:m,onDingtalkAccountsBlur:h,dmOpts:g,groupOpts:_,chatAgents:v,saving:y,dirty:b,save:x,discard:S}){let C=H,w=t.dingtalk,E=n?.dingtalk?.clientSecret??``,D=!r&&!!String(E).trim()&&w.clientSecret===E;return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(N,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:w.enabled,onChange:e=>s({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.dingtalkClientId,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),value:w.clientId,onChange:e=>s({clientId:e.target.value}),placeholder:`dingxxx`}),(0,I.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.dingtalkClientSecret,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:D,value:D?`*`.repeat(Math.max(1,w.clientSecret.length)):w.clientSecret,onChange:e=>{D||s({clientSecret:e.target.value})},placeholder:`••••••••`}),w.clientSecret?(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void o(),children:[a?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),a?e.copied:e.copy]}):null,(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,I.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dingtalkEndpoint}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),value:w.endpoint,onChange:e=>s({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,I.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:w.debug,onChange:e=>s({debug:e.target.checked})}),e.dingtalkDebug]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dmPolicy}),(0,I.jsx)(`select`,{className:C(),value:w.dmPolicy,onChange:e=>s({dmPolicy:e.target.value}),children:g.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.groupPolicy}),(0,I.jsx)(`select`,{className:C(),value:w.groupPolicy,onChange:e=>s({groupPolicy:e.target.value}),children:_.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:w.requireMention,onChange:e=>s({requireMention:e.target.checked})}),e.requireMention]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(C(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:W(w.allowFrom),onChange:e=>s({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromDmDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(C(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:W(w.groupAllowFrom),onChange:e=>s({groupAllowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.historyLimit}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(w.historyLimit),onChange:e=>s({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.textChunkLimit}),(0,I.jsx)(`input`,{className:u(C(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(w.textChunkLimit),onChange:e=>s({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,I.jsx)(Se,{accountIds:he(w),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:v?.items??[],disabled:y,onChange:(e,t)=>c(`dingtalk`,e,t),ch:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(C(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:l,onChange:e=>f(e.target.value),onBlur:h,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),m?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:m}):(0,I.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!b||y,onClick:S,children:e.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!b||y,onClick:async()=>{await x()},children:y?e.saving:e.save})]})]})]})}var Y=e(t(),1),X=e(de(),1);function Z(e){return{accountId:e,name:``,enabled:!0,botToken:``,allowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,apiRoot:``,proxy:``,historyLimit:50,textChunkLimit:4e3,streamMode:`partial`}}function we(){return{bindingsFull:[],channelAgentRoutes:{telegram:{},weixin:{},feishu:{},dingtalk:{}},defaultAgentId:`main`,telegram:{enabled:!1,apiRoot:``,debug:!1,allowFrom:[],groupAllowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,streamMode:`partial`,historyLimit:50,textChunkLimit:4e3,proxy:``,accounts:{default:Z(`default`)}},weixin:{enabled:!1,dmPolicy:`pairing`,allowFrom:[],debug:!1,streamMode:`partial`,historyLimit:50,textChunkLimit:4e3,routeTag:``,accounts:{}},feishu:{enabled:!1,defaultAccount:``,appId:``,appSecret:``,domain:`feishu`,connectionMode:`websocket`,verificationToken:``,encryptKey:``,webhookHost:`127.0.0.1`,webhookPort:3e3,webhookPath:`/feishu/events`,dmPolicy:`pairing`,groupPolicy:`allowlist`,allowFrom:[],groupAllowFrom:[],requireMention:!0,historyLimit:50,textChunkLimit:4e3,renderMode:`auto`,streaming:!1,reactionNotifications:`own`,tools:{doc:!0,wiki:!0,drive:!0,scopes:!0,bitable:!0,perm:!1},actions:{reactions:!0},accounts:{}},dingtalk:{enabled:!1,defaultAccount:``,clientId:``,clientSecret:``,dmPolicy:`pairing`,groupPolicy:`open`,allowFrom:[],groupAllowFrom:[],requireMention:!1,debug:!1,endpoint:`https://api.dingtalk.com`,historyLimit:50,textChunkLimit:4e3,accounts:{}}}}function Te(e){let t=e&&typeof e==`object`?e.channels:void 0,n=t&&typeof t==`object`?t:{},r=n.telegram,i=n.weixin,a=n.feishu,o=n.dingtalk,s=r?.accounts,c=s&&typeof s==`object`&&!Array.isArray(s)?{...s}:{},l=typeof r?.botToken==`string`?r.botToken.trim():``,u=c.default?.botToken?.trim()??``;l&&!u&&(c={...c,default:{...c.default??Z(`default`),accountId:`default`,botToken:l}}),c.default||(c={...c,default:Z(`default`)});let d=i?.accounts,f=d&&typeof d==`object`&&!Array.isArray(d)?d:{},p=(()=>{let t=(e&&typeof e==`object`?e:{}).bindings;return Array.isArray(t)?t:[]})(),m=(()=>{let t=(e&&typeof e==`object`?e:{}).agents;return t&&typeof t==`object`?t:{}})(),h=typeof m.defaultId==`string`&&m.defaultId.trim()?m.defaultId.trim().toLowerCase():`main`,g={telegram:{enabled:!!r?.enabled,apiRoot:typeof r?.apiRoot==`string`?r.apiRoot:``,debug:!!r?.debug,allowFrom:Array.isArray(r?.allowFrom)?[...r.allowFrom]:[],groupAllowFrom:Array.isArray(r?.groupAllowFrom)?[...r.groupAllowFrom]:[],dmPolicy:r?.dmPolicy||`pairing`,groupPolicy:r?.groupPolicy||`open`,replyToMode:r?.replyToMode||`off`,streamMode:r?.streamMode??`partial`,historyLimit:typeof r?.historyLimit==`number`?r.historyLimit:50,textChunkLimit:typeof r?.textChunkLimit==`number`?r.textChunkLimit:4e3,proxy:typeof r?.proxy==`string`?r.proxy:``,accounts:{...c}},weixin:{enabled:!!i?.enabled,dmPolicy:i?.dmPolicy||`pairing`,allowFrom:Array.isArray(i?.allowFrom)?[...i.allowFrom]:[],debug:!!i?.debug,streamMode:i?.streamMode??`partial`,historyLimit:typeof i?.historyLimit==`number`?i.historyLimit:50,textChunkLimit:typeof i?.textChunkLimit==`number`?i.textChunkLimit:4e3,routeTag:i?.routeTag==null?``:String(i.routeTag),accounts:{...f}},feishu:{enabled:!!a?.enabled,defaultAccount:typeof a?.defaultAccount==`string`?a.defaultAccount:``,appId:typeof a?.appId==`string`?a.appId:``,appSecret:typeof a?.appSecret==`string`?a.appSecret:``,domain:typeof a?.domain==`string`&&a.domain||`feishu`,connectionMode:a?.connectionMode||`websocket`,verificationToken:typeof a?.verificationToken==`string`?a.verificationToken:``,encryptKey:typeof a?.encryptKey==`string`?a.encryptKey:``,webhookHost:typeof a?.webhookHost==`string`?a.webhookHost:`127.0.0.1`,webhookPort:typeof a?.webhookPort==`number`?a.webhookPort:3e3,webhookPath:typeof a?.webhookPath==`string`?a.webhookPath:`/feishu/events`,dmPolicy:a?.dmPolicy||`pairing`,groupPolicy:a?.groupPolicy||`allowlist`,allowFrom:Array.isArray(a?.allowFrom)?[...a.allowFrom]:[],groupAllowFrom:Array.isArray(a?.groupAllowFrom)?[...a.groupAllowFrom]:[],requireMention:a?.requireMention===void 0?!0:!!a.requireMention,historyLimit:typeof a?.historyLimit==`number`?a.historyLimit:50,textChunkLimit:typeof a?.textChunkLimit==`number`?a.textChunkLimit:4e3,renderMode:a?.renderMode||`auto`,streaming:a?.streaming===void 0?!1:!!a.streaming,reactionNotifications:a?.reactionNotifications||`own`,tools:a?.tools&&typeof a.tools==`object`&&!Array.isArray(a.tools)?{...a.tools}:void 0,actions:a?.actions&&typeof a.actions==`object`&&!Array.isArray(a.actions)?{...a.actions}:void 0,accounts:a?.accounts&&typeof a.accounts==`object`&&!Array.isArray(a.accounts)?{...a.accounts}:{}},dingtalk:{enabled:!!o?.enabled,defaultAccount:typeof o?.defaultAccount==`string`?o.defaultAccount:``,clientId:typeof o?.clientId==`string`?o.clientId:``,clientSecret:typeof o?.clientSecret==`string`?o.clientSecret:``,dmPolicy:o?.dmPolicy||`pairing`,groupPolicy:o?.groupPolicy||`open`,allowFrom:Array.isArray(o?.allowFrom)?[...o.allowFrom]:[],groupAllowFrom:Array.isArray(o?.groupAllowFrom)?[...o.groupAllowFrom]:[],requireMention:o?.requireMention===!0,debug:!!o?.debug,endpoint:typeof o?.endpoint==`string`&&o.endpoint.trim()?o.endpoint.trim():`https://api.dingtalk.com`,historyLimit:typeof o?.historyLimit==`number`?o.historyLimit:50,textChunkLimit:typeof o?.textChunkLimit==`number`?o.textChunkLimit:4e3,accounts:o?.accounts&&typeof o.accounts==`object`&&!Array.isArray(o.accounts)?{...o.accounts}:{}}},_=V(p,me(g.telegram),z(g.weixin),B(g.feishu),he(g.dingtalk),h);return{...g,bindingsFull:p.map(e=>({...e})),channelAgentRoutes:_,defaultAgentId:h}}async function Ee(e){return(await E(w(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Q(e){return(await E(w(`/api/channels/weixin/login/${encodeURIComponent(e)}`))).payload.status}async function De(e){let t=e.telegram,n=e.weixin,r=e.feishu,i=e.dingtalk,a=ge(e.bindingsFull,e.channelAgentRoutes,me(t),z(n),B(r),he(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await E(w(`/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 E(w(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function ke(e){return(await E(w(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function Ae(){return(await E(w(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function je(e){return(await E(w(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Me({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[o,s]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null),[y,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useCallback)(async()=>{S(null),d(null),v(null),s(!0);try{let e=await Ae();v(e.qrUrl),d(e.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{s(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),S(null),w(null),E(!1),s(!1);return}D()},[e,D]),(0,Y.useEffect)(()=>{if(!c)return;let e=!1,n,i=async()=>{try{let i=await je(c);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})):(S(i.message),v(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),S(i.message),d(null),v(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),S(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)}},[c,t,r]),(0,Y.useEffect)(()=>{if(!_){w(null),E(!1);return}let e=!1;return E(!1),X.toDataURL(_,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[_]);let O=!!(_&&c),A=e&&!y&&!O;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.dingtalkQrCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(h,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,I.jsx)(j,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(O||A)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:A?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,A&&`bg-surface-muted/40 dark:bg-surface-base`),children:[A?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,O&&_&&!y&&C&&!T?(0,I.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,O&&_&&!y&&!C&&!T&&!A?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,O&&_&&!y&&T?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,I.jsxs)(`a`,{href:_,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(b,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void D(),children:o?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function Ne({ch:e,form:t,baseline:n,showFeishuSecret:r,setShowFeishuSecret:i,showFeishuWebhookSecrets:a,setShowFeishuWebhookSecrets:o,feishuCopied:s,feishuWebhookCopied:c,copyFeishuSecret:l,copyFeishuWebhookConfig:f,updateFeishu:m,updateChannelAgentRoute:h,feishuAccountsDraft:g,setFeishuAccountsDraft:_,feishuAccountsError:v,onFeishuAccountsBlur:y,dmOpts:b,groupOpts:x,chatAgents:S,saving:C,dirty:w,save:E,discard:D}){let O=H,k=t.feishu,A=n?.feishu?.appSecret??``,j=!r&&!!String(A).trim()&&k.appSecret===A;return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(N,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:k.enabled,onChange:e=>m({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.feishuAppId,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.appId,onChange:e=>m({appId:e.target.value}),placeholder:`cli_xxx`}),(0,I.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[e.feishuAppSecret,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:j,value:j?`*`.repeat(Math.max(1,k.appSecret.length)):k.appSecret,onChange:e=>{j||m({appSecret:e.target.value})},placeholder:`••••••••`}),k.appSecret?(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void l(),children:[s?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),s?e.copied:e.copy]}):null,(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>i(e=>!e),children:[r?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,I.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.feishuDomain}),(0,I.jsxs)(`select`,{className:O(),value:String(k.domain||`feishu`),onChange:e=>m({domain:e.target.value}),children:[(0,I.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,I.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.connectionMode}),(0,I.jsxs)(`select`,{className:O(),value:k.connectionMode,onChange:e=>m({connectionMode:e.target.value}),children:[(0,I.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,I.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,I.jsx)(q,{children:e.connectionModeDesc})]})]}),k.connectionMode===`webhook`?(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e=>!e),children:[a?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),a?e.hide:e.show]}),(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void f(),children:[c?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),c?e.copied:e.copy]})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.verificationToken}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:k.verificationToken??``,onChange:e=>m({verificationToken:e.target.value})}),(0,I.jsx)(q,{children:e.verificationTokenDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.encryptKey}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:a?`text`:`password`,autoComplete:`off`,value:k.encryptKey??``,onChange:e=>m({encryptKey:e.target.value})}),(0,I.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,I.jsx)(K,{children:e.webhookHost}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.webhookHost??``,onChange:e=>m({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.webhookPort}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.webhookPort??``),onChange:e=>m({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,I.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.webhookPath}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),value:k.webhookPath??``,onChange:e=>m({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,I.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.renderMode}),(0,I.jsxs)(`select`,{className:O(),value:k.renderMode,onChange:e=>m({renderMode:e.target.value}),children:[(0,I.jsx)(`option`,{value:`auto`,children:`auto`}),(0,I.jsx)(`option`,{value:`raw`,children:`raw`}),(0,I.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.reactionNotifications}),(0,I.jsxs)(`select`,{className:O(),value:k.reactionNotifications,onChange:e=>m({reactionNotifications:e.target.value}),children:[(0,I.jsx)(`option`,{value:`off`,children:`off`}),(0,I.jsx)(`option`,{value:`own`,children:`own`}),(0,I.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:k.streaming,onChange:e=>m({streaming:e.target.checked})}),e.enableStreaming]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.dmPolicy}),(0,I.jsx)(`select`,{className:O(),value:k.dmPolicy,onChange:e=>m({dmPolicy:e.target.value}),children:b.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.groupPolicy}),(0,I.jsx)(`select`,{className:O(),value:k.groupPolicy,onChange:e=>m({groupPolicy:e.target.value}),children:x.map(e=>(0,I.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:k.requireMention,onChange:e=>m({requireMention:e.target.checked})}),e.requireMention]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:W(k.allowFrom),onChange:e=>m({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromDmDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:W(k.groupAllowFrom),onChange:e=>m({groupAllowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.historyLimit}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.historyLimit),onChange:e=>m({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.textChunkLimit}),(0,I.jsx)(`input`,{className:u(O(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(k.textChunkLimit),onChange:e=>m({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,I.jsx)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:[[`doc`,e.feishuToolDoc],[`wiki`,e.feishuToolWiki],[`drive`,e.feishuToolDrive],[`perm`,e.feishuToolPerm],[`bitable`,e.feishuToolBitable],[`scopes`,e.feishuToolScopes]].map(([e,t])=>(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!k.tools?.[e],onChange:t=>m({tools:{...k.tools,[e]:t.target.checked}})}),t]},e))}),(0,I.jsx)(`div`,{className:`mt-2`,children:(0,I.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,I.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,I.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!k.actions?.reactions,onChange:e=>m({actions:{...k.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,I.jsx)(Se,{accountIds:B(k),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:S?.items??[],disabled:C,onChange:(e,t)=>h(`feishu`,e,t),ch:e}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:e.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(O(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:g,onChange:e=>_(e.target.value),onBlur:y,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),v?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:v}):(0,I.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!w||C,onClick:D,children:e.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!w||C,onClick:async()=>{await E()},children:C?e.saving:e.save})]})]})]})}function Pe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:i}){let[o,s]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(`feishu`),[_,v]=(0,Y.useState)(null),[y,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(!1),A=(0,Y.useCallback)(async e=>{d(e),w(null),v(null),S(null),s(!0);try{let t=await Oe({domain:e});S(t.qrUrl),v(t.sessionKey)}catch(e){w(e instanceof Error?e.message:`Start failed`)}finally{s(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){v(null),S(null),w(null),E(null),O(!1),d(`feishu`),s(!1);return}A(`feishu`)},[e,A]),(0,Y.useEffect)(()=>{if(!_)return;let e=!1,n,i=async()=>{try{let i=await ke(_);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),v(null),i.ok?(S(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(w(i.message),S(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),w(i.message),v(null),S(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),w(t instanceof Error?t.message:`Request failed`),v(null),S(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[_,t,r]),(0,Y.useEffect)(()=>{if(!y){E(null),O(!1);return}let e=!1;return O(!1),X.toDataURL(y,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||E(t)}).catch(()=>{e||(O(!0),E(null))}),()=>{e=!0}},[y]);let M=!!(y&&_),N=e,P=e&&!C&&!M;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.feishuQrCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(h,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,I.jsx)(j,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[C?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:C}):null,!C&&(M||P)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:P?n.feishuQrStarting:n.feishuQrScanHint}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,P&&`bg-surface-muted/40 dark:bg-surface-base`),children:[P?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,M&&y&&!C&&T&&!D?(0,I.jsx)(`img`,{src:T,alt:``,className:`relative z-[1] size-full object-contain`}):null,M&&y&&!C&&!T&&!D&&!P?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,M&&y&&!C&&D?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,I.jsxs)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(b,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),N?(0,I.jsx)(`div`,{className:`mx-auto mt-4 flex w-full max-w-[20rem] justify-center px-1`,role:`group`,"aria-label":n.feishuRegionSwitchAria,children:(0,I.jsxs)(`div`,{className:`inline-flex w-full rounded-full border border-edge bg-surface-muted/60 p-1 dark:border-edge dark:bg-surface-base`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:o,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,c===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void A(`feishu`),children:n.feishuRegionChina}),(0,I.jsx)(`button`,{type:`button`,disabled:o,className:u(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,c===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void A(`lark`),children:n.feishuRegionInternational})]})}):null,(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void A(c),children:o?n.feishuQrStarting:n.feishuQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function $({tg:e,updateTelegram:t,ch:n,dmOpts:r,groupOpts:i,replyOpts:a,streamOpts:o,tgAccountsDraft:s,setTgAccountsDraft:c,tgAccountsError:l,onTgAccountsBlur:d}){let f=H;return(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.apiRoot}),(0,I.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.proxy}),(0,I.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,I.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,I.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:i}),(0,I.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:a}),(0,I.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:o}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.allowFromGroups}),(0,I.jsx)(`textarea`,{className:u(f(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`-1001234567890`,value:W(e.groupAllowFrom),onChange:e=>t({groupAllowFrom:U(e.target.value)})})]}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.historyLimit}),(0,I.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.textChunkLimit}),(0,I.jsx)(`input`,{type:`number`,min:1e3,max:1e4,step:100,className:f(),value:e.textChunkLimit,onChange:e=>t({textChunkLimit:parseInt(e.target.value,10)||4e3})})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.multiAccountJson}),(0,I.jsx)(`textarea`,{className:u(f(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:s,onChange:e=>c(e.target.value),onBlur:d,placeholder:`{ "personal": { "accountId": "personal", "botToken": "...", ... } }`}),l?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:l}):(0,I.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Fe({open:e,onOpenChange:t,ch:n,form:r,baseline:i,tgAdvanced:o,setTgAdvanced:s,showToken:c,setShowToken:_,copied:v,copyToken:y,updateTelegram:b,updateChannelAgentRoute:S,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:E,onTgAccountsBlur:D,dmOpts:O,groupOpts:A,replyOpts:te,streamOpts:ne,chatAgents:re,saving:ie,dirty:ae,save:oe,discard:se}){let ce=H,F=r.telegram,le=i?ve(i.telegram):``,ue=ve(F),de=!c&&!!String(le).trim()&&ue===le;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(h,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,I.jsx)(j,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.modalCancel,children:(0,I.jsx)(f,{className:`size-4`})})})]}),(0,I.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:F.enabled,onChange:e=>b({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,I.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsxs)(K,{children:[n.telegramToken,(0,I.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsx)(`input`,{className:u(ce(),`min-w-0 flex-1 font-mono text-xs`),type:c?`text`:`password`,autoComplete:`off`,readOnly:de,value:de?`*`.repeat(Math.max(1,le.length)):ue,onChange:e=>{if(de)return;let t=F.accounts?.default??Z(`default`);b({accounts:{...F.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),ue?(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void y(),children:[v?(0,I.jsx)(M,{className:`size-3.5`}):(0,I.jsx)(T,{className:`size-3.5`}),v?n.copied:n.copy]}):null,(0,I.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>_(e=>!e),children:[c?(0,I.jsx)(d,{className:`size-3.5`}):(0,I.jsx)(P,{className:`size-3.5`}),c?n.hide:n.show]})]}),(0,I.jsx)(q,{children:n.telegramTokenDesc})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.allowFromDm}),(0,I.jsx)(`textarea`,{className:u(ce(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:W(F.allowFrom),onChange:e=>b({allowFrom:U(e.target.value)})}),(0,I.jsx)(q,{children:n.allowFromDmDesc})]}),(0,I.jsx)(Se,{accountIds:me(F),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:re?.items??[],disabled:ie,onChange:(e,t)=>S(`telegram`,e,t),ch:n}),(0,I.jsxs)(p,{type:`button`,variant:`ghost`,className:`-ml-2 h-auto justify-start px-2 py-1 text-sm text-fg-muted hover:text-fg`,onClick:()=>s(e=>!e),children:[(0,I.jsx)(N,{className:u(`mr-1 size-4 transition-transform`,o&&`rotate-180`)}),o?n.advancedHide:n.advancedShow]}),o?(0,I.jsx)($,{tg:F,updateTelegram:b,ch:n,dmOpts:O,groupOpts:A,replyOpts:te,streamOpts:ne,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:E,onTgAccountsBlur:D}):null]}),(0,I.jsxs)(`div`,{className:`mt-8 flex flex-wrap justify-end gap-2 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,I.jsx)(p,{type:`button`,variant:`secondary`,disabled:!ae||ie,onClick:se,children:n.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,disabled:!ae||ie,onClick:async()=>{await oe()&&t(!1)},children:ie?n.saving:n.save})]})]})]})})}function Ie(){let e=o(e=>e.language),t=O(e),n=t.channelsSettings,i=!!te(e=>e.token),[a,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,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(null),[j,M]=(0,Y.useState)(null),[N,P]=(0,Y.useState)(null),[ee,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(!1),[F,le]=(0,Y.useState)(!1),[ue,de]=(0,Y.useState)(!1),[I,fe]=(0,Y.useState)(!1),[pe,L]=(0,Y.useState)(!1),[R,me]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)(``),[he,V]=(0,Y.useState)(``),[ge,H]=(0,Y.useState)(``),[_e,U]=(0,Y.useState)(``),[W,ye]=(0,Y.useState)(``),[be,G]=(0,Y.useState)(``),[xe,K]=(0,Y.useState)(``),[q,J]=(0,Y.useState)(``),{data:Se}=r(i?`gateway-chat-agents-ch`:null,C,{revalidateOnFocus:!1}),{data:Ce,error:X,isLoading:Z,mutate:Ee}=_(i),Q=(0,Y.useMemo)(()=>Ce?.payload?.config===void 0?null:Te(Ce.payload.config),[Ce]),Oe=(0,Y.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,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(!a||u)return!1;d(!0),p(null),h(!1);try{let e=await De(a);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)}},[a,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(!a||u)return;let r=a,i=e===`weixin`?{...a,weixin:{...a.weixin,enabled:t}}:e===`telegram`?{...a,telegram:{...a.telegram,enabled:t}}:e===`feishu`?{...a,feishu:{...a.feishu,enabled:t}}:{...a,dingtalk:{...a.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)}},[a,u,n.saveError]),Re=(0,Y.useCallback)(async()=>{if(!a||!E||u)return;let e=we(),t=E===`weixin`?{...a,weixin:e.weixin}:E===`telegram`?{...a,telegram:e.telegram}:E===`feishu`?{...a,feishu:e.feishu}:{...a,dingtalk:e.dingtalk};d(!0),p(null);try{let e=await De(t);s(e);let n=structuredClone(e);l(n),B(JSON.stringify(n.telegram.accounts??{},null,2)),H(JSON.stringify(n.weixin.accounts??{},null,2)),V(``),U(``),ye(JSON.stringify(n.feishu?.accounts??{},null,2)),G(``),K(JSON.stringify(n.dingtalk?.accounts??{},null,2)),J(``),D(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[a,E,u,n.saveError]),ze=(0,Y.useCallback)(async()=>{let e=a?ve(a.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),de(!0),window.setTimeout(()=>de(!1),2e3))},[a]),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=a?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),L(!0),window.setTimeout(()=>L(!1),2e3))},[a]);return{language:e,m:t,ch:n,hasToken:i,loading:ke,fetchError:Ae,mutate:Ee,form:a,baseline:c,dirty:Oe,saving:u,error:f,saveOk:m,weixinModalOpen:g,setWeixinModalOpen:v,telegramModalOpen:y,setTelegramModalOpen:b,feishuModalOpen:x,setFeishuModalOpen:S,dingtalkModalOpen:w,setDingtalkModalOpen:T,removeTarget:E,setRemoveTarget:D,weixinSuccessBanner:k,setWeixinSuccessBanner:A,feishuSetupSuccessBanner:j,dingtalkSetupSuccessBanner:N,tgAdvanced:ee,setTgAdvanced:ne,showToken:re,setShowToken:ie,showFeishuSecret:ae,setShowFeishuSecret:oe,showFeishuWebhookSecrets:se,setShowFeishuWebhookSecrets:ce,showDingtalkSecret:F,setShowDingtalkSecret:le,copied:ue,feishuCopied:I,dingtalkCopied:pe,feishuWebhookCopied:R,tgAccountsDraft:z,setTgAccountsDraft:B,tgAccountsError:he,wxAccountsDraft:ge,setWxAccountsDraft:H,wxAccountsError:_e,feishuAccountsDraft:W,setFeishuAccountsDraft:ye,feishuAccountsError:be,dingtalkAccountsDraft:xe,setDingtalkAccountsDraft:K,dingtalkAccountsError:q,chatAgents:Se,updateChannelAgentRoute:je,updateTelegram:Me,updateWeixin:Ne,updateFeishu:Pe,updateDingtalk:$,save:Fe,discard:Ie,toggleChannelEnabled:Le,removeChannel:Re,copyToken:ze,handleFeishuQrSetupSuccess:Be,handleDingtalkQrSetupSuccess:Ve,copyFeishuSecret:(0,Y.useCallback)(async()=>{let e=a?.feishu?.appSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),fe(!0),window.setTimeout(()=>fe(!1),2e3))},[a]),copyDingtalkSecret:He,copyFeishuWebhookConfig:(0,Y.useCallback)(async()=>{let e=a?.feishu;if(!e)return;let t={connectionMode:e.connectionMode,verificationToken:e.verificationToken||``,encryptKey:e.encryptKey||``,webhookHost:e.webhookHost||``,webhookPort:e.webhookPort||0,webhookPath:e.webhookPath||``};await navigator.clipboard.writeText(JSON.stringify(t,null,2)).catch(()=>{}),me(!0),window.setTimeout(()=>me(!1),2e3)},[a]),onTgAccountsBlur:(0,Y.useCallback)(()=>{if(!a)return;let e=z.trim();if(!e){Me({accounts:{}}),V(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Me({accounts:t}),V(``)}catch(e){V(e instanceof Error?e.message:n.jsonInvalid)}},[a,z,Me,n.jsonObjectAccounts,n.jsonInvalid]),onWxAccountsBlur:(0,Y.useCallback)(()=>{if(!a)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)}},[a,ge,Ne,n.jsonObjectAccounts,n.jsonInvalid]),onFeishuAccountsBlur:(0,Y.useCallback)(()=>{if(!a)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)}},[a,W,Pe,n.jsonObjectAccounts,n.jsonInvalid]),onDingtalkAccountsBlur:(0,Y.useCallback)(()=>{if(!a)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)}},[a,xe,$,n.jsonObjectAccounts,n.jsonInvalid]),dmOpts:(0,Y.useMemo)(()=>[`pairing`,`allowlist`,`open`,`disabled`].map(e=>({value:e,label:n.policy.dm[e]})),[n.policy.dm]),groupOpts:(0,Y.useMemo)(()=>[`open`,`disabled`,`allowlist`].map(e=>({value:e,label:n.policy.group[e]})),[n.policy.group]),replyOpts:(0,Y.useMemo)(()=>[`off`,`first`,`all`].map(e=>({value:e,label:n.policy.reply[e]})),[n.policy.reply]),streamOpts:(0,Y.useMemo)(()=>[`off`,`partial`,`block`].map(e=>({value:e,label:n.policy.stream[e]})),[n.policy.stream])}}function Le({open:e,onOpenChange:t,ch:n,onLoginSuccess:r,moreSettings:i}){let[o,s]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null),[y,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(!1),A=(0,Y.useCallback)(async()=>{S(null),w(null),d(null),s(!0);try{let e=await Ee();v(e.qrcodeUrl),d(e.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{s(!1)}},[]);(0,Y.useEffect)(()=>{if(!e){d(null),v(null),S(null),E(null),O(!1),w(null);return}A()},[e,A]),(0,Y.useEffect)(()=>{if(!c)return;let e=!1,i,a=async()=>{try{let a=await Q(c);if(e)return;if(a.phase===`polling`){v(a.qrcodeUrl),a.qrStatus===`scaned`?w(n.weixinQrLoginScanned):w(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()):(S(a.message),v(null));return}a.phase===`unknown`&&w(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),S(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)}},[c,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,Y.useEffect)(()=>{if(!_){E(null),O(!1);return}let e=!1;return O(!1),X.toDataURL(_,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||E(t)}).catch(()=>{e||(O(!0),E(null))}),()=>{e=!0}},[_]);let M=!!(_&&c),N=e&&!y&&!M;return(0,I.jsx)(m,{open:e,onOpenChange:t,children:(0,I.jsxs)(k,{children:[(0,I.jsx)(a,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,I.jsxs)(g,{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`,x,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,I.jsx)(l,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`absolute right-3 top-3 z-20 rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":n.weixinQrModalCloseAria,children:(0,I.jsx)(f,{className:`size-4`})})}),(0,I.jsx)(h,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,I.jsx)(j,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,I.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,I.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,I.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(M||N)?(0,I.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,I.jsx)(`p`,{className:u(`min-h-[1.25rem] text-center text-sm`,C&&!N?`text-accent`:`text-fg-muted`),children:N?n.weixinQrLoginBusy:C??`\xA0`}),(0,I.jsxs)(`div`,{className:u(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,N&&`bg-surface-muted/40 dark:bg-surface-base`),children:[N?(0,I.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,M&&_&&!y&&T&&!D?(0,I.jsx)(`img`,{src:T,alt:``,className:`relative z-[1] size-full object-contain`}):null,M&&_&&!y&&!T&&!D&&!N?(0,I.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,M&&_&&!y&&D?(0,I.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,I.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,I.jsxs)(`a`,{href:_,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent underline-offset-2 hover:underline`,children:[(0,I.jsx)(b,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,I.jsx)(`div`,{className:`mt-6`,children:(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:o,onClick:()=>void A(),children:o?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),i?(0,I.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:i}):null]})]})})}function Re({wx:e,updateWeixin:t,ch:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,channelAgentRoutesWx:l,defaultAgentId:d,agentItems:f,onAgentRouteChange:p,routingDisabled:m}){let h=H;return(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinAllowFrom}),(0,I.jsx)(`textarea`,{className:u(h(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`wxid_..., openid_...`,value:e.allowFrom.join(`, `),onChange:e=>t({allowFrom:e.target.value.split(/[,\n]/).map(e=>e.trim()).filter(Boolean)})}),(0,I.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,I.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,I.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:i}),(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.historyLimit}),(0,I.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.textChunkLimit}),(0,I.jsx)(`input`,{type:`number`,min:1e3,max:1e4,step:100,className:h(),value:e.textChunkLimit,onChange:e=>t({textChunkLimit:parseInt(e.target.value,10)||4e3})})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinRouteTag}),(0,I.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,I.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,I.jsx)(q,{children:n.weixinDebugDesc}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,I.jsx)(K,{children:n.weixinAccountsJson}),(0,I.jsx)(`textarea`,{className:u(h(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:a,onChange:e=>o(e.target.value),onBlur:c,placeholder:`{ "personal": { "name": "...", "cdnBaseUrl": "...", "enabled": true } }`}),s?(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}):(0,I.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,I.jsx)(Se,{accountIds:z(e),routes:l,defaultAgentId:d,agentItems:f,disabled:m,onChange:p,ch:n})]})}function ze({ch:e,wx:t,updateWeixin:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,form:l,chatAgents:u,onAgentRouteChange:d,saving:f,dirty:m,save:h,discard:g}){return(0,I.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer list-none rounded-xl px-3 py-2.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(N,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,I.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,I.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,I.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,I.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,I.jsx)(Re,{wx:t,updateWeixin:n,ch:e,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,channelAgentRoutesWx:l.channelAgentRoutes.weixin,defaultAgentId:l.defaultAgentId,agentItems:u?.items??[],onAgentRouteChange:d,routingDisabled:f})}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,I.jsx)(p,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!m||f,onClick:g,children:e.discard}),(0,I.jsx)(p,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!m||f,onClick:async()=>{await h()},children:f?e.saving:e.save})]})]})]})}function Be(){let{language:e,m:t,ch:n,hasToken:r,loading:i,fetchError:a,mutate:o,form:c,baseline:l,dirty:u,saving:d,error:f,saveOk:m,weixinModalOpen:h,setWeixinModalOpen:g,telegramModalOpen:_,setTelegramModalOpen:v,feishuModalOpen:y,setFeishuModalOpen:x,removeTarget:S,setRemoveTarget:C,weixinSuccessBanner:w,setWeixinSuccessBanner:T,dingtalkModalOpen:E,setDingtalkModalOpen:O,feishuSetupSuccessBanner:k,dingtalkSetupSuccessBanner:A,tgAdvanced:j,setTgAdvanced:M,showToken:N,setShowToken:P,showFeishuSecret:ee,setShowFeishuSecret:te,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,showDingtalkSecret:ae,setShowDingtalkSecret:se,copied:ce,feishuCopied:F,dingtalkCopied:le,feishuWebhookCopied:ue,tgAccountsDraft:de,setTgAccountsDraft:L,tgAccountsError:R,wxAccountsDraft:me,setWxAccountsDraft:z,wxAccountsError:B,feishuAccountsDraft:he,setFeishuAccountsDraft:V,feishuAccountsError:ge,dingtalkAccountsDraft:H,setDingtalkAccountsDraft:_e,dingtalkAccountsError:U,chatAgents:W,updateChannelAgentRoute:ve,updateTelegram:K,updateWeixin:q,updateFeishu:J,updateDingtalk:Se,save:Y,discard:X,toggleChannelEnabled:Z,removeChannel:we,copyToken:Te,handleFeishuQrSetupSuccess:Ee,handleDingtalkQrSetupSuccess:Q,copyFeishuSecret:De,copyDingtalkSecret:Oe,copyFeishuWebhookConfig:ke,onTgAccountsBlur:Ae,onWxAccountsBlur:je,onFeishuAccountsBlur:$,onDingtalkAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue}=Ie();if(!r)return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,I.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,I.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,I.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,I.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!c)return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,I.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,I.jsx)(p,{type:`button`,variant:`secondary`,onClick:()=>void o(),children:n.retry})]});let We=c.weixin,Ge=c.telegram,Ke=c.feishu,qe=c.dingtalk,Je=be(We),Ye=ye(Ge),Xe=G(Ke),Ze=xe(qe),Qe=(0,I.jsx)(Ne,{ch:n,form:c,baseline:l,showFeishuSecret:ee,setShowFeishuSecret:te,showFeishuWebhookSecrets:ne,setShowFeishuWebhookSecrets:ie,feishuCopied:F,feishuWebhookCopied:ue,copyFeishuSecret:De,copyFeishuWebhookConfig:ke,updateFeishu:J,updateChannelAgentRoute:ve,feishuAccountsDraft:he,setFeishuAccountsDraft:V,feishuAccountsError:ge,onFeishuAccountsBlur:$,dmOpts:Be,groupOpts:Ve,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),$e=(0,I.jsx)(Ce,{ch:n,form:c,baseline:l,showDingtalkSecret:ae,setShowDingtalkSecret:se,dingtalkCopied:le,copyDingtalkSecret:Oe,updateDingtalk:Se,updateChannelAgentRoute:ve,dingtalkAccountsDraft:H,setDingtalkAccountsDraft:_e,dingtalkAccountsError:U,onDingtalkAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),et=(0,I.jsx)(ze,{ch:n,wx:We,updateWeixin:q,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:me,setWxAccountsDraft:z,wxAccountsError:B,onWxAccountsBlur:je,form:c,chatAgents:W,onAgentRouteChange:(e,t)=>ve(`weixin`,e,t),saving:d,dirty:u,save:Y,discard:X});return(0,I.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,I.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,I.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,I.jsxs)(`a`,{href:oe(e,`channels`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,I.jsx)(b,{className:`size-3.5`})]})]}),u?(0,I.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,I.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,I.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,w?(0,I.jsx)(`p`,{className:`text-xs text-accent`,children:w}):null,k?(0,I.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:k}):null,A?(0,I.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:A}):null,(0,I.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,I.jsx)(fe,{icon:(0,I.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.weixinTitle,subtitle:n.weixinSubtitle,configured:Je,enabled:We.enabled,toggleDisabled:d,onToggle:e=>void Z(`weixin`,e),onConfigure:()=>g(!0),onEdit:()=>g(!0),onRemove:()=>C(`weixin`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(D,{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:()=>C(`telegram`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.feishuTitle,subtitle:n.feishuSubtitle,configured:Xe,enabled:Ke.enabled,toggleDisabled:d,onToggle:e=>void Z(`feishu`,e),onConfigure:()=>x(!0),onEdit:()=>x(!0),onRemove:()=>C(`feishu`),ch:n}),(0,I.jsx)(fe,{icon:(0,I.jsx)(s,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.dingtalkTitle,subtitle:n.dingtalkSubtitle,configured:Ze,enabled:qe.enabled,toggleDisabled:d,onToggle:e=>void Z(`dingtalk`,e),onConfigure:()=>O(!0),onEdit:()=>O(!0),onRemove:()=>C(`dingtalk`),ch:n})]}),(0,I.jsx)(Le,{open:h,onOpenChange:g,ch:n,onLoginSuccess:async()=>{await o(),T(n.weixinQrLoginSuccess),window.setTimeout(()=>T(null),4e3)},moreSettings:et}),(0,I.jsx)(Fe,{open:_,onOpenChange:v,ch:n,form:c,baseline:l,tgAdvanced:j,setTgAdvanced:M,showToken:N,setShowToken:P,copied:ce,copyToken:Te,updateTelegram:K,updateChannelAgentRoute:ve,tgAccountsDraft:de,setTgAccountsDraft:L,tgAccountsError:R,onTgAccountsBlur:Ae,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:W,saving:d,dirty:u,save:Y,discard:X}),(0,I.jsx)(Pe,{open:y,onOpenChange:x,ch:n,onSetupSuccess:Ee,moreSettings:Qe}),(0,I.jsx)(Me,{open:E,onOpenChange:O,ch:n,onSetupSuccess:Q,moreSettings:$e}),(0,I.jsx)(pe,{open:S!==null,onOpenChange:e=>{e||C(null)},ch:n,removeTarget:S,onCancel:()=>C(null),saving:d,onConfirmRemove:()=>void we()})]})}export{Be as ChannelsSettingsPanel};
2
+ //# sourceMappingURL=channels-settings-BDkP3YdO.js.map