dsh-desktop-statusbar 3.0.5 → 3.0.7
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/lib/client.js +614 -179
- package/lib/index.js +456 -93
- package/package.json +1 -1
- package/tests/helpers/client-harness.js +86 -0
- package/tests/verify-balance.js +55 -1
- package/tests/verify-context.js +23 -3
- package/tests/verify-copy.js +6 -2
- package/tests/verify-fixes.js +30 -0
- package/tests/verify-generic-relay.js +405 -6
- package/tests/verify-magpie-quota.mjs +24 -1
- package/tests/verify-modelrow-scroll.js +669 -0
- package/tests/verify-provider-fees.js +131 -1
- package/tests/verify-relay-settings.js +1166 -115
- package/tests/verify-render.js +7 -0
- package/tests/verify.js +23 -8
package/lib/client.js
CHANGED
|
@@ -76,7 +76,7 @@ window.__ModuleLoader__.load({
|
|
|
76
76
|
*/
|
|
77
77
|
const CONFIG_VERSION = 6;
|
|
78
78
|
/** 插件版本:显示在设置页底部,用来确认页面加载的是哪一版客户端代码。 */
|
|
79
|
-
const VERSION = "3.0.
|
|
79
|
+
const VERSION = "3.0.7";
|
|
80
80
|
/** 官方参考价的版本:官方调价时改这个数字,老价格库会自动并入新参考价。
|
|
81
81
|
* v4:官方模型目录(MODEL_PRESENTATION)**默认全部加入价格表**(按官网价播种),
|
|
82
82
|
* 不再需要「点名字加入」;用户删掉的模型可用「恢复默认」找回。
|
|
@@ -578,6 +578,22 @@ function normalizePlatforms(raw) {
|
|
|
578
578
|
});
|
|
579
579
|
return out;
|
|
580
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* 平台显示顺序:显式数组优先(只认仍存在的平台、去重);
|
|
583
|
+
* 数组里没有的平台(旧配置迁移 / 手改配置)按对象键序补在末尾,保证不丢平台。
|
|
584
|
+
* 不能直接用 Object.keys 当显示顺序:纯数字平台名会被 JS 对象按数值排到最前。
|
|
585
|
+
*/
|
|
586
|
+
function normalizePlatformOrder(raw, platforms) {
|
|
587
|
+
const table = platforms === null || platforms === undefined || typeof platforms !== "object" ? {} : platforms;
|
|
588
|
+
const out = [];
|
|
589
|
+
(Array.isArray(raw) ? raw : []).forEach((name) => {
|
|
590
|
+
if (typeof name === "string" && Object.prototype.hasOwnProperty.call(table, name) && out.indexOf(name) === -1) out.push(name);
|
|
591
|
+
});
|
|
592
|
+
Object.keys(table).forEach((name) => {
|
|
593
|
+
if (out.indexOf(name) === -1) out.push(name);
|
|
594
|
+
});
|
|
595
|
+
return out;
|
|
596
|
+
}
|
|
581
597
|
/**
|
|
582
598
|
* 平台档案里的模型名 ↔ 价格条目键:**宽容匹配**(同名或归一化紧凑串相同,与 pickPriceKey 同一套口径)。
|
|
583
599
|
* 平台里存的是价格库键,但迁移 / 手改配置来的名字可能带 provider 前缀或不同分隔符。
|
|
@@ -2075,6 +2091,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
2075
2091
|
platformEmpty: "还没有第三方平台。",
|
|
2076
2092
|
platformModels: "适用模型",
|
|
2077
2093
|
platformModelSelectPh: "请选择模型",
|
|
2094
|
+
platformModelNoMatch: "无匹配模型",
|
|
2078
2095
|
platformFeePh: "如 0.02",
|
|
2079
2096
|
platformAddModel: "添加模型",
|
|
2080
2097
|
platformNameRequired: "平台名称不能为空。",
|
|
@@ -2248,6 +2265,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
2248
2265
|
platformEmpty: "No third-party platforms yet.",
|
|
2249
2266
|
platformModels: "Applicable models",
|
|
2250
2267
|
platformModelSelectPh: "Select a model",
|
|
2268
|
+
platformModelNoMatch: "No matching models",
|
|
2251
2269
|
platformFeePh: "e.g. 0.02",
|
|
2252
2270
|
platformAddModel: "Add model",
|
|
2253
2271
|
platformNameRequired: "Platform name is required.",
|
|
@@ -2412,6 +2430,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
2412
2430
|
"platformEmpty": "サードパーティプラットフォームはまだありません。",
|
|
2413
2431
|
"platformModels": "対象モデル",
|
|
2414
2432
|
"platformModelSelectPh": "モデルを選択",
|
|
2433
|
+
"platformModelNoMatch": "一致するモデルがありません",
|
|
2415
2434
|
"platformFeePh": "例:0.02",
|
|
2416
2435
|
"platformAddModel": "モデルを追加",
|
|
2417
2436
|
"platformNameRequired": "プラットフォーム名は必須です。",
|
|
@@ -2572,6 +2591,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
2572
2591
|
"platformEmpty": "Aún no hay plataformas de terceros.",
|
|
2573
2592
|
"platformModels": "Modelos aplicables",
|
|
2574
2593
|
"platformModelSelectPh": "Selecciona un modelo",
|
|
2594
|
+
"platformModelNoMatch": "No hay modelos coincidentes",
|
|
2575
2595
|
"platformFeePh": "p. ej. 0.02",
|
|
2576
2596
|
"platformAddModel": "Añadir modelo",
|
|
2577
2597
|
"platformNameRequired": "El nombre de la plataforma es obligatorio.",
|
|
@@ -2732,6 +2752,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
2732
2752
|
"platformEmpty": "Aucune plateforme tierce pour le moment.",
|
|
2733
2753
|
"platformModels": "Modèles applicables",
|
|
2734
2754
|
"platformModelSelectPh": "Sélectionner un modèle",
|
|
2755
|
+
"platformModelNoMatch": "Aucun modèle correspondant",
|
|
2735
2756
|
"platformFeePh": "ex. 0.02",
|
|
2736
2757
|
"platformAddModel": "Ajouter un modèle",
|
|
2737
2758
|
"platformNameRequired": "Le nom de la plateforme est obligatoire.",
|
|
@@ -2892,6 +2913,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
2892
2913
|
"platformEmpty": "Noch keine Drittanbieter-Plattformen.",
|
|
2893
2914
|
"platformModels": "Passende Modelle",
|
|
2894
2915
|
"platformModelSelectPh": "Modell auswählen",
|
|
2916
|
+
"platformModelNoMatch": "Keine passenden Modelle",
|
|
2895
2917
|
"platformFeePh": "z. B. 0.02",
|
|
2896
2918
|
"platformAddModel": "Modell hinzufügen",
|
|
2897
2919
|
"platformNameRequired": "Der Plattformname ist erforderlich.",
|
|
@@ -3052,6 +3074,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
3052
3074
|
"platformEmpty": "Сторонних платформ пока нет.",
|
|
3053
3075
|
"platformModels": "Подходящие модели",
|
|
3054
3076
|
"platformModelSelectPh": "Выберите модель",
|
|
3077
|
+
"platformModelNoMatch": "Нет подходящих моделей",
|
|
3055
3078
|
"platformFeePh": "напр. 0.02",
|
|
3056
3079
|
"platformAddModel": "Добавить модель",
|
|
3057
3080
|
"platformNameRequired": "Укажите название платформы.",
|
|
@@ -3212,6 +3235,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
3212
3235
|
"platformEmpty": "Ainda não há plataformas de terceiros.",
|
|
3213
3236
|
"platformModels": "Modelos aplicáveis",
|
|
3214
3237
|
"platformModelSelectPh": "Selecionar um modelo",
|
|
3238
|
+
"platformModelNoMatch": "Nenhum modelo correspondente",
|
|
3215
3239
|
"platformFeePh": "ex.: 0.02",
|
|
3216
3240
|
"platformAddModel": "Adicionar modelo",
|
|
3217
3241
|
"platformNameRequired": "O nome da plataforma é obrigatório.",
|
|
@@ -3326,6 +3350,8 @@ function platformOfBook(book, platforms, model) {
|
|
|
3326
3350
|
holidayDays: [],
|
|
3327
3351
|
/* 第三方平台档案(非密):平台名 → { endpoint, userIdHeader, balancePath, currency, balanceDivisor, models } */
|
|
3328
3352
|
relayPlatforms: {},
|
|
3353
|
+
/* 平台显示顺序(平台名数组)。JS 对象对纯数字键按数值排序,不能靠 Object.keys 保序。 */
|
|
3354
|
+
relayPlatformOrder: [],
|
|
3329
3355
|
catalogOrder: DEFAULT_CATALOG_ORDER.slice()
|
|
3330
3356
|
};
|
|
3331
3357
|
try {
|
|
@@ -3427,6 +3453,9 @@ function platformOfBook(book, platforms, model) {
|
|
|
3427
3453
|
models: [{ model: name, feeMultiplier: models[name].feeMultiplier }]
|
|
3428
3454
|
});
|
|
3429
3455
|
});
|
|
3456
|
+
/* 平台显示顺序:显式数组优先;旧配置没有该数组时按当前 Object.keys(relayPlatforms)
|
|
3457
|
+
初始化(保留既有显示顺序),数组里缺的平台按对象键序补在末尾,绝不丢平台。 */
|
|
3458
|
+
const relayPlatformOrder = normalizePlatformOrder(parsed.relayPlatformOrder, relayPlatforms);
|
|
3430
3459
|
/* 旧版取消勾选「峰谷计价」时会把空闲价写成高峰价的副本,再勾回来也回不去。
|
|
3431
3460
|
这里按参考价补回:只修"勾着峰谷计价、两档却完全相同"的官方模型。 */
|
|
3432
3461
|
Object.keys(reference).forEach((name) => {
|
|
@@ -3456,6 +3485,7 @@ function platformOfBook(book, platforms, model) {
|
|
|
3456
3485
|
models: Object.keys(models).length > 0 ? models : normalizeModels(officialDefaultModels(currency), currency),
|
|
3457
3486
|
modelOrder: modelOrder.length > 0 ? modelOrder : Object.keys(officialDefaultModels(currency)),
|
|
3458
3487
|
relayPlatforms: relayPlatforms,
|
|
3488
|
+
relayPlatformOrder: relayPlatformOrder,
|
|
3459
3489
|
catalogOrder: catalogOrder,
|
|
3460
3490
|
/* 抓来的放假日历:字符串数组,按年分组在 refreshHolidays() 里做 */
|
|
3461
3491
|
holidayDays: Array.isArray(parsed.holidayDays)
|
|
@@ -3477,6 +3507,8 @@ function platformOfBook(book, platforms, model) {
|
|
|
3477
3507
|
function snapshot() { return config; }
|
|
3478
3508
|
function setConfig(patch) {
|
|
3479
3509
|
config = Object.assign({ version: CONFIG_VERSION }, config, patch);
|
|
3510
|
+
/* 平台顺序不变量:保留既有顺序;已删平台剔除;数组里缺的平台按对象键序补到末尾。 */
|
|
3511
|
+
config.relayPlatformOrder = normalizePlatformOrder(config.relayPlatformOrder, config.relayPlatforms);
|
|
3480
3512
|
refreshHolidays();
|
|
3481
3513
|
try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(config)); } catch (error) { /* 隐私模式下仅内存生效 */ }
|
|
3482
3514
|
listeners.forEach((fn) => { try { fn(); } catch (error) { /* 单个订阅者失败不影响其余 */ } });
|
|
@@ -3489,6 +3521,9 @@ function platformOfBook(book, platforms, model) {
|
|
|
3489
3521
|
绝不写进 localStorage / config。 */
|
|
3490
3522
|
let relayState = { loaded: false, models: {} };
|
|
3491
3523
|
let relayLoading = null;
|
|
3524
|
+
let relayLoadSeq = 0;
|
|
3525
|
+
/* 最近一次 loadRelayState 是否真正拿到 Host 新快照(ok:true)。force 刷新失败时为 false。 */
|
|
3526
|
+
let relayLoadOk = false;
|
|
3492
3527
|
const relayListeners = new Set();
|
|
3493
3528
|
function relaySnapshot() { return relayState; }
|
|
3494
3529
|
function subscribeRelayState(fn) {
|
|
@@ -3507,23 +3542,37 @@ function publishRelayState(channels) {
|
|
|
3507
3542
|
relayState = { loaded: true, models: models };
|
|
3508
3543
|
relayListeners.forEach((fn) => { try { fn(); } catch (error) { /* 单个订阅者失败不影响其余 */ } });
|
|
3509
3544
|
}
|
|
3510
|
-
/**
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3545
|
+
/**
|
|
3546
|
+
* 拉取 Host relay-balance-config。force=true 时忽略已加载缓存与在途请求,强制重新 GET。
|
|
3547
|
+
* 用单调序号保证只有**最新一次**请求的结果能 publish:并发 / 强制刷新时旧的空结果不会覆盖新快照
|
|
3548
|
+
* (后台自动探测可能随时写回真实 endpoint/解析字段,陈旧空快照会让编辑区回显/保存用默认值覆盖)。
|
|
3549
|
+
*/
|
|
3550
|
+
function loadRelayState(force) {
|
|
3551
|
+
if (force !== true && relayState.loaded === true) return Promise.resolve(relayState);
|
|
3552
|
+
if (force !== true && relayLoading !== null) return relayLoading;
|
|
3553
|
+
const seq = ++relayLoadSeq;
|
|
3554
|
+
const run = window.fetch(RELAY_URL, { cache: "no-store" })
|
|
3515
3555
|
.then((response) => response.json())
|
|
3516
3556
|
.then((data) => {
|
|
3517
|
-
|
|
3557
|
+
const ok = data !== null && data !== undefined && data.ok === true;
|
|
3558
|
+
if (seq === relayLoadSeq) {
|
|
3559
|
+
relayLoadOk = ok;
|
|
3560
|
+
if (ok) publishRelayState(data.channels);
|
|
3561
|
+
}
|
|
3518
3562
|
return relayState;
|
|
3519
3563
|
})
|
|
3520
|
-
.catch(() => relayState)
|
|
3564
|
+
.catch(() => { if (seq === relayLoadSeq) relayLoadOk = false; return relayState; })
|
|
3521
3565
|
.then((result) => {
|
|
3522
|
-
relayLoading = null;
|
|
3566
|
+
if (seq === relayLoadSeq) relayLoading = null;
|
|
3523
3567
|
return result;
|
|
3524
3568
|
});
|
|
3525
|
-
|
|
3569
|
+
relayLoading = run;
|
|
3570
|
+
return run;
|
|
3526
3571
|
}
|
|
3572
|
+
/** 首次需要时 GET 一次(模块级缓存)。 */
|
|
3573
|
+
function ensureRelayState() { return loadRelayState(false); }
|
|
3574
|
+
/** 打开平台编辑区前强制刷新,避免复用旧的空 in-flight/loaded 快照。 */
|
|
3575
|
+
function refreshRelayState() { return loadRelayState(true); }
|
|
3527
3576
|
/** 保存 / 移除某个模型的中转站配置;响应里的布尔状态刷新本地缓存。 */
|
|
3528
3577
|
function postRelayState(payload) {
|
|
3529
3578
|
return window.fetch(RELAY_URL, {
|
|
@@ -3535,6 +3584,12 @@ function postRelayState(payload) {
|
|
|
3535
3584
|
return data;
|
|
3536
3585
|
});
|
|
3537
3586
|
}
|
|
3587
|
+
/** 宿主当前快照里该平台的记录(没有则 null):判断 Host 是否已有可用地址 / 运行时默认值。 */
|
|
3588
|
+
function relayChannelOf(name) {
|
|
3589
|
+
return relayState.models === null || relayState.models === undefined
|
|
3590
|
+
? null
|
|
3591
|
+
: (relayState.models[name] === undefined ? null : relayState.models[name]);
|
|
3592
|
+
}
|
|
3538
3593
|
function useRelayState() {
|
|
3539
3594
|
return react.useSyncExternalStore(subscribeRelayState, relaySnapshot, relaySnapshot);
|
|
3540
3595
|
}
|
|
@@ -3989,12 +4044,27 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
3989
4044
|
* 蓝紫两色复用总计令牌条已有的「输出」蓝与「未命中输入」紫,不新造颜色。
|
|
3990
4045
|
* 旋转是 CSS animation(见样式表),不占 JS 定时器。
|
|
3991
4046
|
*/
|
|
3992
|
-
function contextRing(percent, state, compact) {
|
|
4047
|
+
function contextRing(percent, state, compact, labelPercent) {
|
|
4048
|
+
const displayPercent = typeof percent === "number" && Number.isFinite(percent)
|
|
4049
|
+
? Math.max(0, Math.min(100, percent))
|
|
4050
|
+
: 0;
|
|
4051
|
+
/* 环心数字显示的是**主会话自己**的占用(labelPercent,调用处传 contextMeter.percent),
|
|
4052
|
+
与弧长(percent,团队运行时是成员级最大/深层最小)不同源 —— 用户拍板:
|
|
4053
|
+
「环里的数字只显示主会话自己的上下文占用」,弧长仍按谁在跑切数据源。
|
|
4054
|
+
只显示整数(四舍五入);到 100 留空(14px 环心塞不下三位,回退的 4.5px 字号已删除)。
|
|
4055
|
+
labelPercent 缺失 / 非数字 / null ⇒ 同样留空:不退回弧长的 percent(那是团队级数据,
|
|
4056
|
+
|
|
4057
|
+
而且没有数据时 percent 也可能是 0,显示 "0" 会让用户误以为占用真的是 0)。 */
|
|
4058
|
+
const labelRaw = typeof labelPercent === "number" && Number.isFinite(labelPercent)
|
|
4059
|
+
? labelPercent
|
|
4060
|
+
: null;
|
|
4061
|
+
const labelRounded = labelRaw === null ? null : Math.round(Math.max(0, Math.min(100, labelRaw)));
|
|
4062
|
+
const ringLabel = labelRounded === null || labelRounded >= 100 ? "" : String(labelRounded);
|
|
3993
4063
|
const stateClass = state === "running" ? " dsb-ring-running"
|
|
3994
4064
|
: (state === "teamRunning" ? " dsb-ring-team"
|
|
3995
4065
|
: (state === "deepRunning" ? " dsb-ring-deep"
|
|
3996
4066
|
: (state === "error" ? " dsb-ring-error" : (state === "approval" ? " dsb-ring-approval" : ""))));
|
|
3997
|
-
const offset = METER_CIRCUMFERENCE * (1 -
|
|
4067
|
+
const offset = METER_CIRCUMFERENCE * (1 - displayPercent / 100);
|
|
3998
4068
|
const dashes = notchDashes(compact);
|
|
3999
4069
|
return h("svg", {
|
|
4000
4070
|
className: "dsb-ring" + stateClass, key: "__ring", viewBox: "0 0 14 14", width: 14, height: 14
|
|
@@ -4012,7 +4082,19 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
4012
4082
|
/* SVG 的弧默认从 3 点方向起,整体转 -90° 才是官方那种"12 点起、顺时针长" */
|
|
4013
4083
|
transform: "rotate(-90 7 7)",
|
|
4014
4084
|
strokeDasharray: METER_CIRCUMFERENCE, strokeDashoffset: offset
|
|
4015
|
-
})
|
|
4085
|
+
}),
|
|
4086
|
+
/* 圆环中间显示占用数字(用户要"占用 80% 就在环里显示 80",不带百分号)。
|
|
4087
|
+
字号只由 CSS 一处固定 6px 决定(见 .dsb-ring-percent),这里不再写动态 fontSize。
|
|
4088
|
+
环心留空时仍是空 text 节点,结构(底环 + 进度弧 + 数字)不变。
|
|
4089
|
+
dy 0.25px:SVG text 的 dominantBaseline="central" 在老内核上按字体度量居中,
|
|
4090
|
+
实测比视觉中心略高约半像素,给一点向下的基线微调补齐。 */
|
|
4091
|
+
h("text", {
|
|
4092
|
+
className: "dsb-ring-percent", x: 7, y: 7,
|
|
4093
|
+
dy: "0.25px",
|
|
4094
|
+
textAnchor: "middle", dominantBaseline: "central",
|
|
4095
|
+
"aria-hidden": "true"
|
|
4096
|
+
}, ringLabel)
|
|
4097
|
+
)
|
|
4016
4098
|
}
|
|
4017
4099
|
|
|
4018
4100
|
/** 气泡自己那一圈描边的宽度(.dsb-tip 的 box-shadow spread:0 0 0 .5px):
|
|
@@ -6806,6 +6888,8 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
6806
6888
|
'.dsb-seg-click:hover,.dsb-seg-click[aria-expanded="true"]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.1));color:var(--dsw-alias-label-secondary)}',
|
|
6807
6889
|
".dsb-ring-track{fill:none;stroke:var(--dsw-alias-border-l3,rgba(127,127,127,.25));stroke-width:2px}",
|
|
6808
6890
|
".dsb-ring-fill{fill:none;stroke:var(--dsw-alias-label-tertiary);stroke-width:2px;stroke-linecap:round}",
|
|
6891
|
+
/* 环心的占用数字:填色跟随主题文字色、细字重、不吃鼠标事件(否则会挡住圆环按钮的点击/悬停) */
|
|
6892
|
+
".dsb-ring-percent{fill:var(--dsw-alias-label-secondary,currentColor);font-size:6px;font-weight:600;line-height:1;pointer-events:none;text-anchor:middle;dominant-baseline:central}",
|
|
6809
6893
|
/* 运行时:绿色那段在淡灰圆圈里匀速转,像加载圈。
|
|
6810
6894
|
-90° 必须写进关键帧:circle 上的 SVG transform="rotate(-90 7 7)"(把弧的起点挪到 12 点)
|
|
6811
6895
|
会被 CSS transform 整个覆盖,不写回来就会从 3 点起、看起来跑偏。
|
|
@@ -7148,7 +7232,7 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
7148
7232
|
".dsb-settings .dsb-modelrow-fee{flex:1 1 0;min-width:0;display:flex;align-items:center;gap:8px}",
|
|
7149
7233
|
".dsb-settings .dsb-modelrow-fee .dsb-action{margin-left:auto;flex:none}",
|
|
7150
7234
|
".dsb-settings .dsb-select-empty .dsb-select-btn{color:var(--dsw-alias-label-tertiary);opacity:1;background:color-mix(in srgb, var(--dsw-specific-menu,#f8f9fa) 55%, var(--dsw-alias-bg-layer-1,#fff))}",
|
|
7151
|
-
|
|
7235
|
+
|
|
7152
7236
|
".dsb-settings .dsb-modelrow-fee input[type=number]{width:calc(5ch + 18px);min-width:calc(5ch + 18px);text-align:left}",
|
|
7153
7237
|
".dsb-settings .dsb-relay-fields .dsb-action{flex:none}",
|
|
7154
7238
|
/* 价格行不换行:档位名与后面那组价格框始终同一行;空间不够时由 .dsb-fields 内部换行 */
|
|
@@ -7204,12 +7288,17 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
7204
7288
|
".dsb-settings .dsb-select-item-on{color:var(--dsw-alias-brand-primary,#4d6bfe)}",
|
|
7205
7289
|
/* 已被本平台其他行选中的模型:灰显、不可点 */
|
|
7206
7290
|
".dsb-settings .dsb-select-item-disabled{opacity:.45;cursor:not-allowed}",
|
|
7207
|
-
|
|
7291
|
+
/* 平台「适用模型」下拉:portal 到 body + fixed 定位,最多 3 项完整可见、始终向下并按实际空间限高、不超出视口 */
|
|
7208
7292
|
".dsb-settings .dsb-modelrow-select{flex:1 1 0;min-width:0}",
|
|
7209
7293
|
".dsb-settings .dsb-modelrow-select .dsb-select-btn{display:flex;width:100%;height:28px;box-sizing:border-box;font-size:13px;justify-content:flex-start;text-align:left;white-space:nowrap;overflow:hidden}",
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7294
|
+
".dsb-settings .dsb-modelrow-select .dsb-select-btn{cursor:text}",
|
|
7295
|
+
/* 菜单 portal 到 body、fixed 定位,样式不能再只挂 .dsb-settings 作用域(脱离设置区后会丢磨砂/宽度/高度约束) */
|
|
7296
|
+
".dsb-modelrow-menu{box-sizing:border-box;position:fixed;padding:4px;border-radius:var(--dsw-radius-lg,16px);background:rgb(from var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1,#1f1f1f)) r g b / .382);backdrop-filter:var(--dsw-menu-backdrop-filter,blur(40px) saturate(150%));-webkit-backdrop-filter:var(--dsw-menu-backdrop-filter,blur(40px) saturate(150%));box-shadow:0 0 0 .5px var(--dsw-alias-border-l1,rgba(127,127,127,.3));z-index:1100;max-width:100%;max-height:calc(3 * 30px + 8px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none}",
|
|
7297
|
+
".dsb-modelrow-menu::-webkit-scrollbar{display:none;width:0;height:0}",
|
|
7298
|
+
".dsb-modelrow-menu .dsb-select-item{display:flex;align-items:center;width:100%;height:30px;box-sizing:border-box;padding:0 10px;border:0;border-radius:var(--dsw-radius-sm,8px);background:transparent;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary);text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
7299
|
+
".dsb-modelrow-menu .dsb-select-item:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}",
|
|
7300
|
+
".dsb-modelrow-menu .dsb-select-item-on{color:var(--dsw-alias-brand-primary,#4d6bfe)}",
|
|
7301
|
+
".dsb-modelrow-menu .dsb-select-item-disabled{opacity:.45;cursor:not-allowed}",
|
|
7213
7302
|
/* 三组字段整体贴右边缘:左边留给时段名,右边一列对齐。
|
|
7214
7303
|
未勾选「峰谷计价」时那行也走同一套 —— 左边是「全时段」标签,
|
|
7215
7304
|
不再用"单档那行没有档位名"时的那条双边对齐规则(用户嫌它跟勾选后的两行不一致)。 */
|
|
@@ -10323,34 +10412,78 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10323
10412
|
}
|
|
10324
10413
|
}, [tipId]);
|
|
10325
10414
|
|
|
10326
|
-
/* 开关状态同步到 <html>:CSS
|
|
10327
|
-
官方「活动 / 用量 / 上下文」节点会重新插回 dock 的嵌套层,光靠 CSS
|
|
10328
|
-
|
|
10415
|
+
/* 开关状态同步到 <html>:CSS 里那几条"藏官方底栏"的规则挂在 html.dsb-on 上。
|
|
10416
|
+
官方「活动 / 用量 / 上下文」节点会重新插回 dock 的嵌套层,光靠 CSS 的直系子节点规则藏不住。
|
|
10417
|
+
|
|
10418
|
+
**3.0.7 起只认官方节点**(用户拍板):旧做法是"从 .dsb-root 逐层向上到 dock,把同层
|
|
10419
|
+
所有非本插件兄弟节点全部 display:none"。那会把第三方插件**后插入**的节点也一并误藏
|
|
10420
|
+
(它们既不是官方节点、也不是本插件)。现在改成用与 CSS 相同的官方选择器精确定位、
|
|
10421
|
+
**只隐藏这些官方节点**:
|
|
10422
|
+
· button[aria-haspopup="dialog"][aria-label*="上下文"] / [aria-label*="context used"]
|
|
10423
|
+
· span[class$="_root"]>button[aria-haspopup="dialog"][class$="_trigger"]
|
|
10424
|
+
第三方插件节点不匹配这些选择器,就永远不会被我们碰。
|
|
10425
|
+
|
|
10426
|
+
**MutationObserver 只在"新增节点匹配(或包含匹配)官方选择器"时重扫一次**:普通流式
|
|
10427
|
+
文字变化不触发,避免每帧空转卡顿。卸载时只还原被我们隐藏过的官方节点。 */
|
|
10329
10428
|
react.useEffect(() => {
|
|
10330
10429
|
if (typeof document === "undefined" || document === null) return undefined;
|
|
10331
10430
|
const root = document.documentElement;
|
|
10332
10431
|
if (root === null || root === undefined || root.classList === undefined) return undefined;
|
|
10333
10432
|
root.classList.add("dsb-on");
|
|
10334
|
-
|
|
10335
|
-
const
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10433
|
+
/* 与 CSS 里那几条官方规则同源的官方选择器;顺序无关,匹配任一即算官方节点。 */
|
|
10434
|
+
const OFFICIAL_SELECTORS = [
|
|
10435
|
+
'button[aria-haspopup="dialog"][aria-label*="上下文"]',
|
|
10436
|
+
'button[aria-haspopup="dialog"][aria-label*="context used"]',
|
|
10437
|
+
'span[class$="_root"]>button[aria-haspopup="dialog"][class$="_trigger"]'
|
|
10438
|
+
];
|
|
10439
|
+
const OFFICIAL = OFFICIAL_SELECTORS.join(",");
|
|
10440
|
+
/* el -> 我们改之前它的行内 display(可能为空串),卸载时逐个还原 */
|
|
10441
|
+
const hidden = new Map();
|
|
10442
|
+
const dockOf = () => document.querySelector('[data-slot="conversation.composer.dock"]');
|
|
10443
|
+
/* 只藏 dock 子树里匹配官方选择器的节点;别的节点(含第三方插件)一概不碰。 */
|
|
10444
|
+
const sweep = () => {
|
|
10445
|
+
const dock = dockOf();
|
|
10446
|
+
if (dock === null || dock === undefined) return null;
|
|
10447
|
+
Array.from(dock.querySelectorAll(OFFICIAL)).forEach((node) => {
|
|
10448
|
+
if (node.style.display !== "none") {
|
|
10449
|
+
if (!hidden.has(node)) hidden.set(node, node.style.display);
|
|
10450
|
+
node.style.display = "none";
|
|
10451
|
+
}
|
|
10452
|
+
});
|
|
10453
|
+
return dock;
|
|
10454
|
+
};
|
|
10455
|
+
/* 新增节点里有没有"官方节点":自己匹配,或子树里含匹配(官方有时整体替换一层外壳)。 */
|
|
10456
|
+
const touchesOfficial = (node) => {
|
|
10457
|
+
if (node === null || node === undefined || node.nodeType !== 1) return false;
|
|
10458
|
+
if (typeof node.matches === "function" && node.matches(OFFICIAL)) return true;
|
|
10459
|
+
return typeof node.querySelector === "function" && node.querySelector(OFFICIAL) !== null;
|
|
10460
|
+
};
|
|
10461
|
+
sweep();
|
|
10462
|
+
/* 只观察 childList:我们自己写 display 是 attribute 变动,不观察它就不会自激。
|
|
10463
|
+
老环境 / 测试替身没有 MutationObserver 时退回"只清扫一次",行为不退化。 */
|
|
10464
|
+
let observer = null;
|
|
10465
|
+
if (typeof MutationObserver === "function") {
|
|
10466
|
+
observer = new MutationObserver((records) => {
|
|
10467
|
+
/* 只有新增节点牵涉到官方节点才重扫;纯文字/属性变化直接跳过,避免卡顿。 */
|
|
10468
|
+
let relevant = false;
|
|
10469
|
+
for (const record of records) {
|
|
10470
|
+
const added = record.addedNodes;
|
|
10471
|
+
for (let i = 0; i < added.length; i += 1) {
|
|
10472
|
+
if (touchesOfficial(added[i])) { relevant = true; break; }
|
|
10346
10473
|
}
|
|
10347
|
-
|
|
10348
|
-
|
|
10474
|
+
if (relevant) break;
|
|
10475
|
+
}
|
|
10476
|
+
if (relevant) sweep();
|
|
10477
|
+
});
|
|
10478
|
+
const dock = sweep();
|
|
10479
|
+
if (dock !== null && dock !== undefined) {
|
|
10480
|
+
observer.observe(dock, { childList: true, subtree: true });
|
|
10349
10481
|
}
|
|
10350
10482
|
}
|
|
10351
10483
|
return () => {
|
|
10484
|
+
if (observer !== null) observer.disconnect();
|
|
10352
10485
|
root.classList.remove("dsb-on");
|
|
10353
|
-
hidden.forEach((
|
|
10486
|
+
hidden.forEach((prev, el) => { el.style.display = prev; });
|
|
10354
10487
|
};
|
|
10355
10488
|
}, []);
|
|
10356
10489
|
|
|
@@ -10628,7 +10761,11 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10628
10761
|
: subagentTiers;
|
|
10629
10762
|
const ringPercent = ringPercentOf(contextMeter, agentState, ringTiers);
|
|
10630
10763
|
/* 圆环自己就是触发项:点开上下文占用面板;峰谷那两个字不带气泡 */
|
|
10631
|
-
|
|
10764
|
+
/* 用户拍板:气泡(以及环心数字)恢复成**主会话自己**的 contextMeter,
|
|
10765
|
+
不再用 ringPercent 覆盖 percent —— ringPercent 只驱动弧长,是"团队级"数据。 */
|
|
10766
|
+
const contextTip = contextMeter === null
|
|
10767
|
+
? null
|
|
10768
|
+
: { kind: "meter", meter: contextMeter };
|
|
10632
10769
|
const children = [];
|
|
10633
10770
|
if (contextTip !== null) {
|
|
10634
10771
|
children.push(h("button", {
|
|
@@ -10638,7 +10775,8 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10638
10775
|
"aria-expanded": tipId === "context" ? "true" : "false",
|
|
10639
10776
|
onClick: (event) => toggleTip("context", event)
|
|
10640
10777
|
}, [
|
|
10641
|
-
|
|
10778
|
+
/* 弧长用 ringPercent(谁在跑切数据源),环心数字用 contextMeter.percent(主会话自己) */
|
|
10779
|
+
contextRing(ringPercent, agentState, contextMeter.compact, contextMeter.empty === true ? null : contextMeter.percent),
|
|
10642
10780
|
tipId === "context" ? tipPanelOf(contextTip) : null
|
|
10643
10781
|
]));
|
|
10644
10782
|
}
|
|
@@ -10792,7 +10930,7 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10792
10930
|
不新增 useState 是为了保持 tools/shot.cjs 截图 presets 的 hook 下标不变(有测试盯着那张表)。
|
|
10793
10931
|
true = 展开;addModel 自动置 true,用户手动开合时同步。 */
|
|
10794
10932
|
const [catalogNotice, setCatalogNotice] = react.useState(false);
|
|
10795
|
-
/* platformModelOpen
|
|
10933
|
+
/* platformModelOpen 状态槽:平台「适用模型」下拉的展开状态;打开时为 { index, filter }(筛选文本),收起为 null。不新增 hook。 */
|
|
10796
10934
|
const [platformModelOpen, setPlatformModelOpen] = react.useState(null);
|
|
10797
10935
|
const [currencyOpen, setCurrencyOpen] = react.useState(false);
|
|
10798
10936
|
/* 第三方平台区块:平台名(编辑中)/ 草稿 / 校验提示 / 新平台名输入框。
|
|
@@ -10807,37 +10945,133 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10807
10945
|
const editPopRef = react.useRef(null);
|
|
10808
10946
|
/* 币种下拉的**菜单节点**(不是那个按钮):展开后要把它滚进视野 */
|
|
10809
10947
|
const currencyMenuRef = react.useRef(null);
|
|
10810
|
-
/*
|
|
10948
|
+
/* 平台编辑区节点:仅当用户点「添加模型」增加行时才把它的底边带进视野(打开编辑区本身不滚) */
|
|
10811
10949
|
const platformEditRef = react.useRef(null);
|
|
10950
|
+
/* task-14:记录上次的平台名 + 模型行数,仅用于判断「同一平台是否新增了模型行」;
|
|
10951
|
+
同一平台行数增加才补滚,打开 / 切换平台都不滚(原地展开,不跳到固定位置)。 */
|
|
10952
|
+
const platformRevealLenRef = react.useRef(null);
|
|
10953
|
+
/* task-31:平台打开时代次,用于丢弃过期的强制刷新回调(切平台 / 保存后不再回填)。 */
|
|
10954
|
+
const platformRefreshSeqRef = react.useRef(0);
|
|
10955
|
+
/* task-33:当前平台强制刷新的进行中 promise(用于把过早的自动保存延后到刷新完成)。 */
|
|
10956
|
+
const platformRefreshPendingRef = react.useRef(null);
|
|
10957
|
+
/* task-35:最近一次强制刷新是否成功(false = GET 失败/5xx,快照可能已陈旧)。 */
|
|
10958
|
+
const platformRefreshOkRef = react.useRef(true);
|
|
10812
10959
|
/* 当前展开平台行的头部节点:外部点击保存时,头部内的点击(保存/删除/平台名)不在此处重复处理 */
|
|
10813
10960
|
const platformHeadRef = react.useRef(null);
|
|
10814
10961
|
/* 平台「适用模型」下拉的菜单节点:用于外部点击判定 */
|
|
10815
10962
|
const platformModelMenuRef = react.useRef(null);
|
|
10816
|
-
/*
|
|
10963
|
+
/* 模型下拉打开那一下算好的定位(fixed 视口坐标:left/宽度/maxHeight/top) */
|
|
10817
10964
|
const platformModelMenuPosRef = react.useRef(null);
|
|
10818
|
-
const platformModelMenuTargetRef = react.useRef(null);
|
|
10819
10965
|
/* 模型下拉的锚点按钮:打开期间靠它找内部滚动容器 */
|
|
10820
10966
|
const platformModelAnchorRef = react.useRef(null);
|
|
10821
|
-
/*
|
|
10822
|
-
|
|
10967
|
+
/* 模型下拉打开期间:菜单内部滚动放行;只有落在设置区(.dsb-settings 内部或包住它的真实滚动祖先)
|
|
10968
|
+
的滚动/滚轮才收起;输入框上的 wheel 改滚候选菜单;DSH 对话区自身的程序滚动不收起。 */
|
|
10823
10969
|
react.useEffect(() => {
|
|
10824
10970
|
if (platformModelOpen === null) return undefined;
|
|
10825
10971
|
const anchor = platformModelAnchorRef.current;
|
|
10826
|
-
const
|
|
10827
|
-
const closeNow = () => {
|
|
10972
|
+
const menu = platformModelMenuRef.current;
|
|
10973
|
+
const closeNow = () => {
|
|
10974
|
+
const state = platformModelOpen;
|
|
10975
|
+
if (state !== null && state !== undefined && state.dirty === true) {
|
|
10976
|
+
const index = state.index;
|
|
10977
|
+
const model = typeof state.filter === "string" ? state.filter : "";
|
|
10978
|
+
setPlatformModelRow(index, { model: model });
|
|
10979
|
+
}
|
|
10980
|
+
const m = platformModelMenuRef.current;
|
|
10981
|
+
if (m !== null && m !== undefined && m.style !== undefined) m.style.display = "none";
|
|
10982
|
+
setPlatformModelOpen(null);
|
|
10983
|
+
};
|
|
10984
|
+
/* 设置区归属:以 input 锚点所属的 .dsb-settings 为准,再找真正包住设置 root 的滚动祖先。
|
|
10985
|
+
menu 可能被 portal 到别处,不能拿 menu 反推设置区;滚动来源只有落在设置 root 内部
|
|
10986
|
+
或那个真实滚动祖先上才算“设置滚动”,DSH 对话区自身(message-list 等)的程序滚动一律放行。 */
|
|
10987
|
+
const isNode = (value) => value !== null && value !== undefined;
|
|
10988
|
+
const containsNode = (parent, child) => isNode(parent) && isNode(child) && typeof parent.contains === "function" && parent.contains(child) === true;
|
|
10989
|
+
const settingsRoot = isNode(anchor) && typeof anchor.closest === "function" ? anchor.closest(".dsb-settings") : null;
|
|
10990
|
+
const findScrollAncestor = (start) => {
|
|
10991
|
+
let node = isNode(start) ? start.parentElement : null;
|
|
10992
|
+
while (isNode(node)) {
|
|
10993
|
+
let scrollable = false;
|
|
10994
|
+
try {
|
|
10995
|
+
if (typeof getComputedStyle === "function") {
|
|
10996
|
+
const cs = getComputedStyle(node);
|
|
10997
|
+
scrollable = isNode(cs) && (cs.overflowY === "auto" || cs.overflowY === "scroll");
|
|
10998
|
+
}
|
|
10999
|
+
} catch (err) { scrollable = false; }
|
|
11000
|
+
if (scrollable !== true && typeof node.scrollHeight === "number" && typeof node.clientHeight === "number") scrollable = node.scrollHeight > node.clientHeight + 2;
|
|
11001
|
+
if (scrollable === true) return node;
|
|
11002
|
+
node = node.parentElement;
|
|
11003
|
+
}
|
|
11004
|
+
return null;
|
|
11005
|
+
};
|
|
11006
|
+
const settingsScroller = findScrollAncestor(isNode(settingsRoot) ? settingsRoot : anchor);
|
|
11007
|
+
const isOuterPageScroll = (target) => typeof document !== "undefined" && isNode(document) && (target === document || target === document.documentElement || target === document.body);
|
|
11008
|
+
const isSettingsScroll = (event) => {
|
|
11009
|
+
const target = isNode(event) ? event.target : null;
|
|
11010
|
+
if (isNode(target) !== true) return false;
|
|
11011
|
+
if (containsNode(settingsRoot, target)) return true;
|
|
11012
|
+
if (containsNode(target, settingsRoot)) return true; /* target 是包住设置 root 的实际滚动祖先 */
|
|
11013
|
+
if (isNode(settingsScroller) && (target === settingsScroller || containsNode(settingsScroller, target))) return true;
|
|
11014
|
+
if (isOuterPageScroll(target)) return true;
|
|
11015
|
+
/* 解析不到设置 root 时退回旧行为(非菜单就关),避免漏关;解析得到时只认设置区。 */
|
|
11016
|
+
return isNode(settingsRoot) !== true;
|
|
11017
|
+
};
|
|
11018
|
+
const isInputWheel = (event) => isNode(event) && event.type === "wheel" && containsNode(anchor, event.target);
|
|
11019
|
+
const menuCanScroll = (node, deltaY) => {
|
|
11020
|
+
if (!isNode(node) || typeof node.scrollTop !== "number" || typeof node.scrollHeight !== "number"
|
|
11021
|
+
|| typeof node.clientHeight !== "number" || typeof deltaY !== "number"
|
|
11022
|
+
|| Number.isFinite(deltaY) !== true || deltaY === 0) return false;
|
|
11023
|
+
const maxScroll = Math.max(0, node.scrollHeight - node.clientHeight);
|
|
11024
|
+
const top = Math.max(0, Math.min(maxScroll, node.scrollTop));
|
|
11025
|
+
return deltaY > 0 ? top < maxScroll : top > 0;
|
|
11026
|
+
};
|
|
11027
|
+
const routeWheelToMenu = (event) => {
|
|
11028
|
+
const m = platformModelMenuRef.current;
|
|
11029
|
+
const deltaY = event !== null && event !== undefined ? event.deltaY : undefined;
|
|
11030
|
+
if (menuCanScroll(m, deltaY) !== true) return false;
|
|
11031
|
+
const maxScroll = Math.max(0, m.scrollHeight - m.clientHeight);
|
|
11032
|
+
m.scrollTop = Math.max(0, Math.min(maxScroll, m.scrollTop + deltaY));
|
|
11033
|
+
if (typeof event.preventDefault === "function") event.preventDefault();
|
|
11034
|
+
if (typeof event.stopPropagation === "function") event.stopPropagation();
|
|
11035
|
+
return true;
|
|
11036
|
+
};
|
|
11037
|
+
/* 菜单内部滚动不关闭:下拉自身就是 overflow-y:auto 的滚动容器,滚它时事件目标在菜单里。
|
|
11038
|
+
window 的捕获监听先于菜单自身的监听触发,所以必须在这里用 contains 放行;
|
|
11039
|
+
菜单再拦一层 wheel/touchmove 冒泡,别让外层 document 的关闭逻辑看到。
|
|
11040
|
+
window 的 wheel 捕获监听必须非 passive:输入框滚轮要 preventDefault 把 deltaY 改滚候选菜单、不传给背景;
|
|
11041
|
+
菜单自身的 wheel/touchmove 仍只 stopPropagation、不 preventDefault,照常滚动。 */
|
|
11042
|
+
const isMenuEvent = (event) => {
|
|
11043
|
+
const node = platformModelMenuRef.current;
|
|
11044
|
+
const target = event !== null && event !== undefined ? event.target : null;
|
|
11045
|
+
return node !== null && node !== undefined && target !== null && target !== undefined
|
|
11046
|
+
&& typeof node.contains === "function" && node.contains(target) === true;
|
|
11047
|
+
};
|
|
11048
|
+
const closeOnScroll = (event) => {
|
|
11049
|
+
if (isMenuEvent(event) === true) return; /* B:菜单内部滚动不关闭 */
|
|
11050
|
+
if (isInputWheel(event) === true && routeWheelToMenu(event) === true) return; /* A:仅菜单能沿 delta 方向滚动时接管输入框滚轮 */
|
|
11051
|
+
if (isSettingsScroll(event) === true) closeNow(); /* C/E:只有真实设置区滚动才关闭 */
|
|
11052
|
+
};
|
|
11053
|
+
const stopMenuScroll = (event) => { if (event !== null && event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation(); };
|
|
10828
11054
|
const pop = anchor !== null && anchor !== undefined && typeof anchor.closest === "function" ? anchor.closest(".dsb-platform-pop") : null;
|
|
10829
11055
|
const list = anchor !== null && anchor !== undefined && typeof anchor.closest === "function" ? anchor.closest(".dsb-platform-model-list") : null;
|
|
10830
|
-
if (pop !== null && pop !== undefined) pop.addEventListener("scroll",
|
|
10831
|
-
if (list !== null && list !== undefined) list.addEventListener("scroll",
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
11056
|
+
if (pop !== null && pop !== undefined) pop.addEventListener("scroll", closeOnScroll, { passive: true });
|
|
11057
|
+
if (list !== null && list !== undefined) list.addEventListener("scroll", closeOnScroll, { passive: true });
|
|
11058
|
+
if (menu !== null && menu !== undefined && typeof menu.addEventListener === "function") {
|
|
11059
|
+
menu.addEventListener("wheel", stopMenuScroll, { passive: true });
|
|
11060
|
+
menu.addEventListener("touchmove", stopMenuScroll, { passive: true });
|
|
11061
|
+
}
|
|
11062
|
+
window.addEventListener("scroll", closeOnScroll, true);
|
|
11063
|
+
window.addEventListener("wheel", closeOnScroll, { passive: false, capture: true });
|
|
11064
|
+
window.addEventListener("touchmove", closeOnScroll, { passive: true, capture: true });
|
|
10835
11065
|
return () => {
|
|
10836
|
-
if (pop !== null && pop !== undefined) pop.removeEventListener("scroll",
|
|
10837
|
-
if (list !== null && list !== undefined) list.removeEventListener("scroll",
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
11066
|
+
if (pop !== null && pop !== undefined) pop.removeEventListener("scroll", closeOnScroll);
|
|
11067
|
+
if (list !== null && list !== undefined) list.removeEventListener("scroll", closeOnScroll);
|
|
11068
|
+
if (menu !== null && menu !== undefined && typeof menu.removeEventListener === "function") {
|
|
11069
|
+
menu.removeEventListener("wheel", stopMenuScroll);
|
|
11070
|
+
menu.removeEventListener("touchmove", stopMenuScroll);
|
|
11071
|
+
}
|
|
11072
|
+
window.removeEventListener("scroll", closeOnScroll, true);
|
|
11073
|
+
window.removeEventListener("wheel", closeOnScroll, { passive: false, capture: true });
|
|
11074
|
+
window.removeEventListener("touchmove", closeOnScroll, { passive: true, capture: true });
|
|
10841
11075
|
};
|
|
10842
11076
|
}, [platformModelOpen]);
|
|
10843
11077
|
/* 平台编辑气泡:绘制前按实际高度决定向上/向下弹 */
|
|
@@ -10897,9 +11131,31 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10897
11131
|
/* 币种下拉菜单(CNY/USD):展开后同样按底部溢出量滚进视野。
|
|
10898
11132
|
用户实测反馈"还要手动滚一下"的就是它 —— 上一轮只接到了价格编辑浮层。 */
|
|
10899
11133
|
useRevealBottom(currencyMenuRef, currencyOpen === true, null);
|
|
10900
|
-
/*
|
|
10901
|
-
|
|
10902
|
-
|
|
11134
|
+
/* 平台编辑区(行内展开):task-14 — 打开编辑区**不再**平白滚动(用户要求原地展开、
|
|
11135
|
+
不跳到固定位置);只有用户点「添加模型」让行数增加时,才把编辑区底边带进视野
|
|
11136
|
+
(保留原来的自动露出行为)。用 prev 记录上次「平台名 + 行数」:首次进入 / 换平台
|
|
11137
|
+
都视为打开、不滚;同一平台行数增加才补滚。 */
|
|
11138
|
+
react.useEffect(() => {
|
|
11139
|
+
if (platformEditing === null || platformDraft === null) {
|
|
11140
|
+
platformRevealLenRef.current = null;
|
|
11141
|
+
return undefined;
|
|
11142
|
+
}
|
|
11143
|
+
const rows = Array.isArray(platformDraft.modelRows) ? platformDraft.modelRows : [];
|
|
11144
|
+
const prev = platformRevealLenRef.current;
|
|
11145
|
+
platformRevealLenRef.current = { name: platformEditing, len: rows.length };
|
|
11146
|
+
if (prev === null || prev.name !== platformEditing || rows.length <= prev.len) return undefined;
|
|
11147
|
+
const retry = () => revealBottom(platformEditRef.current);
|
|
11148
|
+
retry();
|
|
11149
|
+
let frame = 0;
|
|
11150
|
+
if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {
|
|
11151
|
+
frame = window.requestAnimationFrame(retry);
|
|
11152
|
+
}
|
|
11153
|
+
return () => {
|
|
11154
|
+
if (frame !== 0 && typeof window !== "undefined" && typeof window.cancelAnimationFrame === "function") {
|
|
11155
|
+
window.cancelAnimationFrame(frame);
|
|
11156
|
+
}
|
|
11157
|
+
};
|
|
11158
|
+
}, [platformEditing, platformDraft === null ? null : platformDraft.modelRows.length]);
|
|
10903
11159
|
/**
|
|
10904
11160
|
* 币种下拉控件(**只在条目的编辑浮层里用一处**:与三个价格框同一处、无文字标签)。
|
|
10905
11161
|
*
|
|
@@ -11082,7 +11338,7 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
11082
11338
|
};
|
|
11083
11339
|
document.addEventListener("pointerdown", onDocPointerDown, true);
|
|
11084
11340
|
return () => document.removeEventListener("pointerdown", onDocPointerDown, true);
|
|
11085
|
-
}, [platformEditing, platformDraft, cfg]);
|
|
11341
|
+
}, [platformEditing, platformDraft, platformModelOpen, cfg]);
|
|
11086
11342
|
/* 厂商目录:点目录外收起所有展开的厂商分组(自定义组是受控的,另同步 catalogNotice=false) */
|
|
11087
11343
|
react.useEffect(() => {
|
|
11088
11344
|
if (typeof document === "undefined" || document === null || typeof document.addEventListener !== "function") return undefined;
|
|
@@ -11284,43 +11540,43 @@ function setDraftTiered(on) {
|
|
|
11284
11540
|
});
|
|
11285
11541
|
}
|
|
11286
11542
|
/* ---- 第三方平台档案:平台列表 / 编辑 / 保存 / 删除(费用倍率与余额查询都挂在这里) ---- */
|
|
11287
|
-
|
|
11543
|
+
/* 平台列表顺序以 relayPlatformOrder 为准:不能直接用 Object.keys ——
|
|
11544
|
+
纯数字平台名(如 35326)会被 JS 对象按数值排到最前,看起来像"夹在中间"。
|
|
11545
|
+
relayPlatformOrder 里没有的平台(旧配置迁移 / 手改配置)按对象键序补在末尾,保证不丢平台。 */
|
|
11546
|
+
const platformBook = cfg.relayPlatforms === undefined || cfg.relayPlatforms === null ? {} : cfg.relayPlatforms;
|
|
11547
|
+
const platformNames = normalizePlatformOrder(cfg.relayPlatformOrder, platformBook);
|
|
11288
11548
|
/* 平台编辑的六个输入:按 Enter 后立即失焦,不残留输入光标 */
|
|
11289
11549
|
const blurOnEnter = (event) => {
|
|
11290
11550
|
if (event === null || event === undefined || event.key !== "Enter") return;
|
|
11291
11551
|
if (typeof event.preventDefault === "function") event.preventDefault();
|
|
11292
11552
|
if (event.target !== null && event.target !== undefined && typeof event.target.blur === "function") event.target.blur();
|
|
11293
11553
|
};
|
|
11294
|
-
|
|
11295
|
-
const
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
while (size > 10 && button.scrollWidth > button.clientWidth) {
|
|
11300
|
-
size -= 0.5;
|
|
11301
|
-
button.style.fontSize = size + "px";
|
|
11302
|
-
}
|
|
11303
|
-
};
|
|
11304
|
-
const platformOf = (name) => normalizePlatform((cfg.relayPlatforms === undefined || cfg.relayPlatforms === null ? {} : cfg.relayPlatforms)[name]);
|
|
11305
|
-
/** 打开平台编辑:优先回显宿主已保存的真实值(含密文令牌 / 用户 ID);无快照时回退平台档案。 */
|
|
11306
|
-
function startPlatform(name) {
|
|
11307
|
-
cancelEdit();
|
|
11554
|
+
|
|
11555
|
+
const platformOf = (name) => normalizePlatform(platformBook[name]);
|
|
11556
|
+
/** 打开平台编辑:非密字段优先本地平台档案;令牌 / 用户 ID 从宿主快照回显。 */
|
|
11557
|
+
/** 依据当前 Host 快照 + 本地档案构造编辑草稿(token / userId 仅来自 Host 回显)。 */
|
|
11558
|
+
function platformDraftOf(name) {
|
|
11308
11559
|
const platform = platformOf(name);
|
|
11309
|
-
const saved =
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
|
|
11315
|
-
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11560
|
+
const saved = relayChannelOf(name);
|
|
11561
|
+
/* 宿主 relayConfigView 会回传运行时默认值(New-Api-User / data.quota 等)。
|
|
11562
|
+
只有 saved.endpoint 非空(该平台已有可用地址 / 首次探测成功已写回)时,才认为
|
|
11563
|
+
这些默认值确实能查到余额并回填;地址为空时只显示本地档案里用户显式填过的值,
|
|
11564
|
+
空就是空,绝不把默认值塞进输入框。令牌 / 用户 ID 只存在宿主凭据,仍从 saved 回显。 */
|
|
11565
|
+
const savedEndpoint = saved !== null && typeof saved.endpoint === "string" ? saved.endpoint.trim() : "";
|
|
11566
|
+
const savedReady = savedEndpoint.length > 0;
|
|
11567
|
+
const platformText = (key) => (platform === null || typeof platform[key] !== "string" ? "" : platform[key]);
|
|
11568
|
+
const platformBalance = platform === null ? "" : balanceFieldText(platform);
|
|
11569
|
+
const savedText = (key) => (saved !== null && typeof saved[key] === "string" && saved[key].length > 0 ? saved[key] : platformText(key));
|
|
11570
|
+
const savedBalance = saved !== null && typeof saved.balancePath === "string" && saved.balancePath.length > 0
|
|
11571
|
+
? balanceFieldText(saved)
|
|
11572
|
+
: platformBalance;
|
|
11573
|
+
return {
|
|
11574
|
+
userIdHeader: savedReady ? savedText("userIdHeader") : platformText("userIdHeader"),
|
|
11575
|
+
endpoint: savedReady ? savedEndpoint : platformText("endpoint"),
|
|
11576
|
+
balanceField: savedReady ? savedBalance : platformBalance,
|
|
11322
11577
|
token: saved !== null && typeof saved.token === "string" ? saved.token : "",
|
|
11323
11578
|
userId: saved !== null && typeof saved.userId === "string" ? saved.userId : "",
|
|
11579
|
+
touched: {},
|
|
11324
11580
|
/* 适用模型 = 价格库下拉行;档案里有几行就回填几行,
|
|
11325
11581
|
**永远至少一行**(新建 / 已存档案模型为空都补一行空白,用户要求固定常驻) */
|
|
11326
11582
|
modelRows: (platform === null || platform.models.length === 0)
|
|
@@ -11331,10 +11587,35 @@ function setDraftTiered(on) {
|
|
|
11331
11587
|
? (one.feeConfigured === true ? "1" : "")
|
|
11332
11588
|
: String(one.feeMultiplier)
|
|
11333
11589
|
}))
|
|
11334
|
-
}
|
|
11590
|
+
};
|
|
11591
|
+
}
|
|
11592
|
+
function startPlatform(name) {
|
|
11593
|
+
cancelEdit();
|
|
11594
|
+
/* task-31:打开平台先用当前快照填草稿(同步,避免交互等待),随后强制刷新
|
|
11595
|
+
relay-balance-config,再用最新快照重填(仅当用户尚未触碰任何字段)。这样后台自动
|
|
11596
|
+
探测写入的 endpoint / balanceKind / 解析字段不会因陈旧空快照被默认 data.quota/500000 覆盖。 */
|
|
11597
|
+
const seq = ++platformRefreshSeqRef.current;
|
|
11598
|
+
platformRefreshOkRef.current = true;
|
|
11599
|
+
setPlatformDraft(platformDraftOf(name));
|
|
11335
11600
|
setPlatformEditing(name);
|
|
11336
11601
|
setPlatformNotice(null);
|
|
11337
11602
|
setPlatformModelOpen(null);
|
|
11603
|
+
if (devOn === true) return;
|
|
11604
|
+
/* task-33:把这次强制刷新挂到 pendingRef,让“刷新还没回来就点外部保存”的 savePlatform
|
|
11605
|
+
先等它完成,避免用旧空快照/空草稿把自动探测结果覆盖成空地址 + data.quota/500000。 */
|
|
11606
|
+
const pending = refreshRelayState().then(() => {
|
|
11607
|
+
if (seq !== platformRefreshSeqRef.current) return;
|
|
11608
|
+
setPlatformDraft((prev) => {
|
|
11609
|
+
if (prev === null) return prev;
|
|
11610
|
+
if (prev.touched !== undefined && prev.touched !== null && Object.keys(prev.touched).length > 0) return prev;
|
|
11611
|
+
return platformDraftOf(name);
|
|
11612
|
+
});
|
|
11613
|
+
}).catch(() => { /* 拿不到最新快照就沿用当前快照 */ });
|
|
11614
|
+
platformRefreshPendingRef.current = pending;
|
|
11615
|
+
pending.then(() => {
|
|
11616
|
+
platformRefreshOkRef.current = relayLoadOk;
|
|
11617
|
+
if (platformRefreshPendingRef.current === pending) platformRefreshPendingRef.current = null;
|
|
11618
|
+
});
|
|
11338
11619
|
}
|
|
11339
11620
|
/** 新平台:名称只做「非空白 + 不重名」两项校验(数字/英文/符号都允许);**添加即落库**再进编辑。 */
|
|
11340
11621
|
function addPlatform() {
|
|
@@ -11353,9 +11634,14 @@ function setDraftTiered(on) {
|
|
|
11353
11634
|
档案必须在添加那一刻就存在,后续编辑只是补充字段。 */
|
|
11354
11635
|
const platforms = Object.assign({}, cfg.relayPlatforms);
|
|
11355
11636
|
platforms[name] = normalizePlatform({});
|
|
11356
|
-
|
|
11637
|
+
/* 新平台追加到显示顺序末尾(纯数字名也不会被 JS 键序提前) */
|
|
11638
|
+
const order = normalizePlatformOrder(cfg.relayPlatformOrder, platforms).filter((one) => one !== name);
|
|
11639
|
+
order.push(name);
|
|
11640
|
+
setConfig({ relayPlatforms: platforms, relayPlatformOrder: order });
|
|
11357
11641
|
}
|
|
11358
11642
|
function cancelPlatformEdit() {
|
|
11643
|
+
platformRefreshSeqRef.current += 1;
|
|
11644
|
+
platformRefreshPendingRef.current = null;
|
|
11359
11645
|
setPlatformEditing(null);
|
|
11360
11646
|
setPlatformDraft(null);
|
|
11361
11647
|
setPlatformNotice(null);
|
|
@@ -11363,7 +11649,11 @@ function setDraftTiered(on) {
|
|
|
11363
11649
|
setPlatformPopUp(false);
|
|
11364
11650
|
}
|
|
11365
11651
|
function setPlatformField(key, value) {
|
|
11366
|
-
setPlatformDraft((prev) => (prev === null ? prev : Object.assign({}, prev, {
|
|
11652
|
+
setPlatformDraft((prev) => (prev === null ? prev : Object.assign({}, prev, {
|
|
11653
|
+
[key]: value,
|
|
11654
|
+
/* 记下用户亲手改过的字段:即使填的值恰好等于 Host 默认值,也要当显式值保留。 */
|
|
11655
|
+
touched: Object.assign({}, prev.touched, { [key]: true })
|
|
11656
|
+
})));
|
|
11367
11657
|
}
|
|
11368
11658
|
/** 适用模型下拉行:增行 / 改行 / 删行(行索引只在本次草稿里有效) */
|
|
11369
11659
|
function addPlatformModelRow() {
|
|
@@ -11391,15 +11681,50 @@ function setDraftTiered(on) {
|
|
|
11391
11681
|
});
|
|
11392
11682
|
}
|
|
11393
11683
|
/** 平台保存:写 config → 按适用模型行把倍率写进价格条目 → 同步宿主余额查询配置(直接保存、不校验不拦截)。 */
|
|
11394
|
-
function savePlatform() {
|
|
11684
|
+
async function savePlatform() {
|
|
11395
11685
|
if (platformEditing === null || platformDraft === null) return;
|
|
11396
11686
|
const name = platformEditing;
|
|
11397
|
-
|
|
11687
|
+
let draftNow = platformDraft;
|
|
11688
|
+
if (platformModelOpen !== null && platformModelOpen !== undefined && platformModelOpen.dirty === true) {
|
|
11689
|
+
const rows = Array.isArray(draftNow.modelRows) ? draftNow.modelRows : [];
|
|
11690
|
+
const index = platformModelOpen.index;
|
|
11691
|
+
if (Number.isInteger(index) && index >= 0 && index < rows.length && rows[index] !== null && rows[index] !== undefined) {
|
|
11692
|
+
const model = typeof platformModelOpen.filter === "string" ? platformModelOpen.filter : "";
|
|
11693
|
+
draftNow = Object.assign({}, draftNow, { modelRows: rows.map((one, at) => at === index ? Object.assign({}, one, { model: model }) : one) });
|
|
11694
|
+
}
|
|
11695
|
+
}
|
|
11696
|
+
/* task-33:刷新还没回来就点外部/保存时,先等强制刷新完成,避免用旧空快照下的空草稿
|
|
11697
|
+
把 Host 自动探测出的 endpoint/解析字段覆盖成空地址 + data.quota/500000。 */
|
|
11698
|
+
const pendingRefresh = platformRefreshPendingRef.current;
|
|
11699
|
+
if (pendingRefresh !== null && pendingRefresh !== undefined) {
|
|
11700
|
+
try { await pendingRefresh; } catch (error) { /* 刷新失败沿用当前快照 */ }
|
|
11701
|
+
}
|
|
11702
|
+
/* 按字段合并:仅对「用户没触碰过」的字段用刷新后的最新快照值,显式输入一律保留;
|
|
11703
|
+
模型行来自草稿不受影响。这样未动字段的自动保存不会退回 data.quota/500000。 */
|
|
11704
|
+
const touchedNow = draftNow.touched === undefined || draftNow.touched === null ? {} : draftNow.touched;
|
|
11705
|
+
const freshDraft = platformDraftOf(name);
|
|
11706
|
+
draftNow = Object.assign({}, draftNow, {
|
|
11707
|
+
userIdHeader: touchedNow.userIdHeader === true ? draftNow.userIdHeader : freshDraft.userIdHeader,
|
|
11708
|
+
endpoint: touchedNow.endpoint === true ? draftNow.endpoint : freshDraft.endpoint,
|
|
11709
|
+
balanceField: touchedNow.balanceField === true ? draftNow.balanceField : freshDraft.balanceField,
|
|
11710
|
+
token: touchedNow.token === true ? draftNow.token : freshDraft.token,
|
|
11711
|
+
userId: touchedNow.userId === true ? draftNow.userId : freshDraft.userId
|
|
11712
|
+
});
|
|
11398
11713
|
const oldPlatform = platformOf(name);
|
|
11714
|
+
/* Host 当前快照:Host 可能已自动探测写入地址,而本地旧档案的 endpoint 本来就是空的。 */
|
|
11715
|
+
const hostChannel = relayChannelOf(name);
|
|
11716
|
+
const hostEndpoint = hostChannel !== null && typeof hostChannel.endpoint === "string" ? hostChannel.endpoint.trim() : "";
|
|
11399
11717
|
const endpoint = typeof draftNow.endpoint === "string" ? draftNow.endpoint.trim() : "";
|
|
11400
11718
|
const endpointValid = endpoint.length > 0 && /^https?:\/\//i.test(endpoint);
|
|
11719
|
+
const refreshTrusted = platformRefreshOkRef.current === true;
|
|
11720
|
+
/* task-35/37/39:强制刷新不可信(refreshTrusted=false)且快照里该平台 endpoint 为空
|
|
11721
|
+
(含 channel 不存在、已存在但 endpoint 仍空、以及首次 GET 从未成功三种常见情况)、
|
|
11722
|
+
本地地址也为空、用户未改地址 → 进入「existing 合并」模式:不发送通用 fallback 字段,
|
|
11723
|
+
交给 Host updateRelayConfig 用 existing 合并,避免把自动探测的 endpoint / balancePath /
|
|
11724
|
+
currency / divisor / balanceKind 覆盖。本地已有的显式请求头 / 解析字段仍照常发出。 */
|
|
11725
|
+
const mergeExistingHost = refreshTrusted !== true && hostEndpoint.length === 0
|
|
11726
|
+
&& endpoint.length === 0 && touchedNow.endpoint !== true;
|
|
11401
11727
|
let noticeKey = null;
|
|
11402
|
-
if (endpoint.length > 0 && endpointValid !== true) noticeKey = noticeKey || "priceEndpointInvalid";
|
|
11403
11728
|
let balance = {};
|
|
11404
11729
|
if (typeof draftNow.balanceField === "string" && draftNow.balanceField.trim().length > 0) {
|
|
11405
11730
|
const parsed = parseBalanceField(draftNow.balanceField);
|
|
@@ -11434,13 +11759,32 @@ function setDraftTiered(on) {
|
|
|
11434
11759
|
});
|
|
11435
11760
|
/* 地址非法就只存空地址(不报错不拦截),其它字段照常保存 */
|
|
11436
11761
|
const endpointOk = endpointValid ? endpoint : "";
|
|
11762
|
+
/* Host 运行时预填值(New-Api-User / data.quota 等)不是用户填的:本地档案原本没有、草稿又与 Host 回显一字不差 → 不写进本地,避免清空地址后变成永久本地值;用户明确改过的值(与回显不同)照常保留。 */
|
|
11763
|
+
const touched = draftNow.touched === undefined || draftNow.touched === null ? {} : draftNow.touched;
|
|
11764
|
+
const localUserIdHeader = oldPlatform === null ? "" : oldPlatform.userIdHeader;
|
|
11765
|
+
const hostUserIdHeader = hostChannel !== null && typeof hostChannel.userIdHeader === "string" ? hostChannel.userIdHeader : "";
|
|
11766
|
+
const draftUserIdHeader = typeof draftNow.userIdHeader === "string" ? draftNow.userIdHeader : "";
|
|
11767
|
+
const userIdHeaderValue = localUserIdHeader.length === 0 && touched.userIdHeader !== true && hostEndpoint.length > 0 && draftUserIdHeader === hostUserIdHeader ? "" : draftUserIdHeader;
|
|
11768
|
+
const localBalanceEmpty = oldPlatform === null || oldPlatform.balancePath.length === 0;
|
|
11769
|
+
const hostBalanceField = hostChannel === null ? "" : balanceFieldText(hostChannel);
|
|
11770
|
+
const draftBalanceField = typeof draftNow.balanceField === "string" ? draftNow.balanceField.trim() : "";
|
|
11771
|
+
const autoHostBalance = localBalanceEmpty && touched.balanceField !== true && hostEndpoint.length > 0 && hostBalanceField.length > 0 && draftBalanceField === hostBalanceField;
|
|
11772
|
+
const effectiveBalance = autoHostBalance ? {} : balance;
|
|
11773
|
+
/* task-29:自动保存(未触碰解析字段、地址未变、草稿只是 Host 回显)时,向 Host 沿用其精确
|
|
11774
|
+
balancePath/currency/balanceDivisor,避免用 data.quota/500000 覆盖自动探测结果(否则 Server
|
|
11775
|
+
视为解析字段变化会清 balanceKind,后续同 endpoint 查询永久 invalid-balance)。不把 balanceKind
|
|
11776
|
+
写本地/写 Host:字段不变,服务端自然保留现有 kind。 */
|
|
11777
|
+
const hostBalancePathRaw = hostChannel !== null && typeof hostChannel.balancePath === "string" ? hostChannel.balancePath : "";
|
|
11778
|
+
const hostCurrencyRaw = hostChannel !== null && typeof hostChannel.currency === "string" ? hostChannel.currency : "";
|
|
11779
|
+
const hostBalanceDivisorRaw = hostChannel !== null && typeof hostChannel.balanceDivisor === "number" && Number.isFinite(hostChannel.balanceDivisor) && hostChannel.balanceDivisor > 0 ? hostChannel.balanceDivisor : null;
|
|
11780
|
+
const useHostBalanceFields = autoHostBalance && endpointValid === true && endpoint === hostEndpoint;
|
|
11437
11781
|
const platform = normalizePlatform({
|
|
11438
11782
|
endpoint: endpointOk,
|
|
11439
|
-
userIdHeader:
|
|
11783
|
+
userIdHeader: userIdHeaderValue,
|
|
11440
11784
|
/* 没填就存空(normalizePlatform 不再塞默认值);默认值只在向宿主 POST 时补 */
|
|
11441
|
-
balancePath:
|
|
11442
|
-
currency:
|
|
11443
|
-
balanceDivisor:
|
|
11785
|
+
balancePath: effectiveBalance.balancePath,
|
|
11786
|
+
currency: effectiveBalance.currency,
|
|
11787
|
+
balanceDivisor: effectiveBalance.balanceDivisor,
|
|
11444
11788
|
models: picked.map((one) => Object.assign({ model: one[0], feeMultiplier: one[1] },
|
|
11445
11789
|
one[1] === 1 && one[2] === true ? { feeConfigured: true } : {}))
|
|
11446
11790
|
}) || normalizePlatform({});
|
|
@@ -11468,34 +11812,49 @@ function setDraftTiered(on) {
|
|
|
11468
11812
|
setConfig({ models: next, relayPlatforms: platforms });
|
|
11469
11813
|
const secretToken = typeof draftNow.token === "string" ? draftNow.token : "";
|
|
11470
11814
|
const secretUserId = typeof draftNow.userId === "string" ? draftNow.userId : "";
|
|
11471
|
-
/* 同步宿主:地址合法且非空 →
|
|
11815
|
+
/* 同步宿主:地址合法且非空 → 保存余额查询配置;地址为空且旧平台也没有地址
|
|
11816
|
+
(新平台 / 还没配过)→ 仍要 POST:令牌 / 用户 ID 只随 POST 走,不能因为地址没填
|
|
11817
|
+
就整条丢掉;endpoint 传空串,由 Host 按模型页 provider baseURL 推导默认地址。
|
|
11818
|
+
旧平台原本有地址、这次清空 → 移除旧配置。
|
|
11472
11819
|
feeMultiplier 固定 1:计费倍率已随价格库上报,避免 Host 二次相乘。 */
|
|
11473
11820
|
const relayFailure = (data) => {
|
|
11474
11821
|
const reason = data !== null && data !== undefined && typeof data.reason === "string" ? data.reason : "failed";
|
|
11475
|
-
|
|
11822
|
+
console.warn("[dsh-desktop-statusbar] " + t("priceRelaySyncFailed", { reason: reason }));
|
|
11476
11823
|
};
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11824
|
+
/* 是否存在可移除的旧地址:本地档案有地址,或 Host 自动探测已写入(本地可能为空)。 */
|
|
11825
|
+
const hadEndpoint = (oldPlatform !== null && oldPlatform.endpoint.length > 0) || hostEndpoint.length > 0;
|
|
11826
|
+
const blankEndpointNew = endpoint.length === 0 && hadEndpoint !== true;
|
|
11827
|
+
if (endpointValid === true || blankEndpointNew === true) {
|
|
11828
|
+
/* task-35/37:mergeExistingHost 时不发通用 fallback 字段,交给 Host existing 合并;
|
|
11829
|
+
但本地已有的显式请求头 / 余额解析字段必须照常发出,不能丢用户配置。 */
|
|
11830
|
+
const payload = { channelKey: name, feeMultiplier: 1 };
|
|
11831
|
+
if (mergeExistingHost !== true) {
|
|
11832
|
+
payload.endpoint = platform.endpoint;
|
|
11833
|
+
payload.tokenHeader = platform.tokenHeader;
|
|
11834
|
+
payload.tokenPrefix = "Bearer ";
|
|
11484
11835
|
/* 档案里空 = 用户没填,但**运行时就按默认值跑**(用户确认的口径):
|
|
11485
11836
|
请求头 New-Api-User、余额字段 ¥data.quota / 500000(CNY,除数 500000)。
|
|
11486
11837
|
默认值只在这里补,不写回档案 —— 再打开编辑仍是空的。 */
|
|
11487
|
-
userIdHeader
|
|
11488
|
-
balancePath: platform.balancePath.length > 0 ? platform.balancePath : "data.quota"
|
|
11489
|
-
currency: platform.currency.length > 0 ? platform.currency : "CNY"
|
|
11490
|
-
balanceDivisor: platform.balanceDivisor === null ? 500000 : platform.balanceDivisor
|
|
11491
|
-
}
|
|
11838
|
+
payload.userIdHeader = platform.userIdHeader.length > 0 ? platform.userIdHeader : "New-Api-User";
|
|
11839
|
+
payload.balancePath = useHostBalanceFields && hostBalancePathRaw.length > 0 ? hostBalancePathRaw : (platform.balancePath.length > 0 ? platform.balancePath : "data.quota");
|
|
11840
|
+
payload.currency = useHostBalanceFields && hostCurrencyRaw.length > 0 ? hostCurrencyRaw : (platform.currency.length > 0 ? platform.currency : "CNY");
|
|
11841
|
+
payload.balanceDivisor = useHostBalanceFields && hostBalanceDivisorRaw !== null ? hostBalanceDivisorRaw : (platform.balanceDivisor === null ? 500000 : platform.balanceDivisor);
|
|
11842
|
+
} else {
|
|
11843
|
+
/* 本地显式请求头 / parser 照发(空则不覆盖 Host 现有值,避免 relaySettings 判非法)。 */
|
|
11844
|
+
if (platform.userIdHeader.length > 0) payload.userIdHeader = platform.userIdHeader;
|
|
11845
|
+
if (platform.balancePath.length > 0) {
|
|
11846
|
+
payload.balancePath = platform.balancePath;
|
|
11847
|
+
if (platform.currency.length > 0) payload.currency = platform.currency;
|
|
11848
|
+
if (platform.balanceDivisor !== null) payload.balanceDivisor = platform.balanceDivisor;
|
|
11849
|
+
}
|
|
11850
|
+
}
|
|
11492
11851
|
/* 密文只在本次输入时带上:空 = 保留宿主原值(提交后本地不保留) */
|
|
11493
11852
|
if (secretToken.length > 0) payload.token = secretToken;
|
|
11494
11853
|
if (secretUserId.length > 0) payload.userId = secretUserId;
|
|
11495
11854
|
postRelayState(payload).then((data) => {
|
|
11496
11855
|
if (data === null || data === undefined || data.ok !== true) relayFailure(data);
|
|
11497
11856
|
}).catch(() => { relayFailure(null); });
|
|
11498
|
-
} else if (
|
|
11857
|
+
} else if (hadEndpoint === true) {
|
|
11499
11858
|
postRelayState({ remove: true, channelKey: name }).then((data) => {
|
|
11500
11859
|
if (data === null || data === undefined || data.ok !== true) relayFailure(data);
|
|
11501
11860
|
}).catch(() => { relayFailure(null); });
|
|
@@ -11517,11 +11876,13 @@ function setDraftTiered(on) {
|
|
|
11517
11876
|
delete entry.feeConfigured;
|
|
11518
11877
|
next[one.model] = entry;
|
|
11519
11878
|
});
|
|
11520
|
-
|
|
11879
|
+
const order = normalizePlatformOrder(cfg.relayPlatformOrder, platforms);
|
|
11880
|
+
setConfig({ models: next, relayPlatforms: platforms, relayPlatformOrder: order });
|
|
11521
11881
|
if (platformEditing === name) cancelPlatformEdit();
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11882
|
+
/* 删除任何已存在的平台都发幂等 remove:即使没有 endpoint,也可能存过
|
|
11883
|
+
token/userId/header,必须让 Host 清掉 credential envelope,否则同名重建会残留
|
|
11884
|
+
(Host 的 remove 对不存在 / 无地址的 channel 是幂等的)。 */
|
|
11885
|
+
postRelayState({ remove: true, channelKey: name }).catch(() => { /* 移除失败不影响本地删除 */ });
|
|
11525
11886
|
}
|
|
11526
11887
|
function saveDraft() {
|
|
11527
11888
|
if (editing === null || draft === null) return;
|
|
@@ -12112,7 +12473,7 @@ function setDraftTiered(on) {
|
|
|
12112
12473
|
})),
|
|
12113
12474
|
/* 适用模型 = 价格库下拉选择(按 modelOrder)。每行自带标签(像「请求头 / 用户 ID」
|
|
12114
12475
|
那样:标签在左、输入框紧随其后),不再单独做整行表头。
|
|
12115
|
-
|
|
12476
|
+
旧档案里不在价格库的模型名仍由输入框回显,但不并入候选。 */
|
|
12116
12477
|
h("div", { className: "dsb-relay-fields", key: "__models" }, [
|
|
12117
12478
|
h("div", { className: "dsb-platform-model-list", key: "__modellist" }, platformModelRows.map((one, index) => {
|
|
12118
12479
|
const current = typeof one.model === "string" ? one.model : "";
|
|
@@ -12127,80 +12488,154 @@ function setDraftTiered(on) {
|
|
|
12127
12488
|
modelNames.forEach((name) => {
|
|
12128
12489
|
if (MODEL_PRESENTATION[name] === undefined && names.indexOf(name) === -1) names.push(name);
|
|
12129
12490
|
});
|
|
12130
|
-
if (current.length > 0 && names.indexOf(current) === -1) names.push(current);
|
|
12131
12491
|
/* 已被本平台其他行选中的模型:本行灰显、不可点;当前行自己的已选模型正常显示 */
|
|
12132
12492
|
const chosenByOthers = (modelName) => platformModelRows.some((other, at) => at !== index
|
|
12133
12493
|
&& typeof other.model === "string" && other.model.length > 0
|
|
12134
12494
|
&& sameModelName(other.model, modelName) === true);
|
|
12135
|
-
const menuOpen = platformModelOpen === index;
|
|
12136
12495
|
const modelRowItems = names.filter(function(modelName){ return modelName === current || chosenByOthers(modelName) !== true; }).map(function(modelName){ return { name: modelName, disabled: modelName.length>0 && chosenByOthers(modelName)===true, selected: modelName===current }; });
|
|
12496
|
+
/* 可输入筛选:候选仍取自 modelRowItems;按显示名或原始名做大小写无关包含匹配。
|
|
12497
|
+
筛选文本挂在 platformModelOpen;dirty 输入仅在保存时写回对应模型行。 */
|
|
12498
|
+
const platformMenuState = platformModelOpen !== null && platformModelOpen !== undefined && typeof platformModelOpen === "object" ? platformModelOpen : null;
|
|
12499
|
+
const menuOpen = platformMenuState !== null && platformMenuState.index === index;
|
|
12500
|
+
const filterText = platformMenuState !== null && typeof platformMenuState.filter === "string" ? platformMenuState.filter : "";
|
|
12501
|
+
const loweredFilter = filterText.trim().toLowerCase();
|
|
12502
|
+
const visibleItems = loweredFilter.length === 0 ? modelRowItems : modelRowItems.filter(function (one) {
|
|
12503
|
+
return one.name.toLowerCase().indexOf(loweredFilter) !== -1 || displayModelName(one.name).toLowerCase().indexOf(loweredFilter) !== -1;
|
|
12504
|
+
});
|
|
12505
|
+
const menuPos = platformModelMenuPosRef.current;
|
|
12506
|
+
const menuVisible = menuOpen === true && visibleItems.length > 0 && menuPos !== null && menuPos !== undefined;
|
|
12507
|
+
const listboxId = "modelrow-list-" + index;
|
|
12508
|
+
const optionId = function (at) { return listboxId + "-" + at; };
|
|
12509
|
+
const closeModelMenu = function () {
|
|
12510
|
+
platformModelAnchorRef.current = null;
|
|
12511
|
+
platformModelMenuPosRef.current = null;
|
|
12512
|
+
setPlatformModelOpen(null);
|
|
12513
|
+
};
|
|
12514
|
+
/* 打开时用 fixed 视口坐标量一次锚点:菜单 portal 到 body,脱离设置卡片的 overflow 裁切。
|
|
12515
|
+
最多 3 个候选;菜单固定从输入框下方展开,maxHeight 不超过视口剩余空间。 */
|
|
12516
|
+
|
|
12517
|
+
const openModelMenu = function (anchorEl) {
|
|
12518
|
+
const anchor = anchorEl !== null && anchorEl !== undefined && typeof anchorEl.closest === "function" ? anchorEl.closest(".dsb-select") : null;
|
|
12519
|
+
if (anchor === null || anchor === undefined || typeof anchor.getBoundingClientRect !== "function") return;
|
|
12520
|
+
const ar = anchor.getBoundingClientRect();
|
|
12521
|
+
const viewportW = typeof window !== "undefined" && typeof window.innerWidth === "number" ? window.innerWidth : 1024;
|
|
12522
|
+
const viewportH = typeof window !== "undefined" && typeof window.innerHeight === "number" ? window.innerHeight : 768;
|
|
12523
|
+
const gap = 4;
|
|
12524
|
+
const margin = 4;
|
|
12525
|
+
const itemH = 30;
|
|
12526
|
+
const count = modelRowItems.length;
|
|
12527
|
+
const desired = count <= 0 ? 0 : 8 + Math.min(count, 3) * itemH;
|
|
12528
|
+
const spaceBelow = Math.max(0, viewportH - ar.bottom - gap - margin);
|
|
12529
|
+
const maxHeight = Math.min(desired, spaceBelow);
|
|
12530
|
+
let left = ar.left;
|
|
12531
|
+
if (left + ar.width > viewportW - margin) left = viewportW - margin - ar.width;
|
|
12532
|
+
if (left < 0) left = 0;
|
|
12533
|
+
let originLeft = 0;
|
|
12534
|
+
let originTop = 0;
|
|
12535
|
+
const portalReady = typeof document !== "undefined" && document !== null && document.body !== undefined && document.body !== null && canPortal === true;
|
|
12536
|
+
if (portalReady !== true && typeof anchor.closest === "function") {
|
|
12537
|
+
const editPop = anchor.closest(".dsb-edit-pop");
|
|
12538
|
+
if (editPop !== null && editPop !== undefined && typeof editPop.getBoundingClientRect === "function") {
|
|
12539
|
+
const editPopRect = editPop.getBoundingClientRect();
|
|
12540
|
+
originLeft = typeof editPopRect.left === "number" ? editPopRect.left : 0;
|
|
12541
|
+
originTop = typeof editPopRect.top === "number" ? editPopRect.top : 0;
|
|
12542
|
+
}
|
|
12543
|
+
}
|
|
12544
|
+
platformModelAnchorRef.current = anchor;
|
|
12545
|
+
platformModelMenuPosRef.current = {
|
|
12546
|
+
left: left - originLeft,
|
|
12547
|
+
width: ar.width,
|
|
12548
|
+
maxHeight: maxHeight,
|
|
12549
|
+
top: ar.bottom + gap - originTop,
|
|
12550
|
+
};
|
|
12551
|
+
setPlatformModelOpen({ index: index, filter: current.length > 0 ? displayModelName(current) : "", dirty: false });
|
|
12552
|
+
};
|
|
12553
|
+
const chooseModel = function (name) {
|
|
12554
|
+
if (typeof name !== "string") return;
|
|
12555
|
+
setPlatformModelRow(index, { model: name });
|
|
12556
|
+
closeModelMenu();
|
|
12557
|
+
};
|
|
12558
|
+
/* 键盘只负责输入筛选,不参与浏览/选择候选:方向键与 Enter 一律不改变选择,仅保留 Escape 关闭气泡(用户要求)。 */
|
|
12559
|
+
const onModelKeyDown = function (event) {
|
|
12560
|
+
const key = event === null || event === undefined ? undefined : event.key;
|
|
12561
|
+
if (key === "Escape" && menuOpen === true) {
|
|
12562
|
+
if (typeof event.preventDefault === "function") event.preventDefault();
|
|
12563
|
+
closeModelMenu();
|
|
12564
|
+
}
|
|
12565
|
+
};
|
|
12566
|
+
const onModelFocus = function (event) {
|
|
12567
|
+
if (menuOpen !== true) {
|
|
12568
|
+
openModelMenu(event.currentTarget);
|
|
12569
|
+
|
|
12570
|
+
}
|
|
12571
|
+
};
|
|
12572
|
+
/* D:菜单已关闭但 input 仍聚焦时,click 不会触发 focus,需要点击主动重开气泡。 */
|
|
12573
|
+
const onModelClick = function (event) {
|
|
12574
|
+
if (menuOpen !== true) openModelMenu(event.currentTarget);
|
|
12575
|
+
};
|
|
12576
|
+
const onModelChange = function (event) {
|
|
12577
|
+
const value = event !== null && event !== undefined && event.target !== null && event.target !== undefined ? event.target.value : "";
|
|
12578
|
+
if (menuOpen !== true) openModelMenu(event.currentTarget);
|
|
12579
|
+
setPlatformModelOpen({ index: index, filter: typeof value === "string" ? value : "", dirty: true });
|
|
12580
|
+
};
|
|
12581
|
+
const onModelBlur = function (event) {
|
|
12582
|
+
if (menuOpen === true && platformMenuState !== null && platformMenuState.dirty === true) {
|
|
12583
|
+
const value = event !== null && event !== undefined && event.currentTarget !== null && event.currentTarget !== undefined ? event.currentTarget.value : "";
|
|
12584
|
+
setPlatformModelRow(index, { model: typeof value === "string" ? value : "" });
|
|
12585
|
+
}
|
|
12586
|
+
closeModelMenu();
|
|
12587
|
+
};
|
|
12137
12588
|
const stop = (event) => {
|
|
12589
|
+
if (event !== null && event !== undefined && typeof event.preventDefault === "function") event.preventDefault();
|
|
12138
12590
|
if (event !== null && event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
12139
12591
|
};
|
|
12140
12592
|
return h("div", { className: "dsb-relay-row dsb-modelrow", key: "__row" + index }, [
|
|
12141
12593
|
relayLine(t("platformModels"), "__modelline", h("div", { className: "dsb-select dsb-modelrow-select" + (current.length > 0 ? "" : " dsb-select-empty"), key: "__model" }, [
|
|
12142
|
-
h("
|
|
12143
|
-
type: "
|
|
12594
|
+
h("input", {
|
|
12595
|
+
type: "text", key: "__modelinput",
|
|
12596
|
+
className: "dsb-select-btn",
|
|
12597
|
+
role: "combobox",
|
|
12598
|
+
"aria-autocomplete": "list",
|
|
12144
12599
|
"aria-haspopup": "listbox",
|
|
12145
|
-
"aria-expanded":
|
|
12146
|
-
|
|
12147
|
-
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
const maxHeight = Math.min(8 + Math.min(modelRowItems.length, 3) * 30, avail);
|
|
12160
|
-
platformModelAnchorRef.current = anchor;
|
|
12161
|
-
platformModelMenuTargetRef.current = target;
|
|
12162
|
-
platformModelMenuPosRef.current = {
|
|
12163
|
-
left: ar.left - tr.left - (target.clientLeft || 0),
|
|
12164
|
-
top: top - tr.top - (target.clientTop || 0),
|
|
12165
|
-
width: ar.width,
|
|
12166
|
-
maxHeight: maxHeight
|
|
12167
|
-
};
|
|
12168
|
-
setPlatformModelOpen(index);
|
|
12169
|
-
}
|
|
12170
|
-
} else {
|
|
12171
|
-
platformModelAnchorRef.current = null;
|
|
12172
|
-
platformModelMenuTargetRef.current = null;
|
|
12173
|
-
platformModelMenuPosRef.current = null;
|
|
12174
|
-
setPlatformModelOpen(null);
|
|
12175
|
-
}
|
|
12176
|
-
}
|
|
12177
|
-
}, current.length > 0 ? displayModelName(current) : h("span", { className: "dsb-select-placeholder" }, t("platformModelSelectPh"))),
|
|
12178
|
-
menuOpen === true
|
|
12600
|
+
"aria-expanded": menuVisible === true ? "true" : "false",
|
|
12601
|
+
"aria-controls": listboxId,
|
|
12602
|
+
"aria-label": t("platformModels"),
|
|
12603
|
+
autoComplete: "off", spellCheck: false, autoCorrect: "off",
|
|
12604
|
+
style: { display: "block", width: "100%", flex: "1 1 auto", minWidth: 0, height: "28px", boxSizing: "border-box" },
|
|
12605
|
+
value: menuOpen === true ? filterText : (current.length > 0 ? displayModelName(current) : ""),
|
|
12606
|
+
placeholder: t("platformModelSelectPh"),
|
|
12607
|
+
onFocus: onModelFocus,
|
|
12608
|
+
onBlur: onModelBlur,
|
|
12609
|
+
onChange: onModelChange,
|
|
12610
|
+
onKeyDown: onModelKeyDown,
|
|
12611
|
+
onClick: onModelClick
|
|
12612
|
+
}),
|
|
12613
|
+
menuVisible === true
|
|
12179
12614
|
? (function () {
|
|
12180
12615
|
const pos = platformModelMenuPosRef.current;
|
|
12181
|
-
if (pos === null || pos === undefined) return null;
|
|
12182
|
-
const
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
12193
|
-
|
|
12194
|
-
|
|
12195
|
-
|
|
12196
|
-
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
}
|
|
12200
|
-
}
|
|
12201
|
-
|
|
12202
|
-
const
|
|
12203
|
-
if (
|
|
12616
|
+
if (visibleItems.length === 0 || pos === null || pos === undefined) return null;
|
|
12617
|
+
const menuStyle = { position: "fixed", left: pos.left + "px", width: pos.width + "px", maxHeight: pos.maxHeight + "px", overflowY: "auto", boxSizing: "border-box" };
|
|
12618
|
+
menuStyle.top = pos.top + "px";
|
|
12619
|
+
menuStyle.bottom = "auto";
|
|
12620
|
+
const menuNode = h("div", { className: "dsb-select-menu dsb-modelrow-menu", role: "listbox", id: listboxId, ref: platformModelMenuRef, style: menuStyle },
|
|
12621
|
+
visibleItems.map(function (one, itemIndex) {
|
|
12622
|
+
return h("button", {
|
|
12623
|
+
type: "button", key: one.name === "" ? "__empty" : one.name, role: "option", id: optionId(itemIndex),
|
|
12624
|
+
"aria-selected": one.selected ? "true" : "false",
|
|
12625
|
+
"aria-disabled": one.disabled ? "true" : "false",
|
|
12626
|
+
disabled: one.disabled,
|
|
12627
|
+
className: "dsb-select-item" + (one.selected ? " dsb-select-item-on" : "") + (one.disabled ? " dsb-select-item-disabled" : ""),
|
|
12628
|
+
onMouseDown: stop,
|
|
12629
|
+
onClick: function (event) {
|
|
12630
|
+
stop(event);
|
|
12631
|
+
if (one.disabled) return;
|
|
12632
|
+
chooseModel(one.name);
|
|
12633
|
+
}
|
|
12634
|
+
}, displayModelName(one.name));
|
|
12635
|
+
}));
|
|
12636
|
+
/* portal 到 body:脱离 .dsb-edit-pop / .dsb-settings 的 overflow 裁切;fixed 坐标贴输入框 */
|
|
12637
|
+
const portalTarget = typeof document !== "undefined" && document !== null && document.body !== undefined ? document.body : null;
|
|
12638
|
+
if (portalTarget !== null && canPortal === true && reactDom !== null && reactDom !== undefined) return reactDom.createPortal(menuNode, portalTarget);
|
|
12204
12639
|
return menuNode;
|
|
12205
12640
|
})()
|
|
12206
12641
|
: null
|