MCPcopy
hub / github.com/anomalyco/opencode / createPluginRoutes

Function createPluginRoutes

packages/tui/src/plugin/api.ts:11–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9export type RouteMap = Map<string, RouteEntry[]>
10
11export function createPluginRoutes() {
12 const routes: RouteMap = new Map()
13 const [revision, setRevision] = createSignal(0)
14
15 return {
16 register(list: TuiRouteDefinition[]) {
17 const key = Symbol()
18 list.forEach((item) => routes.set(item.name, [...(routes.get(item.name) ?? []), { key, render: item.render }]))
19 setRevision((value) => value + 1)
20
21 return () => {
22 list.forEach((item) => {
23 const next = routes.get(item.name)?.filter((entry) => entry.key !== key) ?? []
24 if (next.length) {
25 routes.set(item.name, next)
26 return
27 }
28 routes.delete(item.name)
29 })
30 setRevision((value) => value + 1)
31 }
32 },
33 get(name: string) {
34 revision()
35 return routes.get(name)?.at(-1)?.render
36 },
37 }
38}
39
40export type PluginRoutes = ReturnType<typeof createPluginRoutes>
41

Callers 1

createPluginRuntimeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected