@tonyclaw/agent-inspector 4.0.1 → 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.
- package/.output/backend/nitro.json +1 -1
- package/.output/cli.js +192 -109
- package/.output/server/_ssr/index.mjs +1 -1
- package/.output/server/_ssr/{router-CTHqmroT.mjs → router-BBY_zWRK.mjs} +91 -3
- package/.output/server/index.mjs +1 -1
- package/.output/ui/assets/{CompareDrawer-L3n4J-Or.js → CompareDrawer-rtNElN-B.js} +1 -1
- package/.output/ui/assets/{InspectorPet-D5o_3OZS.js → InspectorPet-QaAiuF3d.js} +1 -1
- package/.output/ui/assets/{ProxyViewerContainer-Ocagx75S.js → ProxyViewerContainer-6twNZHwl.js} +4 -4
- package/.output/ui/assets/{ReplayDialog-Bk7x1h-y.js → ReplayDialog-B7KlziO2.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-U4lzL7Sc.js → RequestAnatomy-2XVFBrW4.js} +1 -1
- package/.output/ui/assets/{ResponseView-LOWfvBLK.js → ResponseView-BULgzLVB.js} +1 -1
- package/.output/ui/assets/{StreamingChunkSequence-DPfsrrXQ.js → StreamingChunkSequence-DSkvkbns.js} +1 -1
- package/.output/ui/assets/{_sessionId-OdX2Jvt1.js → _sessionId-D2dmJi3G.js} +1 -1
- package/.output/ui/assets/{_sessionId-0MlWS-CO.js → _sessionId-DcS0s1Mr.js} +1 -1
- package/.output/ui/assets/{index-Du4qNOOt.js → index-B0TN1KKO.js} +2 -2
- package/.output/ui/assets/{index-gvFj_9K6.js → index-Bva1zHEs.js} +1 -1
- package/.output/ui/assets/{index-Ea-c8hPg.js → index-BzBExOxu.js} +1 -1
- package/.output/ui/assets/{index-zVVS53Hd.js → index-k6sRQz55.js} +1 -1
- package/.output/ui/assets/{json-viewer-C1WAMzg3.js → json-viewer-CWM4tY-j.js} +1 -1
- package/.output/ui/assets/{jszip.min-B8AKu2zm.js → jszip.min-BkWvRFlo.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,429 +0,0 @@
|
|
|
1
|
-
import { type ReactNode, useCallback, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
ChevronDown,
|
|
4
|
-
ChevronRight,
|
|
5
|
-
Clock,
|
|
6
|
-
ExternalLink,
|
|
7
|
-
Loader2,
|
|
8
|
-
MessageSquare,
|
|
9
|
-
Trash2,
|
|
10
|
-
Zap,
|
|
11
|
-
} from "lucide-react";
|
|
12
|
-
import type { JSX } from "react";
|
|
13
|
-
import { getSessionPath } from "../../lib/sessionUrl";
|
|
14
|
-
import type { TimeDisplayFormat } from "../../lib/runtimeConfig";
|
|
15
|
-
import { formatTimestampRange } from "../../lib/timeDisplay";
|
|
16
|
-
import { cn, formatTokens } from "../../lib/utils";
|
|
17
|
-
import type { CapturedLog } from "../../contracts";
|
|
18
|
-
import { ConfirmDialog } from "../ui/confirm-dialog";
|
|
19
|
-
import type { Provider } from "../providers/ProviderLogo";
|
|
20
|
-
import { ClientLogo, clientAppLabel, detectClientApp } from "../clients/ClientLogo";
|
|
21
|
-
import { ProviderLogoStack } from "./ProviderLogoStack";
|
|
22
|
-
import { resolveLogFormat } from "./log-formats";
|
|
23
|
-
|
|
24
|
-
const HEADER_ACTION_BUTTON_CLASS =
|
|
25
|
-
"inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md bg-[var(--inspector-surface-low)] text-muted-foreground transition-colors hover:bg-[var(--inspector-surface-medium)] hover:text-foreground";
|
|
26
|
-
|
|
27
|
-
export function isSyntheticSessionId(conversationId: string): boolean {
|
|
28
|
-
return (
|
|
29
|
-
conversationId.startsWith("PID:") ||
|
|
30
|
-
conversationId.startsWith("process:") ||
|
|
31
|
-
conversationId.startsWith("connection:") ||
|
|
32
|
-
conversationId.includes("|")
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function compactSessionLabel(conversationId: string): string {
|
|
37
|
-
if (isSyntheticSessionId(conversationId)) return "No session ID";
|
|
38
|
-
return conversationId.length > 24
|
|
39
|
-
? `${conversationId.slice(0, 12)}...${conversationId.slice(-12)}`
|
|
40
|
-
: conversationId;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function HeaderMetric({
|
|
44
|
-
icon,
|
|
45
|
-
children,
|
|
46
|
-
title,
|
|
47
|
-
className,
|
|
48
|
-
}: {
|
|
49
|
-
icon: ReactNode;
|
|
50
|
-
children: ReactNode;
|
|
51
|
-
title?: string;
|
|
52
|
-
className?: string;
|
|
53
|
-
}): JSX.Element {
|
|
54
|
-
return (
|
|
55
|
-
<span
|
|
56
|
-
className={cn(
|
|
57
|
-
"inline-flex h-7 min-w-0 items-center gap-1.5 rounded-md bg-[var(--inspector-surface-low)] px-2 text-xs text-muted-foreground",
|
|
58
|
-
className,
|
|
59
|
-
)}
|
|
60
|
-
title={title}
|
|
61
|
-
>
|
|
62
|
-
{icon}
|
|
63
|
-
<span className="min-w-0 font-mono tabular-nums">{children}</span>
|
|
64
|
-
</span>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function PendingTurnBadge(): JSX.Element {
|
|
69
|
-
return (
|
|
70
|
-
<span
|
|
71
|
-
className="inline-flex h-6 shrink-0 items-center gap-1.5 rounded-md bg-[var(--inspector-surface-medium)] px-1.5 font-mono text-[10px] uppercase text-[var(--inspector-status-watch)] ring-1 ring-border/50"
|
|
72
|
-
title="This session has a turn that has not finished yet"
|
|
73
|
-
>
|
|
74
|
-
<Loader2 className="size-3 animate-spin" />
|
|
75
|
-
Turn open
|
|
76
|
-
</span>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type ConversationHeaderProps = {
|
|
81
|
-
conversationId: string;
|
|
82
|
-
startTime: string;
|
|
83
|
-
endTime: string;
|
|
84
|
-
totalCalls: number;
|
|
85
|
-
totalInputTokens: number;
|
|
86
|
-
totalOutputTokens: number;
|
|
87
|
-
expanded: boolean;
|
|
88
|
-
onToggle: () => void;
|
|
89
|
-
/** Unique providers whose models appear in this group, with their distinct
|
|
90
|
-
* model names. Rendered as a row of provider logos next to the header, one
|
|
91
|
-
* per provider so model-switching inside a single session is visible.
|
|
92
|
-
* at a glance. `undefined` hides the strip (default). */
|
|
93
|
-
providers?: { provider: Provider; models: string[] }[];
|
|
94
|
-
/** When true and the group is collapsed, show a spinner instead of the
|
|
95
|
-
* expand chevron to indicate an in-flight request inside the group. */
|
|
96
|
-
isLoading?: boolean;
|
|
97
|
-
/** User-Agent string from the first log in the group. */
|
|
98
|
-
userAgent?: string | null;
|
|
99
|
-
/** Process ID of the client that issued the first log in the group, used
|
|
100
|
-
* to render the session identifier. When `conversationId` is a real
|
|
101
|
-
* session id this is shown as a secondary pill; when `conversationId` is
|
|
102
|
-
* a fallback (no sessionId was emitted by the client, e.g. `PID:123|/cwd`)
|
|
103
|
-
* the PID is shown as the primary identifier instead. */
|
|
104
|
-
clientPid?: number | null;
|
|
105
|
-
/** Project folder of the client that issued the first log in the group.
|
|
106
|
-
* Only shown as a secondary label when the session lacks a real
|
|
107
|
-
* `sessionId` (the same fallback path used for `clientPid`). */
|
|
108
|
-
clientProjectFolder?: string | null;
|
|
109
|
-
/** Show IDE identity in the header. Parent IDE rows can disable this to avoid repetition. */
|
|
110
|
-
showClientIdentity?: boolean;
|
|
111
|
-
/** Show process/project metadata in the header. Parent process rows can disable this. */
|
|
112
|
-
showProcessMetadata?: boolean;
|
|
113
|
-
/** Controls whether timestamps render as compact local time or full ISO strings. */
|
|
114
|
-
timeDisplayFormat: TimeDisplayFormat;
|
|
115
|
-
/** Clear all logs in this group from the current view; this header is then unmounted. */
|
|
116
|
-
onClear?: () => void;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export function ConversationHeader({
|
|
120
|
-
conversationId,
|
|
121
|
-
startTime,
|
|
122
|
-
endTime,
|
|
123
|
-
totalCalls,
|
|
124
|
-
totalInputTokens,
|
|
125
|
-
totalOutputTokens,
|
|
126
|
-
expanded,
|
|
127
|
-
onToggle,
|
|
128
|
-
providers,
|
|
129
|
-
isLoading = false,
|
|
130
|
-
userAgent,
|
|
131
|
-
clientPid,
|
|
132
|
-
clientProjectFolder,
|
|
133
|
-
showClientIdentity = true,
|
|
134
|
-
showProcessMetadata = true,
|
|
135
|
-
timeDisplayFormat,
|
|
136
|
-
onClear,
|
|
137
|
-
}: ConversationHeaderProps): JSX.Element {
|
|
138
|
-
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
139
|
-
|
|
140
|
-
const handleClearClick = (e: React.MouseEvent | React.KeyboardEvent): void => {
|
|
141
|
-
e.stopPropagation();
|
|
142
|
-
if (onClear === undefined) return;
|
|
143
|
-
setConfirmOpen(true);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const handleOpenInNewTab = useCallback(
|
|
147
|
-
(e: React.MouseEvent | React.KeyboardEvent): void => {
|
|
148
|
-
e.stopPropagation();
|
|
149
|
-
window.open(getSessionPath(conversationId), "_blank", "noopener,noreferrer");
|
|
150
|
-
},
|
|
151
|
-
[conversationId],
|
|
152
|
-
);
|
|
153
|
-
const providerLogoItems =
|
|
154
|
-
providers?.map(({ provider, models }) => ({
|
|
155
|
-
provider,
|
|
156
|
-
tooltip: models.length === 1 ? (models[0] ?? provider) : models.join(", "),
|
|
157
|
-
})) ?? [];
|
|
158
|
-
const clientApp = detectClientApp({ userAgent, conversationId, clientProjectFolder });
|
|
159
|
-
const detectedClientLabel = clientAppLabel(clientApp);
|
|
160
|
-
const hasUserAgent = userAgent !== null && userAgent !== undefined && userAgent !== "";
|
|
161
|
-
const clientDisplayLabel = detectedClientLabel ?? userAgent ?? null;
|
|
162
|
-
const clientTooltip =
|
|
163
|
-
detectedClientLabel !== null && hasUserAgent ? `${detectedClientLabel} - ${userAgent}` : null;
|
|
164
|
-
const isFallbackConversation = isSyntheticSessionId(conversationId);
|
|
165
|
-
const sessionLabel = compactSessionLabel(conversationId);
|
|
166
|
-
|
|
167
|
-
const timeLabel = formatTimestampRange(startTime, endTime, timeDisplayFormat);
|
|
168
|
-
const callsLabel = `${totalCalls} call${totalCalls !== 1 ? "s" : ""}`;
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<div
|
|
172
|
-
role="button"
|
|
173
|
-
tabIndex={0}
|
|
174
|
-
data-nav-id={`conv-${conversationId}`}
|
|
175
|
-
data-nav-action={expanded ? "collapse" : "expand"}
|
|
176
|
-
className={cn(
|
|
177
|
-
"relative flex cursor-pointer items-start gap-2.5 overflow-hidden rounded-md bg-[var(--inspector-surface-low)] px-3 py-2.5 transition-colors",
|
|
178
|
-
"hover:bg-[var(--inspector-surface-medium)]",
|
|
179
|
-
"select-none",
|
|
180
|
-
"sticky top-0 z-10 mb-2",
|
|
181
|
-
"focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none",
|
|
182
|
-
)}
|
|
183
|
-
onClick={onToggle}
|
|
184
|
-
onKeyDown={(e) => {
|
|
185
|
-
if (e.target !== e.currentTarget) return;
|
|
186
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
187
|
-
e.preventDefault();
|
|
188
|
-
onToggle();
|
|
189
|
-
}
|
|
190
|
-
}}
|
|
191
|
-
>
|
|
192
|
-
{/* Provider logos: first visual element whenever model/provider logos are available. */}
|
|
193
|
-
<ProviderLogoStack
|
|
194
|
-
items={providerLogoItems}
|
|
195
|
-
ariaLabel="Models used in this session"
|
|
196
|
-
className="mt-0.5"
|
|
197
|
-
/>
|
|
198
|
-
|
|
199
|
-
<span className="min-w-0 flex-1">
|
|
200
|
-
<span className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1">
|
|
201
|
-
<span className="shrink-0 rounded bg-[var(--inspector-surface-medium)] px-1.5 py-0.5 font-mono text-[9px] uppercase text-muted-foreground">
|
|
202
|
-
Session
|
|
203
|
-
</span>
|
|
204
|
-
{isFallbackConversation && showProcessMetadata ? (
|
|
205
|
-
clientPid !== null && clientPid !== undefined ? (
|
|
206
|
-
<span
|
|
207
|
-
className="min-w-0 max-w-full truncate font-mono text-xs font-semibold text-foreground"
|
|
208
|
-
title={`PID ${clientPid}`}
|
|
209
|
-
>
|
|
210
|
-
PID {clientPid}
|
|
211
|
-
</span>
|
|
212
|
-
) : (
|
|
213
|
-
<span
|
|
214
|
-
className="min-w-0 max-w-full truncate font-mono text-xs font-semibold text-foreground"
|
|
215
|
-
title={conversationId}
|
|
216
|
-
>
|
|
217
|
-
{conversationId}
|
|
218
|
-
</span>
|
|
219
|
-
)
|
|
220
|
-
) : (
|
|
221
|
-
<span
|
|
222
|
-
className="min-w-0 max-w-full truncate font-mono text-xs font-semibold text-foreground"
|
|
223
|
-
title={conversationId}
|
|
224
|
-
>
|
|
225
|
-
{sessionLabel}
|
|
226
|
-
</span>
|
|
227
|
-
)}
|
|
228
|
-
|
|
229
|
-
{!isFallbackConversation &&
|
|
230
|
-
showProcessMetadata &&
|
|
231
|
-
clientPid !== null &&
|
|
232
|
-
clientPid !== undefined && (
|
|
233
|
-
<span
|
|
234
|
-
className="shrink-0 rounded bg-[var(--inspector-surface-medium)] px-1.5 py-0.5 font-mono text-xs tabular-nums text-muted-foreground"
|
|
235
|
-
title={`Client process ID ${clientPid}`}
|
|
236
|
-
>
|
|
237
|
-
PID {clientPid}
|
|
238
|
-
</span>
|
|
239
|
-
)}
|
|
240
|
-
|
|
241
|
-
{isFallbackConversation &&
|
|
242
|
-
showProcessMetadata &&
|
|
243
|
-
clientProjectFolder !== null &&
|
|
244
|
-
clientProjectFolder !== undefined &&
|
|
245
|
-
clientProjectFolder !== "" && (
|
|
246
|
-
<span
|
|
247
|
-
className="min-w-0 max-w-[240px] truncate font-mono text-xs text-muted-foreground"
|
|
248
|
-
title={clientProjectFolder}
|
|
249
|
-
>
|
|
250
|
-
{clientProjectFolder}
|
|
251
|
-
</span>
|
|
252
|
-
)}
|
|
253
|
-
|
|
254
|
-
{showClientIdentity && clientDisplayLabel !== null && clientDisplayLabel !== "" && (
|
|
255
|
-
<span
|
|
256
|
-
className="inline-flex min-h-6 shrink-0 flex-wrap items-center gap-1 rounded-md bg-[var(--inspector-surface-medium)] px-1.5 py-0.5 text-xs text-muted-foreground"
|
|
257
|
-
title={clientTooltip ?? clientDisplayLabel}
|
|
258
|
-
>
|
|
259
|
-
<ClientLogo client={clientApp} className="size-4 shrink-0" decorative={true} />
|
|
260
|
-
<span className="font-mono leading-snug tabular-nums">{clientDisplayLabel}</span>
|
|
261
|
-
</span>
|
|
262
|
-
)}
|
|
263
|
-
|
|
264
|
-
{isLoading && <PendingTurnBadge />}
|
|
265
|
-
</span>
|
|
266
|
-
|
|
267
|
-
<span className="mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5">
|
|
268
|
-
<HeaderMetric icon={<Clock className="size-3 shrink-0" />} title={timeLabel}>
|
|
269
|
-
{timeLabel}
|
|
270
|
-
</HeaderMetric>
|
|
271
|
-
<HeaderMetric icon={<MessageSquare className="size-3 shrink-0" />}>
|
|
272
|
-
{callsLabel}
|
|
273
|
-
</HeaderMetric>
|
|
274
|
-
<HeaderMetric icon={<Zap className="size-3 shrink-0" />} className="max-w-full">
|
|
275
|
-
<span className="text-[var(--inspector-status-info)]">
|
|
276
|
-
{formatTokens(totalInputTokens)}
|
|
277
|
-
</span>
|
|
278
|
-
{" / "}
|
|
279
|
-
<span className="text-[var(--inspector-status-watch)]">
|
|
280
|
-
{formatTokens(totalOutputTokens)}
|
|
281
|
-
</span>
|
|
282
|
-
</HeaderMetric>
|
|
283
|
-
</span>
|
|
284
|
-
</span>
|
|
285
|
-
|
|
286
|
-
<span className="flex shrink-0 items-start gap-1.5">
|
|
287
|
-
{/* Open this session in a new tab - deep link to /session/$id */}
|
|
288
|
-
<button
|
|
289
|
-
type="button"
|
|
290
|
-
onClick={handleOpenInNewTab}
|
|
291
|
-
onKeyDown={(e) => {
|
|
292
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
293
|
-
handleOpenInNewTab(e);
|
|
294
|
-
}
|
|
295
|
-
}}
|
|
296
|
-
aria-label={`Open session ${conversationId} in a new tab`}
|
|
297
|
-
title="Open this session in a new tab"
|
|
298
|
-
className={HEADER_ACTION_BUTTON_CLASS}
|
|
299
|
-
>
|
|
300
|
-
<ExternalLink className="size-3.5" />
|
|
301
|
-
</button>
|
|
302
|
-
|
|
303
|
-
{/* Per-group Clear - does not toggle the group's expand state */}
|
|
304
|
-
{onClear !== undefined && (
|
|
305
|
-
<button
|
|
306
|
-
type="button"
|
|
307
|
-
onClick={handleClearClick}
|
|
308
|
-
aria-label={`Clear group (${totalCalls} request${totalCalls !== 1 ? "s" : ""})`}
|
|
309
|
-
title="Clear this group from the current view"
|
|
310
|
-
className={HEADER_ACTION_BUTTON_CLASS}
|
|
311
|
-
>
|
|
312
|
-
<Trash2 className="size-3.5" />
|
|
313
|
-
</button>
|
|
314
|
-
)}
|
|
315
|
-
|
|
316
|
-
{/* Expand chevron - shows spinner when collapsed and group has pending logs */}
|
|
317
|
-
<span
|
|
318
|
-
className="inline-flex size-8 shrink-0 items-center justify-center rounded-md bg-[var(--inspector-surface-low)] text-muted-foreground transition-colors hover:bg-[var(--inspector-surface-medium)] hover:text-foreground"
|
|
319
|
-
aria-hidden="true"
|
|
320
|
-
>
|
|
321
|
-
{expanded ? (
|
|
322
|
-
<ChevronDown className="size-4 shrink-0" />
|
|
323
|
-
) : isLoading ? (
|
|
324
|
-
<Loader2 className="size-4 shrink-0 animate-spin" />
|
|
325
|
-
) : (
|
|
326
|
-
<ChevronRight className="size-4 shrink-0" />
|
|
327
|
-
)}
|
|
328
|
-
</span>
|
|
329
|
-
</span>
|
|
330
|
-
|
|
331
|
-
{isLoading && (
|
|
332
|
-
<span
|
|
333
|
-
className="pointer-events-none absolute inset-x-3 bottom-0 h-px overflow-hidden rounded-full bg-[var(--inspector-surface-medium)]"
|
|
334
|
-
aria-hidden="true"
|
|
335
|
-
>
|
|
336
|
-
<span className="absolute inset-y-0 left-0 w-1/3 animate-pulse rounded-full bg-[var(--inspector-status-watch)] opacity-70" />
|
|
337
|
-
</span>
|
|
338
|
-
)}
|
|
339
|
-
|
|
340
|
-
<ConfirmDialog
|
|
341
|
-
open={confirmOpen}
|
|
342
|
-
onOpenChange={setConfirmOpen}
|
|
343
|
-
title="Clear this group from the current view?"
|
|
344
|
-
description={`This will hide ${totalCalls} request${totalCalls !== 1 ? "s" : ""} from the current view. Stored logs remain reloadable.`}
|
|
345
|
-
confirmLabel="Clear"
|
|
346
|
-
variant="destructive"
|
|
347
|
-
onConfirm={() => {
|
|
348
|
-
onClear?.();
|
|
349
|
-
}}
|
|
350
|
-
/>
|
|
351
|
-
</div>
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export type ConversationGroupData = {
|
|
356
|
-
id: string;
|
|
357
|
-
conversationId: string;
|
|
358
|
-
logs: CapturedLog[];
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
export function getGroupApiFormat(logs: CapturedLog[]): "anthropic" | "openai" | "unknown" {
|
|
362
|
-
for (const log of logs) {
|
|
363
|
-
const apiFormat = resolveLogFormat(log);
|
|
364
|
-
if (apiFormat !== "unknown") {
|
|
365
|
-
return apiFormat;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return "unknown";
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Returns true when a group contains logs of BOTH Anthropic and OpenAI
|
|
373
|
-
* formats. Used to decide whether to render the per-row API format badge
|
|
374
|
-
* inside a group (the badge is normally hidden because the group header
|
|
375
|
-
* already shows the format).
|
|
376
|
-
*/
|
|
377
|
-
export function hasMixedApiFormat(logs: CapturedLog[]): boolean {
|
|
378
|
-
let hasAnthropic = false;
|
|
379
|
-
let hasOpenai = false;
|
|
380
|
-
for (const log of logs) {
|
|
381
|
-
const apiFormat = resolveLogFormat(log);
|
|
382
|
-
if (apiFormat === "anthropic") hasAnthropic = true;
|
|
383
|
-
else if (apiFormat === "openai") hasOpenai = true;
|
|
384
|
-
if (hasAnthropic && hasOpenai) return true;
|
|
385
|
-
}
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
export function getConversationId(log: CapturedLog): string {
|
|
390
|
-
if (log.sessionId !== null && log.sessionId !== "" && log.sessionId !== undefined) {
|
|
391
|
-
return log.sessionId;
|
|
392
|
-
}
|
|
393
|
-
if (log.isTest === true) return "provider-test";
|
|
394
|
-
const hasPid = log.clientPid !== null && log.clientPid !== undefined;
|
|
395
|
-
const hasFolder = log.clientProjectFolder !== null && log.clientProjectFolder !== undefined;
|
|
396
|
-
if (!hasPid && !hasFolder) return "default";
|
|
397
|
-
const pid = hasPid ? `PID:${log.clientPid}` : "unknown";
|
|
398
|
-
const folder = hasFolder ? log.clientProjectFolder : "no-folder";
|
|
399
|
-
return `${pid}|${folder}`;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export function groupLogsByConversation(logs: CapturedLog[]): ConversationGroupData[] {
|
|
403
|
-
const groups = new Map<string, CapturedLog[]>();
|
|
404
|
-
|
|
405
|
-
for (const log of logs) {
|
|
406
|
-
const convId = getConversationId(log);
|
|
407
|
-
const existing = groups.get(convId);
|
|
408
|
-
if (existing !== undefined) {
|
|
409
|
-
existing.push(log);
|
|
410
|
-
} else {
|
|
411
|
-
groups.set(convId, [log]);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const result: ConversationGroupData[] = [];
|
|
416
|
-
|
|
417
|
-
for (const [conversationId, groupLogs] of groups) {
|
|
418
|
-
const sorted = [...groupLogs].sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
419
|
-
result.push({
|
|
420
|
-
id: conversationId,
|
|
421
|
-
conversationId,
|
|
422
|
-
logs: sorted,
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
result.sort((a, b) => (a.logs[0]?.timestamp ?? "").localeCompare(b.logs[0]?.timestamp ?? ""));
|
|
427
|
-
|
|
428
|
-
return result;
|
|
429
|
-
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { type JSX } from "react";
|
|
2
|
-
import { CircleStop, RefreshCw } from "lucide-react";
|
|
3
|
-
import { cn } from "../../lib/utils";
|
|
4
|
-
import type { LiveConnectionPhase, LiveConnectionState } from "./liveConnectionState";
|
|
5
|
-
|
|
6
|
-
type ConnectionPresentation = {
|
|
7
|
-
label: string;
|
|
8
|
-
description: string;
|
|
9
|
-
toneClass: string;
|
|
10
|
-
dotClass: string;
|
|
11
|
-
canRetry: boolean;
|
|
12
|
-
canStop: boolean;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function formatLastSuccess(lastSuccessAt: number | null): string | null {
|
|
16
|
-
if (lastSuccessAt === null) return null;
|
|
17
|
-
return new Date(lastSuccessAt).toLocaleTimeString([], {
|
|
18
|
-
hour: "2-digit",
|
|
19
|
-
minute: "2-digit",
|
|
20
|
-
second: "2-digit",
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function buildDescription(state: LiveConnectionState, message: string, hasLogs: boolean): string {
|
|
25
|
-
const lastSuccess = formatLastSuccess(state.lastSuccessAt);
|
|
26
|
-
const retry = state.retryCount > 0 ? ` Retry ${state.retryCount.toString()}.` : "";
|
|
27
|
-
const retained = hasLogs ? " Captured logs remain visible." : "";
|
|
28
|
-
const lastUpdate = lastSuccess === null ? "" : ` Last update ${lastSuccess}.`;
|
|
29
|
-
return `${message}${lastUpdate}${retry}${retained}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function presentationForStatus(
|
|
33
|
-
status: LiveConnectionPhase,
|
|
34
|
-
state: LiveConnectionState,
|
|
35
|
-
hasLogs: boolean,
|
|
36
|
-
): ConnectionPresentation {
|
|
37
|
-
switch (status) {
|
|
38
|
-
case "connecting":
|
|
39
|
-
return {
|
|
40
|
-
label: "Connecting",
|
|
41
|
-
description: buildDescription(state, "Waiting for the first live update.", hasLogs),
|
|
42
|
-
toneClass: "border-cyan-400/20 bg-cyan-500/8 text-cyan-100",
|
|
43
|
-
dotClass: "bg-cyan-300 animate-pulse motion-reduce:animate-none",
|
|
44
|
-
canRetry: false,
|
|
45
|
-
canStop: false,
|
|
46
|
-
};
|
|
47
|
-
case "live":
|
|
48
|
-
return {
|
|
49
|
-
label: "Live",
|
|
50
|
-
description: buildDescription(state, "Live updates are current.", hasLogs),
|
|
51
|
-
toneClass: "border-emerald-400/20 bg-emerald-500/8 text-emerald-100",
|
|
52
|
-
dotClass: "bg-emerald-300",
|
|
53
|
-
canRetry: false,
|
|
54
|
-
canStop: false,
|
|
55
|
-
};
|
|
56
|
-
case "reconnecting":
|
|
57
|
-
return {
|
|
58
|
-
label: "Reconnecting",
|
|
59
|
-
description: buildDescription(state, "Live updates were interrupted.", hasLogs),
|
|
60
|
-
toneClass: "border-amber-400/20 bg-amber-500/8 text-amber-100",
|
|
61
|
-
dotClass: "bg-amber-300 animate-pulse motion-reduce:animate-none",
|
|
62
|
-
canRetry: true,
|
|
63
|
-
canStop: true,
|
|
64
|
-
};
|
|
65
|
-
case "stale":
|
|
66
|
-
return {
|
|
67
|
-
label: "Stale data",
|
|
68
|
-
description: buildDescription(state, "Live updates have not resumed.", hasLogs),
|
|
69
|
-
toneClass: "border-orange-400/25 bg-orange-500/10 text-orange-100",
|
|
70
|
-
dotClass: "bg-orange-300",
|
|
71
|
-
canRetry: true,
|
|
72
|
-
canStop: true,
|
|
73
|
-
};
|
|
74
|
-
case "offline":
|
|
75
|
-
return {
|
|
76
|
-
label: "Offline",
|
|
77
|
-
description: buildDescription(
|
|
78
|
-
state,
|
|
79
|
-
state.errorMessage ?? "Live updates are paused.",
|
|
80
|
-
hasLogs,
|
|
81
|
-
),
|
|
82
|
-
toneClass: "border-slate-400/20 bg-slate-500/10 text-slate-200",
|
|
83
|
-
dotClass: "bg-slate-400",
|
|
84
|
-
canRetry: true,
|
|
85
|
-
canStop: false,
|
|
86
|
-
};
|
|
87
|
-
case "error":
|
|
88
|
-
return {
|
|
89
|
-
label: "Connection error",
|
|
90
|
-
description: buildDescription(
|
|
91
|
-
state,
|
|
92
|
-
state.errorMessage ?? "The live stream reported a recoverable error.",
|
|
93
|
-
hasLogs,
|
|
94
|
-
),
|
|
95
|
-
toneClass: "border-red-400/25 bg-red-500/10 text-red-100",
|
|
96
|
-
dotClass: "bg-red-300",
|
|
97
|
-
canRetry: true,
|
|
98
|
-
canStop: true,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function LiveConnectionBadge({ state }: { state: LiveConnectionState }): JSX.Element {
|
|
104
|
-
const presentation = presentationForStatus(state.status, state, false);
|
|
105
|
-
const lastSuccess = formatLastSuccess(state.lastSuccessAt);
|
|
106
|
-
const retryLabel = state.retryCount > 0 ? `Retry ${state.retryCount.toString()}` : null;
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<span
|
|
110
|
-
role="status"
|
|
111
|
-
aria-label={presentation.description}
|
|
112
|
-
data-connection-state={state.status}
|
|
113
|
-
className={cn(
|
|
114
|
-
"inline-flex h-7 max-w-full items-center gap-1.5 rounded-full border px-2.5 text-xs font-medium",
|
|
115
|
-
presentation.toneClass,
|
|
116
|
-
)}
|
|
117
|
-
>
|
|
118
|
-
<span className={cn("size-1.5 shrink-0 rounded-full", presentation.dotClass)} />
|
|
119
|
-
<span className="shrink-0">{presentation.label}</span>
|
|
120
|
-
{retryLabel !== null && (
|
|
121
|
-
<span className="hidden truncate text-current/70 sm:inline">{retryLabel}</span>
|
|
122
|
-
)}
|
|
123
|
-
{lastSuccess !== null && (
|
|
124
|
-
<span className="hidden truncate font-mono text-[10px] text-current/65 md:inline">
|
|
125
|
-
Last {lastSuccess}
|
|
126
|
-
</span>
|
|
127
|
-
)}
|
|
128
|
-
</span>
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function LiveConnectionStatus({
|
|
133
|
-
state,
|
|
134
|
-
hasLogs,
|
|
135
|
-
onRetry,
|
|
136
|
-
onStop,
|
|
137
|
-
}: {
|
|
138
|
-
state: LiveConnectionState;
|
|
139
|
-
hasLogs: boolean;
|
|
140
|
-
onRetry: () => void;
|
|
141
|
-
onStop: () => void;
|
|
142
|
-
}): JSX.Element {
|
|
143
|
-
const presentation = presentationForStatus(state.status, state, hasLogs);
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<div
|
|
147
|
-
role="status"
|
|
148
|
-
aria-live="polite"
|
|
149
|
-
data-connection-state={state.status}
|
|
150
|
-
className={cn(
|
|
151
|
-
"mt-2 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-md border px-3 py-2 text-xs",
|
|
152
|
-
presentation.toneClass,
|
|
153
|
-
)}
|
|
154
|
-
>
|
|
155
|
-
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
156
|
-
<span className={cn("size-2 shrink-0 rounded-full", presentation.dotClass)} />
|
|
157
|
-
<span className="shrink-0 font-semibold">{presentation.label}</span>
|
|
158
|
-
<span className="min-w-0 text-current/75">{presentation.description}</span>
|
|
159
|
-
</div>
|
|
160
|
-
{(presentation.canRetry || presentation.canStop) && (
|
|
161
|
-
<div className="flex shrink-0 items-center gap-1.5">
|
|
162
|
-
{presentation.canRetry && (
|
|
163
|
-
<button
|
|
164
|
-
type="button"
|
|
165
|
-
onClick={onRetry}
|
|
166
|
-
className="inline-flex h-7 items-center gap-1 rounded-md bg-black/15 px-2 font-medium transition-colors hover:bg-black/25 focus-visible:ring-1 focus-visible:ring-current focus-visible:outline-none"
|
|
167
|
-
>
|
|
168
|
-
<RefreshCw className="size-3" />
|
|
169
|
-
Retry now
|
|
170
|
-
</button>
|
|
171
|
-
)}
|
|
172
|
-
{presentation.canStop && (
|
|
173
|
-
<button
|
|
174
|
-
type="button"
|
|
175
|
-
onClick={onStop}
|
|
176
|
-
className="inline-flex h-7 items-center gap-1 rounded-md px-2 text-current/70 transition-colors hover:bg-black/15 hover:text-current focus-visible:ring-1 focus-visible:ring-current focus-visible:outline-none"
|
|
177
|
-
>
|
|
178
|
-
<CircleStop className="size-3" />
|
|
179
|
-
Stop retrying
|
|
180
|
-
</button>
|
|
181
|
-
)}
|
|
182
|
-
</div>
|
|
183
|
-
)}
|
|
184
|
-
</div>
|
|
185
|
-
);
|
|
186
|
-
}
|