@@ -153,7 +153,15 @@ def _render_stream_message(data: str, *, pretty: bool, text_only: bool) -> list[
153153 return []
154154
155155
156- def _build_websocket_url (* , endpoint : str , chat_token : str , claw_instance_id : str ) -> str :
156+ def _build_websocket_url (
157+ * ,
158+ endpoint : str ,
159+ chat_token : str ,
160+ claw_instance_id : str ,
161+ default_scheme : str = "wss" ,
162+ ) -> str :
163+ if default_scheme not in ("ws" , "wss" ):
164+ raise ValidationError (f"ws_scheme must be 'ws' or 'wss', got { default_scheme !r} " )
157165 normalized = endpoint .strip ()
158166 if normalized .startswith ("wss://" ) or normalized .startswith ("ws://" ):
159167 base = normalized
@@ -162,7 +170,7 @@ def _build_websocket_url(*, endpoint: str, chat_token: str, claw_instance_id: st
162170 elif normalized .startswith ("http://" ):
163171 base = "ws://" + normalized [len ("http://" ) :]
164172 else :
165- base = f"wss ://{ normalized } "
173+ base = f"{ default_scheme } ://{ normalized } "
166174
167175 if "?" not in base :
168176 scheme_split = base .split ("://" , 1 )
@@ -235,9 +243,12 @@ def __init__(
235243 connect_retries : int = 2 ,
236244 session_key : str = "agent:main:main" ,
237245 protocol_version : int = 4 ,
246+ ws_scheme : str = "wss" ,
238247 ) -> None :
239248 if connect_retries < 0 :
240249 raise ValidationError ("connect_retries must be >= 0" )
250+ if ws_scheme not in ("ws" , "wss" ):
251+ raise ValidationError (f"ws_scheme must be 'ws' or 'wss', got { ws_scheme !r} " )
241252 self .client = client
242253 self .space_id = space_id
243254 self .instance_id = instance_id
@@ -251,6 +262,7 @@ def __init__(
251262 if protocol_version not in (3 , 4 ):
252263 raise ValidationError (f"protocol_version must be 3 or 4, got { protocol_version } " )
253264 self .protocol_version = protocol_version
265+ self .ws_scheme = ws_scheme
254266
255267 self ._websocket_module : Any | None = None
256268 self ._timeout_exc : type [BaseException ] = TimeoutError
@@ -438,6 +450,7 @@ def _refresh_chat_access(self) -> None:
438450 endpoint = endpoint ,
439451 chat_token = chat_token ,
440452 claw_instance_id = claw_instance_id ,
453+ default_scheme = self .ws_scheme ,
441454 )
442455
443456 def _get_websocket_module (self ) -> Any :
0 commit comments