@tonyclaw/agent-inspector 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.output/backend/nitro.json +1 -1
- package/.output/cli.js +193 -110
- package/.output/server/_ssr/index.mjs +1 -1
- package/.output/server/_ssr/{router-CTHqmroT.mjs → router-ChILzhmz.mjs} +92 -4
- package/.output/server/index.mjs +1 -1
- package/.output/ui/assets/{CompareDrawer-L3n4J-Or.js → CompareDrawer-Co3cUF_I.js} +1 -1
- package/.output/ui/assets/{InspectorPet-D5o_3OZS.js → InspectorPet-jFcrL37X.js} +1 -1
- package/.output/ui/assets/{ProxyViewerContainer-Ocagx75S.js → ProxyViewerContainer-BPzt_VpM.js} +4 -4
- package/.output/ui/assets/{ReplayDialog-Bk7x1h-y.js → ReplayDialog-C6O_zuwI.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-U4lzL7Sc.js → RequestAnatomy-Ca6NvB7L.js} +1 -1
- package/.output/ui/assets/{ResponseView-LOWfvBLK.js → ResponseView-BzqKcveJ.js} +1 -1
- package/.output/ui/assets/{StreamingChunkSequence-DPfsrrXQ.js → StreamingChunkSequence-9pCZIsS_.js} +1 -1
- package/.output/ui/assets/{_sessionId-0MlWS-CO.js → _sessionId-BMP3KVGR.js} +1 -1
- package/.output/ui/assets/{_sessionId-OdX2Jvt1.js → _sessionId-y4eRoT1H.js} +1 -1
- package/.output/ui/assets/{index-Ea-c8hPg.js → index-CH5w-haG.js} +1 -1
- package/.output/ui/assets/{index-zVVS53Hd.js → index-CmocEhyU.js} +1 -1
- package/.output/ui/assets/{index-Du4qNOOt.js → index-DT8sMJ_n.js} +2 -2
- package/.output/ui/assets/{index-gvFj_9K6.js → index-bfsbIRZa.js} +1 -1
- package/.output/ui/assets/{json-viewer-C1WAMzg3.js → json-viewer-BfFOSDG5.js} +1 -1
- package/.output/ui/assets/{jszip.min-B8AKu2zm.js → jszip.min-BkbVkOsp.js} +1 -1
- package/.output/ui/index.html +1 -1
- package/package.json +5 -10
- package/src/assets/IDE/claudecode-color.svg +0 -1
- package/src/assets/IDE/codex-color.svg +0 -1
- package/src/assets/IDE/opencode.svg +0 -1
- package/src/assets/IDE/xiaomimimo.svg +0 -1
- package/src/assets/favicon.svg +0 -21
- package/src/assets/logos/alibaba.svg +0 -1
- package/src/assets/logos/anthropic.svg +0 -1
- package/src/assets/logos/claude-code.svg +0 -4
- package/src/assets/logos/deepseek.svg +0 -1
- package/src/assets/logos/minimax.jpeg +0 -0
- package/src/assets/logos/openai.svg +0 -1
- package/src/assets/logos/opencode.svg +0 -4
- package/src/assets/logos/qwen.webp +0 -0
- package/src/assets/logos/zhipuai.svg +0 -219
- package/src/backend/router.tsx +0 -36
- package/src/backend/routes/$.ts +0 -26
- package/src/backend/routes/__root.ts +0 -4
- package/src/backend/routes/api/-instances.ts +0 -7
- package/src/backend/routes/api/alerts.summary.ts +0 -28
- package/src/backend/routes/api/alerts.ts +0 -70
- package/src/backend/routes/api/config.paths.ts +0 -14
- package/src/backend/routes/api/config.ts +0 -73
- package/src/backend/routes/api/ecosystem.packages.$packageId.help.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.install.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.runner-presets.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.$packageId.upgrade.ts +0 -11
- package/src/backend/routes/api/ecosystem.packages.ts +0 -21
- package/src/backend/routes/api/ecosystem.recipes.$recipeId.run.ts +0 -11
- package/src/backend/routes/api/ecosystem.tasks.$taskId.ts +0 -16
- package/src/backend/routes/api/ecosystem.tasks.ts +0 -12
- package/src/backend/routes/api/groups.$groupId.evidence.ts +0 -55
- package/src/backend/routes/api/groups.$groupId.sessions.ts +0 -50
- package/src/backend/routes/api/groups.$groupId.ts +0 -93
- package/src/backend/routes/api/groups.ts +0 -79
- package/src/backend/routes/api/health.ts +0 -22
- package/src/backend/routes/api/instances.$name.connection.ts +0 -12
- package/src/backend/routes/api/instances.$name.restart.ts +0 -23
- package/src/backend/routes/api/instances.$name.start.ts +0 -18
- package/src/backend/routes/api/instances.$name.stop.ts +0 -23
- package/src/backend/routes/api/instances.$name.ts +0 -12
- package/src/backend/routes/api/instances.ts +0 -16
- package/src/backend/routes/api/knowledge.candidates.$candidateId.promote.ts +0 -32
- package/src/backend/routes/api/knowledge.candidates.$candidateId.ts +0 -50
- package/src/backend/routes/api/knowledge.candidates.ts +0 -10
- package/src/backend/routes/api/knowledge.project-context.ts +0 -29
- package/src/backend/routes/api/knowledge.search.ts +0 -62
- package/src/backend/routes/api/knowledge.sessions.$sessionId.candidates.ts +0 -26
- package/src/backend/routes/api/logs.$id.body.ts +0 -58
- package/src/backend/routes/api/logs.$id.chunks.ts +0 -37
- package/src/backend/routes/api/logs.$id.replay.ts +0 -297
- package/src/backend/routes/api/logs.$id.ts +0 -23
- package/src/backend/routes/api/logs.import.ts +0 -39
- package/src/backend/routes/api/logs.stream.ts +0 -174
- package/src/backend/routes/api/logs.ts +0 -214
- package/src/backend/routes/api/mcp.ts +0 -25
- package/src/backend/routes/api/models.ts +0 -10
- package/src/backend/routes/api/pi-agent.ts +0 -29
- package/src/backend/routes/api/providers.$providerId.model-metadata.ts +0 -173
- package/src/backend/routes/api/providers.$providerId.test.log.ts +0 -342
- package/src/backend/routes/api/providers.$providerId.ts +0 -111
- package/src/backend/routes/api/providers.export.ts +0 -44
- package/src/backend/routes/api/providers.import.ts +0 -81
- package/src/backend/routes/api/providers.scan.ts +0 -28
- package/src/backend/routes/api/providers.ts +0 -102
- package/src/backend/routes/api/runs.$runId.evidence.ts +0 -55
- package/src/backend/routes/api/runs.$runId.ts +0 -50
- package/src/backend/routes/api/runs.ts +0 -62
- package/src/backend/routes/api/runtime.ts +0 -46
- package/src/backend/routes/api/sessions.ts +0 -51
- package/src/backend/routes/api/storage.ts +0 -56
- package/src/backend/routes/livez.ts +0 -13
- package/src/backend/routes/metrics.ts +0 -14
- package/src/backend/routes/proxy/$.ts +0 -15
- package/src/backend/routes/readyz.ts +0 -18
- package/src/backend/start.ts +0 -10
- package/src/cli/alias.ts +0 -431
- package/src/cli/detect-tools.ts +0 -123
- package/src/cli/doctor.ts +0 -836
- package/src/cli/instance.ts +0 -1071
- package/src/cli/instanceApi.ts +0 -213
- package/src/cli/instanceArgs.ts +0 -301
- package/src/cli/instanceControl.ts +0 -191
- package/src/cli/instanceModel.ts +0 -276
- package/src/cli/instanceRegistry.ts +0 -731
- package/src/cli/networkHints.ts +0 -170
- package/src/cli/onboard.ts +0 -1668
- package/src/cli/onboardTarget.ts +0 -228
- package/src/cli/rustBackendPackage.ts +0 -458
- package/src/cli/startupOutput.ts +0 -16
- package/src/cli/templates/codex-skill-onboard.ts +0 -320
- package/src/cli/templates/command-onboard.ts +0 -25
- package/src/cli/templates/skill-onboard.ts +0 -625
- package/src/cli.ts +0 -1433
- package/src/components/OnboardingBanner.tsx +0 -115
- package/src/components/ProxyViewer.tsx +0 -2259
- package/src/components/ProxyViewerContainer.tsx +0 -1076
- package/src/components/alerts/AlertsDialog.tsx +0 -615
- package/src/components/clients/ClientLogo.tsx +0 -175
- package/src/components/ecosystem/AgentLabDialog.tsx +0 -947
- package/src/components/errors/SafeErrorBoundary.tsx +0 -201
- package/src/components/groups/GroupsDialog.tsx +0 -1304
- package/src/components/inspector-pet/InspectorPet.tsx +0 -398
- package/src/components/inspector-pet/InspectorPetCrab3D.tsx +0 -455
- package/src/components/inspector-pet/inspectorPetLogic.ts +0 -272
- package/src/components/pi-agent/PiAgentPanel.tsx +0 -446
- package/src/components/pi-agent/piAgentChatLogic.ts +0 -273
- package/src/components/providers/ImportWizardDialog.tsx +0 -281
- package/src/components/providers/ProviderCard.tsx +0 -347
- package/src/components/providers/ProviderForm.tsx +0 -1183
- package/src/components/providers/ProviderLogo.tsx +0 -122
- package/src/components/providers/ProviderTestResultsView.tsx +0 -734
- package/src/components/providers/ProvidersPanel.tsx +0 -714
- package/src/components/providers/SettingsDialog.tsx +0 -1042
- package/src/components/providers/providerFormCapabilities.ts +0 -36
- package/src/components/proxy-viewer/AgentTraceSummary.tsx +0 -902
- package/src/components/proxy-viewer/AnswerMarkdown.tsx +0 -51
- package/src/components/proxy-viewer/ApplicationBar.tsx +0 -123
- package/src/components/proxy-viewer/CompareDrawer.tsx +0 -984
- package/src/components/proxy-viewer/ConversationGroup.tsx +0 -208
- package/src/components/proxy-viewer/ConversationGroupList.tsx +0 -652
- package/src/components/proxy-viewer/ConversationHeader.tsx +0 -429
- package/src/components/proxy-viewer/LiveConnectionStatus.tsx +0 -186
- package/src/components/proxy-viewer/LogEntry.tsx +0 -1419
- package/src/components/proxy-viewer/LogEntryHeader.tsx +0 -596
- package/src/components/proxy-viewer/ProviderLogoStack.tsx +0 -57
- package/src/components/proxy-viewer/RawExportWarning.tsx +0 -77
- package/src/components/proxy-viewer/ReplayDialog.tsx +0 -636
- package/src/components/proxy-viewer/RequestToolsPanel.tsx +0 -299
- package/src/components/proxy-viewer/ResponseView.tsx +0 -202
- package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +0 -61
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +0 -265
- package/src/components/proxy-viewer/ThreadConnector.tsx +0 -165
- package/src/components/proxy-viewer/ToolTraceEvents.tsx +0 -64
- package/src/components/proxy-viewer/TurnGroup.tsx +0 -383
- package/src/components/proxy-viewer/TurnGroupList.tsx +0 -156
- package/src/components/proxy-viewer/accessibility.ts +0 -8
- package/src/components/proxy-viewer/anatomy/RequestAnatomy.tsx +0 -887
- package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +0 -222
- package/src/components/proxy-viewer/anatomy/contextIntelligence.ts +0 -737
- package/src/components/proxy-viewer/anatomy/sessionContextSummary.ts +0 -268
- package/src/components/proxy-viewer/anatomy/tokenEstimate.ts +0 -53
- package/src/components/proxy-viewer/anatomy/types.ts +0 -41
- package/src/components/proxy-viewer/anatomy/useAnatomyJump.ts +0 -114
- package/src/components/proxy-viewer/bodyHydration.ts +0 -123
- package/src/components/proxy-viewer/cacheTrend.ts +0 -50
- package/src/components/proxy-viewer/diff/DiffView.tsx +0 -321
- package/src/components/proxy-viewer/diff/computeDiff.ts +0 -178
- package/src/components/proxy-viewer/diff/index.ts +0 -3
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +0 -194
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +0 -81
- package/src/components/proxy-viewer/formats/anthropic/thinkingExtract.ts +0 -21
- package/src/components/proxy-viewer/formats/index.tsx +0 -47
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +0 -442
- package/src/components/proxy-viewer/index.ts +0 -9
- package/src/components/proxy-viewer/lazy.ts +0 -41
- package/src/components/proxy-viewer/liveConnectionState.ts +0 -158
- package/src/components/proxy-viewer/log-formats/anthropic.ts +0 -191
- package/src/components/proxy-viewer/log-formats/index.ts +0 -23
- package/src/components/proxy-viewer/log-formats/openai.ts +0 -256
- package/src/components/proxy-viewer/log-formats/types.ts +0 -40
- package/src/components/proxy-viewer/log-formats/unknown.ts +0 -18
- package/src/components/proxy-viewer/logEntryVisibility.ts +0 -73
- package/src/components/proxy-viewer/logFocus.ts +0 -54
- package/src/components/proxy-viewer/proxyViewerContainerLogic.ts +0 -124
- package/src/components/proxy-viewer/proxyViewerLogic.ts +0 -488
- package/src/components/proxy-viewer/replayComparison.ts +0 -131
- package/src/components/proxy-viewer/requestDiff.ts +0 -277
- package/src/components/proxy-viewer/requestTools.ts +0 -220
- package/src/components/proxy-viewer/useCopyFeedback.ts +0 -38
- package/src/components/proxy-viewer/useKeyboardNavigation.ts +0 -232
- package/src/components/proxy-viewer/viewerState.ts +0 -176
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/button.tsx +0 -47
- package/src/components/ui/collapsible.tsx +0 -21
- package/src/components/ui/confirm-dialog.tsx +0 -51
- package/src/components/ui/crab-logo.tsx +0 -45
- package/src/components/ui/crab-variants.tsx +0 -467
- package/src/components/ui/dialog.tsx +0 -130
- package/src/components/ui/icon-trigger.ts +0 -2
- package/src/components/ui/json-viewer-bulk.ts +0 -132
- package/src/components/ui/json-viewer.tsx +0 -508
- package/src/components/ui/scroll-area.tsx +0 -54
- package/src/components/ui/select.tsx +0 -178
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/tabs.tsx +0 -88
- package/src/components/ui/tooltip.tsx +0 -51
- package/src/components/ui/transient-toast.tsx +0 -105
- package/src/contracts/anthropic.ts +0 -230
- package/src/contracts/index.ts +0 -59
- package/src/contracts/json.ts +0 -37
- package/src/contracts/log.ts +0 -139
- package/src/contracts/openai.ts +0 -267
- package/src/index.css +0 -11
- package/src/knowledge/candidateStore.ts +0 -94
- package/src/knowledge/distiller.ts +0 -98
- package/src/knowledge/openclawClient.ts +0 -161
- package/src/knowledge/openclawGatewayClient.ts +0 -249
- package/src/knowledge/openclawMarkdown.ts +0 -146
- package/src/knowledge/redactor.ts +0 -80
- package/src/knowledge/types.ts +0 -83
- package/src/lib/alertContract.ts +0 -76
- package/src/lib/apiClient.ts +0 -166
- package/src/lib/apiFormat.ts +0 -29
- package/src/lib/backendImplementation.ts +0 -16
- package/src/lib/basePath.ts +0 -107
- package/src/lib/browserRuntimeContract.ts +0 -124
- package/src/lib/browserRuntimeResolver.ts +0 -333
- package/src/lib/chunkLoadRecovery.ts +0 -83
- package/src/lib/claudeCodeStrip.ts +0 -98
- package/src/lib/clipboard.ts +0 -67
- package/src/lib/codingAgentEndpoints.ts +0 -54
- package/src/lib/ecosystemContract.ts +0 -130
- package/src/lib/export-logs.ts +0 -287
- package/src/lib/groupContract.ts +0 -166
- package/src/lib/instanceContract.ts +0 -239
- package/src/lib/jsonFile.ts +0 -46
- package/src/lib/logImportContract.ts +0 -12
- package/src/lib/managedInstance.ts +0 -112
- package/src/lib/mask.ts +0 -4
- package/src/lib/objectUtils.ts +0 -22
- package/src/lib/piAgentContract.ts +0 -102
- package/src/lib/providerContract.ts +0 -125
- package/src/lib/providerImportContract.ts +0 -27
- package/src/lib/providerModelMetadata.ts +0 -458
- package/src/lib/providerTestContract.ts +0 -170
- package/src/lib/providerTestPrompt.ts +0 -100
- package/src/lib/publicBasePathContext.ts +0 -137
- package/src/lib/resourceLimits.ts +0 -345
- package/src/lib/runContract.ts +0 -164
- package/src/lib/runtimeConfig.ts +0 -43
- package/src/lib/safeDiagnostic.ts +0 -38
- package/src/lib/safeFetch.ts +0 -508
- package/src/lib/serverPort.ts +0 -47
- package/src/lib/sessionInfoContract.ts +0 -78
- package/src/lib/sessionUrl.ts +0 -46
- package/src/lib/ssrfGuard.ts +0 -133
- package/src/lib/stopReason.ts +0 -130
- package/src/lib/themeMode.ts +0 -41
- package/src/lib/timeDisplay.ts +0 -22
- package/src/lib/toolTrace.ts +0 -290
- package/src/lib/uiScale.ts +0 -117
- package/src/lib/unknown.ts +0 -27
- package/src/lib/upstreamUrl.ts +0 -150
- package/src/lib/useAlerts.ts +0 -82
- package/src/lib/useGroupEvidence.ts +0 -37
- package/src/lib/useGroups.ts +0 -32
- package/src/lib/useOnboarding.ts +0 -93
- package/src/lib/useProviders.ts +0 -30
- package/src/lib/useStripConfig.ts +0 -154
- package/src/lib/useThemeMode.ts +0 -40
- package/src/lib/useUiScale.ts +0 -52
- package/src/lib/utils.ts +0 -78
- package/src/mcp/currentContext.ts +0 -65
- package/src/mcp/instanceHandlers.ts +0 -151
- package/src/mcp/loopback.ts +0 -88
- package/src/mcp/mode.ts +0 -75
- package/src/mcp/previewExtractor.ts +0 -233
- package/src/mcp/server.ts +0 -2274
- package/src/mcp/toolHandlers.ts +0 -1533
- package/src/proxy/alerts.ts +0 -664
- package/src/proxy/chunkStorage.ts +0 -123
- package/src/proxy/config.ts +0 -218
- package/src/proxy/constants.ts +0 -66
- package/src/proxy/dataDir.ts +0 -147
- package/src/proxy/ecosystemExecutionConfirmation.ts +0 -114
- package/src/proxy/ecosystemExecutionRoute.ts +0 -116
- package/src/proxy/ecosystemRegistry.ts +0 -296
- package/src/proxy/ecosystemTasks.ts +0 -415
- package/src/proxy/evidenceAnalysis.ts +0 -526
- package/src/proxy/evidenceExporter.ts +0 -235
- package/src/proxy/formats/anthropic/anthropicProvider.ts +0 -75
- package/src/proxy/formats/anthropic/handler.ts +0 -75
- package/src/proxy/formats/anthropic/index.ts +0 -13
- package/src/proxy/formats/anthropic/register.ts +0 -4
- package/src/proxy/formats/anthropic/schemas.ts +0 -6
- package/src/proxy/formats/anthropic/stream.ts +0 -205
- package/src/proxy/formats/handler.ts +0 -46
- package/src/proxy/formats/index.ts +0 -13
- package/src/proxy/formats/jsonSchema.ts +0 -2
- package/src/proxy/formats/openai/alibabaProvider.ts +0 -34
- package/src/proxy/formats/openai/codexMetadata.ts +0 -61
- package/src/proxy/formats/openai/handler.ts +0 -133
- package/src/proxy/formats/openai/index.ts +0 -33
- package/src/proxy/formats/openai/provider.ts +0 -50
- package/src/proxy/formats/openai/register.ts +0 -4
- package/src/proxy/formats/openai/schemas.ts +0 -25
- package/src/proxy/formats/openai/stream.ts +0 -600
- package/src/proxy/formats/openai/zhipuProvider.ts +0 -31
- package/src/proxy/formats/providerAdapter.ts +0 -50
- package/src/proxy/formats/providerRegistry.ts +0 -51
- package/src/proxy/formats/providers/index.ts +0 -3
- package/src/proxy/formats/registry.ts +0 -65
- package/src/proxy/groupEvidenceExporter.ts +0 -371
- package/src/proxy/groupStore.ts +0 -336
- package/src/proxy/handler.ts +0 -729
- package/src/proxy/identityProxy.ts +0 -1842
- package/src/proxy/jsonlRecovery.ts +0 -554
- package/src/proxy/logBodyChunks.ts +0 -91
- package/src/proxy/logFinalizer.ts +0 -777
- package/src/proxy/logFinalizer.worker.ts +0 -24
- package/src/proxy/logImportUpload.ts +0 -128
- package/src/proxy/logImporter.ts +0 -813
- package/src/proxy/logIndex.ts +0 -663
- package/src/proxy/logSearch.ts +0 -122
- package/src/proxy/logger.ts +0 -537
- package/src/proxy/openaiOrphanToolStrip.ts +0 -142
- package/src/proxy/platformCommands.ts +0 -258
- package/src/proxy/privateDataPath.ts +0 -419
- package/src/proxy/providerImporters.ts +0 -578
- package/src/proxy/providerScanStore.ts +0 -87
- package/src/proxy/providerSecretStore.ts +0 -216
- package/src/proxy/providers.ts +0 -998
- package/src/proxy/rawStreamCapture.ts +0 -342
- package/src/proxy/runFailures.ts +0 -94
- package/src/proxy/runStore.ts +0 -214
- package/src/proxy/runtimeAdmission.ts +0 -55
- package/src/proxy/runtimeHealth.ts +0 -221
- package/src/proxy/runtimeMetrics.ts +0 -149
- package/src/proxy/runtimeShutdown.ts +0 -157
- package/src/proxy/schemas.ts +0 -112
- package/src/proxy/sessionArchive.ts +0 -479
- package/src/proxy/sessionInfo.ts +0 -266
- package/src/proxy/sessionProcess.ts +0 -194
- package/src/proxy/sessionRuntime.ts +0 -121
- package/src/proxy/sessionSupervisor.ts +0 -305
- package/src/proxy/sessionWorkerEntry.ts +0 -26
- package/src/proxy/shutdownCoordinator.ts +0 -90
- package/src/proxy/socketTracker.ts +0 -639
- package/src/proxy/sqliteLogIndex.ts +0 -733
- package/src/proxy/storageLifecycle.ts +0 -432
- package/src/proxy/store.ts +0 -1773
- package/src/proxy/streamTiming.ts +0 -31
- package/src/proxy/toolSchemaWarnings.ts +0 -529
- package/src/proxy/uiAssetServer.ts +0 -106
- package/src/proxy/upstream.ts +0 -127
- package/src/services/alerts.ts +0 -12
- package/src/services/groups.ts +0 -119
- package/src/services/piAgent.ts +0 -421
- package/src/services/piAgentRetrieval.ts +0 -1180
- package/src/services/result.ts +0 -17
- package/src/services/runs.ts +0 -76
- package/src/ui/bootstrap.ts +0 -167
- package/src/ui/index.html +0 -38
- package/src/ui/logsStreamClient.ts +0 -20
- package/src/ui/main.tsx +0 -13
- package/src/ui/public/runtime-config.js +0 -2
- package/src/ui/router.tsx +0 -13
- package/src/ui/routes/__root.tsx +0 -69
- package/src/ui/routes/index.tsx +0 -35
- package/src/ui/routes/session/$sessionId.tsx +0 -50
- package/src/ui/runtimeDiscovery.ts +0 -50
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import type { ProviderConfig } from "../../../lib/providerContract";
|
|
2
|
-
import type { CapturedLog } from "../../../contracts";
|
|
3
|
-
import { getLogFormatAdapter, resolveLogFormat } from "../log-formats";
|
|
4
|
-
import {
|
|
5
|
-
analyzeContextIntelligence,
|
|
6
|
-
type ContextHealth,
|
|
7
|
-
type ContextRiskLevel,
|
|
8
|
-
type ContextWindow,
|
|
9
|
-
type RoleUsage,
|
|
10
|
-
} from "./contextIntelligence";
|
|
11
|
-
import type { AnatomySegment } from "./types";
|
|
12
|
-
|
|
13
|
-
export type SessionContextSnapshot = {
|
|
14
|
-
logId: number;
|
|
15
|
-
model: string;
|
|
16
|
-
timestamp: string;
|
|
17
|
-
contextWindow: ContextWindow;
|
|
18
|
-
estimatedInputTokens: number;
|
|
19
|
-
windowUsedTokens: number | null;
|
|
20
|
-
usagePercent: number | null;
|
|
21
|
-
riskLevel: ContextRiskLevel;
|
|
22
|
-
health: ContextHealth;
|
|
23
|
-
diagnostics: string[];
|
|
24
|
-
roleSegments: AnatomySegment[];
|
|
25
|
-
roleTotalTokens: number;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type SessionModelContextSummary = {
|
|
29
|
-
model: string;
|
|
30
|
-
requestCount: number;
|
|
31
|
-
first: SessionContextSnapshot;
|
|
32
|
-
latest: SessionContextSnapshot;
|
|
33
|
-
peak: SessionContextSnapshot;
|
|
34
|
-
trendPercent: number | null;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type SessionContextSummary = {
|
|
38
|
-
models: SessionModelContextSummary[];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type SummaryAccumulator = {
|
|
42
|
-
model: string;
|
|
43
|
-
requestCount: number;
|
|
44
|
-
first: SessionContextSnapshot;
|
|
45
|
-
latest: SessionContextSnapshot;
|
|
46
|
-
peak: SessionContextSnapshot;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type SnapshotCacheEntry = {
|
|
50
|
-
id: number;
|
|
51
|
-
rawRequestBody: string | null;
|
|
52
|
-
inputTokens: number | null;
|
|
53
|
-
model: string | null;
|
|
54
|
-
path: string;
|
|
55
|
-
apiFormat: CapturedLog["apiFormat"];
|
|
56
|
-
timestamp: string;
|
|
57
|
-
providersSignature: string;
|
|
58
|
-
snapshot: SessionContextSnapshot | null;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const snapshotCache = new WeakMap<CapturedLog, SnapshotCacheEntry>();
|
|
62
|
-
|
|
63
|
-
function providerSignature(providers: readonly ProviderConfig[]): string {
|
|
64
|
-
return providers
|
|
65
|
-
.map((provider) => {
|
|
66
|
-
const metadata =
|
|
67
|
-
provider.modelMetadata
|
|
68
|
-
?.map((entry) => `${entry.model}:${String(entry.contextWindow ?? "")}`)
|
|
69
|
-
.join(",") ?? "";
|
|
70
|
-
return `${provider.id}:${provider.updatedAt}:${provider.models.join(",")}:${metadata}`;
|
|
71
|
-
})
|
|
72
|
-
.join("|");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function parseRequestBody(rawBody: string | null): unknown | null {
|
|
76
|
-
if (rawBody === null) return null;
|
|
77
|
-
try {
|
|
78
|
-
const parsed: unknown = JSON.parse(rawBody);
|
|
79
|
-
return parsed;
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function roleUsageSegment(usage: RoleUsage): AnatomySegment {
|
|
86
|
-
return {
|
|
87
|
-
role: usage.role,
|
|
88
|
-
label: usage.label,
|
|
89
|
-
size: usage.tokens,
|
|
90
|
-
characters: usage.tokens * 4,
|
|
91
|
-
text: "",
|
|
92
|
-
path: `role:${usage.role}`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function snapshotFromLog(
|
|
97
|
-
log: CapturedLog,
|
|
98
|
-
providers: readonly ProviderConfig[],
|
|
99
|
-
): SessionContextSnapshot | null {
|
|
100
|
-
const parsed = parseRequestBody(log.rawRequestBody);
|
|
101
|
-
if (parsed === null) return null;
|
|
102
|
-
|
|
103
|
-
const adapter = getLogFormatAdapter(resolveLogFormat(log));
|
|
104
|
-
const segments = adapter.anatomySegments(parsed);
|
|
105
|
-
if (segments === null) return null;
|
|
106
|
-
|
|
107
|
-
const intelligence = analyzeContextIntelligence({
|
|
108
|
-
segments,
|
|
109
|
-
inputTokens: log.inputTokens ?? null,
|
|
110
|
-
parsed,
|
|
111
|
-
model: log.model,
|
|
112
|
-
providers,
|
|
113
|
-
});
|
|
114
|
-
const model = intelligence.model ?? log.model ?? "Unknown model";
|
|
115
|
-
const roleSegments = intelligence.roleUsages.map(roleUsageSegment);
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
logId: log.id,
|
|
119
|
-
model,
|
|
120
|
-
timestamp: log.timestamp,
|
|
121
|
-
contextWindow: intelligence.contextWindow,
|
|
122
|
-
estimatedInputTokens: intelligence.estimatedInputTokens,
|
|
123
|
-
windowUsedTokens: intelligence.windowUsedTokens,
|
|
124
|
-
usagePercent: intelligence.usagePercent,
|
|
125
|
-
riskLevel: intelligence.riskLevel,
|
|
126
|
-
health: intelligence.health,
|
|
127
|
-
diagnostics: intelligence.diagnostics.map((diagnostic) => diagnostic.title),
|
|
128
|
-
roleSegments,
|
|
129
|
-
roleTotalTokens: roleSegments.reduce((sum, segment) => sum + segment.size, 0),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function cachedSnapshotFromLog(
|
|
134
|
-
log: CapturedLog,
|
|
135
|
-
providers: readonly ProviderConfig[],
|
|
136
|
-
providersSignature: string,
|
|
137
|
-
): SessionContextSnapshot | null {
|
|
138
|
-
const cached = snapshotCache.get(log);
|
|
139
|
-
if (
|
|
140
|
-
cached !== undefined &&
|
|
141
|
-
cached.id === log.id &&
|
|
142
|
-
cached.rawRequestBody === log.rawRequestBody &&
|
|
143
|
-
cached.inputTokens === log.inputTokens &&
|
|
144
|
-
cached.model === log.model &&
|
|
145
|
-
cached.path === log.path &&
|
|
146
|
-
cached.apiFormat === log.apiFormat &&
|
|
147
|
-
cached.timestamp === log.timestamp &&
|
|
148
|
-
cached.providersSignature === providersSignature
|
|
149
|
-
) {
|
|
150
|
-
return cached.snapshot;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const snapshot = snapshotFromLog(log, providers);
|
|
154
|
-
snapshotCache.set(log, {
|
|
155
|
-
id: log.id,
|
|
156
|
-
rawRequestBody: log.rawRequestBody,
|
|
157
|
-
inputTokens: log.inputTokens,
|
|
158
|
-
model: log.model,
|
|
159
|
-
path: log.path,
|
|
160
|
-
apiFormat: log.apiFormat,
|
|
161
|
-
timestamp: log.timestamp,
|
|
162
|
-
providersSignature,
|
|
163
|
-
snapshot,
|
|
164
|
-
});
|
|
165
|
-
return snapshot;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function isHigherPeak(candidate: SessionContextSnapshot, current: SessionContextSnapshot): boolean {
|
|
169
|
-
if (candidate.usagePercent !== null && current.usagePercent !== null) {
|
|
170
|
-
return candidate.usagePercent > current.usagePercent;
|
|
171
|
-
}
|
|
172
|
-
if (candidate.usagePercent !== null && current.usagePercent === null) return true;
|
|
173
|
-
if (candidate.usagePercent === null && current.usagePercent !== null) return false;
|
|
174
|
-
return candidate.estimatedInputTokens > current.estimatedInputTokens;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function riskRank(risk: ContextRiskLevel): number {
|
|
178
|
-
switch (risk) {
|
|
179
|
-
case "danger":
|
|
180
|
-
return 4;
|
|
181
|
-
case "watch":
|
|
182
|
-
return 3;
|
|
183
|
-
case "unknown":
|
|
184
|
-
return 2;
|
|
185
|
-
case "ok":
|
|
186
|
-
return 1;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function compareModelSummary(
|
|
191
|
-
left: SessionModelContextSummary,
|
|
192
|
-
right: SessionModelContextSummary,
|
|
193
|
-
): number {
|
|
194
|
-
const riskDelta = riskRank(right.latest.riskLevel) - riskRank(left.latest.riskLevel);
|
|
195
|
-
if (riskDelta !== 0) return riskDelta;
|
|
196
|
-
|
|
197
|
-
const leftPeak = left.peak.usagePercent ?? -1;
|
|
198
|
-
const rightPeak = right.peak.usagePercent ?? -1;
|
|
199
|
-
const peakDelta = rightPeak - leftPeak;
|
|
200
|
-
if (peakDelta !== 0) return peakDelta;
|
|
201
|
-
|
|
202
|
-
return right.latest.logId - left.latest.logId;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function trendPercent(
|
|
206
|
-
first: SessionContextSnapshot,
|
|
207
|
-
latest: SessionContextSnapshot,
|
|
208
|
-
): number | null {
|
|
209
|
-
if (first.usagePercent === null || latest.usagePercent === null) return null;
|
|
210
|
-
return (latest.usagePercent - first.usagePercent) * 100;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function logsInAscendingIdOrder(logs: readonly CapturedLog[]): readonly CapturedLog[] {
|
|
214
|
-
for (let index = 1; index < logs.length; index++) {
|
|
215
|
-
const previous = logs[index - 1];
|
|
216
|
-
const current = logs[index];
|
|
217
|
-
if (previous === undefined || current === undefined) continue;
|
|
218
|
-
if (previous.id > current.id) return [...logs].sort((left, right) => left.id - right.id);
|
|
219
|
-
}
|
|
220
|
-
return logs;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function buildSessionContextSummary(
|
|
224
|
-
logs: readonly CapturedLog[],
|
|
225
|
-
providers: readonly ProviderConfig[] = [],
|
|
226
|
-
): SessionContextSummary {
|
|
227
|
-
const sortedLogs = logsInAscendingIdOrder(logs);
|
|
228
|
-
const providersSignature = providerSignature(providers);
|
|
229
|
-
const byModel = new Map<string, SummaryAccumulator>();
|
|
230
|
-
|
|
231
|
-
for (const log of sortedLogs) {
|
|
232
|
-
const snapshot = cachedSnapshotFromLog(log, providers, providersSignature);
|
|
233
|
-
if (snapshot === null) continue;
|
|
234
|
-
|
|
235
|
-
const existing = byModel.get(snapshot.model);
|
|
236
|
-
if (existing === undefined) {
|
|
237
|
-
byModel.set(snapshot.model, {
|
|
238
|
-
model: snapshot.model,
|
|
239
|
-
requestCount: 1,
|
|
240
|
-
first: snapshot,
|
|
241
|
-
latest: snapshot,
|
|
242
|
-
peak: snapshot,
|
|
243
|
-
});
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
byModel.set(snapshot.model, {
|
|
248
|
-
model: existing.model,
|
|
249
|
-
requestCount: existing.requestCount + 1,
|
|
250
|
-
first: existing.first,
|
|
251
|
-
latest: snapshot,
|
|
252
|
-
peak: isHigherPeak(snapshot, existing.peak) ? snapshot : existing.peak,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const models = [...byModel.values()]
|
|
257
|
-
.map((entry) => ({
|
|
258
|
-
model: entry.model,
|
|
259
|
-
requestCount: entry.requestCount,
|
|
260
|
-
first: entry.first,
|
|
261
|
-
latest: entry.latest,
|
|
262
|
-
peak: entry.peak,
|
|
263
|
-
trendPercent: trendPercent(entry.first, entry.latest),
|
|
264
|
-
}))
|
|
265
|
-
.sort(compareModelSummary);
|
|
266
|
-
|
|
267
|
-
return { models };
|
|
268
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Blended 4-chars-per-token heuristic with CJK / emoji adjustment.
|
|
3
|
-
*
|
|
4
|
-
* Rationale: Anthropic and OpenAI both document ~4 chars/token for
|
|
5
|
-
* English / Latin / punctuation. CJK characters, Hangul, kana, fullwidth
|
|
6
|
-
* forms, and emoji tokenize roughly 1:1 in practice. We use a simple
|
|
7
|
-
* two-bucket counter rather than a full BPE tokenizer to keep the
|
|
8
|
-
* estimate cheap and synchronous — the result is shown with a leading
|
|
9
|
-
* `~` so the user is never misled about precision.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** A single Unicode code-point character from `text`. */
|
|
13
|
-
function forEachCodePoint(text: string, visit: (ch: string) => void): void {
|
|
14
|
-
// `Array.from` iterates by code point, so surrogate pairs and
|
|
15
|
-
// combining marks stay together.
|
|
16
|
-
for (const ch of Array.from(text)) {
|
|
17
|
-
visit(ch);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const CJK_REGEX = /[\u3000-\u9FFF\uAC00-\uD7FF\uF900-\uFAFF\uFF00-\uFFEF\u{1F300}-\u{1FAFF}]/u;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Estimate the token count of a piece of text.
|
|
25
|
-
*
|
|
26
|
-
* - CJK / Hangul / kana / fullwidth / emoji → 1 token per character
|
|
27
|
-
* - Everything else → 1 token per 4 characters, rounded up
|
|
28
|
-
*
|
|
29
|
-
* Returns 0 for the empty string.
|
|
30
|
-
*/
|
|
31
|
-
export function estimateTokens(text: string): number {
|
|
32
|
-
if (text.length === 0) return 0;
|
|
33
|
-
let cjk = 0;
|
|
34
|
-
let other = 0;
|
|
35
|
-
forEachCodePoint(text, (ch) => {
|
|
36
|
-
if (CJK_REGEX.test(ch)) {
|
|
37
|
-
cjk += 1;
|
|
38
|
-
} else {
|
|
39
|
-
other += 1;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return Math.ceil(cjk * 1) + Math.ceil(other / 4);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Count Unicode code points in a string (graphemes ≈ characters for our purposes). */
|
|
46
|
-
export function countCharacters(text: string): number {
|
|
47
|
-
if (text.length === 0) return 0;
|
|
48
|
-
let n = 0;
|
|
49
|
-
forEachCodePoint(text, () => {
|
|
50
|
-
n += 1;
|
|
51
|
-
});
|
|
52
|
-
return n;
|
|
53
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Role of a request segment. Drives the segment's color in the context bar.
|
|
3
|
-
*
|
|
4
|
-
* - `system`: the system prompt (Anthropic `system`, or leading system-role message in OpenAI)
|
|
5
|
-
* - `user`: a user-role message
|
|
6
|
-
* - `assistant`: an assistant-role message
|
|
7
|
-
* - `tool`: a tool-role message (OpenAI only; Anthropic uses tool_result blocks inside user messages)
|
|
8
|
-
* - `tools`: the synthetic tool definitions segment that aggregates the `tools` array
|
|
9
|
-
*/
|
|
10
|
-
export type AnatomyRole = "system" | "user" | "assistant" | "tool" | "tools";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A single segment of a request as visualized in the request context tab.
|
|
14
|
-
*
|
|
15
|
-
* `path` is a JSON-pointer-style path into the parsed body
|
|
16
|
-
* (e.g. `/system`, `/messages/0`, `/tools`). The path is opaque to
|
|
17
|
-
* consumers: it is matched against the same path emitted by the request
|
|
18
|
-
* analyzer and is used to drive click-to-jump in the `JsonViewer`.
|
|
19
|
-
*/
|
|
20
|
-
export type AnatomySegment = {
|
|
21
|
-
/** Stable role used for color and label prefix. */
|
|
22
|
-
role: AnatomyRole;
|
|
23
|
-
/** Human-readable short label shown below the segment (e.g. "system", "[3] user", "tools"). */
|
|
24
|
-
label: string;
|
|
25
|
-
/** Estimated token count for this segment. Drives bar width. */
|
|
26
|
-
size: number;
|
|
27
|
-
/** Character count for this segment (raw text length). Used in the tooltip. */
|
|
28
|
-
characters: number;
|
|
29
|
-
/** Raw text of the segment used to compute `size`. Used in the tooltip preview. */
|
|
30
|
-
text: string;
|
|
31
|
-
/** JSON-pointer-style path into the parsed body (e.g. `/messages/3`). */
|
|
32
|
-
path: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const ANATOMY_ROLE_LABELS: Record<AnatomyRole, string> = {
|
|
36
|
-
system: "System",
|
|
37
|
-
user: "User",
|
|
38
|
-
assistant: "Assistant",
|
|
39
|
-
tool: "Tool Results",
|
|
40
|
-
tools: "Tool Definitions",
|
|
41
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { type RefObject, useCallback, useRef } from "react";
|
|
2
|
-
import type { AnatomySegment } from "./types";
|
|
3
|
-
|
|
4
|
-
const HIGHLIGHT_DURATION_MS = 1200;
|
|
5
|
-
/**
|
|
6
|
-
* Cap on the number of animation frames we are willing to wait
|
|
7
|
-
* before giving up on finding the target row. Each frame is
|
|
8
|
-
* ~16ms at 60Hz, so 12 frames gives ~200ms — enough headroom for
|
|
9
|
-
* the cascade of `useEffect` -> `setExpanded` calls that fires
|
|
10
|
-
* for each ancestor on the way down to the target.
|
|
11
|
-
*/
|
|
12
|
-
const MAX_HIGHLIGHT_ATTEMPTS = 12;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Build a `jumpToSegment` callback that:
|
|
16
|
-
*
|
|
17
|
-
* 1. Optionally switches the active tab to the Request tab (so the
|
|
18
|
-
* target row is in the DOM and visible).
|
|
19
|
-
* 2. Asks the JSON viewer to expand the path's ancestors via the
|
|
20
|
-
* `expandToPath` prop (which is reset to `null` shortly after).
|
|
21
|
-
* 3. Polls via `requestAnimationFrame` for the target row to appear
|
|
22
|
-
* (the cascade of `useEffect` -> `setExpanded` calls needs
|
|
23
|
-
* multiple frames for deep paths), then scrolls the matching
|
|
24
|
-
* row into view and applies a 1.2 s primary-color ring
|
|
25
|
-
* highlight via a temporary class toggle.
|
|
26
|
-
*/
|
|
27
|
-
export function useAnatomyJump(options: {
|
|
28
|
-
/** Ref to the DOM root that contains the JSON tree rows. */
|
|
29
|
-
containerRef: RefObject<HTMLElement | null>;
|
|
30
|
-
/** Setter for the `JsonViewer`'s `expandToPath` prop. */
|
|
31
|
-
setExpandToPath: (path: string | null) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Optional hook called before the DOM lookup so the caller can
|
|
34
|
-
* make the Request tab active. The hook should be synchronous
|
|
35
|
-
* (it triggers a React state update which is flushed by the
|
|
36
|
-
* subsequent `requestAnimationFrame`).
|
|
37
|
-
*/
|
|
38
|
-
ensureTabActive?: () => void;
|
|
39
|
-
highlightMs?: number;
|
|
40
|
-
}): (segment: AnatomySegment) => void {
|
|
41
|
-
const { containerRef, setExpandToPath, ensureTabActive, highlightMs } = options;
|
|
42
|
-
const highlightTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
43
|
-
|
|
44
|
-
return useCallback(
|
|
45
|
-
(segment: AnatomySegment) => {
|
|
46
|
-
ensureTabActive?.();
|
|
47
|
-
|
|
48
|
-
// Trigger the JSON viewer to expand ancestors of this path.
|
|
49
|
-
// We pass the same path; the JsonViewer resets the prop via
|
|
50
|
-
// the caller clearing the state after the scroll lands.
|
|
51
|
-
setExpandToPath(segment.path);
|
|
52
|
-
|
|
53
|
-
const applyHighlight = (target: HTMLElement): void => {
|
|
54
|
-
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
55
|
-
target.classList.add(
|
|
56
|
-
"ring-2",
|
|
57
|
-
"ring-primary/60",
|
|
58
|
-
"ring-offset-1",
|
|
59
|
-
"ring-offset-background",
|
|
60
|
-
"rounded-sm",
|
|
61
|
-
"transition-shadow",
|
|
62
|
-
);
|
|
63
|
-
if (highlightTimer.current !== null) clearTimeout(highlightTimer.current);
|
|
64
|
-
highlightTimer.current = setTimeout(() => {
|
|
65
|
-
target.classList.remove(
|
|
66
|
-
"ring-2",
|
|
67
|
-
"ring-primary/60",
|
|
68
|
-
"ring-offset-1",
|
|
69
|
-
"ring-offset-background",
|
|
70
|
-
"rounded-sm",
|
|
71
|
-
"transition-shadow",
|
|
72
|
-
);
|
|
73
|
-
// Clear the expand signal AFTER the highlight fades so the
|
|
74
|
-
// user sees the tree in its final (expanded) state, not
|
|
75
|
-
// suddenly collapsing the moment we release control.
|
|
76
|
-
setExpandToPath(null);
|
|
77
|
-
}, highlightMs ?? HIGHLIGHT_DURATION_MS);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const escape = (value: string): string => {
|
|
81
|
-
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
82
|
-
return CSS.escape(value);
|
|
83
|
-
}
|
|
84
|
-
return value.replace(/(["'\\[\](){}])/g, "\\$1");
|
|
85
|
-
};
|
|
86
|
-
const selector = `[data-anatomy-path="${escape(segment.path)}"]`;
|
|
87
|
-
|
|
88
|
-
const tryFindTarget = (attemptsLeft: number): void => {
|
|
89
|
-
const container = containerRef.current;
|
|
90
|
-
if (container !== null) {
|
|
91
|
-
const target = container.querySelector<HTMLElement>(selector);
|
|
92
|
-
if (target !== null) {
|
|
93
|
-
applyHighlight(target);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (attemptsLeft > 0) {
|
|
98
|
-
window.requestAnimationFrame(() => tryFindTarget(attemptsLeft - 1));
|
|
99
|
-
} else {
|
|
100
|
-
// Path not in the DOM after a generous wait — reset state
|
|
101
|
-
// and bail. This is the right behavior for malformed paths
|
|
102
|
-
// (e.g. when the format adapter returns a path that does
|
|
103
|
-
// not exist in the current request body).
|
|
104
|
-
setExpandToPath(null);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// Wait one frame for the tab-switch / expandToPath state
|
|
109
|
-
// update to commit before we start probing the DOM.
|
|
110
|
-
window.requestAnimationFrame(() => tryFindTarget(MAX_HIGHLIGHT_ATTEMPTS));
|
|
111
|
-
},
|
|
112
|
-
[containerRef, ensureTabActive, highlightMs, setExpandToPath],
|
|
113
|
-
);
|
|
114
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { ApiTimeoutError } from "../../lib/apiClient";
|
|
2
|
-
import type { CapturedLog } from "../../contracts";
|
|
3
|
-
|
|
4
|
-
export type FullBodyHydrationError = {
|
|
5
|
-
title: string;
|
|
6
|
-
detail: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const DEFAULT_FULL_BODY_HYDRATION_ERROR_DETAIL =
|
|
10
|
-
"The compact log metadata is still available. Retry if the local server was restarting or the body store was briefly unavailable.";
|
|
11
|
-
const DEFAULT_DETAIL_CACHE_LIMIT = 64;
|
|
12
|
-
|
|
13
|
-
const hydratedLogCache = new Map<number, CapturedLog>();
|
|
14
|
-
const hydratedLogInFlight = new Map<number, Promise<CapturedLog>>();
|
|
15
|
-
|
|
16
|
-
export function formatBytes(bytes: number): string {
|
|
17
|
-
if (bytes < 1024) return `${bytes.toLocaleString()} B`;
|
|
18
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB`;
|
|
19
|
-
if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MiB`;
|
|
20
|
-
return `${(bytes / 1024 / 1024 / 1024).toFixed(1)} GiB`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function formatBodyHydrationFootprint(
|
|
24
|
-
requestBytes: number | null | undefined,
|
|
25
|
-
responseBytes: number | null | undefined,
|
|
26
|
-
): string | null {
|
|
27
|
-
const parts: string[] = [];
|
|
28
|
-
|
|
29
|
-
if (requestBytes !== null && requestBytes !== undefined) {
|
|
30
|
-
parts.push(`Request ${formatBytes(requestBytes)}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (responseBytes !== null && responseBytes !== undefined) {
|
|
34
|
-
parts.push(`Response ${formatBytes(responseBytes)}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return parts.length === 0 ? null : parts.join(" · ");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function describeFullBodyHydrationError(error: unknown): FullBodyHydrationError {
|
|
41
|
-
if (error instanceof ApiTimeoutError) {
|
|
42
|
-
return {
|
|
43
|
-
title: "Full bodies timed out",
|
|
44
|
-
detail:
|
|
45
|
-
"The log store did not answer before the UI timeout. Compact metadata is still available; retry loading the bodies.",
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (error instanceof Error) {
|
|
50
|
-
const message = error.message.trim();
|
|
51
|
-
return {
|
|
52
|
-
title: "Full bodies could not be loaded",
|
|
53
|
-
detail: message === "" ? DEFAULT_FULL_BODY_HYDRATION_ERROR_DETAIL : message,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
title: "Full bodies could not be loaded",
|
|
59
|
-
detail: DEFAULT_FULL_BODY_HYDRATION_ERROR_DETAIL,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function detailCacheLimit(): number {
|
|
64
|
-
const raw = process.env["AGENT_INSPECTOR_UI_DETAIL_CACHE_LIMIT"];
|
|
65
|
-
if (raw === undefined || raw === "") return DEFAULT_DETAIL_CACHE_LIMIT;
|
|
66
|
-
const parsed = Number(raw);
|
|
67
|
-
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 1000) {
|
|
68
|
-
return DEFAULT_DETAIL_CACHE_LIMIT;
|
|
69
|
-
}
|
|
70
|
-
return parsed;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function rememberHydratedLog(log: CapturedLog): CapturedLog {
|
|
74
|
-
hydratedLogCache.delete(log.id);
|
|
75
|
-
hydratedLogCache.set(log.id, log);
|
|
76
|
-
while (hydratedLogCache.size > detailCacheLimit()) {
|
|
77
|
-
const oldest = hydratedLogCache.keys().next().value;
|
|
78
|
-
if (typeof oldest !== "number") break;
|
|
79
|
-
hydratedLogCache.delete(oldest);
|
|
80
|
-
}
|
|
81
|
-
return log;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function readHydratedLogFromCache(logId: number): CapturedLog | null {
|
|
85
|
-
const cached = hydratedLogCache.get(logId);
|
|
86
|
-
if (cached === undefined) return null;
|
|
87
|
-
hydratedLogCache.delete(logId);
|
|
88
|
-
hydratedLogCache.set(logId, cached);
|
|
89
|
-
return cached;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function deleteHydratedLogFromCache(logId: number): void {
|
|
93
|
-
hydratedLogCache.delete(logId);
|
|
94
|
-
hydratedLogInFlight.delete(logId);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function clearHydratedLogCacheForTests(): void {
|
|
98
|
-
hydratedLogCache.clear();
|
|
99
|
-
hydratedLogInFlight.clear();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function getHydratedLogCacheSizeForTests(): number {
|
|
103
|
-
return hydratedLogCache.size;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export async function getOrFetchHydratedLog(
|
|
107
|
-
logId: number,
|
|
108
|
-
fetcher: () => Promise<CapturedLog>,
|
|
109
|
-
): Promise<CapturedLog> {
|
|
110
|
-
const cached = readHydratedLogFromCache(logId);
|
|
111
|
-
if (cached !== null) return cached;
|
|
112
|
-
|
|
113
|
-
const existing = hydratedLogInFlight.get(logId);
|
|
114
|
-
if (existing !== undefined) return await existing;
|
|
115
|
-
|
|
116
|
-
const pending = fetcher()
|
|
117
|
-
.then(rememberHydratedLog)
|
|
118
|
-
.finally(() => {
|
|
119
|
-
hydratedLogInFlight.delete(logId);
|
|
120
|
-
});
|
|
121
|
-
hydratedLogInFlight.set(logId, pending);
|
|
122
|
-
return await pending;
|
|
123
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { ConversationGroupData } from "./ConversationHeader";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Trend direction for a single cache token field, comparing the current log
|
|
5
|
-
* to the previous log in the same conversation group.
|
|
6
|
-
*/
|
|
7
|
-
export type CacheTrend = { direction: "up" | "down"; delta: number };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Per-log trend entry. `creation` covers `cacheCreationInputTokens`,
|
|
11
|
-
* `read` covers `cacheReadInputTokens`. Each field is `null` when there is
|
|
12
|
-
* no previous log to compare against, when the current log has no value for
|
|
13
|
-
* the field, or when the values are equal (no visual change).
|
|
14
|
-
*/
|
|
15
|
-
export type CacheTrendEntry = { creation: CacheTrend | null; read: CacheTrend | null };
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Build a `logId -> CacheTrendEntry` map for every log that has a previous
|
|
19
|
-
* log in its conversation group. Pure: does not mutate `groups`. Walks each
|
|
20
|
-
* group in array order (which is the timestamp-sorted order produced by
|
|
21
|
-
* `groupLogsByConversation`), so "previous log" is the adjacent entry in
|
|
22
|
-
* that order.
|
|
23
|
-
*/
|
|
24
|
-
export function computeCacheTrends(groups: ConversationGroupData[]): Map<number, CacheTrendEntry> {
|
|
25
|
-
const result = new Map<number, CacheTrendEntry>();
|
|
26
|
-
|
|
27
|
-
for (const group of groups) {
|
|
28
|
-
const logs = group.logs;
|
|
29
|
-
for (let i = 1; i < logs.length; i++) {
|
|
30
|
-
const prev = logs[i - 1];
|
|
31
|
-
const curr = logs[i];
|
|
32
|
-
if (prev === undefined || curr === undefined) continue;
|
|
33
|
-
|
|
34
|
-
result.set(curr.id, {
|
|
35
|
-
creation: compareField(prev.cacheCreationInputTokens, curr.cacheCreationInputTokens),
|
|
36
|
-
read: compareField(prev.cacheReadInputTokens, curr.cacheReadInputTokens),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function compareField(previous: number | null, current: number | null): CacheTrend | null {
|
|
45
|
-
if (current === null) return null;
|
|
46
|
-
if (previous === null) return null;
|
|
47
|
-
if (current > previous) return { direction: "up", delta: current - previous };
|
|
48
|
-
if (current < previous) return { direction: "down", delta: previous - current };
|
|
49
|
-
return null;
|
|
50
|
-
}
|