@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 +1 @@
1
- import{r as l,H as D,j as s,B as y,o as U,n as j,a as ae,F as le,b as L,s as H}from"./index-B__qT0Yd.js";import{c as oe,u as ie,D as de,i as ue,j as ce,k as pe,l as A,T as R,m as N,n as d,o as u,p as me,q as xe,s as fe,t as he,v as ye,w as je,x as be}from"./ProxyViewerContainer-Buu8vkCK.js";import{ResponseView as O}from"./ResponseView-DDpKdYk6.js";const ge=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Te=oe("braces",ge);function W(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ve(e){return e==null?null:new TextEncoder().encode(e).length}function Re(e){try{const t=JSON.parse(e);if(!W(t))return null;const a=t.model;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function Ne(e,t){try{const a=JSON.parse(e);return W(a)?{body:JSON.stringify({...a,model:t},null,2),error:null}:{body:e,error:"Request body must be a JSON object."}}catch{return{body:e,error:"Request body must be valid JSON before changing the replay model."}}}function V(e){return{status:e.status??null,elapsedMs:e.elapsedMs??null,inputTokens:e.inputTokens??null,outputTokens:e.outputTokens??null,responseBytes:ve(e.responseText),streaming:e.streaming===!0}}function g(e,t){return e===null||t===null?null:t-e}function ke(e,t){return[{id:"status",label:"Status",original:e.status,replay:t.status,delta:g(e.status,t.status)},{id:"elapsed",label:"Elapsed",original:e.elapsedMs,replay:t.elapsedMs,delta:g(e.elapsedMs,t.elapsedMs)},{id:"input",label:"Input",original:e.inputTokens,replay:t.inputTokens,delta:g(e.inputTokens,t.inputTokens)},{id:"output",label:"Output",original:e.outputTokens,replay:t.outputTokens,delta:g(e.outputTokens,t.outputTokens)},{id:"bytes",label:"Bytes",original:e.responseBytes,replay:t.responseBytes,delta:g(e.responseBytes,t.responseBytes)},{id:"streaming",label:"Stream",original:e.streaming,replay:t.streaming,delta:null}]}const Se=U({success:L(),error:H().optional(),responseStatus:j().nullable().optional(),responseText:H().nullable().optional(),inputTokens:j().nullable().optional(),outputTokens:j().nullable().optional(),elapsedMs:j().nullable().optional(),streaming:L().optional(),replayLogId:j().optional()}),we=U({logs:ae(be),total:j()}),Me=6e4,Ce=1e4;function k(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function Oe(e){try{const t=JSON.parse(e);return JSON.stringify(t)}catch{return e}}function Ee(e){try{return JSON.parse(e),{valid:!0,message:"Valid JSON"}}catch(t){return{valid:!1,message:t instanceof Error?t.message:"Invalid JSON"}}}function E(e){return e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`}function P(e,t){if(e===null)return"-";if(typeof e=="boolean")return e?"stream":"non-stream";switch(t){case"elapsed":return E(e);case"input":case"output":case"bytes":return e.toLocaleString();case"status":return String(e);case"streaming":return e?"stream":"non-stream"}}function Je(e,t){if(e===null)return"-";const a=e>0?"+":"";switch(t){case"elapsed":return`${a}${E(e)}`;case"input":case"output":case"bytes":case"status":return`${a}${e.toLocaleString()}`;case"streaming":return"-"}}function Be(e){return e===null||e===0?"text-muted-foreground":e>0?"text-amber-400":"text-emerald-400"}function Y({comparisons:e}){return s.jsxs("div",{className:"overflow-hidden rounded-md border border-border",children:[s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] bg-muted/40 px-3 py-2 text-[11px] font-medium text-muted-foreground",children:[s.jsx("span",{children:"Metric"}),s.jsx("span",{children:"Original"}),s.jsx("span",{children:"Replay"}),s.jsx("span",{children:"Delta"})]}),e.map(t=>s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] border-t border-border px-3 py-2 text-xs",children:[s.jsx("span",{className:"text-muted-foreground",children:t.label}),s.jsx("span",{className:"font-mono",children:P(t.original,t.id)}),s.jsx("span",{className:"font-mono",children:P(t.replay,t.id)}),s.jsx("span",{className:`font-mono ${Be(t.delta)}`,children:Je(t.delta,t.id)})]},t.id))]})}function Ie({log:e,displayNumber:t,open:a,onOpenChange:J}){const{providers:B}=ie(),$=e.rawRequestBody??"{}",[c,G]=l.useState(()=>k($)),[r,T]=l.useState(null),[K,Q]=l.useState([]),[q,S]=l.useState(!1),[w,p]=l.useState(null),m=l.useRef(null),x=l.useRef(0),f=l.useMemo(()=>Ee(c),[c]),M=l.useCallback(()=>{x.current+=1,m.current?.abort(),m.current=null,S(!1)},[]),v=l.useCallback(async()=>{if(a)try{const n=await D(`/api/logs?replayOf=${String(e.id)}`,we,Ce);Q(n.logs)}catch{}},[e.id,a]);l.useEffect(()=>{v()},[v]),l.useEffect(()=>{a||M()},[M,a]),l.useEffect(()=>()=>{x.current+=1,m.current?.abort(),m.current=null},[]);async function X(){if(!f.valid){p("Request body must be valid JSON before replay.");return}m.current?.abort();const n=x.current+1;x.current=n;const i=new AbortController;m.current=i,S(!0),p(null),T(null);try{const o=await D(`/api/logs/${e.id}/replay`,Se,Me,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modifiedBody:c}),signal:i.signal});if(x.current!==n)return;T(o),await v(),o.success||p(o.error??"Replay failed")}catch(o){if(x.current!==n)return;if(o instanceof le||o instanceof DOMException&&o.name==="AbortError"){p("Replay timed out or was canceled.");return}p(o instanceof Error?o.message:"Network error")}finally{x.current===n&&(m.current=null,S(!1))}}function Z(){M(),T(null),p(null),J(!1)}function b(n){G(n),T(null),p(null)}function ee(){b(k(c))}function se(){b(Oe(c))}function te(){b(k($))}function F(n){window.location.hash=`log-${String(n)}`,je({logId:n,tab:"request"}),J(!1)}const C=l.useMemo(()=>{const n=[];for(const i of B)for(const o of i.models)o.trim().length!==0&&n.push({key:`${i.id}:${o}`,providerName:i.name,model:o});return n},[B]),h=Re(c)??e.model??"";function ne(n){const i=Ne(c,n);if(i.error!==null){p(i.error);return}b(k(i.body))}const re=V({status:e.responseStatus,elapsedMs:e.elapsedMs,inputTokens:e.inputTokens,outputTokens:e.outputTokens,responseText:e.responseText,streaming:e.streaming}),I=r===null?null:V({status:r.responseStatus,elapsedMs:r.elapsedMs,inputTokens:r.inputTokens,outputTokens:r.outputTokens,responseText:r.responseText,streaming:r.streaming}),_=I===null?[]:ke(re,I),z=K.slice(-5).reverse();return s.jsx(de,{open:a,onOpenChange:Z,children:s.jsxs(ue,{className:"max-w-4xl max-h-[85vh] overflow-auto",children:[s.jsx(ce,{children:s.jsxs(pe,{className:"flex items-center gap-2",children:[s.jsx(A,{className:"size-4"}),s.jsxs("span",{title:`Log ID ${String(e.id)}`,children:["Replay Request #",t]})]})}),s.jsxs(R,{defaultValue:"modified",children:[s.jsxs(N,{children:[s.jsx(d,{value:"modified",children:"Modified Request"}),s.jsx(d,{value:"original",children:"Original Response"}),r&&s.jsx(d,{value:"replay",children:"Replay Response"}),r&&s.jsx(d,{value:"compare",children:"Compare"})]}),s.jsxs(u,{value:"modified",className:"space-y-4",children:[C.length>0&&s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:`replay-model-${String(e.id)}`,className:"text-sm font-medium",children:"Replay target"}),s.jsxs("select",{id:`replay-model-${String(e.id)}`,value:h,onChange:n=>ne(n.currentTarget.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[h===""&&s.jsx("option",{value:"",children:"Select model"}),h!==""&&!C.some(n=>n.model===h)&&s.jsx("option",{value:h,children:h}),C.map(n=>s.jsxs("option",{value:n.model,children:[n.providerName," / ",n.model]},n.key))]})]}),z.length>0&&s.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-muted/20 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"text-xs font-medium",children:"Replay history"}),s.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:()=>{v()},children:"Refresh"})]}),s.jsx("div",{className:"grid gap-1",children:z.map(n=>s.jsxs("button",{type:"button",onClick:()=>F(n.id),className:"grid grid-cols-[auto_1fr_auto_auto] items-center gap-2 rounded-sm px-2 py-1 text-left text-xs hover:bg-muted",children:[s.jsxs("span",{className:"font-mono text-emerald-600",children:["#",n.id]}),s.jsx("span",{className:"truncate font-mono text-muted-foreground",children:n.model??"unknown"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.responseStatus??"-"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.elapsedMs===null?"-":E(n.elapsedMs)})]},n.id))})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("label",{htmlFor:`replay-body-${String(e.id)}`,className:"text-sm font-medium",children:"Request Body"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:f.valid?"text-xs text-emerald-500":"text-xs text-destructive",children:f.message}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:ee,disabled:!f.valid,title:"Format JSON",children:[s.jsx(Te,{className:"size-3.5"}),"Format"]}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:se,disabled:!f.valid,title:"Compact JSON",children:[s.jsx(me,{className:"size-3.5"}),"Compact"]}),s.jsxs(y,{type:"button",variant:"ghost",size:"sm",onClick:te,title:"Reset to original request",children:[s.jsx(A,{className:"size-3.5"}),"Reset"]})]})]}),s.jsx(xe,{children:s.jsxs(fe,{children:[s.jsx(he,{asChild:!0,children:s.jsx("textarea",{id:`replay-body-${String(e.id)}`,className:"w-full min-h-80 p-3 font-mono text-xs leading-5 bg-muted rounded-md border border-input resize-y tabular-nums focus:outline-none focus:ring-2 focus:ring-ring",value:c,onChange:n=>b(n.target.value),spellCheck:!1})}),s.jsx(ye,{children:"Edit formatted JSON before re-sending to the provider"})]})})]}),w!==null&&w!==""&&s.jsx("div",{className:"text-sm text-destructive bg-destructive/10 px-3 py-2 rounded-md",children:w}),s.jsx("div",{className:"flex justify-end",children:s.jsx(y,{onClick:()=>{X()},disabled:q||!f.valid,children:q?"Replaying...":"Replay"})}),r!==null&&s.jsx(Y,{comparisons:_.slice(0,4)}),r?.success===!0&&r.replayLogId!==void 0&&s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-emerald-500/25 bg-emerald-500/10 px-3 py-2 text-xs text-emerald-600",children:[s.jsxs("span",{children:["Replay saved as test log #",r.replayLogId,"."]}),s.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>F(r.replayLogId??e.id),children:"Open saved log"})]}),r&&r.success&&s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??"No response"})})]})]}),s.jsx(u,{value:"original",children:e.responseText!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:e.responseText,responseStatus:e.responseStatus,streaming:e.streaming,inputTokens:e.inputTokens,outputTokens:e.outputTokens,cacheCreationInputTokens:e.cacheCreationInputTokens,cacheReadInputTokens:e.cacheReadInputTokens,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:e.responseText})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No original response"})}),r&&r.success&&s.jsx(u,{value:"replay",children:(r.responseText??null)!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??""})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No replay response"})}),r&&s.jsxs(u,{value:"compare",className:"space-y-3",children:[s.jsx(Y,{comparisons:_}),r.success?null:s.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:r.error??"Replay failed"})]})]})]})})}export{Ie as ReplayDialog};
1
+ import{r as l,H as D,j as s,B as y,o as U,n as j,a as ae,F as le,b as L,s as H}from"./index-B0TN1KKO.js";import{c as oe,u as ie,D as de,i as ue,j as ce,k as pe,l as A,T as R,m as N,n as d,o as u,p as me,q as xe,s as fe,t as he,v as ye,w as je,x as be}from"./ProxyViewerContainer-6twNZHwl.js";import{ResponseView as O}from"./ResponseView-BULgzLVB.js";const ge=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Te=oe("braces",ge);function W(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ve(e){return e==null?null:new TextEncoder().encode(e).length}function Re(e){try{const t=JSON.parse(e);if(!W(t))return null;const a=t.model;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function Ne(e,t){try{const a=JSON.parse(e);return W(a)?{body:JSON.stringify({...a,model:t},null,2),error:null}:{body:e,error:"Request body must be a JSON object."}}catch{return{body:e,error:"Request body must be valid JSON before changing the replay model."}}}function V(e){return{status:e.status??null,elapsedMs:e.elapsedMs??null,inputTokens:e.inputTokens??null,outputTokens:e.outputTokens??null,responseBytes:ve(e.responseText),streaming:e.streaming===!0}}function g(e,t){return e===null||t===null?null:t-e}function ke(e,t){return[{id:"status",label:"Status",original:e.status,replay:t.status,delta:g(e.status,t.status)},{id:"elapsed",label:"Elapsed",original:e.elapsedMs,replay:t.elapsedMs,delta:g(e.elapsedMs,t.elapsedMs)},{id:"input",label:"Input",original:e.inputTokens,replay:t.inputTokens,delta:g(e.inputTokens,t.inputTokens)},{id:"output",label:"Output",original:e.outputTokens,replay:t.outputTokens,delta:g(e.outputTokens,t.outputTokens)},{id:"bytes",label:"Bytes",original:e.responseBytes,replay:t.responseBytes,delta:g(e.responseBytes,t.responseBytes)},{id:"streaming",label:"Stream",original:e.streaming,replay:t.streaming,delta:null}]}const Se=U({success:L(),error:H().optional(),responseStatus:j().nullable().optional(),responseText:H().nullable().optional(),inputTokens:j().nullable().optional(),outputTokens:j().nullable().optional(),elapsedMs:j().nullable().optional(),streaming:L().optional(),replayLogId:j().optional()}),we=U({logs:ae(be),total:j()}),Me=6e4,Ce=1e4;function k(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function Oe(e){try{const t=JSON.parse(e);return JSON.stringify(t)}catch{return e}}function Ee(e){try{return JSON.parse(e),{valid:!0,message:"Valid JSON"}}catch(t){return{valid:!1,message:t instanceof Error?t.message:"Invalid JSON"}}}function E(e){return e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`}function P(e,t){if(e===null)return"-";if(typeof e=="boolean")return e?"stream":"non-stream";switch(t){case"elapsed":return E(e);case"input":case"output":case"bytes":return e.toLocaleString();case"status":return String(e);case"streaming":return e?"stream":"non-stream"}}function Je(e,t){if(e===null)return"-";const a=e>0?"+":"";switch(t){case"elapsed":return`${a}${E(e)}`;case"input":case"output":case"bytes":case"status":return`${a}${e.toLocaleString()}`;case"streaming":return"-"}}function Be(e){return e===null||e===0?"text-muted-foreground":e>0?"text-amber-400":"text-emerald-400"}function Y({comparisons:e}){return s.jsxs("div",{className:"overflow-hidden rounded-md border border-border",children:[s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] bg-muted/40 px-3 py-2 text-[11px] font-medium text-muted-foreground",children:[s.jsx("span",{children:"Metric"}),s.jsx("span",{children:"Original"}),s.jsx("span",{children:"Replay"}),s.jsx("span",{children:"Delta"})]}),e.map(t=>s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] border-t border-border px-3 py-2 text-xs",children:[s.jsx("span",{className:"text-muted-foreground",children:t.label}),s.jsx("span",{className:"font-mono",children:P(t.original,t.id)}),s.jsx("span",{className:"font-mono",children:P(t.replay,t.id)}),s.jsx("span",{className:`font-mono ${Be(t.delta)}`,children:Je(t.delta,t.id)})]},t.id))]})}function Ie({log:e,displayNumber:t,open:a,onOpenChange:J}){const{providers:B}=ie(),$=e.rawRequestBody??"{}",[c,G]=l.useState(()=>k($)),[r,T]=l.useState(null),[K,Q]=l.useState([]),[q,S]=l.useState(!1),[w,p]=l.useState(null),m=l.useRef(null),x=l.useRef(0),f=l.useMemo(()=>Ee(c),[c]),M=l.useCallback(()=>{x.current+=1,m.current?.abort(),m.current=null,S(!1)},[]),v=l.useCallback(async()=>{if(a)try{const n=await D(`/api/logs?replayOf=${String(e.id)}`,we,Ce);Q(n.logs)}catch{}},[e.id,a]);l.useEffect(()=>{v()},[v]),l.useEffect(()=>{a||M()},[M,a]),l.useEffect(()=>()=>{x.current+=1,m.current?.abort(),m.current=null},[]);async function X(){if(!f.valid){p("Request body must be valid JSON before replay.");return}m.current?.abort();const n=x.current+1;x.current=n;const i=new AbortController;m.current=i,S(!0),p(null),T(null);try{const o=await D(`/api/logs/${e.id}/replay`,Se,Me,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modifiedBody:c}),signal:i.signal});if(x.current!==n)return;T(o),await v(),o.success||p(o.error??"Replay failed")}catch(o){if(x.current!==n)return;if(o instanceof le||o instanceof DOMException&&o.name==="AbortError"){p("Replay timed out or was canceled.");return}p(o instanceof Error?o.message:"Network error")}finally{x.current===n&&(m.current=null,S(!1))}}function Z(){M(),T(null),p(null),J(!1)}function b(n){G(n),T(null),p(null)}function ee(){b(k(c))}function se(){b(Oe(c))}function te(){b(k($))}function F(n){window.location.hash=`log-${String(n)}`,je({logId:n,tab:"request"}),J(!1)}const C=l.useMemo(()=>{const n=[];for(const i of B)for(const o of i.models)o.trim().length!==0&&n.push({key:`${i.id}:${o}`,providerName:i.name,model:o});return n},[B]),h=Re(c)??e.model??"";function ne(n){const i=Ne(c,n);if(i.error!==null){p(i.error);return}b(k(i.body))}const re=V({status:e.responseStatus,elapsedMs:e.elapsedMs,inputTokens:e.inputTokens,outputTokens:e.outputTokens,responseText:e.responseText,streaming:e.streaming}),I=r===null?null:V({status:r.responseStatus,elapsedMs:r.elapsedMs,inputTokens:r.inputTokens,outputTokens:r.outputTokens,responseText:r.responseText,streaming:r.streaming}),_=I===null?[]:ke(re,I),z=K.slice(-5).reverse();return s.jsx(de,{open:a,onOpenChange:Z,children:s.jsxs(ue,{className:"max-w-4xl max-h-[85vh] overflow-auto",children:[s.jsx(ce,{children:s.jsxs(pe,{className:"flex items-center gap-2",children:[s.jsx(A,{className:"size-4"}),s.jsxs("span",{title:`Log ID ${String(e.id)}`,children:["Replay Request #",t]})]})}),s.jsxs(R,{defaultValue:"modified",children:[s.jsxs(N,{children:[s.jsx(d,{value:"modified",children:"Modified Request"}),s.jsx(d,{value:"original",children:"Original Response"}),r&&s.jsx(d,{value:"replay",children:"Replay Response"}),r&&s.jsx(d,{value:"compare",children:"Compare"})]}),s.jsxs(u,{value:"modified",className:"space-y-4",children:[C.length>0&&s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:`replay-model-${String(e.id)}`,className:"text-sm font-medium",children:"Replay target"}),s.jsxs("select",{id:`replay-model-${String(e.id)}`,value:h,onChange:n=>ne(n.currentTarget.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[h===""&&s.jsx("option",{value:"",children:"Select model"}),h!==""&&!C.some(n=>n.model===h)&&s.jsx("option",{value:h,children:h}),C.map(n=>s.jsxs("option",{value:n.model,children:[n.providerName," / ",n.model]},n.key))]})]}),z.length>0&&s.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-muted/20 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"text-xs font-medium",children:"Replay history"}),s.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:()=>{v()},children:"Refresh"})]}),s.jsx("div",{className:"grid gap-1",children:z.map(n=>s.jsxs("button",{type:"button",onClick:()=>F(n.id),className:"grid grid-cols-[auto_1fr_auto_auto] items-center gap-2 rounded-sm px-2 py-1 text-left text-xs hover:bg-muted",children:[s.jsxs("span",{className:"font-mono text-emerald-600",children:["#",n.id]}),s.jsx("span",{className:"truncate font-mono text-muted-foreground",children:n.model??"unknown"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.responseStatus??"-"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.elapsedMs===null?"-":E(n.elapsedMs)})]},n.id))})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("label",{htmlFor:`replay-body-${String(e.id)}`,className:"text-sm font-medium",children:"Request Body"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:f.valid?"text-xs text-emerald-500":"text-xs text-destructive",children:f.message}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:ee,disabled:!f.valid,title:"Format JSON",children:[s.jsx(Te,{className:"size-3.5"}),"Format"]}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:se,disabled:!f.valid,title:"Compact JSON",children:[s.jsx(me,{className:"size-3.5"}),"Compact"]}),s.jsxs(y,{type:"button",variant:"ghost",size:"sm",onClick:te,title:"Reset to original request",children:[s.jsx(A,{className:"size-3.5"}),"Reset"]})]})]}),s.jsx(xe,{children:s.jsxs(fe,{children:[s.jsx(he,{asChild:!0,children:s.jsx("textarea",{id:`replay-body-${String(e.id)}`,className:"w-full min-h-80 p-3 font-mono text-xs leading-5 bg-muted rounded-md border border-input resize-y tabular-nums focus:outline-none focus:ring-2 focus:ring-ring",value:c,onChange:n=>b(n.target.value),spellCheck:!1})}),s.jsx(ye,{children:"Edit formatted JSON before re-sending to the provider"})]})})]}),w!==null&&w!==""&&s.jsx("div",{className:"text-sm text-destructive bg-destructive/10 px-3 py-2 rounded-md",children:w}),s.jsx("div",{className:"flex justify-end",children:s.jsx(y,{onClick:()=>{X()},disabled:q||!f.valid,children:q?"Replaying...":"Replay"})}),r!==null&&s.jsx(Y,{comparisons:_.slice(0,4)}),r?.success===!0&&r.replayLogId!==void 0&&s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-emerald-500/25 bg-emerald-500/10 px-3 py-2 text-xs text-emerald-600",children:[s.jsxs("span",{children:["Replay saved as test log #",r.replayLogId,"."]}),s.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>F(r.replayLogId??e.id),children:"Open saved log"})]}),r&&r.success&&s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??"No response"})})]})]}),s.jsx(u,{value:"original",children:e.responseText!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:e.responseText,responseStatus:e.responseStatus,streaming:e.streaming,inputTokens:e.inputTokens,outputTokens:e.outputTokens,cacheCreationInputTokens:e.cacheCreationInputTokens,cacheReadInputTokens:e.cacheReadInputTokens,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:e.responseText})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No original response"})}),r&&r.success&&s.jsx(u,{value:"replay",children:(r.responseText??null)!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??""})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No replay response"})}),r&&s.jsxs(u,{value:"compare",className:"space-y-3",children:[s.jsx(Y,{comparisons:_}),r.success?null:s.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:r.error??"Replay failed"})]})]})]})})}export{Ie as ReplayDialog};
@@ -1 +1 @@
1
- import{r as f,C as u,j as t,x as p,I as B}from"./index-B__qT0Yd.js";import{u as F,y as q,q as V,s as J,t as Y,I as K,v as X,S as Q,z as $,A as Z,E as C,F as ee,e as z}from"./ProxyViewerContainer-Buu8vkCK.js";const te=.25,se=5,re=4,ne=6,oe=.25,ae=.2,ie=.2,le=["system","user","assistant","tool","tools"],de={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},ue=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}],ce={unknown:"bg-muted-foreground/50",ok:"bg-emerald-500/70",watch:"bg-amber-400/75",danger:"bg-red-500/80"},me={unknown:"text-muted-foreground",ok:"text-emerald-400",watch:"text-amber-300",danger:"text-red-300"},xe={ok:"border-emerald-400/30 bg-emerald-400/8 text-emerald-200",optimizable:"border-amber-400/30 bg-amber-400/8 text-amber-100",risk:"border-red-400/35 bg-red-500/10 text-red-100"},pe={ok:"OK",optimizable:"Optimizable",risk:"Risk"};function h(e){return e>=10?`${e.toFixed(0)}%`:e>=1?`${e.toFixed(1)}%`:e>0?"<1%":"0%"}function w(e){return e===null?"Unknown":h(e*100)}function L(e){return e===null?"Unknown":e<0?`-${u(Math.abs(e))}`:u(e)}function A(e){return e.contextWindow.tokens===null?"Unknown":B(e.contextWindow.tokens)}function fe(e){switch(e.contextWindow.source){case"request":return e.contextWindow.label;case"provider":return e.contextWindow.label;case"model-rule":return e.contextWindow.label;case"unknown":return e.model===null?e.contextWindow.label:`${e.contextWindow.label}: ${e.model}`}}function he(e){switch(e){case"watch":return"border-amber-400/30 bg-amber-400/8 text-amber-100";case"danger":return"border-red-400/35 bg-red-500/10 text-red-100"}}function _(e){const s=pe[e.level];if(e.level==="ok")return s;const r=e.level==="risk"?`${String(e.opportunityCount)} signal${e.opportunityCount===1?"":"s"}`:`${String(e.opportunityCount)} opportunit${e.opportunityCount===1?"y":"ies"}`;return e.reclaimableTokens<=0?`${s} | ${r}`:`${s} | ${r} | ~${u(e.reclaimableTokens)} tokens`}function ge({health:e}){return t.jsx("span",{className:p("inline-flex h-5 max-w-full items-center rounded border px-1.5 font-mono text-[10px]",xe[e.level]),"aria-label":`Context health ${_(e)}`,children:t.jsx("span",{className:"truncate",children:_(e)})})}function y(e,s){return e.roleUsages.find(r=>r.role===s)?.tokens??0}function O(e,s){return e.roleUsages.find(r=>r.role===s)?.percent??0}function S(e,s){if(e<=0)return null;const r=Math.round(e*s);return r>0?r:null}function I(e,s){return[...e].filter(r=>r.role===s).sort((r,n)=>n.size-r.size)[0]??null}function be(e){return[...e].filter(s=>s.role==="user"||s.role==="assistant"||s.role==="tool").sort((s,r)=>r.size-s.size)[0]??null}function ve(e,s){const r=e[0]??null;if(r===null)return null;const n=r.segments[0]??null;return n===null?null:P(n,s)}function je(e){const s=e.reduce((r,n)=>r+n.repeatedTokens,0);return s>0?s:null}function Ne(e){return y(e,"user")+y(e,"assistant")+y(e,"tool")}function ke({diagnostic:e,intelligence:s,segments:r}){switch(e.kind){case"duplicate":return{key:"duplicate",kind:"duplicate",severity:e.severity,title:"Duplicate content",impact:e.detail,action:"Remove repeated blocks or keep one canonical copy in the next request.",savingTokens:je(s.duplicateGroups),target:ve(s.duplicateGroups,r)};case"tool-schema":{const n=y(s,"tools"),l=O(s,"tools");return{key:"tool-schema",kind:"tool-schema",severity:e.severity,title:"Tool schema pressure",impact:`Tool definitions use ~${u(n)} tokens (${h(l*100)}).`,action:"Disable unused tools or shorten verbose schema descriptions.",savingTokens:S(n,oe),target:I(r,"tools")}}case"system-heavy":{const n=y(s,"system"),l=O(s,"system");return{key:"system-heavy",kind:"system-heavy",severity:e.severity,title:"Large system prompt",impact:`System instructions use ~${u(n)} tokens (${h(l*100)}).`,action:"Compress repeated policy text and move stable guidance into reusable memory.",savingTokens:S(n,ae),target:I(r,"system")}}case"history-bloat":{const n=Ne(s);return{key:"history-bloat",kind:"history-bloat",severity:e.severity,title:"Conversation history growth",impact:e.detail,action:"Summarize older turns and trim resolved tool outputs before continuing.",savingTokens:S(n,ie),target:be(r)}}}}function we({intelligence:e,segments:s}){const r=[];return(e.riskLevel==="watch"||e.riskLevel==="danger")&&r.push({key:"context-pressure",kind:"context-pressure",severity:e.riskLevel==="danger"?"danger":"watch",title:"Context window pressure",impact:`${w(e.usagePercent)} used, ${L(e.remainingAfterReserveTokens)} remaining after output reserve.`,action:"Start with the largest context block, then remove duplicates or summarize history.",savingTokens:null,target:[...s].sort((n,l)=>l.size-n.size)[0]??null}),e.contextWindow.source==="unknown"&&r.push({key:"context-window",kind:"context-window",severity:"watch",title:"Context window unknown",impact:"Agent Inspector cannot calculate remaining space for this model.",action:"Add model metadata in Provider settings so risk and remaining space are accurate.",savingTokens:null,target:null}),e.diagnostics.forEach(n=>{r.push(ke({diagnostic:n,intelligence:e,segments:s}))}),r}function ye({items:e,onSegmentActivate:s}){return e.length===0?null:t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Context Advisor"}),t.jsxs("div",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," issue",e.length===1?"":"s"]})]}),t.jsx("div",{className:"grid gap-2",children:e.map(r=>{const n=r.target,l=n!==null&&s!==void 0;return t.jsx("div",{className:p("rounded border px-2 py-1.5 text-xs",he(r.severity)),children:t.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium",children:r.title}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Impact: ",r.impact]}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Action: ",r.action]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.savingTokens!==null&&t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["Save ~",u(r.savingTokens)]}),l&&n!==null&&s!==void 0&&t.jsxs("button",{type:"button",onClick:()=>s(n),className:"inline-flex h-6 items-center gap-1 rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to the most relevant context block",children:[t.jsx(z,{className:"size-3"}),"Jump"]})]})]})},r.key)})})]})}function Te({intelligence:e,segments:s,onSegmentActivate:r}){const n=e.usagePercent===null?0:Math.max(1,e.usagePercent*100),l=e.outputReserveTokens===null?"No output reserve":`Output reserve ${u(e.outputReserveTokens)}`,c=e.largestRole,m=we({intelligence:e,segments:s});return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"grid gap-x-4 gap-y-2 border-y border-border/60 py-2 text-xs sm:grid-cols-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Window"}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-foreground",children:A(e)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:fe(e)})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Used"}),t.jsx("div",{className:p("mt-0.5 font-mono",me[e.riskLevel]),children:w(e.usagePercent)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:l})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Remaining"}),t.jsx("div",{className:"mt-0.5 font-mono text-foreground",children:L(e.remainingAfterReserveTokens)}),t.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:["Input only ",L(e.remainingInputTokens)]})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Largest"}),c===null?t.jsx("div",{className:"mt-0.5 text-muted-foreground",children:"Unknown"}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[c.role])}),t.jsx("span",{className:"truncate text-foreground",children:c.label})]}),t.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[h(c.percent*100)," | ~",u(c.tokens)]})]})]})]}),e.contextWindow.tokens!==null&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted/40",children:[t.jsx("div",{className:p("h-full rounded-full",ce[e.riskLevel]),style:{width:`${String(n)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-amber-200/70",style:{left:`${String(C.watch*100)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-red-200/80",style:{left:`${String(C.danger*100)}%`}})]}),t.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[t.jsx("span",{children:"Context window"}),t.jsxs("span",{children:["Watch ",w(C.watch)," / Danger"," ",w(C.danger)]})]})]}),t.jsx(ye,{items:m,onSegmentActivate:r})]})}function P(e,s){return s.find(r=>r.path===e.path)??null}function Ce({groups:e,segments:s,onSegmentActivate:r}){const[n,l]=f.useState(!1);if(e.length===0)return null;const c=e.slice(0,re),m=e.length-c.length,g=e.reduce((o,i)=>o+i.repeatedTokens,0);return t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("button",{type:"button",onClick:()=>l(o=>!o),"aria-expanded":n,className:"flex w-full flex-wrap items-center justify-between gap-2 rounded px-1 py-0.5 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",children:[t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[n?t.jsx(ee,{className:"size-3.5 shrink-0 text-muted-foreground"}):t.jsx(z,{className:"size-3.5 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:"Duplicate Content"})]}),t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," group",e.length===1?"":"s"," | ~",u(g)," repeated"]})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2",children:c.map((o,i)=>{const b=o.segments.slice(0,ne),T=o.segments.length-b.length;return t.jsxs("div",{className:"space-y-1.5 border-t border-border/50 pt-2 first:border-t-0 first:pt-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(i+1)}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",children:o.firstLabel}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:["x",String(o.count)," | ~",u(o.repeatedTokens)," saved"]})]}),o.preview.length>0&&t.jsx("div",{className:"ml-7 line-clamp-2 break-words rounded bg-background/40 px-2 py-1 font-mono text-[11px] leading-4 text-muted-foreground",children:o.preview}),t.jsxs("div",{className:"ml-7 flex flex-wrap gap-1",children:[b.map((d,v)=>{const j=P(d,s),N=j===null||r===void 0?void 0:r,k=`${d.label} ~${u(d.tokens)}`;return N===void 0||j===null?t.jsx("span",{className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground",title:k,children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`):t.jsx("button",{type:"button",onClick:()=>N(j),className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to this duplicate block",children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`)}),T>0&&t.jsxs("span",{className:"inline-flex h-6 items-center rounded border border-border/40 px-1.5 font-mono text-[11px] text-muted-foreground/70",children:["+",String(T)]})]})]},o.key)})}),m>0&&t.jsxs("div",{className:"border-t border-border/50 pt-2 font-mono text-[11px] text-muted-foreground",children:["+",String(m)," more duplicate group",m===1?"":"s"]})]})]})}function Se(e){const s=[];for(const r of le){const n=e.filter(o=>o.role===r);if(n.length===0)continue;const l=n.reduce((o,i)=>o+i.size,0),c=n.reduce((o,i)=>o+i.characters,0),m=Z[r],g=`${n.length} segment${n.length===1?"":"s"} grouped as ${de[r]}`;s.push({role:r,label:m,size:l,characters:c,text:g,path:`role:${r}`})}return s}function $e(e){return[...e].sort((s,r)=>r.size-s.size).slice(0,se)}function Ee({parsed:e,inputTokens:s,model:r=null,onSegmentActivate:n,segments:l}){const{providers:c}=F(),[m,g]=f.useState("role"),o=f.useMemo(()=>l??null,[l]),i=f.useMemo(()=>(o??[]).reduce((a,x)=>a+x.size,0),[o]),b=f.useMemo(()=>o===null?[]:Se(o),[o]),T=f.useMemo(()=>o===null?[]:$e(o),[o]),d=f.useMemo(()=>o===null?null:q({segments:o,inputTokens:s,parsed:e,model:r,providers:c}),[s,r,e,c,o]),v=f.useMemo(()=>o===null||s===null||i===0?!1:Math.abs(s-i)/Math.max(s,i)>=te,[s,o,i]);if(o===null||o.length===0||e===null&&l===void 0)return null;const j=s!==null&&v?"text-amber-400":"text-muted-foreground",N=m==="role"?b:o,k=i>0?i:N.reduce((a,x)=>a+x.size,0),D=m==="segment"?n:void 0,M=`${String(o.length)} segment${o.length===1?"":"s"}`,U=s===null?"Provider input unknown":`Provider input ${u(s)}`,W=d===null?"Limit unknown":`Limit ${A(d)}`,G=d===null?"Usage unknown":`${w(d.usagePercent)} used`;return t.jsx(V,{delayDuration:150,children:t.jsxs("div",{className:"px-4 py-3 space-y-3","data-testid":"anatomy-root",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[t.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Request Context"}),d!==null&&t.jsx(ge,{health:d.health})]}),t.jsxs("div",{className:p("mt-0.5 text-xs font-mono tabular-nums",j),children:["Estimated ~",u(i)," tokens | ",U," | ",W," |"," ",G," | ",M]})]}),t.jsx("div",{className:"inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",role:"group","aria-label":"Context breakdown mode",children:ue.map(a=>t.jsx("button",{type:"button","aria-pressed":m===a.value,onClick:()=>g(a.value),className:p("h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",m===a.value?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:a.label},a.value))})]}),v&&t.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[t.jsxs(J,{children:[t.jsx(Y,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex items-center hover:text-amber-300","aria-label":"Token estimate differs from provider input",children:t.jsx(K,{className:"size-3.5"})})}),t.jsx(X,{className:"max-w-xs text-xs",children:"The bar uses a local token estimate. Provider input tokens remain the source of truth for billing and context-window usage."})]}),"Estimate differs from provider-reported input."]}),d!==null&&t.jsx(Te,{intelligence:d,segments:o,onSegmentActivate:n}),d!==null&&t.jsx(Ce,{groups:d.duplicateGroups,segments:o,onSegmentActivate:n}),t.jsx(Q,{segments:N,totalTokens:k,showLabels:m==="segment",onActivate:D}),t.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground",children:b.map(a=>{const x=i>0?a.size/i*100:0;return t.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 rounded-[2px]",$[a.role])}),t.jsx("span",{children:a.label}),t.jsx("span",{className:"font-mono text-muted-foreground/70",children:h(x)})]},a.role)})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Top Contributors"}),t.jsx("div",{className:"grid gap-1",children:T.map((a,x)=>{const H=i>0?a.size/i*100:0,R=n,E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(x+1)}),t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[a.role])}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:a.label}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:[h(H)," | ~",u(a.size)]})]});return R!==void 0?t.jsx("button",{type:"button",onClick:()=>R(a),className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",title:"Jump to this request block",children:E},`${a.path}-${x}`):t.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:E},`${a.path}-${x}`)})})]})]})})}export{Ee as RequestAnatomy};
1
+ import{r as f,C as u,j as t,x as p,I as B}from"./index-B0TN1KKO.js";import{u as F,y as q,q as V,s as J,t as Y,I as K,v as X,S as Q,z as $,A as Z,E as C,F as ee,e as z}from"./ProxyViewerContainer-6twNZHwl.js";const te=.25,se=5,re=4,ne=6,oe=.25,ae=.2,ie=.2,le=["system","user","assistant","tool","tools"],de={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},ue=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}],ce={unknown:"bg-muted-foreground/50",ok:"bg-emerald-500/70",watch:"bg-amber-400/75",danger:"bg-red-500/80"},me={unknown:"text-muted-foreground",ok:"text-emerald-400",watch:"text-amber-300",danger:"text-red-300"},xe={ok:"border-emerald-400/30 bg-emerald-400/8 text-emerald-200",optimizable:"border-amber-400/30 bg-amber-400/8 text-amber-100",risk:"border-red-400/35 bg-red-500/10 text-red-100"},pe={ok:"OK",optimizable:"Optimizable",risk:"Risk"};function h(e){return e>=10?`${e.toFixed(0)}%`:e>=1?`${e.toFixed(1)}%`:e>0?"<1%":"0%"}function w(e){return e===null?"Unknown":h(e*100)}function L(e){return e===null?"Unknown":e<0?`-${u(Math.abs(e))}`:u(e)}function A(e){return e.contextWindow.tokens===null?"Unknown":B(e.contextWindow.tokens)}function fe(e){switch(e.contextWindow.source){case"request":return e.contextWindow.label;case"provider":return e.contextWindow.label;case"model-rule":return e.contextWindow.label;case"unknown":return e.model===null?e.contextWindow.label:`${e.contextWindow.label}: ${e.model}`}}function he(e){switch(e){case"watch":return"border-amber-400/30 bg-amber-400/8 text-amber-100";case"danger":return"border-red-400/35 bg-red-500/10 text-red-100"}}function _(e){const s=pe[e.level];if(e.level==="ok")return s;const r=e.level==="risk"?`${String(e.opportunityCount)} signal${e.opportunityCount===1?"":"s"}`:`${String(e.opportunityCount)} opportunit${e.opportunityCount===1?"y":"ies"}`;return e.reclaimableTokens<=0?`${s} | ${r}`:`${s} | ${r} | ~${u(e.reclaimableTokens)} tokens`}function ge({health:e}){return t.jsx("span",{className:p("inline-flex h-5 max-w-full items-center rounded border px-1.5 font-mono text-[10px]",xe[e.level]),"aria-label":`Context health ${_(e)}`,children:t.jsx("span",{className:"truncate",children:_(e)})})}function y(e,s){return e.roleUsages.find(r=>r.role===s)?.tokens??0}function O(e,s){return e.roleUsages.find(r=>r.role===s)?.percent??0}function S(e,s){if(e<=0)return null;const r=Math.round(e*s);return r>0?r:null}function I(e,s){return[...e].filter(r=>r.role===s).sort((r,n)=>n.size-r.size)[0]??null}function be(e){return[...e].filter(s=>s.role==="user"||s.role==="assistant"||s.role==="tool").sort((s,r)=>r.size-s.size)[0]??null}function ve(e,s){const r=e[0]??null;if(r===null)return null;const n=r.segments[0]??null;return n===null?null:P(n,s)}function je(e){const s=e.reduce((r,n)=>r+n.repeatedTokens,0);return s>0?s:null}function Ne(e){return y(e,"user")+y(e,"assistant")+y(e,"tool")}function ke({diagnostic:e,intelligence:s,segments:r}){switch(e.kind){case"duplicate":return{key:"duplicate",kind:"duplicate",severity:e.severity,title:"Duplicate content",impact:e.detail,action:"Remove repeated blocks or keep one canonical copy in the next request.",savingTokens:je(s.duplicateGroups),target:ve(s.duplicateGroups,r)};case"tool-schema":{const n=y(s,"tools"),l=O(s,"tools");return{key:"tool-schema",kind:"tool-schema",severity:e.severity,title:"Tool schema pressure",impact:`Tool definitions use ~${u(n)} tokens (${h(l*100)}).`,action:"Disable unused tools or shorten verbose schema descriptions.",savingTokens:S(n,oe),target:I(r,"tools")}}case"system-heavy":{const n=y(s,"system"),l=O(s,"system");return{key:"system-heavy",kind:"system-heavy",severity:e.severity,title:"Large system prompt",impact:`System instructions use ~${u(n)} tokens (${h(l*100)}).`,action:"Compress repeated policy text and move stable guidance into reusable memory.",savingTokens:S(n,ae),target:I(r,"system")}}case"history-bloat":{const n=Ne(s);return{key:"history-bloat",kind:"history-bloat",severity:e.severity,title:"Conversation history growth",impact:e.detail,action:"Summarize older turns and trim resolved tool outputs before continuing.",savingTokens:S(n,ie),target:be(r)}}}}function we({intelligence:e,segments:s}){const r=[];return(e.riskLevel==="watch"||e.riskLevel==="danger")&&r.push({key:"context-pressure",kind:"context-pressure",severity:e.riskLevel==="danger"?"danger":"watch",title:"Context window pressure",impact:`${w(e.usagePercent)} used, ${L(e.remainingAfterReserveTokens)} remaining after output reserve.`,action:"Start with the largest context block, then remove duplicates or summarize history.",savingTokens:null,target:[...s].sort((n,l)=>l.size-n.size)[0]??null}),e.contextWindow.source==="unknown"&&r.push({key:"context-window",kind:"context-window",severity:"watch",title:"Context window unknown",impact:"Agent Inspector cannot calculate remaining space for this model.",action:"Add model metadata in Provider settings so risk and remaining space are accurate.",savingTokens:null,target:null}),e.diagnostics.forEach(n=>{r.push(ke({diagnostic:n,intelligence:e,segments:s}))}),r}function ye({items:e,onSegmentActivate:s}){return e.length===0?null:t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Context Advisor"}),t.jsxs("div",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," issue",e.length===1?"":"s"]})]}),t.jsx("div",{className:"grid gap-2",children:e.map(r=>{const n=r.target,l=n!==null&&s!==void 0;return t.jsx("div",{className:p("rounded border px-2 py-1.5 text-xs",he(r.severity)),children:t.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium",children:r.title}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Impact: ",r.impact]}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Action: ",r.action]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.savingTokens!==null&&t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["Save ~",u(r.savingTokens)]}),l&&n!==null&&s!==void 0&&t.jsxs("button",{type:"button",onClick:()=>s(n),className:"inline-flex h-6 items-center gap-1 rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to the most relevant context block",children:[t.jsx(z,{className:"size-3"}),"Jump"]})]})]})},r.key)})})]})}function Te({intelligence:e,segments:s,onSegmentActivate:r}){const n=e.usagePercent===null?0:Math.max(1,e.usagePercent*100),l=e.outputReserveTokens===null?"No output reserve":`Output reserve ${u(e.outputReserveTokens)}`,c=e.largestRole,m=we({intelligence:e,segments:s});return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"grid gap-x-4 gap-y-2 border-y border-border/60 py-2 text-xs sm:grid-cols-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Window"}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-foreground",children:A(e)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:fe(e)})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Used"}),t.jsx("div",{className:p("mt-0.5 font-mono",me[e.riskLevel]),children:w(e.usagePercent)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:l})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Remaining"}),t.jsx("div",{className:"mt-0.5 font-mono text-foreground",children:L(e.remainingAfterReserveTokens)}),t.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:["Input only ",L(e.remainingInputTokens)]})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Largest"}),c===null?t.jsx("div",{className:"mt-0.5 text-muted-foreground",children:"Unknown"}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[c.role])}),t.jsx("span",{className:"truncate text-foreground",children:c.label})]}),t.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[h(c.percent*100)," | ~",u(c.tokens)]})]})]})]}),e.contextWindow.tokens!==null&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted/40",children:[t.jsx("div",{className:p("h-full rounded-full",ce[e.riskLevel]),style:{width:`${String(n)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-amber-200/70",style:{left:`${String(C.watch*100)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-red-200/80",style:{left:`${String(C.danger*100)}%`}})]}),t.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[t.jsx("span",{children:"Context window"}),t.jsxs("span",{children:["Watch ",w(C.watch)," / Danger"," ",w(C.danger)]})]})]}),t.jsx(ye,{items:m,onSegmentActivate:r})]})}function P(e,s){return s.find(r=>r.path===e.path)??null}function Ce({groups:e,segments:s,onSegmentActivate:r}){const[n,l]=f.useState(!1);if(e.length===0)return null;const c=e.slice(0,re),m=e.length-c.length,g=e.reduce((o,i)=>o+i.repeatedTokens,0);return t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("button",{type:"button",onClick:()=>l(o=>!o),"aria-expanded":n,className:"flex w-full flex-wrap items-center justify-between gap-2 rounded px-1 py-0.5 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",children:[t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[n?t.jsx(ee,{className:"size-3.5 shrink-0 text-muted-foreground"}):t.jsx(z,{className:"size-3.5 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:"Duplicate Content"})]}),t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," group",e.length===1?"":"s"," | ~",u(g)," repeated"]})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2",children:c.map((o,i)=>{const b=o.segments.slice(0,ne),T=o.segments.length-b.length;return t.jsxs("div",{className:"space-y-1.5 border-t border-border/50 pt-2 first:border-t-0 first:pt-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(i+1)}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",children:o.firstLabel}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:["x",String(o.count)," | ~",u(o.repeatedTokens)," saved"]})]}),o.preview.length>0&&t.jsx("div",{className:"ml-7 line-clamp-2 break-words rounded bg-background/40 px-2 py-1 font-mono text-[11px] leading-4 text-muted-foreground",children:o.preview}),t.jsxs("div",{className:"ml-7 flex flex-wrap gap-1",children:[b.map((d,v)=>{const j=P(d,s),N=j===null||r===void 0?void 0:r,k=`${d.label} ~${u(d.tokens)}`;return N===void 0||j===null?t.jsx("span",{className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground",title:k,children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`):t.jsx("button",{type:"button",onClick:()=>N(j),className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to this duplicate block",children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`)}),T>0&&t.jsxs("span",{className:"inline-flex h-6 items-center rounded border border-border/40 px-1.5 font-mono text-[11px] text-muted-foreground/70",children:["+",String(T)]})]})]},o.key)})}),m>0&&t.jsxs("div",{className:"border-t border-border/50 pt-2 font-mono text-[11px] text-muted-foreground",children:["+",String(m)," more duplicate group",m===1?"":"s"]})]})]})}function Se(e){const s=[];for(const r of le){const n=e.filter(o=>o.role===r);if(n.length===0)continue;const l=n.reduce((o,i)=>o+i.size,0),c=n.reduce((o,i)=>o+i.characters,0),m=Z[r],g=`${n.length} segment${n.length===1?"":"s"} grouped as ${de[r]}`;s.push({role:r,label:m,size:l,characters:c,text:g,path:`role:${r}`})}return s}function $e(e){return[...e].sort((s,r)=>r.size-s.size).slice(0,se)}function Ee({parsed:e,inputTokens:s,model:r=null,onSegmentActivate:n,segments:l}){const{providers:c}=F(),[m,g]=f.useState("role"),o=f.useMemo(()=>l??null,[l]),i=f.useMemo(()=>(o??[]).reduce((a,x)=>a+x.size,0),[o]),b=f.useMemo(()=>o===null?[]:Se(o),[o]),T=f.useMemo(()=>o===null?[]:$e(o),[o]),d=f.useMemo(()=>o===null?null:q({segments:o,inputTokens:s,parsed:e,model:r,providers:c}),[s,r,e,c,o]),v=f.useMemo(()=>o===null||s===null||i===0?!1:Math.abs(s-i)/Math.max(s,i)>=te,[s,o,i]);if(o===null||o.length===0||e===null&&l===void 0)return null;const j=s!==null&&v?"text-amber-400":"text-muted-foreground",N=m==="role"?b:o,k=i>0?i:N.reduce((a,x)=>a+x.size,0),D=m==="segment"?n:void 0,M=`${String(o.length)} segment${o.length===1?"":"s"}`,U=s===null?"Provider input unknown":`Provider input ${u(s)}`,W=d===null?"Limit unknown":`Limit ${A(d)}`,G=d===null?"Usage unknown":`${w(d.usagePercent)} used`;return t.jsx(V,{delayDuration:150,children:t.jsxs("div",{className:"px-4 py-3 space-y-3","data-testid":"anatomy-root",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[t.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Request Context"}),d!==null&&t.jsx(ge,{health:d.health})]}),t.jsxs("div",{className:p("mt-0.5 text-xs font-mono tabular-nums",j),children:["Estimated ~",u(i)," tokens | ",U," | ",W," |"," ",G," | ",M]})]}),t.jsx("div",{className:"inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",role:"group","aria-label":"Context breakdown mode",children:ue.map(a=>t.jsx("button",{type:"button","aria-pressed":m===a.value,onClick:()=>g(a.value),className:p("h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",m===a.value?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:a.label},a.value))})]}),v&&t.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[t.jsxs(J,{children:[t.jsx(Y,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex items-center hover:text-amber-300","aria-label":"Token estimate differs from provider input",children:t.jsx(K,{className:"size-3.5"})})}),t.jsx(X,{className:"max-w-xs text-xs",children:"The bar uses a local token estimate. Provider input tokens remain the source of truth for billing and context-window usage."})]}),"Estimate differs from provider-reported input."]}),d!==null&&t.jsx(Te,{intelligence:d,segments:o,onSegmentActivate:n}),d!==null&&t.jsx(Ce,{groups:d.duplicateGroups,segments:o,onSegmentActivate:n}),t.jsx(Q,{segments:N,totalTokens:k,showLabels:m==="segment",onActivate:D}),t.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground",children:b.map(a=>{const x=i>0?a.size/i*100:0;return t.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 rounded-[2px]",$[a.role])}),t.jsx("span",{children:a.label}),t.jsx("span",{className:"font-mono text-muted-foreground/70",children:h(x)})]},a.role)})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Top Contributors"}),t.jsx("div",{className:"grid gap-1",children:T.map((a,x)=>{const H=i>0?a.size/i*100:0,R=n,E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(x+1)}),t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[a.role])}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:a.label}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:[h(H)," | ~",u(a.size)]})]});return R!==void 0?t.jsx("button",{type:"button",onClick:()=>R(a),className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",title:"Jump to this request block",children:E},`${a.path}-${x}`):t.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:E},`${a.path}-${x}`)})})]})]})})}export{Ee as RequestAnatomy};
@@ -1,2 +1,2 @@
1
- import{r as c,j as e,x as J,C as d,G as M}from"./index-B__qT0Yd.js";import{G as $,H as g,J as j,K as X,B as m,F as N,e as v,N as y,O as k,Q as S,U as O,V as A,W as b,Y as E,Z as w,_ as p,g as Z,$ as Q}from"./ProxyViewerContainer-Buu8vkCK.js";var W="Separator",L="horizontal",Y=["horizontal","vertical"],K=c.forwardRef((n,t)=>{const{decorative:r,orientation:o=L,...s}=n,a=q(o)?o:L,l=r?{role:"none"}:{"aria-orientation":a==="vertical"?a:void 0,role:"separator"};return e.jsx($.div,{"data-orientation":a,...l,...s,ref:t})});K.displayName=W;function q(n){return Y.includes(n)}var ee=K;function z({className:n,orientation:t="horizontal",decorative:r=!0,...o}){return e.jsx(ee,{"data-slot":"separator",decorative:r,orientation:t,className:J("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",n),...o})}const te=/<think>([\s\S]*?)<\/think>/gi,ne=/<think>([\s\S]*?)<\/think>/i;function D(n){const t=ne.exec(n);if(!t||t[1]===void 0)return{thinking:null,remainingText:n};const r=t[1].trim(),o=n.replace(te,"").trim();return{thinking:r,remainingText:o}}function se(n){return e.jsx(e.Fragment,{})}function re({text:n}){const[t,r]=c.useState(!1);return e.jsxs(g,{open:t,onOpenChange:r,children:[e.jsxs(j,{className:"flex items-center gap-1.5 py-0.5 cursor-pointer hover:opacity-80 transition-opacity group",children:[t?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs italic select-none opacity-60",children:"[system-reminder]"})]}),e.jsx(y,{children:e.jsx("div",{className:"pl-4 pt-1",children:e.jsx(b,{text:n})})})]})}const oe=c.memo(function({text:t}){if(t.includes("<system-reminder>"))return e.jsx(re,{text:t});const{thinking:r,remainingText:o}=D(t);return e.jsxs("div",{className:"space-y-2",children:[r!==null&&e.jsx(_,{thinking:r}),o.length>0&&e.jsx(b,{text:o}),r===null&&o.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty text block"})]})}),_=c.memo(function({thinking:t}){const[r,o]=c.useState(!1);return e.jsx(g,{open:r,onOpenChange:o,children:e.jsxs("div",{className:"border-l-2 border-purple-500/40 my-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-purple-500/5 transition-colors rounded-r-sm group",children:[e.jsx(X,{className:"size-3.5 text-purple-400 shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-purple-400",children:"Thinking"}),e.jsxs(m,{variant:"ghost",className:"text-[10px] text-muted-foreground px-1.5 py-0 h-4 font-mono",children:[t.length.toLocaleString()," chars"]}),e.jsx("span",{className:"flex-1"}),r?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed",children:t})})})})]})})}),ae=c.memo(function({name:t,input:r,toolIndex:o,toolFocus:s}){const[a,i]=c.useState(!1),l=c.useRef(null),x=s?.focusedToolIndex===o;return c.useEffect(()=>{if(!x||s===void 0||s.toolFocusNonce<=0)return;i(!0);const u=window.setTimeout(()=>{const f=l.current;f!==null&&(f.scrollIntoView({block:"center",behavior:"smooth"}),f.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(u)},[x,s,s?.toolFocusNonce]),e.jsx(g,{open:a,onOpenChange:i,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":o,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(S,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:t}),e.jsx("span",{className:"flex-1"}),a?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:a&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(O,{data:A(r),defaultExpandDepth:0})})})})})]})})}),ie=c.memo(function({block:t,toolIndex:r,toolFocus:o}){switch(t.type){case"text":return e.jsx(oe,{text:t.text});case"thinking":case"think":return e.jsx(_,{thinking:t.thinking});case"tool_use":return e.jsx(ae,{name:t.name,input:t.input,toolIndex:r??0,toolFocus:o});default:return se()}}),le=c.memo(function({response:t,toolFocus:r}){let o=0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),t.stop_reason!==null&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(E,{className:"size-2.5"}),t.stop_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(t.usage.input_tokens??0)," in /"," ",d(t.usage.output_tokens??0)," out"]}),t.usage.cache_creation_input_tokens!==void 0&&t.usage.cache_creation_input_tokens!==null&&t.usage.cache_creation_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",d(t.usage.cache_creation_input_tokens)]}),t.usage.cache_read_input_tokens!==void 0&&t.usage.cache_read_input_tokens!==null&&t.usage.cache_read_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",d(t.usage.cache_read_input_tokens)]})]})]}),e.jsx(z,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[t.content.map((s,a)=>{const i=s.type==="tool_use"?o:void 0;return s.type==="tool_use"&&(o+=1),e.jsx(ie,{block:s,toolIndex:i,toolFocus:r},a)}),t.content.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function F(n){if(n===void 0||n==="")return{};try{return JSON.parse(n)}catch{return null}}function H({toolIndex:n,toolFocus:t,setOpen:r}){const o=c.useRef(null),s=t?.focusedToolIndex===n;return c.useEffect(()=>{if(!s||t===void 0||t.toolFocusNonce<=0)return;r(!0);const a=window.setTimeout(()=>{const i=o.current;i!==null&&(i.scrollIntoView({block:"center",behavior:"smooth"}),i.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(a)},[r,s,t,t?.toolFocusNonce]),o}function ce({name:n,argumentsText:t,toolIndex:r,toolFocus:o}){const s=c.useRef(null),a=o?.focusedToolIndex===r;return c.useEffect(()=>{if(!a||o===void 0||o.toolFocusNonce<=0)return;const i=window.setTimeout(()=>{const l=s.current;l!==null&&(l.scrollIntoView({block:"center",behavior:"smooth"}),l.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(i)},[a,o,o?.toolFocusNonce]),e.jsxs("div",{ref:s,tabIndex:-1,className:"border border-sky-400/20 rounded-md p-3 bg-muted/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-response-tool-index":r,children:[e.jsx("div",{className:"text-xs text-sky-400/80 font-mono mb-1",children:"function_call"}),e.jsxs("div",{className:"font-mono text-xs",children:[e.jsx("span",{className:"text-foreground/80",children:n}),e.jsxs("span",{className:"text-muted-foreground",children:["(",t,")"]})]})]})}function ue({call:n,toolIndex:t,toolFocus:r}){const[o,s]=c.useState(!1),a=n.function.name??"(unnamed tool)",i=o?F(n.function.arguments):{},l=H({toolIndex:t,toolFocus:r,setOpen:s});return e.jsx(g,{open:o,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":t,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(S,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:a}),n.id!==void 0&&n.id!==""&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground/60 truncate",children:n.id}),e.jsx("span",{className:"flex-1"}),o?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:o&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:i===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.function.arguments}):e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(O,{data:A(i),defaultExpandDepth:0})})})})})]})})}function de(n){if(n.output_text!==void 0&&n.output_text.length>0)return n.output_text;const t=[];for(const r of n.output??[]){if(p(r,"type")!=="message")continue;const o=p(r,"content");if(Array.isArray(o))for(const s of o){const a=p(s,"type"),i=p(s,"text");(a==="output_text"||a==="text")&&typeof i=="string"&&t.push(i)}}return t.join(`
1
+ import{r as c,j as e,x as J,C as d,G as M}from"./index-B0TN1KKO.js";import{G as $,H as g,J as j,K as X,B as m,F as N,e as v,N as y,O as k,Q as S,U as O,V as A,W as b,Y as E,Z as w,_ as p,g as Z,$ as Q}from"./ProxyViewerContainer-6twNZHwl.js";var W="Separator",L="horizontal",Y=["horizontal","vertical"],K=c.forwardRef((n,t)=>{const{decorative:r,orientation:o=L,...s}=n,a=q(o)?o:L,l=r?{role:"none"}:{"aria-orientation":a==="vertical"?a:void 0,role:"separator"};return e.jsx($.div,{"data-orientation":a,...l,...s,ref:t})});K.displayName=W;function q(n){return Y.includes(n)}var ee=K;function z({className:n,orientation:t="horizontal",decorative:r=!0,...o}){return e.jsx(ee,{"data-slot":"separator",decorative:r,orientation:t,className:J("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",n),...o})}const te=/<think>([\s\S]*?)<\/think>/gi,ne=/<think>([\s\S]*?)<\/think>/i;function D(n){const t=ne.exec(n);if(!t||t[1]===void 0)return{thinking:null,remainingText:n};const r=t[1].trim(),o=n.replace(te,"").trim();return{thinking:r,remainingText:o}}function se(n){return e.jsx(e.Fragment,{})}function re({text:n}){const[t,r]=c.useState(!1);return e.jsxs(g,{open:t,onOpenChange:r,children:[e.jsxs(j,{className:"flex items-center gap-1.5 py-0.5 cursor-pointer hover:opacity-80 transition-opacity group",children:[t?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs italic select-none opacity-60",children:"[system-reminder]"})]}),e.jsx(y,{children:e.jsx("div",{className:"pl-4 pt-1",children:e.jsx(b,{text:n})})})]})}const oe=c.memo(function({text:t}){if(t.includes("<system-reminder>"))return e.jsx(re,{text:t});const{thinking:r,remainingText:o}=D(t);return e.jsxs("div",{className:"space-y-2",children:[r!==null&&e.jsx(_,{thinking:r}),o.length>0&&e.jsx(b,{text:o}),r===null&&o.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty text block"})]})}),_=c.memo(function({thinking:t}){const[r,o]=c.useState(!1);return e.jsx(g,{open:r,onOpenChange:o,children:e.jsxs("div",{className:"border-l-2 border-purple-500/40 my-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-purple-500/5 transition-colors rounded-r-sm group",children:[e.jsx(X,{className:"size-3.5 text-purple-400 shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-purple-400",children:"Thinking"}),e.jsxs(m,{variant:"ghost",className:"text-[10px] text-muted-foreground px-1.5 py-0 h-4 font-mono",children:[t.length.toLocaleString()," chars"]}),e.jsx("span",{className:"flex-1"}),r?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed",children:t})})})})]})})}),ae=c.memo(function({name:t,input:r,toolIndex:o,toolFocus:s}){const[a,i]=c.useState(!1),l=c.useRef(null),x=s?.focusedToolIndex===o;return c.useEffect(()=>{if(!x||s===void 0||s.toolFocusNonce<=0)return;i(!0);const u=window.setTimeout(()=>{const f=l.current;f!==null&&(f.scrollIntoView({block:"center",behavior:"smooth"}),f.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(u)},[x,s,s?.toolFocusNonce]),e.jsx(g,{open:a,onOpenChange:i,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":o,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(S,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:t}),e.jsx("span",{className:"flex-1"}),a?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:a&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(O,{data:A(r),defaultExpandDepth:0})})})})})]})})}),ie=c.memo(function({block:t,toolIndex:r,toolFocus:o}){switch(t.type){case"text":return e.jsx(oe,{text:t.text});case"thinking":case"think":return e.jsx(_,{thinking:t.thinking});case"tool_use":return e.jsx(ae,{name:t.name,input:t.input,toolIndex:r??0,toolFocus:o});default:return se()}}),le=c.memo(function({response:t,toolFocus:r}){let o=0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),t.stop_reason!==null&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(E,{className:"size-2.5"}),t.stop_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(t.usage.input_tokens??0)," in /"," ",d(t.usage.output_tokens??0)," out"]}),t.usage.cache_creation_input_tokens!==void 0&&t.usage.cache_creation_input_tokens!==null&&t.usage.cache_creation_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",d(t.usage.cache_creation_input_tokens)]}),t.usage.cache_read_input_tokens!==void 0&&t.usage.cache_read_input_tokens!==null&&t.usage.cache_read_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",d(t.usage.cache_read_input_tokens)]})]})]}),e.jsx(z,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[t.content.map((s,a)=>{const i=s.type==="tool_use"?o:void 0;return s.type==="tool_use"&&(o+=1),e.jsx(ie,{block:s,toolIndex:i,toolFocus:r},a)}),t.content.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function F(n){if(n===void 0||n==="")return{};try{return JSON.parse(n)}catch{return null}}function H({toolIndex:n,toolFocus:t,setOpen:r}){const o=c.useRef(null),s=t?.focusedToolIndex===n;return c.useEffect(()=>{if(!s||t===void 0||t.toolFocusNonce<=0)return;r(!0);const a=window.setTimeout(()=>{const i=o.current;i!==null&&(i.scrollIntoView({block:"center",behavior:"smooth"}),i.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(a)},[r,s,t,t?.toolFocusNonce]),o}function ce({name:n,argumentsText:t,toolIndex:r,toolFocus:o}){const s=c.useRef(null),a=o?.focusedToolIndex===r;return c.useEffect(()=>{if(!a||o===void 0||o.toolFocusNonce<=0)return;const i=window.setTimeout(()=>{const l=s.current;l!==null&&(l.scrollIntoView({block:"center",behavior:"smooth"}),l.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(i)},[a,o,o?.toolFocusNonce]),e.jsxs("div",{ref:s,tabIndex:-1,className:"border border-sky-400/20 rounded-md p-3 bg-muted/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-response-tool-index":r,children:[e.jsx("div",{className:"text-xs text-sky-400/80 font-mono mb-1",children:"function_call"}),e.jsxs("div",{className:"font-mono text-xs",children:[e.jsx("span",{className:"text-foreground/80",children:n}),e.jsxs("span",{className:"text-muted-foreground",children:["(",t,")"]})]})]})}function ue({call:n,toolIndex:t,toolFocus:r}){const[o,s]=c.useState(!1),a=n.function.name??"(unnamed tool)",i=o?F(n.function.arguments):{},l=H({toolIndex:t,toolFocus:r,setOpen:s});return e.jsx(g,{open:o,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":t,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(S,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:a}),n.id!==void 0&&n.id!==""&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground/60 truncate",children:n.id}),e.jsx("span",{className:"flex-1"}),o?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:o&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:i===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.function.arguments}):e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(O,{data:A(i),defaultExpandDepth:0})})})})})]})})}function de(n){if(n.output_text!==void 0&&n.output_text.length>0)return n.output_text;const t=[];for(const r of n.output??[]){if(p(r,"type")!=="message")continue;const o=p(r,"content");if(Array.isArray(o))for(const s of o){const a=p(s,"type"),i=p(s,"text");(a==="output_text"||a==="text")&&typeof i=="string"&&t.push(i)}}return t.join(`
2
2
  `)}function xe(n){const t=[];for(const r of n.output??[]){if(p(r,"type")!=="function_call")continue;const o=p(r,"name");if(typeof o!="string"||o.length===0)continue;const s=p(r,"id"),a=p(r,"call_id"),i=p(r,"arguments"),l=p(r,"status");t.push({id:typeof s=="string"&&s.length>0?s:null,callId:typeof a=="string"&&a.length>0?a:null,name:o,argumentsText:typeof i=="string"?i:"",status:typeof l=="string"&&l.length>0?l:null})}return t}function me({call:n,toolIndex:t,toolFocus:r}){const[o,s]=c.useState(!1),a=o?F(n.argumentsText):{},i=n.callId??n.id,l=H({toolIndex:t,toolFocus:r,setOpen:s});return e.jsx(g,{open:o,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":t,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(S,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:n.name}),i!==null&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground/60 truncate",children:i}),n.status!==null&&e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4 font-mono",children:n.status}),e.jsx("span",{className:"flex-1"}),o?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:o&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:a===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.argumentsText}):e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(O,{data:A(a),defaultExpandDepth:0})})})})})]})})}const pe=c.memo(function({response:t,toolFocus:r}){const o=t.choices[0],s=o?.message,a=s?.tool_calls??[];return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),o?.finish_reason!==null&&o?.finish_reason!==void 0&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(E,{className:"size-2.5"}),o.finish_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(t.usage.prompt_tokens??0)," in /"," ",d(t.usage.completion_tokens??0)," out"]})]})]}),e.jsx(z,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[s?.reasoning_content!==null&&s?.reasoning_content!==void 0&&s.reasoning_content.length>0&&e.jsx(_,{thinking:s.reasoning_content}),s?.content!==null&&s?.content!==void 0&&s.content.length>0&&(()=>{const i=s.reasoning_content!==null&&s.reasoning_content!==void 0&&s.reasoning_content.length>0,{thinking:l,remainingText:x}=D(s.content);return e.jsxs("div",{className:"space-y-2",children:[l!==null&&!i&&e.jsx(_,{thinking:l}),x.length>0&&e.jsx(b,{text:x})]})})(),a.map((i,l)=>e.jsx(ue,{call:i,toolIndex:l,toolFocus:r},i.id??`tc-${l}`)),s?.function_call!==null&&s?.function_call!==void 0&&e.jsx(ce,{name:s.function_call.name,argumentsText:s.function_call.arguments,toolIndex:a.length,toolFocus:r}),(s?.content===null||s?.content===void 0||s.content.length===0)&&(s?.reasoning_content===null||s?.reasoning_content===void 0||s.reasoning_content.length===0)&&(s?.function_call===null||s?.function_call===void 0)&&a.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})}),fe=c.memo(function({response:t,toolFocus:r}){const o=de(t),s=xe(t),a=t.status??null,i=t.usage?.input_tokens??0,l=t.usage?.output_tokens??0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.model!==void 0&&t.model.length>0&&e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),a!==null&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(E,{className:"size-2.5"}),a]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(i)," in / ",d(l)," out"]})]})]}),e.jsx(z,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx(b,{text:o}),s.map((x,u)=>e.jsx(me,{call:x,toolIndex:u,toolFocus:r},x.callId??x.id??`call-${u}`)),o.length===0&&s.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function I(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function he(n){return I(n)&&n.object==="chat.completion"}function ge(n){return I(n)&&n.object==="response"}function je(n){return I(n)&&n.type==="message"&&Array.isArray(n.content)}function Ne(n,t,r){return n==="openai"&&he(t)?e.jsx(pe,{response:t,toolFocus:r}):n==="openai"&&ge(t)?e.jsx(fe,{response:t,toolFocus:r}):n==="anthropic"&&je(t)?e.jsx(le,{response:t,toolFocus:r}):null}function ve(n){switch(n){case"success":return"text-emerald-400";case"client_error":return"text-amber-400";case"server_error":return"text-red-400";case"pending":return"text-muted-foreground"}}function h({status:n}){const t=M(n),r=ve(t);return n===null?e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"pending"}):e.jsxs("span",{className:J("flex items-center gap-1 text-xs font-mono font-semibold",r),children:[t==="server_error"&&e.jsx(Q,{className:"size-3"}),n]})}function G({text:n}){return e.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/5 p-3",children:e.jsx("pre",{className:"text-xs text-red-300 whitespace-pre-wrap font-mono leading-relaxed overflow-auto max-h-[60vh]",children:n})})}function ye({text:n}){return e.jsx(b,{text:n})}const be=1024*1024,Re=c.memo(function({responseText:t,responseStatus:r,streaming:o,inputTokens:s,outputTokens:a,cacheCreationInputTokens:i,cacheReadInputTokens:l,apiFormat:x,error:u,focusedToolIndex:f=null,toolFocusNonce:U=0}){const R=x??"unknown",[T,C]=c.useState(!1),V=t!==null&&t.length>be,B=t===null||V&&!T?null:t,P=c.useMemo(()=>Z(R).analyzeResponse(B).parsed,[R,B]);return c.useEffect(()=>{C(!1)},[t]),t===null&&u===void 0?e.jsxs("div",{className:"flex items-center gap-2 py-3",children:[e.jsx(h,{status:r}),e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"No response"})]}):r!==null&&r>=400?e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{status:r}),e.jsx(G,{text:t??""}),u!=null&&e.jsxs("div",{className:"rounded border border-destructive/50 bg-destructive/10 p-3 text-xs",children:[e.jsx("div",{className:"font-semibold text-destructive mb-1",children:"SSE Error"}),e.jsx("div",{className:"text-muted-foreground font-mono",children:u})]})]}):u!=null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{status:r}),e.jsxs("div",{className:"rounded border border-destructive/50 bg-destructive/10 p-3 text-xs",children:[e.jsx("div",{className:"font-semibold text-destructive mb-1",children:"SSE Error"}),e.jsx("div",{className:"text-muted-foreground font-mono",children:u})]}),t!==null&&e.jsx("div",{className:"mt-2",children:e.jsx(G,{text:t})})]}):P!==null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{status:r}),Ne(R,P,{focusedToolIndex:f,toolFocusNonce:U})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{status:r}),o&&(s!==null||a!==null)&&e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[s!==null?d(s):"—"," in /"," ",a!==null?d(a):"—"," out"]}),i!=null&&i>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",d(i)]}),l!=null&&l>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",d(l)]})]})]}),V&&!T&&e.jsxs("div",{className:"rounded-md border border-amber-300/20 bg-amber-300/[0.06] px-3 py-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"mb-2",children:["This response is ",t.length.toLocaleString()," characters, so structured parsing is deferred to keep the UI responsive. The final Response remains available here without rendering the raw event stream by default."]}),e.jsx("button",{type:"button",className:"rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>C(!0),children:"Parse full structured response"})]}),e.jsx(ye,{text:t??""})]})});export{Re as ResponseView};
@@ -1 +1 @@
1
- import{r as o,H as U,j as e,o as A,b as B,a as P}from"./index-B__qT0Yd.js";import{q as z,s as O,t as H,F as S,e as C,B as V,v as $,a0 as q,U as D,a1 as J}from"./ProxyViewerContainer-Buu8vkCK.js";const K=A({chunks:P(J),truncated:B().optional()}),F=1e4,k=80,p=80,N=40,f=40,X=o.memo(function({logId:a,truncated:E}){const[c,y]=o.useState(!1),[r,u]=o.useState({status:"idle"}),[w,b]=o.useState(new Set),[M,g]=o.useState(k),[_,j]=o.useState(new Map),l=o.useRef(null);o.useEffect(()=>{b(new Set),g(k),j(new Map),u({status:"idle"}),l.current=null},[a]),o.useEffect(()=>{if(!c||l.current===a)return;const t=new AbortController;return u({status:"loading"}),U(`/api/logs/${a}/chunks`,K,F,{signal:t.signal},()=>"Chunks not found").then(s=>{l.current=a,u({status:"success",chunks:s.chunks})}).catch(s=>{s instanceof DOMException&&s.name==="AbortError"||(l.current=null,u({status:"error",message:s instanceof Error?s.message:"Chunk data unavailable"}))}),()=>{t.abort()}},[c,a]);const d=o.useMemo(()=>{if(r.status!=="success")return[];const t=new Map;for(const s of r.chunks){const n=t.get(s.index);n?n.push(s):t.set(s.index,[s])}return Array.from(t.entries()).map(([s,n])=>({index:s,chunks:n})).sort((s,n)=>s.index-n.index)},[r]),v=d.slice(0,M),m=Math.max(d.length-v.length,0),G=t=>{b(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},I=()=>{g(t=>Math.min(t+p,d.length))},T=t=>{j(s=>{const n=new Map(s),x=n.get(t.index)??N;return n.set(t.index,Math.min(x+f,t.chunks.length)),n})};function R(){return r.status==="idle"||r.status==="loading"?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[e.jsx(q,{className:"size-3 animate-spin"}),e.jsx("span",{children:"Loading chunks..."})]}):r.status==="error"?e.jsx("div",{className:"py-2 text-xs text-muted-foreground italic",children:r.message}):e.jsxs("div",{className:"p-2 space-y-1",children:[e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono mb-2",children:[d.length," index group",d.length!==1?"s":""," available"]}),v.map(t=>{const s=w.has(t.index),n=_.get(t.index)??N,x=t.chunks.slice(0,n),h=Math.max(t.chunks.length-x.length,0);return e.jsxs("div",{className:"rounded border border-border bg-background",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 w-full px-2 py-1.5 text-left hover:bg-muted/50 transition-colors cursor-pointer",onClick:()=>G(t.index),children:[s?e.jsx(S,{className:"size-3 text-muted-foreground"}):e.jsx(C,{className:"size-3 text-muted-foreground"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["[",t.index,"] ",t.chunks[0]?.type??""]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[t.chunks.length," chunk",t.chunks.length!==1?"s":""]})]}),s&&e.jsxs("div",{className:"px-2 pb-2 space-y-1",children:[x.map((i,L)=>e.jsxs("div",{className:"rounded border border-border bg-muted/20 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["+",i.timestamp,"ms"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:i.type})]}),e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(D,{data:i,defaultExpandDepth:0,showCopy:!0})})]},`${i.index}:${i.timestamp}:${i.type}:${L}`)),h>0&&e.jsxs("button",{type:"button",className:"mt-1 rounded-md border border-border bg-background px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>T(t),children:["Show ",Math.min(f,h)," more chunk",Math.min(f,h)!==1?"s":""]})]})]},t.index)}),m>0&&e.jsxs("button",{type:"button",className:"rounded-md border border-border bg-background px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:I,children:["Show ",Math.min(p,m)," more SSE group",Math.min(p,m)!==1?"s":""]})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx(z,{children:e.jsxs(O,{children:[e.jsx(H,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:()=>y(t=>!t),children:[c?e.jsx(S,{className:"size-3"}):e.jsx(C,{className:"size-3"}),e.jsx("span",{children:"Raw SSE Events"}),e.jsxs(V,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-mono ml-1",children:[a,E===!0?"+":""]})]})}),e.jsx($,{children:"Server-Sent Events streaming chunks from the provider"})]})}),c===!0?e.jsx("div",{className:"rounded-md border border-border bg-muted/20 overflow-auto max-h-64",children:R()}):null]})});export{X as StreamingChunkSequence};
1
+ import{r as o,H as U,j as e,o as A,b as B,a as P}from"./index-B0TN1KKO.js";import{q as z,s as O,t as H,F as S,e as C,B as V,v as $,a0 as q,U as D,a1 as J}from"./ProxyViewerContainer-6twNZHwl.js";const K=A({chunks:P(J),truncated:B().optional()}),F=1e4,k=80,p=80,N=40,f=40,X=o.memo(function({logId:a,truncated:E}){const[c,y]=o.useState(!1),[r,u]=o.useState({status:"idle"}),[w,b]=o.useState(new Set),[M,g]=o.useState(k),[_,j]=o.useState(new Map),l=o.useRef(null);o.useEffect(()=>{b(new Set),g(k),j(new Map),u({status:"idle"}),l.current=null},[a]),o.useEffect(()=>{if(!c||l.current===a)return;const t=new AbortController;return u({status:"loading"}),U(`/api/logs/${a}/chunks`,K,F,{signal:t.signal},()=>"Chunks not found").then(s=>{l.current=a,u({status:"success",chunks:s.chunks})}).catch(s=>{s instanceof DOMException&&s.name==="AbortError"||(l.current=null,u({status:"error",message:s instanceof Error?s.message:"Chunk data unavailable"}))}),()=>{t.abort()}},[c,a]);const d=o.useMemo(()=>{if(r.status!=="success")return[];const t=new Map;for(const s of r.chunks){const n=t.get(s.index);n?n.push(s):t.set(s.index,[s])}return Array.from(t.entries()).map(([s,n])=>({index:s,chunks:n})).sort((s,n)=>s.index-n.index)},[r]),v=d.slice(0,M),m=Math.max(d.length-v.length,0),G=t=>{b(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},I=()=>{g(t=>Math.min(t+p,d.length))},T=t=>{j(s=>{const n=new Map(s),x=n.get(t.index)??N;return n.set(t.index,Math.min(x+f,t.chunks.length)),n})};function R(){return r.status==="idle"||r.status==="loading"?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[e.jsx(q,{className:"size-3 animate-spin"}),e.jsx("span",{children:"Loading chunks..."})]}):r.status==="error"?e.jsx("div",{className:"py-2 text-xs text-muted-foreground italic",children:r.message}):e.jsxs("div",{className:"p-2 space-y-1",children:[e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono mb-2",children:[d.length," index group",d.length!==1?"s":""," available"]}),v.map(t=>{const s=w.has(t.index),n=_.get(t.index)??N,x=t.chunks.slice(0,n),h=Math.max(t.chunks.length-x.length,0);return e.jsxs("div",{className:"rounded border border-border bg-background",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 w-full px-2 py-1.5 text-left hover:bg-muted/50 transition-colors cursor-pointer",onClick:()=>G(t.index),children:[s?e.jsx(S,{className:"size-3 text-muted-foreground"}):e.jsx(C,{className:"size-3 text-muted-foreground"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["[",t.index,"] ",t.chunks[0]?.type??""]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[t.chunks.length," chunk",t.chunks.length!==1?"s":""]})]}),s&&e.jsxs("div",{className:"px-2 pb-2 space-y-1",children:[x.map((i,L)=>e.jsxs("div",{className:"rounded border border-border bg-muted/20 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["+",i.timestamp,"ms"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:i.type})]}),e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(D,{data:i,defaultExpandDepth:0,showCopy:!0})})]},`${i.index}:${i.timestamp}:${i.type}:${L}`)),h>0&&e.jsxs("button",{type:"button",className:"mt-1 rounded-md border border-border bg-background px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>T(t),children:["Show ",Math.min(f,h)," more chunk",Math.min(f,h)!==1?"s":""]})]})]},t.index)}),m>0&&e.jsxs("button",{type:"button",className:"rounded-md border border-border bg-background px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:I,children:["Show ",Math.min(p,m)," more SSE group",Math.min(p,m)!==1?"s":""]})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx(z,{children:e.jsxs(O,{children:[e.jsx(H,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:()=>y(t=>!t),children:[c?e.jsx(S,{className:"size-3"}):e.jsx(C,{className:"size-3"}),e.jsx("span",{children:"Raw SSE Events"}),e.jsxs(V,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-mono ml-1",children:[a,E===!0?"+":""]})]})}),e.jsx($,{children:"Server-Sent Events streaming chunks from the provider"})]})}),c===!0?e.jsx("div",{className:"rounded-md border border-border bg-muted/20 overflow-auto max-h-64",children:R()}):null]})});export{X as StreamingChunkSequence};
@@ -1 +1 @@
1
- import{j as e,S as s}from"./index-B__qT0Yd.js";function n({error:o,reset:r}){return e.jsx(s,{error:o,reset:r,scope:"session-route"})}export{n as errorComponent};
1
+ import{j as e,S as s}from"./index-B0TN1KKO.js";function n({error:o,reset:r}){return e.jsx(s,{error:o,reset:r,scope:"session-route"})}export{n as errorComponent};
@@ -1 +1 @@
1
- import{R as o,j as e,r}from"./index-B__qT0Yd.js";import{P as a}from"./ProxyViewerContainer-Buu8vkCK.js";function m(){const{sessionId:t}=o.useParams();return e.jsx(i,{sessionId:t})}function i({sessionId:t}){const[s,n]=r.useState(!1);return r.useEffect(()=>{n(!0)},[]),s?e.jsx(a,{initialSessionId:t},t):e.jsx("main",{className:"min-h-screen bg-background text-foreground",children:e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-2xl flex-col justify-center px-6 py-16 text-center",children:e.jsxs("div",{className:"rounded-[8px] border border-border bg-card px-4 py-8 shadow-sm",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Loading session data..."}),e.jsx("p",{className:"mt-3 inline-block max-w-full break-all rounded bg-muted px-3 py-1 font-mono text-xs text-muted-foreground",children:t})]})})})}export{m as component};
1
+ import{R as o,j as e,r}from"./index-B0TN1KKO.js";import{P as a}from"./ProxyViewerContainer-6twNZHwl.js";function m(){const{sessionId:t}=o.useParams();return e.jsx(i,{sessionId:t})}function i({sessionId:t}){const[s,n]=r.useState(!1);return r.useEffect(()=>{n(!0)},[]),s?e.jsx(a,{initialSessionId:t},t):e.jsx("main",{className:"min-h-screen bg-background text-foreground",children:e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-2xl flex-col justify-center px-6 py-16 text-center",children:e.jsxs("div",{className:"rounded-[8px] border border-border bg-card px-4 py-8 shadow-sm",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Loading session data..."}),e.jsx("p",{className:"mt-3 inline-block max-w-full break-all rounded bg-muted px-3 py-1 font-mono text-xs text-muted-foreground",children:t})]})})})}export{m as component};