Open History to see the last commit
1---
2id: toWebSocketStream
3title: toWebSocketStream
4---
5
6```ts
7function toWebSocketStream<TOffset>(
8 socket,
9 request,
10 init): void;
11```
12
13Defined in: [packages/ai/src/stream-to-websocket.ts:120](https://github.com/TanStack/ai/blob/main/packages/ai/src/stream-to-websocket.ts#L120)
14
15Run a full-duplex, conversation-scoped chat over an already-accepted server
16socket. Each inbound RunAgentInput frame starts one chat() turn (via onRun)
17whose chunks are pumped back as frames; the socket stays open across turns
18(pending client-tool resubmit, next user message) until the client closes it
19or the idle timeout fires. An abort control frame aborts only its turn.
20
21## Type Parameters
22
23### TOffset
24
25`TOffset` *extends* `string` = `string`
26
27## Parameters
28
29### socket
30
31[`WebSocketLike`](../interfaces/WebSocketLike.md)
32
33### request
34
35`Request`
36
37### init
38
39[`WebSocketStreamInit`](../interfaces/WebSocketStreamInit.md)\<`TOffset`\>
40
41## Returns
42
43`void`