@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,218 @@
|
|
|
1
|
+
import { log } from "@temporalio/activity";
|
|
2
|
+
import {
|
|
3
|
+
ContentObjectTypeItem,
|
|
4
|
+
CreateContentObjectTypePayload,
|
|
5
|
+
DSLActivityExecutionPayload,
|
|
6
|
+
DSLActivitySpec,
|
|
7
|
+
ImageRenditionFormat,
|
|
8
|
+
} from "@vertesia/common";
|
|
9
|
+
import {
|
|
10
|
+
ActivityContext,
|
|
11
|
+
setupActivity,
|
|
12
|
+
} from "../dsl/setup/ActivityContext.js";
|
|
13
|
+
import { TruncateSpec, truncByMaxTokens } from "../utils/tokens.js";
|
|
14
|
+
import {
|
|
15
|
+
InteractionExecutionParams,
|
|
16
|
+
executeInteractionFromActivity,
|
|
17
|
+
} from "./executeInteraction.js";
|
|
18
|
+
|
|
19
|
+
const INT_SELECT_DOCUMENT_TYPE = "sys:SelectDocumentType";
|
|
20
|
+
const INT_GENERATE_METADATA_MODEL = "sys:GenerateMetadataModel";
|
|
21
|
+
|
|
22
|
+
export interface GenerateOrAssignContentTypeParams
|
|
23
|
+
extends InteractionExecutionParams {
|
|
24
|
+
typesHint?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* truncate the input doc text to the specified max_tokens
|
|
27
|
+
*/
|
|
28
|
+
truncate?: TruncateSpec;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The name of the interaction to execute
|
|
32
|
+
* @default SelectDocumentType
|
|
33
|
+
*/
|
|
34
|
+
interactionNames?: {
|
|
35
|
+
selectDocumentType?: string;
|
|
36
|
+
generateMetadataModel?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface GenerateOrAssignContentType
|
|
41
|
+
extends DSLActivitySpec<GenerateOrAssignContentTypeParams> {
|
|
42
|
+
name: "generateOrAssignContentType";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function generateOrAssignContentType(
|
|
46
|
+
payload: DSLActivityExecutionPayload<GenerateOrAssignContentTypeParams>,
|
|
47
|
+
) {
|
|
48
|
+
const context =
|
|
49
|
+
await setupActivity<GenerateOrAssignContentTypeParams>(payload);
|
|
50
|
+
const { params, client, objectId } = context;
|
|
51
|
+
|
|
52
|
+
const interactionName =
|
|
53
|
+
params.interactionNames?.selectDocumentType ?? INT_SELECT_DOCUMENT_TYPE;
|
|
54
|
+
|
|
55
|
+
log.info("SelectDocumentType for object: " + objectId, { payload });
|
|
56
|
+
|
|
57
|
+
const object = await client.objects.retrieve(objectId, "+text");
|
|
58
|
+
|
|
59
|
+
//Expects object.type to be null on first ingestion of content
|
|
60
|
+
//User initiated Content Type change via the Composable UI,
|
|
61
|
+
//sets object.type to null when they let Composable choose for them.
|
|
62
|
+
//sets object.type to chosen type (thus non-null) when user picks a type.
|
|
63
|
+
if (object.type) {
|
|
64
|
+
log.warn(`Object ${objectId} has already a type. Skipping type creation.`);
|
|
65
|
+
return {
|
|
66
|
+
status: "skipped",
|
|
67
|
+
message: "Object already has a type: " + object.type.name,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (
|
|
72
|
+
!object ||
|
|
73
|
+
(!object.text &&
|
|
74
|
+
!object.content?.type?.startsWith("image/") &&
|
|
75
|
+
!object.content?.type?.startsWith("application/pdf"))
|
|
76
|
+
) {
|
|
77
|
+
log.info(`Object ${objectId} not found or text is empty and not an image`, {
|
|
78
|
+
object,
|
|
79
|
+
});
|
|
80
|
+
return { status: "failed", error: "no-text" };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const types = await client.types.list(undefined, {
|
|
84
|
+
schema: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
//make a list of all existing types, and add hints if any
|
|
88
|
+
const existing_types = types.filter(
|
|
89
|
+
(t) => !["DocumentPart", "Rendition"].includes(t.name),
|
|
90
|
+
);
|
|
91
|
+
const content = object.text
|
|
92
|
+
? truncByMaxTokens(object.text, params.truncate || 30000)
|
|
93
|
+
: undefined;
|
|
94
|
+
|
|
95
|
+
const getImage = async () => {
|
|
96
|
+
if (
|
|
97
|
+
object.content?.type?.includes("pdf") &&
|
|
98
|
+
object.text?.length &&
|
|
99
|
+
object.text?.length < 100
|
|
100
|
+
) {
|
|
101
|
+
return "store:" + objectId;
|
|
102
|
+
}
|
|
103
|
+
if (!object.content?.type?.startsWith("image/")) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const res = await client.objects.getRendition(objectId, {
|
|
107
|
+
format: ImageRenditionFormat.jpeg,
|
|
108
|
+
generate_if_missing: true,
|
|
109
|
+
});
|
|
110
|
+
if (!res.renditions?.length && res.status === "generating") {
|
|
111
|
+
//throw to try again
|
|
112
|
+
throw new Error(`Rendition for object ${objectId} is in progress`);
|
|
113
|
+
} else if (res.renditions) {
|
|
114
|
+
return "store:" + objectId;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const fileRef = await getImage();
|
|
119
|
+
|
|
120
|
+
log.info(
|
|
121
|
+
"Execute SelectDocumentType interaction on content with \nexisting types - passing full types: " +
|
|
122
|
+
existing_types.filter((t) => !t.tags?.includes("system")),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const res = await executeInteractionFromActivity(
|
|
126
|
+
client,
|
|
127
|
+
interactionName,
|
|
128
|
+
params,
|
|
129
|
+
{
|
|
130
|
+
existing_types,
|
|
131
|
+
content,
|
|
132
|
+
image: fileRef,
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const jsonResult = res.result.object();
|
|
137
|
+
|
|
138
|
+
log.info("Selected Content Type Result: " + JSON.stringify(jsonResult));
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
//if type is not identified or not present in the database, generate a new type
|
|
142
|
+
let selectedType: { id: string; name: string } | undefined = undefined;
|
|
143
|
+
|
|
144
|
+
selectedType = types.find((t) => t.name === jsonResult.document_type);
|
|
145
|
+
|
|
146
|
+
if (!selectedType) {
|
|
147
|
+
log.warn("Document type not identified: starting type generation");
|
|
148
|
+
const newType = await generateNewType(
|
|
149
|
+
context,
|
|
150
|
+
existing_types,
|
|
151
|
+
content,
|
|
152
|
+
fileRef,
|
|
153
|
+
);
|
|
154
|
+
selectedType = { id: newType.id, name: newType.name };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!selectedType) {
|
|
158
|
+
log.error("Type not found: ", res.result);
|
|
159
|
+
throw new Error("Type not found: " + jsonResult.document_type);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//update object with selected type
|
|
163
|
+
await client.objects.update(objectId, {
|
|
164
|
+
type: selectedType.id,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
id: selectedType.id,
|
|
169
|
+
name: selectedType.name,
|
|
170
|
+
isNew: !types.find((t) => t.name === selectedType.name),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function generateNewType(
|
|
175
|
+
context: ActivityContext<GenerateOrAssignContentTypeParams>,
|
|
176
|
+
existing_types: ContentObjectTypeItem[],
|
|
177
|
+
content?: string,
|
|
178
|
+
fileRef?: string,
|
|
179
|
+
) {
|
|
180
|
+
const { client, params } = context;
|
|
181
|
+
|
|
182
|
+
const project = await context.fetchProject();
|
|
183
|
+
const interactionName =
|
|
184
|
+
params.interactionNames?.generateMetadataModel ??
|
|
185
|
+
INT_GENERATE_METADATA_MODEL;
|
|
186
|
+
|
|
187
|
+
const genTypeRes = await executeInteractionFromActivity(
|
|
188
|
+
client,
|
|
189
|
+
interactionName,
|
|
190
|
+
params,
|
|
191
|
+
{
|
|
192
|
+
existing_types,
|
|
193
|
+
content: content,
|
|
194
|
+
human_context: project?.configuration?.human_context ?? undefined,
|
|
195
|
+
image: fileRef ? fileRef : undefined,
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const jsonResult = genTypeRes.result.object();
|
|
200
|
+
|
|
201
|
+
if (!jsonResult.document_type) {
|
|
202
|
+
log.error("No name generated for type", genTypeRes);
|
|
203
|
+
throw new Error("No name generated for type");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
log.info("Generated schema for type", jsonResult.metadata_schema);
|
|
207
|
+
const typeData: CreateContentObjectTypePayload = {
|
|
208
|
+
name: jsonResult.document_type,
|
|
209
|
+
description: jsonResult.document_type_description,
|
|
210
|
+
object_schema: jsonResult.metadata_schema,
|
|
211
|
+
is_chunkable: jsonResult.is_chunkable,
|
|
212
|
+
table_layout: jsonResult.table_layout,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const type = await client.types.create(typeData);
|
|
216
|
+
|
|
217
|
+
return type;
|
|
218
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ContentObject, DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
|
2
|
+
import { projectResult } from "../dsl/projections.js";
|
|
3
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface GetObjectParams {
|
|
7
|
+
select?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface GetObject extends DSLActivitySpec<GetObjectParams> {
|
|
11
|
+
name: 'getObject';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* We are using a union type for the status parameter since typescript enums breaks the workflow code generation
|
|
16
|
+
* @param objectId
|
|
17
|
+
* @param status
|
|
18
|
+
*/
|
|
19
|
+
export async function getObjectFromStore(payload: DSLActivityExecutionPayload<GetObjectParams>): Promise<ContentObject> {
|
|
20
|
+
const { client, params, objectId } = await setupActivity<GetObjectParams>(payload);
|
|
21
|
+
|
|
22
|
+
const obj = await client.objects.retrieve(objectId, params.select);
|
|
23
|
+
|
|
24
|
+
const projection = projectResult(payload, params, obj, obj);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...projection,
|
|
28
|
+
id: obj.id,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ContentObjectStatus, DSLActivityExecutionPayload } from "@vertesia/common";
|
|
2
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
3
|
+
import { log } from "@temporalio/activity"
|
|
4
|
+
|
|
5
|
+
export interface HandleDslErrorParams {
|
|
6
|
+
errorMessage: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function handleDslError(payload: DSLActivityExecutionPayload<HandleDslErrorParams>): Promise<void> {
|
|
10
|
+
const { client, params, objectId } = await setupActivity<HandleDslErrorParams>(payload);
|
|
11
|
+
const isIntake = payload.workflow_name === "StandardDocumentIntake" || payload.workflow_name === "StandardImageIntake";
|
|
12
|
+
if (!isIntake) {
|
|
13
|
+
log.warn(`Workflow execution failed, but no error handler registered for this workflow: ${payload.workflow_name}`,
|
|
14
|
+
{ error: params.errorMessage },
|
|
15
|
+
);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await client.objects.update(objectId, { status: ContentObjectStatus.failed });
|
|
21
|
+
} catch (e) {
|
|
22
|
+
log.error("Failed to handle error", { error: e });
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Export here DSL activities
|
|
2
|
+
export { createDocumentTypeFromInteractionRun } from "./advanced/createDocumentTypeFromInteractionRun.js";
|
|
3
|
+
export { createOrUpdateDocumentFromInteractionRun } from "./advanced/createOrUpdateDocumentFromInteractionRun.js";
|
|
4
|
+
export { updateDocumentFromInteractionRun } from "./advanced/updateDocumentFromInteractionRun.js";
|
|
5
|
+
export { chunkDocument } from "./chunkDocument.js";
|
|
6
|
+
export { createPdfDocumentFromSource } from "./createDocumentFromOther.js";
|
|
7
|
+
export { executeInteraction } from "./executeInteraction.js";
|
|
8
|
+
export { extractDocumentText } from "./extractDocumentText.js";
|
|
9
|
+
export { generateDocumentProperties } from "./generateDocumentProperties.js";
|
|
10
|
+
export { generateEmbeddings } from "./generateEmbeddings.js";
|
|
11
|
+
export { generateOrAssignContentType } from "./generateOrAssignContentType.js";
|
|
12
|
+
export { getObjectFromStore } from "./getObjectFromStore.js";
|
|
13
|
+
export { handleDslError } from "./handleError.js";
|
|
14
|
+
export { prepareVideo } from "./media/prepareVideo.js";
|
|
15
|
+
export { prepareAudio } from "./media/prepareAudio.js";
|
|
16
|
+
export { convertPdfToStructuredText } from "./media/processPdfWithTextract.js";
|
|
17
|
+
export { saveGladiaTranscription } from "./media/saveGladiaTranscription.js";
|
|
18
|
+
export { transcribeMedia } from "./media/transcribeMediaWithGladia.js";
|
|
19
|
+
export type { TranscriptMediaResult } from "./media/transcribeMediaWithGladia.js";
|
|
20
|
+
export { notifyWebhook } from "./notifyWebhook.js";
|
|
21
|
+
export { checkRateLimit } from "./rateLimiter.js";
|
|
22
|
+
export { copyParentArtifacts } from "./copyParentArtifacts.js";
|
|
23
|
+
export { generateImageRendition } from "./renditions/generateImageRendition.js";
|
|
24
|
+
export { generateVideoRendition } from "./renditions/generateVideoRendition.js";
|
|
25
|
+
export { setDocumentStatus } from "./setDocumentStatus.js";
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { log } from '@temporalio/activity';
|
|
2
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec, AudioMetadata, AUDIO_RENDITION_NAME, ContentNature, Rendition } 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, InvalidContentTypeError } from '../../errors.js';
|
|
10
|
+
import { saveBlobToTempFile } from '../../utils/blobs.js';
|
|
11
|
+
import { VertesiaClient } from '@vertesia/client';
|
|
12
|
+
import { RequestError } from '@vertesia/api-fetch-client';
|
|
13
|
+
|
|
14
|
+
const execAsync = promisify(exec);
|
|
15
|
+
|
|
16
|
+
// Default configuration constants
|
|
17
|
+
const DEFAULT_AUDIO_BITRATE = '128k'; // Default audio bitrate for AAC encoding
|
|
18
|
+
const FFMPEG_MAX_BUFFER = 1024 * 1024 * 10; // 10MB buffer for ffmpeg output
|
|
19
|
+
|
|
20
|
+
export interface PrepareAudioParams {
|
|
21
|
+
audioBitrate?: string; // Audio bitrate for AAC encoding, default '128k'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PrepareAudio extends DSLActivitySpec<PrepareAudioParams> {
|
|
25
|
+
name: 'prepareAudio';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface AudioMetadataExtended {
|
|
29
|
+
duration: number;
|
|
30
|
+
codec: string;
|
|
31
|
+
bitrate: number;
|
|
32
|
+
sampleRate: number;
|
|
33
|
+
channels: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface FFProbeStream {
|
|
37
|
+
codec_type: string;
|
|
38
|
+
codec_name?: string;
|
|
39
|
+
sample_rate?: string;
|
|
40
|
+
channels?: number;
|
|
41
|
+
bit_rate?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface FFProbeFormat {
|
|
45
|
+
duration?: string;
|
|
46
|
+
bit_rate?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface FFProbeOutput {
|
|
50
|
+
streams: FFProbeStream[];
|
|
51
|
+
format: FFProbeFormat;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PrepareAudioMetadata {
|
|
55
|
+
duration: number;
|
|
56
|
+
codec: string;
|
|
57
|
+
bitrate: number;
|
|
58
|
+
sampleRate: number;
|
|
59
|
+
channels: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PrepareAudioResult {
|
|
63
|
+
objectId: string;
|
|
64
|
+
metadata: PrepareAudioMetadata;
|
|
65
|
+
renditions: Rendition[];
|
|
66
|
+
status: 'success';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Extract comprehensive audio metadata using ffprobe
|
|
71
|
+
*/
|
|
72
|
+
async function getAudioMetadata(audioPath: string): Promise<AudioMetadataExtended> {
|
|
73
|
+
try {
|
|
74
|
+
const command = `ffprobe -v quiet -print_format json -show_format -show_streams "${audioPath}"`;
|
|
75
|
+
const { stdout } = await execAsync(command);
|
|
76
|
+
const metadata = JSON.parse(stdout) as FFProbeOutput;
|
|
77
|
+
|
|
78
|
+
const audioStream = metadata.streams.find(
|
|
79
|
+
(stream) => stream.codec_type === 'audio',
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (!audioStream) {
|
|
83
|
+
throw new Error('No audio stream found in file');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const duration = parseFloat(metadata.format.duration ?? '0') || 0;
|
|
87
|
+
const codec = audioStream.codec_name || 'unknown';
|
|
88
|
+
const bitrate = parseInt(audioStream.bit_rate ?? metadata.format.bit_rate ?? '0', 10) || 0;
|
|
89
|
+
const sampleRate = parseInt(audioStream.sample_rate ?? '0', 10) || 0;
|
|
90
|
+
const channels = audioStream.channels || 0;
|
|
91
|
+
|
|
92
|
+
return { duration, codec, bitrate, sampleRate, channels };
|
|
93
|
+
} catch (error) {
|
|
94
|
+
log.error(
|
|
95
|
+
`Failed to get audio metadata: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
96
|
+
);
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Failed to probe audio metadata: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Generate a web-compatible audio rendition (AAC in M4A container)
|
|
105
|
+
* Ensures broad browser compatibility for HTML5 audio playback
|
|
106
|
+
*/
|
|
107
|
+
async function generateAudioRendition(
|
|
108
|
+
audioPath: string,
|
|
109
|
+
outputDir: string,
|
|
110
|
+
audioBitrate: string,
|
|
111
|
+
): Promise<string | null> {
|
|
112
|
+
const outputFile = path.join(outputDir, 'audio.m4a');
|
|
113
|
+
|
|
114
|
+
const command = [
|
|
115
|
+
'ffmpeg',
|
|
116
|
+
'-y', // Overwrite output
|
|
117
|
+
'-i', `"${audioPath}"`,
|
|
118
|
+
'-c:a', 'aac', // AAC codec
|
|
119
|
+
'-b:a', audioBitrate, // Audio bitrate
|
|
120
|
+
'-movflags', '+faststart', // Enable streaming
|
|
121
|
+
`"${outputFile}"`,
|
|
122
|
+
].join(' ');
|
|
123
|
+
|
|
124
|
+
log.info('Generating web audio rendition (AAC M4A)', { command, audioBitrate });
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const { stderr } = await execAsync(command, { maxBuffer: FFMPEG_MAX_BUFFER });
|
|
128
|
+
|
|
129
|
+
if (stderr && !stderr.includes('frame=')) {
|
|
130
|
+
log.debug(`FFmpeg stderr for audio rendition: ${stderr}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Verify output file was created
|
|
134
|
+
try {
|
|
135
|
+
await fs.promises.access(outputFile, fs.constants.F_OK);
|
|
136
|
+
log.info(`Generated web audio rendition: ${outputFile}`);
|
|
137
|
+
return outputFile;
|
|
138
|
+
} catch {
|
|
139
|
+
log.warn('Audio rendition not generated');
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
log.error(
|
|
144
|
+
`Failed to generate audio rendition: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
145
|
+
);
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Upload a file to the storage and return its URI
|
|
152
|
+
*/
|
|
153
|
+
async function uploadFile(
|
|
154
|
+
client: VertesiaClient,
|
|
155
|
+
filePath: string,
|
|
156
|
+
mimeType: string,
|
|
157
|
+
fileName: string,
|
|
158
|
+
storagePath: string,
|
|
159
|
+
): Promise<string> {
|
|
160
|
+
const { NodeStreamSource } = await import('@vertesia/client/node');
|
|
161
|
+
const fileStream = fs.createReadStream(filePath);
|
|
162
|
+
const source = new NodeStreamSource(fileStream, fileName, mimeType, storagePath);
|
|
163
|
+
|
|
164
|
+
const result = await client.files.uploadFile(source);
|
|
165
|
+
log.info(`Uploaded file to ${storagePath}`, { result });
|
|
166
|
+
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Upload audio file and create a rendition entry
|
|
172
|
+
*/
|
|
173
|
+
async function uploadAudioAsRendition(
|
|
174
|
+
client: VertesiaClient,
|
|
175
|
+
audioFile: string,
|
|
176
|
+
renditionName: string,
|
|
177
|
+
fileName: string,
|
|
178
|
+
mimeType: string,
|
|
179
|
+
etag: string,
|
|
180
|
+
): Promise<Rendition> {
|
|
181
|
+
const storagePath = `renditions/${etag}/audio/${fileName}`;
|
|
182
|
+
const uri = await uploadFile(client, audioFile, mimeType, fileName, storagePath);
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
name: renditionName,
|
|
186
|
+
content: {
|
|
187
|
+
source: uri,
|
|
188
|
+
type: mimeType,
|
|
189
|
+
name: fileName,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Main activity: Prepare audio by extracting metadata and generating web rendition
|
|
196
|
+
*/
|
|
197
|
+
export async function prepareAudio(
|
|
198
|
+
payload: DSLActivityExecutionPayload<PrepareAudioParams>,
|
|
199
|
+
): Promise<PrepareAudioResult> {
|
|
200
|
+
const {
|
|
201
|
+
client,
|
|
202
|
+
objectId,
|
|
203
|
+
params,
|
|
204
|
+
} = await setupActivity<PrepareAudioParams>(payload);
|
|
205
|
+
|
|
206
|
+
const audioBitrate = params.audioBitrate ?? DEFAULT_AUDIO_BITRATE;
|
|
207
|
+
|
|
208
|
+
log.info(`Preparing audio for ${objectId}`, { audioBitrate });
|
|
209
|
+
|
|
210
|
+
// Retrieve the content object
|
|
211
|
+
const inputObject = await client.objects.retrieve(objectId).catch((err: unknown) => {
|
|
212
|
+
log.error(`Failed to retrieve document ${objectId}`, { err });
|
|
213
|
+
if (err instanceof RequestError && err.status === 404) {
|
|
214
|
+
throw new DocumentNotFoundError(`Document ${objectId} not found`, [objectId]);
|
|
215
|
+
}
|
|
216
|
+
throw err;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (!inputObject.content?.source) {
|
|
220
|
+
log.error(`Document ${objectId} has no source`);
|
|
221
|
+
throw new DocumentNotFoundError(`Document ${objectId} has no source`, [objectId]);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!inputObject.content.type || !inputObject.content.type.startsWith('audio/')) {
|
|
225
|
+
log.error(`Document ${objectId} is not an audio file: ${inputObject.content.type}`);
|
|
226
|
+
throw new InvalidContentTypeError(
|
|
227
|
+
objectId,
|
|
228
|
+
'audio/*',
|
|
229
|
+
inputObject.content.type || 'unknown',
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Download audio to temp file
|
|
234
|
+
const audioFile = await saveBlobToTempFile(client, inputObject.content.source);
|
|
235
|
+
const tempOutputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'prepare-audio-'));
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
// Step 1: Extract audio metadata
|
|
239
|
+
log.info('Extracting audio metadata');
|
|
240
|
+
const metadata = await getAudioMetadata(audioFile);
|
|
241
|
+
|
|
242
|
+
// Step 2: Generate web audio rendition (AAC M4A)
|
|
243
|
+
log.info('Generating web audio rendition');
|
|
244
|
+
const renditionFile = await generateAudioRendition(
|
|
245
|
+
audioFile,
|
|
246
|
+
tempOutputDir,
|
|
247
|
+
audioBitrate,
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
// Step 3: Upload generated rendition
|
|
251
|
+
const renditions: Rendition[] = [];
|
|
252
|
+
const etag = inputObject.content.etag ?? inputObject.id;
|
|
253
|
+
|
|
254
|
+
if (renditionFile) {
|
|
255
|
+
const audioRendition = await uploadAudioAsRendition(
|
|
256
|
+
client,
|
|
257
|
+
renditionFile,
|
|
258
|
+
AUDIO_RENDITION_NAME,
|
|
259
|
+
'audio.m4a',
|
|
260
|
+
'audio/mp4',
|
|
261
|
+
etag,
|
|
262
|
+
);
|
|
263
|
+
renditions.push(audioRendition);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Step 4: Update content object with metadata and renditions
|
|
267
|
+
const audioMetadata: AudioMetadata = {
|
|
268
|
+
type: ContentNature.Audio,
|
|
269
|
+
duration: metadata.duration,
|
|
270
|
+
renditions,
|
|
271
|
+
generation_runs: inputObject.metadata?.generation_runs || [],
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
await client.objects.update(objectId, {
|
|
275
|
+
metadata: audioMetadata,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
log.info(`Successfully prepared audio ${objectId}`, {
|
|
279
|
+
duration: metadata.duration,
|
|
280
|
+
codec: metadata.codec,
|
|
281
|
+
bitrate: metadata.bitrate,
|
|
282
|
+
sampleRate: metadata.sampleRate,
|
|
283
|
+
channels: metadata.channels,
|
|
284
|
+
renditionsGenerated: renditions.length,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
objectId,
|
|
289
|
+
metadata: {
|
|
290
|
+
duration: metadata.duration,
|
|
291
|
+
codec: metadata.codec,
|
|
292
|
+
bitrate: metadata.bitrate,
|
|
293
|
+
sampleRate: metadata.sampleRate,
|
|
294
|
+
channels: metadata.channels,
|
|
295
|
+
},
|
|
296
|
+
renditions: renditions,
|
|
297
|
+
status: 'success',
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
301
|
+
log.error(`Error preparing audio: ${errorMessage}`, { error });
|
|
302
|
+
|
|
303
|
+
// Re-throw known errors as-is
|
|
304
|
+
if (error instanceof DocumentNotFoundError || error instanceof InvalidContentTypeError) {
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Wrap unknown errors in Error
|
|
309
|
+
throw new Error(
|
|
310
|
+
`Failed to prepare audio ${objectId}: ${errorMessage}`,
|
|
311
|
+
);
|
|
312
|
+
} finally {
|
|
313
|
+
// Clean up temporary files
|
|
314
|
+
const cleanupPromises: Promise<void>[] = [];
|
|
315
|
+
|
|
316
|
+
if (audioFile) {
|
|
317
|
+
cleanupPromises.push(
|
|
318
|
+
fs.promises.unlink(audioFile).catch((err) => {
|
|
319
|
+
log.warn(`Failed to cleanup audio file: ${audioFile}`, { err });
|
|
320
|
+
}),
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (tempOutputDir) {
|
|
325
|
+
cleanupPromises.push(
|
|
326
|
+
fs.promises.rm(tempOutputDir, { recursive: true, force: true }).catch((err) => {
|
|
327
|
+
log.warn(`Failed to cleanup temp directory: ${tempOutputDir}`, { err });
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
await Promise.allSettled(cleanupPromises);
|
|
333
|
+
}
|
|
334
|
+
}
|