@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,696 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isMediaReferenceBlock } from '../services/history/IContent.js';
|
|
8
|
+
import type {
|
|
9
|
+
MediaReferenceBlock,
|
|
10
|
+
MediaSemanticMetadata,
|
|
11
|
+
MediaStoredObject,
|
|
12
|
+
} from '../services/history/IContent.js';
|
|
13
|
+
import { LocalMediaStorePersistence } from './local-media-store-persistence.js';
|
|
14
|
+
import {
|
|
15
|
+
MediaObjectCorruptError,
|
|
16
|
+
MediaObjectHashMismatchError,
|
|
17
|
+
MediaStoreError,
|
|
18
|
+
type LocalMediaStoreOptions,
|
|
19
|
+
type MediaAdmissionInput,
|
|
20
|
+
type MediaKnownAdmissionInput,
|
|
21
|
+
type MediaReclamationResult,
|
|
22
|
+
type MediaStoredObjectAdmission,
|
|
23
|
+
type MediaStoredObjectFileAdmission,
|
|
24
|
+
type PreparedAdmission,
|
|
25
|
+
type PublishedMediaObjectPath,
|
|
26
|
+
type StagedMediaObjectAdmission,
|
|
27
|
+
} from './local-media-store-types.js';
|
|
28
|
+
import {
|
|
29
|
+
buildIdentityReference,
|
|
30
|
+
buildReference,
|
|
31
|
+
buildStoredObject,
|
|
32
|
+
contentIdFor,
|
|
33
|
+
isPositiveSafeInteger,
|
|
34
|
+
prepareAdmission,
|
|
35
|
+
uniqueStoredObjects,
|
|
36
|
+
validateContentId,
|
|
37
|
+
validatedProviderFileIds,
|
|
38
|
+
validatedSemanticMetadata,
|
|
39
|
+
validateStoredObjectMetadata,
|
|
40
|
+
} from './local-media-store-validation.js';
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
MediaObjectCorruptError,
|
|
44
|
+
MediaObjectHashMismatchError,
|
|
45
|
+
MediaObjectMissingError,
|
|
46
|
+
MediaStoreError,
|
|
47
|
+
} from './local-media-store-types.js';
|
|
48
|
+
export type {
|
|
49
|
+
LocalMediaStoreFileOperations,
|
|
50
|
+
LocalMediaStoreOptions,
|
|
51
|
+
MediaAdmissionInput,
|
|
52
|
+
MediaKnownAdmissionInput,
|
|
53
|
+
MediaObjectAdmissionInput,
|
|
54
|
+
MediaReclamationResult,
|
|
55
|
+
MediaStoredObjectAdmission,
|
|
56
|
+
MediaStoredObjectFileAdmission,
|
|
57
|
+
MediaTransformationInput,
|
|
58
|
+
} from './local-media-store-types.js';
|
|
59
|
+
|
|
60
|
+
interface StoredObjectWithBytes {
|
|
61
|
+
readonly object: MediaStoredObject;
|
|
62
|
+
readonly bytes: Uint8Array;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface StoredObjectWithFile {
|
|
66
|
+
readonly object: MediaStoredObject;
|
|
67
|
+
readonly sourcePath: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function storedObjectMetadataMatches(
|
|
71
|
+
left: MediaStoredObject,
|
|
72
|
+
right: MediaStoredObject,
|
|
73
|
+
): boolean {
|
|
74
|
+
return (
|
|
75
|
+
left.mimeType === right.mimeType &&
|
|
76
|
+
left.byteLength === right.byteLength &&
|
|
77
|
+
left.dimensions?.width === right.dimensions?.width &&
|
|
78
|
+
left.dimensions?.height === right.dimensions?.height
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class LocalMediaStore {
|
|
83
|
+
readonly rootDirectory: string;
|
|
84
|
+
readonly quotaBytes: number;
|
|
85
|
+
private readonly persistence: LocalMediaStorePersistence;
|
|
86
|
+
|
|
87
|
+
constructor(options: LocalMediaStoreOptions) {
|
|
88
|
+
this.persistence = new LocalMediaStorePersistence(options);
|
|
89
|
+
this.rootDirectory = this.persistence.rootDirectory;
|
|
90
|
+
this.quotaBytes = this.persistence.quotaBytes;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async close(): Promise<void> {
|
|
94
|
+
await this.persistence.close();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async admit(input: MediaAdmissionInput): Promise<MediaReferenceBlock> {
|
|
98
|
+
const selectedBytes = new Uint8Array(input.bytes);
|
|
99
|
+
const originalBytes =
|
|
100
|
+
input.original === undefined
|
|
101
|
+
? selectedBytes
|
|
102
|
+
: new Uint8Array(input.original.bytes);
|
|
103
|
+
return this.persistence.runExclusive(
|
|
104
|
+
'admit object',
|
|
105
|
+
undefined,
|
|
106
|
+
async () => {
|
|
107
|
+
const prepared = prepareAdmission(input, selectedBytes, originalBytes);
|
|
108
|
+
await this.admitPreparedUnlocked(prepared);
|
|
109
|
+
return buildReference(prepared);
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async preflightObjects(objects: readonly MediaStoredObject[]): Promise<void> {
|
|
115
|
+
await this.persistence.runExclusive(
|
|
116
|
+
'preflight object batch',
|
|
117
|
+
undefined,
|
|
118
|
+
async () => {
|
|
119
|
+
const unique = uniqueStoredObjects(objects);
|
|
120
|
+
const additionalBytes = await this.measureMissingObjects(unique);
|
|
121
|
+
if (!Number.isSafeInteger(additionalBytes)) {
|
|
122
|
+
throw new MediaStoreError(
|
|
123
|
+
'preflight object batch',
|
|
124
|
+
undefined,
|
|
125
|
+
new Error('Object batch byte length exceeds safe integer range'),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
129
|
+
this.persistence.enforceQuota(storedBytes, additionalBytes, 'batch');
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async admitObjects(
|
|
135
|
+
admissions: readonly MediaStoredObjectAdmission[],
|
|
136
|
+
): Promise<void> {
|
|
137
|
+
await this.admitObjectsTransaction(admissions, () => Promise.resolve());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async stageObjects(
|
|
141
|
+
admissions: readonly MediaStoredObjectAdmission[],
|
|
142
|
+
): Promise<StagedMediaObjectAdmission> {
|
|
143
|
+
const copied = admissions.map((admission) => ({
|
|
144
|
+
object: admission.object,
|
|
145
|
+
bytes: new Uint8Array(admission.bytes),
|
|
146
|
+
}));
|
|
147
|
+
const published = await this.persistence.runExclusive(
|
|
148
|
+
'stage object batch',
|
|
149
|
+
undefined,
|
|
150
|
+
() => this.stageObjectBatchUnlocked(copied),
|
|
151
|
+
);
|
|
152
|
+
let pending = true;
|
|
153
|
+
return {
|
|
154
|
+
createdContentIds: published.map((entry) => entry.contentId),
|
|
155
|
+
commit(): void {
|
|
156
|
+
pending = false;
|
|
157
|
+
},
|
|
158
|
+
rollback: async (): Promise<void> => {
|
|
159
|
+
if (!pending) return;
|
|
160
|
+
await this.persistence.rollbackStagedObjects(published);
|
|
161
|
+
pending = false;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async stageObjectFiles(
|
|
167
|
+
admissions: readonly MediaStoredObjectFileAdmission[],
|
|
168
|
+
): Promise<StagedMediaObjectAdmission> {
|
|
169
|
+
const published = await this.persistence.runExclusive(
|
|
170
|
+
'stage object file batch',
|
|
171
|
+
undefined,
|
|
172
|
+
() => this.stageObjectFileBatchUnlocked(admissions),
|
|
173
|
+
);
|
|
174
|
+
let pending = true;
|
|
175
|
+
return {
|
|
176
|
+
createdContentIds: published.map((entry) => entry.contentId),
|
|
177
|
+
commit(): void {
|
|
178
|
+
pending = false;
|
|
179
|
+
},
|
|
180
|
+
rollback: async (): Promise<void> => {
|
|
181
|
+
if (!pending) return;
|
|
182
|
+
await this.persistence.rollbackStagedObjects(published);
|
|
183
|
+
pending = false;
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async admitObjectsTransaction<T>(
|
|
189
|
+
admissions: readonly MediaStoredObjectAdmission[],
|
|
190
|
+
publish: () => Promise<T>,
|
|
191
|
+
): Promise<T> {
|
|
192
|
+
const copied = admissions.map((admission) => ({
|
|
193
|
+
object: admission.object,
|
|
194
|
+
bytes: new Uint8Array(admission.bytes),
|
|
195
|
+
}));
|
|
196
|
+
return this.persistence.runExclusive('admit object batch', undefined, () =>
|
|
197
|
+
this.admitObjectBatchUnlocked(copied, publish),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async preflightKnown(
|
|
202
|
+
contentId: string,
|
|
203
|
+
knownByteLength: number,
|
|
204
|
+
): Promise<void> {
|
|
205
|
+
validateContentId(contentId, 'preflight known object');
|
|
206
|
+
this.validateKnownByteLength(knownByteLength, contentId);
|
|
207
|
+
await this.persistence.runExclusive(
|
|
208
|
+
'preflight known object',
|
|
209
|
+
contentId,
|
|
210
|
+
async () => {
|
|
211
|
+
if (await this.persistence.objectExistsUnlocked(contentId)) return;
|
|
212
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
213
|
+
this.persistence.enforceQuota(storedBytes, knownByteLength, contentId);
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async admitKnown(
|
|
219
|
+
input: MediaKnownAdmissionInput,
|
|
220
|
+
readBytes: () => Promise<Uint8Array>,
|
|
221
|
+
): Promise<MediaReferenceBlock> {
|
|
222
|
+
validateContentId(input.contentId, 'admit known object');
|
|
223
|
+
this.validateKnownByteLength(input.knownByteLength, input.contentId);
|
|
224
|
+
const metadata = buildStoredObject(
|
|
225
|
+
input.contentId,
|
|
226
|
+
input.mimeType,
|
|
227
|
+
input.knownByteLength,
|
|
228
|
+
input.dimensions,
|
|
229
|
+
);
|
|
230
|
+
const semanticMetadata = validatedSemanticMetadata(
|
|
231
|
+
input.semanticMetadata,
|
|
232
|
+
input.contentId,
|
|
233
|
+
);
|
|
234
|
+
const providerFileIds = validatedProviderFileIds(
|
|
235
|
+
input.providerFileIds,
|
|
236
|
+
input.contentId,
|
|
237
|
+
);
|
|
238
|
+
const existing = await this.persistence.runExclusive(
|
|
239
|
+
'preflight known object admission',
|
|
240
|
+
input.contentId,
|
|
241
|
+
async () => {
|
|
242
|
+
if (await this.persistence.objectExistsUnlocked(input.contentId)) {
|
|
243
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
244
|
+
metadata,
|
|
245
|
+
'admit deduplicated object',
|
|
246
|
+
);
|
|
247
|
+
return buildIdentityReference(
|
|
248
|
+
metadata,
|
|
249
|
+
semanticMetadata,
|
|
250
|
+
providerFileIds,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
254
|
+
this.persistence.enforceQuota(
|
|
255
|
+
storedBytes,
|
|
256
|
+
input.knownByteLength,
|
|
257
|
+
input.contentId,
|
|
258
|
+
);
|
|
259
|
+
return undefined;
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
if (existing !== undefined) return existing;
|
|
263
|
+
const bytes = new Uint8Array(await readBytes());
|
|
264
|
+
if (
|
|
265
|
+
bytes.byteLength !== input.knownByteLength ||
|
|
266
|
+
contentIdFor(bytes) !== input.contentId
|
|
267
|
+
) {
|
|
268
|
+
throw new MediaStoreError(
|
|
269
|
+
'validate known object source',
|
|
270
|
+
input.contentId,
|
|
271
|
+
new Error('Known object source changed after preflight'),
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
return this.persistence.runExclusive(
|
|
275
|
+
'admit known object',
|
|
276
|
+
input.contentId,
|
|
277
|
+
() =>
|
|
278
|
+
this.admitKnownSnapshotUnlocked(
|
|
279
|
+
input,
|
|
280
|
+
metadata,
|
|
281
|
+
semanticMetadata,
|
|
282
|
+
providerFileIds,
|
|
283
|
+
bytes,
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async readObjectVerified(reference: MediaStoredObject): Promise<Uint8Array> {
|
|
289
|
+
return this.persistence.readObjectVerified(reference);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async readVerified(reference: MediaReferenceBlock): Promise<Uint8Array> {
|
|
293
|
+
if (!isMediaReferenceBlock(reference)) {
|
|
294
|
+
throw new MediaObjectCorruptError(
|
|
295
|
+
'read verified',
|
|
296
|
+
undefined,
|
|
297
|
+
new Error('Malformed media reference'),
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
return this.readObjectVerified(reference.selectedObject);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async getStoredByteLength(): Promise<number> {
|
|
304
|
+
return this.persistence.getStoredByteLength();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async reserve(
|
|
308
|
+
reference: MediaReferenceBlock,
|
|
309
|
+
ownerId: string,
|
|
310
|
+
): Promise<void> {
|
|
311
|
+
await this.reserveAndReadVerified(reference, ownerId);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async reserveAndReadVerified(
|
|
315
|
+
reference: MediaReferenceBlock,
|
|
316
|
+
ownerId: string,
|
|
317
|
+
): Promise<Uint8Array> {
|
|
318
|
+
return this.persistence.reserveAndReadVerified(reference, ownerId);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async release(contentId: string, ownerId: string): Promise<void> {
|
|
322
|
+
await this.persistence.release(contentId, ownerId);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async hasReservations(contentId: string): Promise<boolean> {
|
|
326
|
+
return this.persistence.hasReservations(contentId);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async reclaimUnreferenced(
|
|
330
|
+
protectedContentIds: ReadonlySet<string>,
|
|
331
|
+
staleTemporaryBefore: number,
|
|
332
|
+
): Promise<MediaReclamationResult> {
|
|
333
|
+
return this.persistence.reclaimUnreferenced(
|
|
334
|
+
protectedContentIds,
|
|
335
|
+
staleTemporaryBefore,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private async measureMissingObjects(
|
|
340
|
+
objects: ReadonlyMap<string, MediaStoredObject>,
|
|
341
|
+
): Promise<number> {
|
|
342
|
+
let additionalBytes = 0;
|
|
343
|
+
for (const object of objects.values()) {
|
|
344
|
+
if (!(await this.persistence.objectExistsUnlocked(object.contentId))) {
|
|
345
|
+
additionalBytes += object.byteLength;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return additionalBytes;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
private async stageObjectFileBatchUnlocked(
|
|
352
|
+
admissions: readonly StoredObjectWithFile[],
|
|
353
|
+
): Promise<readonly PublishedMediaObjectPath[]> {
|
|
354
|
+
const byContentId = new Map<string, StoredObjectWithFile>();
|
|
355
|
+
for (const admission of admissions) {
|
|
356
|
+
validateStoredObjectMetadata(admission.object, 'stage object file batch');
|
|
357
|
+
const existing = byContentId.get(admission.object.contentId);
|
|
358
|
+
if (
|
|
359
|
+
existing !== undefined &&
|
|
360
|
+
!storedObjectMetadataMatches(existing.object, admission.object)
|
|
361
|
+
) {
|
|
362
|
+
throw new MediaStoreError(
|
|
363
|
+
'stage object file batch',
|
|
364
|
+
admission.object.contentId,
|
|
365
|
+
new Error('Conflicting stored object metadata'),
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
byContentId.set(admission.object.contentId, admission);
|
|
369
|
+
}
|
|
370
|
+
const missing: StoredObjectWithFile[] = [];
|
|
371
|
+
for (const admission of byContentId.values()) {
|
|
372
|
+
if (
|
|
373
|
+
await this.persistence.objectExistsUnlocked(admission.object.contentId)
|
|
374
|
+
) {
|
|
375
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
376
|
+
admission.object,
|
|
377
|
+
'stage deduplicated object file batch',
|
|
378
|
+
);
|
|
379
|
+
} else {
|
|
380
|
+
missing.push(admission);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const additionalBytes = missing.reduce(
|
|
384
|
+
(total, admission) => total + admission.object.byteLength,
|
|
385
|
+
0,
|
|
386
|
+
);
|
|
387
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
388
|
+
this.persistence.enforceQuota(storedBytes, additionalBytes, 'batch');
|
|
389
|
+
const published: PublishedMediaObjectPath[] = [];
|
|
390
|
+
try {
|
|
391
|
+
for (const admission of missing) {
|
|
392
|
+
const path = await this.persistence.publishObjectFile(
|
|
393
|
+
admission.sourcePath,
|
|
394
|
+
admission.object.contentId,
|
|
395
|
+
admission.object.byteLength,
|
|
396
|
+
'stage object file batch',
|
|
397
|
+
);
|
|
398
|
+
if (path !== undefined) {
|
|
399
|
+
published.push({ contentId: admission.object.contentId, path });
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return published;
|
|
403
|
+
} catch (error) {
|
|
404
|
+
return this.throwAfterRollback(
|
|
405
|
+
error,
|
|
406
|
+
published.map((entry) => entry.path),
|
|
407
|
+
'stage object file batch and rollback',
|
|
408
|
+
undefined,
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
private async stageObjectBatchUnlocked(
|
|
414
|
+
admissions: readonly StoredObjectWithBytes[],
|
|
415
|
+
): Promise<readonly PublishedMediaObjectPath[]> {
|
|
416
|
+
const byContentId = this.prepareObjectAdmissions(admissions);
|
|
417
|
+
const missing = await this.findMissingAdmissions(byContentId);
|
|
418
|
+
const additionalBytes = missing.reduce(
|
|
419
|
+
(total, admission) => total + admission.object.byteLength,
|
|
420
|
+
0,
|
|
421
|
+
);
|
|
422
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
423
|
+
this.persistence.enforceQuota(storedBytes, additionalBytes, 'batch');
|
|
424
|
+
const published: PublishedMediaObjectPath[] = [];
|
|
425
|
+
try {
|
|
426
|
+
for (const admission of missing) {
|
|
427
|
+
const path = await this.persistence.publishObjectBytes(
|
|
428
|
+
admission.bytes,
|
|
429
|
+
admission.object.contentId,
|
|
430
|
+
'stage object batch',
|
|
431
|
+
);
|
|
432
|
+
if (path !== undefined) {
|
|
433
|
+
published.push({ contentId: admission.object.contentId, path });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
await this.verifyAdmissions(missing, 'verify staged object batch');
|
|
437
|
+
return published;
|
|
438
|
+
} catch (error) {
|
|
439
|
+
return this.throwAfterRollback(
|
|
440
|
+
error,
|
|
441
|
+
published.map((entry) => entry.path),
|
|
442
|
+
'stage object batch and rollback',
|
|
443
|
+
undefined,
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private async admitObjectBatchUnlocked<T>(
|
|
449
|
+
admissions: readonly StoredObjectWithBytes[],
|
|
450
|
+
publish: () => Promise<T>,
|
|
451
|
+
): Promise<T> {
|
|
452
|
+
const byContentId = this.prepareObjectAdmissions(admissions);
|
|
453
|
+
const missing = await this.findMissingAdmissions(byContentId);
|
|
454
|
+
const additionalBytes = missing.reduce(
|
|
455
|
+
(total, admission) => total + admission.object.byteLength,
|
|
456
|
+
0,
|
|
457
|
+
);
|
|
458
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
459
|
+
this.persistence.enforceQuota(storedBytes, additionalBytes, 'batch');
|
|
460
|
+
const published: string[] = [];
|
|
461
|
+
try {
|
|
462
|
+
await this.publishAdmissions(missing, published, 'commit object batch');
|
|
463
|
+
await this.verifyAdmissions(missing, 'verify admitted object batch');
|
|
464
|
+
return await publish();
|
|
465
|
+
} catch (error) {
|
|
466
|
+
return this.throwAfterRollback(
|
|
467
|
+
error,
|
|
468
|
+
published,
|
|
469
|
+
'admit object batch and rollback',
|
|
470
|
+
undefined,
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
private prepareObjectAdmissions(
|
|
476
|
+
admissions: readonly StoredObjectWithBytes[],
|
|
477
|
+
): ReadonlyMap<string, StoredObjectWithBytes> {
|
|
478
|
+
const byContentId = new Map<string, StoredObjectWithBytes>();
|
|
479
|
+
for (const admission of admissions) {
|
|
480
|
+
validateStoredObjectMetadata(admission.object, 'admit object batch');
|
|
481
|
+
if (
|
|
482
|
+
admission.bytes.byteLength !== admission.object.byteLength ||
|
|
483
|
+
contentIdFor(admission.bytes) !== admission.object.contentId
|
|
484
|
+
) {
|
|
485
|
+
throw new MediaObjectHashMismatchError(
|
|
486
|
+
'admit object batch',
|
|
487
|
+
admission.object.contentId,
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
this.validateCompatibleAdmission(byContentId, admission);
|
|
491
|
+
byContentId.set(admission.object.contentId, admission);
|
|
492
|
+
}
|
|
493
|
+
return byContentId;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private validateCompatibleAdmission(
|
|
497
|
+
admissions: ReadonlyMap<string, StoredObjectWithBytes>,
|
|
498
|
+
admission: StoredObjectWithBytes,
|
|
499
|
+
): void {
|
|
500
|
+
const existing = admissions.get(admission.object.contentId);
|
|
501
|
+
if (existing === undefined) return;
|
|
502
|
+
if (storedObjectMetadataMatches(existing.object, admission.object)) return;
|
|
503
|
+
throw new MediaStoreError(
|
|
504
|
+
'admit object batch',
|
|
505
|
+
admission.object.contentId,
|
|
506
|
+
new Error('Conflicting stored object metadata'),
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
private async findMissingAdmissions(
|
|
511
|
+
admissions: ReadonlyMap<string, StoredObjectWithBytes>,
|
|
512
|
+
): Promise<readonly StoredObjectWithBytes[]> {
|
|
513
|
+
const missing: StoredObjectWithBytes[] = [];
|
|
514
|
+
for (const admission of admissions.values()) {
|
|
515
|
+
if (
|
|
516
|
+
await this.persistence.objectExistsUnlocked(admission.object.contentId)
|
|
517
|
+
) {
|
|
518
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
519
|
+
admission.object,
|
|
520
|
+
'admit deduplicated object batch',
|
|
521
|
+
);
|
|
522
|
+
} else {
|
|
523
|
+
missing.push(admission);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return missing;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
private async publishAdmissions(
|
|
530
|
+
admissions: Iterable<StoredObjectWithBytes>,
|
|
531
|
+
published: string[],
|
|
532
|
+
operation: string,
|
|
533
|
+
): Promise<void> {
|
|
534
|
+
for (const admission of admissions) {
|
|
535
|
+
const path = await this.persistence.publishObjectBytes(
|
|
536
|
+
admission.bytes,
|
|
537
|
+
admission.object.contentId,
|
|
538
|
+
operation,
|
|
539
|
+
);
|
|
540
|
+
if (path !== undefined) published.push(path);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private async verifyAdmissions(
|
|
545
|
+
admissions: Iterable<StoredObjectWithBytes>,
|
|
546
|
+
operation: string,
|
|
547
|
+
): Promise<void> {
|
|
548
|
+
for (const admission of admissions) {
|
|
549
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
550
|
+
admission.object,
|
|
551
|
+
operation,
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
private async throwAfterRollback(
|
|
557
|
+
error: unknown,
|
|
558
|
+
published: readonly string[],
|
|
559
|
+
operation: string,
|
|
560
|
+
contentId: string | undefined,
|
|
561
|
+
): Promise<never> {
|
|
562
|
+
const cleanupErrors =
|
|
563
|
+
await this.persistence.rollbackPublishedPaths(published);
|
|
564
|
+
if (cleanupErrors.length > 0) {
|
|
565
|
+
throw new MediaStoreError(
|
|
566
|
+
operation,
|
|
567
|
+
contentId,
|
|
568
|
+
new AggregateError([error, ...cleanupErrors]),
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
throw error;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
private validateKnownByteLength(
|
|
575
|
+
knownByteLength: number,
|
|
576
|
+
contentId: string,
|
|
577
|
+
): void {
|
|
578
|
+
if (!isPositiveSafeInteger(knownByteLength)) {
|
|
579
|
+
throw new MediaStoreError(
|
|
580
|
+
'validate known byte length',
|
|
581
|
+
contentId,
|
|
582
|
+
new Error('Known byte length must be a positive safe integer'),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
private async admitKnownSnapshotUnlocked(
|
|
588
|
+
input: MediaKnownAdmissionInput,
|
|
589
|
+
metadata: MediaStoredObject,
|
|
590
|
+
semanticMetadata: MediaSemanticMetadata,
|
|
591
|
+
providerFileIds: Readonly<Record<string, string>> | undefined,
|
|
592
|
+
bytes: Uint8Array,
|
|
593
|
+
): Promise<MediaReferenceBlock> {
|
|
594
|
+
if (await this.persistence.objectExistsUnlocked(input.contentId)) {
|
|
595
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
596
|
+
metadata,
|
|
597
|
+
'admit deduplicated object',
|
|
598
|
+
);
|
|
599
|
+
return buildIdentityReference(
|
|
600
|
+
metadata,
|
|
601
|
+
semanticMetadata,
|
|
602
|
+
providerFileIds,
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
606
|
+
this.persistence.enforceQuota(
|
|
607
|
+
storedBytes,
|
|
608
|
+
input.knownByteLength,
|
|
609
|
+
input.contentId,
|
|
610
|
+
);
|
|
611
|
+
const published = await this.persistence.publishObjectBytes(
|
|
612
|
+
bytes,
|
|
613
|
+
input.contentId,
|
|
614
|
+
'commit object',
|
|
615
|
+
);
|
|
616
|
+
try {
|
|
617
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
618
|
+
metadata,
|
|
619
|
+
'verify admitted object',
|
|
620
|
+
);
|
|
621
|
+
return buildIdentityReference(
|
|
622
|
+
metadata,
|
|
623
|
+
semanticMetadata,
|
|
624
|
+
providerFileIds,
|
|
625
|
+
);
|
|
626
|
+
} catch (error) {
|
|
627
|
+
return this.throwAfterRollback(
|
|
628
|
+
error,
|
|
629
|
+
published === undefined ? [] : [published],
|
|
630
|
+
'admit known object and rollback',
|
|
631
|
+
input.contentId,
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
private async admitPreparedUnlocked(
|
|
637
|
+
prepared: PreparedAdmission,
|
|
638
|
+
): Promise<void> {
|
|
639
|
+
const objects = new Map<string, StoredObjectWithBytes>();
|
|
640
|
+
objects.set(prepared.original.contentId, {
|
|
641
|
+
object: prepared.original,
|
|
642
|
+
bytes: prepared.originalBytes,
|
|
643
|
+
});
|
|
644
|
+
objects.set(prepared.selected.contentId, {
|
|
645
|
+
object: prepared.selected,
|
|
646
|
+
bytes: prepared.selectedBytes,
|
|
647
|
+
});
|
|
648
|
+
const missing = await this.findMissingPreparedObjects(objects);
|
|
649
|
+
const additionalBytes = missing.reduce(
|
|
650
|
+
(total, entry) => total + entry.object.byteLength,
|
|
651
|
+
0,
|
|
652
|
+
);
|
|
653
|
+
const storedBytes = await this.persistence.measureStoredBytesUnlocked();
|
|
654
|
+
this.persistence.enforceQuota(
|
|
655
|
+
storedBytes,
|
|
656
|
+
additionalBytes,
|
|
657
|
+
prepared.selected.contentId,
|
|
658
|
+
);
|
|
659
|
+
await this.publishAndVerifyPrepared(prepared, missing);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
private async findMissingPreparedObjects(
|
|
663
|
+
objects: ReadonlyMap<string, StoredObjectWithBytes>,
|
|
664
|
+
): Promise<readonly StoredObjectWithBytes[]> {
|
|
665
|
+
const missing: StoredObjectWithBytes[] = [];
|
|
666
|
+
for (const entry of objects.values()) {
|
|
667
|
+
if (await this.persistence.objectExistsUnlocked(entry.object.contentId)) {
|
|
668
|
+
await this.persistence.readObjectVerifiedUnlocked(
|
|
669
|
+
entry.object,
|
|
670
|
+
'admit deduplicated object',
|
|
671
|
+
);
|
|
672
|
+
} else {
|
|
673
|
+
missing.push(entry);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return missing;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
private async publishAndVerifyPrepared(
|
|
680
|
+
prepared: PreparedAdmission,
|
|
681
|
+
missing: readonly StoredObjectWithBytes[],
|
|
682
|
+
): Promise<void> {
|
|
683
|
+
const published: string[] = [];
|
|
684
|
+
try {
|
|
685
|
+
await this.publishAdmissions(missing, published, 'commit object');
|
|
686
|
+
await this.verifyAdmissions(missing, 'verify admitted object');
|
|
687
|
+
} catch (error) {
|
|
688
|
+
await this.throwAfterRollback(
|
|
689
|
+
error,
|
|
690
|
+
published,
|
|
691
|
+
'admit objects and rollback',
|
|
692
|
+
prepared.selected.contentId,
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|