@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,120 @@
|
|
|
1
|
+
import { log } from "@temporalio/activity";
|
|
2
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
|
3
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
4
|
+
import { TruncateSpec, truncByMaxTokens } from "../utils/tokens.js";
|
|
5
|
+
import { InteractionExecutionParams, executeInteractionFromActivity } from "./executeInteraction.js";
|
|
6
|
+
|
|
7
|
+
const INT_EXTRACT_INFORMATION = "sys:ExtractInformation";
|
|
8
|
+
export interface GenerateDocumentPropertiesParams extends InteractionExecutionParams {
|
|
9
|
+
typesHint?: string[];
|
|
10
|
+
/**
|
|
11
|
+
* truncate the input doc text to the specified max_tokens
|
|
12
|
+
*/
|
|
13
|
+
truncate?: TruncateSpec;
|
|
14
|
+
|
|
15
|
+
interactionName?: string;
|
|
16
|
+
|
|
17
|
+
use_vision?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface GenerateDocumentProperties extends DSLActivitySpec<GenerateDocumentPropertiesParams> {
|
|
20
|
+
name: "generateDocumentProperties";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function generateDocumentProperties(
|
|
24
|
+
payload: DSLActivityExecutionPayload<GenerateDocumentPropertiesParams>,
|
|
25
|
+
) {
|
|
26
|
+
const context = await setupActivity<GenerateDocumentPropertiesParams>(payload);
|
|
27
|
+
const { params, client, objectId } = context;
|
|
28
|
+
const interactionName = params.interactionName ?? INT_EXTRACT_INFORMATION;
|
|
29
|
+
|
|
30
|
+
const project = await context.fetchProject();
|
|
31
|
+
|
|
32
|
+
const doc = await client.objects.retrieve(objectId, "+text");
|
|
33
|
+
const type = doc.type ? await client.types.retrieve(doc.type.id) : undefined;
|
|
34
|
+
|
|
35
|
+
if (!doc?.text && !params.use_vision && !doc?.content?.type?.startsWith("image/")) {
|
|
36
|
+
log.warn(`Object ${objectId} not found or text is empty`);
|
|
37
|
+
return { status: "failed", error: "no-text" };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!type || !type.object_schema) {
|
|
41
|
+
log.info(`Object ${objectId} has no schema`);
|
|
42
|
+
return { document: objectId, status: "skipped", message: "no schema defined on type" };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getImageRef = () => {
|
|
46
|
+
if (doc.content?.type?.startsWith("image/")) {
|
|
47
|
+
return "store:" + doc.id;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (params.use_vision && doc.content?.type?.startsWith("application/pdf")) {
|
|
51
|
+
return "store:" + doc.id;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
log.info(`Object ${objectId} is not an image or pdf`);
|
|
55
|
+
return undefined;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const content = doc.text
|
|
59
|
+
? truncByMaxTokens(doc.text, params.truncate || 30000)
|
|
60
|
+
: undefined;
|
|
61
|
+
|
|
62
|
+
const promptData = {
|
|
63
|
+
content: content,
|
|
64
|
+
image: getImageRef() ?? undefined,
|
|
65
|
+
human_context: project?.configuration?.human_context ?? undefined,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
log.info(
|
|
69
|
+
` Extracting information from object ${objectId} with type ${type.name}`,
|
|
70
|
+
payload.debug_mode ? { params } : undefined,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const infoRes = await executeInteractionFromActivity(
|
|
74
|
+
client,
|
|
75
|
+
interactionName,
|
|
76
|
+
{
|
|
77
|
+
...params,
|
|
78
|
+
include_previous_error: true,
|
|
79
|
+
result_schema: type.object_schema,
|
|
80
|
+
validate_result: type.strict_mode,
|
|
81
|
+
},
|
|
82
|
+
promptData,
|
|
83
|
+
payload.debug_mode ?? false,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const getText = () => {
|
|
87
|
+
if (doc.text) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
let text = "";
|
|
91
|
+
const jsonResult = infoRes.result.object();
|
|
92
|
+
if (jsonResult.title) {
|
|
93
|
+
text += jsonResult.title + "\n";
|
|
94
|
+
}
|
|
95
|
+
if (jsonResult.description) {
|
|
96
|
+
text += jsonResult.description;
|
|
97
|
+
}
|
|
98
|
+
if (text) {
|
|
99
|
+
return text;
|
|
100
|
+
} else {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
log.info(`Extracted information from object ${objectId} with type ${type.name}`, { runId: infoRes.id });
|
|
106
|
+
await client.objects.update(doc.id, {
|
|
107
|
+
properties: {
|
|
108
|
+
...infoRes.result.object(),
|
|
109
|
+
etag: doc.text_etag,
|
|
110
|
+
},
|
|
111
|
+
text: getText(),
|
|
112
|
+
generation_run_info: {
|
|
113
|
+
id: infoRes.id,
|
|
114
|
+
date: new Date().toISOString(),
|
|
115
|
+
model: infoRes.modelId,
|
|
116
|
+
},
|
|
117
|
+
}, { suppressWorkflows: true });
|
|
118
|
+
|
|
119
|
+
return { status: "completed" };
|
|
120
|
+
}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { EmbeddingsResult } from "@llumiverse/common";
|
|
2
|
+
import { log } from "@temporalio/activity";
|
|
3
|
+
import { VertesiaClient } from "@vertesia/client";
|
|
4
|
+
import {
|
|
5
|
+
ContentObject,
|
|
6
|
+
DSLActivityExecutionPayload,
|
|
7
|
+
DSLActivitySpec,
|
|
8
|
+
ImageRenditionFormat,
|
|
9
|
+
ProjectConfigurationEmbeddings,
|
|
10
|
+
SupportedEmbeddingTypes,
|
|
11
|
+
} from "@vertesia/common";
|
|
12
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
|
13
|
+
import { DocumentNotFoundError } from "../errors.js";
|
|
14
|
+
import { fetchBlobAsBase64, md5 } from "../utils/blobs.js";
|
|
15
|
+
import { DocPart } from "../utils/chunks.js";
|
|
16
|
+
import { countTokens } from "../utils/tokens.js";
|
|
17
|
+
|
|
18
|
+
export interface GenerateEmbeddingsParams {
|
|
19
|
+
/**
|
|
20
|
+
* The model to use for embedding generation
|
|
21
|
+
* If not set, the default model for the project will be used
|
|
22
|
+
*/
|
|
23
|
+
model?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The environment to use for embedding generation
|
|
27
|
+
* If not set, the default environment for the project will be used
|
|
28
|
+
*/
|
|
29
|
+
environment?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* If true, force embedding generation even if the document already has embeddings
|
|
33
|
+
*/
|
|
34
|
+
force?: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The embedding type to generate
|
|
38
|
+
*/
|
|
39
|
+
type: SupportedEmbeddingTypes;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The DocParts to use for long documents
|
|
43
|
+
*/
|
|
44
|
+
parts?: DocPart[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface GenerateEmbeddings
|
|
48
|
+
extends DSLActivitySpec<GenerateEmbeddingsParams> {
|
|
49
|
+
name: "generateEmbeddings";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function generateEmbeddings(
|
|
53
|
+
payload: DSLActivityExecutionPayload<GenerateEmbeddingsParams>,
|
|
54
|
+
) {
|
|
55
|
+
const { params, client, objectId, fetchProject } =
|
|
56
|
+
await setupActivity<GenerateEmbeddingsParams>(payload);
|
|
57
|
+
const { force, type } = params;
|
|
58
|
+
|
|
59
|
+
const projectData = await fetchProject();
|
|
60
|
+
const config = projectData?.configuration.embeddings[type];
|
|
61
|
+
if (!projectData) {
|
|
62
|
+
throw new DocumentNotFoundError("Project not found", [payload.project_id]);
|
|
63
|
+
}
|
|
64
|
+
if (!config) {
|
|
65
|
+
throw new DocumentNotFoundError("Embeddings configuration not found", [
|
|
66
|
+
objectId,
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!projectData) {
|
|
71
|
+
throw new DocumentNotFoundError("Project not found", [payload.project_id]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!projectData?.configuration.embeddings[type]?.enabled) {
|
|
75
|
+
log.info(
|
|
76
|
+
`Embeddings generation disabled for type ${type} on project: ${projectData.name} (${projectData.namespace})`,
|
|
77
|
+
{ config },
|
|
78
|
+
);
|
|
79
|
+
return {
|
|
80
|
+
id: objectId,
|
|
81
|
+
status: "skipped",
|
|
82
|
+
message: `Embeddings generation disabled for type ${type}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
log.info(`${type} embedding generation starting for object ${objectId}`, {
|
|
87
|
+
force,
|
|
88
|
+
config,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!config.environment) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
"No environment found in project configuration. Set environment in project configuration to generate embeddings.",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const document = await client.objects.retrieve(
|
|
98
|
+
objectId,
|
|
99
|
+
"+text +parts +embeddings +tokens +properties",
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
if (!document) {
|
|
103
|
+
throw new DocumentNotFoundError("Document not found", [objectId]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!document.content) {
|
|
107
|
+
throw new DocumentNotFoundError("Document content not found", [objectId]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let res;
|
|
111
|
+
|
|
112
|
+
switch (type) {
|
|
113
|
+
case SupportedEmbeddingTypes.text:
|
|
114
|
+
res = await generateTextEmbeddings({
|
|
115
|
+
client,
|
|
116
|
+
config,
|
|
117
|
+
document,
|
|
118
|
+
type,
|
|
119
|
+
force,
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
case SupportedEmbeddingTypes.properties:
|
|
123
|
+
res = await generateTextEmbeddings({
|
|
124
|
+
client,
|
|
125
|
+
config,
|
|
126
|
+
document,
|
|
127
|
+
type,
|
|
128
|
+
force,
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
case SupportedEmbeddingTypes.image:
|
|
132
|
+
res = await generateImageEmbeddings({
|
|
133
|
+
client,
|
|
134
|
+
config,
|
|
135
|
+
document,
|
|
136
|
+
type,
|
|
137
|
+
force,
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
res = {
|
|
142
|
+
id: objectId,
|
|
143
|
+
status: "failed",
|
|
144
|
+
message: `unsupported embedding type: ${type}`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return res;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface ExecuteGenerateEmbeddingsParams {
|
|
152
|
+
document: ContentObject;
|
|
153
|
+
client: VertesiaClient;
|
|
154
|
+
type: SupportedEmbeddingTypes;
|
|
155
|
+
config: ProjectConfigurationEmbeddings;
|
|
156
|
+
property?: string;
|
|
157
|
+
force?: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function generateTextEmbeddings(
|
|
161
|
+
{ document, client, type, config, force }: ExecuteGenerateEmbeddingsParams
|
|
162
|
+
) {
|
|
163
|
+
|
|
164
|
+
if (!document) {
|
|
165
|
+
return { status: "error", message: "document is null or undefined" };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (
|
|
169
|
+
type !== SupportedEmbeddingTypes.text &&
|
|
170
|
+
type !== SupportedEmbeddingTypes.properties
|
|
171
|
+
) {
|
|
172
|
+
return {
|
|
173
|
+
id: document.id,
|
|
174
|
+
status: "failed",
|
|
175
|
+
message: `unsupported embedding type: ${type}`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (type === SupportedEmbeddingTypes.text && !document.text) {
|
|
180
|
+
return { id: document.id, status: "failed", message: "no text found" };
|
|
181
|
+
}
|
|
182
|
+
if (type === SupportedEmbeddingTypes.properties && !document?.properties) {
|
|
183
|
+
return {
|
|
184
|
+
id: document.id,
|
|
185
|
+
status: "failed",
|
|
186
|
+
message: "no properties found",
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const { environment } = config;
|
|
191
|
+
|
|
192
|
+
// Compute text etag for comparison
|
|
193
|
+
const textEtag = document.text_etag ?? (document.text ? md5(document.text) : undefined);
|
|
194
|
+
|
|
195
|
+
// Skip if embeddings already exist with matching etag (unless force=true)
|
|
196
|
+
const existingEmbedding = document.embeddings?.[type];
|
|
197
|
+
if (!force && existingEmbedding?.etag && textEtag && existingEmbedding.etag === textEtag) {
|
|
198
|
+
log.info(`Skipping ${type} embeddings for document ${document.id} - etag unchanged`);
|
|
199
|
+
return {
|
|
200
|
+
id: document.id,
|
|
201
|
+
type,
|
|
202
|
+
status: "skipped",
|
|
203
|
+
message: "embeddings already exist with matching etag",
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Count tokens if needed, do not rely on existing token count
|
|
208
|
+
let tokenCount : number | undefined = undefined;
|
|
209
|
+
if (type === SupportedEmbeddingTypes.text && document.text) {
|
|
210
|
+
tokenCount = countTokens(document.text).count;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const maxTokens = config.max_tokens ?? 8000;
|
|
214
|
+
|
|
215
|
+
//generate embeddings for the main doc if document isn't too large
|
|
216
|
+
log.info(`Generating ${type} embeddings for document ${document.id}`);
|
|
217
|
+
if (
|
|
218
|
+
type === SupportedEmbeddingTypes.text &&
|
|
219
|
+
tokenCount !== undefined &&
|
|
220
|
+
tokenCount > maxTokens
|
|
221
|
+
) {
|
|
222
|
+
//TODO: Review strategy for large documents
|
|
223
|
+
log.warn(
|
|
224
|
+
`Document too large for ${type} embeddings generation, skipping (${tokenCount} tokens)`,
|
|
225
|
+
);
|
|
226
|
+
return {
|
|
227
|
+
id: document.id,
|
|
228
|
+
status: "skipped",
|
|
229
|
+
message: `${type} embeddings generation, skipped for large document (${tokenCount} tokens)`,
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
log.info(`Generating ${type} embeddings for document`);
|
|
233
|
+
|
|
234
|
+
const res = await generateEmbeddingsFromStudio(
|
|
235
|
+
JSON.stringify(document[type]),
|
|
236
|
+
environment,
|
|
237
|
+
client,
|
|
238
|
+
);
|
|
239
|
+
if (!res || !res.values) {
|
|
240
|
+
return {
|
|
241
|
+
id: document.id,
|
|
242
|
+
status: "failed",
|
|
243
|
+
message: "no embeddings generated",
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
log.info(`${type} embeddings generated for document ${document.id}`, {
|
|
248
|
+
len: res.values.length,
|
|
249
|
+
});
|
|
250
|
+
await client.objects.setEmbedding(document.id, type, {
|
|
251
|
+
values: res.values,
|
|
252
|
+
model: res.model,
|
|
253
|
+
etag: textEtag,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
id: document.id,
|
|
258
|
+
type,
|
|
259
|
+
status: "completed",
|
|
260
|
+
len: res.values.length,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function generateImageEmbeddings({
|
|
266
|
+
document,
|
|
267
|
+
client,
|
|
268
|
+
type,
|
|
269
|
+
config,
|
|
270
|
+
force,
|
|
271
|
+
}: ExecuteGenerateEmbeddingsParams) {
|
|
272
|
+
log.info("Generating image embeddings for document " + document.id, {
|
|
273
|
+
content: document.content,
|
|
274
|
+
});
|
|
275
|
+
if (
|
|
276
|
+
!document.content?.type?.startsWith("image/") &&
|
|
277
|
+
!document.content?.type?.includes("pdf")
|
|
278
|
+
) {
|
|
279
|
+
return {
|
|
280
|
+
id: document.id,
|
|
281
|
+
type,
|
|
282
|
+
status: "failed",
|
|
283
|
+
message: "content is not an image",
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Use content etag for image change detection
|
|
288
|
+
const contentEtag = document.content?.etag;
|
|
289
|
+
|
|
290
|
+
// Skip if embeddings already exist with matching etag (unless force=true)
|
|
291
|
+
const existingEmbedding = document.embeddings?.[type];
|
|
292
|
+
if (!force && existingEmbedding?.etag && contentEtag && existingEmbedding.etag === contentEtag) {
|
|
293
|
+
log.info(`Skipping ${type} embeddings for document ${document.id} - content etag unchanged`);
|
|
294
|
+
return {
|
|
295
|
+
id: document.id,
|
|
296
|
+
type,
|
|
297
|
+
status: "skipped",
|
|
298
|
+
message: "embeddings already exist with matching etag",
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const { environment, model } = config;
|
|
303
|
+
|
|
304
|
+
const resRnd = await client.store.objects.getRendition(document.id, {
|
|
305
|
+
format: ImageRenditionFormat.jpeg,
|
|
306
|
+
generate_if_missing: true,
|
|
307
|
+
sign_url: true,
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
if (resRnd.status === "generating") {
|
|
311
|
+
throw new Error("Rendition is generating, will retry later");
|
|
312
|
+
} else if (
|
|
313
|
+
resRnd.status === "failed" ||
|
|
314
|
+
!resRnd.renditions ||
|
|
315
|
+
!resRnd.renditions.length
|
|
316
|
+
) {
|
|
317
|
+
throw new DocumentNotFoundError("Rendition retrieval failed", [document.id]);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const renditions = resRnd.renditions;
|
|
321
|
+
if (!renditions?.length) {
|
|
322
|
+
throw new DocumentNotFoundError("No source found in rendition", [
|
|
323
|
+
document.id,
|
|
324
|
+
]);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const rendition = renditions[0];
|
|
328
|
+
const image = await fetchBlobAsBase64(client, rendition);
|
|
329
|
+
|
|
330
|
+
const res = await client.environments
|
|
331
|
+
.embeddings(environment, {
|
|
332
|
+
image,
|
|
333
|
+
model,
|
|
334
|
+
})
|
|
335
|
+
.then((res) => res)
|
|
336
|
+
.catch((e) => {
|
|
337
|
+
log.error("Error generating embeddings for image", { error: e });
|
|
338
|
+
throw e;
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
if (!res || !res.values) {
|
|
342
|
+
return {
|
|
343
|
+
id: document.id,
|
|
344
|
+
status: "failed",
|
|
345
|
+
message: "no embeddings generated",
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
await client.objects.setEmbedding(
|
|
350
|
+
document.id,
|
|
351
|
+
SupportedEmbeddingTypes.image,
|
|
352
|
+
{
|
|
353
|
+
values: res.values,
|
|
354
|
+
model: res.model,
|
|
355
|
+
etag: contentEtag,
|
|
356
|
+
},
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
id: document.id,
|
|
361
|
+
type,
|
|
362
|
+
status: "completed",
|
|
363
|
+
len: res.values.length,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function generateEmbeddingsFromStudio(
|
|
368
|
+
text: string,
|
|
369
|
+
env: string,
|
|
370
|
+
client: VertesiaClient,
|
|
371
|
+
model?: string,
|
|
372
|
+
): Promise<EmbeddingsResult> {
|
|
373
|
+
log.info(
|
|
374
|
+
`Generating embeddings for text of ${text.length} chars with environment ${env}`,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
return client.environments
|
|
378
|
+
.embeddings(env, {
|
|
379
|
+
text,
|
|
380
|
+
model,
|
|
381
|
+
})
|
|
382
|
+
.then((res) => res)
|
|
383
|
+
.catch((e) => {
|
|
384
|
+
log.error("Error generating embeddings for text", { error: e });
|
|
385
|
+
throw e;
|
|
386
|
+
});
|
|
387
|
+
}
|