@vertesia/workflow 0.42.2
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 +24 -0
- package/bin/bundle-workflows.mjs +26 -0
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js +32 -0
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -0
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +66 -0
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -0
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js +18 -0
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -0
- package/lib/cjs/activities/chunkDocument.js +79 -0
- package/lib/cjs/activities/chunkDocument.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 +135 -0
- package/lib/cjs/activities/executeInteraction.js.map +1 -0
- package/lib/cjs/activities/extractDocumentText.js +140 -0
- package/lib/cjs/activities/extractDocumentText.js.map +1 -0
- package/lib/cjs/activities/generateDocumentProperties.js +59 -0
- package/lib/cjs/activities/generateDocumentProperties.js.map +1 -0
- package/lib/cjs/activities/generateEmbeddings.js +292 -0
- package/lib/cjs/activities/generateEmbeddings.js.map +1 -0
- package/lib/cjs/activities/generateImageRendition.js +104 -0
- package/lib/cjs/activities/generateImageRendition.js.map +1 -0
- package/lib/cjs/activities/generateOrAssignContentType.js +103 -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/index.js +54 -0
- package/lib/cjs/activities/index.js.map +1 -0
- package/lib/cjs/activities/media/processPdfWithTextract.js +102 -0
- package/lib/cjs/activities/media/processPdfWithTextract.js.map +1 -0
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js +51 -0
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +1 -0
- package/lib/cjs/activities/notifyWebhook.js +34 -0
- package/lib/cjs/activities/notifyWebhook.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 +416 -0
- package/lib/cjs/conversion/TextractProcessor.js.map +1 -0
- package/lib/cjs/conversion/image.js +22 -0
- package/lib/cjs/conversion/image.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/conversion/pdf.js +13 -0
- package/lib/cjs/conversion/pdf.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 +223 -0
- package/lib/cjs/dsl/dsl-workflow.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 +96 -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/errors.js +36 -0
- package/lib/cjs/errors.js.map +1 -0
- package/lib/cjs/index.js +43 -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 +69 -0
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/generatePart.js +73 -0
- package/lib/cjs/iterative-generation/activities/generatePart.js.map +1 -0
- package/lib/cjs/iterative-generation/activities/generateToc.js +91 -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 +55 -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 +118 -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/generateObjectText.js +89 -0
- package/lib/cjs/system/generateObjectText.js.map +1 -0
- package/lib/cjs/system/notifyWebhookWorkflow.js +52 -0
- package/lib/cjs/system/notifyWebhookWorkflow.js.map +1 -0
- package/lib/cjs/system/recalculateEmbeddingsWorkflow.js +37 -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 +63 -0
- package/lib/cjs/utils/blobs.js.map +1 -0
- package/lib/cjs/utils/client.js +25 -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 +72 -0
- package/lib/cjs/utils/memory.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 +17 -0
- package/lib/cjs/workflows.js.map +1 -0
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js +29 -0
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -0
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +63 -0
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -0
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js +15 -0
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -0
- package/lib/esm/activities/chunkDocument.js +76 -0
- package/lib/esm/activities/chunkDocument.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 +131 -0
- package/lib/esm/activities/executeInteraction.js.map +1 -0
- package/lib/esm/activities/extractDocumentText.js +137 -0
- package/lib/esm/activities/extractDocumentText.js.map +1 -0
- package/lib/esm/activities/generateDocumentProperties.js +56 -0
- package/lib/esm/activities/generateDocumentProperties.js.map +1 -0
- package/lib/esm/activities/generateEmbeddings.js +256 -0
- package/lib/esm/activities/generateEmbeddings.js.map +1 -0
- package/lib/esm/activities/generateImageRendition.js +98 -0
- package/lib/esm/activities/generateImageRendition.js.map +1 -0
- package/lib/esm/activities/generateOrAssignContentType.js +100 -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/index.js +21 -0
- package/lib/esm/activities/index.js.map +1 -0
- package/lib/esm/activities/media/processPdfWithTextract.js +98 -0
- package/lib/esm/activities/media/processPdfWithTextract.js.map +1 -0
- package/lib/esm/activities/media/transcribeMediaWithGladia.js +48 -0
- package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +1 -0
- package/lib/esm/activities/notifyWebhook.js +31 -0
- package/lib/esm/activities/notifyWebhook.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 +409 -0
- package/lib/esm/conversion/TextractProcessor.js.map +1 -0
- package/lib/esm/conversion/image.js +16 -0
- package/lib/esm/conversion/image.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/conversion/pdf.js +7 -0
- package/lib/esm/conversion/pdf.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 +216 -0
- package/lib/esm/dsl/dsl-workflow.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 +91 -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/errors.js +30 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/index.js +25 -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 +66 -0
- package/lib/esm/iterative-generation/activities/finalizeOutput.js.map +1 -0
- package/lib/esm/iterative-generation/activities/generatePart.js +70 -0
- package/lib/esm/iterative-generation/activities/generatePart.js.map +1 -0
- package/lib/esm/iterative-generation/activities/generateToc.js +88 -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 +52 -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 +109 -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/generateObjectText.js +86 -0
- package/lib/esm/system/generateObjectText.js.map +1 -0
- package/lib/esm/system/notifyWebhookWorkflow.js +49 -0
- package/lib/esm/system/notifyWebhookWorkflow.js.map +1 -0
- package/lib/esm/system/recalculateEmbeddingsWorkflow.js +34 -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 +52 -0
- package/lib/esm/utils/blobs.js.map +1 -0
- package/lib/esm/utils/client.js +22 -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 +60 -0
- package/lib/esm/utils/memory.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 +9 -0
- package/lib/esm/workflows.js.map +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 +29 -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 +18 -0
- package/lib/types/activities/chunkDocument.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 +40 -0
- package/lib/types/activities/executeInteraction.d.ts.map +1 -0
- package/lib/types/activities/extractDocumentText.d.ts +9 -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 +49 -0
- package/lib/types/activities/generateEmbeddings.d.ts.map +1 -0
- package/lib/types/activities/generateImageRendition.d.ts +17 -0
- package/lib/types/activities/generateImageRendition.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/index.d.ts +21 -0
- package/lib/types/activities/index.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/transcribeMediaWithGladia.d.ts +14 -0
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +1 -0
- package/lib/types/activities/notifyWebhook.d.ts +17 -0
- package/lib/types/activities/notifyWebhook.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 +9 -0
- package/lib/types/conversion/image.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/conversion/pdf.d.ts +2 -0
- package/lib/types/conversion/pdf.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/projections.d.ts +4 -0
- package/lib/types/dsl/projections.d.ts.map +1 -0
- package/lib/types/dsl/setup/ActivityContext.d.ts +14 -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/errors.d.ts +16 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/index.d.ts +24 -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 +27 -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/generateObjectText.d.ts +4 -0
- package/lib/types/system/generateObjectText.d.ts.map +1 -0
- package/lib/types/system/notifyWebhookWorkflow.d.ts +6 -0
- package/lib/types/system/notifyWebhookWorkflow.d.ts.map +1 -0
- package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts +40 -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 +8 -0
- package/lib/types/utils/blobs.d.ts.map +1 -0
- package/lib/types/utils/client.d.ts +7 -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 +12 -0
- package/lib/types/utils/memory.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 +9 -0
- package/lib/types/workflows.d.ts.map +1 -0
- package/lib/workflows-bundle.js +18394 -0
- package/package.json +109 -0
- package/src/activities/advanced/createDocumentTypeFromInteractionRun.ts +54 -0
- package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +97 -0
- package/src/activities/advanced/updateDocumentFromInteractionRun.ts +34 -0
- package/src/activities/chunkDocument.ts +124 -0
- package/src/activities/createDocumentFromOther.ts +92 -0
- package/src/activities/executeInteraction.ts +191 -0
- package/src/activities/extractDocumentText.ts +174 -0
- package/src/activities/generateDocumentProperties.ts +93 -0
- package/src/activities/generateEmbeddings.ts +345 -0
- package/src/activities/generateImageRendition.ts +134 -0
- package/src/activities/generateOrAssignContentType.ts +152 -0
- package/src/activities/getObjectFromStore.ts +31 -0
- package/src/activities/index.ts +21 -0
- package/src/activities/media/processPdfWithTextract.ts +141 -0
- package/src/activities/media/transcribeMediaWithGladia.ts +83 -0
- package/src/activities/notifyWebhook.test.ts +32 -0
- package/src/activities/notifyWebhook.ts +51 -0
- package/src/activities/setDocumentStatus.ts +25 -0
- package/src/conversion/TextractProcessor.ts +505 -0
- package/src/conversion/image.test.ts +26 -0
- package/src/conversion/image.ts +22 -0
- package/src/conversion/mutool.test.ts +74 -0
- package/src/conversion/mutool.ts +180 -0
- package/src/conversion/pandoc.test.ts +22 -0
- package/src/conversion/pandoc.ts +44 -0
- package/src/conversion/pdf.test.ts +35 -0
- package/src/conversion/pdf.ts +8 -0
- package/src/dsl/conditions.ts +76 -0
- package/src/dsl/dsl-workflow.test.ts +58 -0
- package/src/dsl/dsl-workflow.ts +235 -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 +106 -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 +182 -0
- package/src/dsl/workflow-fetch.test.ts +135 -0
- package/src/dsl/workflow-import.test.ts +89 -0
- package/src/dsl/workflow.test.ts +110 -0
- package/src/errors.ts +24 -0
- package/src/index.ts +27 -0
- package/src/iterative-generation/activities/extractToc.ts +49 -0
- package/src/iterative-generation/activities/finalizeOutput.ts +77 -0
- package/src/iterative-generation/activities/generatePart.ts +82 -0
- package/src/iterative-generation/activities/generateToc.ts +98 -0
- package/src/iterative-generation/activities/index.ts +4 -0
- package/src/iterative-generation/iterativeGenerationWorkflow.ts +67 -0
- package/src/iterative-generation/types.ts +99 -0
- package/src/iterative-generation/utils.ts +123 -0
- package/src/result-types.ts +25 -0
- package/src/system/generateObjectText.ts +109 -0
- package/src/system/notifyWebhookWorkflow.ts +64 -0
- package/src/system/recalculateEmbeddingsWorkflow.ts +46 -0
- package/src/utils/auth.ts +10 -0
- package/src/utils/blobs.ts +58 -0
- package/src/utils/client.ts +31 -0
- package/src/utils/expand-vars.ts +31 -0
- package/src/utils/memory.ts +66 -0
- package/src/utils/tokens.ts +44 -0
- package/src/vars.ts +3 -0
- package/src/workflows.ts +9 -0
package/package.json
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
{
|
2
|
+
"name": "@vertesia/workflow",
|
3
|
+
"version": "0.42.2",
|
4
|
+
"type": "module",
|
5
|
+
"description": "Composable prompts workflow dsl",
|
6
|
+
"main": "./lib/esm/index.js",
|
7
|
+
"files": [
|
8
|
+
"lib",
|
9
|
+
"src"
|
10
|
+
],
|
11
|
+
"bin": {
|
12
|
+
"bundle-workflows": "./bin/bundle-workflows.mjs"
|
13
|
+
},
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "https://github.com/vertesia/composableai.git",
|
17
|
+
"directory": "zeno/workflow"
|
18
|
+
},
|
19
|
+
"license": "Apache-2.0",
|
20
|
+
"devDependencies": {
|
21
|
+
"@temporalio/testing": "^1.11.5",
|
22
|
+
"@temporalio/worker": "^1.11.5",
|
23
|
+
"@types/jsonwebtoken": "^9.0.7",
|
24
|
+
"@types/node": "^22.5.1",
|
25
|
+
"@types/papaparse": "^5.3.15",
|
26
|
+
"@types/tmp": "^0.2.6",
|
27
|
+
"ts-dual-module": "^0.6.3",
|
28
|
+
"vitest": "^2.1.6",
|
29
|
+
"@smithy/types": "^3.7.2"
|
30
|
+
},
|
31
|
+
"dependencies": {
|
32
|
+
"@aws-sdk/client-s3": "^3.693.0",
|
33
|
+
"@aws-sdk/client-textract": "^3.693.0",
|
34
|
+
"@aws-sdk/credential-providers": "^3.693.0",
|
35
|
+
"@becomposable/memory": "^0.43.0",
|
36
|
+
"@opendocsg/pdf2md": "0.2.0",
|
37
|
+
"@temporalio/activity": "^1.11.5",
|
38
|
+
"@temporalio/workflow": "^1.11.5",
|
39
|
+
"@tensorflow/tfjs-node": "^4.19.0",
|
40
|
+
"@types/json-schema": "^7.0.15",
|
41
|
+
"api-fetch-client": "^0.13.0",
|
42
|
+
"fast-deep-equal": "^3.1.3",
|
43
|
+
"jsonwebtoken": "^9.0.2",
|
44
|
+
"ms": "3.0.0-canary.1",
|
45
|
+
"node-web-stream-adapters": "^0.2.1",
|
46
|
+
"papaparse": "^5.4.1",
|
47
|
+
"seedrandom": "^3.0.5",
|
48
|
+
"sharp": "^0.33.4",
|
49
|
+
"tiktoken": "^1.0.15",
|
50
|
+
"tmp": "^0.2.3",
|
51
|
+
"yaml": "^2.6.0",
|
52
|
+
"@vertesia/common": "0.42.2",
|
53
|
+
"@llumiverse/core": "0.15.0",
|
54
|
+
"@vertesia/client": "0.42.2"
|
55
|
+
},
|
56
|
+
"ts_dual_module": {
|
57
|
+
"outDir": "lib",
|
58
|
+
"exports": {
|
59
|
+
"activities": "./activities",
|
60
|
+
"workflows": "./workflows",
|
61
|
+
"workflows-bundle": "./workflows-bundle.js",
|
62
|
+
"vars": "./vars"
|
63
|
+
}
|
64
|
+
},
|
65
|
+
"exports": {
|
66
|
+
".": {
|
67
|
+
"types": "./lib/types/index.d.ts",
|
68
|
+
"import": "./lib/esm/index.js",
|
69
|
+
"require": "./lib/cjs/index.js"
|
70
|
+
},
|
71
|
+
"./vars": {
|
72
|
+
"types": "./lib/types/vars.d.ts",
|
73
|
+
"import": "./lib/esm/vars.js",
|
74
|
+
"require": "./lib/cjs/vars.js"
|
75
|
+
},
|
76
|
+
"./activities": {
|
77
|
+
"types": "./lib/types/activities/index.d.ts",
|
78
|
+
"import": "./lib/esm/activities/index.js",
|
79
|
+
"require": "./lib/cjs/activities/index.js"
|
80
|
+
},
|
81
|
+
"./workflows": {
|
82
|
+
"types": "./lib/types/workflows.d.ts",
|
83
|
+
"import": "./lib/esm/workflows.js",
|
84
|
+
"require": "./lib/cjs/workflows.js"
|
85
|
+
},
|
86
|
+
"./workflows-bundle": {
|
87
|
+
"import": "./lib/workflows-bundle.js"
|
88
|
+
}
|
89
|
+
},
|
90
|
+
"types": "./lib/types/index.d.ts",
|
91
|
+
"typesVersions": {
|
92
|
+
"*": {
|
93
|
+
"activities": [
|
94
|
+
"./lib/types/activities/index.d.ts"
|
95
|
+
],
|
96
|
+
"workflows": [
|
97
|
+
"./lib/types/workflows.d.ts"
|
98
|
+
],
|
99
|
+
"vars": [
|
100
|
+
"./lib/types/dsl/vars.d.ts"
|
101
|
+
]
|
102
|
+
}
|
103
|
+
},
|
104
|
+
"scripts": {
|
105
|
+
"test": "vitest run",
|
106
|
+
"build": "pnpm exec tsmod build && node ./bin/bundle-workflows.mjs lib/esm/workflows.js lib/workflows-bundle.js",
|
107
|
+
"clean": "rm -rf ./lib tsconfig.tsbuildinfo"
|
108
|
+
}
|
109
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { CreateContentObjectTypePayload, DSLActivityExecutionPayload, DSLActivitySpec, ExecutionRun } from "@vertesia/common";
|
2
|
+
import { log } from "@temporalio/activity";
|
3
|
+
import { projectResult } from "../../dsl/projections.js";
|
4
|
+
import { setupActivity } from "../../dsl/setup/ActivityContext.js";
|
5
|
+
import { ActivityParamNotFound } from "../../errors.js";
|
6
|
+
|
7
|
+
|
8
|
+
export interface CreateDocumentTypeFromInteractionRunParams {
|
9
|
+
/**
|
10
|
+
* The execution run object to use. Required.
|
11
|
+
* Not required in params since it is usually fetched
|
12
|
+
*/
|
13
|
+
run: ExecutionRun,
|
14
|
+
/**
|
15
|
+
* If defined then update the object type with the created type
|
16
|
+
*/
|
17
|
+
updateObjectId?: string;
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface CreateDocumentTypeFromInteractionRun extends DSLActivitySpec<CreateDocumentTypeFromInteractionRunParams> {
|
21
|
+
name: 'createDocumentTypeFromInteractionRun';
|
22
|
+
}
|
23
|
+
|
24
|
+
export async function createDocumentTypeFromInteractionRun(payload: DSLActivityExecutionPayload) {
|
25
|
+
const { params, client } = await setupActivity<CreateDocumentTypeFromInteractionRunParams>(payload);
|
26
|
+
|
27
|
+
if (!params.run) {
|
28
|
+
throw new ActivityParamNotFound("run", payload.activity);
|
29
|
+
}
|
30
|
+
|
31
|
+
const genTypeRes = params.run.result;
|
32
|
+
|
33
|
+
if (!genTypeRes.document_type) {
|
34
|
+
log.error("No name generated for type: " + JSON.stringify(genTypeRes), genTypeRes);
|
35
|
+
throw new Error("No name generated for type");
|
36
|
+
}
|
37
|
+
|
38
|
+
log.info("Generated schema for type", genTypeRes.metadata_schema);
|
39
|
+
const typeData: CreateContentObjectTypePayload = {
|
40
|
+
name: genTypeRes.document_type,
|
41
|
+
object_schema: genTypeRes.metadata_schema,
|
42
|
+
is_chunkable: !!genTypeRes.is_chunkable,
|
43
|
+
}
|
44
|
+
|
45
|
+
const type = await client.types.create(typeData);
|
46
|
+
|
47
|
+
if (params.updateObjectId) {
|
48
|
+
await client.objects.update(params.updateObjectId, {
|
49
|
+
type: type.id,
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
return projectResult(payload, params, type, { id: type.id, name: type.name });
|
54
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { ContentObjectStatus, DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
2
|
+
import { log } from "@temporalio/activity";
|
3
|
+
import { setupActivity } from "../../dsl/setup/ActivityContext.js";
|
4
|
+
import { ActivityParamNotFound, NoDocumentFound } from "../../errors.js";
|
5
|
+
interface CreateOrUpdateObjectFromInteractionRunParams {
|
6
|
+
/**
|
7
|
+
* The execution run object to use. Required.
|
8
|
+
* Not required in params since it is usually fetched
|
9
|
+
*/
|
10
|
+
run_id?: string,
|
11
|
+
/**
|
12
|
+
* The document type to use. Required if update_existing_id is false.
|
13
|
+
* Not required in params since it is usually fetched
|
14
|
+
*/
|
15
|
+
object_type?: string,
|
16
|
+
|
17
|
+
/**
|
18
|
+
* The id of the document to update. If not provided, a new document will be created
|
19
|
+
*/
|
20
|
+
update_existing_id?: string,
|
21
|
+
|
22
|
+
fallback_name?: string, // a name to use if no one was generated by the interaction
|
23
|
+
|
24
|
+
parent?: string, // the parent object id
|
25
|
+
}
|
26
|
+
|
27
|
+
export interface CreateOrUpdateObjectFromInteractionRun extends DSLActivitySpec<CreateOrUpdateObjectFromInteractionRunParams> {
|
28
|
+
name: 'createOrUpdateDocumentFromInteractionRun';
|
29
|
+
}
|
30
|
+
|
31
|
+
export async function createOrUpdateDocumentFromInteractionRun(payload: DSLActivityExecutionPayload) {
|
32
|
+
const { params, client } = await setupActivity<CreateOrUpdateObjectFromInteractionRunParams>(payload);
|
33
|
+
|
34
|
+
const runId = params.run_id;
|
35
|
+
const objectTypeName = params.object_type;
|
36
|
+
|
37
|
+
if (!runId) {
|
38
|
+
throw new ActivityParamNotFound("run_id", payload.activity);
|
39
|
+
}
|
40
|
+
if (!objectTypeName && !params.update_existing_id) {
|
41
|
+
throw new ActivityParamNotFound("object_type", payload.activity);
|
42
|
+
}
|
43
|
+
|
44
|
+
log.info("Creating document from interaction result", { runId, objectTypeName });
|
45
|
+
|
46
|
+
const run = await client.runs.retrieve(runId).catch((e) => {
|
47
|
+
throw new NoDocumentFound(`Error fetching run ${runId}: ${e.message}`);
|
48
|
+
});
|
49
|
+
|
50
|
+
const type = objectTypeName ?
|
51
|
+
await client.types.getTypeByName(objectTypeName).catch((e) => {
|
52
|
+
throw new NoDocumentFound(`Error fetching type ${objectTypeName}: ${e.message}`);
|
53
|
+
})
|
54
|
+
: undefined;
|
55
|
+
|
56
|
+
|
57
|
+
const result = run.result;
|
58
|
+
const resultIsObject = typeof result === 'object';
|
59
|
+
const inputData = run.parameters;
|
60
|
+
|
61
|
+
let name: string;
|
62
|
+
if (resultIsObject) {
|
63
|
+
name = result['name'] || result["title"] || inputData['name'] || params.fallback_name || 'Untitled';
|
64
|
+
} else {
|
65
|
+
name = inputData['name'] || params.fallback_name || 'Untitled';
|
66
|
+
}
|
67
|
+
|
68
|
+
const docPayload = {
|
69
|
+
name,
|
70
|
+
parent: params.parent ?? undefined,
|
71
|
+
properties: resultIsObject ? result : {},
|
72
|
+
text: !resultIsObject ? result : undefined,
|
73
|
+
type: type?.id,
|
74
|
+
status: ContentObjectStatus.completed,
|
75
|
+
generation_run_info: {
|
76
|
+
id: run.id,
|
77
|
+
date: new Date().toISOString(),
|
78
|
+
model: run.modelId,
|
79
|
+
target: resultIsObject ? 'properties' : 'text'
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
//create or update the document
|
84
|
+
let newDoc: boolean = false;
|
85
|
+
let doc = undefined;
|
86
|
+
if (params.update_existing_id) {
|
87
|
+
log.info(`Updating existing document ${params.update_existing_id}`);
|
88
|
+
doc = await client.objects.update(params.update_existing_id, docPayload);
|
89
|
+
} else {
|
90
|
+
log.info(`Creating new document of type ${objectTypeName}`);
|
91
|
+
doc = await client.objects.create(docPayload);
|
92
|
+
newDoc = true;
|
93
|
+
}
|
94
|
+
|
95
|
+
log.info(`Document ${objectTypeName + ' '}${doc.id}(${doc.name}) ${newDoc ? 'created' : 'updated'}`);
|
96
|
+
return { id: doc.id, isNew: newDoc, type: name }
|
97
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec, ExecutionRun } from "@vertesia/common";
|
2
|
+
import { setupActivity } from "../../dsl/setup/ActivityContext.js";
|
3
|
+
import { ActivityParamNotFound } from "../../errors.js";
|
4
|
+
|
5
|
+
|
6
|
+
export interface UpdateDocumentFromInteractionRunParams {
|
7
|
+
/**
|
8
|
+
* The execution run object to use. Required.
|
9
|
+
* Not required in params since it is usually fetched
|
10
|
+
*/
|
11
|
+
run?: ExecutionRun,
|
12
|
+
}
|
13
|
+
|
14
|
+
export interface UpdateDocumentFromInteractionRun extends DSLActivitySpec<UpdateDocumentFromInteractionRunParams> {
|
15
|
+
name: 'updateDocumentFromInteractionRun';
|
16
|
+
}
|
17
|
+
|
18
|
+
export async function updateDocumentFromInteractionRun(payload: DSLActivityExecutionPayload) {
|
19
|
+
const { params, client, objectId } = await setupActivity<UpdateDocumentFromInteractionRunParams>(payload);
|
20
|
+
|
21
|
+
if (!params.run) {
|
22
|
+
throw new ActivityParamNotFound("run", payload.activity);
|
23
|
+
}
|
24
|
+
|
25
|
+
const docProps = params.run.result;
|
26
|
+
|
27
|
+
if (!docProps) {
|
28
|
+
return { status: "failed", error: "no-props" };
|
29
|
+
}
|
30
|
+
|
31
|
+
await client.objects.update(objectId, docProps);
|
32
|
+
|
33
|
+
return { status: "success" };
|
34
|
+
}
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
2
|
+
import { log } from "@temporalio/activity";
|
3
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
4
|
+
import { InteractionExecutionParams, executeInteractionFromActivity } from "./executeInteraction.js";
|
5
|
+
|
6
|
+
const INT_CHUNK_DOCUMENT = "sys:ChunkDocument"
|
7
|
+
|
8
|
+
interface DocPart {
|
9
|
+
|
10
|
+
line_number_start: number
|
11
|
+
line_number_end: number
|
12
|
+
name: string
|
13
|
+
type: string
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
export interface ChunkDocumentResult {
|
18
|
+
id: string
|
19
|
+
status: "completed" | "failed" | "skipped"
|
20
|
+
parts?: string[]
|
21
|
+
message?: string
|
22
|
+
}
|
23
|
+
|
24
|
+
export interface ChunkDocumentParams extends InteractionExecutionParams {
|
25
|
+
force?: boolean;
|
26
|
+
interactionName?: string;
|
27
|
+
docPartType?: string;
|
28
|
+
}
|
29
|
+
|
30
|
+
export interface ChunkDocument extends DSLActivitySpec<ChunkDocumentParams> {
|
31
|
+
name: 'chunkDocument';
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
export async function chunkDocument(payload: DSLActivityExecutionPayload): Promise<ChunkDocumentResult> {
|
36
|
+
const { params, client, objectId } = await setupActivity<ChunkDocumentParams>(payload);
|
37
|
+
|
38
|
+
const { force } = params;
|
39
|
+
const interactionName = params.interactionName ?? INT_CHUNK_DOCUMENT;
|
40
|
+
|
41
|
+
log.info(`Object ${objectId} chunking started`);
|
42
|
+
|
43
|
+
const document = await client.objects.retrieve(objectId, "+text");
|
44
|
+
|
45
|
+
const type = document.type ? await client.types.retrieve(document.type.id) : undefined;
|
46
|
+
|
47
|
+
if (!type?.is_chunkable) {
|
48
|
+
log.warn('Type is not chunkable for object ID: ' + objectId);
|
49
|
+
return { id: objectId, status: "skipped", message: "type not chunkable" }
|
50
|
+
}
|
51
|
+
|
52
|
+
//check if text is present
|
53
|
+
if (!document.text) {
|
54
|
+
log.warn('No text found for object ID: ' + objectId);
|
55
|
+
return { id: objectId, status: "failed", message: "no text found" }
|
56
|
+
}
|
57
|
+
|
58
|
+
if (!force && document.parts && document.parts.length > 0 && document.parts_etag === document.text_etag) {
|
59
|
+
log.info('Document already chunked for object ID: ' + objectId);
|
60
|
+
return { id: objectId, status: "skipped", message: "document already chunked with correct etag" }
|
61
|
+
}
|
62
|
+
|
63
|
+
//instrument the text with line numbers
|
64
|
+
const lines = document.text.split('\n')
|
65
|
+
const instrumented = lines.map((l, i) => `{%${i}%}${l}`).join('\n')
|
66
|
+
|
67
|
+
const res = await executeInteractionFromActivity(client, interactionName, params, {
|
68
|
+
objectId: objectId,
|
69
|
+
content: instrumented
|
70
|
+
});
|
71
|
+
|
72
|
+
const parts = res.result.parts as DocPart[];
|
73
|
+
if (!parts || parts.length === 0) {
|
74
|
+
log.warn('No parts found for object ID: ' + objectId, res);
|
75
|
+
return { id: objectId, status: "failed", parts: [], message: "no parts found" }
|
76
|
+
}
|
77
|
+
|
78
|
+
const partDocs = await Promise.all(parts.map(async (part, i) => {
|
79
|
+
|
80
|
+
const text = lines.filter((_l, i) => i >= part.line_number_start && i <= part.line_number_end).join('\n');
|
81
|
+
|
82
|
+
const location = () => {
|
83
|
+
let location = document.location;
|
84
|
+
if (location.endsWith('/')) {
|
85
|
+
location += document.name + "/" + part.type
|
86
|
+
}
|
87
|
+
location += '/' + document.name + "/" + part.type;
|
88
|
+
return location;
|
89
|
+
}
|
90
|
+
|
91
|
+
const docPart = await client.objects.create({
|
92
|
+
name: part.name,
|
93
|
+
parent: objectId,
|
94
|
+
text: text,
|
95
|
+
location: location(),
|
96
|
+
properties: {
|
97
|
+
part_number: i + 1,
|
98
|
+
etag: document.text_etag,
|
99
|
+
source_line_start: part.line_number_start,
|
100
|
+
source_line_end: part.line_number_end,
|
101
|
+
title: part.name
|
102
|
+
}
|
103
|
+
});
|
104
|
+
return docPart;
|
105
|
+
}));
|
106
|
+
|
107
|
+
//delete previous parts
|
108
|
+
if (document.parts && document.parts.length > 0) {
|
109
|
+
log.info('Deleting previous parts for object ID: ' + objectId, { parts: document.parts });
|
110
|
+
await Promise.all(document.parts.map(async (partId) => {
|
111
|
+
await client.objects.delete(partId);
|
112
|
+
}));
|
113
|
+
}
|
114
|
+
|
115
|
+
await client.objects.update(objectId, {
|
116
|
+
parts: partDocs.map(p => p.id),
|
117
|
+
parts_etag: document.text_etag
|
118
|
+
});
|
119
|
+
|
120
|
+
log.info(`Object ${objectId} chunking completed`, { parts: document.parts });
|
121
|
+
|
122
|
+
return { id: objectId, status: "completed", parts: document.parts }
|
123
|
+
|
124
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
|
2
|
+
import { log } from "@temporalio/activity";
|
3
|
+
import fs from 'fs';
|
4
|
+
import { pdfExtractPages } from "../conversion/mutool.js";
|
5
|
+
import { setupActivity } from "../dsl/setup/ActivityContext.js";
|
6
|
+
import { NoDocumentFound } from "../errors.js";
|
7
|
+
import { saveBlobToTempFile } from "../utils/blobs.js";
|
8
|
+
import { NodeStreamSource } from "../utils/memory.js";
|
9
|
+
|
10
|
+
interface CreatePdfDocumentFromSourceParams {
|
11
|
+
|
12
|
+
target_object_type: string; //type of the object to create
|
13
|
+
title: string; //title of the object to create
|
14
|
+
filename?: string; //filename of the object to create
|
15
|
+
pages: number[]; //pages to extract into the new document
|
16
|
+
parent?: string; //set the new document as child of the source document
|
17
|
+
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
export interface CreatePdfDocumentFromSource extends DSLActivitySpec<CreatePdfDocumentFromSourceParams> {
|
22
|
+
name: 'createPdfDocumentFromSource';
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Create a new PDF by extrracting pages from a source PDF
|
28
|
+
* @returns
|
29
|
+
*/
|
30
|
+
export async function createPdfDocumentFromSource(payload: DSLActivityExecutionPayload) {
|
31
|
+
const { client, objectId, params } = await setupActivity<CreatePdfDocumentFromSourceParams>(payload);
|
32
|
+
const inputObject = await client.objects.retrieve(objectId);
|
33
|
+
|
34
|
+
const { pages, filename, title } = params;
|
35
|
+
log.info(`Creating PDF from source`, { objectId, pages, filename, title });
|
36
|
+
|
37
|
+
if (!pages || pages.length === 0) {
|
38
|
+
log.error(`No pages provided`);
|
39
|
+
throw new Error(`No pages provided`);
|
40
|
+
}
|
41
|
+
|
42
|
+
if (!inputObject) {
|
43
|
+
log.error(`Document ${objectId} not found`);
|
44
|
+
throw new NoDocumentFound(`Document ${objectId} not found`, [objectId]);
|
45
|
+
}
|
46
|
+
|
47
|
+
if (!inputObject.content?.source) {
|
48
|
+
log.error(`Document ${objectId} has no source`);
|
49
|
+
throw new NoDocumentFound(`Document ${objectId} has no source`, [objectId]);
|
50
|
+
}
|
51
|
+
|
52
|
+
if (!inputObject.content.type || (!inputObject.content.type?.startsWith('application/pdf'))) {
|
53
|
+
log.error(`Document ${objectId} is not an image`);
|
54
|
+
throw new NoDocumentFound(`Document ${objectId} is not an image or pdf: ${inputObject.content.type}`, [objectId]);
|
55
|
+
}
|
56
|
+
|
57
|
+
const targetType = await client.types.getTypeByName(params.target_object_type);
|
58
|
+
if (!targetType) {
|
59
|
+
log.error(`Type ${params.target_object_type} not found`);
|
60
|
+
throw new NoDocumentFound(`Type ${params.target_object_type} not found`);
|
61
|
+
}
|
62
|
+
|
63
|
+
const tmpFile = await saveBlobToTempFile(client, inputObject.content.source, ".pdf");
|
64
|
+
const newPdf = await pdfExtractPages(tmpFile, pages);
|
65
|
+
log.info(`PDF created from pages ${pages.join(', ')} `, { newPdf });
|
66
|
+
const name = `pages-${pages.join('-')}.pdf`;
|
67
|
+
|
68
|
+
const sourceToUpload = new NodeStreamSource(
|
69
|
+
fs.createReadStream(newPdf),
|
70
|
+
name,
|
71
|
+
"application/pdf"
|
72
|
+
)
|
73
|
+
|
74
|
+
log.info(`Uploading file ${newPdf} `);
|
75
|
+
const upload = await client.objects.upload(sourceToUpload);
|
76
|
+
log.info(`File uploaded ${upload.source} `);
|
77
|
+
|
78
|
+
const newObject = await client.objects.create({
|
79
|
+
type: targetType.id,
|
80
|
+
name: title || targetType.name,
|
81
|
+
parent: objectId,
|
82
|
+
content: {
|
83
|
+
source: upload.source,
|
84
|
+
name: upload.name,
|
85
|
+
type: 'application/pdf'
|
86
|
+
}
|
87
|
+
});
|
88
|
+
|
89
|
+
return { newObjectId: newObject.id, uploadedFile: upload.name };
|
90
|
+
|
91
|
+
|
92
|
+
}
|