@vertesia/workflow 0.74.0 → 0.77.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vertesia/workflow",
3
- "version": "0.74.0",
3
+ "version": "0.77.0",
4
4
  "type": "module",
5
- "description": "Composable prompts workflow dsl",
5
+ "description": "Vertesia workflow DSL",
6
6
  "main": "./lib/esm/index.js",
7
7
  "files": [
8
8
  "lib",
@@ -50,10 +50,10 @@
50
50
  "tmp-promise": "^3.0.3",
51
51
  "yaml": "^2.6.0",
52
52
  "@llumiverse/common": "0.22.0",
53
- "@vertesia/common": "0.74.0",
54
- "@vertesia/client": "0.74.0",
55
- "@vertesia/memory": "0.46.0",
56
- "@vertesia/api-fetch-client": "0.74.0"
53
+ "@vertesia/common": "0.77.0",
54
+ "@vertesia/client": "0.77.0",
55
+ "@vertesia/api-fetch-client": "0.77.0",
56
+ "@vertesia/memory": "0.48.0"
57
57
  },
58
58
  "ts_dual_module": {
59
59
  "outDir": "lib",
@@ -1,6 +1,7 @@
1
- import { ModelOptions } from "@llumiverse/common";
1
+ import { Modalities, ModelOptions } from "@llumiverse/common";
2
2
  import { activityInfo, log } from "@temporalio/activity";
3
3
  import { VertesiaClient } from "@vertesia/client";
4
+ import { NodeStreamSource } from "@vertesia/client/node";
4
5
  import {
5
6
  DSLActivityExecutionPayload,
6
7
  DSLActivitySpec,
@@ -14,6 +15,7 @@ import { projectResult } from "../dsl/projections.js";
14
15
  import { setupActivity } from "../dsl/setup/ActivityContext.js";
15
16
  import { ActivityParamInvalidError, ActivityParamNotFoundError } from "../errors.js";
16
17
  import { TruncateSpec, truncByMaxTokens } from "../utils/tokens.js";
18
+ import { Readable } from "stream";
17
19
 
18
20
  //Example:
19
21
  //@ts-ignore
@@ -148,11 +150,42 @@ export async function executeInteraction(payload: DSLActivityExecutionPayload<Ex
148
150
  prompt_data,
149
151
  payload.debug_mode,
150
152
  );
153
+
154
+ // Handle image uploads if the result contains base64 images
155
+ if (res.output_modality === Modalities.image) {
156
+ const images = res.result.images;
157
+ const uploadedImages = await Promise.all(
158
+ images.map((image: string, index: number) => {
159
+ // Extract base64 data and create buffer
160
+ const base64Data = image.replace(/^data:image\/[a-z]+;base64,/, "");
161
+ const buffer = Buffer.from(base64Data, 'base64');
162
+
163
+ // Generate filename
164
+ const { runId } = activityInfo().workflowExecution;
165
+ const { activityId } = activityInfo();
166
+ const filename = `generated-image-${runId}-${activityId}-${index}.png`;
167
+
168
+ // Create a readable stream from the buffer
169
+ const stream = Readable.from(buffer);
170
+
171
+ const source = new NodeStreamSource(
172
+ stream,
173
+ filename,
174
+ "image/png",
175
+ );
176
+
177
+ return client.files.uploadFile(source);
178
+ })
179
+ );
180
+ res.result.images = uploadedImages;
181
+ }
182
+
151
183
  return projectResult(payload, params, res, {
152
184
  runId: res.id,
153
185
  status: res.status,
154
186
  result: res.result,
155
187
  });
188
+
156
189
  } catch (error: any) {
157
190
  log.error("Failed to execute interaction", { error });
158
191
  if (error.message.includes("Failed to validate merged prompt schema")) {
@@ -143,7 +143,7 @@ async function handleError(originalError: any, basePayload: BaseActivityPayload,
143
143
  await CancellationScope.nonCancellable(() => handleDslError(payload));
144
144
  } else {
145
145
  log.warn(`Workflow execution failed, executing error handler to update document status`, { error: originalError });
146
- handleDslError(payload);
146
+ await handleDslError(payload);
147
147
  }
148
148
  throw originalError;
149
149
  }
@@ -68,7 +68,7 @@ describe('Workflow vars', () => {
68
68
  boolean: "${objectId ?? true}",
69
69
  array: "${objectId ?? [1,2]}",
70
70
  });
71
- // object valus and path expression are not supported
71
+ // object value and path expression are not supported
72
72
  expect(vars.getValue("squote")).toBe("123");
73
73
  expect(vars.getValue("dquote")).toBe("123");
74
74
  expect(vars.getValue("number")).toBe(123);
@@ -20,8 +20,14 @@ const {
20
20
  export async function recalculateEmbeddingsWorkflow(payload: WorkflowExecutionPayload) {
21
21
 
22
22
  const embeddings = [];
23
+ const payloadType = payload.vars?.type as SupportedEmbeddingTypes;
23
24
 
24
- for (const type of Object.values(SupportedEmbeddingTypes)) {
25
+ if (payloadType && !Object.values(SupportedEmbeddingTypes).includes(payloadType)) {
26
+ throw new Error("Embedding type must be text, image, or properties");
27
+ }
28
+ const types = payloadType ? [payloadType] : Object.values(SupportedEmbeddingTypes);
29
+
30
+ for (const type of types) {
25
31
  embeddings.push(generateEmbeddings(payload, {
26
32
  force: true,
27
33
  type