botmux 3.18.7 → 3.18.8

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 (133) hide show
  1. package/dist/.runtime-build-id +1 -1
  2. package/dist/adapters/backend/tmux-pipe-backend.d.ts +57 -0
  3. package/dist/adapters/backend/tmux-pipe-backend.d.ts.map +1 -1
  4. package/dist/adapters/backend/tmux-pipe-backend.js +200 -21
  5. package/dist/adapters/backend/tmux-pipe-backend.js.map +1 -1
  6. package/dist/adapters/cli/pi-turn-boundary-extension.d.ts +66 -0
  7. package/dist/adapters/cli/pi-turn-boundary-extension.d.ts.map +1 -0
  8. package/dist/adapters/cli/pi-turn-boundary-extension.js +106 -0
  9. package/dist/adapters/cli/pi-turn-boundary-extension.js.map +1 -0
  10. package/dist/adapters/cli/pi.d.ts +29 -0
  11. package/dist/adapters/cli/pi.d.ts.map +1 -1
  12. package/dist/adapters/cli/pi.js +61 -10
  13. package/dist/adapters/cli/pi.js.map +1 -1
  14. package/dist/bot-registry.d.ts +9 -0
  15. package/dist/bot-registry.d.ts.map +1 -1
  16. package/dist/bot-registry.js +5 -0
  17. package/dist/bot-registry.js.map +1 -1
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +8 -1
  20. package/dist/cli.js.map +1 -1
  21. package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
  22. package/dist/core/dashboard-ipc-server.js +24 -0
  23. package/dist/core/dashboard-ipc-server.js.map +1 -1
  24. package/dist/core/worker-pool.d.ts.map +1 -1
  25. package/dist/core/worker-pool.js +134 -17
  26. package/dist/core/worker-pool.js.map +1 -1
  27. package/dist/daemon.d.ts.map +1 -1
  28. package/dist/daemon.js +5 -3
  29. package/dist/daemon.js.map +1 -1
  30. package/dist/dashboard/bot-payload.d.ts +2 -0
  31. package/dist/dashboard/bot-payload.d.ts.map +1 -1
  32. package/dist/dashboard/bot-payload.js +2 -0
  33. package/dist/dashboard/bot-payload.js.map +1 -1
  34. package/dist/dashboard/groups-matrix-snapshot.d.ts +27 -0
  35. package/dist/dashboard/groups-matrix-snapshot.d.ts.map +1 -1
  36. package/dist/dashboard/groups-matrix-snapshot.js +16 -0
  37. package/dist/dashboard/groups-matrix-snapshot.js.map +1 -1
  38. package/dist/dashboard/web/bot-defaults-page.d.ts +4 -0
  39. package/dist/dashboard/web/bot-defaults-page.d.ts.map +1 -1
  40. package/dist/dashboard/web/bot-defaults-page.js +52 -9
  41. package/dist/dashboard/web/bot-defaults-page.js.map +1 -1
  42. package/dist/dashboard/web/bot-defaults.d.ts +29 -0
  43. package/dist/dashboard/web/bot-defaults.d.ts.map +1 -1
  44. package/dist/dashboard/web/bot-defaults.js +45 -1
  45. package/dist/dashboard/web/bot-defaults.js.map +1 -1
  46. package/dist/dashboard/web/bot-onboarding.d.ts.map +1 -1
  47. package/dist/dashboard/web/bot-onboarding.js +5 -0
  48. package/dist/dashboard/web/bot-onboarding.js.map +1 -1
  49. package/dist/dashboard/web/dashboard-components.d.ts +29 -0
  50. package/dist/dashboard/web/dashboard-components.d.ts.map +1 -1
  51. package/dist/dashboard/web/dashboard-components.js +96 -4
  52. package/dist/dashboard/web/dashboard-components.js.map +1 -1
  53. package/dist/dashboard/web/groups-api.d.ts +11 -0
  54. package/dist/dashboard/web/groups-api.d.ts.map +1 -1
  55. package/dist/dashboard/web/groups-api.js +51 -0
  56. package/dist/dashboard/web/groups-api.js.map +1 -1
  57. package/dist/dashboard/web/i18n.d.ts.map +1 -1
  58. package/dist/dashboard/web/i18n.js +10 -0
  59. package/dist/dashboard/web/i18n.js.map +1 -1
  60. package/dist/dashboard/web/overview.d.ts.map +1 -1
  61. package/dist/dashboard/web/overview.js +11 -2
  62. package/dist/dashboard/web/overview.js.map +1 -1
  63. package/dist/dashboard/web/ui.d.ts.map +1 -1
  64. package/dist/dashboard/web/ui.js +12 -2
  65. package/dist/dashboard/web/ui.js.map +1 -1
  66. package/dist/dashboard-web/app.js +1 -1
  67. package/dist/dashboard-web/chunks/{agent-workbench-dock-page-6LC422N6.js → agent-workbench-dock-page-FAL2YGY5.js} +1 -1
  68. package/dist/dashboard-web/chunks/{agent-workbench-page-RSAWY7O2.js → agent-workbench-page-G65IOPLY.js} +1 -1
  69. package/dist/dashboard-web/chunks/bot-defaults-page-3BNFNZEO.js +1 -0
  70. package/dist/dashboard-web/chunks/chunk-2XHWGUTB.js +10 -0
  71. package/dist/dashboard-web/chunks/{chunk-R3LJUCEO.js → chunk-3OJQKYM3.js} +1 -1
  72. package/dist/dashboard-web/chunks/{chunk-K232GT3M.js → chunk-IRFGJSPL.js} +5 -5
  73. package/dist/dashboard-web/chunks/{chunk-IA5KMD5O.js → chunk-IYVXEFKU.js} +1 -1
  74. package/dist/dashboard-web/chunks/{chunk-YJA3KY3J.js → chunk-MYLVEXYF.js} +1 -1
  75. package/dist/dashboard-web/chunks/chunk-QALRQEKD.js +1 -0
  76. package/dist/dashboard-web/chunks/{connectors-page-DJCTHSFB.js → connectors-page-K6VZNYUQ.js} +1 -1
  77. package/dist/dashboard-web/chunks/{customization-page-VQJAEDZY.js → customization-page-FRP6RFOI.js} +1 -1
  78. package/dist/dashboard-web/chunks/{feedback-page-O7SZRKNM.js → feedback-page-4X7N5J33.js} +1 -1
  79. package/dist/dashboard-web/chunks/{groups-page-7PONUYHE.js → groups-page-RFQVUO6K.js} +1 -1
  80. package/dist/dashboard-web/chunks/{insights-page-J6DAAJ6D.js → insights-page-XWH77GX7.js} +1 -1
  81. package/dist/dashboard-web/chunks/{monitor-room-F3QNEW7N.js → monitor-room-WFU3745R.js} +1 -1
  82. package/dist/dashboard-web/chunks/{monitoring-page-JHDD2VS2.js → monitoring-page-3NYPZEQT.js} +1 -1
  83. package/dist/dashboard-web/chunks/{office-page-MMTN4IKD.js → office-page-4I3X6PTF.js} +1 -1
  84. package/dist/dashboard-web/chunks/overview-page-OQWLVTKT.js +1 -0
  85. package/dist/dashboard-web/chunks/{roles-page-FNI4MGX6.js → roles-page-RKUGNQOW.js} +1 -1
  86. package/dist/dashboard-web/chunks/{schedules-page-6PUU63KS.js → schedules-page-SAJKYRZ6.js} +1 -1
  87. package/dist/dashboard-web/chunks/{sessions-page-O4N72EXT.js → sessions-page-IU6VNSX4.js} +1 -1
  88. package/dist/dashboard-web/chunks/{settings-page-G7B3STUF.js → settings-page-WTIPX7BQ.js} +1 -1
  89. package/dist/dashboard-web/chunks/{skills-page-CEWKQOIG.js → skills-page-MKG3HJIU.js} +1 -1
  90. package/dist/dashboard-web/chunks/{team-federation-page-NUP4VK4H.js → team-federation-page-7SMZJWPT.js} +1 -1
  91. package/dist/dashboard-web/chunks/{v3-page-M4XF6D5Z.js → v3-page-JMCFLY4Y.js} +1 -1
  92. package/dist/dashboard-web/chunks/{whiteboards-page-L755NZX6.js → whiteboards-page-5YTWY5EB.js} +1 -1
  93. package/dist/dashboard-web/style.css +65 -3
  94. package/dist/dashboard.js +50 -4
  95. package/dist/dashboard.js.map +1 -1
  96. package/dist/i18n/en.d.ts.map +1 -1
  97. package/dist/i18n/en.js +4 -1
  98. package/dist/i18n/en.js.map +1 -1
  99. package/dist/i18n/zh.d.ts.map +1 -1
  100. package/dist/i18n/zh.js +4 -1
  101. package/dist/i18n/zh.js.map +1 -1
  102. package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
  103. package/dist/im/lark/event-dispatcher.js +141 -38
  104. package/dist/im/lark/event-dispatcher.js.map +1 -1
  105. package/dist/services/card-prefs-store.d.ts +2 -0
  106. package/dist/services/card-prefs-store.d.ts.map +1 -1
  107. package/dist/services/card-prefs-store.js +9 -1
  108. package/dist/services/card-prefs-store.js.map +1 -1
  109. package/dist/services/pi-transcript.d.ts +21 -1
  110. package/dist/services/pi-transcript.d.ts.map +1 -1
  111. package/dist/services/pi-transcript.js +188 -8
  112. package/dist/services/pi-transcript.js.map +1 -1
  113. package/dist/services/session-store.d.ts.map +1 -1
  114. package/dist/services/session-store.js +495 -11
  115. package/dist/services/session-store.js.map +1 -1
  116. package/dist/services/under-review-notify-store.d.ts +18 -0
  117. package/dist/services/under-review-notify-store.d.ts.map +1 -0
  118. package/dist/services/under-review-notify-store.js +67 -0
  119. package/dist/services/under-review-notify-store.js.map +1 -0
  120. package/dist/setup/open-platform-automation.d.ts +210 -2
  121. package/dist/setup/open-platform-automation.d.ts.map +1 -1
  122. package/dist/setup/open-platform-automation.js +538 -44
  123. package/dist/setup/open-platform-automation.js.map +1 -1
  124. package/dist/setup/open-platform-outcome.d.ts.map +1 -1
  125. package/dist/setup/open-platform-outcome.js +5 -0
  126. package/dist/setup/open-platform-outcome.js.map +1 -1
  127. package/dist/workflows/events/payloads.d.ts +6 -6
  128. package/dist/workflows/events/schema.d.ts +12 -12
  129. package/package.json +9 -7
  130. package/dist/dashboard-web/chunks/bot-defaults-page-67RAWCSQ.js +0 -1
  131. package/dist/dashboard-web/chunks/chunk-MMLTCXHP.js +0 -10
  132. package/dist/dashboard-web/chunks/chunk-NYY66DNC.js +0 -1
  133. package/dist/dashboard-web/chunks/overview-page-IQ2UJAJP.js +0 -1
