@vertesia/workflow 0.24.0-dev.202601221707
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/LICENSE +13 -0
- package/README.md +65 -0
- package/bin/bundle-workflows.mjs +39 -0
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js +33 -0
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -0
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +73 -0
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -0
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js +19 -0
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -0
- package/lib/cjs/activities/chunkDocument.js +85 -0
- package/lib/cjs/activities/chunkDocument.js.map +1 -0
- package/lib/cjs/activities/copyParentArtifacts.js +127 -0
- package/lib/cjs/activities/copyParentArtifacts.js.map +1 -0
- package/lib/cjs/activities/createDocumentFromOther.js +64 -0
- package/lib/cjs/activities/createDocumentFromOther.js.map +1 -0
- package/lib/cjs/activities/executeInteraction.js +194 -0
- package/lib/cjs/activities/executeInteraction.js.map +1 -0
- package/lib/cjs/activities/extractDocumentText.js +156 -0
- package/lib/cjs/activities/extractDocumentText.js.map +1 -0
- package/lib/cjs/activities/generateDocumentProperties.js +83 -0
- package/lib/cjs/activities/generateDocumentProperties.js.map +1 -0
- package/lib/cjs/activities/generateEmbeddings.js +257 -0
- package/lib/cjs/activities/generateEmbeddings.js.map +1 -0
- package/lib/cjs/activities/generateOrAssignContentType.js +125 -0
- package/lib/cjs/activities/generateOrAssignContentType.js.map +1 -0
- package/lib/cjs/activities/getObjectFromStore.js +20 -0
- package/lib/cjs/activities/getObjectFromStore.js.map +1 -0
- package/lib/cjs/activities/handleError.js +22 -0
- package/lib/cjs/activities/handleError.js.map +1 -0
- package/lib/cjs/activities/index-dsl.js +51 -0
- package/lib/cjs/activities/index-dsl.js.map +1 -0
- package/lib/cjs/activities/index.js +21 -0
- package/lib/cjs/activities/index.js.map +1 -0
- package/lib/cjs/activities/media/prepareAudio.js +239 -0
- package/lib/cjs/activities/media/prepareAudio.js.map +1 -0
- package/lib/cjs/activities/media/prepareVideo.js +429 -0
- package/lib/cjs/activities/media/prepareVideo.js.map +1 -0
- package/lib/cjs/activities/media/processPdfWithTextract.js +103 -0
- package/lib/cjs/activities/media/processPdfWithTextract.js.map +1 -0
- package/lib/cjs/activities/media/saveGladiaTranscription.js +81 -0
- package/lib/cjs/activities/media/saveGladiaTranscription.js.map +1 -0
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js +82 -0
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +1 -0
- package/lib/cjs/activities/notifyWebhook.js +158 -0
- package/lib/cjs/activities/notifyWebhook.js.map +1 -0
- package/lib/cjs/activities/rateLimiter.js +30 -0
- package/lib/cjs/activities/rateLimiter.js.map +1 -0
- package/lib/cjs/activities/renditions/generateImageRendition.js +66 -0
- package/lib/cjs/activities/renditions/generateImageRendition.js.map +1 -0
- package/lib/cjs/activities/renditions/generateVideoRendition.js +200 -0
- package/lib/cjs/activities/renditions/generateVideoRendition.js.map +1 -0
- package/lib/cjs/activities/setDocumentStatus.js +15 -0
- package/lib/cjs/activities/setDocumentStatus.js.map +1 -0
- package/lib/cjs/conversion/TextractProcessor.js +417 -0
- package/lib/cjs/conversion/TextractProcessor.js.map +1 -0
- package/lib/cjs/conversion/image.js +149 -0
- package/lib/cjs/conversion/image.js.map +1 -0
- package/lib/cjs/conversion/markitdown.js +42 -0
- package/lib/cjs/conversion/markitdown.js.map +1 -0
- package/lib/cjs/conversion/mutool.js +147 -0
- package/lib/cjs/conversion/mutool.js.map +1 -0
- package/lib/cjs/conversion/pandoc.js +39 -0
- package/lib/cjs/conversion/pandoc.js.map +1 -0
- package/lib/cjs/dsl/conditions.js +81 -0
- package/lib/cjs/dsl/conditions.js.map +1 -0
- package/lib/cjs/dsl/dsl-workflow.js +343 -0
- package/lib/cjs/dsl/dsl-workflow.js.map +1 -0
- package/lib/cjs/dsl/dslProxyActivities.js +23 -0
- package/lib/cjs/dsl/dslProxyActivities.js.map +1 -0
- package/lib/cjs/dsl/projections.js +59 -0
- package/lib/cjs/dsl/projections.js.map +1 -0
- package/lib/cjs/dsl/setup/ActivityContext.js +122 -0
- package/lib/cjs/dsl/setup/ActivityContext.js.map +1 -0
- package/lib/cjs/dsl/setup/fetch/DataProvider.js +51 -0
- package/lib/cjs/dsl/setup/fetch/DataProvider.js.map +1 -0
- package/lib/cjs/dsl/setup/fetch/index.js +16 -0
- package/lib/cjs/dsl/setup/fetch/index.js.map +1 -0
- package/lib/cjs/dsl/setup/fetch/providers.js +67 -0
- package/lib/cjs/dsl/setup/fetch/providers.js.map +1 -0
- package/lib/cjs/dsl/test/test-child-workflow.js +10 -0
- package/lib/cjs/dsl/test/test-child-workflow.js.map +1 -0
- package/lib/cjs/dsl/validation.js +122 -0
- package/lib/cjs/dsl/validation.js.map +1 -0
- package/lib/cjs/dsl/vars.js +341 -0
- package/lib/cjs/dsl/vars.js.map +1 -0
- package/lib/cjs/dsl/walk.js +100 -0
- package/lib/cjs/dsl/walk.js.map +1 -0
- package/lib/cjs/dsl.js +20 -0
- package/lib/cjs/dsl.js.map +1 -0
- package/lib/cjs/errors.js +79 -0
- package/lib/cjs/errors.js.map +1 -0
- package/lib/cjs/index.js +56 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/extractToc.js +47 -0
- package/lib/cjs/iterative-generation/activities/extractToc.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js +72 -0
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/generatePart.js +78 -0
- package/lib/cjs/iterative-generation/activities/generatePart.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/generateToc.js +86 -0
- package/lib/cjs/iterative-generation/activities/generateToc.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/index.js +12 -0
- package/lib/cjs/iterative-generation/activities/index.js.map +1 -0
- package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js +56 -0
- package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js.map +1 -0
- package/lib/cjs/iterative-generation/types.js +5 -0
- package/lib/cjs/iterative-generation/types.js.map +1 -0
- package/lib/cjs/iterative-generation/utils.js +121 -0
- package/lib/cjs/iterative-generation/utils.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/result-types.js +10 -0
- package/lib/cjs/result-types.js.map +1 -0
- package/lib/cjs/system/notifyWebhookWorkflow.js +53 -0
- package/lib/cjs/system/notifyWebhookWorkflow.js.map +1 -0
- package/lib/cjs/system/recalculateEmbeddingsWorkflow.js +33 -0
- package/lib/cjs/system/recalculateEmbeddingsWorkflow.js.map +1 -0
- package/lib/cjs/utils/auth.js +15 -0
- package/lib/cjs/utils/auth.js.map +1 -0
- package/lib/cjs/utils/blobs.js +64 -0
- package/lib/cjs/utils/blobs.js.map +1 -0
- package/lib/cjs/utils/chunks.js +14 -0
- package/lib/cjs/utils/chunks.js.map +1 -0
- package/lib/cjs/utils/client.js +31 -0
- package/lib/cjs/utils/client.js.map +1 -0
- package/lib/cjs/utils/expand-vars.js +33 -0
- package/lib/cjs/utils/expand-vars.js.map +1 -0
- package/lib/cjs/utils/memory.js +65 -0
- package/lib/cjs/utils/memory.js.map +1 -0
- package/lib/cjs/utils/renditions.js +88 -0
- package/lib/cjs/utils/renditions.js.map +1 -0
- package/lib/cjs/utils/storage.js +54 -0
- package/lib/cjs/utils/storage.js.map +1 -0
- package/lib/cjs/utils/tokens.js +38 -0
- package/lib/cjs/utils/tokens.js.map +1 -0
- package/lib/cjs/vars.js +20 -0
- package/lib/cjs/vars.js.map +1 -0
- package/lib/cjs/workflows.js +15 -0
- package/lib/cjs/workflows.js.map +1 -0
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js +30 -0
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -0
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +70 -0
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -0
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js +16 -0
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -0
- package/lib/esm/activities/chunkDocument.js +82 -0
- package/lib/esm/activities/chunkDocument.js.map +1 -0
- package/lib/esm/activities/copyParentArtifacts.js +124 -0
- package/lib/esm/activities/copyParentArtifacts.js.map +1 -0
- package/lib/esm/activities/createDocumentFromOther.js +58 -0
- package/lib/esm/activities/createDocumentFromOther.js.map +1 -0
- package/lib/esm/activities/executeInteraction.js +190 -0
- package/lib/esm/activities/executeInteraction.js.map +1 -0
- package/lib/esm/activities/extractDocumentText.js +153 -0
- package/lib/esm/activities/extractDocumentText.js.map +1 -0
- package/lib/esm/activities/generateDocumentProperties.js +80 -0
- package/lib/esm/activities/generateDocumentProperties.js.map +1 -0
- package/lib/esm/activities/generateEmbeddings.js +254 -0
- package/lib/esm/activities/generateEmbeddings.js.map +1 -0
- package/lib/esm/activities/generateOrAssignContentType.js +122 -0
- package/lib/esm/activities/generateOrAssignContentType.js.map +1 -0
- package/lib/esm/activities/getObjectFromStore.js +17 -0
- package/lib/esm/activities/getObjectFromStore.js.map +1 -0
- package/lib/esm/activities/handleError.js +19 -0
- package/lib/esm/activities/handleError.js.map +1 -0
- package/lib/esm/activities/index-dsl.js +25 -0
- package/lib/esm/activities/index-dsl.js.map +1 -0
- package/lib/esm/activities/index.js +5 -0
- package/lib/esm/activities/index.js.map +1 -0
- package/lib/esm/activities/media/prepareAudio.js +200 -0
- package/lib/esm/activities/media/prepareAudio.js.map +1 -0
- package/lib/esm/activities/media/prepareVideo.js +390 -0
- package/lib/esm/activities/media/prepareVideo.js.map +1 -0
- package/lib/esm/activities/media/processPdfWithTextract.js +99 -0
- package/lib/esm/activities/media/processPdfWithTextract.js.map +1 -0
- package/lib/esm/activities/media/saveGladiaTranscription.js +78 -0
- package/lib/esm/activities/media/saveGladiaTranscription.js.map +1 -0
- package/lib/esm/activities/media/transcribeMediaWithGladia.js +79 -0
- package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +1 -0
- package/lib/esm/activities/notifyWebhook.js +155 -0
- package/lib/esm/activities/notifyWebhook.js.map +1 -0
- package/lib/esm/activities/rateLimiter.js +27 -0
- package/lib/esm/activities/rateLimiter.js.map +1 -0
- package/lib/esm/activities/renditions/generateImageRendition.js +63 -0
- package/lib/esm/activities/renditions/generateImageRendition.js.map +1 -0
- package/lib/esm/activities/renditions/generateVideoRendition.js +194 -0
- package/lib/esm/activities/renditions/generateVideoRendition.js.map +1 -0
- package/lib/esm/activities/setDocumentStatus.js +12 -0
- package/lib/esm/activities/setDocumentStatus.js.map +1 -0
- package/lib/esm/conversion/TextractProcessor.js +410 -0
- package/lib/esm/conversion/TextractProcessor.js.map +1 -0
- package/lib/esm/conversion/image.js +143 -0
- package/lib/esm/conversion/image.js.map +1 -0
- package/lib/esm/conversion/markitdown.js +36 -0
- package/lib/esm/conversion/markitdown.js.map +1 -0
- package/lib/esm/conversion/mutool.js +139 -0
- package/lib/esm/conversion/mutool.js.map +1 -0
- package/lib/esm/conversion/pandoc.js +36 -0
- package/lib/esm/conversion/pandoc.js.map +1 -0
- package/lib/esm/dsl/conditions.js +75 -0
- package/lib/esm/dsl/conditions.js.map +1 -0
- package/lib/esm/dsl/dsl-workflow.js +336 -0
- package/lib/esm/dsl/dsl-workflow.js.map +1 -0
- package/lib/esm/dsl/dslProxyActivities.js +20 -0
- package/lib/esm/dsl/dslProxyActivities.js.map +1 -0
- package/lib/esm/dsl/projections.js +55 -0
- package/lib/esm/dsl/projections.js.map +1 -0
- package/lib/esm/dsl/setup/ActivityContext.js +117 -0
- package/lib/esm/dsl/setup/ActivityContext.js.map +1 -0
- package/lib/esm/dsl/setup/fetch/DataProvider.js +47 -0
- package/lib/esm/dsl/setup/fetch/DataProvider.js.map +1 -0
- package/lib/esm/dsl/setup/fetch/index.js +12 -0
- package/lib/esm/dsl/setup/fetch/index.js.map +1 -0
- package/lib/esm/dsl/setup/fetch/providers.js +61 -0
- package/lib/esm/dsl/setup/fetch/providers.js.map +1 -0
- package/lib/esm/dsl/test/test-child-workflow.js +5 -0
- package/lib/esm/dsl/test/test-child-workflow.js.map +1 -0
- package/lib/esm/dsl/validation.js +118 -0
- package/lib/esm/dsl/validation.js.map +1 -0
- package/lib/esm/dsl/vars.js +335 -0
- package/lib/esm/dsl/vars.js.map +1 -0
- package/lib/esm/dsl/walk.js +96 -0
- package/lib/esm/dsl/walk.js.map +1 -0
- package/lib/esm/dsl.js +4 -0
- package/lib/esm/dsl.js.map +1 -0
- package/lib/esm/errors.js +69 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/index.js +38 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/iterative-generation/activities/extractToc.js +44 -0
- package/lib/esm/iterative-generation/activities/extractToc.js.map +1 -0
- package/lib/esm/iterative-generation/activities/finalizeOutput.js +69 -0
- package/lib/esm/iterative-generation/activities/finalizeOutput.js.map +1 -0
- package/lib/esm/iterative-generation/activities/generatePart.js +75 -0
- package/lib/esm/iterative-generation/activities/generatePart.js.map +1 -0
- package/lib/esm/iterative-generation/activities/generateToc.js +83 -0
- package/lib/esm/iterative-generation/activities/generateToc.js.map +1 -0
- package/lib/esm/iterative-generation/activities/index.js +5 -0
- package/lib/esm/iterative-generation/activities/index.js.map +1 -0
- package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js +53 -0
- package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js.map +1 -0
- package/lib/esm/iterative-generation/types.js +2 -0
- package/lib/esm/iterative-generation/types.js.map +1 -0
- package/lib/esm/iterative-generation/utils.js +112 -0
- package/lib/esm/iterative-generation/utils.js.map +1 -0
- package/lib/esm/result-types.js +7 -0
- package/lib/esm/result-types.js.map +1 -0
- package/lib/esm/system/notifyWebhookWorkflow.js +50 -0
- package/lib/esm/system/notifyWebhookWorkflow.js.map +1 -0
- package/lib/esm/system/recalculateEmbeddingsWorkflow.js +30 -0
- package/lib/esm/system/recalculateEmbeddingsWorkflow.js.map +1 -0
- package/lib/esm/utils/auth.js +8 -0
- package/lib/esm/utils/auth.js.map +1 -0
- package/lib/esm/utils/blobs.js +54 -0
- package/lib/esm/utils/blobs.js.map +1 -0
- package/lib/esm/utils/chunks.js +9 -0
- package/lib/esm/utils/chunks.js.map +1 -0
- package/lib/esm/utils/client.js +27 -0
- package/lib/esm/utils/client.js.map +1 -0
- package/lib/esm/utils/expand-vars.js +30 -0
- package/lib/esm/utils/expand-vars.js.map +1 -0
- package/lib/esm/utils/memory.js +55 -0
- package/lib/esm/utils/memory.js.map +1 -0
- package/lib/esm/utils/renditions.js +80 -0
- package/lib/esm/utils/renditions.js.map +1 -0
- package/lib/esm/utils/storage.js +45 -0
- package/lib/esm/utils/storage.js.map +1 -0
- package/lib/esm/utils/tokens.js +34 -0
- package/lib/esm/utils/tokens.js.map +1 -0
- package/lib/esm/vars.js +4 -0
- package/lib/esm/vars.js.map +1 -0
- package/lib/esm/workflows.js +8 -0
- package/lib/esm/workflows.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts +17 -0
- package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts.map +1 -0
- package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts +39 -0
- package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts.map +1 -0
- package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts +19 -0
- package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts.map +1 -0
- package/lib/types/activities/chunkDocument.d.ts +33 -0
- package/lib/types/activities/chunkDocument.d.ts.map +1 -0
- package/lib/types/activities/copyParentArtifacts.d.ts +19 -0
- package/lib/types/activities/copyParentArtifacts.d.ts.map +1 -0
- package/lib/types/activities/createDocumentFromOther.d.ts +21 -0
- package/lib/types/activities/createDocumentFromOther.d.ts.map +1 -0
- package/lib/types/activities/executeInteraction.d.ts +61 -0
- package/lib/types/activities/executeInteraction.d.ts.map +1 -0
- package/lib/types/activities/extractDocumentText.d.ts +10 -0
- package/lib/types/activities/extractDocumentText.d.ts.map +1 -0
- package/lib/types/activities/generateDocumentProperties.d.ts +32 -0
- package/lib/types/activities/generateDocumentProperties.d.ts.map +1 -0
- package/lib/types/activities/generateEmbeddings.d.ts +53 -0
- package/lib/types/activities/generateEmbeddings.d.ts.map +1 -0
- package/lib/types/activities/generateOrAssignContentType.d.ts +44 -0
- package/lib/types/activities/generateOrAssignContentType.d.ts.map +1 -0
- package/lib/types/activities/getObjectFromStore.d.ts +14 -0
- package/lib/types/activities/getObjectFromStore.d.ts.map +1 -0
- package/lib/types/activities/handleError.d.ts +6 -0
- package/lib/types/activities/handleError.d.ts.map +1 -0
- package/lib/types/activities/index-dsl.d.ts +25 -0
- package/lib/types/activities/index-dsl.d.ts.map +1 -0
- package/lib/types/activities/index.d.ts +5 -0
- package/lib/types/activities/index.d.ts.map +1 -0
- package/lib/types/activities/media/prepareAudio.d.ts +25 -0
- package/lib/types/activities/media/prepareAudio.d.ts.map +1 -0
- package/lib/types/activities/media/prepareVideo.d.ts +30 -0
- package/lib/types/activities/media/prepareVideo.d.ts.map +1 -0
- package/lib/types/activities/media/processPdfWithTextract.d.ts +26 -0
- package/lib/types/activities/media/processPdfWithTextract.d.ts.map +1 -0
- package/lib/types/activities/media/saveGladiaTranscription.d.ts +14 -0
- package/lib/types/activities/media/saveGladiaTranscription.d.ts.map +1 -0
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts +19 -0
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +1 -0
- package/lib/types/activities/notifyWebhook.d.ts +27 -0
- package/lib/types/activities/notifyWebhook.d.ts.map +1 -0
- package/lib/types/activities/rateLimiter.d.ts +11 -0
- package/lib/types/activities/rateLimiter.d.ts.map +1 -0
- package/lib/types/activities/renditions/generateImageRendition.d.ts +14 -0
- package/lib/types/activities/renditions/generateImageRendition.d.ts.map +1 -0
- package/lib/types/activities/renditions/generateVideoRendition.d.ts +15 -0
- package/lib/types/activities/renditions/generateVideoRendition.d.ts.map +1 -0
- package/lib/types/activities/setDocumentStatus.d.ts +15 -0
- package/lib/types/activities/setDocumentStatus.d.ts.map +1 -0
- package/lib/types/conversion/TextractProcessor.d.ts +45 -0
- package/lib/types/conversion/TextractProcessor.d.ts.map +1 -0
- package/lib/types/conversion/image.d.ts +13 -0
- package/lib/types/conversion/image.d.ts.map +1 -0
- package/lib/types/conversion/markitdown.d.ts +2 -0
- package/lib/types/conversion/markitdown.d.ts.map +1 -0
- package/lib/types/conversion/mutool.d.ts +19 -0
- package/lib/types/conversion/mutool.d.ts.map +1 -0
- package/lib/types/conversion/pandoc.d.ts +2 -0
- package/lib/types/conversion/pandoc.d.ts.map +1 -0
- package/lib/types/dsl/conditions.d.ts +2 -0
- package/lib/types/dsl/conditions.d.ts.map +1 -0
- package/lib/types/dsl/dsl-workflow.d.ts +5 -0
- package/lib/types/dsl/dsl-workflow.d.ts.map +1 -0
- package/lib/types/dsl/dslProxyActivities.d.ts +10 -0
- package/lib/types/dsl/dslProxyActivities.d.ts.map +1 -0
- package/lib/types/dsl/projections.d.ts +4 -0
- package/lib/types/dsl/projections.d.ts.map +1 -0
- package/lib/types/dsl/setup/ActivityContext.d.ts +17 -0
- package/lib/types/dsl/setup/ActivityContext.d.ts.map +1 -0
- package/lib/types/dsl/setup/fetch/DataProvider.d.ts +9 -0
- package/lib/types/dsl/setup/fetch/DataProvider.d.ts.map +1 -0
- package/lib/types/dsl/setup/fetch/index.d.ts +6 -0
- package/lib/types/dsl/setup/fetch/index.d.ts.map +1 -0
- package/lib/types/dsl/setup/fetch/providers.d.ts +25 -0
- package/lib/types/dsl/setup/fetch/providers.d.ts.map +1 -0
- package/lib/types/dsl/test/test-child-workflow.d.ts +4 -0
- package/lib/types/dsl/test/test-child-workflow.d.ts.map +1 -0
- package/lib/types/dsl/validation.d.ts +4 -0
- package/lib/types/dsl/validation.d.ts.map +1 -0
- package/lib/types/dsl/vars.d.ts +48 -0
- package/lib/types/dsl/vars.d.ts.map +1 -0
- package/lib/types/dsl/walk.d.ts +18 -0
- package/lib/types/dsl/walk.d.ts.map +1 -0
- package/lib/types/dsl.d.ts +4 -0
- package/lib/types/dsl.d.ts.map +1 -0
- package/lib/types/errors.d.ts +37 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/index.d.ts +37 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/iterative-generation/activities/extractToc.d.ts +10 -0
- package/lib/types/iterative-generation/activities/extractToc.d.ts.map +1 -0
- package/lib/types/iterative-generation/activities/finalizeOutput.d.ts +3 -0
- package/lib/types/iterative-generation/activities/finalizeOutput.d.ts.map +1 -0
- package/lib/types/iterative-generation/activities/generatePart.d.ts +3 -0
- package/lib/types/iterative-generation/activities/generatePart.d.ts.map +1 -0
- package/lib/types/iterative-generation/activities/generateToc.d.ts +4 -0
- package/lib/types/iterative-generation/activities/generateToc.d.ts.map +1 -0
- package/lib/types/iterative-generation/activities/index.d.ts +5 -0
- package/lib/types/iterative-generation/activities/index.d.ts.map +1 -0
- package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts +3 -0
- package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts.map +1 -0
- package/lib/types/iterative-generation/types.d.ts +79 -0
- package/lib/types/iterative-generation/types.d.ts.map +1 -0
- package/lib/types/iterative-generation/utils.d.ts +26 -0
- package/lib/types/iterative-generation/utils.d.ts.map +1 -0
- package/lib/types/result-types.d.ts +22 -0
- package/lib/types/result-types.d.ts.map +1 -0
- package/lib/types/system/notifyWebhookWorkflow.d.ts +8 -0
- package/lib/types/system/notifyWebhookWorkflow.d.ts.map +1 -0
- package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts +25 -0
- package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts.map +1 -0
- package/lib/types/utils/auth.d.ts +4 -0
- package/lib/types/utils/auth.d.ts.map +1 -0
- package/lib/types/utils/blobs.d.ts +7 -0
- package/lib/types/utils/blobs.d.ts.map +1 -0
- package/lib/types/utils/chunks.d.ts +9 -0
- package/lib/types/utils/chunks.d.ts.map +1 -0
- package/lib/types/utils/client.d.ts +8 -0
- package/lib/types/utils/client.d.ts.map +1 -0
- package/lib/types/utils/expand-vars.d.ts +8 -0
- package/lib/types/utils/expand-vars.d.ts.map +1 -0
- package/lib/types/utils/memory.d.ts +8 -0
- package/lib/types/utils/memory.d.ts.map +1 -0
- package/lib/types/utils/renditions.d.ts +23 -0
- package/lib/types/utils/renditions.d.ts.map +1 -0
- package/lib/types/utils/storage.d.ts +16 -0
- package/lib/types/utils/storage.d.ts.map +1 -0
- package/lib/types/utils/tokens.d.ts +11 -0
- package/lib/types/utils/tokens.d.ts.map +1 -0
- package/lib/types/vars.d.ts +3 -0
- package/lib/types/vars.d.ts.map +1 -0
- package/lib/types/workflows.d.ts +8 -0
- package/lib/types/workflows.d.ts.map +1 -0
- package/lib/workflows-bundle.js +17213 -0
- package/package.json +146 -0
- package/src/activities/advanced/createDocumentTypeFromInteractionRun.ts +55 -0
- package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +119 -0
- package/src/activities/advanced/updateDocumentFromInteractionRun.ts +35 -0
- package/src/activities/chunkDocument.ts +146 -0
- package/src/activities/copyParentArtifacts.ts +162 -0
- package/src/activities/createDocumentFromOther.ts +92 -0
- package/src/activities/executeInteraction.ts +300 -0
- package/src/activities/extractDocumentText.ts +205 -0
- package/src/activities/generateDocumentProperties.ts +120 -0
- package/src/activities/generateEmbeddings.ts +387 -0
- package/src/activities/generateOrAssignContentType.ts +218 -0
- package/src/activities/getObjectFromStore.ts +31 -0
- package/src/activities/handleError.ts +25 -0
- package/src/activities/index-dsl.ts +25 -0
- package/src/activities/index.ts +4 -0
- package/src/activities/media/prepareAudio.ts +334 -0
- package/src/activities/media/prepareVideo.ts +622 -0
- package/src/activities/media/processPdfWithTextract.ts +141 -0
- package/src/activities/media/saveGladiaTranscription.ts +128 -0
- package/src/activities/media/transcribeMediaWithGladia.ts +117 -0
- package/src/activities/notifyWebhook.test.ts +134 -0
- package/src/activities/notifyWebhook.ts +199 -0
- package/src/activities/rateLimiter.ts +41 -0
- package/src/activities/renditions/generateImageRendition.ts +111 -0
- package/src/activities/renditions/generateVideoRendition.ts +293 -0
- package/src/activities/setDocumentStatus.ts +25 -0
- package/src/conversion/TextractProcessor.ts +506 -0
- package/src/conversion/image.test.ts +118 -0
- package/src/conversion/image.ts +168 -0
- package/src/conversion/markitdown.ts +41 -0
- package/src/conversion/mutool.test.ts +74 -0
- package/src/conversion/mutool.ts +180 -0
- package/src/conversion/pandoc.test.ts +24 -0
- package/src/conversion/pandoc.ts +40 -0
- package/src/dsl/conditions.ts +76 -0
- package/src/dsl/dsl-workflow.test.ts +58 -0
- package/src/dsl/dsl-workflow.ts +397 -0
- package/src/dsl/dslProxyActivities.ts +38 -0
- package/src/dsl/ms.d.ts +11 -0
- package/src/dsl/projections.test.ts +159 -0
- package/src/dsl/projections.ts +72 -0
- package/src/dsl/setup/ActivityContext.ts +178 -0
- package/src/dsl/setup/fetch/DataProvider.ts +45 -0
- package/src/dsl/setup/fetch/index.ts +19 -0
- package/src/dsl/setup/fetch/providers.ts +67 -0
- package/src/dsl/test/test-child-workflow.ts +6 -0
- package/src/dsl/validation.test.ts +257 -0
- package/src/dsl/validation.ts +125 -0
- package/src/dsl/vars.test.ts +245 -0
- package/src/dsl/vars.ts +340 -0
- package/src/dsl/walk.test.ts +81 -0
- package/src/dsl/walk.ts +103 -0
- package/src/dsl/workflow-exec-child.test.ts +273 -0
- package/src/dsl/workflow-fetch.test.ts +138 -0
- package/src/dsl/workflow-import.test.ts +89 -0
- package/src/dsl/workflow.test.ts +122 -0
- package/src/dsl.ts +3 -0
- package/src/errors.ts +101 -0
- package/src/index.ts +41 -0
- package/src/iterative-generation/activities/extractToc.ts +63 -0
- package/src/iterative-generation/activities/finalizeOutput.ts +100 -0
- package/src/iterative-generation/activities/generatePart.ts +123 -0
- package/src/iterative-generation/activities/generateToc.ts +116 -0
- package/src/iterative-generation/activities/index.ts +4 -0
- package/src/iterative-generation/iterativeGenerationWorkflow.ts +68 -0
- package/src/iterative-generation/types.ts +99 -0
- package/src/iterative-generation/utils.ts +126 -0
- package/src/result-types.ts +25 -0
- package/src/system/notifyWebhookWorkflow.ts +70 -0
- package/src/system/recalculateEmbeddingsWorkflow.ts +41 -0
- package/src/utils/auth.ts +10 -0
- package/src/utils/blobs.ts +59 -0
- package/src/utils/chunks.ts +17 -0
- package/src/utils/client.ts +46 -0
- package/src/utils/expand-vars.ts +31 -0
- package/src/utils/memory.ts +61 -0
- package/src/utils/renditions.ts +127 -0
- package/src/utils/storage.ts +60 -0
- package/src/utils/tokens.ts +44 -0
- package/src/vars.ts +3 -0
- package/src/workflows.ts +7 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { log } from "@temporalio/activity";
|
|
2
|
+
import { VertesiaClient } from "@vertesia/client";
|
|
3
|
+
import { ApiVersions, DSLActivityExecutionPayload, DSLActivitySpec, WebHookSpec, WorkflowExecutionBaseParams } from "@vertesia/common";
|
|
4
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
5
|
+
import { WorkflowParamNotFoundError } from "../errors.js";
|
|
6
|
+
import { getVertesiaClientOptions } from "../utils/client.js";
|
|
7
|
+
|
|
8
|
+
export interface NotifyWebhookParams {
|
|
9
|
+
webhook: string | WebHookSpec; //URL to send the notification to
|
|
10
|
+
workflow_id: string; //The ID of the workflow sending the notification
|
|
11
|
+
workflow_type: string; //The type of workflow sending the notification (the wf function name)
|
|
12
|
+
workflow_run_id: string; //The ID of the specific workflow run sending the notification
|
|
13
|
+
event_name: string; //The event that triggered the notification (e.g. "completed", "failed", etc.)
|
|
14
|
+
detail?: Record<string, any>; // additional data about the event if any. It will be send to the webhook when using POST
|
|
15
|
+
//target_url: string; //URL to send the notification to
|
|
16
|
+
method: 'GET' | 'POST'; //HTTP method to use
|
|
17
|
+
headers?: Record<string, string>; // additional headers to send
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WebhookNotificationPayload {
|
|
21
|
+
workflow_id: string,
|
|
22
|
+
workflow_name: string,
|
|
23
|
+
workflow_run_id: string,
|
|
24
|
+
event_name: string,
|
|
25
|
+
detail?: Record<string, any>,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface NotifyWebhook extends DSLActivitySpec<NotifyWebhookParams> {
|
|
29
|
+
name: 'notifyWebhook';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export async function notifyWebhook(payload: DSLActivityExecutionPayload<NotifyWebhookParams>) {
|
|
34
|
+
|
|
35
|
+
const { params } = await setupActivity<NotifyWebhookParams>(payload);
|
|
36
|
+
const { webhook, method, headers: defaultHeaders } = params
|
|
37
|
+
// resolve the url and the api version of the webhook
|
|
38
|
+
let target_url: string, version: number | undefined;
|
|
39
|
+
if (typeof webhook === 'string') {
|
|
40
|
+
target_url = webhook;
|
|
41
|
+
} else {
|
|
42
|
+
target_url = webhook.url;
|
|
43
|
+
version = webhook.version;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!target_url) throw new WorkflowParamNotFoundError('target_url');
|
|
47
|
+
|
|
48
|
+
const hasBody = params.detail && method === 'POST'; //body is sent only for POST
|
|
49
|
+
|
|
50
|
+
const headers = {
|
|
51
|
+
...defaultHeaders,
|
|
52
|
+
};
|
|
53
|
+
if (hasBody) {
|
|
54
|
+
headers['Content-Type'] = 'application/json';
|
|
55
|
+
}
|
|
56
|
+
const body = hasBody ? await createRequestBody(payload, params, version) : undefined
|
|
57
|
+
|
|
58
|
+
log.info(`Notifying webhook at ${target_url}`);
|
|
59
|
+
const res = await fetch(target_url, {
|
|
60
|
+
method,
|
|
61
|
+
body,
|
|
62
|
+
headers,
|
|
63
|
+
}).catch(err => {
|
|
64
|
+
log.error(`An error occurred while notifying webhook at ${target_url}`, { err });
|
|
65
|
+
throw err;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
log.warn(`Webhook endpoint ${target_url} returned an error - ${res.status} ${res.statusText}`, { fetchResponse: res });
|
|
70
|
+
|
|
71
|
+
// Try to get response payload for error message
|
|
72
|
+
let errorMessage = `Webhook Notification to ${target_url} failed with status: ${res.status} ${res.statusText}`;
|
|
73
|
+
try {
|
|
74
|
+
const responseText = await res.text();
|
|
75
|
+
if (responseText) {
|
|
76
|
+
errorMessage += ` - Response: ${responseText}`;
|
|
77
|
+
}
|
|
78
|
+
} catch (readError) {
|
|
79
|
+
// If we can't read the response, just use the basic error message
|
|
80
|
+
log.debug('Could not read response body for error', { readError });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
throw new Error(errorMessage);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return { status: res.status, message: res.statusText, url: res.url }
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// --------------------------------------
|
|
93
|
+
// Data provider for webhooks
|
|
94
|
+
// this allows to customize the payload sent to the webhook depending on the
|
|
95
|
+
// type of workflow and the api version of the webhook
|
|
96
|
+
// --------------------------------------
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
function getWorkflowName(workflowType: string): string {
|
|
100
|
+
// remove trailing Workflow or _Workflow case insensitive from the workflow type
|
|
101
|
+
return workflowType.replace(/_?workflow$/i, '');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function createRequestBody(payload: WorkflowExecutionBaseParams, params: NotifyWebhookParams, api_version: number | undefined): Promise<string> {
|
|
105
|
+
if (api_version === undefined || Number(api_version) < ApiVersions.COMPLETION_RESULT_V1) {
|
|
106
|
+
return createOldRequestBody(payload, params);
|
|
107
|
+
} else {
|
|
108
|
+
return createLatestRequestBody(payload, params, api_version);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function createLatestRequestBody(payload: WorkflowExecutionBaseParams, params: NotifyWebhookParams, api_version: number | undefined): Promise<string> {
|
|
113
|
+
const data = await createEventData(payload, params, api_version);
|
|
114
|
+
return JSON.stringify({
|
|
115
|
+
workflow_id: params.workflow_id,
|
|
116
|
+
workflow_name: getWorkflowName(params.workflow_type),
|
|
117
|
+
workflow_run_id: params.workflow_run_id,
|
|
118
|
+
event_name: params.event_name,
|
|
119
|
+
detail: data,
|
|
120
|
+
} satisfies WebhookNotificationPayload);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function createEventData(payload: WorkflowExecutionBaseParams, params: NotifyWebhookParams, api_version: number | undefined): Promise<any> {
|
|
124
|
+
const data = params.detail;
|
|
125
|
+
if (data && data.run_id && params.event_name === "workflow_completed" && params.workflow_type === 'ExecuteInteractionWorkflow') {
|
|
126
|
+
const client = getVersionedVertesiaClient(payload, api_version); //ensure client is initialized
|
|
127
|
+
// we replace the result property with the full execution run object
|
|
128
|
+
return await client.runs.retrieve(data.run_id);
|
|
129
|
+
}
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
function getVersionedVertesiaClient(payload: WorkflowExecutionBaseParams, version: string | number | undefined | null) {
|
|
135
|
+
// set the api version header
|
|
136
|
+
return new VertesiaClient(getVertesiaClientOptions(payload)).withApiVersion(version ? String(version) : null);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
// ----------------- Compatibility code -----------------
|
|
141
|
+
/* Before 2025-10-08 the notifyWebhook POST body was in the format:
|
|
142
|
+
|
|
143
|
+
{
|
|
144
|
+
"workflowId": "generation:ExecuteInteractionWorkflow:WhatColor:ox8wu6t4",
|
|
145
|
+
"runId": "0199c2c6-818f-77eb-b931-c1ba8b9e5184",
|
|
146
|
+
"status": "completed",
|
|
147
|
+
"result": {
|
|
148
|
+
"run_id": "68e616274b0e9bb510462378",
|
|
149
|
+
"status": "completed",
|
|
150
|
+
"result": {"Color": "white"}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
After Versions.COMPLETION_RESULT_V1 (20250925) when the completion result interface changed we improved the
|
|
155
|
+
payload to the current format:
|
|
156
|
+
|
|
157
|
+
{
|
|
158
|
+
"workflow_id": "generation:ExecuteInteractionWorkflow:WhatColor:bdedqjqj6",
|
|
159
|
+
"workflow_name": "ExecuteInteraction",
|
|
160
|
+
"workflow_run_id": "0199c2d4-6b1d-7cf2-a1e5-4cac6778091e",
|
|
161
|
+
"event_name": "workflow_completed",
|
|
162
|
+
"detail": ExecutionRun
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
where ExecutionRun contains a result property with the new completion result format.
|
|
166
|
+
|
|
167
|
+
"result": [
|
|
168
|
+
{
|
|
169
|
+
"type": "json",
|
|
170
|
+
"value": {
|
|
171
|
+
"Color": "white"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
//@ts-ignore
|
|
179
|
+
async function createOldRequestBody(payload: WorkflowExecutionBaseParams, params: NotifyWebhookParams): Promise<string> {
|
|
180
|
+
let data = params.detail;
|
|
181
|
+
if (data && data.run_id && params.event_name === "workflow_completed" && params.workflow_type === 'ExecuteInteractionWorkflow') {
|
|
182
|
+
const client = getVersionedVertesiaClient(payload, null); //ensure client is using no specific version
|
|
183
|
+
// Important Note: we cannot use client.runs.retrieve since it will transform the run result to the new format because of InteractionOutput
|
|
184
|
+
const run = await client.runs.get(data.run_id);
|
|
185
|
+
// since we use an unversioned client the run will be in old format so we don't need to tranform the result
|
|
186
|
+
const result = run.result;
|
|
187
|
+
data = {
|
|
188
|
+
workflowId: params.workflow_id,
|
|
189
|
+
runId: params.workflow_run_id,
|
|
190
|
+
status: params.event_name === 'workflow_completed' ? 'completed' : params.event_name,
|
|
191
|
+
result: {
|
|
192
|
+
run_id: run.id,
|
|
193
|
+
status: run.status,
|
|
194
|
+
result: result || null
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return JSON.stringify(data || {});
|
|
199
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DSLActivityExecutionPayload, RateLimitRequestPayload } from "@vertesia/common";
|
|
2
|
+
import { activityInfo, log } from "@temporalio/activity";
|
|
3
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
4
|
+
|
|
5
|
+
export interface RateLimitParams {
|
|
6
|
+
interactionIdOrEndpoint: string;
|
|
7
|
+
environmentId?: string;
|
|
8
|
+
modelId?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RateLimitResult {
|
|
12
|
+
delayMs: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function checkRateLimit(payload: DSLActivityExecutionPayload<RateLimitParams>): Promise<RateLimitResult> {
|
|
16
|
+
const { client, params } = await setupActivity<RateLimitParams>(payload);
|
|
17
|
+
const { environmentId, modelId } = params;
|
|
18
|
+
|
|
19
|
+
const result: RateLimitResult = {
|
|
20
|
+
delayMs: 0,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
// Call the studio-server endpoint to get rate limit delay using the Vertesia client
|
|
25
|
+
const info = activityInfo();
|
|
26
|
+
const requestPayload: RateLimitRequestPayload = {
|
|
27
|
+
interaction: params.interactionIdOrEndpoint,
|
|
28
|
+
workflow_run_id: info.workflowExecution.runId,
|
|
29
|
+
environment_id: environmentId,
|
|
30
|
+
model_id: modelId,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const response = await client.interactions.requestSlot(requestPayload);
|
|
34
|
+
result.delayMs = response.delay_ms;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
log.warn('Failed to call rate limit API:', {error});
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { log } from "@temporalio/activity";
|
|
2
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
|
3
|
+
import { setupActivity } from "../../dsl/setup/ActivityContext.js";
|
|
4
|
+
import { DocumentNotFoundError, WorkflowParamNotFoundError } from "../../errors.js";
|
|
5
|
+
import { saveBlobToTempFile } from "../../utils/blobs.js";
|
|
6
|
+
import {
|
|
7
|
+
ImageRenditionParams,
|
|
8
|
+
uploadRenditionPages,
|
|
9
|
+
} from "../../utils/renditions.js";
|
|
10
|
+
|
|
11
|
+
interface GenerateImageRenditionParams extends ImageRenditionParams { }
|
|
12
|
+
|
|
13
|
+
export interface GenerateImageRendition
|
|
14
|
+
extends DSLActivitySpec<GenerateImageRenditionParams> {
|
|
15
|
+
name: "generateImageRendition";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function generateImageRendition(
|
|
19
|
+
payload: DSLActivityExecutionPayload<GenerateImageRenditionParams>,
|
|
20
|
+
) {
|
|
21
|
+
const {
|
|
22
|
+
client,
|
|
23
|
+
objectId,
|
|
24
|
+
params: originParams,
|
|
25
|
+
} = await setupActivity<GenerateImageRenditionParams>(payload);
|
|
26
|
+
|
|
27
|
+
// Fix: Use maxHeightWidth if max_hw is not provided
|
|
28
|
+
const params = {
|
|
29
|
+
...originParams,
|
|
30
|
+
max_hw: originParams.max_hw || (originParams as any).maxHeightWidth || 1596, // Default to 1596 if both are missing
|
|
31
|
+
format: originParams.format || (originParams as any).format_output || "png", // Default to png if format is missing
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
log.info(`Generating image rendition for ${objectId}`, {
|
|
35
|
+
originParams,
|
|
36
|
+
params,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const inputObject = await client.objects.retrieve(objectId).catch((err) => {
|
|
40
|
+
log.error(`Failed to retrieve document ${objectId}`, { err });
|
|
41
|
+
if (err.message.includes("not found")) {
|
|
42
|
+
throw new DocumentNotFoundError(`Document ${objectId} not found`, [objectId]);
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!inputObject) {
|
|
48
|
+
log.error(`Document ${objectId} not found`);
|
|
49
|
+
throw new DocumentNotFoundError(`Document ${objectId} not found`, [objectId]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!params.format) {
|
|
53
|
+
log.error(`Format not found`);
|
|
54
|
+
throw new WorkflowParamNotFoundError(`format`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!inputObject.content?.source) {
|
|
58
|
+
log.error(`Document ${objectId} has no source`);
|
|
59
|
+
throw new DocumentNotFoundError(`Document ${objectId} has no source`, [objectId]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
!inputObject.content.type ||
|
|
64
|
+
!inputObject.content.type?.startsWith("image/")
|
|
65
|
+
) {
|
|
66
|
+
log.error(
|
|
67
|
+
`Document ${objectId} is not an image or a video: ${inputObject.content.type}`,
|
|
68
|
+
);
|
|
69
|
+
throw new DocumentNotFoundError(
|
|
70
|
+
`Document ${objectId} is not an image or a video: ${inputObject.content.type}`,
|
|
71
|
+
[objectId],
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//array of rendition files to upload
|
|
76
|
+
let renditionPages: string[] = [];
|
|
77
|
+
|
|
78
|
+
const imageFile = await saveBlobToTempFile(
|
|
79
|
+
client,
|
|
80
|
+
inputObject.content.source,
|
|
81
|
+
);
|
|
82
|
+
log.info(`Image ${objectId} copied to ${imageFile}`);
|
|
83
|
+
renditionPages.push(imageFile);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
//IF no etag, log and use use object id as etag
|
|
87
|
+
if (!inputObject.content.etag) {
|
|
88
|
+
log.warn(`Document ${objectId} has no etag, using object id as etag`);
|
|
89
|
+
}
|
|
90
|
+
const contentEtag = inputObject.content.etag ?? inputObject.id;
|
|
91
|
+
|
|
92
|
+
const uploaded = await uploadRenditionPages(
|
|
93
|
+
client,
|
|
94
|
+
contentEtag,
|
|
95
|
+
[imageFile],
|
|
96
|
+
params,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (!uploaded || !uploaded.length || !uploaded[0]) {
|
|
100
|
+
log.error(`Failed to upload rendition for ${objectId}`, { uploaded });
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Failed to upload rendition for ${objectId} - upload object is empty`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
uploads: uploaded.map((u) => u),
|
|
108
|
+
format: params.format,
|
|
109
|
+
status: "success",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { log } from "@temporalio/activity";
|
|
2
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
|
3
|
+
import { exec } from "child_process";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { promisify } from "util";
|
|
8
|
+
import { setupActivity } from "../../dsl/setup/ActivityContext.js";
|
|
9
|
+
import { DocumentNotFoundError, WorkflowParamNotFoundError } from "../../errors.js";
|
|
10
|
+
import { saveBlobToTempFile } from "../../utils/blobs.js";
|
|
11
|
+
import {
|
|
12
|
+
ImageRenditionParams,
|
|
13
|
+
uploadRenditionPages,
|
|
14
|
+
} from "../../utils/renditions.js";
|
|
15
|
+
|
|
16
|
+
const execAsync = promisify(exec);
|
|
17
|
+
|
|
18
|
+
interface GenerateVideoRenditionParams extends ImageRenditionParams { }
|
|
19
|
+
|
|
20
|
+
export interface GenerateVideoRendition
|
|
21
|
+
extends DSLActivitySpec<GenerateVideoRenditionParams> {
|
|
22
|
+
name: "generateImageRendition";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface VideoMetadata {
|
|
26
|
+
duration: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function getVideoMetadata(videoPath: string): Promise<VideoMetadata> {
|
|
32
|
+
try {
|
|
33
|
+
const command = `ffprobe -v quiet -print_format json -show_format -show_streams "${videoPath}"`;
|
|
34
|
+
const { stdout } = await execAsync(command);
|
|
35
|
+
const metadata = JSON.parse(stdout);
|
|
36
|
+
|
|
37
|
+
const videoStream = metadata.streams.find(
|
|
38
|
+
(stream: any) => stream.codec_type === "video",
|
|
39
|
+
);
|
|
40
|
+
const duration = parseFloat(metadata.format.duration) || 0;
|
|
41
|
+
const width = videoStream?.width || 0;
|
|
42
|
+
const height = videoStream?.height || 0;
|
|
43
|
+
|
|
44
|
+
return { duration, width, height };
|
|
45
|
+
} catch (error) {
|
|
46
|
+
log.error(
|
|
47
|
+
`Failed to get video metadata: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
48
|
+
);
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Failed to probe video metadata: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function generateThumbnail(
|
|
56
|
+
videoPath: string,
|
|
57
|
+
outputDir: string,
|
|
58
|
+
timestamp: number,
|
|
59
|
+
maxSize: number,
|
|
60
|
+
): Promise<string | undefined> {
|
|
61
|
+
//pad timestamp to 5 digits as filename
|
|
62
|
+
const outputFile = path.join(
|
|
63
|
+
outputDir,
|
|
64
|
+
`thumb-${timestamp.toString().padStart(5, "0")}.jpg`,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// FFmpeg command to extract thumbnail at specific timestamp
|
|
68
|
+
// Use proper scale filter syntax: scale=w:h:force_original_aspect_ratio=decrease
|
|
69
|
+
const scaleFilter = `scale=${maxSize}:${maxSize}:force_original_aspect_ratio=decrease`;
|
|
70
|
+
|
|
71
|
+
const command = [
|
|
72
|
+
"ffmpeg",
|
|
73
|
+
"-y", // Overwrite output files
|
|
74
|
+
"-ss",
|
|
75
|
+
timestamp.toString(), // Seek to timestamp
|
|
76
|
+
"-i",
|
|
77
|
+
`"${videoPath}"`, // Input file
|
|
78
|
+
"-vframes",
|
|
79
|
+
"1", // Extract only 1 frame
|
|
80
|
+
"-vf",
|
|
81
|
+
`"${scaleFilter}"`, // Scale maintaining aspect ratio
|
|
82
|
+
"-q:v",
|
|
83
|
+
"2", // High quality
|
|
84
|
+
`"${outputFile}"`,
|
|
85
|
+
].join(" ");
|
|
86
|
+
log.info(`Generating thumbnail at ${timestamp}s`), { command };
|
|
87
|
+
try {
|
|
88
|
+
const { stderr } = await execAsync(command);
|
|
89
|
+
|
|
90
|
+
// Log any warnings from ffmpeg
|
|
91
|
+
if (stderr && !stderr.includes("frame=")) {
|
|
92
|
+
log.debug(
|
|
93
|
+
`FFmpeg stderr for thumbnail at ${timestamp}s: ${stderr}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Verify the file was created
|
|
98
|
+
if (fs.existsSync(outputFile)) {
|
|
99
|
+
log.debug(`Generated thumbnail at ${timestamp}s`);
|
|
100
|
+
return outputFile;
|
|
101
|
+
} else {
|
|
102
|
+
log.warn(`Thumbnail not generated for timestamp ${timestamp}s`);
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
log.error(
|
|
107
|
+
`Failed to generate thumbnail at ${timestamp}s: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
108
|
+
);
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function generateVideoRendition(
|
|
114
|
+
payload: DSLActivityExecutionPayload<GenerateVideoRenditionParams>,
|
|
115
|
+
) {
|
|
116
|
+
const {
|
|
117
|
+
client,
|
|
118
|
+
objectId,
|
|
119
|
+
params: originParams,
|
|
120
|
+
} = await setupActivity<GenerateVideoRenditionParams>(payload);
|
|
121
|
+
|
|
122
|
+
// Fix: Use maxHeightWidth if max_hw is not provided
|
|
123
|
+
const params = {
|
|
124
|
+
...originParams,
|
|
125
|
+
max_hw:
|
|
126
|
+
originParams.max_hw || (originParams as any).maxHeightWidth || 1024, // Default to 1024 if both are missing
|
|
127
|
+
format:
|
|
128
|
+
originParams.format || (originParams as any).format_output || "png", // Default to png if format is missing
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
log.info(`Generating video rendition for ${objectId}`, {
|
|
132
|
+
originParams,
|
|
133
|
+
params,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const inputObject = await client.objects.retrieve(objectId).catch((err) => {
|
|
137
|
+
log.error(`Failed to retrieve document ${objectId}`, { err });
|
|
138
|
+
if (err.message.includes("not found")) {
|
|
139
|
+
throw new DocumentNotFoundError(`Document ${objectId} not found`, [
|
|
140
|
+
objectId,
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
throw err;
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (!params.format) {
|
|
147
|
+
log.error(`Format not found`);
|
|
148
|
+
throw new WorkflowParamNotFoundError(`format`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!inputObject.content?.source) {
|
|
152
|
+
log.error(`Document ${objectId} has no source`);
|
|
153
|
+
throw new DocumentNotFoundError(`Document ${objectId} has no source`, [
|
|
154
|
+
objectId,
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (
|
|
159
|
+
!inputObject.content.type ||
|
|
160
|
+
!inputObject.content.type?.startsWith("video/")
|
|
161
|
+
) {
|
|
162
|
+
log.error(
|
|
163
|
+
`Document ${objectId} is not a video: ${inputObject.content.type}`,
|
|
164
|
+
);
|
|
165
|
+
throw new DocumentNotFoundError(
|
|
166
|
+
`Document ${objectId} is not a video: ${inputObject.content.type}`,
|
|
167
|
+
[objectId],
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//array of rendition files to upload
|
|
172
|
+
let renditionPages: string[] = [];
|
|
173
|
+
|
|
174
|
+
const videoFile = await saveBlobToTempFile(
|
|
175
|
+
client,
|
|
176
|
+
inputObject.content.source,
|
|
177
|
+
);
|
|
178
|
+
const tempOutputDir = fs.mkdtempSync(
|
|
179
|
+
path.join(os.tmpdir(), "video-rendition-"),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
// Get video metadata using command line ffprobe
|
|
184
|
+
const metadata = await getVideoMetadata(videoFile);
|
|
185
|
+
const duration = metadata.duration;
|
|
186
|
+
|
|
187
|
+
// Calculate optimal number of thumbnails based on video length
|
|
188
|
+
const calculateThumbnailCount = (videoDuration: number): number => {
|
|
189
|
+
if (videoDuration <= 60) return 3; // Short videos: 3 thumbnails
|
|
190
|
+
if (videoDuration <= 300) return 5; // 5min videos: 5 thumbnails
|
|
191
|
+
if (videoDuration <= 600) return 8; // 10min videos: 8 thumbnails
|
|
192
|
+
if (videoDuration <= 1800) return 12; // 30min videos: 12 thumbnails
|
|
193
|
+
if (videoDuration <= 3600) return 16; // 1hr videos: 16 thumbnails
|
|
194
|
+
return 20; // Longer videos: max 20 thumbnails
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const thumbnailCount = calculateThumbnailCount(duration);
|
|
198
|
+
|
|
199
|
+
// Generate evenly spaced timestamps, avoiding very beginning and end
|
|
200
|
+
const timestamps: number[] = [];
|
|
201
|
+
const startOffset = Math.min(duration * 0.05, 5); // Skip first 5% or 5 seconds
|
|
202
|
+
const endOffset = Math.min(duration * 0.05, 5); // Skip last 5% or 5 seconds
|
|
203
|
+
const usableDuration = duration - startOffset - endOffset;
|
|
204
|
+
|
|
205
|
+
for (let i = 0; i < thumbnailCount; i++) {
|
|
206
|
+
const progress = (i + 1) / (thumbnailCount + 1); // Evenly distribute
|
|
207
|
+
const timestamp = startOffset + usableDuration * progress;
|
|
208
|
+
timestamps.push(Math.max(timestamp, 1));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
log.info(
|
|
212
|
+
`Generating ${thumbnailCount} thumbnails for ${duration}s video`,
|
|
213
|
+
{
|
|
214
|
+
objectId,
|
|
215
|
+
duration,
|
|
216
|
+
thumbnailCount,
|
|
217
|
+
timestamps: timestamps.map((t) => Math.round(t)),
|
|
218
|
+
tempOutputDir,
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
// Generate thumbnails using command line ffmpeg
|
|
223
|
+
const generatedThumbnails = await Promise.all(
|
|
224
|
+
timestamps.map(async (timestamp) => {
|
|
225
|
+
return await generateThumbnail(
|
|
226
|
+
videoFile,
|
|
227
|
+
tempOutputDir,
|
|
228
|
+
timestamp,
|
|
229
|
+
params.max_hw,
|
|
230
|
+
);
|
|
231
|
+
}),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
if (generatedThumbnails.length === 0) {
|
|
235
|
+
log.info(`No thumbnails were generated for video ${objectId}`, {
|
|
236
|
+
objectId,
|
|
237
|
+
thumbnailCount,
|
|
238
|
+
tempOutputDir,
|
|
239
|
+
});
|
|
240
|
+
throw new Error(
|
|
241
|
+
`No thumbnails were generated for video ${objectId}`,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
renditionPages.push(
|
|
246
|
+
...generatedThumbnails.filter(
|
|
247
|
+
(thumbnail) => thumbnail !== undefined,
|
|
248
|
+
),
|
|
249
|
+
);
|
|
250
|
+
log.info(
|
|
251
|
+
`Successfully generated ${generatedThumbnails.length} thumbnails for ${objectId}`,
|
|
252
|
+
{
|
|
253
|
+
objectId,
|
|
254
|
+
generatedCount: generatedThumbnails.length,
|
|
255
|
+
requestedCount: thumbnailCount,
|
|
256
|
+
},
|
|
257
|
+
);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
log.error(
|
|
260
|
+
`Error generating thumbnails for video: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
261
|
+
);
|
|
262
|
+
throw new Error(`Failed to generate thumbnails for video: ${objectId}`);
|
|
263
|
+
} finally {
|
|
264
|
+
// Clean up temporary video file
|
|
265
|
+
try {
|
|
266
|
+
if (fs.existsSync(videoFile)) {
|
|
267
|
+
fs.unlinkSync(videoFile);
|
|
268
|
+
}
|
|
269
|
+
} catch (cleanupError) {
|
|
270
|
+
log.warn(`Failed to cleanup temporary video file: ${videoFile}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!inputObject.content?.etag) {
|
|
275
|
+
log.warn(`Document ${objectId} has no etag, using object id as etag`);
|
|
276
|
+
}
|
|
277
|
+
const etag = inputObject.content.etag ?? inputObject.id;
|
|
278
|
+
|
|
279
|
+
// Update the final upload call to handle multiple thumbnails
|
|
280
|
+
const uploaded = await uploadRenditionPages(
|
|
281
|
+
client,
|
|
282
|
+
etag,
|
|
283
|
+
renditionPages,
|
|
284
|
+
params,
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
uploads: uploaded.map((u) => u),
|
|
289
|
+
format: params.format,
|
|
290
|
+
thumbnailCount: renditionPages.length,
|
|
291
|
+
status: "success",
|
|
292
|
+
};
|
|
293
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ContentObjectStatus, DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
|
2
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
3
|
+
|
|
4
|
+
export interface SetDocumentStatusParams {
|
|
5
|
+
status: ContentObjectStatus;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SetDocumentStatus extends DSLActivitySpec<SetDocumentStatusParams> {
|
|
9
|
+
name: 'setDocumentStatus';
|
|
10
|
+
projection?: never;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* We are using a union type for the status parameter since typescript enums breaks the workflow code generation
|
|
15
|
+
* @param objectId
|
|
16
|
+
* @param status
|
|
17
|
+
*/
|
|
18
|
+
export async function setDocumentStatus(payload: DSLActivityExecutionPayload<SetDocumentStatusParams>) {
|
|
19
|
+
const { client, params, objectId } = await setupActivity<SetDocumentStatusParams>(payload);
|
|
20
|
+
|
|
21
|
+
const res = await client.objects.update(objectId, { status: params.status });
|
|
22
|
+
|
|
23
|
+
return res.status;
|
|
24
|
+
|
|
25
|
+
}
|