botmux 3.18.7 → 3.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/.runtime-build-id +1 -1
  2. package/dist/adapters/backend/tmux-pipe-backend.d.ts +57 -0
  3. package/dist/adapters/backend/tmux-pipe-backend.d.ts.map +1 -1
  4. package/dist/adapters/backend/tmux-pipe-backend.js +200 -21
  5. package/dist/adapters/backend/tmux-pipe-backend.js.map +1 -1
  6. package/dist/adapters/cli/pi-turn-boundary-extension.d.ts +66 -0
  7. package/dist/adapters/cli/pi-turn-boundary-extension.d.ts.map +1 -0
  8. package/dist/adapters/cli/pi-turn-boundary-extension.js +106 -0
  9. package/dist/adapters/cli/pi-turn-boundary-extension.js.map +1 -0
  10. package/dist/adapters/cli/pi.d.ts +29 -0
  11. package/dist/adapters/cli/pi.d.ts.map +1 -1
  12. package/dist/adapters/cli/pi.js +61 -10
  13. package/dist/adapters/cli/pi.js.map +1 -1
  14. package/dist/bot-registry.d.ts +9 -0
  15. package/dist/bot-registry.d.ts.map +1 -1
  16. package/dist/bot-registry.js +5 -0
  17. package/dist/bot-registry.js.map +1 -1
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +8 -1
  20. package/dist/cli.js.map +1 -1
  21. package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
  22. package/dist/core/dashboard-ipc-server.js +24 -0
  23. package/dist/core/dashboard-ipc-server.js.map +1 -1
  24. package/dist/core/worker-pool.d.ts.map +1 -1
  25. package/dist/core/worker-pool.js +134 -17
  26. package/dist/core/worker-pool.js.map +1 -1
  27. package/dist/daemon.d.ts.map +1 -1
  28. package/dist/daemon.js +5 -3
  29. package/dist/daemon.js.map +1 -1
  30. package/dist/dashboard/bot-payload.d.ts +2 -0
  31. package/dist/dashboard/bot-payload.d.ts.map +1 -1
  32. package/dist/dashboard/bot-payload.js +2 -0
  33. package/dist/dashboard/bot-payload.js.map +1 -1
  34. package/dist/dashboard/groups-matrix-snapshot.d.ts +27 -0
  35. package/dist/dashboard/groups-matrix-snapshot.d.ts.map +1 -1
  36. package/dist/dashboard/groups-matrix-snapshot.js +16 -0
  37. package/dist/dashboard/groups-matrix-snapshot.js.map +1 -1
  38. package/dist/dashboard/web/bot-defaults-page.d.ts +4 -0
  39. package/dist/dashboard/web/bot-defaults-page.d.ts.map +1 -1
  40. package/dist/dashboard/web/bot-defaults-page.js +52 -9
  41. package/dist/dashboard/web/bot-defaults-page.js.map +1 -1
  42. package/dist/dashboard/web/bot-defaults.d.ts +29 -0
  43. package/dist/dashboard/web/bot-defaults.d.ts.map +1 -1
  44. package/dist/dashboard/web/bot-defaults.js +45 -1
  45. package/dist/dashboard/web/bot-defaults.js.map +1 -1
  46. package/dist/dashboard/web/bot-onboarding.d.ts.map +1 -1
  47. package/dist/dashboard/web/bot-onboarding.js +5 -0
  48. package/dist/dashboard/web/bot-onboarding.js.map +1 -1
  49. package/dist/dashboard/web/dashboard-components.d.ts +29 -0
  50. package/dist/dashboard/web/dashboard-components.d.ts.map +1 -1
  51. package/dist/dashboard/web/dashboard-components.js +96 -4
  52. package/dist/dashboard/web/dashboard-components.js.map +1 -1
  53. package/dist/dashboard/web/groups-api.d.ts +11 -0
  54. package/dist/dashboard/web/groups-api.d.ts.map +1 -1
  55. package/dist/dashboard/web/groups-api.js +51 -0
  56. package/dist/dashboard/web/groups-api.js.map +1 -1
  57. package/dist/dashboard/web/i18n.d.ts.map +1 -1
  58. package/dist/dashboard/web/i18n.js +10 -0
  59. package/dist/dashboard/web/i18n.js.map +1 -1
  60. package/dist/dashboard/web/overview.d.ts.map +1 -1
  61. package/dist/dashboard/web/overview.js +11 -2
  62. package/dist/dashboard/web/overview.js.map +1 -1
  63. package/dist/dashboard/web/ui.d.ts.map +1 -1
  64. package/dist/dashboard/web/ui.js +12 -2
  65. package/dist/dashboard/web/ui.js.map +1 -1
  66. package/dist/dashboard-web/app.js +1 -1
  67. package/dist/dashboard-web/chunks/{agent-workbench-dock-page-6LC422N6.js → agent-workbench-dock-page-FAL2YGY5.js} +1 -1
  68. package/dist/dashboard-web/chunks/{agent-workbench-page-RSAWY7O2.js → agent-workbench-page-G65IOPLY.js} +1 -1
  69. package/dist/dashboard-web/chunks/bot-defaults-page-3BNFNZEO.js +1 -0
  70. package/dist/dashboard-web/chunks/chunk-2XHWGUTB.js +10 -0
  71. package/dist/dashboard-web/chunks/{chunk-R3LJUCEO.js → chunk-3OJQKYM3.js} +1 -1
  72. package/dist/dashboard-web/chunks/{chunk-K232GT3M.js → chunk-IRFGJSPL.js} +5 -5
  73. package/dist/dashboard-web/chunks/{chunk-IA5KMD5O.js → chunk-IYVXEFKU.js} +1 -1
  74. package/dist/dashboard-web/chunks/{chunk-YJA3KY3J.js → chunk-MYLVEXYF.js} +1 -1
  75. package/dist/dashboard-web/chunks/chunk-QALRQEKD.js +1 -0
  76. package/dist/dashboard-web/chunks/{connectors-page-DJCTHSFB.js → connectors-page-K6VZNYUQ.js} +1 -1
  77. package/dist/dashboard-web/chunks/{customization-page-VQJAEDZY.js → customization-page-FRP6RFOI.js} +1 -1
  78. package/dist/dashboard-web/chunks/{feedback-page-O7SZRKNM.js → feedback-page-4X7N5J33.js} +1 -1
  79. package/dist/dashboard-web/chunks/{groups-page-7PONUYHE.js → groups-page-RFQVUO6K.js} +1 -1
  80. package/dist/dashboard-web/chunks/{insights-page-J6DAAJ6D.js → insights-page-XWH77GX7.js} +1 -1
  81. package/dist/dashboard-web/chunks/{monitor-room-F3QNEW7N.js → monitor-room-WFU3745R.js} +1 -1
  82. package/dist/dashboard-web/chunks/{monitoring-page-JHDD2VS2.js → monitoring-page-3NYPZEQT.js} +1 -1
  83. package/dist/dashboard-web/chunks/{office-page-MMTN4IKD.js → office-page-4I3X6PTF.js} +1 -1
  84. package/dist/dashboard-web/chunks/overview-page-OQWLVTKT.js +1 -0
  85. package/dist/dashboard-web/chunks/{roles-page-FNI4MGX6.js → roles-page-RKUGNQOW.js} +1 -1
  86. package/dist/dashboard-web/chunks/{schedules-page-6PUU63KS.js → schedules-page-SAJKYRZ6.js} +1 -1
  87. package/dist/dashboard-web/chunks/{sessions-page-O4N72EXT.js → sessions-page-IU6VNSX4.js} +1 -1
  88. package/dist/dashboard-web/chunks/{settings-page-G7B3STUF.js → settings-page-WTIPX7BQ.js} +1 -1
  89. package/dist/dashboard-web/chunks/{skills-page-CEWKQOIG.js → skills-page-MKG3HJIU.js} +1 -1
  90. package/dist/dashboard-web/chunks/{team-federation-page-NUP4VK4H.js → team-federation-page-7SMZJWPT.js} +1 -1
  91. package/dist/dashboard-web/chunks/{v3-page-M4XF6D5Z.js → v3-page-JMCFLY4Y.js} +1 -1
  92. package/dist/dashboard-web/chunks/{whiteboards-page-L755NZX6.js → whiteboards-page-5YTWY5EB.js} +1 -1
  93. package/dist/dashboard-web/style.css +65 -3
  94. package/dist/dashboard.js +50 -4
  95. package/dist/dashboard.js.map +1 -1
  96. package/dist/i18n/en.d.ts.map +1 -1
  97. package/dist/i18n/en.js +4 -1
  98. package/dist/i18n/en.js.map +1 -1
  99. package/dist/i18n/zh.d.ts.map +1 -1
  100. package/dist/i18n/zh.js +4 -1
  101. package/dist/i18n/zh.js.map +1 -1
  102. package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
  103. package/dist/im/lark/event-dispatcher.js +141 -38
  104. package/dist/im/lark/event-dispatcher.js.map +1 -1
  105. package/dist/services/card-prefs-store.d.ts +2 -0
  106. package/dist/services/card-prefs-store.d.ts.map +1 -1
  107. package/dist/services/card-prefs-store.js +9 -1
  108. package/dist/services/card-prefs-store.js.map +1 -1
  109. package/dist/services/pi-transcript.d.ts +21 -1
  110. package/dist/services/pi-transcript.d.ts.map +1 -1
  111. package/dist/services/pi-transcript.js +188 -8
  112. package/dist/services/pi-transcript.js.map +1 -1
  113. package/dist/services/session-store.d.ts.map +1 -1
  114. package/dist/services/session-store.js +495 -11
  115. package/dist/services/session-store.js.map +1 -1
  116. package/dist/services/under-review-notify-store.d.ts +18 -0
  117. package/dist/services/under-review-notify-store.d.ts.map +1 -0
  118. package/dist/services/under-review-notify-store.js +67 -0
  119. package/dist/services/under-review-notify-store.js.map +1 -0
  120. package/dist/setup/open-platform-automation.d.ts +210 -2
  121. package/dist/setup/open-platform-automation.d.ts.map +1 -1
  122. package/dist/setup/open-platform-automation.js +538 -44
  123. package/dist/setup/open-platform-automation.js.map +1 -1
  124. package/dist/setup/open-platform-outcome.d.ts.map +1 -1
  125. package/dist/setup/open-platform-outcome.js +5 -0
  126. package/dist/setup/open-platform-outcome.js.map +1 -1
  127. package/dist/workflows/events/payloads.d.ts +6 -6
  128. package/dist/workflows/events/schema.d.ts +12 -12
  129. package/package.json +9 -7
  130. package/dist/dashboard-web/chunks/bot-defaults-page-67RAWCSQ.js +0 -1
  131. package/dist/dashboard-web/chunks/chunk-MMLTCXHP.js +0 -10
  132. package/dist/dashboard-web/chunks/chunk-NYY66DNC.js +0 -1
  133. package/dist/dashboard-web/chunks/overview-page-IQ2UJAJP.js +0 -1
