botmux 3.9.2 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/.runtime-build-id +1 -1
  4. package/dist/adapters/cli/codex.d.ts.map +1 -1
  5. package/dist/adapters/cli/codex.js +6 -0
  6. package/dist/adapters/cli/codex.js.map +1 -1
  7. package/dist/adapters/cli/opencode.d.ts.map +1 -1
  8. package/dist/adapters/cli/opencode.js +7 -1
  9. package/dist/adapters/cli/opencode.js.map +1 -1
  10. package/dist/adapters/cli/reasonix.d.ts +35 -0
  11. package/dist/adapters/cli/reasonix.d.ts.map +1 -0
  12. package/dist/adapters/cli/reasonix.js +236 -0
  13. package/dist/adapters/cli/reasonix.js.map +1 -0
  14. package/dist/adapters/cli/registry.d.ts +2 -1
  15. package/dist/adapters/cli/registry.d.ts.map +1 -1
  16. package/dist/adapters/cli/registry.js +4 -1
  17. package/dist/adapters/cli/registry.js.map +1 -1
  18. package/dist/adapters/cli/types.d.ts +5 -1
  19. package/dist/adapters/cli/types.d.ts.map +1 -1
  20. package/dist/cli.d.ts.map +1 -1
  21. package/dist/cli.js +168 -62
  22. package/dist/cli.js.map +1 -1
  23. package/dist/core/command-handler.d.ts +18 -4
  24. package/dist/core/command-handler.d.ts.map +1 -1
  25. package/dist/core/command-handler.js +234 -26
  26. package/dist/core/command-handler.js.map +1 -1
  27. package/dist/core/dashboard-ipc-server.d.ts +1 -0
  28. package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
  29. package/dist/core/dashboard-ipc-server.js +27 -3
  30. package/dist/core/dashboard-ipc-server.js.map +1 -1
  31. package/dist/core/dispatch.d.ts +54 -24
  32. package/dist/core/dispatch.d.ts.map +1 -1
  33. package/dist/core/dispatch.js +81 -27
  34. package/dist/core/dispatch.js.map +1 -1
  35. package/dist/core/input-turn-dedupe.d.ts +20 -0
  36. package/dist/core/input-turn-dedupe.d.ts.map +1 -0
  37. package/dist/core/input-turn-dedupe.js +57 -0
  38. package/dist/core/input-turn-dedupe.js.map +1 -0
  39. package/dist/core/local-terminal-opener.d.ts.map +1 -1
  40. package/dist/core/local-terminal-opener.js +10 -1
  41. package/dist/core/local-terminal-opener.js.map +1 -1
  42. package/dist/core/passthrough-commands.d.ts.map +1 -1
  43. package/dist/core/passthrough-commands.js +1 -1
  44. package/dist/core/passthrough-commands.js.map +1 -1
  45. package/dist/core/plugins/pm2.d.ts.map +1 -1
  46. package/dist/core/plugins/pm2.js +7 -1
  47. package/dist/core/plugins/pm2.js.map +1 -1
  48. package/dist/core/resource-monitor/attribution.d.ts.map +1 -1
  49. package/dist/core/resource-monitor/attribution.js +17 -1
  50. package/dist/core/resource-monitor/attribution.js.map +1 -1
  51. package/dist/core/resource-monitor/darwin.d.ts +145 -0
  52. package/dist/core/resource-monitor/darwin.d.ts.map +1 -0
  53. package/dist/core/resource-monitor/darwin.js +360 -0
  54. package/dist/core/resource-monitor/darwin.js.map +1 -0
  55. package/dist/core/resource-monitor/procfs.d.ts.map +1 -1
  56. package/dist/core/resource-monitor/procfs.js +6 -0
  57. package/dist/core/resource-monitor/procfs.js.map +1 -1
  58. package/dist/core/resource-monitor/types.d.ts +1 -1
  59. package/dist/core/resource-monitor/types.d.ts.map +1 -1
  60. package/dist/core/scheduler.d.ts.map +1 -1
  61. package/dist/core/scheduler.js +5 -2
  62. package/dist/core/scheduler.js.map +1 -1
  63. package/dist/core/session-discovery.d.ts.map +1 -1
  64. package/dist/core/session-discovery.js +3 -0
  65. package/dist/core/session-discovery.js.map +1 -1
  66. package/dist/core/session-manager.d.ts +3 -1
  67. package/dist/core/session-manager.d.ts.map +1 -1
  68. package/dist/core/session-manager.js +46 -0
  69. package/dist/core/session-manager.js.map +1 -1
  70. package/dist/core/session-marker.d.ts +1 -8
  71. package/dist/core/session-marker.d.ts.map +1 -1
  72. package/dist/core/session-marker.js +2 -50
  73. package/dist/core/session-marker.js.map +1 -1
  74. package/dist/core/types.d.ts +3 -1
  75. package/dist/core/types.d.ts.map +1 -1
  76. package/dist/core/types.js.map +1 -1
  77. package/dist/core/worker-pool.d.ts +17 -0
  78. package/dist/core/worker-pool.d.ts.map +1 -1
  79. package/dist/core/worker-pool.js +292 -9
  80. package/dist/core/worker-pool.js.map +1 -1
  81. package/dist/daemon.d.ts.map +1 -1
  82. package/dist/daemon.js +27 -12
  83. package/dist/daemon.js.map +1 -1
  84. package/dist/dashboard/daemon-internal-api.d.ts.map +1 -1
  85. package/dist/dashboard/daemon-internal-api.js +11 -2
  86. package/dist/dashboard/daemon-internal-api.js.map +1 -1
  87. package/dist/dashboard/groups-action-helpers.d.ts +2 -0
  88. package/dist/dashboard/groups-action-helpers.d.ts.map +1 -1
  89. package/dist/dashboard/groups-action-helpers.js +9 -0
  90. package/dist/dashboard/groups-action-helpers.js.map +1 -1
  91. package/dist/dashboard/groups-matrix-snapshot.d.ts +56 -0
  92. package/dist/dashboard/groups-matrix-snapshot.d.ts.map +1 -0
  93. package/dist/dashboard/groups-matrix-snapshot.js +127 -0
  94. package/dist/dashboard/groups-matrix-snapshot.js.map +1 -0
  95. package/dist/dashboard/resource-monitor-service.d.ts.map +1 -1
  96. package/dist/dashboard/resource-monitor-service.js +18 -2
  97. package/dist/dashboard/resource-monitor-service.js.map +1 -1
  98. package/dist/dashboard/web/app.d.ts.map +1 -1
  99. package/dist/dashboard/web/app.js +45 -4
  100. package/dist/dashboard/web/app.js.map +1 -1
  101. package/dist/dashboard/web/groups-api.js +1 -1
  102. package/dist/dashboard/web/groups-api.js.map +1 -1
  103. package/dist/dashboard/web/i18n.js +10 -10
  104. package/dist/dashboard/web/i18n.js.map +1 -1
  105. package/dist/dashboard/web/roles-page.d.ts.map +1 -1
  106. package/dist/dashboard/web/roles-page.js +26 -11
  107. package/dist/dashboard/web/roles-page.js.map +1 -1
  108. package/dist/dashboard-web/app.js +1 -1
  109. package/dist/dashboard-web/chunks/{bot-defaults-page-BHTQEWCH.js → bot-defaults-page-LTVOUDIS.js} +1 -1
  110. package/dist/dashboard-web/chunks/{chunk-KLZCQAHF.js → chunk-3UE7S77S.js} +1 -1
  111. package/dist/dashboard-web/chunks/{chunk-W77TPKZH.js → chunk-DCS35UMD.js} +1 -1
  112. package/dist/dashboard-web/chunks/{chunk-E3HZZXK5.js → chunk-MFQPCVHY.js} +4 -4
  113. package/dist/dashboard-web/chunks/{chunk-EZH56JCI.js → chunk-ZU3UUKAR.js} +1 -1
  114. package/dist/dashboard-web/chunks/{connectors-page-BP255CAX.js → connectors-page-5KWDIMKC.js} +1 -1
  115. package/dist/dashboard-web/chunks/{groups-page-CDHVXBUT.js → groups-page-FHOKYXMW.js} +1 -1
  116. package/dist/dashboard-web/chunks/{insights-page-57BFE6GT.js → insights-page-T2ZX2RWL.js} +1 -1
  117. package/dist/dashboard-web/chunks/{monitor-room-UTOYGQVF.js → monitor-room-YNVBAGR6.js} +1 -1
  118. package/dist/dashboard-web/chunks/{monitoring-page-WTHYAIUM.js → monitoring-page-LHM55YWN.js} +1 -1
  119. package/dist/dashboard-web/chunks/{office-page-JSMIB353.js → office-page-ATXVP7PW.js} +1 -1
  120. package/dist/dashboard-web/chunks/{overview-page-3VDBOH7L.js → overview-page-QYI3KBDD.js} +1 -1
  121. package/dist/dashboard-web/chunks/roles-page-56VWM6CD.js +1 -0
  122. package/dist/dashboard-web/chunks/{schedules-page-HHN736H6.js → schedules-page-S5K6U4EO.js} +1 -1
  123. package/dist/dashboard-web/chunks/{sessions-page-EIWOZD7A.js → sessions-page-WBP4N7D2.js} +1 -1
  124. package/dist/dashboard-web/chunks/{settings-page-2IUT5LS4.js → settings-page-QUZDQARR.js} +1 -1
  125. package/dist/dashboard-web/chunks/{skills-page-JKFKMUEM.js → skills-page-IFY7AEND.js} +1 -1
  126. package/dist/dashboard-web/chunks/{team-federation-page-Q2PXC3UY.js → team-federation-page-C7FJQPFZ.js} +1 -1
  127. package/dist/dashboard-web/chunks/{v3-page-EBQCD4AO.js → v3-page-2LMF3WWR.js} +1 -1
  128. package/dist/dashboard-web/chunks/{whiteboards-page-QZRMVNZN.js → whiteboards-page-3XC6QRMY.js} +1 -1
  129. package/dist/dashboard-web/style.css +2 -4
  130. package/dist/dashboard.js +65 -9
  131. package/dist/dashboard.js.map +1 -1
  132. package/dist/i18n/en.d.ts.map +1 -1
  133. package/dist/i18n/en.js +33 -7
  134. package/dist/i18n/en.js.map +1 -1
  135. package/dist/i18n/zh.d.ts.map +1 -1
  136. package/dist/i18n/zh.js +31 -7
  137. package/dist/i18n/zh.js.map +1 -1
  138. package/dist/im/lark/card-builder.d.ts +7 -0
  139. package/dist/im/lark/card-builder.d.ts.map +1 -1
  140. package/dist/im/lark/card-builder.js +56 -0
  141. package/dist/im/lark/card-builder.js.map +1 -1
  142. package/dist/im/lark/card-handler.d.ts.map +1 -1
  143. package/dist/im/lark/card-handler.js +42 -19
  144. package/dist/im/lark/card-handler.js.map +1 -1
  145. package/dist/im/lark/client.d.ts +10 -0
  146. package/dist/im/lark/client.d.ts.map +1 -1
  147. package/dist/im/lark/client.js +79 -0
  148. package/dist/im/lark/client.js.map +1 -1
  149. package/dist/im/lark/event-dispatcher.d.ts +14 -1
  150. package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
  151. package/dist/im/lark/event-dispatcher.js +171 -15
  152. package/dist/im/lark/event-dispatcher.js.map +1 -1
  153. package/dist/im/lark/lark-hosts.d.ts +5 -0
  154. package/dist/im/lark/lark-hosts.d.ts.map +1 -1
  155. package/dist/im/lark/lark-hosts.js +10 -0
  156. package/dist/im/lark/lark-hosts.js.map +1 -1
  157. package/dist/im/lark/message-parser.d.ts.map +1 -1
  158. package/dist/im/lark/message-parser.js +24 -7
  159. package/dist/im/lark/message-parser.js.map +1 -1
  160. package/dist/pm2-graceful-exit.d.ts +28 -0
  161. package/dist/pm2-graceful-exit.d.ts.map +1 -0
  162. package/dist/pm2-graceful-exit.js +39 -0
  163. package/dist/pm2-graceful-exit.js.map +1 -0
  164. package/dist/services/bridge-fallback-gate.d.ts +9 -2
  165. package/dist/services/bridge-fallback-gate.d.ts.map +1 -1
  166. package/dist/services/bridge-fallback-gate.js +31 -19
  167. package/dist/services/bridge-fallback-gate.js.map +1 -1
  168. package/dist/services/message-listener-store.d.ts +18 -0
  169. package/dist/services/message-listener-store.d.ts.map +1 -1
  170. package/dist/services/message-listener-store.js +35 -10
  171. package/dist/services/message-listener-store.js.map +1 -1
  172. package/dist/services/message-listener.d.ts +17 -0
  173. package/dist/services/message-listener.d.ts.map +1 -1
  174. package/dist/services/message-listener.js +26 -0
  175. package/dist/services/message-listener.js.map +1 -1
  176. package/dist/setup/bot-config-editor.d.ts.map +1 -1
  177. package/dist/setup/bot-config-editor.js +2 -0
  178. package/dist/setup/bot-config-editor.js.map +1 -1
  179. package/dist/setup/lark-scopes.json +1 -0
  180. package/dist/setup/verify-permissions.d.ts.map +1 -1
  181. package/dist/setup/verify-permissions.js +8 -0
  182. package/dist/setup/verify-permissions.js.map +1 -1
  183. package/dist/types.d.ts +34 -0
  184. package/dist/types.d.ts.map +1 -1
  185. package/dist/utils/child-env.d.ts +1 -1
  186. package/dist/utils/child-env.d.ts.map +1 -1
  187. package/dist/utils/child-env.js +13 -0
  188. package/dist/utils/child-env.js.map +1 -1
  189. package/dist/utils/file-lock.d.ts.map +1 -1
  190. package/dist/utils/file-lock.js +1 -1
  191. package/dist/utils/file-lock.js.map +1 -1
  192. package/dist/utils/global-install.d.ts.map +1 -1
  193. package/dist/utils/global-install.js +56 -10
  194. package/dist/utils/global-install.js.map +1 -1
  195. package/dist/utils/idle-detector.d.ts +4 -0
  196. package/dist/utils/idle-detector.d.ts.map +1 -1
  197. package/dist/utils/idle-detector.js +25 -0
  198. package/dist/utils/idle-detector.js.map +1 -1
  199. package/dist/utils/process-identity.d.ts +7 -0
  200. package/dist/utils/process-identity.d.ts.map +1 -0
  201. package/dist/utils/process-identity.js +62 -0
  202. package/dist/utils/process-identity.js.map +1 -0
  203. package/dist/worker.js +123 -9
  204. package/dist/worker.js.map +1 -1
  205. package/dist/workflows/events/payloads.d.ts +10 -10
  206. package/dist/workflows/events/schema.d.ts +28 -28
  207. package/dist/workflows/hostExecutors/registry.d.ts +2 -7
  208. package/dist/workflows/hostExecutors/registry.d.ts.map +1 -1
  209. package/dist/workflows/hostExecutors/registry.js.map +1 -1
  210. package/dist/workflows/shared/provider-reconciler.d.ts +1 -30
  211. package/dist/workflows/shared/provider-reconciler.d.ts.map +1 -1
  212. package/dist/workflows/shared/provider-reconciler.js.map +1 -1
  213. package/dist/workflows/v3/artifact-contract.d.ts +41 -0
  214. package/dist/workflows/v3/artifact-contract.d.ts.map +1 -0
  215. package/dist/workflows/v3/artifact-contract.js +20 -0
  216. package/dist/workflows/v3/artifact-contract.js.map +1 -0
  217. package/dist/workflows/v3/botmux-attempt-lease.d.ts +7 -0
  218. package/dist/workflows/v3/botmux-attempt-lease.d.ts.map +1 -0
  219. package/dist/workflows/v3/botmux-attempt-lease.js +189 -0
  220. package/dist/workflows/v3/botmux-attempt-lease.js.map +1 -0
  221. package/dist/workflows/v3/botmux-host-policy.d.ts +7 -0
  222. package/dist/workflows/v3/botmux-host-policy.d.ts.map +1 -0
  223. package/dist/workflows/v3/botmux-host-policy.js +34 -0
  224. package/dist/workflows/v3/botmux-host-policy.js.map +1 -0
  225. package/dist/workflows/v3/cli-run.d.ts +1 -1
  226. package/dist/workflows/v3/cli-run.d.ts.map +1 -1
  227. package/dist/workflows/v3/cli-run.js +1 -1
  228. package/dist/workflows/v3/cli-run.js.map +1 -1
  229. package/dist/workflows/v3/contract.d.ts +8 -89
  230. package/dist/workflows/v3/contract.d.ts.map +1 -1
  231. package/dist/workflows/v3/contract.js +2 -8
  232. package/dist/workflows/v3/contract.js.map +1 -1
  233. package/dist/workflows/v3/core-control.d.ts +16 -0
  234. package/dist/workflows/v3/core-control.d.ts.map +1 -0
  235. package/dist/workflows/v3/core-control.js +60 -0
  236. package/dist/workflows/v3/core-control.js.map +1 -0
  237. package/dist/workflows/v3/daemon-run.d.ts.map +1 -1
  238. package/dist/workflows/v3/daemon-run.js +2 -1
  239. package/dist/workflows/v3/daemon-run.js.map +1 -1
  240. package/dist/workflows/v3/dag-loader.d.ts +5 -0
  241. package/dist/workflows/v3/dag-loader.d.ts.map +1 -0
  242. package/dist/workflows/v3/dag-loader.js +22 -0
  243. package/dist/workflows/v3/dag-loader.js.map +1 -0
  244. package/dist/workflows/v3/dag.d.ts +2 -6
  245. package/dist/workflows/v3/dag.d.ts.map +1 -1
  246. package/dist/workflows/v3/dag.js +2 -24
  247. package/dist/workflows/v3/dag.js.map +1 -1
  248. package/dist/workflows/v3/ephemeral-pool.d.ts.map +1 -1
  249. package/dist/workflows/v3/ephemeral-pool.js +22 -12
  250. package/dist/workflows/v3/ephemeral-pool.js.map +1 -1
  251. package/dist/workflows/v3/event-contract.d.ts +273 -0
  252. package/dist/workflows/v3/event-contract.d.ts.map +1 -0
  253. package/dist/workflows/v3/event-contract.js +8 -0
  254. package/dist/workflows/v3/event-contract.js.map +1 -0
  255. package/dist/workflows/v3/gate-policy.d.ts +12 -0
  256. package/dist/workflows/v3/gate-policy.d.ts.map +1 -0
  257. package/dist/workflows/v3/gate-policy.js +20 -0
  258. package/dist/workflows/v3/gate-policy.js.map +1 -0
  259. package/dist/workflows/v3/gate-wait-store.d.ts +99 -0
  260. package/dist/workflows/v3/gate-wait-store.d.ts.map +1 -0
  261. package/dist/workflows/v3/gate-wait-store.js +263 -0
  262. package/dist/workflows/v3/gate-wait-store.js.map +1 -0
  263. package/dist/workflows/v3/host.js +1 -1
  264. package/dist/workflows/v3/host.js.map +1 -1
  265. package/dist/workflows/v3/human-gate.d.ts +4 -99
  266. package/dist/workflows/v3/human-gate.d.ts.map +1 -1
  267. package/dist/workflows/v3/human-gate.js +4 -275
  268. package/dist/workflows/v3/human-gate.js.map +1 -1
  269. package/dist/workflows/v3/in-process-attempt-lease.d.ts +10 -0
  270. package/dist/workflows/v3/in-process-attempt-lease.d.ts.map +1 -0
  271. package/dist/workflows/v3/in-process-attempt-lease.js +47 -0
  272. package/dist/workflows/v3/in-process-attempt-lease.js.map +1 -0
  273. package/dist/workflows/v3/journal.d.ts +2 -275
  274. package/dist/workflows/v3/journal.d.ts.map +1 -1
  275. package/dist/workflows/v3/journal.js.map +1 -1
  276. package/dist/workflows/v3/library-service.js +1 -1
  277. package/dist/workflows/v3/library-service.js.map +1 -1
  278. package/dist/workflows/v3/orchestrator.d.ts +1 -2
  279. package/dist/workflows/v3/orchestrator.d.ts.map +1 -1
  280. package/dist/workflows/v3/orchestrator.js.map +1 -1
  281. package/dist/workflows/v3/portable-artifact-snapshot.d.ts +15 -0
  282. package/dist/workflows/v3/portable-artifact-snapshot.d.ts.map +1 -0
  283. package/dist/workflows/v3/portable-artifact-snapshot.js +76 -0
  284. package/dist/workflows/v3/portable-artifact-snapshot.js.map +1 -0
  285. package/dist/workflows/v3/portable-final-outputs.d.ts +37 -0
  286. package/dist/workflows/v3/portable-final-outputs.d.ts.map +1 -0
  287. package/dist/workflows/v3/portable-final-outputs.js +137 -0
  288. package/dist/workflows/v3/portable-final-outputs.js.map +1 -0
  289. package/dist/workflows/v3/portable-run-snapshot.d.ts +14 -0
  290. package/dist/workflows/v3/portable-run-snapshot.d.ts.map +1 -0
  291. package/dist/workflows/v3/portable-run-snapshot.js +176 -0
  292. package/dist/workflows/v3/portable-run-snapshot.js.map +1 -0
  293. package/dist/workflows/v3/portable-runtime.d.ts +83 -0
  294. package/dist/workflows/v3/portable-runtime.d.ts.map +1 -0
  295. package/dist/workflows/v3/portable-runtime.js +135 -0
  296. package/dist/workflows/v3/portable-runtime.js.map +1 -0
  297. package/dist/workflows/v3/runtime-host-contract.d.ts +182 -0
  298. package/dist/workflows/v3/runtime-host-contract.d.ts.map +1 -0
  299. package/dist/workflows/v3/runtime-host-contract.js +9 -0
  300. package/dist/workflows/v3/runtime-host-contract.js.map +1 -0
  301. package/dist/workflows/v3/runtime.d.ts +12 -226
  302. package/dist/workflows/v3/runtime.d.ts.map +1 -1
  303. package/dist/workflows/v3/runtime.js +14 -3173
  304. package/dist/workflows/v3/runtime.js.map +1 -1
  305. package/dist/workflows/v3/shared-node-runtime.d.ts +203 -0
  306. package/dist/workflows/v3/shared-node-runtime.d.ts.map +1 -0
  307. package/dist/workflows/v3/shared-node-runtime.js +2978 -0
  308. package/dist/workflows/v3/shared-node-runtime.js.map +1 -0
  309. package/dist/workflows/v3/shared-runtime.d.ts +17 -0
  310. package/dist/workflows/v3/shared-runtime.d.ts.map +1 -0
  311. package/dist/workflows/v3/shared-runtime.js +12 -0
  312. package/dist/workflows/v3/shared-runtime.js.map +1 -0
  313. package/package.json +4 -1
  314. package/dist/dashboard-web/chunks/roles-page-LHVAU2BI.js +0 -1
