@vertesia/workflow 0.79.0 → 0.80.0-dev-20251118
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/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js +3 -4
- package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -1
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +10 -4
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -1
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js +3 -4
- package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -1
- package/lib/cjs/activities/chunkDocument.js +1 -2
- package/lib/cjs/activities/chunkDocument.js.map +1 -1
- package/lib/cjs/activities/executeInteraction.js +5 -4
- package/lib/cjs/activities/executeInteraction.js.map +1 -1
- package/lib/cjs/activities/generateDocumentProperties.js +2 -3
- package/lib/cjs/activities/generateDocumentProperties.js.map +1 -1
- package/lib/cjs/activities/generateOrAssignContentType.js +2 -3
- package/lib/cjs/activities/generateOrAssignContentType.js.map +1 -1
- package/lib/cjs/activities/index-dsl.js +3 -1
- package/lib/cjs/activities/index-dsl.js.map +1 -1
- package/lib/cjs/activities/media/prepareVideo.js +429 -0
- package/lib/cjs/activities/media/prepareVideo.js.map +1 -0
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js +48 -15
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +1 -1
- package/lib/cjs/activities/notifyWebhook.js +2 -1
- package/lib/cjs/activities/notifyWebhook.js.map +1 -1
- package/lib/cjs/dsl/dsl-workflow.js +6 -1
- package/lib/cjs/dsl/dsl-workflow.js.map +1 -1
- package/lib/cjs/dsl/setup/ActivityContext.js +7 -4
- package/lib/cjs/dsl/setup/ActivityContext.js.map +1 -1
- package/lib/cjs/errors.js +14 -1
- package/lib/cjs/errors.js.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/iterative-generation/activities/extractToc.js +2 -2
- package/lib/cjs/iterative-generation/activities/extractToc.js.map +1 -1
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js +7 -4
- package/lib/cjs/iterative-generation/activities/finalizeOutput.js.map +1 -1
- package/lib/cjs/iterative-generation/activities/generatePart.js +18 -14
- package/lib/cjs/iterative-generation/activities/generatePart.js.map +1 -1
- package/lib/cjs/iterative-generation/activities/generateToc.js +46 -56
- package/lib/cjs/iterative-generation/activities/generateToc.js.map +1 -1
- package/lib/cjs/iterative-generation/utils.js.map +1 -1
- package/lib/cjs/utils/blobs.js +4 -1
- package/lib/cjs/utils/blobs.js.map +1 -1
- package/lib/cjs/utils/client.js +3 -1
- package/lib/cjs/utils/client.js.map +1 -1
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js +3 -4
- package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -1
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +10 -4
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -1
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js +3 -4
- package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -1
- package/lib/esm/activities/chunkDocument.js +1 -2
- package/lib/esm/activities/chunkDocument.js.map +1 -1
- package/lib/esm/activities/executeInteraction.js +5 -4
- package/lib/esm/activities/executeInteraction.js.map +1 -1
- package/lib/esm/activities/generateDocumentProperties.js +2 -3
- package/lib/esm/activities/generateDocumentProperties.js.map +1 -1
- package/lib/esm/activities/generateOrAssignContentType.js +2 -3
- package/lib/esm/activities/generateOrAssignContentType.js.map +1 -1
- package/lib/esm/activities/index-dsl.js +1 -0
- package/lib/esm/activities/index-dsl.js.map +1 -1
- package/lib/esm/activities/media/prepareVideo.js +390 -0
- package/lib/esm/activities/media/prepareVideo.js.map +1 -0
- package/lib/esm/activities/media/transcribeMediaWithGladia.js +50 -17
- package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +1 -1
- package/lib/esm/activities/notifyWebhook.js +2 -1
- package/lib/esm/activities/notifyWebhook.js.map +1 -1
- package/lib/esm/dsl/dsl-workflow.js +6 -1
- package/lib/esm/dsl/dsl-workflow.js.map +1 -1
- package/lib/esm/dsl/setup/ActivityContext.js +10 -7
- package/lib/esm/dsl/setup/ActivityContext.js.map +1 -1
- package/lib/esm/errors.js +12 -0
- package/lib/esm/errors.js.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/iterative-generation/activities/extractToc.js +3 -3
- package/lib/esm/iterative-generation/activities/extractToc.js.map +1 -1
- package/lib/esm/iterative-generation/activities/finalizeOutput.js +9 -6
- package/lib/esm/iterative-generation/activities/finalizeOutput.js.map +1 -1
- package/lib/esm/iterative-generation/activities/generatePart.js +19 -15
- package/lib/esm/iterative-generation/activities/generatePart.js.map +1 -1
- package/lib/esm/iterative-generation/activities/generateToc.js +46 -56
- package/lib/esm/iterative-generation/activities/generateToc.js.map +1 -1
- package/lib/esm/iterative-generation/utils.js.map +1 -1
- package/lib/esm/utils/blobs.js +4 -1
- package/lib/esm/utils/blobs.js.map +1 -1
- package/lib/esm/utils/client.js +4 -2
- package/lib/esm/utils/client.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts.map +1 -1
- package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts.map +1 -1
- package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts.map +1 -1
- package/lib/types/activities/chunkDocument.d.ts.map +1 -1
- package/lib/types/activities/executeInteraction.d.ts +1 -1
- package/lib/types/activities/executeInteraction.d.ts.map +1 -1
- package/lib/types/activities/generateDocumentProperties.d.ts.map +1 -1
- package/lib/types/activities/generateOrAssignContentType.d.ts.map +1 -1
- package/lib/types/activities/index-dsl.d.ts +1 -0
- package/lib/types/activities/index-dsl.d.ts.map +1 -1
- package/lib/types/activities/media/prepareVideo.d.ts +30 -0
- package/lib/types/activities/media/prepareVideo.d.ts.map +1 -0
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +1 -1
- package/lib/types/dsl/dsl-workflow.d.ts.map +1 -1
- package/lib/types/dsl/setup/ActivityContext.d.ts.map +1 -1
- package/lib/types/errors.d.ts +6 -0
- package/lib/types/errors.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/iterative-generation/activities/extractToc.d.ts.map +1 -1
- package/lib/types/iterative-generation/activities/finalizeOutput.d.ts.map +1 -1
- package/lib/types/iterative-generation/activities/generatePart.d.ts.map +1 -1
- package/lib/types/iterative-generation/activities/generateToc.d.ts.map +1 -1
- package/lib/types/iterative-generation/utils.d.ts +3 -4
- package/lib/types/iterative-generation/utils.d.ts.map +1 -1
- package/lib/types/utils/blobs.d.ts.map +1 -1
- package/lib/types/utils/client.d.ts +2 -6
- package/lib/types/utils/client.d.ts.map +1 -1
- package/lib/workflows-bundle.js +9494 -6518
- package/package.json +127 -127
- package/src/activities/advanced/createDocumentTypeFromInteractionRun.ts +4 -6
- package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +10 -4
- package/src/activities/advanced/updateDocumentFromInteractionRun.ts +3 -5
- package/src/activities/chunkDocument.ts +1 -2
- package/src/activities/executeInteraction.ts +13 -11
- package/src/activities/generateDocumentProperties.ts +2 -3
- package/src/activities/generateOrAssignContentType.ts +2 -3
- package/src/activities/index-dsl.ts +1 -0
- package/src/activities/media/prepareVideo.ts +622 -0
- package/src/activities/media/transcribeMediaWithGladia.ts +52 -21
- package/src/activities/notifyWebhook.test.ts +1 -1
- package/src/activities/notifyWebhook.ts +2 -1
- package/src/dsl/dsl-workflow.ts +7 -1
- package/src/dsl/setup/ActivityContext.ts +45 -12
- package/src/dsl/workflow-exec-child.test.ts +3 -3
- package/src/dsl/workflow-fetch.test.ts +1 -1
- package/src/dsl/workflow-import.test.ts +1 -1
- package/src/dsl/workflow.test.ts +1 -1
- package/src/errors.ts +15 -0
- package/src/index.ts +1 -0
- package/src/iterative-generation/activities/extractToc.ts +26 -12
- package/src/iterative-generation/activities/finalizeOutput.ts +52 -29
- package/src/iterative-generation/activities/generatePart.ts +65 -25
- package/src/iterative-generation/activities/generateToc.ts +79 -67
- package/src/iterative-generation/utils.ts +4 -5
- package/src/utils/blobs.ts +3 -1
- package/src/utils/client.ts +22 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DSLActivityExecutionPayload, DSLActivitySpec, GladiaConfiguration, SupportedIntegrations } from "@vertesia/common";
|
|
1
|
+
import { DSLActivityExecutionPayload, DSLActivitySpec, GladiaConfiguration, SupportedIntegrations, AUDIO_RENDITION_NAME, VideoMetadata, ContentNature } from "@vertesia/common";
|
|
2
2
|
import { activityInfo, CompleteAsyncError, log } from "@temporalio/activity";
|
|
3
|
-
import { FetchClient } from "@vertesia/api-fetch-client";
|
|
3
|
+
import { FetchClient, RequestError } from "@vertesia/api-fetch-client";
|
|
4
4
|
import { setupActivity } from "../../dsl/setup/ActivityContext.js";
|
|
5
5
|
import { DocumentNotFoundError } from "../../errors.js";
|
|
6
6
|
import { TextExtractionResult, TextExtractionStatus } from "../../index.js";
|
|
@@ -27,7 +27,12 @@ export async function transcribeMedia(payload: DSLActivityExecutionPayload<Trans
|
|
|
27
27
|
|
|
28
28
|
const gladiaConfig = await client.projects.integrations.retrieve(payload.project_id, SupportedIntegrations.gladia) as GladiaConfiguration | undefined;
|
|
29
29
|
if (!gladiaConfig || !gladiaConfig.enabled) {
|
|
30
|
-
|
|
30
|
+
return {
|
|
31
|
+
hasText: false,
|
|
32
|
+
objectId,
|
|
33
|
+
status: TextExtractionStatus.error,
|
|
34
|
+
error: "Gladia integration not enabled",
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
const object = await client.objects.retrieve(objectId, "+text");
|
|
@@ -42,37 +47,63 @@ export async function transcribeMedia(payload: DSLActivityExecutionPayload<Trans
|
|
|
42
47
|
throw new DocumentNotFoundError(`No source found for object ${objectId}`);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
// Check for audio rendition in video metadata (preferred for videos)
|
|
51
|
+
let mediaSource: string = object.content.source;
|
|
52
|
+
if (object.metadata?.type === ContentNature.Video) {
|
|
53
|
+
const videoMetadata = object.metadata as VideoMetadata;
|
|
54
|
+
const audioRendition = videoMetadata.renditions?.find(r => r.name === AUDIO_RENDITION_NAME);
|
|
55
|
+
if (audioRendition?.content?.source) {
|
|
56
|
+
mediaSource = audioRendition.content.source;
|
|
57
|
+
log.info(`Found audio rendition for video object ${objectId}`, { mediaSource });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Get download URL for the media source
|
|
62
|
+
const { url: mediaUrl } = await client.files.getDownloadUrl(mediaSource);
|
|
46
63
|
|
|
47
64
|
if (!mediaUrl) {
|
|
48
|
-
throw new DocumentNotFoundError(`Error fetching
|
|
65
|
+
throw new DocumentNotFoundError(`Error fetching media URL for ${mediaSource}`);
|
|
49
66
|
}
|
|
50
67
|
|
|
68
|
+
log.info(`Using media URL for transcription`, { objectId, mediaUrl: mediaSource });
|
|
69
|
+
|
|
51
70
|
const taskToken = Buffer.from(activityInfo().taskToken).toString('base64url');
|
|
52
71
|
const callbackUrl = generateCallbackUrlForGladia(client.store.baseUrl, payload.auth_token, taskToken, objectId);
|
|
53
72
|
|
|
54
73
|
log.info(`Transcribing media ${mediaUrl} with Gladia`, { objectId, callbackUrl });
|
|
55
74
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
try {
|
|
76
|
+
const res = await gladiaClient.post("/transcription", {
|
|
77
|
+
payload: {
|
|
78
|
+
audio_url: mediaUrl,
|
|
79
|
+
callback_url: callbackUrl,
|
|
80
|
+
diarization_enhanced: true,
|
|
81
|
+
enable_code_switching: true,
|
|
82
|
+
subtitles: true,
|
|
83
|
+
subtitles_config: {
|
|
84
|
+
formats: ["vtt"],
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}) as GladiaTranscriptRequestResponse;
|
|
88
|
+
|
|
89
|
+
log.info(`Transcription request sent to Gladia`, { objectId, res });
|
|
90
|
+
throw new CompleteAsyncError();
|
|
91
|
+
|
|
92
|
+
} catch (error: any) {
|
|
93
|
+
if (error instanceof RequestError && error.status === 422) {
|
|
94
|
+
return {
|
|
95
|
+
hasText: false,
|
|
96
|
+
objectId,
|
|
97
|
+
status: TextExtractionStatus.error,
|
|
98
|
+
error: `Gladia transcription error: ${error.message}`,
|
|
65
99
|
}
|
|
100
|
+
} else {
|
|
101
|
+
log.error(`Error sending transcription request to Gladia for object ${objectId}`, { error });
|
|
102
|
+
throw error;
|
|
66
103
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
log.info(`Transcription request sent to Gladia`, { objectId, res });
|
|
70
|
-
|
|
71
|
-
throw new CompleteAsyncError();
|
|
72
|
-
|
|
104
|
+
}
|
|
73
105
|
}
|
|
74
106
|
|
|
75
|
-
|
|
76
107
|
function generateCallbackUrlForGladia(baseUrl: string, authToken: string, taskToken: string, objectId: string) {
|
|
77
108
|
return `${baseUrl}/api/v1/webhooks/gladia/${objectId}?access_token=${authToken}&task_token=${taskToken}`;
|
|
78
109
|
}
|
|
@@ -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: "
|
|
36
|
+
auth_token: process.env.VERTESIA_KEY || "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbW9jay10b2tlbi1zZXJ2ZXIiLCJzdWIiOiJ0ZXN0In0.signature",
|
|
37
37
|
account_id: "unset",
|
|
38
38
|
project_id: "unset",
|
|
39
39
|
params: mergedParams,
|
|
@@ -180,7 +180,8 @@ async function createOldRequestBody(payload: WorkflowExecutionBaseParams, params
|
|
|
180
180
|
let data = params.detail;
|
|
181
181
|
if (data && data.run_id && params.event_name === "workflow_completed" && params.workflow_type === 'ExecuteInteractionWorkflow') {
|
|
182
182
|
const client = getVersionedVertesiaClient(payload, null); //ensure client is using no specific version
|
|
183
|
-
|
|
183
|
+
// Important Note: we cannot use client.runs.retrieve since it will transform the run result to the new format because of InteractionOutput
|
|
184
|
+
const run = await client.runs.get(data.run_id);
|
|
184
185
|
// since we use an unversioned client the run will be in old format so we don't need to tranform the result
|
|
185
186
|
const result = run.result;
|
|
186
187
|
data = {
|
package/src/dsl/dsl-workflow.ts
CHANGED
|
@@ -225,7 +225,13 @@ async function executeChildWorkflow(step: DSLChildWorkflowStep, payload: DSLWork
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
function buildRateLimitParams(activity: DSLActivitySpec, executionPayload: DSLActivityExecutionPayload<any>): RateLimitParams {
|
|
228
|
-
|
|
228
|
+
// resolve payload params
|
|
229
|
+
const vars = new Vars({
|
|
230
|
+
...executionPayload.params, // imported params (doesn't contain expressions)
|
|
231
|
+
...executionPayload.activity.params, // activity params (may contain expressions)
|
|
232
|
+
});
|
|
233
|
+
const params = vars.resolve();
|
|
234
|
+
|
|
229
235
|
let interactionId: string;
|
|
230
236
|
|
|
231
237
|
switch (activity.name) {
|
|
@@ -6,16 +6,32 @@ import {
|
|
|
6
6
|
Project,
|
|
7
7
|
WorkflowExecutionPayload,
|
|
8
8
|
} from "@vertesia/common";
|
|
9
|
-
import {
|
|
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 {
|
|
14
|
-
|
|
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(
|
|
18
|
-
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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(
|
|
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(
|
|
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(
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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",
|
package/src/dsl/workflow.test.ts
CHANGED
|
@@ -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: '
|
|
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",
|
package/src/errors.ts
CHANGED
|
@@ -64,9 +64,24 @@ export class ResourceExhaustedError extends ApplicationFailure {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export class InvalidContentTypeError extends ApplicationFailure {
|
|
68
|
+
constructor(
|
|
69
|
+
public objectId: string,
|
|
70
|
+
public expectedType: string,
|
|
71
|
+
public actualType: string,
|
|
72
|
+
) {
|
|
73
|
+
super(
|
|
74
|
+
`Document ${objectId} has invalid content type. Expected ${expectedType}, got ${actualType}`,
|
|
75
|
+
"InvalidContentTypeError",
|
|
76
|
+
true, // non-retryable
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
export const WF_NON_RETRYABLE_ERRORS = [
|
|
68
82
|
"DocumentNotFoundError",
|
|
69
83
|
"ActivityParamInvalidError",
|
|
70
84
|
"ActivityParamNotFoundError",
|
|
71
85
|
"WorkflowParamNotFoundError",
|
|
86
|
+
"InvalidContentTypeError",
|
|
72
87
|
];
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from "./activities/notifyWebhook.js";
|
|
|
25
25
|
export * from "./activities/rateLimiter.js";
|
|
26
26
|
export * from "./activities/setDocumentStatus.js";
|
|
27
27
|
export * from "./iterative-generation/activities/index.js";
|
|
28
|
+
export * from "./activities/media/prepareVideo.js";
|
|
28
29
|
|
|
29
30
|
export * from "./dsl/setup/ActivityContext.js";
|
|
30
31
|
export * from "./errors.js";
|
|
@@ -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 {
|
|
6
|
-
|
|
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(
|
|
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(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 {
|
|
6
|
-
|
|
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(
|
|
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(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
}
|