mslxdff 0.1.162 → 0.1.163
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/package.json +1 -1
- package/src/chat-pipeline/index.js +3 -2
- package/src/cli/commands/stats.js +21 -9
- package/src/cli/help.js +1 -1
- package/src/providers/globalworkbuddy/account-store.js +198 -0
- package/src/providers/globalworkbuddy/auth.js +97 -0
- package/src/providers/globalworkbuddy/catalog.js +138 -0
- package/src/providers/globalworkbuddy/constants.js +73 -0
- package/src/providers/globalworkbuddy/device-auth.js +120 -0
- package/src/providers/globalworkbuddy/errors.js +98 -0
- package/src/providers/globalworkbuddy/headers.js +89 -0
- package/src/providers/globalworkbuddy/models.js +96 -0
- package/src/providers/globalworkbuddy/payload.js +80 -0
- package/src/providers/qoder/aggregate.js +12 -3
- package/src/providers/qoder/chat.js +9 -2
- package/src/providers/qoder/index.js +13 -3
- package/src/providers/qoder/models.js +7 -3
- package/src/providers/qoder/payload.js +7 -1
- package/src/providers/qoder/request.js +2 -1
- package/src/providers/qoder/sse.js +5 -1
- package/src/providers/qoder/stream.js +16 -4
- package/src/routes/chat/exhausted-handler.js +13 -2
- package/src/routes/chat/relay-pipeline.js +18 -2
- package/src/routes/stream-scan.js +22 -5
- package/src/routes/stream.js +2 -3
- package/src/server.js +5 -0
- package/src/talk-full-redact.js +129 -0
- package/src/talk-full.js +130 -0
- package/src/talk-log.js +42 -15
- package/src/upstream-engine/sdk/responses.js +5 -0
- package/src/usage/report.js +14 -8
package/package.json
CHANGED
|
@@ -92,7 +92,8 @@ export function createChatPipeline({ upstream, auto, logs, peers, groups, bus, t
|
|
|
92
92
|
const canForwardPeers = Boolean(peers) && hops < (maxHops ?? 3);
|
|
93
93
|
mark("ordered");
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
const reqIp = clientIp(req); // 一次解析两处用:request 事件的 ip 字段 + 回路语料的 clientIp(routes/helpers.js 取 x-forwarded-for 首段)
|
|
96
|
+
evt("request", { reqId, hops, ip: reqIp, stream: Boolean(req?.body?.stream), prompt: summarizePrompt(req?.body), rawModel: policy.rawModel, requested, lockModel: lockModel || null });
|
|
96
97
|
if (aliasInfo) evt("alias", { reqId, alias: aliasInfo, rawModel: policy.rawModel, requested });
|
|
97
98
|
if (Object.keys(shareKeys).length) evt("share-keys", { reqId, providers: Object.keys(shareKeys) });
|
|
98
99
|
evt("ordered", { reqId, order, canFallback, canForwardPeers, useAuto, statuses: auto?.statuses?.() ?? null });
|
|
@@ -110,7 +111,7 @@ export function createChatPipeline({ upstream, auto, logs, peers, groups, bus, t
|
|
|
110
111
|
// 客户端会话标识(opencode 插件 chat.headers 注入)→ 透传上游做粘性路由/缓存亲和;
|
|
111
112
|
// 无头时由 upstream.js 按对话首两条消息哈希兜底(不再每请求随机)
|
|
112
113
|
const clientSession = String(req?.headers?.["x-session-affinity"] || req?.headers?.["x-session-id"] || "").trim() || null;
|
|
113
|
-
const handlerCtx = { reqId, model: null, body: req?.body, hops, peers, plugins, evt, logError, logCall, logs, workbuddyUid, sessionId: clientSession };
|
|
114
|
+
const handlerCtx = { reqId, model: null, body: req?.body, hops, peers, plugins, evt, logError, logCall, logs, workbuddyUid, sessionId: clientSession, clientIp: reqIp };
|
|
114
115
|
if (clientSession) evt("client-session", { reqId, sessionId: clientSession.slice(0, 24) });
|
|
115
116
|
|
|
116
117
|
await engine.run({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `-stats`
|
|
1
|
+
// `-stats` 模型用量报表:每窗口每模型 token 消耗 + 首字/总耗时/速度。默认窗口 = 今日 0 点至现在,--hours N 切近 N 小时滚动。
|
|
2
2
|
// 数据来自 src/usage/(逐请求 JSONL),不是 state.json 的终生 EMA —— 见 .scratch/stats-report/SPEC.md
|
|
3
3
|
import { usageReport } from "../../usage/report.js";
|
|
4
4
|
import { usageEnabled, usageKeepDays } from "../../usage/record.js";
|
|
@@ -9,10 +9,18 @@ export function isStatsFlag(args) {
|
|
|
9
9
|
return FLAGS.some((f) => args.includes(f));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// 默认窗口起点 = 本地当日 0 点(setHours 归零,随系统本地时区)。
|
|
13
|
+
export function startOfTodayMs(now = Date.now()) {
|
|
14
|
+
const d = new Date(now);
|
|
15
|
+
d.setHours(0, 0, 0, 0);
|
|
16
|
+
return d.getTime();
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
export function parseStatsArgs(args) {
|
|
13
20
|
const hoursIdx = args.findIndex((a) => a === "--hours" || a === "-hours");
|
|
14
21
|
const rawHours = hoursIdx >= 0 ? Number(args[hoursIdx + 1]) : NaN;
|
|
15
|
-
|
|
22
|
+
// null = 默认「今日 00:00 至今」窗口;显式但非法(非数/≤0)的 --hours 同样视为 null,不再回退 24h
|
|
23
|
+
const hours = Number.isFinite(rawHours) && Math.floor(rawHours) >= 1 ? Math.min(168, Math.floor(rawHours)) : null; // 0<N<1 折成 0 会造成「近 0h 标签配 24h 数据」,与非法同路走当日窗口
|
|
16
24
|
const modelIdx = args.findIndex((a) => a === "--model" || a === "-model");
|
|
17
25
|
const rawModel = modelIdx >= 0 && args[modelIdx + 1] && !String(args[modelIdx + 1]).startsWith("-") ? args[modelIdx + 1] : null;
|
|
18
26
|
return { hours, model: rawModel, json: args.includes("--json") };
|
|
@@ -80,11 +88,12 @@ function performanceRow(id, r) {
|
|
|
80
88
|
return [id, ttfb, fmtMs(r.avgTotalMs), fmtTps(r.avgTps), `${Number(r.ttfSamples) || 0}/${samples}`];
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
export function renderStats(report, { hours =
|
|
91
|
+
export function renderStats(report, { hours = null, model = null } = {}) {
|
|
92
|
+
const rangeLabel = hours == null ? "今日 00:00 至今" : `近 ${hours}h`;
|
|
84
93
|
const lines = [];
|
|
85
94
|
const { models, totals } = report;
|
|
86
95
|
if (!models.length) {
|
|
87
|
-
lines.push(
|
|
96
|
+
lines.push(`暂无用量记录(${rangeLabel}${model ? ` · 模型 ${model}` : ""})— 经 8989 网关发一次请求后出现`);
|
|
88
97
|
lines.push("提示:mslxdff -status 看当前体检 · mslxdff -log 20 看最近事件");
|
|
89
98
|
lines.push("说明:-chat 直连 mimo/big-pickle 不经网关,不计入本表");
|
|
90
99
|
return lines.join("\n");
|
|
@@ -93,7 +102,7 @@ export function renderStats(report, { hours = 24, model = null } = {}) {
|
|
|
93
102
|
const right = "right";
|
|
94
103
|
const tokenRows = [...models.map((m) => tokenRow(m.id, m)), tokenRow("合计", totals)];
|
|
95
104
|
const performanceRows = [...models.map((m) => performanceRow(m.id, m)), performanceRow("合计", totals)];
|
|
96
|
-
lines.push(
|
|
105
|
+
lines.push(`模型用量报告(${rangeLabel}${model ? ` · 筛选 ${model}` : ""})`);
|
|
97
106
|
lines.push(`成功请求:${totals.requests} 次 · 模型:${models.length} 个`);
|
|
98
107
|
lines.push("");
|
|
99
108
|
lines.push("Token 用量");
|
|
@@ -109,14 +118,15 @@ export function renderStats(report, { hours = 24, model = null } = {}) {
|
|
|
109
118
|
lines.push("口径差异:-status / -model stats 的首字仍取自 state 的终生 EMA(按转发入口量),与本表**不同源**。");
|
|
110
119
|
lines.push("范围:只含经 8989 网关的成功请求;不含失败请求和 -chat 直连。");
|
|
111
120
|
const keepDays = usageKeepDays();
|
|
112
|
-
if (hours > keepDays * 24) {
|
|
113
|
-
lines.push(
|
|
121
|
+
if (hours != null && hours > keepDays * 24) {
|
|
122
|
+
lines.push(`警告:查询窗口 ${hours}h 超过数据保留 ${keepDays} 天,历史可能不完整。`);
|
|
114
123
|
} else {
|
|
115
124
|
lines.push(`数据保留 ${keepDays} 天;更早的历史已删除。`);
|
|
116
125
|
}
|
|
117
126
|
lines.push("明细口径:本表按模型聚合,不展开 via、interrupted 和单次 tps。");
|
|
118
127
|
lines.push("数值使用 k/M 缩写;需要精确值或机器处理请加 --json。");
|
|
119
|
-
lines.push("
|
|
128
|
+
lines.push("可调:默认统计今日 0 点至现在 · mslxdff -stats --hours N(近 N 小时滚动,上限 168)| --model <id> | --json");
|
|
129
|
+
lines.push("时区:「今日 0 点」按系统本地时区计,与用量日文件的日切同源。");
|
|
120
130
|
return lines.join("\n");
|
|
121
131
|
}
|
|
122
132
|
|
|
@@ -127,7 +137,9 @@ export async function handleStats(args) {
|
|
|
127
137
|
console.log("用量记录已关闭(MSLXDFF_USAGE_LOG=0)—— 去掉该 env 后重启 daemon 即可恢复采集。");
|
|
128
138
|
return true;
|
|
129
139
|
}
|
|
130
|
-
const
|
|
140
|
+
const now = Date.now();
|
|
141
|
+
const since = hours == null ? startOfTodayMs(now) : null; // 缺省/非法 --hours → 当日 0 点起,毫秒精确不漂移
|
|
142
|
+
const report = await usageReport({ hours, since, model, now });
|
|
131
143
|
if (json) {
|
|
132
144
|
console.log(JSON.stringify(report, null, 2));
|
|
133
145
|
return true;
|
package/src/cli/help.js
CHANGED
|
@@ -5,7 +5,7 @@ Usage:
|
|
|
5
5
|
mslxdff start as a background daemon and exit (status + help if one is already running)
|
|
6
6
|
mslxdff -d start as a background daemon
|
|
7
7
|
mslxdff -status show current status (daemon/health/port/config, upstream providers, models + metrics/体检表, autostart/plugins, groups/peers, recent calls with ttfb/tps, last error)
|
|
8
|
-
mslxdff -stats [--hours N] [--json] [--model <id>] per-model token usage + speed
|
|
8
|
+
mslxdff -stats [--hours N] [--json] [--model <id>] per-model token usage + speed; default window: today 00:00 → now (local timezone); with --hours N a rolling last-N-hours window (max 168; success requests only, from the local usage JSONL)
|
|
9
9
|
|
|
10
10
|
mslxdff -log [N] show last N events (default 10, e.g. -log 100)
|
|
11
11
|
mslxdff -models interactive picker: ↑/↓ select a model, Enter sets it as the default (non-TTY: plain list)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// globalworkbuddy 账号落盘单一源:`auths/globalworkbuddy-<uid>.json`(0600 tmp+rename)+ `state.json` 双写。
|
|
2
|
+
// 结构 vendor 自 `globalqwenwork/account-store.js`(同仓库的多租户先例,ADR-0041),三处命名空间独立:
|
|
3
|
+
// ① 文件前缀 `globalworkbuddy-`:与 `workbuddy-` **互不为前缀**,故两区凭据同目录也扫不串
|
|
4
|
+
// (反向亦然:`workbuddy-x.json` 不 startsWith("globalworkbuddy-"));
|
|
5
|
+
// ② state 键 `providerConfigs.globalworkbuddy`;
|
|
6
|
+
// ③ 凭据目录 env 独立 `GLOBALWORKBUDDY_AUTH_DIR`(不与国内版 WORKBUDDY_AUTH_DIR 共享)。
|
|
7
|
+
// ⚠ region 守卫:`state/provider-config.js:14-29` 的 `normalizeAuths` 会把缺失的 domain **默认成 www.codebuddy.cn**。
|
|
8
|
+
// 所以这里写入时必须显式带 domain,读取时又按 `isGlobalDomain` 复核一遍 —— 否则一枚国内号一旦被误写进来,
|
|
9
|
+
// 就会被当国际号发给 .ai(或反向),那是跨产品泄露凭据(参考仓库 auth.ts:377-395 对此直接抛错)。
|
|
10
|
+
import { writeFileSync, mkdirSync, existsSync, renameSync, unlinkSync, readdirSync, readFileSync, chmodSync } from "node:fs";
|
|
11
|
+
import { join, dirname } from "node:path";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { isTestEnv, defaultStateFile } from "../../state/store.js";
|
|
14
|
+
import { DOMAIN, isGlobalDomain } from "./constants.js";
|
|
15
|
+
|
|
16
|
+
const PROVIDER_ID = "globalworkbuddy";
|
|
17
|
+
const FILE_PREFIX = "globalworkbuddy-";
|
|
18
|
+
|
|
19
|
+
export function authDirFor({ explicit = "", testEnv = false, stateFile } = {}) {
|
|
20
|
+
if (explicit) return explicit;
|
|
21
|
+
if (testEnv) return join(tmpdir(), "mslxdff-test-auths-globalworkbuddy");
|
|
22
|
+
return join(dirname(stateFile), "auths");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function resolveAuthDir() {
|
|
26
|
+
return authDirFor({
|
|
27
|
+
explicit: process.env.GLOBALWORKBUDDY_AUTH_DIR || "",
|
|
28
|
+
testEnv: isTestEnv(),
|
|
29
|
+
stateFile: defaultStateFile(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 读取候选:主位置优先;显式 env 或测试环境不带 cwd 兜底(防把凭据写进任意目录,教训见 ADR-0025)。 */
|
|
34
|
+
export function resolveAuthDirs() {
|
|
35
|
+
const primary = resolveAuthDir();
|
|
36
|
+
const cwdDir = join(process.cwd(), "auths");
|
|
37
|
+
const explicit = process.env.GLOBALWORKBUDDY_AUTH_DIR || "";
|
|
38
|
+
if (explicit || isTestEnv() || !cwdDir || cwdDir === primary) return [primary];
|
|
39
|
+
return [primary, cwdDir];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseDoc(fp) {
|
|
43
|
+
try {
|
|
44
|
+
const doc = JSON.parse(readFileSync(fp, "utf8"));
|
|
45
|
+
const uid = doc?.account?.uid;
|
|
46
|
+
if (!uid || !doc?.auth?.accessToken) return null;
|
|
47
|
+
return doc;
|
|
48
|
+
} catch { return null; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 这枚凭据是否属于国际版(domain 判定;缺失即视为国内号,绝不默认放行)。 */
|
|
52
|
+
export function isGlobalDoc(doc) {
|
|
53
|
+
return isGlobalDomain(doc?.auth?.domain || "");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 列国际版账号。**非 global domain 的文件直接跳过并计数**,供上层打一条人话告警:
|
|
58
|
+
* 表现上就是「CN 号被误写进本 provider」的唯一出口。
|
|
59
|
+
*/
|
|
60
|
+
export function listAccountDocs({ dirs } = {}) {
|
|
61
|
+
const out = [];
|
|
62
|
+
const rejected = [];
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
for (const dir of dirs || resolveAuthDirs()) {
|
|
65
|
+
let files = [];
|
|
66
|
+
try {
|
|
67
|
+
if (!existsSync(dir)) continue;
|
|
68
|
+
files = readdirSync(dir).filter((f) => f.startsWith(FILE_PREFIX) && f.endsWith(".json"));
|
|
69
|
+
} catch { continue; }
|
|
70
|
+
for (const f of files) {
|
|
71
|
+
const fp = join(dir, f);
|
|
72
|
+
const doc = parseDoc(fp);
|
|
73
|
+
if (!doc) continue;
|
|
74
|
+
const uid = String(doc.account.uid);
|
|
75
|
+
if (seen.has(uid)) continue;
|
|
76
|
+
if (!isGlobalDoc(doc)) { rejected.push({ uid, file: fp, domain: doc?.auth?.domain || "" }); continue; }
|
|
77
|
+
seen.add(uid);
|
|
78
|
+
out.push({ uid, file: fp, dir, doc });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { docs: out, rejectedRegionMismatch: rejected };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 兼容旧调用面:只要 docs。 */
|
|
85
|
+
export function listAccounts(opts) {
|
|
86
|
+
return listAccountDocs(opts).docs;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function findAccountFile(uid) {
|
|
90
|
+
for (const { file } of listAccounts()) {
|
|
91
|
+
if (file.endsWith(`${FILE_PREFIX}${uid}.json`)) return file;
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function writeAccountFile({ uid, accessToken, refreshToken = "", expiresAt = 0, domain = DOMAIN, enterpriseId = "", nickname = "" }) {
|
|
97
|
+
const authDir = resolveAuthDir();
|
|
98
|
+
mkdirSync(authDir, { recursive: true });
|
|
99
|
+
const doc = {
|
|
100
|
+
account: { uid, enterpriseId, nickname },
|
|
101
|
+
auth: { accessToken, refreshToken, expiresAt, domain },
|
|
102
|
+
};
|
|
103
|
+
const fp = join(authDir, `${FILE_PREFIX}${uid}.json`);
|
|
104
|
+
const tmp = `${fp}.tmp`;
|
|
105
|
+
writeFileSync(tmp, JSON.stringify(doc, null, 2), { mode: 0o600 });
|
|
106
|
+
try {
|
|
107
|
+
if (existsSync(fp)) { try { chmodSync(fp, 0o600); } catch {} unlinkSync(fp); }
|
|
108
|
+
renameSync(tmp, fp);
|
|
109
|
+
} catch {
|
|
110
|
+
writeFileSync(fp, JSON.stringify(doc, null, 2), { mode: 0o600 });
|
|
111
|
+
try { unlinkSync(tmp); } catch {} // 失败路径别把含凭据的 .tmp 留在盘上
|
|
112
|
+
}
|
|
113
|
+
try { chmodSync(fp, 0o600); } catch {}
|
|
114
|
+
return fp;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** state 落盘:keys[i] 存裸 accessToken(对话直接当 Bearer 用,与国内版家族一致)。 */
|
|
118
|
+
async function persistAccounts(accounts, file) {
|
|
119
|
+
const { loadProviderConfigs, saveProviderConfig } = await import("../../state.js");
|
|
120
|
+
const cfg = (loadProviderConfigs(file ? { file } : {})?.[PROVIDER_ID]) || {};
|
|
121
|
+
const keys = [...(Array.isArray(cfg.keys) ? cfg.keys : [])];
|
|
122
|
+
const auths = [...(Array.isArray(cfg.auths) ? cfg.auths : [])];
|
|
123
|
+
let updated = 0;
|
|
124
|
+
for (const acc of accounts) {
|
|
125
|
+
if (!acc?.uid || !acc?.accessToken) continue;
|
|
126
|
+
const row = {
|
|
127
|
+
uid: String(acc.uid),
|
|
128
|
+
domain: acc.domain || DOMAIN, // **必须显式**:normalizeAuths 缺省会填国内域
|
|
129
|
+
enterpriseId: acc.enterpriseId || "",
|
|
130
|
+
refreshToken: acc.refreshToken || "",
|
|
131
|
+
};
|
|
132
|
+
const idx = auths.findIndex((a) => String(a?.uid) === String(acc.uid));
|
|
133
|
+
if (idx >= 0) { keys[idx] = acc.accessToken; auths[idx] = row; updated += 1; }
|
|
134
|
+
else { keys.push(acc.accessToken); auths.push(row); }
|
|
135
|
+
}
|
|
136
|
+
saveProviderConfig(PROVIDER_ID, { baseUrl: cfg.baseUrl || "", keys, auths }, file ? { file } : {});
|
|
137
|
+
return { keys, auths, updated };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function saveGlobalworkbuddyAccount({ uid, accessToken, refreshToken = "", expiresAt = 0, domain = DOMAIN, enterpriseId = "", nickname = "", file } = {}) {
|
|
141
|
+
if (!uid || !accessToken) throw new Error("saveGlobalworkbuddyAccount: 缺少 uid/accessToken");
|
|
142
|
+
if (!isGlobalDomain(domain)) throw new Error(`saveGlobalworkbuddyAccount: domain=${domain || "(空)"} 不是国际版域,拒绝写入(防跨区串号)`);
|
|
143
|
+
const fp = writeAccountFile({ uid, accessToken, refreshToken, expiresAt, domain, enterpriseId, nickname });
|
|
144
|
+
const st = await persistAccounts([{ uid, accessToken, refreshToken, domain, enterpriseId, nickname }], file);
|
|
145
|
+
return { file: fp, accounts: st.keys.length, updated: st.updated > 0 };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 刷新后回写:accessToken 换新的、refreshToken 可能被上游一并轮换、expiresAt 取上游 expiresIn。 */
|
|
149
|
+
export async function applyTokenRefresh({ uid, oldKey = "", accessToken, refreshToken = "", expiresAt = 0, domain = DOMAIN, enterpriseId = "", file } = {}) {
|
|
150
|
+
if (!uid || !accessToken) return { updated: false, accounts: 0, file: null };
|
|
151
|
+
const prevDocs = listAccounts();
|
|
152
|
+
const prev = prevDocs.find((d) => String(d.uid) === String(uid))?.doc || {};
|
|
153
|
+
const fp = writeAccountFile({
|
|
154
|
+
uid,
|
|
155
|
+
accessToken,
|
|
156
|
+
refreshToken: refreshToken || prev?.auth?.refreshToken || "",
|
|
157
|
+
expiresAt: expiresAt || 0,
|
|
158
|
+
domain: prev?.auth?.domain || domain,
|
|
159
|
+
enterpriseId: enterpriseId || prev?.account?.enterpriseId || "",
|
|
160
|
+
nickname: prev?.account?.nickname || "",
|
|
161
|
+
});
|
|
162
|
+
const st = await persistAccounts([{
|
|
163
|
+
uid,
|
|
164
|
+
accessToken,
|
|
165
|
+
refreshToken: refreshToken || prev?.auth?.refreshToken || "",
|
|
166
|
+
domain: prev?.auth?.domain || domain,
|
|
167
|
+
enterpriseId: enterpriseId || prev?.account?.enterpriseId || "",
|
|
168
|
+
}], file);
|
|
169
|
+
return { updated: Boolean(oldKey) || st.updated > 0, accounts: st.keys.length, file: fp };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 删号:扫全部候选目录,防旧副本「复活」(与国内版同纪律)。 */
|
|
173
|
+
export async function removeAccount(uid) {
|
|
174
|
+
let removed = 0;
|
|
175
|
+
for (const dir of resolveAuthDirs()) {
|
|
176
|
+
const fp = join(dir, `${FILE_PREFIX}${uid}.json`);
|
|
177
|
+
try { if (existsSync(fp)) { unlinkSync(fp); removed += 1; } } catch {}
|
|
178
|
+
}
|
|
179
|
+
const { loadProviderConfigs, saveProviderConfig } = await import("../../state.js");
|
|
180
|
+
const cfg = loadProviderConfigs()?.[PROVIDER_ID] || {};
|
|
181
|
+
const rawKeys = Array.isArray(cfg.keys) ? cfg.keys : [];
|
|
182
|
+
const rawAuths = Array.isArray(cfg.auths) ? cfg.auths : [];
|
|
183
|
+
// keys[i] ↔ auths[i] 是平行数组:**必须成对摘**。按 uid 命中时整对丢弃,
|
|
184
|
+
// 否则会出现「keys 少一格、auths 少另一格」的错位串号(比留个孤儿更糟)。
|
|
185
|
+
const newKeys = [];
|
|
186
|
+
const newAuths = [];
|
|
187
|
+
const n = Math.max(rawKeys.length, rawAuths.length);
|
|
188
|
+
for (let i = 0; i < n; i++) {
|
|
189
|
+
const a = rawAuths[i];
|
|
190
|
+
if (a && String(a.uid) === String(uid)) continue;
|
|
191
|
+
if (rawKeys[i] !== undefined) newKeys.push(rawKeys[i]);
|
|
192
|
+
if (a !== undefined) newAuths.push(a);
|
|
193
|
+
}
|
|
194
|
+
saveProviderConfig(PROVIDER_ID, { baseUrl: cfg.baseUrl || "", keys: newKeys, auths: newAuths }, {});
|
|
195
|
+
return { removed, accounts: newAuths.length };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export const PROVIDER_ID_FOR_STORE = PROVIDER_ID;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// 国际版 token 生命周期。与国内版 `workbuddy/auth.js` 有两处**有意不同**(都是取证换来的):
|
|
2
|
+
// ① 刷新响应里的 `domain` / `expiresIn` **要采纳**(国内版只取 token 对,等于把上游的账号迁移信息丢掉);
|
|
3
|
+
// ② 刷新请求**不带 Bearer**(见 `headers.js` 通道隔离),国内版带着可能已过期的 accessToken 打刷新口。
|
|
4
|
+
// ⚠ 只认「明确失败」:拿不到新 accessToken 一律返回 null 交给上层,绝不抛穿对话链路。
|
|
5
|
+
import { compatFetch, timeoutSignal } from "../../compat.js";
|
|
6
|
+
import { joinUrl } from "../base.js";
|
|
7
|
+
import { BASE, REFRESH_PATH, DOMAIN, JSON_TIMEOUT_MS, REFRESH_MARGIN_MS } from "./constants.js";
|
|
8
|
+
import { refreshHeaders } from "./headers.js";
|
|
9
|
+
import { classifyUpstreamError } from "./errors.js";
|
|
10
|
+
|
|
11
|
+
/** JWT `exp`(秒);非 JWT/解不出一律 0 = 「不主动刷新」,比猜一个安全。 */
|
|
12
|
+
export function decodeJwtExp(token) {
|
|
13
|
+
try {
|
|
14
|
+
const payload = String(token || "").split(".")[1];
|
|
15
|
+
if (!payload) return 0;
|
|
16
|
+
let b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
17
|
+
const pad = b64.length % 4;
|
|
18
|
+
if (pad) b64 += "=".repeat(4 - pad);
|
|
19
|
+
const json = JSON.parse(Buffer.from(b64, "base64").toString("utf8"));
|
|
20
|
+
return Number(json.exp || 0);
|
|
21
|
+
} catch { return 0; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createAuthService({
|
|
25
|
+
baseUrl = BASE,
|
|
26
|
+
fetchImpl,
|
|
27
|
+
clock = Date.now,
|
|
28
|
+
dispatcher,
|
|
29
|
+
applyRefresh, // 注入落盘(测试用假实现);缺省走 account-store.applyTokenRefresh
|
|
30
|
+
marginMs = REFRESH_MARGIN_MS,
|
|
31
|
+
} = {}) {
|
|
32
|
+
if (!fetchImpl) fetchImpl = compatFetch;
|
|
33
|
+
const resolvedBase = String(baseUrl || BASE).trim().replace(/\/+$/, "");
|
|
34
|
+
const inflight = new Map(); // uid → Promise,同一号并发只刷一次
|
|
35
|
+
|
|
36
|
+
async function doRefresh(cred) {
|
|
37
|
+
const url = joinUrl(resolvedBase, REFRESH_PATH);
|
|
38
|
+
try {
|
|
39
|
+
const opts = { method: "POST", headers: refreshHeaders(cred), body: "{}", signal: timeoutSignal(JSON_TIMEOUT_MS) };
|
|
40
|
+
if (dispatcher) opts.dispatcher = dispatcher;
|
|
41
|
+
const res = await fetchImpl(url, opts);
|
|
42
|
+
const text = await res.text();
|
|
43
|
+
let j;
|
|
44
|
+
try { j = JSON.parse(text); } catch { return null; }
|
|
45
|
+
if (j.code !== 0 || !j.data?.accessToken) {
|
|
46
|
+
// 刷新口自己说「会话死了」才算真死;网络/5xx 之类返回 null 让上层换号,别把 refreshToken 烧光
|
|
47
|
+
const cls = classifyUpstreamError(res.status, text);
|
|
48
|
+
if (cls.kind !== "session_dead") {
|
|
49
|
+
try { console.error(`[globalworkbuddy] refresh 被拒(${cls.code || cls.kind}),保留凭据不换思路重试`); } catch {}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const out = {
|
|
54
|
+
accessToken: String(j.data.accessToken),
|
|
55
|
+
refreshToken: String(j.data.refreshToken || cred.refreshToken || ""),
|
|
56
|
+
expiresAt: Number(j.data.expiresIn) > 0 ? Math.floor(Date.now() / 1000) + Number(j.data.expiresIn) : 0,
|
|
57
|
+
domain: String(j.data.domain || cred.domain || DOMAIN),
|
|
58
|
+
};
|
|
59
|
+
const persist = applyRefresh || (await import("./account-store.js")).applyTokenRefresh;
|
|
60
|
+
try {
|
|
61
|
+
await persist({ uid: cred.uid, oldKey: cred.accessToken, accessToken: out.accessToken, refreshToken: out.refreshToken, expiresAt: out.expiresAt, domain: out.domain, enterpriseId: cred.enterpriseId || "" });
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(`[globalworkbuddy] token 落盘失败(刷新已成功,重启将丢失): ${String(err?.message || err).slice(0, 200)}`);
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
} catch { return null; }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 返回新 accessToken(失败 null)。并发去重按 uid。 */
|
|
70
|
+
async function refreshTokenFor(cred) {
|
|
71
|
+
if (!cred?.uid || !cred?.refreshToken) return null;
|
|
72
|
+
const key = String(cred.uid);
|
|
73
|
+
if (inflight.has(key)) {
|
|
74
|
+
try { return (await inflight.get(key))?.accessToken || null; } catch { return null; }
|
|
75
|
+
}
|
|
76
|
+
const p = doRefresh(cred);
|
|
77
|
+
inflight.set(key, p);
|
|
78
|
+
try {
|
|
79
|
+
const r = await p;
|
|
80
|
+
return r?.accessToken || null;
|
|
81
|
+
} finally { inflight.delete(key); }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 临期(<margin 且未过期太久)先刷,省掉一次 401 往返。 */
|
|
85
|
+
function maybeProactiveRefresh(cred) {
|
|
86
|
+
try {
|
|
87
|
+
const exp = decodeJwtExp(cred?.accessToken);
|
|
88
|
+
if (!exp) return;
|
|
89
|
+
const remain = exp * 1000 - clock();
|
|
90
|
+
if (remain < marginMs && remain > -60 * 60 * 1000) {
|
|
91
|
+
void refreshTokenFor(cred).catch(() => {});
|
|
92
|
+
}
|
|
93
|
+
} catch {}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { refreshTokenFor, maybeProactiveRefresh, decodeJwtExp, _inflight: inflight };
|
|
97
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// `/v3/config` 产品文档 → 可调用模型表。
|
|
2
|
+
// 解析纪律照参考仓库 `parseModelCatalog`(upstream.ts:1100-1153),但**成员判定按国际版实测**:
|
|
3
|
+
// 成员 = `agents[name==cli].models` 白名单 ∩ 可用行(`disabled!==true` 且 maxInput/maxOutput 均 > 0)。
|
|
4
|
+
// 为什么要「交」而不是直接信白名单:白名单里有、但池里没有元数据的多是别名(`default-model`/`fast-model`/
|
|
5
|
+
// `primary-model` 等),直调容易被拒;反过来池里有、白名单没有的是「本身份不能调」的模型。两个都不能进选择器。
|
|
6
|
+
// 国际版独有:行的窗口是 `contextWindow` **对象**(`defaultLength` + `supportedLengths[]`),国内版是平铺 `maxInputTokens`。
|
|
7
|
+
import { KNOWN_MODELS } from "./constants.js";
|
|
8
|
+
|
|
9
|
+
/** 目录可能带 `{code,msg,data}` 信封,也可能把产品文档**裸**放在顶层(实测两种都出现过)。 */
|
|
10
|
+
export function unwrapConfigDocument(json) {
|
|
11
|
+
if (!json || typeof json !== "object") return {};
|
|
12
|
+
if (json.data && typeof json.data === "object" && !Array.isArray(json.data)) return json.data;
|
|
13
|
+
if (Array.isArray(json.models) || Array.isArray(json.agents)) return json;
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** `x0.79 credits` / `x0.79` → 0.79;空串(别名行)→ 0;无法解析 → 999(排到最后,不当免费)。 */
|
|
18
|
+
export function creditsValue(credits) {
|
|
19
|
+
const s = String(credits ?? "").trim();
|
|
20
|
+
if (!s) return 0;
|
|
21
|
+
const m = s.match(/x\s*([\d.]+)/i);
|
|
22
|
+
if (m) {
|
|
23
|
+
const v = Number(m[1]);
|
|
24
|
+
return Number.isFinite(v) ? v : 999;
|
|
25
|
+
}
|
|
26
|
+
return /^\d+(\.\d+)?$/.test(s) ? Number(s) : 999;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 折掉上游单位词,得到语言中性倍率(上游会拼英文 `credits`,钉死在文案里会串语言)。 */
|
|
30
|
+
export function normalizeCredits(credits) {
|
|
31
|
+
const s = String(credits ?? "").trim();
|
|
32
|
+
if (!s || /^credits?$/i.test(s)) return "";
|
|
33
|
+
return s.replace(/\s+credits?$/i, "").trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `modelPromotions[]`(国际版独有)→ 覆盖该模型的生效促销。
|
|
38
|
+
* 只认实测形状:`enabled` + 时间窗 + `displayMode:"replace"`;不认识的形状**整条丢掉**,
|
|
39
|
+
* 因为「渲染一个自己看不懂的折扣」会把用户实际要付的钱报少。
|
|
40
|
+
*/
|
|
41
|
+
export function parsePromotions(document, modelId) {
|
|
42
|
+
const list = Array.isArray(document?.modelPromotions) ? document.modelPromotions : [];
|
|
43
|
+
const out = [];
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
for (const p of list) {
|
|
46
|
+
if (!p || typeof p !== "object") continue;
|
|
47
|
+
const targets = Array.isArray(p.modelIds) ? p.modelIds : Array.isArray(p.models) ? p.models : [];
|
|
48
|
+
if (p.enabled === false) continue;
|
|
49
|
+
if (targets.length && !targets.some((x) => String(x) === String(modelId))) continue;
|
|
50
|
+
const start = Number(p.validFrom ?? p.startTime ?? 0);
|
|
51
|
+
const end = Number(p.validTo ?? p.endTime ?? 0);
|
|
52
|
+
const windowed = Number.isFinite(start) && Number.isFinite(end) && start > 0 && end > 0;
|
|
53
|
+
if (windowed && (now < start || now > end)) continue; // 过期促销不得继续显示
|
|
54
|
+
const factor = Number(p.factor ?? p.discount ?? p.rate ?? NaN);
|
|
55
|
+
out.push({
|
|
56
|
+
start: windowed ? start : 0,
|
|
57
|
+
end: windowed ? end : 0,
|
|
58
|
+
label: typeof p.label === "string" ? p.label.trim() : typeof p.name === "string" ? p.name.trim() : "",
|
|
59
|
+
factor: Number.isFinite(factor) ? factor : NaN,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function positiveNum(v) {
|
|
66
|
+
return typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 解析产品文档。返回按 credits 升序的模型行;**cli 白名单缺失时返回空数组**(由调用方决定回落兜底表)。
|
|
71
|
+
* 每行带 `source: "upstream"`,方便 UI 区分「真目录」与「兜底表」。
|
|
72
|
+
*/
|
|
73
|
+
export function parseModelCatalog(document) {
|
|
74
|
+
const doc = document && typeof document === "object" ? document : {};
|
|
75
|
+
const rawModels = Array.isArray(doc.models) ? doc.models : [];
|
|
76
|
+
const agents = Array.isArray(doc.agents) ? doc.agents : [];
|
|
77
|
+
let cliIds = null;
|
|
78
|
+
for (const agent of agents) {
|
|
79
|
+
if (agent && typeof agent === "object" && agent.name === "cli" && Array.isArray(agent.models)) {
|
|
80
|
+
cliIds = agent.models.filter((x) => typeof x === "string");
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!cliIds || !cliIds.length) return [];
|
|
85
|
+
|
|
86
|
+
const byId = new Map();
|
|
87
|
+
for (const m of rawModels) {
|
|
88
|
+
if (!m || typeof m !== "object") continue;
|
|
89
|
+
const id = typeof m.id === "string" ? m.id.trim() : "";
|
|
90
|
+
if (!id || m.disabled === true) continue;
|
|
91
|
+
const input = Number(m.maxInputTokens) || 0;
|
|
92
|
+
const output = Number(m.maxOutputTokens) || 0;
|
|
93
|
+
if (!positiveNum(input) || !positiveNum(output)) continue; // 「上架但不可服务」的 id 绝不进选择器
|
|
94
|
+
const cw = m.contextWindow && typeof m.contextWindow === "object" ? m.contextWindow : null;
|
|
95
|
+
const defaultLen = cw && positiveNum(cw.defaultLength) ? cw.defaultLength : 0;
|
|
96
|
+
const supported = cw && Array.isArray(cw.supportedLengths)
|
|
97
|
+
? cw.supportedLengths.filter(positiveNum) : [];
|
|
98
|
+
const credits = normalizeCredits(m.credits);
|
|
99
|
+
byId.set(id, {
|
|
100
|
+
id,
|
|
101
|
+
name: typeof m.name === "string" && m.name.trim() ? m.name.trim() : id,
|
|
102
|
+
vendor: typeof m.vendor === "string" ? m.vendor : "",
|
|
103
|
+
credits,
|
|
104
|
+
multiplier: creditsValue(m.credits),
|
|
105
|
+
free: creditsValue(m.credits) === 0,
|
|
106
|
+
maxInputTokens: input,
|
|
107
|
+
maxOutputTokens: output,
|
|
108
|
+
contextWindow: defaultLen || input,
|
|
109
|
+
...(defaultLen ? { defaultContextWindow: defaultLen } : {}),
|
|
110
|
+
...(supported.length ? { supportedContextWindows: supported } : {}),
|
|
111
|
+
supportsImages: m.supportsImages === true && m.disabledMultimodal !== true,
|
|
112
|
+
supportsReasoning: m.supportsReasoning === true,
|
|
113
|
+
onlyReasoning: m.onlyReasoning === true,
|
|
114
|
+
promotions: parsePromotions(doc, id),
|
|
115
|
+
source: "upstream",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const rows = cliIds.map((id) => byId.get(id)).filter(Boolean);
|
|
120
|
+
return rows.sort((a, b) => a.multiplier - b.multiplier || a.id.localeCompare(b.id));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 兜底表:仅上游取数失败时用,标 `source:"fallback"`,**不编窗口数字**。 */
|
|
124
|
+
export function fallbackCatalog() {
|
|
125
|
+
return KNOWN_MODELS.map((m) => ({
|
|
126
|
+
...m,
|
|
127
|
+
multiplier: creditsValue(m.credits),
|
|
128
|
+
free: creditsValue(m.credits) === 0,
|
|
129
|
+
source: "fallback",
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 挑最便宜的可调用模型(验收 hi 与「省积分」默认值都用它)。 */
|
|
134
|
+
export function pickCheapest(rows) {
|
|
135
|
+
const list = Array.isArray(rows) ? rows.filter((r) => r && typeof r.id === "string") : [];
|
|
136
|
+
if (!list.length) return null;
|
|
137
|
+
return [...list].sort((a, b) => (a.multiplier ?? 999) - (b.multiplier ?? 999) || a.id.localeCompare(b.id))[0];
|
|
138
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// globalworkbuddy(WorkBuddy AI 国际站 www.workbuddy.ai)上游技术常量。
|
|
2
|
+
// 值来源:2026-10-05 现网取证,逐条证据见 `.scratch/globalworkbuddy/FINDINGS.md` 结论 A/B。
|
|
3
|
+
// **禁止凭记忆改值**;要改先现网复测 —— 上游一升级这些快照就可能变(同 `globalqwenwork/constants.js:3` 的纪律)。
|
|
4
|
+
// Note: 为何独立 provider 而非 workbuddy 的新 region —— ① 两区模型池几乎无交集(国际版独有 gpt-6 系/gemini-3.8-flash),
|
|
5
|
+
// 目录与 allowlist 绝不能跨区互供;② 把 `.ai` 的 token 发给 `copilot.tencent.com` 等于跨产品泄露凭据
|
|
6
|
+
// (参考仓库 auth.ts 对此直接抛 credential-region-mismatch);③ 两区凭据不可互通。
|
|
7
|
+
|
|
8
|
+
export function envStr(name, fallback) {
|
|
9
|
+
const v = process.env[name];
|
|
10
|
+
return typeof v === "string" && v.trim() ? v.trim() : fallback;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 国际版是「三区合一」:chat / billing / Origin 全指向同一个 host。
|
|
15
|
+
* 国内版才是 chat=copilot.tencent.com、billing/Origin=www.codebuddy.cn 分开的,别把那个形状搬过来。
|
|
16
|
+
*/
|
|
17
|
+
export const BASE = envStr("MSLXDFF_GLOBALWORKBUDDY_BASE_URL", "https://www.workbuddy.ai").replace(/\/+$/, "");
|
|
18
|
+
export const ORIGIN = BASE;
|
|
19
|
+
/** 凭据归属域;判定「这枚凭据属不属于国际版」的依据就是它是否以 `.workbuddy.ai` 结尾。 */
|
|
20
|
+
export const DOMAIN = envStr("MSLXDFF_GLOBALWORKBUDDY_DOMAIN", "www.workbuddy.ai");
|
|
21
|
+
|
|
22
|
+
export function isGlobalDomain(domain) {
|
|
23
|
+
const d = String(domain || "").trim().toLowerCase();
|
|
24
|
+
return d === "workbuddy.ai" || d.endsWith(".workbuddy.ai");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// —— 端点(全部现网实测,2026-10-05)——
|
|
28
|
+
export const MODELS_PATH = "/v3/config"; // 200 code=0;国内版的 /console/enterprises/personal/models 在这里恒 **500**
|
|
29
|
+
export const CHAT_PATH = "/v2/chat/completions"; // 与国内版同路径
|
|
30
|
+
export const REFRESH_PATH = "/v2/plugin/auth/token/refresh"; // 实测路由存在(伪造 token 探得 401/12153「token format error」,非 404)
|
|
31
|
+
export const BILLING_PATH = "/v2/billing/meter/get-user-resource"; // 200,`data.Response.Data`,与国内版同形状
|
|
32
|
+
export const BILLING_SUMMARY_PATH = "/billing/meter/get-user-resource-summary"; // 200,`data.Packages[]`(容量是**字符串**)
|
|
33
|
+
export const AUTH_STATE_PATH = "/v2/plugin/auth/state"; // POST ?platform= → {state, authUrl}
|
|
34
|
+
export const AUTH_TOKEN_PATH = "/v2/plugin/auth/token"; // GET ?state= → 轮询
|
|
35
|
+
export const LOGIN_ACCOUNT_PATH = "/v2/plugin/login/account"; // GET ?state= → {uid, enterpriseId, nickname}
|
|
36
|
+
|
|
37
|
+
// ⚠ 参考仓库 issue/PR **#19 声称**国际版 refresh 是 `/v2/auth/token/refresh` —— 现网实测 `404 {"error_msg":"404 Route Not Found"}`,
|
|
38
|
+
// 且该 PR `merged=False`、从未进 shipped 代码。**别照抄未合并 PR 的说法**,一律以本文件路径为准。
|
|
39
|
+
|
|
40
|
+
/** 设备授权的平台参数;`workbuddy-ai` 与 `CLI` 两个值实测都能拿到 state+authUrl。 */
|
|
41
|
+
export const DEVICE_PLATFORM = envStr("MSLXDFF_GLOBALWORKBUDDY_PLATFORM", "workbuddy-ai");
|
|
42
|
+
|
|
43
|
+
// —— 客户端身份 ——
|
|
44
|
+
// 取证结论 B:`/v3/config` 的返回**不随 UA 变**(5 种配方字节级同一份目录:pool=30/cliRoster=26/usable=26),
|
|
45
|
+
// 所以这里用稳定值即可,不必像参考仓库那样去读安装 App 的 Info.plist。上游一旦收紧,用下面的 env 覆盖排障。
|
|
46
|
+
/** 本机注册表实测实装版本(`DisplayName=[WorkBuddy AI 5.6.2]`;国内版是 5.3.14)。
|
|
47
|
+
* ⚠ 2026-10-08 桌面端错误报告显示 App 已自升级至 **5.7.6** —— 但这不影响任何判定:
|
|
48
|
+
* 官方客户端(自带正身 UA)与我们的请求收到**一字不差**的 11140,身份版本已被证明不是闸门的变量。 */
|
|
49
|
+
export const APP_VERSION = envStr("MSLXDFF_GLOBALWORKBUDDY_APP_VERSION", "5.6.2");
|
|
50
|
+
export const CHAT_UA = envStr("MSLXDFF_GLOBALWORKBUDDY_UA", `WorkBuddy/${APP_VERSION} WorkBuddy AI/${APP_VERSION} CLI/${APP_VERSION}`);
|
|
51
|
+
export const CATALOG_UA = envStr("MSLXDFF_GLOBALWORKBUDDY_CATALOG_UA", `WorkBuddyAI/${APP_VERSION}`);
|
|
52
|
+
export const REFRESH_UA = envStr("MSLXDFF_GLOBALWORKBUDDY_REFRESH_UA", CHAT_UA);
|
|
53
|
+
|
|
54
|
+
export const COOLDOWN_MS = Number(envStr("MSLXDFF_GLOBALWORKBUDDY_COOLDOWN_MS", "30000"));
|
|
55
|
+
export const CONNECT_TIMEOUT_MS = Number(envStr("MSLXDFF_GLOBALWORKBUDDY_TIMEOUT_MS", "30000"));
|
|
56
|
+
export const JSON_TIMEOUT_MS = 20_000;
|
|
57
|
+
export const CHAT_TIMEOUT_MS = 120_000;
|
|
58
|
+
export const MODELS_CACHE_MS = 10 * 60 * 1000;
|
|
59
|
+
export const BALANCE_CACHE_MS = 5 * 60 * 1000;
|
|
60
|
+
export const REFRESH_MARGIN_MS = 5 * 60 * 1000;
|
|
61
|
+
/** 11140(安全审核)实测会随机出现,同请求体原地重试可救回;次数上限走 env。 */
|
|
62
|
+
export const SAFETY_RETRY = Number(envStr("MSLXDFF_GLOBALWORKBUDDY_SAFETY_RETRY", "2"));
|
|
63
|
+
|
|
64
|
+
/** 兜底可调用模型(仅取数失败时展示用)。**刻意只写实测过的 id/倍率,不编造窗口数字。** */
|
|
65
|
+
export const KNOWN_MODELS = [
|
|
66
|
+
{ id: "hy3", credits: "x0.00" },
|
|
67
|
+
{ id: "hy4-preview-f", credits: "x0.00" },
|
|
68
|
+
{ id: "deepseek-v4.1-flash", credits: "x0.00" },
|
|
69
|
+
{ id: "glm-5.3-flash", credits: "x0.06" },
|
|
70
|
+
{ id: "gpt-6-luna", credits: "x0.07" },
|
|
71
|
+
];
|
|
72
|
+
/** 缺省模型:实测 x0.00 且响应快,做 hi 验收用。 */
|
|
73
|
+
export const FALLBACK_MODEL = "hy3";
|