zcode-acp-server 0.85.2 → 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.
Files changed (74) hide show
  1. package/README.md +3 -1
  2. package/dist/bin/quota.d.ts +1 -1
  3. package/dist/bin/quota.d.ts.map +1 -1
  4. package/dist/bin/quota.js +5 -20
  5. package/dist/bin/quota.js.map +1 -1
  6. package/dist/code-fingerprint.json +2 -2
  7. package/dist/config/options.d.ts.map +1 -1
  8. package/dist/config/options.js +33 -7
  9. package/dist/config/options.js.map +1 -1
  10. package/dist/config/settings.d.ts +7 -0
  11. package/dist/config/settings.d.ts.map +1 -1
  12. package/dist/config/settings.js +15 -0
  13. package/dist/config/settings.js.map +1 -1
  14. package/dist/config/user-config.d.ts +9 -8
  15. package/dist/config/user-config.d.ts.map +1 -1
  16. package/dist/config/user-config.js +7 -2
  17. package/dist/config/user-config.js.map +1 -1
  18. package/dist/handlers/account.d.ts +3 -34
  19. package/dist/handlers/account.d.ts.map +1 -1
  20. package/dist/handlers/account.js +5 -38
  21. package/dist/handlers/account.js.map +1 -1
  22. package/dist/handlers/session.d.ts.map +1 -1
  23. package/dist/handlers/session.js +66 -4
  24. package/dist/handlers/session.js.map +1 -1
  25. package/dist/lazy-sessions.d.ts +9 -0
  26. package/dist/lazy-sessions.d.ts.map +1 -1
  27. package/dist/lazy-sessions.js +8 -0
  28. package/dist/lazy-sessions.js.map +1 -1
  29. package/dist/quota/combined.d.ts +1 -5
  30. package/dist/quota/combined.d.ts.map +1 -1
  31. package/dist/quota/combined.js +6 -24
  32. package/dist/quota/combined.js.map +1 -1
  33. package/dist/quota/format.d.ts +0 -9
  34. package/dist/quota/format.d.ts.map +1 -1
  35. package/dist/quota/format.js +0 -19
  36. package/dist/quota/format.js.map +1 -1
  37. package/dist/quota/live.d.ts.map +1 -1
  38. package/dist/quota/live.js +5 -12
  39. package/dist/quota/live.js.map +1 -1
  40. package/dist/remote/hub-server.d.ts.map +1 -1
  41. package/dist/remote/hub-server.js +3 -7
  42. package/dist/remote/hub-server.js.map +1 -1
  43. package/dist/server.d.ts +11 -0
  44. package/dist/server.d.ts.map +1 -1
  45. package/dist/server.js.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/quota/cliproxy/aggregate.d.ts +0 -48
  48. package/dist/quota/cliproxy/aggregate.d.ts.map +0 -1
  49. package/dist/quota/cliproxy/aggregate.js +0 -118
  50. package/dist/quota/cliproxy/aggregate.js.map +0 -1
  51. package/dist/quota/cliproxy/client.d.ts +0 -45
  52. package/dist/quota/cliproxy/client.d.ts.map +0 -1
  53. package/dist/quota/cliproxy/client.js +0 -140
  54. package/dist/quota/cliproxy/client.js.map +0 -1
  55. package/dist/quota/cliproxy/config.d.ts +0 -24
  56. package/dist/quota/cliproxy/config.d.ts.map +0 -1
  57. package/dist/quota/cliproxy/config.js +0 -27
  58. package/dist/quota/cliproxy/config.js.map +0 -1
  59. package/dist/quota/cliproxy/format.d.ts +0 -18
  60. package/dist/quota/cliproxy/format.d.ts.map +0 -1
  61. package/dist/quota/cliproxy/format.js +0 -71
  62. package/dist/quota/cliproxy/format.js.map +0 -1
  63. package/dist/quota/cliproxy/index.d.ts +0 -44
  64. package/dist/quota/cliproxy/index.d.ts.map +0 -1
  65. package/dist/quota/cliproxy/index.js +0 -148
  66. package/dist/quota/cliproxy/index.js.map +0 -1
  67. package/dist/quota/cliproxy/parse.d.ts +0 -46
  68. package/dist/quota/cliproxy/parse.d.ts.map +0 -1
  69. package/dist/quota/cliproxy/parse.js +0 -176
  70. package/dist/quota/cliproxy/parse.js.map +0 -1
  71. package/dist/quota/cliproxy/types.d.ts +0 -82
  72. package/dist/quota/cliproxy/types.d.ts.map +0 -1
  73. package/dist/quota/cliproxy/types.js +0 -33
  74. package/dist/quota/cliproxy/types.js.map +0 -1
