From 1527a2260f9105242a3e362cf60b62b2ea29fd9e Mon Sep 17 00:00:00 2001 From: starptech Date: Fri, 22 May 2026 12:10:06 +0200 Subject: [PATCH] Update plugin and SDK auth types --- packages/opencode/src/plugin/codex.ts | 2 +- packages/opencode/src/plugin/digitalocean.ts | 2 +- packages/opencode/src/plugin/index.ts | 1 - packages/plugin/src/index.ts | 12 ++++++++++-- packages/sdk/js/src/client.ts | 20 ++++++++++++++++---- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/opencode/src/plugin/codex.ts b/packages/opencode/src/plugin/codex.ts index d520750035..ed5b3072ad 100644 --- a/packages/opencode/src/plugin/codex.ts +++ b/packages/opencode/src/plugin/codex.ts @@ -433,7 +433,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise { const tokens = await refreshAccessToken(currentAuth.refresh) const newAccountId = extractAccountId(tokens) || authWithAccount.accountId await input.client.auth.set({ - path: { id: "openai" }, + path: { providerID: "openai" }, body: { type: "oauth", refresh: tokens.refresh_token, diff --git a/packages/opencode/src/plugin/digitalocean.ts b/packages/opencode/src/plugin/digitalocean.ts index 19d1364875..4cd32a4d5f 100644 --- a/packages/opencode/src/plugin/digitalocean.ts +++ b/packages/opencode/src/plugin/digitalocean.ts @@ -332,7 +332,7 @@ export async function DigitalOceanAuthPlugin(input: PluginInput): Promise } await input.client.auth .set({ - path: { id: "digitalocean" }, + path: { providerID: "digitalocean" }, body: { type: "api", key: ctx.auth.key, metadata: updated }, }) .catch((err) => log.warn("failed to persist refreshed routers", { error: err })) diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index a9a5067677..50c429ddf2 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/packages/opencode/src/plugin/index.ts @@ -124,7 +124,6 @@ export const layer = Layer.effect( } const { Server } = yield* Effect.promise(() => import("../server/server")) - const client = createOpencodeClient({ baseUrl: "http://localhost:4096", directory: ctx.directory, diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 6156477be2..43ba7c3567 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -4,7 +4,7 @@ import type { Project, Model, Provider, - Permission, + PermissionRequest, UserMessage, Message, Part, @@ -67,8 +67,16 @@ export type PluginInput = { export type PluginOptions = Record +type TuiConfig = { + scroll_speed?: number + scroll_acceleration?: { enabled?: boolean } + diff_style?: "auto" | "stacked" +} + export type Config = Omit & { plugin?: Array + theme?: string + tui?: TuiConfig } export type Plugin = (input: PluginInput, options?: PluginOptions) => Promise @@ -257,7 +265,7 @@ export interface Hooks { input: { sessionID: string; agent: string; model: Model; provider: ProviderContext; message: UserMessage }, output: { headers: Record }, ) => Promise - "permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise + "permission.ask"?: (input: PermissionRequest, output: { status: "ask" | "deny" | "allow" }) => Promise "command.execute.before"?: ( input: { command: string; sessionID: string; arguments: string }, output: { parts: Part[] }, diff --git a/packages/sdk/js/src/client.ts b/packages/sdk/js/src/client.ts index 5cf071e7b7..250bdb9c92 100644 --- a/packages/sdk/js/src/client.ts +++ b/packages/sdk/js/src/client.ts @@ -4,7 +4,10 @@ import { createClient } from "./gen/client/client.gen.js" import { type Config } from "./gen/client/types.gen.js" import { OpencodeClient } from "./gen/sdk.gen.js" import { wrapClientError } from "./error-interceptor.js" -export { type Config as OpencodeClientConfig, OpencodeClient } +export { OpencodeClient } + +type Fetch = (request: Request) => ReturnType +export type OpencodeClientConfig = Omit & { fetch?: Fetch; directory?: string } function pick(value: string | null, fallback?: string) { if (!value) return @@ -30,9 +33,18 @@ function rewrite(request: Request, directory?: string) { return next } -export function createOpencodeClient(config?: Config & { directory?: string }) { +function toFetch(input: Fetch | undefined): typeof fetch | undefined { + if (!input) return + return Object.assign( + async (value: Parameters[0], init?: Parameters[1]) => + input(value instanceof Request && init === undefined ? value : new Request(value, init)), + fetch, + ) +} + +export function createOpencodeClient(config?: OpencodeClientConfig) { if (!config?.fetch) { - const customFetch: any = (req: any) => { + const customFetch: Fetch = (req) => { // @ts-ignore req.timeout = false return fetch(req) @@ -50,7 +62,7 @@ export function createOpencodeClient(config?: Config & { directory?: string }) { } } - const client = createClient(config) + const client = createClient({ ...config, fetch: toFetch(config?.fetch) }) client.interceptors.request.use((request) => rewrite(request, config?.directory)) client.interceptors.error.use(wrapClientError) return new OpencodeClient({ client })