@@ -1,4 +1,4 @@
1
- import{c as ne,d as we,e as Se}from"./chunk-6RLYYCVH.js";import{a as Pe,b as Ie,c as Ce,d as Ne}from"./chunk-R3FXBFQH.js";import{a as fe}from"./chunk-ZJVTGU5X.js";import{a as W}from"./chunk-OXSVWLER.js";import{a as re}from"./chunk-CEUCNZFJ.js";import{c as ee,g as te,h as he,m as oe,n as ve,o as be,p as ye,q as ke}from"./chunk-NYY66DNC.js";import{d as ge}from"./chunk-R3LJUCEO.js";import"./chunk-QITAMHW6.js";import{A as de,D as ue,a as V,b as Z,x as X}from"./chunk-K232GT3M.js";import{c as pe}from"./chunk-ARROO6TE.js";import{c as Q,d as _e,e as me}from"./chunk-3YZFAHNK.js";var l=Q(_e(),1);var We=/^[A-Za-z0-9._-]{1,64}$/,Re=6,Ge=30;function ae(o,t){return Ce(o,t)}function xe(o,t,r=Ge){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):Ge,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,p=Math.min(c,Math.max(1,s)),v=(p-1)*n,x=Math.min(a,v+n);return{rows:o.slice(v,x),page:p,totalPages:c,from:a===0?0:v+1,to:x,total:a}}async function Ae(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 se(o){return We.test(o)&&o!=="."&&o!==".."}function ie(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return se(t)?t:"profile"}async function Y(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Be(o){let t=await Y(),r=await Ae(t,Re,async s=>{try{let v=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(v.entries)?v.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let p of s.memberBots??[]){if(!p?.inChat||!p?.hasRole||!p?.larkAppId)continue;let v=ae(p.larkAppId,s.chatId);n.has(v)||(n.add(v),a.push({chatId:s.chatId,larkAppId:p.larkAppId}))}let c=await Ne(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Te(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ae(t,Re,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,p=c?String(s??"").trim():"",v=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:p,status:p?v??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ee(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function $e(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 Le(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 Me(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Oe(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:X("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:X("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:X("groups.roleProfileBootstrapDone",{name:n})}}function De(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(p=>({larkAppId:p.larkAppId,botName:p.botName,inChat:c.has(p.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(p=>p.chatId!==t)]}}var e=Q(me(),1);function Fe(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Je(o){let t={};for(let r of de(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function qe(o){let t=o.chat,r=t.avatar??ue(t.chatId),[n,a]=(0,l.useState)(!1);(0,l.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:Je(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 le(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 Ue(o){let t=Ee(o.bots,o.excludeIds),r=o.tr;return(0,e.jsx)(Se,{bots:t,selected:o.selected,onToggle:o.onToggle,searchPlaceholder:r("botPicker.searchPlaceholder"),noMatchLabel:r("botPicker.noMatch"),emptyLabel:r("botPicker.empty"),selectedCountLabel:n=>r("botPicker.selectedCount",{n:String(n)})})}function ze(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 Ve(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let v of t.memberBots??[])v?.inChat&&a.set(v.larkAppId,r.groupRoleContentByBot.get(ae(v.larkAppId,t.chatId))??null);if(!Pe(a))return null;let s=Ie(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 p=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(p,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function Ke(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function Ze(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 Xe(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=Ke(n),c=Ze(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 je=(0,l.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(ve,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(qe,{chat:r}),(0,e.jsxs)(be,{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)(Ve,{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)(Xe,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(ye,{children:[(0,e.jsx)(te,{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 Ye(o){let{tr:t}=o,[r,n]=(0,l.useState)(!1),[a,c]=(0,l.useState)(null),[s,p]=(0,l.useState)(null),[v,x]=(0,l.useState)(!1),[g,C]=(0,l.useState)(new Set),[I,d]=(0,l.useState)(""),[w,m]=(0,l.useState)([]),[S,T]=(0,l.useState)(""),[A,E]=(0,l.useState)(""),[N,U]=(0,l.useState)(""),[M,q]=(0,l.useState)(!0),[B,$]=(0,l.useState)(""),[D,z]=(0,l.useState)(!1),[F,O]=(0,l.useState)(""),[u,k]=(0,l.useState)("");(0,l.useEffect)(()=>{let f=!0;return fetch("/api/feed-groups").then(async b=>{let P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);f&&(m(Array.isArray(P.groups)?P.groups:[]),T(typeof P.larkAppId=="string"?P.larkAppId:""))}).catch(b=>{f&&$(b instanceof Error?b.message:String(b))}).finally(()=>{f&&q(!1)}),()=>{f=!1}},[]),(0,l.useEffect)(()=>{if(!F)return;let f=!0,b=window.setInterval(()=>{fetch("/api/feed-groups").then(async P=>{let G=await P.json().catch(()=>({}));!P.ok||!G.ok||!f||(m(Array.isArray(G.groups)?G.groups:[]),T(typeof G.larkAppId=="string"?G.larkAppId:""),$(""),O(""),k(""))}).catch(()=>{})},1e3);return()=>{f=!1,window.clearInterval(b)}},[F]);async function j(){let f=S?`?larkAppId=${encodeURIComponent(S)}`:"",b=await fetch(`/api/feed-groups/auth-url${f}`),P=await b.json().catch(()=>({}));if(!b.ok||!P.authUrl){c({title:"\u65E0\u6CD5\u53D1\u8D77\u6807\u7B7E\u6388\u6743",reason:P.error??`HTTP ${b.status}`});return}O(String(P.authUrl)),k("")}async function H(f){z(!0);try{let b=await fetch("/api/feed-groups/oauth-callback",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({callbackUrl:f.trim()})}),P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);let G=await fetch("/api/feed-groups"),i=await G.json().catch(()=>({}));if(!G.ok||!i.ok)throw new Error(i.message??i.error??`HTTP ${G.status}`);m(Array.isArray(i.groups)?i.groups:[]),T(typeof i.larkAppId=="string"?i.larkAppId:""),$(""),O(""),k("")}catch(b){c({title:"\u6807\u7B7E\u6388\u6743\u5931\u8D25",reason:b instanceof Error?b.message:String(b)})}finally{z(!1)}}async function _(f){f.preventDefault();let b=new FormData(f.currentTarget),P=String(b.get("name")??"").trim(),G=String(b.get("bindWorkingDir")??"").trim(),i=String(b.get("roleProfileId")??"").trim(),h=[...g];if(h.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 y=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:P||void 0,larkAppIds:h,bindWorkingDir:G||void 0,roleProfileId:i||void 0,feedGroupId:A||void 0,newFeedGroupName:N||void 0,feedGroupAppId:A||N?S:void 0})}),R=await y.json().catch(()=>({ok:!1,error:`HTTP ${y.status}`}));R.ok&&R.chatId?(p(R),o.onCreated(R,h,P)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:R.error??`HTTP ${y.status}`}),n(!1))}catch(y){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:y}),n(!1)}}if(s){let f=String(s.chatId),b=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(f)}`,P=s.invalidBotIds??[],G=s.invalidUserIds??[],i=Array.isArray(s.oncallBindings)?s.oncallBindings:[],h=i.filter(L=>L?.ok).length,y=i.filter(L=>!L?.ok),R=Oe(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:f})," ",(0,e.jsx)("button",{type:"button","data-copy":f,onClick:()=>{fe(f,t("sessions.copy")).then(L=>{L&&(x(!0),o.setTimer(()=>x(!1),800))})},children:t(v?"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}),i.length>0?y.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",h,"/",i.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",h,"/",i.length,"\u3002",y.map((L,J)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(L?.larkAppId??"?")}),": ",String(L?.error??"unknown")]},`${L?.larkAppId??"?"}-${J}`))]}):null,R?(0,e.jsx)("p",{className:R.kind==="ok"?"hint-ok":"hint-warn",children:R.text}):null,P.length||G.length?(0,e.jsxs)("ul",{children:[P.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:P.join(", ")})]}):null,G.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:G.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:b,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:f=>{_(f)},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)(Ue,{bots:o.bots,tr:t,selected:g,onToggle:(f,b)=>C(P=>{let G=new Set(P);return b?G.add(f):G.delete(f),G})})})]}),(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:I}),(0,e.jsx)(ke,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:I||t("groups.roleProfileNone"),value:I,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(f=>({value:f.profileId,label:f.profileId}))],onChange:d}),(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:A}),(0,e.jsx)(we,{groups:w,selectedId:A,newName:N,disabled:M||!!B,onChange:(f,b)=>{E(f),U(b)}}),(0,e.jsx)("small",{children:"\u5C55\u5F00\u540E\u53EF\u5728\u7B2C\u4E00\u884C\u8F93\u5165\u65B0\u6807\u7B7E\u540D\u79F0\uFF0C\u6216\u9009\u62E9\u4E0B\u65B9\u5DF2\u6709\u6807\u7B7E\u3002"}),M?(0,e.jsx)("small",{children:"\u6B63\u5728\u8BFB\u53D6\u98DE\u4E66\u6807\u7B7E\u2026"}):null,B?(0,e.jsxs)("div",{className:"hint-warn-inline",children:[(0,e.jsx)("small",{children:B})," ",(0,e.jsx)("button",{type:"button",disabled:D,onClick:()=>{j()},children:D?"\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&&!B&&w.length===0?(0,e.jsx)("small",{children:"\u5F53\u524D\u6CA1\u6709\u6807\u7B7E\uFF0C\u53EF\u76F4\u63A5\u521B\u5EFA\u4E00\u4E2A\u3002"}):null]})]}),F?(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(F,"_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:u,placeholder:"http://127.0.0.1:9768/callback?code=\u2026&state=\u2026",onChange:f=>k(f.currentTarget.value)})]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{O(""),k("")},children:"\u53D6\u6D88"}),(0,e.jsx)("button",{type:"button",className:"primary",disabled:!u.trim()||D,onClick:()=>{H(u)},children:D?"\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)(le,{...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,p=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,p?(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",p,"\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 et(o){let{chat:t,tr:r}=o,[n,a]=(0,l.useState)(!1),[c,s]=(0,l.useState)(null),[p,v]=(0,l.useState)(null),[x,g]=(0,l.useState)(new Set),C=(0,l.useMemo)(()=>new Set((t.memberBots??[]).filter(d=>d.inChat).map(d=>d.larkAppId)),[t]);async function I(d){d.preventDefault();let w=[...x];if(w.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),v(null);return}a(!0),s(null),v(null);try{let S=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:w})})).json();if(S.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(S.result){let T=Me(S.result);try{await o.onReloadGroups({force:!0}),v({result:T})}catch(A){v({result:T,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${A}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(S)})}catch(m){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:m})}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:d=>{I(d)},children:[(0,e.jsx)(Ue,{bots:o.bots,excludeIds:C,tr:r,selected:x,onToggle:(d,w)=>g(m=>{let S=new Set(m);return w?S.add(d):S.delete(d),S})}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(le,{...c}):null,p?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ze,{summary:p.result}),p.refreshError?(0,e.jsx)(le,{title:"\u5237\u65B0\u5931\u8D25",reason:p.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 tt(o){let{tr:t}=o,[r,n]=(0,l.useState)([]),[a,c]=(0,l.useState)([]),[s,p]=(0,l.useState)(!0),[v,x]=(0,l.useState)(null),g=(0,l.useMemo)(()=>[...a].sort((u,k)=>u.profileId.localeCompare(k.profileId)),[a]),C=g.length>0,I=r.filter(u=>u.status==="empty").length,d=r.filter(u=>u.status==="error").length,w=!s&&!v&&r.length>0&&d===0,[m,S]=(0,l.useState)("new"),[T,A]=(0,l.useState)(o.suggestedProfileId),[E,N]=(0,l.useState)(""),[U,M]=(0,l.useState)(!1),[q,B]=(0,l.useState)(null),$=m==="overwrite"?E:T.trim(),D=t(m==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),z=v||(s?t("groups.saveProfilePreparing"):d?t("groups.saveProfileFailedLoadSummary",{count:d}):r.length?I?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:I}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,l.useEffect)(()=>{let u=!0;return p(!0),x(null),B(null),(async()=>{try{let[k,j]=await Promise.all([Te(o.chat),Y().catch(()=>[])]);if(!u)return;let H=[...j].sort((_,f)=>_.profileId.localeCompare(f.profileId));n(k),c(j),N(_=>H.some(f=>f.profileId===_)?_:H[0]?.profileId??"")}catch(k){if(!u)return;n([]),c([]),N(""),x(k instanceof Error?k.message:String(k))}finally{u&&p(!1)}})(),()=>{u=!1}},[o.chat]);async function F(u){if(u.preventDefault(),!!w){if(!se($)){B({text:t("groups.saveProfileInvalid"),className:"error"});return}M(!0),B({text:t("groups.saveProfileSaving")});try{let j=(await Promise.all(r.map(async H=>(await fetch(`/api/role-profiles/${encodeURIComponent($)}/${encodeURIComponent(H.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:H.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(j!==r.length){B({text:t("groups.saveProfileFailed",{saved:j,total:r.length}),className:"error"}),M(!1);return}B({text:t("groups.saveProfileDone",{name:$,count:j}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(k){B({text:String(k),className:"error"}),M(!1)}}}function O(u){u==="overwrite"&&!C||(S(u),B(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:u=>{F(u)},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})]}),d?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:d})]}):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)(ee,{label:t("common.loading")})}):v?(0,e.jsx)("div",{className:"g-save-profile-empty",children:v}):r.length?r.map(u=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${u.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:u.botName??u.larkAppId}),(0,e.jsx)("code",{children:u.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${u.status==="error"?"error":"ok"}`,children:t(u.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},u.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:m==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":m==="new",onClick:()=>O("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:m==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":m==="overwrite",disabled:!C,onClick:()=>O("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:m!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:T,maxLength:64,autoComplete:"off",onChange:u=>{A(u.currentTarget.value),B(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:m!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),C?(0,e.jsx)("div",{className:"g-save-profile-picker",children:g.map(u=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${u.profileId===E?"selected":""}`,"data-profile-id":u.profileId,"aria-pressed":u.profileId===E,onClick:()=>{N(u.profileId),S("overwrite"),B(null)},children:[(0,e.jsx)("span",{children:u.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:u.entryCount??0})})]},u.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(m==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${w?"":"warn"}`,children:z}),(0,e.jsx)("div",{className:`g-save-profile-status ${q?.className??""}`,"data-save-profile-status":!0,children:q?.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:!w||U||m==="overwrite"&&!E,children:U?t("groups.saveProfileSaving"):D})]})]})]})}function ot(o){let{member:t,tr:r}=o,n=(0,l.useRef)(null),[a,c]=(0,l.useState)(!!t.oncallChat),[s,p]=(0,l.useState)(t.oncallChat?.workingDir??""),[v,x]=(0,l.useState)(!1),[g,C]=(0,l.useState)(null);async function I(){C(null);let d=s.trim();if(a&&!d){C({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}x(!0);try{let w=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,m=a?await fetch(w,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:d})}):await fetch(w,{method:"DELETE"}),S=await m.json().catch(()=>({}));if(m.ok&&S.ok){C({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${S.resolvedPath??d}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else C({text:`\u2717 ${S.error??m.status}`,className:"hint-warn-inline"})}catch(w){C({text:`\u2717 ${w?.message??w}`,className:"hint-warn-inline"})}finally{x(!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:d=>{c(d.currentTarget.checked),d.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:d=>p(d.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:v,onClick:()=>{I()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${g?.className??""}`,"data-status":!0,children:g?.text??""})]})]})}function rt(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(g=>g.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,l.useState)(()=>new Set);function p(g,C){s(I=>{let d=new Set(I);return C?d.add(g):d.delete(g),d})}async function v(){let g=[...c];if(g.length===0){W("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA",{kind:"warning"});return}if(await re({title:"\u9000\u51FA\u7FA4\u804A",message:`\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`,danger:!0}))try{let I=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:g})})).json(),d=(I.result??[]).map(w=>{if(!w.ok)return`${w.larkAppId}: \u5931\u8D25 (${w.error??"unknown"})`;let m=w.closedSessions??[],S=m.filter(N=>!N.ok).length,T=m.length-S,A=m.filter(N=>N.ok&&N.residual).map(N=>ne(N.residual)),E=m.length===0?"":`\uFF08\u5173\u95ED ${T} \u4E2A\u4F1A\u8BDD${S?`\uFF0C${S} \u4E2A\u5931\u8D25`:""}${A.length?`\uFF0C${A.length} \u4E2A\u6709\u6B8B\u7559\u9700\u4EBA\u5DE5\u6E05\u7406\uFF1A${A.join(", ")}`:""}\uFF09`;return`${w.larkAppId}: OK${E}`}).join(`
1
+ import{c as ne,d as we,e as Se}from"./chunk-6RLYYCVH.js";import{a as Pe,b as Ie,c as Ce,d as Ne}from"./chunk-R3FXBFQH.js";import{a as fe}from"./chunk-ZJVTGU5X.js";import{a as W}from"./chunk-OXSVWLER.js";import{a as re}from"./chunk-CEUCNZFJ.js";import{c as ee,g as te,h as he,m as oe,n as ve,o as be,p as ye,q as ke}from"./chunk-QALRQEKD.js";import{d as ge}from"./chunk-3OJQKYM3.js";import"./chunk-QITAMHW6.js";import{B as de,E as ue,a as V,c as Z,y as X}from"./chunk-IRFGJSPL.js";import{c as pe}from"./chunk-ARROO6TE.js";import{c as Q,d as _e,e as me}from"./chunk-3YZFAHNK.js";var l=Q(_e(),1);var We=/^[A-Za-z0-9._-]{1,64}$/,Re=6,Ge=30;function ae(o,t){return Ce(o,t)}function xe(o,t,r=Ge){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):Ge,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,p=Math.min(c,Math.max(1,s)),v=(p-1)*n,x=Math.min(a,v+n);return{rows:o.slice(v,x),page:p,totalPages:c,from:a===0?0:v+1,to:x,total:a}}async function Ae(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 se(o){return We.test(o)&&o!=="."&&o!==".."}function ie(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return se(t)?t:"profile"}async function Y(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Be(o){let t=await Y(),r=await Ae(t,Re,async s=>{try{let v=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(v.entries)?v.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let p of s.memberBots??[]){if(!p?.inChat||!p?.hasRole||!p?.larkAppId)continue;let v=ae(p.larkAppId,s.chatId);n.has(v)||(n.add(v),a.push({chatId:s.chatId,larkAppId:p.larkAppId}))}let c=await Ne(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Te(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ae(t,Re,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,p=c?String(s??"").trim():"",v=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:p,status:p?v??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ee(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function $e(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 Le(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 Me(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Oe(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:X("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:X("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:X("groups.roleProfileBootstrapDone",{name:n})}}function De(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(p=>({larkAppId:p.larkAppId,botName:p.botName,inChat:c.has(p.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(p=>p.chatId!==t)]}}var e=Q(me(),1);function Fe(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Je(o){let t={};for(let r of de(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function qe(o){let t=o.chat,r=t.avatar??ue(t.chatId),[n,a]=(0,l.useState)(!1);(0,l.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:Je(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 le(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 Ue(o){let t=Ee(o.bots,o.excludeIds),r=o.tr;return(0,e.jsx)(Se,{bots:t,selected:o.selected,onToggle:o.onToggle,searchPlaceholder:r("botPicker.searchPlaceholder"),noMatchLabel:r("botPicker.noMatch"),emptyLabel:r("botPicker.empty"),selectedCountLabel:n=>r("botPicker.selectedCount",{n:String(n)})})}function ze(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 Ve(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let v of t.memberBots??[])v?.inChat&&a.set(v.larkAppId,r.groupRoleContentByBot.get(ae(v.larkAppId,t.chatId))??null);if(!Pe(a))return null;let s=Ie(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 p=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(p,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function Ke(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function Ze(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 Xe(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=Ke(n),c=Ze(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 je=(0,l.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(ve,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(qe,{chat:r}),(0,e.jsxs)(be,{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)(Ve,{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)(Xe,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(ye,{children:[(0,e.jsx)(te,{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 Ye(o){let{tr:t}=o,[r,n]=(0,l.useState)(!1),[a,c]=(0,l.useState)(null),[s,p]=(0,l.useState)(null),[v,x]=(0,l.useState)(!1),[g,C]=(0,l.useState)(new Set),[I,d]=(0,l.useState)(""),[w,m]=(0,l.useState)([]),[S,T]=(0,l.useState)(""),[A,E]=(0,l.useState)(""),[N,U]=(0,l.useState)(""),[M,q]=(0,l.useState)(!0),[B,$]=(0,l.useState)(""),[D,z]=(0,l.useState)(!1),[F,O]=(0,l.useState)(""),[u,k]=(0,l.useState)("");(0,l.useEffect)(()=>{let f=!0;return fetch("/api/feed-groups").then(async b=>{let P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);f&&(m(Array.isArray(P.groups)?P.groups:[]),T(typeof P.larkAppId=="string"?P.larkAppId:""))}).catch(b=>{f&&$(b instanceof Error?b.message:String(b))}).finally(()=>{f&&q(!1)}),()=>{f=!1}},[]),(0,l.useEffect)(()=>{if(!F)return;let f=!0,b=window.setInterval(()=>{fetch("/api/feed-groups").then(async P=>{let G=await P.json().catch(()=>({}));!P.ok||!G.ok||!f||(m(Array.isArray(G.groups)?G.groups:[]),T(typeof G.larkAppId=="string"?G.larkAppId:""),$(""),O(""),k(""))}).catch(()=>{})},1e3);return()=>{f=!1,window.clearInterval(b)}},[F]);async function j(){let f=S?`?larkAppId=${encodeURIComponent(S)}`:"",b=await fetch(`/api/feed-groups/auth-url${f}`),P=await b.json().catch(()=>({}));if(!b.ok||!P.authUrl){c({title:"\u65E0\u6CD5\u53D1\u8D77\u6807\u7B7E\u6388\u6743",reason:P.error??`HTTP ${b.status}`});return}O(String(P.authUrl)),k("")}async function H(f){z(!0);try{let b=await fetch("/api/feed-groups/oauth-callback",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({callbackUrl:f.trim()})}),P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);let G=await fetch("/api/feed-groups"),i=await G.json().catch(()=>({}));if(!G.ok||!i.ok)throw new Error(i.message??i.error??`HTTP ${G.status}`);m(Array.isArray(i.groups)?i.groups:[]),T(typeof i.larkAppId=="string"?i.larkAppId:""),$(""),O(""),k("")}catch(b){c({title:"\u6807\u7B7E\u6388\u6743\u5931\u8D25",reason:b instanceof Error?b.message:String(b)})}finally{z(!1)}}async function _(f){f.preventDefault();let b=new FormData(f.currentTarget),P=String(b.get("name")??"").trim(),G=String(b.get("bindWorkingDir")??"").trim(),i=String(b.get("roleProfileId")??"").trim(),h=[...g];if(h.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 y=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:P||void 0,larkAppIds:h,bindWorkingDir:G||void 0,roleProfileId:i||void 0,feedGroupId:A||void 0,newFeedGroupName:N||void 0,feedGroupAppId:A||N?S:void 0})}),R=await y.json().catch(()=>({ok:!1,error:`HTTP ${y.status}`}));R.ok&&R.chatId?(p(R),o.onCreated(R,h,P)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:R.error??`HTTP ${y.status}`}),n(!1))}catch(y){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:y}),n(!1)}}if(s){let f=String(s.chatId),b=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(f)}`,P=s.invalidBotIds??[],G=s.invalidUserIds??[],i=Array.isArray(s.oncallBindings)?s.oncallBindings:[],h=i.filter(L=>L?.ok).length,y=i.filter(L=>!L?.ok),R=Oe(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:f})," ",(0,e.jsx)("button",{type:"button","data-copy":f,onClick:()=>{fe(f,t("sessions.copy")).then(L=>{L&&(x(!0),o.setTimer(()=>x(!1),800))})},children:t(v?"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}),i.length>0?y.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",h,"/",i.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",h,"/",i.length,"\u3002",y.map((L,J)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(L?.larkAppId??"?")}),": ",String(L?.error??"unknown")]},`${L?.larkAppId??"?"}-${J}`))]}):null,R?(0,e.jsx)("p",{className:R.kind==="ok"?"hint-ok":"hint-warn",children:R.text}):null,P.length||G.length?(0,e.jsxs)("ul",{children:[P.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:P.join(", ")})]}):null,G.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:G.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:b,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:f=>{_(f)},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)(Ue,{bots:o.bots,tr:t,selected:g,onToggle:(f,b)=>C(P=>{let G=new Set(P);return b?G.add(f):G.delete(f),G})})})]}),(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:I}),(0,e.jsx)(ke,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:I||t("groups.roleProfileNone"),value:I,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(f=>({value:f.profileId,label:f.profileId}))],onChange:d}),(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:A}),(0,e.jsx)(we,{groups:w,selectedId:A,newName:N,disabled:M||!!B,onChange:(f,b)=>{E(f),U(b)}}),(0,e.jsx)("small",{children:"\u5C55\u5F00\u540E\u53EF\u5728\u7B2C\u4E00\u884C\u8F93\u5165\u65B0\u6807\u7B7E\u540D\u79F0\uFF0C\u6216\u9009\u62E9\u4E0B\u65B9\u5DF2\u6709\u6807\u7B7E\u3002"}),M?(0,e.jsx)("small",{children:"\u6B63\u5728\u8BFB\u53D6\u98DE\u4E66\u6807\u7B7E\u2026"}):null,B?(0,e.jsxs)("div",{className:"hint-warn-inline",children:[(0,e.jsx)("small",{children:B})," ",(0,e.jsx)("button",{type:"button",disabled:D,onClick:()=>{j()},children:D?"\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&&!B&&w.length===0?(0,e.jsx)("small",{children:"\u5F53\u524D\u6CA1\u6709\u6807\u7B7E\uFF0C\u53EF\u76F4\u63A5\u521B\u5EFA\u4E00\u4E2A\u3002"}):null]})]}),F?(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(F,"_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:u,placeholder:"http://127.0.0.1:9768/callback?code=\u2026&state=\u2026",onChange:f=>k(f.currentTarget.value)})]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{O(""),k("")},children:"\u53D6\u6D88"}),(0,e.jsx)("button",{type:"button",className:"primary",disabled:!u.trim()||D,onClick:()=>{H(u)},children:D?"\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)(le,{...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,p=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,p?(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",p,"\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 et(o){let{chat:t,tr:r}=o,[n,a]=(0,l.useState)(!1),[c,s]=(0,l.useState)(null),[p,v]=(0,l.useState)(null),[x,g]=(0,l.useState)(new Set),C=(0,l.useMemo)(()=>new Set((t.memberBots??[]).filter(d=>d.inChat).map(d=>d.larkAppId)),[t]);async function I(d){d.preventDefault();let w=[...x];if(w.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),v(null);return}a(!0),s(null),v(null);try{let S=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:w})})).json();if(S.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(S.result){let T=Me(S.result);try{await o.onReloadGroups({force:!0}),v({result:T})}catch(A){v({result:T,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${A}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(S)})}catch(m){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:m})}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:d=>{I(d)},children:[(0,e.jsx)(Ue,{bots:o.bots,excludeIds:C,tr:r,selected:x,onToggle:(d,w)=>g(m=>{let S=new Set(m);return w?S.add(d):S.delete(d),S})}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(le,{...c}):null,p?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ze,{summary:p.result}),p.refreshError?(0,e.jsx)(le,{title:"\u5237\u65B0\u5931\u8D25",reason:p.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 tt(o){let{tr:t}=o,[r,n]=(0,l.useState)([]),[a,c]=(0,l.useState)([]),[s,p]=(0,l.useState)(!0),[v,x]=(0,l.useState)(null),g=(0,l.useMemo)(()=>[...a].sort((u,k)=>u.profileId.localeCompare(k.profileId)),[a]),C=g.length>0,I=r.filter(u=>u.status==="empty").length,d=r.filter(u=>u.status==="error").length,w=!s&&!v&&r.length>0&&d===0,[m,S]=(0,l.useState)("new"),[T,A]=(0,l.useState)(o.suggestedProfileId),[E,N]=(0,l.useState)(""),[U,M]=(0,l.useState)(!1),[q,B]=(0,l.useState)(null),$=m==="overwrite"?E:T.trim(),D=t(m==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),z=v||(s?t("groups.saveProfilePreparing"):d?t("groups.saveProfileFailedLoadSummary",{count:d}):r.length?I?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:I}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,l.useEffect)(()=>{let u=!0;return p(!0),x(null),B(null),(async()=>{try{let[k,j]=await Promise.all([Te(o.chat),Y().catch(()=>[])]);if(!u)return;let H=[...j].sort((_,f)=>_.profileId.localeCompare(f.profileId));n(k),c(j),N(_=>H.some(f=>f.profileId===_)?_:H[0]?.profileId??"")}catch(k){if(!u)return;n([]),c([]),N(""),x(k instanceof Error?k.message:String(k))}finally{u&&p(!1)}})(),()=>{u=!1}},[o.chat]);async function F(u){if(u.preventDefault(),!!w){if(!se($)){B({text:t("groups.saveProfileInvalid"),className:"error"});return}M(!0),B({text:t("groups.saveProfileSaving")});try{let j=(await Promise.all(r.map(async H=>(await fetch(`/api/role-profiles/${encodeURIComponent($)}/${encodeURIComponent(H.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:H.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(j!==r.length){B({text:t("groups.saveProfileFailed",{saved:j,total:r.length}),className:"error"}),M(!1);return}B({text:t("groups.saveProfileDone",{name:$,count:j}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(k){B({text:String(k),className:"error"}),M(!1)}}}function O(u){u==="overwrite"&&!C||(S(u),B(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:u=>{F(u)},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})]}),d?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:d})]}):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)(ee,{label:t("common.loading")})}):v?(0,e.jsx)("div",{className:"g-save-profile-empty",children:v}):r.length?r.map(u=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${u.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:u.botName??u.larkAppId}),(0,e.jsx)("code",{children:u.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${u.status==="error"?"error":"ok"}`,children:t(u.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},u.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:m==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":m==="new",onClick:()=>O("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:m==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":m==="overwrite",disabled:!C,onClick:()=>O("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:m!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:T,maxLength:64,autoComplete:"off",onChange:u=>{A(u.currentTarget.value),B(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:m!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),C?(0,e.jsx)("div",{className:"g-save-profile-picker",children:g.map(u=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${u.profileId===E?"selected":""}`,"data-profile-id":u.profileId,"aria-pressed":u.profileId===E,onClick:()=>{N(u.profileId),S("overwrite"),B(null)},children:[(0,e.jsx)("span",{children:u.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:u.entryCount??0})})]},u.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(m==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${w?"":"warn"}`,children:z}),(0,e.jsx)("div",{className:`g-save-profile-status ${q?.className??""}`,"data-save-profile-status":!0,children:q?.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:!w||U||m==="overwrite"&&!E,children:U?t("groups.saveProfileSaving"):D})]})]})]})}function ot(o){let{member:t,tr:r}=o,n=(0,l.useRef)(null),[a,c]=(0,l.useState)(!!t.oncallChat),[s,p]=(0,l.useState)(t.oncallChat?.workingDir??""),[v,x]=(0,l.useState)(!1),[g,C]=(0,l.useState)(null);async function I(){C(null);let d=s.trim();if(a&&!d){C({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}x(!0);try{let w=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,m=a?await fetch(w,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:d})}):await fetch(w,{method:"DELETE"}),S=await m.json().catch(()=>({}));if(m.ok&&S.ok){C({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${S.resolvedPath??d}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else C({text:`\u2717 ${S.error??m.status}`,className:"hint-warn-inline"})}catch(w){C({text:`\u2717 ${w?.message??w}`,className:"hint-warn-inline"})}finally{x(!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:d=>{c(d.currentTarget.checked),d.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:d=>p(d.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:v,onClick:()=>{I()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${g?.className??""}`,"data-status":!0,children:g?.text??""})]})]})}function rt(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(g=>g.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,l.useState)(()=>new Set);function p(g,C){s(I=>{let d=new Set(I);return C?d.add(g):d.delete(g),d})}async function v(){let g=[...c];if(g.length===0){W("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA",{kind:"warning"});return}if(await re({title:"\u9000\u51FA\u7FA4\u804A",message:`\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`,danger:!0}))try{let I=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:g})})).json(),d=(I.result??[]).map(w=>{if(!w.ok)return`${w.larkAppId}: \u5931\u8D25 (${w.error??"unknown"})`;let m=w.closedSessions??[],S=m.filter(N=>!N.ok).length,T=m.length-S,A=m.filter(N=>N.ok&&N.residual).map(N=>ne(N.residual)),E=m.length===0?"":`\uFF08\u5173\u95ED ${T} \u4E2A\u4F1A\u8BDD${S?`\uFF0C${S} \u4E2A\u5931\u8D25`:""}${A.length?`\uFF0C${A.length} \u4E2A\u6709\u6B8B\u7559\u9700\u4EBA\u5DE5\u6E05\u7406\uFF1A${A.join(", ")}`:""}\uFF09`;return`${w.larkAppId}: OK${E}`}).join(`
2
2
  `);W(d||`Unexpected: ${JSON.stringify(I)}`,{kind:"success"}),await o.onReloadGroups({force:!0})}catch(C){W("Network error: "+C,{kind:"error"})}finally{o.onClose()}}async function x(){if(n.length===0||!await re({title:"\u89E3\u6563\u7FA4\u804A",message:`\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`,danger:!0}))return;let g=[...n].sort((I,d)=>(d.larkAppId===a?1:0)-(I.larkAppId===a?1:0)),C=[];for(let I of g)try{let d=await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/disband`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppId:I.larkAppId})}),w=await d.json();if(w.ok){let m=w.closedSessions??[],S=m.filter(N=>!N.ok).length,T=m.length-S,A=m.filter(N=>N.ok&&N.residual).map(N=>ne(N.residual)),E=m.length===0?"":`
3
3
  \u5173\u95ED\u4E86 ${T} \u4E2A\u4F1A\u8BDD${S?`\uFF0C${S} \u4E2A\u4F1A\u8BDD\u5173\u95ED\u5931\u8D25`:""}${A.length?`
4
4
  \u26A0\uFE0F ${A.length} \u4E2A\u6709\u6B8B\u7559\u9700\u4EBA\u5DE5\u6E05\u7406\uFF1A${A.join(", ")}`:""}\u3002`;W(`\u5DF2\u89E3\u6563\uFF08\u7531 ${I.botName??I.larkAppId} \u6267\u884C\uFF09${E}`,{kind:"success"}),await o.onReloadGroups({force:!0}),o.onClose();return}C.push(`${I.botName??I.larkAppId}: ${w.error??d.status}`)}catch(d){C.push(`${I.botName??I.larkAppId}: ${d}`)}W(`\u6240\u6709\u5728\u7FA4\u673A\u5668\u4EBA\u5747\u65E0\u6CD5\u89E3\u6563\uFF1A
@@ -1,4 +1,4 @@
1
- import{a as Me}from"./chunk-75LEPNN3.js";import{c as Ct,h as Re,q as rt}from"./chunk-NYY66DNC.js";import{d as Te}from"./chunk-R3LJUCEO.js";import"./chunk-QITAMHW6.js";import{G as ke,I as V,x as o,y as Vt,z as Mt}from"./chunk-K232GT3M.js";import{a as Fs,c as Ie}from"./chunk-ARROO6TE.js";import{c as Rt,d as Ds,e as $e}from"./chunk-3YZFAHNK.js";var b=Rt(Ds(),1),gs=Rt(Fs(),1);var tt={bad:0,warn:1,info:2},Ae=["research","edit","run","delegate","discuss"],G=["research","edit","run","delegate","discuss"],Gt=[{key:"overview",label:"insights.tabOverview"},{key:"sessions",label:"insights.tabSessions"},{key:"flow",label:"insights.tabFlow"},{key:"dist",label:"insights.tabDist"},{key:"hot",label:"insights.tabHot"}],Ut=[{key:"all",label:"insights.timeAll",days:0},{key:"1d",label:"insights.time1d",days:1},{key:"7d",label:"insights.time7d",days:7},{key:"30d",label:"insights.time30d",days:30}],Yt=["all","review","failed","slow"],Es=["overview","sessions","flow","dist","hot"],Le=[{key:"recent",label:"insights.sortRecent"},{key:"review",label:"insights.sortReview"},{key:"spans",label:"insights.sortSpans"},{key:"fails",label:"insights.sortFails"},{key:"slow",label:"insights.sortSlow"},{key:"agent",label:"insights.sortAgent"}],De=["recent","review","spans","fails","slow","agent"],Jt=["failure","slow","retry","read_write_imbalance"],Fe=[{key:"all",label:"spanAll"},{key:"user",label:"senderHuman"},{key:"a2a_agent",label:"senderA2A"},{key:"system",label:"senderSystem"}],Ee=[{key:"all",label:"spanAll"},{key:"failure",label:"tag.failure"},{key:"slow",label:"tag.slow"}],lt=new Set(["tool_error","test_failed","typecheck_failed","lint_failed","command_failed","timeout","no_output"]);function Qt(){return{messages:[],total:0,hasMore:!1,nextOffset:0,loading:!1,q:"",role:"all",tag:"all",openOps:new Set}}function T(e){return Number.isFinite(e)?Math.round(e).toLocaleString("en-US"):"-"}function O(e){return e==null||!Number.isFinite(e)?"-":e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function _e(e){return e==="error"?"!":e==="running"?"~":"OK"}function Pt(e,s){return s||(e?e.status==="unsupported_cli"?o("insights.unsupported"):e.status==="transcript_missing"?o("insights.noTranscript"):e.status==="parse_error"?o("insights.parseError"):e.status:"-")}function q(e){return String(e.title??"").replace(/^(?:@\S+\s*)+/,"").trim()||String(e.sessionId??"")}function Xt(e){return e==="bad"?o("insights.sevBad"):e==="warn"?o("insights.sevWarn"):o("insights.sevInfo")}function je(e,s){let n=o(e);return n===e?s:n}function He(e){return je(`insights.suggestion.${e.id}.title`,e.title)}function U(e){let s=`insights.phase.${e}`,n=o(s);return n===s?e:n}function ct(e){return String(e||"unknown").replace(/[^a-z0-9_-]/gi,"-")}function W(e){return`phase-${ct(e)}`}function Ot(e){return!e||e.status!=="ok"?!1:e.agg.failedSpans>0||e.agg.slowSpans>0||e.suggestions.some(s=>s.severity!=="info")}function Be(e){return{session:{sessionId:e.sessionId,cliId:e.cliId,cliSessionId:e.cliSessionId,title:e.title,botName:e.botName,larkAppId:e.larkAppId,workingDir:e.workingDir,status:e.status,lastMessageAt:e.lastMessageAt},report:e.report}}function At(e){return String(e.session.cliId??"unknown")}var Ce=["claude-code","seed","relay","aiden","codex","traex","antigravity"];function qe(e){let s=new Map;for(let n of e){let i=At(n);s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>{let r=Ce.indexOf(n.id),l=Ce.indexOf(i.id);return(r<0?99:r)-(l<0?99:l)||n.id.localeCompare(i.id)})}function dt(e){let s=String(e.session.workingDir??"").replace(/\/+$/,"");return s?s.split("/").pop()||s:""}function We(e){let s=new Map;for(let n of e){let i=dt(n);i&&s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>i.count-n.count||n.id.localeCompare(i.id))}function Lt(e,s,n,i=new Set,r={}){let l=n.trim().toLowerCase();return e.filter(g=>{let c=g.session,d=g.report;return r.analyzableOnly&&d?.status!=="ok"||r.project&&dt(g)!==r.project||r.sinceMs&&Number(c.lastMessageAt??c.spawnedAt??0)<r.sinceMs||i.size&&!i.has(At(g))||s==="review"&&!Ot(d)||s==="failed"&&!(d?.status==="ok"&&d.agg.failedSpans>0)||s==="slow"&&!(d?.status==="ok"&&d.agg.slowSpans>0)?!1:l?`${q(c)} ${V(c)} ${c.cliId??""} ${c.workingDir??""} ${c.sessionId??""}`.toLowerCase().includes(l):!0})}function Ke(e){let s={totalSpans:0,failedSpans:0,slowSpans:0,failByTool:{},phase:{research:{count:0,ms:0},edit:{count:0,ms:0},run:{count:0,ms:0},delegate:{count:0,ms:0},discuss:{count:0,ms:0}},readWriteRatio:null,compactions:0,subagentCostShare:null},n=0,i=new Map;for(let l of e){let g=l.report;if(!g||g.status!=="ok")continue;n+=1;let c=g.agg;s.totalSpans+=c.totalSpans,s.failedSpans+=c.failedSpans,s.slowSpans+=c.slowSpans,s.compactions+=c.compactions;for(let[d,a]of Object.entries(c.failByTool??{}))s.failByTool[d]=(s.failByTool[d]??0)+a;for(let d of Ae){let a=c.phase?.[d];a&&(s.phase[d].count+=a.count,s.phase[d].ms+=a.ms)}for(let d of g.suggestions??[]){let a=i.get(d.id);a?a.count+=1:i.set(d.id,{id:d.id,title:d.title,severity:d.severity,count:1,evidence:d.evidence??[],action:d.action})}}s.readWriteRatio=s.phase.edit.count>0?Number((s.phase.research.count/s.phase.edit.count).toFixed(2)):null;let r=Object.entries(s.failByTool).map(([l,g])=>({tool:l,count:g})).sort((l,g)=>g.count-l.count).slice(0,5);return{totalCount:e.length,analyzedCount:n,agg:s,topFailedTools:r,suggestions:[...i.values()]}}function Z(e){return Ae.reduce((s,n)=>s+(e.agg.phase?.[n]?.ms??0),0)}function ze(e){return e.map(s=>s.report).filter(s=>!!s&&s.status==="ok")}function Ve(e){if(!e.length)return 0;let s=[...e].sort((i,r)=>i-r),n=Math.floor(s.length/2);return s.length%2?s[n]:(s[n-1]+s[n])/2}function _s(e){return e?.status==="ok"?e.agg.failedSpans*6+e.agg.slowSpans*3+e.suggestions.filter(s=>s.severity==="bad").length*5:0}function Ge(e,s){let n=r=>Number(r.session.lastMessageAt??0),i=r=>{let l=r.report,g=l?.status==="ok"?l.agg:null;switch(s){case"spans":return g?.totalSpans??-1;case"fails":return g?.failedSpans??-1;case"slow":return g?.slowSpans??-1;case"agent":return l?.status==="ok"?Z(l):-1;case"review":return _s(l);default:return 0}};return[...e].sort((r,l)=>s==="recent"?n(l)-n(r):i(l)-i(r)||n(l)-n(r))}function Ue(e){let s=`insights.intent.${e}`,n=o(s);return n===s?e:n}function et(e){let s=`insights.result.${e}`,n=o(s);return n===s?e:n}function st(e){let s=`insights.tag.${e}`,n=o(s);return n===s?e:n}function K(e,s){let n=`insights.${e}.${s.id}`,i=o(n,s.params);return i===n?s.id:i}function Ye(e){return K("turnHeadline",e)}var Pe={"shell command":"insights.struct.shell","file edit":"insights.struct.fileEdit","read/search":"insights.struct.readSearch","agent task":"insights.struct.agentTask","tool input":"insights.struct.toolInput","tool result":"insights.struct.toolResult","tool error":"insights.struct.toolError","patch failed":"insights.struct.patchFailed","patch applied":"insights.struct.patchApplied"};function Zt(e){if(!e)return"";let s=e.match(/^exit (-?\d+)$/);return s?o("insights.struct.exit",{code:s[1]}):Pe[e]?je(Pe[e],e):e}function Je(e){return e.status==="error"||!!e.result&&lt.has(e.result.category)}function Dt(e,s){return e&&e.kind!=="unknown"?Ue(e.kind):s}function te(e){return Dt(e.intent,e.tool)}function Ft(e){return e?[e.kind!=="unknown"?Ue(e.kind):"",e.subject,e.detail].filter(Boolean).join(" \xB7 "):""}var js=["failure","retry","read_write_imbalance","slow"];function Qe(e){for(let s of js)if(e.includes(s)){let n=o(`insights.advice.${s}`);if(n!==`insights.advice.${s}`)return n}return""}function Xe(e,s){let n=e.spans??[],i=s?(e.recommendations??[]).find(l=>l.id===s)??null:null;if(!i)return{rec:null,spanIdx:new Set,turnIdx:new Set};let r=(i.evidence?.spanIndexes??[]).filter(l=>Number.isInteger(l)&&l>=0&&l<n.length);return{rec:i,spanIdx:new Set(r),turnIdx:new Set(i.evidence?.turnIndexes??[])}}function Et(e){return e.replace(/<(mentions|attachments|available_bots|system-reminder|quoted_messages|sender)\b[\s\S]*?<\/\1>/g," ").replace(/<botmux_reminder>[\s\S]*?<\/botmux_reminder>/g," ").replace(/<\/?(user_message|local-command-[a-z]+)>/g," ").replace(/<sender\b[^>]*\/?>/g," ").replace(/<mention\b[^>]*\/?>/g," ").replace(/\[用户引用了消息[\s\S]*?\]/g," ").replace(/\[来自[^\]]*@mention\]/g," ").replace(/\[(图片|文件)\s*\d+[^\]\n]*\][^\n]*/g," ").replace(/[ \t]+/g," ").replace(/ *\n */g,`
1
+ import{a as Me}from"./chunk-75LEPNN3.js";import{c as Ct,h as Re,q as rt}from"./chunk-QALRQEKD.js";import{d as Te}from"./chunk-3OJQKYM3.js";import"./chunk-QITAMHW6.js";import{A as Mt,H as ke,J as V,y as o,z as Vt}from"./chunk-IRFGJSPL.js";import{a as Fs,c as Ie}from"./chunk-ARROO6TE.js";import{c as Rt,d as Ds,e as $e}from"./chunk-3YZFAHNK.js";var b=Rt(Ds(),1),gs=Rt(Fs(),1);var tt={bad:0,warn:1,info:2},Ae=["research","edit","run","delegate","discuss"],G=["research","edit","run","delegate","discuss"],Gt=[{key:"overview",label:"insights.tabOverview"},{key:"sessions",label:"insights.tabSessions"},{key:"flow",label:"insights.tabFlow"},{key:"dist",label:"insights.tabDist"},{key:"hot",label:"insights.tabHot"}],Ut=[{key:"all",label:"insights.timeAll",days:0},{key:"1d",label:"insights.time1d",days:1},{key:"7d",label:"insights.time7d",days:7},{key:"30d",label:"insights.time30d",days:30}],Yt=["all","review","failed","slow"],Es=["overview","sessions","flow","dist","hot"],Le=[{key:"recent",label:"insights.sortRecent"},{key:"review",label:"insights.sortReview"},{key:"spans",label:"insights.sortSpans"},{key:"fails",label:"insights.sortFails"},{key:"slow",label:"insights.sortSlow"},{key:"agent",label:"insights.sortAgent"}],De=["recent","review","spans","fails","slow","agent"],Jt=["failure","slow","retry","read_write_imbalance"],Fe=[{key:"all",label:"spanAll"},{key:"user",label:"senderHuman"},{key:"a2a_agent",label:"senderA2A"},{key:"system",label:"senderSystem"}],Ee=[{key:"all",label:"spanAll"},{key:"failure",label:"tag.failure"},{key:"slow",label:"tag.slow"}],lt=new Set(["tool_error","test_failed","typecheck_failed","lint_failed","command_failed","timeout","no_output"]);function Qt(){return{messages:[],total:0,hasMore:!1,nextOffset:0,loading:!1,q:"",role:"all",tag:"all",openOps:new Set}}function T(e){return Number.isFinite(e)?Math.round(e).toLocaleString("en-US"):"-"}function O(e){return e==null||!Number.isFinite(e)?"-":e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function _e(e){return e==="error"?"!":e==="running"?"~":"OK"}function Pt(e,s){return s||(e?e.status==="unsupported_cli"?o("insights.unsupported"):e.status==="transcript_missing"?o("insights.noTranscript"):e.status==="parse_error"?o("insights.parseError"):e.status:"-")}function q(e){return String(e.title??"").replace(/^(?:@\S+\s*)+/,"").trim()||String(e.sessionId??"")}function Xt(e){return e==="bad"?o("insights.sevBad"):e==="warn"?o("insights.sevWarn"):o("insights.sevInfo")}function je(e,s){let n=o(e);return n===e?s:n}function He(e){return je(`insights.suggestion.${e.id}.title`,e.title)}function U(e){let s=`insights.phase.${e}`,n=o(s);return n===s?e:n}function ct(e){return String(e||"unknown").replace(/[^a-z0-9_-]/gi,"-")}function W(e){return`phase-${ct(e)}`}function Ot(e){return!e||e.status!=="ok"?!1:e.agg.failedSpans>0||e.agg.slowSpans>0||e.suggestions.some(s=>s.severity!=="info")}function Be(e){return{session:{sessionId:e.sessionId,cliId:e.cliId,cliSessionId:e.cliSessionId,title:e.title,botName:e.botName,larkAppId:e.larkAppId,workingDir:e.workingDir,status:e.status,lastMessageAt:e.lastMessageAt},report:e.report}}function At(e){return String(e.session.cliId??"unknown")}var Ce=["claude-code","seed","relay","aiden","codex","traex","antigravity"];function qe(e){let s=new Map;for(let n of e){let i=At(n);s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>{let r=Ce.indexOf(n.id),l=Ce.indexOf(i.id);return(r<0?99:r)-(l<0?99:l)||n.id.localeCompare(i.id)})}function dt(e){let s=String(e.session.workingDir??"").replace(/\/+$/,"");return s?s.split("/").pop()||s:""}function We(e){let s=new Map;for(let n of e){let i=dt(n);i&&s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>i.count-n.count||n.id.localeCompare(i.id))}function Lt(e,s,n,i=new Set,r={}){let l=n.trim().toLowerCase();return e.filter(g=>{let c=g.session,d=g.report;return r.analyzableOnly&&d?.status!=="ok"||r.project&&dt(g)!==r.project||r.sinceMs&&Number(c.lastMessageAt??c.spawnedAt??0)<r.sinceMs||i.size&&!i.has(At(g))||s==="review"&&!Ot(d)||s==="failed"&&!(d?.status==="ok"&&d.agg.failedSpans>0)||s==="slow"&&!(d?.status==="ok"&&d.agg.slowSpans>0)?!1:l?`${q(c)} ${V(c)} ${c.cliId??""} ${c.workingDir??""} ${c.sessionId??""}`.toLowerCase().includes(l):!0})}function Ke(e){let s={totalSpans:0,failedSpans:0,slowSpans:0,failByTool:{},phase:{research:{count:0,ms:0},edit:{count:0,ms:0},run:{count:0,ms:0},delegate:{count:0,ms:0},discuss:{count:0,ms:0}},readWriteRatio:null,compactions:0,subagentCostShare:null},n=0,i=new Map;for(let l of e){let g=l.report;if(!g||g.status!=="ok")continue;n+=1;let c=g.agg;s.totalSpans+=c.totalSpans,s.failedSpans+=c.failedSpans,s.slowSpans+=c.slowSpans,s.compactions+=c.compactions;for(let[d,a]of Object.entries(c.failByTool??{}))s.failByTool[d]=(s.failByTool[d]??0)+a;for(let d of Ae){let a=c.phase?.[d];a&&(s.phase[d].count+=a.count,s.phase[d].ms+=a.ms)}for(let d of g.suggestions??[]){let a=i.get(d.id);a?a.count+=1:i.set(d.id,{id:d.id,title:d.title,severity:d.severity,count:1,evidence:d.evidence??[],action:d.action})}}s.readWriteRatio=s.phase.edit.count>0?Number((s.phase.research.count/s.phase.edit.count).toFixed(2)):null;let r=Object.entries(s.failByTool).map(([l,g])=>({tool:l,count:g})).sort((l,g)=>g.count-l.count).slice(0,5);return{totalCount:e.length,analyzedCount:n,agg:s,topFailedTools:r,suggestions:[...i.values()]}}function Z(e){return Ae.reduce((s,n)=>s+(e.agg.phase?.[n]?.ms??0),0)}function ze(e){return e.map(s=>s.report).filter(s=>!!s&&s.status==="ok")}function Ve(e){if(!e.length)return 0;let s=[...e].sort((i,r)=>i-r),n=Math.floor(s.length/2);return s.length%2?s[n]:(s[n-1]+s[n])/2}function _s(e){return e?.status==="ok"?e.agg.failedSpans*6+e.agg.slowSpans*3+e.suggestions.filter(s=>s.severity==="bad").length*5:0}function Ge(e,s){let n=r=>Number(r.session.lastMessageAt??0),i=r=>{let l=r.report,g=l?.status==="ok"?l.agg:null;switch(s){case"spans":return g?.totalSpans??-1;case"fails":return g?.failedSpans??-1;case"slow":return g?.slowSpans??-1;case"agent":return l?.status==="ok"?Z(l):-1;case"review":return _s(l);default:return 0}};return[...e].sort((r,l)=>s==="recent"?n(l)-n(r):i(l)-i(r)||n(l)-n(r))}function Ue(e){let s=`insights.intent.${e}`,n=o(s);return n===s?e:n}function et(e){let s=`insights.result.${e}`,n=o(s);return n===s?e:n}function st(e){let s=`insights.tag.${e}`,n=o(s);return n===s?e:n}function K(e,s){let n=`insights.${e}.${s.id}`,i=o(n,s.params);return i===n?s.id:i}function Ye(e){return K("turnHeadline",e)}var Pe={"shell command":"insights.struct.shell","file edit":"insights.struct.fileEdit","read/search":"insights.struct.readSearch","agent task":"insights.struct.agentTask","tool input":"insights.struct.toolInput","tool result":"insights.struct.toolResult","tool error":"insights.struct.toolError","patch failed":"insights.struct.patchFailed","patch applied":"insights.struct.patchApplied"};function Zt(e){if(!e)return"";let s=e.match(/^exit (-?\d+)$/);return s?o("insights.struct.exit",{code:s[1]}):Pe[e]?je(Pe[e],e):e}function Je(e){return e.status==="error"||!!e.result&&lt.has(e.result.category)}function Dt(e,s){return e&&e.kind!=="unknown"?Ue(e.kind):s}function te(e){return Dt(e.intent,e.tool)}function Ft(e){return e?[e.kind!=="unknown"?Ue(e.kind):"",e.subject,e.detail].filter(Boolean).join(" \xB7 "):""}var js=["failure","retry","read_write_imbalance","slow"];function Qe(e){for(let s of js)if(e.includes(s)){let n=o(`insights.advice.${s}`);if(n!==`insights.advice.${s}`)return n}return""}function Xe(e,s){let n=e.spans??[],i=s?(e.recommendations??[]).find(l=>l.id===s)??null:null;if(!i)return{rec:null,spanIdx:new Set,turnIdx:new Set};let r=(i.evidence?.spanIndexes??[]).filter(l=>Number.isInteger(l)&&l>=0&&l<n.length);return{rec:i,spanIdx:new Set(r),turnIdx:new Set(i.evidence?.turnIndexes??[])}}function Et(e){return e.replace(/<(mentions|attachments|available_bots|system-reminder|quoted_messages|sender)\b[\s\S]*?<\/\1>/g," ").replace(/<botmux_reminder>[\s\S]*?<\/botmux_reminder>/g," ").replace(/<\/?(user_message|local-command-[a-z]+)>/g," ").replace(/<sender\b[^>]*\/?>/g," ").replace(/<mention\b[^>]*\/?>/g," ").replace(/\[用户引用了消息[\s\S]*?\]/g," ").replace(/\[来自[^\]]*@mention\]/g," ").replace(/\[(图片|文件)\s*\d+[^\]\n]*\][^\n]*/g," ").replace(/[ \t]+/g," ").replace(/ *\n */g,`
2
2
  `).replace(/\n{3,}/g,`
3
3
 
4
4
  `).trim()}var _t=new Me({html:!1,linkify:!0,breaks:!0});_t.validateLink=e=>/^(https?:|mailto:)/i.test(e.trim());var Oe=_t.renderer.rules.link_open;_t.renderer.rules.link_open=(e,s,n,i,r)=>(e[s].attrSet("target","_blank"),e[s].attrSet("rel","noopener noreferrer nofollow"),Oe?Oe(e,s,n,i,r):r.renderToken(e,s,n));function Ze(e){try{return _t.render(e).trim()||`<p>${Vt(e)}</p>`}catch{return`<p>${Vt(e)}</p>`}}function wt(e){return e.prompt?.source?.kind??"user"}function ts(e){let s=[];for(let n of e)if(n.role==="agent"){let i=s[s.length-1];i&&i.kind==="ops"&&i.turnIndex===n.turnIndex?i.msgs.push(n):s.push({kind:"ops",turnIndex:n.turnIndex,msgs:[n]})}else s.push({kind:"prompt",msg:n});return s}function es(e){let s=new Map;for(let r of e.events??[])r.phase&&s.set(r.phase,(s.get(r.phase)??0)+(r.durationMs??0)+1);let n="discuss",i=-1;for(let[r,l]of s)l>i&&(i=l,n=r);return n}function ss(e,s,n){let i=Ut.find(l=>l.key===e),r=i&&i.days>0?Date.now()-i.days*864e5:void 0;return{project:s||void 0,sinceMs:r,analyzableOnly:!n}}function ee(){let e=typeof location<"u"&&location.hash||"",s=e.indexOf("?");if(s<0)return{};let n={};for(let[i,r]of new URLSearchParams(e.slice(s+1)))n[i]=r;return n}function ns(e){let s=new URLSearchParams;for(let[i,r]of Object.entries(e))r&&s.set(i,r);let n=s.toString();return"#/insights"+(n?`?${n}`:"")}function as(){let e=ee();return Es.includes(e.tab)?e.tab:"overview"}async function is(){let e=await fetch("/api/insights/summary?limit=200",{cache:"no-store"}),s=await e.json().catch(()=>({}));if(!e.ok||s?.ok===!1||!s.overview)throw new Error(String(s?.error??e.status));return s.overview}async function os(e){let s=await fetch(`/api/sessions/${encodeURIComponent(e)}/insight?detail=spans`,{cache:"no-store"}),n=await s.json().catch(()=>({}));if(!s.ok||n?.ok===!1)throw new Error(String(n?.error??s.status));return n.report}async function rs(e,s){let n=new URLSearchParams({detail:"conversation",offset:String(s.offset),limit:String(s.limit)});s.q&&n.set("q",s.q),s.role&&s.role!=="all"&&n.set("role",s.role),s.tag&&s.tag!=="all"&&n.set("tag",s.tag);let i=await fetch(`/api/sessions/${encodeURIComponent(e)}/insight?${n.toString()}`,{cache:"no-store"}),r=await i.json().catch(()=>({}));if(!i.ok||r?.ok===!1)throw new Error(String(r?.error??i.status));let l=r?.conversation;return{messages:l?.messages??[],total:l?.total??0,hasMore:!!l?.hasMore,nextOffset:l?.nextOffset??s.offset+(l?.messages?.length??0)}}async function ls(e,s){let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/insight/turn/${s}?offset=0&limit=40000`,{cache:"no-store"}),i=await n.json().catch(()=>({}));if(!n.ok||i?.ok===!1)throw new Error(String(i?.error??n.status));return i?.turn?.prompt??{text:"",truncated:!1}}function cs(e){let s=e.session;return`${V(s)} \xB7 ${String(s.cliId??"-")}${s.workingDir?` \xB7 ${dt(e)}`:""} \xB7 ${Mt(s.lastMessageAt??s.spawnedAt??0)}`}var t=Rt($e(),1),se="__all__";function ds(e,s,n){return Math.min(Math.max(e,s),n)}function Hs(e){let s=e.getBoundingClientRect(),n=12,i=Math.min(420,Math.max(280,window.innerWidth-n*2)),r=ds(Math.round(s.left+s.width/2-i/2),n,Math.max(n,window.innerWidth-i-n)),l=Math.round(s.bottom+8),g=ds(l,n,Math.max(n,window.innerHeight-132)),c=Math.max(140,Math.floor(window.innerHeight-g-n));return{top:g,left:r,width:i,maxHeight:c}}function pt(e,s){let n=new Set(e);return n.has(s)?n.delete(s):n.add(s),n}function us(e,s){let n=new Set(e);return n.add(s),n}function Ht({text:e,className:s="md-body"}){return(0,t.jsx)("div",{className:s,dangerouslySetInnerHTML:{__html:Ze(e)}})}function Bs({tip:e}){return(0,t.jsx)("div",{id:"insight-tip",className:"ins-tip",role:"tooltip",hidden:!e.visible,style:{left:e.x,top:e.y},children:e.text})}function Y({label:e,value:s,sub:n}){return(0,t.jsxs)("div",{className:"card",children:[(0,t.jsx)("div",{className:"cv",children:s}),(0,t.jsx)("div",{className:"cl",children:e}),n?(0,t.jsx)("div",{className:"cs",children:n}):null]})}function ae(){return(0,t.jsxs)("p",{className:"insight-disclosure",children:["\u2696\uFE0E ",o("insights.disclosure")]})}function ie({phase:e}){let s=Object.entries(e??{}).filter(([,n])=>n.count>0||n.ms>0);return s.length?(0,t.jsx)("div",{className:"mph",children:s.map(([n,i])=>{let r=Math.max(1,i.ms||i.count);return(0,t.jsx)("i",{className:W(n),style:{flex:r},title:`${U(n)} \xB7 ${i.count} \xB7 ${O(i.ms)}`},n)})}):null}function qs({active:e,onChange:s}){return(0,t.jsx)("div",{className:"insight-tabs",role:"tablist",children:Gt.map(n=>(0,t.jsx)("button",{type:"button",className:`itab${n.key===e?" on":""}`,role:"tab","aria-selected":n.key===e,onClick:()=>s(n.key),children:o(n.label)},n.key))})}function Ws({data:e}){let s=e.agg,n=s.readWriteRatio===null?"-":s.readWriteRatio.toFixed(1),i=e.topFailedTools.slice(0,5),r=[...e.suggestions].sort((l,g)=>tt[l.severity]-tt[g.severity]||g.count-l.count).slice(0,6);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"cards insights-metrics",children:[(0,t.jsx)(Y,{label:o("insights.metricSessions"),value:T(e.totalCount),sub:o("insights.metricAnalyzed",{count:e.analyzedCount})}),(0,t.jsx)(Y,{label:o("insights.metricSpans"),value:T(s.totalSpans),sub:o("insights.metricSafe")}),(0,t.jsx)(Y,{label:o("insights.metricFailed"),value:T(s.failedSpans),sub:i[0]?`${i[0].tool} \xD7${i[0].count}`:""}),(0,t.jsx)(Y,{label:o("insights.metricSlow"),value:T(s.slowSpans)}),(0,t.jsx)(Y,{label:o("insights.metricRw"),value:n,sub:o("insights.metricCompactions",{count:s.compactions})})]}),(0,t.jsxs)("div",{className:"insights-overview-grid",children:[(0,t.jsxs)("section",{className:"block recblock",children:[(0,t.jsx)("h3",{children:o("insights.recommendations")}),(0,t.jsx)("div",{className:"reclist",children:r.length?r.map(l=>(0,t.jsxs)("div",{className:`rec ${l.severity}`,children:[(0,t.jsxs)("div",{className:"rectop",children:[(0,t.jsx)("b",{children:He(l)}),(0,t.jsx)("span",{children:Xt(l.severity)})]}),(0,t.jsx)("div",{className:"recev",children:o("insights.seenInSessions",{count:l.count})})]},l.id)):(0,t.jsx)("p",{className:"mut",children:o("insights.noRecommendations")})})]}),(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.toolFailures")}),(0,t.jsx)(ms,{rows:i.map(l=>({key:l.tool,label:l.tool,count:l.count})),empty:o("insights.noFailures")})]})]}),(0,t.jsx)(ae,{})]})}function ms({rows:e,empty:s,renderValue:n,onRowClick:i}){if(!e.length)return(0,t.jsx)("div",{className:"hbars",children:(0,t.jsx)("p",{className:"mut",children:s})});let r=Math.max(1,...e.map(l=>l.count));return(0,t.jsx)("div",{className:"hbars",children:e.map(l=>{let g=Math.max(l.count?4:0,Math.round(l.count/r*100)),c=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"hblabel",title:l.label,children:l.label}),(0,t.jsx)("div",{className:"hbtrack",children:(0,t.jsx)("div",{className:"hbfill",style:{width:`${g}%`}})}),(0,t.jsxs)("div",{className:"hbval",children:[n?n(l):T(l.count),l.sub]})]});return i?(0,t.jsx)("button",{type:"button",className:"hbrow hbrow-click",onClick:()=>i(l),children:c},l.key):(0,t.jsx)("div",{className:"hbrow",children:c},l.key)})})}function Ks({records:e}){let i=Date.now(),r=new Array(28).fill(0);for(let c of e){let d=Number(c.session.lastMessageAt??0);if(!d)continue;let a=Math.floor((i-d)/864e5);a>=0&&a<28&&(r[27-a]+=1)}let l=r.reduce((c,d)=>c+d,0);if(!l)return null;let g=Math.max(1,...r);return(0,t.jsxs)("section",{className:"block trend-block",children:[(0,t.jsxs)("div",{className:"ihist-head",children:[(0,t.jsx)("h3",{children:o("insights.distTrend")}),(0,t.jsxs)("span",{className:"mut",children:[o("insights.distTrendSub")," \xB7 ",l]})]}),(0,t.jsx)("div",{className:"trend",children:r.map((c,d)=>{let a=new Date(i-(27-d)*864e5),v=`${a.getMonth()+1}-${a.getDate()} \xB7 ${c}`;return(0,t.jsx)("i",{className:"trendbar",style:{height:`${c?Math.max(8,Math.round(c/g*100)):2}%`},title:v},d)})})]})}function ut({title:e,values:s,bins:n,fmtMedian:i=T,sortKey:r,onSort:l}){let g=n.map(a=>({label:a.label,count:s.filter(a.test).length})),c=Math.max(1,...g.map(a=>a.count)),d=Math.max(1,s.length);return(0,t.jsxs)("section",{className:"block ihist",children:[(0,t.jsxs)("div",{className:"ihist-head",children:[(0,t.jsx)("h3",{children:e}),(0,t.jsx)("span",{className:"mut",children:o("insights.distMedian",{v:i(Ve(s))})}),r?(0,t.jsxs)("button",{type:"button",className:"ihist-jump",onClick:()=>l?.(r),children:[o("insights.viewSessions")," \u203A"]}):null]}),(0,t.jsx)("div",{className:"hbars",children:g.map(a=>{let v=Math.max(a.count?4:0,Math.round(a.count/c*100)),p=Math.round(a.count/d*100);return(0,t.jsxs)("div",{className:"hbrow",children:[(0,t.jsx)("div",{className:"hblabel",children:a.label}),(0,t.jsx)("div",{className:"hbtrack",children:(0,t.jsx)("div",{className:"hbfill",style:{width:`${v}%`}})}),(0,t.jsxs)("div",{className:"hbval",children:[T(a.count),(0,t.jsxs)("small",{children:[p,"%"]})]})]},a.label)})})]})}function zs({records:e,onSort:s}){let n=ze(e);if(!n.length)return(0,t.jsx)("div",{className:"insight-empty",children:o("insights.distEmpty")});let i=n.map(a=>(a.hot?.files??[]).reduce((v,p)=>v+(p.added??0)+(p.removed??0),0)),r=n.map(a=>a.agg.totalSpans),l=n.map(a=>a.agg.failedSpans),g=n.map(a=>a.agg.slowSpans),c=n.map(a=>Z(a)/6e4),d=n.map(a=>a.agg.readWriteRatio).filter(a=>a!==null&&Number.isFinite(a));return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"mut ins-hint",children:o("insights.distHint")}),(0,t.jsxs)("div",{className:"ihist-grid",children:[(0,t.jsx)(Ks,{records:e}),(0,t.jsx)(ut,{title:o("insights.distSpans"),values:r,onSort:s,sortKey:"spans",bins:[{label:"0-10",test:a=>a<=10},{label:"11-50",test:a=>a>10&&a<=50},{label:"51-200",test:a=>a>50&&a<=200},{label:"201-500",test:a=>a>200&&a<=500},{label:"500+",test:a=>a>500}]}),(0,t.jsx)(ut,{title:o("insights.distFailed"),values:l,onSort:s,sortKey:"fails",bins:[{label:"0",test:a=>a===0},{label:"1-2",test:a=>a>=1&&a<=2},{label:"3-5",test:a=>a>=3&&a<=5},{label:"6-10",test:a=>a>=6&&a<=10},{label:"10+",test:a=>a>10}]}),(0,t.jsx)(ut,{title:o("insights.distSlow"),values:g,onSort:s,sortKey:"slow",bins:[{label:"0",test:a=>a===0},{label:"1-2",test:a=>a>=1&&a<=2},{label:"3-5",test:a=>a>=3&&a<=5},{label:"5+",test:a=>a>5}]}),(0,t.jsx)(ut,{title:o("insights.distAgentTime"),values:c,onSort:s,sortKey:"agent",fmtMedian:a=>`${Math.round(a)}m`,bins:[{label:"<1m",test:a=>a<1},{label:"1-5m",test:a=>a>=1&&a<5},{label:"5-30m",test:a=>a>=5&&a<30},{label:"30m-2h",test:a=>a>=30&&a<120},{label:"2h+",test:a=>a>=120}]}),d.length?(0,t.jsx)(ut,{title:o("insights.distRw"),values:d,fmtMedian:a=>a.toFixed(1),bins:[{label:"0",test:a=>a===0},{label:"0-1",test:a=>a>0&&a<1},{label:"1-3",test:a=>a>=1&&a<3},{label:"3+",test:a=>a>=3}]}):null,(0,t.jsx)(ut,{title:o("insights.distChurn"),values:i,bins:[{label:"0",test:a=>a===0},{label:"1-100",test:a=>a>0&&a<=100},{label:"100-1k",test:a=>a>100&&a<=1e3},{label:"1k-10k",test:a=>a>1e3&&a<=1e4},{label:"10k+",test:a=>a>1e4}]})]}),(0,t.jsx)(ae,{})]})}function Vs({records:e,onSession:s}){let n=e.filter(c=>c.report&&c.report.status==="ok"&&c.report.agg);if(!n.length)return(0,t.jsx)("div",{className:"insight-empty",children:o("insights.distEmpty")});let i={};for(let c of G)i[c]={count:0,ms:0};for(let c of n)for(let d of G){let a=c.report.agg.phase?.[d];a&&(i[d].count+=a.count,i[d].ms+=a.ms)}let r=G.reduce((c,d)=>c+i[d].count,0)||1,l=G.reduce((c,d)=>c+i[d].ms,0)||1,g=[...n].sort((c,d)=>Z(d.report)-Z(c.report)).slice(0,40);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"mut ins-hint",children:o("insights.flowHint")}),(0,t.jsxs)("section",{className:"block flow-pipe-block",children:[(0,t.jsx)("h3",{children:o("insights.flowPipeline")}),(0,t.jsx)("p",{className:"mut flow-sub",children:o("insights.flowPipeSub")}),(0,t.jsx)("div",{className:"flow-pipe",children:G.map((c,d)=>{let a=i[c],v=Math.round(a.count/r*100),p=Math.round(a.ms/l*100);return(0,t.jsxs)("span",{style:{display:"contents"},children:[(0,t.jsxs)("div",{className:"flow-node",children:[(0,t.jsx)("i",{className:`flow-dot ${W(c)}`}),(0,t.jsx)("strong",{children:U(c)}),(0,t.jsxs)("span",{className:"flow-n",children:[T(a.count),(0,t.jsxs)("em",{children:[" \xB7 ",v,"%"]})]}),(0,t.jsxs)("span",{className:"flow-t",children:[O(a.ms),(0,t.jsxs)("em",{children:[" \xB7 ",p,"%"]})]})]}),d<G.length-1?(0,t.jsx)("span",{className:"flow-arrow",children:"\u2192"}):null]},c)})})]}),(0,t.jsxs)("div",{className:"insights-overview-grid",children:[(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.flowShares")}),(0,t.jsxs)("div",{className:"flow-bhead",children:[(0,t.jsx)("span",{}),(0,t.jsx)("span",{children:o("insights.flowActShare")}),(0,t.jsx)("span",{children:o("insights.flowTimeShare")})]}),(0,t.jsx)("div",{className:"flow-bars",children:G.map(c=>{let d=i[c],a=d.count/r*100,v=d.ms/l*100;return(0,t.jsxs)("div",{className:"flow-brow",children:[(0,t.jsxs)("span",{className:"flow-blabel",children:[(0,t.jsx)("i",{className:W(c)}),U(c)]}),(0,t.jsxs)("span",{className:"flow-btrack",children:[(0,t.jsx)("span",{className:`flow-bfill ${W(c)}`,style:{width:`${Math.max(2,a).toFixed(1)}%`}}),(0,t.jsxs)("em",{children:[Math.round(a),"%"]})]}),(0,t.jsxs)("span",{className:"flow-btrack",children:[(0,t.jsx)("span",{className:`flow-bfill ${W(c)}`,style:{width:`${Math.max(2,v).toFixed(1)}%`}}),(0,t.jsxs)("em",{children:[Math.round(v),"%"]})]})]},c)})})]}),(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.flowRhythm")}),(0,t.jsx)("div",{className:"flow-rhythm",children:g.map(c=>(0,t.jsxs)("button",{type:"button",className:"flow-sess",onClick:()=>s(String(c.session.sessionId)),children:[(0,t.jsx)("span",{className:"flow-stitle",children:q(c.session)}),(0,t.jsx)(ie,{phase:c.report.agg.phase}),(0,t.jsx)("span",{className:"flow-stime",children:O(Z(c.report))})]},String(c.session.sessionId)))}),(0,t.jsx)("div",{className:"rl-legend",children:G.map(c=>(0,t.jsxs)("span",{className:"rl-item",children:[(0,t.jsx)("i",{className:W(c)}),U(c)]},c))})]})]}),(0,t.jsx)(ae,{})]})}function Gs({records:e,openHot:s,onToggleHot:n,onProject:i,onSession:r}){let l=e.filter(m=>!!m.report&&m.report.status==="ok");if(!l.length)return(0,t.jsx)("div",{className:"insight-empty",children:o("insights.distEmpty")});let g=new Map,c=new Map,d=new Map,a=(m,f,P,C,h)=>{let N=m.get(f);return N||(N={key:f,label:P,sessions:[],reads:0,edits:0,runs:0,fails:0,count:0},m.set(f,N)),N.sessions.some(D=>D.id===C)||N.sessions.push({id:C,title:h}),N};for(let m of l){let f=String(m.session.sessionId),P=q(m.session),C=m.report.hot;for(let h of C?.files??[]){let N=a(g,`file:${h.path}`,h.path,f,P);N.reads+=h.reads,N.edits+=h.edits}for(let h of C?.cmds??[]){let N=a(c,`cmd:${h.cmd}`,h.cmd,f,P);N.runs+=h.runs,N.fails+=h.fails}for(let h of C?.errs??[]){let N=a(d,`err:${h.tool} ${h.result}`,`${h.tool} \xB7 ${et(h.result)}`,f,P);N.count+=h.count}}let v=(m,f)=>f.sessions.length-m.sessions.length,p=[...g.values()].sort((m,f)=>v(m,f)||f.edits+f.reads-(m.edits+m.reads)).slice(0,12),w=[...c.values()].sort((m,f)=>v(m,f)||f.fails-m.fails||f.runs-m.runs).slice(0,12),y=[...d.values()].sort((m,f)=>v(m,f)||f.count-m.count).slice(0,10),x=new Map;for(let m of l){let f=dt(m);if(!f)continue;let P=x.get(f)??{sessions:0,fails:0};P.sessions+=1,P.fails+=m.report.agg.failedSpans,x.set(f,P)}let M=[...x.entries()].map(([m,f])=>({id:m,...f})).sort((m,f)=>f.fails-m.fails||f.sessions-m.sessions).slice(0,10).map(m=>({key:m.id,label:m.id,count:m.sessions,sub:(0,t.jsxs)("small",{children:[m.fails," ",o("insights.hotFailsCol")]})})),k=[...l].filter(m=>m.report.agg.slowSpans>0).sort((m,f)=>f.report.agg.slowSpans-m.report.agg.slowSpans).slice(0,8);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"mut ins-hint",children:o("insights.hotHint")}),(0,t.jsxs)("div",{className:"hot-grid",children:[(0,t.jsx)(ne,{title:o("insights.hotFiles"),rows:p,openHot:s,onToggle:n,onSession:r,meta:m=>`${o("insights.readsShort")}${m.reads} \xB7 ${o("insights.editsShort")}${m.edits}`}),(0,t.jsx)(ne,{title:o("insights.hotCommands"),rows:w,openHot:s,onToggle:n,onSession:r,meta:m=>(0,t.jsxs)(t.Fragment,{children:[m.runs,"\xD7",m.fails?(0,t.jsxs)(t.Fragment,{children:[" \xB7 ",(0,t.jsxs)("span",{className:"bad",children:[m.fails," ",o("insights.hotFailsCol")]})]}):null]})}),(0,t.jsx)(ne,{title:o("insights.hotErrors"),rows:y,openHot:s,onToggle:n,onSession:r,meta:m=>`${m.count}\xD7`}),(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.hotProjects")}),(0,t.jsx)(ms,{rows:M,empty:"-",onRowClick:m=>i(m.key),renderValue:m=>T(m.count)})]}),(0,t.jsxs)("section",{className:"block hot-sessions",children:[(0,t.jsx)("h3",{children:o("insights.hotSlowSessions")}),(0,t.jsx)("div",{className:"slist",children:k.length?k.map(m=>{let f=m.report.agg;return(0,t.jsxs)("button",{type:"button",className:"srow",onClick:()=>r(String(m.session.sessionId)),children:[(0,t.jsxs)("div",{className:"srmain",children:[(0,t.jsx)("strong",{children:q(m.session)}),(0,t.jsxs)("small",{children:[V(m.session)," \xB7 ",String(m.session.cliId??"-")]})]}),(0,t.jsxs)("div",{className:"srstats",children:[(0,t.jsxs)("b",{children:[o("insights.hotSlowCol"),(0,t.jsx)("em",{children:T(f.slowSpans)})]}),(0,t.jsxs)("b",{children:["span",(0,t.jsx)("em",{children:T(f.totalSpans)})]})]})]},String(m.session.sessionId))}):(0,t.jsx)("p",{className:"mut",children:"-"})})]})]})]})}function ne({title:e,rows:s,openHot:n,onToggle:i,onSession:r,meta:l}){return(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:e}),(0,t.jsx)("div",{className:"hotlist",children:s.length?s.map(g=>{let c=n.has(g.key);return(0,t.jsxs)("div",{className:`hotitem${c?" open":""}`,children:[(0,t.jsxs)("button",{type:"button",className:"hotrow","aria-expanded":c,onClick:()=>i(g.key),children:[(0,t.jsx)("span",{className:"hotlabel",title:g.label,children:g.label}),(0,t.jsx)("span",{className:"hotmeta",children:l(g)}),(0,t.jsxs)("span",{className:"hotses",children:[g.sessions.length," ",o("insights.hotSessionsCol")]})]}),c?(0,t.jsx)("div",{className:"hot-sess",children:g.sessions.map(d=>(0,t.jsx)("button",{type:"button",className:"hot-sesslink",onClick:()=>r(d.id),children:d.title||d.id},d.id))}):null]},g.key)}):(0,t.jsx)("p",{className:"mut",children:"-"})})]})}function Us({sort:e,layout:s,onSort:n,onLayout:i}){let r=Le.map(g=>({value:g.key,label:o(g.label)})),l=r.find(g=>g.value===e)?.label??o("insights.sortLabel");return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(rt,{id:"insight-session-sort",className:"insight-sort-menu",ariaLabel:o("insights.sortLabel"),label:l,value:e,options:r,onChange:n}),(0,t.jsx)("div",{className:"insight-layout-switch",role:"group","aria-label":`${o("insights.layoutCard")} / ${o("insights.layoutTable")}`,children:[["card","insights.layoutCard"],["table","insights.layoutTable"]].map(([g,c])=>(0,t.jsx)("button",{type:"button",className:s===g?"active":"","aria-pressed":s===g,onClick:()=>i(g),children:o(c)},g))})]})}function Ys({records:e,selectedId:s,wide:n,onSelect:i,emptyHint:r}){if(!e.length)return(0,t.jsxs)("div",{className:"insight-empty",children:[o("insights.empty"),r?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("br",{}),(0,t.jsx)("span",{className:"mut",children:r})]}):null]});let l=(g,c,d=!1)=>(0,t.jsxs)("b",{className:d?"bad":void 0,children:[g,(0,t.jsx)("em",{children:c})]});return(0,t.jsx)("div",{className:`slist${n?" wide":""}`,children:e.map(g=>{let c=g.session,d=g.report,a=d?.status==="ok",v=d?.agg,p=v?.phase?.research?.count??0,w=v?.phase?.edit?.count??0;return(0,t.jsxs)("button",{type:"button",className:`srow${c.sessionId===s?" on":""}${Ot(d)?" review":""}`,onClick:()=>i(String(c.sessionId)),children:[(0,t.jsxs)("div",{className:"srmain",children:[(0,t.jsx)("strong",{children:q(c)}),(0,t.jsx)("small",{children:cs(g)}),a?(0,t.jsx)(ie,{phase:d.agg.phase}):null]}),a?(0,t.jsxs)("div",{className:"srstats",children:[l(o("insights.spansShort"),T(v.totalSpans)),l(o("insights.failedShort"),T(v.failedSpans),v.failedSpans>0),l(o("insights.slowShort"),T(v.slowSpans)),n?(0,t.jsxs)(t.Fragment,{children:[l(o("insights.readsShort"),T(p)),l(o("insights.editsShort"),T(w)),l(o("insights.durShort"),O(Z(d)))]}):null,l(o("insights.rwShort"),v.readWriteRatio!==null?v.readWriteRatio.toFixed(1):"-")]}):(0,t.jsx)("div",{className:"srmsg",children:Pt(d,g.error)})]},String(c.sessionId))})})}function Js({records:e,selectedId:s,onSelect:n,emptyHint:i}){return e.length?(0,t.jsxs)("div",{className:"stable",children:[(0,t.jsxs)("div",{className:"strow sthead",children:[(0,t.jsx)("span",{className:"stc-title",children:o("insights.colTitle")}),(0,t.jsx)("span",{className:"stc-proj",children:o("insights.colProject")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.spansShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.failedShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.slowShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.rwShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.durShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.colTime")})]}),e.map(r=>{let l=r.session,g=r.report,c=g?.status==="ok",d=g?.agg;return(0,t.jsxs)("button",{type:"button",className:`strow${l.sessionId===s?" on":""}${Ot(g)?" review":""}${c?"":" nostat"}`,onClick:()=>n(String(l.sessionId)),children:[(0,t.jsxs)("span",{className:"stc-title",children:[(0,t.jsx)("strong",{children:q(l)}),(0,t.jsxs)("small",{children:[V(l)," \xB7 ",String(l.cliId??"-")]})]}),(0,t.jsx)("span",{className:"stc-proj",children:l.workingDir?dt(r):"-"}),c?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"stc-num",children:T(d.totalSpans)}),(0,t.jsx)("span",{className:`stc-num${d.failedSpans?" bad":""}`,children:T(d.failedSpans)}),(0,t.jsx)("span",{className:"stc-num",children:T(d.slowSpans)}),(0,t.jsx)("span",{className:"stc-num",children:d.readWriteRatio!==null?d.readWriteRatio.toFixed(1):"-"}),(0,t.jsx)("span",{className:"stc-num",children:O(Z(g))})]}):(0,t.jsx)("span",{className:"stc-msg",children:Pt(g,r.error)}),(0,t.jsx)("span",{className:"stc-num stc-time",children:Mt(l.lastMessageAt??l.spawnedAt??0)})]},String(l.sessionId))})]}):(0,t.jsxs)("div",{className:"insight-empty",children:[o("insights.empty"),i?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("br",{}),(0,t.jsx)("span",{className:"mut",children:i})]}):null]})}function jt({label:e,preview:s}){return s?.text?(0,t.jsxs)("div",{className:"span-io",children:[(0,t.jsx)("span",{className:"span-io-label",children:e}),(0,t.jsxs)("pre",{className:"span-io-text",children:[s.text,s.truncated?`
@@ -1,4 +1,4 @@
1
- import{a as T,b as I,d as N,e as P,f as _,g as q}from"./chunk-XJ7BGPJH.js";import{a as B}from"./chunk-CEUCNZFJ.js";import{a as E}from"./chunk-QITAMHW6.js";import{C as x,G as O,I as S,K as W,x as r,y as n,z as C}from"./chunk-K232GT3M.js";import"./chunk-3YZFAHNK.js";function F(t){let o=String(t??"unknown"),e=`sessions.status.${o}`,i=r(e);return i===e?o:i}function D(t){return String(t??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function G(t){let o=String(t??"unknown");return`<span class="status status-${n(D(o))}">${n(F(o))}</span>`}function z(t){return W(t?.title)||String(t?.sessionId??"")}var A=14,K=49,U=18;function j(){let t=[...E.sessions.values()].filter(o=>typeof o?.sessionId=="string"&&o.sessionId&&o.status!=="closed").sort((o,e)=>Number(e.lastMessageAt??0)-Number(o.lastMessageAt??0));return[...new Set(t.map(o=>String(o.sessionId)))]}function J(t,o,e){let i=Math.max(0,Math.floor(e)),s=Math.max(1,t.width),m=Math.max(1,t.height),a=s/m,l=Math.max(1,o.width),p=Math.max(180,m-Math.max(0,o.top)-U);if(i<=0)return{columns:1,rows:0,frameWidth:Math.floor(l),frameHeight:Math.floor(l/a),ratio:a};let d=null;for(let u=1;u<=i;u+=1){let b=Math.ceil(i/u),f=(l-A*(u-1))/u,L=(p-A*(b-1)-K*b)/b;if(f<=0||L<=0)continue;let h=Math.max(1,Math.min(f,L*a)),M=h/a,c=h*M;(!d||c>d.score)&&(d={columns:u,rows:b,frameWidth:h,frameHeight:M,score:c})}if(!d){let u=Math.min(i,Math.max(1,Math.floor(l/220))),b=Math.ceil(i/u),f=Math.max(1,(l-A*(u-1))/u);return{columns:u,rows:b,frameWidth:Math.floor(f),frameHeight:Math.floor(f/a),ratio:a}}return{columns:d.columns,rows:d.rows,frameWidth:Math.floor(d.frameWidth),frameHeight:Math.floor(d.frameHeight),ratio:a}}function Q(t,o){let e=Math.max(1,Math.floor(t.width)),i=Math.max(1,Math.floor(t.height)),s=Math.max(1,o.width),m=Math.max(1,o.height),a=Math.min(1,s/e,m/i);return{width:e,height:i,scale:a}}function V(t,o){return t?`frame:${T(t,o)??"none"}`:"missing"}function X(t,o){let e=E.sessions.get(t),i=o?nt(t):"";if(!e)return`<div class="monitor-room-card-title">
1
+ import{a as T,b as I,d as N,e as P,f as _,g as q}from"./chunk-XJ7BGPJH.js";import{a as B}from"./chunk-CEUCNZFJ.js";import{a as E}from"./chunk-QITAMHW6.js";import{A as C,D as x,H as O,J as S,L as W,y as r,z as n}from"./chunk-IRFGJSPL.js";import"./chunk-3YZFAHNK.js";function F(t){let o=String(t??"unknown"),e=`sessions.status.${o}`,i=r(e);return i===e?o:i}function D(t){return String(t??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function G(t){let o=String(t??"unknown");return`<span class="status status-${n(D(o))}">${n(F(o))}</span>`}function z(t){return W(t?.title)||String(t?.sessionId??"")}var A=14,K=49,U=18;function j(){let t=[...E.sessions.values()].filter(o=>typeof o?.sessionId=="string"&&o.sessionId&&o.status!=="closed").sort((o,e)=>Number(e.lastMessageAt??0)-Number(o.lastMessageAt??0));return[...new Set(t.map(o=>String(o.sessionId)))]}function J(t,o,e){let i=Math.max(0,Math.floor(e)),s=Math.max(1,t.width),m=Math.max(1,t.height),a=s/m,l=Math.max(1,o.width),p=Math.max(180,m-Math.max(0,o.top)-U);if(i<=0)return{columns:1,rows:0,frameWidth:Math.floor(l),frameHeight:Math.floor(l/a),ratio:a};let d=null;for(let u=1;u<=i;u+=1){let b=Math.ceil(i/u),f=(l-A*(u-1))/u,L=(p-A*(b-1)-K*b)/b;if(f<=0||L<=0)continue;let h=Math.max(1,Math.min(f,L*a)),M=h/a,c=h*M;(!d||c>d.score)&&(d={columns:u,rows:b,frameWidth:h,frameHeight:M,score:c})}if(!d){let u=Math.min(i,Math.max(1,Math.floor(l/220))),b=Math.ceil(i/u),f=Math.max(1,(l-A*(u-1))/u);return{columns:u,rows:b,frameWidth:Math.floor(f),frameHeight:Math.floor(f/a),ratio:a}}return{columns:d.columns,rows:d.rows,frameWidth:Math.floor(d.frameWidth),frameHeight:Math.floor(d.frameHeight),ratio:a}}function Q(t,o){let e=Math.max(1,Math.floor(t.width)),i=Math.max(1,Math.floor(t.height)),s=Math.max(1,o.width),m=Math.max(1,o.height),a=Math.min(1,s/e,m/i);return{width:e,height:i,scale:a}}function V(t,o){return t?`frame:${T(t,o)??"none"}`:"missing"}function X(t,o){let e=E.sessions.get(t),i=o?nt(t):"";if(!e)return`<div class="monitor-room-card-title">
2
2
  <strong>${n(t)}</strong>
3
3
  <span>${n(r("monitorRoom.missing"))}</span>
4
4
  </div>${i}`;let s=z(e),m=T(e),a=S(e),l=m?rt(t):"";return`<div class="monitor-room-card-title">
@@ -1,2 +1,2 @@
1
- import{c as G,d as f,j as _,m as H,n as T,o as D,p as A}from"./chunk-NYY66DNC.js";import{d as k}from"./chunk-R3LJUCEO.js";import"./chunk-QITAMHW6.js";import"./chunk-K232GT3M.js";import{c as U}from"./chunk-ARROO6TE.js";import{c as $,d as Y,e as K}from"./chunk-3YZFAHNK.js";var g=$(Y(),1);var e=$(K(),1);function b(n){let s=Number(n);return!Number.isFinite(s)||s<=0?"-":s>=1024**3?`${(s/1024**3).toFixed(1)} GiB`:s>=1024**2?`${(s/1024**2).toFixed(0)} MiB`:`${Math.max(1,Math.round(s/1024))} KiB`}function N(n){let s=Number(n);return Number.isFinite(s)?`${s.toFixed(1)}%`:"-"}function S(n,s){return s?N(n):"-"}function q(n){return n?.cpuReady!==!1}function d(n){let s=Number(n);return Number.isFinite(s)?String(s):"-"}function E(n){let s=Number(n);if(!Number.isFinite(s)||s<0)return"-";if(s===0)return"0s";if(s<6e4)return`${Math.max(1,Math.floor(s/1e3))}s`;let r=Math.floor(s/6e4);if(r<60)return`${Math.max(1,r)}m`;let t=Math.floor(r/60),o=r%60;return o?`${t}h ${o}m`:`${t}h`}function Z(n){return n==="fresh"||n==="stale"||n==="unsupported"?n:"unknown"}function j(n){return n?`${n.botName||"-"} \xB7 ${n.title||n.sessionId}`:"-"}function W(n,s){return s==="cpu"?Number(n.current?.cpu1mPct??n.current?.cpuPct??0):s==="rss"?Number(n.current?.rssBytes??0):s==="growth"?Number(n.current?.rssGrowth5mBytes??0):s==="bot"?n.botName??"":n.status??""}function ee(n,s){return[...n].sort((r,t)=>{let o=W(r,s),u=W(t,s);return typeof o=="number"&&typeof u=="number"?u-o||r.sessionId.localeCompare(t.sessionId):String(o).localeCompare(String(u))||r.sessionId.localeCompare(t.sessionId)})}function V(n,s){return s==="bytes"?b(n):N(n)}function F(n,s,r){let t=(n??[]).filter(Number.isFinite);if(t.length<2)return r("monitoring.chartNoData");let o=t[0],u=Number.isFinite(s)?Number(s):Date.now(),a=Math.max(0,u-o),m=Math.max(1,Math.round(a/6e4));if(m<60)return r("monitoring.chartMinutesAgo",{value:m});let p=Math.round(m/60);return p<48?r("monitoring.chartHoursAgo",{value:p}):r("monitoring.chartDaysAgo",{value:Math.round(p/24)})}function C(n){let s=(n??[]).filter(Number.isFinite);return s.length?s[s.length-1]:void 0}function R({values:n,timestamps:s,unit:r="pct",startLabel:t,endLabel:o,emptyLabel:u,className:a}){let m=(n??[]).filter(Number.isFinite),p=m.length?Math.min(...m):0,x=m.length?Math.max(...m):0,w=x-p,c=m.length>1?m.map((L,i)=>{let l=i/(m.length-1)*100,h=w>0?100-(L-p)/w*100:50;return`${l},${h}`}).join(" "):"",P=c?`0,100 ${c} 100,100`:"",B=c?c.split(" "):[],v=B.length?B[B.length-1].split(",").map(Number):null;return(0,e.jsxs)("div",{className:["resource-chart",a].filter(Boolean).join(" "),children:[(0,e.jsxs)("div",{className:"resource-chart-y","aria-hidden":"true",children:[(0,e.jsx)("span",{children:m.length?V(x,r):"-"}),(0,e.jsx)("span",{children:m.length?V(p,r):"-"})]}),(0,e.jsxs)("div",{className:"resource-chart-plot",children:[(0,e.jsxs)("div",{className:"resource-spark-wrap",children:[(0,e.jsxs)("svg",{className:"resource-spark",viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-label":m.length>1?void 0:u,children:[(0,e.jsx)("line",{x1:"0",y1:"12",x2:"100",y2:"12",className:"resource-grid-line"}),(0,e.jsx)("line",{x1:"0",y1:"50",x2:"100",y2:"50",className:"resource-grid-line"}),(0,e.jsx)("line",{x1:"0",y1:"88",x2:"100",y2:"88",className:"resource-grid-line"}),P?(0,e.jsx)("polygon",{className:"resource-spark-area",points:P}):null,c?(0,e.jsx)("polyline",{points:c}):null]}),v&&Number.isFinite(v[0])&&Number.isFinite(v[1])?(0,e.jsx)("span",{className:"resource-spark-dot","aria-hidden":"true",style:{left:`${v[0]}%`,top:`${v[1]}%`}}):null]}),(0,e.jsxs)("div",{className:"resource-chart-x","aria-hidden":"true",children:[(0,e.jsx)("span",{children:m.length>1?t:u}),(0,e.jsx)("span",{children:m.length>1?o:""})]})]})]})}function I(n){let s=r=>r instanceof Element&&!!r.closest(".ui-info-tip");return(0,e.jsx)("section",{className:"metric-card","data-resource-expandable":"",role:"button",tabIndex:0,"aria-label":n.label,onClick:r=>{s(r.target)||n.onOpen()},onKeyDown:r=>{s(r.target)||r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),n.onOpen())},children:n.children})}function M(n){return(0,e.jsx)("article",{className:"resource-trend-cell","data-resource-expandable":"",role:"button",tabIndex:0,"aria-label":n.label,onClick:n.onOpen,onKeyDown:s=>{s.key!=="Enter"&&s.key!==" "||(s.preventDefault(),n.onOpen())},children:n.children})}function te(n){let s=k(),r=(0,g.useRef)(null);return(0,g.useEffect)(()=>{let t=r.current;if(t)if(n.detail){if(!t.open)try{t.showModal()}catch{}}else t.open&&t.close()},[n.detail]),(0,g.useEffect)(()=>()=>{let t=r.current;t?.open&&t.close()},[]),(0,e.jsx)("dialog",{ref:r,className:"resource-detail-modal",onCancel:t=>{t.preventDefault(),n.onClose()},onClose:n.onClose,onClick:t=>{t.target===t.currentTarget&&n.onClose()},children:n.detail?(0,e.jsxs)("article",{className:"resource-detail-modal-card",children:[(0,e.jsxs)("header",{className:"resource-detail-modal-head",children:[(0,e.jsx)("h3",{children:n.detail.title}),(0,e.jsx)("button",{type:"button",className:"resource-detail-modal-close","aria-label":s("monitoring.modalClose"),title:s("monitoring.modalClose"),onClick:n.onClose})]}),(0,e.jsxs)("div",{className:"resource-detail-modal-body",children:[(0,e.jsxs)("section",{className:"resource-detail-summary",children:[(0,e.jsx)("strong",{children:n.detail.value}),(0,e.jsx)("p",{children:n.detail.detail})]}),n.detail.chart?(0,e.jsx)(R,{className:"resource-detail-chart",values:n.detail.chart.values,timestamps:n.detail.chart.timestamps,unit:n.detail.chart.unit,startLabel:n.detail.chart.startLabel,endLabel:n.detail.chart.endLabel,emptyLabel:n.detail.chart.emptyLabel}):(0,e.jsx)("p",{className:"resource-detail-empty",children:n.detail.emptyText})]})]}):null})}function ne({reasons:n}){return(0,e.jsx)("span",{className:"resource-reasons",children:(n??[]).join(", ")||"-"})}function y({label:n,value:s,tone:r}){return(0,e.jsxs)("span",{className:`resource-pill${r?` ${r}`:""}`,children:[(0,e.jsx)("span",{children:n}),(0,e.jsx)("b",{children:s})]})}function se({bots:n,cpuReady:s=!0}){let r=k();return(0,e.jsx)("div",{className:"resource-list-shell",children:(0,e.jsx)(H,{className:"resource-runtime-list",children:n.length?n.map(t=>{let o=t.runtime?.sessions,u=t.runtime?.daemonStatus??t.daemonStatus??"unknown",a=u==="online"?"ok":u==="offline"?"off":"warn";return(0,e.jsxs)(T,{className:"resource-list-item resource-bot-item",children:[(0,e.jsxs)(D,{children:[(0,e.jsx)("strong",{title:t.botName,children:t.botName}),(0,e.jsxs)("span",{children:[r("monitoring.sessionsCount")," ",d(o?.total??t.sessions?.count)]})]}),(0,e.jsx)(A,{children:(0,e.jsxs)("div",{className:"resource-pill-group",children:[(0,e.jsx)(y,{label:r("monitoring.daemon"),value:u,tone:a}),(0,e.jsx)(y,{label:r("monitoring.working"),value:d(o?.working),tone:"accent"}),(0,e.jsx)(y,{label:r("monitoring.starting"),value:d(o?.starting)}),(0,e.jsx)(y,{label:r("monitoring.cpu"),value:S(t.total?.cpuPct,s)}),(0,e.jsx)(y,{label:r("monitoring.rss"),value:b(t.total?.rssBytes)})]})})]},t.larkAppId)}):(0,e.jsx)("li",{className:"empty",children:r("overview.noSessions")})})})}function re({sessions:n,cpuReady:s=!0}){let r=k();return(0,e.jsx)("div",{className:"resource-list-shell resource-session-shell",children:(0,e.jsx)(H,{className:"resource-runtime-list resource-session-list",children:n.length?n.map(t=>(0,e.jsxs)(T,{className:`resource-list-item resource-session-item${t.tracked?" is-tracked":""}`,children:[(0,e.jsxs)(D,{children:[(0,e.jsx)("strong",{title:t.title||t.sessionId,children:t.title||t.sessionId}),(0,e.jsxs)("span",{title:t.sessionId,children:[t.botName," \xB7 ",t.sessionId]})]}),(0,e.jsx)(A,{children:(0,e.jsxs)("div",{className:"resource-pill-group",children:[(0,e.jsx)(y,{label:r("monitoring.cpu"),value:S(t.current?.cpu1mPct??t.current?.cpuPct,s),tone:"accent"}),(0,e.jsx)(y,{label:r("monitoring.rss"),value:b(t.current?.rssBytes)}),(0,e.jsx)(y,{label:r("monitoring.growth"),value:b(t.current?.rssGrowth5mBytes)}),(0,e.jsx)(y,{label:r("monitoring.confidence"),value:t.confidence??"unknown",tone:t.tracked?"ok":void 0}),(0,e.jsxs)("span",{className:"resource-pill resource-rank-pill",children:[(0,e.jsx)("span",{children:r("monitoring.rank")}),(0,e.jsx)(ne,{reasons:t.rankReasons})]})]})})]},t.sessionId)):(0,e.jsx)("li",{className:"empty",children:r("overview.noSessions")})})})}function oe({current:n}){let s=k(),r=n.runtime,t=q(n),o=Z(r?.sampleHealth?.status),u=r?.daemons?.total,a=r?.daemons?.online,m=r?.daemons?.offline??(Number.isFinite(Number(u))&&Number.isFinite(Number(a))?Math.max(0,Number(u)-Number(a)):void 0),p=r?.sessions?.total,x=r?.sessions?.working,w=r?.sessions?.starting;return(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:s("monitoring.runtimeHealth")}),(0,e.jsx)("section",{className:"panel runtime-health-panel",children:(0,e.jsxs)("div",{className:"runtime-health-grid",children:[(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.sampleHealth")}),(0,e.jsx)("strong",{children:(0,e.jsx)("span",{className:`runtime-status-pill ${o}`,children:s(`monitoring.sample.${o}`)})}),(0,e.jsxs)("small",{children:[s("monitoring.sampleAge")," ",E(r?.sampleHealth?.ageMs)]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.daemonHealth")}),(0,e.jsxs)("strong",{children:[d(a),"/",d(u)]}),(0,e.jsxs)("small",{children:[d(m)," ",s("monitoring.offline")]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.sessionHealth")}),(0,e.jsx)("strong",{children:d(p)}),(0,e.jsxs)("small",{children:[s("monitoring.working")," ",d(x)," \xB7 ",s("monitoring.starting")," ",d(w)]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.resourcePressure")}),(0,e.jsx)("strong",{children:S(n.host?.cpuPct,t)}),(0,e.jsxs)("small",{children:[s("monitoring.hostMemory")," ",N(n.host?.memUsedPct)," \xB7 RSS ",b(n.botmux?.rssBytes)]})]})]})})]})}function ae({runtime:n}){let s=k(),r=n?.sessions,t=r?.longestRunning,o=r?.longestWaiting;return(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:s("monitoring.sessionPressure")}),(0,e.jsx)("section",{className:"panel runtime-session-pressure",children:(0,e.jsxs)("div",{className:"runtime-session-grid",children:[(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.statusDistribution")}),(0,e.jsx)("strong",{children:d(r?.total)}),(0,e.jsxs)("small",{children:[s("monitoring.working")," ",d(r?.working)," \xB7 ",s("monitoring.starting")," ",d(r?.starting)," \xB7 ",s("monitoring.waiting")," ",d(r?.waiting)," \xB7 ",s("monitoring.idle")," ",d(r?.idle)," \xB7 ",s("monitoring.unknown")," ",d(r?.unknown)]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.longestRunning")}),(0,e.jsx)("strong",{children:j(t)}),(0,e.jsx)("small",{children:E(t?.durationMs)})]}),(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.longestWaiting")}),(0,e.jsx)("strong",{children:j(o)}),(0,e.jsx)("small",{children:E(o?.durationMs)})]}),(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.unattributedSessions")}),(0,e.jsx)("strong",{children:d(r?.unattributed)}),(0,e.jsx)("small",{children:s("monitoring.unattributedHint")})]})]})})]})}function ie({initialCurrent:n=null,initialHistory:s=null,poll:r=!0}={}){let t=k(),[o,u]=(0,g.useState)(n),[a,m]=(0,g.useState)(s),[p,x]=(0,g.useState)("cpu"),[w,c]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!r)return;let l=!1;async function h(){try{let[z,J]=await Promise.all([fetch("/api/resources/current",{cache:"no-store"}),fetch("/api/resources/history?range=3h",{cache:"no-store"})]),[Q,X]=await Promise.all([z.json(),J.json()]);l||(u(Q),m(X))}catch{l||(u({supported:!1,reason:"fetch_failed",bots:[],sessions:[]}),m({supported:!1,bots:[],sessions:[]}))}}h();let O=window.setInterval(()=>{h()},1e4);return()=>{l=!0,window.clearInterval(O)}},[r]);let P=o!==null&&a!==null,B=(0,g.useMemo)(()=>ee(o?.sessions??[],p),[o?.sessions,p]),v=o?.supported!==!1,L=q(o),i={hostStartLabel:F(a?.host?.timestamps,o?.sampledAt,t),botmuxStartLabel:F(a?.botmux?.timestamps,o?.sampledAt,t),endLabel:t("monitoring.chartNow"),emptyLabel:t("monitoring.chartNoData")};return(0,e.jsxs)("section",{className:"page resource-page",children:[(0,e.jsx)("div",{className:"page-heading",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:t("monitoring.eyebrow")}),(0,e.jsx)("h1",{children:t("monitoring.runtimeTitle")})]})}),P?null:(0,e.jsx)(G,{label:t("common.loading")}),P?(0,e.jsxs)(e.Fragment,{children:[o?(0,e.jsx)(oe,{current:o}):null,v?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("section",{className:"overview-block resource-block resource-pressure-block",children:[(0,e.jsx)(f,{title:t("monitoring.resourcePressure")}),(0,e.jsx)("section",{className:"panel resource-pressure",children:(0,e.jsxs)("div",{className:"resource-metrics runtime-pressure-grid",children:[(0,e.jsxs)(I,{label:t("monitoring.hostCpu"),onOpen:()=>c({title:t("monitoring.hostCpu"),value:S(o?.host?.cpuPct,L),detail:`load ${Number(o?.host?.load1??0).toFixed(2)}`,chart:{values:a?.host?.cpuPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("span",{children:t("monitoring.hostCpu")}),(0,e.jsx)("strong",{children:S(o?.host?.cpuPct,L)}),(0,e.jsxs)("small",{children:["load ",Number(o?.host?.load1??0).toFixed(2)]})]}),(0,e.jsxs)(I,{label:t("monitoring.hostMemory"),onOpen:()=>c({title:t("monitoring.hostMemory"),value:N(o?.host?.memUsedPct),detail:t("monitoring.memoryOnly"),chart:{values:a?.host?.memUsedPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("span",{children:t("monitoring.hostMemory")}),(0,e.jsx)("strong",{children:N(o?.host?.memUsedPct)}),(0,e.jsx)("small",{children:t("monitoring.memoryOnly")})]}),(0,e.jsxs)(I,{label:t("monitoring.botmuxRss"),onOpen:()=>c({title:t("monitoring.botmuxRss"),value:b(o?.botmux?.rssBytes),detail:o?.botmuxBreakdown?`${t("monitoring.botmuxSelf")} ${b((o.botmuxBreakdown.daemon.rssBytes??0)+(o.botmuxBreakdown.worker.rssBytes??0))}
1
+ import{c as G,d as f,j as _,m as H,n as T,o as D,p as A}from"./chunk-QALRQEKD.js";import{d as k}from"./chunk-3OJQKYM3.js";import"./chunk-QITAMHW6.js";import"./chunk-IRFGJSPL.js";import{c as U}from"./chunk-ARROO6TE.js";import{c as $,d as Y,e as K}from"./chunk-3YZFAHNK.js";var g=$(Y(),1);var e=$(K(),1);function b(n){let s=Number(n);return!Number.isFinite(s)||s<=0?"-":s>=1024**3?`${(s/1024**3).toFixed(1)} GiB`:s>=1024**2?`${(s/1024**2).toFixed(0)} MiB`:`${Math.max(1,Math.round(s/1024))} KiB`}function N(n){let s=Number(n);return Number.isFinite(s)?`${s.toFixed(1)}%`:"-"}function S(n,s){return s?N(n):"-"}function q(n){return n?.cpuReady!==!1}function d(n){let s=Number(n);return Number.isFinite(s)?String(s):"-"}function E(n){let s=Number(n);if(!Number.isFinite(s)||s<0)return"-";if(s===0)return"0s";if(s<6e4)return`${Math.max(1,Math.floor(s/1e3))}s`;let r=Math.floor(s/6e4);if(r<60)return`${Math.max(1,r)}m`;let t=Math.floor(r/60),o=r%60;return o?`${t}h ${o}m`:`${t}h`}function Z(n){return n==="fresh"||n==="stale"||n==="unsupported"?n:"unknown"}function j(n){return n?`${n.botName||"-"} \xB7 ${n.title||n.sessionId}`:"-"}function W(n,s){return s==="cpu"?Number(n.current?.cpu1mPct??n.current?.cpuPct??0):s==="rss"?Number(n.current?.rssBytes??0):s==="growth"?Number(n.current?.rssGrowth5mBytes??0):s==="bot"?n.botName??"":n.status??""}function ee(n,s){return[...n].sort((r,t)=>{let o=W(r,s),u=W(t,s);return typeof o=="number"&&typeof u=="number"?u-o||r.sessionId.localeCompare(t.sessionId):String(o).localeCompare(String(u))||r.sessionId.localeCompare(t.sessionId)})}function V(n,s){return s==="bytes"?b(n):N(n)}function F(n,s,r){let t=(n??[]).filter(Number.isFinite);if(t.length<2)return r("monitoring.chartNoData");let o=t[0],u=Number.isFinite(s)?Number(s):Date.now(),a=Math.max(0,u-o),m=Math.max(1,Math.round(a/6e4));if(m<60)return r("monitoring.chartMinutesAgo",{value:m});let p=Math.round(m/60);return p<48?r("monitoring.chartHoursAgo",{value:p}):r("monitoring.chartDaysAgo",{value:Math.round(p/24)})}function C(n){let s=(n??[]).filter(Number.isFinite);return s.length?s[s.length-1]:void 0}function R({values:n,timestamps:s,unit:r="pct",startLabel:t,endLabel:o,emptyLabel:u,className:a}){let m=(n??[]).filter(Number.isFinite),p=m.length?Math.min(...m):0,x=m.length?Math.max(...m):0,w=x-p,c=m.length>1?m.map((L,i)=>{let l=i/(m.length-1)*100,h=w>0?100-(L-p)/w*100:50;return`${l},${h}`}).join(" "):"",P=c?`0,100 ${c} 100,100`:"",B=c?c.split(" "):[],v=B.length?B[B.length-1].split(",").map(Number):null;return(0,e.jsxs)("div",{className:["resource-chart",a].filter(Boolean).join(" "),children:[(0,e.jsxs)("div",{className:"resource-chart-y","aria-hidden":"true",children:[(0,e.jsx)("span",{children:m.length?V(x,r):"-"}),(0,e.jsx)("span",{children:m.length?V(p,r):"-"})]}),(0,e.jsxs)("div",{className:"resource-chart-plot",children:[(0,e.jsxs)("div",{className:"resource-spark-wrap",children:[(0,e.jsxs)("svg",{className:"resource-spark",viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-label":m.length>1?void 0:u,children:[(0,e.jsx)("line",{x1:"0",y1:"12",x2:"100",y2:"12",className:"resource-grid-line"}),(0,e.jsx)("line",{x1:"0",y1:"50",x2:"100",y2:"50",className:"resource-grid-line"}),(0,e.jsx)("line",{x1:"0",y1:"88",x2:"100",y2:"88",className:"resource-grid-line"}),P?(0,e.jsx)("polygon",{className:"resource-spark-area",points:P}):null,c?(0,e.jsx)("polyline",{points:c}):null]}),v&&Number.isFinite(v[0])&&Number.isFinite(v[1])?(0,e.jsx)("span",{className:"resource-spark-dot","aria-hidden":"true",style:{left:`${v[0]}%`,top:`${v[1]}%`}}):null]}),(0,e.jsxs)("div",{className:"resource-chart-x","aria-hidden":"true",children:[(0,e.jsx)("span",{children:m.length>1?t:u}),(0,e.jsx)("span",{children:m.length>1?o:""})]})]})]})}function I(n){let s=r=>r instanceof Element&&!!r.closest(".ui-info-tip");return(0,e.jsx)("section",{className:"metric-card","data-resource-expandable":"",role:"button",tabIndex:0,"aria-label":n.label,onClick:r=>{s(r.target)||n.onOpen()},onKeyDown:r=>{s(r.target)||r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),n.onOpen())},children:n.children})}function M(n){return(0,e.jsx)("article",{className:"resource-trend-cell","data-resource-expandable":"",role:"button",tabIndex:0,"aria-label":n.label,onClick:n.onOpen,onKeyDown:s=>{s.key!=="Enter"&&s.key!==" "||(s.preventDefault(),n.onOpen())},children:n.children})}function te(n){let s=k(),r=(0,g.useRef)(null);return(0,g.useEffect)(()=>{let t=r.current;if(t)if(n.detail){if(!t.open)try{t.showModal()}catch{}}else t.open&&t.close()},[n.detail]),(0,g.useEffect)(()=>()=>{let t=r.current;t?.open&&t.close()},[]),(0,e.jsx)("dialog",{ref:r,className:"resource-detail-modal",onCancel:t=>{t.preventDefault(),n.onClose()},onClose:n.onClose,onClick:t=>{t.target===t.currentTarget&&n.onClose()},children:n.detail?(0,e.jsxs)("article",{className:"resource-detail-modal-card",children:[(0,e.jsxs)("header",{className:"resource-detail-modal-head",children:[(0,e.jsx)("h3",{children:n.detail.title}),(0,e.jsx)("button",{type:"button",className:"resource-detail-modal-close","aria-label":s("monitoring.modalClose"),title:s("monitoring.modalClose"),onClick:n.onClose})]}),(0,e.jsxs)("div",{className:"resource-detail-modal-body",children:[(0,e.jsxs)("section",{className:"resource-detail-summary",children:[(0,e.jsx)("strong",{children:n.detail.value}),(0,e.jsx)("p",{children:n.detail.detail})]}),n.detail.chart?(0,e.jsx)(R,{className:"resource-detail-chart",values:n.detail.chart.values,timestamps:n.detail.chart.timestamps,unit:n.detail.chart.unit,startLabel:n.detail.chart.startLabel,endLabel:n.detail.chart.endLabel,emptyLabel:n.detail.chart.emptyLabel}):(0,e.jsx)("p",{className:"resource-detail-empty",children:n.detail.emptyText})]})]}):null})}function ne({reasons:n}){return(0,e.jsx)("span",{className:"resource-reasons",children:(n??[]).join(", ")||"-"})}function y({label:n,value:s,tone:r}){return(0,e.jsxs)("span",{className:`resource-pill${r?` ${r}`:""}`,children:[(0,e.jsx)("span",{children:n}),(0,e.jsx)("b",{children:s})]})}function se({bots:n,cpuReady:s=!0}){let r=k();return(0,e.jsx)("div",{className:"resource-list-shell",children:(0,e.jsx)(H,{className:"resource-runtime-list",children:n.length?n.map(t=>{let o=t.runtime?.sessions,u=t.runtime?.daemonStatus??t.daemonStatus??"unknown",a=u==="online"?"ok":u==="offline"?"off":"warn";return(0,e.jsxs)(T,{className:"resource-list-item resource-bot-item",children:[(0,e.jsxs)(D,{children:[(0,e.jsx)("strong",{title:t.botName,children:t.botName}),(0,e.jsxs)("span",{children:[r("monitoring.sessionsCount")," ",d(o?.total??t.sessions?.count)]})]}),(0,e.jsx)(A,{children:(0,e.jsxs)("div",{className:"resource-pill-group",children:[(0,e.jsx)(y,{label:r("monitoring.daemon"),value:u,tone:a}),(0,e.jsx)(y,{label:r("monitoring.working"),value:d(o?.working),tone:"accent"}),(0,e.jsx)(y,{label:r("monitoring.starting"),value:d(o?.starting)}),(0,e.jsx)(y,{label:r("monitoring.cpu"),value:S(t.total?.cpuPct,s)}),(0,e.jsx)(y,{label:r("monitoring.rss"),value:b(t.total?.rssBytes)})]})})]},t.larkAppId)}):(0,e.jsx)("li",{className:"empty",children:r("overview.noSessions")})})})}function re({sessions:n,cpuReady:s=!0}){let r=k();return(0,e.jsx)("div",{className:"resource-list-shell resource-session-shell",children:(0,e.jsx)(H,{className:"resource-runtime-list resource-session-list",children:n.length?n.map(t=>(0,e.jsxs)(T,{className:`resource-list-item resource-session-item${t.tracked?" is-tracked":""}`,children:[(0,e.jsxs)(D,{children:[(0,e.jsx)("strong",{title:t.title||t.sessionId,children:t.title||t.sessionId}),(0,e.jsxs)("span",{title:t.sessionId,children:[t.botName," \xB7 ",t.sessionId]})]}),(0,e.jsx)(A,{children:(0,e.jsxs)("div",{className:"resource-pill-group",children:[(0,e.jsx)(y,{label:r("monitoring.cpu"),value:S(t.current?.cpu1mPct??t.current?.cpuPct,s),tone:"accent"}),(0,e.jsx)(y,{label:r("monitoring.rss"),value:b(t.current?.rssBytes)}),(0,e.jsx)(y,{label:r("monitoring.growth"),value:b(t.current?.rssGrowth5mBytes)}),(0,e.jsx)(y,{label:r("monitoring.confidence"),value:t.confidence??"unknown",tone:t.tracked?"ok":void 0}),(0,e.jsxs)("span",{className:"resource-pill resource-rank-pill",children:[(0,e.jsx)("span",{children:r("monitoring.rank")}),(0,e.jsx)(ne,{reasons:t.rankReasons})]})]})})]},t.sessionId)):(0,e.jsx)("li",{className:"empty",children:r("overview.noSessions")})})})}function oe({current:n}){let s=k(),r=n.runtime,t=q(n),o=Z(r?.sampleHealth?.status),u=r?.daemons?.total,a=r?.daemons?.online,m=r?.daemons?.offline??(Number.isFinite(Number(u))&&Number.isFinite(Number(a))?Math.max(0,Number(u)-Number(a)):void 0),p=r?.sessions?.total,x=r?.sessions?.working,w=r?.sessions?.starting;return(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:s("monitoring.runtimeHealth")}),(0,e.jsx)("section",{className:"panel runtime-health-panel",children:(0,e.jsxs)("div",{className:"runtime-health-grid",children:[(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.sampleHealth")}),(0,e.jsx)("strong",{children:(0,e.jsx)("span",{className:`runtime-status-pill ${o}`,children:s(`monitoring.sample.${o}`)})}),(0,e.jsxs)("small",{children:[s("monitoring.sampleAge")," ",E(r?.sampleHealth?.ageMs)]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.daemonHealth")}),(0,e.jsxs)("strong",{children:[d(a),"/",d(u)]}),(0,e.jsxs)("small",{children:[d(m)," ",s("monitoring.offline")]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.sessionHealth")}),(0,e.jsx)("strong",{children:d(p)}),(0,e.jsxs)("small",{children:[s("monitoring.working")," ",d(x)," \xB7 ",s("monitoring.starting")," ",d(w)]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-health-card",children:[(0,e.jsx)("span",{children:s("monitoring.resourcePressure")}),(0,e.jsx)("strong",{children:S(n.host?.cpuPct,t)}),(0,e.jsxs)("small",{children:[s("monitoring.hostMemory")," ",N(n.host?.memUsedPct)," \xB7 RSS ",b(n.botmux?.rssBytes)]})]})]})})]})}function ae({runtime:n}){let s=k(),r=n?.sessions,t=r?.longestRunning,o=r?.longestWaiting;return(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:s("monitoring.sessionPressure")}),(0,e.jsx)("section",{className:"panel runtime-session-pressure",children:(0,e.jsxs)("div",{className:"runtime-session-grid",children:[(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.statusDistribution")}),(0,e.jsx)("strong",{children:d(r?.total)}),(0,e.jsxs)("small",{children:[s("monitoring.working")," ",d(r?.working)," \xB7 ",s("monitoring.starting")," ",d(r?.starting)," \xB7 ",s("monitoring.waiting")," ",d(r?.waiting)," \xB7 ",s("monitoring.idle")," ",d(r?.idle)," \xB7 ",s("monitoring.unknown")," ",d(r?.unknown)]})]}),(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.longestRunning")}),(0,e.jsx)("strong",{children:j(t)}),(0,e.jsx)("small",{children:E(t?.durationMs)})]}),(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.longestWaiting")}),(0,e.jsx)("strong",{children:j(o)}),(0,e.jsx)("small",{children:E(o?.durationMs)})]}),(0,e.jsxs)("section",{className:"metric-card runtime-session-card",children:[(0,e.jsx)("span",{children:s("monitoring.unattributedSessions")}),(0,e.jsx)("strong",{children:d(r?.unattributed)}),(0,e.jsx)("small",{children:s("monitoring.unattributedHint")})]})]})})]})}function ie({initialCurrent:n=null,initialHistory:s=null,poll:r=!0}={}){let t=k(),[o,u]=(0,g.useState)(n),[a,m]=(0,g.useState)(s),[p,x]=(0,g.useState)("cpu"),[w,c]=(0,g.useState)(null);(0,g.useEffect)(()=>{if(!r)return;let l=!1;async function h(){try{let[z,J]=await Promise.all([fetch("/api/resources/current",{cache:"no-store"}),fetch("/api/resources/history?range=3h",{cache:"no-store"})]),[Q,X]=await Promise.all([z.json(),J.json()]);l||(u(Q),m(X))}catch{l||(u({supported:!1,reason:"fetch_failed",bots:[],sessions:[]}),m({supported:!1,bots:[],sessions:[]}))}}h();let O=window.setInterval(()=>{h()},1e4);return()=>{l=!0,window.clearInterval(O)}},[r]);let P=o!==null&&a!==null,B=(0,g.useMemo)(()=>ee(o?.sessions??[],p),[o?.sessions,p]),v=o?.supported!==!1,L=q(o),i={hostStartLabel:F(a?.host?.timestamps,o?.sampledAt,t),botmuxStartLabel:F(a?.botmux?.timestamps,o?.sampledAt,t),endLabel:t("monitoring.chartNow"),emptyLabel:t("monitoring.chartNoData")};return(0,e.jsxs)("section",{className:"page resource-page",children:[(0,e.jsx)("div",{className:"page-heading",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:t("monitoring.eyebrow")}),(0,e.jsx)("h1",{children:t("monitoring.runtimeTitle")})]})}),P?null:(0,e.jsx)(G,{label:t("common.loading")}),P?(0,e.jsxs)(e.Fragment,{children:[o?(0,e.jsx)(oe,{current:o}):null,v?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("section",{className:"overview-block resource-block resource-pressure-block",children:[(0,e.jsx)(f,{title:t("monitoring.resourcePressure")}),(0,e.jsx)("section",{className:"panel resource-pressure",children:(0,e.jsxs)("div",{className:"resource-metrics runtime-pressure-grid",children:[(0,e.jsxs)(I,{label:t("monitoring.hostCpu"),onOpen:()=>c({title:t("monitoring.hostCpu"),value:S(o?.host?.cpuPct,L),detail:`load ${Number(o?.host?.load1??0).toFixed(2)}`,chart:{values:a?.host?.cpuPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("span",{children:t("monitoring.hostCpu")}),(0,e.jsx)("strong",{children:S(o?.host?.cpuPct,L)}),(0,e.jsxs)("small",{children:["load ",Number(o?.host?.load1??0).toFixed(2)]})]}),(0,e.jsxs)(I,{label:t("monitoring.hostMemory"),onOpen:()=>c({title:t("monitoring.hostMemory"),value:N(o?.host?.memUsedPct),detail:t("monitoring.memoryOnly"),chart:{values:a?.host?.memUsedPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("span",{children:t("monitoring.hostMemory")}),(0,e.jsx)("strong",{children:N(o?.host?.memUsedPct)}),(0,e.jsx)("small",{children:t("monitoring.memoryOnly")})]}),(0,e.jsxs)(I,{label:t("monitoring.botmuxRss"),onOpen:()=>c({title:t("monitoring.botmuxRss"),value:b(o?.botmux?.rssBytes),detail:o?.botmuxBreakdown?`${t("monitoring.botmuxSelf")} ${b((o.botmuxBreakdown.daemon.rssBytes??0)+(o.botmuxBreakdown.worker.rssBytes??0))}
2
2
  ${t("monitoring.botmuxCli")} ${b(o.botmuxBreakdown.cli.rssBytes)}`:S(o?.botmux?.cpuPct,L),chart:{values:a?.botmux?.rssBytes,timestamps:a?.botmux?.timestamps,unit:"bytes",startLabel:i.botmuxStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsxs)("div",{className:"metric-label-with-help",children:[(0,e.jsx)("span",{children:t("monitoring.botmuxRss")}),(0,e.jsx)(_,{label:t("monitoring.rssHelpLabel"),children:t("monitoring.rssHelp")})]}),(0,e.jsx)("strong",{children:b(o?.botmux?.rssBytes)}),o?.botmuxBreakdown&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("small",{className:"metric-breakdown",children:[t("monitoring.botmuxSelf")," ",b((o.botmuxBreakdown.daemon.rssBytes??0)+(o.botmuxBreakdown.worker.rssBytes??0)),(0,e.jsxs)("span",{className:"metric-breakdown-detail",children:[" (",t("monitoring.botmuxDaemon")," ",b(o.botmuxBreakdown.daemon.rssBytes)," \xB7 ",t("monitoring.botmuxWorker")," ",b(o.botmuxBreakdown.worker.rssBytes),")"]})]}),(0,e.jsxs)("small",{className:"metric-breakdown",children:[t("monitoring.botmuxCli")," ",b(o.botmuxBreakdown.cli.rssBytes)]})]})]}),(0,e.jsxs)(I,{label:t("monitoring.trackedSessions"),onOpen:()=>c({title:t("monitoring.trackedSessions"),value:d(o?.rankings?.tracked?.length),detail:`${t("monitoring.currentSessions")} ${(o?.sessions??[]).length}`,emptyText:t("monitoring.trackedSessionHint")}),children:[(0,e.jsx)("span",{children:t("monitoring.trackedSessions")}),(0,e.jsx)("strong",{children:o?.rankings?.tracked?.length??0}),(0,e.jsxs)("small",{children:[t("monitoring.currentSessions")," ",(o?.sessions??[]).length]})]})]})})]}),(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:t("monitoring.trends")}),(0,e.jsx)("section",{className:"panel resource-trends",children:(0,e.jsxs)("div",{className:"resource-trend-grid",children:[(0,e.jsxs)(M,{label:t("monitoring.trendHostCpu"),onOpen:()=>c({title:t("monitoring.trendHostCpu"),value:N(C(a?.host?.cpuPct)),detail:`load ${Number(o?.host?.load1??0).toFixed(2)}`,chart:{values:a?.host?.cpuPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("b",{children:t("monitoring.trendHostCpu")}),(0,e.jsx)(R,{values:a?.host?.cpuPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel})]}),(0,e.jsxs)(M,{label:t("monitoring.trendHostMemory"),onOpen:()=>c({title:t("monitoring.trendHostMemory"),value:N(C(a?.host?.memUsedPct)),detail:t("monitoring.memoryOnly"),chart:{values:a?.host?.memUsedPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("b",{children:t("monitoring.trendHostMemory")}),(0,e.jsx)(R,{values:a?.host?.memUsedPct,timestamps:a?.host?.timestamps,unit:"pct",startLabel:i.hostStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel})]}),(0,e.jsxs)(M,{label:t("monitoring.trendBotmuxCpu"),onOpen:()=>c({title:t("monitoring.trendBotmuxCpu"),value:N(C(a?.botmux?.cpuPct)),detail:t("monitoring.botRuntime"),chart:{values:a?.botmux?.cpuPct,timestamps:a?.botmux?.timestamps,unit:"pct",startLabel:i.botmuxStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("b",{children:t("monitoring.trendBotmuxCpu")}),(0,e.jsx)(R,{values:a?.botmux?.cpuPct,timestamps:a?.botmux?.timestamps,unit:"pct",startLabel:i.botmuxStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel})]}),(0,e.jsxs)(M,{label:t("monitoring.botmuxRss"),onOpen:()=>c({title:t("monitoring.botmuxRss"),value:b(C(a?.botmux?.rssBytes)),detail:t("monitoring.memoryOnly"),chart:{values:a?.botmux?.rssBytes,timestamps:a?.botmux?.timestamps,unit:"bytes",startLabel:i.botmuxStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("b",{children:t("monitoring.botmuxRss")}),(0,e.jsx)(R,{values:a?.botmux?.rssBytes,timestamps:a?.botmux?.timestamps,unit:"bytes",startLabel:i.botmuxStartLabel,endLabel:i.endLabel,emptyLabel:i.emptyLabel})]})]})})]})]}):(0,e.jsx)("section",{className:"panel resource-unavailable",children:(0,e.jsxs)("div",{className:"resource-unavailable-card",children:[(0,e.jsx)("span",{className:"resource-unavailable-status","aria-hidden":"true"}),(0,e.jsxs)("div",{className:"resource-unavailable-copy",children:[(0,e.jsx)("span",{children:t("monitoring.unsupportedKicker")}),(0,e.jsx)("h2",{children:t("monitoring.unsupportedTitle")}),(0,e.jsx)("p",{children:t("monitoring.unsupportedHint")})]}),(0,e.jsxs)("div",{className:"resource-unavailable-tags","aria-label":t("monitoring.unsupported"),children:[(0,e.jsx)("span",{children:t("monitoring.unsupportedRuntimeOk")}),(0,e.jsx)("span",{children:t("monitoring.unsupportedResourceOnly")})]})]})}),o?(0,e.jsx)(ae,{runtime:o.runtime}):null,v?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:t("monitoring.botRuntime")}),(0,e.jsx)("section",{className:"panel",children:(0,e.jsx)(se,{bots:o?.bots??[],cpuReady:L})})]}),(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:t("monitoring.sessions"),children:(0,e.jsx)("div",{className:"resource-sortbar resource-sortbar-inline dashboard-toolbar",role:"group","aria-label":t("monitoring.sort"),children:(0,e.jsx)("div",{className:"segmented resource-sort-switch",children:["cpu","rss","growth","bot","status"].map(l=>(0,e.jsx)("button",{type:"button",className:p===l?"active":void 0,"aria-pressed":p===l,onClick:()=>x(l),children:t(`monitoring.sort.${l}`)},l))})})}),(0,e.jsx)("section",{className:"panel",children:(0,e.jsx)(re,{sessions:B,cpuReady:L})})]}),(0,e.jsxs)("section",{className:"overview-block resource-block",children:[(0,e.jsx)(f,{title:t("monitoring.trackedSessionTrends")}),(0,e.jsx)("section",{className:"panel",children:(0,e.jsxs)("div",{className:"resource-trend-grid",children:[(a?.sessions??[]).map(l=>{let h=`${l.botName} \xB7 ${l.title||l.sessionId}`,O=F(l.series?.timestamps,o?.sampledAt,t);return(0,e.jsxs)(M,{label:h,onOpen:()=>c({title:h,value:b(C(l.series?.rssBytes)),detail:l.sessionId,chart:{values:l.series?.rssBytes,timestamps:l.series?.timestamps,unit:"bytes",startLabel:O,endLabel:i.endLabel,emptyLabel:i.emptyLabel}}),children:[(0,e.jsx)("b",{title:h,children:h}),(0,e.jsx)(R,{values:l.series?.rssBytes,timestamps:l.series?.timestamps,unit:"bytes",startLabel:O,endLabel:i.endLabel,emptyLabel:i.emptyLabel})]},l.sessionId)}),(a?.sessions??[]).length?null:(0,e.jsx)("div",{className:"empty",children:t("monitoring.noTrackedHistory")})]})})]})]}):null]}):null,(0,e.jsx)(te,{detail:w,onClose:()=>c(null)})]})}function ce(n){return U(n,(0,e.jsx)(ie,{}))}export{ie as MonitoringPage,re as SessionResourceTable,ce as renderMonitoringPage};
