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.
@@ -1,205 +0,0 @@
1
- /**
2
- * `GetCascadeModelConfigs` — per-account model catalog from Cognition.
3
- *
4
- * Returns every model UID the subscription can use, with pricing and context
5
- * windows. This is the same source the Devin CLI uses (`GetCliModelConfigs`).
6
- * Originally ported from pi-devin-auth (MIT, Copyright (c) 2026 nmzpy).
7
- */
8
- import { encodeMessage, iterFields } from "./wire.js";
9
- import { buildMetadata } from "./metadata.js";
10
- import { clearCachedUserJwt, credentialKey, getCachedUserJwt } from "./auth.js";
11
- import { splitEffortSuffix } from "./effort.js";
12
- import { DEFAULT_API_SERVER } from "../constants.js";
13
- const CATALOG_TTL_MS = 10 * 60 * 1000;
14
- const CATALOG_FETCH_TIMEOUT_MS = 10_000;
15
- /**
16
- * Raised when the account's catalog lists the model but marks it disabled.
17
- *
18
- * Only this case is safe to fail on: the catalog states it explicitly, so the
19
- * upstream request would be rejected regardless. A model that is simply absent
20
- * is *not* asserted on, because the catalog is not guaranteed to enumerate every
21
- * uid Cascade accepts and a false rejection would break a working model.
22
- */
23
- export class ModelNotAvailableError extends Error {
24
- modelUid;
25
- label;
26
- constructor(modelUid, label) {
27
- super(label && label !== modelUid
28
- ? `Model "${label}" (uid=${modelUid}) is not enabled for your Cognition account tier.`
29
- : `Model uid "${modelUid}" is not enabled for your Cognition account tier.`);
30
- this.name = "ModelNotAvailableError";
31
- this.modelUid = modelUid;
32
- this.label = label;
33
- }
34
- }
35
- async function fetchCatalog(apiKey, host, signal) {
36
- const userJwt = await getCachedUserJwt(apiKey, host, signal);
37
- const metadata = buildMetadata({
38
- apiKey,
39
- userJwt,
40
- sessionId: crypto.randomUUID(),
41
- requestId: BigInt(Date.now()),
42
- triggerId: crypto.randomUUID(),
43
- });
44
- const request = encodeMessage(1, metadata);
45
- const timeout = AbortSignal.timeout(CATALOG_FETCH_TIMEOUT_MS);
46
- const response = await fetch(`${host}/exa.api_server_pb.ApiServerService/GetCascadeModelConfigs`, {
47
- method: "POST",
48
- headers: { "Content-Type": "application/proto", "Connect-Protocol-Version": "1" },
49
- body: new Uint8Array(request),
50
- signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
51
- });
52
- if (!response.ok) {
53
- const text = await response.text();
54
- // A 401 means the cached user_jwt was rejected. Drop it so the next attempt
55
- // mints a fresh one instead of replaying a token already known to be bad.
56
- if (response.status === 401)
57
- clearCachedUserJwt();
58
- throw new Error(`GetCascadeModelConfigs HTTP ${response.status}: ${text.slice(0, 200)}`);
59
- }
60
- const buf = Buffer.from(await response.arrayBuffer());
61
- const byUid = new Map();
62
- for (const field of iterFields(buf)) {
63
- if (field.num !== 1 || field.wire !== 2 || !Buffer.isBuffer(field.value))
64
- continue;
65
- const entry = decodeModelConfig(field.value);
66
- if (entry)
67
- byUid.set(entry.modelUid, entry);
68
- }
69
- return { byUid, fetchedAt: Date.now(), apiKey, host };
70
- }
71
- function decodeModelConfig(buf) {
72
- let label = "";
73
- let modelUid = "";
74
- let disabled = false;
75
- let contextWindow = 0;
76
- let pricing;
77
- let capabilities;
78
- for (const field of iterFields(buf)) {
79
- if (field.num === 1 && field.wire === 2 && Buffer.isBuffer(field.value)) {
80
- label = field.value.toString("utf8");
81
- }
82
- else if (field.num === 4 && field.wire === 0) {
83
- disabled = field.value === 1n;
84
- }
85
- else if (field.num === 18 && field.wire === 0) {
86
- contextWindow = Number(field.value);
87
- }
88
- else if (field.num === 22 && field.wire === 2 && Buffer.isBuffer(field.value)) {
89
- modelUid = field.value.toString("utf8");
90
- }
91
- else if (field.num === 30 && field.wire === 2 && Buffer.isBuffer(field.value)) {
92
- // Capabilities message: #1 display name, #2 (repeated) feature { #1 name, #2 { #1 enabled, #2 value } }
93
- capabilities = [];
94
- for (const feature of iterFields(field.value)) {
95
- if (feature.num !== 2 || feature.wire !== 2 || !Buffer.isBuffer(feature.value))
96
- continue;
97
- let name = "";
98
- let enabled = false;
99
- let value;
100
- for (const part of iterFields(feature.value)) {
101
- if (part.num === 1 && part.wire === 2 && Buffer.isBuffer(part.value)) {
102
- name = part.value.toString("utf8");
103
- }
104
- else if (part.num === 1 && part.wire === 0) {
105
- enabled = part.value === 1n;
106
- }
107
- else if (part.num === 2 && part.wire === 2 && Buffer.isBuffer(part.value)) {
108
- value = part.value.toString("utf8");
109
- }
110
- }
111
- if (name)
112
- capabilities.push({ name, enabled, value });
113
- }
114
- }
115
- else if (field.num === 32 && field.wire === 2 && Buffer.isBuffer(field.value)) {
116
- // Pricing message (repeated), verified against a live
117
- // GetCascadeModelConfigs dump and the prices shown in the Devin app
118
- // (e.g. claude-opus-5-5 = $4/$20, claude-sonnet-5-5 = $2/$10):
119
- // #1 type string "Input" | "Cached input" | "Output"
120
- // #2 price float32 USD per unit (#3 = "1M tokens") ← real price
121
- // #3 unit string "1M tokens"
122
- // #4 factor float32 per-type constant (0.1/0.007/0.28) —
123
- // internal credit coefficient, NOT the price.
124
- // This is what the old code read by mistake.
125
- // #5 credits float32 same price expressed in Cognition credits
126
- // #6 flag varint 1
127
- // #7 note string e.g. "Higher effort consumes more tokens"
128
- pricing ??= { input: 0, cachedInput: 0, output: 0 };
129
- let type = "";
130
- let price = 0;
131
- for (const part of iterFields(field.value)) {
132
- if (part.num === 1 && part.wire === 2 && Buffer.isBuffer(part.value)) {
133
- type = part.value.toString("utf8").toLowerCase();
134
- }
135
- else if (part.num === 2 &&
136
- part.wire === 5 &&
137
- Buffer.isBuffer(part.value) &&
138
- part.value.length === 4) {
139
- price = part.value.readFloatLE(0);
140
- }
141
- }
142
- // Match the pricing dimension by exact label, not substring: the REST
143
- // API documents extra labels like "sidekick_input" (Fusion models) and
144
- // "cache_read"/"cache_write" that would corrupt a substring match.
145
- // Normalise case/spacing defensively — the wire strings are the same
146
- // labels the REST API exposes in snake_case.
147
- const normalized = type.trim().toLowerCase().replace(/[\s-]+/g, "_");
148
- if (normalized === "input")
149
- pricing.input = price;
150
- else if (normalized === "cached_input" || normalized === "cache_read")
151
- pricing.cachedInput = price;
152
- else if (normalized === "output")
153
- pricing.output = price;
154
- }
155
- }
156
- if (modelUid.length === 0)
157
- return undefined;
158
- const { baseModelUid, effortLevel } = splitEffortSuffix(modelUid);
159
- return {
160
- modelUid,
161
- label: label || modelUid,
162
- disabled,
163
- contextWindow,
164
- pricing,
165
- capabilities,
166
- baseModelUid,
167
- effortLevel,
168
- };
169
- }
170
- let cached = null;
171
- let inFlight = null;
172
- let inFlightKey = null;
173
- const flightKey = (apiKey, host) => credentialKey(host, apiKey);
174
- /** Fetch the per-account catalog, cached for 10 minutes. Returns null on failure. */
175
- export async function getCachedCatalog(apiKey, host = DEFAULT_API_SERVER, signal) {
176
- if (cached && cached.apiKey === apiKey && cached.host === host && Date.now() - cached.fetchedAt < CATALOG_TTL_MS) {
177
- return cached;
178
- }
179
- const key = flightKey(apiKey, host);
180
- if (inFlight && inFlightKey === key) {
181
- try {
182
- return await inFlight;
183
- }
184
- catch {
185
- return null;
186
- }
187
- }
188
- const promise = fetchCatalog(apiKey, host, signal);
189
- inFlight = promise;
190
- inFlightKey = key;
191
- try {
192
- const result = await promise;
193
- cached = result;
194
- return result;
195
- }
196
- catch {
197
- return null;
198
- }
199
- finally {
200
- if (inFlight === promise) {
201
- inFlight = null;
202
- inFlightKey = null;
203
- }
204
- }
205
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * `GetChatMessage` — chat streaming over Cognition's Connect-RPC endpoint.
3
- *
4
- * Field layouts come from mitm captures of the Windsurf language_server.
5
- * Originally ported from pi-devin-auth (MIT, Copyright (c) 2026 nmzpy).
6
- */
7
- export declare class CloudChatError extends Error {
8
- readonly code?: string;
9
- readonly traceId?: string;
10
- constructor(message: string, code?: string, traceId?: string);
11
- }
12
- /** Cognition rejects source=3 for system; system content is inlined into user turns. */
13
- declare const SOURCE_BY_ROLE: {
14
- readonly user: 1;
15
- readonly assistant: 2;
16
- readonly system: 1;
17
- readonly tool: 4;
18
- };
19
- export type ChatRole = keyof typeof SOURCE_BY_ROLE;
20
- export interface ChatImage {
21
- mimeType: string;
22
- base64Data: string;
23
- caption?: string;
24
- }
25
- export type ChatContent = string | Array<{
26
- type: "text";
27
- text: string;
28
- } | ({
29
- type: "image";
30
- } & ChatImage)>;
31
- export interface ChatToolCall {
32
- id: string;
33
- name: string;
34
- arguments: string;
35
- }
36
- export interface ChatHistoryItem {
37
- role: ChatRole;
38
- content: ChatContent;
39
- tool_call_id?: string;
40
- tool_calls?: ChatToolCall[];
41
- }
42
- export interface ChatToolDefinition {
43
- name: string;
44
- description?: string;
45
- parameters?: unknown;
46
- }
47
- export interface CompletionOptions {
48
- maxInputTokens?: number;
49
- maxOutputTokens?: number;
50
- temperature?: number;
51
- topP?: number;
52
- topK?: number;
53
- }
54
- export type ChatEvent = {
55
- kind: "text";
56
- text: string;
57
- } | {
58
- kind: "reasoning";
59
- text: string;
60
- } | {
61
- kind: "tool_call_start";
62
- id: string;
63
- name: string;
64
- } | {
65
- kind: "tool_call_args";
66
- argsDelta: string;
67
- id?: string;
68
- } | {
69
- kind: "finish";
70
- reason: string;
71
- } | {
72
- kind: "usage";
73
- promptTokens?: number;
74
- completionTokens?: number;
75
- totalTokens?: number;
76
- cachedInputTokens?: number;
77
- cacheCreationInputTokens?: number;
78
- reasoningTokens?: number;
79
- };
80
- export interface StreamChatRequest {
81
- apiKey: string;
82
- apiServerUrl?: string;
83
- modelUid: string;
84
- messages: ChatHistoryItem[];
85
- tools?: ChatToolDefinition[];
86
- cascadeId?: string;
87
- completionOpts?: CompletionOptions;
88
- signal?: AbortSignal;
89
- }
90
- /** Stream decoded chat events from the GetChatMessage Connect-RPC endpoint. */
91
- export declare function streamChatEvents(request: StreamChatRequest): AsyncGenerator<ChatEvent>;
92
- export {};