dsh-cliproxyapi-pro 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/lib/client.js +232 -15
- package/lib/host/accounts.js +4 -0
- package/lib/host/apply/controller.js +24 -0
- package/lib/host/apply-utils.js +2 -0
- package/lib/host/config.js +9 -0
- package/lib/host/controller.js +18 -0
- package/lib/host/prompt-sanitize.js +119 -0
- package/lib/index.js +1 -0
- package/lib/quota/constants.js +15 -7
- package/lib/quota/controller.js +1 -3
- package/lib/quota/matching.js +32 -3
- package/lib/quota/parsers.js +93 -27
- package/lib/quota/probes/google.js +69 -44
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
本插件的所有重要变更。版本号遵循[语义化版本](https://semver.org/lang/zh-CN/)。
|
|
6
6
|
|
|
7
|
+
## 1.12.0 — 2026-11-18
|
|
8
|
+
|
|
9
|
+
### 新增
|
|
10
|
+
- **提示词净化(兼容性)。** 每个账号的连接页「高级路由与规则过滤」新增开关(默认开启)与「替换文本」输入框:开启后,发往该账号三条路由的请求的系统提示词中,每个精确短语 “DeepSeek Harness”(不区分大小写)都整体替换为指定文本(默认 `Custom Harness`,开场白变为 “You are an AI agent powered by Custom Harness.”),并删除在上下文中同样会触发拦截的 “The browser provides no implicit DOM, route, or screenshot context.” 一句(Google 按内容综合判断,单独发送不拦、连同前后文才拦),规避部分上游网关(已确认 Antigravity 的 Gemini 账号)因此返回的无原因 429 以及 CPA 连带的全账号冷却。改写发生在提示词组装的最后阶段(`system-prompt/assemble` 瀑布),覆盖提示词分节与插值变量,只影响该账号自己的路由,已保存在会话中的提示词不变。升级前已有的账号同样默认开启,可在该开关处关闭。
|
|
11
|
+
|
|
12
|
+
### 修复
|
|
13
|
+
- **Antigravity 和 Gemini CLI 的套餐升级 / 降级后会及时更新。** 凭证已带项目 ID 时,原先只要显示过一次套餐就不再查询,比如从 Pro 升级到 Ultra 后仍一直显示 Pro。现在每轮额度刷新都会通过 `loadCodeAssist` 重新读取套餐,并以新读到的结果为准;这次读取失败时沿用上一次的套餐。代价是这两类凭证每轮刷新多一次很轻的 `loadCodeAssist` 请求。
|
|
14
|
+
- **Antigravity 的 Gemini 模型(如 `gemini-4-argon-high`)重新显示额度。** 额度汇总接口现在只返回「Claude and GPT models」一组,原先的补充查询只认 Gemini CLI 列出的模型,而且读的是生产主机(显示 100%,不随用量变化),所以这些模型一直显示「上游未返回额度窗口」。现在 Gemini 额度改从 CPA 实际走的 daily 主机的逐模型列表读取:同一族模型共用同一份额度时合成一个「Gemini models」窗口,按前缀匹配,列表里没有的 Gemini 型号也能对上;各模型额度不同时仍按模型分别显示。逐模型列表改用公开模型 ID(原先误用内部占位 ID,永远匹配不上),并跳过内部补全模型(`chat_*`、`tab_*`)。
|
|
15
|
+
- **Antigravity 额度读取与 CPA 自己一致。** 所有 Antigravity 额度请求改用 CPA 及其管理面板使用的 Antigravity Hub 标识(`antigravity/hub/2.23.0 darwin/arm64`;旧标识下汇总常缺「Gemini Models」组、也看不到较新的模型);汇总主机按管理面板的顺序 daily → daily sandbox → 生产依次尝试(生产主机的 Gemini 组常显示 100% 假额度),每类额度取最先给出它的主机,不再因为某一轮回退到生产主机就一直优先用它。来自 [@Six6stRINgs](https://github.com/Six6stRINgs) 的修复(#6)。
|
|
16
|
+
- **Gemini Argon 单独计额度时不再与其他 Gemini 模型混算。** Google AI Pro 等套餐的 Argon 额度独立于其他 Gemini 模型,原先 Argon 窗口按 `gemini` 前缀被一并算进常规 Gemini,对话框额度显示错误。现在 Argon 分组 / Argon 额度桶 / 逐模型列表里的 Argon 型号单独成窗口,Argon 模型只看自己的额度;套餐没有独立 Argon 额度时仍与 Gemini 共用。弹层里的分组名缩写为 Claude/GPT、Gemini、Argon,避免折行挤断百分比。来自 [@Six6stRINgs](https://github.com/Six6stRINgs) 的修复(#6)。
|
|
17
|
+
- **停用的 Antigravity 凭证不再挂到无关的 GPT / Claude 模型下。** 凭证停用后 CPA 不再报告它的模型列表,原先按「Claude and GPT models」分组名推断,结果所有 GPT / Claude 模型(如 `gpt-6-luna`)都显示了这个凭证。现在它只匹配同一账号里其他 Antigravity 凭证列出的模型;没有可参照的凭证时只匹配 Gemini 模型。来自 [@Six6stRINgs](https://github.com/Six6stRINgs) 的报告(#6)。
|
|
18
|
+
|
|
19
|
+
### 修复(界面优化)
|
|
20
|
+
- **设置页的 ⓘ 说明不再被对话框截断。** 说明气泡原先渲染在设置对话框的滚动区域内,靠近底部的行(如「提示词净化」)展开时下半截被裁掉。现在气泡通过浏览器的 Popover API 显示在顶层,可以超出对话框范围;按整个窗口定位,下方放不下时改到上方,左右超出窗口时自动收回,只有窗口都放不下时才限制高度并在气泡内滚动;滚动设置页时跟随按钮移动。气泡元素仍在插件自己的插槽内,不写入页面其他位置。
|
|
21
|
+
|
|
7
22
|
## 1.11.0 — 2026-11-12
|
|
8
23
|
|
|
9
24
|
### 新增
|
package/README.en.md
CHANGED
|
@@ -36,7 +36,7 @@ The plugin is published on npm as [`dsh-cliproxyapi-pro`](https://www.npmjs.com/
|
|
|
36
36
|
dsh-cliproxyapi-pro
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
To pin a version, write `dsh-cliproxyapi-pro@1.
|
|
39
|
+
To pin a version, write `dsh-cliproxyapi-pro@1.12.0`.
|
|
40
40
|
4. Click **Install**. When it finishes, the dialog offers to enable the plugin right away — accept it.
|
|
41
41
|
|
|
42
42
|
> If downloads are slow in mainland China, open **Registry** next to the input and choose **the mainland China mirror**.
|
|
@@ -65,7 +65,7 @@ In **Add plugin**, or as the `plugin_manager` `target`, you can also enter:
|
|
|
65
65
|
|
|
66
66
|
| Source | What to enter |
|
|
67
67
|
|---|---|
|
|
68
|
-
| A released version | `git+https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro.git#v1.
|
|
68
|
+
| A released version | `git+https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro.git#v1.12.0` |
|
|
69
69
|
| Latest development version | `git+https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro.git#main` |
|
|
70
70
|
| Offline package | Download [`dsh-cliproxyapi-pro.tgz`](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/releases/latest/download/dsh-cliproxyapi-pro.tgz) (always the latest release) and enter its absolute local path |
|
|
71
71
|
| Local source (development) | Absolute path of a cloned repository; installed as a link, so code changes go live when the plugin reloads |
|
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
dsh-cliproxyapi-pro
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
需要固定版本时可以写成 `dsh-cliproxyapi-pro@1.
|
|
39
|
+
需要固定版本时可以写成 `dsh-cliproxyapi-pro@1.12.0`。
|
|
40
40
|
4. 点击 **安装**,完成后点击 **立即启用**。
|
|
41
41
|
|
|
42
42
|
> 在中国大陆下载慢,可以点输入框旁的 **安装源**,切换到 **中国大陆镜像源**。
|
|
@@ -65,7 +65,7 @@ dsh plugin --profile <profile 名称> add dsh-cliproxyapi-pro
|
|
|
65
65
|
|
|
66
66
|
| 来源 | 填写内容 |
|
|
67
67
|
|---|---|
|
|
68
|
-
| 某个发布版本 | `git+https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro.git#v1.
|
|
68
|
+
| 某个发布版本 | `git+https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro.git#v1.12.0` |
|
|
69
69
|
| 最新开发版 | `git+https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro.git#main` |
|
|
70
70
|
| 离线安装包 | 下载 [`dsh-cliproxyapi-pro.tgz`](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/releases/latest/download/dsh-cliproxyapi-pro.tgz)(始终是最新版),填写它的本地绝对路径 |
|
|
71
71
|
| 本地源码(开发用) | 克隆后的仓库目录绝对路径;以链接方式安装,改代码后重载插件即生效 |
|
package/lib/client.js
CHANGED
|
@@ -8,7 +8,7 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
|
|
9
9
|
const React = require("react");
|
|
10
10
|
const h = React.createElement;
|
|
11
|
-
const { useState, useEffect, useCallback, useMemo, useRef } = React;
|
|
11
|
+
const { useState, useEffect, useLayoutEffect, useCallback, useMemo, useRef } = React;
|
|
12
12
|
|
|
13
13
|
const PACKAGE_NAME = "dsh-cliproxyapi-pro";
|
|
14
14
|
const MODULE_ID = "dsh-cliproxyapi-pro";
|
|
@@ -104,6 +104,10 @@ window.__ModuleLoader__.load({
|
|
|
104
104
|
excludePrefixLabel: "排除关键词",
|
|
105
105
|
excludePrefixPlaceholder: "例如: tts, image, video, zj/ (多个用逗号分隔)",
|
|
106
106
|
excludePrefixHint: "附加规则:排除包含指定关键词的模型 ID。",
|
|
107
|
+
sanitizePromptLabel: "提示词净化(兼容性)",
|
|
108
|
+
sanitizePromptHint: "部分上游(如 Antigravity 的 Gemini)会拒绝包含精确短语 “DeepSeek Harness” 的系统提示词并直接 429,CPA 还会据此给账号冷却。开启后,该账号请求的系统提示词中所有该短语会被整体替换为下面的文本,并删除已知会在上下文中触发拦截的语句(如 “The browser provides no implicit DOM, route, or screenshot context.”)。仅影响发往此账号的请求;对话历史中已有的提示词不受影响。",
|
|
109
|
+
sanitizePromptReplacementLabel: "替换文本",
|
|
110
|
+
sanitizePromptReplacementHint: "提示词中每个 “DeepSeek Harness” 短语整体替换为此文本,留空时使用默认值。例如开场白会变成 “You are an AI agent powered by <此文本>.”。",
|
|
107
111
|
refreshIntervalLabel: "自动刷新间隔",
|
|
108
112
|
searchModelsPlaceholder: "搜索模型 ID 或名称(如 claude-opus, gpt-6, gemini-4, swe)…",
|
|
109
113
|
filterAll: "全部发现",
|
|
@@ -647,6 +651,10 @@ window.__ModuleLoader__.load({
|
|
|
647
651
|
excludePrefixLabel: "Exclude Keywords",
|
|
648
652
|
excludePrefixPlaceholder: "e.g. tts, image, video, zj/ (comma-separated)",
|
|
649
653
|
excludePrefixHint: "Additional rule: hide models matching any of these substrings.",
|
|
654
|
+
sanitizePromptLabel: "Prompt Sanitizing (compat)",
|
|
655
|
+
sanitizePromptHint: "Some upstreams (e.g. Antigravity Gemini accounts) reject any system prompt containing the exact phrase \"DeepSeek Harness\" with an unexplained 429, and CPA cools the account down over it. When on, every occurrence of that phrase in the system prompt of requests routed to this account is replaced by the text below, and sentences known to trigger the block in context (such as \"The browser provides no implicit DOM, route, or screenshot context.\") are removed. History already carrying them is unchanged.",
|
|
656
|
+
sanitizePromptReplacementLabel: "Replacement Text",
|
|
657
|
+
sanitizePromptReplacementHint: "Every \"DeepSeek Harness\" phrase is replaced with this text as a whole; the default is used when blank. For example the opener becomes \"You are an AI agent powered by <this text>.\"",
|
|
650
658
|
refreshIntervalLabel: "Auto Refresh",
|
|
651
659
|
searchModelsPlaceholder: "Search model ID or name (e.g. claude-opus, gpt-6, gemini-4)…",
|
|
652
660
|
filterAll: "All Discovered",
|
|
@@ -2137,7 +2145,7 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2137
2145
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2138
2146
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2139
2147
|
}
|
|
2140
|
-
.dcpa-menu-pop::before
|
|
2148
|
+
.dcpa-menu-pop::before {
|
|
2141
2149
|
content: "";
|
|
2142
2150
|
position: absolute;
|
|
2143
2151
|
inset: 0;
|
|
@@ -2192,6 +2200,11 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2192
2200
|
max-width: 280px;
|
|
2193
2201
|
padding: 8px 10px;
|
|
2194
2202
|
border-radius: var(--dsw-radius-md, 10px);
|
|
2203
|
+
/* Painted on the bubble itself, not a ::before layer, so a capped bubble
|
|
2204
|
+
that scrolls its own text keeps its background (same fix as the quota
|
|
2205
|
+
popover). */
|
|
2206
|
+
background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-layer-1));
|
|
2207
|
+
backdrop-filter: var(--dsw-menu-backdrop-filter, none);
|
|
2195
2208
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2196
2209
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2197
2210
|
color: var(--dsw-alias-label-primary);
|
|
@@ -2200,8 +2213,21 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2200
2213
|
font-weight: 400;
|
|
2201
2214
|
white-space: normal;
|
|
2202
2215
|
text-align: left;
|
|
2216
|
+
overscroll-behavior: contain;
|
|
2203
2217
|
}
|
|
2204
|
-
|
|
2218
|
+
/* Top layer (Popover API): free of the Settings dialog's clipping; InfoTip
|
|
2219
|
+
writes fixed viewport top / left. Reset the UA popover box (centered,
|
|
2220
|
+
inset 0, auto margin, border). */
|
|
2221
|
+
.dcpa-info-pop[popover] {
|
|
2222
|
+
position: fixed;
|
|
2223
|
+
inset: auto;
|
|
2224
|
+
margin: 0;
|
|
2225
|
+
border: 0;
|
|
2226
|
+
overflow: visible;
|
|
2227
|
+
}
|
|
2228
|
+
/* In-place fallback without the Popover API. */
|
|
2229
|
+
.dcpa-info-pop[data-layer="inline"][data-align="end"] { left: auto; right: -8px; }
|
|
2230
|
+
.dcpa-info-pop[data-layer="inline"][data-place="above"] { top: auto; bottom: calc(100% + 6px); }
|
|
2205
2231
|
.dcpa-savebar {
|
|
2206
2232
|
position: sticky;
|
|
2207
2233
|
bottom: 0;
|
|
@@ -3413,25 +3439,148 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3413
3439
|
);
|
|
3414
3440
|
}
|
|
3415
3441
|
|
|
3442
|
+
// Gap between the help button and its bubble, the margin kept from the
|
|
3443
|
+
// edge of the visible area, and the smallest capped bubble height (px).
|
|
3444
|
+
const TIP_GAP = 6;
|
|
3445
|
+
const TIP_MARGIN = 8;
|
|
3446
|
+
const TIP_MIN_HEIGHT = 48;
|
|
3447
|
+
// The bubble's start edge sits this far before the button (matches the CSS).
|
|
3448
|
+
const TIP_INSET = 8;
|
|
3449
|
+
|
|
3450
|
+
function tipView() {
|
|
3451
|
+
return typeof window === "undefined" ? null : window;
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3454
|
+
/** Whether this browser can lift an in-slot element into the top layer. */
|
|
3455
|
+
function canUseTopLayer(pop) {
|
|
3456
|
+
return typeof pop?.showPopover === "function" && typeof pop?.setAttribute === "function";
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
/**
|
|
3460
|
+
* The area an in-place element can actually be seen in: the viewport
|
|
3461
|
+
* intersected with every ancestor that clips its overflow (the Settings
|
|
3462
|
+
* dialog body, scroll panes, popovers).
|
|
3463
|
+
*/
|
|
3464
|
+
function visibleBounds(el) {
|
|
3465
|
+
const view = tipView();
|
|
3466
|
+
let bounds = {
|
|
3467
|
+
top: 0,
|
|
3468
|
+
left: 0,
|
|
3469
|
+
right: view?.innerWidth ?? Infinity,
|
|
3470
|
+
bottom: view?.innerHeight ?? Infinity,
|
|
3471
|
+
};
|
|
3472
|
+
for (let node = el?.parentElement; node; node = node.parentElement) {
|
|
3473
|
+
const style = view?.getComputedStyle?.(node);
|
|
3474
|
+
if (!style) break;
|
|
3475
|
+
const clips = [style.overflow, style.overflowX, style.overflowY].some((v) => v && v !== "visible");
|
|
3476
|
+
if (!clips) continue;
|
|
3477
|
+
const r = node.getBoundingClientRect();
|
|
3478
|
+
bounds = {
|
|
3479
|
+
top: Math.max(bounds.top, r.top),
|
|
3480
|
+
left: Math.max(bounds.left, r.left),
|
|
3481
|
+
right: Math.min(bounds.right, r.right),
|
|
3482
|
+
bottom: Math.min(bounds.bottom, r.bottom),
|
|
3483
|
+
};
|
|
3484
|
+
}
|
|
3485
|
+
return bounds;
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
/**
|
|
3489
|
+
* Place an open bubble next to its help button, writing only the bubble's
|
|
3490
|
+
* own position styles and data attributes.
|
|
3491
|
+
*
|
|
3492
|
+
* In the top layer (`topLayer`), the bubble is free of every clipping
|
|
3493
|
+
* ancestor and is laid out with fixed viewport coordinates: below the
|
|
3494
|
+
* button when it fits, otherwise on the roomier side, shifted back inside
|
|
3495
|
+
* the window horizontally, and capped with its own scrolling only when the
|
|
3496
|
+
* whole window cannot hold it. Without top-layer support it stays absolutely
|
|
3497
|
+
* positioned in place and the same rules apply within the visible area of
|
|
3498
|
+
* its clipping ancestors.
|
|
3499
|
+
*/
|
|
3500
|
+
function placeTip(anchor, pop, topLayer) {
|
|
3501
|
+
const view = tipView();
|
|
3502
|
+
const a = anchor?.getBoundingClientRect?.();
|
|
3503
|
+
if (!a || !pop?.style) return;
|
|
3504
|
+
const bounds = topLayer
|
|
3505
|
+
? { top: 0, left: 0, right: view?.innerWidth ?? Infinity, bottom: view?.innerHeight ?? Infinity }
|
|
3506
|
+
: visibleBounds(anchor);
|
|
3507
|
+
// Measure the natural size: drop any earlier cap first.
|
|
3508
|
+
pop.style.maxHeight = "";
|
|
3509
|
+
pop.style.overflowY = "";
|
|
3510
|
+
const natural = pop.getBoundingClientRect?.() ?? { width: 0, height: 0 };
|
|
3511
|
+
const height = Math.max(natural.height ?? 0, pop.scrollHeight ?? 0);
|
|
3512
|
+
const width = natural.width ?? 0;
|
|
3513
|
+
const below = bounds.bottom - a.bottom - TIP_GAP - TIP_MARGIN;
|
|
3514
|
+
const aboveRoom = a.top - bounds.top - TIP_GAP - TIP_MARGIN;
|
|
3515
|
+
const above = height > below && aboveRoom > below;
|
|
3516
|
+
const room = above ? aboveRoom : below;
|
|
3517
|
+
const shown = height > room ? Math.max(TIP_MIN_HEIGHT, Math.floor(room)) : height;
|
|
3518
|
+
if (height > room) {
|
|
3519
|
+
pop.style.maxHeight = `${shown}px`;
|
|
3520
|
+
pop.style.overflowY = "auto";
|
|
3521
|
+
}
|
|
3522
|
+
pop.setAttribute?.("data-place", above ? "above" : "below");
|
|
3523
|
+
if (topLayer) {
|
|
3524
|
+
const maxLeft = bounds.right - width - TIP_MARGIN;
|
|
3525
|
+
const left = Math.max(bounds.left + TIP_MARGIN, Math.min(a.left - TIP_INSET, maxLeft));
|
|
3526
|
+
const top = above ? a.top - TIP_GAP - shown : a.bottom + TIP_GAP;
|
|
3527
|
+
pop.style.left = `${Math.round(left)}px`;
|
|
3528
|
+
pop.style.top = `${Math.round(top)}px`;
|
|
3529
|
+
return;
|
|
3530
|
+
}
|
|
3531
|
+
// In place: open towards the roomier horizontal side of the visible area.
|
|
3532
|
+
pop.setAttribute?.("data-align", a.left - bounds.left > bounds.right - a.right ? "end" : "start");
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3416
3535
|
/**
|
|
3417
3536
|
* Small "i" help button: the explanation opens on hover, keyboard focus or
|
|
3418
3537
|
* click (touch), closes on Escape / leaving. The text stays in the locale
|
|
3419
3538
|
* dictionaries and is announced through aria-describedby.
|
|
3539
|
+
*
|
|
3540
|
+
* The bubble node is rendered inside this plugin's slot (plugins never
|
|
3541
|
+
* write to `document.body`) but is shown through the Popover API in the
|
|
3542
|
+
* browser's top layer, so it can extend past the Settings dialog instead of
|
|
3543
|
+
* being cut by its clipping containers. It follows its button while the
|
|
3544
|
+
* page scrolls or resizes. See {@link placeTip}.
|
|
3420
3545
|
*/
|
|
3421
3546
|
function InfoTip({ t, text }) {
|
|
3422
3547
|
const [open, setOpen] = useState(false);
|
|
3423
|
-
const [alignEnd, setAlignEnd] = useState(false);
|
|
3424
3548
|
const ref = useRef(null);
|
|
3549
|
+
const popRef = useRef(null);
|
|
3425
3550
|
const id = useMemo(() => `dcpa-tip-${Math.random().toString(36).slice(2, 9)}`, []);
|
|
3551
|
+
|
|
3552
|
+
// Show and place before paint so the bubble never flashes at a wrong spot.
|
|
3553
|
+
useLayoutEffect(() => {
|
|
3554
|
+
if (!open) return undefined;
|
|
3555
|
+
const anchor = ref.current;
|
|
3556
|
+
const pop = popRef.current;
|
|
3557
|
+
if (!anchor || !pop) return undefined;
|
|
3558
|
+
let topLayer = false;
|
|
3559
|
+
if (canUseTopLayer(pop)) {
|
|
3560
|
+
try {
|
|
3561
|
+
pop.setAttribute("popover", "manual");
|
|
3562
|
+
if (!pop.matches?.(":popover-open")) pop.showPopover();
|
|
3563
|
+
topLayer = true;
|
|
3564
|
+
} catch {
|
|
3565
|
+
pop.removeAttribute?.("popover");
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
pop.setAttribute?.("data-layer", topLayer ? "top" : "inline");
|
|
3569
|
+
const place = () => placeTip(anchor, pop, topLayer);
|
|
3570
|
+
place();
|
|
3571
|
+
const view = tipView();
|
|
3572
|
+
if (typeof view?.addEventListener !== "function") return undefined;
|
|
3573
|
+
// Capture scrolls of any pane (the Settings body scrolls, not the window).
|
|
3574
|
+
view.addEventListener("scroll", place, true);
|
|
3575
|
+
view.addEventListener("resize", place);
|
|
3576
|
+
return () => {
|
|
3577
|
+
view.removeEventListener("scroll", place, true);
|
|
3578
|
+
view.removeEventListener("resize", place);
|
|
3579
|
+
};
|
|
3580
|
+
}, [open, text]);
|
|
3581
|
+
|
|
3426
3582
|
if (!text) return null;
|
|
3427
|
-
|
|
3428
|
-
const show = () => {
|
|
3429
|
-
const el = ref.current;
|
|
3430
|
-
const box = el?.closest?.(".dcpa-wrap, .dcpa-q-pop")?.getBoundingClientRect?.();
|
|
3431
|
-
const r = el?.getBoundingClientRect?.();
|
|
3432
|
-
if (box && r) setAlignEnd(r.left - box.left > box.width / 2);
|
|
3433
|
-
setOpen(true);
|
|
3434
|
-
};
|
|
3583
|
+
const show = () => setOpen(true);
|
|
3435
3584
|
return h(
|
|
3436
3585
|
"span",
|
|
3437
3586
|
{
|
|
@@ -3462,7 +3611,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3462
3611
|
},
|
|
3463
3612
|
"i"
|
|
3464
3613
|
),
|
|
3465
|
-
|
|
3614
|
+
// Unmounting a shown popover hides it, so closing needs no hidePopover().
|
|
3615
|
+
open ? h("span", { id, ref: popRef, role: "tooltip", className: "dcpa-info-pop" }, text) : null
|
|
3466
3616
|
);
|
|
3467
3617
|
}
|
|
3468
3618
|
|
|
@@ -3964,6 +4114,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3964
4114
|
const [apiKeyEnv, setApiKeyEnv] = useState("CLI_PROXY_API_KEY");
|
|
3965
4115
|
const [includePrefix, setIncludePrefix] = useState("");
|
|
3966
4116
|
const [excludePrefix, setExcludePrefix] = useState("");
|
|
4117
|
+
const [sanitizePrompt, setSanitizePrompt] = useState(false);
|
|
4118
|
+
const [sanitizePromptReplacement, setSanitizePromptReplacement] = useState("");
|
|
3967
4119
|
const [refreshIntervalSeconds, setRefreshIntervalSeconds] = useState("300");
|
|
3968
4120
|
const [probeTimeoutMs, setProbeTimeoutMs] = useState("5000");
|
|
3969
4121
|
|
|
@@ -3975,6 +4127,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3975
4127
|
apiKeyEnv: c.effectiveApiKeyEnv ?? c.apiKeyEnv ?? "CLI_PROXY_API_KEY",
|
|
3976
4128
|
includePrefix: c.includePrefix ?? "",
|
|
3977
4129
|
excludePrefix: c.excludePrefix ?? "",
|
|
4130
|
+
sanitizePrompt: c.sanitizePrompt === true,
|
|
4131
|
+
sanitizePromptReplacement: c.sanitizePromptReplacement ?? "",
|
|
3978
4132
|
refreshIntervalSeconds: String(global?.refreshIntervalSeconds ?? 300),
|
|
3979
4133
|
});
|
|
3980
4134
|
|
|
@@ -3989,6 +4143,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3989
4143
|
setApiKeyEnv(saved.apiKeyEnv);
|
|
3990
4144
|
setIncludePrefix(saved.includePrefix);
|
|
3991
4145
|
setExcludePrefix(saved.excludePrefix);
|
|
4146
|
+
setSanitizePrompt(saved.sanitizePrompt);
|
|
4147
|
+
setSanitizePromptReplacement(saved.sanitizePromptReplacement);
|
|
3992
4148
|
setRefreshIntervalSeconds(saved.refreshIntervalSeconds);
|
|
3993
4149
|
setProbeTimeoutMs(String(global?.probeTimeoutMs ?? 5000));
|
|
3994
4150
|
setApiKeyDraft("");
|
|
@@ -4033,6 +4189,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4033
4189
|
apiKeyEnv: apiKeyEnv.trim() || account.config?.apiKeyEnv || "CLI_PROXY_API_KEY",
|
|
4034
4190
|
includePrefix: includePrefix.trim(),
|
|
4035
4191
|
excludePrefix: excludePrefix.trim(),
|
|
4192
|
+
sanitizePrompt,
|
|
4193
|
+
sanitizePromptReplacement,
|
|
4036
4194
|
// Before the first catalog is seen, an empty draft is not a choice:
|
|
4037
4195
|
// leave the selection unset so the first probe can recommend one.
|
|
4038
4196
|
...(selectedIds.size > 0 || (account.status?.allModels?.length ?? 0) > 0
|
|
@@ -4101,6 +4259,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4101
4259
|
apiKeyEnv,
|
|
4102
4260
|
includePrefix,
|
|
4103
4261
|
excludePrefix,
|
|
4262
|
+
sanitizePrompt,
|
|
4263
|
+
sanitizePromptReplacement,
|
|
4104
4264
|
refreshIntervalSeconds,
|
|
4105
4265
|
};
|
|
4106
4266
|
const dirty =
|
|
@@ -4357,6 +4517,35 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4357
4517
|
})
|
|
4358
4518
|
)
|
|
4359
4519
|
),
|
|
4520
|
+
h(
|
|
4521
|
+
FieldRow,
|
|
4522
|
+
{ t, label: t("sanitizePromptLabel"), help: t("sanitizePromptHint"), htmlFor: `dcpa-sanitize-${account.id}` },
|
|
4523
|
+
h(
|
|
4524
|
+
"button",
|
|
4525
|
+
{
|
|
4526
|
+
id: `dcpa-sanitize-${account.id}`,
|
|
4527
|
+
type: "button",
|
|
4528
|
+
role: "switch",
|
|
4529
|
+
className: "dcpa-switch",
|
|
4530
|
+
"aria-checked": sanitizePrompt,
|
|
4531
|
+
"aria-label": t("sanitizePromptLabel"),
|
|
4532
|
+
onClick: () => setSanitizePrompt((v) => !v),
|
|
4533
|
+
},
|
|
4534
|
+
h("span", { className: "dcpa-switch-thumb" })
|
|
4535
|
+
)
|
|
4536
|
+
),
|
|
4537
|
+
h(
|
|
4538
|
+
FieldRow,
|
|
4539
|
+
{ t, label: t("sanitizePromptReplacementLabel"), help: t("sanitizePromptReplacementHint"), htmlFor: `dcpa-sanitize-repl-${account.id}` },
|
|
4540
|
+
h("input", {
|
|
4541
|
+
id: `dcpa-sanitize-repl-${account.id}`,
|
|
4542
|
+
className: "dcpa-q-input",
|
|
4543
|
+
value: sanitizePromptReplacement,
|
|
4544
|
+
placeholder: "Custom Harness",
|
|
4545
|
+
disabled: !sanitizePrompt,
|
|
4546
|
+
onChange: (e) => setSanitizePromptReplacement(e.target.value),
|
|
4547
|
+
})
|
|
4548
|
+
),
|
|
4360
4549
|
h(
|
|
4361
4550
|
FieldRow,
|
|
4362
4551
|
{ t, label: t("refreshIntervalLabel"), htmlFor: `dcpa-interval-${account.id}` },
|
|
@@ -5562,9 +5751,29 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5562
5751
|
return `${text} ${fmt(t, account.authPaused ? "qAuthPaused" : "qAuthRetrying", { n, max })}`;
|
|
5563
5752
|
}
|
|
5564
5753
|
|
|
5754
|
+
/** Whether a window covers only Gemini Argon models (Antigravity plans with a separate Argon quota). */
|
|
5755
|
+
function isArgonWindow(w) {
|
|
5756
|
+
const has = (list) => Array.isArray(list) && list.some((x) => String(x).toLowerCase().includes("argon"));
|
|
5757
|
+
return has(w.modelPrefixes) || has(w.modelIds);
|
|
5758
|
+
}
|
|
5759
|
+
|
|
5760
|
+
/**
|
|
5761
|
+
* Short names for Antigravity's quota pools ("Claude and GPT models",
|
|
5762
|
+
* "Gemini models", Argon limits), so rows in narrow popups stay on one
|
|
5763
|
+
* line; any other group name is shown as is.
|
|
5764
|
+
*/
|
|
5765
|
+
function windowGroupName(w) {
|
|
5766
|
+
if (isArgonWindow(w)) return "Argon";
|
|
5767
|
+
const s = String(w.group ?? "").trim().toLowerCase();
|
|
5768
|
+
if (s === "claude and gpt models") return "Claude/GPT";
|
|
5769
|
+
if (s === "gemini models") return "Gemini";
|
|
5770
|
+
return String(w.group ?? "");
|
|
5771
|
+
}
|
|
5772
|
+
|
|
5565
5773
|
function windowLabel(t, w) {
|
|
5566
5774
|
const base = WINDOW_KEYS[w.kind] !== undefined ? t(WINDOW_KEYS[w.kind]) : w.label || t("qWinOther");
|
|
5567
|
-
|
|
5775
|
+
const group = w.group ? windowGroupName(w) : "";
|
|
5776
|
+
return group ? `${group} · ${base}` : base;
|
|
5568
5777
|
}
|
|
5569
5778
|
|
|
5570
5779
|
function durationText(t, ms) {
|
|
@@ -5629,9 +5838,17 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5629
5838
|
return true;
|
|
5630
5839
|
}
|
|
5631
5840
|
|
|
5841
|
+
/**
|
|
5842
|
+
* Windows of one credential that apply to `modelId`. When a Gemini Argon
|
|
5843
|
+
* model has windows of its own, the general Gemini pool ("gemini" prefix)
|
|
5844
|
+
* does not limit it; without them it shares that pool.
|
|
5845
|
+
*/
|
|
5632
5846
|
function credentialWindows(cred, modelId) {
|
|
5633
5847
|
const windows = Array.isArray(cred?.windows) ? cred.windows : [];
|
|
5634
|
-
|
|
5848
|
+
if (!modelId) return windows;
|
|
5849
|
+
const applying = windows.filter((w) => windowAppliesTo(w, modelId));
|
|
5850
|
+
if (!bareModel(modelId).includes("argon") || !applying.some(isArgonWindow)) return applying;
|
|
5851
|
+
return applying.filter((w) => isArgonWindow(w) || !(Array.isArray(w.modelPrefixes) && w.modelPrefixes.length > 0));
|
|
5635
5852
|
}
|
|
5636
5853
|
|
|
5637
5854
|
/** The tightest remaining percentage of the windows that apply, or null. */
|
package/lib/host/accounts.js
CHANGED
|
@@ -16,6 +16,10 @@ export function pickAccount(resolved) {
|
|
|
16
16
|
protocolMode: resolved.protocolMode,
|
|
17
17
|
includePrefix: resolved.includePrefix,
|
|
18
18
|
excludePrefix: resolved.excludePrefix,
|
|
19
|
+
sanitizePrompt: resolved.sanitizePrompt,
|
|
20
|
+
...(resolved.sanitizePromptReplacement === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: { sanitizePromptReplacement: resolved.sanitizePromptReplacement }),
|
|
19
23
|
...(resolved.selectedModels === undefined ? {} : { selectedModels: resolved.selectedModels }),
|
|
20
24
|
modelOverrides: resolved.modelOverrides,
|
|
21
25
|
};
|
|
@@ -7,6 +7,7 @@ import { outsideHmrTransaction } from "../apply-utils.js";
|
|
|
7
7
|
import { toCredentialRef, getEnvValue } from "../config.js";
|
|
8
8
|
import { createCpaController } from "../controller.js";
|
|
9
9
|
import { createModelInfo } from "../model-info.js";
|
|
10
|
+
import { sanitizeAssembly } from "../prompt-sanitize.js";
|
|
10
11
|
|
|
11
12
|
export function createController(shared) {
|
|
12
13
|
const { ctx, readExistingPiAiRoute, readDefaultModel, readState, writeState, updateDirectory } = shared;
|
|
@@ -117,5 +118,28 @@ export function createController(shared) {
|
|
|
117
118
|
onGlobalsChanged: () => reschedule(),
|
|
118
119
|
});
|
|
119
120
|
|
|
121
|
+
// Some upstreams (Antigravity-backed Gemini accounts) return an unexplained
|
|
122
|
+
// 429 whenever the system prompt contains the exact phrase "DeepSeek
|
|
123
|
+
// Harness", and CPA cools the whole account down over that one rejection.
|
|
124
|
+
// The assemble waterfall is the last point where the prompt text is still
|
|
125
|
+
// editable; matching steps get a copy with the phrase rewritten. This fires
|
|
126
|
+
// once per model step, so the per-request work stays a regex over already
|
|
127
|
+
// built strings — a sanitizing failure degrades to the unsanitized prompt.
|
|
128
|
+
ctx.on("system-prompt/assemble", (assembly, context, next) => {
|
|
129
|
+
const provider = context?.modelSelection?.provider;
|
|
130
|
+
const replacement = typeof provider === "string" ? controller.sanitizePromptRoutes().get(provider) : undefined;
|
|
131
|
+
if (replacement === undefined) return next();
|
|
132
|
+
return next().then((resolved) => {
|
|
133
|
+
try {
|
|
134
|
+
return sanitizeAssembly(resolved, replacement);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
ctx.logger?.warn?.(
|
|
137
|
+
`dsh-cliproxyapi: prompt sanitizing failed, sending the prompt unchanged: ${error instanceof Error ? error.message : String(error)}`
|
|
138
|
+
);
|
|
139
|
+
return resolved;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
120
144
|
return { resolveApiKey, describeApiKey, reschedule, mediaSettingsPath, readMedia, controller, modelInfo };
|
|
121
145
|
}
|
package/lib/host/apply-utils.js
CHANGED
|
@@ -28,6 +28,8 @@ export function accountPatchFromInput(input) {
|
|
|
28
28
|
if (typeof input[field] === "string") patch[field] = input[field];
|
|
29
29
|
}
|
|
30
30
|
if (typeof input.enabled === "boolean") patch.enabled = input.enabled;
|
|
31
|
+
if (typeof input.sanitizePrompt === "boolean") patch.sanitizePrompt = input.sanitizePrompt;
|
|
32
|
+
if (typeof input.sanitizePromptReplacement === "string") patch.sanitizePromptReplacement = input.sanitizePromptReplacement;
|
|
31
33
|
if (Array.isArray(input.selectedModels)) patch.selectedModels = input.selectedModels;
|
|
32
34
|
if (plainObject(input.modelOverrides) !== undefined) patch.modelOverrides = input.modelOverrides;
|
|
33
35
|
if (typeof input.apiKey === "string" && input.apiKey.trim() !== "") patch.apiKey = input.apiKey.trim();
|
package/lib/host/config.js
CHANGED
|
@@ -25,6 +25,8 @@ export const ACCOUNT_FIELDS = [
|
|
|
25
25
|
"excludePrefix",
|
|
26
26
|
"selectedModels",
|
|
27
27
|
"modelOverrides",
|
|
28
|
+
"sanitizePrompt",
|
|
29
|
+
"sanitizePromptReplacement",
|
|
28
30
|
];
|
|
29
31
|
/**
|
|
30
32
|
* All-account settings. `onlineModelInfo` (default on) lets recommendations
|
|
@@ -201,6 +203,13 @@ export function resolveConfig(rawConfig = {}) {
|
|
|
201
203
|
sidebarQuota: readVolatile(rawConfig?.sidebarQuota, true) !== false,
|
|
202
204
|
includePrefix,
|
|
203
205
|
excludePrefix,
|
|
206
|
+
// On by default: rewrite upstream-triggering brand phrases in the assembled
|
|
207
|
+
// system prompt for this account's routes (see lib/host/prompt-sanitize.js).
|
|
208
|
+
sanitizePrompt: readVolatile(rawConfig?.sanitizePrompt, true) === true,
|
|
209
|
+
// Optional custom text substituted for the phrase; omitted when unset.
|
|
210
|
+
...(String(readVolatile(rawConfig?.sanitizePromptReplacement, "")).trim() !== ""
|
|
211
|
+
? { sanitizePromptReplacement: String(readVolatile(rawConfig?.sanitizePromptReplacement, "")).trim() }
|
|
212
|
+
: {}),
|
|
204
213
|
...(selectedModels === undefined ? {} : { selectedModels }),
|
|
205
214
|
modelOverrides,
|
|
206
215
|
};
|
package/lib/host/controller.js
CHANGED
|
@@ -5,6 +5,7 @@ import { DEFAULT_API_KEY_ENV, GLOBAL_FIELDS, toCredentialRef, resolveConfig } fr
|
|
|
5
5
|
import { planRecommendations, selectionSuggestions } from "./recommend.js";
|
|
6
6
|
import { isChatModel, managedRouteKeys } from "./routes.js";
|
|
7
7
|
import { pickFields, normalizeState, accountConflicts, assertNoConflicts, newAccountDefaults, patchAccount } from "./accounts.js";
|
|
8
|
+
import { sanitizeReplacement } from "./prompt-sanitize.js";
|
|
8
9
|
import { normalizeCpaRoot, discoverCpa } from "./discovery.js";
|
|
9
10
|
import { CpaRuntime } from "./runtime.js";
|
|
10
11
|
|
|
@@ -240,6 +241,23 @@ export function createCpaController(deps) {
|
|
|
240
241
|
statusPayload,
|
|
241
242
|
findAccount: (ref) => findAccount(deps.readState(), ref),
|
|
242
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Route keys whose requests get a sanitized system prompt, mapped to the
|
|
246
|
+
* phrase replacement each account configured: every managed route of each
|
|
247
|
+
* account that switched the workaround on (its base route plus
|
|
248
|
+
* `-responses` / `-messages` siblings). A blank configured value resolves
|
|
249
|
+
* to the default in lib/host/prompt-sanitize.js.
|
|
250
|
+
*/
|
|
251
|
+
sanitizePromptRoutes() {
|
|
252
|
+
const routes = new Map();
|
|
253
|
+
for (const account of deps.readState().accounts) {
|
|
254
|
+
if (account.sanitizePrompt !== true) continue;
|
|
255
|
+
const replacement = sanitizeReplacement(account.sanitizePromptReplacement);
|
|
256
|
+
for (const key of managedRouteKeys(account.provider)) routes.set(key, replacement);
|
|
257
|
+
}
|
|
258
|
+
return routes;
|
|
259
|
+
},
|
|
260
|
+
|
|
243
261
|
/** Refresh every account (no catalog probe for disabled ones). */
|
|
244
262
|
async refreshAll(options = {}) {
|
|
245
263
|
const state = deps.readState();
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// System-prompt sanitizing: the `system-prompt/assemble` waterfall hook that
|
|
2
|
+
// removes text some upstreams reject before a request leaves DSH — the brand
|
|
3
|
+
// phrase (replaced) and known trigger sentences (removed).
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default text substituted for every "DeepSeek Harness" phrase, used when the
|
|
7
|
+
* account leaves its replacement blank. The phrase is used as a proper noun
|
|
8
|
+
* throughout the prompt ("powered by ___.", "the ___ implementation
|
|
9
|
+
* checkout", "the ___ Web GUI"), so the default is an article-free proper
|
|
10
|
+
* noun that reads grammatically in every position and is free of the brand
|
|
11
|
+
* words the upstream blocks.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_SANITIZE_REPLACEMENT = "Custom Harness";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The phrase some upstream gateways refuse in the system prompt. Antigravity
|
|
17
|
+
* Gemini accounts reject requests whose system text contains "DeepSeek
|
|
18
|
+
* Harness" (any letter case, across whitespace) with an unexplained 429, so
|
|
19
|
+
* every occurrence is replaced as one whole phrase — wherever it appears,
|
|
20
|
+
* including inside the fixed identity opener.
|
|
21
|
+
*/
|
|
22
|
+
export const PROMPT_PHRASE_PATTERN = /deepseek\s+harness/gi;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The replacement text one account configured: its trimmed value, or the
|
|
26
|
+
* default when blank/missing.
|
|
27
|
+
*/
|
|
28
|
+
export function sanitizeReplacement(configured) {
|
|
29
|
+
return typeof configured === "string" && configured.trim() !== ""
|
|
30
|
+
? configured.trim()
|
|
31
|
+
: DEFAULT_SANITIZE_REPLACEMENT;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Build a sentence matcher that tolerates any whitespace between words, in
|
|
36
|
+
* any letter case, and also consumes the horizontal whitespace around it.
|
|
37
|
+
*/
|
|
38
|
+
function sentencePattern(sentence) {
|
|
39
|
+
const words = sentence.trim().split(/\s+/).map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
40
|
+
return new RegExp(`[ \\t]*${words.join("\\s+")}[ \\t]*`, "gi");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whole sentences removed from the prompt because upstream content screening
|
|
45
|
+
* rejects them in context. Google is not a plain keyword filter here: this
|
|
46
|
+
* sentence of DSH's Web GUI orientation (`app:web-surface`, also in its
|
|
47
|
+
* frozen legacy paragraph) passes on its own but 429s together with its
|
|
48
|
+
* neighbours ("…they mean this GUI. … The client-plugin…"); the full prompt
|
|
49
|
+
* passes once it is removed. Losing it only drops the hint that the browser
|
|
50
|
+
* supplies no implicit page context.
|
|
51
|
+
*/
|
|
52
|
+
export const PROMPT_SENTENCE_REMOVALS = [
|
|
53
|
+
sentencePattern("The browser provides no implicit DOM, route, or screenshot context."),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Drop one matched sentence, keeping a single space only where it sat between
|
|
58
|
+
* two pieces of text on the same line (no doubled or dangling spaces).
|
|
59
|
+
*/
|
|
60
|
+
function removeSentence(match, offset, whole) {
|
|
61
|
+
const before = whole[offset - 1];
|
|
62
|
+
const after = whole[offset + match.length];
|
|
63
|
+
const textBefore = before !== undefined && before !== "\n" && before !== "\r";
|
|
64
|
+
const textAfter = after !== undefined && after !== "\n" && after !== "\r";
|
|
65
|
+
return textBefore && textAfter ? " " : "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sanitize one string: remove every known trigger sentence, then replace each
|
|
70
|
+
* "DeepSeek Harness" phrase with `replacement`, verbatim — a function replacer
|
|
71
|
+
* keeps `$`-sequences in custom text literal. Returns the input when nothing
|
|
72
|
+
* matched.
|
|
73
|
+
*/
|
|
74
|
+
export function sanitizePromptText(text, replacement = DEFAULT_SANITIZE_REPLACEMENT) {
|
|
75
|
+
const target = sanitizeReplacement(replacement);
|
|
76
|
+
let out = text;
|
|
77
|
+
for (const pattern of PROMPT_SENTENCE_REMOVALS) {
|
|
78
|
+
pattern.lastIndex = 0;
|
|
79
|
+
out = out.replace(pattern, removeSentence);
|
|
80
|
+
}
|
|
81
|
+
PROMPT_PHRASE_PATTERN.lastIndex = 0;
|
|
82
|
+
return out.replace(PROMPT_PHRASE_PATTERN, () => target);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Rewrite every text value the assembled prompt contributes to the request:
|
|
87
|
+
* ordered sections, dynamic runtime contexts and interpolation variables.
|
|
88
|
+
* Section/context objects are shallow-copied; the input assembly is never
|
|
89
|
+
* mutated. Returns the original assembly reference when nothing matched, so
|
|
90
|
+
* listeners downstream see one identical value.
|
|
91
|
+
*/
|
|
92
|
+
export function sanitizeAssembly(assembly, replacement = DEFAULT_SANITIZE_REPLACEMENT) {
|
|
93
|
+
if (assembly === null || typeof assembly !== "object") return assembly;
|
|
94
|
+
let changed = false;
|
|
95
|
+
const mapText = (entry) => {
|
|
96
|
+
if (entry === null || typeof entry !== "object" || typeof entry.text !== "string") return entry;
|
|
97
|
+
const text = sanitizePromptText(entry.text, replacement);
|
|
98
|
+
if (text === entry.text) return entry;
|
|
99
|
+
changed = true;
|
|
100
|
+
return { ...entry, text };
|
|
101
|
+
};
|
|
102
|
+
const sections = Array.isArray(assembly.sections) ? assembly.sections.map(mapText) : assembly.sections;
|
|
103
|
+
const contexts = Array.isArray(assembly.contexts) ? assembly.contexts.map(mapText) : assembly.contexts;
|
|
104
|
+
let variables = assembly.variables;
|
|
105
|
+
if (variables !== null && typeof variables === "object") {
|
|
106
|
+
const next = {};
|
|
107
|
+
let varsChanged = false;
|
|
108
|
+
for (const [name, value] of Object.entries(variables)) {
|
|
109
|
+
const rewritten = typeof value === "string" ? sanitizePromptText(value, replacement) : value;
|
|
110
|
+
if (rewritten !== value) varsChanged = true;
|
|
111
|
+
next[name] = rewritten;
|
|
112
|
+
}
|
|
113
|
+
if (varsChanged) {
|
|
114
|
+
variables = next;
|
|
115
|
+
changed = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return changed ? { ...assembly, sections, contexts, variables } : assembly;
|
|
119
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { filterModels, modelFamily, sortModelsNewestFirst } from "./host/models.
|
|
|
18
18
|
export { recommendModels, planRecommendations, selectionSuggestions } from "./host/recommend.js";
|
|
19
19
|
export { nativeProtocol, modelProtocol, routeKeyFor, applyModelOverride, isChatModel, buildPiAiRoutes, managedRouteKeys } from "./host/routes.js";
|
|
20
20
|
export { CpaRuntime } from "./host/runtime.js";
|
|
21
|
+
export { DEFAULT_SANITIZE_REPLACEMENT, PROMPT_PHRASE_PATTERN, PROMPT_SENTENCE_REMOVALS, sanitizeReplacement, sanitizePromptText, sanitizeAssembly } from "./host/prompt-sanitize.js";
|
|
21
22
|
export { resolveStateFilePath, loadPersistedState, savePersistedState } from "./host/state-store.js";
|
|
22
23
|
export { renderQuotaText, renderStatusText } from "./host/status-text.js";
|
|
23
24
|
|
package/lib/quota/constants.js
CHANGED
|
@@ -13,17 +13,20 @@ export const UPSTREAM = {
|
|
|
13
13
|
claudeUsage: "https://api.anthropic.com/api/oauth/usage",
|
|
14
14
|
googleLoad: "https://daily-cloudcode-pa.googleapis.com/v1internal:loadCodeAssist",
|
|
15
15
|
googleQuota: "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota",
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
16
|
+
// Same order as CPA's management center: CPA serves Antigravity through the
|
|
17
|
+
// daily host, whose numbers are the ones that move; the production host's
|
|
18
|
+
// Gemini group can read 100% regardless of use, so it comes last. A summary
|
|
19
|
+
// may carry only the "Claude and GPT models" group (5h and weekly buckets);
|
|
20
|
+
// Gemini then comes from the per-model list.
|
|
19
21
|
antigravityQuota: [
|
|
20
|
-
"https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
21
22
|
"https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
22
23
|
"https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
24
|
+
"https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary",
|
|
23
25
|
],
|
|
24
26
|
antigravityModels: [
|
|
25
|
-
"https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
|
|
26
27
|
"https://daily-cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
|
|
28
|
+
"https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:fetchAvailableModels",
|
|
29
|
+
"https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
|
|
27
30
|
],
|
|
28
31
|
kimiUsage: "https://api.kimi.com/coding/v1/usages",
|
|
29
32
|
// Kimi International (kimi.ai) accounts use the same API on another host.
|
|
@@ -50,12 +53,17 @@ export const DEVIN_METADATA = {
|
|
|
50
53
|
|
|
51
54
|
export const AG_META = { ideType: "ANTIGRAVITY", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" };
|
|
52
55
|
export const GEMINI_META = { ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" };
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
// The Antigravity Hub identity CPA itself sends (internal/misc/antigravity_version.go,
|
|
57
|
+
// mirrored by its management center): Cloud Code omits groups and newer models
|
|
58
|
+
// for clients below 2.23.0, so every Antigravity quota request uses it.
|
|
59
|
+
export const AG_UA = "antigravity/hub/2.23.0 darwin/arm64";
|
|
55
60
|
export const CODEX_UA = "codex_cli_rs/0.76.0 (Debian 13.0.0; x86_64) WindowsTerminal";
|
|
56
61
|
|
|
57
62
|
export const GROUP_CLAUDE_GPT = "Claude and GPT models";
|
|
58
63
|
export const GROUP_GEMINI = "Gemini models";
|
|
64
|
+
// Gemini Argon models: some plans (e.g. Google AI Pro) give them a quota of
|
|
65
|
+
// their own, separate from the other Gemini models.
|
|
66
|
+
export const GROUP_ARGON = "Gemini Argon models";
|
|
59
67
|
export const GROUP_OTHER = "Other models";
|
|
60
68
|
|
|
61
69
|
export const W5H = 5 * 60 * 60;
|
package/lib/quota/controller.js
CHANGED
|
@@ -25,8 +25,6 @@ export function createQuotaController(deps) {
|
|
|
25
25
|
const root = new AbortController();
|
|
26
26
|
const pool = createLimiter(concurrency);
|
|
27
27
|
const states = new Map();
|
|
28
|
-
/** management origin → Antigravity endpoint that last returned usable rows. */
|
|
29
|
-
const agPreferred = new Map();
|
|
30
28
|
let disposed = false;
|
|
31
29
|
|
|
32
30
|
// Consecutive management 401/403 counts survive reloads through
|
|
@@ -119,7 +117,7 @@ export function createQuotaController(deps) {
|
|
|
119
117
|
// --- Provider quota probes: each returns { windows, plan? } or throws QuotaError ---
|
|
120
118
|
const PROBES = {
|
|
121
119
|
...createOAuthProbes({ apiCall, now }),
|
|
122
|
-
...createGoogleProbes({ apiCall, now
|
|
120
|
+
...createGoogleProbes({ apiCall, now }),
|
|
123
121
|
...createBillingProbes({ apiCall, management, now }),
|
|
124
122
|
};
|
|
125
123
|
PROBES.gemini = PROBES["gemini-cli"];
|
package/lib/quota/matching.js
CHANGED
|
@@ -51,8 +51,13 @@ function servesFamily(credential, family) {
|
|
|
51
51
|
case "gemini-api":
|
|
52
52
|
case "aistudio": return family === "gemini";
|
|
53
53
|
case "vertex": return family === "gemini" || family === "claude";
|
|
54
|
-
// Antigravity serves Gemini, and Claude/GPT only when its quota groups say
|
|
55
|
-
|
|
54
|
+
// Antigravity serves Gemini, and Claude/GPT only when its quota groups say
|
|
55
|
+
// so. Those groups name whole families ("Claude and GPT models") while
|
|
56
|
+
// Antigravity offers only a few such models, so a disabled credential
|
|
57
|
+
// (whose model list CPA no longer reports) never claims Claude/GPT ids
|
|
58
|
+
// from them alone.
|
|
59
|
+
case "antigravity": return family === "gemini"
|
|
60
|
+
|| ((family === "claude" || family === "gpt") && credential.status !== "disabled" && windowsMention(credential, family));
|
|
56
61
|
case "kimi":
|
|
57
62
|
case "xai":
|
|
58
63
|
case "qwen":
|
|
@@ -65,6 +70,23 @@ function servesFamily(credential, family) {
|
|
|
65
70
|
|
|
66
71
|
const listHas = (credential, idLower) => Array.isArray(credential.models) && credential.models.some((m) => text(m).toLowerCase() === idLower);
|
|
67
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Lower-cased union of the model lists of the other Antigravity credentials
|
|
75
|
+
* with the same prefix, or null when none reports one. A credential whose own
|
|
76
|
+
* list is unknown (CPA reports none while it is disabled) serves what its
|
|
77
|
+
* siblings serve; that is far narrower than the family heuristics.
|
|
78
|
+
*/
|
|
79
|
+
function antigravitySiblingModels(credentials, credential) {
|
|
80
|
+
let union = null;
|
|
81
|
+
for (const other of credentials) {
|
|
82
|
+
if (other === credential || !Array.isArray(other.models) || text(other.provider).toLowerCase() !== "antigravity") continue;
|
|
83
|
+
if (prefixOf(other) !== prefixOf(credential)) continue;
|
|
84
|
+
union ??= new Set();
|
|
85
|
+
for (const m of other.models) union.add(text(m).toLowerCase());
|
|
86
|
+
}
|
|
87
|
+
return union;
|
|
88
|
+
}
|
|
89
|
+
|
|
68
90
|
function finishMatch(list, matchedBy) {
|
|
69
91
|
const seen = new Set();
|
|
70
92
|
const unique = list.filter((c) => (seen.has(c.id) ? false : (seen.add(c.id), true)));
|
|
@@ -109,7 +131,14 @@ export function matchCredentials(accountEntry, modelId) {
|
|
|
109
131
|
const hint = picker.find((m) => isObj(m) && text(m.id).toLowerCase() === id && text(m.ownedBy) !== "");
|
|
110
132
|
if (hint !== undefined) family = ownedByFamily(hint.ownedBy);
|
|
111
133
|
}
|
|
112
|
-
const familyHits =
|
|
134
|
+
const familyHits = unprefixed.filter((c) => {
|
|
135
|
+
if (Array.isArray(c.models)) return false;
|
|
136
|
+
if (text(c.provider).toLowerCase() === "antigravity") {
|
|
137
|
+
const siblings = antigravitySiblingModels(credentials, c);
|
|
138
|
+
if (siblings !== null) return siblings.has(id);
|
|
139
|
+
}
|
|
140
|
+
return family !== "" && servesFamily(c, family);
|
|
141
|
+
});
|
|
113
142
|
|
|
114
143
|
const listHits = [...plainHits, ...prefixedHits];
|
|
115
144
|
if (listHits.length > 0) return finishMatch([...listHits, ...familyHits], "model-list");
|
package/lib/quota/parsers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Converts provider quota payloads into safe windows and plan labels.
|
|
2
|
-
import { GROUP_CLAUDE_GPT, GROUP_GEMINI, GROUP_OTHER, PLAN_LABELS } from "./constants.js";
|
|
2
|
+
import { GROUP_CLAUDE_GPT, GROUP_GEMINI, GROUP_ARGON, GROUP_OTHER, PLAN_LABELS } from "./constants.js";
|
|
3
3
|
import { QuotaError, isObj, text, firstText, numberOrNull, flagOf, clampPct, roundPct, getPath, fractionPercent, kindFromText, kindFromSeconds, durationSeconds, kindFromReset, isoFromUnix, isoFromString, isoFromRelative, makeWindow, dedupeWindows, extractPlan } from "./helpers.js";
|
|
4
4
|
|
|
5
5
|
//#region Upstream Parsers
|
|
@@ -101,17 +101,44 @@ function claudeProfilePlan(profile) {
|
|
|
101
101
|
return extractPlan(profile);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (s
|
|
104
|
+
/** Model family a quota group/bucket/model text names: "claude-gpt", "argon", "gemini" or "". */
|
|
105
|
+
function textFamily(value) {
|
|
106
|
+
const s = text(value).toLowerCase();
|
|
107
|
+
if (s === "") return "";
|
|
108
|
+
// Antigravity labels its Claude/GPT ("third-party") buckets 3p-*.
|
|
109
|
+
if (/claude|gpt|third[\s_-]?party|(?:^|[^a-z0-9])3p(?:[^a-z0-9]|$)/.test(s)) return "claude-gpt";
|
|
110
|
+
if (/argon/.test(s)) return "argon";
|
|
111
|
+
if (/gemini|gemma/.test(s)) return "gemini";
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Prefixes for Argon windows: "argon" plus every "gemini-<version>-argon"
|
|
117
|
+
* the text names (e.g. "Gemini 4 Argon" / "gemini-4-argon-high" →
|
|
118
|
+
* "gemini-4-argon"), so model ids match by prefix without hard-coding a
|
|
119
|
+
* version; "gemini-4-argon" when the text names none.
|
|
120
|
+
*/
|
|
121
|
+
function argonPrefixes(...values) {
|
|
122
|
+
const found = new Set(["argon"]);
|
|
123
|
+
for (const value of values) {
|
|
124
|
+
for (const m of text(value).toLowerCase().matchAll(/gemini[\s_-]+([0-9][0-9.]*)[\s_-]+argon/g)) found.add(`gemini-${m[1]}-argon`);
|
|
125
|
+
}
|
|
126
|
+
if (found.size === 1) found.add("gemini-4-argon");
|
|
127
|
+
return [...found];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function familyPrefixes(family, ...values) {
|
|
131
|
+
if (family === "claude-gpt") return ["claude", "gpt"];
|
|
132
|
+
if (family === "argon") return argonPrefixes(...values);
|
|
133
|
+
if (family === "gemini") return ["gemini", "gemma"];
|
|
108
134
|
return undefined;
|
|
109
135
|
}
|
|
110
136
|
|
|
111
137
|
function groupForModel(modelId, label) {
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
if (
|
|
138
|
+
const family = textFamily(modelId) || textFamily(label);
|
|
139
|
+
if (family === "claude-gpt") return GROUP_CLAUDE_GPT;
|
|
140
|
+
if (family === "argon") return GROUP_ARGON;
|
|
141
|
+
if (family === "gemini") return GROUP_GEMINI;
|
|
115
142
|
return GROUP_OTHER;
|
|
116
143
|
}
|
|
117
144
|
|
|
@@ -133,19 +160,26 @@ function groupedQuotaWindows(body, idPrefix) {
|
|
|
133
160
|
if (!isObj(group)) return;
|
|
134
161
|
const groupLabel = firstText(group.displayName, group.display_name, group.name, `Quota Group ${groupIndex + 1}`);
|
|
135
162
|
const groupId = text(group.id) || groupLabel.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || `group-${groupIndex + 1}`;
|
|
136
|
-
|
|
163
|
+
// The group's own name decides its family; its description (a model list
|
|
164
|
+
// that may mention Argon among the Gemini models) only when the name says nothing.
|
|
165
|
+
const groupFamily = textFamily(groupLabel) || textFamily(group.description);
|
|
137
166
|
const buckets = Array.isArray(group.buckets) ? group.buckets : [];
|
|
138
167
|
buckets.forEach((bucket, bucketIndex) => {
|
|
139
168
|
if (!isObj(bucket)) return;
|
|
140
169
|
const remaining = fractionPercent(bucket.remainingFraction ?? bucket.remaining_fraction);
|
|
141
170
|
const resetAt = isoFromString(firstText(bucket.resetTime, bucket.reset_time));
|
|
142
171
|
if (remaining === null && resetAt === null) return;
|
|
143
|
-
const
|
|
144
|
-
const
|
|
172
|
+
const bucketId = firstText(bucket.bucketId, bucket.bucket_id);
|
|
173
|
+
const label = firstText(bucket.displayName, bucket.display_name, bucket.label, bucket.description, bucket.window, bucketId);
|
|
174
|
+
const kind = kindFromText(bucket.window, bucket.windowType, bucket.window_type, label, bucketId)
|
|
145
175
|
|| kindFromSeconds(bucket.windowSeconds ?? bucket.window_seconds ?? bucket.limitWindowSeconds ?? bucket.limit_window_seconds)
|
|
146
176
|
|| "other";
|
|
177
|
+
// An Argon bucket (e.g. an Argon weekly limit inside the Gemini group)
|
|
178
|
+
// covers only the Argon models; any other bucket covers its group.
|
|
179
|
+
const argonBucket = textFamily(`${bucketId} ${label}`) === "argon";
|
|
180
|
+
const prefixes = argonBucket ? argonPrefixes(bucketId, label, groupLabel) : familyPrefixes(groupFamily, groupLabel);
|
|
147
181
|
rows.push(makeWindow({
|
|
148
|
-
id: `${idPrefix}:${groupId}:${firstText(
|
|
182
|
+
id: `${idPrefix}:${groupId}:${firstText(bucketId, `${kind}-${bucketIndex + 1}`)}`,
|
|
149
183
|
kind,
|
|
150
184
|
label,
|
|
151
185
|
group: groupLabel,
|
|
@@ -158,31 +192,63 @@ function groupedQuotaWindows(body, idPrefix) {
|
|
|
158
192
|
return rows;
|
|
159
193
|
}
|
|
160
194
|
|
|
195
|
+
const FAMILY_OF_GROUP = { [GROUP_CLAUDE_GPT]: "claude-gpt", [GROUP_ARGON]: "argon", [GROUP_GEMINI]: "gemini" };
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Antigravity `fetchAvailableModels`: per-model quotaInfo keyed by the public
|
|
199
|
+
* model id (`modelId` there is an internal placeholder). Models of one family
|
|
200
|
+
* (Claude/GPT, Gemini Argon, other Gemini) that report the same quota share
|
|
201
|
+
* one pool: that pool becomes a single family window matched by prefix, so
|
|
202
|
+
* models the list omits (CPA serves more Gemini ids than Antigravity lists)
|
|
203
|
+
* still find it. Families with diverging values keep one window per pool,
|
|
204
|
+
* matched by exact id. Internal tab/chat completion models are skipped.
|
|
205
|
+
*/
|
|
161
206
|
function antigravityModelWindows(body, nowMs) {
|
|
162
207
|
const models = body.models;
|
|
163
208
|
if (models === null || typeof models !== "object") return [];
|
|
164
209
|
const entries = Array.isArray(models) ? models.map((raw, i) => [String(i), raw]) : Object.entries(models);
|
|
165
|
-
const
|
|
210
|
+
const families = new Map();
|
|
166
211
|
for (const [key, raw] of entries) {
|
|
167
|
-
if (!isObj(raw)) continue;
|
|
168
|
-
const modelId =
|
|
169
|
-
|
|
212
|
+
if (!isObj(raw) || flagOf(raw.isInternal ?? raw.is_internal) === true) continue;
|
|
213
|
+
const modelId = Array.isArray(models)
|
|
214
|
+
? firstText(raw.id, raw.model_id, raw.modelId, raw.model, raw.name)
|
|
215
|
+
: firstText(key, raw.id, raw.model_id, raw.modelId, raw.model, raw.name);
|
|
216
|
+
if (modelId === "" || /^(?:chat|tab)_/i.test(modelId)) continue;
|
|
170
217
|
const quota = isObj(raw.quotaInfo) ? raw.quotaInfo : isObj(raw.quota_info) ? raw.quota_info : raw;
|
|
171
218
|
let remaining = fractionPercent(quota.remainingFraction ?? quota.remaining_fraction ?? quota.remaining);
|
|
172
219
|
const amount = numberOrNull(quota.remainingAmount ?? quota.remaining_amount);
|
|
173
220
|
const resetAt = isoFromString(firstText(quota.resetTime, quota.reset_time, raw.resetTime, raw.reset_time));
|
|
174
221
|
if (remaining === null && amount !== null && amount <= 0) remaining = 0;
|
|
175
222
|
if (remaining === null && resetAt === null) continue;
|
|
176
|
-
const label = firstText(raw.displayName, raw.display_name
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
})
|
|
223
|
+
const label = firstText(raw.displayName, raw.display_name);
|
|
224
|
+
const group = groupForModel(modelId, label);
|
|
225
|
+
if (group === GROUP_OTHER && label === "") continue;
|
|
226
|
+
const kind = kindFromReset(resetAt, nowMs);
|
|
227
|
+
const pct = roundPct(remaining);
|
|
228
|
+
if (!families.has(group)) families.set(group, new Map());
|
|
229
|
+
const pools = families.get(group);
|
|
230
|
+
const poolKey = `${kind}|${pct}|${resetAt ?? ""}`;
|
|
231
|
+
const pool = pools.get(poolKey);
|
|
232
|
+
if (pool === undefined) pools.set(poolKey, { kind, pct, resetAt, label, modelIds: [modelId] });
|
|
233
|
+
else if (!pool.modelIds.includes(modelId)) pool.modelIds.push(modelId);
|
|
234
|
+
}
|
|
235
|
+
const rows = [];
|
|
236
|
+
for (const [group, pools] of families) {
|
|
237
|
+
const list = [...pools.values()];
|
|
238
|
+
const prefixes = familyPrefixes(FAMILY_OF_GROUP[group], ...list.flatMap((pool) => pool.modelIds));
|
|
239
|
+
const familyKey = group.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
240
|
+
list.forEach((pool, index) => {
|
|
241
|
+
const shared = list.length === 1 && prefixes !== undefined;
|
|
242
|
+
rows.push(makeWindow({
|
|
243
|
+
id: shared ? `ag-model:${familyKey}` : `ag-model:${familyKey}:${index + 1}`,
|
|
244
|
+
kind: pool.kind,
|
|
245
|
+
label: shared || pool.modelIds.length > 1 ? "" : pool.label,
|
|
246
|
+
group,
|
|
247
|
+
remainingPercent: pool.pct,
|
|
248
|
+
resetAt: pool.resetAt,
|
|
249
|
+
...(shared ? { modelPrefixes: prefixes } : { modelIds: pool.modelIds }),
|
|
250
|
+
}));
|
|
251
|
+
});
|
|
186
252
|
}
|
|
187
253
|
return rows;
|
|
188
254
|
}
|
|
@@ -194,7 +260,7 @@ function googleBucketWindows(body, nowMs, idPrefix) {
|
|
|
194
260
|
for (const bucket of buckets) {
|
|
195
261
|
if (!isObj(bucket)) continue;
|
|
196
262
|
const modelId = firstText(bucket.modelId, bucket.model_id).replace(/_vertex$/, "");
|
|
197
|
-
if (!/^(?:gemini|gemma)/i.test(modelId)) continue;
|
|
263
|
+
if (!/^(?:gemini|gemma|argon)/i.test(modelId)) continue;
|
|
198
264
|
const remaining = fractionPercent(bucket.remainingFraction ?? bucket.remaining_fraction ?? bucket.remaining);
|
|
199
265
|
const resetAt = isoFromString(firstText(bucket.resetTime, bucket.reset_time));
|
|
200
266
|
if (remaining === null && resetAt === null) continue;
|
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
// Google Code Assist loading and Antigravity/Gemini quota requests and fallback order.
|
|
2
|
-
import { UPSTREAM, AG_META, GEMINI_META,
|
|
2
|
+
import { UPSTREAM, AG_META, GEMINI_META, AG_UA, GROUP_GEMINI, GROUP_ARGON, GROUP_CLAUDE_GPT } from "../constants.js";
|
|
3
3
|
import { QuotaError, isObj, firstText, projectIdOf, extractPlan } from "../helpers.js";
|
|
4
4
|
import { antigravitySummaryWindows, antigravityModelWindows, googleBucketWindows } from "../parsers.js";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const agHeaders = () => ({ Authorization: "Bearer $TOKEN$", "Content-Type": "application/json", "User-Agent": AG_UA });
|
|
7
|
+
|
|
8
|
+
/** Which Antigravity quota pool a window describes: "argon", "gemini", "claude-gpt" or "other". */
|
|
9
|
+
function windowFamily(w) {
|
|
10
|
+
const prefixes = Array.isArray(w.modelPrefixes) ? w.modelPrefixes : [];
|
|
11
|
+
if (w.group === GROUP_ARGON || prefixes.includes("argon")) return "argon";
|
|
12
|
+
if (w.group === GROUP_GEMINI || prefixes.includes("gemini")) return "gemini";
|
|
13
|
+
if (w.group === GROUP_CLAUDE_GPT || prefixes.includes("claude")) return "claude-gpt";
|
|
14
|
+
return "other";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function hasFamily(windows, family) {
|
|
18
|
+
return Array.isArray(windows) && windows.some((w) => windowFamily(w) === family);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `base` plus the rows of families it does not have yet (unclassified rows by id). */
|
|
22
|
+
function mergeFamilies(base, rows) {
|
|
23
|
+
if (base === null) return [...rows];
|
|
24
|
+
const present = new Set(base.map(windowFamily));
|
|
25
|
+
const ids = new Set(base.map((w) => w.id));
|
|
26
|
+
return [...base, ...rows.filter((r) => {
|
|
27
|
+
const family = windowFamily(r);
|
|
28
|
+
return family === "other" ? !ids.has(r.id) : !present.has(family);
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createGoogleProbes({ apiCall, now }) {
|
|
7
33
|
async function loadCodeAssist(ctx, authIndex, metadata) {
|
|
8
|
-
const headers = metadata.ideType === "ANTIGRAVITY"
|
|
9
|
-
? { Authorization: "Bearer $TOKEN$", "Content-Type": "application/json", "User-Agent": AG_SUMMARY_UA }
|
|
10
|
-
: googleHeaders(metadata);
|
|
34
|
+
const headers = metadata.ideType === "ANTIGRAVITY" ? agHeaders() : googleHeaders(metadata);
|
|
11
35
|
const body = await apiCall(ctx, { auth_index: authIndex, method: "POST", url: UPSTREAM.googleLoad, header: headers, data: JSON.stringify({ metadata }) });
|
|
12
36
|
const project = body.cloudaicompanionProject ?? body.cloudaicompanion_project;
|
|
13
37
|
return { body, projectID: isObj(project) ? firstText(project.id) : firstText(project) };
|
|
@@ -24,7 +48,7 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
24
48
|
}
|
|
25
49
|
|
|
26
50
|
return {
|
|
27
|
-
async antigravity(ctx, entry, authIndex
|
|
51
|
+
async antigravity(ctx, entry, authIndex) {
|
|
28
52
|
let projectID = projectIdOf(entry);
|
|
29
53
|
let plan = "";
|
|
30
54
|
let tier = null;
|
|
@@ -32,58 +56,54 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
32
56
|
const loaded = await loadCodeAssist(ctx, authIndex, AG_META);
|
|
33
57
|
projectID = loaded.projectID;
|
|
34
58
|
plan = extractPlan(loaded.body);
|
|
35
|
-
} else
|
|
59
|
+
} else {
|
|
60
|
+
// Re-read the tier every round so an upgrade/downgrade replaces the cached plan;
|
|
61
|
+
// a failed read yields "" and the controller keeps the previous plan.
|
|
36
62
|
tier = loadCodeAssist(ctx, authIndex, AG_META).then((l) => extractPlan(l.body), () => "");
|
|
37
63
|
}
|
|
38
64
|
if (projectID === "") throw new QuotaError("missing-project");
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
65
|
+
const read = async (url) => {
|
|
66
|
+
const body = await apiCall(ctx, { auth_index: authIndex, method: "POST", url, header: agHeaders(), data: JSON.stringify({ project: projectID }) });
|
|
67
|
+
plan = plan || extractPlan(body);
|
|
68
|
+
return body;
|
|
69
|
+
};
|
|
70
|
+
// Hosts are always tried in their fixed order (daily first): a host
|
|
71
|
+
// that answered once is not preferred later, because production's
|
|
72
|
+
// Gemini numbers can read 100% regardless of use.
|
|
47
73
|
let lastError = null;
|
|
48
|
-
let partial = null;
|
|
49
74
|
let windows = null;
|
|
50
|
-
for (const url of
|
|
51
|
-
const summary = url.includes("retrieveUserQuotaSummary");
|
|
52
|
-
if (partial !== null && !summary) continue;
|
|
75
|
+
for (const url of UPSTREAM.antigravityQuota) {
|
|
53
76
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
if (rows.some((r) => r.modelPrefixes?.includes("gemini"))) {
|
|
59
|
-
windows = rows;
|
|
60
|
-
agPreferred.set(ctx.origin, url);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
// A host without the Gemini group: keep looking at the other summary hosts.
|
|
64
|
-
if (partial === null) partial = { rows, url };
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const modelRows = antigravityModelWindows(body, now());
|
|
68
|
-
if (modelRows.length > 0) {
|
|
69
|
-
windows = modelRows;
|
|
70
|
-
agPreferred.set(ctx.origin, url);
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
77
|
+
// Like CPA's management center: keep each family from the first host
|
|
78
|
+
// that reports it, until one host has supplied the Gemini pool.
|
|
79
|
+
windows = mergeFamilies(windows, antigravitySummaryWindows(await read(url)));
|
|
80
|
+
if (hasFamily(windows, "gemini")) break;
|
|
73
81
|
} catch (error) {
|
|
74
82
|
if (error?.code === "aborted") throw error;
|
|
75
83
|
lastError = error;
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
|
-
if (windows
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
if (!hasFamily(windows, "gemini")) {
|
|
87
|
+
// Per-model quota supplies the families the summaries lacked.
|
|
88
|
+
for (const url of UPSTREAM.antigravityModels) {
|
|
89
|
+
try {
|
|
90
|
+
const merged = mergeFamilies(windows, antigravityModelWindows(await read(url), now()));
|
|
91
|
+
if (merged.length === (windows?.length ?? 0)) continue;
|
|
92
|
+
windows = merged;
|
|
93
|
+
break;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (error?.code === "aborted") throw error;
|
|
96
|
+
lastError = error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (windows !== null && windows.length > 0 && !hasFamily(windows, "gemini")) {
|
|
81
101
|
try {
|
|
82
102
|
const body = await apiCall(ctx, {
|
|
83
103
|
auth_index: authIndex,
|
|
84
104
|
method: "POST",
|
|
85
105
|
url: UPSTREAM.googleQuota,
|
|
86
|
-
header:
|
|
106
|
+
header: agHeaders(),
|
|
87
107
|
data: JSON.stringify({ project: projectID }),
|
|
88
108
|
});
|
|
89
109
|
windows = [...windows, ...googleBucketWindows(body, now(), "ag-gemini")];
|
|
@@ -92,18 +112,22 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
92
112
|
/* the supplementary Gemini read is best-effort */
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
|
-
if (tier !== null) plan =
|
|
96
|
-
if (windows === null) throw lastError ?? new QuotaError("invalid-response");
|
|
115
|
+
if (tier !== null) plan = (await tier) || plan;
|
|
116
|
+
if (windows === null || windows.length === 0) throw lastError ?? new QuotaError("invalid-response");
|
|
97
117
|
return { windows, plan };
|
|
98
118
|
},
|
|
99
119
|
|
|
100
120
|
async "gemini-cli"(ctx, entry, authIndex) {
|
|
101
121
|
let projectID = projectIdOf(entry);
|
|
102
122
|
let plan = "";
|
|
123
|
+
let tier = null;
|
|
103
124
|
if (projectID === "") {
|
|
104
125
|
const loaded = await loadCodeAssist(ctx, authIndex, GEMINI_META);
|
|
105
126
|
projectID = loaded.projectID;
|
|
106
127
|
plan = extractPlan(loaded.body);
|
|
128
|
+
} else {
|
|
129
|
+
// Same as Antigravity: refresh the tier each round; failures fall back to the cached plan.
|
|
130
|
+
tier = loadCodeAssist(ctx, authIndex, GEMINI_META).then((l) => extractPlan(l.body), () => "");
|
|
107
131
|
}
|
|
108
132
|
if (projectID === "") throw new QuotaError("missing-project");
|
|
109
133
|
const body = await apiCall(ctx, {
|
|
@@ -113,6 +137,7 @@ export function createGoogleProbes({ apiCall, now, agPreferred }) {
|
|
|
113
137
|
header: googleHeaders({ ...GEMINI_META, duetProject: projectID }),
|
|
114
138
|
data: JSON.stringify({ project: projectID }),
|
|
115
139
|
});
|
|
140
|
+
if (tier !== null) plan = (await tier) || plan;
|
|
116
141
|
return { windows: googleBucketWindows(body, now(), "gemini"), plan };
|
|
117
142
|
},
|
|
118
143
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cliproxyapi-pro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "CLIProxyAPI (CPA) provider for DeepSeek Harness — multiple accounts, model sync over native protocols, per-credential quota, and optional image / video generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|