@@ -1 +1 @@
1
- import{d as x}from"./chunk-R3LJUCEO.js";import"./chunk-QITAMHW6.js";import"./chunk-K232GT3M.js";import{c as p}from"./chunk-ARROO6TE.js";import{c as g,d as S,e as w}from"./chunk-3YZFAHNK.js";var n=g(S(),1);var e=g(w(),1),u=78222186;function y(t){return(t/1048576).toFixed(0)}function T(){let t=x(),[i,a]=(0,n.useState)(null),[c,l]=(0,n.useState)(""),[m,h]=(0,n.useState)(!1),d=(0,n.useRef)(null),r=(0,n.useRef)(!1),v=()=>{d.current&&(clearTimeout(d.current),d.current=null)};async function f(){if(!r.current)try{let s=await fetch("/api/game/status");if(r.current)return;if(!s.ok){a({state:"absent",received:0,total:u});return}let o=await s.json();if(r.current)return;a(o),typeof o.proxy=="string"&&l(o.proxy),o.state==="downloading"&&(d.current=setTimeout(()=>{f()},700))}catch{r.current||(d.current=setTimeout(()=>{f()},1500))}}(0,n.useEffect)(()=>(r.current=!1,f(),()=>{r.current=!0,v()}),[]);async function b(){v(),h(!0),a({state:"downloading",received:0,total:u});try{let s=await fetch("/api/game/download",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({proxy:c.trim()})});if(r.current)return;if(!s.ok)throw new Error(`HTTP ${s.status}`);let o=await s.json();if(r.current)return;a(o),typeof o.proxy=="string"&&l(o.proxy),o.state==="downloading"&&(d.current=setTimeout(()=>{f()},700))}catch(s){if(r.current)return;a({state:"error",received:0,total:u,error:s instanceof Error?s.message:String(s)})}finally{r.current||h(!1)}}return i?.state==="ready"?(0,e.jsx)("div",{className:"office-frame-shell",children:(0,e.jsx)("iframe",{className:"office-game-frame",src:"/game/index.html",title:"HD2D Office",allow:"autoplay"})}):(0,e.jsx)(P,{status:i??{state:"absent",received:0,total:u},title:t("nav.office"),proxy:c,starting:m,onProxyChange:l,onStart:()=>{b()}})}function P(t){let i=t.status.total||u,a=(0,n.useMemo)(()=>i?Math.min(100,Math.round(t.status.received/i*100)):0,[t.status.received,i]),c=t.status.state==="downloading",l=t.status.state==="error";return(0,e.jsxs)("div",{style:{margin:"auto",textAlign:"center",maxWidth:440,padding:32,color:"var(--fg,#e6e6e6)"},children:[(0,e.jsx)("h1",{style:{fontSize:18,fontWeight:600,lineHeight:1.2,margin:"0 0 8px"},children:t.title}),(0,e.jsxs)("div",{style:{fontSize:13,opacity:.7,lineHeight:1.7,marginBottom:20},children:["\u628A\u6BCF\u4E2A\u4F1A\u8BDD\u53D8\u6210\u529E\u516C\u5BA4\u91CC\u7684\u4E00\u4E2A\u673A\u5668\u4EBA\uFF0C\u5B9E\u65F6\u6620\u5C04\u5C4F\u5E55\u72B6\u6001\u3002",(0,e.jsx)("br",{}),"\u9996\u6B21\u8FDB\u5165\u9700\u4E0B\u8F7D\u7EA6 ",y(i)," MB \u6E38\u620F\u8D44\u6E90\uFF08\u4EC5\u4E00\u6B21\uFF0C\u4E4B\u540E\u672C\u5730\u7F13\u5B58\uFF09\u3002"]}),l?(0,e.jsxs)("div",{style:{color:"#e06c75",fontSize:12,marginBottom:14},children:["\u4E0A\u6B21\u4E0B\u8F7D\u5931\u8D25\uFF1A",t.status.error??"\u672A\u77E5\u9519\u8BEF",(0,e.jsx)("br",{}),(0,e.jsx)("span",{style:{opacity:.7},children:"\u586B\u4EE3\u7406\u540E\u70B9\u91CD\u8BD5"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{style:{background:"var(--surface-muted)",borderRadius:"var(--radius-lg)",height:10,overflow:"hidden",marginBottom:10},children:(0,e.jsx)("div",{style:{height:"100%",width:`${a}%`,background:"var(--accent)",transition:"width .3s"}})}),(0,e.jsxs)("div",{style:{fontSize:12,opacity:.7},children:["\u4E0B\u8F7D\u4E2D... ",y(t.status.received)," / ",y(i)," MB\uFF08",a,"%\uFF09"]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("input",{id:"hd2d-proxy",className:"office-proxy-input",type:"text",value:t.proxy,onChange:m=>t.onProxyChange(m.currentTarget.value),placeholder:"HTTP \u4EE3\u7406\uFF08\u53EF\u9009\uFF0C\u5982 http://127.0.0.1:7890\uFF09"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.5,marginBottom:14,textAlign:"left"},children:"\u8FDE\u4E0D\u4E0A GitHub \u65F6\u586B\u4EE3\u7406\uFF08\u4EC5\u7528\u4E8E\u4E0B\u8F7D\u672C\u8D44\u6E90\uFF0C\u4F1A\u8BB0\u4F4F\uFF09\u3002\u7559\u7A7A\u8D70\u76F4\u8FDE/\u7CFB\u7EDF\u4EE3\u7406\u73AF\u5883\u53D8\u91CF\u3002"}),(0,e.jsxs)("button",{id:"hd2d-load",type:"button",className:"page-primary-action office-load-button",disabled:t.starting,onClick:t.onStart,children:[l?"\u91CD\u8BD5":"\u52A0\u8F7D\u529E\u516C\u5BA4","\uFF08\u7EA6 ",y(i)," MB\uFF09"]})]})]})}function B(t){let i={maxWidth:t.style.maxWidth,padding:t.style.padding,flex:t.style.flex,minHeight:t.style.minHeight,minWidth:t.style.minWidth,display:t.style.display,overflow:t.style.overflow};t.style.maxWidth="none",t.style.padding="0",t.style.flex="1 1 auto",t.style.minHeight="0",t.style.minWidth="0",t.style.display="flex",t.style.overflow="hidden";let a=p(t,(0,e.jsx)(T,{}));return()=>{a(),t.style.maxWidth=i.maxWidth,t.style.padding=i.padding,t.style.flex=i.flex,t.style.minHeight=i.minHeight,t.style.minWidth=i.minWidth,t.style.display=i.display,t.style.overflow=i.overflow}}export{B as renderOfficePage};
1
+ import{d as x}from"./chunk-3OJQKYM3.js";import"./chunk-QITAMHW6.js";import"./chunk-IRFGJSPL.js";import{c as p}from"./chunk-ARROO6TE.js";import{c as g,d as S,e as w}from"./chunk-3YZFAHNK.js";var n=g(S(),1);var e=g(w(),1),u=78222186;function y(t){return(t/1048576).toFixed(0)}function T(){let t=x(),[i,a]=(0,n.useState)(null),[c,l]=(0,n.useState)(""),[m,h]=(0,n.useState)(!1),d=(0,n.useRef)(null),r=(0,n.useRef)(!1),v=()=>{d.current&&(clearTimeout(d.current),d.current=null)};async function f(){if(!r.current)try{let s=await fetch("/api/game/status");if(r.current)return;if(!s.ok){a({state:"absent",received:0,total:u});return}let o=await s.json();if(r.current)return;a(o),typeof o.proxy=="string"&&l(o.proxy),o.state==="downloading"&&(d.current=setTimeout(()=>{f()},700))}catch{r.current||(d.current=setTimeout(()=>{f()},1500))}}(0,n.useEffect)(()=>(r.current=!1,f(),()=>{r.current=!0,v()}),[]);async function b(){v(),h(!0),a({state:"downloading",received:0,total:u});try{let s=await fetch("/api/game/download",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({proxy:c.trim()})});if(r.current)return;if(!s.ok)throw new Error(`HTTP ${s.status}`);let o=await s.json();if(r.current)return;a(o),typeof o.proxy=="string"&&l(o.proxy),o.state==="downloading"&&(d.current=setTimeout(()=>{f()},700))}catch(s){if(r.current)return;a({state:"error",received:0,total:u,error:s instanceof Error?s.message:String(s)})}finally{r.current||h(!1)}}return i?.state==="ready"?(0,e.jsx)("div",{className:"office-frame-shell",children:(0,e.jsx)("iframe",{className:"office-game-frame",src:"/game/index.html",title:"HD2D Office",allow:"autoplay"})}):(0,e.jsx)(P,{status:i??{state:"absent",received:0,total:u},title:t("nav.office"),proxy:c,starting:m,onProxyChange:l,onStart:()=>{b()}})}function P(t){let i=t.status.total||u,a=(0,n.useMemo)(()=>i?Math.min(100,Math.round(t.status.received/i*100)):0,[t.status.received,i]),c=t.status.state==="downloading",l=t.status.state==="error";return(0,e.jsxs)("div",{style:{margin:"auto",textAlign:"center",maxWidth:440,padding:32,color:"var(--fg,#e6e6e6)"},children:[(0,e.jsx)("h1",{style:{fontSize:18,fontWeight:600,lineHeight:1.2,margin:"0 0 8px"},children:t.title}),(0,e.jsxs)("div",{style:{fontSize:13,opacity:.7,lineHeight:1.7,marginBottom:20},children:["\u628A\u6BCF\u4E2A\u4F1A\u8BDD\u53D8\u6210\u529E\u516C\u5BA4\u91CC\u7684\u4E00\u4E2A\u673A\u5668\u4EBA\uFF0C\u5B9E\u65F6\u6620\u5C04\u5C4F\u5E55\u72B6\u6001\u3002",(0,e.jsx)("br",{}),"\u9996\u6B21\u8FDB\u5165\u9700\u4E0B\u8F7D\u7EA6 ",y(i)," MB \u6E38\u620F\u8D44\u6E90\uFF08\u4EC5\u4E00\u6B21\uFF0C\u4E4B\u540E\u672C\u5730\u7F13\u5B58\uFF09\u3002"]}),l?(0,e.jsxs)("div",{style:{color:"#e06c75",fontSize:12,marginBottom:14},children:["\u4E0A\u6B21\u4E0B\u8F7D\u5931\u8D25\uFF1A",t.status.error??"\u672A\u77E5\u9519\u8BEF",(0,e.jsx)("br",{}),(0,e.jsx)("span",{style:{opacity:.7},children:"\u586B\u4EE3\u7406\u540E\u70B9\u91CD\u8BD5"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{style:{background:"var(--surface-muted)",borderRadius:"var(--radius-lg)",height:10,overflow:"hidden",marginBottom:10},children:(0,e.jsx)("div",{style:{height:"100%",width:`${a}%`,background:"var(--accent)",transition:"width .3s"}})}),(0,e.jsxs)("div",{style:{fontSize:12,opacity:.7},children:["\u4E0B\u8F7D\u4E2D... ",y(t.status.received)," / ",y(i)," MB\uFF08",a,"%\uFF09"]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("input",{id:"hd2d-proxy",className:"office-proxy-input",type:"text",value:t.proxy,onChange:m=>t.onProxyChange(m.currentTarget.value),placeholder:"HTTP \u4EE3\u7406\uFF08\u53EF\u9009\uFF0C\u5982 http://127.0.0.1:7890\uFF09"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.5,marginBottom:14,textAlign:"left"},children:"\u8FDE\u4E0D\u4E0A GitHub \u65F6\u586B\u4EE3\u7406\uFF08\u4EC5\u7528\u4E8E\u4E0B\u8F7D\u672C\u8D44\u6E90\uFF0C\u4F1A\u8BB0\u4F4F\uFF09\u3002\u7559\u7A7A\u8D70\u76F4\u8FDE/\u7CFB\u7EDF\u4EE3\u7406\u73AF\u5883\u53D8\u91CF\u3002"}),(0,e.jsxs)("button",{id:"hd2d-load",type:"button",className:"page-primary-action office-load-button",disabled:t.starting,onClick:t.onStart,children:[l?"\u91CD\u8BD5":"\u52A0\u8F7D\u529E\u516C\u5BA4","\uFF08\u7EA6 ",y(i)," MB\uFF09"]})]})]})}function B(t){let i={maxWidth:t.style.maxWidth,padding:t.style.padding,flex:t.style.flex,minHeight:t.style.minHeight,minWidth:t.style.minWidth,display:t.style.display,overflow:t.style.overflow};t.style.maxWidth="none",t.style.padding="0",t.style.flex="1 1 auto",t.style.minHeight="0",t.style.minWidth="0",t.style.display="flex",t.style.overflow="hidden";let a=p(t,(0,e.jsx)(T,{}));return()=>{a(),t.style.maxWidth=i.maxWidth,t.style.padding=i.padding,t.style.flex=i.flex,t.style.minHeight=i.minHeight,t.style.minWidth=i.minWidth,t.style.display=i.display,t.style.overflow=i.overflow}}export{B as renderOfficePage};
@@ -0,0 +1 @@
1
+ import{a as re,b as le}from"./chunk-MYLVEXYF.js";import{b as ae}from"./chunk-SZOB6VK2.js";import{b as I,d as M,e as E,f as L,g as ee,k as te,m as ne,n as se,o as oe,r as ie}from"./chunk-QALRQEKD.js";import{b as q,d as A}from"./chunk-3OJQKYM3.js";import"./chunk-QITAMHW6.js";import{A as C,C as j,D as x,H as V,J as T,K as Y,L as y,M as b,N}from"./chunk-IRFGJSPL.js";import{c as G}from"./chunk-ARROO6TE.js";import{c as _,d as ue,e as Q}from"./chunk-3YZFAHNK.js";var r=_(ue(),1);var e=_(Q(),1),pe=new Set(["working","analyzing","active"]),ce="botmux.overview.teamExpanded",ve="botmux.overview.activeSort",$=5,D=1,we=6,ge=7,B=24,he=4e3;function fe(){try{return window.localStorage.getItem(ce)==="1"}catch{return!1}}function Se(t){try{window.localStorage.setItem(ce,t?"1":"0")}catch{}}function be(t){return t==="attention"?"attention":"time"}function Ne(){try{return be(window.localStorage.getItem(ve))}catch{return"time"}}function Ae(t){try{window.localStorage.setItem(ve,t)}catch{}}function ke(t,s){let o=(i,a)=>Number(a.lastMessageAt??0)-Number(i.lastMessageAt??0);return s==="attention"?[...t].sort((i,a)=>{let v=b(i)?0:1,w=b(a)?0:1;if(v!==w)return v-w;if(v===0){let c=N(i)-N(a);if(c!==0)return c}return o(i,a)}):[...t].sort(o)}function ye(t){return String(t??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function Me(t,s){let o=String(t??"unknown"),i=`sessions.status.${o}`,a=s(i);return a===i?o:a}function Re(t){if(!t)return D*$;let s=window.getComputedStyle(t).gridTemplateColumns.split(/\s+/).filter(i=>Number.parseFloat(i)>0);return Math.max(1,s.length||$)*D}function Ce(t){let s=(0,r.useRef)(null),o=(0,r.useRef)(t);o.current=t;let[,i]=(0,r.useState)(0);(0,r.useEffect)(()=>{s.current===null&&(s.current=Array(B).fill(o.current));let k=window.setInterval(()=>{let m=s.current;m&&(m.push(o.current),m.length>B&&m.shift(),i(u=>u+1))},he);return()=>window.clearInterval(k)},[]);let a=s.current??Array(B).fill(t),v=Math.min(...a),c=Math.max(...a)-v,f=100,l=32,d=4,R=a.map((k,m)=>{let u=m/(a.length-1)*f,p=c===0?l/2:l-d-(k-v)/c*(l-d*2);return`${u.toFixed(1)},${p.toFixed(1)}`}).join(" ");return{line:R,area:`0,${l} ${R} ${f},${l}`}}function xe({kind:t}){let s={viewBox:"0 0 24 24",width:18,height:18,fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};return t==="need"?(0,e.jsxs)("svg",{...s,children:[(0,e.jsx)("path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"}),(0,e.jsx)("path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0"})]}):t==="work"?(0,e.jsx)("svg",{...s,children:(0,e.jsx)("path",{d:"M3 12h4l3 8 4-16 3 8h4"})}):t==="active"?(0,e.jsx)("svg",{...s,children:(0,e.jsx)("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})}):(0,e.jsxs)("svg",{...s,children:[(0,e.jsx)("rect",{x:"4",y:"8",width:"16",height:"12",rx:"3"}),(0,e.jsx)("path",{d:"M12 8V4"}),(0,e.jsx)("circle",{cx:"12",cy:"3",r:"1"}),(0,e.jsx)("path",{d:"M9 14h.01M15 14h.01"})]})}function O(t){let{line:s,area:o}=Ce(t.value);return(0,e.jsxs)("article",{className:`stat-chip stat-chip--${t.tone}`,children:[(0,e.jsx)("span",{className:"stat-chip-icon",children:(0,e.jsx)(xe,{kind:t.tone})}),(0,e.jsxs)("div",{className:"stat-chip-body",children:[(0,e.jsxs)("b",{className:"stat-chip-value",children:[t.value,t.suffix?(0,e.jsx)("small",{className:"stat-chip-suffix",children:t.suffix}):null]}),(0,e.jsx)("span",{className:"stat-chip-label",children:t.label})]}),(0,e.jsxs)("svg",{className:"stat-chip-spark",viewBox:"0 0 100 32",preserveAspectRatio:"none","aria-hidden":"true",children:[(0,e.jsx)("polygon",{points:o}),(0,e.jsx)("polyline",{points:s,vectorEffect:"non-scaling-stroke"})]})]})}function Te({card:t}){let s=A(),o=j(t.larkAppId,t.brand),i=!t.online&&t.active.length===0,a=t.attention.length>0,v=t.busy.length>0,w=a?"warn":v?"busy":i?"off":"ok",c;if(a){let l=[...t.attention].sort((d,h)=>N(d)-N(h))[0];c=(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("b",{children:(y(l.title)||l.sessionId).slice(0,60)})," \xB7 ",b(l)??""]})}else if(v){let l=[...t.busy].sort((d,h)=>Number(h.lastMessageAt??0)-Number(d.lastMessageAt??0))[0];c=(0,e.jsx)("b",{children:(y(l.title)||l.sessionId).slice(0,60)})}else i?c=s("overview.botOffline"):c=s("overview.botIdle");let f=a?(0,e.jsx)("span",{className:"tag tag-warn",children:s("overview.botNeedsYou")}):v?(0,e.jsx)("span",{className:"tag tag-run",children:s("overview.botBusy",{count:t.busy.length})}):i?(0,e.jsx)("span",{className:"tag tag-off",children:s("overview.botOff")}):(0,e.jsx)("span",{className:"tag tag-ok",children:s("overview.botReady")});return(0,e.jsxs)("article",{className:`mate${a?" mate-attn":""}${i?" mate-off":""}`,children:[o?(0,e.jsx)("a",{className:"mate-console",href:o,target:"_blank",rel:"noopener noreferrer","data-tip":s("overview.botConsole"),"aria-label":s("overview.botConsole"),children:(0,e.jsx)("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M7 17 17 7M9 7h8v8"})})}):null,(0,e.jsxs)("div",{className:"mate-top",children:[(0,e.jsx)(I,{html:x({name:t.botName,larkAppId:t.larkAppId,avatarUrl:t.botAvatarUrl,dot:w})}),(0,e.jsxs)("div",{className:"mate-id",children:[(0,e.jsx)("b",{children:t.botName}),(0,e.jsx)("span",{className:"mate-role",children:t.cliId})]})]}),(0,e.jsx)("div",{className:"mate-task",children:c}),(0,e.jsxs)("div",{className:"mate-foot",children:[f,(0,e.jsx)("span",{children:t.lastActiveAt?s("overview.lastActive",{time:C(t.lastActiveAt)}):s("common.never")})]})]})}function Ie({session:t}){let s=A(),o=T(t),i=b(t)??"";return(0,e.jsxs)("a",{className:"attn-item",href:"#/sessions",role:"listitem",children:[(0,e.jsx)(I,{html:x({name:o,larkAppId:t.larkAppId,size:"sm"})}),(0,e.jsxs)("span",{className:"attn-main",children:[(0,e.jsx)("b",{children:(y(t.title)||t.sessionId).slice(0,64)}),(0,e.jsxs)("span",{children:[i," \xB7 ",s("overview.waitingFor",{time:C(N(t))})]})]}),(0,e.jsx)("span",{className:"attn-action",children:s("strip.handle")})]})}function Ee({session:t}){let s=A(),o=T(t),i=String(t.status??"unknown");return(0,e.jsxs)("a",{className:"work-item",href:"#/sessions",role:"listitem",children:[(0,e.jsx)(I,{html:x({name:o,larkAppId:t.larkAppId,size:"sm"})}),(0,e.jsxs)("span",{className:"work-main",children:[(0,e.jsx)("b",{children:(y(t.title)||t.sessionId).slice(0,64)}),(0,e.jsxs)("span",{children:[o," \xB7 ",Y(t)??t.cliId??"unknown"," \xB7 ",C(t.lastMessageAt)]})]}),(0,e.jsx)("span",{className:`status work-status status-${ye(i)}`,children:Me(i,s)})]})}function Le({schedule:t,timeZone:s}){let o=t.nextRunAt?new Date(t.nextRunAt).toLocaleString(void 0,s?{timeZone:s,timeZoneName:"short"}:void 0):"-";return(0,e.jsxs)(se,{kind:"schedule",children:[(0,e.jsx)("span",{className:"sched-clock","aria-hidden":"true",children:(0,e.jsxs)("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,e.jsx)("path",{d:"M12 7v5l3 2"})]})}),(0,e.jsxs)(oe,{children:[(0,e.jsx)("strong",{children:t.name??t.id}),(0,e.jsxs)("span",{children:[T(t)," \xB7 ",t.parsed?.display??""]})]}),(0,e.jsx)("span",{className:"overview-list-meta",children:(0,e.jsx)(te,{text:o,showPopover:!1,durationMs:2600})})]})}function Oe({mode:t,onModeChange:s}){let o=A(),i=o(t==="attention"?"overview.sortAttentionFirst":"overview.sortByTime");return(0,e.jsx)(ie,{className:"overview-active-sort-menu",label:i,value:t,options:[{value:"time",label:o("overview.sortByTime")},{value:"attention",label:o("overview.sortAttentionFirst")}],onChange:s})}function He(){let t=A(),s=(0,r.useRef)(null),[o,i]=(0,r.useState)(fe),[a,v]=(0,r.useState)(Ne),[w,c]=(0,r.useState)(D*$),[f,l]=(0,r.useState)(0),{sessions:d,schedules:h,scheduleTimeZone:R,schedulesAvailable:k,online:m}=q(n=>({sessions:[...n.sessions.values()],schedules:[...n.schedules.values()],scheduleTimeZone:n.scheduleTimeZone,schedulesAvailable:n.schedulesAvailable,online:n.online}));(0,r.useEffect)(()=>{let n=0,g=()=>{window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{let U=Re(s.current);c(Z=>Z===U?Z:U)})};g();let P=typeof ResizeObserver>"u"||!s.current?null:new ResizeObserver(g);return P&&s.current&&P.observe(s.current),window.addEventListener("resize",g),()=>{window.cancelAnimationFrame(n),P?.disconnect(),window.removeEventListener("resize",g)}},[]),(0,r.useEffect)(()=>{re().then(()=>l(n=>n+1)),V().then(()=>l(n=>n+1))},[]);let u=(0,r.useMemo)(()=>d.filter(n=>n.status!=="closed"),[d]),p=(0,r.useMemo)(()=>le(d),[d,f]),z=o?p:p.slice(0,w),S=(0,r.useMemo)(()=>u.filter(n=>b(n)),[u]),W=(0,r.useMemo)(()=>ke(S,a).slice(0,we),[S,a]),H=(0,r.useMemo)(()=>u.filter(n=>pe.has(String(n.status))).sort((n,g)=>Number(g.lastMessageAt??0)-Number(n.lastMessageAt??0)),[u]),F=H.slice(0,ge),X=(0,r.useMemo)(()=>p.filter(n=>n.online||n.active.length>0).length,[p]),J=(0,r.useMemo)(()=>h.filter(n=>n.nextRunAt).sort((n,g)=>Date.parse(n.nextRunAt)-Date.parse(g.nextRunAt)).slice(0,5),[h]),K=k&&J.length>0,de=()=>{i(n=>(Se(!n),!n))},me=n=>{v(n),Ae(n)};return(0,e.jsxs)("section",{className:"page hero-page",children:[(0,e.jsxs)("div",{className:"page-heading",children:[(0,e.jsxs)("div",{className:"overview-head",children:[(0,e.jsx)("p",{className:"eyebrow",children:t("app.subtitle")}),(0,e.jsx)("h1",{children:t("overview.title")}),(0,e.jsxs)("p",{className:"overview-subtitle",children:[(0,e.jsx)("span",{children:t("overview.headingSubtitle",{bots:X,needs:S.length})}),(0,e.jsxs)("span",{className:`overview-live${m?" is-online":" is-offline"}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),t(m?"overview.liveSync":"overview.syncOffline")]})]})]}),(0,e.jsxs)("div",{className:"page-heading-actions",children:[(0,e.jsx)("a",{className:"btn-link",href:"#/monitoring",children:t("nav.monitoring")}),(0,e.jsx)(ee,{className:"page-primary-action",onClick:()=>ae(),children:t("nav.createSession")})]})]}),(0,e.jsxs)("div",{className:"overview-stats",children:[(0,e.jsx)(O,{tone:"need",label:t("overview.attention"),value:S.length}),(0,e.jsx)(O,{tone:"work",label:t("overview.workingSessions"),value:H.length}),(0,e.jsx)(O,{tone:"active",label:t("overview.activeSessions"),value:u.length}),(0,e.jsx)(O,{tone:"online",label:t("overview.onlineBots"),value:X,suffix:`/ ${p.length}`})]}),(0,e.jsxs)("section",{className:"overview-block attention-section",children:[(0,e.jsx)(M,{title:t("overview.attention"),count:t("strip.pending",{count:S.length}),children:S.length>1?(0,e.jsx)(L,{children:(0,e.jsx)(Oe,{mode:a,onModeChange:me})}):null}),W.length?(0,e.jsx)("div",{className:"attn-list",role:"list",children:W.map(n=>(0,e.jsx)(Ie,{session:n},n.sessionId))}):(0,e.jsxs)("div",{className:"attn-empty",children:[(0,e.jsx)("span",{className:"attn-empty-icon","aria-hidden":"true",children:(0,e.jsx)("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M20 6 9 17l-5-5"})})}),(0,e.jsx)("span",{children:t("overview.allClear")})]})]}),(0,e.jsxs)("div",{className:`overview-layout${K?"":" overview-layout--single"}`,children:[(0,e.jsxs)("div",{className:"overview-main",children:[(0,e.jsxs)("section",{className:"overview-block",children:[(0,e.jsx)(M,{title:t("overview.workingSessions"),count:String(H.length),children:(0,e.jsx)(L,{children:(0,e.jsx)(E,{href:"#/sessions",children:t("overview.viewAllPlain")})})}),(0,e.jsx)("section",{className:"panel active-sessions-panel",children:F.length?(0,e.jsx)("div",{className:"work-list",role:"list",children:F.map(n=>(0,e.jsx)(Ee,{session:n},n.sessionId))}):(0,e.jsx)("div",{className:"empty",children:t("overview.noSessions")})})]}),(0,e.jsxs)("section",{className:"overview-block team-section",children:[(0,e.jsx)(M,{title:t("overview.team"),count:t("overview.teamCount",{count:p.length}),hint:t("overview.teamHint"),children:(0,e.jsx)(L,{children:(0,e.jsx)(E,{href:"#/bot-defaults",children:t("overview.viewAllPlain")})})}),(0,e.jsx)("div",{className:"team-grid",id:"team-grid",ref:s,children:z.length?z.map(n=>(0,e.jsx)(Te,{card:n},n.larkAppId??n.botName)):(0,e.jsx)("div",{className:"empty",children:t("overview.noSessions")})}),p.length>w?(0,e.jsx)("button",{type:"button",className:"team-toggle",id:"team-toggle",onClick:de,children:t(o?"overview.teamCollapse":"overview.teamExpand")}):null]})]}),K?(0,e.jsx)("aside",{className:"overview-side",children:(0,e.jsxs)("section",{className:"overview-block",children:[(0,e.jsx)(M,{title:t("overview.upcomingSchedules"),children:(0,e.jsx)(E,{href:"#/schedules",children:t("overview.viewAllPlain")})}),(0,e.jsx)("section",{className:"panel schedules-panel",children:(0,e.jsx)(ne,{id:"next-schedules",children:J.map(n=>(0,e.jsx)(Le,{schedule:n,timeZone:R},n.id))})})]})}):null]})]})}function We(t){t.classList.add("overview-root");let s=G(t,(0,e.jsx)(He,{}));return()=>{s(),t.classList.remove("overview-root")}}export{We as renderOverviewPage};