@@ -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,EAAE,IAAI,EAAE,EAAE,CAAC;IAC9E,OAAO,GAAG,OAAO,GAAG,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,MAAqB;IACxC,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,e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AC,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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AM;aAC3C,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,2BAA2B,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC9E,OAAO,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IAC/D,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACtC,WAAW,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAC1C,WAAW,GAAG,IAAI,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,WAAW,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,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"}
@@ -1,176 +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
- /** Antigravity accounts' provider id in the credentials listing (CPAMC's own
9
- * quota support is antigravity-only — there is no separate gemini provider). */
10
- export const ANTIGRAVITY_PROVIDER = "antigravity";
11
- function asRecord(v) {
12
- return typeof v === "object" && v !== null && !Array.isArray(v)
13
- ? v
14
- : null;
15
- }
16
- function str(v) {
17
- return typeof v === "string" && v.trim().length > 0 ? v : undefined;
18
- }
19
- function num(v) {
20
- return typeof v === "number" && Number.isFinite(v) ? v : undefined;
21
- }
22
- /**
23
- * Parse the credentials listing. The response is an array of entries (the
24
- * field-carrying object may nest one level under `auth_files`/`credentials`/
25
- * `files` on some builds), each with `auth_index`/`authIndex` and
26
- * `provider`. The Gemini quota relay needs the account's CloudCode project
27
- * id: `file.project_id` → `metadata` → `attributes` → the entry itself
28
- * (CPAMC's resolution ladder).
29
- */
30
- export function parseCredentialEntries(text) {
31
- let parsed;
32
- try {
33
- parsed = JSON.parse(text);
34
- }
35
- catch {
36
- return [];
37
- }
38
- let arr = Array.isArray(parsed) ? parsed : null;
39
- if (!arr) {
40
- const doc = asRecord(parsed);
41
- if (doc) {
42
- for (const key of ["auth_files", "credentials", "files", "data"]) {
43
- if (Array.isArray(doc[key])) {
44
- arr = doc[key];
45
- break;
46
- }
47
- }
48
- }
49
- }
50
- if (!arr)
51
- return [];
52
- const entries = [];
53
- for (const raw of arr) {
54
- const e = asRecord(raw);
55
- if (!e)
56
- continue;
57
- const authIndex = str(e.auth_index ?? e.authIndex ?? e.id);
58
- const provider = str(e.provider ?? e.type) ?? "";
59
- if (!authIndex)
60
- continue;
61
- const file = asRecord(e.file);
62
- const metadata = asRecord(e.metadata);
63
- const attributes = asRecord(e.attributes);
64
- const email = str(file?.email) ?? str(metadata?.email) ?? str(attributes?.email) ?? str(e.email);
65
- entries.push({
66
- authIndex,
67
- provider,
68
- label: email ? email.split("@")[0] : authIndex,
69
- projectId: str(file?.project_id ?? file?.projectId) ??
70
- str(metadata?.project_id ?? metadata?.projectId) ??
71
- str(attributes?.project_id ?? attributes?.projectId) ??
72
- str(e.project_id ?? e.projectId),
73
- });
74
- }
75
- return entries;
76
- }
77
- /**
78
- * Parse one relayed `retrieveUserQuotaSummary` body into per-family windowed
79
- * rows.
80
- *
81
- * Shape (live-verified 2026-10, CPAMC `builders.ts`): `{groups: [{displayName,
82
- * buckets: [{window, remainingFraction, resetTime, …}]}]}` — each group is a
83
- * model family ("Gemini Models", "Claude and GPT models") with one bucket per
84
- * window. Bucket `window` spellings normalize to `5h` / `week` (CPAMC's
85
- * accepted spellings); buckets with an unknown window or an out-of-range
86
- * fraction are dropped. Multiple buckets sharing a window keep the TIGHTEST.
87
- * Missing/odd fields degrade to empty, never throw.
88
- */
89
- export function parseQuotaSummary(bodyText) {
90
- let parsed;
91
- try {
92
- parsed = JSON.parse(bodyText);
93
- }
94
- catch {
95
- return [];
96
- }
97
- const doc = asRecord(parsed);
98
- if (!doc || !Array.isArray(doc.groups))
99
- return [];
100
- const models = [];
101
- for (const [index, gRaw] of doc.groups.entries()) {
102
- const g = asRecord(gRaw);
103
- if (!g)
104
- continue;
105
- const name = str(g.displayName ?? g.display_name) ?? `Quota Group ${index + 1}`;
106
- // window → tightest bucket seen for it
107
- const tightest = new Map();
108
- if (Array.isArray(g.buckets)) {
109
- for (const bRaw of g.buckets) {
110
- const b = asRecord(bRaw);
111
- if (!b)
112
- continue;
113
- const window = windowOf(b.window);
114
- if (window === null)
115
- continue;
116
- const remaining = num(b.remainingFraction ?? b.remaining_fraction);
117
- if (remaining === undefined || remaining < 0 || remaining > 1)
118
- continue;
119
- const used = 1 - remaining;
120
- const prev = tightest.get(window);
121
- if (prev && prev.used >= used)
122
- continue;
123
- const resetRaw = str(b.resetTime ?? b.reset_time);
124
- const resetAt = resetRaw !== undefined ? Date.parse(resetRaw) : Number.NaN;
125
- tightest.set(window, {
126
- used,
127
- ...(Number.isFinite(resetAt) && { resetAt }),
128
- });
129
- }
130
- }
131
- if (tightest.size === 0)
132
- continue;
133
- models.push({ name, windows: orderWindows(tightest) });
134
- }
135
- return models;
136
- }
137
- /** Bucket window spellings → canonical window (mirrors CPAMC's
138
- * `antigravityPeriodHours` accepted spellings; anything else is dropped). */
139
- function windowOf(raw) {
140
- const v = typeof raw === "string" ? raw.trim().toLowerCase() : "";
141
- if (v === "5h" || v === "five-hour" || v === "five_hour")
142
- return "5h";
143
- if (v === "weekly" || v === "week")
144
- return "week";
145
- return null;
146
- }
147
- function orderWindows(tightest) {
148
- const out = [];
149
- for (const window of ["5h", "week"]) {
150
- const hit = tightest.get(window);
151
- if (hit)
152
- out.push({ window, ...hit });
153
- }
154
- return out;
155
- }
156
- /** Convenience: the relay envelope's upstream status (200 unless malformed). */
157
- export function relayUpstreamStatus(text) {
158
- try {
159
- const doc = asRecord(JSON.parse(text));
160
- return num(doc?.status_code ?? doc?.statusCode) ?? 200;
161
- }
162
- catch {
163
- return 200;
164
- }
165
- }
166
- /** Convenience: the relay envelope's upstream body (a STRING inside). */
167
- export function relayUpstreamBody(text) {
168
- try {
169
- const doc = asRecord(JSON.parse(text));
170
- return str(doc?.body);
171
- }
172
- catch {
173
- return undefined;
174
- }
175
- }
176
- //# sourceMappingURL=parse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/parse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;iFACiF;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAE,CAA6B;QAChC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,SAAS,GAAG,CAAC,CAAU;IACrB,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC;AAED,SAAS,GAAG,CAAC,CAAU;IACrB,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC;AAUD;;;;;;;GAOG;AAC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C,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACvC,OAAO,GAAG,CAAC,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,UAAU,CAAC,IAAI,GAAG,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACvC,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -1,82 +0,0 @@
1
- /**
2
- * Type definitions for the CLIProxyAPI quota feature.
3
- *
4
- * `zcode-acp quota cp` talks to a (typically REMOTE, user-deployed)
5
- * CLIProxyAPI instance's management API — the same channel its management web
6
- * UI uses (source-verified against CLIProxyAPI v8.0.28 + the CPAMC web UI,
7
- * 2026-10-14; see `.zcode/scratch/research-cliproxyapi-quota.md`):
8
- *
9
- * 1. `GET /v8/management/credentials` (v8 spelling; v0 servers answer
10
- * `GET /v0/management/auth-files`) — one entry per upstream OAuth
11
- * account. Gemini accounts are provider `antigravity`.
12
- * 2. For each Gemini account, `POST …/api-call` — a credential-scoped
13
- * upstream call relay: the proxy substitutes `$TOKEN$` in the header
14
- * with that account's OAuth token and forwards to
15
- * `daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary`
16
- * (CPAMC tries three URL variants in order). The response wraps the
17
- * upstream body: `{status_code, header, body}` with `body` a STRING.
18
- *
19
- * The management key is a shared secret that can drive credential-bearing
20
- * upstream calls — HTTPS is mandatory, never plain HTTP over a network.
21
- *
22
- * REFRESH CADENCE: the Gemini quota summary rides a Google INTERNAL endpoint
23
- * with the account's own OAuth token, so every refresh is charged to that
24
- * Google account. The orchestrator therefore caches for 5 MINUTES regardless
25
- * of caller cadence (watch mode's 30s ticks included — they do not clear
26
- * this cache), and the renderer stamps the section's age when serving
27
- * cached values.
28
- *
29
- * Everything here is undocumented/best-effort: parse failures degrade to
30
- * `unavailable`, never a crash.
31
- */
32
- /** Canonical quota window — bucket spellings normalize to these at parse time. */
33
- export type CpWindow = "5h" | "week";
34
- /** One window of one model family. */
35
- export interface CpWindowQuota {
36
- window: CpWindow;
37
- /** Used fraction [0, 1] — 1 minus the bucket's remainingFraction. */
38
- used: number;
39
- /** Reset moment of that window's tightest bucket (epoch ms), when reported. */
40
- resetAt?: number;
41
- }
42
- /** One model family's quota rows — one per reported window. */
43
- export interface CpModelQuota {
44
- /** Family display name (e.g. "Gemini Models"). */
45
- name: string;
46
- /** Per-window rows, `5h` before `week`. */
47
- windows: CpWindowQuota[];
48
- }
49
- /** One upstream account's quota block. */
50
- export interface CpAccountQuota {
51
- /** Short account label (email local-part, or the auth index). */
52
- label: string;
53
- /** Provider id from the credential entry — `antigravity` for Gemini. */
54
- provider: string;
55
- /** Per-model rows, tightest-first. Empty when the summary carried none. */
56
- models: CpModelQuota[];
57
- }
58
- /**
59
- * Result of querying CLIProxyAPI — a 4-state sum type mirroring
60
- * {@link ../ollama-cloud/types.js OcQueryResult}.
61
- *
62
- * `not_configured` = no URL/key resolved; the CLI silently skips the section
63
- * in all-provider mode. `success` with zero accounts = reachable server, no
64
- * Gemini accounts routed through it.
65
- */
66
- export type CpQueryResult = {
67
- kind: "success";
68
- accounts: CpAccountQuota[];
69
- fetchedAt: number;
70
- } | {
71
- kind: "not_configured";
72
- } | {
73
- kind: "auth_error";
74
- } | {
75
- kind: "unavailable";
76
- };
77
- /** Raw fetch result — status + body text (shared by both endpoints). */
78
- export interface CpResponse {
79
- status: number;
80
- text: string;
81
- }
82
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/quota/cliproxy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,kFAAkF;AAClF,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC;AAErC,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,+DAA+D;AAC/D,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAClE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAE5B,wEAAwE;AACxE,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd"}
@@ -1,33 +0,0 @@
1
- /**
2
- * Type definitions for the CLIProxyAPI quota feature.
3
- *
4
- * `zcode-acp quota cp` talks to a (typically REMOTE, user-deployed)
5
- * CLIProxyAPI instance's management API — the same channel its management web
6
- * UI uses (source-verified against CLIProxyAPI v8.0.28 + the CPAMC web UI,
7
- * 2026-10-14; see `.zcode/scratch/research-cliproxyapi-quota.md`):
8
- *
9
- * 1. `GET /v8/management/credentials` (v8 spelling; v0 servers answer
10
- * `GET /v0/management/auth-files`) — one entry per upstream OAuth
11
- * account. Gemini accounts are provider `antigravity`.
12
- * 2. For each Gemini account, `POST …/api-call` — a credential-scoped
13
- * upstream call relay: the proxy substitutes `$TOKEN$` in the header
14
- * with that account's OAuth token and forwards to
15
- * `daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary`
16
- * (CPAMC tries three URL variants in order). The response wraps the
17
- * upstream body: `{status_code, header, body}` with `body` a STRING.
18
- *
19
- * The management key is a shared secret that can drive credential-bearing
20
- * upstream calls — HTTPS is mandatory, never plain HTTP over a network.
21
- *
22
- * REFRESH CADENCE: the Gemini quota summary rides a Google INTERNAL endpoint
23
- * with the account's own OAuth token, so every refresh is charged to that
24
- * Google account. The orchestrator therefore caches for 5 MINUTES regardless
25
- * of caller cadence (watch mode's 30s ticks included — they do not clear
26
- * this cache), and the renderer stamps the section's age when serving
27
- * cached values.
28
- *
29
- * Everything here is undocumented/best-effort: parse failures degrade to
30
- * `unavailable`, never a crash.
31
- */
32
- export {};
33
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG"}