dsh-cliproxyapi-pro 1.8.0 → 1.9.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.en.md +38 -409
  3. package/README.md +38 -409
  4. package/lib/client.js +131 -28
  5. package/lib/host/accounts.js +176 -0
  6. package/lib/host/apply/agent-tool.js +406 -0
  7. package/lib/host/apply/commands.js +122 -0
  8. package/lib/host/apply/controller.js +105 -0
  9. package/lib/host/apply/http-routes.js +273 -0
  10. package/lib/host/apply/image-jobs.js +171 -0
  11. package/lib/host/apply/index.js +41 -0
  12. package/lib/host/apply/interpret.js +72 -0
  13. package/lib/host/apply/lifecycle.js +34 -0
  14. package/lib/host/apply/media-failures.js +68 -0
  15. package/lib/host/apply/media-service.js +202 -0
  16. package/lib/host/apply/quota-service.js +42 -0
  17. package/lib/host/apply/references.js +43 -0
  18. package/lib/host/apply/session-status.js +104 -0
  19. package/lib/host/apply/state.js +78 -0
  20. package/lib/host/apply/updates.js +55 -0
  21. package/lib/host/apply/video-command.js +152 -0
  22. package/lib/host/apply/video-edit.js +253 -0
  23. package/lib/host/apply/video-jobs.js +206 -0
  24. package/lib/host/apply-utils.js +39 -0
  25. package/lib/host/config.js +205 -0
  26. package/lib/host/controller.js +435 -0
  27. package/lib/host/discovery.js +295 -0
  28. package/lib/host/http-gate.js +144 -0
  29. package/lib/host/models.js +102 -0
  30. package/lib/host/mount-guard.js +56 -0
  31. package/lib/host/routes.js +165 -0
  32. package/lib/host/runtime.js +445 -0
  33. package/lib/host/state-store.js +39 -0
  34. package/lib/host/status-text.js +93 -0
  35. package/lib/index.js +17 -4330
  36. package/lib/media/agent-tool.js +255 -0
  37. package/lib/media/choice.js +83 -0
  38. package/lib/media/classify.js +65 -0
  39. package/lib/media/codec/fit.js +76 -0
  40. package/lib/media/codec/jpeg.js +158 -0
  41. package/lib/media/codec/png.js +102 -0
  42. package/lib/media/commands/parsing.js +269 -0
  43. package/lib/media/constants.js +46 -0
  44. package/lib/media/diagnose.js +134 -0
  45. package/lib/media/images.js +165 -0
  46. package/lib/media/index.js +29 -0
  47. package/lib/media/interpret.js +126 -0
  48. package/lib/media/job-store.js +99 -0
  49. package/lib/media/mp4.js +44 -0
  50. package/lib/media/output-files.js +59 -0
  51. package/lib/media/session-store.js +293 -0
  52. package/lib/media/settings.js +255 -0
  53. package/lib/media/util.js +45 -0
  54. package/lib/media/video.js +326 -0
  55. package/lib/quota/auth-state.js +33 -0
  56. package/lib/quota/constants.js +86 -0
  57. package/lib/quota/controller.js +467 -0
  58. package/lib/quota/helpers.js +325 -0
  59. package/lib/quota/index.js +19 -0
  60. package/lib/quota/management.js +216 -0
  61. package/lib/quota/matching.js +143 -0
  62. package/lib/quota/parsers.js +352 -0
  63. package/lib/quota/probes/billing.js +80 -0
  64. package/lib/quota/probes/google.js +120 -0
  65. package/lib/quota/probes/oauth.js +27 -0
  66. package/lib/quota/probes/plugin.js +18 -0
  67. package/lib/updater/constants.js +23 -0
  68. package/lib/updater/errors.js +8 -0
  69. package/lib/updater/index.js +11 -0
  70. package/lib/updater/registry.js +83 -0
  71. package/lib/updater/settings.js +45 -0
  72. package/lib/updater/store.js +23 -0
  73. package/lib/updater/updater.js +148 -0
  74. package/lib/updater/verify.js +110 -0
  75. package/lib/updater/version.js +31 -0
  76. package/locale/en.json +1 -1
  77. package/locale/zh.json +1 -1
  78. package/package.json +6 -9
  79. package/lib/media.js +0 -2528
  80. package/lib/quota.js +0 -1646
  81. package/lib/updater.js +0 -443
