mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-30 17:56:44 +00:00
separate tui from server plugin
This commit is contained in:
86
packages/plugin/src/tui.ts
Normal file
86
packages/plugin/src/tui.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import type { createOpencodeClient as createOpencodeClientV2, Event as TuiEvent } from "@opencode-ai/sdk/v2"
|
||||
import type { CliRenderer } from "@opentui/core"
|
||||
import type { Plugin, PluginOptions } from "./index"
|
||||
|
||||
export type { CliRenderer } from "@opentui/core"
|
||||
|
||||
type HexColor = `#${string}`
|
||||
type RefName = string
|
||||
type Variant = {
|
||||
dark: HexColor | RefName | number
|
||||
light: HexColor | RefName | number
|
||||
}
|
||||
type ThemeColorValue = HexColor | RefName | number | Variant
|
||||
|
||||
export type ThemeJson = {
|
||||
$schema?: string
|
||||
defs?: Record<string, HexColor | RefName>
|
||||
theme: Record<string, ThemeColorValue> & {
|
||||
selectedListItemText?: ThemeColorValue
|
||||
backgroundMenu?: ThemeColorValue
|
||||
thinkingOpacity?: number
|
||||
}
|
||||
}
|
||||
|
||||
export type SlotMode = "append" | "replace" | "single_winner"
|
||||
|
||||
type SlotRenderer<Node, Props, Context extends object = object> = (ctx: Readonly<Context>, props: Props) => Node
|
||||
|
||||
type SlotPlugin<Node, Slots extends object, Context extends object = object> = {
|
||||
id: string
|
||||
order?: number
|
||||
setup?: (ctx: Readonly<Context>, renderer: CliRenderer) => void
|
||||
dispose?: () => void
|
||||
slots: {
|
||||
[K in keyof Slots]?: SlotRenderer<Node, Slots[K], Context>
|
||||
}
|
||||
}
|
||||
|
||||
export type TuiSlotMap = {
|
||||
home_hint: {}
|
||||
home_footer: {}
|
||||
session_footer: {
|
||||
session_id: string
|
||||
}
|
||||
}
|
||||
|
||||
export type TuiSlotContext = {
|
||||
url: string
|
||||
directory?: string
|
||||
}
|
||||
|
||||
export type TuiSlotPlugin<Node = unknown> = SlotPlugin<Node, TuiSlotMap, TuiSlotContext>
|
||||
|
||||
export type TuiSlots = {
|
||||
register: (plugin: TuiSlotPlugin) => () => void
|
||||
}
|
||||
|
||||
export type TuiEventBus = {
|
||||
on: <Type extends TuiEvent["type"]>(
|
||||
type: Type,
|
||||
handler: (event: Extract<TuiEvent, { type: Type }>) => void,
|
||||
) => () => void
|
||||
}
|
||||
|
||||
export type TuiPluginInput<Renderer = CliRenderer> = {
|
||||
client: ReturnType<typeof createOpencodeClientV2>
|
||||
event: TuiEventBus
|
||||
url: string
|
||||
directory?: string
|
||||
renderer: Renderer
|
||||
slots: TuiSlots
|
||||
}
|
||||
|
||||
export type TuiPlugin<Renderer = CliRenderer> = (
|
||||
input: TuiPluginInput<Renderer>,
|
||||
options?: PluginOptions,
|
||||
) => Promise<void>
|
||||
|
||||
export type TuiPluginModule<Renderer = CliRenderer> =
|
||||
| TuiPlugin<Renderer>
|
||||
| {
|
||||
server?: Plugin
|
||||
tui?: TuiPlugin<Renderer>
|
||||
slots?: TuiSlotPlugin
|
||||
themes?: Record<string, ThemeJson>
|
||||
}
|
||||
Reference in New Issue
Block a user