@diagonal-hq/workflows 0.6.1 → 0.8.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/dist/chunks/{chunk-55XJDIQB.js → chunk-AQGV2DYG.js} +1 -1
- package/dist/chunks/{chunk-IQF5EEBK.js → chunk-FDU4BQPD.js} +59 -10
- package/dist/chunks/{chunk-XJOXCKID.js → chunk-U2PBCCHZ.js} +4 -2
- package/dist/errors.d.ts +3 -1
- package/dist/generated/capabilities.d.ts +17 -2
- package/dist/http-transport.js +1 -1
- package/dist/index.js +3 -3
- package/dist/profiles/test.js +3 -3
- package/dist/testing/index.js +9 -5
- package/dist/workflow.d.ts +15 -0
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
invoke
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AQGV2DYG.js";
|
|
4
4
|
import {
|
|
5
5
|
HostError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-U2PBCCHZ.js";
|
|
7
7
|
|
|
8
8
|
// packages/workflows/src/transaction.ts
|
|
9
9
|
async function transaction(fn) {
|
|
@@ -13,10 +13,11 @@ async function transaction(fn) {
|
|
|
13
13
|
try {
|
|
14
14
|
result = await fn();
|
|
15
15
|
} catch (error) {
|
|
16
|
-
|
|
16
|
+
const rolledBack = await rollBack({ error: thrownError(error) });
|
|
17
|
+
if (rolledBack.retry) {
|
|
17
18
|
continue;
|
|
18
19
|
}
|
|
19
|
-
throw error;
|
|
20
|
+
throw rollbackError(rolledBack.reply, error) ?? error;
|
|
20
21
|
}
|
|
21
22
|
try {
|
|
22
23
|
await invoke("transaction.commit", {});
|
|
@@ -25,30 +26,78 @@ async function transaction(fn) {
|
|
|
25
26
|
continue;
|
|
26
27
|
}
|
|
27
28
|
if (error instanceof HostError && error.code === "transaction_concurrent") {
|
|
28
|
-
await rollBack();
|
|
29
|
+
await rollBack({});
|
|
29
30
|
}
|
|
30
31
|
throw error;
|
|
31
32
|
}
|
|
32
33
|
return result;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
async function rollBack() {
|
|
36
|
+
async function rollBack(input) {
|
|
36
37
|
try {
|
|
37
|
-
await invoke("transaction.rollback",
|
|
38
|
+
return { retry: false, reply: await invoke("transaction.rollback", input) };
|
|
38
39
|
} catch (error) {
|
|
39
40
|
if (isTransient(error)) {
|
|
40
|
-
return true;
|
|
41
|
+
return { retry: true };
|
|
41
42
|
}
|
|
42
43
|
throw error;
|
|
43
44
|
}
|
|
44
|
-
return false;
|
|
45
45
|
}
|
|
46
46
|
function isTransient(error) {
|
|
47
47
|
return error instanceof HostError && error.code === "transaction_transient";
|
|
48
48
|
}
|
|
49
|
+
function thrownError(error) {
|
|
50
|
+
if (typeof error !== "object" || error === null) {
|
|
51
|
+
const value2 = typeof error === "bigint" ? String(error) : JSON.stringify(error);
|
|
52
|
+
return { name: "Error", message: `The workflow threw a non-error value: ${value2}` };
|
|
53
|
+
}
|
|
54
|
+
const name = Reflect.get(error, "name");
|
|
55
|
+
const failureId = Reflect.get(error, "failureId");
|
|
56
|
+
if (name === "HostError" && typeof failureId === "number" && Number.isInteger(failureId)) {
|
|
57
|
+
return { name, failure_id: failureId };
|
|
58
|
+
}
|
|
59
|
+
const message = Reflect.get(error, "message");
|
|
60
|
+
const code = Reflect.get(error, "code");
|
|
61
|
+
const status = Reflect.get(error, "status");
|
|
62
|
+
const details = Reflect.get(error, "details");
|
|
63
|
+
const errors = typeof details === "object" && details !== null ? Reflect.get(details, "errors") : void 0;
|
|
64
|
+
const thrown = {
|
|
65
|
+
name: typeof name === "string" ? name : "Error",
|
|
66
|
+
message: String(message ?? "The workflow threw an error.")
|
|
67
|
+
};
|
|
68
|
+
if (typeof code === "string") {
|
|
69
|
+
thrown.code = code;
|
|
70
|
+
}
|
|
71
|
+
if (typeof status === "number" && Number.isInteger(status)) {
|
|
72
|
+
thrown.status = status;
|
|
73
|
+
}
|
|
74
|
+
if (typeof errors === "object" && errors !== null && !Array.isArray(errors)) {
|
|
75
|
+
thrown.errors = { ...errors };
|
|
76
|
+
}
|
|
77
|
+
return thrown;
|
|
78
|
+
}
|
|
79
|
+
function rollbackError(reply, cause) {
|
|
80
|
+
if (typeof reply !== "object" || reply === null) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const message = Reflect.get(reply, "message");
|
|
84
|
+
const code = Reflect.get(reply, "code");
|
|
85
|
+
const status = Reflect.get(reply, "status");
|
|
86
|
+
const failureId = Reflect.get(reply, "failure_id");
|
|
87
|
+
const failure = Reflect.get(reply, "failure");
|
|
88
|
+
if (typeof message !== "string" || code !== "transaction_rollback" || typeof status !== "number" || typeof failureId !== "number" || !isFailure(failure)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return new HostError(message, code, status, Reflect.get(reply, "details"), failureId, failure, {
|
|
92
|
+
cause
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function isFailure(value2) {
|
|
96
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
97
|
+
}
|
|
49
98
|
|
|
50
99
|
// packages/workflows/src/generated/capabilities.ts
|
|
51
|
-
var SDK_VERSION =
|
|
100
|
+
var SDK_VERSION = 71;
|
|
52
101
|
var ai = {
|
|
53
102
|
/** Ask a decisions model typed questions about some content and get labelled answers with their probabilities */
|
|
54
103
|
decide: (input) => invoke("ai.decide", input),
|
|
@@ -5,9 +5,11 @@ var HostError = class extends Error {
|
|
|
5
5
|
* host records that failure, so a run records the failure of the call that it rethrows.
|
|
6
6
|
* @param failure The failure that a graph step records for the same error, or null for a
|
|
7
7
|
* refusal that only a script call can receive, such as an unknown capability.
|
|
8
|
+
* @param options `cause` is the error of a `transaction()` body that a `transaction_rollback`
|
|
9
|
+
* error replaces.
|
|
8
10
|
*/
|
|
9
|
-
constructor(message, code, status, details, failureId = null, failure = null) {
|
|
10
|
-
super(message);
|
|
11
|
+
constructor(message, code, status, details, failureId = null, failure = null, options = {}) {
|
|
12
|
+
super(message, options);
|
|
11
13
|
this.code = code;
|
|
12
14
|
this.status = status;
|
|
13
15
|
this.details = details;
|
package/dist/errors.d.ts
CHANGED
|
@@ -24,8 +24,10 @@ export declare class HostError extends Error {
|
|
|
24
24
|
* host records that failure, so a run records the failure of the call that it rethrows.
|
|
25
25
|
* @param failure The failure that a graph step records for the same error, or null for a
|
|
26
26
|
* refusal that only a script call can receive, such as an unknown capability.
|
|
27
|
+
* @param options `cause` is the error of a `transaction()` body that a `transaction_rollback`
|
|
28
|
+
* error replaces.
|
|
27
29
|
*/
|
|
28
|
-
constructor(message: string, code: string, status: number, details: unknown, failureId?: number | null, failure?: HostFailure | null);
|
|
30
|
+
constructor(message: string, code: string, status: number, details: unknown, failureId?: number | null, failure?: HostFailure | null, options?: ErrorOptions);
|
|
29
31
|
}
|
|
30
32
|
export declare class WorkflowFailure extends Error {
|
|
31
33
|
readonly status: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResourceKeyWith } from "../data.js";
|
|
2
2
|
import type { ContentDocument } from "../input.js";
|
|
3
|
-
export declare const SDK_VERSION =
|
|
3
|
+
export declare const SDK_VERSION = 71;
|
|
4
4
|
export interface WorkspaceSystemFields {
|
|
5
5
|
"ai_custom_system_prompt": string | null;
|
|
6
6
|
"brand_kit": {
|
|
@@ -1868,8 +1868,23 @@ export interface TransactionCommitInput {
|
|
|
1868
1868
|
}
|
|
1869
1869
|
export type TransactionCommitOutput = null;
|
|
1870
1870
|
export interface TransactionRollbackInput {
|
|
1871
|
+
error?: {
|
|
1872
|
+
name?: string;
|
|
1873
|
+
message?: string;
|
|
1874
|
+
code?: string;
|
|
1875
|
+
status?: number;
|
|
1876
|
+
errors?: Record<string, unknown>;
|
|
1877
|
+
failure_id?: number;
|
|
1878
|
+
};
|
|
1871
1879
|
}
|
|
1872
|
-
export type TransactionRollbackOutput = null
|
|
1880
|
+
export type TransactionRollbackOutput = null | {
|
|
1881
|
+
message: string;
|
|
1882
|
+
code: string;
|
|
1883
|
+
status: number;
|
|
1884
|
+
details: Record<string, unknown>;
|
|
1885
|
+
failure: Record<string, unknown>;
|
|
1886
|
+
failure_id: number;
|
|
1887
|
+
};
|
|
1873
1888
|
export interface UserAuthorizeInput {
|
|
1874
1889
|
permission: string;
|
|
1875
1890
|
user?: Record<string, unknown>;
|
package/dist/http-transport.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
web,
|
|
38
38
|
workflow,
|
|
39
39
|
workspace
|
|
40
|
-
} from "./chunks/chunk-
|
|
40
|
+
} from "./chunks/chunk-FDU4BQPD.js";
|
|
41
41
|
import {
|
|
42
42
|
InputField,
|
|
43
43
|
InputSchema,
|
|
@@ -49,13 +49,13 @@ import {
|
|
|
49
49
|
setTransport,
|
|
50
50
|
v,
|
|
51
51
|
validateWorkflowInput
|
|
52
|
-
} from "./chunks/chunk-
|
|
52
|
+
} from "./chunks/chunk-AQGV2DYG.js";
|
|
53
53
|
import {
|
|
54
54
|
HostError,
|
|
55
55
|
WorkflowFailure,
|
|
56
56
|
fail,
|
|
57
57
|
validationError
|
|
58
|
-
} from "./chunks/chunk-
|
|
58
|
+
} from "./chunks/chunk-U2PBCCHZ.js";
|
|
59
59
|
|
|
60
60
|
// packages/workflows/src/notifications.ts
|
|
61
61
|
var mail2 = {
|
package/dist/profiles/test.js
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
web,
|
|
36
36
|
workflow,
|
|
37
37
|
workspace
|
|
38
|
-
} from "../chunks/chunk-
|
|
38
|
+
} from "../chunks/chunk-FDU4BQPD.js";
|
|
39
39
|
import {
|
|
40
40
|
InputField,
|
|
41
41
|
InputSchema,
|
|
@@ -45,13 +45,13 @@ import {
|
|
|
45
45
|
respond,
|
|
46
46
|
v,
|
|
47
47
|
validateWorkflowInput
|
|
48
|
-
} from "../chunks/chunk-
|
|
48
|
+
} from "../chunks/chunk-AQGV2DYG.js";
|
|
49
49
|
import {
|
|
50
50
|
HostError,
|
|
51
51
|
WorkflowFailure,
|
|
52
52
|
fail,
|
|
53
53
|
validationError
|
|
54
|
-
} from "../chunks/chunk-
|
|
54
|
+
} from "../chunks/chunk-U2PBCCHZ.js";
|
|
55
55
|
|
|
56
56
|
// packages/workflows/src/generated/profiles/test.ts
|
|
57
57
|
var ai2 = {
|
package/dist/testing/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
parseWorkflowInput,
|
|
3
3
|
setTransport,
|
|
4
4
|
validateWorkflowInput
|
|
5
|
-
} from "../chunks/chunk-
|
|
5
|
+
} from "../chunks/chunk-AQGV2DYG.js";
|
|
6
6
|
import {
|
|
7
7
|
HostError
|
|
8
|
-
} from "../chunks/chunk-
|
|
8
|
+
} from "../chunks/chunk-U2PBCCHZ.js";
|
|
9
9
|
|
|
10
10
|
// packages/workflows/src/testing/index.ts
|
|
11
11
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -28,15 +28,19 @@ var SerialTransactionTransport = class {
|
|
|
28
28
|
const rollsBack = name === "transaction.rollback";
|
|
29
29
|
const ends = rollsBack || name === "transaction.commit";
|
|
30
30
|
if (begins || ends) {
|
|
31
|
-
|
|
31
|
+
const keys = input !== null && typeof input === "object" && !isArray(input) ? objectKeys(input) : null;
|
|
32
|
+
const describesError = rollsBack && keys !== null && keys.length === 1 && keys[0] === "error";
|
|
33
|
+
if (keys === null || keys.length > 0 && !describesError) {
|
|
32
34
|
throw new HostError(
|
|
33
|
-
"Transaction controls accept an empty object.",
|
|
35
|
+
"Transaction controls accept an empty object. A rollback also accepts the error of the body.",
|
|
34
36
|
"invalid_arguments",
|
|
35
37
|
422,
|
|
36
38
|
null
|
|
37
39
|
);
|
|
38
40
|
}
|
|
39
|
-
|
|
41
|
+
if (!describesError) {
|
|
42
|
+
input = {};
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
if (this.closing || (this.transactionOpen || begins) && this.pending > 0 && !rollsBack) {
|
|
42
46
|
throw new HostError(
|
package/dist/workflow.d.ts
CHANGED
|
@@ -15,8 +15,23 @@ export interface RequestContext {
|
|
|
15
15
|
url: string;
|
|
16
16
|
params: Record<string, string>;
|
|
17
17
|
query: Record<string, unknown>;
|
|
18
|
+
/** The request input: the payload with the query string values added. */
|
|
18
19
|
body: Record<string, unknown>;
|
|
20
|
+
/** The payload as the caller sent it, without the query string. */
|
|
21
|
+
payload: Record<string, unknown>;
|
|
22
|
+
/** Header names are lowercase. A header with more than one value joins them with `, `. */
|
|
19
23
|
headers: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* The raw value of each field that the request contract of the trigger declares, under its
|
|
26
|
+
* declared key, as a graph `request.input` reference reads it. A field that the request does
|
|
27
|
+
* not carry is absent. A header has its first value only.
|
|
28
|
+
*/
|
|
29
|
+
declared: {
|
|
30
|
+
params: Record<string, unknown>;
|
|
31
|
+
query: Record<string, unknown>;
|
|
32
|
+
headers: Record<string, unknown>;
|
|
33
|
+
body: Record<string, unknown>;
|
|
34
|
+
};
|
|
20
35
|
}
|
|
21
36
|
export interface ScriptExecution {
|
|
22
37
|
id: string;
|
package/package.json
CHANGED