opencode
~/dev/opencode-studio
model claude-sonnet-4 mode build tokens 12,481
[ explorer ]
▾ src
agent.tsM
tools.ts
llm.ts
session.ts
prompt.ts
▾ providers
anthropic.ts
openai.ts
▾ tests
agent.test.ts
▸ node_modules
package.json
tsconfig.json
README.md
.gitignore
branchmain
changes1 modified
ctx3 files
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
build chat @file / commands  ·  ↑↓ history  ·  ⌘↵ send
ctx 3/25 $0.0142
idle main ↑0 ↓1 tools.ts 3 files in context opencode v0.4.1