summaryrefslogtreecommitdiffhomepage
path: root/src/core/wire/conformance.ts
blob: eff2330705e53b724e693286e2eff13dc1768501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import type { WsClientMessage, WsServerMessage } from "@dispatch/transport-contract";
import type { AgentEvent, Chunk } from "@dispatch/wire";

/**
 * Compile-time exhaustiveness guard for `AgentEvent.type`.
 * If a variant is added/removed/renamed in `@dispatch/wire`, this function's
 * default branch becomes reachable → TypeScript error at build time.
 */
export function assertAgentEventExhaustive(event: AgentEvent): string {
  switch (event.type) {
    case "status":
      return "status";
    case "turn-start":
      return "turn-start";
    case "user-message":
      return "user-message";
    case "text-delta":
      return "text-delta";
    case "reasoning-delta":
      return "reasoning-delta";
    case "reasoning-end":
      return "reasoning-end";
    case "tool-call":
      return "tool-call";
    case "tool-result":
      return "tool-result";
    case "tool-output":
      return "tool-output";
    case "usage":
      return "usage";
    case "error":
      return "error";
    case "done":
      return "done";
    case "turn-sealed":
      return "turn-sealed";
    case "turn-ended":
      return "turn-ended";
    case "step-complete":
      return "step-complete";
    case "steering":
      return "steering";
    case "provider-retry":
      return "provider-retry";
    default:
      return event satisfies never;
  }
}

/**
 * Compile-time exhaustiveness guard for `Chunk.type`.
 */
export function assertChunkExhaustive(chunk: Chunk): string {
  switch (chunk.type) {
    case "text":
      return "text";
    case "thinking":
      return "thinking";
    case "tool-call":
      return "tool-call";
    case "tool-result":
      return "tool-result";
    case "error":
      return "error";
    case "system":
      return "system";
    case "image":
      return "image";
    default:
      return chunk satisfies never;
  }
}

/**
 * Compile-time exhaustiveness guard for `WsServerMessage.type`.
 * Covers both surface ops and chat ops.
 */
export function assertWsServerMessageExhaustive(msg: WsServerMessage): string {
  switch (msg.type) {
    case "catalog":
      return "catalog";
    case "surface":
      return "surface";
    case "update":
      return "update";
    case "error":
      return "error";
    case "chat.delta":
      return "chat.delta";
    case "chat.resync-required":
      return "chat.resync-required";
    case "chat.accepted":
      return "chat.accepted";
    case "chat.subscription-rejected":
      return "chat.subscription-rejected";
    case "chat.queued":
      return "chat.queued";
    case "chat.error":
      return "chat.error";
    case "conversation.open":
      return "conversation.open";
    case "conversation.statusChanged":
      return "conversation.statusChanged";
    case "conversation.compacted":
      return "conversation.compacted";
    case "conversation.tabGroupChanged":
      return "conversation.tabGroupChanged";
    case "extensions-changed":
      return "extensions-changed";
    case "layout":
      return "layout";
    case "tile-layout":
      return "tile-layout";
    default:
      return msg satisfies never;
  }
}

/**
 * Compile-time exhaustiveness guard for `WsClientMessage.type`.
 * Covers both surface ops and chat ops.
 */
export function assertWsClientMessageExhaustive(msg: WsClientMessage): string {
  switch (msg.type) {
    case "subscribe":
      return "subscribe";
    case "unsubscribe":
      return "unsubscribe";
    case "invoke":
      return "invoke";
    case "chat.send":
      return "chat.send";
    case "chat.subscribe":
      return "chat.subscribe";
    case "chat.unsubscribe":
      return "chat.unsubscribe";
    case "chat.queue":
      return "chat.queue";
    case "chat.queue.cancel":
      return "chat.queue.cancel";
    case "workspace.set":
      return "workspace.set";
    default:
      return msg satisfies never;
  }
}