@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
55import qrcode from "qrcode" ;
66import { createServer , type Plugin , type ViteDevServer } from "vite" ;
77import type {
8+ RequestFrame ,
89 SystemAgentChatHistoryResult ,
910 SystemAgentChatQuestion ,
1011 SystemAgentChatResult ,
@@ -2071,19 +2072,26 @@ function installControlUiCustodianMock(replyDelayMs: number): void {
20712072 if ( ! gateway || ! MockWebSocket ) {
20722073 return ;
20732074 }
2074- const originalSend = MockWebSocket . prototype . send ;
2075+ const sendDescriptor = Object . getOwnPropertyDescriptor ( MockWebSocket . prototype , "send" ) ;
2076+ const originalSend = sendDescriptor ?. value as WebSocket [ "send" ] | undefined ;
2077+ if ( typeof originalSend !== "function" ) {
2078+ return ;
2079+ }
2080+ const sendOriginal = ( socket : WebSocket , data : Parameters < WebSocket [ "send" ] > [ 0 ] ) : void => {
2081+ Reflect . apply ( originalSend , socket , [ data ] ) ;
2082+ } ;
20752083 const sessionTurns = new Map < string , number > ( ) ;
20762084 MockWebSocket . prototype . send = function ( data ) : void {
2077- let frame : { method ?: unknown ; params ?: unknown ; type ?: unknown } | null = null ;
2085+ let frame : RequestFrame | null = null ;
20782086 if ( typeof data === "string" ) {
20792087 try {
2080- frame = JSON . parse ( data ) as typeof frame ;
2088+ frame = JSON . parse ( data ) as RequestFrame ;
20812089 } catch {
20822090 frame = null ;
20832091 }
20842092 }
20852093 if ( frame ?. type !== "req" || frame . method !== "openclaw.chat" ) {
2086- originalSend . call ( this , data ) ;
2094+ sendOriginal ( this , data ) ;
20872095 return ;
20882096 }
20892097
@@ -2145,7 +2153,7 @@ function installControlUiCustodianMock(replyDelayMs: number): void {
21452153 // Defer before forwarding so the generic gateway records the request but
21462154 // cannot race its normal immediate response against this stateful reply.
21472155 gateway . deferNext ( "openclaw.chat" ) ;
2148- originalSend . call ( this , data ) ;
2156+ sendOriginal ( this , data ) ;
21492157 window . setTimeout (
21502158 ( ) => gateway . resolveDeferred ( "openclaw.chat" , response ) ,
21512159 message === undefined ? 0 : replyDelayMs ,
0 commit comments