@diagonal-hq/workflows 0.5.3 → 0.6.1

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/README.md CHANGED
@@ -76,7 +76,7 @@ Imported from this package, `runWorkflow` runs the handler in Node. A deployed s
76
76
 
77
77
  - It always runs the `validate` option of the workflow config, as a deployed run does. It runs a `validateInput` export only when the test passes that export as the `validateInput` option. Another validator, or a `validateInput` option for a workflow with a `validate` option, is refused.
78
78
  - Inputs, context, mock replies, and the result cross the engine boundary as JSON. A handler that returns `undefined` gives `null`, and a `Date` becomes a string.
79
- - A `WorkflowFailure` or `HostError` from the script is rethrown as that class. A mock that throws another error reaches the script as a `HostError` with the code `internal_error`.
79
+ - A `WorkflowFailure` or `HostError` from the script is rethrown as that class. A mock that throws another error reaches the script as a `HostError` with the code `internal_error` and `failure: null`. To test a script that reads `failure`, make the mock throw a `HostError` with the `failure` argument.
80
80
  - A workflow that the test defines itself has no compiled code, so it runs in Node.
81
81
 
82
82
  ### QuickJS limits
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  validationError
3
- } from "./chunk-OF5QITP7.js";
3
+ } from "./chunk-XJOXCKID.js";
4
4
 
5
5
  // packages/workflows/src/transport.ts
6
6
  var active = null;
@@ -1,33 +1,54 @@
1
1
  import {
2
2
  invoke
3
- } from "./chunk-EU2ME5WR.js";
3
+ } from "./chunk-55XJDIQB.js";
4
4
  import {
5
5
  HostError
6
- } from "./chunk-OF5QITP7.js";
6
+ } from "./chunk-XJOXCKID.js";
7
7
 
8
8
  // packages/workflows/src/transaction.ts
