1818 */
1919
2020// Server -> client WebSocket frames for this service's protocol
21- // (`/agents/:id/react`). Modeled as a discriminated union on `type`, so each
22- // message kind declares exactly the fields it sends.
2321
2422import type { AgentState , ReActStep } from "../agent" ;
2523import type { WorkflowContent } from "../workflow" ;
24+ import type { CustomUnionType } from "../util" ;
2625
2726/**
2827 * Wire projection of one operator's execution result, summarized for the
@@ -42,69 +41,54 @@ export interface OperatorResultSummaryWs {
4241 resultStatistics ?: Record < string , string > ;
4342}
4443
45- /** Per-operator result summaries, keyed by operator id. */
46- type OperatorResults = Record < string , OperatorResultSummaryWs > ;
47-
48- /** Shared discriminator base; every server frame sets a unique `type`. */
49- interface WsServerMessageBase {
50- type : "snapshot" | "step" | "status" | "error" | "headChange" ;
51- }
52-
5344/**
5445 * Full state pushed once when a client connects: the agent's current lifecycle
5546 * state, the complete step list, and the HEAD pointer. Operator results are not
5647 * included — they are pulled on demand via `GET /operator-results`.
5748 */
58- export interface WsServerSnapshotMessage extends WsServerMessageBase {
59- type : "snapshot" ;
49+ export interface WsServerSnapshotEvent extends Readonly < {
6050 state : AgentState ;
6151 steps : ReActStep [ ] ;
6252 headId : string ;
63- }
53+ } > { }
6454
65- /**
66- * A single ReAct step, streamed live as the agent runs.
67- */
68- export interface WsServerStepMessage extends WsServerMessageBase {
69- type : "step" ;
55+ /** A single ReAct step, streamed live as the agent runs. */
56+ export interface WsServerStepEvent extends Readonly < {
7057 step : ReActStep ;
71- }
58+ } > { }
7259
7360/**
7461 * An agent lifecycle transition (e.g. GENERATING when a run starts, the resting
7562 * state when it ends, STOPPING on stop).
7663 */
77- export interface WsServerStatusMessage extends WsServerMessageBase {
78- type : "status" ;
64+ export interface WsServerStatusEvent extends Readonly < {
7965 state : AgentState ;
80- }
66+ } > { }
8167
8268/** An error surfaced to the client (agent not found, bad request, failed run). */
83- export interface WsServerErrorMessage extends WsServerMessageBase {
84- type : "error" ;
69+ export interface WsServerErrorEvent extends Readonly < {
8570 error : string ;
86- }
71+ } > { }
8772
8873/**
8974 * Emitted after a checkout: HEAD moved, carrying the full step list and the
9075 * workflow snapshot at the new head.
9176 *
92- * @deprecated Redundant and unused — the checkout flow that produces this frame
93- * is unreachable in the product (nothing invokes the client's `checkoutStep()`).
94- * Scheduled for removal (see #5930); do not build new code on it.
77+ * @deprecated Redundant and unused. TODO: remove this message and related caller logics.
9578 */
96- export interface WsServerHeadChangeMessage extends WsServerMessageBase {
97- type : "headChange" ;
79+ export interface WsServerHeadChangeEvent extends Readonly < {
9880 headId : string ;
9981 steps : ReActStep [ ] ;
10082 workflowContent ?: WorkflowContent ;
101- operatorResults : OperatorResults ;
102- }
83+ } > { }
84+
85+ export type WsServerEventTypeMap = {
86+ snapshot : WsServerSnapshotEvent ;
87+ step : WsServerStepEvent ;
88+ status : WsServerStatusEvent ;
89+ error : WsServerErrorEvent ;
90+ headChange : WsServerHeadChangeEvent ;
91+ } ;
10392
10493/** Discriminated union of every server -> client frame. */
105- export type WsServerMessage =
106- | WsServerSnapshotMessage
107- | WsServerStepMessage
108- | WsServerStatusMessage
109- | WsServerErrorMessage
110- | WsServerHeadChangeMessage ;
94+ export type WsServerEvent = CustomUnionType < WsServerEventTypeMap > ;
0 commit comments