@vybestack/llxprt-code-core 0.11.0 → 0.12.0-nightly.260910.2aac6841e
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt-config/defaults/default-prompts.json +3 -3
- package/dist/src/config/agentClientLifecycle.d.ts +4 -3
- package/dist/src/config/agentClientLifecycle.js +27 -14
- package/dist/src/config/agentClientLifecycle.js.map +1 -1
- package/dist/src/config/config.d.ts +2 -5
- package/dist/src/config/config.js +10 -23
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/configBase.d.ts +5 -1
- package/dist/src/config/configBase.js +27 -6
- package/dist/src/config/configBase.js.map +1 -1
- package/dist/src/config/configBaseCore.d.ts +26 -8
- package/dist/src/config/configBaseCore.js +30 -26
- package/dist/src/config/configBaseCore.js.map +1 -1
- package/dist/src/config/configMcpRuntime.d.ts +16 -0
- package/dist/src/config/configMcpRuntime.js +31 -0
- package/dist/src/config/configMcpRuntime.js.map +1 -0
- package/dist/src/config/configMediaDefaults.d.ts +10 -0
- package/dist/src/config/configMediaDefaults.js +17 -0
- package/dist/src/config/configMediaDefaults.js.map +1 -0
- package/dist/src/config/configTestHarness.d.ts +4 -0
- package/dist/src/config/configTypes.d.ts +4 -54
- package/dist/src/config/configTypes.js +6 -82
- package/dist/src/config/configTypes.js.map +1 -1
- package/dist/src/config/index.d.ts +1 -2
- package/dist/src/config/index.js +1 -2
- package/dist/src/config/index.js.map +1 -1
- package/dist/src/config/models.d.ts +0 -4
- package/dist/src/config/models.js +0 -4
- package/dist/src/config/models.js.map +1 -1
- package/dist/src/config/toolRegistryFactory.d.ts +2 -2
- package/dist/src/core/clientContract.d.ts +4 -6
- package/dist/src/core/compression/transcriptPathNotice.d.ts +22 -0
- package/dist/src/core/compression/transcriptPathNotice.js +29 -0
- package/dist/src/core/compression/transcriptPathNotice.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +2 -5
- package/dist/src/core/contentGenerator.js +10 -24
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/logger.d.ts +66 -0
- package/dist/src/core/logger.js +345 -30
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/prompts.d.ts +0 -1
- package/dist/src/core/prompts.js +5 -79
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/turn.d.ts +3 -3
- package/dist/src/hooks/hookTranslator.js +5 -4
- package/dist/src/hooks/hookTranslator.js.map +1 -1
- package/dist/src/index.d.ts +8 -6
- package/dist/src/index.js +8 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/llm-types/index.d.ts +1 -1
- package/dist/src/llm-types/modelEnvelope.d.ts +2 -1
- package/dist/src/llm-types/modelEnvelope.js +17 -1
- package/dist/src/llm-types/modelEnvelope.js.map +1 -1
- package/dist/src/models/schema.d.ts +40 -40
- package/dist/src/policy/policies/read-only.toml +0 -5
- package/dist/src/prompt-config/TemplateEngine.js +0 -3
- package/dist/src/prompt-config/TemplateEngine.js.map +1 -1
- package/dist/src/prompt-config/defaults/providers/gemini/core.md +0 -2
- package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
- package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
- package/dist/src/prompt-config/prompt-loader.d.ts +1 -1
- package/dist/src/prompt-config/prompt-loader.js +4 -4
- package/dist/src/prompt-config/prompt-loader.js.map +1 -1
- package/dist/src/prompt-config/types.d.ts +0 -1
- package/dist/src/recording/CheckpointService.d.ts +4 -0
- package/dist/src/recording/CheckpointService.js +67 -46
- package/dist/src/recording/CheckpointService.js.map +1 -1
- package/dist/src/recording/HistoryMutationService.d.ts +1 -1
- package/dist/src/recording/HistoryMutationService.js +27 -4
- package/dist/src/recording/HistoryMutationService.js.map +1 -1
- package/dist/src/recording/RecordingIntegration.d.ts +36 -2
- package/dist/src/recording/RecordingIntegration.js +224 -7
- package/dist/src/recording/RecordingIntegration.js.map +1 -1
- package/dist/src/recording/ReplayEngine.d.ts +8 -10
- package/dist/src/recording/ReplayEngine.js +161 -95
- package/dist/src/recording/ReplayEngine.js.map +1 -1
- package/dist/src/recording/SessionDiscovery.d.ts +4 -2
- package/dist/src/recording/SessionDiscovery.js +13 -5
- package/dist/src/recording/SessionDiscovery.js.map +1 -1
- package/dist/src/recording/SessionRecordingService.d.ts +23 -3
- package/dist/src/recording/SessionRecordingService.js +209 -51
- package/dist/src/recording/SessionRecordingService.js.map +1 -1
- package/dist/src/recording/SessionTransitionService.d.ts +7 -0
- package/dist/src/recording/SessionTransitionService.js +66 -13
- package/dist/src/recording/SessionTransitionService.js.map +1 -1
- package/dist/src/recording/index.d.ts +1 -0
- package/dist/src/recording/index.js +1 -0
- package/dist/src/recording/index.js.map +1 -1
- package/dist/src/recording/janitor/cleanupTypes.d.ts +3 -0
- package/dist/src/recording/janitor/cleanupTypes.js.map +1 -1
- package/dist/src/recording/janitor/mediaReclamation.d.ts +23 -0
- package/dist/src/recording/janitor/mediaReclamation.js +195 -0
- package/dist/src/recording/janitor/mediaReclamation.js.map +1 -0
- package/dist/src/recording/janitor/sessionJanitor.js +47 -1
- package/dist/src/recording/janitor/sessionJanitor.js.map +1 -1
- package/dist/src/recording/janitor/sessionScanner.d.ts +12 -9
- package/dist/src/recording/janitor/sessionScanner.js +248 -193
- package/dist/src/recording/janitor/sessionScanner.js.map +1 -1
- package/dist/src/recording/replay-test-helpers.d.ts +10 -1
- package/dist/src/recording/replay-test-helpers.js +24 -2
- package/dist/src/recording/replay-test-helpers.js.map +1 -1
- package/dist/src/recording/replayCheckpointMetadata.d.ts +28 -0
- package/dist/src/recording/replayCheckpointMetadata.js +96 -0
- package/dist/src/recording/replayCheckpointMetadata.js.map +1 -0
- package/dist/src/recording/replayErrorFormatting.d.ts +6 -0
- package/dist/src/recording/replayErrorFormatting.js +38 -0
- package/dist/src/recording/replayErrorFormatting.js.map +1 -0
- package/dist/src/recording/resumeSession.d.ts +3 -0
- package/dist/src/recording/resumeSession.js +7 -1
- package/dist/src/recording/resumeSession.js.map +1 -1
- package/dist/src/recording/semanticMediaPurgeReplayValidation.d.ts +14 -0
- package/dist/src/recording/semanticMediaPurgeReplayValidation.js +24 -0
- package/dist/src/recording/semanticMediaPurgeReplayValidation.js.map +1 -0
- package/dist/src/recording/session-media-package-blobs.d.ts +8 -0
- package/dist/src/recording/session-media-package-blobs.js +72 -0
- package/dist/src/recording/session-media-package-blobs.js.map +1 -0
- package/dist/src/recording/session-media-package-import.d.ts +26 -0
- package/dist/src/recording/session-media-package-import.js +124 -0
- package/dist/src/recording/session-media-package-import.js.map +1 -0
- package/dist/src/recording/session-media-package-state.d.ts +19 -0
- package/dist/src/recording/session-media-package-state.js +56 -0
- package/dist/src/recording/session-media-package-state.js.map +1 -0
- package/dist/src/recording/session-media-package-validation.d.ts +59 -0
- package/dist/src/recording/session-media-package-validation.js +286 -0
- package/dist/src/recording/session-media-package-validation.js.map +1 -0
- package/dist/src/recording/session-media-package-writer.d.ts +18 -0
- package/dist/src/recording/session-media-package-writer.js +70 -0
- package/dist/src/recording/session-media-package-writer.js.map +1 -0
- package/dist/src/recording/session-media-package.d.ts +27 -0
- package/dist/src/recording/session-media-package.js +366 -0
- package/dist/src/recording/session-media-package.js.map +1 -0
- package/dist/src/recording/types.d.ts +34 -2
- package/dist/src/recording/types.js.map +1 -1
- package/dist/src/runtime/AgentRuntimeContext.d.ts +22 -5
- package/dist/src/runtime/AgentRuntimeLoader.d.ts +6 -0
- package/dist/src/runtime/AgentRuntimeLoader.js +25 -6
- package/dist/src/runtime/AgentRuntimeLoader.js.map +1 -1
- package/dist/src/runtime/contracts/PromptEstimation.d.ts +1 -0
- package/dist/src/runtime/contracts/PromptEstimation.js.map +1 -1
- package/dist/src/runtime/contracts/RuntimeProvider.d.ts +3 -2
- package/dist/src/runtime/contracts/RuntimeProviderManager.d.ts +0 -2
- package/dist/src/runtime/createAgentRuntimeContext.js +28 -1
- package/dist/src/runtime/createAgentRuntimeContext.js.map +1 -1
- package/dist/src/runtime/providerRuntimeContext.d.ts +12 -0
- package/dist/src/runtime/providerRuntimeContext.js +3 -0
- package/dist/src/runtime/providerRuntimeContext.js.map +1 -1
- package/dist/src/runtime/runtimeAdapters.js +2 -2
- package/dist/src/runtime/runtimeAdapters.js.map +1 -1
- package/dist/src/services/history/ContentConverters.d.ts +11 -7
- package/dist/src/services/history/ContentConverters.js +11 -7
- package/dist/src/services/history/ContentConverters.js.map +1 -1
- package/dist/src/services/history/HistoryService.d.ts +18 -180
- package/dist/src/services/history/HistoryService.js +53 -523
- package/dist/src/services/history/HistoryService.js.map +1 -1
- package/dist/src/services/history/HistoryServiceCore.d.ts +278 -0
- package/dist/src/services/history/HistoryServiceCore.js +727 -0
- package/dist/src/services/history/HistoryServiceCore.js.map +1 -0
- package/dist/src/services/history/IContent.d.ts +118 -16
- package/dist/src/services/history/IContent.js +284 -4
- package/dist/src/services/history/IContent.js.map +1 -1
- package/dist/src/services/history/contentSize.js +22 -2
- package/dist/src/services/history/contentSize.js.map +1 -1
- package/dist/src/services/history/historyChronology.d.ts +7 -0
- package/dist/src/services/history/historyChronology.js +35 -3
- package/dist/src/services/history/historyChronology.js.map +1 -1
- package/dist/src/services/history/historyCloneUtils.d.ts +5 -4
- package/dist/src/services/history/historyCloneUtils.js +23 -16
- package/dist/src/services/history/historyCloneUtils.js.map +1 -1
- package/dist/src/services/history/historyCompressionQueue.d.ts +33 -0
- package/dist/src/services/history/historyCompressionQueue.js +81 -0
- package/dist/src/services/history/historyCompressionQueue.js.map +1 -0
- package/dist/src/services/history/historyEventTypes.d.ts +3 -0
- package/dist/src/services/history/historyMutationFailure.d.ts +15 -0
- package/dist/src/services/history/historyMutationFailure.js +22 -0
- package/dist/src/services/history/historyMutationFailure.js.map +1 -1
- package/dist/src/services/history/historyProviderPipeline.d.ts +1 -1
- package/dist/src/services/history/historyProviderPipeline.js +15 -5
- package/dist/src/services/history/historyProviderPipeline.js.map +1 -1
- package/dist/src/services/history/historyTokenEstimation.js +10 -6
- package/dist/src/services/history/historyTokenEstimation.js.map +1 -1
- package/dist/src/services/history/historyToolNormalization.d.ts +2 -0
- package/dist/src/services/history/historyToolNormalization.js +26 -9
- package/dist/src/services/history/historyToolNormalization.js.map +1 -1
- package/dist/src/services/history/provider-file-binding.d.ts +11 -0
- package/dist/src/services/history/provider-file-binding.js +70 -0
- package/dist/src/services/history/provider-file-binding.js.map +1 -0
- package/dist/src/services/history/semantic-media-purge.d.ts +66 -0
- package/dist/src/services/history/semantic-media-purge.js +404 -0
- package/dist/src/services/history/semantic-media-purge.js.map +1 -0
- package/dist/src/storage/SessionPersistenceService.d.ts +53 -2
- package/dist/src/storage/SessionPersistenceService.js +435 -23
- package/dist/src/storage/SessionPersistenceService.js.map +1 -1
- package/dist/src/storage/history-media-ownership.d.ts +38 -0
- package/dist/src/storage/history-media-ownership.js +136 -0
- package/dist/src/storage/history-media-ownership.js.map +1 -0
- package/dist/src/storage/local-media-store-child.d.ts +6 -0
- package/dist/src/storage/local-media-store-child.js +140 -0
- package/dist/src/storage/local-media-store-child.js.map +1 -0
- package/dist/src/storage/local-media-store-files.d.ts +44 -0
- package/dist/src/storage/local-media-store-files.js +460 -0
- package/dist/src/storage/local-media-store-files.js.map +1 -0
- package/dist/src/storage/local-media-store-lock-recovery.d.ts +15 -0
- package/dist/src/storage/local-media-store-lock-recovery.js +112 -0
- package/dist/src/storage/local-media-store-lock-recovery.js.map +1 -0
- package/dist/src/storage/local-media-store-persistence.d.ts +48 -0
- package/dist/src/storage/local-media-store-persistence.js +443 -0
- package/dist/src/storage/local-media-store-persistence.js.map +1 -0
- package/dist/src/storage/local-media-store-quota.d.ts +6 -0
- package/dist/src/storage/local-media-store-quota.js +66 -0
- package/dist/src/storage/local-media-store-quota.js.map +1 -0
- package/dist/src/storage/local-media-store-reservations.d.ts +55 -0
- package/dist/src/storage/local-media-store-reservations.js +377 -0
- package/dist/src/storage/local-media-store-reservations.js.map +1 -0
- package/dist/src/storage/local-media-store-types.d.ts +110 -0
- package/dist/src/storage/local-media-store-types.js +35 -0
- package/dist/src/storage/local-media-store-types.js.map +1 -0
- package/dist/src/storage/local-media-store-validation.d.ts +34 -0
- package/dist/src/storage/local-media-store-validation.js +449 -0
- package/dist/src/storage/local-media-store-validation.js.map +1 -0
- package/dist/src/storage/local-media-store.d.ts +47 -0
- package/dist/src/storage/local-media-store.js +353 -0
- package/dist/src/storage/local-media-store.js.map +1 -0
- package/dist/src/storage/media-admission-service.d.ts +49 -0
- package/dist/src/storage/media-admission-service.js +333 -0
- package/dist/src/storage/media-admission-service.js.map +1 -0
- package/dist/src/storage/media-lifecycle-metrics.d.ts +75 -0
- package/dist/src/storage/media-lifecycle-metrics.js +105 -0
- package/dist/src/storage/media-lifecycle-metrics.js.map +1 -0
- package/dist/src/storage/media-reference-lifecycle.d.ts +16 -0
- package/dist/src/storage/media-reference-lifecycle.js +84 -0
- package/dist/src/storage/media-reference-lifecycle.js.map +1 -0
- package/dist/src/storage/request-media-resolver.d.ts +67 -0
- package/dist/src/storage/request-media-resolver.js +325 -0
- package/dist/src/storage/request-media-resolver.js.map +1 -0
- package/dist/src/storage/session-media-service-factories.d.ts +19 -0
- package/dist/src/storage/session-media-service-factories.js +34 -0
- package/dist/src/storage/session-media-service-factories.js.map +1 -0
- package/dist/src/storage/session-persistence-helpers.d.ts +10 -0
- package/dist/src/storage/session-persistence-helpers.js +46 -0
- package/dist/src/storage/session-persistence-helpers.js.map +1 -0
- package/dist/src/test-utils/config.d.ts +2 -0
- package/dist/src/test-utils/config.js +5 -5
- package/dist/src/test-utils/config.js.map +1 -1
- package/dist/src/test-utils/runtime.d.ts +2 -0
- package/dist/src/test-utils/runtime.js +1 -2
- package/dist/src/test-utils/runtime.js.map +1 -1
- package/dist/src/tools-adapters/CoreShellToolHostAdapter.js +1 -9
- package/dist/src/tools-adapters/CoreShellToolHostAdapter.js.map +1 -1
- package/dist/src/tools-adapters/CoreSkillServiceAdapter.d.ts +0 -2
- package/dist/src/tools-adapters/CoreSkillServiceAdapter.js +0 -17
- package/dist/src/tools-adapters/CoreSkillServiceAdapter.js.map +1 -1
- package/dist/src/tools-adapters/CoreToolHostAdapter.d.ts +0 -21
- package/dist/src/tools-adapters/CoreToolHostAdapter.js +0 -8
- package/dist/src/tools-adapters/CoreToolHostAdapter.js.map +1 -1
- package/dist/src/utils/environmentContext.d.ts +8 -9
- package/dist/src/utils/environmentContext.js +11 -22
- package/dist/src/utils/environmentContext.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +1 -2
- package/dist/src/utils/errorParsing.js +22 -41
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/generateContentResponseUtilities.js +12 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
- package/dist/src/utils/summarizer.d.ts +1 -2
- package/dist/src/utils/summarizer.js +6 -5
- package/dist/src/utils/summarizer.js.map +1 -1
- package/dist/src/utils/tool-utils.js +7 -1
- package/dist/src/utils/tool-utils.js.map +1 -1
- package/index.ts +0 -4
- package/package.json +38 -30
- package/src/config/agentClientLifecycle.ts +53 -22
- package/src/config/config.ts +11 -26
- package/src/config/configBase.ts +46 -7
- package/src/config/configBaseCore.ts +38 -36
- package/src/config/configMcpRuntime.ts +46 -0
- package/src/config/configMediaDefaults.ts +19 -0
- package/src/config/configTypes.ts +13 -53
- package/src/config/index.ts +1 -4
- package/src/config/models.ts +0 -6
- package/src/config/toolRegistryFactory.ts +2 -2
- package/src/core/clientContract.ts +4 -6
- package/src/core/compression/transcriptPathNotice.ts +31 -0
- package/src/core/contentGenerator.ts +15 -39
- package/src/core/logger.ts +370 -39
- package/src/core/prompts.ts +4 -114
- package/src/core/turn.ts +3 -3
- package/src/hooks/hookTranslator.ts +6 -4
- package/src/index.ts +7 -7
- package/src/llm-types/index.ts +5 -0
- package/src/llm-types/modelEnvelope.ts +26 -2
- package/src/policy/policies/read-only.toml +0 -5
- package/src/prompt-config/TemplateEngine.ts +0 -3
- package/src/prompt-config/defaults/providers/gemini/core.md +0 -2
- package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
- package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
- package/src/prompt-config/prompt-loader.ts +7 -8
- package/src/prompt-config/types.ts +0 -1
- package/src/recording/CheckpointService.ts +110 -45
- package/src/recording/HistoryMutationService.ts +28 -3
- package/src/recording/RecordingIntegration.ts +258 -11
- package/src/recording/ReplayEngine.ts +220 -110
- package/src/recording/SessionDiscovery.ts +30 -4
- package/src/recording/SessionRecordingService.ts +253 -55
- package/src/recording/SessionTransitionService.ts +75 -12
- package/src/recording/index.ts +7 -0
- package/src/recording/janitor/cleanupTypes.ts +4 -0
- package/src/recording/janitor/mediaReclamation.ts +295 -0
- package/src/recording/janitor/sessionJanitor.ts +54 -1
- package/src/recording/janitor/sessionScanner.ts +319 -227
- package/src/recording/replay-test-helpers.ts +33 -2
- package/src/recording/replayCheckpointMetadata.ts +115 -0
- package/src/recording/replayErrorFormatting.ts +43 -0
- package/src/recording/resumeSession.ts +10 -0
- package/src/recording/semanticMediaPurgeReplayValidation.ts +35 -0
- package/src/recording/session-media-package-blobs.ts +116 -0
- package/src/recording/session-media-package-import.ts +189 -0
- package/src/recording/session-media-package-state.ts +120 -0
- package/src/recording/session-media-package-validation.ts +400 -0
- package/src/recording/session-media-package-writer.ts +117 -0
- package/src/recording/session-media-package.ts +692 -0
- package/src/recording/types.ts +37 -2
- package/src/runtime/AgentRuntimeContext.ts +28 -5
- package/src/runtime/AgentRuntimeLoader.ts +32 -7
- package/src/runtime/contracts/PromptEstimation.ts +1 -0
- package/src/runtime/contracts/RuntimeProvider.ts +3 -8
- package/src/runtime/contracts/RuntimeProviderManager.ts +0 -2
- package/src/runtime/createAgentRuntimeContext.ts +43 -1
- package/src/runtime/providerRuntimeContext.ts +22 -0
- package/src/runtime/runtimeAdapters.ts +2 -2
- package/src/services/history/ContentConverters.ts +11 -7
- package/src/services/history/HistoryService.ts +71 -696
- package/src/services/history/HistoryServiceCore.ts +1055 -0
- package/src/services/history/IContent.ts +460 -20
- package/src/services/history/contentSize.ts +22 -2
- package/src/services/history/historyChronology.ts +53 -3
- package/src/services/history/historyCloneUtils.ts +26 -22
- package/src/services/history/historyCompressionQueue.ts +102 -0
- package/src/services/history/historyEventTypes.ts +9 -0
- package/src/services/history/historyMutationFailure.ts +33 -0
- package/src/services/history/historyProviderPipeline.ts +19 -5
- package/src/services/history/historyTokenEstimation.ts +9 -5
- package/src/services/history/historyToolNormalization.ts +43 -11
- package/src/services/history/provider-file-binding.ts +115 -0
- package/src/services/history/semantic-media-purge.ts +593 -0
- package/src/storage/SessionPersistenceService.ts +667 -30
- package/src/storage/history-media-ownership.ts +185 -0
- package/src/storage/local-media-store-child.ts +163 -0
- package/src/storage/local-media-store-files.ts +643 -0
- package/src/storage/local-media-store-lock-recovery.ts +159 -0
- package/src/storage/local-media-store-persistence.ts +737 -0
- package/src/storage/local-media-store-quota.ts +111 -0
- package/src/storage/local-media-store-reservations.ts +485 -0
- package/src/storage/local-media-store-types.ts +161 -0
- package/src/storage/local-media-store-validation.ts +643 -0
- package/src/storage/local-media-store.ts +696 -0
- package/src/storage/media-admission-service.ts +512 -0
- package/src/storage/media-lifecycle-metrics.ts +228 -0
- package/src/storage/media-reference-lifecycle.ts +164 -0
- package/src/storage/request-media-resolver.ts +491 -0
- package/src/storage/session-media-service-factories.ts +48 -0
- package/src/storage/session-persistence-helpers.ts +85 -0
- package/src/test-utils/config.ts +7 -5
- package/src/test-utils/runtime.ts +3 -2
- package/src/tools-adapters/CoreShellToolHostAdapter.ts +1 -11
- package/src/tools-adapters/CoreSkillServiceAdapter.ts +0 -23
- package/src/tools-adapters/CoreToolHostAdapter.ts +0 -36
- package/src/utils/environmentContext.ts +11 -30
- package/src/utils/errorParsing.ts +19 -69
- package/src/utils/generateContentResponseUtilities.ts +28 -1
- package/src/utils/summarizer.ts +8 -10
- package/src/utils/tool-utils.ts +7 -1
- package/dist/src/code_assist/codeAssist.d.ts +0 -19
- package/dist/src/code_assist/codeAssist.js +0 -41
- package/dist/src/code_assist/codeAssist.js.map +0 -1
- package/dist/src/code_assist/contentGeneratorAdapters.d.ts +0 -49
- package/dist/src/code_assist/contentGeneratorAdapters.js +0 -197
- package/dist/src/code_assist/contentGeneratorAdapters.js.map +0 -1
- package/dist/src/code_assist/converter.d.ts +0 -74
- package/dist/src/code_assist/converter.js +0 -158
- package/dist/src/code_assist/converter.js.map +0 -1
- package/dist/src/code_assist/googleGenAIWrapper.d.ts +0 -27
- package/dist/src/code_assist/googleGenAIWrapper.js +0 -46
- package/dist/src/code_assist/googleGenAIWrapper.js.map +0 -1
- package/dist/src/code_assist/oauth-credential-storage.d.ts +0 -30
- package/dist/src/code_assist/oauth-credential-storage.js +0 -135
- package/dist/src/code_assist/oauth-credential-storage.js.map +0 -1
- package/dist/src/code_assist/server.d.ts +0 -44
- package/dist/src/code_assist/server.js +0 -154
- package/dist/src/code_assist/server.js.map +0 -1
- package/dist/src/code_assist/setup.d.ts +0 -20
- package/dist/src/code_assist/setup.js +0 -126
- package/dist/src/code_assist/setup.js.map +0 -1
- package/dist/src/code_assist/types.d.ts +0 -161
- package/dist/src/code_assist/types.js +0 -46
- package/dist/src/code_assist/types.js.map +0 -1
- package/dist/src/utils/getFolderStructure.d.ts +0 -31
- package/dist/src/utils/getFolderStructure.js +0 -240
- package/dist/src/utils/getFolderStructure.js.map +0 -1
- package/dist/src/utils/installationManager.d.ts +0 -16
- package/dist/src/utils/installationManager.js +0 -51
- package/dist/src/utils/installationManager.js.map +0 -1
- package/dist/src/utils/llm-edit-fixer.d.ts +0 -25
- package/dist/src/utils/llm-edit-fixer.js +0 -120
- package/dist/src/utils/llm-edit-fixer.js.map +0 -1
- package/src/code_assist/codeAssist.ts +0 -59
- package/src/code_assist/contentGeneratorAdapters.ts +0 -275
- package/src/code_assist/converter.ts +0 -288
- package/src/code_assist/googleGenAIWrapper.ts +0 -90
- package/src/code_assist/oauth-credential-storage.ts +0 -171
- package/src/code_assist/server.ts +0 -263
- package/src/code_assist/setup.ts +0 -189
- package/src/code_assist/types.ts +0 -201
- package/src/utils/getFolderStructure.ts +0 -382
- package/src/utils/installationManager.ts +0 -59
- package/src/utils/llm-edit-fixer.ts +0 -157
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { CheckpointMetadataView, SessionRecordLine } from './types.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Checkpoint metadata folding for replay (kept beside ReplayEngine so the
|
|
21
|
+
* engine stays within its size budget).
|
|
22
|
+
*/
|
|
23
|
+
export function appendCheckpointMetadataWarnings(
|
|
24
|
+
events: readonly SessionRecordLine[],
|
|
25
|
+
warnings: string[],
|
|
26
|
+
): void {
|
|
27
|
+
const knownIds = new Set<string>();
|
|
28
|
+
const deletedIds = new Set<string>();
|
|
29
|
+
for (const line of events) {
|
|
30
|
+
const checkpointId = extractCheckpointId(line);
|
|
31
|
+
if (checkpointId === null) continue;
|
|
32
|
+
if (line.type === 'checkpoint_created') {
|
|
33
|
+
if (knownIds.has(checkpointId)) {
|
|
34
|
+
warnings.push(
|
|
35
|
+
`Sequence ${line.seq}: checkpoint_created duplicates checkpoint ${checkpointId}`,
|
|
36
|
+
);
|
|
37
|
+
} else {
|
|
38
|
+
knownIds.add(checkpointId);
|
|
39
|
+
}
|
|
40
|
+
} else if (
|
|
41
|
+
line.type === 'checkpoint_renamed' ||
|
|
42
|
+
line.type === 'checkpoint_deleted'
|
|
43
|
+
) {
|
|
44
|
+
if (!knownIds.has(checkpointId)) {
|
|
45
|
+
warnings.push(
|
|
46
|
+
`Sequence ${line.seq}: ${line.type} references unknown checkpoint ${checkpointId}`,
|
|
47
|
+
);
|
|
48
|
+
} else if (deletedIds.has(checkpointId)) {
|
|
49
|
+
warnings.push(
|
|
50
|
+
`Sequence ${line.seq}: ${line.type} references deleted checkpoint ${checkpointId}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (line.type === 'checkpoint_deleted') deletedIds.add(checkpointId);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function extractCheckpointId(line: SessionRecordLine): string | null {
|
|
59
|
+
if (typeof line.payload !== 'object' || line.payload === null) return null;
|
|
60
|
+
const checkpointId =
|
|
61
|
+
'checkpointId' in line.payload ? line.payload.checkpointId : undefined;
|
|
62
|
+
return typeof checkpointId === 'string' ? checkpointId : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Fold checkpoint lifecycle events into a stable view ordered by sequence.
|
|
67
|
+
* Each checkpoint is tracked by stable `checkpointId`. Created events set
|
|
68
|
+
* the name, watermark, and createdAt; renamed events update the name;
|
|
69
|
+
* deleted events set `deleted: true`.
|
|
70
|
+
*/
|
|
71
|
+
export function foldCheckpointMetadata(
|
|
72
|
+
events: readonly SessionRecordLine[],
|
|
73
|
+
): CheckpointMetadataView[] {
|
|
74
|
+
const byId = new Map<string, CheckpointMetadataView>();
|
|
75
|
+
|
|
76
|
+
for (const line of events) {
|
|
77
|
+
foldCheckpointLine(line, byId);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return Array.from(byId.values()).sort((a, b) => a.sequence - b.sequence);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function foldCheckpointLine(
|
|
84
|
+
line: SessionRecordLine,
|
|
85
|
+
byId: Map<string, CheckpointMetadataView>,
|
|
86
|
+
): void {
|
|
87
|
+
if (typeof line.payload !== 'object' || line.payload === null) return;
|
|
88
|
+
const payload = line.payload;
|
|
89
|
+
const checkpointId =
|
|
90
|
+
'checkpointId' in payload ? payload.checkpointId : undefined;
|
|
91
|
+
if (typeof checkpointId !== 'string' || checkpointId.length === 0) return;
|
|
92
|
+
const existing = byId.get(checkpointId);
|
|
93
|
+
const name = 'name' in payload ? payload.name : undefined;
|
|
94
|
+
if (
|
|
95
|
+
line.type === 'checkpoint_created' &&
|
|
96
|
+
typeof name === 'string' &&
|
|
97
|
+
existing === undefined
|
|
98
|
+
) {
|
|
99
|
+
byId.set(checkpointId, {
|
|
100
|
+
checkpointId,
|
|
101
|
+
name,
|
|
102
|
+
sequence: line.seq,
|
|
103
|
+
deleted: false,
|
|
104
|
+
createdAt: line.ts,
|
|
105
|
+
});
|
|
106
|
+
} else if (
|
|
107
|
+
line.type === 'checkpoint_renamed' &&
|
|
108
|
+
typeof name === 'string' &&
|
|
109
|
+
existing !== undefined
|
|
110
|
+
) {
|
|
111
|
+
byId.set(checkpointId, { ...existing, name });
|
|
112
|
+
} else if (line.type === 'checkpoint_deleted' && existing !== undefined) {
|
|
113
|
+
byId.set(checkpointId, { ...existing, deleted: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const MAX_REPLAY_DIAGNOSTIC_DEPTH = 32;
|
|
8
|
+
|
|
9
|
+
function isUnknownArray(value: unknown): value is unknown[] {
|
|
10
|
+
return Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function appendReplayDiagnostic(
|
|
14
|
+
error: unknown,
|
|
15
|
+
messages: string[],
|
|
16
|
+
seen: Set<object>,
|
|
17
|
+
depth: number,
|
|
18
|
+
): void {
|
|
19
|
+
if (depth >= MAX_REPLAY_DIAGNOSTIC_DEPTH) return;
|
|
20
|
+
if (typeof error !== 'object' || error === null) {
|
|
21
|
+
messages.push(String(error));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (seen.has(error)) return;
|
|
25
|
+
seen.add(error);
|
|
26
|
+
if (error instanceof Error) messages.push(error.message);
|
|
27
|
+
const nestedErrors = Reflect.get(error, 'errors');
|
|
28
|
+
if (isUnknownArray(nestedErrors)) {
|
|
29
|
+
for (const nested of nestedErrors) {
|
|
30
|
+
appendReplayDiagnostic(nested, messages, seen, depth + 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const cause = Reflect.get(error, 'cause');
|
|
34
|
+
if (cause !== undefined) {
|
|
35
|
+
appendReplayDiagnostic(cause, messages, seen, depth + 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function formatReplayDiagnostic(error: unknown): string {
|
|
40
|
+
const messages: string[] = [];
|
|
41
|
+
appendReplayDiagnostic(error, messages, new Set<object>(), 0);
|
|
42
|
+
return messages.length > 0 ? messages.join(': ') : String(error);
|
|
43
|
+
}
|
|
@@ -30,6 +30,7 @@ import { SessionDiscovery } from './SessionDiscovery.js';
|
|
|
30
30
|
import { SessionLockManager, type LockHandle } from './SessionLockManager.js';
|
|
31
31
|
import { replaySession } from './ReplayEngine.js';
|
|
32
32
|
import { RESUME_NO_SESSIONS_FOUND } from './resumeNotFoundMessages.js';
|
|
33
|
+
import type { LocalMediaStore } from '../storage/local-media-store.js';
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Sentinel constant for "resume most recent session".
|
|
@@ -48,6 +49,8 @@ export interface ResumeRequest {
|
|
|
48
49
|
currentProvider: string;
|
|
49
50
|
currentModel: string;
|
|
50
51
|
workspaceDirs: string[];
|
|
52
|
+
mediaStore?: LocalMediaStore;
|
|
53
|
+
maxQueueBytes?: number;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -118,6 +121,12 @@ function initializeRecordingForResume(
|
|
|
118
121
|
workspaceDirs: request.workspaceDirs,
|
|
119
122
|
provider: request.currentProvider,
|
|
120
123
|
model: request.currentModel,
|
|
124
|
+
...(request.mediaStore === undefined
|
|
125
|
+
? {}
|
|
126
|
+
: { mediaStore: request.mediaStore }),
|
|
127
|
+
...(request.maxQueueBytes === undefined
|
|
128
|
+
? {}
|
|
129
|
+
: { maxQueueBytes: request.maxQueueBytes }),
|
|
121
130
|
});
|
|
122
131
|
recording.initializeForResume(
|
|
123
132
|
lockedSession.targetFilePath,
|
|
@@ -191,6 +200,7 @@ export async function resumeSession(
|
|
|
191
200
|
const replayResult = await replaySession(
|
|
192
201
|
lockedSession.targetFilePath,
|
|
193
202
|
request.projectHash,
|
|
203
|
+
{ mediaStore: request.mediaStore },
|
|
194
204
|
);
|
|
195
205
|
if (!replayResult.ok) {
|
|
196
206
|
await lockedSession.lockHandle.release();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { IContent } from '../services/history/IContent.js';
|
|
8
|
+
|
|
9
|
+
export function isSemanticMediaPurgeFrontierWithinHistory(
|
|
10
|
+
history: readonly IContent[],
|
|
11
|
+
frontier: { readonly contentIndex: number; readonly blockIndex: number },
|
|
12
|
+
): boolean {
|
|
13
|
+
if (history.length === 0) {
|
|
14
|
+
return frontier.contentIndex === 0 && frontier.blockIndex === 0;
|
|
15
|
+
}
|
|
16
|
+
const content = history.find(
|
|
17
|
+
(_entry, index) => index === frontier.contentIndex,
|
|
18
|
+
);
|
|
19
|
+
return content !== undefined && frontier.blockIndex < content.blocks.length;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isNonNegativeInteger(value: unknown): value is number {
|
|
23
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isRecordWithNonNegativeIntegerPair(
|
|
27
|
+
value: unknown,
|
|
28
|
+
): value is { readonly contentIndex: number; readonly blockIndex: number } {
|
|
29
|
+
if (typeof value !== 'object' || value === null) return false;
|
|
30
|
+
if (!('contentIndex' in value) || !('blockIndex' in value)) return false;
|
|
31
|
+
return (
|
|
32
|
+
isNonNegativeInteger(value.contentIndex) &&
|
|
33
|
+
isNonNegativeInteger(value.blockIndex)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createHash, type Hash } from 'node:crypto';
|
|
8
|
+
import { open } from 'node:fs/promises';
|
|
9
|
+
import type { MediaStoredObject } from '../services/history/IContent.js';
|
|
10
|
+
import {
|
|
11
|
+
HASH_CHUNK_BYTES,
|
|
12
|
+
MAX_OBJECT_BYTES,
|
|
13
|
+
boundedFileSize,
|
|
14
|
+
packageBlobPath,
|
|
15
|
+
type VerifiedPackageBlob,
|
|
16
|
+
} from './session-media-package-validation.js';
|
|
17
|
+
function appendVerifiedChunk(
|
|
18
|
+
hash: Hash,
|
|
19
|
+
buffer: Buffer,
|
|
20
|
+
bytesRead: number,
|
|
21
|
+
bytesReadTotal: number,
|
|
22
|
+
expectedByteLength: number,
|
|
23
|
+
): number {
|
|
24
|
+
const nextTotal = bytesReadTotal + bytesRead;
|
|
25
|
+
if (nextTotal > expectedByteLength) {
|
|
26
|
+
throw new Error('Session media package blob grew during verification');
|
|
27
|
+
}
|
|
28
|
+
hash.update(buffer.subarray(0, bytesRead));
|
|
29
|
+
return nextTotal;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function verifyPackageBlob(
|
|
33
|
+
sourcePath: string,
|
|
34
|
+
object: MediaStoredObject,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const handle = await open(sourcePath, 'r');
|
|
37
|
+
const hash = createHash('sha256');
|
|
38
|
+
const buffer = Buffer.allocUnsafe(HASH_CHUNK_BYTES);
|
|
39
|
+
let bytesReadTotal = 0;
|
|
40
|
+
let reading = true;
|
|
41
|
+
let failure: unknown;
|
|
42
|
+
try {
|
|
43
|
+
while (reading) {
|
|
44
|
+
const { bytesRead } = await handle.read(
|
|
45
|
+
buffer,
|
|
46
|
+
0,
|
|
47
|
+
buffer.byteLength,
|
|
48
|
+
null,
|
|
49
|
+
);
|
|
50
|
+
reading = bytesRead !== 0;
|
|
51
|
+
if (reading) {
|
|
52
|
+
bytesReadTotal = appendVerifiedChunk(
|
|
53
|
+
hash,
|
|
54
|
+
buffer,
|
|
55
|
+
bytesRead,
|
|
56
|
+
bytesReadTotal,
|
|
57
|
+
object.byteLength,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const contentId = `sha256:${hash.digest('hex')}`;
|
|
62
|
+
if (
|
|
63
|
+
contentId !== object.contentId ||
|
|
64
|
+
bytesReadTotal !== object.byteLength
|
|
65
|
+
) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Session media package blob is corrupt [contentId=${object.contentId}]`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
failure = error;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await handle.close();
|
|
75
|
+
} catch (closeError) {
|
|
76
|
+
failure =
|
|
77
|
+
failure === undefined
|
|
78
|
+
? closeError
|
|
79
|
+
: new AggregateError(
|
|
80
|
+
[failure, closeError],
|
|
81
|
+
'Session media package blob verification and file close failed',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (failure !== undefined) throw failure;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function verifyPackageBlobs(
|
|
88
|
+
packageDirectory: string,
|
|
89
|
+
objects: readonly MediaStoredObject[],
|
|
90
|
+
): Promise<readonly VerifiedPackageBlob[]> {
|
|
91
|
+
const verified: VerifiedPackageBlob[] = [];
|
|
92
|
+
for (const object of objects) {
|
|
93
|
+
const sourcePath = packageBlobPath(packageDirectory, object.contentId);
|
|
94
|
+
let fileSize: number;
|
|
95
|
+
try {
|
|
96
|
+
fileSize = await boundedFileSize(
|
|
97
|
+
sourcePath,
|
|
98
|
+
MAX_OBJECT_BYTES,
|
|
99
|
+
'Session media package blob',
|
|
100
|
+
);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Session media package blob is missing or exceeds limits [contentId=${object.contentId}]`,
|
|
104
|
+
{ cause: error },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (fileSize !== object.byteLength) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Session media package blob size differs from declared metadata [contentId=${object.contentId}]`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
await verifyPackageBlob(sourcePath, object);
|
|
113
|
+
verified.push({ object, sourcePath });
|
|
114
|
+
}
|
|
115
|
+
return verified;
|
|
116
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { mkdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import type { LocalMediaStore } from '../storage/local-media-store.js';
|
|
11
|
+
import { pathExists } from './session-media-package-validation.js';
|
|
12
|
+
|
|
13
|
+
export interface ImportPublication {
|
|
14
|
+
readonly destinationChatsDirectory: string;
|
|
15
|
+
readonly recordingPath: string;
|
|
16
|
+
readonly recordingBytes: Uint8Array;
|
|
17
|
+
readonly persistedStates: ReadonlyArray<{
|
|
18
|
+
readonly fileName: string;
|
|
19
|
+
readonly serialized: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PublishedImportedSession {
|
|
24
|
+
rollback(): Promise<readonly unknown[]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ImportReservation {
|
|
28
|
+
readonly contentId: string;
|
|
29
|
+
readonly ownerId: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function rollbackImportedFiles(
|
|
33
|
+
published: readonly string[],
|
|
34
|
+
destinationChatsDirectory: string,
|
|
35
|
+
removeDestinationDirectory: boolean,
|
|
36
|
+
): Promise<readonly unknown[]> {
|
|
37
|
+
const failures: unknown[] = [];
|
|
38
|
+
for (let index = published.length - 1; index >= 0; index -= 1) {
|
|
39
|
+
try {
|
|
40
|
+
await rm(published[index], { force: true });
|
|
41
|
+
} catch (error) {
|
|
42
|
+
failures.push(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (removeDestinationDirectory) {
|
|
46
|
+
try {
|
|
47
|
+
await rmdir(destinationChatsDirectory);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
failures.push(error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return failures;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function publishImportedSession(
|
|
56
|
+
input: ImportPublication,
|
|
57
|
+
): Promise<PublishedImportedSession> {
|
|
58
|
+
const destinationExisted = await pathExists(input.destinationChatsDirectory);
|
|
59
|
+
const stagingDirectory = join(
|
|
60
|
+
input.destinationChatsDirectory,
|
|
61
|
+
`.session-import-${randomUUID()}`,
|
|
62
|
+
);
|
|
63
|
+
const published: string[] = [];
|
|
64
|
+
try {
|
|
65
|
+
await mkdir(input.destinationChatsDirectory, {
|
|
66
|
+
recursive: true,
|
|
67
|
+
mode: 0o700,
|
|
68
|
+
});
|
|
69
|
+
await mkdir(stagingDirectory, { mode: 0o700 });
|
|
70
|
+
const stagedRecording = join(stagingDirectory, 'recording.jsonl');
|
|
71
|
+
await writeFile(stagedRecording, input.recordingBytes, {
|
|
72
|
+
mode: 0o600,
|
|
73
|
+
flag: 'wx',
|
|
74
|
+
});
|
|
75
|
+
for (const state of input.persistedStates) {
|
|
76
|
+
await writeFile(
|
|
77
|
+
join(stagingDirectory, state.fileName),
|
|
78
|
+
state.serialized,
|
|
79
|
+
{ mode: 0o600, flag: 'wx' },
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
await rename(stagedRecording, input.recordingPath);
|
|
83
|
+
published.push(input.recordingPath);
|
|
84
|
+
for (const state of input.persistedStates) {
|
|
85
|
+
const destination = join(input.destinationChatsDirectory, state.fileName);
|
|
86
|
+
await rename(join(stagingDirectory, state.fileName), destination);
|
|
87
|
+
published.push(destination);
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const rollbackFailures = [
|
|
91
|
+
...(await rollbackImportedFiles(
|
|
92
|
+
published,
|
|
93
|
+
input.destinationChatsDirectory,
|
|
94
|
+
!destinationExisted,
|
|
95
|
+
)),
|
|
96
|
+
];
|
|
97
|
+
try {
|
|
98
|
+
await rm(stagingDirectory, { recursive: true, force: true });
|
|
99
|
+
} catch (cleanupError) {
|
|
100
|
+
rollbackFailures.push(cleanupError);
|
|
101
|
+
}
|
|
102
|
+
if (rollbackFailures.length > 0) {
|
|
103
|
+
throw new AggregateError(
|
|
104
|
+
[error, ...rollbackFailures],
|
|
105
|
+
'Session import publication and rollback failed',
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
await rm(stagingDirectory, { recursive: true, force: true });
|
|
113
|
+
} catch (error) {
|
|
114
|
+
const rollbackFailures = await rollbackImportedFiles(
|
|
115
|
+
published,
|
|
116
|
+
input.destinationChatsDirectory,
|
|
117
|
+
!destinationExisted,
|
|
118
|
+
);
|
|
119
|
+
throw new AggregateError(
|
|
120
|
+
[error, ...rollbackFailures],
|
|
121
|
+
'Session import staging cleanup failed',
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
rollback: () =>
|
|
127
|
+
rollbackImportedFiles(
|
|
128
|
+
published,
|
|
129
|
+
input.destinationChatsDirectory,
|
|
130
|
+
!destinationExisted,
|
|
131
|
+
),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function assertImportReservationsReleased(
|
|
136
|
+
failures: readonly unknown[],
|
|
137
|
+
): void {
|
|
138
|
+
if (failures.length > 0) {
|
|
139
|
+
throw new AggregateError(failures, 'Session import owner release failed');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function releaseImportReservations(
|
|
144
|
+
mediaStore: LocalMediaStore,
|
|
145
|
+
reservations: ImportReservation[],
|
|
146
|
+
): Promise<readonly unknown[]> {
|
|
147
|
+
const failures: unknown[] = [];
|
|
148
|
+
for (let index = reservations.length - 1; index >= 0; index -= 1) {
|
|
149
|
+
const reservation = reservations[index];
|
|
150
|
+
try {
|
|
151
|
+
await mediaStore.release(reservation.contentId, reservation.ownerId);
|
|
152
|
+
reservations.splice(index, 1);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
failures.push(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return failures;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export async function rollbackImport(
|
|
161
|
+
error: unknown,
|
|
162
|
+
published: PublishedImportedSession | undefined,
|
|
163
|
+
stagedMedia: Awaited<ReturnType<LocalMediaStore['stageObjectFiles']>>,
|
|
164
|
+
mediaStore: LocalMediaStore,
|
|
165
|
+
reservations: ImportReservation[],
|
|
166
|
+
): Promise<never> {
|
|
167
|
+
const failures: unknown[] = [
|
|
168
|
+
...(await releaseImportReservations(mediaStore, reservations)),
|
|
169
|
+
];
|
|
170
|
+
if (published !== undefined) {
|
|
171
|
+
try {
|
|
172
|
+
failures.push(...(await published.rollback()));
|
|
173
|
+
} catch (rollbackError) {
|
|
174
|
+
failures.push(rollbackError);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
await stagedMedia.rollback();
|
|
179
|
+
} catch (rollbackError) {
|
|
180
|
+
failures.push(rollbackError);
|
|
181
|
+
}
|
|
182
|
+
if (failures.length > 0) {
|
|
183
|
+
throw new AggregateError(
|
|
184
|
+
[error, ...failures],
|
|
185
|
+
'Session import and rollback both failed',
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import type {
|
|
9
|
+
IContent,
|
|
10
|
+
MediaReferenceBlock,
|
|
11
|
+
} from '../services/history/IContent.js';
|
|
12
|
+
import {
|
|
13
|
+
MAX_HISTORY_CONTENTS,
|
|
14
|
+
MAX_PERSISTED_STATE_AGGREGATE_BYTES,
|
|
15
|
+
MAX_PERSISTED_STATE_BYTES,
|
|
16
|
+
PERSISTED_SESSION_PREFIX,
|
|
17
|
+
boundedAggregate,
|
|
18
|
+
boundedFileSize,
|
|
19
|
+
hasSameObjectMetadata,
|
|
20
|
+
isContent,
|
|
21
|
+
isRecord,
|
|
22
|
+
readBoundedFile,
|
|
23
|
+
type PackagedPersistedState,
|
|
24
|
+
} from './session-media-package-validation.js';
|
|
25
|
+
|
|
26
|
+
export interface CapturedPersistedState {
|
|
27
|
+
readonly definition: PackagedPersistedState;
|
|
28
|
+
readonly serialized: string;
|
|
29
|
+
readonly record: Readonly<Record<string, unknown>>;
|
|
30
|
+
readonly history: readonly IContent[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function capturePersistedStates(
|
|
34
|
+
packageDirectory: string,
|
|
35
|
+
states: readonly PackagedPersistedState[],
|
|
36
|
+
): Promise<readonly CapturedPersistedState[]> {
|
|
37
|
+
const paths = states.map((definition) =>
|
|
38
|
+
join(packageDirectory, definition.file),
|
|
39
|
+
);
|
|
40
|
+
const sizes: number[] = [];
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
sizes.push(
|
|
43
|
+
await boundedFileSize(
|
|
44
|
+
path,
|
|
45
|
+
MAX_PERSISTED_STATE_BYTES,
|
|
46
|
+
'Packaged persisted session state',
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
boundedAggregate(
|
|
51
|
+
sizes,
|
|
52
|
+
MAX_PERSISTED_STATE_AGGREGATE_BYTES,
|
|
53
|
+
'Packaged persisted session states',
|
|
54
|
+
);
|
|
55
|
+
const captured: CapturedPersistedState[] = [];
|
|
56
|
+
for (let index = 0; index < states.length; index += 1) {
|
|
57
|
+
const definition = states[index];
|
|
58
|
+
const path = paths[index];
|
|
59
|
+
const serialized = (
|
|
60
|
+
await readBoundedFile(
|
|
61
|
+
path,
|
|
62
|
+
MAX_PERSISTED_STATE_BYTES,
|
|
63
|
+
'Packaged persisted session state',
|
|
64
|
+
)
|
|
65
|
+
).toString('utf8');
|
|
66
|
+
const parsed: unknown = JSON.parse(serialized);
|
|
67
|
+
if (!isRecord(parsed)) {
|
|
68
|
+
throw new Error('Invalid packaged persisted session state');
|
|
69
|
+
}
|
|
70
|
+
const history = parsed['history'];
|
|
71
|
+
if (
|
|
72
|
+
parsed['version'] !== definition.version ||
|
|
73
|
+
!Array.isArray(history) ||
|
|
74
|
+
!history.every(isContent) ||
|
|
75
|
+
history.length > MAX_HISTORY_CONTENTS
|
|
76
|
+
) {
|
|
77
|
+
throw new Error('Invalid packaged persisted session state');
|
|
78
|
+
}
|
|
79
|
+
captured.push({ definition, serialized, record: parsed, history });
|
|
80
|
+
}
|
|
81
|
+
return captured;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function rewrittenPersistedStates(
|
|
85
|
+
states: readonly CapturedPersistedState[],
|
|
86
|
+
projectHash: string,
|
|
87
|
+
sessionId: string,
|
|
88
|
+
): ReadonlyArray<{ fileName: string; serialized: string }> {
|
|
89
|
+
return states.map((state, index) => ({
|
|
90
|
+
fileName: `${PERSISTED_SESSION_PREFIX}imported-${sessionId}-${index}.json`,
|
|
91
|
+
serialized: JSON.stringify({ ...state.record, projectHash, sessionId }),
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function verifyHistoryReferences(
|
|
96
|
+
source: string,
|
|
97
|
+
historyReferences: readonly MediaReferenceBlock[],
|
|
98
|
+
manifestReferences: readonly MediaReferenceBlock[],
|
|
99
|
+
): void {
|
|
100
|
+
const manifestById = new Map(
|
|
101
|
+
manifestReferences.map((reference) => [reference.contentId, reference]),
|
|
102
|
+
);
|
|
103
|
+
for (const reference of historyReferences) {
|
|
104
|
+
const expected = manifestById.get(reference.contentId);
|
|
105
|
+
if (expected === undefined) {
|
|
106
|
+
throw new Error(`Packaged ${source} references undeclared media`);
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
reference.originalContentId !== expected.originalContentId ||
|
|
110
|
+
reference.selectedContentId !== expected.selectedContentId ||
|
|
111
|
+
!hasSameObjectMetadata(
|
|
112
|
+
reference.originalObject,
|
|
113
|
+
expected.originalObject,
|
|
114
|
+
) ||
|
|
115
|
+
!hasSameObjectMetadata(reference.selectedObject, expected.selectedObject)
|
|
116
|
+
) {
|
|
117
|
+
throw new Error(`Packaged ${source} reference metadata is invalid`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|