@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.
Files changed (387) hide show
  1. package/package.json +9 -6
  2. package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +20 -1
  3. package/src/activities/chunkDocument.ts +62 -42
  4. package/src/activities/createDocumentFromOther.ts +2 -2
  5. package/src/activities/executeInteraction.ts +92 -47
  6. package/src/activities/extractDocumentText.ts +91 -54
  7. package/src/activities/generateDocumentProperties.ts +37 -16
  8. package/src/activities/generateEmbeddings.ts +91 -79
  9. package/src/activities/generateImageRendition.ts +127 -59
  10. package/src/activities/generateOrAssignContentType.ts +52 -32
  11. package/src/activities/getObjectFromStore.ts +1 -1
  12. package/src/activities/handleError.ts +25 -0
  13. package/src/activities/index-dsl.ts +1 -0
  14. package/src/activities/index.ts +0 -1
  15. package/src/activities/media/processPdfWithTextract.ts +4 -4
  16. package/src/activities/media/transcribeMediaWithGladia.ts +1 -1
  17. package/src/activities/notifyWebhook.ts +2 -2
  18. package/src/activities/setDocumentStatus.ts +1 -1
  19. package/src/conversion/TextractProcessor.ts +9 -9
  20. package/src/conversion/image.test.ts +110 -18
  21. package/src/conversion/image.ts +96 -15
  22. package/src/conversion/markitdown.ts +41 -0
  23. package/src/conversion/mutool.ts +1 -1
  24. package/src/conversion/pandoc.test.ts +8 -6
  25. package/src/conversion/pandoc.ts +38 -42
  26. package/src/dsl/dsl-workflow.ts +80 -12
  27. package/src/dsl/setup/ActivityContext.ts +57 -16
  28. package/src/dsl/validation.test.ts +2 -2
  29. package/src/dsl/vars.test.ts +1 -1
  30. package/src/dsl/vars.ts +6 -6
  31. package/src/dsl/workflow-exec-child.test.ts +14 -4
  32. package/src/dsl/workflow-fetch.test.ts +1 -1
  33. package/src/dsl/workflow-import.test.ts +1 -1
  34. package/src/dsl/workflow.test.ts +12 -2
  35. package/src/dsl.ts +1 -1
  36. package/src/errors.ts +27 -6
  37. package/src/index.ts +1 -1
  38. package/src/iterative-generation/activities/extractToc.ts +1 -1
  39. package/src/iterative-generation/activities/generatePart.ts +2 -2
  40. package/src/iterative-generation/activities/generateToc.ts +1 -1
  41. package/src/iterative-generation/iterativeGenerationWorkflow.ts +3 -2
  42. package/src/iterative-generation/types.ts +4 -4
  43. package/src/iterative-generation/utils.ts +4 -4
  44. package/src/system/notifyWebhookWorkflow.ts +2 -1
  45. package/src/system/recalculateEmbeddingsWorkflow.ts +2 -2
  46. package/src/utils/blobs.ts +11 -6
  47. package/src/utils/chunks.ts +17 -0
  48. package/src/utils/client.ts +4 -3
  49. package/src/utils/memory.ts +3 -8
  50. package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js +0 -32
  51. package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js.map +0 -1
  52. package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +0 -66
  53. package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +0 -1
  54. package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js +0 -18
  55. package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js.map +0 -1
  56. package/lib/cjs/activities/chunkDocument.js +0 -79
  57. package/lib/cjs/activities/chunkDocument.js.map +0 -1
  58. package/lib/cjs/activities/createDocumentFromOther.js +0 -64
  59. package/lib/cjs/activities/createDocumentFromOther.js.map +0 -1
  60. package/lib/cjs/activities/executeInteraction.js +0 -134
  61. package/lib/cjs/activities/executeInteraction.js.map +0 -1
  62. package/lib/cjs/activities/extractDocumentText.js +0 -135
  63. package/lib/cjs/activities/extractDocumentText.js.map +0 -1
  64. package/lib/cjs/activities/generateDocumentProperties.js +0 -59
  65. package/lib/cjs/activities/generateDocumentProperties.js.map +0 -1
  66. package/lib/cjs/activities/generateEmbeddings.js +0 -292
  67. package/lib/cjs/activities/generateEmbeddings.js.map +0 -1
  68. package/lib/cjs/activities/generateImageRendition.js +0 -104
  69. package/lib/cjs/activities/generateImageRendition.js.map +0 -1
  70. package/lib/cjs/activities/generateOrAssignContentType.js +0 -103
  71. package/lib/cjs/activities/generateOrAssignContentType.js.map +0 -1
  72. package/lib/cjs/activities/getObjectFromStore.js +0 -20
  73. package/lib/cjs/activities/getObjectFromStore.js.map +0 -1
  74. package/lib/cjs/activities/index-dsl.js +0 -37
  75. package/lib/cjs/activities/index-dsl.js.map +0 -1
  76. package/lib/cjs/activities/index.js +0 -22
  77. package/lib/cjs/activities/index.js.map +0 -1
  78. package/lib/cjs/activities/media/processPdfWithTextract.js +0 -102
  79. package/lib/cjs/activities/media/processPdfWithTextract.js.map +0 -1
  80. package/lib/cjs/activities/media/transcribeMediaWithGladia.js +0 -51
  81. package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +0 -1
  82. package/lib/cjs/activities/notifyWebhook.js +0 -34
  83. package/lib/cjs/activities/notifyWebhook.js.map +0 -1
  84. package/lib/cjs/activities/setDocumentStatus.js +0 -15
  85. package/lib/cjs/activities/setDocumentStatus.js.map +0 -1
  86. package/lib/cjs/conversion/TextractProcessor.js +0 -417
  87. package/lib/cjs/conversion/TextractProcessor.js.map +0 -1
  88. package/lib/cjs/conversion/image.js +0 -22
  89. package/lib/cjs/conversion/image.js.map +0 -1
  90. package/lib/cjs/conversion/mutool.js +0 -147
  91. package/lib/cjs/conversion/mutool.js.map +0 -1
  92. package/lib/cjs/conversion/pandoc.js +0 -39
  93. package/lib/cjs/conversion/pandoc.js.map +0 -1
  94. package/lib/cjs/dsl/conditions.js +0 -81
  95. package/lib/cjs/dsl/conditions.js.map +0 -1
  96. package/lib/cjs/dsl/dsl-workflow.js +0 -223
  97. package/lib/cjs/dsl/dsl-workflow.js.map +0 -1
  98. package/lib/cjs/dsl/dslProxyActivities.js +0 -23
  99. package/lib/cjs/dsl/dslProxyActivities.js.map +0 -1
  100. package/lib/cjs/dsl/projections.js +0 -59
  101. package/lib/cjs/dsl/projections.js.map +0 -1
  102. package/lib/cjs/dsl/setup/ActivityContext.js +0 -96
  103. package/lib/cjs/dsl/setup/ActivityContext.js.map +0 -1
  104. package/lib/cjs/dsl/setup/fetch/DataProvider.js +0 -51
  105. package/lib/cjs/dsl/setup/fetch/DataProvider.js.map +0 -1
  106. package/lib/cjs/dsl/setup/fetch/index.js +0 -16
  107. package/lib/cjs/dsl/setup/fetch/index.js.map +0 -1
  108. package/lib/cjs/dsl/setup/fetch/providers.js +0 -67
  109. package/lib/cjs/dsl/setup/fetch/providers.js.map +0 -1
  110. package/lib/cjs/dsl/test/test-child-workflow.js +0 -10
  111. package/lib/cjs/dsl/test/test-child-workflow.js.map +0 -1
  112. package/lib/cjs/dsl/validation.js +0 -122
  113. package/lib/cjs/dsl/validation.js.map +0 -1
  114. package/lib/cjs/dsl/vars.js +0 -341
  115. package/lib/cjs/dsl/vars.js.map +0 -1
  116. package/lib/cjs/dsl/walk.js +0 -100
  117. package/lib/cjs/dsl/walk.js.map +0 -1
  118. package/lib/cjs/dsl.js +0 -20
  119. package/lib/cjs/dsl.js.map +0 -1
  120. package/lib/cjs/errors.js +0 -36
  121. package/lib/cjs/errors.js.map +0 -1
  122. package/lib/cjs/index.js +0 -50
  123. package/lib/cjs/index.js.map +0 -1
  124. package/lib/cjs/iterative-generation/activities/extractToc.js +0 -47
  125. package/lib/cjs/iterative-generation/activities/extractToc.js.map +0 -1
  126. package/lib/cjs/iterative-generation/activities/finalizeOutput.js +0 -69
  127. package/lib/cjs/iterative-generation/activities/finalizeOutput.js.map +0 -1
  128. package/lib/cjs/iterative-generation/activities/generatePart.js +0 -73
  129. package/lib/cjs/iterative-generation/activities/generatePart.js.map +0 -1
  130. package/lib/cjs/iterative-generation/activities/generateToc.js +0 -91
  131. package/lib/cjs/iterative-generation/activities/generateToc.js.map +0 -1
  132. package/lib/cjs/iterative-generation/activities/index.js +0 -12
  133. package/lib/cjs/iterative-generation/activities/index.js.map +0 -1
  134. package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js +0 -55
  135. package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js.map +0 -1
  136. package/lib/cjs/iterative-generation/types.js +0 -5
  137. package/lib/cjs/iterative-generation/types.js.map +0 -1
  138. package/lib/cjs/iterative-generation/utils.js +0 -121
  139. package/lib/cjs/iterative-generation/utils.js.map +0 -1
  140. package/lib/cjs/package.json +0 -3
  141. package/lib/cjs/result-types.js +0 -10
  142. package/lib/cjs/result-types.js.map +0 -1
  143. package/lib/cjs/system/notifyWebhookWorkflow.js +0 -46
  144. package/lib/cjs/system/notifyWebhookWorkflow.js.map +0 -1
  145. package/lib/cjs/system/recalculateEmbeddingsWorkflow.js +0 -28
  146. package/lib/cjs/system/recalculateEmbeddingsWorkflow.js.map +0 -1
  147. package/lib/cjs/utils/auth.js +0 -15
  148. package/lib/cjs/utils/auth.js.map +0 -1
  149. package/lib/cjs/utils/blobs.js +0 -63
  150. package/lib/cjs/utils/blobs.js.map +0 -1
  151. package/lib/cjs/utils/client.js +0 -25
  152. package/lib/cjs/utils/client.js.map +0 -1
  153. package/lib/cjs/utils/expand-vars.js +0 -33
  154. package/lib/cjs/utils/expand-vars.js.map +0 -1
  155. package/lib/cjs/utils/memory.js +0 -72
  156. package/lib/cjs/utils/memory.js.map +0 -1
  157. package/lib/cjs/utils/tokens.js +0 -38
  158. package/lib/cjs/utils/tokens.js.map +0 -1
  159. package/lib/cjs/vars.js +0 -20
  160. package/lib/cjs/vars.js.map +0 -1
  161. package/lib/cjs/workflows.js +0 -15
  162. package/lib/cjs/workflows.js.map +0 -1
  163. package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js +0 -29
  164. package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js.map +0 -1
  165. package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +0 -63
  166. package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +0 -1
  167. package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js +0 -15
  168. package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js.map +0 -1
  169. package/lib/esm/activities/chunkDocument.js +0 -76
  170. package/lib/esm/activities/chunkDocument.js.map +0 -1
  171. package/lib/esm/activities/createDocumentFromOther.js +0 -58
  172. package/lib/esm/activities/createDocumentFromOther.js.map +0 -1
  173. package/lib/esm/activities/executeInteraction.js +0 -130
  174. package/lib/esm/activities/executeInteraction.js.map +0 -1
  175. package/lib/esm/activities/extractDocumentText.js +0 -132
  176. package/lib/esm/activities/extractDocumentText.js.map +0 -1
  177. package/lib/esm/activities/generateDocumentProperties.js +0 -56
  178. package/lib/esm/activities/generateDocumentProperties.js.map +0 -1
  179. package/lib/esm/activities/generateEmbeddings.js +0 -256
  180. package/lib/esm/activities/generateEmbeddings.js.map +0 -1
  181. package/lib/esm/activities/generateImageRendition.js +0 -98
  182. package/lib/esm/activities/generateImageRendition.js.map +0 -1
  183. package/lib/esm/activities/generateOrAssignContentType.js +0 -100
  184. package/lib/esm/activities/generateOrAssignContentType.js.map +0 -1
  185. package/lib/esm/activities/getObjectFromStore.js +0 -17
  186. package/lib/esm/activities/getObjectFromStore.js.map +0 -1
  187. package/lib/esm/activities/index-dsl.js +0 -18
  188. package/lib/esm/activities/index-dsl.js.map +0 -1
  189. package/lib/esm/activities/index.js +0 -6
  190. package/lib/esm/activities/index.js.map +0 -1
  191. package/lib/esm/activities/media/processPdfWithTextract.js +0 -98
  192. package/lib/esm/activities/media/processPdfWithTextract.js.map +0 -1
  193. package/lib/esm/activities/media/transcribeMediaWithGladia.js +0 -48
  194. package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +0 -1
  195. package/lib/esm/activities/notifyWebhook.js +0 -31
  196. package/lib/esm/activities/notifyWebhook.js.map +0 -1
  197. package/lib/esm/activities/setDocumentStatus.js +0 -12
  198. package/lib/esm/activities/setDocumentStatus.js.map +0 -1
  199. package/lib/esm/conversion/TextractProcessor.js +0 -410
  200. package/lib/esm/conversion/TextractProcessor.js.map +0 -1
  201. package/lib/esm/conversion/image.js +0 -16
  202. package/lib/esm/conversion/image.js.map +0 -1
  203. package/lib/esm/conversion/mutool.js +0 -139
  204. package/lib/esm/conversion/mutool.js.map +0 -1
  205. package/lib/esm/conversion/pandoc.js +0 -36
  206. package/lib/esm/conversion/pandoc.js.map +0 -1
  207. package/lib/esm/dsl/conditions.js +0 -75
  208. package/lib/esm/dsl/conditions.js.map +0 -1
  209. package/lib/esm/dsl/dsl-workflow.js +0 -216
  210. package/lib/esm/dsl/dsl-workflow.js.map +0 -1
  211. package/lib/esm/dsl/dslProxyActivities.js +0 -20
  212. package/lib/esm/dsl/dslProxyActivities.js.map +0 -1
  213. package/lib/esm/dsl/projections.js +0 -55
  214. package/lib/esm/dsl/projections.js.map +0 -1
  215. package/lib/esm/dsl/setup/ActivityContext.js +0 -91
  216. package/lib/esm/dsl/setup/ActivityContext.js.map +0 -1
  217. package/lib/esm/dsl/setup/fetch/DataProvider.js +0 -47
  218. package/lib/esm/dsl/setup/fetch/DataProvider.js.map +0 -1
  219. package/lib/esm/dsl/setup/fetch/index.js +0 -12
  220. package/lib/esm/dsl/setup/fetch/index.js.map +0 -1
  221. package/lib/esm/dsl/setup/fetch/providers.js +0 -61
  222. package/lib/esm/dsl/setup/fetch/providers.js.map +0 -1
  223. package/lib/esm/dsl/test/test-child-workflow.js +0 -5
  224. package/lib/esm/dsl/test/test-child-workflow.js.map +0 -1
  225. package/lib/esm/dsl/validation.js +0 -118
  226. package/lib/esm/dsl/validation.js.map +0 -1
  227. package/lib/esm/dsl/vars.js +0 -335
  228. package/lib/esm/dsl/vars.js.map +0 -1
  229. package/lib/esm/dsl/walk.js +0 -96
  230. package/lib/esm/dsl/walk.js.map +0 -1
  231. package/lib/esm/dsl.js +0 -4
  232. package/lib/esm/dsl.js.map +0 -1
  233. package/lib/esm/errors.js +0 -30
  234. package/lib/esm/errors.js.map +0 -1
  235. package/lib/esm/index.js +0 -32
  236. package/lib/esm/index.js.map +0 -1
  237. package/lib/esm/iterative-generation/activities/extractToc.js +0 -44
  238. package/lib/esm/iterative-generation/activities/extractToc.js.map +0 -1
  239. package/lib/esm/iterative-generation/activities/finalizeOutput.js +0 -66
  240. package/lib/esm/iterative-generation/activities/finalizeOutput.js.map +0 -1
  241. package/lib/esm/iterative-generation/activities/generatePart.js +0 -70
  242. package/lib/esm/iterative-generation/activities/generatePart.js.map +0 -1
  243. package/lib/esm/iterative-generation/activities/generateToc.js +0 -88
  244. package/lib/esm/iterative-generation/activities/generateToc.js.map +0 -1
  245. package/lib/esm/iterative-generation/activities/index.js +0 -5
  246. package/lib/esm/iterative-generation/activities/index.js.map +0 -1
  247. package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js +0 -52
  248. package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js.map +0 -1
  249. package/lib/esm/iterative-generation/types.js +0 -2
  250. package/lib/esm/iterative-generation/types.js.map +0 -1
  251. package/lib/esm/iterative-generation/utils.js +0 -112
  252. package/lib/esm/iterative-generation/utils.js.map +0 -1
  253. package/lib/esm/result-types.js +0 -7
  254. package/lib/esm/result-types.js.map +0 -1
  255. package/lib/esm/system/notifyWebhookWorkflow.js +0 -43
  256. package/lib/esm/system/notifyWebhookWorkflow.js.map +0 -1
  257. package/lib/esm/system/recalculateEmbeddingsWorkflow.js +0 -25
  258. package/lib/esm/system/recalculateEmbeddingsWorkflow.js.map +0 -1
  259. package/lib/esm/utils/auth.js +0 -8
  260. package/lib/esm/utils/auth.js.map +0 -1
  261. package/lib/esm/utils/blobs.js +0 -52
  262. package/lib/esm/utils/blobs.js.map +0 -1
  263. package/lib/esm/utils/client.js +0 -22
  264. package/lib/esm/utils/client.js.map +0 -1
  265. package/lib/esm/utils/expand-vars.js +0 -30
  266. package/lib/esm/utils/expand-vars.js.map +0 -1
  267. package/lib/esm/utils/memory.js +0 -60
  268. package/lib/esm/utils/memory.js.map +0 -1
  269. package/lib/esm/utils/tokens.js +0 -34
  270. package/lib/esm/utils/tokens.js.map +0 -1
  271. package/lib/esm/vars.js +0 -4
  272. package/lib/esm/vars.js.map +0 -1
  273. package/lib/esm/workflows.js +0 -8
  274. package/lib/esm/workflows.js.map +0 -1
  275. package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts +0 -17
  276. package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts.map +0 -1
  277. package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts +0 -29
  278. package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts.map +0 -1
  279. package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts +0 -19
  280. package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts.map +0 -1
  281. package/lib/types/activities/chunkDocument.d.ts +0 -18
  282. package/lib/types/activities/chunkDocument.d.ts.map +0 -1
  283. package/lib/types/activities/createDocumentFromOther.d.ts +0 -21
  284. package/lib/types/activities/createDocumentFromOther.d.ts.map +0 -1
  285. package/lib/types/activities/executeInteraction.d.ts +0 -44
  286. package/lib/types/activities/executeInteraction.d.ts.map +0 -1
  287. package/lib/types/activities/extractDocumentText.d.ts +0 -10
  288. package/lib/types/activities/extractDocumentText.d.ts.map +0 -1
  289. package/lib/types/activities/generateDocumentProperties.d.ts +0 -32
  290. package/lib/types/activities/generateDocumentProperties.d.ts.map +0 -1
  291. package/lib/types/activities/generateEmbeddings.d.ts +0 -49
  292. package/lib/types/activities/generateEmbeddings.d.ts.map +0 -1
  293. package/lib/types/activities/generateImageRendition.d.ts +0 -17
  294. package/lib/types/activities/generateImageRendition.d.ts.map +0 -1
  295. package/lib/types/activities/generateOrAssignContentType.d.ts +0 -44
  296. package/lib/types/activities/generateOrAssignContentType.d.ts.map +0 -1
  297. package/lib/types/activities/getObjectFromStore.d.ts +0 -14
  298. package/lib/types/activities/getObjectFromStore.d.ts.map +0 -1
  299. package/lib/types/activities/index-dsl.d.ts +0 -17
  300. package/lib/types/activities/index-dsl.d.ts.map +0 -1
  301. package/lib/types/activities/index.d.ts +0 -6
  302. package/lib/types/activities/index.d.ts.map +0 -1
  303. package/lib/types/activities/media/processPdfWithTextract.d.ts +0 -26
  304. package/lib/types/activities/media/processPdfWithTextract.d.ts.map +0 -1
  305. package/lib/types/activities/media/transcribeMediaWithGladia.d.ts +0 -14
  306. package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +0 -1
  307. package/lib/types/activities/notifyWebhook.d.ts +0 -17
  308. package/lib/types/activities/notifyWebhook.d.ts.map +0 -1
  309. package/lib/types/activities/setDocumentStatus.d.ts +0 -15
  310. package/lib/types/activities/setDocumentStatus.d.ts.map +0 -1
  311. package/lib/types/conversion/TextractProcessor.d.ts +0 -45
  312. package/lib/types/conversion/TextractProcessor.d.ts.map +0 -1
  313. package/lib/types/conversion/image.d.ts +0 -9
  314. package/lib/types/conversion/image.d.ts.map +0 -1
  315. package/lib/types/conversion/mutool.d.ts +0 -19
  316. package/lib/types/conversion/mutool.d.ts.map +0 -1
  317. package/lib/types/conversion/pandoc.d.ts +0 -2
  318. package/lib/types/conversion/pandoc.d.ts.map +0 -1
  319. package/lib/types/dsl/conditions.d.ts +0 -2
  320. package/lib/types/dsl/conditions.d.ts.map +0 -1
  321. package/lib/types/dsl/dsl-workflow.d.ts +0 -5
  322. package/lib/types/dsl/dsl-workflow.d.ts.map +0 -1
  323. package/lib/types/dsl/dslProxyActivities.d.ts +0 -10
  324. package/lib/types/dsl/dslProxyActivities.d.ts.map +0 -1
  325. package/lib/types/dsl/projections.d.ts +0 -4
  326. package/lib/types/dsl/projections.d.ts.map +0 -1
  327. package/lib/types/dsl/setup/ActivityContext.d.ts +0 -14
  328. package/lib/types/dsl/setup/ActivityContext.d.ts.map +0 -1
  329. package/lib/types/dsl/setup/fetch/DataProvider.d.ts +0 -9
  330. package/lib/types/dsl/setup/fetch/DataProvider.d.ts.map +0 -1
  331. package/lib/types/dsl/setup/fetch/index.d.ts +0 -6
  332. package/lib/types/dsl/setup/fetch/index.d.ts.map +0 -1
  333. package/lib/types/dsl/setup/fetch/providers.d.ts +0 -25
  334. package/lib/types/dsl/setup/fetch/providers.d.ts.map +0 -1
  335. package/lib/types/dsl/test/test-child-workflow.d.ts +0 -4
  336. package/lib/types/dsl/test/test-child-workflow.d.ts.map +0 -1
  337. package/lib/types/dsl/validation.d.ts +0 -4
  338. package/lib/types/dsl/validation.d.ts.map +0 -1
  339. package/lib/types/dsl/vars.d.ts +0 -48
  340. package/lib/types/dsl/vars.d.ts.map +0 -1
  341. package/lib/types/dsl/walk.d.ts +0 -18
  342. package/lib/types/dsl/walk.d.ts.map +0 -1
  343. package/lib/types/dsl.d.ts +0 -4
  344. package/lib/types/dsl.d.ts.map +0 -1
  345. package/lib/types/errors.d.ts +0 -16
  346. package/lib/types/errors.d.ts.map +0 -1
  347. package/lib/types/index.d.ts +0 -31
  348. package/lib/types/index.d.ts.map +0 -1
  349. package/lib/types/iterative-generation/activities/extractToc.d.ts +0 -10
  350. package/lib/types/iterative-generation/activities/extractToc.d.ts.map +0 -1
  351. package/lib/types/iterative-generation/activities/finalizeOutput.d.ts +0 -3
  352. package/lib/types/iterative-generation/activities/finalizeOutput.d.ts.map +0 -1
  353. package/lib/types/iterative-generation/activities/generatePart.d.ts +0 -3
  354. package/lib/types/iterative-generation/activities/generatePart.d.ts.map +0 -1
  355. package/lib/types/iterative-generation/activities/generateToc.d.ts +0 -4
  356. package/lib/types/iterative-generation/activities/generateToc.d.ts.map +0 -1
  357. package/lib/types/iterative-generation/activities/index.d.ts +0 -5
  358. package/lib/types/iterative-generation/activities/index.d.ts.map +0 -1
  359. package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts +0 -3
  360. package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts.map +0 -1
  361. package/lib/types/iterative-generation/types.d.ts +0 -79
  362. package/lib/types/iterative-generation/types.d.ts.map +0 -1
  363. package/lib/types/iterative-generation/utils.d.ts +0 -27
  364. package/lib/types/iterative-generation/utils.d.ts.map +0 -1
  365. package/lib/types/result-types.d.ts +0 -22
  366. package/lib/types/result-types.d.ts.map +0 -1
  367. package/lib/types/system/notifyWebhookWorkflow.d.ts +0 -3
  368. package/lib/types/system/notifyWebhookWorkflow.d.ts.map +0 -1
  369. package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts +0 -40
  370. package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts.map +0 -1
  371. package/lib/types/utils/auth.d.ts +0 -4
  372. package/lib/types/utils/auth.d.ts.map +0 -1
  373. package/lib/types/utils/blobs.d.ts +0 -8
  374. package/lib/types/utils/blobs.d.ts.map +0 -1
  375. package/lib/types/utils/client.d.ts +0 -7
  376. package/lib/types/utils/client.d.ts.map +0 -1
  377. package/lib/types/utils/expand-vars.d.ts +0 -8
  378. package/lib/types/utils/expand-vars.d.ts.map +0 -1
  379. package/lib/types/utils/memory.d.ts +0 -12
  380. package/lib/types/utils/memory.d.ts.map +0 -1
  381. package/lib/types/utils/tokens.d.ts +0 -11
  382. package/lib/types/utils/tokens.d.ts.map +0 -1
  383. package/lib/types/vars.d.ts +0 -3
  384. package/lib/types/vars.d.ts.map +0 -1
  385. package/lib/types/workflows.d.ts +0 -8
  386. package/lib/types/workflows.d.ts.map +0 -1
  387. 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 { DSLActivityExecutionPayload, DSLWorkflowExecutionPayload, Project, WorkflowExecutionPayload } from "@vertesia/common";
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(public payload: DSLActivityExecutionPayload<ParamsT>, client: VertesiaClient, public params: ParamsT) {
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('No objectId found in payload');
33
- throw new WorkflowParamNotFound('objectIds[0]', (this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow);
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
- export async function setupActivity<ParamsT extends Record<string, any>>(payload: DSLActivityExecutionPayload<ParamsT>) {
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}`, { config: payload.config, activity: payload.activity, params: payload.params, vars });
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 = await getFetchProvider(client, fetchSpec);
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 === 'throw') {
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`, { params });
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 shpuld be an array', () => {
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 imorted var through expressions', () => {
84
+ test('import unknown imported var through expressions', () => {
85
85
  const workflow: any = {
86
86
  name: "test",
87
87
  vars: { "foo": true },
@@ -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.unnown).toBeUndefined();
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 idnexed using a string key then a map is done and an array with the content of the properties with that name are returned
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 obejct
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 eb able to regenrate another Vars instance with the same expression
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 (canboot set a ref)
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 UnknownRefrencesVisitor(this);
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 UnknownRefrencesVisitor implements ObjectVisitor {
314
+ class UnknownReferencesVisitor implements ObjectVisitor {
315
315
 
316
316
  result: { name: string, expression: string }[] = [];
317
317
 
@@ -1,6 +1,7 @@
1
- import { ContentEventName, DSLActivityExecutionPayload, DSLWorkflowExecutionPayload, DSLWorkflowStep } from '@vertesia/common';
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 chld workflows', () => {
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.CP_STODRE_URL || "http://localhost:8082",
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.CP_STODRE_URL || "http://localhost:8082",
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.CP_STODRE_URL || "http://localhost:8082",
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.CP_STODRE_URL || "http://localhost:8082",
67
+ store_url: process.env.CP_STORE_URL || "http://localhost:8082",
68
68
  },
69
69
  workflow: {
70
70
  activities,
@@ -1,6 +1,7 @@
1
- import { ContentEventName, DSLActivityExecutionPayload, DSLActivitySpec, DSLWorkflowExecutionPayload } from '@vertesia/common';
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.CP_STODRE_URL || "http://localhost:8082",
95
+ store_url: process.env.CP_STORE_URL || "http://localhost:8082",
86
96
  },
87
97
  workflow: {
88
98
  activities,
package/src/dsl.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./dsl/dslProxyActivities.js";
2
+ export * from "./errors.js";
2
3
  export * from "./result-types.js";
3
- export * from "./errors.js";
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(message: string, public ids?: string[]) {
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(public paramName: string, public activity: DSLActivitySpec) {
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(public paramName: string, public workflow?: DSLWorkflowSpec) {
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 reuired to create workflow TS definitions.
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
- lastProcessdPart: undefined, // the part index (a number array)
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.rememberance_strategy);
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.lastProcessdPart = path;
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
- lastProcessdPart: undefined, // the part index (a number array)
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 retiurning the toc hierarchy.
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 genrate parts.
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 previopusly generated document content will be passed to the next iteration.
37
+ * If "document" is used the whole previously generated document content will be passed to the next iteration.
38
38
  * Defaults to section.
39
39
  */
40
- rememberance_strategy?: "document" | "section" | "none";
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
- lastProcessdPart?: number[] | undefined;
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.lastProcessdPart;
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 consitent with the workflow.', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: [pathIndex[0], pathIndex[1] - 1], previousIndex: metaLastProcessedPart });
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 consitent with the workflow', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: prevPathIndex, previousIndex: metaLastProcessedPart });
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 consitent with the workflow', 'MemoryPackNotConsistent', { currentIndex: pathIndex, expectedPreviousIndex: prevPathIndex, previousIndex: meta.lastProcessdPart });
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 { NoDocumentFound } from "../errors.js";
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: [NoDocumentFound.name],
16
+ nonRetryableErrorTypes: WF_NON_RETRYABLE_ERRORS,
17
17
  },
18
18
  });
19
19
 
@@ -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
- throw new NoDocumentFound(`Failed to download blob ${blobUri}: ${err.message}`, []);
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('base64');
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('drain', resolve));
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('md5').update(contents).digest("hex");
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
+ }
@@ -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 Error("Authentication Token is missing from WorkflowExecutionPayload.authToken");
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 Error("Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl");
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 Error("Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl");
21
+ throw new WorkflowParamNotFound("Content Store URL is missing from WorkflowExecutionPayload.servers.storeUrl");
21
22
  }
22
23
 
23
24
  const client = new VertesiaClient({