opencode-devin 0.2.11 → 2.0.0-beta.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/CHANGELOG.md +56 -0
- package/LICENSE +1 -1
- package/README.md +118 -228
- package/SECURITY.md +81 -0
- package/package.json +52 -58
- package/scripts/dump-log.ts +22 -0
- package/scripts/login.ts +46 -0
- package/src/index.ts +5 -0
- package/src/plugin.ts +293 -0
- package/src/provider/auth.ts +339 -0
- package/src/provider/cascade.ts +469 -0
- package/src/provider/index.ts +321 -0
- package/src/provider/log.ts +99 -0
- package/src/provider/package.json +6 -0
- package/src/provider/paths.ts +33 -0
- package/src/provider/proto.ts +197 -0
- package/dist/catalog.d.ts +0 -22
- package/dist/catalog.js +0 -111
- package/dist/constants.d.ts +0 -19
- package/dist/constants.js +0 -19
- package/dist/credentials.d.ts +0 -23
- package/dist/credentials.js +0 -57
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -135
- package/dist/protocol/model.d.ts +0 -68
- package/dist/protocol/model.js +0 -738
- package/dist/provider.d.ts +0 -43
- package/dist/provider.js +0 -30
package/package.json
CHANGED
|
@@ -1,58 +1,52 @@
|
|
|
1
|
-
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
},
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
"url": "
|
|
44
|
-
},
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@types/bun": "1.4.4",
|
|
55
|
-
"protobufjs": "8.8.1",
|
|
56
|
-
"typescript": "7.0.2"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-devin",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"description": "Devin (Cognition) provider for opencode — clean-room Cascade client, PKCE login, full model catalog",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"CHANGELOG.md",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md",
|
|
14
|
+
"SECURITY.md",
|
|
15
|
+
"scripts",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
20
|
+
"login": "bun run scripts/login.ts",
|
|
21
|
+
"log": "bun run scripts/dump-log.ts"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"opencode",
|
|
25
|
+
"opencode-plugin",
|
|
26
|
+
"opencode-v2",
|
|
27
|
+
"devin",
|
|
28
|
+
"cognition",
|
|
29
|
+
"cascade",
|
|
30
|
+
"windsurf"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"author": {
|
|
34
|
+
"name": "JoShMiQueL",
|
|
35
|
+
"email": "joshmiquel.cs@gmail.com"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/JoShMiQueL/opencode-devin.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/JoShMiQueL/opencode-devin#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/JoShMiQueL/opencode-devin/issues"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@opencode/plugin": "2.4.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/bun": "1.4.5",
|
|
50
|
+
"typescript": "7.0.2"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dump-log — print the tail of devin.log for bug reports.
|
|
3
|
+
*
|
|
4
|
+
* Usage: bun run scripts/dump-log.ts [lines]
|
|
5
|
+
* A user runs this, copies the output, and hands it to us. Tokens are already
|
|
6
|
+
* redacted at write time — the dump is safe to paste anywhere.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
|
|
10
|
+
import { logFile } from "../src/provider/paths.js";
|
|
11
|
+
|
|
12
|
+
const N = Number(process.argv[2] ?? 120);
|
|
13
|
+
const path = logFile();
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const lines = readFileSync(path, "utf8").trimEnd().split("\n");
|
|
17
|
+
console.log(lines.slice(-N).join("\n"));
|
|
18
|
+
console.error(`\n[dump-log] ${Math.min(N, lines.length)} of ${lines.length} lines from ${path}`);
|
|
19
|
+
} catch {
|
|
20
|
+
console.error(`[dump-log] no log file at ${path}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
package/scripts/login.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone Devin PKCE login.
|
|
3
|
+
* bun run scripts/login.ts
|
|
4
|
+
*
|
|
5
|
+
* Opens the browser on app.devin.ai/auth/cli/continue, catches the loopback
|
|
6
|
+
* callback, exchanges the code, verifies the token by minting a user_jwt,
|
|
7
|
+
* then persists the session token to the per-user data dir (gitignored by
|
|
8
|
+
* location — never inside a repo).
|
|
9
|
+
*/
|
|
10
|
+
import { writeFileSync } from "node:fs";
|
|
11
|
+
import { loginAuto, mintUserJwt, SESSION_PREFIX } from "../src/provider/auth.js";
|
|
12
|
+
import { sessionFile } from "../src/provider/paths.js";
|
|
13
|
+
|
|
14
|
+
// Fixed per-user location (%APPDATA%/opencode-devin/session or
|
|
15
|
+
// ~/.config/opencode-devin/session) — the plugin reads it from anywhere.
|
|
16
|
+
const TOKEN_FILE = sessionFile();
|
|
17
|
+
|
|
18
|
+
const flow = await loginAuto();
|
|
19
|
+
console.log("\nOpening Devin login in your browser…");
|
|
20
|
+
console.log("If it doesn't open, paste this URL manually:\n\n " + flow.url + "\n");
|
|
21
|
+
|
|
22
|
+
// cmd `start` splits on & — use rundll32 url.dll,FileProtocolHandler instead
|
|
23
|
+
const openCmd =
|
|
24
|
+
process.platform === "win32"
|
|
25
|
+
? ["rundll32", "url.dll,FileProtocolHandler", flow.url]
|
|
26
|
+
: process.platform === "darwin"
|
|
27
|
+
? ["open", flow.url]
|
|
28
|
+
: ["xdg-open", flow.url];
|
|
29
|
+
Bun.spawn(openCmd, { stdout: "ignore", stderr: "ignore" });
|
|
30
|
+
|
|
31
|
+
console.log("Waiting for the login callback on 127.0.0.1…");
|
|
32
|
+
const cred = await flow.finish();
|
|
33
|
+
console.log("Got session token (redacted).");
|
|
34
|
+
|
|
35
|
+
if (!cred.sessionToken.startsWith(SESSION_PREFIX))
|
|
36
|
+
throw new Error("unexpected token format");
|
|
37
|
+
|
|
38
|
+
// verify it end-to-end: mint a user_jwt against the cascade host
|
|
39
|
+
console.log("Verifying: minting user_jwt via GetUserJwt…");
|
|
40
|
+
const uj = await mintUserJwt(cred.sessionToken);
|
|
41
|
+
console.log("user_jwt OK — cascade host:", uj.cascadeHost);
|
|
42
|
+
|
|
43
|
+
writeFileSync(TOKEN_FILE, cred.sessionToken + "\n", { mode: 0o600 });
|
|
44
|
+
console.log(`\nSaved to ${TOKEN_FILE}\n`);
|
|
45
|
+
console.log("Run a test:");
|
|
46
|
+
console.log(' opencode run --standalone -m devin/swe-2 "say OK"');
|
package/src/index.ts
ADDED
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opencode-devin — clean-room Devin provider plugin for opencode v2.4.
|
|
3
|
+
*
|
|
4
|
+
* Publishes the `devin` provider backed
|
|
5
|
+
* by our own Cascade client (src/provider/*). Credential =
|
|
6
|
+
* devin-session-token$<jwt> from /connect, OPENCODE_DEVIN session file, or
|
|
7
|
+
* DEVIN_API_KEY env var.
|
|
8
|
+
*
|
|
9
|
+
* This module is the package entry point (`src/index.ts` re-exports it); the
|
|
10
|
+
* local `.opencode/plugin/opencode-devin.ts` is a thin re-export for dev
|
|
11
|
+
* auto-loading.
|
|
12
|
+
*/
|
|
13
|
+
import { Plugin, Provider, Model, Credential } from "@opencode/plugin";
|
|
14
|
+
import { Effect } from "effect";
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import * as cascadeModule from "./provider/index.js";
|
|
17
|
+
import * as authModule from "./provider/auth.js";
|
|
18
|
+
import { log, redact, logPath } from "./provider/log.js";
|
|
19
|
+
import * as pathsModule from "./provider/paths.js";
|
|
20
|
+
|
|
21
|
+
// Provider id + display name — everything downstream (provider info, integration
|
|
22
|
+
// id, methods, settings key, /connect labels) derives from these.
|
|
23
|
+
const PROVIDER_ID = "devin" as const;
|
|
24
|
+
const PROVIDER_NAME = "Devin" as const;
|
|
25
|
+
|
|
26
|
+
// Plugin id = npm package name. Replaces the previous opencode-devin@0.x.
|
|
27
|
+
const PLUGIN_ID = "opencode-devin" as const;
|
|
28
|
+
|
|
29
|
+
// Token sources, in priority order:
|
|
30
|
+
// 1. hook options / explicit sessionToken
|
|
31
|
+
// 2. DEVIN_API_KEY env var
|
|
32
|
+
// 3. the /connect stored credential (via resolveStoredToken, needs ctx)
|
|
33
|
+
// 4. the session file in the per-user data dir (paths.ts)
|
|
34
|
+
function resolveSessionToken(opts?: any): string {
|
|
35
|
+
if (opts?.sessionToken) return opts.sessionToken;
|
|
36
|
+
if (process.env.DEVIN_API_KEY) return process.env.DEVIN_API_KEY;
|
|
37
|
+
try {
|
|
38
|
+
const t = readFileSync(pathsModule.sessionFile(), "utf8").trim();
|
|
39
|
+
if (t) return t;
|
|
40
|
+
} catch {}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const CREDENTIAL_TTL_MS = 30 * 24 * 3600 * 1000; // ~30 days, mirrors devin session
|
|
45
|
+
|
|
46
|
+
/** Credential shape opencode stores after /connect finishes. */
|
|
47
|
+
function toStoredCredential(apiKey: string, name = "opencode"): Credential.OAuth {
|
|
48
|
+
return {
|
|
49
|
+
type: "oauth",
|
|
50
|
+
methodID: "devin",
|
|
51
|
+
refresh: "",
|
|
52
|
+
access: apiKey,
|
|
53
|
+
expires: Date.now() + CREDENTIAL_TTL_MS,
|
|
54
|
+
metadata: { name },
|
|
55
|
+
} as unknown as Credential.OAuth;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Read the session token stored by /connect. */
|
|
59
|
+
async function resolveStoredToken(ctx: any): Promise<string | undefined> {
|
|
60
|
+
try {
|
|
61
|
+
const connection = await ctx.integration.connection.active(PROVIDER_ID);
|
|
62
|
+
if (!connection) return undefined;
|
|
63
|
+
const value = await ctx.integration.connection.resolve(connection);
|
|
64
|
+
const access =
|
|
65
|
+
value?.type === "oauth" ? value.access : value?.type === "key" ? value.key : undefined;
|
|
66
|
+
return access?.startsWith("devin-session-token$") ? access : undefined;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
log.warn("credential.resolve_fail", { err: String(e) });
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function openBrowser(url: string): void {
|
|
74
|
+
const cmd =
|
|
75
|
+
process.platform === "win32"
|
|
76
|
+
? ["rundll32", "url.dll,FileProtocolHandler", url]
|
|
77
|
+
: process.platform === "darwin"
|
|
78
|
+
? ["open", url]
|
|
79
|
+
: ["xdg-open", url];
|
|
80
|
+
Bun.spawn(cmd, { stdout: "ignore", stderr: "ignore" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** "Free" = no per-token pricing block — the model rides on the plan quota
|
|
84
|
+
* (swe-2 family, claude, gemini… all carry pricing:undefined). The paid
|
|
85
|
+
* promo tiers (-lightning ultrafast, muse-wonder) report real $/M rates. */
|
|
86
|
+
function isFree(e: { pricing?: { input: number; cachedInput: number; output: number } }): boolean {
|
|
87
|
+
return e.pricing === undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Group catalog entries into one Model.Info per family (baseModelUid), with
|
|
91
|
+
* effort variants from the present suffixes. Speed modifiers like
|
|
92
|
+
* `-fast`/`-lightning`/`ultrafast` live in the family name, not the effort —
|
|
93
|
+
* `swe-2-flash-high` joins family `swe-2-flash` with variant `high`. */
|
|
94
|
+
function catalogModels(
|
|
95
|
+
entries: {
|
|
96
|
+
modelUid: string; label: string; disabled: boolean; contextWindow: number;
|
|
97
|
+
effortLevel?: string; baseModelUid: string;
|
|
98
|
+
pricing?: { input: number; cachedInput: number; output: number };
|
|
99
|
+
}[],
|
|
100
|
+
): Model.Info[] {
|
|
101
|
+
const pid = Provider.ID.make(PROVIDER_ID);
|
|
102
|
+
const families = new Map<string, {
|
|
103
|
+
name: string; ctx: number; free: boolean; variants: Map<string, string>;
|
|
104
|
+
pricing?: { input: number; cachedInput: number; output: number };
|
|
105
|
+
}>();
|
|
106
|
+
for (const e of entries) {
|
|
107
|
+
if (e.disabled || !e.modelUid) continue;
|
|
108
|
+
const fam = families.get(e.baseModelUid) ?? {
|
|
109
|
+
// Strip ONLY the trailing effort word — keep speed modifiers in the
|
|
110
|
+
// family name ("SWE-2 Flash Medium Ultrafast" → effort medium →
|
|
111
|
+
// "SWE-2 Flash Ultrafast"; "SWE-2 Flash Medium" → "SWE-2 Flash").
|
|
112
|
+
name: e.label
|
|
113
|
+
.replace(/\s+(Minimal|Low|Medium|High|XHigh|Max|No Thinking)$/g, "")
|
|
114
|
+
.trim() || e.label,
|
|
115
|
+
ctx: e.contextWindow,
|
|
116
|
+
free: isFree(e),
|
|
117
|
+
variants: new Map(),
|
|
118
|
+
pricing: e.pricing,
|
|
119
|
+
};
|
|
120
|
+
// A member without a pricing block rides the plan quota; keep biggest ctx.
|
|
121
|
+
fam.free = fam.free || isFree(e);
|
|
122
|
+
fam.pricing ??= e.pricing;
|
|
123
|
+
fam.ctx = Math.max(fam.ctx, e.contextWindow);
|
|
124
|
+
if (e.effortLevel) fam.variants.set(e.effortLevel, e.modelUid);
|
|
125
|
+
families.set(e.baseModelUid, fam);
|
|
126
|
+
}
|
|
127
|
+
// float32 wire values carry noise (0.10000000149011612) — round to 4 decimals
|
|
128
|
+
const usd = (n: number) => Math.round(n * 10_000) / 10_000;
|
|
129
|
+
return [...families].map(([base, f]) => ({
|
|
130
|
+
...Model.Info.default(pid, Model.ID.make(base)),
|
|
131
|
+
name: f.name + (f.free ? " · Free" : ""),
|
|
132
|
+
limit: { context: f.ctx, output: 32000 },
|
|
133
|
+
// Plan-quota models report no pricing → no cost entries (opencode shows
|
|
134
|
+
// nothing to pay). Paid families get their real $/1M rates so spend adds up.
|
|
135
|
+
cost: !f.free && f.pricing
|
|
136
|
+
? [{
|
|
137
|
+
input: usd(f.pricing.input),
|
|
138
|
+
output: usd(f.pricing.output),
|
|
139
|
+
cache: { read: usd(f.pricing.cachedInput), write: 0 },
|
|
140
|
+
}]
|
|
141
|
+
: [],
|
|
142
|
+
// Variant id IS the effort word (low/medium/high/…). settings merge into
|
|
143
|
+
// the call options — providerOptions.devin.reasoningEffort reaches doStream.
|
|
144
|
+
variants: [...f.variants].map(([effort]) => ({
|
|
145
|
+
id: effort,
|
|
146
|
+
name: effort,
|
|
147
|
+
settings: { reasoningEffort: effort },
|
|
148
|
+
})),
|
|
149
|
+
} as unknown as Model.Info));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export default Plugin.define({
|
|
153
|
+
id: PLUGIN_ID,
|
|
154
|
+
async setup(ctx) {
|
|
155
|
+
log.info("plugin.setup", {
|
|
156
|
+
aisdkHook: typeof (ctx as any).aisdk?.hook, logPath: logPath(),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Shared token cache — resolved async at publish, read sync by hooks.
|
|
160
|
+
let activeToken = "";
|
|
161
|
+
|
|
162
|
+
if (ctx.aisdk?.hook) {
|
|
163
|
+
// The runtime wants an Effect here (the hook runs it); the published
|
|
164
|
+
// d.ts only declares void | Promise<void>, hence the casts.
|
|
165
|
+
const onSdk = ((evt: any) =>
|
|
166
|
+
Effect.sync(() => {
|
|
167
|
+
if (evt.model?.providerID !== PROVIDER_ID) return;
|
|
168
|
+
log.debug("aisdk.sdk", { modelID: evt.model?.modelID });
|
|
169
|
+
evt.sdk = cascadeModule.createDevinProvider(evt.options ?? {});
|
|
170
|
+
})) as any;
|
|
171
|
+
const onLanguage = ((evt: any) =>
|
|
172
|
+
Effect.sync(() => {
|
|
173
|
+
if (evt.model?.providerID !== PROVIDER_ID) return;
|
|
174
|
+
const token = resolveSessionToken(evt.options) || activeToken;
|
|
175
|
+
// Variant id is the effort word; the language model resolves the
|
|
176
|
+
// exact catalog uid (default member when no variant is selected).
|
|
177
|
+
const variant =
|
|
178
|
+
evt.model?.variant ?? evt.model?.selectedVariant ?? evt.variant;
|
|
179
|
+
const effortId = typeof variant === "string" ? variant : variant?.id;
|
|
180
|
+
const base = evt.model.modelID ?? evt.model.id;
|
|
181
|
+
const modelUid = effortId
|
|
182
|
+
? cascadeModule.withEffortSuffix(base, effortId)
|
|
183
|
+
: base;
|
|
184
|
+
log.info("model.resolve", { base, effort: effortId ?? null, modelUid, token: redact(token) });
|
|
185
|
+
evt.language = new cascadeModule.CascadeLanguageModel(
|
|
186
|
+
modelUid,
|
|
187
|
+
new authModule.DevinCredentials(token),
|
|
188
|
+
);
|
|
189
|
+
})) as any;
|
|
190
|
+
await ctx.aisdk.hook("sdk", onSdk);
|
|
191
|
+
await ctx.aisdk.hook("language", onLanguage);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// /connect integration — three ways to store a session token:
|
|
195
|
+
// auto → browser PKCE flow (loopback callback, no paste)
|
|
196
|
+
// code → headless: open URL, paste the shown code back
|
|
197
|
+
// env → DEVIN_API_KEY env var
|
|
198
|
+
await ctx.integration.transform((editor) => {
|
|
199
|
+
editor.update(PROVIDER_ID, (int: any) => { int.name = PROVIDER_NAME; });
|
|
200
|
+
editor.method.update({
|
|
201
|
+
integrationID: PROVIDER_ID,
|
|
202
|
+
method: { id: "devin", type: "oauth", label: "Log in with Devin (browser)" },
|
|
203
|
+
authorize: async () => {
|
|
204
|
+
const flow = await authModule.loginAuto();
|
|
205
|
+
openBrowser(flow.url);
|
|
206
|
+
return {
|
|
207
|
+
url: flow.url,
|
|
208
|
+
instructions: `Log in to Devin in the opened browser tab. If it did not open, go to: ${flow.url}`,
|
|
209
|
+
mode: "auto",
|
|
210
|
+
callback: flow.finish().then((c: any) => toStoredCredential(c.sessionToken)),
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
editor.method.update({
|
|
215
|
+
integrationID: PROVIDER_ID,
|
|
216
|
+
method: { id: "code", type: "oauth", label: "Paste code (headless)" },
|
|
217
|
+
authorize: async () => {
|
|
218
|
+
const flow = await authModule.loginManual();
|
|
219
|
+
return {
|
|
220
|
+
url: flow.url,
|
|
221
|
+
instructions: "Open the URL, sign in to Devin, copy the code shown, and paste it here.",
|
|
222
|
+
mode: "code",
|
|
223
|
+
callback: async (code: string) =>
|
|
224
|
+
toStoredCredential((await flow.finish(code)).sessionToken),
|
|
225
|
+
};
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
editor.method.update({
|
|
229
|
+
integrationID: PROVIDER_ID,
|
|
230
|
+
method: { type: "env", names: ["DEVIN_API_KEY"] },
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const publish = async () => {
|
|
235
|
+
// /connect credential first, then env / session file.
|
|
236
|
+
const sessionToken =
|
|
237
|
+
(await resolveStoredToken(ctx)) ?? resolveSessionToken();
|
|
238
|
+
if (!sessionToken) {
|
|
239
|
+
log.warn("publish.no_token");
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
activeToken = sessionToken; // shared with the sync aisdk language hook
|
|
243
|
+
log.info("publish.start", { token: redact(sessionToken) });
|
|
244
|
+
let models: Model.Info[] = [];
|
|
245
|
+
try {
|
|
246
|
+
const catalog = await cascadeModule.fetchCatalog(
|
|
247
|
+
new authModule.DevinCredentials(sessionToken),
|
|
248
|
+
);
|
|
249
|
+
models = catalogModels(catalog);
|
|
250
|
+
log.info("provider.catalog", { entries: catalog.length, families: models.length });
|
|
251
|
+
} catch (e) {
|
|
252
|
+
log.error("provider.catalog_fail", { err: String(e) });
|
|
253
|
+
}
|
|
254
|
+
if (!models.length) {
|
|
255
|
+
log.warn("provider.fallback_models");
|
|
256
|
+
models = [{
|
|
257
|
+
...Model.Info.default(Provider.ID.make(PROVIDER_ID), Model.ID.make("swe-2")),
|
|
258
|
+
name: "SWE-2",
|
|
259
|
+
} as Model.Info];
|
|
260
|
+
}
|
|
261
|
+
await ctx.provider.transform((editor) => {
|
|
262
|
+
editor.add({
|
|
263
|
+
info: {
|
|
264
|
+
...Provider.Info.empty(Provider.ID.make(PROVIDER_ID)),
|
|
265
|
+
name: PROVIDER_NAME,
|
|
266
|
+
activation: "enabled",
|
|
267
|
+
package: `aisdk:${new URL("./provider/", import.meta.url).href}`,
|
|
268
|
+
settings: { sessionToken },
|
|
269
|
+
},
|
|
270
|
+
models,
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
await publish().catch((error) => {
|
|
276
|
+
log.error("publish.failed", { err: String(error) });
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const controller = new AbortController();
|
|
280
|
+
void (async () => {
|
|
281
|
+
for await (const event of ctx.event.subscribe({ signal: controller.signal })) {
|
|
282
|
+
if (event.type === "credential.updated" || event.type === "credential.switched") {
|
|
283
|
+
log.info("credential.event", { type: event.type });
|
|
284
|
+
await publish().catch((error) => {
|
|
285
|
+
log.error("republish.fail", { type: event.type, err: String(error) });
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
})();
|
|
290
|
+
|
|
291
|
+
return () => controller.abort();
|
|
292
|
+
},
|
|
293
|
+
});
|