zcode-acp-server 0.85.3 → 0.86.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/README.md +1 -1
- package/dist/bin/quota.d.ts +1 -1
- package/dist/bin/quota.d.ts.map +1 -1
- package/dist/bin/quota.js +5 -20
- package/dist/bin/quota.js.map +1 -1
- package/dist/code-fingerprint.json +2 -2
- package/dist/config/user-config.d.ts +0 -8
- package/dist/config/user-config.d.ts.map +1 -1
- package/dist/config/user-config.js +0 -2
- package/dist/config/user-config.js.map +1 -1
- package/dist/handlers/account.d.ts +3 -34
- package/dist/handlers/account.d.ts.map +1 -1
- package/dist/handlers/account.js +5 -38
- package/dist/handlers/account.js.map +1 -1
- package/dist/quota/combined.d.ts +1 -5
- package/dist/quota/combined.d.ts.map +1 -1
- package/dist/quota/combined.js +6 -24
- package/dist/quota/combined.js.map +1 -1
- package/dist/quota/format.d.ts +0 -9
- package/dist/quota/format.d.ts.map +1 -1
- package/dist/quota/format.js +0 -19
- package/dist/quota/format.js.map +1 -1
- package/dist/quota/live.d.ts.map +1 -1
- package/dist/quota/live.js +5 -12
- package/dist/quota/live.js.map +1 -1
- package/dist/remote/hub-server.d.ts.map +1 -1
- package/dist/remote/hub-server.js +3 -7
- package/dist/remote/hub-server.js.map +1 -1
- package/package.json +1 -1
- package/dist/quota/cliproxy/aggregate.d.ts +0 -48
- package/dist/quota/cliproxy/aggregate.d.ts.map +0 -1
- package/dist/quota/cliproxy/aggregate.js +0 -118
- package/dist/quota/cliproxy/aggregate.js.map +0 -1
- package/dist/quota/cliproxy/client.d.ts +0 -45
- package/dist/quota/cliproxy/client.d.ts.map +0 -1
- package/dist/quota/cliproxy/client.js +0 -140
- package/dist/quota/cliproxy/client.js.map +0 -1
- package/dist/quota/cliproxy/config.d.ts +0 -24
- package/dist/quota/cliproxy/config.d.ts.map +0 -1
- package/dist/quota/cliproxy/config.js +0 -27
- package/dist/quota/cliproxy/config.js.map +0 -1
- package/dist/quota/cliproxy/format.d.ts +0 -18
- package/dist/quota/cliproxy/format.d.ts.map +0 -1
- package/dist/quota/cliproxy/format.js +0 -71
- package/dist/quota/cliproxy/format.js.map +0 -1
- package/dist/quota/cliproxy/index.d.ts +0 -44
- package/dist/quota/cliproxy/index.d.ts.map +0 -1
- package/dist/quota/cliproxy/index.js +0 -148
- package/dist/quota/cliproxy/index.js.map +0 -1
- package/dist/quota/cliproxy/parse.d.ts +0 -46
- package/dist/quota/cliproxy/parse.d.ts.map +0 -1
- package/dist/quota/cliproxy/parse.js +0 -176
- package/dist/quota/cliproxy/parse.js.map +0 -1
- package/dist/quota/cliproxy/types.d.ts +0 -82
- package/dist/quota/cliproxy/types.d.ts.map +0 -1
- package/dist/quota/cliproxy/types.js +0 -33
- package/dist/quota/cliproxy/types.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/aggregate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmBH;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAA0B;IAC5D,oDAAoD;IACpD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA+E,CAAC;IACxG,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;gBACpB,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACpC,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CA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,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACzC,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;KACzE,CAAC,CAAC,CAAC;IACJ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACrF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI management HTTP client.
|
|
3
|
-
*
|
|
4
|
-
* Two calls, both Bearer-authed with the management key:
|
|
5
|
-
* - credentials listing (v8: `/v8/management/credentials`; the v0 servers
|
|
6
|
-
* that still exist answer `/v0/management/auth-files` — probed once, the
|
|
7
|
-
* working spelling cached for the process);
|
|
8
|
-
* - `api-call` — the credential-scoped upstream relay the management web UI
|
|
9
|
-
* itself uses for Gemini quota.
|
|
10
|
-
*
|
|
11
|
-
* No retries beyond the URL-candidate ladder: a remote quota card must fail
|
|
12
|
-
* fast into `unavailable`, not hang the combined view.
|
|
13
|
-
*/
|
|
14
|
-
import type { CpResponse } from "./types.js";
|
|
15
|
-
/**
|
|
16
|
-
* Upstream quota endpoints CPAMC itself tries, in order
|
|
17
|
-
* (Cli-Proxy-API-Management-Center `constants.ts`): the primary internal
|
|
18
|
-
* quota API first, sandbox and bare variants as fallbacks.
|
|
19
|
-
*/
|
|
20
|
-
export declare const QUOTA_SUMMARY_URLS: readonly ["https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary", "https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:retrieveUserQuotaSummary", "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary"];
|
|
21
|
-
/** Hook: forget the cached route spellings (tests, and watch-mode ticks so a
|
|
22
|
-
* server upgrade mid-watch re-probes instead of sticking to a stale route). */
|
|
23
|
-
export declare function resetRouteCache(): void;
|
|
24
|
-
/**
|
|
25
|
-
* List the proxy's credential entries. 401/403 surfaces to the caller as
|
|
26
|
-
* `auth_error`; other statuses as `unavailable`.
|
|
27
|
-
*/
|
|
28
|
-
export declare function fetchCredentials(base: string, key: string, fetchImpl?: typeof globalThis.fetch): Promise<CpResponse>;
|
|
29
|
-
/**
|
|
30
|
-
* Relay `retrieveUserQuotaSummary` for one account. `$TOKEN$` is substituted
|
|
31
|
-
* by the proxy with that credential's OAuth token — the key never sees the
|
|
32
|
-
* token, and we never see it either (it stays server-side).
|
|
33
|
-
*
|
|
34
|
-
* The upstream URL ladder walks on the UPSTREAM status carried inside the
|
|
35
|
-
* relay envelope (CPAMC's semantics): the relay itself answers HTTP 200 with
|
|
36
|
-
* the upstream result embedded, so a 403/404 upstream means this URL variant
|
|
37
|
-
* is not the one this account's client is recognized on — the next variant
|
|
38
|
-
* may still answer. Only an upstream 2xx satisfies the ladder.
|
|
39
|
-
*
|
|
40
|
-
* @returns the relay response (its `body` is the upstream JSON as a STRING),
|
|
41
|
-
* or null when every URL candidate failed (relay/network error, or
|
|
42
|
-
* no variant produced an upstream 2xx).
|
|
43
|
-
*/
|
|
44
|
-
export declare function fetchQuotaSummary(base: string, key: string, authIndex: string, projectId: string | undefined, fetchImpl?: typeof globalThis.fetch): Promise<CpResponse | null>;
|
|
45
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/quota/cliproxy/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAwB7C;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,gQAIrB,CAAC;AAMX;gFACgF;AAChF,wBAAgB,eAAe,IAAI,IAAI,CAGtC;AA4CD;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,OAAO,UAAU,CAAC,KAAwB,GACpD,OAAO,CAAC,UAAU,CAAC,CAWrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,GAAE,OAAO,UAAU,CAAC,KAAwB,GACpD,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAoC5B"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI management HTTP client.
|
|
3
|
-
*
|
|
4
|
-
* Two calls, both Bearer-authed with the management key:
|
|
5
|
-
* - credentials listing (v8: `/v8/management/credentials`; the v0 servers
|
|
6
|
-
* that still exist answer `/v0/management/auth-files` — probed once, the
|
|
7
|
-
* working spelling cached for the process);
|
|
8
|
-
* - `api-call` — the credential-scoped upstream relay the management web UI
|
|
9
|
-
* itself uses for Gemini quota.
|
|
10
|
-
*
|
|
11
|
-
* No retries beyond the URL-candidate ladder: a remote quota card must fail
|
|
12
|
-
* fast into `unavailable`, not hang the combined view.
|
|
13
|
-
*/
|
|
14
|
-
import { relayUpstreamStatus } from "./parse.js";
|
|
15
|
-
const TIMEOUT_MS = 10_000;
|
|
16
|
-
/** Both route spellings, tried in order; the winner is cached per process. */
|
|
17
|
-
const CREDENTIALS_ROUTES = ["/v8/management/credentials", "/v0/management/auth-files"];
|
|
18
|
-
// The v8 relay lives under `/requests/` (official docs/management-api-v8.md);
|
|
19
|
-
// a top-level `/v8/management/api-call` does not exist and answers 404.
|
|
20
|
-
const API_CALL_ROUTES = ["/v8/management/requests/api-call", "/v0/management/api-call"];
|
|
21
|
-
/**
|
|
22
|
-
* Antigravity accounts' client identity (CPAMC `constants.ts`
|
|
23
|
-
* ANTIGRAVITY_USER_AGENT). The quota endpoint gates on it twice: no
|
|
24
|
-
* antigravity UA at all → 403 "You do not have a valid license of this
|
|
25
|
-
* product"; the `antigravity/cli/1.0.13` UA → a PARTIAL snapshot that drops
|
|
26
|
-
* the Gemini Models group on the daily-* hosts (observed live 2026-10-20:
|
|
27
|
-
* the card reported only the Claude/GPT pool while the user's real usage sat
|
|
28
|
-
* in the invisible Gemini family). The hub UA gets the full two-group
|
|
29
|
-
* payload. Keep aligned with CPAMC (ANTIGRAVITY_HUB_VERSION) and CLIProxyAPI's
|
|
30
|
-
* internal/misc/antigravity_version.go — Cloud Code rejects clients below
|
|
31
|
-
* 2.23.0 for newer models.
|
|
32
|
-
*/
|
|
33
|
-
const ANTIGRAVITY_USER_AGENT = "antigravity/hub/2.23.0 darwin/arm64";
|
|
34
|
-
/**
|
|
35
|
-
* Upstream quota endpoints CPAMC itself tries, in order
|
|
36
|
-
* (Cli-Proxy-API-Management-Center `constants.ts`): the primary internal
|
|
37
|
-
* quota API first, sandbox and bare variants as fallbacks.
|
|
38
|
-
*/
|
|
39
|
-
export const QUOTA_SUMMARY_URLS = [
|
|
40
|
-
"https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
41
|
-
"https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
42
|
-
"https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
43
|
-
];
|
|
44
|
-
/** Route-spelling memory (set on first success; 404 keeps probing). */
|
|
45
|
-
let credentialsRoute = null;
|
|
46
|
-
let apiCallRoute = null;
|
|
47
|
-
/** Hook: forget the cached route spellings (tests, and watch-mode ticks so a
|
|
48
|
-
* server upgrade mid-watch re-probes instead of sticking to a stale route). */
|
|
49
|
-
export function resetRouteCache() {
|
|
50
|
-
credentialsRoute = null;
|
|
51
|
-
apiCallRoute = null;
|
|
52
|
-
}
|
|
53
|
-
function authHeaders(key) {
|
|
54
|
-
return {
|
|
55
|
-
Authorization: `Bearer ${key}`,
|
|
56
|
-
"X-Management-Key": key,
|
|
57
|
-
Accept: "application/json",
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
async function fetchOnce(url, key, init, fetchImpl) {
|
|
61
|
-
const resp = await fetchImpl(url, {
|
|
62
|
-
...init,
|
|
63
|
-
headers: { ...authHeaders(key), ...init.headers },
|
|
64
|
-
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
65
|
-
});
|
|
66
|
-
return { status: resp.status, text: await resp.text() };
|
|
67
|
-
}
|
|
68
|
-
/** Probe the route spellings until one answers non-404 (cached afterwards). */
|
|
69
|
-
async function fetchRouted(base, key, routes, cached, init, fetchImpl) {
|
|
70
|
-
if (cached) {
|
|
71
|
-
return { route: cached, resp: await fetchOnce(`${base}${cached}`, key, init, fetchImpl) };
|
|
72
|
-
}
|
|
73
|
-
let last = { status: 404, text: "" };
|
|
74
|
-
for (const route of routes) {
|
|
75
|
-
last = await fetchOnce(`${base}${route}`, key, init, fetchImpl);
|
|
76
|
-
if (last.status !== 404)
|
|
77
|
-
return { route, resp: last };
|
|
78
|
-
}
|
|
79
|
-
return { route: null, resp: last };
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* List the proxy's credential entries. 401/403 surfaces to the caller as
|
|
83
|
-
* `auth_error`; other statuses as `unavailable`.
|
|
84
|
-
*/
|
|
85
|
-
export async function fetchCredentials(base, key, fetchImpl = globalThis.fetch) {
|
|
86
|
-
const { route, resp } = await fetchRouted(base, key, CREDENTIALS_ROUTES, credentialsRoute, { method: "GET" }, fetchImpl);
|
|
87
|
-
if (route)
|
|
88
|
-
credentialsRoute = route;
|
|
89
|
-
return resp;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Relay `retrieveUserQuotaSummary` for one account. `$TOKEN$` is substituted
|
|
93
|
-
* by the proxy with that credential's OAuth token — the key never sees the
|
|
94
|
-
* token, and we never see it either (it stays server-side).
|
|
95
|
-
*
|
|
96
|
-
* The upstream URL ladder walks on the UPSTREAM status carried inside the
|
|
97
|
-
* relay envelope (CPAMC's semantics): the relay itself answers HTTP 200 with
|
|
98
|
-
* the upstream result embedded, so a 403/404 upstream means this URL variant
|
|
99
|
-
* is not the one this account's client is recognized on — the next variant
|
|
100
|
-
* may still answer. Only an upstream 2xx satisfies the ladder.
|
|
101
|
-
*
|
|
102
|
-
* @returns the relay response (its `body` is the upstream JSON as a STRING),
|
|
103
|
-
* or null when every URL candidate failed (relay/network error, or
|
|
104
|
-
* no variant produced an upstream 2xx).
|
|
105
|
-
*/
|
|
106
|
-
export async function fetchQuotaSummary(base, key, authIndex, projectId, fetchImpl = globalThis.fetch) {
|
|
107
|
-
for (const url of QUOTA_SUMMARY_URLS) {
|
|
108
|
-
let resp = null;
|
|
109
|
-
try {
|
|
110
|
-
const routed = await fetchRouted(base, key, API_CALL_ROUTES, apiCallRoute, {
|
|
111
|
-
method: "POST",
|
|
112
|
-
headers: { "Content-Type": "application/json" },
|
|
113
|
-
body: JSON.stringify({
|
|
114
|
-
auth_index: authIndex,
|
|
115
|
-
method: "POST",
|
|
116
|
-
url,
|
|
117
|
-
header: {
|
|
118
|
-
Authorization: "Bearer $TOKEN$",
|
|
119
|
-
"Content-Type": "application/json",
|
|
120
|
-
"User-Agent": ANTIGRAVITY_USER_AGENT,
|
|
121
|
-
},
|
|
122
|
-
data: JSON.stringify(projectId !== undefined ? { project: projectId } : {}),
|
|
123
|
-
}),
|
|
124
|
-
}, fetchImpl);
|
|
125
|
-
if (routed.route)
|
|
126
|
-
apiCallRoute = routed.route;
|
|
127
|
-
resp = routed.resp;
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
resp = null; // network/timeout on this variant — try the next
|
|
131
|
-
}
|
|
132
|
-
if (resp?.status !== 200)
|
|
133
|
-
continue;
|
|
134
|
-
const upstream = relayUpstreamStatus(resp.text);
|
|
135
|
-
if (upstream >= 200 && upstream < 300)
|
|
136
|
-
return resp;
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,8EAA8E;AAC9E,MAAM,kBAAkB,GAAG,CAAC,4BAA4B,EAAE,2BAA2B,CAAC,CAAC;AACvF,8EAA8E;AAC9E,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,kCAAkC,EAAE,yBAAyB,CAAC,CAAC;AAExF;;;;;;;;;;;GAWG;AACH,MAAM,sBAAsB,GAAG,qCAAqC,CAAC;AAErE;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,+EAA+E;IAC/E,uFAAuF;IACvF,yEAAyE;CACjE,CAAC;AAEX,uEAAuE;AACvE,IAAI,gBAAgB,GAAkB,IAAI,CAAC;AAC3C,IAAI,YAAY,GAAkB,IAAI,CAAC;AAEvC;gFACgF;AAChF,MAAM,UAAU,eAAe;IAC7B,gBAAgB,GAAG,IAAI,CAAC;IACxB,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO;QACL,aAAa,EAAE,UAAU,GAAG,EAAE;QAC9B,kBAAkB,EAAE,GAAG;QACvB,MAAM,EAAE,kBAAkB;KAC3B,CAAC;AACJ,CAAC;AAED,KAAK,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AC;QAAC,MAAM,CAAC;YACP,IAAI,GAAG,IAAI,CAAC,CAAC,iDAAiD;QAChE,CAAC;QACD,IAAI,IAAI,EAAE,MAAM,KAAK,GAAG;YAAE,SAAS;QACnC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,QAAQ,IAAI,GAAG,IAAI,QAAQ,GAAG,GAAG;YAAE,OAAO,IAAI,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI credential discovery — the same convention as the Ollama card:
|
|
3
|
-
* config file first (`~/.config/zcode-acp/config.json` `quota.cliproxyUrl` +
|
|
4
|
-
* `quota.cliproxyManagementKey`), env vars as a full fallback
|
|
5
|
-
* (`CLIPROXY_URL` / `CLIPROXY_MANAGEMENT_KEY`).
|
|
6
|
-
*
|
|
7
|
-
* A missing URL or key yields `not_configured` (the section is silently
|
|
8
|
-
* skipped in `all` mode). An `http://` URL to a non-loopback host is refused
|
|
9
|
-
* at query time — see {@link loadCpConfig}.
|
|
10
|
-
*/
|
|
11
|
-
export declare const ENV_URL = "CLIPROXY_URL";
|
|
12
|
-
export declare const ENV_KEY = "CLIPROXY_MANAGEMENT_KEY";
|
|
13
|
-
export interface CpConfig {
|
|
14
|
-
/** Base URL, no trailing slash/path (e.g. `https://cp.example.com:8317`). */
|
|
15
|
-
url: string;
|
|
16
|
-
/** Management key (`remote-management.secret-key`). */
|
|
17
|
-
key: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Resolve the endpoint + key. Blank strings count as absent. The URL gets a
|
|
21
|
-
* trailing-slash trim so `https://host/` still works.
|
|
22
|
-
*/
|
|
23
|
-
export declare function loadCpConfig(): CpConfig | null;
|
|
24
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/quota/cliproxy/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,eAAO,MAAM,OAAO,iBAAiB,CAAC;AACtC,eAAO,MAAM,OAAO,4BAA4B,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,QAAQ,GAAG,IAAI,CAM9C"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI credential discovery — the same convention as the Ollama card:
|
|
3
|
-
* config file first (`~/.config/zcode-acp/config.json` `quota.cliproxyUrl` +
|
|
4
|
-
* `quota.cliproxyManagementKey`), env vars as a full fallback
|
|
5
|
-
* (`CLIPROXY_URL` / `CLIPROXY_MANAGEMENT_KEY`).
|
|
6
|
-
*
|
|
7
|
-
* A missing URL or key yields `not_configured` (the section is silently
|
|
8
|
-
* skipped in `all` mode). An `http://` URL to a non-loopback host is refused
|
|
9
|
-
* at query time — see {@link loadCpConfig}.
|
|
10
|
-
*/
|
|
11
|
-
import process from "node:process";
|
|
12
|
-
import { loadUserConfig } from "../../config/user-config.js";
|
|
13
|
-
export const ENV_URL = "CLIPROXY_URL";
|
|
14
|
-
export const ENV_KEY = "CLIPROXY_MANAGEMENT_KEY";
|
|
15
|
-
/**
|
|
16
|
-
* Resolve the endpoint + key. Blank strings count as absent. The URL gets a
|
|
17
|
-
* trailing-slash trim so `https://host/` still works.
|
|
18
|
-
*/
|
|
19
|
-
export function loadCpConfig() {
|
|
20
|
-
const quota = loadUserConfig().quota;
|
|
21
|
-
const url = (quota?.cliproxyUrl ?? process.env[ENV_URL] ?? "").trim().replace(/\/+$/, "");
|
|
22
|
-
const key = (quota?.cliproxyManagementKey ?? process.env[ENV_KEY] ?? "").trim();
|
|
23
|
-
if (!url || !key)
|
|
24
|
-
return null;
|
|
25
|
-
return { url, key };
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AASjD;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,KAAK,GAAG,cAAc,EAAE,CAAC,KAAK,CAAC;IACrC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1F,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,qBAAqB,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAChF,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI quota rendering — pool-wide rows: every Gemini subscription's
|
|
3
|
-
* usage aggregated per model family and window (`5h` / `Week`), each row
|
|
4
|
-
* stamped with that window's EARLIEST reset across accounts (when capacity
|
|
5
|
-
* starts coming back). Same bar style as the other sections so the combined
|
|
6
|
-
* card reads as one piece. Non-Gemini providers the proxy routes are
|
|
7
|
-
* summarised in a single trailing count line.
|
|
8
|
-
*/
|
|
9
|
-
import type { CpQueryResult } from "./types.js";
|
|
10
|
-
export declare function formatCpSection(result: CpQueryResult, color?: boolean,
|
|
11
|
-
/** Count of non-Gemini accounts routed by the proxy, for the tail line. */
|
|
12
|
-
otherAccounts?: number,
|
|
13
|
-
/** Clock for the cached-age stamp (tests inject; default real time). */
|
|
14
|
-
now?: () => number): {
|
|
15
|
-
header: string;
|
|
16
|
-
body: string[];
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=format.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/quota/cliproxy/format.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAahD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,KAAK,UAAQ;AACb,2EAA2E;AAC3E,aAAa,SAAI;AACjB,wEAAwE;AACxE,GAAG,GAAE,MAAM,MAAyB,GACnC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CA2CpC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI quota rendering — pool-wide rows: every Gemini subscription's
|
|
3
|
-
* usage aggregated per model family and window (`5h` / `Week`), each row
|
|
4
|
-
* stamped with that window's EARLIEST reset across accounts (when capacity
|
|
5
|
-
* starts coming back). Same bar style as the other sections so the combined
|
|
6
|
-
* card reads as one piece. Non-Gemini providers the proxy routes are
|
|
7
|
-
* summarised in a single trailing count line.
|
|
8
|
-
*/
|
|
9
|
-
import { aggregateCpFamilies } from "./aggregate.js";
|
|
10
|
-
import { pickOverlay, renderColorBar } from "../color.js";
|
|
11
|
-
import { formatResetTime, renderBar } from "../format.js";
|
|
12
|
-
import { roundTenth } from "../rounding.js";
|
|
13
|
-
/** `3m`-style age for the cached-stale header stamp. */
|
|
14
|
-
function formatAge(ms) {
|
|
15
|
-
const minutes = Math.floor(ms / 60_000);
|
|
16
|
-
if (minutes >= 60)
|
|
17
|
-
return `${Math.floor(minutes / 60)}h${minutes % 60 || ""}`;
|
|
18
|
-
return `${minutes}m`;
|
|
19
|
-
}
|
|
20
|
-
function windowLabel(window) {
|
|
21
|
-
return window === "5h" ? "5h" : "Week";
|
|
22
|
-
}
|
|
23
|
-
export function formatCpSection(result, color = false,
|
|
24
|
-
/** Count of non-Gemini accounts routed by the proxy, for the tail line. */
|
|
25
|
-
otherAccounts = 0,
|
|
26
|
-
/** Clock for the cached-age stamp (tests inject; default real time). */
|
|
27
|
-
now = () => Date.now()) {
|
|
28
|
-
// The section's 5-minute server-side-of-the-card TTL means values can lag
|
|
29
|
-
// the rest of the card by minutes (see ../index.js TTL_MS) — stamp the age
|
|
30
|
-
// so a motionless number reads as cached, not broken.
|
|
31
|
-
const ageMs = result.kind === "success" ? now() - result.fetchedAt : 0;
|
|
32
|
-
const header = ageMs > 90_000 ? `CLIProxy · ${formatAge(ageMs)} old` : "CLIProxy";
|
|
33
|
-
if (result.kind !== "success") {
|
|
34
|
-
const msg = result.kind === "not_configured"
|
|
35
|
-
? "not configured (set quota.cliproxyUrl + quota.cliproxyManagementKey)"
|
|
36
|
-
: result.kind === "auth_error"
|
|
37
|
-
? "auth failed — check the management key"
|
|
38
|
-
: "unavailable";
|
|
39
|
-
return { header, body: [msg] };
|
|
40
|
-
}
|
|
41
|
-
if (result.accounts.length === 0) {
|
|
42
|
-
return { header, body: ["no Gemini accounts on this proxy"] };
|
|
43
|
-
}
|
|
44
|
-
const body = [];
|
|
45
|
-
for (const family of aggregateCpFamilies(result.accounts)) {
|
|
46
|
-
const label = family.name.slice(0, 22);
|
|
47
|
-
for (const [index, w] of family.windows.entries()) {
|
|
48
|
-
const pct = roundTenth(w.used * 100);
|
|
49
|
-
// Continuation rows (2nd window, 2nd family…) indent under the label.
|
|
50
|
-
const name = index === 0 ? label.padEnd(22) : " ".repeat(22);
|
|
51
|
-
const window = windowLabel(w.window).padEnd(5);
|
|
52
|
-
const reset = formatResetTime(w.resetAt);
|
|
53
|
-
const trailing = reset ? ` · ${reset}` : "";
|
|
54
|
-
if (color) {
|
|
55
|
-
const bar = renderColorBar(pct, { overlay: pickOverlay({ usedPercent: pct }) });
|
|
56
|
-
body.push(`${name}${window}${bar}${trailing}`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
body.push(`${name}${window}${renderBar(pct)} ${String(pct).padStart(2)}%${trailing}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (body.length === 0) {
|
|
64
|
-
return { header, body: ["no quota buckets reported"] };
|
|
65
|
-
}
|
|
66
|
-
if (otherAccounts > 0) {
|
|
67
|
-
body.push(` + ${otherAccounts} non-Gemini account${otherAccounts > 1 ? "s" : ""}`);
|
|
68
|
-
}
|
|
69
|
-
return { header, body };
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/format.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,wDAAwD;AACxD,SAAS,SAAS,CAAC,EAAU;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACxC,IAAI,OAAO,IAAI,EAAE;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,OAAO,GAAG,EAA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AC;QACH,CAAC;IACH,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,2BAA2B,CAAC,EAAE,CAAC;IACzD,CAAC;IACD,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,WAAW,aAAa,sBAAsB,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI quota orchestration — the entry used by `zcode-acp quota cp`
|
|
3
|
-
* and the combined card.
|
|
4
|
-
*
|
|
5
|
-
* Flow: config (file → env) → plain-HTTP guard → cache → credentials listing
|
|
6
|
-
* → per-Gemini-account quota relay (parallel across accounts, three upstream
|
|
7
|
-
* URL variants in order) → parse → cache. Account-level failures degrade to
|
|
8
|
-
* that account's omission; a failed listing degrades the whole section — but
|
|
9
|
-
* a transient failure never evicts the last SUCCESS from the display (see
|
|
10
|
-
* `queryCpUsage`).
|
|
11
|
-
*
|
|
12
|
-
* Never throws — the CLI always produces output.
|
|
13
|
-
*/
|
|
14
|
-
import type { CpQueryResult } from "./types.js";
|
|
15
|
-
/** Result carrying the non-Gemini account count for the renderer's tail. */
|
|
16
|
-
export interface CpQueryOutcome {
|
|
17
|
-
result: CpQueryResult;
|
|
18
|
-
/** Credential entries whose provider is not Gemini (codex/claude/…). */
|
|
19
|
-
otherCount: number;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Drop the cached outcomes. NOT wired into the CLI watch tick on purpose —
|
|
23
|
-
* clearing it per tick would restore the 30s poll this TTL exists to prevent.
|
|
24
|
-
* Tests use it to force a fresh query.
|
|
25
|
-
*/
|
|
26
|
-
export declare function clearCpCache(): void;
|
|
27
|
-
/**
|
|
28
|
-
* Query the remote CLIProxyAPI. Returns `{result, otherCount}` so the caller
|
|
29
|
-
* can render the codex/claude tail without a second listing.
|
|
30
|
-
*
|
|
31
|
-
* STICKY LAST-SUCCESS: a transient failure (`unavailable` — listing timeout,
|
|
32
|
-
* relay failures) never evicts the last successful outcome from the display;
|
|
33
|
-
* the stale success keeps its original `fetchedAt`, so the card header stamps
|
|
34
|
-
* its age honestly (observed 2026-11-10: the credentials listing times out
|
|
35
|
-
* intermittently and one blip blanked the Gemini quota for the whole TTL).
|
|
36
|
-
* `auth_error` (wrong management key) is durable and actionable — it still
|
|
37
|
-
* surfaces.
|
|
38
|
-
*/
|
|
39
|
-
export declare function queryCpUsage(): Promise<CpQueryOutcome>;
|
|
40
|
-
export { formatCpSection } from "./format.js";
|
|
41
|
-
export { loadCpConfig, ENV_KEY, ENV_URL } from "./config.js";
|
|
42
|
-
export { ANTIGRAVITY_PROVIDER, parseCredentialEntries, parseQuotaSummary } from "./parse.js";
|
|
43
|
-
export type { CpAccountQuota, CpModelQuota, CpQueryResult, CpWindow, CpWindowQuota, } from "./types.js";
|
|
44
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/quota/cliproxy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhE,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,aAAa,CAAC;IACtB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;CACpB;AAyBD;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAGnC;AAsBD;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,cAAc,CAAC,CAkE5D;AAED,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7F,YAAY,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,aAAa,GACd,MAAM,YAAY,CAAC"}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLIProxyAPI quota orchestration — the entry used by `zcode-acp quota cp`
|
|
3
|
-
* and the combined card.
|
|
4
|
-
*
|
|
5
|
-
* Flow: config (file → env) → plain-HTTP guard → cache → credentials listing
|
|
6
|
-
* → per-Gemini-account quota relay (parallel across accounts, three upstream
|
|
7
|
-
* URL variants in order) → parse → cache. Account-level failures degrade to
|
|
8
|
-
* that account's omission; a failed listing degrades the whole section — but
|
|
9
|
-
* a transient failure never evicts the last SUCCESS from the display (see
|
|
10
|
-
* `queryCpUsage`).
|
|
11
|
-
*
|
|
12
|
-
* Never throws — the CLI always produces output.
|
|
13
|
-
*/
|
|
14
|
-
import { log } from "../../utils.js";
|
|
15
|
-
import { fetchCredentials, fetchQuotaSummary } from "./client.js";
|
|
16
|
-
import { loadCpConfig } from "./config.js";
|
|
17
|
-
import { ANTIGRAVITY_PROVIDER, parseCredentialEntries, parseQuotaSummary, relayUpstreamBody, relayUpstreamStatus, } from "./parse.js";
|
|
18
|
-
/**
|
|
19
|
-
* Success TTL — deliberately MUCH longer than the other providers (10s): the
|
|
20
|
-
* Gemini quota summary rides `v1internal:retrieveUserQuotaSummary`, a Google
|
|
21
|
-
* INTERNAL endpoint reached with the account's own OAuth token, so every
|
|
22
|
-
* refresh is charged to that Google account. High-frequency polling risks
|
|
23
|
-
* rate-limiting or account-level risk flags, and quota buckets move at
|
|
24
|
-
* minute-scale anyway. This TTL is the rate guard NO MATTER how often the
|
|
25
|
-
* caller polls (watch mode's 30s ticks included — they must not clear this
|
|
26
|
-
* cache; see `clearCpCache`).
|
|
27
|
-
*/
|
|
28
|
-
const TTL_MS = 5 * 60_000;
|
|
29
|
-
/**
|
|
30
|
-
* Failure re-entry gate: a failed sweep is retried at most once a minute, so
|
|
31
|
-
* the dock's 60s tick cannot turn a down proxy into a poll storm — but unlike
|
|
32
|
-
* the success TTL it is short, so a single blip recovers on the next tick
|
|
33
|
-
* instead of blanking the card for the whole 5 minutes.
|
|
34
|
-
*/
|
|
35
|
-
const FAILURE_RETRY_MS = 60_000;
|
|
36
|
-
/** Last SUCCESSFUL outcome — the only record allowed on the display path. */
|
|
37
|
-
let lastSuccess = null;
|
|
38
|
-
/** Last failed sweep and when it happened (drives the retry gate + sticky). */
|
|
39
|
-
let lastFailure = null;
|
|
40
|
-
/**
|
|
41
|
-
* Drop the cached outcomes. NOT wired into the CLI watch tick on purpose —
|
|
42
|
-
* clearing it per tick would restore the 30s poll this TTL exists to prevent.
|
|
43
|
-
* Tests use it to force a fresh query.
|
|
44
|
-
*/
|
|
45
|
-
export function clearCpCache() {
|
|
46
|
-
lastSuccess = null;
|
|
47
|
-
lastFailure = null;
|
|
48
|
-
}
|
|
49
|
-
async function queryOneAccount(base, key, entry) {
|
|
50
|
-
try {
|
|
51
|
-
const relay = await fetchQuotaSummary(base, key, entry.authIndex, entry.projectId);
|
|
52
|
-
if (!relay)
|
|
53
|
-
return null;
|
|
54
|
-
if (relayUpstreamStatus(relay.text) !== 200)
|
|
55
|
-
return null;
|
|
56
|
-
const body = relayUpstreamBody(relay.text);
|
|
57
|
-
if (body === undefined)
|
|
58
|
-
return null;
|
|
59
|
-
const models = parseQuotaSummary(body);
|
|
60
|
-
if (models.length === 0)
|
|
61
|
-
return null;
|
|
62
|
-
return { label: entry.label, provider: ANTIGRAVITY_PROVIDER, models };
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
log(`cliproxy: account ${entry.authIndex} quota relay failed (${String(e)})`);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Query the remote CLIProxyAPI. Returns `{result, otherCount}` so the caller
|
|
71
|
-
* can render the codex/claude tail without a second listing.
|
|
72
|
-
*
|
|
73
|
-
* STICKY LAST-SUCCESS: a transient failure (`unavailable` — listing timeout,
|
|
74
|
-
* relay failures) never evicts the last successful outcome from the display;
|
|
75
|
-
* the stale success keeps its original `fetchedAt`, so the card header stamps
|
|
76
|
-
* its age honestly (observed 2026-11-10: the credentials listing times out
|
|
77
|
-
* intermittently and one blip blanked the Gemini quota for the whole TTL).
|
|
78
|
-
* `auth_error` (wrong management key) is durable and actionable — it still
|
|
79
|
-
* surfaces.
|
|
80
|
-
*/
|
|
81
|
-
export async function queryCpUsage() {
|
|
82
|
-
if (lastSuccess && Date.now() - lastSuccess.at < TTL_MS) {
|
|
83
|
-
log("cliproxy: serving cached result");
|
|
84
|
-
return lastSuccess.outcome;
|
|
85
|
-
}
|
|
86
|
-
if (lastFailure && Date.now() - lastFailure.at < FAILURE_RETRY_MS) {
|
|
87
|
-
if (lastFailure.outcome.result.kind === "unavailable" && lastSuccess) {
|
|
88
|
-
log("cliproxy: serving the last success after a failed sweep");
|
|
89
|
-
return lastSuccess.outcome;
|
|
90
|
-
}
|
|
91
|
-
return lastFailure.outcome;
|
|
92
|
-
}
|
|
93
|
-
const cfg = loadCpConfig();
|
|
94
|
-
if (!cfg)
|
|
95
|
-
return { result: { kind: "not_configured" }, otherCount: 0 };
|
|
96
|
-
// The management key relays credential-bearing upstream calls — refuse a
|
|
97
|
-
// plaintext connection to anything but loopback (an SSH tunnel is the
|
|
98
|
-
// recommended way to reach a plain-HTTP instance).
|
|
99
|
-
if (cfg.url.startsWith("http://") && !/^http:\/\/(127\.|localhost|\[::1\])/.test(cfg.url)) {
|
|
100
|
-
log("cliproxy: refusing plain-HTTP management URL to a non-loopback host (use https or an SSH tunnel)");
|
|
101
|
-
return { result: { kind: "unavailable" }, otherCount: 0 };
|
|
102
|
-
}
|
|
103
|
-
let outcome;
|
|
104
|
-
try {
|
|
105
|
-
const resp = await fetchCredentials(cfg.url, cfg.key);
|
|
106
|
-
if (resp.status === 401 || resp.status === 403) {
|
|
107
|
-
outcome = { result: { kind: "auth_error" }, otherCount: 0 };
|
|
108
|
-
}
|
|
109
|
-
else if (resp.status !== 200) {
|
|
110
|
-
log(`cliproxy: unexpected status ${resp.status}`);
|
|
111
|
-
outcome = { result: { kind: "unavailable" }, otherCount: 0 };
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
const entries = parseCredentialEntries(resp.text);
|
|
115
|
-
const gemini = entries.filter((e) => e.provider === ANTIGRAVITY_PROVIDER);
|
|
116
|
-
const accounts = (await Promise.all(gemini.map((e) => queryOneAccount(cfg.url, cfg.key, e)))).filter((a) => a !== null);
|
|
117
|
-
// Every Gemini account failing its relay reads as "unreachable quota",
|
|
118
|
-
// not as an empty success — with accounts present but none answering,
|
|
119
|
-
// the honest row is an error line.
|
|
120
|
-
outcome = {
|
|
121
|
-
result: gemini.length > 0 && accounts.length === 0
|
|
122
|
-
? { kind: "unavailable" }
|
|
123
|
-
: { kind: "success", accounts, fetchedAt: Date.now() },
|
|
124
|
-
otherCount: entries.length - gemini.length,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (e) {
|
|
129
|
-
log(`cliproxy: fetch failed (${e instanceof Error ? e.message : String(e)})`);
|
|
130
|
-
outcome = { result: { kind: "unavailable" }, otherCount: 0 };
|
|
131
|
-
}
|
|
132
|
-
if (outcome.result.kind === "success") {
|
|
133
|
-
lastSuccess = { outcome, at: Date.now() };
|
|
134
|
-
lastFailure = null;
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
lastFailure = { outcome, at: Date.now() };
|
|
138
|
-
if (outcome.result.kind === "unavailable" && lastSuccess) {
|
|
139
|
-
log("cliproxy: sweep failed — serving the last successful result");
|
|
140
|
-
return lastSuccess.outcome;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return outcome;
|
|
144
|
-
}
|
|
145
|
-
export { formatCpSection } from "./format.js";
|
|
146
|
-
export { loadCpConfig, ENV_KEY, ENV_URL } from "./config.js";
|
|
147
|
-
export { ANTIGRAVITY_PROVIDER, parseCredentialEntries, parseQuotaSummary } from "./parse.js";
|
|
148
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAUpB;;;;;;;;;GASG;AACH,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC;AAC1B;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,6EAA6E;AAC7E,IAAI,WAAW,GAAmD,IAAI,CAAC;AACvE,+EAA+E;AAC/E,IAAI,WAAW,GAAmD,IAAI,CAAC;AAEvE;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,WAAW,GAAG,IAAI,CAAC;IACnB,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED,KAAK,UAAU,eAAe,CAC5B,IAAY,EACZ,GAAW,EACX,KAA+D;IAE/D,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;QACnF,IAAI,CAAC,KAAK;YAA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AAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAC1C,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa,IAAI,WAAW,EAAE,CAAC;YACzD,GAAG,CAAC,6DAA6D,CAAC,CAAC;YACnE,OAAO,WAAW,CAAC,OAAO,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parsers for the two CLIProxyAPI response shapes. Both are reconstructed
|
|
3
|
-
* from the v8.0.28 source + CPAMC web-UI readers (undocumented on the wire) —
|
|
4
|
-
* every field is read defensively: missing/odd shapes degrade to empty, never
|
|
5
|
-
* throw. The management API accepts both camelCase and snake_case INPUT, but
|
|
6
|
-
* its OUTPUT spelling is not contractual, so both variants are read.
|
|
7
|
-
*/
|
|
8
|
-
import type { CpModelQuota, CpWindow, CpWindowQuota } from "./types.js";
|
|
9
|
-
/** Antigravity accounts' provider id in the credentials listing (CPAMC's own
|
|
10
|
-
* quota support is antigravity-only — there is no separate gemini provider). */
|
|
11
|
-
export declare const ANTIGRAVITY_PROVIDER = "antigravity";
|
|
12
|
-
/** A parsed credential entry — only the fields the quota flow needs. */
|
|
13
|
-
export interface CpCredentialEntry {
|
|
14
|
-
authIndex: string;
|
|
15
|
-
provider: string;
|
|
16
|
-
label: string;
|
|
17
|
-
projectId?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Parse the credentials listing. The response is an array of entries (the
|
|
21
|
-
* field-carrying object may nest one level under `auth_files`/`credentials`/
|
|
22
|
-
* `files` on some builds), each with `auth_index`/`authIndex` and
|
|
23
|
-
* `provider`. The Gemini quota relay needs the account's CloudCode project
|
|
24
|
-
* id: `file.project_id` → `metadata` → `attributes` → the entry itself
|
|
25
|
-
* (CPAMC's resolution ladder).
|
|
26
|
-
*/
|
|
27
|
-
export declare function parseCredentialEntries(text: string): CpCredentialEntry[];
|
|
28
|
-
/**
|
|
29
|
-
* Parse one relayed `retrieveUserQuotaSummary` body into per-family windowed
|
|
30
|
-
* rows.
|
|
31
|
-
*
|
|
32
|
-
* Shape (live-verified 2026-10, CPAMC `builders.ts`): `{groups: [{displayName,
|
|
33
|
-
* buckets: [{window, remainingFraction, resetTime, …}]}]}` — each group is a
|
|
34
|
-
* model family ("Gemini Models", "Claude and GPT models") with one bucket per
|
|
35
|
-
* window. Bucket `window` spellings normalize to `5h` / `week` (CPAMC's
|
|
36
|
-
* accepted spellings); buckets with an unknown window or an out-of-range
|
|
37
|
-
* fraction are dropped. Multiple buckets sharing a window keep the TIGHTEST.
|
|
38
|
-
* Missing/odd fields degrade to empty, never throw.
|
|
39
|
-
*/
|
|
40
|
-
export declare function parseQuotaSummary(bodyText: string): CpModelQuota[];
|
|
41
|
-
/** Convenience: the relay envelope's upstream status (200 unless malformed). */
|
|
42
|
-
export declare function relayUpstreamStatus(text: string): number;
|
|
43
|
-
/** Convenience: the relay envelope's upstream body (a STRING inside). */
|
|
44
|
-
export declare function relayUpstreamBody(text: string): string | undefined;
|
|
45
|
-
export type { CpModelQuota, CpWindow, CpWindowQuota };
|
|
46
|
-
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/quota/cliproxy/parse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExE;iFACiF;AACjF,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAgBlD,wEAAwE;AACxE,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,EAAE,CA4CxE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAuClE;AAoBD,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOlE;AAED,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC"}
|