creditdaddy 1.7.2 → 1.8.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/LICENSE +21 -21
- package/README.md +445 -440
- package/build.json +3 -3
- package/package.json +34 -34
- package/src/accounts.js +15 -0
- package/src/assets/donate-alipay.svg +1 -1
- package/src/assets/donate-ifdian.svg +1 -1
- package/src/assets/donate-wechat.svg +1 -1
- package/src/assets/providers/catpaw.png +0 -0
- package/src/assets/providers/codebuddy-ide.png +0 -0
- package/src/assets/providers/dumate.png +0 -0
- package/src/assets/providers/loomy.png +0 -0
- package/src/assets/providers/meoo.png +0 -0
- package/src/assets/providers/mirasim.png +0 -0
- package/src/bgdaemon.js +341 -341
- package/src/buildInfo.js +65 -65
- package/src/catpawClient.js +103 -103
- package/src/catpawLocal.js +236 -236
- package/src/checkin.js +7 -2
- package/src/codebuddyIdeLocal.js +381 -381
- package/src/constants.js +121 -117
- package/src/cookieSites.js +340 -301
- package/src/daemon.js +2682 -2443
- package/src/doubaoClient.js +167 -167
- package/src/dumateClient.js +517 -0
- package/src/dumateLocal.js +298 -0
- package/src/dumateQr.js +337 -0
- package/src/externalQuota.js +577 -574
- package/src/formatDuration.js +17 -17
- package/src/i18n/en.json +161 -7
- package/src/i18n/ja.json +161 -7
- package/src/i18n/ko.json +161 -7
- package/src/i18n/zh-TW.json +161 -7
- package/src/i18n.js +47 -47
- package/src/lingxiClient.js +373 -373
- package/src/localDetect.js +147 -147
- package/src/longcatClient.js +260 -260
- package/src/loomyAuth.js +230 -230
- package/src/loomyClient.js +366 -366
- package/src/loomyLocal.js +206 -206
- package/src/meooAuth.js +246 -0
- package/src/meooClient.js +250 -0
- package/src/minimaxGateway.js +520 -520
- package/src/minimaxLocal.js +344 -344
- package/src/mirasimClient.js +211 -211
- package/src/mirasimLocal.js +392 -392
- package/src/modelscopeClient.js +275 -275
- package/src/panel.html +374 -48
- package/src/prodIcons.json +7 -5
- package/src/providers.js +34 -0
- package/src/qoderApp.js +578 -578
- package/src/qoderClient.js +266 -266
- package/src/qoderUmid.js +199 -199
- package/src/quotaRefresh.js +119 -119
- package/src/refreshGuard.js +75 -75
- package/src/riverClient.js +372 -372
- package/src/store.js +2 -1
- package/src/tenrouterAccounts.js +237 -232
- package/src/traeAuth.js +601 -599
- package/src/traeClient.js +356 -360
- package/src/traeGateway.js +875 -875
- package/src/traeLocal.js +463 -371
- package/src/transfer.js +4 -0
- package/src/usageSync.js +535 -523
- package/src/winProc.js +134 -134
- package/src/xiaomiMimoClient.js +206 -206
- package/src/zcodeAuth.js +131 -131
- package/src/zcodeGateway.js +850 -850
- package/src/zcodeLocal.js +340 -340
- package/src/zcrypto.js +160 -160
package/src/zcodeAuth.js
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ZCode 浏览器登录 — 与 ZCode 客户端的「CLI 轮询登录」同一协议(无需 zcode:// 回调,任何浏览器都能用):
|
|
3
|
-
*
|
|
4
|
-
* 1. POST https://zcode.z.ai/api/v1/oauth/cli/init Authorization: Bearer <本地随机 poll token>
|
|
5
|
-
* {provider: 'bigmodel' | 'zai'} → {flow_id, authorize_url, expires_at, poll_interval_sec}
|
|
6
|
-
* authorize_url 的回调指向 zcode.z.ai 自己的 /oauth/cli/callback,由服务端完成换 token
|
|
7
|
-
* 2. 用户在浏览器(桌面版为隐私窗口)打开 authorize_url 登录授权
|
|
8
|
-
* 3. GET /api/v1/oauth/cli/poll/{flow_id}(同一 poll token)→ status pending / ready / failed
|
|
9
|
-
* ready 时带 token(zcode JWT)、user、bigmodel{access_token, refresh_token} 或 zai{access_token}
|
|
10
|
-
* 4. Z.ai 的 access_token 还要换一次业务 token:POST https://api.z.ai/api/auth/z/login {token}
|
|
11
|
-
*
|
|
12
|
-
* 拿到的凭据按客户端 credentials.json 的格式(enc:v1 加密)组装,存进账号 meta,
|
|
13
|
-
* 之后与「本机导入」的账号完全一样:可查额度、可一键切换到 ZCode 客户端。
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import crypto from 'node:crypto';
|
|
17
|
-
import * as zc from './zcrypto.js';
|
|
18
|
-
import { zcodePaths } from './zcodeLocal.js';
|
|
19
|
-
import { FETCH_TIMEOUT_MS } from './constants.js';
|
|
20
|
-
|
|
21
|
-
const API_BASE = 'https://zcode.z.ai';
|
|
22
|
-
const ZAI_BUSINESS_LOGIN_URL = 'https://api.z.ai/api/auth/z/login';
|
|
23
|
-
|
|
24
|
-
async function fetchJson(url, init = {}) {
|
|
25
|
-
const res = await fetch(url, { ...init, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
26
|
-
const text = await res.text();
|
|
27
|
-
let body = null;
|
|
28
|
-
try { body = text ? JSON.parse(text) : null; } catch {}
|
|
29
|
-
return { res, body };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const str = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
|
|
33
|
-
|
|
34
|
-
/** kind: 'zcode-bigmodel'(智谱 BigModel)| 'zcode-zai'(Z.ai 国际) */
|
|
35
|
-
export async function startZcodeLogin(kind) {
|
|
36
|
-
const provider = kind === 'zcode-zai' ? 'zai' : 'bigmodel';
|
|
37
|
-
const pollToken = crypto.randomBytes(32).toString('hex');
|
|
38
|
-
const { res, body } = await fetchJson(API_BASE + '/api/v1/oauth/cli/init', {
|
|
39
|
-
method: 'POST',
|
|
40
|
-
headers: { Authorization: 'Bearer ' + pollToken, 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
41
|
-
body: JSON.stringify({ provider }),
|
|
42
|
-
});
|
|
43
|
-
const d = body?.data;
|
|
44
|
-
if (!res.ok || body?.code !== 0 || !str(d?.flow_id) || !str(d?.authorize_url)) {
|
|
45
|
-
throw new Error('ZCode 登录初始化失败:' + (body?.msg || 'HTTP ' + res.status));
|
|
46
|
-
}
|
|
47
|
-
if (!d.authorize_url.startsWith('https://')) throw new Error('ZCode 登录初始化返回了非 https 授权地址');
|
|
48
|
-
const expiresInMs = Number.isFinite(d.expires_at) ? d.expires_at * 1000 - Date.now() : 5 * 60e3;
|
|
49
|
-
return {
|
|
50
|
-
url: d.authorize_url,
|
|
51
|
-
expiresInMs: Math.max(60e3, Math.min(expiresInMs, 15 * 60e3)),
|
|
52
|
-
intervalMs: Math.max(1000, (Number(d.poll_interval_sec) || 2) * 1000),
|
|
53
|
-
data: { provider, flowId: d.flow_id, pollToken },
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** 单次轮询:{status:'pending'} | {status:'ok', input};失败抛错 */
|
|
58
|
-
export async function pollZcodeLogin(data) {
|
|
59
|
-
const { res, body } = await fetchJson(API_BASE + '/api/v1/oauth/cli/poll/' + encodeURIComponent(data.flowId), {
|
|
60
|
-
headers: { Authorization: 'Bearer ' + data.pollToken, Accept: 'application/json' },
|
|
61
|
-
});
|
|
62
|
-
if (res.status >= 500 || res.status === 408 || res.status === 429) return { status: 'pending' };
|
|
63
|
-
if (!res.ok || body?.code !== 0) throw new Error('ZCode 授权失败:' + (body?.msg || 'HTTP ' + res.status));
|
|
64
|
-
const d = body.data || {};
|
|
65
|
-
if (d.status === 'pending') return { status: 'pending' };
|
|
66
|
-
if (d.status === 'failed') throw new Error('ZCode 授权失败(用户取消或授权被拒绝)');
|
|
67
|
-
if (d.status !== 'ready') throw new Error('ZCode 授权返回未知状态:' + d.status);
|
|
68
|
-
|
|
69
|
-
const jwt = str(d.token);
|
|
70
|
-
const user = d.user && typeof d.user === 'object' ? d.user : {};
|
|
71
|
-
const userId = user.user_id !== undefined && user.user_id !== null ? String(user.user_id) : null;
|
|
72
|
-
let accessToken = data.provider === 'zai' ? str(d.zai?.access_token) : str(d.bigmodel?.access_token) || str(d.bigmodel?.accessToken);
|
|
73
|
-
const refreshToken = data.provider === 'bigmodel' ? str(d.bigmodel?.refresh_token) || str(d.bigmodel?.refreshToken) : null;
|
|
74
|
-
if (!jwt || !accessToken || !userId) throw new Error('ZCode 授权返回缺少 token / 用户信息(上游结构可能变化)');
|
|
75
|
-
if (data.provider === 'zai') accessToken = await resolveZaiBusinessToken(accessToken);
|
|
76
|
-
|
|
77
|
-
return { status: 'ok', input: buildAccountInput({ provider: data.provider, jwt, accessToken, refreshToken, user, userId }) };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Z.ai OAuth token → 业务 access token(与客户端 ZaiBusinessTokenResolver 一致) */
|
|
81
|
-
async function resolveZaiBusinessToken(oauthToken) {
|
|
82
|
-
const { res, body } = await fetchJson(ZAI_BUSINESS_LOGIN_URL, {
|
|
83
|
-
method: 'POST',
|
|
84
|
-
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
85
|
-
body: JSON.stringify({ token: oauthToken }),
|
|
86
|
-
});
|
|
87
|
-
const ok = res.ok && (body?.code === undefined || body.code === 0 || body.code === 200) && body?.success !== false;
|
|
88
|
-
const t = str(body?.data?.access_token) || str(body?.data?.accessToken);
|
|
89
|
-
if (!ok || !t) throw new Error('Z.ai 业务 token 交换失败:' + (body?.msg || 'HTTP ' + res.status));
|
|
90
|
-
return t;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** 按 ZCode credentials.json 的键名组装并用本机密钥加密(与客户端写出的格式一致) */
|
|
94
|
-
export function buildCredentials({ provider, jwt, accessToken, refreshToken, user, userId }, secret) {
|
|
95
|
-
const label = str(user.name) || str(user.email) || userId;
|
|
96
|
-
const userInfo = {
|
|
97
|
-
id: userId, username: label, displayName: label,
|
|
98
|
-
...(str(user.avatar) ? { avatarUrl: user.avatar } : {}),
|
|
99
|
-
rawProfile: user,
|
|
100
|
-
};
|
|
101
|
-
const enc = (v) => zc.encryptWithSecret(v, secret);
|
|
102
|
-
const creds = {
|
|
103
|
-
'oauth:active_provider': enc(provider),
|
|
104
|
-
[`oauth:${provider}:access_token`]: enc(accessToken),
|
|
105
|
-
[`oauth:${provider}:user_info`]: enc(JSON.stringify(userInfo)),
|
|
106
|
-
zcodejwttoken: enc(jwt),
|
|
107
|
-
};
|
|
108
|
-
if (refreshToken) creds[`oauth:${provider}:refresh_token`] = enc(refreshToken);
|
|
109
|
-
return creds;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function buildAccountInput(parts) {
|
|
113
|
-
const secret = zc.defaultSecret(zcodePaths().home);
|
|
114
|
-
const credentials = buildCredentials(parts, secret);
|
|
115
|
-
const id = zc.identityWithSecret(credentials, secret);
|
|
116
|
-
return {
|
|
117
|
-
provider: 'zcode',
|
|
118
|
-
token: `zcode-creds:${parts.userId}`, // 与本机导入同一标记,同一用户自动去重 / 续期
|
|
119
|
-
uid: parts.userId,
|
|
120
|
-
name: zc.identityLabel(id),
|
|
121
|
-
email: str(parts.user.email),
|
|
122
|
-
source: 'browser',
|
|
123
|
-
// 不带 config / deviceMid:同一账号再次登录时保留已保存的客户端配置与虚拟设备 ID
|
|
124
|
-
meta: {
|
|
125
|
-
credentials,
|
|
126
|
-
canonicalHash: zc.canonicalHash(credentials),
|
|
127
|
-
capturedAt: new Date().toISOString(),
|
|
128
|
-
loginProvider: parts.provider,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* ZCode 浏览器登录 — 与 ZCode 客户端的「CLI 轮询登录」同一协议(无需 zcode:// 回调,任何浏览器都能用):
|
|
3
|
+
*
|
|
4
|
+
* 1. POST https://zcode.z.ai/api/v1/oauth/cli/init Authorization: Bearer <本地随机 poll token>
|
|
5
|
+
* {provider: 'bigmodel' | 'zai'} → {flow_id, authorize_url, expires_at, poll_interval_sec}
|
|
6
|
+
* authorize_url 的回调指向 zcode.z.ai 自己的 /oauth/cli/callback,由服务端完成换 token
|
|
7
|
+
* 2. 用户在浏览器(桌面版为隐私窗口)打开 authorize_url 登录授权
|
|
8
|
+
* 3. GET /api/v1/oauth/cli/poll/{flow_id}(同一 poll token)→ status pending / ready / failed
|
|
9
|
+
* ready 时带 token(zcode JWT)、user、bigmodel{access_token, refresh_token} 或 zai{access_token}
|
|
10
|
+
* 4. Z.ai 的 access_token 还要换一次业务 token:POST https://api.z.ai/api/auth/z/login {token}
|
|
11
|
+
*
|
|
12
|
+
* 拿到的凭据按客户端 credentials.json 的格式(enc:v1 加密)组装,存进账号 meta,
|
|
13
|
+
* 之后与「本机导入」的账号完全一样:可查额度、可一键切换到 ZCode 客户端。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import crypto from 'node:crypto';
|
|
17
|
+
import * as zc from './zcrypto.js';
|
|
18
|
+
import { zcodePaths } from './zcodeLocal.js';
|
|
19
|
+
import { FETCH_TIMEOUT_MS } from './constants.js';
|
|
20
|
+
|
|
21
|
+
const API_BASE = 'https://zcode.z.ai';
|
|
22
|
+
const ZAI_BUSINESS_LOGIN_URL = 'https://api.z.ai/api/auth/z/login';
|
|
23
|
+
|
|
24
|
+
async function fetchJson(url, init = {}) {
|
|
25
|
+
const res = await fetch(url, { ...init, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
26
|
+
const text = await res.text();
|
|
27
|
+
let body = null;
|
|
28
|
+
try { body = text ? JSON.parse(text) : null; } catch {}
|
|
29
|
+
return { res, body };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const str = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
|
|
33
|
+
|
|
34
|
+
/** kind: 'zcode-bigmodel'(智谱 BigModel)| 'zcode-zai'(Z.ai 国际) */
|
|
35
|
+
export async function startZcodeLogin(kind) {
|
|
36
|
+
const provider = kind === 'zcode-zai' ? 'zai' : 'bigmodel';
|
|
37
|
+
const pollToken = crypto.randomBytes(32).toString('hex');
|
|
38
|
+
const { res, body } = await fetchJson(API_BASE + '/api/v1/oauth/cli/init', {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: { Authorization: 'Bearer ' + pollToken, 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
41
|
+
body: JSON.stringify({ provider }),
|
|
42
|
+
});
|
|
43
|
+
const d = body?.data;
|
|
44
|
+
if (!res.ok || body?.code !== 0 || !str(d?.flow_id) || !str(d?.authorize_url)) {
|
|
45
|
+
throw new Error('ZCode 登录初始化失败:' + (body?.msg || 'HTTP ' + res.status));
|
|
46
|
+
}
|
|
47
|
+
if (!d.authorize_url.startsWith('https://')) throw new Error('ZCode 登录初始化返回了非 https 授权地址');
|
|
48
|
+
const expiresInMs = Number.isFinite(d.expires_at) ? d.expires_at * 1000 - Date.now() : 5 * 60e3;
|
|
49
|
+
return {
|
|
50
|
+
url: d.authorize_url,
|
|
51
|
+
expiresInMs: Math.max(60e3, Math.min(expiresInMs, 15 * 60e3)),
|
|
52
|
+
intervalMs: Math.max(1000, (Number(d.poll_interval_sec) || 2) * 1000),
|
|
53
|
+
data: { provider, flowId: d.flow_id, pollToken },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 单次轮询:{status:'pending'} | {status:'ok', input};失败抛错 */
|
|
58
|
+
export async function pollZcodeLogin(data) {
|
|
59
|
+
const { res, body } = await fetchJson(API_BASE + '/api/v1/oauth/cli/poll/' + encodeURIComponent(data.flowId), {
|
|
60
|
+
headers: { Authorization: 'Bearer ' + data.pollToken, Accept: 'application/json' },
|
|
61
|
+
});
|
|
62
|
+
if (res.status >= 500 || res.status === 408 || res.status === 429) return { status: 'pending' };
|
|
63
|
+
if (!res.ok || body?.code !== 0) throw new Error('ZCode 授权失败:' + (body?.msg || 'HTTP ' + res.status));
|
|
64
|
+
const d = body.data || {};
|
|
65
|
+
if (d.status === 'pending') return { status: 'pending' };
|
|
66
|
+
if (d.status === 'failed') throw new Error('ZCode 授权失败(用户取消或授权被拒绝)');
|
|
67
|
+
if (d.status !== 'ready') throw new Error('ZCode 授权返回未知状态:' + d.status);
|
|
68
|
+
|
|
69
|
+
const jwt = str(d.token);
|
|
70
|
+
const user = d.user && typeof d.user === 'object' ? d.user : {};
|
|
71
|
+
const userId = user.user_id !== undefined && user.user_id !== null ? String(user.user_id) : null;
|
|
72
|
+
let accessToken = data.provider === 'zai' ? str(d.zai?.access_token) : str(d.bigmodel?.access_token) || str(d.bigmodel?.accessToken);
|
|
73
|
+
const refreshToken = data.provider === 'bigmodel' ? str(d.bigmodel?.refresh_token) || str(d.bigmodel?.refreshToken) : null;
|
|
74
|
+
if (!jwt || !accessToken || !userId) throw new Error('ZCode 授权返回缺少 token / 用户信息(上游结构可能变化)');
|
|
75
|
+
if (data.provider === 'zai') accessToken = await resolveZaiBusinessToken(accessToken);
|
|
76
|
+
|
|
77
|
+
return { status: 'ok', input: buildAccountInput({ provider: data.provider, jwt, accessToken, refreshToken, user, userId }) };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Z.ai OAuth token → 业务 access token(与客户端 ZaiBusinessTokenResolver 一致) */
|
|
81
|
+
async function resolveZaiBusinessToken(oauthToken) {
|
|
82
|
+
const { res, body } = await fetchJson(ZAI_BUSINESS_LOGIN_URL, {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
85
|
+
body: JSON.stringify({ token: oauthToken }),
|
|
86
|
+
});
|
|
87
|
+
const ok = res.ok && (body?.code === undefined || body.code === 0 || body.code === 200) && body?.success !== false;
|
|
88
|
+
const t = str(body?.data?.access_token) || str(body?.data?.accessToken);
|
|
89
|
+
if (!ok || !t) throw new Error('Z.ai 业务 token 交换失败:' + (body?.msg || 'HTTP ' + res.status));
|
|
90
|
+
return t;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 按 ZCode credentials.json 的键名组装并用本机密钥加密(与客户端写出的格式一致) */
|
|
94
|
+
export function buildCredentials({ provider, jwt, accessToken, refreshToken, user, userId }, secret) {
|
|
95
|
+
const label = str(user.name) || str(user.email) || userId;
|
|
96
|
+
const userInfo = {
|
|
97
|
+
id: userId, username: label, displayName: label,
|
|
98
|
+
...(str(user.avatar) ? { avatarUrl: user.avatar } : {}),
|
|
99
|
+
rawProfile: user,
|
|
100
|
+
};
|
|
101
|
+
const enc = (v) => zc.encryptWithSecret(v, secret);
|
|
102
|
+
const creds = {
|
|
103
|
+
'oauth:active_provider': enc(provider),
|
|
104
|
+
[`oauth:${provider}:access_token`]: enc(accessToken),
|
|
105
|
+
[`oauth:${provider}:user_info`]: enc(JSON.stringify(userInfo)),
|
|
106
|
+
zcodejwttoken: enc(jwt),
|
|
107
|
+
};
|
|
108
|
+
if (refreshToken) creds[`oauth:${provider}:refresh_token`] = enc(refreshToken);
|
|
109
|
+
return creds;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function buildAccountInput(parts) {
|
|
113
|
+
const secret = zc.defaultSecret(zcodePaths().home);
|
|
114
|
+
const credentials = buildCredentials(parts, secret);
|
|
115
|
+
const id = zc.identityWithSecret(credentials, secret);
|
|
116
|
+
return {
|
|
117
|
+
provider: 'zcode',
|
|
118
|
+
token: `zcode-creds:${parts.userId}`, // 与本机导入同一标记,同一用户自动去重 / 续期
|
|
119
|
+
uid: parts.userId,
|
|
120
|
+
name: zc.identityLabel(id),
|
|
121
|
+
email: str(parts.user.email),
|
|
122
|
+
source: 'browser',
|
|
123
|
+
// 不带 config / deviceMid:同一账号再次登录时保留已保存的客户端配置与虚拟设备 ID
|
|
124
|
+
meta: {
|
|
125
|
+
credentials,
|
|
126
|
+
canonicalHash: zc.canonicalHash(credentials),
|
|
127
|
+
capturedAt: new Date().toISOString(),
|
|
128
|
+
loginProvider: parts.provider,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|