@openrobops/iso21423 0.0.0-stage → 0.1.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.
Files changed (100) hide show
  1. package/README.md +358 -2
  2. package/dist/ccs-CU8XD5sl.d.cts +69 -0
  3. package/dist/ccs-CU8XD5sl.d.ts +69 -0
  4. package/dist/chunk-3JNSIJSX.js +31 -0
  5. package/dist/chunk-3JNSIJSX.js.map +1 -0
  6. package/dist/chunk-5ZIUSUHF.js +55 -0
  7. package/dist/chunk-5ZIUSUHF.js.map +1 -0
  8. package/dist/chunk-DMJ6T3RX.js +445 -0
  9. package/dist/chunk-DMJ6T3RX.js.map +1 -0
  10. package/dist/chunk-GPNR37CI.js +1915 -0
  11. package/dist/chunk-GPNR37CI.js.map +1 -0
  12. package/dist/chunk-JDO725KR.js +210 -0
  13. package/dist/chunk-JDO725KR.js.map +1 -0
  14. package/dist/chunk-JIYCTQXR.js +1 -0
  15. package/dist/chunk-JIYCTQXR.js.map +1 -0
  16. package/dist/chunk-JLUENXGS.js +48 -0
  17. package/dist/chunk-JLUENXGS.js.map +1 -0
  18. package/dist/chunk-JQAMNFAF.js +1 -0
  19. package/dist/chunk-JQAMNFAF.js.map +1 -0
  20. package/dist/chunk-LTPOAVGF.js +44 -0
  21. package/dist/chunk-LTPOAVGF.js.map +1 -0
  22. package/dist/chunk-ODBIFZN3.js +65 -0
  23. package/dist/chunk-ODBIFZN3.js.map +1 -0
  24. package/dist/chunk-OH2DOPKJ.js +107 -0
  25. package/dist/chunk-OH2DOPKJ.js.map +1 -0
  26. package/dist/chunk-QAA44UNO.js +1 -0
  27. package/dist/chunk-QAA44UNO.js.map +1 -0
  28. package/dist/chunk-RD7PYTIT.js +107 -0
  29. package/dist/chunk-RD7PYTIT.js.map +1 -0
  30. package/dist/chunk-UJC46NTA.js +13 -0
  31. package/dist/chunk-UJC46NTA.js.map +1 -0
  32. package/dist/chunk-UW6WTEPT.js +293 -0
  33. package/dist/chunk-UW6WTEPT.js.map +1 -0
  34. package/dist/chunk-W7DIDPTG.js +1 -0
  35. package/dist/chunk-W7DIDPTG.js.map +1 -0
  36. package/dist/core.cjs +2874 -0
  37. package/dist/core.cjs.map +1 -0
  38. package/dist/core.d.cts +996 -0
  39. package/dist/core.d.ts +996 -0
  40. package/dist/core.js +59 -0
  41. package/dist/core.js.map +1 -0
  42. package/dist/gateway.cjs +2937 -0
  43. package/dist/gateway.cjs.map +1 -0
  44. package/dist/gateway.d.cts +165 -0
  45. package/dist/gateway.d.ts +165 -0
  46. package/dist/gateway.js +21 -0
  47. package/dist/gateway.js.map +1 -0
  48. package/dist/geometry.cjs +98 -0
  49. package/dist/geometry.cjs.map +1 -0
  50. package/dist/geometry.d.cts +38 -0
  51. package/dist/geometry.d.ts +38 -0
  52. package/dist/geometry.js +14 -0
  53. package/dist/geometry.js.map +1 -0
  54. package/dist/identity-BGr2FJmC.d.cts +258 -0
  55. package/dist/identity-Bw8Dik5S.d.ts +258 -0
  56. package/dist/index.cjs +3327 -0
  57. package/dist/index.cjs.map +1 -0
  58. package/dist/index.d.cts +118 -0
  59. package/dist/index.d.ts +118 -0
  60. package/dist/index.js +193 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/schema.cjs +375 -0
  63. package/dist/schema.cjs.map +1 -0
  64. package/dist/schema.d.cts +28 -0
  65. package/dist/schema.d.ts +28 -0
  66. package/dist/schema.js +14 -0
  67. package/dist/schema.js.map +1 -0
  68. package/dist/session-RV32MFpV.d.cts +139 -0
  69. package/dist/session-ueiESY7Y.d.ts +139 -0
  70. package/dist/session.cjs +855 -0
  71. package/dist/session.cjs.map +1 -0
  72. package/dist/session.d.cts +94 -0
  73. package/dist/session.d.ts +94 -0
  74. package/dist/session.js +20 -0
  75. package/dist/session.js.map +1 -0
  76. package/dist/testing.cjs +205 -0
  77. package/dist/testing.cjs.map +1 -0
  78. package/dist/testing.d.cts +94 -0
  79. package/dist/testing.d.ts +94 -0
  80. package/dist/testing.js +169 -0
  81. package/dist/testing.js.map +1 -0
  82. package/dist/topics-BiVeZyTW.d.cts +43 -0
  83. package/dist/topics-BiVeZyTW.d.ts +43 -0
  84. package/dist/topics.cjs +134 -0
  85. package/dist/topics.cjs.map +1 -0
  86. package/dist/topics.d.cts +41 -0
  87. package/dist/topics.d.ts +41 -0
  88. package/dist/topics.js +30 -0
  89. package/dist/topics.js.map +1 -0
  90. package/dist/transport-BT4AjTn9.d.cts +61 -0
  91. package/dist/transport-BT4AjTn9.d.ts +61 -0
  92. package/dist/types.cjs +186 -0
  93. package/dist/types.cjs.map +1 -0
  94. package/dist/types.d.cts +83 -0
  95. package/dist/types.d.ts +83 -0
  96. package/dist/types.js +50 -0
  97. package/dist/types.js.map +1 -0
  98. package/dist/validators-Be0ce1b8.d.cts +29 -0
  99. package/dist/validators-Be0ce1b8.d.ts +29 -0
  100. package/package.json +48 -4
