@versori/run 0.4.25 → 0.4.26
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/esm/src/context/AsyncWorkflow.js +1 -1
- package/esm/src/context/Context.d.ts +8 -24
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +18 -5
- package/esm/src/context/ContextProvider.d.ts +2 -0
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +5 -2
- package/esm/src/context/WorkflowClient.d.ts +28 -0
- package/esm/src/context/WorkflowClient.d.ts.map +1 -0
- package/esm/src/context/WorkflowClient.js +108 -0
- package/esm/src/context/mod.d.ts +2 -1
- package/esm/src/context/mod.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts +1 -1
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.d.ts +5 -3
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +3 -0
- package/esm/src/internal/InternalAuth.d.ts +0 -1
- package/esm/src/internal/InternalAuth.d.ts.map +1 -1
- package/esm/src/internal/InternalAuth.js +1 -17
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/durable/DurableInterpreter.js +4 -17
- package/esm/src/interpreter/durable/Queue.d.ts +25 -17
- package/esm/src/interpreter/durable/Queue.d.ts.map +1 -1
- package/esm/src/interpreter/durable/Queue.js +17 -8
- package/esm/src/interpreter/durable/compilers/catch.js +2 -2
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/durableworkflow.js +31 -35
- package/esm/src/interpreter/memory/MemoryInterpreter.js +2 -2
- package/esm/src/interpreter/memory/compilers/catch.js +2 -2
- package/esm/src/kv/sdk/SDKKeyValue.d.ts +2 -2
- package/esm/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
- package/esm/src/kv/sdk/SDKKeyValue.js +9 -3
- package/package.json +1 -1
- package/script/src/context/AsyncWorkflow.js +1 -1
- package/script/src/context/Context.d.ts +8 -24
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +18 -5
- package/script/src/context/ContextProvider.d.ts +2 -0
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +5 -2
- package/script/src/context/WorkflowClient.d.ts +28 -0
- package/script/src/context/WorkflowClient.d.ts.map +1 -0
- package/script/src/context/WorkflowClient.js +112 -0
- package/script/src/context/mod.d.ts +2 -1
- package/script/src/context/mod.d.ts.map +1 -1
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts +1 -1
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.d.ts +5 -3
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +3 -0
- package/script/src/internal/InternalAuth.d.ts +0 -1
- package/script/src/internal/InternalAuth.d.ts.map +1 -1
- package/script/src/internal/InternalAuth.js +0 -16
- package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/durable/DurableInterpreter.js +3 -16
- package/script/src/interpreter/durable/Queue.d.ts +25 -17
- package/script/src/interpreter/durable/Queue.d.ts.map +1 -1
- package/script/src/interpreter/durable/Queue.js +17 -8
- package/script/src/interpreter/durable/compilers/catch.js +2 -2
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/durableworkflow.js +31 -35
- package/script/src/interpreter/memory/MemoryInterpreter.js +1 -1
- package/script/src/interpreter/memory/compilers/catch.js +2 -2
- package/script/src/kv/sdk/SDKKeyValue.d.ts +2 -2
- package/script/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
- package/script/src/kv/sdk/SDKKeyValue.js +9 -3
- package/esm/src/internal/cli.d.ts +0 -2
- package/esm/src/internal/cli.d.ts.map +0 -1
- package/esm/src/internal/cli.js +0 -32
- package/script/src/internal/cli.d.ts +0 -2
- package/script/src/internal/cli.d.ts.map +0 -1
- package/script/src/internal/cli.js +0 -35
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.durableWorkflowCompiler = void 0;
|
|
16
16
|
exports.compileDurableWorkflow = compileDurableWorkflow;
|
|
17
|
+
const mod_js_1 = require("../../../../deps/jsr.io/@std/ulid/1.0.0/mod.js");
|
|
17
18
|
const rxjs_1 = require("rxjs");
|
|
18
19
|
const DurableTrigger_js_1 = require("../../../dsl/triggers/DurableTrigger.js");
|
|
19
20
|
const constants_js_1 = require("../../../internal/constants.js");
|
|
@@ -25,20 +26,12 @@ function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
25
26
|
}
|
|
26
27
|
signal.addEventListener('abort', cleanup, { once: true });
|
|
27
28
|
let consecutiveErrors = 0;
|
|
28
|
-
const maxConsecutiveErrors = 5;
|
|
29
29
|
(async () => {
|
|
30
30
|
while (true) {
|
|
31
31
|
if (signal.aborted) {
|
|
32
32
|
cleanup();
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
35
|
-
if (consecutiveErrors >= maxConsecutiveErrors) {
|
|
36
|
-
ctx.log.error('reached too many consecutive errors stopping trigger', {
|
|
37
|
-
'triggerId': trigger.id,
|
|
38
|
-
});
|
|
39
|
-
cleanup();
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
35
|
try {
|
|
43
36
|
// Right now the API itself will hang for a period of time if no workflows are available.
|
|
44
37
|
// so we don't need to add a delay here.
|
|
@@ -51,37 +44,38 @@ function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
51
44
|
continue;
|
|
52
45
|
}
|
|
53
46
|
for (const wf of wfs.workflows) {
|
|
54
|
-
if (wf.id &&
|
|
55
|
-
wf.attempt !== undefined &&
|
|
56
|
-
trigger.options.maxAttempts &&
|
|
57
|
-
wf.attempt > trigger.options.maxAttempts) {
|
|
58
|
-
ctx.log.error('Workflow exceeded max attempts failing', {
|
|
59
|
-
workflowId: wf.id,
|
|
60
|
-
attempts: wf.attempt,
|
|
61
|
-
});
|
|
62
|
-
await ctx.queueProvider.complete({
|
|
63
|
-
id: wf.id,
|
|
64
|
-
output: wf.output,
|
|
65
|
-
status: 'failed',
|
|
66
|
-
});
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
47
|
const data = JSON.parse(atob(wf.payload ?? '{}'));
|
|
70
48
|
let activation;
|
|
71
49
|
if (wf.metadata?.activationId) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
50
|
+
try {
|
|
51
|
+
const { data } = await ctx.platformApi.getActivation({
|
|
52
|
+
path: {
|
|
53
|
+
activation_id: wf.metadata.activationId,
|
|
54
|
+
organisation_id: ctx.organisationId,
|
|
55
|
+
environment_id: Deno.env.get(constants_js_1.envVarEnvId) || 'development',
|
|
56
|
+
},
|
|
57
|
+
throwOnError: true,
|
|
58
|
+
});
|
|
59
|
+
activation = data;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
ctx.log.error('Failed to get activation', { error });
|
|
63
|
+
throw new Error('Failed to get activation');
|
|
64
|
+
}
|
|
81
65
|
}
|
|
82
|
-
const newContext = ctx.contextProvider.
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
const newContext = ctx.contextProvider.createWithExecutionId(activation, data, wf.metadata?.executionId ?? (0, mod_js_1.ulid)().toString(), {
|
|
67
|
+
workflow: wf,
|
|
68
|
+
onSuccess: (completedContext) => {
|
|
69
|
+
// locked status means we own the workflow and it's not completed yet
|
|
70
|
+
if (wf.status !== 'locked') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
ctx.queueProvider.complete({
|
|
74
|
+
id: wf.id,
|
|
75
|
+
output: btoa(JSON.stringify(completedContext.data)),
|
|
76
|
+
status: 'completed',
|
|
77
|
+
});
|
|
78
|
+
},
|
|
85
79
|
});
|
|
86
80
|
consecutiveErrors = 0;
|
|
87
81
|
subscriber.next(newContext);
|
|
@@ -90,6 +84,8 @@ function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
90
84
|
catch (error) {
|
|
91
85
|
ctx.log.error('Error fetching workflows', { error });
|
|
92
86
|
consecutiveErrors++;
|
|
87
|
+
// no workflows available, back-off a bit before retrying
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(consecutiveErrors * 1000, 30000)));
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
91
|
})();
|
|
@@ -279,7 +279,7 @@ class MemoryInterpreter {
|
|
|
279
279
|
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
280
280
|
registration.subscription = registration.trigger$
|
|
281
281
|
.pipe((0, rxjs_1.tap)((ctx) => {
|
|
282
|
-
ctx.log.info('MemoryInterpreter.executionStarted', {
|
|
282
|
+
ctx.log.info('MemoryInterpreter.executionStarted', {});
|
|
283
283
|
}), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((err) => {
|
|
284
284
|
ctx.log.error('MemoryInterpreter.executionError', {
|
|
285
285
|
error: err instanceof Error ? err.toString() : err,
|
|
@@ -37,7 +37,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
37
37
|
annotations: {
|
|
38
38
|
'error': error.message,
|
|
39
39
|
'stack': error.stack || '',
|
|
40
|
-
'workflowId': ctx.options.
|
|
40
|
+
'workflowId': ctx.options.workflow?.id || ctx.workflow?.id || '',
|
|
41
41
|
'executionId': ctx.executionId,
|
|
42
42
|
'activationId': ctx.activation.id,
|
|
43
43
|
'activationExternalId': ctx.activation?.user.externalId,
|
|
@@ -51,7 +51,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
51
51
|
annotations: {
|
|
52
52
|
'error': error.message,
|
|
53
53
|
'stack': error.stack || '',
|
|
54
|
-
'workflowId': ctx.options.
|
|
54
|
+
'workflowId': ctx.options.workflow?.id || ctx.workflow?.id || '',
|
|
55
55
|
'executionId': ctx.executionId,
|
|
56
56
|
'activationId': ctx.activation.id,
|
|
57
57
|
'activationExternalId': ctx.activation?.user.externalId,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CountKVResponse } from '../../dsl/http/versori/kvapi/models/CountKVResponse.js';
|
|
2
2
|
import { CreateStoreResponse } from '../../dsl/http/versori/kvapi/models/CreateStoreResponse.js';
|
|
3
3
|
import { ListKVRequest } from '../../dsl/http/versori/kvapi/models/ListKVRequest.js';
|
|
4
4
|
import { ListKVResponse } from '../../dsl/http/versori/kvapi/models/ListKVResponse.js';
|
|
5
|
-
import {
|
|
5
|
+
import { GetOptions, KeyValue } from '../KeyValue.js';
|
|
6
6
|
export declare class SDKKeyValue implements KeyValue {
|
|
7
7
|
private readonly store;
|
|
8
8
|
private readonly prefix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SDKKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/sdk/SDKKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SDKKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/sdk/SDKKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,wDAAwD,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4DAA4D,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,sDAAsD,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,uDAAuD,CAAC;AAGvF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,qBAAa,WAAY,YAAW,QAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAuB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAnD,KAAK,EAAE,mBAAmB,EAAmB,MAAM,EAAE,MAAM;IAElF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA8BnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAUjD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAY9E,OAAO,CAAC,WAAW;CAGtB"}
|
|
@@ -34,7 +34,13 @@ class SDKKeyValue {
|
|
|
34
34
|
try {
|
|
35
35
|
const k = this.generateKey(key instanceof Array ? key.join('/') : key);
|
|
36
36
|
const entry = await KvOperationsService_js_1.KvOperationsService.getKv(this.store.id, k);
|
|
37
|
-
|
|
37
|
+
if (entry.value === undefined) {
|
|
38
|
+
if (options.throwOnNotFound) {
|
|
39
|
+
throw new Error('Key not found');
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return JSON.parse(String(entry.value));
|
|
38
44
|
}
|
|
39
45
|
catch (error) {
|
|
40
46
|
if (options.throwOnNotFound && error instanceof Error &&
|
|
@@ -49,10 +55,10 @@ class SDKKeyValue {
|
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
async set(key, value) {
|
|
52
|
-
|
|
58
|
+
const payload = JSON.stringify(value);
|
|
53
59
|
const k = this.generateKey(key instanceof Array ? key.join('/') : key);
|
|
54
60
|
await KvOperationsService_js_1.KvOperationsService.setKv(this.store.id, k, {
|
|
55
|
-
value:
|
|
61
|
+
value: payload,
|
|
56
62
|
options: {},
|
|
57
63
|
});
|
|
58
64
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/src/internal/cli.ts"],"names":[],"mappings":"AA8BA,wBAAgB,gBAAgB,IAAI,MAAM,CAmBzC"}
|
package/esm/src/internal/cli.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Versori Group Inc
|
|
3
|
-
*
|
|
4
|
-
* Use of this software is governed by the Business Source License 1.1
|
|
5
|
-
* included in the LICENSE file at the root of this repository.
|
|
6
|
-
*
|
|
7
|
-
* Change Date: 2029-01-01
|
|
8
|
-
* Change License: Apache License, Version 2.0
|
|
9
|
-
*
|
|
10
|
-
* As of the Change Date, in accordance with the Business Source License,
|
|
11
|
-
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
|
-
*/
|
|
13
|
-
// This file contains functions that can read stuff generated by the Versori CLI. This is used when running locally.
|
|
14
|
-
import { homedir } from 'node:os';
|
|
15
|
-
const cookiesFileName = 'cookies.json';
|
|
16
|
-
const versoriCookieName = 'versori_sess';
|
|
17
|
-
export function getVersoriCookie() {
|
|
18
|
-
const cookiesFilePath = `${homedir()}/.config/versori/${cookiesFileName}`;
|
|
19
|
-
let cookiesFile;
|
|
20
|
-
try {
|
|
21
|
-
cookiesFile = JSON.parse(Deno.readTextFileSync(cookiesFilePath));
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
console.error('Error reading file, have you run the Versori CLI to log in?');
|
|
25
|
-
throw new Error(`Failed to read or parse cookies file at ${cookiesFilePath}: ${e}`);
|
|
26
|
-
}
|
|
27
|
-
const versoriCookie = cookiesFile.cookies.find((cookie) => cookie.Name === versoriCookieName);
|
|
28
|
-
if (!versoriCookie) {
|
|
29
|
-
throw new Error(`Cookie 'versori_sess' not found in ${cookiesFilePath}`);
|
|
30
|
-
}
|
|
31
|
-
return `${versoriCookieName}=${versoriCookie.Value}`;
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/src/internal/cli.ts"],"names":[],"mappings":"AA8BA,wBAAgB,gBAAgB,IAAI,MAAM,CAmBzC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2025 Versori Group Inc
|
|
4
|
-
*
|
|
5
|
-
* Use of this software is governed by the Business Source License 1.1
|
|
6
|
-
* included in the LICENSE file at the root of this repository.
|
|
7
|
-
*
|
|
8
|
-
* Change Date: 2029-01-01
|
|
9
|
-
* Change License: Apache License, Version 2.0
|
|
10
|
-
*
|
|
11
|
-
* As of the Change Date, in accordance with the Business Source License,
|
|
12
|
-
* use of this software will be governed by the Apache License, Version 2.0.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getVersoriCookie = getVersoriCookie;
|
|
16
|
-
// This file contains functions that can read stuff generated by the Versori CLI. This is used when running locally.
|
|
17
|
-
const node_os_1 = require("node:os");
|
|
18
|
-
const cookiesFileName = 'cookies.json';
|
|
19
|
-
const versoriCookieName = 'versori_sess';
|
|
20
|
-
function getVersoriCookie() {
|
|
21
|
-
const cookiesFilePath = `${(0, node_os_1.homedir)()}/.config/versori/${cookiesFileName}`;
|
|
22
|
-
let cookiesFile;
|
|
23
|
-
try {
|
|
24
|
-
cookiesFile = JSON.parse(Deno.readTextFileSync(cookiesFilePath));
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
console.error('Error reading file, have you run the Versori CLI to log in?');
|
|
28
|
-
throw new Error(`Failed to read or parse cookies file at ${cookiesFilePath}: ${e}`);
|
|
29
|
-
}
|
|
30
|
-
const versoriCookie = cookiesFile.cookies.find((cookie) => cookie.Name === versoriCookieName);
|
|
31
|
-
if (!versoriCookie) {
|
|
32
|
-
throw new Error(`Cookie 'versori_sess' not found in ${cookiesFilePath}`);
|
|
33
|
-
}
|
|
34
|
-
return `${versoriCookieName}=${versoriCookie.Value}`;
|
|
35
|
-
}
|