@vertesia/workflow 0.79.1 → 0.80.0-dev.20251121

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,136 +1,136 @@
1
1
  {
2
- "name": "@vertesia/workflow",
3
- "version": "0.79.1",
4
- "type": "module",
5
- "description": "Vertesia workflow DSL",
6
- "main": "./lib/esm/index.js",
7
- "files": [
8
- "lib",
9
- "src"
10
- ],
11
- "bin": {
12
- "bundle-workflows": "./bin/bundle-workflows.mjs"
2
+ "name": "@vertesia/workflow",
3
+ "version": "0.80.0-dev.20251121",
4
+ "type": "module",
5
+ "description": "Vertesia workflow DSL",
6
+ "main": "./lib/esm/index.js",
7
+ "files": [
8
+ "lib",
9
+ "src"
10
+ ],
11
+ "bin": {
12
+ "bundle-workflows": "./bin/bundle-workflows.mjs"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "devDependencies": {
16
+ "@smithy/types": "^3.7.2",
17
+ "@temporalio/proto": "^1.11.5",
18
+ "@temporalio/testing": "^1.11.5",
19
+ "@temporalio/worker": "^1.11.5",
20
+ "@types/jsonwebtoken": "^9.0.7",
21
+ "@types/node": "^22.5.1",
22
+ "@types/papaparse": "^5.3.15",
23
+ "@types/tmp": "^0.2.6",
24
+ "ts-dual-module": "^0.6.3",
25
+ "vitest": "^3.0.9"
26
+ },
27
+ "dependencies": {
28
+ "@aws-sdk/client-s3": "^3.693.0",
29
+ "@aws-sdk/client-textract": "^3.693.0",
30
+ "@aws-sdk/credential-providers": "^3.693.0",
31
+ "@temporalio/activity": "^1.11.5",
32
+ "@temporalio/workflow": "^1.11.5",
33
+ "@types/json-schema": "^7.0.15",
34
+ "fast-deep-equal": "^3.1.3",
35
+ "jsonwebtoken": "^9.0.2",
36
+ "mime": "^4.0.0",
37
+ "ms": "3.0.0-canary.1",
38
+ "node-web-stream-adapters": "^0.2.1",
39
+ "p-limit": "^6.2.0",
40
+ "papaparse": "^5.4.1",
41
+ "seedrandom": "^3.0.5",
42
+ "sharp": "^0.33.4",
43
+ "tiktoken": "^1.0.15",
44
+ "tmp": "^0.2.4",
45
+ "tmp-promise": "^3.0.3",
46
+ "yaml": "^2.6.0",
47
+ "@vertesia/api-fetch-client": "0.80.0-dev.20251121",
48
+ "@vertesia/memory": "0.80.0-dev.20251121",
49
+ "@vertesia/common": "0.80.0-dev.20251121",
50
+ "@vertesia/client": "0.80.0-dev.20251121",
51
+ "@llumiverse/common": "0.23.0-dev.20251121"
52
+ },
53
+ "ts_dual_module": {
54
+ "outDir": "lib",
55
+ "exports": {
56
+ "activities": "./activities/index.js",
57
+ "dsl-activities": "./activities/index-dsl.js",
58
+ "workflows": "./workflows",
59
+ "workflows-bundle": "./workflows-bundle.js",
60
+ "vars": "./vars"
61
+ }
62
+ },
63
+ "exports": {
64
+ ".": {
65
+ "types": "./lib/types/index.d.ts",
66
+ "import": "./lib/esm/index.js",
67
+ "require": "./lib/cjs/index.js"
13
68
  },
14
- "scripts": {
15
- "test": "vitest run",
16
- "build": "pnpm exec tsmod build && node ./bin/bundle-workflows.mjs lib/esm/workflows.js lib/workflows-bundle.js",
17
- "clean": "rm -rf ./lib tsconfig.tsbuildinfo"
69
+ "./vars": {
70
+ "types": "./lib/types/vars.d.ts",
71
+ "import": "./lib/esm/vars.js",
72
+ "require": "./lib/cjs/vars.js"
18
73
  },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/vertesia/composableai.git",
22
- "directory": "zeno/workflow"
74
+ "./activities": {
75
+ "types": "./lib/types/activities/index.d.ts",
76
+ "import": "./lib/esm/activities/index.js",
77
+ "require": "./lib/cjs/activities/index.js"
23
78
  },
24
- "license": "Apache-2.0",
25
- "devDependencies": {
26
- "@smithy/types": "^3.7.2",
27
- "@temporalio/proto": "^1.11.5",
28
- "@temporalio/testing": "^1.11.5",
29
- "@temporalio/worker": "^1.11.5",
30
- "@types/jsonwebtoken": "^9.0.7",
31
- "@types/node": "^22.5.1",
32
- "@types/papaparse": "^5.3.15",
33
- "@types/tmp": "^0.2.6",
34
- "ts-dual-module": "^0.6.3",
35
- "vitest": "^3.0.9"
79
+ "./dsl-activities": {
80
+ "types": "./lib/types/activities/index-dsl.d.ts",
81
+ "import": "./lib/esm/activities/index-dsl.js",
82
+ "require": "./lib/cjs/activities/index-dsl.js"
36
83
  },
37
- "dependencies": {
38
- "@aws-sdk/client-s3": "^3.693.0",
39
- "@aws-sdk/client-textract": "^3.693.0",
40
- "@aws-sdk/credential-providers": "^3.693.0",
41
- "@llumiverse/common": "workspace:*",
42
- "@temporalio/activity": "^1.11.5",
43
- "@temporalio/workflow": "^1.11.5",
44
- "@types/json-schema": "^7.0.15",
45
- "@vertesia/api-fetch-client": "workspace:*",
46
- "@vertesia/client": "workspace:*",
47
- "@vertesia/common": "workspace:*",
48
- "@vertesia/memory": "workspace:*",
49
- "fast-deep-equal": "^3.1.3",
50
- "jsonwebtoken": "^9.0.2",
51
- "mime": "^4.0.0",
52
- "ms": "3.0.0-canary.1",
53
- "node-web-stream-adapters": "^0.2.1",
54
- "p-limit": "^6.2.0",
55
- "papaparse": "^5.4.1",
56
- "seedrandom": "^3.0.5",
57
- "sharp": "^0.33.4",
58
- "tiktoken": "^1.0.15",
59
- "tmp": "^0.2.3",
60
- "tmp-promise": "^3.0.3",
61
- "yaml": "^2.6.0"
84
+ "./workflows": {
85
+ "types": "./lib/types/workflows.d.ts",
86
+ "import": "./lib/esm/workflows.js",
87
+ "require": "./lib/cjs/workflows.js"
62
88
  },
63
- "ts_dual_module": {
64
- "outDir": "lib",
65
- "exports": {
66
- "activities": "./activities/index.js",
67
- "dsl-activities": "./activities/index-dsl.js",
68
- "workflows": "./workflows",
69
- "workflows-bundle": "./workflows-bundle.js",
70
- "vars": "./vars"
71
- }
89
+ "./dsl": {
90
+ "types": "./lib/types/dsl.d.ts",
91
+ "import": "./lib/esm/dsl.js",
92
+ "require": "./lib/cjs/dsl.js"
72
93
  },
73
- "exports": {
74
- ".": {
75
- "types": "./lib/types/index.d.ts",
76
- "import": "./lib/esm/index.js",
77
- "require": "./lib/cjs/index.js"
78
- },
79
- "./vars": {
80
- "types": "./lib/types/vars.d.ts",
81
- "import": "./lib/esm/vars.js",
82
- "require": "./lib/cjs/vars.js"
83
- },
84
- "./activities": {
85
- "types": "./lib/types/activities/index.d.ts",
86
- "import": "./lib/esm/activities/index.js",
87
- "require": "./lib/cjs/activities/index.js"
88
- },
89
- "./dsl-activities": {
90
- "types": "./lib/types/activities/index-dsl.d.ts",
91
- "import": "./lib/esm/activities/index-dsl.js",
92
- "require": "./lib/cjs/activities/index-dsl.js"
93
- },
94
- "./workflows": {
95
- "types": "./lib/types/workflows.d.ts",
96
- "import": "./lib/esm/workflows.js",
97
- "require": "./lib/cjs/workflows.js"
98
- },
99
- "./dsl": {
100
- "types": "./lib/types/dsl.d.ts",
101
- "import": "./lib/esm/dsl.js",
102
- "require": "./lib/cjs/dsl.js"
103
- },
104
- "./workflows-bundle": {
105
- "import": "./lib/workflows-bundle.js"
106
- },
107
- "./errors": {
108
- "types": "./lib/types/errors.d.ts",
109
- "import": "./lib/esm/errors.js",
110
- "require": "./lib/cjs/errors.js"
111
- }
94
+ "./workflows-bundle": {
95
+ "import": "./lib/workflows-bundle.js"
112
96
  },
113
- "types": "./lib/types/index.d.ts",
114
- "typesVersions": {
115
- "*": {
116
- "activities": [
117
- "./lib/types/activities/index.d.ts"
118
- ],
119
- "dsl-activities": [
120
- "./lib/types/activities/index-dsl.d.ts"
121
- ],
122
- "workflows": [
123
- "./lib/types/workflows.d.ts"
124
- ],
125
- "dsl": [
126
- "./lib/types/dsl.d.ts"
127
- ],
128
- "vars": [
129
- "./lib/types/dsl/vars.d.ts"
130
- ],
131
- "errors": [
132
- "./lib/types/errors.d.ts"
133
- ]
134
- }
97
+ "./errors": {
98
+ "types": "./lib/types/errors.d.ts",
99
+ "import": "./lib/esm/errors.js",
100
+ "require": "./lib/cjs/errors.js"
101
+ }
102
+ },
103
+ "repository": {
104
+ "type": "git",
105
+ "url": "https://github.com/vertesia/composableai.git",
106
+ "directory": "packages/workflow"
107
+ },
108
+ "types": "./lib/types/index.d.ts",
109
+ "typesVersions": {
110
+ "*": {
111
+ "activities": [
112
+ "./lib/types/activities/index.d.ts"
113
+ ],
114
+ "dsl-activities": [
115
+ "./lib/types/activities/index-dsl.d.ts"
116
+ ],
117
+ "workflows": [
118
+ "./lib/types/workflows.d.ts"
119
+ ],
120
+ "dsl": [
121
+ "./lib/types/dsl.d.ts"
122
+ ],
123
+ "vars": [
124
+ "./lib/types/dsl/vars.d.ts"
125
+ ],
126
+ "errors": [
127
+ "./lib/types/errors.d.ts"
128
+ ]
135
129
  }
136
- }
130
+ },
131
+ "scripts": {
132
+ "test": "vitest run",
133
+ "build": "pnpm exec tsmod build && node ./bin/bundle-workflows.mjs lib/esm/workflows.js lib/workflows-bundle.js",
134
+ "clean": "rm -rf ./lib tsconfig.tsbuildinfo"
135
+ }
136
+ }
@@ -33,7 +33,7 @@ const defaultParams = {
33
33
  const createTestPayload = (params: Partial<NotifyWebhookParams> = {}): DSLActivityExecutionPayload<NotifyWebhookParams> => {
34
34
  const mergedParams = { ...defaultParams, ...params };
35
35
  return {
36
- auth_token: "unset",
36
+ auth_token: process.env.VERTESIA_KEY || "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature",
37
37
  account_id: "unset",
38
38
  project_id: "unset",
39
39
  params: mergedParams,
@@ -6,16 +6,32 @@ import {
6
6
  Project,
7
7
  WorkflowExecutionPayload,
8
8
  } from "@vertesia/common";
9
- import { DocumentNotFoundError, WorkflowParamNotFoundError } from "../../errors.js";
9
+ import {
10
+ DocumentNotFoundError,
11
+ WorkflowParamNotFoundError,
12
+ } from "../../errors.js";
10
13
  import { getProjectFromToken } from "../../utils/auth.js";
11
14
  import { getVertesiaClient } from "../../utils/client.js";
12
15
  import { Vars } from "../vars.js";
13
- import { getFetchProvider, registerFetchProviderFactory } from "./fetch/index.js";
14
- import { DocumentProvider, DocumentTypeProvider, InteractionRunProvider } from "./fetch/providers.js";
16
+ import {
17
+ getFetchProvider,
18
+ registerFetchProviderFactory,
19
+ } from "./fetch/index.js";
20
+ import {
21
+ DocumentProvider,
22
+ DocumentTypeProvider,
23
+ InteractionRunProvider,
24
+ } from "./fetch/providers.js";
15
25
 
16
26
  registerFetchProviderFactory(DocumentProvider.ID, DocumentProvider.factory);
17
- registerFetchProviderFactory(DocumentTypeProvider.ID, DocumentTypeProvider.factory);
18
- registerFetchProviderFactory(InteractionRunProvider.ID, InteractionRunProvider.factory);
27
+ registerFetchProviderFactory(
28
+ DocumentTypeProvider.ID,
29
+ DocumentTypeProvider.factory,
30
+ );
31
+ registerFetchProviderFactory(
32
+ InteractionRunProvider.ID,
33
+ InteractionRunProvider.factory,
34
+ );
19
35
 
20
36
  export class ActivityContext<ParamsT extends Record<string, any>> {
21
37
  client: VertesiaClient;
@@ -40,7 +56,10 @@ export class ActivityContext<ParamsT extends Record<string, any>> {
40
56
  log.error("No objectId found in payload");
41
57
  throw new WorkflowParamNotFoundError(
42
58
  "objectIds[0]",
43
- (this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow,
59
+ (
60
+ this
61
+ .payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload
62
+ ).workflow,
44
63
  );
45
64
  }
46
65
  return objectId;
@@ -56,7 +75,10 @@ export class ActivityContext<ParamsT extends Record<string, any>> {
56
75
  log.error("No runId found in activityInfo");
57
76
  throw new WorkflowParamNotFoundError(
58
77
  "runId",
59
- (this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow,
78
+ (
79
+ this
80
+ .payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload
81
+ ).workflow,
60
82
  );
61
83
  }
62
84
  return runId;
@@ -68,7 +90,10 @@ export class ActivityContext<ParamsT extends Record<string, any>> {
68
90
  log.error("No workflowId found in activityInfo");
69
91
  throw new WorkflowParamNotFoundError(
70
92
  "workflowId",
71
- (this.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload).workflow,
93
+ (
94
+ this
95
+ .payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload
96
+ ).workflow,
72
97
  );
73
98
  }
74
99
  return workflowId;
@@ -102,7 +127,7 @@ export async function setupActivity<ParamsT extends Record<string, any>>(
102
127
  });
103
128
  }
104
129
 
105
- const client = getVertesiaClient(payload);
130
+ const client = await getVertesiaClient(payload);
106
131
  const fetchSpecs = payload.activity.fetch;
107
132
  if (fetchSpecs) {
108
133
  const keys = Object.keys(fetchSpecs);
@@ -118,7 +143,10 @@ export async function setupActivity<ParamsT extends Record<string, any>>(
118
143
 
119
144
  const provider = getFetchProvider(client, fetchSpec);
120
145
 
121
- log.info(`Fetching data for ${key} with provider ${provider.name}`, { fetchSpec });
146
+ log.info(
147
+ `Fetching data for ${key} with provider ${provider.name}`,
148
+ { fetchSpec },
149
+ );
122
150
  const result = await provider.fetch(fetchSpec);
123
151
  if (result && result.length > 0) {
124
152
  if (fetchSpec.limit === 1) {
@@ -127,7 +155,9 @@ export async function setupActivity<ParamsT extends Record<string, any>>(
127
155
  vars.setValue(key, result);
128
156
  }
129
157
  } else if (fetchSpec.on_not_found === "throw") {
130
- throw new DocumentNotFoundError("No documents found for: " + JSON.stringify(fetchSpec));
158
+ throw new DocumentNotFoundError(
159
+ "No documents found for: " + JSON.stringify(fetchSpec),
160
+ );
131
161
  } else {
132
162
  vars.setValue(key, null);
133
163
  }
@@ -141,7 +171,10 @@ export async function setupActivity<ParamsT extends Record<string, any>>(
141
171
  return new ActivityContext<ParamsT>(payload, client, params);
142
172
  }
143
173
 
144
- async function _fetchProject(client: VertesiaClient, payload: WorkflowExecutionPayload) {
174
+ async function _fetchProject(
175
+ client: VertesiaClient,
176
+ payload: WorkflowExecutionPayload,
177
+ ) {
145
178
  const project = await getProjectFromToken(payload.auth_token);
146
179
  return project ? await client.projects.retrieve(project.id) : undefined;
147
180
  }
@@ -159,7 +159,7 @@ describe('DSL Workflow with child workflows', () => {
159
159
  account_id: '123',
160
160
  project_id: '123',
161
161
  wf_rule_name: 'test',
162
- auth_token: 'test',
162
+ auth_token: process.env.VERTESIA_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature',
163
163
  config: {
164
164
  studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
165
165
  store_url: process.env.CP_STORE_URL || "http://localhost:8082",
@@ -203,7 +203,7 @@ describe('DSL Workflow with child workflows', () => {
203
203
  account_id: '123',
204
204
  project_id: '123',
205
205
  wf_rule_name: 'test',
206
- auth_token: 'test',
206
+ auth_token: process.env.VERTESIA_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature',
207
207
  config: {
208
208
  studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
209
209
  store_url: process.env.CP_STORE_URL || "http://localhost:8082",
@@ -247,7 +247,7 @@ describe('DSL Workflow with child workflows', () => {
247
247
  account_id: '123',
248
248
  project_id: '123',
249
249
  wf_rule_name: 'test',
250
- auth_token: 'test',
250
+ auth_token: process.env.VERTESIA_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature',
251
251
  config: {
252
252
  studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
253
253
  store_url: process.env.CP_STORE_URL || "http://localhost:8082",
@@ -107,7 +107,7 @@ describe('DSL Workflow', () => {
107
107
  project_id: '123',
108
108
  timestamp: Date.now(),
109
109
  wf_rule_name: 'test',
110
- auth_token: 'test',
110
+ auth_token: process.env.VERTESIA_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature',
111
111
  config: {
112
112
  studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
113
113
  store_url: process.env.CP_STORE_URL || "http://localhost:8082",
@@ -61,7 +61,7 @@ describe('DSL Workflow import vars', () => {
61
61
  project_id: '123',
62
62
  timestamp: Date.now(),
63
63
  wf_rule_name: 'test',
64
- auth_token: 'test',
64
+ auth_token: process.env.VERTESIA_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature',
65
65
  config: {
66
66
  studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
67
67
  store_url: process.env.CP_STORE_URL || "http://localhost:8082",
@@ -91,7 +91,7 @@ describe('DSL Workflow', () => {
91
91
  project_id: '123',
92
92
  timestamp: Date.now(),
93
93
  wf_rule_name: 'test',
94
- auth_token: 'test',
94
+ auth_token: process.env.VERTESIA_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature',
95
95
  config: {
96
96
  studio_url: process.env.CP_STUDIO_URL || "http://localhost:8081",
97
97
  store_url: process.env.CP_STORE_URL || "http://localhost:8082",
@@ -2,8 +2,16 @@ import { log } from "@temporalio/activity";
2
2
  import { WorkflowExecutionPayload } from "@vertesia/common";
3
3
  import { parse as parseYaml } from "yaml";
4
4
  import { getVertesiaClient } from "../../utils/client.js";
5
- import { buildAndPublishMemoryPack, loadMemoryPack } from "../../utils/memory.js";
6
- import { IterativeGenerationPayload, OutputMemoryMeta, Toc, TocIndex } from "../types.js";
5
+ import {
6
+ buildAndPublishMemoryPack,
7
+ loadMemoryPack,
8
+ } from "../../utils/memory.js";
9
+ import {
10
+ IterativeGenerationPayload,
11
+ OutputMemoryMeta,
12
+ Toc,
13
+ TocIndex,
14
+ } from "../types.js";
7
15
  import { tocIndex } from "../utils.js";
8
16
 
9
17
  /**
@@ -12,10 +20,12 @@ import { tocIndex } from "../utils.js";
12
20
  *
13
21
  * @param payload
14
22
  */
15
- export async function it_gen_extractToc(payload: WorkflowExecutionPayload): Promise<TocIndex | null> {
23
+ export async function it_gen_extractToc(
24
+ payload: WorkflowExecutionPayload,
25
+ ): Promise<TocIndex | null> {
16
26
  const vars = payload.vars as IterativeGenerationPayload;
17
27
  const memory = vars.memory;
18
- const client = getVertesiaClient(payload);
28
+ const client = await getVertesiaClient(payload);
19
29
 
20
30
  const inMemory = await loadMemoryPack(client, `${memory}/input`);
21
31
  let tocJson: string | null = null;
@@ -37,13 +47,17 @@ export async function it_gen_extractToc(payload: WorkflowExecutionPayload): Prom
37
47
 
38
48
  log.info(`Found a TOC in the input memory pack`);
39
49
 
40
- await buildAndPublishMemoryPack(client, `${vars.memory}/output`, async () => {
41
- return {
42
- toc,
43
- lastProcessedPart: undefined, // the part index (a number array)
44
- previouslyGenerated: ""
45
- } as OutputMemoryMeta
46
- });
50
+ await buildAndPublishMemoryPack(
51
+ client,
52
+ `${vars.memory}/output`,
53
+ async () => {
54
+ return {
55
+ toc,
56
+ lastProcessedPart: undefined, // the part index (a number array)
57
+ previouslyGenerated: "",
58
+ } as OutputMemoryMeta;
59
+ },
60
+ );
47
61
 
48
62
  return tocIndex(toc);
49
- }
63
+ }
@@ -2,14 +2,24 @@ import { log } from "@temporalio/activity";
2
2
  import { WorkflowExecutionPayload } from "@vertesia/common";
3
3
  import { getVertesiaClient } from "../../utils/client.js";
4
4
  import { expandVars } from "../../utils/expand-vars.js";
5
- import { buildAndPublishMemoryPack, loadMemoryPack } from "../../utils/memory.js";
6
- import { IterativeGenerationPayload, Section, SECTION_ID_PLACEHOLDER, TocSection } from "../types.js";
5
+ import {
6
+ buildAndPublishMemoryPack,
7
+ loadMemoryPack,
8
+ } from "../../utils/memory.js";
9
+ import {
10
+ IterativeGenerationPayload,
11
+ Section,
12
+ SECTION_ID_PLACEHOLDER,
13
+ TocSection,
14
+ } from "../types.js";
7
15
 
8
- export async function it_gen_finalizeOutput(payload: WorkflowExecutionPayload): Promise<string> {
16
+ export async function it_gen_finalizeOutput(
17
+ payload: WorkflowExecutionPayload,
18
+ ): Promise<string> {
9
19
  const vars = payload.vars as IterativeGenerationPayload;
10
20
 
11
21
  const memory = vars.memory;
12
- const client = getVertesiaClient(payload);
22
+ const client = await getVertesiaClient(payload);
13
23
  const inMemory = await loadMemoryPack(client, `${memory}/input`);
14
24
  const outMemory = await loadMemoryPack(client, `${memory}/output`);
15
25
 
@@ -35,43 +45,56 @@ export async function it_gen_finalizeOutput(payload: WorkflowExecutionPayload):
35
45
  }
36
46
  const sections = JSON.parse(content) as Section[];
37
47
 
38
- await buildAndPublishMemoryPack(client, `${memory}/output`, async ({ copyText }) => {
39
- // copy the input toc file if any
40
- if (toc) {
41
- copyText(toc, tocName);
42
- }
43
- // copy the raw JSON content
44
- copyText(content, "content.json");
45
- if (vars.section_file_pattern) {
46
- log.info(`Saving sections to files using pattern: ${vars.section_file_pattern}`);
47
- // save sections to files
48
- for (const section of sections) {
49
- let content = section.content;
50
- if (vars.section_file_header) {
51
- content = getSectionFileHeader(section, vars.section_file_header) + '\n\n' + content;
48
+ await buildAndPublishMemoryPack(
49
+ client,
50
+ `${memory}/output`,
51
+ async ({ copyText }) => {
52
+ // copy the input toc file if any
53
+ if (toc) {
54
+ copyText(toc, tocName);
55
+ }
56
+ // copy the raw JSON content
57
+ copyText(content, "content.json");
58
+ if (vars.section_file_pattern) {
59
+ log.info(
60
+ `Saving sections to files using pattern: ${vars.section_file_pattern}`,
61
+ );
62
+ // save sections to files
63
+ for (const section of sections) {
64
+ let content = section.content;
65
+ if (vars.section_file_header) {
66
+ content =
67
+ getSectionFileHeader(
68
+ section,
69
+ vars.section_file_header,
70
+ ) +
71
+ "\n\n" +
72
+ content;
73
+ }
74
+ copyText(
75
+ content,
76
+ getSectionFileName(section, vars.section_file_pattern),
77
+ );
52
78
  }
53
- copyText(content, getSectionFileName(section, vars.section_file_pattern));
54
79
  }
55
- }
56
- return {
57
- ...inMeta,
58
- vars
59
- };
60
- });
80
+ return {
81
+ ...inMeta,
82
+ vars,
83
+ };
84
+ },
85
+ );
61
86
 
62
87
  return `Processing done. Extracted files to: ${vars.section_file_pattern}`;
63
88
  }
64
89
 
65
-
66
-
67
90
  function getSectionFileHeader(section: TocSection, header: string): string {
68
91
  const date = new Date().toISOString();
69
92
  return expandVars(header, {
70
93
  section,
71
- date
94
+ date,
72
95
  });
73
96
  }
74
97
 
75
98
  function getSectionFileName(section: TocSection, pattern: string): string {
76
99
  return pattern.replace(SECTION_ID_PLACEHOLDER, section.id);
77
- }
100
+ }