opencode-devin 0.2.2 → 0.2.4
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/README.md +13 -0
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.js +18 -7
- package/dist/index.js +2 -2
- package/dist/protocol/model.d.ts +2 -2
- package/dist/protocol/model.js +3 -3
- package/package.json +54 -53
- package/dist/auth/browser.d.ts +0 -7
- package/dist/auth/browser.js +0 -18
- package/dist/auth/exchange.d.ts +0 -15
- package/dist/auth/exchange.js +0 -43
- package/dist/auth/login.d.ts +0 -15
- package/dist/auth/login.js +0 -51
- package/dist/auth/loopback.d.ts +0 -15
- package/dist/auth/loopback.js +0 -93
- package/dist/auth/pkce.d.ts +0 -11
- package/dist/auth/pkce.js +0 -27
- package/dist/auth/url.d.ts +0 -12
- package/dist/auth/url.js +0 -17
- package/dist/protocol/auth.d.ts +0 -31
- package/dist/protocol/auth.js +0 -142
- package/dist/protocol/catalog.d.ts +0 -69
- package/dist/protocol/catalog.js +0 -230
- package/dist/protocol/chat.d.ts +0 -128
- package/dist/protocol/chat.js +0 -629
- package/dist/protocol/effort.d.ts +0 -36
- package/dist/protocol/effort.js +0 -71
- package/dist/protocol/metadata.d.ts +0 -17
- package/dist/protocol/metadata.js +0 -42
- package/dist/protocol/wire.d.ts +0 -30
- package/dist/protocol/wire.js +0 -114
package/README.md
CHANGED
|
@@ -207,3 +207,16 @@ secret.
|
|
|
207
207
|
## License
|
|
208
208
|
|
|
209
209
|
[MIT](LICENSE)
|
|
210
|
+
|
|
211
|
+
## Ecosystem
|
|
212
|
+
|
|
213
|
+
| Package | Role |
|
|
214
|
+
| --- | --- |
|
|
215
|
+
| `devin-core` | Cascade wire + PKCE auth + catalog — consumed here as `devin-core@^0.0.3` (replaces the old `src/protocol` + `src/auth`) |
|
|
216
|
+
| `devin-engine` | guarded-retry pipeline (embeddable) |
|
|
217
|
+
| `devin-proxy` | standalone OpenAI-compatible proxy |
|
|
218
|
+
| `devin-proxy-py` | Python reference implementation |
|
|
219
|
+
| **`opencode-devin`** (this) | OpenCode v2 plugin — `LanguageModelV3` adapter + `/connect` login |
|
|
220
|
+
| `claude-devin` | Claude/Anthropic-compatible surface — same core |
|
|
221
|
+
|
|
222
|
+
Topic `devin-ecosystem` groups the repos on GitHub.
|
package/dist/catalog.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* those out of the model picker but still resolves them, so a config, a
|
|
16
16
|
* favourite or a session that names `devin/claude-opus-5-5-high` keeps working.
|
|
17
17
|
*/
|
|
18
|
-
import { type ModelCatalogEntry } from "
|
|
18
|
+
import { type ModelCatalogEntry } from "devin-core";
|
|
19
19
|
import { Model } from "@opencode/plugin";
|
|
20
20
|
export declare function fetchModels(apiKey: string, apiServerUrl?: string): Promise<Model.Info[]>;
|
|
21
21
|
/** Exported for tests. */
|
package/dist/catalog.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* those out of the model picker but still resolves them, so a config, a
|
|
16
16
|
* favourite or a session that names `devin/claude-opus-5-5-high` keeps working.
|
|
17
17
|
*/
|
|
18
|
-
import { getCachedCatalog } from "
|
|
19
|
-
import { defaultMember, EFFORT_LEVELS, toEffortLevel } from "
|
|
18
|
+
import { getCachedCatalog } from "devin-core";
|
|
19
|
+
import { defaultMember, EFFORT_LEVELS, toEffortLevel } from "devin-core";
|
|
20
20
|
import { Model, Provider } from "@opencode/plugin";
|
|
21
21
|
import { DEFAULT_RELEASED_MS, PROVIDER_ID } from "./constants.js";
|
|
22
22
|
export async function fetchModels(apiKey, apiServerUrl) {
|
|
@@ -40,11 +40,22 @@ export function toModelInfos(entries) {
|
|
|
40
40
|
}
|
|
41
41
|
const models = [];
|
|
42
42
|
for (const [baseModelUid, family] of families) {
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
// Members carrying a resolvable effort (suffix or capability) are the
|
|
44
|
+
// variant candidates; members without one are bare uids. A bare uid whose
|
|
45
|
+
// modelUid equals the family key is the family's default member — the
|
|
46
|
+
// model the picker shows. Any other bare uid is a distinct model (e.g.
|
|
47
|
+
// `-fast` speed variants sit in their own family key, so this is rare).
|
|
48
|
+
const effortful = family.filter((entry) => toEffortLevel(entry.effortLevel) !== undefined);
|
|
49
|
+
const distinctEfforts = new Set(effortful.map((entry) => toEffortLevel(entry.effortLevel)));
|
|
50
|
+
// Merge when every effortful member maps to a distinct effort. The old
|
|
51
|
+
// rule also required zero bare members — but the bare uid IS the default
|
|
52
|
+
// variant, so a family of bare+effortful must merge too, not explode into
|
|
53
|
+
// one model per uid. Only a family with more than one unresolvable bare
|
|
54
|
+
// member (ambiguous default) falls back to one-model-per-uid.
|
|
55
|
+
const bareCount = family.length - effortful.length;
|
|
56
|
+
if (effortful.length > 0 && distinctEfforts.size === effortful.length && bareCount <= 1) {
|
|
57
|
+
const primary = defaultMember(family);
|
|
58
|
+
models.push(toModelInfo(primary, baseModelUid, effortful));
|
|
48
59
|
for (const entry of family) {
|
|
49
60
|
if (entry.modelUid !== baseModelUid)
|
|
50
61
|
models.push(toModelInfo(entry, entry.modelUid, [], "deprecated"));
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
import { Plugin, Provider } from "@opencode/plugin";
|
|
15
15
|
import { DEFAULT_API_SERVER, LLM_ENV_VAR, PROVIDER_ID } from "./constants.js";
|
|
16
16
|
import { resolveCredentials, toStoredCredential } from "./credentials.js";
|
|
17
|
-
import { openBrowser } from "
|
|
18
|
-
import { loginAuto, loginManual } from "
|
|
17
|
+
import { openBrowser } from "devin-core";
|
|
18
|
+
import { loginAuto, loginManual } from "devin-core";
|
|
19
19
|
import { fetchModels } from "./catalog.js";
|
|
20
20
|
export { createDevinProvider } from "./provider.js";
|
|
21
21
|
export default Plugin.define({
|
package/dist/protocol/model.d.ts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* Originally ported from ai-sdk-devin / pi-devin-auth (MIT).
|
|
10
10
|
*/
|
|
11
11
|
import type { LanguageModelV3, LanguageModelV3Prompt, LanguageModelV3StreamPart, LanguageModelV3Usage, SharedV3Warning } from "@ai-sdk/provider";
|
|
12
|
-
import { type ChatEvent, type ChatHistoryItem } from "
|
|
13
|
-
import { type ModelCatalogEntry } from "
|
|
12
|
+
import { type ChatEvent, type ChatHistoryItem } from "devin-core";
|
|
13
|
+
import { type ModelCatalogEntry } from "devin-core";
|
|
14
14
|
/**
|
|
15
15
|
* Resolve the model UID to send upstream.
|
|
16
16
|
*
|
package/dist/protocol/model.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Originally ported from ai-sdk-devin / pi-devin-auth (MIT).
|
|
10
10
|
*/
|
|
11
|
-
import { streamChatEvents, } from "
|
|
12
|
-
import { getCachedCatalog, ModelNotAvailableError, } from "
|
|
13
|
-
import { defaultMember, splitEffortSuffix, toEffortLevel, withEffortSuffix } from "
|
|
11
|
+
import { streamChatEvents, } from "devin-core";
|
|
12
|
+
import { getCachedCatalog, ModelNotAvailableError, } from "devin-core";
|
|
13
|
+
import { defaultMember, splitEffortSuffix, toEffortLevel, withEffortSuffix } from "devin-core";
|
|
14
14
|
import { DEFAULT_API_SERVER } from "../constants.js";
|
|
15
15
|
/**
|
|
16
16
|
* Resolve the model UID to send upstream.
|
package/package.json
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"./provider": {
|
|
14
|
-
"types": "./dist/provider.d.ts",
|
|
15
|
-
"default": "./dist/provider.js"
|
|
16
|
-
}
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "opencode-devin",
|
|
4
|
+
"version": "0.2.4",
|
|
5
|
+
"description": "OpenCode v2 plugin: connect your Devin subscription to opencode with native /connect login and devin/* models",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
17
12
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "node scripts/build.mjs",
|
|
23
|
-
"build:clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\" && tsc",
|
|
24
|
-
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
25
|
-
"test": "bun test",
|
|
26
|
-
"prepublishOnly": "npm run build:clean"
|
|
27
|
-
},
|
|
28
|
-
"keywords": [
|
|
29
|
-
"opencode",
|
|
30
|
-
"opencode-plugin",
|
|
31
|
-
"opencode-v2",
|
|
32
|
-
"devin",
|
|
33
|
-
"cognition",
|
|
34
|
-
"windsurf"
|
|
35
|
-
],
|
|
36
|
-
"license": "MIT",
|
|
37
|
-
"author": {
|
|
38
|
-
"name": "JoShMiQueL",
|
|
39
|
-
"email": "joshmiquel.cs@gmail.com"
|
|
40
|
-
},
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "git+https://github.com/JoShMiQueL/opencode-devin.git"
|
|
44
|
-
},
|
|
45
|
-
"homepage": "https://github.com/JoShMiQueL/opencode-devin#readme",
|
|
46
|
-
"bugs": "https://github.com/JoShMiQueL/opencode-devin/issues",
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"@ai-sdk/provider": "3.0.8",
|
|
49
|
-
"@opencode/plugin": "2.0.16"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@types/bun": "1.4.4",
|
|
53
|
-
"protobufjs": "8.8.1",
|
|
54
|
-
"typescript": "7.0.2"
|
|
13
|
+
"./provider": {
|
|
14
|
+
"types": "./dist/provider.d.ts",
|
|
15
|
+
"default": "./dist/provider.js"
|
|
55
16
|
}
|
|
56
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "node scripts/build.mjs",
|
|
23
|
+
"build:clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\" && tsc",
|
|
24
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
25
|
+
"test": "bun test",
|
|
26
|
+
"prepublishOnly": "npm run build:clean"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"opencode",
|
|
30
|
+
"opencode-plugin",
|
|
31
|
+
"opencode-v2",
|
|
32
|
+
"devin",
|
|
33
|
+
"cognition",
|
|
34
|
+
"windsurf"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"author": {
|
|
38
|
+
"name": "JoShMiQueL",
|
|
39
|
+
"email": "joshmiquel.cs@gmail.com"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/JoShMiQueL/opencode-devin.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/JoShMiQueL/opencode-devin#readme",
|
|
46
|
+
"bugs": "https://github.com/JoShMiQueL/opencode-devin/issues",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@ai-sdk/provider": "3.0.8",
|
|
49
|
+
"@opencode/plugin": "2.4.1",
|
|
50
|
+
"devin-core": "^0.0.3"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/bun": "1.4.4",
|
|
54
|
+
"protobufjs": "8.8.1",
|
|
55
|
+
"typescript": "7.0.2"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/auth/browser.d.ts
DELETED
package/dist/auth/browser.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Open a URL in the system browser.
|
|
3
|
-
*
|
|
4
|
-
* Windows: `cmd /c start` truncates URLs at "&" (cmd metacharacter) when
|
|
5
|
-
* spawned from Bun — rundll32 hands the URL to the default browser verbatim.
|
|
6
|
-
*/
|
|
7
|
-
export function openBrowser(url) {
|
|
8
|
-
if (process.platform === "win32") {
|
|
9
|
-
Bun.spawn(["rundll32", "url.dll,FileProtocolHandler", url], {
|
|
10
|
-
stdin: "ignore",
|
|
11
|
-
stdout: "ignore",
|
|
12
|
-
stderr: "ignore",
|
|
13
|
-
});
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const cmd = process.platform === "darwin" ? ["open", url] : ["xdg-open", url];
|
|
17
|
-
Bun.spawn(cmd, { stdin: "ignore", stdout: "ignore", stderr: "ignore" });
|
|
18
|
-
}
|
package/dist/auth/exchange.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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>;
|
package/dist/auth/exchange.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/auth/login.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type CallbackServer } from "./loopback.ts";
|
|
2
|
-
export interface LoginFlow {
|
|
3
|
-
/** URL to open in the browser. */
|
|
4
|
-
url: string;
|
|
5
|
-
/** Resolve with the authorization code (auto: wait for redirect; code: pass the pasted code). */
|
|
6
|
-
finish: (code?: string) => Promise<string>;
|
|
7
|
-
/** Abort the flow and release resources. */
|
|
8
|
-
close: () => void;
|
|
9
|
-
}
|
|
10
|
-
/** Start an automatic login: binds the loopback server and returns the URL to open. */
|
|
11
|
-
export declare function loginAuto(): Promise<LoginFlow & {
|
|
12
|
-
server: CallbackServer;
|
|
13
|
-
}>;
|
|
14
|
-
/** Start a manual login: no loopback; the webapp displays the code for pasting. */
|
|
15
|
-
export declare function loginManual(): Promise<LoginFlow>;
|
package/dist/auth/login.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Devin CLI login flow (PKCE), shared by the plugin's `/connect` methods and
|
|
3
|
-
* the standalone `scripts/devin.ts login` command.
|
|
4
|
-
*
|
|
5
|
-
* Two modes, matching what the webapp supports:
|
|
6
|
-
* - "auto": loopback callback — browser redirects to 127.0.0.1, we capture
|
|
7
|
-
* the code. Hands-free once the user finishes the web login.
|
|
8
|
-
* - "code": no redirect_uri — the webapp shows a code the user pastes back.
|
|
9
|
-
* Fallback for headless machines and environments where loopback
|
|
10
|
-
* redirects can't reach the browser.
|
|
11
|
-
*/
|
|
12
|
-
import { authorizeUrl } from "./url.js";
|
|
13
|
-
import { exchangeCode } from "./exchange.js";
|
|
14
|
-
import { startCallbackServer } from "./loopback.js";
|
|
15
|
-
import { challengeFor, generateState, generateVerifier } from "./pkce.js";
|
|
16
|
-
/** Start an automatic login: binds the loopback server and returns the URL to open. */
|
|
17
|
-
export async function loginAuto() {
|
|
18
|
-
const verifier = generateVerifier();
|
|
19
|
-
const state = generateState();
|
|
20
|
-
const server = await startCallbackServer(state);
|
|
21
|
-
const url = authorizeUrl({ state, challenge: await challengeFor(verifier), redirectUri: server.redirectUri });
|
|
22
|
-
return {
|
|
23
|
-
url,
|
|
24
|
-
server,
|
|
25
|
-
finish: async () => {
|
|
26
|
-
try {
|
|
27
|
-
const code = await server.code;
|
|
28
|
-
return await exchangeCode({ code, verifier });
|
|
29
|
-
}
|
|
30
|
-
finally {
|
|
31
|
-
server.close();
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
close: () => server.close(),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/** Start a manual login: no loopback; the webapp displays the code for pasting. */
|
|
38
|
-
export async function loginManual() {
|
|
39
|
-
const verifier = generateVerifier();
|
|
40
|
-
const state = generateState();
|
|
41
|
-
const url = authorizeUrl({ state, challenge: await challengeFor(verifier) });
|
|
42
|
-
return {
|
|
43
|
-
url,
|
|
44
|
-
finish: async (code) => {
|
|
45
|
-
if (!code?.trim())
|
|
46
|
-
throw new Error("Manual login requires the pasted authorization code");
|
|
47
|
-
return exchangeCode({ code: code.trim(), verifier });
|
|
48
|
-
},
|
|
49
|
-
close: () => { },
|
|
50
|
-
};
|
|
51
|
-
}
|
package/dist/auth/loopback.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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, timeoutMs?: number): Promise<CallbackServer>;
|
package/dist/auth/loopback.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
/**
|
|
11
|
-
* How long the loopback listener stays armed waiting for the browser redirect.
|
|
12
|
-
*
|
|
13
|
-
* The integration method registration has no cancellation hook, so an
|
|
14
|
-
* abandoned sign-in (tab closed, user picked the paste-code method instead)
|
|
15
|
-
* would otherwise leave the port bound and the HTTP server running for the
|
|
16
|
-
* life of the process. This timer is the only place that can be cleaned up
|
|
17
|
-
* from, so it is the backstop. Long enough for a real interactive login
|
|
18
|
-
* including any second factor.
|
|
19
|
-
*/
|
|
20
|
-
const CALLBACK_TIMEOUT_MS = 5 * 60 * 1000;
|
|
21
|
-
/** Bind a one-shot HTTP server and wait for the authorization code. */
|
|
22
|
-
export function startCallbackServer(state, timeoutMs = CALLBACK_TIMEOUT_MS) {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
let settle;
|
|
25
|
-
let fail;
|
|
26
|
-
const code = new Promise((res, rej) => {
|
|
27
|
-
settle = res;
|
|
28
|
-
fail = rej;
|
|
29
|
-
});
|
|
30
|
-
let timer;
|
|
31
|
-
let stopped = false;
|
|
32
|
-
const clearTimer = () => {
|
|
33
|
-
if (timer)
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
timer = undefined;
|
|
36
|
-
};
|
|
37
|
-
const stop = () => {
|
|
38
|
-
if (stopped)
|
|
39
|
-
return;
|
|
40
|
-
stopped = true;
|
|
41
|
-
clearTimer();
|
|
42
|
-
server.stop(true);
|
|
43
|
-
};
|
|
44
|
-
let server;
|
|
45
|
-
try {
|
|
46
|
-
server = Bun.serve({
|
|
47
|
-
hostname: "127.0.0.1",
|
|
48
|
-
port: 0,
|
|
49
|
-
async fetch(req) {
|
|
50
|
-
const url = new URL(req.url);
|
|
51
|
-
const page = (title, body, status = 200) => new Response(`<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head>` +
|
|
52
|
-
`<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" } });
|
|
53
|
-
if (url.pathname !== CALLBACK_PATH) {
|
|
54
|
-
return page("Not found", "", 404);
|
|
55
|
-
}
|
|
56
|
-
if (url.searchParams.get("state") !== state) {
|
|
57
|
-
return page("Invalid state parameter", "This may indicate a security issue. Please try again.", 400);
|
|
58
|
-
}
|
|
59
|
-
const received = url.searchParams.get("code");
|
|
60
|
-
if (!received) {
|
|
61
|
-
return page("No authorization code received", "Please return to the terminal and try again.", 400);
|
|
62
|
-
}
|
|
63
|
-
settle?.(received);
|
|
64
|
-
// Stopping here would kill the listener before this response is
|
|
65
|
-
// delivered, so the success page would never reach the browser.
|
|
66
|
-
// The caller closes the server once the code is exchanged.
|
|
67
|
-
clearTimer();
|
|
68
|
-
return page("Signed in to Devin", "You can close this tab and return to opencode.");
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
catch (cause) {
|
|
73
|
-
reject(cause instanceof Error ? cause : new Error("Failed to bind loopback callback server"));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
// Armed before the caller can learn the redirect URI, so there is no
|
|
77
|
-
// window in which a completed redirect would leave the timer running.
|
|
78
|
-
timer = setTimeout(() => {
|
|
79
|
-
const label = timeoutMs >= 1000 ? `${Math.round(timeoutMs / 1000)}s` : `${timeoutMs}ms`;
|
|
80
|
-
fail?.(new Error(`Login timed out after ${label}`));
|
|
81
|
-
stop();
|
|
82
|
-
}, timeoutMs);
|
|
83
|
-
resolve({
|
|
84
|
-
// The server is listening at this point, so the port is always set.
|
|
85
|
-
redirectUri: `http://127.0.0.1:${server.port}${CALLBACK_PATH}`,
|
|
86
|
-
code,
|
|
87
|
-
close: () => {
|
|
88
|
-
fail?.(new Error("Login cancelled"));
|
|
89
|
-
stop();
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}
|
package/dist/auth/pkce.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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;
|
package/dist/auth/pkce.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/auth/url.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/protocol/auth.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `GetUserJwt` — mints the short-lived `user_jwt` required by catalog and chat
|
|
3
|
-
* RPCs. The long-lived session token alone is not accepted.
|
|
4
|
-
*
|
|
5
|
-
* The real lifetime comes from the token's own `exp` claim; the cache only
|
|
6
|
-
* trusts it, and falls back to {@link FALLBACK_JWT_TTL_SECONDS} when `exp` is
|
|
7
|
-
* missing or unparseable. Observed tokens run roughly 24 minutes.
|
|
8
|
-
*
|
|
9
|
-
* Originally ported from pi-devin-auth (MIT, Copyright (c) 2026 nmzpy).
|
|
10
|
-
*/
|
|
11
|
-
import { APICallError } from "@ai-sdk/provider";
|
|
12
|
-
/**
|
|
13
|
-
* An `APICallError`, so the host sees the status: a rejected session token is
|
|
14
|
-
* then reported as an auth failure instead of being retried as unknown.
|
|
15
|
-
*/
|
|
16
|
-
export declare class CloudAuthError extends APICallError {
|
|
17
|
-
readonly status: number;
|
|
18
|
-
constructor(message: string, status: number, url?: string);
|
|
19
|
-
}
|
|
20
|
-
export interface UserJwt {
|
|
21
|
-
jwt: string;
|
|
22
|
-
expiresAt: number;
|
|
23
|
-
}
|
|
24
|
-
/** Mint a fresh user_jwt for the given session token. */
|
|
25
|
-
export declare function mintUserJwt(apiKey: string, host?: string, signal?: AbortSignal): Promise<UserJwt>;
|
|
26
|
-
/** Cache key for one credential against one host. */
|
|
27
|
-
export declare const credentialKey: (host: string, apiKey: string) => string;
|
|
28
|
-
/** Mint a user_jwt, reusing a cached one until shortly before expiry. */
|
|
29
|
-
export declare function getCachedUserJwt(apiKey: string, host?: string, signal?: AbortSignal): Promise<string>;
|
|
30
|
-
/** Drop the cached user_jwt (e.g. after an auth failure). */
|
|
31
|
-
export declare function clearCachedUserJwt(): void;
|