mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: use async iterable event stream for live tool updates
This commit is contained in:
parent
5355143960
commit
debe18f58f
1 changed files with 9 additions and 7 deletions
|
|
@ -100,15 +100,17 @@ app.message(async ({ message, say }) => {
|
|||
// Start listening to events for this session
|
||||
const eventStream = await client.event.subscribe()
|
||||
|
||||
eventStream.addEventListener("message", (event: any) => {
|
||||
const data = JSON.parse(event.data)
|
||||
if (data.type === "message.part.updated" && data.properties.part.sessionID === createResult.data.id) {
|
||||
const part = data.properties.part
|
||||
if (part.type === "tool") {
|
||||
handleToolUpdate(part, channel, thread)
|
||||
// Listen for events in the background
|
||||
;(async () => {
|
||||
for await (const event of eventStream.stream) {
|
||||
if (event.type === "message.part.updated" && event.properties.part.sessionID === createResult.data.id) {
|
||||
const part = event.properties.part
|
||||
if (part.type === "tool") {
|
||||
handleToolUpdate(part, channel, thread)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})()
|
||||
|
||||
session = { client, server, sessionId: createResult.data.id, channel, thread, eventStream }
|
||||
sessions.set(sessionKey, session)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue