@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
package/src/proxy/alerts.ts
DELETED
|
@@ -1,664 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import type { JsonValue } from "../contracts";
|
|
3
|
-
import type {
|
|
4
|
-
Alert,
|
|
5
|
-
AlertCategory,
|
|
6
|
-
AlertEvidenceLink,
|
|
7
|
-
AlertListResponse,
|
|
8
|
-
AlertSeverity,
|
|
9
|
-
AlertSource,
|
|
10
|
-
AlertSummary,
|
|
11
|
-
} from "../lib/alertContract";
|
|
12
|
-
import type { InspectorGroup, InspectorGroupMember } from "../lib/groupContract";
|
|
13
|
-
import type { RecentFailure } from "../lib/runContract";
|
|
14
|
-
import { getSessionPath } from "../lib/sessionUrl";
|
|
15
|
-
import { getConfig } from "./config";
|
|
16
|
-
import { listGroups } from "./groupStore";
|
|
17
|
-
import { listRecentFailures } from "./runFailures";
|
|
18
|
-
import type { CapturedLog } from "./schemas";
|
|
19
|
-
import { listLogsCursorPage } from "./store";
|
|
20
|
-
|
|
21
|
-
export const DEFAULT_ALERT_LIMIT = 50;
|
|
22
|
-
export const MAX_ALERT_LIMIT = 200;
|
|
23
|
-
export const DEFAULT_ALERT_SCAN_LIMIT = 500;
|
|
24
|
-
export const MAX_ALERT_SCAN_LIMIT = 2_000;
|
|
25
|
-
|
|
26
|
-
type AlertFilters = {
|
|
27
|
-
severity?: AlertSeverity;
|
|
28
|
-
category?: AlertCategory;
|
|
29
|
-
source?: AlertSource;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type ListAlertsOptions = AlertFilters & {
|
|
33
|
-
limit?: number;
|
|
34
|
-
scanLimit?: number;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type AlertObservation = {
|
|
38
|
-
fingerprint: string;
|
|
39
|
-
severity: AlertSeverity;
|
|
40
|
-
category: AlertCategory;
|
|
41
|
-
source: AlertSource;
|
|
42
|
-
title: string;
|
|
43
|
-
message: string;
|
|
44
|
-
observedAt: string;
|
|
45
|
-
logId: number | null;
|
|
46
|
-
sessionId: string | null;
|
|
47
|
-
runId: string | null;
|
|
48
|
-
groupId: string | null;
|
|
49
|
-
provider: string | null;
|
|
50
|
-
model: string | null;
|
|
51
|
-
apiFormat: Alert["apiFormat"];
|
|
52
|
-
evidence: AlertEvidenceLink[];
|
|
53
|
-
metadata: Record<string, JsonValue>;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type AlertCollectionInput = {
|
|
57
|
-
logs: readonly CapturedLog[];
|
|
58
|
-
recentFailures: readonly RecentFailure[];
|
|
59
|
-
groups: readonly InspectorGroup[];
|
|
60
|
-
slowResponseThresholdSeconds: number;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
function clampPositiveInt(value: number | undefined, fallback: number, max: number): number {
|
|
64
|
-
if (value === undefined) return fallback;
|
|
65
|
-
if (!Number.isInteger(value) || value < 1) return fallback;
|
|
66
|
-
return Math.min(value, max);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function clampAlertLimit(value: number | undefined): number {
|
|
70
|
-
return clampPositiveInt(value, DEFAULT_ALERT_LIMIT, MAX_ALERT_LIMIT);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function clampAlertScanLimit(value: number | undefined): number {
|
|
74
|
-
return clampPositiveInt(value, DEFAULT_ALERT_SCAN_LIMIT, MAX_ALERT_SCAN_LIMIT);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function alertIdFor(value: string): string {
|
|
78
|
-
const digest = createHash("sha1").update(value).digest("hex").slice(0, 16);
|
|
79
|
-
return `alert_${digest}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function sanitizeFingerprintPart(value: string | number | null): string {
|
|
83
|
-
if (value === null) return "-";
|
|
84
|
-
return String(value).trim().toLowerCase().replace(/\s+/g, " ").slice(0, 240);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function fingerprint(parts: readonly (string | number | null)[]): string {
|
|
88
|
-
return parts.map(sanitizeFingerprintPart).join("|");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function uniqueStrings(values: readonly string[]): string[] {
|
|
92
|
-
return [...new Set(values)].sort();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function uniqueNumbers(values: readonly number[]): number[] {
|
|
96
|
-
return [...new Set(values)].sort((left, right) => left - right);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function logEvidence(logId: number): AlertEvidenceLink {
|
|
100
|
-
const id = String(logId);
|
|
101
|
-
return { kind: "log", id, label: `Log #${id}`, href: `#log-${id}` };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function sessionEvidence(sessionId: string): AlertEvidenceLink {
|
|
105
|
-
return {
|
|
106
|
-
kind: "session",
|
|
107
|
-
id: sessionId,
|
|
108
|
-
label: `Session ${sessionId}`,
|
|
109
|
-
href: getSessionPath(sessionId),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function runEvidence(runId: string): AlertEvidenceLink {
|
|
114
|
-
return { kind: "run", id: runId, label: `Run ${runId}`, href: null };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function groupEvidence(groupId: string): AlertEvidenceLink {
|
|
118
|
-
return { kind: "group", id: groupId, label: `Group ${groupId}`, href: null };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function baseEvidence(
|
|
122
|
-
logId: number | null,
|
|
123
|
-
sessionId: string | null,
|
|
124
|
-
runId: string | null,
|
|
125
|
-
groupId: string | null,
|
|
126
|
-
): AlertEvidenceLink[] {
|
|
127
|
-
const links: AlertEvidenceLink[] = [];
|
|
128
|
-
if (logId !== null) links.push(logEvidence(logId));
|
|
129
|
-
if (sessionId !== null) links.push(sessionEvidence(sessionId));
|
|
130
|
-
if (runId !== null) links.push(runEvidence(runId));
|
|
131
|
-
if (groupId !== null) links.push(groupEvidence(groupId));
|
|
132
|
-
return links;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function hasEquivalentEvidence(
|
|
136
|
-
links: readonly AlertEvidenceLink[],
|
|
137
|
-
candidate: AlertEvidenceLink,
|
|
138
|
-
): boolean {
|
|
139
|
-
return links.some((link) => link.kind === candidate.kind && link.id === candidate.id);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function mergeEvidence(
|
|
143
|
-
left: readonly AlertEvidenceLink[],
|
|
144
|
-
right: readonly AlertEvidenceLink[],
|
|
145
|
-
): AlertEvidenceLink[] {
|
|
146
|
-
const merged: AlertEvidenceLink[] = [...left];
|
|
147
|
-
for (const link of right) {
|
|
148
|
-
if (!hasEquivalentEvidence(merged, link)) merged.push(link);
|
|
149
|
-
}
|
|
150
|
-
return merged;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function firstString(left: string | null, right: string | null): string | null {
|
|
154
|
-
return left ?? right;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function mergeAlert(existing: Alert, observation: AlertObservation): Alert {
|
|
158
|
-
const logIds =
|
|
159
|
-
observation.logId === null ? existing.logIds : [...existing.logIds, observation.logId];
|
|
160
|
-
const sessionIds =
|
|
161
|
-
observation.sessionId === null
|
|
162
|
-
? existing.sessionIds
|
|
163
|
-
: [...existing.sessionIds, observation.sessionId];
|
|
164
|
-
const runIds =
|
|
165
|
-
observation.runId === null ? existing.runIds : [...existing.runIds, observation.runId];
|
|
166
|
-
const groupIds =
|
|
167
|
-
observation.groupId === null ? existing.groupIds : [...existing.groupIds, observation.groupId];
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
...existing,
|
|
171
|
-
count: existing.count + 1,
|
|
172
|
-
firstSeenAt:
|
|
173
|
-
observation.observedAt < existing.firstSeenAt ? observation.observedAt : existing.firstSeenAt,
|
|
174
|
-
lastSeenAt:
|
|
175
|
-
observation.observedAt > existing.lastSeenAt ? observation.observedAt : existing.lastSeenAt,
|
|
176
|
-
logIds: uniqueNumbers(logIds),
|
|
177
|
-
sessionIds: uniqueStrings(sessionIds),
|
|
178
|
-
runIds: uniqueStrings(runIds),
|
|
179
|
-
groupIds: uniqueStrings(groupIds),
|
|
180
|
-
provider: firstString(existing.provider, observation.provider),
|
|
181
|
-
model: firstString(existing.model, observation.model),
|
|
182
|
-
apiFormat: existing.apiFormat ?? observation.apiFormat,
|
|
183
|
-
evidence: mergeEvidence(existing.evidence, observation.evidence),
|
|
184
|
-
metadata: { ...existing.metadata, ...observation.metadata },
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function observationToAlert(observation: AlertObservation): Alert {
|
|
189
|
-
return {
|
|
190
|
-
id: alertIdFor(observation.fingerprint),
|
|
191
|
-
fingerprint: observation.fingerprint,
|
|
192
|
-
severity: observation.severity,
|
|
193
|
-
category: observation.category,
|
|
194
|
-
source: observation.source,
|
|
195
|
-
status: "open",
|
|
196
|
-
title: observation.title,
|
|
197
|
-
message: observation.message,
|
|
198
|
-
count: 1,
|
|
199
|
-
firstSeenAt: observation.observedAt,
|
|
200
|
-
lastSeenAt: observation.observedAt,
|
|
201
|
-
logIds: observation.logId === null ? [] : [observation.logId],
|
|
202
|
-
sessionIds: observation.sessionId === null ? [] : [observation.sessionId],
|
|
203
|
-
runIds: observation.runId === null ? [] : [observation.runId],
|
|
204
|
-
groupIds: observation.groupId === null ? [] : [observation.groupId],
|
|
205
|
-
provider: observation.provider,
|
|
206
|
-
model: observation.model,
|
|
207
|
-
apiFormat: observation.apiFormat,
|
|
208
|
-
evidence: observation.evidence,
|
|
209
|
-
metadata: observation.metadata,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function addObservation(map: Map<string, Alert>, observation: AlertObservation): void {
|
|
214
|
-
const existing = map.get(observation.fingerprint);
|
|
215
|
-
if (existing === undefined) {
|
|
216
|
-
map.set(observation.fingerprint, observationToAlert(observation));
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
map.set(observation.fingerprint, mergeAlert(existing, observation));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function lowerText(value: string | null | undefined): string {
|
|
223
|
-
if (value === null || value === undefined) return "";
|
|
224
|
-
return value.toLowerCase();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function isTimeoutStatus(status: number | null): boolean {
|
|
228
|
-
return status === 408 || status === 504;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function isTimeoutLog(log: CapturedLog): boolean {
|
|
232
|
-
const text = `${lowerText(log.error)} ${lowerText(log.responseText)}`;
|
|
233
|
-
return (
|
|
234
|
-
isTimeoutStatus(log.responseStatus) ||
|
|
235
|
-
text.includes("timeout") ||
|
|
236
|
-
text.includes("timed out") ||
|
|
237
|
-
text.includes("abort")
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function hasFailureStatus(status: number | null): boolean {
|
|
242
|
-
return status !== null && status >= 400;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function isFailedLog(log: CapturedLog): boolean {
|
|
246
|
-
return log.error !== null && log.error !== undefined && log.error.length > 0
|
|
247
|
-
? true
|
|
248
|
-
: hasFailureStatus(log.responseStatus);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function statusLabel(status: number | null): string {
|
|
252
|
-
return status === null ? "no status" : `HTTP ${String(status)}`;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function errorDetail(log: CapturedLog): string {
|
|
256
|
-
if (log.error !== null && log.error !== undefined && log.error.length > 0) return log.error;
|
|
257
|
-
return statusLabel(log.responseStatus);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function requestFailureTitle(log: CapturedLog, timeout: boolean): string {
|
|
261
|
-
if (log.isTest === true && timeout) return "Provider test timed out";
|
|
262
|
-
if (log.isTest === true) return "Provider test failed";
|
|
263
|
-
return timeout ? "Request timed out" : "Request failed";
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function requestFailureCategory(timeout: boolean): AlertCategory {
|
|
267
|
-
return timeout ? "request-timeout" : "request-failure";
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function logProvider(log: CapturedLog): string | null {
|
|
271
|
-
return log.providerName ?? null;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function requestFailureObservation(log: CapturedLog): AlertObservation | null {
|
|
275
|
-
if (!isFailedLog(log)) return null;
|
|
276
|
-
|
|
277
|
-
const timeout = isTimeoutLog(log);
|
|
278
|
-
const category = requestFailureCategory(timeout);
|
|
279
|
-
const message = `${errorDetail(log)} while calling ${log.path}.`;
|
|
280
|
-
return {
|
|
281
|
-
fingerprint: fingerprint([
|
|
282
|
-
"proxy",
|
|
283
|
-
category,
|
|
284
|
-
logProvider(log),
|
|
285
|
-
log.model,
|
|
286
|
-
log.responseStatus,
|
|
287
|
-
errorDetail(log),
|
|
288
|
-
]),
|
|
289
|
-
severity: "critical",
|
|
290
|
-
category,
|
|
291
|
-
source: "proxy",
|
|
292
|
-
title: requestFailureTitle(log, timeout),
|
|
293
|
-
message,
|
|
294
|
-
observedAt: log.timestamp,
|
|
295
|
-
logId: log.id,
|
|
296
|
-
sessionId: log.sessionId,
|
|
297
|
-
runId: null,
|
|
298
|
-
groupId: null,
|
|
299
|
-
provider: logProvider(log),
|
|
300
|
-
model: log.model,
|
|
301
|
-
apiFormat: log.apiFormat,
|
|
302
|
-
evidence: baseEvidence(log.id, log.sessionId, null, null),
|
|
303
|
-
metadata: {
|
|
304
|
-
path: log.path,
|
|
305
|
-
status: log.responseStatus,
|
|
306
|
-
error: log.error ?? null,
|
|
307
|
-
isTest: log.isTest,
|
|
308
|
-
streaming: log.streaming,
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function slowResponseObservation(
|
|
314
|
-
log: CapturedLog,
|
|
315
|
-
slowResponseThresholdSeconds: number,
|
|
316
|
-
): AlertObservation | null {
|
|
317
|
-
if (slowResponseThresholdSeconds <= 0) return null;
|
|
318
|
-
if (isFailedLog(log)) return null;
|
|
319
|
-
if (log.elapsedMs === null) return null;
|
|
320
|
-
|
|
321
|
-
const thresholdMs = slowResponseThresholdSeconds * 1000;
|
|
322
|
-
if (log.elapsedMs < thresholdMs) return null;
|
|
323
|
-
|
|
324
|
-
const elapsedSeconds = (log.elapsedMs / 1000).toFixed(1);
|
|
325
|
-
return {
|
|
326
|
-
fingerprint: fingerprint(["proxy", "slow-response", logProvider(log), log.model, log.path]),
|
|
327
|
-
severity: "warning",
|
|
328
|
-
category: "slow-response",
|
|
329
|
-
source: "proxy",
|
|
330
|
-
title: "Slow model response",
|
|
331
|
-
message: `Response took ${elapsedSeconds}s, above the ${String(
|
|
332
|
-
slowResponseThresholdSeconds,
|
|
333
|
-
)}s threshold.`,
|
|
334
|
-
observedAt: log.timestamp,
|
|
335
|
-
logId: log.id,
|
|
336
|
-
sessionId: log.sessionId,
|
|
337
|
-
runId: null,
|
|
338
|
-
groupId: null,
|
|
339
|
-
provider: logProvider(log),
|
|
340
|
-
model: log.model,
|
|
341
|
-
apiFormat: log.apiFormat,
|
|
342
|
-
evidence: baseEvidence(log.id, log.sessionId, null, null),
|
|
343
|
-
metadata: {
|
|
344
|
-
path: log.path,
|
|
345
|
-
elapsedMs: log.elapsedMs,
|
|
346
|
-
thresholdMs,
|
|
347
|
-
streaming: log.streaming,
|
|
348
|
-
firstChunkMs: log.firstChunkMs ?? null,
|
|
349
|
-
totalStreamMs: log.totalStreamMs ?? null,
|
|
350
|
-
},
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function warningObservation(log: CapturedLog, warning: string): AlertObservation {
|
|
355
|
-
return {
|
|
356
|
-
fingerprint: fingerprint(["tool-schema", logProvider(log), log.model, warning]),
|
|
357
|
-
severity: "warning",
|
|
358
|
-
category: "tool-schema",
|
|
359
|
-
source: "tool-schema",
|
|
360
|
-
title: "Tool calling argument warning",
|
|
361
|
-
message: warning,
|
|
362
|
-
observedAt: log.timestamp,
|
|
363
|
-
logId: log.id,
|
|
364
|
-
sessionId: log.sessionId,
|
|
365
|
-
runId: null,
|
|
366
|
-
groupId: null,
|
|
367
|
-
provider: logProvider(log),
|
|
368
|
-
model: log.model,
|
|
369
|
-
apiFormat: log.apiFormat,
|
|
370
|
-
evidence: baseEvidence(log.id, log.sessionId, null, null),
|
|
371
|
-
metadata: {
|
|
372
|
-
path: log.path,
|
|
373
|
-
warning,
|
|
374
|
-
},
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function addLogObservations(
|
|
379
|
-
map: Map<string, Alert>,
|
|
380
|
-
logs: readonly CapturedLog[],
|
|
381
|
-
slowResponseThresholdSeconds: number,
|
|
382
|
-
): void {
|
|
383
|
-
for (const log of logs) {
|
|
384
|
-
const failure = requestFailureObservation(log);
|
|
385
|
-
if (failure !== null) addObservation(map, failure);
|
|
386
|
-
|
|
387
|
-
const slow = slowResponseObservation(log, slowResponseThresholdSeconds);
|
|
388
|
-
if (slow !== null) addObservation(map, slow);
|
|
389
|
-
|
|
390
|
-
for (const warning of log.warnings ?? []) {
|
|
391
|
-
addObservation(map, warningObservation(log, warning));
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function alertSeverityFromFailure(failure: RecentFailure): AlertSeverity {
|
|
397
|
-
switch (failure.classification.severity) {
|
|
398
|
-
case "high":
|
|
399
|
-
return "critical";
|
|
400
|
-
case "medium":
|
|
401
|
-
case "low":
|
|
402
|
-
return "warning";
|
|
403
|
-
case "none":
|
|
404
|
-
return "notice";
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
function providerFromRun(failure: RecentFailure): string | null {
|
|
409
|
-
const provider = failure.run.metadata["provider"] ?? failure.run.metadata["providerName"];
|
|
410
|
-
return typeof provider === "string" && provider.length > 0 ? provider : null;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function modelFromRun(failure: RecentFailure): string | null {
|
|
414
|
-
const model = failure.run.metadata["model"] ?? failure.run.metadata["modelName"];
|
|
415
|
-
return typeof model === "string" && model.length > 0 ? model : null;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function runFailureObservation(failure: RecentFailure): AlertObservation {
|
|
419
|
-
const groupId = failure.run.groupId;
|
|
420
|
-
const logEvidenceLinks = failure.classification.evidenceLogIds.map(logEvidence);
|
|
421
|
-
const links = mergeEvidence(
|
|
422
|
-
baseEvidence(null, failure.sessionId, failure.run.id, groupId),
|
|
423
|
-
logEvidenceLinks,
|
|
424
|
-
);
|
|
425
|
-
|
|
426
|
-
return {
|
|
427
|
-
fingerprint: fingerprint(["run", failure.run.id, failure.classification.category]),
|
|
428
|
-
severity: alertSeverityFromFailure(failure),
|
|
429
|
-
category: "run-failure",
|
|
430
|
-
source: "run",
|
|
431
|
-
title: `Run ${failure.run.status}`,
|
|
432
|
-
message: failure.classification.summary,
|
|
433
|
-
observedAt: failure.updatedAt,
|
|
434
|
-
logId: failure.classification.evidenceLogIds[0] ?? null,
|
|
435
|
-
sessionId: failure.sessionId,
|
|
436
|
-
runId: failure.run.id,
|
|
437
|
-
groupId,
|
|
438
|
-
provider: providerFromRun(failure),
|
|
439
|
-
model: modelFromRun(failure),
|
|
440
|
-
apiFormat: null,
|
|
441
|
-
evidence: links,
|
|
442
|
-
metadata: {
|
|
443
|
-
runStatus: failure.run.status,
|
|
444
|
-
failureCategory: failure.classification.category,
|
|
445
|
-
evidenceMarkdownPath: failure.evidenceMarkdownPath,
|
|
446
|
-
},
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function addRunFailureObservations(
|
|
451
|
-
map: Map<string, Alert>,
|
|
452
|
-
recentFailures: readonly RecentFailure[],
|
|
453
|
-
): void {
|
|
454
|
-
for (const failure of recentFailures) {
|
|
455
|
-
addObservation(map, runFailureObservation(failure));
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function memberProvider(member: InspectorGroupMember): string | null {
|
|
460
|
-
return member.provider !== null && member.provider.length > 0 ? member.provider : null;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function memberModel(member: InspectorGroupMember): string | null {
|
|
464
|
-
return member.model !== null && member.model.length > 0 ? member.model : null;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function isFailedMember(member: InspectorGroupMember): boolean {
|
|
468
|
-
return member.status === "failed" || member.status === "cancelled";
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function groupFailureObservation(group: InspectorGroup): AlertObservation | null {
|
|
472
|
-
if (group.status !== "failed" && group.status !== "cancelled") return null;
|
|
473
|
-
return {
|
|
474
|
-
fingerprint: fingerprint(["group", group.id, group.status]),
|
|
475
|
-
severity: "critical",
|
|
476
|
-
category: "group-failure",
|
|
477
|
-
source: "group",
|
|
478
|
-
title: `Group ${group.status}`,
|
|
479
|
-
message: `${group.title} is marked ${group.status}.`,
|
|
480
|
-
observedAt: group.updatedAt,
|
|
481
|
-
logId: null,
|
|
482
|
-
sessionId: null,
|
|
483
|
-
runId: null,
|
|
484
|
-
groupId: group.id,
|
|
485
|
-
provider: null,
|
|
486
|
-
model: null,
|
|
487
|
-
apiFormat: null,
|
|
488
|
-
evidence: baseEvidence(null, null, null, group.id),
|
|
489
|
-
metadata: {
|
|
490
|
-
groupStatus: group.status,
|
|
491
|
-
memberCount: group.members.length,
|
|
492
|
-
},
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
function groupMemberFailureObservation(
|
|
497
|
-
group: InspectorGroup,
|
|
498
|
-
member: InspectorGroupMember,
|
|
499
|
-
): AlertObservation {
|
|
500
|
-
return {
|
|
501
|
-
fingerprint: fingerprint(["group-member", group.id, member.id, member.status]),
|
|
502
|
-
severity: "critical",
|
|
503
|
-
category: "group-failure",
|
|
504
|
-
source: "group",
|
|
505
|
-
title: "Group member failed",
|
|
506
|
-
message: `${member.label ?? member.sessionId} is marked ${member.status ?? "unknown"}.`,
|
|
507
|
-
observedAt: member.updatedAt,
|
|
508
|
-
logId: null,
|
|
509
|
-
sessionId: member.sessionId,
|
|
510
|
-
runId: member.runId,
|
|
511
|
-
groupId: group.id,
|
|
512
|
-
provider: memberProvider(member),
|
|
513
|
-
model: memberModel(member),
|
|
514
|
-
apiFormat: null,
|
|
515
|
-
evidence: baseEvidence(null, member.sessionId, member.runId, group.id),
|
|
516
|
-
metadata: {
|
|
517
|
-
groupTitle: group.title,
|
|
518
|
-
memberId: member.id,
|
|
519
|
-
memberStatus: member.status,
|
|
520
|
-
},
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
function groupIncompleteObservation(
|
|
525
|
-
group: InspectorGroup,
|
|
526
|
-
missingStatusCount: number,
|
|
527
|
-
): AlertObservation {
|
|
528
|
-
return {
|
|
529
|
-
fingerprint: fingerprint(["group-incomplete", group.id, missingStatusCount]),
|
|
530
|
-
severity: "notice",
|
|
531
|
-
category: "group-incomplete",
|
|
532
|
-
source: "group",
|
|
533
|
-
title: "Group has unclassified members",
|
|
534
|
-
message: `${group.title} has ${String(missingStatusCount)} member(s) without a final status.`,
|
|
535
|
-
observedAt: group.updatedAt,
|
|
536
|
-
logId: null,
|
|
537
|
-
sessionId: null,
|
|
538
|
-
runId: null,
|
|
539
|
-
groupId: group.id,
|
|
540
|
-
provider: null,
|
|
541
|
-
model: null,
|
|
542
|
-
apiFormat: null,
|
|
543
|
-
evidence: baseEvidence(null, null, null, group.id),
|
|
544
|
-
metadata: {
|
|
545
|
-
groupTitle: group.title,
|
|
546
|
-
missingStatusCount,
|
|
547
|
-
},
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
function addGroupObservations(map: Map<string, Alert>, groups: readonly InspectorGroup[]): void {
|
|
552
|
-
for (const group of groups) {
|
|
553
|
-
const groupFailure = groupFailureObservation(group);
|
|
554
|
-
if (groupFailure !== null) addObservation(map, groupFailure);
|
|
555
|
-
|
|
556
|
-
let missingStatusCount = 0;
|
|
557
|
-
for (const member of group.members) {
|
|
558
|
-
if (isFailedMember(member)) {
|
|
559
|
-
addObservation(map, groupMemberFailureObservation(group, member));
|
|
560
|
-
}
|
|
561
|
-
if (member.status === null) missingStatusCount += 1;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
if (missingStatusCount > 0) {
|
|
565
|
-
addObservation(map, groupIncompleteObservation(group, missingStatusCount));
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function alertMatchesFilters(alert: Alert, filters: AlertFilters): boolean {
|
|
571
|
-
if (filters.severity !== undefined && alert.severity !== filters.severity) return false;
|
|
572
|
-
if (filters.category !== undefined && alert.category !== filters.category) return false;
|
|
573
|
-
if (filters.source !== undefined && alert.source !== filters.source) return false;
|
|
574
|
-
return true;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
function sortAlerts(alerts: readonly Alert[]): Alert[] {
|
|
578
|
-
return [...alerts].sort((left, right) => {
|
|
579
|
-
const timeCompare = right.lastSeenAt.localeCompare(left.lastSeenAt);
|
|
580
|
-
if (timeCompare !== 0) return timeCompare;
|
|
581
|
-
return left.id.localeCompare(right.id);
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
export function buildAlertSummary(alerts: readonly Alert[]): AlertSummary {
|
|
586
|
-
let critical = 0;
|
|
587
|
-
let warning = 0;
|
|
588
|
-
let notice = 0;
|
|
589
|
-
const byCategory = new Map<AlertCategory, number>();
|
|
590
|
-
|
|
591
|
-
for (const alert of alerts) {
|
|
592
|
-
switch (alert.severity) {
|
|
593
|
-
case "critical":
|
|
594
|
-
critical += 1;
|
|
595
|
-
break;
|
|
596
|
-
case "warning":
|
|
597
|
-
warning += 1;
|
|
598
|
-
break;
|
|
599
|
-
case "notice":
|
|
600
|
-
notice += 1;
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
byCategory.set(alert.category, (byCategory.get(alert.category) ?? 0) + 1);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
return {
|
|
607
|
-
total: alerts.length,
|
|
608
|
-
open: alerts.length,
|
|
609
|
-
critical,
|
|
610
|
-
warning,
|
|
611
|
-
notice,
|
|
612
|
-
byCategory: [...byCategory.entries()]
|
|
613
|
-
.map(([category, count]) => ({ category, count }))
|
|
614
|
-
.sort(
|
|
615
|
-
(left, right) => right.count - left.count || left.category.localeCompare(right.category),
|
|
616
|
-
),
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
export function collectAlertsFromEvidence(input: AlertCollectionInput): Alert[] {
|
|
621
|
-
const map = new Map<string, Alert>();
|
|
622
|
-
addLogObservations(map, input.logs, input.slowResponseThresholdSeconds);
|
|
623
|
-
addRunFailureObservations(map, input.recentFailures);
|
|
624
|
-
addGroupObservations(map, input.groups);
|
|
625
|
-
return sortAlerts([...map.values()]);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
function filterAlerts(alerts: readonly Alert[], filters: AlertFilters): Alert[] {
|
|
629
|
-
return alerts.filter((alert) => alertMatchesFilters(alert, filters));
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
export async function listAlerts(options: ListAlertsOptions = {}): Promise<AlertListResponse> {
|
|
633
|
-
const limit = clampAlertLimit(options.limit);
|
|
634
|
-
const scanLimit = clampAlertScanLimit(options.scanLimit);
|
|
635
|
-
const logPage = await listLogsCursorPage({
|
|
636
|
-
limit: scanLimit,
|
|
637
|
-
includeBodies: false,
|
|
638
|
-
anchor: "newest",
|
|
639
|
-
});
|
|
640
|
-
const config = getConfig();
|
|
641
|
-
const alerts = collectAlertsFromEvidence({
|
|
642
|
-
logs: logPage.logs,
|
|
643
|
-
recentFailures: listRecentFailures(scanLimit).failures,
|
|
644
|
-
groups: listGroups(),
|
|
645
|
-
slowResponseThresholdSeconds: config.slowResponseThresholdSeconds,
|
|
646
|
-
});
|
|
647
|
-
const filtered = filterAlerts(alerts, options);
|
|
648
|
-
return {
|
|
649
|
-
alerts: filtered.slice(0, limit),
|
|
650
|
-
total: filtered.length,
|
|
651
|
-
limit,
|
|
652
|
-
summary: buildAlertSummary(filtered),
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
export async function getAlertSummary(
|
|
657
|
-
options: Pick<ListAlertsOptions, "scanLimit"> = {},
|
|
658
|
-
): Promise<AlertSummary> {
|
|
659
|
-
const response = await listAlerts({
|
|
660
|
-
limit: MAX_ALERT_LIMIT,
|
|
661
|
-
scanLimit: options.scanLimit,
|
|
662
|
-
});
|
|
663
|
-
return response.summary;
|
|
664
|
-
}
|