Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

toWebSocketResponse.md

36 lines889 Bytes

1---
2id: toWebSocketResponse
3title: toWebSocketResponse
4---
5​
6```ts
7function toWebSocketResponse<TOffset>(request, init): Response;
8```
9​
10Defined in: [packages/ai/src/stream-to-websocket.ts:398](https://github.com/TanStack/ai/blob/main/packages/ai/src/stream-to-websocket.ts#L398)
11​
12Cloudflare wrapper (Workers/Durable Objects): creates a `WebSocketPair`,
13accepts the server socket, delegates to [toWebSocketStream](toWebSocketStream.md), and
14returns the 101 upgrade `Response` carrying the client socket. Throws when
15the runtime has no `WebSocketPair` (Node, Deno, Bun) — upgrade the socket
16yourself and call [toWebSocketStream](toWebSocketStream.md) directly there.
17​
18## Type Parameters
19​
20### TOffset
21​
22`TOffset` *extends* `string` = `string`
23​
24## Parameters
25​
26### request
27​
28`Request`
29​
30### init
31​
32[`WebSocketStreamInit`](../interfaces/WebSocketStreamInit.md)\<`TOffset`\>
33​
34## Returns
35​
36`Response`