@isoloop/protocol 0.1.0-next.8 → 0.1.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.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @isoloop/protocol
2
+
3
+ **Internal.** The wire protocol of [Isoloop](https://github.com/isoloop/isoloop): the message, event and error types that the kernel, the bus and isolates exchange. `@isoloop/host`, `@isoloop/runtime`, `@isoloop/bus` and the adapters depend on it. App code never imports it: the types it needs come re-exported from those packages, and this package's API carries no semver promise of its own.
4
+
5
+ | Entry | What it is |
6
+ | --- | --- |
7
+ | `@isoloop/protocol` | The envelopes, events, grants, bus and control messages, system topics and error codes, and the guards that check a message's shape. |
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare const PROTOCOL: {
4
4
  readonly min: 1;
5
5
  };
6
6
  /** Every message on every port is an envelope. */
7
- export type Envelope<T extends string, P> = {
7
+ type Envelope<T extends string, P> = {
8
8
  /** Protocol version. */
9
9
  v: 1;
10
10
  /** Message type. */
@@ -22,7 +22,7 @@ export type Envelope<T extends string, P> = {
22
22
  p: P;
23
23
  };
24
24
  /** Any envelope, before its type is known. */
25
- export type AnyEnvelope = Envelope<string, unknown>;
25
+ type AnyEnvelope = Envelope<string, unknown>;
26
26
  /**
27
27
  * True for a well-formed envelope this build can read: `v` is a supported
28
28
  * version, `t` is a string, `id`/`re`/`isolate` are absent or strings, and `p`
@@ -34,7 +34,7 @@ export declare function isEnvelope(x: unknown): x is AnyEnvelope;
34
34
  * The message types of one port, as a map so the compiler checks that every
35
35
  * type in the union is listed: a missing key is a type error.
36
36
  */
37
- export type MessageTypes<E extends AnyEnvelope> = Readonly<Record<E["t"], true>>;
37
+ type MessageTypes<E extends AnyEnvelope> = Readonly<Record<E["t"], true>>;
38
38
  /**
39
39
  * Builds a guard for one port's union from its message types. Each side drops
40
40
  * (and counts) envelopes with an unknown `v` or `t` (design §3), so a guard
@@ -43,22 +43,35 @@ export type MessageTypes<E extends AnyEnvelope> = Readonly<Record<E["t"], true>>
43
43
  export declare function envelopeGuard<E extends AnyEnvelope>(types: MessageTypes<E>): (x: unknown) => x is E;
44
44
  /** Exhaustiveness check for switches over message unions. */
45
45
  export declare function assertNever(x: never, message?: string): never;
46
- /** Every error code on the wire (design §3, §4.7, §6.1, §6.3; ADRs 0002, 0003, 0007, 0008). */
46
+ /** Every error code the bus and the host answer with. */
47
47
  export declare const ERROR_CODES: readonly ["protocol_mismatch", "timeout", "no_surface", "forbidden", "not_found", "unsupported", "cross_origin", "routing_disabled", "navigate_failed", "unknown_topic", "too_large", "invalid", "not_encodable", "quota_exceeded", "bus_unavailable", "not_requestable", "already_replied", "reply_invalid", "aborted", "no_responder", "dropped", "contracts_failed", "contracts_invalid", "contracts_mismatch", "reserved_topic", "seed_async", "seed_pending"];
48
- export type ErrorCode = (typeof ERROR_CODES)[number];
48
+ /**
49
+ * An error code a `BusError` or `HostCallError` carries. By where it comes from:
50
+ * - host calls: `timeout`, `no_surface`, `forbidden`, `not_found`, `unsupported`;
51
+ * - routing: `cross_origin`, `routing_disabled`, `navigate_failed`;
52
+ * - the broker: `unknown_topic`, `too_large`, `invalid`, `not_encodable`,
53
+ * `quota_exceeded`, `bus_unavailable`, `not_requestable`, `already_replied`,
54
+ * `reply_invalid`;
55
+ * - `kernel.request`: `aborted`, `no_responder`, `dropped`;
56
+ * - the contracts, fatal and never retried: `contracts_failed`,
57
+ * `contracts_invalid`, `contracts_mismatch`, `reserved_topic`;
58
+ * - seeding: `seed_async`, `seed_pending`;
59
+ * - the version handshake: `protocol_mismatch`.
60
+ */
61
+ type ErrorCode = (typeof ERROR_CODES)[number];
49
62
  export declare function isErrorCode(x: unknown): x is ErrorCode;
50
- /** A schema issue, as reported with `invalid` (design §6.3). */
51
- export type Issue = {
63
+ /** A schema issue, as reported with `invalid`: what's wrong, and where in the value. */
64
+ type Issue = {
52
65
  message: string;
53
66
  path: (string | number)[];
54
67
  };
55
- export type CallError = {
68
+ type CallError = {
56
69
  code: ErrorCode;
57
70
  message: string;
58
71
  issues?: Issue[];
59
72
  };
60
73
  /** Reply to a host call or an acknowledged publish. */
61
- export type CallResult = {
74
+ type CallResult = {
62
75
  ok: true;
63
76
  value: unknown;
64
77
  } | {
@@ -66,23 +79,22 @@ export type CallResult = {
66
79
  error: CallError;
67
80
  };
68
81
  /** Payload of an `error` envelope from an isolate or the bus worker. */
69
- export type ErrorPayload = {
82
+ type ErrorPayload = {
70
83
  message: string;
71
84
  stack?: string;
72
85
  fatal: boolean;
73
86
  code?: ErrorCode;
74
87
  };
75
- /** What an isolate may do on the bus and the host (design §3). */
76
- export type Grants = {
77
- /** Topic patterns the isolate may publish to. */
88
+ /** What an isolate may do on the bus and the host: `IsolateManifest.grants`. */
89
+ type Grants = {
90
+ /** Topic patterns the isolate may publish to. `*` matches one or more characters, dots included. */
78
91
  publish: string[];
79
- /** Topic patterns the isolate may subscribe to. */
92
+ /** Topic patterns the isolate may subscribe to, the same way. */
80
93
  subscribe: string[];
81
- /** Programmatic `navigate()` allowed (ADR 0002). Default false. */
94
+ /** `ctx.host.navigate()` allowed. Default false. */
82
95
  navigate?: boolean;
83
96
  /**
84
- * The inspection feed and its controls (ADR 0020, decision 6): the isolate
85
- * gets `ctx.inspector` on a port of its own, which reads the feed and can
97
+ * The inspection feed and its controls: the isolate gets `ctx.inspector` on a port of its own, which reads the feed and can
86
98
  * restart, kill and block isolates. Default false. Never in a pool: spawning
87
99
  * a pooled isolate with it fails with `invalid_config`, since a pool merges
88
100
  * its members' grants.
@@ -102,7 +114,7 @@ export declare function matchTopic(grant: string, topic: string): boolean;
102
114
  /** True if any pattern in the list matches `topic`. */
103
115
  export declare function matchAny(patterns: readonly string[], topic: string): boolean;
104
116
  /** Modifier keys held during an event. */
105
- export type Mods = {
117
+ type Mods = {
106
118
  alt: boolean;
107
119
  ctrl: boolean;
108
120
  meta: boolean;
@@ -113,9 +125,9 @@ export type Mods = {
113
125
  * canvases (§4.7). `pointermove` and `scroll` are opt-in per node and come at
114
126
  * most once a frame.
115
127
  */
116
- export type EventType = "click" | "dblclick" | "input" | "change" | "keydown" | "keyup" | "submit" | "focusin" | "focusout" | "pointerdown" | "pointerup" | "pointermove" | "scroll" | "resize";
128
+ type EventType = "click" | "dblclick" | "input" | "change" | "keydown" | "keyup" | "submit" | "focusin" | "focusout" | "pointerdown" | "pointerup" | "pointermove" | "scroll" | "resize";
117
129
  /** A DOM event as it reaches an isolate (design §4.6). Node ids are the isolate's own. */
118
- export type SerializedEvent = {
130
+ type SerializedEvent = {
119
131
  type: EventType;
120
132
  target: string;
121
133
  /** The target and its ancestors that have a listener, innermost first. */
@@ -135,19 +147,19 @@ export type SerializedEvent = {
135
147
  scrollTop?: number;
136
148
  scrollLeft?: number;
137
149
  };
138
- /** Why the host asks an isolate to shut down. `suspend` keeps its offsets (M2, ADR 0001). */
139
- export type ShutdownReason = "stop" | "restart" | "suspend";
150
+ /** Why the host asks an isolate to shut down. `suspend` keeps its offsets, to replay what it missed on waking. */
151
+ type ShutdownReason = "stop" | "restart" | "suspend";
140
152
  /** Calls an isolate can make to the host (design §4.7). */
141
- export type HostMethod = "measure" | "focus" | "navigate" | "scrollIntoView" | "requestCanvas";
153
+ type HostMethod = "measure" | "focus" | "navigate" | "scrollIntoView" | "requestCanvas";
142
154
  /** What `measure` returns: a node's box relative to its surface, in CSS pixels. */
143
- export type Rect = {
155
+ type Rect = {
144
156
  x: number;
145
157
  y: number;
146
158
  width: number;
147
159
  height: number;
148
160
  };
149
161
  /** First message to an isolate. The host's half of the version handshake. */
150
- export type InitPayload = {
162
+ type InitPayload = {
151
163
  isolateId: string;
152
164
  /** Protocol versions the host accepts. */
153
165
  protocol: {
@@ -173,7 +185,7 @@ export type InitPayload = {
173
185
  commitIntervalMs?: number;
174
186
  };
175
187
  /** What a beat says about whether the isolate could be suspended (ADR 0001). */
176
- export type IdleReport = {
188
+ type IdleReport = {
177
189
  /** Time since the bus last delivered a record to this isolate. */
178
190
  sinceDeliveryMs: number;
179
191
  /** Host calls, publishes and requests waiting for an answer. */
@@ -196,7 +208,7 @@ export type IdleReport = {
196
208
  /** The longest `block` a runtime runs; a longer one is cut to this (ADR 0020, decision 4). */
197
209
  export declare const MAX_BLOCK_MS = 1e4;
198
210
  /** Isolate port: host → isolate. */
199
- export type HostToIsolate = Envelope<"init", InitPayload> | Envelope<"event", SerializedEvent> | Envelope<"result", CallResult> | Envelope<"shutdown", {
211
+ type HostToIsolate = Envelope<"init", InitPayload> | Envelope<"event", SerializedEvent> | Envelope<"result", CallResult> | Envelope<"shutdown", {
200
212
  reason: ShutdownReason;
201
213
  graceMs: number;
202
214
  }> | Envelope<"reattach", {
@@ -207,7 +219,7 @@ export type HostToIsolate = Envelope<"init", InitPayload> | Envelope<"event", Se
207
219
  port: MessagePort;
208
220
  }>;
209
221
  /** Isolate port: isolate → host. */
210
- export type IsolateToHost = Envelope<"ready", {
222
+ type IsolateToHost = Envelope<"ready", {
211
223
  runtime: string;
212
224
  adapter: string;
213
225
  renderFmt: string;
@@ -238,10 +250,13 @@ export declare const HOST_TO_ISOLATE: MessageTypes<HostToIsolate>;
238
250
  export declare const ISOLATE_TO_HOST: MessageTypes<IsolateToHost>;
239
251
  export declare const isHostToIsolate: (x: unknown) => x is HostToIsolate;
240
252
  export declare const isIsolateToHost: (x: unknown) => x is IsolateToHost;
241
- /** One record in a topic's log (design §6.1). */
242
- export type BusRecord = {
253
+ /** One record in a topic's log. */
254
+ type BusRecord = {
255
+ /** Its place in the topic's log, from 0. */
243
256
  offset: number;
257
+ /** The key it was published with, if any. */
244
258
  key?: string;
259
+ /** The value, checked against the topic's schema. */
245
260
  value: unknown;
246
261
  /** `Date.now()` at append. */
247
262
  ts: number;
@@ -250,27 +265,26 @@ export type BusRecord = {
250
265
  /**
251
266
  * Set on a `bus.request` record: the caller's isolate id (`'host'` for
252
267
  * `kernel.request`) and its request id. A recipient answers with
253
- * `reply { topic, offset }` (design §6.3). `via` names the agent transport
254
- * that made the call (ADR 0018, decision 4); an isolate's own `bus.request`
255
- * never sets it.
268
+ * `bus.reply(record, value)`. `via` names the agent transport that made the
269
+ * call; an isolate's own `bus.request` never sets it.
256
270
  */
257
271
  req?: RecordReq;
258
272
  };
259
273
  /**
260
- * The agent transports that call through `kernel.request` (ADR 0018, decision 4):
261
- * the dev MCP, WebMCP, and later the Builder.
274
+ * The agent transports that call through `kernel.request`: `mcp` (the dev
275
+ * MCP) and `webmcp` (WebMCP). Nothing in Isoloop sets `builder`.
262
276
  *
263
277
  * Self-declared by the caller: a label for logging and policy between
264
278
  * cooperating code on one page. Never authorize anything by it.
265
279
  * @experimental
266
280
  */
267
- export type RequestVia = "mcp" | "webmcp" | "builder";
281
+ type RequestVia = "mcp" | "webmcp" | "builder";
268
282
  /** Every {@link RequestVia}, for guards. @experimental */
269
283
  export declare const REQUEST_VIA: readonly RequestVia[];
270
284
  /** True for a known {@link RequestVia}. @experimental */
271
285
  export declare function isRequestVia(x: unknown): x is RequestVia;
272
286
  /** `BusRecord.req`: who asked, under which request id, and through which transport. */
273
- export type RecordReq = {
287
+ type RecordReq = {
274
288
  from: string;
275
289
  id: string;
276
290
  via?: RequestVia;
@@ -287,14 +301,19 @@ export declare function isRecordReq(x: unknown): x is RecordReq;
287
301
  * publishes and requests. The bus answers a re-send it already holds with the
288
302
  * original offset. Memory topics ignore it.
289
303
  */
290
- export type PublishId = {
304
+ type PublishId = {
291
305
  epoch?: number;
292
306
  seq?: number;
293
307
  };
294
- /** Where a new subscription starts reading. */
295
- export type StartPosition = "latest" | "earliest" | "committed";
308
+ /**
309
+ * Where a new subscription starts reading: `latest`, only records appended
310
+ * from now on; `earliest`, the oldest record still retained; `committed`,
311
+ * after the last record this subscriber committed, or the oldest retained
312
+ * when it has committed none.
313
+ */
314
+ type StartPosition = "latest" | "earliest" | "committed";
296
315
  /** Bus port: isolate → bus worker. */
297
- export type IsolateToBus = Envelope<"publish", {
316
+ type IsolateToBus = Envelope<"publish", {
298
317
  topic: string;
299
318
  key?: string;
300
319
  value: unknown;
@@ -322,7 +341,7 @@ export type IsolateToBus = Envelope<"publish", {
322
341
  value: unknown;
323
342
  }>;
324
343
  /** Bus port: bus worker → isolate. */
325
- export type BusToIsolate = Envelope<"deliver", {
344
+ type BusToIsolate = Envelope<"deliver", {
326
345
  topic: string;
327
346
  records: BusRecord[];
328
347
  gap?: {
@@ -351,12 +370,12 @@ export declare function commitIntervalProblem(ms: unknown): string | undefined;
351
370
  * delivery `seq` settled whole (ADR 0016, point 11), and how many records of
352
371
  * delivery `seq + 1` are settled, when some are (point 17).
353
372
  */
354
- export type CommitPoint = {
373
+ type CommitPoint = {
355
374
  offset: number;
356
375
  seq: number;
357
376
  partial?: number;
358
377
  };
359
- export type CommitOffsets = ({
378
+ type CommitOffsets = ({
360
379
  topic: string;
361
380
  } & CommitPoint)[];
362
381
  /**
@@ -371,7 +390,7 @@ export type CommitOffsets = ({
371
390
  * also reaches every offset in it.
372
391
  */
373
392
  export declare function deliveryPoints(seq: number, offsets: readonly number[], highest: number): CommitPoint[];
374
- export type CommitterOptions = {
393
+ type CommitterOptions = {
375
394
  /** Sends one `commits` message. Called with at least one entry. */
376
395
  send: (offsets: CommitOffsets) => void;
377
396
  /** 0: at the end of each task that settled a record. Default 100. */
@@ -379,7 +398,7 @@ export type CommitterOptions = {
379
398
  /** The broker's credit per subscription; a subscription sends early at half of it. Default 1,000. */
380
399
  credit?: number;
381
400
  };
382
- export type Committer = {
401
+ type Committer = {
383
402
  /**
384
403
  * `records` records of `topic` are settled (default one): everything up to
385
404
  * `at.offset`, and every delivery up to `at.seq` whole. Each is kept as the
@@ -407,15 +426,25 @@ export declare function createCommitter(o: CommitterOptions): Committer;
407
426
  * `reply`): the broker's error code, and the schema issues for `invalid`.
408
427
  */
409
428
  export declare class BusError extends Error {
429
+ /** What went wrong, to branch on: `invalid`, `forbidden`, `timeout`, `bus_unavailable`, … */
410
430
  readonly code: ErrorCode;
431
+ /** For `invalid`: where the value failed its schema, and why. */
411
432
  readonly issues: readonly Issue[] | undefined;
433
+ /** @param error The broker's error: its code, message and issues. */
412
434
  constructor(error: CallError);
413
435
  }
414
- export type Retention = {
436
+ /**
437
+ * What a topic's log keeps: `last-n`, the newest `n` records; `time`, the
438
+ * records younger than `ms` by their `ts`; `compacted`, the latest record per
439
+ * key.
440
+ */
441
+ type Retention = {
415
442
  kind: "last-n";
443
+ /** How many records to keep, a positive integer. */
416
444
  n: number;
417
445
  } | {
418
446
  kind: "time";
447
+ /** How long to keep a record, in milliseconds, a positive integer. */
419
448
  ms: number;
420
449
  } | {
421
450
  kind: "compacted";
@@ -424,7 +453,7 @@ export type Retention = {
424
453
  * The structured-cloneable part of a topic definition: what the host sends at
425
454
  * `boot` so the bus worker can check it against the contracts module (ADR 0003).
426
455
  */
427
- export type TopicConfig = {
456
+ type TopicConfig = {
428
457
  name: string;
429
458
  retention: Retention;
430
459
  /** Default 256 KiB. */
@@ -439,15 +468,15 @@ export type TopicConfig = {
439
468
  follow: boolean;
440
469
  };
441
470
  };
442
- /** Why persistent topics run in memory (`bus:durability-degraded`). */
443
- export type DurabilityDegraded = "another-tab" | "no-sync-access" | "open-failed";
471
+ /** Why persistent topics run in memory (`bus:durability_degraded`). */
472
+ type DurabilityDegraded = "another_tab" | "no_sync_access" | "open_failed";
444
473
  /**
445
474
  * Seeding news (ADR 0003, decision 18). `rejected`: a source record `map`
446
475
  * threw on, returned a promise for (`seed_async`), or the topic's schema
447
476
  * rejected; it was skipped and stays in `from`. `seeded`: the seed ended and
448
477
  * the topic opened.
449
478
  */
450
- export type SeedEvent = {
479
+ type SeedEvent = {
451
480
  kind: "rejected";
452
481
  topic: string;
453
482
  from: string;
@@ -460,11 +489,11 @@ export type SeedEvent = {
460
489
  copied: number;
461
490
  rejected: number;
462
491
  };
463
- /** Sampled every second on the control port (design §6.3). */
464
- export type BusMetrics = {
492
+ /** The bus's figures, sampled every second: `bus:metrics`. */
493
+ type BusMetrics = {
465
494
  /**
466
- * `head` is the next offset to be written; `retained` is how many records
467
- * the topic still holds (ADR 0020, decision 2).
495
+ * Per topic: records and bytes a second; `head`, the next offset to be
496
+ * written; and `retained`, how many records the topic still holds.
468
497
  */
469
498
  topics: {
470
499
  topic: string;
@@ -473,13 +502,17 @@ export type BusMetrics = {
473
502
  head: number;
474
503
  retained: number;
475
504
  }[];
476
- /** `lag` is `head − cursor`. */
505
+ /**
506
+ * Per consumer and topic: `lag` is `head − cursor`; `credit` is how many
507
+ * records may still be delivered before its next commit.
508
+ */
477
509
  subscriptions: {
478
510
  consumer: string;
479
511
  topic: string;
480
512
  lag: number;
481
513
  credit: number;
482
514
  }[];
515
+ /** Rejected publishes by error code, since the bus worker started. */
483
516
  rejected: Partial<Record<ErrorCode, number>>;
484
517
  /** The origin's storage use, from `navigator.storage.estimate()`, while the bus keeps files. */
485
518
  storage?: {
@@ -494,20 +527,26 @@ export declare const DEFAULT_TAP_PER_SEC = 50;
494
527
  /** Most records one `read` returns. */
495
528
  export declare const MAX_READ = 100;
496
529
  /**
497
- * A record as the inspection feed shows it (ADR 0020, decision 3): its value
498
- * as text, cut to `PREVIEW_CHARS`, with the value's estimated size in bytes.
530
+ * A record as the inspection feed shows it: its value as text, cut to 2,048
531
+ * characters, with the value's estimated size in bytes.
499
532
  * @experimental
500
533
  */
501
- export type RecordPreview = {
534
+ type RecordPreview = {
535
+ /** The topic's name. */
502
536
  topic: string;
537
+ /** Its place in the topic's log. */
503
538
  offset: number;
539
+ /** The key it was published with, if any. */
504
540
  key?: string;
541
+ /** `Date.now()` at append. */
505
542
  ts: number;
543
+ /** Who published it: an isolate's id, or the host. */
506
544
  producer: string;
545
+ /** For a request record: who asked, and the request's id. */
507
546
  req?: RecordReq;
508
547
  /** The value's estimated size, as the bus counts it for `too_large` and the byte rates. */
509
548
  bytes: number;
510
- /** The value as JSON-like text, at most `PREVIEW_CHARS` characters. */
549
+ /** The value as JSON-like text, at most 2,048 characters. */
511
550
  preview: string;
512
551
  /** `preview` was cut short. */
513
552
  truncated: boolean;
@@ -517,13 +556,13 @@ export type RecordPreview = {
517
556
  * `maxPerSec` since the last `skipped`, sent at most once a second.
518
557
  * @experimental
519
558
  */
520
- export type BusToTap = Envelope<"record", RecordPreview> | Envelope<"skipped", {
559
+ type BusToTap = Envelope<"record", RecordPreview> | Envelope<"skipped", {
521
560
  count: number;
522
561
  }>;
523
562
  /** A tap's port: host → bus. `close` ends the tap. @experimental */
524
- export type TapToBus = Envelope<"close", Record<string, never>>;
563
+ type TapToBus = Envelope<"close", Record<string, never>>;
525
564
  /** Control port: host → bus worker. */
526
- export type HostToBus = Envelope<"boot", {
565
+ type HostToBus = Envelope<"boot", {
527
566
  contractsUrl: string;
528
567
  topics: TopicConfig[];
529
568
  heartbeatMs?: number;
@@ -566,7 +605,7 @@ export type HostToBus = Envelope<"boot", {
566
605
  last: number;
567
606
  }>;
568
607
  /** Control port: bus worker → host. */
569
- export type BusToHost = Envelope<"ready", {
608
+ type BusToHost = Envelope<"ready", {
570
609
  engine: string;
571
610
  storage: "memory" | "opfs";
572
611
  restored: {
@@ -612,7 +651,7 @@ export declare const isTapToBus: (x: unknown) => x is TapToBus;
612
651
  * on nothing, so this is the structural subset of the interface that system
613
652
  * topics need; it is assignable to the bus's vendored `StandardSchemaV1`.
614
653
  */
615
- export type SystemSchema<T> = {
654
+ type SystemSchema<T> = {
616
655
  readonly "~standard": {
617
656
  readonly version: 1;
618
657
  readonly vendor: "isoloop";
@@ -629,7 +668,7 @@ export type SystemSchema<T> = {
629
668
  };
630
669
  };
631
670
  /** A kernel-owned `isoloop.*` topic: same shape as a bus `TopicDef`. */
632
- export type SystemTopicDef<T> = {
671
+ type SystemTopicDef<T> = {
633
672
  readonly name: string;
634
673
  readonly schema: SystemSchema<T>;
635
674
  readonly retention: Retention;
@@ -639,7 +678,7 @@ export type SystemTopicDef<T> = {
639
678
  * A check that returns the issues found in `value`, or none. `path` is where
640
679
  * `value` sits, so nested checks can report full paths.
641
680
  */
642
- export type Check = (value: unknown, path: (string | number)[]) => Issue[];
681
+ type Check = (value: unknown, path: (string | number)[]) => Issue[];
643
682
  /** Wraps a hand-written check as a Standard Schema that passes valid values through unchanged. */
644
683
  export declare function systemSchema<T>(check: Check): SystemSchema<T>;
645
684
  /** Defines a system topic. The name must start with `isoloop.`. */
@@ -653,14 +692,17 @@ export declare const checks: {
653
692
  /** Any value. */
654
693
  any: Check;
655
694
  };
656
- /** The current location, as the kernel publishes it (ADR 0002). */
657
- export type RouteValue = {
658
- /** Absolute URL. */
695
+ /** The host page's current location, as the kernel publishes it on each navigation. */
696
+ type RouteValue = {
697
+ /** The absolute URL. */
659
698
  href: string;
699
+ /** The URL's path, as `location.pathname` has it. */
660
700
  pathname: string;
661
701
  /** `pathname` relative to `basePath`, starting with `/`; `null` outside it. */
662
702
  path: string | null;
703
+ /** The query string, with its `?`, or `''`. */
663
704
  search: string;
705
+ /** The fragment, with its `#`, or `''`. */
664
706
  hash: string;
665
707
  /** `history.state` as is; `null` when it was too large for the bus (`route:state_dropped`). */
666
708
  state: unknown;
@@ -676,14 +718,20 @@ export declare const routeTopic: SystemTopicDef<RouteValue>;
676
718
  export declare const ROUTE_KEY = "current";
677
719
  /** Every system topic, built into the bus. */
678
720
  export declare const SYSTEM_TOPICS: readonly SystemTopicDef<any>[];
679
- /** A topic as `kernel.publish`, `kernel.subscribe` and `BusClient` take it. */
680
- export type TopicRef<In = unknown, Out = In, RIn = never, ROut = RIn> = {
721
+ /**
722
+ * A topic as `kernel.publish`, `kernel.subscribe` and `BusClient` take it:
723
+ * any `topic()` from `@isoloop/bus` fits, and its schema types carry over.
724
+ */
725
+ type TopicRef<In = unknown, Out = In, RIn = never, ROut = RIn> = {
726
+ /** The topic's name. */
681
727
  readonly name: string;
728
+ /** Its schema's types. */
682
729
  readonly schema: SchemaTypes<In, Out>;
730
+ /** Its `reply` schema's types, for a requestable topic. */
683
731
  readonly reply?: SchemaTypes<RIn, ROut>;
684
732
  };
685
733
  /** The type-only part of a Standard Schema V1. */
686
- export type SchemaTypes<In, Out> = {
734
+ type SchemaTypes<In, Out> = {
687
735
  readonly "~standard": {
688
736
  readonly types?: {
689
737
  readonly input: In;
@@ -692,17 +740,17 @@ export type SchemaTypes<In, Out> = {
692
740
  };
693
741
  };
694
742
  /** A record whose value has the topic's output type. */
695
- export type TypedRecord<T> = Omit<BusRecord, "value"> & {
743
+ type TypedRecord<T> = Omit<BusRecord, "value"> & {
696
744
  value: T;
697
745
  };
698
746
  /**
699
- * Describes a requestable topic as a tool for agents (ADR 0018, decision 1).
747
+ * Describes a requestable topic as a tool for agents.
700
748
  * A `tool` field alone exposes nothing: the app's kernel config lists what
701
749
  * agents may call (`agents.expose`). It stays on the host and isn't part of
702
750
  * the `TopicConfig` the bus sees.
703
751
  * @experimental
704
752
  */
705
- export type ToolSpec = {
753
+ type ToolSpec = {
706
754
  /** A short human-readable name. The tool's name is always the topic's name. */
707
755
  readonly title?: string;
708
756
  /** What the tool does, for the agent choosing it. */
@@ -714,29 +762,35 @@ export type ToolSpec = {
714
762
  /** The reply can carry third-party text. WebMCP `untrustedContentHint`. Default `false`. */
715
763
  readonly untrustedContent?: boolean;
716
764
  };
717
- /** The parts of a topic definition that make up its `TopicConfig`. */
718
- export type TopicShape = {
765
+ /** A topic as the host reads it from the contracts: any `topic()` from `@isoloop/bus` fits. */
766
+ type TopicShape = {
767
+ /** The topic's name. */
719
768
  readonly name: string;
720
769
  /**
721
770
  * The topic's Standard Schema. The host reads it only to make a tool's
722
- * JSON Schema (ADR 0018, decision 1); it never validates with it.
771
+ * JSON Schema; it never validates with it.
723
772
  */
724
773
  readonly schema?: unknown;
774
+ /** How long it keeps its records. */
725
775
  readonly retention: Retention;
776
+ /** The largest value it takes, in bytes. Default 256 KiB. */
726
777
  readonly maxRecordBytes?: number;
778
+ /** `persistent` topics keep their records across reloads, on disk. Default `memory`. */
727
779
  readonly durability?: "memory" | "persistent";
780
+ /** The `reply` schema, for a requestable topic. */
728
781
  readonly reply?: unknown;
782
+ /** The topic it's seeded from, and whether it keeps following it. */
729
783
  readonly seed?: {
730
784
  readonly from: {
731
785
  readonly name: string;
732
786
  };
733
787
  readonly follow?: boolean;
734
788
  };
735
- /** Host only: never part of the `TopicConfig` (ADR 0018, decision 1). */
789
+ /** The topic as a tool for agents. The host keeps it; the bus never sees it. */
736
790
  readonly tool?: ToolSpec;
737
791
  };
738
792
  /** What `KernelConfig.contracts.list` holds: a `contracts()` list, seen structurally. */
739
- export type ContractsList = {
793
+ type ContractsList = {
740
794
  readonly topics: readonly TopicShape[];
741
795
  };
742
796
  /**
@@ -764,11 +818,11 @@ export declare const UNCHECKED_VENDOR = "isoloop/unchecked";
764
818
  *
765
819
  * @internal
766
820
  */
767
- export interface StandardJSONSchemaV1 {
821
+ interface StandardJSONSchemaV1 {
768
822
  readonly "~standard": StandardJSONSchemaV1.Props;
769
823
  }
770
824
  /** @internal */
771
- export declare namespace StandardJSONSchemaV1 {
825
+ declare namespace StandardJSONSchemaV1 {
772
826
  export interface Props<Input = unknown, Output = Input> {
773
827
  readonly version: 1;
774
828
  readonly vendor: string;
@@ -796,7 +850,7 @@ export declare namespace StandardJSONSchemaV1 {
796
850
  *
797
851
  * @internal
798
852
  */
799
- export type JsonSchema = {
853
+ type JsonSchema = {
800
854
  [key: string]: unknown;
801
855
  };
802
856
  /**
@@ -805,7 +859,7 @@ export type JsonSchema = {
805
859
  *
806
860
  * @internal
807
861
  */
808
- export type JsonSchemaPair = {
862
+ type JsonSchemaPair = {
809
863
  readonly input: JsonSchema;
810
864
  readonly output: JsonSchema;
811
865
  };
@@ -818,13 +872,13 @@ export type JsonSchemaPair = {
818
872
  *
819
873
  * @internal
820
874
  */
821
- export type NotExportableReason = "unchecked" | "unsupported" | "failed";
875
+ type NotExportableReason = "unchecked" | "unsupported" | "failed";
822
876
  /**
823
877
  * The result of {@link jsonSchemaOf}. Never throws; a failure is a value.
824
878
  *
825
879
  * @internal
826
880
  */
827
- export type JsonSchemaResult = ({
881
+ type JsonSchemaResult = ({
828
882
  readonly ok: true;
829
883
  } & JsonSchemaPair) | {
830
884
  readonly ok: false;
@@ -858,7 +912,7 @@ export declare function jsonSchemaOf(schema: unknown): JsonSchemaResult;
858
912
  *
859
913
  * @internal
860
914
  */
861
- export type TopicJsonSchemas = {
915
+ type TopicJsonSchemas = {
862
916
  readonly schema: JsonSchemaPair;
863
917
  readonly reply?: JsonSchemaPair;
864
918
  };
@@ -867,7 +921,7 @@ export type TopicJsonSchemas = {
867
921
  *
868
922
  * @internal
869
923
  */
870
- export type TopicJsonSchemasResult = ({
924
+ type TopicJsonSchemasResult = ({
871
925
  readonly ok: true;
872
926
  } & TopicJsonSchemas) | {
873
927
  readonly ok: false;
@@ -893,7 +947,7 @@ export declare function topicJsonSchemas(def: {
893
947
  * An exposed tool as the page sends it: `kernel.tools()` without `topic`.
894
948
  * @internal
895
949
  */
896
- export type DevMcpTool = {
950
+ type DevMcpTool = {
897
951
  readonly name: string;
898
952
  readonly title?: string;
899
953
  readonly description: string;
@@ -909,7 +963,7 @@ export type DevMcpTool = {
909
963
  readonly timeoutMs: number;
910
964
  };
911
965
  /** A call's answer: the reply, or the error's code and message. @internal */
912
- export type DevMcpResult = {
966
+ type DevMcpResult = {
913
967
  readonly ok: true;
914
968
  readonly value: unknown;
915
969
  } | {
@@ -920,7 +974,7 @@ export type DevMcpResult = {
920
974
  readonly issues?: readonly Issue[];
921
975
  };
922
976
  /** `hello`'s payload: the pairing token, the page's URL and title, and its tools. @internal */
923
- export type DevMcpHello = {
977
+ type DevMcpHello = {
924
978
  readonly token: string;
925
979
  readonly url: string;
926
980
  readonly title?: string;
@@ -933,11 +987,11 @@ export type DevMcpHello = {
933
987
  readonly inspect?: boolean;
934
988
  };
935
989
  /** `welcome`'s payload: the page's id, which agents pass as `page`. @internal */
936
- export type DevMcpWelcome = {
990
+ type DevMcpWelcome = {
937
991
  readonly page: string;
938
992
  };
939
993
  /** `call`'s payload: the tool to request and its input. @internal */
940
- export type DevMcpCall = {
994
+ type DevMcpCall = {
941
995
  readonly name: string;
942
996
  readonly input: unknown;
943
997
  };
@@ -945,14 +999,14 @@ export type DevMcpCall = {
945
999
  * Page → CLI: `hello` first, then a `result` per call (`re` = the call's `id`).
946
1000
  * @internal
947
1001
  */
948
- export type PageToCli = Envelope<"hello", DevMcpHello> | Envelope<"result", DevMcpResult>;
1002
+ type PageToCli = Envelope<"hello", DevMcpHello> | Envelope<"result", DevMcpResult>;
949
1003
  /**
950
1004
  * CLI → page: `welcome` once paired; `call` (an app tool) or `op` (one of the
951
1005
  * dev MCP's own tools), each with an `id`; `cancel`, `re` = a call's `id`,
952
1006
  * when the agent cancelled it (the page aborts its signal).
953
1007
  * @internal
954
1008
  */
955
- export type CliToPage = Envelope<"welcome", DevMcpWelcome> | Envelope<"call", DevMcpCall> | Envelope<"op", DevMcpOp> | Envelope<"cancel", DevMcpCancel>;
1009
+ type CliToPage = Envelope<"welcome", DevMcpWelcome> | Envelope<"call", DevMcpCall> | Envelope<"op", DevMcpOp> | Envelope<"cancel", DevMcpCancel>;
956
1010
  /**
957
1011
  * `op`'s payload: one of the dev MCP's own tools, answered by the page from
958
1012
  * `kernel.inspect()` (ADR 0020) or the kernel (M4a decision 12). The page
@@ -960,7 +1014,7 @@ export type CliToPage = Envelope<"welcome", DevMcpWelcome> | Envelope<"call", De
960
1014
  * `kill`, `block`, `publish`, `request`) are sent only with `--allow-write`.
961
1015
  * @internal
962
1016
  */
963
- export type DevMcpOp = {
1017
+ type DevMcpOp = {
964
1018
  readonly op: "isolates";
965
1019
  } | {
966
1020
  readonly op: "topics";
@@ -998,7 +1052,7 @@ export type DevMcpOp = {
998
1052
  /** `DevMcpOp['op']`, as a list. @internal */
999
1053
  export declare const DEV_MCP_OPS: readonly DevMcpOp["op"][];
1000
1054
  /** `cancel`'s payload: empty. @internal */
1001
- export type DevMcpCancel = Record<string, never>;
1055
+ type DevMcpCancel = Record<string, never>;
1002
1056
  /** @internal */
1003
1057
  export declare const PAGE_TO_CLI: MessageTypes<PageToCli>;
1004
1058
  /** @internal */
@@ -1028,15 +1082,25 @@ export declare const DEV_MCP_PORT = 4317;
1028
1082
  * a newer kernel's values.
1029
1083
  * @experimental
1030
1084
  */
1031
- export type InspectIsolate = {
1085
+ type InspectIsolate = {
1086
+ /** The isolate's id. */
1032
1087
  id: string;
1088
+ /** Its `IsolateState`. */
1033
1089
  state: string;
1090
+ /** The pool it runs in; absent for a worker of its own. */
1034
1091
  pool?: string;
1035
1092
  /** `performance.now()` on the host when its last beat arrived. */
1036
1093
  lastBeatAt: number;
1094
+ /**
1095
+ * How late its worker's last beat fired, past the heartbeat interval, in ms. It keeps the last beat's value while
1096
+ * the worker is blocked and sends no beat. To see a block in progress, read `state` and the time since `lastBeatAt`.
1097
+ */
1037
1098
  lagMs: number;
1099
+ /** Restarts after a crash since it was spawned. */
1038
1100
  restarts: number;
1101
+ /** The last crash's `CrashReason`, while restarting or failed. */
1039
1102
  reason?: string;
1103
+ /** The last crash's message, while restarting or failed. */
1040
1104
  error?: string;
1041
1105
  /** Compositor figures for a visual isolate (`SurfaceStats`). */
1042
1106
  surface?: {
@@ -1046,28 +1110,30 @@ export type InspectIsolate = {
1046
1110
  dropped: number;
1047
1111
  lastFrameMs: number;
1048
1112
  };
1113
+ /** Messages from its worker dropped because their version or type was unknown. */
1049
1114
  dropped: number;
1115
+ /** Open `ctx.keepAwake()` holds, from the last beat. */
1050
1116
  holds?: {
1051
1117
  ageMs: number;
1052
1118
  stack?: string;
1053
1119
  }[];
1120
+ /** Milliseconds its worker spent running its code during the last beat's interval. */
1054
1121
  busyMs?: number;
1055
1122
  /**
1056
- * Its worker's memory, from the host's last measurement (ADR 0020, decision
1057
- * 4). Absent when the page isn't cross-origin isolated, in engines without
1123
+ * Its worker's memory, from the host's last measurement. Absent when the page isn't cross-origin isolated, in engines without
1058
1124
  * `performance.measureUserAgentSpecificMemory()` (Firefox, Safari), and
1059
1125
  * before the first measurement.
1060
1126
  */
1061
1127
  memory?: InspectMemory;
1062
1128
  };
1063
1129
  /**
1064
- * One isolate's memory (ADR 0020, decision 4): the bytes the browser
1065
- * attributes to its worker. Coarse, and seconds old: Chromium answers a
1130
+ * One isolate's memory: the bytes the browser attributes to its worker. Coarse, and seconds old: Chromium answers a
1066
1131
  * measurement at its next garbage collection. A reader shows its age and
1067
1132
  * labels it "Chromium, cross-origin isolated".
1068
1133
  * @experimental
1069
1134
  */
1070
- export type InspectMemory = {
1135
+ type InspectMemory = {
1136
+ /** The bytes the browser attributes to the worker. */
1071
1137
  bytes: number;
1072
1138
  /** `performance.now()` on the host when the measurement came back. */
1073
1139
  at: number;
@@ -1075,31 +1141,45 @@ export type InspectMemory = {
1075
1141
  shared?: true;
1076
1142
  };
1077
1143
  /** One pool in the feed, as `kernel.pools()` has it. @experimental */
1078
- export type InspectPool = {
1144
+ type InspectPool = {
1145
+ /** The pool's name. */
1079
1146
  name: string;
1147
+ /** Isolates naming this pool, not stopped, in spawn order. */
1080
1148
  members: string[];
1149
+ /** True while the pool's worker runs. */
1081
1150
  running: boolean;
1151
+ /** The union of its members' grants: what the pool can do in effect. */
1082
1152
  grants: Grants;
1153
+ /** True when a member has a surface: the visual members share one document. */
1083
1154
  sharesDocument: boolean;
1155
+ /** When `sharesDocument`: what that means for the members, in a sentence for people. */
1084
1156
  warning?: string;
1085
1157
  };
1086
1158
  /**
1087
- * One kernel event, at once or from the ring buffer (ADR 0020, decisions 2
1088
- * and 5). `event` is a `KernelEvents` name (`isolate:crash`, `bus:restart`, …)
1159
+ * One kernel event, at once or from the ring buffer. `event` is a `KernelEvents` name (`isolate:crash`, `bus:restart`, …)
1089
1160
  * and `data` its payload. Beats and bus metrics come as their own messages.
1090
1161
  * @experimental
1091
1162
  */
1092
- export type InspectEvent = {
1163
+ type InspectEvent = {
1093
1164
  /** `performance.now()` on the host when it happened. */
1094
1165
  at: number;
1166
+ /** The event's name, a `KernelEvents` key. */
1095
1167
  event: string;
1168
+ /** The event's data, as `kernel.on` gives it. */
1096
1169
  data: Record<string, unknown>;
1097
1170
  };
1098
1171
  /** One isolate's latest beat in a `beats` message. @experimental */
1099
- export type InspectBeat = {
1172
+ type InspectBeat = {
1173
+ /** The isolate's id. */
1100
1174
  id: string;
1175
+ /** Its pool, when it's a pool member. */
1101
1176
  pool?: string;
1177
+ /**
1178
+ * How late its worker's beat fired, past the heartbeat interval, in ms. A block shows in it only on the first beat
1179
+ * after the block ends; while it lasts, no beat arrives.
1180
+ */
1102
1181
  lagMs: number;
1182
+ /** Milliseconds its worker spent running its code during the beat's interval. */
1103
1183
  busyMs?: number;
1104
1184
  /** `performance.now()` on the host when it arrived. */
1105
1185
  at: number;
@@ -1110,34 +1190,39 @@ export type InspectBeat = {
1110
1190
  * `restarts` counts bus restarts since the kernel started.
1111
1191
  * @experimental
1112
1192
  */
1113
- export type InspectBus = {
1193
+ type InspectBus = {
1194
+ /** The bus supervisor's state, or `none`. */
1114
1195
  state: string;
1196
+ /** Bus restarts since the kernel started. */
1115
1197
  restarts: number;
1116
1198
  /** The last `bus:metrics`, once one has arrived. */
1117
1199
  metrics?: BusMetrics;
1118
1200
  };
1119
- /** What a reader gets first (ADR 0020, decision 2). @experimental */
1120
- export type InspectSnapshot = {
1201
+ /** What a reader gets first: the feed's state at one moment. @experimental */
1202
+ type InspectSnapshot = {
1121
1203
  /** `performance.now()` on the host when it was taken. */
1122
1204
  at: number;
1205
+ /** Every isolate not stopped. */
1123
1206
  isolates: InspectIsolate[];
1207
+ /** The named pools that have members. */
1124
1208
  pools: InspectPool[];
1209
+ /** The bus. */
1125
1210
  bus: InspectBus;
1126
1211
  /** The ring buffer: the last 200 events since the kernel started, oldest first. */
1127
1212
  events: InspectEvent[];
1128
1213
  };
1129
1214
  /**
1130
- * The feed's messages, in the usual envelope (ADR 0020, decision 7):
1215
+ * The feed's messages, each `{ v, t, p }`: `t` names it and `p` carries it.
1131
1216
  * - `snapshot`, on request: an isolate's `ctx.inspector.snapshot()` gets it
1132
1217
  * over its `inspect` port, as the reply to its `snapshot` call;
1133
1218
  * - `event`, a kernel event as it happens;
1134
1219
  * - `beats`, each isolate's latest beat, coalesced to about one a second;
1135
1220
  * - `metrics`, the latest `bus:metrics`, at most one a second;
1136
1221
  * - `memory`, each isolate's memory after a measurement, at most one every
1137
- * 5 s, and only where the page is cross-origin isolated (decision 4).
1222
+ * 5 s, and only where the page is cross-origin isolated.
1138
1223
  * @experimental
1139
1224
  */
1140
- export type InspectMessage = Envelope<"snapshot", InspectSnapshot> | Envelope<"event", InspectEvent> | Envelope<"beats", {
1225
+ type InspectMessage = Envelope<"snapshot", InspectSnapshot> | Envelope<"event", InspectEvent> | Envelope<"beats", {
1141
1226
  at: number;
1142
1227
  beats: InspectBeat[];
1143
1228
  }> | Envelope<"metrics", BusMetrics> | Envelope<"memory", {
@@ -1162,13 +1247,13 @@ export declare const INSPECT_COALESCE_MS = 1e3;
1162
1247
  /** The shortest time between two memory measurements (ADR 0020, decision 4). */
1163
1248
  export declare const INSPECT_MEMORY_MS = 5e3;
1164
1249
  /**
1165
- * One record from a tap or a read (ADR 0020, decision 3): its value cut to a
1166
- * 2 KB preview, with its full size.
1250
+ * One record from a tap or a read: its value cut to a 2 KB preview, with its
1251
+ * full size.
1167
1252
  * @experimental
1168
1253
  */
1169
- export type InspectRecord = RecordPreview;
1254
+ type InspectRecord = RecordPreview;
1170
1255
  /** What an isolate asks over its `inspect` port (ADR 0020, decision 6). @experimental */
1171
- export type InspectControl = "restart" | "kill" | "block";
1256
+ type InspectControl = "restart" | "kill" | "block";
1172
1257
  /**
1173
1258
  * The `inspect` port: isolate → host (ADR 0020, decision 6). Each message with
1174
1259
  * an `id` gets a `result` (`snapshot` gets a `snapshot`) with `re` set to it.
@@ -1182,7 +1267,7 @@ export type InspectControl = "restart" | "kill" | "block";
1182
1267
  * - `control`: restart, kill or block (`ms`, at most 10 s) an isolate.
1183
1268
  * @experimental
1184
1269
  */
1185
- export type IsolateToInspect = Envelope<"listen", Record<string, never>> | Envelope<"unlisten", Record<string, never>> | Envelope<"snapshot", Record<string, never>> | Envelope<"records", {
1270
+ type IsolateToInspect = Envelope<"listen", Record<string, never>> | Envelope<"unlisten", Record<string, never>> | Envelope<"snapshot", Record<string, never>> | Envelope<"records", {
1186
1271
  topic: string;
1187
1272
  last: number;
1188
1273
  }> | Envelope<"tap", {
@@ -1198,7 +1283,7 @@ export type IsolateToInspect = Envelope<"listen", Record<string, never>> | Envel
1198
1283
  * `result`, and a tap's `record` and `skipped` (with `re` naming the tap).
1199
1284
  * @experimental
1200
1285
  */
1201
- export type InspectToIsolate = InspectMessage | Envelope<"result", CallResult> | Envelope<"record", InspectRecord> | Envelope<"skipped", {
1286
+ type InspectToIsolate = InspectMessage | Envelope<"result", CallResult> | Envelope<"record", InspectRecord> | Envelope<"skipped", {
1202
1287
  count: number;
1203
1288
  }>;
1204
1289
  /** @experimental */
@@ -1208,4 +1293,5 @@ export declare const INSPECT_TO_ISOLATE: MessageTypes<InspectToIsolate>;
1208
1293
  /** @experimental */
1209
1294
  export declare const isIsolateToInspect: (x: unknown) => x is IsolateToInspect;
1210
1295
  /** @experimental */
1211
- export declare const isInspectToIsolate: (x: unknown) => x is InspectToIsolate;
1296
+ export declare const isInspectToIsolate: (x: unknown) => x is InspectToIsolate;
1297
+ export type { AnyEnvelope, BusMetrics, BusRecord, BusToHost, BusToIsolate, BusToTap, CallError, CallResult, Check, CliToPage, CommitOffsets, CommitPoint, Committer, CommitterOptions, ContractsList, DevMcpCall, DevMcpCancel, DevMcpHello, DevMcpOp, DevMcpResult, DevMcpTool, DevMcpWelcome, DurabilityDegraded, Envelope, ErrorCode, ErrorPayload, EventType, Grants, HostMethod, HostToBus, HostToIsolate, IdleReport, InitPayload, InspectBeat, InspectBus, InspectControl, InspectEvent, InspectIsolate, InspectMemory, InspectMessage, InspectPool, InspectRecord, InspectSnapshot, InspectToIsolate, IsolateToBus, IsolateToHost, IsolateToInspect, Issue, JsonSchema, JsonSchemaPair, JsonSchemaResult, MessageTypes, Mods, NotExportableReason, PageToCli, PublishId, RecordPreview, RecordReq, Rect, RequestVia, Retention, RouteValue, SchemaTypes, SeedEvent, SerializedEvent, ShutdownReason, StandardJSONSchemaV1, StartPosition, SystemSchema, SystemTopicDef, TapToBus, ToolSpec, TopicConfig, TopicJsonSchemas, TopicJsonSchemasResult, TopicRef, TopicShape, TypedRecord };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/envelope.ts
1
+ // src/messages/envelope.ts
2
2
  /** Protocol version this build speaks (`v`) and the oldest it still accepts (`min`). */
3
3
  const PROTOCOL = {
4
4
  v: 1,
@@ -27,8 +27,8 @@ function envelopeGuard(types) {
27
27
  function assertNever(x, message = "Unexpected value") {
28
28
  throw new Error(`${message}: ${JSON.stringify(x)}`);
29
29
  }
30
- // src/errors.ts
31
- /** Every error code on the wire (design §3, §4.7, §6.1, §6.3; ADRs 0002, 0003, 0007, 0008). */
30
+ // src/errors/errors.ts
31
+ /** Every error code the bus and the host answer with. */
32
32
  const ERROR_CODES = [
33
33
  "protocol_mismatch",
34
34
  "timeout",
@@ -62,7 +62,7 @@ const codes = new Set(ERROR_CODES);
62
62
  function isErrorCode(x) {
63
63
  return typeof x === "string" && codes.has(x);
64
64
  }
65
- // src/grants.ts
65
+ // src/topics/grants.ts
66
66
  /** Topics under this prefix belong to the kernel (ADR 0002). */
67
67
  const SYSTEM_TOPIC_PREFIX = "isoloop.";
68
68
  function isSystemTopic(topic) {
@@ -88,7 +88,7 @@ function matchTopic(grant, topic) {
88
88
  function matchAny(patterns, topic) {
89
89
  return patterns.some((p) => matchTopic(p, topic));
90
90
  }
91
- // src/isolate.ts
91
+ // src/messages/isolate.ts
92
92
  /** The longest `block` a runtime runs; a longer one is cut to this (ADR 0020, decision 4). */
93
93
  const MAX_BLOCK_MS = 1e4;
94
94
  const HOST_TO_ISOLATE = {
@@ -110,7 +110,7 @@ const ISOLATE_TO_HOST = {
110
110
  };
111
111
  const isHostToIsolate = envelopeGuard(HOST_TO_ISOLATE);
112
112
  const isIsolateToHost = envelopeGuard(ISOLATE_TO_HOST);
113
- // src/bus.ts
113
+ // src/messages/bus.ts
114
114
  /** Every {@link RequestVia}, for guards. @experimental */
115
115
  const REQUEST_VIA = Object.freeze([
116
116
  "mcp",
@@ -145,7 +145,7 @@ const BUS_TO_ISOLATE = {
145
145
  };
146
146
  const isIsolateToBus = envelopeGuard(ISOLATE_TO_BUS);
147
147
  const isBusToIsolate = envelopeGuard(BUS_TO_ISOLATE);
148
- // src/commits.ts
148
+ // src/topics/commits.ts
149
149
  /** `KernelConfig.bus.commitIntervalMs` when unset (ADR 0016, decision 1, point 7). */
150
150
  const DEFAULT_COMMIT_INTERVAL_MS = 100;
151
151
  /** The highest allowed interval: keeps the redelivery window after a crash under a second. */
@@ -273,14 +273,17 @@ function createCommitter(o) {
273
273
  }
274
274
  };
275
275
  }
276
- // src/bus-error.ts
276
+ // src/errors/bus-error.ts
277
277
  /**
278
278
  * A rejected bus call (`kernel.publish`, `ctx.bus.publish`, `request`,
279
279
  * `reply`): the broker's error code, and the schema issues for `invalid`.
280
280
  */
281
281
  var BusError = class extends Error {
282
+ /** What went wrong, to branch on: `invalid`, `forbidden`, `timeout`, `bus_unavailable`, … */
282
283
  code;
284
+ /** For `invalid`: where the value failed its schema, and why. */
283
285
  issues;
286
+ /** @param error The broker's error: its code, message and issues. */
284
287
  constructor(error) {
285
288
  super(error.message);
286
289
  this.name = "BusError";
@@ -288,7 +291,7 @@ var BusError = class extends Error {
288
291
  this.issues = error.issues;
289
292
  }
290
293
  };
291
- // src/control.ts
294
+ // src/messages/control.ts
292
295
  /** Longest preview of a record's value, in characters (ADR 0020, decision 3). */
293
296
  const PREVIEW_CHARS = 2048;
294
297
  /** Records a `tap` sends each second when its `maxPerSec` isn't given. */
@@ -328,7 +331,7 @@ const isBusToHost = envelopeGuard(BUS_TO_HOST);
328
331
  const isBusToTap = envelopeGuard(BUS_TO_TAP);
329
332
  /** A well-formed message from the host on a tap's port. @experimental */
330
333
  const isTapToBus = envelopeGuard(TAP_TO_BUS);
331
- // src/system-topics.ts
334
+ // src/topics/system-topics.ts
332
335
  /** Wraps a hand-written check as a Standard Schema that passes valid values through unchanged. */
333
336
  function systemSchema(check) {
334
337
  return { "~standard": {
@@ -363,7 +366,7 @@ const checks = {
363
366
  },
364
367
  any: () => []
365
368
  };
366
- // src/route.ts
369
+ // src/topics/route.ts
367
370
  const stringOrNull = (v, path) => v === null || typeof v === "string" ? [] : [{
368
371
  message: "expected a string or null",
369
372
  path
@@ -389,7 +392,7 @@ const routeTopic = systemTopic("isoloop.route.v1", {
389
392
  const ROUTE_KEY = "current";
390
393
  /** Every system topic, built into the bus. */
391
394
  const SYSTEM_TOPICS = [routeTopic];
392
- // src/topics.ts
395
+ // src/topics/topics.ts
393
396
  /**
394
397
  * The structured-cloneable part of a topic, sent at `boot` and compared with
395
398
  * the contracts module's (ADR 0003, decision 5). Host and bus both use this
@@ -409,7 +412,7 @@ function topicConfigOf(t) {
409
412
  };
410
413
  return cfg;
411
414
  }
412
- // src/version.ts
415
+ // src/messages/version.ts
413
416
  /** `"0.4.2"` → `"0.4"`. Anything that isn't `major.minor[.patch…]` gives `undefined`. */
414
417
  function majorMinor(version) {
415
418
  const m = /^(\d+)\.(\d+)(?:[.+-].*)?$/.exec(version);
@@ -427,7 +430,7 @@ function compareVersions(a, b) {
427
430
  const [bm, bn] = parse(b);
428
431
  return am - bm || an - bn;
429
432
  }
430
- // src/json-schema.ts
433
+ // src/topics/json-schema.ts
431
434
  /**
432
435
  * The vendor `unchecked()` in `@isoloop/bus` gives its schemas.
433
436
  *
@@ -532,7 +535,7 @@ function topicJsonSchemas(def) {
532
535
  reply: pair(reply)
533
536
  };
534
537
  }
535
- // src/dev-mcp.ts
538
+ // src/messages/dev-mcp.ts
536
539
  /** `DevMcpOp['op']`, as a list. @internal */
537
540
  const DEV_MCP_OPS = [
538
541
  "isolates",
@@ -576,7 +579,7 @@ const DEV_MCP_CLOSE = {
576
579
  };
577
580
  /** The CLI's WebSocket port when `--port` isn't given. @internal */
578
581
  const DEV_MCP_PORT = 4317;
579
- // src/inspect.ts
582
+ // src/messages/inspect.ts
580
583
  /** @experimental */
581
584
  const INSPECT_MESSAGES = {
582
585
  snapshot: true,
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@isoloop/protocol",
3
- "version": "0.1.0-next.8",
4
- "description": "Wire protocol types and guards shared by every Isoloop package.",
3
+ "version": "0.1.0",
4
+ "description": "Internal: Isoloop's wire protocol types and guards. Used by the @isoloop/* packages; not for app code.",
5
+ "keywords": [
6
+ "isoloop"
7
+ ],
8
+ "homepage": "https://isoloop.dev/",
5
9
  "license": "MIT",
6
10
  "type": "module",
7
11
  "sideEffects": false,