@tonyclaw/agent-inspector 3.1.32 → 4.0.2

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 (373) hide show
  1. package/.output/backend/nitro.json +1 -1
  2. package/.output/cli.js +241 -120
  3. package/.output/server/_ssr/index.mjs +1 -1
  4. package/.output/server/_ssr/{router-oXUk3MBR.mjs → router-BBY_zWRK.mjs} +91 -3
  5. package/.output/server/index.mjs +1 -1
  6. package/.output/ui/assets/{CompareDrawer-BtfPSpkV.js → CompareDrawer-rtNElN-B.js} +1 -1
  7. package/.output/ui/assets/{InspectorPet-D9DPPQ3n.js → InspectorPet-QaAiuF3d.js} +1 -1
  8. package/.output/ui/assets/{ProxyViewerContainer-Buu8vkCK.js → ProxyViewerContainer-6twNZHwl.js} +4 -4
  9. package/.output/ui/assets/{ReplayDialog-BER-QzpD.js → ReplayDialog-B7KlziO2.js} +1 -1
  10. package/.output/ui/assets/{RequestAnatomy-C8Zwxrr7.js → RequestAnatomy-2XVFBrW4.js} +1 -1
  11. package/.output/ui/assets/{ResponseView-DDpKdYk6.js → ResponseView-BULgzLVB.js} +1 -1
  12. package/.output/ui/assets/{StreamingChunkSequence-sMPGG7Sw.js → StreamingChunkSequence-DSkvkbns.js} +1 -1
  13. package/.output/ui/assets/{_sessionId-e4IheHnP.js → _sessionId-D2dmJi3G.js} +1 -1
  14. package/.output/ui/assets/{_sessionId-C5Uv72Fx.js → _sessionId-DcS0s1Mr.js} +1 -1
  15. package/.output/ui/assets/{index-B__qT0Yd.js → index-B0TN1KKO.js} +2 -2
  16. package/.output/ui/assets/{index-Be3bTCzi.js → index-Bva1zHEs.js} +1 -1
  17. package/.output/ui/assets/{index-C9q__p8J.js → index-BzBExOxu.js} +1 -1
  18. package/.output/ui/assets/{index-CtB0deSZ.js → index-k6sRQz55.js} +1 -1
  19. package/.output/ui/assets/{json-viewer-Db0AFp-7.js → json-viewer-CWM4tY-j.js} +1 -1
  20. package/.output/ui/assets/{jszip.min-DkY0Ym_q.js → jszip.min-BkWvRFlo.js} +1 -1
  21. package/.output/ui/index.html +1 -1
  22. package/package.json +8 -13
  23. package/src/assets/IDE/claudecode-color.svg +0 -1
  24. package/src/assets/IDE/codex-color.svg +0 -1
  25. package/src/assets/IDE/opencode.svg +0 -1
  26. package/src/assets/IDE/xiaomimimo.svg +0 -1
  27. package/src/assets/favicon.svg +0 -21
  28. package/src/assets/logos/alibaba.svg +0 -1
  29. package/src/assets/logos/anthropic.svg +0 -1
  30. package/src/assets/logos/claude-code.svg +0 -4
  31. package/src/assets/logos/deepseek.svg +0 -1
  32. package/src/assets/logos/minimax.jpeg +0 -0
  33. package/src/assets/logos/openai.svg +0 -1
  34. package/src/assets/logos/opencode.svg +0 -4
  35. package/src/assets/logos/qwen.webp +0 -0
  36. package/src/assets/logos/zhipuai.svg +0 -219
  37. package/src/backend/router.tsx +0 -36
  38. package/src/backend/routes/$.ts +0 -26
  39. package/src/backend/routes/__root.ts +0 -4
  40. package/src/backend/routes/api/-instances.ts +0 -7
  41. package/src/backend/routes/api/alerts.summary.ts +0 -28
  42. package/src/backend/routes/api/alerts.ts +0 -70
  43. package/src/backend/routes/api/config.paths.ts +0 -14
  44. package/src/backend/routes/api/config.ts +0 -73
  45. package/src/backend/routes/api/ecosystem.packages.$packageId.help.ts +0 -11
  46. package/src/backend/routes/api/ecosystem.packages.$packageId.install.ts +0 -11
  47. package/src/backend/routes/api/ecosystem.packages.$packageId.runner-presets.ts +0 -11
  48. package/src/backend/routes/api/ecosystem.packages.$packageId.upgrade.ts +0 -11
  49. package/src/backend/routes/api/ecosystem.packages.ts +0 -21
  50. package/src/backend/routes/api/ecosystem.recipes.$recipeId.run.ts +0 -11
  51. package/src/backend/routes/api/ecosystem.tasks.$taskId.ts +0 -16
  52. package/src/backend/routes/api/ecosystem.tasks.ts +0 -12
  53. package/src/backend/routes/api/groups.$groupId.evidence.ts +0 -55
  54. package/src/backend/routes/api/groups.$groupId.sessions.ts +0 -50
  55. package/src/backend/routes/api/groups.$groupId.ts +0 -93
  56. package/src/backend/routes/api/groups.ts +0 -79
  57. package/src/backend/routes/api/health.ts +0 -22
  58. package/src/backend/routes/api/instances.$name.connection.ts +0 -12
  59. package/src/backend/routes/api/instances.$name.restart.ts +0 -23
  60. package/src/backend/routes/api/instances.$name.start.ts +0 -18
  61. package/src/backend/routes/api/instances.$name.stop.ts +0 -23
  62. package/src/backend/routes/api/instances.$name.ts +0 -12
  63. package/src/backend/routes/api/instances.ts +0 -16
  64. package/src/backend/routes/api/knowledge.candidates.$candidateId.promote.ts +0 -32
  65. package/src/backend/routes/api/knowledge.candidates.$candidateId.ts +0 -50
  66. package/src/backend/routes/api/knowledge.candidates.ts +0 -10
  67. package/src/backend/routes/api/knowledge.project-context.ts +0 -29
  68. package/src/backend/routes/api/knowledge.search.ts +0 -62
  69. package/src/backend/routes/api/knowledge.sessions.$sessionId.candidates.ts +0 -26
  70. package/src/backend/routes/api/logs.$id.body.ts +0 -58
  71. package/src/backend/routes/api/logs.$id.chunks.ts +0 -37
  72. package/src/backend/routes/api/logs.$id.replay.ts +0 -297
  73. package/src/backend/routes/api/logs.$id.ts +0 -23
  74. package/src/backend/routes/api/logs.import.ts +0 -39
  75. package/src/backend/routes/api/logs.stream.ts +0 -174
  76. package/src/backend/routes/api/logs.ts +0 -214
  77. package/src/backend/routes/api/mcp.ts +0 -25
  78. package/src/backend/routes/api/models.ts +0 -10
  79. package/src/backend/routes/api/pi-agent.ts +0 -29
  80. package/src/backend/routes/api/providers.$providerId.model-metadata.ts +0 -173
  81. package/src/backend/routes/api/providers.$providerId.test.log.ts +0 -342
  82. package/src/backend/routes/api/providers.$providerId.ts +0 -111
  83. package/src/backend/routes/api/providers.export.ts +0 -44
  84. package/src/backend/routes/api/providers.import.ts +0 -81
  85. package/src/backend/routes/api/providers.scan.ts +0 -28
  86. package/src/backend/routes/api/providers.ts +0 -102
  87. package/src/backend/routes/api/runs.$runId.evidence.ts +0 -55
  88. package/src/backend/routes/api/runs.$runId.ts +0 -50
  89. package/src/backend/routes/api/runs.ts +0 -62
  90. package/src/backend/routes/api/runtime.ts +0 -46
  91. package/src/backend/routes/api/sessions.ts +0 -51
  92. package/src/backend/routes/api/storage.ts +0 -56
  93. package/src/backend/routes/livez.ts +0 -13
  94. package/src/backend/routes/metrics.ts +0 -14
  95. package/src/backend/routes/proxy/$.ts +0 -15
  96. package/src/backend/routes/readyz.ts +0 -18
  97. package/src/backend/start.ts +0 -10
  98. package/src/cli/alias.ts +0 -431
  99. package/src/cli/detect-tools.ts +0 -123
  100. package/src/cli/doctor.ts +0 -836
  101. package/src/cli/instance.ts +0 -1071
  102. package/src/cli/instanceApi.ts +0 -213
  103. package/src/cli/instanceArgs.ts +0 -301
  104. package/src/cli/instanceControl.ts +0 -191
  105. package/src/cli/instanceModel.ts +0 -276
  106. package/src/cli/instanceRegistry.ts +0 -731
  107. package/src/cli/networkHints.ts +0 -170
  108. package/src/cli/onboard.ts +0 -1668
  109. package/src/cli/onboardTarget.ts +0 -228
  110. package/src/cli/rustBackendPackage.ts +0 -458
  111. package/src/cli/startupOutput.ts +0 -16
  112. package/src/cli/templates/codex-skill-onboard.ts +0 -320
  113. package/src/cli/templates/command-onboard.ts +0 -25
  114. package/src/cli/templates/skill-onboard.ts +0 -625
  115. package/src/cli.ts +0 -1397
  116. package/src/components/OnboardingBanner.tsx +0 -115
  117. package/src/components/ProxyViewer.tsx +0 -2259
  118. package/src/components/ProxyViewerContainer.tsx +0 -1076
  119. package/src/components/alerts/AlertsDialog.tsx +0 -615
  120. package/src/components/clients/ClientLogo.tsx +0 -175
  121. package/src/components/ecosystem/AgentLabDialog.tsx +0 -947
  122. package/src/components/errors/SafeErrorBoundary.tsx +0 -201
  123. package/src/components/groups/GroupsDialog.tsx +0 -1304
  124. package/src/components/inspector-pet/InspectorPet.tsx +0 -398
  125. package/src/components/inspector-pet/InspectorPetCrab3D.tsx +0 -455
  126. package/src/components/inspector-pet/inspectorPetLogic.ts +0 -272
  127. package/src/components/pi-agent/PiAgentPanel.tsx +0 -446
  128. package/src/components/pi-agent/piAgentChatLogic.ts +0 -273
  129. package/src/components/providers/ImportWizardDialog.tsx +0 -281
  130. package/src/components/providers/ProviderCard.tsx +0 -347
  131. package/src/components/providers/ProviderForm.tsx +0 -1183
  132. package/src/components/providers/ProviderLogo.tsx +0 -122
  133. package/src/components/providers/ProviderTestResultsView.tsx +0 -734
  134. package/src/components/providers/ProvidersPanel.tsx +0 -714
  135. package/src/components/providers/SettingsDialog.tsx +0 -1042
  136. package/src/components/providers/providerFormCapabilities.ts +0 -36
  137. package/src/components/proxy-viewer/AgentTraceSummary.tsx +0 -902
  138. package/src/components/proxy-viewer/AnswerMarkdown.tsx +0 -51
  139. package/src/components/proxy-viewer/ApplicationBar.tsx +0 -123
  140. package/src/components/proxy-viewer/CompareDrawer.tsx +0 -984
  141. package/src/components/proxy-viewer/ConversationGroup.tsx +0 -208
  142. package/src/components/proxy-viewer/ConversationGroupList.tsx +0 -652
  143. package/src/components/proxy-viewer/ConversationHeader.tsx +0 -429
  144. package/src/components/proxy-viewer/LiveConnectionStatus.tsx +0 -186
  145. package/src/components/proxy-viewer/LogEntry.tsx +0 -1419
  146. package/src/components/proxy-viewer/LogEntryHeader.tsx +0 -596
  147. package/src/components/proxy-viewer/ProviderLogoStack.tsx +0 -57
  148. package/src/components/proxy-viewer/RawExportWarning.tsx +0 -77
  149. package/src/components/proxy-viewer/ReplayDialog.tsx +0 -636
  150. package/src/components/proxy-viewer/RequestToolsPanel.tsx +0 -299
  151. package/src/components/proxy-viewer/ResponseView.tsx +0 -202
  152. package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +0 -61
  153. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +0 -265
  154. package/src/components/proxy-viewer/ThreadConnector.tsx +0 -165
  155. package/src/components/proxy-viewer/ToolTraceEvents.tsx +0 -64
  156. package/src/components/proxy-viewer/TurnGroup.tsx +0 -383
  157. package/src/components/proxy-viewer/TurnGroupList.tsx +0 -156
  158. package/src/components/proxy-viewer/accessibility.ts +0 -8
  159. package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +0 -887
  160. package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +0 -222
  161. package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +0 -737
  162. package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +0 -268
  163. package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +0 -53
  164. package/src/components/proxy-viewer/anatomy/types.ts +0 -41
  165. package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +0 -114
  166. package/src/components/proxy-viewer/bodyHydration.ts +0 -123
  167. package/src/components/proxy-viewer/cacheTrend.ts +0 -50
  168. package/src/components/proxy-viewer/diff/DiffView.tsx +0 -321
  169. package/src/components/proxy-viewer/diff/computeDiff.ts +0 -178
  170. package/src/components/proxy-viewer/diff/index.ts +0 -3
  171. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +0 -194
  172. package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +0 -81
  173. package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +0 -21
  174. package/src/components/proxy-viewer/formats/index.tsx +0 -47
  175. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +0 -442
  176. package/src/components/proxy-viewer/index.ts +0 -9
  177. package/src/components/proxy-viewer/lazy.ts +0 -41
  178. package/src/components/proxy-viewer/liveConnectionState.ts +0 -158
  179. package/src/components/proxy-viewer/log-formats/anthropic.ts +0 -191
  180. package/src/components/proxy-viewer/log-formats/index.ts +0 -23
  181. package/src/components/proxy-viewer/log-formats/openai.ts +0 -256
  182. package/src/components/proxy-viewer/log-formats/types.ts +0 -40
  183. package/src/components/proxy-viewer/log-formats/unknown.ts +0 -18
  184. package/src/components/proxy-viewer/logEntryVisibility.ts +0 -73
  185. package/src/components/proxy-viewer/logFocus.ts +0 -54
  186. package/src/components/proxy-viewer/proxyViewerContainerLogic.ts +0 -124
  187. package/src/components/proxy-viewer/proxyViewerLogic.ts +0 -488
  188. package/src/components/proxy-viewer/replayComparison.ts +0 -131
  189. package/src/components/proxy-viewer/requestDiff.ts +0 -277
  190. package/src/components/proxy-viewer/requestTools.ts +0 -220
  191. package/src/components/proxy-viewer/useCopyFeedback.ts +0 -38
  192. package/src/components/proxy-viewer/useKeyboardNavigation.ts +0 -232
  193. package/src/components/proxy-viewer/viewerState.ts +0 -176
  194. package/src/components/ui/badge.tsx +0 -47
  195. package/src/components/ui/button.tsx +0 -47
  196. package/src/components/ui/collapsible.tsx +0 -21
  197. package/src/components/ui/confirm-dialog.tsx +0 -51
  198. package/src/components/ui/crab-logo.tsx +0 -45
  199. package/src/components/ui/crab-variants.tsx +0 -467
  200. package/src/components/ui/dialog.tsx +0 -130
  201. package/src/components/ui/icon-trigger.ts +0 -2
  202. package/src/components/ui/json-viewer-bulk.ts +0 -132
  203. package/src/components/ui/json-viewer.tsx +0 -508
  204. package/src/components/ui/scroll-area.tsx +0 -54
  205. package/src/components/ui/select.tsx +0 -178
  206. package/src/components/ui/separator.tsx +0 -28
  207. package/src/components/ui/tabs.tsx +0 -88
  208. package/src/components/ui/tooltip.tsx +0 -51
  209. package/src/components/ui/transient-toast.tsx +0 -105
  210. package/src/contracts/anthropic.ts +0 -230
  211. package/src/contracts/index.ts +0 -59
  212. package/src/contracts/json.ts +0 -37
  213. package/src/contracts/log.ts +0 -139
  214. package/src/contracts/openai.ts +0 -267
  215. package/src/index.css +0 -11
  216. package/src/knowledge/candidateStore.ts +0 -94
  217. package/src/knowledge/distiller.ts +0 -98
  218. package/src/knowledge/openclawClient.ts +0 -161
  219. package/src/knowledge/openclawGatewayClient.ts +0 -249
  220. package/src/knowledge/openclawMarkdown.ts +0 -146
  221. package/src/knowledge/redactor.ts +0 -80
  222. package/src/knowledge/types.ts +0 -83
  223. package/src/lib/alertContract.ts +0 -76
  224. package/src/lib/apiClient.ts +0 -166
  225. package/src/lib/apiFormat.ts +0 -29
  226. package/src/lib/backendImplementation.ts +0 -16
  227. package/src/lib/basePath.ts +0 -107
  228. package/src/lib/browserRuntimeContract.ts +0 -124
  229. package/src/lib/browserRuntimeResolver.ts +0 -333
  230. package/src/lib/chunkLoadRecovery.ts +0 -83
  231. package/src/lib/claudeCodeStrip.ts +0 -98
  232. package/src/lib/clipboard.ts +0 -67
  233. package/src/lib/codingAgentEndpoints.ts +0 -54
  234. package/src/lib/ecosystemContract.ts +0 -130
  235. package/src/lib/export-logs.ts +0 -287
  236. package/src/lib/groupContract.ts +0 -166
  237. package/src/lib/instanceContract.ts +0 -239
  238. package/src/lib/jsonFile.ts +0 -46
  239. package/src/lib/logImportContract.ts +0 -12
  240. package/src/lib/managedInstance.ts +0 -112
  241. package/src/lib/mask.ts +0 -4
  242. package/src/lib/objectUtils.ts +0 -22
  243. package/src/lib/piAgentContract.ts +0 -102
  244. package/src/lib/providerContract.ts +0 -125
  245. package/src/lib/providerImportContract.ts +0 -27
  246. package/src/lib/providerModelMetadata.ts +0 -458
  247. package/src/lib/providerTestContract.ts +0 -170
  248. package/src/lib/providerTestPrompt.ts +0 -100
  249. package/src/lib/publicBasePathContext.ts +0 -137
  250. package/src/lib/resourceLimits.ts +0 -345
  251. package/src/lib/runContract.ts +0 -164
  252. package/src/lib/runtimeConfig.ts +0 -43
  253. package/src/lib/safeDiagnostic.ts +0 -38
  254. package/src/lib/safeFetch.ts +0 -508
  255. package/src/lib/serverPort.ts +0 -47
  256. package/src/lib/sessionInfoContract.ts +0 -78
  257. package/src/lib/sessionUrl.ts +0 -46
  258. package/src/lib/ssrfGuard.ts +0 -133
  259. package/src/lib/stopReason.ts +0 -130
  260. package/src/lib/themeMode.ts +0 -41
  261. package/src/lib/timeDisplay.ts +0 -22
  262. package/src/lib/toolTrace.ts +0 -290
  263. package/src/lib/uiScale.ts +0 -117
  264. package/src/lib/unknown.ts +0 -27
  265. package/src/lib/upstreamUrl.ts +0 -150
  266. package/src/lib/useAlerts.ts +0 -82
  267. package/src/lib/useGroupEvidence.ts +0 -37
  268. package/src/lib/useGroups.ts +0 -32
  269. package/src/lib/useOnboarding.ts +0 -93
  270. package/src/lib/useProviders.ts +0 -30
  271. package/src/lib/useStripConfig.ts +0 -154
  272. package/src/lib/useThemeMode.ts +0 -40
  273. package/src/lib/useUiScale.ts +0 -52
  274. package/src/lib/utils.ts +0 -78
  275. package/src/mcp/currentContext.ts +0 -65
  276. package/src/mcp/instanceHandlers.ts +0 -151
  277. package/src/mcp/loopback.ts +0 -88
  278. package/src/mcp/mode.ts +0 -75
  279. package/src/mcp/previewExtractor.ts +0 -233
  280. package/src/mcp/server.ts +0 -2274
  281. package/src/mcp/toolHandlers.ts +0 -1533
  282. package/src/proxy/alerts.ts +0 -664
  283. package/src/proxy/chunkStorage.ts +0 -123
  284. package/src/proxy/config.ts +0 -218
  285. package/src/proxy/constants.ts +0 -66
  286. package/src/proxy/dataDir.ts +0 -147
  287. package/src/proxy/ecosystemExecutionConfirmation.ts +0 -114
  288. package/src/proxy/ecosystemExecutionRoute.ts +0 -116
  289. package/src/proxy/ecosystemRegistry.ts +0 -296
  290. package/src/proxy/ecosystemTasks.ts +0 -415
  291. package/src/proxy/evidenceAnalysis.ts +0 -526
  292. package/src/proxy/evidenceExporter.ts +0 -235
  293. package/src/proxy/formats/anthropic/anthropicProvider.ts +0 -75
  294. package/src/proxy/formats/anthropic/handler.ts +0 -75
  295. package/src/proxy/formats/anthropic/index.ts +0 -13
  296. package/src/proxy/formats/anthropic/register.ts +0 -4
  297. package/src/proxy/formats/anthropic/schemas.ts +0 -6
  298. package/src/proxy/formats/anthropic/stream.ts +0 -205
  299. package/src/proxy/formats/handler.ts +0 -46
  300. package/src/proxy/formats/index.ts +0 -13
  301. package/src/proxy/formats/jsonSchema.ts +0 -2
  302. package/src/proxy/formats/openai/alibabaProvider.ts +0 -34
  303. package/src/proxy/formats/openai/codexMetadata.ts +0 -61
  304. package/src/proxy/formats/openai/handler.ts +0 -133
  305. package/src/proxy/formats/openai/index.ts +0 -33
  306. package/src/proxy/formats/openai/provider.ts +0 -50
  307. package/src/proxy/formats/openai/register.ts +0 -4
  308. package/src/proxy/formats/openai/schemas.ts +0 -25
  309. package/src/proxy/formats/openai/stream.ts +0 -600
  310. package/src/proxy/formats/openai/zhipuProvider.ts +0 -31
  311. package/src/proxy/formats/providerAdapter.ts +0 -50
  312. package/src/proxy/formats/providerRegistry.ts +0 -51
  313. package/src/proxy/formats/providers/index.ts +0 -3
  314. package/src/proxy/formats/registry.ts +0 -65
  315. package/src/proxy/groupEvidenceExporter.ts +0 -371
  316. package/src/proxy/groupStore.ts +0 -336
  317. package/src/proxy/handler.ts +0 -729
  318. package/src/proxy/identityProxy.ts +0 -1842
  319. package/src/proxy/jsonlRecovery.ts +0 -554
  320. package/src/proxy/logBodyChunks.ts +0 -91
  321. package/src/proxy/logFinalizer.ts +0 -777
  322. package/src/proxy/logFinalizer.worker.ts +0 -24
  323. package/src/proxy/logImportUpload.ts +0 -128
  324. package/src/proxy/logImporter.ts +0 -813
  325. package/src/proxy/logIndex.ts +0 -663
  326. package/src/proxy/logSearch.ts +0 -122
  327. package/src/proxy/logger.ts +0 -537
  328. package/src/proxy/openaiOrphanToolStrip.ts +0 -142
  329. package/src/proxy/platformCommands.ts +0 -253
  330. package/src/proxy/privateDataPath.ts +0 -419
  331. package/src/proxy/providerImporters.ts +0 -578
  332. package/src/proxy/providerScanStore.ts +0 -87
  333. package/src/proxy/providerSecretStore.ts +0 -216
  334. package/src/proxy/providers.ts +0 -998
  335. package/src/proxy/rawStreamCapture.ts +0 -342
  336. package/src/proxy/runFailures.ts +0 -94
  337. package/src/proxy/runStore.ts +0 -214
  338. package/src/proxy/runtimeAdmission.ts +0 -55
  339. package/src/proxy/runtimeHealth.ts +0 -221
  340. package/src/proxy/runtimeMetrics.ts +0 -149
  341. package/src/proxy/runtimeShutdown.ts +0 -157
  342. package/src/proxy/schemas.ts +0 -112
  343. package/src/proxy/sessionArchive.ts +0 -479
  344. package/src/proxy/sessionInfo.ts +0 -266
  345. package/src/proxy/sessionProcess.ts +0 -194
  346. package/src/proxy/sessionRuntime.ts +0 -121
  347. package/src/proxy/sessionSupervisor.ts +0 -305
  348. package/src/proxy/sessionWorkerEntry.ts +0 -26
  349. package/src/proxy/shutdownCoordinator.ts +0 -90
  350. package/src/proxy/socketTracker.ts +0 -639
  351. package/src/proxy/sqliteLogIndex.ts +0 -733
  352. package/src/proxy/storageLifecycle.ts +0 -432
  353. package/src/proxy/store.ts +0 -1773
  354. package/src/proxy/streamTiming.ts +0 -31
  355. package/src/proxy/toolSchemaWarnings.ts +0 -529
  356. package/src/proxy/uiAssetServer.ts +0 -106
  357. package/src/proxy/upstream.ts +0 -127
  358. package/src/services/alerts.ts +0 -12
  359. package/src/services/groups.ts +0 -119
  360. package/src/services/piAgent.ts +0 -421
  361. package/src/services/piAgentRetrieval.ts +0 -1180
  362. package/src/services/result.ts +0 -17
  363. package/src/services/runs.ts +0 -76
  364. package/src/ui/bootstrap.ts +0 -167
  365. package/src/ui/index.html +0 -38
  366. package/src/ui/logsStreamClient.ts +0 -20
  367. package/src/ui/main.tsx +0 -13
  368. package/src/ui/public/runtime-config.js +0 -2
  369. package/src/ui/router.tsx +0 -13
  370. package/src/ui/routes/__root.tsx +0 -69
  371. package/src/ui/routes/index.tsx +0 -35
  372. package/src/ui/routes/session/$sessionId.tsx +0 -50
  373. package/src/ui/runtimeDiscovery.ts +0 -50
