opencode-devin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/auth/exchange.d.ts +15 -0
- package/dist/auth/exchange.js +43 -0
- package/dist/auth/loopback.d.ts +15 -0
- package/dist/auth/loopback.js +57 -0
- package/dist/auth/pkce.d.ts +11 -0
- package/dist/auth/pkce.js +27 -0
- package/dist/auth/url.d.ts +12 -0
- package/dist/auth/url.js +17 -0
- package/dist/catalog.d.ts +11 -0
- package/dist/catalog.js +47 -0
- package/dist/constants.d.ts +19 -0
- package/dist/constants.js +19 -0
- package/dist/credentials.d.ts +23 -0
- package/dist/credentials.js +53 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +121 -0
- package/dist/protocol/auth.d.ts +20 -0
- package/dist/protocol/auth.js +97 -0
- package/dist/protocol/catalog.d.ts +49 -0
- package/dist/protocol/catalog.js +182 -0
- package/dist/protocol/chat.d.ts +92 -0
- package/dist/protocol/chat.js +465 -0
- package/dist/protocol/metadata.d.ts +17 -0
- package/dist/protocol/metadata.js +42 -0
- package/dist/protocol/model.d.ts +32 -0
- package/dist/protocol/model.js +412 -0
- package/dist/protocol/wire.d.ts +30 -0
- package/dist/protocol/wire.js +114 -0
- package/dist/provider.d.ts +18 -0
- package/dist/provider.js +20 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 opencode-devin contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# opencode-devin
|
|
2
|
+
|
|
3
|
+
[OpenCode v2](https://opencode.ai) plugin that connects your [Devin](https://devin.ai) subscription to OpenCode:
|
|
4
|
+
|
|
5
|
+
- **Native `/connect` integration** — log in with Devin straight from the OpenCode TUI using the same browser PKCE flow as the Devin CLI. The credential is stored in OpenCode's own auth store; no config files or API keys to copy.
|
|
6
|
+
- **`devin/*` models in `/models`** — the live, per-account catalog (SWE, Claude Opus, GPT, Gemini, Grok, Kimi and more, with reasoning-effort and speed variants), streamed from Cognition's Cascade inference API.
|
|
7
|
+
|
|
8
|
+
> **Requires OpenCode v2.** This plugin targets the v2 plugin API (`Plugin.define`). The official [`@cognitionai/opencode-devin`](https://www.npmjs.com/package/@cognitionai/opencode-devin) plugin is v1-only at the time of writing and does not load on v2.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Add the plugin to `opencode.json` (project or `~/.config/opencode/opencode.json`):
|
|
13
|
+
|
|
14
|
+
```jsonc
|
|
15
|
+
{
|
|
16
|
+
"$schema": "https://opencode.ai/config.json",
|
|
17
|
+
"plugins": ["opencode-devin"]
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
OpenCode installs it automatically on the next start.
|
|
22
|
+
|
|
23
|
+
## Connect
|
|
24
|
+
|
|
25
|
+
Start OpenCode, run `/connect`, pick **Devin**, then choose a method:
|
|
26
|
+
|
|
27
|
+
| Method | How it works | Best for |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| **Log in with Devin (browser)** | Opens the Devin sign-in page (PKCE + S256) and captures the authorization code through a local loopback callback. | Interactive terminals |
|
|
30
|
+
| **Paste code (headless)** | Opens the same login page without a redirect; the page shows a code to copy and paste back into the TUI. | Headless machines, SSH |
|
|
31
|
+
| **`DEVIN_LLM_API_KEY`** | Reads a `devin-session-token$...` token from the environment. | CI, scripting |
|
|
32
|
+
|
|
33
|
+
After connecting, the model list refreshes automatically and `devin/<model>` entries appear in `/models`.
|
|
34
|
+
|
|
35
|
+
### Environment variable alternative
|
|
36
|
+
|
|
37
|
+
Skip `/connect` entirely:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
export DEVIN_LLM_API_KEY=devin-session-token$your_token_here
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Use
|
|
44
|
+
|
|
45
|
+
Pick any `devin/` model in the `/models` picker, or set a default:
|
|
46
|
+
|
|
47
|
+
```jsonc
|
|
48
|
+
// opencode.json
|
|
49
|
+
{
|
|
50
|
+
"model": "devin/swe-2-max"
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
From the CLI:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
opencode run --model devin/swe-2-max "Refactor the auth module"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## How it works
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
/connect ──▶ app.devin.ai PKCE login ──▶ devin-session-token$<JWT>
|
|
64
|
+
│ │
|
|
65
|
+
▼ ▼
|
|
66
|
+
stored as an OpenCode credential GetCascadeModelConfigs (gRPC)
|
|
67
|
+
│
|
|
68
|
+
▼
|
|
69
|
+
provider `devin`
|
|
70
|
+
│
|
|
71
|
+
▼
|
|
72
|
+
ai-sdk-devin ──▶ Cascade gRPC (GetUserJwt + GetChatMessage)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
1. **Integration** — the plugin registers a `devin` integration with the Devin CLI login flow: PKCE (S256) against `app.devin.ai/auth/cli/continue`, a loopback callback on `127.0.0.1` (or manual code paste), and a token exchange at `api.devin.ai/auth/cli/token`.
|
|
76
|
+
2. **Catalog** — model families come from Cognition's Cascade API for the logged-in account (the same source the Devin CLI uses). The OpenAI-compatible REST gateway (`/api/v1`) is not provisioned for most accounts, so chat streams through Cascade gRPC instead.
|
|
77
|
+
3. **Provider** — the plugin publishes a `devin` provider whose package specifier self-references the plugin's own installed location (`aisdk:<this-package>`), so OpenCode's dynamic AI-SDK loader imports it directly with no registry round-trip — both from a repo checkout during development and from the npm cache once installed. Its `LanguageModelV3` implementation lives in `src/protocol/`: a short-lived `user_jwt` is minted per session (`GetUserJwt`) and chat streams through `GetChatMessage`.
|
|
78
|
+
4. **Reactivity** — the inventory re-publishes whenever a credential is connected, switched, or removed, so connecting mid-session updates `/models` without a restart.
|
|
79
|
+
|
|
80
|
+
## Troubleshooting
|
|
81
|
+
|
|
82
|
+
- **No `devin/` models** — the credential is missing or the catalog fetch failed. Run `/connect` again.
|
|
83
|
+
- **401 during chat** — the session token was revoked. Re-run `/connect`.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
bun install
|
|
89
|
+
npm run typecheck
|
|
90
|
+
npm run build # emits dist/
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To test a local checkout without publishing, create a bridge file that re-exports the build:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// ~/.config/opencode/plugins/devin.ts
|
|
97
|
+
export { default } from "file:///absolute/path/to/opencode-devin/dist/index.js"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Credits
|
|
101
|
+
|
|
102
|
+
- The Cascade protocol client is a **typed TypeScript port**, owned in `src/protocol/` (see `ATTRIBUTION.md`) — originally from [`ai-sdk-devin`](https://www.npmjs.com/package/ai-sdk-devin) by [karthiknish](https://github.com/karthiknish) and `pi-devin-auth` by nmzpy, both MIT. Owning the port keeps the credential path free of third-party runtime dependencies.
|
|
103
|
+
- [`@cognitionai/opencode-devin`](https://www.npmjs.com/package/@cognitionai/opencode-devin) — reference for the Devin CLI PKCE login flow.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token exchange: `POST {authApi}/auth/cli/token {code, code_verifier}`.
|
|
3
|
+
*
|
|
4
|
+
* Returns the token in the `devin-session-token$<jwt>` form opencode stores
|
|
5
|
+
* and sends as the bearer credential. Never echoes the code or token.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DevinAuthError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
constructor(message: string, status: number);
|
|
10
|
+
}
|
|
11
|
+
/** Exchange a PKCE authorization code for the long-lived session token. */
|
|
12
|
+
export declare function exchangeCode(input: {
|
|
13
|
+
code: string;
|
|
14
|
+
verifier: string;
|
|
15
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token exchange: `POST {authApi}/auth/cli/token {code, code_verifier}`.
|
|
3
|
+
*
|
|
4
|
+
* Returns the token in the `devin-session-token$<jwt>` form opencode stores
|
|
5
|
+
* and sends as the bearer credential. Never echoes the code or token.
|
|
6
|
+
*/
|
|
7
|
+
import { AUTH_API_URL, TOKEN_PREFIX } from "../constants.js";
|
|
8
|
+
export class DevinAuthError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
constructor(message, status) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "DevinAuthError";
|
|
13
|
+
this.status = status;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Exchange a PKCE authorization code for the long-lived session token. */
|
|
17
|
+
export async function exchangeCode(input) {
|
|
18
|
+
const response = await fetch(`${AUTH_API_URL}/auth/cli/token`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
21
|
+
body: JSON.stringify({ code: input.code, code_verifier: input.verifier }),
|
|
22
|
+
signal: AbortSignal.timeout(30_000),
|
|
23
|
+
}).catch((cause) => {
|
|
24
|
+
throw new DevinAuthError(`Token exchange request to ${AUTH_API_URL} failed: ${String(cause)}`, 0);
|
|
25
|
+
});
|
|
26
|
+
const text = await response.text();
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
let message = text || `Token exchange failed with HTTP ${response.status}`;
|
|
29
|
+
try {
|
|
30
|
+
const err = JSON.parse(text);
|
|
31
|
+
if (err.message)
|
|
32
|
+
message = err.message;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// non-JSON body — keep the raw text
|
|
36
|
+
}
|
|
37
|
+
throw new DevinAuthError(message, response.status);
|
|
38
|
+
}
|
|
39
|
+
const token = JSON.parse(text).token;
|
|
40
|
+
if (!token)
|
|
41
|
+
throw new DevinAuthError("Token exchange succeeded but the response had no token", response.status);
|
|
42
|
+
return `${TOKEN_PREFIX}${token}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback callback server for the Devin CLI login flow.
|
|
3
|
+
*
|
|
4
|
+
* Binds first so the redirect port is known before the sign-in URL is
|
|
5
|
+
* returned, and pre-registers the waiter before the browser opens — a cached
|
|
6
|
+
* app.devin.ai session can round-trip fast enough to hit `/callback` before
|
|
7
|
+
* the caller awaits the promise.
|
|
8
|
+
*/
|
|
9
|
+
export interface CallbackServer {
|
|
10
|
+
redirectUri: string;
|
|
11
|
+
code: Promise<string>;
|
|
12
|
+
close: () => void;
|
|
13
|
+
}
|
|
14
|
+
/** Bind a one-shot HTTP server and wait for the authorization code. */
|
|
15
|
+
export declare function startCallbackServer(state: string): Promise<CallbackServer>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback callback server for the Devin CLI login flow.
|
|
3
|
+
*
|
|
4
|
+
* Binds first so the redirect port is known before the sign-in URL is
|
|
5
|
+
* returned, and pre-registers the waiter before the browser opens — a cached
|
|
6
|
+
* app.devin.ai session can round-trip fast enough to hit `/callback` before
|
|
7
|
+
* the caller awaits the promise.
|
|
8
|
+
*/
|
|
9
|
+
import { CALLBACK_PATH } from "../constants.js";
|
|
10
|
+
/** Bind a one-shot HTTP server and wait for the authorization code. */
|
|
11
|
+
export function startCallbackServer(state) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
let settle;
|
|
14
|
+
let fail;
|
|
15
|
+
const code = new Promise((res, rej) => {
|
|
16
|
+
settle = res;
|
|
17
|
+
fail = rej;
|
|
18
|
+
});
|
|
19
|
+
let server;
|
|
20
|
+
try {
|
|
21
|
+
server = Bun.serve({
|
|
22
|
+
hostname: "127.0.0.1",
|
|
23
|
+
port: 0,
|
|
24
|
+
async fetch(req) {
|
|
25
|
+
const url = new URL(req.url);
|
|
26
|
+
const page = (title, body, status = 200) => new Response(`<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head>` +
|
|
27
|
+
`<body style="font-family:system-ui;margin:3rem"><h1>${title}</h1><p>${body}</p></body></html>`, { status, headers: { "Content-Type": "text/html; charset=utf-8" } });
|
|
28
|
+
if (url.pathname !== CALLBACK_PATH) {
|
|
29
|
+
return page("Not found", "", 404);
|
|
30
|
+
}
|
|
31
|
+
if (url.searchParams.get("state") !== state) {
|
|
32
|
+
return page("Invalid state parameter", "This may indicate a security issue. Please try again.", 400);
|
|
33
|
+
}
|
|
34
|
+
const received = url.searchParams.get("code");
|
|
35
|
+
if (!received) {
|
|
36
|
+
return page("No authorization code received", "Please return to the terminal and try again.", 400);
|
|
37
|
+
}
|
|
38
|
+
settle?.(received);
|
|
39
|
+
return page("Signed in to Devin", "You can close this tab and return to opencode.");
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (cause) {
|
|
44
|
+
reject(cause instanceof Error ? cause : new Error("Failed to bind loopback callback server"));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
resolve({
|
|
48
|
+
// The server is listening at this point, so the port is always set.
|
|
49
|
+
redirectUri: `http://127.0.0.1:${server.port}${CALLBACK_PATH}`,
|
|
50
|
+
code,
|
|
51
|
+
close: () => {
|
|
52
|
+
fail?.(new Error("Login cancelled"));
|
|
53
|
+
server.stop(true);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PKCE (S256) helpers, matching the Devin CLI (chisel): 32 random bytes,
|
|
3
|
+
* base64url-encoded, and a base64url SHA-256 challenge derived from the
|
|
4
|
+
* verifier.
|
|
5
|
+
*/
|
|
6
|
+
/** PKCE code verifier: 32 random bytes, base64url without padding. */
|
|
7
|
+
export declare function generateVerifier(): string;
|
|
8
|
+
/** S256 challenge: base64url(sha256(verifier)). */
|
|
9
|
+
export declare function challengeFor(verifier: string): Promise<string>;
|
|
10
|
+
/** CSRF state token. */
|
|
11
|
+
export declare function generateState(): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PKCE (S256) helpers, matching the Devin CLI (chisel): 32 random bytes,
|
|
3
|
+
* base64url-encoded, and a base64url SHA-256 challenge derived from the
|
|
4
|
+
* verifier.
|
|
5
|
+
*/
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
function base64url(bytes) {
|
|
8
|
+
return Buffer.from(bytes).toString("base64url");
|
|
9
|
+
}
|
|
10
|
+
function randomToken() {
|
|
11
|
+
const bytes = new Uint8Array(32);
|
|
12
|
+
crypto.getRandomValues(bytes);
|
|
13
|
+
return base64url(bytes);
|
|
14
|
+
}
|
|
15
|
+
/** PKCE code verifier: 32 random bytes, base64url without padding. */
|
|
16
|
+
export function generateVerifier() {
|
|
17
|
+
return randomToken();
|
|
18
|
+
}
|
|
19
|
+
/** S256 challenge: base64url(sha256(verifier)). */
|
|
20
|
+
export async function challengeFor(verifier) {
|
|
21
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(verifier));
|
|
22
|
+
return base64url(new Uint8Array(digest));
|
|
23
|
+
}
|
|
24
|
+
/** CSRF state token. */
|
|
25
|
+
export function generateState() {
|
|
26
|
+
return randomToken();
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin CLI login URL (`{webapp}/auth/cli/continue`).
|
|
3
|
+
*
|
|
4
|
+
* With `redirect_uri` the webapp redirects the browser back to our loopback
|
|
5
|
+
* server; without it, the webapp shows the user a code to paste instead.
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthorizeInput {
|
|
8
|
+
state: string;
|
|
9
|
+
challenge: string;
|
|
10
|
+
redirectUri?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function authorizeUrl(input: AuthorizeInput): string;
|
package/dist/auth/url.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin CLI login URL (`{webapp}/auth/cli/continue`).
|
|
3
|
+
*
|
|
4
|
+
* With `redirect_uri` the webapp redirects the browser back to our loopback
|
|
5
|
+
* server; without it, the webapp shows the user a code to paste instead.
|
|
6
|
+
*/
|
|
7
|
+
import { WEBAPP_URL } from "../constants.js";
|
|
8
|
+
export function authorizeUrl(input) {
|
|
9
|
+
const url = new URL("/auth/cli/continue", WEBAPP_URL);
|
|
10
|
+
if (input.redirectUri)
|
|
11
|
+
url.searchParams.set("redirect_uri", input.redirectUri);
|
|
12
|
+
url.searchParams.set("state", input.state);
|
|
13
|
+
url.searchParams.set("prompt", "select_account");
|
|
14
|
+
url.searchParams.set("code_challenge", input.challenge);
|
|
15
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
16
|
+
return url.toString();
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model catalog from Cognition's Cascade gRPC API.
|
|
3
|
+
*
|
|
4
|
+
* The live catalog comes from the per-account `GetCascadeModelConfigs` RPC
|
|
5
|
+
* (via ai-sdk-devin) — every model UID the subscription can use, with pricing
|
|
6
|
+
* and context windows. This is the same source the Devin CLI uses
|
|
7
|
+
* (`GetCliModelConfigs`); the REST gateway (`/api/v1/models`) is not
|
|
8
|
+
* provisioned for most accounts.
|
|
9
|
+
*/
|
|
10
|
+
import { Model } from "@opencode/plugin";
|
|
11
|
+
export declare function fetchModels(apiKey: string, apiServerUrl?: string): Promise<Model.Info[]>;
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model catalog from Cognition's Cascade gRPC API.
|
|
3
|
+
*
|
|
4
|
+
* The live catalog comes from the per-account `GetCascadeModelConfigs` RPC
|
|
5
|
+
* (via ai-sdk-devin) — every model UID the subscription can use, with pricing
|
|
6
|
+
* and context windows. This is the same source the Devin CLI uses
|
|
7
|
+
* (`GetCliModelConfigs`); the REST gateway (`/api/v1/models`) is not
|
|
8
|
+
* provisioned for most accounts.
|
|
9
|
+
*/
|
|
10
|
+
import { getCachedCatalog } from "./protocol/catalog.js";
|
|
11
|
+
import { Model, Provider } from "@opencode/plugin";
|
|
12
|
+
import { DEFAULT_RELEASED_MS, PROVIDER_ID } from "./constants.js";
|
|
13
|
+
export async function fetchModels(apiKey, apiServerUrl) {
|
|
14
|
+
const catalog = await getCachedCatalog(apiKey, apiServerUrl || undefined);
|
|
15
|
+
if (!catalog)
|
|
16
|
+
return [];
|
|
17
|
+
return Array.from(catalog.byUid.values())
|
|
18
|
+
.filter((entry) => !entry.disabled)
|
|
19
|
+
.map(toModelInfo);
|
|
20
|
+
}
|
|
21
|
+
function toModelInfo(entry) {
|
|
22
|
+
const { pricing } = entry;
|
|
23
|
+
const base = Model.Info.default(Provider.ID.make(PROVIDER_ID), Model.ID.make(entry.modelUid));
|
|
24
|
+
return {
|
|
25
|
+
...base,
|
|
26
|
+
name: entry.label || entry.modelUid,
|
|
27
|
+
enabled: !entry.disabled,
|
|
28
|
+
status: "active",
|
|
29
|
+
capabilities: {
|
|
30
|
+
tools: true,
|
|
31
|
+
input: ["text", "image"],
|
|
32
|
+
output: ["text"],
|
|
33
|
+
},
|
|
34
|
+
cost: [
|
|
35
|
+
{
|
|
36
|
+
input: pricing?.input ?? 0,
|
|
37
|
+
output: pricing?.output ?? 0,
|
|
38
|
+
cache: { read: pricing?.cachedInput ?? 0, write: 0 },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
limit: {
|
|
42
|
+
context: entry.contextWindow || 256_000,
|
|
43
|
+
output: 128_000,
|
|
44
|
+
},
|
|
45
|
+
time: { released: DEFAULT_RELEASED_MS },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Shared constants for the opencode-devin plugin. */
|
|
2
|
+
/** OpenCode provider and integration ID. Models appear as `devin/<uid>`. */
|
|
3
|
+
export declare const PROVIDER_ID = "devin";
|
|
4
|
+
/** Environment variable holding a Devin session token (`devin-session-token$...`). */
|
|
5
|
+
export declare const LLM_ENV_VAR = "DEVIN_LLM_API_KEY";
|
|
6
|
+
/** Devin webapp — hosts the CLI login page (`/auth/cli/continue`). */
|
|
7
|
+
export declare const WEBAPP_URL = "https://app.devin.ai";
|
|
8
|
+
/** Devin auth API — exchanges the PKCE code for a session token. */
|
|
9
|
+
export declare const AUTH_API_URL = "https://api.devin.ai";
|
|
10
|
+
/** Default Codeium API server (Cascade gRPC) when no tenant host is known. */
|
|
11
|
+
export declare const DEFAULT_API_SERVER = "https://server.codeium.com";
|
|
12
|
+
/** Prefix the Devin CLI puts in front of the session JWT. */
|
|
13
|
+
export declare const TOKEN_PREFIX = "devin-session-token$";
|
|
14
|
+
/** Loopback callback path required by the webapp's safe-redirect check. */
|
|
15
|
+
export declare const CALLBACK_PATH = "/callback";
|
|
16
|
+
/** Credential lifetime reported to opencode (the token itself is long-lived). */
|
|
17
|
+
export declare const CREDENTIAL_TTL_MS: number;
|
|
18
|
+
/** Fallback release date for catalog models that do not expose one (epoch ms). */
|
|
19
|
+
export declare const DEFAULT_RELEASED_MS: number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Shared constants for the opencode-devin plugin. */
|
|
2
|
+
/** OpenCode provider and integration ID. Models appear as `devin/<uid>`. */
|
|
3
|
+
export const PROVIDER_ID = "devin";
|
|
4
|
+
/** Environment variable holding a Devin session token (`devin-session-token$...`). */
|
|
5
|
+
export const LLM_ENV_VAR = "DEVIN_LLM_API_KEY";
|
|
6
|
+
/** Devin webapp — hosts the CLI login page (`/auth/cli/continue`). */
|
|
7
|
+
export const WEBAPP_URL = "https://app.devin.ai";
|
|
8
|
+
/** Devin auth API — exchanges the PKCE code for a session token. */
|
|
9
|
+
export const AUTH_API_URL = "https://api.devin.ai";
|
|
10
|
+
/** Default Codeium API server (Cascade gRPC) when no tenant host is known. */
|
|
11
|
+
export const DEFAULT_API_SERVER = "https://server.codeium.com";
|
|
12
|
+
/** Prefix the Devin CLI puts in front of the session JWT. */
|
|
13
|
+
export const TOKEN_PREFIX = "devin-session-token$";
|
|
14
|
+
/** Loopback callback path required by the webapp's safe-redirect check. */
|
|
15
|
+
export const CALLBACK_PATH = "/callback";
|
|
16
|
+
/** Credential lifetime reported to opencode (the token itself is long-lived). */
|
|
17
|
+
export const CREDENTIAL_TTL_MS = 365 * 24 * 60 * 60 * 1000;
|
|
18
|
+
/** Fallback release date for catalog models that do not expose one (epoch ms). */
|
|
19
|
+
export const DEFAULT_RELEASED_MS = Date.parse("2025-01-01T00:00:00Z");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin credential resolution.
|
|
3
|
+
*
|
|
4
|
+
* The chat credential is a long-lived session token
|
|
5
|
+
* (`devin-session-token$<JWT>`), issued either by the Devin CLI login flow
|
|
6
|
+
* (PKCE) or by Windsurf OAuth. Sources, in priority order:
|
|
7
|
+
*
|
|
8
|
+
* 1. `DEVIN_LLM_API_KEY` environment variable
|
|
9
|
+
* 2. the credential stored by opencode's `/connect` (this plugin's integration)
|
|
10
|
+
*/
|
|
11
|
+
import type { Plugin } from "@opencode/plugin";
|
|
12
|
+
import { Credential } from "@opencode/plugin";
|
|
13
|
+
export interface DevinCredentials {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
name: string;
|
|
16
|
+
/** Tenant-scoped inference host; empty means the default Codeium server. */
|
|
17
|
+
apiServerUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
export type PluginContext = Parameters<Parameters<typeof Plugin.define>[0]["setup"]>[0];
|
|
20
|
+
/** Resolve the active Devin credentials, or `undefined` when not connected. */
|
|
21
|
+
export declare function resolveCredentials(ctx: PluginContext): Promise<DevinCredentials | undefined>;
|
|
22
|
+
/** Build the opencode credential object stored by `/connect`. */
|
|
23
|
+
export declare function toStoredCredential(apiKey: string, name?: string, apiServerUrl?: string): Credential.OAuth;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin credential resolution.
|
|
3
|
+
*
|
|
4
|
+
* The chat credential is a long-lived session token
|
|
5
|
+
* (`devin-session-token$<JWT>`), issued either by the Devin CLI login flow
|
|
6
|
+
* (PKCE) or by Windsurf OAuth. Sources, in priority order:
|
|
7
|
+
*
|
|
8
|
+
* 1. `DEVIN_LLM_API_KEY` environment variable
|
|
9
|
+
* 2. the credential stored by opencode's `/connect` (this plugin's integration)
|
|
10
|
+
*/
|
|
11
|
+
import { Credential } from "@opencode/plugin";
|
|
12
|
+
import { CREDENTIAL_TTL_MS, DEFAULT_API_SERVER, LLM_ENV_VAR, PROVIDER_ID, TOKEN_PREFIX } from "./constants.js";
|
|
13
|
+
function fromEnv() {
|
|
14
|
+
const apiKey = process.env[LLM_ENV_VAR];
|
|
15
|
+
if (!apiKey?.startsWith(TOKEN_PREFIX))
|
|
16
|
+
return undefined;
|
|
17
|
+
return { apiKey, name: "env" };
|
|
18
|
+
}
|
|
19
|
+
async function fromStoredConnection(ctx) {
|
|
20
|
+
try {
|
|
21
|
+
const connection = await ctx.integration.connection.active(PROVIDER_ID);
|
|
22
|
+
if (!connection)
|
|
23
|
+
return undefined;
|
|
24
|
+
const value = await ctx.integration.connection.resolve(connection);
|
|
25
|
+
const access = value?.type === "oauth" ? value.access : value?.type === "key" ? value.key : undefined;
|
|
26
|
+
if (!access?.startsWith(TOKEN_PREFIX))
|
|
27
|
+
return undefined;
|
|
28
|
+
const metadata = value?.type === "oauth" ? value.metadata : undefined;
|
|
29
|
+
return {
|
|
30
|
+
apiKey: access,
|
|
31
|
+
name: typeof metadata?.name === "string" ? metadata.name : "opencode",
|
|
32
|
+
apiServerUrl: typeof metadata?.apiServerUrl === "string" ? metadata.apiServerUrl : undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Resolve the active Devin credentials, or `undefined` when not connected. */
|
|
40
|
+
export async function resolveCredentials(ctx) {
|
|
41
|
+
return (await fromEnv()) ?? (await fromStoredConnection(ctx));
|
|
42
|
+
}
|
|
43
|
+
/** Build the opencode credential object stored by `/connect`. */
|
|
44
|
+
export function toStoredCredential(apiKey, name = "opencode", apiServerUrl) {
|
|
45
|
+
return {
|
|
46
|
+
type: "oauth",
|
|
47
|
+
methodID: "devin",
|
|
48
|
+
refresh: "",
|
|
49
|
+
access: apiKey,
|
|
50
|
+
expires: Date.now() + CREDENTIAL_TTL_MS,
|
|
51
|
+
metadata: apiServerUrl ? { name, apiServerUrl } : { name },
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode v2 plugin: Devin / Cognition.
|
|
3
|
+
*
|
|
4
|
+
* - Integration `devin` with the Devin CLI login flow (PKCE, same as chisel)
|
|
5
|
+
* so `/connect` stores the credential natively: automated browser flow and
|
|
6
|
+
* a paste-code fallback for headless machines.
|
|
7
|
+
* - Provider `devin` streaming chat through Cognition's Cascade protocol
|
|
8
|
+
* (src/protocol/), with the live per-account catalog published as
|
|
9
|
+
* `devin/*` models.
|
|
10
|
+
*
|
|
11
|
+
* The provider inventory re-publishes automatically whenever a credential is
|
|
12
|
+
* connected, switched, or removed.
|
|
13
|
+
*/
|
|
14
|
+
import { Plugin } from "@opencode/plugin";
|
|
15
|
+
export { createDevinProvider } from "./provider.ts";
|
|
16
|
+
declare const _default: Plugin.Plugin;
|
|
17
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode v2 plugin: Devin / Cognition.
|
|
3
|
+
*
|
|
4
|
+
* - Integration `devin` with the Devin CLI login flow (PKCE, same as chisel)
|
|
5
|
+
* so `/connect` stores the credential natively: automated browser flow and
|
|
6
|
+
* a paste-code fallback for headless machines.
|
|
7
|
+
* - Provider `devin` streaming chat through Cognition's Cascade protocol
|
|
8
|
+
* (src/protocol/), with the live per-account catalog published as
|
|
9
|
+
* `devin/*` models.
|
|
10
|
+
*
|
|
11
|
+
* The provider inventory re-publishes automatically whenever a credential is
|
|
12
|
+
* connected, switched, or removed.
|
|
13
|
+
*/
|
|
14
|
+
import { Plugin, Provider } from "@opencode/plugin";
|
|
15
|
+
import { DEFAULT_API_SERVER, LLM_ENV_VAR, PROVIDER_ID } from "./constants.js";
|
|
16
|
+
import { resolveCredentials, toStoredCredential } from "./credentials.js";
|
|
17
|
+
import { startCallbackServer } from "./auth/loopback.js";
|
|
18
|
+
import { authorizeUrl } from "./auth/url.js";
|
|
19
|
+
import { challengeFor, generateState, generateVerifier } from "./auth/pkce.js";
|
|
20
|
+
import { exchangeCode } from "./auth/exchange.js";
|
|
21
|
+
import { fetchModels } from "./catalog.js";
|
|
22
|
+
export { createDevinProvider } from "./provider.js";
|
|
23
|
+
function openBrowser(url) {
|
|
24
|
+
const cmd = process.platform === "win32"
|
|
25
|
+
? ["cmd", "/c", "start", "", url]
|
|
26
|
+
: process.platform === "darwin"
|
|
27
|
+
? ["open", url]
|
|
28
|
+
: ["xdg-open", url];
|
|
29
|
+
Bun.spawn(cmd, { stdin: "ignore", stdout: "ignore", stderr: "ignore" });
|
|
30
|
+
}
|
|
31
|
+
export default Plugin.define({
|
|
32
|
+
id: PROVIDER_ID,
|
|
33
|
+
async setup(ctx) {
|
|
34
|
+
const publish = async () => {
|
|
35
|
+
const credentials = await resolveCredentials(ctx);
|
|
36
|
+
if (!credentials)
|
|
37
|
+
return;
|
|
38
|
+
const models = await fetchModels(credentials.apiKey, credentials.apiServerUrl);
|
|
39
|
+
await ctx.provider.transform((editor) => {
|
|
40
|
+
editor.add({
|
|
41
|
+
info: {
|
|
42
|
+
...Provider.Info.empty(Provider.ID.make(PROVIDER_ID)),
|
|
43
|
+
name: "Devin",
|
|
44
|
+
activation: "enabled",
|
|
45
|
+
// `aisdk:` routes through opencode's dynamic AI-SDK provider
|
|
46
|
+
// loader. The specifier self-references this package's own
|
|
47
|
+
// location: the repo checkout during development, or the plugin's
|
|
48
|
+
// npm cache copy once installed — either way the loader imports
|
|
49
|
+
// it directly, with no registry round-trip.
|
|
50
|
+
package: `aisdk:${new URL("..", import.meta.url).href}`,
|
|
51
|
+
settings: {
|
|
52
|
+
apiKey: credentials.apiKey,
|
|
53
|
+
baseURL: credentials.apiServerUrl ?? DEFAULT_API_SERVER,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
models,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
await ctx.integration.transform((editor) => {
|
|
61
|
+
editor.update(PROVIDER_ID, (integration) => {
|
|
62
|
+
integration.name = "Devin";
|
|
63
|
+
});
|
|
64
|
+
editor.method.update({
|
|
65
|
+
integrationID: PROVIDER_ID,
|
|
66
|
+
method: { id: "devin", type: "oauth", label: "Log in with Devin (browser)" },
|
|
67
|
+
authorize: async () => {
|
|
68
|
+
const verifier = generateVerifier();
|
|
69
|
+
const state = generateState();
|
|
70
|
+
const server = await startCallbackServer(state);
|
|
71
|
+
const url = authorizeUrl({ state, challenge: await challengeFor(verifier), redirectUri: server.redirectUri });
|
|
72
|
+
openBrowser(url);
|
|
73
|
+
return {
|
|
74
|
+
url,
|
|
75
|
+
instructions: `Log in to Devin in the opened browser tab. If it did not open, go to: ${url}`,
|
|
76
|
+
mode: "auto",
|
|
77
|
+
callback: (async () => {
|
|
78
|
+
try {
|
|
79
|
+
const code = await server.code;
|
|
80
|
+
return toStoredCredential(await exchangeCode({ code, verifier }));
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
server.close();
|
|
84
|
+
}
|
|
85
|
+
})(),
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
editor.method.update({
|
|
90
|
+
integrationID: PROVIDER_ID,
|
|
91
|
+
method: { id: "code", type: "oauth", label: "Paste code (headless)" },
|
|
92
|
+
authorize: async () => {
|
|
93
|
+
const verifier = generateVerifier();
|
|
94
|
+
const state = generateState();
|
|
95
|
+
return {
|
|
96
|
+
url: authorizeUrl({ state, challenge: await challengeFor(verifier) }),
|
|
97
|
+
instructions: "Open the URL, sign in to Devin, and copy the code shown on the page, then paste it here.",
|
|
98
|
+
mode: "code",
|
|
99
|
+
callback: async (code) => toStoredCredential(await exchangeCode({ code: code.trim(), verifier })),
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
editor.method.update({
|
|
104
|
+
integrationID: PROVIDER_ID,
|
|
105
|
+
method: { type: "env", names: [LLM_ENV_VAR] },
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
await publish().catch((error) => {
|
|
109
|
+
console.error("[opencode-devin] initial load failed:", error);
|
|
110
|
+
});
|
|
111
|
+
const controller = new AbortController();
|
|
112
|
+
void (async () => {
|
|
113
|
+
for await (const event of ctx.event.subscribe({ signal: controller.signal })) {
|
|
114
|
+
if (event.type === "credential.updated" || event.type === "credential.switched") {
|
|
115
|
+
await publish().catch(() => { });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
119
|
+
return () => controller.abort();
|
|
120
|
+
},
|
|
121
|
+
});
|