chat 4
diff +6
logs
▸ you
add a streaming method to the Agent class so tokens render in the UI as they arrive
◂ opencode · claude-sonnet-4 · 1.2s
I'll add an async generator
stream() that wraps generateText and yields the text stream. Reading the current src/agent.ts first.readsrc/agent.ts18 lines
writesrc/agent.ts✓ applied
@@ -20,6 +20,13 @@ export class Agent {
+ // Stream tokens to the UI as they arrive
+ async *stream(input: string) {
+ const res = await generateText({
+ model: this.model, tools: this.tools, input,
+ });
+ yield* res.textStream;
+ }
}
bashtsc --noEmit✓ exit 0
$ tsc --noEmit
✔ no type errors (0.8s)
◂ opencode
Added
stream() to src/agent.ts — an async generator yielding res.textStream. Type-check passes. The diff is on the diff tab (6 lines added).
❯
now wire it into the TUI render loop