@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,236 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { r as __exportAll } from "./fs-promises-shim-B-9cMxz5.mjs";
|
|
4
|
+
import { H as getAgentDir, P as $env } from "./src-DTid0g4K.mjs";
|
|
5
|
+
import { c as OAuthError, h as LoginCancelledError } from "./error-B3bevhrs.mjs";
|
|
6
|
+
import "./utils-2Wq2eATG.mjs";
|
|
7
|
+
import { n as isRecord } from "./type-guards-B9VVjRDK.mjs";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import { scheduler } from "node:timers/promises";
|
|
12
|
+
import * as crypto from "node:crypto";
|
|
13
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/package.json
|
|
14
|
+
var version = "17.3.5";
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/kimi.ts
|
|
17
|
+
/**
|
|
18
|
+
* Kimi Code OAuth flow (device authorization grant)
|
|
19
|
+
*/
|
|
20
|
+
var kimi_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
getKimiCommonHeaders: () => getKimiCommonHeaders,
|
|
22
|
+
loginKimi: () => loginKimi,
|
|
23
|
+
refreshKimiToken: () => refreshKimiToken
|
|
24
|
+
});
|
|
25
|
+
const CLIENT_ID = "17e5f671-d194-4dfb-9706-5516cb48c098";
|
|
26
|
+
const DEFAULT_OAUTH_HOST = "https://auth.kimi.com";
|
|
27
|
+
const DEVICE_ID_FILENAME = "kimi-device-id";
|
|
28
|
+
const DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
29
|
+
const DEFAULT_DEVICE_FLOW_TTL_MS = 9e5;
|
|
30
|
+
const OAUTH_EXPIRY_SKEW_MS = 3e5;
|
|
31
|
+
function resolveOAuthHost() {
|
|
32
|
+
return $env.KIMI_CODE_OAUTH_HOST || $env.KIMI_OAUTH_HOST || DEFAULT_OAUTH_HOST;
|
|
33
|
+
}
|
|
34
|
+
function formatDeviceModel(system, release, arch) {
|
|
35
|
+
return [
|
|
36
|
+
system,
|
|
37
|
+
release,
|
|
38
|
+
arch
|
|
39
|
+
].filter(Boolean).join(" ").trim();
|
|
40
|
+
}
|
|
41
|
+
function getDeviceModel() {
|
|
42
|
+
const platform = os.platform();
|
|
43
|
+
const release = os.release();
|
|
44
|
+
const arch = os.arch();
|
|
45
|
+
if (platform === "darwin") return formatDeviceModel("macOS", release, arch);
|
|
46
|
+
if (platform === "win32") return formatDeviceModel("Windows", release, arch);
|
|
47
|
+
return formatDeviceModel(platform === "linux" ? "Linux" : platform, release, arch);
|
|
48
|
+
}
|
|
49
|
+
let getDeviceId = () => {
|
|
50
|
+
const deviceIdPath = path.join(getAgentDir(), DEVICE_ID_FILENAME);
|
|
51
|
+
try {
|
|
52
|
+
const existing = fs.readFileSync(deviceIdPath, "utf-8").trim();
|
|
53
|
+
if (existing) {
|
|
54
|
+
getDeviceId = () => existing;
|
|
55
|
+
return existing;
|
|
56
|
+
}
|
|
57
|
+
} catch {}
|
|
58
|
+
const deviceId = crypto.randomUUID().replace(/-/g, "");
|
|
59
|
+
try {
|
|
60
|
+
fs.mkdirSync(path.dirname(deviceIdPath), { recursive: true });
|
|
61
|
+
fs.writeFileSync(deviceIdPath, `${deviceId}\n`, { mode: 384 });
|
|
62
|
+
} catch {}
|
|
63
|
+
getDeviceId = () => deviceId;
|
|
64
|
+
return deviceId;
|
|
65
|
+
};
|
|
66
|
+
function sanitizeHeaderValue(value, fallback = "") {
|
|
67
|
+
return value.replace(/[^\x20-\x7E]/g, "").trim() || fallback;
|
|
68
|
+
}
|
|
69
|
+
let getKimiCommonHeaders = () => {
|
|
70
|
+
const headers = Object.freeze({
|
|
71
|
+
"User-Agent": `KimiCLI/${version}`,
|
|
72
|
+
"X-Msh-Platform": "kimi_cli",
|
|
73
|
+
"X-Msh-Version": version,
|
|
74
|
+
"X-Msh-Device-Name": sanitizeHeaderValue(os.hostname(), "unknown"),
|
|
75
|
+
"X-Msh-Device-Model": sanitizeHeaderValue(getDeviceModel(), "unknown"),
|
|
76
|
+
"X-Msh-Os-Version": sanitizeHeaderValue(os.version(), "unknown"),
|
|
77
|
+
"X-Msh-Device-Id": sanitizeHeaderValue(getDeviceId(), "unknown")
|
|
78
|
+
});
|
|
79
|
+
getKimiCommonHeaders = () => headers;
|
|
80
|
+
return headers;
|
|
81
|
+
};
|
|
82
|
+
async function requestDeviceAuthorization() {
|
|
83
|
+
const response = await fetch(`${resolveOAuthHost()}/api/oauth/device_authorization`, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
87
|
+
...getKimiCommonHeaders()
|
|
88
|
+
},
|
|
89
|
+
body: new URLSearchParams({ client_id: CLIENT_ID })
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
const text = await response.text();
|
|
93
|
+
throw new OAuthError(`Kimi device authorization failed: ${response.status} ${text}`, {
|
|
94
|
+
kind: "device-auth",
|
|
95
|
+
provider: "kimi",
|
|
96
|
+
status: response.status
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const payload = await response.json();
|
|
100
|
+
const userCode = payload.user_code;
|
|
101
|
+
const deviceCode = payload.device_code;
|
|
102
|
+
const verificationUri = payload.verification_uri;
|
|
103
|
+
const verificationUriComplete = payload.verification_uri_complete;
|
|
104
|
+
if (!userCode || !deviceCode || !verificationUri) throw new OAuthError("Kimi device authorization response missing required fields", {
|
|
105
|
+
kind: "validation",
|
|
106
|
+
provider: "kimi"
|
|
107
|
+
});
|
|
108
|
+
const expiresInMs = typeof payload.expires_in === "number" ? payload.expires_in * 1e3 : DEFAULT_DEVICE_FLOW_TTL_MS;
|
|
109
|
+
const intervalMs = typeof payload.interval === "number" && payload.interval > 0 ? payload.interval * 1e3 : DEFAULT_POLL_INTERVAL_MS;
|
|
110
|
+
return {
|
|
111
|
+
userCode,
|
|
112
|
+
deviceCode,
|
|
113
|
+
verificationUri,
|
|
114
|
+
verificationUriComplete: verificationUriComplete || verificationUri,
|
|
115
|
+
expiresInMs,
|
|
116
|
+
intervalMs
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function parseTokenPayload(payload, refreshTokenFallback) {
|
|
120
|
+
if (!payload.access_token || typeof payload.expires_in !== "number") throw new OAuthError("Kimi token response missing required fields", {
|
|
121
|
+
kind: "validation",
|
|
122
|
+
provider: "kimi"
|
|
123
|
+
});
|
|
124
|
+
const refresh = payload.refresh_token ?? refreshTokenFallback;
|
|
125
|
+
if (!refresh) throw new OAuthError("Kimi token response missing refresh token", {
|
|
126
|
+
kind: "validation",
|
|
127
|
+
provider: "kimi"
|
|
128
|
+
});
|
|
129
|
+
let accountId;
|
|
130
|
+
const tokenParts = payload.access_token.split(".");
|
|
131
|
+
const jwtPayloadPart = tokenParts.length === 3 ? tokenParts[1] : void 0;
|
|
132
|
+
if (jwtPayloadPart) try {
|
|
133
|
+
const jwtPayload = JSON.parse(new TextDecoder("utf-8").decode(Uint8Array.fromBase64(jwtPayloadPart, { alphabet: "base64url" })));
|
|
134
|
+
if (isRecord(jwtPayload)) {
|
|
135
|
+
const userId = typeof jwtPayload.user_id === "string" ? jwtPayload.user_id.trim() : "";
|
|
136
|
+
const subject = typeof jwtPayload.sub === "string" ? jwtPayload.sub.trim() : "";
|
|
137
|
+
accountId = userId || subject || void 0;
|
|
138
|
+
}
|
|
139
|
+
} catch {}
|
|
140
|
+
return {
|
|
141
|
+
access: payload.access_token,
|
|
142
|
+
refresh,
|
|
143
|
+
expires: Date.now() + payload.expires_in * 1e3 - OAUTH_EXPIRY_SKEW_MS,
|
|
144
|
+
accountId
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
async function pollForToken(deviceCode, intervalMs, expiresInMs, signal) {
|
|
148
|
+
const deadline = Date.now() + expiresInMs;
|
|
149
|
+
let waitMs = Math.max(1e3, intervalMs);
|
|
150
|
+
while (Date.now() < deadline) {
|
|
151
|
+
if (signal?.aborted) throw new LoginCancelledError();
|
|
152
|
+
const response = await fetch(`${resolveOAuthHost()}/api/oauth/token`, {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: {
|
|
155
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
156
|
+
...getKimiCommonHeaders()
|
|
157
|
+
},
|
|
158
|
+
body: new URLSearchParams({
|
|
159
|
+
client_id: CLIENT_ID,
|
|
160
|
+
device_code: deviceCode,
|
|
161
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code"
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
const payload = await response.json();
|
|
165
|
+
if (response.ok && payload.access_token) return parseTokenPayload(payload);
|
|
166
|
+
const error = payload.error;
|
|
167
|
+
if (error === "authorization_pending") {
|
|
168
|
+
await scheduler.wait(waitMs, { signal });
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (error === "slow_down") {
|
|
172
|
+
waitMs += 5e3;
|
|
173
|
+
const retryAfter = typeof payload.interval === "number" ? payload.interval * 1e3 : void 0;
|
|
174
|
+
if (retryAfter && retryAfter > waitMs) waitMs = retryAfter;
|
|
175
|
+
await scheduler.wait(waitMs, { signal });
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (error === "expired_token") throw new OAuthError("Kimi device authorization expired", {
|
|
179
|
+
kind: "validation",
|
|
180
|
+
provider: "kimi"
|
|
181
|
+
});
|
|
182
|
+
if (error === "access_denied") throw new OAuthError("Kimi device authorization denied", {
|
|
183
|
+
kind: "validation",
|
|
184
|
+
provider: "kimi"
|
|
185
|
+
});
|
|
186
|
+
const description = payload.error_description ? `: ${payload.error_description}` : "";
|
|
187
|
+
throw new OAuthError(`Kimi device flow failed: ${error ?? response.status}${description}`, {
|
|
188
|
+
kind: "polling",
|
|
189
|
+
provider: "kimi"
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
throw new OAuthError("Kimi device flow timed out", {
|
|
193
|
+
kind: "timeout",
|
|
194
|
+
provider: "kimi"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Login with Kimi Code OAuth (device code flow).
|
|
199
|
+
*/
|
|
200
|
+
async function loginKimi(options) {
|
|
201
|
+
const device = await requestDeviceAuthorization();
|
|
202
|
+
options.onAuth?.({
|
|
203
|
+
url: device.verificationUriComplete,
|
|
204
|
+
instructions: `Enter code: ${device.userCode}`
|
|
205
|
+
});
|
|
206
|
+
return pollForToken(device.deviceCode, device.intervalMs, device.expiresInMs, options.signal);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Refresh Kimi OAuth token.
|
|
210
|
+
*/
|
|
211
|
+
async function refreshKimiToken(refreshToken) {
|
|
212
|
+
const response = await fetch(`${resolveOAuthHost()}/api/oauth/token`, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
headers: {
|
|
215
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
216
|
+
...getKimiCommonHeaders()
|
|
217
|
+
},
|
|
218
|
+
body: new URLSearchParams({
|
|
219
|
+
grant_type: "refresh_token",
|
|
220
|
+
refresh_token: refreshToken,
|
|
221
|
+
client_id: CLIENT_ID
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
if (!response.ok) {
|
|
225
|
+
const payload = await response.json().catch(() => void 0);
|
|
226
|
+
const description = payload?.error_description ? `: ${payload.error_description}` : "";
|
|
227
|
+
throw new OAuthError(`Kimi token refresh failed: ${response.status}${description}`, {
|
|
228
|
+
kind: "token-refresh",
|
|
229
|
+
provider: "kimi",
|
|
230
|
+
status: response.status
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return parseTokenPayload(await response.json(), refreshToken);
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
export { kimi_exports as n, getKimiCommonHeaders as t };
|