botmux 3.6.0 → 3.7.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 (177) hide show
  1. package/dist/.runtime-build-id +1 -1
  2. package/dist/adapters/backend/riff-backend.d.ts +7 -6
  3. package/dist/adapters/backend/riff-backend.d.ts.map +1 -1
  4. package/dist/adapters/backend/riff-backend.js +8 -7
  5. package/dist/adapters/backend/riff-backend.js.map +1 -1
  6. package/dist/adapters/backend/sandbox.d.ts.map +1 -1
  7. package/dist/adapters/backend/sandbox.js +5 -2
  8. package/dist/adapters/backend/sandbox.js.map +1 -1
  9. package/dist/adapters/cli/codex.d.ts.map +1 -1
  10. package/dist/adapters/cli/codex.js +15 -6
  11. package/dist/adapters/cli/codex.js.map +1 -1
  12. package/dist/adapters/cli/fs-policy.d.ts +62 -6
  13. package/dist/adapters/cli/fs-policy.d.ts.map +1 -1
  14. package/dist/adapters/cli/fs-policy.js +70 -7
  15. package/dist/adapters/cli/fs-policy.js.map +1 -1
  16. package/dist/bot-registry.d.ts +13 -0
  17. package/dist/bot-registry.d.ts.map +1 -1
  18. package/dist/bot-registry.js +15 -7
  19. package/dist/bot-registry.js.map +1 -1
  20. package/dist/cli/daemon-lifecycle-env.d.ts +1 -1
  21. package/dist/cli/daemon-lifecycle-env.d.ts.map +1 -1
  22. package/dist/cli/daemon-lifecycle-env.js +12 -0
  23. package/dist/cli/daemon-lifecycle-env.js.map +1 -1
  24. package/dist/cli.d.ts.map +1 -1
  25. package/dist/cli.js +23 -7
  26. package/dist/cli.js.map +1 -1
  27. package/dist/core/command-handler.d.ts +7 -5
  28. package/dist/core/command-handler.d.ts.map +1 -1
  29. package/dist/core/command-handler.js +37 -21
  30. package/dist/core/command-handler.js.map +1 -1
  31. package/dist/core/cost-calculator.d.ts +3 -0
  32. package/dist/core/cost-calculator.d.ts.map +1 -1
  33. package/dist/core/cost-calculator.js.map +1 -1
  34. package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
  35. package/dist/core/dashboard-ipc-server.js +12 -9
  36. package/dist/core/dashboard-ipc-server.js.map +1 -1
  37. package/dist/core/dashboard-rows.d.ts.map +1 -1
  38. package/dist/core/dashboard-rows.js +1 -0
  39. package/dist/core/dashboard-rows.js.map +1 -1
  40. package/dist/core/initial-user-turn.d.ts +14 -0
  41. package/dist/core/initial-user-turn.d.ts.map +1 -0
  42. package/dist/core/initial-user-turn.js +65 -0
  43. package/dist/core/initial-user-turn.js.map +1 -0
  44. package/dist/core/maintenance.d.ts.map +1 -1
  45. package/dist/core/maintenance.js +6 -0
  46. package/dist/core/maintenance.js.map +1 -1
  47. package/dist/core/per-bot-env.d.ts.map +1 -1
  48. package/dist/core/per-bot-env.js +10 -0
  49. package/dist/core/per-bot-env.js.map +1 -1
  50. package/dist/core/plugins/pm2.d.ts.map +1 -1
  51. package/dist/core/plugins/pm2.js +4 -0
  52. package/dist/core/plugins/pm2.js.map +1 -1
  53. package/dist/core/session-discovery.d.ts +23 -0
  54. package/dist/core/session-discovery.d.ts.map +1 -1
  55. package/dist/core/session-discovery.js +162 -82
  56. package/dist/core/session-discovery.js.map +1 -1
  57. package/dist/core/session-manager.d.ts.map +1 -1
  58. package/dist/core/session-manager.js +23 -4
  59. package/dist/core/session-manager.js.map +1 -1
  60. package/dist/core/worker-pool.d.ts +2 -0
  61. package/dist/core/worker-pool.d.ts.map +1 -1
  62. package/dist/core/worker-pool.js +27 -4
  63. package/dist/core/worker-pool.js.map +1 -1
  64. package/dist/daemon.d.ts +18 -0
  65. package/dist/daemon.d.ts.map +1 -1
  66. package/dist/daemon.js +205 -39
  67. package/dist/daemon.js.map +1 -1
  68. package/dist/dashboard/bot-onboarding.d.ts.map +1 -1
  69. package/dist/dashboard/bot-onboarding.js +29 -5
  70. package/dist/dashboard/bot-onboarding.js.map +1 -1
  71. package/dist/dashboard/bot-payload.js +3 -3
  72. package/dist/dashboard/bot-payload.js.map +1 -1
  73. package/dist/dashboard/web/bot-defaults-page.js +5 -5
  74. package/dist/dashboard/web/bot-defaults-page.js.map +1 -1
  75. package/dist/dashboard/web/bot-onboarding.d.ts.map +1 -1
  76. package/dist/dashboard/web/bot-onboarding.js +1 -1
  77. package/dist/dashboard/web/bot-onboarding.js.map +1 -1
  78. package/dist/dashboard/web/i18n.js +18 -18
  79. package/dist/dashboard/web/i18n.js.map +1 -1
  80. package/dist/dashboard-web/app.js +1 -1
  81. package/dist/dashboard-web/chunks/{bot-defaults-page-VQMPUJ4Y.js → bot-defaults-page-UKA7K4JV.js} +2 -2
  82. package/dist/dashboard-web/chunks/{chunk-NP4JUBGS.js → chunk-3QAUJXAS.js} +1 -1
  83. package/dist/dashboard-web/chunks/{chunk-JMRGZQDB.js → chunk-FLGXZJTD.js} +1 -1
  84. package/dist/dashboard-web/chunks/chunk-FNPGOZMX.js +1 -0
  85. package/dist/dashboard-web/chunks/{chunk-SNKATZWK.js → chunk-KQB42ML5.js} +4 -4
  86. package/dist/dashboard-web/chunks/{connectors-page-DOY4J3ZL.js → connectors-page-A77YAB5Y.js} +1 -1
  87. package/dist/dashboard-web/chunks/{groups-page-74TS2DIH.js → groups-page-RUZNVXQB.js} +1 -1
  88. package/dist/dashboard-web/chunks/{insights-page-AYCO65JC.js → insights-page-RF7U7RTA.js} +1 -1
  89. package/dist/dashboard-web/chunks/{monitor-room-YKYLTSAN.js → monitor-room-7IVIS75W.js} +1 -1
  90. package/dist/dashboard-web/chunks/{monitoring-page-QBIUNRBR.js → monitoring-page-5SSJRQZF.js} +1 -1
  91. package/dist/dashboard-web/chunks/{office-page-4PH2A26P.js → office-page-EOND3L5D.js} +1 -1
  92. package/dist/dashboard-web/chunks/{overview-page-H73D5UT4.js → overview-page-NISBVBBJ.js} +1 -1
  93. package/dist/dashboard-web/chunks/{roles-page-U4BTOQ7F.js → roles-page-BUMKD7Y4.js} +1 -1
  94. package/dist/dashboard-web/chunks/{schedules-page-RHRHX7R7.js → schedules-page-AVOOKLUH.js} +1 -1
  95. package/dist/dashboard-web/chunks/{sessions-page-VSC6AM5G.js → sessions-page-6HLSEAB7.js} +2 -2
  96. package/dist/dashboard-web/chunks/{settings-page-LF3RKM5P.js → settings-page-MJDZHQ4X.js} +1 -1
  97. package/dist/dashboard-web/chunks/{skills-page-SYOIGGXH.js → skills-page-5MW54PCC.js} +1 -1
  98. package/dist/dashboard-web/chunks/{team-federation-page-RMBLASTW.js → team-federation-page-2SNIMVXI.js} +1 -1
  99. package/dist/dashboard-web/chunks/{v3-page-XJXKKJRN.js → v3-page-W6SBXXQC.js} +1 -1
  100. package/dist/dashboard-web/chunks/{whiteboards-page-K3YVSTHJ.js → whiteboards-page-STC54KTP.js} +1 -1
  101. package/dist/dashboard-web/style.css +5 -0
  102. package/dist/dashboard.js +2 -2
  103. package/dist/dashboard.js.map +1 -1
  104. package/dist/desktop/main/dashboard-compat.js +1 -1
  105. package/dist/i18n/en.js +6 -6
  106. package/dist/i18n/en.js.map +1 -1
  107. package/dist/i18n/zh.js +6 -6
  108. package/dist/i18n/zh.js.map +1 -1
  109. package/dist/im/lark/card-builder.d.ts.map +1 -1
  110. package/dist/im/lark/card-builder.js +5 -4
  111. package/dist/im/lark/card-builder.js.map +1 -1
  112. package/dist/im/lark/card-handler.d.ts.map +1 -1
  113. package/dist/im/lark/card-handler.js +40 -7
  114. package/dist/im/lark/card-handler.js.map +1 -1
  115. package/dist/im/lark/client.d.ts.map +1 -1
  116. package/dist/im/lark/client.js +82 -1
  117. package/dist/im/lark/client.js.map +1 -1
  118. package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
  119. package/dist/im/lark/event-dispatcher.js +46 -12
  120. package/dist/im/lark/event-dispatcher.js.map +1 -1
  121. package/dist/im/lark/relay-target-routing.d.ts.map +1 -1
  122. package/dist/im/lark/relay-target-routing.js +12 -11
  123. package/dist/im/lark/relay-target-routing.js.map +1 -1
  124. package/dist/im/lark/reply-mode-command.d.ts.map +1 -1
  125. package/dist/im/lark/reply-mode-command.js +4 -3
  126. package/dist/im/lark/reply-mode-command.js.map +1 -1
  127. package/dist/index-daemon.js +6 -1
  128. package/dist/index-daemon.js.map +1 -1
  129. package/dist/mir-runner.js +1 -1
  130. package/dist/mir-runner.js.map +1 -1
  131. package/dist/services/bot-config-store.d.ts +1 -1
  132. package/dist/services/bot-config-store.d.ts.map +1 -1
  133. package/dist/services/bot-config-store.js +1 -1
  134. package/dist/services/bot-config-store.js.map +1 -1
  135. package/dist/services/card-prefs-store.js +8 -8
  136. package/dist/services/card-prefs-store.js.map +1 -1
  137. package/dist/services/chat-reply-mode-store.d.ts.map +1 -1
  138. package/dist/services/chat-reply-mode-store.js +16 -11
  139. package/dist/services/chat-reply-mode-store.js.map +1 -1
  140. package/dist/services/insight/types.d.ts +3 -1
  141. package/dist/services/insight/types.d.ts.map +1 -1
  142. package/dist/services/insight/types.js.map +1 -1
  143. package/dist/services/project-scanner.d.ts +4 -4
  144. package/dist/services/project-scanner.d.ts.map +1 -1
  145. package/dist/services/project-scanner.js +13 -5
  146. package/dist/services/project-scanner.js.map +1 -1
  147. package/dist/services/transcript-resolver.d.ts +4 -0
  148. package/dist/services/transcript-resolver.d.ts.map +1 -1
  149. package/dist/services/transcript-resolver.js +53 -5
  150. package/dist/services/transcript-resolver.js.map +1 -1
  151. package/dist/services/usage-ledger.d.ts.map +1 -1
  152. package/dist/services/usage-ledger.js +1 -0
  153. package/dist/services/usage-ledger.js.map +1 -1
  154. package/dist/setup/bot-config-editor.d.ts +37 -1
  155. package/dist/setup/bot-config-editor.d.ts.map +1 -1
  156. package/dist/setup/bot-config-editor.js +61 -3
  157. package/dist/setup/bot-config-editor.js.map +1 -1
  158. package/dist/setup/setup-args.js +1 -1
  159. package/dist/setup/setup-args.js.map +1 -1
  160. package/dist/types.d.ts +20 -0
  161. package/dist/types.d.ts.map +1 -1
  162. package/dist/utils/allowed-users-apply.d.ts.map +1 -1
  163. package/dist/utils/allowed-users-apply.js +3 -2
  164. package/dist/utils/allowed-users-apply.js.map +1 -1
  165. package/dist/utils/child-env.d.ts +31 -2
  166. package/dist/utils/child-env.d.ts.map +1 -1
  167. package/dist/utils/child-env.js +61 -3
  168. package/dist/utils/child-env.js.map +1 -1
  169. package/dist/utils/file-lock.d.ts +10 -0
  170. package/dist/utils/file-lock.d.ts.map +1 -1
  171. package/dist/utils/file-lock.js +295 -53
  172. package/dist/utils/file-lock.js.map +1 -1
  173. package/dist/worker.js +52 -3
  174. package/dist/worker.js.map +1 -1
  175. package/dist/workflows/v3/run-envelope.d.ts +24 -24
  176. package/package.json +1 -1
  177. package/dist/dashboard-web/chunks/chunk-P327LXOT.js +0 -1
