@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,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Stats } from 'node:fs';
|
|
8
|
+
import { open, stat } from 'node:fs/promises';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import {
|
|
11
|
+
isMediaReferenceBlock,
|
|
12
|
+
type IContent,
|
|
13
|
+
type MediaReferenceBlock,
|
|
14
|
+
type MediaStoredObject,
|
|
15
|
+
} from '../services/history/IContent.js';
|
|
16
|
+
|
|
17
|
+
export const PACKAGE_VERSION = 2;
|
|
18
|
+
const SUPPORTED_RECORDING_VERSIONS = new Set([1, 2]);
|
|
19
|
+
export const SUPPORTED_PERSISTED_SESSION_VERSION = 1;
|
|
20
|
+
export const RECORDING_FILE = 'session.jsonl';
|
|
21
|
+
export const MANIFEST_FILE = 'manifest.json';
|
|
22
|
+
const CONTENT_ID_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
23
|
+
const MIME_TYPE_PATTERN =
|
|
24
|
+
/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
25
|
+
export const PERSISTED_SESSION_PREFIX = 'persisted-session-';
|
|
26
|
+
export const HASH_CHUNK_BYTES = 64 * 1024;
|
|
27
|
+
export const MAX_MANIFEST_BYTES = 8 * 1024 * 1024;
|
|
28
|
+
export const MAX_RECORDING_BYTES = 256 * 1024 * 1024;
|
|
29
|
+
export const MAX_PERSISTED_STATES = 256;
|
|
30
|
+
export const MAX_PERSISTED_STATE_BYTES = 64 * 1024 * 1024;
|
|
31
|
+
export const MAX_PERSISTED_STATE_AGGREGATE_BYTES = 256 * 1024 * 1024;
|
|
32
|
+
const MAX_REFERENCES = 10_000;
|
|
33
|
+
const MAX_OBJECTS = 20_000;
|
|
34
|
+
export const MAX_OBJECT_BYTES = 256 * 1024 * 1024;
|
|
35
|
+
export const MAX_OBJECT_AGGREGATE_BYTES = 2 * 1024 * 1024 * 1024;
|
|
36
|
+
export const MAX_HISTORY_CONTENTS = 100_000;
|
|
37
|
+
|
|
38
|
+
export interface PackagedPersistedState {
|
|
39
|
+
readonly file: string;
|
|
40
|
+
readonly version: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface MediaPackageManifest {
|
|
44
|
+
readonly version: number;
|
|
45
|
+
readonly recording: string;
|
|
46
|
+
readonly persistedStates: readonly PackagedPersistedState[];
|
|
47
|
+
readonly references: readonly MediaReferenceBlock[];
|
|
48
|
+
readonly objects: readonly MediaStoredObject[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface VerifiedPackageBlob {
|
|
52
|
+
readonly object: MediaStoredObject;
|
|
53
|
+
readonly sourcePath: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface PortableRecording {
|
|
57
|
+
readonly bytes: Uint8Array;
|
|
58
|
+
readonly sessionId: string;
|
|
59
|
+
readonly histories: readonly IContent[][];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PortablePersistedState {
|
|
63
|
+
readonly file: string;
|
|
64
|
+
readonly serialized: string;
|
|
65
|
+
readonly history: readonly IContent[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function packageBlobPath(root: string, contentId: string): string {
|
|
69
|
+
return join(root, 'blobs', 'sha256', contentId.slice('sha256:'.length));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
73
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function pathExists(path: string): Promise<boolean> {
|
|
77
|
+
try {
|
|
78
|
+
await stat(path);
|
|
79
|
+
return true;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (isRecord(error) && error['code'] === 'ENOENT') return false;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function boundedFileSize(
|
|
87
|
+
path: string,
|
|
88
|
+
maxBytes: number,
|
|
89
|
+
label: string,
|
|
90
|
+
): Promise<number> {
|
|
91
|
+
const fileStat = await stat(path);
|
|
92
|
+
if (!fileStat.isFile() || fileStat.size > maxBytes) {
|
|
93
|
+
throw new Error(`${label} exceeds finite byte limit`);
|
|
94
|
+
}
|
|
95
|
+
return fileStat.size;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function boundedReadChanged(
|
|
99
|
+
before: Stats,
|
|
100
|
+
after: Stats,
|
|
101
|
+
current: Stats,
|
|
102
|
+
total: number,
|
|
103
|
+
): boolean {
|
|
104
|
+
if (before.dev !== after.dev || before.ino !== after.ino) return true;
|
|
105
|
+
if (before.size !== total || after.size !== total) return true;
|
|
106
|
+
if (before.mtimeMs !== after.mtimeMs) return true;
|
|
107
|
+
if (before.ctimeMs !== after.ctimeMs) return true;
|
|
108
|
+
return current.dev !== after.dev || current.ino !== after.ino;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function readBoundedFile(
|
|
112
|
+
path: string,
|
|
113
|
+
maxBytes: number,
|
|
114
|
+
label: string,
|
|
115
|
+
): Promise<Buffer> {
|
|
116
|
+
const handle = await open(path, 'r');
|
|
117
|
+
const chunks: Buffer[] = [];
|
|
118
|
+
let total = 0;
|
|
119
|
+
let result: Buffer | undefined;
|
|
120
|
+
let failure: unknown;
|
|
121
|
+
try {
|
|
122
|
+
const before = await handle.stat();
|
|
123
|
+
if (!before.isFile() || before.size > maxBytes) {
|
|
124
|
+
throw new Error(`${label} exceeds finite byte limit`);
|
|
125
|
+
}
|
|
126
|
+
while (total <= maxBytes) {
|
|
127
|
+
const remaining = maxBytes + 1 - total;
|
|
128
|
+
const chunk = Buffer.allocUnsafe(Math.min(HASH_CHUNK_BYTES, remaining));
|
|
129
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.byteLength, null);
|
|
130
|
+
if (bytesRead === 0) break;
|
|
131
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
132
|
+
total += bytesRead;
|
|
133
|
+
}
|
|
134
|
+
const [after, current] = await Promise.all([handle.stat(), stat(path)]);
|
|
135
|
+
if (total > maxBytes) {
|
|
136
|
+
throw new Error(`${label} exceeds finite byte limit`);
|
|
137
|
+
}
|
|
138
|
+
if (boundedReadChanged(before, after, current, total)) {
|
|
139
|
+
throw new Error(`${label} changed during bounded read`);
|
|
140
|
+
}
|
|
141
|
+
result = Buffer.concat(chunks, total);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
failure = error;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
await handle.close();
|
|
147
|
+
} catch (closeError) {
|
|
148
|
+
failure =
|
|
149
|
+
failure === undefined
|
|
150
|
+
? closeError
|
|
151
|
+
: new AggregateError(
|
|
152
|
+
[failure, closeError],
|
|
153
|
+
`${label} read and file close failed`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (failure !== undefined) throw failure;
|
|
157
|
+
if (result === undefined) throw new Error(`${label} bounded read failed`);
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function boundedAggregate(
|
|
162
|
+
values: readonly number[],
|
|
163
|
+
maxBytes: number,
|
|
164
|
+
label: string,
|
|
165
|
+
): number {
|
|
166
|
+
let total = 0;
|
|
167
|
+
for (const value of values) {
|
|
168
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > maxBytes - total) {
|
|
169
|
+
throw new Error(`${label} exceeds finite aggregate byte limit`);
|
|
170
|
+
}
|
|
171
|
+
total += value;
|
|
172
|
+
}
|
|
173
|
+
return total;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function isPositiveInteger(value: unknown): value is number {
|
|
177
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isDimensions(value: unknown): boolean {
|
|
181
|
+
return (
|
|
182
|
+
isRecord(value) &&
|
|
183
|
+
Object.keys(value).length === 2 &&
|
|
184
|
+
isPositiveInteger(value['width']) &&
|
|
185
|
+
isPositiveInteger(value['height'])
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function isStoredObject(value: unknown): value is MediaStoredObject {
|
|
190
|
+
if (!isRecord(value)) return false;
|
|
191
|
+
const contentId = value['contentId'];
|
|
192
|
+
if (typeof contentId !== 'string' || !CONTENT_ID_PATTERN.test(contentId)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const mimeType = value['mimeType'];
|
|
196
|
+
if (typeof mimeType !== 'string' || !MIME_TYPE_PATTERN.test(mimeType)) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
const byteLength = value['byteLength'];
|
|
200
|
+
if (!isPositiveInteger(byteLength)) return false;
|
|
201
|
+
if (value['normalizedBase64Length'] !== Math.ceil(byteLength / 3) * 4) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
return value['dimensions'] === undefined || isDimensions(value['dimensions']);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isPackagedPersistedState(
|
|
208
|
+
value: unknown,
|
|
209
|
+
): value is PackagedPersistedState {
|
|
210
|
+
return (
|
|
211
|
+
isRecord(value) &&
|
|
212
|
+
typeof value['file'] === 'string' &&
|
|
213
|
+
/^state\/persisted-[0-9]+\.json$/.test(value['file']) &&
|
|
214
|
+
value['version'] === SUPPORTED_PERSISTED_SESSION_VERSION
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function parseManifest(serialized: string): MediaPackageManifest {
|
|
219
|
+
const parsed: unknown = JSON.parse(serialized);
|
|
220
|
+
if (!isRecord(parsed)) {
|
|
221
|
+
throw new Error('Invalid session media package manifest');
|
|
222
|
+
}
|
|
223
|
+
if (parsed['version'] !== PACKAGE_VERSION) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`Unsupported session media package version ${String(parsed['version'])}`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (parsed['recording'] !== RECORDING_FILE) {
|
|
229
|
+
throw new Error('Invalid session media package manifest');
|
|
230
|
+
}
|
|
231
|
+
const references = parsed['references'];
|
|
232
|
+
const objects = parsed['objects'];
|
|
233
|
+
const persistedStates = parsed['persistedStates'];
|
|
234
|
+
if (!Array.isArray(references) || !references.every(isMediaReferenceBlock)) {
|
|
235
|
+
throw new Error('Invalid session media package manifest');
|
|
236
|
+
}
|
|
237
|
+
if (!Array.isArray(objects) || !objects.every(isStoredObject)) {
|
|
238
|
+
throw new Error('Invalid session media package manifest');
|
|
239
|
+
}
|
|
240
|
+
if (
|
|
241
|
+
!Array.isArray(persistedStates) ||
|
|
242
|
+
!persistedStates.every(isPackagedPersistedState)
|
|
243
|
+
) {
|
|
244
|
+
throw new Error('Invalid session media package manifest');
|
|
245
|
+
}
|
|
246
|
+
if (references.length > MAX_REFERENCES) {
|
|
247
|
+
throw new Error('Session media package reference count exceeds limit');
|
|
248
|
+
}
|
|
249
|
+
if (objects.length > MAX_OBJECTS) {
|
|
250
|
+
throw new Error('Session media package object count exceeds limit');
|
|
251
|
+
}
|
|
252
|
+
if (persistedStates.length > MAX_PERSISTED_STATES) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
'Session media package persisted state count exceeds limit',
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
version: PACKAGE_VERSION,
|
|
259
|
+
recording: RECORDING_FILE,
|
|
260
|
+
persistedStates,
|
|
261
|
+
references,
|
|
262
|
+
objects,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function hasSameDimensions(
|
|
267
|
+
first: MediaStoredObject['dimensions'],
|
|
268
|
+
second: MediaStoredObject['dimensions'],
|
|
269
|
+
): boolean {
|
|
270
|
+
if (first === undefined || second === undefined) return first === second;
|
|
271
|
+
return first.width === second.width && first.height === second.height;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function hasSameObjectMetadata(
|
|
275
|
+
first: MediaStoredObject,
|
|
276
|
+
second: MediaStoredObject,
|
|
277
|
+
): boolean {
|
|
278
|
+
return (
|
|
279
|
+
first.mimeType === second.mimeType &&
|
|
280
|
+
first.byteLength === second.byteLength &&
|
|
281
|
+
first.normalizedBase64Length === second.normalizedBase64Length &&
|
|
282
|
+
hasSameDimensions(first.dimensions, second.dimensions)
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function uniqueReferences(
|
|
287
|
+
references: readonly MediaReferenceBlock[],
|
|
288
|
+
): readonly MediaReferenceBlock[] {
|
|
289
|
+
const byContentId = new Map<string, MediaReferenceBlock>();
|
|
290
|
+
for (const reference of references) {
|
|
291
|
+
const existing = byContentId.get(reference.contentId);
|
|
292
|
+
if (
|
|
293
|
+
existing !== undefined &&
|
|
294
|
+
(existing.byteLength !== reference.byteLength ||
|
|
295
|
+
existing.mimeType !== reference.mimeType ||
|
|
296
|
+
existing.originalContentId !== reference.originalContentId)
|
|
297
|
+
) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
`Conflicting media reference metadata [contentId=${reference.contentId}]`,
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
byContentId.set(reference.contentId, reference);
|
|
303
|
+
}
|
|
304
|
+
return [...byContentId.values()];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function requiredObjects(
|
|
308
|
+
references: readonly MediaReferenceBlock[],
|
|
309
|
+
): readonly MediaStoredObject[] {
|
|
310
|
+
const byContentId = new Map<string, MediaStoredObject>();
|
|
311
|
+
for (const reference of references) {
|
|
312
|
+
for (const object of [reference.originalObject, reference.selectedObject]) {
|
|
313
|
+
const existing = byContentId.get(object.contentId);
|
|
314
|
+
if (existing !== undefined && !hasSameObjectMetadata(existing, object)) {
|
|
315
|
+
throw new Error(
|
|
316
|
+
`Conflicting media object metadata [contentId=${object.contentId}]`,
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
byContentId.set(object.contentId, object);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return [...byContentId.values()];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function verifyManifestObjectSet(
|
|
326
|
+
expected: readonly MediaStoredObject[],
|
|
327
|
+
packaged: readonly MediaStoredObject[],
|
|
328
|
+
): void {
|
|
329
|
+
const packagedById = new Map<string, MediaStoredObject>();
|
|
330
|
+
for (const object of packaged) {
|
|
331
|
+
if (packagedById.has(object.contentId)) {
|
|
332
|
+
throw new Error(
|
|
333
|
+
`Session media package contains duplicate object [contentId=${object.contentId}]`,
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
packagedById.set(object.contentId, object);
|
|
337
|
+
}
|
|
338
|
+
if (packagedById.size !== expected.length) {
|
|
339
|
+
throw new Error('Session media package object set is incomplete');
|
|
340
|
+
}
|
|
341
|
+
for (const object of expected) {
|
|
342
|
+
const packagedObject = packagedById.get(object.contentId);
|
|
343
|
+
if (
|
|
344
|
+
packagedObject === undefined ||
|
|
345
|
+
!hasSameObjectMetadata(packagedObject, object)
|
|
346
|
+
) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`Session media package object metadata is invalid [contentId=${object.contentId}]`,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function isContentSpeaker(value: unknown): boolean {
|
|
355
|
+
return value === 'human' || value === 'ai' || value === 'tool';
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function isContent(value: unknown): value is IContent {
|
|
359
|
+
return (
|
|
360
|
+
isRecord(value) &&
|
|
361
|
+
isContentSpeaker(value['speaker']) &&
|
|
362
|
+
Array.isArray(value['blocks'])
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function requireRecordingLine(value: unknown, lineNumber: number) {
|
|
367
|
+
if (!isRecord(value)) {
|
|
368
|
+
throw new Error(`Invalid recording line ${lineNumber}`);
|
|
369
|
+
}
|
|
370
|
+
const version = value['v'];
|
|
371
|
+
if (
|
|
372
|
+
typeof version !== 'number' ||
|
|
373
|
+
!SUPPORTED_RECORDING_VERSIONS.has(version)
|
|
374
|
+
) {
|
|
375
|
+
throw new Error(
|
|
376
|
+
`Unsupported recording version ${String(version)} at line ${lineNumber}`,
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
if (
|
|
380
|
+
!Number.isSafeInteger(value['seq']) ||
|
|
381
|
+
typeof value['type'] !== 'string' ||
|
|
382
|
+
!isRecord(value['payload'])
|
|
383
|
+
) {
|
|
384
|
+
throw new Error(`Invalid recording line ${lineNumber}`);
|
|
385
|
+
}
|
|
386
|
+
return value;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function requirePortableMediaContent(content: IContent): IContent {
|
|
390
|
+
for (const block of content.blocks) {
|
|
391
|
+
if (
|
|
392
|
+
block.type === 'media' &&
|
|
393
|
+
block.encoding !== 'reference' &&
|
|
394
|
+
block.encoding !== 'url'
|
|
395
|
+
) {
|
|
396
|
+
throw new Error('Packaged recording contains raw JSON media');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return content;
|
|
400
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { mkdir, open, rename, rm, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
import type {
|
|
10
|
+
MediaReferenceBlock,
|
|
11
|
+
MediaStoredObject,
|
|
12
|
+
} from '../services/history/IContent.js';
|
|
13
|
+
import type { LocalMediaStore } from '../storage/local-media-store.js';
|
|
14
|
+
import {
|
|
15
|
+
MANIFEST_FILE,
|
|
16
|
+
PACKAGE_VERSION,
|
|
17
|
+
RECORDING_FILE,
|
|
18
|
+
SUPPORTED_PERSISTED_SESSION_VERSION,
|
|
19
|
+
packageBlobPath,
|
|
20
|
+
pathExists,
|
|
21
|
+
type MediaPackageManifest,
|
|
22
|
+
type PortablePersistedState,
|
|
23
|
+
type PortableRecording,
|
|
24
|
+
} from './session-media-package-validation.js';
|
|
25
|
+
|
|
26
|
+
export interface SessionMediaPackageWriteInput {
|
|
27
|
+
readonly temporaryDirectory: string;
|
|
28
|
+
readonly mediaStore: LocalMediaStore;
|
|
29
|
+
readonly recording: PortableRecording;
|
|
30
|
+
readonly persistedStates: readonly PortablePersistedState[];
|
|
31
|
+
readonly references: readonly MediaReferenceBlock[];
|
|
32
|
+
readonly objects: readonly MediaStoredObject[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function stageSessionMediaPackage(
|
|
36
|
+
input: SessionMediaPackageWriteInput,
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
await mkdir(join(input.temporaryDirectory, 'blobs', 'sha256'), {
|
|
39
|
+
recursive: true,
|
|
40
|
+
mode: 0o700,
|
|
41
|
+
});
|
|
42
|
+
if (input.persistedStates.length > 0) {
|
|
43
|
+
await mkdir(join(input.temporaryDirectory, 'state'), {
|
|
44
|
+
recursive: true,
|
|
45
|
+
mode: 0o700,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
for (const object of input.objects) {
|
|
49
|
+
const bytes = await input.mediaStore.readObjectVerified(object);
|
|
50
|
+
await writeFile(
|
|
51
|
+
packageBlobPath(input.temporaryDirectory, object.contentId),
|
|
52
|
+
bytes,
|
|
53
|
+
{ mode: 0o600, flag: 'wx' },
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
await writeFile(
|
|
57
|
+
join(input.temporaryDirectory, RECORDING_FILE),
|
|
58
|
+
input.recording.bytes,
|
|
59
|
+
{ mode: 0o600, flag: 'wx' },
|
|
60
|
+
);
|
|
61
|
+
for (const state of input.persistedStates) {
|
|
62
|
+
await writeFile(
|
|
63
|
+
join(input.temporaryDirectory, state.file),
|
|
64
|
+
state.serialized,
|
|
65
|
+
{
|
|
66
|
+
mode: 0o600,
|
|
67
|
+
flag: 'wx',
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const manifest: MediaPackageManifest = {
|
|
72
|
+
version: PACKAGE_VERSION,
|
|
73
|
+
recording: RECORDING_FILE,
|
|
74
|
+
persistedStates: input.persistedStates.map((state) => ({
|
|
75
|
+
file: state.file,
|
|
76
|
+
version: SUPPORTED_PERSISTED_SESSION_VERSION,
|
|
77
|
+
})),
|
|
78
|
+
references: input.references,
|
|
79
|
+
objects: input.objects,
|
|
80
|
+
};
|
|
81
|
+
await writeFile(
|
|
82
|
+
join(input.temporaryDirectory, MANIFEST_FILE),
|
|
83
|
+
JSON.stringify(manifest, null, 2),
|
|
84
|
+
{ mode: 0o600, flag: 'wx' },
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function publishStagedSessionMediaPackage(
|
|
89
|
+
temporaryDirectory: string,
|
|
90
|
+
packageDirectory: string,
|
|
91
|
+
): Promise<void> {
|
|
92
|
+
await mkdir(dirname(packageDirectory), { recursive: true });
|
|
93
|
+
const claimPath = `${packageDirectory}.publish`;
|
|
94
|
+
const claim = await open(claimPath, 'wx', 0o600);
|
|
95
|
+
let failure: unknown;
|
|
96
|
+
try {
|
|
97
|
+
await claim.close();
|
|
98
|
+
if (await pathExists(packageDirectory)) {
|
|
99
|
+
throw new Error(`Session media package destination already exists`);
|
|
100
|
+
}
|
|
101
|
+
await rename(temporaryDirectory, packageDirectory);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
failure = error;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
await rm(claimPath, { force: true });
|
|
107
|
+
} catch (cleanupError) {
|
|
108
|
+
failure =
|
|
109
|
+
failure === undefined
|
|
110
|
+
? cleanupError
|
|
111
|
+
: new AggregateError(
|
|
112
|
+
[failure, cleanupError],
|
|
113
|
+
'Session media package publication and claim cleanup failed',
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (failure !== undefined) throw failure;
|
|
117
|
+
}
|