@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,643 @@
|
|
|
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 type {
|
|
9
|
+
MediaDimensions,
|
|
10
|
+
MediaReferenceBlock,
|
|
11
|
+
MediaSemanticMetadata,
|
|
12
|
+
MediaSemanticMetadataValue,
|
|
13
|
+
MediaStoredObject,
|
|
14
|
+
MediaTransformation,
|
|
15
|
+
} from '../services/history/IContent.js';
|
|
16
|
+
import {
|
|
17
|
+
MediaObjectCorruptError,
|
|
18
|
+
MediaStoreError,
|
|
19
|
+
type MediaAdmissionInput,
|
|
20
|
+
type MediaTransformationInput,
|
|
21
|
+
type PreparedAdmission,
|
|
22
|
+
type ReservationRecord,
|
|
23
|
+
type StoreLockOwner,
|
|
24
|
+
} from './local-media-store-types.js';
|
|
25
|
+
|
|
26
|
+
export const CONTENT_ID_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
27
|
+
export const MIME_TYPE_PATTERN =
|
|
28
|
+
/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
29
|
+
export const DIGEST_PATTERN = /^[0-9a-f]{64}$/;
|
|
30
|
+
export const CONTENT_ID_PREFIX = 'sha256:';
|
|
31
|
+
export const RESERVATION_VERSION = 1;
|
|
32
|
+
export const LOCK_VERSION = 1;
|
|
33
|
+
|
|
34
|
+
export function hasErrnoCode(error: unknown, code: string): boolean {
|
|
35
|
+
return (
|
|
36
|
+
typeof error === 'object' &&
|
|
37
|
+
error !== null &&
|
|
38
|
+
Reflect.get(error, 'code') === code
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function contentIdFor(bytes: Uint8Array): string {
|
|
43
|
+
return `${CONTENT_ID_PREFIX}${createHash('sha256').update(bytes).digest('hex')}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function digestFor(contentId: string): string {
|
|
47
|
+
return contentId.slice(CONTENT_ID_PREFIX.length);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isNonNegativeSafeInteger(value: number): boolean {
|
|
51
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isPositiveSafeInteger(value: number): boolean {
|
|
55
|
+
return Number.isSafeInteger(value) && value > 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isUnknownArray(value: unknown): value is unknown[] {
|
|
59
|
+
return Array.isArray(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
63
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const prototype: unknown = Object.getPrototypeOf(value);
|
|
67
|
+
return prototype === Object.prototype || prototype === null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function validDimensions(value: unknown): value is MediaDimensions {
|
|
71
|
+
if (!isPlainRecord(value) || Object.keys(value).length !== 2) return false;
|
|
72
|
+
const width = value['width'];
|
|
73
|
+
const height = value['height'];
|
|
74
|
+
if (typeof width !== 'number' || typeof height !== 'number') return false;
|
|
75
|
+
return isPositiveSafeInteger(width) && isPositiveSafeInteger(height);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const MAX_SEMANTIC_METADATA_DEPTH = 64;
|
|
79
|
+
|
|
80
|
+
function semanticChildPath(parent: string, key: string): string {
|
|
81
|
+
return /^[A-Za-z_$][\w$]*$/.test(key)
|
|
82
|
+
? `${parent}.${key}`
|
|
83
|
+
: `${parent}[${JSON.stringify(key)}]`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function cloneSemanticValue(
|
|
87
|
+
value: unknown,
|
|
88
|
+
ancestors: Set<object>,
|
|
89
|
+
depth: number,
|
|
90
|
+
location: string,
|
|
91
|
+
): MediaSemanticMetadataValue {
|
|
92
|
+
if (
|
|
93
|
+
value === null ||
|
|
94
|
+
typeof value === 'string' ||
|
|
95
|
+
typeof value === 'boolean'
|
|
96
|
+
) {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
if (typeof value === 'number') {
|
|
100
|
+
if (!Number.isFinite(value)) throw new Error('numbers must be finite');
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
if (typeof value !== 'object') {
|
|
104
|
+
throw new Error('values must be JSON-compatible');
|
|
105
|
+
}
|
|
106
|
+
if (depth > MAX_SEMANTIC_METADATA_DEPTH) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`${location} exceeds maximum depth ${MAX_SEMANTIC_METADATA_DEPTH}`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (ancestors.has(value)) throw new Error('cycles are not allowed');
|
|
112
|
+
ancestors.add(value);
|
|
113
|
+
try {
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
return Object.freeze(
|
|
116
|
+
value.map((entry, index) =>
|
|
117
|
+
cloneSemanticValue(
|
|
118
|
+
entry,
|
|
119
|
+
ancestors,
|
|
120
|
+
depth + 1,
|
|
121
|
+
`${location}[${index}]`,
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (!isPlainRecord(value)) {
|
|
127
|
+
throw new Error('objects must have a plain prototype');
|
|
128
|
+
}
|
|
129
|
+
const cloned: Record<string, MediaSemanticMetadataValue> = {};
|
|
130
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
131
|
+
if (key.length === 0) throw new Error('keys must not be empty');
|
|
132
|
+
cloned[key] = cloneSemanticValue(
|
|
133
|
+
entry,
|
|
134
|
+
ancestors,
|
|
135
|
+
depth + 1,
|
|
136
|
+
semanticChildPath(location, key),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return Object.freeze(cloned);
|
|
140
|
+
} finally {
|
|
141
|
+
ancestors.delete(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function cloneSemanticMetadata(value: unknown): MediaSemanticMetadata {
|
|
146
|
+
if (!isPlainRecord(value)) {
|
|
147
|
+
throw new Error('metadata must be a plain object');
|
|
148
|
+
}
|
|
149
|
+
const cloned = cloneSemanticValue(
|
|
150
|
+
value,
|
|
151
|
+
new Set<object>(),
|
|
152
|
+
0,
|
|
153
|
+
'semanticMetadata',
|
|
154
|
+
);
|
|
155
|
+
if (!isPlainRecord(cloned)) throw new Error('metadata must be an object');
|
|
156
|
+
return cloned;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function cloneProviderFileIds(
|
|
160
|
+
value: unknown,
|
|
161
|
+
): Readonly<Record<string, string>> {
|
|
162
|
+
if (!isPlainRecord(value)) {
|
|
163
|
+
throw new Error('provider file IDs must be a plain object');
|
|
164
|
+
}
|
|
165
|
+
const cloned: Record<string, string> = {};
|
|
166
|
+
for (const [provider, fileId] of Object.entries(value)) {
|
|
167
|
+
if (
|
|
168
|
+
provider.length === 0 ||
|
|
169
|
+
typeof fileId !== 'string' ||
|
|
170
|
+
fileId.length === 0
|
|
171
|
+
) {
|
|
172
|
+
throw new Error('provider names and file IDs must not be empty');
|
|
173
|
+
}
|
|
174
|
+
cloned[provider] = fileId;
|
|
175
|
+
}
|
|
176
|
+
return Object.freeze(cloned);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function validateContentId(contentId: string, operation: string): void {
|
|
180
|
+
if (!CONTENT_ID_PATTERN.test(contentId)) {
|
|
181
|
+
throw new MediaStoreError(
|
|
182
|
+
operation,
|
|
183
|
+
contentId,
|
|
184
|
+
new Error('Invalid content ID'),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function validatePositiveDuration(value: number, name: string): void {
|
|
190
|
+
if (!isPositiveSafeInteger(value)) {
|
|
191
|
+
throw new MediaStoreError(
|
|
192
|
+
'initialize',
|
|
193
|
+
undefined,
|
|
194
|
+
new Error(`${name} must be a positive safe integer`),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function wrapError(
|
|
200
|
+
operation: string,
|
|
201
|
+
contentId: string | undefined,
|
|
202
|
+
error: unknown,
|
|
203
|
+
): MediaStoreError {
|
|
204
|
+
if (error instanceof MediaStoreError) return error;
|
|
205
|
+
return new MediaStoreError(operation, contentId, error);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function processIsAlive(pid: number): boolean {
|
|
209
|
+
try {
|
|
210
|
+
process.kill(pid, 0);
|
|
211
|
+
return true;
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return !hasErrnoCode(error, 'ESRCH');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function hasValidLockOwnerFields(value: Record<string, unknown>): boolean {
|
|
218
|
+
if (value['version'] !== LOCK_VERSION) return false;
|
|
219
|
+
if (typeof value['token'] !== 'string' || value['token'].length === 0) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (typeof value['pid'] !== 'number') return false;
|
|
223
|
+
if (!isPositiveSafeInteger(value['pid'])) return false;
|
|
224
|
+
if (typeof value['hostname'] !== 'string') return false;
|
|
225
|
+
if (value['hostname'].length === 0) return false;
|
|
226
|
+
if (typeof value['createdAt'] !== 'number') return false;
|
|
227
|
+
return isNonNegativeSafeInteger(value['createdAt']);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function parseStoreLockOwner(
|
|
231
|
+
value: unknown,
|
|
232
|
+
): StoreLockOwner | undefined {
|
|
233
|
+
if (!isPlainRecord(value) || !hasValidLockOwnerFields(value))
|
|
234
|
+
return undefined;
|
|
235
|
+
const token = value['token'];
|
|
236
|
+
const pid = value['pid'];
|
|
237
|
+
const ownerHostname = value['hostname'];
|
|
238
|
+
const createdAt = value['createdAt'];
|
|
239
|
+
if (
|
|
240
|
+
typeof token !== 'string' ||
|
|
241
|
+
typeof pid !== 'number' ||
|
|
242
|
+
typeof ownerHostname !== 'string' ||
|
|
243
|
+
typeof createdAt !== 'number'
|
|
244
|
+
) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
version: LOCK_VERSION,
|
|
249
|
+
token,
|
|
250
|
+
pid,
|
|
251
|
+
hostname: ownerHostname,
|
|
252
|
+
createdAt,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function hasValidReservationIdentity(value: Record<string, unknown>): boolean {
|
|
257
|
+
if (value['version'] !== RESERVATION_VERSION) return false;
|
|
258
|
+
if (typeof value['ownerDigest'] !== 'string') return false;
|
|
259
|
+
if (!DIGEST_PATTERN.test(value['ownerDigest'])) return false;
|
|
260
|
+
if (typeof value['instanceId'] !== 'string') return false;
|
|
261
|
+
if (value['instanceId'].length === 0) return false;
|
|
262
|
+
if (typeof value['pid'] !== 'number') return false;
|
|
263
|
+
if (!isPositiveSafeInteger(value['pid'])) return false;
|
|
264
|
+
if (typeof value['hostname'] !== 'string') return false;
|
|
265
|
+
return value['hostname'].length > 0;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function hasValidReservationTimes(value: Record<string, unknown>): boolean {
|
|
269
|
+
if (typeof value['createdAt'] !== 'number') return false;
|
|
270
|
+
if (!isNonNegativeSafeInteger(value['createdAt'])) return false;
|
|
271
|
+
if (typeof value['expiresAt'] !== 'number') return false;
|
|
272
|
+
return isNonNegativeSafeInteger(value['expiresAt']);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function validRelatedContentIds(value: unknown): value is string[] {
|
|
276
|
+
if (!isUnknownArray(value) || value.length === 0) return false;
|
|
277
|
+
return value.every(
|
|
278
|
+
(contentId) =>
|
|
279
|
+
typeof contentId === 'string' && CONTENT_ID_PATTERN.test(contentId),
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function parseReservationRecord(
|
|
284
|
+
value: unknown,
|
|
285
|
+
): ReservationRecord | undefined {
|
|
286
|
+
if (!isPlainRecord(value)) return undefined;
|
|
287
|
+
if (!hasValidReservationIdentity(value)) return undefined;
|
|
288
|
+
if (!hasValidReservationTimes(value)) return undefined;
|
|
289
|
+
const relatedContentIds = value['relatedContentIds'];
|
|
290
|
+
if (!validRelatedContentIds(relatedContentIds)) return undefined;
|
|
291
|
+
return buildReservationRecord(value, relatedContentIds);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function buildReservationRecord(
|
|
295
|
+
value: Record<string, unknown>,
|
|
296
|
+
relatedContentIds: readonly string[],
|
|
297
|
+
): ReservationRecord | undefined {
|
|
298
|
+
const ownerDigest = value['ownerDigest'];
|
|
299
|
+
if (typeof ownerDigest !== 'string') return undefined;
|
|
300
|
+
const instanceId = value['instanceId'];
|
|
301
|
+
if (typeof instanceId !== 'string') return undefined;
|
|
302
|
+
const pid = value['pid'];
|
|
303
|
+
if (typeof pid !== 'number') return undefined;
|
|
304
|
+
const ownerHostname = value['hostname'];
|
|
305
|
+
if (typeof ownerHostname !== 'string') return undefined;
|
|
306
|
+
const createdAt = value['createdAt'];
|
|
307
|
+
if (typeof createdAt !== 'number') return undefined;
|
|
308
|
+
const expiresAt = value['expiresAt'];
|
|
309
|
+
if (typeof expiresAt !== 'number') return undefined;
|
|
310
|
+
return {
|
|
311
|
+
version: RESERVATION_VERSION,
|
|
312
|
+
ownerDigest,
|
|
313
|
+
instanceId,
|
|
314
|
+
pid,
|
|
315
|
+
hostname: ownerHostname,
|
|
316
|
+
createdAt,
|
|
317
|
+
expiresAt,
|
|
318
|
+
relatedContentIds,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function validateStoredObjectMetadata(
|
|
323
|
+
object: MediaStoredObject,
|
|
324
|
+
operation: string,
|
|
325
|
+
): void {
|
|
326
|
+
validateContentId(object.contentId, operation);
|
|
327
|
+
if (!MIME_TYPE_PATTERN.test(object.mimeType)) {
|
|
328
|
+
throwMalformedStoredObject(object, operation);
|
|
329
|
+
}
|
|
330
|
+
if (!isPositiveSafeInteger(object.byteLength)) {
|
|
331
|
+
throwMalformedStoredObject(object, operation);
|
|
332
|
+
}
|
|
333
|
+
if (object.normalizedBase64Length !== Math.ceil(object.byteLength / 3) * 4) {
|
|
334
|
+
throwMalformedStoredObject(object, operation);
|
|
335
|
+
}
|
|
336
|
+
if (object.dimensions !== undefined && !validDimensions(object.dimensions)) {
|
|
337
|
+
throwMalformedStoredObject(object, operation);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function throwMalformedStoredObject(
|
|
342
|
+
object: MediaStoredObject,
|
|
343
|
+
operation: string,
|
|
344
|
+
): never {
|
|
345
|
+
throw new MediaObjectCorruptError(
|
|
346
|
+
operation,
|
|
347
|
+
object.contentId,
|
|
348
|
+
new Error('Malformed stored object metadata'),
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function buildStoredObject(
|
|
353
|
+
contentId: string,
|
|
354
|
+
mimeType: string,
|
|
355
|
+
byteLength: number,
|
|
356
|
+
dimensionsValue: unknown,
|
|
357
|
+
): MediaStoredObject {
|
|
358
|
+
validateContentId(contentId, 'validate stored object');
|
|
359
|
+
if (!MIME_TYPE_PATTERN.test(mimeType)) {
|
|
360
|
+
throw new MediaStoreError(
|
|
361
|
+
'validate MIME type',
|
|
362
|
+
contentId,
|
|
363
|
+
new Error('Invalid MIME type'),
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
if (!isPositiveSafeInteger(byteLength)) {
|
|
367
|
+
throw new MediaStoreError(
|
|
368
|
+
'validate byte length',
|
|
369
|
+
contentId,
|
|
370
|
+
new Error('Byte length must be a positive safe integer'),
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
const dimensions = validatedDimensions(dimensionsValue, contentId);
|
|
374
|
+
return Object.freeze({
|
|
375
|
+
contentId,
|
|
376
|
+
mimeType,
|
|
377
|
+
byteLength,
|
|
378
|
+
normalizedBase64Length: Math.ceil(byteLength / 3) * 4,
|
|
379
|
+
...(dimensions === undefined ? {} : { dimensions }),
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function validatedDimensions(
|
|
384
|
+
value: unknown,
|
|
385
|
+
contentId: string,
|
|
386
|
+
): MediaDimensions | undefined {
|
|
387
|
+
if (value === undefined) return undefined;
|
|
388
|
+
if (!validDimensions(value)) {
|
|
389
|
+
throw new MediaStoreError(
|
|
390
|
+
'validate dimensions',
|
|
391
|
+
contentId,
|
|
392
|
+
new Error('Malformed dimensions'),
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
return Object.freeze({ width: value.width, height: value.height });
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function validatedSemanticMetadata(
|
|
399
|
+
value: unknown,
|
|
400
|
+
contentId: string,
|
|
401
|
+
): MediaSemanticMetadata {
|
|
402
|
+
try {
|
|
403
|
+
return cloneSemanticMetadata(value);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
throw new MediaStoreError('validate semantic metadata', contentId, error);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function validatedProviderFileIds(
|
|
410
|
+
value: unknown,
|
|
411
|
+
contentId: string,
|
|
412
|
+
): Readonly<Record<string, string>> | undefined {
|
|
413
|
+
if (value === undefined) return undefined;
|
|
414
|
+
try {
|
|
415
|
+
return cloneProviderFileIds(value);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
throw new MediaStoreError('validate provider file IDs', contentId, error);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function validatedTransformation(
|
|
422
|
+
value: MediaTransformationInput | undefined,
|
|
423
|
+
identity: boolean,
|
|
424
|
+
contentId: string,
|
|
425
|
+
): MediaTransformation {
|
|
426
|
+
if (value === undefined) return identityTransformation(identity, contentId);
|
|
427
|
+
if (
|
|
428
|
+
value.policyId.length === 0 ||
|
|
429
|
+
!isPositiveSafeInteger(value.policyVersion)
|
|
430
|
+
) {
|
|
431
|
+
throw new MediaStoreError(
|
|
432
|
+
'validate transformation',
|
|
433
|
+
contentId,
|
|
434
|
+
new Error('Invalid transformation policy identity'),
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
return Object.freeze({
|
|
438
|
+
policyId: value.policyId,
|
|
439
|
+
policyVersion: value.policyVersion,
|
|
440
|
+
parameters: validatedSemanticMetadata(value.parameters ?? {}, contentId),
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function identityTransformation(
|
|
445
|
+
identity: boolean,
|
|
446
|
+
contentId: string,
|
|
447
|
+
): MediaTransformation {
|
|
448
|
+
if (!identity) {
|
|
449
|
+
throw new MediaStoreError(
|
|
450
|
+
'validate transformation',
|
|
451
|
+
contentId,
|
|
452
|
+
new Error('Derived media requires transformation policy identity'),
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return Object.freeze({
|
|
456
|
+
policyId: 'identity',
|
|
457
|
+
policyVersion: 1,
|
|
458
|
+
parameters: Object.freeze({}),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function prepareAdmission(
|
|
463
|
+
input: MediaAdmissionInput,
|
|
464
|
+
selectedBytes: Uint8Array,
|
|
465
|
+
originalBytes: Uint8Array,
|
|
466
|
+
): PreparedAdmission {
|
|
467
|
+
if (selectedBytes.byteLength === 0 || originalBytes.byteLength === 0) {
|
|
468
|
+
throw new MediaStoreError(
|
|
469
|
+
'admit empty bytes',
|
|
470
|
+
undefined,
|
|
471
|
+
new Error('Media bytes must not be empty'),
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
const selectedContentId = contentIdFor(selectedBytes);
|
|
475
|
+
validateKnownByteLength(input, selectedBytes, selectedContentId);
|
|
476
|
+
const selected = buildStoredObject(
|
|
477
|
+
selectedContentId,
|
|
478
|
+
input.mimeType,
|
|
479
|
+
selectedBytes.byteLength,
|
|
480
|
+
input.dimensions,
|
|
481
|
+
);
|
|
482
|
+
const original = buildStoredObject(
|
|
483
|
+
contentIdFor(originalBytes),
|
|
484
|
+
input.original?.mimeType ?? input.mimeType,
|
|
485
|
+
originalBytes.byteLength,
|
|
486
|
+
input.original?.dimensions ?? input.dimensions,
|
|
487
|
+
);
|
|
488
|
+
const providerFileIds = validatedProviderFileIds(
|
|
489
|
+
input.providerFileIds,
|
|
490
|
+
selectedContentId,
|
|
491
|
+
);
|
|
492
|
+
return {
|
|
493
|
+
selected,
|
|
494
|
+
selectedBytes,
|
|
495
|
+
original,
|
|
496
|
+
originalBytes,
|
|
497
|
+
transformation: validatedTransformation(
|
|
498
|
+
input.transformation,
|
|
499
|
+
original.contentId === selected.contentId,
|
|
500
|
+
selectedContentId,
|
|
501
|
+
),
|
|
502
|
+
semanticMetadata: validatedSemanticMetadata(
|
|
503
|
+
input.semanticMetadata,
|
|
504
|
+
selectedContentId,
|
|
505
|
+
),
|
|
506
|
+
...(providerFileIds === undefined ? {} : { providerFileIds }),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function validateKnownByteLength(
|
|
511
|
+
input: MediaAdmissionInput,
|
|
512
|
+
selectedBytes: Uint8Array,
|
|
513
|
+
contentId: string,
|
|
514
|
+
): void {
|
|
515
|
+
if (input.knownByteLength === undefined) return;
|
|
516
|
+
if (
|
|
517
|
+
isPositiveSafeInteger(input.knownByteLength) &&
|
|
518
|
+
input.knownByteLength === selectedBytes.byteLength
|
|
519
|
+
) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
throw new MediaStoreError(
|
|
523
|
+
'validate known byte length',
|
|
524
|
+
contentId,
|
|
525
|
+
new Error('Known byte length is inconsistent with actual bytes'),
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export function buildReference(
|
|
530
|
+
prepared: PreparedAdmission,
|
|
531
|
+
): MediaReferenceBlock {
|
|
532
|
+
return Object.freeze({
|
|
533
|
+
type: 'media',
|
|
534
|
+
encoding: 'reference',
|
|
535
|
+
mimeType: prepared.selected.mimeType,
|
|
536
|
+
contentId: prepared.selected.contentId,
|
|
537
|
+
originalContentId: prepared.original.contentId,
|
|
538
|
+
selectedContentId: prepared.selected.contentId,
|
|
539
|
+
originalObject: prepared.original,
|
|
540
|
+
selectedObject: prepared.selected,
|
|
541
|
+
transformation: prepared.transformation,
|
|
542
|
+
byteLength: prepared.selected.byteLength,
|
|
543
|
+
normalizedBase64Length: prepared.selected.normalizedBase64Length,
|
|
544
|
+
...(prepared.selected.dimensions === undefined
|
|
545
|
+
? {}
|
|
546
|
+
: { dimensions: prepared.selected.dimensions }),
|
|
547
|
+
semanticMetadata: prepared.semanticMetadata,
|
|
548
|
+
...(prepared.providerFileIds === undefined
|
|
549
|
+
? {}
|
|
550
|
+
: { providerFileIds: prepared.providerFileIds }),
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export function buildIdentityReference(
|
|
555
|
+
object: MediaStoredObject,
|
|
556
|
+
semanticMetadata: MediaSemanticMetadata,
|
|
557
|
+
providerFileIds: Readonly<Record<string, string>> | undefined,
|
|
558
|
+
): MediaReferenceBlock {
|
|
559
|
+
return Object.freeze({
|
|
560
|
+
type: 'media',
|
|
561
|
+
encoding: 'reference',
|
|
562
|
+
mimeType: object.mimeType,
|
|
563
|
+
contentId: object.contentId,
|
|
564
|
+
originalContentId: object.contentId,
|
|
565
|
+
selectedContentId: object.contentId,
|
|
566
|
+
originalObject: object,
|
|
567
|
+
selectedObject: object,
|
|
568
|
+
transformation: identityTransformation(true, object.contentId),
|
|
569
|
+
byteLength: object.byteLength,
|
|
570
|
+
normalizedBase64Length: object.normalizedBase64Length,
|
|
571
|
+
...(object.dimensions === undefined
|
|
572
|
+
? {}
|
|
573
|
+
: { dimensions: object.dimensions }),
|
|
574
|
+
semanticMetadata,
|
|
575
|
+
...(providerFileIds === undefined ? {} : { providerFileIds }),
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export function uniqueStoredObjects(
|
|
580
|
+
objects: readonly MediaStoredObject[],
|
|
581
|
+
): ReadonlyMap<string, MediaStoredObject> {
|
|
582
|
+
const unique = new Map<string, MediaStoredObject>();
|
|
583
|
+
for (const object of objects) {
|
|
584
|
+
validateStoredObjectMetadata(object, 'validate object batch');
|
|
585
|
+
const existing = unique.get(object.contentId);
|
|
586
|
+
const dimensionsDiffer =
|
|
587
|
+
existing?.dimensions?.width !== object.dimensions?.width ||
|
|
588
|
+
existing?.dimensions?.height !== object.dimensions?.height;
|
|
589
|
+
if (
|
|
590
|
+
existing !== undefined &&
|
|
591
|
+
(existing.mimeType !== object.mimeType ||
|
|
592
|
+
existing.byteLength !== object.byteLength ||
|
|
593
|
+
dimensionsDiffer)
|
|
594
|
+
) {
|
|
595
|
+
throw new MediaStoreError(
|
|
596
|
+
'validate object batch',
|
|
597
|
+
object.contentId,
|
|
598
|
+
new Error('Conflicting stored object metadata'),
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
unique.set(object.contentId, object);
|
|
602
|
+
}
|
|
603
|
+
return unique;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function requiredObjects(
|
|
607
|
+
reference: MediaReferenceBlock,
|
|
608
|
+
): readonly MediaStoredObject[] {
|
|
609
|
+
if (
|
|
610
|
+
reference.originalObject.contentId === reference.selectedObject.contentId
|
|
611
|
+
) {
|
|
612
|
+
return [reference.selectedObject];
|
|
613
|
+
}
|
|
614
|
+
return [reference.originalObject, reference.selectedObject];
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function containsControlCharacter(value: string): boolean {
|
|
618
|
+
for (const character of value) {
|
|
619
|
+
const code = character.charCodeAt(0);
|
|
620
|
+
if (code <= 0x1f || code === 0x7f) return true;
|
|
621
|
+
}
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export function validateOwnerId(
|
|
626
|
+
ownerId: string,
|
|
627
|
+
contentId: string,
|
|
628
|
+
operation: string,
|
|
629
|
+
): void {
|
|
630
|
+
if (
|
|
631
|
+
ownerId.length === 0 ||
|
|
632
|
+
ownerId.length > 512 ||
|
|
633
|
+
containsControlCharacter(ownerId)
|
|
634
|
+
) {
|
|
635
|
+
throw new MediaStoreError(
|
|
636
|
+
operation,
|
|
637
|
+
contentId,
|
|
638
|
+
new Error(
|
|
639
|
+
'Owner ID must contain between 1 and 512 non-control characters',
|
|
640
|
+
),
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
}
|