Skip to content

Commit 193dca9

Browse files
committed
fix(tui): align plugin with snapshot tui api
1 parent 44b15b4 commit 193dca9

3 files changed

Lines changed: 126 additions & 74 deletions

File tree

tui/shared/names.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export const LABEL = "DCP"
22

33
export const NAMES = {
4-
slot: "dcp.sidebar",
54
routes: {
65
summary: "dcp.summary",
76
},

tui/slots/sidebar-top.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,9 @@ export const createSidebarTopSlot = (
489489
}
490490

491491
return {
492-
id: names.slot,
493492
order: 90,
494493
slots: {
495494
sidebar_content: renderSidebar,
496-
sidebar_top: renderSidebar,
497495
},
498496
}
499497
}

tui/types/opencode-plugin-tui.d.ts

Lines changed: 126 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@ declare module "@opencode-ai/plugin/tui" {
55
LspStatus,
66
McpStatus,
77
Todo,
8+
Message,
9+
Part,
10+
Provider,
11+
PermissionRequest,
12+
QuestionRequest,
13+
SessionStatus,
14+
Workspace,
15+
Config as SdkConfig,
816
} from "@opencode-ai/sdk/v2"
9-
import type { CliRenderer, ParsedKey, Plugin as CorePlugin, SlotMode } from "@opentui/core"
10-
import type { JSX } from "@opentui/solid"
17+
18+
import type { CliRenderer, ParsedKey, RGBA } from "@opentui/core"
19+
import type { JSX, SolidPlugin } from "@opentui/solid"
1120
import type { Plugin as ServerPlugin } from "@opencode-ai/plugin"
1221

13-
export type { CliRenderer, SlotMode }
22+
// PluginOptions = Record<string, unknown> — not yet exported by installed @opencode-ai/plugin
23+
type PluginOptions = Record<string, unknown>
24+
25+
export type { CliRenderer }
26+
export type { SlotMode } from "@opentui/core"
1427

