diff --git a/packages/opencode/src/plugin/codex.ts b/packages/opencode/src/plugin/codex.ts index fc172dad939..68dd711effc 100644 --- a/packages/opencode/src/plugin/codex.ts +++ b/packages/opencode/src/plugin/codex.ts @@ -397,9 +397,9 @@ export async function CodexAuthPlugin(input: PluginInput): Promise { log.info("refreshing codex access token") const tokens = await refreshAccessToken(currentAuth.refresh) const newAccountId = extractAccountId(tokens) || authWithAccount.accountId - await input.client.auth.set({ - path: { id: "codex" }, - body: { + await input.clientNext.auth.set({ + providerID: "codex", + auth: { type: "oauth", refresh: tokens.refresh_token, access: tokens.access_token, diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index 84de520b81d..c7c57485be9 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/packages/opencode/src/plugin/index.ts @@ -2,7 +2,8 @@ import type { Hooks, PluginInput, Plugin as PluginInstance } from "@opencode-ai/ import { Config } from "../config/config" import { Bus } from "../bus" import { Log } from "../util/log" -import { createOpencodeClient } from "@opencode-ai/sdk" +import { createOpencodeClient as createV2Client } from "@opencode-ai/sdk/v2" +import { createOpencodeClient as createV1Client } from "@opencode-ai/sdk" import { Server } from "../server/server" import { BunProc } from "../bun" import { Instance } from "../project/instance" @@ -21,7 +22,12 @@ export namespace Plugin { const INTERNAL_PLUGINS: PluginInstance[] = [CodexAuthPlugin, CopilotAuthPlugin] const state = Instance.state(async () => { - const client = createOpencodeClient({ + const client = createV1Client({ + baseUrl: "http://localhost:4096", + // @ts-ignore - fetch type incompatibility + fetch: async (...args) => Server.App().fetch(...args), + }) + const clientNext = createV2Client({ baseUrl: "http://localhost:4096", // @ts-ignore - fetch type incompatibility fetch: async (...args) => Server.App().fetch(...args), @@ -30,6 +36,7 @@ export namespace Plugin { const hooks: Hooks[] = [] const input: PluginInput = { client, + clientNext, project: Instance.project, worktree: Instance.worktree, directory: Instance.directory, @@ -120,7 +127,6 @@ export namespace Plugin { const hooks = await state().then((x) => x.hooks) const config = await Config.get() for (const hook of hooks) { - // @ts-expect-error this is because we haven't moved plugin to sdk v2 await hook.config?.(config) } Bus.subscribeAll(async (input) => { diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index e57eff579e6..cfd010a9140 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -1,16 +1,16 @@ +import type { createOpencodeClient as createOpencodeClientV1 } from "@opencode-ai/sdk" import type { Event, createOpencodeClient, Project, Model, Provider, - Permission, UserMessage, Message, Part, Auth, Config, -} from "@opencode-ai/sdk" +} from "@opencode-ai/sdk/v2" import type { BunShell } from "./shell" import { type ToolDefinition } from "./tool" @@ -24,7 +24,8 @@ export type ProviderContext = { } export type PluginInput = { - client: ReturnType + client: ReturnType + clientNext: ReturnType project: Project directory: string worktree: string @@ -172,7 +173,21 @@ export interface Hooks { input: { sessionID: string; agent: string; model: Model; provider: ProviderContext; message: UserMessage }, output: { temperature: number; topP: number; topK: number; options: Record }, ) => Promise - "permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise + "permission.ask"?: ( + // based on Permission.Info from Core + input: { + id: string + type: string + pattern?: string | Array + sessionID: string + messageID: string + callID?: string + title: string + metadata: { [key: string]: unknown } + time: { created: number } + }, + output: { status: "ask" | "deny" | "allow" }, + ) => Promise "tool.execute.before"?: ( input: { tool: string; sessionID: string; callID: string }, output: { args: any },