mslxdff 0.1.216 → 0.1.217

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mslxdff",
3
- "version": "0.1.216",
3
+ "version": "0.1.217",
4
4
  "description": "测试项目,请勿使用。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -26,6 +26,12 @@ export function injectReasoningPlaceholder(messages, model) {
26
26
 
27
27
  const PASSTHROUGH_KEYS = ["temperature", "top_p", "max_tokens", "max_completion_tokens", "reasoning_effort", "tools", "tool_choice", "stop", "presence_penalty", "frequency_penalty", "response_format", "user", "n", "seed"];
28
28
 
29
+ // 账号级「会话/并发饱和」:上游按账号限同时活跃会话数(TM.00001041 = 并发会话数已达上限(3个))。
30
+ // 这是账号此刻进不去,不是本请求参数错;槽位在上游保留分钟级才回收(与本地进程无关)。
31
+ // 多号场景换另一个账号通常立即成功——故短冷却本账号让下一次 next() 换号并 continue 重试。
32
+ const SESSION_SATURATED_RE = /TM\.00001041|并发会话数已达上限/;
33
+ const SESSION_SATURATED_COOLDOWN_MS = Number.parseInt(process.env.MSLXDFF_CODEARTS_SESSION_COOLDOWN_MS ?? "", 10) || 30_000;
34
+
29
35
  export function buildUpstreamBody(body, { chatId, upstreamModel }) {
30
36
  const out = {
31
37
  model: upstreamModel,
@@ -59,6 +65,12 @@ function stripOwnPrefix(model, providerId) {
59
65
  return s.slice(0, i).toLowerCase() === String(providerId || "").toLowerCase() ? s.slice(i + 1) : s;
60
66
  }
61
67
 
68
+ // 从 4xx/5xx 正文里判「账号级会话饱和」:命中则可换号重试(不同于参数类 400,换号无意义)。
69
+ export function isSessionSaturated(status, bodyText) {
70
+ if (status !== 400 && status !== 429 && status < 500) return false;
71
+ return SESSION_SATURATED_RE.test(String(bodyText || ""));
72
+ }
73
+
62
74
  export function createChatService({
63
75
  id = "codearts",
64
76
  baseUrl = SNAP_BASE,
@@ -155,8 +167,16 @@ export function createChatService({
155
167
  }
156
168
  if (res.status >= 400) {
157
169
  const txt = await res.text().catch(() => "");
170
+ const msg = `codearts upstream http ${res.status}: ${String(txt).slice(0, 300)}`;
171
+ // 账号会话饱和:短冷却本号并换号重试(多号场景另一号通常立即成功);
172
+ // 所有号都饱和才落到重试耗尽分支,交给上层按上游不可用输出。
173
+ if (isSessionSaturated(res.status, txt)) {
174
+ try { activeRing.onError(blob, SESSION_SATURATED_COOLDOWN_MS); } catch {}
175
+ lastErr = Object.assign(new Error(msg), { upstreamStatus: res.status, upstreamBody: txt });
176
+ continue;
177
+ }
158
178
  if (res.status === 429 || res.status >= 500) try { activeRing.onError(blob); } catch {}
159
- return withTiming(errRes(res.status, `codearts upstream http ${res.status}: ${String(txt).slice(0, 300)}`), t0);
179
+ return withTiming(errRes(res.status, msg), t0);
160
180
  }
161
181
  try {
162
182
  const pre = await preflightResponse(res); // HTTP 200 内嵌错误(排队/未注册/福利未领)→ 抛 UpstreamEventError
@@ -173,6 +193,11 @@ export function createChatService({
173
193
  continue;
174
194
  }
175
195
  }
196
+ // 全部号跑完仍无成功:若最后一个是账号会话饱和(非参数错),如实回传上游 400,
197
+ // 别退化成笼统的 "all accounts unavailable"——用户要看得到「并发会话数已达上限」。
198
+ if (lastErr?.upstreamStatus && lastErr?.upstreamBody != null && isSessionSaturated(lastErr.upstreamStatus, lastErr.upstreamBody)) {
199
+ return withTiming(errRes(lastErr.upstreamStatus, lastErr.message), t0);
200
+ }
176
201
  throw Object.assign(lastErr || new Error("codearts: all accounts unavailable"), {
177
202
  _t: { attempts: [], waitMs: 0, totalMs: Math.round(clock() - t0) },
178
203
  });