@vertesia/workflow 1.0.0-dev.20260128.144200 → 1.0.0-dev.20260225.024852Z
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/createOrUpdateDocumentFromInteractionRun.js +1 -1
- package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -1
- package/lib/cjs/activities/chunkDocument.js +3 -1
- package/lib/cjs/activities/chunkDocument.js.map +1 -1
- package/lib/cjs/activities/extractDocumentText.js +56 -16
- package/lib/cjs/activities/extractDocumentText.js.map +1 -1
- package/lib/cjs/activities/generateDocumentProperties.js +4 -2
- package/lib/cjs/activities/generateDocumentProperties.js.map +1 -1
- package/lib/cjs/activities/generateEmbeddings.js +20 -10
- package/lib/cjs/activities/generateEmbeddings.js.map +1 -1
- package/lib/cjs/activities/generateOrAssignContentType.js +2 -2
- package/lib/cjs/activities/generateOrAssignContentType.js.map +1 -1
- package/lib/cjs/activities/index-dsl.js +7 -7
- package/lib/cjs/activities/index-dsl.js.map +1 -1
- package/lib/cjs/activities/media/saveGladiaTranscription.js +38 -24
- package/lib/cjs/activities/media/saveGladiaTranscription.js.map +1 -1
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js +41 -24
- package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +1 -1
- package/lib/cjs/activities/notifyWebhook.js +11 -2
- package/lib/cjs/activities/notifyWebhook.js.map +1 -1
- package/lib/cjs/activities/renditions/generateImageRendition.js +2 -2
- package/lib/cjs/activities/renditions/generateImageRendition.js.map +1 -1
- package/lib/cjs/activities/setDocumentStatus.js +13 -2
- package/lib/cjs/activities/setDocumentStatus.js.map +1 -1
- package/lib/cjs/conversion/image.js +10 -10
- package/lib/cjs/conversion/image.js.map +1 -1
- package/lib/cjs/dsl/dsl-workflow.js +44 -7
- package/lib/cjs/dsl/dsl-workflow.js.map +1 -1
- package/lib/cjs/dsl/setup/ActivityContext.js +56 -0
- package/lib/cjs/dsl/setup/ActivityContext.js.map +1 -1
- package/lib/cjs/errors.js +11 -1
- package/lib/cjs/errors.js.map +1 -1
- package/lib/cjs/index.js +6 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/result-types.js.map +1 -1
- package/lib/cjs/utils/renditions.js +9 -5
- package/lib/cjs/utils/renditions.js.map +1 -1
- package/lib/cjs/utils/text-preview-utils.js +43 -0
- package/lib/cjs/utils/text-preview-utils.js.map +1 -0
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +1 -1
- package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -1
- package/lib/esm/activities/chunkDocument.js +3 -1
- package/lib/esm/activities/chunkDocument.js.map +1 -1
- package/lib/esm/activities/extractDocumentText.js +56 -16
- package/lib/esm/activities/extractDocumentText.js.map +1 -1
- package/lib/esm/activities/generateDocumentProperties.js +4 -2
- package/lib/esm/activities/generateDocumentProperties.js.map +1 -1
- package/lib/esm/activities/generateEmbeddings.js +20 -10
- package/lib/esm/activities/generateEmbeddings.js.map +1 -1
- package/lib/esm/activities/generateOrAssignContentType.js +2 -2
- package/lib/esm/activities/generateOrAssignContentType.js.map +1 -1
- package/lib/esm/activities/index-dsl.js +3 -3
- package/lib/esm/activities/index-dsl.js.map +1 -1
- package/lib/esm/activities/media/saveGladiaTranscription.js +38 -24
- package/lib/esm/activities/media/saveGladiaTranscription.js.map +1 -1
- package/lib/esm/activities/media/transcribeMediaWithGladia.js +41 -24
- package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +1 -1
- package/lib/esm/activities/notifyWebhook.js +11 -2
- package/lib/esm/activities/notifyWebhook.js.map +1 -1
- package/lib/esm/activities/renditions/generateImageRendition.js +2 -2
- package/lib/esm/activities/renditions/generateImageRendition.js.map +1 -1
- package/lib/esm/activities/setDocumentStatus.js +13 -2
- package/lib/esm/activities/setDocumentStatus.js.map +1 -1
- package/lib/esm/conversion/image.js +10 -10
- package/lib/esm/conversion/image.js.map +1 -1
- package/lib/esm/dsl/dsl-workflow.js +44 -7
- package/lib/esm/dsl/dsl-workflow.js.map +1 -1
- package/lib/esm/dsl/setup/ActivityContext.js +57 -1
- package/lib/esm/dsl/setup/ActivityContext.js.map +1 -1
- package/lib/esm/errors.js +9 -0
- package/lib/esm/errors.js.map +1 -1
- package/lib/esm/index.js +6 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/result-types.js.map +1 -1
- package/lib/esm/utils/renditions.js +9 -5
- package/lib/esm/utils/renditions.js.map +1 -1
- package/lib/esm/utils/text-preview-utils.js +38 -0
- package/lib/esm/utils/text-preview-utils.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/activities/chunkDocument.d.ts.map +1 -1
- package/lib/types/activities/extractDocumentText.d.ts +1 -0
- package/lib/types/activities/extractDocumentText.d.ts.map +1 -1
- package/lib/types/activities/generateDocumentProperties.d.ts.map +1 -1
- package/lib/types/activities/generateEmbeddings.d.ts.map +1 -1
- package/lib/types/activities/index-dsl.d.ts +3 -3
- package/lib/types/activities/index-dsl.d.ts.map +1 -1
- package/lib/types/activities/media/saveGladiaTranscription.d.ts +1 -0
- package/lib/types/activities/media/saveGladiaTranscription.d.ts.map +1 -1
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts +1 -0
- package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +1 -1
- package/lib/types/activities/setDocumentStatus.d.ts +1 -1
- package/lib/types/activities/setDocumentStatus.d.ts.map +1 -1
- package/lib/types/dsl/dsl-workflow.d.ts.map +1 -1
- package/lib/types/dsl/setup/ActivityContext.d.ts +32 -2
- package/lib/types/dsl/setup/ActivityContext.d.ts.map +1 -1
- package/lib/types/errors.d.ts +4 -0
- package/lib/types/errors.d.ts.map +1 -1
- package/lib/types/index.d.ts +6 -5
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/result-types.d.ts +5 -1
- package/lib/types/result-types.d.ts.map +1 -1
- package/lib/types/utils/renditions.d.ts +2 -0
- package/lib/types/utils/renditions.d.ts.map +1 -1
- package/lib/types/utils/text-preview-utils.d.ts +15 -0
- package/lib/types/utils/text-preview-utils.d.ts.map +1 -0
- package/lib/workflows-bundle.js +11747 -11141
- package/package.json +6 -7
- package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +1 -1
- package/src/activities/chunkDocument.ts +3 -1
- package/src/activities/extractDocumentText.ts +85 -26
- package/src/activities/generateDocumentProperties.ts +4 -2
- package/src/activities/generateEmbeddings.ts +22 -14
- package/src/activities/generateOrAssignContentType.ts +2 -2
- package/src/activities/index-dsl.ts +4 -3
- package/src/activities/media/saveGladiaTranscription.test.ts +406 -0
- package/src/activities/media/saveGladiaTranscription.ts +41 -26
- package/src/activities/media/transcribeMediaWithGladia.test.ts +583 -0
- package/src/activities/media/transcribeMediaWithGladia.ts +46 -25
- package/src/activities/notifyWebhook.test.ts +121 -8
- package/src/activities/notifyWebhook.ts +10 -2
- package/src/activities/renditions/generateImageRendition.ts +2 -2
- package/src/activities/setDocumentStatus.ts +12 -4
- package/src/conversion/image.test.ts +1 -0
- package/src/conversion/image.ts +10 -10
- package/src/dsl/dsl-workflow.ts +57 -9
- package/src/dsl/setup/ActivityContext.ts +73 -0
- package/src/dsl.ts +1 -0
- package/src/errors.ts +15 -0
- package/src/index.ts +6 -5
- package/src/result-types.ts +5 -1
- package/src/utils/renditions.ts +11 -5
- package/src/utils/text-preview-utils.ts +62 -0
|
@@ -5,10 +5,13 @@ import {
|
|
|
5
5
|
DSLWorkflowExecutionPayload,
|
|
6
6
|
Project,
|
|
7
7
|
WorkflowExecutionPayload,
|
|
8
|
+
WorkflowInputType,
|
|
9
|
+
WorkflowInputFile,
|
|
8
10
|
} from "@vertesia/common";
|
|
9
11
|
import {
|
|
10
12
|
DocumentNotFoundError,
|
|
11
13
|
WorkflowParamNotFoundError,
|
|
14
|
+
WorkflowExecutionError,
|
|
12
15
|
} from "../../errors.js";
|
|
13
16
|
import { getProjectFromToken } from "../../utils/auth.js";
|
|
14
17
|
import { getVertesiaClient } from "../../utils/client.js";
|
|
@@ -99,6 +102,76 @@ export class ActivityContext<ParamsT extends Record<string, any>> {
|
|
|
99
102
|
return workflowId;
|
|
100
103
|
}
|
|
101
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Get the workflow input type (objectIds or files).
|
|
107
|
+
* Defaults to 'objectIds' for backward compatibility with legacy format.
|
|
108
|
+
*/
|
|
109
|
+
get inputType(): WorkflowInputType {
|
|
110
|
+
return this.payload.input?.inputType || 'objectIds';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get the first file from the workflow input.
|
|
115
|
+
* Only available when workflow input type is 'files'.
|
|
116
|
+
* @throws {WorkflowExecutionError} If input type is not 'files'
|
|
117
|
+
* @throws {WorkflowParamNotFoundError} If files array is empty
|
|
118
|
+
*/
|
|
119
|
+
get file(): WorkflowInputFile {
|
|
120
|
+
const input = this.payload.input;
|
|
121
|
+
if (!input || input.inputType !== 'files') {
|
|
122
|
+
throw new WorkflowExecutionError(
|
|
123
|
+
'Activity expects files but received objectIds'
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
// TypeScript now knows input is { inputType: 'files', files: WorkflowInputFile[] }
|
|
127
|
+
const files = input.files;
|
|
128
|
+
if (!files || files.length === 0) {
|
|
129
|
+
log.error("No files found in payload");
|
|
130
|
+
throw new WorkflowParamNotFoundError(
|
|
131
|
+
"files[0]",
|
|
132
|
+
(
|
|
133
|
+
this
|
|
134
|
+
.payload as WorkflowExecutionPayload as DSLWorkflowExecutionPayload
|
|
135
|
+
).workflow,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return files[0];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get all files from the workflow input.
|
|
143
|
+
* Only available when workflow input type is 'files'.
|
|
144
|
+
* @throws {WorkflowExecutionError} If input type is not 'files'
|
|
145
|
+
*/
|
|
146
|
+
get files(): WorkflowInputFile[] {
|
|
147
|
+
const input = this.payload.input;
|
|
148
|
+
if (!input || input.inputType !== 'files') {
|
|
149
|
+
throw new WorkflowExecutionError(
|
|
150
|
+
'Activity expects files but received objectIds'
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
// TypeScript now knows input is { inputType: 'files', files: WorkflowInputFile[] }
|
|
154
|
+
return input.files;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Generic accessor for the first input (objectId or file URL).
|
|
159
|
+
* Use this in dual-mode activities that support both input types.
|
|
160
|
+
* For files, returns the URL of the first file.
|
|
161
|
+
*/
|
|
162
|
+
get input(): string {
|
|
163
|
+
return this.inputType === 'objectIds' ? this.objectId : this.file.url;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Generic accessor for all inputs (objectIds or file URLs).
|
|
168
|
+
* Use this in dual-mode activities that support both input types.
|
|
169
|
+
* For files, returns an array of URLs.
|
|
170
|
+
*/
|
|
171
|
+
get inputs(): string[] {
|
|
172
|
+
return this.inputType === 'objectIds' ? (this.objectIds || []) : this.files.map(f => f.url);
|
|
173
|
+
}
|
|
174
|
+
|
|
102
175
|
fetchProject() {
|
|
103
176
|
if (!this._project) {
|
|
104
177
|
this._project = _fetchProject(this.client, this.payload);
|
package/src/dsl.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -91,6 +91,19 @@ export class TokenExpiredError extends ApplicationFailure {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
export class WorkflowExecutionError extends ApplicationFailure {
|
|
95
|
+
constructor(
|
|
96
|
+
message: string,
|
|
97
|
+
public workflow?: DSLWorkflowSpec,
|
|
98
|
+
) {
|
|
99
|
+
super(
|
|
100
|
+
message,
|
|
101
|
+
"WorkflowExecutionError",
|
|
102
|
+
true, // non-retryable
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
94
107
|
export const WF_NON_RETRYABLE_ERRORS = [
|
|
95
108
|
"DocumentNotFoundError",
|
|
96
109
|
"ActivityParamInvalidError",
|
|
@@ -98,4 +111,6 @@ export const WF_NON_RETRYABLE_ERRORS = [
|
|
|
98
111
|
"WorkflowParamNotFoundError",
|
|
99
112
|
"InvalidContentTypeError",
|
|
100
113
|
"TokenExpiredError",
|
|
114
|
+
"ZenoClientNotFoundError",
|
|
115
|
+
"WorkflowExecutionError",
|
|
101
116
|
];
|
package/src/index.ts
CHANGED
|
@@ -18,15 +18,15 @@ export * from "./activities/executeInteraction.js";
|
|
|
18
18
|
export * from "./activities/extractDocumentText.js";
|
|
19
19
|
export * from "./activities/generateDocumentProperties.js";
|
|
20
20
|
export * from "./activities/generateEmbeddings.js";
|
|
21
|
-
export * from "./activities/renditions/generateImageRendition.js";
|
|
22
|
-
export * from "./activities/renditions/generateVideoRendition.js";
|
|
23
21
|
export * from "./activities/generateOrAssignContentType.js";
|
|
22
|
+
export * from "./activities/media/prepareAudio.js";
|
|
23
|
+
export * from "./activities/media/prepareVideo.js";
|
|
24
24
|
export * from "./activities/notifyWebhook.js";
|
|
25
25
|
export * from "./activities/rateLimiter.js";
|
|
26
|
+
export * from "./activities/renditions/generateImageRendition.js";
|
|
27
|
+
export * from "./activities/renditions/generateVideoRendition.js";
|
|
26
28
|
export * from "./activities/setDocumentStatus.js";
|
|
27
29
|
export * from "./iterative-generation/activities/index.js";
|
|
28
|
-
export * from "./activities/media/prepareVideo.js";
|
|
29
|
-
export * from "./activities/media/prepareAudio.js";
|
|
30
30
|
|
|
31
31
|
export * from "./dsl/setup/ActivityContext.js";
|
|
32
32
|
export * from "./errors.js";
|
|
@@ -34,8 +34,9 @@ export * from "./result-types.js";
|
|
|
34
34
|
export * from "./utils/blobs.js";
|
|
35
35
|
export * from "./utils/client.js";
|
|
36
36
|
export * from "./utils/memory.js";
|
|
37
|
-
export * from "./utils/tokens.js";
|
|
38
37
|
export * from "./utils/renditions.js";
|
|
39
38
|
export * from "./utils/storage.js";
|
|
39
|
+
export * from "./utils/text-preview-utils.js";
|
|
40
|
+
export * from "./utils/tokens.js";
|
|
40
41
|
|
|
41
42
|
export * from "./conversion/image.js";
|
package/src/result-types.ts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* The result of a text extraction operation.
|
|
6
6
|
*/
|
|
7
7
|
export interface TextExtractionResult {
|
|
8
|
-
objectId
|
|
8
|
+
objectId?: string;
|
|
9
|
+
file?: {
|
|
10
|
+
source_url: string;
|
|
11
|
+
result_url?: string;
|
|
12
|
+
}
|
|
9
13
|
status: TextExtractionStatus;
|
|
10
14
|
hasText: boolean;
|
|
11
15
|
message?: string;
|
package/src/utils/renditions.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { imageResizer } from "../conversion/image.js";
|
|
|
9
9
|
export interface ImageRenditionParams {
|
|
10
10
|
max_hw: number; //maximum size of the longest side of the image
|
|
11
11
|
format: ImageRenditionFormat;
|
|
12
|
+
/** Custom upload path — overrides default renditions/{etag}/{max_hw}/{page}.{format} path */
|
|
13
|
+
outputPath?: string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -53,7 +55,7 @@ export async function uploadRenditionPages(
|
|
|
53
55
|
params: ImageRenditionParams,
|
|
54
56
|
concurrency?: number,
|
|
55
57
|
) {
|
|
56
|
-
log.
|
|
58
|
+
log.debug(
|
|
57
59
|
`Uploading rendition for etag ${contentEtag} with ${files.length} pages (max_hw: ${params.max_hw}, format: ${params.format})`,
|
|
58
60
|
{ files },
|
|
59
61
|
);
|
|
@@ -61,11 +63,15 @@ export async function uploadRenditionPages(
|
|
|
61
63
|
const limit = pLimit(concurrency ?? 20);
|
|
62
64
|
|
|
63
65
|
const uploads = files.map((file, i) => limit(async () => {
|
|
64
|
-
const pageId =
|
|
66
|
+
const pageId = params.outputPath
|
|
67
|
+
? (files.length === 1
|
|
68
|
+
? params.outputPath
|
|
69
|
+
: `${params.outputPath}/${String(i).padStart(4, "0")}.${params.format}`)
|
|
70
|
+
: getRenditionPagePath(contentEtag, params, i);
|
|
65
71
|
let resizedImagePath = null;
|
|
66
72
|
|
|
67
73
|
try {
|
|
68
|
-
log.
|
|
74
|
+
log.debug(`Resizing image for ${contentEtag} page ${i}`, {
|
|
69
75
|
file,
|
|
70
76
|
params,
|
|
71
77
|
});
|
|
@@ -87,7 +93,7 @@ export async function uploadRenditionPages(
|
|
|
87
93
|
pageId,
|
|
88
94
|
);
|
|
89
95
|
|
|
90
|
-
log.
|
|
96
|
+
log.debug(
|
|
91
97
|
`Uploading rendition for ${contentEtag} page ${i} with max_hw: ${params.max_hw} and format: ${params.format}`,
|
|
92
98
|
{
|
|
93
99
|
resizedImagePath,
|
|
@@ -110,7 +116,7 @@ export async function uploadRenditionPages(
|
|
|
110
116
|
);
|
|
111
117
|
return Promise.reject(`Upload failed: ${err.message}`);
|
|
112
118
|
});
|
|
113
|
-
log.
|
|
119
|
+
log.debug(`Rendition uploaded for ${contentEtag} page ${i}`, {
|
|
114
120
|
result,
|
|
115
121
|
});
|
|
116
122
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { log } from "@temporalio/activity";
|
|
2
|
+
import { VertesiaClient } from "@vertesia/client";
|
|
3
|
+
import { NodeStreamSource } from "@vertesia/client/node";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
import { TextExtractionResult, TextExtractionStatus } from "../result-types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Uploads extracted text preview to cloud storage
|
|
9
|
+
*/
|
|
10
|
+
export async function uploadTextPreviewToStorage(
|
|
11
|
+
vertesia: VertesiaClient,
|
|
12
|
+
text: string,
|
|
13
|
+
storagePath: string,
|
|
14
|
+
fileType: string
|
|
15
|
+
): Promise<string> {
|
|
16
|
+
|
|
17
|
+
const source = new NodeStreamSource(
|
|
18
|
+
Readable.from(text),
|
|
19
|
+
storagePath,
|
|
20
|
+
'text/markdown',
|
|
21
|
+
storagePath
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const uploadedPath = await vertesia.files.uploadFile(source);
|
|
25
|
+
log.info(`Uploaded ${fileType} preview text to ${uploadedPath}`);
|
|
26
|
+
|
|
27
|
+
return uploadedPath;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates the TextExtractionResult for file_source mode
|
|
32
|
+
*/
|
|
33
|
+
export function createFileSourceResult(
|
|
34
|
+
sourceUrl: string,
|
|
35
|
+
storagePath: string,
|
|
36
|
+
text: string | null
|
|
37
|
+
): TextExtractionResult {
|
|
38
|
+
return {
|
|
39
|
+
hasText: !!text,
|
|
40
|
+
file: {
|
|
41
|
+
source_url: sourceUrl,
|
|
42
|
+
result_url: text && storagePath ? storagePath : undefined,
|
|
43
|
+
},
|
|
44
|
+
status: TextExtractionStatus.success,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Saves extracted text to an object in the object store
|
|
50
|
+
*/
|
|
51
|
+
export async function saveTextToObject(
|
|
52
|
+
vertesia: VertesiaClient,
|
|
53
|
+
objectId: string,
|
|
54
|
+
text: string
|
|
55
|
+
): Promise<void> {
|
|
56
|
+
const object = await vertesia.objects.retrieve(objectId);
|
|
57
|
+
await vertesia.objects.update(objectId, {
|
|
58
|
+
text: text,
|
|
59
|
+
text_etag: object.content?.etag,
|
|
60
|
+
});
|
|
61
|
+
log.info(`Saved text to object ${objectId}`);
|
|
62
|
+
}
|