@isoloop/protocol 0.1.0-next.10 → 0.1.0-next.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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
@@ -58,20 +58,20 @@ export declare const ERROR_CODES: readonly ["protocol_mismatch", "timeout", "no_
58
58
  * - seeding: `seed_async`, `seed_pending`;
59
59
  * - the version handshake: `protocol_mismatch`.
60
60
  */
61
- export type ErrorCode = (typeof ERROR_CODES)[number];
61
+ type ErrorCode = (typeof ERROR_CODES)[number];
62
62
  export declare function isErrorCode(x: unknown): x is ErrorCode;
63
63
  /** A schema issue, as reported with `invalid`: what's wrong, and where in the value. */
64
- export type Issue = {
64
+ type Issue = {
65
65
  message: string;
66
66
  path: (string | number)[];
67
67
  };
68
- export type CallError = {
68
+ type CallError = {
69
69
  code: ErrorCode;
70
70
  message: string;
71
71
  issues?: Issue[];
72
72
  };
73
73
  /** Reply to a host call or an acknowledged publish. */
74
- export type CallResult = {
74
+ type CallResult = {
75
75
  ok: true;
76
76
  value: unknown;
77
77
  } | {
@@ -79,14 +79,14 @@ export type CallResult = {
79
79
  error: CallError;
80
80
  };
81
81
  /** Payload of an `error` envelope from an isolate or the bus worker. */
82
- export type ErrorPayload = {
82
+ type ErrorPayload = {
83
83
  message: string;
84
84
  stack?: string;
85
85
  fatal: boolean;
86
86
  code?: ErrorCode;
87
87
  };
88
88
  /** What an isolate may do on the bus and the host: `IsolateManifest.grants`. */
89
- export type Grants = {
89
+ type Grants = {
90
90
  /** Topic patterns the isolate may publish to. `*` matches one or more characters, dots included. */
91
91
  publish: string[];
92
92
  /** Topic patterns the isolate may subscribe to, the same way. */
@@ -114,7 +114,7 @@ export declare function matchTopic(grant: string, topic: string): boolean;
114
114
  /** True if any pattern in the list matches `topic`. */
115
115
  export declare function matchAny(patterns: readonly string[], topic: string): boolean;
116
116
  /** Modifier keys held during an event. */
117
- export type Mods = {
117
+ type Mods = {
118
118
  alt: boolean;
119
119
  ctrl: boolean;
120
120
  meta: boolean;
@@ -125,9 +125,9 @@ export type Mods = {
125
125
  * canvases (§4.7). `pointermove` and `scroll` are opt-in per node and come at
126
126
  * most once a frame.
127
127
  */
128
- 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";
129
129
  /** A DOM event as it reaches an isolate (design §4.6). Node ids are the isolate's own. */
130
- export type SerializedEvent = {
130
+ type SerializedEvent = {
131
131
  type: EventType;
132
132
  target: string;
133
133
  /** The target and its ancestors that have a listener, innermost first. */
@@ -148,18 +148,18 @@ export type SerializedEvent = {
148
148
  scrollLeft?: number;
149
149
  };
150
150
  /** Why the host asks an isolate to shut down. `suspend` keeps its offsets, to replay what it missed on waking. */
151
- export type ShutdownReason = "stop" | "restart" | "suspend";
151
+ type ShutdownReason = "stop" | "restart" | "suspend";
152
152
  /** Calls an isolate can make to the host (design §4.7). */
153
- export type HostMethod = "measure" | "focus" | "navigate" | "scrollIntoView" | "requestCanvas";
153
+ type HostMethod = "measure" | "focus" | "navigate" | "scrollIntoView" | "requestCanvas";
154
154
  /** What `measure` returns: a node's box relative to its surface, in CSS pixels. */
155
- export type Rect = {
155
+ type Rect = {
156
156
  x: number;
157
157
  y: number;
158
158
  width: number;
159
159
  height: number;
160
160
  };
161
161
  /** First message to an isolate. The host's half of the version handshake. */
162
- export type InitPayload = {
162
+ type InitPayload = {
163
163
  isolateId: string;
164
164
  /** Protocol versions the host accepts. */
165
165
  protocol: {
@@ -185,7 +185,7 @@ export type InitPayload = {
185
185
  commitIntervalMs?: number;
186
186
  };
187
187
  /** What a beat says about whether the isolate could be suspended (ADR 0001). */
188
- export type IdleReport = {
188
+ type IdleReport = {
189
189
  /** Time since the bus last delivered a record to this isolate. */
190
190
  sinceDeliveryMs: number;
191
191
  /** Host calls, publishes and requests waiting for an answer. */
@@ -208,7 +208,7 @@ export type IdleReport = {
208
208
  /** The longest `block` a runtime runs; a longer one is cut to this (ADR 0020, decision 4). */
209
209
  export declare const MAX_BLOCK_MS = 1e4;
210
210
  /** Isolate port: host → isolate. */
211
- 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", {
212
212
  reason: ShutdownReason;
213
213
  graceMs: number;
214
214
  }> | Envelope<"reattach", {
@@ -219,7 +219,7 @@ export type HostToIsolate = Envelope<"init", InitPayload> | Envelope<"event", Se
219
219
  port: MessagePort;
220
220
  }>;
221
221
  /** Isolate port: isolate → host. */
222
- export type IsolateToHost = Envelope<"ready", {
222
+ type IsolateToHost = Envelope<"ready", {
223
223
  runtime: string;
224
224
  adapter: string;
225
225
  renderFmt: string;
@@ -251,7 +251,7 @@ export declare const ISOLATE_TO_HOST: MessageTypes<IsolateToHost>;
251
251
  export declare const isHostToIsolate: (x: unknown) => x is HostToIsolate;
252
252
  export declare const isIsolateToHost: (x: unknown) => x is IsolateToHost;
253
253
  /** One record in a topic's log. */
254
- export type BusRecord = {
254
+ type BusRecord = {
255
255
  /** Its place in the topic's log, from 0. */
256
256
  offset: number;
257
257
  /** The key it was published with, if any. */
@@ -278,13 +278,13 @@ export type BusRecord = {
278
278
  * cooperating code on one page. Never authorize anything by it.
279
279
  * @experimental
280
280
  */
281
- export type RequestVia = "mcp" | "webmcp" | "builder";
281
+ type RequestVia = "mcp" | "webmcp" | "builder";
282
282
  /** Every {@link RequestVia}, for guards. @experimental */
283
283
  export declare const REQUEST_VIA: readonly RequestVia[];
284
284
  /** True for a known {@link RequestVia}. @experimental */
285
285
  export declare function isRequestVia(x: unknown): x is RequestVia;
286
286
  /** `BusRecord.req`: who asked, under which request id, and through which transport. */
287
- export type RecordReq = {
287
+ type RecordReq = {
288
288
  from: string;
289
289
  id: string;
290
290
  via?: RequestVia;
@@ -301,7 +301,7 @@ export declare function isRecordReq(x: unknown): x is RecordReq;
301
301
  * publishes and requests. The bus answers a re-send it already holds with the
302
302
  * original offset. Memory topics ignore it.
303
303
  */
304
- export type PublishId = {
304
+ type PublishId = {
305
305
  epoch?: number;
306
306
  seq?: number;
307
307
  };
@@ -311,9 +311,9 @@ export type PublishId = {
311
311
  * after the last record this subscriber committed, or the oldest retained
312
312
  * when it has committed none.
313
313
  */
314
- export type StartPosition = "latest" | "earliest" | "committed";
314
+ type StartPosition = "latest" | "earliest" | "committed";
315
315
  /** Bus port: isolate → bus worker. */
316
- export type IsolateToBus = Envelope<"publish", {
316
+ type IsolateToBus = Envelope<"publish", {
317
317
  topic: string;
318
318
  key?: string;
319
319
  value: unknown;
@@ -341,7 +341,7 @@ export type IsolateToBus = Envelope<"publish", {
341
341
  value: unknown;
342
342
  }>;
343
343
  /** Bus port: bus worker → isolate. */
344
- export type BusToIsolate = Envelope<"deliver", {
344
+ type BusToIsolate = Envelope<"deliver", {
345
345
  topic: string;
346
346
  records: BusRecord[];
347
347
  gap?: {
@@ -370,12 +370,12 @@ export declare function commitIntervalProblem(ms: unknown): string | undefined;
370
370
  * delivery `seq` settled whole (ADR 0016, point 11), and how many records of
371
371
  * delivery `seq + 1` are settled, when some are (point 17).
372
372
  */
373
- export type CommitPoint = {
373
+ type CommitPoint = {
374
374
  offset: number;
375
375
  seq: number;
376
376
  partial?: number;
377
377
  };
378
- export type CommitOffsets = ({
378
+ type CommitOffsets = ({
379
379
  topic: string;
380
380
  } & CommitPoint)[];
381
381
  /**
@@ -390,7 +390,7 @@ export type CommitOffsets = ({
390
390
  * also reaches every offset in it.
391
391
  */
392
392
  export declare function deliveryPoints(seq: number, offsets: readonly number[], highest: number): CommitPoint[];
393
- export type CommitterOptions = {
393
+ type CommitterOptions = {
394
394
  /** Sends one `commits` message. Called with at least one entry. */
395
395
  send: (offsets: CommitOffsets) => void;
396
396
  /** 0: at the end of each task that settled a record. Default 100. */
@@ -398,7 +398,7 @@ export type CommitterOptions = {
398
398
  /** The broker's credit per subscription; a subscription sends early at half of it. Default 1,000. */
399
399
  credit?: number;
400
400
  };
401
- export type Committer = {
401
+ type Committer = {
402
402
  /**
403
403
  * `records` records of `topic` are settled (default one): everything up to
404
404
  * `at.offset`, and every delivery up to `at.seq` whole. Each is kept as the
@@ -438,7 +438,7 @@ export declare class BusError extends Error {
438
438
  * records younger than `ms` by their `ts`; `compacted`, the latest record per
439
439
  * key.
440
440
  */
441
- export type Retention = {
441
+ type Retention = {
442
442
  kind: "last-n";
443
443
  /** How many records to keep, a positive integer. */
444
444
  n: number;
@@ -453,7 +453,7 @@ export type Retention = {
453
453
  * The structured-cloneable part of a topic definition: what the host sends at
454
454
  * `boot` so the bus worker can check it against the contracts module (ADR 0003).
455
455
  */
456
- export type TopicConfig = {
456
+ type TopicConfig = {
457
457
  name: string;
458
458
  retention: Retention;
459
459
  /** Default 256 KiB. */
@@ -469,14 +469,14 @@ export type TopicConfig = {
469
469
  };
470
470
  };
471
471
  /** Why persistent topics run in memory (`bus:durability_degraded`). */
472
- export type DurabilityDegraded = "another_tab" | "no_sync_access" | "open_failed";
472
+ type DurabilityDegraded = "another_tab" | "no_sync_access" | "open_failed";
473
473
  /**
474
474
  * Seeding news (ADR 0003, decision 18). `rejected`: a source record `map`
475
475
  * threw on, returned a promise for (`seed_async`), or the topic's schema
476
476
  * rejected; it was skipped and stays in `from`. `seeded`: the seed ended and
477
477
  * the topic opened.
478
478
  */
479
- export type SeedEvent = {
479
+ type SeedEvent = {
480
480
  kind: "rejected";
481
481
  topic: string;
482
482
  from: string;
@@ -490,7 +490,7 @@ export type SeedEvent = {
490
490
  rejected: number;
491
491
  };
492
492
  /** The bus's figures, sampled every second: `bus:metrics`. */
493
- export type BusMetrics = {
493
+ type BusMetrics = {
494
494
  /**
495
495
  * Per topic: records and bytes a second; `head`, the next offset to be
496
496
  * written; and `retained`, how many records the topic still holds.
@@ -531,7 +531,7 @@ export declare const MAX_READ = 100;
531
531
  * characters, with the value's estimated size in bytes.
532
532
  * @experimental
533
533
  */
534
- export type RecordPreview = {
534
+ type RecordPreview = {
535
535
  /** The topic's name. */
536
536
  topic: string;
537
537
  /** Its place in the topic's log. */
@@ -556,13 +556,13 @@ export type RecordPreview = {
556
556
  * `maxPerSec` since the last `skipped`, sent at most once a second.
557
557
  * @experimental
558
558
  */
559
- export type BusToTap = Envelope<"record", RecordPreview> | Envelope<"skipped", {
559
+ type BusToTap = Envelope<"record", RecordPreview> | Envelope<"skipped", {
560
560
  count: number;
561
561
  }>;
562
562
  /** A tap's port: host → bus. `close` ends the tap. @experimental */
563
- export type TapToBus = Envelope<"close", Record<string, never>>;
563
+ type TapToBus = Envelope<"close", Record<string, never>>;
564
564
  /** Control port: host → bus worker. */
565
- export type HostToBus = Envelope<"boot", {
565
+ type HostToBus = Envelope<"boot", {
566
566
  contractsUrl: string;
567
567
  topics: TopicConfig[];
568
568
  heartbeatMs?: number;
@@ -605,7 +605,7 @@ export type HostToBus = Envelope<"boot", {
605
605
  last: number;
606
606
  }>;
607
607
  /** Control port: bus worker → host. */
608
- export type BusToHost = Envelope<"ready", {
608
+ type BusToHost = Envelope<"ready", {
609
609
  engine: string;
610
610
  storage: "memory" | "opfs";
611
611
  restored: {
@@ -651,7 +651,7 @@ export declare const isTapToBus: (x: unknown) => x is TapToBus;
651
651
  * on nothing, so this is the structural subset of the interface that system
652
652
  * topics need; it is assignable to the bus's vendored `StandardSchemaV1`.
653
653
  */
654
- export type SystemSchema<T> = {
654
+ type SystemSchema<T> = {
655
655
  readonly "~standard": {
656
656
  readonly version: 1;
657
657
  readonly vendor: "isoloop";
@@ -668,7 +668,7 @@ export type SystemSchema<T> = {
668
668
  };
669
669
  };
670
670
  /** A kernel-owned `isoloop.*` topic: same shape as a bus `TopicDef`. */
671
- export type SystemTopicDef<T> = {
671
+ type SystemTopicDef<T> = {
672
672
  readonly name: string;
673
673
  readonly schema: SystemSchema<T>;
674
674
  readonly retention: Retention;
@@ -678,7 +678,7 @@ export type SystemTopicDef<T> = {
678
678
  * A check that returns the issues found in `value`, or none. `path` is where
679
679
  * `value` sits, so nested checks can report full paths.
680
680
  */
681
- export type Check = (value: unknown, path: (string | number)[]) => Issue[];
681
+ type Check = (value: unknown, path: (string | number)[]) => Issue[];
682
682
  /** Wraps a hand-written check as a Standard Schema that passes valid values through unchanged. */
683
683
  export declare function systemSchema<T>(check: Check): SystemSchema<T>;
684
684
  /** Defines a system topic. The name must start with `isoloop.`. */
@@ -693,7 +693,7 @@ export declare const checks: {
693
693
  any: Check;
694
694
  };
695
695
  /** The host page's current location, as the kernel publishes it on each navigation. */
696
- export type RouteValue = {
696
+ type RouteValue = {
697
697
  /** The absolute URL. */
698
698
  href: string;
699
699
  /** The URL's path, as `location.pathname` has it. */
@@ -722,7 +722,7 @@ export declare const SYSTEM_TOPICS: readonly SystemTopicDef<any>[];
722
722
  * A topic as `kernel.publish`, `kernel.subscribe` and `BusClient` take it:
723
723
  * any `topic()` from `@isoloop/bus` fits, and its schema types carry over.
724
724
  */
725
- export type TopicRef<In = unknown, Out = In, RIn = never, ROut = RIn> = {
725
+ type TopicRef<In = unknown, Out = In, RIn = never, ROut = RIn> = {
726
726
  /** The topic's name. */
727
727
  readonly name: string;
728
728
  /** Its schema's types. */
@@ -731,7 +731,7 @@ export type TopicRef<In = unknown, Out = In, RIn = never, ROut = RIn> = {
731
731
  readonly reply?: SchemaTypes<RIn, ROut>;
732
732
  };
733
733
  /** The type-only part of a Standard Schema V1. */
734
- export type SchemaTypes<In, Out> = {
734
+ type SchemaTypes<In, Out> = {
735
735
  readonly "~standard": {
736
736
  readonly types?: {
737
737
  readonly input: In;
@@ -740,7 +740,7 @@ export type SchemaTypes<In, Out> = {
740
740
  };
741
741
  };
742
742
  /** A record whose value has the topic's output type. */
743
- export type TypedRecord<T> = Omit<BusRecord, "value"> & {
743
+ type TypedRecord<T> = Omit<BusRecord, "value"> & {
744
744
  value: T;
745
745
  };
746
746
  /**
@@ -750,7 +750,7 @@ export type TypedRecord<T> = Omit<BusRecord, "value"> & {
750
750
  * the `TopicConfig` the bus sees.
751
751
  * @experimental
752
752
  */
753
- export type ToolSpec = {
753
+ type ToolSpec = {
754
754
  /** A short human-readable name. The tool's name is always the topic's name. */
755
755
  readonly title?: string;
756
756
  /** What the tool does, for the agent choosing it. */
@@ -763,7 +763,7 @@ export type ToolSpec = {
763
763
  readonly untrustedContent?: boolean;
764
764
  };
765
765
  /** A topic as the host reads it from the contracts: any `topic()` from `@isoloop/bus` fits. */
766
- export type TopicShape = {
766
+ type TopicShape = {
767
767
  /** The topic's name. */
768
768
  readonly name: string;
769
769
  /**
@@ -790,7 +790,7 @@ export type TopicShape = {
790
790
  readonly tool?: ToolSpec;
791
791
  };
792
792
  /** What `KernelConfig.contracts.list` holds: a `contracts()` list, seen structurally. */
793
- export type ContractsList = {
793
+ type ContractsList = {
794
794
  readonly topics: readonly TopicShape[];
795
795
  };
796
796
  /**
@@ -818,11 +818,11 @@ export declare const UNCHECKED_VENDOR = "isoloop/unchecked";
818
818
  *
819
819
  * @internal
820
820
  */
821
- export interface StandardJSONSchemaV1 {
821
+ interface StandardJSONSchemaV1 {
822
822
  readonly "~standard": StandardJSONSchemaV1.Props;
823
823
  }
824
824
  /** @internal */
825
- export declare namespace StandardJSONSchemaV1 {
825
+ declare namespace StandardJSONSchemaV1 {
826
826
  export interface Props<Input = unknown, Output = Input> {
827
827
  readonly version: 1;
828
828
  readonly vendor: string;
@@ -850,7 +850,7 @@ export declare namespace StandardJSONSchemaV1 {
850
850
  *
851
851
  * @internal
852
852
  */
853
- export type JsonSchema = {
853
+ type JsonSchema = {
854
854
  [key: string]: unknown;
855
855
  };
856
856
  /**
@@ -859,7 +859,7 @@ export type JsonSchema = {
859
859
  *
860
860
  * @internal
861
861
  */
862
- export type JsonSchemaPair = {
862
+ type JsonSchemaPair = {
863
863
  readonly input: JsonSchema;
864
864
  readonly output: JsonSchema;
865
865
  };
@@ -872,13 +872,13 @@ export type JsonSchemaPair = {
872
872
  *
873
873
  * @internal
874
874
  */
875
- export type NotExportableReason = "unchecked" | "unsupported" | "failed";
875
+ type NotExportableReason = "unchecked" | "unsupported" | "failed";
876
876
  /**
877
877
  * The result of {@link jsonSchemaOf}. Never throws; a failure is a value.
878
878
  *
879
879
  * @internal
880
880
  */
881
- export type JsonSchemaResult = ({
881
+ type JsonSchemaResult = ({
882
882
  readonly ok: true;
883
883
  } & JsonSchemaPair) | {
884
884
  readonly ok: false;
@@ -912,7 +912,7 @@ export declare function jsonSchemaOf(schema: unknown): JsonSchemaResult;
912
912
  *
913
913
  * @internal
914
914
  */
915
- export type TopicJsonSchemas = {
915
+ type TopicJsonSchemas = {
916
916
  readonly schema: JsonSchemaPair;
917
917
  readonly reply?: JsonSchemaPair;
918
918
  };
@@ -921,7 +921,7 @@ export type TopicJsonSchemas = {
921
921
  *
922
922
  * @internal
923
923
  */
924
- export type TopicJsonSchemasResult = ({
924
+ type TopicJsonSchemasResult = ({
925
925
  readonly ok: true;
926
926
  } & TopicJsonSchemas) | {
927
927
  readonly ok: false;
@@ -947,7 +947,7 @@ export declare function topicJsonSchemas(def: {
947
947
  * An exposed tool as the page sends it: `kernel.tools()` without `topic`.
948
948
  * @internal
949
949
  */
950
- export type DevMcpTool = {
950
+ type DevMcpTool = {
951
951
  readonly name: string;
952
952
  readonly title?: string;
953
953
  readonly description: string;
@@ -963,7 +963,7 @@ export type DevMcpTool = {
963
963
  readonly timeoutMs: number;
964
964
  };
965
965
  /** A call's answer: the reply, or the error's code and message. @internal */
966
- export type DevMcpResult = {
966
+ type DevMcpResult = {
967
967
  readonly ok: true;
968
968
  readonly value: unknown;
969
969
  } | {
@@ -974,7 +974,7 @@ export type DevMcpResult = {
974
974
  readonly issues?: readonly Issue[];
975
975
  };
976
976
  /** `hello`'s payload: the pairing token, the page's URL and title, and its tools. @internal */
977
- export type DevMcpHello = {
977
+ type DevMcpHello = {
978
978
  readonly token: string;
979
979
  readonly url: string;
980
980
  readonly title?: string;
@@ -987,11 +987,11 @@ export type DevMcpHello = {
987
987
  readonly inspect?: boolean;
988
988
  };
989
989
  /** `welcome`'s payload: the page's id, which agents pass as `page`. @internal */
990
- export type DevMcpWelcome = {
990
+ type DevMcpWelcome = {
991
991
  readonly page: string;
992
992
  };
993
993
  /** `call`'s payload: the tool to request and its input. @internal */
994
- export type DevMcpCall = {
994
+ type DevMcpCall = {
995
995
  readonly name: string;
996
996
  readonly input: unknown;
997
997
  };
@@ -999,14 +999,14 @@ export type DevMcpCall = {
999
999
  * Page → CLI: `hello` first, then a `result` per call (`re` = the call's `id`).
1000
1000
  * @internal
1001
1001
  */
1002
- export type PageToCli = Envelope<"hello", DevMcpHello> | Envelope<"result", DevMcpResult>;
1002
+ type PageToCli = Envelope<"hello", DevMcpHello> | Envelope<"result", DevMcpResult>;
1003
1003
  /**
1004
1004
  * CLI → page: `welcome` once paired; `call` (an app tool) or `op` (one of the
1005
1005
  * dev MCP's own tools), each with an `id`; `cancel`, `re` = a call's `id`,
1006
1006
  * when the agent cancelled it (the page aborts its signal).
1007
1007
  * @internal
1008
1008
  */
1009
- 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>;
1010
1010
  /**
1011
1011
  * `op`'s payload: one of the dev MCP's own tools, answered by the page from
1012
1012
  * `kernel.inspect()` (ADR 0020) or the kernel (M4a decision 12). The page
@@ -1014,7 +1014,7 @@ export type CliToPage = Envelope<"welcome", DevMcpWelcome> | Envelope<"call", De
1014
1014
  * `kill`, `block`, `publish`, `request`) are sent only with `--allow-write`.
1015
1015
  * @internal
1016
1016
  */
1017
- export type DevMcpOp = {
1017
+ type DevMcpOp = {
1018
1018
  readonly op: "isolates";
1019
1019
  } | {
1020
1020
  readonly op: "topics";
@@ -1052,7 +1052,7 @@ export type DevMcpOp = {
1052
1052
  /** `DevMcpOp['op']`, as a list. @internal */
1053
1053
  export declare const DEV_MCP_OPS: readonly DevMcpOp["op"][];
1054
1054
  /** `cancel`'s payload: empty. @internal */
1055
- export type DevMcpCancel = Record<string, never>;
1055
+ type DevMcpCancel = Record<string, never>;
1056
1056
  /** @internal */
1057
1057
  export declare const PAGE_TO_CLI: MessageTypes<PageToCli>;
1058
1058
  /** @internal */
@@ -1082,7 +1082,7 @@ export declare const DEV_MCP_PORT = 4317;
1082
1082
  * a newer kernel's values.
1083
1083
  * @experimental
1084
1084
  */
1085
- export type InspectIsolate = {
1085
+ type InspectIsolate = {
1086
1086
  /** The isolate's id. */
1087
1087
  id: string;
1088
1088
  /** Its `IsolateState`. */
@@ -1129,7 +1129,7 @@ export type InspectIsolate = {
1129
1129
  * labels it "Chromium, cross-origin isolated".
1130
1130
  * @experimental
1131
1131
  */
1132
- export type InspectMemory = {
1132
+ type InspectMemory = {
1133
1133
  /** The bytes the browser attributes to the worker. */
1134
1134
  bytes: number;
1135
1135
  /** `performance.now()` on the host when the measurement came back. */
@@ -1138,7 +1138,7 @@ export type InspectMemory = {
1138
1138
  shared?: true;
1139
1139
  };
1140
1140
  /** One pool in the feed, as `kernel.pools()` has it. @experimental */
1141
- export type InspectPool = {
1141
+ type InspectPool = {
1142
1142
  /** The pool's name. */
1143
1143
  name: string;
1144
1144
  /** Isolates naming this pool, not stopped, in spawn order. */
@@ -1157,7 +1157,7 @@ export type InspectPool = {
1157
1157
  * and `data` its payload. Beats and bus metrics come as their own messages.
1158
1158
  * @experimental
1159
1159
  */
1160
- export type InspectEvent = {
1160
+ type InspectEvent = {
1161
1161
  /** `performance.now()` on the host when it happened. */
1162
1162
  at: number;
1163
1163
  /** The event's name, a `KernelEvents` key. */
@@ -1166,7 +1166,7 @@ export type InspectEvent = {
1166
1166
  data: Record<string, unknown>;
1167
1167
  };
1168
1168
  /** One isolate's latest beat in a `beats` message. @experimental */
1169
- export type InspectBeat = {
1169
+ type InspectBeat = {
1170
1170
  /** The isolate's id. */
1171
1171
  id: string;
1172
1172
  /** Its pool, when it's a pool member. */
@@ -1184,7 +1184,7 @@ export type InspectBeat = {
1184
1184
  * `restarts` counts bus restarts since the kernel started.
1185
1185
  * @experimental
1186
1186
  */
1187
- export type InspectBus = {
1187
+ type InspectBus = {
1188
1188
  /** The bus supervisor's state, or `none`. */
1189
1189
  state: string;
1190
1190
  /** Bus restarts since the kernel started. */
@@ -1193,7 +1193,7 @@ export type InspectBus = {
1193
1193
  metrics?: BusMetrics;
1194
1194
  };
1195
1195
  /** What a reader gets first: the feed's state at one moment. @experimental */
1196
- export type InspectSnapshot = {
1196
+ type InspectSnapshot = {
1197
1197
  /** `performance.now()` on the host when it was taken. */
1198
1198
  at: number;
1199
1199
  /** Every isolate not stopped. */
@@ -1216,7 +1216,7 @@ export type InspectSnapshot = {
1216
1216
  * 5 s, and only where the page is cross-origin isolated.
1217
1217
  * @experimental
1218
1218
  */
1219
- export type InspectMessage = Envelope<"snapshot", InspectSnapshot> | Envelope<"event", InspectEvent> | Envelope<"beats", {
1219
+ type InspectMessage = Envelope<"snapshot", InspectSnapshot> | Envelope<"event", InspectEvent> | Envelope<"beats", {
1220
1220
  at: number;
1221
1221
  beats: InspectBeat[];
1222
1222
  }> | Envelope<"metrics", BusMetrics> | Envelope<"memory", {
@@ -1245,9 +1245,9 @@ export declare const INSPECT_MEMORY_MS = 5e3;
1245
1245
  * full size.
1246
1246
  * @experimental
1247
1247
  */
1248
- export type InspectRecord = RecordPreview;
1248
+ type InspectRecord = RecordPreview;
1249
1249
  /** What an isolate asks over its `inspect` port (ADR 0020, decision 6). @experimental */
1250
- export type InspectControl = "restart" | "kill" | "block";
1250
+ type InspectControl = "restart" | "kill" | "block";
1251
1251
  /**
1252
1252
  * The `inspect` port: isolate → host (ADR 0020, decision 6). Each message with
1253
1253
  * an `id` gets a `result` (`snapshot` gets a `snapshot`) with `re` set to it.
@@ -1261,7 +1261,7 @@ export type InspectControl = "restart" | "kill" | "block";
1261
1261
  * - `control`: restart, kill or block (`ms`, at most 10 s) an isolate.
1262
1262
  * @experimental
1263
1263
  */
1264
- export type IsolateToInspect = Envelope<"listen", Record<string, never>> | Envelope<"unlisten", Record<string, never>> | Envelope<"snapshot", Record<string, never>> | Envelope<"records", {
1264
+ type IsolateToInspect = Envelope<"listen", Record<string, never>> | Envelope<"unlisten", Record<string, never>> | Envelope<"snapshot", Record<string, never>> | Envelope<"records", {
1265
1265
  topic: string;
1266
1266
  last: number;
1267
1267
  }> | Envelope<"tap", {
@@ -1277,7 +1277,7 @@ export type IsolateToInspect = Envelope<"listen", Record<string, never>> | Envel
1277
1277
  * `result`, and a tap's `record` and `skipped` (with `re` naming the tap).
1278
1278
  * @experimental
1279
1279
  */
1280
- export type InspectToIsolate = InspectMessage | Envelope<"result", CallResult> | Envelope<"record", InspectRecord> | Envelope<"skipped", {
1280
+ type InspectToIsolate = InspectMessage | Envelope<"result", CallResult> | Envelope<"record", InspectRecord> | Envelope<"skipped", {
1281
1281
  count: number;
1282
1282
  }>;
1283
1283
  /** @experimental */
@@ -1287,4 +1287,5 @@ export declare const INSPECT_TO_ISOLATE: MessageTypes<InspectToIsolate>;
1287
1287
  /** @experimental */
1288
1288
  export declare const isIsolateToInspect: (x: unknown) => x is IsolateToInspect;
1289
1289
  /** @experimental */
1290
- export declare const isInspectToIsolate: (x: unknown) => x is InspectToIsolate;
1290
+ export declare const isInspectToIsolate: (x: unknown) => x is InspectToIsolate;
1291
+ 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,7 +27,7 @@ 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
30
+ // src/errors/errors.ts
31
31
  /** Every error code the bus and the host answer with. */
32
32
  const ERROR_CODES = [
33
33
  "protocol_mismatch",
@@ -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,7 +273,7 @@ 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`.
@@ -291,7 +291,7 @@ var BusError = class extends Error {
291
291
  this.issues = error.issues;
292
292
  }
293
293
  };
294
- // src/control.ts
294
+ // src/messages/control.ts
295
295
  /** Longest preview of a record's value, in characters (ADR 0020, decision 3). */
296
296
  const PREVIEW_CHARS = 2048;
297
297
  /** Records a `tap` sends each second when its `maxPerSec` isn't given. */
@@ -331,7 +331,7 @@ const isBusToHost = envelopeGuard(BUS_TO_HOST);
331
331
  const isBusToTap = envelopeGuard(BUS_TO_TAP);
332
332
  /** A well-formed message from the host on a tap's port. @experimental */
333
333
  const isTapToBus = envelopeGuard(TAP_TO_BUS);
334
- // src/system-topics.ts
334
+ // src/topics/system-topics.ts
335
335
  /** Wraps a hand-written check as a Standard Schema that passes valid values through unchanged. */
336
336
  function systemSchema(check) {
337
337
  return { "~standard": {
@@ -366,7 +366,7 @@ const checks = {
366
366
  },
367
367
  any: () => []
368
368
  };
369
- // src/route.ts
369
+ // src/topics/route.ts
370
370
  const stringOrNull = (v, path) => v === null || typeof v === "string" ? [] : [{
371
371
  message: "expected a string or null",
372
372
  path
@@ -392,7 +392,7 @@ const routeTopic = systemTopic("isoloop.route.v1", {
392
392
  const ROUTE_KEY = "current";
393
393
  /** Every system topic, built into the bus. */
394
394
  const SYSTEM_TOPICS = [routeTopic];
395
- // src/topics.ts
395
+ // src/topics/topics.ts
396
396
  /**
397
397
  * The structured-cloneable part of a topic, sent at `boot` and compared with
398
398
  * the contracts module's (ADR 0003, decision 5). Host and bus both use this
@@ -412,7 +412,7 @@ function topicConfigOf(t) {
412
412
  };
413
413
  return cfg;
414
414
  }
415
- // src/version.ts
415
+ // src/messages/version.ts
416
416
  /** `"0.4.2"` → `"0.4"`. Anything that isn't `major.minor[.patch…]` gives `undefined`. */
417
417
  function majorMinor(version) {
418
418
  const m = /^(\d+)\.(\d+)(?:[.+-].*)?$/.exec(version);
@@ -430,7 +430,7 @@ function compareVersions(a, b) {
430
430
  const [bm, bn] = parse(b);
431
431
  return am - bm || an - bn;
432
432
  }
433
- // src/json-schema.ts
433
+ // src/topics/json-schema.ts
434
434
  /**
435
435
  * The vendor `unchecked()` in `@isoloop/bus` gives its schemas.
436
436
  *
@@ -535,7 +535,7 @@ function topicJsonSchemas(def) {
535
535
  reply: pair(reply)
536
536
  };
537
537
  }
538
- // src/dev-mcp.ts
538
+ // src/messages/dev-mcp.ts
539
539
  /** `DevMcpOp['op']`, as a list. @internal */
540
540
  const DEV_MCP_OPS = [
541
541
  "isolates",
@@ -579,7 +579,7 @@ const DEV_MCP_CLOSE = {
579
579
  };
580
580
  /** The CLI's WebSocket port when `--port` isn't given. @internal */
581
581
  const DEV_MCP_PORT = 4317;
582
- // src/inspect.ts
582
+ // src/messages/inspect.ts
583
583
  /** @experimental */
584
584
  const INSPECT_MESSAGES = {
585
585
  snapshot: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoloop/protocol",
3
- "version": "0.1.0-next.10",
3
+ "version": "0.1.0-next.11",
4
4
  "description": "Internal: Isoloop's wire protocol types and guards. Used by the @isoloop/* packages; not for app code.",
5
5
  "license": "MIT",
6
6
  "type": "module",