dsh-cliproxyapi-pro 1.10.1 → 1.12.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/CHANGELOG.md +24 -0
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/lib/client.js +618 -48
- package/lib/host/accounts.js +7 -2
- package/lib/host/apply/controller.js +24 -0
- package/lib/host/apply/quota-service.js +2 -1
- package/lib/host/apply-utils.js +2 -0
- package/lib/host/config.js +12 -1
- package/lib/host/controller.js +19 -0
- package/lib/host/prompt-sanitize.js +119 -0
- package/lib/index.js +1 -0
- package/lib/quota/constants.js +15 -7
- package/lib/quota/controller.js +3 -3
- package/lib/quota/matching.js +32 -3
- package/lib/quota/parsers.js +93 -27
- package/lib/quota/probes/google.js +69 -44
- package/package.json +1 -1
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
// Google Code Assist loading and Antigravity/Gemini quota requests and fallback order.
|
|
2
|
-
import { UPSTREAM, AG_META, GEMINI_META,
|
|
2
|
+
import { UPSTREAM, AG_META, GEMINI_META, AG_UA, GROUP_GEMINI, GROUP_ARGON, GROUP_CLAUDE_GPT } from "../constants.js";
|
|
3
3
|
import { QuotaError, isObj, firstText, projectIdOf, extractPlan } from "../helpers.js";
|
|
4
4
|
import { antigravitySummaryWindows, antigravityModelWindows, googleBucketWindows } from "../parsers.js";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const agHeaders = () => ({ Authorization: "Bearer $TOKEN$", "Content-Type": "application/json", "User-Agent": AG_UA });
|
|
7
|
+
|
|
8
|
+
/** Which Antigravity quota pool a window describes: "argon", "gemini", "claude-gpt" or "other". */
|
|
9
|
+
function windowFamily(w) {
|
|
10
|
+
const prefixes = Array.isArray(w.modelPrefixes) ? w.modelPrefixes : [];
|
|
11
|
+
if (w.group === GROUP_ARGON || prefixes.includes("argon")) return "argon";
|
|
12
|
+
if (w.group === GROUP_GEMINI || prefixes.includes("gemini")) return "gemini";
|
|
13
|
+
if (w.group === GROUP_CLAUDE_GPT || prefixes.includes("claude")) return "claude-gpt";
|
|
14
|
+
return "other";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function hasFamily(windows, family) {
|
|
18
|
+
return Array.isArray(windows) && windows.some((w) => windowFamily(w) === family);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `base` plus the rows of families it does not have yet (unclassified rows by id). */
|
|
22
|
+
function mergeFamilies(base, rows) {
|
|
23
|
+
if (base === null) return [...rows];
|
|
24
|
+
const present = new Set(base.map(windowFamily));
|
|
25
|
+
const ids = new Set(base.map((w) => w.id));
|
|
26
|
+
return [...base, ...rows.filter((r) => {
|
|
27
|
+
const family = windowFamily(r);
|
|
28
|
+
return family === "other" ? !ids.has(r.id) : !present.has(family);
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createGoogleProbes({ apiCall, now }) {
|
|
7
33
|
async function loadCodeAssist(ctx, authIndex, metadata) {
|
|
8
|
-
const headers = metadata.ideType === "ANTIGRAVITY"
|
|
9
|
-
? { Authorization: "Bearer $TOKEN$", "Content-Type": "application/json", "User-Agent": AG_SUMMARY_UA }
|
|
10
|
-
: googleHeaders(metadata);
|
|
34
|
+
const headers = metadata.ideType === "ANTIGRAVITY" ? agHeaders() : googleHeaders(metadata);
|
|
11
35
|
const body = await apiCall(ctx, { auth_index: authIndex, method: "POST", url: UPSTREAM.googleLoad, header: headers, data: JSON.stringify({ metadata }) });
|
|
12
36
|
const project = body.cloudaicompanionProject ?? body.cloudaicompanion_project;
|
|
13
37
|
return { body, projectID: isObj(project) ? firstText(project.id) : firstText(project) };
|
|
@@ -24,7 +48,7 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
24
48
|
}
|
|
25
49
|
|
|
26
50
|
return {
|
|
27
|
-
async antigravity(ctx, entry, authIndex
|
|
51
|
+
async antigravity(ctx, entry, authIndex) {
|
|
28
52
|
let projectID = projectIdOf(entry);
|
|
29
53
|
let plan = "";
|
|
30
54
|
let tier = null;
|
|
@@ -32,58 +56,54 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
32
56
|
const loaded = await loadCodeAssist(ctx, authIndex, AG_META);
|
|
33
57
|
projectID = loaded.projectID;
|
|
34
58
|
plan = extractPlan(loaded.body);
|
|
35
|
-
} else
|
|
59
|
+
} else {
|
|
60
|
+
// Re-read the tier every round so an upgrade/downgrade replaces the cached plan;
|
|
61
|
+
// a failed read yields "" and the controller keeps the previous plan.
|
|
36
62
|
tier = loadCodeAssist(ctx, authIndex, AG_META).then((l) => extractPlan(l.body), () => "");
|
|
37
63
|
}
|
|
38
64
|
if (projectID === "") throw new QuotaError("missing-project");
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
65
|
+
const read = async (url) => {
|
|
66
|
+
const body = await apiCall(ctx, { auth_index: authIndex, method: "POST", url, header: agHeaders(), data: JSON.stringify({ project: projectID }) });
|
|
67
|
+
plan = plan || extractPlan(body);
|
|
68
|
+
return body;
|
|
69
|
+
};
|
|
70
|
+
// Hosts are always tried in their fixed order (daily first): a host
|
|
71
|
+
// that answered once is not preferred later, because production's
|
|
72
|
+
// Gemini numbers can read 100% regardless of use.
|
|
47
73
|
let lastError = null;
|
|
48
|
-
let partial = null;
|
|
49
74
|
let windows = null;
|
|
50
|
-
for (const url of
|
|
51
|
-
const summary = url.includes("retrieveUserQuotaSummary");
|
|
52
|
-
if (partial !== null && !summary) continue;
|
|
75
|
+
for (const url of UPSTREAM.antigravityQuota) {
|
|
53
76
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
if (rows.some((r) => r.modelPrefixes?.includes("gemini"))) {
|
|
59
|
-
windows = rows;
|
|
60
|
-
agPreferred.set(ctx.origin, url);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
// A host without the Gemini group: keep looking at the other summary hosts.
|
|
64
|
-
if (partial === null) partial = { rows, url };
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const modelRows = antigravityModelWindows(body, now());
|
|
68
|
-
if (modelRows.length > 0) {
|
|
69
|
-
windows = modelRows;
|
|
70
|
-
agPreferred.set(ctx.origin, url);
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
77
|
+
// Like CPA's management center: keep each family from the first host
|
|
78
|
+
// that reports it, until one host has supplied the Gemini pool.
|
|
79
|
+
windows = mergeFamilies(windows, antigravitySummaryWindows(await read(url)));
|
|
80
|
+
if (hasFamily(windows, "gemini")) break;
|
|
73
81
|
} catch (error) {
|
|
74
82
|
if (error?.code === "aborted") throw error;
|
|
75
83
|
lastError = error;
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
|
-
if (windows
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
if (!hasFamily(windows, "gemini")) {
|
|
87
|
+
// Per-model quota supplies the families the summaries lacked.
|
|
88
|
+
for (const url of UPSTREAM.antigravityModels) {
|
|
89
|
+
try {
|
|
90
|
+
const merged = mergeFamilies(windows, antigravityModelWindows(await read(url), now()));
|
|
91
|
+
if (merged.length === (windows?.length ?? 0)) continue;
|
|
92
|
+
windows = merged;
|
|
93
|
+
break;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (error?.code === "aborted") throw error;
|
|
96
|
+
lastError = error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (windows !== null && windows.length > 0 && !hasFamily(windows, "gemini")) {
|
|
81
101
|
try {
|
|
82
102
|
const body = await apiCall(ctx, {
|
|
83
103
|
auth_index: authIndex,
|
|
84
104
|
method: "POST",
|
|
85
105
|
url: UPSTREAM.googleQuota,
|
|
86
|
-
header:
|
|
106
|
+
header: agHeaders(),
|
|
87
107
|
data: JSON.stringify({ project: projectID }),
|
|
88
108
|
});
|
|
89
109
|
windows = [...windows, ...googleBucketWindows(body, now(), "ag-gemini")];
|
|
@@ -92,18 +112,22 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
92
112
|
/* the supplementary Gemini read is best-effort */
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
|
-
if (tier !== null) plan =
|
|
96
|
-
if (windows === null) throw lastError ?? new QuotaError("invalid-response");
|
|
115
|
+
if (tier !== null) plan = (await tier) || plan;
|
|
116
|
+
if (windows === null || windows.length === 0) throw lastError ?? new QuotaError("invalid-response");
|
|
97
117
|
return { windows, plan };
|
|
98
118
|
},
|
|
99
119
|
|
|
100
120
|
async "gemini-cli"(ctx, entry, authIndex) {
|
|
101
121
|
let projectID = projectIdOf(entry);
|
|
102
122
|
let plan = "";
|
|
123
|
+
let tier = null;
|
|
103
124
|
if (projectID === "") {
|
|
104
125
|
const loaded = await loadCodeAssist(ctx, authIndex, GEMINI_META);
|
|
105
126
|
projectID = loaded.projectID;
|
|
106
127
|
plan = extractPlan(loaded.body);
|
|
128
|
+
} else {
|
|
129
|
+
// Same as Antigravity: refresh the tier each round; failures fall back to the cached plan.
|
|
130
|
+
tier = loadCodeAssist(ctx, authIndex, GEMINI_META).then((l) => extractPlan(l.body), () => "");
|
|
107
131
|
}
|
|
108
132
|
if (projectID === "") throw new QuotaError("missing-project");
|
|
109
133
|
const body = await apiCall(ctx, {
|
|
@@ -113,6 +137,7 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
113
137
|
header: googleHeaders({ ...GEMINI_META, duetProject: projectID }),
|
|
114
138
|
data: JSON.stringify({ project: projectID }),
|
|
115
139
|
});
|
|
140
|
+
if (tier !== null) plan = (await tier) || plan;
|
|
116
141
|
return { windows: googleBucketWindows(body, now(), "gemini"), plan };
|
|
117
142
|
},
|
|
118
143
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cliproxyapi-pro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "CLIProxyAPI (CPA) provider for DeepSeek Harness — multiple accounts, model sync over native protocols, per-credential quota, and optional image / video generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|