Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ async function exchange(code, verifier) {
}

/**
* @type {import('@opencode-ai/plugin').Plugin}
* build an anthropic provider plugin with the given name.
*
* @param {string} name the provider's key (eg. 'anthropic', 'anthropic-personal', etc)
* @param {import('@opencode-ai/plugin').PluginInput['client']} client
* @returns {Promise<Hooks>}
*/
export async function AnthropicAuthPlugin({ client }) {
export async function makeAnthropicProviderPlugin(name, client) {
return {
auth: {
provider: "anthropic",
provider: name,
async loader(getAuth, provider) {
const auth = await getAuth();
if (auth.type === "oauth") {
Expand Down Expand Up @@ -116,7 +120,7 @@ export async function AnthropicAuthPlugin({ client }) {
const json = await response.json();
await client.auth.set({
path: {
id: "anthropic",
id: name,
},
body: {
type: "oauth",
Expand Down Expand Up @@ -206,11 +210,18 @@ export async function AnthropicAuthPlugin({ client }) {
},
},
{
provider: "anthropic",
provider: name,
label: "Manually enter API Key",
type: "api",
},
],
},
};
}

/**
* @type {import('@opencode-ai/plugin').Plugin}
*/
export async function AnthropicAuthPlugin({ client }) {
return makeAnthropicProviderPlugin("anthropic", client);
}