Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions packages/opencode/src/cli/ink/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@ export const App = (): ReactElement => {
// Initialize session on mount
useEffect(() => {
const initSession = async () => {
const session = await Session.createNext({ directory: Instance.directory })
const agent = await Agent.defaultAgent()
dispatch({
type: "SET_SESSION",
payload: {
id: session.id,
agent,
model: null,
},
})
try {
const session = await Session.createNext({ directory: Instance.directory })
const agent = await Agent.defaultAgent()
dispatch({
type: "SET_SESSION",
payload: {
id: session.id,
agent,
model: null,
},
})
} catch (error) {
console.error("Session init failed:", error)
dispatch({
type: "STREAM_TEXT",
payload: `Error: Failed to initialize session - ${error}\n`,
})
}
}
initSession().catch(console.error)
initSession()
}, [])

// Use SDK events hook for streaming
Expand All @@ -50,7 +58,14 @@ export const App = (): ReactElement => {
}).catch(() => {
// Silently handle command errors
})
} else if (value.trim() && state.session.id) {
} else if (value.trim()) {
if (!state.session.id) {
dispatch({
type: "STREAM_TEXT",
payload: "Waiting for session to initialize...\n",
})
return
}
// Send message via SDK hook
await sendMessage(value.trim())
}
Expand Down
11 changes: 11 additions & 0 deletions packages/opencode/src/cli/ink/hooks/useSDKEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ function handleEvent(
const part = event.properties.part
if (part.sessionID !== sessionId) return

// Handle text streaming
if (part.type === "text") {
const delta = event.properties.delta
if (delta) {
dispatch({
type: "STREAM_TEXT",
payload: delta,
})
}
}

if (part.type === "tool") {
const toolState = part.state

Expand Down
Loading