@@ -0,0 +1,996 @@
1
+ import { M as MessageKind } from './validators-Be0ce1b8.cjs';
2
+ import { U as Uuid, I as IsoTimestamp } from './ccs-CU8XD5sl.cjs';
3
+ import { x as Request, i as EntityIdentity, F as RequestStatus, R as RequestState, y as RequestDetail, t as OperatingState, b as BatteryStatus, s as Odometry, G as GlobalPath, k as GlobalPlan, w as ReasonCode, c as Capabilities, q as LocationPointStamped, D as DetailState } from './identity-BGr2FJmC.cjs';
4
+ import { I as Iso21423Session, V as ValidationWarningEvent } from './session-RV32MFpV.cjs';
5
+ import { E as EntityRef } from './topics-BiVeZyTW.cjs';
6
+ import { C as ConnectionState, M as MqttTransport } from './transport-BT4AjTn9.cjs';
7
+
8
+ /**
9
+ * Copyright 2026 InOrbit, Inc.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ type ResourceKind = 'identity' | 'status' | 'batteryStatus' | 'odometry' | 'localTrajectory' | 'globalPath' | 'globalPlan' | 'activeRequestsStatus' | 'disconnection' | (string & {});
25
+ /** Resource name → schema message kind; `null` means "no schema, raw text" (ND-04). */
26
+ declare const RESOURCE_MESSAGE_KIND: Record<string, MessageKind | null>;
27
+ /** Looks up a resource's schema message kind; unknown resources are treated as "no schema" rather than throwing. */
28
+ declare function messageKindFor(resource: string): MessageKind | null;
29
+
30
+ /**
31
+ * Copyright 2026 InOrbit, Inc.
32
+ *
33
+ * Licensed under the Apache License, Version 2.0 (the "License");
34
+ * you may not use this file except in compliance with the License.
35
+ * You may obtain a copy of the License at
36
+ *
37
+ * http://www.apache.org/licenses/LICENSE-2.0
38
+ *
39
+ * Unless required by applicable law or agreed to in writing, software
40
+ * distributed under the License is distributed on an "AS IS" BASIS,
41
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
+ * See the License for the specific language governing permissions and
43
+ * limitations under the License.
44
+ */
45
+ /** Lifetime token: `unsubscribe()` or `await using` (D-19). */
46
+ interface Subscription extends AsyncDisposable {
47
+ unsubscribe(): Promise<void>;
48
+ readonly active: boolean;
49
+ readonly topicFilters: readonly string[];
50
+ }
51
+ /** Bundle N session subscriptions (one per compiled MQTT filter) into one token. */
52
+ declare function composeSubscription(topicFilters: string[], parts: Array<{
53
+ unsubscribe(): Promise<void>;
54
+ }>): Subscription;
55
+
56
+ /**
57
+ * Copyright 2026 InOrbit, Inc.
58
+ *
59
+ * Licensed under the Apache License, Version 2.0 (the "License");
60
+ * you may not use this file except in compliance with the License.
61
+ * You may obtain a copy of the License at
62
+ *
63
+ * http://www.apache.org/licenses/LICENSE-2.0
64
+ *
65
+ * Unless required by applicable law or agreed to in writing, software
66
+ * distributed under the License is distributed on an "AS IS" BASIS,
67
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68
+ * See the License for the specific language governing permissions and
69
+ * limitations under the License.
70
+ */
71
+
72
+ /** One filter clause; an omitted field means "any" (compiles to an MQTT `+` wildcard). */
73
+ interface EntitySelector {
74
+ entityType?: string;
75
+ entityUuid?: Uuid;
76
+ }
77
+ /** Structured observer filter compiling to MQTT wildcard subscriptions (P-3, NP-3). */
78
+ declare class EntityFilter {
79
+ readonly selectors: readonly EntitySelector[];
80
+ private constructor();
81
+ static all(): EntityFilter;
82
+ static ofType(entityType: string): EntityFilter;
83
+ static entity(entityUuid: Uuid): EntityFilter;
84
+ /** Accepts uuids or nested filters; duplicate selectors collapse. */
85
+ static anyOf(items: Array<Uuid | EntityFilter>): EntityFilter;
86
+ /** One MQTT topic filter per selector, for subscribing to `resource` across every entity this filter selects. */
87
+ topicFiltersFor(resource: string): string[];
88
+ matches(ref: {
89
+ entityType: string;
90
+ entityUuid: string;
91
+ }): boolean;
92
+ }
93
+ /** Shared base for filters that subscribe to a fixed topic suffix (e.g. `request/+`) across a set of entity selectors. */
94
+ declare class TopicSetFilter {
95
+ protected readonly selectors: readonly EntitySelector[];
96
+ private readonly suffix;
97
+ protected constructor(selectors: readonly EntitySelector[], suffix: string);
98
+ topicFilters(): string[];
99
+ }
100
+ /** Observe requests addressed to entities (`…/request/<uuid>`). */
101
+ declare class RequestFilter extends TopicSetFilter {
102
+ static all(): RequestFilter;
103
+ static toEntity(entityUuid: Uuid): RequestFilter;
104
+ static ofType(entityType: string): RequestFilter;
105
+ }
106
+ /** Observe request status streams (`…/request/<uuid>/status`). */
107
+ declare class RequestStatusFilter extends TopicSetFilter {
108
+ static all(): RequestStatusFilter;
109
+ static ofEntity(entityUuid: Uuid): RequestStatusFilter;
110
+ static ofType(entityType: string): RequestStatusFilter;
111
+ }
112
+ /** Local predicate over requests arriving on an entity's own request topic (ND-11.2). */
113
+ declare class RequestAcceptanceFilter {
114
+ private readonly predicate;
115
+ private constructor();
116
+ static all(): RequestAcceptanceFilter;
117
+ static actions(types: string[]): RequestAcceptanceFilter;
118
+ static fromSource(source: Uuid): RequestAcceptanceFilter;
119
+ matches(req: Request): boolean;
120
+ }
121
+
122
+ /**
123
+ * Copyright 2026 InOrbit, Inc.
124
+ *
125
+ * Licensed under the Apache License, Version 2.0 (the "License");
126
+ * you may not use this file except in compliance with the License.
127
+ * You may obtain a copy of the License at
128
+ *
129
+ * http://www.apache.org/licenses/LICENSE-2.0
130
+ *
131
+ * Unless required by applicable law or agreed to in writing, software
132
+ * distributed under the License is distributed on an "AS IS" BASIS,
133
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134
+ * See the License for the specific language governing permissions and
135
+ * limitations under the License.
136
+ */
137
+
138
+ /** Pluggable persistence for the per-entity sequenceId seed (ND-09). */
139
+ interface SequenceStore {
140
+ load(entityUuid: Uuid): Promise<number | undefined>;
141
+ save(entityUuid: Uuid, value: number): Promise<void>;
142
+ }
143
+ declare function defaultStateDir(): string;
144
+ /** Default store: one JSON map per state directory, written atomically. */
145
+ declare class FileSequenceStore implements SequenceStore {
146
+ #private;
147
+ private readonly dir;
148
+ private readonly file;
149
+ constructor(dir?: string);
150
+ private read;
151
+ load(entityUuid: Uuid): Promise<number | undefined>;
152
+ /** Queued so concurrent saves in one process read-modify-write the file one at a time. */
153
+ save(entityUuid: Uuid, value: number): Promise<void>;
154
+ private writeOne;
155
+ }
156
+ /**
157
+ * Monotonic sequenceId source owned by an EntityHandle (D-15).
158
+ * Reserves BLOCK ids per persisted write, so a crash can waste ids but never reuse them.
159
+ */
160
+ declare class SequenceCounter {
161
+ private readonly entityUuid;
162
+ private readonly store;
163
+ private counter;
164
+ private reservedThrough;
165
+ private constructor();
166
+ static open(entityUuid: Uuid, store?: SequenceStore, onFallback?: (err: unknown) => void): Promise<SequenceCounter>;
167
+ /** Returns the next sequenceId, persisting a fresh reservation block when the current one is exhausted. */
168
+ next(): Promise<number>;
169
+ }
170
+
171
+ /**
172
+ * Copyright 2026 InOrbit, Inc.
173
+ *
174
+ * Licensed under the Apache License, Version 2.0 (the "License");
175
+ * you may not use this file except in compliance with the License.
176
+ * You may obtain a copy of the License at
177
+ *
178
+ * http://www.apache.org/licenses/LICENSE-2.0
179
+ *
180
+ * Unless required by applicable law or agreed to in writing, software
181
+ * distributed under the License is distributed on an "AS IS" BASIS,
182
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ * See the License for the specific language governing permissions and
184
+ * limitations under the License.
185
+ */
186
+
187
+ /** One entity's known-state snapshot in the {@link EntityCache}. */
188
+ interface EntityCatalogEntry {
189
+ entityUuid: Uuid;
190
+ entityType: string;
191
+ identity: EntityIdentity;
192
+ manages: readonly Uuid[];
193
+ managedBy?: Uuid;
194
+ lost: boolean;
195
+ firstSeen: Date;
196
+ lastSeen: Date;
197
+ }
198
+ /** Public read/observe surface over the discovered-entity catalog. */
199
+ interface EntityCatalog {
200
+ entities(): EntityCatalogEntry[];
201
+ get(uuid: Uuid): EntityCatalogEntry | undefined;
202
+ managedBy(uuid: Uuid): EntityCatalogEntry[];
203
+ on(event: 'entity' | 'lost' | 'gone', cb: (e: EntityCatalogEntry) => void): void;
204
+ }
205
+ /**
206
+ * Best-effort local catalog built purely from retained `identity` messages (D-18) —
207
+ * never a broker query. Also backs destination-type resolution and capability checks.
208
+ */
209
+ declare class EntityCache implements EntityCatalog {
210
+ private readonly session;
211
+ private readonly byUuid;
212
+ private readonly listeners;
213
+ private disconnectionSubscribed;
214
+ constructor(session: Iso21423Session);
215
+ /** Subscribed once per client session (decision 3): identities are cheap and always needed. */
216
+ start(): Promise<void>;
217
+ /** Disconnection tracking is only wired when someone actually calls discover(). */
218
+ watchDisconnections(): Promise<void>;
219
+ entities(): EntityCatalogEntry[];
220
+ get(uuid: Uuid): EntityCatalogEntry | undefined;
221
+ managedBy(uuid: Uuid): EntityCatalogEntry[];
222
+ on(event: 'entity' | 'lost' | 'gone', cb: (e: EntityCatalogEntry) => void): void;
223
+ /** Removal path for `on()` — not part of the public `EntityCatalog` interface (D-18 consumers
224
+ * never unsubscribe from discovery), but used internally so per-call listeners don't leak. */
225
+ off(event: 'entity' | 'lost' | 'gone', cb: (e: EntityCatalogEntry) => void): void;
226
+ /** Destination entityType resolution for request topics (decision 2). */
227
+ entityTypeOf(uuid: Uuid): string | undefined;
228
+ /** Known-accepts lookup for NotCapableError (decision 4); undefined = unknown entity. */
229
+ acceptsOf(uuid: Uuid): string[] | undefined;
230
+ private onIdentity;
231
+ private onDisconnection;
232
+ private emit;
233
+ }
234
+
235
+ /**
236
+ * Copyright 2026 InOrbit, Inc.
237
+ *
238
+ * Licensed under the Apache License, Version 2.0 (the "License");
239
+ * you may not use this file except in compliance with the License.
240
+ * You may obtain a copy of the License at
241
+ *
242
+ * http://www.apache.org/licenses/LICENSE-2.0
243
+ *
244
+ * Unless required by applicable law or agreed to in writing, software
245
+ * distributed under the License is distributed on an "AS IS" BASIS,
246
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
247
+ * See the License for the specific language governing permissions and
248
+ * limitations under the License.
249
+ */
250
+
251
+ /**
252
+ * Requester-side lifecycle for one outbound {@link Request}: subscribes to its status topic,
253
+ * resolves `completion()` on a terminal status (or rejects on timeout/broker loss), and owns the
254
+ * sender-side ND-10 duty of clearing the retained request once it's terminal.
255
+ */
256
+ declare class RequestHandle {
257
+ #private;
258
+ private readonly ctx;
259
+ private readonly destRef;
260
+ readonly requestUuid: Uuid;
261
+ readonly sourceUuid: Uuid;
262
+ readonly sequenceId: number;
263
+ readonly destination: Uuid | '';
264
+ private readonly timeoutMs;
265
+ readonly createdAt: Date;
266
+ /** @internal */
267
+ constructor(ctx: EntityContext, destRef: EntityRef, requestUuid: Uuid, sourceUuid: Uuid, sequenceId: number, destination: Uuid | '', timeoutMs: number);
268
+ /** @internal — called by sendRequest once the status subscription is live. */
269
+ armTimeout(sub: {
270
+ unsubscribe(): Promise<void>;
271
+ }): void;
272
+ /** @internal — one inbound requestStatus message. */
273
+ ingest(status: RequestStatus): void;
274
+ /** @internal — connection lost while in flight (nodejs_api.md §12). */
275
+ failFast(): void;
276
+ latestStatus(): RequestStatus | undefined;
277
+ /** @internal — the resolved topic ref (post R3 empty-destination resolution), for sendCancel. */
278
+ internalDestRef(): EntityRef;
279
+ /** Registers a callback for every inbound status update on this request (not just the terminal one); returns a token to stop receiving them. */
280
+ onStatus(handler: (s: RequestStatus) => void): Subscription;
281
+ /** Resolves with the terminal SUCCEEDED status, or rejects with {@link RequestFailed}/{@link RequestTimeout}/{@link BrokerUnavailable} — never both. */
282
+ completion(): Promise<RequestStatus>;
283
+ /** Sends a cancelRequest for this request (or one action within it, via `actionId`); a no-op once the request has already settled. */
284
+ cancel(opts?: {
285
+ actionId?: number;
286
+ }): Promise<void>;
287
+ private settle;
288
+ /** Sender duty: clear the retained request on a terminal status (ND-10). Never throws — if the
289
+ * broker publish fails, Task 8's janitor is the backstop that eventually clears stale
290
+ * retained requests. */
291
+ private clearRetainedRequest;
292
+ }
293
+
294
+ /**
295
+ * Copyright 2026 InOrbit, Inc.
296
+ *
297
+ * Licensed under the Apache License, Version 2.0 (the "License");
298
+ * you may not use this file except in compliance with the License.
299
+ * You may obtain a copy of the License at
300
+ *
301
+ * http://www.apache.org/licenses/LICENSE-2.0
302
+ *
303
+ * Unless required by applicable law or agreed to in writing, software
304
+ * distributed under the License is distributed on an "AS IS" BASIS,
305
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
306
+ * See the License for the specific language governing permissions and
307
+ * limitations under the License.
308
+ */
309
+
310
+ /** What an {@link IncomingRequest} publishes status through; implemented by `RequestServer`. */
311
+ interface StatusSink {
312
+ /** Publishes one requestStatus message (QoS 2, retained) and refreshes activeRequestsStatus. */
313
+ publishStatus(req: IncomingRequest, status: RequestStatus): Promise<void>;
314
+ ownerUuid: Uuid;
315
+ nextStatusSequenceId(): Promise<number>;
316
+ }
317
+ /**
318
+ * Server-side lifecycle for one received {@link Request}: tracks the overall request state and
319
+ * each detail's state via {@link RequestLifecycle}/{@link DetailLifecycle}, and publishes a
320
+ * requestStatus message on every change. A request-level transition cascades onto any
321
+ * still-in-flight details that legally admit it (see `cascadeDetails`), so callers don't have to
322
+ * individually resolve every detail before completing the request.
323
+ */
324
+ declare class IncomingRequest {
325
+ #private;
326
+ readonly request: Request;
327
+ readonly requestUuid: Uuid;
328
+ private readonly sink;
329
+ /** @internal */
330
+ constructor(request: Request, requestUuid: Uuid, sink: StatusSink);
331
+ get source(): Uuid;
332
+ get sequenceId(): number;
333
+ get state(): RequestState;
334
+ get isTerminal(): boolean;
335
+ /** @internal — D-12: RECEIVED is published by the server before the handler sees this. */
336
+ publishReceived(): Promise<void>;
337
+ accept(): Promise<void>;
338
+ /** Transitions straight to ABORTED with the given reason (e.g. for pre-flight rejections that never reach ACCEPTED). */
339
+ reject(reason: StatusReason): Promise<void>;
340
+ updateStatus(update: RequestStatusUpdate): Promise<void>;
341
+ updateDetailStatus(update: RequestDetailStatusUpdate): Promise<void>;
342
+ complete(terminal: RequestTerminalUpdate): Promise<void>;
343
+ /** @internal — used by the executor for the RECOVERY phase: transitions the request to
344
+ * RECOVERY and seeds `recoveryStatuses` from the request's declared `recoveries`, mirroring
345
+ * how the constructor seeds `detailStatuses` from `request.details`. */
346
+ enterRecovery(recoveries: RequestDetail[], reason?: StatusReason): Promise<void>;
347
+ /** @internal — used by the executor to report a recovery detail's progress/outcome. Unlike
348
+ * `updateDetailStatus`, recovery entries are never cascaded by a terminal request transition
349
+ * (RECOVERY has no detail-level equivalent — see cascadeDetails), so the executor must call
350
+ * this for every recovery detail as it finishes, not just the non-last ones. */
351
+ updateRecoveryStatus(update: RequestDetailStatusUpdate): Promise<void>;
352
+ private transitionTo;
353
+ private cascadeDetails;
354
+ /**
355
+ * Builds and publishes the current requestStatus snapshot. A `reason`/`message` passed here
356
+ * (from a request-level transition) is attached to the first detail status entry, not stored
357
+ * at the request level — the wire schema carries reason/message per-detail, not on the request.
358
+ */
359
+ private emit;
360
+ }
361
+
362
+ /**
363
+ * Copyright 2026 InOrbit, Inc.
364
+ *
365
+ * Licensed under the Apache License, Version 2.0 (the "License");
366
+ * you may not use this file except in compliance with the License.
367
+ * You may obtain a copy of the License at
368
+ *
369
+ * http://www.apache.org/licenses/LICENSE-2.0
370
+ *
371
+ * Unless required by applicable law or agreed to in writing, software
372
+ * distributed under the License is distributed on an "AS IS" BASIS,
373
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
374
+ * See the License for the specific language governing permissions and
375
+ * limitations under the License.
376
+ */
377
+
378
+ /** Identifies one in-flight request by its ORIGINAL sender (Uuid) and that sender's own
379
+ * sequenceId — the same (source, sequenceId) pair a cancelRequest names (Table C.4, D-02). Never
380
+ * the serving entity's own uuid: two different senders may coincidentally share a sequenceId, so
381
+ * the sender is what actually disambiguates. */
382
+ interface RequestKey {
383
+ source: Uuid;
384
+ sequenceId: number;
385
+ }
386
+ /** What an {@link ExecutionPolicy} decides to do with a newly-arrived request against the currently-active ones. */
387
+ type AdmissionDecision = {
388
+ action: 'accept';
389
+ } | {
390
+ action: 'reject';
391
+ reason: StatusReason;
392
+ } | {
393
+ action: 'buffer';
394
+ } | {
395
+ action: 'preempt';
396
+ preempt: readonly RequestKey[];
397
+ };
398
+ /** Runtime admission strategy (D-17). Named C.2.2 strategies ship as presets below. */
399
+ interface ExecutionPolicy {
400
+ admit(pending: Request, active: readonly RequestStatus[]): AdmissionDecision;
401
+ /** Optional hint: how many buffered requests to hold before displacing the oldest. */
402
+ readonly bufferLimit?: number;
403
+ /** Optional hint: if true, drain buffered requests by priority; else FIFO. */
404
+ readonly drainByPriority?: boolean;
405
+ }
406
+ /** Table C.1: 0 = highest … 255 = lowest; an omitted priority is mid-scale. */
407
+ declare const DEFAULT_PRIORITY = 100;
408
+ /** Named C.2.2 execution policy presets. */
409
+ declare const policies: {
410
+ /** Only one active request at a time; any new request while one is active is rejected outright (no buffering). */
411
+ abortNew(): ExecutionPolicy;
412
+ /** One active + one queued slot; the server aborts the displaced queue entry with REJECTED. */
413
+ queueReplace(): ExecutionPolicy;
414
+ /** One active request; unlimited FIFO queueing behind it. */
415
+ queueAfter(): ExecutionPolicy;
416
+ /** Up to `max` concurrently active requests (unbounded by default); beyond that, buffer FIFO. */
417
+ parallel(max?: number): ExecutionPolicy;
418
+ /** A pending request with strictly lower `priority` (Table C.1: lower number = higher priority) than every active request preempts all of them; otherwise it buffers, and the buffer drains by priority. */
419
+ priority(): ExecutionPolicy;
420
+ };
421
+ /** Parallel-capable default (D-17); overridable per client (P-2) and per handle. */
422
+ declare const DEFAULT_EXECUTION_POLICY: ExecutionPolicy;
423
+
424
+ /**
425
+ * Copyright 2026 InOrbit, Inc.
426
+ *
427
+ * Licensed under the Apache License, Version 2.0 (the "License");
428
+ * you may not use this file except in compliance with the License.
429
+ * You may obtain a copy of the License at
430
+ *
431
+ * http://www.apache.org/licenses/LICENSE-2.0
432
+ *
433
+ * Unless required by applicable law or agreed to in writing, software
434
+ * distributed under the License is distributed on an "AS IS" BASIS,
435
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
436
+ * See the License for the specific language governing permissions and
437
+ * limitations under the License.
438
+ */
439
+
440
+ /**
441
+ * The per-action executor (ND-11.1): runs `EntityHandle.onRequest` handlers against admitted
442
+ * requests, driving detail sequencing, atomic protection, cancelRequest resolution and recovery.
443
+ * See task-7-brief.md for the exact behavior list.
444
+ */
445
+ declare class ActionExecutor {
446
+ private readonly handlers;
447
+ private readonly runs;
448
+ /** Registers a handler for `type`; throws if one is already registered unless `override: true`. */
449
+ register(type: string, handler: ActionHandler, opts?: {
450
+ override?: true;
451
+ }): void;
452
+ hasHandlers(): boolean;
453
+ private runKey;
454
+ /** Fires the AbortController for an admitted request the policy is preempting (Task 7 seam). */
455
+ cancel(key: RequestKey): boolean;
456
+ /** Entry point called once a request is admitted (RequestServer step 6 fallback). The run stays
457
+ * registered in `this.runs` (so a cancelRequest can still find it) until the request is fully
458
+ * terminal — including through the RECOVERY phase (controller ruling: RECOVERY→CANCELED is
459
+ * legal, so a cancel arriving mid-recovery must still resolve). */
460
+ run(incoming: IncomingRequest, entity: EntityHandle): Promise<void>;
461
+ /** Runs one detail array (main details or recoveries) under the shared sequencing rules
462
+ * (item 3), atomic protection (item 4) and outcome mapping (item 5).
463
+ * - `allowSkipLastSuccess` lets the caller rely on the request-level terminal cascade for the
464
+ * very last detail of a clean success run (main details only).
465
+ * - `markRemainingCanceled`: recoveryStatuses is never cascaded by the request's terminal
466
+ * transition (unlike detailStatuses), so when the sequence stops early the caller must ask
467
+ * us to explicitly mark every not-yet-started item CANCELED (main details rely on the
468
+ * cascade instead and pass false here). */
469
+ private runSequence;
470
+ /**
471
+ * Runs a single detail's handler: publishes an EXECUTING status first, then invokes the
472
+ * registered handler (or produces an ACTION_NOT_IMPLEMENTED result if none exists), catching any
473
+ * thrown error as a GENERAL_FAILURE abort. Waits for any `ctx.progress()` updates issued during
474
+ * the handler call to finish publishing before returning.
475
+ */
476
+ private runOneDetail;
477
+ /** Item 1: pre-flight rejection, first match wins across the four rule categories, each
478
+ * scanned over every detail in order. */
479
+ private preflightReject;
480
+ }
481
+ /**
482
+ * ND-11.1 / ND-12: cancelRequest is resolved by searching for the named (source, requestId) run
483
+ * across a list of executors — never dispatched to an app handler. A plain client passes just its
484
+ * own executor; the IMRFM's RequestServer additionally passes every managed handle's executor,
485
+ * because a request it dispatched (ND-12) actually runs there, not in its own `runs` map.
486
+ */
487
+ declare function resolveCancelRequest(cancelReq: IncomingRequest, executors: Iterable<ActionExecutor>): Promise<void>;
488
+
489
+ /**
490
+ * Copyright 2026 InOrbit, Inc.
491
+ *
492
+ * Licensed under the Apache License, Version 2.0 (the "License");
493
+ * you may not use this file except in compliance with the License.
494
+ * You may obtain a copy of the License at
495
+ *
496
+ * http://www.apache.org/licenses/LICENSE-2.0
497
+ *
498
+ * Unless required by applicable law or agreed to in writing, software
499
+ * distributed under the License is distributed on an "AS IS" BASIS,
500
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
501
+ * See the License for the specific language governing permissions and
502
+ * limitations under the License.
503
+ */
504
+
505
+ /** @internal — FleetGateway dispatch seam (ND-12): resolves an empty-destination request to a
506
+ * managed handle's executor, or null to reject it. */
507
+ interface DispatchTarget {
508
+ executor: ActionExecutor;
509
+ entity: EntityHandle;
510
+ }
511
+ type DispatchInterceptor = (request: Request) => DispatchTarget | null;
512
+ /**
513
+ * One `RequestServer` per `EntityHandle`, created lazily on the first `acceptRequests` call.
514
+ * Owns the `request/+` subscription, D-12/D-13 handling, duplicate suppression and the
515
+ * `activeRequestsStatus` aggregation. See task-5-brief.md Step 4 for the 8-point behavior spec.
516
+ */
517
+ declare class RequestServer {
518
+ private readonly ctx;
519
+ private sessionSub?;
520
+ private registrations;
521
+ private readonly seen;
522
+ private readonly activeStatuses;
523
+ private readonly pendingRequests;
524
+ private readonly sink;
525
+ private executor?;
526
+ private dispatchInterceptor?;
527
+ private requestSettledHook?;
528
+ private managedExecutorsHook?;
529
+ constructor(ctx: EntityContext);
530
+ /** Idempotent: a second acceptRequests() on the same handle reuses the live subscription. */
531
+ ensureStarted(): Promise<void>;
532
+ /** @internal — EntityHandle.onRequest wires the executor in here once, the first time it's used. */
533
+ setExecutor(executor: ActionExecutor, entity: EntityHandle): void;
534
+ /** @internal — EntityHandle.setDispatchInterceptor (ND-12, IMRFM handle only). */
535
+ setDispatchInterceptor(cb: DispatchInterceptor): void;
536
+ /** @internal — EntityHandle.setManagedExecutorsHook (ND-12 cancel resolution, IMRFM handle
537
+ * only). */
538
+ setManagedExecutorsHook(cb: () => Iterable<ActionExecutor>): void;
539
+ /** @internal — EntityHandle.onRequestSettled (ND-10 janitor feed). */
540
+ setRequestSettledHook(cb: (requestTopic: string) => void): void;
541
+ /** Adds a low-level request handler for `filter`; returns a deregistration function (not itself async — callers unsubscribe/teardown separately once `handlerCount` hits 0). */
542
+ register(filter: RequestAcceptanceFilter, handler: (req: IncomingRequest) => void): () => void;
543
+ get handlerCount(): number;
544
+ /** ND-18: count of admitted (handed to a handler), still-non-terminal requests — what
545
+ * ClientHealth.activeRequests.serving sums across every handle. */
546
+ get servingCount(): number;
547
+ teardown(): Promise<void>;
548
+ /**
549
+ * Top-level inbound message handler for this entity's `request/+` subscription: parses and
550
+ * schema-validates the payload (rejecting/warning on failure), drops retained clears and
551
+ * already-seen duplicates, publishes RECEIVED, then routes the request — dispatch interception
552
+ * (ND-12) first, then cancelRequest resolution, then normal admission-policy handling.
553
+ */
554
+ private handleInbound;
555
+ /** Controller ruling R2: build a minimal one-detail IncomingRequest and reject it with
556
+ * MALFORMED_REQUEST when (source, sequenceId) can still be read; otherwise surface the usual
557
+ * 'validation-warning' event and drop, same as any other schema-routed subscription would. */
558
+ private rejectOrWarn;
559
+ private inferDetailType;
560
+ /** The StatusSink: publish the requestStatus, then republish activeRequestsStatus (point 7). */
561
+ private publishStatus;
562
+ /** The admission view (R7: augmented with priority): only requests a policy decision has
563
+ * already admitted. Buffered requests — and the pending request itself, which is entered as
564
+ * admitted:false by its own RECEIVED — never appear here. */
565
+ private buildActiveStatuses;
566
+ /** Apply an admission decision: accept, reject, buffer, or preempt. */
567
+ private applyAdmissionDecision;
568
+ /** Handle an accepted request: mark as admitted, route to matching handlers. */
569
+ private handleAcceptedRequest;
570
+ /** Every executor a cancelRequest should be resolved against: this server's own first (if any),
571
+ * then every managed handle's (ND-12, IMRFM only). */
572
+ private cancelExecutors;
573
+ /** Enforce bufferLimit: if the buffer exceeds the limit, displace the oldest request with REJECTED. */
574
+ private enforceBufferLimit;
575
+ /** Re-admit buffered requests after a terminal transition, one at a time: each admitted request
576
+ * is marked admitted before the next decision is taken, so the drain stops as soon as the
577
+ * policy buffers again. Removal from the queue happens before any await, so two overlapping
578
+ * drains can never hand the same request to a handler twice. */
579
+ private reAdmitPending;
580
+ /** Next buffered request to drain: lowest numeric priority first when the policy asks for a
581
+ * priority drain (arrival order breaking ties), plain FIFO otherwise. */
582
+ private selectNextPending;
583
+ }
584
+
585
+ /**
586
+ * Copyright 2026 InOrbit, Inc.
587
+ *
588
+ * Licensed under the Apache License, Version 2.0 (the "License");
589
+ * you may not use this file except in compliance with the License.
590
+ * You may obtain a copy of the License at
591
+ *
592
+ * http://www.apache.org/licenses/LICENSE-2.0
593
+ *
594
+ * Unless required by applicable law or agreed to in writing, software
595
+ * distributed under the License is distributed on an "AS IS" BASIS,
596
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
597
+ * See the License for the specific language governing permissions and
598
+ * limitations under the License.
599
+ */
600
+
601
+ /**
602
+ * Internal seam shared by the publication, requester and executor mixins (Tasks 4–7): the shared
603
+ * dependencies (`session`, `sequence`, `catalog`) plus callbacks up into the owning `Iso21423Client`.
604
+ */
605
+ interface EntityContext {
606
+ session: Iso21423Session;
607
+ ref: EntityRef;
608
+ sequence: SequenceCounter;
609
+ catalog: EntityCache;
610
+ diagnostic(code: DiagnosticCode, detail?: unknown): void;
611
+ countPublish(): void;
612
+ requestTimeoutMs: number;
613
+ /** Cancel = a new request naming (source, requestId) — D-02, Table C.4. */
614
+ sendCancel(handle: RequestHandle, actionId?: number): Promise<void>;
615
+ /** Registers a sent request so close()/an offline connection can failFast() it and
616
+ * health().activeRequests.sent stays accurate; the client drops it once it settles. */
617
+ trackInFlight(handle: RequestHandle): void;
618
+ /** Get the client's default execution policy. */
619
+ getDefaultExecutionPolicy(): ExecutionPolicy;
620
+ /** Get the resolved execution policy for this entity (per-handle > registration > client default > DEFAULT_EXECUTION_POLICY). */
621
+ getExecutionPolicy(): ExecutionPolicy;
622
+ }
623
+ /**
624
+ * Per-entity facade over a {@link Iso21423Session}: publishes identity/status/telemetry resources,
625
+ * sends outbound requests (as a requester) and, once `onRequest`/`acceptRequests` is called,
626
+ * serves inbound ones (as a `RequestServer` + `ActionExecutor` pair). One handle per entity uuid,
627
+ * whether it's the client's own entity (`ownershipMode: 'self'`) or one it manages on behalf of
628
+ * a fleet manager (`'managed'`).
629
+ */
630
+ declare class EntityHandle {
631
+ #private;
632
+ readonly ctx: EntityContext;
633
+ readonly ownershipMode: 'self' | 'managed';
634
+ /** @internal — constructed by Iso21423Client.registerSelfEntity/registerManagedEntity. */
635
+ constructor(ctx: EntityContext, ownershipMode: 'self' | 'managed', registration: EntityRegistration);
636
+ get entityUuid(): Uuid;
637
+ get entityType(): string;
638
+ /** Last states this handle published — feeds the automatic INVALID_IMR_STATE_FOR_ACTION rule. */
639
+ lastStates(): readonly OperatingState[];
640
+ identity(): EntityIdentity;
641
+ publishIdentity(identity: EntityIdentity): Promise<void>;
642
+ /** Shallow-merges `partial` onto the current identity (top-level fields only — e.g. a partial `capabilities` replaces the whole object) and republishes it with a fresh timestamp. */
643
+ updateIdentity(partial: Partial<EntityIdentity>): Promise<void>;
644
+ /** Set a per-handle execution policy override (P-2). */
645
+ setExecutionPolicy(policy: ExecutionPolicy): void;
646
+ /** Get the resolved execution policy (per-handle > registration > client default > DEFAULT_EXECUTION_POLICY). */
647
+ getExecutionPolicy(): ExecutionPolicy;
648
+ publishStatus(update: StatusUpdate): Promise<void>;
649
+ publishBatteryStatus(update: WithOptionalTimestamp<BatteryStatus>): Promise<void>;
650
+ publishOdometry(sample: WithOptionalTimestamp<Odometry>): Promise<void>;
651
+ publishLocalTrajectory(sample: LocalTrajectoryUpdate): Promise<void>;
652
+ publishGlobalPath(snapshot: WithOptionalTimestamp<GlobalPath>): Promise<void>;
653
+ publishGlobalPlan(snapshot: WithOptionalTimestamp<GlobalPlan>): Promise<void>;
654
+ /**
655
+ * Publishes a deployment-defined resource previously declared with `registerExtensionResource`
656
+ * (throws for an undeclared name). No schema applies: `payload` is JSON-serialized as given, so
657
+ * include your own `timestamp` if the resource needs one.
658
+ */
659
+ publishExtension(resource: string, payload: unknown): Promise<void>;
660
+ /**
661
+ * Sends a request to `cmd.destination` (or resolves an empty destination via
662
+ * {@link resolveDestRef}, R3). Unless `requireCapability: false`, checks the destination's
663
+ * known `accepts` capability list first and throws {@link NotCapableError} for any detail type
664
+ * it doesn't advertise — skipped entirely for an unknown (not-yet-discovered) destination.
665
+ * Subscribes to the status topic before publishing the request, so no status can be missed.
666
+ */
667
+ sendRequest(cmd: RequestCommand): Promise<RequestHandle>;
668
+ /** Registers a low-level request handler (Task 5); Tasks 6/7 add admission and the executor
669
+ * hand-off on top of the same `RequestServer`. */
670
+ acceptRequests(filter: RequestAcceptanceFilter, handler: (req: IncomingRequest) => void): Promise<Subscription>;
671
+ /**
672
+ * Registers a per-action handler (Task 7, ND-11.1): the `ActionExecutor` becomes the fallback
673
+ * consumer on this handle's `RequestServer` — low-level `acceptRequests` filters still win when
674
+ * they match, otherwise any request whose details this executor recognizes is driven through
675
+ * the executor's sequencing/atomic/recovery/cancelRequest logic. Registering a second handler
676
+ * for the same `type` without `override: true` throws.
677
+ */
678
+ onRequest<P = Record<string, unknown>>(type: string, handler: ActionHandler<P>, opts?: {
679
+ override?: true;
680
+ }): void;
681
+ /**
682
+ * @internal — FleetGateway janitor seam (ND-10): `cb` fires with this handle's request topic
683
+ * whenever its `RequestServer` publishes a terminal status, or drops a duplicate/unroutable
684
+ * retained request. Force-creates and starts the `RequestServer` so the hook is live even
685
+ * before any `onRequest`/`acceptRequests` call.
686
+ */
687
+ onRequestSettled(cb: (requestTopic: string) => void): Promise<void>;
688
+ /**
689
+ * @internal — FleetGateway dispatch seam (ND-12): wires the empty-destination interceptor onto
690
+ * this handle's `RequestServer` (the IMRFM handle, wired once at `FleetGateway.connect()`).
691
+ */
692
+ setDispatchInterceptor(cb: DispatchInterceptor): Promise<void>;
693
+ /**
694
+ * @internal — FleetGateway cancel-resolution seam (ND-12): wires the managed-handles executor
695
+ * lookup onto this handle's `RequestServer` (the IMRFM handle, wired once at
696
+ * `FleetGateway.connect()`) so a cancelRequest for a dispatched request can find the run in the
697
+ * robot's executor instead of the IMRFM's own.
698
+ */
699
+ setManagedExecutorsHook(cb: () => Iterable<ActionExecutor>): Promise<void>;
700
+ /** @internal — ND-12 retarget seam: this handle's executor, if an `onRequest` handler is
701
+ * registered on it; used to hand a dispatched request off to a managed handle. A valid,
702
+ * registered robot with no `onRequest` handler yields `undefined` here too — the dispatch
703
+ * callback rejects it the same as an unknown uuid (there is nothing to run the request). */
704
+ dispatchTarget(): DispatchTarget | undefined;
705
+ /** ND-18: requests this handle's RequestServer is currently serving (0 if it never started). */
706
+ servingCount(): number;
707
+ private ensureRequestServer;
708
+ /**
709
+ * Controller ruling R3: an empty `destination` (spec §3.1 "IMRFM picks the robot") is not a
710
+ * literal topic segment — resolve the actual target from the identity catalog by
711
+ * `destinationType` (default `'IMRFM'`). Exactly one match is required; the wire `Request`
712
+ * still carries `destination: ''` (only the topic ref is resolved).
713
+ */
714
+ private resolveDestRef;
715
+ /** Final OFFLINE status stays as the tombstone; every other retained topic is cleared. */
716
+ unregister(): Promise<void>;
717
+ private publish;
718
+ }
719
+
720
+ /** nodejs_api.md calls the wire enum StatusReason; Plan 1 named it ReasonCode (decision 9). */
721
+ type StatusReason = ReasonCode;
722
+ type WithOptionalTimestamp<T> = Omit<T, 'timestamp'> & {
723
+ timestamp?: Date | IsoTimestamp;
724
+ };
725
+ /** Accept Date or string at API boundaries; always emit dot-decimal ISO 8601 (ND-07). */
726
+ declare function toTimestamp(t?: Date | IsoTimestamp): IsoTimestamp;
727
+
728
+ /** Options for registering an entity's identity via `Iso21423Client.registerSelfEntity`/`registerManagedEntity`. */
729
+ interface EntityRegistration {
730
+ entityUuid: Uuid;
731
+ entityType: string;
732
+ manufacturerName: string;
733
+ iso21423Version?: string;
734
+ details?: Record<string, unknown>;
735
+ /** `accepts` are action type names; the SDK wraps them into `{ requests: [...] }` (schema shape). */
736
+ capabilities?: {
737
+ provides?: string[];
738
+ accepts?: string[];
739
+ };
740
+ executionPolicy?: ExecutionPolicy;
741
+ }
742
+ type ManagedEntityRegistration = EntityRegistration;
743
+ /** Input to publish a new {@link EntityStatus} snapshot. */
744
+ interface StatusUpdate {
745
+ states: OperatingState[];
746
+ disabledCapabilities?: Capabilities;
747
+ timestamp?: Date | IsoTimestamp;
748
+ }
749
+ /** Wire field is `localTrajectory` (schema); the API takes `points` (example_imr.md §2). */
750
+ interface LocalTrajectoryUpdate {
751
+ points: LocationPointStamped[];
752
+ timestamp?: Date | IsoTimestamp;
753
+ }
754
+ /** Payload delivered to a resource observer callback: the validated/parsed message plus its origin. */
755
+ interface ResourceEvent<T = unknown> {
756
+ entityType: string;
757
+ entityUuid: Uuid;
758
+ kind: ResourceKind;
759
+ topic: string;
760
+ message: T;
761
+ }
762
+ /** Payload delivered to a request observer callback. */
763
+ interface RequestEvent {
764
+ entityType: string;
765
+ entityUuid: Uuid;
766
+ requestUuid: Uuid;
767
+ request: Request;
768
+ topic: string;
769
+ }
770
+ interface SecurityOptions {
771
+ username?: string;
772
+ password?: string;
773
+ /** Passed through to the transport (TLS/mTLS material) — ND-15. */
774
+ tls?: Record<string, unknown>;
775
+ /** Identity-echo publish self-check: default off for clients, on for FleetGateway. */
776
+ selfCheck?: boolean;
777
+ selfCheckTimeoutMs?: number;
778
+ }
779
+ /** Internal, non-fatal conditions the client surfaces via a diagnostics event rather than throwing or logging directly. */
780
+ type DiagnosticCode = 'sequence-store-unavailable' | 'legacy-cancel-normalized' | 'inbound-illegal-transition' | 'self-check-failed' | 'janitor-cleared' | 'duplicate-request-ignored' | 'dispatch-rejected' | 'will-not-armed';
781
+ interface DiagnosticEvent {
782
+ code: DiagnosticCode;
783
+ detail?: unknown;
784
+ at: Date;
785
+ }
786
+ /** Point-in-time snapshot of client connection/entity/subscription/traffic state. */
787
+ interface ClientHealth {
788
+ connection: ConnectionState;
789
+ since: Date;
790
+ lastConnectionChange: Date;
791
+ entities: {
792
+ self: Uuid[];
793
+ managed: Uuid[];
794
+ };
795
+ subscriptions: number;
796
+ activeRequests: {
797
+ sent: number;
798
+ serving: number;
799
+ };
800
+ counters: {
801
+ published: number;
802
+ received: number;
803
+ validationWarnings: number;
804
+ rejections: number;
805
+ };
806
+ }
807
+ /** Requester-side command (Task 4). */
808
+ interface RequestCommand {
809
+ destination: Uuid | '';
810
+ /** Destination namespace type; resolved from the identity catalog, else 'IMR' (decision 2). */
811
+ destinationType?: string;
812
+ details: RequestDetail[];
813
+ recoveries?: RequestDetail[];
814
+ priority?: number;
815
+ atomic?: boolean;
816
+ requestUuid?: Uuid;
817
+ /** Local-only RECEIVED deadline (D-14); default from ClientOptions.requestTimeoutMs. */
818
+ timeoutMs?: number;
819
+ /** Set false to skip the discovered-capability check (decision 4). */
820
+ requireCapability?: boolean;
821
+ }
822
+ /** Executor-side updates (Tasks 5–7). */
823
+ /** Publishes a new overall status for the whole request. */
824
+ interface RequestStatusUpdate {
825
+ status: RequestState;
826
+ reason?: StatusReason;
827
+ message?: string;
828
+ }
829
+ /** Publishes a new status for one detail by its index in the request's `details` array. */
830
+ interface RequestDetailStatusUpdate {
831
+ index: number;
832
+ status: DetailState;
833
+ reason?: StatusReason;
834
+ message?: string;
835
+ properties?: Record<string, unknown>;
836
+ }
837
+ /** Marks the request finished; `status` is restricted to the actual terminal states (no `RECOVERY`, which is not itself terminal). */
838
+ interface RequestTerminalUpdate {
839
+ status: Extract<RequestState, 'SUCCEEDED' | 'ABORTED' | 'CANCELED'>;
840
+ reason?: StatusReason;
841
+ message?: string;
842
+ }
843
+ /** A {@link RequestDetail} with its `properties` narrowed to the action's own payload shape `P`. */
844
+ type TypedRequestDetail<P = Record<string, unknown>> = Omit<RequestDetail, 'properties'> & {
845
+ properties: P;
846
+ };
847
+ /** Terminal outcome an {@link ActionHandler} returns (via `ctx.succeeded`/`ctx.aborted`) for one action. */
848
+ type ActionResult = {
849
+ outcome: 'succeeded';
850
+ properties?: Record<string, unknown>;
851
+ } | {
852
+ outcome: 'aborted';
853
+ reason: StatusReason;
854
+ message?: string;
855
+ };
856
+ /** Handed to an {@link ActionHandler}: the executing entity, the request being served, a cancellation signal, and helpers to report progress/finish the action. */
857
+ interface ActionContext {
858
+ readonly entity: EntityHandle;
859
+ readonly request: Request;
860
+ readonly signal: AbortSignal;
861
+ /** Publishes an EXECUTING detail-status update carrying arbitrary vendor properties, without changing lifecycle state. */
862
+ progress(properties: Record<string, unknown>): void;
863
+ succeeded(properties?: Record<string, unknown>): ActionResult;
864
+ aborted(reason: StatusReason, message?: string): ActionResult;
865
+ }
866
+ /** User-supplied implementation of one action type, registered via `EntityHandle.onRequest`. */
867
+ type ActionHandler<P = Record<string, unknown>> = (action: TypedRequestDetail<P>, ctx: ActionContext) => Promise<ActionResult>;
868
+
869
+ /**
870
+ * Copyright 2026 InOrbit, Inc.
871
+ *
872
+ * Licensed under the Apache License, Version 2.0 (the "License");
873
+ * you may not use this file except in compliance with the License.
874
+ * You may obtain a copy of the License at
875
+ *
876
+ * http://www.apache.org/licenses/LICENSE-2.0
877
+ *
878
+ * Unless required by applicable law or agreed to in writing, software
879
+ * distributed under the License is distributed on an "AS IS" BASIS,
880
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
881
+ * See the License for the specific language governing permissions and
882
+ * limitations under the License.
883
+ */
884
+
885
+ /** Options for {@link Iso21423Client.connect}. */
886
+ interface ClientOptions {
887
+ transport?: MqttTransport;
888
+ url?: string;
889
+ security?: SecurityOptions;
890
+ validateOutbound?: boolean;
891
+ sourceId?: Uuid;
892
+ sequenceStore?: SequenceStore | null;
893
+ requestTimeoutMs?: number;
894
+ }
895
+ type ClientEvents = {
896
+ connection: (s: ConnectionState) => void;
897
+ 'validation-warning': (w: ValidationWarningEvent) => void;
898
+ diagnostic: (e: DiagnosticEvent) => void;
899
+ };
900
+ /**
901
+ * Entry point for the ISO 21423 SDK (nodejs_api.md §6). Owns exactly one MQTT session,
902
+ * opened lazily (decision 1) so a client can be constructed without picking an identity
903
+ * up front — `registerSelfEntity` is what arms the B.4 Last Will.
904
+ */
905
+ declare class Iso21423Client {
906
+ private readonly transport;
907
+ private readonly security?;
908
+ private readonly validateOutbound?;
909
+ private readonly sourceId?;
910
+ private readonly sequenceStore;
911
+ private readonly requestTimeoutMs;
912
+ private sessionPromise?;
913
+ private session?;
914
+ private cache?;
915
+ private pendingCatalogListeners;
916
+ private defaultExecutionPolicy?;
917
+ private readonly selfEntities;
918
+ private readonly managedEntities;
919
+ private readonly trackedSubs;
920
+ private readonly inFlightRequests;
921
+ private since?;
922
+ private lastConnectionChange?;
923
+ private subscriptionCount;
924
+ private closed;
925
+ private readonly counters;
926
+ private readonly listeners;
927
+ private constructor();
928
+ static connect(opts: ClientOptions): Promise<Iso21423Client>;
929
+ /**
930
+ * Registers this process's own entity: opens the session (arming the B.4 Last Will) if it
931
+ * isn't open yet, and publishes the resulting identity. Must be the first operation on the
932
+ * client (P-4) — if a session is already open under a different entity, throws rather than
933
+ * silently registering under the wrong identity/will.
934
+ */
935
+ registerSelfEntity(reg: EntityRegistration): Promise<EntityHandle>;
936
+ /**
937
+ * Registers an entity managed on behalf of `managerUuid` (an already-registered self entity,
938
+ * per B.5.2.4): publishes the managed entity's identity with `managedBy` set, and updates the
939
+ * manager's own retained identity to include it in `manages`.
940
+ */
941
+ registerManagedEntity(managerUuid: Uuid, reg: ManagedEntityRegistration): Promise<EntityHandle>;
942
+ listManagedEntities(managerUuid: Uuid): EntityHandle[];
943
+ /** @internal — FleetGateway.registerImr rollback (ND-15 self-check failure): drops a managed
944
+ * entity's handle so listManagedEntities()/health() stop reporting it. */
945
+ removeManagedEntity(managerUuid: Uuid, entityUuid: Uuid): void;
946
+ /** Set the client-wide default execution policy (P-2), overridable per entity handle. */
947
+ setDefaultExecutionPolicy(policy: ExecutionPolicy): void;
948
+ /**
949
+ * Deliberately does NOT go through `subscribeResource('identity', ...)`: the shared
950
+ * `EntityCache` already owns the one identity-wildcard subscription (every client needs it,
951
+ * per decision 3). A second, independent subscribeTopic() to the same filter would make the
952
+ * fake broker (and a real one) redeliver retained identities twice over — this taps the
953
+ * cache's own stream instead, replaying what it already knows plus every future update.
954
+ */
955
+ subscribeEntities(filter: EntityFilter, handler: (identity: EntityIdentity) => void): Promise<Subscription>;
956
+ /** Subscribes to a raw resource (not identity — see {@link subscribeEntities}) across every entity `filter` selects. */
957
+ subscribeResource<T = unknown>(kind: ResourceKind, filter: EntityFilter, handler: (ev: ResourceEvent<T>) => void): Promise<Subscription>;
958
+ /** Observes inbound requests matching `filter`, without participating in serving them (no admission/status effects). */
959
+ subscribeRequests(filter: RequestFilter, handler: (ev: RequestEvent) => void): Promise<Subscription>;
960
+ /** Observes request status updates matching `filter`, e.g. for a fleet-wide activity dashboard. */
961
+ subscribeRequestStatus(filter: RequestStatusFilter, handler: (ev: ResourceEvent<RequestStatus>) => void): Promise<Subscription>;
962
+ /**
963
+ * Retained-identity-only catalog (D-18). Deliberately await-free: callers get a live handle
964
+ * immediately, and the graph fills in as retained `identity`/`disconnection` messages arrive
965
+ * (opening the session — identity-less if none is open yet — happens in the background).
966
+ */
967
+ discover(): EntityCatalog;
968
+ /** Point-in-time snapshot of connection state, registered entities, subscription/traffic counters — see {@link ClientHealth}. */
969
+ health(): ClientHealth;
970
+ on<K extends keyof ClientEvents>(event: K, cb: ClientEvents[K]): void;
971
+ /** Graceful shutdown: the will never fires (MemoryTransport.end() reports ungraceful:false). */
972
+ close(opts?: {
973
+ timeout?: number;
974
+ }): Promise<void>;
975
+ private identitylessRef;
976
+ private ensureSession;
977
+ private openSession;
978
+ private openSequence;
979
+ /**
980
+ * `bindSelf` must be called with the `EntityHandle` built from the returned `ctx`, right after
981
+ * construction — `sendCancel` re-enters `EntityHandle.sendRequest` (cancel = a new request,
982
+ * D-02) and `contextFor` necessarily runs before that `EntityHandle` exists.
983
+ */
984
+ private contextFor;
985
+ private failAllInFlight;
986
+ /** Identity-echo publish self-check (ND-15): confirms our own retained identity round-trips.
987
+ * Shares its implementation with FleetGateway's self-check (default ON there, OFF here). */
988
+ private runSelfCheck;
989
+ private diagnostic;
990
+ /** ND-18: sum of servingCount() across every self and managed handle. */
991
+ private servingCount;
992
+ /** Wraps a raw {@link Subscription} to maintain `subscriptionCount` and the tracked-subs set that `close()` drains. */
993
+ private trackSubscription;
994
+ }
995
+
996
+ export { type ActionContext, ActionExecutor, type ActionHandler, type ActionResult, type AdmissionDecision, type ClientHealth, type ClientOptions, DEFAULT_EXECUTION_POLICY, DEFAULT_PRIORITY, type DiagnosticCode, type DiagnosticEvent, type DispatchInterceptor, type DispatchTarget, EntityCache, type EntityCatalog, type EntityCatalogEntry, type EntityContext, EntityFilter, EntityHandle, EntityIdentity, type EntityRegistration, type EntitySelector, type ExecutionPolicy, FileSequenceStore, IncomingRequest, Iso21423Client, type LocalTrajectoryUpdate, type ManagedEntityRegistration, RESOURCE_MESSAGE_KIND, RequestAcceptanceFilter, type RequestCommand, type RequestDetailStatusUpdate, type RequestEvent, RequestFilter, RequestHandle, type RequestKey, RequestServer, RequestStatusFilter, type RequestStatusUpdate, type RequestTerminalUpdate, type ResourceEvent, type ResourceKind, type SecurityOptions, SequenceCounter, type SequenceStore, type StatusReason, type StatusSink, type StatusUpdate, type Subscription, type TypedRequestDetail, type WithOptionalTimestamp, composeSubscription, defaultStateDir, messageKindFor, policies, resolveCancelRequest, toTimestamp };