@@ -1 +1 @@
1
- import{a as n,t as s,u as i}from"./chunk-E3HZZXK5.js";import{a as l}from"./chunk-5THX4DI2.js";import{c as S}from"./chunk-7SZRL6FY.js";var e=S(l(),1);function f(o){return n.on(o)}function m(o){let u=(0,e.useRef)(o),r=(0,e.useRef)(null);u.current=o;let a=()=>{let t=n.getSnapshot();if(r.current&&r.current.version===t.version)return r.current.value;let c=u.current(t);return r.current={version:t.version,value:c},c};return(0,e.useSyncExternalStore)(f,a,a)}function h(o){return s.on(o)}function p(){return s.locale}function v(){return(0,e.useSyncExternalStore)(h,p,p)}function T(){return v(),i}export{m as a,v as b,T as c};
1
+ import{a as n,t as s,u as i}from"./chunk-MFQPCVHY.js";import{a as l}from"./chunk-5THX4DI2.js";import{c as S}from"./chunk-7SZRL6FY.js";var e=S(l(),1);function f(o){return n.on(o)}function m(o){let u=(0,e.useRef)(o),r=(0,e.useRef)(null);u.current=o;let a=()=>{let t=n.getSnapshot();if(r.current&&r.current.version===t.version)return r.current.value;let c=u.current(t);return r.current={version:t.version,value:c},c};return(0,e.useSyncExternalStore)(f,a,a)}function h(o){return s.on(o)}function p(){return s.locale}function v(){return(0,e.useSyncExternalStore)(h,p,p)}function T(){return v(),i}export{m as a,v as b,T as c};
@@ -1 +1 @@
1
- import{a as H,b as Q}from"./chunk-EVK77ASG.js";import{a as de}from"./chunk-ZJVTGU5X.js";import{c as W}from"./chunk-EZH56JCI.js";import{a as ce,c as le,g as Ie,l as M,q as ie}from"./chunk-5CJMHTT4.js";import"./chunk-E3HZZXK5.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Le,d as re}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var i=K(Le(),1);var m=K(Le(),1);var n=K(re(),1),Oe=50,we={total:0,ok:0,error:0,successRate:0};function $e(t,e=Date.now()){if(t==="all")return;let s=t==="24h"?24:t==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function He(t,e=0){let s=new URLSearchParams({limit:String(Oe),offset:String(e)});t.connectorId&&s.set("connectorId",t.connectorId),t.status&&s.set("status",t.status);let g=$e(t.timeWindow);return g&&s.set("since",g),t.query.trim()&&s.set("q",t.query.trim()),s}function Te(t){if(!t)return"\u2014";let e=new Date(t);return Number.isFinite(e.getTime())?e.toLocaleString():t}function ue(t){return t===void 0||!Number.isFinite(t)?"\u2014":t<1e3?`${Math.round(t)} ms`:t<6e4?`${(t/1e3).toFixed(t<1e4?1:0)} s`:`${(t/6e4).toFixed(1)} min`}function Ae(t){return t===void 0?"\u2014":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ve(t){return t.value===void 0||t.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):typeof t.value=="object"&&!Array.isArray(t.value)&&Object.keys(t.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${t.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(t.value,null,2)})})}function qe(t){let e=[["kind",t.value?.kind],["mode",t.value?.mode],["botId",t.value?.botId],["chatId",t.value?.chatId],["sessionId",t.value?.sessionId],["rootMessageId",t.value?.rootMessageId],["workflowId",t.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,g])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(g)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function Ce(t){return(0,n.jsx)(ie,{id:t.id,className:"webhook-log-filter-menu",ariaLabel:t.label,style:{width:"100%",minWidth:0},value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function ge(t){return(0,n.jsxs)("article",{className:`card webhook-log-metric${t.tone?` ${t.tone}`:""}`,children:[(0,n.jsx)("span",{children:t.label}),(0,n.jsx)("strong",{children:t.value}),(0,n.jsx)("small",{children:t.hint||"\xA0"})]})}function Me(t={}){let e=W(),s=(0,m.useRef)(!1),g=(0,m.useRef)([]),[w,L]=(0,m.useState)([]),[f,I]=(0,m.useState)([]),[y,D]=(0,m.useState)(we),[N,O]=(0,m.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[d,r]=(0,m.useState)(null),[R,_]=(0,m.useState)(!0),[v,U]=(0,m.useState)(!1),[A,J]=(0,m.useState)(!1),[V,Y]=(0,m.useState)(0),[q,P]=(0,m.useState)(""),[X,Z]=(0,m.useState)(!1),T=(0,m.useMemo)(()=>new Map(w.map(c=>[c.id,c.name])),[w]),u=(0,m.useMemo)(()=>f.find(c=>c.triggerId===d)??f[0]??null,[f,d]),ee=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...w.map(c=>({value:c.id,label:c.name}))],[w,e]),B=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),be=(0,m.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]),$=(0,m.useCallback)(async(c=!1,k=!1)=>{k?U(!0):_(!0),P("");let z=c?g.current.length:0,oe=He(N,z),b=new URLSearchParams(oe);b.delete("limit"),b.delete("offset");try{let[F,te]=await Promise.all([H(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):H(`/api/trigger-logs/summary?${b}`)]);if(!s.current)return;if(F.status!==200)throw new Error(String(F.body?.error||F.status));let S=Array.isArray(F.body?.logs)?F.body.logs:[],ne=c?[...g.current,...S]:S;g.current=ne,I(ne),Y(Number(F.body?.total??S.length)),J(F.body?.hasMore===!0),c||(D(te?.status===200?te.body?.summary??we:we),r(ae=>S.some(ye=>ye.triggerId===ae)?ae:S[0]?.triggerId??null))}catch(F){s.current&&P(F?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(_(!1),U(!1))}},[N,e]);(0,m.useEffect)(()=>(s.current=!0,H("/api/connectors").then(c=>{s.current&&c.status===200&&L(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,m.useEffect)(()=>{let c=setTimeout(()=>{$(!1)},N.query?260:0);return()=>clearTimeout(c)},[N,$]),(0,m.useEffect)(()=>{let c=setInterval(()=>{$(!1,!0)},15e3);return()=>clearInterval(c)},[$]);async function he(){!u||!await de(JSON.stringify(u,null,2),e("webhookLogs.copyJson"))||(Z(!0),setTimeout(()=>s.current&&Z(!1),1200))}let fe=u?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):u?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),j=(0,n.jsxs)(n.Fragment,{children:[t.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)(ge,{label:e("webhookLogs.total"),value:y.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(ge,{label:e("webhookLogs.successRate"),value:`${y.successRate.toFixed(y.successRate%1?1:0)}%`,tone:"ok",hint:`${y.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(ge,{label:e("webhookLogs.failures"),value:y.error,tone:y.error?"error":void 0,hint:y.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(ge,{label:e("webhookLogs.p95"),value:ue(y.p95DurationMs),hint:`${e("webhookLogs.average")} ${ue(y.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:N.query,onChange:c=>{let k=c.currentTarget.value;O(z=>({...z,query:k}))}}),(0,n.jsx)(Ce,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:N.connectorId,options:ee,onChange:c=>O(k=>({...k,connectorId:c}))}),(0,n.jsx)(Ce,{id:"webhook-log-status",label:e("webhookLogs.status"),value:N.status,options:B,onChange:c=>O(k=>({...k,status:c}))}),(0,n.jsx)(Ce,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:N.timeWindow,options:be,onChange:c=>O(k=>({...k,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:v,onClick:()=>{$(!1,!0)},children:e("webhookLogs.refresh")})]}),q?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",q]}):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:V})})]})}),R&&!f.length?(0,n.jsx)(le,{label:e("webhookLogs.loading"),compact:!0}):null,!R&&!f.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:f.map(c=>{let k=u?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":k,className:`webhook-log-row${k?" 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:T.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:Te(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:ue(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),A?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:R,onClick:()=>{$(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:u?(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 ${u.status}`,children:u.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:T.get(u.connectorId||"")||u.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Te(u.createdAt)," \xB7 ",u.request?.method||"POST"," ",u.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{he()},children:e(X?"webhookLogs.copied":"webhookLogs.copyJson")})]}),u.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:u.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:u.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:u.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:ue(u.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:u.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:Ae(u.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.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:u.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:u.target?.chatId||u.target?.sessionId||u.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(ve,{value:u.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)(ve,{value:u.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")})]}),u.request?.payloadStored?(0,n.jsx)(ve,{value:u.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:fe})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(qe,{value:u.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return t.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:j}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:j})}var o=K(re(),1);function Be(t,e){return t.map(s=>s.id===e.id?e:s)}var Pe={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",suppressFinalOutput:!1,verify:"token",secret:"",storePayload:!0};function ao(t,e){return{promptEnvelope:{sourceName:t.promptEnvelope?.sourceName||t.name,instruction:e}}}function Ge(t){return[{value:"turn",label:t("connectors.kindTurn")},{value:"workflow",label:t("connectors.kindWorkflowRetiring"),disabled:!0}]}function Ne(t){return`${location.origin}/webhook/${encodeURIComponent(t)}`}function me(t){return(0,o.jsx)(ie,{id:t.id,className:"connector-form-menu",ariaLabel:t.label,value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function xe(t){let e=(0,i.useRef)(null),[s,g]=(0,i.useState)(!1),[w,L]=(0,i.useState)(""),f=Array.isArray(t.value)?t.value:t.value?[t.value]:[],I=(0,i.useMemo)(()=>new Set(f),[f]),y=w.trim().toLocaleLowerCase(),D=(0,i.useMemo)(()=>y?t.groups.filter(d=>`${d.name} ${d.chatId}`.toLocaleLowerCase().includes(y)):t.groups,[y,t.groups]),N=t.multiple?f.length===0?t.allLabel||t.placeholder:t.selectedCountLabel(f.length):t.groups.find(d=>d.chatId===f[0])?.name||f[0]||t.placeholder;(0,i.useEffect)(()=>{if(!s)return;let d=r=>{e.current?.contains(r.target)||g(!1)};return document.addEventListener("pointerdown",d),()=>document.removeEventListener("pointerdown",d)},[s]);function O(d){if(!t.multiple){t.onChange(d),g(!1),L("");return}t.onChange(I.has(d)?f.filter(r=>r!==d):[...f,d])}return(0,o.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,o.jsxs)("button",{id:t.id,type:"button",className:"connector-group-picker-trigger","aria-label":t.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>g(d=>!d),children:[(0,o.jsx)("span",{className:f.length||t.multiple&&t.allLabel?"":"muted",children:N}),(0,o.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,o.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,o.jsxs)("label",{className:"connector-group-search",htmlFor:`${t.id}-search`,children:[(0,o.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,o.jsx)("input",{id:`${t.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:w,placeholder:t.searchPlaceholder,onChange:d=>L(d.currentTarget.value),onKeyDown:d=>{d.key==="Escape"&&(d.preventDefault(),g(!1))}})]}),(0,o.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":t.label,"aria-multiselectable":t.multiple||void 0,children:[t.multiple&&t.allLabel&&!y?(0,o.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${f.length===0?" selected":""}`,role:"option","aria-selected":f.length===0,onClick:()=>t.onChange([]),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:t.allLabel}),(0,o.jsx)("small",{children:t.placeholder})]})]}):null,D.map(d=>{let r=I.has(d.chatId);return(0,o.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>O(d.chatId),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:d.name||d.chatId}),d.name?(0,o.jsx)("small",{children:d.chatId}):null]})]},d.chatId)}),D.length?null:(0,o.jsx)("p",{className:"connector-group-empty",children:t.emptyLabel})]})]}):null]})}function pe(t,e){return t.filter(s=>s.bots.includes(e))}function We(t,e){let s=t.target.chatId||"",g=s&&pe(e,t.target.botId).some(w=>w.chatId===s);return{name:t.name,botId:t.target.botId,kind:t.target.kind,workflowId:t.target.workflowId||"",mode:t.target.mode,chatId:g?s:"",manualChat:!!(s&&!g),manualChatId:g?"":s,allowChats:t.target.allowChats||[],deduplicate:!!t.lifecycleExtractors?.dedupKey,dedup:t.lifecycleExtractors?.dedupKey||"",instruction:t.promptEnvelope?.instruction||"",topicMessageMode:t.topicMessage?.mode||"default",topicMessageText:t.topicMessage?.text||"",suppressFinalOutput:t.suppressFinalOutput===!0,verify:t.verify?.type||"token",secret:"",storePayload:t.loggingPolicy?.storePayload!==!1}}function _e(t){let e=W(),s=t.active==="webhooks",g=t.active==="logs";return(0,o.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,o.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,o.jsx)("a",{href:"#/connectors/logs",className:`itab${g?" on":""}`,role:"tab","aria-selected":g,children:e("connectors.tabLogs")})]})}function Se(t){let e=W(),s=(0,i.useRef)(!1),g=(0,i.useRef)(null),w=(0,i.useRef)(null),[L,f]=(0,i.useState)([]),[I,y]=(0,i.useState)([]),[D,N]=(0,i.useState)([]),[O,d]=(0,i.useState)(!0),[r,R]=(0,i.useState)(Pe),[_,v]=(0,i.useState)(null),[U,A]=(0,i.useState)(null),[J,V]=(0,i.useState)(!1),[Y,q]=(0,i.useState)(!1),[P,X]=(0,i.useState)(null),[Z,T]=(0,i.useState)(null),[u,ee]=(0,i.useState)(null),B=(0,i.useMemo)(()=>pe(I,r.botId),[I,r.botId]),be=(0,i.useMemo)(()=>L.length?L.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[L,e]),$=(0,i.useMemo)(()=>Ge(e),[e]),he=(0,i.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),fe=(0,i.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),j=(0,i.useCallback)(a=>I.find(p=>p.chatId===a)?.name||a,[I]),c=(0,i.useCallback)((a,l)=>{R(p=>{let C=p.botId&&a.some(E=>E.larkAppId===p.botId)?p.botId:a[0]?.larkAppId??"",h=pe(l,C),x=p.chatId&&h.some(E=>E.chatId===p.chatId)?p.chatId:h[0]?.chatId??"",G=new Set(h.map(E=>E.chatId));return{...p,botId:C,chatId:x,allowChats:p.allowChats.filter(E=>G.has(E))}})},[]),k=(0,i.useCallback)(async()=>{d(!0);try{let[a,l,p]=await Promise.all([H("/api/bots"),H("/api/connectors"),H("/api/groups")]);if(!s.current)return;let C=(a.body?.bots||[]).map(x=>({larkAppId:x.larkAppId,botName:x.botName||x.larkAppId})),h=(p.body?.chats||[]).map(x=>({chatId:x.chatId,name:x.name||"",bots:(x.memberBots||[]).filter(G=>G.inChat).map(G=>G.larkAppId)}));f(C),y(h),N(Array.isArray(l.body?.connectors)?l.body.connectors:[]),c(C,h)}finally{s.current&&d(!1)}},[c]);(0,i.useEffect)(()=>(s.current=!0,k(),()=>{s.current=!1,g.current&&clearTimeout(g.current)}),[k]),(0,i.useEffect)(()=>{let a=new Set(B.map(l=>l.chatId));R(l=>({...l,chatId:l.chatId&&a.has(l.chatId)?l.chatId:B[0]?.chatId??"",allowChats:l.allowChats.filter(p=>a.has(p))}))},[B]),(0,i.useEffect)(()=>{let a=w.current;if(a)if(Y){if(!a.open)try{a.showModal()}catch{}let l=a.querySelector(".connector-modal-body");l&&(l.scrollTop=0)}else a.open&&a.close()},[Y]),(0,i.useEffect)(()=>()=>{let a=w.current;a?.open&&a.close()},[]);function z(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 b(a){R(l=>({...l,...a}))}function F(){v(null),A(null),X(null),R(a=>{let l=a.botId||L[0]?.larkAppId||"";return{...Pe,botId:l,chatId:pe(I,l)[0]?.chatId||""}}),q(!0)}function te(a){v(null),A(null),T(null),X(a),R(We(a,I)),q(!0)}function S(){J||(q(!1),v(null),A(null),X(null))}async function ne(){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 p=r.topicMessageText.trim();if(r.topicMessageMode==="custom"&&!p){v({text:e("connectors.errTopicMessage"),error:!0});return}let C={name:a,enabled:P?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:l},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:{mode:r.topicMessageMode,...r.topicMessageMode==="custom"?{text:p}:{}},suppressFinalOutput:r.suppressFinalOutput,verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let h=r.manualChat?r.manualChatId.trim():r.chatId;if(!h){v({text:e("connectors.errChat"),error:!0});return}C.target.chatId=h}else r.mode==="dynamic"&&(C.target.allowChats=r.allowChats);if(r.mode==="new-group"){let h=r.dedup.trim();if(r.deduplicate&&!h){v({text:e("connectors.errDedup"),error:!0});return}C.lifecycleExtractors=r.deduplicate?{dedupKey:h}:null}else C.lifecycleExtractors=null;r.secret.trim()&&(C.secret=r.secret.trim()),V(!0),v({text:e(P?"connectors.saving":"connectors.creating")});try{let h=await Q(P?"PUT":"POST",P?`/api/connectors/${encodeURIComponent(P.id)}`:"/api/connectors",C);if(!s.current)return;if((h.status===201||h.status===200)&&h.body?.ok){if(P){let ke=P.id;N(De=>Be(De,h.body.connector)),T({id:ke,text:e("connectors.updated")}),q(!1),X(null);return}let x=h.body.webhookUrl||Ne(h.body.connector.id),G=(h.body.connector?.verify?.type??"token")==="token",E=r.mode==="dynamic",Ee=E?C.target.allowChats?.[0]||"<chatId>":"";v(null),A({name:a,mode:r.mode,chatId:C.target.chatId,url:x,secret:h.body.secret,isToken:G,isDynamic:E,exampleChat:Ee}),R(ke=>({...ke,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",suppressFinalOutput:!1,allowChats:[],storePayload:!0})),await k()}else{let x=h.body?.error||h.status;v({text:e("connectors.createFailed",{error:String(x)}),error:!0})}}finally{s.current&&V(!1)}}async function ae(a){T({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let l=await Q("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(l.status===200&&l.body?.ok)T(null),await k();else{let p=l.body?.error||l.status;T({id:a.id,text:e("connectors.toggleFailed",{error:String(p)}),error:!0})}}async function ye(a){let l=a.loggingPolicy?.storePayload!==!1;T({id:a.id,text:e("connectors.saving")});let p=await Q("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!l,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(p.status===200&&p.body?.ok)T(null),await k();else{let C=p.body?.error||p.status;T({id:a.id,text:e("connectors.saveFailed",{error:String(C)}),error:!0})}}async function Fe(a){if(!confirm(e("connectors.delConfirm")))return;T({id:a.id,text:e("connectors.deleting")});let l=await Q("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(l.status===200&&l.body?.ok)T(null),await k();else{let p=l.body?.error||l.status;T({id:a.id,text:e("connectors.deleteFailed",{error:String(p)}),error:!0})}}function Re(a){de(Ne(a.id),e("connectors.copy")).then(l=>{!l||!s.current||(ee(a.id),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{s.current&&ee(null)},1200))})}return(0,o.jsxs)("section",{className:"page connectors-page",children:[(0,o.jsxs)("div",{className:"page-heading",children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,o.jsx)("h1",{children:e("nav.connectors")})]}),(0,o.jsx)("div",{className:"page-heading-actions",children:t.tab==="webhooks"?(0,o.jsx)(Ie,{className:"page-primary-action connector-create-trigger",onClick:F,children:e("connectors.createTitle")}):(0,o.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,o.jsx)(_e,{active:t.tab}),t.tab==="webhooks"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("dialog",{ref:w,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),S()},onClose:S,onClick:a=>{a.target===a.currentTarget&&S()},children:(0,o.jsxs)("article",{className:"connector-modal-card",children:[(0,o.jsxs)("header",{className:"connector-modal-header",children:[(0,o.jsx)("h3",{children:e(P?"connectors.editTitle":"connectors.createTitle")}),(0,o.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:J,onClick:S,children:(0,o.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,o.jsx)("div",{className:"connector-modal-body",children:U?(0,o.jsx)(Ue,{created:U,groupName:j}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"cn-form",children:[(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,o.jsx)(M,{children:e("connectors.fName")}),(0,o.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>b({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fBot")}),(0,o.jsx)(me,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:be,onChange:a=>b({botId:a})})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fKind")}),(0,o.jsx)(me,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:$,onChange:a=>b({kind:a})})]}),r.kind==="workflow"?(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,o.jsx)(M,{children:e("connectors.fWf")}),(0,o.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>b({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fMode")}),(0,o.jsx)(me,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:he,onChange:a=>b({mode:a})})]}),r.mode==="fixed"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsx)(M,{children:e("connectors.fFixedChat")}),(0,o.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,o.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>b({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,o.jsx)(xe,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:B,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>b({chatId:a})}),(0,o.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>b({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsxs)(M,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)(xe,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:B,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=>b({allowChats:a})})]}):null,r.mode==="dynamic"?(0,o.jsx)("div",{className:"cn-field-wide",children:(0,o.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,o.jsx)(M,{children:e("connectors.newGroupStrategy")}),(0,o.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>b({deduplicate:!1}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,o.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>b({deduplicate:!0}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,o.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,o.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,o.jsx)(M,{help:(0,o.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,o.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>b({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,o.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,o.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,o.jsxs)(M,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>b({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,o.jsx)(M,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,o.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","none"].map(a=>(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>b({topicMessageMode:a}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e(`connectors.topicMessage${a==="default"?"Default":a==="custom"?"Custom":"None"}`)}),(0,o.jsx)("small",{children:e(`connectors.topicMessage${a==="default"?"DefaultHint":a==="custom"?"CustomHint":"NoneHint"}`)})]})]},a))}),r.topicMessageMode==="custom"?(0,o.jsxs)("label",{className:"connector-topic-message-input",htmlFor:"cn-topic-message",children:[(0,o.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>b({topicMessageText:a.currentTarget.value}),placeholder:e("connectors.topicMessageCustomPh")}),(0,o.jsxs)("small",{children:[e("connectors.topicMessageCustomHelp"),(0,o.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]})]}):(0,o.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,o.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,o.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>b({storePayload:a.currentTarget.checked})}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:e("connectors.storePayload")}),(0,o.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,o.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-suppress-final",children:[(0,o.jsx)("input",{id:"cn-suppress-final",type:"checkbox",checked:r.suppressFinalOutput,onChange:a=>b({suppressFinalOutput:a.currentTarget.checked})}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:e("connectors.suppressFinalOutput")}),(0,o.jsx)("small",{children:e("connectors.suppressFinalOutputHint")})]})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fVerify")}),(0,o.jsx)(me,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:fe,onChange:a=>b({verify:a})})]}),(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,o.jsx)(M,{children:e("connectors.fSecret")}),(0,o.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>b({secret:a.currentTarget.value}),placeholder:e(P?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),_?(0,o.jsx)("p",{className:`connector-create-message${_.error?" err":""}`,children:_.text}):null]})}),(0,o.jsxs)("footer",{className:"connector-modal-actions",children:[(0,o.jsx)("button",{type:"button",disabled:J,onClick:S,children:e("connectors.cancel")}),U?(0,o.jsx)("button",{type:"button",className:"primary",onClick:S,children:e("connectors.close")}):(0,o.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:J,onClick:()=>{ne()},children:e(P?"connectors.btnSave":"connectors.btnCreate")})]})]})}),(0,o.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,o.jsx)("div",{className:"card connector-list-card",children:O?(0,o.jsx)(le,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,o.jsx)(Je,{connectors:D,bots:L,copiedId:u,editMsg:Z,groupName:j,modeLabel:z,kindLabel:oe,onCopy:Re,onEdit:te,onToggle:a=>{ae(a)},onTogglePayloadLogging:a=>{ye(a)},onDelete:a=>{Fe(a)}})})})]}):(0,o.jsx)(Me,{embedded:!0})]})}function Ue(t){let e=W(),s=t.created,g=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,w=s.exampleChat!=="<chatId>"?`\uFF08${t.groupName(s.exampleChat)}\uFF09`:"";return(0,o.jsx)("div",{className:"connector-created-wrap",children:(0,o.jsxs)("div",{className:"card connector-created-card",children:[(0,o.jsxs)("p",{className:"connector-created-title ok",children:[e("connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,o.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:t.groupName(s.chatId)})]}):null]}),(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsx)("code",{children:s.url})]}),s.secret?(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,o.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:w})}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Je(t){let e=W();return t.connectors.length?(0,o.jsx)(o.Fragment,{children:t.connectors.map(s=>{let g=t.bots.find(N=>N.larkAppId===s.target.botId),w=Ne(s.id),L=(s.verify?.type??"token")==="token",f=e(L?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:t.groupName(s.target.chatId)}):"",y=t.editMsg?.id===s.id?t.editMsg:null,D=t.copiedId===s.id;return(0,o.jsxs)("div",{className:"card connector-item-card",children:[(0,o.jsxs)("div",{className:"connector-item-head",children:[(0,o.jsxs)("div",{className:"connector-item-main",children:[(0,o.jsxs)("div",{className:"connector-item-title",children:[(0,o.jsx)("b",{children:s.name}),(0,o.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,o.jsxs)("div",{className:"connector-item-meta",children:[(0,o.jsx)("span",{children:g?.botName||s.target.botId}),(0,o.jsx)("span",{children:t.kindLabel(s.target.kind)}),(0,o.jsx)("span",{children:t.modeLabel(s.target.mode)}),I?(0,o.jsx)("span",{children:I}):null,(0,o.jsx)("span",{children:f}),(0,o.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,o.jsx)("button",{className:`ghost connector-copy-button${D?" copied":""}`,type:"button",onClick:()=>t.onCopy(s),children:e(D?"connectors.copied":"connectors.copy")})]}),(0,o.jsxs)("div",{className:"connector-url-row",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsxs)("code",{children:[w,L?"/<token>":""]})]}),L?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,o.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,o.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,o.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),y?(0,o.jsx)("div",{className:y.error?"err connector-item-note":"muted connector-item-note",children:y.text}):null,(0,o.jsxs)("div",{className:"connector-item-actions",children:[(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onEdit(s),children:e("connectors.btnEdit")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,o.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function so(t){return se(t,(0,o.jsx)(Se,{tab:"webhooks"}))}function ro(t){return se(t,(0,o.jsx)(Se,{tab:"logs"}))}export{ao as buildConnectorInstructionUpdateBody,Ge as buildConnectorKindOptions,ro as renderConnectorsLogsPage,so as renderConnectorsPage,Be as replaceConnectorById};
1
+ import{a as H,b as Q}from"./chunk-EVK77ASG.js";import{a as de}from"./chunk-ZJVTGU5X.js";import{c as W}from"./chunk-ZU3UUKAR.js";import{a as ce,c as le,g as Ie,l as M,q as ie}from"./chunk-5CJMHTT4.js";import"./chunk-MFQPCVHY.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Le,d as re}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var i=K(Le(),1);var m=K(Le(),1);var n=K(re(),1),Oe=50,we={total:0,ok:0,error:0,successRate:0};function $e(t,e=Date.now()){if(t==="all")return;let s=t==="24h"?24:t==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function He(t,e=0){let s=new URLSearchParams({limit:String(Oe),offset:String(e)});t.connectorId&&s.set("connectorId",t.connectorId),t.status&&s.set("status",t.status);let g=$e(t.timeWindow);return g&&s.set("since",g),t.query.trim()&&s.set("q",t.query.trim()),s}function Te(t){if(!t)return"\u2014";let e=new Date(t);return Number.isFinite(e.getTime())?e.toLocaleString():t}function ue(t){return t===void 0||!Number.isFinite(t)?"\u2014":t<1e3?`${Math.round(t)} ms`:t<6e4?`${(t/1e3).toFixed(t<1e4?1:0)} s`:`${(t/6e4).toFixed(1)} min`}function Ae(t){return t===void 0?"\u2014":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ve(t){return t.value===void 0||t.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):typeof t.value=="object"&&!Array.isArray(t.value)&&Object.keys(t.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${t.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(t.value,null,2)})})}function qe(t){let e=[["kind",t.value?.kind],["mode",t.value?.mode],["botId",t.value?.botId],["chatId",t.value?.chatId],["sessionId",t.value?.sessionId],["rootMessageId",t.value?.rootMessageId],["workflowId",t.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,g])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(g)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function Ce(t){return(0,n.jsx)(ie,{id:t.id,className:"webhook-log-filter-menu",ariaLabel:t.label,style:{width:"100%",minWidth:0},value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function ge(t){return(0,n.jsxs)("article",{className:`card webhook-log-metric${t.tone?` ${t.tone}`:""}`,children:[(0,n.jsx)("span",{children:t.label}),(0,n.jsx)("strong",{children:t.value}),(0,n.jsx)("small",{children:t.hint||"\xA0"})]})}function Me(t={}){let e=W(),s=(0,m.useRef)(!1),g=(0,m.useRef)([]),[w,L]=(0,m.useState)([]),[f,I]=(0,m.useState)([]),[y,D]=(0,m.useState)(we),[N,O]=(0,m.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[d,r]=(0,m.useState)(null),[R,_]=(0,m.useState)(!0),[v,U]=(0,m.useState)(!1),[A,J]=(0,m.useState)(!1),[V,Y]=(0,m.useState)(0),[q,P]=(0,m.useState)(""),[X,Z]=(0,m.useState)(!1),T=(0,m.useMemo)(()=>new Map(w.map(c=>[c.id,c.name])),[w]),u=(0,m.useMemo)(()=>f.find(c=>c.triggerId===d)??f[0]??null,[f,d]),ee=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...w.map(c=>({value:c.id,label:c.name}))],[w,e]),B=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),be=(0,m.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]),$=(0,m.useCallback)(async(c=!1,k=!1)=>{k?U(!0):_(!0),P("");let z=c?g.current.length:0,oe=He(N,z),b=new URLSearchParams(oe);b.delete("limit"),b.delete("offset");try{let[F,te]=await Promise.all([H(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):H(`/api/trigger-logs/summary?${b}`)]);if(!s.current)return;if(F.status!==200)throw new Error(String(F.body?.error||F.status));let S=Array.isArray(F.body?.logs)?F.body.logs:[],ne=c?[...g.current,...S]:S;g.current=ne,I(ne),Y(Number(F.body?.total??S.length)),J(F.body?.hasMore===!0),c||(D(te?.status===200?te.body?.summary??we:we),r(ae=>S.some(ye=>ye.triggerId===ae)?ae:S[0]?.triggerId??null))}catch(F){s.current&&P(F?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(_(!1),U(!1))}},[N,e]);(0,m.useEffect)(()=>(s.current=!0,H("/api/connectors").then(c=>{s.current&&c.status===200&&L(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,m.useEffect)(()=>{let c=setTimeout(()=>{$(!1)},N.query?260:0);return()=>clearTimeout(c)},[N,$]),(0,m.useEffect)(()=>{let c=setInterval(()=>{$(!1,!0)},15e3);return()=>clearInterval(c)},[$]);async function he(){!u||!await de(JSON.stringify(u,null,2),e("webhookLogs.copyJson"))||(Z(!0),setTimeout(()=>s.current&&Z(!1),1200))}let fe=u?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):u?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),j=(0,n.jsxs)(n.Fragment,{children:[t.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)(ge,{label:e("webhookLogs.total"),value:y.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(ge,{label:e("webhookLogs.successRate"),value:`${y.successRate.toFixed(y.successRate%1?1:0)}%`,tone:"ok",hint:`${y.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(ge,{label:e("webhookLogs.failures"),value:y.error,tone:y.error?"error":void 0,hint:y.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(ge,{label:e("webhookLogs.p95"),value:ue(y.p95DurationMs),hint:`${e("webhookLogs.average")} ${ue(y.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:N.query,onChange:c=>{let k=c.currentTarget.value;O(z=>({...z,query:k}))}}),(0,n.jsx)(Ce,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:N.connectorId,options:ee,onChange:c=>O(k=>({...k,connectorId:c}))}),(0,n.jsx)(Ce,{id:"webhook-log-status",label:e("webhookLogs.status"),value:N.status,options:B,onChange:c=>O(k=>({...k,status:c}))}),(0,n.jsx)(Ce,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:N.timeWindow,options:be,onChange:c=>O(k=>({...k,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:v,onClick:()=>{$(!1,!0)},children:e("webhookLogs.refresh")})]}),q?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",q]}):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:V})})]})}),R&&!f.length?(0,n.jsx)(le,{label:e("webhookLogs.loading"),compact:!0}):null,!R&&!f.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:f.map(c=>{let k=u?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":k,className:`webhook-log-row${k?" 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:T.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:Te(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:ue(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),A?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:R,onClick:()=>{$(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:u?(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 ${u.status}`,children:u.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:T.get(u.connectorId||"")||u.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Te(u.createdAt)," \xB7 ",u.request?.method||"POST"," ",u.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{he()},children:e(X?"webhookLogs.copied":"webhookLogs.copyJson")})]}),u.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:u.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:u.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:u.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:ue(u.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:u.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:Ae(u.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.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:u.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:u.target?.chatId||u.target?.sessionId||u.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(ve,{value:u.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)(ve,{value:u.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")})]}),u.request?.payloadStored?(0,n.jsx)(ve,{value:u.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:fe})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(qe,{value:u.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return t.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:j}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:j})}var o=K(re(),1);function Be(t,e){return t.map(s=>s.id===e.id?e:s)}var Pe={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",suppressFinalOutput:!1,verify:"token",secret:"",storePayload:!0};function ao(t,e){return{promptEnvelope:{sourceName:t.promptEnvelope?.sourceName||t.name,instruction:e}}}function Ge(t){return[{value:"turn",label:t("connectors.kindTurn")},{value:"workflow",label:t("connectors.kindWorkflowRetiring"),disabled:!0}]}function Ne(t){return`${location.origin}/webhook/${encodeURIComponent(t)}`}function me(t){return(0,o.jsx)(ie,{id:t.id,className:"connector-form-menu",ariaLabel:t.label,value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function xe(t){let e=(0,i.useRef)(null),[s,g]=(0,i.useState)(!1),[w,L]=(0,i.useState)(""),f=Array.isArray(t.value)?t.value:t.value?[t.value]:[],I=(0,i.useMemo)(()=>new Set(f),[f]),y=w.trim().toLocaleLowerCase(),D=(0,i.useMemo)(()=>y?t.groups.filter(d=>`${d.name} ${d.chatId}`.toLocaleLowerCase().includes(y)):t.groups,[y,t.groups]),N=t.multiple?f.length===0?t.allLabel||t.placeholder:t.selectedCountLabel(f.length):t.groups.find(d=>d.chatId===f[0])?.name||f[0]||t.placeholder;(0,i.useEffect)(()=>{if(!s)return;let d=r=>{e.current?.contains(r.target)||g(!1)};return document.addEventListener("pointerdown",d),()=>document.removeEventListener("pointerdown",d)},[s]);function O(d){if(!t.multiple){t.onChange(d),g(!1),L("");return}t.onChange(I.has(d)?f.filter(r=>r!==d):[...f,d])}return(0,o.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,o.jsxs)("button",{id:t.id,type:"button",className:"connector-group-picker-trigger","aria-label":t.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>g(d=>!d),children:[(0,o.jsx)("span",{className:f.length||t.multiple&&t.allLabel?"":"muted",children:N}),(0,o.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,o.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,o.jsxs)("label",{className:"connector-group-search",htmlFor:`${t.id}-search`,children:[(0,o.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,o.jsx)("input",{id:`${t.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:w,placeholder:t.searchPlaceholder,onChange:d=>L(d.currentTarget.value),onKeyDown:d=>{d.key==="Escape"&&(d.preventDefault(),g(!1))}})]}),(0,o.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":t.label,"aria-multiselectable":t.multiple||void 0,children:[t.multiple&&t.allLabel&&!y?(0,o.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${f.length===0?" selected":""}`,role:"option","aria-selected":f.length===0,onClick:()=>t.onChange([]),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:t.allLabel}),(0,o.jsx)("small",{children:t.placeholder})]})]}):null,D.map(d=>{let r=I.has(d.chatId);return(0,o.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>O(d.chatId),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:d.name||d.chatId}),d.name?(0,o.jsx)("small",{children:d.chatId}):null]})]},d.chatId)}),D.length?null:(0,o.jsx)("p",{className:"connector-group-empty",children:t.emptyLabel})]})]}):null]})}function pe(t,e){return t.filter(s=>s.bots.includes(e))}function We(t,e){let s=t.target.chatId||"",g=s&&pe(e,t.target.botId).some(w=>w.chatId===s);return{name:t.name,botId:t.target.botId,kind:t.target.kind,workflowId:t.target.workflowId||"",mode:t.target.mode,chatId:g?s:"",manualChat:!!(s&&!g),manualChatId:g?"":s,allowChats:t.target.allowChats||[],deduplicate:!!t.lifecycleExtractors?.dedupKey,dedup:t.lifecycleExtractors?.dedupKey||"",instruction:t.promptEnvelope?.instruction||"",topicMessageMode:t.topicMessage?.mode||"default",topicMessageText:t.topicMessage?.text||"",suppressFinalOutput:t.suppressFinalOutput===!0,verify:t.verify?.type||"token",secret:"",storePayload:t.loggingPolicy?.storePayload!==!1}}function _e(t){let e=W(),s=t.active==="webhooks",g=t.active==="logs";return(0,o.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,o.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,o.jsx)("a",{href:"#/connectors/logs",className:`itab${g?" on":""}`,role:"tab","aria-selected":g,children:e("connectors.tabLogs")})]})}function Se(t){let e=W(),s=(0,i.useRef)(!1),g=(0,i.useRef)(null),w=(0,i.useRef)(null),[L,f]=(0,i.useState)([]),[I,y]=(0,i.useState)([]),[D,N]=(0,i.useState)([]),[O,d]=(0,i.useState)(!0),[r,R]=(0,i.useState)(Pe),[_,v]=(0,i.useState)(null),[U,A]=(0,i.useState)(null),[J,V]=(0,i.useState)(!1),[Y,q]=(0,i.useState)(!1),[P,X]=(0,i.useState)(null),[Z,T]=(0,i.useState)(null),[u,ee]=(0,i.useState)(null),B=(0,i.useMemo)(()=>pe(I,r.botId),[I,r.botId]),be=(0,i.useMemo)(()=>L.length?L.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[L,e]),$=(0,i.useMemo)(()=>Ge(e),[e]),he=(0,i.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),fe=(0,i.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),j=(0,i.useCallback)(a=>I.find(p=>p.chatId===a)?.name||a,[I]),c=(0,i.useCallback)((a,l)=>{R(p=>{let C=p.botId&&a.some(E=>E.larkAppId===p.botId)?p.botId:a[0]?.larkAppId??"",h=pe(l,C),x=p.chatId&&h.some(E=>E.chatId===p.chatId)?p.chatId:h[0]?.chatId??"",G=new Set(h.map(E=>E.chatId));return{...p,botId:C,chatId:x,allowChats:p.allowChats.filter(E=>G.has(E))}})},[]),k=(0,i.useCallback)(async()=>{d(!0);try{let[a,l,p]=await Promise.all([H("/api/bots"),H("/api/connectors"),H("/api/groups")]);if(!s.current)return;let C=(a.body?.bots||[]).map(x=>({larkAppId:x.larkAppId,botName:x.botName||x.larkAppId})),h=(p.body?.chats||[]).map(x=>({chatId:x.chatId,name:x.name||"",bots:(x.memberBots||[]).filter(G=>G.inChat).map(G=>G.larkAppId)}));f(C),y(h),N(Array.isArray(l.body?.connectors)?l.body.connectors:[]),c(C,h)}finally{s.current&&d(!1)}},[c]);(0,i.useEffect)(()=>(s.current=!0,k(),()=>{s.current=!1,g.current&&clearTimeout(g.current)}),[k]),(0,i.useEffect)(()=>{let a=new Set(B.map(l=>l.chatId));R(l=>({...l,chatId:l.chatId&&a.has(l.chatId)?l.chatId:B[0]?.chatId??"",allowChats:l.allowChats.filter(p=>a.has(p))}))},[B]),(0,i.useEffect)(()=>{let a=w.current;if(a)if(Y){if(!a.open)try{a.showModal()}catch{}let l=a.querySelector(".connector-modal-body");l&&(l.scrollTop=0)}else a.open&&a.close()},[Y]),(0,i.useEffect)(()=>()=>{let a=w.current;a?.open&&a.close()},[]);function z(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 b(a){R(l=>({...l,...a}))}function F(){v(null),A(null),X(null),R(a=>{let l=a.botId||L[0]?.larkAppId||"";return{...Pe,botId:l,chatId:pe(I,l)[0]?.chatId||""}}),q(!0)}function te(a){v(null),A(null),T(null),X(a),R(We(a,I)),q(!0)}function S(){J||(q(!1),v(null),A(null),X(null))}async function ne(){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 p=r.topicMessageText.trim();if(r.topicMessageMode==="custom"&&!p){v({text:e("connectors.errTopicMessage"),error:!0});return}let C={name:a,enabled:P?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:l},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:{mode:r.topicMessageMode,...r.topicMessageMode==="custom"?{text:p}:{}},suppressFinalOutput:r.suppressFinalOutput,verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let h=r.manualChat?r.manualChatId.trim():r.chatId;if(!h){v({text:e("connectors.errChat"),error:!0});return}C.target.chatId=h}else r.mode==="dynamic"&&(C.target.allowChats=r.allowChats);if(r.mode==="new-group"){let h=r.dedup.trim();if(r.deduplicate&&!h){v({text:e("connectors.errDedup"),error:!0});return}C.lifecycleExtractors=r.deduplicate?{dedupKey:h}:null}else C.lifecycleExtractors=null;r.secret.trim()&&(C.secret=r.secret.trim()),V(!0),v({text:e(P?"connectors.saving":"connectors.creating")});try{let h=await Q(P?"PUT":"POST",P?`/api/connectors/${encodeURIComponent(P.id)}`:"/api/connectors",C);if(!s.current)return;if((h.status===201||h.status===200)&&h.body?.ok){if(P){let ke=P.id;N(De=>Be(De,h.body.connector)),T({id:ke,text:e("connectors.updated")}),q(!1),X(null);return}let x=h.body.webhookUrl||Ne(h.body.connector.id),G=(h.body.connector?.verify?.type??"token")==="token",E=r.mode==="dynamic",Ee=E?C.target.allowChats?.[0]||"<chatId>":"";v(null),A({name:a,mode:r.mode,chatId:C.target.chatId,url:x,secret:h.body.secret,isToken:G,isDynamic:E,exampleChat:Ee}),R(ke=>({...ke,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",suppressFinalOutput:!1,allowChats:[],storePayload:!0})),await k()}else{let x=h.body?.error||h.status;v({text:e("connectors.createFailed",{error:String(x)}),error:!0})}}finally{s.current&&V(!1)}}async function ae(a){T({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let l=await Q("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(l.status===200&&l.body?.ok)T(null),await k();else{let p=l.body?.error||l.status;T({id:a.id,text:e("connectors.toggleFailed",{error:String(p)}),error:!0})}}async function ye(a){let l=a.loggingPolicy?.storePayload!==!1;T({id:a.id,text:e("connectors.saving")});let p=await Q("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!l,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(p.status===200&&p.body?.ok)T(null),await k();else{let C=p.body?.error||p.status;T({id:a.id,text:e("connectors.saveFailed",{error:String(C)}),error:!0})}}async function Fe(a){if(!confirm(e("connectors.delConfirm")))return;T({id:a.id,text:e("connectors.deleting")});let l=await Q("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(l.status===200&&l.body?.ok)T(null),await k();else{let p=l.body?.error||l.status;T({id:a.id,text:e("connectors.deleteFailed",{error:String(p)}),error:!0})}}function Re(a){de(Ne(a.id),e("connectors.copy")).then(l=>{!l||!s.current||(ee(a.id),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{s.current&&ee(null)},1200))})}return(0,o.jsxs)("section",{className:"page connectors-page",children:[(0,o.jsxs)("div",{className:"page-heading",children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,o.jsx)("h1",{children:e("nav.connectors")})]}),(0,o.jsx)("div",{className:"page-heading-actions",children:t.tab==="webhooks"?(0,o.jsx)(Ie,{className:"page-primary-action connector-create-trigger",onClick:F,children:e("connectors.createTitle")}):(0,o.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,o.jsx)(_e,{active:t.tab}),t.tab==="webhooks"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("dialog",{ref:w,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),S()},onClose:S,onClick:a=>{a.target===a.currentTarget&&S()},children:(0,o.jsxs)("article",{className:"connector-modal-card",children:[(0,o.jsxs)("header",{className:"connector-modal-header",children:[(0,o.jsx)("h3",{children:e(P?"connectors.editTitle":"connectors.createTitle")}),(0,o.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:J,onClick:S,children:(0,o.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,o.jsx)("div",{className:"connector-modal-body",children:U?(0,o.jsx)(Ue,{created:U,groupName:j}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"cn-form",children:[(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,o.jsx)(M,{children:e("connectors.fName")}),(0,o.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>b({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fBot")}),(0,o.jsx)(me,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:be,onChange:a=>b({botId:a})})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fKind")}),(0,o.jsx)(me,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:$,onChange:a=>b({kind:a})})]}),r.kind==="workflow"?(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,o.jsx)(M,{children:e("connectors.fWf")}),(0,o.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>b({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fMode")}),(0,o.jsx)(me,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:he,onChange:a=>b({mode:a})})]}),r.mode==="fixed"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsx)(M,{children:e("connectors.fFixedChat")}),(0,o.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,o.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>b({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,o.jsx)(xe,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:B,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>b({chatId:a})}),(0,o.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>b({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsxs)(M,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)(xe,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:B,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=>b({allowChats:a})})]}):null,r.mode==="dynamic"?(0,o.jsx)("div",{className:"cn-field-wide",children:(0,o.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,o.jsx)(M,{children:e("connectors.newGroupStrategy")}),(0,o.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>b({deduplicate:!1}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,o.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>b({deduplicate:!0}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,o.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,o.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,o.jsx)(M,{help:(0,o.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,o.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>b({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,o.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,o.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,o.jsxs)(M,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>b({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,o.jsx)(M,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,o.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","none"].map(a=>(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>b({topicMessageMode:a}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e(`connectors.topicMessage${a==="default"?"Default":a==="custom"?"Custom":"None"}`)}),(0,o.jsx)("small",{children:e(`connectors.topicMessage${a==="default"?"DefaultHint":a==="custom"?"CustomHint":"NoneHint"}`)})]})]},a))}),r.topicMessageMode==="custom"?(0,o.jsxs)("label",{className:"connector-topic-message-input",htmlFor:"cn-topic-message",children:[(0,o.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>b({topicMessageText:a.currentTarget.value}),placeholder:e("connectors.topicMessageCustomPh")}),(0,o.jsxs)("small",{children:[e("connectors.topicMessageCustomHelp"),(0,o.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]})]}):(0,o.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,o.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,o.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>b({storePayload:a.currentTarget.checked})}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:e("connectors.storePayload")}),(0,o.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,o.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-suppress-final",children:[(0,o.jsx)("input",{id:"cn-suppress-final",type:"checkbox",checked:r.suppressFinalOutput,onChange:a=>b({suppressFinalOutput:a.currentTarget.checked})}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:e("connectors.suppressFinalOutput")}),(0,o.jsx)("small",{children:e("connectors.suppressFinalOutputHint")})]})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fVerify")}),(0,o.jsx)(me,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:fe,onChange:a=>b({verify:a})})]}),(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,o.jsx)(M,{children:e("connectors.fSecret")}),(0,o.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>b({secret:a.currentTarget.value}),placeholder:e(P?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),_?(0,o.jsx)("p",{className:`connector-create-message${_.error?" err":""}`,children:_.text}):null]})}),(0,o.jsxs)("footer",{className:"connector-modal-actions",children:[(0,o.jsx)("button",{type:"button",disabled:J,onClick:S,children:e("connectors.cancel")}),U?(0,o.jsx)("button",{type:"button",className:"primary",onClick:S,children:e("connectors.close")}):(0,o.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:J,onClick:()=>{ne()},children:e(P?"connectors.btnSave":"connectors.btnCreate")})]})]})}),(0,o.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,o.jsx)("div",{className:"card connector-list-card",children:O?(0,o.jsx)(le,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,o.jsx)(Je,{connectors:D,bots:L,copiedId:u,editMsg:Z,groupName:j,modeLabel:z,kindLabel:oe,onCopy:Re,onEdit:te,onToggle:a=>{ae(a)},onTogglePayloadLogging:a=>{ye(a)},onDelete:a=>{Fe(a)}})})})]}):(0,o.jsx)(Me,{embedded:!0})]})}function Ue(t){let e=W(),s=t.created,g=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,w=s.exampleChat!=="<chatId>"?`\uFF08${t.groupName(s.exampleChat)}\uFF09`:"";return(0,o.jsx)("div",{className:"connector-created-wrap",children:(0,o.jsxs)("div",{className:"card connector-created-card",children:[(0,o.jsxs)("p",{className:"connector-created-title ok",children:[e("connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,o.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:t.groupName(s.chatId)})]}):null]}),(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsx)("code",{children:s.url})]}),s.secret?(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,o.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:w})}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Je(t){let e=W();return t.connectors.length?(0,o.jsx)(o.Fragment,{children:t.connectors.map(s=>{let g=t.bots.find(N=>N.larkAppId===s.target.botId),w=Ne(s.id),L=(s.verify?.type??"token")==="token",f=e(L?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:t.groupName(s.target.chatId)}):"",y=t.editMsg?.id===s.id?t.editMsg:null,D=t.copiedId===s.id;return(0,o.jsxs)("div",{className:"card connector-item-card",children:[(0,o.jsxs)("div",{className:"connector-item-head",children:[(0,o.jsxs)("div",{className:"connector-item-main",children:[(0,o.jsxs)("div",{className:"connector-item-title",children:[(0,o.jsx)("b",{children:s.name}),(0,o.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,o.jsxs)("div",{className:"connector-item-meta",children:[(0,o.jsx)("span",{children:g?.botName||s.target.botId}),(0,o.jsx)("span",{children:t.kindLabel(s.target.kind)}),(0,o.jsx)("span",{children:t.modeLabel(s.target.mode)}),I?(0,o.jsx)("span",{children:I}):null,(0,o.jsx)("span",{children:f}),(0,o.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,o.jsx)("button",{className:`ghost connector-copy-button${D?" copied":""}`,type:"button",onClick:()=>t.onCopy(s),children:e(D?"connectors.copied":"connectors.copy")})]}),(0,o.jsxs)("div",{className:"connector-url-row",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsxs)("code",{children:[w,L?"/<token>":""]})]}),L?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,o.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,o.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,o.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),y?(0,o.jsx)("div",{className:y.error?"err connector-item-note":"muted connector-item-note",children:y.text}):null,(0,o.jsxs)("div",{className:"connector-item-actions",children:[(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onEdit(s),children:e("connectors.btnEdit")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,o.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function so(t){return se(t,(0,o.jsx)(Se,{tab:"webhooks"}))}function ro(t){return se(t,(0,o.jsx)(Se,{tab:"logs"}))}export{ao as buildConnectorInstructionUpdateBody,Ge as buildConnectorKindOptions,ro as renderConnectorsLogsPage,so as renderConnectorsPage,Be as replaceConnectorById};
@@ -1,4 +1,4 @@
1
- import{a as he,b as ve,c as be,d as ye}from"./chunk-R3FXBFQH.js";import{a as fe}from"./chunk-ZJVTGU5X.js";import{c as me}from"./chunk-EZH56JCI.js";import{c as Z,g as X,h as le,m as ce,n as ue,o as de,p as pe,q as ge}from"./chunk-5CJMHTT4.js";import{c as j,d as J,u as z,x as ae,z as ne}from"./chunk-E3HZZXK5.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as $e,d as ie}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var i=K($e(),1);var Me=/^[A-Za-z0-9._-]{1,64}$/,ke=6,we=30;function Y(o,t){return be(o,t)}function Pe(o,t,r=we){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):we,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,d=Math.min(c,Math.max(1,s)),f=(d-1)*n,I=Math.min(a,f+n);return{rows:o.slice(f,I),page:d,totalPages:c,from:a===0?0:f+1,to:I,total:a}}async function Ce(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function Q(o){return Me.test(o)&&o!=="."&&o!==".."}function ee(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return Q(t)?t:"profile"}async function V(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Ie(o){let t=await V(),r=await Ce(t,ke,async s=>{try{let f=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(f.entries)?f.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let d of s.memberBots??[]){if(!d?.inChat||!d?.hasRole||!d?.larkAppId)continue;let f=Y(d.larkAppId,s.chatId);n.has(f)||(n.add(f),a.push({chatId:s.chatId,larkAppId:d.larkAppId}))}let c=await ye(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Se(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ce(t,ke,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,d=c?String(s??"").trim():"",f=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:d,status:d?f??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ne(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Re(o,t){let r=t.q.trim().toLowerCase();return o.filter(n=>!r||(n.name??"").toLowerCase().includes(r)||n.chatId.toLowerCase().includes(r)||(n.ownerId??"").toLowerCase().includes(r)).filter(n=>!t.missingOnly||(n.memberBots??[]).some(a=>!a.inChat))}function xe(o,t){if(t.size===0)return!0;let r=o?.memberBots??[];for(let n of t)if(!r.some(a=>a.larkAppId===n&&a.inChat))return!1;return!0}function Ae(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Ge(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:z("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:z("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:z("groups.roleProfileBootstrapDone",{name:n})}}function Be(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(d=>({larkAppId:d.larkAppId,botName:d.botName,inChat:c.has(d.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(d=>d.chatId!==t)]}}var e=K(ie(),1);function Te(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Oe(o){let t={};for(let r of ae(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function De(o){let t=o.chat,r=t.avatar??ne(t.chatId),[n,a]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:Oe(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function te(o){return(0,e.jsxs)("p",{className:"hint-warn",children:[(0,e.jsx)("strong",{children:o.title}),(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:String(o.reason??"unknown")})]})}function Ee(o){return(0,e.jsx)(e.Fragment,{children:Ne(o.bots,o.excludeIds).map(t=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"bot",value:t.larkAppId}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]})]},t.larkAppId))})}function Fe(o){let t=o.summary;return t.rows.length?(0,e.jsxs)("div",{className:t.failed?"hint-warn":"hint-ok",children:[(0,e.jsxs)("strong",{children:["\u6DFB\u52A0\u7ED3\u679C\uFF1A\u6210\u529F ",t.okCount,"/",t.rows.length,t.failed?`\uFF0C\u5931\u8D25 ${t.failed}`:""]}),(0,e.jsx)("ul",{children:t.rows.map((r,n)=>{let a=String(r?.id??"?");return(0,e.jsxs)("li",{children:[(0,e.jsx)("code",{children:a}),": ",r?.ok?"OK":`failed (${String(r?.error??"unknown")})`]},`${a}-${n}`)})})]}):(0,e.jsx)("p",{className:"hint-warn",children:"\u6CA1\u6709\u8FD4\u56DE\u6DFB\u52A0\u7ED3\u679C\u3002"})}function je(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let f of t.memberBots??[])f?.inChat&&a.set(f.larkAppId,r.groupRoleContentByBot.get(Y(f.larkAppId,t.chatId))??null);if(!he(a))return null;let s=ve(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let d=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(d,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function Ue(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function He(o,t){switch(o){case"in":return t("groups.botStatusIn");case"out":return t("groups.botStatusOut");case"error":return t("groups.botStatusError");default:return t("groups.botStatusUnknown")}}function _e(o){let t=new Map((o.chat.memberBots??[]).map(r=>[r.larkAppId,r]));return(0,e.jsx)("div",{className:"groups-bot-strip","aria-label":o.tr("groups.botCoverage"),children:o.bots.map(r=>{let n=t.get(r.larkAppId),a=Ue(n),c=He(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var We=(0,i.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(ue,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(De,{chat:r}),(0,e.jsxs)(de,{children:[(0,e.jsxs)("div",{className:"groups-row-head",children:[(0,e.jsx)("b",{children:r.name??r.chatId}),(0,e.jsxs)("span",{className:"groups-row-meta",children:[(0,e.jsx)("span",{className:"groups-row-tag",children:(0,e.jsx)("code",{children:r.chatId})}),r.ownerId?(0,e.jsxs)("span",{className:"groups-row-tag groups-row-owner-tag",children:[(0,e.jsx)("span",{children:n("groups.owner")}),(0,e.jsx)("code",{children:r.ownerId})]}):null]})]}),(0,e.jsx)(je,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(_e,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(pe,{children:[(0,e.jsx)(X,{className:"add-bots",onClick:()=>t.onAddBots(r),children:n("groups.addBots")}),(0,e.jsx)("button",{className:"save-profile",type:"button",onClick:()=>t.onSaveProfile(r),children:n("groups.saveAsProfile")}),(0,e.jsx)("button",{className:"manage-chat",type:"button",onClick:()=>t.onManage(r),children:n("groups.manage")})]})]})]})});function Je(o){let{tr:t}=o,[r,n]=(0,i.useState)(!1),[a,c]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)("");async function w(u){u.preventDefault();let v=new FormData(u.currentTarget),g=String(v.get("name")??"").trim(),y=String(v.get("bindWorkingDir")??"").trim(),C=String(v.get("roleProfileId")??"").trim(),x=v.getAll("bot");if(x.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let P=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:g||void 0,larkAppIds:x,bindWorkingDir:y||void 0,roleProfileId:C||void 0})}),S=await P.json().catch(()=>({ok:!1,error:`HTTP ${P.status}`}));S.ok&&S.chatId?(d(S),o.onCreated(S,x,g)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:S.error??`HTTP ${P.status}`}),n(!1))}catch(P){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:P}),n(!1)}}if(s){let u=String(s.chatId),v=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(u)}`,g=s.invalidBotIds??[],y=s.invalidUserIds??[],C=Array.isArray(s.oncallBindings)?s.oncallBindings:[],x=C.filter(R=>R?.ok).length,P=C.filter(R=>!R?.ok),S=Ge(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:u})," ",(0,e.jsx)("button",{type:"button","data-copy":u,onClick:()=>{fe(u,t("sessions.copy")).then(R=>{R&&(I(!0),o.setTimer(()=>I(!1),800))})},children:t(f?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),(0,e.jsx)(ze,{resp:s}),C.length>0?P.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",x,"/",C.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",x,"/",C.length,"\u3002",P.map((R,A)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(R?.larkAppId??"?")}),": ",String(R?.error??"unknown")]},`${R?.larkAppId??"?"}-${A}`))]}):null,S?(0,e.jsx)("p",{className:S.kind==="ok"?"hint-ok":"hint-warn",children:S.text}):null,g.length||y.length?(0,e.jsxs)("ul",{children:[g.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:g.join(", ")})]}):null,y.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:y.join(", ")})]}):null]}):null,(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-close",onClick:o.onClose,children:t("sessions.dismiss")}),(0,e.jsx)("a",{className:"btn-link primary",href:v,target:"_blank",rel:"noopener",children:t("groups.openGroup")})]})]})}return(0,e.jsxs)("article",{className:"g-create-dialog",children:[(0,e.jsxs)("header",{className:"g-create-head",children:[(0,e.jsx)("h3",{children:t("groups.createTitle")}),(0,e.jsx)("p",{children:t("groups.createHelp")})]}),(0,e.jsxs)("form",{id:"g-createform",className:"g-create-form",onSubmit:u=>{w(u)},children:[(0,e.jsxs)("fieldset",{className:"g-modal-field g-create-bots",children:[(0,e.jsx)("legend",{children:t("groups.botPicker")}),(0,e.jsx)("div",{className:"g-bot-picker",children:(0,e.jsx)(Ee,{bots:o.bots})})]}),(0,e.jsxs)("div",{className:"g-create-fields",children:[(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.name")}),(0,e.jsx)("input",{type:"text",name:"name",placeholder:t("groups.namePlaceholder"),maxLength:60})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.bindDir")}),(0,e.jsx)("input",{type:"text",name:"bindWorkingDir",placeholder:"e.g. ~/projects/botmux"}),(0,e.jsx)("small",{children:t("groups.bindDirHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-profile-field",children:[(0,e.jsx)("legend",{children:t("groups.roleProfile")}),(0,e.jsx)("input",{type:"hidden",name:"roleProfileId",value:p}),(0,e.jsx)(ge,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:p||t("groups.roleProfileNone"),value:p,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(u=>({value:u.profileId,label:u.profileId}))],onChange:h}),(0,e.jsx)("small",{children:t("groups.roleProfileHelp")})]})]}),(0,e.jsx)("div",{className:"g-create-status","data-create-status":!0,"aria-live":"polite",children:a?(0,e.jsx)(te,{...a}):null}),(0,e.jsxs)("div",{className:"actions g-create-actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:r,children:r?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("i",{className:"button-spinner","aria-hidden":"true"}),t("groups.createSubmitting")]}):t("groups.createSubmit")})]})]})]})}function ze(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,d=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8 @ \u901A\u77E5\u5931\u8D25\uFF08",d,"\uFF09\uFF0C\u65B0\u7FA4\u53EF\u80FD\u4E0D\u4F1A\u4E3B\u52A8\u51FA\u73B0\u5728\u4F60\u4FA7\u8FB9\u680F\uFF0C\u5EFA\u8BAE\u4ECE\u4E0B\u9762\u6309\u94AE\u8DF3\u8FDB\u53BB\u3002"]})]}):null]}):n?(0,e.jsxs)("p",{className:"hint-warn",children:["\u98DE\u4E66\u62D2\u7EDD\u4E86\u81EA\u52A8\u9080\u8BF7\uFF08\u4F60\u7684 open_id \u5728\u521B\u5EFA\u8005 bot \u7684 scope \u4E0B\u4E0D\u53EF\u7528\uFF09\u3002",(0,e.jsx)("strong",{children:"\u4F60\u76EE\u524D\u4E0D\u662F\u65B0\u7FA4\u6210\u5458"}),"\uFF0C\u9700\u8981\u8BA9\u7FA4\u91CC\u7684\u67D0\u4E2A\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u6765\u3002"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u6CA1\u5728 dashboard \u7F13\u5B58\u91CC\u627E\u5230 ownerOpenId\uFF0C",(0,e.jsx)("strong",{children:"\u6CA1\u6709\u81EA\u52A8\u9080\u8BF7\u4F60"}),"\u3002\u70B9\u5F00\u4E0B\u9762\u94FE\u63A5\u524D\uFF0C\u5148\u8BA9\u7FA4\u91CC\u4EFB\u4E00\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u53BB\u3002"]})}function Ve(o){let{chat:t,tr:r}=o,[n,a]=(0,i.useState)(!1),[c,s]=(0,i.useState)(null),[d,f]=(0,i.useState)(null),I=(0,i.useMemo)(()=>new Set((t.memberBots??[]).filter(h=>h.inChat).map(h=>h.larkAppId)),[t]);async function p(h){h.preventDefault();let u=new FormData(h.currentTarget).getAll("bot");if(u.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),f(null);return}a(!0),s(null),f(null);try{let g=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:u})})).json();if(g.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(g.result){let y=Ae(g.result);try{await o.onReloadGroups({force:!0}),f({result:y})}catch(C){f({result:y,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${C}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(g)})}catch(v){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:v})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:h=>{p(h)},children:[(0,e.jsx)(Ee,{bots:o.bots,excludeIds:I}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(te,{...c}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Fe,{summary:d.result}),d.refreshError?(0,e.jsx)(te,{title:"\u5237\u65B0\u5931\u8D25",reason:d.refreshError}):null]}):null]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-cancel",onClick:o.onClose,children:r("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:n,children:n?"Adding...":r("groups.addBots")})]})]})]})}function qe(o){let{tr:t}=o,[r,n]=(0,i.useState)([]),[a,c]=(0,i.useState)([]),[s,d]=(0,i.useState)(!0),[f,I]=(0,i.useState)(null),p=(0,i.useMemo)(()=>[...a].sort((m,T)=>m.profileId.localeCompare(T.profileId)),[a]),h=p.length>0,w=r.filter(m=>m.status==="empty").length,u=r.filter(m=>m.status==="error").length,v=!s&&!f&&r.length>0&&u===0,[g,y]=(0,i.useState)("new"),[C,x]=(0,i.useState)(o.suggestedProfileId),[P,S]=(0,i.useState)(""),[R,A]=(0,i.useState)(!1),[_,G]=(0,i.useState)(null),B=g==="overwrite"?P:C.trim(),D=t(g==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),q=f||(s?t("groups.saveProfilePreparing"):u?t("groups.saveProfileFailedLoadSummary",{count:u}):r.length?w?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:w}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,i.useEffect)(()=>{let m=!0;return d(!0),I(null),G(null),(async()=>{try{let[T,L]=await Promise.all([Se(o.chat),V().catch(()=>[])]);if(!m)return;let M=[...L].sort((O,U)=>O.profileId.localeCompare(U.profileId));n(T),c(L),S(O=>M.some(U=>U.profileId===O)?O:M[0]?.profileId??"")}catch(T){if(!m)return;n([]),c([]),S(""),I(T instanceof Error?T.message:String(T))}finally{m&&d(!1)}})(),()=>{m=!1}},[o.chat]);async function $(m){if(m.preventDefault(),!!v){if(!Q(B)){G({text:t("groups.saveProfileInvalid"),className:"error"});return}A(!0),G({text:t("groups.saveProfileSaving")});try{let L=(await Promise.all(r.map(async M=>(await fetch(`/api/role-profiles/${encodeURIComponent(B)}/${encodeURIComponent(M.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:M.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(L!==r.length){G({text:t("groups.saveProfileFailed",{saved:L,total:r.length}),className:"error"}),A(!1);return}G({text:t("groups.saveProfileDone",{name:B,count:L}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(T){G({text:String(T),className:"error"}),A(!1)}}}function N(m){m==="overwrite"&&!h||(y(m),G(null))}return(0,e.jsxs)("article",{className:"g-save-profile-dialog",children:[(0,e.jsxs)("header",{children:[(0,e.jsx)("h3",{children:t("groups.saveProfileTitle")}),(0,e.jsx)("p",{children:t("groups.saveProfileIntro",{name:o.chat.name??o.chat.chatId,count:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:m=>{$(m)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),u?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:u})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Z,{label:t("common.loading")})}):f?(0,e.jsx)("div",{className:"g-save-profile-empty",children:f}):r.length?r.map(m=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${m.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:m.botName??m.larkAppId}),(0,e.jsx)("code",{children:m.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${m.status==="error"?"error":"ok"}`,children:t(m.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},m.larkAppId)):(0,e.jsx)("div",{className:"g-save-profile-empty",children:t("groups.saveProfileNoRoles")})})]}),(0,e.jsxs)("div",{className:"form-row",children:[(0,e.jsx)("span",{children:t("groups.saveProfileMode")}),(0,e.jsxs)("div",{className:"g-save-profile-switch",role:"tablist","aria-label":t("groups.saveProfileMode"),children:[(0,e.jsx)("button",{type:"button",className:g==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":g==="new",onClick:()=>N("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:g==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":g==="overwrite",disabled:!h,onClick:()=>N("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:g!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:C,maxLength:64,autoComplete:"off",onChange:m=>{x(m.currentTarget.value),G(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:g!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),h?(0,e.jsx)("div",{className:"g-save-profile-picker",children:p.map(m=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${m.profileId===P?"selected":""}`,"data-profile-id":m.profileId,"aria-pressed":m.profileId===P,onClick:()=>{S(m.profileId),y("overwrite"),G(null)},children:[(0,e.jsx)("span",{children:m.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:m.entryCount??0})})]},m.profileId))}):(0,e.jsx)("div",{className:"g-save-profile-summary warn",children:t("groups.saveProfileExistingEmpty")}),(0,e.jsx)("small",{children:t("groups.saveProfileOverwriteHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-target",children:[(0,e.jsx)("span",{children:t("groups.saveProfileTarget")}),(0,e.jsx)("code",{"data-save-profile-target":!0,children:B||"-"}),(0,e.jsx)("small",{"data-save-profile-target-mode":!0,children:t(g==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${v?"":"warn"}`,children:q}),(0,e.jsx)("div",{className:`g-save-profile-status ${_?.className??""}`,"data-save-profile-status":!0,children:_?.text??""}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-save-profile-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:!v||R||g==="overwrite"&&!P,children:R?t("groups.saveProfileSaving"):D})]})]})]})}function Ke(o){let{member:t,tr:r}=o,n=(0,i.useRef)(null),[a,c]=(0,i.useState)(!!t.oncallChat),[s,d]=(0,i.useState)(t.oncallChat?.workingDir??""),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null);async function w(){h(null);let u=s.trim();if(a&&!u){h({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}I(!0);try{let v=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,g=a?await fetch(v,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:u})}):await fetch(v,{method:"DELETE"}),y=await g.json().catch(()=>({}));if(g.ok&&y.ok){h({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${y.resolvedPath??u}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else h({text:`\u2717 ${y.error??g.status}`,className:"hint-warn-inline"})}catch(v){h({text:`\u2717 ${v?.message??v}`,className:"hint-warn-inline"})}finally{I(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:u=>{c(u.currentTarget.checked),u.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:u=>d(u.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:f,onClick:()=>{w()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${p?.className??""}`,"data-status":!0,children:p?.text??""})]})]})}function Ze(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(p=>p.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,i.useState)(()=>new Set);function d(p,h){s(w=>{let u=new Set(w);return h?u.add(p):u.delete(p),u})}async function f(){let p=[...c];if(p.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${p.length} \u4E2A\u673A\u5668\u4EBA\u9000\u51FA\u7FA4\u804A\uFF1F\u8BE5 bot \u5728\u6B64\u7FA4\u7684\u4F1A\u8BDD\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))try{let w=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:p})})).json(),u=(w.result??[]).map(v=>{if(!v.ok)return`${v.larkAppId}: \u5931\u8D25 (${v.error??"unknown"})`;let g=v.closedSessions??[],y=g.filter(P=>!P.ok).length,C=g.length-y,x=g.length===0?"":y===0?`\uFF08\u5173\u95ED ${C} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${C} \u4E2A\uFF0C${y} \u4E2A\u5931\u8D25\uFF09`;return`${v.larkAppId}: OK${x}`}).join(`
1
+ import{a as he,b as ve,c as be,d as ye}from"./chunk-R3FXBFQH.js";import{a as fe}from"./chunk-ZJVTGU5X.js";import{c as me}from"./chunk-ZU3UUKAR.js";import{c as Z,g as X,h as le,m as ce,n as ue,o as de,p as pe,q as ge}from"./chunk-5CJMHTT4.js";import{c as j,d as J,u as z,x as ae,z as ne}from"./chunk-MFQPCVHY.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as $e,d as ie}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var i=K($e(),1);var Me=/^[A-Za-z0-9._-]{1,64}$/,ke=6,we=30;function Y(o,t){return be(o,t)}function Pe(o,t,r=we){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):we,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,d=Math.min(c,Math.max(1,s)),f=(d-1)*n,I=Math.min(a,f+n);return{rows:o.slice(f,I),page:d,totalPages:c,from:a===0?0:f+1,to:I,total:a}}async function Ce(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function Q(o){return Me.test(o)&&o!=="."&&o!==".."}function ee(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return Q(t)?t:"profile"}async function V(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Ie(o){let t=await V(),r=await Ce(t,ke,async s=>{try{let f=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(f.entries)?f.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let d of s.memberBots??[]){if(!d?.inChat||!d?.hasRole||!d?.larkAppId)continue;let f=Y(d.larkAppId,s.chatId);n.has(f)||(n.add(f),a.push({chatId:s.chatId,larkAppId:d.larkAppId}))}let c=await ye(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Se(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ce(t,ke,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,d=c?String(s??"").trim():"",f=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:d,status:d?f??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ne(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Re(o,t){let r=t.q.trim().toLowerCase();return o.filter(n=>!r||(n.name??"").toLowerCase().includes(r)||n.chatId.toLowerCase().includes(r)||(n.ownerId??"").toLowerCase().includes(r)).filter(n=>!t.missingOnly||(n.memberBots??[]).some(a=>!a.inChat))}function xe(o,t){if(t.size===0)return!0;let r=o?.memberBots??[];for(let n of t)if(!r.some(a=>a.larkAppId===n&&a.inChat))return!1;return!0}function Ae(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Ge(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:z("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:z("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:z("groups.roleProfileBootstrapDone",{name:n})}}function Be(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(d=>({larkAppId:d.larkAppId,botName:d.botName,inChat:c.has(d.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(d=>d.chatId!==t)]}}var e=K(ie(),1);function Te(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Oe(o){let t={};for(let r of ae(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function De(o){let t=o.chat,r=t.avatar??ne(t.chatId),[n,a]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:Oe(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function te(o){return(0,e.jsxs)("p",{className:"hint-warn",children:[(0,e.jsx)("strong",{children:o.title}),(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:String(o.reason??"unknown")})]})}function Ee(o){return(0,e.jsx)(e.Fragment,{children:Ne(o.bots,o.excludeIds).map(t=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"bot",value:t.larkAppId}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]})]},t.larkAppId))})}function Fe(o){let t=o.summary;return t.rows.length?(0,e.jsxs)("div",{className:t.failed?"hint-warn":"hint-ok",children:[(0,e.jsxs)("strong",{children:["\u6DFB\u52A0\u7ED3\u679C\uFF1A\u6210\u529F ",t.okCount,"/",t.rows.length,t.failed?`\uFF0C\u5931\u8D25 ${t.failed}`:""]}),(0,e.jsx)("ul",{children:t.rows.map((r,n)=>{let a=String(r?.id??"?");return(0,e.jsxs)("li",{children:[(0,e.jsx)("code",{children:a}),": ",r?.ok?"OK":`failed (${String(r?.error??"unknown")})`]},`${a}-${n}`)})})]}):(0,e.jsx)("p",{className:"hint-warn",children:"\u6CA1\u6709\u8FD4\u56DE\u6DFB\u52A0\u7ED3\u679C\u3002"})}function je(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let f of t.memberBots??[])f?.inChat&&a.set(f.larkAppId,r.groupRoleContentByBot.get(Y(f.larkAppId,t.chatId))??null);if(!he(a))return null;let s=ve(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let d=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(d,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function Ue(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function He(o,t){switch(o){case"in":return t("groups.botStatusIn");case"out":return t("groups.botStatusOut");case"error":return t("groups.botStatusError");default:return t("groups.botStatusUnknown")}}function _e(o){let t=new Map((o.chat.memberBots??[]).map(r=>[r.larkAppId,r]));return(0,e.jsx)("div",{className:"groups-bot-strip","aria-label":o.tr("groups.botCoverage"),children:o.bots.map(r=>{let n=t.get(r.larkAppId),a=Ue(n),c=He(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var We=(0,i.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(ue,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(De,{chat:r}),(0,e.jsxs)(de,{children:[(0,e.jsxs)("div",{className:"groups-row-head",children:[(0,e.jsx)("b",{children:r.name??r.chatId}),(0,e.jsxs)("span",{className:"groups-row-meta",children:[(0,e.jsx)("span",{className:"groups-row-tag",children:(0,e.jsx)("code",{children:r.chatId})}),r.ownerId?(0,e.jsxs)("span",{className:"groups-row-tag groups-row-owner-tag",children:[(0,e.jsx)("span",{children:n("groups.owner")}),(0,e.jsx)("code",{children:r.ownerId})]}):null]})]}),(0,e.jsx)(je,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(_e,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(pe,{children:[(0,e.jsx)(X,{className:"add-bots",onClick:()=>t.onAddBots(r),children:n("groups.addBots")}),(0,e.jsx)("button",{className:"save-profile",type:"button",onClick:()=>t.onSaveProfile(r),children:n("groups.saveAsProfile")}),(0,e.jsx)("button",{className:"manage-chat",type:"button",onClick:()=>t.onManage(r),children:n("groups.manage")})]})]})]})});function Je(o){let{tr:t}=o,[r,n]=(0,i.useState)(!1),[a,c]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)("");async function w(u){u.preventDefault();let v=new FormData(u.currentTarget),g=String(v.get("name")??"").trim(),y=String(v.get("bindWorkingDir")??"").trim(),C=String(v.get("roleProfileId")??"").trim(),x=v.getAll("bot");if(x.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let P=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:g||void 0,larkAppIds:x,bindWorkingDir:y||void 0,roleProfileId:C||void 0})}),S=await P.json().catch(()=>({ok:!1,error:`HTTP ${P.status}`}));S.ok&&S.chatId?(d(S),o.onCreated(S,x,g)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:S.error??`HTTP ${P.status}`}),n(!1))}catch(P){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:P}),n(!1)}}if(s){let u=String(s.chatId),v=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(u)}`,g=s.invalidBotIds??[],y=s.invalidUserIds??[],C=Array.isArray(s.oncallBindings)?s.oncallBindings:[],x=C.filter(R=>R?.ok).length,P=C.filter(R=>!R?.ok),S=Ge(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:u})," ",(0,e.jsx)("button",{type:"button","data-copy":u,onClick:()=>{fe(u,t("sessions.copy")).then(R=>{R&&(I(!0),o.setTimer(()=>I(!1),800))})},children:t(f?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),(0,e.jsx)(ze,{resp:s}),C.length>0?P.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",x,"/",C.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",x,"/",C.length,"\u3002",P.map((R,A)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(R?.larkAppId??"?")}),": ",String(R?.error??"unknown")]},`${R?.larkAppId??"?"}-${A}`))]}):null,S?(0,e.jsx)("p",{className:S.kind==="ok"?"hint-ok":"hint-warn",children:S.text}):null,g.length||y.length?(0,e.jsxs)("ul",{children:[g.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:g.join(", ")})]}):null,y.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:y.join(", ")})]}):null]}):null,(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-close",onClick:o.onClose,children:t("sessions.dismiss")}),(0,e.jsx)("a",{className:"btn-link primary",href:v,target:"_blank",rel:"noopener",children:t("groups.openGroup")})]})]})}return(0,e.jsxs)("article",{className:"g-create-dialog",children:[(0,e.jsxs)("header",{className:"g-create-head",children:[(0,e.jsx)("h3",{children:t("groups.createTitle")}),(0,e.jsx)("p",{children:t("groups.createHelp")})]}),(0,e.jsxs)("form",{id:"g-createform",className:"g-create-form",onSubmit:u=>{w(u)},children:[(0,e.jsxs)("fieldset",{className:"g-modal-field g-create-bots",children:[(0,e.jsx)("legend",{children:t("groups.botPicker")}),(0,e.jsx)("div",{className:"g-bot-picker",children:(0,e.jsx)(Ee,{bots:o.bots})})]}),(0,e.jsxs)("div",{className:"g-create-fields",children:[(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.name")}),(0,e.jsx)("input",{type:"text",name:"name",placeholder:t("groups.namePlaceholder"),maxLength:60})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.bindDir")}),(0,e.jsx)("input",{type:"text",name:"bindWorkingDir",placeholder:"e.g. ~/projects/botmux"}),(0,e.jsx)("small",{children:t("groups.bindDirHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-profile-field",children:[(0,e.jsx)("legend",{children:t("groups.roleProfile")}),(0,e.jsx)("input",{type:"hidden",name:"roleProfileId",value:p}),(0,e.jsx)(ge,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:p||t("groups.roleProfileNone"),value:p,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(u=>({value:u.profileId,label:u.profileId}))],onChange:h}),(0,e.jsx)("small",{children:t("groups.roleProfileHelp")})]})]}),(0,e.jsx)("div",{className:"g-create-status","data-create-status":!0,"aria-live":"polite",children:a?(0,e.jsx)(te,{...a}):null}),(0,e.jsxs)("div",{className:"actions g-create-actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:r,children:r?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("i",{className:"button-spinner","aria-hidden":"true"}),t("groups.createSubmitting")]}):t("groups.createSubmit")})]})]})]})}function ze(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,d=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8 @ \u901A\u77E5\u5931\u8D25\uFF08",d,"\uFF09\uFF0C\u65B0\u7FA4\u53EF\u80FD\u4E0D\u4F1A\u4E3B\u52A8\u51FA\u73B0\u5728\u4F60\u4FA7\u8FB9\u680F\uFF0C\u5EFA\u8BAE\u4ECE\u4E0B\u9762\u6309\u94AE\u8DF3\u8FDB\u53BB\u3002"]})]}):null]}):n?(0,e.jsxs)("p",{className:"hint-warn",children:["\u98DE\u4E66\u62D2\u7EDD\u4E86\u81EA\u52A8\u9080\u8BF7\uFF08\u4F60\u7684 open_id \u5728\u521B\u5EFA\u8005 bot \u7684 scope \u4E0B\u4E0D\u53EF\u7528\uFF09\u3002",(0,e.jsx)("strong",{children:"\u4F60\u76EE\u524D\u4E0D\u662F\u65B0\u7FA4\u6210\u5458"}),"\uFF0C\u9700\u8981\u8BA9\u7FA4\u91CC\u7684\u67D0\u4E2A\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u6765\u3002"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u6CA1\u5728 dashboard \u7F13\u5B58\u91CC\u627E\u5230 ownerOpenId\uFF0C",(0,e.jsx)("strong",{children:"\u6CA1\u6709\u81EA\u52A8\u9080\u8BF7\u4F60"}),"\u3002\u70B9\u5F00\u4E0B\u9762\u94FE\u63A5\u524D\uFF0C\u5148\u8BA9\u7FA4\u91CC\u4EFB\u4E00\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u53BB\u3002"]})}function Ve(o){let{chat:t,tr:r}=o,[n,a]=(0,i.useState)(!1),[c,s]=(0,i.useState)(null),[d,f]=(0,i.useState)(null),I=(0,i.useMemo)(()=>new Set((t.memberBots??[]).filter(h=>h.inChat).map(h=>h.larkAppId)),[t]);async function p(h){h.preventDefault();let u=new FormData(h.currentTarget).getAll("bot");if(u.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),f(null);return}a(!0),s(null),f(null);try{let g=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:u})})).json();if(g.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(g.result){let y=Ae(g.result);try{await o.onReloadGroups({force:!0}),f({result:y})}catch(C){f({result:y,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${C}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(g)})}catch(v){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:v})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:h=>{p(h)},children:[(0,e.jsx)(Ee,{bots:o.bots,excludeIds:I}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(te,{...c}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Fe,{summary:d.result}),d.refreshError?(0,e.jsx)(te,{title:"\u5237\u65B0\u5931\u8D25",reason:d.refreshError}):null]}):null]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-cancel",onClick:o.onClose,children:r("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:n,children:n?"Adding...":r("groups.addBots")})]})]})]})}function qe(o){let{tr:t}=o,[r,n]=(0,i.useState)([]),[a,c]=(0,i.useState)([]),[s,d]=(0,i.useState)(!0),[f,I]=(0,i.useState)(null),p=(0,i.useMemo)(()=>[...a].sort((m,T)=>m.profileId.localeCompare(T.profileId)),[a]),h=p.length>0,w=r.filter(m=>m.status==="empty").length,u=r.filter(m=>m.status==="error").length,v=!s&&!f&&r.length>0&&u===0,[g,y]=(0,i.useState)("new"),[C,x]=(0,i.useState)(o.suggestedProfileId),[P,S]=(0,i.useState)(""),[R,A]=(0,i.useState)(!1),[_,G]=(0,i.useState)(null),B=g==="overwrite"?P:C.trim(),D=t(g==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),q=f||(s?t("groups.saveProfilePreparing"):u?t("groups.saveProfileFailedLoadSummary",{count:u}):r.length?w?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:w}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,i.useEffect)(()=>{let m=!0;return d(!0),I(null),G(null),(async()=>{try{let[T,L]=await Promise.all([Se(o.chat),V().catch(()=>[])]);if(!m)return;let M=[...L].sort((O,U)=>O.profileId.localeCompare(U.profileId));n(T),c(L),S(O=>M.some(U=>U.profileId===O)?O:M[0]?.profileId??"")}catch(T){if(!m)return;n([]),c([]),S(""),I(T instanceof Error?T.message:String(T))}finally{m&&d(!1)}})(),()=>{m=!1}},[o.chat]);async function $(m){if(m.preventDefault(),!!v){if(!Q(B)){G({text:t("groups.saveProfileInvalid"),className:"error"});return}A(!0),G({text:t("groups.saveProfileSaving")});try{let L=(await Promise.all(r.map(async M=>(await fetch(`/api/role-profiles/${encodeURIComponent(B)}/${encodeURIComponent(M.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:M.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(L!==r.length){G({text:t("groups.saveProfileFailed",{saved:L,total:r.length}),className:"error"}),A(!1);return}G({text:t("groups.saveProfileDone",{name:B,count:L}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(T){G({text:String(T),className:"error"}),A(!1)}}}function N(m){m==="overwrite"&&!h||(y(m),G(null))}return(0,e.jsxs)("article",{className:"g-save-profile-dialog",children:[(0,e.jsxs)("header",{children:[(0,e.jsx)("h3",{children:t("groups.saveProfileTitle")}),(0,e.jsx)("p",{children:t("groups.saveProfileIntro",{name:o.chat.name??o.chat.chatId,count:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:m=>{$(m)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),u?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:u})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Z,{label:t("common.loading")})}):f?(0,e.jsx)("div",{className:"g-save-profile-empty",children:f}):r.length?r.map(m=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${m.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:m.botName??m.larkAppId}),(0,e.jsx)("code",{children:m.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${m.status==="error"?"error":"ok"}`,children:t(m.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},m.larkAppId)):(0,e.jsx)("div",{className:"g-save-profile-empty",children:t("groups.saveProfileNoRoles")})})]}),(0,e.jsxs)("div",{className:"form-row",children:[(0,e.jsx)("span",{children:t("groups.saveProfileMode")}),(0,e.jsxs)("div",{className:"g-save-profile-switch",role:"tablist","aria-label":t("groups.saveProfileMode"),children:[(0,e.jsx)("button",{type:"button",className:g==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":g==="new",onClick:()=>N("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:g==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":g==="overwrite",disabled:!h,onClick:()=>N("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:g!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:C,maxLength:64,autoComplete:"off",onChange:m=>{x(m.currentTarget.value),G(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:g!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),h?(0,e.jsx)("div",{className:"g-save-profile-picker",children:p.map(m=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${m.profileId===P?"selected":""}`,"data-profile-id":m.profileId,"aria-pressed":m.profileId===P,onClick:()=>{S(m.profileId),y("overwrite"),G(null)},children:[(0,e.jsx)("span",{children:m.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:m.entryCount??0})})]},m.profileId))}):(0,e.jsx)("div",{className:"g-save-profile-summary warn",children:t("groups.saveProfileExistingEmpty")}),(0,e.jsx)("small",{children:t("groups.saveProfileOverwriteHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-target",children:[(0,e.jsx)("span",{children:t("groups.saveProfileTarget")}),(0,e.jsx)("code",{"data-save-profile-target":!0,children:B||"-"}),(0,e.jsx)("small",{"data-save-profile-target-mode":!0,children:t(g==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${v?"":"warn"}`,children:q}),(0,e.jsx)("div",{className:`g-save-profile-status ${_?.className??""}`,"data-save-profile-status":!0,children:_?.text??""}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-save-profile-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:!v||R||g==="overwrite"&&!P,children:R?t("groups.saveProfileSaving"):D})]})]})]})}function Ke(o){let{member:t,tr:r}=o,n=(0,i.useRef)(null),[a,c]=(0,i.useState)(!!t.oncallChat),[s,d]=(0,i.useState)(t.oncallChat?.workingDir??""),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null);async function w(){h(null);let u=s.trim();if(a&&!u){h({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}I(!0);try{let v=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,g=a?await fetch(v,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:u})}):await fetch(v,{method:"DELETE"}),y=await g.json().catch(()=>({}));if(g.ok&&y.ok){h({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${y.resolvedPath??u}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else h({text:`\u2717 ${y.error??g.status}`,className:"hint-warn-inline"})}catch(v){h({text:`\u2717 ${v?.message??v}`,className:"hint-warn-inline"})}finally{I(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:u=>{c(u.currentTarget.checked),u.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:u=>d(u.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:f,onClick:()=>{w()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${p?.className??""}`,"data-status":!0,children:p?.text??""})]})]})}function Ze(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(p=>p.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,i.useState)(()=>new Set);function d(p,h){s(w=>{let u=new Set(w);return h?u.add(p):u.delete(p),u})}async function f(){let p=[...c];if(p.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${p.length} \u4E2A\u673A\u5668\u4EBA\u9000\u51FA\u7FA4\u804A\uFF1F\u8BE5 bot \u5728\u6B64\u7FA4\u7684\u4F1A\u8BDD\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))try{let w=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:p})})).json(),u=(w.result??[]).map(v=>{if(!v.ok)return`${v.larkAppId}: \u5931\u8D25 (${v.error??"unknown"})`;let g=v.closedSessions??[],y=g.filter(P=>!P.ok).length,C=g.length-y,x=g.length===0?"":y===0?`\uFF08\u5173\u95ED ${C} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${C} \u4E2A\uFF0C${y} \u4E2A\u5931\u8D25\uFF09`;return`${v.larkAppId}: OK${x}`}).join(`
2
2
  `);alert(u||`Unexpected: ${JSON.stringify(w)}`),await o.onReloadGroups({force:!0})}catch(h){alert("Network error: "+h)}finally{o.onClose()}}async function I(){if(n.length===0||!confirm(`\u786E\u5B9A\u89E3\u6563\u7FA4\u804A\u300C${t.name??t.chatId}\u300D\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D\uFF0C\u672C\u7FA4\u6240\u6709\u673A\u5668\u4EBA\u4F1A\u8BDD\u4E5F\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))return;let p=[...n].sort((w,u)=>(u.larkAppId===a?1:0)-(w.larkAppId===a?1:0)),h=[];for(let w of p)try{let u=await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/disband`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppId:w.larkAppId})}),v=await u.json();if(v.ok){let g=v.closedSessions??[],y=g.filter(P=>!P.ok).length,C=g.length-y,x=g.length===0?"":y===0?`
3
3
  \u5173\u95ED\u4E86 ${C} \u4E2A\u4F1A\u8BDD\u3002`:`
4
4
  \u5173\u95ED\u4E86 ${C} \u4E2A\u4F1A\u8BDD\uFF0C${y} \u4E2A\u4F1A\u8BDD\u5173\u95ED\u5931\u8D25\u3002`;alert(`\u5DF2\u89E3\u6563\uFF08\u7531 ${w.botName??w.larkAppId} \u6267\u884C\uFF09${x}`),await o.onReloadGroups({force:!0}),o.onClose();return}h.push(`${w.botName??w.larkAppId}: ${v.error??u.status}`)}catch(u){h.push(`${w.botName??w.larkAppId}: ${u}`)}alert(`\u6240\u6709\u5728\u7FA4\u673A\u5668\u4EBA\u5747\u65E0\u6CD5\u89E3\u6563\uFF1A
@@ -1,4 +1,4 @@
1
- import{a as Me}from"./chunk-FDZ7WOBW.js";import{c as Re}from"./chunk-EZH56JCI.js";import{c as Ct,h as $e,q as rt}from"./chunk-5CJMHTT4.js";import{C as ke,E as V,u as o,v as Vt,w as Mt}from"./chunk-E3HZZXK5.js";import{a as Ie}from"./chunk-SYC6D5XU.js";import{a as Ds,b as Fs,d as Te}from"./chunk-5THX4DI2.js";import{c as Rt}from"./chunk-7SZRL6FY.js";var b=Rt(Ds(),1),gs=Rt(Fs(),1);var tt={bad:0,warn:1,info:2},Ae=["research","edit","run","delegate","discuss"],G=["research","edit","run","delegate","discuss"],Gt=[{key:"overview",label:"insights.tabOverview"},{key:"sessions",label:"insights.tabSessions"},{key:"flow",label:"insights.tabFlow"},{key:"dist",label:"insights.tabDist"},{key:"hot",label:"insights.tabHot"}],Ut=[{key:"all",label:"insights.timeAll",days:0},{key:"1d",label:"insights.time1d",days:1},{key:"7d",label:"insights.time7d",days:7},{key:"30d",label:"insights.time30d",days:30}],Yt=["all","review","failed","slow"],Es=["overview","sessions","flow","dist","hot"],Le=[{key:"recent",label:"insights.sortRecent"},{key:"review",label:"insights.sortReview"},{key:"spans",label:"insights.sortSpans"},{key:"fails",label:"insights.sortFails"},{key:"slow",label:"insights.sortSlow"},{key:"agent",label:"insights.sortAgent"}],De=["recent","review","spans","fails","slow","agent"],Jt=["failure","slow","retry","read_write_imbalance"],Fe=[{key:"all",label:"spanAll"},{key:"user",label:"senderHuman"},{key:"a2a_agent",label:"senderA2A"},{key:"system",label:"senderSystem"}],Ee=[{key:"all",label:"spanAll"},{key:"failure",label:"tag.failure"},{key:"slow",label:"tag.slow"}],lt=new Set(["tool_error","test_failed","typecheck_failed","lint_failed","command_failed","timeout","no_output"]);function Qt(){return{messages:[],total:0,hasMore:!1,nextOffset:0,loading:!1,q:"",role:"all",tag:"all",openOps:new Set}}function T(e){return Number.isFinite(e)?Math.round(e).toLocaleString("en-US"):"-"}function O(e){return e==null||!Number.isFinite(e)?"-":e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function _e(e){return e==="error"?"!":e==="running"?"~":"OK"}function Pt(e,s){return s||(e?e.status==="unsupported_cli"?o("insights.unsupported"):e.status==="transcript_missing"?o("insights.noTranscript"):e.status==="parse_error"?o("insights.parseError"):e.status:"-")}function q(e){return String(e.title??"").replace(/^(?:@\S+\s*)+/,"").trim()||String(e.sessionId??"")}function Xt(e){return e==="bad"?o("insights.sevBad"):e==="warn"?o("insights.sevWarn"):o("insights.sevInfo")}function je(e,s){let n=o(e);return n===e?s:n}function He(e){return je(`insights.suggestion.${e.id}.title`,e.title)}function U(e){let s=`insights.phase.${e}`,n=o(s);return n===s?e:n}function ct(e){return String(e||"unknown").replace(/[^a-z0-9_-]/gi,"-")}function W(e){return`phase-${ct(e)}`}function Ot(e){return!e||e.status!=="ok"?!1:e.agg.failedSpans>0||e.agg.slowSpans>0||e.suggestions.some(s=>s.severity!=="info")}function Be(e){return{session:{sessionId:e.sessionId,cliId:e.cliId,cliSessionId:e.cliSessionId,title:e.title,botName:e.botName,larkAppId:e.larkAppId,workingDir:e.workingDir,status:e.status,lastMessageAt:e.lastMessageAt},report:e.report}}function At(e){return String(e.session.cliId??"unknown")}var Ce=["claude-code","seed","relay","aiden","codex","traex","antigravity"];function qe(e){let s=new Map;for(let n of e){let i=At(n);s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>{let r=Ce.indexOf(n.id),l=Ce.indexOf(i.id);return(r<0?99:r)-(l<0?99:l)||n.id.localeCompare(i.id)})}function dt(e){let s=String(e.session.workingDir??"").replace(/\/+$/,"");return s?s.split("/").pop()||s:""}function We(e){let s=new Map;for(let n of e){let i=dt(n);i&&s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>i.count-n.count||n.id.localeCompare(i.id))}function Lt(e,s,n,i=new Set,r={}){let l=n.trim().toLowerCase();return e.filter(g=>{let c=g.session,d=g.report;return r.analyzableOnly&&d?.status!=="ok"||r.project&&dt(g)!==r.project||r.sinceMs&&Number(c.lastMessageAt??c.spawnedAt??0)<r.sinceMs||i.size&&!i.has(At(g))||s==="review"&&!Ot(d)||s==="failed"&&!(d?.status==="ok"&&d.agg.failedSpans>0)||s==="slow"&&!(d?.status==="ok"&&d.agg.slowSpans>0)?!1:l?`${q(c)} ${V(c)} ${c.cliId??""} ${c.workingDir??""} ${c.sessionId??""}`.toLowerCase().includes(l):!0})}function Ke(e){let s={totalSpans:0,failedSpans:0,slowSpans:0,failByTool:{},phase:{research:{count:0,ms:0},edit:{count:0,ms:0},run:{count:0,ms:0},delegate:{count:0,ms:0},discuss:{count:0,ms:0}},readWriteRatio:null,compactions:0,subagentCostShare:null},n=0,i=new Map;for(let l of e){let g=l.report;if(!g||g.status!=="ok")continue;n+=1;let c=g.agg;s.totalSpans+=c.totalSpans,s.failedSpans+=c.failedSpans,s.slowSpans+=c.slowSpans,s.compactions+=c.compactions;for(let[d,a]of Object.entries(c.failByTool??{}))s.failByTool[d]=(s.failByTool[d]??0)+a;for(let d of Ae){let a=c.phase?.[d];a&&(s.phase[d].count+=a.count,s.phase[d].ms+=a.ms)}for(let d of g.suggestions??[]){let a=i.get(d.id);a?a.count+=1:i.set(d.id,{id:d.id,title:d.title,severity:d.severity,count:1,evidence:d.evidence??[],action:d.action})}}s.readWriteRatio=s.phase.edit.count>0?Number((s.phase.research.count/s.phase.edit.count).toFixed(2)):null;let r=Object.entries(s.failByTool).map(([l,g])=>({tool:l,count:g})).sort((l,g)=>g.count-l.count).slice(0,5);return{totalCount:e.length,analyzedCount:n,agg:s,topFailedTools:r,suggestions:[...i.values()]}}function Z(e){return Ae.reduce((s,n)=>s+(e.agg.phase?.[n]?.ms??0),0)}function ze(e){return e.map(s=>s.report).filter(s=>!!s&&s.status==="ok")}function Ve(e){if(!e.length)return 0;let s=[...e].sort((i,r)=>i-r),n=Math.floor(s.length/2);return s.length%2?s[n]:(s[n-1]+s[n])/2}function _s(e){return e?.status==="ok"?e.agg.failedSpans*6+e.agg.slowSpans*3+e.suggestions.filter(s=>s.severity==="bad").length*5:0}function Ge(e,s){let n=r=>Number(r.session.lastMessageAt??0),i=r=>{let l=r.report,g=l?.status==="ok"?l.agg:null;switch(s){case"spans":return g?.totalSpans??-1;case"fails":return g?.failedSpans??-1;case"slow":return g?.slowSpans??-1;case"agent":return l?.status==="ok"?Z(l):-1;case"review":return _s(l);default:return 0}};return[...e].sort((r,l)=>s==="recent"?n(l)-n(r):i(l)-i(r)||n(l)-n(r))}function Ue(e){let s=`insights.intent.${e}`,n=o(s);return n===s?e:n}function et(e){let s=`insights.result.${e}`,n=o(s);return n===s?e:n}function st(e){let s=`insights.tag.${e}`,n=o(s);return n===s?e:n}function K(e,s){let n=`insights.${e}.${s.id}`,i=o(n,s.params);return i===n?s.id:i}function Ye(e){return K("turnHeadline",e)}var Pe={"shell command":"insights.struct.shell","file edit":"insights.struct.fileEdit","read/search":"insights.struct.readSearch","agent task":"insights.struct.agentTask","tool input":"insights.struct.toolInput","tool result":"insights.struct.toolResult","tool error":"insights.struct.toolError","patch failed":"insights.struct.patchFailed","patch applied":"insights.struct.patchApplied"};function Zt(e){if(!e)return"";let s=e.match(/^exit (-?\d+)$/);return s?o("insights.struct.exit",{code:s[1]}):Pe[e]?je(Pe[e],e):e}function Je(e){return e.status==="error"||!!e.result&&lt.has(e.result.category)}function Dt(e,s){return e&&e.kind!=="unknown"?Ue(e.kind):s}function te(e){return Dt(e.intent,e.tool)}function Ft(e){return e?[e.kind!=="unknown"?Ue(e.kind):"",e.subject,e.detail].filter(Boolean).join(" \xB7 "):""}var js=["failure","retry","read_write_imbalance","slow"];function Qe(e){for(let s of js)if(e.includes(s)){let n=o(`insights.advice.${s}`);if(n!==`insights.advice.${s}`)return n}return""}function Xe(e,s){let n=e.spans??[],i=s?(e.recommendations??[]).find(l=>l.id===s)??null:null;if(!i)return{rec:null,spanIdx:new Set,turnIdx:new Set};let r=(i.evidence?.spanIndexes??[]).filter(l=>Number.isInteger(l)&&l>=0&&l<n.length);return{rec:i,spanIdx:new Set(r),turnIdx:new Set(i.evidence?.turnIndexes??[])}}function Et(e){return e.replace(/<(mentions|attachments|available_bots|system-reminder|quoted_messages|sender)\b[\s\S]*?<\/\1>/g," ").replace(/<botmux_reminder>[\s\S]*?<\/botmux_reminder>/g," ").replace(/<\/?(user_message|local-command-[a-z]+)>/g," ").replace(/<sender\b[^>]*\/?>/g," ").replace(/<mention\b[^>]*\/?>/g," ").replace(/\[用户引用了消息[\s\S]*?\]/g," ").replace(/\[来自[^\]]*@mention\]/g," ").replace(/\[(图片|文件)\s*\d+[^\]\n]*\][^\n]*/g," ").replace(/[ \t]+/g," ").replace(/ *\n */g,`
1
+ import{a as Me}from"./chunk-FDZ7WOBW.js";import{c as Re}from"./chunk-ZU3UUKAR.js";import{c as Ct,h as $e,q as rt}from"./chunk-5CJMHTT4.js";import{C as ke,E as V,u as o,v as Vt,w as Mt}from"./chunk-MFQPCVHY.js";import{a as Ie}from"./chunk-SYC6D5XU.js";import{a as Ds,b as Fs,d as Te}from"./chunk-5THX4DI2.js";import{c as Rt}from"./chunk-7SZRL6FY.js";var b=Rt(Ds(),1),gs=Rt(Fs(),1);var tt={bad:0,warn:1,info:2},Ae=["research","edit","run","delegate","discuss"],G=["research","edit","run","delegate","discuss"],Gt=[{key:"overview",label:"insights.tabOverview"},{key:"sessions",label:"insights.tabSessions"},{key:"flow",label:"insights.tabFlow"},{key:"dist",label:"insights.tabDist"},{key:"hot",label:"insights.tabHot"}],Ut=[{key:"all",label:"insights.timeAll",days:0},{key:"1d",label:"insights.time1d",days:1},{key:"7d",label:"insights.time7d",days:7},{key:"30d",label:"insights.time30d",days:30}],Yt=["all","review","failed","slow"],Es=["overview","sessions","flow","dist","hot"],Le=[{key:"recent",label:"insights.sortRecent"},{key:"review",label:"insights.sortReview"},{key:"spans",label:"insights.sortSpans"},{key:"fails",label:"insights.sortFails"},{key:"slow",label:"insights.sortSlow"},{key:"agent",label:"insights.sortAgent"}],De=["recent","review","spans","fails","slow","agent"],Jt=["failure","slow","retry","read_write_imbalance"],Fe=[{key:"all",label:"spanAll"},{key:"user",label:"senderHuman"},{key:"a2a_agent",label:"senderA2A"},{key:"system",label:"senderSystem"}],Ee=[{key:"all",label:"spanAll"},{key:"failure",label:"tag.failure"},{key:"slow",label:"tag.slow"}],lt=new Set(["tool_error","test_failed","typecheck_failed","lint_failed","command_failed","timeout","no_output"]);function Qt(){return{messages:[],total:0,hasMore:!1,nextOffset:0,loading:!1,q:"",role:"all",tag:"all",openOps:new Set}}function T(e){return Number.isFinite(e)?Math.round(e).toLocaleString("en-US"):"-"}function O(e){return e==null||!Number.isFinite(e)?"-":e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function _e(e){return e==="error"?"!":e==="running"?"~":"OK"}function Pt(e,s){return s||(e?e.status==="unsupported_cli"?o("insights.unsupported"):e.status==="transcript_missing"?o("insights.noTranscript"):e.status==="parse_error"?o("insights.parseError"):e.status:"-")}function q(e){return String(e.title??"").replace(/^(?:@\S+\s*)+/,"").trim()||String(e.sessionId??"")}function Xt(e){return e==="bad"?o("insights.sevBad"):e==="warn"?o("insights.sevWarn"):o("insights.sevInfo")}function je(e,s){let n=o(e);return n===e?s:n}function He(e){return je(`insights.suggestion.${e.id}.title`,e.title)}function U(e){let s=`insights.phase.${e}`,n=o(s);return n===s?e:n}function ct(e){return String(e||"unknown").replace(/[^a-z0-9_-]/gi,"-")}function W(e){return`phase-${ct(e)}`}function Ot(e){return!e||e.status!=="ok"?!1:e.agg.failedSpans>0||e.agg.slowSpans>0||e.suggestions.some(s=>s.severity!=="info")}function Be(e){return{session:{sessionId:e.sessionId,cliId:e.cliId,cliSessionId:e.cliSessionId,title:e.title,botName:e.botName,larkAppId:e.larkAppId,workingDir:e.workingDir,status:e.status,lastMessageAt:e.lastMessageAt},report:e.report}}function At(e){return String(e.session.cliId??"unknown")}var Ce=["claude-code","seed","relay","aiden","codex","traex","antigravity"];function qe(e){let s=new Map;for(let n of e){let i=At(n);s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>{let r=Ce.indexOf(n.id),l=Ce.indexOf(i.id);return(r<0?99:r)-(l<0?99:l)||n.id.localeCompare(i.id)})}function dt(e){let s=String(e.session.workingDir??"").replace(/\/+$/,"");return s?s.split("/").pop()||s:""}function We(e){let s=new Map;for(let n of e){let i=dt(n);i&&s.set(i,(s.get(i)??0)+1)}return[...s.entries()].map(([n,i])=>({id:n,count:i})).sort((n,i)=>i.count-n.count||n.id.localeCompare(i.id))}function Lt(e,s,n,i=new Set,r={}){let l=n.trim().toLowerCase();return e.filter(g=>{let c=g.session,d=g.report;return r.analyzableOnly&&d?.status!=="ok"||r.project&&dt(g)!==r.project||r.sinceMs&&Number(c.lastMessageAt??c.spawnedAt??0)<r.sinceMs||i.size&&!i.has(At(g))||s==="review"&&!Ot(d)||s==="failed"&&!(d?.status==="ok"&&d.agg.failedSpans>0)||s==="slow"&&!(d?.status==="ok"&&d.agg.slowSpans>0)?!1:l?`${q(c)} ${V(c)} ${c.cliId??""} ${c.workingDir??""} ${c.sessionId??""}`.toLowerCase().includes(l):!0})}function Ke(e){let s={totalSpans:0,failedSpans:0,slowSpans:0,failByTool:{},phase:{research:{count:0,ms:0},edit:{count:0,ms:0},run:{count:0,ms:0},delegate:{count:0,ms:0},discuss:{count:0,ms:0}},readWriteRatio:null,compactions:0,subagentCostShare:null},n=0,i=new Map;for(let l of e){let g=l.report;if(!g||g.status!=="ok")continue;n+=1;let c=g.agg;s.totalSpans+=c.totalSpans,s.failedSpans+=c.failedSpans,s.slowSpans+=c.slowSpans,s.compactions+=c.compactions;for(let[d,a]of Object.entries(c.failByTool??{}))s.failByTool[d]=(s.failByTool[d]??0)+a;for(let d of Ae){let a=c.phase?.[d];a&&(s.phase[d].count+=a.count,s.phase[d].ms+=a.ms)}for(let d of g.suggestions??[]){let a=i.get(d.id);a?a.count+=1:i.set(d.id,{id:d.id,title:d.title,severity:d.severity,count:1,evidence:d.evidence??[],action:d.action})}}s.readWriteRatio=s.phase.edit.count>0?Number((s.phase.research.count/s.phase.edit.count).toFixed(2)):null;let r=Object.entries(s.failByTool).map(([l,g])=>({tool:l,count:g})).sort((l,g)=>g.count-l.count).slice(0,5);return{totalCount:e.length,analyzedCount:n,agg:s,topFailedTools:r,suggestions:[...i.values()]}}function Z(e){return Ae.reduce((s,n)=>s+(e.agg.phase?.[n]?.ms??0),0)}function ze(e){return e.map(s=>s.report).filter(s=>!!s&&s.status==="ok")}function Ve(e){if(!e.length)return 0;let s=[...e].sort((i,r)=>i-r),n=Math.floor(s.length/2);return s.length%2?s[n]:(s[n-1]+s[n])/2}function _s(e){return e?.status==="ok"?e.agg.failedSpans*6+e.agg.slowSpans*3+e.suggestions.filter(s=>s.severity==="bad").length*5:0}function Ge(e,s){let n=r=>Number(r.session.lastMessageAt??0),i=r=>{let l=r.report,g=l?.status==="ok"?l.agg:null;switch(s){case"spans":return g?.totalSpans??-1;case"fails":return g?.failedSpans??-1;case"slow":return g?.slowSpans??-1;case"agent":return l?.status==="ok"?Z(l):-1;case"review":return _s(l);default:return 0}};return[...e].sort((r,l)=>s==="recent"?n(l)-n(r):i(l)-i(r)||n(l)-n(r))}function Ue(e){let s=`insights.intent.${e}`,n=o(s);return n===s?e:n}function et(e){let s=`insights.result.${e}`,n=o(s);return n===s?e:n}function st(e){let s=`insights.tag.${e}`,n=o(s);return n===s?e:n}function K(e,s){let n=`insights.${e}.${s.id}`,i=o(n,s.params);return i===n?s.id:i}function Ye(e){return K("turnHeadline",e)}var Pe={"shell command":"insights.struct.shell","file edit":"insights.struct.fileEdit","read/search":"insights.struct.readSearch","agent task":"insights.struct.agentTask","tool input":"insights.struct.toolInput","tool result":"insights.struct.toolResult","tool error":"insights.struct.toolError","patch failed":"insights.struct.patchFailed","patch applied":"insights.struct.patchApplied"};function Zt(e){if(!e)return"";let s=e.match(/^exit (-?\d+)$/);return s?o("insights.struct.exit",{code:s[1]}):Pe[e]?je(Pe[e],e):e}function Je(e){return e.status==="error"||!!e.result&&lt.has(e.result.category)}function Dt(e,s){return e&&e.kind!=="unknown"?Ue(e.kind):s}function te(e){return Dt(e.intent,e.tool)}function Ft(e){return e?[e.kind!=="unknown"?Ue(e.kind):"",e.subject,e.detail].filter(Boolean).join(" \xB7 "):""}var js=["failure","retry","read_write_imbalance","slow"];function Qe(e){for(let s of js)if(e.includes(s)){let n=o(`insights.advice.${s}`);if(n!==`insights.advice.${s}`)return n}return""}function Xe(e,s){let n=e.spans??[],i=s?(e.recommendations??[]).find(l=>l.id===s)??null:null;if(!i)return{rec:null,spanIdx:new Set,turnIdx:new Set};let r=(i.evidence?.spanIndexes??[]).filter(l=>Number.isInteger(l)&&l>=0&&l<n.length);return{rec:i,spanIdx:new Set(r),turnIdx:new Set(i.evidence?.turnIndexes??[])}}function Et(e){return e.replace(/<(mentions|attachments|available_bots|system-reminder|quoted_messages|sender)\b[\s\S]*?<\/\1>/g," ").replace(/<botmux_reminder>[\s\S]*?<\/botmux_reminder>/g," ").replace(/<\/?(user_message|local-command-[a-z]+)>/g," ").replace(/<sender\b[^>]*\/?>/g," ").replace(/<mention\b[^>]*\/?>/g," ").replace(/\[用户引用了消息[\s\S]*?\]/g," ").replace(/\[来自[^\]]*@mention\]/g," ").replace(/\[(图片|文件)\s*\d+[^\]\n]*\][^\n]*/g," ").replace(/[ \t]+/g," ").replace(/ *\n */g,`
2
2
  `).replace(/\n{3,}/g,`
3
3
 
4
4
  `).trim()}var _t=new Me({html:!1,linkify:!0,breaks:!0});_t.validateLink=e=>/^(https?:|mailto:)/i.test(e.trim());var Oe=_t.renderer.rules.link_open;_t.renderer.rules.link_open=(e,s,n,i,r)=>(e[s].attrSet("target","_blank"),e[s].attrSet("rel","noopener noreferrer nofollow"),Oe?Oe(e,s,n,i,r):r.renderToken(e,s,n));function Ze(e){try{return _t.render(e).trim()||`<p>${Vt(e)}</p>`}catch{return`<p>${Vt(e)}</p>`}}function wt(e){return e.prompt?.source?.kind??"user"}function ts(e){let s=[];for(let n of e)if(n.role==="agent"){let i=s[s.length-1];i&&i.kind==="ops"&&i.turnIndex===n.turnIndex?i.msgs.push(n):s.push({kind:"ops",turnIndex:n.turnIndex,msgs:[n]})}else s.push({kind:"prompt",msg:n});return s}function es(e){let s=new Map;for(let r of e.events??[])r.phase&&s.set(r.phase,(s.get(r.phase)??0)+(r.durationMs??0)+1);let n="discuss",i=-1;for(let[r,l]of s)l>i&&(i=l,n=r);return n}function ss(e,s,n){let i=Ut.find(l=>l.key===e),r=i&&i.days>0?Date.now()-i.days*864e5:void 0;return{project:s||void 0,sinceMs:r,analyzableOnly:!n}}function ee(){let e=typeof location<"u"&&location.hash||"",s=e.indexOf("?");if(s<0)return{};let n={};for(let[i,r]of new URLSearchParams(e.slice(s+1)))n[i]=r;return n}function ns(e){let s=new URLSearchParams;for(let[i,r]of Object.entries(e))r&&s.set(i,r);let n=s.toString();return"#/insights"+(n?`?${n}`:"")}function as(){let e=ee();return Es.includes(e.tab)?e.tab:"overview"}async function is(){let e=await fetch("/api/insights/summary?limit=200",{cache:"no-store"}),s=await e.json().catch(()=>({}));if(!e.ok||s?.ok===!1||!s.overview)throw new Error(String(s?.error??e.status));return s.overview}async function os(e){let s=await fetch(`/api/sessions/${encodeURIComponent(e)}/insight?detail=spans`,{cache:"no-store"}),n=await s.json().catch(()=>({}));if(!s.ok||n?.ok===!1)throw new Error(String(n?.error??s.status));return n.report}async function rs(e,s){let n=new URLSearchParams({detail:"conversation",offset:String(s.offset),limit:String(s.limit)});s.q&&n.set("q",s.q),s.role&&s.role!=="all"&&n.set("role",s.role),s.tag&&s.tag!=="all"&&n.set("tag",s.tag);let i=await fetch(`/api/sessions/${encodeURIComponent(e)}/insight?${n.toString()}`,{cache:"no-store"}),r=await i.json().catch(()=>({}));if(!i.ok||r?.ok===!1)throw new Error(String(r?.error??i.status));let l=r?.conversation;return{messages:l?.messages??[],total:l?.total??0,hasMore:!!l?.hasMore,nextOffset:l?.nextOffset??s.offset+(l?.messages?.length??0)}}async function ls(e,s){let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/insight/turn/${s}?offset=0&limit=40000`,{cache:"no-store"}),i=await n.json().catch(()=>({}));if(!n.ok||i?.ok===!1)throw new Error(String(i?.error??n.status));return i?.turn?.prompt??{text:"",truncated:!1}}function cs(e){let s=e.session;return`${V(s)} \xB7 ${String(s.cliId??"-")}${s.workingDir?` \xB7 ${dt(e)}`:""} \xB7 ${Mt(s.lastMessageAt??s.spawnedAt??0)}`}var t=Rt(Te(),1),se="__all__";function ds(e,s,n){return Math.min(Math.max(e,s),n)}function Hs(e){let s=e.getBoundingClientRect(),n=12,i=Math.min(420,Math.max(280,window.innerWidth-n*2)),r=ds(Math.round(s.left+s.width/2-i/2),n,Math.max(n,window.innerWidth-i-n)),l=Math.round(s.bottom+8),g=ds(l,n,Math.max(n,window.innerHeight-132)),c=Math.max(140,Math.floor(window.innerHeight-g-n));return{top:g,left:r,width:i,maxHeight:c}}function pt(e,s){let n=new Set(e);return n.has(s)?n.delete(s):n.add(s),n}function us(e,s){let n=new Set(e);return n.add(s),n}function Ht({text:e,className:s="md-body"}){return(0,t.jsx)("div",{className:s,dangerouslySetInnerHTML:{__html:Ze(e)}})}function Bs({tip:e}){return(0,t.jsx)("div",{id:"insight-tip",className:"ins-tip",role:"tooltip",hidden:!e.visible,style:{left:e.x,top:e.y},children:e.text})}function Y({label:e,value:s,sub:n}){return(0,t.jsxs)("div",{className:"card",children:[(0,t.jsx)("div",{className:"cv",children:s}),(0,t.jsx)("div",{className:"cl",children:e}),n?(0,t.jsx)("div",{className:"cs",children:n}):null]})}function ae(){return(0,t.jsxs)("p",{className:"insight-disclosure",children:["\u2696\uFE0E ",o("insights.disclosure")]})}function ie({phase:e}){let s=Object.entries(e??{}).filter(([,n])=>n.count>0||n.ms>0);return s.length?(0,t.jsx)("div",{className:"mph",children:s.map(([n,i])=>{let r=Math.max(1,i.ms||i.count);return(0,t.jsx)("i",{className:W(n),style:{flex:r},title:`${U(n)} \xB7 ${i.count} \xB7 ${O(i.ms)}`},n)})}):null}function qs({active:e,onChange:s}){return(0,t.jsx)("div",{className:"insight-tabs",role:"tablist",children:Gt.map(n=>(0,t.jsx)("button",{type:"button",className:`itab${n.key===e?" on":""}`,role:"tab","aria-selected":n.key===e,onClick:()=>s(n.key),children:o(n.label)},n.key))})}function Ws({data:e}){let s=e.agg,n=s.readWriteRatio===null?"-":s.readWriteRatio.toFixed(1),i=e.topFailedTools.slice(0,5),r=[...e.suggestions].sort((l,g)=>tt[l.severity]-tt[g.severity]||g.count-l.count).slice(0,6);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"cards insights-metrics",children:[(0,t.jsx)(Y,{label:o("insights.metricSessions"),value:T(e.totalCount),sub:o("insights.metricAnalyzed",{count:e.analyzedCount})}),(0,t.jsx)(Y,{label:o("insights.metricSpans"),value:T(s.totalSpans),sub:o("insights.metricSafe")}),(0,t.jsx)(Y,{label:o("insights.metricFailed"),value:T(s.failedSpans),sub:i[0]?`${i[0].tool} \xD7${i[0].count}`:""}),(0,t.jsx)(Y,{label:o("insights.metricSlow"),value:T(s.slowSpans)}),(0,t.jsx)(Y,{label:o("insights.metricRw"),value:n,sub:o("insights.metricCompactions",{count:s.compactions})})]}),(0,t.jsxs)("div",{className:"insights-overview-grid",children:[(0,t.jsxs)("section",{className:"block recblock",children:[(0,t.jsx)("h3",{children:o("insights.recommendations")}),(0,t.jsx)("div",{className:"reclist",children:r.length?r.map(l=>(0,t.jsxs)("div",{className:`rec ${l.severity}`,children:[(0,t.jsxs)("div",{className:"rectop",children:[(0,t.jsx)("b",{children:He(l)}),(0,t.jsx)("span",{children:Xt(l.severity)})]}),(0,t.jsx)("div",{className:"recev",children:o("insights.seenInSessions",{count:l.count})})]},l.id)):(0,t.jsx)("p",{className:"mut",children:o("insights.noRecommendations")})})]}),(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.toolFailures")}),(0,t.jsx)(ms,{rows:i.map(l=>({key:l.tool,label:l.tool,count:l.count})),empty:o("insights.noFailures")})]})]}),(0,t.jsx)(ae,{})]})}function ms({rows:e,empty:s,renderValue:n,onRowClick:i}){if(!e.length)return(0,t.jsx)("div",{className:"hbars",children:(0,t.jsx)("p",{className:"mut",children:s})});let r=Math.max(1,...e.map(l=>l.count));return(0,t.jsx)("div",{className:"hbars",children:e.map(l=>{let g=Math.max(l.count?4:0,Math.round(l.count/r*100)),c=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"hblabel",title:l.label,children:l.label}),(0,t.jsx)("div",{className:"hbtrack",children:(0,t.jsx)("div",{className:"hbfill",style:{width:`${g}%`}})}),(0,t.jsxs)("div",{className:"hbval",children:[n?n(l):T(l.count),l.sub]})]});return i?(0,t.jsx)("button",{type:"button",className:"hbrow hbrow-click",onClick:()=>i(l),children:c},l.key):(0,t.jsx)("div",{className:"hbrow",children:c},l.key)})})}function Ks({records:e}){let i=Date.now(),r=new Array(28).fill(0);for(let c of e){let d=Number(c.session.lastMessageAt??0);if(!d)continue;let a=Math.floor((i-d)/864e5);a>=0&&a<28&&(r[27-a]+=1)}let l=r.reduce((c,d)=>c+d,0);if(!l)return null;let g=Math.max(1,...r);return(0,t.jsxs)("section",{className:"block trend-block",children:[(0,t.jsxs)("div",{className:"ihist-head",children:[(0,t.jsx)("h3",{children:o("insights.distTrend")}),(0,t.jsxs)("span",{className:"mut",children:[o("insights.distTrendSub")," \xB7 ",l]})]}),(0,t.jsx)("div",{className:"trend",children:r.map((c,d)=>{let a=new Date(i-(27-d)*864e5),v=`${a.getMonth()+1}-${a.getDate()} \xB7 ${c}`;return(0,t.jsx)("i",{className:"trendbar",style:{height:`${c?Math.max(8,Math.round(c/g*100)):2}%`},title:v},d)})})]})}function ut({title:e,values:s,bins:n,fmtMedian:i=T,sortKey:r,onSort:l}){let g=n.map(a=>({label:a.label,count:s.filter(a.test).length})),c=Math.max(1,...g.map(a=>a.count)),d=Math.max(1,s.length);return(0,t.jsxs)("section",{className:"block ihist",children:[(0,t.jsxs)("div",{className:"ihist-head",children:[(0,t.jsx)("h3",{children:e}),(0,t.jsx)("span",{className:"mut",children:o("insights.distMedian",{v:i(Ve(s))})}),r?(0,t.jsxs)("button",{type:"button",className:"ihist-jump",onClick:()=>l?.(r),children:[o("insights.viewSessions")," \u203A"]}):null]}),(0,t.jsx)("div",{className:"hbars",children:g.map(a=>{let v=Math.max(a.count?4:0,Math.round(a.count/c*100)),p=Math.round(a.count/d*100);return(0,t.jsxs)("div",{className:"hbrow",children:[(0,t.jsx)("div",{className:"hblabel",children:a.label}),(0,t.jsx)("div",{className:"hbtrack",children:(0,t.jsx)("div",{className:"hbfill",style:{width:`${v}%`}})}),(0,t.jsxs)("div",{className:"hbval",children:[T(a.count),(0,t.jsxs)("small",{children:[p,"%"]})]})]},a.label)})})]})}function zs({records:e,onSort:s}){let n=ze(e);if(!n.length)return(0,t.jsx)("div",{className:"insight-empty",children:o("insights.distEmpty")});let i=n.map(a=>(a.hot?.files??[]).reduce((v,p)=>v+(p.added??0)+(p.removed??0),0)),r=n.map(a=>a.agg.totalSpans),l=n.map(a=>a.agg.failedSpans),g=n.map(a=>a.agg.slowSpans),c=n.map(a=>Z(a)/6e4),d=n.map(a=>a.agg.readWriteRatio).filter(a=>a!==null&&Number.isFinite(a));return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"mut ins-hint",children:o("insights.distHint")}),(0,t.jsxs)("div",{className:"ihist-grid",children:[(0,t.jsx)(Ks,{records:e}),(0,t.jsx)(ut,{title:o("insights.distSpans"),values:r,onSort:s,sortKey:"spans",bins:[{label:"0-10",test:a=>a<=10},{label:"11-50",test:a=>a>10&&a<=50},{label:"51-200",test:a=>a>50&&a<=200},{label:"201-500",test:a=>a>200&&a<=500},{label:"500+",test:a=>a>500}]}),(0,t.jsx)(ut,{title:o("insights.distFailed"),values:l,onSort:s,sortKey:"fails",bins:[{label:"0",test:a=>a===0},{label:"1-2",test:a=>a>=1&&a<=2},{label:"3-5",test:a=>a>=3&&a<=5},{label:"6-10",test:a=>a>=6&&a<=10},{label:"10+",test:a=>a>10}]}),(0,t.jsx)(ut,{title:o("insights.distSlow"),values:g,onSort:s,sortKey:"slow",bins:[{label:"0",test:a=>a===0},{label:"1-2",test:a=>a>=1&&a<=2},{label:"3-5",test:a=>a>=3&&a<=5},{label:"5+",test:a=>a>5}]}),(0,t.jsx)(ut,{title:o("insights.distAgentTime"),values:c,onSort:s,sortKey:"agent",fmtMedian:a=>`${Math.round(a)}m`,bins:[{label:"<1m",test:a=>a<1},{label:"1-5m",test:a=>a>=1&&a<5},{label:"5-30m",test:a=>a>=5&&a<30},{label:"30m-2h",test:a=>a>=30&&a<120},{label:"2h+",test:a=>a>=120}]}),d.length?(0,t.jsx)(ut,{title:o("insights.distRw"),values:d,fmtMedian:a=>a.toFixed(1),bins:[{label:"0",test:a=>a===0},{label:"0-1",test:a=>a>0&&a<1},{label:"1-3",test:a=>a>=1&&a<3},{label:"3+",test:a=>a>=3}]}):null,(0,t.jsx)(ut,{title:o("insights.distChurn"),values:i,bins:[{label:"0",test:a=>a===0},{label:"1-100",test:a=>a>0&&a<=100},{label:"100-1k",test:a=>a>100&&a<=1e3},{label:"1k-10k",test:a=>a>1e3&&a<=1e4},{label:"10k+",test:a=>a>1e4}]})]}),(0,t.jsx)(ae,{})]})}function Vs({records:e,onSession:s}){let n=e.filter(c=>c.report&&c.report.status==="ok"&&c.report.agg);if(!n.length)return(0,t.jsx)("div",{className:"insight-empty",children:o("insights.distEmpty")});let i={};for(let c of G)i[c]={count:0,ms:0};for(let c of n)for(let d of G){let a=c.report.agg.phase?.[d];a&&(i[d].count+=a.count,i[d].ms+=a.ms)}let r=G.reduce((c,d)=>c+i[d].count,0)||1,l=G.reduce((c,d)=>c+i[d].ms,0)||1,g=[...n].sort((c,d)=>Z(d.report)-Z(c.report)).slice(0,40);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"mut ins-hint",children:o("insights.flowHint")}),(0,t.jsxs)("section",{className:"block flow-pipe-block",children:[(0,t.jsx)("h3",{children:o("insights.flowPipeline")}),(0,t.jsx)("p",{className:"mut flow-sub",children:o("insights.flowPipeSub")}),(0,t.jsx)("div",{className:"flow-pipe",children:G.map((c,d)=>{let a=i[c],v=Math.round(a.count/r*100),p=Math.round(a.ms/l*100);return(0,t.jsxs)("span",{style:{display:"contents"},children:[(0,t.jsxs)("div",{className:"flow-node",children:[(0,t.jsx)("i",{className:`flow-dot ${W(c)}`}),(0,t.jsx)("strong",{children:U(c)}),(0,t.jsxs)("span",{className:"flow-n",children:[T(a.count),(0,t.jsxs)("em",{children:[" \xB7 ",v,"%"]})]}),(0,t.jsxs)("span",{className:"flow-t",children:[O(a.ms),(0,t.jsxs)("em",{children:[" \xB7 ",p,"%"]})]})]}),d<G.length-1?(0,t.jsx)("span",{className:"flow-arrow",children:"\u2192"}):null]},c)})})]}),(0,t.jsxs)("div",{className:"insights-overview-grid",children:[(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.flowShares")}),(0,t.jsxs)("div",{className:"flow-bhead",children:[(0,t.jsx)("span",{}),(0,t.jsx)("span",{children:o("insights.flowActShare")}),(0,t.jsx)("span",{children:o("insights.flowTimeShare")})]}),(0,t.jsx)("div",{className:"flow-bars",children:G.map(c=>{let d=i[c],a=d.count/r*100,v=d.ms/l*100;return(0,t.jsxs)("div",{className:"flow-brow",children:[(0,t.jsxs)("span",{className:"flow-blabel",children:[(0,t.jsx)("i",{className:W(c)}),U(c)]}),(0,t.jsxs)("span",{className:"flow-btrack",children:[(0,t.jsx)("span",{className:`flow-bfill ${W(c)}`,style:{width:`${Math.max(2,a).toFixed(1)}%`}}),(0,t.jsxs)("em",{children:[Math.round(a),"%"]})]}),(0,t.jsxs)("span",{className:"flow-btrack",children:[(0,t.jsx)("span",{className:`flow-bfill ${W(c)}`,style:{width:`${Math.max(2,v).toFixed(1)}%`}}),(0,t.jsxs)("em",{children:[Math.round(v),"%"]})]})]},c)})})]}),(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.flowRhythm")}),(0,t.jsx)("div",{className:"flow-rhythm",children:g.map(c=>(0,t.jsxs)("button",{type:"button",className:"flow-sess",onClick:()=>s(String(c.session.sessionId)),children:[(0,t.jsx)("span",{className:"flow-stitle",children:q(c.session)}),(0,t.jsx)(ie,{phase:c.report.agg.phase}),(0,t.jsx)("span",{className:"flow-stime",children:O(Z(c.report))})]},String(c.session.sessionId)))}),(0,t.jsx)("div",{className:"rl-legend",children:G.map(c=>(0,t.jsxs)("span",{className:"rl-item",children:[(0,t.jsx)("i",{className:W(c)}),U(c)]},c))})]})]}),(0,t.jsx)(ae,{})]})}function Gs({records:e,openHot:s,onToggleHot:n,onProject:i,onSession:r}){let l=e.filter(m=>!!m.report&&m.report.status==="ok");if(!l.length)return(0,t.jsx)("div",{className:"insight-empty",children:o("insights.distEmpty")});let g=new Map,c=new Map,d=new Map,a=(m,f,P,C,h)=>{let N=m.get(f);return N||(N={key:f,label:P,sessions:[],reads:0,edits:0,runs:0,fails:0,count:0},m.set(f,N)),N.sessions.some(D=>D.id===C)||N.sessions.push({id:C,title:h}),N};for(let m of l){let f=String(m.session.sessionId),P=q(m.session),C=m.report.hot;for(let h of C?.files??[]){let N=a(g,`file:${h.path}`,h.path,f,P);N.reads+=h.reads,N.edits+=h.edits}for(let h of C?.cmds??[]){let N=a(c,`cmd:${h.cmd}`,h.cmd,f,P);N.runs+=h.runs,N.fails+=h.fails}for(let h of C?.errs??[]){let N=a(d,`err:${h.tool} ${h.result}`,`${h.tool} \xB7 ${et(h.result)}`,f,P);N.count+=h.count}}let v=(m,f)=>f.sessions.length-m.sessions.length,p=[...g.values()].sort((m,f)=>v(m,f)||f.edits+f.reads-(m.edits+m.reads)).slice(0,12),w=[...c.values()].sort((m,f)=>v(m,f)||f.fails-m.fails||f.runs-m.runs).slice(0,12),y=[...d.values()].sort((m,f)=>v(m,f)||f.count-m.count).slice(0,10),x=new Map;for(let m of l){let f=dt(m);if(!f)continue;let P=x.get(f)??{sessions:0,fails:0};P.sessions+=1,P.fails+=m.report.agg.failedSpans,x.set(f,P)}let M=[...x.entries()].map(([m,f])=>({id:m,...f})).sort((m,f)=>f.fails-m.fails||f.sessions-m.sessions).slice(0,10).map(m=>({key:m.id,label:m.id,count:m.sessions,sub:(0,t.jsxs)("small",{children:[m.fails," ",o("insights.hotFailsCol")]})})),k=[...l].filter(m=>m.report.agg.slowSpans>0).sort((m,f)=>f.report.agg.slowSpans-m.report.agg.slowSpans).slice(0,8);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"mut ins-hint",children:o("insights.hotHint")}),(0,t.jsxs)("div",{className:"hot-grid",children:[(0,t.jsx)(ne,{title:o("insights.hotFiles"),rows:p,openHot:s,onToggle:n,onSession:r,meta:m=>`${o("insights.readsShort")}${m.reads} \xB7 ${o("insights.editsShort")}${m.edits}`}),(0,t.jsx)(ne,{title:o("insights.hotCommands"),rows:w,openHot:s,onToggle:n,onSession:r,meta:m=>(0,t.jsxs)(t.Fragment,{children:[m.runs,"\xD7",m.fails?(0,t.jsxs)(t.Fragment,{children:[" \xB7 ",(0,t.jsxs)("span",{className:"bad",children:[m.fails," ",o("insights.hotFailsCol")]})]}):null]})}),(0,t.jsx)(ne,{title:o("insights.hotErrors"),rows:y,openHot:s,onToggle:n,onSession:r,meta:m=>`${m.count}\xD7`}),(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:o("insights.hotProjects")}),(0,t.jsx)(ms,{rows:M,empty:"-",onRowClick:m=>i(m.key),renderValue:m=>T(m.count)})]}),(0,t.jsxs)("section",{className:"block hot-sessions",children:[(0,t.jsx)("h3",{children:o("insights.hotSlowSessions")}),(0,t.jsx)("div",{className:"slist",children:k.length?k.map(m=>{let f=m.report.agg;return(0,t.jsxs)("button",{type:"button",className:"srow",onClick:()=>r(String(m.session.sessionId)),children:[(0,t.jsxs)("div",{className:"srmain",children:[(0,t.jsx)("strong",{children:q(m.session)}),(0,t.jsxs)("small",{children:[V(m.session)," \xB7 ",String(m.session.cliId??"-")]})]}),(0,t.jsxs)("div",{className:"srstats",children:[(0,t.jsxs)("b",{children:[o("insights.hotSlowCol"),(0,t.jsx)("em",{children:T(f.slowSpans)})]}),(0,t.jsxs)("b",{children:["span",(0,t.jsx)("em",{children:T(f.totalSpans)})]})]})]},String(m.session.sessionId))}):(0,t.jsx)("p",{className:"mut",children:"-"})})]})]})]})}function ne({title:e,rows:s,openHot:n,onToggle:i,onSession:r,meta:l}){return(0,t.jsxs)("section",{className:"block",children:[(0,t.jsx)("h3",{children:e}),(0,t.jsx)("div",{className:"hotlist",children:s.length?s.map(g=>{let c=n.has(g.key);return(0,t.jsxs)("div",{className:`hotitem${c?" open":""}`,children:[(0,t.jsxs)("button",{type:"button",className:"hotrow","aria-expanded":c,onClick:()=>i(g.key),children:[(0,t.jsx)("span",{className:"hotlabel",title:g.label,children:g.label}),(0,t.jsx)("span",{className:"hotmeta",children:l(g)}),(0,t.jsxs)("span",{className:"hotses",children:[g.sessions.length," ",o("insights.hotSessionsCol")]})]}),c?(0,t.jsx)("div",{className:"hot-sess",children:g.sessions.map(d=>(0,t.jsx)("button",{type:"button",className:"hot-sesslink",onClick:()=>r(d.id),children:d.title||d.id},d.id))}):null]},g.key)}):(0,t.jsx)("p",{className:"mut",children:"-"})})]})}function Us({sort:e,layout:s,onSort:n,onLayout:i}){let r=Le.map(g=>({value:g.key,label:o(g.label)})),l=r.find(g=>g.value===e)?.label??o("insights.sortLabel");return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(rt,{id:"insight-session-sort",className:"insight-sort-menu",ariaLabel:o("insights.sortLabel"),label:l,value:e,options:r,onChange:n}),(0,t.jsx)("div",{className:"insight-layout-switch",role:"group","aria-label":`${o("insights.layoutCard")} / ${o("insights.layoutTable")}`,children:[["card","insights.layoutCard"],["table","insights.layoutTable"]].map(([g,c])=>(0,t.jsx)("button",{type:"button",className:s===g?"active":"","aria-pressed":s===g,onClick:()=>i(g),children:o(c)},g))})]})}function Ys({records:e,selectedId:s,wide:n,onSelect:i,emptyHint:r}){if(!e.length)return(0,t.jsxs)("div",{className:"insight-empty",children:[o("insights.empty"),r?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("br",{}),(0,t.jsx)("span",{className:"mut",children:r})]}):null]});let l=(g,c,d=!1)=>(0,t.jsxs)("b",{className:d?"bad":void 0,children:[g,(0,t.jsx)("em",{children:c})]});return(0,t.jsx)("div",{className:`slist${n?" wide":""}`,children:e.map(g=>{let c=g.session,d=g.report,a=d?.status==="ok",v=d?.agg,p=v?.phase?.research?.count??0,w=v?.phase?.edit?.count??0;return(0,t.jsxs)("button",{type:"button",className:`srow${c.sessionId===s?" on":""}${Ot(d)?" review":""}`,onClick:()=>i(String(c.sessionId)),children:[(0,t.jsxs)("div",{className:"srmain",children:[(0,t.jsx)("strong",{children:q(c)}),(0,t.jsx)("small",{children:cs(g)}),a?(0,t.jsx)(ie,{phase:d.agg.phase}):null]}),a?(0,t.jsxs)("div",{className:"srstats",children:[l(o("insights.spansShort"),T(v.totalSpans)),l(o("insights.failedShort"),T(v.failedSpans),v.failedSpans>0),l(o("insights.slowShort"),T(v.slowSpans)),n?(0,t.jsxs)(t.Fragment,{children:[l(o("insights.readsShort"),T(p)),l(o("insights.editsShort"),T(w)),l(o("insights.durShort"),O(Z(d)))]}):null,l(o("insights.rwShort"),v.readWriteRatio!==null?v.readWriteRatio.toFixed(1):"-")]}):(0,t.jsx)("div",{className:"srmsg",children:Pt(d,g.error)})]},String(c.sessionId))})})}function Js({records:e,selectedId:s,onSelect:n,emptyHint:i}){return e.length?(0,t.jsxs)("div",{className:"stable",children:[(0,t.jsxs)("div",{className:"strow sthead",children:[(0,t.jsx)("span",{className:"stc-title",children:o("insights.colTitle")}),(0,t.jsx)("span",{className:"stc-proj",children:o("insights.colProject")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.spansShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.failedShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.slowShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.rwShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.durShort")}),(0,t.jsx)("span",{className:"stc-num",children:o("insights.colTime")})]}),e.map(r=>{let l=r.session,g=r.report,c=g?.status==="ok",d=g?.agg;return(0,t.jsxs)("button",{type:"button",className:`strow${l.sessionId===s?" on":""}${Ot(g)?" review":""}${c?"":" nostat"}`,onClick:()=>n(String(l.sessionId)),children:[(0,t.jsxs)("span",{className:"stc-title",children:[(0,t.jsx)("strong",{children:q(l)}),(0,t.jsxs)("small",{children:[V(l)," \xB7 ",String(l.cliId??"-")]})]}),(0,t.jsx)("span",{className:"stc-proj",children:l.workingDir?dt(r):"-"}),c?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"stc-num",children:T(d.totalSpans)}),(0,t.jsx)("span",{className:`stc-num${d.failedSpans?" bad":""}`,children:T(d.failedSpans)}),(0,t.jsx)("span",{className:"stc-num",children:T(d.slowSpans)}),(0,t.jsx)("span",{className:"stc-num",children:d.readWriteRatio!==null?d.readWriteRatio.toFixed(1):"-"}),(0,t.jsx)("span",{className:"stc-num",children:O(Z(g))})]}):(0,t.jsx)("span",{className:"stc-msg",children:Pt(g,r.error)}),(0,t.jsx)("span",{className:"stc-num stc-time",children:Mt(l.lastMessageAt??l.spawnedAt??0)})]},String(l.sessionId))})]}):(0,t.jsxs)("div",{className:"insight-empty",children:[o("insights.empty"),i?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("br",{}),(0,t.jsx)("span",{className:"mut",children:i})]}):null]})}function jt({label:e,preview:s}){return s?.text?(0,t.jsxs)("div",{className:"span-io",children:[(0,t.jsx)("span",{className:"span-io-label",children:e}),(0,t.jsxs)("pre",{className:"span-io-text",children:[s.text,s.truncated?`
@@ -1,4 +1,4 @@
1
- import{a as T,b as B,d as I,e as N,f as P,g as _}from"./chunk-XJ7BGPJH.js";import{C as O,E as S,G as W,a as E,u as r,v as n,w as C,y as x}from"./chunk-E3HZZXK5.js";import"./chunk-7SZRL6FY.js";function z(t){let o=String(t??"unknown"),e=`sessions.status.${o}`,i=r(e);return i===e?o:i}function F(t){return String(t??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function D(t){let o=String(t??"unknown");return`<span class="status status-${n(F(o))}">${n(z(o))}</span>`}function q(t){return W(t?.title)||String(t?.sessionId??"")}var A=14,G=49,K=18;function U(){let t=[...E.sessions.values()].filter(o=>typeof o?.sessionId=="string"&&o.sessionId&&o.status!=="closed").sort((o,e)=>Number(e.lastMessageAt??0)-Number(o.lastMessageAt??0));return[...new Set(t.map(o=>String(o.sessionId)))]}function j(t,o,e){let i=Math.max(0,Math.floor(e)),s=Math.max(1,t.width),m=Math.max(1,t.height),a=s/m,l=Math.max(1,o.width),p=Math.max(180,m-Math.max(0,o.top)-K);if(i<=0)return{columns:1,rows:0,frameWidth:Math.floor(l),frameHeight:Math.floor(l/a),ratio:a};let d=null;for(let u=1;u<=i;u+=1){let b=Math.ceil(i/u),f=(l-A*(u-1))/u,L=(p-A*(b-1)-G*b)/b;if(f<=0||L<=0)continue;let h=Math.max(1,Math.min(f,L*a)),M=h/a,c=h*M;(!d||c>d.score)&&(d={columns:u,rows:b,frameWidth:h,frameHeight:M,score:c})}if(!d){let u=Math.min(i,Math.max(1,Math.floor(l/220))),b=Math.ceil(i/u),f=Math.max(1,(l-A*(u-1))/u);return{columns:u,rows:b,frameWidth:Math.floor(f),frameHeight:Math.floor(f/a),ratio:a}}return{columns:d.columns,rows:d.rows,frameWidth:Math.floor(d.frameWidth),frameHeight:Math.floor(d.frameHeight),ratio:a}}function J(t,o){let e=Math.max(1,Math.floor(t.width)),i=Math.max(1,Math.floor(t.height)),s=Math.max(1,o.width),m=Math.max(1,o.height),a=Math.min(1,s/e,m/i);return{width:e,height:i,scale:a}}function Q(t,o){return t?`frame:${T(t,o)??"none"}`:"missing"}function V(t,o){let e=E.sessions.get(t),i=o?et(t):"";if(!e)return`<div class="monitor-room-card-title">
1
+ import{a as T,b as B,d as I,e as N,f as P,g as _}from"./chunk-XJ7BGPJH.js";import{C as O,E as S,G as W,a as E,u as r,v as n,w as C,y as x}from"./chunk-MFQPCVHY.js";import"./chunk-7SZRL6FY.js";function z(t){let o=String(t??"unknown"),e=`sessions.status.${o}`,i=r(e);return i===e?o:i}function F(t){return String(t??"unknown").toLowerCase().replace(/[^a-z0-9_-]/g,"-")}function D(t){let o=String(t??"unknown");return`<span class="status status-${n(F(o))}">${n(z(o))}</span>`}function q(t){return W(t?.title)||String(t?.sessionId??"")}var A=14,G=49,K=18;function U(){let t=[...E.sessions.values()].filter(o=>typeof o?.sessionId=="string"&&o.sessionId&&o.status!=="closed").sort((o,e)=>Number(e.lastMessageAt??0)-Number(o.lastMessageAt??0));return[...new Set(t.map(o=>String(o.sessionId)))]}function j(t,o,e){let i=Math.max(0,Math.floor(e)),s=Math.max(1,t.width),m=Math.max(1,t.height),a=s/m,l=Math.max(1,o.width),p=Math.max(180,m-Math.max(0,o.top)-K);if(i<=0)return{columns:1,rows:0,frameWidth:Math.floor(l),frameHeight:Math.floor(l/a),ratio:a};let d=null;for(let u=1;u<=i;u+=1){let b=Math.ceil(i/u),f=(l-A*(u-1))/u,L=(p-A*(b-1)-G*b)/b;if(f<=0||L<=0)continue;let h=Math.max(1,Math.min(f,L*a)),M=h/a,c=h*M;(!d||c>d.score)&&(d={columns:u,rows:b,frameWidth:h,frameHeight:M,score:c})}if(!d){let u=Math.min(i,Math.max(1,Math.floor(l/220))),b=Math.ceil(i/u),f=Math.max(1,(l-A*(u-1))/u);return{columns:u,rows:b,frameWidth:Math.floor(f),frameHeight:Math.floor(f/a),ratio:a}}return{columns:d.columns,rows:d.rows,frameWidth:Math.floor(d.frameWidth),frameHeight:Math.floor(d.frameHeight),ratio:a}}function J(t,o){let e=Math.max(1,Math.floor(t.width)),i=Math.max(1,Math.floor(t.height)),s=Math.max(1,o.width),m=Math.max(1,o.height),a=Math.min(1,s/e,m/i);return{width:e,height:i,scale:a}}function Q(t,o){return t?`frame:${T(t,o)??"none"}`:"missing"}function V(t,o){let e=E.sessions.get(t),i=o?et(t):"";if(!e)return`<div class="monitor-room-card-title">
2
2
  <strong>${n(t)}</strong>
3
3
  <span>${n(r("monitorRoom.missing"))}</span>
4
4
  </div>${i}`;let s=q(e),m=T(e),a=S(e),l=m?nt(t):"";return`<div class="monitor-room-card-title">