@parcha/agentrun-dsl 0.1.0-beta.13 → 0.1.0-beta.15
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 +3 -1
- package/dist/author.js +1 -1
- package/dist/dry-run.d.ts +6 -0
- package/dist/dry-run.js +30 -5
- package/dist/graph.d.ts +67 -0
- package/dist/graph.js +158 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/job.d.ts +14 -0
- package/dist/job.js +5 -0
- package/dist/recovery/canonical-hash.d.ts +1 -1
- package/dist/recovery/canonical-hash.js +3 -3
- package/dist/recovery/driver.d.ts +21 -1
- package/dist/recovery/driver.js +394 -16
- package/dist/recovery/execution-path.d.ts +8 -0
- package/dist/recovery/execution-path.js +14 -0
- package/dist/recovery/frozen-snapshot.d.ts +76 -1
- package/dist/recovery/frozen-snapshot.js +21 -0
- package/dist/recovery/index.d.ts +3 -3
- package/dist/recovery/index.js +2 -2
- package/dist/recovery/item-state.d.ts +48 -0
- package/dist/recovery/item-state.js +89 -0
- package/dist/recovery/journal.d.ts +6 -3
- package/dist/recovery/journal.js +20 -8
- package/dist/recovery/store.d.ts +33 -9
- package/dist/recovery/testing/conformance.js +55 -0
- package/dist/system-one.d.ts +17 -1
- package/dist/system-one.js +17 -1
- package/dist/workflow.d.ts +3 -0
- package/dist/workflow.js +42 -1
- package/package.json +8 -1
- package/skills/author/references/language.md +1 -1
- package/skills/author/references/sdk-authoring.md +2 -0
|
@@ -3,8 +3,29 @@
|
|
|
3
3
|
// the path grammar, maps nodes onto these records and owns the store's lifecycle.
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { RecoveryError } from "./errors.js";
|
|
6
|
+
import { itemState as rebuildItemState, partialResults as readPartialResults } from "./item-state.js";
|
|
6
7
|
const failure = (code, message) => new RecoveryError(message, code);
|
|
7
8
|
export const FROZEN_SNAPSHOT_SCHEMA = "agentrun.frozen_run.v3";
|
|
9
|
+
/** The keyed layout: what lies in a map item is kept in that item's record beside the state, and a state the driver
|
|
10
|
+
* references is kept once by its digest, so no record rewritten at a commit grows with a map's items. */
|
|
11
|
+
export const FROZEN_SNAPSHOT_SCHEMA_V4 = "agentrun.frozen_run.v4";
|
|
12
|
+
export { stateDelta, applyStateDelta, canonicalJson } from "./item-state.js";
|
|
13
|
+
/** Two values a state holds under one key are the same value. A key an item copied from its base holds the base's own
|
|
14
|
+
* object, or one with the same JSON. */
|
|
15
|
+
/** A map item's state at `path`, rebuilt as the driver rebuilds it (`./item-state.ts`, which imports nothing): the
|
|
16
|
+
* `agentrun.states` value its `base` names, with the item's `set` and `unset` for that path applied, checked against
|
|
17
|
+
* that path's `sha256`. `item` is an `agentrun.items` value; `states` holds `agentrun.states` values by SHA-256. When
|
|
18
|
+
* the base is missing, or a digest differs, it says why and never guesses. `sha256` defaults to Node's. */
|
|
19
|
+
export function itemState(item, states, path, options = {}) {
|
|
20
|
+
return rebuildItemState(item, states, path, { sha256: options.sha256 ?? ((text) => createHash("sha256").update(text).digest("hex")) });
|
|
21
|
+
}
|
|
22
|
+
/** A failed map's finished results from the driver state's `pin.partial` (`./item-state.ts`, which imports nothing): in
|
|
23
|
+
* the keyed layout, the list of slots and each result read by digest and checked; a whole-state run's list as it is.
|
|
24
|
+
* Each slot is null (the item never finished), `{ result }`, or `{ unreadable }`, never a guess. `sha256` defaults to
|
|
25
|
+
* Node's. */
|
|
26
|
+
export function partialResults(partial, states, options = {}) {
|
|
27
|
+
return readPartialResults(partial, states, { sha256: options.sha256 ?? ((text) => createHash("sha256").update(text).digest("hex")) });
|
|
28
|
+
}
|
|
8
29
|
export const emptyPathFrame = () => ({ input: null, done: [], states: {}, chains: {}, loops: {}, routes: {}, inputs: {}, steps: {} });
|
|
9
30
|
const record = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
10
31
|
const SHA256 = /^[a-f0-9]{64}$/;
|
package/dist/recovery/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { RecoveryBinding, RecoveryEffect, RecoveryIntent, RecoveryJournal, RecoveryNote, RecoveryStore } from "./store.js";
|
|
1
|
+
export type { RecoveryBinding, RecoveryEffect, RecoveryIntent, RecoveryItem, RecoveryJournal, RecoveryNote, RecoveryParts, RecoveryStore } from "./store.js";
|
|
2
2
|
export { openRecovery, recoveryBinding, recoveryBound, routeTaken, workspaceFiles, type RecoveryEffectParams, type RecoveryFiles, type RecoveryOptions, type RecoveryStop } from "./driver.js";
|
|
3
3
|
export { withRecovery, type RecoveryAdapters, type RecoveryDriver, type RecoveryNodeParams, type RecoveryStep, type WithRecoveryOptions } from "./with-recovery.js";
|
|
4
4
|
export { memoryStore } from "./memory-store.js";
|
|
@@ -8,8 +8,8 @@ export { RecoveryError, asRecoveryError, isRecoveryError, runStopOf, runStoppedE
|
|
|
8
8
|
export { bindingDigests, bindingMismatch, LEDGER_FORMAT } from "./binding.js";
|
|
9
9
|
export { canonicalHash, canonicalSha256 } from "./canonical-hash.js";
|
|
10
10
|
export { callKey, heldCallKey, CALL_KEY_BYTES } from "./call-key.js";
|
|
11
|
-
export { FROZEN_SNAPSHOT_SCHEMA, validateFrozenSnapshot, openedFrozenSnapshot, serializeFrozenSnapshot, emptyPathFrame, frozenStepSessionId, frozenStepId, frozenEffectId, frozenEffectPath, admitFrozenStep, closeFrozenStepAttempt, frozenStop, type FrozenSnapshot, type PathFrame, type RouteDecision, type QuestionReceipts, type FrameTag, type StepRecord, type EscalationRow, type FrozenShape, } from "./frozen-snapshot.js";
|
|
12
|
-
export { chainStep, childrenOf, completedIteration, enclosingChains, enclosingIterations, isWithin, nodeAt, pathSegments, topLevelCompletion } from "./execution-path.js";
|
|
11
|
+
export { FROZEN_SNAPSHOT_SCHEMA, FROZEN_SNAPSHOT_SCHEMA_V4, validateFrozenSnapshot, openedFrozenSnapshot, serializeFrozenSnapshot, emptyPathFrame, stateDelta, applyStateDelta, itemState, partialResults, canonicalJson, frozenStepSessionId, frozenStepId, frozenEffectId, frozenEffectPath, admitFrozenStep, closeFrozenStepAttempt, frozenStop, type FrozenSnapshot, type FrozenSnapshotV4, type ItemRecord, type MapEntry, type StateDelta, type Sha256, type PartialSlot, type PathFrame, type RouteDecision, type QuestionReceipts, type FrameTag, type StepRecord, type EscalationRow, type FrozenShape, } from "./frozen-snapshot.js";
|
|
12
|
+
export { chainStep, childrenOf, completedIteration, enclosingChains, enclosingIterations, isWithin, mapItemOf, nodeAt, pathSegments, topLevelCompletion } from "./execution-path.js";
|
|
13
13
|
export { TypedEffectFailure, EffectEnvelopeFailure, classifyEffectFailure } from "./effect-failure.js";
|
|
14
14
|
export { effectRetryClass, transportFactOf, type TransportFact } from "./transport-facts.js";
|
|
15
15
|
export { buildHandoff, handoffFirstTurn, type Handoff, type HandoffOptions } from "./handoff.js";
|
package/dist/recovery/index.js
CHANGED
|
@@ -7,8 +7,8 @@ export { RecoveryError, asRecoveryError, isRecoveryError, runStopOf, runStoppedE
|
|
|
7
7
|
export { bindingDigests, bindingMismatch, LEDGER_FORMAT } from "./binding.js";
|
|
8
8
|
export { canonicalHash, canonicalSha256 } from "./canonical-hash.js";
|
|
9
9
|
export { callKey, heldCallKey, CALL_KEY_BYTES } from "./call-key.js";
|
|
10
|
-
export { FROZEN_SNAPSHOT_SCHEMA, validateFrozenSnapshot, openedFrozenSnapshot, serializeFrozenSnapshot, emptyPathFrame, frozenStepSessionId, frozenStepId, frozenEffectId, frozenEffectPath, admitFrozenStep, closeFrozenStepAttempt, frozenStop, } from "./frozen-snapshot.js";
|
|
11
|
-
export { chainStep, childrenOf, completedIteration, enclosingChains, enclosingIterations, isWithin, nodeAt, pathSegments, topLevelCompletion } from "./execution-path.js";
|
|
10
|
+
export { FROZEN_SNAPSHOT_SCHEMA, FROZEN_SNAPSHOT_SCHEMA_V4, validateFrozenSnapshot, openedFrozenSnapshot, serializeFrozenSnapshot, emptyPathFrame, stateDelta, applyStateDelta, itemState, partialResults, canonicalJson, frozenStepSessionId, frozenStepId, frozenEffectId, frozenEffectPath, admitFrozenStep, closeFrozenStepAttempt, frozenStop, } from "./frozen-snapshot.js";
|
|
11
|
+
export { chainStep, childrenOf, completedIteration, enclosingChains, enclosingIterations, isWithin, mapItemOf, nodeAt, pathSegments, topLevelCompletion } from "./execution-path.js";
|
|
12
12
|
export { TypedEffectFailure, EffectEnvelopeFailure, classifyEffectFailure } from "./effect-failure.js";
|
|
13
13
|
export { effectRetryClass, transportFactOf } from "./transport-facts.js";
|
|
14
14
|
export { buildHandoff, handoffFirstTurn } from "./handoff.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
type State = Record<string, unknown>;
|
|
2
|
+
/** A committed state inside a map item, against its map's base (the state the map started from): the keys it sets
|
|
3
|
+
* (new, or holding another value than the base's), the base's keys it lacks, and the digest of the whole state, which
|
|
4
|
+
* a rebuild must reach. */
|
|
5
|
+
export type StateDelta = {
|
|
6
|
+
set: State;
|
|
7
|
+
unset: string[];
|
|
8
|
+
sha256: string;
|
|
9
|
+
};
|
|
10
|
+
/** The hex SHA-256 of a text's UTF-8 bytes, synchronous. */
|
|
11
|
+
export type Sha256 = (text: string) => string;
|
|
12
|
+
/** The JSON a state's digest is taken over: every object's keys sorted. */
|
|
13
|
+
export declare function canonicalJson(value: unknown): string;
|
|
14
|
+
/** `state` against `base`, as a map item keeps it. */
|
|
15
|
+
export declare function stateDelta(base: State, state: State, sha256: string): StateDelta;
|
|
16
|
+
/** The state a delta was taken from, in its own key order: the base's keys first (a map item starts from a copy of its
|
|
17
|
+
* base), then the keys it added. */
|
|
18
|
+
export declare function applyStateDelta(base: State, delta: StateDelta): State;
|
|
19
|
+
/** A map item's state at `path`, rebuilt as the driver rebuilds it: the `agentrun.states` value its `base` names, with
|
|
20
|
+
* the item's `set` and `unset` for that path applied, checked against that path's `sha256`. `item` is an
|
|
21
|
+
* `agentrun.items` value; `states` holds `agentrun.states` values by SHA-256; `sha256` hashes a text's UTF-8 bytes.
|
|
22
|
+
* When the base is missing, or a digest differs, it says why and never guesses. */
|
|
23
|
+
export declare function itemState(item: unknown, states: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>, path: string, { sha256 }: {
|
|
24
|
+
sha256: Sha256;
|
|
25
|
+
}): {
|
|
26
|
+
state: State;
|
|
27
|
+
} | {
|
|
28
|
+
unreadable: string;
|
|
29
|
+
};
|
|
30
|
+
/** A slot of a failed map: `null` for an item that never finished, its result, or why it cannot be read. */
|
|
31
|
+
export type PartialSlot = null | {
|
|
32
|
+
result: unknown;
|
|
33
|
+
} | {
|
|
34
|
+
unreadable: string;
|
|
35
|
+
};
|
|
36
|
+
/** A failed map's finished results, read as the driver reads them: `partial` is the driver state's `pin.partial`. In the
|
|
37
|
+
* keyed layout its `results` is one SHA-256 naming the `agentrun.states` value that lists each slot (null, or the
|
|
38
|
+
* SHA-256 of that item's result); `states` holds `agentrun.states` values by SHA-256, and every digest is checked. A
|
|
39
|
+
* whole-state run's `results` is the list itself. A document that is missing or does not match its digest is
|
|
40
|
+
* unreadable, never guessed: the list as a whole, or one slot. */
|
|
41
|
+
export declare function partialResults(partial: unknown, states: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>, { sha256 }: {
|
|
42
|
+
sha256: Sha256;
|
|
43
|
+
}): {
|
|
44
|
+
slots: PartialSlot[];
|
|
45
|
+
} | {
|
|
46
|
+
unreadable: string;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// A map item's state in the keyed layout, rebuilt from its record and its base. This module imports nothing, so a
|
|
2
|
+
// reader with no Node (the static viewer inlines it) runs the same rebuild the driver runs; the SHA-256 is the caller's.
|
|
3
|
+
/** The JSON a state's digest is taken over: every object's keys sorted. */
|
|
4
|
+
export function canonicalJson(value) {
|
|
5
|
+
return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item)
|
|
6
|
+
? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
|
|
7
|
+
}
|
|
8
|
+
const sameValue = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
|
|
9
|
+
/** `state` against `base`, as a map item keeps it. */
|
|
10
|
+
export function stateDelta(base, state, sha256) {
|
|
11
|
+
const set = {};
|
|
12
|
+
for (const [key, value] of Object.entries(state))
|
|
13
|
+
if (!Object.hasOwn(base, key) || !sameValue(base[key], value))
|
|
14
|
+
set[key] = value;
|
|
15
|
+
return { set, unset: Object.keys(base).filter((key) => !Object.hasOwn(state, key)), sha256 };
|
|
16
|
+
}
|
|
17
|
+
/** The state a delta was taken from, in its own key order: the base's keys first (a map item starts from a copy of its
|
|
18
|
+
* base), then the keys it added. */
|
|
19
|
+
export function applyStateDelta(base, delta) {
|
|
20
|
+
const unset = new Set(delta.unset);
|
|
21
|
+
const state = {};
|
|
22
|
+
for (const key of Object.keys(base))
|
|
23
|
+
if (!unset.has(key))
|
|
24
|
+
state[key] = Object.hasOwn(delta.set, key) ? delta.set[key] : base[key];
|
|
25
|
+
for (const [key, value] of Object.entries(delta.set))
|
|
26
|
+
if (!Object.hasOwn(base, key))
|
|
27
|
+
state[key] = value;
|
|
28
|
+
return state;
|
|
29
|
+
}
|
|
30
|
+
const isObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
31
|
+
/** A map item's state at `path`, rebuilt as the driver rebuilds it: the `agentrun.states` value its `base` names, with
|
|
32
|
+
* the item's `set` and `unset` for that path applied, checked against that path's `sha256`. `item` is an
|
|
33
|
+
* `agentrun.items` value; `states` holds `agentrun.states` values by SHA-256; `sha256` hashes a text's UTF-8 bytes.
|
|
34
|
+
* When the base is missing, or a digest differs, it says why and never guesses. */
|
|
35
|
+
export function itemState(item, states, path, { sha256 }) {
|
|
36
|
+
if (typeof sha256 !== "function")
|
|
37
|
+
throw new TypeError("itemState needs a sha256 function");
|
|
38
|
+
if (!isObject(item) || typeof item.base !== "string" || !isObject(item.frame) || !isObject(item.frame.states))
|
|
39
|
+
return { unreadable: "not a map item's record" };
|
|
40
|
+
const delta = item.frame.states[path];
|
|
41
|
+
if (delta === undefined)
|
|
42
|
+
return { unreadable: `the item keeps no state at ${path}` };
|
|
43
|
+
if (!isObject(delta) || !isObject(delta.set) || !Array.isArray(delta.unset) || !delta.unset.every((key) => typeof key === "string") || typeof delta.sha256 !== "string") {
|
|
44
|
+
return { unreadable: `the state at ${path} is not a delta` };
|
|
45
|
+
}
|
|
46
|
+
const held = states instanceof Map ? states.get(item.base) : Object.hasOwn(states, item.base) ? states[item.base] : undefined;
|
|
47
|
+
if (!isObject(held) || !isObject(held.state))
|
|
48
|
+
return { unreadable: `its base ${item.base} is missing` };
|
|
49
|
+
if (sha256(canonicalJson(held.state)) !== item.base)
|
|
50
|
+
return { unreadable: `its base does not match its SHA-256 ${item.base}` };
|
|
51
|
+
const state = applyStateDelta(held.state, delta);
|
|
52
|
+
if (sha256(canonicalJson(state)) !== delta.sha256)
|
|
53
|
+
return { unreadable: `the state at ${path} does not rebuild to its SHA-256 ${delta.sha256}` };
|
|
54
|
+
return { state };
|
|
55
|
+
}
|
|
56
|
+
/** A failed map's finished results, read as the driver reads them: `partial` is the driver state's `pin.partial`. In the
|
|
57
|
+
* keyed layout its `results` is one SHA-256 naming the `agentrun.states` value that lists each slot (null, or the
|
|
58
|
+
* SHA-256 of that item's result); `states` holds `agentrun.states` values by SHA-256, and every digest is checked. A
|
|
59
|
+
* whole-state run's `results` is the list itself. A document that is missing or does not match its digest is
|
|
60
|
+
* unreadable, never guessed: the list as a whole, or one slot. */
|
|
61
|
+
export function partialResults(partial, states, { sha256 }) {
|
|
62
|
+
if (typeof sha256 !== "function")
|
|
63
|
+
throw new TypeError("partialResults needs a sha256 function");
|
|
64
|
+
if (!isObject(partial) || typeof partial.path !== "string" || typeof partial.as !== "string")
|
|
65
|
+
return { unreadable: "not a failed map's results" };
|
|
66
|
+
if (Array.isArray(partial.results))
|
|
67
|
+
return { slots: partial.results.map((result) => (result === null ? null : { result })) };
|
|
68
|
+
if (typeof partial.results !== "string")
|
|
69
|
+
return { unreadable: "not a failed map's results" };
|
|
70
|
+
const read = (digest) => {
|
|
71
|
+
const held = states instanceof Map ? states.get(digest) : Object.hasOwn(states, digest) ? states[digest] : undefined;
|
|
72
|
+
if (!isObject(held) || !Object.hasOwn(held, "state"))
|
|
73
|
+
return { unreadable: `${digest} is missing` };
|
|
74
|
+
if (sha256(canonicalJson(held.state)) !== digest)
|
|
75
|
+
return { unreadable: `${digest} does not match its SHA-256` };
|
|
76
|
+
return { value: held.state };
|
|
77
|
+
};
|
|
78
|
+
const list = read(partial.results);
|
|
79
|
+
if ("unreadable" in list)
|
|
80
|
+
return { unreadable: `the list of results ${list.unreadable}` };
|
|
81
|
+
if (!Array.isArray(list.value) || !list.value.every((slot) => slot === null || (typeof slot === "string" && /^[a-f0-9]{64}$/.test(slot))))
|
|
82
|
+
return { unreadable: "the list of results is not a list of digests" };
|
|
83
|
+
return { slots: list.value.map((slot) => {
|
|
84
|
+
if (slot === null)
|
|
85
|
+
return null;
|
|
86
|
+
const result = read(slot);
|
|
87
|
+
return "unreadable" in result ? { unreadable: `the result ${result.unreadable}` } : { result: result.value };
|
|
88
|
+
}) };
|
|
89
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { RecoveryBinding, RecoveryEffect, RecoveryJournal, RecoveryNote } from "./store.js";
|
|
2
|
-
/** A journal as a backend keeps it: what it is bound to, who owns it, its state, its notes,
|
|
3
|
-
*
|
|
1
|
+
import type { RecoveryBinding, RecoveryEffect, RecoveryItem, RecoveryJournal, RecoveryNote } from "./store.js";
|
|
2
|
+
/** A journal as a backend keeps it: what it is bound to, who owns it, its state, its notes, its effects in admission
|
|
3
|
+
* order, each with the outside calls it made, and the parts written beside the state (map items' records by path,
|
|
4
|
+
* states by digest). */
|
|
4
5
|
export type JournalRecord = {
|
|
5
6
|
binding: string | null;
|
|
6
7
|
inputs: Record<string, string> | null;
|
|
@@ -11,6 +12,8 @@ export type JournalRecord = {
|
|
|
11
12
|
effects: Array<RecoveryEffect & {
|
|
12
13
|
calls?: unknown;
|
|
13
14
|
}>;
|
|
15
|
+
items?: Record<string, RecoveryItem>;
|
|
16
|
+
states?: Record<string, unknown>;
|
|
14
17
|
};
|
|
15
18
|
export type JournalBackend = {
|
|
16
19
|
/** Take the journal for one owner, or throw when it has a live one. Resolves to what lets go of it. */
|
package/dist/recovery/journal.js
CHANGED
|
@@ -52,13 +52,22 @@ export async function openJournal(backend, bound) {
|
|
|
52
52
|
return done;
|
|
53
53
|
};
|
|
54
54
|
/** One commit, inside a write: it checks this open still owns the journal, advances the revision, and lets `change`
|
|
55
|
-
* alter the record with that revision. The record is replaced only when
|
|
56
|
-
const commit = async (change) => {
|
|
55
|
+
* alter the record with that revision, then lays the parts beside it. The record is replaced only when both return. */
|
|
56
|
+
const commit = async (change, parts) => {
|
|
57
57
|
const record = await backend.read();
|
|
58
58
|
if (!record || record.generation !== generation)
|
|
59
59
|
throw new RecoveryError("Run owner generation is not acquired");
|
|
60
60
|
const next = record.revision + 1;
|
|
61
61
|
change(record, next);
|
|
62
|
+
const laid = parts?.(next);
|
|
63
|
+
if (laid?.items)
|
|
64
|
+
record.items = { ...record.items, ...json(laid.items) };
|
|
65
|
+
if (laid?.states) {
|
|
66
|
+
const states = record.states ??= {};
|
|
67
|
+
for (const [sha256, state] of Object.entries(laid.states))
|
|
68
|
+
if (!Object.hasOwn(states, sha256))
|
|
69
|
+
states[sha256] = json(state);
|
|
70
|
+
}
|
|
62
71
|
record.revision = next;
|
|
63
72
|
await backend.write(record);
|
|
64
73
|
revision = next;
|
|
@@ -71,7 +80,7 @@ export async function openJournal(backend, bound) {
|
|
|
71
80
|
effects: () => [...effects.values()],
|
|
72
81
|
effect: (id) => effects.get(id),
|
|
73
82
|
notes: () => [...notes],
|
|
74
|
-
save: (state, note) => inOrder(async () => {
|
|
83
|
+
save: (state, note, parts) => inOrder(async () => {
|
|
75
84
|
let entry;
|
|
76
85
|
const committed = await commit((record, next) => {
|
|
77
86
|
record.state = json(typeof state === "function" ? state(next) : state);
|
|
@@ -79,7 +88,7 @@ export async function openJournal(backend, bound) {
|
|
|
79
88
|
entry = { revision: next, kind: note.kind, detail: json(note.detail), at: new Date().toISOString() };
|
|
80
89
|
record.notes.push(entry);
|
|
81
90
|
}
|
|
82
|
-
});
|
|
91
|
+
}, parts);
|
|
83
92
|
if (entry)
|
|
84
93
|
notes.push(entry);
|
|
85
94
|
return committed;
|
|
@@ -90,23 +99,24 @@ export async function openJournal(backend, bound) {
|
|
|
90
99
|
notes.push({ revision: committed, ...entry });
|
|
91
100
|
return committed;
|
|
92
101
|
}),
|
|
93
|
-
|
|
102
|
+
// A record kept whole lists every effect itself, an owned one too.
|
|
103
|
+
admit: (id, name, argsHash, state, session = null, intent, args, parts) => inOrder(async () => {
|
|
94
104
|
const known = effects.get(id);
|
|
95
105
|
if (known)
|
|
96
106
|
return known;
|
|
97
107
|
const effect = { id, name, argsHash, status: "unknown", session, result: null, ...(intent ? { intent: json(intent) } : {}), ...(args !== undefined ? { args: json(args) } : {}) };
|
|
98
|
-
await commit((record) => { record.effects.push({ ...effect }); record.state = json(state); });
|
|
108
|
+
await commit((record) => { record.effects.push({ ...effect }); record.state = json(state); }, parts);
|
|
99
109
|
effects.set(id, effect);
|
|
100
110
|
return "new";
|
|
101
111
|
}),
|
|
102
|
-
complete: (id, result, state = opened.state) => inOrder(async () => {
|
|
112
|
+
complete: (id, result, state = opened.state, parts) => inOrder(async () => {
|
|
103
113
|
const known = effects.get(id);
|
|
104
114
|
if (!known)
|
|
105
115
|
throw new RecoveryError(`Effect ${id} completes without an admission`);
|
|
106
116
|
if (known.status === "completed")
|
|
107
117
|
throw new RecoveryError(`Effect ${id} completes once`);
|
|
108
118
|
const value = json(result);
|
|
109
|
-
await commit((record) => { Object.assign(stored(record, id), { status: "completed", result: value }); record.state = json(state); });
|
|
119
|
+
await commit((record) => { Object.assign(stored(record, id), { status: "completed", result: value }); record.state = json(state); }, parts);
|
|
110
120
|
effects.set(id, { ...known, status: "completed", result: value });
|
|
111
121
|
}),
|
|
112
122
|
called: (id, calls) => inOrder(async () => {
|
|
@@ -123,5 +133,7 @@ export async function openJournal(backend, bound) {
|
|
|
123
133
|
await queue;
|
|
124
134
|
await release();
|
|
125
135
|
},
|
|
136
|
+
items: async (paths) => { const record = await backend.read(); return paths.map((path) => (record?.items && Object.hasOwn(record.items, path) ? json(record.items[path]) : undefined)); },
|
|
137
|
+
stateOf: async (sha256) => { const record = await backend.read(); return record?.states && Object.hasOwn(record.states, sha256) ? json(record.states[sha256]) : undefined; },
|
|
126
138
|
};
|
|
127
139
|
}
|
package/dist/recovery/store.d.ts
CHANGED
|
@@ -4,13 +4,27 @@ export type RecoveryBinding = {
|
|
|
4
4
|
binding: string;
|
|
5
5
|
inputs?: Record<string, string>;
|
|
6
6
|
};
|
|
7
|
-
/** A decision recorded beside the state, with the revision of the commit that wrote it.
|
|
7
|
+
/** A decision recorded beside the state, with the revision of the commit that wrote it. `layout` says once per open
|
|
8
|
+
* that the driver keeps the whole state in one record although the host asked for the keyed layout, and why. */
|
|
8
9
|
export type RecoveryNote = {
|
|
9
10
|
revision: number;
|
|
10
|
-
kind: "escalation" | "handoff" | "inherited";
|
|
11
|
+
kind: "escalation" | "handoff" | "inherited" | "layout";
|
|
11
12
|
detail: unknown;
|
|
12
13
|
at: string;
|
|
13
14
|
};
|
|
15
|
+
/** A map item's record, as a store keeps it beside the state: plain JSON the driver writes and reads back. The store
|
|
16
|
+
* reads one field of it, `effects`: the ids of the effects admitted with this item as their owner. */
|
|
17
|
+
export type RecoveryItem = {
|
|
18
|
+
effects: string[];
|
|
19
|
+
[field: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
/** What a write keeps beside the state, in the same commit: map items' records by item path, each replacing the one
|
|
22
|
+
* before it whole, and states by their digest (`canonicalHash`), each written once and never changed. Computed with
|
|
23
|
+
* the commit's revision, after the state. */
|
|
24
|
+
export type RecoveryParts = {
|
|
25
|
+
items?: Record<string, RecoveryItem>;
|
|
26
|
+
states?: Record<string, unknown>;
|
|
27
|
+
};
|
|
14
28
|
/** The external call an effect stands for: the tool it calls and the hash of the arguments it calls it with
|
|
15
29
|
* (`canonicalHash` of the arguments). A continuation's own call is keyed the same way, so a call that repeats an
|
|
16
30
|
* effect is known for one whatever the effect's status. */
|
|
@@ -49,10 +63,11 @@ export type RecoveryJournal = {
|
|
|
49
63
|
effect(id: string): RecoveryEffect | undefined;
|
|
50
64
|
notes(): RecoveryNote[];
|
|
51
65
|
/** Commit a state computed with the commit's own revision, so a row that names its revision is never durable without
|
|
52
|
-
* it, and a note when the state records a decision. Resolves to that revision. */
|
|
53
|
-
save(state: (revision: number) => unknown, note?: Pick<RecoveryNote, "kind" | "detail"
|
|
54
|
-
/** Commit the state, and a note when the state records a decision. Resolves to the
|
|
55
|
-
|
|
66
|
+
* it, and a note when the state records a decision, and the parts that go with it. Resolves to that revision. */
|
|
67
|
+
save(state: (revision: number) => unknown, note?: Pick<RecoveryNote, "kind" | "detail">, parts?: (revision: number) => RecoveryParts): Promise<number>;
|
|
68
|
+
/** Commit the state, and a note when the state records a decision, and the parts that go with it. Resolves to the
|
|
69
|
+
* commit's revision. */
|
|
70
|
+
save(state: unknown, note?: Pick<RecoveryNote, "kind" | "detail">, parts?: (revision: number) => RecoveryParts): Promise<number>;
|
|
56
71
|
/** Commit a note with no state change. Resolves to the commit's revision. */
|
|
57
72
|
note(kind: RecoveryNote["kind"], detail: unknown): Promise<number>;
|
|
58
73
|
/** Admit an effect before it is dispatched, with the state that admits it, in one commit, and the external call it
|
|
@@ -60,18 +75,27 @@ export type RecoveryJournal = {
|
|
|
60
75
|
* later open. `args` are the call's arguments as the driver admitted it, kept with the effect as the host's door is sent them
|
|
61
76
|
* (an optional field: a record without them reads as it always did). A store that does not keep them leaves a call that was
|
|
62
77
|
* admitted and never sent unsettleable: a host's `reconcile` cannot re-send it, and the resume refuses it
|
|
63
|
-
* (`FROZEN_EFFECT_UNKNOWN`). An id already admitted is returned as it stands and nothing is written.
|
|
64
|
-
|
|
78
|
+
* (`FROZEN_EFFECT_UNKNOWN`). An id already admitted is returned as it stands and nothing is written. `owner` names the
|
|
79
|
+
* map item whose record lists the effect, written in `parts` in the same commit: a store that keeps parts lists the
|
|
80
|
+
* effect there, and needs not list it again. */
|
|
81
|
+
admit(id: string, name: string, argsHash: string, state: unknown, session?: string | null, intent?: RecoveryIntent, args?: unknown, parts?: (revision: number) => RecoveryParts, owner?: string): Promise<"new" | RecoveryEffect>;
|
|
65
82
|
/** Complete an admitted effect with its result, and the state that follows, in one commit. An effect completes once,
|
|
66
83
|
* and never without an admission. With no state given, the state stays as this open found it: that is how an
|
|
67
84
|
* operator reconciles an unknown effect. */
|
|
68
|
-
complete(id: string, result: unknown, state?: unknown): Promise<void>;
|
|
85
|
+
complete(id: string, result: unknown, state?: unknown, parts?: (revision: number) => RecoveryParts): Promise<void>;
|
|
69
86
|
/** Keep the outside calls an admitted effect made, whether or not the effect completes: the list given replaces the one the
|
|
70
87
|
* effect held, and the effect's `calls` carries it from then on, at every later open. They are evidence for the host; no
|
|
71
88
|
* resume depends on them. A caller that adds to the calls an earlier process kept passes the earlier ones first. */
|
|
72
89
|
called(id: string, calls: unknown): Promise<void>;
|
|
73
90
|
/** Let go of the journal. No later commit is made through this open, and the next open is the next generation. */
|
|
74
91
|
close(): Promise<void>;
|
|
92
|
+
/** The records of the map items at `paths`, as the last commit that wrote each left it (undefined for one never
|
|
93
|
+
* written), so a driver reads back what it wrote in `parts`. The effects they list are then in `effects()` too.
|
|
94
|
+
* A store that keeps parts has both `items` and `stateOf`; a store without them cannot keep the keyed layout, and the
|
|
95
|
+
* driver keeps the whole state in one record there. */
|
|
96
|
+
items?(paths: string[]): Promise<Array<RecoveryItem | undefined>>;
|
|
97
|
+
/** The state written in `parts` under `sha256`, or undefined. */
|
|
98
|
+
stateOf?(sha256: string): Promise<unknown>;
|
|
75
99
|
};
|
|
76
100
|
/** Where one run's journal lives. `open` takes ownership of it: a journal that is already open is refused, a binding
|
|
77
101
|
* that differs from the one the journal was first opened under is refused naming the inputs that moved, and the
|
|
@@ -210,4 +210,59 @@ export function registerStoreConformance(name, create) {
|
|
|
210
210
|
assert.deepEqual(fourth.state, { kept: 1, nested: [null, { at: "1970-01-01T00:00:00.000Z" }] });
|
|
211
211
|
await fourth.close();
|
|
212
212
|
});
|
|
213
|
+
// Parts: a store that keeps them declares it with both reads, `items` and `stateOf`; a store with neither keeps the
|
|
214
|
+
// driver's whole state in one record, and these cases hold for it trivially.
|
|
215
|
+
const keeps = (journal) => {
|
|
216
|
+
assert.equal(typeof journal.items === "function", typeof journal.stateOf === "function", "a store declares both items and stateOf, or neither");
|
|
217
|
+
return typeof journal.items === "function";
|
|
218
|
+
};
|
|
219
|
+
const ITEM = "/root/steps/0/items/0";
|
|
220
|
+
it("parts are kept beside the state, in the same commit: an item's record replaced whole at each write, a state written once", async (store) => {
|
|
221
|
+
const first = await store.open(BOUND);
|
|
222
|
+
if (!keeps(first)) {
|
|
223
|
+
await first.close();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
assert.equal(await first.save({ n: 1 }, undefined, (revision) => ({ items: { [ITEM]: { effects: [], status: "running", revision } }, states: { "sha-a": { a: 1 } } })), 1);
|
|
227
|
+
assert.equal(await first.save({ n: 2 }, undefined, (revision) => ({ items: { [ITEM]: { effects: [], revision } }, states: { "sha-a": { a: "rewritten" }, "sha-b": { b: 2 } } })), 2);
|
|
228
|
+
await first.close();
|
|
229
|
+
const second = await store.open(BOUND);
|
|
230
|
+
assert.deepEqual(await second.items([ITEM, "/root/steps/0/items/1"]), [{ effects: [], revision: 2 }, undefined]);
|
|
231
|
+
assert.deepEqual([await second.stateOf("sha-a"), await second.stateOf("sha-b")], [{ a: 1 }, { b: 2 }]);
|
|
232
|
+
assert.deepEqual(second.state, { n: 2 });
|
|
233
|
+
await second.close();
|
|
234
|
+
});
|
|
235
|
+
it("an effect admitted with an owner is listed by the owner's record, and by effects() once that record is read", async (store) => {
|
|
236
|
+
const first = await store.open(BOUND);
|
|
237
|
+
if (!keeps(first)) {
|
|
238
|
+
await first.close();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const owned = (ids) => () => ({ items: { [ITEM]: { effects: ids } } });
|
|
242
|
+
assert.equal(await first.admit("e1", "lookup", "args-1", { n: 1 }, "run-1", undefined, { id: 1 }, owned(["e1"]), ITEM), "new");
|
|
243
|
+
assert.equal(await first.admit("e2", "lookup", "args-2", { n: 2 }, "run-1", undefined, undefined, owned(["e1", "e2"]), ITEM), "new");
|
|
244
|
+
await first.complete("e1", { value: 1 }, { n: 3 }, owned(["e1", "e2"]));
|
|
245
|
+
await first.close();
|
|
246
|
+
const second = await store.open(BOUND);
|
|
247
|
+
const [record] = await second.items([ITEM]);
|
|
248
|
+
assert.deepEqual(record?.effects, ["e1", "e2"]);
|
|
249
|
+
assert.deepEqual(second.effects().map((effect) => [effect.id, effect.status, effect.result]).sort(), [["e1", "completed", { value: 1 }], ["e2", "unknown", null]]);
|
|
250
|
+
assert.deepEqual(second.effect("e1")?.args, { id: 1 });
|
|
251
|
+
assert.deepEqual(second.state, { n: 3 });
|
|
252
|
+
await second.close();
|
|
253
|
+
});
|
|
254
|
+
it("a write whose parts cannot be stored writes nothing at all, its state included", async (store) => {
|
|
255
|
+
const first = await store.open(BOUND);
|
|
256
|
+
if (!keeps(first)) {
|
|
257
|
+
await first.close();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
await first.save({ kept: 1 });
|
|
261
|
+
await assert.rejects(first.save({ kept: 2 }, undefined, () => ({ items: { [ITEM]: { effects: [], bad: Number.POSITIVE_INFINITY } } })), refused());
|
|
262
|
+
assert.equal(first.revision, 1);
|
|
263
|
+
await first.close();
|
|
264
|
+
const second = await store.open(BOUND);
|
|
265
|
+
assert.deepEqual([second.state, second.revision, await second.items([ITEM])], [{ kept: 1 }, 1, [undefined]]);
|
|
266
|
+
await second.close();
|
|
267
|
+
});
|
|
213
268
|
}
|
package/dist/system-one.d.ts
CHANGED
|
@@ -13,6 +13,18 @@ export type SystemOneQuestion = {
|
|
|
13
13
|
type: "score";
|
|
14
14
|
instructions: string;
|
|
15
15
|
criteria: string[];
|
|
16
|
+
}
|
|
17
|
+
/** Locates what its instructions describe in the request's image. A host-side question: no workflow node declares one, and it needs an image sent with the request. */
|
|
18
|
+
| {
|
|
19
|
+
type: "box";
|
|
20
|
+
instructions: string;
|
|
21
|
+
};
|
|
22
|
+
/** A box's edges as fractions of the image's height (`top`, `bottom`) and width (`left`, `right`), from the top left corner. */
|
|
23
|
+
export type SystemOneBox = {
|
|
24
|
+
top: number;
|
|
25
|
+
bottom: number;
|
|
26
|
+
left: number;
|
|
27
|
+
right: number;
|
|
16
28
|
};
|
|
17
29
|
export type SystemOneAnswer = {
|
|
18
30
|
type: "choice";
|
|
@@ -28,6 +40,10 @@ export type SystemOneAnswer = {
|
|
|
28
40
|
legend: Record<string, string>;
|
|
29
41
|
probabilities: Record<string, number>;
|
|
30
42
|
confidence: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: "box";
|
|
45
|
+
box: SystemOneBox;
|
|
46
|
+
confidence: number | null;
|
|
31
47
|
};
|
|
32
48
|
export type SystemOneResult = {
|
|
33
49
|
answers: Record<string, SystemOneAnswer>;
|
|
@@ -65,7 +81,7 @@ export type AnswersSidecar = {
|
|
|
65
81
|
export declare function answersSidecar(answers: Record<string, SystemOneAnswer>): AnswersSidecar;
|
|
66
82
|
export declare function synthesizeAnswers(questions: Record<string, SystemOneQuestion>): Record<string, SystemOneAnswer>;
|
|
67
83
|
export type SystemOneRetryClass = "http_429" | "http_5xx" | "connection" | "timeout";
|
|
68
|
-
declare const responseReasons: readonly ["answers_shape", "answer_keys", "answer_shape", "answer_type", "noul_probability", "confidence", "probabilities", "probability_keys", "probability_mass", "score_legend", "score_consistency", "choice_option", "score_range"];
|
|
84
|
+
declare const responseReasons: readonly ["answers_shape", "answer_keys", "answer_shape", "answer_type", "noul_probability", "confidence", "box_coordinates", "probabilities", "probability_keys", "probability_mass", "score_legend", "score_consistency", "choice_option", "score_range"];
|
|
69
85
|
export type SystemOneResponseReason = typeof responseReasons[number];
|
|
70
86
|
export declare function isSystemOneResponseReason(value: unknown): value is SystemOneResponseReason;
|
|
71
87
|
export declare class SystemOneError extends Error {
|
package/dist/system-one.js
CHANGED
|
@@ -94,6 +94,8 @@ export function answersToValue(answers, questions) {
|
|
|
94
94
|
out[id] = a.noul >= 0.5;
|
|
95
95
|
else if (q.type === "score" && a.type === "score")
|
|
96
96
|
out[id] = Math.max(0, Math.round(a.score));
|
|
97
|
+
else if (q.type === "box" && a.type === "box")
|
|
98
|
+
out[id] = { ...a.box };
|
|
97
99
|
else
|
|
98
100
|
throw new Error(`System One answered question "${id}" with type "${a.type}", expected ${q.type}`);
|
|
99
101
|
}
|
|
@@ -104,6 +106,7 @@ export function answerConfidence(answer) {
|
|
|
104
106
|
throw new SystemOneError("System One answer missing for a question that was asked", null);
|
|
105
107
|
if (answer.type === "noul")
|
|
106
108
|
return Math.abs(answer.noul - 0.5) * 2;
|
|
109
|
+
// A box the provider reported no confidence for counts as none: unknown is never read as sure.
|
|
107
110
|
return typeof answer.confidence === "number" ? answer.confidence : 0;
|
|
108
111
|
}
|
|
109
112
|
export function answersSidecar(answers) {
|
|
@@ -124,6 +127,8 @@ export function synthesizeAnswers(questions) {
|
|
|
124
127
|
const options = Object.keys(q.criteria);
|
|
125
128
|
out[id] = { type: "choice", choice: options[0], probabilities: Object.fromEntries(options.map((o) => [o, 1 / options.length])), confidence: 0 };
|
|
126
129
|
}
|
|
130
|
+
else if (q.type === "box")
|
|
131
|
+
out[id] = { type: "box", box: { top: 0, bottom: 1, left: 0, right: 1 }, confidence: 0 };
|
|
127
132
|
else if (q.type === "noul")
|
|
128
133
|
out[id] = { type: "noul", noul: 0.5 };
|
|
129
134
|
else
|
|
@@ -132,7 +137,7 @@ export function synthesizeAnswers(questions) {
|
|
|
132
137
|
return { ...out };
|
|
133
138
|
}
|
|
134
139
|
const responseReasons = ["answers_shape", "answer_keys", "answer_shape", "answer_type", "noul_probability",
|
|
135
|
-
"confidence", "probabilities", "probability_keys", "probability_mass", "score_legend", "score_consistency", "choice_option", "score_range"];
|
|
140
|
+
"confidence", "box_coordinates", "probabilities", "probability_keys", "probability_mass", "score_legend", "score_consistency", "choice_option", "score_range"];
|
|
136
141
|
export function isSystemOneResponseReason(value) {
|
|
137
142
|
return typeof value === "string" && responseReasons.includes(value);
|
|
138
143
|
}
|
|
@@ -205,6 +210,17 @@ export function validateAnswers(questions, answers) {
|
|
|
205
210
|
throw new SystemOneError("System One returned no answer for a question", null, undefined, "answer_shape");
|
|
206
211
|
if (a.type !== q.type)
|
|
207
212
|
throw new SystemOneError("System One answer type does not match its question", null, undefined, "answer_type");
|
|
213
|
+
if (q.type === "box") {
|
|
214
|
+
const box = a.box;
|
|
215
|
+
if (!box || typeof box !== "object" || Array.isArray(box) || Object.keys(box).length !== 4 || !["top", "bottom", "left", "right"].every(edge => unit(box[edge])))
|
|
216
|
+
throw new SystemOneError("System One answer: a box's edges are not fractions in [0, 1]", null, undefined, "box_coordinates");
|
|
217
|
+
// An edge pair that runs backwards is a box with negative width or height: not a box.
|
|
218
|
+
if (box.top > box.bottom || box.left > box.right)
|
|
219
|
+
throw new SystemOneError("System One answer: a box's top and left edges cannot lie past its bottom and right", null, undefined, "box_coordinates");
|
|
220
|
+
if (!(a.confidence === null || unit(a.confidence)))
|
|
221
|
+
throw new SystemOneError("System One answer: confidence is not in [0, 1]", null, undefined, "confidence");
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
208
224
|
if (q.type === "noul") {
|
|
209
225
|
if (!unit(a.noul))
|
|
210
226
|
throw new SystemOneError("System One answer: noul is not a probability", null, undefined, "noul_probability");
|
package/dist/workflow.d.ts
CHANGED
|
@@ -592,6 +592,7 @@ export declare function workflowSha256(workflow: Workflow): string;
|
|
|
592
592
|
/** Bound the complete document before any recursive schema or semantic traversal. Shared
|
|
593
593
|
* objects are valid, but each occurrence consumes the budget; cycles are never JSON. */
|
|
594
594
|
export declare function workflowDocumentError(value: unknown): string | undefined;
|
|
595
|
+
/** Whether a workflow can run, checked without running it: `errors` refuse it, `warnings` advise and never refuse. */
|
|
595
596
|
export declare function validateWorkflow(workflow: Workflow, opts?: {
|
|
596
597
|
executeCode?: boolean;
|
|
597
598
|
input?: Record<string, unknown>;
|
|
@@ -605,9 +606,11 @@ export declare function validateWorkflow(workflow: Workflow, opts?: {
|
|
|
605
606
|
};
|
|
606
607
|
}): {
|
|
607
608
|
ok: true;
|
|
609
|
+
warnings?: string[];
|
|
608
610
|
} | {
|
|
609
611
|
ok: false;
|
|
610
612
|
errors: string[];
|
|
613
|
+
warnings?: string[];
|
|
611
614
|
};
|
|
612
615
|
export declare class EscalationSignal extends Error {
|
|
613
616
|
readonly escalation: Escalation;
|
package/dist/workflow.js
CHANGED
|
@@ -331,6 +331,46 @@ export function workflowDocumentError(value) {
|
|
|
331
331
|
* without evaluating authored expressions or probing transforms. This is not execution admission;
|
|
332
332
|
* trusted/default validation and runtime output checks remain authoritative. */
|
|
333
333
|
const RETRY_ON_NAMES = [...CALL_RETRY_CLASSES, ...EFFECT_FAILURE_CODES];
|
|
334
|
+
/** Advice the validator gives without refusing: a shape that runs and costs more than it needs to. A map with no
|
|
335
|
+
* `resultPath` whose body writes no `as` returns each item's whole state, which holds the list the map ran over: the
|
|
336
|
+
* map's result, and every state after it, grow with the square of its items. */
|
|
337
|
+
function workflowWarnings(workflow) {
|
|
338
|
+
const warnings = [];
|
|
339
|
+
// Warnings are given for a document the validator refuses too, so a field may be missing or of the wrong kind.
|
|
340
|
+
const list = (value) => (Array.isArray(value) ? value : []);
|
|
341
|
+
const visit = (node) => {
|
|
342
|
+
if (!node || typeof node !== "object")
|
|
343
|
+
return;
|
|
344
|
+
switch (node.node) {
|
|
345
|
+
case "chain":
|
|
346
|
+
list(node.steps).forEach(visit);
|
|
347
|
+
break;
|
|
348
|
+
case "parallel":
|
|
349
|
+
list(node.branches).forEach(visit);
|
|
350
|
+
break;
|
|
351
|
+
case "map":
|
|
352
|
+
if (node.resultPath === undefined && node.body && typeof node.body === "object" && !node.body.as) {
|
|
353
|
+
warnings.push(`map "${node.label}": each item's result is its whole state, including ${node.itemsPath}; set resultPath (or an as in the body) for a large map`);
|
|
354
|
+
}
|
|
355
|
+
visit(node.body);
|
|
356
|
+
break;
|
|
357
|
+
case "loop":
|
|
358
|
+
visit(node.body);
|
|
359
|
+
break;
|
|
360
|
+
case "route":
|
|
361
|
+
if (node.branches && typeof node.branches === "object")
|
|
362
|
+
Object.values(node.branches).forEach((branch) => visit(branch?.body));
|
|
363
|
+
break;
|
|
364
|
+
case "workflow":
|
|
365
|
+
visit(node.workflow?.root);
|
|
366
|
+
break;
|
|
367
|
+
default: break;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
visit(workflow.root);
|
|
371
|
+
return warnings;
|
|
372
|
+
}
|
|
373
|
+
/** Whether a workflow can run, checked without running it: `errors` refuse it, `warnings` advise and never refuse. */
|
|
334
374
|
export function validateWorkflow(workflow, opts) {
|
|
335
375
|
const bounded = workflowDocumentError(workflow);
|
|
336
376
|
if (bounded)
|
|
@@ -1330,7 +1370,8 @@ export function validateWorkflow(workflow, opts) {
|
|
|
1330
1370
|
}
|
|
1331
1371
|
if (!errors.length)
|
|
1332
1372
|
errors.push(...workflowShapeErrors(workflow, true));
|
|
1333
|
-
|
|
1373
|
+
const warnings = workflowWarnings(workflow);
|
|
1374
|
+
return errors.length ? { ok: false, errors, ...(warnings.length ? { warnings } : {}) } : { ok: true, ...(warnings.length ? { warnings } : {}) };
|
|
1334
1375
|
}
|
|
1335
1376
|
function interpolate(template, state) {
|
|
1336
1377
|
return template.replace(/\{([a-zA-Z0-9_.$]+)\}/g, (_, p) => {
|