@tonyclaw/agent-inspector 3.1.32 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.output/backend/nitro.json +1 -1
- package/.output/cli.js +241 -120
- package/.output/server/_ssr/index.mjs +1 -1
- package/.output/server/_ssr/{router-oXUk3MBR.mjs → router-BBY_zWRK.mjs} +91 -3
- package/.output/server/index.mjs +1 -1
- package/.output/ui/assets/{CompareDrawer-BtfPSpkV.js → CompareDrawer-rtNElN-B.js} +1 -1
- package/.output/ui/assets/{InspectorPet-D9DPPQ3n.js → InspectorPet-QaAiuF3d.js} +1 -1
- package/.output/ui/assets/{ProxyViewerContainer-Buu8vkCK.js → ProxyViewerContainer-6twNZHwl.js} +4 -4
- package/.output/ui/assets/{ReplayDialog-BER-QzpD.js → ReplayDialog-B7KlziO2.js} +1 -1
- package/.output/ui/assets/{RequestAnatomy-C8Zwxrr7.js → RequestAnatomy-2XVFBrW4.js} +1 -1
- package/.output/ui/assets/{ResponseView-DDpKdYk6.js → ResponseView-BULgzLVB.js} +1 -1
- package/.output/ui/assets/{StreamingChunkSequence-sMPGG7Sw.js → StreamingChunkSequence-DSkvkbns.js} +1 -1
- package/.output/ui/assets/{_sessionId-e4IheHnP.js → _sessionId-D2dmJi3G.js} +1 -1
- package/.output/ui/assets/{_sessionId-C5Uv72Fx.js → _sessionId-DcS0s1Mr.js} +1 -1
- package/.output/ui/assets/{index-B__qT0Yd.js → index-B0TN1KKO.js} +2 -2
- package/.output/ui/assets/{index-Be3bTCzi.js → index-Bva1zHEs.js} +1 -1
- package/.output/ui/assets/{index-C9q__p8J.js → index-BzBExOxu.js} +1 -1
- package/.output/ui/assets/{index-CtB0deSZ.js → index-k6sRQz55.js} +1 -1
- package/.output/ui/assets/{json-viewer-Db0AFp-7.js → json-viewer-CWM4tY-j.js} +1 -1
- package/.output/ui/assets/{jszip.min-DkY0Ym_q.js → jszip.min-BkWvRFlo.js} +1 -1
- package/.output/ui/index.html +1 -1
- package/package.json +8 -13
- 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 -1397
- 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 -253
- 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,235 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
type EvidenceExportOptions,
|
|
6
|
-
type EvidenceExportResult,
|
|
7
|
-
type InspectorRun,
|
|
8
|
-
type InspectorRunEvidence,
|
|
9
|
-
} from "../lib/runContract";
|
|
10
|
-
import { getDataDir } from "./dataDir";
|
|
11
|
-
import { analyzeEvidence } from "./evidenceAnalysis";
|
|
12
|
-
import { getSessionInfo } from "./store";
|
|
13
|
-
import { updateRunEvidence } from "./runStore";
|
|
14
|
-
import {
|
|
15
|
-
ensurePrivateDirectorySync,
|
|
16
|
-
PRIVATE_FILE_MODE,
|
|
17
|
-
securePrivateFileSync,
|
|
18
|
-
} from "./privateDataPath";
|
|
19
|
-
|
|
20
|
-
type EvidenceDocument = EvidenceExportResult;
|
|
21
|
-
|
|
22
|
-
function evidenceDir(runId: string): string {
|
|
23
|
-
return join(getDataDir(), "evidence", runId);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function jsonPath(runId: string): string {
|
|
27
|
-
return join(evidenceDir(runId), "evidence.json");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function markdownPath(runId: string): string {
|
|
31
|
-
return join(evidenceDir(runId), "evidence.md");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function htmlPath(runId: string): string {
|
|
35
|
-
return join(evidenceDir(runId), "evidence.html");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function formatList(values: readonly string[]): string {
|
|
39
|
-
return values.length > 0 ? values.join(", ") : "n/a";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function escapeHtml(value: string): string {
|
|
43
|
-
return value
|
|
44
|
-
.replace(/&/g, "&")
|
|
45
|
-
.replace(/</g, "<")
|
|
46
|
-
.replace(/>/g, ">")
|
|
47
|
-
.replace(/"/g, """);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function buildMarkdown(document: EvidenceDocument): string {
|
|
51
|
-
const session = document.session;
|
|
52
|
-
const lines = [
|
|
53
|
-
`# ${document.run.title}`,
|
|
54
|
-
"",
|
|
55
|
-
`- Run ID: ${document.run.id}`,
|
|
56
|
-
`- Session ID: ${document.run.sessionId}`,
|
|
57
|
-
`- Group ID: ${document.run.groupId ?? "n/a"}`,
|
|
58
|
-
`- Status: ${document.run.status}`,
|
|
59
|
-
`- Project: ${document.run.project ?? "n/a"}`,
|
|
60
|
-
`- Agent: ${document.run.agent ?? "n/a"}`,
|
|
61
|
-
`- Created: ${document.run.createdAt}`,
|
|
62
|
-
"",
|
|
63
|
-
`- Outcome: ${document.classification.outcome}`,
|
|
64
|
-
`- Failure Category: ${document.classification.category}`,
|
|
65
|
-
`- Severity: ${document.classification.severity}`,
|
|
66
|
-
`- Evidence JSON: ${document.evidence.jsonPath}`,
|
|
67
|
-
`- Evidence HTML: ${document.evidence.htmlPath}`,
|
|
68
|
-
"",
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
if (document.run.task !== null) {
|
|
72
|
-
lines.push("## Task", "", document.run.task, "");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (session === null) {
|
|
76
|
-
lines.push("## Session", "", "No Inspector session data was available for this run.", "");
|
|
77
|
-
} else {
|
|
78
|
-
lines.push(
|
|
79
|
-
"## Session",
|
|
80
|
-
"",
|
|
81
|
-
`- Inspector URL: ${session.inspectorUrl}`,
|
|
82
|
-
`- Compact Logs URL: ${session.compactLogsUrl}`,
|
|
83
|
-
`- Status: ${session.status}`,
|
|
84
|
-
`- Coverage: ${session.logCoverage}`,
|
|
85
|
-
`- Requests: ${session.requestCount}`,
|
|
86
|
-
`- Errors: ${session.errorCount}`,
|
|
87
|
-
`- Models: ${formatList(session.models)}`,
|
|
88
|
-
`- Providers: ${formatList(session.providers)}`,
|
|
89
|
-
`- Tokens: ${session.tokenUsage.total}`,
|
|
90
|
-
"",
|
|
91
|
-
"## Failure Classification",
|
|
92
|
-
"",
|
|
93
|
-
document.classification.summary,
|
|
94
|
-
"",
|
|
95
|
-
"### Evidence Logs",
|
|
96
|
-
"",
|
|
97
|
-
document.classification.evidenceLogIds.length > 0
|
|
98
|
-
? document.classification.evidenceLogIds.map((id) => `- #${id}`).join("\n")
|
|
99
|
-
: "No failing log ids were identified.",
|
|
100
|
-
"",
|
|
101
|
-
"### Suggested Next Actions",
|
|
102
|
-
"",
|
|
103
|
-
...document.classification.hints.map((hint) => `- ${hint}`),
|
|
104
|
-
"",
|
|
105
|
-
"## Run Timeline",
|
|
106
|
-
"",
|
|
107
|
-
"| Time | Event | Severity | Evidence |",
|
|
108
|
-
"| --- | --- | --- | --- |",
|
|
109
|
-
...document.timeline.map((event) => {
|
|
110
|
-
const evidence = event.logId === null ? "n/a" : `log ${event.logId}`;
|
|
111
|
-
return `| ${event.timestamp} | ${event.title} | ${event.severity} | ${evidence} |`;
|
|
112
|
-
}),
|
|
113
|
-
"",
|
|
114
|
-
"## Latest Logs",
|
|
115
|
-
"",
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
if (session.latestLogs.length === 0) {
|
|
119
|
-
lines.push("No compact logs were available.", "");
|
|
120
|
-
} else {
|
|
121
|
-
lines.push(
|
|
122
|
-
"| ID | Status | Model | Latency | Stream | Path | Error |",
|
|
123
|
-
"| --- | --- | --- | --- | --- | --- | --- |",
|
|
124
|
-
);
|
|
125
|
-
for (const log of session.latestLogs) {
|
|
126
|
-
const streamTiming = log.isStreaming
|
|
127
|
-
? `first=${log.firstChunkMs ?? "n/a"}ms total=${log.totalStreamMs ?? "n/a"}ms tps=${
|
|
128
|
-
log.tokensPerSecond ?? "n/a"
|
|
129
|
-
}`
|
|
130
|
-
: "n/a";
|
|
131
|
-
lines.push(
|
|
132
|
-
`| ${log.id} | ${log.status ?? "n/a"} | ${log.model ?? "n/a"} | ${
|
|
133
|
-
log.latencyMs ?? "n/a"
|
|
134
|
-
} | ${streamTiming} | ${log.path} | ${log.hasError ? "yes" : "no"} |`,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
lines.push("");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
lines.push("## Jenkins Report", "", document.jenkinsReport.markdown, "");
|
|
142
|
-
|
|
143
|
-
return `${lines.join("\n")}\n`;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function buildHtml(markdown: string, title: string): string {
|
|
147
|
-
return `<!doctype html>
|
|
148
|
-
<html lang="en">
|
|
149
|
-
<head>
|
|
150
|
-
<meta charset="utf-8">
|
|
151
|
-
<title>${escapeHtml(title)}</title>
|
|
152
|
-
<style>
|
|
153
|
-
body { font-family: system-ui, sans-serif; max-width: 960px; margin: 40px auto; line-height: 1.5; }
|
|
154
|
-
pre { white-space: pre-wrap; background: #f6f8fa; padding: 16px; border-radius: 8px; }
|
|
155
|
-
</style>
|
|
156
|
-
</head>
|
|
157
|
-
<body>
|
|
158
|
-
<pre>${escapeHtml(markdown)}</pre>
|
|
159
|
-
</body>
|
|
160
|
-
</html>
|
|
161
|
-
`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export async function exportRunEvidence(
|
|
165
|
-
run: InspectorRun,
|
|
166
|
-
options: EvidenceExportOptions,
|
|
167
|
-
baseUrl: string,
|
|
168
|
-
): Promise<EvidenceExportResult> {
|
|
169
|
-
const session = await getSessionInfo(run.sessionId, {
|
|
170
|
-
baseUrl,
|
|
171
|
-
includeHistory: options?.includeHistory,
|
|
172
|
-
latestLogLimit: options?.latestLogLimit,
|
|
173
|
-
});
|
|
174
|
-
const exportedAt = new Date().toISOString();
|
|
175
|
-
const evidence: InspectorRunEvidence = {
|
|
176
|
-
jsonPath: jsonPath(run.id),
|
|
177
|
-
markdownPath: markdownPath(run.id),
|
|
178
|
-
htmlPath: htmlPath(run.id),
|
|
179
|
-
exportedAt,
|
|
180
|
-
};
|
|
181
|
-
const documentRun: InspectorRun = {
|
|
182
|
-
...run,
|
|
183
|
-
evidence,
|
|
184
|
-
updatedAt: exportedAt,
|
|
185
|
-
};
|
|
186
|
-
const analysis = analyzeEvidence({
|
|
187
|
-
run: documentRun,
|
|
188
|
-
session,
|
|
189
|
-
exportedAt,
|
|
190
|
-
evidencePaths: {
|
|
191
|
-
jsonPath: evidence.jsonPath,
|
|
192
|
-
markdownPath: evidence.markdownPath,
|
|
193
|
-
htmlPath: evidence.htmlPath,
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
const document: EvidenceDocument = {
|
|
197
|
-
run: documentRun,
|
|
198
|
-
evidence,
|
|
199
|
-
session,
|
|
200
|
-
timeline: analysis.timeline,
|
|
201
|
-
classification: analysis.classification,
|
|
202
|
-
jenkinsReport: analysis.jenkinsReport,
|
|
203
|
-
};
|
|
204
|
-
const markdown = buildMarkdown(document);
|
|
205
|
-
|
|
206
|
-
assert(ensurePrivateDirectorySync(evidenceDir(run.id)), "Could not secure evidence directory");
|
|
207
|
-
writeFileSync(evidence.jsonPath, `${JSON.stringify({ ...document, evidence }, null, 2)}\n`, {
|
|
208
|
-
encoding: "utf8",
|
|
209
|
-
mode: PRIVATE_FILE_MODE,
|
|
210
|
-
});
|
|
211
|
-
writeFileSync(evidence.markdownPath, markdown, {
|
|
212
|
-
encoding: "utf8",
|
|
213
|
-
mode: PRIVATE_FILE_MODE,
|
|
214
|
-
});
|
|
215
|
-
writeFileSync(evidence.htmlPath, buildHtml(markdown, run.title), {
|
|
216
|
-
encoding: "utf8",
|
|
217
|
-
mode: PRIVATE_FILE_MODE,
|
|
218
|
-
});
|
|
219
|
-
for (const path of [evidence.jsonPath, evidence.markdownPath, evidence.htmlPath]) {
|
|
220
|
-
assert(securePrivateFileSync(path), `Could not secure evidence file ${path}`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const updatedRun = updateRunEvidence(run.id, evidence) ?? documentRun;
|
|
224
|
-
return { ...document, run: updatedRun };
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export function readEvidenceMarkdown(run: InspectorRun): string | null {
|
|
228
|
-
const path = run.evidence?.markdownPath;
|
|
229
|
-
if (path === undefined || !existsSync(path)) return null;
|
|
230
|
-
try {
|
|
231
|
-
return readFileSync(path, "utf8");
|
|
232
|
-
} catch {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { CapturedLog } from "../../schemas";
|
|
2
|
-
import type { ProviderAdapter } from "../providerAdapter";
|
|
3
|
-
import { registry } from "../providers";
|
|
4
|
-
import { extractAnthropicStream } from "./stream";
|
|
5
|
-
|
|
6
|
-
const DEFAULT_UPSTREAM = "https://api.anthropic.com";
|
|
7
|
-
|
|
8
|
-
// Default routes - MiniMax is hardcoded here
|
|
9
|
-
const DEFAULT_ROUTES: Record<string, string> = {
|
|
10
|
-
MiniMax: "https://api.minimaxi.com/anthropic",
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function getUpstreamForModel(model: string): string {
|
|
14
|
-
let bestPrefix = "";
|
|
15
|
-
let bestUrl = DEFAULT_UPSTREAM;
|
|
16
|
-
|
|
17
|
-
for (const [prefix, url] of Object.entries(DEFAULT_ROUTES)) {
|
|
18
|
-
if (model.startsWith(prefix) && prefix.length > bestPrefix.length) {
|
|
19
|
-
bestPrefix = prefix;
|
|
20
|
-
bestUrl = url;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return bestUrl;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Anthropic Provider Implementation
|
|
29
|
-
*/
|
|
30
|
-
export const anthropicProvider: ProviderAdapter = {
|
|
31
|
-
name: "anthropic",
|
|
32
|
-
|
|
33
|
-
matches(model: string): boolean {
|
|
34
|
-
const modelLower = model.toLowerCase();
|
|
35
|
-
|
|
36
|
-
// Don't match OpenAI models
|
|
37
|
-
if (modelLower.startsWith("openai-")) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Match Anthropic models
|
|
42
|
-
if (modelLower.includes("claude") || modelLower.includes("anthropic")) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Match known route prefixes (e.g., MiniMax)
|
|
47
|
-
for (const prefix of Object.keys(DEFAULT_ROUTES)) {
|
|
48
|
-
if (modelLower.startsWith(prefix.toLowerCase())) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Default to Anthropic for unknown models (legacy behavior)
|
|
54
|
-
return true;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
getUpstreamBase(_isChatCompletions: boolean, providerConfig?: { baseUrl?: string }): string {
|
|
58
|
-
if (providerConfig?.baseUrl !== undefined) {
|
|
59
|
-
return providerConfig.baseUrl;
|
|
60
|
-
}
|
|
61
|
-
return DEFAULT_UPSTREAM;
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
extractStream(
|
|
65
|
-
raw: string,
|
|
66
|
-
log: CapturedLog,
|
|
67
|
-
fallbackModel?: string,
|
|
68
|
-
collectChunks?: boolean,
|
|
69
|
-
): string {
|
|
70
|
-
return extractAnthropicStream(raw, log, fallbackModel, collectChunks);
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Register the provider
|
|
75
|
-
registry.register(anthropicProvider);
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { FormatHandler, ParsedRequest } from "../handler";
|
|
2
|
-
import type { CapturedLog, TokenUsage } from "../../schemas";
|
|
3
|
-
import { AnthropicRequestSchema, AnthropicResponseSchema } from "./schemas";
|
|
4
|
-
import { extractAnthropicStream } from "./stream";
|
|
5
|
-
|
|
6
|
-
export const AnthropicFormatHandler: FormatHandler = {
|
|
7
|
-
format: "anthropic",
|
|
8
|
-
|
|
9
|
-
parseRequest(rawBody: string, headers?: Headers): ParsedRequest | null {
|
|
10
|
-
try {
|
|
11
|
-
const json: unknown = JSON.parse(rawBody);
|
|
12
|
-
const result = AnthropicRequestSchema.safeParse(json);
|
|
13
|
-
if (result.success) {
|
|
14
|
-
return {
|
|
15
|
-
model: result.data.model,
|
|
16
|
-
sessionId:
|
|
17
|
-
result.data.metadata?.user_id ??
|
|
18
|
-
headers?.get("x-agent-inspector-session-id") ??
|
|
19
|
-
headers?.get("x-session-affinity") ??
|
|
20
|
-
null,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
extractTokens(responseBody: string): TokenUsage {
|
|
30
|
-
try {
|
|
31
|
-
const json: unknown = JSON.parse(responseBody);
|
|
32
|
-
const result = AnthropicResponseSchema.safeParse(json);
|
|
33
|
-
if (result.success) {
|
|
34
|
-
return {
|
|
35
|
-
inputTokens: result.data.usage.input_tokens ?? null,
|
|
36
|
-
outputTokens: result.data.usage.output_tokens ?? null,
|
|
37
|
-
cacheCreationInputTokens: result.data.usage.cache_creation_input_tokens ?? null,
|
|
38
|
-
cacheReadInputTokens: result.data.usage.cache_read_input_tokens ?? null,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
} catch {
|
|
42
|
-
// Fall through
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
inputTokens: null,
|
|
46
|
-
outputTokens: null,
|
|
47
|
-
cacheCreationInputTokens: null,
|
|
48
|
-
cacheReadInputTokens: null,
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
extractStream(
|
|
53
|
-
raw: string,
|
|
54
|
-
log: CapturedLog,
|
|
55
|
-
fallbackModel?: string,
|
|
56
|
-
collectChunks?: boolean,
|
|
57
|
-
): string {
|
|
58
|
-
return extractAnthropicStream(raw, log, fallbackModel, collectChunks);
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
detectFormat(rawBody: string | null): boolean {
|
|
62
|
-
if (rawBody === null) return false;
|
|
63
|
-
try {
|
|
64
|
-
const json: unknown = JSON.parse(rawBody);
|
|
65
|
-
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
66
|
-
const keys = Object.keys(json);
|
|
67
|
-
// Anthropic puts `system` as a top-level key alongside `model` and `messages`
|
|
68
|
-
return keys.includes("model") && keys.includes("messages") && keys.includes("system");
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
} catch {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Register format handler
|
|
2
|
-
import "./register";
|
|
3
|
-
|
|
4
|
-
export { AnthropicFormatHandler } from "./handler";
|
|
5
|
-
export {
|
|
6
|
-
AnthropicRequestSchema,
|
|
7
|
-
AnthropicResponseSchema,
|
|
8
|
-
SseEventSchema,
|
|
9
|
-
type AnthropicResponse,
|
|
10
|
-
type ResponseContentBlockType,
|
|
11
|
-
} from "./schemas";
|
|
12
|
-
export { extractAnthropicStream } from "./stream";
|
|
13
|
-
export { anthropicProvider } from "./anthropicProvider";
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import type { CapturedLog, JsonValue } from "../../schemas";
|
|
2
|
-
import { trustAsJsonValue } from "../jsonSchema";
|
|
3
|
-
import { SseEventSchema } from "./schemas";
|
|
4
|
-
|
|
5
|
-
type StreamTextBlock = { type: "text"; text: string };
|
|
6
|
-
type StreamThinkingBlock = { type: "thinking"; thinking: string; signature: string };
|
|
7
|
-
type StreamThinkBlock = { type: "think"; thinking: string; signature: string };
|
|
8
|
-
type StreamToolUseBlock = { type: "tool_use"; id: string; name: string; inputJson: string };
|
|
9
|
-
type StreamBlock = StreamTextBlock | StreamThinkingBlock | StreamThinkBlock | StreamToolUseBlock;
|
|
10
|
-
|
|
11
|
-
function parseInputJson(json: string): Record<string, unknown> {
|
|
12
|
-
if (json === "") return {};
|
|
13
|
-
try {
|
|
14
|
-
const parsed: unknown = JSON.parse(json);
|
|
15
|
-
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
16
|
-
return { ...parsed };
|
|
17
|
-
}
|
|
18
|
-
return {};
|
|
19
|
-
} catch {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function finalizeBlock(block: StreamBlock): Record<string, unknown> {
|
|
25
|
-
switch (block.type) {
|
|
26
|
-
case "text":
|
|
27
|
-
return { type: "text", text: block.text };
|
|
28
|
-
case "thinking": {
|
|
29
|
-
const out: Record<string, unknown> = { type: "thinking", thinking: block.thinking };
|
|
30
|
-
if (block.signature !== "") out.signature = block.signature;
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
case "think": {
|
|
34
|
-
const out: Record<string, unknown> = { type: "think", thinking: block.thinking };
|
|
35
|
-
if (block.signature !== "") out.signature = block.signature;
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
case "tool_use":
|
|
39
|
-
return {
|
|
40
|
-
type: "tool_use",
|
|
41
|
-
id: block.id,
|
|
42
|
-
name: block.name,
|
|
43
|
-
input: parseInputJson(block.inputJson),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extract Anthropic streaming response and return normalized JSON.
|
|
50
|
-
* Optionally collects SSE chunks into log.streamingChunks for debugging/display.
|
|
51
|
-
*/
|
|
52
|
-
export function extractAnthropicStream(
|
|
53
|
-
raw: string,
|
|
54
|
-
log: CapturedLog,
|
|
55
|
-
fallbackModel?: string,
|
|
56
|
-
collectChunks?: boolean,
|
|
57
|
-
): string {
|
|
58
|
-
const blocks = new Map<number, StreamBlock>();
|
|
59
|
-
let id = "";
|
|
60
|
-
let model = "";
|
|
61
|
-
let stopReason: string | null = null;
|
|
62
|
-
let stopSequence: string | null = null;
|
|
63
|
-
let inputTokens = 0;
|
|
64
|
-
let outputTokens = 0;
|
|
65
|
-
|
|
66
|
-
const MAX_CHUNKS = 1000;
|
|
67
|
-
let chunkIndex = 0;
|
|
68
|
-
let streamStartMs = 0;
|
|
69
|
-
const chunks: Array<{ index: number; timestamp: number; type: string; data: JsonValue }> = [];
|
|
70
|
-
|
|
71
|
-
for (const line of raw.split("\n")) {
|
|
72
|
-
const trimmedLine = line.trim();
|
|
73
|
-
if (!trimmedLine.startsWith("data: ")) continue;
|
|
74
|
-
try {
|
|
75
|
-
const json: unknown = JSON.parse(trimmedLine.slice(6));
|
|
76
|
-
const parsed = SseEventSchema.safeParse(json);
|
|
77
|
-
if (!parsed.success) continue;
|
|
78
|
-
const data = parsed.data;
|
|
79
|
-
|
|
80
|
-
if (chunkIndex === 0) streamStartMs = Date.now();
|
|
81
|
-
|
|
82
|
-
if (collectChunks === true && chunks.length < MAX_CHUNKS) {
|
|
83
|
-
chunks.push({
|
|
84
|
-
index: chunkIndex,
|
|
85
|
-
timestamp: Date.now() - streamStartMs,
|
|
86
|
-
type: data.type,
|
|
87
|
-
// `data` has already been validated by SseEventSchema above; the
|
|
88
|
-
// recursive JsonValue walk is a redundant full-tree zod parse on
|
|
89
|
-
// every SSE event. See trustAsJsonValue for the rationale.
|
|
90
|
-
data: trustAsJsonValue(data),
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
chunkIndex++;
|
|
94
|
-
|
|
95
|
-
switch (data.type) {
|
|
96
|
-
case "message_start":
|
|
97
|
-
id = data.message.id;
|
|
98
|
-
model = data.message.model;
|
|
99
|
-
inputTokens = data.message.usage.input_tokens;
|
|
100
|
-
log.inputTokens = inputTokens;
|
|
101
|
-
log.cacheCreationInputTokens = data.message.usage.cache_creation_input_tokens ?? null;
|
|
102
|
-
log.cacheReadInputTokens = data.message.usage.cache_read_input_tokens ?? null;
|
|
103
|
-
if (log.model === null) log.model = model;
|
|
104
|
-
break;
|
|
105
|
-
case "content_block_start": {
|
|
106
|
-
const cb = data.content_block;
|
|
107
|
-
switch (cb.type) {
|
|
108
|
-
case "text":
|
|
109
|
-
blocks.set(data.index, { type: "text", text: cb.text ?? "" });
|
|
110
|
-
break;
|
|
111
|
-
case "thinking":
|
|
112
|
-
blocks.set(data.index, {
|
|
113
|
-
type: "thinking",
|
|
114
|
-
thinking: cb.thinking ?? "",
|
|
115
|
-
signature: cb.signature ?? "",
|
|
116
|
-
});
|
|
117
|
-
break;
|
|
118
|
-
case "think":
|
|
119
|
-
blocks.set(data.index, {
|
|
120
|
-
type: "think",
|
|
121
|
-
thinking: cb.thinking ?? "",
|
|
122
|
-
signature: cb.signature ?? "",
|
|
123
|
-
});
|
|
124
|
-
break;
|
|
125
|
-
case "tool_use":
|
|
126
|
-
blocks.set(data.index, {
|
|
127
|
-
type: "tool_use",
|
|
128
|
-
id: cb.id,
|
|
129
|
-
name: cb.name,
|
|
130
|
-
inputJson: "",
|
|
131
|
-
});
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case "content_block_delta": {
|
|
137
|
-
const block = blocks.get(data.index);
|
|
138
|
-
if (block === undefined) break;
|
|
139
|
-
const delta = data.delta;
|
|
140
|
-
if (delta.type === "text_delta" && block.type === "text") {
|
|
141
|
-
block.text += delta.text;
|
|
142
|
-
} else if (
|
|
143
|
-
delta.type === "thinking_delta" &&
|
|
144
|
-
(block.type === "thinking" || block.type === "think")
|
|
145
|
-
) {
|
|
146
|
-
block.thinking += delta.thinking;
|
|
147
|
-
} else if (
|
|
148
|
-
delta.type === "signature_delta" &&
|
|
149
|
-
(block.type === "thinking" || block.type === "think")
|
|
150
|
-
) {
|
|
151
|
-
block.signature += delta.signature;
|
|
152
|
-
} else if (delta.type === "input_json_delta" && block.type === "tool_use") {
|
|
153
|
-
block.inputJson += delta.partial_json;
|
|
154
|
-
}
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
case "message_delta":
|
|
158
|
-
stopReason = data.delta.stop_reason;
|
|
159
|
-
stopSequence = data.delta.stop_sequence ?? null;
|
|
160
|
-
outputTokens = data.usage.output_tokens;
|
|
161
|
-
log.outputTokens = outputTokens;
|
|
162
|
-
// Cache tokens may also be present in message_delta usage
|
|
163
|
-
if (data.usage.cache_creation_input_tokens !== undefined) {
|
|
164
|
-
log.cacheCreationInputTokens = data.usage.cache_creation_input_tokens;
|
|
165
|
-
}
|
|
166
|
-
if (data.usage.cache_read_input_tokens !== undefined) {
|
|
167
|
-
log.cacheReadInputTokens = data.usage.cache_read_input_tokens;
|
|
168
|
-
}
|
|
169
|
-
break;
|
|
170
|
-
case "error":
|
|
171
|
-
// Store error info on the log for display
|
|
172
|
-
log.error = data.error.message;
|
|
173
|
-
break;
|
|
174
|
-
case "content_block_stop":
|
|
175
|
-
case "message_stop":
|
|
176
|
-
case "ping":
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
} catch {
|
|
180
|
-
// non-JSON SSE line, skip
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (collectChunks === true) {
|
|
185
|
-
log.streamingChunks = {
|
|
186
|
-
chunks,
|
|
187
|
-
truncated: chunkIndex > MAX_CHUNKS,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const orderedContent = [...blocks.entries()]
|
|
192
|
-
.sort(([a], [b]) => a - b)
|
|
193
|
-
.map(([, block]) => finalizeBlock(block));
|
|
194
|
-
|
|
195
|
-
return JSON.stringify({
|
|
196
|
-
id,
|
|
197
|
-
type: "message",
|
|
198
|
-
model: model !== "" ? model : (fallbackModel ?? ""),
|
|
199
|
-
role: "assistant",
|
|
200
|
-
content: orderedContent,
|
|
201
|
-
stop_reason: stopReason,
|
|
202
|
-
stop_sequence: stopSequence,
|
|
203
|
-
usage: { input_tokens: inputTokens, output_tokens: outputTokens },
|
|
204
|
-
});
|
|
205
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { ApiFormat, CapturedLog, TokenUsage } from "../schemas";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Structured result of parsing a raw request body.
|
|
5
|
-
*/
|
|
6
|
-
export type ParsedRequest = {
|
|
7
|
-
model: string | null;
|
|
8
|
-
sessionId: string | null;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* FormatHandler defines the contract for all API format implementations.
|
|
13
|
-
*
|
|
14
|
-
* Each API format (Anthropic, OpenAI) provides its own handler that encapsulates
|
|
15
|
-
* request parsing, response parsing, SSE stream extraction, and token extraction.
|
|
16
|
-
* This replaces the scattered if/else format branching previously in handler.ts.
|
|
17
|
-
*/
|
|
18
|
-
export type FormatHandler = {
|
|
19
|
-
/** The format identifier */
|
|
20
|
-
readonly format: ApiFormat;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Parse a raw request body to extract model name and metadata.
|
|
24
|
-
*/
|
|
25
|
-
parseRequest(rawBody: string, headers?: Headers): ParsedRequest | null;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Extract token usage from a non-streaming response body.
|
|
29
|
-
*/
|
|
30
|
-
extractTokens(responseBody: string): TokenUsage;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Extract structured content from a streaming SSE response.
|
|
34
|
-
*/
|
|
35
|
-
extractStream(
|
|
36
|
-
raw: string,
|
|
37
|
-
log: CapturedLog,
|
|
38
|
-
fallbackModel?: string,
|
|
39
|
-
collectChunks?: boolean,
|
|
40
|
-
): string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Detect if a raw request body uses this format.
|
|
44
|
-
*/
|
|
45
|
-
detectFormat(rawBody: string | null): boolean;
|
|
46
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Import submodules to trigger handler registration
|
|
2
|
-
import "./anthropic/index";
|
|
3
|
-
import "./openai/index";
|
|
4
|
-
|
|
5
|
-
// Import providers to trigger self-registration
|
|
6
|
-
import "./anthropic/anthropicProvider";
|
|
7
|
-
import "./openai/provider";
|
|
8
|
-
import "./openai/zhipuProvider";
|
|
9
|
-
import "./openai/alibabaProvider";
|
|
10
|
-
|
|
11
|
-
export type { FormatHandler, ParsedRequest } from "./handler";
|
|
12
|
-
export { apiFormatForPath, formatRegistry, formatForPath } from "./registry";
|
|
13
|
-
export { registry } from "./providers";
|