MCPcopy
hub / github.com/TanStack/ai / buildRunStream

Function buildRunStream

packages/ai-sandbox-cloudflare/src/chat-coordinator.ts:118–140  ·  view source on GitHub ↗

* Run `chat()` IN the DO, streaming its `StreamChunk`s. `stream: true` (with no * outputSchema) makes chat() return an `AsyncIterable ` directly — * no cast needed for the run driver. Both middlewares run `setup` before * streaming begins: our middleware provides the DO-backed b

(
    input: StartRunInput,
  )

Source from the content-addressed store, hash-verified

116 * and `withSandbox` provides the sandbox handle the harness adapter needs.
117 */
118 protected override buildRunStream(
119 input: StartRunInput,
120 ): AsyncIterable<StreamChunk> {
121 const { adapter, sandbox, tools, systemPrompts } = this.config(input)
122 const sessionId = input.metadata?.sessionId
123 const modelOptions =
124 typeof sessionId === 'string' && sessionId !== ''
125 ? { sessionId }
126 : undefined
127 return chat({
128 threadId: input.threadId,
129 adapter,
130 messages: input.messages,
131 stream: true,
132 ...(tools !== undefined ? { tools } : {}),
133 ...(systemPrompts !== undefined ? { systemPrompts } : {}),
134 ...(modelOptions !== undefined ? { modelOptions } : {}),
135 middleware: [
136 this.bridgeProvisionerMiddleware(input),
137 withSandbox(sandbox),
138 ],
139 })
140 }
141
142 /** Drop the per-run bridge once the run is terminal (override from base). */
143 protected override onRunSettled(runId: string): void {

Callers

nothing calls this directly

Calls 3

chatFunction · 0.90
withSandboxFunction · 0.90
configMethod · 0.45

Tested by

no test coverage detected