@bpmnkit/core 1.2.0 → 1.4.0

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 (51) hide show
  1. package/README.md +26 -0
  2. package/dist/bpmn/bpmn-builder.d.ts +8 -0
  3. package/dist/bpmn/bpmn-builder.js +6 -2
  4. package/dist/bpmn/compact.d.ts +39 -5
  5. package/dist/bpmn/compact.js +151 -29
  6. package/dist/bpmn/connector-line.d.ts +46 -0
  7. package/dist/bpmn/connector-line.js +135 -0
  8. package/dist/bpmn/full-operations.js +8 -1
  9. package/dist/bpmn/optimize/patterns.js +1 -3
  10. package/dist/bpmn/process-delta.d.ts +7 -0
  11. package/dist/bpmn/process-delta.js +34 -2
  12. package/dist/bpmn/process-text-writer.d.ts +12 -2
  13. package/dist/bpmn/process-text-writer.js +16 -1
  14. package/dist/bpmn/process-text.d.ts +36 -1
  15. package/dist/bpmn/process-text.js +412 -17
  16. package/dist/bpmn/rest-connector.d.ts +6 -0
  17. package/dist/bpmn/rest-connector.js +6 -0
  18. package/dist/bpmn/secrets.d.ts +15 -0
  19. package/dist/bpmn/secrets.js +59 -0
  20. package/dist/bpmn/utils.js +4 -0
  21. package/dist/bpmn/zeebe-extensions.d.ts +10 -0
  22. package/dist/bpmn/zeebe-extensions.js +7 -0
  23. package/dist/connectors/aliases.d.ts +21 -0
  24. package/dist/connectors/aliases.js +272 -0
  25. package/dist/connectors/api.d.ts +118 -0
  26. package/dist/connectors/api.js +280 -0
  27. package/dist/connectors/apply-element.d.ts +59 -0
  28. package/dist/connectors/apply-element.js +385 -0
  29. package/dist/connectors/apply.d.ts +136 -0
  30. package/dist/connectors/apply.js +352 -0
  31. package/dist/connectors/cards.d.ts +96 -0
  32. package/dist/connectors/cards.js +306 -0
  33. package/dist/connectors/catalog.d.ts +79 -0
  34. package/dist/connectors/catalog.js +209 -0
  35. package/dist/connectors/index.d.ts +33 -0
  36. package/dist/connectors/index.js +24 -0
  37. package/dist/connectors/lines.d.ts +108 -0
  38. package/dist/connectors/lines.js +568 -0
  39. package/dist/connectors/select.d.ts +85 -0
  40. package/dist/connectors/select.js +419 -0
  41. package/dist/connectors/template-types.d.ts +188 -0
  42. package/dist/connectors/template-types.js +6 -0
  43. package/dist/connectors/templates/bpmnkit.d.ts +12 -0
  44. package/dist/connectors/templates/bpmnkit.js +186 -0
  45. package/dist/connectors/templates/generated.d.ts +3 -0
  46. package/dist/connectors/templates/generated.js +95885 -0
  47. package/dist/connectors/validate.d.ts +66 -0
  48. package/dist/connectors/validate.js +271 -0
  49. package/dist/index.d.ts +7 -3
  50. package/dist/index.js +2 -0
  51. package/package.json +5 -1
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Connector cards: the smallest text that lets a model configure one connector
3
+ * operation.
4
+ *
5
+ * A template mixes many operations in one property list, gated by dropdowns:
6
+ * GitHub's `owner` is required by five operations and listed five times. A
7
+ * model handed the template, or a summary of it, cannot tell which inputs
8
+ * belong to the operation it wants. A card is one operation with only the
9
+ * inputs active for it. Modes of an operation (authentication type, AI
10
+ * provider) stay on the card as choices, each with the inputs it adds.
11
+ *
12
+ * Cards are worked out from the templates and {@link CONNECTOR_ALIASES}, never
13
+ * written by hand; tests apply every card's required inputs and expect no
14
+ * missing-required problem.
15
+ */
16
+ import { CONNECTOR_ALIASES } from "./aliases.js";
17
+ import { evalCondition, resolveValues } from "./apply.js";
18
+ import { allTemplates, isSecretField, propertyKey, summarizeTemplate, } from "./catalog.js";
19
+ /** The keys every condition of a template reads. */
20
+ function conditionKeys(template) {
21
+ const keys = new Set();
22
+ const visit = (condition) => {
23
+ if (!condition)
24
+ return;
25
+ if ("allMatch" in condition) {
26
+ for (const part of condition.allMatch)
27
+ keys.add(part.property);
28
+ }
29
+ else {
30
+ keys.add(condition.property);
31
+ }
32
+ };
33
+ for (const prop of template.properties)
34
+ visit(prop.condition);
35
+ return keys;
36
+ }
37
+ function isActive(prop, resolved) {
38
+ return prop.condition === undefined || evalCondition(prop.condition, resolved);
39
+ }
40
+ function activeDropdown(template, key, resolved) {
41
+ return template.properties.find((p) => p.type === "Dropdown" && propertyKey(p) === key && isActive(p, resolved));
42
+ }
43
+ /** Every choice of the operation dropdowns, nested ones only under the choice that shows them. */
44
+ function operationsOf(template, selectors) {
45
+ const found = [];
46
+ const walk = (values, path) => {
47
+ const resolved = resolveValues(template, values);
48
+ for (const key of selectors) {
49
+ if (key in values)
50
+ continue;
51
+ const dropdown = activeDropdown(template, key, resolved);
52
+ if (!dropdown?.choices?.length)
53
+ continue;
54
+ for (const choice of dropdown.choices) {
55
+ walk({ ...values, [key]: choice.value }, [...path, choice]);
56
+ }
57
+ return;
58
+ }
59
+ found.push({ values, path });
60
+ };
61
+ walk({}, []);
62
+ return found;
63
+ }
64
+ /** Inputs nearly every template has and nearly no flow sets. */
65
+ const ADVANCED_KEYS = new Set([
66
+ "errorExpression",
67
+ "retryCount",
68
+ "retryBackoff",
69
+ "jobTimeout",
70
+ "connectionTimeoutInSeconds",
71
+ "readTimeoutInSeconds",
72
+ "messageTtl",
73
+ "messageIdExpression",
74
+ "activationCondition",
75
+ "inbound.activationCondition",
76
+ "consumeUnmatchedEvents",
77
+ "regionOverride",
78
+ ]);
79
+ function isAdvanced(prop, key) {
80
+ return (ADVANCED_KEYS.has(key) ||
81
+ key.startsWith("clientTls.") ||
82
+ key.startsWith("deduplication") ||
83
+ prop.type === "Configuration");
84
+ }
85
+ function toInput(prop, key) {
86
+ const input = { key, label: prop.label ?? key };
87
+ if (isAdvanced(prop, key))
88
+ input.advanced = true;
89
+ if (isSecretField(prop, key))
90
+ input.secret = true;
91
+ if (prop.feel === "required")
92
+ input.feel = true;
93
+ if (prop.type === "Dropdown" && prop.choices)
94
+ input.choices = prop.choices.map((c) => c.value);
95
+ if (prop.value !== undefined && prop.value !== "")
96
+ input.default = String(prop.value);
97
+ return input;
98
+ }
99
+ function buildCard(template, alias, operation, name) {
100
+ const summary = summarizeTemplate(template);
101
+ const gates = conditionKeys(template);
102
+ const resolved = resolveValues(template, operation.values);
103
+ const required = [];
104
+ const optional = [];
105
+ const modes = [];
106
+ const seen = new Set(Object.keys(operation.values));
107
+ for (const prop of template.properties) {
108
+ const key = propertyKey(prop);
109
+ if (!key || seen.has(key) || prop.type === "Hidden" || !isActive(prop, resolved))
110
+ continue;
111
+ seen.add(key);
112
+ if (prop.type === "Dropdown" && gates.has(key) && prop.choices?.length) {
113
+ const mode = {
114
+ key,
115
+ label: prop.label ?? key,
116
+ default: resolved[key],
117
+ choices: prop.choices.map(({ value }) => {
118
+ const chosen = resolveValues(template, { ...operation.values, [key]: value });
119
+ const requires = template.properties
120
+ .filter((p) => p.type !== "Hidden" &&
121
+ p.constraints?.notEmpty === true &&
122
+ isActive(p, chosen) &&
123
+ !isActive(p, resolved))
124
+ .map(propertyKey);
125
+ return { value, requires: [...new Set(requires)] };
126
+ }),
127
+ };
128
+ if (prop.constraints?.notEmpty && resolved[key] === undefined)
129
+ mode.required = true;
130
+ modes.push(mode);
131
+ continue;
132
+ }
133
+ // Required means the flow must supply it: a required input with a default already has one
134
+ const needed = prop.constraints?.notEmpty === true && (prop.value === undefined || prop.value === "");
135
+ (needed ? required : optional).push(toInput(prop, key));
136
+ }
137
+ const card = {
138
+ templateId: template.id,
139
+ alias,
140
+ title: operation.path.length > 0
141
+ ? `${template.name}: ${operation.path.map((p) => p.name).join(" / ")}`
142
+ : template.name,
143
+ direction: summary.direction,
144
+ values: operation.values,
145
+ required,
146
+ optional,
147
+ modes,
148
+ };
149
+ if (name !== undefined)
150
+ card.operation = name;
151
+ if (template.description)
152
+ card.description = template.description;
153
+ if (summary.taskType)
154
+ card.taskType = summary.taskType;
155
+ return card;
156
+ }
157
+ /** The alias of a template: its entry in {@link CONNECTOR_ALIASES}, else its id. */
158
+ export function connectorAlias(templateId) {
159
+ return CONNECTOR_ALIASES[templateId]?.alias ?? templateId;
160
+ }
161
+ /** The template an alias names, among bundled and registered templates. */
162
+ export function templateIdForAlias(alias) {
163
+ const wanted = alias.toLowerCase();
164
+ return allTemplates().find((t) => connectorAlias(t.id).toLowerCase() === wanted)?.id;
165
+ }
166
+ const cardsByTemplate = new WeakMap();
167
+ function cardsFor(template) {
168
+ const cached = cardsByTemplate.get(template);
169
+ if (cached)
170
+ return cached;
171
+ const entry = CONNECTOR_ALIASES[template.id];
172
+ const operations = operationsOf(template, entry?.operations ?? []);
173
+ // The innermost choice names an operation, unless two share it (then the whole path does)
174
+ const leaf = (op) => op.path.at(-1)?.value;
175
+ const counts = new Map();
176
+ for (const op of operations)
177
+ counts.set(leaf(op), (counts.get(leaf(op)) ?? 0) + 1);
178
+ const cards = operations.map((op) => buildCard(template, connectorAlias(template.id), op, op.path.length === 0
179
+ ? undefined
180
+ : (counts.get(leaf(op)) ?? 0) > 1
181
+ ? op.path.map((p) => p.value).join(".")
182
+ : leaf(op)));
183
+ cardsByTemplate.set(template, cards);
184
+ return cards;
185
+ }
186
+ /** The cards of one template, registered or bundled; empty for an unknown id. */
187
+ export function connectorCards(templateId) {
188
+ const template = allTemplates().find((t) => t.id === templateId);
189
+ return template ? cardsFor(template) : [];
190
+ }
191
+ /** Every card of every bundled and registered template. */
192
+ export function listConnectorCards() {
193
+ return allTemplates().flatMap(cardsFor);
194
+ }
195
+ const DIRECTION_RANK = {
196
+ outbound: 0,
197
+ agentic: 1,
198
+ "inbound-start": 2,
199
+ "inbound-intermediate": 3,
200
+ "inbound-boundary": 4,
201
+ };
202
+ function words(text) {
203
+ return text
204
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
205
+ .toLowerCase()
206
+ .split(/[^a-z0-9]+/)
207
+ .filter((w) => w.length > 1);
208
+ }
209
+ /** Words a request uses that say nothing about which connector it means. */
210
+ const NOISE = new Set([
211
+ "a",
212
+ "an",
213
+ "the",
214
+ "to",
215
+ "of",
216
+ "for",
217
+ "from",
218
+ "with",
219
+ "and",
220
+ "in",
221
+ "on",
222
+ "into",
223
+ "via",
224
+ "my",
225
+ "our",
226
+ "api",
227
+ "call",
228
+ "connector",
229
+ "using",
230
+ ]);
231
+ /** How well a card matches search terms: alias, then template name, then operation, then anywhere. */
232
+ export function cardScore(card, terms) {
233
+ const alias = card.alias.toLowerCase();
234
+ const name = new Set(words(card.title.split(":")[0] ?? ""));
235
+ const operation = new Set(words(`${card.operation ?? ""} ${card.title.split(":")[1] ?? ""}`));
236
+ const anywhere = `${card.description ?? ""} ${card.taskType ?? ""}`.toLowerCase();
237
+ let score = 0;
238
+ for (const term of terms) {
239
+ if (alias === term || alias.split("-").includes(term))
240
+ score += 5;
241
+ else if (name.has(term))
242
+ score += 4;
243
+ if (operation.has(term))
244
+ score += 3;
245
+ else if (anywhere.includes(term))
246
+ score += 1;
247
+ }
248
+ return score;
249
+ }
250
+ /** The words of a request that can say which connector it means. */
251
+ export function searchTerms(text) {
252
+ return words(text).filter((w) => !NOISE.has(w));
253
+ }
254
+ /**
255
+ * Cards that match a query, best first: an alias named outright scores highest,
256
+ * then words of the template name, then of the operation, then anywhere.
257
+ * Outbound connectors win ties.
258
+ */
259
+ export function findConnectorCards(query, options = {}) {
260
+ const terms = searchTerms(query);
261
+ if (terms.length === 0)
262
+ return [];
263
+ const scored = listConnectorCards()
264
+ .map((card) => ({ card, score: cardScore(card, terms) }))
265
+ .filter((s) => s.score > 0)
266
+ .sort((a, b) => b.score - a.score || DIRECTION_RANK[a.card.direction] - DIRECTION_RANK[b.card.direction]);
267
+ return scored.slice(0, options.limit ?? 5).map((s) => s.card);
268
+ }
269
+ function inputText(input, required) {
270
+ let text = input.key;
271
+ if (required)
272
+ text += "*";
273
+ if (input.secret)
274
+ text += "(secret)";
275
+ else if (input.feel)
276
+ text += "(=FEEL)";
277
+ else if (input.choices) {
278
+ const shown = input.choices.slice(0, 6).join("|");
279
+ text += `(${shown}${input.choices.length > 6 ? "|…" : ""})`;
280
+ }
281
+ return text;
282
+ }
283
+ /**
284
+ * A card as one line for a prompt: `alias operation — title | required* … |
285
+ * optional: … | mode=default: choice(adds*) …`. A `*` marks a required input.
286
+ * Advanced inputs are left out unless `options.advanced` is set.
287
+ */
288
+ export function formatConnectorCard(card, options = {}) {
289
+ const head = `${card.alias}${card.operation ? ` ${card.operation}` : ""} — ${card.title}`;
290
+ const parts = [head];
291
+ if (card.required.length > 0)
292
+ parts.push(card.required.map((i) => inputText(i, true)).join(" "));
293
+ const optional = options.advanced ? card.optional : card.optional.filter((i) => !i.advanced);
294
+ if (optional.length > 0) {
295
+ parts.push(`optional: ${optional.map((i) => inputText(i, false)).join(" ")}`);
296
+ }
297
+ for (const mode of card.modes) {
298
+ const choices = mode.choices
299
+ .map((c) => (c.requires.length > 0 ? `${c.value}(${c.requires.join(" ")})` : c.value))
300
+ .join(" | ");
301
+ const head = `${mode.key}${mode.required ? "*" : ""}${mode.default ? `=${mode.default}` : ""}`;
302
+ parts.push(`${head}: ${choices}`);
303
+ }
304
+ return parts.join(" | ");
305
+ }
306
+ //# sourceMappingURL=cards.js.map
@@ -0,0 +1,79 @@
1
+ import type { ElementTemplate, TemplateCondition, TemplateProperty } from "./template-types.js";
2
+ /** Where in the process a connector template attaches. */
3
+ export type ConnectorDirection = "outbound" | "inbound-start" | "inbound-intermediate" | "inbound-boundary"
4
+ /** The AI Agent Sub-process connector — an ad-hoc sub-process, not a single task. */
5
+ | "agentic";
6
+ /** One user-configurable (non-Hidden) property on a connector template. */
7
+ export interface ConnectorInputSpec {
8
+ /** Lookup key — matches the keys `applyConnectorTemplate()` expects in its `values` argument. */
9
+ key: string;
10
+ label: string;
11
+ description?: string;
12
+ /** True for fields whose label/key suggest a credential (API key, token, password, secret). */
13
+ isSecret: boolean;
14
+ /** True if the field's value is interpreted as FEEL (a leading "=" makes it an expression). */
15
+ isFeel: boolean;
16
+ default?: string | number | boolean;
17
+ choices?: Array<{
18
+ name: string;
19
+ value: string;
20
+ }>;
21
+ /** This field only applies (and is only required) when this condition holds against other values. */
22
+ condition?: TemplateCondition;
23
+ }
24
+ /** A connector template reduced to what a skill or LLM needs to select and configure it. */
25
+ export interface ConnectorSummary {
26
+ id: string;
27
+ name: string;
28
+ description?: string;
29
+ /** Zeebe job type this template sets, e.g. "io.camunda:slack:1". Absent for some inbound templates. */
30
+ taskType?: string;
31
+ appliesTo: string[];
32
+ direction: ConnectorDirection;
33
+ keywords: string[];
34
+ requiredInputs: ConnectorInputSpec[];
35
+ optionalInputs: ConnectorInputSpec[];
36
+ }
37
+ export declare function isSecretField(prop: TemplateProperty, key: string): boolean;
38
+ /** Same key-derivation logic used at apply time — kept in sync with `apply.ts`. */
39
+ export declare function propertyKey(prop: TemplateProperty): string;
40
+ /**
41
+ * What a template will do, without applying it.
42
+ *
43
+ * The catalogue computes this for every listing already; it is exported because
44
+ * anything offering a template to a person needs to be able to say what it
45
+ * binds and what it will ask for — a picker that applies on the first click is
46
+ * asking someone to choose blind.
47
+ *
48
+ * @param template - The template to describe.
49
+ */
50
+ export declare function summarizeTemplate(template: ElementTemplate): ConnectorSummary;
51
+ /**
52
+ * Adds templates to the catalogue, replacing any bundled template with the same
53
+ * id.
54
+ *
55
+ * The workspace wins deliberately: a project that ships its own version of a
56
+ * connector means it, and the bundle is the fallback. Registering the same id
57
+ * twice keeps the later one, so a nearer directory can override a further one.
58
+ *
59
+ * @param templates - Validated templates. Nothing is checked here; run
60
+ * `validateElementTemplate` (or `readTemplateDocument`) at the boundary where
61
+ * the JSON was read, so a bad file is reported against its own path.
62
+ */
63
+ export declare function registerElementTemplates(templates: readonly ElementTemplate[]): void;
64
+ /** Drops every registered template, leaving only the bundled catalogue. */
65
+ export declare function clearRegisteredTemplates(): void;
66
+ /** The bundled templates plus registered ones, the latter winning on id. */
67
+ export declare function allTemplates(): readonly ElementTemplate[];
68
+ /** Every connector template — bundled and registered — as a compact summary. */
69
+ export declare function listConnectors(): ConnectorSummary[];
70
+ /** The full element template for a given template id, registered or bundled. */
71
+ export declare function getTemplate(id: string): ElementTemplate | undefined;
72
+ /**
73
+ * Keyword-scored search over the bundled connector catalog — mirrors
74
+ * `@bpmnkit/patterns`' `findPattern()` matching style. Matches against the
75
+ * template name are weighted highest, then keyword-list matches, then a
76
+ * general substring match; ties prefer outbound connectors.
77
+ */
78
+ export declare function searchConnectors(query: string): ConnectorSummary[];
79
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1,209 @@
1
+ import { BPMNKIT_CONNECTOR_TEMPLATES } from "./templates/bpmnkit.js";
2
+ import { BUNDLED_CONNECTOR_TEMPLATES } from "./templates/generated.js";
3
+ const SECRET_PATTERN = /token|secret|password|api.?key|apikey|credential|access.?key/i;
4
+ export function isSecretField(prop, key) {
5
+ return SECRET_PATTERN.test(`${prop.label ?? ""} ${key}`);
6
+ }
7
+ /** Same key-derivation logic used at apply time — kept in sync with `apply.ts`. */
8
+ export function propertyKey(prop) {
9
+ if (prop.id)
10
+ return prop.id;
11
+ const b = prop.binding;
12
+ if (b.type === "zeebe:input")
13
+ return b.name;
14
+ if (b.type === "zeebe:output")
15
+ return b.source;
16
+ if (b.type === "zeebe:taskHeader")
17
+ return b.key;
18
+ if (b.type === "zeebe:taskDefinition")
19
+ return `taskDef.${b.property}`;
20
+ if (b.type === "zeebe:taskDefinition:type")
21
+ return "taskDef.type";
22
+ if (b.type === "property")
23
+ return b.name;
24
+ if (b.type === "zeebe:property")
25
+ return b.name;
26
+ if (b.type === "zeebe:adHoc")
27
+ return `adHoc.${b.property}`;
28
+ if (b.type === "zeebe:agentDefinition")
29
+ return `agentDefinition.${b.property}`;
30
+ if (b.type === "bpmn:Message#property")
31
+ return `message.${b.name}`;
32
+ if (b.type === "bpmn:Message#zeebe:subscription#property")
33
+ return `message.${b.name}`;
34
+ if (b.type === "zeebe:linkedResource")
35
+ return `linkedResource.${b.linkName}.${b.property}`;
36
+ return "";
37
+ }
38
+ function toInputSpec(prop) {
39
+ const key = propertyKey(prop);
40
+ return {
41
+ key,
42
+ label: prop.label ?? key,
43
+ description: prop.description,
44
+ isSecret: isSecretField(prop, key),
45
+ isFeel: prop.feel === "required" || prop.feel === "optional",
46
+ default: prop.value,
47
+ choices: prop.choices,
48
+ condition: prop.condition,
49
+ };
50
+ }
51
+ function taskDefinitionType(template) {
52
+ for (const prop of template.properties) {
53
+ if (prop.binding.type === "zeebe:taskDefinition" && prop.binding.property === "type") {
54
+ return typeof prop.value === "string" ? prop.value : undefined;
55
+ }
56
+ if (prop.binding.type === "zeebe:taskDefinition:type") {
57
+ return typeof prop.value === "string" ? prop.value : undefined;
58
+ }
59
+ }
60
+ return undefined;
61
+ }
62
+ function directionOf(template) {
63
+ const elementType = template.elementType?.value ?? template.appliesTo[0];
64
+ switch (elementType) {
65
+ case "bpmn:AdHocSubProcess":
66
+ return "agentic";
67
+ case "bpmn:StartEvent":
68
+ return "inbound-start";
69
+ case "bpmn:IntermediateCatchEvent":
70
+ case "bpmn:IntermediateThrowEvent":
71
+ case "bpmn:ReceiveTask":
72
+ return "inbound-intermediate";
73
+ case "bpmn:BoundaryEvent":
74
+ return "inbound-boundary";
75
+ default:
76
+ return "outbound";
77
+ }
78
+ }
79
+ function keywordsOf(template) {
80
+ const words = new Set();
81
+ for (const raw of `${template.name} ${template.description ?? ""}`
82
+ .toLowerCase()
83
+ .split(/[^a-z0-9]+/)) {
84
+ if (raw.length > 2)
85
+ words.add(raw);
86
+ }
87
+ return [...words];
88
+ }
89
+ /**
90
+ * What a template will do, without applying it.
91
+ *
92
+ * The catalogue computes this for every listing already; it is exported because
93
+ * anything offering a template to a person needs to be able to say what it
94
+ * binds and what it will ask for — a picker that applies on the first click is
95
+ * asking someone to choose blind.
96
+ *
97
+ * @param template - The template to describe.
98
+ */
99
+ export function summarizeTemplate(template) {
100
+ const visible = template.properties.filter((p) => p.type !== "Hidden");
101
+ return {
102
+ id: template.id,
103
+ name: template.name,
104
+ description: template.description,
105
+ taskType: taskDefinitionType(template),
106
+ appliesTo: template.appliesTo,
107
+ direction: directionOf(template),
108
+ keywords: keywordsOf(template),
109
+ requiredInputs: visible.filter((p) => p.constraints?.notEmpty === true).map(toInputSpec),
110
+ optionalInputs: visible.filter((p) => p.constraints?.notEmpty !== true).map(toInputSpec),
111
+ };
112
+ }
113
+ /**
114
+ * Templates a host has registered on top of the bundled catalogue — a project's
115
+ * own `.camunda/element-templates/`, or anything else it has that the bundle
116
+ * does not.
117
+ *
118
+ * Kept separate rather than merged into one array so the bundle stays the
119
+ * constant it is declared to be, and so `clearRegisteredTemplates()` is exact.
120
+ */
121
+ const registered = new Map();
122
+ let cachedSummaries;
123
+ /**
124
+ * Adds templates to the catalogue, replacing any bundled template with the same
125
+ * id.
126
+ *
127
+ * The workspace wins deliberately: a project that ships its own version of a
128
+ * connector means it, and the bundle is the fallback. Registering the same id
129
+ * twice keeps the later one, so a nearer directory can override a further one.
130
+ *
131
+ * @param templates - Validated templates. Nothing is checked here; run
132
+ * `validateElementTemplate` (or `readTemplateDocument`) at the boundary where
133
+ * the JSON was read, so a bad file is reported against its own path.
134
+ */
135
+ export function registerElementTemplates(templates) {
136
+ for (const template of templates)
137
+ registered.set(template.id, template);
138
+ cachedSummaries = undefined;
139
+ }
140
+ /** Drops every registered template, leaving only the bundled catalogue. */
141
+ export function clearRegisteredTemplates() {
142
+ registered.clear();
143
+ cachedSummaries = undefined;
144
+ }
145
+ /** Camunda's marketplace templates, then the ones this repo maintains. */
146
+ const BUNDLED = [
147
+ ...BUNDLED_CONNECTOR_TEMPLATES,
148
+ ...BPMNKIT_CONNECTOR_TEMPLATES,
149
+ ];
150
+ /** The bundled templates plus registered ones, the latter winning on id. */
151
+ export function allTemplates() {
152
+ if (registered.size === 0)
153
+ return BUNDLED;
154
+ const bundled = BUNDLED.filter((t) => !registered.has(t.id));
155
+ return [...bundled, ...registered.values()];
156
+ }
157
+ /** Every connector template — bundled and registered — as a compact summary. */
158
+ export function listConnectors() {
159
+ if (!cachedSummaries) {
160
+ cachedSummaries = allTemplates().map(summarizeTemplate);
161
+ }
162
+ return cachedSummaries;
163
+ }
164
+ /** The full element template for a given template id, registered or bundled. */
165
+ export function getTemplate(id) {
166
+ return registered.get(id) ?? BUNDLED.find((t) => t.id === id);
167
+ }
168
+ /** Tie-break preference when two templates score equally — outbound "do this" connectors are the common case. */
169
+ const DIRECTION_RANK = {
170
+ outbound: 0,
171
+ agentic: 1,
172
+ "inbound-start": 2,
173
+ "inbound-intermediate": 3,
174
+ "inbound-boundary": 4,
175
+ };
176
+ /**
177
+ * Keyword-scored search over the bundled connector catalog — mirrors
178
+ * `@bpmnkit/patterns`' `findPattern()` matching style. Matches against the
179
+ * template name are weighted highest, then keyword-list matches, then a
180
+ * general substring match; ties prefer outbound connectors.
181
+ */
182
+ export function searchConnectors(query) {
183
+ const terms = query
184
+ .toLowerCase()
185
+ .split(/[^a-z0-9]+/)
186
+ .filter((t) => t.length > 1);
187
+ if (terms.length === 0)
188
+ return [];
189
+ const scored = listConnectors()
190
+ .map((summary) => {
191
+ const nameWords = new Set(summary.name.toLowerCase().split(/[^a-z0-9]+/));
192
+ const haystack = `${summary.name} ${summary.description ?? ""} ${summary.keywords.join(" ")} ${summary.taskType ?? ""}`.toLowerCase();
193
+ let score = 0;
194
+ for (const term of terms) {
195
+ if (nameWords.has(term))
196
+ score += 4;
197
+ else if (summary.keywords.includes(term))
198
+ score += 3;
199
+ else if (haystack.includes(term))
200
+ score += 1;
201
+ }
202
+ return { summary, score };
203
+ })
204
+ .filter((s) => s.score > 0)
205
+ .sort((a, b) => b.score - a.score ||
206
+ DIRECTION_RANK[a.summary.direction] - DIRECTION_RANK[b.summary.direction]);
207
+ return scored.map((s) => s.summary);
208
+ }
209
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The Camunda 8 out-of-the-box connector catalog and deterministic
3
+ * element-template application, as `@bpmnkit/core/connectors`.
4
+ *
5
+ * A separate entry so the catalog's data (about 100 KB gzipped) is only paid
6
+ * for by code that imports it; `@bpmnkit/core` itself does not grow. The
7
+ * bundled templates leave out icons, groups, tooltips and placeholders, which
8
+ * only a property panel draws — `@bpmnkit/connectors` has the full templates
9
+ * and re-exports this API on top of them.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ export { listConnectors, searchConnectors, getTemplate, propertyKey, registerElementTemplates, clearRegisteredTemplates, summarizeTemplate, } from "./catalog.js";
14
+ export type { ConnectorSummary, ConnectorInputSpec, ConnectorDirection } from "./catalog.js";
15
+ export { applyConnectorTemplate, applyElementTemplate } from "./apply.js";
16
+ export type { ApplyResult, ApplyProblem } from "./apply.js";
17
+ export { applyTemplateToElement } from "./apply-element.js";
18
+ export type { ApplyToElementResult } from "./apply-element.js";
19
+ export { BUNDLED_CONNECTOR_TEMPLATES } from "./templates/generated.js";
20
+ export { BPMNKIT_CONNECTOR_TEMPLATES } from "./templates/bpmnkit.js";
21
+ export { CONNECTOR_ALIASES } from "./aliases.js";
22
+ export { connectorAlias, connectorCards, findConnectorCards, formatConnectorCard, listConnectorCards, templateIdForAlias, } from "./cards.js";
23
+ export type { CardInput, CardMode, ConnectorCard } from "./cards.js";
24
+ export { CONNECT_GUIDE, applyConnectorLines, connectorLineFor, isConnectorAlias, resolveConnectorLine, } from "./lines.js";
25
+ export type { AppliedConnectorLines, ConnectorLineOptions, ResolvedConnectorLine, } from "./lines.js";
26
+ export { apiAuthValues, apiBrand, apiSecretNames, apiServicesIn, apiUrl, findApiOperation, findApiOperations, formatApiCard, formatApiOperation, rankApiOperations, } from "./api.js";
27
+ export type { ApiAuth, ApiCard, ApiOperation, ApiService, ApiServiceSummary, RankedApiOperation, } from "./api.js";
28
+ export { formatConnectorSelection, selectConnectors } from "./select.js";
29
+ export type { ConnectorTask, TaskCards } from "./select.js";
30
+ export type { ElementTemplate, TemplateGroup, TemplateProperty, TemplateBinding, TemplateCondition, } from "./template-types.js";
31
+ export { validateElementTemplate, readTemplateDocument } from "./validate.js";
32
+ export type { TemplateProblem, TemplateValidation, TemplateDocumentResult, } from "./validate.js";
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The Camunda 8 out-of-the-box connector catalog and deterministic
3
+ * element-template application, as `@bpmnkit/core/connectors`.
4
+ *
5
+ * A separate entry so the catalog's data (about 100 KB gzipped) is only paid
6
+ * for by code that imports it; `@bpmnkit/core` itself does not grow. The
7
+ * bundled templates leave out icons, groups, tooltips and placeholders, which
8
+ * only a property panel draws — `@bpmnkit/connectors` has the full templates
9
+ * and re-exports this API on top of them.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ export { listConnectors, searchConnectors, getTemplate, propertyKey, registerElementTemplates, clearRegisteredTemplates, summarizeTemplate, } from "./catalog.js";
14
+ export { applyConnectorTemplate, applyElementTemplate } from "./apply.js";
15
+ export { applyTemplateToElement } from "./apply-element.js";
16
+ export { BUNDLED_CONNECTOR_TEMPLATES } from "./templates/generated.js";
17
+ export { BPMNKIT_CONNECTOR_TEMPLATES } from "./templates/bpmnkit.js";
18
+ export { CONNECTOR_ALIASES } from "./aliases.js";
19
+ export { connectorAlias, connectorCards, findConnectorCards, formatConnectorCard, listConnectorCards, templateIdForAlias, } from "./cards.js";
20
+ export { CONNECT_GUIDE, applyConnectorLines, connectorLineFor, isConnectorAlias, resolveConnectorLine, } from "./lines.js";
21
+ export { apiAuthValues, apiBrand, apiSecretNames, apiServicesIn, apiUrl, findApiOperation, findApiOperations, formatApiCard, formatApiOperation, rankApiOperations, } from "./api.js";
22
+ export { formatConnectorSelection, selectConnectors } from "./select.js";
23
+ export { validateElementTemplate, readTemplateDocument } from "./validate.js";
24
+ //# sourceMappingURL=index.js.map