From f19586cebd77a4d2092e6ff66fb184a1366a9ce4 Mon Sep 17 00:00:00 2001 From: Dax Date: Mon, 18 Aug 2025 17:12:21 -0400 Subject: fix anthropic console auth (#2049) --- packages/opencode/src/cli/cmd/auth.ts | 40 +++++++++++++++++------- packages/opencode/src/cli/cmd/opentui/opentui.ts | 0 packages/opencode/src/plugin/index.ts | 2 +- packages/plugin/src/index.ts | 28 +++++++++++------ 4 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 packages/opencode/src/cli/cmd/opentui/opentui.ts (limited to 'packages') diff --git a/packages/opencode/src/cli/cmd/auth.ts b/packages/opencode/src/cli/cmd/auth.ts index ab06d5bf3..cf736486a 100644 --- a/packages/opencode/src/cli/cmd/auth.ts +++ b/packages/opencode/src/cli/cmd/auth.ts @@ -176,12 +176,20 @@ export const AuthLoginCommand = cmd({ spinner.stop("Failed to authorize", 1) } if (result.type === "success") { - await Auth.set(provider, { - type: "oauth", - refresh: result.refresh, - access: result.access, - expires: result.expires, - }) + if ("refresh" in result) { + await Auth.set(provider, { + type: "oauth", + refresh: result.refresh, + access: result.access, + expires: result.expires, + }) + } + if ("key" in result) { + await Auth.set(provider, { + type: "api", + key: result.key, + }) + } spinner.stop("Login successful") } } @@ -197,12 +205,20 @@ export const AuthLoginCommand = cmd({ prompts.log.error("Failed to authorize") } if (result.type === "success") { - await Auth.set(provider, { - type: "oauth", - refresh: result.refresh, - access: result.access, - expires: result.expires, - }) + if ("refresh" in result) { + await Auth.set(provider, { + type: "oauth", + refresh: result.refresh, + access: result.access, + expires: result.expires, + }) + } + if ("key" in result) { + await Auth.set(provider, { + type: "api", + key: result.key, + }) + } prompts.log.success("Login successful") } } diff --git a/packages/opencode/src/cli/cmd/opentui/opentui.ts b/packages/opencode/src/cli/cmd/opentui/opentui.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index 8fbd38c67..633dc850e 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/packages/opencode/src/plugin/index.ts @@ -26,7 +26,7 @@ export namespace Plugin { const plugins = [...(config.plugin ?? [])] if (!Flag.OPENCODE_DISABLE_DEFAULT_PLUGINS) { plugins.push("opencode-copilot-auth") - plugins.push("opencode-anthropic-auth") + plugins.push("opencode-anthropic-auth@0.0.2") } for (let plugin of plugins) { log.info("loading plugin", { path: plugin }) diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 1a6cbf124..a214af110 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -32,12 +32,16 @@ export interface Hooks { | { method: "auto" callback(): Promise< - | { + | ({ type: "success" - refresh: string - access: string - expires: number - } + } & ( + | { + refresh: string + access: string + expires: number + } + | { key: string } + )) | { type: "failed" } @@ -46,12 +50,16 @@ export interface Hooks { | { method: "code" callback(code: string): Promise< - | { + | ({ type: "success" - refresh: string - access: string - expires: number - } + } & ( + | { + refresh: string + access: string + expires: number + } + | { key: string } + )) | { type: "failed" } -- cgit v1.2.3