botmux 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.runtime-build-id +1 -1
- package/dist/adapters/backend/riff-backend.d.ts.map +1 -1
- package/dist/adapters/backend/riff-backend.js +11 -2
- package/dist/adapters/backend/riff-backend.js.map +1 -1
- package/dist/adapters/cli/coco.js +3 -3
- package/dist/adapters/cli/coco.js.map +1 -1
- package/dist/adapters/cli/codex.js +2 -2
- package/dist/adapters/cli/codex.js.map +1 -1
- package/dist/cli/dashboard-command.d.ts +23 -0
- package/dist/cli/dashboard-command.d.ts.map +1 -0
- package/dist/cli/dashboard-command.js +61 -0
- package/dist/cli/dashboard-command.js.map +1 -0
- package/dist/cli/dashboard-endpoint.d.ts +3 -3
- package/dist/cli/dashboard-endpoint.d.ts.map +1 -1
- package/dist/cli/dashboard-endpoint.js +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +36 -22
- package/dist/cli.js.map +1 -1
- package/dist/codex-rpc-engine.d.ts +33 -3
- package/dist/codex-rpc-engine.d.ts.map +1 -1
- package/dist/codex-rpc-engine.js +182 -20
- package/dist/codex-rpc-engine.js.map +1 -1
- package/dist/codex-rpc-lifecycle.d.ts +42 -7
- package/dist/codex-rpc-lifecycle.d.ts.map +1 -1
- package/dist/codex-rpc-lifecycle.js +73 -7
- package/dist/codex-rpc-lifecycle.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/core/command-handler.d.ts +3 -2
- package/dist/core/command-handler.d.ts.map +1 -1
- package/dist/core/command-handler.js +3 -2
- package/dist/core/command-handler.js.map +1 -1
- package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
- package/dist/core/dashboard-ipc-server.js +15 -10
- package/dist/core/dashboard-ipc-server.js.map +1 -1
- package/dist/core/dispatch.d.ts +9 -10
- package/dist/core/dispatch.d.ts.map +1 -1
- package/dist/core/dispatch.js +17 -10
- package/dist/core/dispatch.js.map +1 -1
- package/dist/core/role-resolver.d.ts +5 -2
- package/dist/core/role-resolver.d.ts.map +1 -1
- package/dist/core/role-resolver.js +55 -23
- package/dist/core/role-resolver.js.map +1 -1
- package/dist/core/session-manager.d.ts +2 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +20 -18
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/terminal-write-auth.d.ts +4 -4
- package/dist/core/terminal-write-auth.d.ts.map +1 -1
- package/dist/core/terminal-write-auth.js +18 -6
- package/dist/core/terminal-write-auth.js.map +1 -1
- package/dist/daemon.d.ts +1 -0
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +101 -12
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard/auth.d.ts +21 -11
- package/dist/dashboard/auth.d.ts.map +1 -1
- package/dist/dashboard/auth.js +39 -25
- package/dist/dashboard/auth.js.map +1 -1
- package/dist/dashboard/bot-payload.d.ts +0 -1
- package/dist/dashboard/bot-payload.d.ts.map +1 -1
- package/dist/dashboard/bot-payload.js +0 -1
- package/dist/dashboard/bot-payload.js.map +1 -1
- package/dist/dashboard/dashboard-summary-endpoint.d.ts +39 -0
- package/dist/dashboard/dashboard-summary-endpoint.d.ts.map +1 -0
- package/dist/dashboard/dashboard-summary-endpoint.js +50 -0
- package/dist/dashboard/dashboard-summary-endpoint.js.map +1 -0
- package/dist/dashboard/dashboard-summary.d.ts +62 -0
- package/dist/dashboard/dashboard-summary.d.ts.map +1 -0
- package/dist/dashboard/dashboard-summary.js +106 -0
- package/dist/dashboard/dashboard-summary.js.map +1 -0
- package/dist/dashboard/web/feed-group-picker.d.ts +13 -0
- package/dist/dashboard/web/feed-group-picker.d.ts.map +1 -0
- package/dist/dashboard/web/feed-group-picker.js +45 -0
- package/dist/dashboard/web/feed-group-picker.js.map +1 -0
- package/dist/dashboard/web/groups-page.d.ts.map +1 -1
- package/dist/dashboard/web/groups-page.js +2 -5
- package/dist/dashboard/web/groups-page.js.map +1 -1
- package/dist/dashboard/web/i18n.d.ts.map +1 -1
- package/dist/dashboard/web/i18n.js +8 -14
- package/dist/dashboard/web/i18n.js.map +1 -1
- package/dist/dashboard/web/roles-page.d.ts.map +1 -1
- package/dist/dashboard/web/roles-page.js +36 -4
- package/dist/dashboard/web/roles-page.js.map +1 -1
- package/dist/dashboard/web/roles.d.ts +3 -1
- package/dist/dashboard/web/roles.d.ts.map +1 -1
- package/dist/dashboard/web/roles.js +10 -2
- package/dist/dashboard/web/roles.js.map +1 -1
- package/dist/dashboard/web/schedules-page.d.ts.map +1 -1
- package/dist/dashboard/web/schedules-page.js +8 -2
- package/dist/dashboard/web/schedules-page.js.map +1 -1
- package/dist/dashboard/web/sessions-page.d.ts.map +1 -1
- package/dist/dashboard/web/sessions-page.js +2 -2
- package/dist/dashboard/web/sessions-page.js.map +1 -1
- package/dist/dashboard-web/app.js +1 -1
- package/dist/dashboard-web/chunks/{bot-defaults-page-GED4FEMS.js → bot-defaults-page-USC6EZXP.js} +1 -1
- package/dist/dashboard-web/chunks/chunk-6ALR252E.js +1 -0
- package/dist/dashboard-web/chunks/{chunk-VBXJOJFH.js → chunk-A7VC4BXR.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-HK7NIBJG.js → chunk-KOPISPHN.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-6J5LS5AU.js → chunk-M6BHWQFO.js} +6 -6
- package/dist/dashboard-web/chunks/{chunk-KRHWZEXU.js → chunk-RXRJB5SO.js} +1 -1
- package/dist/dashboard-web/chunks/{connectors-page-EELM66G3.js → connectors-page-4Z76HWRH.js} +1 -1
- package/dist/dashboard-web/chunks/groups-page-C6NSDTIN.js +8 -0
- package/dist/dashboard-web/chunks/{insights-page-54UBPPOC.js → insights-page-UTOVYLLY.js} +1 -1
- package/dist/dashboard-web/chunks/{monitor-room-PORHVKRH.js → monitor-room-UKTJYTA2.js} +1 -1
- package/dist/dashboard-web/chunks/{monitoring-page-XGA7AXNL.js → monitoring-page-Q3CEZIVX.js} +1 -1
- package/dist/dashboard-web/chunks/{office-page-AO3AFG45.js → office-page-GYCZOOVJ.js} +1 -1
- package/dist/dashboard-web/chunks/{overview-page-F5BUTYR6.js → overview-page-W2VBJ6OH.js} +1 -1
- package/dist/dashboard-web/chunks/roles-page-U4SHER4K.js +1 -0
- package/dist/dashboard-web/chunks/schedules-page-TNPW3N3Q.js +1 -0
- package/dist/dashboard-web/chunks/{sessions-page-YFRPSTIL.js → sessions-page-YWWDDV57.js} +3 -3
- package/dist/dashboard-web/chunks/{settings-page-OJAZLZQT.js → settings-page-VKW5ZK5K.js} +1 -1
- package/dist/dashboard-web/chunks/{skills-page-EFZQPWV4.js → skills-page-ZCEDFGZZ.js} +1 -1
- package/dist/dashboard-web/chunks/{team-federation-page-ZJVAP7HW.js → team-federation-page-OMFGGBT2.js} +1 -1
- package/dist/dashboard-web/chunks/{v3-page-GYWTRGO2.js → v3-page-PLXWK4KO.js} +1 -1
- package/dist/dashboard-web/chunks/{whiteboards-page-MSDAG6P7.js → whiteboards-page-NJQOEO2P.js} +1 -1
- package/dist/dashboard-web/style.css +112 -0
- package/dist/dashboard.js +116 -31
- package/dist/dashboard.js.map +1 -1
- package/dist/desktop/main/ipc.js +1 -1
- package/dist/desktop/main/runtime-service.js +2 -2
- package/dist/desktop/main/runtime-service.js.map +1 -1
- package/dist/desktop/shared/types.d.ts +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +3 -1
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +3 -1
- package/dist/i18n/zh.js.map +1 -1
- package/dist/services/adopt-input-sequence.d.ts +52 -0
- package/dist/services/adopt-input-sequence.d.ts.map +1 -0
- package/dist/services/adopt-input-sequence.js +50 -0
- package/dist/services/adopt-input-sequence.js.map +1 -0
- package/dist/services/bridge-fallback-gate.d.ts.map +1 -1
- package/dist/services/bridge-fallback-gate.js +34 -11
- package/dist/services/bridge-fallback-gate.js.map +1 -1
- package/dist/services/codex-bridge-queue.d.ts +103 -7
- package/dist/services/codex-bridge-queue.d.ts.map +1 -1
- package/dist/services/codex-bridge-queue.js +291 -17
- package/dist/services/codex-bridge-queue.js.map +1 -1
- package/dist/services/codex-transcript.d.ts +4 -3
- package/dist/services/codex-transcript.d.ts.map +1 -1
- package/dist/services/codex-transcript.js.map +1 -1
- package/dist/services/structured-bridge-clis.d.ts +8 -1
- package/dist/services/structured-bridge-clis.d.ts.map +1 -1
- package/dist/services/structured-bridge-clis.js +13 -0
- package/dist/services/structured-bridge-clis.js.map +1 -1
- package/dist/services/submit-confirmation.d.ts +50 -0
- package/dist/services/submit-confirmation.d.ts.map +1 -1
- package/dist/services/submit-confirmation.js +82 -0
- package/dist/services/submit-confirmation.js.map +1 -1
- package/dist/utils/async-serial-queue.d.ts +9 -0
- package/dist/utils/async-serial-queue.d.ts.map +1 -0
- package/dist/utils/async-serial-queue.js +13 -0
- package/dist/utils/async-serial-queue.js.map +1 -0
- package/dist/utils/runtime-screen-status.d.ts +52 -0
- package/dist/utils/runtime-screen-status.d.ts.map +1 -0
- package/dist/utils/runtime-screen-status.js +60 -0
- package/dist/utils/runtime-screen-status.js.map +1 -0
- package/dist/worker.js +1642 -452
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/dashboard-web/chunks/groups-page-WKUV6E42.js +0 -8
- package/dist/dashboard-web/chunks/roles-page-M5GIASJU.js +0 -1
- package/dist/dashboard-web/chunks/schedules-page-O232WQRR.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as T,b as B,d as I,e as N,f as P,g as _}from"./chunk-XJ7BGPJH.js";import{D as O,F as S,H as W,a as E,u as r,v as n,w as C,z as x}from"./chunk-
|
|
1
|
+
import{a as T,b as B,d as I,e as N,f as P,g as _}from"./chunk-XJ7BGPJH.js";import{D as O,F as S,H as W,a as E,u as r,v as n,w as C,z as x}from"./chunk-M6BHWQFO.js";import"./chunk-7SZRL6FY.js";function z(t){let o=String(t??"unknown"),e=`sessions.status.${o}`,i=r(e);return i===e?o:i}function F(t){return String(t??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function D(t){let o=String(t??"unknown");return`<span class="status status-${n(F(o))}">${n(z(o))}</span>`}function q(t){return W(t?.title)||String(t?.sessionId??"")}var A=14,G=49,K=18;function U(){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)-K);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)-G*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 J(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 Q(t,o){return t?`frame:${T(t,o)??"none"}`:"missing"}function V(t,o){let e=E.sessions.get(t),i=o?et(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=q(e),m=T(e),a=S(e),l=m?nt(t):"";return`<div class="monitor-room-card-title">
|
package/dist/dashboard-web/chunks/{monitoring-page-XGA7AXNL.js → monitoring-page-Q3CEZIVX.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as k}from"./chunk-HK7NIBJG.js";import{c as G,d as f,j as _,m as H,n as T,o as D,p as A}from"./chunk-5CJMHTT4.js";import"./chunk-6J5LS5AU.js";import{a as U}from"./chunk-SYC6D5XU.js";import{a as Y,d as K}from"./chunk-5THX4DI2.js";import{c as $}from"./chunk-7SZRL6FY.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 k}from"./chunk-KOPISPHN.js";import{c as G,d as f,j as _,m as H,n as T,o as D,p as A}from"./chunk-5CJMHTT4.js";import"./chunk-M6BHWQFO.js";import{a as U}from"./chunk-SYC6D5XU.js";import{a as Y,d as K}from"./chunk-5THX4DI2.js";import{c as $}from"./chunk-7SZRL6FY.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{c as w}from"./chunk-
|
|
1
|
+
import{c as w}from"./chunk-KOPISPHN.js";import"./chunk-M6BHWQFO.js";import{a as p}from"./chunk-SYC6D5XU.js";import{a as S,d as x}from"./chunk-5THX4DI2.js";import{c as g}from"./chunk-7SZRL6FY.js";var n=g(S(),1);var e=g(x(),1),u=78222186;function y(t){return(t/1048576).toFixed(0)}function T(){let t=w(),[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 +1 @@
|
|
|
1
|
-
import{a as Q,b as ee}from"./chunk-
|
|
1
|
+
import{a as Q,b as ee}from"./chunk-A7VC4BXR.js";import{a as j,c as N}from"./chunk-KOPISPHN.js";import{b as x,d as T,e as k,f as I,k as X,m as O,n as P,o as _,p as G,r as J}from"./chunk-5CJMHTT4.js";import{D as q,F as H,G as V,H as M,I as g,J as A,w as L,y as $,z as C}from"./chunk-M6BHWQFO.js";import{a as W}from"./chunk-SYC6D5XU.js";import{a as re,d as K}from"./chunk-5THX4DI2.js";import{c as E}from"./chunk-7SZRL6FY.js";var r=E(re(),1);var t=E(K(),1),le=new Set(["working","analyzing","active","starting"]),ce=new Set(["idle","dormant"]),te="botmux.overview.teamExpanded",ne="botmux.overview.activeSort",z=5,B=1,ve=260;function de(){try{return window.localStorage.getItem(te)==="1"}catch{return!1}}function me(e){try{window.localStorage.setItem(te,e?"1":"0")}catch{}}function ue(e){return e==="attention"?"attention":"time"}function pe(){try{return ue(window.localStorage.getItem(ne))}catch{return"time"}}function we(e){try{window.localStorage.setItem(ne,e)}catch{}}function fe(e,o){let s=(i,a)=>Number(a.lastMessageAt??0)-Number(i.lastMessageAt??0);return o==="attention"?[...e].sort((i,a)=>{let v=g(i)?0:1,c=g(a)?0:1;if(v!==c)return v-c;if(v===0){let d=A(i)-A(a);if(d!==0)return d}return s(i,a)}):[...e].sort(s)}function ge(e){return String(e??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function Se(e,o){let s=String(e??"unknown"),i=`sessions.status.${s}`,a=o(i);return a===i?s:a}function he(e){if(!e)return B*z;let o=window.getComputedStyle(e).gridTemplateColumns.split(/\s+/).filter(i=>Number.parseFloat(i)>0);return Math.max(1,o.length||z)*B}function be(e,o){if(!e)return;let s=document.querySelector(".sidebar");if(!s||window.matchMedia("(max-width: 980px)").matches){e.style.removeProperty(o);return}let i=s.getBoundingClientRect().bottom,a=e.getBoundingClientRect().top,c=`${Math.max(ve,Math.round(i-a))}px`;e.style.getPropertyValue(o)!==c&&e.style.setProperty(o,c)}function Ae({card:e}){let o=N(),s=$(e.larkAppId,e.brand),i=!e.online&&e.active.length===0,a=e.attention.length>0,v=e.busy.length>0,c=a?"warn":v?"busy":i?"off":"ok",d;if(a){let u=[...e.attention].sort((h,f)=>A(h)-A(f))[0];d=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("b",{children:(M(u.title)||u.sessionId).slice(0,60)})," \xB7 ",g(u)??""]})}else if(v){let u=[...e.busy].sort((h,f)=>Number(f.lastMessageAt??0)-Number(h.lastMessageAt??0))[0];d=(0,t.jsx)("b",{children:(M(u.title)||u.sessionId).slice(0,60)})}else i?d=o("overview.botOffline"):d=o("overview.botIdle");let S=a?(0,t.jsx)("span",{className:"tag tag-warn",children:o("overview.botNeedsYou")}):v?(0,t.jsx)("span",{className:"tag tag-run",children:o("overview.botBusy",{count:e.busy.length})}):i?(0,t.jsx)("span",{className:"tag tag-off",children:o("overview.botOff")}):(0,t.jsx)("span",{className:"tag tag-ok",children:o("overview.botReady")});return(0,t.jsxs)("article",{className:`mate${a?" mate-attn":""}${i?" mate-off":""}`,children:[s?(0,t.jsx)("a",{className:"mate-console",href:s,target:"_blank",rel:"noopener noreferrer","data-tip":o("overview.botConsole"),"aria-label":o("overview.botConsole"),children:(0,t.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,t.jsx)("path",{d:"M7 17 17 7M9 7h8v8"})})}):null,(0,t.jsxs)("div",{className:"mate-top",children:[(0,t.jsx)(x,{html:C({name:e.botName,larkAppId:e.larkAppId,avatarUrl:e.botAvatarUrl,dot:c})}),(0,t.jsxs)("div",{className:"mate-id",children:[(0,t.jsx)("b",{children:e.botName}),(0,t.jsx)("span",{className:"mate-role",children:e.cliId})]})]}),(0,t.jsx)("div",{className:"mate-task",children:d}),(0,t.jsxs)("div",{className:"mate-foot",children:[S,(0,t.jsx)("span",{children:e.lastActiveAt?o("overview.lastActive",{time:L(e.lastActiveAt)}):o("common.never")})]})]})}function Ne({session:e}){let o=N(),s=H(e),i=String(e.status??"unknown"),a=g(e);return(0,t.jsxs)(P,{kind:"session",children:[(0,t.jsx)(x,{html:C({name:s,larkAppId:e.larkAppId,size:"sm"})}),(0,t.jsxs)(_,{children:[(0,t.jsx)("b",{children:(M(e.title)||e.sessionId).slice(0,64)}),(0,t.jsxs)("span",{children:[s," \xB7 ",V(e)??e.cliId??"unknown"," \xB7 ",L(e.lastMessageAt)]})]}),(0,t.jsx)(G,{children:a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("a",{className:"overview-list-action",href:"#/sessions",children:o("strip.handle")}),(0,t.jsx)("span",{className:"status overview-list-status status-attention",children:a})]}):(0,t.jsx)("span",{className:`status overview-list-status status-${ge(i)}`,children:Se(i,o)})})]})}function ye({schedule:e,timeZone:o}){let s=e.nextRunAt?new Date(e.nextRunAt).toLocaleString(void 0,o?{timeZone:o,timeZoneName:"short"}:void 0):"-";return(0,t.jsxs)(P,{kind:"schedule",children:[(0,t.jsxs)(_,{children:[(0,t.jsx)("strong",{children:e.name??e.id}),(0,t.jsxs)("span",{children:[H(e)," \xB7 ",e.parsed?.display??""]})]}),(0,t.jsx)("span",{className:"overview-list-meta",children:(0,t.jsx)(X,{text:s,showPopover:!1,durationMs:2600})})]})}function Me({mode:e,onModeChange:o}){let s=N(),i=s(e==="attention"?"overview.sortAttentionFirst":"overview.sortByTime");return(0,t.jsx)(J,{className:"overview-active-sort-menu",label:i,value:e,options:[{value:"time",label:s("overview.sortByTime")},{value:"attention",label:s("overview.sortAttentionFirst")}],onChange:o})}function Te(){let e=N(),o=(0,r.useRef)(null),s=(0,r.useRef)(null),i=(0,r.useRef)(null),[a,v]=(0,r.useState)(de),[c,d]=(0,r.useState)(pe),[S,u]=(0,r.useState)(B*z),[h,f]=(0,r.useState)(0),{sessions:y,schedules:D,scheduleTimeZone:oe}=j(n=>({sessions:[...n.sessions.values()],schedules:[...n.schedules.values()],scheduleTimeZone:n.scheduleTimeZone}));(0,r.useEffect)(()=>{let n=0,m=()=>{window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{let w=he(o.current);u(l=>l===w?l:w)})};m();let p=typeof ResizeObserver>"u"||!o.current?null:new ResizeObserver(m);return p&&o.current&&p.observe(o.current),window.addEventListener("resize",m),()=>{window.cancelAnimationFrame(n),p?.disconnect(),window.removeEventListener("resize",m)}},[]),(0,r.useEffect)(()=>{Q().then(()=>f(n=>n+1)),q().then(()=>f(n=>n+1))},[]);let F=(0,r.useMemo)(()=>y.filter(n=>n.status!=="closed"),[y]),b=(0,r.useMemo)(()=>ee(y),[y,h]),U=a?b:b.slice(0,S),Y=(0,r.useMemo)(()=>fe(F.filter(n=>g(n)||le.has(n.status)||ce.has(n.status)),c).slice(0,7),[F,c]),R=(0,r.useMemo)(()=>D.filter(n=>n.nextRunAt).sort((n,m)=>Date.parse(n.nextRunAt)-Date.parse(m.nextRunAt)).slice(0,5),[D]);(0,r.useEffect)(()=>{let n=[{el:s.current,propertyName:"--active-sessions-min-height"},{el:i.current,propertyName:"--schedules-panel-min-height"}].filter(l=>!!l.el);if(!n.length)return;let m=0,p=()=>{window.cancelAnimationFrame(m),m=window.requestAnimationFrame(()=>{for(let l of n)be(l.el,l.propertyName)})};p();let w=typeof ResizeObserver>"u"?null:new ResizeObserver(p);if(w){for(let ae of n)w.observe(ae.el);let l=document.querySelector(".sidebar"),Z=n[0].el.closest(".page");l&&w.observe(l),Z&&w.observe(Z)}return window.addEventListener("resize",p),()=>{window.cancelAnimationFrame(m),w?.disconnect(),window.removeEventListener("resize",p);for(let l of n)l.el.style.removeProperty(l.propertyName)}},[a,S,b.length,R.length]);let se=()=>{v(n=>(me(!n),!n))},ie=n=>{d(n),we(n)};return(0,t.jsxs)("section",{className:"page hero-page",children:[(0,t.jsx)("div",{className:"page-heading",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"eyebrow",children:e("app.subtitle")}),(0,t.jsx)("h1",{children:e("overview.title")})]})}),(0,t.jsxs)("div",{className:"overview-layout",children:[(0,t.jsxs)("div",{className:"overview-main",children:[(0,t.jsxs)("section",{className:"overview-block team-section",children:[(0,t.jsx)(T,{title:e("overview.team"),count:e("overview.teamCount",{count:b.length}),hint:e("overview.teamHint"),children:(0,t.jsx)(I,{children:(0,t.jsx)(k,{href:"#/bot-defaults",children:e("overview.viewAllPlain")})})}),(0,t.jsx)("div",{className:"team-grid",id:"team-grid",ref:o,children:U.length?U.map(n=>(0,t.jsx)(Ae,{card:n},n.larkAppId??n.botName)):(0,t.jsx)("div",{className:"empty",children:e("overview.noSessions")})}),b.length>S?(0,t.jsx)("button",{type:"button",className:"team-toggle",id:"team-toggle",onClick:se,children:e(a?"overview.teamCollapse":"overview.teamExpand")}):null]}),(0,t.jsxs)("section",{className:"overview-block",children:[(0,t.jsx)(T,{title:e("overview.activeSessions"),children:(0,t.jsxs)(I,{children:[(0,t.jsx)(Me,{mode:c,onModeChange:ie}),(0,t.jsx)(k,{href:"#/sessions",children:e("overview.viewAllPlain")})]})}),(0,t.jsx)("section",{className:"panel active-sessions-panel",ref:s,children:(0,t.jsx)(O,{id:"recent-sessions",children:Y.length?Y.map(n=>(0,t.jsx)(Ne,{session:n},n.sessionId)):(0,t.jsx)("li",{className:"empty",children:e("overview.noSessions")})})})]})]}),(0,t.jsx)("aside",{className:"overview-side",children:(0,t.jsxs)("section",{className:"overview-block",children:[(0,t.jsx)(T,{title:e("overview.nextSchedules"),children:(0,t.jsx)(k,{href:"#/schedules",children:e("overview.viewAllPlain")})}),(0,t.jsx)("section",{className:"panel schedules-panel",ref:i,children:(0,t.jsx)(O,{id:"next-schedules",children:R.length?R.map(n=>(0,t.jsx)(ye,{schedule:n,timeZone:oe},n.id)):(0,t.jsx)("li",{className:"empty",children:e("overview.noSchedules")})})})]})})]})]})}function He(e){e.classList.add("overview-root");let o=W(e,(0,t.jsx)(Te,{}));return()=>{o(),e.classList.remove("overview-root")}}export{He as renderOverviewPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as Gt,b as Ft,c as $t,d as Ot}from"./chunk-R3FXBFQH.js";import{c as Dt}from"./chunk-KOPISPHN.js";import{b as Bt,c as ce,h as $e,q as Oe}from"./chunk-5CJMHTT4.js";import{D as At,z as Et}from"./chunk-M6BHWQFO.js";import{a as Fe}from"./chunk-SYC6D5XU.js";import{a as bn,d as _t}from"./chunk-5THX4DI2.js";import{c as Ge}from"./chunk-7SZRL6FY.js";var a=Ge(bn(),1);function jt(t,n){let r=n.trim().toLowerCase();return r?t.filter(o=>o.openId.toLowerCase().includes(r)||o.name.toLowerCase().includes(r)||o.memberType.toLowerCase().includes(r)):t}function Ut(t){return[...new Set([...t].filter(Boolean))]}function Ht(t){let n=new Set(t.targetIds.filter(Boolean));if(t.mode==="all_except_excluded"){let o=new Set(t.exclude);for(let c of n)o.delete(c),t.listening||o.add(c);return{include:[],exclude:Ut(o)}}let r=new Set(t.include);for(let o of n)r.delete(o),t.listening&&r.add(o);return{include:Ut(r),exclude:[]}}function Ue(t){let n=t.targetIds.filter(Boolean);if(n.length===0)return t.mode==="all_except_excluded"?"listen":"ignore";let r=new Set;if(t.mode==="all_except_excluded"){let o=new Set(t.exclude);for(let c of n)r.add(o.has(c)?"ignore":"listen")}else{let o=new Set(t.include);for(let c of n)r.add(o.has(c)?"listen":"ignore")}return r.size===1?[...r][0]:"mixed"}function Vt(t,n,r){let o={};for(let c of t){if(!c)continue;let m=n(c),f=m==="user"||m==="bot"?m:r?.[c];(f==="user"||f==="bot")&&(o[c]=f)}return o}var O=32768,qt=Math.floor(O*.95),pe=32768,Kt=Math.floor(pe*.95),je=5,He=20,hn=/^[A-Za-z0-9._-]{1,64}$/;function Ve(t){return hn.test(t)&&t!=="."&&t!==".."}function Wt(t=location.hash){let[,n=""]=t.split("?");return new URLSearchParams(n).get("chatId")?.trim()||null}function qe(t,n){return $t(t,n)}function we(t){return new TextEncoder().encode(t).length}function Yt(t){return t.memberBots.filter(n=>n.inChat&&n.hasRole).length}function zt(t){return t.memberBots.filter(n=>n.inChat).length}function me(t,n){return n?t.find(r=>r.larkAppId===n):void 0}function Jt(t,n){let r=n.toLowerCase();return r?t.filter(o=>{let c=o.chatId.toLowerCase().includes(r)||(o.name??"").toLowerCase().includes(r),m=o.memberBots.some(f=>f.larkAppId.toLowerCase().includes(r)||(f.botName??"").toLowerCase().includes(r));return c||m}):t}function Xt(t,n){let r=n.toLowerCase();return t.filter(o=>!r||o.profileId.toLowerCase().includes(r))}async function x(t){return t.json().catch(()=>({}))}async function Qt(){let t=await fetch("/api/groups"),n=await x(t);return{bots:(n.bots??[]).map(r=>({larkAppId:r.larkAppId,botName:r.botName??r.larkAppId,botAvatarUrl:r.botAvatarUrl})),groups:(n.chats??[]).map(r=>({chatId:r.chatId,name:r.name??r.chatId,memberBots:(r.memberBots??[]).map(o=>({larkAppId:o.larkAppId,botName:o.botName??o.larkAppId,inChat:o.inChat??!1,hasRole:o.hasRole??!1,hasMessageListener:o.hasMessageListener??!1,oncallChat:o.oncallChat??null}))}))}}async function Zt(){let t=await fetch("/api/role-profiles");return(await x(t)).profiles??[]}async function q(t){let n=await fetch(`/api/role-profiles/${encodeURIComponent(t)}`);return(await x(n)).entries??[]}async function Ke(t,n){let r=await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`);return x(r)}async function er(t,n,r,o,c){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:r,injectMode:o,dispatchCompletionEnabled:c})})).ok}async function tr(t,n,r){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({injectMode:r})})).ok}async function rr(t,n,r){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({dispatchCompletionEnabled:r})})).ok}async function nr(t,n){return(await fetch(`/api/roles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"DELETE"})).ok}async function We(t,n){let r=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}`);return(await x(r)).listener??{enabled:!1,prompt:"",messagePolicy:{scope:"top_level"}}}async function sr(t,n,r){return(await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(r)})).ok}async function or(t,n){return(await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"DELETE"})).ok}function Se(t){return Number.isFinite(t)?Math.min(He,Math.max(1,Math.floor(t))):je}function ue(t){return String(t).padStart(2,"0")}function lr(t){if(!t)return"";let n=Number(t);if(!Number.isFinite(n)||n<=0)return"";let r=n<1e12?n*1e3:n,o=new Date(r);return Number.isFinite(o.getTime())?[o.getFullYear(),"-",ue(o.getMonth()+1),"-",ue(o.getDate())," ",ue(o.getHours()),":",ue(o.getMinutes()),":",ue(o.getSeconds())].join(""):""}async function ir(t,n,r,o){let c=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({listener:r,limit:Se(o)})}),m=await x(c);return{ok:c.ok&&m.ok!==!1,requestedLimit:m.requestedLimit??Se(o),matches:m.matches??[],error:m.error}}async function ar(t,n,r,o){let c=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}/run-preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({listener:r,limit:Se(o)})}),m=await x(c);return{ok:c.ok&&m.ok!==!1,requestedLimit:m.requestedLimit??Se(o),matches:m.matches??[],results:m.results,error:m.error}}async function dr(t,n,r){let o=await fetch(`/api/message-listeners/${encodeURIComponent(t)}/${encodeURIComponent(n)}/run-preview/${encodeURIComponent(r)}`),c=await x(o);return{ok:o.ok&&c.ok!==!1,runId:c.runId,results:c.results,error:c.error}}async function cr(t,n){let r=await fetch(`/api/groups/${encodeURIComponent(t)}/${encodeURIComponent(n)}/members-display`);return(await x(r)).members??[]}async function ur(t,n){let r=await fetch(`/api/role-profiles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`);return x(r)}async function pr(t,n,r){return(await fetch(`/api/role-profiles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:r,allowEmpty:!0})})).ok}async function mr(t,n){return(await fetch(`/api/role-profiles/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{method:"DELETE"})).ok}async function fr(t,n){let r=await Promise.all(n.map(async f=>{try{let p=await fetch(`/api/role-profiles/${encodeURIComponent(f.profileId)}`),v=await x(p);return[f.profileId,Array.isArray(v.entries)?v.entries:[]]}catch{return[f.profileId,[]]}})),o=new Set,c=[];for(let f of t)for(let p of f.memberBots){if(!p.inChat||!p.hasRole)continue;let v=qe(p.larkAppId,f.chatId);o.has(v)||(o.add(v),c.push({larkAppId:p.larkAppId,chatId:f.chatId}))}let m=await Ot(c);return{entriesByProfile:new Map(r),effectiveRolesByBot:m}}async function gr(t){let n=await fetch(`/api/role-profiles/${encodeURIComponent(t.profileId)}/apply`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({chatId:t.chatId,larkAppId:t.larkAppId,force:t.force,preview:t.preview})}),r=await x(n);return{larkAppId:t.larkAppId,ok:n.ok&&r.ok!==!1,status:n.status,error:r.error,wouldRefuse:r.wouldRefuse}}var e=Ge(_t(),1),hr=["text","post","image","interactive"],K={enabled:!1,prompt:"",senderPolicy:{mode:"include_only",includeSenderTypes:["user"],excludeSelf:!0},messagePolicy:{includeMsgTypes:[...hr],scope:"top_level"}};function ze(t){let n=t?.senderPolicy?.mode==="include_only"?"include_only":"all_except_excluded";return{enabled:t?.enabled===!0,name:t?.name??"",replyCardTitle:t?.replyCardTitle??"",workingDir:t?.workingDir??"",prompt:t?.prompt??"",senderPolicy:{mode:n,includeSenderOpenIds:[...t?.senderPolicy?.includeSenderOpenIds??[]],excludeSenderOpenIds:[...t?.senderPolicy?.excludeSenderOpenIds??[]],...t?.senderPolicy?.excludeSenderKinds?{excludeSenderKinds:{...t.senderPolicy.excludeSenderKinds}}:{},includeSenderTypes:[...t?.senderPolicy?.includeSenderTypes??K.senderPolicy?.includeSenderTypes??[]],excludeSenderTypes:[...t?.senderPolicy?.excludeSenderTypes??[]],excludeSelf:t?.senderPolicy?.excludeSelf!==!1},messagePolicy:{includeMsgTypes:[...t?.messagePolicy?.includeMsgTypes??K.messagePolicy?.includeMsgTypes??[]],scope:"top_level"}}}function yr(t){return!!t&&t.prompt.trim().length>0}function Pn(t){return t.memberBots.some(n=>n.inChat&&(n.hasRole||n.hasMessageListener))}function Ye(t,n){return t?.name||n}function In(t,n){let r=new Map;for(let o of t??[])r.set(o.messageId,o);for(let o of n)r.set(o.messageId,{...r.get(o.messageId),...o});return[...r.values()]}function Sn(t,n){return!n||t==="failed"?"error":t==="replied"?"ok":t==="running"?"running":"triggered"}function wn(t,n=[]){return ze(t??K)}function xn(){let t=(0,a.useRef)(!0);return(0,a.useEffect)(()=>(t.current=!0,()=>{t.current=!1}),[]),t}function Rn(){let t=(0,a.useRef)(new Set);return(0,a.useEffect)(()=>()=>{for(let n of t.current)window.clearTimeout(n);t.current.clear()},[]),(0,a.useCallback)((n,r)=>{let o=window.setTimeout(()=>{t.current.delete(o),n()},r);return t.current.add(o),o},[])}function Pr(t){return(0,e.jsx)(Bt,{html:Et({name:t.bot.botName,larkAppId:t.bot.larkAppId,avatarUrl:t.bot.botAvatarUrl,size:"sm"})})}function Ir(t){let n=Dt(),r=xn(),o=Rn(),[c,m]=(0,a.useState)([]),[f,p]=(0,a.useState)([]),[v,T]=(0,a.useState)([]),[xe,R]=(0,a.useState)({entriesByProfile:new Map,effectiveRolesByBot:new Map}),[W,A]=(0,a.useState)(!1),[Re,Y]=(0,a.useState)(!0),[ke,_]=(0,a.useState)(!0),[F,k]=(0,a.useState)(""),[z,ge]=(0,a.useState)(""),[U,B]=(0,a.useState)(()=>new Set),[g,ye]=(0,a.useState)(null),[y,J]=(0,a.useState)(null),[d,b]=(0,a.useState)(null),[I,M]=(0,a.useState)(""),[X,Q]=(0,a.useState)("every"),[ve,Z]=(0,a.useState)(!1),[Je,Xe]=(0,a.useState)(!1),[Qe,Ze]=(0,a.useState)(!1),[Sr,et]=(0,a.useState)(!1),[wr,tt]=(0,a.useState)(!1),[xr,Ne]=(0,a.useState)(null),[Rr,rt]=(0,a.useState)(null),[kr,nt]=(0,a.useState)(null),[j,st]=(0,a.useState)("role"),[Nr,Lr]=(0,a.useState)(null),[P,D]=(0,a.useState)(()=>ze(K)),[Le,ot]=(0,a.useState)([]),[Tr,lt]=(0,a.useState)(!1),[Mr,it]=(0,a.useState)(!1),[at,dt]=(0,a.useState)(!1),[Te,ct]=(0,a.useState)(!1),[Cr,G]=(0,a.useState)(null),[Me,Er]=(0,a.useState)(je),[Ar,be]=(0,a.useState)({kind:"idle"}),ee=(0,a.useRef)(null),ut=(0,a.useRef)(0),[S,_r]=(0,a.useState)(null),[C,pt]=(0,a.useState)(null),[te,re]=(0,a.useState)([]),[ne,he]=(0,a.useState)(""),[$,se]=(0,a.useState)(null),[mt,Br]=(0,a.useState)(!1),[ft,gt]=(0,a.useState)(()=>new Set),[yt,vt]=(0,a.useState)(!1),[bt,ht]=(0,a.useState)(!1),[Dr,Ce]=(0,a.useState)(null),[Gr,oe]=(0,a.useState)({kind:"idle"}),H=(0,a.useRef)(0),le=(0,a.useRef)(0),Pt=(0,a.useRef)(null),Ee=g?c.find(s=>s.chatId===g):void 0,Fr=Ee&&y?Ee.memberBots.find(s=>s.larkAppId===y):void 0,Ae=C?f.find(s=>s.larkAppId===C):void 0,$r=me(te,C),_e=$?c.find(s=>s.chatId===$):void 0,Pe=_e?.memberBots.filter(s=>s.inChat)??[],Or=Pe.map(s=>s.larkAppId).join("\0"),Ur=te.map(s=>s.larkAppId).sort().join("\0"),jr=(0,a.useMemo)(()=>Jt(c,F),[c,F]),Hr=(0,a.useMemo)(()=>Xt(v,z),[v,z]),Be=we(I),De=we(ne),It=we(P.prompt),St=(0,a.useMemo)(()=>{let s=new Map;for(let l of Le)s.set(l.openId,l);return s},[Le]),N=(0,a.useCallback)((s,l,i=!1)=>{let u=Date.now()+Math.random();s({text:l,isError:i,id:u}),o(()=>{s(h=>h?.id===u?null:h)},i?3e3:2e3)},[o]),L=(0,a.useCallback)(async(s,l)=>{try{let i=await fr(s,l);if(!r.current)return;R(i),A(!0)}catch{if(!r.current)return;R({entriesByProfile:new Map,effectiveRolesByBot:new Map}),A(!0)}},[r]),E=(0,a.useCallback)(async()=>{let s=await Qt();return r.current&&(m(s.groups),p(s.bots)),s},[r]),ie=(0,a.useCallback)(async()=>{let s=await Zt();return r.current&&T(s),s},[r]),ae=(0,a.useCallback)((s,l=[])=>{let i=wn(s??K,l);Lr(s),D(i)},[]),wt=(0,a.useCallback)(async(s,l,i)=>{lt(!0),it(!0),ot([]);try{let[u,h]=await Promise.all([We(s,l).catch(()=>ze(K)),cr(s,l).catch(()=>[])]);if(!r.current||i!==H.current)return;ae(yr(u)?u:null,h),ot(h),G(null)}finally{r.current&&i===H.current&&(lt(!1),it(!1))}},[r,ae]),xt=(0,a.useCallback)(async()=>{Y(!0),_(!0),A(!1);try{let s=await E();if(!r.current)return;let l=await ie();if(!r.current||(await At(),!r.current))return;if(B(new Set(s.groups.filter(Pn).map(i=>i.chatId))),t.tab==="profiles"){let i=Wt();se(u=>u||(i&&s.groups.some(h=>h.chatId===i)?i:s.groups[0]?.chatId??null))}else se(i=>i??s.groups[0]?.chatId??null);Y(!1),_(!1),L(s.groups,l)}catch{if(!r.current)return;Y(!1),_(!1),A(!0)}},[r,t.tab,E,ie,L]);(0,a.useEffect)(()=>{xt()},[xt]),(0,a.useEffect)(()=>()=>{ut.current+=1,ee.current=null},[]),(0,a.useEffect)(()=>{$||c.length===0||se(c[0].chatId)},[c,$]),(0,a.useEffect)(()=>{let s=new Set(Pe.filter(l=>!!me(te,l.larkAppId)).map(l=>l.larkAppId));gt(s),oe({kind:"idle"})},[Ur,Or]);async function Vr(s,l){let i=++H.current;ye(s),J(l),Ne(null),rt(null),nt(null),G(null),ae(null);let u=await Ke(l,s);!r.current||i!==H.current||(b(u),M(u.content??""),Q(u.injectMode==="once"?"once":"every"),Z(u.dispatchCompletionEnabled===!0),await wt(l,s,i))}async function qr(){let s=await E();if(r.current&&(L(s.groups,v),g&&y)){let l=++H.current,i=await Ke(y,g);if(!r.current||l!==H.current)return;b(i),M(i.content??""),Q(i.injectMode==="once"?"once":"every"),Z(i.dispatchCompletionEnabled===!0),await wt(y,g,l)}}async function Kr(){if(!(!g||!y)){Xe(!0);try{let s=await er(y,g,I,X,ve);if(!r.current)return;if(s){let l=await E();if(!r.current)return;b(i=>i&&{...i,content:I,hasRole:!0,injectMode:X,dispatchCompletionEnabled:ve}),L(l.groups,v),N(Ne,n("roles.saved"))}else N(Ne,I.trim().length===0?n("roles.emptyError"):n("roles.saveFailed"),!0)}finally{r.current&&Xe(!1)}}}async function Wr(){if(!(!g||!y)&&confirm(n("roles.confirmDelete"))){Ze(!0);try{let s=await nr(y,g);if(!r.current)return;if(s){let l=await E();if(!r.current)return;ye(null),J(null),b(null),M(""),Q("every"),Z(!1),L(l.groups,v)}}finally{r.current&&Ze(!1)}}}async function Yr(s){if(!g||!y)return;let l=X;Q(s),et(!0);try{let i=await tr(y,g,s);if(!r.current)return;i||Q(l),N(rt,n(i?"roles.saved":"roles.saveFailed"),!i)}finally{r.current&&et(!1)}}async function zr(s){if(!g||!y)return;let l=ve;Z(s),tt(!0);try{let i=await rr(y,g,s);if(!r.current)return;i||Z(l),N(nt,n(i?"roles.saved":"roles.saveFailed"),!i)}finally{r.current&&tt(!1)}}function Jr(s){D(l=>({...l,...s}))}function Xr(s){D(l=>({...l,senderPolicy:{...l.senderPolicy??{},...s}}))}function Qr(s){D(l=>({...l,messagePolicy:{...l.messagePolicy??{scope:"top_level"},...s,scope:"top_level"}}))}function Zr(s,l){D(i=>{let u=new Set(i.senderPolicy?.includeSenderTypes??[]);if(l)u.add(s);else{if(u.size<=1&&u.has(s))return i;u.delete(s)}return{...i,senderPolicy:{...i.senderPolicy??{},includeSenderTypes:[...u]}}})}function en(s,l){D(i=>{let u=new Set(i.messagePolicy?.includeMsgTypes??[]);if(l)u.add(s);else{if(u.size<=1&&u.has(s))return i;u.delete(s)}return{...i,messagePolicy:{...i.messagePolicy??{scope:"top_level"},includeMsgTypes:[...u],scope:"top_level"}}})}function Rt(s,l){D(i=>{let u=i.senderPolicy?.mode==="all_except_excluded"?"all_except_excluded":"include_only",h=Ht({mode:u,include:i.senderPolicy?.includeSenderOpenIds??[],exclude:i.senderPolicy?.excludeSenderOpenIds??[],targetIds:s,listening:l});return{...i,senderPolicy:{...i.senderPolicy??{},mode:u,includeSenderOpenIds:h.include,excludeSenderOpenIds:h.exclude}}})}function tn(s,l){Rt([s],l)}function rn(s,l){Rt(s,l)}function nn(s){D(l=>({...l,senderPolicy:{...l.senderPolicy??{},mode:s,includeSenderOpenIds:[...l.senderPolicy?.includeSenderOpenIds??[]],excludeSenderOpenIds:[...l.senderPolicy?.excludeSenderOpenIds??[]]}}))}function kt(){let s=P.senderPolicy??{},l=P.messagePolicy??{},i=s.mode==="all_except_excluded"?"all_except_excluded":"include_only",u=[...new Set(s.includeSenderOpenIds??[])].filter(Boolean),h=[...new Set(s.excludeSenderOpenIds??[])].filter(Boolean),de=Vt(h,Ie=>St.get(Ie)?.memberType,s.excludeSenderKinds),w=[...new Set(s.includeSenderTypes??[])].filter(Ie=>Ie==="user"||Ie==="bot"),Ct=[...new Set(l.includeMsgTypes??[])].filter(Boolean);return{enabled:P.enabled,...P.name?.trim()?{name:P.name.trim()}:{},...P.replyCardTitle?.trim()?{replyCardTitle:P.replyCardTitle.trim()}:{},...P.workingDir?.trim()?{workingDir:P.workingDir.trim()}:{},prompt:P.prompt.trim(),senderPolicy:{mode:i,...i==="include_only"&&u.length>0?{includeSenderOpenIds:u}:{},...i==="all_except_excluded"&&h.length>0?{excludeSenderOpenIds:h}:{},...i==="all_except_excluded"&&Object.keys(de).length>0?{excludeSenderKinds:de}:{},...w.length>0?{includeSenderTypes:w}:{},excludeSelf:s.excludeSelf!==!1},messagePolicy:{...Ct.length>0?{includeMsgTypes:Ct}:{},scope:"top_level"}}}function sn(){return P.prompt.trim()?P.senderPolicy?.mode!=="all_except_excluded"&&(P.senderPolicy?.includeSenderOpenIds?.length??0)===0?(N(G,n("roles.listenerSenderRequired"),!0),null):{...kt(),enabled:!0}:(N(G,n("roles.listenerPromptRequired"),!0),null)}async function Nt(s){if(!g||!y)return;let l=sn();if(!l)return;let i=s?"run":"preview";be({kind:"loading",mode:i});try{let u=s?await ar(y,g,l,Me):await ir(y,g,l,Me);if(!r.current)return;be(u.ok?{kind:"result",response:u,mode:i}:{kind:"error",text:u.error||n("roles.listenerPreviewFailed")}),u.ok&&s&&u.runId&&on(u.runId)}catch(u){if(!r.current)return;be({kind:"error",text:u instanceof Error?u.message:n("roles.listenerPreviewFailed")})}}function on(s){if(!g||!y)return;let l=++ut.current;ee.current={runId:s,token:l};let i=async()=>{if(!r.current)return;let u=ee.current;if(!(!u||u.runId!==s||u.token!==l||!g||!y))try{let h=await dr(y,g,s);if(!r.current)return;if(h.ok&&h.results){let de=h.results;be(w=>w.kind!=="result"||w.mode!=="run"||w.response.runId!==s?w:{...w,response:{...w.response,results:In(w.response.results,de)}}),de.some(w=>w.state==="triggered"||w.state==="running")?o(i,1500):ee.current?.runId===s&&(ee.current=null)}}catch{o(i,2500)}};o(i,1500)}async function ln(){if(!(!g||!y)){if(!P.enabled&&!P.prompt.trim()){await Lt(!1);return}if(P.enabled){if(!P.prompt.trim()){N(G,n("roles.listenerPromptRequired"),!0);return}if(P.senderPolicy?.mode!=="all_except_excluded"&&(P.senderPolicy?.includeSenderOpenIds?.length??0)===0){N(G,n("roles.listenerSenderRequired"),!0);return}}dt(!0);try{let s=await sr(y,g,kt());if(!r.current)return;if(s){let l=await E();if(!r.current)return;let i=await We(y,g);if(!r.current)return;ae(yr(i)?i:null),L(l.groups,v)}N(G,n(s?"roles.saved":"roles.saveFailed"),!s)}finally{r.current&&dt(!1)}}}async function Lt(s=!0){if(!(!g||!y)&&!(s&&!confirm(n("roles.listenerConfirmDelete")))){ct(!0);try{let l=await or(y,g);if(!r.current)return;if(l){let i=await E();if(!r.current)return;ae(null),L(i.groups,v)}N(G,n(l?"roles.saved":"roles.saveFailed"),!l)}finally{r.current&&ct(!1)}}}async function Tt(s){let l=s.trim();if(!Ve(l))return;let i=++le.current;_r(l),pt(null),he(""),oe({kind:"idle"}),se(h=>h??c[0]?.chatId??null);let u=await q(l);!r.current||i!==le.current||(re(u),Ce(null))}async function an(s){if(!S)return;let l=++le.current;pt(s);let i=await ur(S,s);if(!r.current||l!==le.current)return;he(i.content??"");let u=await q(S);!r.current||l!==le.current||(re(u),Ce(null))}async function dn(){let s=await E();if(!r.current)return;let l=await ie();if(r.current){if(S){let i=await q(S);if(!r.current)return;re(i)}L(s.groups,l)}}async function cn(){let s=Pt.current,l=s?.value.trim()??"";if(l){if(!Ve(l)){s?.setCustomValidity(n("roles.profileIdInvalid")),s?.reportValidity();return}s?.setCustomValidity(""),await Tt(l),r.current&&(location.hash.startsWith("#/roles/profile")||(location.hash="#/roles/profile"))}}async function un(){if(!(!S||!C)){vt(!0);try{let s=await pr(S,C,ne);if(!r.current)return;let l=await ie();if(!r.current)return;let i=await q(S);if(!r.current)return;re(i),L(c,l),N(Ce,n(s?"roles.saved":"roles.saveFailed"),!s)}finally{r.current&&vt(!1)}}}async function pn(){if(!(!S||!C)&&confirm(n("roles.confirmDeleteProfileEntry"))){ht(!0);try{if(await mr(S,C),!r.current)return;he("");let s=await ie();if(!r.current)return;let l=await q(S);if(!r.current)return;re(l),L(c,s)}finally{r.current&&ht(!1)}}}function mn(s,l){gt(i=>{let u=new Set(i);return l?u.add(s):u.delete(s),u})}async function Mt(s){if(!S)return;let l=$??c[0]?.chatId;if(!l)return;let i=[...ft];if(i.length===0){oe({kind:"text",text:n("roles.applyPickBots")});return}oe({kind:"text",text:"..."});let u=await Promise.all(i.map(h=>gr({profileId:S,chatId:l,larkAppId:h,force:mt,preview:s})));if(r.current&&(oe({kind:"results",preview:s,results:u}),!s)){let h=await E();if(!r.current)return;L(h.groups,v)}}let fn=Je||Be>O||I.trim().length===0,gn=at||Te||It>pe||P.enabled&&P.prompt.trim().length===0,yn=yt||De>O||ne.trim().length===0,V=t.tab==="profiles",vn=(0,e.jsxs)("nav",{className:"roles-subnav insight-tabs",role:"tablist","aria-label":n("roles.title"),children:[(0,e.jsx)("a",{href:"#/roles",className:`itab${V?"":" on"}`,role:"tab","aria-selected":!V,children:n("roles.tabGroups")}),(0,e.jsx)("a",{href:"#/roles/profile",className:`itab${V?" on":""}`,role:"tab","aria-selected":V,children:n("roles.tabProfiles")})]});return(0,e.jsxs)("section",{className:"page roles-page",children:[(0,e.jsxs)("div",{className:"page-heading roles-heading",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:n("nav.roles")}),(0,e.jsx)("h1",{children:n("roles.title")})]}),(0,e.jsx)("div",{className:"page-heading-actions",children:vn})]}),(0,e.jsxs)("div",{id:"roles-by-group-view",className:"roles-layout",hidden:V,children:[(0,e.jsxs)("div",{className:"roles-tree-panel",children:[(0,e.jsxs)("div",{className:"roles-tree-header dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",id:"roles-search",placeholder:n("roles.search"),value:F,onChange:s=>k(s.target.value)}),(0,e.jsx)($e,{id:"roles-refresh",label:n("roles.refresh"),onClick:()=>{qr()}})]}),(0,e.jsx)("div",{id:"roles-tree",className:"roles-tree",children:Re?(0,e.jsx)(ce,{label:n("common.loading")}):(0,e.jsx)(Ln,{groups:jr,profiles:v,context:xe,contextLoaded:W,expandedGroups:U,selectedGroupId:g,selectedBotId:y,tr:n,onToggleGroup:s=>B(l=>kn(l,s)),onSelectBot:(s,l)=>{Vr(s,l)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:!g||!y?(0,e.jsx)("div",{id:"roles-editor-empty",className:"roles-editor-empty",children:n("roles.selectHint")}):(0,e.jsxs)("div",{id:"roles-editor-form",className:"roles-editor-form",children:[(0,e.jsxs)("div",{className:"roles-editor-head",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"roles-editor-breadcrumb",children:[(0,e.jsx)("span",{id:"roles-editor-group-name",children:Ee?.name??g}),(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{id:"roles-editor-bot-name",children:Fr?.botName??y})]}),(0,e.jsx)("div",{className:"roles-editor-meta",children:(0,e.jsxs)("span",{id:"roles-editor-chat-id",className:"roles-editor-meta-line",children:[g," \xB7 ",y]})})]}),(0,e.jsx)("div",{className:"roles-editor-actions roles-editor-head-actions",children:j==="role"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",id:"roles-delete",className:"danger",style:{display:d?.hasRole?"":"none"},disabled:Qe,onClick:()=>{Wr()},children:Qe?"...":n("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-save",className:"primary",disabled:fn,onClick:()=>{Kr()},children:Je?"...":n("roles.save")})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",id:"roles-listener-delete",className:"danger",style:{display:Nr?"":"none"},disabled:Te,onClick:()=>{Lt()},children:Te?"...":n("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-listener-save",className:"primary",disabled:gn,onClick:()=>{ln()},children:at?"...":n("roles.save")})]})})]}),(0,e.jsxs)("div",{className:"roles-editor-switch segmented",role:"tablist","aria-label":n("roles.editorTabs"),children:[(0,e.jsx)("button",{type:"button",className:j==="role"?"active":"","aria-pressed":j==="role",onClick:()=>st("role"),children:n("roles.roleTab")}),(0,e.jsx)("button",{type:"button",className:j==="listener"?"active":"","aria-pressed":j==="listener",onClick:()=>st("listener"),children:n("roles.listenerTab")})]}),j==="role"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"roles-editor-inject",children:[(0,e.jsx)("span",{className:"roles-field-label",children:n("roles.injectModeLabel")}),(0,e.jsx)(Oe,{id:"roles-editor-inject-mode",className:"roles-inline-menu",ariaLabel:n("roles.injectModeLabel"),disabled:Sr,label:n(X==="once"?"roles.injectModeOnce":"roles.injectModeEvery"),value:X,options:[{value:"every",label:n("roles.injectModeEvery")},{value:"once",label:n("roles.injectModeOnce")}],onChange:s=>{Yr(s==="once"?"once":"every")}}),(0,e.jsx)("span",{className:"roles-editor-inject-hint",children:n("roles.injectModeHint")}),(0,e.jsx)(fe,{flash:Rr})]}),(0,e.jsxs)("div",{className:"roles-editor-inject",children:[(0,e.jsx)("span",{className:"roles-field-label",children:n("roles.dispatchCompletionLabel")}),(0,e.jsxs)("label",{className:"filter-toggle roles-listener-enabled",children:[(0,e.jsx)("input",{id:"roles-editor-dispatch-completion-enabled",type:"checkbox",checked:ve,disabled:wr,onChange:s=>{zr(s.currentTarget.checked)}}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"}),(0,e.jsx)("span",{className:"filter-toggle-label",children:n("roles.dispatchCompletionEnabled")})]}),(0,e.jsx)("span",{className:"roles-editor-inject-hint",children:n("roles.dispatchCompletionHint")}),(0,e.jsx)(fe,{flash:kr})]}),(0,e.jsx)("textarea",{id:"roles-editor-textarea",placeholder:n("roles.editorPlaceholder"),rows:14,value:I,onChange:s=>M(s.target.value)}),(0,e.jsxs)("div",{className:"roles-editor-footer",children:[(0,e.jsxs)("span",{id:"roles-editor-bytecount",className:vr(Be),children:[Be," / ",O," bytes"]}),(0,e.jsx)(fe,{flash:xr})]}),(0,e.jsx)(br,{content:I,tr:n,id:"roles-preview"})]}):(0,e.jsx)(Mn,{listener:P,members:Le,memberById:St,promptByteLen:It,loading:Tr,membersLoading:Mr,flash:Cr,tr:n,onPatch:Jr,onSenderPolicyPatch:Xr,onMessagePolicyPatch:Qr,onToggleSenderType:Zr,onToggleMsgType:en,onSetTargetPolicy:tn,onSetTargetsPolicy:rn,onSetSenderMode:nn,previewLimit:Me,previewStatus:Ar,onPreviewLimitChange:Er,onPreview:()=>{Nt(!1)},onRunPreview:()=>{Nt(!0)}})]})})]}),(0,e.jsxs)("div",{id:"roles-profiles-view",className:"roles-layout roles-profiles-layout",hidden:!V,children:[(0,e.jsxs)("div",{className:"roles-tree-panel",children:[(0,e.jsxs)("div",{className:"roles-tree-header roles-profile-create dashboard-toolbar",children:[(0,e.jsx)("input",{type:"text",id:"roles-profile-id",placeholder:n("roles.profileIdPlaceholder"),maxLength:64,ref:Pt,onChange:s=>s.currentTarget.setCustomValidity("")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-select",onClick:()=>{cn()},children:n("roles.openProfile")})]}),(0,e.jsxs)("div",{className:"roles-tree-header dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",id:"roles-profile-search",placeholder:n("roles.profileSearch"),value:z,onChange:s=>ge(s.target.value)}),(0,e.jsx)($e,{id:"roles-profile-refresh",label:n("roles.refresh"),onClick:()=>{dn()}})]}),(0,e.jsx)("div",{id:"roles-profile-list",className:"roles-tree",children:ke?(0,e.jsx)(ce,{label:n("common.loading")}):(0,e.jsx)(An,{profiles:Hr,selectedProfileId:S,tr:n,onSelect:s=>{Tt(s)}})})]}),(0,e.jsx)("div",{className:"roles-editor-panel",children:S?(0,e.jsxs)("div",{id:"roles-profile-detail",className:"roles-editor-form roles-profile-detail",children:[(0,e.jsx)("div",{className:"roles-profile-title",children:(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"roles-editor-breadcrumb",children:[(0,e.jsx)("span",{children:S}),Ae?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"roles-breadcrumb-sep",children:"\u203A"}),(0,e.jsx)("span",{children:Ae.botName??Ae.larkAppId})]}):null]}),(0,e.jsx)("div",{className:"roles-editor-meta-line",children:n("roles.profileRuntimeHint")})]})}),(0,e.jsxs)("div",{className:"roles-profile-grid",children:[(0,e.jsxs)("div",{className:"roles-profile-bots",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:n("roles.profileBots")}),(0,e.jsx)("div",{className:"roles-profile-bot-list",children:f.map(s=>{let l=!!me(te,s.larkAppId),i=C===s.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row roles-profile-bot-row ${i?"selected":""}`,"data-profile-bot-id":s.larkAppId,onClick:()=>{an(s.larkAppId)},children:[(0,e.jsx)(Pr,{bot:s}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:s.botName??s.larkAppId}),(0,e.jsx)("div",{className:"roles-bot-id",children:s.larkAppId})]}),(0,e.jsx)("span",{className:`roles-badge ${l?"has-role":"no-role"}`,children:n(l?"roles.configured":"roles.unconfigured")})]},s.larkAppId)})})]}),(0,e.jsx)("div",{className:"roles-profile-editor",children:C?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"roles-profile-editor-head",children:[(0,e.jsxs)("span",{id:"roles-profile-bytecount",className:vr(De),children:[De," / ",O," bytes"]}),(0,e.jsxs)("div",{className:"roles-editor-actions roles-editor-head-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-profile-delete",className:"danger",style:{display:$r?"":"none"},disabled:bt,onClick:()=>{pn()},children:bt?"...":n("roles.delete")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-save",className:"primary",disabled:yn,onClick:()=>{un()},children:yt?"...":n("roles.saveEntry")})]})]}),(0,e.jsx)("textarea",{id:"roles-profile-textarea",placeholder:n("roles.profileEditorPlaceholder"),rows:12,value:ne,onChange:s=>he(s.target.value)}),(0,e.jsx)("div",{className:"roles-editor-footer",children:(0,e.jsx)(fe,{flash:Dr})}),(0,e.jsx)(br,{content:ne,tr:n,id:"roles-profile-preview"})]}):(0,e.jsx)("div",{className:"roles-editor-empty roles-profile-inline-empty",children:n("roles.profileBotSelectHint")})})]}),(0,e.jsxs)("div",{className:"roles-profile-apply",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:n("roles.applyToGroup")}),(0,e.jsxs)("div",{className:"roles-profile-apply-controls",children:[(0,e.jsx)(Oe,{id:"roles-profile-apply-group",className:"roles-apply-group-menu",ariaLabel:n("roles.applyToGroup"),disabled:c.length===0,label:_e?.name??$??n("roles.noChats"),value:$??"",options:c.map(s=>({value:s.chatId,label:s.name??s.chatId})),onChange:s=>se(s)}),(0,e.jsxs)("label",{className:"roles-profile-force",children:[(0,e.jsx)("input",{type:"checkbox",id:"roles-profile-apply-force",checked:mt,onChange:s=>Br(s.target.checked)})," ",n("roles.applyForce")]})]}),(0,e.jsx)("div",{id:"roles-profile-apply-bots",children:!_e||Pe.length===0?(0,e.jsx)("div",{className:"roles-empty",children:n("roles.noChats")}):Pe.map(s=>{let l=!!me(te,s.larkAppId);return(0,e.jsxs)("label",{className:"checkbox-row roles-profile-apply-bot",children:[(0,e.jsx)("input",{type:"checkbox",name:"profile-apply-bot",value:s.larkAppId,checked:ft.has(s.larkAppId),onChange:i=>mn(s.larkAppId,i.target.checked)}),(0,e.jsx)("span",{children:s.botName??s.larkAppId}),(0,e.jsx)("small",{children:n(l?"roles.configured":"roles.profileMissing")})]},s.larkAppId)})}),(0,e.jsxs)("div",{className:"roles-editor-actions",children:[(0,e.jsx)("button",{type:"button",id:"roles-profile-preview-apply",onClick:()=>{Mt(!0)},children:n("roles.previewApply")}),(0,e.jsx)("button",{type:"button",id:"roles-profile-apply",className:"primary",onClick:()=>{Mt(!1)},children:n("roles.applyProfile")})]}),(0,e.jsx)("div",{id:"roles-profile-apply-status",className:"roles-profile-status",children:(0,e.jsx)(_n,{status:Gr,bots:f,tr:n})})]})]}):(0,e.jsx)("div",{id:"roles-profile-empty",className:"roles-editor-empty",children:n("roles.profileSelectHint")})})]})]})}function kn(t,n){let r=new Set(t);return r.has(n)?r.delete(n):r.add(n),r}function vr(t){return`roles-bytecount ${t>qt?"warn":""} ${t>O?"over":""}`}function Nn(t){return`roles-bytecount ${t>Kt?"warn":""} ${t>pe?"over":""}`}function fe(t){return t.flash?(0,e.jsxs)("span",{className:`roles-saved-flash ${t.flash.isError?"roles-save-error":""}`,children:[" ",t.flash.text]}):null}function Ln(t){let{tr:n}=t;return t.groups.length===0?(0,e.jsx)("div",{className:"roles-empty",children:n("roles.noChats")}):(0,e.jsx)(e.Fragment,{children:t.groups.map(r=>{let o=t.expandedGroups.has(r.chatId),c=r.memberBots.filter(p=>p.inChat),m=Yt(r),f=zt(r);return(0,e.jsxs)("div",{className:"roles-group-section",children:[(0,e.jsxs)("div",{className:`roles-group-row ${o?"expanded":""} ${t.selectedGroupId===r.chatId&&!t.selectedBotId?"selected":""}`,"data-group-id":r.chatId,onClick:()=>t.onToggleGroup(r.chatId),children:[(0,e.jsx)("span",{className:"roles-group-arrow",children:o?"\u25BE":"\u25B8"}),(0,e.jsx)("span",{className:"roles-group-icon","aria-hidden":"true",children:(0,e.jsxs)("svg",{viewBox:"0 0 16 16",children:[(0,e.jsx)("circle",{cx:"5.6",cy:"5.8",r:"2.4"}),(0,e.jsx)("path",{d:"M1.8 13.2c.5-2.4 2-3.6 3.8-3.6s3.3 1.2 3.8 3.6"}),(0,e.jsx)("circle",{cx:"11",cy:"6.8",r:"1.9"}),(0,e.jsx)("path",{d:"M9.8 12.6c.4-1.7 1.5-2.6 2.8-2.6 1 0 1.9.5 2.4 1.6"})]})}),(0,e.jsxs)("div",{className:"roles-group-info",children:[(0,e.jsx)("div",{className:"roles-group-name",children:r.name??r.chatId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[m,"/",f," ",n("roles.botsWithRoles")]}),(0,e.jsx)(Tn,{group:r,profiles:t.profiles,context:t.context,loaded:t.contextLoaded,tr:n})]}),(0,e.jsx)("span",{className:"roles-group-chevron"})]}),(0,e.jsx)("div",{className:"roles-bot-list",children:o?c.map(p=>{let v=t.selectedGroupId===r.chatId&&t.selectedBotId===p.larkAppId;return(0,e.jsxs)("div",{className:`roles-bot-row ${v?"selected":""}`,"data-group-id":r.chatId,"data-bot-id":p.larkAppId,onClick:T=>{T.stopPropagation(),t.onSelectBot(r.chatId,p.larkAppId)},children:[(0,e.jsx)("span",{className:"roles-bot-indent"}),(0,e.jsx)(Pr,{bot:p}),(0,e.jsxs)("div",{className:"roles-bot-info",children:[(0,e.jsx)("div",{className:"roles-bot-name",children:p.botName}),(0,e.jsx)("div",{className:"roles-bot-id",children:p.larkAppId})]}),(0,e.jsxs)("div",{className:"roles-bot-badges",children:[(0,e.jsx)("span",{className:`roles-badge ${p.hasRole?"has-role":"no-role"}`,children:p.hasRole?n("roles.configured"):n("roles.unconfigured")}),p.hasMessageListener?(0,e.jsx)("span",{className:"roles-badge has-listener",children:n("roles.listenerBadge")}):null]})]},p.larkAppId)}):null})]},r.chatId)})})}function Tn(t){let{group:n,profiles:r,context:o,loaded:c,tr:m}=t;if(!r.length||!c)return null;let f=new Map;for(let T of n.memberBots)T.inChat&&f.set(T.larkAppId,o.effectiveRolesByBot.get(qe(T.larkAppId,n.chatId))??null);if(!Gt(f))return null;let p=Ft(n.memberBots,r,o.entriesByProfile,f)[0];if(!p)return(0,e.jsx)("div",{className:"roles-profile-match muted",children:m("groups.profileStatusUnmatched")});let v=p.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`roles-profile-match ${p.kind}`,children:m(v,{name:p.profileId,matched:p.matched,total:p.total,chat:p.chatMatched})})}function Mn(t){let{listener:n,tr:r}=t,[o,c]=(0,a.useState)("members"),[m,f]=(0,a.useState)(""),[p,v]=(0,a.useState)(()=>new Set),T=new Set(n.senderPolicy?.includeSenderTypes??[]),xe=new Set(n.messagePolicy?.includeMsgTypes??[]),R=n.senderPolicy?.mode==="all_except_excluded"?"all_except_excluded":"include_only",W=new Set(n.senderPolicy?.includeSenderOpenIds??[]),A=new Set(n.senderPolicy?.excludeSenderOpenIds??[]),Re=[...[...R==="all_except_excluded"?A:W].filter(d=>!t.memberById.has(d))],Y=[...t.members.filter(d=>d.memberType!=="bot"),...Re.map(d=>({openId:d,name:d,memberType:"unknown"}))],ke=t.members.filter(d=>d.memberType==="bot"),_=o==="bots"?ke:Y,F=jt(_,m),k=F.map(d=>d.openId),z=k.filter(d=>p.has(d)),ge=k.length>0&&z.length===k.length,U=[...p].filter(d=>_.some(b=>b.openId===d)),B=U.length>0?U:k,g=Ue({mode:R,include:[...W],exclude:[...A],targetIds:B});(0,a.useEffect)(()=>{f(""),v(new Set)},[o]),(0,a.useEffect)(()=>{let d=new Set(_.map(b=>b.openId));v(b=>{let I=new Set([...b].filter(M=>d.has(M)));return I.size===b.size?b:I})},[_]);let ye=(d,b)=>{v(I=>{let M=new Set(I);return b?M.add(d):M.delete(d),M})},y=()=>{v(d=>{let b=new Set(d);if(ge)for(let I of k)b.delete(I);else for(let I of k)b.add(I);return b})},J=d=>{B.length!==0&&t.onSetTargetsPolicy(B,d)};return(0,e.jsxs)("div",{className:"roles-listener-editor",children:[t.loading?(0,e.jsx)(ce,{label:r("common.loading")}):null,(0,e.jsxs)("label",{className:"filter-toggle roles-listener-enabled",children:[(0,e.jsx)("input",{type:"checkbox",checked:n.enabled,onChange:d=>t.onPatch({enabled:d.currentTarget.checked})}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"}),(0,e.jsx)("span",{className:"filter-toggle-label",children:r("roles.listenerEnabled")})]}),(0,e.jsx)("p",{className:"roles-listener-scope-help",children:r("roles.listenerScopeHelp")}),(0,e.jsxs)("div",{className:"roles-listener-grid",children:[(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerName")}),(0,e.jsx)("input",{type:"text",value:n.name??"",placeholder:r("roles.listenerNamePlaceholder"),onChange:d=>t.onPatch({name:d.currentTarget.value})})]}),(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerReplyCardTitle")}),(0,e.jsx)("input",{type:"text",value:n.replyCardTitle??"",placeholder:r("roles.listenerReplyCardTitlePlaceholder"),onChange:d=>t.onPatch({replyCardTitle:d.currentTarget.value})})]}),(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerWorkingDir")}),(0,e.jsx)("input",{type:"text",value:n.workingDir??"",placeholder:r("roles.listenerWorkingDirPlaceholder"),onChange:d=>t.onPatch({workingDir:d.currentTarget.value})})]})]}),(0,e.jsxs)("div",{className:"roles-listener-policy-row",children:[(0,e.jsxs)("div",{className:"roles-listener-policy",children:[(0,e.jsx)("div",{className:"roles-field-label",children:r("roles.listenerSenderTypes")}),(0,e.jsxs)("label",{className:"roles-listener-chip",children:[(0,e.jsx)("input",{type:"checkbox",checked:T.has("user"),onChange:d=>t.onToggleSenderType("user",d.currentTarget.checked)}),(0,e.jsx)("span",{children:r("roles.listenerSenderUser")})]}),(0,e.jsxs)("label",{className:"roles-listener-chip",children:[(0,e.jsx)("input",{type:"checkbox",checked:T.has("bot"),onChange:d=>t.onToggleSenderType("bot",d.currentTarget.checked)}),(0,e.jsx)("span",{children:r("roles.listenerSenderBot")})]})]}),(0,e.jsxs)("div",{className:"roles-listener-policy",children:[(0,e.jsx)("div",{className:"roles-field-label",children:r("roles.listenerMessageTypes")}),hr.map(d=>(0,e.jsxs)("label",{className:"roles-listener-chip",children:[(0,e.jsx)("input",{type:"checkbox",checked:xe.has(d),onChange:b=>t.onToggleMsgType(d,b.currentTarget.checked)}),(0,e.jsx)("span",{children:d})]},d))]}),(0,e.jsxs)("label",{className:"roles-listener-checkbox",children:[(0,e.jsx)("input",{type:"checkbox",checked:n.senderPolicy?.excludeSelf!==!1,onChange:d=>t.onSenderPolicyPatch({excludeSelf:d.currentTarget.checked})}),(0,e.jsx)("span",{children:r("roles.listenerExcludeSelf")})]})]}),(0,e.jsx)("div",{className:"roles-listener-policy-row",children:(0,e.jsxs)("div",{className:"roles-listener-policy",children:[(0,e.jsx)("div",{className:"roles-field-label",children:r("roles.listenerSenderMode")}),(0,e.jsxs)("div",{className:"roles-listener-target-tabs segmented",role:"tablist","aria-label":r("roles.listenerSenderMode"),children:[(0,e.jsx)("button",{type:"button",className:R==="include_only"?"active":"","aria-pressed":R==="include_only",onClick:()=>t.onSetSenderMode("include_only"),children:r("roles.listenerSenderModeInclude")}),(0,e.jsx)("button",{type:"button",className:R==="all_except_excluded"?"active":"","aria-pressed":R==="all_except_excluded",onClick:()=>t.onSetSenderMode("all_except_excluded"),children:r("roles.listenerSenderModeAllExcept")})]}),(0,e.jsx)("small",{className:"roles-listener-scope-help",children:r(R==="all_except_excluded"?"roles.listenerSenderModeAllExceptHelp":"roles.listenerSenderModeIncludeHelp")})]})}),(0,e.jsxs)("label",{className:"roles-listener-field",children:[(0,e.jsx)("span",{className:"roles-field-label",children:r("roles.listenerPrompt")}),(0,e.jsx)("textarea",{id:"roles-listener-prompt",placeholder:r("roles.listenerPromptPlaceholder"),rows:9,value:n.prompt,onChange:d=>t.onPatch({prompt:d.currentTarget.value})})]}),(0,e.jsxs)("div",{className:"roles-editor-footer",children:[(0,e.jsxs)("span",{id:"roles-listener-bytecount",className:Nn(t.promptByteLen),children:[t.promptByteLen," / ",pe," bytes"]}),(0,e.jsx)(fe,{flash:t.flash})]}),(0,e.jsxs)("div",{className:"roles-listener-preview-panel",children:[(0,e.jsxs)("div",{className:"roles-listener-preview-head",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:r("roles.listenerPreviewTitle")}),(0,e.jsx)("small",{children:r("roles.listenerPreviewHint")})]}),(0,e.jsxs)("div",{className:"roles-listener-preview-actions",children:[(0,e.jsxs)("label",{children:[(0,e.jsx)("span",{children:r("roles.listenerPreviewCount")}),(0,e.jsx)("select",{value:t.previewLimit,onChange:d=>t.onPreviewLimitChange(Number(d.currentTarget.value)),children:Array.from({length:He},(d,b)=>b+1).map(d=>(0,e.jsx)("option",{value:d,children:d},d))})]}),(0,e.jsx)("button",{type:"button",onClick:t.onPreview,disabled:t.previewStatus.kind==="loading",children:t.previewStatus.kind==="loading"&&t.previewStatus.mode==="preview"?"...":r("roles.listenerPreviewButton")}),(0,e.jsx)("button",{type:"button",className:"primary",onClick:t.onRunPreview,disabled:t.previewStatus.kind==="loading",children:t.previewStatus.kind==="loading"&&t.previewStatus.mode==="run"?"...":r("roles.listenerRunPreviewButton")})]})]}),(0,e.jsx)(Cn,{status:t.previewStatus,tr:r})]}),(0,e.jsxs)("div",{className:"roles-listener-members",children:[(0,e.jsxs)("div",{className:"roles-listener-members-head",children:[(0,e.jsx)("div",{className:"roles-profile-section-title",children:r("roles.listenerFilters")}),(0,e.jsx)("small",{children:t.membersLoading?r("common.loading"):r("roles.listenerMembersHint")})]}),(0,e.jsxs)("div",{className:"roles-listener-target-tabs segmented",role:"tablist","aria-label":r("roles.listenerFilters"),children:[(0,e.jsx)("button",{type:"button",className:o==="members"?"active":"","aria-pressed":o==="members",onClick:()=>c("members"),children:r("roles.listenerMembers")}),(0,e.jsx)("button",{type:"button",className:o==="bots"?"active":"","aria-pressed":o==="bots",onClick:()=>c("bots"),children:r("roles.listenerBots")})]}),(0,e.jsxs)("div",{className:"roles-listener-filter-toolbar",children:[(0,e.jsx)("input",{type:"search",value:m,placeholder:r("roles.listenerSearchPlaceholder"),onChange:d=>f(d.currentTarget.value)}),m?(0,e.jsx)("button",{type:"button",className:"roles-listener-clear-search",onClick:()=>f(""),"aria-label":r("roles.listenerClearSearch"),children:"\xD7"}):null,(0,e.jsx)("button",{type:"button",className:"roles-listener-select-all",disabled:k.length===0,onClick:y,children:r(ge?"roles.listenerClearVisible":"roles.listenerSelectVisible",{count:k.length})})]}),(0,e.jsxs)("div",{className:"roles-listener-bulkbar",children:[(0,e.jsxs)("span",{children:[U.length>0?r("roles.listenerSelectedCount",{count:U.length}):r("roles.listenerFilteredCount",{count:k.length}),g==="mixed"?` \xB7 ${r("roles.listenerMixedMode")}`:""]}),(0,e.jsxs)("div",{className:"roles-listener-member-actions",role:"group","aria-label":r("roles.listenerBulkActions"),children:[(0,e.jsx)("button",{type:"button",className:g==="listen"?"active":"","aria-pressed":g==="listen",disabled:B.length===0,onClick:()=>J(!0),children:r("roles.listenerTargetListen")}),(0,e.jsx)("button",{type:"button",className:g==="ignore"?"active":"","aria-pressed":g==="ignore",disabled:B.length===0,onClick:()=>J(!1),children:r("roles.listenerTargetIgnore")})]})]}),(0,e.jsx)("div",{className:"roles-listener-member-list",children:F.length===0?(0,e.jsx)("div",{className:"roles-empty",children:r(o==="bots"?"roles.listenerBotsEmpty":"roles.listenerMembersEmpty")}):F.map(d=>{let b=Ue({mode:R,include:[...W],exclude:[...A],targetIds:[d.openId]});return(0,e.jsxs)("div",{className:"roles-listener-member",children:[(0,e.jsx)("label",{className:"roles-listener-member-select","aria-label":Ye(d,d.openId),children:(0,e.jsx)("input",{type:"checkbox",checked:p.has(d.openId),onChange:I=>ye(d.openId,I.currentTarget.checked)})}),(0,e.jsxs)("div",{className:"roles-listener-member-main",children:[(0,e.jsx)("strong",{children:Ye(d,d.openId)}),(0,e.jsx)("span",{children:d.openId})]}),(0,e.jsxs)("div",{className:"roles-listener-member-actions",role:"group","aria-label":Ye(d,d.openId),children:[(0,e.jsx)("button",{type:"button",className:b==="listen"?"active":"","aria-pressed":b==="listen",onClick:()=>t.onSetTargetPolicy(d.openId,!0),children:r("roles.listenerTargetListen")}),(0,e.jsx)("button",{type:"button",className:b==="ignore"?"active":"","aria-pressed":b==="ignore",onClick:()=>t.onSetTargetPolicy(d.openId,!1),children:r("roles.listenerTargetIgnore")})]})]},d.openId)})})]})]})}function br(t){return(0,e.jsx)("div",{id:t.id,className:"roles-preview",children:t.content.trim()?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("strong",{children:t.tr("roles.preview")}),(0,e.jsx)("pre",{children:t.content})]}):(0,e.jsx)("small",{children:t.tr("roles.previewEmpty")})})}function Cn(t){let{status:n,tr:r}=t;if(n.kind==="idle")return(0,e.jsx)("div",{className:"roles-listener-preview-empty",children:r("roles.listenerPreviewEmpty")});if(n.kind==="loading")return(0,e.jsx)(ce,{label:r("common.loading")});if(n.kind==="error")return(0,e.jsx)("div",{className:"roles-listener-preview-error",children:n.text});let o=n.response.matches??[],m=(n.response.results??[]).reduce((f,p)=>{let v=p.ok?p.state??"triggered":"failed";return f[v]=(f[v]??0)+1,f},{});return(0,e.jsxs)("div",{className:"roles-listener-preview-results",children:[(0,e.jsx)("div",{className:"roles-listener-preview-summary",children:n.mode==="run"?r("roles.listenerRunPreviewSummary",{count:o.length,triggered:m.triggered??0,running:m.running??0,replied:m.replied??0,failed:m.failed??0}):r("roles.listenerPreviewSummary",{count:o.length})}),o.length===0?(0,e.jsx)("div",{className:"roles-listener-preview-empty",children:r("roles.listenerPreviewNoMatches")}):(0,e.jsx)("div",{className:"roles-listener-preview-list",children:o.map(f=>(0,e.jsx)(En,{item:f,result:n.response.results?.find(p=>p.messageId===f.messageId),tr:r},f.messageId))})]})}function En(t){let n=t.item.messageText.length>300?`${t.item.messageText.slice(0,300)}...`:t.item.messageText,r=t.item.senderName||t.item.senderOpenId||t.item.senderType,o=lr(t.item.createTime);return(0,e.jsxs)("div",{className:"roles-listener-preview-item",children:[(0,e.jsxs)("div",{className:"roles-listener-preview-meta",children:[(0,e.jsx)("span",{children:t.item.msgType}),(0,e.jsx)("span",{children:t.item.senderType}),t.item.senderOpenId?(0,e.jsx)("span",{children:t.item.senderOpenId}):null,(0,e.jsx)("span",{children:t.item.messageId}),t.result?(0,e.jsx)("span",{className:Sn(t.result.state,t.result.ok),children:t.tr(`roles.listenerRunPreviewState.${t.result.ok?t.result.state??"triggered":"failed"}`)}):null]}),t.result?.sessionId||t.result?.replyMessageId||t.result?.error?(0,e.jsxs)("div",{className:"roles-listener-preview-run-detail",children:[t.result.sessionId?(0,e.jsx)("span",{children:t.result.sessionId}):null,t.result.replyMessageId?(0,e.jsx)("span",{children:t.result.replyMessageId}):null,t.result.error?(0,e.jsx)("strong",{children:t.result.error}):null]}):null,(0,e.jsxs)("div",{className:"roles-listener-preview-sender",children:[(0,e.jsx)("span",{children:t.tr("roles.listenerPreviewSender")}),(0,e.jsx)("strong",{children:r})]}),o?(0,e.jsxs)("div",{className:"roles-listener-preview-time",children:[(0,e.jsx)("span",{children:t.tr("roles.listenerPreviewTime")}),(0,e.jsx)("strong",{children:o})]}):null,t.item.messageTitle?(0,e.jsxs)("div",{className:"roles-listener-preview-title",children:[(0,e.jsx)("span",{children:t.tr("roles.listenerPreviewMessageTitle")}),(0,e.jsx)("strong",{children:t.item.messageTitle})]}):null,(0,e.jsx)("div",{className:"roles-listener-preview-content-label",children:t.tr("roles.listenerPreviewContent")}),(0,e.jsx)("pre",{children:n})]})}function An(t){let{tr:n}=t;return t.profiles.length===0?(0,e.jsx)("div",{className:"roles-empty",children:n("roles.profileEmpty")}):(0,e.jsx)(e.Fragment,{children:t.profiles.map(r=>{let o=t.selectedProfileId===r.profileId,c=(r.botEntries??[]).some(m=>m.hasEntry);return(0,e.jsxs)("div",{className:`roles-profile-row ${o?"selected":""}`,"data-profile-id":r.profileId,onClick:()=>t.onSelect(r.profileId),children:[(0,e.jsxs)("div",{className:"roles-profile-row-main",children:[(0,e.jsx)("div",{className:"roles-profile-name",children:r.profileId}),(0,e.jsxs)("div",{className:"roles-group-meta",children:[r.entryCount," ",n("roles.profileEntries")]})]}),(0,e.jsx)("span",{className:`roles-badge ${c?"has-role":"no-role"}`,children:n(c?"roles.configured":"roles.profileMissing")})]},r.profileId)})})}function _n(t){let{status:n,bots:r,tr:o}=t;return n.kind==="idle"?null:n.kind==="text"?(0,e.jsx)(e.Fragment,{children:n.text}):(0,e.jsx)(e.Fragment,{children:n.results.map(c=>{let f=r.find(v=>v.larkAppId===c.larkAppId)?.botName??c.larkAppId,p=c.ok?n.preview?c.wouldRefuse?o("roles.applyWouldRefuse"):o("roles.applyPreviewOk"):o("roles.applyOk"):`${o("roles.applyFailed")}: ${String(c.error??`HTTP ${c.status}`)}`;return(0,e.jsxs)("div",{children:[f,": ",p]},c.larkAppId)})})}function qn(t){return Fe(t,(0,e.jsx)(Ir,{tab:"groups"}))}function Kn(t){return Fe(t,(0,e.jsx)(Ir,{tab:"profiles"}))}export{Kn as renderRoleProfilesPage,qn as renderRolesPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as G,c as F}from"./chunk-KOPISPHN.js";import{g as _,m as B,n as K,o as U,p as j,q as J}from"./chunk-5CJMHTT4.js";import{D as H,G as M}from"./chunk-M6BHWQFO.js";import{a as q}from"./chunk-SYC6D5XU.js";import{a as Q,d as Z}from"./chunk-5THX4DI2.js";import{c as L}from"./chunk-7SZRL6FY.js";var a=L(Q(),1);var e=L(Z(),1),W=1e3;function V(t,l){if(!t)return"\u2014";try{return new Date(t).toLocaleString(void 0,l?{timeZone:l,timeZoneName:"short"}:void 0)}catch{return t}}function X(t,l){let n=l.q.toLowerCase();return t.filter(o=>!l.kind||o.parsed?.kind===l.kind).filter(o=>!l.enabledOnly||o.enabled).filter(o=>!n||JSON.stringify(o).toLowerCase().includes(n)).sort((o,r)=>{if(o.enabled!==r.enabled)return o.enabled?-1:1;let w=o.nextRunAt?Date.parse(o.nextRunAt):1/0,p=r.nextRunAt?Date.parse(r.nextRunAt):1/0;return w-p})}function O(t){return t.deliver==="local"?"local":t.executionPosition==="new-topic"?"new-topic":t.executionPosition==="topic"?t.rootMessageId?"thread":"chat":t.executionPosition==="top-level"?"chat":t.deliver==="new-topic"?"new-topic":t.scope==="chat"?"chat":t.rootMessageId?"thread":"chat"}function Y(t,l){let n=O(t);return l(n==="local"?"schedules.deliveryLocal":n==="new-topic"?"schedules.deliveryNewTopic":n==="thread"?"schedules.deliveryThread":"schedules.deliveryTopLevel")}function ee(t){return t.repeat?`${t.repeat.completed}/${t.repeat.times??"\u221E"}`:"\u2014"}function le(t){return new Promise(l=>window.setTimeout(l,t))}function te(t){let{schedule:l,scheduleTimeZone:n,tr:o}=t,r=M(l),w=String(l.parsed?.kind??"unknown"),p=l.enabled?"pause":"resume",N=`${l.id}:${p}`,b=`${l.id}:run`;return(0,e.jsxs)(K,{kind:"schedule",className:"schedule-list-row","data-id":l.id,children:[(0,e.jsxs)(U,{children:[(0,e.jsxs)("div",{className:"schedule-row-head",children:[(0,e.jsx)("b",{children:l.name??l.id}),(0,e.jsx)("span",{className:`schedule-state ${l.enabled?"enabled":"paused"}`,children:l.enabled?o("schedules.enabled"):o("schedules.paused")})]}),(0,e.jsxs)("div",{className:"schedule-row-meta",children:[(0,e.jsx)("span",{children:l.botName??l.larkAppId??"-"}),(0,e.jsx)("span",{children:"\xB7"}),(0,e.jsx)("code",{children:l.parsed?.display??"?"})]}),(0,e.jsxs)("div",{className:"schedule-chip-strip",children:[(0,e.jsx)("span",{children:w}),l.chatId?(0,e.jsxs)("span",{className:"schedule-chat-chip",title:r?`${r} \xB7 ${String(l.chatId)}`:String(l.chatId),children:[o("schedules.form.chat"),": ",r??l.chatId]}):null,(0,e.jsxs)("span",{children:[o("schedules.delivery"),": ",Y(l,o)]}),l.silent?(0,e.jsxs)("span",{children:["\u{1F507} ",o("schedules.silent")]}):null,(0,e.jsxs)("span",{children:[o("schedules.next"),": ",V(l.nextRunAt,n)]}),(0,e.jsxs)("span",{children:[o("schedules.last"),": ",V(l.lastRunAt,n)]}),l.lastStatus==="error"?(0,e.jsxs)("span",{className:"schedule-error-chip",title:typeof l.lastError=="string"?l.lastError:void 0,children:["\u26A0 ",o("schedules.error"),": ",typeof l.lastError=="string"&&l.lastError.length>60?l.lastError.slice(0,60)+"\u2026":l.lastError??o("schedules.errorUnknown")]}):null,(0,e.jsxs)("span",{children:[o("schedules.repeat"),": ",ee(l)]})]})]}),(0,e.jsx)(j,{children:(0,e.jsxs)("div",{className:"schedule-actions",children:[(0,e.jsx)(oe,{op:"run",label:o("schedules.runNow"),pending:t.pending===b,feedback:t.feedback[b]??null,onClick:()=>t.onAction(l.id,"run")}),(0,e.jsx)(ce,{checked:!!l.enabled,pending:t.pending===N,feedback:t.feedback[N]??null,tr:o,onClick:()=>t.onAction(l.id,p)}),(0,e.jsx)("button",{type:"button",className:"schedule-action-button schedule-edit-button",onClick:()=>t.onEdit(l),title:o("schedules.edit"),children:(0,e.jsx)("span",{className:"schedule-action-label",children:o("schedules.edit")})}),(0,e.jsx)("button",{type:"button",className:"schedule-action-button schedule-delete-button",onClick:()=>t.onDelete(l),title:o("schedules.delete"),children:(0,e.jsx)("span",{className:"schedule-action-label",children:o("schedules.delete")})})]})})]})}function se(){let t=F(),{scheduleRows:l,scheduleTimeZone:n}=G(s=>({scheduleRows:[...s.schedules.values()],scheduleTimeZone:s.scheduleTimeZone})),[o,r]=(0,a.useState)({q:"",kind:"",enabledOnly:!1}),[w,p]=(0,a.useState)(null),[N,b]=(0,a.useState)({}),k=(0,a.useRef)(new Map),[P,y]=(0,a.useState)(!1),[u,T]=(0,a.useState)(null),[S,A]=(0,a.useState)(null),[C,E]=(0,a.useState)([]),[,I]=(0,a.useState)(0);(0,a.useEffect)(()=>{fetch("/api/bots").then(s=>s.json()).then(s=>{Array.isArray(s?.bots)&&E(s.bots)}).catch(()=>{})},[]),(0,a.useEffect)(()=>{H().then(()=>I(s=>s+1))},[]);let R=(0,a.useMemo)(()=>X(l,o),[l,o]);(0,a.useEffect)(()=>()=>{k.current.forEach(s=>window.clearTimeout(s)),k.current.clear()},[]);function m(s,c){b(f=>({...f,[s]:c}));let d=k.current.get(s);d&&window.clearTimeout(d);let v=window.setTimeout(()=>{b(f=>{let h={...f};return delete h[s],h}),k.current.delete(s)},c==="success"?1600:2200);k.current.set(s,v)}async function x(s,c){let d=`${s}:${c}`,v=performance.now(),f="success";p(d);try{let h=await fetch(`/api/schedules/${encodeURIComponent(s)}/${c}`,{method:"POST"}),D=await h.json().catch(()=>({}));if(!h.ok||D.ok===!1)throw new Error(`Failed: ${h.status} ${D?.error??""}`.trim())}catch{f="error"}finally{if(c==="run"){let h=W-(performance.now()-v);h>0&&await le(h)}m(d,f),p(h=>h===d?null:h)}}function g(){T(null),A(null),y(!0)}function $(s){T(s),A(null),y(!0)}async function i(s){if(!window.confirm(t("schedules.deleteConfirm")))return;let c=`${s.id}:delete`;p(c);try{let d=await fetch(`/api/schedules/${encodeURIComponent(s.id)}`,{method:"DELETE"}),v=await d.json().catch(()=>({}));if(!d.ok||v.ok===!1)throw new Error(v?.error??`HTTP ${d.status}`);m(c,"success")}catch{m(c,"error")}finally{p(d=>d===c?null:d)}}async function z(s){A(null);try{let c=u?`/api/schedules/${encodeURIComponent(u.id)}`:"/api/schedules",d=u?"PATCH":"POST",v=u?{name:s.name,schedule:s.schedule,prompt:s.prompt,silent:s.silent,...s.updateExecutionPosition?{executionPosition:s.executionPosition,rootMessageId:s.rootMessageId,topicTitle:s.topicTitle}:{}}:{name:s.name,schedule:s.schedule,prompt:s.prompt,silent:s.silent,executionPosition:s.executionPosition,rootMessageId:s.rootMessageId,topicTitle:s.topicTitle,chatId:s.chatId,larkAppId:s.larkAppId},f=await fetch(c,{method:d,headers:{"Content-Type":"application/json"},body:JSON.stringify(v)}),h=await f.json().catch(()=>({}));if(!f.ok||h.ok===!1)throw new Error(h?.error??`HTTP ${f.status}`);y(!1)}catch(c){A(c instanceof Error?c.message:String(c))}}return(0,e.jsxs)("section",{className:"page schedules-page",children:[(0,e.jsxs)("div",{className:"page-heading",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:t("nav.schedules")}),(0,e.jsx)("h1",{children:t("schedules.title")})]}),(0,e.jsx)(_,{onClick:g,disabled:C.length===0,children:t("schedules.create")})]}),(0,e.jsxs)("form",{id:"sched-filters",className:"filters dashboard-toolbar",children:[(0,e.jsx)("input",{type:"search",name:"q",placeholder:t("schedules.search"),value:o.q,onChange:s=>{let c=s.currentTarget.value;r(d=>({...d,q:c}))}}),(0,e.jsx)(J,{id:"sched-kind-menu",ariaLabel:t("schedules.anyKind"),label:o.kind||t("schedules.anyKind"),value:o.kind,options:[{value:"",label:t("schedules.anyKind")},{value:"cron",label:"cron"},{value:"interval",label:"interval"},{value:"once",label:"once"}],onChange:s=>r(c=>({...c,kind:s}))}),(0,e.jsxs)("label",{className:"filter-toggle",children:[(0,e.jsx)("input",{type:"checkbox",name:"enabled",checked:o.enabledOnly,onChange:s=>{let c=s.currentTarget.checked;r(d=>({...d,enabledOnly:c}))}}),(0,e.jsx)("span",{className:"filter-toggle-label",children:t("schedules.enabledOnly")}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"})]}),(0,e.jsx)("span",{className:"schedules-toolbar-spacer","aria-hidden":"true"}),(0,e.jsxs)("span",{className:"schedules-toolbar-count",children:[R.length,"/",l.length]})]}),(0,e.jsx)("section",{className:"overview-block schedules-list-section",children:(0,e.jsx)("div",{className:"schedules-list-wrap",children:R.length===0?(0,e.jsx)("div",{id:"schedules-tbody",className:"empty schedules-list-empty",children:t("schedules.empty")}):(0,e.jsx)(B,{id:"schedules-tbody",className:"schedules-list",children:R.map(s=>(0,e.jsx)(te,{schedule:s,scheduleTimeZone:n,pending:w,feedback:N,tr:t,onAction:(c,d)=>{x(c,d)},onEdit:$,onDelete:c=>{i(c)}},s.id))})})}),P?(0,e.jsx)(ae,{editing:u,error:S,bots:C,tr:t,onClose:()=>y(!1),onSubmit:s=>{z(s)}}):null]})}function ne(t,l,n,o,r){return n?r(t==="run"?"schedules.running":"schedules.saving"):o==="success"?r(t==="run"?"schedules.runDone":"schedules.saved"):o==="error"?r("schedules.failed"):l}function oe(t){let l=F(),n=t.feedback?` is-${t.feedback}`:"";return(0,e.jsx)("button",{type:"button",className:`schedule-action-button${t.pending?" is-pending":""}${n}`,"data-op":t.op,disabled:t.pending,onClick:t.onClick,children:(0,e.jsx)("span",{className:"schedule-action-label",children:ne(t.op,t.label,t.pending,t.feedback,l)})})}function ce(t){let l=t.feedback==="error"?t.tr("schedules.failed"):t.checked?t.tr("schedules.enabled"):t.tr("schedules.paused");return(0,e.jsxs)("button",{type:"button",className:`schedule-enabled-switch${t.checked?" is-on":""}${t.pending?" is-pending":""}${t.feedback?` is-${t.feedback}`:""}`,"aria-pressed":t.checked,disabled:t.pending,onClick:t.onClick,children:[(0,e.jsx)("span",{className:"schedule-enabled-switch-label",children:l}),(0,e.jsx)("span",{className:"schedule-enabled-switch-track","aria-hidden":"true",children:(0,e.jsx)("span",{})})]})}function he(t){return q(t,(0,e.jsx)(se,{}))}function ae(t){let{editing:l,tr:n,bots:o}=t,[r,w]=(0,a.useState)(l?.name??""),[p,N]=(0,a.useState)(l?.schedule??""),[b,k]=(0,a.useState)(l?.prompt??""),[P,y]=(0,a.useState)(l?.silent===!0),[u,T]=(0,a.useState)(l&&O(l)==="thread"?"topic":l&&O(l)==="new-topic"?"new-topic":"top-level"),[S,A]=(0,a.useState)(l?.rootMessageId??""),[C,E]=(0,a.useState)(l?.topicTitle??""),[I,R]=(0,a.useState)(l?.chatId??""),[m,x]=(0,a.useState)(l?.larkAppId??o[0]?.larkAppId??""),g=l?.deliver==="local";(0,a.useEffect)(()=>{!l&&!m&&o.length>0&&x(o[0].larkAppId)},[l,m,o]);function $(i){i.preventDefault(),!(!l&&!m)&&(!g&&u==="topic"&&!S.trim()||t.onSubmit({name:r,schedule:p,prompt:b,silent:P,executionPosition:u,rootMessageId:S.trim(),topicTitle:C.trim(),updateExecutionPosition:!g,chatId:I,larkAppId:m}))}return(0,e.jsx)("div",{className:"schedule-form-overlay",onClick:t.onClose,children:(0,e.jsxs)("div",{className:"schedule-form-dialog",role:"dialog","aria-modal":"true",onClick:i=>i.stopPropagation(),children:[(0,e.jsx)("h2",{children:n(l?"schedules.edit":"schedules.create")}),(0,e.jsxs)("form",{onSubmit:$,className:"schedule-form",children:[l?null:(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.bot")}),(0,e.jsx)("select",{value:m,onChange:i=>x(i.target.value),required:!0,children:o.map(i=>(0,e.jsx)("option",{value:i.larkAppId,children:i.botName??i.larkAppId},i.larkAppId))})]}),(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.name")}),(0,e.jsx)("input",{type:"text",value:r,onChange:i=>w(i.target.value),required:!0,autoFocus:!0})]}),(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.schedule")}),(0,e.jsx)("input",{type:"text",value:p,onChange:i=>N(i.target.value),placeholder:n("schedules.form.scheduleHelp"),required:!0}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.scheduleHelp")})]}),(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.prompt")}),(0,e.jsx)("textarea",{value:b,onChange:i=>k(i.target.value),rows:4,required:!0}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.promptHelp")})]}),l?(0,e.jsxs)("div",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.chat")}),(0,e.jsx)("code",{title:I,children:M(l)??I})]}):(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.chat")}),(0,e.jsx)("input",{type:"text",value:I,onChange:i=>R(i.target.value),placeholder:"oc_...",required:!0})]}),g?(0,e.jsxs)("div",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.deliver")}),(0,e.jsxs)("div",{className:"schedule-form-placement",children:[(0,e.jsx)("strong",{children:n("schedules.deliveryLocal")}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.localHelp")})]})]}):(0,e.jsxs)("div",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.deliver")}),(0,e.jsxs)("div",{className:"schedule-form-radio-group",children:[(0,e.jsxs)("label",{children:[(0,e.jsx)("input",{type:"radio",name:"executionPosition",value:"top-level",checked:u==="top-level",onChange:()=>T("top-level")}),n("schedules.deliveryTopLevel")]}),(0,e.jsxs)("label",{children:[(0,e.jsx)("input",{type:"radio",name:"executionPosition",value:"topic",checked:u==="topic",onChange:()=>T("topic")}),n("schedules.deliveryThread")]}),(0,e.jsxs)("label",{children:[(0,e.jsx)("input",{type:"radio",name:"executionPosition",value:"new-topic",checked:u==="new-topic",onChange:()=>{T("new-topic"),y(!1)}}),n("schedules.deliveryNewTopic")]})]}),(0,e.jsx)("small",{className:"schedule-form-help",children:n(u==="top-level"?"schedules.form.topLevelHelp":u==="topic"?"schedules.form.topicHelp":"schedules.form.newTopicHelp")})]}),!g&&u==="topic"?(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.topicRoot")}),(0,e.jsx)("input",{type:"text",value:S,onChange:i=>A(i.target.value),placeholder:"om_...",required:!0}),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.topicRootHelp")})]}):null,!g&&u==="new-topic"?(0,e.jsxs)("label",{className:"schedule-form-field",children:[(0,e.jsx)("span",{className:"schedule-form-label",children:n("schedules.form.topicTitle")}),(0,e.jsx)("input",{type:"text",value:C,onChange:i=>E(i.target.value),placeholder:n("schedules.form.topicTitlePlaceholder"),maxLength:200}),(0,e.jsxs)("small",{className:"schedule-form-help schedule-form-help-with-count",children:[n("schedules.form.topicTitleHelp"),(0,e.jsxs)("span",{children:[Array.from(C).length,"/200"]})]})]}):null,(0,e.jsxs)("label",{className:"schedule-form-field schedule-form-toggle",children:[(0,e.jsx)("input",{type:"checkbox",checked:P,onChange:i=>y(i.target.checked)}),(0,e.jsxs)("span",{children:[n("schedules.form.silent"),(0,e.jsx)("small",{className:"schedule-form-help",children:n("schedules.form.silentHelp")})]})]}),u==="new-topic"&&P?(0,e.jsx)("p",{className:"schedule-form-help",children:n("schedules.form.silentNewTopicConflict")}):null,t.error?(0,e.jsx)("p",{className:"schedule-form-error",children:t.error}):null,(0,e.jsxs)("div",{className:"schedule-form-actions",children:[(0,e.jsx)("button",{type:"button",className:"schedule-form-cancel",onClick:t.onClose,children:n("schedules.form.cancel")}),(0,e.jsx)("button",{type:"submit",className:"schedule-form-submit",disabled:!l&&!m||!g&&u==="topic"&&!S.trim(),children:n(l?"schedules.form.save":"schedules.form.create")})]})]})]})})}export{X as filterSchedules,V as fmtScheduleDate,he as renderSchedulesPage,O as scheduleExecutionPlacement};
|