@parcha/agentrun-dsl 0.1.0-beta.238 → 0.1.0-beta.240

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
@@ -188,7 +188,7 @@ The schema helpers resolve the owning workflow's schema catalog; `stageSchemaFor
188
188
 
189
189
  `@parcha/agentrun-dsl/edit` edits a workflow document as JSON, one pure function per edit, for a visual editor, a CLI or a server. It imports only the graph and the node vocabulary, so a browser bundles it, and it names a node by its graph path. `insert(doc, parentPath, slot, index, node)`, `remove(doc, path)`, `move(doc, fromPath, toParentPath, slot, index)`, `duplicate(doc, path)`, `wrap(doc, paths, kind)` (in a map, loop, route, parallel or chain), `unwrap(doc, path, branch?)`, `addBranch(doc, path, node, name?)`, `removeBranch(doc, path, branch)`, `renameBranch(doc, path, from, to)`, `setField(doc, path, field, value)`, `rename(doc, path, name)` and `renameKey(doc, path, name, options?)` each return `{ doc, moved, added, removed, changed }`. `doc` is the next document: the input is never mutated, and every subtree the edit did not touch is shared with it, byte for byte. `moved` maps each node whose path changed, old path to new; `added` and `removed` list the nodes only one of the two documents has; `changed` lists the nodes whose own fields changed. A slot is where a child sits under its parent: `steps`, `branches`, `body`, `branches/<name>/body`, `workflow/root`, or `root` under the parent path `""`; `locate(doc, path)` says which one holds a node, and `move` counts its index in the document as given, the drop point between two steps. An edit that would break the document's structure (a report inside a map, a chain with no steps, a parallel with one branch, a node of no known kind or without a required field) throws an `EditError` with a `code` from `EDIT_ERROR_CODES` and the `path` it is about, and writes nothing. Whether each reference is produced and each field filled in is still `validateWorkflow`'s to say: `wrap` gives its new container placeholders the validator flags on it (an empty `itemsPath`, `valuePath` or `until` predicate). `rename` changes a label. When the label is the key the node writes (an agent, decide, extract or code node with no `as`; a code node writes there when its code returns something other than a record), every `{placeholder}` and state path that reads the key in scope follows it, and the code and shell sources that mention it, or one of its `<key>$...` keys, are listed in `mentions`, unchanged. A renamed code node's own code is listed too when it names the key, since a record it returns with that key still writes the old name. `renameKey` renames the key a node writes the same way: its `as` when it has one, any kind's, else its label when that is the key, where it gives the document `rename` gives; `{ field: "failedAs" }` renames a map's `failedAs` instead. No edit gives a label, an `as`, a `failedAs` or a route branch a name `Object.prototype` has (`constructor`, `toString`, `__proto__` and the rest) or `prototype`: `rename`, `renameKey`, `renameBranch` and `setField` refuse one, and `insert` and `addBranch` refuse a node with one anywhere inside it; `validateWorkflow` refuses a document written with one (`NODE_FIELD_INVALID`, saying to rename it). With `{ reservedNames: "warn" }`, the check a run makes of a document already stored (`runWorkflow` and `runWorkflowSlice` make it so), each such name is a warning instead, listed in the result's `reserved` (`{ path, field, name }`): the engine reads every label, key, branch and state path as an own key, so a stored document that has one runs as written, and a read of `constructor` that nothing wrote is unset. `renameBranch` carries the route's `otherwise` and `unsure`, but not a value elsewhere that compares against the old branch name (a `field_equals` on the route's `as`, or the value a route by value reads), which the caller must change. `duplicate` copies code as it is, so a copied code node writes the same record keys as its source: duplicating a code branch of a parallel gives two branches that write one key, which the run refuses. The copy's reads of a copied code node's label follow its fresh label, so when that code returns a record naming the old label, those reads find nothing; `duplicate` lists the copy's code and shell sources that mention a key it renamed in `mentions`, as `rename` does. `editableFields(node)` and `requiredFields(node)` are the schema's fields for a node, as `setField` writes them.
190
190
 
