@lynn123411/dsh-a6api 1.3.0 → 1.4.1
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.md +1 -1
- package/lib/client.js +9 -1
- package/lib/client.js.map +2 -2
- package/lib/index.js +76 -24
- package/lib/index.js.map +4 -4
- package/lib/types/server/catalog.d.ts +2 -0
- package/package.json +4 -1
package/lib/index.js
CHANGED
|
@@ -2,26 +2,78 @@
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import fsp from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
|
|
6
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.1.2-alpha.2_@deepseek-ai+cordis@4.0.2_@deepseek-ai+dsh-in_201e0f99eb7c6b9ed77157bb5f14e24e/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js
|
|
7
|
+
import { opendir, realpath } from "node:fs/promises";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
10
|
+
var DSH_HOME_DIR_NAME = ".dsh";
|
|
11
|
+
var DEFAULT_DSH_HOME_DISPLAY = `~/${DSH_HOME_DIR_NAME}`;
|
|
12
|
+
var DSH_HOME_ENV = "DSH_HOME";
|
|
13
|
+
function defaultDshHome() {
|
|
14
|
+
return join(homedir(), DSH_HOME_DIR_NAME);
|
|
15
|
+
}
|
|
16
|
+
function expandHomePath(path3) {
|
|
17
|
+
if (path3 === "~") return homedir();
|
|
18
|
+
if (path3.startsWith("~/") || path3.startsWith("~\\")) return join(homedir(), path3.slice(2));
|
|
19
|
+
return path3;
|
|
20
|
+
}
|
|
21
|
+
function resolveDshHome(configured, env = process.env) {
|
|
22
|
+
const fromEnv = env[DSH_HOME_ENV];
|
|
23
|
+
return resolve(expandHomePath(configured ?? (fromEnv !== void 0 && fromEnv.trim().length > 0 ? fromEnv : defaultDshHome())));
|
|
24
|
+
}
|
|
25
|
+
function dshHomePath(...segments) {
|
|
26
|
+
return join(resolveDshHome(), ...segments);
|
|
9
27
|
}
|
|
28
|
+
|
|
29
|
+
// src/server/catalog.ts
|
|
30
|
+
var CATALOG_VERSION = 1;
|
|
10
31
|
function catalogFile() {
|
|
11
|
-
return
|
|
32
|
+
return dshHomePath("dsh-a6api", "catalog.json");
|
|
33
|
+
}
|
|
34
|
+
function legacyCatalogFile() {
|
|
35
|
+
return dshHomePath("dsh-a6api-catalog.json");
|
|
36
|
+
}
|
|
37
|
+
function ensureRelocated() {
|
|
38
|
+
const target = catalogFile();
|
|
39
|
+
const legacy = legacyCatalogFile();
|
|
40
|
+
try {
|
|
41
|
+
fs.accessSync(target);
|
|
42
|
+
try {
|
|
43
|
+
fs.unlinkSync(legacy);
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
51
|
+
fs.renameSync(legacy, target);
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
12
54
|
}
|
|
13
55
|
var catalogCache = null;
|
|
14
56
|
function ensureLoaded() {
|
|
15
57
|
if (catalogCache) return catalogCache;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
58
|
+
ensureRelocated();
|
|
59
|
+
const sources = [catalogFile(), legacyCatalogFile()];
|
|
60
|
+
for (const file of sources) {
|
|
61
|
+
try {
|
|
62
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
63
|
+
const j = JSON.parse(raw);
|
|
64
|
+
catalogCache = Array.isArray(j?.entries) ? j.entries.filter((e) => e && typeof e.id === "string") : [];
|
|
65
|
+
if (file !== catalogFile()) {
|
|
66
|
+
try {
|
|
67
|
+
fs.unlinkSync(file);
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return catalogCache;
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
22
74
|
}
|
|
23
|
-
|
|
24
|
-
return
|
|
75
|
+
catalogCache = [];
|
|
76
|
+
return catalogCache;
|
|
25
77
|
}
|
|
26
78
|
function getCatalog() {
|
|
27
79
|
return ensureLoaded();
|
|
@@ -928,7 +980,7 @@ async function marketplaceRestoreChannel(userId, accessToken, channelId, model)
|
|
|
928
980
|
}
|
|
929
981
|
|
|
930
982
|
// src/server/probe.ts
|
|
931
|
-
var sleep = (ms) => new Promise((
|
|
983
|
+
var sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
932
984
|
async function probeSingleModel(baseURL, apiKey, userId, accessToken, modelName) {
|
|
933
985
|
const targetModel = modelName || "";
|
|
934
986
|
const cleanUrl = cleanBaseUrl(baseURL);
|
|
@@ -1061,7 +1113,7 @@ async function getKnownMerchantsFromLogs(userId, accessToken, modelNames = [], l
|
|
|
1061
1113
|
import * as fs2 from "node:fs";
|
|
1062
1114
|
import * as fsp2 from "node:fs/promises";
|
|
1063
1115
|
import * as path2 from "node:path";
|
|
1064
|
-
import * as
|
|
1116
|
+
import * as os from "node:os";
|
|
1065
1117
|
var A6API_CRED_REF = "A6API_API_KEY";
|
|
1066
1118
|
var A6API_TOKEN_REF = "A6API_ACCESS_TOKEN";
|
|
1067
1119
|
var A6API_USER_REF = "A6API_USER_ID";
|
|
@@ -1076,17 +1128,17 @@ async function atomicWriteFile(filePath, content, mode = 384) {
|
|
|
1076
1128
|
await fsp2.writeFile(tmpPath, content, { mode });
|
|
1077
1129
|
await fsp2.rename(tmpPath, filePath);
|
|
1078
1130
|
}
|
|
1079
|
-
function
|
|
1080
|
-
return process.env.DSH_HOME || path2.join(
|
|
1131
|
+
function dshHome() {
|
|
1132
|
+
return process.env.DSH_HOME || path2.join(os.homedir(), ".dsh");
|
|
1081
1133
|
}
|
|
1082
1134
|
function legacyConfigFile() {
|
|
1083
|
-
return path2.join(
|
|
1135
|
+
return path2.join(dshHome(), LEGACY_CONFIG_NAME);
|
|
1084
1136
|
}
|
|
1085
1137
|
function credentialsFile() {
|
|
1086
|
-
return path2.join(
|
|
1138
|
+
return path2.join(dshHome(), ".credentials.yaml");
|
|
1087
1139
|
}
|
|
1088
1140
|
function settingsFile() {
|
|
1089
|
-
return path2.join(
|
|
1141
|
+
return path2.join(dshHome(), "settings.yaml");
|
|
1090
1142
|
}
|
|
1091
1143
|
function getCredentials(ctx) {
|
|
1092
1144
|
try {
|
|
@@ -1656,7 +1708,7 @@ function sendJson(res, status, body) {
|
|
|
1656
1708
|
res.end(JSON.stringify(body));
|
|
1657
1709
|
}
|
|
1658
1710
|
function readBody(req) {
|
|
1659
|
-
return new Promise((
|
|
1711
|
+
return new Promise((resolve2, reject) => {
|
|
1660
1712
|
let data = "";
|
|
1661
1713
|
req.on("data", (chunk) => {
|
|
1662
1714
|
data += chunk;
|
|
@@ -1665,7 +1717,7 @@ function readBody(req) {
|
|
|
1665
1717
|
reject(new Error("Body too large"));
|
|
1666
1718
|
}
|
|
1667
1719
|
});
|
|
1668
|
-
req.on("end", () =>
|
|
1720
|
+
req.on("end", () => resolve2(data.trim()));
|
|
1669
1721
|
req.on("error", reject);
|
|
1670
1722
|
});
|
|
1671
1723
|
}
|
|
@@ -1799,7 +1851,7 @@ function apply(ctx) {
|
|
|
1799
1851
|
try {
|
|
1800
1852
|
found = await Promise.race([
|
|
1801
1853
|
getKnownMerchantsFromLogs(config.userId, token, missing, allLogs),
|
|
1802
|
-
new Promise((
|
|
1854
|
+
new Promise((resolve2) => setTimeout(() => resolve2({}), 1e4))
|
|
1803
1855
|
]);
|
|
1804
1856
|
} catch {
|
|
1805
1857
|
found = {};
|
|
@@ -1867,7 +1919,7 @@ function apply(ctx) {
|
|
|
1867
1919
|
);
|
|
1868
1920
|
}
|
|
1869
1921
|
})(),
|
|
1870
|
-
new Promise((
|
|
1922
|
+
new Promise((resolve2) => setTimeout(() => resolve2(), 1e4))
|
|
1871
1923
|
]);
|
|
1872
1924
|
} catch {
|
|
1873
1925
|
}
|