dsh-cliproxyapi-pro 1.10.1 → 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 +24 -0
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/lib/client.js +618 -48
- package/lib/host/accounts.js +7 -2
- package/lib/host/apply/controller.js +24 -0
- package/lib/host/apply/quota-service.js +2 -1
- package/lib/host/apply-utils.js +2 -0
- package/lib/host/config.js +12 -1
- package/lib/host/controller.js +19 -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 +3 -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/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: "全部发现",
|
|
@@ -253,7 +257,7 @@ window.__ModuleLoader__.load({
|
|
|
253
257
|
tabSettings: "设置",
|
|
254
258
|
tabQuota: "额度",
|
|
255
259
|
qTitle: "CPA 渠道额度",
|
|
256
|
-
qSubtitle: "填写管理密钥后,查看 CPA
|
|
260
|
+
qSubtitle: "填写管理密钥后,查看 CPA 上每个渠道凭证的剩余额度;对话框模型选择器旁也会显示当前模型的额度,左侧边栏底部可快速查看所有账号的额度。",
|
|
257
261
|
qAccountsLabel: "选择账号",
|
|
258
262
|
qNoAccounts: "还没有 CLIProxyAPI 账号,请先在「设置」页添加并连接。",
|
|
259
263
|
qAccountDisabled: "账号未启用",
|
|
@@ -337,6 +341,15 @@ window.__ModuleLoader__.load({
|
|
|
337
341
|
qPeekLoading: "正在读取额度…",
|
|
338
342
|
qPeekFooter: "完整列表见 设置 → CLIProxyAPI → 额度",
|
|
339
343
|
qPeekBest: "最充足",
|
|
344
|
+
qSideLabel: "CPA 额度",
|
|
345
|
+
qSideCount: "{ok}/{n} 充足",
|
|
346
|
+
qSideAria: "CPA 额度:{n} 个可用凭证中 {ok} 个充足",
|
|
347
|
+
qSideSwitch: "在侧边栏显示额度",
|
|
348
|
+
qSideSwitchHint: "所有账号共用。开启后左侧边栏底部显示「CPA 额度」,汇总所有已启用、已填写管理密钥账号的凭证;关闭后侧边栏不再显示,也不再为它读取额度状态。也可以在侧边栏额度弹层底部点「从侧边栏隐藏」。",
|
|
349
|
+
qSideHide: "从侧边栏隐藏",
|
|
350
|
+
qSideHideFailed: "隐藏失败:{error}",
|
|
351
|
+
qSideOnToast: "已在侧边栏显示额度",
|
|
352
|
+
qSideOffToast: "已从侧边栏隐藏额度",
|
|
340
353
|
infoLabel: "说明",
|
|
341
354
|
tabConnection: "连接",
|
|
342
355
|
tabModels: "模型",
|
|
@@ -638,6 +651,10 @@ window.__ModuleLoader__.load({
|
|
|
638
651
|
excludePrefixLabel: "Exclude Keywords",
|
|
639
652
|
excludePrefixPlaceholder: "e.g. tts, image, video, zj/ (comma-separated)",
|
|
640
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>.\"",
|
|
641
658
|
refreshIntervalLabel: "Auto Refresh",
|
|
642
659
|
searchModelsPlaceholder: "Search model ID or name (e.g. claude-opus, gpt-6, gemini-4)…",
|
|
643
660
|
filterAll: "All Discovered",
|
|
@@ -787,7 +804,7 @@ window.__ModuleLoader__.load({
|
|
|
787
804
|
tabSettings: "Settings",
|
|
788
805
|
tabQuota: "Quota",
|
|
789
806
|
qTitle: "CPA Channel Quota",
|
|
790
|
-
qSubtitle: "With a management key, see the remaining quota of every channel credential on CPA; the composer also shows the current model's quota next to the model picker.",
|
|
807
|
+
qSubtitle: "With a management key, see the remaining quota of every channel credential on CPA; the composer also shows the current model's quota next to the model picker, and the sidebar footer gives a quick view of every account.",
|
|
791
808
|
qAccountsLabel: "Choose account",
|
|
792
809
|
qNoAccounts: "No CLIProxyAPI account yet. Add and connect one on the Settings tab first.",
|
|
793
810
|
qAccountDisabled: "Account disabled",
|
|
@@ -871,6 +888,15 @@ window.__ModuleLoader__.load({
|
|
|
871
888
|
qPeekLoading: "Loading quota…",
|
|
872
889
|
qPeekFooter: "Full list in Settings → CLIProxyAPI → Quota",
|
|
873
890
|
qPeekBest: "Best",
|
|
891
|
+
qSideLabel: "CPA Quota",
|
|
892
|
+
qSideCount: "{ok}/{n} healthy",
|
|
893
|
+
qSideAria: "CPA quota: {ok} of {n} usable credentials healthy",
|
|
894
|
+
qSideSwitch: "Show quota in the sidebar",
|
|
895
|
+
qSideSwitchHint: "Shared by all accounts. When on, the bottom of the left sidebar shows CPA Quota, summing up the credentials of every enabled account with a management key; when off, the sidebar shows nothing and stops reading quota status for it. You can also click Hide from sidebar at the bottom of the sidebar quota peek.",
|
|
896
|
+
qSideHide: "Hide from sidebar",
|
|
897
|
+
qSideHideFailed: "Could not hide: {error}",
|
|
898
|
+
qSideOnToast: "Quota shown in the sidebar",
|
|
899
|
+
qSideOffToast: "Quota hidden from the sidebar",
|
|
874
900
|
infoLabel: "More info",
|
|
875
901
|
tabConnection: "Connection",
|
|
876
902
|
tabModels: "Models",
|
|
@@ -2119,7 +2145,7 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2119
2145
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2120
2146
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2121
2147
|
}
|
|
2122
|
-
.dcpa-menu-pop::before
|
|
2148
|
+
.dcpa-menu-pop::before {
|
|
2123
2149
|
content: "";
|
|
2124
2150
|
position: absolute;
|
|
2125
2151
|
inset: 0;
|
|
@@ -2174,6 +2200,11 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2174
2200
|
max-width: 280px;
|
|
2175
2201
|
padding: 8px 10px;
|
|
2176
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);
|
|
2177
2208
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2178
2209
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2179
2210
|
color: var(--dsw-alias-label-primary);
|
|
@@ -2182,8 +2213,21 @@ select.dcpa-q-input { appearance: auto; padding-right: 8px; }
|
|
|
2182
2213
|
font-weight: 400;
|
|
2183
2214
|
white-space: normal;
|
|
2184
2215
|
text-align: left;
|
|
2216
|
+
overscroll-behavior: contain;
|
|
2185
2217
|
}
|
|
2186
|
-
|
|
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); }
|
|
2187
2231
|
.dcpa-savebar {
|
|
2188
2232
|
position: sticky;
|
|
2189
2233
|
bottom: 0;
|
|
@@ -2432,21 +2476,13 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
2432
2476
|
border-radius: var(--dsw-radius-lg, 12px);
|
|
2433
2477
|
--dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
|
|
2434
2478
|
box-shadow: var(--dsw-elevation-prominent, 0 8px 24px var(--dsw-alias-border-l2));
|
|
2479
|
+
background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-layer-1));
|
|
2480
|
+
backdrop-filter: var(--dsw-menu-backdrop-filter, none);
|
|
2435
2481
|
color: var(--dsw-alias-label-primary);
|
|
2436
2482
|
font-size: 13px;
|
|
2437
2483
|
line-height: 20px;
|
|
2438
2484
|
text-align: left;
|
|
2439
2485
|
}
|
|
2440
|
-
.dcpa-q-pop::before {
|
|
2441
|
-
content: "";
|
|
2442
|
-
position: absolute;
|
|
2443
|
-
inset: 0;
|
|
2444
|
-
z-index: -1;
|
|
2445
|
-
border-radius: inherit;
|
|
2446
|
-
background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-layer-1));
|
|
2447
|
-
backdrop-filter: var(--dsw-menu-backdrop-filter, none);
|
|
2448
|
-
pointer-events: none;
|
|
2449
|
-
}
|
|
2450
2486
|
.dcpa-q-pop-head { padding: 8px 8px 6px; }
|
|
2451
2487
|
.dcpa-q-pop-model { font-weight: 500; overflow-wrap: anywhere; }
|
|
2452
2488
|
.dcpa-q-pop-sub { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
@@ -2476,7 +2512,48 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
2476
2512
|
font-size: 12px;
|
|
2477
2513
|
color: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
|
|
2478
2514
|
}
|
|
2479
|
-
|
|
2515
|
+
|
|
2516
|
+
/* ---- Sidebar footer entry: same metrics as DSH's native footer buttons ---- */
|
|
2517
|
+
.dcpa-q-side { display: flex; align-items: center; width: 100%; min-width: 0; }
|
|
2518
|
+
.dcpa-q-side[data-wide="false"] { width: 36px; height: 36px; }
|
|
2519
|
+
.dcpa-q-side-btn {
|
|
2520
|
+
box-sizing: border-box;
|
|
2521
|
+
display: inline-flex;
|
|
2522
|
+
align-items: center;
|
|
2523
|
+
gap: 8px;
|
|
2524
|
+
width: calc(100% + 4px);
|
|
2525
|
+
height: 42px;
|
|
2526
|
+
margin: 0 -2px;
|
|
2527
|
+
padding: 0 10px 0 8px;
|
|
2528
|
+
border: none;
|
|
2529
|
+
border-radius: var(--dsw-radius-lg, 12px);
|
|
2530
|
+
background: transparent;
|
|
2531
|
+
color: var(--dsw-alias-label-primary);
|
|
2532
|
+
font: inherit;
|
|
2533
|
+
font-size: 14px;
|
|
2534
|
+
cursor: pointer;
|
|
2535
|
+
overflow: hidden;
|
|
2536
|
+
}
|
|
2537
|
+
.dcpa-q-side-btn:hover, .dcpa-q-side-btn[aria-expanded="true"] {
|
|
2538
|
+
background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2));
|
|
2539
|
+
}
|
|
2540
|
+
.dcpa-q-side[data-wide="false"] .dcpa-q-side-btn { width: 36px; height: 36px; margin: 0; padding: 0; gap: 0; justify-content: center; border-radius: 50%; }
|
|
2541
|
+
.dcpa-q-side-btn .dcpa-q-bars { flex: none; justify-content: center; width: 16px; }
|
|
2542
|
+
.dcpa-q-side-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2543
|
+
.dcpa-q-side-count {
|
|
2544
|
+
flex: none;
|
|
2545
|
+
margin-left: auto;
|
|
2546
|
+
font-size: 12px;
|
|
2547
|
+
line-height: 16px;
|
|
2548
|
+
color: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
|
|
2549
|
+
font-variant-numeric: tabular-nums;
|
|
2550
|
+
}
|
|
2551
|
+
.dcpa-q-side-count[data-level="low"] { color: var(--dsw-alias-state-warn-primary); }
|
|
2552
|
+
.dcpa-q-side-count[data-level="empty"] { color: var(--dsw-alias-state-error-primary); }
|
|
2553
|
+
.dcpa-q-side-acct + .dcpa-q-side-acct { margin-top: 8px; }
|
|
2554
|
+
.dcpa-q-side-pop .dcpa-q-summary { padding: 0 8px 4px; }
|
|
2555
|
+
.dcpa-q-side-pop .dcpa-q-side-hint { padding-top: 6px; }
|
|
2556
|
+
.dcpa-q-side-foot { margin-top: 8px; }`;
|
|
2480
2557
|
|
|
2481
2558
|
const REASONING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
2482
2559
|
const PROTOCOL_NAME_KEYS = {
|
|
@@ -3362,25 +3439,148 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3362
3439
|
);
|
|
3363
3440
|
}
|
|
3364
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
|
+
|
|
3365
3535
|
/**
|
|
3366
3536
|
* Small "i" help button: the explanation opens on hover, keyboard focus or
|
|
3367
3537
|
* click (touch), closes on Escape / leaving. The text stays in the locale
|
|
3368
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}.
|
|
3369
3545
|
*/
|
|
3370
3546
|
function InfoTip({ t, text }) {
|
|
3371
3547
|
const [open, setOpen] = useState(false);
|
|
3372
|
-
const [alignEnd, setAlignEnd] = useState(false);
|
|
3373
3548
|
const ref = useRef(null);
|
|
3549
|
+
const popRef = useRef(null);
|
|
3374
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
|
+
|
|
3375
3582
|
if (!text) return null;
|
|
3376
|
-
|
|
3377
|
-
const show = () => {
|
|
3378
|
-
const el = ref.current;
|
|
3379
|
-
const box = el?.closest?.(".dcpa-wrap, .dcpa-q-pop")?.getBoundingClientRect?.();
|
|
3380
|
-
const r = el?.getBoundingClientRect?.();
|
|
3381
|
-
if (box && r) setAlignEnd(r.left - box.left > box.width / 2);
|
|
3382
|
-
setOpen(true);
|
|
3383
|
-
};
|
|
3583
|
+
const show = () => setOpen(true);
|
|
3384
3584
|
return h(
|
|
3385
3585
|
"span",
|
|
3386
3586
|
{
|
|
@@ -3411,7 +3611,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3411
3611
|
},
|
|
3412
3612
|
"i"
|
|
3413
3613
|
),
|
|
3414
|
-
|
|
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
|
|
3415
3616
|
);
|
|
3416
3617
|
}
|
|
3417
3618
|
|
|
@@ -3454,7 +3655,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3454
3655
|
}
|
|
3455
3656
|
|
|
3456
3657
|
/**
|
|
3457
|
-
* The CLIProxyAPI settings section:
|
|
3658
|
+
* The CLIProxyAPI settings section: the all-account sidebar-quota switch,
|
|
3659
|
+
* one account bar for every tab, then the
|
|
3458
3660
|
* selected account's header, its 连接 / 模型 / 额度 tabs and one save bar.
|
|
3459
3661
|
* Owns the account server data; the add-account form creates an account only
|
|
3460
3662
|
* when the user connects it.
|
|
@@ -3548,6 +3750,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3548
3750
|
run("patch", async () => {
|
|
3549
3751
|
setData(await postJson(API.save, { ...patch, accountId }));
|
|
3550
3752
|
if (okText) setNotice({ tone: "ok", text: okText });
|
|
3753
|
+
return true;
|
|
3551
3754
|
}),
|
|
3552
3755
|
test: (accountId, draft) =>
|
|
3553
3756
|
run("test", async () => (await postJson(API.testAccount, { ...(accountId ? { accountId } : {}), ...draft })).test),
|
|
@@ -3585,11 +3788,31 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3585
3788
|
}),
|
|
3586
3789
|
};
|
|
3587
3790
|
|
|
3791
|
+
// The sidebar peek's "hide" button (or this switch) changed the global:
|
|
3792
|
+
// follow it here without reloading the drafts.
|
|
3793
|
+
useEffect(() => {
|
|
3794
|
+
const listener = (on) =>
|
|
3795
|
+
setData((d) => (d && d.global?.sidebarQuota !== on ? { ...d, global: { ...d.global, sidebarQuota: on } } : d));
|
|
3796
|
+
sidebarQuotaListeners.add(listener);
|
|
3797
|
+
return () => {
|
|
3798
|
+
sidebarQuotaListeners.delete(listener);
|
|
3799
|
+
};
|
|
3800
|
+
}, []);
|
|
3801
|
+
const toggleSidebarQuota = (next) =>
|
|
3802
|
+
void run("patch", async () => {
|
|
3803
|
+
setData(await saveSidebarQuota(next));
|
|
3804
|
+
setNotice({ tone: "ok", text: next ? t("qSideOnToast") : t("qSideOffToast") });
|
|
3805
|
+
});
|
|
3806
|
+
|
|
3588
3807
|
const showAdd = adding || (!loading && data !== null && accounts.length === 0);
|
|
3589
3808
|
|
|
3590
3809
|
return h(
|
|
3591
3810
|
"div",
|
|
3592
3811
|
{ className: "dcpa-wrap dcpa-q", "data-dsh-plugin": MODULE_ID },
|
|
3812
|
+
// All-account settings that are not part of any account draft.
|
|
3813
|
+
data !== null
|
|
3814
|
+
? h(SidebarQuotaSwitch, { t, on: data.global?.sidebarQuota !== false, busy: busy !== null, onToggle: toggleSidebarQuota })
|
|
3815
|
+
: null,
|
|
3593
3816
|
h(
|
|
3594
3817
|
"div",
|
|
3595
3818
|
{ className: "dcpa-acct-bar" },
|
|
@@ -3891,6 +4114,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3891
4114
|
const [apiKeyEnv, setApiKeyEnv] = useState("CLI_PROXY_API_KEY");
|
|
3892
4115
|
const [includePrefix, setIncludePrefix] = useState("");
|
|
3893
4116
|
const [excludePrefix, setExcludePrefix] = useState("");
|
|
4117
|
+
const [sanitizePrompt, setSanitizePrompt] = useState(false);
|
|
4118
|
+
const [sanitizePromptReplacement, setSanitizePromptReplacement] = useState("");
|
|
3894
4119
|
const [refreshIntervalSeconds, setRefreshIntervalSeconds] = useState("300");
|
|
3895
4120
|
const [probeTimeoutMs, setProbeTimeoutMs] = useState("5000");
|
|
3896
4121
|
|
|
@@ -3902,6 +4127,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3902
4127
|
apiKeyEnv: c.effectiveApiKeyEnv ?? c.apiKeyEnv ?? "CLI_PROXY_API_KEY",
|
|
3903
4128
|
includePrefix: c.includePrefix ?? "",
|
|
3904
4129
|
excludePrefix: c.excludePrefix ?? "",
|
|
4130
|
+
sanitizePrompt: c.sanitizePrompt === true,
|
|
4131
|
+
sanitizePromptReplacement: c.sanitizePromptReplacement ?? "",
|
|
3905
4132
|
refreshIntervalSeconds: String(global?.refreshIntervalSeconds ?? 300),
|
|
3906
4133
|
});
|
|
3907
4134
|
|
|
@@ -3916,6 +4143,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3916
4143
|
setApiKeyEnv(saved.apiKeyEnv);
|
|
3917
4144
|
setIncludePrefix(saved.includePrefix);
|
|
3918
4145
|
setExcludePrefix(saved.excludePrefix);
|
|
4146
|
+
setSanitizePrompt(saved.sanitizePrompt);
|
|
4147
|
+
setSanitizePromptReplacement(saved.sanitizePromptReplacement);
|
|
3919
4148
|
setRefreshIntervalSeconds(saved.refreshIntervalSeconds);
|
|
3920
4149
|
setProbeTimeoutMs(String(global?.probeTimeoutMs ?? 5000));
|
|
3921
4150
|
setApiKeyDraft("");
|
|
@@ -3960,6 +4189,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
3960
4189
|
apiKeyEnv: apiKeyEnv.trim() || account.config?.apiKeyEnv || "CLI_PROXY_API_KEY",
|
|
3961
4190
|
includePrefix: includePrefix.trim(),
|
|
3962
4191
|
excludePrefix: excludePrefix.trim(),
|
|
4192
|
+
sanitizePrompt,
|
|
4193
|
+
sanitizePromptReplacement,
|
|
3963
4194
|
// Before the first catalog is seen, an empty draft is not a choice:
|
|
3964
4195
|
// leave the selection unset so the first probe can recommend one.
|
|
3965
4196
|
...(selectedIds.size > 0 || (account.status?.allModels?.length ?? 0) > 0
|
|
@@ -4028,6 +4259,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4028
4259
|
apiKeyEnv,
|
|
4029
4260
|
includePrefix,
|
|
4030
4261
|
excludePrefix,
|
|
4262
|
+
sanitizePrompt,
|
|
4263
|
+
sanitizePromptReplacement,
|
|
4031
4264
|
refreshIntervalSeconds,
|
|
4032
4265
|
};
|
|
4033
4266
|
const dirty =
|
|
@@ -4284,6 +4517,35 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4284
4517
|
})
|
|
4285
4518
|
)
|
|
4286
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
|
+
),
|
|
4287
4549
|
h(
|
|
4288
4550
|
FieldRow,
|
|
4289
4551
|
{ t, label: t("refreshIntervalLabel"), htmlFor: `dcpa-interval-${account.id}` },
|
|
@@ -5489,9 +5751,29 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5489
5751
|
return `${text} ${fmt(t, account.authPaused ? "qAuthPaused" : "qAuthRetrying", { n, max })}`;
|
|
5490
5752
|
}
|
|
5491
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
|
+
|
|
5492
5773
|
function windowLabel(t, w) {
|
|
5493
5774
|
const base = WINDOW_KEYS[w.kind] !== undefined ? t(WINDOW_KEYS[w.kind]) : w.label || t("qWinOther");
|
|
5494
|
-
|
|
5775
|
+
const group = w.group ? windowGroupName(w) : "";
|
|
5776
|
+
return group ? `${group} · ${base}` : base;
|
|
5495
5777
|
}
|
|
5496
5778
|
|
|
5497
5779
|
function durationText(t, ms) {
|
|
@@ -5556,9 +5838,17 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5556
5838
|
return true;
|
|
5557
5839
|
}
|
|
5558
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
|
+
*/
|
|
5559
5846
|
function credentialWindows(cred, modelId) {
|
|
5560
5847
|
const windows = Array.isArray(cred?.windows) ? cred.windows : [];
|
|
5561
|
-
|
|
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));
|
|
5562
5852
|
}
|
|
5563
5853
|
|
|
5564
5854
|
/** The tightest remaining percentage of the windows that apply, or null. */
|
|
@@ -5760,18 +6050,24 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5760
6050
|
/** Subscribe a component to the shared quota store (null when inactive). */
|
|
5761
6051
|
function useQuota(store) {
|
|
5762
6052
|
const [, setTick] = useState(0);
|
|
6053
|
+
const snapshot = store ? store.getSnapshot() : { data: null, loading: false, error: null, busy: null };
|
|
6054
|
+
// The snapshot this render used: another subscriber's load can finish
|
|
6055
|
+
// between this render and the effect below, without notifying us.
|
|
6056
|
+
const rendered = useRef(snapshot);
|
|
6057
|
+
rendered.current = snapshot;
|
|
5763
6058
|
useEffect(() => {
|
|
5764
6059
|
if (store === null || store === undefined) return undefined;
|
|
5765
6060
|
let alive = true;
|
|
5766
6061
|
const off = store.subscribe(() => {
|
|
5767
6062
|
if (alive) setTick((n) => n + 1);
|
|
5768
6063
|
});
|
|
6064
|
+
if (store.getSnapshot() !== rendered.current) setTick((n) => n + 1);
|
|
5769
6065
|
return () => {
|
|
5770
6066
|
alive = false;
|
|
5771
6067
|
off();
|
|
5772
6068
|
};
|
|
5773
6069
|
}, [store]);
|
|
5774
|
-
return
|
|
6070
|
+
return snapshot;
|
|
5775
6071
|
}
|
|
5776
6072
|
|
|
5777
6073
|
/**
|
|
@@ -5822,6 +6118,16 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5822
6118
|
} catch {}
|
|
5823
6119
|
}
|
|
5824
6120
|
};
|
|
6121
|
+
// The Quota tab's sidebar switch tells the sidebar entry on this page
|
|
6122
|
+
// (which stops reading quota status while switched off).
|
|
6123
|
+
const sidebarQuotaListeners = new Set();
|
|
6124
|
+
const announceSidebarQuota = (on) => {
|
|
6125
|
+
for (const fn of [...sidebarQuotaListeners]) {
|
|
6126
|
+
try {
|
|
6127
|
+
fn(on === true);
|
|
6128
|
+
} catch {}
|
|
6129
|
+
}
|
|
6130
|
+
};
|
|
5825
6131
|
|
|
5826
6132
|
/**
|
|
5827
6133
|
* Composer placement announces itself for its session; hero placement
|
|
@@ -5992,6 +6298,33 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5992
6298
|
return bounds;
|
|
5993
6299
|
}
|
|
5994
6300
|
|
|
6301
|
+
/**
|
|
6302
|
+
* Close an open peek on a press outside `wrapRef` (the peek renders inside
|
|
6303
|
+
* it) or on Escape, which returns focus to `buttonRef`.
|
|
6304
|
+
*/
|
|
6305
|
+
function useDismissPeek(open, wrapRef, buttonRef, close) {
|
|
6306
|
+
const closeRef = useRef(close);
|
|
6307
|
+
closeRef.current = close;
|
|
6308
|
+
useEffect(() => {
|
|
6309
|
+
if (!open || typeof document === "undefined") return undefined;
|
|
6310
|
+
const onDown = (e) => {
|
|
6311
|
+
if (wrapRef.current && !wrapRef.current.contains(e.target)) closeRef.current();
|
|
6312
|
+
};
|
|
6313
|
+
const onKey = (e) => {
|
|
6314
|
+
if (e.key === "Escape") {
|
|
6315
|
+
closeRef.current();
|
|
6316
|
+
buttonRef.current?.focus?.();
|
|
6317
|
+
}
|
|
6318
|
+
};
|
|
6319
|
+
document.addEventListener("mousedown", onDown, true);
|
|
6320
|
+
document.addEventListener("keydown", onKey, true);
|
|
6321
|
+
return () => {
|
|
6322
|
+
document.removeEventListener("mousedown", onDown, true);
|
|
6323
|
+
document.removeEventListener("keydown", onKey, true);
|
|
6324
|
+
};
|
|
6325
|
+
}, [open]);
|
|
6326
|
+
}
|
|
6327
|
+
|
|
5995
6328
|
/**
|
|
5996
6329
|
* Style for a fixed peek anchored above `anchorRef`, rendered with
|
|
5997
6330
|
* `ref: popRef` inside the same component. Tracks the anchor every frame
|
|
@@ -6502,24 +6835,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
6502
6835
|
const summary = selection ? summarizeModelQuota(snap.data, selection.provider, selection.model) : null;
|
|
6503
6836
|
const visible = !shadowed && summary !== null && summary.account.keyConfigured === true;
|
|
6504
6837
|
|
|
6505
|
-
|
|
6506
|
-
if (!open) return undefined;
|
|
6507
|
-
const onDown = (e) => {
|
|
6508
|
-
if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false);
|
|
6509
|
-
};
|
|
6510
|
-
const onKey = (e) => {
|
|
6511
|
-
if (e.key === "Escape") {
|
|
6512
|
-
setOpen(false);
|
|
6513
|
-
buttonRef.current?.focus?.();
|
|
6514
|
-
}
|
|
6515
|
-
};
|
|
6516
|
-
document.addEventListener("mousedown", onDown, true);
|
|
6517
|
-
document.addEventListener("keydown", onKey, true);
|
|
6518
|
-
return () => {
|
|
6519
|
-
document.removeEventListener("mousedown", onDown, true);
|
|
6520
|
-
document.removeEventListener("keydown", onKey, true);
|
|
6521
|
-
};
|
|
6522
|
-
}, [open]);
|
|
6838
|
+
useDismissPeek(open, wrapRef, buttonRef, () => setOpen(false));
|
|
6523
6839
|
|
|
6524
6840
|
useEffect(() => {
|
|
6525
6841
|
if (!visible && open) setOpen(false);
|
|
@@ -6614,6 +6930,244 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
6614
6930
|
|
|
6615
6931
|
// #endregion
|
|
6616
6932
|
|
|
6933
|
+
/** Accounts the sidebar summarizes: enabled, with a management key. */
|
|
6934
|
+
function sidebarQuotaAccounts(data) {
|
|
6935
|
+
const accounts = Array.isArray(data?.accounts) ? data.accounts : [];
|
|
6936
|
+
return accounts.filter((a) => a.keyConfigured === true && a.enabled !== false);
|
|
6937
|
+
}
|
|
6938
|
+
|
|
6939
|
+
/**
|
|
6940
|
+
* Totals over the credentials of those accounts. `usable` leaves out
|
|
6941
|
+
* disabled / failing credentials; the level is the signal-bar fill.
|
|
6942
|
+
*/
|
|
6943
|
+
function sidebarQuotaSummary(accounts) {
|
|
6944
|
+
const credentials = accounts.flatMap((a) => (Array.isArray(a.credentials) ? a.credentials : []));
|
|
6945
|
+
const stats = quotaStats(credentials);
|
|
6946
|
+
const usable = stats.total - stats.issue;
|
|
6947
|
+
let level = "unknown";
|
|
6948
|
+
if (stats.healthy > 0) level = stats.healthy * 2 >= usable ? "ok" : "mid";
|
|
6949
|
+
else if (stats.low > 0) level = "low";
|
|
6950
|
+
else if (stats.empty > 0) level = "empty";
|
|
6951
|
+
const loading = accounts.every((a) => a.fetchedAt === undefined && a.errorCode === undefined);
|
|
6952
|
+
return { stats, usable, level, loading };
|
|
6953
|
+
}
|
|
6954
|
+
|
|
6955
|
+
/**
|
|
6956
|
+
* Save the global `sidebarQuota` switch (a globals-only save leaves every
|
|
6957
|
+
* account alone) and tell this page's sidebar entry and settings section.
|
|
6958
|
+
*/
|
|
6959
|
+
async function saveSidebarQuota(on) {
|
|
6960
|
+
const body = await postJson(API.save, { sidebarQuota: on === true });
|
|
6961
|
+
announceSidebarQuota(body?.global?.sidebarQuota !== false);
|
|
6962
|
+
return body;
|
|
6963
|
+
}
|
|
6964
|
+
|
|
6965
|
+
/**
|
|
6966
|
+
* The all-account switch at the top of the CLIProxyAPI settings section
|
|
6967
|
+
* (the sidebar peek also has a "hide" button for the same setting).
|
|
6968
|
+
*/
|
|
6969
|
+
function SidebarQuotaSwitch({ t, on, busy, onToggle }) {
|
|
6970
|
+
return h(
|
|
6971
|
+
"div",
|
|
6972
|
+
{ className: "dcpa-q-row dcpa-q-side-switch" },
|
|
6973
|
+
h(
|
|
6974
|
+
"div",
|
|
6975
|
+
{ className: "dcpa-q-row-main" },
|
|
6976
|
+
h("div", { className: "dcpa-q-title" }, t("qSideSwitch"), h(InfoTip, { t, text: t("qSideSwitchHint") }))
|
|
6977
|
+
),
|
|
6978
|
+
h(
|
|
6979
|
+
"div",
|
|
6980
|
+
{ className: "dcpa-q-actions" },
|
|
6981
|
+
h(
|
|
6982
|
+
"button",
|
|
6983
|
+
{
|
|
6984
|
+
type: "button",
|
|
6985
|
+
role: "switch",
|
|
6986
|
+
className: "dcpa-switch",
|
|
6987
|
+
"aria-checked": on,
|
|
6988
|
+
"aria-label": t("qSideSwitch"),
|
|
6989
|
+
disabled: busy,
|
|
6990
|
+
onClick: () => onToggle(!on),
|
|
6991
|
+
},
|
|
6992
|
+
h("span", { className: "dcpa-switch-thumb" })
|
|
6993
|
+
)
|
|
6994
|
+
)
|
|
6995
|
+
);
|
|
6996
|
+
}
|
|
6997
|
+
|
|
6998
|
+
/** Problems last, then least remaining first, like the Quota tab. */
|
|
6999
|
+
function sidebarCredentialOrder(a, b) {
|
|
7000
|
+
const rank = (c) => (c.status !== "active" ? 1 : 0);
|
|
7001
|
+
return rank(a) - rank(b) || (credentialHeadroom(a) ?? 101) - (credentialHeadroom(b) ?? 101);
|
|
7002
|
+
}
|
|
7003
|
+
|
|
7004
|
+
function SidebarQuotaAccount({ t, account, snap, store, now }) {
|
|
7005
|
+
const credentials = Array.isArray(account.credentials) ? [...account.credentials].sort(sidebarCredentialOrder) : [];
|
|
7006
|
+
const errorText = quotaErrorText(t, account);
|
|
7007
|
+
const refreshing = account.refreshing === true || (snap.busy === "refresh" && snap.busyAccount === account.accountId);
|
|
7008
|
+
const loadingFirst = account.fetchedAt === undefined && errorText === null;
|
|
7009
|
+
return h(
|
|
7010
|
+
"section",
|
|
7011
|
+
{ className: "dcpa-q-side-acct", "aria-label": account.displayName || account.accountId },
|
|
7012
|
+
h(
|
|
7013
|
+
"div",
|
|
7014
|
+
{ className: "dcpa-q-pop-head" },
|
|
7015
|
+
h("div", { className: "dcpa-q-pop-model" }, account.displayName || account.accountId),
|
|
7016
|
+
h("div", { className: "dcpa-q-pop-sub" }, fmt(t, "qTotalCreds", { n: credentials.length }))
|
|
7017
|
+
),
|
|
7018
|
+
errorText ? h("p", { className: "dcpa-q-pop-text", "data-tone": "error" }, errorText) : null,
|
|
7019
|
+
loadingFirst ? h("p", { className: "dcpa-q-pop-text" }, t("qPeekLoading")) : null,
|
|
7020
|
+
!loadingFirst && credentials.length === 0 && account.state === "ok" ? h("p", { className: "dcpa-q-pop-text" }, t("qNoCredentials")) : null,
|
|
7021
|
+
credentials.length > 0 ? h(QuotaSummary, { t, credentials }) : null,
|
|
7022
|
+
credentials.map((cred) =>
|
|
7023
|
+
h(
|
|
7024
|
+
"div",
|
|
7025
|
+
{ key: cred.id, className: "dcpa-q-pop-cred" },
|
|
7026
|
+
h(
|
|
7027
|
+
"div",
|
|
7028
|
+
{ className: "dcpa-q-pop-who" },
|
|
7029
|
+
h("span", { className: "dcpa-q-tag" }, providerName(t, cred.provider)),
|
|
7030
|
+
h("span", { className: "dcpa-q-name", title: cred.label || cred.id }, cred.label || cred.id),
|
|
7031
|
+
CredentialTags({ t, cred })
|
|
7032
|
+
),
|
|
7033
|
+
h(CredentialWindows, { t, cred, windows: credentialWindows(cred), now })
|
|
7034
|
+
)
|
|
7035
|
+
),
|
|
7036
|
+
h(
|
|
7037
|
+
"div",
|
|
7038
|
+
{ className: "dcpa-q-pop-foot" },
|
|
7039
|
+
h("span", null,
|
|
7040
|
+
account.fetchedAt ? fmt(t, "qUpdated", { time: agoText(t, account.fetchedAt, now) }) : t("qNeverUpdated"),
|
|
7041
|
+
account.autoRefreshPaused === true ? ` · ${t("qAccountPaused")}` : ""),
|
|
7042
|
+
h(
|
|
7043
|
+
"button",
|
|
7044
|
+
{
|
|
7045
|
+
type: "button",
|
|
7046
|
+
className: "dcpa-q-btn",
|
|
7047
|
+
disabled: snap.busy !== null || refreshing,
|
|
7048
|
+
onClick: () => void store?.refresh(account.accountId),
|
|
7049
|
+
},
|
|
7050
|
+
refreshing ? t("qRefreshing") : t("qRefresh")
|
|
7051
|
+
)
|
|
7052
|
+
)
|
|
7053
|
+
);
|
|
7054
|
+
}
|
|
7055
|
+
|
|
7056
|
+
/**
|
|
7057
|
+
* `sidebar.footer.action`: signal bars for the credentials of every enabled
|
|
7058
|
+
* account with a management key (label and healthy count while the
|
|
7059
|
+
* sidebar is wide); click opens a peek listing them per account. Renders
|
|
7060
|
+
* nothing until such an account exists. Same shared store as the badge.
|
|
7061
|
+
*
|
|
7062
|
+
* The global `sidebarQuota` switch arrives as `sidebar` in the quota
|
|
7063
|
+
* snapshot. Once it reads off, the entry unsubscribes, so it adds no
|
|
7064
|
+
* status polling; the Quota tab's switch on this page announces changes
|
|
7065
|
+
* (an in-page answer then wins over the last snapshot).
|
|
7066
|
+
*/
|
|
7067
|
+
function SidebarQuota({ t, wide = true, store = sharedQuota }) {
|
|
7068
|
+
// null = follow the snapshot; true / false = switched on this page.
|
|
7069
|
+
const [override, setOverride] = useState(null);
|
|
7070
|
+
const [seenOff, setSeenOff] = useState(false);
|
|
7071
|
+
const off = override === null ? seenOff : !override;
|
|
7072
|
+
const snap = useQuota(off ? null : store);
|
|
7073
|
+
const now = useNow(60 * 1000);
|
|
7074
|
+
const [open, setOpen] = useState(false);
|
|
7075
|
+
const [hiding, setHiding] = useState(false);
|
|
7076
|
+
const [hideError, setHideError] = useState(null);
|
|
7077
|
+
const wrapRef = useRef(null);
|
|
7078
|
+
const buttonRef = useRef(null);
|
|
7079
|
+
const popRef = useRef(null);
|
|
7080
|
+
const mounted = useRef(true);
|
|
7081
|
+
const popStyle = useAnchoredPeek(open, buttonRef, popRef);
|
|
7082
|
+
const flagOff = override === null && snap.data?.sidebar === false;
|
|
7083
|
+
const accounts = sidebarQuotaAccounts(snap.data);
|
|
7084
|
+
const visible = !off && !flagOff && store !== null && store !== undefined && accounts.length > 0;
|
|
7085
|
+
|
|
7086
|
+
useEffect(() => {
|
|
7087
|
+
const listener = (on) => {
|
|
7088
|
+
setOverride(on);
|
|
7089
|
+
if (on) void store?.load?.();
|
|
7090
|
+
};
|
|
7091
|
+
sidebarQuotaListeners.add(listener);
|
|
7092
|
+
return () => {
|
|
7093
|
+
sidebarQuotaListeners.delete(listener);
|
|
7094
|
+
};
|
|
7095
|
+
}, [store]);
|
|
7096
|
+
|
|
7097
|
+
useEffect(() => {
|
|
7098
|
+
if (flagOff) setSeenOff(true);
|
|
7099
|
+
}, [flagOff]);
|
|
7100
|
+
|
|
7101
|
+
useEffect(() => {
|
|
7102
|
+
mounted.current = true;
|
|
7103
|
+
return () => {
|
|
7104
|
+
mounted.current = false;
|
|
7105
|
+
};
|
|
7106
|
+
}, []);
|
|
7107
|
+
|
|
7108
|
+
// Turn the global switch off from the peek itself; the Settings switch
|
|
7109
|
+
// brings the entry back.
|
|
7110
|
+
const hide = async () => {
|
|
7111
|
+
setHiding(true);
|
|
7112
|
+
setHideError(null);
|
|
7113
|
+
try {
|
|
7114
|
+
await saveSidebarQuota(false);
|
|
7115
|
+
} catch (error) {
|
|
7116
|
+
if (mounted.current) setHideError(error instanceof Error ? error.message : String(error));
|
|
7117
|
+
} finally {
|
|
7118
|
+
if (mounted.current) setHiding(false);
|
|
7119
|
+
}
|
|
7120
|
+
};
|
|
7121
|
+
useDismissPeek(open, wrapRef, buttonRef, () => setOpen(false));
|
|
7122
|
+
|
|
7123
|
+
useEffect(() => {
|
|
7124
|
+
if (!visible && open) setOpen(false);
|
|
7125
|
+
}, [visible, open]);
|
|
7126
|
+
|
|
7127
|
+
if (!visible) return null;
|
|
7128
|
+
const { stats, usable, level, loading } = sidebarQuotaSummary(accounts);
|
|
7129
|
+
const count = loading ? "…" : fmt(t, "qSideCount", { ok: stats.healthy, n: usable });
|
|
7130
|
+
const label = loading ? t("qSideLabel") : fmt(t, "qSideAria", { ok: stats.healthy, n: usable });
|
|
7131
|
+
|
|
7132
|
+
const peek = open
|
|
7133
|
+
? h(
|
|
7134
|
+
"div",
|
|
7135
|
+
{ ref: popRef, className: "dcpa-q-pop dcpa-q-side-pop", role: "dialog", "aria-label": t("qSideLabel"), style: popStyle },
|
|
7136
|
+
accounts.map((account) => h(SidebarQuotaAccount, { key: account.accountId, t, account, snap, store, now })),
|
|
7137
|
+
snap.error ? h("p", { className: "dcpa-q-pop-text", "data-tone": "error" }, fmt(t, "qErrLoad", { error: snap.error })) : null,
|
|
7138
|
+
hideError ? h("p", { className: "dcpa-q-pop-text", "data-tone": "error", role: "alert" }, fmt(t, "qSideHideFailed", { error: hideError })) : null,
|
|
7139
|
+
h(
|
|
7140
|
+
"div",
|
|
7141
|
+
{ className: "dcpa-q-pop-foot dcpa-q-side-foot" },
|
|
7142
|
+
h("span", null, t("qPeekFooter")),
|
|
7143
|
+
h("button", { type: "button", className: "dcpa-q-btn", disabled: hiding, onClick: () => void hide() }, t("qSideHide"))
|
|
7144
|
+
)
|
|
7145
|
+
)
|
|
7146
|
+
: null;
|
|
7147
|
+
|
|
7148
|
+
return h(
|
|
7149
|
+
"div",
|
|
7150
|
+
{ ref: wrapRef, className: "dcpa-q-side", "data-wide": wide ? "true" : "false", "data-dsh-plugin": MODULE_ID },
|
|
7151
|
+
h(
|
|
7152
|
+
"button",
|
|
7153
|
+
{
|
|
7154
|
+
ref: buttonRef,
|
|
7155
|
+
type: "button",
|
|
7156
|
+
className: "dcpa-q-side-btn",
|
|
7157
|
+
"aria-label": label,
|
|
7158
|
+
"aria-haspopup": "dialog",
|
|
7159
|
+
"aria-expanded": open,
|
|
7160
|
+
title: wide ? undefined : label,
|
|
7161
|
+
onClick: () => setOpen((v) => !v),
|
|
7162
|
+
},
|
|
7163
|
+
h("span", { className: "dcpa-q-bars", "data-level": loading ? "unknown" : level, "aria-hidden": "true" }, h("i"), h("i"), h("i")),
|
|
7164
|
+
wide ? h("span", { className: "dcpa-q-side-label" }, t("qSideLabel")) : null,
|
|
7165
|
+
wide ? h("span", { className: "dcpa-q-side-count", "data-level": loading ? "unknown" : level }, count) : null
|
|
7166
|
+
),
|
|
7167
|
+
peek
|
|
7168
|
+
);
|
|
7169
|
+
}
|
|
7170
|
+
|
|
6617
7171
|
// #region Generation-model button (composer / hero)
|
|
6618
7172
|
|
|
6619
7173
|
function mediaFileURL(sessionId, id) {
|
|
@@ -8009,6 +8563,22 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
8009
8563
|
});
|
|
8010
8564
|
}
|
|
8011
8565
|
|
|
8566
|
+
// Sidebar footer: every keyed account's quota at a glance (renders
|
|
8567
|
+
// nothing until an enabled account has a management key).
|
|
8568
|
+
ctx.slots.inject("sidebar.footer.action", () =>
|
|
8569
|
+
registerListEntry(
|
|
8570
|
+
ctx.slots,
|
|
8571
|
+
{
|
|
8572
|
+
name: "sidebar.footer.action",
|
|
8573
|
+
id: `${NS}:quota-sidebar`,
|
|
8574
|
+
order: 100,
|
|
8575
|
+
label: () => t("qSideLabel"),
|
|
8576
|
+
locale: NS,
|
|
8577
|
+
},
|
|
8578
|
+
(props = {}) => h(SidebarQuota, { t, wide: props.wide !== false, store: sharedQuota })
|
|
8579
|
+
)
|
|
8580
|
+
);
|
|
8581
|
+
|
|
8012
8582
|
// Generation-model button, left of the quota badge. It only needs the
|
|
8013
8583
|
// session id; like the badge, the hero copy steps aside while the
|
|
8014
8584
|
// composer copy of the same session is mounted.
|