dsh-cliproxyapi-pro 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/lib/client.js +237 -17
- 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 +14 -5
- package/lib/host/controller.js +18 -0
- package/lib/host/prompt-sanitize.js +119 -0
- package/lib/host/routes.js +48 -12
- 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,26 @@
|
|
|
4
4
|
|
|
5
5
|
本插件的所有重要变更。版本号遵循[语义化版本](https://semver.org/lang/zh-CN/)。
|
|
6
6
|
|
|
7
|
+
## 1.12.1 — 2026-11-18
|
|
8
|
+
|
|
9
|
+
### 变更
|
|
10
|
+
- **Gemini 改走原生协议。** DSH 的 `llm-pi-ai` 自定义路由支持 Gemini `generateContent`(`google-generative-ai`),自动模式下不带前缀的 `gemini-*` 模型不再走 OpenAI Chat,而是写入新的 `<路由>-gemini` 路由(地址为 `<CPA>/v1beta`),省去 CPA 的 Chat ↔ Gemini 转换,思考签名和工具调用按原生格式往返。该路由必须配置 API Key,未配置密钥的账号 Gemini 仍走 Chat;思考档位只提供 Gemini 适配器能发送的 `minimal` / `low` / `medium` / `high`。`devin/gemini-*` 等带前缀的 ID 仍走 Chat。「统一使用」和单模型协议也可以选 **Gemini**。已经在 `cli-proxy` 上使用 Gemini 的会话需要重新选一次模型。
|
|
11
|
+
|
|
12
|
+
## 1.12.0 — 2026-11-18
|
|
13
|
+
|
|
14
|
+
### 新增
|
|
15
|
+
- **提示词净化(兼容性)。** 每个账号的连接页「高级路由与规则过滤」新增开关(默认开启)与「替换文本」输入框:开启后,发往该账号三条路由的请求的系统提示词中,每个精确短语 “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` 瀑布),覆盖提示词分节与插值变量,只影响该账号自己的路由,已保存在会话中的提示词不变。升级前已有的账号同样默认开启,可在该开关处关闭。
|
|
16
|
+
|
|
17
|
+
### 修复
|
|
18
|
+
- **Antigravity 和 Gemini CLI 的套餐升级 / 降级后会及时更新。** 凭证已带项目 ID 时,原先只要显示过一次套餐就不再查询,比如从 Pro 升级到 Ultra 后仍一直显示 Pro。现在每轮额度刷新都会通过 `loadCodeAssist` 重新读取套餐,并以新读到的结果为准;这次读取失败时沿用上一次的套餐。代价是这两类凭证每轮刷新多一次很轻的 `loadCodeAssist` 请求。
|
|
19
|
+
- **Antigravity 的 Gemini 模型(如 `gemini-4-argon-high`)重新显示额度。** 额度汇总接口现在只返回「Claude and GPT models」一组,原先的补充查询只认 Gemini CLI 列出的模型,而且读的是生产主机(显示 100%,不随用量变化),所以这些模型一直显示「上游未返回额度窗口」。现在 Gemini 额度改从 CPA 实际走的 daily 主机的逐模型列表读取:同一族模型共用同一份额度时合成一个「Gemini models」窗口,按前缀匹配,列表里没有的 Gemini 型号也能对上;各模型额度不同时仍按模型分别显示。逐模型列表改用公开模型 ID(原先误用内部占位 ID,永远匹配不上),并跳过内部补全模型(`chat_*`、`tab_*`)。
|
|
20
|
+
- **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)。
|
|
21
|
+
- **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)。
|
|
22
|
+
- **停用的 Antigravity 凭证不再挂到无关的 GPT / Claude 模型下。** 凭证停用后 CPA 不再报告它的模型列表,原先按「Claude and GPT models」分组名推断,结果所有 GPT / Claude 模型(如 `gpt-6-luna`)都显示了这个凭证。现在它只匹配同一账号里其他 Antigravity 凭证列出的模型;没有可参照的凭证时只匹配 Gemini 模型。来自 [@Six6stRINgs](https://github.com/Six6stRINgs) 的报告(#6)。
|
|
23
|
+
|
|
24
|
+
### 修复(界面优化)
|
|
25
|
+
- **设置页的 ⓘ 说明不再被对话框截断。** 说明气泡原先渲染在设置对话框的滚动区域内,靠近底部的行(如「提示词净化」)展开时下半截被裁掉。现在气泡通过浏览器的 Popover API 显示在顶层,可以超出对话框范围;按整个窗口定位,下方放不下时改到上方,左右超出窗口时自动收回,只有窗口都放不下时才限制高度并在气泡内滚动;滚动设置页时跟随按钮移动。气泡元素仍在插件自己的插槽内,不写入页面其他位置。
|
|
26
|
+
|
|
7
27
|
## 1.11.0 — 2026-11-12
|
|
8
28
|
|
|
9
29
|
### 新增
|
package/README.en.md
CHANGED
|
@@ -12,7 +12,7 @@ Enter a server URL and an API key, and the plugin reads the CPA model catalog an
|
|
|
12
12
|
|
|
13
13
|
- **Multiple accounts**: each account has its own URL, key, model selection and parameters, and can be switched off at any time. [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/accounts-and-models.md)
|
|
14
14
|
- **Works out of the box**: on the first connection, the newest model of each family in that server's own catalog is checked (at most 12), so the picker isn't flooded with hundreds of models. [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/accounts-and-models.md)
|
|
15
|
-
- **Native protocols**: Claude over Anthropic Messages, GPT / Codex / Grok over OpenAI Responses, everything else over OpenAI Chat — fewer protocol translations inside CPA. [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/accounts-and-models.md)
|
|
15
|
+
- **Native protocols**: Claude over Anthropic Messages, GPT / Codex / Grok over OpenAI Responses, Gemini over its native `generateContent` (needs an API key, otherwise OpenAI Chat), everything else over OpenAI Chat — fewer protocol translations inside CPA. [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/accounts-and-models.md)
|
|
16
16
|
- **Visual management**: check models and edit per-model parameters in the settings panel. By default the plugin registers no agent tool, so it takes no model context (the optional generation tool `generate_media` is switched on in the Generation tab). [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/accounts-and-models.md)
|
|
17
17
|
- **Channel quota**: see each channel's remaining quota per credential, with a badge for the current model in the composer and a quick view of every account in the sidebar footer; failed queries pause automatic refresh. [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/quota.md)
|
|
18
18
|
- **Images and videos**: generate and edit images, and generate, edit and extend videos through CPA; the optional agent generation tool is off by default. [Details](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/en/media.md)
|
|
@@ -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.1`.
|
|
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.1` |
|
|
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
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
- **多账号**:每个账号独立的地址、密钥、模型勾选和参数,互不影响,可随时停用。 [详解](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/zh/accounts-and-models.md)
|
|
14
14
|
- **开箱即用**:首次连接时按该服务自己的模型目录,为每个模型家族勾选最新的一个(最多 12 个),模型选择器不会被上百个模型淹没。 [详解](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/zh/accounts-and-models.md)
|
|
15
|
-
- **原生协议**:Claude 走 Anthropic Messages,GPT / Codex / Grok 走 OpenAI Responses
|
|
15
|
+
- **原生协议**:Claude 走 Anthropic Messages,GPT / Codex / Grok 走 OpenAI Responses,Gemini 走 Gemini 原生 `generateContent`(需配置 API Key,否则走 OpenAI Chat),其余走 OpenAI Chat,减少 CPA 的协议转换。 [详解](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/zh/accounts-and-models.md)
|
|
16
16
|
- **可视化管理**:设置面板里勾选模型、编辑单个模型的参数。默认不注册 Agent 工具,不占用模型上下文(可选的生成工具 `generate_media` 需在「生成」标签手动打开)。 [详解](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/zh/accounts-and-models.md)
|
|
17
17
|
- **渠道额度**:按凭证查看各渠道的剩余额度,对话框里的徽标显示当前模型的额度,侧边栏底部可快速查看所有账号;查询失败会暂停自动刷新。 [详解](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/zh/quota.md)
|
|
18
18
|
- **生图 / 生视频**:通过 CPA 生成和编辑图片,生成、编辑和延长视频;可选的 agent 生成工具默认关闭。 [详解](https://github.com/TinyBOOOOM/dsh-cliproxyapi-pro/blob/main/docs/zh/media.md)
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
dsh-cliproxyapi-pro
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
需要固定版本时可以写成 `dsh-cliproxyapi-pro@1.
|
|
39
|
+
需要固定版本时可以写成 `dsh-cliproxyapi-pro@1.12.1`。
|
|
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.1` |
|
|
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";
|
|
@@ -82,12 +82,13 @@ window.__ModuleLoader__.load({
|
|
|
82
82
|
apiKeyHint: "保存在 DSH 凭证服务({ref}),不会写入配置文件。本地免密的 CPA 可留空。",
|
|
83
83
|
clearKeyBtn: "清除密钥",
|
|
84
84
|
protocolLabel: "接口协议",
|
|
85
|
-
protocolHint: "自动模式下每个模型走所属家族的原生协议,减少 CPA
|
|
85
|
+
protocolHint: "自动模式下每个模型走所属家族的原生协议,减少 CPA 中转转换:Claude 走 Claude Messages,GPT / Grok 走 OpenAI Responses,Gemini 走 Gemini 原生协议(需要配置 API Key,未配置时改走 OpenAI Chat),其余模型走 OpenAI Chat。",
|
|
86
86
|
protocolAuto: "自动:按模型家族走原生协议(推荐)",
|
|
87
87
|
protocolFixedPrefix: "统一使用:",
|
|
88
88
|
protocolNameCompletions: "OpenAI Chat",
|
|
89
89
|
protocolNameResponses: "OpenAI Responses",
|
|
90
90
|
protocolNameMessages: "Claude Messages",
|
|
91
|
+
protocolNameGemini: "Gemini",
|
|
91
92
|
modelProtocolLabel: "请求协议",
|
|
92
93
|
modelProtocolDefault: "跟随全局设置",
|
|
93
94
|
modelProtocolHint: "原生协议:",
|
|
@@ -104,6 +105,10 @@ window.__ModuleLoader__.load({
|
|
|
104
105
|
excludePrefixLabel: "排除关键词",
|
|
105
106
|
excludePrefixPlaceholder: "例如: tts, image, video, zj/ (多个用逗号分隔)",
|
|
106
107
|
excludePrefixHint: "附加规则:排除包含指定关键词的模型 ID。",
|
|
108
|
+
sanitizePromptLabel: "提示词净化(兼容性)",
|
|
109
|
+
sanitizePromptHint: "部分上游(如 Antigravity 的 Gemini)会拒绝包含精确短语 “DeepSeek Harness” 的系统提示词并直接 429,CPA 还会据此给账号冷却。开启后,该账号请求的系统提示词中所有该短语会被整体替换为下面的文本,并删除已知会在上下文中触发拦截的语句(如 “The browser provides no implicit DOM, route, or screenshot context.”)。仅影响发往此账号的请求;对话历史中已有的提示词不受影响。",
|
|
110
|
+
sanitizePromptReplacementLabel: "替换文本",
|
|
111
|
+
sanitizePromptReplacementHint: "提示词中每个 “DeepSeek Harness” 短语整体替换为此文本,留空时使用默认值。例如开场白会变成 “You are an AI agent powered by <此文本>.”。",
|
|
107
112
|
refreshIntervalLabel: "自动刷新间隔",
|
|
108
113
|
searchModelsPlaceholder: "搜索模型 ID 或名称(如 claude-opus, gpt-6, gemini-4, swe)…",
|
|
109
114
|
filterAll: "全部发现",
|
|
@@ -625,12 +630,13 @@ window.__ModuleLoader__.load({
|
|
|
625
630
|
apiKeyHint: "Stored in the DSH credentials service ({ref}), never in settings files. Leave blank for a local CPA without a key.",
|
|
626
631
|
clearKeyBtn: "Clear Key",
|
|
627
632
|
protocolLabel: "Wire Protocol",
|
|
628
|
-
protocolHint: "Auto sends each model over its family's own protocol to avoid CPA translation
|
|
633
|
+
protocolHint: "Auto sends each model over its family's own protocol to avoid CPA translation: Claude uses Claude Messages, GPT / Grok use OpenAI Responses, Gemini uses Gemini (needs an API key; without one it falls back to OpenAI Chat), and everything else uses OpenAI Chat.",
|
|
629
634
|
protocolAuto: "Auto: native protocol per model family (recommended)",
|
|
630
635
|
protocolFixedPrefix: "Always use: ",
|
|
631
636
|
protocolNameCompletions: "OpenAI Chat",
|
|
632
637
|
protocolNameResponses: "OpenAI Responses",
|
|
633
638
|
protocolNameMessages: "Claude Messages",
|
|
639
|
+
protocolNameGemini: "Gemini",
|
|
634
640
|
modelProtocolLabel: "Request Protocol",
|
|
635
641
|
modelProtocolDefault: "Follow global setting",
|
|
636
642
|
modelProtocolHint: "Native protocol: ",
|
|
@@ -647,6 +653,10 @@ window.__ModuleLoader__.load({
|
|
|
647
653
|
excludePrefixLabel: "Exclude Keywords",
|
|
648
654
|
excludePrefixPlaceholder: "e.g. tts, image, video, zj/ (comma-separated)",
|
|
649
655
|
excludePrefixHint: "Additional rule: hide models matching any of these substrings.",
|
|
656
|
+
sanitizePromptLabel: "Prompt Sanitizing (compat)",
|
|
657
|
+
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.",
|
|
658
|
+
sanitizePromptReplacementLabel: "Replacement Text",
|
|
659
|
+
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
660
|
refreshIntervalLabel: "Auto Refresh",
|
|
651
661
|
searchModelsPlaceholder: "Search model ID or name (e.g. claude-opus, gpt-6, gemini-4)…",
|
|
652
662
|
filterAll: "All Discovered",
|
|
@@ -2137,7 +2147,7 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2137
2147
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2138
2148
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2139
2149
|
}
|
|
2140
|
-
.dcpa-menu-pop::before
|
|
2150
|
+
.dcpa-menu-pop::before {
|
|
2141
2151
|
content: "";
|
|
2142
2152
|
position: absolute;
|
|
2143
2153
|
inset: 0;
|
|
@@ -2192,6 +2202,11 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2192
2202
|
max-width: 280px;
|
|
2193
2203
|
padding: 8px 10px;
|
|
2194
2204
|
border-radius: var(--dsw-radius-md, 10px);
|
|
2205
|
+
/* Painted on the bubble itself, not a ::before layer, so a capped bubble
|
|
2206
|
+
that scrolls its own text keeps its background (same fix as the quota
|
|
2207
|
+
popover). */
|
|
2208
|
+
background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-layer-1));
|
|
2209
|
+
backdrop-filter: var(--dsw-menu-backdrop-filter, none);
|
|
2195
2210
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2196
2211
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2197
2212
|
color: var(--dsw-alias-label-primary);
|
|
@@ -2200,8 +2215,21 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2200
2215
|
font-weight: 400;
|
|
2201
2216
|
white-space: normal;
|
|
2202
2217
|
text-align: left;
|
|
2218
|
+
overscroll-behavior: contain;
|
|
2203
2219
|
}
|
|
2204
|
-
|
|
2220
|
+
/* Top layer (Popover API): free of the Settings dialog's clipping; InfoTip
|
|
2221
|
+
writes fixed viewport top / left. Reset the UA popover box (centered,
|
|
2222
|
+
inset 0, auto margin, border). */
|
|
2223
|
+
.dcpa-info-pop[popover] {
|
|
2224
|
+
position: fixed;
|
|
2225
|
+
inset: auto;
|
|
2226
|
+
margin: 0;
|
|
2227
|
+
border: 0;
|
|
2228
|
+
overflow: visible;
|
|
2229
|
+
}
|
|
2230
|
+
/* In-place fallback without the Popover API. */
|
|
2231
|
+
.dcpa-info-pop[data-layer="inline"][data-align="end"] { left: auto; right: -8px; }
|
|
2232
|
+
.dcpa-info-pop[data-layer="inline"][data-place="above"] { top: auto; bottom: calc(100% + 6px); }
|
|
2205
2233
|
.dcpa-savebar {
|
|
2206
2234
|
position: sticky;
|
|
2207
2235
|
bottom: 0;
|
|
@@ -2534,6 +2562,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
2534
2562
|
"openai-completions": "protocolNameCompletions",
|
|
2535
2563
|
"openai-responses": "protocolNameResponses",
|
|
2536
2564
|
"anthropic-messages": "protocolNameMessages",
|
|
2565
|
+
"google-generative-ai": "protocolNameGemini",
|
|
2537
2566
|
};
|
|
2538
2567
|
const PROTOCOLS = Object.keys(PROTOCOL_NAME_KEYS);
|
|
2539
2568
|
|
|
@@ -3413,25 +3442,148 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3413
3442
|
);
|
|
3414
3443
|
}
|
|
3415
3444
|
|
|
3445
|
+
// Gap between the help button and its bubble, the margin kept from the
|
|
3446
|
+
// edge of the visible area, and the smallest capped bubble height (px).
|
|
3447
|
+
const TIP_GAP = 6;
|
|
3448
|
+
const TIP_MARGIN = 8;
|
|
3449
|
+
const TIP_MIN_HEIGHT = 48;
|
|
3450
|
+
// The bubble's start edge sits this far before the button (matches the CSS).
|
|
3451
|
+
const TIP_INSET = 8;
|
|
3452
|
+
|
|
3453
|
+
function tipView() {
|
|
3454
|
+
return typeof window === "undefined" ? null : window;
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3457
|
+
/** Whether this browser can lift an in-slot element into the top layer. */
|
|
3458
|
+
function canUseTopLayer(pop) {
|
|
3459
|
+
return typeof pop?.showPopover === "function" && typeof pop?.setAttribute === "function";
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
/**
|
|
3463
|
+
* The area an in-place element can actually be seen in: the viewport
|
|
3464
|
+
* intersected with every ancestor that clips its overflow (the Settings
|
|
3465
|
+
* dialog body, scroll panes, popovers).
|
|
3466
|
+
*/
|
|
3467
|
+
function visibleBounds(el) {
|
|
3468
|
+
const view = tipView();
|
|
3469
|
+
let bounds = {
|
|
3470
|
+
top: 0,
|
|
3471
|
+
left: 0,
|
|
3472
|
+
right: view?.innerWidth ?? Infinity,
|
|
3473
|
+
bottom: view?.innerHeight ?? Infinity,
|
|
3474
|
+
};
|
|
3475
|
+
for (let node = el?.parentElement; node; node = node.parentElement) {
|
|
3476
|
+
const style = view?.getComputedStyle?.(node);
|
|
3477
|
+
if (!style) break;
|
|
3478
|
+
const clips = [style.overflow, style.overflowX, style.overflowY].some((v) => v && v !== "visible");
|
|
3479
|
+
if (!clips) continue;
|
|
3480
|
+
const r = node.getBoundingClientRect();
|
|
3481
|
+
bounds = {
|
|
3482
|
+
top: Math.max(bounds.top, r.top),
|
|
3483
|
+
left: Math.max(bounds.left, r.left),
|
|
3484
|
+
right: Math.min(bounds.right, r.right),
|
|
3485
|
+
bottom: Math.min(bounds.bottom, r.bottom),
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
return bounds;
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
/**
|
|
3492
|
+
* Place an open bubble next to its help button, writing only the bubble's
|
|
3493
|
+
* own position styles and data attributes.
|
|
3494
|
+
*
|
|
3495
|
+
* In the top layer (`topLayer`), the bubble is free of every clipping
|
|
3496
|
+
* ancestor and is laid out with fixed viewport coordinates: below the
|
|
3497
|
+
* button when it fits, otherwise on the roomier side, shifted back inside
|
|
3498
|
+
* the window horizontally, and capped with its own scrolling only when the
|
|
3499
|
+
* whole window cannot hold it. Without top-layer support it stays absolutely
|
|
3500
|
+
* positioned in place and the same rules apply within the visible area of
|
|
3501
|
+
* its clipping ancestors.
|
|
3502
|
+
*/
|
|
3503
|
+
function placeTip(anchor, pop, topLayer) {
|
|
3504
|
+
const view = tipView();
|
|
3505
|
+
const a = anchor?.getBoundingClientRect?.();
|
|
3506
|
+
if (!a || !pop?.style) return;
|
|
3507
|
+
const bounds = topLayer
|
|
3508
|
+
? { top: 0, left: 0, right: view?.innerWidth ?? Infinity, bottom: view?.innerHeight ?? Infinity }
|
|
3509
|
+
: visibleBounds(anchor);
|
|
3510
|
+
// Measure the natural size: drop any earlier cap first.
|
|
3511
|
+
pop.style.maxHeight = "";
|
|
3512
|
+
pop.style.overflowY = "";
|
|
3513
|
+
const natural = pop.getBoundingClientRect?.() ?? { width: 0, height: 0 };
|
|
3514
|
+
const height = Math.max(natural.height ?? 0, pop.scrollHeight ?? 0);
|
|
3515
|
+
const width = natural.width ?? 0;
|
|
3516
|
+
const below = bounds.bottom - a.bottom - TIP_GAP - TIP_MARGIN;
|
|
3517
|
+
const aboveRoom = a.top - bounds.top - TIP_GAP - TIP_MARGIN;
|
|
3518
|
+
const above = height > below && aboveRoom > below;
|
|
3519
|
+
const room = above ? aboveRoom : below;
|
|
3520
|
+
const shown = height > room ? Math.max(TIP_MIN_HEIGHT, Math.floor(room)) : height;
|
|
3521
|
+
if (height > room) {
|
|
3522
|
+
pop.style.maxHeight = `${shown}px`;
|
|
3523
|
+
pop.style.overflowY = "auto";
|
|
3524
|
+
}
|
|
3525
|
+
pop.setAttribute?.("data-place", above ? "above" : "below");
|
|
3526
|
+
if (topLayer) {
|
|
3527
|
+
const maxLeft = bounds.right - width - TIP_MARGIN;
|
|
3528
|
+
const left = Math.max(bounds.left + TIP_MARGIN, Math.min(a.left - TIP_INSET, maxLeft));
|
|
3529
|
+
const top = above ? a.top - TIP_GAP - shown : a.bottom + TIP_GAP;
|
|
3530
|
+
pop.style.left = `${Math.round(left)}px`;
|
|
3531
|
+
pop.style.top = `${Math.round(top)}px`;
|
|
3532
|
+
return;
|
|
3533
|
+
}
|
|
3534
|
+
// In place: open towards the roomier horizontal side of the visible area.
|
|
3535
|
+
pop.setAttribute?.("data-align", a.left - bounds.left > bounds.right - a.right ? "end" : "start");
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3416
3538
|
/**
|
|
3417
3539
|
* Small "i" help button: the explanation opens on hover, keyboard focus or
|
|
3418
3540
|
* click (touch), closes on Escape / leaving. The text stays in the locale
|
|
3419
3541
|
* dictionaries and is announced through aria-describedby.
|
|
3542
|
+
*
|
|
3543
|
+
* The bubble node is rendered inside this plugin's slot (plugins never
|
|
3544
|
+
* write to `document.body`) but is shown through the Popover API in the
|
|
3545
|
+
* browser's top layer, so it can extend past the Settings dialog instead of
|
|
3546
|
+
* being cut by its clipping containers. It follows its button while the
|
|
3547
|
+
* page scrolls or resizes. See {@link placeTip}.
|
|
3420
3548
|
*/
|
|
3421
3549
|
function InfoTip({ t, text }) {
|
|
3422
3550
|
const [open, setOpen] = useState(false);
|
|
3423
|
-
const [alignEnd, setAlignEnd] = useState(false);
|
|
3424
3551
|
const ref = useRef(null);
|
|
3552
|
+
const popRef = useRef(null);
|
|
3425
3553
|
const id = useMemo(() => `dcpa-tip-${Math.random().toString(36).slice(2, 9)}`, []);
|
|
3554
|
+
|
|
3555
|
+
// Show and place before paint so the bubble never flashes at a wrong spot.
|
|
3556
|
+
useLayoutEffect(() => {
|
|
3557
|
+
if (!open) return undefined;
|
|
3558
|
+
const anchor = ref.current;
|
|
3559
|
+
const pop = popRef.current;
|
|
3560
|
+
if (!anchor || !pop) return undefined;
|
|
3561
|
+
let topLayer = false;
|
|
3562
|
+
if (canUseTopLayer(pop)) {
|
|
3563
|
+
try {
|
|
3564
|
+
pop.setAttribute("popover", "manual");
|
|
3565
|
+
if (!pop.matches?.(":popover-open")) pop.showPopover();
|
|
3566
|
+
topLayer = true;
|
|
3567
|
+
} catch {
|
|
3568
|
+
pop.removeAttribute?.("popover");
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
pop.setAttribute?.("data-layer", topLayer ? "top" : "inline");
|
|
3572
|
+
const place = () => placeTip(anchor, pop, topLayer);
|
|
3573
|
+
place();
|
|
3574
|
+
const view = tipView();
|
|
3575
|
+
if (typeof view?.addEventListener !== "function") return undefined;
|
|
3576
|
+
// Capture scrolls of any pane (the Settings body scrolls, not the window).
|
|
3577
|
+
view.addEventListener("scroll", place, true);
|
|
3578
|
+
view.addEventListener("resize", place);
|
|
3579
|
+
return () => {
|
|
3580
|
+
view.removeEventListener("scroll", place, true);
|
|
3581
|
+
view.removeEventListener("resize", place);
|
|
3582
|
+
};
|
|
3583
|
+
}, [open, text]);
|
|
3584
|
+
|
|
3426
3585
|
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
|
-
};
|
|
3586
|
+
const show = () => setOpen(true);
|
|
3435
3587
|
return h(
|
|
3436
3588
|
"span",
|
|
3437
3589
|
{
|
|
@@ -3462,7 +3614,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3462
3614
|
},
|
|
3463
3615
|
"i"
|
|
3464
3616
|
),
|
|
3465
|
-
|
|
3617
|
+
// Unmounting a shown popover hides it, so closing needs no hidePopover().
|
|
3618
|
+
open ? h("span", { id, ref: popRef, role: "tooltip", className: "dcpa-info-pop" }, text) : null
|
|
3466
3619
|
);
|
|
3467
3620
|
}
|
|
3468
3621
|
|
|
@@ -3964,6 +4117,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3964
4117
|
const [apiKeyEnv, setApiKeyEnv] = useState("CLI_PROXY_API_KEY");
|
|
3965
4118
|
const [includePrefix, setIncludePrefix] = useState("");
|
|
3966
4119
|
const [excludePrefix, setExcludePrefix] = useState("");
|
|
4120
|
+
const [sanitizePrompt, setSanitizePrompt] = useState(false);
|
|
4121
|
+
const [sanitizePromptReplacement, setSanitizePromptReplacement] = useState("");
|
|
3967
4122
|
const [refreshIntervalSeconds, setRefreshIntervalSeconds] = useState("300");
|
|
3968
4123
|
const [probeTimeoutMs, setProbeTimeoutMs] = useState("5000");
|
|
3969
4124
|
|
|
@@ -3975,6 +4130,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3975
4130
|
apiKeyEnv: c.effectiveApiKeyEnv ?? c.apiKeyEnv ?? "CLI_PROXY_API_KEY",
|
|
3976
4131
|
includePrefix: c.includePrefix ?? "",
|
|
3977
4132
|
excludePrefix: c.excludePrefix ?? "",
|
|
4133
|
+
sanitizePrompt: c.sanitizePrompt === true,
|
|
4134
|
+
sanitizePromptReplacement: c.sanitizePromptReplacement ?? "",
|
|
3978
4135
|
refreshIntervalSeconds: String(global?.refreshIntervalSeconds ?? 300),
|
|
3979
4136
|
});
|
|
3980
4137
|
|
|
@@ -3989,6 +4146,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3989
4146
|
setApiKeyEnv(saved.apiKeyEnv);
|
|
3990
4147
|
setIncludePrefix(saved.includePrefix);
|
|
3991
4148
|
setExcludePrefix(saved.excludePrefix);
|
|
4149
|
+
setSanitizePrompt(saved.sanitizePrompt);
|
|
4150
|
+
setSanitizePromptReplacement(saved.sanitizePromptReplacement);
|
|
3992
4151
|
setRefreshIntervalSeconds(saved.refreshIntervalSeconds);
|
|
3993
4152
|
setProbeTimeoutMs(String(global?.probeTimeoutMs ?? 5000));
|
|
3994
4153
|
setApiKeyDraft("");
|
|
@@ -4033,6 +4192,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4033
4192
|
apiKeyEnv: apiKeyEnv.trim() || account.config?.apiKeyEnv || "CLI_PROXY_API_KEY",
|
|
4034
4193
|
includePrefix: includePrefix.trim(),
|
|
4035
4194
|
excludePrefix: excludePrefix.trim(),
|
|
4195
|
+
sanitizePrompt,
|
|
4196
|
+
sanitizePromptReplacement,
|
|
4036
4197
|
// Before the first catalog is seen, an empty draft is not a choice:
|
|
4037
4198
|
// leave the selection unset so the first probe can recommend one.
|
|
4038
4199
|
...(selectedIds.size > 0 || (account.status?.allModels?.length ?? 0) > 0
|
|
@@ -4101,6 +4262,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4101
4262
|
apiKeyEnv,
|
|
4102
4263
|
includePrefix,
|
|
4103
4264
|
excludePrefix,
|
|
4265
|
+
sanitizePrompt,
|
|
4266
|
+
sanitizePromptReplacement,
|
|
4104
4267
|
refreshIntervalSeconds,
|
|
4105
4268
|
};
|
|
4106
4269
|
const dirty =
|
|
@@ -4357,6 +4520,35 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4357
4520
|
})
|
|
4358
4521
|
)
|
|
4359
4522
|
),
|
|
4523
|
+
h(
|
|
4524
|
+
FieldRow,
|
|
4525
|
+
{ t, label: t("sanitizePromptLabel"), help: t("sanitizePromptHint"), htmlFor: `dcpa-sanitize-${account.id}` },
|
|
4526
|
+
h(
|
|
4527
|
+
"button",
|
|
4528
|
+
{
|
|
4529
|
+
id: `dcpa-sanitize-${account.id}`,
|
|
4530
|
+
type: "button",
|
|
4531
|
+
role: "switch",
|
|
4532
|
+
className: "dcpa-switch",
|
|
4533
|
+
"aria-checked": sanitizePrompt,
|
|
4534
|
+
"aria-label": t("sanitizePromptLabel"),
|
|
4535
|
+
onClick: () => setSanitizePrompt((v) => !v),
|
|
4536
|
+
},
|
|
4537
|
+
h("span", { className: "dcpa-switch-thumb" })
|
|
4538
|
+
)
|
|
4539
|
+
),
|
|
4540
|
+
h(
|
|
4541
|
+
FieldRow,
|
|
4542
|
+
{ t, label: t("sanitizePromptReplacementLabel"), help: t("sanitizePromptReplacementHint"), htmlFor: `dcpa-sanitize-repl-${account.id}` },
|
|
4543
|
+
h("input", {
|
|
4544
|
+
id: `dcpa-sanitize-repl-${account.id}`,
|
|
4545
|
+
className: "dcpa-q-input",
|
|
4546
|
+
value: sanitizePromptReplacement,
|
|
4547
|
+
placeholder: "Custom Harness",
|
|
4548
|
+
disabled: !sanitizePrompt,
|
|
4549
|
+
onChange: (e) => setSanitizePromptReplacement(e.target.value),
|
|
4550
|
+
})
|
|
4551
|
+
),
|
|
4360
4552
|
h(
|
|
4361
4553
|
FieldRow,
|
|
4362
4554
|
{ t, label: t("refreshIntervalLabel"), htmlFor: `dcpa-interval-${account.id}` },
|
|
@@ -5562,9 +5754,29 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5562
5754
|
return `${text} ${fmt(t, account.authPaused ? "qAuthPaused" : "qAuthRetrying", { n, max })}`;
|
|
5563
5755
|
}
|
|
5564
5756
|
|
|
5757
|
+
/** Whether a window covers only Gemini Argon models (Antigravity plans with a separate Argon quota). */
|
|
5758
|
+
function isArgonWindow(w) {
|
|
5759
|
+
const has = (list) => Array.isArray(list) && list.some((x) => String(x).toLowerCase().includes("argon"));
|
|
5760
|
+
return has(w.modelPrefixes) || has(w.modelIds);
|
|
5761
|
+
}
|
|
5762
|
+
|
|
5763
|
+
/**
|
|
5764
|
+
* Short names for Antigravity's quota pools ("Claude and GPT models",
|
|
5765
|
+
* "Gemini models", Argon limits), so rows in narrow popups stay on one
|
|
5766
|
+
* line; any other group name is shown as is.
|
|
5767
|
+
*/
|
|
5768
|
+
function windowGroupName(w) {
|
|
5769
|
+
if (isArgonWindow(w)) return "Argon";
|
|
5770
|
+
const s = String(w.group ?? "").trim().toLowerCase();
|
|
5771
|
+
if (s === "claude and gpt models") return "Claude/GPT";
|
|
5772
|
+
if (s === "gemini models") return "Gemini";
|
|
5773
|
+
return String(w.group ?? "");
|
|
5774
|
+
}
|
|
5775
|
+
|
|
5565
5776
|
function windowLabel(t, w) {
|
|
5566
5777
|
const base = WINDOW_KEYS[w.kind] !== undefined ? t(WINDOW_KEYS[w.kind]) : w.label || t("qWinOther");
|
|
5567
|
-
|
|
5778
|
+
const group = w.group ? windowGroupName(w) : "";
|
|
5779
|
+
return group ? `${group} · ${base}` : base;
|
|
5568
5780
|
}
|
|
5569
5781
|
|
|
5570
5782
|
function durationText(t, ms) {
|
|
@@ -5629,9 +5841,17 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5629
5841
|
return true;
|
|
5630
5842
|
}
|
|
5631
5843
|
|
|
5844
|
+
/**
|
|
5845
|
+
* Windows of one credential that apply to `modelId`. When a Gemini Argon
|
|
5846
|
+
* model has windows of its own, the general Gemini pool ("gemini" prefix)
|
|
5847
|
+
* does not limit it; without them it shares that pool.
|
|
5848
|
+
*/
|
|
5632
5849
|
function credentialWindows(cred, modelId) {
|
|
5633
5850
|
const windows = Array.isArray(cred?.windows) ? cred.windows : [];
|
|
5634
|
-
|
|
5851
|
+
if (!modelId) return windows;
|
|
5852
|
+
const applying = windows.filter((w) => windowAppliesTo(w, modelId));
|
|
5853
|
+
if (!bareModel(modelId).includes("argon") || !applying.some(isArgonWindow)) return applying;
|
|
5854
|
+
return applying.filter((w) => isArgonWindow(w) || !(Array.isArray(w.modelPrefixes) && w.modelPrefixes.length > 0));
|
|
5635
5855
|
}
|
|
5636
5856
|
|
|
5637
5857
|
/** 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
|
|
@@ -51,13 +53,16 @@ export const MAX_CATALOG_BYTES = 8 * 1024 * 1024;
|
|
|
51
53
|
export const PI_AI_NS = "llm-pi-ai";
|
|
52
54
|
export const REASONING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
53
55
|
/** Wire protocols the DSH llm-pi-ai adapter accepts on a hand-declared route. */
|
|
54
|
-
export const PROTOCOLS = ["openai-completions", "openai-responses", "anthropic-messages"];
|
|
56
|
+
export const PROTOCOLS = ["openai-completions", "openai-responses", "anthropic-messages", "google-generative-ai"];
|
|
55
57
|
/** Route-key suffix and display-name label of each protocol's route. */
|
|
56
58
|
export const PROTOCOL_ROUTES = {
|
|
57
59
|
"openai-completions": { suffix: "", label: "" },
|
|
58
60
|
"openai-responses": { suffix: "-responses", label: " (OpenAI Responses)" },
|
|
59
61
|
"anthropic-messages": { suffix: "-messages", label: " (Claude Messages)" },
|
|
62
|
+
"google-generative-ai": { suffix: "-gemini", label: " (Gemini)" },
|
|
60
63
|
};
|
|
64
|
+
/** The only thinking levels pi-ai's Gemini adapter can send (`thinkingLevel` / budget). */
|
|
65
|
+
export const GOOGLE_THINKING_LEVELS = ["minimal", "low", "medium", "high"];
|
|
61
66
|
export const DEFAULT_MODEL_NS = "agent-default-model";
|
|
62
67
|
export const REF_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
63
68
|
|
|
@@ -163,10 +168,7 @@ export function resolveConfig(rawConfig = {}) {
|
|
|
163
168
|
const apiKeyEnv = apiKeyEnvRaw || DEFAULT_API_KEY_ENV;
|
|
164
169
|
const baseURL = String(readVolatile(rawConfig?.baseURL, "")).trim();
|
|
165
170
|
const protocolRaw = String(readVolatile(rawConfig?.protocol, "openai-completions")).trim();
|
|
166
|
-
const protocol =
|
|
167
|
-
protocolRaw === "openai-responses" || protocolRaw === "anthropic-messages"
|
|
168
|
-
? protocolRaw
|
|
169
|
-
: "openai-completions";
|
|
171
|
+
const protocol = PROTOCOLS.includes(protocolRaw) ? protocolRaw : "openai-completions";
|
|
170
172
|
const protocolMode =
|
|
171
173
|
String(readVolatile(rawConfig?.protocolMode, "auto")).trim() === "fixed" ? "fixed" : "auto";
|
|
172
174
|
const refreshRaw = Number(
|
|
@@ -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();
|