@bpmnkit/core 0.1.0 → 0.1.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.
Files changed (63) hide show
  1. package/README.md +2 -0
  2. package/dist/bpmn/agentic.d.ts +121 -0
  3. package/dist/bpmn/agentic.js +97 -0
  4. package/dist/bpmn/auto-layout.d.ts +5 -5
  5. package/dist/bpmn/auto-layout.js +592 -36
  6. package/dist/bpmn/bpmn-builder.d.ts +56 -0
  7. package/dist/bpmn/bpmn-builder.js +155 -182
  8. package/dist/bpmn/bpmn-model.d.ts +39 -2
  9. package/dist/bpmn/bpmn-parser.js +48 -2
  10. package/dist/bpmn/bpmn-serializer.js +33 -0
  11. package/dist/bpmn/compact.js +11 -1
  12. package/dist/bpmn/di-planes.d.ts +13 -0
  13. package/dist/bpmn/di-planes.js +20 -0
  14. package/dist/bpmn/optimize/agentic.d.ts +10 -0
  15. package/dist/bpmn/optimize/agentic.js +88 -0
  16. package/dist/bpmn/optimize/deploy.d.ts +16 -0
  17. package/dist/bpmn/optimize/deploy.js +143 -0
  18. package/dist/bpmn/optimize/feel-syntax.d.ts +12 -0
  19. package/dist/bpmn/optimize/feel-syntax.js +87 -0
  20. package/dist/bpmn/optimize/feel.js +5 -2
  21. package/dist/bpmn/optimize/flow.js +22 -2
  22. package/dist/bpmn/optimize/index.js +20 -9
  23. package/dist/bpmn/optimize/tasks.js +1 -0
  24. package/dist/bpmn/optimize/types.d.ts +10 -1
  25. package/dist/bpmn/svg.js +22 -3
  26. package/dist/bpmn/type-guards.d.ts +7 -1
  27. package/dist/bpmn/type-guards.js +13 -0
  28. package/dist/bpmn/zeebe-extensions.d.ts +27 -0
  29. package/dist/bpmn/zeebe-extensions.js +38 -0
  30. package/dist/index.d.ts +9 -3
  31. package/dist/index.js +4 -1
  32. package/dist/layout/annotations.js +36 -1
  33. package/dist/layout/collaboration/alignment.d.ts +26 -0
  34. package/dist/layout/collaboration/alignment.js +66 -0
  35. package/dist/layout/collaboration/ordering.d.ts +21 -0
  36. package/dist/layout/collaboration/ordering.js +102 -0
  37. package/dist/layout/index.d.ts +1 -0
  38. package/dist/layout/layout-engine.d.ts +13 -3
  39. package/dist/layout/layout-engine.js +9 -4
  40. package/dist/layout/semantic/bands.d.ts +19 -0
  41. package/dist/layout/semantic/bands.js +324 -0
  42. package/dist/layout/semantic/graph.d.ts +29 -0
  43. package/dist/layout/semantic/graph.js +217 -0
  44. package/dist/layout/semantic/index.d.ts +13 -0
  45. package/dist/layout/semantic/index.js +181 -0
  46. package/dist/layout/semantic/place.d.ts +40 -0
  47. package/dist/layout/semantic/place.js +271 -0
  48. package/dist/layout/semantic/route.d.ts +14 -0
  49. package/dist/layout/semantic/route.js +454 -0
  50. package/dist/layout/types.d.ts +17 -0
  51. package/dist/plan/compile.d.ts +39 -0
  52. package/dist/plan/compile.js +380 -0
  53. package/dist/plan/extract.d.ts +31 -0
  54. package/dist/plan/extract.js +248 -0
  55. package/dist/plan/index.d.ts +6 -0
  56. package/dist/plan/index.js +5 -0
  57. package/dist/plan/merge.d.ts +13 -0
  58. package/dist/plan/merge.js +80 -0
  59. package/dist/plan/slug.d.ts +5 -0
  60. package/dist/plan/slug.js +22 -0
  61. package/dist/plan/types.d.ts +225 -0
  62. package/dist/plan/types.js +13 -0
  63. package/package.json +2 -2
