@nanobpm/nano-agent-graph-engine 0.18.0 → 0.18.2

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.
@@ -14,7 +14,7 @@
14
14
  "ref": "release"
15
15
  },
16
16
  "description": "Durable process engine: defineFlow → BPMN, local engine, agent steps on your CLI, user tasks, web explorer",
17
- "version": "0.18.0"
17
+ "version": "0.18.2"
18
18
  }
19
19
  ]
20
20
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-agent-graph-engine",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Nano Agent Graph Engine: write durable flows in TypeScript (defineFlow), compile them to BPMN, and run them in a local engine that orchestrates scripts, headless agents, this session and you (user tasks).",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
package/dist/cli.js CHANGED
@@ -1042,6 +1042,41 @@ function requireStartAt(timer) {
1042
1042
  function declarativeToBpmn(flow) {
1043
1043
  return new Compiler(flow).compile();
1044
1044
  }
1045
+ function jsonSchemaType(f2) {
1046
+ if (f2.list)
1047
+ return "array";
1048
+ switch (f2.type) {
1049
+ case "string":
1050
+ case "datetime":
1051
+ return "string";
1052
+ case "integer":
1053
+ return "integer";
1054
+ case "number":
1055
+ return "number";
1056
+ case "boolean":
1057
+ return "boolean";
1058
+ }
1059
+ }
1060
+ function toolProps(tool, input2) {
1061
+ const props = [toolProp("name", tool.name), toolProp("purpose", tool.purpose)];
1062
+ if (tool.inputs !== void 0)
1063
+ props.push(toolProp("inputs", tool.inputs));
1064
+ if (tool.whenToUse !== void 0)
1065
+ props.push(toolProp("when_to_use", tool.whenToUse));
1066
+ if (tool.whenNotToUse !== void 0)
1067
+ props.push(toolProp("when_not_to_use", tool.whenNotToUse));
1068
+ if (tool.results !== void 0)
1069
+ props.push(toolProp("results", tool.results));
1070
+ input2?.fields.forEach((f2, idx) => {
1071
+ const i = idx + 1;
1072
+ props.push(toolProp(`input_${i}_name`, f2.name));
1073
+ props.push(toolProp(`input_${i}_type`, jsonSchemaType(f2)));
1074
+ if (f2.description !== void 0)
1075
+ props.push(toolProp(`input_${i}_description`, f2.description));
1076
+ props.push(toolProp(`input_${i}_required`, f2.optional ? "false" : "true"));
1077
+ });
1078
+ return props;
1079
+ }
1045
1080
  function incomingOutgoing(inc, outg) {
1046
1081
  return inc.map((f2) => ` <bpmn:incoming>${f2}</bpmn:incoming>
1047
1082
  `).join("") + outg.map((f2) => ` <bpmn:outgoing>${f2}</bpmn:outgoing>
@@ -1056,7 +1091,7 @@ function sequenceFlow(e) {
1056
1091
  }
1057
1092
  return ` <bpmn:sequenceFlow id="${e.id}" sourceRef="${e.from}" targetRef="${e.to}"${nm} />`;
1058
1093
  }
1059
- var Compiler, envelopeProp, feel, feelEquals, incomingOnly, outgoingOnly;
1094
+ var Compiler, TOOL_START_MESSAGE_ID, toolProp, envelopeProp, feel, feelEquals, incomingOnly, outgoingOnly;
1060
1095
  var init_declarative = __esm({
1061
1096
  "node_modules/@nanobpm/workflow/dist/declarative.js"() {
1062
1097
  init_xml();
@@ -1068,6 +1103,9 @@ var init_declarative = __esm({
1068
1103
  edges = [];
1069
1104
  /** envelope name → its fields, deduped for lifting to a single nano:shape. */
1070
1105
  envelopes = /* @__PURE__ */ new Map();
1106
+ /** Every `<bpmn:message>` id emitted, recorded by {@link emitMessages} (the
1107
+ * single source) so lifted shape ids can be checked against it. */
1108
+ messageIds = /* @__PURE__ */ new Set();
1071
1109
  /** The stack of open sub-process scopes; `.at(-1)` is the current scope (a
1072
1110
  * node/edge created now nests inside it). Empty at the top level. */
1073
1111
  scopeStack = [];
@@ -1268,12 +1306,22 @@ ${props.join("\n")}
1268
1306
  const t = this.flow.startTimer;
1269
1307
  const input2 = this.flow.input;
1270
1308
  this.recordEnvelope(input2);
1271
- const ext = input2 ? ` <bpmn:extensionElements>
1309
+ const props = [
1310
+ ...input2 ? [envelopeProp("in", input2.name)] : [],
1311
+ ...this.flow.tool ? toolProps(this.flow.tool, input2) : []
1312
+ ];
1313
+ const ext = props.length ? ` <bpmn:extensionElements>
1272
1314
  <zeebe:properties>
1273
- ${envelopeProp("in", input2.name)}
1315
+ ${props.join("\n")}
1274
1316
  </zeebe:properties>
1275
1317
  </bpmn:extensionElements>
1276
1318
  ` : "";
1319
+ if (this.flow.tool) {
1320
+ return ` <bpmn:startEvent id="Start">
1321
+ ` + ext + ` ${outgoingOnly(outg)}
1322
+ <bpmn:messageEventDefinition messageRef="${TOOL_START_MESSAGE_ID}" />
1323
+ </bpmn:startEvent>`;
1324
+ }
1277
1325
  if (!t) {
1278
1326
  if (!ext)
1279
1327
  return ` <bpmn:startEvent id="Start">${outgoingOnly(outg)}</bpmn:startEvent>`;
@@ -1306,6 +1354,7 @@ ${ext} ${outgoingOnly(outg)}
1306
1354
  this.live = this.edges.filter((e) => e.to !== void 0);
1307
1355
  const bodyXml = this.renderScope(void 0);
1308
1356
  const messageXml = this.emitMessages();
1357
+ this.assertShapeIdsDisjointFromMessages();
1309
1358
  const shapeXml = this.emitShapes();
1310
1359
  return `<?xml version="1.0" encoding="UTF-8"?>
1311
1360
  <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:nano="https://nanobpm.io/schema/shapes/1.0" id="Definitions_${escapeXml(this.flow.id)}" targetNamespace="http://bpmn.io/schema/bpmn">
@@ -1319,10 +1368,15 @@ ${ext} ${outgoingOnly(outg)}
1319
1368
  * typed) its payload data envelope. */
1320
1369
  emitMessages() {
1321
1370
  const msgs = [];
1371
+ if (this.flow.tool) {
1372
+ this.messageIds.add(TOOL_START_MESSAGE_ID);
1373
+ msgs.push(` <bpmn:message id="${TOOL_START_MESSAGE_ID}" name="${escapeXml(messageName(this.flow.id, "Start"))}" />`);
1374
+ }
1322
1375
  walkNodes(this.flow.steps, (n) => {
1323
1376
  if (n.kind !== "signal")
1324
1377
  return;
1325
1378
  const msgId = `Msg_${n.name}`;
1379
+ this.messageIds.add(msgId);
1326
1380
  const payloadProp = n.payload ? `
1327
1381
  <zeebe:properties>
1328
1382
  ${envelopeProp("in", n.payload.name)}
@@ -1335,6 +1389,18 @@ ${envelopeProp("in", n.payload.name)}
1335
1389
  });
1336
1390
  return msgs.join("\n");
1337
1391
  }
1392
+ /** Every lifted envelope becomes `<nano:shape id=NAME>` and every message a
1393
+ * `<bpmn:message id="Msg_…">` (the tool start message and one per signal step,
1394
+ * anywhere in the tree). Any overlap is a duplicate id → an invalid document,
1395
+ * so check the COLLECTED shape set (step in/out, signal payloads, nested
1396
+ * steps — every envelope source) against the derived message ids, fail-closed. */
1397
+ assertShapeIdsDisjointFromMessages() {
1398
+ for (const name2 of this.envelopes.keys()) {
1399
+ if (this.messageIds.has(name2)) {
1400
+ throw new Error(`envelope "${name2}" collides with the generated <bpmn:message> id in flow "${this.flow.id}" \u2014 rename the envelope`);
1401
+ }
1402
+ }
1403
+ }
1338
1404
  /** Lift the referenced data envelopes into a `<nano:shapes>` container on the
1339
1405
  * process extension elements, so the model carries the typed contracts and is
1340
1406
  * ejectable to model-first. */
@@ -1358,6 +1424,8 @@ ${shapes.join("\n")}
1358
1424
  </bpmn:extensionElements>`;
1359
1425
  }
1360
1426
  };
1427
+ TOOL_START_MESSAGE_ID = "Msg_Start";
1428
+ toolProp = (key, value) => ` <zeebe:property name="io.camunda.tool:${key}" value="${escapeXml(value)}" />`;
1361
1429
  envelopeProp = (dir, value) => ` <zeebe:property name="io.nanobpm.dataEnvelope.${dir}" value="${escapeXml(value)}" />`;
1362
1430
  feel = (expr) => `=${expr}`;
1363
1431
  feelEquals = (subject, value) => `=${subject} = "${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
@@ -29203,7 +29271,7 @@ var init_layout = __esm({
29203
29271
  init_dist7();
29204
29272
  init_paths();
29205
29273
  workflowVersion = (() => {
29206
- if ("0.19.0") return "0.19.0";
29274
+ if ("0.20.0") return "0.20.0";
29207
29275
  try {
29208
29276
  let dir = path2.dirname(createRequire(import.meta.url).resolve("@nanobpm/workflow"));
29209
29277
  while (!fs2.existsSync(path2.join(dir, "package.json")) && path2.dirname(dir) !== dir) dir = path2.dirname(dir);