Defined in: packages/ai/src/stream-to-response.ts:1166
Everything the resume helpers need to take a run over as a side effect of serving its log.
claim and pipe are injected, not imported. The two mechanisms a
takeover needs (withRunClaim and pipeToRunLog) live in
@tanstack/ai-sandbox, and @tanstack/ai must not depend on that package —
that layering inversion is exactly what moving LockStore into core was meant
to prevent, and it would make core depend on the sandbox package to serve a
plain chat run. Injecting them keeps only the shape of a takeover in core
(parse the run id, read the record, skip if terminal, claim, drive) and lets a
background-worker-driven run supply its own pair.
@tanstack/ai-sandbox's sandboxRunDriver fills both in.
Properties#
claim#
claim: <T>(input, fn) => Promise<T>;
Defined in: packages/ai/src/stream-to-response.ts:1178
Run fn under exclusive ownership of the run, or reject if refused.
Type Parameters#
T#
T
Parameters#
input#
locks#
LockStore
runId#
string
runs#
fn#
(claim) => Promise<T>
Returns#
Promise<T>
drive#
drive: (input) => AsyncIterable<AGUIEvent>;
Defined in: packages/ai/src/stream-to-response.ts:1172
Produce the run's remaining events. Called only once the claim is held.
Parameters#
input#
runId#
string
signal#
AbortSignal
threadId#
string
Returns#
AsyncIterable<AGUIEvent>
locks#
locks: LockStore;
Defined in: packages/ai/src/stream-to-response.ts:1170
logger?#
optional logger?: InternalLogger;
Defined in: packages/ai/src/stream-to-response.ts:1193
pipe#
pipe: (stream, input) => Promise<unknown>;
Defined in: packages/ai/src/stream-to-response.ts:1187
Persist the driven stream to the run's producer-side durability log.
Parameters#
stream#
AsyncIterable<AGUIEvent>
input#
runId#
string
signal#
AbortSignal
threadId#
string
Returns#
Promise<unknown>
request#
request: Request;
Defined in: packages/ai/src/stream-to-response.ts:1168
The attach request; its run id is read with resolveResumeRunId.
runs#
runs: RunStore;
Defined in: packages/ai/src/stream-to-response.ts:1169
waitUntil?#
optional waitUntil?: (promise) => void;
Defined in: packages/ai/src/stream-to-response.ts:1192
Platform keep-alive (e.g. ctx.waitUntil) for the background drive.
Parameters#
promise#
Promise<unknown>
Returns#
void