1528
export type TuiRouteCurrent =
1629
| {
@@ -133,8 +146,64 @@ declare module "@opencode-ai/plugin/tui" {
133146
duration?: number
134147
}
135148

149+
export type TuiThemeCurrent = {
150+
readonly primary: RGBA
151+
readonly secondary: RGBA
152+
readonly accent: RGBA
153+
readonly error: RGBA
154+
readonly warning: RGBA
155+
readonly success: RGBA
156+
readonly info: RGBA
157+
readonly text: RGBA
158+
readonly textMuted: RGBA
159+
readonly selectedListItemText: RGBA
160+
readonly background: RGBA
161+
readonly backgroundPanel: RGBA
162+
readonly backgroundElement: RGBA
163+
readonly backgroundMenu: RGBA
164+
readonly border: RGBA
165+
readonly borderActive: RGBA
166+
readonly borderSubtle: RGBA
167+
readonly diffAdded: RGBA
168+
readonly diffRemoved: RGBA
169+
readonly diffContext: RGBA
170+
readonly diffHunkHeader: RGBA
171+
readonly diffHighlightAdded: RGBA
172+
readonly diffHighlightRemoved: RGBA
173+
readonly diffAddedBg: RGBA
174+
readonly diffRemovedBg: RGBA
175+
readonly diffContextBg: RGBA
176+
readonly diffLineNumber: RGBA
177+
readonly diffAddedLineNumberBg: RGBA
178+
readonly diffRemovedLineNumberBg: RGBA
179+
readonly markdownText: RGBA
180+
readonly markdownHeading: RGBA
181+
readonly markdownLink: RGBA
182+
readonly markdownLinkText: RGBA
183+
readonly markdownCode: RGBA
184+
readonly markdownBlockQuote: RGBA
185+
readonly markdownEmph: RGBA
186+
readonly markdownStrong: RGBA
187+
readonly markdownHorizontalRule: RGBA
188+
readonly markdownListItem: RGBA
189+
readonly markdownListEnumeration: RGBA
190+
readonly markdownImage: RGBA
191+
readonly markdownImageText: RGBA
192+
readonly markdownCodeBlock: RGBA
193+
readonly syntaxComment: RGBA
194+
readonly syntaxKeyword: RGBA
195+
readonly syntaxFunction: RGBA
196+
readonly syntaxVariable: RGBA
197+
readonly syntaxString: RGBA
198+
readonly syntaxNumber: RGBA
199+
readonly syntaxType: RGBA
200+
readonly syntaxOperator: RGBA
201+
readonly syntaxPunctuation: RGBA
202+
readonly thinkingOpacity: number
203+
}
204+
136205
export type TuiTheme = {
137-
readonly current: Record<string, unknown>
206+
readonly current: TuiThemeCurrent
138207
readonly selected: string
139208
has: (name: string) => boolean
140209
set: (name: string) => boolean
@@ -150,15 +219,52 @@ declare module "@opencode-ai/plugin/tui" {
150219
}
151220

152221
export type TuiState = {
222+
readonly ready: boolean
223+
readonly config: SdkConfig
224+
readonly provider: ReadonlyArray<Provider>
225+
readonly path: {
226+
state: string
227+
config: string
228+
worktree: string
229+
directory: string
230+
}
231+
readonly vcs: { branch?: string } | undefined
232+
readonly workspace: {
233+
list: () => ReadonlyArray<Workspace>
234+
get: (workspaceID: string) => Workspace | undefined
235+
}
153236
session: {
237+
count: () => number
154238
diff: (sessionID: string) => ReadonlyArray<TuiSidebarFileItem>
155239
todo: (sessionID: string) => ReadonlyArray<TuiSidebarTodoItem>
240+
messages: (sessionID: string) => ReadonlyArray<Message>
241+
status: (sessionID: string) => SessionStatus | undefined
242+
permission: (sessionID: string) => ReadonlyArray<PermissionRequest>
243+
question: (sessionID: string) => ReadonlyArray<QuestionRequest>
156244
}
245+
part: (messageID: string) => ReadonlyArray<Part>
157246
lsp: () => ReadonlyArray<TuiSidebarLspItem>
158247
mcp: () => ReadonlyArray<TuiSidebarMcpItem>
159248
}
160249

250+
// Inlined: Pick<PluginConfig, "$schema" | "theme" | "keybinds" | "plugin"> & NonNullable<PluginConfig["tui"]>
251+
// PluginConfig (opencode.json schema) is not re-exported by @opencode-ai/plugin at installed version.
252+
type TuiConfigView = Record<string, unknown>
253+
254+
type Frozen<Value> = Value extends (...args: never[]) => unknown
255+
? Value
256+
: Value extends ReadonlyArray<infer Item>
257+
? ReadonlyArray<Frozen<Item>>
258+
: Value extends object
259+
? { readonly [Key in keyof Value]: Frozen<Value[Key]> }
260+
: Value
261+
262+
export type TuiApp = {
263+
readonly version: string
264+
}
265+
161266
export type TuiApi = {
267+
app: TuiApp
162268
command: {
163269
register: (cb: () => TuiCommand[]) => () => void
164270
trigger: (value: string) => void
@@ -182,6 +288,7 @@ declare module "@opencode-ai/plugin/tui" {
182288
print: (key: string) => string
183289
create: (defaults: TuiKeybindMap, overrides?: Record<string, unknown>) => TuiKeybindSet
184290
}
291+
readonly tuiConfig: Frozen<TuiConfigView>
185292
kv: TuiKV
186293
state: TuiState
187294
theme: TuiTheme
@@ -206,88 +313,30 @@ declare module "@opencode-ai/plugin/tui" {
206313
export type TuiSlotMap = {
207314
app: {}
208315
home_logo: {}
209-
home_tips: {
210-
show_tips: boolean
211-
tips_hidden: boolean
212-
first_time_user: boolean
213-
}
214-
home_below_tips: {
215-
show_tips: boolean
216-
tips_hidden: boolean
217-
first_time_user: boolean
218-
}
219-
sidebar_top: {
220-
session_id: string
221-
}
222-
sidebar_content: {
223-
session_id: string
224-
}
316+
home_bottom: {}
225317
sidebar_title: {
226318
session_id: string
227319
title: string
228320
share_url?: string
229321
}
230-
sidebar_context: {
231-
session_id: string
232-
tokens: number
233-
percentage: number | null
234-
cost: number
235-
}
236-
sidebar_mcp: {
237-
session_id: string
238-
items: TuiSidebarMcpItem[]
239-
connected: number
240-
errors: number
241-
}
242-
sidebar_lsp: {
243-
session_id: string
244-
items: TuiSidebarLspItem[]
245-
disabled: boolean
246-
}
247-
sidebar_todo: {
248-
session_id: string
249-
items: TuiSidebarTodoItem[]
250-
}
251-
sidebar_files: {
252-
session_id: string
253-
items: TuiSidebarFileItem[]
254-
}
255-
sidebar_getting_started: {
256-
session_id: string
257-
show_getting_started: boolean
258-
has_providers: boolean
259-
dismissed: boolean
260-
}
261-
sidebar_directory: {
322+
sidebar_content: {
262323
session_id: string
263-
directory: string
264-
directory_parent: string
265-
directory_name: string
266324
}
267-
sidebar_version: {
325+
sidebar_footer: {
268326
session_id: string
269-
version: string
270-
}
271-
sidebar_bottom: {
272-
session_id: string
273-
directory: string
274-
directory_parent: string
275-
directory_name: string
276-
version: string
277-
show_getting_started: boolean
278-
has_providers: boolean
279-
dismissed: boolean
280327
}
281328
}
282329

283330
export type TuiSlotContext = {
284331
theme: TuiTheme
285332
}
286333

287-
export type TuiSlotPlugin = CorePlugin<JSX.Element, TuiSlotMap, TuiSlotContext>
334+
export type TuiSlotPlugin = Omit<SolidPlugin<TuiSlotMap, TuiSlotContext>, "id"> & {
335+
id?: never
336+
}
288337

289338
export type TuiSlots = {
290-
register: (plugin: TuiSlotPlugin) => () => void
339+
register: (plugin: TuiSlotPlugin) => string
291340
}
292341

293342
export type TuiEventBus = {
@@ -325,8 +374,15 @@ declare module "@opencode-ai/plugin/tui" {
325374
state: TuiPluginState
326375
}
327376

377+
export type TuiWorkspace = {
378+
current: () => string | undefined
379+
set: (workspaceID?: string) => void
380+
}
381+
328382
export type TuiHostPluginApi<Renderer = CliRenderer> = TuiApi & {
329383
client: ReturnType<typeof createOpencodeClientV2>
384+
scopedClient: (workspaceID?: string) => ReturnType<typeof createOpencodeClientV2>
385+
workspace: TuiWorkspace
330386
event: TuiEventBus
331387
renderer: Renderer
332388
}
@@ -338,13 +394,12 @@ declare module "@opencode-ai/plugin/tui" {
338394

339395
export type TuiPlugin<Renderer = CliRenderer> = (
340396
api: TuiPluginApi<Renderer>,
341-
options: Record<string, unknown> | undefined,
397+
options: PluginOptions | undefined,
342398
meta: TuiPluginMeta,
343399
) => Promise<void>
344400

345401
export type TuiPluginModule<Renderer = CliRenderer> = {
346402
server?: ServerPlugin
347403
tui?: TuiPlugin<Renderer>
348-
slots?: TuiSlotPlugin
349404
}
350405
}

0 commit comments

Comments
 (0)