@linxiraos/pi-wire 1.5.1 → 1.5.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.
@@ -27,7 +27,7 @@ export declare const TSP_DEFAULT_CREDITS = 2;
27
27
  /** One-letter message verb. */
28
28
  export type TspVerb = "q" | "o" | "f" | "b" | "x" | "r" | "e";
29
29
  /** Every component kind in the v1 vocabulary. */
30
- export declare const TSP_KINDS: readonly ["col", "row", "card", "section", "rule", "spacer", "text", "md", "code", "diff", "ansi", "math", "image", "media", "kv", "table", "tree", "json", "badge", "kbd", "icon", "spinner", "shimmer", "elapsed", "progress", "rate", "list", "item", "tabs", "editor", "input", "button", "status", "seg", "overlay", "toast", "rows", "picker", "prefs", "tool", "checklist", "agent", "chart", "meter", "effort", "shell"];
30
+ export declare const TSP_KINDS: readonly ["col", "row", "card", "section", "rule", "spacer", "text", "md", "code", "diff", "ansi", "math", "image", "media", "web", "kv", "table", "tree", "json", "badge", "kbd", "icon", "spinner", "shimmer", "elapsed", "progress", "rate", "list", "item", "tabs", "editor", "input", "button", "buttons", "menu", "doc", "status", "seg", "overlay", "toast", "rows", "picker", "prefs", "tool", "checklist", "agent", "chart", "meter", "effort", "shell"];
31
31
  export type TspKind = (typeof TSP_KINDS)[number];
32
32
  /** Semantic colour of a node's chrome. */
33
33
  export type TspTone = "neutral" | "accent" | "info" | "success" | "warning" | "error" | "pending" | "muted" | "user";
@@ -65,6 +65,21 @@ export type TspText = string | readonly TspSpan[];
65
65
  * beside it) large in the terminal's viewer; it is an image's click by default.
66
66
  */
67
67
  export type TspAction = "toggle" | "copy" | "open" | "zoom" | "select" | "activate" | (string & {});
68
+ /**
69
+ * One entry of `actions.menu` or `actions.hold`: an action name (labeled from it), `"-"` a separator, a dim
70
+ * `{ header }`, or a row running action `id`, with its `label`, `icon` and `detail` (the hold menu shows it dim
71
+ * at the row's end).
72
+ */
73
+ export type TspMenuEntry = TspAction | {
74
+ header: string;
75
+ } | {
76
+ id: TspAction;
77
+ label?: string;
78
+ icon?: string;
79
+ detail?: string;
80
+ disabled?: boolean | string;
81
+ danger?: boolean;
82
+ };
68
83
  /** Props every node accepts. */
