@nanobpm/urban 0.94.2 → 0.96.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 (37) hide show
  1. package/dist/runtime/adapters/deno.js +30 -0
  2. package/dist/runtime/adapters/node.js +31 -1
  3. package/dist/runtime/core/host.d.ts +54 -11
  4. package/dist/runtime/core/modules/mcp.js +5 -1
  5. package/dist/runtime/core/modules/pages.d.ts +17 -0
  6. package/dist/runtime/core/modules/pages.js +54 -10
  7. package/dist/runtime/core/process-identity.d.ts +21 -0
  8. package/dist/runtime/core/process-identity.js +56 -0
  9. package/dist/runtime/engine/nanosdk.d.ts +3 -5
  10. package/dist/runtime/engine/nanosdk.js +12 -16
  11. package/dist/runtime/index.d.ts +2 -1
  12. package/dist/runtime/index.js +5 -0
  13. package/package.json +2 -2
  14. package/src/runtime/adapters/deno.ts +32 -1
  15. package/src/runtime/adapters/node.test.ts +153 -0
  16. package/src/runtime/adapters/node.ts +27 -1
  17. package/src/runtime/core/glob.test.ts +6 -0
  18. package/src/runtime/core/host.ts +54 -8
  19. package/src/runtime/core/modules/actions.test.ts +2 -0
  20. package/src/runtime/core/modules/agent.test.ts +1 -0
  21. package/src/runtime/core/modules/api.test.ts +2 -0
  22. package/src/runtime/core/modules/connectors.test.ts +1 -0
  23. package/src/runtime/core/modules/datasource.test.ts +1 -0
  24. package/src/runtime/core/modules/mcp.test.ts +25 -0
  25. package/src/runtime/core/modules/mcp.ts +7 -2
  26. package/src/runtime/core/modules/pages.test.ts +136 -1
  27. package/src/runtime/core/modules/pages.ts +75 -11
  28. package/src/runtime/core/modules/surfaces.test.ts +1 -0
  29. package/src/runtime/core/modules/triggers.test.ts +1 -0
  30. package/src/runtime/core/modules/workers.test.ts +1 -0
  31. package/src/runtime/core/process-identity.test.ts +72 -0
  32. package/src/runtime/core/process-identity.ts +66 -0
  33. package/src/runtime/core/runtime.test.ts +27 -0
  34. package/src/runtime/devserver.test.ts +1 -0
  35. package/src/runtime/engine/nanosdk.test.ts +82 -0
  36. package/src/runtime/engine/nanosdk.ts +18 -16
  37. package/src/runtime/index.ts +11 -0