@@ -1 +1 @@
1
- import{a as Oe,b as He,c as Ve,d as _e}from"./chunk-R3FXBFQH.js";import{c as Ue}from"./chunk-JMRGZQDB.js";import{b as Fe,c as ne,h as le,p as se}from"./chunk-QFMH6ITB.js";import{C as $e,y as je}from"./chunk-SNKATZWK.js";import{a as re}from"./chunk-SYC6D5XU.js";import{a as Jt,d as De}from"./chunk-5THX4DI2.js";import{c as oe}from"./chunk-7SZRL6FY.js";var l=oe(Jt(),1);var w=32768,Je=Math.floor(w*.95),Kt=/^[A-Za-z0-9._-]{1,64}$/;function ae(n){return Kt.test(n)&&n!=="."&&n!==".."}function Ke(n=location.hash){let[,t=""]=n.split("?");return new URLSearchParams(t).get("chatId")?.trim()||null}function ie(n,t){return Ve(n,t)}function de(n){return new TextEncoder().encode(n).length}function ce(n){return n.memberBots.filter(t=>t.inChat&&t.hasRole).length}function We(n){return n.memberBots.filter(t=>t.inChat).length}function D(n,t){return t?n.find(o=>o.larkAppId===t):void 0}function qe(n,t){let o=t.toLowerCase();return o?n.filter(i=>{let d=i.chatId.toLowerCase().includes(o)||(i.name??"").toLowerCase().includes(o),y=i.memberBots.some(p=>p.larkAppId.toLowerCase().includes(o)||(p.botName??"").toLowerCase().includes(o));return d||y}):n}function Ye(n,t){let o=t.toLowerCase();return n.filter(i=>!o||i.profileId.toLowerCase().includes(o))}async function C(n){return n.json().catch(()=>({}))}async function ze(){let n=await fetch("/api/groups"),t=await C(n);return{bots:(t.bots??[]).map(o=>({larkAppId:o.larkAppId,botName:o.botName??o.larkAppId,botAvatarUrl:o.botAvatarUrl})),groups:(t.chats??[]).map(o=>({chatId:o.chatId,name:o.name??o.chatId,memberBots:(o.memberBots??[]).map(i=>({larkAppId:i.larkAppId,botName:i.botName??i.larkAppId,inChat:i.inChat??!1,hasRole:i.hasRole??!1,oncallChat:i.oncallChat??null}))}))}}async function Xe(){let n=await fetch("/api/role-profiles");return(await C(n)).profiles??[]}async function x(n){let t=await fetch(`/api/role-profiles/${encodeURIComponent(n)}`);return(await C(t)).entries??[]}async function pe(n,t){let o=await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`);return C(o)}async function Ze(n,t,o,i){return(await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:o,injectMode:i})})).ok}async function Qe(n,t,o){return(await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({injectMode:o})})).ok}async function et(n,t){return(await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"DELETE"})).ok}async function tt(n,t){let o=await fetch(`/api/role-profiles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`);return C(o)}async function ot(n,t,o){return(await fetch(`/api/role-profiles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:o,allowEmpty:!0})})).ok}async function rt(n,t){return(await fetch(`/api/role-profiles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"DELETE"})).ok}async function nt(n,t){let o=await Promise.all(t.map(async p=>{try{let c=await fetch(`/api/role-profiles/${encodeURIComponent(p.profileId)}`),f=await C(c);return[p.profileId,Array.isArray(f.entries)?f.entries:[]]}catch{return[p.profileId,[]]}})),i=new Set,d=[];for(let p of n)for(let c of p.memberBots){if(!c.inChat||!c.hasRole)continue;let f=ie(c.larkAppId,p.chatId);i.has(f)||(i.add(f),d.push({larkAppId:c.larkAppId,chatId:p.chatId}))}let y=await _e(d);return{entriesByProfile:new Map(o),effectiveRolesByBot:y}}async function lt(n){let t=await fetch(`/api/role-profiles/${encodeURIComponent(n.profileId)}/apply`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({chatId:n.chatId,larkAppId:n.larkAppId,force:n.force,preview:n.preview})}),o=await C(t);return{larkAppId:n.larkAppId,ok:t.ok&&o.ok!==!1,status:t.status,error:o.error,wouldRefuse:o.wouldRefuse}}var e=oe(De(),1);function Wt(){let n=(0,l.useRef)(!0);return(0,l.useEffect)(()=>(n.current=!0,()=>{n.current=!1}),[]),n}function qt(){let n=(0,l.useRef)(new Set);return(0,l.useEffect)(()=>()=>{for(let t of n.current)window.clearTimeout(t);n.current.clear()},[]),(0,l.useCallback)((t,o)=>{let i=window.setTimeout(()=>{n.current.delete(i),t()},o);return n.current.add(i),i},[])}function it(n){return(0,e.jsx)(Fe,{html:je({name:n.bot.botName,larkAppId:n.bot.larkAppId,avatarUrl:n.bot.botAvatarUrl,size:"sm"})})}function dt(n){let t=Ue(),o=Wt(),i=qt(),[d,y]=(0,l.useState)([]),[p,c]=(0,l.useState)([]),[f,P]=(0,l.useState)([]),[ct,ue]=(0,l.useState)({entriesByProfile:new Map,effectiveRolesByBot:new Map}),[pt,F]=(0,l.useState)(!1),[ft,J]=(0,l.useState)(!0),[ut,K]=(0,l.useState)(!0),[W,mt]=(0,l.useState)(""),[q,vt]=(0,l.useState)(""),[ht,me]=(0,l.useState)(()=>new Set),[v,ve]=(0,l.useState)(null),[h,he]=(0,l.useState)(null),[yt,U]=(0,l.useState)(null),[R,O]=(0,l.useState)(""),[S,E]=(0,l.useState)("every"),[ye,ge]=(0,l.useState)(!1),[Ie,be]=(0,l.useState)(!1),[gt,Pe]=(0,l.useState)(!1),[It,Y]=(0,l.useState)(null),[bt,Re]=(0,l.useState)(null),[m,Pt]=(0,l.useState)(null),[I,ke]=(0,l.useState)(null),[B,M]=(0,l.useState)([]),[L,H]=(0,l.useState)(""),[k,G]=(0,l.useState)(null),[Ne,Rt]=(0,l.useState)(!1),[we,Ce]=(0,l.useState)(()=>new Set),[Ae,xe]=(0,l.useState)(!1),[Se,Ee]=(0,l.useState)(!1),[kt,z]=(0,l.useState)(null),[Nt,T]=(0,l.useState)({kind:"idle"}),Be=(0,l.useRef)(0),j=(0,l.useRef)(0),Me=(0,l.useRef)(null),X=v?d.find(r=>r.chatId===v):void 0,wt=X&&h?X.memberBots.find(r=>r.larkAppId===h):void 0,Z=I?p.find(r=>r.larkAppId===I):void 0,Ct=D(B,I),Q=k?d.find(r=>r.chatId===k):void 0,V=Q?.memberBots.filter(r=>r.inChat)??[],At=V.map(r=>r.larkAppId).join("\0"),xt=B.map(r=>r.larkAppId).sort().join("\0"),St=(0,l.useMemo)(()=>qe(d,W),[d,W]),Et=(0,l.useMemo)(()=>Ye(f,q),[f,q]),ee=de(R),te=de(L),_=(0,l.useCallback)((r,s,a=!1)=>{let u=Date.now()+Math.random();r({text:s,isError:a,id:u}),i(()=>{r(g=>g?.id===u?null:g)},a?3e3:2e3)},[i]),b=(0,l.useCallback)(async(r,s)=>{try{let a=await nt(r,s);if(!o.current)return;ue(a),F(!0)}catch{if(!o.current)return;ue({entriesByProfile:new Map,effectiveRolesByBot:new Map}),F(!0)}},[o]),N=(0,l.useCallback)(async()=>{let r=await ze();return o.current&&(y(r.groups),c(r.bots)),r},[o]),$=(0,l.useCallback)(async()=>{let r=await Xe();return o.current&&P(r),r},[o]),Le=(0,l.useCallback)(async()=>{J(!0),K(!0),F(!1);try{let r=await N();if(!o.current)return;let s=await $();if(!o.current||(await $e(),!o.current))return;if(me(new Set(r.groups.filter(a=>ce(a)>0).map(a=>a.chatId))),n.tab==="profiles"){let a=Ke();G(u=>u||(a&&r.groups.some(g=>g.chatId===a)?a:r.groups[0]?.chatId??null))}else G(a=>a??r.groups[0]?.chatId??null);J(!1),K(!1),b(r.groups,s)}catch{if(!o.current)return;J(!1),K(!1),F(!0)}},[o,n.tab,N,$,b]);(0,l.useEffect)(()=>{Le()},[Le]),(0,l.useEffect)(()=>{k||d.length===0||G(d[0].chatId)},[d,k]),(0,l.useEffect)(()=>{let r=new Set(V.filter(s=>!!D(B,s.larkAppId)).map(s=>s.larkAppId));Ce(r),T({kind:"idle"})},[xt,At]);async function Bt(r,s){let a=++Be.current;ve(r),he(s);let u=await pe(s,r);!o.current||a!==Be.current||(U(u),O(u.content??""),E(u.injectMode==="once"?"once":"every"),Y(null),Re(null))}async function Mt(){let r=await N();if(o.current&&(b(r.groups,f),v&&h)){let s=await pe(h,v);if(!o.current)return;U(s),O(s.content??""),E(s.injectMode==="once"?"once":"every")}}async function Lt(){if(!(!v||!h)){ge(!0);try{let r=await Ze(h,v,R,S);if(!o.current)return;if(r){let s=await N();if(!o.current)return;U(a=>a&&{...a,content:R,hasRole:!0,injectMode:S}),b(s.groups,f),_(Y,t("roles.saved"))}else _(Y,R.trim().length===0?t("roles.emptyError"):t("roles.saveFailed"),!0)}finally{o.current&&ge(!1)}}}async function Gt(){if(!(!v||!h)&&confirm(t("roles.confirmDelete"))){be(!0);try{let r=await et(h,v);if(!o.current)return;if(r){let s=await N();if(!o.current)return;ve(null),he(null),U(null),O(""),E("every"),b(s.groups,f)}}finally{o.current&&be(!1)}}}async function Tt(r){if(!v||!h)return;let s=S;E(r),Pe(!0);try{let a=await Qe(h,v,r);if(!o.current)return;a||E(s),_(Re,t(a?"roles.saved":"roles.saveFailed"),!a)}finally{o.current&&Pe(!1)}}async function Ge(r){let s=r.trim();if(!ae(s))return;let a=++j.current;Pt(s),ke(null),H(""),T({kind:"idle"}),G(g=>g??d[0]?.chatId??null);let u=await x(s);!o.current||a!==j.current||(M(u),z(null))}async function jt(r){if(!m)return;let s=++j.current;ke(r);let a=await tt(m,r);if(!o.current||s!==j.current)return;H(a.content??"");let u=await x(m);!o.current||s!==j.current||(M(u),z(null))}async function $t(){let r=await N();if(!o.current)return;let s=await $();if(o.current){if(m){let a=await x(m);if(!o.current)return;M(a)}b(r.groups,s)}}async function Dt(){let r=Me.current,s=r?.value.trim()??"";if(s){if(!ae(s)){r?.setCustomValidity(t("roles.profileIdInvalid")),r?.reportValidity();return}r?.setCustomValidity(""),await Ge(s),o.current&&(location.hash.startsWith("#/roles/profile")||(location.hash="#/roles/profile"))}}async function Ft(){if(!(!m||!I)){xe(!0);try{let r=await ot(m,I,L);if(!o.current)return;let s=await $();if(!o.current)return;let a=await x(m);if(!o.current)return;M(a),b(d,s),_(z,t(r?"roles.saved":"roles.saveFailed"),!r)}finally{o.current&&xe(!1)}}}async function Ut(){if(!(!m||!I)&&confirm(t("roles.confirmDeleteProfileEntry"))){Ee(!0);try{if(await rt(m,I),!o.current)return;H("");let r=await $();if(!o.current)return;let s=await x(m);if(!o.current)return;M(s),b(d,r)}finally{o.current&&Ee(!1)}}}function Ot(r,s){Ce(a=>{let u=new Set(a);return s?u.add(r):u.delete(r),u})}async function Te(r){if(!m)return;let s=k??d[0]?.chatId;if(!s)return;let a=[...we];if(a.length===0){T({kind:"text",text:t("roles.applyPickBots")});return}T({kind:"text",text:"..."});let u=await Promise.all(a.map(g=>lt({profileId:m,chatId:s,larkAppId:g,force:Ne,preview:r})));if(o.current&&(T({kind:"results",preview:r,results:u}),!r)){let g=await N();if(!o.current)return;b(g.groups,f)}}let Ht=ye||ee>w||R.trim().length===0,Vt=Ae||te>w||L.trim().length===0,A=n.tab==="profiles",_t=(0,e.jsxs)("nav",{className:"roles-subnav insight-tabs",role:"tablist","aria-label":t("roles.title"),children:[(0,e.jsx)("a",{href:"#/roles",className:`itab${A?"":" on"}`,role:"tab","aria-selected":!A,children:t("roles.tabGroups")}),(0,e.jsx)("a",{href:"#/roles/profile",className:`itab${A?" on":""}`,role:"tab","aria-selected":A,children:t("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:t("nav.roles")}),(0,e.jsx)("h1",{children:t("roles.title")})]}),(0,e.jsx)("div",{className:"page-heading-actions",children:_t})]}),(0,e.jsxs)("div",{id:"roles-by-group-view",className:"roles-layout",hidden:A,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:t("roles.search"),value:W,onChange:r=>mt(r.target.value)}),(0,e.jsx)(le,{id:"roles-refresh",label:t("roles.refresh"),onClick:()=>{Mt()}})]}),(0,e.jsx)("div",{id:"roles-tree",className:"roles-tree",children:ft?(0,e.jsx)(ne,{label:t("common.loading")}):(0,e.jsx)(zt,{groups:St,profiles:f,context:ct,contextLoaded:pt,expandedGroups:ht,selectedGroupId:v,selectedBotId:h,tr:t,onToggleGroup:r=>me(s=>Yt(s,r)),onSelectBot:(r,s)=>{Bt(r,s)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:!v||!h?(0,e.jsx)("div",{id:"roles-editor-empty",className:"roles-editor-empty",children:t("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:X?.name??v}),(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{id:"roles-editor-bot-name",children:wt?.botName??h})]}),(0,e.jsx)("div",{className:"roles-editor-meta",children:(0,e.jsxs)("span",{id:"roles-editor-chat-id",className:"roles-editor-meta-line",children:[v," \xB7 ",h]})})]}),(0,e.jsxs)("div",{className:"roles-editor-actions roles-editor-head-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-delete",className:"danger",style:{display:yt?.hasRole?"":"none"},disabled:Ie,onClick:()=>{Gt()},children:Ie?"...":t("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-save",className:"primary",disabled:Ht,onClick:()=>{Lt()},children:ye?"...":t("roles.save")})]})]}),(0,e.jsxs)("div",{className:"roles-editor-inject",children:[(0,e.jsx)("span",{className:"roles-field-label",children:t("roles.injectModeLabel")}),(0,e.jsx)(se,{id:"roles-editor-inject-mode",className:"roles-inline-menu",ariaLabel:t("roles.injectModeLabel"),disabled:gt,label:t(S==="once"?"roles.injectModeOnce":"roles.injectModeEvery"),value:S,options:[{value:"every",label:t("roles.injectModeEvery")},{value:"once",label:t("roles.injectModeOnce")}],onChange:r=>{Tt(r==="once"?"once":"every")}}),(0,e.jsx)("span",{className:"roles-editor-inject-hint",children:t("roles.injectModeHint")}),(0,e.jsx)(fe,{flash:bt})]}),(0,e.jsx)("textarea",{id:"roles-editor-textarea",placeholder:t("roles.editorPlaceholder"),rows:14,value:R,onChange:r=>O(r.target.value)}),(0,e.jsxs)("div",{className:"roles-editor-footer",children:[(0,e.jsxs)("span",{id:"roles-editor-bytecount",className:st(ee),children:[ee," / ",w," bytes"]}),(0,e.jsx)(fe,{flash:It})]}),(0,e.jsx)(at,{content:R,tr:t,id:"roles-preview"})]})})]}),(0,e.jsxs)("div",{id:"roles-profiles-view",className:"roles-layout roles-profiles-layout",hidden:!A,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:t("roles.profileIdPlaceholder"),maxLength:64,ref:Me,onChange:r=>r.currentTarget.setCustomValidity("")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-select",onClick:()=>{Dt()},children:t("roles.openProfile")})]}),(0,e.jsxs)("div",{className:"roles-tree-header dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",id:"roles-profile-search",placeholder:t("roles.profileSearch"),value:q,onChange:r=>vt(r.target.value)}),(0,e.jsx)(le,{id:"roles-profile-refresh",label:t("roles.refresh"),onClick:()=>{$t()}})]}),(0,e.jsx)("div",{id:"roles-profile-list",className:"roles-tree",children:ut?(0,e.jsx)(ne,{label:t("common.loading")}):(0,e.jsx)(Zt,{profiles:Et,selectedProfileId:m,tr:t,onSelect:r=>{Ge(r)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:m?(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:m}),Z?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{children:Z.botName??Z.larkAppId})]}):null]}),(0,e.jsx)("div",{className:"roles-editor-meta-line",children:t("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:t("roles.profileBots")}),(0,e.jsx)("div",{className:"roles-profile-bot-list",children:p.map(r=>{let s=!!D(B,r.larkAppId),a=I===r.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row roles-profile-bot-row ${a?"selected":""}`,"data-profile-bot-id":r.larkAppId,onClick:()=>{jt(r.larkAppId)},children:[(0,e.jsx)(it,{bot:r}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:r.botName??r.larkAppId}),(0,e.jsx)("div",{className:"roles-bot-id",children:r.larkAppId})]}),(0,e.jsx)("span",{className:`roles-badge ${s?"has-role":"no-role"}`,children:t(s?"roles.configured":"roles.unconfigured")})]},r.larkAppId)})})]}),(0,e.jsx)("div",{className:"roles-profile-editor",children:I?(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:st(te),children:[te," / ",w," 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:Ct?"":"none"},disabled:Se,onClick:()=>{Ut()},children:Se?"...":t("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-save",className:"primary",disabled:Vt,onClick:()=>{Ft()},children:Ae?"...":t("roles.saveEntry")})]})]}),(0,e.jsx)("textarea",{id:"roles-profile-textarea",placeholder:t("roles.profileEditorPlaceholder"),rows:12,value:L,onChange:r=>H(r.target.value)}),(0,e.jsx)("div",{className:"roles-editor-footer",children:(0,e.jsx)(fe,{flash:kt})}),(0,e.jsx)(at,{content:L,tr:t,id:"roles-profile-preview"})]}):(0,e.jsx)("div",{className:"roles-editor-empty roles-profile-inline-empty",children:t("roles.profileBotSelectHint")})})]}),(0,e.jsxs)("div",{className:"roles-profile-apply",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:t("roles.applyToGroup")}),(0,e.jsxs)("div",{className:"roles-profile-apply-controls",children:[(0,e.jsx)(se,{id:"roles-profile-apply-group",className:"roles-apply-group-menu",ariaLabel:t("roles.applyToGroup"),disabled:d.length===0,label:Q?.name??k??t("roles.noChats"),value:k??"",options:d.map(r=>({value:r.chatId,label:r.name??r.chatId})),onChange:r=>G(r)}),(0,e.jsxs)("label",{className:"roles-profile-force",children:[(0,e.jsx)("input",{type:"checkbox",id:"roles-profile-apply-force",checked:Ne,onChange:r=>Rt(r.target.checked)})," ",t("roles.applyForce")]})]}),(0,e.jsx)("div",{id:"roles-profile-apply-bots",children:!Q||V.length===0?(0,e.jsx)("div",{className:"roles-empty",children:t("roles.noChats")}):V.map(r=>{let s=!!D(B,r.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:r.larkAppId,checked:we.has(r.larkAppId),onChange:a=>Ot(r.larkAppId,a.target.checked)}),(0,e.jsx)("span",{children:r.botName??r.larkAppId}),(0,e.jsx)("small",{children:t(s?"roles.configured":"roles.profileMissing")})]},r.larkAppId)})}),(0,e.jsxs)("div",{className:"roles-editor-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-profile-preview-apply",onClick:()=>{Te(!0)},children:t("roles.previewApply")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-apply",className:"primary",onClick:()=>{Te(!1)},children:t("roles.applyProfile")})]}),(0,e.jsx)("div",{id:"roles-profile-apply-status",className:"roles-profile-status",children:(0,e.jsx)(Qt,{status:Nt,bots:p,tr:t})})]})]}):(0,e.jsx)("div",{id:"roles-profile-empty",className:"roles-editor-empty",children:t("roles.profileSelectHint")})})]})]})}function Yt(n,t){let o=new Set(n);return o.has(t)?o.delete(t):o.add(t),o}function st(n){return`roles-bytecount ${n>Je?"warn":""} ${n>w?"over":""}`}function fe(n){return n.flash?(0,e.jsxs)("span",{className:`roles-saved-flash ${n.flash.isError?"roles-save-error":""}`,children:[" ",n.flash.text]}):null}function zt(n){let{tr:t}=n;return n.groups.length===0?(0,e.jsx)("div",{className:"roles-empty",children:t("roles.noChats")}):(0,e.jsx)(e.Fragment,{children:n.groups.map(o=>{let i=n.expandedGroups.has(o.chatId),d=o.memberBots.filter(c=>c.inChat),y=ce(o),p=We(o);return(0,e.jsxs)("div",{className:"roles-group-section",children:[(0,e.jsxs)("div",{className:`roles-group-row ${i?"expanded":""} ${n.selectedGroupId===o.chatId&&!n.selectedBotId?"selected":""}`,"data-group-id":o.chatId,onClick:()=>n.onToggleGroup(o.chatId),children:[(0,e.jsx)("span",{className:"roles-group-arrow",children:i?"\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:o.name??o.chatId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[y,"/",p," ",t("roles.botsWithRoles")]}),(0,e.jsx)(Xt,{group:o,profiles:n.profiles,context:n.context,loaded:n.contextLoaded,tr:t})]}),(0,e.jsx)("span",{className:"roles-group-chevron"})]}),(0,e.jsx)("div",{className:"roles-bot-list",children:i?d.map(c=>{let f=n.selectedGroupId===o.chatId&&n.selectedBotId===c.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row ${f?"selected":""}`,"data-group-id":o.chatId,"data-bot-id":c.larkAppId,onClick:P=>{P.stopPropagation(),n.onSelectBot(o.chatId,c.larkAppId)},children:[(0,e.jsx)("span",{className:"roles-bot-indent"}),(0,e.jsx)(it,{bot:c}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:c.botName}),(0,e.jsx)("div",{className:"roles-bot-id",children:c.larkAppId})]}),(0,e.jsx)("span",{className:`roles-badge ${c.hasRole?"has-role":"no-role"}`,children:c.hasRole?t("roles.configured"):t("roles.unconfigured")})]},c.larkAppId)}):null})]},o.chatId)})})}function Xt(n){let{group:t,profiles:o,context:i,loaded:d,tr:y}=n;if(!o.length||!d)return null;let p=new Map;for(let P of t.memberBots)P.inChat&&p.set(P.larkAppId,i.effectiveRolesByBot.get(ie(P.larkAppId,t.chatId))??null);if(!Oe(p))return null;let c=He(t.memberBots,o,i.entriesByProfile,p)[0];if(!c)return(0,e.jsx)("div",{className:"roles-profile-match muted",children:y("groups.profileStatusUnmatched")});let f=c.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`roles-profile-match ${c.kind}`,children:y(f,{name:c.profileId,matched:c.matched,total:c.total,chat:c.chatMatched})})}function at(n){return(0,e.jsx)("div",{id:n.id,className:"roles-preview",children:n.content.trim()?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("strong",{children:n.tr("roles.preview")}),(0,e.jsx)("pre",{children:n.content})]}):(0,e.jsx)("small",{children:n.tr("roles.previewEmpty")})})}function Zt(n){let{tr:t}=n;return n.profiles.length===0?(0,e.jsx)("div",{className:"roles-empty",children:t("roles.profileEmpty")}):(0,e.jsx)(e.Fragment,{children:n.profiles.map(o=>{let i=n.selectedProfileId===o.profileId,d=(o.botEntries??[]).some(y=>y.hasEntry);return(0,e.jsxs)("div",{className:`roles-profile-row ${i?"selected":""}`,"data-profile-id":o.profileId,onClick:()=>n.onSelect(o.profileId),children:[(0,e.jsxs)("div",{className:"roles-profile-row-main",children:[(0,e.jsx)("div",{className:"roles-profile-name",children:o.profileId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[o.entryCount," ",t("roles.profileEntries")]})]}),(0,e.jsx)("span",{className:`roles-badge ${d?"has-role":"no-role"}`,children:t(d?"roles.configured":"roles.profileMissing")})]},o.profileId)})})}function Qt(n){let{status:t,bots:o,tr:i}=n;return t.kind==="idle"?null:t.kind==="text"?(0,e.jsx)(e.Fragment,{children:t.text}):(0,e.jsx)(e.Fragment,{children:t.results.map(d=>{let p=o.find(f=>f.larkAppId===d.larkAppId)?.botName??d.larkAppId,c=d.ok?t.preview?d.wouldRefuse?i("roles.applyWouldRefuse"):i("roles.applyPreviewOk"):i("roles.applyOk"):`${i("roles.applyFailed")}: ${String(d.error??`HTTP ${d.status}`)}`;return(0,e.jsxs)("div",{children:[p,": ",c]},d.larkAppId)})})}function io(n){return re(n,(0,e.jsx)(dt,{tab:"groups"}))}function co(n){return re(n,(0,e.jsx)(dt,{tab:"profiles"}))}export{co as renderRoleProfilesPage,io as renderRolesPage};
1
+ import{a as Oe,b as He,c as Ve,d as _e}from"./chunk-R3FXBFQH.js";import{c as Ue}from"./chunk-FLGXZJTD.js";import{b as Fe,c as ne,h as le,p as se}from"./chunk-QFMH6ITB.js";import{C as $e,y as je}from"./chunk-KQB42ML5.js";import{a as re}from"./chunk-SYC6D5XU.js";import{a as Jt,d as De}from"./chunk-5THX4DI2.js";import{c as oe}from"./chunk-7SZRL6FY.js";var l=oe(Jt(),1);var w=32768,Je=Math.floor(w*.95),Kt=/^[A-Za-z0-9._-]{1,64}$/;function ae(n){return Kt.test(n)&&n!=="."&&n!==".."}function Ke(n=location.hash){let[,t=""]=n.split("?");return new URLSearchParams(t).get("chatId")?.trim()||null}function ie(n,t){return Ve(n,t)}function de(n){return new TextEncoder().encode(n).length}function ce(n){return n.memberBots.filter(t=>t.inChat&&t.hasRole).length}function We(n){return n.memberBots.filter(t=>t.inChat).length}function D(n,t){return t?n.find(o=>o.larkAppId===t):void 0}function qe(n,t){let o=t.toLowerCase();return o?n.filter(i=>{let d=i.chatId.toLowerCase().includes(o)||(i.name??"").toLowerCase().includes(o),y=i.memberBots.some(p=>p.larkAppId.toLowerCase().includes(o)||(p.botName??"").toLowerCase().includes(o));return d||y}):n}function Ye(n,t){let o=t.toLowerCase();return n.filter(i=>!o||i.profileId.toLowerCase().includes(o))}async function C(n){return n.json().catch(()=>({}))}async function ze(){let n=await fetch("/api/groups"),t=await C(n);return{bots:(t.bots??[]).map(o=>({larkAppId:o.larkAppId,botName:o.botName??o.larkAppId,botAvatarUrl:o.botAvatarUrl})),groups:(t.chats??[]).map(o=>({chatId:o.chatId,name:o.name??o.chatId,memberBots:(o.memberBots??[]).map(i=>({larkAppId:i.larkAppId,botName:i.botName??i.larkAppId,inChat:i.inChat??!1,hasRole:i.hasRole??!1,oncallChat:i.oncallChat??null}))}))}}async function Xe(){let n=await fetch("/api/role-profiles");return(await C(n)).profiles??[]}async function x(n){let t=await fetch(`/api/role-profiles/${encodeURIComponent(n)}`);return(await C(t)).entries??[]}async function pe(n,t){let o=await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`);return C(o)}async function Ze(n,t,o,i){return(await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:o,injectMode:i})})).ok}async function Qe(n,t,o){return(await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({injectMode:o})})).ok}async function et(n,t){return(await fetch(`/api/roles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"DELETE"})).ok}async function tt(n,t){let o=await fetch(`/api/role-profiles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`);return C(o)}async function ot(n,t,o){return(await fetch(`/api/role-profiles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:o,allowEmpty:!0})})).ok}async function rt(n,t){return(await fetch(`/api/role-profiles/${encodeURIComponent(n)}/${encodeURIComponent(t)}`,{method:"DELETE"})).ok}async function nt(n,t){let o=await Promise.all(t.map(async p=>{try{let c=await fetch(`/api/role-profiles/${encodeURIComponent(p.profileId)}`),f=await C(c);return[p.profileId,Array.isArray(f.entries)?f.entries:[]]}catch{return[p.profileId,[]]}})),i=new Set,d=[];for(let p of n)for(let c of p.memberBots){if(!c.inChat||!c.hasRole)continue;let f=ie(c.larkAppId,p.chatId);i.has(f)||(i.add(f),d.push({larkAppId:c.larkAppId,chatId:p.chatId}))}let y=await _e(d);return{entriesByProfile:new Map(o),effectiveRolesByBot:y}}async function lt(n){let t=await fetch(`/api/role-profiles/${encodeURIComponent(n.profileId)}/apply`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({chatId:n.chatId,larkAppId:n.larkAppId,force:n.force,preview:n.preview})}),o=await C(t);return{larkAppId:n.larkAppId,ok:t.ok&&o.ok!==!1,status:t.status,error:o.error,wouldRefuse:o.wouldRefuse}}var e=oe(De(),1);function Wt(){let n=(0,l.useRef)(!0);return(0,l.useEffect)(()=>(n.current=!0,()=>{n.current=!1}),[]),n}function qt(){let n=(0,l.useRef)(new Set);return(0,l.useEffect)(()=>()=>{for(let t of n.current)window.clearTimeout(t);n.current.clear()},[]),(0,l.useCallback)((t,o)=>{let i=window.setTimeout(()=>{n.current.delete(i),t()},o);return n.current.add(i),i},[])}function it(n){return(0,e.jsx)(Fe,{html:je({name:n.bot.botName,larkAppId:n.bot.larkAppId,avatarUrl:n.bot.botAvatarUrl,size:"sm"})})}function dt(n){let t=Ue(),o=Wt(),i=qt(),[d,y]=(0,l.useState)([]),[p,c]=(0,l.useState)([]),[f,P]=(0,l.useState)([]),[ct,ue]=(0,l.useState)({entriesByProfile:new Map,effectiveRolesByBot:new Map}),[pt,F]=(0,l.useState)(!1),[ft,J]=(0,l.useState)(!0),[ut,K]=(0,l.useState)(!0),[W,mt]=(0,l.useState)(""),[q,vt]=(0,l.useState)(""),[ht,me]=(0,l.useState)(()=>new Set),[v,ve]=(0,l.useState)(null),[h,he]=(0,l.useState)(null),[yt,U]=(0,l.useState)(null),[R,O]=(0,l.useState)(""),[S,E]=(0,l.useState)("every"),[ye,ge]=(0,l.useState)(!1),[Ie,be]=(0,l.useState)(!1),[gt,Pe]=(0,l.useState)(!1),[It,Y]=(0,l.useState)(null),[bt,Re]=(0,l.useState)(null),[m,Pt]=(0,l.useState)(null),[I,ke]=(0,l.useState)(null),[B,M]=(0,l.useState)([]),[L,H]=(0,l.useState)(""),[k,G]=(0,l.useState)(null),[Ne,Rt]=(0,l.useState)(!1),[we,Ce]=(0,l.useState)(()=>new Set),[Ae,xe]=(0,l.useState)(!1),[Se,Ee]=(0,l.useState)(!1),[kt,z]=(0,l.useState)(null),[Nt,T]=(0,l.useState)({kind:"idle"}),Be=(0,l.useRef)(0),j=(0,l.useRef)(0),Me=(0,l.useRef)(null),X=v?d.find(r=>r.chatId===v):void 0,wt=X&&h?X.memberBots.find(r=>r.larkAppId===h):void 0,Z=I?p.find(r=>r.larkAppId===I):void 0,Ct=D(B,I),Q=k?d.find(r=>r.chatId===k):void 0,V=Q?.memberBots.filter(r=>r.inChat)??[],At=V.map(r=>r.larkAppId).join("\0"),xt=B.map(r=>r.larkAppId).sort().join("\0"),St=(0,l.useMemo)(()=>qe(d,W),[d,W]),Et=(0,l.useMemo)(()=>Ye(f,q),[f,q]),ee=de(R),te=de(L),_=(0,l.useCallback)((r,s,a=!1)=>{let u=Date.now()+Math.random();r({text:s,isError:a,id:u}),i(()=>{r(g=>g?.id===u?null:g)},a?3e3:2e3)},[i]),b=(0,l.useCallback)(async(r,s)=>{try{let a=await nt(r,s);if(!o.current)return;ue(a),F(!0)}catch{if(!o.current)return;ue({entriesByProfile:new Map,effectiveRolesByBot:new Map}),F(!0)}},[o]),N=(0,l.useCallback)(async()=>{let r=await ze();return o.current&&(y(r.groups),c(r.bots)),r},[o]),$=(0,l.useCallback)(async()=>{let r=await Xe();return o.current&&P(r),r},[o]),Le=(0,l.useCallback)(async()=>{J(!0),K(!0),F(!1);try{let r=await N();if(!o.current)return;let s=await $();if(!o.current||(await $e(),!o.current))return;if(me(new Set(r.groups.filter(a=>ce(a)>0).map(a=>a.chatId))),n.tab==="profiles"){let a=Ke();G(u=>u||(a&&r.groups.some(g=>g.chatId===a)?a:r.groups[0]?.chatId??null))}else G(a=>a??r.groups[0]?.chatId??null);J(!1),K(!1),b(r.groups,s)}catch{if(!o.current)return;J(!1),K(!1),F(!0)}},[o,n.tab,N,$,b]);(0,l.useEffect)(()=>{Le()},[Le]),(0,l.useEffect)(()=>{k||d.length===0||G(d[0].chatId)},[d,k]),(0,l.useEffect)(()=>{let r=new Set(V.filter(s=>!!D(B,s.larkAppId)).map(s=>s.larkAppId));Ce(r),T({kind:"idle"})},[xt,At]);async function Bt(r,s){let a=++Be.current;ve(r),he(s);let u=await pe(s,r);!o.current||a!==Be.current||(U(u),O(u.content??""),E(u.injectMode==="once"?"once":"every"),Y(null),Re(null))}async function Mt(){let r=await N();if(o.current&&(b(r.groups,f),v&&h)){let s=await pe(h,v);if(!o.current)return;U(s),O(s.content??""),E(s.injectMode==="once"?"once":"every")}}async function Lt(){if(!(!v||!h)){ge(!0);try{let r=await Ze(h,v,R,S);if(!o.current)return;if(r){let s=await N();if(!o.current)return;U(a=>a&&{...a,content:R,hasRole:!0,injectMode:S}),b(s.groups,f),_(Y,t("roles.saved"))}else _(Y,R.trim().length===0?t("roles.emptyError"):t("roles.saveFailed"),!0)}finally{o.current&&ge(!1)}}}async function Gt(){if(!(!v||!h)&&confirm(t("roles.confirmDelete"))){be(!0);try{let r=await et(h,v);if(!o.current)return;if(r){let s=await N();if(!o.current)return;ve(null),he(null),U(null),O(""),E("every"),b(s.groups,f)}}finally{o.current&&be(!1)}}}async function Tt(r){if(!v||!h)return;let s=S;E(r),Pe(!0);try{let a=await Qe(h,v,r);if(!o.current)return;a||E(s),_(Re,t(a?"roles.saved":"roles.saveFailed"),!a)}finally{o.current&&Pe(!1)}}async function Ge(r){let s=r.trim();if(!ae(s))return;let a=++j.current;Pt(s),ke(null),H(""),T({kind:"idle"}),G(g=>g??d[0]?.chatId??null);let u=await x(s);!o.current||a!==j.current||(M(u),z(null))}async function jt(r){if(!m)return;let s=++j.current;ke(r);let a=await tt(m,r);if(!o.current||s!==j.current)return;H(a.content??"");let u=await x(m);!o.current||s!==j.current||(M(u),z(null))}async function $t(){let r=await N();if(!o.current)return;let s=await $();if(o.current){if(m){let a=await x(m);if(!o.current)return;M(a)}b(r.groups,s)}}async function Dt(){let r=Me.current,s=r?.value.trim()??"";if(s){if(!ae(s)){r?.setCustomValidity(t("roles.profileIdInvalid")),r?.reportValidity();return}r?.setCustomValidity(""),await Ge(s),o.current&&(location.hash.startsWith("#/roles/profile")||(location.hash="#/roles/profile"))}}async function Ft(){if(!(!m||!I)){xe(!0);try{let r=await ot(m,I,L);if(!o.current)return;let s=await $();if(!o.current)return;let a=await x(m);if(!o.current)return;M(a),b(d,s),_(z,t(r?"roles.saved":"roles.saveFailed"),!r)}finally{o.current&&xe(!1)}}}async function Ut(){if(!(!m||!I)&&confirm(t("roles.confirmDeleteProfileEntry"))){Ee(!0);try{if(await rt(m,I),!o.current)return;H("");let r=await $();if(!o.current)return;let s=await x(m);if(!o.current)return;M(s),b(d,r)}finally{o.current&&Ee(!1)}}}function Ot(r,s){Ce(a=>{let u=new Set(a);return s?u.add(r):u.delete(r),u})}async function Te(r){if(!m)return;let s=k??d[0]?.chatId;if(!s)return;let a=[...we];if(a.length===0){T({kind:"text",text:t("roles.applyPickBots")});return}T({kind:"text",text:"..."});let u=await Promise.all(a.map(g=>lt({profileId:m,chatId:s,larkAppId:g,force:Ne,preview:r})));if(o.current&&(T({kind:"results",preview:r,results:u}),!r)){let g=await N();if(!o.current)return;b(g.groups,f)}}let Ht=ye||ee>w||R.trim().length===0,Vt=Ae||te>w||L.trim().length===0,A=n.tab==="profiles",_t=(0,e.jsxs)("nav",{className:"roles-subnav insight-tabs",role:"tablist","aria-label":t("roles.title"),children:[(0,e.jsx)("a",{href:"#/roles",className:`itab${A?"":" on"}`,role:"tab","aria-selected":!A,children:t("roles.tabGroups")}),(0,e.jsx)("a",{href:"#/roles/profile",className:`itab${A?" on":""}`,role:"tab","aria-selected":A,children:t("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:t("nav.roles")}),(0,e.jsx)("h1",{children:t("roles.title")})]}),(0,e.jsx)("div",{className:"page-heading-actions",children:_t})]}),(0,e.jsxs)("div",{id:"roles-by-group-view",className:"roles-layout",hidden:A,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:t("roles.search"),value:W,onChange:r=>mt(r.target.value)}),(0,e.jsx)(le,{id:"roles-refresh",label:t("roles.refresh"),onClick:()=>{Mt()}})]}),(0,e.jsx)("div",{id:"roles-tree",className:"roles-tree",children:ft?(0,e.jsx)(ne,{label:t("common.loading")}):(0,e.jsx)(zt,{groups:St,profiles:f,context:ct,contextLoaded:pt,expandedGroups:ht,selectedGroupId:v,selectedBotId:h,tr:t,onToggleGroup:r=>me(s=>Yt(s,r)),onSelectBot:(r,s)=>{Bt(r,s)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:!v||!h?(0,e.jsx)("div",{id:"roles-editor-empty",className:"roles-editor-empty",children:t("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:X?.name??v}),(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{id:"roles-editor-bot-name",children:wt?.botName??h})]}),(0,e.jsx)("div",{className:"roles-editor-meta",children:(0,e.jsxs)("span",{id:"roles-editor-chat-id",className:"roles-editor-meta-line",children:[v," \xB7 ",h]})})]}),(0,e.jsxs)("div",{className:"roles-editor-actions roles-editor-head-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-delete",className:"danger",style:{display:yt?.hasRole?"":"none"},disabled:Ie,onClick:()=>{Gt()},children:Ie?"...":t("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-save",className:"primary",disabled:Ht,onClick:()=>{Lt()},children:ye?"...":t("roles.save")})]})]}),(0,e.jsxs)("div",{className:"roles-editor-inject",children:[(0,e.jsx)("span",{className:"roles-field-label",children:t("roles.injectModeLabel")}),(0,e.jsx)(se,{id:"roles-editor-inject-mode",className:"roles-inline-menu",ariaLabel:t("roles.injectModeLabel"),disabled:gt,label:t(S==="once"?"roles.injectModeOnce":"roles.injectModeEvery"),value:S,options:[{value:"every",label:t("roles.injectModeEvery")},{value:"once",label:t("roles.injectModeOnce")}],onChange:r=>{Tt(r==="once"?"once":"every")}}),(0,e.jsx)("span",{className:"roles-editor-inject-hint",children:t("roles.injectModeHint")}),(0,e.jsx)(fe,{flash:bt})]}),(0,e.jsx)("textarea",{id:"roles-editor-textarea",placeholder:t("roles.editorPlaceholder"),rows:14,value:R,onChange:r=>O(r.target.value)}),(0,e.jsxs)("div",{className:"roles-editor-footer",children:[(0,e.jsxs)("span",{id:"roles-editor-bytecount",className:st(ee),children:[ee," / ",w," bytes"]}),(0,e.jsx)(fe,{flash:It})]}),(0,e.jsx)(at,{content:R,tr:t,id:"roles-preview"})]})})]}),(0,e.jsxs)("div",{id:"roles-profiles-view",className:"roles-layout roles-profiles-layout",hidden:!A,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:t("roles.profileIdPlaceholder"),maxLength:64,ref:Me,onChange:r=>r.currentTarget.setCustomValidity("")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-select",onClick:()=>{Dt()},children:t("roles.openProfile")})]}),(0,e.jsxs)("div",{className:"roles-tree-header dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",id:"roles-profile-search",placeholder:t("roles.profileSearch"),value:q,onChange:r=>vt(r.target.value)}),(0,e.jsx)(le,{id:"roles-profile-refresh",label:t("roles.refresh"),onClick:()=>{$t()}})]}),(0,e.jsx)("div",{id:"roles-profile-list",className:"roles-tree",children:ut?(0,e.jsx)(ne,{label:t("common.loading")}):(0,e.jsx)(Zt,{profiles:Et,selectedProfileId:m,tr:t,onSelect:r=>{Ge(r)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:m?(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:m}),Z?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{children:Z.botName??Z.larkAppId})]}):null]}),(0,e.jsx)("div",{className:"roles-editor-meta-line",children:t("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:t("roles.profileBots")}),(0,e.jsx)("div",{className:"roles-profile-bot-list",children:p.map(r=>{let s=!!D(B,r.larkAppId),a=I===r.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row roles-profile-bot-row ${a?"selected":""}`,"data-profile-bot-id":r.larkAppId,onClick:()=>{jt(r.larkAppId)},children:[(0,e.jsx)(it,{bot:r}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:r.botName??r.larkAppId}),(0,e.jsx)("div",{className:"roles-bot-id",children:r.larkAppId})]}),(0,e.jsx)("span",{className:`roles-badge ${s?"has-role":"no-role"}`,children:t(s?"roles.configured":"roles.unconfigured")})]},r.larkAppId)})})]}),(0,e.jsx)("div",{className:"roles-profile-editor",children:I?(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:st(te),children:[te," / ",w," 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:Ct?"":"none"},disabled:Se,onClick:()=>{Ut()},children:Se?"...":t("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-save",className:"primary",disabled:Vt,onClick:()=>{Ft()},children:Ae?"...":t("roles.saveEntry")})]})]}),(0,e.jsx)("textarea",{id:"roles-profile-textarea",placeholder:t("roles.profileEditorPlaceholder"),rows:12,value:L,onChange:r=>H(r.target.value)}),(0,e.jsx)("div",{className:"roles-editor-footer",children:(0,e.jsx)(fe,{flash:kt})}),(0,e.jsx)(at,{content:L,tr:t,id:"roles-profile-preview"})]}):(0,e.jsx)("div",{className:"roles-editor-empty roles-profile-inline-empty",children:t("roles.profileBotSelectHint")})})]}),(0,e.jsxs)("div",{className:"roles-profile-apply",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:t("roles.applyToGroup")}),(0,e.jsxs)("div",{className:"roles-profile-apply-controls",children:[(0,e.jsx)(se,{id:"roles-profile-apply-group",className:"roles-apply-group-menu",ariaLabel:t("roles.applyToGroup"),disabled:d.length===0,label:Q?.name??k??t("roles.noChats"),value:k??"",options:d.map(r=>({value:r.chatId,label:r.name??r.chatId})),onChange:r=>G(r)}),(0,e.jsxs)("label",{className:"roles-profile-force",children:[(0,e.jsx)("input",{type:"checkbox",id:"roles-profile-apply-force",checked:Ne,onChange:r=>Rt(r.target.checked)})," ",t("roles.applyForce")]})]}),(0,e.jsx)("div",{id:"roles-profile-apply-bots",children:!Q||V.length===0?(0,e.jsx)("div",{className:"roles-empty",children:t("roles.noChats")}):V.map(r=>{let s=!!D(B,r.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:r.larkAppId,checked:we.has(r.larkAppId),onChange:a=>Ot(r.larkAppId,a.target.checked)}),(0,e.jsx)("span",{children:r.botName??r.larkAppId}),(0,e.jsx)("small",{children:t(s?"roles.configured":"roles.profileMissing")})]},r.larkAppId)})}),(0,e.jsxs)("div",{className:"roles-editor-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-profile-preview-apply",onClick:()=>{Te(!0)},children:t("roles.previewApply")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-apply",className:"primary",onClick:()=>{Te(!1)},children:t("roles.applyProfile")})]}),(0,e.jsx)("div",{id:"roles-profile-apply-status",className:"roles-profile-status",children:(0,e.jsx)(Qt,{status:Nt,bots:p,tr:t})})]})]}):(0,e.jsx)("div",{id:"roles-profile-empty",className:"roles-editor-empty",children:t("roles.profileSelectHint")})})]})]})}function Yt(n,t){let o=new Set(n);return o.has(t)?o.delete(t):o.add(t),o}function st(n){return`roles-bytecount ${n>Je?"warn":""} ${n>w?"over":""}`}function fe(n){return n.flash?(0,e.jsxs)("span",{className:`roles-saved-flash ${n.flash.isError?"roles-save-error":""}`,children:[" ",n.flash.text]}):null}function zt(n){let{tr:t}=n;return n.groups.length===0?(0,e.jsx)("div",{className:"roles-empty",children:t("roles.noChats")}):(0,e.jsx)(e.Fragment,{children:n.groups.map(o=>{let i=n.expandedGroups.has(o.chatId),d=o.memberBots.filter(c=>c.inChat),y=ce(o),p=We(o);return(0,e.jsxs)("div",{className:"roles-group-section",children:[(0,e.jsxs)("div",{className:`roles-group-row ${i?"expanded":""} ${n.selectedGroupId===o.chatId&&!n.selectedBotId?"selected":""}`,"data-group-id":o.chatId,onClick:()=>n.onToggleGroup(o.chatId),children:[(0,e.jsx)("span",{className:"roles-group-arrow",children:i?"\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:o.name??o.chatId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[y,"/",p," ",t("roles.botsWithRoles")]}),(0,e.jsx)(Xt,{group:o,profiles:n.profiles,context:n.context,loaded:n.contextLoaded,tr:t})]}),(0,e.jsx)("span",{className:"roles-group-chevron"})]}),(0,e.jsx)("div",{className:"roles-bot-list",children:i?d.map(c=>{let f=n.selectedGroupId===o.chatId&&n.selectedBotId===c.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row ${f?"selected":""}`,"data-group-id":o.chatId,"data-bot-id":c.larkAppId,onClick:P=>{P.stopPropagation(),n.onSelectBot(o.chatId,c.larkAppId)},children:[(0,e.jsx)("span",{className:"roles-bot-indent"}),(0,e.jsx)(it,{bot:c}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:c.botName}),(0,e.jsx)("div",{className:"roles-bot-id",children:c.larkAppId})]}),(0,e.jsx)("span",{className:`roles-badge ${c.hasRole?"has-role":"no-role"}`,children:c.hasRole?t("roles.configured"):t("roles.unconfigured")})]},c.larkAppId)}):null})]},o.chatId)})})}function Xt(n){let{group:t,profiles:o,context:i,loaded:d,tr:y}=n;if(!o.length||!d)return null;let p=new Map;for(let P of t.memberBots)P.inChat&&p.set(P.larkAppId,i.effectiveRolesByBot.get(ie(P.larkAppId,t.chatId))??null);if(!Oe(p))return null;let c=He(t.memberBots,o,i.entriesByProfile,p)[0];if(!c)return(0,e.jsx)("div",{className:"roles-profile-match muted",children:y("groups.profileStatusUnmatched")});let f=c.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`roles-profile-match ${c.kind}`,children:y(f,{name:c.profileId,matched:c.matched,total:c.total,chat:c.chatMatched})})}function at(n){return(0,e.jsx)("div",{id:n.id,className:"roles-preview",children:n.content.trim()?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("strong",{children:n.tr("roles.preview")}),(0,e.jsx)("pre",{children:n.content})]}):(0,e.jsx)("small",{children:n.tr("roles.previewEmpty")})})}function Zt(n){let{tr:t}=n;return n.profiles.length===0?(0,e.jsx)("div",{className:"roles-empty",children:t("roles.profileEmpty")}):(0,e.jsx)(e.Fragment,{children:n.profiles.map(o=>{let i=n.selectedProfileId===o.profileId,d=(o.botEntries??[]).some(y=>y.hasEntry);return(0,e.jsxs)("div",{className:`roles-profile-row ${i?"selected":""}`,"data-profile-id":o.profileId,onClick:()=>n.onSelect(o.profileId),children:[(0,e.jsxs)("div",{className:"roles-profile-row-main",children:[(0,e.jsx)("div",{className:"roles-profile-name",children:o.profileId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[o.entryCount," ",t("roles.profileEntries")]})]}),(0,e.jsx)("span",{className:`roles-badge ${d?"has-role":"no-role"}`,children:t(d?"roles.configured":"roles.profileMissing")})]},o.profileId)})})}function Qt(n){let{status:t,bots:o,tr:i}=n;return t.kind==="idle"?null:t.kind==="text"?(0,e.jsx)(e.Fragment,{children:t.text}):(0,e.jsx)(e.Fragment,{children:t.results.map(d=>{let p=o.find(f=>f.larkAppId===d.larkAppId)?.botName??d.larkAppId,c=d.ok?t.preview?d.wouldRefuse?i("roles.applyWouldRefuse"):i("roles.applyPreviewOk"):i("roles.applyOk"):`${i("roles.applyFailed")}: ${String(d.error??`HTTP ${d.status}`)}`;return(0,e.jsxs)("div",{children:[p,": ",c]},d.larkAppId)})})}function io(n){return re(n,(0,e.jsx)(dt,{tab:"groups"}))}function co(n){return re(n,(0,e.jsx)(dt,{tab:"profiles"}))}export{co as renderRoleProfilesPage,io as renderRolesPage};
@@ -1 +1 @@
1
- import{a as j,c as F}from"./chunk-JMRGZQDB.js";import{g as q,l as Z,m as _,n as B,o as K,p as U}from"./chunk-QFMH6ITB.js";import"./chunk-SNKATZWK.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};
1
+ import{a as j,c as F}from"./chunk-FLGXZJTD.js";import{g as q,l as Z,m as _,n as B,o as K,p as U}from"./chunk-QFMH6ITB.js";import"./chunk-KQB42ML5.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};