@@ -1,2 +1,2 @@
1
- import{a as Ke}from"./chunk-OWUXOKFE.js";import{a as Be}from"./chunk-ZJVTGU5X.js";import{f as he,h as De,i as Oe,w as Fe,x as h}from"./chunk-K232GT3M.js";import{c as D,d as pe,e as j}from"./chunk-3YZFAHNK.js";var $e="#/agent-workbench",Ue="#/agent-workbench-dock";var ke=[{value:"status",label:"\u72B6\u6001"},{value:"bot",label:"\u673A\u5668\u4EBA"},{value:"chat",label:"\u4F1A\u8BDD\u4F4D\u7F6E"},{value:"kind",label:"\u7C7B\u578B"},{value:"cli",label:"CLI"},{value:"time",label:"\u6D3B\u8DC3\u65F6\u95F4"}];function K(e){return typeof e=="string"&&ke.some(n=>n.value===e)}var Kn=new Set(["starting","working","analyzing","active","idle","limited"]),Bn=512;function Y(e){return typeof e=="string"&&e.length>0&&e.length<=Bn&&!/[\u0000-\u001f\u007f]/.test(e)}function fe(e,n){let t=e==="dock"?Ue:$e;return Y(n)?`${t}/${encodeURIComponent(n)}`:t}function Ot(e){let n=String(e||"").split("?")[0].replace(/\/+$/,"");for(let[t,r]of[["dock",Ue],["main",$e]]){if(n===r)return{surface:t,sessionId:null};if(!n.startsWith(`${r}/`))continue;let o=n.slice(r.length+1),s;try{s=decodeURIComponent(o)}catch{return null}return Y(s)?{surface:t,sessionId:s}:null}return null}function z(e){return Number.isFinite(e)?Math.min(460,Math.max(176,Math.round(e))):300}function Gn(e){return Number.isFinite(e)?Math.min(.72,Math.max(.28,Math.round(e*1e3)/1e3)):.5}function H(){return{version:1,railWidth:300,railCollapsed:!1,focus:"terminal",paneMode:"focus",splitAxis:"horizontal",splitRatio:.5,chatRequested:!1}}function me(e){let n=H();if(!e||typeof e!="object"||Array.isArray(e))return n;let t=e;return{version:1,railWidth:z(Number(t.railWidth)),railCollapsed:t.railCollapsed===!0,focus:t.focus==="web"?"web":"terminal",paneMode:t.paneMode==="split"?"split":"focus",splitAxis:t.splitAxis==="vertical"?"vertical":"horizontal",splitRatio:Gn(Number(t.splitRatio)),chatRequested:t.chatRequested===!0}}function Ft(e,n){return e<620?{mode:"mobile",step:"mobile-stack",railCollapsed:!0,paneMode:"focus",chatMode:"jump"}:e<960?{mode:"desktop",step:"chat-jump",railCollapsed:n.railCollapsed,paneMode:"focus",chatMode:"jump"}:e<1120?{mode:"desktop",step:"focus",railCollapsed:n.railCollapsed,paneMode:"focus",chatMode:"native-split"}:e<1280?{mode:"desktop",step:"rail-collapsed",railCollapsed:n.railCollapsed,paneMode:n.paneMode,chatMode:"native-split"}:{mode:"desktop",step:"full",railCollapsed:n.railCollapsed,paneMode:n.paneMode,chatMode:"native-split"}}function q(e){if(e.status==="closed")return null;let n=String(e.agentAttention?.reason??"").trim();return n||(e.agentAttention?"Agent \u8BF7\u6C42\u534F\u52A9":e.pendingRepo?"\u9700\u8981\u9009\u62E9\u4ED3\u5E93":e.tuiPromptActive?"\u7EC8\u7AEF\u6709\u5F85\u786E\u8BA4\u7684\u63D0\u793A":e.queued?"\u5F85\u542F\u52A8":e.status==="limited"?"\u7528\u91CF\u5DF2\u8FBE\u4E0A\u9650":null)}function ge(e){return e.chatType==="p2p"?"p2p":e.scope==="thread"?"thread":e.scope==="chat"?"group":null}function X(e,n=!1){return q(e)||n&&e.status!=="closed"?"needs-you":e.status!=="closed"&&e.status!=="dormant"&&Kn.has(e.status)||e.status!=="closed"&&e.status!=="dormant"?"active":"recent"}function L(e){let n=Number(e.agentAttention?.at??e.lastMessageAt??e.closedAt??e.spawnedAt??0);return Number.isFinite(n)?n:0}function ye(e){return String(e.title??"").trim()||String(e.chatDisplayName??"").trim()||e.sessionId}function Je(e){return[ye(e),e.sessionId,e.botName,e.cliId,e.repoName,e.workingDir,e.gitBranch,e.chatDisplayName,q(e)].filter(Boolean).join(`
1
+ import{a as Ke}from"./chunk-OWUXOKFE.js";import{a as Be}from"./chunk-ZJVTGU5X.js";import{g as he,i as De,j as Oe,x as Fe,y as h}from"./chunk-IRFGJSPL.js";import{c as D,d as pe,e as j}from"./chunk-3YZFAHNK.js";var $e="#/agent-workbench",Ue="#/agent-workbench-dock";var ke=[{value:"status",label:"\u72B6\u6001"},{value:"bot",label:"\u673A\u5668\u4EBA"},{value:"chat",label:"\u4F1A\u8BDD\u4F4D\u7F6E"},{value:"kind",label:"\u7C7B\u578B"},{value:"cli",label:"CLI"},{value:"time",label:"\u6D3B\u8DC3\u65F6\u95F4"}];function K(e){return typeof e=="string"&&ke.some(n=>n.value===e)}var Kn=new Set(["starting","working","analyzing","active","idle","limited"]),Bn=512;function Y(e){return typeof e=="string"&&e.length>0&&e.length<=Bn&&!/[\u0000-\u001f\u007f]/.test(e)}function fe(e,n){let t=e==="dock"?Ue:$e;return Y(n)?`${t}/${encodeURIComponent(n)}`:t}function Ot(e){let n=String(e||"").split("?")[0].replace(/\/+$/,"");for(let[t,r]of[["dock",Ue],["main",$e]]){if(n===r)return{surface:t,sessionId:null};if(!n.startsWith(`${r}/`))continue;let o=n.slice(r.length+1),s;try{s=decodeURIComponent(o)}catch{return null}return Y(s)?{surface:t,sessionId:s}:null}return null}function z(e){return Number.isFinite(e)?Math.min(460,Math.max(176,Math.round(e))):300}function Gn(e){return Number.isFinite(e)?Math.min(.72,Math.max(.28,Math.round(e*1e3)/1e3)):.5}function H(){return{version:1,railWidth:300,railCollapsed:!1,focus:"terminal",paneMode:"focus",splitAxis:"horizontal",splitRatio:.5,chatRequested:!1}}function me(e){let n=H();if(!e||typeof e!="object"||Array.isArray(e))return n;let t=e;return{version:1,railWidth:z(Number(t.railWidth)),railCollapsed:t.railCollapsed===!0,focus:t.focus==="web"?"web":"terminal",paneMode:t.paneMode==="split"?"split":"focus",splitAxis:t.splitAxis==="vertical"?"vertical":"horizontal",splitRatio:Gn(Number(t.splitRatio)),chatRequested:t.chatRequested===!0}}function Ft(e,n){return e<620?{mode:"mobile",step:"mobile-stack",railCollapsed:!0,paneMode:"focus",chatMode:"jump"}:e<960?{mode:"desktop",step:"chat-jump",railCollapsed:n.railCollapsed,paneMode:"focus",chatMode:"jump"}:e<1120?{mode:"desktop",step:"focus",railCollapsed:n.railCollapsed,paneMode:"focus",chatMode:"native-split"}:e<1280?{mode:"desktop",step:"rail-collapsed",railCollapsed:n.railCollapsed,paneMode:n.paneMode,chatMode:"native-split"}:{mode:"desktop",step:"full",railCollapsed:n.railCollapsed,paneMode:n.paneMode,chatMode:"native-split"}}function q(e){if(e.status==="closed")return null;let n=String(e.agentAttention?.reason??"").trim();return n||(e.agentAttention?"Agent \u8BF7\u6C42\u534F\u52A9":e.pendingRepo?"\u9700\u8981\u9009\u62E9\u4ED3\u5E93":e.tuiPromptActive?"\u7EC8\u7AEF\u6709\u5F85\u786E\u8BA4\u7684\u63D0\u793A":e.queued?"\u5F85\u542F\u52A8":e.status==="limited"?"\u7528\u91CF\u5DF2\u8FBE\u4E0A\u9650":null)}function ge(e){return e.chatType==="p2p"?"p2p":e.scope==="thread"?"thread":e.scope==="chat"?"group":null}function X(e,n=!1){return q(e)||n&&e.status!=="closed"?"needs-you":e.status!=="closed"&&e.status!=="dormant"&&Kn.has(e.status)||e.status!=="closed"&&e.status!=="dormant"?"active":"recent"}function L(e){let n=Number(e.agentAttention?.at??e.lastMessageAt??e.closedAt??e.spawnedAt??0);return Number.isFinite(n)?n:0}function ye(e){return String(e.title??"").trim()||String(e.chatDisplayName??"").trim()||e.sessionId}function Je(e){return[ye(e),e.sessionId,e.botName,e.cliId,e.repoName,e.workingDir,e.gitBranch,e.chatDisplayName,q(e)].filter(Boolean).join(`
2
2
  `).toLocaleLowerCase()}function Kt(e,n=""){let t=n.trim().toLocaleLowerCase(),r={"needs-you":[],active:[],recent:[]};for(let o of e)Y(o.sessionId)&&(t&&!Je(o).includes(t)||r[X(o)].push(o));for(let o of Object.values(r))o.sort((s,l)=>L(l)-L(s)||s.sessionId.localeCompare(l.sessionId));return r}var je="\u5F85\u4F60\u5904\u7406",Ve={"needs-you":je,active:"\u8FDB\u884C\u4E2D",recent:"\u6700\u8FD1"},Hn={thread:"\u8BDD\u9898",group:"\u7FA4",p2p:"\u5355\u804A"},$n=["\u8BDD\u9898","\u7FA4","\u5355\u804A","\u5176\u4ED6"],Un=["\u4ECA\u5929","\u6628\u5929","\u672C\u5468","\u66F4\u65E9"],Jn={status:["active","recent"],kind:$n.map(e=>`kind:${e}`),time:Un.map(e=>`time:${e}`)};function V(e){return typeof e=="string"?e.trim():""}function be(e){let n=new Date(e);return n.setHours(0,0,0,0),n}function jn(e){let n=be(e),t=be(e);t.setDate(t.getDate()-1);let r=be(e);return r.setDate(r.getDate()-6),{today:n.getTime(),yesterday:t.getTime(),week:r.getTime()}}function Vn(e,n){return e>0?e>=n.today?"\u4ECA\u5929":e>=n.yesterday?"\u6628\u5929":e>=n.week?"\u672C\u5468":"\u66F4\u65E9":"\u66F4\u65E9"}function Yn(e,n,t){switch(n){case"bot":{let r=V(e.botName)||"\u672A\u77E5\u673A\u5668\u4EBA";return{key:`bot:${r}`,label:r}}case"chat":{let r=V(e.chatDisplayName)||V(e.chatId)||"\u672A\u77E5\u4F1A\u8BDD";return{key:`chat:${r}`,label:r}}case"kind":{let r=ge(e),o=r?Hn[r]:"\u5176\u4ED6";return{key:`kind:${o}`,label:o}}case"cli":{let r=V(e.cliId)||"unknown";return{key:`cli:${r}`,label:r}}case"time":{let r=Vn(L(e),t);return{key:`time:${r}`,label:r}}default:{let r=X(e)==="recent"?"recent":"active";return{key:r,label:Ve[r]}}}}function Ge(e,n){return L(n)-L(e)||e.sessionId.localeCompare(n.sessionId)}function Ye(e,n){let t=String(n.query??"").trim().toLocaleLowerCase(),r=n.unreadIds,o=Number.isFinite(n.now)?Number(n.now):Date.now(),s=jn(o),l=K(n.dimension)?n.dimension:"status",p=[],A=new Map;for(let b of e){if(!Y(b.sessionId)||t&&!Je(b).includes(t))continue;let m=r?.has(b.sessionId)===!0;if(X(b,m)==="needs-you"){p.push(b);continue}let g=Yn(b,l,s),E=A.get(g.key);E?E.sessions.push(b):A.set(g.key,{key:g.key,label:g.label,kind:"plain",sessions:[b]})}let y=Jn[l],S=[...A.values()];if(y)S.sort((b,m)=>{let g=y.indexOf(b.key),E=y.indexOf(m.key);return(g<0?y.length:g)-(E<0?y.length:E)||b.label.localeCompare(m.label)});else{let b=new Map(S.map(m=>[m.key,m.sessions.reduce((g,E)=>Math.max(g,L(E)),0)]));S.sort((m,g)=>(b.get(g.key)??0)-(b.get(m.key)??0)||m.label.localeCompare(g.label))}for(let b of S)b.sessions.sort(Ge);let k=[];return p.length>0&&(p.sort(Ge),k.push({key:"needs-you",label:je,kind:"needs-you",sessions:p})),k.push(...S),k}function zn(e){return["needs-you","active","recent"].map(n=>({key:n,label:Ve[n],kind:n==="needs-you"?"needs-you":"plain",sessions:e[n]}))}function He(e,n){return e.kind==="needs-you"?"needs-you":n?X(n):e.key==="recent"?"recent":"active"}function ze(e,n){let t=Array.isArray(e)?e:zn(e),r=[];for(let o of t){let s=o.kind==="needs-you",l=n?.has(o.key)===!0;if(r.push({kind:"header",key:`header-${o.key}`,group:He(o),groupKey:o.key,label:o.label,count:o.sessions.length,isNeedsYou:s,collapsed:l}),!l)for(let p of o.sessions)r.push({kind:"session",key:`${o.key}-${p.sessionId}`,group:He(o,p),groupKey:o.key,label:o.label,isNeedsYou:s,session:p})}return r}function Q(e,n=!1){return e.kind==="header"?30:n?60:54}function qe(e,n,t,r=240,o=!1){let s=new Array(e.length+1);s[0]=0;for(let k=0;k<e.length;k+=1)s[k+1]=s[k]+Q(e[k],o);let l=s[e.length]??0,p=Math.max(0,Number.isFinite(n)?n-r:0),A=Math.min(l,Math.max(0,n)+Math.max(0,t)+r),y=0;for(;y<e.length&&s[y+1]<p;)y+=1;let S=y;for(;S<e.length&&s[S]<=A;)S+=1;return{start:y,end:S,offsetTop:s[y]??0,totalHeight:l,positions:s}}function Xe(e,n=Date.now(),t="en"){if(!Number.isFinite(e)||e<=0)return"\u2014";let r=Math.round((e-n)/1e3),o=Math.abs(r);if(o<45)return t.toLowerCase().startsWith("zh")?"\u521A\u521A":"just now";let s=[["year",365*24*60*60],["month",720*60*60],["day",1440*60],["hour",3600],["minute",60]],[l,p]=s.find(([,A])=>o>=A)??["minute",60];return new Intl.RelativeTimeFormat(t,{numeric:"auto",style:"short"}).format(Math.round(r/p),l)}function Bt(e,n){let t=qn(e);return t||(!e.webPort||!e.proxyPort||!n?null:`${n.origin}/s/${encodeURIComponent(e.sessionId)}`)}function qn(e){if(typeof e.riffAccessUrl!="string"||e.riffAccessUrl.length>2048)return null;try{let n=new URL(e.riffAccessUrl);return n.protocol!=="http:"&&n.protocol!=="https:"||n.username||n.password?null:n.toString()}catch{return null}}function Gt(e){let n=e.preview?.path;if(typeof n!="string"||n.length>2048)return null;let t=`/preview/${encodeURIComponent(e.sessionId)}/`;return n===t?n:null}function Qe(e){return e==="lark"?"https://applink.larksuite.com":"https://applink.feishu.cn"}function Ze(e,n="feishu"){let t=new URL("/client/chat/open",Qe(n));return t.searchParams.set("openChatId",e),t.toString()}function Ut(e){if(!e.appId.trim()||!/^https?:\/\//.test(e.targetOrigin))return null;try{let n=new URL("/client/web_app/open",Qe(e.brand??"feishu")),t=fe(e.surface,e.sessionId),r=new URL("/",e.targetOrigin);return r.protocol!=="http:"&&r.protocol!=="https:"?null:(r.hash=t,n.searchParams.set("appId",e.appId),n.searchParams.set("mode",e.surface==="dock"?"sidebar":"appCenter"),e.surface==="dock"&&(n.searchParams.set("min_width","350"),n.searchParams.set("max_width","520")),n.searchParams.set("lk_target_url",r.toString()),n.toString())}catch{return null}}function Jt(e,n,t){return`${/^\/[A-Za-z0-9/_-]+$/.test(e)?e:"/auth/feishu"}?returnTo=${encodeURIComponent(`/${fe(n,t)}`)}`}function Yt(){let e=globalThis.crypto;try{if(typeof e?.randomUUID=="function")return`a${e.randomUUID().replaceAll("-","")}`;if(typeof e?.getRandomValues=="function")return`a${[...e.getRandomValues(new Uint8Array(16))].map(t=>t.toString(16).padStart(2,"0")).join("")}`}catch{}return`a${Date.now().toString(36)}${Math.random().toString(36).slice(2,12)}`}var v=class extends Error{constructor(t,r,o){super(r);this.status=t;this.code=r;this.retryAfterSeconds=o;this.name="WorkbenchApiError"}status;code;retryAfterSeconds};function Xn(e,n){if(e.status!==429)return;let t=Number(e.headers?.get?.("retry-after"));if(Number.isFinite(t)&&t>0)return Math.ceil(t);let r=Number(n?.retryAfterMs);if(Number.isFinite(r)&&r>0)return Math.ceil(r/1e3)}async function T(e,n,t={}){let o=String(t.method??"GET").toUpperCase()==="GET"?t.headers:{...Ke(),...t.headers},s=await e(n,{cache:"no-store",...t,headers:o}),l=await s.json().catch(()=>null);if(!s.ok||!l||l.ok===!1)throw new v(s.status,String(l?.error??`http_${s.status}`),Xn(s,l));return l}function B(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new v(502,n);return e}function en(e,n){if(e!==void 0){if(typeof e!="number"||!Number.isSafeInteger(e)||e<=0)throw new v(502,n);return e}}function we(e,n){let t=B(e,"invalid_control_response");if(t.mode!=="readonly"&&t.mode!=="controlled")throw new v(502,"invalid_control_response");let r=typeof t.owned=="boolean"?t.owned:n;if(typeof r!="boolean")throw new v(502,"invalid_control_response");let o=en(t.expiresAt,"invalid_control_response"),s=t.fixed===void 0?void 0:t.fixed;if(s!==void 0&&typeof s!="boolean")throw new v(502,"invalid_control_response");if(t.mode==="readonly"&&(r||o!==void 0)||t.mode==="controlled"&&o===void 0&&s!==!0)throw new v(502,"invalid_control_response");let l=t.reused===void 0?void 0:t.reused;if(l!==void 0&&typeof l!="boolean")throw new v(502,"invalid_control_response");let p=t.acquisition===void 0?void 0:t.acquisition;if(p!==void 0&&(typeof p!="string"||!p||p.length>256))throw new v(502,"invalid_control_response");if(s===!0&&(t.mode!=="controlled"||!r||o!==void 0))throw new v(502,"invalid_control_response");return{mode:t.mode,owned:r,...o===void 0?{}:{expiresAt:o},...l===void 0?{}:{reused:l},...s===void 0?{}:{fixed:s},...p===void 0?{}:{acquisition:p}}}function Z(e){let n=B(e,"invalid_preview_interaction_response");if(n.mode!=="preview"&&n.mode!=="interactive")throw new v(502,"invalid_preview_interaction_response");if(typeof n.label!="string"||!n.label||n.label.length>256||typeof n.securityNotice!="string"||!n.securityNotice||n.securityNotice.length>1024)throw new v(502,"invalid_preview_interaction_response");let t=en(n.idleExpiresAt,"invalid_preview_interaction_response");if(n.mode==="preview"&&t!==void 0||n.mode==="interactive"&&t===void 0)throw new v(502,"invalid_preview_interaction_response");return{mode:n.mode,label:n.label,securityNotice:n.securityNotice,...t===void 0?{}:{idleExpiresAt:t}}}function Qn(){let e=globalThis.window?.location?.origin;return typeof e=="string"&&e?e:null}function Zn(e){let n=Qn();if(!n)return e;try{let t=new URL(e,n);return t.protocol!=="http:"&&t.protocol!=="https:"?e:t.toString()}catch{return e}}function Se(e,n,t){let r=`/api/sessions/${encodeURIComponent(e)}/control${n?`/${n}`:""}`;return t?`${r}?${t.param}=${encodeURIComponent(t.value)}`:r}function ee(e,n){return`/api/sessions/${encodeURIComponent(e)}/preview-interaction${n?`/${n}`:""}`}function nn(e=fetch){return{getTerminalControl:async(n,t)=>we(await T(e,Se(n),{signal:t})),takeoverTerminal:async(n,t,r)=>we(await T(e,Se(n,"takeover",r?{param:"acq",value:r}:void 0),{method:"POST",signal:t}),!0),releaseTerminal:async(n,t,r)=>we(await T(e,Se(n,"release",r?{param:"expect",value:r}:void 0),{method:"POST",signal:t}),!1),getPreviewInteraction:async(n,t)=>Z(await T(e,ee(n),{signal:t})),unlockPreview:async(n,t)=>Z(await T(e,ee(n,"unlock"),{method:"POST",signal:t})),touchPreview:async(n,t)=>Z(await T(e,ee(n,"activity"),{method:"POST",signal:t})),lockPreview:async(n,t)=>Z(await T(e,ee(n,"lock"),{method:"POST",signal:t})),async locateSession(n,t){await T(e,`/api/sessions/${encodeURIComponent(n)}/locate`,{method:"POST",signal:t})},async getTerminalViewLink(n,t){try{let r=B(await T(e,`/api/sessions/${encodeURIComponent(n)}/view-link`,{signal:t}),"invalid_view_link_response");if(typeof r.url!="string"||r.url.length>2048||!/^\/s\/[^/\\]/.test(r.url))return null;let o=typeof r.expiresAt=="number"&&Number.isSafeInteger(r.expiresAt)&&r.expiresAt>0?r.expiresAt:null;return{url:Zn(r.url),expiresAt:o}}catch{return null}},async getStandingLink(n){try{let t=B(await T(e,"/api/workbench/standing-link",{signal:n}),"invalid_standing_link_response");if(typeof t.url!="string"||!t.url||t.url.length>2048)return null;let r=new URL(t.url);return r.protocol!=="http:"&&r.protocol!=="https:"?null:{url:t.url}}catch{return null}},async getH5Context(n){try{let t=B(await T(e,"/api/workbench/h5-context",{signal:n}),"invalid_h5_context_response"),r=B(t.h5,"invalid_h5_context_response");if(typeof r.enabled!="boolean"||typeof r.appId!="string"||r.appId.length>256||r.brand!=="feishu"&&r.brand!=="lark"||typeof r.entryPath!="string"||!/^\/[A-Za-z0-9/_-]{1,127}$/.test(r.entryPath))throw new v(502,"invalid_h5_context_response");return{enabled:r.enabled,appId:r.appId,brand:r.brand,entryPath:r.entryPath}}catch{return null}}}}var w=D(pe(),1);var ve="botmux.agent-workbench.appearance.v1",Ae=["ink","slate-blue","warm-graphite","light-frost"];var et={"orca-ink":"ink"},nt={orca:"reader"};function tt(e){return it(e)?e:typeof e=="string"?et[e]??null:null}function rt(e){return st(e)?e:typeof e=="string"?nt[e]??null:null}var ne="light-frost",on="slate-blue",ot="classic";function it(e){return typeof e=="string"&&Ae.includes(e)}function st(e){return e==="reader"||e==="classic"}function at(e){return e===ne?"light":"dark"}function G(e="dark"){return{skin:on,mode:he(e)??"dark",termStyle:ot}}function xe(e,n="dark"){let t=G(n);if(!e||typeof e!="object"||Array.isArray(e))return t;let r=e;return{skin:tt(r.skin)??t.skin,mode:he(r.mode)??t.mode,termStyle:rt(r.termStyle)??t.termStyle}}function tn(e,n="dark"){if(!e)return G(n);try{let t=e.getItem(ve);return t?xe(JSON.parse(t),n):G(n)}catch{return G(n)}}function ct(e,n){if(!e)return!1;try{return e.setItem(ve,JSON.stringify(xe(n))),!0}catch{return!1}}function lt(e,n){return De(e.mode,n)==="light"?ne:e.skin===ne?on:e.skin}function sn(e,n){if(n===ne)return e.mode==="light"?e:{...e,mode:"light"};let t=e.mode==="light"?"dark":e.mode;return{...e,skin:n,mode:t}}function an(e,n){return e.mode===n?e:{...e,mode:n}}function cn(e,n){return e.termStyle===n?e:{...e,termStyle:n}}function Xt(e){return e==="reader"?"wb-term-reader":"wb-term-classic"}var ln={ink:{bg:"#212121",raise:"#3C3C3C",accent:"#FF8B63"},"slate-blue":{bg:"#19212C",raise:"#333F4E",accent:"#6FCBF7"},"warm-graphite":{bg:"#24211A",raise:"#443E34",accent:"#F2A33C"},"light-frost":{bg:"#F3F6F9",raise:"#C9D7E8",accent:"#0B5F8F"}},ut={background:"#1a1b26",foreground:"#a9b1d6",cursor:"#c0caf5",selectionBackground:"#33467c",black:"#15161e",red:"#f7768e",green:"#9ece6a",yellow:"#e0af68",blue:"#7aa2f7",magenta:"#bb9af7",cyan:"#7dcfff",white:"#a9b1d6"},dt={ink:{background:"#030303",foreground:"#EDEDED",cursor:"#FF8B63",selectionBackground:"#3C3C3C",black:"#181818",red:"#FF8C8F",green:"#3ED598",yellow:"#EFC260",blue:"#FF8B63",magenta:"#D8A0FF",cyan:"#7FD8D0",white:"#A6A6A6"},"slate-blue":{background:"#030407",foreground:"#E4EBF2",cursor:"#6FCBF7",selectionBackground:"#333F4E",black:"#141922",red:"#F58A94",green:"#63D6A0",yellow:"#EDB95C",blue:"#6FCBF7",magenta:"#C0A6F5",cyan:"#7FD8D0",white:"#A2B2C3"},"warm-graphite":{background:"#040402",foreground:"#F0EBE1",cursor:"#F2A33C",selectionBackground:"#443E34",black:"#1B1912",red:"#FF9186",green:"#5FCE9B",yellow:"#EAC14F",blue:"#F2A33C",magenta:"#D9A7DA",cyan:"#7FD8D0",white:"#B3AA9C"},"light-frost":{background:"#16202B",foreground:"#E8EEF5",cursor:"#6FCBF7",selectionBackground:"#33465C",black:"#16202B",red:"#F58A94",green:"#63D6A0",yellow:"#EDB95C",blue:"#6FCBF7",magenta:"#C0A6F5",cyan:"#7FD8D0",white:"#A7B6C6"}};function un(e,n){return e==="reader"?dt[n]:ut}var pt="--term-canvas-bg";function Qt(e,n){return{[pt]:un(e,n).background}}var ht="botmux:wb-appearance";function bt(e,n){return{type:ht,termStyle:e,skin:n,theme:un(e,n)}}function Zt(e,n,t,r,o){let s=e?.contentWindow;if(!s||!n)return!1;let l;try{l=new URL(n,o).origin}catch{return!1}if(!l||l==="null")return!1;try{return s.postMessage(bt(t,r),l),!0}catch{return!1}}function rn(e,n){if(!e)return{};let t={skin:e.dataset.skin,theme:e.dataset.theme};return e.dataset.skin=n.skin,e.dataset.theme=n.theme,t}function kt(e,n){e&&(n.skin===void 0?delete e.dataset.skin:e.dataset.skin=n.skin,n.theme===void 0?delete e.dataset.theme:e.dataset.theme=n.theme)}function ft(){if(typeof window>"u")return null;let e=null;try{e=window.localStorage}catch{e=null}let n=window.matchMedia?.("(prefers-color-scheme: dark)")??null;return{storage:e,root:typeof document>"u"?null:document.documentElement,inheritedMode:Oe(e??void 0),prefersDark:()=>!!n?.matches,onSystemThemeChange:t=>(n?.addEventListener("change",t),()=>n?.removeEventListener("change",t)),onStorageChange:t=>{let r=o=>t(o.key,o.newValue);return window.addEventListener("storage",r),()=>window.removeEventListener("storage",r)}}}var We=class{env=null;envResolved=!1;value=G();snapshot=this.buildSnapshot(!1);listeners=new Set;mounted=0;disposers=[];rootSnapshot=null;configure(n){this.envResolved||(this.envResolved=!0,this.env=n,n&&(this.value=tn(n.storage,n.inheritedMode),this.snapshot=this.buildSnapshot(n.prefersDark())))}getSnapshot(){return this.ensureEnv(),this.snapshot}subscribe(n){return this.ensureEnv(),this.listeners.add(n),()=>{this.listeners.delete(n)}}set(n){this.ensureEnv(),n!==this.value&&(this.value=n,ct(this.env?.storage,n),this.refresh())}mount(){this.ensureEnv(),this.mounted+=1,this.mounted===1&&this.bind();let n=!1;return()=>{n||(n=!0,this.mounted-=1,this.mounted===0&&this.unbind())}}reset(){this.unbind(),this.mounted=0,this.env=null,this.envResolved=!1,this.value=G(),this.snapshot=this.buildSnapshot(!1),this.listeners.clear()}ensureEnv(){this.envResolved||this.configure(ft())}bind(){let n=this.env;n&&(this.rootSnapshot=rn(n.root,{skin:this.snapshot.skin,theme:this.snapshot.theme}),n.onSystemThemeChange&&this.disposers.push(n.onSystemThemeChange(()=>this.refresh())),n.onStorageChange&&this.disposers.push(n.onStorageChange((t,r)=>{if(t!==null&&t!==ve)return;let o=null;if(r)try{o=JSON.parse(r)}catch{o=null}this.value=r?xe(o,n.inheritedMode):tn(n.storage,n.inheritedMode),this.refresh()})))}unbind(){for(let n of this.disposers.splice(0))n();this.rootSnapshot&&(kt(this.env?.root,this.rootSnapshot),this.rootSnapshot=null)}reapply(){this.refresh()}refresh(){let n=this.buildSnapshot(this.env?.prefersDark()??!1),t=this.snapshot,r=t.skin===n.skin&&t.theme===n.theme&&t.appearance.skin===n.appearance.skin&&t.appearance.mode===n.appearance.mode&&t.appearance.termStyle===n.appearance.termStyle;if(r?this.value=t.appearance:this.snapshot=n,this.rootSnapshot&&rn(this.env?.root,{skin:this.snapshot.skin,theme:this.snapshot.theme}),!r)for(let o of this.listeners)o()}buildSnapshot(n){let t=lt(this.value,n);return{appearance:this.value,skin:t,theme:at(t)}}},I=new We;var a=D(j(),1),dn={ink:"workbench.appearance.skin.ink","slate-blue":"workbench.appearance.skin.slateBlue","warm-graphite":"workbench.appearance.skin.warmGraphite","light-frost":"workbench.appearance.skin.lightFrost"},mt=[{value:"system",labelKey:"workbench.appearance.mode.system"},{value:"light",labelKey:"workbench.appearance.mode.light"},{value:"dark",labelKey:"workbench.appearance.mode.dark"}],gt=[{value:"reader",labelKey:"workbench.appearance.term.reader"},{value:"classic",labelKey:"workbench.appearance.term.classic"}],yt=null;function bn(){return yt??=nn()}function wt(e){return I.subscribe(e)}function pn(){return I.getSnapshot()}function kn(){return(0,w.useSyncExternalStore)(wt,pn,pn)}function ir(){return(0,w.useEffect)(()=>I.mount(),[]),(0,w.useEffect)(()=>Fe.on(()=>I.reapply()),[]),kn()}function St(e){I.set(sn(I.getSnapshot().appearance,e))}function Wt(e){I.set(an(I.getSnapshot().appearance,e))}function vt(e){I.set(cn(I.getSnapshot().appearance,e))}function hn(e,n){let r=[...e.currentTarget.querySelectorAll('button[role="radio"]')];if(r.length===0)return;let o=r.indexOf(e.target),s=r[((o<0?0:o)+n+r.length)%r.length];e.preventDefault(),s.focus(),s.click()}function Re(e){e.key==="ArrowRight"||e.key==="ArrowDown"?hn(e,1):(e.key==="ArrowLeft"||e.key==="ArrowUp")&&hn(e,-1)}function At(e){return(0,a.jsx)("span",{className:"wb-seg wb-term-style-seg",role:"radiogroup","aria-label":h("workbench.appearance.termStyleLabel"),onKeyDown:Re,children:gt.map(n=>(0,a.jsx)("button",{type:"button",role:"radio",className:`wb-seg-item${e.termStyle===n.value?" is-on":""}`,"aria-checked":e.termStyle===n.value,tabIndex:e.termStyle===n.value?0:-1,onClick:()=>vt(n.value),children:h(n.labelKey)},n.value))})}function fn(){let{appearance:e,skin:n}=kn();return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"wb-appearance-group",children:[(0,a.jsx)("span",{className:"wb-appearance-group-label",id:"wb-appearance-theme-label",children:h("workbench.appearance.themeGroup")}),(0,a.jsx)("span",{className:"wb-skin-swatches",role:"radiogroup","aria-labelledby":"wb-appearance-theme-label",onKeyDown:Re,children:Ae.map(t=>{let r=ln[t],o=n===t;return(0,a.jsxs)("button",{type:"button",role:"radio",className:`wb-skin-swatch${o?" is-active":""}`,"aria-checked":o,tabIndex:o?0:-1,title:h(dn[t]),onClick:()=>St(t),children:[(0,a.jsx)("span",{className:"wb-skin-swatch-chip","aria-hidden":"true",style:{"--sw-bg":r.bg,"--sw-raise":r.raise,"--sw-accent":r.accent}}),(0,a.jsx)("span",{className:"wb-skin-swatch-name",children:h(dn[t])})]},t)})}),(0,a.jsx)("span",{className:"wb-seg wb-appearance-mode-seg",role:"radiogroup","aria-label":h("workbench.appearance.modeLabel"),onKeyDown:Re,children:mt.map(t=>(0,a.jsx)("button",{type:"button",role:"radio",className:`wb-seg-item${e.mode===t.value?" is-on":""}`,"aria-checked":e.mode===t.value,tabIndex:e.mode===t.value?0:-1,onClick:()=>Wt(t.value),children:h(t.labelKey)},t.value))})]}),(0,a.jsxs)("div",{className:"wb-appearance-group",children:[(0,a.jsx)("span",{className:"wb-appearance-group-label",children:h("workbench.appearance.termGroup")}),(0,a.jsx)(At,{termStyle:e.termStyle}),(0,a.jsx)("p",{className:"wb-appearance-note",children:h("workbench.appearance.termNote")})]})]})}function mn(e){let[n,t]=(0,w.useState)(null),[r,o]=(0,w.useState)(!0),[s,l]=(0,w.useState)("idle"),p=(0,w.useRef)(null),{api:A}=e;(0,w.useEffect)(()=>{let k=typeof AbortController=="function"?new AbortController:null,b=!0;return A.getStandingLink(k?.signal).then(m=>{b&&(t(m?.url??null),o(!1))}),()=>{b=!1,k?.abort()}},[A]);let y=e.copy??Be,S=async()=>{n&&l(await y(n)?"copied":"failed")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{className:"wb-appearance-head",children:[(0,a.jsx)("strong",{children:h("workbench.standingLink.title")}),(0,a.jsx)("button",{type:"button","aria-label":h("workbench.appearance.close"),onClick:e.onClose,children:"\u2715"})]}),r?(0,a.jsx)("p",{className:"wb-standing-link-status",role:"status",children:h("workbench.standingLink.loading")}):n?(0,a.jsxs)("div",{className:"wb-standing-link-body",children:[(0,a.jsx)("textarea",{ref:p,className:"wb-standing-link-url",readOnly:!0,rows:3,value:n,"aria-label":h("workbench.standingLink.fieldLabel"),onFocus:k=>k.currentTarget.select(),onClick:k=>k.currentTarget.select()}),(0,a.jsx)("button",{type:"button",className:"wb-standing-link-copy",onClick:()=>{S()},children:s==="copied"?h("workbench.standingLink.copied"):s==="failed"?h("workbench.standingLink.copyFailed"):h("workbench.standingLink.copy")})]}):(0,a.jsx)("p",{className:"wb-standing-link-status",role:"status",children:h("workbench.standingLink.error")}),(0,a.jsx)("p",{className:"wb-standing-link-note wb-appearance-note",children:h("workbench.standingLink.note")})]})}function gn(e,n,t){(0,w.useEffect)(()=>{if(!e||typeof document>"u")return;let r=s=>{s.key==="Escape"&&n()},o=s=>{let l=s.target;l instanceof Node&&t.current&&!t.current.contains(l)&&n()};return document.addEventListener("keydown",r),document.addEventListener("mousedown",o),()=>{document.removeEventListener("keydown",r),document.removeEventListener("mousedown",o)}},[n,e,t])}function sr(e){let n=(0,w.useRef)(null),[t,r]=(0,w.useState)(!1),o=e.api??bn();return gn(e.open,e.onClose,n),(0,w.useEffect)(()=>{e.open||r(!1)},[e.open]),e.open?(0,a.jsx)("div",{className:"wb-appearance-backdrop",children:(0,a.jsx)("div",{ref:n,className:"wb-appearance-sheet",role:"dialog","aria-label":h("workbench.appearance.title"),children:t?(0,a.jsx)(mn,{api:o,onClose:e.onClose}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{className:"wb-appearance-head",children:[(0,a.jsx)("strong",{children:h("workbench.appearance.title")}),(0,a.jsx)("button",{type:"button","aria-label":h("workbench.appearance.close"),onClick:e.onClose,children:"\u2715"})]}),(0,a.jsx)(fn,{}),e.standingLink?(0,a.jsx)("div",{className:"wb-appearance-group",children:(0,a.jsx)("button",{type:"button",className:"wb-standing-link-open",onClick:()=>r(!0),children:h("workbench.standingLink.title")})}):null]})})}):null}function ar(e={}){let[n,t]=(0,w.useState)(null),r=(0,w.useRef)(null),o=(0,w.useRef)(null),s=e.api??bn(),l=(0,w.useCallback)(()=>{t(p=>(p!==null&&o.current?.focus(),null))},[]);return gn(n!==null,l,r),(0,a.jsxs)("div",{className:"wb-more",ref:r,children:[(0,a.jsx)("button",{ref:o,type:"button",className:"wb-more-btn","aria-haspopup":"menu","aria-expanded":n!==null,"aria-label":h("workbench.appearance.more"),title:h("workbench.appearance.more"),onClick:()=>t(p=>p===null?"menu":null),children:"\u22EF"}),n==="menu"?(0,a.jsxs)("div",{className:"wb-more-menu",role:"menu",children:[(0,a.jsx)("button",{type:"button",role:"menuitem",className:"wb-more-item",autoFocus:!0,onClick:()=>t("panel"),children:h("workbench.appearance.title")}),e.standingLink?(0,a.jsx)("button",{type:"button",role:"menuitem",className:"wb-more-item",onClick:()=>t("standing"),children:h("workbench.standingLink.title")}):null]}):null,n==="panel"?(0,a.jsxs)("div",{className:"wb-appearance-pop",role:"dialog","aria-label":h("workbench.appearance.title"),children:[(0,a.jsxs)("header",{className:"wb-appearance-head",children:[(0,a.jsx)("strong",{children:h("workbench.appearance.title")}),(0,a.jsx)("button",{type:"button","aria-label":h("workbench.appearance.close"),onClick:l,children:"\u2715"})]}),(0,a.jsx)(fn,{})]}):null,n==="standing"?(0,a.jsx)("div",{className:"wb-appearance-pop wb-standing-link-pop",role:"dialog","aria-label":h("workbench.standingLink.title"),children:(0,a.jsx)(mn,{api:s,onClose:l})}):null]})}var xt="botmux.agent-workbench.layout.v1:",wn="botmux.agent-workbench.rail.v1",Sn="botmux.agent-workbench.seen.v1",Wn="botmux.agent-workbench.group-dim.v1",vn="botmux.agent-workbench.collapsed.v1",Rt=500,Tt=200;function An(e){return`${xt}${encodeURIComponent(e)}`}function ur(e,n){if(!n)return H();try{let t=n.getItem(An(e));return t?me(JSON.parse(t)):H()}catch{return H()}}function dr(e,n,t){if(!t)return!1;try{return t.setItem(An(e),JSON.stringify(me(n))),!0}catch{return!1}}function pr(e){if(!e)return null;try{let n=e.getItem(wn);if(!n)return null;let t=JSON.parse(n);if(!t||typeof t!="object"||Array.isArray(t))return null;let r=t;return{railWidth:z(Number(r.railWidth)),railCollapsed:r.railCollapsed===!0}}catch{return null}}function hr(e,n){if(!e)return!1;try{return e.setItem(wn,JSON.stringify({railWidth:z(Number(n.railWidth)),railCollapsed:n.railCollapsed===!0})),!0}catch{return!1}}function te(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function yn(e,n){if(!te(e))return{};let t=[];for(let[r,o]of Object.entries(e)){let s=Number(o);!r||!Number.isFinite(s)||s<=0||t.push([r,s])}return t.length>n&&(t.sort((r,o)=>o[1]-r[1]),t.length=n),Object.fromEntries(t)}function xn(e,n=Rt){return{seen:yn(e.seen,n),unread:yn(e.unread,n)}}function br(e){if(!e)return null;try{let n=e.getItem(Sn);if(!n)return null;let t=JSON.parse(n);return!te(t)||!te(t.seen)&&!te(t.unread)?null:xn({seen:t.seen??{},unread:t.unread??{}})}catch{return null}}function kr(e,n){if(!e)return!1;try{return e.setItem(Sn,JSON.stringify(xn(n))),!0}catch{return!1}}function fr(e){if(!e)return null;try{let n=e.getItem(Wn);return K(n)?n:null}catch{return null}}function mr(e,n){if(!e||!K(n))return!1;try{return e.setItem(Wn,n),!0}catch{return!1}}function Rn(e,n=Tt){let t=e.filter(o=>typeof o=="string"&&o.length>0),r=[...new Set(t)];return r.length>n?r.slice(r.length-n):r}function Tn(e){if(!e)return null;try{let n=e.getItem(vn);if(!n)return null;let t=JSON.parse(n);return Array.isArray(t)?Rn(t):null}catch{return null}}function In(e,n){if(!e)return!1;try{return e.setItem(vn,JSON.stringify(Rn([...n]))),!0}catch{return!1}}var f=D(pe(),1);var c=D(j(),1),re=3e4,It=2e3;function Ct(e){let n=Number(e?.retryAfterSeconds);return Number.isFinite(n)&&n>0?Math.min(n*1e3,re):null}function Et(e){return(e instanceof Error?e.message:String(e??"")).trim()||"\u672A\u77E5\u9519\u8BEF"}var Cn={thread:{label:"\u8BDD\u9898",title:"\u8BDD\u9898\u4F1A\u8BDD"},group:{label:"\u7FA4",title:"\u7FA4\u4F1A\u8BDD"},p2p:{label:"\u5355\u804A",title:"\u5355\u804A\u4F1A\u8BDD"}},oe={"needs-you":"!",active:"\u25CF",recent:"\u21BA"},En="\u6709\u65B0\u56DE\u590D",Lt=new Set;function Ln(){if(typeof window>"u")return null;try{return window.localStorage}catch{return null}}function Nt(e){let n=e;return typeof n?.closest=="function"&&n.closest(".wb-session-group-toggle")!==null}function _t(e){return e.isNeedsYou?oe["needs-you"]:e.groupKey==="active"?oe.active:e.groupKey==="recent"?oe.recent:"\xB7"}function Pt(e){return e.isNeedsYou?"wb-session-group wb-session-group-needs-you":e.groupKey==="active"?"wb-session-group wb-session-group-active":e.groupKey==="recent"?"wb-session-group wb-session-group-recent":"wb-session-group"}function Te(e){return(0,c.jsx)("a",{className:e.className,href:e.href,target:"_blank",rel:"noopener",title:e.title,"aria-label":e.ariaLabel,onClick:n=>{n.stopPropagation(),e.onActivate?.()},children:e.children})}function Mt(e){let[n,t]=(0,f.useState)(560);return(0,f.useEffect)(()=>{let r=e.current;if(!r)return;let o=()=>t(Math.max(120,r.clientHeight||560));if(o(),typeof ResizeObserver>"u")return;let s=new ResizeObserver(o);return s.observe(r),()=>s.disconnect()},[e]),n}function Ie(e){let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return`wb-session-${(n>>>0).toString(36)}`}function Nn(e){return[e.botName,e.cliId,e.repoName].filter(Boolean).join(" \xB7 ")||e.sessionId}function Dt(){let[e,n]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{if(typeof window>"u"||!window.matchMedia)return;let t=window.matchMedia("(max-width: 620px)"),r=()=>n(t.matches);return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),e}function vr(e){let n=Dt(),[t,r]=(0,f.useState)(""),[o,s]=(0,f.useState)(0),l=(0,f.useRef)(null),p=(0,f.useRef)(e.selectedSessionId??null),A=Mt(l),[y,S]=(0,f.useState)(()=>new Map),[k,b]=(0,f.useState)(()=>new Map),[,m]=(0,f.useState)(0),[g,E]=(0,f.useState)(()=>new Set(Tn(Ln())??[])),ie=e.unreadIds??Lt,se=e.dimension??"status",Ce=Math.floor((e.now??Date.now())/6e4)*6e4,O=(0,f.useMemo)(()=>Ye(e.sessions,{query:t,dimension:se,unreadIds:ie,now:Ce}),[Ce,se,e.sessions,t,ie]),N=(0,f.useMemo)(()=>ze(O,g),[g,O]),P=(0,f.useMemo)(()=>qe(N,o,A,240,n),[N,o,n,A]),M=(0,f.useMemo)(()=>N.filter(i=>i.kind==="session"),[N]),_n=(0,f.useMemo)(()=>O.reduce((i,d)=>i+d.sessions.length,0),[O]),Ee=(0,f.useMemo)(()=>O.find(i=>i.kind==="needs-you")?.sessions.length??0,[O]);(0,f.useEffect)(()=>{if(!e.selectedSessionId){p.current=null;return}if(p.current===e.selectedSessionId||!M.some(u=>u.session.sessionId===e.selectedSessionId))return;p.current=e.selectedSessionId;let i=N.findIndex(u=>u.kind==="session"&&u.session.sessionId===e.selectedSessionId),d=P.positions[i]??0,x=d+Q(N[i],n),W=l.current;!W||d>=W.scrollTop&&x<=W.scrollTop+W.clientHeight||(W.scrollTop=Math.max(0,d-Math.round(W.clientHeight/3)))},[N,e.selectedSessionId,M,P.positions]),(0,f.useEffect)(()=>{if(y.size===0)return;let i=setInterval(()=>{S(d=>{let x=Date.now(),W=new Map([...d].filter(([,u])=>x-u<re));return W.size===d.size?d:W}),m(d=>d+1)},500);return()=>clearInterval(i)},[y]);let ae=e.onLocate,Pn=i=>{ae&&(S(d=>new Map(d).set(i,Date.now())),b(d=>{if(!d.has(i))return d;let x=new Map(d);return x.delete(i),x}),ae(i).then(()=>{S(d=>new Map(d).set(i,Date.now()))},d=>{b(W=>new Map(W).set(i,Et(d)));let x=Ct(d);S(W=>{let u=new Map(W);return x===null?u.delete(i):u.set(i,Date.now()-(re-x)),u})}))},Mn=i=>{let d=new Set(g);d.delete(i)||d.add(i),E(d),In(Ln(),d)},ce=i=>{if(M.length===0)return;let d=M.findIndex(W=>W.session.sessionId===e.selectedSessionId),x=d<0?i>0?0:M.length-1:Math.max(0,Math.min(M.length-1,d+i));e.onSelect(M[x].session.sessionId)},Le=i=>{r(i),s(0),l.current&&(l.current.scrollTop=0)},Dn=i=>{i.altKey||i.ctrlKey||i.metaKey||(i.key==="Enter"||i.key===" ")&&Nt(i.target)||(i.key==="j"||i.key==="ArrowDown"?(i.preventDefault(),ce(1)):i.key==="k"||i.key==="ArrowUp"?(i.preventDefault(),ce(-1)):i.key==="Enter"&&e.selectedSessionId&&(i.preventDefault(),e.onSelect(e.selectedSessionId),e.chatFollowNavigates&&typeof document<"u"&&document.getElementById(Ie(e.selectedSessionId))?.querySelector("a.wb-session-copy-link")?.focus()))};if(e.collapsed){let i=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("span",{"aria-hidden":"true",children:"\xBB"}),(0,c.jsx)("span",{className:"wb-rail-vertical-label",children:"\u4F1A\u8BDD"})]});return(0,c.jsxs)("aside",{className:"wb-session-rail is-collapsed","aria-label":"\u4F1A\u8BDD\u5217\u8868\uFF08\u5DF2\u6536\u8D77\uFF09",children:[e.onToggleCollapsed?(0,c.jsx)("button",{type:"button",className:"wb-rail-expand","aria-label":"\u5C55\u5F00\u4F1A\u8BDD\u5217\u8868",title:"\u5C55\u5F00\u4F1A\u8BDD\u5217\u8868",onClick:e.onToggleCollapsed,children:i}):(0,c.jsx)("div",{className:"wb-rail-expand","aria-label":"\u4F1A\u8BDD\u5217\u8868\uFF08\u5DF2\u6536\u8D77\uFF09",children:i}),(0,c.jsx)("span",{className:"wb-rail-count","aria-label":`${Ee} \u4E2A\u4F1A\u8BDD\u9700\u8981\u5904\u7406`,children:Ee})]})}return(0,c.jsxs)("aside",{className:"wb-session-rail","aria-label":"\u4F1A\u8BDD\u5217\u8868",children:[(0,c.jsxs)("div",{className:"wb-rail-heading",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:e.online?"is-online":"is-offline",title:e.online?"\u5B9E\u65F6\u8FDE\u63A5\u6B63\u5E38":"\u5DF2\u79BB\u7EBF\uFF0C\u663E\u793A\u6700\u540E\u5FEB\u7167","aria-hidden":"true",children:e.online?"\u25CF":"\u25CB"}),(0,c.jsx)("strong",{children:"\u4F1A\u8BDD"}),(0,c.jsx)("span",{children:e.sessions.length})]}),e.onDimensionChange?(0,c.jsx)("select",{className:"wb-group-dim","aria-label":"\u5206\u7EC4\u7EF4\u5EA6",value:se,onChange:i=>{let d=i.currentTarget.value;K(d)&&e.onDimensionChange?.(d)},children:ke.map(i=>(0,c.jsx)("option",{value:i.value,children:i.label},i.value))}):null,e.onOpenAppearance?(0,c.jsx)("button",{type:"button",className:"wb-appearance-btn","aria-haspopup":"dialog","aria-label":h("workbench.appearance.title"),title:h("workbench.appearance.title"),onClick:e.onOpenAppearance,children:"\u25D0"}):null,e.onToggleCollapsed?(0,c.jsx)("button",{type:"button","aria-label":"\u6536\u8D77\u4F1A\u8BDD\u5217\u8868",title:"\u6536\u8D77\u4F1A\u8BDD\u5217\u8868",onClick:e.onToggleCollapsed,children:"\xAB"}):null]}),(0,c.jsxs)("label",{className:"wb-session-search",children:[(0,c.jsx)("span",{className:"wb-visually-hidden",children:"\u641C\u7D22\u4F1A\u8BDD"}),(0,c.jsx)("span",{"aria-hidden":"true",children:"\u2315"}),(0,c.jsx)("input",{type:"search",placeholder:"\u641C\u7D22\u2026",value:t,onChange:i=>Le(i.currentTarget.value),onKeyDown:i=>{i.key==="ArrowDown"&&(i.preventDefault(),l.current?.focus(),ce(1))}}),t?(0,c.jsx)("button",{type:"button","aria-label":"\u6E05\u9664\u641C\u7D22",onClick:()=>Le(""),children:"\xD7"}):null]}),(0,c.jsxs)("div",{ref:l,className:"wb-session-list",role:"listbox",tabIndex:0,"aria-label":"\u5DE5\u4F5C\u53F0\u4F1A\u8BDD","aria-activedescendant":e.selectedSessionId?Ie(e.selectedSessionId):void 0,onScroll:i=>s(i.currentTarget.scrollTop),onKeyDown:Dn,children:[(0,c.jsx)("div",{className:"wb-session-list-space",style:{height:P.totalHeight},children:N.slice(P.start,P.end).map((i,d)=>{let x=P.start+d,W={top:P.positions[x],height:Q(i,n)};if(i.kind==="header"){let R=i.collapsed===!0;return(0,c.jsxs)("button",{type:"button",className:`${Pt(i)} wb-session-group-toggle`,style:W,"aria-expanded":!R,title:R?`\u5C55\u5F00\u300C${i.label}\u300D`:`\u6298\u53E0\u300C${i.label}\u300D`,onClick:()=>Mn(i.groupKey),children:[(0,c.jsx)("span",{className:"wb-session-group-caret","aria-hidden":"true",children:R?"\u25B8":"\u25BE"}),(0,c.jsx)("span",{"aria-hidden":"true",children:_t(i)}),(0,c.jsx)("strong",{children:i.label}),(0,c.jsx)("span",{children:i.count})]},i.key)}let u=i.session,_=ye(u),le=ie.has(u.sessionId),$=q(u)??(le?En:null),Ne=u.sessionId===e.selectedSessionId,On=i.group==="needs-you"?"\u5F85\u4F60\u5904\u7406":i.group==="active"?u.status:"\u6700\u8FD1",_e=e.onOpenTerminal,U=u.feishuChatLink||(u.chatId?Ze(u.chatId):null),F=ge(u);return(0,c.jsxs)("div",{id:Ie(u.sessionId),className:`wb-session-row wb-session-row-${i.group}${Ne?" is-selected":""}${le?" is-unread":""}`,role:"option",tabIndex:-1,"aria-selected":Ne,"aria-label":`${_}. ${On}${$?`. ${$}`:""}`,style:W,onClick:()=>e.onSelect(u.sessionId),children:[(0,c.jsx)("span",{className:"wb-session-state-mark","aria-hidden":"true",children:oe[i.group]}),(()=>{let R=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("span",{className:"wb-session-title",title:_,children:_}),(0,c.jsxs)("span",{className:"wb-session-meta",title:Nn(u),children:[F?(0,c.jsx)("span",{className:`wb-session-kind is-${F}`,title:Cn[F].title,children:Cn[F].label}):null,$?(0,c.jsx)("span",{className:"wb-session-reason",children:$}):(0,c.jsx)("span",{children:Nn(u)}),le?(0,c.jsx)("span",{className:"wb-unread-dot",role:"img","aria-label":En}):null,(0,c.jsx)("time",{dateTime:new Date(L(u)).toISOString(),children:Xe(L(u),e.now,e.locale)})]})]});return!e.chatFollowNavigates||!U?(0,c.jsx)("span",{className:"wb-session-copy",children:R}):(0,c.jsx)(Te,{className:"wb-session-copy wb-session-copy-link",href:U,ariaLabel:`\u9009\u4E2D\u5E76\u6253\u5F00\u98DE\u4E66\u804A\u5929 \u2014 ${_}`,onActivate:()=>e.onSelect(u.sessionId),children:R})})(),_e?(0,c.jsxs)("span",{className:"wb-session-row-actions",children:[U?(0,c.jsx)(Te,{className:"wb-session-row-action is-chat",href:U,title:"\u6253\u5F00\u98DE\u4E66\u804A\u5929",ariaLabel:`\u6253\u5F00\u98DE\u4E66\u804A\u5929 \u2014 ${_}`,onActivate:()=>e.onSeen?.(u.sessionId),children:"\u804A\u5929"}):null,F==="thread"&&ae?(()=>{let R=y.get(u.sessionId)??0,J=Date.now()-R,ue=R>0&&J<re,de=k.get(u.sessionId),Pe=ue&&!de&&J<It,Me=ue?"\u5B9A\u4F4D\u5DF2\u53D1\u9001\uFF0C30 \u79D2\u540E\u53EF\u518D\u6B21\u4F7F\u7528":de?`\u5B9A\u4F4D\u5931\u8D25\uFF1A${de}`:"\u5728\u8BDD\u9898\u91CC @ \u6211\u5B9A\u4F4D";return(0,c.jsx)("button",{type:"button",className:`wb-session-row-action is-locate${Pe?" is-located":""}`,title:Me,"aria-label":`${Me} \u2014 ${_}`,disabled:ue,onClick:Fn=>{Fn.stopPropagation(),e.onSeen?.(u.sessionId),Pn(u.sessionId)},children:Pe?"\u5DF2\u53D1\u9001":"\u5B9A\u4F4D"})})():null,F==="thread"&&u.feishuThreadLink?(0,c.jsx)(Te,{className:"wb-session-row-action is-jump",href:u.feishuThreadLink,title:"\u8DF3\u8F6C\u5230\u539F\u8BDD\u9898",ariaLabel:`\u8DF3\u8F6C\u5230\u539F\u8BDD\u9898 \u2014 ${_}`,onActivate:()=>e.onSeen?.(u.sessionId),children:"\u8DF3\u8F6C"}):null,(()=>{let R=e.fixedTerminal?"\u6253\u5F00\u7EC8\u7AEF\uFF08\u5F53\u524D\u8EAB\u4EFD\u53EF\u76F4\u63A5\u8F93\u5165\uFF09":"\u6253\u5F00\u53EA\u8BFB\u7EC8\u7AEF";return(0,c.jsx)("button",{type:"button",className:"wb-session-row-action is-terminal",title:R,"aria-label":`${R} \u2014 ${_}`,disabled:e.terminalBusySessionId===u.sessionId,onClick:J=>{J.stopPropagation(),_e(u.sessionId)},children:"\u7EC8\u7AEF"})})()]}):null]},i.key)})}),_n===0?(0,c.jsx)("p",{className:"wb-session-empty",children:"\u6CA1\u6709\u5339\u914D\u7684\u4F1A\u8BDD"}):null]})]})}var C=D(pe(),1);function xr(){let[e,n]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{if(typeof window>"u"||!window.matchMedia)return;let t=window.matchMedia("(hover: none)"),r=()=>n(typeof navigator<"u"&&navigator.maxTouchPoints>0||t.matches);return r(),t.addEventListener?.("change",r),()=>t.removeEventListener?.("change",r)},[]),e}function Rr(e){let{api:n,enabled:t,sessionId:r}=e,[o,s]=(0,C.useState)(null),[l,p]=(0,C.useState)("idle"),[A,y]=(0,C.useState)(0);(0,C.useEffect)(()=>{if(!t)return;let k=new AbortController,b;return s(m=>m?.sessionId===r?m:null),p("loading"),n.getTerminalViewLink(r,k.signal).then(m=>{if(!k.signal.aborted){if(m){s({sessionId:r,url:m.url,expiresAt:m.expiresAt}),p("ready");return}p("failed"),s(g=>g?.sessionId===r&&g.expiresAt!==null&&g.expiresAt<=Date.now()?null:g),b=setTimeout(()=>y(g=>g+1),8e3)}}),()=>{k.abort(),b!==void 0&&clearTimeout(b)}},[n,A,t,r]),(0,C.useEffect)(()=>{if(l!=="ready"||o?.expiresAt==null)return;let k=o.expiresAt-Date.now()-3e4,b=setTimeout(()=>y(m=>m+1),Math.max(5e3,k));return()=>clearTimeout(b)},[o,l]);let S=(0,C.useCallback)(()=>{p("loading"),y(k=>k+1)},[]);return{link:o,phase:l,retry:S}}export{Y as a,fe as b,Ot as c,z as d,Gn as e,Ft as f,L as g,ye as h,Kt as i,Xe as j,Bt as k,qn as l,Gt as m,Ze as n,Ut as o,Jt as p,Yt as q,v as r,nn as s,Xt as t,Qt as u,Zt as v,kn as w,ir as x,At as y,sr as z,ar as A,ur as B,dr as C,pr as D,hr as E,xn as F,br as G,kr as H,fr as I,mr as J,vr as K,xr as L,Rr as M};
@@ -1 +1 @@
1
- import{H as i,L as c,b as r}from"./chunk-K232GT3M.js";var l={chats:[],bots:[]};async function A(){try{l=await r()}catch{}}var p=new Set(["working","analyzing","active","starting"]);function m(d){let s=new Map,e=t=>{let a=s.get(t);return a||(a={botName:t,larkAppId:t,cliId:"unknown",online:!1,sessions:[],active:[],busy:[],attention:[],lastActiveAt:0},s.set(t,a)),a};for(let t of l.bots??[]){let a=e(t.larkAppId??t.botName??"-");a.online=!0,t.botName&&(a.botName=t.botName),t.botAvatarUrl&&(a.botAvatarUrl=t.botAvatarUrl),t.cliId&&(a.cliId=t.cliId),t.brand&&(a.brand=t.brand)}let b=[...d].sort((t,a)=>+(t.status==="closed")-+(a.status==="closed"));for(let t of b){let a=t.larkAppId??t.botName??"-";if(t.status==="closed"&&!s.has(a))continue;let o=e(a);t.botName&&(o.botName===o.larkAppId||!o.botName)&&(o.botName=t.botName),o.sessions.push(t),t.cliId&&o.cliId==="unknown"&&(o.cliId=t.cliId),o.lastActiveAt=Math.max(o.lastActiveAt,Number(t.lastMessageAt??0)),t.status!=="closed"&&(o.active.push(t),p.has(t.status)&&o.busy.push(t),c(t)&&o.attention.push(t))}for(let t of s.values())if(t.botName===t.larkAppId){let a=i(t.larkAppId);a&&(t.botName=a)}return[...s.values()].sort((t,a)=>{let o=n=>n.attention.length?0:n.busy.length?1:n.online||n.active.length?2:3;return o(t)!==o(a)?o(t)-o(a):a.lastActiveAt-t.lastActiveAt})}export{A as a,m as b};
1
+ import{I as i,M as c,b as r}from"./chunk-IRFGJSPL.js";var l={chats:[],bots:[]};async function m(){try{l=await r()}catch{}}var p=new Set(["working","analyzing","active","starting"]);function A(d){let s=new Map,e=t=>{let a=s.get(t);return a||(a={botName:t,larkAppId:t,cliId:"unknown",online:!1,sessions:[],active:[],busy:[],attention:[],lastActiveAt:0},s.set(t,a)),a};for(let t of l.bots??[]){let a=e(t.larkAppId??t.botName??"-");a.online=!0,t.botName&&(a.botName=t.botName),t.botAvatarUrl&&(a.botAvatarUrl=t.botAvatarUrl),t.cliId&&(a.cliId=t.cliId),t.brand&&(a.brand=t.brand)}let b=[...d].sort((t,a)=>+(t.status==="closed")-+(a.status==="closed"));for(let t of b){let a=t.larkAppId??t.botName??"-";if(t.status==="closed"&&!s.has(a))continue;let o=e(a);t.botName&&(o.botName===o.larkAppId||!o.botName)&&(o.botName=t.botName),o.sessions.push(t),t.cliId&&o.cliId==="unknown"&&(o.cliId=t.cliId),o.lastActiveAt=Math.max(o.lastActiveAt,Number(t.lastMessageAt??0)),t.status!=="closed"&&(o.active.push(t),p.has(t.status)&&o.busy.push(t),c(t)&&o.attention.push(t))}for(let t of s.values())if(t.botName===t.larkAppId){let a=i(t.larkAppId);a&&(t.botName=a)}return[...s.values()].sort((t,a)=>{let o=n=>n.attention.length?0:n.busy.length?1:n.online||n.active.length?2:3;return o(t)!==o(a)?o(t)-o(a):a.lastActiveAt-t.lastActiveAt})}export{m as a,A as b};
@@ -0,0 +1 @@
1
+ import{a as C}from"./chunk-ARROO6TE.js";import{c as L,d as S,e as R}from"./chunk-3YZFAHNK.js";var i=L(S(),1),x=L(C(),1),t=L(R(),1);function D(e,o){return e.find(a=>a.value===o)?.label??o}function O(e){let o=e.as??"span";return(0,t.jsx)(o,{style:{display:"contents"},dangerouslySetInnerHTML:{__html:e.html}})}function A(e){let o=["page-loading",e.compact?"page-loading-compact":"",e.className].filter(Boolean).join(" ");return(0,t.jsxs)("div",{className:o,role:"status","aria-live":"polite",children:[(0,t.jsx)("i",{className:"page-loading-spin","aria-hidden":"true"}),(0,t.jsx)("span",{children:e.label})]})}function J(e){return(0,t.jsxs)("div",{className:"sect-head overview-panel-head",children:[(0,t.jsx)("h2",{children:e.title}),e.count?(0,t.jsx)("span",{className:"sect-head-count",children:e.count}):null,e.hint?(0,t.jsx)("span",{className:"sect-head-hint",children:e.hint}):null,e.children]})}function X(e){return(0,t.jsx)("a",{className:"sect-head-action",href:e.href,children:e.children})}function z(e){return(0,t.jsx)("div",{className:"sect-head-controls",children:e.children})}function M(e){return e.kind==="plus"?(0,t.jsx)("svg",{className:"ui-action-icon",viewBox:"0 0 16 16","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M8 3.25v9.5M3.25 8h9.5"})}):(0,t.jsxs)("svg",{className:"ui-action-icon",viewBox:"0 0 16 16","aria-hidden":"true",children:[(0,t.jsx)("path",{d:"M13.1 6.55A5.35 5.35 0 1 0 13 10.1"}),(0,t.jsx)("path",{d:"M13.15 2.95v3.7H9.45"})]})}function j(e){let{children:o,className:a,type:l="button",...u}=e;return(0,t.jsxs)("button",{...u,type:l,className:["ui-create-action",a].filter(Boolean).join(" "),children:[(0,t.jsx)(M,{kind:"plus"}),(0,t.jsx)("span",{className:"ui-create-action-label",children:o})]})}function I(e){let{label:o,busy:a=!1,className:l,type:u="button",...d}=e;return(0,t.jsx)("button",{...d,type:u,className:["ui-refresh-button",a?"is-loading":"",l].filter(Boolean).join(" "),title:o,"aria-label":o,"aria-busy":a||void 0,children:(0,t.jsx)(M,{kind:"refresh"})})}function H(e,o){return e?.closest("dialog[open]")??o}function P(e){let o=(0,i.useRef)(null),a=(0,i.useRef)(null),[l,u]=(0,i.useState)(!1),[d,v]=(0,i.useState)(null),f=(0,i.useCallback)(()=>{let b=o.current;if(!b||typeof window>"u")return;let n=b.getBoundingClientRect(),r=Math.min(360,Math.max(160,window.innerWidth-48)),c=24+r/2,s=window.innerWidth-24-r/2,p=n.left+n.width/2,g=Math.min(Math.max(p,c),Math.max(c,s)),N=n.top<80;v({left:g,top:N?n.bottom+8:n.top-8,placement:N?"bottom":"top"})},[]),h=(0,i.useCallback)(()=>{a.current&&(clearTimeout(a.current),a.current=null),f(),u(!0)},[f]),m=(0,i.useCallback)(()=>{a.current&&clearTimeout(a.current),a.current=setTimeout(()=>u(!1),160)},[]);(0,i.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),(0,i.useEffect)(()=>{if(l)return f(),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[l,f]);let w=l&&d&&typeof document<"u"?(0,x.createPortal)((0,t.jsx)("span",{className:`ui-info-pop ui-info-pop-floating ui-info-pop-${d.placement}`,role:"tooltip",style:{left:d.left,top:d.top},onMouseEnter:h,onMouseLeave:m,children:e.children}),H(o.current,document.body)):null;return(0,t.jsxs)("span",{ref:o,className:["ui-info-tip",e.className].filter(Boolean).join(" "),tabIndex:e.focusable===!1?void 0:0,"aria-label":e.label,onClick:e.preventClick===!1?void 0:b=>b.preventDefault(),onMouseEnter:h,onMouseLeave:m,onFocus:h,onBlur:m,children:[e.trigger??(0,t.jsx)("span",{className:"ui-info-mark","aria-hidden":"true",children:"?"}),w]})}function W(e){let o=(0,i.useRef)(null),[a,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(!1),[v,f]=(0,i.useState)(null),h=(0,i.useCallback)(()=>{let r=o.current;if(!r)return!1;let s=(r.querySelector(".ui-overflow-scroll")??r).scrollWidth>r.clientWidth+1;return d(s),s||l(!1),s},[]),m=(0,i.useCallback)(()=>{let r=o.current;if(!r||typeof window>"u")return;let c=r.getBoundingClientRect(),s=Math.min(460,Math.max(220,window.innerWidth-48)),p=24+s/2,g=window.innerWidth-24-s/2,N=c.left+c.width/2,E=Math.min(Math.max(N,p),Math.max(p,g)),y=c.top<84;f({left:E,top:y?c.bottom+8:c.top-8,placement:y?"bottom":"top"})},[]),w=(0,i.useCallback)(()=>{if(!(!e.text.trim()||!h())){if(e.showPopover===!1){l(!1);return}m(),l(!0)}},[h,e.showPopover,e.text,m]),b=(0,i.useCallback)(()=>l(!1),[]);(0,i.useEffect)(()=>{let r=o.current;if(!r||typeof window>"u")return;let c=window.requestAnimationFrame(h),s=typeof ResizeObserver<"u"?new ResizeObserver(()=>h()):null;return s?.observe(r),window.addEventListener("resize",h),()=>{window.cancelAnimationFrame(c),s?.disconnect(),window.removeEventListener("resize",h)}},[h,e.text]),(0,i.useEffect)(()=>{if(a)return m(),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),()=>{window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0)}},[a,m]);let n=e.showPopover!==!1&&a&&v&&typeof document<"u"?(0,x.createPortal)((0,t.jsx)("span",{className:["ui-info-pop","ui-info-pop-floating",`ui-info-pop-${v.placement}`,"ui-overflow-popover",e.popoverClassName].filter(Boolean).join(" "),role:"tooltip",style:{left:v.left,top:v.top},children:e.text}),H(o.current,document.body)):null;return(0,t.jsxs)("span",{ref:o,className:["ui-overflow-text",u?"is-overflowing":"",e.className].filter(Boolean).join(" "),style:e.durationMs?{"--ui-overflow-duration":`${e.durationMs}ms`}:void 0,onMouseEnter:w,onMouseLeave:b,children:[(0,t.jsx)("span",{className:["ui-overflow-scroll",e.textClassName].filter(Boolean).join(" "),children:e.children??e.text}),n]})}function U(e){return(0,t.jsxs)("span",{className:["ui-field-title",e.className].filter(Boolean).join(" "),children:[(0,t.jsx)("span",{className:"ui-field-title-text",children:e.children}),e.help?(0,t.jsx)(P,{label:e.helpLabel,children:e.help}):null]})}function F(e){return(0,t.jsx)("ul",{className:["overview-list",e.className].filter(Boolean).join(" "),id:e.id,children:e.children})}function q(e){let{kind:o,className:a,children:l,...u}=e,d=o?`overview-list-item-${o}`:"";return(0,t.jsx)("li",{...u,className:["overview-list-item",d,a].filter(Boolean).join(" "),children:l})}function $(e){return(0,t.jsx)("div",{className:"overview-list-main",children:e.children})}function K(e){return(0,t.jsx)("div",{className:"overview-list-tail",children:e.children})}function T(e){let l=e.viewportHeight-e.triggerBottom-8-12,u=e.triggerTop-8-12,d=e.forceDropUp??(e.naturalHeight>l&&u>l),v=Math.max(140,Math.floor(d?u:l));return{dropUp:d,maxHeight:v}}function k(e){let o=(0,i.useRef)(null),a=(0,i.useRef)(null),l=(0,i.useRef)(null),[u,d]=(0,i.useState)(""),[v,f]=(0,i.useState)(!1),h=n=>{o.current?.removeAttribute("open"),f(!1),n!==e.value&&e.onChange(n)},m=u.trim().toLowerCase(),w=e.searchable&&m?e.options.filter(n=>n.value.toLowerCase().includes(m)||typeof n.label=="string"&&n.label.toLowerCase().includes(m)):e.options;(0,i.useLayoutEffect)(()=>{if(!v)return;let n=()=>{let c=o.current,s=l.current;if(!c||!s)return;let p=c.getBoundingClientRect(),{dropUp:g,maxHeight:N}=T({triggerTop:p.top,triggerBottom:p.bottom,naturalHeight:s.scrollHeight,viewportHeight:window.innerHeight});c.classList.toggle("is-drop-up",g);let E=s.getBoundingClientRect(),y=E.height>0&&E.bottom<=p.top+1,B=y===g?N:T({triggerTop:p.top,triggerBottom:p.bottom,naturalHeight:s.scrollHeight,viewportHeight:window.innerHeight,forceDropUp:y}).maxHeight;s.style.setProperty("--dropdown-popover-space",`${B}px`)},r=window.requestAnimationFrame(n);return window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{window.cancelAnimationFrame(r),window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0)}},[v,w.length]),(0,i.useEffect)(()=>{if(typeof document>"u")return;let n=()=>{o.current?.open&&(o.current.open=!1),f(!1)},r=s=>{let p=o.current;if(!p?.open)return;let g=s.target;g instanceof Node&&p.contains(g)||n()},c=s=>{s.key==="Escape"&&n()};return document.addEventListener("pointerdown",r,!0),document.addEventListener("keydown",c),()=>{document.removeEventListener("pointerdown",r,!0),document.removeEventListener("keydown",c)}},[]),(0,i.useEffect)(()=>{e.disabled&&(o.current?.open&&(o.current.open=!1),f(!1))},[e.disabled]);let b=["sect-sort-menu",e.disabled?"is-disabled":"",e.className].filter(Boolean).join(" ");return(0,t.jsxs)("details",{id:e.id,className:b,ref:o,hidden:e.hidden,style:e.style,onToggle:n=>{let r=n.currentTarget.open;f(r),!(!e.searchable||!r)&&(d(""),a.current?.focus())},children:[(0,t.jsx)("summary",{"aria-label":e.ariaLabel,"aria-disabled":e.disabled?!0:void 0,tabIndex:e.disabled?-1:void 0,onClick:n=>{e.disabled&&n.preventDefault()},onKeyDown:n=>{e.disabled&&(n.key==="Enter"||n.key===" ")&&n.preventDefault()},children:(0,t.jsx)("span",{className:"sect-sort-value",children:e.label})}),(0,t.jsxs)("div",{className:"sect-sort-pop",ref:l,children:[e.searchable?(0,t.jsx)("input",{ref:a,className:"sect-sort-search",type:"search",placeholder:e.searchPlaceholder,"aria-label":e.searchPlaceholder,autoComplete:"off",spellCheck:!1,value:u,onChange:n=>d(n.currentTarget.value),onKeyDown:n=>{if(n.key!=="Enter")return;n.preventDefault();let r=w.find(c=>!c.disabled);r&&h(r.value)}}):null,w.map(n=>(0,t.jsx)("button",{type:"button",disabled:n.disabled,"aria-current":e.value===n.value?"true":void 0,onClick:()=>h(n.value),children:n.label},n.value)),e.searchable&&w.length===0?(0,t.jsx)("p",{className:"sect-sort-empty",children:e.searchEmptyLabel}):null]})]})}function _(e){return(0,t.jsx)(k,{...e})}export{D as a,O as b,A as c,J as d,X as e,z as f,j as g,I as h,H as i,P as j,W as k,U as l,F as m,q as n,$ as o,K as p,k as q,_ as r};
@@ -1 +1 @@
1
- import{a as q,b as V}from"./chunk-EVK77ASG.js";import{a as ce}from"./chunk-ZJVTGU5X.js";import{a as Fe}from"./chunk-CEUCNZFJ.js";import{a as ie,c as de,g as Se,l as T,q as ue}from"./chunk-NYY66DNC.js";import{d as _}from"./chunk-R3LJUCEO.js";import"./chunk-QITAMHW6.js";import"./chunk-K232GT3M.js";import{c as re}from"./chunk-ARROO6TE.js";import{c as j,d as Pe,e as le}from"./chunk-3YZFAHNK.js";var i=j(Pe(),1);var p=j(Pe(),1);var n=j(le(),1),We=50,Ne={total:0,ok:0,error:0,successRate:0};function _e(o,e=Date.now()){if(o==="all")return;let s=o==="24h"?24:o==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function Ue(o,e=0){let s=new URLSearchParams({limit:String(We),offset:String(e)});o.connectorId&&s.set("connectorId",o.connectorId),o.status&&s.set("status",o.status);let d=_e(o.timeWindow);return d&&s.set("since",d),o.query.trim()&&s.set("q",o.query.trim()),s}function Ee(o){if(!o)return"\u2014";let e=new Date(o);return Number.isFinite(e.getTime())?e.toLocaleString():o}function ge(o){return o===void 0||!Number.isFinite(o)?"\u2014":o<1e3?`${Math.round(o)} ms`:o<6e4?`${(o/1e3).toFixed(o<1e4?1:0)} s`:`${(o/6e4).toFixed(1)} min`}function Je(o){return o===void 0?"\u2014":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/1024/1024).toFixed(1)} MB`}function Le(o){return o.value===void 0||o.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):typeof o.value=="object"&&!Array.isArray(o.value)&&Object.keys(o.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${o.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(o.value,null,2)})})}function Xe(o){let e=[["kind",o.value?.kind],["mode",o.value?.mode],["botId",o.value?.botId],["chatId",o.value?.chatId],["sessionId",o.value?.sessionId],["rootMessageId",o.value?.rootMessageId],["workflowId",o.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,d])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(d)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function Ie(o){return(0,n.jsx)(ue,{id:o.id,className:"webhook-log-filter-menu",ariaLabel:o.label,style:{width:"100%",minWidth:0},value:o.value,label:ie(o.options,o.value),options:o.options,onChange:o.onChange})}function me(o){return(0,n.jsxs)("article",{className:`card webhook-log-metric${o.tone?` ${o.tone}`:""}`,children:[(0,n.jsx)("span",{children:o.label}),(0,n.jsx)("strong",{children:o.value}),(0,n.jsx)("small",{children:o.hint||"\xA0"})]})}function Re(o={}){let e=_(),s=(0,p.useRef)(!1),d=(0,p.useRef)([]),[f,N]=(0,p.useState)([]),[y,I]=(0,p.useState)([]),[k,R]=(0,p.useState)(Ne),[L,$]=(0,p.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[u,r]=(0,p.useState)(null),[E,U]=(0,p.useState)(!0),[v,J]=(0,p.useState)(!1),[A,X]=(0,p.useState)(!1),[Y,Z]=(0,p.useState)(0),[B,x]=(0,p.useState)(""),[K,ee]=(0,p.useState)(!1),M=(0,p.useMemo)(()=>new Map(f.map(c=>[c.id,c.name])),[f]),g=(0,p.useMemo)(()=>y.find(c=>c.triggerId===u)??y[0]??null,[y,u]),te=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...f.map(c=>({value:c.id,label:c.name}))],[f,e]),G=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),fe=(0,p.useMemo)(()=>[{value:"24h",label:e("webhookLogs.last24h")},{value:"7d",label:e("webhookLogs.last7d")},{value:"30d",label:e("webhookLogs.last30d")},{value:"all",label:e("webhookLogs.allTime")}],[e]),H=(0,p.useCallback)(async(c=!1,w=!1)=>{w?J(!0):U(!0),x("");let Q=c?d.current.length:0,oe=Ue(L,Q),h=new URLSearchParams(oe);h.delete("limit"),h.delete("offset");try{let[S,ne]=await Promise.all([q(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):q(`/api/trigger-logs/summary?${h}`)]);if(!s.current)return;if(S.status!==200)throw new Error(String(S.body?.error||S.status));let P=Array.isArray(S.body?.logs)?S.body.logs:[],ae=c?[...d.current,...P]:P;d.current=ae,I(ae),Z(Number(S.body?.total??P.length)),X(S.body?.hasMore===!0),c||(R(ne?.status===200?ne.body?.summary??Ne:Ne),r(se=>P.some(we=>we.triggerId===se)?se:P[0]?.triggerId??null))}catch(S){s.current&&x(S?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(U(!1),J(!1))}},[L,e]);(0,p.useEffect)(()=>(s.current=!0,q("/api/connectors").then(c=>{s.current&&c.status===200&&N(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,p.useEffect)(()=>{let c=setTimeout(()=>{H(!1)},L.query?260:0);return()=>clearTimeout(c)},[L,H]),(0,p.useEffect)(()=>{let c=setInterval(()=>{H(!1,!0)},15e3);return()=>clearInterval(c)},[H]);async function ye(){!g||!await ce(JSON.stringify(g,null,2),e("webhookLogs.copyJson"))||(ee(!0),setTimeout(()=>s.current&&ee(!1),1200))}let ke=g?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):g?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),z=(0,n.jsxs)(n.Fragment,{children:[o.embedded?null:(0,n.jsxs)("div",{className:"page-heading",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,n.jsx)("h1",{children:e("nav.webhookLogs")}),(0,n.jsx)("p",{className:"webhook-log-heading-copy",children:e("webhookLogs.subtitle")})]}),(0,n.jsxs)("div",{className:"page-heading-actions",children:[(0,n.jsxs)("span",{className:`webhook-log-live${v?" refreshing":""}`,children:[(0,n.jsx)("i",{}),e("webhookLogs.autoRefresh")]}),(0,n.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})]})]}),(0,n.jsxs)("section",{className:"webhook-log-metrics","aria-label":e("webhookLogs.summary"),children:[(0,n.jsx)(me,{label:e("webhookLogs.total"),value:k.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(me,{label:e("webhookLogs.successRate"),value:`${k.successRate.toFixed(k.successRate%1?1:0)}%`,tone:"ok",hint:`${k.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(me,{label:e("webhookLogs.failures"),value:k.error,tone:k.error?"error":void 0,hint:k.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(me,{label:e("webhookLogs.p95"),value:ge(k.p95DurationMs),hint:`${e("webhookLogs.average")} ${ge(k.avgDurationMs)}`})]}),(0,n.jsxs)("form",{className:"filters dashboard-toolbar webhook-log-toolbar",onSubmit:c=>c.preventDefault(),children:[(0,n.jsx)("input",{type:"search",name:"q","aria-label":e("webhookLogs.search"),placeholder:e("webhookLogs.searchPlaceholder"),value:L.query,onChange:c=>{let w=c.currentTarget.value;$(Q=>({...Q,query:w}))}}),(0,n.jsx)(Ie,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:L.connectorId,options:te,onChange:c=>$(w=>({...w,connectorId:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-status",label:e("webhookLogs.status"),value:L.status,options:G,onChange:c=>$(w=>({...w,status:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:L.timeWindow,options:fe,onChange:c=>$(w=>({...w,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:v,onClick:()=>{H(!1,!0)},children:e("webhookLogs.refresh")})]}),B?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",B]}):null,(0,n.jsxs)("section",{className:"webhook-log-workspace",children:[(0,n.jsxs)("article",{className:"card webhook-log-list-panel",children:[(0,n.jsx)("header",{className:"webhook-log-panel-head",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{children:e("webhookLogs.records")}),(0,n.jsx)("span",{children:e("webhookLogs.matching",{count:Y})})]})}),E&&!y.length?(0,n.jsx)(de,{label:e("webhookLogs.loading"),compact:!0}):null,!E&&!y.length?(0,n.jsxs)("div",{className:"webhook-log-empty",children:[(0,n.jsx)("span",{"aria-hidden":"true",children:"\u25CE"}),(0,n.jsx)("strong",{children:e("webhookLogs.empty")}),(0,n.jsx)("p",{children:e("webhookLogs.emptyHint")})]}):null,(0,n.jsx)("div",{className:"webhook-log-list",role:"listbox","aria-label":e("webhookLogs.records"),children:y.map(c=>{let w=g?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":w,className:`webhook-log-row${w?" active":""}`,onClick:()=>r(c.triggerId),children:[(0,n.jsx)("span",{className:`webhook-log-status-dot ${c.status}`,"aria-hidden":"true"}),(0,n.jsxs)("span",{className:"webhook-log-row-main",children:[(0,n.jsxs)("span",{className:"webhook-log-row-title",children:[(0,n.jsx)("strong",{children:M.get(c.connectorId||"")||c.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsx)("code",{children:c.request?.method||"POST"})]}),(0,n.jsxs)("span",{className:"webhook-log-row-meta",children:[(0,n.jsx)("span",{children:Ee(c.createdAt)}),(0,n.jsx)("span",{children:c.errorCode||c.action})]})]}),(0,n.jsxs)("span",{className:"webhook-log-row-result",children:[(0,n.jsx)("b",{className:c.status,children:c.response?.httpStatus??(c.status==="ok"?"2xx":"ERR")}),(0,n.jsx)("small",{children:ge(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),A?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:E,onClick:()=>{H(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:g?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("header",{className:"webhook-log-detail-head",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:`webhook-log-result-pill ${g.status}`,children:g.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:M.get(g.connectorId||"")||g.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Ee(g.createdAt)," \xB7 ",g.request?.method||"POST"," ",g.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{ye()},children:e(K?"webhookLogs.copied":"webhookLogs.copyJson")})]}),g.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:g.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:g.error})]}):null,(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.overview")}),(0,n.jsxs)("dl",{className:"webhook-log-facts",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.httpStatus")}),(0,n.jsx)("dd",{children:g.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:ge(g.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:g.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:Je(g.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.requestId||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.remoteAddress")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.request?.remoteAddress||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.target")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.target?.chatId||g.target?.sessionId||g.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(Le,{value:g.request?.query,empty:e("webhookLogs.none")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.headers"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),(0,n.jsx)(Le,{value:g.request?.headers,empty:e("webhookLogs.headersNotStored")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.payload"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),g.request?.payloadStored?(0,n.jsx)(Le,{value:g.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:ke})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(Xe,{value:g.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return o.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:z}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:z})}var t=j(le(),1);function Ke(o,e){return o.map(s=>s.id===e.id?e:s)}var De={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,verify:"token",secret:"",storePayload:!0};function mt(o,e){return{promptEnvelope:{sourceName:o.promptEnvelope?.sourceName||o.name,instruction:e}}}function je(o,e,s){let d=e.trim();if(o!=="template")return{ok:!0,value:o==="custom"?{mode:o,text:d}:{mode:o}};try{let f=JSON.parse(s);return!f||typeof f!="object"||Array.isArray(f)?{ok:!1,error:"connectors.errTopicExtractors"}:{ok:!0,value:{mode:o,text:d,extractors:f}}}catch{return{ok:!1,error:"connectors.errTopicExtractors"}}}function ze(o){return[{value:"turn",label:o("connectors.kindTurn")},{value:"workflow",label:o("connectors.kindWorkflowRetiring"),disabled:!0}]}function be(o){return`${location.origin}/webhook/${encodeURIComponent(o)}`}function pe(o){return(0,t.jsx)(ue,{id:o.id,className:"connector-form-menu",ariaLabel:o.label,value:o.value,label:ie(o.options,o.value),options:o.options,onChange:o.onChange})}function Oe(o){let e=(0,i.useRef)(null),[s,d]=(0,i.useState)(!1),[f,N]=(0,i.useState)(""),y=Array.isArray(o.value)?o.value:o.value?[o.value]:[],I=(0,i.useMemo)(()=>new Set(y),[y]),k=f.trim().toLocaleLowerCase(),R=(0,i.useMemo)(()=>k?o.groups.filter(u=>`${u.name} ${u.chatId}`.toLocaleLowerCase().includes(k)):o.groups,[k,o.groups]),L=o.multiple?y.length===0?o.allLabel||o.placeholder:o.selectedCountLabel(y.length):o.groups.find(u=>u.chatId===y[0])?.name||y[0]||o.placeholder;(0,i.useEffect)(()=>{if(!s)return;let u=r=>{e.current?.contains(r.target)||d(!1)};return document.addEventListener("pointerdown",u),()=>document.removeEventListener("pointerdown",u)},[s]);function $(u){if(!o.multiple){o.onChange(u),d(!1),N("");return}o.onChange(I.has(u)?y.filter(r=>r!==u):[...y,u])}return(0,t.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,t.jsxs)("button",{id:o.id,type:"button",className:"connector-group-picker-trigger","aria-label":o.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>d(u=>!u),children:[(0,t.jsx)("span",{className:y.length||o.multiple&&o.allLabel?"":"muted",children:L}),(0,t.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,t.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,t.jsxs)("label",{className:"connector-group-search",htmlFor:`${o.id}-search`,children:[(0,t.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,t.jsx)("input",{id:`${o.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:f,placeholder:o.searchPlaceholder,onChange:u=>N(u.currentTarget.value),onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),d(!1))}})]}),(0,t.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":o.label,"aria-multiselectable":o.multiple||void 0,children:[o.multiple&&o.allLabel&&!k?(0,t.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${y.length===0?" selected":""}`,role:"option","aria-selected":y.length===0,onClick:()=>o.onChange([]),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:o.allLabel}),(0,t.jsx)("small",{children:o.placeholder})]})]}):null,R.map(u=>{let r=I.has(u.chatId);return(0,t.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>$(u.chatId),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:u.name||u.chatId}),u.name?(0,t.jsx)("small",{children:u.chatId}):null]})]},u.chatId)}),R.length?null:(0,t.jsx)("p",{className:"connector-group-empty",children:o.emptyLabel})]})]}):null]})}function he(o,e){return o.filter(s=>s.bots.includes(e))}function Qe(o,e){let s=o.target.chatId||"",d=s&&he(e,o.target.botId).some(f=>f.chatId===s);return{name:o.name,botId:o.target.botId,kind:o.target.kind,workflowId:o.target.workflowId||"",mode:o.target.mode,chatId:d?s:"",manualChat:!!(s&&!d),manualChatId:d?"":s,allowChats:o.target.allowChats||[],deduplicate:!!o.lifecycleExtractors?.dedupKey,dedup:o.lifecycleExtractors?.dedupKey||"",instruction:o.promptEnvelope?.instruction||"",topicMessageMode:o.topicMessage?.mode||"default",topicMessageText:o.topicMessage?.text||"",topicMessageExtractors:JSON.stringify(o.topicMessage?.extractors||{},null,2),suppressFinalOutput:o.suppressFinalOutput===!0,verify:o.verify?.type||"token",secret:"",storePayload:o.loggingPolicy?.storePayload!==!1}}function Ve(o){let e=_(),s=o.active==="webhooks",d=o.active==="logs";return(0,t.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,t.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,t.jsx)("a",{href:"#/connectors/logs",className:`itab${d?" on":""}`,role:"tab","aria-selected":d,children:e("connectors.tabLogs")})]})}function $e(o){let e=_(),s=(0,i.useRef)(!1),d=(0,i.useRef)(null),f=(0,i.useRef)(null),[N,y]=(0,i.useState)([]),[I,k]=(0,i.useState)([]),[R,L]=(0,i.useState)([]),[$,u]=(0,i.useState)(!0),[r,E]=(0,i.useState)(De),[U,v]=(0,i.useState)(null),[J,A]=(0,i.useState)(null),[X,Y]=(0,i.useState)(!1),[Z,B]=(0,i.useState)(!1),[x,K]=(0,i.useState)(null),[ee,M]=(0,i.useState)(null),[g,te]=(0,i.useState)(null),G=(0,i.useMemo)(()=>he(I,r.botId),[I,r.botId]),fe=(0,i.useMemo)(()=>N.length?N.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[N,e]),H=(0,i.useMemo)(()=>ze(e),[e]),ye=(0,i.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),ke=(0,i.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),z=(0,i.useCallback)(a=>I.find(b=>b.chatId===a)?.name||a,[I]),c=(0,i.useCallback)((a,l)=>{E(b=>{let F=b.botId&&a.some(O=>O.larkAppId===b.botId)?b.botId:a[0]?.larkAppId??"",C=he(l,F),m=b.chatId&&C.some(O=>O.chatId===b.chatId)?b.chatId:C[0]?.chatId??"",D=new Set(C.map(O=>O.chatId));return{...b,botId:F,chatId:m,allowChats:b.allowChats.filter(O=>D.has(O))}})},[]),w=(0,i.useCallback)(async()=>{u(!0);try{let[a,l,b]=await Promise.all([q("/api/bots"),q("/api/connectors"),q("/api/groups")]);if(!s.current)return;let F=(a.body?.bots||[]).map(m=>({larkAppId:m.larkAppId,botName:m.botName||m.larkAppId})),C=(b.body?.chats||[]).map(m=>({chatId:m.chatId,name:m.name||"",bots:(m.memberBots||[]).filter(D=>D.inChat).map(D=>D.larkAppId)}));y(F),k(C),L(Array.isArray(l.body?.connectors)?l.body.connectors:[]),c(F,C)}finally{s.current&&u(!1)}},[c]);(0,i.useEffect)(()=>(s.current=!0,w(),()=>{s.current=!1,d.current&&clearTimeout(d.current)}),[w]),(0,i.useEffect)(()=>{let a=new Set(G.map(l=>l.chatId));E(l=>({...l,chatId:l.chatId&&a.has(l.chatId)?l.chatId:G[0]?.chatId??"",allowChats:l.allowChats.filter(b=>a.has(b))}))},[G]),(0,i.useEffect)(()=>{let a=f.current;if(a)if(Z){if(!a.open)try{a.showModal()}catch{}let l=a.querySelector(".connector-modal-body");l&&(l.scrollTop=0)}else a.open&&a.close()},[Z]),(0,i.useEffect)(()=>()=>{let a=f.current;a?.open&&a.close()},[]);function Q(a){return e(a==="fixed"?"connectors.modeLabelFixed":a==="new-group"?"connectors.modeLabelNewGroup":"connectors.modeLabelDynamic")}function oe(a){return e(a==="workflow"?"connectors.kindLabelWorkflow":"connectors.kindLabelTurn")}function h(a){E(l=>({...l,...a}))}function S(){v(null),A(null),K(null),E(a=>{let l=a.botId||N[0]?.larkAppId||"";return{...De,botId:l,chatId:he(I,l)[0]?.chatId||""}}),B(!0)}function ne(a){v(null),A(null),M(null),K(a),E(Qe(a,I)),B(!0)}function P(){X||(B(!1),v(null),A(null),K(null))}async function ae(){v(null),A(null);let a=r.name.trim(),l=r.botId;if(!a){v({text:e("connectors.errName"),error:!0});return}if(!l){v({text:e("connectors.errBot"),error:!0});return}if(r.kind==="workflow"){v({text:e("connectors.errLegacyWorkflowRetired"),error:!0});return}let b=r.topicMessageText.trim();if((r.topicMessageMode==="custom"||r.topicMessageMode==="template")&&!b){v({text:e("connectors.errTopicMessage"),error:!0});return}let F=je(r.topicMessageMode,b,r.topicMessageExtractors);if(!F.ok){v({text:e(F.error),error:!0});return}let C={name:a,enabled:x?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:l},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:F.value,suppressFinalOutput:r.suppressFinalOutput,verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let m=r.manualChat?r.manualChatId.trim():r.chatId;if(!m){v({text:e("connectors.errChat"),error:!0});return}C.target.chatId=m}else r.mode==="dynamic"&&(C.target.allowChats=r.allowChats);if(r.mode==="new-group"){let m=r.dedup.trim();if(r.deduplicate&&!m){v({text:e("connectors.errDedup"),error:!0});return}C.lifecycleExtractors=r.deduplicate?{dedupKey:m}:null}else C.lifecycleExtractors=null;r.secret.trim()&&(C.secret=r.secret.trim()),Y(!0),v({text:e(x?"connectors.saving":"connectors.creating")});try{let m=await V(x?"PUT":"POST",x?`/api/connectors/${encodeURIComponent(x.id)}`:"/api/connectors",C);if(!s.current)return;if((m.status===201||m.status===200)&&m.body?.ok){if(x){let ve=x.id,W=m.body.connector;L(Ce=>Ke(Ce,W));let Te=m.body.secret??C.secret;if(Te){let Ce=m.body.webhookUrl||be(W.id),Be=(W.verify?.type??"token")==="token",xe=W.target.mode==="dynamic",Ge=xe?W.target.allowChats?.[0]||"<chatId>":"";v(null),A({name:a,mode:W.target.mode,chatId:W.target.chatId,url:Ce,secret:Te,isToken:Be,isDynamic:xe,exampleChat:Ge,rotated:!0}),await w();return}M({id:ve,text:e("connectors.updated")}),B(!1),K(null);return}let D=m.body.webhookUrl||be(m.body.connector.id),O=(m.body.connector?.verify?.type??"token")==="token",Me=r.mode==="dynamic",qe=Me?C.target.allowChats?.[0]||"<chatId>":"";v(null),A({name:a,mode:r.mode,chatId:C.target.chatId,url:D,secret:m.body.secret,isToken:O,isDynamic:Me,exampleChat:qe}),E(ve=>({...ve,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,allowChats:[],storePayload:!0})),await w()}else{let D=m.body?.error||m.status;v({text:e("connectors.createFailed",{error:String(D)}),error:!0})}}finally{s.current&&Y(!1)}}async function se(a){M({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let l=await V("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(l.status===200&&l.body?.ok)M(null),await w();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.toggleFailed",{error:String(b)}),error:!0})}}async function we(a){let l=a.loggingPolicy?.storePayload!==!1;M({id:a.id,text:e("connectors.saving")});let b=await V("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!l,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(b.status===200&&b.body?.ok)M(null),await w();else{let F=b.body?.error||b.status;M({id:a.id,text:e("connectors.saveFailed",{error:String(F)}),error:!0})}}async function Ae(a){if(!await Fe({title:"\u5220\u9664\u8FDE\u63A5\u5668",message:e("connectors.delConfirm"),danger:!0}))return;M({id:a.id,text:e("connectors.deleting")});let l=await V("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(l.status===200&&l.body?.ok)M(null),await w();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.deleteFailed",{error:String(b)}),error:!0})}}function He(a){ce(be(a.id),e("connectors.copy")).then(l=>{!l||!s.current||(te(a.id),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{s.current&&te(null)},1200))})}return(0,t.jsxs)("section",{className:"page connectors-page",children:[(0,t.jsxs)("div",{className:"page-heading",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,t.jsx)("h1",{children:e("nav.connectors")})]}),(0,t.jsx)("div",{className:"page-heading-actions",children:o.tab==="webhooks"?(0,t.jsx)(Se,{className:"page-primary-action connector-create-trigger",onClick:S,children:e("connectors.createTitle")}):(0,t.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,t.jsx)(Ve,{active:o.tab}),o.tab==="webhooks"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("dialog",{ref:f,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),P()},onClose:P,onClick:a=>{a.target===a.currentTarget&&P()},children:(0,t.jsxs)("article",{className:"connector-modal-card",children:[(0,t.jsxs)("header",{className:"connector-modal-header",children:[(0,t.jsx)("h3",{children:e(x?"connectors.editTitle":"connectors.createTitle")}),(0,t.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:X,onClick:P,children:(0,t.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,t.jsx)("div",{className:"connector-modal-body",children:J?(0,t.jsx)(Ye,{created:J,groupName:z}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"cn-form",children:[(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,t.jsx)(T,{children:e("connectors.fName")}),(0,t.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>h({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fBot")}),(0,t.jsx)(pe,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:fe,onChange:a=>h({botId:a})})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fKind")}),(0,t.jsx)(pe,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:H,onChange:a=>h({kind:a})})]}),r.kind==="workflow"?(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,t.jsx)(T,{children:e("connectors.fWf")}),(0,t.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>h({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fMode")}),(0,t.jsx)(pe,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:ye,onChange:a=>h({mode:a})})]}),r.mode==="fixed"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsx)(T,{children:e("connectors.fFixedChat")}),(0,t.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,t.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>h({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,t.jsx)(Oe,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:G,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>h({chatId:a})}),(0,t.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>h({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsxs)(T,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)(Oe,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:G,value:r.allowChats,multiple:!0,allLabel:e("connectors.allowAll"),placeholder:e("connectors.allowAllHint"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>h({allowChats:a})})]}):null,r.mode==="dynamic"?(0,t.jsx)("div",{className:"cn-field-wide",children:(0,t.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,t.jsx)(T,{children:e("connectors.newGroupStrategy")}),(0,t.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>h({deduplicate:!1}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,t.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>h({deduplicate:!0}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,t.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,t.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,t.jsx)(T,{help:(0,t.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,t.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>h({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,t.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,t.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,t.jsxs)(T,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>h({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,t.jsx)(T,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,t.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","template","none"].map(a=>{let l=a==="default"?"Default":a==="custom"?"Custom":a==="template"?"Template":"None";return(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>h({topicMessageMode:a}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e(`connectors.topicMessage${l}`)}),(0,t.jsx)("small",{children:e(`connectors.topicMessage${l}Hint`)})]})]},a)})}),r.topicMessageMode==="custom"||r.topicMessageMode==="template"?(0,t.jsxs)("div",{className:"connector-topic-message-input",children:[(0,t.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>h({topicMessageText:a.currentTarget.value}),"aria-label":e(r.topicMessageMode==="template"?"connectors.topicMessageTemplate":"connectors.topicMessageCustom"),placeholder:e(r.topicMessageMode==="template"?"connectors.topicMessageTemplatePh":"connectors.topicMessageCustomPh")}),(0,t.jsxs)("small",{children:[e(r.topicMessageMode==="template"?"connectors.topicMessageTemplateHelp":"connectors.topicMessageCustomHelp"),(0,t.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]}),r.topicMessageMode==="template"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("textarea",{id:"cn-topic-message-extractors",className:"connector-topic-message-extractors",rows:8,value:r.topicMessageExtractors,onChange:a=>h({topicMessageExtractors:a.currentTarget.value}),placeholder:e("connectors.topicMessageExtractorsPh"),"aria-label":e("connectors.topicMessageExtractors")}),(0,t.jsx)("small",{children:e("connectors.topicMessageExtractorsHelp")})]}):null]}):(0,t.jsx)("p",{className:`connector-topic-message-preview${r.topicMessageMode==="none"?" muted":""}`,children:r.topicMessageMode==="none"?e("connectors.topicMessageNonePreview"):e("connectors.topicMessagePreview",{source:r.name.trim()||e("connectors.topicMessageSourceFallback")})})]}),(0,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,t.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>h({storePayload:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.storePayload")}),(0,t.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-suppress-final",children:[(0,t.jsx)("input",{id:"cn-suppress-final",type:"checkbox",checked:r.suppressFinalOutput,onChange:a=>h({suppressFinalOutput:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.suppressFinalOutput")}),(0,t.jsx)("small",{children:e("connectors.suppressFinalOutputHint")})]})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fVerify")}),(0,t.jsx)(pe,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:ke,onChange:a=>h({verify:a})})]}),(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,t.jsx)(T,{children:e("connectors.fSecret")}),(0,t.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>h({secret:a.currentTarget.value}),placeholder:e(x?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),U?(0,t.jsx)("p",{className:`connector-create-message${U.error?" err":""}`,children:U.text}):null]})}),(0,t.jsx)("footer",{className:"connector-modal-actions",children:J?(0,t.jsx)("button",{type:"button",className:"primary",onClick:P,children:e("connectors.close")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",disabled:X,onClick:P,children:e("connectors.cancel")}),(0,t.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:X,onClick:()=>{ae()},children:e(x?"connectors.btnSave":"connectors.btnCreate")})]})})]})}),(0,t.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,t.jsx)("div",{className:"card connector-list-card",children:$?(0,t.jsx)(de,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,t.jsx)(Ze,{connectors:R,bots:N,copiedId:g,editMsg:ee,groupName:z,modeLabel:Q,kindLabel:oe,onCopy:He,onEdit:ne,onToggle:a=>{se(a)},onTogglePayloadLogging:a=>{we(a)},onDelete:a=>{Ae(a)}})})})]}):(0,t.jsx)(Re,{embedded:!0})]})}function Ye(o){let e=_(),s=o.created,d=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,f=s.exampleChat!=="<chatId>"?`\uFF08${o.groupName(s.exampleChat)}\uFF09`:"";return(0,t.jsx)("div",{className:"connector-created-wrap",children:(0,t.jsxs)("div",{className:"card connector-created-card",children:[(0,t.jsxs)("p",{className:"connector-created-title ok",children:[e(s.rotated?"connectors.rotatedPrefix":"connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,t.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:o.groupName(s.chatId)})]}):null]}),(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsx)("code",{children:s.url})]}),s.secret?(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,t.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:f})}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Ze(o){let e=_();return o.connectors.length?(0,t.jsx)(t.Fragment,{children:o.connectors.map(s=>{let d=o.bots.find(L=>L.larkAppId===s.target.botId),f=be(s.id),N=(s.verify?.type??"token")==="token",y=e(N?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:o.groupName(s.target.chatId)}):"",k=o.editMsg?.id===s.id?o.editMsg:null,R=o.copiedId===s.id;return(0,t.jsxs)("div",{className:"card connector-item-card",children:[(0,t.jsxs)("div",{className:"connector-item-head",children:[(0,t.jsxs)("div",{className:"connector-item-main",children:[(0,t.jsxs)("div",{className:"connector-item-title",children:[(0,t.jsx)("b",{children:s.name}),(0,t.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,t.jsxs)("div",{className:"connector-item-meta",children:[(0,t.jsx)("span",{children:d?.botName||s.target.botId}),(0,t.jsx)("span",{children:o.kindLabel(s.target.kind)}),(0,t.jsx)("span",{children:o.modeLabel(s.target.mode)}),I?(0,t.jsx)("span",{children:I}):null,(0,t.jsx)("span",{children:y}),(0,t.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,t.jsx)("button",{className:`ghost connector-copy-button${R?" copied":""}`,type:"button",onClick:()=>o.onCopy(s),children:e(R?"connectors.copied":"connectors.copy")})]}),(0,t.jsxs)("div",{className:"connector-url-row",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsxs)("code",{children:[f,N?"/<token>":""]})]}),N?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,t.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,t.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,t.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"||s.topicMessage?.mode==="template"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),k?(0,t.jsx)("div",{className:k.error?"err connector-item-note":"muted connector-item-note",children:k.text}):null,(0,t.jsxs)("div",{className:"connector-item-actions",children:[(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onEdit(s),children:e("connectors.btnEdit")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,t.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function pt(o){return re(o,(0,t.jsx)($e,{tab:"webhooks"}))}function bt(o){return re(o,(0,t.jsx)($e,{tab:"logs"}))}export{mt as buildConnectorInstructionUpdateBody,ze as buildConnectorKindOptions,je as buildConnectorTopicMessageConfig,bt as renderConnectorsLogsPage,pt as renderConnectorsPage,Ke as replaceConnectorById};
1
+ import{a as q,b as V}from"./chunk-EVK77ASG.js";import{a as ce}from"./chunk-ZJVTGU5X.js";import{a as Fe}from"./chunk-CEUCNZFJ.js";import{a as ie,c as de,g as Se,l as T,q as ue}from"./chunk-QALRQEKD.js";import{d as _}from"./chunk-3OJQKYM3.js";import"./chunk-QITAMHW6.js";import"./chunk-IRFGJSPL.js";import{c as re}from"./chunk-ARROO6TE.js";import{c as j,d as Pe,e as le}from"./chunk-3YZFAHNK.js";var i=j(Pe(),1);var p=j(Pe(),1);var n=j(le(),1),We=50,Ne={total:0,ok:0,error:0,successRate:0};function _e(o,e=Date.now()){if(o==="all")return;let s=o==="24h"?24:o==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function Ue(o,e=0){let s=new URLSearchParams({limit:String(We),offset:String(e)});o.connectorId&&s.set("connectorId",o.connectorId),o.status&&s.set("status",o.status);let d=_e(o.timeWindow);return d&&s.set("since",d),o.query.trim()&&s.set("q",o.query.trim()),s}function Ee(o){if(!o)return"\u2014";let e=new Date(o);return Number.isFinite(e.getTime())?e.toLocaleString():o}function ge(o){return o===void 0||!Number.isFinite(o)?"\u2014":o<1e3?`${Math.round(o)} ms`:o<6e4?`${(o/1e3).toFixed(o<1e4?1:0)} s`:`${(o/6e4).toFixed(1)} min`}function Je(o){return o===void 0?"\u2014":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/1024/1024).toFixed(1)} MB`}function Le(o){return o.value===void 0||o.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):typeof o.value=="object"&&!Array.isArray(o.value)&&Object.keys(o.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${o.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(o.value,null,2)})})}function Xe(o){let e=[["kind",o.value?.kind],["mode",o.value?.mode],["botId",o.value?.botId],["chatId",o.value?.chatId],["sessionId",o.value?.sessionId],["rootMessageId",o.value?.rootMessageId],["workflowId",o.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,d])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(d)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function Ie(o){return(0,n.jsx)(ue,{id:o.id,className:"webhook-log-filter-menu",ariaLabel:o.label,style:{width:"100%",minWidth:0},value:o.value,label:ie(o.options,o.value),options:o.options,onChange:o.onChange})}function me(o){return(0,n.jsxs)("article",{className:`card webhook-log-metric${o.tone?` ${o.tone}`:""}`,children:[(0,n.jsx)("span",{children:o.label}),(0,n.jsx)("strong",{children:o.value}),(0,n.jsx)("small",{children:o.hint||"\xA0"})]})}function Re(o={}){let e=_(),s=(0,p.useRef)(!1),d=(0,p.useRef)([]),[f,N]=(0,p.useState)([]),[y,I]=(0,p.useState)([]),[k,R]=(0,p.useState)(Ne),[L,$]=(0,p.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[u,r]=(0,p.useState)(null),[E,U]=(0,p.useState)(!0),[v,J]=(0,p.useState)(!1),[A,X]=(0,p.useState)(!1),[Y,Z]=(0,p.useState)(0),[B,x]=(0,p.useState)(""),[K,ee]=(0,p.useState)(!1),M=(0,p.useMemo)(()=>new Map(f.map(c=>[c.id,c.name])),[f]),g=(0,p.useMemo)(()=>y.find(c=>c.triggerId===u)??y[0]??null,[y,u]),te=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...f.map(c=>({value:c.id,label:c.name}))],[f,e]),G=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),fe=(0,p.useMemo)(()=>[{value:"24h",label:e("webhookLogs.last24h")},{value:"7d",label:e("webhookLogs.last7d")},{value:"30d",label:e("webhookLogs.last30d")},{value:"all",label:e("webhookLogs.allTime")}],[e]),H=(0,p.useCallback)(async(c=!1,w=!1)=>{w?J(!0):U(!0),x("");let Q=c?d.current.length:0,oe=Ue(L,Q),h=new URLSearchParams(oe);h.delete("limit"),h.delete("offset");try{let[S,ne]=await Promise.all([q(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):q(`/api/trigger-logs/summary?${h}`)]);if(!s.current)return;if(S.status!==200)throw new Error(String(S.body?.error||S.status));let P=Array.isArray(S.body?.logs)?S.body.logs:[],ae=c?[...d.current,...P]:P;d.current=ae,I(ae),Z(Number(S.body?.total??P.length)),X(S.body?.hasMore===!0),c||(R(ne?.status===200?ne.body?.summary??Ne:Ne),r(se=>P.some(we=>we.triggerId===se)?se:P[0]?.triggerId??null))}catch(S){s.current&&x(S?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(U(!1),J(!1))}},[L,e]);(0,p.useEffect)(()=>(s.current=!0,q("/api/connectors").then(c=>{s.current&&c.status===200&&N(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,p.useEffect)(()=>{let c=setTimeout(()=>{H(!1)},L.query?260:0);return()=>clearTimeout(c)},[L,H]),(0,p.useEffect)(()=>{let c=setInterval(()=>{H(!1,!0)},15e3);return()=>clearInterval(c)},[H]);async function ye(){!g||!await ce(JSON.stringify(g,null,2),e("webhookLogs.copyJson"))||(ee(!0),setTimeout(()=>s.current&&ee(!1),1200))}let ke=g?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):g?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),z=(0,n.jsxs)(n.Fragment,{children:[o.embedded?null:(0,n.jsxs)("div",{className:"page-heading",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,n.jsx)("h1",{children:e("nav.webhookLogs")}),(0,n.jsx)("p",{className:"webhook-log-heading-copy",children:e("webhookLogs.subtitle")})]}),(0,n.jsxs)("div",{className:"page-heading-actions",children:[(0,n.jsxs)("span",{className:`webhook-log-live${v?" refreshing":""}`,children:[(0,n.jsx)("i",{}),e("webhookLogs.autoRefresh")]}),(0,n.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})]})]}),(0,n.jsxs)("section",{className:"webhook-log-metrics","aria-label":e("webhookLogs.summary"),children:[(0,n.jsx)(me,{label:e("webhookLogs.total"),value:k.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(me,{label:e("webhookLogs.successRate"),value:`${k.successRate.toFixed(k.successRate%1?1:0)}%`,tone:"ok",hint:`${k.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(me,{label:e("webhookLogs.failures"),value:k.error,tone:k.error?"error":void 0,hint:k.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(me,{label:e("webhookLogs.p95"),value:ge(k.p95DurationMs),hint:`${e("webhookLogs.average")} ${ge(k.avgDurationMs)}`})]}),(0,n.jsxs)("form",{className:"filters dashboard-toolbar webhook-log-toolbar",onSubmit:c=>c.preventDefault(),children:[(0,n.jsx)("input",{type:"search",name:"q","aria-label":e("webhookLogs.search"),placeholder:e("webhookLogs.searchPlaceholder"),value:L.query,onChange:c=>{let w=c.currentTarget.value;$(Q=>({...Q,query:w}))}}),(0,n.jsx)(Ie,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:L.connectorId,options:te,onChange:c=>$(w=>({...w,connectorId:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-status",label:e("webhookLogs.status"),value:L.status,options:G,onChange:c=>$(w=>({...w,status:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:L.timeWindow,options:fe,onChange:c=>$(w=>({...w,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:v,onClick:()=>{H(!1,!0)},children:e("webhookLogs.refresh")})]}),B?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",B]}):null,(0,n.jsxs)("section",{className:"webhook-log-workspace",children:[(0,n.jsxs)("article",{className:"card webhook-log-list-panel",children:[(0,n.jsx)("header",{className:"webhook-log-panel-head",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{children:e("webhookLogs.records")}),(0,n.jsx)("span",{children:e("webhookLogs.matching",{count:Y})})]})}),E&&!y.length?(0,n.jsx)(de,{label:e("webhookLogs.loading"),compact:!0}):null,!E&&!y.length?(0,n.jsxs)("div",{className:"webhook-log-empty",children:[(0,n.jsx)("span",{"aria-hidden":"true",children:"\u25CE"}),(0,n.jsx)("strong",{children:e("webhookLogs.empty")}),(0,n.jsx)("p",{children:e("webhookLogs.emptyHint")})]}):null,(0,n.jsx)("div",{className:"webhook-log-list",role:"listbox","aria-label":e("webhookLogs.records"),children:y.map(c=>{let w=g?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":w,className:`webhook-log-row${w?" active":""}`,onClick:()=>r(c.triggerId),children:[(0,n.jsx)("span",{className:`webhook-log-status-dot ${c.status}`,"aria-hidden":"true"}),(0,n.jsxs)("span",{className:"webhook-log-row-main",children:[(0,n.jsxs)("span",{className:"webhook-log-row-title",children:[(0,n.jsx)("strong",{children:M.get(c.connectorId||"")||c.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsx)("code",{children:c.request?.method||"POST"})]}),(0,n.jsxs)("span",{className:"webhook-log-row-meta",children:[(0,n.jsx)("span",{children:Ee(c.createdAt)}),(0,n.jsx)("span",{children:c.errorCode||c.action})]})]}),(0,n.jsxs)("span",{className:"webhook-log-row-result",children:[(0,n.jsx)("b",{className:c.status,children:c.response?.httpStatus??(c.status==="ok"?"2xx":"ERR")}),(0,n.jsx)("small",{children:ge(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),A?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:E,onClick:()=>{H(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:g?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("header",{className:"webhook-log-detail-head",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:`webhook-log-result-pill ${g.status}`,children:g.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:M.get(g.connectorId||"")||g.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Ee(g.createdAt)," \xB7 ",g.request?.method||"POST"," ",g.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{ye()},children:e(K?"webhookLogs.copied":"webhookLogs.copyJson")})]}),g.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:g.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:g.error})]}):null,(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.overview")}),(0,n.jsxs)("dl",{className:"webhook-log-facts",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.httpStatus")}),(0,n.jsx)("dd",{children:g.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:ge(g.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:g.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:Je(g.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.requestId||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.remoteAddress")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.request?.remoteAddress||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.target")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.target?.chatId||g.target?.sessionId||g.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(Le,{value:g.request?.query,empty:e("webhookLogs.none")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.headers"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),(0,n.jsx)(Le,{value:g.request?.headers,empty:e("webhookLogs.headersNotStored")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.payload"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),g.request?.payloadStored?(0,n.jsx)(Le,{value:g.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:ke})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(Xe,{value:g.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return o.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:z}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:z})}var t=j(le(),1);function Ke(o,e){return o.map(s=>s.id===e.id?e:s)}var De={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,verify:"token",secret:"",storePayload:!0};function mt(o,e){return{promptEnvelope:{sourceName:o.promptEnvelope?.sourceName||o.name,instruction:e}}}function je(o,e,s){let d=e.trim();if(o!=="template")return{ok:!0,value:o==="custom"?{mode:o,text:d}:{mode:o}};try{let f=JSON.parse(s);return!f||typeof f!="object"||Array.isArray(f)?{ok:!1,error:"connectors.errTopicExtractors"}:{ok:!0,value:{mode:o,text:d,extractors:f}}}catch{return{ok:!1,error:"connectors.errTopicExtractors"}}}function ze(o){return[{value:"turn",label:o("connectors.kindTurn")},{value:"workflow",label:o("connectors.kindWorkflowRetiring"),disabled:!0}]}function be(o){return`${location.origin}/webhook/${encodeURIComponent(o)}`}function pe(o){return(0,t.jsx)(ue,{id:o.id,className:"connector-form-menu",ariaLabel:o.label,value:o.value,label:ie(o.options,o.value),options:o.options,onChange:o.onChange})}function Oe(o){let e=(0,i.useRef)(null),[s,d]=(0,i.useState)(!1),[f,N]=(0,i.useState)(""),y=Array.isArray(o.value)?o.value:o.value?[o.value]:[],I=(0,i.useMemo)(()=>new Set(y),[y]),k=f.trim().toLocaleLowerCase(),R=(0,i.useMemo)(()=>k?o.groups.filter(u=>`${u.name} ${u.chatId}`.toLocaleLowerCase().includes(k)):o.groups,[k,o.groups]),L=o.multiple?y.length===0?o.allLabel||o.placeholder:o.selectedCountLabel(y.length):o.groups.find(u=>u.chatId===y[0])?.name||y[0]||o.placeholder;(0,i.useEffect)(()=>{if(!s)return;let u=r=>{e.current?.contains(r.target)||d(!1)};return document.addEventListener("pointerdown",u),()=>document.removeEventListener("pointerdown",u)},[s]);function $(u){if(!o.multiple){o.onChange(u),d(!1),N("");return}o.onChange(I.has(u)?y.filter(r=>r!==u):[...y,u])}return(0,t.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,t.jsxs)("button",{id:o.id,type:"button",className:"connector-group-picker-trigger","aria-label":o.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>d(u=>!u),children:[(0,t.jsx)("span",{className:y.length||o.multiple&&o.allLabel?"":"muted",children:L}),(0,t.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,t.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,t.jsxs)("label",{className:"connector-group-search",htmlFor:`${o.id}-search`,children:[(0,t.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,t.jsx)("input",{id:`${o.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:f,placeholder:o.searchPlaceholder,onChange:u=>N(u.currentTarget.value),onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),d(!1))}})]}),(0,t.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":o.label,"aria-multiselectable":o.multiple||void 0,children:[o.multiple&&o.allLabel&&!k?(0,t.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${y.length===0?" selected":""}`,role:"option","aria-selected":y.length===0,onClick:()=>o.onChange([]),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:o.allLabel}),(0,t.jsx)("small",{children:o.placeholder})]})]}):null,R.map(u=>{let r=I.has(u.chatId);return(0,t.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>$(u.chatId),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:u.name||u.chatId}),u.name?(0,t.jsx)("small",{children:u.chatId}):null]})]},u.chatId)}),R.length?null:(0,t.jsx)("p",{className:"connector-group-empty",children:o.emptyLabel})]})]}):null]})}function he(o,e){return o.filter(s=>s.bots.includes(e))}function Qe(o,e){let s=o.target.chatId||"",d=s&&he(e,o.target.botId).some(f=>f.chatId===s);return{name:o.name,botId:o.target.botId,kind:o.target.kind,workflowId:o.target.workflowId||"",mode:o.target.mode,chatId:d?s:"",manualChat:!!(s&&!d),manualChatId:d?"":s,allowChats:o.target.allowChats||[],deduplicate:!!o.lifecycleExtractors?.dedupKey,dedup:o.lifecycleExtractors?.dedupKey||"",instruction:o.promptEnvelope?.instruction||"",topicMessageMode:o.topicMessage?.mode||"default",topicMessageText:o.topicMessage?.text||"",topicMessageExtractors:JSON.stringify(o.topicMessage?.extractors||{},null,2),suppressFinalOutput:o.suppressFinalOutput===!0,verify:o.verify?.type||"token",secret:"",storePayload:o.loggingPolicy?.storePayload!==!1}}function Ve(o){let e=_(),s=o.active==="webhooks",d=o.active==="logs";return(0,t.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,t.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,t.jsx)("a",{href:"#/connectors/logs",className:`itab${d?" on":""}`,role:"tab","aria-selected":d,children:e("connectors.tabLogs")})]})}function $e(o){let e=_(),s=(0,i.useRef)(!1),d=(0,i.useRef)(null),f=(0,i.useRef)(null),[N,y]=(0,i.useState)([]),[I,k]=(0,i.useState)([]),[R,L]=(0,i.useState)([]),[$,u]=(0,i.useState)(!0),[r,E]=(0,i.useState)(De),[U,v]=(0,i.useState)(null),[J,A]=(0,i.useState)(null),[X,Y]=(0,i.useState)(!1),[Z,B]=(0,i.useState)(!1),[x,K]=(0,i.useState)(null),[ee,M]=(0,i.useState)(null),[g,te]=(0,i.useState)(null),G=(0,i.useMemo)(()=>he(I,r.botId),[I,r.botId]),fe=(0,i.useMemo)(()=>N.length?N.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[N,e]),H=(0,i.useMemo)(()=>ze(e),[e]),ye=(0,i.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),ke=(0,i.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),z=(0,i.useCallback)(a=>I.find(b=>b.chatId===a)?.name||a,[I]),c=(0,i.useCallback)((a,l)=>{E(b=>{let F=b.botId&&a.some(O=>O.larkAppId===b.botId)?b.botId:a[0]?.larkAppId??"",C=he(l,F),m=b.chatId&&C.some(O=>O.chatId===b.chatId)?b.chatId:C[0]?.chatId??"",D=new Set(C.map(O=>O.chatId));return{...b,botId:F,chatId:m,allowChats:b.allowChats.filter(O=>D.has(O))}})},[]),w=(0,i.useCallback)(async()=>{u(!0);try{let[a,l,b]=await Promise.all([q("/api/bots"),q("/api/connectors"),q("/api/groups")]);if(!s.current)return;let F=(a.body?.bots||[]).map(m=>({larkAppId:m.larkAppId,botName:m.botName||m.larkAppId})),C=(b.body?.chats||[]).map(m=>({chatId:m.chatId,name:m.name||"",bots:(m.memberBots||[]).filter(D=>D.inChat).map(D=>D.larkAppId)}));y(F),k(C),L(Array.isArray(l.body?.connectors)?l.body.connectors:[]),c(F,C)}finally{s.current&&u(!1)}},[c]);(0,i.useEffect)(()=>(s.current=!0,w(),()=>{s.current=!1,d.current&&clearTimeout(d.current)}),[w]),(0,i.useEffect)(()=>{let a=new Set(G.map(l=>l.chatId));E(l=>({...l,chatId:l.chatId&&a.has(l.chatId)?l.chatId:G[0]?.chatId??"",allowChats:l.allowChats.filter(b=>a.has(b))}))},[G]),(0,i.useEffect)(()=>{let a=f.current;if(a)if(Z){if(!a.open)try{a.showModal()}catch{}let l=a.querySelector(".connector-modal-body");l&&(l.scrollTop=0)}else a.open&&a.close()},[Z]),(0,i.useEffect)(()=>()=>{let a=f.current;a?.open&&a.close()},[]);function Q(a){return e(a==="fixed"?"connectors.modeLabelFixed":a==="new-group"?"connectors.modeLabelNewGroup":"connectors.modeLabelDynamic")}function oe(a){return e(a==="workflow"?"connectors.kindLabelWorkflow":"connectors.kindLabelTurn")}function h(a){E(l=>({...l,...a}))}function S(){v(null),A(null),K(null),E(a=>{let l=a.botId||N[0]?.larkAppId||"";return{...De,botId:l,chatId:he(I,l)[0]?.chatId||""}}),B(!0)}function ne(a){v(null),A(null),M(null),K(a),E(Qe(a,I)),B(!0)}function P(){X||(B(!1),v(null),A(null),K(null))}async function ae(){v(null),A(null);let a=r.name.trim(),l=r.botId;if(!a){v({text:e("connectors.errName"),error:!0});return}if(!l){v({text:e("connectors.errBot"),error:!0});return}if(r.kind==="workflow"){v({text:e("connectors.errLegacyWorkflowRetired"),error:!0});return}let b=r.topicMessageText.trim();if((r.topicMessageMode==="custom"||r.topicMessageMode==="template")&&!b){v({text:e("connectors.errTopicMessage"),error:!0});return}let F=je(r.topicMessageMode,b,r.topicMessageExtractors);if(!F.ok){v({text:e(F.error),error:!0});return}let C={name:a,enabled:x?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:l},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:F.value,suppressFinalOutput:r.suppressFinalOutput,verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let m=r.manualChat?r.manualChatId.trim():r.chatId;if(!m){v({text:e("connectors.errChat"),error:!0});return}C.target.chatId=m}else r.mode==="dynamic"&&(C.target.allowChats=r.allowChats);if(r.mode==="new-group"){let m=r.dedup.trim();if(r.deduplicate&&!m){v({text:e("connectors.errDedup"),error:!0});return}C.lifecycleExtractors=r.deduplicate?{dedupKey:m}:null}else C.lifecycleExtractors=null;r.secret.trim()&&(C.secret=r.secret.trim()),Y(!0),v({text:e(x?"connectors.saving":"connectors.creating")});try{let m=await V(x?"PUT":"POST",x?`/api/connectors/${encodeURIComponent(x.id)}`:"/api/connectors",C);if(!s.current)return;if((m.status===201||m.status===200)&&m.body?.ok){if(x){let ve=x.id,W=m.body.connector;L(Ce=>Ke(Ce,W));let Te=m.body.secret??C.secret;if(Te){let Ce=m.body.webhookUrl||be(W.id),Be=(W.verify?.type??"token")==="token",xe=W.target.mode==="dynamic",Ge=xe?W.target.allowChats?.[0]||"<chatId>":"";v(null),A({name:a,mode:W.target.mode,chatId:W.target.chatId,url:Ce,secret:Te,isToken:Be,isDynamic:xe,exampleChat:Ge,rotated:!0}),await w();return}M({id:ve,text:e("connectors.updated")}),B(!1),K(null);return}let D=m.body.webhookUrl||be(m.body.connector.id),O=(m.body.connector?.verify?.type??"token")==="token",Me=r.mode==="dynamic",qe=Me?C.target.allowChats?.[0]||"<chatId>":"";v(null),A({name:a,mode:r.mode,chatId:C.target.chatId,url:D,secret:m.body.secret,isToken:O,isDynamic:Me,exampleChat:qe}),E(ve=>({...ve,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,allowChats:[],storePayload:!0})),await w()}else{let D=m.body?.error||m.status;v({text:e("connectors.createFailed",{error:String(D)}),error:!0})}}finally{s.current&&Y(!1)}}async function se(a){M({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let l=await V("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(l.status===200&&l.body?.ok)M(null),await w();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.toggleFailed",{error:String(b)}),error:!0})}}async function we(a){let l=a.loggingPolicy?.storePayload!==!1;M({id:a.id,text:e("connectors.saving")});let b=await V("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!l,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(b.status===200&&b.body?.ok)M(null),await w();else{let F=b.body?.error||b.status;M({id:a.id,text:e("connectors.saveFailed",{error:String(F)}),error:!0})}}async function Ae(a){if(!await Fe({title:"\u5220\u9664\u8FDE\u63A5\u5668",message:e("connectors.delConfirm"),danger:!0}))return;M({id:a.id,text:e("connectors.deleting")});let l=await V("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(l.status===200&&l.body?.ok)M(null),await w();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.deleteFailed",{error:String(b)}),error:!0})}}function He(a){ce(be(a.id),e("connectors.copy")).then(l=>{!l||!s.current||(te(a.id),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{s.current&&te(null)},1200))})}return(0,t.jsxs)("section",{className:"page connectors-page",children:[(0,t.jsxs)("div",{className:"page-heading",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,t.jsx)("h1",{children:e("nav.connectors")})]}),(0,t.jsx)("div",{className:"page-heading-actions",children:o.tab==="webhooks"?(0,t.jsx)(Se,{className:"page-primary-action connector-create-trigger",onClick:S,children:e("connectors.createTitle")}):(0,t.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,t.jsx)(Ve,{active:o.tab}),o.tab==="webhooks"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("dialog",{ref:f,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),P()},onClose:P,onClick:a=>{a.target===a.currentTarget&&P()},children:(0,t.jsxs)("article",{className:"connector-modal-card",children:[(0,t.jsxs)("header",{className:"connector-modal-header",children:[(0,t.jsx)("h3",{children:e(x?"connectors.editTitle":"connectors.createTitle")}),(0,t.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:X,onClick:P,children:(0,t.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,t.jsx)("div",{className:"connector-modal-body",children:J?(0,t.jsx)(Ye,{created:J,groupName:z}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"cn-form",children:[(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,t.jsx)(T,{children:e("connectors.fName")}),(0,t.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>h({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fBot")}),(0,t.jsx)(pe,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:fe,onChange:a=>h({botId:a})})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fKind")}),(0,t.jsx)(pe,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:H,onChange:a=>h({kind:a})})]}),r.kind==="workflow"?(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,t.jsx)(T,{children:e("connectors.fWf")}),(0,t.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>h({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fMode")}),(0,t.jsx)(pe,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:ye,onChange:a=>h({mode:a})})]}),r.mode==="fixed"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsx)(T,{children:e("connectors.fFixedChat")}),(0,t.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,t.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>h({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,t.jsx)(Oe,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:G,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>h({chatId:a})}),(0,t.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>h({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsxs)(T,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)(Oe,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:G,value:r.allowChats,multiple:!0,allLabel:e("connectors.allowAll"),placeholder:e("connectors.allowAllHint"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>h({allowChats:a})})]}):null,r.mode==="dynamic"?(0,t.jsx)("div",{className:"cn-field-wide",children:(0,t.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,t.jsx)(T,{children:e("connectors.newGroupStrategy")}),(0,t.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>h({deduplicate:!1}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,t.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>h({deduplicate:!0}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,t.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,t.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,t.jsx)(T,{help:(0,t.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,t.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>h({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,t.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,t.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,t.jsxs)(T,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>h({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,t.jsx)(T,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,t.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","template","none"].map(a=>{let l=a==="default"?"Default":a==="custom"?"Custom":a==="template"?"Template":"None";return(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>h({topicMessageMode:a}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e(`connectors.topicMessage${l}`)}),(0,t.jsx)("small",{children:e(`connectors.topicMessage${l}Hint`)})]})]},a)})}),r.topicMessageMode==="custom"||r.topicMessageMode==="template"?(0,t.jsxs)("div",{className:"connector-topic-message-input",children:[(0,t.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>h({topicMessageText:a.currentTarget.value}),"aria-label":e(r.topicMessageMode==="template"?"connectors.topicMessageTemplate":"connectors.topicMessageCustom"),placeholder:e(r.topicMessageMode==="template"?"connectors.topicMessageTemplatePh":"connectors.topicMessageCustomPh")}),(0,t.jsxs)("small",{children:[e(r.topicMessageMode==="template"?"connectors.topicMessageTemplateHelp":"connectors.topicMessageCustomHelp"),(0,t.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]}),r.topicMessageMode==="template"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("textarea",{id:"cn-topic-message-extractors",className:"connector-topic-message-extractors",rows:8,value:r.topicMessageExtractors,onChange:a=>h({topicMessageExtractors:a.currentTarget.value}),placeholder:e("connectors.topicMessageExtractorsPh"),"aria-label":e("connectors.topicMessageExtractors")}),(0,t.jsx)("small",{children:e("connectors.topicMessageExtractorsHelp")})]}):null]}):(0,t.jsx)("p",{className:`connector-topic-message-preview${r.topicMessageMode==="none"?" muted":""}`,children:r.topicMessageMode==="none"?e("connectors.topicMessageNonePreview"):e("connectors.topicMessagePreview",{source:r.name.trim()||e("connectors.topicMessageSourceFallback")})})]}),(0,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,t.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>h({storePayload:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.storePayload")}),(0,t.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-suppress-final",children:[(0,t.jsx)("input",{id:"cn-suppress-final",type:"checkbox",checked:r.suppressFinalOutput,onChange:a=>h({suppressFinalOutput:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.suppressFinalOutput")}),(0,t.jsx)("small",{children:e("connectors.suppressFinalOutputHint")})]})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fVerify")}),(0,t.jsx)(pe,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:ke,onChange:a=>h({verify:a})})]}),(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,t.jsx)(T,{children:e("connectors.fSecret")}),(0,t.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>h({secret:a.currentTarget.value}),placeholder:e(x?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),U?(0,t.jsx)("p",{className:`connector-create-message${U.error?" err":""}`,children:U.text}):null]})}),(0,t.jsx)("footer",{className:"connector-modal-actions",children:J?(0,t.jsx)("button",{type:"button",className:"primary",onClick:P,children:e("connectors.close")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",disabled:X,onClick:P,children:e("connectors.cancel")}),(0,t.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:X,onClick:()=>{ae()},children:e(x?"connectors.btnSave":"connectors.btnCreate")})]})})]})}),(0,t.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,t.jsx)("div",{className:"card connector-list-card",children:$?(0,t.jsx)(de,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,t.jsx)(Ze,{connectors:R,bots:N,copiedId:g,editMsg:ee,groupName:z,modeLabel:Q,kindLabel:oe,onCopy:He,onEdit:ne,onToggle:a=>{se(a)},onTogglePayloadLogging:a=>{we(a)},onDelete:a=>{Ae(a)}})})})]}):(0,t.jsx)(Re,{embedded:!0})]})}function Ye(o){let e=_(),s=o.created,d=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,f=s.exampleChat!=="<chatId>"?`\uFF08${o.groupName(s.exampleChat)}\uFF09`:"";return(0,t.jsx)("div",{className:"connector-created-wrap",children:(0,t.jsxs)("div",{className:"card connector-created-card",children:[(0,t.jsxs)("p",{className:"connector-created-title ok",children:[e(s.rotated?"connectors.rotatedPrefix":"connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,t.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:o.groupName(s.chatId)})]}):null]}),(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsx)("code",{children:s.url})]}),s.secret?(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,t.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:f})}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Ze(o){let e=_();return o.connectors.length?(0,t.jsx)(t.Fragment,{children:o.connectors.map(s=>{let d=o.bots.find(L=>L.larkAppId===s.target.botId),f=be(s.id),N=(s.verify?.type??"token")==="token",y=e(N?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:o.groupName(s.target.chatId)}):"",k=o.editMsg?.id===s.id?o.editMsg:null,R=o.copiedId===s.id;return(0,t.jsxs)("div",{className:"card connector-item-card",children:[(0,t.jsxs)("div",{className:"connector-item-head",children:[(0,t.jsxs)("div",{className:"connector-item-main",children:[(0,t.jsxs)("div",{className:"connector-item-title",children:[(0,t.jsx)("b",{children:s.name}),(0,t.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,t.jsxs)("div",{className:"connector-item-meta",children:[(0,t.jsx)("span",{children:d?.botName||s.target.botId}),(0,t.jsx)("span",{children:o.kindLabel(s.target.kind)}),(0,t.jsx)("span",{children:o.modeLabel(s.target.mode)}),I?(0,t.jsx)("span",{children:I}):null,(0,t.jsx)("span",{children:y}),(0,t.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,t.jsx)("button",{className:`ghost connector-copy-button${R?" copied":""}`,type:"button",onClick:()=>o.onCopy(s),children:e(R?"connectors.copied":"connectors.copy")})]}),(0,t.jsxs)("div",{className:"connector-url-row",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsxs)("code",{children:[f,N?"/<token>":""]})]}),N?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,t.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,t.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,t.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"||s.topicMessage?.mode==="template"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),k?(0,t.jsx)("div",{className:k.error?"err connector-item-note":"muted connector-item-note",children:k.text}):null,(0,t.jsxs)("div",{className:"connector-item-actions",children:[(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onEdit(s),children:e("connectors.btnEdit")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,t.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function pt(o){return re(o,(0,t.jsx)($e,{tab:"webhooks"}))}function bt(o){return re(o,(0,t.jsx)($e,{tab:"logs"}))}export{mt as buildConnectorInstructionUpdateBody,ze as buildConnectorKindOptions,je as buildConnectorTopicMessageConfig,bt as renderConnectorsLogsPage,pt as renderConnectorsPage,Ke as replaceConnectorById};
@@ -1,4 +1,4 @@
1
- import{a as k}from"./chunk-CEUCNZFJ.js";import{c as P}from"./chunk-NYY66DNC.js";import{c as C}from"./chunk-ARROO6TE.js";import{c as y,d as j,e as S}from"./chunk-3YZFAHNK.js";var s=y(j(),1);var a=y(S(),1),L={botmux_routing:"<botmux_routing> \u8DEF\u7531\u8BF4\u660E",identity:"<identity> \u8EAB\u4EFD\u89C4\u5219",shell_hints:"Shell \u63D0\u793A\uFF08codex/gemini \u7B49\uFF09",available_bots:"<available_bots> \u534F\u4F5C bot",attachments:"<attachments> \u9644\u4EF6",followup:"\u8DDF\u8FDB\u8F6E\u63D0\u9192"};function O(n){let e=Date.parse(n);if(!e)return n||"-";let c=Math.max(0,Math.floor((Date.now()-e)/1e3));if(c<60)return`${c}s \u524D`;let r=Math.floor(c/60);if(r<60)return`${r}m \u524D`;let l=Math.floor(r/60);return l<24?`${l}h \u524D`:`${Math.floor(l/24)}d \u524D`}async function x(n,e){let c=await fetch(n,e),r=await c.json().catch(()=>({}));if(!c.ok||r?.ok===!1)throw new Error(r?.error||`HTTP ${c.status}`);return r}function D(n){let{frag:e,locale:c}=n,r=e.locales[c]??{factory:"",override:null},l=r.override!==null,[z,p]=(0,s.useState)(!1),[g,m]=(0,s.useState)(r.override??r.factory),[o,i]=(0,s.useState)(!1);(0,s.useEffect)(()=>{m(r.override??r.factory),p(!1)},[r.override,r.factory,c]);let h=async d=>{i(!0);try{let f=await x("/api/customization/prompt",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({locale:c,key:e.key,value:d})});n.onSaved(f.snapshot),p(!1)}catch(f){n.onError(f?.message??"\u4FDD\u5B58\u5931\u8D25")}finally{i(!1)}},u=async d=>{i(!0);try{let f=await x("/api/customization/condition",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,value:d})});n.onSaved(f.snapshot)}catch(f){n.onError(f?.message??"\u4FDD\u5B58\u5931\u8D25")}finally{i(!1)}};return(0,a.jsxs)("div",{className:`cz-frag cz-frag-${e.kind}${l?" cz-mod":""}`,children:[(0,a.jsx)("div",{className:"cz-frag-bar"}),(0,a.jsxs)("div",{className:"cz-frag-inner",children:[(0,a.jsxs)("div",{className:"cz-frag-top",children:[(0,a.jsx)("span",{className:"cz-frag-label",children:e.label}),(0,a.jsx)("code",{className:"cz-frag-key",children:e.key}),(0,a.jsxs)("span",{className:"cz-frag-badges",children:[l?(0,a.jsx)("span",{className:"cz-chip cz-chip-mod",children:"\u5DF2\u4FEE\u6539"}):null,e.kind==="placeholder"?(0,a.jsxs)("span",{className:"cz-chip cz-chip-ph",children:["\u5360\u4F4D\u7B26 ",(e.placeholders??[]).map(d=>`{${d}}`).join(" ")]}):null,e.kind==="conditional"?(0,a.jsxs)("span",{className:"cz-chip cz-chip-cond",children:["\u6761\u4EF6\u884C",(0,a.jsxs)("select",{className:"cz-cond-select",disabled:o,value:e.conditionForced===null||e.conditionForced===void 0?"default":e.conditionForced?"on":"off",onChange:d=>{let f=d.target.value;u(f==="default"?null:f==="on")},children:[(0,a.jsx)("option",{value:"default",children:"\u8DDF\u968F\u9ED8\u8BA4"}),(0,a.jsx)("option",{value:"on",children:"\u5F3A\u5236\u663E\u793A"}),(0,a.jsx)("option",{value:"off",children:"\u5F3A\u5236\u9690\u85CF"})]})]}):null,l?(0,a.jsx)("button",{className:"cz-link cz-link-reset",disabled:o,onClick:()=>{h(null)},children:"\u6062\u590D\u51FA\u5382"}):null]})]}),z?(0,a.jsxs)("div",{className:"cz-edit",children:[(0,a.jsx)("textarea",{className:"cz-textarea",value:g,rows:Math.max(2,Math.ceil(g.length/52)),onChange:d=>m(d.target.value),autoFocus:!0}),(0,a.jsxs)("div",{className:"cz-edit-actions",children:[(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:o,onClick:()=>{h(g)},children:"\u4FDD\u5B58"}),(0,a.jsx)("button",{className:"cz-btn cz-btn-ghost",disabled:o,onClick:()=>{m(r.override??r.factory),p(!1)},children:"\u53D6\u6D88"}),e.kind==="placeholder"?(0,a.jsxs)("span",{className:"cz-hint",children:["\u4FDD\u7559 ",(e.placeholders??[]).map(d=>`{${d}}`).join("\u3001")," \u624D\u80FD\u4FDD\u5B58"]}):null]})]}):(0,a.jsxs)("div",{className:"cz-frag-text",onClick:()=>p(!0),title:"\u70B9\u51FB\u7F16\u8F91",children:[r.override??r.factory,(0,a.jsx)("span",{className:"cz-edit-hint",children:"\u270E"})]})]})]})}function M(n){let{skill:e}=n,[c,r]=(0,s.useState)(!1),[l,z]=(0,s.useState)(e.override??e.factory),[p,g]=(0,s.useState)(!1);(0,s.useEffect)(()=>{z(e.override??e.factory)},[e.override,e.factory]);let m=async o=>{g(!0);try{let i=await x("/api/customization/skill",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,...o})});n.onSaved(i.snapshot)}catch(i){n.onError(i?.message??"\u4FDD\u5B58\u5931\u8D25")}finally{g(!1)}};return(0,a.jsxs)("div",{className:`cz-skill${e.disabled?" cz-skill-off":""}`,children:[(0,a.jsxs)("div",{className:"cz-skill-head",onClick:()=>r(o=>!o),children:[(0,a.jsx)("span",{className:`cz-caret${c?" cz-caret-open":""}`,children:"\u25B6"}),(0,a.jsx)("code",{className:"cz-skill-name",children:e.name}),(0,a.jsx)("span",{className:"cz-skill-desc",children:e.description}),(0,a.jsxs)("span",{className:"cz-skill-badges",children:[e.disabled?(0,a.jsx)("span",{className:"cz-chip cz-chip-off",children:"\u5DF2\u505C\u7528"}):e.override!==null?(0,a.jsx)("span",{className:"cz-chip cz-chip-mod",children:"\u6B63\u6587\u5DF2\u6539"}):(0,a.jsx)("span",{className:"cz-chip cz-chip-factory",children:"\u51FA\u5382\u9ED8\u8BA4"}),e.override!==null?(0,a.jsx)("button",{className:"cz-link cz-link-reset",disabled:p,onClick:o=>{o.stopPropagation(),m({body:null})},children:"\u6062\u590D\u6B63\u6587"}):null,(0,a.jsx)("button",{className:`cz-link${e.disabled?"":" cz-link-danger"}`,disabled:p,onClick:o=>{o.stopPropagation(),m({disabled:!e.disabled})},children:e.disabled?"\u542F\u7528":"\u505C\u7528"})]})]}),c?(0,a.jsxs)("div",{className:"cz-skill-body",children:[(0,a.jsx)("textarea",{className:"cz-textarea cz-skill-textarea",value:l,onChange:o=>z(o.target.value),disabled:e.disabled,rows:12}),(0,a.jsxs)("div",{className:"cz-edit-actions",children:[(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:p||e.disabled,onClick:()=>{m({body:l})},children:"\u4FDD\u5B58\u6B63\u6587\u8986\u76D6"}),(0,a.jsx)("span",{className:"cz-hint",children:"\u7559\u7A7A\u5E76\u4FDD\u5B58 = \u7528\u51FA\u5382\u9ED8\u8BA4\uFF1B\u5B8C\u6574 SKILL.md\uFF08frontmatter + \u6B63\u6587\uFF09"})]})]}):null]})}function R(n){let[e,c]=(0,s.useState)(""),[r,l]=(0,s.useState)(null),[z,p]=(0,s.useState)(!1),g=async o=>{p(!0);try{let i=await x("/api/customization/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:e,apply:o})});if(o&&i.applied){n.onApplied(i.snapshot),n.onClose();return}l(i.preview)}catch(i){n.onError(i?.message??"\u5BFC\u5165\u5931\u8D25")}finally{p(!1)}},m=o=>{let i=new FileReader;i.onload=()=>{c(String(i.result??"")),l(null)},i.readAsText(o)};return(0,a.jsx)("div",{className:"cz-mask",onClick:o=>{o.target===o.currentTarget&&n.onClose()},children:(0,a.jsxs)("div",{className:"cz-modal",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("h3",{children:"\u5BFC\u5165 bundle"}),(0,a.jsx)("button",{className:"cz-x",onClick:n.onClose,children:"\xD7"})]}),(0,a.jsxs)("div",{className:"cz-modal-body",children:[(0,a.jsxs)("label",{className:"cz-drop",onDragOver:o=>o.preventDefault(),onDrop:o=>{o.preventDefault();let i=o.dataTransfer.files[0];i&&m(i)},children:["\u62D6\u5165 .json \u6587\u4EF6\uFF0C\u6216\u70B9\u6B64\u9009\u62E9",(0,a.jsx)("input",{type:"file",accept:".json,application/json",style:{display:"none"},onChange:o=>{let i=o.target.files?.[0];i&&m(i)}})]}),(0,a.jsx)("textarea",{className:"cz-textarea",placeholder:"\u6216\u76F4\u63A5\u7C98\u8D34 bundle JSON\u2026",value:e,rows:6,onChange:o=>{c(o.target.value),l(null)}}),r?(0,a.jsxs)("div",{className:"cz-diff",children:[(0,a.jsxs)("div",{className:"cz-diff-sum",children:["\u65B0\u589E ",r.summary.adds," \xB7 \u66FF\u6362 ",r.summary.replaces," \xB7 \u505C\u7528 ",r.summary.disables," \xB7 \u65E0\u53D8\u5316 ",r.summary.unchanged]}),r.diff.map((o,i)=>(0,a.jsxs)("div",{className:`cz-diff-row cz-diff-${o.action}`,children:[(0,a.jsx)("span",{className:"cz-diff-mark",children:o.action==="add"?"\uFF0B":o.action==="replace"?"\u21BB":o.action==="disable"?"\u2298":"\uFF1D"}),(0,a.jsxs)("span",{className:"cz-diff-id",children:[o.kind,":",o.id,o.locale?` (${o.locale})`:""]}),o.after?(0,a.jsx)("span",{className:"cz-diff-after",children:o.after}):null]},i))]}):null]}),(0,a.jsxs)("footer",{children:[(0,a.jsx)("button",{className:"cz-btn cz-btn-ghost",onClick:n.onClose,children:"\u53D6\u6D88"}),r?(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:z,onClick:()=>{g(!0)},children:"\u786E\u8BA4\u5BFC\u5165\uFF08\u5148\u5B58\u5FEB\u7167\uFF09"}):(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:z||!e.trim(),onClick:()=>{g(!1)},children:"\u9884\u89C8\u5DEE\u5F02"})]})]})})}function J(){let[n,e]=(0,s.useState)(null),[c,r]=(0,s.useState)(null),[l,z]=(0,s.useState)(null),[p,g]=(0,s.useState)("zh"),[m,o]=(0,s.useState)(!1),[i,h]=(0,s.useState)(!1),u=(0,s.useCallback)(t=>{z(t),window.setTimeout(()=>z(null),2400)},[]),d=(0,s.useCallback)(t=>u(`\u26A0 ${t}`),[u]),f=(0,s.useCallback)(t=>{e(t),u("\u5DF2\u4FDD\u5B58 \xB7 \u4E0B\u4E2A\u4F1A\u8BDD\u5373\u751F\u6548")},[u]),w=(0,s.useCallback)(async()=>{try{e(await x("/api/customization"))}catch(t){r(t?.message??"\u52A0\u8F7D\u5931\u8D25")}},[]);(0,s.useEffect)(()=>{w()},[w]);let N=async(t,b)=>{try{let v=await x(t,{method:"POST",headers:{"Content-Type":"application/json"},body:b?JSON.stringify(b):void 0});return v.snapshot&&e(v.snapshot),v}catch(v){d(v?.message??"\u64CD\u4F5C\u5931\u8D25")}},T=async t=>{try{let b=await x("/api/customization/enabled",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});e(b.snapshot),u(t?"\u81EA\u5B9A\u4E49\u5DF2\u542F\u7528":"\u81EA\u5B9A\u4E49\u5DF2\u505C\u7528\uFF08\u8986\u76D6\u4FDD\u7559\uFF09")}catch(b){d(b?.message??"\u64CD\u4F5C\u5931\u8D25")}};if(c)return(0,a.jsx)("div",{className:"cz-page",children:(0,a.jsxs)("div",{className:"cz-error",children:["\u52A0\u8F7D\u5931\u8D25\uFF1A",c]})});if(!n)return(0,a.jsx)(P,{label:"\u52A0\u8F7D\u81EA\u5B9A\u4E49\u914D\u7F6E\u2026"});let E=Array.from(new Set(n.fragments.map(t=>t.block))),$=n.fragments.filter(t=>t.locales[p]?.override!==null).length,F=n.skills.filter(t=>t.override!==null||t.disabled).length;return(0,a.jsxs)("section",{className:"cz-page",children:[(0,a.jsx)("style",{children:q}),(0,a.jsx)("div",{className:"cz-head",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{children:"\u81EA\u5B9A\u4E49\u4E2D\u5FC3"}),(0,a.jsxs)("p",{children:["\u8C03\u4F18 botmux \u5185\u7F6E\u7684\u6846\u67B6 prompt \u4E0E\u5185\u7F6E skill\u3002\u6240\u6709\u6539\u52A8",(0,a.jsx)("b",{children:"\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u5373\u751F\u6548\uFF0C\u65E0\u9700\u91CD\u542F daemon"}),"\uFF1B\u968F\u65F6\u53EF\u9010\u9879\u6062\u590D\u51FA\u5382\u6216\u6574\u4F53\u56DE\u6EDA\u3002"]})]})}),(0,a.jsxs)("div",{className:"cz-master",children:[(0,a.jsxs)("div",{className:"cz-master-txt",children:[(0,a.jsx)("b",{children:"\u542F\u7528\u81EA\u5B9A\u4E49"}),(0,a.jsx)("span",{children:"\u5173\u95ED\u540E\u6240\u6709\u8986\u76D6\u7ACB\u5373\u505C\u7528\u3001\u4F46\u4E0D\u5220\u9664\u2014\u2014\u6392\u67E5\u300C\u662F\u4E0D\u662F\u6211\u6539\u7684 prompt \u5BFC\u81F4\u7684\u300D\u65F6\u4E00\u952E\u56DE\u5230\u51FA\u5382\u884C\u4E3A\u3002"})]}),(0,a.jsxs)("label",{className:"toggle-row cz-master-switch",children:[(0,a.jsx)("input",{type:"checkbox",checked:n.enabled,onChange:t=>{T(t.currentTarget.checked)}}),(0,a.jsx)("span",{className:"switch","aria-hidden":"true"})]})]}),(0,a.jsxs)("div",{className:`cz-dim${n.enabled?"":" cz-dim-off"}`,children:[(0,a.jsxs)("div",{className:"cz-toolbar",children:[(0,a.jsx)("div",{className:"cz-locale-tabs",children:Object.keys(n.fragments[0]?.locales??{zh:0,en:0}).map(t=>(0,a.jsx)("button",{className:`cz-tab${p===t?" cz-tab-on":""}`,onClick:()=>g(t),children:t.toUpperCase()},t))}),(0,a.jsx)("div",{className:"cz-toolbar-spacer"}),(0,a.jsxs)("button",{className:"cz-btn cz-btn-ghost",onClick:()=>h(t=>!t),children:["\u5386\u53F2 / \u56DE\u6EDA (",n.history.length,")"]}),(0,a.jsx)("a",{className:"cz-btn cz-btn-ghost",href:"/api/customization/export",download:!0,children:"\u5BFC\u51FA bundle"}),(0,a.jsx)("button",{className:"cz-btn cz-btn-ghost",onClick:()=>o(!0),children:"\u5BFC\u5165 bundle"}),(0,a.jsx)("button",{className:"cz-btn cz-btn-danger",onClick:async()=>{await k({title:"\u5168\u90E8\u6062\u590D\u51FA\u5382",message:"\u628A\u6240\u6709 prompt/skill \u8986\u76D6\u6062\u590D\u51FA\u5382\uFF1F\u4F1A\u5148\u5B58\u5FEB\u7167\uFF0C\u53EF\u56DE\u6EDA\u64A4\u56DE\u3002",danger:!0,confirmLabel:"\u6062\u590D\u51FA\u5382"})&&(await N("/api/customization/reset-all"),u("\u5DF2\u5168\u90E8\u6062\u590D\u51FA\u5382"))},children:"\u5168\u90E8\u6062\u590D\u51FA\u5382"})]}),i?(0,a.jsxs)("div",{className:"cz-section",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("span",{className:"cz-dot"}),(0,a.jsx)("h2",{children:"\u6539\u52A8\u5386\u53F2"}),(0,a.jsx)("span",{className:"cz-sub",children:"\u56DE\u6EDA\u672C\u8EAB\u4E5F\u5B58\u5FEB\u7167\uFF0C\u975E\u7834\u574F\u5F0F"})]}),(0,a.jsx)("div",{className:"cz-section-body",children:n.history.length===0?(0,a.jsx)("div",{className:"cz-hint",children:"\uFF08\u6682\u65E0\u5386\u53F2\uFF09"}):n.history.map(t=>(0,a.jsxs)("div",{className:"cz-hist-row",children:[(0,a.jsx)("span",{className:"cz-hist-when",children:O(t.at)}),(0,a.jsx)("span",{className:"cz-hist-label",children:t.label}),(0,a.jsxs)("span",{className:"cz-hist-sum",children:["prompt ",t.summary.promptKeys," \xB7 skill ",t.summary.skills," \xB7 ",t.summary.enabled?"on":"off"]}),(0,a.jsx)("button",{className:"cz-link",onClick:async()=>{await k({title:"\u56DE\u6EDA\u5FEB\u7167",message:"\u56DE\u6EDA\u5230\u6B64\u5FEB\u7167\uFF1F\u56DE\u6EDA\u672C\u8EAB\u4E5F\u4F1A\u5B58\u5FEB\u7167\uFF0C\u975E\u7834\u574F\u5F0F\u3002",confirmLabel:"\u56DE\u6EDA"})&&(await N("/api/customization/rollback",{id:t.id}),u("\u5DF2\u56DE\u6EDA"))},children:"\u56DE\u6EDA\u5230\u6B64"})]},t.id))})]}):null,(0,a.jsxs)("div",{className:"cz-section",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("span",{className:"cz-dot"}),(0,a.jsx)("h2",{children:"\u5185\u7F6E Prompt \u7247\u6BB5"}),(0,a.jsxs)("span",{className:"cz-sub",children:["\u5B9E\u9645\u6CE8\u5165\u6A21\u578B\u7684\u5185\u5BB9 \xB7 ",$," \u5904\u5DF2\u6539\uFF08",p.toUpperCase(),"\uFF09"]})]}),(0,a.jsxs)("div",{className:"cz-section-body",children:[(0,a.jsxs)("div",{className:"cz-legend",children:[(0,a.jsxs)("span",{children:[(0,a.jsx)("i",{className:"cz-sq cz-sq-editable"}),"\u53EF\u7F16\u8F91\uFF1A\u70B9\u51FB\u5C31\u5730\u6539"]}),(0,a.jsxs)("span",{children:[(0,a.jsx)("i",{className:"cz-sq cz-sq-conditional"}),"\u6761\u4EF6\u884C\uFF1A\u4E0B\u62C9\u51B3\u5B9A\u662F\u5426\u6CE8\u5165"]}),(0,a.jsx)("span",{className:"cz-chip cz-chip-ph",style:{fontSize:10},children:"{\u5360\u4F4D\u7B26}"})," \u5220\u4E0D\u5F97\uFF0C\u4FDD\u5B58\u65F6\u6821\u9A8C"]}),(0,a.jsxs)("div",{className:"cz-callout",children:["\u26A0 \u9003\u751F\u9600\uFF1A\u53EF\u4EE5\u5220\u6389\u547D\u8109\u6307\u4EE4\uFF08\u5982 ",(0,a.jsx)("code",{children:"botmux send"}),"\uFF09\uFF0C\u4F46\u673A\u5668\u4EBA\u53EF\u80FD\u56E0\u6B64\u65E0\u6CD5\u628A\u56DE\u590D\u53D1\u56DE\u98DE\u4E66\u3002\u62FF\u4E0D\u51C6\u5C31\u70B9\u300C\u6062\u590D\u51FA\u5382\u300D\u3002"]}),E.map(t=>(0,a.jsxs)("div",{className:"cz-block",children:[(0,a.jsxs)("div",{className:"cz-block-label",children:[(0,a.jsx)("span",{className:"cz-block-tag",children:L[t]??t}),(0,a.jsx)("span",{className:"cz-block-line"})]}),n.fragments.filter(b=>b.block===t).map(b=>(0,a.jsx)(D,{frag:b,locale:p,onSaved:f,onError:d},b.key))]},t))]})]}),(0,a.jsxs)("div",{className:"cz-section",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("span",{className:"cz-dot"}),(0,a.jsx)("h2",{children:"\u5185\u7F6E Skill \u8986\u76D6"}),(0,a.jsxs)("span",{className:"cz-sub",children:[n.skills.length," \u4E2A\u5185\u7F6E\u6280\u80FD \xB7 ",F," \u4E2A\u5DF2\u6539/\u505C\u7528"]})]}),(0,a.jsx)("div",{className:"cz-section-body",children:n.skills.map(t=>(0,a.jsx)(M,{skill:t,onSaved:f,onError:d},t.name))})]})]}),l?(0,a.jsx)("div",{className:"cz-toast",children:l}):null,m?(0,a.jsx)(R,{onClose:()=>o(!1),onApplied:f,onError:d}):null]})}function U(n){return C(n,(0,a.jsx)(J,{}))}var q=`
1
+ import{a as k}from"./chunk-CEUCNZFJ.js";import{c as P}from"./chunk-QALRQEKD.js";import{c as C}from"./chunk-ARROO6TE.js";import{c as y,d as j,e as S}from"./chunk-3YZFAHNK.js";var s=y(j(),1);var a=y(S(),1),L={botmux_routing:"<botmux_routing> \u8DEF\u7531\u8BF4\u660E",identity:"<identity> \u8EAB\u4EFD\u89C4\u5219",shell_hints:"Shell \u63D0\u793A\uFF08codex/gemini \u7B49\uFF09",available_bots:"<available_bots> \u534F\u4F5C bot",attachments:"<attachments> \u9644\u4EF6",followup:"\u8DDF\u8FDB\u8F6E\u63D0\u9192"};function O(n){let e=Date.parse(n);if(!e)return n||"-";let c=Math.max(0,Math.floor((Date.now()-e)/1e3));if(c<60)return`${c}s \u524D`;let r=Math.floor(c/60);if(r<60)return`${r}m \u524D`;let l=Math.floor(r/60);return l<24?`${l}h \u524D`:`${Math.floor(l/24)}d \u524D`}async function x(n,e){let c=await fetch(n,e),r=await c.json().catch(()=>({}));if(!c.ok||r?.ok===!1)throw new Error(r?.error||`HTTP ${c.status}`);return r}function D(n){let{frag:e,locale:c}=n,r=e.locales[c]??{factory:"",override:null},l=r.override!==null,[z,p]=(0,s.useState)(!1),[g,m]=(0,s.useState)(r.override??r.factory),[o,i]=(0,s.useState)(!1);(0,s.useEffect)(()=>{m(r.override??r.factory),p(!1)},[r.override,r.factory,c]);let h=async d=>{i(!0);try{let f=await x("/api/customization/prompt",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({locale:c,key:e.key,value:d})});n.onSaved(f.snapshot),p(!1)}catch(f){n.onError(f?.message??"\u4FDD\u5B58\u5931\u8D25")}finally{i(!1)}},u=async d=>{i(!0);try{let f=await x("/api/customization/condition",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,value:d})});n.onSaved(f.snapshot)}catch(f){n.onError(f?.message??"\u4FDD\u5B58\u5931\u8D25")}finally{i(!1)}};return(0,a.jsxs)("div",{className:`cz-frag cz-frag-${e.kind}${l?" cz-mod":""}`,children:[(0,a.jsx)("div",{className:"cz-frag-bar"}),(0,a.jsxs)("div",{className:"cz-frag-inner",children:[(0,a.jsxs)("div",{className:"cz-frag-top",children:[(0,a.jsx)("span",{className:"cz-frag-label",children:e.label}),(0,a.jsx)("code",{className:"cz-frag-key",children:e.key}),(0,a.jsxs)("span",{className:"cz-frag-badges",children:[l?(0,a.jsx)("span",{className:"cz-chip cz-chip-mod",children:"\u5DF2\u4FEE\u6539"}):null,e.kind==="placeholder"?(0,a.jsxs)("span",{className:"cz-chip cz-chip-ph",children:["\u5360\u4F4D\u7B26 ",(e.placeholders??[]).map(d=>`{${d}}`).join(" ")]}):null,e.kind==="conditional"?(0,a.jsxs)("span",{className:"cz-chip cz-chip-cond",children:["\u6761\u4EF6\u884C",(0,a.jsxs)("select",{className:"cz-cond-select",disabled:o,value:e.conditionForced===null||e.conditionForced===void 0?"default":e.conditionForced?"on":"off",onChange:d=>{let f=d.target.value;u(f==="default"?null:f==="on")},children:[(0,a.jsx)("option",{value:"default",children:"\u8DDF\u968F\u9ED8\u8BA4"}),(0,a.jsx)("option",{value:"on",children:"\u5F3A\u5236\u663E\u793A"}),(0,a.jsx)("option",{value:"off",children:"\u5F3A\u5236\u9690\u85CF"})]})]}):null,l?(0,a.jsx)("button",{className:"cz-link cz-link-reset",disabled:o,onClick:()=>{h(null)},children:"\u6062\u590D\u51FA\u5382"}):null]})]}),z?(0,a.jsxs)("div",{className:"cz-edit",children:[(0,a.jsx)("textarea",{className:"cz-textarea",value:g,rows:Math.max(2,Math.ceil(g.length/52)),onChange:d=>m(d.target.value),autoFocus:!0}),(0,a.jsxs)("div",{className:"cz-edit-actions",children:[(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:o,onClick:()=>{h(g)},children:"\u4FDD\u5B58"}),(0,a.jsx)("button",{className:"cz-btn cz-btn-ghost",disabled:o,onClick:()=>{m(r.override??r.factory),p(!1)},children:"\u53D6\u6D88"}),e.kind==="placeholder"?(0,a.jsxs)("span",{className:"cz-hint",children:["\u4FDD\u7559 ",(e.placeholders??[]).map(d=>`{${d}}`).join("\u3001")," \u624D\u80FD\u4FDD\u5B58"]}):null]})]}):(0,a.jsxs)("div",{className:"cz-frag-text",onClick:()=>p(!0),title:"\u70B9\u51FB\u7F16\u8F91",children:[r.override??r.factory,(0,a.jsx)("span",{className:"cz-edit-hint",children:"\u270E"})]})]})]})}function M(n){let{skill:e}=n,[c,r]=(0,s.useState)(!1),[l,z]=(0,s.useState)(e.override??e.factory),[p,g]=(0,s.useState)(!1);(0,s.useEffect)(()=>{z(e.override??e.factory)},[e.override,e.factory]);let m=async o=>{g(!0);try{let i=await x("/api/customization/skill",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,...o})});n.onSaved(i.snapshot)}catch(i){n.onError(i?.message??"\u4FDD\u5B58\u5931\u8D25")}finally{g(!1)}};return(0,a.jsxs)("div",{className:`cz-skill${e.disabled?" cz-skill-off":""}`,children:[(0,a.jsxs)("div",{className:"cz-skill-head",onClick:()=>r(o=>!o),children:[(0,a.jsx)("span",{className:`cz-caret${c?" cz-caret-open":""}`,children:"\u25B6"}),(0,a.jsx)("code",{className:"cz-skill-name",children:e.name}),(0,a.jsx)("span",{className:"cz-skill-desc",children:e.description}),(0,a.jsxs)("span",{className:"cz-skill-badges",children:[e.disabled?(0,a.jsx)("span",{className:"cz-chip cz-chip-off",children:"\u5DF2\u505C\u7528"}):e.override!==null?(0,a.jsx)("span",{className:"cz-chip cz-chip-mod",children:"\u6B63\u6587\u5DF2\u6539"}):(0,a.jsx)("span",{className:"cz-chip cz-chip-factory",children:"\u51FA\u5382\u9ED8\u8BA4"}),e.override!==null?(0,a.jsx)("button",{className:"cz-link cz-link-reset",disabled:p,onClick:o=>{o.stopPropagation(),m({body:null})},children:"\u6062\u590D\u6B63\u6587"}):null,(0,a.jsx)("button",{className:`cz-link${e.disabled?"":" cz-link-danger"}`,disabled:p,onClick:o=>{o.stopPropagation(),m({disabled:!e.disabled})},children:e.disabled?"\u542F\u7528":"\u505C\u7528"})]})]}),c?(0,a.jsxs)("div",{className:"cz-skill-body",children:[(0,a.jsx)("textarea",{className:"cz-textarea cz-skill-textarea",value:l,onChange:o=>z(o.target.value),disabled:e.disabled,rows:12}),(0,a.jsxs)("div",{className:"cz-edit-actions",children:[(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:p||e.disabled,onClick:()=>{m({body:l})},children:"\u4FDD\u5B58\u6B63\u6587\u8986\u76D6"}),(0,a.jsx)("span",{className:"cz-hint",children:"\u7559\u7A7A\u5E76\u4FDD\u5B58 = \u7528\u51FA\u5382\u9ED8\u8BA4\uFF1B\u5B8C\u6574 SKILL.md\uFF08frontmatter + \u6B63\u6587\uFF09"})]})]}):null]})}function R(n){let[e,c]=(0,s.useState)(""),[r,l]=(0,s.useState)(null),[z,p]=(0,s.useState)(!1),g=async o=>{p(!0);try{let i=await x("/api/customization/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:e,apply:o})});if(o&&i.applied){n.onApplied(i.snapshot),n.onClose();return}l(i.preview)}catch(i){n.onError(i?.message??"\u5BFC\u5165\u5931\u8D25")}finally{p(!1)}},m=o=>{let i=new FileReader;i.onload=()=>{c(String(i.result??"")),l(null)},i.readAsText(o)};return(0,a.jsx)("div",{className:"cz-mask",onClick:o=>{o.target===o.currentTarget&&n.onClose()},children:(0,a.jsxs)("div",{className:"cz-modal",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("h3",{children:"\u5BFC\u5165 bundle"}),(0,a.jsx)("button",{className:"cz-x",onClick:n.onClose,children:"\xD7"})]}),(0,a.jsxs)("div",{className:"cz-modal-body",children:[(0,a.jsxs)("label",{className:"cz-drop",onDragOver:o=>o.preventDefault(),onDrop:o=>{o.preventDefault();let i=o.dataTransfer.files[0];i&&m(i)},children:["\u62D6\u5165 .json \u6587\u4EF6\uFF0C\u6216\u70B9\u6B64\u9009\u62E9",(0,a.jsx)("input",{type:"file",accept:".json,application/json",style:{display:"none"},onChange:o=>{let i=o.target.files?.[0];i&&m(i)}})]}),(0,a.jsx)("textarea",{className:"cz-textarea",placeholder:"\u6216\u76F4\u63A5\u7C98\u8D34 bundle JSON\u2026",value:e,rows:6,onChange:o=>{c(o.target.value),l(null)}}),r?(0,a.jsxs)("div",{className:"cz-diff",children:[(0,a.jsxs)("div",{className:"cz-diff-sum",children:["\u65B0\u589E ",r.summary.adds," \xB7 \u66FF\u6362 ",r.summary.replaces," \xB7 \u505C\u7528 ",r.summary.disables," \xB7 \u65E0\u53D8\u5316 ",r.summary.unchanged]}),r.diff.map((o,i)=>(0,a.jsxs)("div",{className:`cz-diff-row cz-diff-${o.action}`,children:[(0,a.jsx)("span",{className:"cz-diff-mark",children:o.action==="add"?"\uFF0B":o.action==="replace"?"\u21BB":o.action==="disable"?"\u2298":"\uFF1D"}),(0,a.jsxs)("span",{className:"cz-diff-id",children:[o.kind,":",o.id,o.locale?` (${o.locale})`:""]}),o.after?(0,a.jsx)("span",{className:"cz-diff-after",children:o.after}):null]},i))]}):null]}),(0,a.jsxs)("footer",{children:[(0,a.jsx)("button",{className:"cz-btn cz-btn-ghost",onClick:n.onClose,children:"\u53D6\u6D88"}),r?(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:z,onClick:()=>{g(!0)},children:"\u786E\u8BA4\u5BFC\u5165\uFF08\u5148\u5B58\u5FEB\u7167\uFF09"}):(0,a.jsx)("button",{className:"cz-btn cz-btn-primary",disabled:z||!e.trim(),onClick:()=>{g(!1)},children:"\u9884\u89C8\u5DEE\u5F02"})]})]})})}function J(){let[n,e]=(0,s.useState)(null),[c,r]=(0,s.useState)(null),[l,z]=(0,s.useState)(null),[p,g]=(0,s.useState)("zh"),[m,o]=(0,s.useState)(!1),[i,h]=(0,s.useState)(!1),u=(0,s.useCallback)(t=>{z(t),window.setTimeout(()=>z(null),2400)},[]),d=(0,s.useCallback)(t=>u(`\u26A0 ${t}`),[u]),f=(0,s.useCallback)(t=>{e(t),u("\u5DF2\u4FDD\u5B58 \xB7 \u4E0B\u4E2A\u4F1A\u8BDD\u5373\u751F\u6548")},[u]),w=(0,s.useCallback)(async()=>{try{e(await x("/api/customization"))}catch(t){r(t?.message??"\u52A0\u8F7D\u5931\u8D25")}},[]);(0,s.useEffect)(()=>{w()},[w]);let N=async(t,b)=>{try{let v=await x(t,{method:"POST",headers:{"Content-Type":"application/json"},body:b?JSON.stringify(b):void 0});return v.snapshot&&e(v.snapshot),v}catch(v){d(v?.message??"\u64CD\u4F5C\u5931\u8D25")}},T=async t=>{try{let b=await x("/api/customization/enabled",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});e(b.snapshot),u(t?"\u81EA\u5B9A\u4E49\u5DF2\u542F\u7528":"\u81EA\u5B9A\u4E49\u5DF2\u505C\u7528\uFF08\u8986\u76D6\u4FDD\u7559\uFF09")}catch(b){d(b?.message??"\u64CD\u4F5C\u5931\u8D25")}};if(c)return(0,a.jsx)("div",{className:"cz-page",children:(0,a.jsxs)("div",{className:"cz-error",children:["\u52A0\u8F7D\u5931\u8D25\uFF1A",c]})});if(!n)return(0,a.jsx)(P,{label:"\u52A0\u8F7D\u81EA\u5B9A\u4E49\u914D\u7F6E\u2026"});let E=Array.from(new Set(n.fragments.map(t=>t.block))),$=n.fragments.filter(t=>t.locales[p]?.override!==null).length,F=n.skills.filter(t=>t.override!==null||t.disabled).length;return(0,a.jsxs)("section",{className:"cz-page",children:[(0,a.jsx)("style",{children:q}),(0,a.jsx)("div",{className:"cz-head",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{children:"\u81EA\u5B9A\u4E49\u4E2D\u5FC3"}),(0,a.jsxs)("p",{children:["\u8C03\u4F18 botmux \u5185\u7F6E\u7684\u6846\u67B6 prompt \u4E0E\u5185\u7F6E skill\u3002\u6240\u6709\u6539\u52A8",(0,a.jsx)("b",{children:"\u4E0B\u4E00\u4E2A\u4F1A\u8BDD\u5373\u751F\u6548\uFF0C\u65E0\u9700\u91CD\u542F daemon"}),"\uFF1B\u968F\u65F6\u53EF\u9010\u9879\u6062\u590D\u51FA\u5382\u6216\u6574\u4F53\u56DE\u6EDA\u3002"]})]})}),(0,a.jsxs)("div",{className:"cz-master",children:[(0,a.jsxs)("div",{className:"cz-master-txt",children:[(0,a.jsx)("b",{children:"\u542F\u7528\u81EA\u5B9A\u4E49"}),(0,a.jsx)("span",{children:"\u5173\u95ED\u540E\u6240\u6709\u8986\u76D6\u7ACB\u5373\u505C\u7528\u3001\u4F46\u4E0D\u5220\u9664\u2014\u2014\u6392\u67E5\u300C\u662F\u4E0D\u662F\u6211\u6539\u7684 prompt \u5BFC\u81F4\u7684\u300D\u65F6\u4E00\u952E\u56DE\u5230\u51FA\u5382\u884C\u4E3A\u3002"})]}),(0,a.jsxs)("label",{className:"toggle-row cz-master-switch",children:[(0,a.jsx)("input",{type:"checkbox",checked:n.enabled,onChange:t=>{T(t.currentTarget.checked)}}),(0,a.jsx)("span",{className:"switch","aria-hidden":"true"})]})]}),(0,a.jsxs)("div",{className:`cz-dim${n.enabled?"":" cz-dim-off"}`,children:[(0,a.jsxs)("div",{className:"cz-toolbar",children:[(0,a.jsx)("div",{className:"cz-locale-tabs",children:Object.keys(n.fragments[0]?.locales??{zh:0,en:0}).map(t=>(0,a.jsx)("button",{className:`cz-tab${p===t?" cz-tab-on":""}`,onClick:()=>g(t),children:t.toUpperCase()},t))}),(0,a.jsx)("div",{className:"cz-toolbar-spacer"}),(0,a.jsxs)("button",{className:"cz-btn cz-btn-ghost",onClick:()=>h(t=>!t),children:["\u5386\u53F2 / \u56DE\u6EDA (",n.history.length,")"]}),(0,a.jsx)("a",{className:"cz-btn cz-btn-ghost",href:"/api/customization/export",download:!0,children:"\u5BFC\u51FA bundle"}),(0,a.jsx)("button",{className:"cz-btn cz-btn-ghost",onClick:()=>o(!0),children:"\u5BFC\u5165 bundle"}),(0,a.jsx)("button",{className:"cz-btn cz-btn-danger",onClick:async()=>{await k({title:"\u5168\u90E8\u6062\u590D\u51FA\u5382",message:"\u628A\u6240\u6709 prompt/skill \u8986\u76D6\u6062\u590D\u51FA\u5382\uFF1F\u4F1A\u5148\u5B58\u5FEB\u7167\uFF0C\u53EF\u56DE\u6EDA\u64A4\u56DE\u3002",danger:!0,confirmLabel:"\u6062\u590D\u51FA\u5382"})&&(await N("/api/customization/reset-all"),u("\u5DF2\u5168\u90E8\u6062\u590D\u51FA\u5382"))},children:"\u5168\u90E8\u6062\u590D\u51FA\u5382"})]}),i?(0,a.jsxs)("div",{className:"cz-section",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("span",{className:"cz-dot"}),(0,a.jsx)("h2",{children:"\u6539\u52A8\u5386\u53F2"}),(0,a.jsx)("span",{className:"cz-sub",children:"\u56DE\u6EDA\u672C\u8EAB\u4E5F\u5B58\u5FEB\u7167\uFF0C\u975E\u7834\u574F\u5F0F"})]}),(0,a.jsx)("div",{className:"cz-section-body",children:n.history.length===0?(0,a.jsx)("div",{className:"cz-hint",children:"\uFF08\u6682\u65E0\u5386\u53F2\uFF09"}):n.history.map(t=>(0,a.jsxs)("div",{className:"cz-hist-row",children:[(0,a.jsx)("span",{className:"cz-hist-when",children:O(t.at)}),(0,a.jsx)("span",{className:"cz-hist-label",children:t.label}),(0,a.jsxs)("span",{className:"cz-hist-sum",children:["prompt ",t.summary.promptKeys," \xB7 skill ",t.summary.skills," \xB7 ",t.summary.enabled?"on":"off"]}),(0,a.jsx)("button",{className:"cz-link",onClick:async()=>{await k({title:"\u56DE\u6EDA\u5FEB\u7167",message:"\u56DE\u6EDA\u5230\u6B64\u5FEB\u7167\uFF1F\u56DE\u6EDA\u672C\u8EAB\u4E5F\u4F1A\u5B58\u5FEB\u7167\uFF0C\u975E\u7834\u574F\u5F0F\u3002",confirmLabel:"\u56DE\u6EDA"})&&(await N("/api/customization/rollback",{id:t.id}),u("\u5DF2\u56DE\u6EDA"))},children:"\u56DE\u6EDA\u5230\u6B64"})]},t.id))})]}):null,(0,a.jsxs)("div",{className:"cz-section",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("span",{className:"cz-dot"}),(0,a.jsx)("h2",{children:"\u5185\u7F6E Prompt \u7247\u6BB5"}),(0,a.jsxs)("span",{className:"cz-sub",children:["\u5B9E\u9645\u6CE8\u5165\u6A21\u578B\u7684\u5185\u5BB9 \xB7 ",$," \u5904\u5DF2\u6539\uFF08",p.toUpperCase(),"\uFF09"]})]}),(0,a.jsxs)("div",{className:"cz-section-body",children:[(0,a.jsxs)("div",{className:"cz-legend",children:[(0,a.jsxs)("span",{children:[(0,a.jsx)("i",{className:"cz-sq cz-sq-editable"}),"\u53EF\u7F16\u8F91\uFF1A\u70B9\u51FB\u5C31\u5730\u6539"]}),(0,a.jsxs)("span",{children:[(0,a.jsx)("i",{className:"cz-sq cz-sq-conditional"}),"\u6761\u4EF6\u884C\uFF1A\u4E0B\u62C9\u51B3\u5B9A\u662F\u5426\u6CE8\u5165"]}),(0,a.jsx)("span",{className:"cz-chip cz-chip-ph",style:{fontSize:10},children:"{\u5360\u4F4D\u7B26}"})," \u5220\u4E0D\u5F97\uFF0C\u4FDD\u5B58\u65F6\u6821\u9A8C"]}),(0,a.jsxs)("div",{className:"cz-callout",children:["\u26A0 \u9003\u751F\u9600\uFF1A\u53EF\u4EE5\u5220\u6389\u547D\u8109\u6307\u4EE4\uFF08\u5982 ",(0,a.jsx)("code",{children:"botmux send"}),"\uFF09\uFF0C\u4F46\u673A\u5668\u4EBA\u53EF\u80FD\u56E0\u6B64\u65E0\u6CD5\u628A\u56DE\u590D\u53D1\u56DE\u98DE\u4E66\u3002\u62FF\u4E0D\u51C6\u5C31\u70B9\u300C\u6062\u590D\u51FA\u5382\u300D\u3002"]}),E.map(t=>(0,a.jsxs)("div",{className:"cz-block",children:[(0,a.jsxs)("div",{className:"cz-block-label",children:[(0,a.jsx)("span",{className:"cz-block-tag",children:L[t]??t}),(0,a.jsx)("span",{className:"cz-block-line"})]}),n.fragments.filter(b=>b.block===t).map(b=>(0,a.jsx)(D,{frag:b,locale:p,onSaved:f,onError:d},b.key))]},t))]})]}),(0,a.jsxs)("div",{className:"cz-section",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("span",{className:"cz-dot"}),(0,a.jsx)("h2",{children:"\u5185\u7F6E Skill \u8986\u76D6"}),(0,a.jsxs)("span",{className:"cz-sub",children:[n.skills.length," \u4E2A\u5185\u7F6E\u6280\u80FD \xB7 ",F," \u4E2A\u5DF2\u6539/\u505C\u7528"]})]}),(0,a.jsx)("div",{className:"cz-section-body",children:n.skills.map(t=>(0,a.jsx)(M,{skill:t,onSaved:f,onError:d},t.name))})]})]}),l?(0,a.jsx)("div",{className:"cz-toast",children:l}):null,m?(0,a.jsx)(R,{onClose:()=>o(!1),onApplied:f,onError:d}):null]})}function U(n){return C(n,(0,a.jsx)(J,{}))}var q=`
2
2
  .cz-page{max-width:960px;padding:20px 22px 80px;}
3
3
  .cz-head h1{font-size:22px;margin:0 0 4px;font-weight:680;}
4
4
  .cz-head p{margin:0;color:var(--muted);font-size:13.5px;max-width:66ch;}
@@ -1 +1 @@
1
- import{x as n}from"./chunk-K232GT3M.js";import{c as v}from"./chunk-ARROO6TE.js";import{c as m,d as F,e as f}from"./chunk-3YZFAHNK.js";var r=m(F(),1);var e=m(f(),1);function C(){let s=new Date,o=new Date(s.getTime()-30*864e5);return new URLSearchParams({from:o.toISOString(),to:s.toISOString()})}async function c(s,o){let i=await fetch(`${s}?${o}`);if(!i.ok)throw new Error(await i.text());return i.json()}function E(){let[s,o]=(0,r.useState)(),[i,k]=(0,r.useState)([]),[l,y]=(0,r.useState)([]),[h,S]=(0,r.useState)([]),[u,R]=(0,r.useState)(),[b,p]=(0,r.useState)(""),g=async a=>{try{p("");let t=C(),[I,D,T,d]=await Promise.all([c("/api/feedback/analytics/summary",t),c("/api/feedback/analytics/trend",t),c("/api/feedback/analytics/reasons",t),c("/api/feedback/analytics/deliveries",new URLSearchParams([...t,["limit","25"],...a?[["cursor",a]]:[]]))]);o(I),k(D.items),y(T.items),S(x=>a?[...x,...d.items]:d.items),R(d.nextCursor)}catch(t){p(t instanceof Error?t.message:String(t))}};(0,r.useEffect)(()=>{g()},[]);let N=Math.max(1,...i.map(a=>a.ratings)),P=Math.max(1,...l.map(a=>a.count));return(0,e.jsxs)("div",{className:"page feedback-page",children:[(0,e.jsx)("header",{className:"sect-header",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{children:n("feedback.title")}),(0,e.jsx)("p",{children:n("feedback.subtitle")})]})}),b&&(0,e.jsx)("p",{className:"error-banner",children:b}),(0,e.jsx)("section",{className:"feedback-kpis",children:[["feedback.delivered",s?.delivered],["feedback.rated",s?.ratedDeliveries],["feedback.coverage",s?`${Math.round(s.ratingCoverage*100)}%`:void 0],["feedback.positiveRate",s?`${Math.round(s.positiveRate*100)}%`:void 0],["feedback.deliveryFailures",s?.deliveryFailures],["feedback.outboxFailures",s?.outboxFailures]].map(([a,t])=>(0,e.jsxs)("article",{children:[(0,e.jsx)("span",{children:n(String(a))}),(0,e.jsx)("strong",{children:t??"\u2014"})]},String(a)))}),(0,e.jsxs)("div",{className:"feedback-grid",children:[(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.trend")}),i.map(a=>(0,e.jsxs)("div",{className:"feedback-bar",children:[(0,e.jsx)("span",{children:a.bucket}),(0,e.jsx)("i",{style:{width:`${a.ratings/N*100}%`}}),(0,e.jsxs)("b",{children:[a.positive,"/",a.ratings]})]},a.bucket))]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.reasons")}),l.map(a=>(0,e.jsxs)("div",{className:"feedback-bar negative",children:[(0,e.jsx)("span",{children:a.reasonKey}),(0,e.jsx)("i",{style:{width:`${a.count/P*100}%`}}),(0,e.jsx)("b",{children:a.count})]},a.reasonKey))]})]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.deliveries")}),(0,e.jsx)("div",{className:"feedback-deliveries",children:h.map(a=>(0,e.jsxs)("div",{children:[(0,e.jsx)("code",{children:a.deliveryId}),(0,e.jsx)("span",{children:a.createdAt}),(0,e.jsxs)("span",{children:[a.botAppId??"\u2014"," \xB7 ",a.model??a.cliId??"\u2014"]}),(0,e.jsx)("b",{children:a.semantic??a.status??"unrated"})]},a.deliveryId))}),u&&(0,e.jsx)("button",{className:"btn-link feedback-more",onClick:()=>{g(u)},children:n("feedback.loadMore")})]})]})}function w(s){return v(s,(0,e.jsx)(E,{}))}export{w as renderFeedbackPage};
1
+ import{y as n}from"./chunk-IRFGJSPL.js";import{c as v}from"./chunk-ARROO6TE.js";import{c as m,d as F,e as f}from"./chunk-3YZFAHNK.js";var r=m(F(),1);var e=m(f(),1);function C(){let s=new Date,o=new Date(s.getTime()-30*864e5);return new URLSearchParams({from:o.toISOString(),to:s.toISOString()})}async function c(s,o){let i=await fetch(`${s}?${o}`);if(!i.ok)throw new Error(await i.text());return i.json()}function E(){let[s,o]=(0,r.useState)(),[i,k]=(0,r.useState)([]),[l,y]=(0,r.useState)([]),[h,S]=(0,r.useState)([]),[u,R]=(0,r.useState)(),[b,p]=(0,r.useState)(""),g=async a=>{try{p("");let t=C(),[I,D,T,d]=await Promise.all([c("/api/feedback/analytics/summary",t),c("/api/feedback/analytics/trend",t),c("/api/feedback/analytics/reasons",t),c("/api/feedback/analytics/deliveries",new URLSearchParams([...t,["limit","25"],...a?[["cursor",a]]:[]]))]);o(I),k(D.items),y(T.items),S(x=>a?[...x,...d.items]:d.items),R(d.nextCursor)}catch(t){p(t instanceof Error?t.message:String(t))}};(0,r.useEffect)(()=>{g()},[]);let N=Math.max(1,...i.map(a=>a.ratings)),P=Math.max(1,...l.map(a=>a.count));return(0,e.jsxs)("div",{className:"page feedback-page",children:[(0,e.jsx)("header",{className:"sect-header",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{children:n("feedback.title")}),(0,e.jsx)("p",{children:n("feedback.subtitle")})]})}),b&&(0,e.jsx)("p",{className:"error-banner",children:b}),(0,e.jsx)("section",{className:"feedback-kpis",children:[["feedback.delivered",s?.delivered],["feedback.rated",s?.ratedDeliveries],["feedback.coverage",s?`${Math.round(s.ratingCoverage*100)}%`:void 0],["feedback.positiveRate",s?`${Math.round(s.positiveRate*100)}%`:void 0],["feedback.deliveryFailures",s?.deliveryFailures],["feedback.outboxFailures",s?.outboxFailures]].map(([a,t])=>(0,e.jsxs)("article",{children:[(0,e.jsx)("span",{children:n(String(a))}),(0,e.jsx)("strong",{children:t??"\u2014"})]},String(a)))}),(0,e.jsxs)("div",{className:"feedback-grid",children:[(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.trend")}),i.map(a=>(0,e.jsxs)("div",{className:"feedback-bar",children:[(0,e.jsx)("span",{children:a.bucket}),(0,e.jsx)("i",{style:{width:`${a.ratings/N*100}%`}}),(0,e.jsxs)("b",{children:[a.positive,"/",a.ratings]})]},a.bucket))]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.reasons")}),l.map(a=>(0,e.jsxs)("div",{className:"feedback-bar negative",children:[(0,e.jsx)("span",{children:a.reasonKey}),(0,e.jsx)("i",{style:{width:`${a.count/P*100}%`}}),(0,e.jsx)("b",{children:a.count})]},a.reasonKey))]})]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.deliveries")}),(0,e.jsx)("div",{className:"feedback-deliveries",children:h.map(a=>(0,e.jsxs)("div",{children:[(0,e.jsx)("code",{children:a.deliveryId}),(0,e.jsx)("span",{children:a.createdAt}),(0,e.jsxs)("span",{children:[a.botAppId??"\u2014"," \xB7 ",a.model??a.cliId??"\u2014"]}),(0,e.jsx)("b",{children:a.semantic??a.status??"unrated"})]},a.deliveryId))}),u&&(0,e.jsx)("button",{className:"btn-link feedback-more",onClick:()=>{g(u)},children:n("feedback.loadMore")})]})]})}function w(s){return v(s,(0,e.jsx)(E,{}))}export{w as renderFeedbackPage};