@@ -1,902 +0,0 @@
1
- import { useCallback, useMemo, useState, type JSX } from "react";
2
- import {
3
- AlertTriangle,
4
- Brain,
5
- ChevronDown,
6
- ChevronRight,
7
- CircleCheck,
8
- Clock,
9
- FileSearch,
10
- Loader2,
11
- MessageSquare,
12
- Pencil,
13
- RefreshCw,
14
- Save,
15
- ShieldCheck,
16
- UploadCloud,
17
- Wrench,
18
- X,
19
- XCircle,
20
- Zap,
21
- } from "lucide-react";
22
- import { z } from "zod";
23
- import type { TimeDisplayFormat } from "../../lib/runtimeConfig";
24
- import { formatTimestampRange } from "../../lib/timeDisplay";
25
- import { cn, formatTokens } from "../../lib/utils";
26
- import { fetchJsonWithTimeout, fetchWithTimeout } from "../../lib/apiClient";
27
- import {
28
- KnowledgeCandidateSchema,
29
- type KnowledgeCandidate,
30
- type KnowledgeCandidateStatus,
31
- } from "../../knowledge/types";
32
- import type { CapturedLog } from "../../contracts";
33
- import { Badge } from "../ui/badge";
34
- import { Button } from "../ui/button";
35
- import { buildTraceSummary, extractToolTraceEvents, type TraceSummary } from "./viewerState";
36
-
37
- const CandidateResponseSchema = z.object({
38
- candidates: z.array(KnowledgeCandidateSchema),
39
- });
40
-
41
- const CandidatePromotionResponseSchema = z.object({
42
- candidate: KnowledgeCandidateSchema,
43
- });
44
-
45
- const CandidatePromotionFailureResponseSchema = z.object({
46
- error: z.string().optional(),
47
- candidate: KnowledgeCandidateSchema.optional(),
48
- });
49
-
50
- const CandidateUpdateResponseSchema = z.object({
51
- candidate: KnowledgeCandidateSchema,
52
- });
53
-
54
- type CandidateDraftUpdate = {
55
- type: KnowledgeCandidate["type"];
56
- title: string;
57
- content: string;
58
- tags: string[];
59
- };
60
-
61
- type CandidateLoadState =
62
- | { status: "idle"; error: null }
63
- | { status: "loading"; error: null }
64
- | { status: "ready"; error: null }
65
- | { status: "failed"; error: string };
66
-
67
- const CANDIDATE_GENERATE_TIMEOUT_MS = 30_000;
68
- const CANDIDATE_PROMOTE_TIMEOUT_MS = 15_000;
69
- const CANDIDATE_UPDATE_TIMEOUT_MS = 15_000;
70
-
71
- type TraceInsightKind = "session" | "tool" | "slow" | "failure" | "candidate";
72
-
73
- type TraceInsight = {
74
- kind: TraceInsightKind;
75
- title: string;
76
- detail: string;
77
- logId: number | null;
78
- };
79
-
80
- const CANDIDATE_STATUS_CLASSES: Record<KnowledgeCandidateStatus, string> = {
81
- draft: "border-amber-500/30 bg-amber-500/10 text-amber-500",
82
- promoted: "border-emerald-500/30 bg-emerald-500/10 text-emerald-500",
83
- failed: "border-destructive/30 bg-destructive/10 text-destructive",
84
- };
85
-
86
- type AgentTraceSummaryProps = {
87
- logs: CapturedLog[];
88
- scopeId: string;
89
- slowResponseThresholdSeconds: number;
90
- showRollupMetrics: boolean;
91
- timeDisplayFormat: TimeDisplayFormat;
92
- };
93
-
94
- function formatElapsed(ms: number | null): string {
95
- if (ms === null) return "-";
96
- if (ms < 1000) return `${String(ms)}ms`;
97
- return `${(ms / 1000).toFixed(1)}s`;
98
- }
99
-
100
- function formatTimeRange(
101
- startedAt: string | null,
102
- endedAt: string | null,
103
- timeDisplayFormat: TimeDisplayFormat,
104
- ): string | null {
105
- if (startedAt === null || endedAt === null) return null;
106
- return formatTimestampRange(startedAt, endedAt, timeDisplayFormat);
107
- }
108
-
109
- function formatCandidateCount(count: number): string {
110
- return `${String(count)} candidate${count === 1 ? "" : "s"}`;
111
- }
112
-
113
- function getLogAnchor(logId: number): string {
114
- return `log-${String(logId)}`;
115
- }
116
-
117
- function jumpToLog(logId: number): void {
118
- const anchor = getLogAnchor(logId);
119
- const target = document.getElementById(anchor);
120
- window.history.replaceState(null, "", `#${anchor}`);
121
- if (!(target instanceof HTMLElement)) return;
122
- target.scrollIntoView({ block: "center", behavior: "smooth" });
123
- target.focus({ preventScroll: true });
124
- }
125
-
126
- function firstFailureLog(logs: CapturedLog[]): CapturedLog | null {
127
- for (const log of logs) {
128
- if (log.responseStatus !== null && log.responseStatus >= 400) return log;
129
- }
130
- return null;
131
- }
132
-
133
- function slowestLog(logs: CapturedLog[]): CapturedLog | null {
134
- let current: CapturedLog | null = null;
135
- let currentElapsed = -1;
136
- for (const log of logs) {
137
- if (log.elapsedMs === null) continue;
138
- if (log.elapsedMs > currentElapsed) {
139
- current = log;
140
- currentElapsed = log.elapsedMs;
141
- }
142
- }
143
- return current;
144
- }
145
-
146
- function firstToolLog(logs: CapturedLog[]): CapturedLog | null {
147
- for (const log of logs) {
148
- if (extractToolTraceEvents(log).length > 0) return log;
149
- }
150
- return null;
151
- }
152
-
153
- function buildDisplayNumberByLogId(logs: readonly CapturedLog[]): Map<number, number> {
154
- const result = new Map<number, number>();
155
- for (let index = 0; index < logs.length; index += 1) {
156
- const log = logs[index];
157
- if (log === undefined) continue;
158
- result.set(log.id, index + 1);
159
- }
160
- return result;
161
- }
162
-
163
- function displayLogNumber(
164
- logId: number,
165
- displayNumberByLogId: ReadonlyMap<number, number>,
166
- ): string {
167
- return String(displayNumberByLogId.get(logId) ?? logId);
168
- }
169
-
170
- function buildTraceInsights(input: {
171
- logs: CapturedLog[];
172
- scopeId: string;
173
- summary: TraceSummary;
174
- candidates: KnowledgeCandidate[];
175
- displayNumberByLogId: ReadonlyMap<number, number>;
176
- }): TraceInsight[] {
177
- const insights: TraceInsight[] = [
178
- {
179
- kind: "session",
180
- title: `${String(input.summary.llmCallCount)} LLM call${
181
- input.summary.llmCallCount === 1 ? "" : "s"
182
- }`,
183
- detail: `Scope ${input.scopeId}`,
184
- logId: input.logs[0]?.id ?? null,
185
- },
186
- ];
187
-
188
- const toolLog = firstToolLog(input.logs);
189
- if (input.summary.toolCallCount > 0 && toolLog !== null) {
190
- insights.push({
191
- kind: "tool",
192
- title: `${String(input.summary.toolCallCount)} tool call${
193
- input.summary.toolCallCount === 1 ? "" : "s"
194
- }`,
195
- detail: `First tool evidence at #${displayLogNumber(toolLog.id, input.displayNumberByLogId)}`,
196
- logId: toolLog.id,
197
- });
198
- }
199
-
200
- const failure = firstFailureLog(input.logs);
201
- if (failure !== null) {
202
- insights.push({
203
- kind: "failure",
204
- title: `Failure #${String(failure.responseStatus)}`,
205
- detail: `First failed request is #${displayLogNumber(failure.id, input.displayNumberByLogId)}`,
206
- logId: failure.id,
207
- });
208
- }
209
-
210
- const slowest = slowestLog(input.logs);
211
- if (slowest !== null && input.summary.maxElapsedMs !== null) {
212
- insights.push({
213
- kind: "slow",
214
- title: `Slowest ${formatElapsed(input.summary.maxElapsedMs)}`,
215
- detail: `Max latency observed at #${displayLogNumber(slowest.id, input.displayNumberByLogId)}`,
216
- logId: slowest.id,
217
- });
218
- }
219
-
220
- if (input.candidates.length > 0) {
221
- const draftCount = input.candidates.filter((candidate) => candidate.status === "draft").length;
222
- const promotedCount = input.candidates.filter(
223
- (candidate) => candidate.status === "promoted",
224
- ).length;
225
- insights.push({
226
- kind: "candidate",
227
- title: `${String(input.candidates.length)} memory candidate${
228
- input.candidates.length === 1 ? "" : "s"
229
- }`,
230
- detail: `${String(draftCount)} draft / ${String(promotedCount)} promoted`,
231
- logId: input.candidates[0]?.logIds[0] ?? null,
232
- });
233
- }
234
-
235
- return insights;
236
- }
237
-
238
- function insightIcon(kind: TraceInsightKind): JSX.Element {
239
- switch (kind) {
240
- case "session":
241
- return <MessageSquare className="size-3.5 text-blue-400" />;
242
- case "tool":
243
- return <Wrench className="size-3.5 text-sky-400/70" />;
244
- case "slow":
245
- return <Clock className="size-3.5 text-amber-400" />;
246
- case "failure":
247
- return <XCircle className="size-3.5 text-destructive" />;
248
- case "candidate":
249
- return <Brain className="size-3.5 text-emerald-400" />;
250
- }
251
- }
252
-
253
- function TraceInsights({ insights }: { insights: TraceInsight[] }): JSX.Element | null {
254
- if (insights.length === 0) return null;
255
- return (
256
- <div className="mt-2 grid gap-1.5 border-t border-border/70 pt-2 md:grid-cols-2 xl:grid-cols-3">
257
- {insights.map((insight) => (
258
- <button
259
- key={`${insight.kind}-${insight.title}`}
260
- type="button"
261
- className={cn(
262
- "flex min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",
263
- "text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground",
264
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
265
- )}
266
- onClick={() => {
267
- if (insight.logId !== null) jumpToLog(insight.logId);
268
- }}
269
- disabled={insight.logId === null}
270
- >
271
- {insightIcon(insight.kind)}
272
- <span className="min-w-0">
273
- <span className="block truncate font-medium text-foreground/90">{insight.title}</span>
274
- <span className="block truncate font-mono text-[10px]">{insight.detail}</span>
275
- </span>
276
- </button>
277
- ))}
278
- </div>
279
- );
280
- }
281
-
282
- function candidateStatusLabel(status: KnowledgeCandidateStatus): string {
283
- switch (status) {
284
- case "draft":
285
- return "Draft";
286
- case "promoted":
287
- return "Promoted";
288
- case "failed":
289
- return "Failed";
290
- }
291
- }
292
-
293
- function candidatePromoteLabel(candidate: KnowledgeCandidate, promoting: boolean): string {
294
- if (promoting) return "Promoting";
295
- switch (candidate.status) {
296
- case "draft":
297
- return "Promote";
298
- case "failed":
299
- return "Retry";
300
- case "promoted":
301
- return "Promoted";
302
- }
303
- }
304
-
305
- function redactionLabel(candidate: KnowledgeCandidate): string {
306
- if (!candidate.redaction.redacted) return "No sensitive pattern matched";
307
- return `Redacted ${candidate.redaction.patterns.join(", ")}`;
308
- }
309
-
310
- function previewText(value: string, maxLength: number): string {
311
- const normalized = value.replace(/\s+/g, " ").trim();
312
- if (normalized.length <= maxLength) return normalized;
313
- return `${normalized.slice(0, maxLength - 3)}...`;
314
- }
315
-
316
- function logRangeLabel(
317
- logIds: number[],
318
- displayNumberByLogId: ReadonlyMap<number, number>,
319
- ): string {
320
- const first = logIds[0];
321
- const last = logIds[logIds.length - 1];
322
- if (first === undefined) return "No evidence logs";
323
- const firstLabel = displayLogNumber(first, displayNumberByLogId);
324
- if (last === undefined || first === last) return `#${firstLabel}`;
325
- return `#${firstLabel}-#${displayLogNumber(last, displayNumberByLogId)}`;
326
- }
327
-
328
- function tagsToText(tags: string[]): string {
329
- return tags.join(", ");
330
- }
331
-
332
- function textToTags(value: string): string[] {
333
- return value
334
- .split(",")
335
- .map((tag) => tag.trim())
336
- .filter((tag) => tag.length > 0);
337
- }
338
-
339
- function CandidateItem({
340
- candidate,
341
- isPromoting,
342
- isUpdating,
343
- onPromoteCandidate,
344
- onUpdateCandidate,
345
- displayNumberByLogId,
346
- }: {
347
- candidate: KnowledgeCandidate;
348
- isPromoting: boolean;
349
- isUpdating: boolean;
350
- onPromoteCandidate: (candidateId: string) => void;
351
- onUpdateCandidate: (candidateId: string, update: CandidateDraftUpdate) => Promise<boolean>;
352
- displayNumberByLogId: ReadonlyMap<number, number>;
353
- }): JSX.Element {
354
- const [editing, setEditing] = useState(false);
355
- const [draftType, setDraftType] = useState<KnowledgeCandidate["type"]>(candidate.type);
356
- const [draftTitle, setDraftTitle] = useState(candidate.title);
357
- const [draftContent, setDraftContent] = useState(candidate.content);
358
- const [draftTags, setDraftTags] = useState(tagsToText(candidate.tags));
359
- const [localError, setLocalError] = useState<string | null>(null);
360
- const canPromote = candidate.status !== "promoted";
361
- const canEdit = candidate.status !== "promoted";
362
-
363
- const resetDraft = useCallback(() => {
364
- setDraftType(candidate.type);
365
- setDraftTitle(candidate.title);
366
- setDraftContent(candidate.content);
367
- setDraftTags(tagsToText(candidate.tags));
368
- setLocalError(null);
369
- }, [candidate.content, candidate.tags, candidate.title, candidate.type]);
370
-
371
- const saveDraft = useCallback(async () => {
372
- const title = draftTitle.trim();
373
- const content = draftContent.trim();
374
- const tags = textToTags(draftTags);
375
- if (title.length === 0) {
376
- setLocalError("Title is required.");
377
- return;
378
- }
379
- if (content.length === 0) {
380
- setLocalError("Content is required.");
381
- return;
382
- }
383
- if (tags.length === 0) {
384
- setLocalError("At least one tag is required.");
385
- return;
386
- }
387
- setLocalError(null);
388
- const saved = await onUpdateCandidate(candidate.id, {
389
- type: draftType,
390
- title,
391
- content,
392
- tags,
393
- });
394
- if (saved) setEditing(false);
395
- }, [candidate.id, draftContent, draftTags, draftTitle, draftType, onUpdateCandidate]);
396
-
397
- if (editing) {
398
- return (
399
- <div className="border border-border bg-card shadow-sm rounded-[8px] px-2.5 py-2">
400
- <div className="grid gap-2">
401
- <div className="flex flex-wrap items-center gap-2">
402
- <select
403
- value={draftType}
404
- disabled={isUpdating}
405
- onChange={(event) => {
406
- const parsed = KnowledgeCandidateSchema.shape.type.safeParse(
407
- event.currentTarget.value,
408
- );
409
- if (parsed.success) setDraftType(parsed.data);
410
- }}
411
- className="border border-input bg-background hover:bg-accent hover:text-accent-foreground h-7 rounded-md px-2 text-xs"
412
- aria-label="Candidate type"
413
- >
414
- <option value="episode">episode</option>
415
- <option value="procedure">procedure</option>
416
- <option value="preference">preference</option>
417
- <option value="project-fact">project-fact</option>
418
- </select>
419
- <input
420
- value={draftTitle}
421
- disabled={isUpdating}
422
- onChange={(event) => setDraftTitle(event.currentTarget.value)}
423
- className="border border-input bg-background hover:bg-accent hover:text-accent-foreground h-7 min-w-[220px] flex-1 rounded-md px-2 text-xs"
424
- aria-label="Candidate title"
425
- />
426
- </div>
427
- <textarea
428
- value={draftContent}
429
- disabled={isUpdating}
430
- onChange={(event) => setDraftContent(event.currentTarget.value)}
431
- className="border border-input bg-background hover:bg-accent hover:text-accent-foreground min-h-28 rounded-md px-2 py-1.5 font-mono text-[11px] leading-relaxed"
432
- aria-label="Candidate content"
433
- />
434
- <input
435
- value={draftTags}
436
- disabled={isUpdating}
437
- onChange={(event) => setDraftTags(event.currentTarget.value)}
438
- className="border border-input bg-background hover:bg-accent hover:text-accent-foreground h-7 rounded-md px-2 text-xs"
439
- aria-label="Candidate tags"
440
- />
441
- <div className="flex flex-wrap items-center gap-2">
442
- <span className="inline-flex items-center gap-1 text-[10px] text-muted-foreground">
443
- <ShieldCheck className="size-3" />
444
- Saving reruns Inspector redaction before promotion.
445
- </span>
446
- <span className="flex-1" />
447
- {localError !== null && (
448
- <span className="text-[10px] text-destructive">{localError}</span>
449
- )}
450
- <Button
451
- type="button"
452
- variant="ghost"
453
- size="sm"
454
- className="h-7 gap-1.5 px-2 text-xs"
455
- disabled={isUpdating}
456
- onClick={() => {
457
- resetDraft();
458
- setEditing(false);
459
- }}
460
- >
461
- <X className="size-3.5" />
462
- Cancel
463
- </Button>
464
- <Button
465
- type="button"
466
- variant="outline"
467
- size="sm"
468
- className="h-7 gap-1.5 px-2 text-xs"
469
- disabled={isUpdating}
470
- onClick={() => {
471
- void saveDraft();
472
- }}
473
- >
474
- {isUpdating ? (
475
- <RefreshCw className="size-3.5 animate-spin" />
476
- ) : (
477
- <Save className="size-3.5" />
478
- )}
479
- Save
480
- </Button>
481
- </div>
482
- </div>
483
- </div>
484
- );
485
- }
486
-
487
- return (
488
- <div className="rounded-md border border-border/80 bg-background/60 px-2.5 py-2">
489
- <div className="flex min-w-0 items-center gap-2">
490
- <Badge variant="outline" className="h-5 px-1.5 text-[10px] font-mono">
491
- {candidate.type}
492
- </Badge>
493
- <span className="min-w-0 flex-1 truncate text-xs font-medium" title={candidate.title}>
494
- {candidate.title}
495
- </span>
496
- <Badge
497
- variant="outline"
498
- className={cn(
499
- "h-5 shrink-0 px-1.5 text-[10px] font-mono",
500
- CANDIDATE_STATUS_CLASSES[candidate.status],
501
- )}
502
- >
503
- {candidateStatusLabel(candidate.status)}
504
- </Badge>
505
- </div>
506
- <p
507
- className="mt-1 text-[11px] leading-relaxed text-muted-foreground"
508
- title={candidate.content}
509
- >
510
- {previewText(candidate.content, 360)}
511
- </p>
512
- <div className="mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground">
513
- <span className="inline-flex items-center gap-1">
514
- <FileSearch className="size-3" />
515
- {logRangeLabel(candidate.logIds, displayNumberByLogId)}
516
- </span>
517
- <span className="inline-flex items-center gap-1">
518
- <ShieldCheck className="size-3" />
519
- {redactionLabel(candidate)}
520
- </span>
521
- {candidate.status === "promoted" && (
522
- <span className="inline-flex items-center gap-1 text-emerald-500">
523
- <CircleCheck className="size-3" />
524
- {candidate.openClawMemoryId ?? "OpenClaw"}
525
- </span>
526
- )}
527
- {candidate.status === "failed" && candidate.error !== null && (
528
- <span className="inline-flex items-center gap-1 text-destructive">
529
- <XCircle className="size-3" />
530
- {candidate.error}
531
- </span>
532
- )}
533
- </div>
534
- <div className="mt-1 flex flex-wrap items-center gap-1.5">
535
- {candidate.logIds.map((logId) => {
536
- const displayNumber = displayLogNumber(logId, displayNumberByLogId);
537
- return (
538
- <a
539
- key={logId}
540
- href={`#${getLogAnchor(logId)}`}
541
- onClick={(event) => {
542
- event.preventDefault();
543
- jumpToLog(logId);
544
- }}
545
- className="rounded border border-blue-400/25 px-1.5 py-0.5 font-mono text-[10px] text-blue-400 underline-offset-2 transition-colors hover:bg-blue-400/10 hover:text-blue-300 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
546
- aria-label={`Jump to evidence log ${displayNumber}`}
547
- title={`Log ID ${String(logId)}`}
548
- >
549
- #{displayNumber}
550
- </a>
551
- );
552
- })}
553
- <span className="flex-1" />
554
- {canEdit && (
555
- <Button
556
- type="button"
557
- variant="ghost"
558
- size="sm"
559
- className="h-6 gap-1.5 px-2 text-[10px]"
560
- disabled={isUpdating || isPromoting}
561
- onClick={() => setEditing(true)}
562
- >
563
- <Pencil className="size-3" />
564
- Review
565
- </Button>
566
- )}
567
- <Button
568
- type="button"
569
- variant={canPromote ? "outline" : "ghost"}
570
- size="sm"
571
- className="h-6 gap-1.5 px-2 text-[10px]"
572
- onClick={() => onPromoteCandidate(candidate.id)}
573
- disabled={!canPromote || isPromoting || isUpdating}
574
- >
575
- {isPromoting ? (
576
- <RefreshCw className="size-3 animate-spin" />
577
- ) : canPromote ? (
578
- <UploadCloud className="size-3" />
579
- ) : (
580
- <CircleCheck className="size-3" />
581
- )}
582
- {candidatePromoteLabel(candidate, isPromoting)}
583
- </Button>
584
- </div>
585
- </div>
586
- );
587
- }
588
-
589
- function CandidateList({
590
- candidates,
591
- promotingCandidateIds,
592
- updatingCandidateIds,
593
- onPromoteCandidate,
594
- onUpdateCandidate,
595
- displayNumberByLogId,
596
- }: {
597
- candidates: KnowledgeCandidate[];
598
- promotingCandidateIds: ReadonlySet<string>;
599
- updatingCandidateIds: ReadonlySet<string>;
600
- onPromoteCandidate: (candidateId: string) => void;
601
- onUpdateCandidate: (candidateId: string, update: CandidateDraftUpdate) => Promise<boolean>;
602
- displayNumberByLogId: ReadonlyMap<number, number>;
603
- }): JSX.Element | null {
604
- if (candidates.length === 0) return null;
605
- return (
606
- <div className="mt-2 grid gap-1.5">
607
- {candidates.map((candidate) => (
608
- <CandidateItem
609
- key={candidate.id}
610
- candidate={candidate}
611
- isPromoting={promotingCandidateIds.has(candidate.id)}
612
- isUpdating={updatingCandidateIds.has(candidate.id)}
613
- onPromoteCandidate={onPromoteCandidate}
614
- onUpdateCandidate={onUpdateCandidate}
615
- displayNumberByLogId={displayNumberByLogId}
616
- />
617
- ))}
618
- </div>
619
- );
620
- }
621
-
622
- export function AgentTraceSummary({
623
- logs,
624
- scopeId,
625
- slowResponseThresholdSeconds,
626
- showRollupMetrics,
627
- timeDisplayFormat,
628
- }: AgentTraceSummaryProps): JSX.Element | null {
629
- const [candidates, setCandidates] = useState<KnowledgeCandidate[]>([]);
630
- const [candidatesExpanded, setCandidatesExpanded] = useState(true);
631
- const [candidateState, setCandidateState] = useState<CandidateLoadState>({
632
- status: "idle",
633
- error: null,
634
- });
635
- const [promotingCandidateIds, setPromotingCandidateIds] = useState<ReadonlySet<string>>(
636
- () => new Set(),
637
- );
638
- const [updatingCandidateIds, setUpdatingCandidateIds] = useState<ReadonlySet<string>>(
639
- () => new Set(),
640
- );
641
- const hasCandidates = candidates.length > 0;
642
- const summary = useMemo(
643
- () => buildTraceSummary(logs, slowResponseThresholdSeconds, candidates.length),
644
- [candidates.length, logs, slowResponseThresholdSeconds],
645
- );
646
- const displayNumberByLogId = useMemo(() => buildDisplayNumberByLogId(logs), [logs]);
647
- const traceInsights = useMemo(
648
- () => buildTraceInsights({ logs, scopeId, summary, candidates, displayNumberByLogId }),
649
- [candidates, displayNumberByLogId, logs, scopeId, summary],
650
- );
651
- const showElapsedSummary = showRollupMetrics || summary.maxElapsedMs !== null;
652
- const timeRange = useMemo(
653
- () => formatTimeRange(summary.startedAt, summary.endedAt, timeDisplayFormat),
654
- [summary.endedAt, summary.startedAt, timeDisplayFormat],
655
- );
656
-
657
- const createCandidates = useCallback(() => {
658
- if (logs.length === 0 || candidateState.status === "loading") return;
659
- setCandidateState({ status: "loading", error: null });
660
- void (async () => {
661
- try {
662
- const parsed = await fetchJsonWithTimeout(
663
- `/api/knowledge/sessions/${encodeURIComponent(scopeId)}/candidates`,
664
- CandidateResponseSchema,
665
- CANDIDATE_GENERATE_TIMEOUT_MS,
666
- { method: "POST" },
667
- (response) => `Candidate generation failed with ${String(response.status)}`,
668
- );
669
- setCandidates(parsed.candidates);
670
- setCandidatesExpanded(parsed.candidates.length > 0);
671
- setCandidateState(
672
- parsed.candidates.length > 0
673
- ? { status: "ready", error: null }
674
- : { status: "failed", error: "No candidate was generated for this trace scope." },
675
- );
676
- } catch (error) {
677
- setCandidateState({
678
- status: "failed",
679
- error: error instanceof Error ? error.message : "Candidate response was invalid",
680
- });
681
- }
682
- })();
683
- }, [candidateState.status, logs.length, scopeId]);
684
-
685
- const promoteCandidate = useCallback((candidateId: string) => {
686
- setPromotingCandidateIds((current) => {
687
- if (current.has(candidateId)) return current;
688
- const next = new Set(current);
689
- next.add(candidateId);
690
- return next;
691
- });
692
-
693
- void (async () => {
694
- try {
695
- const response = await fetchWithTimeout(
696
- `/api/knowledge/candidates/${encodeURIComponent(candidateId)}/promote`,
697
- CANDIDATE_PROMOTE_TIMEOUT_MS,
698
- { method: "POST" },
699
- );
700
- const raw: unknown = await response.json().catch(() => null);
701
- const parsed = CandidatePromotionResponseSchema.safeParse(raw);
702
- if (response.ok && parsed.success) {
703
- setCandidates((current) =>
704
- current.map((candidate) =>
705
- candidate.id === parsed.data.candidate.id ? parsed.data.candidate : candidate,
706
- ),
707
- );
708
- setCandidateState({ status: "ready", error: null });
709
- return;
710
- }
711
-
712
- const failure = CandidatePromotionFailureResponseSchema.safeParse(raw);
713
- if (failure.success && failure.data.candidate !== undefined) {
714
- setCandidates((current) =>
715
- current.map((candidate) =>
716
- candidate.id === failure.data.candidate?.id ? failure.data.candidate : candidate,
717
- ),
718
- );
719
- }
720
- setCandidateState({
721
- status: "failed",
722
- error: failure.success
723
- ? (failure.data.error ?? "Candidate promotion failed")
724
- : `Candidate promotion failed with ${String(response.status)}`,
725
- });
726
- } catch (error) {
727
- setCandidateState({
728
- status: "failed",
729
- error: error instanceof Error ? error.message : "Candidate promotion failed",
730
- });
731
- } finally {
732
- setPromotingCandidateIds((current) => {
733
- const next = new Set(current);
734
- next.delete(candidateId);
735
- return next;
736
- });
737
- }
738
- })();
739
- }, []);
740
-
741
- const updateCandidate = useCallback(
742
- async (candidateId: string, update: CandidateDraftUpdate): Promise<boolean> => {
743
- setUpdatingCandidateIds((current) => {
744
- if (current.has(candidateId)) return current;
745
- const next = new Set(current);
746
- next.add(candidateId);
747
- return next;
748
- });
749
-
750
- try {
751
- const parsed = await fetchJsonWithTimeout(
752
- `/api/knowledge/candidates/${encodeURIComponent(candidateId)}`,
753
- CandidateUpdateResponseSchema,
754
- CANDIDATE_UPDATE_TIMEOUT_MS,
755
- {
756
- method: "PATCH",
757
- headers: { "Content-Type": "application/json" },
758
- body: JSON.stringify(update),
759
- },
760
- (response) => `Candidate update failed with ${String(response.status)}`,
761
- );
762
- setCandidates((current) =>
763
- current.map((candidate) =>
764
- candidate.id === parsed.candidate.id ? parsed.candidate : candidate,
765
- ),
766
- );
767
- setCandidateState({ status: "ready", error: null });
768
- return true;
769
- } catch (error) {
770
- setCandidateState({
771
- status: "failed",
772
- error: error instanceof Error ? error.message : "Candidate update failed",
773
- });
774
- return false;
775
- } finally {
776
- setUpdatingCandidateIds((current) => {
777
- const next = new Set(current);
778
- next.delete(candidateId);
779
- return next;
780
- });
781
- }
782
- },
783
- [],
784
- );
785
-
786
- if (logs.length === 0) return null;
787
-
788
- return (
789
- <section className="border border-border bg-card shadow-sm mb-2 rounded-[8px] px-3 py-2">
790
- <div className="flex flex-wrap items-center gap-x-3 gap-y-2 text-xs">
791
- {showRollupMetrics && (
792
- <span className="inline-flex items-center gap-1.5 font-semibold text-foreground">
793
- <MessageSquare className="size-3.5 text-blue-400" />
794
- {summary.llmCallCount} LLM
795
- </span>
796
- )}
797
- <span className="inline-flex items-center gap-1.5 text-muted-foreground">
798
- <Wrench className="size-3.5 text-sky-400/70" />
799
- {summary.toolCallCount} tools
800
- </span>
801
- {showRollupMetrics && (
802
- <span className="inline-flex items-center gap-1.5 text-muted-foreground">
803
- <Zap className="size-3.5 text-emerald-400" />
804
- <span className="font-mono">
805
- {formatTokens(summary.totalInputTokens)} / {formatTokens(summary.totalOutputTokens)}
806
- </span>
807
- </span>
808
- )}
809
- {(summary.totalCacheCreationInputTokens > 0 || summary.totalCacheReadInputTokens > 0) && (
810
- <span className="inline-flex items-center gap-1.5 text-muted-foreground">
811
- <Zap className="size-3.5 text-purple-400" />
812
- <span className="font-mono">
813
- KV Cache +{formatTokens(summary.totalCacheCreationInputTokens)} / ~
814
- {formatTokens(summary.totalCacheReadInputTokens)}
815
- </span>
816
- </span>
817
- )}
818
- {showElapsedSummary && (
819
- <span className="inline-flex items-center gap-1.5 text-muted-foreground">
820
- <Clock className="size-3.5" />
821
- {showRollupMetrics && (
822
- <span className="font-mono">{formatElapsed(summary.totalElapsedMs)}</span>
823
- )}
824
- {summary.maxElapsedMs !== null && (
825
- <span className="font-mono text-muted-foreground/70">
826
- max {formatElapsed(summary.maxElapsedMs)}
827
- </span>
828
- )}
829
- </span>
830
- )}
831
- {showRollupMetrics && timeRange !== null && (
832
- <span className="font-mono text-muted-foreground/70">{timeRange}</span>
833
- )}
834
- {(summary.failedCallCount > 0 ||
835
- summary.pendingCallCount > 0 ||
836
- summary.slowCallCount > 0) && (
837
- <span className="inline-flex items-center gap-1.5 text-amber-400">
838
- <AlertTriangle className="size-3.5" />
839
- <span className="font-mono">
840
- {summary.failedCallCount} fail / {summary.pendingCallCount} pending /{" "}
841
- {summary.slowCallCount} slow
842
- </span>
843
- </span>
844
- )}
845
- <span className="flex-1" />
846
- {hasCandidates && (
847
- <Badge variant="outline" className="h-6 px-2 text-[10px] font-mono">
848
- {formatCandidateCount(summary.knowledgeCandidateCount)}
849
- </Badge>
850
- )}
851
- <Button
852
- type="button"
853
- variant="outline"
854
- size="sm"
855
- className="h-7 gap-1.5 px-2 text-xs"
856
- onClick={createCandidates}
857
- disabled={candidateState.status === "loading"}
858
- >
859
- {candidateState.status === "loading" ? (
860
- <Loader2 className="size-3.5 animate-spin" />
861
- ) : (
862
- <Brain className="size-3.5" />
863
- )}
864
- Candidate
865
- </Button>
866
- {hasCandidates && (
867
- <Button
868
- type="button"
869
- variant="ghost"
870
- size="icon"
871
- className="size-7 text-muted-foreground"
872
- onClick={() => setCandidatesExpanded((value) => !value)}
873
- aria-expanded={candidatesExpanded}
874
- aria-label={
875
- candidatesExpanded ? "Collapse memory candidates" : "Expand memory candidates"
876
- }
877
- >
878
- {candidatesExpanded ? (
879
- <ChevronDown className="size-3.5" />
880
- ) : (
881
- <ChevronRight className="size-3.5" />
882
- )}
883
- </Button>
884
- )}
885
- </div>
886
- {candidateState.status === "failed" && (
887
- <p className="mt-2 text-xs text-destructive">{candidateState.error}</p>
888
- )}
889
- <TraceInsights insights={traceInsights} />
890
- {candidatesExpanded && (
891
- <CandidateList
892
- candidates={candidates}
893
- promotingCandidateIds={promotingCandidateIds}
894
- updatingCandidateIds={updatingCandidateIds}
895
- onPromoteCandidate={promoteCandidate}
896
- onUpdateCandidate={updateCandidate}
897
- displayNumberByLogId={displayNumberByLogId}
898
- />
899
- )}
900
- </section>
901
- );
902
- }