mslxdff 0.1.96 → 0.1.97

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.96",
3
+ "version": "0.1.97",
4
4
  "description": "测试项目,请勿使用。",
5
5
  "type": "module",
6
6
  "bin": {
package/src/groups.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { timingSafeEqual, createHash } from "node:crypto";
2
+ import { compatFetch } from "./compat.js";
2
3
  import { loadGroups, saveGroups, loadBans, saveBans } from "./state.js";
3
4
  import { normalizePeerUrl } from "./peers.js";
4
5
 
@@ -159,7 +160,7 @@ export function createGroupsService({ file } = {}) {
159
160
 
160
161
  // Re-register with the leader (join is idempotent) and return the fresh member list.
161
162
  // No key is needed once registered: the leader verifies our bearer token.
162
- export async function refreshGroupMembers(name, { leaderUrl, memberName, url, token, kind, fetchImpl = fetch } = {}) {
163
+ export async function refreshGroupMembers(name, { leaderUrl, memberName, url, token, kind, fetchImpl = compatFetch } = {}) {
163
164
  const controller = new AbortController();
164
165
  const timer = setTimeout(() => controller.abort(), SYNC_TIMEOUT_MS);
165
166
  try {
@@ -1,6 +1,7 @@
1
1
  import { createKeyRing } from "../keyring.js";
2
2
  import { loadProviderKeys, loadProviderBaseUrl, loadProviderModelsPath, loadProviderChatPath, saveProviderConfig } from "../../state.js";
3
3
  import { envInt, joinUrl, getUndici, createAgent, collectApiKeysGeneric, createChatRunner } from "../base.js";
4
+ import { compatFetch } from "../../compat.js";
4
5
  import { joinModelId } from "../model-id.js";
5
6
  import { createAuthPool } from "./auth.js";
6
7
  import { clineHeaders, isRefreshToken } from "./headers.js";
@@ -34,7 +35,7 @@ export function createClineProvider({
34
35
  const resolvedModelsPath = modelsPath || (_cfgModels && _cfgModels !== "/models" ? _cfgModels : null) || "/ai/cline/recommended-models";
35
36
  const defaultChat = String(resolvedBase).includes("/api/v1") ? "/chat/completions" : "/api/v1/chat/completions";
36
37
  const resolvedChatPath = chatPath || loadProviderChatPath(id, file ? { file } : {}) || defaultChat;
37
- if (!fetchImpl) fetchImpl = UndiciFetch || fetch;
38
+ if (!fetchImpl) fetchImpl = UndiciFetch || compatFetch;
38
39
 
39
40
  const rawKeys = collectApiKeysGeneric(id, apiKeys, apiKey, (pid) => loadProviderKeys(pid, file ? { file } : {}));
40
41
  // 同时兼容 cline 与 clinebot 两个 id 的 keys(用户可能配在任一)
@@ -1,4 +1,5 @@
1
1
  import { joinUrl, getUndici } from "../base.js";
2
+ import { compatFetch } from "../../compat.js";
2
3
  import { joinModelId } from "../model-id.js";
3
4
 
4
5
  const { UndiciFetch } = getUndici();
@@ -8,7 +9,7 @@ function isClineBotHost(baseUrl) {
8
9
  }
9
10
 
10
11
  export function createModelsService({ id, baseUrl, modelsPath, fetchImpl, dispatcher, ring, loadKeys } = {}) {
11
- if (!fetchImpl) fetchImpl = UndiciFetch || fetch;
12
+ if (!fetchImpl) fetchImpl = UndiciFetch || compatFetch;
12
13
  const resolvedBase = String(baseUrl).trim().replace(/\/+$/, "");
13
14
  const resolvedPath = modelsPath || "/ai/cline/recommended-models";
14
15
  const CACHE_TTL = 10 * 60 * 1000;
@@ -1,6 +1,7 @@
1
1
  import { createKeyRing } from "./keyring.js";
2
2
  import { loadProviderKeys, loadProviderBaseUrl, loadProviderModelsPath, loadProviderChatPath } from "../state.js";
3
3
  import { envInt, joinUrl, getUndici, createAgent, collectApiKeysGeneric, createChatRunner, createListModelsRunner, createPreheatRunner } from "./base.js";
4
+ import { compatFetch } from "../compat.js";
4
5
 
5
6
  const { UndiciFetch } = getUndici();
6
7
 
@@ -36,7 +37,7 @@ export function createGenericProvider({
36
37
  if (!id) throw new Error("generic provider requires id");
37
38
  const resolvedBase = resolveBaseUrl(id, baseUrl);
38
39
  if (!resolvedBase) throw new Error(`generic provider ${id}: missing baseUrl`);
39
- if (!fetchImpl) fetchImpl = UndiciFetch || fetch;
40
+ if (!fetchImpl) fetchImpl = UndiciFetch || compatFetch;
40
41
  const resolvedModelsPath = modelsPath || loadProviderModelsPath(id, file ? { file } : {});
41
42
  const resolvedChatPath = chatPath || loadProviderChatPath(id, file ? { file } : {});
42
43
  const ring = createKeyRing(collectApiKeysGeneric(id, apiKeys, apiKey, loadProviderKeys), { cooldownMs });
@@ -1,4 +1,5 @@
1
1
  import { joinUrl } from "../base.js";
2
+ import { compatFetch } from "../../compat.js";
2
3
  import { WORKBUDDY_DEFAULT_BASE_URL } from "../../state/schemas/provider.js";
3
4
 
4
5
  export function decodeJwtExp(token) {
@@ -45,15 +46,11 @@ export function createAuthService({
45
46
  } = {}) {
46
47
  const resolvedBase = baseUrl ? String(baseUrl).trim().replace(/\/+$/, "") : WORKBUDDY_DEFAULT_BASE_URL;
47
48
  if (!fetchImpl) {
48
- try {
49
- const { getUndici } = awaitImportUndici();
50
- fetchImpl = getUndici()?.UndiciFetch || fetch;
51
- } catch {
52
- fetchImpl = fetch;
53
- }
49
+ // 兼容层统一取(undici 优先,老 Node 兜底)
50
+ fetchImpl = compatFetch;
54
51
  }
55
52
  // lazy resolve UndiciFetch if not provided
56
- if (!fetchImpl) fetchImpl = fetch;
53
+ if (!fetchImpl) fetchImpl = compatFetch;
57
54
 
58
55
  const inflightRefresh = new Map();
59
56
 
@@ -1,3 +1,5 @@
1
+ import { compatFetch } from "../../compat.js";
2
+
1
3
  const BALANCE_TTL_MS = 5 * 60 * 1000;
2
4
 
3
5
  export function createBalanceCache({ ttlMs = BALANCE_TTL_MS, now = Date.now } = {}) {
@@ -24,7 +26,7 @@ export function createBalanceCache({ ttlMs = BALANCE_TTL_MS, now = Date.now } =
24
26
  const u = uid || auth?.uid || "";
25
27
  const d = domain || auth?.domain || "www.codebuddy.cn";
26
28
  if (!u || !at) return null;
27
- const fetcher = fetchImpl || fetch;
29
+ const fetcher = fetchImpl || compatFetch;
28
30
  const body = JSON.stringify({
29
31
  PageNumber: 1, PageSize: 100, ProductCode: "p_tcaca", Status: [0, 3],
30
32
  PackageEndTimeRangeBegin: "2026-08-01 00:00:00",
@@ -1,6 +1,7 @@
1
1
  import { createKeyRing } from "../keyring.js";
2
2
  import { loadProviderKeys, loadProviderAuths, loadProviderBaseUrl, loadProviderShareKeys, saveProviderConfig, WORKBUDDY_DEFAULT_BASE_URL, loadProviderModelsPath, loadProviderChatPath } from "../../state.js";
3
3
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { compatFetch } from "../../compat.js";
4
5
  import { join, dirname } from "node:path";
5
6
  import { tmpdir } from "node:os";
6
7
  import { envInt, joinUrl, getUndici, createAgent } from "../base.js";
@@ -54,7 +55,7 @@ export function createWorkbuddyProvider({
54
55
  const resolvedBase = resolveBaseUrl(baseUrl);
55
56
  const resolvedModelsPath = modelsPath || loadProviderModelsPath(id, file ? { file } : {});
56
57
  const resolvedChatPath = chatPath || loadProviderChatPath(id, file ? { file } : {});
57
- if (!fetchImpl) fetchImpl = UndiciFetch || fetch;
58
+ if (!fetchImpl) fetchImpl = UndiciFetch || compatFetch;
58
59
 
59
60
  const keysFromState = loadProviderKeys(id, file ? { file } : {});
60
61
  const authsFromState = loadProviderAuths(id, file ? { file } : {});
@@ -1,3 +1,5 @@
1
+ import { compatFetch } from "../compat.js";
2
+
1
3
  const BALANCE_TTL_MS = 5 * 60 * 1000;
2
4
 
3
5
  const balanceCache = new Map(); // uid -> { total, dailyPacks, activeCount, nextExpire, fetchedAt }
@@ -26,7 +28,7 @@ export async function fetchBalance({ uid, key, auth, domain, baseUrl = "https://
26
28
  const u = uid || auth?.uid || "";
27
29
  const d = domain || auth?.domain || "www.codebuddy.cn";
28
30
  if (!u || !at) return null;
29
- const fetcher = fetchImpl || fetch;
31
+ const fetcher = fetchImpl || compatFetch;
30
32
  const body = JSON.stringify({
31
33
  PageNumber: 1, PageSize: 100, ProductCode: "p_tcaca", Status: [0, 3],
32
34
  PackageEndTimeRangeBegin: "2026-08-01 00:00:00",
@@ -21,7 +21,7 @@ export function clearPeerHealthCache() {
21
21
  healthInflight.clear();
22
22
  }
23
23
 
24
- export async function peerHealthyModels(peer, { timeoutMs = PEER_STATUS_TIMEOUT_MS, fetchImpl = fetch } = {}) {
24
+ export async function peerHealthyModels(peer, { timeoutMs = PEER_STATUS_TIMEOUT_MS, fetchImpl = compatFetch } = {}) {
25
25
  const key = peer?.url || "";
26
26
  const ttl = peerHealthTtlMs();
27
27
  if (ttl > 0) {