@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,512 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { parseImageDimensionsFromBase64 } from '@vybestack/llxprt-code-tools/utils/imageDimensions.js';
|
|
9
|
+
import type { HistoryService } from '../services/history/HistoryService.js';
|
|
10
|
+
import type {
|
|
11
|
+
ContentBlock,
|
|
12
|
+
IContent,
|
|
13
|
+
InlineMediaBlock,
|
|
14
|
+
MediaBlock,
|
|
15
|
+
MediaReferenceBlock,
|
|
16
|
+
} from '../services/history/IContent.js';
|
|
17
|
+
import { isMediaReferenceBlock } from '../services/history/IContent.js';
|
|
18
|
+
import { MediaStoreError, type LocalMediaStore } from './local-media-store.js';
|
|
19
|
+
import { MIME_TYPE_PATTERN } from './local-media-store-validation.js';
|
|
20
|
+
import { verifyHistoryMedia } from './media-reference-lifecycle.js';
|
|
21
|
+
|
|
22
|
+
const MAX_DATA_URI_PREFIX_LENGTH = 256;
|
|
23
|
+
const CANONICAL_BASE64_PATTERN =
|
|
24
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
25
|
+
|
|
26
|
+
export interface MediaAdmissionContext {
|
|
27
|
+
readonly turnId: string;
|
|
28
|
+
readonly source: string;
|
|
29
|
+
readonly preserveLegacyMimeParameters?: boolean;
|
|
30
|
+
readonly reservationOwnerScope?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface MediaAdmissionRelease {
|
|
34
|
+
readonly contents: readonly IContent[];
|
|
35
|
+
readonly context: MediaAdmissionContext;
|
|
36
|
+
readonly mode: 'content' | 'contents';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface AdmissionReservation {
|
|
40
|
+
readonly contentId: string;
|
|
41
|
+
readonly ownerId: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class MediaAdmissionError extends Error {
|
|
45
|
+
readonly turnId: string;
|
|
46
|
+
readonly source: string;
|
|
47
|
+
readonly mediaIndex: number;
|
|
48
|
+
readonly contentId: string | undefined;
|
|
49
|
+
readonly historyContentId: string | undefined;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
context: MediaAdmissionContext,
|
|
53
|
+
mediaIndex: number,
|
|
54
|
+
contentId: string | undefined,
|
|
55
|
+
historyContentId: string | undefined,
|
|
56
|
+
cause: unknown,
|
|
57
|
+
) {
|
|
58
|
+
super(
|
|
59
|
+
`Media admission failed [turn=${context.turnId}] [source=${context.source}] ` +
|
|
60
|
+
`[media[${mediaIndex}]] [historyContentId=${historyContentId ?? 'unavailable'}] ` +
|
|
61
|
+
`[contentId=${contentId ?? 'unavailable'}]`,
|
|
62
|
+
{ cause },
|
|
63
|
+
);
|
|
64
|
+
this.name = 'MediaAdmissionError';
|
|
65
|
+
this.turnId = context.turnId;
|
|
66
|
+
this.source = context.source;
|
|
67
|
+
this.mediaIndex = mediaIndex;
|
|
68
|
+
this.contentId = contentId;
|
|
69
|
+
this.historyContentId = historyContentId;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function base64PaddingLength(value: string): number {
|
|
73
|
+
if (value.endsWith('==')) return 2;
|
|
74
|
+
if (value.endsWith('=')) return 1;
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface NormalizedBase64Source {
|
|
79
|
+
readonly payload: string;
|
|
80
|
+
readonly decodedByteLength: number;
|
|
81
|
+
readonly contentId: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeBase64Source(data: string): NormalizedBase64Source {
|
|
85
|
+
let payload = data;
|
|
86
|
+
if (data.toLowerCase().startsWith('data:')) {
|
|
87
|
+
const comma = data.slice(0, MAX_DATA_URI_PREFIX_LENGTH).indexOf(',');
|
|
88
|
+
if (comma < 0) throw new Error('Image data URI has no payload separator');
|
|
89
|
+
const header = data.slice(0, comma);
|
|
90
|
+
if (!header.toLowerCase().endsWith(';base64')) {
|
|
91
|
+
throw new Error('Image data URI is not base64 encoded');
|
|
92
|
+
}
|
|
93
|
+
payload = data.slice(comma + 1);
|
|
94
|
+
}
|
|
95
|
+
const canonical = payload.replace(/\s+/g, '');
|
|
96
|
+
if (
|
|
97
|
+
canonical.length === 0 ||
|
|
98
|
+
canonical.length % 4 !== 0 ||
|
|
99
|
+
!CANONICAL_BASE64_PATTERN.test(canonical)
|
|
100
|
+
) {
|
|
101
|
+
throw new Error('Base64 image data is malformed or non-canonical');
|
|
102
|
+
}
|
|
103
|
+
const padding = base64PaddingLength(canonical);
|
|
104
|
+
const decodedByteLength = (canonical.length / 4) * 3 - padding;
|
|
105
|
+
if (!Number.isSafeInteger(decodedByteLength) || decodedByteLength <= 0) {
|
|
106
|
+
throw new Error('Base64 image data decoded length is invalid');
|
|
107
|
+
}
|
|
108
|
+
const contentId = `sha256:${createHash('sha256')
|
|
109
|
+
.update(canonical, 'base64')
|
|
110
|
+
.digest('hex')}`;
|
|
111
|
+
return { payload: canonical, decodedByteLength, contentId };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function decodeCanonicalBase64(source: NormalizedBase64Source): Uint8Array {
|
|
115
|
+
const bytes = Buffer.from(source.payload, 'base64');
|
|
116
|
+
if (
|
|
117
|
+
bytes.byteLength !== source.decodedByteLength ||
|
|
118
|
+
bytes.toString('base64') !== source.payload
|
|
119
|
+
) {
|
|
120
|
+
throw new Error('Base64 image data is malformed or non-canonical');
|
|
121
|
+
}
|
|
122
|
+
return new Uint8Array(bytes);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function sourceObject(
|
|
126
|
+
source: NormalizedBase64Source,
|
|
127
|
+
mimeType: string,
|
|
128
|
+
): {
|
|
129
|
+
readonly contentId: string;
|
|
130
|
+
readonly mimeType: string;
|
|
131
|
+
readonly byteLength: number;
|
|
132
|
+
readonly normalizedBase64Length: number;
|
|
133
|
+
} {
|
|
134
|
+
return {
|
|
135
|
+
contentId: source.contentId,
|
|
136
|
+
mimeType,
|
|
137
|
+
byteLength: source.decodedByteLength,
|
|
138
|
+
normalizedBase64Length: source.payload.length,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function modelVisibleMetadata(
|
|
143
|
+
block: MediaBlock,
|
|
144
|
+
): Pick<
|
|
145
|
+
MediaBlock,
|
|
146
|
+
'caption' | 'filename' | 'providerMetadata' | 'providerFiles'
|
|
147
|
+
> {
|
|
148
|
+
return {
|
|
149
|
+
...(block.caption === undefined ? {} : { caption: block.caption }),
|
|
150
|
+
...(block.filename === undefined ? {} : { filename: block.filename }),
|
|
151
|
+
...(block.providerMetadata === undefined
|
|
152
|
+
? {}
|
|
153
|
+
: { providerMetadata: block.providerMetadata }),
|
|
154
|
+
...(block.providerFiles === undefined
|
|
155
|
+
? {}
|
|
156
|
+
: { providerFiles: block.providerFiles }),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function copyModelVisibleMetadata(
|
|
161
|
+
block: InlineMediaBlock,
|
|
162
|
+
reference: MediaReferenceBlock,
|
|
163
|
+
): MediaReferenceBlock {
|
|
164
|
+
return Object.freeze({ ...reference, ...modelVisibleMetadata(block) });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function ownerIdFor(
|
|
168
|
+
context: MediaAdmissionContext,
|
|
169
|
+
mediaIndex: number,
|
|
170
|
+
contentId: string,
|
|
171
|
+
): string {
|
|
172
|
+
return historyOwnerIdFor(contentId, context.reservationOwnerScope);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Content-derived durable reservation owner. Live history adopts and releases
|
|
176
|
+
* under this exact identity so the one reservation survives admission, ownership,
|
|
177
|
+
* release, and rollback. */
|
|
178
|
+
export function historyOwnerIdFor(
|
|
179
|
+
contentId: string,
|
|
180
|
+
scope = 'history',
|
|
181
|
+
): string {
|
|
182
|
+
return `history:${createHash('sha256')
|
|
183
|
+
.update(scope)
|
|
184
|
+
.update('\u0000')
|
|
185
|
+
.update(contentId)
|
|
186
|
+
.digest('hex')}`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class MediaAdmissionService {
|
|
190
|
+
constructor(private readonly store: LocalMediaStore) {}
|
|
191
|
+
|
|
192
|
+
async admitContent(
|
|
193
|
+
content: IContent,
|
|
194
|
+
context: MediaAdmissionContext,
|
|
195
|
+
): Promise<IContent> {
|
|
196
|
+
const reservations: AdmissionReservation[] = [];
|
|
197
|
+
try {
|
|
198
|
+
return await this.admitContentWithinTransaction(
|
|
199
|
+
content,
|
|
200
|
+
context,
|
|
201
|
+
reservations,
|
|
202
|
+
);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
return this.rollbackReservations(reservations, error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async admitContents(
|
|
209
|
+
contents: readonly IContent[],
|
|
210
|
+
context: MediaAdmissionContext,
|
|
211
|
+
): Promise<IContent[]> {
|
|
212
|
+
const reservations: AdmissionReservation[] = [];
|
|
213
|
+
const admitted: IContent[] = [];
|
|
214
|
+
try {
|
|
215
|
+
for (const [index, content] of contents.entries()) {
|
|
216
|
+
admitted.push(
|
|
217
|
+
await this.admitContentWithinTransaction(
|
|
218
|
+
content,
|
|
219
|
+
{
|
|
220
|
+
...context,
|
|
221
|
+
turnId: content.metadata?.turnId ?? `${context.turnId}:${index}`,
|
|
222
|
+
},
|
|
223
|
+
reservations,
|
|
224
|
+
),
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return admitted;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
return this.rollbackReservations(reservations, error);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async releaseContents(
|
|
234
|
+
contents: readonly IContent[],
|
|
235
|
+
context: MediaAdmissionContext,
|
|
236
|
+
): Promise<void> {
|
|
237
|
+
return this.releaseAdmissions([{ contents, context, mode: 'contents' }]);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async releaseAdmissions(
|
|
241
|
+
admissions: readonly MediaAdmissionRelease[],
|
|
242
|
+
): Promise<void> {
|
|
243
|
+
const reservations: AdmissionReservation[] = [];
|
|
244
|
+
for (const admission of admissions) {
|
|
245
|
+
for (const reservation of this.contentReservations(
|
|
246
|
+
admission.contents,
|
|
247
|
+
admission.context,
|
|
248
|
+
admission.mode === 'contents',
|
|
249
|
+
)) {
|
|
250
|
+
this.recordReservation(reservations, reservation);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const failures: unknown[] = [];
|
|
254
|
+
for (const reservation of reservations) {
|
|
255
|
+
try {
|
|
256
|
+
await this.store.release(reservation.contentId, reservation.ownerId);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
failures.push(error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (failures.length > 0) {
|
|
262
|
+
throw new AggregateError(failures, 'Media reservation release failed');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private contentReservations(
|
|
267
|
+
contents: readonly IContent[],
|
|
268
|
+
context: MediaAdmissionContext,
|
|
269
|
+
deriveContentTurnIds = true,
|
|
270
|
+
): readonly AdmissionReservation[] {
|
|
271
|
+
const reservations: AdmissionReservation[] = [];
|
|
272
|
+
for (const [contentIndex, content] of contents.entries()) {
|
|
273
|
+
const contentContext = deriveContentTurnIds
|
|
274
|
+
? {
|
|
275
|
+
...context,
|
|
276
|
+
turnId:
|
|
277
|
+
content.metadata?.turnId ?? `${context.turnId}:${contentIndex}`,
|
|
278
|
+
}
|
|
279
|
+
: context;
|
|
280
|
+
let mediaIndex = 0;
|
|
281
|
+
for (const block of content.blocks) {
|
|
282
|
+
if (block.type !== 'media') continue;
|
|
283
|
+
if (block.encoding === 'reference' && isMediaReferenceBlock(block)) {
|
|
284
|
+
this.recordReservation(reservations, {
|
|
285
|
+
contentId: block.contentId,
|
|
286
|
+
ownerId: ownerIdFor(contentContext, mediaIndex, block.contentId),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
mediaIndex += 1;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return reservations;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private async admitContentWithinTransaction(
|
|
296
|
+
content: IContent,
|
|
297
|
+
context: MediaAdmissionContext,
|
|
298
|
+
reservations: AdmissionReservation[],
|
|
299
|
+
): Promise<IContent> {
|
|
300
|
+
let mediaIndex = 0;
|
|
301
|
+
let contentChanged = false;
|
|
302
|
+
const blocks: ContentBlock[] = [];
|
|
303
|
+
for (const block of content.blocks) {
|
|
304
|
+
if (block.type === 'media') {
|
|
305
|
+
const admitted = await this.admitMediaBlock(
|
|
306
|
+
block,
|
|
307
|
+
content,
|
|
308
|
+
context,
|
|
309
|
+
mediaIndex++,
|
|
310
|
+
reservations,
|
|
311
|
+
);
|
|
312
|
+
blocks.push(admitted.block);
|
|
313
|
+
contentChanged ||= admitted.changed;
|
|
314
|
+
} else {
|
|
315
|
+
blocks.push(block);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return contentChanged ? { ...content, blocks } : content;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private async rollbackReservations(
|
|
322
|
+
reservations: readonly AdmissionReservation[],
|
|
323
|
+
admissionError: unknown,
|
|
324
|
+
): Promise<never> {
|
|
325
|
+
const rollbackErrors: unknown[] = [];
|
|
326
|
+
for (let index = reservations.length - 1; index >= 0; index -= 1) {
|
|
327
|
+
const reservation = reservations[index];
|
|
328
|
+
try {
|
|
329
|
+
await this.store.release(reservation.contentId, reservation.ownerId);
|
|
330
|
+
} catch (error) {
|
|
331
|
+
rollbackErrors.push(error);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (rollbackErrors.length > 0) {
|
|
335
|
+
throw new AggregateError(
|
|
336
|
+
[admissionError, ...rollbackErrors],
|
|
337
|
+
'Media admission and reservation rollback failed',
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
throw admissionError;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async addToHistory(
|
|
344
|
+
history: HistoryService,
|
|
345
|
+
content: IContent,
|
|
346
|
+
context: MediaAdmissionContext,
|
|
347
|
+
model?: string,
|
|
348
|
+
): Promise<void> {
|
|
349
|
+
const admitted = await this.admitContent(content, context);
|
|
350
|
+
history.add(admitted, model);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async verifyHistory(history: readonly IContent[]): Promise<void> {
|
|
354
|
+
await verifyHistoryMedia(history, this.store, 'history-restore');
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private recordReservation(
|
|
358
|
+
reservations: AdmissionReservation[],
|
|
359
|
+
reservation: AdmissionReservation,
|
|
360
|
+
): void {
|
|
361
|
+
const alreadyRecorded = reservations.some(
|
|
362
|
+
(existing) =>
|
|
363
|
+
existing.contentId === reservation.contentId &&
|
|
364
|
+
existing.ownerId === reservation.ownerId,
|
|
365
|
+
);
|
|
366
|
+
if (!alreadyRecorded) reservations.push(reservation);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private async admitMediaBlock(
|
|
370
|
+
block: MediaBlock,
|
|
371
|
+
content: IContent,
|
|
372
|
+
context: MediaAdmissionContext,
|
|
373
|
+
mediaIndex: number,
|
|
374
|
+
reservations: AdmissionReservation[],
|
|
375
|
+
): Promise<{ readonly block: MediaBlock; readonly changed: boolean }> {
|
|
376
|
+
if (block.encoding === 'reference') {
|
|
377
|
+
try {
|
|
378
|
+
if (!isMediaReferenceBlock(block)) {
|
|
379
|
+
throw new Error('Malformed media reference');
|
|
380
|
+
}
|
|
381
|
+
const ownerId = ownerIdFor(context, mediaIndex, block.contentId);
|
|
382
|
+
await this.store.reserveAndReadVerified(block, ownerId);
|
|
383
|
+
this.recordReservation(reservations, {
|
|
384
|
+
contentId: block.contentId,
|
|
385
|
+
ownerId,
|
|
386
|
+
});
|
|
387
|
+
} catch (error) {
|
|
388
|
+
throw new MediaAdmissionError(
|
|
389
|
+
context,
|
|
390
|
+
mediaIndex,
|
|
391
|
+
block.contentId,
|
|
392
|
+
content.metadata?.id,
|
|
393
|
+
error,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return { block, changed: false };
|
|
397
|
+
}
|
|
398
|
+
if (
|
|
399
|
+
block.encoding !== 'base64' ||
|
|
400
|
+
!block.mimeType.toLowerCase().startsWith('image/') ||
|
|
401
|
+
(context.preserveLegacyMimeParameters === true &&
|
|
402
|
+
!MIME_TYPE_PATTERN.test(block.mimeType))
|
|
403
|
+
) {
|
|
404
|
+
return { block, changed: false };
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
block: await this.admitImage(block, context, mediaIndex, reservations),
|
|
408
|
+
changed: true,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private async admitIdentity(
|
|
413
|
+
block: InlineMediaBlock,
|
|
414
|
+
source: NormalizedBase64Source,
|
|
415
|
+
): Promise<MediaReferenceBlock> {
|
|
416
|
+
await this.store.preflightKnown(source.contentId, source.decodedByteLength);
|
|
417
|
+
const dimensions =
|
|
418
|
+
block.dimensions ?? parseImageDimensionsFromBase64(source.payload);
|
|
419
|
+
return this.store.admitKnown(
|
|
420
|
+
{
|
|
421
|
+
contentId: source.contentId,
|
|
422
|
+
knownByteLength: source.decodedByteLength,
|
|
423
|
+
mimeType: block.mimeType,
|
|
424
|
+
...(dimensions === undefined ? {} : { dimensions }),
|
|
425
|
+
semanticMetadata: block.semanticMetadata ?? {},
|
|
426
|
+
...(block.providerFileIds === undefined
|
|
427
|
+
? {}
|
|
428
|
+
: { providerFileIds: block.providerFileIds }),
|
|
429
|
+
},
|
|
430
|
+
async () => decodeCanonicalBase64(source),
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private async admitDerived(
|
|
435
|
+
block: InlineMediaBlock,
|
|
436
|
+
source: NormalizedBase64Source,
|
|
437
|
+
): Promise<MediaReferenceBlock> {
|
|
438
|
+
if (
|
|
439
|
+
block.originalData === undefined ||
|
|
440
|
+
block.transformation === undefined
|
|
441
|
+
) {
|
|
442
|
+
throw new Error(
|
|
443
|
+
'Derived image is missing original data or policy identity',
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
const originalSource = normalizeBase64Source(block.originalData);
|
|
447
|
+
const originalMimeType = block.originalMimeType ?? block.mimeType;
|
|
448
|
+
await this.store.preflightObjects([
|
|
449
|
+
sourceObject(source, block.mimeType),
|
|
450
|
+
sourceObject(originalSource, originalMimeType),
|
|
451
|
+
]);
|
|
452
|
+
const dimensions =
|
|
453
|
+
block.dimensions ?? parseImageDimensionsFromBase64(source.payload);
|
|
454
|
+
const originalDimensions =
|
|
455
|
+
block.originalDimensions ??
|
|
456
|
+
parseImageDimensionsFromBase64(originalSource.payload);
|
|
457
|
+
return this.store.admit({
|
|
458
|
+
bytes: decodeCanonicalBase64(source),
|
|
459
|
+
mimeType: block.mimeType,
|
|
460
|
+
...(dimensions === undefined ? {} : { dimensions }),
|
|
461
|
+
original: {
|
|
462
|
+
bytes: decodeCanonicalBase64(originalSource),
|
|
463
|
+
mimeType: originalMimeType,
|
|
464
|
+
...(originalDimensions === undefined
|
|
465
|
+
? {}
|
|
466
|
+
: { dimensions: originalDimensions }),
|
|
467
|
+
},
|
|
468
|
+
transformation: block.transformation,
|
|
469
|
+
semanticMetadata: block.semanticMetadata ?? {},
|
|
470
|
+
...(block.providerFileIds === undefined
|
|
471
|
+
? {}
|
|
472
|
+
: { providerFileIds: block.providerFileIds }),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private async admitImage(
|
|
477
|
+
block: InlineMediaBlock,
|
|
478
|
+
context: MediaAdmissionContext,
|
|
479
|
+
mediaIndex: number,
|
|
480
|
+
reservations: AdmissionReservation[],
|
|
481
|
+
): Promise<MediaReferenceBlock> {
|
|
482
|
+
let contentId: string | undefined;
|
|
483
|
+
try {
|
|
484
|
+
const source = normalizeBase64Source(block.data);
|
|
485
|
+
contentId = source.contentId;
|
|
486
|
+
const reference =
|
|
487
|
+
block.originalData === undefined
|
|
488
|
+
? await this.admitIdentity(block, source)
|
|
489
|
+
: await this.admitDerived(block, source);
|
|
490
|
+
const presented = copyModelVisibleMetadata(block, reference);
|
|
491
|
+
const ownerId = ownerIdFor(context, mediaIndex, presented.contentId);
|
|
492
|
+
await this.store.reserve(presented, ownerId);
|
|
493
|
+
this.recordReservation(reservations, {
|
|
494
|
+
contentId: presented.contentId,
|
|
495
|
+
ownerId,
|
|
496
|
+
});
|
|
497
|
+
return presented;
|
|
498
|
+
} catch (error) {
|
|
499
|
+
const knownContentId =
|
|
500
|
+
error instanceof MediaStoreError
|
|
501
|
+
? (error.contentId ?? contentId)
|
|
502
|
+
: contentId;
|
|
503
|
+
throw new MediaAdmissionError(
|
|
504
|
+
context,
|
|
505
|
+
mediaIndex,
|
|
506
|
+
knownContentId,
|
|
507
|
+
undefined,
|
|
508
|
+
error,
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|