@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.
package/dist/index.js CHANGED
@@ -910,8 +910,22 @@ function makeBuilder(id, out, ctx, isRoot = false) {
910
910
  throw new Error(`startOn() must be the first statement in flow "${id}"`);
911
911
  if (ctx.startTimer)
912
912
  throw new Error(`startOn() may be called only once in flow "${id}"`);
913
+ if (ctx.tool)
914
+ throw new Error(`startOn() cannot be combined with exposeAsTool() in flow "${id}"`);
913
915
  ctx.startTimer = t;
914
916
  };
917
+ const setTool = (t) => {
918
+ if (!isRoot) {
919
+ throw new Error(`exposeAsTool() is only valid at the top level of flow "${id}" (not inside switch/branch/loop)`);
920
+ }
921
+ if (out.length !== 0)
922
+ throw new Error(`exposeAsTool() must precede every step in flow "${id}"`);
923
+ if (ctx.tool)
924
+ throw new Error(`exposeAsTool() may be called only once in flow "${id}"`);
925
+ if (ctx.startTimer)
926
+ throw new Error(`exposeAsTool() cannot be combined with startOn() in flow "${id}"`);
927
+ ctx.tool = t;
928
+ };
915
929
  let builderRef;
916
930
  const api = {
917
931
  id,
@@ -935,10 +949,12 @@ function makeBuilder(id, out, ctx, isRoot = false) {
935
949
  contractEnvelopes(name) {
936
950
  return contractEnvelopes(ctx, name);
937
951
  },
938
- setStartTimer
952
+ setStartTimer,
953
+ setTool
939
954
  };
940
955
  const methods = /* @__PURE__ */ Object.create(null);
941
956
  methods.startOn = startOnMethod(api);
957
+ methods.exposeAsTool = exposeAsToolMethod(api);
942
958
  for (const [kind, handlers] of eachNodeKind()) {
943
959
  if (!handlers.build)
944
960
  continue;
@@ -959,6 +975,7 @@ function makeBuilder(id, out, ctx, isRoot = false) {
959
975
  }
960
976
  var BUILTIN_BUILDER_METHODS = [
961
977
  "startOn",
978
+ "exposeAsTool",
962
979
  "run",
963
980
  "task",
964
981
  "signal",
@@ -1014,6 +1031,31 @@ function startOnMethod(api) {
1014
1031
  return api.self();
1015
1032
  };
1016
1033
  }
1034
+ var TOOL_TEXT_KEYS = ["inputs", "whenToUse", "whenNotToUse", "results"];
1035
+ function exposeAsToolMethod(api) {
1036
+ return (opts) => {
1037
+ if (opts === null || typeof opts !== "object") {
1038
+ throw new Error(`exposeAsTool() needs an options object in flow "${api.id}"`);
1039
+ }
1040
+ for (const key of ["name", "purpose"]) {
1041
+ const v = opts[key];
1042
+ if (typeof v !== "string" || v.trim() === "") {
1043
+ throw new Error(`exposeAsTool() needs a non-empty \`${key}\` in flow "${api.id}"`);
1044
+ }
1045
+ }
1046
+ const tool = { name: opts.name.trim(), purpose: opts.purpose };
1047
+ for (const key of TOOL_TEXT_KEYS) {
1048
+ const v = opts[key];
1049
+ if (v === void 0)
1050
+ continue;
1051
+ if (typeof v !== "string")
1052
+ throw new Error(`exposeAsTool() \`${key}\` must be a string in flow "${api.id}"`);
1053
+ tool[key] = v;
1054
+ }
1055
+ api.setTool(tool);
1056
+ return api.self();
1057
+ };
1058
+ }
1017
1059
  function defineFlow(id, second, third) {
1018
1060
  assertIdent("workflow id", id);
1019
1061
  if (typeof second !== "function" && (second === null || typeof second !== "object")) {
@@ -1040,11 +1082,32 @@ function defineFlow(id, second, third) {
1040
1082
  const flow = { kind: "declarative", id, steps, handlers };
1041
1083
  if (ctx.startTimer)
1042
1084
  flow.startTimer = ctx.startTimer;
1085
+ if (ctx.tool)
1086
+ flow.tool = ctx.tool;
1043
1087
  const input = startInput(id, contracts);
1044
1088
  if (input)
1045
1089
  flow.input = input;
1090
+ if (ctx.tool)
1091
+ assertToolExposure(id, input);
1046
1092
  return flow;
1047
1093
  }
1094
+ function assertToolExposure(id, input) {
1095
+ if (id === TOOL_START_MESSAGE_ID) {
1096
+ throw new Error(`exposeAsTool() in flow "${id}": the flow id "${TOOL_START_MESSAGE_ID}" collides with the generated start message id \u2014 rename the flow`);
1097
+ }
1098
+ if (input === void 0)
1099
+ return;
1100
+ if (input.name === TOOL_START_MESSAGE_ID) {
1101
+ throw new Error(`exposeAsTool() in flow "${id}": the input envelope "${TOOL_START_MESSAGE_ID}" collides with the generated start message id (it lifts to a nano:shape with that id) \u2014 rename the envelope`);
1102
+ }
1103
+ for (const f of input.fields) {
1104
+ if (f.name === TOOL_RESERVED_INPUT_FIELD) {
1105
+ throw new Error(`exposeAsTool() in flow "${id}": the input field "${TOOL_RESERVED_INPUT_FIELD}" is reserved by the MCP tool surface (it is stripped from the process variables), so the field would never reach the flow \u2014 rename it`);
1106
+ }
1107
+ }
1108
+ }
1109
+ var TOOL_START_MESSAGE_ID = "Msg_Start";
1110
+ var TOOL_RESERVED_INPUT_FIELD = "businessId";
1048
1111
  var feel = (expr) => `=${expr}`;
1049
1112
  var feelEquals = (subject, value) => `=${subject} = "${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
1050
1113
  function incomingOutgoing(inc, outg) {
@@ -1079,12 +1142,19 @@ function normaliseField(name, spec) {
1079
1142
  if (!SCALARS.has(raw.type)) {
1080
1143
  throw new Error(`envelope field "${name}": unknown type "${raw.type}" (expected one of ${[...SCALARS].join(", ")})`);
1081
1144
  }
1082
- return {
1145
+ const field = {
1083
1146
  name,
1084
1147
  type: raw.type,
1085
1148
  optional: typeof spec === "object" && spec.optional === true,
1086
1149
  list: typeof spec === "object" && spec.list === true
1087
1150
  };
1151
+ if (typeof spec === "object" && spec.description !== void 0) {
1152
+ if (typeof spec.description !== "string") {
1153
+ throw new Error(`envelope field "${name}": description must be a string`);
1154
+ }
1155
+ field.description = spec.description;
1156
+ }
1157
+ return field;
1088
1158
  }
1089
1159
  function envelope(name, fields) {
1090
1160
  assertIdent("envelope name", name);
Binary file
@@ -1,4 +1,4 @@
1
- import type { DeclarativeFlow, FlowContracts, FlowNode, JsonObject, NodeEnvelopes, StepHandler, TimerStart } from "./types.js";
1
+ import type { DeclarativeFlow, FlowContracts, FlowNode, JsonObject, NodeEnvelopes, StepHandler, TimerStart, ToolExposure } from "./types.js";
2
2
  import type { Envelope } from "./envelope.js";
3
3
  import type { HumanIoMapping } from "./io-mapping.js";
4
4
  import type { ForEachOpts } from "./nodes/forEach.js";
@@ -94,6 +94,15 @@ export interface FlowBuilder<C extends object = object> {
94
94
  } | {
95
95
  at: string;
96
96
  }): FlowBuilder<C>;
97
+ /**
98
+ * Expose this flow as an MCP tool. The start event renders as a MESSAGE start
99
+ * (MCP tool calls correlate its start message) carrying the Camunda
100
+ * `io.camunda.tool:*` properties, plus Nano's typed `io.camunda.tool:input_N_*`
101
+ * superset DERIVED from the flow's `Start` input envelope (field name, JSON
102
+ * type, `description`, required). Top level only, before any step; exclusive
103
+ * with `startOn`.
104
+ */
105
+ exposeAsTool(opts: ToolExposure): FlowBuilder<C>;
97
106
  /**
98
107
  * Make this flow's start event a durable TIMER start rather than an explicit
99
108
  * `client.start(...)`. Must be the first statement, at the top level. Pass
@@ -210,6 +219,8 @@ export interface BuildApi {
210
219
  } | undefined;
211
220
  /** Lift a durable timer start onto the flow (used only by `startOn`). */
212
221
  setStartTimer(t: TimerStart): void;
222
+ /** Lift an MCP tool exposure onto the flow (used only by `exposeAsTool`). */
223
+ setTool(t: ToolExposure): void;
213
224
  }
214
225
  /** A dynamically-assembled builder satisfies `FlowBuilder<C>` once every core
215
226
  * built-in method is installed. The check is a runtime type guard (not an `as`
@@ -9,6 +9,7 @@ export type FieldSpec = ScalarType | {
9
9
  type: ScalarType;
10
10
  optional?: boolean;
11
11
  list?: boolean;
12
+ description?: string;
12
13
  };
13
14
  /** The TS type of a single field spec (applies `list` before `optional`). A spec
14
15
  * whose `list` isn't a literal (the widened `FieldSpec` of a plain `Envelope`) may
@@ -40,6 +41,9 @@ export interface EnvelopeField {
40
41
  type: ScalarType;
41
42
  optional: boolean;
42
43
  list: boolean;
44
+ /** Human-readable field doc (e.g. surfaced as an MCP tool input description).
45
+ * Present only when declared. */
46
+ description?: string;
43
47
  }
44
48
  /**
45
49
  * A typed data envelope: a named schema (for the model) plus a phantom TS type
@@ -11,4 +11,4 @@ export { WorkflowClient, WorkflowError, toBpmn, toDeployableBpmn } from "./clien
11
11
  export type { WorkflowClientOptions, NanoSdkClient, NanoJobWorker, JobWorkerConfig, ActivatedJob, } from "./client.js";
12
12
  export { Worker } from "./worker.js";
13
13
  export type { WorkerOptions, ActivityEvent } from "./worker.js";
14
- export type { Json, JsonObject, Job, StepHandler, DeclarativeFlow, DeclarativeStep, FlowNode, SwitchCase, TimerStart, NodeEnvelopes, StepContract, FlowContracts, ImperativeWorkflow, Orchestration, WorkflowContext, Workflow, DeployResult, StartResult, } from "./types.js";
14
+ export type { Json, JsonObject, Job, StepHandler, DeclarativeFlow, DeclarativeStep, FlowNode, SwitchCase, TimerStart, ToolExposure, NodeEnvelopes, StepContract, FlowContracts, ImperativeWorkflow, Orchestration, WorkflowContext, Workflow, DeployResult, StartResult, } from "./types.js";
@@ -112,6 +112,29 @@ export interface DeclarativeFlow {
112
112
  * takes; a host can render a start form from it and check start variables
113
113
  * with {@link validateEnvelope}. Absent = untyped start. */
114
114
  input?: Envelope;
115
+ /** When set, the flow is exposed as an MCP tool: its start event renders as a
116
+ * MESSAGE start carrying the `io.camunda.tool:*` properties (see
117
+ * {@link ToolExposure}). Set by `w.exposeAsTool(...)`. */
118
+ tool?: ToolExposure;
119
+ }
120
+ /** How a flow is exposed as an MCP tool (`w.exposeAsTool(...)`). Emitted as the
121
+ * Camunda `io.camunda.tool:*` `zeebe:properties` on a message start event (the
122
+ * bindings of the `io.camunda.mcp.start-message` template). The typed
123
+ * `io.camunda.tool:input_N_*` superset is DERIVED from the flow's `Start` input
124
+ * envelope — never restated here. */
125
+ export interface ToolExposure {
126
+ /** The tool name (`io.camunda.tool:name`). */
127
+ name: string;
128
+ /** What the tool does (`io.camunda.tool:purpose`). */
129
+ purpose: string;
130
+ /** Free-text description of the inputs (`io.camunda.tool:inputs`). */
131
+ inputs?: string;
132
+ /** When an agent should call it (`io.camunda.tool:when_to_use`). */
133
+ whenToUse?: string;
134
+ /** When an agent should not call it (`io.camunda.tool:when_not_to_use`). */
135
+ whenNotToUse?: string;
136
+ /** What the tool returns (`io.camunda.tool:results`). */
137
+ results?: string;
115
138
  }
116
139
  /** The context passed to an imperative orchestration function. */
117
140
  export interface WorkflowContext {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanobpm/workflow",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Code-first durable orchestration for nanobpmn (ADR 0044/0045). Author a durable workflow as a declarative flow — `defineFlow(id, w => { w.run(...); w.signal(...); w.task(...) })` — and the SDK derives the executable BPMN model, the job types, and the message/correlation wiring, then hosts a generic worker. `w.run` is a local step, `w.signal` is a durable human-in-the-loop wait, `w.task` is a step serviced by an external worker. `defineFlow` is the single code-first surface; the imperative `defineWorkflow` replay function is experimental/internal, not a recommended API. No diagram, no task-type wiring, no correlation plumbing authored by hand — and you can optionally auto-generate a diagram (DI) for the derived model with `declarativeToLayoutedBpmn` via the optional `bpmn-auto-layout` peer dependency. Talks to a running nanobpmn gateway through @nanobpm/nano-sdk (the shared engine-transport spine — ADR 0055), which negotiates the Falcon protocol on a Nano server and REST elsewhere.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanobpm/nano-agent-graph-engine",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Durable BPMN process engine for Claude Code: code-first flows (defineFlow) that orchestrate scripts, Claude Code agents and people.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -61,9 +61,9 @@
61
61
  "@modelcontextprotocol/ext-apps": "^1.7.5",
62
62
  "@modelcontextprotocol/sdk": "^1.32.2",
63
63
  "@nanobpm/agentic": "^0.16.0",
64
- "@nanobpm/engine-wasm": "^0.11.0",
64
+ "@nanobpm/engine-wasm": "^0.11.2",
65
65
  "@nanobpm/nano-app-schema": "^0.11.0",
66
- "@nanobpm/workflow": "^0.19.0",
66
+ "@nanobpm/workflow": "^0.20.0",
67
67
  "@tailwindcss/cli": "^4.3.5",
68
68
  "@tanstack/react-query": "^5.107.1",
69
69
  "@types/node": "^26.6.6",