MCPcopy Create free account
hub / github.com/anomalyco/opencode / pluginApi

Function pluginApi

packages/opencode/src/plugin/tui/runtime.ts:572–651  ·  view source on GitHub ↗
(runtime: RuntimeState, plugin: PluginEntry, scope: PluginScope, base: string)

Source from the content-addressed store, hash-verified

570}
571
572function pluginApi(runtime: RuntimeState, plugin: PluginEntry, scope: PluginScope, base: string): TuiPluginApi {
573 const api = runtime.api
574 const host = runtime.slots
575 const load = plugin.load
576
577 const route: TuiPluginApi["route"] = {
578 register(list) {
579 return scope.track(api.route.register(list))
580 },
581 navigate(name, params) {
582 api.route.navigate(name, params)
583 },
584 get current() {
585 return api.route.current
586 },
587 }
588
589 const theme: TuiPluginApi["theme"] = Object.assign(Object.create(api.theme), {
590 install: createThemeInstaller(load.origin, load.plugin_root, load.spec, plugin),
591 })
592
593 const event: TuiPluginApi["event"] = {
594 on(type, handler) {
595 return scope.track(api.event.on(type, handler))
596 },
597 }
598
599 const keymap = createScopedKeymap(api.keymap, scope)
600
601 let count = 0
602
603 const slots: TuiPluginApi["slots"] = {
604 register(plugin: TuiSlotPlugin) {
605 const id = count ? `${base}:${count}` : base
606 count += 1
607 scope.track(host.register({ ...plugin, id }))
608 return id
609 },
610 }
611
612 return {
613 app: api.app,
614 attention: createScopedAttention(api.attention, scope, load.plugin_root),
615 // Keep deprecated `api.command` working for v1 plugins; remove in v2.
616 command: createCommandShim(keymap, api.ui.dialog, api.tuiConfig.keybinds),
617 keys: api.keys,
618 keymap,
619 mode: createScopedMode(api.mode, scope),
620 route,
621 ui: api.ui,
622 tuiConfig: api.tuiConfig,
623 kv: api.kv,
624 state: api.state,
625 theme,
626 get client() {
627 return api.client
628 },
629 event,

Callers 1

activatePluginEntryFunction · 0.85

Calls 6

createCommandShimFunction · 0.90
createThemeInstallerFunction · 0.85
createScopedKeymapFunction · 0.85
createScopedAttentionFunction · 0.85
createScopedModeFunction · 0.85
createMethod · 0.65

Tested by

no test coverage detected