@@ -32,6 +32,7 @@ import type {
32
32
  JobFilter,
33
33
  JobHandler,
34
34
  JobSummary,
35
+ CreatedProcessInstance,
35
36
  ProcessInstanceSnapshot,
36
37
  ProcessInstanceState,
37
38
  UserTaskState,
@@ -49,6 +50,11 @@ import type {
49
50
  TranscriptTurnRole,
50
51
  } from "@nanobpm/agentic/transcript";
51
52
  import { assertDeployedWaitStateType, isBpmnError } from "../core/host.ts";
53
+ import {
54
+ pickProcessDefinitionIdentity,
55
+ presentEngineKey,
56
+ presentString,
57
+ } from "../core/process-identity.ts";
52
58
  import {
53
59
  buildFormSchema,
54
60
  parseFormSchema,
@@ -153,19 +159,11 @@ export function normalizeIncidentState(raw: unknown): IncidentState {
153
159
  }
154
160
  }
155
161
 
156
- /** A non-empty string form of an engine key/id, or `undefined` when absent/blank (including a
157
- * whitespace-only string). Coerces a numeric key to a string (the engine may serialize a key
158
- * either way) but never `String(...)`-coerces an arbitrary object into a garbage
159
- * `"[object Object]"` id. The blank check trims, matching `getElementInstance`'s blank-key
160
- * guard and the form-key presence helpers, so a `" "` key can never leak into a result. */
161
- function presentEngineKey(value: unknown): string | undefined {
162
- if (typeof value === "number") {
163
- return Number.isFinite(value) ? String(value) : undefined;
164
- }
165
- if (typeof value !== "string") return undefined;
166
- const trimmed = value.trim();
167
- return trimmed === "" ? undefined : trimmed;
168
- }
162
+ // Engine-key / process-definition-identity normalization now lives in the shared, adapter-agnostic
163
+ // `../core/process-identity.ts` (imported above), so this adapter's `createInstance` and
164
+ // `searchProcessInstances` run the *same* mapping — see that module's header for the drift class
165
+ // this removes. The WASM test adapter keeps a mirrored local copy until #585 (that module header's
166
+ // "Ownership today" note), so the shared mapping is not yet a cross-adapter guarantee.
169
167
 
170
168
  /** The non-empty, trimmed string form of a *required* engine key, or throws when the value is
171
169
  * absent/blank (including a whitespace-only string). A mutating seam operation addresses a
@@ -858,7 +856,7 @@ export class SdkEngineClient implements EngineClient {
858
856
  processDefinitionId: string;
859
857
  variables?: Record<string, unknown>;
860
858
  awaitCompletion?: boolean;
861
- }): Promise<{ processInstanceKey: string; variables?: Record<string, unknown> }> {
859
+ }): Promise<CreatedProcessInstance> {
862
860
  // Auto-thread the `_urban.lineage` envelope (issue #254): a handler that spawns an
863
861
  // instance propagates its `rootRequestKey` and stamps `causedByInstanceKey`; a genuine
864
862
  // top-level request mints a fresh root. An explicit caller-supplied envelope wins.
@@ -873,6 +871,7 @@ export class SdkEngineClient implements EngineClient {
873
871
  const variables = isRecord(body.variables) ? body.variables : undefined;
874
872
  return {
875
873
  processInstanceKey: requireProcessInstanceKey(key),
874
+ ...pickProcessDefinitionIdentity(body),
876
875
  variables,
877
876
  };
878
877
  }
@@ -1003,11 +1002,15 @@ export class SdkEngineClient implements EngineClient {
1003
1002
  async searchProcessInstances(filter?: {
1004
1003
  processInstanceKeys?: string[];
1005
1004
  state?: ProcessInstanceState;
1005
+ processDefinitionId?: string;
1006
1006
  parentProcessInstanceKey?: string;
1007
1007
  rootProcessInstanceKey?: string;
1008
1008
  }): Promise<ProcessInstanceSnapshot[]> {
1009
1009
  const f: Record<string, unknown> = {};
1010
1010
  if (filter?.state) f.state = filter.state;
1011
+ // A blank BPMN process-id selector is absent, not an empty filter that matches nothing.
1012
+ const processDefinitionId = presentString(filter?.processDefinitionId);
1013
+ if (processDefinitionId) f.processDefinitionId = processDefinitionId;
1011
1014
  // Normalize each requested key through the shared presence rule (drop blank/whitespace-only
1012
1015
  // entries, trim padded ones like `" 123 "`) so the `$in` filter carries only present keys that
1013
1016
  // match the normalized keys we surface — mirroring `WasmEngineClient` and the selector
@@ -1051,13 +1054,12 @@ export class SdkEngineClient implements EngineClient {
1051
1054
  });
1052
1055
  return [];
1053
1056
  }
1054
- const processDefinitionKey = presentEngineKey(it.processDefinitionKey);
1055
1057
  const parentProcessInstanceKey = presentEngineKey(it.parentProcessInstanceKey);
1056
1058
  const rootProcessInstanceKey = presentEngineKey(it.rootProcessInstanceKey);
1057
1059
  return [{
1058
1060
  processInstanceKey,
1059
1061
  state,
1060
- ...(processDefinitionKey ? { processDefinitionKey } : {}),
1062
+ ...pickProcessDefinitionIdentity(it),
1061
1063
  ...(parentProcessInstanceKey ? { parentProcessInstanceKey } : {}),
1062
1064
  ...(rootProcessInstanceKey ? { rootProcessInstanceKey } : {}),
1063
1065
  }];
@@ -108,6 +108,8 @@ export type {
108
108
  JobFilter,
109
109
  JobHandler,
110
110
  JobSummary,
111
+ CreatedProcessInstance,
112
+ ProcessDefinitionIdentity,
111
113
  ProcessInstanceSnapshot,
112
114
  ProcessInstanceState,
113
115
  SqliteDb,
@@ -140,6 +142,15 @@ export {
140
142
  presentFormIdentifier,
141
143
  resolveFormIdentifier,
142
144
  } from "./core/form-contract.ts";
145
+ // The adapter-agnostic process-definition-identity normalizer (the single mapping both
146
+ // `createInstance` and `searchProcessInstances` use), owned today by the live SDK adapter; the WASM
147
+ // test adapter keeps a mirrored local copy until #585, so cross-adapter drift-freedom is not yet
148
+ // claimed. `ProcessDefinitionIdentity` itself is re-exported from `./core/host.ts`.
149
+ export {
150
+ pickProcessDefinitionIdentity,
151
+ presentEngineKey,
152
+ presentString,
153
+ } from "./core/process-identity.ts";
143
154
  export type { AppApi, Mounted, RuntimeContext } from "./core/context.ts";
144
155
  // Structured logging surface (see core/logger.ts): the shape of `AppApi.log`, plus `createLogger`
145
156
  // so consumers can build a Logger for a custom sink or a no-op test double (`createLogger(() => {})`).