botmux 3.11.0 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/.runtime-build-id +1 -1
  2. package/dist/adapters/backend/riff-backend.d.ts.map +1 -1
  3. package/dist/adapters/backend/riff-backend.js +11 -2
  4. package/dist/adapters/backend/riff-backend.js.map +1 -1
  5. package/dist/adapters/cli/coco.js +3 -3
  6. package/dist/adapters/cli/coco.js.map +1 -1
  7. package/dist/adapters/cli/codex.js +2 -2
  8. package/dist/adapters/cli/codex.js.map +1 -1
  9. package/dist/cli/dashboard-command.d.ts +23 -0
  10. package/dist/cli/dashboard-command.d.ts.map +1 -0
  11. package/dist/cli/dashboard-command.js +61 -0
  12. package/dist/cli/dashboard-command.js.map +1 -0
  13. package/dist/cli/dashboard-endpoint.d.ts +3 -3
  14. package/dist/cli/dashboard-endpoint.d.ts.map +1 -1
  15. package/dist/cli/dashboard-endpoint.js +1 -1
  16. package/dist/cli.d.ts.map +1 -1
  17. package/dist/cli.js +36 -22
  18. package/dist/cli.js.map +1 -1
  19. package/dist/codex-rpc-engine.d.ts +33 -3
  20. package/dist/codex-rpc-engine.d.ts.map +1 -1
  21. package/dist/codex-rpc-engine.js +182 -20
  22. package/dist/codex-rpc-engine.js.map +1 -1
  23. package/dist/codex-rpc-lifecycle.d.ts +42 -7
  24. package/dist/codex-rpc-lifecycle.d.ts.map +1 -1
  25. package/dist/codex-rpc-lifecycle.js +73 -7
  26. package/dist/codex-rpc-lifecycle.js.map +1 -1
  27. package/dist/config.d.ts +1 -1
  28. package/dist/config.js +1 -1
  29. package/dist/core/command-handler.d.ts +3 -2
  30. package/dist/core/command-handler.d.ts.map +1 -1
  31. package/dist/core/command-handler.js +3 -2
  32. package/dist/core/command-handler.js.map +1 -1
  33. package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
  34. package/dist/core/dashboard-ipc-server.js +15 -10
  35. package/dist/core/dashboard-ipc-server.js.map +1 -1
  36. package/dist/core/dispatch.d.ts +9 -10
  37. package/dist/core/dispatch.d.ts.map +1 -1
  38. package/dist/core/dispatch.js +17 -10
  39. package/dist/core/dispatch.js.map +1 -1
  40. package/dist/core/role-resolver.d.ts +5 -2
  41. package/dist/core/role-resolver.d.ts.map +1 -1
  42. package/dist/core/role-resolver.js +55 -23
  43. package/dist/core/role-resolver.js.map +1 -1
  44. package/dist/core/session-manager.d.ts +2 -0
  45. package/dist/core/session-manager.d.ts.map +1 -1
  46. package/dist/core/session-manager.js +20 -18
  47. package/dist/core/session-manager.js.map +1 -1
  48. package/dist/core/terminal-write-auth.d.ts +4 -4
  49. package/dist/core/terminal-write-auth.d.ts.map +1 -1
  50. package/dist/core/terminal-write-auth.js +18 -6
  51. package/dist/core/terminal-write-auth.js.map +1 -1
  52. package/dist/daemon.d.ts +1 -0
  53. package/dist/daemon.d.ts.map +1 -1
  54. package/dist/daemon.js +101 -12
  55. package/dist/daemon.js.map +1 -1
  56. package/dist/dashboard/auth.d.ts +21 -11
  57. package/dist/dashboard/auth.d.ts.map +1 -1
  58. package/dist/dashboard/auth.js +39 -25
  59. package/dist/dashboard/auth.js.map +1 -1
  60. package/dist/dashboard/bot-payload.d.ts +0 -1
  61. package/dist/dashboard/bot-payload.d.ts.map +1 -1
  62. package/dist/dashboard/bot-payload.js +0 -1
  63. package/dist/dashboard/bot-payload.js.map +1 -1
  64. package/dist/dashboard/dashboard-summary-endpoint.d.ts +39 -0
  65. package/dist/dashboard/dashboard-summary-endpoint.d.ts.map +1 -0
  66. package/dist/dashboard/dashboard-summary-endpoint.js +50 -0
  67. package/dist/dashboard/dashboard-summary-endpoint.js.map +1 -0
  68. package/dist/dashboard/dashboard-summary.d.ts +62 -0
  69. package/dist/dashboard/dashboard-summary.d.ts.map +1 -0
  70. package/dist/dashboard/dashboard-summary.js +106 -0
  71. package/dist/dashboard/dashboard-summary.js.map +1 -0
  72. package/dist/dashboard/web/feed-group-picker.d.ts +13 -0
  73. package/dist/dashboard/web/feed-group-picker.d.ts.map +1 -0
  74. package/dist/dashboard/web/feed-group-picker.js +45 -0
  75. package/dist/dashboard/web/feed-group-picker.js.map +1 -0
  76. package/dist/dashboard/web/groups-page.d.ts.map +1 -1
  77. package/dist/dashboard/web/groups-page.js +2 -5
  78. package/dist/dashboard/web/groups-page.js.map +1 -1
  79. package/dist/dashboard/web/i18n.d.ts.map +1 -1
  80. package/dist/dashboard/web/i18n.js +8 -14
  81. package/dist/dashboard/web/i18n.js.map +1 -1
  82. package/dist/dashboard/web/roles-page.d.ts.map +1 -1
  83. package/dist/dashboard/web/roles-page.js +36 -4
  84. package/dist/dashboard/web/roles-page.js.map +1 -1
  85. package/dist/dashboard/web/roles.d.ts +3 -1
  86. package/dist/dashboard/web/roles.d.ts.map +1 -1
  87. package/dist/dashboard/web/roles.js +10 -2
  88. package/dist/dashboard/web/roles.js.map +1 -1
  89. package/dist/dashboard/web/schedules-page.d.ts.map +1 -1
  90. package/dist/dashboard/web/schedules-page.js +8 -2
  91. package/dist/dashboard/web/schedules-page.js.map +1 -1
  92. package/dist/dashboard/web/sessions-page.d.ts.map +1 -1
  93. package/dist/dashboard/web/sessions-page.js +2 -2
  94. package/dist/dashboard/web/sessions-page.js.map +1 -1
  95. package/dist/dashboard-web/app.js +1 -1
  96. package/dist/dashboard-web/chunks/{bot-defaults-page-GED4FEMS.js → bot-defaults-page-USC6EZXP.js} +1 -1
  97. package/dist/dashboard-web/chunks/chunk-6ALR252E.js +1 -0
  98. package/dist/dashboard-web/chunks/{chunk-VBXJOJFH.js → chunk-A7VC4BXR.js} +1 -1
  99. package/dist/dashboard-web/chunks/{chunk-HK7NIBJG.js → chunk-KOPISPHN.js} +1 -1
  100. package/dist/dashboard-web/chunks/{chunk-6J5LS5AU.js → chunk-M6BHWQFO.js} +6 -6
  101. package/dist/dashboard-web/chunks/{chunk-KRHWZEXU.js → chunk-RXRJB5SO.js} +1 -1
  102. package/dist/dashboard-web/chunks/{connectors-page-EELM66G3.js → connectors-page-4Z76HWRH.js} +1 -1
  103. package/dist/dashboard-web/chunks/groups-page-C6NSDTIN.js +8 -0
  104. package/dist/dashboard-web/chunks/{insights-page-54UBPPOC.js → insights-page-UTOVYLLY.js} +1 -1
  105. package/dist/dashboard-web/chunks/{monitor-room-PORHVKRH.js → monitor-room-UKTJYTA2.js} +1 -1
  106. package/dist/dashboard-web/chunks/{monitoring-page-XGA7AXNL.js → monitoring-page-Q3CEZIVX.js} +1 -1
  107. package/dist/dashboard-web/chunks/{office-page-AO3AFG45.js → office-page-GYCZOOVJ.js} +1 -1
  108. package/dist/dashboard-web/chunks/{overview-page-F5BUTYR6.js → overview-page-W2VBJ6OH.js} +1 -1
  109. package/dist/dashboard-web/chunks/roles-page-U4SHER4K.js +1 -0
  110. package/dist/dashboard-web/chunks/schedules-page-TNPW3N3Q.js +1 -0
  111. package/dist/dashboard-web/chunks/{sessions-page-YFRPSTIL.js → sessions-page-YWWDDV57.js} +3 -3
  112. package/dist/dashboard-web/chunks/{settings-page-OJAZLZQT.js → settings-page-VKW5ZK5K.js} +1 -1
  113. package/dist/dashboard-web/chunks/{skills-page-EFZQPWV4.js → skills-page-ZCEDFGZZ.js} +1 -1
  114. package/dist/dashboard-web/chunks/{team-federation-page-ZJVAP7HW.js → team-federation-page-OMFGGBT2.js} +1 -1
  115. package/dist/dashboard-web/chunks/{v3-page-GYWTRGO2.js → v3-page-PLXWK4KO.js} +1 -1
  116. package/dist/dashboard-web/chunks/{whiteboards-page-MSDAG6P7.js → whiteboards-page-NJQOEO2P.js} +1 -1
  117. package/dist/dashboard-web/style.css +112 -0
  118. package/dist/dashboard.js +116 -31
  119. package/dist/dashboard.js.map +1 -1
  120. package/dist/desktop/main/ipc.js +1 -1
  121. package/dist/desktop/main/runtime-service.js +2 -2
  122. package/dist/desktop/main/runtime-service.js.map +1 -1
  123. package/dist/desktop/shared/types.d.ts +1 -1
  124. package/dist/i18n/en.d.ts.map +1 -1
  125. package/dist/i18n/en.js +3 -1
  126. package/dist/i18n/en.js.map +1 -1
  127. package/dist/i18n/zh.d.ts.map +1 -1
  128. package/dist/i18n/zh.js +3 -1
  129. package/dist/i18n/zh.js.map +1 -1
  130. package/dist/services/adopt-input-sequence.d.ts +52 -0
  131. package/dist/services/adopt-input-sequence.d.ts.map +1 -0
  132. package/dist/services/adopt-input-sequence.js +50 -0
  133. package/dist/services/adopt-input-sequence.js.map +1 -0
  134. package/dist/services/bridge-fallback-gate.d.ts.map +1 -1
  135. package/dist/services/bridge-fallback-gate.js +34 -11
  136. package/dist/services/bridge-fallback-gate.js.map +1 -1
  137. package/dist/services/codex-bridge-queue.d.ts +103 -7
  138. package/dist/services/codex-bridge-queue.d.ts.map +1 -1
  139. package/dist/services/codex-bridge-queue.js +291 -17
  140. package/dist/services/codex-bridge-queue.js.map +1 -1
  141. package/dist/services/codex-transcript.d.ts +4 -3
  142. package/dist/services/codex-transcript.d.ts.map +1 -1
  143. package/dist/services/codex-transcript.js.map +1 -1
  144. package/dist/services/structured-bridge-clis.d.ts +8 -1
  145. package/dist/services/structured-bridge-clis.d.ts.map +1 -1
  146. package/dist/services/structured-bridge-clis.js +13 -0
  147. package/dist/services/structured-bridge-clis.js.map +1 -1
  148. package/dist/services/submit-confirmation.d.ts +50 -0
  149. package/dist/services/submit-confirmation.d.ts.map +1 -1
  150. package/dist/services/submit-confirmation.js +82 -0
  151. package/dist/services/submit-confirmation.js.map +1 -1
  152. package/dist/utils/async-serial-queue.d.ts +9 -0
  153. package/dist/utils/async-serial-queue.d.ts.map +1 -0
  154. package/dist/utils/async-serial-queue.js +13 -0
  155. package/dist/utils/async-serial-queue.js.map +1 -0
  156. package/dist/utils/runtime-screen-status.d.ts +52 -0
  157. package/dist/utils/runtime-screen-status.d.ts.map +1 -0
  158. package/dist/utils/runtime-screen-status.js +60 -0
  159. package/dist/utils/runtime-screen-status.js.map +1 -0
  160. package/dist/worker.js +1642 -452
  161. package/dist/worker.js.map +1 -1
  162. package/package.json +1 -1
  163. package/dist/dashboard-web/chunks/groups-page-WKUV6E42.js +0 -8
  164. package/dist/dashboard-web/chunks/roles-page-M5GIASJU.js +0 -1
  165. package/dist/dashboard-web/chunks/schedules-page-O232WQRR.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "botmux",
3
- "version": "3.11.0",
3
+ "version": "3.12.0",
4
4
  "description": "Bridge between IM platforms and AI coding CLIs — one topic, one CLI session with live streaming",
5
5
  "type": "module",
6
6
  "main": "dist/index-daemon.js",