191
- The same module answers what a property panel asks. `setBranchCriteria(doc, path, branch, criteria)` writes or removes (`undefined`) a judged route branch's criteria. `setSchema(doc, id, schema, scope?)` writes or removes a schema of the document, or of the child workflow of the workflow node at `scope`, and refuses to remove one that `schemaUsers(doc, id, scope?)` says is named: it lists the JSON Pointers of the workflow's `input.schemaId` and `output.schemaId`, each node's `out` and `verify.out`, and each `$ref` to `#/definitions/<id>` in another schema. `namesInScope(doc, path, field?)` lists the names the node at `path` may read, each `{ name, from }` with `from` the path of the node that writes it, `"input"` or `"engine"` (a map body's `item` and `item_index`), by the scope rules `rename` carries a key along; `field` asks for one field where it sees more (a map's `resultPath`, a loop's `until`, `verify`, a pick's or sift's `describe`, a workflow node's `workflow`). It cannot list a key only a code node's returned record writes, nor the keys of an input whose schema lists no properties. `readsOf(doc, path)` lists each `{placeholder}` and state path the node reads as `{ pointer, name }`, the references `rename` carries, and `openPlaceholderAt(text, offset)` finds the `{` open at a cursor and the name typed after it. `freshName(doc, base)` gives `base` or `<base>_<n>`, free in every scope (a child workflow's with no node yet included), and `placeholderNode(doc, kind)` the smallest node of a kind that holds no nodes, each required field holding its `FIELD_PLACEHOLDERS` value, which the validator flags until it is filled in.
191
+ The same module answers what a property panel asks. `setBranchCriteria(doc, path, branch, criteria)` writes or removes (`undefined`) a judged route branch's criteria. `setSchema(doc, id, schema, scope?)` writes or removes a schema of the document, or of the child workflow of the workflow node at `scope`, and refuses to remove one that `schemaUsers(doc, id, scope?)` says is named: it lists the JSON Pointers of the workflow's `input.schemaId` and `output.schemaId`, each node's `out` and `verify.out`, and each `$ref` to `#/definitions/<id>` in another schema. `setWorkflowField(doc, field, value)` writes the document's own `input` or `output` (`{ schemaId }`, and the output's optional `path`), or removes the input (`undefined`); `outputNames(doc)` lists the names that `path` may read, as `namesInScope` lists a node's: the input keys and the keys written outside any map body or child workflow, a terminal's fixed key among them (`report_markdown` for a report or a prose artifact, `artifact` for a file artifact). Like `namesInScope`, it cannot list a key only a code node's returned record writes. `namesInScope(doc, path, field?)` lists the names the node at `path` may read, each `{ name, from }` with `from` the path of the node that writes it, `"input"` or `"engine"` (a map body's `item` and `item_index`), by the scope rules `rename` carries a key along; `field` asks for one field where it sees more (a map's `resultPath`, a loop's `until`, `verify`, a pick's or sift's `describe`, a workflow node's `workflow`). It cannot list a key only a code node's returned record writes, nor the keys of an input whose schema lists no properties. `readsOf(doc, path)` lists each `{placeholder}` and state path the node reads as `{ pointer, name }`, the references `rename` carries, and `openPlaceholderAt(text, offset)` finds the `{` open at a cursor and the name typed after it. `freshName(doc, base)` gives `base` or `<base>_<n>`, free in every scope (a child workflow's with no node yet included), and `placeholderNode(doc, kind)` the smallest node of a kind that holds no nodes, each required field holding its `FIELD_PLACEHOLDERS` value, which the validator flags until it is filled in.
192
192
 
193
193
  The separate `@parcha/agentrun-dsl/demo` entrypoint provides the support-triage example. `@parcha/agentrun-dsl/schema` provides the generated workflow JSON Schema, a JSON file: import it with `import schema from '@parcha/agentrun-dsl/schema' with { type: 'json' };` (a plain `import` throws `ERR_IMPORT_ATTRIBUTE_MISSING`), or load it with `require('@parcha/agentrun-dsl/schema')` in CommonJS.
194
194
 
package/dist/edit.d.ts CHANGED
@@ -110,6 +110,10 @@ export declare function schemaUsers(doc: WorkflowDocument, id: string, scope?: s
110
110
  /** Write `schema` (copied) as schema `id` of a scope ("" for the document, or a workflow node's path for its child), in
111
111
  * its place when it exists; `undefined` removes it, unless something still names it (`schemaUsers`). */
112
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;
113
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
114
118
  * child's), or "engine" (a map body's `item` and `item_index`). */
115
119
  export type NameInScope = {
@@ -123,6 +127,11 @@ export type NameInScope = {
123
127
  * keys, `verify` the node's own `as` and `submission`, a pick's or sift's `describe` its own `item` and `item_index`,
124
128
  * and a workflow node's `workflow` (its child's `output.path`) the child's state. */
125
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[];
126
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
127
136
  * `optional` for a whole-string placeholder marked `?` (`"{plan?}"`), which the engine fills with null while unset. */
128
137
  export type NodeRead = {
package/dist/edit.js CHANGED
@@ -87,6 +87,9 @@
87
87
  // It refuses to remove a schema something names (schemaUsers lists them: the workflow's `input.schemaId` and
88
88
  // `output.schemaId`, a node's `out` and `verify.out`, and a `$ref` to `#/definitions/<id>` in another schema), and it
89
89
  // never renames one.
90
+ // - setWorkflowField writes the document's own `input` or `output` as given, and removes the input but never the
91
+ // output. outputNames lists what the output's `path` may read: the input keys and the keys written outside any map
92
+ // body or child workflow.
90
93
  // - namesInScope runs rename's scope rules backwards: a node may read its workflow's input keys, a map body's `item`
91
94
  // and `item_index`, and every key whose readers include it, with that key's `<key>$answers` and `<key>$verify`. A
92
95
  // map's `resultPath`, a loop's `until`, a `verify` (the node's own `as` and `submission`), a pick's or sift's
@@ -95,7 +98,7 @@
95
98
  // input whose schema lists no properties; the validator does not flag a read of either.
96
99
  // - placeholderNode makes the smallest node of a kind that holds no nodes: wrap makes containers of nodes that exist.
97
100
  import { workflowGraph } from "./graph.js";
98
- import { DECISION_NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, isPrototypeName, NODE_FIELDS, WORKFLOW_NODE_KINDS } from "./vocabulary.js";
101
+ import { DECISION_NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, isPrototypeName, NODE_FIELDS, PROSE_ARTIFACT_TYPES, WORKFLOW_NODE_KINDS } from "./vocabulary.js";
99
102
  /** Every code an EditError carries. */
100
103
  export const EDIT_ERROR_CODES = [
101
104
  /** The document is not an object. */
@@ -1298,6 +1301,25 @@ export function setSchema(doc, id, schema, scope = "") {
1298
1301
  return finish(draft, before, draft.update(before, [...keys, "schemas"], () => ({ [id]: clone(schema) })));
1299
1302
  return finish(draft, before, draft.update(before, [...keys, "schemas", id], () => clone(schema)));
1300
1303
  }
1304
+ /** Write the document's own `input` or `output` (copied): `{ schemaId }`, naming one of its schemas, and for the output
1305
+ * an optional `path`, the state path its value is read from when the run ends. `undefined` removes the input; a workflow
1306
+ * always has its output. Whether the schema exists and something sets the path is the validator's call. */
1307
+ export function setWorkflowField(doc, field, value) {
1308
+ const before = documentOf(doc);
1309
+ if (field !== "input" && field !== "output")
1310
+ throw new EditError("FIELD_INVALID", "", `a workflow's own field edited here is input or output: ${JSON.stringify(field)}`);
1311
+ const draft = new Draft();
1312
+ if (value === undefined) {
1313
+ if (field === "output")
1314
+ throw new EditError("FIELD_INVALID", "/output", "a workflow needs its output");
1315
+ return finish(draft, before, draft.update(before, ["input"], () => DELETE));
1316
+ }
1317
+ if (!isObject(value) || typeof value.schemaId !== "string" || !value.schemaId.trim())
1318
+ throw new EditError("FIELD_INVALID", `/${field}`, `a workflow's ${field} names a schema: ${JSON.stringify(value)}`);
1319
+ if (field === "output" && value.path !== undefined && typeof value.path !== "string")
1320
+ throw new EditError("FIELD_INVALID", "/output", `the output's path is a state path: ${JSON.stringify(value.path)}`);
1321
+ return finish(draft, before, draft.update(before, [field], () => clone(value)));
1322
+ }
1301
1323
  /** The engine-owned keys a node writes beside `key`: a judge's, a pick's or a judged route's answers under
1302
1324
  * `<as>$answers`, and a verified node's verdict under `<key>$verify`. */
1303
1325
  const sidecarsOf = (node, key) => [
@@ -1362,6 +1384,30 @@ export function namesInScope(doc, path, field) {
1362
1384
  }
1363
1385
  return out;
1364
1386
  }
1387
+ /** The names the document's `output.path` may read, each with what gives it, as namesInScope gives a node's: its input
1388
+ * keys, and the keys (with their `<key>$answers` and `<key>$verify`) of each node whose write is in the state when the
1389
+ * 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
1390
+ * a prose artifact's (which runs as a report), `report_markdown`, and a file artifact's `artifact`. */
1391
+ export function outputNames(doc) {
1392
+ const before = documentOf(doc);
1393
+ const entries = entriesOf(before);
1394
+ const out = [];
1395
+ const seen = new Set();
1396
+ const add = (name, from) => { const key = JSON.stringify([name, from]); if (!seen.has(key)) {
1397
+ seen.add(key);
1398
+ out.push({ name, from });
1399
+ } };
1400
+ for (const key of inputKeys(before, entries, ""))
1401
+ add(key, "input");
1402
+ const terminalKeys = (node) => node.node === "report" || (node.node === "artifact" && PROSE_ARTIFACT_TYPES.includes(node.type)) ? ["report_markdown"] : node.node === "artifact" ? ["artifact"] : [];
1403
+ for (const writer of entries) {
1404
+ const names = [...keysWritten(writer.node).flatMap((key) => [key, ...sidecarsOf(writer.node, key)]), ...terminalKeys(writer.node)];
1405
+ if (names.length && readersOf(entries, writer).output)
1406
+ for (const name of names)
1407
+ add(name, writer.path);
1408
+ }
1409
+ return out;
1410
+ }
1365
1411
  /** Each `{placeholder}` and state path the node at `path` reads, in its fields' order: the references rename carries,
1366
1412
  * found by the same walk. A workflow node's include its child's `output.path`, which reads the child's state. */
1367
1413
  export function readsOf(doc, path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-dsl",
3
- "version": "0.1.0-beta.238",
3
+ "version": "0.1.0-beta.240",
4
4
  "description": "Composable, typed workflows for agents",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",