package/README.md CHANGED
@@ -179,10 +179,12 @@ const outXml = Bpmn.export(restored)
179
179
  | [`@bpmnkit/plugins`](https://www.npmjs.com/package/@bpmnkit/plugins) | 22 composable canvas plugins |
180
180
  | [`@bpmnkit/api`](https://www.npmjs.com/package/@bpmnkit/api) | Camunda 8 REST API TypeScript client |
181
181
  | [`@bpmnkit/ascii`](https://www.npmjs.com/package/@bpmnkit/ascii) | Render BPMN diagrams as Unicode ASCII art |
182
+ | [`@bpmnkit/docspack`](https://www.npmjs.com/package/@bpmnkit/docspack) | BPMN Kit docs as an offline docspack package for AI agents |
182
183
  | [`@bpmnkit/ui`](https://www.npmjs.com/package/@bpmnkit/ui) | Shared design tokens and UI components |
183
184
  | [`@bpmnkit/profiles`](https://www.npmjs.com/package/@bpmnkit/profiles) | Shared auth, profile storage, and client factories for CLI & proxy |
184
185
  | [`@bpmnkit/operate`](https://www.npmjs.com/package/@bpmnkit/operate) | Monitoring & operations frontend for Camunda clusters |
185
186
  | [`@bpmnkit/connector-gen`](https://www.npmjs.com/package/@bpmnkit/connector-gen) | Generate connector templates from OpenAPI specs |
187
+ | [`@bpmnkit/connectors`](https://www.npmjs.com/package/@bpmnkit/connectors) | Camunda 8 OOTB connector catalog and deterministic template application |
186
188
  | [`@bpmnkit/cli`](https://www.npmjs.com/package/@bpmnkit/cli) | Camunda 8 command-line interface (casen) |
187
189
  | [`@bpmnkit/proxy`](https://www.npmjs.com/package/@bpmnkit/proxy) | Local AI bridge and Camunda API proxy server |
188
190
  | [`@bpmnkit/patterns`](https://www.npmjs.com/package/@bpmnkit/patterns) | Domain process patterns for BPMNKit AIKit |
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Deterministic constructor for the Camunda 8 "AI Agent Sub-process" pattern
3
+ * (`io.camunda.agenticai:aiagent-job-worker:1`, template
4
+ * `io.camunda.connectors.agenticai.aiagent.jobworker.v1`).
5
+ *
6
+ * Modeled as an `adHocSubProcess` carrying a `zeebe:taskDefinition` (the
7
+ * presence of which is what makes an ad-hoc sub-process a "job worker
8
+ * implementation" — there is no separate `zeebe:adHocImplementation`
9
+ * attribute). Each tool is a root-node activity (no incoming sequence flow),
10
+ * per the connector's tool-discovery rule; its `fromAi()` input mappings
11
+ * describe the parameters the LLM must supply, and its documentation becomes
12
+ * the tool description shown to the model.
13
+ *
14
+ * Binding keys below (`provider.type`, `data.systemPrompt.prompt`, …) are
15
+ * verified against the bundled element template
16
+ * (packages/plugins/src/config-panel-bpmn/templates/generated.ts,
17
+ * template id io.camunda.connectors.agenticai.aiagent.jobworker.v1, version 3).
18
+ */
19
+ import type { AdHocSubProcessOptions, ServiceTaskOptions, SubProcessContentBuilder } from "./bpmn-builder.js";
20
+ /** AI Agent job-worker connector task type — the pattern that marks an ad-hoc sub-process as an AI Agent. */
21
+ export declare const AI_AGENT_JOB_WORKER_TASK_TYPE = "io.camunda.agenticai:aiagent-job-worker:1";
22
+ /** Default FEEL expression aggregating each tool's result into `outputCollection`. */
23
+ export declare const AI_AGENT_DEFAULT_OUTPUT_ELEMENT = "={\n id: toolCall._meta.id,\n name: toolCall._meta.name,\n content: toolCallResult\n}";
24
+ /** JSON-schema-ish primitive types accepted by the AI Agent connector's `fromAi()` tool parameters. */
25
+ export type AiAgentToolParamType = "string" | "number" | "boolean" | "integer" | "array" | "object";
26
+ /** One parameter the LLM must supply when calling a tool, expressed as a `fromAi()` input mapping. */
27
+ export interface AiAgentToolParam {
28
+ /** Parameter name — becomes `toolCall.<name>` in the generated FEEL expression. */
29
+ name: string;
30
+ /** Description shown to the LLM for this parameter. */
31
+ description: string;
32
+ /** JSON-schema type hint (default "string"). */
33
+ type?: AiAgentToolParamType;
34
+ /** Whether the LLM must always supply this parameter (passed to `fromAi()`'s `options.required`). */
35
+ required?: boolean;
36
+ /** JSON Schema object for complex/nested parameter shapes (passed as `fromAi()`'s 4th argument). */
37
+ schema?: Record<string, unknown>;
38
+ /** IO-mapping target on the tool activity that receives the `fromAi()` value (e.g. "channel"). */
39
+ target: string;
40
+ }
41
+ /** One tool available to the agent — a root-node activity inside the ad-hoc sub-process. */
42
+ export interface AiAgentToolSpec {
43
+ /** Element ID — also the tool name shown to the LLM. */
44
+ id: string;
45
+ /** Tool description shown to the LLM (becomes the activity's `<bpmn:documentation>`). */
46
+ description: string;
47
+ /**
48
+ * Pre-resolved service task options for this tool — e.g. the output of
49
+ * `applyConnectorTemplate()` from `@bpmnkit/connectors`, or a plain
50
+ * `{ name, taskType }` for a hand-scaffolded worker.
51
+ */
52
+ serviceTask: ServiceTaskOptions;
53
+ /** Parameters the LLM supplies at call time, mapped via `fromAi()`. */
54
+ params?: AiAgentToolParam[];
55
+ /** FEEL expression producing the tool's result (default `"=response"`), mapped to the `toolCallResult` process variable. */
56
+ resultSource?: string;
57
+ }
58
+ /** Model provider + its dotted `zeebe:input` bindings for the AI Agent connector. */
59
+ export interface AiAgentModelConfig {
60
+ /**
61
+ * Provider dropdown value — must match the connector's `provider.type`
62
+ * choices exactly: "anthropic" | "bedrock" | "azureOpenAi" | "google-vertex-ai" | "openai" | "openaiCompatible".
63
+ */
64
+ provider: string;
65
+ /**
66
+ * Dotted `zeebe:input` target → value for provider/model/auth fields, e.g.
67
+ * `{ "provider.anthropic.model.model": "claude-sonnet-5",
68
+ * "provider.anthropic.authentication.apiKey": "{{secrets.ANTHROPIC_API_KEY}}" }`.
69
+ * A value without a leading "=" is a literal string; a leading "=" makes it a FEEL expression
70
+ * (matches Zeebe's `zeebe:input`/`zeebe:output` source convention throughout this SDK).
71
+ */
72
+ inputs: Record<string, string>;
73
+ }
74
+ export interface AiAgentOptions {
75
+ /** Element ID for the ad-hoc sub-process. */
76
+ id: string;
77
+ /** Display name. */
78
+ name?: string;
79
+ /** Model provider + its bindings. */
80
+ model: AiAgentModelConfig;
81
+ /** System prompt — literal text or a FEEL expression (leading "="). */
82
+ systemPrompt: string;
83
+ /** User prompt — literal text or a FEEL expression (leading "="). */
84
+ userPrompt: string;
85
+ /** Memory storage type (default `"in-process"`). */
86
+ memoryStorageType?: string;
87
+ /** Safety limit on model calls per agent run (default 10). */
88
+ maxModelCalls?: number;
89
+ /** Escape hatch for any other dotted `zeebe:input` target not covered above (e.g. `"data.response.format.type"`). */
90
+ extraInputs?: Record<string, string>;
91
+ /** Job retries (default "3"). */
92
+ retries?: string;
93
+ /** Tools available to the agent — each becomes a root-node activity. */
94
+ tools: AiAgentToolSpec[];
95
+ /** Process variable that receives the agent's final response (`zeebe:output source="=agent"`, default `"agent"`). */
96
+ outputVariable?: string;
97
+ /** Variable that collects tool call results (default `"toolCallResults"`). */
98
+ outputCollection?: string;
99
+ /** FEEL expression aggregating each tool result (default {@link AI_AGENT_DEFAULT_OUTPUT_ELEMENT}). */
100
+ outputElement?: string;
101
+ /** FEEL expression ending the ad-hoc scope early. */
102
+ completionCondition?: string;
103
+ /** Whether still-running tool instances are cancelled once the completion condition is met (default true). */
104
+ cancelRemainingInstances?: boolean;
105
+ }
106
+ /** The two pieces `adHocSubProcess(id, content, options)` needs to build the agent. */
107
+ export interface AiAgentBuild {
108
+ content: (b: SubProcessContentBuilder) => void;
109
+ options: AdHocSubProcessOptions;
110
+ }
111
+ /**
112
+ * Builds the ad-hoc sub-process content callback + options for the Camunda 8
113
+ * AI Agent Sub-process connector. Feed the result into `.adHocSubProcess()`:
114
+ *
115
+ * ```ts
116
+ * const agent = buildAiAgentSubProcess({ ... })
117
+ * builder.adHocSubProcess(agent.options.id ?? "Agent_1", agent.content, agent.options)
118
+ * ```
119
+ */
120
+ export declare function buildAiAgentSubProcess(opts: AiAgentOptions): AiAgentBuild;
121
+ //# sourceMappingURL=agentic.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { SubProcessContentBuilder as SubProcessContentBuilderImpl } from "./bpmn-builder.js";
2
+ /** AI Agent job-worker connector task type — the pattern that marks an ad-hoc sub-process as an AI Agent. */
3
+ export const AI_AGENT_JOB_WORKER_TASK_TYPE = "io.camunda.agenticai:aiagent-job-worker:1";
4
+ /** Default FEEL expression aggregating each tool's result into `outputCollection`. */
5
+ export const AI_AGENT_DEFAULT_OUTPUT_ELEMENT = "={\n id: toolCall._meta.id,\n name: toolCall._meta.name,\n content: toolCallResult\n}";
6
+ function fromAiExpression(param) {
7
+ const args = [`toolCall.${param.name}`, JSON.stringify(param.description)];
8
+ const needsType = param.type !== undefined || param.schema !== undefined || param.required === false;
9
+ if (needsType)
10
+ args.push(JSON.stringify(param.type ?? "string"));
11
+ if (param.schema !== undefined)
12
+ args.push(JSON.stringify(param.schema));
13
+ if (param.required === false) {
14
+ if (param.schema === undefined)
15
+ args.push("null");
16
+ args.push("{ required: false }");
17
+ }
18
+ return `=fromAi(${args.join(", ")})`;
19
+ }
20
+ /** Builds a single tool activity (a root node with no incoming sequence flow) from its spec. */
21
+ function buildToolElement(spec) {
22
+ // A `fromAi()` param declares its target as agent-controlled, so it must win over
23
+ // any static value the connector template resolved for the same target — otherwise
24
+ // two <zeebe:input> entries would bind the same target, which is invalid/ambiguous.
25
+ const inputsByTarget = new Map();
26
+ for (const input of spec.serviceTask.ioMapping?.inputs ?? [])
27
+ inputsByTarget.set(input.target, input);
28
+ for (const p of spec.params ?? []) {
29
+ inputsByTarget.set(p.target, { target: p.target, source: fromAiExpression(p) });
30
+ }
31
+ const inputs = [...inputsByTarget.values()];
32
+ const outputs = [
33
+ ...(spec.serviceTask.ioMapping?.outputs ?? []),
34
+ { source: spec.resultSource ?? "=response", target: "toolCallResult" },
35
+ ];
36
+ const scratch = new SubProcessContentBuilderImpl();
37
+ scratch.serviceTask(spec.id, {
38
+ ...spec.serviceTask,
39
+ documentation: spec.description,
40
+ ioMapping: { inputs, outputs },
41
+ });
42
+ // A fresh scratch builder's very first element never gets an auto-connected
43
+ // sequence flow, so `_elements[0]` is exactly the disconnected tool element.
44
+ const [element] = scratch._elements;
45
+ if (!element)
46
+ throw new Error(`buildAiAgentSubProcess: failed to build tool "${spec.id}"`);
47
+ return element;
48
+ }
49
+ /**
50
+ * Builds the ad-hoc sub-process content callback + options for the Camunda 8
51
+ * AI Agent Sub-process connector. Feed the result into `.adHocSubProcess()`:
52
+ *
53
+ * ```ts
54
+ * const agent = buildAiAgentSubProcess({ ... })
55
+ * builder.adHocSubProcess(agent.options.id ?? "Agent_1", agent.content, agent.options)
56
+ * ```
57
+ */
58
+ export function buildAiAgentSubProcess(opts) {
59
+ if (opts.tools.length === 0) {
60
+ throw new Error("buildAiAgentSubProcess: at least one tool is required");
61
+ }
62
+ const ids = new Set();
63
+ for (const tool of opts.tools) {
64
+ if (ids.has(tool.id)) {
65
+ throw new Error(`buildAiAgentSubProcess: duplicate tool id "${tool.id}"`);
66
+ }
67
+ ids.add(tool.id);
68
+ }
69
+ const inputs = {
70
+ "provider.type": opts.model.provider,
71
+ ...opts.model.inputs,
72
+ "data.systemPrompt.prompt": opts.systemPrompt,
73
+ "data.userPrompt.prompt": opts.userPrompt,
74
+ "data.memory.storage.type": opts.memoryStorageType ?? "in-process",
75
+ "data.limits.maxModelCalls": String(opts.maxModelCalls ?? 10),
76
+ ...opts.extraInputs,
77
+ };
78
+ const options = {
79
+ name: opts.name,
80
+ taskDefinition: { type: AI_AGENT_JOB_WORKER_TASK_TYPE, retries: opts.retries },
81
+ ioMapping: {
82
+ inputs: Object.entries(inputs).map(([target, source]) => ({ source, target })),
83
+ outputs: [{ source: "=agent", target: opts.outputVariable ?? "agent" }],
84
+ },
85
+ outputCollection: opts.outputCollection ?? "toolCallResults",
86
+ outputElement: opts.outputElement ?? AI_AGENT_DEFAULT_OUTPUT_ELEMENT,
87
+ completionCondition: opts.completionCondition,
88
+ cancelRemainingInstances: opts.cancelRemainingInstances,
89
+ };
90
+ const content = (b) => {
91
+ for (const tool of opts.tools) {
92
+ b.addDisconnected(buildToolElement(tool));
93
+ }
94
+ };
95
+ return { content, options };
96
+ }
97
+ //# sourceMappingURL=agentic.js.map
@@ -1,10 +1,10 @@
1
+ import type { LayoutEngine } from "../layout/layout-engine.js";
1
2
  import type { BpmnDefinitions } from "./bpmn-model.js";
2
3
  /**
3
- * Apply auto-layout to all processes in a BpmnDefinitions, replacing the
4
- * diagram interchange (BPMNDi) with freshly computed positions.
4
+ * Replace every diagram-interchange position in `defs` with a computed layout.
5
5
  *
6
- * - Handles plain processes (no collaboration) and collaborations with pools.
7
- * - When pools have lanes, lane shapes are tiled vertically around the process content.
6
+ * @param engine - Which process layout algorithm to run. Defaults to `semantic`;
7
+ * `grid` runs the older cell-grid walk and is used to compare the two.
8
8
  */
9
- export declare function applyAutoLayout(defs: BpmnDefinitions): BpmnDefinitions;
9
+ export declare function applyAutoLayout(defs: BpmnDefinitions, engine?: LayoutEngine): BpmnDefinitions;
10
10
  //# sourceMappingURL=auto-layout.d.ts.map