@bpmnkit/proxy 0.0.25 → 0.0.27
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/aikit-mcp.js +93 -0
- package/dist/camunda-spec.js +1147 -0
- package/dist/mcp-server.js +56 -0
- package/dist/sandbox.js +27 -0
- package/dist/sdk-code-mode.js +60 -0
- package/dist/sdk-spec.js +67 -0
- package/package.json +6 -5
package/dist/aikit-mcp.js
CHANGED
|
@@ -22,9 +22,12 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from
|
|
|
22
22
|
import { homedir } from "node:os";
|
|
23
23
|
import { basename, dirname, join } from "node:path";
|
|
24
24
|
import { createInterface } from "node:readline";
|
|
25
|
+
import { CamundaClient } from "@bpmnkit/api";
|
|
25
26
|
import { Bpmn, compactify, optimize } from "@bpmnkit/core";
|
|
26
27
|
import { ALL_PATTERNS, findPattern } from "@bpmnkit/patterns";
|
|
27
28
|
import { getActiveProfile, getAuthHeader } from "@bpmnkit/profiles";
|
|
29
|
+
import { CAMUNDA_SPEC } from "./camunda-spec.js";
|
|
30
|
+
import { runSandboxed } from "./sandbox.js";
|
|
28
31
|
// ── Config ────────────────────────────────────────────────────────────────────
|
|
29
32
|
const PROXY_URL = (process.env.BPMNKIT_PROXY_URL ?? "http://localhost:3033").replace(/\/$/, "");
|
|
30
33
|
const ZEEBE_ADDRESS = (process.env.ZEEBE_ADDRESS ?? "http://localhost:26500").replace(/\/$/, "");
|
|
@@ -867,7 +870,93 @@ const TOOLS = [
|
|
|
867
870
|
required: ["bpmnPath"],
|
|
868
871
|
},
|
|
869
872
|
},
|
|
873
|
+
{
|
|
874
|
+
name: "camunda_search",
|
|
875
|
+
description: "Inspect the Camunda 8 REST API spec to discover available operations before calling camunda_execute.\n" +
|
|
876
|
+
"Receives `spec` — an object keyed by resource group (processInstance, incident, job, etc.).\n" +
|
|
877
|
+
"Each entry maps method names to { description, endpoint, params, returns }.\n\n" +
|
|
878
|
+
"Example — list all process instance methods:\n" +
|
|
879
|
+
" return Object.keys(spec.processInstance)\n\n" +
|
|
880
|
+
"Example — find all search operations across resources:\n" +
|
|
881
|
+
" return Object.entries(spec).flatMap(([r, ms]) => Object.keys(ms).filter(m => m.startsWith('search')).map(m => r + '.' + m))\n\n" +
|
|
882
|
+
"Example — get full spec for one method:\n" +
|
|
883
|
+
" return spec.incident.resolveIncident",
|
|
884
|
+
inputSchema: {
|
|
885
|
+
type: "object",
|
|
886
|
+
properties: {
|
|
887
|
+
code: {
|
|
888
|
+
type: "string",
|
|
889
|
+
description: "JavaScript returning a value. Has `spec` as a global.",
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
required: ["code"],
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
name: "camunda_execute",
|
|
897
|
+
description: "Execute JavaScript against the authenticated Camunda 8 REST API.\n" +
|
|
898
|
+
"Has access to `camunda` — a proxy over the live CamundaClient.\n" +
|
|
899
|
+
"Call camunda_search first to discover resource group names and method parameter shapes.\n\n" +
|
|
900
|
+
"Example — list active process instances:\n" +
|
|
901
|
+
" const r = await camunda.processInstance.searchProcessInstances({ filter: { state: 'ACTIVE' } })\n" +
|
|
902
|
+
" return r.items.map(i => ({ key: i.processInstanceKey, id: i.bpmnProcessId }))\n\n" +
|
|
903
|
+
"Example — resolve an incident:\n" +
|
|
904
|
+
" await camunda.incident.resolveIncident({ incidentKey: '9007199254741099' })\n" +
|
|
905
|
+
" return 'resolved'",
|
|
906
|
+
inputSchema: {
|
|
907
|
+
type: "object",
|
|
908
|
+
properties: {
|
|
909
|
+
code: {
|
|
910
|
+
type: "string",
|
|
911
|
+
description: "Async JavaScript. Has `camunda` proxy. Return value is JSON-serialized.",
|
|
912
|
+
},
|
|
913
|
+
},
|
|
914
|
+
required: ["code"],
|
|
915
|
+
},
|
|
916
|
+
},
|
|
870
917
|
];
|
|
918
|
+
export async function handleCamundaSearch(code) {
|
|
919
|
+
const result = await runSandboxed(code, { data: { spec: CAMUNDA_SPEC } }, 5000);
|
|
920
|
+
return JSON.stringify(result);
|
|
921
|
+
}
|
|
922
|
+
// Bootstrap injected into the isolate — builds a camunda proxy over __dispatch.
|
|
923
|
+
// The proxy intercepts resource.method(args) calls and routes them to the host client.
|
|
924
|
+
const CAMUNDA_PROXY_BOOTSTRAP = `
|
|
925
|
+
const camunda = new Proxy({}, {
|
|
926
|
+
get(_, resource) {
|
|
927
|
+
return new Proxy({}, {
|
|
928
|
+
get(_, method) {
|
|
929
|
+
return async (args) => {
|
|
930
|
+
const json = await __dispatch.apply(
|
|
931
|
+
undefined,
|
|
932
|
+
[resource, method, JSON.stringify(args ?? null)],
|
|
933
|
+
{ result: { promise: true, copy: true } }
|
|
934
|
+
)
|
|
935
|
+
return JSON.parse(json)
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
})
|
|
939
|
+
}
|
|
940
|
+
})
|
|
941
|
+
`;
|
|
942
|
+
export async function handleCamundaExecute(code) {
|
|
943
|
+
const profile = getActiveProfile();
|
|
944
|
+
if (!profile)
|
|
945
|
+
throw new Error("No active Camunda profile");
|
|
946
|
+
const client = new CamundaClient(profile.config);
|
|
947
|
+
const dispatch = async (resource, method, argsJson) => {
|
|
948
|
+
const rc = client[String(resource)];
|
|
949
|
+
if (!rc)
|
|
950
|
+
throw new Error(`Unknown resource: ${resource}`);
|
|
951
|
+
const fn = rc[String(method)];
|
|
952
|
+
if (typeof fn !== "function")
|
|
953
|
+
throw new Error(`Unknown method: ${resource}.${method}`);
|
|
954
|
+
const result = await fn.call(rc, JSON.parse(String(argsJson)));
|
|
955
|
+
return JSON.stringify(result ?? null);
|
|
956
|
+
};
|
|
957
|
+
const result = await runSandboxed(code, { bootstrap: CAMUNDA_PROXY_BOOTSTRAP, functions: { __dispatch: dispatch } }, 10000);
|
|
958
|
+
return JSON.stringify(result);
|
|
959
|
+
}
|
|
871
960
|
async function callTool(name, args) {
|
|
872
961
|
process.stderr.write(`[aikit-mcp] tool: ${name} args: ${JSON.stringify(args)}\n`);
|
|
873
962
|
switch (name) {
|
|
@@ -908,6 +997,10 @@ async function callTool(name, args) {
|
|
|
908
997
|
const outDir = args.outputDir ? String(args.outputDir) : undefined;
|
|
909
998
|
return toolDmnCreate(path, outDir);
|
|
910
999
|
}
|
|
1000
|
+
case "camunda_search":
|
|
1001
|
+
return handleCamundaSearch(args.code);
|
|
1002
|
+
case "camunda_execute":
|
|
1003
|
+
return handleCamundaExecute(args.code);
|
|
911
1004
|
default:
|
|
912
1005
|
throw new Error(`Unknown tool: ${name}`);
|
|
913
1006
|
}
|