@vertesia/workflow 0.51.0 → 0.54.0
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/package.json +9 -6
- package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +20 -1
- package/src/activities/chunkDocument.ts +62 -42
- package/src/activities/createDocumentFromOther.ts +2 -2
- package/src/activities/executeInteraction.ts +92 -47
- package/src/activities/extractDocumentText.ts +91 -54
- package/src/activities/generateDocumentProperties.ts +37 -16
- package/src/activities/generateEmbeddings.ts +91 -79
- package/src/activities/generateImageRendition.ts +127 -59
- package/src/activities/generateOrAssignContentType.ts +52 -32
- package/src/activities/getObjectFromStore.ts +1 -1
- package/src/activities/handleError.ts +25 -0
- package/src/activities/index-dsl.ts +1 -0
- package/src/activities/index.ts +0 -1
- package/src/activities/media/processPdfWithTextract.ts +4 -4
- package/src/activities/media/transcribeMediaWithGladia.ts +1 -1
- package/src/activities/notifyWebhook.ts +2 -2
- package/src/activities/setDocumentStatus.ts +1 -1
- package/src/conversion/TextractProcessor.ts +9 -9
- package/src/conversion/image.test.ts +110 -18
- package/src/conversion/image.ts +96 -15
- package/src/conversion/markitdown.ts +41 -0
- package/src/conversion/mutool.ts +1 -1
- package/src/conversion/pandoc.test.ts +8 -6
- package/src/conversion/pandoc.ts +38 -42
- package/src/dsl/dsl-workflow.ts +80 -12
- package/src/dsl/setup/ActivityContext.ts +57 -16
- package/src/dsl/validation.test.ts +2 -2
- package/src/dsl/vars.test.ts +1 -1
- package/src/dsl/vars.ts +6 -6
- package/src/dsl/workflow-exec-child.test.ts +14 -4
- package/src/dsl/workflow-fetch.test.ts +1 -1
- package/src/dsl/workflow-import.test.ts +1 -1
- package/src/dsl/workflow.test.ts +12 -2
- package/src/dsl.ts +1 -1
- package/src/errors.ts +27 -6
- package/src/index.ts +1 -1
- package/src/iterative-generation/activities/extractToc.ts +1 -1
- package/src/iterative-generation/activities/generatePart.ts +2 -2
- package/src/iterative-generation/activities/generateToc.ts +1 -1
- package/src/iterative-generation/iterativeGenerationWorkflow.ts +3 -2
- package/src/iterative-generation/types.ts +4 -4
- package/src/iterative-generation/utils.ts +4 -4
- package/src/system/notifyWebhookWorkflow.ts +2 -1
- package/src/system/recalculateEmbeddingsWorkflow.ts +2 -2
- package/src/utils/blobs.ts +11 -6
- package/src/utils/chunks.ts +17 -0
- package/src/utils/client.ts +4 -3
- package/src/utils/memory.ts +3 -8
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js +0 -32
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js.map +0 -1
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +0 -66
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +0 -1
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js +0 -18
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js.map +0 -1
- package/lib/cjs/activities/chunkDocument.js +0 -79
- package/lib/cjs/activities/chunkDocument.js.map +0 -1
- package/lib/cjs/activities/createDocumentFromOther.js +0 -64
- package/lib/cjs/activities/createDocumentFromOther.js.map +0 -1
- package/lib/cjs/activities/executeInteraction.js +0 -134
- package/lib/cjs/activities/executeInteraction.js.map +0 -1
- package/lib/cjs/activities/extractDocumentText.js +0 -135
- package/lib/cjs/activities/extractDocumentText.js.map +0 -1
- package/lib/cjs/activities/generateDocumentProperties.js +0 -59
- package/lib/cjs/activities/generateDocumentProperties.js.map +0 -1
- package/lib/cjs/activities/generateEmbeddings.js +0 -292
- package/lib/cjs/activities/generateEmbeddings.js.map +0 -1
- package/lib/cjs/activities/generateImageRendition.js +0 -104
- package/lib/cjs/activities/generateImageRendition.js.map +0 -1
- package/lib/cjs/activities/generateOrAssignContentType.js +0 -103
- package/lib/cjs/activities/generateOrAssignContentType.js.map +0 -1
- package/lib/cjs/activities/getObjectFromStore.js +0 -20
- package/lib/cjs/activities/getObjectFromStore.js.map +0 -1
- package/lib/cjs/activities/index-dsl.js +0 -37
- package/lib/cjs/activities/index-dsl.js.map +0 -1
- package/lib/cjs/activities/index.js +0 -22
- package/lib/cjs/activities/index.js.map +0 -1
- package/lib/cjs/activities/media/processPdfWithTextract.js +0 -102
- package/lib/cjs/activities/media/processPdfWithTextract.js.map +0 -1
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js +0 -51
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +0 -1
- package/lib/cjs/activities/notifyWebhook.js +0 -34
- package/lib/cjs/activities/notifyWebhook.js.map +0 -1
- package/lib/cjs/activities/setDocumentStatus.js +0 -15
- package/lib/cjs/activities/setDocumentStatus.js.map +0 -1
- package/lib/cjs/conversion/TextractProcessor.js +0 -417
- package/lib/cjs/conversion/TextractProcessor.js.map +0 -1
- package/lib/cjs/conversion/image.js +0 -22
- package/lib/cjs/conversion/image.js.map +0 -1
- package/lib/cjs/conversion/mutool.js +0 -147
- package/lib/cjs/conversion/mutool.js.map +0 -1
- package/lib/cjs/conversion/pandoc.js +0 -39
- package/lib/cjs/conversion/pandoc.js.map +0 -1
- package/lib/cjs/dsl/conditions.js +0 -81
- package/lib/cjs/dsl/conditions.js.map +0 -1
- package/lib/cjs/dsl/dsl-workflow.js +0 -223
- package/lib/cjs/dsl/dsl-workflow.js.map +0 -1
- package/lib/cjs/dsl/dslProxyActivities.js +0 -23
- package/lib/cjs/dsl/dslProxyActivities.js.map +0 -1
- package/lib/cjs/dsl/projections.js +0 -59
- package/lib/cjs/dsl/projections.js.map +0 -1
- package/lib/cjs/dsl/setup/ActivityContext.js +0 -96
- package/lib/cjs/dsl/setup/ActivityContext.js.map +0 -1
- package/lib/cjs/dsl/setup/fetch/DataProvider.js +0 -51
- package/lib/cjs/dsl/setup/fetch/DataProvider.js.map +0 -1
- package/lib/cjs/dsl/setup/fetch/index.js +0 -16
- package/lib/cjs/dsl/setup/fetch/index.js.map +0 -1
- package/lib/cjs/dsl/setup/fetch/providers.js +0 -67
- package/lib/cjs/dsl/setup/fetch/providers.js.map +0 -1
- package/lib/cjs/dsl/test/test-child-workflow.js +0 -10
- package/lib/cjs/dsl/test/test-child-workflow.js.map +0 -1
- package/lib/cjs/dsl/validation.js +0 -122
- package/lib/cjs/dsl/validation.js.map +0 -1
- package/lib/cjs/dsl/vars.js +0 -341
- package/lib/cjs/dsl/vars.js.map +0 -1
- package/lib/cjs/dsl/walk.js +0 -100
- package/lib/cjs/dsl/walk.js.map +0 -1
- package/lib/cjs/dsl.js +0 -20
- package/lib/cjs/dsl.js.map +0 -1
- package/lib/cjs/errors.js +0 -36
- package/lib/cjs/errors.js.map +0 -1
- package/lib/cjs/index.js +0 -50
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/iterative-generation/activities/extractToc.js +0 -47
- package/lib/cjs/iterative-generation/activities/extractToc.js.map +0 -1
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js +0 -69
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js.map +0 -1
- package/lib/cjs/iterative-generation/activities/generatePart.js +0 -73
- package/lib/cjs/iterative-generation/activities/generatePart.js.map +0 -1
- package/lib/cjs/iterative-generation/activities/generateToc.js +0 -91
- package/lib/cjs/iterative-generation/activities/generateToc.js.map +0 -1
- package/lib/cjs/iterative-generation/activities/index.js +0 -12
- package/lib/cjs/iterative-generation/activities/index.js.map +0 -1
- package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js +0 -55
- package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js.map +0 -1
- package/lib/cjs/iterative-generation/types.js +0 -5
- package/lib/cjs/iterative-generation/types.js.map +0 -1
- package/lib/cjs/iterative-generation/utils.js +0 -121
- package/lib/cjs/iterative-generation/utils.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/result-types.js +0 -10
- package/lib/cjs/result-types.js.map +0 -1
- package/lib/cjs/system/notifyWebhookWorkflow.js +0 -46
- package/lib/cjs/system/notifyWebhookWorkflow.js.map +0 -1
- package/lib/cjs/system/recalculateEmbeddingsWorkflow.js +0 -28
- package/lib/cjs/system/recalculateEmbeddingsWorkflow.js.map +0 -1
- package/lib/cjs/utils/auth.js +0 -15
- package/lib/cjs/utils/auth.js.map +0 -1
- package/lib/cjs/utils/blobs.js +0 -63
- package/lib/cjs/utils/blobs.js.map +0 -1
- package/lib/cjs/utils/client.js +0 -25
- package/lib/cjs/utils/client.js.map +0 -1
- package/lib/cjs/utils/expand-vars.js +0 -33
- package/lib/cjs/utils/expand-vars.js.map +0 -1
- package/lib/cjs/utils/memory.js +0 -72
- package/lib/cjs/utils/memory.js.map +0 -1
- package/lib/cjs/utils/tokens.js +0 -38
- package/lib/cjs/utils/tokens.js.map +0 -1
- package/lib/cjs/vars.js +0 -20
- package/lib/cjs/vars.js.map +0 -1
- package/lib/cjs/workflows.js +0 -15
- package/lib/cjs/workflows.js.map +0 -1
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js +0 -29
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js.map +0 -1
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +0 -63
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +0 -1
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js +0 -15
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js.map +0 -1
- package/lib/esm/activities/chunkDocument.js +0 -76
- package/lib/esm/activities/chunkDocument.js.map +0 -1
- package/lib/esm/activities/createDocumentFromOther.js +0 -58
- package/lib/esm/activities/createDocumentFromOther.js.map +0 -1
- package/lib/esm/activities/executeInteraction.js +0 -130
- package/lib/esm/activities/executeInteraction.js.map +0 -1
- package/lib/esm/activities/extractDocumentText.js +0 -132
- package/lib/esm/activities/extractDocumentText.js.map +0 -1
- package/lib/esm/activities/generateDocumentProperties.js +0 -56
- package/lib/esm/activities/generateDocumentProperties.js.map +0 -1
- package/lib/esm/activities/generateEmbeddings.js +0 -256
- package/lib/esm/activities/generateEmbeddings.js.map +0 -1
- package/lib/esm/activities/generateImageRendition.js +0 -98
- package/lib/esm/activities/generateImageRendition.js.map +0 -1
- package/lib/esm/activities/generateOrAssignContentType.js +0 -100
- package/lib/esm/activities/generateOrAssignContentType.js.map +0 -1
- package/lib/esm/activities/getObjectFromStore.js +0 -17
- package/lib/esm/activities/getObjectFromStore.js.map +0 -1
- package/lib/esm/activities/index-dsl.js +0 -18
- package/lib/esm/activities/index-dsl.js.map +0 -1
- package/lib/esm/activities/index.js +0 -6
- package/lib/esm/activities/index.js.map +0 -1
- package/lib/esm/activities/media/processPdfWithTextract.js +0 -98
- package/lib/esm/activities/media/processPdfWithTextract.js.map +0 -1
- package/lib/esm/activities/media/transcribeMediaWithGladia.js +0 -48
- package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +0 -1
- package/lib/esm/activities/notifyWebhook.js +0 -31
- package/lib/esm/activities/notifyWebhook.js.map +0 -1
- package/lib/esm/activities/setDocumentStatus.js +0 -12
- package/lib/esm/activities/setDocumentStatus.js.map +0 -1
- package/lib/esm/conversion/TextractProcessor.js +0 -410
- package/lib/esm/conversion/TextractProcessor.js.map +0 -1
- package/lib/esm/conversion/image.js +0 -16
- package/lib/esm/conversion/image.js.map +0 -1
- package/lib/esm/conversion/mutool.js +0 -139
- package/lib/esm/conversion/mutool.js.map +0 -1
- package/lib/esm/conversion/pandoc.js +0 -36
- package/lib/esm/conversion/pandoc.js.map +0 -1
- package/lib/esm/dsl/conditions.js +0 -75
- package/lib/esm/dsl/conditions.js.map +0 -1
- package/lib/esm/dsl/dsl-workflow.js +0 -216
- package/lib/esm/dsl/dsl-workflow.js.map +0 -1
- package/lib/esm/dsl/dslProxyActivities.js +0 -20
- package/lib/esm/dsl/dslProxyActivities.js.map +0 -1
- package/lib/esm/dsl/projections.js +0 -55
- package/lib/esm/dsl/projections.js.map +0 -1
- package/lib/esm/dsl/setup/ActivityContext.js +0 -91
- package/lib/esm/dsl/setup/ActivityContext.js.map +0 -1
- package/lib/esm/dsl/setup/fetch/DataProvider.js +0 -47
- package/lib/esm/dsl/setup/fetch/DataProvider.js.map +0 -1
- package/lib/esm/dsl/setup/fetch/index.js +0 -12
- package/lib/esm/dsl/setup/fetch/index.js.map +0 -1
- package/lib/esm/dsl/setup/fetch/providers.js +0 -61
- package/lib/esm/dsl/setup/fetch/providers.js.map +0 -1
- package/lib/esm/dsl/test/test-child-workflow.js +0 -5
- package/lib/esm/dsl/test/test-child-workflow.js.map +0 -1
- package/lib/esm/dsl/validation.js +0 -118
- package/lib/esm/dsl/validation.js.map +0 -1
- package/lib/esm/dsl/vars.js +0 -335
- package/lib/esm/dsl/vars.js.map +0 -1
- package/lib/esm/dsl/walk.js +0 -96
- package/lib/esm/dsl/walk.js.map +0 -1
- package/lib/esm/dsl.js +0 -4
- package/lib/esm/dsl.js.map +0 -1
- package/lib/esm/errors.js +0 -30
- package/lib/esm/errors.js.map +0 -1
- package/lib/esm/index.js +0 -32
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/iterative-generation/activities/extractToc.js +0 -44
- package/lib/esm/iterative-generation/activities/extractToc.js.map +0 -1
- package/lib/esm/iterative-generation/activities/finalizeOutput.js +0 -66
- package/lib/esm/iterative-generation/activities/finalizeOutput.js.map +0 -1
- package/lib/esm/iterative-generation/activities/generatePart.js +0 -70
- package/lib/esm/iterative-generation/activities/generatePart.js.map +0 -1
- package/lib/esm/iterative-generation/activities/generateToc.js +0 -88
- package/lib/esm/iterative-generation/activities/generateToc.js.map +0 -1
- package/lib/esm/iterative-generation/activities/index.js +0 -5
- package/lib/esm/iterative-generation/activities/index.js.map +0 -1
- package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js +0 -52
- package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js.map +0 -1
- package/lib/esm/iterative-generation/types.js +0 -2
- package/lib/esm/iterative-generation/types.js.map +0 -1
- package/lib/esm/iterative-generation/utils.js +0 -112
- package/lib/esm/iterative-generation/utils.js.map +0 -1
- package/lib/esm/result-types.js +0 -7
- package/lib/esm/result-types.js.map +0 -1
- package/lib/esm/system/notifyWebhookWorkflow.js +0 -43
- package/lib/esm/system/notifyWebhookWorkflow.js.map +0 -1
- package/lib/esm/system/recalculateEmbeddingsWorkflow.js +0 -25
- package/lib/esm/system/recalculateEmbeddingsWorkflow.js.map +0 -1
- package/lib/esm/utils/auth.js +0 -8
- package/lib/esm/utils/auth.js.map +0 -1
- package/lib/esm/utils/blobs.js +0 -52
- package/lib/esm/utils/blobs.js.map +0 -1
- package/lib/esm/utils/client.js +0 -22
- package/lib/esm/utils/client.js.map +0 -1
- package/lib/esm/utils/expand-vars.js +0 -30
- package/lib/esm/utils/expand-vars.js.map +0 -1
- package/lib/esm/utils/memory.js +0 -60
- package/lib/esm/utils/memory.js.map +0 -1
- package/lib/esm/utils/tokens.js +0 -34
- package/lib/esm/utils/tokens.js.map +0 -1
- package/lib/esm/vars.js +0 -4
- package/lib/esm/vars.js.map +0 -1
- package/lib/esm/workflows.js +0 -8
- package/lib/esm/workflows.js.map +0 -1
- package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts +0 -17
- package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts.map +0 -1
- package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts +0 -29
- package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts.map +0 -1
- package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts +0 -19
- package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts.map +0 -1
- package/lib/types/activities/chunkDocument.d.ts +0 -18
- package/lib/types/activities/chunkDocument.d.ts.map +0 -1
- package/lib/types/activities/createDocumentFromOther.d.ts +0 -21
- package/lib/types/activities/createDocumentFromOther.d.ts.map +0 -1
- package/lib/types/activities/executeInteraction.d.ts +0 -44
- package/lib/types/activities/executeInteraction.d.ts.map +0 -1
- package/lib/types/activities/extractDocumentText.d.ts +0 -10
- package/lib/types/activities/extractDocumentText.d.ts.map +0 -1
- package/lib/types/activities/generateDocumentProperties.d.ts +0 -32
- package/lib/types/activities/generateDocumentProperties.d.ts.map +0 -1
- package/lib/types/activities/generateEmbeddings.d.ts +0 -49
- package/lib/types/activities/generateEmbeddings.d.ts.map +0 -1
- package/lib/types/activities/generateImageRendition.d.ts +0 -17
- package/lib/types/activities/generateImageRendition.d.ts.map +0 -1
- package/lib/types/activities/generateOrAssignContentType.d.ts +0 -44
- package/lib/types/activities/generateOrAssignContentType.d.ts.map +0 -1
- package/lib/types/activities/getObjectFromStore.d.ts +0 -14
- package/lib/types/activities/getObjectFromStore.d.ts.map +0 -1
- package/lib/types/activities/index-dsl.d.ts +0 -17
- package/lib/types/activities/index-dsl.d.ts.map +0 -1
- package/lib/types/activities/index.d.ts +0 -6
- package/lib/types/activities/index.d.ts.map +0 -1
- package/lib/types/activities/media/processPdfWithTextract.d.ts +0 -26
- package/lib/types/activities/media/processPdfWithTextract.d.ts.map +0 -1
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts +0 -14
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +0 -1
- package/lib/types/activities/notifyWebhook.d.ts +0 -17
- package/lib/types/activities/notifyWebhook.d.ts.map +0 -1
- package/lib/types/activities/setDocumentStatus.d.ts +0 -15
- package/lib/types/activities/setDocumentStatus.d.ts.map +0 -1
- package/lib/types/conversion/TextractProcessor.d.ts +0 -45
- package/lib/types/conversion/TextractProcessor.d.ts.map +0 -1
- package/lib/types/conversion/image.d.ts +0 -9
- package/lib/types/conversion/image.d.ts.map +0 -1
- package/lib/types/conversion/mutool.d.ts +0 -19
- package/lib/types/conversion/mutool.d.ts.map +0 -1
- package/lib/types/conversion/pandoc.d.ts +0 -2
- package/lib/types/conversion/pandoc.d.ts.map +0 -1
- package/lib/types/dsl/conditions.d.ts +0 -2
- package/lib/types/dsl/conditions.d.ts.map +0 -1
- package/lib/types/dsl/dsl-workflow.d.ts +0 -5
- package/lib/types/dsl/dsl-workflow.d.ts.map +0 -1
- package/lib/types/dsl/dslProxyActivities.d.ts +0 -10
- package/lib/types/dsl/dslProxyActivities.d.ts.map +0 -1
- package/lib/types/dsl/projections.d.ts +0 -4
- package/lib/types/dsl/projections.d.ts.map +0 -1
- package/lib/types/dsl/setup/ActivityContext.d.ts +0 -14
- package/lib/types/dsl/setup/ActivityContext.d.ts.map +0 -1
- package/lib/types/dsl/setup/fetch/DataProvider.d.ts +0 -9
- package/lib/types/dsl/setup/fetch/DataProvider.d.ts.map +0 -1
- package/lib/types/dsl/setup/fetch/index.d.ts +0 -6
- package/lib/types/dsl/setup/fetch/index.d.ts.map +0 -1
- package/lib/types/dsl/setup/fetch/providers.d.ts +0 -25
- package/lib/types/dsl/setup/fetch/providers.d.ts.map +0 -1
- package/lib/types/dsl/test/test-child-workflow.d.ts +0 -4
- package/lib/types/dsl/test/test-child-workflow.d.ts.map +0 -1
- package/lib/types/dsl/validation.d.ts +0 -4
- package/lib/types/dsl/validation.d.ts.map +0 -1
- package/lib/types/dsl/vars.d.ts +0 -48
- package/lib/types/dsl/vars.d.ts.map +0 -1
- package/lib/types/dsl/walk.d.ts +0 -18
- package/lib/types/dsl/walk.d.ts.map +0 -1
- package/lib/types/dsl.d.ts +0 -4
- package/lib/types/dsl.d.ts.map +0 -1
- package/lib/types/errors.d.ts +0 -16
- package/lib/types/errors.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -31
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/iterative-generation/activities/extractToc.d.ts +0 -10
- package/lib/types/iterative-generation/activities/extractToc.d.ts.map +0 -1
- package/lib/types/iterative-generation/activities/finalizeOutput.d.ts +0 -3
- package/lib/types/iterative-generation/activities/finalizeOutput.d.ts.map +0 -1
- package/lib/types/iterative-generation/activities/generatePart.d.ts +0 -3
- package/lib/types/iterative-generation/activities/generatePart.d.ts.map +0 -1
- package/lib/types/iterative-generation/activities/generateToc.d.ts +0 -4
- package/lib/types/iterative-generation/activities/generateToc.d.ts.map +0 -1
- package/lib/types/iterative-generation/activities/index.d.ts +0 -5
- package/lib/types/iterative-generation/activities/index.d.ts.map +0 -1
- package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts +0 -3
- package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts.map +0 -1
- package/lib/types/iterative-generation/types.d.ts +0 -79
- package/lib/types/iterative-generation/types.d.ts.map +0 -1
- package/lib/types/iterative-generation/utils.d.ts +0 -27
- package/lib/types/iterative-generation/utils.d.ts.map +0 -1
- package/lib/types/result-types.d.ts +0 -22
- package/lib/types/result-types.d.ts.map +0 -1
- package/lib/types/system/notifyWebhookWorkflow.d.ts +0 -3
- package/lib/types/system/notifyWebhookWorkflow.d.ts.map +0 -1
- package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts +0 -40
- package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts.map +0 -1
- package/lib/types/utils/auth.d.ts +0 -4
- package/lib/types/utils/auth.d.ts.map +0 -1
- package/lib/types/utils/blobs.d.ts +0 -8
- package/lib/types/utils/blobs.d.ts.map +0 -1
- package/lib/types/utils/client.d.ts +0 -7
- package/lib/types/utils/client.d.ts.map +0 -1
- package/lib/types/utils/expand-vars.d.ts +0 -8
- package/lib/types/utils/expand-vars.d.ts.map +0 -1
- package/lib/types/utils/memory.d.ts +0 -12
- package/lib/types/utils/memory.d.ts.map +0 -1
- package/lib/types/utils/tokens.d.ts +0 -11
- package/lib/types/utils/tokens.d.ts.map +0 -1
- package/lib/types/vars.d.ts +0 -3
- package/lib/types/vars.d.ts.map +0 -1
- package/lib/types/workflows.d.ts +0 -8
- package/lib/types/workflows.d.ts.map +0 -1
- package/lib/workflows-bundle.js +0 -19897
@@ -1,26 +1,118 @@
|
|
1
|
-
import fs from
|
2
|
-
import path from
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
import {
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
import { exec } from "child_process";
|
4
|
+
import { promisify } from "util";
|
5
|
+
import { expect, test, vi, describe } from "vitest";
|
6
6
|
|
7
|
+
// Mock Temporal activity context
|
8
|
+
vi.mock("@temporalio/activity", () => ({
|
9
|
+
log: {
|
10
|
+
info: vi.fn(),
|
11
|
+
warn: vi.fn(),
|
12
|
+
error: vi.fn(),
|
13
|
+
},
|
14
|
+
}));
|
7
15
|
|
8
|
-
|
9
|
-
|
10
|
-
const format: keyof sharp.FormatEnum = 'jpeg';
|
11
|
-
const imageFile = fs.readFileSync(path.join(__dirname, '../../fixtures', 'cat-picture.jpg'));
|
16
|
+
// Import after mocking
|
17
|
+
import { imageResizer } from "../conversion/image";
|
12
18
|
|
13
|
-
|
19
|
+
const execAsync = promisify(exec);
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
describe("ImageMagick image resizing", () => {
|
22
|
+
test("should resize an image to a maximum height or width using ImageMagick", async () => {
|
23
|
+
const max_hw = 1024;
|
24
|
+
const format = "jpeg";
|
25
|
+
const inputImagePath = path.join(__dirname, "../../fixtures", "cat-picture.jpg");
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
// Make sure the input file exists
|
28
|
+
expect(fs.existsSync(inputImagePath)).toBe(true);
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
expect(metadata.format).to.equal(format);
|
30
|
+
// Call the imageResizer function with a file path
|
31
|
+
const resizedImagePath = await imageResizer(inputImagePath, max_hw, format);
|
25
32
|
|
33
|
+
// Make sure the output file exists
|
34
|
+
expect(fs.existsSync(resizedImagePath)).toBe(true);
|
35
|
+
|
36
|
+
// Use ImageMagick identify to get metadata about the resized image
|
37
|
+
const { stdout } = await execAsync(`identify -format "%w %h %m" "${resizedImagePath}"`);
|
38
|
+
const [width, height, imageFormat] = stdout.trim().split(" ");
|
39
|
+
|
40
|
+
console.log({ width, height, imageFormat });
|
41
|
+
|
42
|
+
// Check dimensions
|
43
|
+
expect(parseInt(width)).to.be.lessThanOrEqual(max_hw);
|
44
|
+
expect(parseInt(height)).to.be.lessThanOrEqual(max_hw);
|
45
|
+
|
46
|
+
// Check format (JPEG)
|
47
|
+
expect(imageFormat.toLowerCase()).to.equal("jpeg");
|
48
|
+
});
|
49
|
+
|
50
|
+
test("should throw an error for non-existent input file", async () => {
|
51
|
+
const max_hw = 1024;
|
52
|
+
const format = "jpeg";
|
53
|
+
const nonExistentPath = path.join(__dirname, "non-existent-image.jpg");
|
54
|
+
|
55
|
+
// Verify file doesn't exist
|
56
|
+
expect(fs.existsSync(nonExistentPath)).toBe(false);
|
57
|
+
|
58
|
+
// Expect the function to throw an error
|
59
|
+
await expect(imageResizer(nonExistentPath, max_hw, format)).rejects.toThrow("Input file does not exist");
|
60
|
+
});
|
61
|
+
|
62
|
+
test("should throw error with empty format", async () => {
|
63
|
+
const max_hw = 1024;
|
64
|
+
const format = "";
|
65
|
+
const inputImagePath = path.join(__dirname, "../../fixtures", "cat-picture.jpg");
|
66
|
+
|
67
|
+
// Test for empty format validation
|
68
|
+
await expect(imageResizer(inputImagePath, max_hw, format)).rejects.toThrow("Invalid format");
|
69
|
+
});
|
70
|
+
|
71
|
+
test("should create progressive/interlaced image when enabled", async () => {
|
72
|
+
const max_hw = 800;
|
73
|
+
const format = "jpeg";
|
74
|
+
const inputImagePath = path.join(__dirname, "../../fixtures", "cat-picture.jpg");
|
75
|
+
|
76
|
+
// Make sure the input file exists
|
77
|
+
expect(fs.existsSync(inputImagePath)).toBe(true);
|
78
|
+
|
79
|
+
// Call the imageResizer function with progressive=true
|
80
|
+
const resizedImagePath = await imageResizer(inputImagePath, max_hw, format, true);
|
81
|
+
|
82
|
+
// Make sure the output file exists
|
83
|
+
expect(fs.existsSync(resizedImagePath)).toBe(true);
|
84
|
+
|
85
|
+
// Use ImageMagick identify to check if the image is interlaced
|
86
|
+
const { stdout } = await execAsync(`identify -format "%[interlace]" "${resizedImagePath}"`);
|
87
|
+
const interlaceMode = stdout.trim();
|
88
|
+
|
89
|
+
console.log({ interlaceMode });
|
90
|
+
|
91
|
+
// Check that interlace is enabled (should be 'JPEG' or 'Line' for progressive JPEG)
|
92
|
+
expect(["JPEG", "Line", "Plane"]).to.include(interlaceMode);
|
93
|
+
});
|
94
|
+
|
95
|
+
test("should create non-interlaced image when progressive is disabled", async () => {
|
96
|
+
const max_hw = 800;
|
97
|
+
const format = "jpeg";
|
98
|
+
const inputImagePath = path.join(__dirname, "../../fixtures", "cat-picture.jpg");
|
99
|
+
|
100
|
+
// Make sure the input file exists
|
101
|
+
expect(fs.existsSync(inputImagePath)).toBe(true);
|
102
|
+
|
103
|
+
// Call the imageResizer function with progressive=false
|
104
|
+
const resizedImagePath = await imageResizer(inputImagePath, max_hw, format, false);
|
105
|
+
|
106
|
+
// Make sure the output file exists
|
107
|
+
expect(fs.existsSync(resizedImagePath)).toBe(true);
|
108
|
+
|
109
|
+
// Use ImageMagick identify to check if the image is interlaced
|
110
|
+
const { stdout } = await execAsync(`identify -format "%[interlace]" "${resizedImagePath}"`);
|
111
|
+
const interlaceMode = stdout.trim().toLowerCase();
|
112
|
+
|
113
|
+
console.log({ interlaceMode });
|
114
|
+
|
115
|
+
// Check that interlace is disabled (should be 'none' or empty string)
|
116
|
+
expect(["none", ""]).to.include(interlaceMode);
|
117
|
+
});
|
26
118
|
});
|
package/src/conversion/image.ts
CHANGED
@@ -1,22 +1,103 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
|
1
|
+
import { log } from "@temporalio/activity";
|
2
|
+
import { execFile as execFileCallback } from "child_process";
|
3
|
+
import fs from "fs";
|
4
|
+
import { file } from "tmp-promise";
|
5
|
+
import { promisify } from "util";
|
6
|
+
const execFile = promisify(execFileCallback);
|
4
7
|
|
5
8
|
/**
|
6
|
-
* Resizes an image to a maximum height or width
|
7
|
-
*
|
8
|
-
* @param
|
9
|
-
* @
|
9
|
+
* Resizes an image to a maximum height or width using ImageMagick
|
10
|
+
* with progressive loading when supported
|
11
|
+
* @param inputPath Input file path
|
12
|
+
* @param max_hw Maximum height or width
|
13
|
+
* @param format Output format
|
14
|
+
* @param progressive Enable progressive loading for supported formats (defaults to true)
|
15
|
+
* @returns Path to the resized image
|
10
16
|
*/
|
11
|
-
export function imageResizer(
|
17
|
+
export async function imageResizer(
|
18
|
+
inputPath: string,
|
19
|
+
max_hw: number,
|
20
|
+
format: string,
|
21
|
+
progressive: boolean = true,
|
22
|
+
): Promise<string> {
|
23
|
+
log.info(`[image-resizer] Resizing image: ${inputPath} to max_hw: ${max_hw}, format: ${format}, progressive: ${progressive}`);
|
12
24
|
|
13
|
-
|
14
|
-
width: max_hw,
|
15
|
-
height: max_hw,
|
16
|
-
fit: sharp.fit.inside,
|
17
|
-
withoutEnlargement: true,
|
25
|
+
const allowedFormats = ["jpg", "jpeg", "png", "webp"];
|
18
26
|
|
19
|
-
|
27
|
+
if (!format || format.trim() === "") {
|
28
|
+
throw new Error(`Invalid format: ${format}.Supported : ${allowedFormats.join(", ")}`);
|
29
|
+
}
|
20
30
|
|
21
|
-
|
31
|
+
//check that max_hw is valid
|
32
|
+
if (!Number.isInteger(max_hw) || max_hw <= 0) {
|
33
|
+
throw new Error(`Invalid max_hw value: ${max_hw}`);
|
34
|
+
}
|
35
|
+
|
36
|
+
//check that inputPath exists
|
37
|
+
if (!fs.existsSync(inputPath)) {
|
38
|
+
throw new Error(`Input file does not exist: ${inputPath}`);
|
39
|
+
}
|
40
|
+
|
41
|
+
// Create a temporary file
|
42
|
+
const { path: outputPath, cleanup } = await file({ postfix: `.${format}` });
|
43
|
+
try {
|
44
|
+
// Check if input file exists
|
45
|
+
if (!fs.existsSync(inputPath)) {
|
46
|
+
throw new Error(`Input file does not exist: ${inputPath}`);
|
47
|
+
}
|
48
|
+
// Validate max_hw
|
49
|
+
if (!Number.isInteger(max_hw) || max_hw <= 0) {
|
50
|
+
throw new Error(`Invalid max_hw value: ${max_hw}`);
|
51
|
+
}
|
52
|
+
|
53
|
+
// Progressive loading options
|
54
|
+
let conversionOption = "";
|
55
|
+
|
56
|
+
// Only add progressive option for formats that support it
|
57
|
+
if (progressive) {
|
58
|
+
// JPEG and some other formats support progressive loading
|
59
|
+
const lowerFormat = format.toLowerCase();
|
60
|
+
if (lowerFormat === "jpg" || lowerFormat === "jpeg") {
|
61
|
+
conversionOption = "-interlace JPEG";
|
62
|
+
log.info(`Enabling interlaced ${lowerFormat.toUpperCase()} format`);
|
63
|
+
} else if (lowerFormat === "png") {
|
64
|
+
conversionOption = "-interlace PNG";
|
65
|
+
log.info(`Enabling interlaced ${lowerFormat.toUpperCase()} format`);
|
66
|
+
} else if (lowerFormat === "gif") {
|
67
|
+
conversionOption = "-interlace GIF";
|
68
|
+
log.info(`Enabling interlaced ${lowerFormat.toUpperCase()} format`);
|
69
|
+
}
|
70
|
+
}
|
22
71
|
|
72
|
+
log.info(`Resizing image using ImageMagick: ${inputPath} -> ${outputPath}`);
|
73
|
+
|
74
|
+
const command = `convert`
|
75
|
+
const args = [
|
76
|
+
inputPath,
|
77
|
+
"-resize",
|
78
|
+
`${max_hw}x${max_hw}>`,
|
79
|
+
...(conversionOption ? conversionOption.split(" ") : []),
|
80
|
+
outputPath,
|
81
|
+
];
|
82
|
+
log.info(`ImageMagick command: ${command} ${args.join(" ")}`);
|
83
|
+
|
84
|
+
const { stderr } = await execFile(command, args);
|
85
|
+
|
86
|
+
if (stderr) {
|
87
|
+
log.warn(`ImageMagick warning: ${stderr}`);
|
88
|
+
}
|
89
|
+
|
90
|
+
// Verify output exists and has content
|
91
|
+
if (!fs.existsSync(outputPath) || fs.statSync(outputPath).size === 0) {
|
92
|
+
throw new Error(`ImageMagick conversion failed: output file not created or empty`);
|
93
|
+
}
|
94
|
+
|
95
|
+
return outputPath;
|
96
|
+
} catch (error) {
|
97
|
+
// Clean up the temporary file
|
98
|
+
await cleanup();
|
99
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
100
|
+
log.error(`Image conversion failed: ${errorMessage}`);
|
101
|
+
throw new Error(`Image conversion failed: ${errorMessage}`);
|
102
|
+
}
|
103
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { log } from "@temporalio/activity";
|
2
|
+
import { spawn } from "child_process";
|
3
|
+
import fs from "fs";
|
4
|
+
import tmp from "tmp";
|
5
|
+
|
6
|
+
export function markdownWithMarkitdown(buffer: Buffer, ext?: string): Promise<string> {
|
7
|
+
const inputFile = tmp.fileSync({ postfix: ext });
|
8
|
+
const targetFileName = tmp.tmpNameSync({ postfix: ".md" });
|
9
|
+
|
10
|
+
fs.writeSync(inputFile.fd, buffer);
|
11
|
+
|
12
|
+
return new Promise((resolve, reject) => {
|
13
|
+
const tool = "markitdown";
|
14
|
+
log.info(`Converting document to markdown with ${tool}`, { inputFile: inputFile.name, targetFileName });
|
15
|
+
|
16
|
+
const command = spawn(tool, [inputFile.name, "-o", targetFileName]);
|
17
|
+
|
18
|
+
command.on("exit", function (code) {
|
19
|
+
if (code) {
|
20
|
+
reject(new Error(`${tool} exited with code ${code}`));
|
21
|
+
}
|
22
|
+
});
|
23
|
+
|
24
|
+
command.on("close", function (code) {
|
25
|
+
if (code) {
|
26
|
+
reject(new Error(`${tool} exited with code ${code}`));
|
27
|
+
} else {
|
28
|
+
return fs.readFile(targetFileName, "utf8", (err, data) => {
|
29
|
+
if (err) {
|
30
|
+
reject(err);
|
31
|
+
}
|
32
|
+
return resolve(data);
|
33
|
+
});
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
37
|
+
command.on("error", (err) => {
|
38
|
+
reject(err);
|
39
|
+
});
|
40
|
+
});
|
41
|
+
}
|
package/src/conversion/mutool.ts
CHANGED
@@ -120,7 +120,7 @@ export async function pdfToImages(file: Buffer | string, pages?: number[]): Prom
|
|
120
120
|
|
121
121
|
|
122
122
|
/**
|
123
|
-
* Get
|
123
|
+
* Get some pages from a PDF to create a new one
|
124
124
|
*/
|
125
125
|
|
126
126
|
export async function pdfExtractPages(file: Buffer | string, pages: number[]): Promise<string> {
|
@@ -2,21 +2,23 @@ import { MockActivityEnvironment, TestWorkflowEnvironment } from '@temporalio/te
|
|
2
2
|
import fs from 'fs';
|
3
3
|
import path from 'path';
|
4
4
|
import { beforeAll, expect, test } from 'vitest';
|
5
|
-
import {
|
5
|
+
import { markdownWithPandoc } from '../conversion/pandoc';
|
6
6
|
|
7
7
|
|
8
8
|
let testEnv: TestWorkflowEnvironment;
|
9
9
|
let activityContext: MockActivityEnvironment;
|
10
10
|
|
11
11
|
beforeAll(async () => {
|
12
|
-
|
13
|
-
|
12
|
+
testEnv = await TestWorkflowEnvironment.createLocal();
|
13
|
+
activityContext = new MockActivityEnvironment();
|
14
14
|
});
|
15
15
|
|
16
16
|
|
17
17
|
// Add more test cases for other file types (ODT, DOCX) if needed
|
18
18
|
test('should convert docx to markdown', async () => {
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
const filepath = path.join(__dirname, '../../fixtures', 'us-ciia.docx');
|
20
|
+
console.log("Converting file from", filepath);
|
21
|
+
const docx = fs.readFileSync(filepath);
|
22
|
+
const result = await activityContext.run(markdownWithPandoc, Buffer.from(docx), 'docx');
|
23
|
+
expect(result).to.include('confidential');
|
22
24
|
});
|
package/src/conversion/pandoc.ts
CHANGED
@@ -1,44 +1,40 @@
|
|
1
|
-
import { log } from
|
2
|
-
import { spawn } from
|
3
|
-
import { PassThrough } from
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
import { log } from "@temporalio/activity";
|
2
|
+
import { spawn } from "child_process";
|
3
|
+
import { PassThrough } from "stream";
|
4
|
+
|
5
|
+
export function markdownWithPandoc(buffer: Buffer, fromFormat: string): Promise<string> {
|
6
|
+
const fromType = undefined;
|
7
|
+
|
8
|
+
return new Promise((resolve, reject) => {
|
9
|
+
log.info(`Converting ${fromType} to markdown`);
|
10
|
+
const input = new PassThrough();
|
11
|
+
input.end(buffer);
|
12
|
+
|
13
|
+
let result: string[] = [];
|
14
|
+
|
15
|
+
const command = spawn("pandoc", ["-t", "markdown", "-f", fromFormat], {
|
16
|
+
stdio: "pipe",
|
17
|
+
});
|
18
|
+
input.pipe(command.stdin);
|
19
|
+
|
20
|
+
command.stdout.on("data", function (data: string) {
|
21
|
+
result.push(data.toString());
|
22
|
+
});
|
23
|
+
command.on("exit", function (code) {
|
24
|
+
if (code) {
|
25
|
+
reject(new Error(`pandoc exited with code ${code}`));
|
26
|
+
}
|
27
|
+
});
|
28
|
+
command.on("close", function (code) {
|
29
|
+
if (code) {
|
30
|
+
reject(new Error(`pandoc exited with code ${code}`));
|
31
|
+
} else {
|
32
|
+
resolve(result.join(""));
|
33
|
+
}
|
34
|
+
});
|
35
|
+
|
36
|
+
command.on("error", (err) => {
|
37
|
+
reject(err);
|
38
|
+
});
|
29
39
|
});
|
30
|
-
command.on('close', function (code) {
|
31
|
-
if (code) {
|
32
|
-
reject(new Error(`pandoc exited with code ${code}`));
|
33
|
-
} else {
|
34
|
-
resolve(result.join(''))
|
35
|
-
}
|
36
|
-
});
|
37
|
-
|
38
|
-
command.on('error', (err) => {
|
39
|
-
reject(err);
|
40
|
-
});
|
41
|
-
|
42
|
-
});
|
43
|
-
|
44
40
|
}
|
package/src/dsl/dsl-workflow.ts
CHANGED
@@ -1,15 +1,30 @@
|
|
1
|
+
import {
|
2
|
+
ActivityInterfaceFor,
|
3
|
+
ActivityOptions,
|
4
|
+
CancellationScope,
|
5
|
+
executeChild,
|
6
|
+
isCancellation,
|
7
|
+
log,
|
8
|
+
patched,
|
9
|
+
proxyActivities,
|
10
|
+
startChild,
|
11
|
+
UntypedActivities,
|
12
|
+
} from "@temporalio/workflow";
|
1
13
|
import {
|
2
14
|
DSLActivityExecutionPayload,
|
3
15
|
DSLActivityOptions,
|
4
16
|
DSLActivitySpec,
|
5
17
|
DSLChildWorkflowStep,
|
6
18
|
DSLWorkflowExecutionPayload,
|
19
|
+
DSLWorkflowSpec,
|
20
|
+
getDocumentIds,
|
7
21
|
WorkflowExecutionPayload
|
8
22
|
} from "@vertesia/common";
|
9
|
-
import { ActivityInterfaceFor, ActivityOptions, executeChild, log, proxyActivities, startChild, UntypedActivities } from "@temporalio/workflow";
|
10
23
|
import ms, { StringValue } from 'ms';
|
11
24
|
import { ActivityParamNotFound, NoDocumentFound, WorkflowParamNotFound } from "../errors.js";
|
12
25
|
import { Vars } from "./vars.js";
|
26
|
+
import { HandleDslErrorParams } from "../activities/handleError.js";
|
27
|
+
import * as activities from "../activities/index.js";
|
13
28
|
|
14
29
|
interface BaseActivityPayload extends WorkflowExecutionPayload {
|
15
30
|
workflow_name: string;
|
@@ -30,7 +45,7 @@ export async function dslWorkflow(payload: DSLWorkflowExecutionPayload) {
|
|
30
45
|
if (!definition) {
|
31
46
|
throw new WorkflowParamNotFound("workflow");
|
32
47
|
}
|
33
|
-
// the base payload
|
48
|
+
// the base payload will be used to create the activities payload
|
34
49
|
const basePayload: BaseActivityPayload = {
|
35
50
|
...payload,
|
36
51
|
workflow_name: definition.name,
|
@@ -42,9 +57,9 @@ export async function dslWorkflow(payload: DSLWorkflowExecutionPayload) {
|
|
42
57
|
...convertDSLActivityOptions(definition.options),
|
43
58
|
startToCloseTimeout: "5 minute",
|
44
59
|
retry: {
|
45
|
-
initialInterval: '
|
60
|
+
initialInterval: '10s',
|
46
61
|
backoffCoefficient: 2,
|
47
|
-
maximumAttempts:
|
62
|
+
maximumAttempts: 10,
|
48
63
|
maximumInterval: 100 * 30 * 1000, //ms
|
49
64
|
nonRetryableErrorTypes: [
|
50
65
|
NoDocumentFound.name,
|
@@ -58,7 +73,7 @@ export async function dslWorkflow(payload: DSLWorkflowExecutionPayload) {
|
|
58
73
|
});
|
59
74
|
const defaultProxy = proxyActivities(defaultOptions);
|
60
75
|
log.debug("Default activity proxy is ready");
|
61
|
-
// merge default vars with the payload vars and add objectIds and
|
76
|
+
// merge default vars with the payload vars and add objectIds and objectId
|
62
77
|
const vars = new Vars({
|
63
78
|
...definition.vars,
|
64
79
|
...payload.vars,
|
@@ -68,6 +83,26 @@ export async function dslWorkflow(payload: DSLWorkflowExecutionPayload) {
|
|
68
83
|
|
69
84
|
log.info("Executing workflow", { payload });
|
70
85
|
|
86
|
+
// TODO(mhuang): remove patch when all workflows are migrated to v2
|
87
|
+
// It avoids breaking the ongoing workflow execution running in v1 and also allows us to
|
88
|
+
// deploy the new error handler in production.
|
89
|
+
// See https://docs.temporal.io/develop/typescript/versioning
|
90
|
+
if (patched('dsl-workflow-error-handling')) {
|
91
|
+
// v2: new version with error handler
|
92
|
+
try {
|
93
|
+
await executeSteps(definition, payload, basePayload, vars, defaultProxy, defaultOptions);
|
94
|
+
} catch (e) {
|
95
|
+
await handleError(e, basePayload, defaultOptions);
|
96
|
+
}
|
97
|
+
} else {
|
98
|
+
// v1: old version without error handler, deprecated since v0.52.0
|
99
|
+
await executeSteps(definition, payload, basePayload, vars, defaultProxy, defaultOptions);
|
100
|
+
}
|
101
|
+
|
102
|
+
return vars.getValue(definition.result || 'result');
|
103
|
+
}
|
104
|
+
|
105
|
+
async function executeSteps(definition: DSLWorkflowSpec, payload: DSLWorkflowExecutionPayload, basePayload: BaseActivityPayload, vars: Vars, defaultProxy: ActivityInterfaceFor<UntypedActivities>, defaultOptions: ActivityOptions) {
|
71
106
|
if (definition.steps) {
|
72
107
|
for (const step of definition.steps) {
|
73
108
|
const stepType = step.type;
|
@@ -89,7 +124,32 @@ export async function dslWorkflow(payload: DSLWorkflowExecutionPayload) {
|
|
89
124
|
} else {
|
90
125
|
throw new Error("No steps or activities found in the workflow definition");
|
91
126
|
}
|
92
|
-
|
127
|
+
}
|
128
|
+
|
129
|
+
async function handleError(originalError: any, basePayload: BaseActivityPayload, defaultOptions: ActivityOptions) {
|
130
|
+
const { handleDslError } = proxyActivities<typeof activities>(defaultOptions);
|
131
|
+
|
132
|
+
const payload = dslActivityPayload(
|
133
|
+
basePayload,
|
134
|
+
{
|
135
|
+
name: "handleDslError",
|
136
|
+
params: { errorMessage: originalError.message },
|
137
|
+
} as DSLActivitySpec,
|
138
|
+
{ errorMessage: originalError.message } satisfies HandleDslErrorParams,
|
139
|
+
)
|
140
|
+
|
141
|
+
if (isCancellation(originalError)) {
|
142
|
+
log.warn(`Workflow execution cancelled, executing error handler to update document status`, { error: originalError });
|
143
|
+
// Cleanup logic must be in a nonCancellable scope
|
144
|
+
// If we'd run cleanup outside of a nonCancellable scope it would've been cancelled
|
145
|
+
// before being started because the Workflow's root scope is cancelled.
|
146
|
+
// see https://docs.temporal.io/develop/typescript/cancellation
|
147
|
+
await CancellationScope.nonCancellable(() => handleDslError(payload));
|
148
|
+
} else {
|
149
|
+
log.warn(`Workflow execution failed, executing error handler to update document status`, { error: originalError });
|
150
|
+
handleDslError(payload);
|
151
|
+
}
|
152
|
+
throw originalError;
|
93
153
|
}
|
94
154
|
|
95
155
|
async function startChildWorkflow(step: DSLChildWorkflowStep, payload: DSLWorkflowExecutionPayload, vars: Vars, debug_mode?: boolean) {
|
@@ -101,14 +161,18 @@ async function startChildWorkflow(step: DSLChildWorkflowStep, payload: DSLWorkfl
|
|
101
161
|
if (debug_mode) {
|
102
162
|
log.debug(`Workflow vars before starting child workflow ${step.name}`, { vars: resolvedVars });
|
103
163
|
}
|
104
|
-
//@ts-ignore
|
105
164
|
const handle = await startChild(step.name, {
|
106
165
|
...step.options,
|
107
166
|
args: [{
|
108
167
|
...payload,
|
109
168
|
workflow: step.spec,
|
110
169
|
vars: resolvedVars
|
111
|
-
}]
|
170
|
+
}],
|
171
|
+
searchAttributes: {
|
172
|
+
AccountId: [payload.account_id],
|
173
|
+
DocumentId: getDocumentIds(payload),
|
174
|
+
ProjectId: [payload.project_id],
|
175
|
+
},
|
112
176
|
});
|
113
177
|
if (step.output) {
|
114
178
|
vars.setValue(step.output, handle.workflowId);
|
@@ -122,16 +186,20 @@ async function executeChildWorkflow(step: DSLChildWorkflowStep, payload: DSLWork
|
|
122
186
|
Object.assign(resolvedVars, step.vars);
|
123
187
|
}
|
124
188
|
if (debug_mode) {
|
125
|
-
log.debug(`Workflow vars before
|
189
|
+
log.debug(`Workflow vars before executing child workflow ${step.name}`, { vars: resolvedVars });
|
126
190
|
}
|
127
|
-
//@ts-ignore
|
128
191
|
const result = await executeChild(step.name, {
|
129
192
|
...step.options,
|
130
193
|
args: [{
|
131
194
|
...payload,
|
132
195
|
workflow: step.spec,
|
133
196
|
vars: resolvedVars,
|
134
|
-
}]
|
197
|
+
}],
|
198
|
+
searchAttributes: {
|
199
|
+
AccountId: [payload.account_id],
|
200
|
+
DocumentId: getDocumentIds(payload),
|
201
|
+
ProjectId: [payload.project_id],
|
202
|
+
},
|
135
203
|
});
|
136
204
|
|
137
205
|
if (step.output) {
|
@@ -149,7 +217,7 @@ async function runActivity(activity: DSLActivitySpec, basePayload: BaseActivityP
|
|
149
217
|
log.debug(`Workflow vars before executing activity ${activity.name}`, { vars: vars.resolve() });
|
150
218
|
}
|
151
219
|
if (activity.condition && !vars.match(activity.condition)) {
|
152
|
-
log.info("Activity
|
220
|
+
log.info("Activity skipped: condition not satisfied", activity.condition);
|
153
221
|
return;
|
154
222
|
}
|
155
223
|
const importParams = vars.createImportVars(activity.import);
|