55 * via WebSocket using these JSON-RPC message formats.
66 */
77
8+ // === Base JSON-RPC Types ===
9+
10+ interface JsonRpcMessage {
11+ jsonrpc : "2.0" ;
12+ }
13+
14+ interface JsonRpcMethodMessage extends JsonRpcMessage {
15+ method : string ;
16+ }
17+
818// === Security Key Types ===
919
1020export interface SecurityKeys {
@@ -51,36 +61,31 @@ export interface TestCaseStartedParams {
5161
5262// === Request Messages (Orchestrator -> Runner) ===
5363
54- export interface StartRequest {
55- jsonrpc : "2.0" ;
64+ export interface StartRequest extends JsonRpcMethodMessage {
5665 id : number ;
5766 method : "start" ;
5867 params : StartParams ;
5968}
6069
61- export interface StopRequest {
62- jsonrpc : "2.0" ;
70+ export interface StopRequest extends JsonRpcMethodMessage {
6371 id : number ;
6472 method : "stop" ;
6573 params : Record < string , never > ;
6674}
6775
68- export interface HandleCttPromptRequest {
69- jsonrpc : "2.0" ;
76+ export interface HandleCttPromptRequest extends JsonRpcMethodMessage {
7077 id : number ;
7178 method : "handleCttPrompt" ;
7279 params : CttPromptParams ;
7380}
7481
75- export interface TestCaseStartedRequest {
76- jsonrpc : "2.0" ;
82+ export interface TestCaseStartedRequest extends JsonRpcMethodMessage {
7783 id : number ;
7884 method : "testCaseStarted" ;
7985 params : TestCaseStartedParams ;
8086}
8187
82- export interface HandleCttLogRequest {
83- jsonrpc : "2.0" ;
88+ export interface HandleCttLogRequest extends JsonRpcMethodMessage {
8489 id : number ;
8590 method : "handleCttLog" ;
8691 params : CttLogParams ;
@@ -90,14 +95,12 @@ export type IpcRequest = StartRequest | StopRequest | HandleCttPromptRequest | T
9095
9196// === Response Messages (Runner -> Orchestrator) ===
9297
93- export interface SuccessResponse {
94- jsonrpc : "2.0" ;
98+ export interface SuccessResponse extends JsonRpcMessage {
9599 id : number ;
96100 result : string ; // "ok" for start/stop, button name for handleCttPrompt
97101}
98102
99- export interface ErrorResponse {
100- jsonrpc : "2.0" ;
103+ export interface ErrorResponse extends JsonRpcMessage {
101104 id : number ;
102105 error : {
103106 code : number ;
@@ -109,50 +112,48 @@ export type IpcResponse = SuccessResponse | ErrorResponse;
109112
110113// === Notification Messages (Runner -> Orchestrator) ===
111114
112- export interface ReadyNotification {
113- jsonrpc : "2.0" ;
115+ export interface ReadyNotification extends JsonRpcMethodMessage {
114116 method : "ready" ;
115117 params : {
116118 name : string ; // Runner name for logging
117119 } ;
118120}
119121
120- export type IpcNotification = ReadyNotification ;
122+ export interface NoHandlerNotification extends JsonRpcMethodMessage {
123+ method : "noHandler" ;
124+ }
125+
126+ export type IpcNotification = ReadyNotification | NoHandlerNotification ;
121127
122128// === Type Guards ===
123129
124- export function isSuccessResponse ( msg : unknown ) : msg is SuccessResponse {
130+ function isJsonRpcMessage ( msg : unknown ) : msg is JsonRpcMessage {
125131 return (
126132 typeof msg === "object" &&
127133 msg !== null &&
128134 "jsonrpc" in msg &&
129- msg . jsonrpc === "2.0" &&
130- "id" in msg &&
131- "result" in msg
135+ msg . jsonrpc === "2.0"
132136 ) ;
133137}
134138
139+ function isJsonRpcMethodMessage ( msg : unknown ) : msg is JsonRpcMethodMessage {
140+ return isJsonRpcMessage ( msg ) && "method" in msg ;
141+ }
142+
143+ export function isSuccessResponse ( msg : unknown ) : msg is SuccessResponse {
144+ return isJsonRpcMessage ( msg ) && "id" in msg && "result" in msg ;
145+ }
146+
135147export function isErrorResponse ( msg : unknown ) : msg is ErrorResponse {
136- return (
137- typeof msg === "object" &&
138- msg !== null &&
139- "jsonrpc" in msg &&
140- msg . jsonrpc === "2.0" &&
141- "id" in msg &&
142- "error" in msg
143- ) ;
148+ return isJsonRpcMessage ( msg ) && "id" in msg && "error" in msg ;
144149}
145150
146151export function isReadyNotification ( msg : unknown ) : msg is ReadyNotification {
147- return (
148- typeof msg === "object" &&
149- msg !== null &&
150- "jsonrpc" in msg &&
151- msg . jsonrpc === "2.0" &&
152- "method" in msg &&
153- msg . method === "ready" &&
154- "params" in msg
155- ) ;
152+ return isJsonRpcMethodMessage ( msg ) && msg . method === "ready" && "params" in msg ;
153+ }
154+
155+ export function isNoHandlerNotification ( msg : unknown ) : msg is NoHandlerNotification {
156+ return isJsonRpcMethodMessage ( msg ) && msg . method === "noHandler" ;
156157}
157158
158159// === Constants ===
0 commit comments