Open History to see the last commit
1---
2id: WebSocketStreamInit
3title: WebSocketStreamInit
4---
5
6Defined in: packages/ai/src/stream-to-websocket.ts:90
7
8## Type Parameters
9
10### TOffset
11
12`TOffset` *extends* `string` = `string`
13
14## Properties
15
16### batch?
17
18```ts
19optional batch?: number;
20```
21
22Defined in: packages/ai/src/stream-to-websocket.ts:96
23
24Chunks buffered per durability append (default 32).
25
26***
27
28### batchWaitMs?
29
30```ts
31optional batchWaitMs?: number;
32```
33
34Defined in: packages/ai/src/stream-to-websocket.ts:101
35
36Most ms a chunk waits in the batch for the next one before the batch is
37appended and sent anyway (default 50). `0` appends every chunk on its own.
38
39***
40
41### debug?
42
43```ts
44optional debug?: DebugOption;
45```
46
47Defined in: packages/ai/src/stream-to-websocket.ts:110
48
49***
50
51### durability?
52
53```ts
54optional durability?: (ctx) => StreamDurability<TOffset>;
55```
56
57Defined in: packages/ai/src/stream-to-websocket.ts:94
58
59Per-TURN durability factory, keyed by the frame's runId via ctx.request.
60
61#### Parameters
62
63##### ctx
64
65[`WsRunContext`](WsRunContext.md)
66
67#### Returns
68
69[`StreamDurability`](StreamDurability.md)\<`TOffset`\>
70
71***
72
73### heartbeatMs?
74
75```ts
76optional heartbeatMs?: number;
77```
78
79Defined in: packages/ai/src/stream-to-websocket.ts:103
80
81Heartbeat ping interval in ms (default 30_000).
82
83***
84
85### idleTimeoutMs?
86
87```ts
88optional idleTimeoutMs?: number;
89```
90
91Defined in: packages/ai/src/stream-to-websocket.ts:109
92
93Close after this many ms without any inbound frame (default 300_000).
94Never fires while a turn is still streaming, so a long single generation
95(agentic loop, >5-min turn) is safe.
96
97***
98
99### onRun
100
101```ts
102onRun: (ctx) => AsyncIterable<AGUIEvent>;
103```
104
105Defined in: packages/ai/src/stream-to-websocket.ts:92
106
107Build a fresh chat() stream for each inbound RunAgentInput frame.
108
109#### Parameters
110
111##### ctx
112
113[`WsRunContext`](WsRunContext.md)
114
115#### Returns
116
117`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>