@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
package/src/proxy/sessionInfo.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import type { SessionInfo, SessionLogSummary, SessionTokenUsage } from "../lib/sessionInfoContract";
|
|
2
|
-
import { withBasePath } from "../lib/basePath";
|
|
3
|
-
import { getPublicBasePath } from "../lib/publicBasePathContext";
|
|
4
|
-
import { getSessionPath } from "../lib/sessionUrl";
|
|
5
|
-
import type { CapturedLog } from "./schemas";
|
|
6
|
-
import type { SessionSnapshot } from "./sessionSupervisor";
|
|
7
|
-
|
|
8
|
-
export const SESSION_INFO_DEFAULT_LATEST_LOG_LIMIT = 10;
|
|
9
|
-
export const SESSION_INFO_MAX_LATEST_LOG_LIMIT = 50;
|
|
10
|
-
|
|
11
|
-
type SessionStatus = SessionInfo["status"];
|
|
12
|
-
|
|
13
|
-
type BuildSessionInfoInput = {
|
|
14
|
-
sessionId: string;
|
|
15
|
-
baseUrl: string;
|
|
16
|
-
snapshot: SessionSnapshot | null;
|
|
17
|
-
summaries: readonly SessionLogSummary[];
|
|
18
|
-
logCoverage: SessionInfo["logCoverage"];
|
|
19
|
-
latestLogLimit?: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export function clampSessionInfoLogLimit(input: number | undefined): number {
|
|
23
|
-
if (input === undefined) return SESSION_INFO_DEFAULT_LATEST_LOG_LIMIT;
|
|
24
|
-
if (!Number.isFinite(input) || input < 1) return 1;
|
|
25
|
-
return Math.min(Math.floor(input), SESSION_INFO_MAX_LATEST_LOG_LIMIT);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function normalizeString(value: string | null | undefined): string | null {
|
|
29
|
-
if (value === null || value === undefined || value.length === 0) return null;
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function truncateError(value: string | null | undefined): string | null {
|
|
34
|
-
const normalized = normalizeString(value);
|
|
35
|
-
if (normalized === null) return null;
|
|
36
|
-
if (normalized.length <= 500) return normalized;
|
|
37
|
-
return `${normalized.slice(0, 500)}...`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function hasLogError(log: CapturedLog): boolean {
|
|
41
|
-
const error = normalizeString(log.error);
|
|
42
|
-
if (error !== null) return true;
|
|
43
|
-
return log.responseStatus !== null && log.responseStatus >= 400;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function buildSessionLogSummary(log: CapturedLog): SessionLogSummary {
|
|
47
|
-
return {
|
|
48
|
-
id: log.id,
|
|
49
|
-
timestamp: log.timestamp,
|
|
50
|
-
provider: normalizeString(log.providerName),
|
|
51
|
-
model: normalizeString(log.model),
|
|
52
|
-
apiFormat: log.apiFormat,
|
|
53
|
-
method: log.method,
|
|
54
|
-
path: log.path,
|
|
55
|
-
status: log.responseStatus,
|
|
56
|
-
isStreaming: log.streaming,
|
|
57
|
-
hasError: hasLogError(log),
|
|
58
|
-
error: truncateError(log.error),
|
|
59
|
-
latencyMs: log.elapsedMs,
|
|
60
|
-
firstChunkMs: log.firstChunkMs ?? null,
|
|
61
|
-
totalStreamMs: log.totalStreamMs ?? null,
|
|
62
|
-
tokensPerSecond: log.tokensPerSecond ?? null,
|
|
63
|
-
tokens: {
|
|
64
|
-
input: log.inputTokens,
|
|
65
|
-
output: log.outputTokens,
|
|
66
|
-
cacheCreate: log.cacheCreationInputTokens,
|
|
67
|
-
cacheRead: log.cacheReadInputTokens,
|
|
68
|
-
},
|
|
69
|
-
sessionId: normalizeString(log.sessionId),
|
|
70
|
-
userAgent: normalizeString(log.userAgent),
|
|
71
|
-
clientPid: log.clientPid ?? null,
|
|
72
|
-
clientProjectFolder: normalizeString(log.clientProjectFolder),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function nonNegativeInteger(value: number | null): number {
|
|
77
|
-
if (value === null || !Number.isFinite(value) || value < 0) return 0;
|
|
78
|
-
return Math.floor(value);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function addTokenUsage(total: SessionTokenUsage, summary: SessionLogSummary): SessionTokenUsage {
|
|
82
|
-
const input = nonNegativeInteger(summary.tokens.input);
|
|
83
|
-
const output = nonNegativeInteger(summary.tokens.output);
|
|
84
|
-
const cacheCreate = nonNegativeInteger(summary.tokens.cacheCreate);
|
|
85
|
-
const cacheRead = nonNegativeInteger(summary.tokens.cacheRead);
|
|
86
|
-
return {
|
|
87
|
-
input: total.input + input,
|
|
88
|
-
output: total.output + output,
|
|
89
|
-
cacheCreate: total.cacheCreate + cacheCreate,
|
|
90
|
-
cacheRead: total.cacheRead + cacheRead,
|
|
91
|
-
total: total.total + input + output + cacheCreate + cacheRead,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function buildRelativePath(pathname: string, params: URLSearchParams): string {
|
|
96
|
-
const query = params.toString();
|
|
97
|
-
return query.length > 0 ? `${pathname}?${query}` : pathname;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function buildAbsoluteUrl(baseUrl: string, path: string): string {
|
|
101
|
-
try {
|
|
102
|
-
return new URL(path, baseUrl).toString();
|
|
103
|
-
} catch {
|
|
104
|
-
return path;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function buildApiPath(sessionId: string): string {
|
|
109
|
-
return buildRelativePath(
|
|
110
|
-
withBasePath("/api/sessions", getPublicBasePath()),
|
|
111
|
-
new URLSearchParams({ sessionId }),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function buildCompactLogsPath(sessionId: string): string {
|
|
116
|
-
return buildRelativePath(
|
|
117
|
-
withBasePath("/api/logs", getPublicBasePath()),
|
|
118
|
-
new URLSearchParams({ compact: "1", sessionId }),
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function collectSortedValues(values: readonly (string | null)[]): string[] {
|
|
123
|
-
const set = new Set<string>();
|
|
124
|
-
for (const value of values) {
|
|
125
|
-
if (value !== null && value.length > 0) {
|
|
126
|
-
set.add(value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return [...set].sort();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function firstSummaryUserAgent(summaries: readonly SessionLogSummary[]): string | null {
|
|
133
|
-
for (const summary of summaries) {
|
|
134
|
-
const value = normalizeString(summary.userAgent);
|
|
135
|
-
if (value !== null) return value;
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function firstSummaryClientPid(summaries: readonly SessionLogSummary[]): number | null {
|
|
141
|
-
for (const summary of summaries) {
|
|
142
|
-
const value = summary.clientPid;
|
|
143
|
-
if (value !== null && value !== undefined) return value;
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function firstSummaryProjectFolder(summaries: readonly SessionLogSummary[]): string | null {
|
|
149
|
-
for (const summary of summaries) {
|
|
150
|
-
const value = normalizeString(summary.clientProjectFolder);
|
|
151
|
-
if (value !== null) return value;
|
|
152
|
-
}
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function countCompletedLogs(summaries: readonly SessionLogSummary[]): number {
|
|
157
|
-
let count = 0;
|
|
158
|
-
for (const summary of summaries) {
|
|
159
|
-
if (summary.status !== null || summary.latencyMs !== null) {
|
|
160
|
-
count += 1;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return count;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function countErrorLogs(summaries: readonly SessionLogSummary[]): number {
|
|
167
|
-
let count = 0;
|
|
168
|
-
for (const summary of summaries) {
|
|
169
|
-
if (summary.hasError) {
|
|
170
|
-
count += 1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return count;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function deriveSessionStatus(input: {
|
|
177
|
-
activeRequests: number;
|
|
178
|
-
runningTasks: number;
|
|
179
|
-
failedRequests: number;
|
|
180
|
-
errorCount: number;
|
|
181
|
-
lastTaskError: string | null;
|
|
182
|
-
completedRequests: number;
|
|
183
|
-
logCount: number;
|
|
184
|
-
}): SessionStatus {
|
|
185
|
-
if (input.activeRequests > 0 || input.runningTasks > 0) return "active";
|
|
186
|
-
if (input.failedRequests > 0 || input.errorCount > 0 || input.lastTaskError !== null) {
|
|
187
|
-
return "failed";
|
|
188
|
-
}
|
|
189
|
-
if (input.completedRequests > 0 || input.logCount > 0) return "completed";
|
|
190
|
-
return "empty";
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function buildSessionInfo(input: BuildSessionInfoInput): SessionInfo {
|
|
194
|
-
const latestLogLimit = clampSessionInfoLogLimit(input.latestLogLimit);
|
|
195
|
-
const summaries = [...input.summaries].sort((left, right) => right.id - left.id);
|
|
196
|
-
const latestLog = summaries[0] ?? null;
|
|
197
|
-
const oldestLog = summaries.length > 0 ? summaries[summaries.length - 1] : null;
|
|
198
|
-
const logCount =
|
|
199
|
-
input.logCoverage === "history"
|
|
200
|
-
? summaries.length
|
|
201
|
-
: Math.max(input.snapshot?.requestCount ?? 0, summaries.length);
|
|
202
|
-
const errorCount = Math.max(countErrorLogs(summaries), input.snapshot?.failedRequests ?? 0);
|
|
203
|
-
const completedLogCount = countCompletedLogs(summaries);
|
|
204
|
-
const tokenUsage = summaries.reduce<SessionTokenUsage>(
|
|
205
|
-
(total, summary) => addTokenUsage(total, summary),
|
|
206
|
-
{ input: 0, output: 0, cacheCreate: 0, cacheRead: 0, total: 0 },
|
|
207
|
-
);
|
|
208
|
-
const requestCount = Math.max(input.snapshot?.requestCount ?? 0, logCount);
|
|
209
|
-
const activeRequests = input.snapshot?.activeRequests ?? 0;
|
|
210
|
-
const completedRequests = Math.max(input.snapshot?.completedRequests ?? 0, completedLogCount);
|
|
211
|
-
const failedRequests = Math.max(input.snapshot?.failedRequests ?? 0, errorCount);
|
|
212
|
-
const queuedTasks = input.snapshot?.queuedTasks ?? 0;
|
|
213
|
-
const runningTasks = input.snapshot?.runningTasks ?? 0;
|
|
214
|
-
const lastTaskError = normalizeString(input.snapshot?.lastTaskError);
|
|
215
|
-
const inspectorPath = getSessionPath(input.sessionId, getPublicBasePath());
|
|
216
|
-
const apiPath = buildApiPath(input.sessionId);
|
|
217
|
-
const compactLogsPath = buildCompactLogsPath(input.sessionId);
|
|
218
|
-
const latestLogs = summaries.slice(0, latestLogLimit).map((summary, index) => ({
|
|
219
|
-
...summary,
|
|
220
|
-
sessionLogNumber: Math.max(1, requestCount - index),
|
|
221
|
-
}));
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
id: input.sessionId,
|
|
225
|
-
status: deriveSessionStatus({
|
|
226
|
-
activeRequests,
|
|
227
|
-
runningTasks,
|
|
228
|
-
failedRequests,
|
|
229
|
-
errorCount,
|
|
230
|
-
lastTaskError,
|
|
231
|
-
completedRequests,
|
|
232
|
-
logCount,
|
|
233
|
-
}),
|
|
234
|
-
logCoverage: input.logCoverage,
|
|
235
|
-
source: input.snapshot?.source ?? null,
|
|
236
|
-
runtimeMode: input.snapshot?.runtimeMode ?? null,
|
|
237
|
-
createdAt: input.snapshot?.createdAt ?? oldestLog?.timestamp ?? null,
|
|
238
|
-
updatedAt: input.snapshot?.updatedAt ?? latestLog?.timestamp ?? null,
|
|
239
|
-
requestCount,
|
|
240
|
-
activeRequests,
|
|
241
|
-
completedRequests,
|
|
242
|
-
failedRequests,
|
|
243
|
-
queuedTasks,
|
|
244
|
-
runningTasks,
|
|
245
|
-
lastTaskError,
|
|
246
|
-
logCount,
|
|
247
|
-
errorCount,
|
|
248
|
-
models: collectSortedValues(summaries.map((summary) => summary.model)),
|
|
249
|
-
providers: collectSortedValues(summaries.map((summary) => summary.provider)),
|
|
250
|
-
tokenUsage,
|
|
251
|
-
lastLogId: input.snapshot?.lastLogId ?? latestLog?.id ?? null,
|
|
252
|
-
lastModel: normalizeString(input.snapshot?.lastModel) ?? latestLog?.model ?? null,
|
|
253
|
-
clientUserAgent: firstSummaryUserAgent(summaries),
|
|
254
|
-
clientPid: input.snapshot?.clientPid ?? firstSummaryClientPid(summaries),
|
|
255
|
-
clientProjectFolder:
|
|
256
|
-
normalizeString(input.snapshot?.clientProjectFolder) ?? firstSummaryProjectFolder(summaries),
|
|
257
|
-
inspectorPath,
|
|
258
|
-
inspectorUrl: buildAbsoluteUrl(input.baseUrl, inspectorPath),
|
|
259
|
-
apiPath,
|
|
260
|
-
apiUrl: buildAbsoluteUrl(input.baseUrl, apiPath),
|
|
261
|
-
compactLogsPath,
|
|
262
|
-
compactLogsUrl: buildAbsoluteUrl(input.baseUrl, compactLogsPath),
|
|
263
|
-
latestLogLimit,
|
|
264
|
-
latestLogs,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { spawn, type ChildProcess } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { logger } from "./logger";
|
|
6
|
-
import type { FinalizeLogJob, FinalizeLogResult } from "./logFinalizer";
|
|
7
|
-
import { isPlainRecord, safeGetOwnProperty } from "../lib/objectUtils";
|
|
8
|
-
|
|
9
|
-
const IDLE_TIMEOUT_MS = Number(process.env["SESSION_PROCESS_IDLE_MS"]) || 5 * 60 * 1000; // 5 min default
|
|
10
|
-
const MAX_RESTARTS = 3;
|
|
11
|
-
|
|
12
|
-
const _processes = new Map<string, SessionProcess>();
|
|
13
|
-
|
|
14
|
-
type PendingJob = {
|
|
15
|
-
resolve: (result: FinalizeLogResult) => void;
|
|
16
|
-
reject: (err: Error) => void;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function errorMessage(err: unknown): string {
|
|
20
|
-
return err instanceof Error ? err.message : String(err);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function resolveSessionWorkerPath(): string {
|
|
24
|
-
const workerDir = process.env["AGENT_INSPECTOR_WORKER_DIR"];
|
|
25
|
-
if (workerDir !== undefined && workerDir.trim().length > 0) {
|
|
26
|
-
const builtWorkerPath = join(workerDir, "sessionWorkerEntry.js");
|
|
27
|
-
if (existsSync(builtWorkerPath)) return builtWorkerPath;
|
|
28
|
-
}
|
|
29
|
-
return fileURLToPath(new URL("./sessionWorkerEntry.ts", import.meta.url));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function isSessionProcessAvailable(): boolean {
|
|
33
|
-
return existsSync(resolveSessionWorkerPath());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class SessionProcess {
|
|
37
|
-
private child: ChildProcess | null = null;
|
|
38
|
-
private pending = new Map<string, PendingJob>();
|
|
39
|
-
private nextId = 0;
|
|
40
|
-
private idleTimer: ReturnType<typeof setTimeout> | null = null;
|
|
41
|
-
private restartCount = 0;
|
|
42
|
-
private destroyed = false;
|
|
43
|
-
|
|
44
|
-
constructor(private sessionId: string) {}
|
|
45
|
-
|
|
46
|
-
/** Number of outstanding jobs sent to this process. */
|
|
47
|
-
get pendingCount(): number {
|
|
48
|
-
return this.pending.size;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private ensureRunning(): ChildProcess {
|
|
52
|
-
if (this.child !== null && this.child.connected) return this.child;
|
|
53
|
-
|
|
54
|
-
const resolvedPath = resolveSessionWorkerPath();
|
|
55
|
-
|
|
56
|
-
this.child = spawn(process.execPath, [...process.execArgv, resolvedPath], {
|
|
57
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
58
|
-
windowsHide: true,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this.restartCount += 1;
|
|
62
|
-
|
|
63
|
-
this.child.on("message", (raw: unknown) => {
|
|
64
|
-
if (!isPlainRecord(raw)) {
|
|
65
|
-
logger.error("[sessionProcess] Received malformed IPC message from worker, discarding");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const id = safeGetOwnProperty(raw, "id");
|
|
69
|
-
const result = safeGetOwnProperty(raw, "result");
|
|
70
|
-
if (typeof id !== "string" || !isPlainRecord(result)) {
|
|
71
|
-
logger.error("[sessionProcess] Received malformed IPC message from worker, discarding");
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
// Runtime shape validated above; the cast bridges unknown → FinalizeLogResult.
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
76
|
-
const msg = { id, result: result as FinalizeLogResult };
|
|
77
|
-
const pending = this.pending.get(msg.id);
|
|
78
|
-
if (pending !== undefined) {
|
|
79
|
-
this.pending.delete(msg.id);
|
|
80
|
-
pending.resolve(msg.result);
|
|
81
|
-
}
|
|
82
|
-
this.resetIdleTimer();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
this.child.on("error", (err) => {
|
|
86
|
-
logger.error(`[sessionProcess] Session ${this.sessionId} process error:`, err.message);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
this.child.on("exit", (code, signal) => {
|
|
90
|
-
const wasConnected = this.child !== null;
|
|
91
|
-
this.child = null;
|
|
92
|
-
|
|
93
|
-
if (this.destroyed) return;
|
|
94
|
-
|
|
95
|
-
// Reject all pending jobs on unexpected exit
|
|
96
|
-
for (const [, pending] of this.pending) {
|
|
97
|
-
pending.reject(
|
|
98
|
-
new Error(
|
|
99
|
-
`Session process exited with code ${code ?? signal}, session=${this.sessionId}`,
|
|
100
|
-
),
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
this.pending.clear();
|
|
104
|
-
|
|
105
|
-
if (wasConnected && this.restartCount <= MAX_RESTARTS) {
|
|
106
|
-
logger.warn(
|
|
107
|
-
`[sessionProcess] Session ${this.sessionId} worker exited (code=${code ?? signal}), ` +
|
|
108
|
-
`restart ${this.restartCount}/${MAX_RESTARTS}`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
this.resetIdleTimer();
|
|
114
|
-
return this.child;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
enqueue(job: FinalizeLogJob): Promise<FinalizeLogResult> {
|
|
118
|
-
return new Promise((resolve, reject) => {
|
|
119
|
-
const child = this.ensureRunning();
|
|
120
|
-
const id = String(++this.nextId);
|
|
121
|
-
this.pending.set(id, { resolve, reject });
|
|
122
|
-
try {
|
|
123
|
-
child.send({ id, job }, (err) => {
|
|
124
|
-
if (err === null || err === undefined) return;
|
|
125
|
-
this.pending.delete(id);
|
|
126
|
-
reject(
|
|
127
|
-
new Error(
|
|
128
|
-
`Session process send failed for session=${this.sessionId}: ${errorMessage(err)}`,
|
|
129
|
-
),
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
} catch (err) {
|
|
133
|
-
this.pending.delete(id);
|
|
134
|
-
reject(
|
|
135
|
-
new Error(
|
|
136
|
-
`Session process send failed for session=${this.sessionId}: ${errorMessage(err)}`,
|
|
137
|
-
),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private resetIdleTimer(): void {
|
|
144
|
-
if (this.idleTimer !== null) clearTimeout(this.idleTimer);
|
|
145
|
-
this.idleTimer = setTimeout(() => {
|
|
146
|
-
if (this.pending.size === 0) {
|
|
147
|
-
this.destroy();
|
|
148
|
-
}
|
|
149
|
-
}, IDLE_TIMEOUT_MS);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
destroy(): void {
|
|
153
|
-
this.destroyed = true;
|
|
154
|
-
if (this.idleTimer !== null) {
|
|
155
|
-
clearTimeout(this.idleTimer);
|
|
156
|
-
this.idleTimer = null;
|
|
157
|
-
}
|
|
158
|
-
if (this.child !== null) {
|
|
159
|
-
this.child.kill();
|
|
160
|
-
this.child = null;
|
|
161
|
-
}
|
|
162
|
-
for (const [, pending] of this.pending) {
|
|
163
|
-
pending.reject(new Error(`Session process shut down, session=${this.sessionId}`));
|
|
164
|
-
}
|
|
165
|
-
this.pending.clear();
|
|
166
|
-
_processes.delete(this.sessionId);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Get or create a dedicated child process for a session. */
|
|
171
|
-
export function getSessionProcess(sessionId: string): SessionProcess {
|
|
172
|
-
const existing = _processes.get(sessionId);
|
|
173
|
-
if (existing !== undefined) return existing;
|
|
174
|
-
|
|
175
|
-
const sp = new SessionProcess(sessionId);
|
|
176
|
-
_processes.set(sessionId, sp);
|
|
177
|
-
return sp;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** Aggregate only queue depth for readiness; session identifiers remain private. */
|
|
181
|
-
export function getSessionProcessPendingCount(): number {
|
|
182
|
-
let pending = 0;
|
|
183
|
-
for (const processWorker of _processes.values()) {
|
|
184
|
-
pending += processWorker.pendingCount;
|
|
185
|
-
}
|
|
186
|
-
return pending;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** Forcefully tear down all session processes (e.g. on server shutdown). */
|
|
190
|
-
export function destroyAllSessionProcesses(): void {
|
|
191
|
-
for (const [, sp] of _processes) {
|
|
192
|
-
sp.destroy();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { logger } from "./logger";
|
|
2
|
-
import { executeFinalizeLogJob, type FinalizeLogJob } from "./logFinalizer";
|
|
3
|
-
import { DEFAULT_RUNTIME_BUDGET_POLICY } from "../lib/resourceLimits";
|
|
4
|
-
import {
|
|
5
|
-
getLogSessionId,
|
|
6
|
-
markSessionTaskFinished,
|
|
7
|
-
markSessionTaskQueued,
|
|
8
|
-
markSessionTaskStarted,
|
|
9
|
-
} from "./sessionSupervisor";
|
|
10
|
-
|
|
11
|
-
const UNASSIGNED_SESSION_QUEUE = "__unassigned__";
|
|
12
|
-
|
|
13
|
-
export type SessionTaskName = "finalize-log";
|
|
14
|
-
|
|
15
|
-
type SessionTask<T> = () => Promise<T> | T;
|
|
16
|
-
|
|
17
|
-
const queues = new Map<string, Promise<void>>();
|
|
18
|
-
let queuedTaskCount = 0;
|
|
19
|
-
|
|
20
|
-
export class SessionTaskQueueRejectedError extends Error {
|
|
21
|
-
constructor(limit: number) {
|
|
22
|
-
super(`Session task queue is full; limit=${String(limit)}`);
|
|
23
|
-
this.name = "SessionTaskQueueRejectedError";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function queueKeyForSession(sessionId: string | null): string {
|
|
28
|
-
return sessionId ?? UNASSIGNED_SESSION_QUEUE;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function resolveSessionTaskQueueLimit(): number {
|
|
32
|
-
const configured = Number(process.env["SESSION_TASK_QUEUE_LIMIT"]);
|
|
33
|
-
if (Number.isSafeInteger(configured) && configured > 0) return configured;
|
|
34
|
-
return DEFAULT_RUNTIME_BUDGET_POLICY.queues.finalizerJobs;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function errorMessage(err: unknown): string {
|
|
38
|
-
return err instanceof Error ? err.message : String(err);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function runSessionTask<T>(
|
|
42
|
-
sessionId: string | null,
|
|
43
|
-
taskName: SessionTaskName,
|
|
44
|
-
task: SessionTask<T>,
|
|
45
|
-
): Promise<T> {
|
|
46
|
-
markSessionTaskStarted(sessionId);
|
|
47
|
-
try {
|
|
48
|
-
const result = await task();
|
|
49
|
-
markSessionTaskFinished(sessionId, null);
|
|
50
|
-
return result;
|
|
51
|
-
} catch (err) {
|
|
52
|
-
const message = errorMessage(err);
|
|
53
|
-
logger.error(`[sessionRuntime] ${taskName} failed for session ${sessionId ?? "unassigned"}`);
|
|
54
|
-
markSessionTaskFinished(sessionId, message);
|
|
55
|
-
return Promise.reject(err);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function enqueueSessionTask<T>(
|
|
60
|
-
sessionId: string | null,
|
|
61
|
-
taskName: SessionTaskName,
|
|
62
|
-
task: SessionTask<T>,
|
|
63
|
-
): Promise<T> {
|
|
64
|
-
const queueLimit = resolveSessionTaskQueueLimit();
|
|
65
|
-
if (queuedTaskCount >= queueLimit) {
|
|
66
|
-
logger.warn(
|
|
67
|
-
`[sessionRuntime] Rejecting ${taskName} for session ${sessionId ?? "unassigned"}: ` +
|
|
68
|
-
`queue full (${String(queuedTaskCount)}/${String(queueLimit)})`,
|
|
69
|
-
);
|
|
70
|
-
return Promise.reject(new SessionTaskQueueRejectedError(queueLimit));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const queueKey = queueKeyForSession(sessionId);
|
|
74
|
-
const previous = queues.get(queueKey) ?? Promise.resolve();
|
|
75
|
-
|
|
76
|
-
queuedTaskCount += 1;
|
|
77
|
-
markSessionTaskQueued(sessionId);
|
|
78
|
-
|
|
79
|
-
const current = previous
|
|
80
|
-
.catch(() => undefined)
|
|
81
|
-
.then(() => runSessionTask(sessionId, taskName, task));
|
|
82
|
-
const settled = current.then(
|
|
83
|
-
() => undefined,
|
|
84
|
-
() => undefined,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
queues.set(queueKey, settled);
|
|
88
|
-
void settled.then(() => {
|
|
89
|
-
queuedTaskCount = Math.max(0, queuedTaskCount - 1);
|
|
90
|
-
if (queues.get(queueKey) === settled) {
|
|
91
|
-
queues.delete(queueKey);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
return current;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function enqueueFinalizeLogJob(job: FinalizeLogJob): Promise<void> {
|
|
99
|
-
return enqueueSessionTask(getLogSessionId(job.log), "finalize-log", () =>
|
|
100
|
-
executeFinalizeLogJob(job),
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Wait until every per-session finalizer queue has settled. */
|
|
105
|
-
export async function flushSessionTasks(): Promise<void> {
|
|
106
|
-
while (queues.size > 0) {
|
|
107
|
-
await Promise.all([...queues.values()]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function getSessionRuntimeQueueHealth(): {
|
|
112
|
-
activeQueues: number;
|
|
113
|
-
queuedTasks: number;
|
|
114
|
-
queueLimit: number;
|
|
115
|
-
} {
|
|
116
|
-
return {
|
|
117
|
-
activeQueues: queues.size,
|
|
118
|
-
queuedTasks: queuedTaskCount,
|
|
119
|
-
queueLimit: resolveSessionTaskQueueLimit(),
|
|
120
|
-
};
|
|
121
|
-
}
|