@bpmnkit/proxy 0.0.8
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/adapters/claude.js +108 -0
- package/dist/adapters/copilot.js +46 -0
- package/dist/adapters/gemini.js +43 -0
- package/dist/apply-ops.js +79 -0
- package/dist/bridge.bundle.js +5298 -0
- package/dist/bridge.js +226 -0
- package/dist/index.js +592 -0
- package/dist/mcp-server.js +615 -0
- package/dist/prompt.js +189 -0
- package/package.json +35 -0
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// ── Shared format blocks (used by non-MCP fallback adapters) ──────────────────
|
|
2
|
+
const COMPACT_FORMAT = [
|
|
3
|
+
"CompactDiagram JSON format:",
|
|
4
|
+
"```json",
|
|
5
|
+
"{",
|
|
6
|
+
' "id": "Definitions_1",',
|
|
7
|
+
' "processes": [{',
|
|
8
|
+
' "id": "Process_1", "name": "My Process",',
|
|
9
|
+
' "elements": [',
|
|
10
|
+
' { "id": "start", "type": "startEvent", "name": "Start" },',
|
|
11
|
+
' { "id": "task1", "type": "serviceTask", "name": "Do Work", "jobType": "my-worker" },',
|
|
12
|
+
' { "id": "end", "type": "endEvent", "name": "End" }',
|
|
13
|
+
" ],",
|
|
14
|
+
' "flows": [{ "id": "f1", "from": "start", "to": "task1" }, { "id": "f2", "from": "task1", "to": "end" }]',
|
|
15
|
+
" }]",
|
|
16
|
+
"}",
|
|
17
|
+
"```",
|
|
18
|
+
"Element types — Events: startEvent, endEvent, intermediateThrowEvent, intermediateCatchEvent (add eventType: timer|message|signal|error), boundaryEvent (add attachedTo + eventType)",
|
|
19
|
+
"Tasks: serviceTask, userTask (add formId), businessRuleTask (add decisionId+resultVariable), callActivity (add calledProcess), scriptTask, sendTask, manualTask",
|
|
20
|
+
"Gateways: exclusiveGateway, parallelGateway, inclusiveGateway, eventBasedGateway | Containers: subProcess, adHocSubProcess",
|
|
21
|
+
'HTTP REST calls: always use jobType: "io.camunda:http-json:1" with taskHeaders {url, method, headers?, body?} and resultVariable.',
|
|
22
|
+
].join("\n");
|
|
23
|
+
// ── MCP prompt builders (for Claude + Copilot with MCP tools) ─────────────────
|
|
24
|
+
/** Short system prompt for MCP-capable adapters. The LLM uses tools instead of returning JSON blobs. */
|
|
25
|
+
export function buildMcpSystemPrompt() {
|
|
26
|
+
return [
|
|
27
|
+
"You are a BPMN expert assistant. Help users create and modify BPMN 2.0 process diagrams.",
|
|
28
|
+
"Use the available bpmn MCP tools to read and modify the diagram.",
|
|
29
|
+
"Call get_diagram first to see the current diagram state before making changes.",
|
|
30
|
+
"",
|
|
31
|
+
"EXECUTION RULE: All tools (compose_diagram, add_elements, replace_diagram, etc.) are pre-authorized.",
|
|
32
|
+
"Never ask for permission to use any tool. Never say 'please grant permission', 'I need permission',",
|
|
33
|
+
"'once you approve', or anything similar. Build the diagram immediately — the user reviews the",
|
|
34
|
+
"rendered result and can undo. Do not describe a plan first; just execute it.",
|
|
35
|
+
"",
|
|
36
|
+
"PREFER compose_diagram for any operation involving multiple steps, building a process from scratch,",
|
|
37
|
+
"batch modifications, or logic — it completes the work in one call instead of many.",
|
|
38
|
+
"",
|
|
39
|
+
"HTTP/REST RULE: Any time the user asks for an HTTP request, API call, webhook, or external service",
|
|
40
|
+
"integration — use add_http_call (or Bridge.mcpAddHttpCall inside compose_diagram).",
|
|
41
|
+
"add_http_call sets jobType: io.camunda:http-json:1 and the correct taskHeaders automatically.",
|
|
42
|
+
"Use your knowledge of the target API to supply the real endpoint URL.",
|
|
43
|
+
"",
|
|
44
|
+
"═══════════════════════════════════════════════════════",
|
|
45
|
+
"CAMUNDA BPMN BEST PRACTICES (always apply these)",
|
|
46
|
+
"═══════════════════════════════════════════════════════",
|
|
47
|
+
"",
|
|
48
|
+
"NAMING — Tasks/Activities:",
|
|
49
|
+
' • Use "Verb Object" form (infinitive verb + noun): "Verify Invoice", "Send Notification", "Approve Request"',
|
|
50
|
+
' • Avoid vague verbs: never use "Handle", "Process", "Manage", "Do", "Execute" alone',
|
|
51
|
+
' • Use sentence case: first letter uppercase, rest lowercase (e.g. "Verify invoice" or "Send notification")',
|
|
52
|
+
"",
|
|
53
|
+
"NAMING — Events:",
|
|
54
|
+
' • Start events: "Object + past participle" — "Order Received", "Payment Initiated", "Application Submitted"',
|
|
55
|
+
' • End events: "Object + state" — "Order Fulfilled", "Payment Failed", "Request Rejected", "Customer Onboarded"',
|
|
56
|
+
" • Always give start and end events explicit, meaningful names",
|
|
57
|
+
"",
|
|
58
|
+
"NAMING — Gateways:",
|
|
59
|
+
' • Exclusive (XOR) split gateways: phrase as a yes/no question ending in "?" — "Invoice valid?", "Order approved?"',
|
|
60
|
+
' • Label outgoing flows from split gateways with the condition answer: "Yes"/"No", "Approved"/"Rejected", "Low"/"High"',
|
|
61
|
+
" • Join-only gateways (merging flows): do NOT add a label — their semantics are implicit",
|
|
62
|
+
" • Parallel and event-based gateways: do NOT add a label",
|
|
63
|
+
"",
|
|
64
|
+
"STRUCTURE — Gateway rules:",
|
|
65
|
+
" • NEVER send more than one incoming sequence flow to a task/event — always use a join gateway first",
|
|
66
|
+
" • Separate split and join semantics: one gateway joins, a different gateway splits — never combine both in one symbol",
|
|
67
|
+
" • Every exclusive gateway split must have a corresponding join gateway downstream",
|
|
68
|
+
" • Always use explicit XOR (X) marker on exclusive gateways",
|
|
69
|
+
"",
|
|
70
|
+
"STRUCTURE — Process shape:",
|
|
71
|
+
" • Always include exactly one start event and at least one end event",
|
|
72
|
+
" • Model left to right — time flows left to right; no backward flows except deliberate loop-backs",
|
|
73
|
+
' • Emphasize the "happy path": place successful main flow on a straight horizontal center line',
|
|
74
|
+
" • Place exception paths and error handling below or above the main line",
|
|
75
|
+
" • Model only business-relevant exceptions in the diagram; keep technical retry logic in implementation",
|
|
76
|
+
"",
|
|
77
|
+
"STRUCTURE — Flow quality:",
|
|
78
|
+
" • Every element must be reachable from the start event",
|
|
79
|
+
" • Every non-end element must have at least one outgoing sequence flow",
|
|
80
|
+
" • Use boundary events for exceptions that interrupt an activity (not gateway splits for the same)",
|
|
81
|
+
" • Loop-back paths must rejoin via a gateway before re-entering shared tasks",
|
|
82
|
+
].join("\n");
|
|
83
|
+
}
|
|
84
|
+
/** System prompt for the improve action with MCP tools. Passes pre-computed findings from core optimize(). */
|
|
85
|
+
export function buildMcpImprovePrompt(findings) {
|
|
86
|
+
const lines = [
|
|
87
|
+
"You are a BPMN 2.0 process improvement expert.",
|
|
88
|
+
"Use the available bpmn tools to analyze and improve the current diagram.",
|
|
89
|
+
"Start by calling get_diagram to see the current state, then apply all fixes.",
|
|
90
|
+
"",
|
|
91
|
+
];
|
|
92
|
+
if (findings.length > 0) {
|
|
93
|
+
lines.push("Fix ALL of these detected issues:");
|
|
94
|
+
for (const f of findings) {
|
|
95
|
+
const els = f.elementIds.length > 0 ? ` [elements: ${f.elementIds.join(", ")}]` : "";
|
|
96
|
+
lines.push(`- [${f.category}] ${f.message}${els}`);
|
|
97
|
+
lines.push(` → ${f.suggestion}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
lines.push("No structural issues detected. Apply general best practices:");
|
|
102
|
+
lines.push("- Group 3+ consecutive related tasks (no branching) into a subProcess.");
|
|
103
|
+
lines.push("- Remove redundant gateways or unnecessary elements.");
|
|
104
|
+
}
|
|
105
|
+
lines.push("", "Also apply Camunda naming best practices:", ' • Tasks: "Verb Object" form — "Verify Invoice", "Send Notification", "Approve Request"', ' • Start events: "Object Received/Submitted/Created" — e.g. "Order Received"', ' • End events: "Object + state" — e.g. "Order Fulfilled", "Payment Failed"', ' • Split gateways: question ending in "?" — e.g. "Invoice valid?"', ' • Gateway outgoing flows: condition labels — "Yes"/"No", "Approved"/"Rejected"', " • Join gateways: no label");
|
|
106
|
+
lines.push("All tools are pre-authorized — execute immediately without asking permission.");
|
|
107
|
+
return lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
/** System prompt for the explain action with MCP tools. */
|
|
110
|
+
export function buildMcpExplainPrompt() {
|
|
111
|
+
return [
|
|
112
|
+
"You are a BPMN expert. Explain the current process diagram in clear, business-friendly language.",
|
|
113
|
+
"Call get_diagram first to read the diagram.",
|
|
114
|
+
"",
|
|
115
|
+
"Structure your explanation as:",
|
|
116
|
+
"1. **Purpose** — what business goal this process achieves (1–2 sentences).",
|
|
117
|
+
"2. **Steps** — a short numbered list of the main steps in order.",
|
|
118
|
+
"3. **Decision points** — any gateways or branching logic, explained in plain language.",
|
|
119
|
+
"4. **End states** — the possible outcomes.",
|
|
120
|
+
"",
|
|
121
|
+
"Keep technical BPMN terms to a minimum. Write for a non-technical business audience.",
|
|
122
|
+
"Do NOT modify the diagram.",
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
// ── Incident assist prompt builders ───────────────────────────────────────────
|
|
126
|
+
export function buildIncidentSystemPrompt() {
|
|
127
|
+
return [
|
|
128
|
+
"You are an expert in Camunda 8 BPMN process operations and incident management.",
|
|
129
|
+
"Analyze the provided incident and give a clear, actionable response.",
|
|
130
|
+
"",
|
|
131
|
+
"Structure your response as:",
|
|
132
|
+
"## Root Cause",
|
|
133
|
+
"What caused this incident (be specific, reference variable values or error message details).",
|
|
134
|
+
"",
|
|
135
|
+
"## Impact",
|
|
136
|
+
"What is blocked or affected while this incident is active.",
|
|
137
|
+
"",
|
|
138
|
+
"## Remediation Steps",
|
|
139
|
+
"Numbered list of concrete steps to fix this incident (e.g., retry job, fix input data, deploy missing resource, update process).",
|
|
140
|
+
"",
|
|
141
|
+
"## Prevention",
|
|
142
|
+
"How to prevent this class of error going forward.",
|
|
143
|
+
"",
|
|
144
|
+
"Be concise and practical. Use markdown formatting.",
|
|
145
|
+
].join("\n");
|
|
146
|
+
}
|
|
147
|
+
export function buildIncidentUserMessage(incident, variables, processXml) {
|
|
148
|
+
const lines = [
|
|
149
|
+
"## Incident",
|
|
150
|
+
`- **Type:** ${incident.errorType}`,
|
|
151
|
+
`- **Message:** ${incident.errorMessage}`,
|
|
152
|
+
`- **Element:** \`${incident.elementId}\``,
|
|
153
|
+
`- **Process:** ${incident.processDefinitionId}`,
|
|
154
|
+
`- **Instance:** ${incident.processInstanceKey}`,
|
|
155
|
+
`- **State:** ${incident.state}`,
|
|
156
|
+
];
|
|
157
|
+
if (incident.creationTime)
|
|
158
|
+
lines.push(`- **Created:** ${incident.creationTime}`);
|
|
159
|
+
if (incident.jobKey)
|
|
160
|
+
lines.push(`- **Job:** ${incident.jobKey}`);
|
|
161
|
+
if (variables.length > 0) {
|
|
162
|
+
lines.push("", "## Process Variables");
|
|
163
|
+
for (const v of variables.slice(0, 30)) {
|
|
164
|
+
lines.push(`- \`${v.name}\`: ${v.value ?? "null"}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (processXml) {
|
|
168
|
+
const MAX_XML = 6000;
|
|
169
|
+
const xml = processXml.length > MAX_XML ? `${processXml.slice(0, MAX_XML)}\n...truncated` : processXml;
|
|
170
|
+
lines.push("", "## Process Definition (BPMN XML)", "```xml", xml, "```");
|
|
171
|
+
}
|
|
172
|
+
return lines.join("\n");
|
|
173
|
+
}
|
|
174
|
+
// ── Fallback prompt builders (for non-MCP adapters like Gemini) ───────────────
|
|
175
|
+
/** Full system prompt for non-MCP adapters that must return a CompactDiagram JSON block. */
|
|
176
|
+
export function buildSystemPrompt(context) {
|
|
177
|
+
const lines = [
|
|
178
|
+
"You are a BPMN expert assistant. Help users create and modify BPMN 2.0 process diagrams.",
|
|
179
|
+
"",
|
|
180
|
+
COMPACT_FORMAT,
|
|
181
|
+
"",
|
|
182
|
+
"Return exactly one JSON code block containing the complete updated CompactDiagram. Explain your changes briefly.",
|
|
183
|
+
];
|
|
184
|
+
if (context !== null && context !== undefined) {
|
|
185
|
+
lines.push("", "Current diagram:", "```json", JSON.stringify(context, null, 2), "```");
|
|
186
|
+
}
|
|
187
|
+
return lines.join("\n");
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=prompt.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bpmnkit/proxy",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "Local proxy server for @bpmn-sdk — AI bridge (SSE/MCP) and Camunda API proxy using stored CLI profiles",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"bpmn-ai-server": "./dist/index.js",
|
|
8
|
+
"bpmn-mcp": "./dist/mcp-server.js"
|
|
9
|
+
},
|
|
10
|
+
"files": ["dist/**/*.js"],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=20"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@bpmnkit/api": "workspace:*",
|
|
16
|
+
"@bpmnkit/core": "workspace:*",
|
|
17
|
+
"@bpmnkit/profiles": "workspace:*"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"start": "node dist/index.js",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"check": "biome check .",
|
|
24
|
+
"dev": "node --watch dist/index.js",
|
|
25
|
+
"bridge": "esbuild src/bridge.ts --bundle --format=iife --global-name=Bridge --platform=neutral --outfile=dist/bridge.bundle.js",
|
|
26
|
+
"bundle": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/bundle.cjs && esbuild src/mcp-server.ts --bundle --platform=node --format=cjs --outfile=dist/mcp-server.cjs && pnpm run bridge"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/bpmnkit/monorepo"
|
|
34
|
+
}
|
|
35
|
+
}
|