@xopcai/xopc 0.0.34 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agents-BENeGWaV.js → agents-3MgROWaB.js} +2 -2
- package/dist/gateway/static/root/assets/{agents-BENeGWaV.js.map → agents-3MgROWaB.js.map} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-C8S_3XR3.js → apps-page-Dh89sZVt.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-C8S_3XR3.js.map → apps-page-Dh89sZVt.js.map} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-Z0gz9LEn.js → channels-settings-BNR4uMFv.js} +2 -2
- package/dist/gateway/static/root/assets/{channels-settings-Z0gz9LEn.js.map → channels-settings-BNR4uMFv.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-api-DHcunvTO.js → cron-api-HehSuhku.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-api-DHcunvTO.js.map → cron-api-HehSuhku.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-page-CdZjOHQ5.js → cron-page-cNl5O7jj.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-page-CdZjOHQ5.js.map → cron-page-cNl5O7jj.js.map} +1 -1
- package/dist/gateway/static/root/assets/{dist-DPEltH1B.js → dist-RpqJxYGW.js} +2 -2
- package/dist/gateway/static/root/assets/{dist-DPEltH1B.js.map → dist-RpqJxYGW.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DyEkbdRu.js → extension-debug-page-C38A0UVx.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-DyEkbdRu.js.map → extension-debug-page-C38A0UVx.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-Vr_24oNG.js → extension-page-BHVeBMn8.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-Vr_24oNG.js.map → extension-page-BHVeBMn8.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-D3wIHYGH.js → extension-settings-page-D1iDIHYn.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-settings-page-D3wIHYGH.js.map → extension-settings-page-D1iDIHYn.js.map} +1 -1
- package/dist/gateway/static/root/assets/{index-DfzxemgG.js → index-C9ACajYe.js} +5 -5
- package/dist/gateway/static/root/assets/{index-DfzxemgG.js.map → index-C9ACajYe.js.map} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-D-swbxzE.js → logs-page-DxbZy88k.js} +2 -2
- package/dist/gateway/static/root/assets/{logs-page-D-swbxzE.js.map → logs-page-DxbZy88k.js.map} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-CkevfEBJ.js → sessions-page-Cl-1QJM9.js} +2 -2
- package/dist/gateway/static/root/assets/{sessions-page-CkevfEBJ.js.map → sessions-page-Cl-1QJM9.js.map} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-CGDCcKXO.js → settings-page-DUYYElOB.js} +2 -2
- package/dist/gateway/static/root/assets/{settings-page-CGDCcKXO.js.map → settings-page-DUYYElOB.js.map} +1 -1
- package/dist/gateway/static/root/assets/skills-page-MiXi4U0-.js +3 -0
- package/dist/gateway/static/root/assets/skills-page-MiXi4U0-.js.map +1 -0
- package/dist/gateway/static/root/index.html +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/skills-page-ZTABuog7.js +0 -3
- package/dist/gateway/static/root/assets/skills-page-ZTABuog7.js.map +0 -1
- /package/skills/{meta → tools}/skill-creator/LICENSE.txt +0 -0
- /package/skills/{meta → tools}/skill-creator/SKILL-zh.md +0 -0
- /package/skills/{meta → tools}/skill-creator/SKILL.md +0 -0
- /package/skills/{meta → tools}/skill-creator/agents/analyzer.md +0 -0
- /package/skills/{meta → tools}/skill-creator/agents/comparator.md +0 -0
- /package/skills/{meta → tools}/skill-creator/agents/grader.md +0 -0
- /package/skills/{meta → tools}/skill-creator/assets/eval_review.html +0 -0
- /package/skills/{meta → tools}/skill-creator/eval-viewer/generate_review.py +0 -0
- /package/skills/{meta → tools}/skill-creator/eval-viewer/viewer.html +0 -0
- /package/skills/{meta → tools}/skill-creator/references/schemas.md +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/__init__.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/aggregate_benchmark.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/generate_report.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/improve_description.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/package_skill.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/quick_validate.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/run_eval.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/run_loop.py +0 -0
- /package/skills/{meta → tools}/skill-creator/scripts/utils.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r}from"./vendor-swr-B5fPo7KK.js";import{t as i}from"./cn-BMCV0OMB.js";import{At as a,Bn as o,Dn as s,Dt as c,En as l,Et as u,Gr as d,Kr as f,Nn as p,On as m,Ot as h,Tt as g,Ur as _,Wr as v,Xr as y,_r as b,_t as x,bn as S,cn as C,er as w,gn as T,hn as E,kn as D,kt as O,li as k,pn as A,pr as j,ui as M,vt as ee,wn as N,wt as te,x as ne,yr as re,yt as ie}from"./index-DfzxemgG.js";import{a as ae,i as oe,n as se,r as P,t as ce}from"./dist-DPEltH1B.js";import{t as le}from"./browser-DNXWYwzc.js";var F=n();function I({icon:e,title:t,subtitle:n,configured:r,enabled:a,onToggle:s,toggleDisabled:c,onConfigure:l,onEdit:u,onRemove:d,ch:p}){return(0,F.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,F.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,F.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,F.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:p.hubConnectedBadge}):null]}),(0,F.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,F.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,F.jsxs)(oe,{children:[(0,F.jsx)(ae,{asChild:!0,children:(0,F.jsx)(D,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":p.menuMoreAria,children:(0,F.jsx)(f,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,F.jsx)(P,{children:(0,F.jsxs)(ce,{className:`z-[70] min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[(0,F.jsx)(se,{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:()=>u(),children:(0,F.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(j,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),p.menuEditConfig]})}),(0,F.jsx)(se,{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:()=>d(),children:(0,F.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(o,{className:`size-4 shrink-0`,strokeWidth:1.75}),p.menuRemoveConfig]})})]})})]}),(0,F.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} — ${p.enableChannelAria}`,disabled:c,className:i(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,a?`justify-end bg-accent`:`justify-start bg-surface-hover`,c&&`cursor-not-allowed opacity-50`),onClick:()=>void s(!a),children:(0,F.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,F.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:l,children:p.hubConfigureButton})})]})}function ue({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:o,saving:s,onConfirmRemove:l}){return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[70] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[70] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,F.jsx)(a,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,F.jsx)(u,{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,F.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,onClick:o,children:n.modalCancel}),(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:s,onClick:l,children:s?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 de(e){return Object.keys(e.accounts??{}).sort()}function fe(e){return Object.keys(e.accounts??{}).sort()}function pe(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 me(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 he(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 z(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 B(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,s,`dark:border-edge`)}function V(){return i(l,N)}function H(e){return e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean).map(e=>/^-?\d+$/.test(e)?Number(e):e)}function U(e){return e.map(String).join(`, `)}function ge(e){let t=e.accounts?.default?.botToken;return typeof t==`string`?t:``}function _e(e){return Object.values(e.accounts??{}).some(e=>typeof e.botToken==`string`&&e.botToken.trim().length>0)}function W(e){return Object.keys(e.accounts??{}).length>0||e.allowFrom.length>0}function ve(e){return!!(e.appId?.trim()&&e.appSecret?.trim())||Object.keys(e.accounts??{}).length>0}function G(e){return!!(e.clientId?.trim()&&e.clientSecret?.trim())||Object.keys(e.accounts??{}).length>0}function K({children:e}){return(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e}),(0,F.jsx)(`select`,{className:V(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Y({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:a,onChange:o,ch:s}){let c=m(S(e=>e.language)).agentsSettings;if(e.length===0)return null;let l=r.length>0?r:[{id:n}];return(0,F.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(K,{children:s.agentRoutingTitle}),(0,F.jsx)(q,{children:s.agentRoutingHint})]}),(0,F.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,F.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,F.jsxs)(`div`,{className:`min-w-0`,children:[(0,F.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,F.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,F.jsxs)(`div`,{className:`min-w-0`,children:[(0,F.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,F.jsx)(`select`,{id:`agent-route-${e}`,className:i(B(),N),disabled:a,value:(t[e]??n).toLowerCase(),onChange:t=>o(e,t.target.value),children:l.map(e=>(0,F.jsx)(`option`,{value:e.id,children:`${ne(e,c)} (${e.id})`},e.id))})]})]},e))})]})}function ye({ch:e,form:t,baseline:n,showDingtalkSecret:r,setShowDingtalkSecret:a,dingtalkCopied:o,copyDingtalkSecret:s,updateDingtalk:c,updateChannelAgentRoute:l,dingtalkAccountsDraft:u,setDingtalkAccountsDraft:d,dingtalkAccountsError:f,onDingtalkAccountsBlur:p,dmOpts:m,groupOpts:h,chatAgents:g,saving:b,dirty:x,save:S,discard:C}){let w=B,T=t.dingtalk,E=n?.dingtalk?.clientSecret??``,O=!r&&!!String(E).trim()&&T.clientSecret===E;return(0,F.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,F.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,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(k,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:T.enabled,onChange:e=>c({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.dingtalkClientId,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.clientId,onChange:e=>c({clientId:e.target.value}),placeholder:`dingxxx`}),(0,F.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.dingtalkClientSecret,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:O,value:O?`*`.repeat(Math.max(1,T.clientSecret.length)):T.clientSecret,onChange:e=>{O||c({clientSecret:e.target.value})},placeholder:`••••••••`}),T.clientSecret?(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void s(),children:[o?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),o?e.copied:e.copy]}):null,(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e=>!e),children:[r?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,F.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.dingtalkEndpoint}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.endpoint,onChange:e=>c({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,F.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.debug,onChange:e=>c({debug:e.target.checked})}),e.dingtalkDebug]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.dmPolicy}),(0,F.jsx)(`select`,{className:w(),value:T.dmPolicy,onChange:e=>c({dmPolicy:e.target.value}),children:m.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.groupPolicy}),(0,F.jsx)(`select`,{className:w(),value:T.groupPolicy,onChange:e=>c({groupPolicy:e.target.value}),children:h.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.requireMention,onChange:e=>c({requireMention:e.target.checked})}),e.requireMention]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromDm}),(0,F.jsx)(`textarea`,{className:i(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:U(T.allowFrom),onChange:e=>c({allowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromDmDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromGroups}),(0,F.jsx)(`textarea`,{className:i(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:U(T.groupAllowFrom),onChange:e=>c({groupAllowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.historyLimit}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.historyLimit),onChange:e=>c({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.textChunkLimit}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.textChunkLimit),onChange:e=>c({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,F.jsx)(Y,{accountIds:me(T),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:g?.items??[],disabled:b,onChange:(e,t)=>l(`dingtalk`,e,t),ch:e}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.multiAccountJson}),(0,F.jsx)(`textarea`,{className:i(w(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:u,onChange:e=>d(e.target.value),onBlur:p,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),f?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:f}):(0,F.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!x||b,onClick:C,children:e.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!x||b,onClick:async()=>{await S()},children:b?e.saving:e.save})]})]})]})}var X=e(t(),1),Z=e(le(),1);function be(e){return{accountId:e,name:``,enabled:!0,botToken:``,allowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,apiRoot:``,proxy:``,historyLimit:50,textChunkLimit:4e3,streamMode:`partial`}}function xe(){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:be(`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 Se(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??be(`default`),accountId:`default`,botToken:l}}),c.default||(c={...c,default:be(`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}:{}}},_=he(p,de(g.telegram),fe(g.weixin),pe(g.feishu),me(g.dingtalk),h);return{...g,bindingsFull:p.map(e=>({...e})),channelAgentRoutes:_,defaultAgentId:h}}async function Q(e){return(await A(C(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Ce(e){return(await A(C(`/api/channels/weixin/login/${encodeURIComponent(e)}`))).payload.status}async function we(e){let t=e.telegram,n=e.weixin,r=e.feishu,i=e.dingtalk,a=z(e.bindingsFull,e.channelAgentRoutes,de(t),fe(n),pe(r),me(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await A(C(`/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 ee(),s?Se(s):{...e,bindingsFull:a}}async function Te(e){return(await A(C(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Ee(e){return(await A(C(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function $(){return(await A(C(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function De(e){return(await A(C(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Oe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:o}){let[s,l]=(0,X.useState)(!1),[f,m]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),T=(0,X.useCallback)(async()=>{b(null),m(null),v(null),l(!0);try{let e=await $();v(e.qrUrl),m(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{l(!1)}},[]);(0,X.useEffect)(()=>{if(!e){m(null),v(null),b(null),S(null),w(!1),l(!1);return}T()},[e,T]),(0,X.useEffect)(()=>{if(!f)return;let e=!1,n,i=async()=>{try{let i=await De(f);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),m(null),i.ok?(v(null),t(!1),r({clientId:i.clientId})):(b(i.message),v(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),b(i.message),m(null),v(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),b(t instanceof Error?t.message:`Request failed`),m(null),v(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[f,t,r]),(0,X.useEffect)(()=>{if(!_){S(null),w(!1);return}let e=!1;return w(!1),Z.toDataURL(_,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||S(t)}).catch(()=>{e||(w(!0),S(null))}),()=>{e=!0}},[_]);let E=!!(_&&f),k=e&&!y&&!E;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})}),(0,F.jsx)(a,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,F.jsx)(u,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,F.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,F.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,F.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(E||k)?(0,F.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:k?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,F.jsxs)(`div`,{className:i(`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`,k&&`bg-surface-muted/40 dark:bg-surface-base`),children:[k?(0,F.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,E&&_&&!y&&x&&!C?(0,F.jsx)(`img`,{src:x,alt:``,className:`relative z-[1] size-full object-contain`}):null,E&&_&&!y&&!x&&!C&&!k?(0,F.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,E&&_&&!y&&C?(0,F.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,F.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,F.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,F.jsx)(d,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,F.jsx)(`div`,{className:`mt-6`,children:(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:s,onClick:()=>void T(),children:s?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),o?(0,F.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:o}):null]})]})})}function ke({ch:e,form:t,baseline:n,showFeishuSecret:r,setShowFeishuSecret:a,showFeishuWebhookSecrets:o,setShowFeishuWebhookSecrets:s,feishuCopied:c,feishuWebhookCopied:l,copyFeishuSecret:u,copyFeishuWebhookConfig:d,updateFeishu:f,updateChannelAgentRoute:p,feishuAccountsDraft:m,setFeishuAccountsDraft:h,feishuAccountsError:g,onFeishuAccountsBlur:b,dmOpts:x,groupOpts:S,chatAgents:C,saving:w,dirty:T,save:E,discard:O}){let A=B,j=t.feishu,ee=n?.feishu?.appSecret??``,N=!r&&!!String(ee).trim()&&j.appSecret===ee;return(0,F.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,F.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,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(k,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:j.enabled,onChange:e=>f({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.feishuAppId,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.appId,onChange:e=>f({appId:e.target.value}),placeholder:`cli_xxx`}),(0,F.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.feishuAppSecret,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:N,value:N?`*`.repeat(Math.max(1,j.appSecret.length)):j.appSecret,onChange:e=>{N||f({appSecret:e.target.value})},placeholder:`••••••••`}),j.appSecret?(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void u(),children:[c?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),c?e.copied:e.copy]}):null,(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e=>!e),children:[r?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,F.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.feishuDomain}),(0,F.jsxs)(`select`,{className:A(),value:String(j.domain||`feishu`),onChange:e=>f({domain:e.target.value}),children:[(0,F.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,F.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.connectionMode}),(0,F.jsxs)(`select`,{className:A(),value:j.connectionMode,onChange:e=>f({connectionMode:e.target.value}),children:[(0,F.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,F.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,F.jsx)(q,{children:e.connectionModeDesc})]})]}),j.connectionMode===`webhook`?(0,F.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e=>!e),children:[o?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),o?e.hide:e.show]}),(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void d(),children:[l?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),l?e.copied:e.copy]})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.verificationToken}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:o?`text`:`password`,autoComplete:`off`,value:j.verificationToken??``,onChange:e=>f({verificationToken:e.target.value})}),(0,F.jsx)(q,{children:e.verificationTokenDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.encryptKey}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:o?`text`:`password`,autoComplete:`off`,value:j.encryptKey??``,onChange:e=>f({encryptKey:e.target.value})}),(0,F.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,F.jsx)(K,{children:e.webhookHost}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookHost??``,onChange:e=>f({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.webhookPort}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.webhookPort??``),onChange:e=>f({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.webhookPath}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookPath??``,onChange:e=>f({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,F.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.renderMode}),(0,F.jsxs)(`select`,{className:A(),value:j.renderMode,onChange:e=>f({renderMode:e.target.value}),children:[(0,F.jsx)(`option`,{value:`auto`,children:`auto`}),(0,F.jsx)(`option`,{value:`raw`,children:`raw`}),(0,F.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.reactionNotifications}),(0,F.jsxs)(`select`,{className:A(),value:j.reactionNotifications,onChange:e=>f({reactionNotifications:e.target.value}),children:[(0,F.jsx)(`option`,{value:`off`,children:`off`}),(0,F.jsx)(`option`,{value:`own`,children:`own`}),(0,F.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.streaming,onChange:e=>f({streaming:e.target.checked})}),e.enableStreaming]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.dmPolicy}),(0,F.jsx)(`select`,{className:A(),value:j.dmPolicy,onChange:e=>f({dmPolicy:e.target.value}),children:x.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.groupPolicy}),(0,F.jsx)(`select`,{className:A(),value:j.groupPolicy,onChange:e=>f({groupPolicy:e.target.value}),children:S.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.requireMention,onChange:e=>f({requireMention:e.target.checked})}),e.requireMention]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromDm}),(0,F.jsx)(`textarea`,{className:i(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:U(j.allowFrom),onChange:e=>f({allowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromDmDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromGroups}),(0,F.jsx)(`textarea`,{className:i(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:U(j.groupAllowFrom),onChange:e=>f({groupAllowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.historyLimit}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.historyLimit),onChange:e=>f({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.textChunkLimit}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.textChunkLimit),onChange:e=>f({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,F.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,F.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,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.tools?.[e],onChange:t=>f({tools:{...j.tools,[e]:t.target.checked}})}),t]},e))}),(0,F.jsx)(`div`,{className:`mt-2`,children:(0,F.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,F.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,F.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.actions?.reactions,onChange:e=>f({actions:{...j.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,F.jsx)(Y,{accountIds:pe(j),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:C?.items??[],disabled:w,onChange:(e,t)=>p(`feishu`,e,t),ch:e}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.multiAccountJson}),(0,F.jsx)(`textarea`,{className:i(A(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:m,onChange:e=>h(e.target.value),onBlur:b,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),g?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:g}):(0,F.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:O,children:e.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:async()=>{await E()},children:w?e.saving:e.save})]})]})]})}function Ae({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:o}){let[s,l]=(0,X.useState)(!1),[f,m]=(0,X.useState)(`feishu`),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),k=(0,X.useCallback)(async e=>{m(e),S(null),v(null),b(null),l(!0);try{let t=await Te({domain:e});b(t.qrUrl),v(t.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{l(!1)}},[]);(0,X.useEffect)(()=>{if(!e){v(null),b(null),S(null),w(null),E(!1),m(`feishu`),l(!1);return}k(`feishu`)},[e,k]),(0,X.useEffect)(()=>{if(!_)return;let e=!1,n,i=async()=>{try{let i=await Ee(_);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),v(null),i.ok?(b(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(S(i.message),b(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),S(i.message),v(null),b(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),S(t instanceof Error?t.message:`Request failed`),v(null),b(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[_,t,r]),(0,X.useEffect)(()=>{if(!y){w(null),E(!1);return}let e=!1;return E(!1),Z.toDataURL(y,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[y]);let A=!!(y&&_),j=e,M=e&&!x&&!A;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})}),(0,F.jsx)(a,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,F.jsx)(u,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,F.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,F.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[x?(0,F.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:x}):null,!x&&(A||M)?(0,F.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:M?n.feishuQrStarting:n.feishuQrScanHint}),(0,F.jsxs)(`div`,{className:i(`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`,M&&`bg-surface-muted/40 dark:bg-surface-base`),children:[M?(0,F.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&y&&!x&&C&&!T?(0,F.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&y&&!x&&!C&&!T&&!M?(0,F.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,A&&y&&!x&&T?(0,F.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,F.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,F.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,F.jsx)(d,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),j?(0,F.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,F.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,F.jsx)(`button`,{type:`button`,disabled:s,className:i(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,f===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void k(`feishu`),children:n.feishuRegionChina}),(0,F.jsx)(`button`,{type:`button`,disabled:s,className:i(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,f===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void k(`lark`),children:n.feishuRegionInternational})]})}):null,(0,F.jsx)(`div`,{className:`mt-6`,children:(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:s,onClick:()=>void k(f),children:s?n.feishuQrStarting:n.feishuQrRegenerate})}),o?(0,F.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:o}):null]})]})})}function je({tg:e,updateTelegram:t,ch:n,dmOpts:r,groupOpts:a,replyOpts:o,streamOpts:s,tgAccountsDraft:c,setTgAccountsDraft:l,tgAccountsError:u,onTgAccountsBlur:d}){let f=B;return(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.apiRoot}),(0,F.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.proxy}),(0,F.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,F.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,F.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:a}),(0,F.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:o}),(0,F.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:s}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.allowFromGroups}),(0,F.jsx)(`textarea`,{className:i(f(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`-1001234567890`,value:U(e.groupAllowFrom),onChange:e=>t({groupAllowFrom:H(e.target.value)})})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.historyLimit}),(0,F.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.textChunkLimit}),(0,F.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,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.multiAccountJson}),(0,F.jsx)(`textarea`,{className:i(f(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:c,onChange:e=>l(e.target.value),onBlur:d,placeholder:`{ "personal": { "accountId": "personal", "botToken": "...", ... } }`}),u?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:u}):(0,F.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Me({open:e,onOpenChange:t,ch:n,form:r,baseline:o,tgAdvanced:s,setTgAdvanced:l,showToken:d,setShowToken:f,copied:m,copyToken:b,updateTelegram:x,updateChannelAgentRoute:S,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:E,dmOpts:A,groupOpts:j,replyOpts:ee,streamOpts:N,chatAgents:ne,saving:re,dirty:ie,save:ae,discard:oe}){let se=B,P=r.telegram,ce=o?ge(o.telegram):``,le=ge(P),I=!d&&!!String(ce).trim()&&le===ce;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,48rem)] w-[min(100%-2rem,36rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(a,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,F.jsx)(u,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})})]}),(0,F.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:P.enabled,onChange:e=>x({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,F.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[n.telegramToken,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(`input`,{className:i(se(),`min-w-0 flex-1 font-mono text-xs`),type:d?`text`:`password`,autoComplete:`off`,readOnly:I,value:I?`*`.repeat(Math.max(1,ce.length)):le,onChange:e=>{if(I)return;let t=P.accounts?.default??be(`default`);x({accounts:{...P.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),le?(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void b(),children:[m?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),m?n.copied:n.copy]}):null,(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>f(e=>!e),children:[d?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),d?n.hide:n.show]})]}),(0,F.jsx)(q,{children:n.telegramTokenDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.allowFromDm}),(0,F.jsx)(`textarea`,{className:i(se(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:U(P.allowFrom),onChange:e=>x({allowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:n.allowFromDmDesc})]}),(0,F.jsx)(Y,{accountIds:de(P),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:ne?.items??[],disabled:re,onChange:(e,t)=>S(`telegram`,e,t),ch:n}),(0,F.jsxs)(D,{type:`button`,variant:`ghost`,className:`-ml-2 h-auto justify-start px-2 py-1 text-sm text-fg-muted hover:text-fg`,onClick:()=>l(e=>!e),children:[(0,F.jsx)(k,{className:i(`mr-1 size-4 transition-transform`,s&&`rotate-180`)}),s?n.advancedHide:n.advancedShow]}),s?(0,F.jsx)(je,{tg:P,updateTelegram:x,ch:n,dmOpts:A,groupOpts:j,replyOpts:ee,streamOpts:N,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:E}):null]}),(0,F.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,F.jsx)(D,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,F.jsx)(D,{type:`button`,variant:`secondary`,disabled:!ie||re,onClick:oe,children:n.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,disabled:!ie||re,onClick:async()=>{await ae()&&t(!1)},children:re?n.saving:n.save})]})]})]})})}function Ne(){let e=S(e=>e.language),t=m(e),n=t.channelsSettings,i=!!E(e=>e.token),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[D,O]=(0,X.useState)(null),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),[ee,N]=(0,X.useState)(null),[te,ne]=(0,X.useState)(!1),[re,ae]=(0,X.useState)(!1),[oe,se]=(0,X.useState)(!1),[P,ce]=(0,X.useState)(!1),[le,F]=(0,X.useState)(!1),[I,ue]=(0,X.useState)(!1),[L,R]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(!1),[pe,me]=(0,X.useState)(!1),[he,z]=(0,X.useState)(``),[B,V]=(0,X.useState)(``),[H,U]=(0,X.useState)(``),[_e,W]=(0,X.useState)(``),[ve,G]=(0,X.useState)(``),[K,q]=(0,X.useState)(``),[J,Y]=(0,X.useState)(``),[ye,Z]=(0,X.useState)(``),{data:be}=r(i?`gateway-chat-agents-ch`:null,x,{revalidateOnFocus:!1}),{data:Q,error:Ce,isLoading:Te,mutate:Ee}=ie(i),$=(0,X.useMemo)(()=>Q?.payload?.config===void 0?null:Se(Q.payload.config),[Q]),De=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!i){o(null),c(null);return}$!==null&&(De||(o($),c(structuredClone($)),z(JSON.stringify($.telegram.accounts??{},null,2)),V(``),U(JSON.stringify($.weixin.accounts??{},null,2)),W(``),G(JSON.stringify($.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify($.dingtalk?.accounts??{},null,2)),Z(``),h(!1)))},[i,$,De]);let Oe=!!(i&&Te&&Q===void 0&&!Ce),ke=Ce instanceof Error?Ce.message:Ce?String(Ce):null,Ae=(0,X.useCallback)((e,t,n)=>{o(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()}}}})},[]),je=(0,X.useCallback)(e=>{o(t=>t?{...t,telegram:{...t.telegram,...e}}:null)},[]),Me=(0,X.useCallback)(e=>{o(t=>t?{...t,weixin:{...t.weixin,...e}}:null)},[]),Ne=(0,X.useCallback)(e=>{o(t=>t?{...t,feishu:{...t.feishu,...e}}:null)},[]),Pe=(0,X.useCallback)(e=>{o(t=>t?{...t,dingtalk:{...t.dingtalk,...e}}:null)},[]),Fe=(0,X.useCallback)(async()=>{if(!a||l)return!1;u(!0),f(null),h(!1);try{let e=await we(a);o(e);let t=structuredClone(e);return c(t),z(JSON.stringify(t.telegram.accounts??{},null,2)),V(``),U(JSON.stringify(t.weixin.accounts??{},null,2)),W(``),G(JSON.stringify(t.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify(t.dingtalk?.accounts??{},null,2)),Z(``),h(!0),window.setTimeout(()=>h(!1),2500),!0}catch(e){return f(e instanceof Error?e.message:n.saveError),!1}finally{u(!1)}},[a,l,n.saveError]),Ie=(0,X.useCallback)(()=>{if(!s)return;let e=structuredClone(s);o(e),z(JSON.stringify(e.telegram.accounts??{},null,2)),V(``),U(JSON.stringify(e.weixin.accounts??{},null,2)),W(``),G(JSON.stringify(e.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify(e.dingtalk?.accounts??{},null,2)),Z(``),f(null),h(!1)},[s]),Le=(0,X.useCallback)(async(e,t)=>{if(!a||l)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}};o(i),u(!0),f(null);try{let e=await we(i);o(e);let t=structuredClone(e);c(t),z(JSON.stringify(t.telegram.accounts??{},null,2)),U(JSON.stringify(t.weixin.accounts??{},null,2)),G(JSON.stringify(t.feishu?.accounts??{},null,2)),Y(JSON.stringify(t.dingtalk?.accounts??{},null,2))}catch(e){f(e instanceof Error?e.message:n.saveError),o(r)}finally{u(!1)}},[a,l,n.saveError]),Re=(0,X.useCallback)(async()=>{if(!a||!D||l)return;let e=xe(),t=D===`weixin`?{...a,weixin:e.weixin}:D===`telegram`?{...a,telegram:e.telegram}:D===`feishu`?{...a,feishu:e.feishu}:{...a,dingtalk:e.dingtalk};u(!0),f(null);try{let e=await we(t);o(e);let n=structuredClone(e);c(n),z(JSON.stringify(n.telegram.accounts??{},null,2)),U(JSON.stringify(n.weixin.accounts??{},null,2)),V(``),W(``),G(JSON.stringify(n.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify(n.dingtalk?.accounts??{},null,2)),Z(``),O(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){f(e instanceof Error?e.message:n.saveError)}finally{u(!1)}},[a,D,l,n.saveError]),ze=(0,X.useCallback)(async()=>{let e=a?ge(a.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),ue(!0),window.setTimeout(()=>ue(!1),2e3))},[a]),Be=(0,X.useCallback)(e=>{Ne({appId:e.appId,domain:e.domain,enabled:!0}),Ee(),M(n.feishuQrSetupSuccess),window.setTimeout(()=>M(null),4e3)},[Ne,Ee,n.feishuQrSetupSuccess]),Ve=(0,X.useCallback)(e=>{Pe({clientId:e.clientId,enabled:!0}),Ee(),N(n.dingtalkQrSetupSuccess),window.setTimeout(()=>N(null),4e3)},[Pe,Ee,n.dingtalkQrSetupSuccess]),He=(0,X.useCallback)(async()=>{let e=a?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),fe(!0),window.setTimeout(()=>fe(!1),2e3))},[a]);return{language:e,m:t,ch:n,hasToken:i,loading:Oe,fetchError:ke,mutate:Ee,form:a,baseline:s,dirty:De,saving:l,error:d,saveOk:p,weixinModalOpen:g,setWeixinModalOpen:_,telegramModalOpen:v,setTelegramModalOpen:y,feishuModalOpen:b,setFeishuModalOpen:C,dingtalkModalOpen:w,setDingtalkModalOpen:T,removeTarget:D,setRemoveTarget:O,weixinSuccessBanner:k,setWeixinSuccessBanner:A,feishuSetupSuccessBanner:j,dingtalkSetupSuccessBanner:ee,tgAdvanced:te,setTgAdvanced:ne,showToken:re,setShowToken:ae,showFeishuSecret:oe,setShowFeishuSecret:se,showFeishuWebhookSecrets:P,setShowFeishuWebhookSecrets:ce,showDingtalkSecret:le,setShowDingtalkSecret:F,copied:I,feishuCopied:L,dingtalkCopied:de,feishuWebhookCopied:pe,tgAccountsDraft:he,setTgAccountsDraft:z,tgAccountsError:B,wxAccountsDraft:H,setWxAccountsDraft:U,wxAccountsError:_e,feishuAccountsDraft:ve,setFeishuAccountsDraft:G,feishuAccountsError:K,dingtalkAccountsDraft:J,setDingtalkAccountsDraft:Y,dingtalkAccountsError:ye,chatAgents:be,updateChannelAgentRoute:Ae,updateTelegram:je,updateWeixin:Me,updateFeishu:Ne,updateDingtalk:Pe,save:Fe,discard:Ie,toggleChannelEnabled:Le,removeChannel:Re,copyToken:ze,handleFeishuQrSetupSuccess:Be,handleDingtalkQrSetupSuccess:Ve,copyFeishuSecret:(0,X.useCallback)(async()=>{let e=a?.feishu?.appSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),R(!0),window.setTimeout(()=>R(!1),2e3))},[a]),copyDingtalkSecret:He,copyFeishuWebhookConfig:(0,X.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,X.useCallback)(()=>{if(!a)return;let e=he.trim();if(!e){je({accounts:{}}),V(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);je({accounts:t}),V(``)}catch(e){V(e instanceof Error?e.message:n.jsonInvalid)}},[a,he,je,n.jsonObjectAccounts,n.jsonInvalid]),onWxAccountsBlur:(0,X.useCallback)(()=>{if(!a)return;let e=H.trim();if(!e){Me({accounts:{}}),W(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Me({accounts:t}),W(``)}catch(e){W(e instanceof Error?e.message:n.jsonInvalid)}},[a,H,Me,n.jsonObjectAccounts,n.jsonInvalid]),onFeishuAccountsBlur:(0,X.useCallback)(()=>{if(!a)return;let e=ve.trim();if(!e){Ne({accounts:{}}),q(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Ne({accounts:t}),q(``)}catch(e){q(e instanceof Error?e.message:n.jsonInvalid)}},[a,ve,Ne,n.jsonObjectAccounts,n.jsonInvalid]),onDingtalkAccountsBlur:(0,X.useCallback)(()=>{if(!a)return;let e=J.trim();if(!e){Pe({accounts:{}}),Z(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Pe({accounts:t}),Z(``)}catch(e){Z(e instanceof Error?e.message:n.jsonInvalid)}},[a,J,Pe,n.jsonObjectAccounts,n.jsonInvalid]),dmOpts:(0,X.useMemo)(()=>[`pairing`,`allowlist`,`open`,`disabled`].map(e=>({value:e,label:n.policy.dm[e]})),[n.policy.dm]),groupOpts:(0,X.useMemo)(()=>[`open`,`disabled`,`allowlist`].map(e=>({value:e,label:n.policy.group[e]})),[n.policy.group]),replyOpts:(0,X.useMemo)(()=>[`off`,`first`,`all`].map(e=>({value:e,label:n.policy.reply[e]})),[n.policy.reply]),streamOpts:(0,X.useMemo)(()=>[`off`,`partial`,`block`].map(e=>({value:e,label:n.policy.stream[e]})),[n.policy.stream])}}function Pe({open:e,onOpenChange:t,ch:n,onLoginSuccess:r,moreSettings:o}){let[s,l]=(0,X.useState)(!1),[f,m]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),k=(0,X.useCallback)(async()=>{b(null),S(null),m(null),l(!0);try{let e=await Q();v(e.qrcodeUrl),m(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{l(!1)}},[]);(0,X.useEffect)(()=>{if(!e){m(null),v(null),b(null),w(null),E(!1),S(null);return}k()},[e,k]),(0,X.useEffect)(()=>{if(!f)return;let e=!1,i,a=async()=>{try{let a=await Ce(f);if(e)return;if(a.phase===`polling`){v(a.qrcodeUrl),a.qrStatus===`scaned`?S(n.weixinQrLoginScanned):S(null);return}if(a.phase===`done`){i!==void 0&&(window.clearInterval(i),i=void 0),m(null),a.ok?(v(null),t(!1),await r()):(b(a.message),v(null));return}a.phase===`unknown`&&S(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),b(t instanceof Error?t.message:`Request failed`),m(null),v(null))}};return i=window.setInterval(()=>void a(),2e3),a(),()=>{e=!0,i!==void 0&&window.clearInterval(i)}},[f,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,X.useEffect)(()=>{if(!_){w(null),E(!1);return}let e=!1;return E(!1),Z.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 A=!!(_&&f),j=e&&!y&&!A;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})}),(0,F.jsx)(a,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,F.jsx)(u,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,F.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,F.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,F.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(A||j)?(0,F.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,F.jsx)(`p`,{className:i(`min-h-[1.25rem] text-center text-sm`,x&&!j?`text-accent`:`text-fg-muted`),children:j?n.weixinQrLoginBusy:x??`\xA0`}),(0,F.jsxs)(`div`,{className:i(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,j&&`bg-surface-muted/40 dark:bg-surface-base`),children:[j?(0,F.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&_&&!y&&C&&!T?(0,F.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&_&&!y&&!C&&!T&&!j?(0,F.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,A&&_&&!y&&T?(0,F.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,F.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,F.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,F.jsx)(d,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,F.jsx)(`div`,{className:`mt-6`,children:(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:s,onClick:()=>void k(),children:s?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),o?(0,F.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:o}):null]})]})})}function Fe({wx:e,updateWeixin:t,ch:n,dmOpts:r,streamOpts:a,wxAccountsDraft:o,setWxAccountsDraft:s,wxAccountsError:c,onWxAccountsBlur:l,channelAgentRoutesWx:u,defaultAgentId:d,agentItems:f,onAgentRouteChange:p,routingDisabled:m}){let h=B;return(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.weixinAllowFrom}),(0,F.jsx)(`textarea`,{className:i(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,F.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,F.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,F.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:a}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.historyLimit}),(0,F.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.textChunkLimit}),(0,F.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,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.weixinRouteTag}),(0,F.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,F.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,F.jsx)(q,{children:n.weixinDebugDesc}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.weixinAccountsJson}),(0,F.jsx)(`textarea`,{className:i(h(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:o,onChange:e=>s(e.target.value),onBlur:l,placeholder:`{ "personal": { "name": "...", "cdnBaseUrl": "...", "enabled": true } }`}),c?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:c}):(0,F.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,F.jsx)(Y,{accountIds:fe(e),routes:u,defaultAgentId:d,agentItems:f,disabled:m,onChange:p,ch:n})]})}function Ie({ch:e,wx:t,updateWeixin:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,form:l,chatAgents:u,onAgentRouteChange:d,saving:f,dirty:p,save:m,discard:h}){return(0,F.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,F.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,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(k,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,F.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,F.jsx)(Fe,{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,F.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:h,children:e.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:async()=>{await m()},children:f?e.saving:e.save})]})]})]})}function Le(){let{language:e,m:t,ch:n,hasToken:r,loading:i,fetchError:a,mutate:o,form:s,baseline:c,dirty:l,saving:u,error:f,saveOk:p,weixinModalOpen:m,setWeixinModalOpen:h,telegramModalOpen:g,setTelegramModalOpen:_,feishuModalOpen:v,setFeishuModalOpen:y,removeTarget:x,setRemoveTarget:S,weixinSuccessBanner:C,setWeixinSuccessBanner:E,dingtalkModalOpen:O,setDingtalkModalOpen:k,feishuSetupSuccessBanner:A,dingtalkSetupSuccessBanner:j,tgAdvanced:M,setTgAdvanced:ee,showToken:N,setShowToken:te,showFeishuSecret:ne,setShowFeishuSecret:ie,showFeishuWebhookSecrets:ae,setShowFeishuWebhookSecrets:oe,showDingtalkSecret:se,setShowDingtalkSecret:P,copied:ce,feishuCopied:le,dingtalkCopied:L,feishuWebhookCopied:R,tgAccountsDraft:de,setTgAccountsDraft:fe,tgAccountsError:pe,wxAccountsDraft:me,setWxAccountsDraft:he,wxAccountsError:z,feishuAccountsDraft:B,setFeishuAccountsDraft:V,feishuAccountsError:H,dingtalkAccountsDraft:U,setDingtalkAccountsDraft:ge,dingtalkAccountsError:K,chatAgents:q,updateChannelAgentRoute:J,updateTelegram:Y,updateWeixin:X,updateFeishu:Z,updateDingtalk:be,save:xe,discard:Se,toggleChannelEnabled:Q,removeChannel:Ce,copyToken:we,handleFeishuQrSetupSuccess:Te,handleDingtalkQrSetupSuccess:Ee,copyFeishuSecret:$,copyDingtalkSecret:De,copyFeishuWebhookConfig:je,onTgAccountsBlur:Fe,onWxAccountsBlur:Le,onFeishuAccountsBlur:Re,onDingtalkAccountsBlur:ze,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue}=Ne();if(!r)return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,F.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,F.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,F.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,F.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,F.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!s)return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,F.jsx)(D,{type:`button`,variant:`secondary`,onClick:()=>void o(),children:n.retry})]});let We=s.weixin,Ge=s.telegram,Ke=s.feishu,qe=s.dingtalk,Je=W(We),Ye=_e(Ge),Xe=ve(Ke),Ze=G(qe),Qe=(0,F.jsx)(ke,{ch:n,form:s,baseline:c,showFeishuSecret:ne,setShowFeishuSecret:ie,showFeishuWebhookSecrets:ae,setShowFeishuWebhookSecrets:oe,feishuCopied:le,feishuWebhookCopied:R,copyFeishuSecret:$,copyFeishuWebhookConfig:je,updateFeishu:Z,updateChannelAgentRoute:J,feishuAccountsDraft:B,setFeishuAccountsDraft:V,feishuAccountsError:H,onFeishuAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,chatAgents:q,saving:u,dirty:l,save:xe,discard:Se}),$e=(0,F.jsx)(ye,{ch:n,form:s,baseline:c,showDingtalkSecret:se,setShowDingtalkSecret:P,dingtalkCopied:L,copyDingtalkSecret:De,updateDingtalk:be,updateChannelAgentRoute:J,dingtalkAccountsDraft:U,setDingtalkAccountsDraft:ge,dingtalkAccountsError:K,onDingtalkAccountsBlur:ze,dmOpts:Be,groupOpts:Ve,chatAgents:q,saving:u,dirty:l,save:xe,discard:Se}),et=(0,F.jsx)(Ie,{ch:n,wx:We,updateWeixin:X,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:me,setWxAccountsDraft:he,wxAccountsError:z,onWxAccountsBlur:Le,form:s,chatAgents:q,onAgentRouteChange:(e,t)=>J(`weixin`,e,t),saving:u,dirty:l,save:xe,discard:Se});return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,F.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,F.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,F.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,F.jsxs)(`a`,{href:T(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,F.jsx)(d,{className:`size-3.5`})]})]}),l?(0,F.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,F.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,F.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,C?(0,F.jsx)(`p`,{className:`text-xs text-accent`,children:C}):null,A?(0,F.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:A}):null,j?(0,F.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:j}):null,(0,F.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,F.jsx)(I,{icon:(0,F.jsx)(b,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.weixinTitle,subtitle:n.weixinSubtitle,configured:Je,enabled:We.enabled,toggleDisabled:u,onToggle:e=>void Q(`weixin`,e),onConfigure:()=>h(!0),onEdit:()=>h(!0),onRemove:()=>S(`weixin`),ch:n}),(0,F.jsx)(I,{icon:(0,F.jsx)(w,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.telegramTitle,subtitle:n.telegramSubtitle,configured:Ye,enabled:Ge.enabled,toggleDisabled:u,onToggle:e=>void Q(`telegram`,e),onConfigure:()=>_(!0),onEdit:()=>_(!0),onRemove:()=>S(`telegram`),ch:n}),(0,F.jsx)(I,{icon:(0,F.jsx)(b,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.feishuTitle,subtitle:n.feishuSubtitle,configured:Xe,enabled:Ke.enabled,toggleDisabled:u,onToggle:e=>void Q(`feishu`,e),onConfigure:()=>y(!0),onEdit:()=>y(!0),onRemove:()=>S(`feishu`),ch:n}),(0,F.jsx)(I,{icon:(0,F.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.dingtalkTitle,subtitle:n.dingtalkSubtitle,configured:Ze,enabled:qe.enabled,toggleDisabled:u,onToggle:e=>void Q(`dingtalk`,e),onConfigure:()=>k(!0),onEdit:()=>k(!0),onRemove:()=>S(`dingtalk`),ch:n})]}),(0,F.jsx)(Pe,{open:m,onOpenChange:h,ch:n,onLoginSuccess:async()=>{await o(),E(n.weixinQrLoginSuccess),window.setTimeout(()=>E(null),4e3)},moreSettings:et}),(0,F.jsx)(Me,{open:g,onOpenChange:_,ch:n,form:s,baseline:c,tgAdvanced:M,setTgAdvanced:ee,showToken:N,setShowToken:te,copied:ce,copyToken:we,updateTelegram:Y,updateChannelAgentRoute:J,tgAccountsDraft:de,setTgAccountsDraft:fe,tgAccountsError:pe,onTgAccountsBlur:Fe,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:q,saving:u,dirty:l,save:xe,discard:Se}),(0,F.jsx)(Ae,{open:v,onOpenChange:y,ch:n,onSetupSuccess:Te,moreSettings:Qe}),(0,F.jsx)(Oe,{open:O,onOpenChange:k,ch:n,onSetupSuccess:Ee,moreSettings:$e}),(0,F.jsx)(ue,{open:x!==null,onOpenChange:e=>{e||S(null)},ch:n,removeTarget:x,onCancel:()=>S(null),saving:u,onConfirmRemove:()=>void Ce()})]})}export{Le as ChannelsSettingsPanel};
|
|
2
|
-
//# sourceMappingURL=channels-settings-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r}from"./vendor-swr-B5fPo7KK.js";import{t as i}from"./cn-BMCV0OMB.js";import{At as a,Bn as o,Dn as s,Dt as c,En as l,Et as u,Gr as d,Kr as f,Nn as p,On as m,Ot as h,Tt as g,Ur as _,Wr as v,Xr as y,_r as b,_t as x,bn as S,cn as C,er as w,gn as T,hn as E,kn as D,kt as O,li as k,pn as A,pr as j,ui as M,vt as ee,wn as N,wt as te,x as ne,yr as re,yt as ie}from"./index-C9ACajYe.js";import{a as ae,i as oe,n as se,r as P,t as ce}from"./dist-RpqJxYGW.js";import{t as le}from"./browser-DNXWYwzc.js";var F=n();function I({icon:e,title:t,subtitle:n,configured:r,enabled:a,onToggle:s,toggleDisabled:c,onConfigure:l,onEdit:u,onRemove:d,ch:p}){return(0,F.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,F.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-4`,children:[(0,F.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-surface-hover`,"aria-hidden":!0,children:e}),(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),r?(0,F.jsx)(`span`,{className:`inline-flex items-center rounded-full bg-success-soft px-2 py-0.5 text-xs font-medium text-success`,children:p.hubConnectedBadge}):null]}),(0,F.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n})]})]}),r?(0,F.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2 sm:gap-3`,children:[(0,F.jsxs)(oe,{children:[(0,F.jsx)(ae,{asChild:!0,children:(0,F.jsx)(D,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":p.menuMoreAria,children:(0,F.jsx)(f,{className:`size-5 text-fg-muted`,strokeWidth:1.75})})}),(0,F.jsx)(P,{children:(0,F.jsxs)(ce,{className:`z-[70] min-w-[11rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[(0,F.jsx)(se,{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:()=>u(),children:(0,F.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(j,{className:`size-4 shrink-0 text-fg-muted`,strokeWidth:1.75}),p.menuEditConfig]})}),(0,F.jsx)(se,{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:()=>d(),children:(0,F.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(o,{className:`size-4 shrink-0`,strokeWidth:1.75}),p.menuRemoveConfig]})})]})})]}),(0,F.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} — ${p.enableChannelAria}`,disabled:c,className:i(`inline-flex h-6 w-10 shrink-0 items-center rounded-full border border-edge p-0.5 transition-colors`,a?`justify-end bg-accent`:`justify-start bg-surface-hover`,c&&`cursor-not-allowed opacity-50`),onClick:()=>void s(!a),children:(0,F.jsx)(`span`,{className:`size-4 rounded-full bg-surface-panel shadow-surface ring-1 ring-edge/40 dark:ring-edge/55`})})]}):(0,F.jsx)(`div`,{className:`flex shrink-0 justify-end sm:justify-end`,children:(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:l,children:p.hubConfigureButton})})]})}function ue({open:e,onOpenChange:t,ch:n,removeTarget:r,onCancel:o,saving:s,onConfirmRemove:l}){return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[70] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[70] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,F.jsx)(a,{className:`text-base font-semibold text-fg`,children:n.removeChannelTitle}),(0,F.jsx)(u,{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,F.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,onClick:o,children:n.modalCancel}),(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:s,onClick:l,children:s?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 de(e){return Object.keys(e.accounts??{}).sort()}function fe(e){return Object.keys(e.accounts??{}).sort()}function pe(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 me(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 he(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 z(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 B(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,s,`dark:border-edge`)}function V(){return i(l,N)}function H(e){return e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean).map(e=>/^-?\d+$/.test(e)?Number(e):e)}function U(e){return e.map(String).join(`, `)}function ge(e){let t=e.accounts?.default?.botToken;return typeof t==`string`?t:``}function _e(e){return Object.values(e.accounts??{}).some(e=>typeof e.botToken==`string`&&e.botToken.trim().length>0)}function W(e){return Object.keys(e.accounts??{}).length>0||e.allowFrom.length>0}function ve(e){return!!(e.appId?.trim()&&e.appSecret?.trim())||Object.keys(e.accounts??{}).length>0}function G(e){return!!(e.clientId?.trim()&&e.clientSecret?.trim())||Object.keys(e.accounts??{}).length>0}function K({children:e}){return(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function q({children:e}){return(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:e})}function J({label:e,value:t,onChange:n,options:r}){return(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e}),(0,F.jsx)(`select`,{className:V(),value:t,onChange:e=>n(e.target.value),children:r.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Y({accountIds:e,routes:t,defaultAgentId:n,agentItems:r,disabled:a,onChange:o,ch:s}){let c=m(S(e=>e.language)).agentsSettings;if(e.length===0)return null;let l=r.length>0?r:[{id:n}];return(0,F.jsxs)(`div`,{className:`space-y-3 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(K,{children:s.agentRoutingTitle}),(0,F.jsx)(q,{children:s.agentRoutingHint})]}),(0,F.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,F.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,F.jsxs)(`div`,{className:`min-w-0`,children:[(0,F.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:s.agentRoutingAccountLabel}),(0,F.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,title:e,children:e})]}),(0,F.jsxs)(`div`,{className:`min-w-0`,children:[(0,F.jsx)(`label`,{className:`sr-only`,htmlFor:`agent-route-${e}`,children:s.agentRoutingAgentLabel}),(0,F.jsx)(`select`,{id:`agent-route-${e}`,className:i(B(),N),disabled:a,value:(t[e]??n).toLowerCase(),onChange:t=>o(e,t.target.value),children:l.map(e=>(0,F.jsx)(`option`,{value:e.id,children:`${ne(e,c)} (${e.id})`},e.id))})]})]},e))})]})}function ye({ch:e,form:t,baseline:n,showDingtalkSecret:r,setShowDingtalkSecret:a,dingtalkCopied:o,copyDingtalkSecret:s,updateDingtalk:c,updateChannelAgentRoute:l,dingtalkAccountsDraft:u,setDingtalkAccountsDraft:d,dingtalkAccountsError:f,onDingtalkAccountsBlur:p,dmOpts:m,groupOpts:h,chatAgents:g,saving:b,dirty:x,save:S,discard:C}){let w=B,T=t.dingtalk,E=n?.dingtalk?.clientSecret??``,O=!r&&!!String(E).trim()&&T.clientSecret===E;return(0,F.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,F.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,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(k,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.dingtalkAdvancedHint}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:T.enabled,onChange:e=>c({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:e.enableDingtalkAria})]}),(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.dingtalkClientId,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.clientId,onChange:e=>c({clientId:e.target.value}),placeholder:`dingxxx`}),(0,F.jsx)(q,{children:e.dingtalkClientIdDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.dingtalkClientSecret,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:O,value:O?`*`.repeat(Math.max(1,T.clientSecret.length)):T.clientSecret,onChange:e=>{O||c({clientSecret:e.target.value})},placeholder:`••••••••`}),T.clientSecret?(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void s(),children:[o?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),o?e.copied:e.copy]}):null,(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e=>!e),children:[r?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,F.jsx)(q,{children:e.dingtalkClientSecretDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.dingtalkEndpoint}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),value:T.endpoint,onChange:e=>c({endpoint:e.target.value}),placeholder:`https://api.dingtalk.com`}),(0,F.jsx)(q,{children:e.dingtalkEndpointDesc})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.debug,onChange:e=>c({debug:e.target.checked})}),e.dingtalkDebug]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.dmPolicy}),(0,F.jsx)(`select`,{className:w(),value:T.dmPolicy,onChange:e=>c({dmPolicy:e.target.value}),children:m.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.groupPolicy}),(0,F.jsx)(`select`,{className:w(),value:T.groupPolicy,onChange:e=>c({groupPolicy:e.target.value}),children:h.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:T.requireMention,onChange:e=>c({requireMention:e.target.checked})}),e.requireMention]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromDm}),(0,F.jsx)(`textarea`,{className:i(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`userId1, userId2`,value:U(T.allowFrom),onChange:e=>c({allowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromDmDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromGroups}),(0,F.jsx)(`textarea`,{className:i(w(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`openConversationId1`,value:U(T.groupAllowFrom),onChange:e=>c({groupAllowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.historyLimit}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.historyLimit),onChange:e=>c({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.textChunkLimit}),(0,F.jsx)(`input`,{className:i(w(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(T.textChunkLimit),onChange:e=>c({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,F.jsx)(Y,{accountIds:me(T),routes:t.channelAgentRoutes.dingtalk,defaultAgentId:t.defaultAgentId,agentItems:g?.items??[],disabled:b,onChange:(e,t)=>l(`dingtalk`,e,t),ch:e}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.multiAccountJson}),(0,F.jsx)(`textarea`,{className:i(w(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:u,onChange:e=>d(e.target.value),onBlur:p,placeholder:`{ "default": { "clientId": "...", "clientSecret": "...", "enabled": true } }`}),f?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:f}):(0,F.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!x||b,onClick:C,children:e.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!x||b,onClick:async()=>{await S()},children:b?e.saving:e.save})]})]})]})}var X=e(t(),1),Z=e(le(),1);function be(e){return{accountId:e,name:``,enabled:!0,botToken:``,allowFrom:[],dmPolicy:`pairing`,groupPolicy:`open`,replyToMode:`off`,apiRoot:``,proxy:``,historyLimit:50,textChunkLimit:4e3,streamMode:`partial`}}function xe(){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:be(`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 Se(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??be(`default`),accountId:`default`,botToken:l}}),c.default||(c={...c,default:be(`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}:{}}},_=he(p,de(g.telegram),fe(g.weixin),pe(g.feishu),me(g.dingtalk),h);return{...g,bindingsFull:p.map(e=>({...e})),channelAgentRoutes:_,defaultAgentId:h}}async function Q(e){return(await A(C(`/api/channels/weixin/login/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Ce(e){return(await A(C(`/api/channels/weixin/login/${encodeURIComponent(e)}`))).payload.status}async function we(e){let t=e.telegram,n=e.weixin,r=e.feishu,i=e.dingtalk,a=z(e.bindingsFull,e.channelAgentRoutes,de(t),fe(n),pe(r),me(i),e.defaultAgentId),o=(()=>{let e=n.routeTag.trim();return e?/^\d+$/.test(e)?Number(e):e:null})(),s=(await A(C(`/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 ee(),s?Se(s):{...e,bindingsFull:a}}async function Te(e){return(await A(C(`/api/channels/feishu/setup/start`),{method:`POST`,body:JSON.stringify(e??{})})).payload}async function Ee(e){return(await A(C(`/api/channels/feishu/setup/${encodeURIComponent(e)}`))).payload.status}async function $(){return(await A(C(`/api/channels/dingtalk/setup/start`),{method:`POST`,body:JSON.stringify({})})).payload}async function De(e){return(await A(C(`/api/channels/dingtalk/setup/${encodeURIComponent(e)}`))).payload.status}function Oe({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:o}){let[s,l]=(0,X.useState)(!1),[f,m]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),T=(0,X.useCallback)(async()=>{b(null),m(null),v(null),l(!0);try{let e=await $();v(e.qrUrl),m(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{l(!1)}},[]);(0,X.useEffect)(()=>{if(!e){m(null),v(null),b(null),S(null),w(!1),l(!1);return}T()},[e,T]),(0,X.useEffect)(()=>{if(!f)return;let e=!1,n,i=async()=>{try{let i=await De(f);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),m(null),i.ok?(v(null),t(!1),r({clientId:i.clientId})):(b(i.message),v(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),b(i.message),m(null),v(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),b(t instanceof Error?t.message:`Request failed`),m(null),v(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[f,t,r]),(0,X.useEffect)(()=>{if(!_){S(null),w(!1);return}let e=!1;return w(!1),Z.toDataURL(_,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||S(t)}).catch(()=>{e||(w(!0),S(null))}),()=>{e=!0}},[_]);let E=!!(_&&f),k=e&&!y&&!E;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})}),(0,F.jsx)(a,{className:`sr-only`,children:n.dingtalkQrModalTitle}),(0,F.jsx)(u,{className:`sr-only`,children:n.dingtalkQrModalSubtitle}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.dingtalkQrModalTitle}),(0,F.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.dingtalkQrModalSubtitle})]}),(0,F.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,F.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(E||k)?(0,F.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:k?n.dingtalkQrStarting:n.dingtalkQrScanHint}),(0,F.jsxs)(`div`,{className:i(`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`,k&&`bg-surface-muted/40 dark:bg-surface-base`),children:[k?(0,F.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,E&&_&&!y&&x&&!C?(0,F.jsx)(`img`,{src:x,alt:``,className:`relative z-[1] size-full object-contain`}):null,E&&_&&!y&&!x&&!C&&!k?(0,F.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.dingtalkQrEncoding}):null,E&&_&&!y&&C?(0,F.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,F.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.dingtalkQrImageError}),(0,F.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,F.jsx)(d,{className:`size-3 shrink-0`}),n.dingtalkQrOpenLink]})]}):null]})]}):null]}),(0,F.jsx)(`div`,{className:`mt-6`,children:(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:s,onClick:()=>void T(),children:s?n.dingtalkQrStarting:n.dingtalkQrRegenerate})}),o?(0,F.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:o}):null]})]})})}function ke({ch:e,form:t,baseline:n,showFeishuSecret:r,setShowFeishuSecret:a,showFeishuWebhookSecrets:o,setShowFeishuWebhookSecrets:s,feishuCopied:c,feishuWebhookCopied:l,copyFeishuSecret:u,copyFeishuWebhookConfig:d,updateFeishu:f,updateChannelAgentRoute:p,feishuAccountsDraft:m,setFeishuAccountsDraft:h,feishuAccountsError:g,onFeishuAccountsBlur:b,dmOpts:x,groupOpts:S,chatAgents:C,saving:w,dirty:T,save:E,discard:O}){let A=B,j=t.feishu,ee=n?.feishu?.appSecret??``,N=!r&&!!String(ee).trim()&&j.appSecret===ee;return(0,F.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,F.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,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(k,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.feishuAdvancedHint}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:j.enabled,onChange:e=>f({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:e.enableFeishuAria})]}),(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.feishuAppId,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.appId,onChange:e=>f({appId:e.target.value}),placeholder:`cli_xxx`}),(0,F.jsx)(q,{children:e.feishuAppIdDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[e.feishuAppSecret,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:r?`text`:`password`,autoComplete:`off`,readOnly:N,value:N?`*`.repeat(Math.max(1,j.appSecret.length)):j.appSecret,onChange:e=>{N||f({appSecret:e.target.value})},placeholder:`••••••••`}),j.appSecret?(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void u(),children:[c?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),c?e.copied:e.copy]}):null,(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e=>!e),children:[r?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),r?e.hide:e.show]})]}),(0,F.jsx)(q,{children:e.feishuAppSecretDesc})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.feishuDomain}),(0,F.jsxs)(`select`,{className:A(),value:String(j.domain||`feishu`),onChange:e=>f({domain:e.target.value}),children:[(0,F.jsx)(`option`,{value:`feishu`,children:`feishu`}),(0,F.jsx)(`option`,{value:`lark`,children:`lark`})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.connectionMode}),(0,F.jsxs)(`select`,{className:A(),value:j.connectionMode,onChange:e=>f({connectionMode:e.target.value}),children:[(0,F.jsx)(`option`,{value:`websocket`,children:`websocket`}),(0,F.jsx)(`option`,{value:`webhook`,children:`webhook`})]}),(0,F.jsx)(q,{children:e.connectionModeDesc})]})]}),j.connectionMode===`webhook`?(0,F.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.webhookTitle}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e=>!e),children:[o?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),o?e.hide:e.show]}),(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void d(),children:[l?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),l?e.copied:e.copy]})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.verificationToken}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:o?`text`:`password`,autoComplete:`off`,value:j.verificationToken??``,onChange:e=>f({verificationToken:e.target.value})}),(0,F.jsx)(q,{children:e.verificationTokenDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.encryptKey}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:o?`text`:`password`,autoComplete:`off`,value:j.encryptKey??``,onChange:e=>f({encryptKey:e.target.value})}),(0,F.jsx)(q,{children:e.encryptKeyDesc})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,F.jsx)(K,{children:e.webhookHost}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookHost??``,onChange:e=>f({webhookHost:e.target.value}),placeholder:`127.0.0.1`})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.webhookPort}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.webhookPort??``),onChange:e=>f({webhookPort:Number(e.target.value||`0`)||0}),placeholder:`3000`})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.webhookPath}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),value:j.webhookPath??``,onChange:e=>f({webhookPath:e.target.value}),placeholder:`/feishu/events`}),(0,F.jsx)(q,{children:e.webhookPathDesc})]})]}):null,(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.renderMode}),(0,F.jsxs)(`select`,{className:A(),value:j.renderMode,onChange:e=>f({renderMode:e.target.value}),children:[(0,F.jsx)(`option`,{value:`auto`,children:`auto`}),(0,F.jsx)(`option`,{value:`raw`,children:`raw`}),(0,F.jsx)(`option`,{value:`card`,children:`card`})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.reactionNotifications}),(0,F.jsxs)(`select`,{className:A(),value:j.reactionNotifications,onChange:e=>f({reactionNotifications:e.target.value}),children:[(0,F.jsx)(`option`,{value:`off`,children:`off`}),(0,F.jsx)(`option`,{value:`own`,children:`own`}),(0,F.jsx)(`option`,{value:`all`,children:`all`})]})]})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.streaming,onChange:e=>f({streaming:e.target.checked})}),e.enableStreaming]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.dmPolicy}),(0,F.jsx)(`select`,{className:A(),value:j.dmPolicy,onChange:e=>f({dmPolicy:e.target.value}),children:x.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.groupPolicy}),(0,F.jsx)(`select`,{className:A(),value:j.groupPolicy,onChange:e=>f({groupPolicy:e.target.value}),children:S.map(e=>(0,F.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.requireMention,onChange:e=>f({requireMention:e.target.checked})}),e.requireMention]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromDm}),(0,F.jsx)(`textarea`,{className:i(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`ou_xxx, on_xxx`,value:U(j.allowFrom),onChange:e=>f({allowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromDmDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.allowFromGroups}),(0,F.jsx)(`textarea`,{className:i(A(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`oc_xxx, oc_yyy`,value:U(j.groupAllowFrom),onChange:e=>f({groupAllowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:e.allowFromGroupsDesc})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.historyLimit}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.historyLimit),onChange:e=>f({historyLimit:Number(e.target.value||`0`)||0})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.textChunkLimit}),(0,F.jsx)(`input`,{className:i(A(),`min-w-0 flex-1 font-mono text-xs`),type:`number`,inputMode:`numeric`,value:String(j.textChunkLimit),onChange:e=>f({textChunkLimit:Number(e.target.value||`0`)||0})})]})]}),(0,F.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuToolsTitle}),(0,F.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,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.tools?.[e],onChange:t=>f({tools:{...j.tools,[e]:t.target.checked}})}),t]},e))}),(0,F.jsx)(`div`,{className:`mt-2`,children:(0,F.jsx)(q,{children:e.feishuToolsDesc})})]}),(0,F.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface px-4 py-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.feishuActionsTitle}),(0,F.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:!!j.actions?.reactions,onChange:e=>f({actions:{...j.actions,reactions:e.target.checked}})}),e.feishuActionReactions]})]}),(0,F.jsx)(Y,{accountIds:pe(j),routes:t.channelAgentRoutes.feishu,defaultAgentId:t.defaultAgentId,agentItems:C?.items??[],disabled:w,onChange:(e,t)=>p(`feishu`,e,t),ch:e}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:e.multiAccountJson}),(0,F.jsx)(`textarea`,{className:i(A(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:m,onChange:e=>h(e.target.value),onBlur:b,placeholder:`{ "default": { "appId": "...", "appSecret": "...", "enabled": true } }`}),g?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:g}):(0,F.jsx)(q,{children:e.multiAccountJsonDesc})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:O,children:e.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!T||w,onClick:async()=>{await E()},children:w?e.saving:e.save})]})]})]})}function Ae({open:e,onOpenChange:t,ch:n,onSetupSuccess:r,moreSettings:o}){let[s,l]=(0,X.useState)(!1),[f,m]=(0,X.useState)(`feishu`),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),k=(0,X.useCallback)(async e=>{m(e),S(null),v(null),b(null),l(!0);try{let t=await Te({domain:e});b(t.qrUrl),v(t.sessionKey)}catch(e){S(e instanceof Error?e.message:`Start failed`)}finally{l(!1)}},[]);(0,X.useEffect)(()=>{if(!e){v(null),b(null),S(null),w(null),E(!1),m(`feishu`),l(!1);return}k(`feishu`)},[e,k]),(0,X.useEffect)(()=>{if(!_)return;let e=!1,n,i=async()=>{try{let i=await Ee(_);if(e||i.phase===`polling`)return;if(i.phase===`done`){n!==void 0&&(window.clearInterval(n),n=void 0),v(null),i.ok?(b(null),t(!1),r({appId:i.appId,domain:i.domain,openId:i.openId})):(S(i.message),b(null));return}i.phase===`unknown`&&(n!==void 0&&window.clearInterval(n),S(i.message),v(null),b(null))}catch(t){e||(n!==void 0&&window.clearInterval(n),S(t instanceof Error?t.message:`Request failed`),v(null),b(null))}};return n=window.setInterval(()=>void i(),3e3),i(),()=>{e=!0,n!==void 0&&window.clearInterval(n)}},[_,t,r]),(0,X.useEffect)(()=>{if(!y){w(null),E(!1);return}let e=!1;return E(!1),Z.toDataURL(y,{width:208,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||w(t)}).catch(()=>{e||(E(!0),w(null))}),()=>{e=!0}},[y]);let A=!!(y&&_),j=e,M=e&&!x&&!A;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})}),(0,F.jsx)(a,{className:`sr-only`,children:n.feishuQrModalTitle}),(0,F.jsx)(u,{className:`sr-only`,children:n.feishuQrModalSubtitle}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.feishuQrModalTitle}),(0,F.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.feishuQrModalSubtitle})]}),(0,F.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[x?(0,F.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:x}):null,!x&&(A||M)?(0,F.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:M?n.feishuQrStarting:n.feishuQrScanHint}),(0,F.jsxs)(`div`,{className:i(`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`,M&&`bg-surface-muted/40 dark:bg-surface-base`),children:[M?(0,F.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&y&&!x&&C&&!T?(0,F.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&y&&!x&&!C&&!T&&!M?(0,F.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.feishuQrEncoding}):null,A&&y&&!x&&T?(0,F.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,F.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.feishuQrImageError}),(0,F.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,F.jsx)(d,{className:`size-3 shrink-0`}),n.feishuQrOpenLink]})]}):null]})]}):null]}),j?(0,F.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,F.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,F.jsx)(`button`,{type:`button`,disabled:s,className:i(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,f===`feishu`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void k(`feishu`),children:n.feishuRegionChina}),(0,F.jsx)(`button`,{type:`button`,disabled:s,className:i(`min-w-0 flex-1 rounded-full px-3 py-2 text-center text-sm font-medium transition-colors`,f===`lark`?`bg-surface-panel text-fg shadow-sm dark:bg-surface-panel`:`text-fg-muted hover:text-fg`),onClick:()=>void k(`lark`),children:n.feishuRegionInternational})]})}):null,(0,F.jsx)(`div`,{className:`mt-6`,children:(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:s,onClick:()=>void k(f),children:s?n.feishuQrStarting:n.feishuQrRegenerate})}),o?(0,F.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:o}):null]})]})})}function je({tg:e,updateTelegram:t,ch:n,dmOpts:r,groupOpts:a,replyOpts:o,streamOpts:s,tgAccountsDraft:c,setTgAccountsDraft:l,tgAccountsError:u,onTgAccountsBlur:d}){let f=B;return(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.apiRoot}),(0,F.jsx)(`input`,{className:f(),value:e.apiRoot,onChange:e=>t({apiRoot:e.target.value}),placeholder:`https://api.telegram.org`})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.proxy}),(0,F.jsx)(`input`,{className:f(),value:e.proxy,onChange:e=>t({proxy:e.target.value}),placeholder:`http://proxy.example.com:8080`})]}),(0,F.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,F.jsx)(J,{label:n.groupPolicy,value:e.groupPolicy,onChange:e=>t({groupPolicy:e}),options:a}),(0,F.jsx)(J,{label:n.replyToMode,value:e.replyToMode,onChange:e=>t({replyToMode:e}),options:o}),(0,F.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:s}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.allowFromGroups}),(0,F.jsx)(`textarea`,{className:i(f(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`-1001234567890`,value:U(e.groupAllowFrom),onChange:e=>t({groupAllowFrom:H(e.target.value)})})]}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.historyLimit}),(0,F.jsx)(`input`,{type:`number`,min:10,max:200,className:f(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.textChunkLimit}),(0,F.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,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.telegramDebug]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.multiAccountJson}),(0,F.jsx)(`textarea`,{className:i(f(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:c,onChange:e=>l(e.target.value),onBlur:d,placeholder:`{ "personal": { "accountId": "personal", "botToken": "...", ... } }`}),u?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:u}):(0,F.jsx)(q,{children:n.multiAccountJsonDesc})]})]})}function Me({open:e,onOpenChange:t,ch:n,form:r,baseline:o,tgAdvanced:s,setTgAdvanced:l,showToken:d,setShowToken:f,copied:m,copyToken:b,updateTelegram:x,updateChannelAgentRoute:S,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:E,dmOpts:A,groupOpts:j,replyOpts:ee,streamOpts:N,chatAgents:ne,saving:re,dirty:ie,save:ae,discard:oe}){let se=B,P=r.telegram,ce=o?ge(o.telegram):``,le=ge(P),I=!d&&!!String(ce).trim()&&le===ce;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,48rem)] w-[min(100%-2rem,36rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(a,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.telegramTitle}),(0,F.jsx)(u,{className:`mt-1 text-sm text-fg-muted`,children:n.telegramSubtitle})]}),(0,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})})]}),(0,F.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:P.enabled,onChange:e=>x({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:n.enableTelegramAria})]}),(0,F.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsxs)(K,{children:[n.telegramToken,(0,F.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsx)(`input`,{className:i(se(),`min-w-0 flex-1 font-mono text-xs`),type:d?`text`:`password`,autoComplete:`off`,readOnly:I,value:I?`*`.repeat(Math.max(1,ce.length)):le,onChange:e=>{if(I)return;let t=P.accounts?.default??be(`default`);x({accounts:{...P.accounts,default:{...t,accountId:`default`,botToken:e.target.value}}})},placeholder:`123456789:ABCdefGHIjklMNOpqrsTUVwxyz`}),le?(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>void b(),children:[m?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(y,{className:`size-3.5`}),m?n.copied:n.copy]}):null,(0,F.jsxs)(D,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>f(e=>!e),children:[d?(0,F.jsx)(v,{className:`size-3.5`}):(0,F.jsx)(_,{className:`size-3.5`}),d?n.hide:n.show]})]}),(0,F.jsx)(q,{children:n.telegramTokenDesc})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.allowFromDm}),(0,F.jsx)(`textarea`,{className:i(se(),`min-h-[2.75rem] resize-y font-mono text-xs`),rows:2,placeholder:`123456789, 987654321`,value:U(P.allowFrom),onChange:e=>x({allowFrom:H(e.target.value)})}),(0,F.jsx)(q,{children:n.allowFromDmDesc})]}),(0,F.jsx)(Y,{accountIds:de(P),routes:r.channelAgentRoutes.telegram,defaultAgentId:r.defaultAgentId,agentItems:ne?.items??[],disabled:re,onChange:(e,t)=>S(`telegram`,e,t),ch:n}),(0,F.jsxs)(D,{type:`button`,variant:`ghost`,className:`-ml-2 h-auto justify-start px-2 py-1 text-sm text-fg-muted hover:text-fg`,onClick:()=>l(e=>!e),children:[(0,F.jsx)(k,{className:i(`mr-1 size-4 transition-transform`,s&&`rotate-180`)}),s?n.advancedHide:n.advancedShow]}),s?(0,F.jsx)(je,{tg:P,updateTelegram:x,ch:n,dmOpts:A,groupOpts:j,replyOpts:ee,streamOpts:N,tgAccountsDraft:C,setTgAccountsDraft:w,tgAccountsError:T,onTgAccountsBlur:E}):null]}),(0,F.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,F.jsx)(D,{type:`button`,variant:`secondary`,onClick:()=>t(!1),children:n.modalCancel}),(0,F.jsx)(D,{type:`button`,variant:`secondary`,disabled:!ie||re,onClick:oe,children:n.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,disabled:!ie||re,onClick:async()=>{await ae()&&t(!1)},children:re?n.saving:n.save})]})]})]})})}function Ne(){let e=S(e=>e.language),t=m(e),n=t.channelsSettings,i=!!E(e=>e.token),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[D,O]=(0,X.useState)(null),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),[ee,N]=(0,X.useState)(null),[te,ne]=(0,X.useState)(!1),[re,ae]=(0,X.useState)(!1),[oe,se]=(0,X.useState)(!1),[P,ce]=(0,X.useState)(!1),[le,F]=(0,X.useState)(!1),[I,ue]=(0,X.useState)(!1),[L,R]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(!1),[pe,me]=(0,X.useState)(!1),[he,z]=(0,X.useState)(``),[B,V]=(0,X.useState)(``),[H,U]=(0,X.useState)(``),[_e,W]=(0,X.useState)(``),[ve,G]=(0,X.useState)(``),[K,q]=(0,X.useState)(``),[J,Y]=(0,X.useState)(``),[ye,Z]=(0,X.useState)(``),{data:be}=r(i?`gateway-chat-agents-ch`:null,x,{revalidateOnFocus:!1}),{data:Q,error:Ce,isLoading:Te,mutate:Ee}=ie(i),$=(0,X.useMemo)(()=>Q?.payload?.config===void 0?null:Se(Q.payload.config),[Q]),De=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!i){o(null),c(null);return}$!==null&&(De||(o($),c(structuredClone($)),z(JSON.stringify($.telegram.accounts??{},null,2)),V(``),U(JSON.stringify($.weixin.accounts??{},null,2)),W(``),G(JSON.stringify($.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify($.dingtalk?.accounts??{},null,2)),Z(``),h(!1)))},[i,$,De]);let Oe=!!(i&&Te&&Q===void 0&&!Ce),ke=Ce instanceof Error?Ce.message:Ce?String(Ce):null,Ae=(0,X.useCallback)((e,t,n)=>{o(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()}}}})},[]),je=(0,X.useCallback)(e=>{o(t=>t?{...t,telegram:{...t.telegram,...e}}:null)},[]),Me=(0,X.useCallback)(e=>{o(t=>t?{...t,weixin:{...t.weixin,...e}}:null)},[]),Ne=(0,X.useCallback)(e=>{o(t=>t?{...t,feishu:{...t.feishu,...e}}:null)},[]),Pe=(0,X.useCallback)(e=>{o(t=>t?{...t,dingtalk:{...t.dingtalk,...e}}:null)},[]),Fe=(0,X.useCallback)(async()=>{if(!a||l)return!1;u(!0),f(null),h(!1);try{let e=await we(a);o(e);let t=structuredClone(e);return c(t),z(JSON.stringify(t.telegram.accounts??{},null,2)),V(``),U(JSON.stringify(t.weixin.accounts??{},null,2)),W(``),G(JSON.stringify(t.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify(t.dingtalk?.accounts??{},null,2)),Z(``),h(!0),window.setTimeout(()=>h(!1),2500),!0}catch(e){return f(e instanceof Error?e.message:n.saveError),!1}finally{u(!1)}},[a,l,n.saveError]),Ie=(0,X.useCallback)(()=>{if(!s)return;let e=structuredClone(s);o(e),z(JSON.stringify(e.telegram.accounts??{},null,2)),V(``),U(JSON.stringify(e.weixin.accounts??{},null,2)),W(``),G(JSON.stringify(e.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify(e.dingtalk?.accounts??{},null,2)),Z(``),f(null),h(!1)},[s]),Le=(0,X.useCallback)(async(e,t)=>{if(!a||l)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}};o(i),u(!0),f(null);try{let e=await we(i);o(e);let t=structuredClone(e);c(t),z(JSON.stringify(t.telegram.accounts??{},null,2)),U(JSON.stringify(t.weixin.accounts??{},null,2)),G(JSON.stringify(t.feishu?.accounts??{},null,2)),Y(JSON.stringify(t.dingtalk?.accounts??{},null,2))}catch(e){f(e instanceof Error?e.message:n.saveError),o(r)}finally{u(!1)}},[a,l,n.saveError]),Re=(0,X.useCallback)(async()=>{if(!a||!D||l)return;let e=xe(),t=D===`weixin`?{...a,weixin:e.weixin}:D===`telegram`?{...a,telegram:e.telegram}:D===`feishu`?{...a,feishu:e.feishu}:{...a,dingtalk:e.dingtalk};u(!0),f(null);try{let e=await we(t);o(e);let n=structuredClone(e);c(n),z(JSON.stringify(n.telegram.accounts??{},null,2)),U(JSON.stringify(n.weixin.accounts??{},null,2)),V(``),W(``),G(JSON.stringify(n.feishu?.accounts??{},null,2)),q(``),Y(JSON.stringify(n.dingtalk?.accounts??{},null,2)),Z(``),O(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){f(e instanceof Error?e.message:n.saveError)}finally{u(!1)}},[a,D,l,n.saveError]),ze=(0,X.useCallback)(async()=>{let e=a?ge(a.telegram):``;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),ue(!0),window.setTimeout(()=>ue(!1),2e3))},[a]),Be=(0,X.useCallback)(e=>{Ne({appId:e.appId,domain:e.domain,enabled:!0}),Ee(),M(n.feishuQrSetupSuccess),window.setTimeout(()=>M(null),4e3)},[Ne,Ee,n.feishuQrSetupSuccess]),Ve=(0,X.useCallback)(e=>{Pe({clientId:e.clientId,enabled:!0}),Ee(),N(n.dingtalkQrSetupSuccess),window.setTimeout(()=>N(null),4e3)},[Pe,Ee,n.dingtalkQrSetupSuccess]),He=(0,X.useCallback)(async()=>{let e=a?.dingtalk?.clientSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),fe(!0),window.setTimeout(()=>fe(!1),2e3))},[a]);return{language:e,m:t,ch:n,hasToken:i,loading:Oe,fetchError:ke,mutate:Ee,form:a,baseline:s,dirty:De,saving:l,error:d,saveOk:p,weixinModalOpen:g,setWeixinModalOpen:_,telegramModalOpen:v,setTelegramModalOpen:y,feishuModalOpen:b,setFeishuModalOpen:C,dingtalkModalOpen:w,setDingtalkModalOpen:T,removeTarget:D,setRemoveTarget:O,weixinSuccessBanner:k,setWeixinSuccessBanner:A,feishuSetupSuccessBanner:j,dingtalkSetupSuccessBanner:ee,tgAdvanced:te,setTgAdvanced:ne,showToken:re,setShowToken:ae,showFeishuSecret:oe,setShowFeishuSecret:se,showFeishuWebhookSecrets:P,setShowFeishuWebhookSecrets:ce,showDingtalkSecret:le,setShowDingtalkSecret:F,copied:I,feishuCopied:L,dingtalkCopied:de,feishuWebhookCopied:pe,tgAccountsDraft:he,setTgAccountsDraft:z,tgAccountsError:B,wxAccountsDraft:H,setWxAccountsDraft:U,wxAccountsError:_e,feishuAccountsDraft:ve,setFeishuAccountsDraft:G,feishuAccountsError:K,dingtalkAccountsDraft:J,setDingtalkAccountsDraft:Y,dingtalkAccountsError:ye,chatAgents:be,updateChannelAgentRoute:Ae,updateTelegram:je,updateWeixin:Me,updateFeishu:Ne,updateDingtalk:Pe,save:Fe,discard:Ie,toggleChannelEnabled:Le,removeChannel:Re,copyToken:ze,handleFeishuQrSetupSuccess:Be,handleDingtalkQrSetupSuccess:Ve,copyFeishuSecret:(0,X.useCallback)(async()=>{let e=a?.feishu?.appSecret;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),R(!0),window.setTimeout(()=>R(!1),2e3))},[a]),copyDingtalkSecret:He,copyFeishuWebhookConfig:(0,X.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,X.useCallback)(()=>{if(!a)return;let e=he.trim();if(!e){je({accounts:{}}),V(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);je({accounts:t}),V(``)}catch(e){V(e instanceof Error?e.message:n.jsonInvalid)}},[a,he,je,n.jsonObjectAccounts,n.jsonInvalid]),onWxAccountsBlur:(0,X.useCallback)(()=>{if(!a)return;let e=H.trim();if(!e){Me({accounts:{}}),W(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Me({accounts:t}),W(``)}catch(e){W(e instanceof Error?e.message:n.jsonInvalid)}},[a,H,Me,n.jsonObjectAccounts,n.jsonInvalid]),onFeishuAccountsBlur:(0,X.useCallback)(()=>{if(!a)return;let e=ve.trim();if(!e){Ne({accounts:{}}),q(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Ne({accounts:t}),q(``)}catch(e){q(e instanceof Error?e.message:n.jsonInvalid)}},[a,ve,Ne,n.jsonObjectAccounts,n.jsonInvalid]),onDingtalkAccountsBlur:(0,X.useCallback)(()=>{if(!a)return;let e=J.trim();if(!e){Pe({accounts:{}}),Z(``);return}try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(n.jsonObjectAccounts);Pe({accounts:t}),Z(``)}catch(e){Z(e instanceof Error?e.message:n.jsonInvalid)}},[a,J,Pe,n.jsonObjectAccounts,n.jsonInvalid]),dmOpts:(0,X.useMemo)(()=>[`pairing`,`allowlist`,`open`,`disabled`].map(e=>({value:e,label:n.policy.dm[e]})),[n.policy.dm]),groupOpts:(0,X.useMemo)(()=>[`open`,`disabled`,`allowlist`].map(e=>({value:e,label:n.policy.group[e]})),[n.policy.group]),replyOpts:(0,X.useMemo)(()=>[`off`,`first`,`all`].map(e=>({value:e,label:n.policy.reply[e]})),[n.policy.reply]),streamOpts:(0,X.useMemo)(()=>[`off`,`partial`,`block`].map(e=>({value:e,label:n.policy.stream[e]})),[n.policy.stream])}}function Pe({open:e,onOpenChange:t,ch:n,onLoginSuccess:r,moreSettings:o}){let[s,l]=(0,X.useState)(!1),[f,m]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),k=(0,X.useCallback)(async()=>{b(null),S(null),m(null),l(!0);try{let e=await Q();v(e.qrcodeUrl),m(e.sessionKey)}catch(e){b(e instanceof Error?e.message:`Start failed`)}finally{l(!1)}},[]);(0,X.useEffect)(()=>{if(!e){m(null),v(null),b(null),w(null),E(!1),S(null);return}k()},[e,k]),(0,X.useEffect)(()=>{if(!f)return;let e=!1,i,a=async()=>{try{let a=await Ce(f);if(e)return;if(a.phase===`polling`){v(a.qrcodeUrl),a.qrStatus===`scaned`?S(n.weixinQrLoginScanned):S(null);return}if(a.phase===`done`){i!==void 0&&(window.clearInterval(i),i=void 0),m(null),a.ok?(v(null),t(!1),await r()):(b(a.message),v(null));return}a.phase===`unknown`&&S(null)}catch(t){e||(i!==void 0&&window.clearInterval(i),b(t instanceof Error?t.message:`Request failed`),m(null),v(null))}};return i=window.setInterval(()=>void a(),2e3),a(),()=>{e=!0,i!==void 0&&window.clearInterval(i)}},[f,n.weixinQrLoginScanned,n.weixinQrLoginSuccess,r,t]),(0,X.useEffect)(()=>{if(!_){w(null),E(!1);return}let e=!1;return E(!1),Z.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 A=!!(_&&f),j=e&&!y&&!A;return(0,F.jsx)(O,{open:e,onOpenChange:t,children:(0,F.jsxs)(h,{children:[(0,F.jsx)(c,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim backdrop-blur-[1px]`}),(0,F.jsxs)(g,{className:i(`fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,52rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`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,F.jsx)(te,{asChild:!0,children:(0,F.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,F.jsx)(p,{className:`size-4`})})}),(0,F.jsx)(a,{className:`sr-only`,children:n.weixinQrModalTitle}),(0,F.jsx)(u,{className:`sr-only`,children:n.weixinQrModalSubtitle}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`p`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.weixinQrModalTitle}),(0,F.jsx)(`p`,{className:`mt-1.5 text-sm text-fg-muted`,children:n.weixinQrModalSubtitle})]}),(0,F.jsxs)(`div`,{className:`mt-6 flex min-h-[17.5rem] flex-col items-center justify-center gap-3`,children:[y?(0,F.jsx)(`p`,{className:`text-center text-sm text-red-600 dark:text-red-400`,children:y}):null,!y&&(A||j)?(0,F.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-3`,children:[(0,F.jsx)(`p`,{className:i(`min-h-[1.25rem] text-center text-sm`,x&&!j?`text-accent`:`text-fg-muted`),children:j?n.weixinQrLoginBusy:x??`\xA0`}),(0,F.jsxs)(`div`,{className:i(`relative flex h-52 w-52 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-edge-subtle bg-white p-3 dark:border-edge`,j&&`bg-surface-muted/40 dark:bg-surface-base`),children:[j?(0,F.jsx)(`div`,{className:`absolute inset-3 animate-pulse rounded-md bg-surface-muted dark:bg-surface-hover`,"aria-hidden":!0}):null,A&&_&&!y&&C&&!T?(0,F.jsx)(`img`,{src:C,alt:``,className:`relative z-[1] size-full object-contain`}):null,A&&_&&!y&&!C&&!T&&!j?(0,F.jsx)(`p`,{className:`relative z-[1] px-2 text-center text-sm text-fg-muted`,children:n.weixinQrEncoding}):null,A&&_&&!y&&T?(0,F.jsxs)(`div`,{className:`relative z-[1] flex size-full flex-col items-center justify-center gap-2 px-1`,children:[(0,F.jsx)(`p`,{className:`text-center text-xs text-fg-muted`,children:n.weixinQrImageError}),(0,F.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,F.jsx)(d,{className:`size-3 shrink-0`}),n.weixinQrOpenLink]})]}):null]})]}):null]}),(0,F.jsx)(`div`,{className:`mt-6`,children:(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`h-11 w-full rounded-full border-0 bg-fg text-surface-panel hover:opacity-90 dark:bg-fg dark:text-surface-panel`,disabled:s,onClick:()=>void k(),children:s?n.weixinQrLoginBusy:n.weixinQrRegenerate})}),o?(0,F.jsx)(`div`,{className:`mt-6 border-t border-edge-subtle pt-4 dark:border-edge-subtle`,children:o}):null]})]})})}function Fe({wx:e,updateWeixin:t,ch:n,dmOpts:r,streamOpts:a,wxAccountsDraft:o,setWxAccountsDraft:s,wxAccountsError:c,onWxAccountsBlur:l,channelAgentRoutesWx:u,defaultAgentId:d,agentItems:f,onAgentRouteChange:p,routingDisabled:m}){let h=B;return(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle pt-4 dark:border-edge`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.weixinAllowFrom}),(0,F.jsx)(`textarea`,{className:i(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,F.jsx)(q,{children:n.weixinAllowFromDesc})]}),(0,F.jsx)(J,{label:n.dmPolicy,value:e.dmPolicy,onChange:e=>t({dmPolicy:e}),options:r}),(0,F.jsx)(J,{label:n.streamMode,value:e.streamMode,onChange:e=>t({streamMode:e}),options:a}),(0,F.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.historyLimit}),(0,F.jsx)(`input`,{type:`number`,min:10,max:200,className:h(),value:e.historyLimit,onChange:e=>t({historyLimit:parseInt(e.target.value,10)||50})})]}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.textChunkLimit}),(0,F.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,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.weixinRouteTag}),(0,F.jsx)(`input`,{className:h(),value:e.routeTag,onChange:e=>t({routeTag:e.target.value}),placeholder:n.routeTagPlaceholder}),(0,F.jsx)(q,{children:n.weixinRouteTagDesc})]}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:e.debug,onChange:e=>t({debug:e.target.checked})}),n.weixinDebug]}),(0,F.jsx)(q,{children:n.weixinDebugDesc}),(0,F.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,F.jsx)(K,{children:n.weixinAccountsJson}),(0,F.jsx)(`textarea`,{className:i(h(),`min-h-[140px] resize-y font-mono text-xs`),spellCheck:!1,value:o,onChange:e=>s(e.target.value),onBlur:l,placeholder:`{ "personal": { "name": "...", "cdnBaseUrl": "...", "enabled": true } }`}),c?(0,F.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:c}):(0,F.jsx)(q,{children:n.weixinAccountsJsonDesc})]}),(0,F.jsx)(Y,{accountIds:fe(e),routes:u,defaultAgentId:d,agentItems:f,disabled:m,onChange:p,ch:n})]})}function Ie({ch:e,wx:t,updateWeixin:n,dmOpts:r,streamOpts:i,wxAccountsDraft:a,setWxAccountsDraft:o,wxAccountsError:s,onWxAccountsBlur:c,form:l,chatAgents:u,onAgentRouteChange:d,saving:f,dirty:p,save:m,discard:h}){return(0,F.jsxs)(`details`,{className:`group rounded-xl border border-edge-subtle bg-surface-base open:pb-3 dark:border-edge`,children:[(0,F.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,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(k,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`}),e.advancedShow]})}),(0,F.jsxs)(`div`,{className:`space-y-4 border-t border-edge-subtle px-3 pb-3 pt-3 dark:border-edge-subtle`,children:[(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:e.weixinAdvancedHint}),(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,F.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:t.enabled,onChange:e=>n({enabled:e.target.checked})}),(0,F.jsx)(`span`,{children:e.enableWeixinAria})]}),(0,F.jsx)(`div`,{className:`[&>div]:border-0 [&>div]:pt-0`,children:(0,F.jsx)(Fe,{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,F.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:justify-end`,children:[(0,F.jsx)(D,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:h,children:e.discard}),(0,F.jsx)(D,{type:`button`,variant:`primary`,className:`w-full sm:w-auto`,disabled:!p||f,onClick:async()=>{await m()},children:f?e.saving:e.save})]})]})]})}function Le(){let{language:e,m:t,ch:n,hasToken:r,loading:i,fetchError:a,mutate:o,form:s,baseline:c,dirty:l,saving:u,error:f,saveOk:p,weixinModalOpen:m,setWeixinModalOpen:h,telegramModalOpen:g,setTelegramModalOpen:_,feishuModalOpen:v,setFeishuModalOpen:y,removeTarget:x,setRemoveTarget:S,weixinSuccessBanner:C,setWeixinSuccessBanner:E,dingtalkModalOpen:O,setDingtalkModalOpen:k,feishuSetupSuccessBanner:A,dingtalkSetupSuccessBanner:j,tgAdvanced:M,setTgAdvanced:ee,showToken:N,setShowToken:te,showFeishuSecret:ne,setShowFeishuSecret:ie,showFeishuWebhookSecrets:ae,setShowFeishuWebhookSecrets:oe,showDingtalkSecret:se,setShowDingtalkSecret:P,copied:ce,feishuCopied:le,dingtalkCopied:L,feishuWebhookCopied:R,tgAccountsDraft:de,setTgAccountsDraft:fe,tgAccountsError:pe,wxAccountsDraft:me,setWxAccountsDraft:he,wxAccountsError:z,feishuAccountsDraft:B,setFeishuAccountsDraft:V,feishuAccountsError:H,dingtalkAccountsDraft:U,setDingtalkAccountsDraft:ge,dingtalkAccountsError:K,chatAgents:q,updateChannelAgentRoute:J,updateTelegram:Y,updateWeixin:X,updateFeishu:Z,updateDingtalk:be,save:xe,discard:Se,toggleChannelEnabled:Q,removeChannel:Ce,copyToken:we,handleFeishuQrSetupSuccess:Te,handleDingtalkQrSetupSuccess:Ee,copyFeishuSecret:$,copyDingtalkSecret:De,copyFeishuWebhookConfig:je,onTgAccountsBlur:Fe,onWxAccountsBlur:Le,onFeishuAccountsBlur:Re,onDingtalkAccountsBlur:ze,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue}=Ne();if(!r)return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,F.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.channels}),(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(i)return(0,F.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,F.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,F.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,F.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:n.loading})]});if(!s)return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,F.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??a??n.loadError}),(0,F.jsx)(D,{type:`button`,variant:`secondary`,onClick:()=>void o(),children:n.retry})]});let We=s.weixin,Ge=s.telegram,Ke=s.feishu,qe=s.dingtalk,Je=W(We),Ye=_e(Ge),Xe=ve(Ke),Ze=G(qe),Qe=(0,F.jsx)(ke,{ch:n,form:s,baseline:c,showFeishuSecret:ne,setShowFeishuSecret:ie,showFeishuWebhookSecrets:ae,setShowFeishuWebhookSecrets:oe,feishuCopied:le,feishuWebhookCopied:R,copyFeishuSecret:$,copyFeishuWebhookConfig:je,updateFeishu:Z,updateChannelAgentRoute:J,feishuAccountsDraft:B,setFeishuAccountsDraft:V,feishuAccountsError:H,onFeishuAccountsBlur:Re,dmOpts:Be,groupOpts:Ve,chatAgents:q,saving:u,dirty:l,save:xe,discard:Se}),$e=(0,F.jsx)(ye,{ch:n,form:s,baseline:c,showDingtalkSecret:se,setShowDingtalkSecret:P,dingtalkCopied:L,copyDingtalkSecret:De,updateDingtalk:be,updateChannelAgentRoute:J,dingtalkAccountsDraft:U,setDingtalkAccountsDraft:ge,dingtalkAccountsError:K,onDingtalkAccountsBlur:ze,dmOpts:Be,groupOpts:Ve,chatAgents:q,saving:u,dirty:l,save:xe,discard:Se}),et=(0,F.jsx)(Ie,{ch:n,wx:We,updateWeixin:X,dmOpts:Be,streamOpts:Ue,wxAccountsDraft:me,setWxAccountsDraft:he,wxAccountsError:z,onWxAccountsBlur:Le,form:s,chatAgents:q,onAgentRouteChange:(e,t)=>J(`weixin`,e,t),saving:u,dirty:l,save:xe,discard:Se});return(0,F.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,F.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,F.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.channels}),(0,F.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,F.jsxs)(`a`,{href:T(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,F.jsx)(d,{className:`size-3.5`})]})]}),l?(0,F.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,F.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.saved}):null,f?(0,F.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,C?(0,F.jsx)(`p`,{className:`text-xs text-accent`,children:C}):null,A?(0,F.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:A}):null,j?(0,F.jsx)(`div`,{className:`rounded-xl border border-success/30 bg-success-soft px-4 py-3 text-sm text-success`,children:j}):null,(0,F.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,F.jsx)(I,{icon:(0,F.jsx)(b,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.weixinTitle,subtitle:n.weixinSubtitle,configured:Je,enabled:We.enabled,toggleDisabled:u,onToggle:e=>void Q(`weixin`,e),onConfigure:()=>h(!0),onEdit:()=>h(!0),onRemove:()=>S(`weixin`),ch:n}),(0,F.jsx)(I,{icon:(0,F.jsx)(w,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.telegramTitle,subtitle:n.telegramSubtitle,configured:Ye,enabled:Ge.enabled,toggleDisabled:u,onToggle:e=>void Q(`telegram`,e),onConfigure:()=>_(!0),onEdit:()=>_(!0),onRemove:()=>S(`telegram`),ch:n}),(0,F.jsx)(I,{icon:(0,F.jsx)(b,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.feishuTitle,subtitle:n.feishuSubtitle,configured:Xe,enabled:Ke.enabled,toggleDisabled:u,onToggle:e=>void Q(`feishu`,e),onConfigure:()=>y(!0),onEdit:()=>y(!0),onRemove:()=>S(`feishu`),ch:n}),(0,F.jsx)(I,{icon:(0,F.jsx)(re,{className:`size-6 text-accent`,strokeWidth:1.75}),title:n.dingtalkTitle,subtitle:n.dingtalkSubtitle,configured:Ze,enabled:qe.enabled,toggleDisabled:u,onToggle:e=>void Q(`dingtalk`,e),onConfigure:()=>k(!0),onEdit:()=>k(!0),onRemove:()=>S(`dingtalk`),ch:n})]}),(0,F.jsx)(Pe,{open:m,onOpenChange:h,ch:n,onLoginSuccess:async()=>{await o(),E(n.weixinQrLoginSuccess),window.setTimeout(()=>E(null),4e3)},moreSettings:et}),(0,F.jsx)(Me,{open:g,onOpenChange:_,ch:n,form:s,baseline:c,tgAdvanced:M,setTgAdvanced:ee,showToken:N,setShowToken:te,copied:ce,copyToken:we,updateTelegram:Y,updateChannelAgentRoute:J,tgAccountsDraft:de,setTgAccountsDraft:fe,tgAccountsError:pe,onTgAccountsBlur:Fe,dmOpts:Be,groupOpts:Ve,replyOpts:He,streamOpts:Ue,chatAgents:q,saving:u,dirty:l,save:xe,discard:Se}),(0,F.jsx)(Ae,{open:v,onOpenChange:y,ch:n,onSetupSuccess:Te,moreSettings:Qe}),(0,F.jsx)(Oe,{open:O,onOpenChange:k,ch:n,onSetupSuccess:Ee,moreSettings:$e}),(0,F.jsx)(ue,{open:x!==null,onOpenChange:e=>{e||S(null)},ch:n,removeTarget:x,onCancel:()=>S(null),saving:u,onConfirmRemove:()=>void Ce()})]})}export{Le as ChannelsSettingsPanel};
|
|
2
|
+
//# sourceMappingURL=channels-settings-BNR4uMFv.js.map
|