@xiaoso/dsh-tool-plus 0.1.0-beta.2 → 0.1.0-beta.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.en.md +122 -0
- package/README.md +3 -2
- package/THIRD_PARTY_NOTICES.md +4 -35
- package/lib/abort-B7izMMna.mjs +51 -0
- package/lib/amazon-bedrock-D-shAr1X.mjs +917 -0
- package/lib/anthropic-BWsZFzU8.mjs +262 -0
- package/lib/anthropic-CMT1Qj1t.mjs +3115 -0
- package/lib/api-key-login-CpzSezsi.mjs +157 -0
- package/lib/aws-credentials-8Mgn5MAy.mjs +867 -0
- package/lib/azure-openai-responses-CNkHiLUh.mjs +274 -0
- package/lib/bun-shim.mjs +172 -7
- package/lib/bundled-references-CSuBco5p.mjs +55 -0
- package/lib/callback-server-BEFNf-jf.mjs +398 -0
- package/lib/client.js +110 -40
- package/lib/cursor-BIQfBC6V.mjs +135 -0
- package/lib/cursor-DNk6eXDd.mjs +5470 -0
- package/lib/cursor-MjSm74IJ.mjs +273 -0
- package/lib/device-code-OI_tQcmc.mjs +51 -0
- package/lib/devin-CldyPD8K.mjs +95 -0
- package/lib/devin-CzRpTUOA.mjs +114 -0
- package/lib/devin-DXOeNyU7.mjs +542 -0
- package/lib/error-B3bevhrs.mjs +1449 -0
- package/lib/event-stream-BDPi64mK.mjs +151 -0
- package/lib/github-copilot-4GaMtQmg.mjs +208 -0
- package/lib/github-copilot-B2HGSIJK.mjs +104 -0
- package/lib/gitlab-duo-akICyfeD.mjs +155 -0
- package/lib/gitlab-duo-workflow-CSEgYk3N.mjs +91 -0
- package/lib/google-antigravity-Dlkdhahq.mjs +198 -0
- package/lib/google-auth-DhqpOYrX.mjs +232 -0
- package/lib/google-gemini-cli-BG_LRdIV.mjs +850 -0
- package/lib/google-gemini-cli-zJhiOcND.mjs +211 -0
- package/lib/google-oauth-shared-CwNWYdmR.mjs +147 -0
- package/lib/google-shared-DzhCb9b0.mjs +760 -0
- package/lib/google-vertex-kscbkyRb.mjs +99 -0
- package/lib/google-zyDOG9x7.mjs +30 -0
- package/lib/identity-DnB63pS7.mjs +219 -0
- package/lib/idle-iterator-C6XbWcuB.mjs +366 -0
- package/lib/index.mjs +2865 -2745
- package/lib/kimi-DMVI-zrZ.mjs +236 -0
- package/lib/markit-M0jhziqU.mjs +1417 -0
- package/lib/minimax-code-BK-3eBbz.mjs +53 -0
- package/lib/models-CfT4coYT.mjs +104660 -0
- package/lib/ollama-BQMGPxtV.mjs +589 -0
- package/lib/openai-codex-CQL_kvYL.mjs +255 -0
- package/lib/openai-codex-responses-Cz-2qpC7.mjs +3144 -0
- package/lib/openai-completions-i8doczAk.mjs +1360 -0
- package/lib/openai-reasoning-fallback-DGVVLgd1.mjs +286 -0
- package/lib/openai-responses-DTkBiiy-.mjs +867 -0
- package/lib/opencode-DaJjcUbf.mjs +38 -0
- package/lib/perplexity-9b-RQ0mV.mjs +194 -0
- package/lib/proxy-ZtUcl6r5.mjs +190 -0
- package/lib/scrapers-CL-WgdU1.mjs +9198 -0
- package/lib/scrapers-CipyKyCH.mjs +9198 -0
- package/lib/scrapers-DGfrYhtw.mjs +9198 -0
- package/lib/scrapers-DSUPYoUF.mjs +9198 -0
- package/lib/scrapers-DZ2GXmp7.mjs +9198 -0
- package/lib/src-DTid0g4K.mjs +5001 -0
- package/lib/stream-C_RAoxJC.mjs +10236 -0
- package/lib/stream-markup-healing-2toHXWXM.mjs +491 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/config/fields.d.ts +1 -1
- package/lib/types/config/settings.d.ts +16 -2
- package/lib/types/tools/omp/sdk.d.ts +6 -0
- package/lib/types/tools/omp/tools/fetch.d.ts +2 -0
- package/lib/types/tools/omp/tools/read.d.ts +2 -8
- package/lib/types/tools/omp/utils/image-loading.d.ts +10 -36
- package/lib/types/tools/read/adapter/index.d.ts +4 -1
- package/lib/types/tools/read-image/index.d.ts +4 -0
- package/lib/types/tools/shared/bun-shim.d.ts +35 -3
- package/lib/types/tools/shared/image-bridge.d.ts +98 -0
- package/lib/types/tools/shared/omp-prompt.d.ts +4 -2
- package/lib/utils-2Wq2eATG.mjs +8119 -0
- package/lib/utils-BnX8O3vi.mjs +12303 -0
- package/lib/utils-CE8N8P4Q.mjs +12315 -0
- package/lib/utils-C_MrQ_0z.mjs +12301 -0
- package/lib/utils-D0Z1fyoO.mjs +12299 -0
- package/lib/utils-DppGHXQB.mjs +51 -0
- package/lib/utils-W8WdSBpX.mjs +12315 -0
- package/lib/vision-guard-BDD4OrKo.mjs +92 -0
- package/lib/wafer-DRU0EjZX.mjs +17 -0
- package/lib/xai-oauth-DPHDXKD7.mjs +446 -0
- package/lib/xiaomi-Dd87KSg5.mjs +157 -0
- package/lib/zai-CFeOt-53.mjs +203 -0
- package/lib/zip-D6QXpvaJ.mjs +1316 -0
- package/package.json +14 -10
- package/presets/package.json +1 -1
- package/presets/tool-plus-ptc/preset.yml +1 -1
- package/presets/tool-plus-standard/preset.yml +1 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { A as semverGte, D as bareModelId, O as parseGlmModel, r as getBundledModels, y as isKimiK3ModelId } from "./models-CfT4coYT.mjs";
|
|
4
|
+
import "./identity-DnB63pS7.mjs";
|
|
5
|
+
import { r as toModelSpec } from "./bundled-references-CSuBco5p.mjs";
|
|
6
|
+
import { E as create, i as fromBinary, t as toBinary } from "./to-binary-B1BEBIPC.mjs";
|
|
7
|
+
import { H as GetUsableModelsRequestSchema, U as GetUsableModelsResponseSchema } from "./agent_pb-Rizyt9Zg.mjs";
|
|
8
|
+
import { type } from "@oh-my-pi/omptype";
|
|
9
|
+
import * as http2$1 from "node:http2";
|
|
10
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-catalog@17.3.5/node_modules/@oh-my-pi/pi-catalog/src/discovery/cursor.ts
|
|
11
|
+
const CURSOR_DEFAULT_BASE_URL = "https://api2.cursor.sh";
|
|
12
|
+
const CURSOR_DEFAULT_CLIENT_VERSION = "cli-2026.02.13-41ac335";
|
|
13
|
+
const CURSOR_GET_USABLE_MODELS_PATH = "/agent.v1.AgentService/GetUsableModels";
|
|
14
|
+
const DEFAULT_CONTEXT_WINDOW = 2e5;
|
|
15
|
+
const DEFAULT_MAX_TOKENS = 64e3;
|
|
16
|
+
/**
|
|
17
|
+
* `GetUsableModels` carries no context-window field, so the 1M ceiling is
|
|
18
|
+
* recovered from the signals Cursor does send:
|
|
19
|
+
* - display-name labels ("Opus 5 1M", "GPT-5.5 1M High") across families,
|
|
20
|
+
* - natively 1M families Cursor serves unlabeled (Kimi K3, GLM 5.2+),
|
|
21
|
+
* - the max-mode flag on Claude/Gemini ids, whose max-mode ceiling is 1M.
|
|
22
|
+
*/
|
|
23
|
+
const CURSOR_1M_CONTEXT_WINDOW = 1e6;
|
|
24
|
+
const CURSOR_1M_NAME_PATTERN = /\b1m\b/i;
|
|
25
|
+
const CURSOR_MAX_MODE_1M_ID_PATTERN = /claude|gemini/;
|
|
26
|
+
/** Kimi's official bare K3 id (`k3`, `kimi/k3`); `k3-256k` is the 256k SKU and stays out. */
|
|
27
|
+
const CURSOR_KIMI_K3_BARE_ID_PATTERN = /(^|\/)k3$/i;
|
|
28
|
+
/**
|
|
29
|
+
* Model-id families whose native catalogs (anthropic, openai/openai-codex,
|
|
30
|
+
* google) are multimodal. Cursor-only or text-only families (`composer-*`,
|
|
31
|
+
* `grok-code-*`) intentionally stay outside this pattern.
|
|
32
|
+
*/
|
|
33
|
+
const CURSOR_MULTIMODAL_ID_PATTERN = /claude|gemini|gpt-|codex/;
|
|
34
|
+
const OptionalDisplayNameSchema = type("unknown").pipe((raw) => typeof raw === "string" ? raw : void 0);
|
|
35
|
+
const CursorAliasesSchema = type("unknown").pipe((raw) => {
|
|
36
|
+
if (Array.isArray(raw)) return raw.filter((alias) => typeof alias === "string");
|
|
37
|
+
return [];
|
|
38
|
+
});
|
|
39
|
+
const CursorModelDetailsSchema = type({
|
|
40
|
+
modelId: "string",
|
|
41
|
+
displayName: OptionalDisplayNameSchema.default(void 0),
|
|
42
|
+
displayNameShort: OptionalDisplayNameSchema.default(void 0),
|
|
43
|
+
displayModelId: OptionalDisplayNameSchema.default(void 0),
|
|
44
|
+
aliases: CursorAliasesSchema.default(() => []),
|
|
45
|
+
"thinkingDetails?": "unknown",
|
|
46
|
+
maxMode: "boolean = false"
|
|
47
|
+
});
|
|
48
|
+
const CursorModelsInnerSchema = type("unknown[]");
|
|
49
|
+
const ResilientCursorModelsSchema = type("unknown").pipe((raw) => {
|
|
50
|
+
const out = CursorModelsInnerSchema(raw);
|
|
51
|
+
return out instanceof type.errors ? [] : out;
|
|
52
|
+
});
|
|
53
|
+
const CursorDecodedResponseSchema = type({ models: ResilientCursorModelsSchema.default(() => []) });
|
|
54
|
+
/**
|
|
55
|
+
* Fetches Cursor models through `GetUsableModels` and normalizes them into canonical model entries.
|
|
56
|
+
*
|
|
57
|
+
* Returns `null` on request/decode failures.
|
|
58
|
+
* Returns `[]` only when the endpoint responds successfully with no usable models.
|
|
59
|
+
*/
|
|
60
|
+
async function fetchCursorUsableModels(options) {
|
|
61
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
62
|
+
try {
|
|
63
|
+
const requestPayload = create(GetUsableModelsRequestSchema, { customModelIds: normalizeCustomModelIds(options.customModelIds) });
|
|
64
|
+
const body = toBinary(GetUsableModelsRequestSchema, requestPayload);
|
|
65
|
+
const responseBuffer = await fetchViaHttp2((options.baseUrl ?? CURSOR_DEFAULT_BASE_URL).replace(/\/+$/, ""), body, options, timeoutMs);
|
|
66
|
+
if (!responseBuffer) return null;
|
|
67
|
+
const decoded = decodeGetUsableModelsResponse(responseBuffer);
|
|
68
|
+
const parsedDecoded = CursorDecodedResponseSchema(decoded);
|
|
69
|
+
if (parsedDecoded instanceof type.errors) return null;
|
|
70
|
+
const references = createCursorReferenceMap();
|
|
71
|
+
return normalizeCursorModels(parsedDecoded.models, options.baseUrl, references);
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function buildRequestHeaders(options) {
|
|
77
|
+
return {
|
|
78
|
+
"content-type": "application/proto",
|
|
79
|
+
te: "trailers",
|
|
80
|
+
authorization: `Bearer ${options.apiKey}`,
|
|
81
|
+
"x-ghost-mode": "true",
|
|
82
|
+
"x-cursor-client-version": options.clientVersion ?? CURSOR_DEFAULT_CLIENT_VERSION,
|
|
83
|
+
"x-cursor-client-type": "cli"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** HTTP/2 transport required by Cursor API (HTTP/1.1 is rejected with 464). */
|
|
87
|
+
async function fetchViaHttp2(baseUrl, body, options, timeoutMs) {
|
|
88
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
89
|
+
const client = http2$1.connect(baseUrl);
|
|
90
|
+
const timer = setTimeout(() => {
|
|
91
|
+
client.destroy();
|
|
92
|
+
resolve(null);
|
|
93
|
+
}, timeoutMs);
|
|
94
|
+
client.on("error", () => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
resolve(null);
|
|
97
|
+
});
|
|
98
|
+
const req = client.request({
|
|
99
|
+
":method": "POST",
|
|
100
|
+
":path": CURSOR_GET_USABLE_MODELS_PATH,
|
|
101
|
+
...buildRequestHeaders(options)
|
|
102
|
+
});
|
|
103
|
+
const chunks = [];
|
|
104
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
105
|
+
req.on("end", () => {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
client.close();
|
|
108
|
+
resolve(new Uint8Array(Buffer.concat(chunks)));
|
|
109
|
+
});
|
|
110
|
+
req.on("error", () => {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
client.close();
|
|
113
|
+
resolve(null);
|
|
114
|
+
});
|
|
115
|
+
req.on("response", (headers) => {
|
|
116
|
+
const status = Number(headers[":status"] ?? 0);
|
|
117
|
+
if (status < 200 || status >= 300) {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
client.close();
|
|
120
|
+
resolve(null);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (body.length > 0) req.end(Buffer.from(body));
|
|
124
|
+
else req.end();
|
|
125
|
+
return promise;
|
|
126
|
+
}
|
|
127
|
+
function normalizeCustomModelIds(customModelIds) {
|
|
128
|
+
if (!customModelIds) return [];
|
|
129
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
130
|
+
for (const value of customModelIds) {
|
|
131
|
+
if (typeof value !== "string") continue;
|
|
132
|
+
const trimmed = value.trim();
|
|
133
|
+
if (!trimmed) continue;
|
|
134
|
+
normalized.add(trimmed);
|
|
135
|
+
}
|
|
136
|
+
return [...normalized];
|
|
137
|
+
}
|
|
138
|
+
function createCursorReferenceMap() {
|
|
139
|
+
const references = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const model of getBundledModels("cursor")) references.set(model.id, toModelSpec(model));
|
|
141
|
+
return references;
|
|
142
|
+
}
|
|
143
|
+
function decodeGetUsableModelsResponse(payload) {
|
|
144
|
+
if (payload.length === 0) return null;
|
|
145
|
+
const framedBody = decodeConnectUnaryBody(payload);
|
|
146
|
+
if (framedBody) try {
|
|
147
|
+
return fromBinary(GetUsableModelsResponseSchema, framedBody);
|
|
148
|
+
} catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
return fromBinary(GetUsableModelsResponseSchema, payload);
|
|
153
|
+
} catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function decodeConnectUnaryBody(payload) {
|
|
158
|
+
if (payload.length < 5) return null;
|
|
159
|
+
let offset = 0;
|
|
160
|
+
while (offset + 5 <= payload.length) {
|
|
161
|
+
const flags = payload[offset];
|
|
162
|
+
const messageLength = new DataView(payload.buffer, payload.byteOffset + offset, payload.byteLength - offset).getUint32(1, false);
|
|
163
|
+
const frameEnd = offset + 5 + messageLength;
|
|
164
|
+
if (frameEnd > payload.length) return null;
|
|
165
|
+
if ((flags & 1) !== 0) return null;
|
|
166
|
+
if (!((flags & 2) !== 0)) return payload.subarray(offset + 5, frameEnd);
|
|
167
|
+
offset = frameEnd;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
function normalizeCursorModels(models, baseUrlOverride, references) {
|
|
172
|
+
if (!models || models.length === 0) return [];
|
|
173
|
+
const byId = /* @__PURE__ */ new Map();
|
|
174
|
+
for (const model of models) {
|
|
175
|
+
const normalized = normalizeCursorModel(model, baseUrlOverride, references);
|
|
176
|
+
if (!normalized) continue;
|
|
177
|
+
byId.set(normalized.id, normalized);
|
|
178
|
+
}
|
|
179
|
+
return [...byId.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
180
|
+
}
|
|
181
|
+
function normalizeCursorModel(model, baseUrlOverride, references) {
|
|
182
|
+
const parsedModel = CursorModelDetailsSchema(model);
|
|
183
|
+
if (parsedModel instanceof type.errors) return null;
|
|
184
|
+
const details = parsedModel;
|
|
185
|
+
const id = details.modelId.trim();
|
|
186
|
+
if (!id) return null;
|
|
187
|
+
const name = pickModelDisplayName(details, id);
|
|
188
|
+
const reference = references.get(id);
|
|
189
|
+
const reasoning = isKimiK3ModelId(id) || Boolean(details.thinkingDetails) || reference?.reasoning === true;
|
|
190
|
+
if (reference) return {
|
|
191
|
+
...reference,
|
|
192
|
+
id,
|
|
193
|
+
name,
|
|
194
|
+
baseUrl: baseUrlOverride ?? reference.baseUrl,
|
|
195
|
+
reasoning,
|
|
196
|
+
contextWindow: resolveCursorContextWindow(details, id, reference.contextWindow),
|
|
197
|
+
cursorMaxMode: details.maxMode
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
id,
|
|
201
|
+
name,
|
|
202
|
+
api: "cursor-agent",
|
|
203
|
+
provider: "cursor",
|
|
204
|
+
baseUrl: baseUrlOverride ?? CURSOR_DEFAULT_BASE_URL,
|
|
205
|
+
reasoning,
|
|
206
|
+
input: inferInputFromCursorId(id),
|
|
207
|
+
cost: {
|
|
208
|
+
input: 0,
|
|
209
|
+
output: 0,
|
|
210
|
+
cacheRead: 0,
|
|
211
|
+
cacheWrite: 0
|
|
212
|
+
},
|
|
213
|
+
contextWindow: resolveCursorContextWindow(details, id, DEFAULT_CONTEXT_WINDOW),
|
|
214
|
+
maxTokens: DEFAULT_MAX_TOKENS,
|
|
215
|
+
cursorMaxMode: details.maxMode
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Context window for a discovered Cursor model: the 1M ceiling when any 1M
|
|
220
|
+
* signal fires (never below a larger bundled reference), else the fallback.
|
|
221
|
+
*/
|
|
222
|
+
function resolveCursorContextWindow(model, id, fallback) {
|
|
223
|
+
if (CURSOR_1M_NAME_PATTERN.test(id) || [
|
|
224
|
+
model.displayName,
|
|
225
|
+
model.displayNameShort,
|
|
226
|
+
model.displayModelId,
|
|
227
|
+
...model.aliases
|
|
228
|
+
].some((candidate) => typeof candidate === "string" && CURSOR_1M_NAME_PATTERN.test(candidate)) || isCursorNative1MModelId(id) || model.maxMode && CURSOR_MAX_MODE_1M_ID_PATTERN.test(id)) return Math.max(fallback ?? 0, CURSOR_1M_CONTEXT_WINDOW);
|
|
229
|
+
return fallback;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Natively 1M-context families Cursor serves without a "1M" label: Kimi K3 and
|
|
233
|
+
* GLM 5.2+ coding SKUs. The shared family parsers cover namespace forms
|
|
234
|
+
* (`moonshotai/kimi-k3`, `z-ai/glm-5.2`) and future GLM versions (`glm-5.10`,
|
|
235
|
+
* `glm-6`); vision and sub-1M variants stay out via the same gates as
|
|
236
|
+
* `isGlm52ReasoningEffortModelId`.
|
|
237
|
+
*/
|
|
238
|
+
function isCursorNative1MModelId(id) {
|
|
239
|
+
if (isKimiK3ModelId(id) || CURSOR_KIMI_K3_BARE_ID_PATTERN.test(id)) return true;
|
|
240
|
+
const glm = parseGlmModel(bareModelId(id));
|
|
241
|
+
if (!glm || glm.vision) return false;
|
|
242
|
+
if (glm.variant !== "base" && glm.variant !== "air" && glm.variant !== "turbo") return false;
|
|
243
|
+
return semverGte(glm.version, "5.2");
|
|
244
|
+
}
|
|
245
|
+
function pickModelDisplayName(model, fallbackId) {
|
|
246
|
+
const candidates = [
|
|
247
|
+
model.displayName,
|
|
248
|
+
model.displayNameShort,
|
|
249
|
+
model.displayModelId,
|
|
250
|
+
...model.aliases,
|
|
251
|
+
fallbackId
|
|
252
|
+
];
|
|
253
|
+
for (const candidate of candidates) {
|
|
254
|
+
if (typeof candidate !== "string") continue;
|
|
255
|
+
const trimmed = candidate.trim();
|
|
256
|
+
if (trimmed) return trimmed;
|
|
257
|
+
}
|
|
258
|
+
return fallbackId;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Infers input modalities for Cursor models without a bundled reference.
|
|
262
|
+
*
|
|
263
|
+
* `GetUsableModels` carries no per-model modality metadata, so classification
|
|
264
|
+
* falls back to the model family: families that are multimodal in OMP's own
|
|
265
|
+
* native catalogs accept images, everything else stays text-only. Mirrors
|
|
266
|
+
* `inferInputFromGeminiId` in ./gemini.ts.
|
|
267
|
+
*/
|
|
268
|
+
function inferInputFromCursorId(id) {
|
|
269
|
+
if (CURSOR_MULTIMODAL_ID_PATTERN.test(id.toLowerCase())) return ["text", "image"];
|
|
270
|
+
return ["text"];
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
export { fetchCursorUsableModels };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { c as OAuthError, h as LoginCancelledError } from "./error-B3bevhrs.mjs";
|
|
4
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/device-code.ts
|
|
5
|
+
const DEVICE_FLOW_CANCEL_MESSAGE = "Login cancelled";
|
|
6
|
+
const DEVICE_FLOW_TIMEOUT_MESSAGE = "Device flow timed out";
|
|
7
|
+
const DEVICE_FLOW_SLOW_DOWN_TIMEOUT_MESSAGE = "Device flow timed out after one or more slow_down responses. This is often caused by clock drift in WSL or VM environments. Please sync or restart the VM clock and try again.";
|
|
8
|
+
const MINIMUM_DEVICE_FLOW_INTERVAL_MS = 1e3;
|
|
9
|
+
const DEFAULT_DEVICE_FLOW_INTERVAL_SECONDS = 5;
|
|
10
|
+
const SLOW_DOWN_INTERVAL_INCREMENT_MS = 5e3;
|
|
11
|
+
async function abortableDeviceFlowSleep(ms, signal) {
|
|
12
|
+
if (!signal) {
|
|
13
|
+
await Bun.sleep(ms);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (signal.aborted) throw new LoginCancelledError(DEVICE_FLOW_CANCEL_MESSAGE);
|
|
17
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
18
|
+
let timer;
|
|
19
|
+
const onAbort = () => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
reject(new LoginCancelledError(DEVICE_FLOW_CANCEL_MESSAGE));
|
|
22
|
+
};
|
|
23
|
+
timer = setTimeout(() => {
|
|
24
|
+
signal.removeEventListener("abort", onAbort);
|
|
25
|
+
resolve();
|
|
26
|
+
}, ms);
|
|
27
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
28
|
+
await promise;
|
|
29
|
+
}
|
|
30
|
+
/** Poll an OAuth device-code flow until completion, provider failure, timeout, or cancellation. */
|
|
31
|
+
async function pollOAuthDeviceCodeFlow(options) {
|
|
32
|
+
const deadline = typeof options.expiresInSeconds === "number" ? Date.now() + options.expiresInSeconds * 1e3 : Number.POSITIVE_INFINITY;
|
|
33
|
+
let intervalMs = Math.max(MINIMUM_DEVICE_FLOW_INTERVAL_MS, Math.floor((options.intervalSeconds ?? DEFAULT_DEVICE_FLOW_INTERVAL_SECONDS) * 1e3));
|
|
34
|
+
let slowDownResponses = 0;
|
|
35
|
+
while (Date.now() < deadline) {
|
|
36
|
+
if (options.signal?.aborted) throw new LoginCancelledError(DEVICE_FLOW_CANCEL_MESSAGE);
|
|
37
|
+
const result = await options.poll();
|
|
38
|
+
if (result.status === "complete") return result.value;
|
|
39
|
+
if (result.status === "failed") throw new OAuthError(result.message, { kind: "polling" });
|
|
40
|
+
if (result.status === "slow_down") {
|
|
41
|
+
slowDownResponses += 1;
|
|
42
|
+
intervalMs = Math.max(MINIMUM_DEVICE_FLOW_INTERVAL_MS, intervalMs + SLOW_DOWN_INTERVAL_INCREMENT_MS);
|
|
43
|
+
}
|
|
44
|
+
const remainingMs = deadline - Date.now();
|
|
45
|
+
if (remainingMs <= 0) break;
|
|
46
|
+
await abortableDeviceFlowSleep(Math.min(intervalMs, remainingMs), options.signal);
|
|
47
|
+
}
|
|
48
|
+
throw new OAuthError(slowDownResponses > 0 ? DEVICE_FLOW_SLOW_DOWN_TIMEOUT_MESSAGE : DEVICE_FLOW_TIMEOUT_MESSAGE, { kind: "timeout" });
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { pollOAuthDeviceCodeFlow as t };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { c as OAuthError } from "./error-B3bevhrs.mjs";
|
|
4
|
+
import { t as OAuthCallbackFlow } from "./callback-server-BEFNf-jf.mjs";
|
|
5
|
+
import { t as generatePKCE } from "./pkce-BlQikGPu.mjs";
|
|
6
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/devin.ts
|
|
7
|
+
const DEVIN_WEBAPP_URL = "https://app.devin.ai";
|
|
8
|
+
const DEVIN_API_URL = "https://api.devin.ai";
|
|
9
|
+
const CALLBACK_PORT = 59653;
|
|
10
|
+
const CALLBACK_PATH = "/callback";
|
|
11
|
+
const TOKEN_PATH = "/auth/cli/token";
|
|
12
|
+
const FALLBACK_EXPIRES_MS = 31536e6;
|
|
13
|
+
async function loginDevin(ctrl) {
|
|
14
|
+
return new DevinOAuthFlow(ctrl).login();
|
|
15
|
+
}
|
|
16
|
+
var DevinOAuthFlow = class extends OAuthCallbackFlow {
|
|
17
|
+
#pkce;
|
|
18
|
+
constructor(ctrl) {
|
|
19
|
+
super(ctrl, {
|
|
20
|
+
preferredPort: CALLBACK_PORT,
|
|
21
|
+
callbackPath: CALLBACK_PATH,
|
|
22
|
+
callbackHostname: "127.0.0.1"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
generateState() {
|
|
26
|
+
return crypto.randomUUID();
|
|
27
|
+
}
|
|
28
|
+
async generateAuthUrl(state, redirectUri) {
|
|
29
|
+
this.#pkce = await generatePKCE();
|
|
30
|
+
const params = new URLSearchParams({
|
|
31
|
+
redirect_uri: redirectUri,
|
|
32
|
+
state,
|
|
33
|
+
prompt: "select_account",
|
|
34
|
+
code_challenge: this.#pkce.challenge,
|
|
35
|
+
code_challenge_method: "S256"
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
url: `${DEVIN_WEBAPP_URL}/auth/cli/continue?${params.toString()}`,
|
|
39
|
+
instructions: "Sign in to Devin in your browser."
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async exchangeToken(code) {
|
|
43
|
+
if (!this.#pkce) throw new OAuthError("Devin PKCE verifier was not initialized", {
|
|
44
|
+
kind: "configuration",
|
|
45
|
+
provider: "devin"
|
|
46
|
+
});
|
|
47
|
+
const token = await exchangeDevinCliToken(code, this.#pkce.verifier, this.ctrl.fetch);
|
|
48
|
+
return {
|
|
49
|
+
access: token,
|
|
50
|
+
refresh: token,
|
|
51
|
+
expires: getTokenExpiry(token),
|
|
52
|
+
apiEndpoint: DEVIN_API_URL,
|
|
53
|
+
enterpriseUrl: DEVIN_WEBAPP_URL
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
async function exchangeDevinCliToken(authorizationCode, codeVerifier, fetchImpl = fetch) {
|
|
58
|
+
const response = await fetchImpl(`${DEVIN_API_URL}${TOKEN_PATH}`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
Accept: "application/json",
|
|
62
|
+
"Content-Type": "application/json"
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
code: authorizationCode,
|
|
66
|
+
code_verifier: codeVerifier
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
const error = await response.text();
|
|
71
|
+
throw new OAuthError(`Devin CLI token exchange failed: ${response.status} ${error}`.trim(), {
|
|
72
|
+
kind: "token-exchange",
|
|
73
|
+
provider: "devin",
|
|
74
|
+
status: response.status
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const data = await response.json();
|
|
78
|
+
if (typeof data.token !== "string" || data.token.length === 0) throw new OAuthError("Devin CLI token exchange returned an empty token", {
|
|
79
|
+
kind: "validation",
|
|
80
|
+
provider: "devin"
|
|
81
|
+
});
|
|
82
|
+
return data.token;
|
|
83
|
+
}
|
|
84
|
+
function getTokenExpiry(token) {
|
|
85
|
+
try {
|
|
86
|
+
const [, payload] = token.split(".");
|
|
87
|
+
if (payload) {
|
|
88
|
+
const decoded = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
89
|
+
if (typeof decoded.exp === "number" && Number.isFinite(decoded.exp)) return decoded.exp * 1e3 - 3e5;
|
|
90
|
+
}
|
|
91
|
+
} catch {}
|
|
92
|
+
return Date.now() + FALLBACK_EXPIRES_MS;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { loginDevin };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { n as discoveryFetch } from "./utils-DppGHXQB.mjs";
|
|
4
|
+
import { E as create, i as fromBinary, t as toBinary } from "./to-binary-B1BEBIPC.mjs";
|
|
5
|
+
import { f as MetadataSchema, i as GetCliModelConfigsResponseSchema, r as GetCliModelConfigsRequestSchema } from "./api_server_pb-CDZgLMta.mjs";
|
|
6
|
+
import { gunzipSync } from "node:zlib";
|
|
7
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-catalog@17.3.5/node_modules/@oh-my-pi/pi-catalog/src/discovery/devin.ts
|
|
8
|
+
const DEVIN_DEFAULT_BASE_URL = "https://server.codeium.com";
|
|
9
|
+
const DEVIN_GET_CLI_MODEL_CONFIGS_PATH = "/exa.api_server_pb.ApiServerService/GetCliModelConfigs";
|
|
10
|
+
const DEVIN_IDE_VERSION = "3.2.23";
|
|
11
|
+
const DEVIN_EXTENSION_VERSION = "1.48.2";
|
|
12
|
+
const DEVIN_SESSION_TOKEN_PREFIX = "devin-session-token$";
|
|
13
|
+
const DEFAULT_CONTEXT_WINDOW = 2e5;
|
|
14
|
+
const DEFAULT_MAX_TOKENS = 64e3;
|
|
15
|
+
/** Best-effort match for labels whose wording implies a thinking / reasoning-effort variant. */
|
|
16
|
+
const REASONING_LABEL_PATTERN = /think|thinking|minimal|high|medium|low|xhigh|max|reasoning/i;
|
|
17
|
+
const NO_REASONING_LABEL_PATTERN = /\bno thinking\b/i;
|
|
18
|
+
function supportsDevinThinking(config) {
|
|
19
|
+
if (NO_REASONING_LABEL_PATTERN.test(config.label)) return false;
|
|
20
|
+
return config.modelInfo?.modelFeatures?.supportsThinking === true || REASONING_LABEL_PATTERN.test(config.label);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fetches Devin models through the `GetCliModelConfigs` unary Connect RPC and
|
|
24
|
+
* normalizes them into canonical model entries.
|
|
25
|
+
*
|
|
26
|
+
* Returns `null` on request/decode failures.
|
|
27
|
+
* Returns `[]` only when the endpoint responds successfully with no usable models.
|
|
28
|
+
*/
|
|
29
|
+
async function fetchDevinModels(options) {
|
|
30
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
31
|
+
const requestUrl = `${(options.baseUrl ?? DEVIN_DEFAULT_BASE_URL).replace(/\/+$/, "")}${DEVIN_GET_CLI_MODEL_CONFIGS_PATH}`;
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
34
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
35
|
+
try {
|
|
36
|
+
const request = create(GetCliModelConfigsRequestSchema, { metadata: create(MetadataSchema, {
|
|
37
|
+
apiKey: normalizeDevinSessionToken(options.apiKey),
|
|
38
|
+
ideName: "windsurf",
|
|
39
|
+
ideVersion: DEVIN_IDE_VERSION,
|
|
40
|
+
extensionName: "windsurf",
|
|
41
|
+
extensionVersion: DEVIN_EXTENSION_VERSION
|
|
42
|
+
}) });
|
|
43
|
+
const body = toBinary(GetCliModelConfigsRequestSchema, request);
|
|
44
|
+
const response = await discoveryFetch(options.fetch)(requestUrl, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"content-type": "application/proto",
|
|
48
|
+
"connect-protocol-version": "1",
|
|
49
|
+
accept: "*/*"
|
|
50
|
+
},
|
|
51
|
+
body,
|
|
52
|
+
signal
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) return null;
|
|
55
|
+
const decoded = decodeCliModelConfigsResponse(new Uint8Array(await response.arrayBuffer()));
|
|
56
|
+
if (!decoded) return null;
|
|
57
|
+
return normalizeDevinModels(decoded.clientModelConfigs, options.baseUrl);
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
} finally {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function normalizeDevinSessionToken(apiKey) {
|
|
65
|
+
if (!apiKey) return "";
|
|
66
|
+
return apiKey.startsWith(DEVIN_SESSION_TOKEN_PREFIX) ? apiKey : `${DEVIN_SESSION_TOKEN_PREFIX}${apiKey}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Decodes a raw (unframed) `GetCliModelConfigsResponse`. Bun's `fetch` usually
|
|
70
|
+
* auto-decompresses gzip, so the direct decode is attempted first; a
|
|
71
|
+
* `gunzipSync` fallback covers runtimes that hand back the still-compressed body.
|
|
72
|
+
*/
|
|
73
|
+
function decodeCliModelConfigsResponse(payload) {
|
|
74
|
+
try {
|
|
75
|
+
return fromBinary(GetCliModelConfigsResponseSchema, payload);
|
|
76
|
+
} catch {
|
|
77
|
+
try {
|
|
78
|
+
return fromBinary(GetCliModelConfigsResponseSchema, gunzipSync(payload));
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function normalizeDevinModels(configs, baseUrlOverride) {
|
|
85
|
+
const byId = /* @__PURE__ */ new Map();
|
|
86
|
+
for (const config of configs) {
|
|
87
|
+
if (config.disabled) continue;
|
|
88
|
+
const id = config.modelUid.trim();
|
|
89
|
+
if (!id) continue;
|
|
90
|
+
const input = config.supportsImages ? ["text", "image"] : ["text"];
|
|
91
|
+
const contextWindow = config.maxTokens > 0 ? config.maxTokens : DEFAULT_CONTEXT_WINDOW;
|
|
92
|
+
byId.set(id, {
|
|
93
|
+
id,
|
|
94
|
+
name: config.label.trim() || id,
|
|
95
|
+
api: "devin-agent",
|
|
96
|
+
provider: "devin",
|
|
97
|
+
baseUrl: baseUrlOverride ?? DEVIN_DEFAULT_BASE_URL,
|
|
98
|
+
reasoning: supportsDevinThinking(config),
|
|
99
|
+
input,
|
|
100
|
+
supportsTools: true,
|
|
101
|
+
cost: {
|
|
102
|
+
input: 0,
|
|
103
|
+
output: 0,
|
|
104
|
+
cacheRead: 0,
|
|
105
|
+
cacheWrite: 0
|
|
106
|
+
},
|
|
107
|
+
contextWindow,
|
|
108
|
+
maxTokens: Math.min(config.maxTokens > 0 ? config.maxTokens : DEFAULT_MAX_TOKENS, DEFAULT_MAX_TOKENS)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return [...byId.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { fetchDevinModels };
|