@@ -1,8 +0,0 @@
1
- import{a as he,b as ve,c as be,d as ye}from"./chunk-R3FXBFQH.js";import{a as fe}from"./chunk-ZJVTGU5X.js";import{c as me}from"./chunk-HK7NIBJG.js";import{c as X,g as Y,h as ce,m as ue,n as de,o as pe,p as ge,q as Q}from"./chunk-5CJMHTT4.js";import{A as se,c as J,d as z,u as V,x as ne}from"./chunk-6J5LS5AU.js";import{a as ie}from"./chunk-SYC6D5XU.js";import{a as Le,d as le}from"./chunk-5THX4DI2.js";import{c as Z}from"./chunk-7SZRL6FY.js";var i=Z(Le(),1);var Me=/^[A-Za-z0-9._-]{1,64}$/,ke=6,we=30;function ee(o,t){return be(o,t)}function Ie(o,t,r=we){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):we,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,d=Math.min(c,Math.max(1,s)),b=(d-1)*n,G=Math.min(a,b+n);return{rows:o.slice(b,G),page:d,totalPages:c,from:a===0?0:b+1,to:G,total:a}}async function Ce(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function te(o){return Me.test(o)&&o!=="."&&o!==".."}function oe(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return te(t)?t:"profile"}async function K(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Pe(o){let t=await K(),r=await Ce(t,ke,async s=>{try{let b=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(b.entries)?b.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let d of s.memberBots??[]){if(!d?.inChat||!d?.hasRole||!d?.larkAppId)continue;let b=ee(d.larkAppId,s.chatId);n.has(b)||(n.add(b),a.push({chatId:s.chatId,larkAppId:d.larkAppId}))}let c=await ye(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Se(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ce(t,ke,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,d=c?String(s??"").trim():"",b=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:d,status:d?b??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ne(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Ge(o,t){let r=t.q.trim().toLowerCase();return o.filter(n=>!r||(n.name??"").toLowerCase().includes(r)||n.chatId.toLowerCase().includes(r)||(n.ownerId??"").toLowerCase().includes(r)).filter(n=>!t.missingOnly||(n.memberBots??[]).some(a=>!a.inChat))}function Re(o,t){if(t.size===0)return!0;let r=o?.memberBots??[];for(let n of t)if(!r.some(a=>a.larkAppId===n&&a.inChat))return!1;return!0}function Ae(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function xe(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:V("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:V("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:V("groups.roleProfileBootstrapDone",{name:n})}}function Te(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(d=>({larkAppId:d.larkAppId,botName:d.botName,inChat:c.has(d.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(d=>d.chatId!==t)]}}var e=Z(le(),1);function Be(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Oe(o){let t={};for(let r of ne(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function De(o){let t=o.chat,r=t.avatar??se(t.chatId),[n,a]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:Oe(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function re(o){return(0,e.jsxs)("p",{className:"hint-warn",children:[(0,e.jsx)("strong",{children:o.title}),(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:String(o.reason??"unknown")})]})}function Ee(o){return(0,e.jsx)(e.Fragment,{children:Ne(o.bots,o.excludeIds).map(t=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"bot",value:t.larkAppId}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]})]},t.larkAppId))})}function Fe(o){let t=o.summary;return t.rows.length?(0,e.jsxs)("div",{className:t.failed?"hint-warn":"hint-ok",children:[(0,e.jsxs)("strong",{children:["\u6DFB\u52A0\u7ED3\u679C\uFF1A\u6210\u529F ",t.okCount,"/",t.rows.length,t.failed?`\uFF0C\u5931\u8D25 ${t.failed}`:""]}),(0,e.jsx)("ul",{children:t.rows.map((r,n)=>{let a=String(r?.id??"?");return(0,e.jsxs)("li",{children:[(0,e.jsx)("code",{children:a}),": ",r?.ok?"OK":`failed (${String(r?.error??"unknown")})`]},`${a}-${n}`)})})]}):(0,e.jsx)("p",{className:"hint-warn",children:"\u6CA1\u6709\u8FD4\u56DE\u6DFB\u52A0\u7ED3\u679C\u3002"})}function Ue(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let b of t.memberBots??[])b?.inChat&&a.set(b.larkAppId,r.groupRoleContentByBot.get(ee(b.larkAppId,t.chatId))??null);if(!he(a))return null;let s=ve(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let d=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(d,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function je(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function He(o,t){switch(o){case"in":return t("groups.botStatusIn");case"out":return t("groups.botStatusOut");case"error":return t("groups.botStatusError");default:return t("groups.botStatusUnknown")}}function _e(o){let t=new Map((o.chat.memberBots??[]).map(r=>[r.larkAppId,r]));return(0,e.jsx)("div",{className:"groups-bot-strip","aria-label":o.tr("groups.botCoverage"),children:o.bots.map(r=>{let n=t.get(r.larkAppId),a=je(n),c=He(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var We=(0,i.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(de,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(De,{chat:r}),(0,e.jsxs)(pe,{children:[(0,e.jsxs)("div",{className:"groups-row-head",children:[(0,e.jsx)("b",{children:r.name??r.chatId}),(0,e.jsxs)("span",{className:"groups-row-meta",children:[(0,e.jsx)("span",{className:"groups-row-tag",children:(0,e.jsx)("code",{children:r.chatId})}),r.ownerId?(0,e.jsxs)("span",{className:"groups-row-tag groups-row-owner-tag",children:[(0,e.jsx)("span",{children:n("groups.owner")}),(0,e.jsx)("code",{children:r.ownerId})]}):null]})]}),(0,e.jsx)(Ue,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(_e,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(ge,{children:[(0,e.jsx)(Y,{className:"add-bots",onClick:()=>t.onAddBots(r),children:n("groups.addBots")}),(0,e.jsx)("button",{className:"save-profile",type:"button",onClick:()=>t.onSaveProfile(r),children:n("groups.saveAsProfile")}),(0,e.jsx)("button",{className:"manage-chat",type:"button",onClick:()=>t.onManage(r),children:n("groups.manage")})]})]})]})});function Je(o){let{tr:t}=o,[r,n]=(0,i.useState)(!1),[a,c]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[b,G]=(0,i.useState)(!1),[g,y]=(0,i.useState)(""),[P,m]=(0,i.useState)([]),[I,v]=(0,i.useState)(""),[C,B]=(0,i.useState)(""),[O,A]=(0,i.useState)(""),[M,j]=(0,i.useState)(!0),[E,H]=(0,i.useState)(""),[x,$]=(0,i.useState)(!1),[D,_]=(0,i.useState)(""),[F,S]=(0,i.useState)("");(0,i.useEffect)(()=>{let u=!0;return fetch("/api/feed-groups").then(async h=>{let k=await h.json().catch(()=>({}));if(!h.ok||!k.ok)throw new Error(k.message??k.error??`HTTP ${h.status}`);u&&(m(Array.isArray(k.groups)?k.groups:[]),v(typeof k.larkAppId=="string"?k.larkAppId:""))}).catch(h=>{u&&H(h instanceof Error?h.message:String(h))}).finally(()=>{u&&j(!1)}),()=>{u=!1}},[]),(0,i.useEffect)(()=>{if(!D)return;let u=!0,h=window.setInterval(()=>{fetch("/api/feed-groups").then(async k=>{let R=await k.json().catch(()=>({}));!k.ok||!R.ok||!u||(m(Array.isArray(R.groups)?R.groups:[]),v(typeof R.larkAppId=="string"?R.larkAppId:""),H(""),_(""),S(""))}).catch(()=>{})},1e3);return()=>{u=!1,window.clearInterval(h)}},[D]);async function p(){let u=I?`?larkAppId=${encodeURIComponent(I)}`:"",h=await fetch(`/api/feed-groups/auth-url${u}`),k=await h.json().catch(()=>({}));if(!h.ok||!k.authUrl){c({title:"\u65E0\u6CD5\u53D1\u8D77\u6807\u7B7E\u6388\u6743",reason:k.error??`HTTP ${h.status}`});return}_(String(k.authUrl)),S("")}async function L(u){$(!0);try{let h=await fetch("/api/feed-groups/oauth-callback",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({callbackUrl:u.trim()})}),k=await h.json().catch(()=>({}));if(!h.ok||!k.ok)throw new Error(k.message??k.error??`HTTP ${h.status}`);let R=await fetch("/api/feed-groups"),l=await R.json().catch(()=>({}));if(!R.ok||!l.ok)throw new Error(l.message??l.error??`HTTP ${R.status}`);m(Array.isArray(l.groups)?l.groups:[]),v(typeof l.larkAppId=="string"?l.larkAppId:""),H(""),_(""),S("")}catch(h){c({title:"\u6807\u7B7E\u6388\u6743\u5931\u8D25",reason:h instanceof Error?h.message:String(h)})}finally{$(!1)}}async function U(u){u.preventDefault();let h=new FormData(u.currentTarget),k=String(h.get("name")??"").trim(),R=String(h.get("bindWorkingDir")??"").trim(),l=String(h.get("roleProfileId")??"").trim(),f=h.getAll("bot");if(f.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let w=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:k||void 0,larkAppIds:f,bindWorkingDir:R||void 0,roleProfileId:l||void 0,feedGroupId:C||void 0,newFeedGroupName:O||void 0,feedGroupAppId:C||O?I:void 0})}),N=await w.json().catch(()=>({ok:!1,error:`HTTP ${w.status}`}));N.ok&&N.chatId?(d(N),o.onCreated(N,f,k)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:N.error??`HTTP ${w.status}`}),n(!1))}catch(w){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:w}),n(!1)}}if(s){let u=String(s.chatId),h=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(u)}`,k=s.invalidBotIds??[],R=s.invalidUserIds??[],l=Array.isArray(s.oncallBindings)?s.oncallBindings:[],f=l.filter(T=>T?.ok).length,w=l.filter(T=>!T?.ok),N=xe(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:u})," ",(0,e.jsx)("button",{type:"button","data-copy":u,onClick:()=>{fe(u,t("sessions.copy")).then(T=>{T&&(G(!0),o.setTimer(()=>G(!1),800))})},children:t(b?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),s.feedGroupId?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u52A0\u5165\u98DE\u4E66\u6807\u7B7E",s.feedGroupName?`\u300C${String(s.feedGroupName)}\u300D`:"","\u3002"]}):null,s.feedGroupError?(0,e.jsxs)("p",{className:"hint-warn",children:["\u7FA4\u804A\u5DF2\u521B\u5EFA\uFF0C\u4F46\u6807\u7B7E\u8BBE\u7F6E\u5931\u8D25\uFF1A",String(s.feedGroupError)]}):null,(0,e.jsx)(qe,{resp:s}),l.length>0?w.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",f,"/",l.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",f,"/",l.length,"\u3002",w.map((T,W)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(T?.larkAppId??"?")}),": ",String(T?.error??"unknown")]},`${T?.larkAppId??"?"}-${W}`))]}):null,N?(0,e.jsx)("p",{className:N.kind==="ok"?"hint-ok":"hint-warn",children:N.text}):null,k.length||R.length?(0,e.jsxs)("ul",{children:[k.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:k.join(", ")})]}):null,R.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:R.join(", ")})]}):null]}):null,(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-close",onClick:o.onClose,children:t("sessions.dismiss")}),(0,e.jsx)("a",{className:"btn-link primary",href:h,target:"_blank",rel:"noopener",children:t("groups.openGroup")})]})]})}return(0,e.jsxs)("article",{className:"g-create-dialog",children:[(0,e.jsxs)("header",{className:"g-create-head",children:[(0,e.jsx)("h3",{children:t("groups.createTitle")}),(0,e.jsx)("p",{children:t("groups.createHelp")})]}),(0,e.jsxs)("form",{id:"g-createform",className:"g-create-form",onSubmit:u=>{U(u)},children:[(0,e.jsxs)("fieldset",{className:"g-modal-field g-create-bots",children:[(0,e.jsx)("legend",{children:t("groups.botPicker")}),(0,e.jsx)("div",{className:"g-bot-picker",children:(0,e.jsx)(Ee,{bots:o.bots})})]}),(0,e.jsxs)("div",{className:"g-create-fields",children:[(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.name")}),(0,e.jsx)("input",{type:"text",name:"name",placeholder:t("groups.namePlaceholder"),maxLength:60})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.bindDir")}),(0,e.jsx)("input",{type:"text",name:"bindWorkingDir",placeholder:"e.g. ~/projects/botmux"}),(0,e.jsx)("small",{children:t("groups.bindDirHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-profile-field",children:[(0,e.jsx)("legend",{children:t("groups.roleProfile")}),(0,e.jsx)("input",{type:"hidden",name:"roleProfileId",value:g}),(0,e.jsx)(Q,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:g||t("groups.roleProfileNone"),value:g,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(u=>({value:u.profileId,label:u.profileId}))],onChange:y}),(0,e.jsx)("small",{children:t("groups.roleProfileHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-feed-group-field",children:[(0,e.jsx)("legend",{children:"\u98DE\u4E66\u6807\u7B7E\uFF08\u53EF\u9009\uFF09"}),(0,e.jsx)("input",{type:"hidden",name:"feedGroupId",value:C}),(0,e.jsx)(Q,{className:"g-profile-menu",ariaLabel:"\u98DE\u4E66\u6807\u7B7E",label:C?P.find(u=>u.groupId===C)?.name??C:"\u70B9\u51FB\u9009\u62E9\u5DF2\u6709\u6807\u7B7E\uFF08\u53EF\u9009\uFF09",value:C,options:[{value:"",label:"\u6682\u4E0D\u4F7F\u7528\u6807\u7B7E"},...P.map(u=>({value:u.groupId,label:u.name}))],onChange:u=>{B(u),u&&A("")}}),(0,e.jsxs)("div",{className:"g-feed-group-new",children:[(0,e.jsx)("span",{children:"\u6216\u65B0\u5EFA\u6807\u7B7E"}),(0,e.jsx)("input",{type:"text",name:"newFeedGroupName",value:O,maxLength:60,placeholder:"\u8F93\u5165\u65B0\u6807\u7B7E\u540D\u79F0",disabled:!!C||M||!!E,onChange:u=>A(u.currentTarget.value.trimStart())})]}),(0,e.jsx)("small",{children:"\u70B9\u51FB\u4E0A\u65B9\u4E0B\u62C9\u6846\u53EF\u9009\u62E9\u5DF2\u6709\u6807\u7B7E\uFF1B\u4E0D\u9009\u62E9\u5219\u4E0D\u4F7F\u7528\u6807\u7B7E\u3002"}),M?(0,e.jsx)("small",{children:"\u6B63\u5728\u8BFB\u53D6\u98DE\u4E66\u6807\u7B7E\u2026"}):null,E?(0,e.jsxs)("div",{className:"hint-warn-inline",children:[(0,e.jsx)("small",{children:E})," ",(0,e.jsx)("button",{type:"button",disabled:x,onClick:()=>{p()},children:x?"\u6B63\u5728\u5B8C\u6210\u6388\u6743\u2026":"\u7ACB\u5373\u6388\u6743"}),(0,e.jsx)("small",{children:" \u6388\u6743\u540E\u4F1A\u5F39\u7A97\u63D0\u793A\u4F60\u7C98\u8D34\u56DE\u8C03\u5730\u5740\u3002"})]}):null,!M&&!E&&P.length===0?(0,e.jsx)("small",{children:"\u5F53\u524D\u6CA1\u6709\u6807\u7B7E\uFF0C\u53EF\u76F4\u63A5\u521B\u5EFA\u4E00\u4E2A\u3002"}):null]})]}),D?(0,e.jsx)("div",{className:"feed-group-auth-overlay",children:(0,e.jsxs)("section",{className:"feed-group-auth-card",role:"dialog","aria-modal":"true","aria-labelledby":"feed-group-auth-title",children:[(0,e.jsx)("h3",{id:"feed-group-auth-title",children:"\u6388\u6743\u98DE\u4E66\u6807\u7B7E"}),(0,e.jsxs)("p",{children:["\u70B9\u51FB\u4E0B\u9762\u7684\u6309\u94AE\uFF0C\u5728\u98DE\u4E66\u9875\u9762\u786E\u8BA4\u6388\u6743\u3002\u5982\u679C BotMux \u4E0E\u6D4F\u89C8\u5668\u5728\u540C\u4E00\u53F0\u7535\u8111\uFF0C\u786E\u8BA4\u540E\u4F1A\u81EA\u52A8\u5B8C\u6210\u6388\u6743\u3002\u5982\u679C BotMux \u8FD0\u884C\u5728\u8FDC\u7A0B\u865A\u62DF\u673A\u4E0A\uFF0C\u6D4F\u89C8\u5668\u4F1A\u56E0\u65E0\u6CD5\u8BBF\u95EE\u672C\u673A\u5730\u5740 ",(0,e.jsx)("code",{children:"127.0.0.1:9768"})," \u800C\u663E\u793A\u201C\u65E0\u6CD5\u8BBF\u95EE\u201D\uFF1B\u6B64\u65F6\u8BF7\u590D\u5236\u5730\u5740\u680F\u4E2D\u7684\u5B8C\u6574\u94FE\u63A5\u5E76\u7C98\u8D34\u5230\u4E0B\u65B9\u3002"]}),(0,e.jsx)("button",{type:"button",className:"primary feed-group-auth-open",onClick:()=>window.open(D,"_blank","noopener"),children:"\u8DF3\u8F6C\u98DE\u4E66\u6388\u6743"}),(0,e.jsxs)("label",{children:[(0,e.jsx)("span",{children:"\u8BF7\u628A\u70B9\u51FB\u6388\u6743\u540E\u7684\u5B8C\u6574\u94FE\u63A5\u7C98\u8D34\u5728\u8FD9\u91CC"}),(0,e.jsx)("input",{type:"url",value:F,placeholder:"http://127.0.0.1:9768/callback?code=\u2026&state=\u2026",onChange:u=>S(u.currentTarget.value)})]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{_(""),S("")},children:"\u53D6\u6D88"}),(0,e.jsx)("button",{type:"button",className:"primary",disabled:!F.trim()||x,onClick:()=>{L(F)},children:x?"\u6B63\u5728\u5B8C\u6210\u6388\u6743\u2026":"\u5B8C\u6210\u6388\u6743"})]})]})}):null,(0,e.jsx)("div",{className:"g-create-status","data-create-status":!0,"aria-live":"polite",children:a?(0,e.jsx)(re,{...a}):null}),(0,e.jsxs)("div",{className:"actions g-create-actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:r,children:r?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("i",{className:"button-spinner","aria-hidden":"true"}),t("groups.createSubmitting")]}):t("groups.createSubmit")})]})]})]})}function qe(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,d=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8 @ \u901A\u77E5\u5931\u8D25\uFF08",d,"\uFF09\uFF0C\u65B0\u7FA4\u53EF\u80FD\u4E0D\u4F1A\u4E3B\u52A8\u51FA\u73B0\u5728\u4F60\u4FA7\u8FB9\u680F\uFF0C\u5EFA\u8BAE\u4ECE\u4E0B\u9762\u6309\u94AE\u8DF3\u8FDB\u53BB\u3002"]})]}):null]}):n?(0,e.jsxs)("p",{className:"hint-warn",children:["\u98DE\u4E66\u62D2\u7EDD\u4E86\u81EA\u52A8\u9080\u8BF7\uFF08\u4F60\u7684 open_id \u5728\u521B\u5EFA\u8005 bot \u7684 scope \u4E0B\u4E0D\u53EF\u7528\uFF09\u3002",(0,e.jsx)("strong",{children:"\u4F60\u76EE\u524D\u4E0D\u662F\u65B0\u7FA4\u6210\u5458"}),"\uFF0C\u9700\u8981\u8BA9\u7FA4\u91CC\u7684\u67D0\u4E2A\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u6765\u3002"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u6CA1\u5728 dashboard \u7F13\u5B58\u91CC\u627E\u5230 ownerOpenId\uFF0C",(0,e.jsx)("strong",{children:"\u6CA1\u6709\u81EA\u52A8\u9080\u8BF7\u4F60"}),"\u3002\u70B9\u5F00\u4E0B\u9762\u94FE\u63A5\u524D\uFF0C\u5148\u8BA9\u7FA4\u91CC\u4EFB\u4E00\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u53BB\u3002"]})}function ze(o){let{chat:t,tr:r}=o,[n,a]=(0,i.useState)(!1),[c,s]=(0,i.useState)(null),[d,b]=(0,i.useState)(null),G=(0,i.useMemo)(()=>new Set((t.memberBots??[]).filter(y=>y.inChat).map(y=>y.larkAppId)),[t]);async function g(y){y.preventDefault();let m=new FormData(y.currentTarget).getAll("bot");if(m.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),b(null);return}a(!0),s(null),b(null);try{let v=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:m})})).json();if(v.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(v.result){let C=Ae(v.result);try{await o.onReloadGroups({force:!0}),b({result:C})}catch(B){b({result:C,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${B}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(v)})}catch(I){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:I})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:y=>{g(y)},children:[(0,e.jsx)(Ee,{bots:o.bots,excludeIds:G}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(re,{...c}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Fe,{summary:d.result}),d.refreshError?(0,e.jsx)(re,{title:"\u5237\u65B0\u5931\u8D25",reason:d.refreshError}):null]}):null]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-cancel",onClick:o.onClose,children:r("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:n,children:n?"Adding...":r("groups.addBots")})]})]})]})}function Ve(o){let{tr:t}=o,[r,n]=(0,i.useState)([]),[a,c]=(0,i.useState)([]),[s,d]=(0,i.useState)(!0),[b,G]=(0,i.useState)(null),g=(0,i.useMemo)(()=>[...a].sort((p,L)=>p.profileId.localeCompare(L.profileId)),[a]),y=g.length>0,P=r.filter(p=>p.status==="empty").length,m=r.filter(p=>p.status==="error").length,I=!s&&!b&&r.length>0&&m===0,[v,C]=(0,i.useState)("new"),[B,O]=(0,i.useState)(o.suggestedProfileId),[A,M]=(0,i.useState)(""),[j,E]=(0,i.useState)(!1),[H,x]=(0,i.useState)(null),$=v==="overwrite"?A:B.trim(),D=t(v==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),_=b||(s?t("groups.saveProfilePreparing"):m?t("groups.saveProfileFailedLoadSummary",{count:m}):r.length?P?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:P}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,i.useEffect)(()=>{let p=!0;return d(!0),G(null),x(null),(async()=>{try{let[L,U]=await Promise.all([Se(o.chat),K().catch(()=>[])]);if(!p)return;let u=[...U].sort((h,k)=>h.profileId.localeCompare(k.profileId));n(L),c(U),M(h=>u.some(k=>k.profileId===h)?h:u[0]?.profileId??"")}catch(L){if(!p)return;n([]),c([]),M(""),G(L instanceof Error?L.message:String(L))}finally{p&&d(!1)}})(),()=>{p=!1}},[o.chat]);async function F(p){if(p.preventDefault(),!!I){if(!te($)){x({text:t("groups.saveProfileInvalid"),className:"error"});return}E(!0),x({text:t("groups.saveProfileSaving")});try{let U=(await Promise.all(r.map(async u=>(await fetch(`/api/role-profiles/${encodeURIComponent($)}/${encodeURIComponent(u.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:u.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(U!==r.length){x({text:t("groups.saveProfileFailed",{saved:U,total:r.length}),className:"error"}),E(!1);return}x({text:t("groups.saveProfileDone",{name:$,count:U}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(L){x({text:String(L),className:"error"}),E(!1)}}}function S(p){p==="overwrite"&&!y||(C(p),x(null))}return(0,e.jsxs)("article",{className:"g-save-profile-dialog",children:[(0,e.jsxs)("header",{children:[(0,e.jsx)("h3",{children:t("groups.saveProfileTitle")}),(0,e.jsx)("p",{children:t("groups.saveProfileIntro",{name:o.chat.name??o.chat.chatId,count:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:p=>{F(p)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),m?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:m})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(X,{label:t("common.loading")})}):b?(0,e.jsx)("div",{className:"g-save-profile-empty",children:b}):r.length?r.map(p=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${p.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:p.botName??p.larkAppId}),(0,e.jsx)("code",{children:p.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${p.status==="error"?"error":"ok"}`,children:t(p.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},p.larkAppId)):(0,e.jsx)("div",{className:"g-save-profile-empty",children:t("groups.saveProfileNoRoles")})})]}),(0,e.jsxs)("div",{className:"form-row",children:[(0,e.jsx)("span",{children:t("groups.saveProfileMode")}),(0,e.jsxs)("div",{className:"g-save-profile-switch",role:"tablist","aria-label":t("groups.saveProfileMode"),children:[(0,e.jsx)("button",{type:"button",className:v==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":v==="new",onClick:()=>S("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:v==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":v==="overwrite",disabled:!y,onClick:()=>S("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:v!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:B,maxLength:64,autoComplete:"off",onChange:p=>{O(p.currentTarget.value),x(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:v!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),y?(0,e.jsx)("div",{className:"g-save-profile-picker",children:g.map(p=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${p.profileId===A?"selected":""}`,"data-profile-id":p.profileId,"aria-pressed":p.profileId===A,onClick:()=>{M(p.profileId),C("overwrite"),x(null)},children:[(0,e.jsx)("span",{children:p.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:p.entryCount??0})})]},p.profileId))}):(0,e.jsx)("div",{className:"g-save-profile-summary warn",children:t("groups.saveProfileExistingEmpty")}),(0,e.jsx)("small",{children:t("groups.saveProfileOverwriteHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-target",children:[(0,e.jsx)("span",{children:t("groups.saveProfileTarget")}),(0,e.jsx)("code",{"data-save-profile-target":!0,children:$||"-"}),(0,e.jsx)("small",{"data-save-profile-target-mode":!0,children:t(v==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${I?"":"warn"}`,children:_}),(0,e.jsx)("div",{className:`g-save-profile-status ${H?.className??""}`,"data-save-profile-status":!0,children:H?.text??""}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-save-profile-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:!I||j||v==="overwrite"&&!A,children:j?t("groups.saveProfileSaving"):D})]})]})]})}function Ke(o){let{member:t,tr:r}=o,n=(0,i.useRef)(null),[a,c]=(0,i.useState)(!!t.oncallChat),[s,d]=(0,i.useState)(t.oncallChat?.workingDir??""),[b,G]=(0,i.useState)(!1),[g,y]=(0,i.useState)(null);async function P(){y(null);let m=s.trim();if(a&&!m){y({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}G(!0);try{let I=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,v=a?await fetch(I,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:m})}):await fetch(I,{method:"DELETE"}),C=await v.json().catch(()=>({}));if(v.ok&&C.ok){y({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${C.resolvedPath??m}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else y({text:`\u2717 ${C.error??v.status}`,className:"hint-warn-inline"})}catch(I){y({text:`\u2717 ${I?.message??I}`,className:"hint-warn-inline"})}finally{G(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:m=>{c(m.currentTarget.checked),m.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:m=>d(m.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:b,onClick:()=>{P()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${g?.className??""}`,"data-status":!0,children:g?.text??""})]})]})}function Ze(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(g=>g.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,i.useState)(()=>new Set);function d(g,y){s(P=>{let m=new Set(P);return y?m.add(g):m.delete(g),m})}async function b(){let g=[...c];if(g.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${g.length} \u4E2A\u673A\u5668\u4EBA\u9000\u51FA\u7FA4\u804A\uFF1F\u8BE5 bot \u5728\u6B64\u7FA4\u7684\u4F1A\u8BDD\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))try{let P=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:g})})).json(),m=(P.result??[]).map(I=>{if(!I.ok)return`${I.larkAppId}: \u5931\u8D25 (${I.error??"unknown"})`;let v=I.closedSessions??[],C=v.filter(A=>!A.ok).length,B=v.length-C,O=v.length===0?"":C===0?`\uFF08\u5173\u95ED ${B} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${B} \u4E2A\uFF0C${C} \u4E2A\u5931\u8D25\uFF09`;return`${I.larkAppId}: OK${O}`}).join(`
2
- `);alert(m||`Unexpected: ${JSON.stringify(P)}`),await o.onReloadGroups({force:!0})}catch(y){alert("Network error: "+y)}finally{o.onClose()}}async function G(){if(n.length===0||!confirm(`\u786E\u5B9A\u89E3\u6563\u7FA4\u804A\u300C${t.name??t.chatId}\u300D\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D\uFF0C\u672C\u7FA4\u6240\u6709\u673A\u5668\u4EBA\u4F1A\u8BDD\u4E5F\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))return;let g=[...n].sort((P,m)=>(m.larkAppId===a?1:0)-(P.larkAppId===a?1:0)),y=[];for(let P of g)try{let m=await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/disband`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppId:P.larkAppId})}),I=await m.json();if(I.ok){let v=I.closedSessions??[],C=v.filter(A=>!A.ok).length,B=v.length-C,O=v.length===0?"":C===0?`
3
- \u5173\u95ED\u4E86 ${B} \u4E2A\u4F1A\u8BDD\u3002`:`
4
- \u5173\u95ED\u4E86 ${B} \u4E2A\u4F1A\u8BDD\uFF0C${C} \u4E2A\u4F1A\u8BDD\u5173\u95ED\u5931\u8D25\u3002`;alert(`\u5DF2\u89E3\u6563\uFF08\u7531 ${P.botName??P.larkAppId} \u6267\u884C\uFF09${O}`),await o.onReloadGroups({force:!0}),o.onClose();return}y.push(`${P.botName??P.larkAppId}: ${I.error??m.status}`)}catch(m){y.push(`${P.botName??P.larkAppId}: ${m}`)}alert(`\u6240\u6709\u5728\u7FA4\u673A\u5668\u4EBA\u5747\u65E0\u6CD5\u89E3\u6563\uFF1A
5
- ${y.join(`
6
- `)}
7
-
8
- \u5EFA\u8BAE\u6539\u7528\u300C\u9000\u51FA\u7FA4\u804A\u300D\u3002`)}return(0,e.jsxs)("article",{className:"g-manage-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:r("groups.manageTitle",{name:t.name??t.chatId})})}),(0,e.jsxs)("div",{className:"g-manage-meta",children:[(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{children:"chatId"}),(0,e.jsx)("code",{children:t.chatId})]}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{children:r("groups.owner")}),(0,e.jsx)("code",{children:t.ownerId??r("common.unknown")})]})]}),(0,e.jsxs)("fieldset",{children:[(0,e.jsx)("legend",{children:r("groups.oncall")}),(0,e.jsx)("p",{children:(0,e.jsx)("small",{children:r("groups.oncallHelp")})}),n.length===0?(0,e.jsx)("p",{className:"empty",children:"\u6CA1\u6709\u673A\u5668\u4EBA\u5728\u7FA4\u91CC"}):n.map(g=>(0,e.jsx)(Ke,{chat:t,member:g,tr:r,onSaved:async()=>{await o.onReloadGroups({force:!0})}},g.larkAppId))]}),(0,e.jsxs)("fieldset",{children:[(0,e.jsx)("legend",{children:r("groups.leaveTitle")}),n.length===0?(0,e.jsx)("p",{className:"empty",children:"\u6CA1\u6709\u673A\u5668\u4EBA\u5728\u7FA4\u91CC"}):(0,e.jsx)("div",{className:"g-leave-picker",children:n.map(g=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"leave-bot",value:g.larkAppId,checked:c.has(g.larkAppId),onChange:y=>d(g.larkAppId,y.currentTarget.checked)}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:g.botName??g.larkAppId}),g.larkAppId===a?(0,e.jsx)("small",{children:"\xB7 \u7FA4\u4E3B"}):null]})]},g.larkAppId))})]}),(0,e.jsx)("p",{className:"g-manage-danger-hint",children:r("groups.dangerHint")}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:o.onClose,children:r("sessions.dismiss")}),(0,e.jsx)("button",{id:"g-leave-btn",type:"button",disabled:n.length===0,onClick:()=>{b()},children:r("groups.leaveSelected")}),(0,e.jsx)("button",{id:"g-disband-btn",type:"button",className:"contrast",disabled:n.length===0,onClick:()=>{G()},children:r("groups.disband")})]})]})}function Xe(o){let t=(0,i.useRef)(null);(0,i.useEffect)(()=>{let a=t.current;if(!a)return;let c=()=>o.onClose();return a.addEventListener("close",c),()=>a.removeEventListener("close",c)},[o.onClose]),(0,i.useEffect)(()=>{let a=t.current;a&&(o.dialog&&!a.open&&a.showModal(),!o.dialog&&a.open&&a.close())},[o.dialog]);let r=null;o.dialog?.type==="create"?r=(0,e.jsx)(Je,{bots:o.snapshot.bots,roleProfiles:o.dialog.roleProfiles,tr:o.tr,onClose:o.onClose,onCreated:o.onCreated,setTimer:o.setTimer}):o.dialog?.type==="add-bots"?r=(0,e.jsx)(ze,{chat:o.dialog.chat,bots:o.snapshot.bots,tr:o.tr,onClose:o.onClose,onReloadGroups:o.onReloadGroups}):o.dialog?.type==="save-profile"?r=(0,e.jsx)(Ve,{chat:o.dialog.chat,suggestedProfileId:o.dialog.suggestedProfileId,tr:o.tr,onClose:o.onClose,onRefreshRoleContext:o.onRefreshRoleContext,setTimer:o.setTimer}):o.dialog?.type==="manage"&&(r=(0,e.jsx)(Ze,{chat:o.dialog.chat,tr:o.tr,onClose:o.onClose,onReloadGroups:o.onReloadGroups}));let n=o.dialog?.type==="create"?"groups-create-modal":void 0;return(0,e.jsx)("dialog",{id:"g-drawer",className:n,ref:t,onMouseDown:a=>{a.target===a.currentTarget&&a.currentTarget.close()},children:r})}function Ye(){let o=me(),t=(0,i.useRef)(!1),r=(0,i.useRef)(J),n=(0,i.useRef)(new Set),a=(0,i.useRef)(new Map),c=(0,i.useRef)(0),[s,d]=(0,i.useState)(J),[b,G]=(0,i.useState)(()=>Be()),[g,y]=(0,i.useState)({q:"",missingOnly:!1}),[P,m]=(0,i.useState)(!0),[I,v]=(0,i.useState)(null),[C,B]=(0,i.useState)(!1),[O,A]=(0,i.useState)(null),[M,j]=(0,i.useState)(1),E=(0,i.useCallback)(l=>{d(f=>{let w=typeof l=="function"?l(f):l;return r.current=w,w})},[]),H=(0,i.useCallback)((l,f)=>{let w=window.setTimeout(()=>{n.current.delete(w),t.current&&l()},f);return n.current.add(w),w},[]),x=(0,i.useCallback)(l=>new Promise(f=>{let w=window.setTimeout(()=>{n.current.delete(w),a.current.delete(w),f()},l);n.current.add(w),a.current.set(w,f)}),[]),$=(0,i.useCallback)(async l=>{let f=++c.current;try{let w=await Pe(l??r.current);t.current&&f===c.current&&G(w)}catch{t.current&&f===c.current&&G({...Be(),loaded:!0})}},[]),D=(0,i.useCallback)(async l=>{let f=await z({force:l?.force});return t.current&&(E(f),v(null),$(f)),f},[$,E]),_=(0,i.useCallback)(async(l,f)=>{let w=[600,1200,1200,1200,1200,1200];for(let N of w){if(await x(N),!t.current)return;let T;try{T=await z({force:!0})}catch{continue}if(!t.current)return;let W=(T.chats??[]).find(q=>q.chatId===l);if(W&&Re(W,f)){E(T),$(T);return}}},[x,$,E]);(0,i.useEffect)(()=>(t.current=!0,(async()=>{m(!0);try{await D()}catch(l){t.current&&(E(J),v(l instanceof Error?l.message:String(l)),$(J))}finally{t.current&&m(!1)}})(),()=>{t.current=!1,c.current+=1;for(let l of n.current)window.clearTimeout(l);n.current.clear();for(let l of a.current.values())l();a.current.clear()}),[D]);let F=(0,i.useMemo)(()=>Ge(s.chats,g),[s.chats,g]),S=(0,i.useMemo)(()=>Ie(F,M),[F,M]);(0,i.useEffect)(()=>{M!==S.page&&j(S.page)},[M,S.page]);async function p(){B(!0);try{await D({force:!0})}catch(l){v(l instanceof Error?l.message:String(l))}finally{t.current&&B(!1)}}async function L(){if(r.current.bots.length===0){alert(o("groups.noBotsOnline"));return}let l=[];try{l=await K()}catch{}t.current&&A({type:"create",roleProfiles:l})}function U(l,f,w){let N=String(l.chatId),T=Array.isArray(l.invalidBotIds)?l.invalidBotIds:[],W=f.filter($e=>!T.includes($e)),q=new Set(W);typeof l.creator=="string"&&l.creator&&q.add(l.creator);let ae=Te(r.current,N,w||N,W,l.creator);E(ae),$(ae),_(N,q).catch(()=>{})}let u=(0,i.useCallback)(l=>{let f=new Set((l.memberBots??[]).filter(N=>N.inChat).map(N=>N.larkAppId));if(!r.current.bots.filter(N=>!f.has(N.larkAppId)).length){alert("All configured bots are already in this chat.");return}A({type:"add-bots",chat:l})},[]),h=(0,i.useCallback)(l=>{let f=oe(l.name??""),w=f==="profile"?oe(l.chatId):f;A({type:"save-profile",chat:l,suggestedProfileId:w})},[]),k=(0,i.useCallback)(l=>{A({type:"manage",chat:l})},[]);function R(l){let f=document.getElementById("g-body");f&&(f.scrollTop=0),j(l)}return(0,e.jsxs)("section",{className:"page groups-page",children:[(0,e.jsxs)("div",{className:"page-heading",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:o("nav.groups")}),(0,e.jsx)("h1",{children:o("groups.title")})]}),(0,e.jsx)("div",{className:"page-heading-actions",children:(0,e.jsx)(Y,{id:"g-create",className:"page-primary-action",onClick:()=>{L()},children:o("groups.create")})})]}),(0,e.jsxs)("form",{id:"g-filters",className:"filters dashboard-toolbar groups-toolbar",onSubmit:l=>l.preventDefault(),children:[(0,e.jsx)("input",{type:"search",name:"q",placeholder:o("groups.search"),value:g.q,onChange:l=>{let f=l.currentTarget.value;j(1),y(w=>({...w,q:f}))}}),(0,e.jsxs)("label",{className:"filter-toggle",children:[(0,e.jsx)("input",{type:"checkbox",name:"missing",checked:g.missingOnly,onChange:l=>{let f=l.currentTarget.checked;j(1),y(w=>({...w,missingOnly:f}))}}),(0,e.jsx)("span",{className:"filter-toggle-label",children:o("groups.missingOnly")}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"})]}),(0,e.jsx)("span",{className:"groups-toolbar-spacer","aria-hidden":"true"}),(0,e.jsxs)("span",{className:"groups-toolbar-count",children:[o("groups.matrixTitle")," ",P?"-/-":`${F.length}/${s.chats.length}`]}),(0,e.jsx)(ce,{id:"g-refresh",label:o("groups.refresh"),busy:C,disabled:C,onClick:()=>{p()}})]}),I?(0,e.jsxs)("p",{className:"hint-warn",children:["\u52A0\u8F7D\u7FA4\u7EC4\u5931\u8D25\uFF1A",I]}):null,(0,e.jsx)("section",{className:"overview-block groups-matrix-section",children:P?(0,e.jsx)("div",{id:"g-loading",children:(0,e.jsx)(X,{label:o("common.loading")})}):(0,e.jsxs)("div",{className:"groups-list-wrap",id:"g-table-wrap",children:[F.length===0?(0,e.jsx)("div",{className:"empty groups-list-empty",id:"g-body",children:o("groups.empty")}):(0,e.jsx)(ue,{id:"g-body",className:"groups-list",children:S.rows.map(l=>(0,e.jsx)(We,{chat:l,bots:s.bots,roleContext:b,tr:o,onAddBots:u,onSaveProfile:h,onManage:k},l.chatId))}),F.length>0&&S.totalPages>1?(0,e.jsxs)("nav",{className:"groups-pagination","aria-label":o("groups.paginationLabel"),children:[(0,e.jsx)("span",{className:"groups-pagination-status","aria-live":"polite",children:o("groups.pageStatus",{page:S.page,pages:S.totalPages,from:S.from,to:S.to,total:S.total})}),(0,e.jsxs)("div",{className:"groups-pagination-actions",children:[(0,e.jsx)("button",{type:"button",disabled:S.page<=1,onClick:()=>R(S.page-1),children:o("groups.prevPage")}),(0,e.jsx)("button",{type:"button",disabled:S.page>=S.totalPages,onClick:()=>R(S.page+1),children:o("groups.nextPage")})]})]}):null]})}),(0,e.jsx)(Xe,{dialog:O,snapshot:s,tr:o,onClose:()=>A(null),onCreated:U,onReloadGroups:D,onRefreshRoleContext:()=>$(),setTimer:H})]})}function ut(o){return ie(o,(0,e.jsx)(Ye,{}))}export{ut as renderGroupsPage};
@@ -1 +0,0 @@
1
- import{a as At,b as _t,c as Bt,d as Dt}from"./chunk-R3FXBFQH.js";import{c as Et}from"./chunk-HK7NIBJG.js";import{b as Ct,c as de,h as Ge,q as Fe}from"./chunk-5CJMHTT4.js";import{D as Tt,z as Lt}from"./chunk-6J5LS5AU.js";import{a as De}from"./chunk-SYC6D5XU.js";import{a as cn,d as Mt}from"./chunk-5THX4DI2.js";import{c as Be}from"./chunk-7SZRL6FY.js";var a=Be(cn(),1);function Ft(t,n){let r=n.trim().toLowerCase();return r?t.filter(o=>o.openId.toLowerCase().includes(r)||o.name.toLowerCase().includes(r)||o.memberType.toLowerCase().includes(r)):t}function Gt(t){return[...new Set([...t].filter(Boolean))]}function $t(t){let n=new Set(t.targetIds.filter(Boolean));if(t.mode==="all_except_excluded"){let o=new Set(t.exclude);for(let c of n)o.delete(c),t.listening||o.add(c);return{include:[],exclude:Gt(o)}}let r=new Set(t.include);for(let o of n)r.delete(o),t.listening&&r.add(o);return{include:Gt(r),exclude:[]}}function $e(t){let n=t.targetIds.filter(Boolean);if(n.length===0)return t.mode==="all_except_excluded"?"listen":"ignore";let r=new Set;if(t.mode==="all_except_excluded"){let o=new Set(t.exclude);for(let c of n)r.add(o.has(c)?"ignore":"listen")}else{let o=new Set(t.include);for(let c of n)r.add(o.has(c)?"listen":"ignore")}return r.size===1?[...r][0]:"mixed"}function Ot(t,n,r){let o={};for(let c of t){if(!c)continue;let f=n(c),m=f==="user"||f==="bot"?f:r?.[c];(m==="user"||m==="bot")&&(o[c]=m)}return o}var O=32768,Ut=Math.floor(O*.95),ue=32768,jt=Math.floor(ue*.95),Oe=5,Ue=20,un=/^[A-Za-z0-9._-]{1,64}$/;function je(t){return un.test(t)&&t!=="."&&t!==".."}function Ht(t=location.hash){let[,n=""]=t.split("?");return new URLSearchParams(n).get("chatId")?.trim()||null}function He(t,n){return Bt(t,n)}function Pe(t){return new TextEncoder().encode(t).length}function Vt(t){return t.memberBots.filter(n=>n.inChat&&n.hasRole).length}function qt(t){return t.memberBots.filter(n=>n.inChat).length}function pe(t,n){return n?t.find(r=>r.larkAppId===n):void 0}function Kt(t,n){let r=n.toLowerCase();return r?t.filter(o=>{let c=o.chatId.toLowerCase().includes(r)||(o.name??"").toLowerCase().includes(r),f=o.memberBots.some(m=>m.larkAppId.toLowerCase().includes(r)||(m.botName??"").toLowerCase().includes(r));return c||f}):t}function Wt(t,n){let r=n.toLowerCase();return t.filter(o=>!r||o.profileId.toLowerCase().includes(r))}async function x(t){return t.json().catch(()=>({}))}async function Yt(){let t=await fetch("/api/groups"),n=await x(t);return{bots:(n.bots??[]).map(r=>({larkAppId:r.larkAppId,botName:r.botName??r.larkAppId,botAvatarUrl:r.botAvatarUrl})),groups:(n.chats??[]).map(r=>({chatId:r.chatId,name:r.name??r.chatId,memberBots:(r.memberBots??[]).map(o=>({larkAppId:o.larkAppId,botName:o.botName??o.larkAppId,inChat:o.inChat??!1,hasRole:o.hasRole??!1,hasMessageListener:o.hasMessageListener??!1,oncallChat:o.oncallChat??null}))}))}}async function zt(){let t=await fetch("/api/role-profiles");return(await x(t)).profiles??[]}async function q(t){let n=await fetch(`/api/role-profiles/${encodeURIComponent(t)}`);return(await x(n)).entries??[]}async function Ve(t,n){let r=await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`);return x(r)}async function Jt(t,n,r,o){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:r,injectMode:o})})).ok}async function Xt(t,n,r){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({injectMode:r})})).ok}async function Qt(t,n){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"DELETE"})).ok}async function qe(t,n){let r=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}`);return(await x(r)).listener??{enabled:!1,prompt:"",messagePolicy:{scope:"top_level"}}}async function Zt(t,n,r){return(await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(r)})).ok}async function er(t,n){return(await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"DELETE"})).ok}function he(t){return Number.isFinite(t)?Math.min(Ue,Math.max(1,Math.floor(t))):Oe}function ce(t){return String(t).padStart(2,"0")}function tr(t){if(!t)return"";let n=Number(t);if(!Number.isFinite(n)||n<=0)return"";let r=n<1e12?n*1e3:n,o=new Date(r);return Number.isFinite(o.getTime())?[o.getFullYear(),"-",ce(o.getMonth()+1),"-",ce(o.getDate())," ",ce(o.getHours()),":",ce(o.getMinutes()),":",ce(o.getSeconds())].join(""):""}async function rr(t,n,r,o){let c=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({listener:r,limit:he(o)})}),f=await x(c);return{ok:c.ok&&f.ok!==!1,requestedLimit:f.requestedLimit??he(o),matches:f.matches??[],error:f.error}}async function nr(t,n,r,o){let c=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}/run-preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({listener:r,limit:he(o)})}),f=await x(c);return{ok:c.ok&&f.ok!==!1,requestedLimit:f.requestedLimit??he(o),matches:f.matches??[],results:f.results,error:f.error}}async function sr(t,n,r){let o=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}/run-preview/${encodeURIComponent(r)}`),c=await x(o);return{ok:o.ok&&c.ok!==!1,runId:c.runId,results:c.results,error:c.error}}async function or(t,n){let r=await fetch(`/api/groups/${encodeURIComponent(t)}/${encodeURIComponent(n)}/members-display`);return(await x(r)).members??[]}async function lr(t,n){let r=await fetch(`/api/role-profiles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`);return x(r)}async function ir(t,n,r){return(await fetch(`/api/role-profiles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:r,allowEmpty:!0})})).ok}async function ar(t,n){return(await fetch(`/api/role-profiles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"DELETE"})).ok}async function dr(t,n){let r=await Promise.all(n.map(async m=>{try{let p=await fetch(`/api/role-profiles/${encodeURIComponent(m.profileId)}`),y=await x(p);return[m.profileId,Array.isArray(y.entries)?y.entries:[]]}catch{return[m.profileId,[]]}})),o=new Set,c=[];for(let m of t)for(let p of m.memberBots){if(!p.inChat||!p.hasRole)continue;let y=He(p.larkAppId,m.chatId);o.has(y)||(o.add(y),c.push({larkAppId:p.larkAppId,chatId:m.chatId}))}let f=await Dt(c);return{entriesByProfile:new Map(r),effectiveRolesByBot:f}}async function cr(t){let n=await fetch(`/api/role-profiles/${encodeURIComponent(t.profileId)}/apply`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({chatId:t.chatId,larkAppId:t.larkAppId,force:t.force,preview:t.preview})}),r=await x(n);return{larkAppId:t.larkAppId,ok:n.ok&&r.ok!==!1,status:n.status,error:r.error,wouldRefuse:r.wouldRefuse}}var e=Be(Mt(),1),fr=["text","post","image","interactive"],K={enabled:!1,prompt:"",senderPolicy:{mode:"include_only",includeSenderTypes:["user"],excludeSelf:!0},messagePolicy:{includeMsgTypes:[...fr],scope:"top_level"}};function We(t){let n=t?.senderPolicy?.mode==="include_only"?"include_only":"all_except_excluded";return{enabled:t?.enabled===!0,name:t?.name??"",replyCardTitle:t?.replyCardTitle??"",workingDir:t?.workingDir??"",prompt:t?.prompt??"",senderPolicy:{mode:n,includeSenderOpenIds:[...t?.senderPolicy?.includeSenderOpenIds??[]],excludeSenderOpenIds:[...t?.senderPolicy?.excludeSenderOpenIds??[]],...t?.senderPolicy?.excludeSenderKinds?{excludeSenderKinds:{...t.senderPolicy.excludeSenderKinds}}:{},includeSenderTypes:[...t?.senderPolicy?.includeSenderTypes??K.senderPolicy?.includeSenderTypes??[]],excludeSenderTypes:[...t?.senderPolicy?.excludeSenderTypes??[]],excludeSelf:t?.senderPolicy?.excludeSelf!==!1},messagePolicy:{includeMsgTypes:[...t?.messagePolicy?.includeMsgTypes??K.messagePolicy?.includeMsgTypes??[]],scope:"top_level"}}}function ur(t){return!!t&&t.prompt.trim().length>0}function pn(t){return t.memberBots.some(n=>n.inChat&&(n.hasRole||n.hasMessageListener))}function Ke(t,n){return t?.name||n}function mn(t,n){let r=new Map;for(let o of t??[])r.set(o.messageId,o);for(let o of n)r.set(o.messageId,{...r.get(o.messageId),...o});return[...r.values()]}function fn(t,n){return!n||t==="failed"?"error":t==="replied"?"ok":t==="running"?"running":"triggered"}function gn(t,n=[]){return We(t??K)}function yn(){let t=(0,a.useRef)(!0);return(0,a.useEffect)(()=>(t.current=!0,()=>{t.current=!1}),[]),t}function vn(){let t=(0,a.useRef)(new Set);return(0,a.useEffect)(()=>()=>{for(let n of t.current)window.clearTimeout(n);t.current.clear()},[]),(0,a.useCallback)((n,r)=>{let o=window.setTimeout(()=>{t.current.delete(o),n()},r);return t.current.add(o),o},[])}function gr(t){return(0,e.jsx)(Ct,{html:Lt({name:t.bot.botName,larkAppId:t.bot.larkAppId,avatarUrl:t.bot.botAvatarUrl,size:"sm"})})}function yr(t){let n=Et(),r=yn(),o=vn(),[c,f]=(0,a.useState)([]),[m,p]=(0,a.useState)([]),[y,L]=(0,a.useState)([]),[Se,R]=(0,a.useState)({entriesByProfile:new Map,effectiveRolesByBot:new Map}),[W,A]=(0,a.useState)(!1),[we,Y]=(0,a.useState)(!0),[xe,_]=(0,a.useState)(!0),[F,k]=(0,a.useState)(""),[z,me]=(0,a.useState)(""),[U,B]=(0,a.useState)(()=>new Set),[g,fe]=(0,a.useState)(null),[v,J]=(0,a.useState)(null),[d,b]=(0,a.useState)(null),[I,T]=(0,a.useState)(""),[X,Q]=(0,a.useState)("every"),[Ye,ze]=(0,a.useState)(!1),[Je,Xe]=(0,a.useState)(!1),[vr,Qe]=(0,a.useState)(!1),[br,Re]=(0,a.useState)(null),[hr,Ze]=(0,a.useState)(null),[j,et]=(0,a.useState)("role"),[Pr,Ir]=(0,a.useState)(null),[P,D]=(0,a.useState)(()=>We(K)),[ke,tt]=(0,a.useState)([]),[Sr,rt]=(0,a.useState)(!1),[wr,nt]=(0,a.useState)(!1),[st,ot]=(0,a.useState)(!1),[Ne,lt]=(0,a.useState)(!1),[xr,G]=(0,a.useState)(null),[Le,Rr]=(0,a.useState)(Oe),[kr,ge]=(0,a.useState)({kind:"idle"}),Z=(0,a.useRef)(null),it=(0,a.useRef)(0),[S,Nr]=(0,a.useState)(null),[C,at]=(0,a.useState)(null),[ee,te]=(0,a.useState)([]),[re,ye]=(0,a.useState)(""),[$,ne]=(0,a.useState)(null),[dt,Lr]=(0,a.useState)(!1),[ct,ut]=(0,a.useState)(()=>new Set),[pt,mt]=(0,a.useState)(!1),[ft,gt]=(0,a.useState)(!1),[Tr,Te]=(0,a.useState)(null),[Mr,se]=(0,a.useState)({kind:"idle"}),H=(0,a.useRef)(0),oe=(0,a.useRef)(0),yt=(0,a.useRef)(null),Me=g?c.find(s=>s.chatId===g):void 0,Cr=Me&&v?Me.memberBots.find(s=>s.larkAppId===v):void 0,Ce=C?m.find(s=>s.larkAppId===C):void 0,Er=pe(ee,C),Ee=$?c.find(s=>s.chatId===$):void 0,ve=Ee?.memberBots.filter(s=>s.inChat)??[],Ar=ve.map(s=>s.larkAppId).join("\0"),_r=ee.map(s=>s.larkAppId).sort().join("\0"),Br=(0,a.useMemo)(()=>Kt(c,F),[c,F]),Dr=(0,a.useMemo)(()=>Wt(y,z),[y,z]),Ae=Pe(I),_e=Pe(re),vt=Pe(P.prompt),bt=(0,a.useMemo)(()=>{let s=new Map;for(let l of ke)s.set(l.openId,l);return s},[ke]),M=(0,a.useCallback)((s,l,i=!1)=>{let u=Date.now()+Math.random();s({text:l,isError:i,id:u}),o(()=>{s(h=>h?.id===u?null:h)},i?3e3:2e3)},[o]),N=(0,a.useCallback)(async(s,l)=>{try{let i=await dr(s,l);if(!r.current)return;R(i),A(!0)}catch{if(!r.current)return;R({entriesByProfile:new Map,effectiveRolesByBot:new Map}),A(!0)}},[r]),E=(0,a.useCallback)(async()=>{let s=await Yt();return r.current&&(f(s.groups),p(s.bots)),s},[r]),le=(0,a.useCallback)(async()=>{let s=await zt();return r.current&&L(s),s},[r]),ie=(0,a.useCallback)((s,l=[])=>{let i=gn(s??K,l);Ir(s),D(i)},[]),ht=(0,a.useCallback)(async(s,l,i)=>{rt(!0),nt(!0),tt([]);try{let[u,h]=await Promise.all([qe(s,l).catch(()=>We(K)),or(s,l).catch(()=>[])]);if(!r.current||i!==H.current)return;ie(ur(u)?u:null,h),tt(h),G(null)}finally{r.current&&i===H.current&&(rt(!1),nt(!1))}},[r,ie]),Pt=(0,a.useCallback)(async()=>{Y(!0),_(!0),A(!1);try{let s=await E();if(!r.current)return;let l=await le();if(!r.current||(await Tt(),!r.current))return;if(B(new Set(s.groups.filter(pn).map(i=>i.chatId))),t.tab==="profiles"){let i=Ht();ne(u=>u||(i&&s.groups.some(h=>h.chatId===i)?i:s.groups[0]?.chatId??null))}else ne(i=>i??s.groups[0]?.chatId??null);Y(!1),_(!1),N(s.groups,l)}catch{if(!r.current)return;Y(!1),_(!1),A(!0)}},[r,t.tab,E,le,N]);(0,a.useEffect)(()=>{Pt()},[Pt]),(0,a.useEffect)(()=>()=>{it.current+=1,Z.current=null},[]),(0,a.useEffect)(()=>{$||c.length===0||ne(c[0].chatId)},[c,$]),(0,a.useEffect)(()=>{let s=new Set(ve.filter(l=>!!pe(ee,l.larkAppId)).map(l=>l.larkAppId));ut(s),se({kind:"idle"})},[_r,Ar]);async function Gr(s,l){let i=++H.current;fe(s),J(l),Re(null),Ze(null),G(null),ie(null);let u=await Ve(l,s);!r.current||i!==H.current||(b(u),T(u.content??""),Q(u.injectMode==="once"?"once":"every"),await ht(l,s,i))}async function Fr(){let s=await E();if(r.current&&(N(s.groups,y),g&&v)){let l=++H.current,i=await Ve(v,g);if(!r.current||l!==H.current)return;b(i),T(i.content??""),Q(i.injectMode==="once"?"once":"every"),await ht(v,g,l)}}async function $r(){if(!(!g||!v)){ze(!0);try{let s=await Jt(v,g,I,X);if(!r.current)return;if(s){let l=await E();if(!r.current)return;b(i=>i&&{...i,content:I,hasRole:!0,injectMode:X}),N(l.groups,y),M(Re,n("roles.saved"))}else M(Re,I.trim().length===0?n("roles.emptyError"):n("roles.saveFailed"),!0)}finally{r.current&&ze(!1)}}}async function Or(){if(!(!g||!v)&&confirm(n("roles.confirmDelete"))){Xe(!0);try{let s=await Qt(v,g);if(!r.current)return;if(s){let l=await E();if(!r.current)return;fe(null),J(null),b(null),T(""),Q("every"),N(l.groups,y)}}finally{r.current&&Xe(!1)}}}async function Ur(s){if(!g||!v)return;let l=X;Q(s),Qe(!0);try{let i=await Xt(v,g,s);if(!r.current)return;i||Q(l),M(Ze,n(i?"roles.saved":"roles.saveFailed"),!i)}finally{r.current&&Qe(!1)}}function jr(s){D(l=>({...l,...s}))}function Hr(s){D(l=>({...l,senderPolicy:{...l.senderPolicy??{},...s}}))}function Vr(s){D(l=>({...l,messagePolicy:{...l.messagePolicy??{scope:"top_level"},...s,scope:"top_level"}}))}function qr(s,l){D(i=>{let u=new Set(i.senderPolicy?.includeSenderTypes??[]);if(l)u.add(s);else{if(u.size<=1&&u.has(s))return i;u.delete(s)}return{...i,senderPolicy:{...i.senderPolicy??{},includeSenderTypes:[...u]}}})}function Kr(s,l){D(i=>{let u=new Set(i.messagePolicy?.includeMsgTypes??[]);if(l)u.add(s);else{if(u.size<=1&&u.has(s))return i;u.delete(s)}return{...i,messagePolicy:{...i.messagePolicy??{scope:"top_level"},includeMsgTypes:[...u],scope:"top_level"}}})}function It(s,l){D(i=>{let u=i.senderPolicy?.mode==="all_except_excluded"?"all_except_excluded":"include_only",h=$t({mode:u,include:i.senderPolicy?.includeSenderOpenIds??[],exclude:i.senderPolicy?.excludeSenderOpenIds??[],targetIds:s,listening:l});return{...i,senderPolicy:{...i.senderPolicy??{},mode:u,includeSenderOpenIds:h.include,excludeSenderOpenIds:h.exclude}}})}function Wr(s,l){It([s],l)}function Yr(s,l){It(s,l)}function zr(s){D(l=>({...l,senderPolicy:{...l.senderPolicy??{},mode:s,includeSenderOpenIds:[...l.senderPolicy?.includeSenderOpenIds??[]],excludeSenderOpenIds:[...l.senderPolicy?.excludeSenderOpenIds??[]]}}))}function St(){let s=P.senderPolicy??{},l=P.messagePolicy??{},i=s.mode==="all_except_excluded"?"all_except_excluded":"include_only",u=[...new Set(s.includeSenderOpenIds??[])].filter(Boolean),h=[...new Set(s.excludeSenderOpenIds??[])].filter(Boolean),ae=Ot(h,be=>bt.get(be)?.memberType,s.excludeSenderKinds),w=[...new Set(s.includeSenderTypes??[])].filter(be=>be==="user"||be==="bot"),Nt=[...new Set(l.includeMsgTypes??[])].filter(Boolean);return{enabled:P.enabled,...P.name?.trim()?{name:P.name.trim()}:{},...P.replyCardTitle?.trim()?{replyCardTitle:P.replyCardTitle.trim()}:{},...P.workingDir?.trim()?{workingDir:P.workingDir.trim()}:{},prompt:P.prompt.trim(),senderPolicy:{mode:i,...i==="include_only"&&u.length>0?{includeSenderOpenIds:u}:{},...i==="all_except_excluded"&&h.length>0?{excludeSenderOpenIds:h}:{},...i==="all_except_excluded"&&Object.keys(ae).length>0?{excludeSenderKinds:ae}:{},...w.length>0?{includeSenderTypes:w}:{},excludeSelf:s.excludeSelf!==!1},messagePolicy:{...Nt.length>0?{includeMsgTypes:Nt}:{},scope:"top_level"}}}function Jr(){return P.prompt.trim()?P.senderPolicy?.mode!=="all_except_excluded"&&(P.senderPolicy?.includeSenderOpenIds?.length??0)===0?(M(G,n("roles.listenerSenderRequired"),!0),null):{...St(),enabled:!0}:(M(G,n("roles.listenerPromptRequired"),!0),null)}async function wt(s){if(!g||!v)return;let l=Jr();if(!l)return;let i=s?"run":"preview";ge({kind:"loading",mode:i});try{let u=s?await nr(v,g,l,Le):await rr(v,g,l,Le);if(!r.current)return;ge(u.ok?{kind:"result",response:u,mode:i}:{kind:"error",text:u.error||n("roles.listenerPreviewFailed")}),u.ok&&s&&u.runId&&Xr(u.runId)}catch(u){if(!r.current)return;ge({kind:"error",text:u instanceof Error?u.message:n("roles.listenerPreviewFailed")})}}function Xr(s){if(!g||!v)return;let l=++it.current;Z.current={runId:s,token:l};let i=async()=>{if(!r.current)return;let u=Z.current;if(!(!u||u.runId!==s||u.token!==l||!g||!v))try{let h=await sr(v,g,s);if(!r.current)return;if(h.ok&&h.results){let ae=h.results;ge(w=>w.kind!=="result"||w.mode!=="run"||w.response.runId!==s?w:{...w,response:{...w.response,results:mn(w.response.results,ae)}}),ae.some(w=>w.state==="triggered"||w.state==="running")?o(i,1500):Z.current?.runId===s&&(Z.current=null)}}catch{o(i,2500)}};o(i,1500)}async function Qr(){if(!(!g||!v)){if(!P.enabled&&!P.prompt.trim()){await xt(!1);return}if(P.enabled){if(!P.prompt.trim()){M(G,n("roles.listenerPromptRequired"),!0);return}if(P.senderPolicy?.mode!=="all_except_excluded"&&(P.senderPolicy?.includeSenderOpenIds?.length??0)===0){M(G,n("roles.listenerSenderRequired"),!0);return}}ot(!0);try{let s=await Zt(v,g,St());if(!r.current)return;if(s){let l=await E();if(!r.current)return;let i=await qe(v,g);if(!r.current)return;ie(ur(i)?i:null),N(l.groups,y)}M(G,n(s?"roles.saved":"roles.saveFailed"),!s)}finally{r.current&&ot(!1)}}}async function xt(s=!0){if(!(!g||!v)&&!(s&&!confirm(n("roles.listenerConfirmDelete")))){lt(!0);try{let l=await er(v,g);if(!r.current)return;if(l){let i=await E();if(!r.current)return;ie(null),N(i.groups,y)}M(G,n(l?"roles.saved":"roles.saveFailed"),!l)}finally{r.current&&lt(!1)}}}async function Rt(s){let l=s.trim();if(!je(l))return;let i=++oe.current;Nr(l),at(null),ye(""),se({kind:"idle"}),ne(h=>h??c[0]?.chatId??null);let u=await q(l);!r.current||i!==oe.current||(te(u),Te(null))}async function Zr(s){if(!S)return;let l=++oe.current;at(s);let i=await lr(S,s);if(!r.current||l!==oe.current)return;ye(i.content??"");let u=await q(S);!r.current||l!==oe.current||(te(u),Te(null))}async function en(){let s=await E();if(!r.current)return;let l=await le();if(r.current){if(S){let i=await q(S);if(!r.current)return;te(i)}N(s.groups,l)}}async function tn(){let s=yt.current,l=s?.value.trim()??"";if(l){if(!je(l)){s?.setCustomValidity(n("roles.profileIdInvalid")),s?.reportValidity();return}s?.setCustomValidity(""),await Rt(l),r.current&&(location.hash.startsWith("#/roles/profile")||(location.hash="#/roles/profile"))}}async function rn(){if(!(!S||!C)){mt(!0);try{let s=await ir(S,C,re);if(!r.current)return;let l=await le();if(!r.current)return;let i=await q(S);if(!r.current)return;te(i),N(c,l),M(Te,n(s?"roles.saved":"roles.saveFailed"),!s)}finally{r.current&&mt(!1)}}}async function nn(){if(!(!S||!C)&&confirm(n("roles.confirmDeleteProfileEntry"))){gt(!0);try{if(await ar(S,C),!r.current)return;ye("");let s=await le();if(!r.current)return;let l=await q(S);if(!r.current)return;te(l),N(c,s)}finally{r.current&&gt(!1)}}}function sn(s,l){ut(i=>{let u=new Set(i);return l?u.add(s):u.delete(s),u})}async function kt(s){if(!S)return;let l=$??c[0]?.chatId;if(!l)return;let i=[...ct];if(i.length===0){se({kind:"text",text:n("roles.applyPickBots")});return}se({kind:"text",text:"..."});let u=await Promise.all(i.map(h=>cr({profileId:S,chatId:l,larkAppId:h,force:dt,preview:s})));if(r.current&&(se({kind:"results",preview:s,results:u}),!s)){let h=await E();if(!r.current)return;N(h.groups,y)}}let on=Ye||Ae>O||I.trim().length===0,ln=st||Ne||vt>ue||P.enabled&&P.prompt.trim().length===0,an=pt||_e>O||re.trim().length===0,V=t.tab==="profiles",dn=(0,e.jsxs)("nav",{className:"roles-subnav insight-tabs",role:"tablist","aria-label":n("roles.title"),children:[(0,e.jsx)("a",{href:"#/roles",className:`itab${V?"":" on"}`,role:"tab","aria-selected":!V,children:n("roles.tabGroups")}),(0,e.jsx)("a",{href:"#/roles/profile",className:`itab${V?" on":""}`,role:"tab","aria-selected":V,children:n("roles.tabProfiles")})]});return(0,e.jsxs)("section",{className:"page roles-page",children:[(0,e.jsxs)("div",{className:"page-heading roles-heading",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:n("nav.roles")}),(0,e.jsx)("h1",{children:n("roles.title")})]}),(0,e.jsx)("div",{className:"page-heading-actions",children:dn})]}),(0,e.jsxs)("div",{id:"roles-by-group-view",className:"roles-layout",hidden:V,children:[(0,e.jsxs)("div",{className:"roles-tree-panel",children:[(0,e.jsxs)("div",{className:"roles-tree-header dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",id:"roles-search",placeholder:n("roles.search"),value:F,onChange:s=>k(s.target.value)}),(0,e.jsx)(Ge,{id:"roles-refresh",label:n("roles.refresh"),onClick:()=>{Fr()}})]}),(0,e.jsx)("div",{id:"roles-tree",className:"roles-tree",children:we?(0,e.jsx)(de,{label:n("common.loading")}):(0,e.jsx)(Pn,{groups:Br,profiles:y,context:Se,contextLoaded:W,expandedGroups:U,selectedGroupId:g,selectedBotId:v,tr:n,onToggleGroup:s=>B(l=>bn(l,s)),onSelectBot:(s,l)=>{Gr(s,l)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:!g||!v?(0,e.jsx)("div",{id:"roles-editor-empty",className:"roles-editor-empty",children:n("roles.selectHint")}):(0,e.jsxs)("div",{id:"roles-editor-form",className:"roles-editor-form",children:[(0,e.jsxs)("div",{className:"roles-editor-head",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"roles-editor-breadcrumb",children:[(0,e.jsx)("span",{id:"roles-editor-group-name",children:Me?.name??g}),(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{id:"roles-editor-bot-name",children:Cr?.botName??v})]}),(0,e.jsx)("div",{className:"roles-editor-meta",children:(0,e.jsxs)("span",{id:"roles-editor-chat-id",className:"roles-editor-meta-line",children:[g," \xB7 ",v]})})]}),(0,e.jsx)("div",{className:"roles-editor-actions roles-editor-head-actions",children:j==="role"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",id:"roles-delete",className:"danger",style:{display:d?.hasRole?"":"none"},disabled:Je,onClick:()=>{Or()},children:Je?"...":n("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-save",className:"primary",disabled:on,onClick:()=>{$r()},children:Ye?"...":n("roles.save")})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",id:"roles-listener-delete",className:"danger",style:{display:Pr?"":"none"},disabled:Ne,onClick:()=>{xt()},children:Ne?"...":n("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-listener-save",className:"primary",disabled:ln,onClick:()=>{Qr()},children:st?"...":n("roles.save")})]})})]}),(0,e.jsxs)("div",{className:"roles-editor-switch segmented",role:"tablist","aria-label":n("roles.editorTabs"),children:[(0,e.jsx)("button",{type:"button",className:j==="role"?"active":"","aria-pressed":j==="role",onClick:()=>et("role"),children:n("roles.roleTab")}),(0,e.jsx)("button",{type:"button",className:j==="listener"?"active":"","aria-pressed":j==="listener",onClick:()=>et("listener"),children:n("roles.listenerTab")})]}),j==="role"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"roles-editor-inject",children:[(0,e.jsx)("span",{className:"roles-field-label",children:n("roles.injectModeLabel")}),(0,e.jsx)(Fe,{id:"roles-editor-inject-mode",className:"roles-inline-menu",ariaLabel:n("roles.injectModeLabel"),disabled:vr,label:n(X==="once"?"roles.injectModeOnce":"roles.injectModeEvery"),value:X,options:[{value:"every",label:n("roles.injectModeEvery")},{value:"once",label:n("roles.injectModeOnce")}],onChange:s=>{Ur(s==="once"?"once":"every")}}),(0,e.jsx)("span",{className:"roles-editor-inject-hint",children:n("roles.injectModeHint")}),(0,e.jsx)(Ie,{flash:hr})]}),(0,e.jsx)("textarea",{id:"roles-editor-textarea",placeholder:n("roles.editorPlaceholder"),rows:14,value:I,onChange:s=>T(s.target.value)}),(0,e.jsxs)("div",{className:"roles-editor-footer",children:[(0,e.jsxs)("span",{id:"roles-editor-bytecount",className:pr(Ae),children:[Ae," / ",O," bytes"]}),(0,e.jsx)(Ie,{flash:br})]}),(0,e.jsx)(mr,{content:I,tr:n,id:"roles-preview"})]}):(0,e.jsx)(Sn,{listener:P,members:ke,memberById:bt,promptByteLen:vt,loading:Sr,membersLoading:wr,flash:xr,tr:n,onPatch:jr,onSenderPolicyPatch:Hr,onMessagePolicyPatch:Vr,onToggleSenderType:qr,onToggleMsgType:Kr,onSetTargetPolicy:Wr,onSetTargetsPolicy:Yr,onSetSenderMode:zr,previewLimit:Le,previewStatus:kr,onPreviewLimitChange:Rr,onPreview:()=>{wt(!1)},onRunPreview:()=>{wt(!0)}})]})})]}),(0,e.jsxs)("div",{id:"roles-profiles-view",className:"roles-layout roles-profiles-layout",hidden:!V,children:[(0,e.jsxs)("div",{className:"roles-tree-panel",children:[(0,e.jsxs)("div",{className:"roles-tree-header roles-profile-create dashboard-toolbar",children:[(0,e.jsx)("input",{type:"text",id:"roles-profile-id",placeholder:n("roles.profileIdPlaceholder"),maxLength:64,ref:yt,onChange:s=>s.currentTarget.setCustomValidity("")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-select",onClick:()=>{tn()},children:n("roles.openProfile")})]}),(0,e.jsxs)("div",{className:"roles-tree-header dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",id:"roles-profile-search",placeholder:n("roles.profileSearch"),value:z,onChange:s=>me(s.target.value)}),(0,e.jsx)(Ge,{id:"roles-profile-refresh",label:n("roles.refresh"),onClick:()=>{en()}})]}),(0,e.jsx)("div",{id:"roles-profile-list",className:"roles-tree",children:xe?(0,e.jsx)(de,{label:n("common.loading")}):(0,e.jsx)(Rn,{profiles:Dr,selectedProfileId:S,tr:n,onSelect:s=>{Rt(s)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:S?(0,e.jsxs)("div",{id:"roles-profile-detail",className:"roles-editor-form roles-profile-detail",children:[(0,e.jsx)("div",{className:"roles-profile-title",children:(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"roles-editor-breadcrumb",children:[(0,e.jsx)("span",{children:S}),Ce?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{children:Ce.botName??Ce.larkAppId})]}):null]}),(0,e.jsx)("div",{className:"roles-editor-meta-line",children:n("roles.profileRuntimeHint")})]})}),(0,e.jsxs)("div",{className:"roles-profile-grid",children:[(0,e.jsxs)("div",{className:"roles-profile-bots",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:n("roles.profileBots")}),(0,e.jsx)("div",{className:"roles-profile-bot-list",children:m.map(s=>{let l=!!pe(ee,s.larkAppId),i=C===s.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row roles-profile-bot-row ${i?"selected":""}`,"data-profile-bot-id":s.larkAppId,onClick:()=>{Zr(s.larkAppId)},children:[(0,e.jsx)(gr,{bot:s}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:s.botName??s.larkAppId}),(0,e.jsx)("div",{className:"roles-bot-id",children:s.larkAppId})]}),(0,e.jsx)("span",{className:`roles-badge ${l?"has-role":"no-role"}`,children:n(l?"roles.configured":"roles.unconfigured")})]},s.larkAppId)})})]}),(0,e.jsx)("div",{className:"roles-profile-editor",children:C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"roles-profile-editor-head",children:[(0,e.jsxs)("span",{id:"roles-profile-bytecount",className:pr(_e),children:[_e," / ",O," bytes"]}),(0,e.jsxs)("div",{className:"roles-editor-actions roles-editor-head-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-profile-delete",className:"danger",style:{display:Er?"":"none"},disabled:ft,onClick:()=>{nn()},children:ft?"...":n("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-save",className:"primary",disabled:an,onClick:()=>{rn()},children:pt?"...":n("roles.saveEntry")})]})]}),(0,e.jsx)("textarea",{id:"roles-profile-textarea",placeholder:n("roles.profileEditorPlaceholder"),rows:12,value:re,onChange:s=>ye(s.target.value)}),(0,e.jsx)("div",{className:"roles-editor-footer",children:(0,e.jsx)(Ie,{flash:Tr})}),(0,e.jsx)(mr,{content:re,tr:n,id:"roles-profile-preview"})]}):(0,e.jsx)("div",{className:"roles-editor-empty roles-profile-inline-empty",children:n("roles.profileBotSelectHint")})})]}),(0,e.jsxs)("div",{className:"roles-profile-apply",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:n("roles.applyToGroup")}),(0,e.jsxs)("div",{className:"roles-profile-apply-controls",children:[(0,e.jsx)(Fe,{id:"roles-profile-apply-group",className:"roles-apply-group-menu",ariaLabel:n("roles.applyToGroup"),disabled:c.length===0,label:Ee?.name??$??n("roles.noChats"),value:$??"",options:c.map(s=>({value:s.chatId,label:s.name??s.chatId})),onChange:s=>ne(s)}),(0,e.jsxs)("label",{className:"roles-profile-force",children:[(0,e.jsx)("input",{type:"checkbox",id:"roles-profile-apply-force",checked:dt,onChange:s=>Lr(s.target.checked)})," ",n("roles.applyForce")]})]}),(0,e.jsx)("div",{id:"roles-profile-apply-bots",children:!Ee||ve.length===0?(0,e.jsx)("div",{className:"roles-empty",children:n("roles.noChats")}):ve.map(s=>{let l=!!pe(ee,s.larkAppId);return(0,e.jsxs)("label",{className:"checkbox-row roles-profile-apply-bot",children:[(0,e.jsx)("input",{type:"checkbox",name:"profile-apply-bot",value:s.larkAppId,checked:ct.has(s.larkAppId),onChange:i=>sn(s.larkAppId,i.target.checked)}),(0,e.jsx)("span",{children:s.botName??s.larkAppId}),(0,e.jsx)("small",{children:n(l?"roles.configured":"roles.profileMissing")})]},s.larkAppId)})}),(0,e.jsxs)("div",{className:"roles-editor-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-profile-preview-apply",onClick:()=>{kt(!0)},children:n("roles.previewApply")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-apply",className:"primary",onClick:()=>{kt(!1)},children:n("roles.applyProfile")})]}),(0,e.jsx)("div",{id:"roles-profile-apply-status",className:"roles-profile-status",children:(0,e.jsx)(kn,{status:Mr,bots:m,tr:n})})]})]}):(0,e.jsx)("div",{id:"roles-profile-empty",className:"roles-editor-empty",children:n("roles.profileSelectHint")})})]})]})}function bn(t,n){let r=new Set(t);return r.has(n)?r.delete(n):r.add(n),r}function pr(t){return`roles-bytecount ${t>Ut?"warn":""} ${t>O?"over":""}`}function hn(t){return`roles-bytecount ${t>jt?"warn":""} ${t>ue?"over":""}`}function Ie(t){return t.flash?(0,e.jsxs)("span",{className:`roles-saved-flash ${t.flash.isError?"roles-save-error":""}`,children:[" ",t.flash.text]}):null}function Pn(t){let{tr:n}=t;return t.groups.length===0?(0,e.jsx)("div",{className:"roles-empty",children:n("roles.noChats")}):(0,e.jsx)(e.Fragment,{children:t.groups.map(r=>{let o=t.expandedGroups.has(r.chatId),c=r.memberBots.filter(p=>p.inChat),f=Vt(r),m=qt(r);return(0,e.jsxs)("div",{className:"roles-group-section",children:[(0,e.jsxs)("div",{className:`roles-group-row ${o?"expanded":""} ${t.selectedGroupId===r.chatId&&!t.selectedBotId?"selected":""}`,"data-group-id":r.chatId,onClick:()=>t.onToggleGroup(r.chatId),children:[(0,e.jsx)("span",{className:"roles-group-arrow",children:o?"\u25BE":"\u25B8"}),(0,e.jsx)("span",{className:"roles-group-icon","aria-hidden":"true",children:(0,e.jsxs)("svg",{viewBox:"0 0 16 16",children:[(0,e.jsx)("circle",{cx:"5.6",cy:"5.8",r:"2.4"}),(0,e.jsx)("path",{d:"M1.8 13.2c.5-2.4 2-3.6 3.8-3.6s3.3 1.2 3.8 3.6"}),(0,e.jsx)("circle",{cx:"11",cy:"6.8",r:"1.9"}),(0,e.jsx)("path",{d:"M9.8 12.6c.4-1.7 1.5-2.6 2.8-2.6 1 0 1.9.5 2.4 1.6"})]})}),(0,e.jsxs)("div",{className:"roles-group-info",children:[(0,e.jsx)("div",{className:"roles-group-name",children:r.name??r.chatId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[f,"/",m," ",n("roles.botsWithRoles")]}),(0,e.jsx)(In,{group:r,profiles:t.profiles,context:t.context,loaded:t.contextLoaded,tr:n})]}),(0,e.jsx)("span",{className:"roles-group-chevron"})]}),(0,e.jsx)("div",{className:"roles-bot-list",children:o?c.map(p=>{let y=t.selectedGroupId===r.chatId&&t.selectedBotId===p.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row ${y?"selected":""}`,"data-group-id":r.chatId,"data-bot-id":p.larkAppId,onClick:L=>{L.stopPropagation(),t.onSelectBot(r.chatId,p.larkAppId)},children:[(0,e.jsx)("span",{className:"roles-bot-indent"}),(0,e.jsx)(gr,{bot:p}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:p.botName}),(0,e.jsx)("div",{className:"roles-bot-id",children:p.larkAppId})]}),(0,e.jsxs)("div",{className:"roles-bot-badges",children:[(0,e.jsx)("span",{className:`roles-badge ${p.hasRole?"has-role":"no-role"}`,children:p.hasRole?n("roles.configured"):n("roles.unconfigured")}),p.hasMessageListener?(0,e.jsx)("span",{className:"roles-badge has-listener",children:n("roles.listenerBadge")}):null]})]},p.larkAppId)}):null})]},r.chatId)})})}function In(t){let{group:n,profiles:r,context:o,loaded:c,tr:f}=t;if(!r.length||!c)return null;let m=new Map;for(let L of n.memberBots)L.inChat&&m.set(L.larkAppId,o.effectiveRolesByBot.get(He(L.larkAppId,n.chatId))??null);if(!At(m))return null;let p=_t(n.memberBots,r,o.entriesByProfile,m)[0];if(!p)return(0,e.jsx)("div",{className:"roles-profile-match muted",children:f("groups.profileStatusUnmatched")});let y=p.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`roles-profile-match ${p.kind}`,children:f(y,{name:p.profileId,matched:p.matched,total:p.total,chat:p.chatMatched})})}function Sn(t){let{listener:n,tr:r}=t,[o,c]=(0,a.useState)("members"),[f,m]=(0,a.useState)(""),[p,y]=(0,a.useState)(()=>new Set),L=new Set(n.senderPolicy?.includeSenderTypes??[]),Se=new Set(n.messagePolicy?.includeMsgTypes??[]),R=n.senderPolicy?.mode==="all_except_excluded"?"all_except_excluded":"include_only",W=new Set(n.senderPolicy?.includeSenderOpenIds??[]),A=new Set(n.senderPolicy?.excludeSenderOpenIds??[]),we=[...[...R==="all_except_excluded"?A:W].filter(d=>!t.memberById.has(d))],Y=[...t.members.filter(d=>d.memberType!=="bot"),...we.map(d=>({openId:d,name:d,memberType:"unknown"}))],xe=t.members.filter(d=>d.memberType==="bot"),_=o==="bots"?xe:Y,F=Ft(_,f),k=F.map(d=>d.openId),z=k.filter(d=>p.has(d)),me=k.length>0&&z.length===k.length,U=[...p].filter(d=>_.some(b=>b.openId===d)),B=U.length>0?U:k,g=$e({mode:R,include:[...W],exclude:[...A],targetIds:B});(0,a.useEffect)(()=>{m(""),y(new Set)},[o]),(0,a.useEffect)(()=>{let d=new Set(_.map(b=>b.openId));y(b=>{let I=new Set([...b].filter(T=>d.has(T)));return I.size===b.size?b:I})},[_]);let fe=(d,b)=>{y(I=>{let T=new Set(I);return b?T.add(d):T.delete(d),T})},v=()=>{y(d=>{let b=new Set(d);if(me)for(let I of k)b.delete(I);else for(let I of k)b.add(I);return b})},J=d=>{B.length!==0&&t.onSetTargetsPolicy(B,d)};return(0,e.jsxs)("div",{className:"roles-listener-editor",children:[t.loading?(0,e.jsx)(de,{label:r("common.loading")}):null,(0,e.jsxs)("label",{className:"filter-toggle roles-listener-enabled",children:[(0,e.jsx)("input",{type:"checkbox",checked:n.enabled,onChange:d=>t.onPatch({enabled:d.currentTarget.checked})}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"}),(0,e.jsx)("span",{className:"filter-toggle-label",children:r("roles.listenerEnabled")})]}),(0,e.jsx)("p",{className:"roles-listener-scope-help",children:r("roles.listenerScopeHelp")}),(0,e.jsxs)("div",{className:"roles-listener-grid",children:[(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerName")}),(0,e.jsx)("input",{type:"text",value:n.name??"",placeholder:r("roles.listenerNamePlaceholder"),onChange:d=>t.onPatch({name:d.currentTarget.value})})]}),(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerReplyCardTitle")}),(0,e.jsx)("input",{type:"text",value:n.replyCardTitle??"",placeholder:r("roles.listenerReplyCardTitlePlaceholder"),onChange:d=>t.onPatch({replyCardTitle:d.currentTarget.value})})]}),(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerWorkingDir")}),(0,e.jsx)("input",{type:"text",value:n.workingDir??"",placeholder:r("roles.listenerWorkingDirPlaceholder"),onChange:d=>t.onPatch({workingDir:d.currentTarget.value})})]})]}),(0,e.jsxs)("div",{className:"roles-listener-policy-row",children:[(0,e.jsxs)("div",{className:"roles-listener-policy",children:[(0,e.jsx)("div",{className:"roles-field-label",children:r("roles.listenerSenderTypes")}),(0,e.jsxs)("label",{className:"roles-listener-chip",children:[(0,e.jsx)("input",{type:"checkbox",checked:L.has("user"),onChange:d=>t.onToggleSenderType("user",d.currentTarget.checked)}),(0,e.jsx)("span",{children:r("roles.listenerSenderUser")})]}),(0,e.jsxs)("label",{className:"roles-listener-chip",children:[(0,e.jsx)("input",{type:"checkbox",checked:L.has("bot"),onChange:d=>t.onToggleSenderType("bot",d.currentTarget.checked)}),(0,e.jsx)("span",{children:r("roles.listenerSenderBot")})]})]}),(0,e.jsxs)("div",{className:"roles-listener-policy",children:[(0,e.jsx)("div",{className:"roles-field-label",children:r("roles.listenerMessageTypes")}),fr.map(d=>(0,e.jsxs)("label",{className:"roles-listener-chip",children:[(0,e.jsx)("input",{type:"checkbox",checked:Se.has(d),onChange:b=>t.onToggleMsgType(d,b.currentTarget.checked)}),(0,e.jsx)("span",{children:d})]},d))]}),(0,e.jsxs)("label",{className:"roles-listener-checkbox",children:[(0,e.jsx)("input",{type:"checkbox",checked:n.senderPolicy?.excludeSelf!==!1,onChange:d=>t.onSenderPolicyPatch({excludeSelf:d.currentTarget.checked})}),(0,e.jsx)("span",{children:r("roles.listenerExcludeSelf")})]})]}),(0,e.jsx)("div",{className:"roles-listener-policy-row",children:(0,e.jsxs)("div",{className:"roles-listener-policy",children:[(0,e.jsx)("div",{className:"roles-field-label",children:r("roles.listenerSenderMode")}),(0,e.jsxs)("div",{className:"roles-listener-target-tabs segmented",role:"tablist","aria-label":r("roles.listenerSenderMode"),children:[(0,e.jsx)("button",{type:"button",className:R==="include_only"?"active":"","aria-pressed":R==="include_only",onClick:()=>t.onSetSenderMode("include_only"),children:r("roles.listenerSenderModeInclude")}),(0,e.jsx)("button",{type:"button",className:R==="all_except_excluded"?"active":"","aria-pressed":R==="all_except_excluded",onClick:()=>t.onSetSenderMode("all_except_excluded"),children:r("roles.listenerSenderModeAllExcept")})]}),(0,e.jsx)("small",{className:"roles-listener-scope-help",children:r(R==="all_except_excluded"?"roles.listenerSenderModeAllExceptHelp":"roles.listenerSenderModeIncludeHelp")})]})}),(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerPrompt")}),(0,e.jsx)("textarea",{id:"roles-listener-prompt",placeholder:r("roles.listenerPromptPlaceholder"),rows:9,value:n.prompt,onChange:d=>t.onPatch({prompt:d.currentTarget.value})})]}),(0,e.jsxs)("div",{className:"roles-editor-footer",children:[(0,e.jsxs)("span",{id:"roles-listener-bytecount",className:hn(t.promptByteLen),children:[t.promptByteLen," / ",ue," bytes"]}),(0,e.jsx)(Ie,{flash:t.flash})]}),(0,e.jsxs)("div",{className:"roles-listener-preview-panel",children:[(0,e.jsxs)("div",{className:"roles-listener-preview-head",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:r("roles.listenerPreviewTitle")}),(0,e.jsx)("small",{children:r("roles.listenerPreviewHint")})]}),(0,e.jsxs)("div",{className:"roles-listener-preview-actions",children:[(0,e.jsxs)("label",{children:[(0,e.jsx)("span",{children:r("roles.listenerPreviewCount")}),(0,e.jsx)("select",{value:t.previewLimit,onChange:d=>t.onPreviewLimitChange(Number(d.currentTarget.value)),children:Array.from({length:Ue},(d,b)=>b+1).map(d=>(0,e.jsx)("option",{value:d,children:d},d))})]}),(0,e.jsx)("button",{type:"button",onClick:t.onPreview,disabled:t.previewStatus.kind==="loading",children:t.previewStatus.kind==="loading"&&t.previewStatus.mode==="preview"?"...":r("roles.listenerPreviewButton")}),(0,e.jsx)("button",{type:"button",className:"primary",onClick:t.onRunPreview,disabled:t.previewStatus.kind==="loading",children:t.previewStatus.kind==="loading"&&t.previewStatus.mode==="run"?"...":r("roles.listenerRunPreviewButton")})]})]}),(0,e.jsx)(wn,{status:t.previewStatus,tr:r})]}),(0,e.jsxs)("div",{className:"roles-listener-members",children:[(0,e.jsxs)("div",{className:"roles-listener-members-head",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:r("roles.listenerFilters")}),(0,e.jsx)("small",{children:t.membersLoading?r("common.loading"):r("roles.listenerMembersHint")})]}),(0,e.jsxs)("div",{className:"roles-listener-target-tabs segmented",role:"tablist","aria-label":r("roles.listenerFilters"),children:[(0,e.jsx)("button",{type:"button",className:o==="members"?"active":"","aria-pressed":o==="members",onClick:()=>c("members"),children:r("roles.listenerMembers")}),(0,e.jsx)("button",{type:"button",className:o==="bots"?"active":"","aria-pressed":o==="bots",onClick:()=>c("bots"),children:r("roles.listenerBots")})]}),(0,e.jsxs)("div",{className:"roles-listener-filter-toolbar",children:[(0,e.jsx)("input",{type:"search",value:f,placeholder:r("roles.listenerSearchPlaceholder"),onChange:d=>m(d.currentTarget.value)}),f?(0,e.jsx)("button",{type:"button",className:"roles-listener-clear-search",onClick:()=>m(""),"aria-label":r("roles.listenerClearSearch"),children:"\xD7"}):null,(0,e.jsx)("button",{type:"button",className:"roles-listener-select-all",disabled:k.length===0,onClick:v,children:r(me?"roles.listenerClearVisible":"roles.listenerSelectVisible",{count:k.length})})]}),(0,e.jsxs)("div",{className:"roles-listener-bulkbar",children:[(0,e.jsxs)("span",{children:[U.length>0?r("roles.listenerSelectedCount",{count:U.length}):r("roles.listenerFilteredCount",{count:k.length}),g==="mixed"?` \xB7 ${r("roles.listenerMixedMode")}`:""]}),(0,e.jsxs)("div",{className:"roles-listener-member-actions",role:"group","aria-label":r("roles.listenerBulkActions"),children:[(0,e.jsx)("button",{type:"button",className:g==="listen"?"active":"","aria-pressed":g==="listen",disabled:B.length===0,onClick:()=>J(!0),children:r("roles.listenerTargetListen")}),(0,e.jsx)("button",{type:"button",className:g==="ignore"?"active":"","aria-pressed":g==="ignore",disabled:B.length===0,onClick:()=>J(!1),children:r("roles.listenerTargetIgnore")})]})]}),(0,e.jsx)("div",{className:"roles-listener-member-list",children:F.length===0?(0,e.jsx)("div",{className:"roles-empty",children:r(o==="bots"?"roles.listenerBotsEmpty":"roles.listenerMembersEmpty")}):F.map(d=>{let b=$e({mode:R,include:[...W],exclude:[...A],targetIds:[d.openId]});return(0,e.jsxs)("div",{className:"roles-listener-member",children:[(0,e.jsx)("label",{className:"roles-listener-member-select","aria-label":Ke(d,d.openId),children:(0,e.jsx)("input",{type:"checkbox",checked:p.has(d.openId),onChange:I=>fe(d.openId,I.currentTarget.checked)})}),(0,e.jsxs)("div",{className:"roles-listener-member-main",children:[(0,e.jsx)("strong",{children:Ke(d,d.openId)}),(0,e.jsx)("span",{children:d.openId})]}),(0,e.jsxs)("div",{className:"roles-listener-member-actions",role:"group","aria-label":Ke(d,d.openId),children:[(0,e.jsx)("button",{type:"button",className:b==="listen"?"active":"","aria-pressed":b==="listen",onClick:()=>t.onSetTargetPolicy(d.openId,!0),children:r("roles.listenerTargetListen")}),(0,e.jsx)("button",{type:"button",className:b==="ignore"?"active":"","aria-pressed":b==="ignore",onClick:()=>t.onSetTargetPolicy(d.openId,!1),children:r("roles.listenerTargetIgnore")})]})]},d.openId)})})]})]})}function mr(t){return(0,e.jsx)("div",{id:t.id,className:"roles-preview",children:t.content.trim()?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("strong",{children:t.tr("roles.preview")}),(0,e.jsx)("pre",{children:t.content})]}):(0,e.jsx)("small",{children:t.tr("roles.previewEmpty")})})}function wn(t){let{status:n,tr:r}=t;if(n.kind==="idle")return(0,e.jsx)("div",{className:"roles-listener-preview-empty",children:r("roles.listenerPreviewEmpty")});if(n.kind==="loading")return(0,e.jsx)(de,{label:r("common.loading")});if(n.kind==="error")return(0,e.jsx)("div",{className:"roles-listener-preview-error",children:n.text});let o=n.response.matches??[],f=(n.response.results??[]).reduce((m,p)=>{let y=p.ok?p.state??"triggered":"failed";return m[y]=(m[y]??0)+1,m},{});return(0,e.jsxs)("div",{className:"roles-listener-preview-results",children:[(0,e.jsx)("div",{className:"roles-listener-preview-summary",children:n.mode==="run"?r("roles.listenerRunPreviewSummary",{count:o.length,triggered:f.triggered??0,running:f.running??0,replied:f.replied??0,failed:f.failed??0}):r("roles.listenerPreviewSummary",{count:o.length})}),o.length===0?(0,e.jsx)("div",{className:"roles-listener-preview-empty",children:r("roles.listenerPreviewNoMatches")}):(0,e.jsx)("div",{className:"roles-listener-preview-list",children:o.map(m=>(0,e.jsx)(xn,{item:m,result:n.response.results?.find(p=>p.messageId===m.messageId),tr:r},m.messageId))})]})}function xn(t){let n=t.item.messageText.length>300?`${t.item.messageText.slice(0,300)}...`:t.item.messageText,r=t.item.senderName||t.item.senderOpenId||t.item.senderType,o=tr(t.item.createTime);return(0,e.jsxs)("div",{className:"roles-listener-preview-item",children:[(0,e.jsxs)("div",{className:"roles-listener-preview-meta",children:[(0,e.jsx)("span",{children:t.item.msgType}),(0,e.jsx)("span",{children:t.item.senderType}),t.item.senderOpenId?(0,e.jsx)("span",{children:t.item.senderOpenId}):null,(0,e.jsx)("span",{children:t.item.messageId}),t.result?(0,e.jsx)("span",{className:fn(t.result.state,t.result.ok),children:t.tr(`roles.listenerRunPreviewState.${t.result.ok?t.result.state??"triggered":"failed"}`)}):null]}),t.result?.sessionId||t.result?.replyMessageId||t.result?.error?(0,e.jsxs)("div",{className:"roles-listener-preview-run-detail",children:[t.result.sessionId?(0,e.jsx)("span",{children:t.result.sessionId}):null,t.result.replyMessageId?(0,e.jsx)("span",{children:t.result.replyMessageId}):null,t.result.error?(0,e.jsx)("strong",{children:t.result.error}):null]}):null,(0,e.jsxs)("div",{className:"roles-listener-preview-sender",children:[(0,e.jsx)("span",{children:t.tr("roles.listenerPreviewSender")}),(0,e.jsx)("strong",{children:r})]}),o?(0,e.jsxs)("div",{className:"roles-listener-preview-time",children:[(0,e.jsx)("span",{children:t.tr("roles.listenerPreviewTime")}),(0,e.jsx)("strong",{children:o})]}):null,t.item.messageTitle?(0,e.jsxs)("div",{className:"roles-listener-preview-title",children:[(0,e.jsx)("span",{children:t.tr("roles.listenerPreviewMessageTitle")}),(0,e.jsx)("strong",{children:t.item.messageTitle})]}):null,(0,e.jsx)("div",{className:"roles-listener-preview-content-label",children:t.tr("roles.listenerPreviewContent")}),(0,e.jsx)("pre",{children:n})]})}function Rn(t){let{tr:n}=t;return t.profiles.length===0?(0,e.jsx)("div",{className:"roles-empty",children:n("roles.profileEmpty")}):(0,e.jsx)(e.Fragment,{children:t.profiles.map(r=>{let o=t.selectedProfileId===r.profileId,c=(r.botEntries??[]).some(f=>f.hasEntry);return(0,e.jsxs)("div",{className:`roles-profile-row ${o?"selected":""}`,"data-profile-id":r.profileId,onClick:()=>t.onSelect(r.profileId),children:[(0,e.jsxs)("div",{className:"roles-profile-row-main",children:[(0,e.jsx)("div",{className:"roles-profile-name",children:r.profileId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[r.entryCount," ",n("roles.profileEntries")]})]}),(0,e.jsx)("span",{className:`roles-badge ${c?"has-role":"no-role"}`,children:n(c?"roles.configured":"roles.profileMissing")})]},r.profileId)})})}function kn(t){let{status:n,bots:r,tr:o}=t;return n.kind==="idle"?null:n.kind==="text"?(0,e.jsx)(e.Fragment,{children:n.text}):(0,e.jsx)(e.Fragment,{children:n.results.map(c=>{let m=r.find(y=>y.larkAppId===c.larkAppId)?.botName??c.larkAppId,p=c.ok?n.preview?c.wouldRefuse?o("roles.applyWouldRefuse"):o("roles.applyPreviewOk"):o("roles.applyOk"):`${o("roles.applyFailed")}: ${String(c.error??`HTTP ${c.status}`)}`;return(0,e.jsxs)("div",{children:[m,": ",p]},c.larkAppId)})})}function Gn(t){return De(t,(0,e.jsx)(yr,{tab:"groups"}))}function Fn(t){return De(t,(0,e.jsx)(yr,{tab:"profiles"}))}export{Fn as renderRoleProfilesPage,Gn as renderRolesPage};
@@ -1 +0,0 @@
1
- import{a as j,c as F}from"./chunk-HK7NIBJG.js";import{g as q,m as Z,n as _,o as B,p as K,q as U}from"./chunk-5CJMHTT4.js";import"./chunk-6J5LS5AU.js";import{a as D}from"./chunk-SYC6D5XU.js";import{a as G,d as H}from"./chunk-5THX4DI2.js";import{c as $}from"./chunk-7SZRL6FY.js";var i=$(G(),1);var e=$(H(),1),z=1e3;function J(l,t){if(!l)return"\u2014";try{return new Date(l).toLocaleString(void 0,t?{timeZone:t,timeZoneName:"short"}:void 0)}catch{return l}}function Q(l,t){let n=t.q.toLowerCase();return l.filter(o=>!t.kind||o.parsed?.kind===t.kind).filter(o=>!t.enabledOnly||o.enabled).filter(o=>!n||JSON.stringify(o).toLowerCase().includes(n)).sort((o,d)=>{if(o.enabled!==d.enabled)return o.enabled?-1:1;let f=o.nextRunAt?Date.parse(o.nextRunAt):1/0,p=d.nextRunAt?Date.parse(d.nextRunAt):1/0;return f-p})}function O(l){return l.deliver==="local"?"local":l.executionPosition==="new-topic"?"new-topic":l.executionPosition==="topic"?l.rootMessageId?"thread":"chat":l.executionPosition==="top-level"?"chat":l.deliver==="new-topic"?"new-topic":l.scope==="chat"?"chat":l.rootMessageId?"thread":"chat"}function V(l,t){let n=O(l);return t(n==="local"?"schedules.deliveryLocal":n==="new-topic"?"schedules.deliveryNewTopic":n==="thread"?"schedules.deliveryThread":"schedules.deliveryTopLevel")}function W(l){return l.repeat?`${l.repeat.completed}/${l.repeat.times??"\u221E"}`:"\u2014"}function X(l){return new Promise(t=>window.setTimeout(t,l))}function Y(l){let{schedule:t,scheduleTimeZone:n,tr:o}=l,d=String(t.parsed?.kind??"unknown"),f=t.enabled?"pause":"resume",p=`${t.id}:${f}`,y=`${t.id}:run`;return(0,e.jsxs)(_,{kind:"schedule",className:"schedule-list-row","data-id":t.id,children:[(0,e.jsxs)(B,{children:[(0,e.jsxs)("div",{className:"schedule-row-head",children:[(0,e.jsx)("b",{children:t.name??t.id}),(0,e.jsx)("span",{className:`schedule-state ${t.enabled?"enabled":"paused"}`,children:t.enabled?o("schedules.enabled"):o("schedules.paused")})]}),(0,e.jsxs)("div",{className:"schedule-row-meta",children:[(0,e.jsx)("span",{children:t.botName??t.larkAppId??"-"}),(0,e.jsx)("span",{children:"\xB7"}),(0,e.jsx)("code",{children:t.parsed?.display??"?"})]}),(0,e.jsxs)("div",{className:"schedule-chip-strip",children:[(0,e.jsx)("span",{children:d}),(0,e.jsxs)("span",{children:[o("schedules.delivery"),": ",V(t,o)]}),t.silent?(0,e.jsxs)("span",{children:["\u{1F507} ",o("schedules.silent")]}):null,(0,e.jsxs)("span",{children:[o("schedules.next"),": ",J(t.nextRunAt,n)]}),(0,e.jsxs)("span",{children:[o("schedules.last"),": ",J(t.lastRunAt,n)]}),t.lastStatus==="error"?(0,e.jsxs)("span",{className:"schedule-error-chip",title:typeof t.lastError=="string"?t.lastError:void 0,children:["\u26A0 ",o("schedules.error"),": ",typeof t.lastError=="string"&&t.lastError.length>60?t.lastError.slice(0,60)+"\u2026":t.lastError??o("schedules.errorUnknown")]}):null,(0,e.jsxs)("span",{children:[o("schedules.repeat"),": ",W(t)]})]})]}),(0,e.jsx)(K,{children:(0,e.jsxs)("div",{className:"schedule-actions",children:[(0,e.jsx)(te,{op:"run",label:o("schedules.runNow"),pending:l.pending===y,feedback:l.feedback[y]??null,onClick:()=>l.onAction(t.id,"run")}),(0,e.jsx)(se,{checked:!!t.enabled,pending:l.pending===p,feedback:l.feedback[p]??null,tr:o,onClick:()=>l.onAction(t.id,f)}),(0,e.jsx)("button",{type:"button",className:"schedule-action-button schedule-edit-button",onClick:()=>l.onEdit(t),title:o("schedules.edit"),children:(0,e.jsx)("span",{className:"schedule-action-label",children:o("schedules.edit")})}),(0,e.jsx)("button",{type:"button",className:"schedule-action-button schedule-delete-button",onClick:()=>l.onDelete(t),title:o("schedules.delete"),children:(0,e.jsx)("span",{className:"schedule-action-label",children:o("schedules.delete")})})]})})]})}function ee(){let l=F(),{scheduleRows:t,scheduleTimeZone:n}=j(s=>({scheduleRows:[...s.schedules.values()],scheduleTimeZone:s.scheduleTimeZone})),[o,d]=(0,i.useState)({q:"",kind:"",enabledOnly:!1}),[f,p]=(0,i.useState)(null),[y,I]=(0,i.useState)({}),w=(0,i.useRef)(new Map),[P,k]=(0,i.useState)(!1),[u,N]=(0,i.useState)(null),[T,S]=(0,i.useState)(null),[A,E]=(0,i.useState)([]);(0,i.useEffect)(()=>{fetch("/api/bots").then(s=>s.json()).then(s=>{Array.isArray(s?.bots)&&E(s.bots)}).catch(()=>{})},[]);let C=(0,i.useMemo)(()=>Q(t,o),[t,o]);(0,i.useEffect)(()=>()=>{w.current.forEach(s=>window.clearTimeout(s)),w.current.clear()},[]);function R(s,c){I(m=>({...m,[s]:c}));let r=w.current.get(s);r&&window.clearTimeout(r);let v=window.setTimeout(()=>{I(m=>{let h={...m};return delete h[s],h}),w.current.delete(s)},c==="success"?1600:2200);w.current.set(s,v)}async function b(s,c){let r=`${s}:${c}`,v=performance.now(),m="success";p(r);try{let h=await fetch(`/api/schedules/${encodeURIComponent(s)}/${c}`,{method:"POST"}),M=await h.json().catch(()=>({}));if(!h.ok||M.ok===!1)throw new Error(`Failed: ${h.status} ${M?.error??""}`.trim())}catch{m="error"}finally{if(c==="run"){let h=z-(performance.now()-v);h>0&&await X(h)}R(r,m),p(h=>h===r?null:h)}}function x(){N(null),S(null),k(!0)}function g(s){N(s),S(null),k(!0)}async function L(s){if(!window.confirm(l("schedules.deleteConfirm")))return;let c=`${s.id}:delete`;p(c);try{let r=await fetch(`/api/schedules/${encodeURIComponent(s.id)}`,{method:"DELETE"}),v=await r.json().catch(()=>({}));if(!r.ok||v.ok===!1)throw new Error(v?.error??`HTTP ${r.status}`);R(c,"success")}catch{R(c,"error")}finally{p(r=>r===c?null:r)}}async function a(s){S(null);try{let c=u?`/api/schedules/${encodeURIComponent(u.id)}`:"/api/schedules",r=u?"PATCH":"POST",v=u?{name:s.name,schedule:s.schedule,prompt:s.prompt,silent:s.silent,...s.updateExecutionPosition?{executionPosition:s.executionPosition,rootMessageId:s.rootMessageId,topicTitle:s.topicTitle}:{}}:{name:s.name,schedule:s.schedule,prompt:s.prompt,silent:s.silent,executionPosition:s.executionPosition,rootMessageId:s.rootMessageId,topicTitle:s.topicTitle,chatId:s.chatId,larkAppId:s.larkAppId},m=await fetch(c,{method:r,headers:{"Content-Type":"application/json"},body:JSON.stringify(v)}),h=await m.json().catch(()=>({}));if(!m.ok||h.ok===!1)throw new Error(h?.error??`HTTP ${m.status}`);k(!1)}catch(c){S(c instanceof Error?c.message:String(c))}}return(0,e.jsxs)("section",{className:"page schedules-page",children:[(0,e.jsxs)("div",{className:"page-heading",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:l("nav.schedules")}),(0,e.jsx)("h1",{children:l("schedules.title")})]}),(0,e.jsx)(q,{onClick:x,disabled:A.length===0,children:l("schedules.create")})]}),(0,e.jsxs)("form",{id:"sched-filters",className:"filters dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",name:"q",placeholder:l("schedules.search"),value:o.q,onChange:s=>{let c=s.currentTarget.value;d(r=>({...r,q:c}))}}),(0,e.jsx)(U,{id:"sched-kind-menu",ariaLabel:l("schedules.anyKind"),label:o.kind||l("schedules.anyKind"),value:o.kind,options:[{value:"",label:l("schedules.anyKind")},{value:"cron",label:"cron"},{value:"interval",label:"interval"},{value:"once",label:"once"}],onChange:s=>d(c=>({...c,kind:s}))}),(0,e.jsxs)("label",{className:"filter-toggle",children:[(0,e.jsx)("input",{type:"checkbox",name:"enabled",checked:o.enabledOnly,onChange:s=>{let c=s.currentTarget.checked;d(r=>({...r,enabledOnly:c}))}}),(0,e.jsx)("span",{className:"filter-toggle-label",children:l("schedules.enabledOnly")}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"})]}),(0,e.jsx)("span",{className:"schedules-toolbar-spacer","aria-hidden":"true"}),(0,e.jsxs)("span",{className:"schedules-toolbar-count",children:[C.length,"/",t.length]})]}),(0,e.jsx)("section",{className:"overview-block schedules-list-section",children:(0,e.jsx)("div",{className:"schedules-list-wrap",children:C.length===0?(0,e.jsx)("div",{id:"schedules-tbody",className:"empty schedules-list-empty",children:l("schedules.empty")}):(0,e.jsx)(Z,{id:"schedules-tbody",className:"schedules-list",children:C.map(s=>(0,e.jsx)(Y,{schedule:s,scheduleTimeZone:n,pending:f,feedback:y,tr:l,onAction:(c,r)=>{b(c,r)},onEdit:g,onDelete:c=>{L(c)}},s.id))})})}),P?(0,e.jsx)(ne,{editing:u,error:T,bots:A,tr:l,onClose:()=>k(!1),onSubmit:s=>{a(s)}}):null]})}function le(l,t,n,o,d){return n?d(l==="run"?"schedules.running":"schedules.saving"):o==="success"?d(l==="run"?"schedules.runDone":"schedules.saved"):o==="error"?d("schedules.failed"):t}function te(l){let t=F(),n=l.feedback?` is-${l.feedback}`:"";return(0,e.jsx)("button",{type:"button",className:`schedule-action-button${l.pending?" is-pending":""}${n}`,"data-op":l.op,disabled:l.pending,onClick:l.onClick,children:(0,e.jsx)("span",{className:"schedule-action-label",children:le(l.op,l.label,l.pending,l.feedback,t)})})}function se(l){let t=l.feedback==="error"?l.tr("schedules.failed"):l.checked?l.tr("schedules.enabled"):l.tr("schedules.paused");return(0,e.jsxs)("button",{type:"button",className:`schedule-enabled-switch${l.checked?" is-on":""}${l.pending?" is-pending":""}${l.feedback?` is-${l.feedback}`:""}`,"aria-pressed":l.checked,disabled:l.pending,onClick:l.onClick,children:[(0,e.jsx)("span",{className:"schedule-enabled-switch-label",children:t}),(0,e.jsx)("span",{className:"schedule-enabled-switch-track","aria-hidden":"true",children:(0,e.jsx)("span",{})})]})}function ie(l){return D(l,(0,e.jsx)(ee,{}))}function ne(l){let{editing:t,tr:n,bots:o}=l,[d,f]=(0,i.useState)(t?.name??""),[p,y]=(0,i.useState)(t?.schedule??""),[I,w]=(0,i.useState)(t?.prompt??""),[P,k]=(0,i.useState)(t?.silent===!0),[u,N]=(0,i.useState)(t&&O(t)==="thread"?"topic":t&&O(t)==="new-topic"?"new-topic":"top-level"),[T,S]=(0,i.useState)(t?.rootMessageId??""),[A,E]=(0,i.useState)(t?.topicTitle??""),[C,R]=(0,i.useState)(t?.chatId??""),[b,x]=(0,i.useState)(t?.larkAppId??o[0]?.larkAppId??""),g=t?.deliver==="local";(0,i.useEffect)(()=>{!t&&!b&&o.length>0&&x(o[0].larkAppId)},[t,b,o]);function L(a){a.preventDefault(),!(!t&&!b)&&(!g&&u==="topic"&&!T.trim()||l.onSubmit({name:d,schedule:p,prompt:I,silent:P,executionPosition:u,rootMessageId:T.trim(),topicTitle:A.trim(),updateExecutionPosition:!g,chatId:C,larkAppId:b}))}return(0,e.jsx)("div",{className:"schedule-form-overlay",onClick:l.onClose,children:(0,e.jsxs)("div",{className:"schedule-form-dialog",role:"dialog","aria-modal":"true",onClick:a=>a.stopPropagation(),children:[(0,e.jsx)("h2",{children:n(t?"schedules.edit":"schedules.create")}),(0,e.jsxs)("form",{onSubmit:L,className:"schedule-form",children:[t?null:(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.bot")}),(0,e.jsx)("select",{value:b,onChange:a=>x(a.target.value),required:!0,children:o.map(a=>(0,e.jsx)("option",{value:a.larkAppId,children:a.botName??a.larkAppId},a.larkAppId))})]}),(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.name")}),(0,e.jsx)("input",{type:"text",value:d,onChange:a=>f(a.target.value),required:!0,autoFocus:!0})]}),(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.schedule")}),(0,e.jsx)("input",{type:"text",value:p,onChange:a=>y(a.target.value),placeholder:n("schedules.form.scheduleHelp"),required:!0}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.scheduleHelp")})]}),(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.prompt")}),(0,e.jsx)("textarea",{value:I,onChange:a=>w(a.target.value),rows:4,required:!0}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.promptHelp")})]}),t?null:(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.chat")}),(0,e.jsx)("input",{type:"text",value:C,onChange:a=>R(a.target.value),placeholder:"oc_...",required:!0})]}),g?(0,e.jsxs)("div",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.deliver")}),(0,e.jsxs)("div",{className:"schedule-form-placement",children:[(0,e.jsx)("strong",{children:n("schedules.deliveryLocal")}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.localHelp")})]})]}):(0,e.jsxs)("div",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.deliver")}),(0,e.jsxs)("div",{className:"schedule-form-radio-group",children:[(0,e.jsxs)("label",{children:[(0,e.jsx)("input",{type:"radio",name:"executionPosition",value:"top-level",checked:u==="top-level",onChange:()=>N("top-level")}),n("schedules.deliveryTopLevel")]}),(0,e.jsxs)("label",{children:[(0,e.jsx)("input",{type:"radio",name:"executionPosition",value:"topic",checked:u==="topic",onChange:()=>N("topic")}),n("schedules.deliveryThread")]}),(0,e.jsxs)("label",{children:[(0,e.jsx)("input",{type:"radio",name:"executionPosition",value:"new-topic",checked:u==="new-topic",onChange:()=>{N("new-topic"),k(!1)}}),n("schedules.deliveryNewTopic")]})]}),(0,e.jsx)("small",{className:"schedule-form-help",children:n(u==="top-level"?"schedules.form.topLevelHelp":u==="topic"?"schedules.form.topicHelp":"schedules.form.newTopicHelp")})]}),!g&&u==="topic"?(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.topicRoot")}),(0,e.jsx)("input",{type:"text",value:T,onChange:a=>S(a.target.value),placeholder:"om_...",required:!0}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.topicRootHelp")})]}):null,!g&&u==="new-topic"?(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.topicTitle")}),(0,e.jsx)("input",{type:"text",value:A,onChange:a=>E(a.target.value),placeholder:n("schedules.form.topicTitlePlaceholder"),maxLength:200}),(0,e.jsxs)("small",{className:"schedule-form-help schedule-form-help-with-count",children:[n("schedules.form.topicTitleHelp"),(0,e.jsxs)("span",{children:[Array.from(A).length,"/200"]})]})]}):null,(0,e.jsxs)("label",{className:"schedule-form-field schedule-form-toggle",children:[(0,e.jsx)("input",{type:"checkbox",checked:P,onChange:a=>k(a.target.checked)}),(0,e.jsxs)("span",{children:[n("schedules.form.silent"),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.silentHelp")})]})]}),u==="new-topic"&&P?(0,e.jsx)("p",{className:"schedule-form-help",children:n("schedules.form.silentNewTopicConflict")}):null,l.error?(0,e.jsx)("p",{className:"schedule-form-error",children:l.error}):null,(0,e.jsxs)("div",{className:"schedule-form-actions",children:[(0,e.jsx)("button",{type:"button",className:"schedule-form-cancel",onClick:l.onClose,children:n("schedules.form.cancel")}),(0,e.jsx)("button",{type:"submit",className:"schedule-form-submit",disabled:!t&&!b||!g&&u==="topic"&&!T.trim(),children:n(t?"schedules.form.save":"schedules.form.create")})]})]})]})})}export{Q as filterSchedules,J as fmtScheduleDate,ie as renderSchedulesPage,O as scheduleExecutionPlacement};