@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,6 +1,11 @@
|
|
1
|
-
import { log } from "@temporalio/activity";
|
1
|
+
import { log, activityInfo } from "@temporalio/activity";
|
2
2
|
import { VertesiaClient } from "@vertesia/client";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
DSLActivityExecutionPayload,
|
5
|
+
DSLWorkflowExecutionPayload,
|
6
|
+
Project,
|
7
|
+
WorkflowExecutionPayload,
|
8
|
+
} from "@vertesia/common";
|
4
9
|
import { NoDocumentFound, WorkflowParamNotFound } from "../../errors.js";
|
5
10
|
import { getProjectFromToken } from "../../utils/auth.js";
|
6
11
|
import { getVertesiaClient } from "../../utils/client.js";
|
@@ -8,7 +13,6 @@ import { Vars } from "../vars.js";
|
|
8
13
|
import { getFetchProvider, registerFetchProviderFactory } from "./fetch/index.js";
|
9
14
|
import { DocumentProvider, DocumentTypeProvider, InteractionRunProvider } from "./fetch/providers.js";
|
10
15
|
|
11
|
-
|
12
16
|
registerFetchProviderFactory(DocumentProvider.ID, DocumentProvider.factory);
|
13
17
|
registerFetchProviderFactory(DocumentTypeProvider.ID, DocumentTypeProvider.factory);
|
14
18
|
registerFetchProviderFactory(InteractionRunProvider.ID, InteractionRunProvider.factory);
|
@@ -17,7 +21,11 @@ export class ActivityContext<ParamsT extends Record<string, any>> {
|
|
17
21
|
client: VertesiaClient;
|
18
22
|
_project?: Promise<Project | undefined>;
|
19
23
|
|
20
|
-
constructor(
|
24
|
+
constructor(
|
25
|
+
public payload: DSLActivityExecutionPayload<ParamsT>,
|
26
|
+
client: VertesiaClient,
|
27
|
+
public params: ParamsT,
|
28
|
+
) {
|
21
29
|
this.client = client;
|
22
30
|
this.fetchProject = this.fetchProject.bind(this);
|
23
31
|
}
|
@@ -29,24 +37,54 @@ export class ActivityContext<ParamsT extends Record<string, any>> {
|
|
29
37
|
get objectId() {
|
30
38
|
const objectId = this.payload.objectIds && this.payload.objectIds[0];
|
31
39
|
if (!objectId) {
|
32
|
-
log.error(
|
33
|
-
throw new WorkflowParamNotFound(
|
40
|
+
log.error("No objectId found in payload");
|
41
|
+
throw new WorkflowParamNotFound(
|
42
|
+
"objectIds[0]",
|
43
|
+
(this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow,
|
44
|
+
);
|
34
45
|
}
|
35
46
|
return objectId;
|
36
47
|
}
|
37
48
|
|
49
|
+
get activityInfo() {
|
50
|
+
return activityInfo();
|
51
|
+
}
|
52
|
+
|
53
|
+
get runId() {
|
54
|
+
const runId = activityInfo().workflowExecution.runId;
|
55
|
+
if (!runId) {
|
56
|
+
log.error("No runId found in activityInfo");
|
57
|
+
throw new WorkflowParamNotFound(
|
58
|
+
"runId",
|
59
|
+
(this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow,
|
60
|
+
);
|
61
|
+
}
|
62
|
+
return runId;
|
63
|
+
}
|
64
|
+
|
65
|
+
get workflowId() {
|
66
|
+
const workflowId = activityInfo().workflowExecution.workflowId;
|
67
|
+
if (!workflowId) {
|
68
|
+
log.error("No workflowId found in activityInfo");
|
69
|
+
throw new WorkflowParamNotFound(
|
70
|
+
"workflowId",
|
71
|
+
(this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow,
|
72
|
+
);
|
73
|
+
}
|
74
|
+
return workflowId;
|
75
|
+
}
|
76
|
+
|
38
77
|
fetchProject() {
|
39
78
|
if (!this._project) {
|
40
79
|
this._project = _fetchProject(this.client, this.payload);
|
41
80
|
}
|
42
81
|
return this._project;
|
43
82
|
}
|
44
|
-
|
45
83
|
}
|
46
84
|
|
47
|
-
|
48
|
-
|
49
|
-
|
85
|
+
export async function setupActivity<ParamsT extends Record<string, any>>(
|
86
|
+
payload: DSLActivityExecutionPayload<ParamsT>,
|
87
|
+
) {
|
50
88
|
const isDebugMode = !!payload.debug_mode;
|
51
89
|
|
52
90
|
const vars = new Vars({
|
@@ -56,13 +94,17 @@ export async function setupActivity<ParamsT extends Record<string, any>>(payload
|
|
56
94
|
|
57
95
|
//}
|
58
96
|
if (isDebugMode) {
|
59
|
-
log.info(`Setting up activity ${payload.activity.name}`, {
|
97
|
+
log.info(`Setting up activity ${payload.activity.name}`, {
|
98
|
+
config: payload.config,
|
99
|
+
activity: payload.activity,
|
100
|
+
params: payload.params,
|
101
|
+
vars,
|
102
|
+
});
|
60
103
|
}
|
61
104
|
|
62
105
|
const client = getVertesiaClient(payload);
|
63
106
|
const fetchSpecs = payload.activity.fetch;
|
64
107
|
if (fetchSpecs) {
|
65
|
-
|
66
108
|
const keys = Object.keys(fetchSpecs);
|
67
109
|
if (keys.length > 0) {
|
68
110
|
// create a new Vars instance to store the fetched data
|
@@ -74,7 +116,7 @@ export async function setupActivity<ParamsT extends Record<string, any>>(payload
|
|
74
116
|
fetchSpec = { ...fetchSpec, query };
|
75
117
|
}
|
76
118
|
|
77
|
-
const provider =
|
119
|
+
const provider = getFetchProvider(client, fetchSpec);
|
78
120
|
|
79
121
|
log.info(`Fetching data for ${key} with provider ${provider.name}`, { fetchSpec });
|
80
122
|
const result = await provider.fetch(fetchSpec);
|
@@ -84,7 +126,7 @@ export async function setupActivity<ParamsT extends Record<string, any>>(payload
|
|
84
126
|
} else {
|
85
127
|
vars.setValue(key, result);
|
86
128
|
}
|
87
|
-
} else if (fetchSpec.on_not_found ===
|
129
|
+
} else if (fetchSpec.on_not_found === "throw") {
|
88
130
|
throw new NoDocumentFound("No documents found for: " + JSON.stringify(fetchSpec));
|
89
131
|
} else {
|
90
132
|
vars.setValue(key, null);
|
@@ -94,12 +136,11 @@ export async function setupActivity<ParamsT extends Record<string, any>>(payload
|
|
94
136
|
}
|
95
137
|
|
96
138
|
const params = vars.resolve() as ParamsT;
|
97
|
-
log.info(`Activity ${payload.activity.name} setup complete
|
139
|
+
log.info(`Activity ${payload.activity.name} setup complete`);
|
98
140
|
|
99
141
|
return new ActivityContext<ParamsT>(payload, client, params);
|
100
142
|
}
|
101
143
|
|
102
|
-
|
103
144
|
async function _fetchProject(client: VertesiaClient, payload: WorkflowExecutionPayload) {
|
104
145
|
const project = await getProjectFromToken(payload.auth_token);
|
105
146
|
return project ? await client.projects.retrieve(project.id) : undefined;
|
@@ -18,7 +18,7 @@ describe('workflow validation', () => {
|
|
18
18
|
expect(errors.length).toBe(1);
|
19
19
|
})
|
20
20
|
|
21
|
-
test('activities
|
21
|
+
test('activities should be an array', () => {
|
22
22
|
const workflow: any = {
|
23
23
|
name: "test",
|
24
24
|
activities: {}
|
@@ -81,7 +81,7 @@ describe('workflow validation', () => {
|
|
81
81
|
expect(errors.length).toBe(0);
|
82
82
|
})
|
83
83
|
|
84
|
-
test('import unknown
|
84
|
+
test('import unknown imported var through expressions', () => {
|
85
85
|
const workflow: any = {
|
86
86
|
name: "test",
|
87
87
|
vars: { "foo": true },
|
package/src/dsl/vars.test.ts
CHANGED
@@ -125,7 +125,7 @@ describe('Workflow vars', () => {
|
|
125
125
|
expect(resolved.prompt_data.message).toBe("hello");
|
126
126
|
expect(resolved.data2).toBeTypeOf("object");
|
127
127
|
expect(resolved.data2.message).toBe("hello");
|
128
|
-
expect(resolved.
|
128
|
+
expect(resolved.unknown).toBeUndefined();
|
129
129
|
});
|
130
130
|
|
131
131
|
|
package/src/dsl/vars.ts
CHANGED
@@ -20,9 +20,9 @@ export function splitPath(path: string) {
|
|
20
20
|
|
21
21
|
/**
|
22
22
|
* Get the property named by "name" of the given object
|
23
|
-
* If an array is
|
23
|
+
* If an array is indexed using a string key then a map is done and an array with the content of the properties with that name are returned
|
24
24
|
* Ex: docs.text => will return an array of text properties of the docs array
|
25
|
-
* @param object the
|
25
|
+
* @param object the object
|
26
26
|
* @param name the name of the property.
|
27
27
|
* @returns the property value
|
28
28
|
*/
|
@@ -128,7 +128,7 @@ export class Vars {
|
|
128
128
|
map: Record<string, any>;
|
129
129
|
/**
|
130
130
|
* This property is used when resolving params. It contains the list of references that should not be resolved to their value
|
131
|
-
* but instead they need to return the string representation of the expression to
|
131
|
+
* but instead they need to return the string representation of the expression to be able to regenerate another Vars instance with the same expression
|
132
132
|
*/
|
133
133
|
//TODO this feature is no more used - it was replaced by importVars so we can now delete `preserveRefs`
|
134
134
|
preserveRefs: Set<string> | undefined;
|
@@ -154,7 +154,7 @@ export class Vars {
|
|
154
154
|
}
|
155
155
|
|
156
156
|
/**
|
157
|
-
* Set a literal value (
|
157
|
+
* Set a literal value (cannot set a ref)
|
158
158
|
* To add refs use `append()`
|
159
159
|
* @param name
|
160
160
|
* @param value
|
@@ -291,7 +291,7 @@ export class Vars {
|
|
291
291
|
}
|
292
292
|
|
293
293
|
getUnknownReferences(obj: any) {
|
294
|
-
const visitor = new
|
294
|
+
const visitor = new UnknownReferencesVisitor(this);
|
295
295
|
new ObjectWalker().walk(obj, visitor);
|
296
296
|
return visitor.result;
|
297
297
|
}
|
@@ -311,7 +311,7 @@ function addImportVar(varPath: string, asName: string | undefined, vars: Vars, r
|
|
311
311
|
}
|
312
312
|
|
313
313
|
|
314
|
-
class
|
314
|
+
class UnknownReferencesVisitor implements ObjectVisitor {
|
315
315
|
|
316
316
|
result: { name: string, expression: string }[] = [];
|
317
317
|
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import * as protos from '@temporalio/proto';
|
2
2
|
import { TestWorkflowEnvironment } from '@temporalio/testing';
|
3
3
|
import { Worker } from '@temporalio/worker';
|
4
|
+
import { ContentEventName, DSLActivityExecutionPayload, DSLWorkflowExecutionPayload, DSLWorkflowStep } from '@vertesia/common';
|
4
5
|
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
|
5
6
|
import { dslWorkflow } from './dsl-workflow.js';
|
6
7
|
import { setupActivity } from './setup/ActivityContext.js';
|
@@ -86,12 +87,21 @@ const steps2: DSLWorkflowStep[] = [
|
|
86
87
|
// ========== test env setup ==========
|
87
88
|
|
88
89
|
|
89
|
-
describe('DSL Workflow with
|
90
|
+
describe('DSL Workflow with child workflows', () => {
|
90
91
|
|
91
92
|
let testEnv: TestWorkflowEnvironment;
|
92
93
|
|
93
94
|
beforeAll(async () => {
|
94
95
|
testEnv = await TestWorkflowEnvironment.createLocal();
|
96
|
+
const { connection } = testEnv;
|
97
|
+
await connection.operatorService.addSearchAttributes({
|
98
|
+
namespace: 'default',
|
99
|
+
searchAttributes: {
|
100
|
+
AccountId: protos.temporal.api.enums.v1.IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD,
|
101
|
+
DocumentId: protos.temporal.api.enums.v1.IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD,
|
102
|
+
ProjectId: protos.temporal.api.enums.v1.IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD,
|
103
|
+
},
|
104
|
+
});
|
95
105
|
});
|
96
106
|
|
97
107
|
afterAll(async () => {
|
@@ -122,7 +132,7 @@ describe('DSL Workflow with chld workflows', () => {
|
|
122
132
|
auth_token: 'test',
|
123
133
|
config: {
|
124
134
|
studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
|
125
|
-
store_url: process.env.
|
135
|
+
store_url: process.env.CP_STORE_URL || "http://localhost:8082",
|
126
136
|
},
|
127
137
|
workflow: {
|
128
138
|
steps: steps1,
|
@@ -167,7 +177,7 @@ describe('DSL Workflow with chld workflows', () => {
|
|
167
177
|
auth_token: 'test',
|
168
178
|
config: {
|
169
179
|
studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
|
170
|
-
store_url: process.env.
|
180
|
+
store_url: process.env.CP_STORE_URL || "http://localhost:8082",
|
171
181
|
},
|
172
182
|
workflow: {
|
173
183
|
steps: steps2,
|
@@ -110,7 +110,7 @@ describe('DSL Workflow', () => {
|
|
110
110
|
auth_token: 'test',
|
111
111
|
config: {
|
112
112
|
studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
|
113
|
-
store_url: process.env.
|
113
|
+
store_url: process.env.CP_STORE_URL || "http://localhost:8082",
|
114
114
|
},
|
115
115
|
workflow: {
|
116
116
|
activities,
|
@@ -64,7 +64,7 @@ describe('DSL Workflow import vars', () => {
|
|
64
64
|
auth_token: 'test',
|
65
65
|
config: {
|
66
66
|
studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
|
67
|
-
store_url: process.env.
|
67
|
+
store_url: process.env.CP_STORE_URL || "http://localhost:8082",
|
68
68
|
},
|
69
69
|
workflow: {
|
70
70
|
activities,
|
package/src/dsl/workflow.test.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import * as protos from '@temporalio/proto';
|
2
2
|
import { TestWorkflowEnvironment } from '@temporalio/testing';
|
3
3
|
import { Worker } from '@temporalio/worker';
|
4
|
+
import { ContentEventName, DSLActivityExecutionPayload, DSLActivitySpec, DSLWorkflowExecutionPayload } from '@vertesia/common';
|
4
5
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
5
6
|
import { dslWorkflow } from './dsl-workflow.js';
|
6
7
|
import { setupActivity } from "./setup/ActivityContext.js";
|
@@ -52,6 +53,15 @@ describe('DSL Workflow', () => {
|
|
52
53
|
|
53
54
|
beforeAll(async () => {
|
54
55
|
testEnv = await TestWorkflowEnvironment.createLocal();
|
56
|
+
const { connection } = testEnv;
|
57
|
+
await connection.operatorService.addSearchAttributes({
|
58
|
+
namespace: 'default',
|
59
|
+
searchAttributes: {
|
60
|
+
AccountId: protos.temporal.api.enums.v1.IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD,
|
61
|
+
DocumentId: protos.temporal.api.enums.v1.IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD,
|
62
|
+
ProjectId: protos.temporal.api.enums.v1.IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD,
|
63
|
+
},
|
64
|
+
});
|
55
65
|
});
|
56
66
|
|
57
67
|
afterAll(async () => {
|
@@ -82,7 +92,7 @@ describe('DSL Workflow', () => {
|
|
82
92
|
auth_token: 'test',
|
83
93
|
config: {
|
84
94
|
studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
|
85
|
-
store_url: process.env.
|
95
|
+
store_url: process.env.CP_STORE_URL || "http://localhost:8082",
|
86
96
|
},
|
87
97
|
workflow: {
|
88
98
|
activities,
|
package/src/dsl.ts
CHANGED
package/src/errors.ts
CHANGED
@@ -1,24 +1,45 @@
|
|
1
1
|
import { DSLActivitySpec, DSLWorkflowSpec } from "@vertesia/common";
|
2
2
|
|
3
|
-
|
4
3
|
export class NoDocumentFound extends Error {
|
5
|
-
constructor(
|
4
|
+
constructor(
|
5
|
+
message: string,
|
6
|
+
public ids?: string[],
|
7
|
+
) {
|
6
8
|
super(message);
|
7
9
|
this.name = "NoDocumentFound";
|
8
|
-
this.ids = ids
|
10
|
+
this.ids = ids;
|
9
11
|
}
|
10
12
|
}
|
11
13
|
|
12
14
|
export class ActivityParamNotFound extends Error {
|
13
|
-
constructor(
|
15
|
+
constructor(
|
16
|
+
public paramName: string,
|
17
|
+
public activity: DSLActivitySpec,
|
18
|
+
) {
|
14
19
|
super(`Required parameter ${paramName} not found in activity ${activity.name}`);
|
15
20
|
this.name = "ActivityParamNotFound";
|
16
21
|
}
|
17
22
|
}
|
18
23
|
|
24
|
+
export class ActivityParamInvalid extends Error {
|
25
|
+
constructor(
|
26
|
+
public paramName: string,
|
27
|
+
public activity: DSLActivitySpec,
|
28
|
+
reason?: string,
|
29
|
+
) {
|
30
|
+
super(`${paramName} in activity ${activity.name} is invalid${reason ? ` ${reason}` : ""}`);
|
31
|
+
this.name = "ActivityParamInvalid";
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
19
35
|
export class WorkflowParamNotFound extends Error {
|
20
|
-
constructor(
|
36
|
+
constructor(
|
37
|
+
public paramName: string,
|
38
|
+
public workflow?: DSLWorkflowSpec,
|
39
|
+
) {
|
21
40
|
super(`Required parameter ${paramName} not found in workflow ${workflow?.name}`);
|
22
41
|
this.name = "WorkflowParamNotFound";
|
23
42
|
}
|
24
|
-
}
|
43
|
+
}
|
44
|
+
|
45
|
+
export const WF_NON_RETRYABLE_ERRORS = ["NoDocumentFound", "ActivityParamNotFound", "WorkflowParamNotFound"];
|
package/src/index.ts
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* Modify the `./activities/index.ts` if you want to modify activity exports
|
4
4
|
* 2. Workflows are exported through the '/workflows' named export in package.json.
|
5
5
|
* Modify the `./workflows.ts` file if you want to modify workflow exports
|
6
|
-
* 3. Here we export the API to be used to validate workflows and the types
|
6
|
+
* 3. Here we export the API to be used to validate workflows and the types required to create workflow TS definitions.
|
7
7
|
*/
|
8
8
|
|
9
9
|
//TODO remove this - it is only for backward compat - iot is used from old workflows
|
@@ -40,7 +40,7 @@ export async function it_gen_extractToc(payload: WorkflowExecutionPayload): Prom
|
|
40
40
|
await buildAndPublishMemoryPack(client, `${vars.memory}/output`, async () => {
|
41
41
|
return {
|
42
42
|
toc,
|
43
|
-
|
43
|
+
lastProcessedPart: undefined, // the part index (a number array)
|
44
44
|
previouslyGenerated: ""
|
45
45
|
} as OutputMemoryMeta
|
46
46
|
});
|
@@ -32,7 +32,7 @@ export async function it_gen_generatePart(payload: WorkflowExecutionPayload, pat
|
|
32
32
|
|
33
33
|
const content = await loadGeneratedContent(outMemory);
|
34
34
|
|
35
|
-
let previously_generated = getPreviouslyGeneratedContent(content, !part, vars.
|
35
|
+
let previously_generated = getPreviouslyGeneratedContent(content, !part, vars.remembrance_strategy);
|
36
36
|
|
37
37
|
if (!part) { // a new section
|
38
38
|
content.push({
|
@@ -58,7 +58,7 @@ export async function it_gen_generatePart(payload: WorkflowExecutionPayload, pat
|
|
58
58
|
|
59
59
|
const result = r.result as string;
|
60
60
|
content[content.length - 1].content += result;
|
61
|
-
meta.
|
61
|
+
meta.lastProcessedPart = path;
|
62
62
|
await buildAndPublishMemoryPack(client, `${memory}/output`, async ({ copyText }) => {
|
63
63
|
copyText(JSON.stringify(content, null, 2), "content.json");
|
64
64
|
return meta;
|
@@ -89,7 +89,7 @@ export async function it_gen_generateToc(payload: WorkflowExecutionPayload): Pro
|
|
89
89
|
await buildAndPublishMemoryPack(client, `${vars.memory}/output`, async () => {
|
90
90
|
return {
|
91
91
|
toc,
|
92
|
-
|
92
|
+
lastProcessedPart: undefined, // the part index (a number array)
|
93
93
|
previouslyGenerated: ""
|
94
94
|
} as OutputMemoryMeta
|
95
95
|
});
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { WorkflowExecutionPayload } from "@vertesia/common";
|
2
2
|
|
3
3
|
import { log, proxyActivities } from "@temporalio/workflow";
|
4
|
+
import { WF_NON_RETRYABLE_ERRORS } from "../errors.js";
|
4
5
|
import * as activities from "./activities/index.js";
|
5
6
|
import { IterativeGenerationPayload, PartIndex, SECTION_ID_PLACEHOLDER } from "./types.js";
|
6
7
|
|
@@ -16,7 +17,7 @@ const {
|
|
16
17
|
backoffCoefficient: 2,
|
17
18
|
maximumAttempts: 20,
|
18
19
|
maximumInterval: 100 * 30 * 1000, //ms
|
19
|
-
nonRetryableErrorTypes:
|
20
|
+
nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
|
20
21
|
},
|
21
22
|
});
|
22
23
|
|
@@ -29,7 +30,7 @@ export async function iterativeGenerationWorkflow(payload: WorkflowExecutionPayl
|
|
29
30
|
}
|
30
31
|
|
31
32
|
// extractToc tries to extract the toc from the input memory pack (toc.json or toc.yaml)
|
32
|
-
// the generateToc activity is
|
33
|
+
// the generateToc activity is returning the toc hierarchy.
|
33
34
|
// It doesn't include extra TOC details like description etc.
|
34
35
|
// To minimize the payload size only the hierarchy and the section/part names are returned
|
35
36
|
let toc = await it_gen_extractToc(payload);
|
@@ -13,7 +13,7 @@ export interface IterativeGenerationPayload {
|
|
13
13
|
// the main interaction will only be used to prepare the iteration (to generate the TOC)
|
14
14
|
// otherwise it will be used for the iterative generation too.
|
15
15
|
interaction: string;
|
16
|
-
// if defined this will be used for the iterative interaction which will
|
16
|
+
// if defined this will be used for the iterative interaction which will generate parts.
|
17
17
|
// otherwise the main interaction will be used for iterative generation.
|
18
18
|
iterative_interaction?: string;
|
19
19
|
// the environment to use
|
@@ -34,10 +34,10 @@ export interface IterativeGenerationPayload {
|
|
34
34
|
* If not set to "none" the previously generated content will be passed to the iteration.
|
35
35
|
* If not set at all defaults to "section".
|
36
36
|
* If "section" is used only the section content previously generated will be passed to the next iteration.
|
37
|
-
* If "document" is used the whole
|
37
|
+
* If "document" is used the whole previously generated document content will be passed to the next iteration.
|
38
38
|
* Defaults to section.
|
39
39
|
*/
|
40
|
-
|
40
|
+
remembrance_strategy?: "document" | "section" | "none";
|
41
41
|
/**
|
42
42
|
* If present will save sections in files using the pattern
|
43
43
|
* The pattern must include a placeholder for the section id: %id.
|
@@ -88,7 +88,7 @@ export interface TocIndex {
|
|
88
88
|
export interface OutputMemoryMeta {
|
89
89
|
toc: Toc;
|
90
90
|
previouslyGenerated: string;
|
91
|
-
|
91
|
+
lastProcessedPart?: number[] | undefined;
|
92
92
|
}
|
93
93
|
|
94
94
|
export interface Section {
|
@@ -79,19 +79,19 @@ export function getPreviousPathIndex(toc: Toc, pathIndex: number[]): number[] |
|
|
79
79
|
|
80
80
|
|
81
81
|
export function expectMemoryIsConsistent(meta: OutputMemoryMeta, pathIndex: number[]) {
|
82
|
-
const metaLastProcessedPart = meta.
|
82
|
+
const metaLastProcessedPart = meta.lastProcessedPart;
|
83
83
|
if (!metaLastProcessedPart) {
|
84
84
|
if (pathIndex.length > 1 && pathIndex[0] !== 0) {
|
85
|
-
throw ApplicationFailure.nonRetryable('Memory last processed part is not
|
85
|
+
throw ApplicationFailure.nonRetryable('Memory last processed part is not consistent with the workflow.', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: [pathIndex[0], pathIndex[1] - 1], previousIndex: metaLastProcessedPart });
|
86
86
|
} else {
|
87
87
|
return;
|
88
88
|
}
|
89
89
|
}
|
90
90
|
const prevPathIndex = getPreviousPathIndex(meta.toc, pathIndex);
|
91
91
|
if (!prevPathIndex) {
|
92
|
-
throw ApplicationFailure.nonRetryable('Memory last processed part is not
|
92
|
+
throw ApplicationFailure.nonRetryable('Memory last processed part is not consistent with the workflow', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: prevPathIndex, previousIndex: metaLastProcessedPart });
|
93
93
|
} else if (!isSamePartIndex(prevPathIndex, metaLastProcessedPart)) {
|
94
|
-
throw ApplicationFailure.nonRetryable('Memory last processed part is not
|
94
|
+
throw ApplicationFailure.nonRetryable('Memory last processed part is not consistent with the workflow', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: prevPathIndex, previousIndex: meta.lastProcessedPart });
|
95
95
|
}
|
96
96
|
}
|
97
97
|
|
@@ -3,6 +3,7 @@ import { log } from "@temporalio/workflow";
|
|
3
3
|
import { ContentEventName, WorkflowExecutionPayload } from "@vertesia/common";
|
4
4
|
import * as activities from "../activities/notifyWebhook.js";
|
5
5
|
import { dslProxyActivities } from "../dsl/dslProxyActivities.js";
|
6
|
+
import { WF_NON_RETRYABLE_ERRORS } from "../errors.js";
|
6
7
|
|
7
8
|
const {
|
8
9
|
notifyWebhook
|
@@ -13,7 +14,7 @@ const {
|
|
13
14
|
backoffCoefficient: 2,
|
14
15
|
maximumAttempts: 5,
|
15
16
|
maximumInterval: 100 * 30 * 1000, //ms
|
16
|
-
nonRetryableErrorTypes:
|
17
|
+
nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
|
17
18
|
},
|
18
19
|
});
|
19
20
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
import { SupportedEmbeddingTypes, WorkflowExecutionPayload } from "@vertesia/common";
|
3
3
|
import * as activities from "../activities/index-dsl.js";
|
4
4
|
import { dslProxyActivities } from "../dsl/dslProxyActivities.js";
|
5
|
-
import {
|
5
|
+
import { WF_NON_RETRYABLE_ERRORS } from "../errors.js";
|
6
6
|
|
7
7
|
const {
|
8
8
|
generateEmbeddings,
|
@@ -13,7 +13,7 @@ const {
|
|
13
13
|
backoffCoefficient: 2,
|
14
14
|
maximumAttempts: 10,
|
15
15
|
maximumInterval: 100 * 30 * 1000, //ms
|
16
|
-
nonRetryableErrorTypes:
|
16
|
+
nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
|
17
17
|
},
|
18
18
|
});
|
19
19
|
|
package/src/utils/blobs.ts
CHANGED
@@ -10,7 +10,12 @@ export async function fetchBlobAsStream(client: VertesiaClient, blobUri: string)
|
|
10
10
|
try {
|
11
11
|
return await client.files.downloadFile(blobUri);
|
12
12
|
} catch (err: any) {
|
13
|
-
|
13
|
+
if (err.message.includes("not found")) {
|
14
|
+
//TODO improve error handling with a fetch fail error class in the client
|
15
|
+
throw new NoDocumentFound(`Failed to download blob ${blobUri}: ${err.message}`, []);
|
16
|
+
} else {
|
17
|
+
throw new Error(`Failed to download blob ${blobUri}: ${err.message}`);
|
18
|
+
}
|
14
19
|
}
|
15
20
|
}
|
16
21
|
export async function fetchBlobAsBuffer(client: VertesiaClient, blobUri: string): Promise<Buffer> {
|
@@ -24,7 +29,7 @@ export async function fetchBlobAsBuffer(client: VertesiaClient, blobUri: string)
|
|
24
29
|
|
25
30
|
export async function fetchBlobAsBase64(client: VertesiaClient, blobUri: string): Promise<string> {
|
26
31
|
const buffer = await fetchBlobAsBuffer(client, blobUri);
|
27
|
-
return buffer.toString(
|
32
|
+
return buffer.toString("base64");
|
28
33
|
}
|
29
34
|
|
30
35
|
export async function saveBlobToFile(client: VertesiaClient, blobUri: string, toFile: string): Promise<void> {
|
@@ -36,8 +41,8 @@ export async function saveBlobToFile(client: VertesiaClient, blobUri: string, to
|
|
36
41
|
export async function saveBlobToTempFile(client: VertesiaClient, blobUri: string, fileExt?: string): Promise<string> {
|
37
42
|
const tmpFile = tmp.fileSync({
|
38
43
|
prefix: "vertesia-activity-",
|
39
|
-
postfix: "." + fileExt,
|
40
|
-
discardDescriptor: true
|
44
|
+
postfix: fileExt ? "." + fileExt : "",
|
45
|
+
discardDescriptor: true,
|
41
46
|
});
|
42
47
|
await saveBlobToFile(client, blobUri, tmpFile.name);
|
43
48
|
return tmpFile.name;
|
@@ -47,12 +52,12 @@ async function writeChunksToStream(chunks: AsyncIterable<Uint8Array>, out: NodeJ
|
|
47
52
|
for await (const chunk of chunks) {
|
48
53
|
if (!out.write(chunk)) {
|
49
54
|
// If the internal buffer is full, wait until it's drained
|
50
|
-
await new Promise(resolve => out.once(
|
55
|
+
await new Promise((resolve) => out.once("drain", resolve));
|
51
56
|
}
|
52
57
|
}
|
53
58
|
out.end(); // Close the stream when done
|
54
59
|
}
|
55
60
|
|
56
61
|
export function md5(contents: string) {
|
57
|
-
return crypto.createHash(
|
62
|
+
return crypto.createHash("md5").update(contents).digest("hex");
|
58
63
|
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
export interface DocPart {
|
3
|
+
line_number_start: number
|
4
|
+
line_number_end: number
|
5
|
+
name: string
|
6
|
+
type: string
|
7
|
+
}
|
8
|
+
|
9
|
+
export const getContentPart = (content: string, part: DocPart): string => {
|
10
|
+
const lines = content.split('\n');
|
11
|
+
const text = lines.filter((_l, i) => i >= part.line_number_start && i <= part.line_number_end).join('\n');
|
12
|
+
return text;
|
13
|
+
}
|
14
|
+
|
15
|
+
export const getContentParts = (content: string, parts: DocPart[]): string[] => {
|
16
|
+
return parts.map(part => getContentPart(content, part));
|
17
|
+
}
|
package/src/utils/client.ts
CHANGED
@@ -4,20 +4,21 @@
|
|
4
4
|
|
5
5
|
import { VertesiaClient } from "@vertesia/client";
|
6
6
|
import { WorkflowExecutionBaseParams } from "@vertesia/common";
|
7
|
+
import { WorkflowParamNotFound } from "../errors.js";
|
7
8
|
|
8
9
|
|
9
10
|
export function getVertesiaClient(payload: WorkflowExecutionBaseParams) {
|
10
11
|
|
11
12
|
if (!payload.auth_token) {
|
12
|
-
throw new
|
13
|
+
throw new WorkflowParamNotFound("Authentication Token is missing from WorkflowExecutionPayload.authToken");
|
13
14
|
}
|
14
15
|
|
15
16
|
if (!payload.config?.studio_url) {
|
16
|
-
throw new
|
17
|
+
throw new WorkflowParamNotFound("Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl");
|
17
18
|
}
|
18
19
|
|
19
20
|
if (!payload.config?.store_url) {
|
20
|
-
throw new
|
21
|
+
throw new WorkflowParamNotFound("Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl");
|
21
22
|
}
|
22
23
|
|
23
24
|
const client = new VertesiaClient({
|