@@ -0,0 +1,326 @@
1
+ // CPA video submission, retrieval, state mapping and streamed downloads.
2
+ import { closeSync, mkdirSync, openSync, unlinkSync, writeSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { VIDEO_REQUEST_TIMEOUT_MS, VIDEO_DOWNLOAD_TIMEOUT_MS, MAX_VIDEO_JSON_BYTES, MAX_VIDEO_BYTES, VIDEO_GENERATION_BODY_MAX_BYTES, VIDEO_UPLOAD_BODY_MAX_BYTES, VIDEO_EDIT_MODEL, REQUEST_ID_PATTERN } from "./constants.js";
5
+ import { mediaAliasTarget } from "./classify.js";
6
+ import { MediaError, readBoundedText, upstreamMessage } from "./util.js";
7
+
8
+ // #region Video generation
9
+
10
+ /**
11
+ * Raw bytes each of `count` attached images may take so that a
12
+ * `/v1/videos/generations` body with this prompt stays within
13
+ * {@link VIDEO_GENERATION_BODY_MAX_BYTES} once base64-encoded.
14
+ */
15
+ export function videoImageBudget(prompt, count) {
16
+ if (!Number.isInteger(count) || count <= 0) return 0;
17
+ const fixed = 1024 + Buffer.byteLength(JSON.stringify(String(prompt ?? "")));
18
+ const room = VIDEO_GENERATION_BODY_MAX_BYTES - fixed - 64 * count;
19
+ return Math.max(0, Math.floor(room / count / 4) * 3);
20
+ }
21
+
22
+ /** The model id CPA's native video route accepts: `sora-2*` is an alias of Grok's video model there. */
23
+ export function videoRequestModel(modelId) {
24
+ return mediaAliasTarget(modelId) ?? modelId;
25
+ }
26
+
27
+ function authHeaders(apiKey, accept = "application/json") {
28
+ return {
29
+ Accept: accept,
30
+ ...(typeof apiKey === "string" && apiKey !== "" ? { Authorization: `Bearer ${apiKey}` } : {}),
31
+ };
32
+ }
33
+
34
+ async function videoJson(fetchImpl, url, init, signal, timeoutMs) {
35
+ const timeout = AbortSignal.timeout(timeoutMs);
36
+ const combined = signal === undefined ? timeout : AbortSignal.any([signal, timeout]);
37
+ let response;
38
+ let text;
39
+ try {
40
+ response = await fetchImpl(url, { ...init, signal: combined });
41
+ text = await readBoundedText(response, MAX_VIDEO_JSON_BYTES);
42
+ } catch (error) {
43
+ if (signal?.aborted) throw signal.reason;
44
+ if (timeout.aborted) throw new MediaError("timeout");
45
+ if (error instanceof MediaError) throw error;
46
+ throw new MediaError("network", error instanceof Error ? error.message.slice(0, 200) : undefined);
47
+ }
48
+ let payload;
49
+ try {
50
+ payload = JSON.parse(text);
51
+ } catch {
52
+ payload = undefined;
53
+ }
54
+ return { response, text, payload };
55
+ }
56
+
57
+ /**
58
+ * Submit one video through CPA's native xAI route `POST /v1/videos/generations`
59
+ * (fields `model`, `prompt`, `duration`, `aspect_ratio`, `resolution`,
60
+ * `image.url`; CPA passes them to xAI). An omitted ratio lets xAI choose
61
+ * (16:9, or the first frame's ratio). A submitted video cannot be cancelled.
62
+ * @param image - optional first frame `{ mediaType, data }`.
63
+ * @returns `{ requestId }`.
64
+ * @throws MediaError `upstream-error` (CPA refused; nothing was submitted), `invalid-response`, `network`, `timeout`.
65
+ */
66
+ const dataUrl = (image) => `data:${image.mediaType};base64,${Buffer.from(image.data).toString("base64")}`;
67
+
68
+ export async function submitVideo({ fetch: fetchImpl = fetch, rootURL, apiKey, model, prompt, seconds, aspect, resolution, image, lastFrame, references, signal }) {
69
+ const body = { model: videoRequestModel(model), prompt, duration: seconds };
70
+ if (aspect !== undefined) body.aspect_ratio = aspect;
71
+ if (resolution !== undefined) body.resolution = resolution;
72
+ if (image !== undefined) body.image = { url: dataUrl(image) };
73
+ if (lastFrame !== undefined) body.last_frame = { url: dataUrl(lastFrame) };
74
+ if (Array.isArray(references) && references.length > 0) body.reference_images = references.map((ref) => ({ url: dataUrl(ref) }));
75
+ return postVideoJob(fetchImpl, `${rootURL}/v1/videos/generations`, apiKey, body, signal, VIDEO_GENERATION_BODY_MAX_BYTES);
76
+ }
77
+
78
+ /**
79
+ * Edit (`POST /v1/videos/edits`) or extend (`POST /v1/videos/extensions`) any
80
+ * MP4: by URL (`sourceUrl` — xAI's own short-lived result link or a public
81
+ * http(s) address; xAI downloads it) or inline (`sourceData`, the file's bytes
82
+ * as a base64 data URI). Extensions take `duration` (2–10 s, the added part
83
+ * only); edits keep the source's length.
84
+ * @returns `{ requestId }`.
85
+ * @throws MediaError `request-too-large`, `route-unsupported`, `upstream-error`, …
86
+ */
87
+ export async function submitVideoEdit({ fetch: fetchImpl = fetch, rootURL, apiKey, mode, sourceUrl, sourceData, prompt, seconds, signal }) {
88
+ const url = sourceData !== undefined ? dataUrl({ mediaType: "video/mp4", data: sourceData }) : sourceUrl;
89
+ const body = { model: VIDEO_EDIT_MODEL, prompt, video: { url } };
90
+ if (mode === "extend" && seconds !== undefined) body.duration = seconds;
91
+ return postVideoJob(
92
+ fetchImpl,
93
+ `${rootURL}/v1/videos/${mode === "extend" ? "extensions" : "edits"}`,
94
+ apiKey,
95
+ body,
96
+ signal,
97
+ VIDEO_UPLOAD_BODY_MAX_BYTES,
98
+ sourceData !== undefined ? VIDEO_UPLOAD_TIMEOUT_MS : VIDEO_REQUEST_TIMEOUT_MS
99
+ );
100
+ }
101
+
102
+ const VIDEO_UPLOAD_TIMEOUT_MS = 5 * 60_000;
103
+
104
+ async function postVideoJob(fetchImpl, url, apiKey, body, signal, maxBodyBytes, timeoutMs = VIDEO_REQUEST_TIMEOUT_MS) {
105
+ const json = JSON.stringify(body);
106
+ const bytes = Buffer.byteLength(json);
107
+ // Refused here rather than upstream: CPA cools the credential down after some upstream errors.
108
+ if (maxBodyBytes !== undefined && bytes > maxBodyBytes) throw new MediaError("request-too-large", String(bytes));
109
+ const { response, text, payload } = await videoJson(
110
+ fetchImpl,
111
+ url,
112
+ { method: "POST", headers: { ...authHeaders(apiKey), "Content-Type": "application/json" }, body: json },
113
+ signal,
114
+ timeoutMs
115
+ );
116
+ // The upstream has no such route (seen for /v1/videos/extensions behind some CPA servers).
117
+ if (response.status === 405) throw new MediaError("route-unsupported", url.slice(url.lastIndexOf("/") + 1));
118
+ if ((response.status === 400 || response.status === 413) && /length limit exceeded|request body too large/i.test(text)) {
119
+ throw new MediaError("request-too-large", String(bytes));
120
+ }
121
+ if (!response.ok) throw new MediaError("upstream-error", upstreamMessage(text, response.status));
122
+ const requestId = String(payload?.request_id ?? payload?.id ?? "").trim();
123
+ if (!REQUEST_ID_PATTERN.test(requestId)) throw new MediaError("invalid-response");
124
+ return { requestId };
125
+ }
126
+
127
+ /** xAI / OpenAI video status words → `queued` / `running` / `done` / `failed`, or undefined. */
128
+ export function videoState(status) {
129
+ switch (String(status ?? "").trim().toLowerCase()) {
130
+ case "queued":
131
+ case "pending":
132
+ return "queued";
133
+ case "in_progress":
134
+ case "processing":
135
+ case "running":
136
+ return "running";
137
+ case "completed":
138
+ case "done":
139
+ case "succeeded":
140
+ case "success":
141
+ return "done";
142
+ case "failed":
143
+ case "error":
144
+ case "expired":
145
+ case "cancelled":
146
+ case "canceled":
147
+ return "failed";
148
+ default:
149
+ return undefined;
150
+ }
151
+ }
152
+
153
+ function videoFailure(payload) {
154
+ const error = payload?.error;
155
+ const message = typeof error === "string" ? error : typeof error?.message === "string" ? error.message : typeof payload?.code === "string" ? payload.code : "";
156
+ return String(message).replace(/https?:\/\/\S+/g, "[url]").replace(/\s+/g, " ").trim().slice(0, 300);
157
+ }
158
+
159
+ /**
160
+ * Ask CPA once about a submitted video (`GET /v1/videos/{request_id}`, the
161
+ * native xAI shape; CPA routes it to the credential that accepted it while
162
+ * its 3-hour binding lasts). A transient HTTP failure is reported as such so
163
+ * the caller can retry. A finished video's own short-lived HTTPS URL comes
164
+ * back as `sourceUrl` for edits / extensions only: the host keeps it in
165
+ * memory and never stores, logs or returns it.
166
+ * @returns `{ state, progress?, error?, seconds?, sourceUrl? }`; `state` is `queued` / `running` / `done` / `failed`.
167
+ * @throws MediaError `upstream-error` (with `status`), `invalid-response`, `network`, `timeout`.
168
+ */
169
+ export async function retrieveVideo({ fetch: fetchImpl = fetch, rootURL, apiKey, requestId, signal }) {
170
+ const { response, text, payload } = await videoJson(
171
+ fetchImpl,
172
+ `${rootURL}/v1/videos/${encodeURIComponent(requestId)}`,
173
+ { method: "GET", headers: authHeaders(apiKey) },
174
+ signal,
175
+ VIDEO_REQUEST_TIMEOUT_MS
176
+ );
177
+ if (!response.ok) {
178
+ const error = new MediaError("upstream-error", upstreamMessage(text, response.status));
179
+ error.status = response.status;
180
+ throw error;
181
+ }
182
+ if (payload === undefined || payload === null || typeof payload !== "object") throw new MediaError("invalid-response");
183
+ const failure = videoFailure(payload);
184
+ let state = videoState(payload.status);
185
+ if (state === undefined && typeof payload.video?.url === "string") state = "done";
186
+ if (failure !== "" && state !== "done") state = "failed";
187
+ if (state === undefined) state = "queued";
188
+ const progress = Number(payload.progress);
189
+ const seconds = Number(payload.video?.duration ?? payload.seconds);
190
+ let sourceUrl;
191
+ if (state === "done" && typeof payload.video?.url === "string") {
192
+ try {
193
+ const parsed = new URL(payload.video.url);
194
+ if (parsed.protocol === "https:" && !parsed.username && !parsed.password) sourceUrl = parsed.toString();
195
+ } catch {}
196
+ }
197
+ return {
198
+ state,
199
+ ...(sourceUrl === undefined ? {} : { sourceUrl }),
200
+ ...(Number.isFinite(progress) && progress >= 0 && progress <= 100 ? { progress: Math.round(progress) } : {}),
201
+ ...(state === "failed" ? { error: failure || "the video could not be generated" } : {}),
202
+ ...(Number.isFinite(seconds) && seconds > 0 ? { seconds: Math.round(seconds * 10) / 10 } : {}),
203
+ };
204
+ }
205
+
206
+ /** Container from magic bytes: MP4 / MOV (`ftyp`) or WebM / Matroska (EBML), or undefined. */
207
+ export function sniffVideoType(bytes) {
208
+ const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes ?? []);
209
+ if (b.length >= 12 && String.fromCharCode(...b.subarray(4, 8)) === "ftyp") {
210
+ return String.fromCharCode(...b.subarray(8, 10)) === "qt" ? { mediaType: "video/quicktime", ext: "mov" } : { mediaType: "video/mp4", ext: "mp4" };
211
+ }
212
+ if (b.length >= 4 && b[0] === 0x1a && b[1] === 0x45 && b[2] === 0xdf && b[3] === 0xa3) return { mediaType: "video/webm", ext: "webm" };
213
+ return undefined;
214
+ }
215
+
216
+ /**
217
+ * Download a finished video through CPA (`GET /openai/v1/videos/{id}/content`,
218
+ * which fetches xAI's file with the credential's own proxy; the plugin never
219
+ * contacts the upstream host) and stream it into `dir` without replacing a
220
+ * file. At most `maxBytes`; a partial file is removed.
221
+ * @returns the absolute path.
222
+ * @throws MediaError `upstream-error`, `video-too-large`, `invalid-video`, `write-failed`, `network`, `timeout`.
223
+ */
224
+ export async function downloadVideo({ fetch: fetchImpl = fetch, rootURL, apiKey, requestId, dir, stem, signal, maxBytes = MAX_VIDEO_BYTES, timeoutMs = VIDEO_DOWNLOAD_TIMEOUT_MS }) {
225
+ const timeout = AbortSignal.timeout(timeoutMs);
226
+ const combined = signal === undefined ? timeout : AbortSignal.any([signal, timeout]);
227
+ let response;
228
+ try {
229
+ response = await fetchImpl(`${rootURL}/openai/v1/videos/${encodeURIComponent(requestId)}/content`, {
230
+ method: "GET",
231
+ headers: authHeaders(apiKey, "video/*, application/octet-stream"),
232
+ signal: combined,
233
+ });
234
+ } catch (error) {
235
+ if (signal?.aborted) throw signal.reason;
236
+ if (timeout.aborted) throw new MediaError("timeout");
237
+ throw new MediaError("network", error instanceof Error ? error.message.slice(0, 200) : undefined);
238
+ }
239
+ if (!response.ok) {
240
+ let text = "";
241
+ try {
242
+ text = await readBoundedText(response, 64 * 1024);
243
+ } catch {}
244
+ throw new MediaError("upstream-error", upstreamMessage(text, response.status));
245
+ }
246
+ const declared = Number(response.headers?.get?.("content-length"));
247
+ if (Number.isFinite(declared) && declared > maxBytes) throw new MediaError("video-too-large");
248
+ mkdirSync(dir, { recursive: true });
249
+ const reader = typeof response.body?.getReader === "function" ? response.body.getReader() : undefined;
250
+ let first;
251
+ let pending = [];
252
+ try {
253
+ if (reader === undefined) {
254
+ first = new Uint8Array(await response.arrayBuffer());
255
+ } else {
256
+ // Read until the container header can be recognized.
257
+ let size = 0;
258
+ while (size < 16) {
259
+ const { done, value } = await reader.read();
260
+ if (done) break;
261
+ pending.push(value);
262
+ size += value.byteLength;
263
+ }
264
+ first = new Uint8Array(Buffer.concat(pending));
265
+ pending = [];
266
+ }
267
+ } catch (error) {
268
+ if (signal?.aborted) throw signal.reason;
269
+ if (timeout.aborted) throw new MediaError("timeout");
270
+ throw new MediaError("network", error instanceof Error ? error.message.slice(0, 200) : undefined);
271
+ }
272
+ const type = sniffVideoType(first);
273
+ if (type === undefined) {
274
+ await reader?.cancel().catch(() => {});
275
+ throw new MediaError("invalid-video");
276
+ }
277
+ let fd;
278
+ let path;
279
+ for (let attempt = 0; attempt < 100 && fd === undefined; attempt += 1) {
280
+ path = join(dir, attempt === 0 ? `${stem}.${type.ext}` : `${stem}-${attempt + 1}.${type.ext}`);
281
+ try {
282
+ fd = openSync(path, "wx");
283
+ } catch (error) {
284
+ if (error?.code !== "EEXIST") {
285
+ await reader?.cancel().catch(() => {});
286
+ throw new MediaError("write-failed", error?.code ?? undefined);
287
+ }
288
+ }
289
+ }
290
+ if (fd === undefined) {
291
+ await reader?.cancel().catch(() => {});
292
+ throw new MediaError("write-failed", "EEXIST");
293
+ }
294
+ let size = 0;
295
+ const write = (chunk) => {
296
+ size += chunk.byteLength;
297
+ if (size > maxBytes) throw new MediaError("video-too-large");
298
+ writeSync(fd, chunk);
299
+ };
300
+ try {
301
+ write(first);
302
+ if (reader !== undefined) {
303
+ for (;;) {
304
+ const { done, value } = await reader.read();
305
+ if (done) break;
306
+ write(value);
307
+ }
308
+ }
309
+ closeSync(fd);
310
+ fd = undefined;
311
+ return path;
312
+ } catch (error) {
313
+ await reader?.cancel().catch(() => {});
314
+ if (fd !== undefined) closeSync(fd);
315
+ try {
316
+ unlinkSync(path);
317
+ } catch {}
318
+ if (signal?.aborted) throw signal.reason;
319
+ if (timeout.aborted) throw new MediaError("timeout");
320
+ if (error instanceof MediaError) throw error;
321
+ if (typeof error?.code === "string") throw new MediaError("write-failed", error.code);
322
+ throw new MediaError("network", error instanceof Error ? error.message.slice(0, 200) : undefined);
323
+ }
324
+ }
325
+
326
+ // #endregion
@@ -0,0 +1,33 @@
1
+ // Persisted management-key rejection counts (quota-state.json); never holds a key.
2
+
3
+ // Consecutive management 401/403 answers after which automatic refresh stops
4
+ // (CPA bans the client address for 30 minutes after 5 failed attempts).
5
+ export const AUTH_FAILURE_LIMIT = 3;
6
+ export const QUOTA_AUTH_STATE_VERSION = 1;
7
+
8
+ export const AUTH_ERROR_CODES = ["unauthorized", "forbidden"];
9
+ const AUTH_ACCOUNT_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
10
+
11
+ /**
12
+ * The persisted management-key failure counts (`quota-state.json`):
13
+ * `{ version: 1, accounts: { [id]: { authFailures, errorCode, errorStatus?, failedAt } } }`.
14
+ * Never holds a key. Invalid entries are dropped; accounts without failures are not kept.
15
+ */
16
+ export function normalizeQuotaAuthState(raw) {
17
+ const accounts = {};
18
+ const input = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw.accounts : undefined;
19
+ if (input !== null && typeof input === "object" && !Array.isArray(input)) {
20
+ for (const [id, entry] of Object.entries(input)) {
21
+ if (!AUTH_ACCOUNT_ID.test(id) || entry === null || typeof entry !== "object") continue;
22
+ const failures = Number.isInteger(entry.authFailures) && entry.authFailures > 0 ? Math.min(entry.authFailures, 1000) : 0;
23
+ if (failures === 0) continue;
24
+ accounts[id] = {
25
+ authFailures: failures,
26
+ errorCode: AUTH_ERROR_CODES.includes(entry.errorCode) ? entry.errorCode : "unauthorized",
27
+ ...(Number.isInteger(entry.errorStatus) ? { errorStatus: entry.errorStatus } : {}),
28
+ ...(typeof entry.failedAt === "string" && entry.failedAt.length <= 40 ? { failedAt: entry.failedAt } : {}),
29
+ };
30
+ }
31
+ }
32
+ return { version: QUOTA_AUTH_STATE_VERSION, accounts };
33
+ }
@@ -0,0 +1,86 @@
1
+ // Quota timing, normalization labels, and upstream protocol constants.
2
+ export const QUOTA_TTL_MS = 30 * 60 * 1000;
3
+ export const DEFAULT_QUOTA_TIMEOUT_MS = 15_000;
4
+ export const DEFAULT_QUOTA_CONCURRENCY = 4;
5
+ export const MAX_QUOTA_RESPONSE_BYTES = 4 * 1024 * 1024;
6
+
7
+ export const MANAGEMENT_KEY_REF = "CLI_PROXY_MANAGEMENT_KEY";
8
+ export const STATUS_MESSAGE_MAX = 160;
9
+
10
+ export const UPSTREAM = {
11
+ codexUsage: "https://chatgpt.com/backend-api/wham/usage",
12
+ claudeProfile: "https://api.anthropic.com/api/oauth/profile",
13
+ claudeUsage: "https://api.anthropic.com/api/oauth/usage",
14
+ googleLoad: "https://daily-cloudcode-pa.googleapis.com/v1internal:loadCodeAssist",
15
+ googleQuota: "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota",
16
+ // cloudcode-pa still serves the Gemini group; the daily/sandbox hosts may
17
+ // return only "Claude and GPT models". Summary hosts first, then the
18
+ // per-model fallbacks.
19
+ antigravityQuota: [
20
+ "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
21
+ "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
22
+ "https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:retrieveUserQuotaSummary",
23
+ ],
24
+ antigravityModels: [
25
+ "https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
26
+ "https://daily-cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
27
+ ],
28
+ kimiUsage: "https://api.kimi.com/coding/v1/usages",
29
+ // Kimi International (kimi.ai) accounts use the same API on another host.
30
+ kimiAiUsage: "https://api.kimi.ai/coding/v1/usages",
31
+ // Meta Muse Code subscription usage (needs the credential's dca_token).
32
+ metaUsage: "https://api.meta.ai/muse-code/key",
33
+ xaiBillingWeekly: "https://cli-chat-proxy.grok.com/v1/billing?format=credits",
34
+ xaiBillingMonthly: "https://cli-chat-proxy.grok.com/v1/billing",
35
+ // Connect RPC (JSON); the same call CPA's management center makes for Devin.
36
+ devinStatus: "https://server.codeium.com/exa.seat_management_pb.SeatManagementService/GetUserStatus",
37
+ };
38
+
39
+ // Client identity sent by CPA's management center; `$TOKEN$` is substituted
40
+ // by CPA's api-call with the credential's own session token.
41
+ export const DEVIN_METADATA = {
42
+ ideName: "chisel",
43
+ ideVersion: "3000.10.21",
44
+ apiKey: "$TOKEN$",
45
+ locale: "en",
46
+ os: "darwin",
47
+ extensionVersion: "3000.10.21",
48
+ clientName: "chisel",
49
+ };
50
+
51
+ export const AG_META = { ideType: "ANTIGRAVITY", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" };
52
+ export const GEMINI_META = { ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" };
53
+ export const AG_SUMMARY_UA = "antigravity/cli/1.0.13 (aidev_client; os_type=darwin; arch=arm64)";
54
+ export const AG_MODELS_UA = "antigravity/1.11.5 windows/amd64";
55
+ export const CODEX_UA = "codex_cli_rs/0.76.0 (Debian 13.0.0; x86_64) WindowsTerminal";
56
+
57
+ export const GROUP_CLAUDE_GPT = "Claude and GPT models";
58
+ export const GROUP_GEMINI = "Gemini models";
59
+ export const GROUP_OTHER = "Other models";
60
+
61
+ export const W5H = 5 * 60 * 60;
62
+ export const W1D = 24 * 60 * 60;
63
+ export const W7D = 7 * W1D;
64
+ export const KIND_RANK = { "5h": 0, "7d": 1, "30d": 2, "1d": 3, other: 4 };
65
+
66
+ export const PLAN_LABELS = {
67
+ free: "Free",
68
+ "free-tier": "Free",
69
+ "plan-free": "Free",
70
+ basic: "Basic",
71
+ standard: "Standard",
72
+ team: "Team",
73
+ "plan-team": "Team",
74
+ pro: "Pro",
75
+ "plan-pro": "Pro",
76
+ "g1-pro-tier": "Pro",
77
+ max: "Max",
78
+ "plan-max": "Max",
79
+ plus: "Plus",
80
+ ultra: "Ultra",
81
+ "g1-ultra-tier": "Ultra",
82
+ "ultra-lite": "Ultra Lite",
83
+ "g1-ultra-lite-tier": "Ultra Lite",
84
+ paid: "Paid",
85
+ enterprise: "Enterprise",
86
+ };