mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-30 17:56:44 +00:00
150 lines
3.4 KiB
TypeScript
150 lines
3.4 KiB
TypeScript
import type { createOpencodeClient as createOpencodeClientV2, Event as TuiEvent } from "@opencode-ai/sdk/v2"
|
|
import type { CliRenderer, ParsedKey, Plugin as CorePlugin } from "@opentui/core"
|
|
import type { Plugin as ServerPlugin, PluginOptions } from "./index"
|
|
|
|
export type { CliRenderer, SlotMode } 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 TuiRouteCurrent =
|
|
| {
|
|
name: "home"
|
|
}
|
|
| {
|
|
name: "session"
|
|
params: {
|
|
sessionID: string
|
|
initialPrompt?: unknown
|
|
}
|
|
}
|
|
| {
|
|
name: string
|
|
params?: Record<string, unknown>
|
|
}
|
|
|
|
export type TuiRouteDefinition<Node = unknown> = {
|
|
name: string
|
|
render: (input: { params?: Record<string, unknown> }) => Node
|
|
}
|
|
|
|
export type TuiCommand = {
|
|
title: string
|
|
value: string
|
|
description?: string
|
|
category?: string
|
|
keybind?: string
|
|
suggested?: boolean
|
|
hidden?: boolean
|
|
enabled?: boolean
|
|
slash?: {
|
|
name: string
|
|
aliases?: string[]
|
|
}
|
|
onSelect?: () => void
|
|
}
|
|
|
|
export type TuiKeybind = {
|
|
name: string
|
|
ctrl: boolean
|
|
meta: boolean
|
|
shift: boolean
|
|
super?: boolean
|
|
leader: boolean
|
|
}
|
|
|
|
export type TuiDialogProps<Node = unknown> = {
|
|
size?: "medium" | "large"
|
|
onClose: () => void
|
|
children?: Node
|
|
}
|
|
|
|
export type TuiToast = {
|
|
variant?: "info" | "success" | "warning" | "error"
|
|
title?: string
|
|
message: string
|
|
duration?: number
|
|
}
|
|
|
|
export type TuiApi<Node = unknown> = {
|
|
command: {
|
|
register: (cb: () => TuiCommand[]) => void
|
|
trigger: (value: string) => void
|
|
}
|
|
route: {
|
|
register: (routes: TuiRouteDefinition<Node>[]) => () => void
|
|
navigate: (name: string, params?: Record<string, unknown>) => void
|
|
readonly current: TuiRouteCurrent
|
|
}
|
|
ui: {
|
|
Dialog: (props: TuiDialogProps<Node>) => Node
|
|
toast: (input: TuiToast) => void
|
|
}
|
|
keybind: {
|
|
parse: (evt: ParsedKey) => TuiKeybind
|
|
match: (key: string, evt: ParsedKey) => boolean
|
|
print: (key: string) => string
|
|
}
|
|
theme: {
|
|
readonly current: Record<string, unknown>
|
|
}
|
|
}
|
|
|
|
export type TuiSlotMap = {
|
|
app: {}
|
|
home_logo: {}
|
|
sidebar_top: {
|
|
session_id: string
|
|
}
|
|
}
|
|
|
|
export type TuiSlotContext = {}
|
|
|
|
export type TuiSlotPlugin<Node = unknown> = CorePlugin<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, Node = unknown> = {
|
|
client: ReturnType<typeof createOpencodeClientV2>
|
|
event: TuiEventBus
|
|
renderer: Renderer
|
|
slots: TuiSlots
|
|
api: TuiApi<Node>
|
|
}
|
|
|
|
export type TuiPlugin<Renderer = CliRenderer, Node = unknown> = (
|
|
input: TuiPluginInput<Renderer, Node>,
|
|
options?: PluginOptions,
|
|
) => Promise<void>
|
|
|
|
export type TuiPluginModule<Renderer = CliRenderer, Node = unknown> = {
|
|
server?: ServerPlugin
|
|
tui?: TuiPlugin<Renderer, Node>
|
|
slots?: TuiSlotPlugin
|
|
themes?: Record<string, ThemeJson>
|
|
}
|