@vertesia/workflow 0.71.0 → 0.72.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertesia/workflow",
3
- "version": "0.71.0",
3
+ "version": "0.72.0",
4
4
  "type": "module",
5
5
  "description": "Composable prompts workflow dsl",
6
6
  "main": "./lib/esm/index.js",
@@ -36,7 +36,6 @@
36
36
  "@temporalio/activity": "^1.11.5",
37
37
  "@temporalio/workflow": "^1.11.5",
38
38
  "@types/json-schema": "^7.0.15",
39
- "@vertesia/memory": "^0.43.0",
40
39
  "fast-deep-equal": "^3.1.3",
41
40
  "jsonwebtoken": "^9.0.2",
42
41
  "mime": "^4.0.0",
@@ -50,10 +49,11 @@
50
49
  "tmp": "^0.2.3",
51
50
  "tmp-promise": "^3.0.3",
52
51
  "yaml": "^2.6.0",
53
- "@vertesia/api-fetch-client": "0.71.0",
54
- "@vertesia/client": "0.71.0",
55
52
  "@llumiverse/common": "0.21.0",
56
- "@vertesia/common": "0.71.0"
53
+ "@vertesia/api-fetch-client": "0.72.0",
54
+ "@vertesia/client": "0.72.0",
55
+ "@vertesia/memory": "0.44.0",
56
+ "@vertesia/common": "0.72.0"
57
57
  },
58
58
  "ts_dual_module": {
59
59
  "outDir": "lib",
@@ -0,0 +1,66 @@
1
+ import { log } from "@temporalio/activity";
2
+ import { DocumentMetadata, DSLActivityExecutionPayload, DSLActivitySpec } from "@vertesia/common";
3
+ import { setupActivity } from "../dsl/setup/ActivityContext.js";
4
+ import { InteractionExecutionParams, executeInteractionFromActivity } from "./executeInteraction.js";
5
+
6
+ const INT_GENERATE_TEXT_PARTS = "sys:IdentifyTextSections";
7
+ export interface identifyTextSectionsParams extends InteractionExecutionParams {
8
+ interactionName?: string;
9
+ }
10
+ export interface identifyTextSections extends DSLActivitySpec<identifyTextSectionsParams> {
11
+ name: "identifyTextSections";
12
+ }
13
+
14
+ export async function identifyTextSections(
15
+ payload: DSLActivityExecutionPayload<identifyTextSectionsParams>,
16
+ ) {
17
+ const context = await setupActivity<identifyTextSectionsParams>(payload);
18
+ const { params, client, objectId } = context;
19
+ const interactionName = params.interactionName ?? INT_GENERATE_TEXT_PARTS;
20
+
21
+ const project = await context.fetchProject();
22
+
23
+ const doc = await client.objects.retrieve(objectId, "+text");
24
+
25
+ const text = doc.text;
26
+ if (!text || text.length === 0) {
27
+ log.warn(`No text found for object ${objectId}`);
28
+ return;
29
+ }
30
+
31
+ //instrument the text with line numbers
32
+ const lines = text.split('\n')
33
+ const instrumented = lines.map((l, i) => `{%${i}%}${l}`).join('\n')
34
+
35
+ const promptData = {
36
+ content: instrumented ?? undefined,
37
+ human_context: project?.configuration?.human_context ?? undefined,
38
+ };
39
+
40
+ const infoRes = await executeInteractionFromActivity(
41
+ client,
42
+ interactionName,
43
+ {
44
+ ...params,
45
+ include_previous_error: true,
46
+ validate_result: true,
47
+ },
48
+ promptData,
49
+ payload.debug_mode ?? false,
50
+ );
51
+
52
+ const parts = infoRes.result.parts;
53
+ if (!parts || !Array.isArray(parts) || parts.length === 0) {
54
+ log.warn(`No text parts generated for object ${objectId}`);
55
+ return;
56
+ }
57
+
58
+ await client.objects.update(doc.id, {
59
+ metadata: {
60
+ type: "document",
61
+ sections: parts
62
+ } as DocumentMetadata
63
+ });
64
+
65
+ return { status: "completed" };
66
+ }
@@ -17,3 +17,4 @@ export { convertPdfToStructuredText } from "./media/processPdfWithTextract.js";
17
17
  export { transcribeMedia } from "./media/transcribeMediaWithGladia.js";
18
18
  export { notifyWebhook } from "./notifyWebhook.js";
19
19
  export { setDocumentStatus } from "./setDocumentStatus.js";
20
+ export { identifyTextSections } from "./identifyTextSections.js";
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ 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/identifyTextSections.js";
21
22
  export * from "./activities/renditions/generateImageRendition.js";
22
23
  export * from "./activities/renditions/generateVideoRendition.js";
23
24
  export * from "./activities/generateOrAssignContentType.js";