Skip to content

Commit 79b55d4

Browse files
committed
fix(tui): use bridged event stream for data
1 parent 36264cc commit 79b55d4

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

packages/tui/src/context/data.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
import { createStore, produce } from "solid-js/store"
2222
import { createSimpleContext } from "./helper"
2323
import { useSDK } from "./sdk"
24+
import { useEvent } from "./event"
2425
import { createSignal, onCleanup, onMount } from "solid-js"
2526

2627
type LocationData = {
@@ -71,6 +72,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
7172
})
7273

7374
const sdk = useSDK()
75+
const events = useEvent()
7476
const [defaultLocation, setDefaultLocation] = createSignal<LocationRef>({
7577
directory: sdk.directory ?? process.cwd(),
7678
})
@@ -119,12 +121,12 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
119121
},
120122
}
121123

122-
function handleEvent(event: V2Event, metadata: { directory: string; workspace: string | undefined }) {
124+
function handleEvent(event: V2Event) {
123125
switch (event.type) {
124126
case "catalog.updated":
125127
void Promise.all([
126-
result.location.model.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
127-
result.location.provider.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
128+
result.location.model.refresh(event.location),
129+
result.location.provider.refresh(event.location),
128130
])
129131
break
130132
case "session.next.agent.switched":
@@ -404,26 +406,23 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
404406
break
405407
case "integration.updated":
406408
void Promise.all([
407-
result.location.integration.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
408-
result.location.model.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
409-
result.location.provider.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
409+
result.location.integration.refresh(event.location),
410+
result.location.model.refresh(event.location),
411+
result.location.provider.refresh(event.location),
410412
])
411413
break
412414
}
413415
}
414416

415417
onMount(() => {
416-
const controller = new AbortController()
417-
onCleanup(() => controller.abort())
418-
void (async () => {
419-
const events = await sdk.client.v2.event.subscribe({ signal: controller.signal })
420-
for await (const event of events.stream) {
421-
handleEvent(event, {
422-
directory: event.location?.directory ?? defaultLocation().directory,
423-
workspace: event.location?.workspaceID,
424-
})
425-
}
426-
})().catch(() => {})
418+
const unsub = events.subscribe((event, metadata) => {
419+
handleEvent({
420+
...event,
421+
data: event.properties,
422+
location: { directory: metadata.directory, workspaceID: metadata.workspace },
423+
} as V2Event)
424+
})
425+
onCleanup(unsub)
427426
})
428427

429428
const result = {

0 commit comments

Comments
 (0)