@parcha/agentrun-dsl 0.1.0-beta.29 → 0.1.0-beta.291
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/NOTICE +2 -0
- package/README.md +11 -7
- package/dist/author-references.d.ts +2 -2
- package/dist/author-references.js +2 -2
- package/dist/author.d.ts +0 -2
- package/dist/author.js +7 -6
- package/dist/authoring.js +3 -2
- package/dist/cli.js +2 -1
- package/dist/code-exec.d.ts +19 -0
- package/dist/code-exec.js +54 -5
- package/dist/decision-provider.d.ts +11 -2
- package/dist/decision-provider.js +12 -4
- package/dist/decision-receipts.d.ts +24 -3
- package/dist/decision-receipts.js +2 -0
- package/dist/dry-run.d.ts +31 -1
- package/dist/dry-run.js +103 -14
- package/dist/edit.d.ts +158 -0
- package/dist/edit.js +1486 -0
- package/dist/evidence.d.ts +19 -0
- package/dist/evidence.js +63 -0
- package/dist/index.d.ts +12 -9
- package/dist/index.js +14 -9
- package/dist/pattern-screen.d.ts +14 -0
- package/dist/pattern-screen.js +451 -0
- package/dist/pointer-warning.d.ts +14 -0
- package/dist/pointer-warning.js +22 -0
- package/dist/predicates.d.ts +23 -3
- package/dist/predicates.js +48 -6
- package/dist/record.d.ts +4 -0
- package/dist/record.js +6 -0
- package/dist/recovery/binding.js +2 -1
- package/dist/recovery/call-key.d.ts +0 -4
- package/dist/recovery/call-key.js +0 -7
- package/dist/recovery/driver.d.ts +20 -14
- package/dist/recovery/driver.js +48 -26
- package/dist/recovery/frozen-snapshot.js +8 -8
- package/dist/recovery/handoff-receipts.d.ts +0 -35
- package/dist/recovery/handoff-receipts.js +2 -44
- package/dist/recovery/index.d.ts +2 -7
- package/dist/recovery/index.js +2 -6
- package/dist/recovery/item-state.d.ts +2 -1
- package/dist/recovery/item-state.js +7 -13
- package/dist/recovery/with-recovery.js +4 -2
- package/dist/submit-envelope.d.ts +1 -1
- package/dist/submit-envelope.js +11 -7
- package/dist/system-one.d.ts +0 -4
- package/dist/system-one.js +7 -8
- package/dist/vocabulary.d.ts +7 -2
- package/dist/vocabulary.js +7 -1
- package/dist/workflow-shape.js +4 -2
- package/dist/workflow.d.ts +64 -13
- package/dist/workflow.js +511 -204
- package/dist/zod-json-contract.js +6 -8
- package/package.json +7 -3
- package/schema/workflow.schema.json +93 -0
- package/skills/author/references/jev-decisions.md +10 -5
- package/skills/author/references/language.md +5 -4
- package/dist/recovery/effect-failure.d.ts +0 -34
- package/dist/recovery/effect-failure.js +0 -62
- package/dist/recovery/handoff-block.d.ts +0 -36
- package/dist/recovery/handoff-block.js +0 -148
- package/dist/recovery/handoff-digest.d.ts +0 -58
- package/dist/recovery/handoff-digest.js +0 -195
- package/dist/recovery/handoff-files.d.ts +0 -54
- package/dist/recovery/handoff-files.js +0 -162
- package/dist/recovery/handoff-redact.d.ts +0 -12
- package/dist/recovery/handoff-redact.js +0 -44
- package/dist/recovery/handoff.d.ts +0 -44
- package/dist/recovery/handoff.js +0 -46
package/dist/dry-run.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Compile } from "typebox/compile";
|
|
|
2
2
|
import { runWorkflow, validateWorkflow, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError } from "./workflow.js";
|
|
3
3
|
import { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
4
4
|
import { synthesizeAnswers } from "./system-one.js";
|
|
5
|
+
import { isRecord } from "./record.js";
|
|
5
6
|
/** A provider for every id the workflow names, and a default: the dry run answers each decision itself, so a node's
|
|
6
7
|
* provider and timeoutMs hold it to no host's providers. */
|
|
7
8
|
function syntheticProviders(workflow) {
|
|
@@ -13,29 +14,63 @@ function syntheticProviders(workflow) {
|
|
|
13
14
|
const provider = (id) => ({ id, needs: [], capabilities, decide: async () => { throw new Error("A dry run answers its decisions itself."); } });
|
|
14
15
|
return { providers: Object.fromEntries([...ids].map((id) => [id, provider(id)])), default: "dry-run" };
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
/** The default: a million values and 16 million characters, far past what a real workflow's dry run builds (a few
|
|
18
|
+
* thousand values at most), and well within a host's memory (a few hundred MB at worst). */
|
|
19
|
+
export const SYNTHESIS_BUDGET = { values: 1_000_000, chars: 16_000_000 };
|
|
20
|
+
/** The schema asked synthesis for more than its budget: the dry run ends not run, saying so. */
|
|
21
|
+
export class SynthesisTooLarge extends Error {
|
|
22
|
+
name = "SynthesisTooLarge";
|
|
23
|
+
}
|
|
24
|
+
/** A budget's limits, each field the default unless given as a number (a field given as undefined keeps the default). */
|
|
25
|
+
const spendOf = (limit = {}) => ({
|
|
26
|
+
values: 0,
|
|
27
|
+
chars: 0,
|
|
28
|
+
limit: { values: typeof limit.values === "number" ? limit.values : SYNTHESIS_BUDGET.values, chars: typeof limit.chars === "number" ? limit.chars : SYNTHESIS_BUDGET.chars },
|
|
29
|
+
});
|
|
30
|
+
/** A literal's characters as the value it is (a const, an enum's first): its serialized size. */
|
|
31
|
+
const literalChars = (value) => JSON.stringify(value)?.length ?? 0;
|
|
32
|
+
function charge(spend, values, chars) {
|
|
33
|
+
spend.values += values;
|
|
34
|
+
spend.chars += chars;
|
|
35
|
+
if (spend.values > spend.limit.values || spend.chars > spend.limit.chars) {
|
|
36
|
+
throw new SynthesisTooLarge(`the schema is too large to synthesize: past ${spend.limit.values} values or ${spend.limit.chars} characters`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** A value of `schema` (its `$ref`s read from `definitions`), synthesized within `budget` (SYNTHESIS_BUDGET when none):
|
|
40
|
+
* past it, SynthesisTooLarge. */
|
|
41
|
+
export function synthesizeInstance(schema, definitions = {}, depth = 0, budget = SYNTHESIS_BUDGET) {
|
|
42
|
+
return synthesize(schema, definitions, depth, spendOf(budget));
|
|
43
|
+
}
|
|
44
|
+
function synthesize(schema, definitions, depth, spend) {
|
|
45
|
+
// Every value it makes is counted before it is made, once (a $ref, an anyOf or a oneOf is the value it leads to, not one
|
|
46
|
+
// of its own): past the budget it throws, having built no more than the budget.
|
|
17
47
|
if (depth > 12 || !schema || typeof schema !== "object")
|
|
18
|
-
return null;
|
|
48
|
+
return (charge(spend, 1, 0), null);
|
|
19
49
|
const spec = schema;
|
|
20
50
|
if (typeof spec.$ref === "string") {
|
|
21
51
|
const match = /^#\/definitions\/(.+)$/.exec(spec.$ref);
|
|
22
|
-
return match && definitions[match[1]] ?
|
|
52
|
+
return match && definitions[match[1]] ? synthesize(definitions[match[1]], definitions, depth + 1, spend) : (charge(spend, 1, 0), null);
|
|
23
53
|
}
|
|
54
|
+
// A literal is charged its serialized size: one written long in the schema does not escape the character budget.
|
|
24
55
|
if (spec.const !== undefined)
|
|
25
|
-
return spec.const;
|
|
56
|
+
return (charge(spend, 1, literalChars(spec.const)), spec.const);
|
|
26
57
|
if (Array.isArray(spec.enum) && spec.enum.length)
|
|
27
|
-
return spec.enum[0];
|
|
58
|
+
return (charge(spend, 1, literalChars(spec.enum[0])), spec.enum[0]);
|
|
28
59
|
if (Array.isArray(spec.anyOf) && spec.anyOf.length) {
|
|
29
60
|
const branch = spec.anyOf.find((candidate) => candidate?.type !== "null") ?? spec.anyOf[0];
|
|
30
|
-
return
|
|
61
|
+
return synthesize(branch, definitions, depth + 1, spend);
|
|
31
62
|
}
|
|
32
63
|
if (Array.isArray(spec.oneOf) && spec.oneOf.length)
|
|
33
|
-
return
|
|
64
|
+
return synthesize(spec.oneOf[0], definitions, depth + 1, spend);
|
|
65
|
+
// The one value made below.
|
|
66
|
+
charge(spend, 1, 0);
|
|
34
67
|
const type = Array.isArray(spec.type) ? spec.type[0] : spec.type;
|
|
35
68
|
if (type === "object" || (!type && spec.properties)) {
|
|
36
69
|
const out = Object.create(null);
|
|
37
70
|
for (const [key, property] of Object.entries(spec.properties || {})) {
|
|
38
|
-
|
|
71
|
+
// Its name is built into every value made under it, and serialized with it: charged before it is added.
|
|
72
|
+
charge(spend, 0, key.length);
|
|
73
|
+
out[key] = synthesize(property, definitions, depth + 1, spend);
|
|
39
74
|
}
|
|
40
75
|
return { ...out };
|
|
41
76
|
}
|
|
@@ -45,12 +80,17 @@ export function synthesizeInstance(schema, definitions = {}, depth = 0) {
|
|
|
45
80
|
const min = Number.isInteger(spec.minItems) ? spec.minItems : 1;
|
|
46
81
|
if (!spec.items)
|
|
47
82
|
return [];
|
|
48
|
-
|
|
83
|
+
// Each item is at least one value: a length past what the budget has left is refused before the array is made.
|
|
84
|
+
const length = Math.max(1, min);
|
|
85
|
+
if (length > spend.limit.values - spend.values)
|
|
86
|
+
charge(spend, length, 0);
|
|
87
|
+
return Array.from({ length }, () => synthesize(spec.items, definitions, depth + 1, spend));
|
|
49
88
|
}
|
|
50
89
|
if (type === "string") {
|
|
51
90
|
if (spec.maxLength === 0)
|
|
52
91
|
return "";
|
|
53
92
|
const min = Number.isInteger(spec.minLength) ? spec.minLength : 1;
|
|
93
|
+
charge(spend, 0, Math.max(1, min));
|
|
54
94
|
return "x".repeat(Math.max(1, min));
|
|
55
95
|
}
|
|
56
96
|
if (type === "integer") {
|
|
@@ -90,6 +130,8 @@ export function synthesizeInstance(schema, definitions = {}, depth = 0) {
|
|
|
90
130
|
return false;
|
|
91
131
|
if (type === "null")
|
|
92
132
|
return null;
|
|
133
|
+
// A schema synthesis cannot read: one character.
|
|
134
|
+
charge(spend, 0, 1);
|
|
93
135
|
return "x";
|
|
94
136
|
}
|
|
95
137
|
function unsupportedConstructs(schema, path, found, depth = 0) {
|
|
@@ -151,11 +193,21 @@ export async function dryRunWorkflow(workflow, opts = {}) {
|
|
|
151
193
|
scanSchemas(workflow);
|
|
152
194
|
if (skipped.length)
|
|
153
195
|
return { ok: true, status: "not_run", skipped };
|
|
196
|
+
// One budget for everything this dry run synthesizes.
|
|
197
|
+
const spend = spendOf(opts.budget);
|
|
154
198
|
let input = opts.input ?? {};
|
|
155
199
|
if (opts.input === undefined && workflow.input) {
|
|
156
200
|
const schema = resolveSchemaForWorkflow(workflow, workflow.schemas[workflow.input.schemaId]);
|
|
157
|
-
|
|
158
|
-
|
|
201
|
+
let generated;
|
|
202
|
+
try {
|
|
203
|
+
generated = synthesize(schema, schema.definitions ?? workflow.schemas, 0, spend);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (error instanceof SynthesisTooLarge)
|
|
207
|
+
return { ok: true, status: "not_run", skipped: [error.message] };
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
if (!isRecord(generated) || !Compile(schema).Check(generated)) {
|
|
159
211
|
return { ok: true, status: "not_run", skipped: ["Could not synthesize a valid input object. Supply input explicitly to dryRunWorkflow or the dry-run CLI."] };
|
|
160
212
|
}
|
|
161
213
|
input = generated;
|
|
@@ -173,12 +225,43 @@ export async function dryRunWorkflow(workflow, opts = {}) {
|
|
|
173
225
|
// Why the dry run stopped early, kept here: the interpreter may wrap what an adapter throws.
|
|
174
226
|
let stopped;
|
|
175
227
|
const stop = (reason) => { stopped ??= reason; throw new Error(stopped); };
|
|
228
|
+
/** A step's synthetic answer within the run's budget: past it, the dry run stops (the interpreter may wrap the throw). */
|
|
229
|
+
const synthesized = (make) => {
|
|
230
|
+
try {
|
|
231
|
+
return make();
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (error instanceof SynthesisTooLarge)
|
|
235
|
+
stop(error.message);
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const deadlineMs = opts.deadlineMs ?? 60_000;
|
|
240
|
+
const deadline = Date.now() + deadlineMs;
|
|
241
|
+
const maxVisits = opts.maxVisits ?? maxSteps * 10;
|
|
242
|
+
let visits = 0;
|
|
243
|
+
const pastDeadline = () => {
|
|
244
|
+
if (Date.now() > deadline)
|
|
245
|
+
stop(`The dry run stopped past its ${deadlineMs} ms deadline.`);
|
|
246
|
+
};
|
|
247
|
+
/** A node's visit (a loop's body each iteration, a map's body for each item), counted against maxVisits and the
|
|
248
|
+
* deadline, so a loop whose body asks nothing (no step) still ends. Synchronous: it reads the clock, never a timer, so
|
|
249
|
+
* a run that never yields still stops. */
|
|
250
|
+
const visit = () => {
|
|
251
|
+
if (opts.signal?.aborted)
|
|
252
|
+
stop("The dry run was stopped before it finished.");
|
|
253
|
+
visits += 1;
|
|
254
|
+
if (visits > maxVisits)
|
|
255
|
+
stop(`The dry run stopped after ${maxVisits} node visits: on synthetic values the workflow's loops or maps go on further, asking nothing. Supply input, or lower a loop's maxIters.`);
|
|
256
|
+
pastDeadline();
|
|
257
|
+
};
|
|
176
258
|
const step = async () => {
|
|
177
259
|
if (opts.signal?.aborted)
|
|
178
260
|
stop("The dry run was stopped before it finished.");
|
|
179
261
|
steps += 1;
|
|
180
262
|
if (steps > maxSteps)
|
|
181
263
|
stop(`The dry run stopped after ${maxSteps} synthetic steps: on synthetic values the workflow's loops or maps go on further. Supply input, or lower a loop's maxIters.`);
|
|
264
|
+
pastDeadline();
|
|
182
265
|
if (steps % 64 === 0) {
|
|
183
266
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
184
267
|
if (opts.signal?.aborted)
|
|
@@ -188,13 +271,14 @@ export async function dryRunWorkflow(workflow, opts = {}) {
|
|
|
188
271
|
const runCode = opts.runCode;
|
|
189
272
|
try {
|
|
190
273
|
const result = await runWorkflow(workflow, input, {
|
|
274
|
+
onVisit: () => visit(),
|
|
191
275
|
sop: opts.sop,
|
|
192
276
|
...(runCode ? { runCode: async (...args) => { await step(); return runCode(...args); } } : {}),
|
|
193
277
|
onEvent: (event) => { if (typeof event.label === "string")
|
|
194
278
|
currentLabel = event.label; },
|
|
195
279
|
runNode: async ({ schema, review }) => {
|
|
196
280
|
await step();
|
|
197
|
-
const candidate =
|
|
281
|
+
const candidate = synthesized(() => synthesize(schema, schema.definitions ?? workflow.schemas, 0, spend));
|
|
198
282
|
if (review)
|
|
199
283
|
await review(candidate);
|
|
200
284
|
return candidate;
|
|
@@ -202,7 +286,11 @@ export async function dryRunWorkflow(workflow, opts = {}) {
|
|
|
202
286
|
// A node that requires evidence gets a placeholder, as a provider that gives evidence would answer it.
|
|
203
287
|
runJudge: async ({ questions, evidence }) => {
|
|
204
288
|
await step();
|
|
205
|
-
|
|
289
|
+
// Its answers are synthetic values like any step's: each charged its serialized size against the run's budget (a
|
|
290
|
+
// choice's first option may be a long string, and a map collects one per item).
|
|
291
|
+
const answers = synthesizeAnswers(questions);
|
|
292
|
+
synthesized(() => charge(spend, Object.keys(answers).length, literalChars(answers)));
|
|
293
|
+
return { answers, model: "synthetic", usage: null, cost_usd: null, request_sha256: "",
|
|
206
294
|
...(evidence === "required" ? { evidence: [{ url: "https://example.invalid/dry-run", title: null, excerpts: [], scope: "dry_run" }] } : {}) };
|
|
207
295
|
},
|
|
208
296
|
syntheticEffects: true,
|
|
@@ -211,13 +299,14 @@ export async function dryRunWorkflow(workflow, opts = {}) {
|
|
|
211
299
|
await step();
|
|
212
300
|
return node.via === "shell"
|
|
213
301
|
? { code: 0, stdout: "{}", stderr: "", truncated: false }
|
|
214
|
-
:
|
|
302
|
+
: synthesized(() => synthesize(schema ?? (workflow.schemas || {})[node.out], schema?.definitions ?? workflow.schemas ?? {}, 0, spend));
|
|
215
303
|
},
|
|
216
304
|
});
|
|
217
305
|
if (result.status === "escalated") {
|
|
218
306
|
// Synthetic values tripping an escalate predicate proves nothing about real cases.
|
|
219
307
|
return { ok: true, status: "not_run", skipped: [`escalated:${result.escalation.kind}@${result.escalation.stage} on synthetic values`] };
|
|
220
308
|
}
|
|
309
|
+
opts.onOutput?.(result.output);
|
|
221
310
|
return { ok: true, status: "passed" };
|
|
222
311
|
}
|
|
223
312
|
catch (error) {
|
package/dist/edit.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/** A workflow document as JSON: an object whose `root` is a node. */
|
|
2
|
+
export type WorkflowDocument = Record<string, unknown>;
|
|
3
|
+
/** A node as JSON: an object whose `node` is its kind. */
|
|
4
|
+
export type WorkflowNodeJson = Record<string, unknown>;
|
|
5
|
+
/** Where a child sits under its parent node: the pointer segments from the parent to it. A chain's `steps` and a
|
|
6
|
+
* parallel's `branches` hold many, by index; a map's or a loop's `body`, a route branch's `branches/<name>/body` (the
|
|
7
|
+
* name pointer-escaped, as in a graph path) and a child workflow's `workflow/root` hold one. The document holds its
|
|
8
|
+
* root at `root`, under the parent path `""`. */
|
|
9
|
+
export type Slot = "root" | "steps" | "branches" | "body" | "workflow/root" | `branches/${string}/body`;
|
|
10
|
+
/** What an operation returns: the next document and what happened to the nodes of the one it was given. */
|
|
11
|
+
export type EditResult = {
|
|
12
|
+
doc: WorkflowDocument;
|
|
13
|
+
/** Each node whose path changed, from its path before to its path after, in the input's document order. */
|
|
14
|
+
moved: Map<string, string>;
|
|
15
|
+
/** The paths, in the result, of the nodes the input did not have. */
|
|
16
|
+
added: string[];
|
|
17
|
+
/** The paths, in the input, of the nodes the result does not have. */
|
|
18
|
+
removed: string[];
|
|
19
|
+
/** The paths, in the result, of the nodes that were kept with their own fields changed. */
|
|
20
|
+
changed: string[];
|
|
21
|
+
};
|
|
22
|
+
/** What rename returns: an EditResult, and the code and shell sources in scope that mention the old key. */
|
|
23
|
+
export type RenameResult = EditResult & {
|
|
24
|
+
mentions: string[];
|
|
25
|
+
};
|
|
26
|
+
/** What duplicate returns: an EditResult, and the paths, in the result, of the copy's code and shell sources that
|
|
27
|
+
* mention a key the copy writes under a fresh name, by its old name. */
|
|
28
|
+
export type DuplicateResult = EditResult & {
|
|
29
|
+
mentions: string[];
|
|
30
|
+
};
|
|
31
|
+
/** Every code an EditError carries. */
|
|
32
|
+
export declare const EDIT_ERROR_CODES: readonly ["DOCUMENT_INVALID", "PATH_NOT_FOUND", "SLOT_INVALID", "INDEX_OUT_OF_RANGE", "NODE_INVALID", "FIELD_INVALID", "NAME_INVALID", "NAME_TAKEN", "NAME_SHARED", "BRANCH_NOT_FOUND", "BRANCH_TAKEN", "BRANCH_IN_USE", "MOVE_INTO_SELF", "WRAP_INVALID", "UNWRAP_INVALID", "STRUCTURE_INVALID", "SCHEMA_NOT_FOUND", "SCHEMA_IN_USE", "SCHEMA_INVALID"];
|
|
33
|
+
export type EditErrorCode = typeof EDIT_ERROR_CODES[number];
|
|
34
|
+
/** The one error the operations throw. `path` is the node it is about, in the input document where that node existed
|
|
35
|
+
* there; `related` names other nodes the error is about: the one holding a taken name, the other writers of a key. */
|
|
36
|
+
export declare class EditError extends Error {
|
|
37
|
+
readonly code: EditErrorCode;
|
|
38
|
+
readonly path: string;
|
|
39
|
+
readonly related: readonly string[];
|
|
40
|
+
constructor(code: EditErrorCode, path: string, message: string, related?: readonly string[]);
|
|
41
|
+
}
|
|
42
|
+
/** The placeholder a required field takes in a new node: a value insert accepts and the validator flags until someone
|
|
43
|
+
* fills it in (an empty text, an empty state map, a predicate with no name, a deadline of 0 seconds), or, for a loop's
|
|
44
|
+
* `maxIters`, the smallest bound. placeholderNode and wrap fill fields from it. */
|
|
45
|
+
export declare const FIELD_PLACEHOLDERS: Readonly<Record<string, unknown>>;
|
|
46
|
+
/** The fields setField writes on this node: its kind's (and its route form's) own fields, without `node` and the child
|
|
47
|
+
* slots. A property panel lists these. */
|
|
48
|
+
export declare function editableFields(node: WorkflowNodeJson): string[];
|
|
49
|
+
/** The fields the schema requires of this node's kind (and its route form), `node` included. */
|
|
50
|
+
export declare function requiredFields(node: WorkflowNodeJson): string[];
|
|
51
|
+
/** Where the node at `path` sits: its parent's path, the slot it is in, and its index there (0 in a slot that holds one
|
|
52
|
+
* node). Undefined when no node sits there. */
|
|
53
|
+
export declare function locate(doc: WorkflowDocument, path: string): {
|
|
54
|
+
parentPath: string;
|
|
55
|
+
slot: Slot;
|
|
56
|
+
index: number;
|
|
57
|
+
} | undefined;
|
|
58
|
+
/** Put `node` (copied) into `slot` of the node at `parentPath`, at `index`. In a chain's steps or a parallel's branches
|
|
59
|
+
* the index is a position, 0 to the count. A slot that holds one node takes index 0 when empty; when it holds a node,
|
|
60
|
+
* 0 puts the new one first and 1 puts it last, in a new chain of the two. */
|
|
61
|
+
export declare function insert(doc: WorkflowDocument, parentPath: string, slot: Slot, index: number, node: WorkflowNodeJson): EditResult;
|
|
62
|
+
/** Take out the node at `path`, and everything inside it. */
|
|
63
|
+
export declare function remove(doc: WorkflowDocument, path: string): EditResult;
|
|
64
|
+
/** Move the node at `fromPath` into `slot` of the node at `toParentPath`, at `index`, counted in the document as given:
|
|
65
|
+
* the drop point a canvas shows. A node never moves inside itself. */
|
|
66
|
+
export declare function move(doc: WorkflowDocument, fromPath: string, toParentPath: string, slot: Slot, index: number): EditResult;
|
|
67
|
+
/** Put a copy of the node at `path` right after it: the next step or branch, or, in a slot that holds one node, the
|
|
68
|
+
* second step of a new chain. Every node of the copy gets a fresh label, every key it writes a fresh name, and its own
|
|
69
|
+
* references follow its keys; the copy's code and shell sources that mention an old key are listed in `mentions`. */
|
|
70
|
+
export declare function duplicate(doc: WorkflowDocument, path: string): DuplicateResult;
|
|
71
|
+
/** The containers wrap makes. */
|
|
72
|
+
export type WrapKind = "map" | "loop" | "route" | "parallel" | "chain";
|
|
73
|
+
/** Put the nodes at `paths` (one node, or consecutive steps or branches of one container, in any order) into a new
|
|
74
|
+
* container of `kind`, where the first of them was. A map's, loop's or route's body is the one node or a chain of
|
|
75
|
+
* them; a parallel takes each as a branch. The new container's fields are placeholders the validator flags. */
|
|
76
|
+
export declare function wrap(doc: WorkflowDocument, paths: readonly string[], kind: WrapKind): EditResult;
|
|
77
|
+
/** Put the children of the container at `path` where it was: a chain's steps or a parallel's branches, the body of a
|
|
78
|
+
* map or a loop, or the body of the route branch `branch` names. Into a chain they are spliced; a parallel's branches
|
|
79
|
+
* join an enclosing parallel; a slot that holds one node takes one child, or a chain of a parallel's branches. */
|
|
80
|
+
export declare function unwrap(doc: WorkflowDocument, path: string, branch?: string): EditResult;
|
|
81
|
+
/** Add a branch to the parallel or route at `path`: `node` (copied) last among a parallel's branches, or as the body of
|
|
82
|
+
* a new route branch `name`, after the others. */
|
|
83
|
+
export declare function addBranch(doc: WorkflowDocument, path: string, node: WorkflowNodeJson, name?: string): EditResult;
|
|
84
|
+
/** Take out a branch of the parallel or route at `path`: a parallel's by its index, a route's by its name. */
|
|
85
|
+
export declare function removeBranch(doc: WorkflowDocument, path: string, branch: string | number): EditResult;
|
|
86
|
+
/** Rename branch `from` of the route at `path` to `to`, in its place among the others; `otherwise` and `unsure` follow. */
|
|
87
|
+
export declare function renameBranch(doc: WorkflowDocument, path: string, from: string, to: string): EditResult;
|
|
88
|
+
/** Write `value` (copied) at the field of the node at `path`, in its place; `undefined` removes an optional field. */
|
|
89
|
+
export declare function setField(doc: WorkflowDocument, path: string, field: string, value: unknown): EditResult;
|
|
90
|
+
/** Rename the label of the node at `path`. When the label is the key the node writes (an agent, decide, extract or code
|
|
91
|
+
* node with no `as`), every reference in scope follows it, and the code and shell sources in scope that mention the old
|
|
92
|
+
* key are listed in `mentions`, unchanged: a code node's own code included, when it names the key. */
|
|
93
|
+
export declare function rename(doc: WorkflowDocument, path: string, name: string): RenameResult;
|
|
94
|
+
/** Which key renameKey renames: the node's `as` (the default), or a map's `failedAs`. */
|
|
95
|
+
export type RenameKeyOptions = {
|
|
96
|
+
field?: "as" | "failedAs";
|
|
97
|
+
};
|
|
98
|
+
/** Rename the state key the node at `path` writes: its `as` when it has one, else its label when the label is the key
|
|
99
|
+
* (an agent, decide, extract or code node with no `as`, where this is `rename`); or, with `field: "failedAs"`, the key a
|
|
100
|
+
* map writes its failed items under. Every reference in scope follows it, `<key>$answers` and `<key>$verify` included,
|
|
101
|
+
* and the code and shell sources in scope that mention the old key are listed in `mentions`, unchanged. */
|
|
102
|
+
export declare function renameKey(doc: WorkflowDocument, path: string, name: string, options?: RenameKeyOptions): RenameResult;
|
|
103
|
+
/** Write `criteria`, the text Jev reads to choose it, on branch `branch` of the judged route at `path`, in its place;
|
|
104
|
+
* `undefined` removes it. A route by value matches its branches by name and takes no criteria. */
|
|
105
|
+
export declare function setBranchCriteria(doc: WorkflowDocument, path: string, branch: string, criteria: string | undefined): EditResult;
|
|
106
|
+
/** The JSON Pointers of the values that name schema `id` of a scope ("" for the document, or a workflow node's path
|
|
107
|
+
* for its child's schemas): the workflow's `input.schemaId` and `output.schemaId`, a `$ref` from another of its
|
|
108
|
+
* schemas, and the `out` and `verify.out` of its nodes (a workflow node's `out` names its parent's schema). */
|
|
109
|
+
export declare function schemaUsers(doc: WorkflowDocument, id: string, scope?: string): string[];
|
|
110
|
+
/** Write `schema` (copied) as schema `id` of a scope ("" for the document, or a workflow node's path for its child), in
|
|
111
|
+
* its place when it exists; `undefined` removes it, unless something still names it (`schemaUsers`). */
|
|
112
|
+
export declare function setSchema(doc: WorkflowDocument, id: string, schema: Record<string, unknown> | undefined, scope?: string): EditResult;
|
|
113
|
+
/** Write the document's own `input` or `output` (copied): `{ schemaId }`, naming one of its schemas, and for the output
|
|
114
|
+
* an optional `path`, the state path its value is read from when the run ends. `undefined` removes the input; a workflow
|
|
115
|
+
* always has its output. Whether the schema exists and something sets the path is the validator's call. */
|
|
116
|
+
export declare function setWorkflowField(doc: WorkflowDocument, field: "input" | "output", value: Record<string, unknown> | undefined): EditResult;
|
|
117
|
+
/** A name a node may read, and what gives it: the path of the node that writes it, "input" (the workflow's input, or a
|
|
118
|
+
* child's), or "engine" (a map body's `item` and `item_index`). */
|
|
119
|
+
export type NameInScope = {
|
|
120
|
+
name: string;
|
|
121
|
+
from: string;
|
|
122
|
+
};
|
|
123
|
+
/** The names the node at `path` may read, each with what gives it, by the scope rules rename carries a key along: its
|
|
124
|
+
* workflow's input keys, a map body's `item` and `item_index`, and the keys (with their `<key>$answers` and
|
|
125
|
+
* `<key>$verify`) of each node whose write it runs after and sees. With `field`, the names that one field of the node
|
|
126
|
+
* reads, where it sees more than the rest: a map's `resultPath` its body's keys and item, a loop's `until` its body's
|
|
127
|
+
* keys, `verify` the node's own `as` and `submission`, a pick's or sift's `describe` its own `item` and `item_index`,
|
|
128
|
+
* and a workflow node's `workflow` (its child's `output.path`) the child's state. */
|
|
129
|
+
export declare function namesInScope(doc: WorkflowDocument, path: string, field?: string): NameInScope[];
|
|
130
|
+
/** The names the document's `output.path` may read, each with what gives it, as namesInScope gives a node's: its input
|
|
131
|
+
* keys, and the keys (with their `<key>$answers` and `<key>$verify`) of each node whose write is in the state when the
|
|
132
|
+
* run ends, which no key written in a map's body or a child workflow is. A terminal's fixed key is one: a report's, or
|
|
133
|
+
* a prose artifact's (which runs as a report), `report_markdown`, and a file artifact's `artifact`. */
|
|
134
|
+
export declare function outputNames(doc: WorkflowDocument): NameInScope[];
|
|
135
|
+
/** A reference a node makes: the JSON Pointer of the value it sits in, the name it reads (the head of its path), and
|
|
136
|
+
* `optional` for a whole-string placeholder marked `?` (`"{plan?}"`), which the engine fills with null while unset. */
|
|
137
|
+
export type NodeRead = {
|
|
138
|
+
pointer: string;
|
|
139
|
+
name: string;
|
|
140
|
+
optional?: true;
|
|
141
|
+
};
|
|
142
|
+
/** Each `{placeholder}` and state path the node at `path` reads, in its fields' order: the references rename carries,
|
|
143
|
+
* found by the same walk. A workflow node's include its child's `output.path`, which reads the child's state. */
|
|
144
|
+
export declare function readsOf(doc: WorkflowDocument, path: string): NodeRead[];
|
|
145
|
+
/** The `{placeholder` open at `offset` in `text`: the index of its `{` and the name typed after it up to the cursor, by
|
|
146
|
+
* the placeholder grammar (letters, digits, "_", "." and "$"; a reference may start with `state.`). Undefined when no
|
|
147
|
+
* placeholder's name holds the cursor. The placeholder may already be closed after it. */
|
|
148
|
+
export declare function openPlaceholderAt(text: string, offset: number): {
|
|
149
|
+
start: number;
|
|
150
|
+
prefix: string;
|
|
151
|
+
} | undefined;
|
|
152
|
+
/** `base`, or its stem (`base` without a `_<n>` ending) with the smallest `_<n>` from 2, so that no label, key,
|
|
153
|
+
* reference, input key or word of code of any scope of the document holds it (a child workflow's that holds no node
|
|
154
|
+
* yet among them), nor an engine key or a name `Object.prototype` has. `base` is a state key name. */
|
|
155
|
+
export declare function freshName(doc: WorkflowDocument, base: string): string;
|
|
156
|
+
/** The smallest node of `kind` for `doc`: its required fields in the schema's order, a fresh name as its label (and its
|
|
157
|
+
* `as`, where it needs one), and each other field's placeholder. A container is made by wrapping nodes that exist. */
|
|
158
|
+
export declare function placeholderNode(doc: WorkflowDocument, kind: string): WorkflowNodeJson;
|