@parcha/agentrun-dsl 0.1.0-beta.205 → 0.1.0-beta.207
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 +1 -1
- package/dist/edit.d.ts +2 -2
- package/dist/edit.js +5 -3
- package/package.json +1 -1
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. `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, 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. `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
|
@@ -141,8 +141,8 @@ export declare function openPlaceholderAt(text: string, offset: number): {
|
|
|
141
141
|
prefix: string;
|
|
142
142
|
} | undefined;
|
|
143
143
|
/** `base`, or its stem (`base` without a `_<n>` ending) with the smallest `_<n>` from 2, so that no label, key,
|
|
144
|
-
* reference, input key or word of code of any scope of the document holds it
|
|
145
|
-
* `Object.prototype` has. `base` is a state key name. */
|
|
144
|
+
* reference, input key or word of code of any scope of the document holds it (a child workflow's that holds no node
|
|
145
|
+
* yet among them), nor an engine key or a name `Object.prototype` has. `base` is a state key name. */
|
|
146
146
|
export declare function freshName(doc: WorkflowDocument, base: string): string;
|
|
147
147
|
/** The smallest node of `kind` for `doc`: its required fields in the schema's order, a fresh name as its label (and its
|
|
148
148
|
* `as`, where it needs one), and each other field's placeholder. A container is made by wrapping nodes that exist. */
|
package/dist/edit.js
CHANGED
|
@@ -1384,15 +1384,17 @@ export function openPlaceholderAt(text, offset) {
|
|
|
1384
1384
|
return { start: start - 1, prefix: text.slice(start, offset) };
|
|
1385
1385
|
}
|
|
1386
1386
|
/** `base`, or its stem (`base` without a `_<n>` ending) with the smallest `_<n>` from 2, so that no label, key,
|
|
1387
|
-
* reference, input key or word of code of any scope of the document holds it
|
|
1388
|
-
* `Object.prototype` has. `base` is a state key name. */
|
|
1387
|
+
* reference, input key or word of code of any scope of the document holds it (a child workflow's that holds no node
|
|
1388
|
+
* yet among them), nor an engine key or a name `Object.prototype` has. `base` is a state key name. */
|
|
1389
1389
|
export function freshName(doc, base) {
|
|
1390
1390
|
const before = documentOf(doc);
|
|
1391
1391
|
if (typeof base !== "string" || !KEY_NAME.test(base))
|
|
1392
1392
|
throw new EditError("NAME_INVALID", "", `a name takes letters, digits and "_" only: ${JSON.stringify(base)}`);
|
|
1393
1393
|
const entries = entriesOf(before);
|
|
1394
1394
|
const used = new Set([...Object.getOwnPropertyNames(Object.prototype), "prototype"]);
|
|
1395
|
-
|
|
1395
|
+
// Each workflow node's path is a scope, its child's first node not yet inserted included: that node is named here.
|
|
1396
|
+
const scopes = ["", ...entries.filter((entry) => entry.node.node === "workflow").map((entry) => entry.path)];
|
|
1397
|
+
for (const scope of scopes)
|
|
1396
1398
|
for (const name of namesUsed(before, entries, scope))
|
|
1397
1399
|
used.add(name);
|
|
1398
1400
|
// `base` itself when free, numbered or not; `fresh` alone numbers a numbered base from its stem even when it is free.
|