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

RunDriverOptions.md

193 lines2.8 KB

1---
2id: RunDriverOptions
3title: RunDriverOptions
4---
5​
6Defined in: packages/ai/src/stream-to-response.ts:1166
7​
8Everything the resume helpers need to take a run over as a side effect of
9serving its log.
10​
11`claim` and `pipe` are **injected**, not imported. The two mechanisms a
12takeover needs (`withRunClaim` and `pipeToRunLog`) live in
13`@tanstack/ai-sandbox`, and `@tanstack/ai` must not depend on that package —
14that layering inversion is exactly what moving `LockStore` into core was meant
15to prevent, and it would make core depend on the sandbox package to serve a
16plain chat run. Injecting them keeps only the *shape* of a takeover in core
17(parse the run id, read the record, skip if terminal, claim, drive) and lets a
18background-worker-driven run supply its own pair.
19`@tanstack/ai-sandbox`'s `sandboxRunDriver` fills both in.
20​
21## Properties
22​
23### claim
24​
25```ts
26claim: <T>(input, fn) => Promise<T>;
27```
28​
29Defined in: packages/ai/src/stream-to-response.ts:1178
30​
31Run `fn` under exclusive ownership of the run, or reject if refused.
32​
33#### Type Parameters
34​
35##### T
36​
37`T`
38​
39#### Parameters
40​
41##### input
42​
43###### locks
44​
45`LockStore`
46​
47###### runId
48​
49`string`
50​
51###### runs
52​
53[`RunStore`](RunStore.md)
54​
55##### fn
56​
57(`claim`) => `Promise`\<`T`\>
58​
59#### Returns
60​
61`Promise`\<`T`\>
62​
63***
64​
65### drive
66​
67```ts
68drive: (input) => AsyncIterable<AGUIEvent>;
69```
70​
71Defined in: packages/ai/src/stream-to-response.ts:1172
72​
73Produce the run's remaining events. Called only once the claim is held.
74​
75#### Parameters
76​
77##### input
78​
79###### runId
80​
81`string`
82​
83###### signal
84​
85`AbortSignal`
86​
87###### threadId
88​
89`string`
90​
91#### Returns
92​
93`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>
94​
95***
96​
97### locks
98​
99```ts
100locks: LockStore;
101```
102​
103Defined in: packages/ai/src/stream-to-response.ts:1170
104​
105***
106​
107### logger?
108​
109```ts
110optional logger?: InternalLogger;
111```
112​
113Defined in: packages/ai/src/stream-to-response.ts:1193
114​
115***
116​
117### pipe
118​
119```ts
120pipe: (stream, input) => Promise<unknown>;
121```
122​
123Defined in: packages/ai/src/stream-to-response.ts:1187
124​
125Persist the driven stream to the run's producer-side durability log.
126​
127#### Parameters
128​
129##### stream
130​
131`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>
132​
133##### input
134​
135###### runId
136​
137`string`
138​
139###### signal
140​
141`AbortSignal`
142​
143###### threadId
144​
145`string`
146​
147#### Returns
148​
149`Promise`\<`unknown`\>
150​
151***
152​
153### request
154​
155```ts
156request: Request;
157```
158​
159Defined in: packages/ai/src/stream-to-response.ts:1168
160​
161The attach request; its run id is read with [resolveResumeRunId](../functions/resolveResumeRunId.md).
162​
163***
164​
165### runs
166​
167```ts
168runs: RunStore;
169```
170​
171Defined in: packages/ai/src/stream-to-response.ts:1169
172​
173***
174​
175### waitUntil?
176​
177```ts
178optional waitUntil?: (promise) => void;
179```
180​
181Defined in: packages/ai/src/stream-to-response.ts:1192
182​
183Platform keep-alive (e.g. `ctx.waitUntil`) for the background drive.
184​
185#### Parameters
186​
187##### promise
188​
189`Promise`\<`unknown`\>
190​
191#### Returns
192​
193`void`