zcode-acp-server 0.82.3 → 0.83.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/dist/backend/resolve.d.ts +1 -0
- package/dist/backend/resolve.d.ts.map +1 -1
- package/dist/backend/resolve.js +97 -3
- package/dist/backend/resolve.js.map +1 -1
- package/dist/code-fingerprint.json +1 -1
- package/dist/config/account-provider.d.ts +16 -0
- package/dist/config/account-provider.d.ts.map +1 -1
- package/dist/config/account-provider.js +124 -1
- package/dist/config/account-provider.js.map +1 -1
- package/dist/handlers/server-requests.d.ts.map +1 -1
- package/dist/handlers/server-requests.js +11 -10
- package/dist/handlers/server-requests.js.map +1 -1
- package/dist/handlers/session.d.ts.map +1 -1
- package/dist/handlers/session.js +25 -4
- package/dist/handlers/session.js.map +1 -1
- package/dist/quota/cliproxy/index.d.ts +13 -3
- package/dist/quota/cliproxy/index.d.ts.map +1 -1
- package/dist/quota/cliproxy/index.js +46 -8
- package/dist/quota/cliproxy/index.js.map +1 -1
- package/docs/PROTOCOL.md +7 -1
- package/docs/TROUBLESHOOTING.md +17 -12
- package/package.json +1 -1
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* Flow: config (file → env) → plain-HTTP guard → cache → credentials listing
|
|
6
6
|
* → per-Gemini-account quota relay (parallel across accounts, three upstream
|
|
7
7
|
* URL variants in order) → parse → cache. Account-level failures degrade to
|
|
8
|
-
* that account's omission; a failed listing degrades the whole section
|
|
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`).
|
|
9
11
|
*
|
|
10
12
|
* Never throws — the CLI always produces output.
|
|
11
13
|
*/
|
|
@@ -14,7 +16,7 @@ import { fetchCredentials, fetchQuotaSummary } from "./client.js";
|
|
|
14
16
|
import { loadCpConfig } from "./config.js";
|
|
15
17
|
import { ANTIGRAVITY_PROVIDER, parseCredentialEntries, parseQuotaSummary, relayUpstreamBody, relayUpstreamStatus, } from "./parse.js";
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
19
|
+
* Success TTL — deliberately MUCH longer than the other providers (10s): the
|
|
18
20
|
* Gemini quota summary rides `v1internal:retrieveUserQuotaSummary`, a Google
|
|
19
21
|
* INTERNAL endpoint reached with the account's own OAuth token, so every
|
|
20
22
|
* refresh is charged to that Google account. High-frequency polling risks
|
|
@@ -24,14 +26,25 @@ import { ANTIGRAVITY_PROVIDER, parseCredentialEntries, parseQuotaSummary, relayU
|
|
|
24
26
|
* cache; see `clearCpCache`).
|
|
25
27
|
*/
|
|
26
28
|
const TTL_MS = 5 * 60_000;
|
|
27
|
-
let cached = null;
|
|
28
29
|
/**
|
|
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 —
|
|
30
42
|
* clearing it per tick would restore the 30s poll this TTL exists to prevent.
|
|
31
43
|
* Tests use it to force a fresh query.
|
|
32
44
|
*/
|
|
33
45
|
export function clearCpCache() {
|
|
34
|
-
|
|
46
|
+
lastSuccess = null;
|
|
47
|
+
lastFailure = null;
|
|
35
48
|
}
|
|
36
49
|
async function queryOneAccount(base, key, entry) {
|
|
37
50
|
try {
|
|
@@ -56,11 +69,26 @@ async function queryOneAccount(base, key, entry) {
|
|
|
56
69
|
/**
|
|
57
70
|
* Query the remote CLIProxyAPI. Returns `{result, otherCount}` so the caller
|
|
58
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.
|
|
59
80
|
*/
|
|
60
81
|
export async function queryCpUsage() {
|
|
61
|
-
if (
|
|
82
|
+
if (lastSuccess && Date.now() - lastSuccess.at < TTL_MS) {
|
|
62
83
|
log("cliproxy: serving cached result");
|
|
63
|
-
return
|
|
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;
|
|
64
92
|
}
|
|
65
93
|
const cfg = loadCpConfig();
|
|
66
94
|
if (!cfg)
|
|
@@ -101,7 +129,17 @@ export async function queryCpUsage() {
|
|
|
101
129
|
log(`cliproxy: fetch failed (${e instanceof Error ? e.message : String(e)})`);
|
|
102
130
|
outcome = { result: { kind: "unavailable" }, otherCount: 0 };
|
|
103
131
|
}
|
|
104
|
-
|
|
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
|
+
}
|
|
105
143
|
return outcome;
|
|
106
144
|
}
|
|
107
145
|
export { formatCpSection } from "./format.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/quota/cliproxy/index.ts"],"names":[],"mappings":"AAAA
|
|
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;YAAE,O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,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"}
|
package/docs/PROTOCOL.md
CHANGED
|
@@ -1097,7 +1097,13 @@ skipped from then on), so `session/list` reads, resume title re-emission, and
|
|
|
1097
1097
|
the desktop app's v4 projection all converge on the user's title.
|
|
1098
1098
|
`adoptStoredTitle` (load/resume) is pin-first: a sibling alias's known title,
|
|
1099
1099
|
then the durable `title_overridden` title, and only then the backend's stored
|
|
1100
|
-
title
|
|
1100
|
+
title (asked `session/list {sessionIds:[id]}` — the bare listing is only the
|
|
1101
|
+
50 most recent sessions across all workspaces, so older conversations need the
|
|
1102
|
+
by-id lookup; backends that reject the key fall back to the bare listing).
|
|
1103
|
+
The `/resume` slash command additionally broadcasts the adopted title as a
|
|
1104
|
+
`session_info_update`: editors derive a thread title from the first prompt —
|
|
1105
|
+
which for an adopting thread is the `/resume` command itself — and only a
|
|
1106
|
+
pushed title replaces that provisional name.
|
|
1101
1107
|
|
|
1102
1108
|
### `session/cancelBackgroundTask`
|
|
1103
1109
|
|
package/docs/TROUBLESHOOTING.md
CHANGED
|
@@ -115,8 +115,11 @@ log into the ZCode desktop app once so it exists. A coding-plan key added in
|
|
|
115
115
|
the desktop's Settings → Model Provider ("Use API key") counts too (#344): it
|
|
116
116
|
lands in `~/.zcode/v2/provider_config.json` as a
|
|
117
117
|
`zhipu-coding-plan-api-key` rule and the bridge reads it as an entitlement +
|
|
118
|
-
request-key source.
|
|
119
|
-
|
|
118
|
+
request-key source. On 3.15+ / 3.17.x OAuth installs where `~/.zcode/v2/credentials.json`
|
|
119
|
+
holds `zcodejwttoken` (0.17.x backends answer Start Plan without interaction —
|
|
120
|
+
the request-security edition disables per-request verification outright),
|
|
121
|
+
Start Plan (`account:<family>-start-plan`) is also entitled and served via
|
|
122
|
+
`startPlanRequestAuthFor`; keyless Start Plan requests stay declined (issue #123).
|
|
120
123
|
|
|
121
124
|
**Desktop 3.15+ after an OAuth sign-in:** the store holds no plan key at all,
|
|
122
125
|
only the sign-in (`oauth:<family>:access_token`), and `setting.json` records the
|
|
@@ -544,16 +547,18 @@ headless bridge has neither a browser nor the captcha credential. GLM Coding
|
|
|
544
547
|
Plan providers are unaffected — they use an `id.secret` API key and sign
|
|
545
548
|
requests themselves.
|
|
546
549
|
|
|
547
|
-
**Workaround:**
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
550
|
+
**Workaround:** sign in to the ZCode desktop app (3.15+ / 3.17.x) so
|
|
551
|
+
`~/.zcode/v2/credentials.json` holds both `oauth:<family>:access_token` and
|
|
552
|
+
`zcodejwttoken` — on 0.17.x backends (per-request verification disabled at the
|
|
553
|
+
edition level; the interactive branch is unreachable), the bridge
|
|
554
|
+
serves `zcodejwttoken` over `interaction/requestProviderRuntimeHeaders`
|
|
555
|
+
(`startPlanRequestAuthFor`) and injects `ZCODE_APP_VERSION` from the desktop
|
|
556
|
+
bundle (`builtinProviderEnv`), matching the desktop host's own
|
|
557
|
+
`AccountProviderRequestAuthService`. If no Start Plan credential is present on
|
|
558
|
+
disk (or if a future edition re-enables browser captcha), switch the session's
|
|
559
|
+
provider to a GLM Coding Plan one; the bridge answers with
|
|
560
|
+
`headersApplied:false` and the backend surfaces a clear error rather than
|
|
561
|
+
bypassing captcha checks (see #123, #363).
|
|
557
562
|
|
|
558
563
|
### Interactive TUI / `script` / `expect` fails with `Operation not permitted` under the sandbox
|
|
559
564
|
|