From 8743dddde69c304c1009cf6ebda308cf59b501b6 Mon Sep 17 00:00:00 2001 From: Sebastian Herrlinger Date: Wed, 4 Mar 2026 23:08:06 +0100 Subject: [PATCH] cleanup sdk provider --- packages/opencode/src/cli/cmd/tui/app.tsx | 3 +-- .../opencode/src/cli/cmd/tui/context/sdk.tsx | 3 --- packages/opencode/src/cli/cmd/tui/plugin.ts | 23 +++++++++++++------ .../test/cli/tui/plugin-loader.test.ts | 10 ++------ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index 149db14b60..676165deb4 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -150,7 +150,7 @@ export function tui(input: { } const renderer = await createCliRenderer(rendererConfig(input.config)) - const slots = TuiPlugin.slots(renderer) + TuiPlugin.initializeSlots(renderer) await render(() => { return ( @@ -166,7 +166,6 @@ export function tui(input: { { console.error("Failed to load TUI plugins", error) }) diff --git a/packages/opencode/src/cli/cmd/tui/plugin.ts b/packages/opencode/src/cli/cmd/tui/plugin.ts index 4a3aa7261d..6049ed7a46 100644 --- a/packages/opencode/src/cli/cmd/tui/plugin.ts +++ b/packages/opencode/src/cli/cmd/tui/plugin.ts @@ -18,6 +18,7 @@ import { resolvePluginTarget, uniqueModuleEntries } from "@/plugin/shared" import { registerThemes } from "./context/theme" type Slot = (props: { name: K } & TuiSlotMap[K]) => JSX.Element | null +type InitInput = Omit, "slots"> function empty(_props: { name: K } & TuiSlotMap[K]) { return null @@ -57,10 +58,15 @@ export namespace TuiPlugin { const log = Log.create({ service: "tui.plugin" }) let loaded: Promise | undefined let view: Slot = empty + let api: TuiSlots = { + register() { + return () => {} + }, + } export const Slot: Slot = (props) => view(props) - export function slots(renderer: CliRenderer): TuiSlots { + export function initializeSlots(renderer: CliRenderer) { const reg = createSolidSlotRegistry( renderer, {}, @@ -79,8 +85,7 @@ export namespace TuiPlugin { const slot = createSlot(reg) view = (props) => slot(props) - - return { + api = { register(pluginSlot) { if (!isTuiSlotPlugin(pluginSlot)) return () => {} return reg.register(pluginSlot) @@ -88,14 +93,18 @@ export namespace TuiPlugin { } } - export async function init(input: TuiPluginInput) { + export async function init(input: InitInput) { if (loaded) return loaded loaded = load(input) return loaded } - async function load(input: TuiPluginInput) { + async function load(input: InitInput) { const dir = process.cwd() + const ctx: TuiPluginInput = { + ...input, + slots: api, + } await Instance.provide({ directory: dir, @@ -133,11 +142,11 @@ export namespace TuiPlugin { if (theme) registerThemes(theme) const slotPlugin = getTuiSlotPlugin(entry) - if (slotPlugin) input.slots.register(slotPlugin) + if (slotPlugin) ctx.slots.register(slotPlugin) const tuiPlugin = getTuiPlugin(entry) if (!tuiPlugin) continue - await tuiPlugin(input, Config.pluginOptions(item)) + await tuiPlugin(ctx, Config.pluginOptions(item)) } } }, diff --git a/packages/opencode/test/cli/tui/plugin-loader.test.ts b/packages/opencode/test/cli/tui/plugin-loader.test.ts index 221c40ee4e..d1c8107f8a 100644 --- a/packages/opencode/test/cli/tui/plugin-loader.test.ts +++ b/packages/opencode/test/cli/tui/plugin-loader.test.ts @@ -2,7 +2,6 @@ import { expect, mock, spyOn, test } from "bun:test" import fs from "fs/promises" import path from "path" import { pathToFileURL } from "url" -import type { TuiPluginInput } from "@opencode-ai/plugin/tui" import { createOpencodeClient } from "@opencode-ai/sdk/v2" import { tmpdir } from "../../fixture/fixture" import { Log } from "../../../src/util/log" @@ -82,7 +81,7 @@ test("ignores function-only tui exports and loads object exports", async () => { const cwd = spyOn(process, "cwd").mockImplementation(() => tmp.path) try { - const input = { + await TuiPlugin.init({ client: createOpencodeClient({ baseUrl: "http://localhost:4096", }), @@ -90,12 +89,7 @@ test("ignores function-only tui exports and loads object exports", async () => { on: () => () => {}, }, renderer: {}, - slots: { - register: () => () => {}, - }, - } satisfies TuiPluginInput - - await TuiPlugin.init(input) + }) expect(await fs.readFile(tmp.extra.objMarker, "utf8")).toBe("called") await expect(fs.readFile(tmp.extra.fnMarker, "utf8")).rejects.toThrow()