Open History to see the last commit
1---
2id: StreamDurability
3title: StreamDurability
4---
5
6Defined in: packages/ai/src/stream-durability.ts:10
7
8A pluggable delivery-durability backend.
9
10Offsets are owned by the adapter and opaque to the transport. The generic
11parameter lets an adapter retain a branded string type across append, read,
12and resume without requiring core to understand its cursor format.
13
14## Extended by
15
16- [`UpsertableStreamDurability`](UpsertableStreamDurability.md)
17
18## Type Parameters
19
20### TOffset
21
22`TOffset` *extends* `string` = `string`
23
24## Properties
25
26### append
27
28```ts
29append: (chunks) => Promise<TOffset[]>;
30```
31
32Defined in: packages/ai/src/stream-durability.ts:17
33
34Persist a batch before it is delivered and return exactly one resumable
35offset for each chunk, in the same order.
36
37#### Parameters
38
39##### chunks
40
41[`AGUIEvent`](../type-aliases/AGUIEvent.md)[]
42
43#### Returns
44
45`Promise`\<`TOffset`[]\>
46
47***
48
49### close
50
51```ts
52close: () => Promise<void>;
53```
54
55Defined in: packages/ai/src/stream-durability.ts:27
56
57Terminalize the producer log and unblock live readers. Core awaits this
58for every producer exit, including completion, cancellation, and failure.
59
60#### Returns
61
62`Promise`\<`void`\>
63
64***
65
66### read
67
68```ts
69read: (offset, signal?) => AsyncIterable<{
70 chunk: AGUIEvent;
71 offset: TOffset;
72}>;
73```
74
75Defined in: packages/ai/src/stream-durability.ts:19
76
77Replay chunks strictly after the supplied adapter-owned offset.
78
79#### Parameters
80
81##### offset
82
83`TOffset`
84
85##### signal?
86
87`AbortSignal`
88
89#### Returns
90
91`AsyncIterable`\<\{
92 `chunk`: [`AGUIEvent`](../type-aliases/AGUIEvent.md);
93 `offset`: `TOffset`;
94\}\>
95
96***
97
98### resumeFrom
99
100```ts
101resumeFrom: () => TOffset | null;
102```
103
104Defined in: packages/ai/src/stream-durability.ts:12
105
106Return the adapter offset captured from the request, or null for a producer.
107
108#### Returns
109
110`TOffset` \| `null`
111
112***
113
114### snapshot
115
116```ts
117snapshot: () => Promise<object[]>;
118```
119
120Defined in: packages/ai/src/stream-durability.ts:57
121
122Everything stored for this run **at the moment of the call**, in append
123order, then resolve.
124
125This is the bounded counterpart to [StreamDurability.read](#read). `read`
126tails: it parks until the log is terminalized or the caller aborts, so it
127cannot be used to inspect a log whose producer died without calling
128`close` — that log stays open forever and a `for await` over it never
129finishes. `snapshot` exists for exactly that case: a producer resuming a
130run needs to see the prefix a previous host already stored so it can line
131its own output up against it, and it needs that read to *return*.
132
133Implementations MUST:
134
135- never wait for more entries — resolve with what is stored, including
136 while the log is still open and still being appended to;
137- resolve to an empty array for a run with nothing stored, rather than
138 throwing. In particular an implementation must not reuse the
139 unknown-run failure path a from-start `read` join takes (`read('-1')` on
140 an empty log is allowed to fail; `snapshot()` is not). A backend over a
141 network may of course still reject on a transport, protocol, or
142 authorization failure — that is a failed call, not an empty run;
143- return a fresh array the caller can keep or mutate without reaching the
144 stored log through it.
145
146The result is a point-in-time view and carries no lock: a concurrent
147`append` may land immediately after the snapshot is taken, so a caller
148must not treat the last returned offset as the permanent tail.
149
150#### Returns
151
152`Promise`\<`object`[]\>