Download packages/tui/src/plugin/api.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/plugin/api.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/tui/src/plugin/api.ts
-
curl -L -o api.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/plugin/api.ts
1.36 kB
| import type { TuiPluginApi, TuiRouteDefinition } from "@opencode-ai/plugin/tui" | |
| import { createSignal } from "solid-js" | |
| type RouteEntry = { | |
| key: symbol | |
| render: TuiRouteDefinition["render"] | |
| } | |
| export type RouteMap = Map<string, RouteEntry[]> | |
| export function createPluginRoutes() { | |
| const routes: RouteMap = new Map() | |
| const [revision, setRevision] = createSignal(0) | |
| return { | |
| register(list: TuiRouteDefinition[]) { | |
| const key = Symbol() | |
| list.forEach((item) => routes.set(item.name, [...(routes.get(item.name) ?? []), { key, render: item.render }])) | |
| setRevision((value) => value + 1) | |
| return () => { | |
| list.forEach((item) => { | |
| const next = routes.get(item.name)?.filter((entry) => entry.key !== key) ?? [] | |
| if (next.length) { | |
| routes.set(item.name, next) | |
| return | |
| } | |
| routes.delete(item.name) | |
| }) | |
| setRevision((value) => value + 1) | |
| } | |
| }, | |
| get(name: string) { | |
| revision() | |
| return routes.get(name)?.at(-1)?.render | |
| }, | |
| } | |
| } | |
| export type PluginRoutes = ReturnType<typeof createPluginRoutes> | |
| export function createTuiApi(input: Omit<TuiPluginApi, "lifecycle">): TuiPluginApi { | |
| return { | |
| ...input, | |
| lifecycle: { | |
| signal: new AbortController().signal, | |
| onDispose() { | |
| return () => {} | |
| }, | |
| }, | |
| } | |
| } | |