devin 0.1.40: a typed API key (cog_…) is a sign-in method

wuxudongxd on X: the plugin offered only the browser and CLI sign-ins,
while a hand-written {type:"api", key:"cog_…"} entry (a service user's
key) worked for chat and usage. Add "Devin API key (cog_…)" as a v1 api
method (no authorize, so the host saves the key as typed) and as an
OpenCode 2 key method; v2Auth already reads a key credential. The key is
sent as a sign-in's token is (Basic on GetChatMessage, apiKey on
GetUserStatus), and the first usage read names the account (syncOrg).

Run: bun test in packages/devin (214 pass) and the whole repo's bun test
with a temp HOME on mote (8542 pass, 20 skip, 0 fail).
Broken by hand: with both methods removed, apikey.test.mjs's method and
OpenCode 2 tests go red (the chat and usage tests pass either way: those
paths already took any api key).
Not tried: a real cog_ key (none on hand).
This commit is contained in:
yetone
2026-11-13 15:02:14 +08:00
parent d24fd5d182
commit aea9438f90
4 changed files with 96 additions and 3 deletions
+5 -2
View File
@@ -6,8 +6,8 @@ Provider id: `devin`.
## Signing in
An account is the CLI's session token (`devin-session-token$…`). There are
two ways to get one:
An account is the CLI's session token (`devin-session-token$…`) or a key
made in Devin's settings. There are three ways to add one:
- **Devin (browser)**: the CLI's own `devin auth login`, run by the
plugin. It is a PKCE sign-in through `app.devin.ai/auth/cli/continue`
@@ -17,6 +17,9 @@ two ways to get one:
its `credentials.toml` (`$XDG_DATA_HOME/devin/`, by default
`~/.local/share/devin/`; `%APPDATA%\devin\` on Windows). The file is only
read, never changed.
- **Devin API key (cog_…)**: a key typed in, such as a service user's
`cog_…` key. It is sent as a sign-in's token is (chat and usage), and is
never renewed. The first usage read names the account.
The plugin names the account as Devin does when asked with the token
(`GetUserStatus`: its email, organization when named, and tier). When Devin can't tell, and the CLI
+84
View File
@@ -0,0 +1,84 @@
// A key typed in (a service user's cog_… from Devin's settings) is a sign-in
// method of its own, saved as OpenCode saves any API key: {type:"api", key},
// no metadata. The chat and usage paths take it as they take a browser
// sign-in's token, and the first usage read names the account.
import { afterEach, expect, test } from "bun:test"
import { DevinAuthPlugin, _internal } from "./index.mjs"
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const LABEL = "Devin API key (cog_…)"
const configs = () => new Response(new _internal.PB().bytes(1, new _internal.PB().bytes(22, "swe-2")).done())
test("the API key method is offered after the two sign-ins, with nothing to authorize", async () => {
const { auth } = await DevinAuthPlugin({})
expect(auth.methods.map((m) => [m.type, m.label])).toEqual([
["oauth", "Devin (browser)"],
["oauth", "Devin CLI's sign-in"],
["api", LABEL],
])
// the host saves the key as typed only when there is no authorize
expect(auth.methods[2].authorize).toBeUndefined()
})
test("a typed key is sent to GetChatMessage as a sign-in's token is", async () => {
const seen = []
globalThis.fetch = async (url, init) => {
if (String(url).endsWith("/GetCliModelConfigs")) return configs()
seen.push({ url: String(url), auth: new Headers(init.headers).get("Authorization") })
return new Response("", { status: 402 })
}
const key = { type: "api", key: "cog_chat_test" }
const { auth } = await DevinAuthPlugin({})
const opts = await auth.loader(async () => key)
expect(opts.apiKey).toBe("cog_chat_test")
const res = await opts.fetch("https://devin.invalid/v1/chat/completions", {
method: "POST",
body: JSON.stringify({ model: "swe-2", messages: [{ role: "user", content: "hi" }] }),
})
expect(res.status).toBe(402)
const chat = seen.find((s) => s.url.endsWith("/GetChatMessage"))
expect(chat?.url).toBe("https://server.codeium.com/exa.api_server_pb.ApiServerService/GetChatMessage")
expect(chat.auth).toBe("Basic cog_chat_test")
})
test("usage reads a typed key's plan and names its account", async () => {
const seen = []
globalThis.fetch = async (url, init) => {
if (String(url).endsWith("/GetCliModelConfigs")) return configs()
seen.push(JSON.parse(init.body))
return Response.json({
userStatus: {
email: "svc@example.com",
teamId: "team-1",
planStatus: { planInfo: { planName: "Teams", devinInfo: { orgId: "org-1" } }, planEnd: "2026-12-01T00:00:00Z", dailyQuotaRemainingPercent: 80 },
},
})
}
const sets = []
const key = { type: "api", key: "cog_usage_test" }
const { auth } = await DevinAuthPlugin({ client: { auth: { set: async (a) => sets.push(a) } } })
const u = await auth.usage(async () => key)
expect(u.signIn).toBe("renewed")
expect(u.error).toBeUndefined()
expect(seen[0].metadata.apiKey).toBe("cog_usage_test")
expect(sets).toEqual([{ path: { id: "devin" }, body: { type: "api", key: "cog_usage_test", metadata: { email: "svc@example.com", orgId: "org-1", teamId: "team-1" } } }])
})
test("OpenCode 2 offers a key method, and its credential is read as an API key", async () => {
const methods = []
const ctx = {
integration: {
transform: async (cb) => cb({ method: { update: (m) => methods.push(m) } }),
connection: { active: async () => null, resolve: async () => null },
},
provider: { transform: async () => {}, reload: async () => {} },
model: { transform: async () => {}, reload: async () => {} },
aisdk: { hook: async () => {} },
event: { subscribe: () => ({ [Symbol.asyncIterator]: () => ({ next: () => new Promise(() => {}) }) }) },
}
await _internal.v2Setup(ctx)
expect(methods.filter((m) => m.method?.type === "key").map((m) => [m.integrationID, m.method.label])).toEqual([["devin", LABEL]])
expect(_internal.v2Auth({ type: "key", key: "cog_v2" })).toEqual({ type: "api", key: "cog_v2", metadata: {} })
})
+6
View File
@@ -2868,6 +2868,8 @@ async function v2Setup(ctx) {
},
label: (c) => c?.metadata?.email || "Devin",
})
// a key typed in, as the v1 "api" method saves it (v2Auth reads it)
editor.method.update({ integrationID: ID, method: { type: "key", label: "Devin API key (cog_…)" } })
})
// authFor resolves the active connection's key each call, so a chat goes
@@ -3153,6 +3155,10 @@ export async function DevinAuthPlugin({ client, magpie } = {}, options = {}) {
methods: [
{ type: "oauth", label: "Devin (browser)", authorize: browserSignIn },
{ type: "oauth", label: "Devin CLI's sign-in", authorize: cliSignIn },
// a key made in Devin's settings (a service user's cog_…, or a
// session token): sent as the sign-ins' token is, never renewed;
// the first usage read names the account (syncOrg)
{ type: "api", label: "Devin API key (cog_…)", placeholder: "cog_…" },
],
// magpie's own switches (OpenCode never reads auth.options)
options: [
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-devin-auth",
"version": "0.1.39",
"version": "0.1.40",
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",