|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
import { createStore, produce } from "solid-js/store"
|
|
|
import { createSimpleContext } from "./helper"
|
|
|
import { useSDK } from "./sdk"
|
|
|
+import { useEvent } from "./event"
|
|
|
import { createSignal, onCleanup, onMount } from "solid-js"
|
|
|
|
|
|
type LocationData = {
|
|
|
@@ -71,6 +72,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
|
|
})
|
|
|
|
|
|
const sdk = useSDK()
|
|
|
+ const events = useEvent()
|
|
|
const [defaultLocation, setDefaultLocation] = createSignal<LocationRef>({
|
|
|
directory: sdk.directory ?? process.cwd(),
|
|
|
})
|
|
|
@@ -119,12 +121,12 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- function handleEvent(event: V2Event, metadata: { directory: string; workspace: string | undefined }) {
|
|
|
+ function handleEvent(event: V2Event) {
|
|
|
switch (event.type) {
|
|
|
case "catalog.updated":
|
|
|
void Promise.all([
|
|
|
- result.location.model.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
|
|
- result.location.provider.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
|
|
+ result.location.model.refresh(event.location),
|
|
|
+ result.location.provider.refresh(event.location),
|
|
|
])
|
|
|
break
|
|
|
case "session.next.agent.switched":
|
|
|
@@ -404,26 +406,23 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
|
|
|
break
|
|
|
case "integration.updated":
|
|
|
void Promise.all([
|
|
|
- result.location.integration.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
|
|
- result.location.model.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
|
|
- result.location.provider.refresh({ directory: metadata.directory, workspaceID: metadata.workspace }),
|
|
|
+ result.location.integration.refresh(event.location),
|
|
|
+ result.location.model.refresh(event.location),
|
|
|
+ result.location.provider.refresh(event.location),
|
|
|
])
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
|
|
|
onMount(() => {
|
|
|
- const controller = new AbortController()
|
|
|
- onCleanup(() => controller.abort())
|
|
|
- void (async () => {
|
|
|
- const events = await sdk.client.v2.event.subscribe({ signal: controller.signal })
|
|
|
- for await (const event of events.stream) {
|
|
|
- handleEvent(event, {
|
|
|
- directory: event.location?.directory ?? defaultLocation().directory,
|
|
|
- workspace: event.location?.workspaceID,
|
|
|
- })
|
|
|
- }
|
|
|
- })().catch(() => {})
|
|
|
+ const unsub = events.subscribe((event, metadata) => {
|
|
|
+ handleEvent({
|
|
|
+ ...event,
|
|
|
+ data: event.properties,
|
|
|
+ location: { directory: metadata.directory, workspaceID: metadata.workspace },
|
|
|
+ } as V2Event)
|
|
|
+ })
|
|
|
+ onCleanup(unsub)
|
|
|
})
|
|
|
|
|
|
const result = {
|