9
9
  async function transaction(fn) {
10
- await invoke("transaction.begin", {});
11
- let result;
12
- try {
13
- result = await fn();
14
- } catch (error) {
15
- await invoke("transaction.rollback", {});
16
- throw error;
10
+ for (; ; ) {
11
+ await invoke("transaction.begin", {});
12
+ let result;
13
+ try {
14
+ result = await fn();
15
+ } catch (error) {
16
+ if (await rollBack()) {
17
+ continue;
18
+ }
19
+ throw error;
20
+ }
21
+ try {
22
+ await invoke("transaction.commit", {});
23
+ } catch (error) {
24
+ if (isTransient(error)) {
25
+ continue;
26
+ }
27
+ if (error instanceof HostError && error.code === "transaction_concurrent") {
28
+ await rollBack();
29
+ }
30
+ throw error;
31
+ }
32
+ return result;
17
33
  }
34
+ }
35
+ async function rollBack() {
18
36
  try {
19
- await invoke("transaction.commit", {});
37
+ await invoke("transaction.rollback", {});
20
38
  } catch (error) {
21
- if (error instanceof HostError && error.code === "transaction_concurrent") {
22
- await invoke("transaction.rollback", {});
39
+ if (isTransient(error)) {
40
+ return true;
23
41
  }
24
42
  throw error;
25
43
  }
26
- return result;
44
+ return false;
45
+ }
46
+ function isTransient(error) {
47
+ return error instanceof HostError && error.code === "transaction_transient";
27
48
  }
28
49
 
29
50
  // packages/workflows/src/generated/capabilities.ts
30
- var SDK_VERSION = 67;
51
+ var SDK_VERSION = 69;
31
52
  var ai = {
32
53
  /** Ask a decisions model typed questions about some content and get labelled answers with their probabilities */
33
54
  decide: (input) => invoke("ai.decide", input),
@@ -3,19 +3,23 @@ var HostError = class extends Error {
3
3
  /**
4
4
  * @param failureId The host's ID for the failure of the call. When the error ends the run, the
5
5
  * host records that failure, so a run records the failure of the call that it rethrows.
6
+ * @param failure The failure that a graph step records for the same error, or null for a
7
+ * refusal that only a script call can receive, such as an unknown capability.
6
8
  */
7
- constructor(message, code, status, details, failureId = null) {
9
+ constructor(message, code, status, details, failureId = null, failure = null) {
8
10
  super(message);
9
11
  this.code = code;
10
12
  this.status = status;
11
13
  this.details = details;
12
14
  this.failureId = failureId;
15
+ this.failure = failure;
13
16
  this.name = "HostError";
14
17
  }
15
18
  code;
16
19
  status;
17
20
  details;
18
21
  failureId;
22
+ failure;
19
23
  };
20
24
  var WorkflowFailure = class extends Error {
21
25
  constructor(message, status, details = null) {
package/dist/errors.d.ts CHANGED
@@ -1,13 +1,31 @@
1
+ /**
2
+ * The failure that a graph step records when its task throws, which the step's error edge reads.
3
+ * A task failure has `type`, `message`, and `status_code`. An unexpected exception also has
4
+ * `original_type`, a validation failure has `errors`, and a refused input has `invalid_input`.
5
+ * A declared error is keyed by its type, and a failed child workflow gives its own failure.
6
+ */
7
+ export type HostFailure = {
8
+ type?: string;
9
+ message?: string;
10
+ original_type?: string;
11
+ status_code?: number;
12
+ errors?: Record<string, string[]>;
13
+ invalid_input?: unknown;
14
+ [key: string]: unknown;
15
+ };
1
16
  export declare class HostError extends Error {
2
17
  readonly code: string;
3
18
  readonly status: number;
4
19
  readonly details: unknown;
5
20
  readonly failureId: number | null;
21
+ readonly failure: HostFailure | null;
6
22
  /**
7
23
  * @param failureId The host's ID for the failure of the call. When the error ends the run, the
8
24
  * host records that failure, so a run records the failure of the call that it rethrows.
25
+ * @param failure The failure that a graph step records for the same error, or null for a
26
+ * refusal that only a script call can receive, such as an unknown capability.
9
27
  */
10
- constructor(message: string, code: string, status: number, details: unknown, failureId?: number | null);
28
+ constructor(message: string, code: string, status: number, details: unknown, failureId?: number | null, failure?: HostFailure | null);
11
29
  }
12
30
  export declare class WorkflowFailure extends Error {
13
31
  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 = 67;
3
+ export declare const SDK_VERSION = 69;
4
4
  export interface WorkspaceSystemFields {
5
5
  "ai_custom_system_prompt": string | null;
6
6
  "brand_kit": {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HostError
3
- } from "./chunks/chunk-OF5QITP7.js";
3
+ } from "./chunks/chunk-XJOXCKID.js";
4
4
 
5
5
  // packages/workflows/src/http-transport.ts
6
6
  var HttpTransport = class {
@@ -39,7 +39,14 @@ var HttpTransport = class {
39
39
  status: response.status,
40
40
  details: null
41
41
  };
42
- throw new HostError(error.message, error.code, error.status, error.details);
42
+ throw new HostError(
43
+ error.message,
44
+ error.code,
45
+ error.status,
46
+ error.details,
47
+ null,
48
+ error.failure ?? null
49
+ );
43
50
  }
44
51
  return reply.value;
45
52
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./console.js";
2
2
  export { HostError, WorkflowFailure, fail, validationError } from "./errors.js";
3
+ export type { HostFailure } from "./errors.js";
3
4
  export { invoke, setTransport, type HostTransport } from "./transport.js";
4
5
  export { transaction } from "./transaction.js";
5
6
  export { data } from "./data.js";
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  web,
38
38
  workflow,
39
39
  workspace
40
- } from "./chunks/chunk-IW2R4RZ3.js";
40
+ } from "./chunks/chunk-IQF5EEBK.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-EU2ME5WR.js";
52
+ } from "./chunks/chunk-55XJDIQB.js";
53
53
  import {
54
54
  HostError,
55
55
  WorkflowFailure,
56
56
  fail,
57
57
  validationError
58
- } from "./chunks/chunk-OF5QITP7.js";
58
+ } from "./chunks/chunk-XJOXCKID.js";
59
59
 
60
60
  // packages/workflows/src/notifications.ts
61
61
  var mail2 = {
@@ -35,7 +35,7 @@ import {
35
35
  web,
36
36
  workflow,
37
37
  workspace
38
- } from "../chunks/chunk-IW2R4RZ3.js";
38
+ } from "../chunks/chunk-IQF5EEBK.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-EU2ME5WR.js";
48
+ } from "../chunks/chunk-55XJDIQB.js";
49
49
  import {
50
50
  HostError,
51
51
  WorkflowFailure,
52
52
  fail,
53
53
  validationError
54
- } from "../chunks/chunk-OF5QITP7.js";
54
+ } from "../chunks/chunk-XJOXCKID.js";
55
55
 
56
56
  // packages/workflows/src/generated/profiles/test.ts
57
57
  var ai2 = {
@@ -2,10 +2,10 @@ import {
2
2
  parseWorkflowInput,
3
3
  setTransport,
4
4
  validateWorkflowInput
5
- } from "../chunks/chunk-EU2ME5WR.js";
5
+ } from "../chunks/chunk-55XJDIQB.js";
6
6
  import {
7
7
  HostError
8
- } from "../chunks/chunk-OF5QITP7.js";
8
+ } from "../chunks/chunk-XJOXCKID.js";
9
9
 
10
10
  // packages/workflows/src/testing/index.ts
11
11
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -1 +1,6 @@
1
+ /**
2
+ * Runs `fn` in one database transaction. When a concurrent write aborts the transaction, the host
3
+ * rolls it back and answers with `transaction_transient`, and `fn` runs again. The host limits the
4
+ * attempts and waits between them, so `fn` can run more than once.
5
+ */
1
6
  export declare function transaction<T>(fn: () => Promise<T>): Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/workflows",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
4
4
  "description": "The authoring API of Diagonal managed workflows, their capabilities, and the workflow test helpers.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {