@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,68 @@
|
|
|
1
|
+
import { WorkflowExecutionPayload } from "@vertesia/common";
|
|
2
|
+
|
|
3
|
+
import { log, proxyActivities } from "@temporalio/workflow";
|
|
4
|
+
import { WF_NON_RETRYABLE_ERRORS } from "../errors.js";
|
|
5
|
+
import * as activities from "./activities/index.js";
|
|
6
|
+
import { IterativeGenerationPayload, PartIndex, SECTION_ID_PLACEHOLDER } from "./types.js";
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
it_gen_extractToc,
|
|
10
|
+
it_gen_generateToc,
|
|
11
|
+
it_gen_generatePart,
|
|
12
|
+
it_gen_finalizeOutput
|
|
13
|
+
} = proxyActivities<typeof activities>({
|
|
14
|
+
startToCloseTimeout: "15 minute",
|
|
15
|
+
retry: {
|
|
16
|
+
initialInterval: '30s',
|
|
17
|
+
backoffCoefficient: 2,
|
|
18
|
+
maximumAttempts: 20,
|
|
19
|
+
maximumInterval: 100 * 30 * 1000, //ms
|
|
20
|
+
nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export async function iterativeGenerationWorkflow(payload: WorkflowExecutionPayload) {
|
|
25
|
+
log.info(`Executing Iterative generation workflow.`);
|
|
26
|
+
|
|
27
|
+
const vars = payload.vars as IterativeGenerationPayload;
|
|
28
|
+
if (vars.section_file_pattern && !vars.section_file_pattern.includes(SECTION_ID_PLACEHOLDER)) {
|
|
29
|
+
throw new Error(`Invalid section_file_pattern: ${vars.section_file_pattern}. It must include the ${SECTION_ID_PLACEHOLDER} placeholder.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// extractToc tries to extract the toc from the input memory pack (toc.json or toc.yaml)
|
|
33
|
+
// the generateToc activity is returning the toc hierarchy.
|
|
34
|
+
// It doesn't include extra TOC details like description etc.
|
|
35
|
+
// To minimize the payload size only the hierarchy and the section/part names are returned
|
|
36
|
+
let toc = await it_gen_extractToc(payload);
|
|
37
|
+
if (!toc) {
|
|
38
|
+
log.info(`No TOC was specified in the input memory pack. Generating one.`);
|
|
39
|
+
toc = await it_gen_generateToc(payload);
|
|
40
|
+
} else {
|
|
41
|
+
log.info(`Using the TOC specified in the input memory pack.`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (toc.sections.length === 0) {
|
|
45
|
+
//TODO how to handle this case?
|
|
46
|
+
throw new Error("Nothing to generate: TOC is empty");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (const section of toc.sections) {
|
|
50
|
+
log.info(`Generating section: ${formatPath(section)}`);
|
|
51
|
+
await it_gen_generatePart(payload, section.path);
|
|
52
|
+
|
|
53
|
+
if (section.parts) {
|
|
54
|
+
for (const part of section.parts) {
|
|
55
|
+
log.info(`Generating part: ${formatPath(part)}`);
|
|
56
|
+
await it_gen_generatePart(payload, part.path);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
log.info(`Post-processing output memory pack`);
|
|
62
|
+
await it_gen_finalizeOutput(payload);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function formatPath(node: PartIndex) {
|
|
66
|
+
// we print 1 based indexes
|
|
67
|
+
return node.path.map(i => i + 1).join('.') + ' ' + node.name;
|
|
68
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
export const SECTION_ID_PLACEHOLDER = '%id';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* An iterative generation workflow uses 2 memory packs one for input and the other for output.
|
|
6
|
+
* The input memory packs must be available in the project blobs bucket at `${tenant_id/memories/${memory_name}/input.tar.gz`.
|
|
7
|
+
* The output memory pack will be generated at `${tenant_id/memories/${memory_name}/output.tar.gz`.
|
|
8
|
+
* Each iteration is overwriting the output memory pack with the new generated content.
|
|
9
|
+
* The complete name of the input and output memory packs are: "${name}/input" and "${name}/output" where name is the base memory name.
|
|
10
|
+
*/
|
|
11
|
+
export interface IterativeGenerationPayload {
|
|
12
|
+
// the main interaction to execute. If iterative_generation is defined
|
|
13
|
+
// the main interaction will only be used to prepare the iteration (to generate the TOC)
|
|
14
|
+
// otherwise it will be used for the iterative generation too.
|
|
15
|
+
interaction: string;
|
|
16
|
+
// if defined this will be used for the iterative interaction which will generate parts.
|
|
17
|
+
// otherwise the main interaction will be used for iterative generation.
|
|
18
|
+
iterative_interaction?: string;
|
|
19
|
+
// the environment to use
|
|
20
|
+
environment?: string;
|
|
21
|
+
// the model to use
|
|
22
|
+
model?: string;
|
|
23
|
+
// A custom max tokens
|
|
24
|
+
max_tokens?: number;
|
|
25
|
+
// A custom temperature
|
|
26
|
+
temperature?: number;
|
|
27
|
+
// the memory pack group name
|
|
28
|
+
memory: string;
|
|
29
|
+
// the input memory pack mapping
|
|
30
|
+
input_mapping?: Record<string, string>;
|
|
31
|
+
// custom toc schema if any TODO remove this
|
|
32
|
+
toc_schema?: Record<string, any>
|
|
33
|
+
/**
|
|
34
|
+
* If not set to "none" the previously generated content will be passed to the iteration.
|
|
35
|
+
* If not set at all defaults to "section".
|
|
36
|
+
* If "section" is used only the section content previously generated will be passed to the next iteration.
|
|
37
|
+
* If "document" is used the whole previously generated document content will be passed to the next iteration.
|
|
38
|
+
* Defaults to section.
|
|
39
|
+
*/
|
|
40
|
+
remembrance_strategy?: "document" | "section" | "none";
|
|
41
|
+
/**
|
|
42
|
+
* If present will save sections in files using the pattern
|
|
43
|
+
* The pattern must include a placeholder for the section id: %id.
|
|
44
|
+
* Examples: `sections/%id.md`, `%id/page.mdx` etc.
|
|
45
|
+
* @see SECTION_ID_PLACEHOLDER
|
|
46
|
+
*/
|
|
47
|
+
section_file_pattern?: string;
|
|
48
|
+
/**
|
|
49
|
+
* An optional header to prepend to the section files.
|
|
50
|
+
* The header can contain the following variables:
|
|
51
|
+
* - ${section} - the section object
|
|
52
|
+
* - ${date} - the date when the file was generated
|
|
53
|
+
*/
|
|
54
|
+
section_file_header?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface TocPart {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
instructions?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface TocSection {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
instructions?: string;
|
|
69
|
+
parts?: TocPart[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface Toc {
|
|
73
|
+
sections: TocSection[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
export interface SectionIndex extends PartIndex {
|
|
78
|
+
parts?: PartIndex[];
|
|
79
|
+
}
|
|
80
|
+
export interface PartIndex {
|
|
81
|
+
path: number[];
|
|
82
|
+
name: string;
|
|
83
|
+
}
|
|
84
|
+
export interface TocIndex {
|
|
85
|
+
sections: SectionIndex[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface OutputMemoryMeta {
|
|
89
|
+
toc: Toc;
|
|
90
|
+
previouslyGenerated: string;
|
|
91
|
+
lastProcessedPart?: number[] | undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface Section {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
content: string;
|
|
99
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ModelOptions, TextFallbackOptions } from "@llumiverse/common";
|
|
2
|
+
import { ApplicationFailure } from "@temporalio/workflow";
|
|
3
|
+
import { VertesiaClient } from "@vertesia/client";
|
|
4
|
+
import { OutputMemoryMeta, PartIndex, Toc, TocIndex, TocSection } from "./types.js";
|
|
5
|
+
|
|
6
|
+
//TODO: For whole file, support for options beyond max_tokens and temperature and multiple modalities.
|
|
7
|
+
export interface ExecuteOptions {
|
|
8
|
+
interaction: string;
|
|
9
|
+
memory: string;
|
|
10
|
+
memory_mapping?: Record<string, any>;
|
|
11
|
+
environment?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
model_options?: ModelOptions;
|
|
14
|
+
result_schema?: Record<string, any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function execute(client: VertesiaClient, options: ExecuteOptions) {
|
|
18
|
+
return client.interactions.executeByName(options.interaction, {
|
|
19
|
+
data: {
|
|
20
|
+
...options.memory_mapping,
|
|
21
|
+
"@memory": options.memory
|
|
22
|
+
},
|
|
23
|
+
result_schema: options.result_schema,
|
|
24
|
+
config: {
|
|
25
|
+
environment: options.environment,
|
|
26
|
+
model: options.model,
|
|
27
|
+
model_options: options.model_options,
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function executeWithVars(client: VertesiaClient, interaction: string, vars: Record<string, any>, mapping?: Record<string, any>, result_schema?: Record<string, any>) {
|
|
33
|
+
if (mapping) {
|
|
34
|
+
mapping = { ...vars.input_mapping, ...mapping };
|
|
35
|
+
} else {
|
|
36
|
+
mapping = vars.input_mapping;
|
|
37
|
+
}
|
|
38
|
+
const model_options: TextFallbackOptions = {
|
|
39
|
+
_option_id: "text-fallback",
|
|
40
|
+
max_tokens: vars.max_tokens,
|
|
41
|
+
temperature: vars.temperature
|
|
42
|
+
}
|
|
43
|
+
return execute(client, {
|
|
44
|
+
interaction: interaction,
|
|
45
|
+
memory: `${vars.memory}/input`,
|
|
46
|
+
memory_mapping: mapping,
|
|
47
|
+
environment: vars.environment,
|
|
48
|
+
model: vars.model,
|
|
49
|
+
model_options: model_options,
|
|
50
|
+
result_schema: result_schema
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isSamePartIndex(part1: number[], part2: number[]) {
|
|
55
|
+
return part1 && part2 && part1.length === part2.length && part1.every((v, i) => v === part2[i]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getPreviousPathIndex(toc: Toc, pathIndex: number[]): number[] | null {
|
|
59
|
+
let [sectionIdx, partIdx] = pathIndex;
|
|
60
|
+
if (partIdx === undefined) {
|
|
61
|
+
let prevSectionIdx = sectionIdx - 1;
|
|
62
|
+
if (prevSectionIdx < 0) {
|
|
63
|
+
return null;
|
|
64
|
+
} else {
|
|
65
|
+
const prevParts = toc.sections[prevSectionIdx].parts;
|
|
66
|
+
if (prevParts && prevParts.length > 0) { // return the last part of the previous section
|
|
67
|
+
return [prevSectionIdx, prevParts.length - 1];
|
|
68
|
+
} else { // if no parts return the section itself
|
|
69
|
+
return [prevSectionIdx];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (partIdx > 0) { // return the previous part in the same section
|
|
73
|
+
return [sectionIdx, partIdx - 1];
|
|
74
|
+
} else { // if the first part return the section itself
|
|
75
|
+
return [sectionIdx];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export function expectMemoryIsConsistent(meta: OutputMemoryMeta, pathIndex: number[]) {
|
|
81
|
+
const metaLastProcessedPart = meta.lastProcessedPart;
|
|
82
|
+
if (!metaLastProcessedPart) {
|
|
83
|
+
if (pathIndex.length > 1 && pathIndex[0] !== 0) {
|
|
84
|
+
throw ApplicationFailure.nonRetryable('Memory last processed part is not consistent with the workflow.', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: [pathIndex[0], pathIndex[1] - 1], previousIndex: metaLastProcessedPart });
|
|
85
|
+
} else {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const prevPathIndex = getPreviousPathIndex(meta.toc, pathIndex);
|
|
90
|
+
if (!prevPathIndex) {
|
|
91
|
+
throw ApplicationFailure.nonRetryable('Memory last processed part is not consistent with the workflow', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: prevPathIndex, previousIndex: metaLastProcessedPart });
|
|
92
|
+
} else if (!isSamePartIndex(prevPathIndex, metaLastProcessedPart)) {
|
|
93
|
+
throw ApplicationFailure.nonRetryable('Memory last processed part is not consistent with the workflow', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: prevPathIndex, previousIndex: meta.lastProcessedPart });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function sectionWithoutParts(section: TocSection) {
|
|
98
|
+
const clone = { ...section };
|
|
99
|
+
delete clone.parts;
|
|
100
|
+
return clone;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function tocIndex(toc: Toc): TocIndex {
|
|
104
|
+
const index = { sections: [] } as TocIndex;
|
|
105
|
+
const sections = toc.sections;
|
|
106
|
+
for (let i = 0, l = sections.length; i < l; i++) {
|
|
107
|
+
const section = sections[i];
|
|
108
|
+
const indexParts: PartIndex[] = [];
|
|
109
|
+
if (section.parts) {
|
|
110
|
+
const parts = section.parts;
|
|
111
|
+
for (let k = 0, ll = section.parts.length; k < ll; k++) {
|
|
112
|
+
const part = parts[k];
|
|
113
|
+
indexParts.push({
|
|
114
|
+
name: part.id,
|
|
115
|
+
path: [i, k]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
index.sections.push({
|
|
120
|
+
name: section.id,
|
|
121
|
+
path: [i],
|
|
122
|
+
parts: indexParts
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return index;
|
|
126
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The result of a text extraction operation.
|
|
6
|
+
*/
|
|
7
|
+
export interface TextExtractionResult {
|
|
8
|
+
objectId: string;
|
|
9
|
+
status: TextExtractionStatus;
|
|
10
|
+
hasText: boolean;
|
|
11
|
+
message?: string;
|
|
12
|
+
tokens?: {
|
|
13
|
+
count: number;
|
|
14
|
+
encoding: string;
|
|
15
|
+
etag: string;
|
|
16
|
+
};
|
|
17
|
+
len?: number;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum TextExtractionStatus {
|
|
22
|
+
skipped = "skipped",
|
|
23
|
+
success = "success",
|
|
24
|
+
error = "error",
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
import { log, workflowInfo } from "@temporalio/workflow";
|
|
3
|
+
import { WebHookSpec, WorkflowExecutionPayload } from "@vertesia/common";
|
|
4
|
+
import * as activities from "../activities/notifyWebhook.js";
|
|
5
|
+
import { dslProxyActivities } from "../dsl/dslProxyActivities.js";
|
|
6
|
+
import { WF_NON_RETRYABLE_ERRORS } from "../errors.js";
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
notifyWebhook
|
|
10
|
+
} = dslProxyActivities<typeof activities>("notifyWebhookWorkflow", {
|
|
11
|
+
startToCloseTimeout: "5 minute",
|
|
12
|
+
retry: {
|
|
13
|
+
initialInterval: '5s',
|
|
14
|
+
backoffCoefficient: 2,
|
|
15
|
+
maximumAttempts: 5,
|
|
16
|
+
maximumInterval: 100 * 30 * 1000, //ms
|
|
17
|
+
nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export interface NotifyWebhookWorfklowParams {
|
|
22
|
+
workflow_type: string;
|
|
23
|
+
endpoints: (string | WebHookSpec)[],
|
|
24
|
+
data: Record<string, any>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export async function notifyWebhookWorkflow(payload: WorkflowExecutionPayload<NotifyWebhookWorfklowParams>): Promise<any> {
|
|
29
|
+
|
|
30
|
+
const info = workflowInfo();
|
|
31
|
+
const { objectIds, vars } = payload;
|
|
32
|
+
const notifications = [];
|
|
33
|
+
const endpoints = vars.endpoints ?? (vars as any).webhooks ?? [];
|
|
34
|
+
const data = vars.data ?? (vars as any).webhook_data ?? undefined;
|
|
35
|
+
const workflow_type = vars.workflow_type ?? info.workflowType;
|
|
36
|
+
const eventName = payload.event;
|
|
37
|
+
|
|
38
|
+
const workflowId = info.parent?.workflowId || info.workflowId;
|
|
39
|
+
const workflowRunId = info.parent?.runId || info.runId;
|
|
40
|
+
|
|
41
|
+
if (!endpoints.length) {
|
|
42
|
+
log.info(`No webhooks to notify`);
|
|
43
|
+
return { notifications: [], message: "No webhooks to notify" };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const ep of endpoints) {
|
|
47
|
+
const n = notifyWebhook(payload, {
|
|
48
|
+
webhook: ep,
|
|
49
|
+
method: 'POST',
|
|
50
|
+
workflow_type,
|
|
51
|
+
workflow_id: workflowId,
|
|
52
|
+
workflow_run_id: workflowRunId,
|
|
53
|
+
event_name: eventName,
|
|
54
|
+
detail: {
|
|
55
|
+
object_ids: objectIds,
|
|
56
|
+
data
|
|
57
|
+
}
|
|
58
|
+
}).then(res => {
|
|
59
|
+
log.info(`Webhook notified at ${ep} with response code: ${res.status}`, { res });
|
|
60
|
+
return res;
|
|
61
|
+
});
|
|
62
|
+
notifications.push(n);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const res = await Promise.all(notifications);
|
|
66
|
+
log.info(`Webhooks notified`);
|
|
67
|
+
|
|
68
|
+
return { notifications: res, message: "Webhooks notified" };
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import { SupportedEmbeddingTypes, WorkflowExecutionPayload } from "@vertesia/common";
|
|
3
|
+
import * as activities from "../activities/index-dsl.js";
|
|
4
|
+
import { dslProxyActivities } from "../dsl/dslProxyActivities.js";
|
|
5
|
+
import { WF_NON_RETRYABLE_ERRORS } from "../errors.js";
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
generateEmbeddings,
|
|
9
|
+
} = dslProxyActivities<typeof activities>("recalculateEmbeddingsWorkflow", {
|
|
10
|
+
startToCloseTimeout: "5 minute",
|
|
11
|
+
retry: {
|
|
12
|
+
initialInterval: '10s',
|
|
13
|
+
backoffCoefficient: 2,
|
|
14
|
+
maximumAttempts: 10,
|
|
15
|
+
maximumInterval: 100 * 30 * 1000, //ms
|
|
16
|
+
nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export async function recalculateEmbeddingsWorkflow(payload: WorkflowExecutionPayload) {
|
|
21
|
+
|
|
22
|
+
const embeddings = [];
|
|
23
|
+
const payloadType = payload.vars?.type as SupportedEmbeddingTypes;
|
|
24
|
+
|
|
25
|
+
if (payloadType && !Object.values(SupportedEmbeddingTypes).includes(payloadType)) {
|
|
26
|
+
throw new Error("Embedding type must be text, image, or properties");
|
|
27
|
+
}
|
|
28
|
+
const types = payloadType ? [payloadType] : Object.values(SupportedEmbeddingTypes);
|
|
29
|
+
|
|
30
|
+
for (const type of types) {
|
|
31
|
+
embeddings.push(generateEmbeddings(payload, {
|
|
32
|
+
force: true,
|
|
33
|
+
type
|
|
34
|
+
}))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const res = await Promise.all(embeddings);
|
|
38
|
+
|
|
39
|
+
return res;
|
|
40
|
+
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthTokenPayload, ProjectRef } from '@vertesia/common';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
3
|
+
|
|
4
|
+
export function decodeAuthToken(token: string): AuthTokenPayload {
|
|
5
|
+
return jwt.decode(token, { json: true }) as AuthTokenPayload;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getProjectFromToken(token: string): ProjectRef | undefined {
|
|
9
|
+
return decodeAuthToken(token)?.project;
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { VertesiaClient } from "@vertesia/client";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
import { createWriteStream } from "fs";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
import { pipeline } from "stream/promises";
|
|
6
|
+
import tmp from "tmp";
|
|
7
|
+
import { DocumentNotFoundError } from "../errors.js";
|
|
8
|
+
|
|
9
|
+
tmp.setGracefulCleanup();
|
|
10
|
+
|
|
11
|
+
export async function fetchBlobAsStream(client: VertesiaClient, blobUri: string): Promise<ReadableStream<Uint8Array>> {
|
|
12
|
+
try {
|
|
13
|
+
return await client.files.downloadFile(blobUri);
|
|
14
|
+
} catch (err: any) {
|
|
15
|
+
if (err.message.includes("not found")) {
|
|
16
|
+
//TODO improve error handling with a fetch fail error class in the client
|
|
17
|
+
throw new DocumentNotFoundError(`Not found at ${blobUri}: ${err.message}`, []);
|
|
18
|
+
} else if (err.message.includes("forbidden")) {
|
|
19
|
+
throw new DocumentNotFoundError(`Forbidden at ${blobUri}: ${err.message}`);
|
|
20
|
+
} else {
|
|
21
|
+
throw new Error(`Failed to download blob ${blobUri}: ${err.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function fetchBlobAsBuffer(client: VertesiaClient, blobUri: string): Promise<Buffer> {
|
|
26
|
+
let stream = await fetchBlobAsStream(client, blobUri);
|
|
27
|
+
const buffers: Uint8Array[] = [];
|
|
28
|
+
for await (const data of stream) {
|
|
29
|
+
buffers.push(data);
|
|
30
|
+
}
|
|
31
|
+
return Buffer.concat(buffers);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function fetchBlobAsBase64(client: VertesiaClient, blobUri: string): Promise<string> {
|
|
35
|
+
const buffer = await fetchBlobAsBuffer(client, blobUri);
|
|
36
|
+
return buffer.toString("base64");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function saveBlobToFile(client: VertesiaClient, blobUri: string, toFile: string): Promise<void> {
|
|
40
|
+
const stream = await fetchBlobAsStream(client, blobUri);
|
|
41
|
+
|
|
42
|
+
const nodeReadable = Readable.from(stream);
|
|
43
|
+
const out = createWriteStream(toFile);
|
|
44
|
+
|
|
45
|
+
await pipeline(nodeReadable, out); // Ensures completion before continuing
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function saveBlobToTempFile(client: VertesiaClient, blobUri: string, fileExt?: string): Promise<string> {
|
|
49
|
+
const tmpFile = tmp.fileSync({
|
|
50
|
+
prefix: "vertesia-activity-",
|
|
51
|
+
postfix: fileExt ? "." + fileExt : "",
|
|
52
|
+
});
|
|
53
|
+
await saveBlobToFile(client, blobUri, tmpFile.name);
|
|
54
|
+
return tmpFile.name;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function md5(contents: string) {
|
|
58
|
+
return crypto.createHash("md5").update(contents).digest("hex");
|
|
59
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
export interface DocPart {
|
|
3
|
+
line_number_start: number
|
|
4
|
+
line_number_end: number
|
|
5
|
+
name: string
|
|
6
|
+
type: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const getContentPart = (content: string, part: DocPart): string => {
|
|
10
|
+
const lines = content.split('\n');
|
|
11
|
+
const text = lines.filter((_l, i) => i >= part.line_number_start && i <= part.line_number_end).join('\n');
|
|
12
|
+
return text;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const getContentParts = (content: string, parts: DocPart[]): string[] => {
|
|
16
|
+
return parts.map(part => getContentPart(content, part));
|
|
17
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* get a zeno client for a given token
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
decodeJWT,
|
|
7
|
+
VertesiaClient,
|
|
8
|
+
VertesiaClientProps,
|
|
9
|
+
} from "@vertesia/client";
|
|
10
|
+
import { WorkflowExecutionBaseParams } from "@vertesia/common";
|
|
11
|
+
import { WorkflowParamNotFoundError } from "../errors.js";
|
|
12
|
+
|
|
13
|
+
export function getVertesiaClient(payload: WorkflowExecutionBaseParams) {
|
|
14
|
+
return new VertesiaClient(getVertesiaClientOptions(payload));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getVertesiaClientOptions(
|
|
18
|
+
payload: WorkflowExecutionBaseParams,
|
|
19
|
+
): VertesiaClientProps {
|
|
20
|
+
if (!payload.auth_token) {
|
|
21
|
+
throw new WorkflowParamNotFoundError(
|
|
22
|
+
"Authentication Token is missing from WorkflowExecutionPayload.authToken",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!payload.config?.studio_url) {
|
|
27
|
+
throw new WorkflowParamNotFoundError(
|
|
28
|
+
"Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!payload.config?.store_url) {
|
|
33
|
+
throw new WorkflowParamNotFoundError(
|
|
34
|
+
"Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const token = decodeJWT(payload.auth_token);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
serverUrl: payload.config.studio_url,
|
|
42
|
+
storeUrl: payload.config.store_url,
|
|
43
|
+
tokenServerUrl: token.iss,
|
|
44
|
+
apikey: payload.auth_token,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
const VARS_RX = /\${\s*([^}]+)\s*}/g;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Given an expression containing ${name} variables, replace them with the properties from the vars object.
|
|
6
|
+
* Nested property paths are also supported, e.g. ${section.name}
|
|
7
|
+
* @param expr
|
|
8
|
+
* @param vars
|
|
9
|
+
*/
|
|
10
|
+
export function expandVars(expr: string, vars: Record<string, any>) {
|
|
11
|
+
return expr.replace(VARS_RX, (_: string, name: string) => {
|
|
12
|
+
const path = name.split('.');
|
|
13
|
+
const value = resolveProp(vars, path);
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
return `${name}`; // return back the expression
|
|
16
|
+
} else {
|
|
17
|
+
return String(value);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolveProp(object: object, path: string[]) {
|
|
23
|
+
let value: any = object;
|
|
24
|
+
for (const part of path) {
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
value = value[part];
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { VertesiaClient } from "@vertesia/client";
|
|
2
|
+
import { NodeStreamSource } from "@vertesia/client/node";
|
|
3
|
+
import { Commands, MemoryPack, buildMemoryPack as _buildMemoryPack, loadMemoryPack as _loadMemoryPack } from "@vertesia/memory";
|
|
4
|
+
import { createReadStream, createWriteStream } from "fs";
|
|
5
|
+
import { rm } from "fs/promises";
|
|
6
|
+
import { webStreamToReadable } from "node-web-stream-adapters";
|
|
7
|
+
import { pipeline } from "stream/promises";
|
|
8
|
+
|
|
9
|
+
import tmp from "tmp";
|
|
10
|
+
import zlib from "zlib";
|
|
11
|
+
|
|
12
|
+
tmp.setGracefulCleanup();
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export async function publishMemoryPack(client: VertesiaClient, file: string, name: string): Promise<void> {
|
|
16
|
+
const stream = createReadStream(file);
|
|
17
|
+
try {
|
|
18
|
+
const source = new NodeStreamSource(stream, name);
|
|
19
|
+
await client.files.uploadMemoryPack(source);
|
|
20
|
+
} catch (err: any) {
|
|
21
|
+
stream.destroy();
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function buildMemoryPack(recipeFn: (commands: Commands) => Promise<Record<string, any>>): Promise<string> {
|
|
27
|
+
const tarFile = tmp.fileSync({
|
|
28
|
+
prefix: "composable-memory-pack-",
|
|
29
|
+
postfix: ".tar.gz",
|
|
30
|
+
});
|
|
31
|
+
return await _buildMemoryPack(recipeFn, {
|
|
32
|
+
out: tarFile.name,
|
|
33
|
+
gzip: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function buildAndPublishMemoryPack(client: VertesiaClient, name: string, recipeFn: (commands: Commands) => Promise<Record<string, any>>): Promise<void> {
|
|
38
|
+
const tarFile = await buildMemoryPack(recipeFn);
|
|
39
|
+
try {
|
|
40
|
+
await publishMemoryPack(client, tarFile, name);
|
|
41
|
+
} finally {
|
|
42
|
+
await rm(tarFile);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function fetchMemoryPack(client: VertesiaClient, name: string): Promise<string> {
|
|
47
|
+
const webStream = await client.files.downloadMemoryPack(name);
|
|
48
|
+
const tarFile = tmp.fileSync({
|
|
49
|
+
prefix: "composable-memory-pack-",
|
|
50
|
+
postfix: ".tar",
|
|
51
|
+
discardDescriptor: true,
|
|
52
|
+
});
|
|
53
|
+
const streamIn = webStreamToReadable(webStream);
|
|
54
|
+
const streamOut = createWriteStream(tarFile.name);
|
|
55
|
+
await pipeline(streamIn, zlib.createGunzip(), streamOut);
|
|
56
|
+
return tarFile.name;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function loadMemoryPack(client: VertesiaClient, name: string): Promise<MemoryPack> {
|
|
60
|
+
return fetchMemoryPack(client, name).then(file => _loadMemoryPack(file));
|
|
61
|
+
}
|