opencode-devin 0.2.1 → 0.2.3
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 +28 -0
- package/dist/catalog.d.ts +11 -0
- package/dist/catalog.js +72 -8
- package/dist/index.js +2 -2
- package/dist/protocol/model.d.ts +15 -7
- package/dist/protocol/model.js +166 -65
- package/package.json +5 -4
- 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 -26
- package/dist/protocol/auth.js +0 -119
- package/dist/protocol/catalog.d.ts +0 -62
- package/dist/protocol/catalog.js +0 -205
- package/dist/protocol/chat.d.ts +0 -92
- package/dist/protocol/chat.js +0 -496
- package/dist/protocol/effort.d.ts +0 -20
- package/dist/protocol/effort.js +0 -31
- 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
|
@@ -57,6 +57,21 @@ From the CLI:
|
|
|
57
57
|
opencode run --model devin/swe-2-max "Refactor the auth module"
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
### Reasoning effort
|
|
61
|
+
|
|
62
|
+
Cognition lists one model UID per reasoning effort (`claude-opus-5-5-low`,
|
|
63
|
+
`claude-opus-5-5-high`, ...). The plugin publishes each family once, as
|
|
64
|
+
`devin/claude-opus-5-5`, with the efforts as variants:
|
|
65
|
+
|
|
66
|
+
- In the TUI, cycle the effort with `ctrl+t` (`variant.cycle`).
|
|
67
|
+
- From the CLI or config, append it: `devin/claude-opus-5-5#high`.
|
|
68
|
+
- With no variant selected, the family runs at medium, or at high when it has
|
|
69
|
+
no medium.
|
|
70
|
+
|
|
71
|
+
Speed and context modifiers are separate families (`devin/claude-opus-5-5-fast`,
|
|
72
|
+
`devin/glm-5-2-1m`). The per-effort UIDs are still accepted, so an existing
|
|
73
|
+
`devin/claude-opus-5-5-high` keeps working; they are only hidden from the picker.
|
|
74
|
+
|
|
60
75
|
## How it works
|
|
61
76
|
|
|
62
77
|
```mermaid
|
|
@@ -192,3 +207,16 @@ secret.
|
|
|
192
207
|
## License
|
|
193
208
|
|
|
194
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
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
* and context windows. This is the same source the Devin CLI uses
|
|
7
7
|
* (`GetCliModelConfigs`); the REST gateway (`/api/v1/models`) is not
|
|
8
8
|
* provisioned for most accounts.
|
|
9
|
+
*
|
|
10
|
+
* Upstream lists one UID per reasoning effort. They are published as one model
|
|
11
|
+
* per family with the efforts as variants, so the effort is picked with the
|
|
12
|
+
* variant switcher instead of by choosing a different model.
|
|
13
|
+
*
|
|
14
|
+
* The per-effort UIDs stay published as deprecated models. opencode leaves
|
|
15
|
+
* those out of the model picker but still resolves them, so a config, a
|
|
16
|
+
* favourite or a session that names `devin/claude-opus-5-5-high` keeps working.
|
|
9
17
|
*/
|
|
18
|
+
import { type ModelCatalogEntry } from "devin-core";
|
|
10
19
|
import { Model } from "@opencode/plugin";
|
|
11
20
|
export declare function fetchModels(apiKey: string, apiServerUrl?: string): Promise<Model.Info[]>;
|
|
21
|
+
/** Exported for tests. */
|
|
22
|
+
export declare function toModelInfos(entries: readonly ModelCatalogEntry[]): Model.Info[];
|
package/dist/catalog.js
CHANGED
|
@@ -6,31 +6,95 @@
|
|
|
6
6
|
* and context windows. This is the same source the Devin CLI uses
|
|
7
7
|
* (`GetCliModelConfigs`); the REST gateway (`/api/v1/models`) is not
|
|
8
8
|
* provisioned for most accounts.
|
|
9
|
+
*
|
|
10
|
+
* Upstream lists one UID per reasoning effort. They are published as one model
|
|
11
|
+
* per family with the efforts as variants, so the effort is picked with the
|
|
12
|
+
* variant switcher instead of by choosing a different model.
|
|
13
|
+
*
|
|
14
|
+
* The per-effort UIDs stay published as deprecated models. opencode leaves
|
|
15
|
+
* those out of the model picker but still resolves them, so a config, a
|
|
16
|
+
* favourite or a session that names `devin/claude-opus-5-5-high` keeps working.
|
|
9
17
|
*/
|
|
10
|
-
import { getCachedCatalog } from "
|
|
18
|
+
import { getCachedCatalog } from "devin-core";
|
|
19
|
+
import { defaultMember, EFFORT_LEVELS, toEffortLevel } from "devin-core";
|
|
11
20
|
import { Model, Provider } from "@opencode/plugin";
|
|
12
21
|
import { DEFAULT_RELEASED_MS, PROVIDER_ID } from "./constants.js";
|
|
13
22
|
export async function fetchModels(apiKey, apiServerUrl) {
|
|
14
23
|
const catalog = await getCachedCatalog(apiKey, apiServerUrl || undefined);
|
|
15
24
|
if (!catalog)
|
|
16
25
|
return [];
|
|
17
|
-
return Array.from(catalog.byUid.values())
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
return toModelInfos(Array.from(catalog.byUid.values()));
|
|
27
|
+
}
|
|
28
|
+
/** Exported for tests. */
|
|
29
|
+
export function toModelInfos(entries) {
|
|
30
|
+
const families = new Map();
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
if (entry.disabled)
|
|
33
|
+
continue;
|
|
34
|
+
const key = entry.baseModelUid ?? entry.modelUid;
|
|
35
|
+
const family = families.get(key);
|
|
36
|
+
if (family)
|
|
37
|
+
family.push(entry);
|
|
38
|
+
else
|
|
39
|
+
families.set(key, [entry]);
|
|
40
|
+
}
|
|
41
|
+
const models = [];
|
|
42
|
+
for (const [baseModelUid, family] of families) {
|
|
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));
|
|
59
|
+
for (const entry of family) {
|
|
60
|
+
if (entry.modelUid !== baseModelUid)
|
|
61
|
+
models.push(toModelInfo(entry, entry.modelUid, [], "deprecated"));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
for (const entry of family)
|
|
66
|
+
models.push(toModelInfo(entry, entry.modelUid, []));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return models;
|
|
70
|
+
}
|
|
71
|
+
/** "Claude Opus 5.5 High Fast" and "GPT-6 Sol No Thinking" without the effort. */
|
|
72
|
+
function familyName(label) {
|
|
73
|
+
const efforts = EFFORT_LEVELS.join("|");
|
|
74
|
+
const stripped = label
|
|
75
|
+
.replace(/\s+No Thinking\b/i, "")
|
|
76
|
+
.replace(new RegExp(`\\s+(?:${efforts})(?:\\s+Thinking)?(?=\\s|$)(?!.*\\s(?:${efforts})(?:\\s|$))`, "i"), "")
|
|
77
|
+
.trim();
|
|
78
|
+
return stripped || label;
|
|
20
79
|
}
|
|
21
|
-
function toModelInfo(entry) {
|
|
80
|
+
function toModelInfo(entry, id, family, status = "active") {
|
|
22
81
|
const { pricing } = entry;
|
|
23
|
-
const base = Model.Info.default(Provider.ID.make(PROVIDER_ID), Model.ID.make(
|
|
82
|
+
const base = Model.Info.default(Provider.ID.make(PROVIDER_ID), Model.ID.make(id));
|
|
83
|
+
const rank = (candidate) => EFFORT_LEVELS.indexOf(toEffortLevel(candidate.effortLevel));
|
|
24
84
|
return {
|
|
25
85
|
...base,
|
|
26
|
-
name: entry.label || entry.
|
|
86
|
+
name: family.length > 0 ? familyName(entry.label || id) : entry.label || id,
|
|
27
87
|
enabled: !entry.disabled,
|
|
28
|
-
status
|
|
88
|
+
status,
|
|
29
89
|
capabilities: {
|
|
30
90
|
tools: true,
|
|
31
91
|
input: ["text", "image"],
|
|
32
92
|
output: ["text"],
|
|
33
93
|
},
|
|
94
|
+
// Read by the provider as `providerOptions.devin.reasoningEffort`.
|
|
95
|
+
variants: [...family]
|
|
96
|
+
.sort((a, b) => rank(a) - rank(b))
|
|
97
|
+
.map((member) => ({ id: member.effortLevel, settings: { reasoningEffort: member.effortLevel } })),
|
|
34
98
|
cost: [
|
|
35
99
|
{
|
|
36
100
|
input: pricing?.input ?? 0,
|
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
|
@@ -8,23 +8,31 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Originally ported from ai-sdk-devin / pi-devin-auth (MIT).
|
|
10
10
|
*/
|
|
11
|
-
import type { LanguageModelV3, LanguageModelV3StreamPart, LanguageModelV3Usage } from "@ai-sdk/provider";
|
|
12
|
-
import { type ChatEvent } from "
|
|
13
|
-
import { type ModelCatalogEntry } from "
|
|
11
|
+
import type { LanguageModelV3, LanguageModelV3Prompt, LanguageModelV3StreamPart, LanguageModelV3Usage, SharedV3Warning } from "@ai-sdk/provider";
|
|
12
|
+
import { type ChatEvent, type ChatHistoryItem } from "devin-core";
|
|
13
|
+
import { type ModelCatalogEntry } from "devin-core";
|
|
14
14
|
/**
|
|
15
|
-
* Resolve the
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Resolve the model UID to send upstream.
|
|
16
|
+
*
|
|
17
|
+
* A model is published once per family, under its UID without the effort, and
|
|
18
|
+
* the effort arrives as `providerOptions.devin.reasoningEffort` from the
|
|
19
|
+
* variant the user picked. Upstream has no effort parameter: each effort is a
|
|
20
|
+
* separate UID, so the choice is made here.
|
|
18
21
|
*
|
|
19
22
|
* Exported for tests: this is what the catalog lookup exists for, so it needs
|
|
20
23
|
* to stay covered independently of the network.
|
|
21
24
|
*/
|
|
22
25
|
export declare function resolveEffortUid(modelId: string, catalog: readonly ModelCatalogEntry[] | undefined, requestedEffort: unknown): string;
|
|
26
|
+
/** Exported for tests. */
|
|
27
|
+
export declare function convertPrompt(prompt: LanguageModelV3Prompt): {
|
|
28
|
+
messages: ChatHistoryItem[];
|
|
29
|
+
warnings: SharedV3Warning[];
|
|
30
|
+
};
|
|
23
31
|
/**
|
|
24
32
|
* Exported for tests: the Cascade event -> AI SDK stream translation is pure,
|
|
25
33
|
* and interleaved parallel tool calls are the case most likely to regress.
|
|
26
34
|
*/
|
|
27
|
-
export declare function convertStreamEvents(events: AsyncGenerator<ChatEvent>, generateId: () => string): AsyncGenerator<LanguageModelV3StreamPart>;
|
|
35
|
+
export declare function convertStreamEvents(events: AsyncGenerator<ChatEvent>, generateId: () => string, warnings?: SharedV3Warning[]): AsyncGenerator<LanguageModelV3StreamPart>;
|
|
28
36
|
interface CollectedResult {
|
|
29
37
|
text: string;
|
|
30
38
|
reasoning: string;
|
package/dist/protocol/model.js
CHANGED
|
@@ -8,33 +8,111 @@
|
|
|
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 { 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
|
-
* Resolve the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Resolve the model UID to send upstream.
|
|
17
|
+
*
|
|
18
|
+
* A model is published once per family, under its UID without the effort, and
|
|
19
|
+
* the effort arrives as `providerOptions.devin.reasoningEffort` from the
|
|
20
|
+
* variant the user picked. Upstream has no effort parameter: each effort is a
|
|
21
|
+
* separate UID, so the choice is made here.
|
|
19
22
|
*
|
|
20
23
|
* Exported for tests: this is what the catalog lookup exists for, so it needs
|
|
21
24
|
* to stay covered independently of the network.
|
|
22
25
|
*/
|
|
23
26
|
export function resolveEffortUid(modelId, catalog, requestedEffort) {
|
|
24
27
|
const effort = toEffortLevel(requestedEffort);
|
|
25
|
-
|
|
28
|
+
const self = splitEffortSuffix(modelId);
|
|
29
|
+
const family = catalog?.filter((entry) => (entry.baseModelUid ?? entry.modelUid) === self.baseModelUid) ?? [];
|
|
30
|
+
if (effort) {
|
|
31
|
+
const match = family.find((entry) => entry.effortLevel === effort);
|
|
32
|
+
if (match)
|
|
33
|
+
return match.modelUid;
|
|
34
|
+
// The catalog is not a contract, so an effort it does not list is still
|
|
35
|
+
// tried on a UID that already carries one.
|
|
36
|
+
if (self.effortLevel)
|
|
37
|
+
return withEffortSuffix(modelId, effort);
|
|
38
|
+
}
|
|
39
|
+
if (!catalog || catalog.some((entry) => entry.modelUid === modelId))
|
|
26
40
|
return modelId;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
// A family id that is not itself a UID, e.g. `claude-opus-5-5`.
|
|
42
|
+
return defaultMember(family)?.modelUid ?? modelId;
|
|
43
|
+
}
|
|
44
|
+
/** Base64 payload of a file part, or `undefined` when it is not inline data. */
|
|
45
|
+
function inlineBase64(data) {
|
|
46
|
+
if (data instanceof Uint8Array)
|
|
47
|
+
return Buffer.from(data).toString("base64");
|
|
48
|
+
if (typeof data !== "string")
|
|
49
|
+
return undefined;
|
|
50
|
+
const dataUrl = /^data:[^,]*;base64,(.*)$/s.exec(data);
|
|
51
|
+
if (dataUrl)
|
|
52
|
+
return dataUrl[1];
|
|
53
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(data) ? undefined : data;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Cascade carries images and nothing else. Anything else is replaced by a
|
|
57
|
+
* note, so the model can say the attachment is missing instead of answering as
|
|
58
|
+
* if it had never been sent, and is reported to the caller as a warning.
|
|
59
|
+
*/
|
|
60
|
+
function pushFile(parts, warnings, file) {
|
|
61
|
+
const base64 = file.mediaType.startsWith("image/") ? inlineBase64(file.data) : undefined;
|
|
62
|
+
if (base64 !== undefined) {
|
|
63
|
+
parts.push({ type: "image", mimeType: file.mediaType, base64Data: base64 });
|
|
64
|
+
return;
|
|
32
65
|
}
|
|
33
|
-
|
|
66
|
+
const what = file.filename ? `${file.mediaType} file "${file.filename}"` : `${file.mediaType} file`;
|
|
67
|
+
const why = file.mediaType.startsWith("image/") ? "only inline image data can be sent" : "only images can be sent";
|
|
68
|
+
parts.push({ type: "text", text: `[Attachment omitted: ${what}. The Devin provider could not send it; ${why}.]` });
|
|
69
|
+
warnings.push({ type: "unsupported", feature: `${file.mediaType} file input`, details: `Omitted: ${why}.` });
|
|
34
70
|
}
|
|
35
|
-
|
|
36
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Flatten a tool result to what the model should read.
|
|
73
|
+
*
|
|
74
|
+
* The output is a tagged union, not the content itself: serialising it whole
|
|
75
|
+
* sends the model `{"type":"text","value":"line1\\nline2"}` in place of the two
|
|
76
|
+
* lines, which costs tokens on every tool call and is harder to read.
|
|
77
|
+
*/
|
|
78
|
+
function convertToolOutput(output, warnings) {
|
|
79
|
+
const text = (value) => [{ type: "text", text: value }];
|
|
80
|
+
switch (output.type) {
|
|
81
|
+
case "text":
|
|
82
|
+
return { content: text(output.value), isError: false };
|
|
83
|
+
case "json":
|
|
84
|
+
return { content: text(JSON.stringify(output.value)), isError: false };
|
|
85
|
+
case "error-text":
|
|
86
|
+
return { content: text(output.value), isError: true };
|
|
87
|
+
case "error-json":
|
|
88
|
+
return { content: text(JSON.stringify(output.value)), isError: true };
|
|
89
|
+
case "execution-denied":
|
|
90
|
+
return {
|
|
91
|
+
content: text(output.reason ? `Tool execution was denied: ${output.reason}` : "Tool execution was denied."),
|
|
92
|
+
isError: true,
|
|
93
|
+
};
|
|
94
|
+
case "content": {
|
|
95
|
+
const content = [];
|
|
96
|
+
for (const part of output.value) {
|
|
97
|
+
if (part.type === "text")
|
|
98
|
+
content.push({ type: "text", text: part.text });
|
|
99
|
+
else if (part.type === "image-data" || part.type === "file-data")
|
|
100
|
+
pushFile(content, warnings, part);
|
|
101
|
+
else {
|
|
102
|
+
content.push({ type: "text", text: `[Attachment omitted: the Devin provider cannot send a ${part.type} part.]` });
|
|
103
|
+
warnings.push({ type: "unsupported", feature: `${part.type} tool output` });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { content, isError: false };
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
return { content: text(JSON.stringify(output)), isError: false };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Exported for tests. */
|
|
113
|
+
export function convertPrompt(prompt) {
|
|
37
114
|
const items = [];
|
|
115
|
+
const warnings = [];
|
|
38
116
|
for (const message of prompt) {
|
|
39
117
|
if (message.role === "system") {
|
|
40
118
|
items.push({ role: "system", content: message.content });
|
|
@@ -42,13 +120,10 @@ function convertPrompt(prompt) {
|
|
|
42
120
|
else if (message.role === "user") {
|
|
43
121
|
const parts = [];
|
|
44
122
|
for (const part of message.content) {
|
|
45
|
-
if (part.type === "text")
|
|
123
|
+
if (part.type === "text")
|
|
46
124
|
parts.push({ type: "text", text: part.text });
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const data = typeof part.data === "string" ? part.data : Buffer.from(part.data).toString("base64");
|
|
50
|
-
parts.push({ type: "image", mimeType: part.mediaType, base64Data: data });
|
|
51
|
-
}
|
|
125
|
+
else if (part.type === "file")
|
|
126
|
+
pushFile(parts, warnings, part);
|
|
52
127
|
}
|
|
53
128
|
items.push({ role: "user", content: parts });
|
|
54
129
|
}
|
|
@@ -72,14 +147,48 @@ function convertPrompt(prompt) {
|
|
|
72
147
|
else if (message.role === "tool") {
|
|
73
148
|
for (const part of message.content) {
|
|
74
149
|
if (part.type === "tool-result") {
|
|
75
|
-
const
|
|
76
|
-
items.push({
|
|
150
|
+
const { content, isError } = convertToolOutput(part.output, warnings);
|
|
151
|
+
items.push({
|
|
152
|
+
role: "tool",
|
|
153
|
+
content,
|
|
154
|
+
tool_call_id: part.toolCallId,
|
|
155
|
+
...(isError ? { is_error: true } : {}),
|
|
156
|
+
});
|
|
77
157
|
}
|
|
78
158
|
}
|
|
79
159
|
}
|
|
80
160
|
}
|
|
81
|
-
return items;
|
|
161
|
+
return { messages: items, warnings };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Cascade reports uncached input, cache reads and cache writes as separate
|
|
165
|
+
* counts: against the live API a repeated 165k-token prompt came back as
|
|
166
|
+
* `input_tokens=4, cached_input_tokens=165031`. The total is their sum, and
|
|
167
|
+
* `promptTokens` is already the uncached share.
|
|
168
|
+
*/
|
|
169
|
+
function toUsage(event) {
|
|
170
|
+
const { promptTokens, cachedInputTokens, cacheCreationInputTokens, completionTokens, reasoningTokens } = event;
|
|
171
|
+
return {
|
|
172
|
+
inputTokens: {
|
|
173
|
+
total: promptTokens === undefined
|
|
174
|
+
? undefined
|
|
175
|
+
: promptTokens + (cachedInputTokens ?? 0) + (cacheCreationInputTokens ?? 0),
|
|
176
|
+
noCache: promptTokens,
|
|
177
|
+
cacheRead: cachedInputTokens,
|
|
178
|
+
cacheWrite: cacheCreationInputTokens,
|
|
179
|
+
},
|
|
180
|
+
outputTokens: {
|
|
181
|
+
total: completionTokens,
|
|
182
|
+
text: completionTokens !== undefined && reasoningTokens !== undefined ? completionTokens - reasoningTokens : undefined,
|
|
183
|
+
reasoning: reasoningTokens,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
82
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Some upstream models end a turn that made tool calls with a plain stop, or
|
|
189
|
+
* with no stop reason at all. The caller has to run the tools either way.
|
|
190
|
+
*/
|
|
191
|
+
const finishReasonFor = (reason, madeToolCalls) => madeToolCalls && reason === "stop" ? "tool_calls" : reason;
|
|
83
192
|
function convertTools(tools) {
|
|
84
193
|
if (!tools || tools.length === 0)
|
|
85
194
|
return undefined;
|
|
@@ -112,7 +221,7 @@ const TICK = Symbol("coalesce-tick");
|
|
|
112
221
|
* Exported for tests: the Cascade event -> AI SDK stream translation is pure,
|
|
113
222
|
* and interleaved parallel tool calls are the case most likely to regress.
|
|
114
223
|
*/
|
|
115
|
-
export async function* convertStreamEvents(events, generateId) {
|
|
224
|
+
export async function* convertStreamEvents(events, generateId, warnings = []) {
|
|
116
225
|
let textId = "";
|
|
117
226
|
let reasoningId = "";
|
|
118
227
|
let textOpen = false;
|
|
@@ -129,6 +238,7 @@ export async function* convertStreamEvents(events, generateId) {
|
|
|
129
238
|
const openTools = new Map();
|
|
130
239
|
// Deltas that carry no id belong to the most recently opened call.
|
|
131
240
|
let lastToolId = "";
|
|
241
|
+
let madeToolCalls = false;
|
|
132
242
|
const pendingDeltas = () => {
|
|
133
243
|
const parts = [];
|
|
134
244
|
if (textBuf) {
|
|
@@ -155,9 +265,11 @@ export async function* convertStreamEvents(events, generateId) {
|
|
|
155
265
|
};
|
|
156
266
|
// The protocol has no end-of-tool-call marker, so a call cannot be completed
|
|
157
267
|
// until the stream ends. They are emitted in the order they were started.
|
|
268
|
+
// The arguments themselves are streamed as they arrive, see `tool_call_args`.
|
|
158
269
|
const completedToolCalls = () => {
|
|
159
270
|
const parts = [];
|
|
160
271
|
for (const [id, tool] of openTools) {
|
|
272
|
+
parts.push({ type: "tool-input-end", id });
|
|
161
273
|
parts.push({ type: "tool-call", toolCallId: id, toolName: tool.name, input: tool.args });
|
|
162
274
|
}
|
|
163
275
|
openTools.clear();
|
|
@@ -230,20 +342,27 @@ export async function* convertStreamEvents(events, generateId) {
|
|
|
230
342
|
parts.push(...pendingDeltas());
|
|
231
343
|
parts.push(...closeBlocks());
|
|
232
344
|
const id = event.id || generateId();
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
else
|
|
345
|
+
// A repeated start keeps the first name: the call was already announced
|
|
346
|
+
// under it, and a host rejects a call whose name changes midway.
|
|
347
|
+
if (!openTools.has(id)) {
|
|
237
348
|
openTools.set(id, { name: event.name, args: "" });
|
|
349
|
+
madeToolCalls = true;
|
|
350
|
+
parts.push({ type: "tool-input-start", id, toolName: event.name });
|
|
351
|
+
}
|
|
238
352
|
lastToolId = id;
|
|
239
353
|
break;
|
|
240
354
|
}
|
|
241
355
|
case "tool_call_args": {
|
|
242
|
-
const
|
|
356
|
+
const id = event.id ?? lastToolId;
|
|
357
|
+
const open = openTools.get(id);
|
|
243
358
|
// An orphan delta has no call to attach to; dropping it beats inventing
|
|
244
359
|
// a nameless tool call.
|
|
245
|
-
if (open)
|
|
360
|
+
if (open && event.argsDelta) {
|
|
246
361
|
open.args += event.argsDelta;
|
|
362
|
+
// Streamed so a long call, such as writing a file, shows progress
|
|
363
|
+
// instead of looking stalled until the whole turn has arrived.
|
|
364
|
+
parts.push({ type: "tool-input-delta", id, delta: event.argsDelta });
|
|
365
|
+
}
|
|
247
366
|
break;
|
|
248
367
|
}
|
|
249
368
|
case "finish": {
|
|
@@ -253,23 +372,7 @@ export async function* convertStreamEvents(events, generateId) {
|
|
|
253
372
|
break;
|
|
254
373
|
}
|
|
255
374
|
case "usage": {
|
|
256
|
-
usage =
|
|
257
|
-
inputTokens: {
|
|
258
|
-
total: event.promptTokens,
|
|
259
|
-
noCache: event.promptTokens !== undefined && event.cachedInputTokens !== undefined
|
|
260
|
-
? event.promptTokens - event.cachedInputTokens
|
|
261
|
-
: undefined,
|
|
262
|
-
cacheRead: event.cachedInputTokens,
|
|
263
|
-
cacheWrite: event.cacheCreationInputTokens,
|
|
264
|
-
},
|
|
265
|
-
outputTokens: {
|
|
266
|
-
total: event.completionTokens,
|
|
267
|
-
text: event.completionTokens !== undefined && event.reasoningTokens !== undefined
|
|
268
|
-
? event.completionTokens - event.reasoningTokens
|
|
269
|
-
: undefined,
|
|
270
|
-
reasoning: event.reasoningTokens,
|
|
271
|
-
},
|
|
272
|
-
};
|
|
375
|
+
usage = toUsage(event);
|
|
273
376
|
break;
|
|
274
377
|
}
|
|
275
378
|
}
|
|
@@ -296,7 +399,7 @@ export async function* convertStreamEvents(events, generateId) {
|
|
|
296
399
|
// With nothing buffered there is nothing to flush, so the timer race — and its
|
|
297
400
|
// allocation — is skipped entirely for the common fast-streaming path.
|
|
298
401
|
const nextStep = () => textBuf || reasoningBuf ? Promise.race([nextEvent(), tick()]) : nextEvent();
|
|
299
|
-
yield { type: "stream-start", warnings
|
|
402
|
+
yield { type: "stream-start", warnings };
|
|
300
403
|
try {
|
|
301
404
|
for (;;) {
|
|
302
405
|
const step = await nextStep();
|
|
@@ -324,6 +427,7 @@ export async function* convertStreamEvents(events, generateId) {
|
|
|
324
427
|
yield* pendingDeltas();
|
|
325
428
|
yield* closeBlocks();
|
|
326
429
|
yield* completedToolCalls();
|
|
430
|
+
finishReason = finishReasonFor(finishReason, madeToolCalls);
|
|
327
431
|
const rawReason = FINISH_REASON_MAP[finishReason] ?? "stop";
|
|
328
432
|
yield {
|
|
329
433
|
type: "finish",
|
|
@@ -374,19 +478,12 @@ export async function collectEvents(events) {
|
|
|
374
478
|
result.finishReason = event.reason;
|
|
375
479
|
break;
|
|
376
480
|
case "usage":
|
|
377
|
-
result.usage =
|
|
378
|
-
inputTokens: {
|
|
379
|
-
total: event.promptTokens,
|
|
380
|
-
noCache: undefined,
|
|
381
|
-
cacheRead: event.cachedInputTokens,
|
|
382
|
-
cacheWrite: event.cacheCreationInputTokens,
|
|
383
|
-
},
|
|
384
|
-
outputTokens: { total: event.completionTokens, text: undefined, reasoning: event.reasoningTokens },
|
|
385
|
-
};
|
|
481
|
+
result.usage = toUsage(event);
|
|
386
482
|
break;
|
|
387
483
|
}
|
|
388
484
|
}
|
|
389
485
|
commit();
|
|
486
|
+
result.finishReason = finishReasonFor(result.finishReason, result.toolCalls.length > 0);
|
|
390
487
|
return result;
|
|
391
488
|
}
|
|
392
489
|
/**
|
|
@@ -439,18 +536,22 @@ function hintUnlistedModel(cause, modelId, known) {
|
|
|
439
536
|
function createLanguageModel(options) {
|
|
440
537
|
const run = async (callOptions, signal) => {
|
|
441
538
|
const catalog = await options.loadCatalog();
|
|
442
|
-
checkModelUsable(options.modelId, catalog);
|
|
443
539
|
const effortOverride = callOptions.providerOptions?.devin?.reasoningEffort;
|
|
444
540
|
const resolvedModelId = resolveEffortUid(options.modelId, catalog?.enabled, effortOverride);
|
|
541
|
+
// Checked on the UID that is sent: a family id is not a UID of its own.
|
|
542
|
+
checkModelUsable(resolvedModelId, catalog);
|
|
543
|
+
const { messages, warnings } = convertPrompt(callOptions.prompt);
|
|
445
544
|
return {
|
|
446
545
|
resolvedModelId,
|
|
447
|
-
|
|
546
|
+
warnings,
|
|
547
|
+
knownToCatalog: isKnownToCatalog(resolvedModelId, catalog),
|
|
448
548
|
events: streamChatEvents({
|
|
449
549
|
apiKey: options.apiKey,
|
|
450
550
|
apiServerUrl: options.apiServerUrl,
|
|
451
551
|
modelUid: resolvedModelId,
|
|
452
|
-
messages
|
|
552
|
+
messages,
|
|
453
553
|
tools: convertTools(callOptions.tools),
|
|
554
|
+
toolChoice: callOptions.toolChoice,
|
|
454
555
|
completionOpts: {
|
|
455
556
|
maxOutputTokens: callOptions.maxOutputTokens,
|
|
456
557
|
temperature: callOptions.temperature,
|
|
@@ -467,7 +568,7 @@ function createLanguageModel(options) {
|
|
|
467
568
|
modelId: options.modelId,
|
|
468
569
|
supportedUrls: {},
|
|
469
570
|
async doGenerate(callOptions) {
|
|
470
|
-
const { events, knownToCatalog } = await run(callOptions, callOptions.abortSignal);
|
|
571
|
+
const { events, knownToCatalog, warnings } = await run(callOptions, callOptions.abortSignal);
|
|
471
572
|
const collected = await collectEvents(events).catch((cause) => {
|
|
472
573
|
throw hintUnlistedModel(cause, options.modelId, knownToCatalog);
|
|
473
574
|
});
|
|
@@ -486,7 +587,7 @@ function createLanguageModel(options) {
|
|
|
486
587
|
raw: collected.finishReason,
|
|
487
588
|
},
|
|
488
589
|
usage: collected.usage ?? DEFAULT_USAGE,
|
|
489
|
-
warnings
|
|
590
|
+
warnings,
|
|
490
591
|
};
|
|
491
592
|
},
|
|
492
593
|
async doStream(callOptions) {
|
|
@@ -496,9 +597,9 @@ function createLanguageModel(options) {
|
|
|
496
597
|
const signal = callOptions.abortSignal
|
|
497
598
|
? AbortSignal.any([callOptions.abortSignal, abort.signal])
|
|
498
599
|
: abort.signal;
|
|
499
|
-
const { events, knownToCatalog } = await run(callOptions, signal);
|
|
600
|
+
const { events, knownToCatalog, warnings } = await run(callOptions, signal);
|
|
500
601
|
const generateId = () => crypto.randomUUID();
|
|
501
|
-
const generator = convertStreamEvents(events, generateId);
|
|
602
|
+
const generator = convertStreamEvents(events, generateId, warnings);
|
|
502
603
|
const modelId = options.modelId;
|
|
503
604
|
let cancelled = false;
|
|
504
605
|
const stream = new ReadableStream({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "opencode-devin",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"description": "OpenCode v2 plugin: connect your Devin subscription to opencode with native /connect login and devin/* models",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -46,11 +46,12 @@
|
|
|
46
46
|
"bugs": "https://github.com/JoShMiQueL/opencode-devin/issues",
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@ai-sdk/provider": "3.0.8",
|
|
49
|
-
"@opencode/plugin": "2.0.16"
|
|
49
|
+
"@opencode/plugin": "2.0.16",
|
|
50
|
+
"devin-core": "^0.0.3"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@types/bun": "1.4.4",
|
|
53
|
-
"protobufjs": "
|
|
54
|
+
"protobufjs": "8.8.1",
|
|
54
55
|
"typescript": "7.0.2"
|
|
55
56
|
}
|
|
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>;
|