69
84
  export interface TspCommonProps {
70
85
  role?: string;
@@ -82,10 +97,15 @@ export interface TspCommonProps {
82
97
  w?: TspExtent;
83
98
  h?: TspExtent;
84
99
  };
100
+ /**
101
+ * What a pointer does: `menu` lists what a right-click offers; `hold` what a long press on a touch screen
102
+ * offers (a phone's hold menu over the lifted node), which a desktop ignores.
103
+ */
85
104
  actions?: {
86
105
  click?: TspAction;
87
106
  dblclick?: TspAction;
88
- menu?: readonly TspAction[];
107
+ menu?: readonly TspMenuEntry[];
108
+ hold?: readonly TspMenuEntry[];
89
109
  };
90
110
  title?: string;
91
111
  /** Accessible name for icon-only or visual-only nodes. */
@@ -169,6 +189,34 @@ export interface TspMarkdownProps {
169
189
  /** Literal runs drawn as these spans wherever they occur in prose (a sent prompt's chip tokens). */
170
190
  marks?: readonly TspSpan[];
171
191
  }
192
+ /** A comment drawn on a {@link TspDocProps} document, anchored to a quote of its source. */
193
+ export interface TspDocComment {
194
+ /** The program's comment id; `comment`/`uncomment` events name it. */
195
+ id: string;
196
+ /** The commented source text. */
197
+ quote: string;
198
+ /** UTF-16 offset of the quote's first char in `text`; the first occurrence of `quote` when it doesn't match there. */
199
+ at?: number;
200
+ note: string;
201
+ }
202
+ /**
203
+ * A rich Markdown document the user reads, selects, edits in place (double-click, `edit`) and comments on
204
+ * (`comment`): edits arrive as `change` events with the full source, comments as `comment`/`uncomment`.
205
+ */
206
+ export interface TspDocProps {
207
+ /** Markdown source in omp's dialect; the document's own current source is a no-op. */
208
+ text?: string;
209
+ /** Double-click enters in-place editing; Esc or a press outside leaves it. */
210
+ edit?: boolean;
211
+ /** A still, non-empty selection offers a Comment bubble. */
212
+ comment?: boolean;
213
+ comments?: readonly TspDocComment[];
214
+ /** Scroll heading number `heading` (0-based, document order, all levels) to the top; each new `n` scrolls again. */
215
+ jump?: {
216
+ heading: number;
217
+ n: number;
218
+ };
219
+ }
172
220
  /** One marked line of a {@link TspCodeProps.marks}. */
173
221
  export interface TspCodeMark {
174
222
  line: number;
@@ -290,6 +338,21 @@ export interface TspMediaProps {
290
338
  h?: TspExtent;
291
339
  };
292
340
  }
341
+ /**
342
+ * A live web page shown inline (an `<iframe>` of a reply): passive until clicked, focused by a
343
+ * click, left with Escape, and replaced by a still of itself once idle. Programs check
344
+ * `cx.supports("web")` first.
345
+ */
346
+ export interface TspWebProps {
347
+ /** The page: an `http(s)` or `file://` URL. */
348
+ url: string;
349
+ /** What the page is, until it reports its own title. */
350
+ title?: string;
351
+ /** Width as a CSS length (`"50%"`, `"400px"`, `"60vw"`, `"80ch"`, `"30em"`); default: the column's. */
352
+ w?: string;
353
+ /** Height as a CSS length; default: a 16:10 box of the width. */
354
+ h?: string;
355
+ }
293
356
  export interface TspKvProps {
294
357
  items: readonly {
295
358
  k: TspText;
@@ -393,6 +456,62 @@ export interface TspItemProps {
393
456
  disabled?: boolean;
394
457
  value?: TspText;
395
458
  }
459
+ /**
460
+ * One row of a {@link TspMenuProps} menu: `"-"` a separator, `{ header }` a dim section title, an action id
461
+ * (labeled from it), or an item sending its `id` as an `action` event's `act`.
462
+ */
463
+ export type TspMenuItem = string | {
464
+ header: string;
465
+ } | {
466
+ id: string;
467
+ label?: string;
468
+ icon?: string;
469
+ /** Shortcut keys drawn at the row's right (display only). */
470
+ keys?: string | readonly string[];
471
+ /** A second line under the label (a rich row). */
472
+ detail?: string;
473
+ /** A check row, checked while true. */
474
+ checked?: boolean;
475
+ /** A radio row of this group. */
476
+ radio?: string;
477
+ /** Dimmed, not choosable; a string is the reason. */
478
+ disabled?: boolean | string;
479
+ danger?: boolean;
480
+ /** A submenu; the row itself sends nothing. */
481
+ items?: readonly TspMenuItem[];
482
+ };
483
+ /**
484
+ * A button opening a dropdown of commands. Choosing a row sends `action` (`act` = the row's id, `checked` for
485
+ * check/radio rows); opening or closing it sends `toggle` with `open`. As the last child of a split
486
+ * {@link TspButtonsProps} group it draws as the split's menu part. Pointer-only: it never takes focus.
487
+ */
488
+ export interface TspMenuProps {
489
+ items?: readonly TspMenuItem[];
490
+ /** The trigger's label; without `text` and `icon` the trigger is a square … button. */
491
+ text?: string;
492
+ icon?: string;
493
+ trigger?: "default" | "quiet" | "primary";
494
+ /** A chevron after the label. */
495
+ caret?: boolean;
496
+ size?: "sm" | "md";
497
+ variant?: "default" | "dense";
498
+ /** Whether the menu shows; a change wins over the user's local open/close. */
499
+ open?: boolean;
500
+ /** The highlighted row's id (the program's keyboard cursor). */
501
+ active?: string;
502
+ /** Which trigger edge the menu lines up with. */
503
+ align?: "start" | "end";
504
+ /** The trigger is dimmed and does not open; a string is the reason. */
505
+ disabled?: boolean | string;
506
+ }
507
+ /** `button` children drawn as one control: joined, an action with its menu part (`split`), or a toolbar well. */
508
+ export interface TspButtonsProps {
509
+ variant?: "joined" | "split" | "toolbar";
510
+ /** The children's size, winning over their own. */
511
+ size?: "sm" | "md";
512
+ /** Accessible name of the group. */
513
+ label?: string;
514
+ }
396
515
  export interface TspTabsProps {
397
516
  items: readonly {
398
517
  id: string;
@@ -428,6 +547,8 @@ export interface TspEditorDecoration {
428
547
  to: number;
429
548
  s: string;
430
549
  fx?: TspEffect;
550
+ /** An image blob the range stands for (an attachment token): copying the range copies the image. */
551
+ blob?: string;
431
552
  }
432
553
  export interface TspEditorProps {
433
554
  text?: string;
@@ -486,6 +607,10 @@ export interface TspToastProps {
486
607
  text: string;
487
608
  sub?: string;
488
609
  ttl?: number;
610
+ /** A button after the text (Undo): clicking it takes the toast down and sends this action for the node. */
611
+ action?: TspAction;
612
+ /** The button's text; defaults to the action's name labeled (`undo` → Undo). */
613
+ label?: string;
489
614
  }
490
615
  export interface TspRowsProps {
491
616
  /** Width the rows were rendered at. */
@@ -579,6 +704,30 @@ export interface TspPickerAction {
579
704
  end?: boolean;
580
705
  /** A toggle's state (`Task model ⌥P`): drawn pressed when true. */
581
706
  on?: boolean;
707
+ /** Drawn in the head as an icon-only button before its esc keycap (`icon`, else the label's initial), its label and keys as tooltip; `on` tints it. */
708
+ head?: boolean;
709
+ /** A head action's icon name. */
710
+ icon?: string;
711
+ disabled?: string | true;
712
+ }
713
+ /** A picker's stepped slider. */
714
+ export interface TspPickerLevel {
715
+ /** What it sets ("Thinking"): shown, or with `icon` its tooltip and accessible name. */
716
+ label: string;
717
+ /** An icon drawn in place of the label. */
718
+ icon?: string;
719
+ /** A dim note after the value in its chip (the model switcher: the highlighted model's provider). */
720
+ detail?: string;
721
+ /** Its steps, low to high: the terminal heats the track up the ladder (color, then motion). */
722
+ steps: readonly {
723
+ id: string;
724
+ label: string;
725
+ }[];
726
+ /** The current step's id. */
727
+ value: string;
728
+ /** The keys the program binds to step it, shown in its tooltip (`["alt", "left", "right"]`). */
729
+ keys?: readonly string[];
730
+ /** Drawn but frozen, the reason as its tooltip. */
582
731
  disabled?: string | true;
583
732
  }
584
733
  /** A group header inside a picker's `order`. */
@@ -602,6 +751,19 @@ export interface TspPickerProps {
602
751
  /** Plural noun for counts and empty copy ("models", "sessions"). */
603
752
  noun?: string;
604
753
  size?: "md" | "lg" | "screen";
754
+ /**
755
+ * Where the sheet sits: absent, its size's place in the layer; `"composer"`, rising from the program's composer
756
+ * (its `composerPart: "composer"` column), left edges aligned — a drop-up for a picker acting on the draft, such as
757
+ * the model switcher. Placed as if absent while no composer is drawn, and on a phone.
758
+ */
759
+ anchor?: "composer";
760
+ /**
761
+ * Where the search sits: the head (default), or `"list"`: no head row, the query leading the column heads' row
762
+ * (count and esc gone), head actions atop a `rail`. Ignored on a phone.
763
+ */
764
+ search?: "head" | "list";
765
+ /** How tall rows run: regular (default), or `"snug"`: 30px rows and 26px group headers, the chrome tightened to match. Ignored on a phone. */
766
+ density?: "regular" | "snug";
605
767
  layout?: "rows" | "cards" | "timeline" | "tree";
606
768
  /** The program's search text (keys stay the program's); `null` hides the field. */
607
769
  query?: string | null;
@@ -610,6 +772,8 @@ export interface TspPickerProps {
610
772
  placeholder?: string;
611
773
  scopes?: readonly TspPickerScope[];
612
774
  scope?: string;
775
+ /** How `scopes` draw: a labeled column (default), or `"rail"`: icons only, label and count as the tooltip, kept on narrow sheets. A `group` change draws a separator. */
776
+ scopeStyle?: "column" | "rail";
613
777
  tabs?: readonly {
614
778
  id: string;
615
779
  label: TspText;
@@ -645,6 +809,8 @@ export interface TspPickerProps {
645
809
  }[];
646
810
  selected?: string;
647
811
  } | null;
812
+ /** A stepped slider docked above the action bar (the model switcher's thinking effort). A press or drag ending on another step sends `action {act:"level", value: <step id>}`. */
813
+ level?: TspPickerLevel | null;
648
814
  state?: "ready" | "loading" | "error";
649
815
  message?: TspText;
650
816
  empty?: TspText;
@@ -976,12 +1142,15 @@ export interface TspShellProps {
976
1142
  replayEpoch?: number;
977
1143
  /** This mounted call received a real execution-start event, not a settled historical load. */
978
1144
  liveOrigin?: boolean;
1145
+ /** The command text is still streaming in: the host marks its write head and the preview follows it. */
1146
+ stream?: boolean;
979
1147
  /** Working directory shown ahead of the script when it differs from the project's. */
980
1148
  cwd?: string;
981
1149
  lang?: "bash" | "zsh";
982
1150
  /**
983
- * Clamp the command to its first `lines` drawn lines under a "N more lines" button; gives way inside an open
984
- * disclosure, and never applies in the inspector. The Raw/Pseudo switch and menu stay on the first line.
1151
+ * Clamp the command to `lines` drawn lines under an Expand button, the window following the write head
1152
+ * (`stream`), then the playhead, with the enclosing scope heads pinned; gives way inside an open
1153
+ * disclosure, and never applies in the inspector. The Raw/Pseudo switch and menu stay on the first visible line.
985
1154
  */
986
1155
  preview?: {
987
1156
  lines: number;
@@ -1003,6 +1172,7 @@ export interface TspPropsByKind {
1003
1172
  math: TspMathProps;
1004
1173
  image: TspImageProps;
1005
1174
  media: TspMediaProps;
1175
+ web: TspWebProps;
1006
1176
  kv: TspKvProps;
1007
1177
  table: TspTableProps;
1008
1178
  tree: TspTreeProps;
@@ -1021,6 +1191,9 @@ export interface TspPropsByKind {
1021
1191
  editor: TspEditorProps;
1022
1192
  input: TspInputProps;
1023
1193
  button: TspButtonProps;
1194
+ buttons: TspButtonsProps;
1195
+ menu: TspMenuProps;
1196
+ doc: TspDocProps;
1024
1197
  status: TspStatusProps;
1025
1198
  seg: TspSegProps;
1026
1199
  overlay: TspOverlayProps;
@@ -1055,7 +1228,7 @@ export type TspPropNode = {
1055
1228
  };
1056
1229
  }[TspKind];
1057
1230
  /** Kinds whose primary text the `text` and `splice` ops address (the `text` prop). */
1058
- export declare const TSP_TEXT_KINDS: readonly ["text", "md", "code", "ansi", "math", "editor", "input", "shimmer"];
1231
+ export declare const TSP_TEXT_KINDS: readonly ["text", "md", "code", "ansi", "math", "editor", "input", "shimmer", "doc"];
1059
1232
  /** A node on the wire. */
1060
1233
  export type TspNode = {
1061
1234
  [K in TspKind]: {
@@ -1174,13 +1347,16 @@ export type TspEvent = {
1174
1347
  sf: string;
1175
1348
  id: string;
1176
1349
  item: string;
1177
- } | {
1350
+ }
1351
+ /** A click action; a `menu` check or radio row adds its new `checked` state. */
1352
+ | {
1178
1353
  ev: "action";
1179
1354
  sf: string;
1180
1355
  id: string;
1181
1356
  act: string;
1182
1357
  value?: string;
1183
1358
  mods?: readonly string[];
1359
+ checked?: boolean;
1184
1360
  }
1185
1361
  /** A typed value changed by pointer (prefs rows, picker toggles); `null` resets to the default. */
1186
1362
  | {
@@ -1190,6 +1366,45 @@ export type TspEvent = {
1190
1366
  item: string;
1191
1367
  value: boolean | number | string | readonly string[] | null;
1192
1368
  }
1369
+ /** The user edited a `doc` (~300 ms after typing pauses, and when editing ends): `text` is its full new source. */
1370
+ | {
1371
+ ev: "change";
1372
+ sf: string;
1373
+ id: string;
1374
+ text: string;
1375
+ }
1376
+ /**
1377
+ * A comment on a `doc`: a new one on `quote` (`at` its UTF-16 offset in the source the user saw), or the
1378
+ * edited `note` of existing comment `comment`.
1379
+ */
1380
+ | {
1381
+ ev: "comment";
1382
+ sf: string;
1383
+ id: string;
1384
+ quote: string;
1385
+ at: number;
1386
+ note: string;
1387
+ } | {
1388
+ ev: "comment";
1389
+ sf: string;
1390
+ id: string;
1391
+ comment: string;
1392
+ note: string;
1393
+ }
1394
+ /** Comment `comment` of a `doc` deleted. */
1395
+ | {
1396
+ ev: "uncomment";
1397
+ sf: string;
1398
+ id: string;
1399
+ comment: string;
1400
+ }
1401
+ /** In-place editing of a `doc` started (`on`) or ended. */
1402
+ | {
1403
+ ev: "editing";
1404
+ sf: string;
1405
+ id: string;
1406
+ on: boolean;
1407
+ }
1193
1408
  /**
1194
1409
  * An edit over the terminal's selection in an `editor`/`input` node: replace
1195
1410
  * `[from, to)` with `text`, caret to `cursor` (UTF-16 offsets; `len` is the
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@linxiraos/pi-wire",
4
- "version": "1.5.1",
4
+ "version": "1.5.11",
5
5
  "description": "Shared wire protocol types for omp packages",
6
6
  "homepage": "https://linxira-os.github.io/zeta/",
7
7
  "author": "Can Boluk",
package/src/index.ts CHANGED
@@ -1,13 +1,295 @@
1
1
  /**
2
- * Shared wire constants for Zeta packages.
2
+ * Shared wire types for the Zeta live-session protocol.
3
3
  *
4
- * This file carries only the cross-package values that do not belong to a
5
- * feature-specific protocol; TSP and the stream wire live in their own modules.
4
+ * Dependency-free JSON shapes produced by `@linxiraos/zeta`
5
+ * (`src/collab/protocol.ts` and friends). Browser and test clients import this
6
+ * package instead of depending on the coding-agent runtime; conformance is
7
+ * asserted type-only in `packages/coding-agent/test/collab/web-wire.types.ts`.
8
+ *
9
+ * Unknown entry/event variants arrive over the wire as plain JSON. The unions
10
+ * below cover only the variants this client renders; consumers cast at the
11
+ * JSON boundary and every `switch` keeps a tolerant `default:` branch.
6
12
  */
7
13
 
8
- /** Parameter key used for intent tracing (e.g. prompt explanation/reasoning). */
14
+ // ═══════════════════════════════════════════════════════════════════════════
15
+ // Content blocks
16
+ // ═══════════════════════════════════════════════════════════════════════════
17
+
18
+ export interface TextContent {
19
+ type: "text";
20
+ text: string;
21
+ }
22
+
23
+ export interface ImageContent {
24
+ type: "image";
25
+ /** Base64-encoded image data. */
26
+ data: string;
27
+ /** e.g. "image/png". */
28
+ mimeType: string;
29
+ }
30
+
31
+ export interface ThinkingContent {
32
+ type: "thinking";
33
+ thinking: string;
34
+ }
35
+
36
+ export interface RedactedThinkingContent {
37
+ type: "redactedThinking";
38
+ data: string;
39
+ }
40
+
41
+ export interface ToolCallContent {
42
+ type: "toolCall";
43
+ id: string;
44
+ name: string;
45
+ arguments: Record<string, unknown>;
46
+ intent?: string;
47
+ }
48
+
49
+ export type AssistantContent = TextContent | ThinkingContent | RedactedThinkingContent | ToolCallContent;
50
+
51
+ export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
52
+
53
+ export interface WireUsage {
54
+ input: number;
55
+ output: number;
56
+ cacheRead: number;
57
+ cacheWrite: number;
58
+ totalTokens: number;
59
+ cost: { total: number };
60
+ }
61
+
62
+ // ═══════════════════════════════════════════════════════════════════════════
63
+ // Messages
64
+ // ═══════════════════════════════════════════════════════════════════════════
65
+
66
+ export interface UserMessage {
67
+ role: "user";
68
+ content: string | (TextContent | ImageContent)[];
69
+ /** True if the message was injected by the system (e.g. auto-continue). */
70
+ synthetic?: boolean;
71
+ /** Unix timestamp in milliseconds. */
72
+ timestamp: number;
73
+ }
74
+
75
+ export interface DeveloperMessage {
76
+ role: "developer";
77
+ content: string | (TextContent | ImageContent)[];
78
+ timestamp: number;
79
+ }
80
+
81
+ export interface AssistantMessage {
82
+ role: "assistant";
83
+ content: AssistantContent[];
84
+ model: string;
85
+ usage: WireUsage;
86
+ stopReason: StopReason;
87
+ errorMessage?: string;
88
+ timestamp: number;
89
+ }
90
+
91
+ export interface ToolResultMessage {
92
+ role: "toolResult";
93
+ toolCallId: string;
94
+ toolName: string;
95
+ content: (TextContent | ImageContent)[];
96
+ details?: unknown;
97
+ isError: boolean;
98
+ timestamp: number;
99
+ }
100
+
101
+ export type WireMessage = UserMessage | DeveloperMessage | AssistantMessage | ToolResultMessage;
102
+
103
+ // ═══════════════════════════════════════════════════════════════════════════
104
+ // Session entries (rendered subset; cast `as SessionEntry` at the JSON
105
+ // boundary and skip unknown `type`s in a tolerant `default:`)
106
+ // ═══════════════════════════════════════════════════════════════════════════
107
+
108
+ export interface SessionHeader {
109
+ type: "session";
110
+ id: string;
111
+ title?: string;
112
+ timestamp: string;
113
+ cwd: string;
114
+ }
115
+
116
+ export interface EntryBase {
117
+ id: string;
118
+ parentId: string | null;
119
+ timestamp: string;
120
+ }
121
+
122
+ export interface MessageEntry extends EntryBase {
123
+ type: "message";
124
+ message: WireMessage;
125
+ }
126
+
127
+ export interface CustomMessageEntry extends EntryBase {
128
+ type: "custom_message";
129
+ customType: string;
130
+ content: string | (TextContent | ImageContent)[];
131
+ details?: unknown;
132
+ display: boolean;
133
+ }
134
+
135
+ export interface CompactionEntry extends EntryBase {
136
+ type: "compaction";
137
+ summary: string;
138
+ shortSummary?: string;
139
+ firstKeptEntryId: string;
140
+ tokensBefore: number;
141
+ }
142
+
143
+ export interface BranchSummaryEntry extends EntryBase {
144
+ type: "branch_summary";
145
+ fromId: string;
146
+ summary: string;
147
+ }
148
+
149
+ export interface ModelChangeEntry extends EntryBase {
150
+ type: "model_change";
151
+ /** Model in "provider/modelId" format. */
152
+ model: string;
153
+ role?: string;
154
+ }
155
+
156
+ export interface ThinkingLevelChangeEntry extends EntryBase {
157
+ type: "thinking_level_change";
158
+ thinkingLevel?: string | null;
159
+ }
160
+
161
+ export type SessionEntry =
162
+ | MessageEntry
163
+ | CustomMessageEntry
164
+ | CompactionEntry
165
+ | BranchSummaryEntry
166
+ | ModelChangeEntry
167
+ | ThinkingLevelChangeEntry;
168
+
169
+ // ═══════════════════════════════════════════════════════════════════════════
170
+ // Events (handled subset)
171
+ // ═══════════════════════════════════════════════════════════════════════════
172
+
173
+ export type AgentEvent =
174
+ | { type: "agent_start" }
175
+ | { type: "agent_end" }
176
+ | { type: "turn_start" }
177
+ | { type: "turn_end" }
178
+ | { type: "message_start"; message: WireMessage }
179
+ /** Carries the FULL accumulating partial message — no delta tracking needed. */
180
+ | { type: "message_update"; message: WireMessage }
181
+ | { type: "message_end"; message: WireMessage }
182
+ | { type: "tool_execution_start"; toolCallId: string; toolName: string; args: unknown; intent?: string }
183
+ | { type: "tool_execution_update"; toolCallId: string; toolName: string; args: unknown; partialResult: unknown }
184
+ | { type: "tool_execution_end"; toolCallId: string; toolName: string; result: unknown; isError?: boolean }
185
+ | { type: "notice"; level: "info" | "warning" | "error"; message: string; source?: string }
186
+ | { type: "auto_compaction_start"; reason: string; action: string }
187
+ | { type: "auto_compaction_end"; aborted: boolean; willRetry: boolean; errorMessage?: string; skipped?: boolean }
188
+ | { type: "auto_retry_start"; attempt: number; maxAttempts: number; delayMs: number; errorMessage: string }
189
+ | { type: "auto_retry_end"; success: boolean; attempt: number; finalError?: string }
190
+ | { type: "thinking_level_changed"; thinkingLevel?: string };
191
+
192
+ // ═══════════════════════════════════════════════════════════════════════════
193
+ // State & agents
194
+ // ═══════════════════════════════════════════════════════════════════════════
195
+
196
+ export interface WireModel {
197
+ id: string;
198
+ name: string;
199
+ provider: string;
200
+ contextWindow: number | null;
201
+ }
202
+
203
+ export interface ContextUsage {
204
+ tokens: number | null;
205
+ contextWindow: number | null;
206
+ percent: number | null;
207
+ }
208
+
209
+ export interface Participant {
210
+ name: string;
211
+ role: "host" | "guest";
212
+ /** True when the guest joined through a read-only (view) link. */
213
+ readOnly?: boolean;
214
+ }
215
+
216
+ /** Parameter key used for intent tracing (e.g. prompt explanation/reasoning) */
9
217
  export const INTENT_FIELD = "i";
10
218
 
219
+ // ═══════════════════════════════════════════════════════════════════════════
220
+ // Envelope & link constants
221
+ // ═══════════════════════════════════════════════════════════════════════════
222
+
223
+ /** Plaintext envelope prefix: `[4B uint32 BE peerId][sealed payload]`. */
224
+ export const ENVELOPE_HEADER_LENGTH = 4;
225
+
226
+ /**
227
+ * Prefix `sealed` with its envelope header. Host→relay: peerId 0 broadcasts to
228
+ * all guests, peerId N targets guest N. Guest→relay: always 0; the relay
229
+ * rewrites it to the sender's id.
230
+ */
231
+ export function packEnvelope(peerId: number, sealed: Uint8Array): Uint8Array<ArrayBuffer> {
232
+ const out = new Uint8Array(ENVELOPE_HEADER_LENGTH + sealed.byteLength);
233
+ new DataView(out.buffer).setUint32(0, peerId, false);
234
+ out.set(sealed, ENVELOPE_HEADER_LENGTH);
235
+ return out;
236
+ }
237
+
238
+ /** Split an envelope into its peerId and sealed payload; `null` when shorter than the header. */
239
+ export function unpackEnvelope(data: Uint8Array): { peerId: number; payload: Uint8Array } | null {
240
+ if (data.byteLength < ENVELOPE_HEADER_LENGTH) return null;
241
+ const peerId = new DataView(data.buffer, data.byteOffset, ENVELOPE_HEADER_LENGTH).getUint32(0, false);
242
+ return { peerId, payload: data.subarray(ENVELOPE_HEADER_LENGTH) };
243
+ }
244
+
245
+ /** Rewrite the peerId in place without copying the payload. */
246
+ export function rewriteEnvelopePeer(data: Uint8Array, peerId: number): void {
247
+ new DataView(data.buffer, data.byteOffset, ENVELOPE_HEADER_LENGTH).setUint32(0, peerId, false);
248
+ }
249
+
250
+ export const ROOM_ID_BYTES = 16;
251
+
252
+ /** AES-256-GCM room key; the seal key for every collab frame. */
253
+ export const ROOM_KEY_BYTES = 32;
254
+
255
+ /**
256
+ * Random write token appended to the room key in full links
257
+ * (`base64url(key ∥ token)`); view links carry the bare key. Possession
258
+ * proves prompt/abort/agent-cmd capability to the host.
259
+ */
260
+ export const WRITE_TOKEN_BYTES = 16;
261
+
262
+ /**
263
+ * Each automatic rejoin costs the host a full snapshot, and a guest on a link
264
+ * too slow for the session is shed again after every one. Past the cap the
265
+ * guest stops rejoining on its own and leaves the decision to the user.
266
+ */
267
+ export const MAX_AUTO_REJOINS = 3;
268
+ export const AUTO_REJOIN_WINDOW_MS = 5 * 60_000;
269
+
270
+ /** Records an automatic rejoin in {@link history} if the window has room for one. */
271
+ export function takeAutoRejoin(history: number[], now = Date.now()): boolean {
272
+ while (history.length > 0 && now - history[0]! >= AUTO_REJOIN_WINDOW_MS) history.shift();
273
+ if (history.length >= MAX_AUTO_REJOINS) return false;
274
+ history.push(now);
275
+ return true;
276
+ }
277
+
278
+ /** Default public relay; bare `<roomId>.<key>` links resolve against it. */
279
+ export const DEFAULT_RELAY_URL = "wss://my.omp.sh";
280
+
281
+ /** Default share viewer/upload base; `/share` links resolve against `<base>/<id>#<key>`. */
282
+
283
+ // ═══════════════════════════════════════════════════════════════════════════
284
+ // Relay control messages (TEXT JSON, unencrypted, no session data)
285
+ // ═══════════════════════════════════════════════════════════════════════════
286
+
287
+ /** Relay → host control message. */
288
+ export type RelayControlToHost = { t: "peer-joined" | "peer-left"; peer: number };
289
+ /** Relay → guest control message. */
290
+ export type RelayControlToGuest = { t: "room-closed" };
291
+ export type RelayControlMessage = RelayControlToHost | RelayControlToGuest;
292
+
11
293
  export * from "./shell-trace";
12
294
  export * from "./shell-viz";
13
295
  export * from "./stream";