@nanobpm/urban 0.85.0 → 0.86.1
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/openapi/spec.d.ts +72 -0
- package/dist/openapi/spec.js +130 -0
- package/dist/runtime/core/host.d.ts +67 -9
- package/dist/runtime/core/host.js +48 -0
- package/dist/runtime/core/modules/mcp.d.ts +23 -5
- package/dist/runtime/core/modules/mcp.js +346 -61
- package/dist/runtime/engine/nanosdk.js +9 -5
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +4 -0
- package/package.json +3 -1
- package/src/openapi/mcp-parity.fixture.yaml +49 -0
- package/src/openapi/mcp-tools.snapshot.json +20 -0
- package/src/openapi/spec.test.ts +92 -0
- package/src/openapi/spec.ts +161 -0
- package/src/runtime/core/host.ts +83 -9
- package/src/runtime/core/modules/mcp.test.ts +526 -14
- package/src/runtime/core/modules/mcp.ts +391 -61
- package/src/runtime/engine/nanosdk.test.ts +69 -11
- package/src/runtime/engine/nanosdk.ts +9 -5
- package/src/runtime/index.ts +8 -0
package/dist/openapi/spec.d.ts
CHANGED
|
@@ -128,6 +128,11 @@ export interface OperationInfo {
|
|
|
128
128
|
* else the document-level default, else `[]`). An empty list means the operation is open. */
|
|
129
129
|
security: OpenApiSecurityRequirement[];
|
|
130
130
|
eject: boolean;
|
|
131
|
+
/** Whether the operation opts OUT of MCP tool projection via the `x-mcp` extension (ADR 0067).
|
|
132
|
+
* Defaults to `false` — an operation IS exposed as a tool unless it explicitly excludes itself.
|
|
133
|
+
* Security-relevant: this is the single authoring switch that keeps an operator-only door (e.g.
|
|
134
|
+
* a human-gated dispatch) out of the agent-facing tool surface. See {@link isMcpExcluded}. */
|
|
135
|
+
mcpExcluded: boolean;
|
|
131
136
|
summary?: string;
|
|
132
137
|
}
|
|
133
138
|
/** Parse an OpenAPI document from text. Accepts both YAML (the sanctioned authoring format for
|
|
@@ -143,6 +148,73 @@ export declare function resolveSchema(doc: OpenApiDoc, schema: OpenApiSchema | u
|
|
|
143
148
|
* (path, method) order. Operations without an operationId are skipped here; the runtime mount logs
|
|
144
149
|
* them at `warn` and skips them too — this keeps the pure collector total. */
|
|
145
150
|
export declare function collectOperations(doc: OpenApiDoc): OperationInfo[];
|
|
151
|
+
/**
|
|
152
|
+
* Read the `x-mcp` operation extension (ADR 0067 — MCP tool projection). An operation is EXPOSED as
|
|
153
|
+
* an MCP tool by default; it is excluded only when it says so explicitly, so a spec author opts a
|
|
154
|
+
* door OUT rather than every operation having to opt in. Recognised exclusion forms:
|
|
155
|
+
* - `x-mcp: false` — a terse boolean opt-out;
|
|
156
|
+
* - `x-mcp: { exclude: true }` — the object form (room for future keys, e.g. per-tool metadata).
|
|
157
|
+
* Any other value (including `x-mcp: true` / `{ exclude: false }` / absent) leaves the operation
|
|
158
|
+
* exposed — fail-open to the documented default. This is a SECURITY-RELEVANT authoring rule: it is
|
|
159
|
+
* the one switch that keeps an operator-only operation out of the agent-facing tool surface, so it
|
|
160
|
+
* is enforced from the same single walker the runtime and the parity guard both read (no second
|
|
161
|
+
* source of truth to drift, ADR 0053).
|
|
162
|
+
*/
|
|
163
|
+
export declare function isMcpExcluded(ext: unknown): boolean;
|
|
164
|
+
/** Whether an operation's HTTP method mutates state — anything other than a safe read verb. Drives
|
|
165
|
+
* the MCP read/mutate split: read tools are unguarded on loopback, mutating tools are gated. */
|
|
166
|
+
export declare function isMutatingMethod(method: HttpMethodLower): boolean;
|
|
167
|
+
/** One operation's MCP-tool projection facts: its id, HTTP method, whether it mutates, and whether
|
|
168
|
+
* `x-mcp` excludes it from projection. This is the shared unit the runtime MCP surface AND the CI
|
|
169
|
+
* spec↔tool parity guard both read — a single derivation of "which operations become tools", never
|
|
170
|
+
* a second walker (ADR 0053). */
|
|
171
|
+
export interface McpToolProjection {
|
|
172
|
+
operationId: string;
|
|
173
|
+
method: HttpMethodLower;
|
|
174
|
+
mutating: boolean;
|
|
175
|
+
excluded: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Project every operationId-bearing operation to its MCP-tool facts, in the stable
|
|
179
|
+
* `collectOperations` (path, method) order. Excluded operations are RETAINED here (flagged
|
|
180
|
+
* `excluded: true`) rather than dropped, so the parity guard can positively assert that an
|
|
181
|
+
* `x-mcp`-excluded door is present-but-withheld — the runtime drops them when it builds the live
|
|
182
|
+
* tool list. Derived entirely from {@link collectOperations}, so it can never diverge from what
|
|
183
|
+
* `mountApi` routes.
|
|
184
|
+
*/
|
|
185
|
+
export declare function collectMcpToolProjection(doc: OpenApiDoc): McpToolProjection[];
|
|
186
|
+
/**
|
|
187
|
+
* Compare a previously-captured MCP-tool projection (the committed snapshot) against the projection
|
|
188
|
+
* freshly computed from the spec, returning a human-readable line for every skew — an operation the
|
|
189
|
+
* spec now projects that the snapshot lacks, one the snapshot still lists that the spec no longer
|
|
190
|
+
* projects, or one whose method / mutating / excluded facts changed. An empty array means the spec
|
|
191
|
+
* and the projected tool list are in parity. This is the pure core of the `check:mcp` CI drift gate
|
|
192
|
+
* (ADR 0067) — the same "generated derived artifact + fail-on-drift" pattern the repo already uses
|
|
193
|
+
* for `check:runtime` — and is unit-tested by feeding it an injected skew.
|
|
194
|
+
*/
|
|
195
|
+
export declare function diffMcpToolProjection(snapshot: McpToolProjection[], current: McpToolProjection[]): string[];
|
|
196
|
+
/**
|
|
197
|
+
* Every app shared-secret security scheme (ADR 0067/0059): the `apiKey` schemes in
|
|
198
|
+
* `components.securitySchemes` presented in a request HEADER and pointing at an env var via
|
|
199
|
+
* `x-nano-secret-env` (declared, even if empty — an empty pointer is a misconfiguration surfaced as
|
|
200
|
+
* 500 downstream, not "no scheme"), in document (authoring) order. Single source of truth for both the guard
|
|
201
|
+
* selector (`sharedSecretSchemeName`) and its ambiguity check — a mutating MCP tool REUSES the
|
|
202
|
+
* app's existing shared secret (the same one a `webhook` trigger or a guarded operation already
|
|
203
|
+
* uses) instead of minting an MCP-specific synonym.
|
|
204
|
+
*/
|
|
205
|
+
export declare function sharedSecretSchemeNames(doc: OpenApiDoc): string[];
|
|
206
|
+
/**
|
|
207
|
+
* The name of the app's single shared-secret security scheme (ADR 0067/0059) — the credential the
|
|
208
|
+
* framework MUTATING MCP tools require. `undefined` when the app declares no such scheme, in which
|
|
209
|
+
* case the mutating tools stay closed unless an explicit runtime opt-in is set.
|
|
210
|
+
*
|
|
211
|
+
* THROWS when the spec declares MORE THAN ONE candidate: which scheme becomes "the" MCP mutation
|
|
212
|
+
* guard would otherwise depend on `securitySchemes` object iteration (authoring) order, silently
|
|
213
|
+
* guarding with an unintended secret (or rejecting a different, valid shared-secret header). That is
|
|
214
|
+
* an incoherent spec, surfaced loudly — the caller maps it to a 500 misconfiguration — rather than
|
|
215
|
+
* resolved by an invisible "first wins" rule. Derived from `sharedSecretSchemeNames` (no drift).
|
|
216
|
+
*/
|
|
217
|
+
export declare function sharedSecretSchemeName(doc: OpenApiDoc): string | undefined;
|
|
146
218
|
/**
|
|
147
219
|
* Throw if the document declares the same `operationId` on more than one operation. An operationId
|
|
148
220
|
* must be unique across the whole OpenAPI document (it names the delegate module `<dir>/<operationId>`
|
package/dist/openapi/spec.js
CHANGED
|
@@ -172,12 +172,142 @@ export function collectOperations(doc) {
|
|
|
172
172
|
responseSchemas: collectResponseSchemas(responses),
|
|
173
173
|
security,
|
|
174
174
|
eject: opRaw["x-urban-eject"] === true,
|
|
175
|
+
mcpExcluded: isMcpExcluded(opRaw["x-mcp"]),
|
|
175
176
|
summary: typeof opRaw.summary === "string" ? opRaw.summary : undefined,
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
return out;
|
|
180
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Read the `x-mcp` operation extension (ADR 0067 — MCP tool projection). An operation is EXPOSED as
|
|
184
|
+
* an MCP tool by default; it is excluded only when it says so explicitly, so a spec author opts a
|
|
185
|
+
* door OUT rather than every operation having to opt in. Recognised exclusion forms:
|
|
186
|
+
* - `x-mcp: false` — a terse boolean opt-out;
|
|
187
|
+
* - `x-mcp: { exclude: true }` — the object form (room for future keys, e.g. per-tool metadata).
|
|
188
|
+
* Any other value (including `x-mcp: true` / `{ exclude: false }` / absent) leaves the operation
|
|
189
|
+
* exposed — fail-open to the documented default. This is a SECURITY-RELEVANT authoring rule: it is
|
|
190
|
+
* the one switch that keeps an operator-only operation out of the agent-facing tool surface, so it
|
|
191
|
+
* is enforced from the same single walker the runtime and the parity guard both read (no second
|
|
192
|
+
* source of truth to drift, ADR 0053).
|
|
193
|
+
*/
|
|
194
|
+
export function isMcpExcluded(ext) {
|
|
195
|
+
if (ext === false)
|
|
196
|
+
return true;
|
|
197
|
+
return isRecord(ext) && ext.exclude === true;
|
|
198
|
+
}
|
|
199
|
+
/** The HTTP methods MCP treats as read-only (safe, non-mutating). These are exactly the HTTP "safe"
|
|
200
|
+
* verbs (RFC 9110 §9.2.1) that {@link HTTP_METHODS} can express: GET/HEAD, plus OPTIONS (a
|
|
201
|
+
* CORS/preflight metadata probe that never mutates). Every other method an operation can declare is
|
|
202
|
+
* a mutation whose tool is guarded (ADR 0067 Slice 3). */
|
|
203
|
+
const READ_ONLY_METHODS = ["get", "head", "options"];
|
|
204
|
+
/** Whether an operation's HTTP method mutates state — anything other than a safe read verb. Drives
|
|
205
|
+
* the MCP read/mutate split: read tools are unguarded on loopback, mutating tools are gated. */
|
|
206
|
+
export function isMutatingMethod(method) {
|
|
207
|
+
return !READ_ONLY_METHODS.includes(method);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Project every operationId-bearing operation to its MCP-tool facts, in the stable
|
|
211
|
+
* `collectOperations` (path, method) order. Excluded operations are RETAINED here (flagged
|
|
212
|
+
* `excluded: true`) rather than dropped, so the parity guard can positively assert that an
|
|
213
|
+
* `x-mcp`-excluded door is present-but-withheld — the runtime drops them when it builds the live
|
|
214
|
+
* tool list. Derived entirely from {@link collectOperations}, so it can never diverge from what
|
|
215
|
+
* `mountApi` routes.
|
|
216
|
+
*/
|
|
217
|
+
export function collectMcpToolProjection(doc) {
|
|
218
|
+
return collectOperations(doc).map((op) => ({
|
|
219
|
+
operationId: op.operationId,
|
|
220
|
+
method: op.method,
|
|
221
|
+
mutating: isMutatingMethod(op.method),
|
|
222
|
+
excluded: op.mcpExcluded,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Compare a previously-captured MCP-tool projection (the committed snapshot) against the projection
|
|
227
|
+
* freshly computed from the spec, returning a human-readable line for every skew — an operation the
|
|
228
|
+
* spec now projects that the snapshot lacks, one the snapshot still lists that the spec no longer
|
|
229
|
+
* projects, or one whose method / mutating / excluded facts changed. An empty array means the spec
|
|
230
|
+
* and the projected tool list are in parity. This is the pure core of the `check:mcp` CI drift gate
|
|
231
|
+
* (ADR 0067) — the same "generated derived artifact + fail-on-drift" pattern the repo already uses
|
|
232
|
+
* for `check:runtime` — and is unit-tested by feeding it an injected skew.
|
|
233
|
+
*/
|
|
234
|
+
export function diffMcpToolProjection(snapshot, current) {
|
|
235
|
+
const drift = [];
|
|
236
|
+
const byId = (list) => new Map(list.map((p) => [p.operationId, p]));
|
|
237
|
+
const snapshotById = byId(snapshot);
|
|
238
|
+
const currentById = byId(current);
|
|
239
|
+
for (const [id, cur] of currentById) {
|
|
240
|
+
const snap = snapshotById.get(id);
|
|
241
|
+
if (!snap) {
|
|
242
|
+
drift.push(`+ ${id}: spec projects a tool the snapshot is missing (regenerate the snapshot)`);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (snap.method !== cur.method || snap.mutating !== cur.mutating || snap.excluded !== cur.excluded) {
|
|
246
|
+
drift.push(`~ ${id}: projection changed — snapshot {method:${snap.method}, mutating:${snap.mutating}, ` +
|
|
247
|
+
`excluded:${snap.excluded}} vs spec {method:${cur.method}, mutating:${cur.mutating}, ` +
|
|
248
|
+
`excluded:${cur.excluded}}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const id of snapshotById.keys()) {
|
|
252
|
+
if (!currentById.has(id)) {
|
|
253
|
+
drift.push(`- ${id}: snapshot lists a tool the spec no longer projects (regenerate the snapshot)`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return drift;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Every app shared-secret security scheme (ADR 0067/0059): the `apiKey` schemes in
|
|
260
|
+
* `components.securitySchemes` presented in a request HEADER and pointing at an env var via
|
|
261
|
+
* `x-nano-secret-env` (declared, even if empty — an empty pointer is a misconfiguration surfaced as
|
|
262
|
+
* 500 downstream, not "no scheme"), in document (authoring) order. Single source of truth for both the guard
|
|
263
|
+
* selector (`sharedSecretSchemeName`) and its ambiguity check — a mutating MCP tool REUSES the
|
|
264
|
+
* app's existing shared secret (the same one a `webhook` trigger or a guarded operation already
|
|
265
|
+
* uses) instead of minting an MCP-specific synonym.
|
|
266
|
+
*/
|
|
267
|
+
export function sharedSecretSchemeNames(doc) {
|
|
268
|
+
const schemes = doc.components?.securitySchemes ?? {};
|
|
269
|
+
const names = [];
|
|
270
|
+
for (const [name, scheme] of Object.entries(schemes)) {
|
|
271
|
+
// A malformed scheme value (e.g. `webhookKey:` with no body parses as `null` in YAML, or a
|
|
272
|
+
// primitive) is not a valid apiKey shared-secret candidate — skip it rather than dereference it
|
|
273
|
+
// and throw a bare TypeError. This mirrors `evaluateSecurity`, which never treats a non-object
|
|
274
|
+
// scheme as a valid credential (a referenced null/primitive scheme surfaces there as a 500), so
|
|
275
|
+
// there is no silent security hole: mutations fail closed and a genuine misconfig is caught at
|
|
276
|
+
// request time by the enforcement path.
|
|
277
|
+
if (!isRecord(scheme))
|
|
278
|
+
continue;
|
|
279
|
+
// Structural presence check (`typeof … === "string"`), NOT truthiness: a declared-but-EMPTY
|
|
280
|
+
// `x-nano-secret-env` is a misconfiguration, not "no scheme". Selecting it here lets
|
|
281
|
+
// `evaluateSecurity` surface it as a 500 (missing env-var pointer) — the same way it treats an
|
|
282
|
+
// empty pointer — instead of silently dropping the scheme so the guard reports a misleading 401.
|
|
283
|
+
if (scheme.type === "apiKey" &&
|
|
284
|
+
(scheme.in ?? "header") === "header" &&
|
|
285
|
+
typeof scheme["x-nano-secret-env"] === "string") {
|
|
286
|
+
names.push(name);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return names;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The name of the app's single shared-secret security scheme (ADR 0067/0059) — the credential the
|
|
293
|
+
* framework MUTATING MCP tools require. `undefined` when the app declares no such scheme, in which
|
|
294
|
+
* case the mutating tools stay closed unless an explicit runtime opt-in is set.
|
|
295
|
+
*
|
|
296
|
+
* THROWS when the spec declares MORE THAN ONE candidate: which scheme becomes "the" MCP mutation
|
|
297
|
+
* guard would otherwise depend on `securitySchemes` object iteration (authoring) order, silently
|
|
298
|
+
* guarding with an unintended secret (or rejecting a different, valid shared-secret header). That is
|
|
299
|
+
* an incoherent spec, surfaced loudly — the caller maps it to a 500 misconfiguration — rather than
|
|
300
|
+
* resolved by an invisible "first wins" rule. Derived from `sharedSecretSchemeNames` (no drift).
|
|
301
|
+
*/
|
|
302
|
+
export function sharedSecretSchemeName(doc) {
|
|
303
|
+
const names = sharedSecretSchemeNames(doc);
|
|
304
|
+
if (names.length > 1) {
|
|
305
|
+
throw new Error(`OpenAPI spec declares multiple shared-secret schemes (apiKey header with x-nano-secret-env): ` +
|
|
306
|
+
`${names.join(", ")}. Exactly one may serve as the MCP mutation guard — remove the extras so ` +
|
|
307
|
+
"the guard scheme is unambiguous.");
|
|
308
|
+
}
|
|
309
|
+
return names[0];
|
|
310
|
+
}
|
|
181
311
|
/**
|
|
182
312
|
* Throw if the document declares the same `operationId` on more than one operation. An operationId
|
|
183
313
|
* must be unique across the whole OpenAPI document (it names the delegate module `<dir>/<operationId>`
|
|
@@ -260,12 +260,58 @@ export interface ElementInstanceSummary {
|
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
262
|
* The kind of wait an element instance is parked in, as a
|
|
263
|
-
* `/v2/element-instances/wait-states/search` result reports it.
|
|
264
|
-
*
|
|
265
|
-
* (an event awaiting correlation), a `TIMER`, a `SIGNAL`, a `CONDITION`, as well
|
|
266
|
-
*
|
|
263
|
+
* `/v2/element-instances/wait-states/search` result reports it. This is the *canonical*
|
|
264
|
+
* six-type contract (Zeebe's, as of 2026): a `JOB` (a service task awaiting a worker), a
|
|
265
|
+
* `MESSAGE` (an event awaiting correlation), a `TIMER`, a `SIGNAL`, a `CONDITION`, as well
|
|
266
|
+
* as a `USER_TASK`.
|
|
267
|
+
*
|
|
268
|
+
* **Not every deployed engine implements the whole union.** It is forward-looking on
|
|
269
|
+
* purpose (the response mapper and {@link normalizeWaitStateType} tolerate all six so a
|
|
270
|
+
* newer engine's rows map cleanly), but the *currently deployed* nanobpmn gateway's
|
|
271
|
+
* read-model floor is narrower — see {@link DEPLOYED_WAIT_STATE_TYPES}. A
|
|
272
|
+
* {@link ElementInstanceWaitStateFilter} whose `waitStateType` falls outside that floor is
|
|
273
|
+
* rejected (the gateway answers HTTP 422); {@link assertDeployedWaitStateType} enforces the
|
|
274
|
+
* same floor client-side so the divergence surfaces as a clear error offline, in tests, and
|
|
275
|
+
* against a live engine alike. Ref: Magikcraft/nano-bpm#1042.
|
|
267
276
|
*/
|
|
268
277
|
export type WaitStateType = "JOB" | "MESSAGE" | "USER_TASK" | "TIMER" | "SIGNAL" | "CONDITION";
|
|
278
|
+
/**
|
|
279
|
+
* The `waitStateType` values the *currently deployed* nanobpmn gateway's wait-state read
|
|
280
|
+
* model actually implements — the **deployed floor**, a strict subset of the canonical
|
|
281
|
+
* {@link WaitStateType} union. The gateway's read model is a snapshot of the Zeebe contract
|
|
282
|
+
* taken 2026-06-09 (the same day Zeebe extended it with `USER_TASK`, then `TIMER`/`SIGNAL`/
|
|
283
|
+
* `CONDITION`), so it recognizes only `JOB | MESSAGE` and rejects any other filter value
|
|
284
|
+
* with HTTP 422.
|
|
285
|
+
*
|
|
286
|
+
* This constant is the **single source of truth** for that floor: the SDK-backed and
|
|
287
|
+
* WASM-backed {@link EngineClient} adapters both gate through {@link assertDeployedWaitStateType},
|
|
288
|
+
* and the WASM emulation synthesizes only these park kinds — so a test cannot pass against
|
|
289
|
+
* the emulation while a real gateway would 422 (No Drift Surfaces). Widen it (adding a leg
|
|
290
|
+
* backed by the real gateway) only once the engine actually serves the richer type — the
|
|
291
|
+
* tracking gap is Magikcraft/nano-bpm#1042.
|
|
292
|
+
*/
|
|
293
|
+
export declare const DEPLOYED_WAIT_STATE_TYPES: readonly WaitStateType[];
|
|
294
|
+
/**
|
|
295
|
+
* Thrown when a wait-state search is asked to filter on a {@link WaitStateType} the deployed
|
|
296
|
+
* gateway's read model does not implement (outside {@link DEPLOYED_WAIT_STATE_TYPES}). It
|
|
297
|
+
* fails fast client-side with a clear, offline-detectable error rather than letting the call
|
|
298
|
+
* reach the gateway and surface as an opaque HTTP 422 "did not match any variant of untagged
|
|
299
|
+
* enum WaitStateTypeFilterProperty". Ref: Magikcraft/nano-bpm#1042.
|
|
300
|
+
*/
|
|
301
|
+
export declare class UnsupportedWaitStateTypeError extends Error {
|
|
302
|
+
readonly waitStateType: string;
|
|
303
|
+
readonly supported: readonly WaitStateType[];
|
|
304
|
+
constructor(waitStateType: string);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Assert a wait-state filter's `waitStateType` is within the deployed floor
|
|
308
|
+
* ({@link DEPLOYED_WAIT_STATE_TYPES}), throwing {@link UnsupportedWaitStateTypeError}
|
|
309
|
+
* otherwise. An absent selector is always allowed (the search is unfiltered by type). Both
|
|
310
|
+
* {@link EngineClient} adapters call this before issuing a wait-state search, so the floor is
|
|
311
|
+
* enforced identically whether the query runs against a live gateway or the in-process
|
|
312
|
+
* emulation. No-ops for an in-floor type.
|
|
313
|
+
*/
|
|
314
|
+
export declare function assertDeployedWaitStateType(waitStateType?: WaitStateType): void;
|
|
269
315
|
/**
|
|
270
316
|
* A single parked (waiting) element instance as
|
|
271
317
|
* {@link EngineClient.searchElementInstanceWaitStates} reports it. Every variant carries the
|
|
@@ -312,6 +358,10 @@ export interface ElementInstanceFilter {
|
|
|
312
358
|
* Selectors for an element-instance *wait-state* search: which process instance, element,
|
|
313
359
|
* and/or kind of wait to match. Used by {@link EngineClient.searchElementInstanceWaitStates}.
|
|
314
360
|
* There is deliberately no lifecycle-`state` selector — a wait state is always an active park.
|
|
361
|
+
*
|
|
362
|
+
* A `waitStateType` selector must fall within the deployed floor
|
|
363
|
+
* ({@link DEPLOYED_WAIT_STATE_TYPES}); a value outside it is rejected with
|
|
364
|
+
* {@link UnsupportedWaitStateTypeError} (the live gateway answers HTTP 422).
|
|
315
365
|
*/
|
|
316
366
|
export interface ElementInstanceWaitStateFilter {
|
|
317
367
|
processInstanceKey?: string;
|
|
@@ -476,11 +526,19 @@ export interface EngineClient {
|
|
|
476
526
|
searchElementInstances(filter?: ElementInstanceFilter): Promise<ElementInstanceSummary[]>;
|
|
477
527
|
/**
|
|
478
528
|
* Search the *wait states* of element instances
|
|
479
|
-
* (`POST /v2/element-instances/wait-states/search`) —
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
529
|
+
* (`POST /v2/element-instances/wait-states/search`) — the parks the deployed engine's
|
|
530
|
+
* read model serves. A zero-wait read; each result is discriminated by `waitStateType`
|
|
531
|
+
* (see {@link ElementInstanceWaitState}), so a consumer can read the job/message parks a
|
|
532
|
+
* {@link searchUserTasks} cannot surface.
|
|
533
|
+
*
|
|
534
|
+
* **Deployed floor.** The currently deployed nanobpmn gateway implements only
|
|
535
|
+
* `JOB | MESSAGE` ({@link DEPLOYED_WAIT_STATE_TYPES}) — a `USER_TASK` park is read via
|
|
536
|
+
* {@link searchUserTasks}, not here. A `waitStateType` filter outside the floor is rejected
|
|
537
|
+
* with {@link UnsupportedWaitStateTypeError} (the live gateway answers HTTP 422); an
|
|
538
|
+
* unfiltered search returns only in-floor parks. The `waitStateType` union is
|
|
539
|
+
* forward-looking (richer engines may serve more), but this adapter contract pins the
|
|
540
|
+
* floor so a query cannot pass in emulation while a real engine rejects it. Ref:
|
|
541
|
+
* Magikcraft/nano-bpm#1042.
|
|
484
542
|
*/
|
|
485
543
|
searchElementInstanceWaitStates(filter?: ElementInstanceWaitStateFilter): Promise<ElementInstanceWaitState[]>;
|
|
486
544
|
/**
|
|
@@ -42,6 +42,54 @@ export function presentFormIdentifier(value) {
|
|
|
42
42
|
const trimmed = value?.trim();
|
|
43
43
|
return trimmed ? trimmed : undefined;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The `waitStateType` values the *currently deployed* nanobpmn gateway's wait-state read
|
|
47
|
+
* model actually implements — the **deployed floor**, a strict subset of the canonical
|
|
48
|
+
* {@link WaitStateType} union. The gateway's read model is a snapshot of the Zeebe contract
|
|
49
|
+
* taken 2026-06-09 (the same day Zeebe extended it with `USER_TASK`, then `TIMER`/`SIGNAL`/
|
|
50
|
+
* `CONDITION`), so it recognizes only `JOB | MESSAGE` and rejects any other filter value
|
|
51
|
+
* with HTTP 422.
|
|
52
|
+
*
|
|
53
|
+
* This constant is the **single source of truth** for that floor: the SDK-backed and
|
|
54
|
+
* WASM-backed {@link EngineClient} adapters both gate through {@link assertDeployedWaitStateType},
|
|
55
|
+
* and the WASM emulation synthesizes only these park kinds — so a test cannot pass against
|
|
56
|
+
* the emulation while a real gateway would 422 (No Drift Surfaces). Widen it (adding a leg
|
|
57
|
+
* backed by the real gateway) only once the engine actually serves the richer type — the
|
|
58
|
+
* tracking gap is Magikcraft/nano-bpm#1042.
|
|
59
|
+
*/
|
|
60
|
+
export const DEPLOYED_WAIT_STATE_TYPES = ["JOB", "MESSAGE"];
|
|
61
|
+
/**
|
|
62
|
+
* Thrown when a wait-state search is asked to filter on a {@link WaitStateType} the deployed
|
|
63
|
+
* gateway's read model does not implement (outside {@link DEPLOYED_WAIT_STATE_TYPES}). It
|
|
64
|
+
* fails fast client-side with a clear, offline-detectable error rather than letting the call
|
|
65
|
+
* reach the gateway and surface as an opaque HTTP 422 "did not match any variant of untagged
|
|
66
|
+
* enum WaitStateTypeFilterProperty". Ref: Magikcraft/nano-bpm#1042.
|
|
67
|
+
*/
|
|
68
|
+
export class UnsupportedWaitStateTypeError extends Error {
|
|
69
|
+
waitStateType;
|
|
70
|
+
supported;
|
|
71
|
+
constructor(waitStateType) {
|
|
72
|
+
super(`unsupported waitStateType "${waitStateType}": the deployed nanobpmn gateway's ` +
|
|
73
|
+
`wait-state read model implements only ${DEPLOYED_WAIT_STATE_TYPES.join(" | ")} and ` +
|
|
74
|
+
`rejects any other value with HTTP 422. Ref: Magikcraft/nano-bpm#1042.`);
|
|
75
|
+
this.name = "UnsupportedWaitStateTypeError";
|
|
76
|
+
this.waitStateType = waitStateType;
|
|
77
|
+
this.supported = DEPLOYED_WAIT_STATE_TYPES;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Assert a wait-state filter's `waitStateType` is within the deployed floor
|
|
82
|
+
* ({@link DEPLOYED_WAIT_STATE_TYPES}), throwing {@link UnsupportedWaitStateTypeError}
|
|
83
|
+
* otherwise. An absent selector is always allowed (the search is unfiltered by type). Both
|
|
84
|
+
* {@link EngineClient} adapters call this before issuing a wait-state search, so the floor is
|
|
85
|
+
* enforced identically whether the query runs against a live gateway or the in-process
|
|
86
|
+
* emulation. No-ops for an in-floor type.
|
|
87
|
+
*/
|
|
88
|
+
export function assertDeployedWaitStateType(waitStateType) {
|
|
89
|
+
if (waitStateType !== undefined && !DEPLOYED_WAIT_STATE_TYPES.includes(waitStateType)) {
|
|
90
|
+
throw new UnsupportedWaitStateTypeError(waitStateType);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
45
93
|
/**
|
|
46
94
|
* The names of every method on {@link EngineClient} — the single *runtime* source of
|
|
47
95
|
* truth for the interface's surface. It is compile-time-pinned to `keyof EngineClient`
|
|
@@ -25,19 +25,37 @@ interface McpConfig {
|
|
|
25
25
|
readonly enabled: boolean;
|
|
26
26
|
/** Whether non-loopback callers are allowed. Defaults OFF (loopback-only). */
|
|
27
27
|
readonly allowRemote: boolean;
|
|
28
|
+
/** Explicit runtime opt-in that authorizes the framework MUTATING debug tools WITHOUT a
|
|
29
|
+
* shared-secret credential (ADR 0067 Slice 3). Defaults OFF: mutations then require the app's
|
|
30
|
+
* shared secret. An operator sets this to open mutations on a trusted, credential-less setup
|
|
31
|
+
* (e.g. a purely local debugging box). It is honoured LOOPBACK-ONLY: when `allowRemote` is also
|
|
32
|
+
* enabled the credential-free bypass is ignored and remote mutations still require the shared
|
|
33
|
+
* secret, so opening the surface to non-loopback callers can never silently expose unguarded
|
|
34
|
+
* mutating tools. */
|
|
35
|
+
readonly allowMutations: boolean;
|
|
28
36
|
}
|
|
29
37
|
/**
|
|
30
|
-
* Resolve the MCP access policy from the manifest
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
38
|
+
* Resolve the MCP access policy from the manifest
|
|
39
|
+
* (`mcp: { enabled?, allowRemote?, allowMutations? }`, read reflectively until the app schema folds
|
|
40
|
+
* the field in — mirroring how `readApiBinding` reads `api`) and the environment
|
|
41
|
+
* (`URBAN_MCP_ENABLED`, `URBAN_MCP_ALLOW_REMOTE`, `URBAN_MCP_ALLOW_MUTATIONS`). The env flags win so
|
|
42
|
+
* an operator can force the surface off (or open it to a non-loopback bind, or enable mutating
|
|
43
|
+
* tools) without editing the manifest. Enabled defaults ON and access defaults to loopback-only
|
|
44
|
+
* ("defaults ON for loopback"); `allowMutations` defaults OFF (mutating tools stay closed).
|
|
35
45
|
*/
|
|
36
46
|
export declare function readMcpConfig(manifest: unknown, env: (name: string) => string | undefined): McpConfig;
|
|
37
47
|
/** Whether the request targets a loopback host — the best-effort loopback signal available at the
|
|
38
48
|
* host seam (which carries no peer address). A missing Host header is treated as loopback (a direct
|
|
39
49
|
* local client that sent none). */
|
|
40
50
|
export declare function isLoopbackRequest(req: HttpRequest): boolean;
|
|
51
|
+
/** Read a header value from the SDK's per-request `requestInfo.headers` map (lower-cased keys,
|
|
52
|
+
* values `string | string[] | undefined`). A repeated header (`string[]`, as Node's raw adapter
|
|
53
|
+
* surfaces it) is comma-joined to MATCH `Headers.get()` semantics — the same read `mountApi` and
|
|
54
|
+
* the reconstructed `toHttpRequest` use for OpenAPI route enforcement — so the shared-secret guard
|
|
55
|
+
* cannot diverge from route enforcement on a repeated credential header. Returns `undefined` when
|
|
56
|
+
* absent. Used to read the shared-secret credential the client presents on the MCP connection for a
|
|
57
|
+
* mutating tool call. */
|
|
58
|
+
export declare function readHeader(headers: Record<string, string | string[] | undefined>, name: string): string | undefined;
|
|
41
59
|
/** The `required` keys a tool's `inputSchema` declares but the call omitted. Presence is decided
|
|
42
60
|
* solely by {@link isBlankArg} — the single source of truth also used for path args — so a value is
|
|
43
61
|
* "provided" unless it is absent (`undefined`/`null`) or a blank/whitespace-only string. A required
|