MCPcopy Index your code
hub / github.com/anomalyco/opencode / createTuiPluginApi

Function createTuiPluginApi

packages/opencode/test/fixture/tui-plugin.ts:126–355  ·  view source on GitHub ↗
(opts: Opts = {})

Source from the content-addressed store, hash-verified

124}
125
126export function createTuiPluginApi(opts: Opts = {}): HostPluginApi {
127 const kv: Record<string, unknown> = {}
128 const count = opts.count
129 const ctrl = new AbortController()
130 const own = createOpencodeClient({
131 baseUrl: "http://localhost:4096",
132 })
133 const fallback = () => own
134 const read =
135 typeof opts.client === "function"
136 ? opts.client
137 : opts.client
138 ? () => opts.client as HostPluginApi["client"]
139 : fallback
140 const client = () => read()
141 let depth = 0
142 let size: "medium" | "large" | "xlarge" = "medium"
143 const has = opts.theme?.has ?? (() => false)
144 let selected = opts.theme?.selected ?? "opencode"
145 const set =
146 opts.theme?.set ??
147 ((name: string) => {
148 if (!has(name)) return false
149 selected = name
150 return true
151 })
152 const renderer: CliRenderer = opts.renderer ?? {
153 ...Object.create(null),
154 once(this: CliRenderer) {
155 return this
156 },
157 }
158 const keymap =
159 opts.keymap ??
160 ({
161 acquireResource(_key: symbol, setup: () => () => void) {
162 const dispose = setup()
163 return () => {
164 dispose()
165 }
166 },
167 registerLayer() {
168 if (count) count.command_add += 1
169 return () => {
170 if (!count) return
171 count.command_drop += 1
172 }
173 },
174 runCommand() {
175 return { ok: true } as const
176 },
177 } as unknown as HostPluginApi["keymap"])
178
179 function kvGet(name: string): unknown
180 function kvGet<Value>(name: string, fallback: Value): Value
181 function kvGet(name: string, fallback?: unknown) {
182 const value = kv[name]
183 if (value === undefined) return fallback

Callers 9

loadFunction · 0.90
mkApiFunction · 0.90
plugin-add.test.tsFile · 0.90

Calls 7

createOpencodeClientFunction · 0.90
activateMethod · 0.80
hasFunction · 0.70
tuiConfigFunction · 0.70
createMethod · 0.65
listMethod · 0.65
currentMethod · 0.45

Tested by 2

loadFunction · 0.72
mkApiFunction · 0.72