zcode-acp-server 0.43.2 → 0.43.4
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.map +1 -1
- package/dist/bin/quota.js +4 -3
- package/dist/bin/quota.js.map +1 -1
- package/dist/code-fingerprint.json +1 -1
- package/dist/config/user-config.d.ts +3 -0
- package/dist/config/user-config.d.ts.map +1 -1
- package/dist/config/user-config.js +1 -0
- package/dist/config/user-config.js.map +1 -1
- package/dist/handlers/session.d.ts +29 -2
- package/dist/handlers/session.d.ts.map +1 -1
- package/dist/handlers/session.js +107 -22
- package/dist/handlers/session.js.map +1 -1
- package/dist/quota/format.d.ts.map +1 -1
- package/dist/quota/format.js +6 -2
- package/dist/quota/format.js.map +1 -1
- package/dist/quota/opencode-go/client.d.ts +17 -16
- package/dist/quota/opencode-go/client.d.ts.map +1 -1
- package/dist/quota/opencode-go/client.js +25 -27
- package/dist/quota/opencode-go/client.js.map +1 -1
- package/dist/quota/opencode-go/config.d.ts +14 -9
- package/dist/quota/opencode-go/config.d.ts.map +1 -1
- package/dist/quota/opencode-go/config.js +14 -9
- package/dist/quota/opencode-go/config.js.map +1 -1
- package/dist/quota/opencode-go/format.js +2 -2
- package/dist/quota/opencode-go/format.js.map +1 -1
- package/dist/quota/opencode-go/index.d.ts +10 -10
- package/dist/quota/opencode-go/index.d.ts.map +1 -1
- package/dist/quota/opencode-go/index.js +42 -28
- package/dist/quota/opencode-go/index.js.map +1 -1
- package/dist/quota/opencode-go/parse.d.ts +17 -28
- package/dist/quota/opencode-go/parse.d.ts.map +1 -1
- package/dist/quota/opencode-go/parse.js +52 -66
- package/dist/quota/opencode-go/parse.js.map +1 -1
- package/dist/quota/opencode-go/types.d.ts +8 -9
- package/dist/quota/opencode-go/types.d.ts.map +1 -1
- package/dist/quota/opencode-go/types.js +6 -5
- package/dist/quota/opencode-go/types.js.map +1 -1
- package/dist/remote/endpoint.d.ts.map +1 -1
- package/dist/remote/endpoint.js +10 -0
- package/dist/remote/endpoint.js.map +1 -1
- package/dist/remote/hub-server.d.ts.map +1 -1
- package/dist/remote/hub-server.js +54 -20
- package/dist/remote/hub-server.js.map +1 -1
- package/docs/PROTOCOL.md +11 -0
- package/package.json +1 -1
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Opencode Go
|
|
2
|
+
* Opencode Go status HTTP client.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The Go dashboard moved off the legacy SSR page (`/workspace/<id>/go` — that
|
|
5
|
+
* URL now bounces EVERY cookie to the login page, observed 2026-09-19) onto
|
|
6
|
+
* the console at `https://opencode.ai/console/<org>/go`, backed by this JSON
|
|
7
|
+
* API. Usage arrives as micro-cents meter pairs per window; the parser turns
|
|
8
|
+
* them into percent + countdown.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Auth needs THREE pieces (verified against the live API 2026-09-19): the
|
|
11
|
+
* `auth` cookie, the `__Host-console_session` cookie, and the `x-org-id`
|
|
12
|
+
* header. Missing session cookie → 401, missing org header → 400; any
|
|
13
|
+
* User-Agent works (one is sent for parity with the console's own requests).
|
|
12
14
|
*/
|
|
13
|
-
/** Request timeout (ms).
|
|
15
|
+
/** Request timeout (ms). */
|
|
14
16
|
const TIMEOUT_MS = 10_000;
|
|
15
|
-
/**
|
|
16
|
-
* Browser-like User-Agent. opencode.ai returns a login redirect for
|
|
17
|
-
* unauthenticated requests; sending a real browser UA avoids any
|
|
18
|
-
* bot-detection short-circuit that would bypass the dashboard route.
|
|
19
|
-
*/
|
|
17
|
+
/** Browser-like User-Agent, mirroring the console's own XHR requests. */
|
|
20
18
|
const USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Gecko/20100101 Firefox/148.0";
|
|
21
|
-
/**
|
|
22
|
-
export function
|
|
23
|
-
return
|
|
19
|
+
/** The console status API endpoint (the org rides the `x-org-id` header). */
|
|
20
|
+
export function goStatusUrl() {
|
|
21
|
+
return "https://opencode.ai/console/api/go/status";
|
|
24
22
|
}
|
|
25
23
|
/**
|
|
26
|
-
* Fetch the Go
|
|
24
|
+
* Fetch the Go status JSON.
|
|
27
25
|
*
|
|
28
|
-
* @throws on
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* @throws on network errors or timeout; the caller maps these to
|
|
27
|
+
* `unavailable`. Auth failures are NOT thrown here — the HTTP status
|
|
28
|
+
* is returned so the orchestrator can classify 400/401/403 as
|
|
31
29
|
* `auth_error`.
|
|
32
30
|
*/
|
|
33
|
-
export async function
|
|
34
|
-
const
|
|
35
|
-
const resp = await fetchImpl(url, {
|
|
31
|
+
export async function fetchGoStatus(workspaceId, authCookie, sessionToken, fetchImpl = globalThis.fetch) {
|
|
32
|
+
const resp = await fetchImpl(goStatusUrl(), {
|
|
36
33
|
method: "GET",
|
|
37
34
|
headers: {
|
|
38
|
-
Cookie: `auth=${authCookie}`,
|
|
35
|
+
Cookie: `auth=${authCookie}; __Host-console_session=${sessionToken}`,
|
|
36
|
+
"x-org-id": workspaceId,
|
|
37
|
+
Accept: "application/json",
|
|
39
38
|
"User-Agent": USER_AGENT,
|
|
40
|
-
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
41
39
|
},
|
|
42
40
|
redirect: "follow",
|
|
43
41
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
44
42
|
});
|
|
45
43
|
const text = await resp.text();
|
|
46
|
-
return { status: resp.status, text
|
|
44
|
+
return { status: resp.status, text };
|
|
47
45
|
}
|
|
48
46
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,4BAA4B;AAC5B,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,yEAAyE;AACzE,MAAM,UAAU,GAAG,8EAA8E,CAAC;AAElG,6EAA6E;AAC7E,MAAM,UAAU,WAAW;IACzB,OAAO,2CAA2C,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,WAAmB,EACnB,UAAkB,EAClB,YAAoB,EACpB,YAAqC,UAAU,CAAC,KAAK;IAErD,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,MAAM,EAAE,QAAQ,UAAU,4BAA4B,YAAY,EAAE;YACpE,UAAU,EAAE,WAAW;YACvB,MAAM,EAAE,kBAAkB;YAC1B,YAAY,EAAE,UAAU;SACzB;QACD,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC;KACxC,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -3,26 +3,31 @@
|
|
|
3
3
|
* fallback source.
|
|
4
4
|
*
|
|
5
5
|
* Full precedence (highest first), resolved in ../index.ts:
|
|
6
|
-
* 1. `quota.opencodeGoWorkspaceId` / `
|
|
7
|
-
* `~/.config/zcode-acp/config.json` (our own
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* 1. `quota.opencodeGoWorkspaceId` / `opencodeGoAuthCookie` /
|
|
7
|
+
* `opencodeGoSessionToken` in `~/.config/zcode-acp/config.json` (our own
|
|
8
|
+
* config).
|
|
9
|
+
* 2. `OPENCODE_GO_WORKSPACE_ID` / `OPENCODE_GO_AUTH_COOKIE` /
|
|
10
|
+
* `OPENCODE_GO_SESSION_TOKEN` env vars (best for CI / scripts /
|
|
11
|
+
* temporary overrides).
|
|
12
|
+
* 3. `~/.pi/agent/opencode-go.json` —
|
|
13
|
+
* `{ workspaceId, authCookie, sessionToken }` (the convention used by
|
|
14
|
+
* the @beyona/pi-zai-usage Pi extension, kept so users who already
|
|
15
|
+
* configured it there get reuse for free).
|
|
13
16
|
*
|
|
14
|
-
*
|
|
15
|
-
* `not_configured`.
|
|
17
|
+
* All three fields must resolve to a valid triple — a missing/invalid one
|
|
18
|
+
* yields `not_configured`.
|
|
16
19
|
*/
|
|
17
20
|
/** Env var names — documented in the CLI help and README. */
|
|
18
21
|
export declare const ENV_WORKSPACE_ID = "OPENCODE_GO_WORKSPACE_ID";
|
|
19
22
|
export declare const ENV_AUTH_COOKIE = "OPENCODE_GO_AUTH_COOKIE";
|
|
23
|
+
export declare const ENV_SESSION_TOKEN = "OPENCODE_GO_SESSION_TOKEN";
|
|
20
24
|
/** Config file path (matches the @beyona/pi-zai-usage convention). */
|
|
21
25
|
export declare const CONFIG_PATH: string;
|
|
22
26
|
/** Shape of the JSON config file. */
|
|
23
27
|
interface OpencodeGoConfig {
|
|
24
28
|
workspaceId?: string;
|
|
25
29
|
authCookie?: string;
|
|
30
|
+
sessionToken?: string;
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* Read (best-effort) the JSON config file. Returns an empty object on any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/quota/opencode-go/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/quota/opencode-go/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAQH,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;AAC3D,eAAO,MAAM,eAAe,4BAA4B,CAAC;AACzD,eAAO,MAAM,iBAAiB,8BAA8B,CAAC;AAE7D,sEAAsE;AACtE,eAAO,MAAM,WAAW,QAKvB,CAAC;AAEF,qCAAqC;AACrC,UAAU,gBAAgB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,GAAE,MAAoB,GAAG,gBAAgB,CAuB/E"}
|
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
* fallback source.
|
|
4
4
|
*
|
|
5
5
|
* Full precedence (highest first), resolved in ../index.ts:
|
|
6
|
-
* 1. `quota.opencodeGoWorkspaceId` / `
|
|
7
|
-
* `~/.config/zcode-acp/config.json` (our own
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* 1. `quota.opencodeGoWorkspaceId` / `opencodeGoAuthCookie` /
|
|
7
|
+
* `opencodeGoSessionToken` in `~/.config/zcode-acp/config.json` (our own
|
|
8
|
+
* config).
|
|
9
|
+
* 2. `OPENCODE_GO_WORKSPACE_ID` / `OPENCODE_GO_AUTH_COOKIE` /
|
|
10
|
+
* `OPENCODE_GO_SESSION_TOKEN` env vars (best for CI / scripts /
|
|
11
|
+
* temporary overrides).
|
|
12
|
+
* 3. `~/.pi/agent/opencode-go.json` —
|
|
13
|
+
* `{ workspaceId, authCookie, sessionToken }` (the convention used by
|
|
14
|
+
* the @beyona/pi-zai-usage Pi extension, kept so users who already
|
|
15
|
+
* configured it there get reuse for free).
|
|
13
16
|
*
|
|
14
|
-
*
|
|
15
|
-
* `not_configured`.
|
|
17
|
+
* All three fields must resolve to a valid triple — a missing/invalid one
|
|
18
|
+
* yields `not_configured`.
|
|
16
19
|
*/
|
|
17
20
|
import { readFileSync } from "node:fs";
|
|
18
21
|
import path from "node:path";
|
|
@@ -21,6 +24,7 @@ import { log } from "../../utils.js";
|
|
|
21
24
|
/** Env var names — documented in the CLI help and README. */
|
|
22
25
|
export const ENV_WORKSPACE_ID = "OPENCODE_GO_WORKSPACE_ID";
|
|
23
26
|
export const ENV_AUTH_COOKIE = "OPENCODE_GO_AUTH_COOKIE";
|
|
27
|
+
export const ENV_SESSION_TOKEN = "OPENCODE_GO_SESSION_TOKEN";
|
|
24
28
|
/** Config file path (matches the @beyona/pi-zai-usage convention). */
|
|
25
29
|
export const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE || "~", ".pi", "agent", "opencode-go.json");
|
|
26
30
|
/**
|
|
@@ -43,6 +47,7 @@ export function readConfigFile(filePath = CONFIG_PATH) {
|
|
|
43
47
|
return {
|
|
44
48
|
workspaceId: typeof cfg.workspaceId === "string" ? cfg.workspaceId : undefined,
|
|
45
49
|
authCookie: typeof cfg.authCookie === "string" ? cfg.authCookie : undefined,
|
|
50
|
+
sessionToken: typeof cfg.sessionToken === "string" ? cfg.sessionToken : undefined,
|
|
46
51
|
};
|
|
47
52
|
}
|
|
48
53
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAC3D,M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AAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,GAAG,CAAC,oCAAoC,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -55,9 +55,9 @@ export function formatGoSection(result, windows, now = Date.now(), color = false
|
|
|
55
55
|
const header = "Opencode Go";
|
|
56
56
|
if (result.kind !== "success") {
|
|
57
57
|
const msg = result.kind === "not_configured"
|
|
58
|
-
? "not configured (set
|
|
58
|
+
? "not configured (set quota.opencodeGo* or OPENCODE_GO_* — see zcode-acp quota --help)"
|
|
59
59
|
: result.kind === "auth_error"
|
|
60
|
-
? "auth expired — refresh your opencode.ai cookie"
|
|
60
|
+
? "auth expired — refresh your opencode.ai cookie + session token"
|
|
61
61
|
: "unavailable";
|
|
62
62
|
return { header, body: [msg] };
|
|
63
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/format.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,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,qDAAqD;AACrD,MAAM,WAAW,GAA+C;IAC9D,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE;IAC/B,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE;IAChC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH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AAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;QAChD,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,YAAY,EAAE;gBACzC,OAAO,EAAE,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC;aACtD,CAAC,CAAC;YACH,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,MAAM,KAAK,EAAE,CAAC;QAClD,CAAC;QACD,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACtC,sEAAsE;QACtE,mEAAmE;QACnE,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACvC,yEAAyE;QACzE,0EAA0E;QAC1E,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC,OAAO,KAAK,EAAE,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Opencode Go usage orchestration — the entry point used by the
|
|
3
|
-
* `zcode-acp quota` CLI.
|
|
3
|
+
* `zcode-acp quota` CLI and the quota dock.
|
|
4
4
|
*
|
|
5
|
-
* Flow: credentials (env + config file) → cache check → fetch →
|
|
5
|
+
* Flow: credentials (env + config file) → cache check → fetch → status/auth
|
|
6
6
|
* check → parse → cache write. Any thrown error degrades to `unavailable`
|
|
7
7
|
* rather than propagating, so the CLI always produces output.
|
|
8
8
|
*
|
|
9
|
-
* A missing/invalid credential
|
|
9
|
+
* A missing/invalid credential triple yields `not_configured`, which the
|
|
10
10
|
* combined view silently skips (vs. `unavailable`, which renders an error
|
|
11
11
|
* line) — so users who only care about GLM see no noise.
|
|
12
12
|
*/
|
|
13
13
|
import type { GoQueryResult } from "./types.js";
|
|
14
14
|
/**
|
|
15
|
-
* Query the Opencode Go
|
|
15
|
+
* Query the Opencode Go console status API and return a normalised
|
|
16
|
+
* {@link GoQueryResult}.
|
|
16
17
|
*
|
|
17
18
|
* - No credentials / invalid → `not_configured`.
|
|
18
19
|
* - Serves a cached result when fresh (< 10s).
|
|
19
|
-
* - HTTP
|
|
20
|
-
* → `auth_error`.
|
|
20
|
+
* - HTTP 400/401/403 → `auth_error` (bad/missing org id or cookie pair).
|
|
21
21
|
* - Network/timeout/parse failure → `unavailable`.
|
|
22
22
|
*/
|
|
23
23
|
export declare function queryGoUsage(): Promise<GoQueryResult>;
|
|
24
24
|
export { clearCache, clearCache as clearGoCache } from "./cache.js";
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
25
|
+
export { fetchGoStatus, goStatusUrl } from "./client.js";
|
|
26
|
+
export { parseGoStatus, looksLikeGoStatus } from "./parse.js";
|
|
27
27
|
export { formatDuration, formatGoSection } from "./format.js";
|
|
28
|
-
export { readConfigFile, CONFIG_PATH, ENV_WORKSPACE_ID, ENV_AUTH_COOKIE } from "./config.js";
|
|
29
|
-
export type { GoQueryResult, GoWindow, GoWindowKey,
|
|
28
|
+
export { readConfigFile, CONFIG_PATH, ENV_WORKSPACE_ID, ENV_AUTH_COOKIE, ENV_SESSION_TOKEN, } from "./config.js";
|
|
29
|
+
export type { GoQueryResult, GoWindow, GoWindowKey, GoStatusResponse } from "./types.js";
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/quota/opencode-go/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/quota/opencode-go/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAyDhD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,aAAa,CAAC,CAgD3D;AAGD,OAAO,EAAE,UAAU,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,46 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Opencode Go usage orchestration — the entry point used by the
|
|
3
|
-
* `zcode-acp quota` CLI.
|
|
3
|
+
* `zcode-acp quota` CLI and the quota dock.
|
|
4
4
|
*
|
|
5
|
-
* Flow: credentials (env + config file) → cache check → fetch →
|
|
5
|
+
* Flow: credentials (env + config file) → cache check → fetch → status/auth
|
|
6
6
|
* check → parse → cache write. Any thrown error degrades to `unavailable`
|
|
7
7
|
* rather than propagating, so the CLI always produces output.
|
|
8
8
|
*
|
|
9
|
-
* A missing/invalid credential
|
|
9
|
+
* A missing/invalid credential triple yields `not_configured`, which the
|
|
10
10
|
* combined view silently skips (vs. `unavailable`, which renders an error
|
|
11
11
|
* line) — so users who only care about GLM see no noise.
|
|
12
12
|
*/
|
|
13
13
|
import { loadUserConfig } from "../../config/user-config.js";
|
|
14
14
|
import { log } from "../../utils.js";
|
|
15
15
|
import { getCached, setCached } from "./cache.js";
|
|
16
|
-
import { ENV_AUTH_COOKIE, ENV_WORKSPACE_ID, readConfigFile } from "./config.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import { ENV_AUTH_COOKIE, ENV_SESSION_TOKEN, ENV_WORKSPACE_ID, readConfigFile } from "./config.js";
|
|
17
|
+
import { fetchGoStatus } from "./client.js";
|
|
18
|
+
import { parseGoStatus } from "./parse.js";
|
|
19
19
|
/** Format validators (match pi-go-bars conventions). */
|
|
20
20
|
const RE_WORKSPACE = /^wrk_[A-Za-z0-9]+$/;
|
|
21
21
|
const COOKIE_PREFIX = "Fe26.2**";
|
|
22
|
+
/** Minimum plausible session-token length (console `st_…` values). */
|
|
23
|
+
const MIN_SESSION_TOKEN = 8;
|
|
22
24
|
/**
|
|
23
25
|
* Resolve & validate credentials.
|
|
24
26
|
*
|
|
25
27
|
* Three sources, merged field-by-field with the standard user-config
|
|
26
28
|
* precedence (highest first):
|
|
27
|
-
* 1. `quota.opencodeGoWorkspaceId` / `
|
|
28
|
-
* `~/.config/zcode-acp/config.json` (our own
|
|
29
|
-
*
|
|
29
|
+
* 1. `quota.opencodeGoWorkspaceId` / `opencodeGoAuthCookie` /
|
|
30
|
+
* `opencodeGoSessionToken` in `~/.config/zcode-acp/config.json` (our own
|
|
31
|
+
* config — preferred home).
|
|
32
|
+
* 2. `OPENCODE_GO_WORKSPACE_ID` / `OPENCODE_GO_AUTH_COOKIE` /
|
|
33
|
+
* `OPENCODE_GO_SESSION_TOKEN` env vars.
|
|
30
34
|
* 3. `~/.pi/agent/opencode-go.json` (legacy — the @beyona/pi-zai-usage Pi
|
|
31
35
|
* extension convention, kept so existing setups keep working).
|
|
32
36
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* The session token is REQUIRED since the 2026-09 console migration: the
|
|
38
|
+
* status API answers 401 to an `auth` cookie alone. A field present in a
|
|
39
|
+
* higher-precedence source overrides the same field below it; a field present
|
|
40
|
+
* only lower down still counts. Returns `null` when the resolved triple is
|
|
41
|
+
* incomplete or malformed — `queryGoUsage` maps that to `not_configured`.
|
|
37
42
|
*/
|
|
38
43
|
function loadCredentials() {
|
|
39
44
|
const own = loadUserConfig().quota;
|
|
40
45
|
const file = readConfigFile();
|
|
41
46
|
const workspaceId = own?.opencodeGoWorkspaceId ?? process.env[ENV_WORKSPACE_ID] ?? file.workspaceId;
|
|
42
47
|
const authCookie = own?.opencodeGoAuthCookie ?? process.env[ENV_AUTH_COOKIE] ?? file.authCookie;
|
|
43
|
-
|
|
48
|
+
const sessionToken = own?.opencodeGoSessionToken ?? process.env[ENV_SESSION_TOKEN] ?? file.sessionToken;
|
|
49
|
+
if (!workspaceId || !authCookie || !sessionToken)
|
|
44
50
|
return null;
|
|
45
51
|
if (!RE_WORKSPACE.test(workspaceId)) {
|
|
46
52
|
log(`opencode-go: invalid workspaceId format (expected wrk_…)`);
|
|
@@ -50,15 +56,19 @@ function loadCredentials() {
|
|
|
50
56
|
log(`opencode-go: authCookie does not start with ${COOKIE_PREFIX}`);
|
|
51
57
|
return null;
|
|
52
58
|
}
|
|
53
|
-
|
|
59
|
+
if (sessionToken.trim().length < MIN_SESSION_TOKEN) {
|
|
60
|
+
log(`opencode-go: sessionToken looks malformed (__Host-console_session value, st_…)`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return { workspaceId, authCookie, sessionToken };
|
|
54
64
|
}
|
|
55
65
|
/**
|
|
56
|
-
* Query the Opencode Go
|
|
66
|
+
* Query the Opencode Go console status API and return a normalised
|
|
67
|
+
* {@link GoQueryResult}.
|
|
57
68
|
*
|
|
58
69
|
* - No credentials / invalid → `not_configured`.
|
|
59
70
|
* - Serves a cached result when fresh (< 10s).
|
|
60
|
-
* - HTTP
|
|
61
|
-
* → `auth_error`.
|
|
71
|
+
* - HTTP 400/401/403 → `auth_error` (bad/missing org id or cookie pair).
|
|
62
72
|
* - Network/timeout/parse failure → `unavailable`.
|
|
63
73
|
*/
|
|
64
74
|
export async function queryGoUsage() {
|
|
@@ -72,20 +82,24 @@ export async function queryGoUsage() {
|
|
|
72
82
|
return { kind: "not_configured" };
|
|
73
83
|
let result;
|
|
74
84
|
try {
|
|
75
|
-
const resp = await
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
85
|
+
const resp = await fetchGoStatus(creds.workspaceId, creds.authCookie, creds.sessionToken);
|
|
86
|
+
// 401/403 = bad cookie pair; 400 = missing/unknown org id (x-org-id).
|
|
87
|
+
// The remedy is the same for all three — re-grab credentials — so they
|
|
88
|
+
// share auth_error.
|
|
89
|
+
if (resp.status === 400 || resp.status === 401 || resp.status === 403) {
|
|
79
90
|
result = { kind: "auth_error" };
|
|
80
91
|
}
|
|
92
|
+
else if (resp.status < 200 || resp.status >= 300) {
|
|
93
|
+
result = { kind: "unavailable" };
|
|
94
|
+
}
|
|
81
95
|
else {
|
|
82
|
-
const parsed =
|
|
96
|
+
const parsed = parseGoStatus(resp.text);
|
|
83
97
|
if (parsed.parserOutdated) {
|
|
84
|
-
log("opencode-go:
|
|
98
|
+
log("opencode-go: status JSON recognised but no windows parsed (parser outdated)");
|
|
85
99
|
result = { kind: "unavailable" };
|
|
86
100
|
}
|
|
87
101
|
else if (!parsed.rolling && !parsed.weekly && !parsed.monthly) {
|
|
88
|
-
// Not a
|
|
102
|
+
// Not a status payload at all (e.g. an HTML error page).
|
|
89
103
|
result = { kind: "unavailable" };
|
|
90
104
|
}
|
|
91
105
|
else {
|
|
@@ -110,8 +124,8 @@ export async function queryGoUsage() {
|
|
|
110
124
|
}
|
|
111
125
|
// Re-exports for consumers (CLI + tests).
|
|
112
126
|
export { clearCache, clearCache as clearGoCache } from "./cache.js";
|
|
113
|
-
export {
|
|
114
|
-
export {
|
|
127
|
+
export { fetchGoStatus, goStatusUrl } from "./client.js";
|
|
128
|
+
export { parseGoStatus, looksLikeGoStatus } from "./parse.js";
|
|
115
129
|
export { formatDuration, formatGoSection } from "./format.js";
|
|
116
|
-
export { readConfigFile, CONFIG_PATH, ENV_WORKSPACE_ID, ENV_AUTH_COOKIE } from "./config.js";
|
|
130
|
+
export { readConfigFile, CONFIG_PATH, ENV_WORKSPACE_ID, ENV_AUTH_COOKIE, ENV_SESSION_TOKEN, } from "./config.js";
|
|
117
131
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/quota/opencode-go/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,wDAAwD;AACxD,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAC1C,MAAM,aAAa,GAAG,UAAU,CAAC;AAEjC,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B;;;;;;;;;;;;;;;;;;GAkBG;A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AAM,CAAC,OAAO,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;oBAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;oBAC3D,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;iBACtB,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,8BAA8B,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjF,MAAM,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IACnC,CAAC;IAED,SAAS,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0CAA0C;AAC1C,OAAO,EAAE,UAAU,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Opencode Go
|
|
2
|
+
* Opencode Go status JSON parser.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
4
|
+
* The console API (`/console/api/go/status`) returns meter pairs in
|
|
5
|
+
* micro-cents per window; we compute the percent (used/limit) and the reset
|
|
6
|
+
* countdown (resetsAt − now) here — the API gives absolute timestamps, the
|
|
7
|
+
* formatter wants a relative countdown captured at fetch time.
|
|
6
8
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* use the same approach as of 2026-08, but the format has no stability
|
|
13
|
-
* contract — a frontend change will silently break extraction, which is why
|
|
14
|
-
* {@link looksLikeDashboard} guards against parser rot.
|
|
9
|
+
* Window mapping:
|
|
10
|
+
* rolling ← meters.fiveHour (resetsAt is null while the window is idle → 0)
|
|
11
|
+
* weekly ← meters.week
|
|
12
|
+
* monthly ← meters.month (carries no resetsAt — anchored to access.endsAt,
|
|
13
|
+
* the subscription renewal instant)
|
|
15
14
|
*/
|
|
16
15
|
import type { GoWindow } from "./types.js";
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
* page). Used to distinguish "parser is outdated" from "no windows present".
|
|
20
|
-
*/
|
|
21
|
-
export declare function looksLikeDashboard(html: string): boolean;
|
|
22
|
-
/** Result of parsing the dashboard — each window is independently optional. */
|
|
23
|
-
export interface ParsedGoDashboard {
|
|
16
|
+
/** Result of parsing the status payload — each window is independently optional. */
|
|
17
|
+
export interface ParsedGoStatus {
|
|
24
18
|
rolling: GoWindow | null;
|
|
25
19
|
weekly: GoWindow | null;
|
|
26
20
|
monthly: GoWindow | null;
|
|
27
21
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
22
|
+
* True when the body parsed and carries the status shape but no window
|
|
23
|
+
* matched — the API layout changed (parser rot).
|
|
30
24
|
*/
|
|
31
25
|
parserOutdated: boolean;
|
|
32
26
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* `parserOutdated` is true when the page looks like a dashboard (contains the
|
|
37
|
-
* window variable names) but none of the three windows matched — signalling
|
|
38
|
-
* that the SolidJS hydration format has drifted.
|
|
39
|
-
*/
|
|
40
|
-
export declare function parseGoDashboard(html: string): ParsedGoDashboard;
|
|
27
|
+
/** Detect the status payload shape (`access.meters`) — the parser-rot guard. */
|
|
28
|
+
export declare function looksLikeGoStatus(parsed: unknown): boolean;
|
|
29
|
+
export declare function parseGoStatus(text: string, now?: number): ParsedGoStatus;
|
|
41
30
|
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/quota/opencode-go/parse.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/quota/opencode-go/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAU3C,oFAAoF;AACpF,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzB;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;CACzB;AAuBD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAG1D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,cAAc,CAsBpF"}
|