Download packages/tui/src/context/event.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 868 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/context/event.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/tui/src/context/event.ts
-
curl -L -o event.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/context/event.ts
868 Bytes
| import type { Event } from "@opencode-ai/sdk/v2" | |
| import { useSDK } from "./sdk" | |
| type EventMetadata = { | |
| directory: string | |
| workspace: string | undefined | |
| } | |
| export function useEvent() { | |
| const sdk = useSDK() | |
| function subscribe(handler: (event: Event, metadata: EventMetadata) => void) { | |
| return sdk.event.on("event", (event) => { | |
| if (event.payload.type === "sync") { | |
| return | |
| } | |
| handler(event.payload, { directory: event.directory, workspace: event.workspace }) | |
| }) | |
| } | |
| function on<T extends Event["type"]>( | |
| type: T, | |
| handler: (event: Extract<Event, { type: T }>, metadata: EventMetadata) => void, | |
| ) { | |
| return subscribe((event: Event, metadata: EventMetadata) => { | |
| if (event.type !== type) return | |
| handler(event as Extract<Event, { type: T }>, metadata) | |
| }) | |
| } | |
| return { | |
| subscribe, | |
| on, | |
| } | |
| } | |