@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,221 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { writeFile, rm, statfs } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { getDataDir } from "./dataDir";
|
|
5
|
-
import { getFinalizerRuntimeHealth } from "./logFinalizer";
|
|
6
|
-
import { ensurePrivateDirectorySync, PRIVATE_FILE_MODE } from "./privateDataPath";
|
|
7
|
-
import { isSqliteLogIndexReady } from "./sqliteLogIndex";
|
|
8
|
-
import { recoverCapturedLogStorage } from "./jsonlRecovery";
|
|
9
|
-
import { resolveLogDir } from "./logger";
|
|
10
|
-
import { loadIndex } from "./logIndex";
|
|
11
|
-
import { getSessionRuntimeQueueHealth } from "./sessionRuntime";
|
|
12
|
-
|
|
13
|
-
const DEFAULT_CACHE_MS = 2_000;
|
|
14
|
-
const DEFAULT_MIN_DISK_HEADROOM_BYTES = 256 * 1024 * 1024;
|
|
15
|
-
const DEFAULT_MAX_FINALIZER_QUEUE = 256;
|
|
16
|
-
|
|
17
|
-
export type ReadinessLevel = "ready" | "degraded" | "unavailable";
|
|
18
|
-
export type ReadinessCheckLevel = "ok" | "degraded" | "unavailable";
|
|
19
|
-
|
|
20
|
-
export type SafeReadiness = {
|
|
21
|
-
status: ReadinessLevel;
|
|
22
|
-
checks: {
|
|
23
|
-
storage: ReadinessCheckLevel;
|
|
24
|
-
disk: ReadinessCheckLevel;
|
|
25
|
-
workers: ReadinessCheckLevel;
|
|
26
|
-
index: ReadinessCheckLevel;
|
|
27
|
-
queue: ReadinessCheckLevel;
|
|
28
|
-
shutdown: ReadinessCheckLevel;
|
|
29
|
-
};
|
|
30
|
-
checkedAt: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type ReadinessDependencies = {
|
|
34
|
-
checkStorage: () => Promise<ReadinessCheckLevel>;
|
|
35
|
-
checkDisk: () => Promise<ReadinessCheckLevel>;
|
|
36
|
-
checkWorkers: () => Promise<ReadinessCheckLevel>;
|
|
37
|
-
checkIndex: () => Promise<ReadinessCheckLevel>;
|
|
38
|
-
checkQueue: () => Promise<ReadinessCheckLevel>;
|
|
39
|
-
checkShutdown: () => Promise<ReadinessCheckLevel>;
|
|
40
|
-
now: () => number;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type ReadinessService = {
|
|
44
|
-
get: () => Promise<SafeReadiness>;
|
|
45
|
-
invalidate: () => void;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
let runtimeShuttingDown = false;
|
|
49
|
-
|
|
50
|
-
function configuredPositiveInteger(name: string, fallback: number): number {
|
|
51
|
-
const raw = process.env[name];
|
|
52
|
-
if (raw === undefined || raw === "") return fallback;
|
|
53
|
-
const parsed = Number(raw);
|
|
54
|
-
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function checkStorageWritable(): Promise<ReadinessCheckLevel> {
|
|
58
|
-
const dataDir = getDataDir();
|
|
59
|
-
if (!ensurePrivateDirectorySync(dataDir)) return "unavailable";
|
|
60
|
-
const probePath = join(dataDir, `.readiness-${String(process.pid)}-${randomUUID()}`);
|
|
61
|
-
try {
|
|
62
|
-
await writeFile(probePath, "", { flag: "wx", mode: PRIVATE_FILE_MODE });
|
|
63
|
-
return "ok";
|
|
64
|
-
} catch {
|
|
65
|
-
return "unavailable";
|
|
66
|
-
} finally {
|
|
67
|
-
await rm(probePath, { force: true }).catch(() => undefined);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function checkDiskHeadroom(): Promise<ReadinessCheckLevel> {
|
|
72
|
-
try {
|
|
73
|
-
const stats = await statfs(getDataDir());
|
|
74
|
-
const availableBytes = stats.bavail * stats.bsize;
|
|
75
|
-
const minimumBytes = configuredPositiveInteger(
|
|
76
|
-
"AGENT_INSPECTOR_MIN_DISK_HEADROOM_BYTES",
|
|
77
|
-
DEFAULT_MIN_DISK_HEADROOM_BYTES,
|
|
78
|
-
);
|
|
79
|
-
return availableBytes >= minimumBytes ? "ok" : "unavailable";
|
|
80
|
-
} catch {
|
|
81
|
-
return "degraded";
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function finalizerChecks(): {
|
|
86
|
-
workers: ReadinessCheckLevel;
|
|
87
|
-
queue: ReadinessCheckLevel;
|
|
88
|
-
} {
|
|
89
|
-
const health = getFinalizerRuntimeHealth();
|
|
90
|
-
const sessionQueue = getSessionRuntimeQueueHealth();
|
|
91
|
-
const runtimeArtifactMissing = health.runtime !== "inline" && !health.artifactAvailable;
|
|
92
|
-
const initializedWorkerMissing =
|
|
93
|
-
health.runtime === "worker" &&
|
|
94
|
-
health.activeWorkers !== null &&
|
|
95
|
-
health.activeWorkers < health.configuredWorkers;
|
|
96
|
-
const workers =
|
|
97
|
-
runtimeArtifactMissing || initializedWorkerMissing
|
|
98
|
-
? "unavailable"
|
|
99
|
-
: health.runtime === "inline"
|
|
100
|
-
? "degraded"
|
|
101
|
-
: "ok";
|
|
102
|
-
|
|
103
|
-
const queueLimit = configuredPositiveInteger(
|
|
104
|
-
"AGENT_INSPECTOR_READY_MAX_FINALIZER_QUEUE",
|
|
105
|
-
DEFAULT_MAX_FINALIZER_QUEUE,
|
|
106
|
-
);
|
|
107
|
-
const warningThreshold = Math.max(1, Math.floor(queueLimit * 0.8));
|
|
108
|
-
const queue =
|
|
109
|
-
health.pendingJobs + sessionQueue.queuedTasks >= queueLimit
|
|
110
|
-
? "unavailable"
|
|
111
|
-
: health.pendingJobs + sessionQueue.queuedTasks >= warningThreshold
|
|
112
|
-
? "degraded"
|
|
113
|
-
: "ok";
|
|
114
|
-
return { workers, queue };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function checkWorkers(): Promise<ReadinessCheckLevel> {
|
|
118
|
-
return Promise.resolve(finalizerChecks().workers);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function checkQueue(): Promise<ReadinessCheckLevel> {
|
|
122
|
-
return Promise.resolve(finalizerChecks().queue);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function checkIndex(): Promise<ReadinessCheckLevel> {
|
|
126
|
-
const recovery = await recoverCapturedLogStorage(resolveLogDir());
|
|
127
|
-
if (recovery.level === "unavailable") return "unavailable";
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
await loadIndex();
|
|
131
|
-
} catch {
|
|
132
|
-
return "unavailable";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const sqliteReady = await isSqliteLogIndexReady();
|
|
136
|
-
return recovery.level === "degraded" || !sqliteReady ? "degraded" : "ok";
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function checkShutdown(): Promise<ReadinessCheckLevel> {
|
|
140
|
-
return Promise.resolve(runtimeShuttingDown ? "unavailable" : "ok");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function readinessLevel(checks: SafeReadiness["checks"]): ReadinessLevel {
|
|
144
|
-
const levels = Object.values(checks);
|
|
145
|
-
if (levels.some((level) => level === "unavailable")) return "unavailable";
|
|
146
|
-
return levels.some((level) => level === "degraded") ? "degraded" : "ready";
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function createReadinessService(
|
|
150
|
-
dependencies: ReadinessDependencies,
|
|
151
|
-
cacheMs = DEFAULT_CACHE_MS,
|
|
152
|
-
): ReadinessService {
|
|
153
|
-
let cached: { expiresAt: number; value: SafeReadiness } | null = null;
|
|
154
|
-
let inFlight: Promise<SafeReadiness> | null = null;
|
|
155
|
-
|
|
156
|
-
async function evaluate(): Promise<SafeReadiness> {
|
|
157
|
-
// Establish the directory before checking its filesystem. On a clean install
|
|
158
|
-
// the data directory may not exist until the first write probe creates it.
|
|
159
|
-
const storage = await dependencies.checkStorage();
|
|
160
|
-
const [disk, workers, index, queue, shutdown] = await Promise.all([
|
|
161
|
-
dependencies.checkDisk(),
|
|
162
|
-
dependencies.checkWorkers(),
|
|
163
|
-
dependencies.checkIndex(),
|
|
164
|
-
dependencies.checkQueue(),
|
|
165
|
-
dependencies.checkShutdown(),
|
|
166
|
-
]);
|
|
167
|
-
const checks = { storage, disk, workers, index, queue, shutdown };
|
|
168
|
-
return {
|
|
169
|
-
status: readinessLevel(checks),
|
|
170
|
-
checks,
|
|
171
|
-
checkedAt: new Date(dependencies.now()).toISOString(),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async function get(): Promise<SafeReadiness> {
|
|
176
|
-
const now = dependencies.now();
|
|
177
|
-
if (cached !== null && cached.expiresAt > now) return cached.value;
|
|
178
|
-
if (inFlight !== null) return await inFlight;
|
|
179
|
-
|
|
180
|
-
const evaluation = evaluate();
|
|
181
|
-
inFlight = evaluation;
|
|
182
|
-
try {
|
|
183
|
-
const value = await evaluation;
|
|
184
|
-
cached = { expiresAt: dependencies.now() + Math.max(0, cacheMs), value };
|
|
185
|
-
return value;
|
|
186
|
-
} finally {
|
|
187
|
-
if (inFlight === evaluation) inFlight = null;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function invalidate(): void {
|
|
192
|
-
cached = null;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return { get, invalidate };
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const readinessService = createReadinessService({
|
|
199
|
-
checkStorage: checkStorageWritable,
|
|
200
|
-
checkDisk: checkDiskHeadroom,
|
|
201
|
-
checkWorkers,
|
|
202
|
-
checkIndex,
|
|
203
|
-
checkQueue,
|
|
204
|
-
checkShutdown,
|
|
205
|
-
now: Date.now,
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
export async function getRuntimeReadiness(): Promise<SafeReadiness> {
|
|
209
|
-
return await readinessService.get();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** Shutdown coordination will call this before stopping admission. */
|
|
213
|
-
export function setRuntimeShuttingDown(shuttingDown: boolean): void {
|
|
214
|
-
runtimeShuttingDown = shuttingDown;
|
|
215
|
-
readinessService.invalidate();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function _resetRuntimeHealthForTests(): void {
|
|
219
|
-
runtimeShuttingDown = false;
|
|
220
|
-
readinessService.invalidate();
|
|
221
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_RUNTIME_BUDGET_POLICY } from "../lib/resourceLimits";
|
|
2
|
-
import { getFinalizerRuntimeHealth } from "./logFinalizer";
|
|
3
|
-
import { getRuntimeAdmissionState } from "./runtimeAdmission";
|
|
4
|
-
import { getRuntimeReadiness } from "./runtimeHealth";
|
|
5
|
-
import { getSessionRuntimeQueueHealth } from "./sessionRuntime";
|
|
6
|
-
import { listSqliteLogCursorEntries } from "./sqliteLogIndex";
|
|
7
|
-
import { getStorageLifecycleInventory, getLastStorageLifecycleGcResult } from "./storageLifecycle";
|
|
8
|
-
|
|
9
|
-
export const PERFORMANCE_METRICS_SCHEMA = "agent-inspector.performance-metrics/v1";
|
|
10
|
-
export const OPERATIONAL_METRICS_SCHEMA = "agent-inspector.operational-metrics/v1";
|
|
11
|
-
|
|
12
|
-
export type SseRuntimeMetrics = {
|
|
13
|
-
activeClients: number;
|
|
14
|
-
capacity: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type SafeOperationalMetrics = {
|
|
18
|
-
schema: typeof PERFORMANCE_METRICS_SCHEMA;
|
|
19
|
-
activeUpstream: number;
|
|
20
|
-
queueDepth: number;
|
|
21
|
-
queueBytes: number;
|
|
22
|
-
incompleteCaptures: number;
|
|
23
|
-
finalizerLagMs: number;
|
|
24
|
-
persistenceLagMs: number;
|
|
25
|
-
activeLeases: number;
|
|
26
|
-
runtime: {
|
|
27
|
-
schema: typeof OPERATIONAL_METRICS_SCHEMA;
|
|
28
|
-
collectedAt: string;
|
|
29
|
-
readiness: Awaited<ReturnType<typeof getRuntimeReadiness>>;
|
|
30
|
-
requests: {
|
|
31
|
-
activeProxyRequests: number;
|
|
32
|
-
proxyCapacity: number;
|
|
33
|
-
acceptingRequests: boolean;
|
|
34
|
-
};
|
|
35
|
-
limits: typeof DEFAULT_RUNTIME_BUDGET_POLICY;
|
|
36
|
-
queues: {
|
|
37
|
-
finalizerPendingJobs: number;
|
|
38
|
-
sessionQueuedTasks: number;
|
|
39
|
-
sessionActiveQueues: number;
|
|
40
|
-
sessionQueueLimit: number;
|
|
41
|
-
};
|
|
42
|
-
workers: ReturnType<typeof getFinalizerRuntimeHealth>;
|
|
43
|
-
storage: {
|
|
44
|
-
totalFiles: number;
|
|
45
|
-
totalBytes: number;
|
|
46
|
-
reclaimableBytes: number;
|
|
47
|
-
lastGc: {
|
|
48
|
-
checkedAt: string;
|
|
49
|
-
filesDeleted: number;
|
|
50
|
-
bytesDeleted: number;
|
|
51
|
-
errors: number;
|
|
52
|
-
} | null;
|
|
53
|
-
};
|
|
54
|
-
sse: SseRuntimeMetrics;
|
|
55
|
-
truncation: {
|
|
56
|
-
captureIncompleteLogs: number;
|
|
57
|
-
droppedChunks: number;
|
|
58
|
-
droppedBytes: number;
|
|
59
|
-
source: "sqlite" | "unavailable";
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
async function getTruncationMetrics(): Promise<SafeOperationalMetrics["runtime"]["truncation"]> {
|
|
65
|
-
const entries = await listSqliteLogCursorEntries({});
|
|
66
|
-
if (entries === null) {
|
|
67
|
-
return {
|
|
68
|
-
captureIncompleteLogs: 0,
|
|
69
|
-
droppedChunks: 0,
|
|
70
|
-
droppedBytes: 0,
|
|
71
|
-
source: "unavailable",
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
captureIncompleteLogs: entries.filter((entry) => entry.summary?.captureIncomplete === true)
|
|
77
|
-
.length,
|
|
78
|
-
droppedChunks: entries.reduce((sum, entry) => sum + (entry.summary?.droppedChunks ?? 0), 0),
|
|
79
|
-
droppedBytes: entries.reduce((sum, entry) => sum + (entry.summary?.droppedBytes ?? 0), 0),
|
|
80
|
-
source: "sqlite",
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function getSafeOperationalMetrics(
|
|
85
|
-
sse: SseRuntimeMetrics,
|
|
86
|
-
): Promise<SafeOperationalMetrics> {
|
|
87
|
-
const [readiness, truncation] = await Promise.all([
|
|
88
|
-
getRuntimeReadiness(),
|
|
89
|
-
getTruncationMetrics(),
|
|
90
|
-
]);
|
|
91
|
-
const admission = getRuntimeAdmissionState();
|
|
92
|
-
const workers = getFinalizerRuntimeHealth();
|
|
93
|
-
const sessionQueue = getSessionRuntimeQueueHealth();
|
|
94
|
-
const storageInventory = getStorageLifecycleInventory();
|
|
95
|
-
const lastGc = getLastStorageLifecycleGcResult();
|
|
96
|
-
const reclaimableBytes = storageInventory.artifacts
|
|
97
|
-
.filter(
|
|
98
|
-
(artifact) =>
|
|
99
|
-
artifact.cleanupBehavior === "retention-gc" ||
|
|
100
|
-
artifact.cleanupBehavior === "orphan-reclaim",
|
|
101
|
-
)
|
|
102
|
-
.reduce((sum, artifact) => sum + artifact.bytes, 0);
|
|
103
|
-
const queueDepth = workers.pendingJobs + sessionQueue.queuedTasks;
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
schema: PERFORMANCE_METRICS_SCHEMA,
|
|
107
|
-
activeUpstream: admission.activeRequests,
|
|
108
|
-
queueDepth,
|
|
109
|
-
queueBytes: 0,
|
|
110
|
-
incompleteCaptures: truncation.captureIncompleteLogs,
|
|
111
|
-
finalizerLagMs: 0,
|
|
112
|
-
persistenceLagMs: 0,
|
|
113
|
-
activeLeases: sse.activeClients,
|
|
114
|
-
runtime: {
|
|
115
|
-
schema: OPERATIONAL_METRICS_SCHEMA,
|
|
116
|
-
collectedAt: new Date().toISOString(),
|
|
117
|
-
readiness,
|
|
118
|
-
requests: {
|
|
119
|
-
activeProxyRequests: admission.activeRequests,
|
|
120
|
-
proxyCapacity: admission.capacity,
|
|
121
|
-
acceptingRequests: admission.acceptingRequests,
|
|
122
|
-
},
|
|
123
|
-
limits: DEFAULT_RUNTIME_BUDGET_POLICY,
|
|
124
|
-
queues: {
|
|
125
|
-
finalizerPendingJobs: workers.pendingJobs,
|
|
126
|
-
sessionQueuedTasks: sessionQueue.queuedTasks,
|
|
127
|
-
sessionActiveQueues: sessionQueue.activeQueues,
|
|
128
|
-
sessionQueueLimit: sessionQueue.queueLimit,
|
|
129
|
-
},
|
|
130
|
-
workers,
|
|
131
|
-
storage: {
|
|
132
|
-
totalFiles: storageInventory.totalFiles,
|
|
133
|
-
totalBytes: storageInventory.totalBytes,
|
|
134
|
-
reclaimableBytes,
|
|
135
|
-
lastGc:
|
|
136
|
-
lastGc === null
|
|
137
|
-
? null
|
|
138
|
-
: {
|
|
139
|
-
checkedAt: lastGc.checkedAt,
|
|
140
|
-
filesDeleted: lastGc.filesDeleted,
|
|
141
|
-
bytesDeleted: lastGc.bytesDeleted,
|
|
142
|
-
errors: lastGc.errors.length,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
sse,
|
|
146
|
-
truncation,
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { createHash, timingSafeEqual } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
parseManagedInstanceShutdownMessage,
|
|
4
|
-
readManagedInstanceLaunch,
|
|
5
|
-
} from "../lib/managedInstance";
|
|
6
|
-
import { closeLogFinalizerWorkers, forceCloseLogFinalizerWorkers } from "./logFinalizer";
|
|
7
|
-
import { flushIndex } from "./logIndex";
|
|
8
|
-
import { flushApplicationLog, flushLogBuffer } from "./logger";
|
|
9
|
-
import { flushAllRawStreamCaptures } from "./rawStreamCapture";
|
|
10
|
-
import { setRuntimeShuttingDown } from "./runtimeHealth";
|
|
11
|
-
import { stopRuntimeAdmission, waitForRuntimeTrafficDrain } from "./runtimeAdmission";
|
|
12
|
-
import {
|
|
13
|
-
createShutdownCoordinator,
|
|
14
|
-
createShutdownSignalHandler,
|
|
15
|
-
type ShutdownResult,
|
|
16
|
-
} from "./shutdownCoordinator";
|
|
17
|
-
import { destroyAllSessionProcesses } from "./sessionProcess";
|
|
18
|
-
import {
|
|
19
|
-
beginEcosystemTaskShutdown,
|
|
20
|
-
forceCloseEcosystemTasks,
|
|
21
|
-
waitForEcosystemTasksToClose,
|
|
22
|
-
} from "./ecosystemTasks";
|
|
23
|
-
import { flushSessionTasks } from "./sessionRuntime";
|
|
24
|
-
import { closeSqliteLogIndex } from "./sqliteLogIndex";
|
|
25
|
-
import { flushSessionArchiveWrites } from "./store";
|
|
26
|
-
import { flushToolSchemaWarningAnalysis } from "./logFinalizer";
|
|
27
|
-
|
|
28
|
-
const DEFAULT_SHUTDOWN_DEADLINE_MS = 15_000;
|
|
29
|
-
|
|
30
|
-
function shutdownDeadlineMs(): number {
|
|
31
|
-
const raw = process.env["AGENT_INSPECTOR_SHUTDOWN_TIMEOUT_MS"];
|
|
32
|
-
if (raw === undefined || raw === "") return DEFAULT_SHUTDOWN_DEADLINE_MS;
|
|
33
|
-
const parsed = Number(raw);
|
|
34
|
-
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= 300_000
|
|
35
|
-
? parsed
|
|
36
|
-
: DEFAULT_SHUTDOWN_DEADLINE_MS;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function drainFinalizers(): Promise<void> {
|
|
40
|
-
await flushAllRawStreamCaptures();
|
|
41
|
-
await flushSessionTasks();
|
|
42
|
-
await flushToolSchemaWarningAnalysis();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function flushPersistence(): Promise<void> {
|
|
46
|
-
await flushLogBuffer();
|
|
47
|
-
await flushSessionArchiveWrites();
|
|
48
|
-
await flushIndex();
|
|
49
|
-
await flushApplicationLog();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function closeResources(): Promise<void> {
|
|
53
|
-
await waitForEcosystemTasksToClose();
|
|
54
|
-
await closeLogFinalizerWorkers();
|
|
55
|
-
destroyAllSessionProcesses();
|
|
56
|
-
closeSqliteLogIndex();
|
|
57
|
-
await flushApplicationLog();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function forceCloseResources(): void {
|
|
61
|
-
forceCloseEcosystemTasks();
|
|
62
|
-
forceCloseLogFinalizerWorkers();
|
|
63
|
-
destroyAllSessionProcesses();
|
|
64
|
-
closeSqliteLogIndex();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const runtimeShutdownCoordinator = createShutdownCoordinator(
|
|
68
|
-
{
|
|
69
|
-
markShuttingDown: () => {
|
|
70
|
-
setRuntimeShuttingDown(true);
|
|
71
|
-
beginEcosystemTaskShutdown();
|
|
72
|
-
},
|
|
73
|
-
stopAdmission: stopRuntimeAdmission,
|
|
74
|
-
drainTraffic: waitForRuntimeTrafficDrain,
|
|
75
|
-
drainFinalizers,
|
|
76
|
-
flushPersistence,
|
|
77
|
-
closeResources,
|
|
78
|
-
forceClose: forceCloseResources,
|
|
79
|
-
},
|
|
80
|
-
shutdownDeadlineMs(),
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
let signalHandlersInstalled = false;
|
|
84
|
-
let managedInstanceHandlersInstalled = false;
|
|
85
|
-
|
|
86
|
-
export type ManagedRuntimeShutdownController = {
|
|
87
|
-
handleDisconnect: () => void;
|
|
88
|
-
handleMessage: (message: unknown) => void;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
type ManagedRuntimeShutdownControllerOptions = {
|
|
92
|
-
controlToken: string;
|
|
93
|
-
shutdown: () => Promise<ShutdownResult>;
|
|
94
|
-
exit: (code: number) => void;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
function managedControlTokensMatch(received: string, expected: string): boolean {
|
|
98
|
-
if (received.length === 0 || expected.length === 0) return false;
|
|
99
|
-
const receivedDigest = createHash("sha256").update(received).digest();
|
|
100
|
-
const expectedDigest = createHash("sha256").update(expected).digest();
|
|
101
|
-
return timingSafeEqual(receivedDigest, expectedDigest);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function createManagedRuntimeShutdownController(
|
|
105
|
-
options: ManagedRuntimeShutdownControllerOptions,
|
|
106
|
-
): ManagedRuntimeShutdownController {
|
|
107
|
-
let shutdownRequested = false;
|
|
108
|
-
const requestShutdown = (): void => {
|
|
109
|
-
if (shutdownRequested) return;
|
|
110
|
-
shutdownRequested = true;
|
|
111
|
-
void options.shutdown().then(
|
|
112
|
-
(result) => options.exit(result.forced ? 1 : 0),
|
|
113
|
-
() => options.exit(1),
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
return {
|
|
117
|
-
handleDisconnect: requestShutdown,
|
|
118
|
-
handleMessage: (message) => {
|
|
119
|
-
const parsed = parseManagedInstanceShutdownMessage(message);
|
|
120
|
-
if (
|
|
121
|
-
parsed === null ||
|
|
122
|
-
!managedControlTokensMatch(parsed.controlToken, options.controlToken)
|
|
123
|
-
) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
requestShutdown();
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Install lifecycle cleanup for the private supervisor/runtime IPC channel. */
|
|
132
|
-
export function installRuntimeManagedInstanceShutdownHandlers(): void {
|
|
133
|
-
if (managedInstanceHandlersInstalled) return;
|
|
134
|
-
const launchResult = readManagedInstanceLaunch(process.env);
|
|
135
|
-
if (launchResult.kind !== "managed") return;
|
|
136
|
-
managedInstanceHandlersInstalled = true;
|
|
137
|
-
const controller = createManagedRuntimeShutdownController({
|
|
138
|
-
controlToken: launchResult.launch.controlToken,
|
|
139
|
-
shutdown: async () => await runtimeShutdownCoordinator.shutdown("manual"),
|
|
140
|
-
exit: (code) => process.exit(code),
|
|
141
|
-
});
|
|
142
|
-
process.on("message", controller.handleMessage);
|
|
143
|
-
process.once("disconnect", controller.handleDisconnect);
|
|
144
|
-
if (process.connected === false) process.nextTick(controller.handleDisconnect);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** Install once in the server runtime; the CLI supervisor owns its own public-ingress signals. */
|
|
148
|
-
export function installRuntimeShutdownSignalHandlers(): void {
|
|
149
|
-
installRuntimeManagedInstanceShutdownHandlers();
|
|
150
|
-
if (signalHandlersInstalled) return;
|
|
151
|
-
signalHandlersInstalled = true;
|
|
152
|
-
const handleSignal = createShutdownSignalHandler(runtimeShutdownCoordinator, (result) => {
|
|
153
|
-
process.exit(result.forced ? 1 : 0);
|
|
154
|
-
});
|
|
155
|
-
process.on("SIGINT", () => handleSignal("SIGINT"));
|
|
156
|
-
process.on("SIGTERM", () => handleSignal("SIGTERM"));
|
|
157
|
-
}
|
package/src/proxy/schemas.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
CaptureIncompleteReasonSchema,
|
|
5
|
-
CapturedLogSchema,
|
|
6
|
-
JsonValueSchema,
|
|
7
|
-
StreamingChunkSchema,
|
|
8
|
-
StopReasonSchema,
|
|
9
|
-
ToolTraceEventSchema,
|
|
10
|
-
} from "../contracts";
|
|
11
|
-
export type {
|
|
12
|
-
CapturedLog,
|
|
13
|
-
ApiFormat,
|
|
14
|
-
CaptureIncompleteReason,
|
|
15
|
-
JsonValue,
|
|
16
|
-
StreamingChunk,
|
|
17
|
-
StopReason,
|
|
18
|
-
ToolTraceEvent,
|
|
19
|
-
TokenUsage,
|
|
20
|
-
} from "../contracts";
|
|
21
|
-
|
|
22
|
-
// ============================================================
|
|
23
|
-
// Import types and schemas from shared contracts
|
|
24
|
-
// ============================================================
|
|
25
|
-
|
|
26
|
-
// Re-export types and schemas from shared contracts for backward compatibility
|
|
27
|
-
export {
|
|
28
|
-
AnthropicRequestSchema,
|
|
29
|
-
AnthropicResponseSchema,
|
|
30
|
-
SseEventSchema,
|
|
31
|
-
} from "../contracts/anthropic";
|
|
32
|
-
export type { AnthropicResponse, ResponseContentBlockType } from "../contracts/anthropic";
|
|
33
|
-
|
|
34
|
-
export {
|
|
35
|
-
OpenAIRequestSchema,
|
|
36
|
-
OpenAIResponsesRequestSchema,
|
|
37
|
-
OpenAIResponsesResponseSchema,
|
|
38
|
-
OpenAIResponsesSSEventSchema,
|
|
39
|
-
OpenAIResponsesUsageSchema,
|
|
40
|
-
OpenAIResponseSchema,
|
|
41
|
-
OpenAISSERawChunkSchema,
|
|
42
|
-
type OpenAIResponse,
|
|
43
|
-
type OpenAIResponsesResponse,
|
|
44
|
-
type OpenAIToolCall,
|
|
45
|
-
parseOpenAIResponsesResponse,
|
|
46
|
-
parseOpenAIResponse,
|
|
47
|
-
} from "../contracts/openai";
|
|
48
|
-
|
|
49
|
-
// Schema for model name in request body (used for routing)
|
|
50
|
-
const RequestModelSchema = z.object({
|
|
51
|
-
model: z.string(),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
export function extractModelFromBody(body: string): string | null {
|
|
55
|
-
try {
|
|
56
|
-
const json: unknown = JSON.parse(body);
|
|
57
|
-
const parsed = RequestModelSchema.safeParse(json);
|
|
58
|
-
if (parsed.success) {
|
|
59
|
-
return parsed.data.model;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
} catch {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Loose request schema used for routing + log metadata. Tolerant of missing
|
|
69
|
-
* fields so it can extract what it can from a partially-valid or unparseable
|
|
70
|
-
* body without throwing.
|
|
71
|
-
*/
|
|
72
|
-
export const LooseRequestSchema = z.object({
|
|
73
|
-
model: z.string().optional(),
|
|
74
|
-
metadata: z.object({ user_id: z.string().optional() }).passthrough().optional(),
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export type RequestMetadata = {
|
|
78
|
-
model: string | null;
|
|
79
|
-
sessionId: string | null;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
function extractSessionIdFromHeaders(headers: Headers): string | null {
|
|
83
|
-
return headers.get("x-agent-inspector-session-id") ?? headers.get("x-session-affinity");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Parse a request body exactly once and pull out everything the handler needs
|
|
88
|
-
* for routing + log creation: the model (used for provider selection) and the
|
|
89
|
-
* session id (from `metadata.user_id` or the `x-session-affinity` header).
|
|
90
|
-
*
|
|
91
|
-
* Returning `null` for either field is a valid outcome; callers must handle
|
|
92
|
-
* "unknown" gracefully. Callers that already have the body string should use
|
|
93
|
-
* this instead of re-parsing with `extractModelFromBody` and a second pass
|
|
94
|
-
* for the session id.
|
|
95
|
-
*/
|
|
96
|
-
export function extractRequestMetadata(body: string | null, headers: Headers): RequestMetadata {
|
|
97
|
-
const headerSessionId = extractSessionIdFromHeaders(headers);
|
|
98
|
-
if (body === null) return { model: null, sessionId: headerSessionId };
|
|
99
|
-
try {
|
|
100
|
-
const json: unknown = JSON.parse(body);
|
|
101
|
-
const loose = LooseRequestSchema.safeParse(json);
|
|
102
|
-
if (loose.success) {
|
|
103
|
-
return {
|
|
104
|
-
model: loose.data.model ?? null,
|
|
105
|
-
sessionId: loose.data.metadata?.user_id ?? headerSessionId,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
} catch {
|
|
109
|
-
// body not valid JSON
|
|
110
|
-
}
|
|
111
|
-
return { model: null, sessionId: headerSessionId };
|
|
112
|
-
}
|