dsh-desktop-statusbar 3.0.6 → 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 +102 -24
- package/lib/index.js +55 -10
- package/package.json +1 -1
- package/tests/verify-context.js +23 -3
- package/tests/verify-fixes.js +30 -0
- package/tests/verify-provider-fees.js +66 -1
- package/tests/verify-render.js +7 -0
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
|
* 不再需要「点名字加入」;用户删掉的模型可用「恢复默认」找回。
|
|
@@ -4044,12 +4044,27 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
4044
4044
|
* 蓝紫两色复用总计令牌条已有的「输出」蓝与「未命中输入」紫,不新造颜色。
|
|
4045
4045
|
* 旋转是 CSS animation(见样式表),不占 JS 定时器。
|
|
4046
4046
|
*/
|
|
4047
|
-
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);
|
|
4048
4063
|
const stateClass = state === "running" ? " dsb-ring-running"
|
|
4049
4064
|
: (state === "teamRunning" ? " dsb-ring-team"
|
|
4050
4065
|
: (state === "deepRunning" ? " dsb-ring-deep"
|
|
4051
4066
|
: (state === "error" ? " dsb-ring-error" : (state === "approval" ? " dsb-ring-approval" : ""))));
|
|
4052
|
-
const offset = METER_CIRCUMFERENCE * (1 -
|
|
4067
|
+
const offset = METER_CIRCUMFERENCE * (1 - displayPercent / 100);
|
|
4053
4068
|
const dashes = notchDashes(compact);
|
|
4054
4069
|
return h("svg", {
|
|
4055
4070
|
className: "dsb-ring" + stateClass, key: "__ring", viewBox: "0 0 14 14", width: 14, height: 14
|
|
@@ -4067,7 +4082,19 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
4067
4082
|
/* SVG 的弧默认从 3 点方向起,整体转 -90° 才是官方那种"12 点起、顺时针长" */
|
|
4068
4083
|
transform: "rotate(-90 7 7)",
|
|
4069
4084
|
strokeDasharray: METER_CIRCUMFERENCE, strokeDashoffset: offset
|
|
4070
|
-
})
|
|
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
|
+
)
|
|
4071
4098
|
}
|
|
4072
4099
|
|
|
4073
4100
|
/** 气泡自己那一圈描边的宽度(.dsb-tip 的 box-shadow spread:0 0 0 .5px):
|
|
@@ -6861,6 +6888,8 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
6861
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)}',
|
|
6862
6889
|
".dsb-ring-track{fill:none;stroke:var(--dsw-alias-border-l3,rgba(127,127,127,.25));stroke-width:2px}",
|
|
6863
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}",
|
|
6864
6893
|
/* 运行时:绿色那段在淡灰圆圈里匀速转,像加载圈。
|
|
6865
6894
|
-90° 必须写进关键帧:circle 上的 SVG transform="rotate(-90 7 7)"(把弧的起点挪到 12 点)
|
|
6866
6895
|
会被 CSS transform 整个覆盖,不写回来就会从 3 点起、看起来跑偏。
|
|
@@ -10383,34 +10412,78 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10383
10412
|
}
|
|
10384
10413
|
}, [tipId]);
|
|
10385
10414
|
|
|
10386
|
-
/* 开关状态同步到 <html>:CSS
|
|
10387
|
-
官方「活动 / 用量 / 上下文」节点会重新插回 dock 的嵌套层,光靠 CSS
|
|
10388
|
-
|
|
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
|
+
文字变化不触发,避免每帧空转卡顿。卸载时只还原被我们隐藏过的官方节点。 */
|
|
10389
10428
|
react.useEffect(() => {
|
|
10390
10429
|
if (typeof document === "undefined" || document === null) return undefined;
|
|
10391
10430
|
const root = document.documentElement;
|
|
10392
10431
|
if (root === null || root === undefined || root.classList === undefined) return undefined;
|
|
10393
10432
|
root.classList.add("dsb-on");
|
|
10394
|
-
|
|
10395
|
-
const
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
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; }
|
|
10406
10473
|
}
|
|
10407
|
-
|
|
10408
|
-
|
|
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 });
|
|
10409
10481
|
}
|
|
10410
10482
|
}
|
|
10411
10483
|
return () => {
|
|
10484
|
+
if (observer !== null) observer.disconnect();
|
|
10412
10485
|
root.classList.remove("dsb-on");
|
|
10413
|
-
hidden.forEach((
|
|
10486
|
+
hidden.forEach((prev, el) => { el.style.display = prev; });
|
|
10414
10487
|
};
|
|
10415
10488
|
}, []);
|
|
10416
10489
|
|
|
@@ -10688,7 +10761,11 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10688
10761
|
: subagentTiers;
|
|
10689
10762
|
const ringPercent = ringPercentOf(contextMeter, agentState, ringTiers);
|
|
10690
10763
|
/* 圆环自己就是触发项:点开上下文占用面板;峰谷那两个字不带气泡 */
|
|
10691
|
-
|
|
10764
|
+
/* 用户拍板:气泡(以及环心数字)恢复成**主会话自己**的 contextMeter,
|
|
10765
|
+
不再用 ringPercent 覆盖 percent —— ringPercent 只驱动弧长,是"团队级"数据。 */
|
|
10766
|
+
const contextTip = contextMeter === null
|
|
10767
|
+
? null
|
|
10768
|
+
: { kind: "meter", meter: contextMeter };
|
|
10692
10769
|
const children = [];
|
|
10693
10770
|
if (contextTip !== null) {
|
|
10694
10771
|
children.push(h("button", {
|
|
@@ -10698,7 +10775,8 @@ function setModelCurrency(name, code, draftNow) {
|
|
|
10698
10775
|
"aria-expanded": tipId === "context" ? "true" : "false",
|
|
10699
10776
|
onClick: (event) => toggleTip("context", event)
|
|
10700
10777
|
}, [
|
|
10701
|
-
|
|
10778
|
+
/* 弧长用 ringPercent(谁在跑切数据源),环心数字用 contextMeter.percent(主会话自己) */
|
|
10779
|
+
contextRing(ringPercent, agentState, contextMeter.compact, contextMeter.empty === true ? null : contextMeter.percent),
|
|
10702
10780
|
tipId === "context" ? tipPanelOf(contextTip) : null
|
|
10703
10781
|
]));
|
|
10704
10782
|
}
|
package/lib/index.js
CHANGED
|
@@ -4383,12 +4383,25 @@ function tokenCost(model, at, parts, provider, feeMultiplier, book) {
|
|
|
4383
4383
|
const price = entry.tiered === false ? entry.peak : (isPeakTime(at) ? entry.peak : entry.offPeak)
|
|
4384
4384
|
const use = price !== null && price !== undefined ? price : entry.peak
|
|
4385
4385
|
if (use === null || use === undefined) return 0
|
|
4386
|
+
/* Magpie 是**本机聚合网关**,不套用通用自建 relay「缺倍率不计价」的门槛:
|
|
4387
|
+
provider 含 magpie / 模型走 remote-magpie/、magpie/ 时,缺价格条目倍率默认按 1 计价,
|
|
4388
|
+
与子代理 Magpie 路径(magpieSubagentTokenCost)口径一致,否则主会话里走 Magpie
|
|
4389
|
+
的调用会一律算成 0、只在台账里挂成欠账(用户报的「走 Magpie 有时不被计费」)。
|
|
4390
|
+
通用 relay(非 Magpie)仍走下面「缺 feeConfigured 就返回 0 / 记欠账」的老行为。 */
|
|
4391
|
+
const magpie = isMagpieMainUsage(provider, model)
|
|
4386
4392
|
/* relay:必须明确配置过价格条目的费用倍率,否则视为无价(由调用方记欠账)。 */
|
|
4387
|
-
const
|
|
4393
|
+
const entryFeeRaw = relayPriceFee(entry)
|
|
4394
|
+
const entryFee = entryFeeRaw === null ? (magpie === true ? 1 : null) : entryFeeRaw
|
|
4388
4395
|
if (entryFee === null) return 0
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4396
|
+
/* Magpie 与子代理路径一致:通道倍率一律取 magpieChannelMultiplier(含 channelKey 大小写/别名
|
|
4397
|
+
兜底到唯一 Magpie 通道),不用事件上那个通用 relay 的 feeMultiplier —— 后者按 channelKey
|
|
4398
|
+
精确匹配,provider 写作小写 magpie 时匹配不到 'Magpie' 通道会退回 1,配置就丢了。
|
|
4399
|
+
通用 relay 仍走 feeMultiplier 参数 / relayFeeMultiplierForProvider。 */
|
|
4400
|
+
const channelMultiplier = magpie === true
|
|
4401
|
+
? magpieChannelMultiplier(provider)
|
|
4402
|
+
: (typeof feeMultiplier === 'number' && Number.isFinite(feeMultiplier) && feeMultiplier > 0
|
|
4403
|
+
? feeMultiplier
|
|
4404
|
+
: relayFeeMultiplierForProvider(provider))
|
|
4392
4405
|
/* 旧 relay 通道倍率(兼容存量)× 价格条目倍率(新口径) */
|
|
4393
4406
|
return ((parts.input * numOrZero(use.input) + parts.cacheRead * numOrZero(use.cacheRead)
|
|
4394
4407
|
+ parts.cacheWrite * numOrZero(use.cacheWrite) + parts.output * numOrZero(use.output)) / 1e6)
|
|
@@ -4401,6 +4414,19 @@ function isMagpieSubagentUsage(provider, model) {
|
|
|
4401
4414
|
return typeof model === 'string' && /^(?:remote-magpie|magpie)\//i.test(model) === true
|
|
4402
4415
|
}
|
|
4403
4416
|
|
|
4417
|
+
/**
|
|
4418
|
+
* 主会话(非子代理)用量是否按 Magpie 计价:provider 含 magpie(magpie / remote-magpie 等别名),
|
|
4419
|
+
* **或**模型走 `remote-magpie/`、`magpie/` 命名空间(无论 provider 是否为空)。
|
|
4420
|
+
*
|
|
4421
|
+
* remote-magpie/ 前缀就是局域网 Magpie 的模型命名空间,前缀本身即归属 Magpie,
|
|
4422
|
+
* 不能因为 provider 为空就降级成通用 relay。与 isMagpieSubagentUsage 口径一致。
|
|
4423
|
+
*/
|
|
4424
|
+
function isMagpieMainUsage(provider, model) {
|
|
4425
|
+
const providerText = typeof provider === 'string' ? provider : ''
|
|
4426
|
+
if (providerText.length > 0 && relayIsMagpie(providerText) === true) return true
|
|
4427
|
+
return typeof model === 'string' && /^(?:remote-magpie|magpie)\//i.test(model) === true
|
|
4428
|
+
}
|
|
4429
|
+
|
|
4404
4430
|
/**
|
|
4405
4431
|
* Magpie 通道倍率:先按 channelKey 精确匹配;provider 大小写/别名对不上(magpie vs Magpie)时,
|
|
4406
4432
|
* 退回配置里唯一的 Magpie 通道(readRelayConfig 保证最多一个)。缺省 1。
|
|
@@ -6584,10 +6610,23 @@ function settleUnpriced(ledger) {
|
|
|
6584
6610
|
? peakPrice
|
|
6585
6611
|
: (entry.offPeak !== null && entry.offPeak !== undefined ? entry.offPeak : entry.peak)
|
|
6586
6612
|
const affiliation = providerAffiliation(debt.provider, debt.model)
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
const
|
|
6613
|
+
/* Magpie 归属(provider 含 magpie / 模型 remote-magpie/、magpie/)缺倍率默认 1,
|
|
6614
|
+
与 tokenCost / magpieSubagentTokenCost 口径一致:老台账里挂了 Magpie 欠账的,
|
|
6615
|
+
这里也照 1 结算掉,不再永远留在欠账里。通用 relay 缺倍率仍要求显式配置。 */
|
|
6616
|
+
const magpie = isMagpieMainUsage(debt.provider, debt.model)
|
|
6617
|
+
/* 两条路径,互斥且各自写清:
|
|
6618
|
+
· Magpie:恒可结算,价格条目倍率优先用**已配置**的(relayPriceFee 非 null),没配默认 1 ——
|
|
6619
|
+
不能把已配置的倍率抹成 1。
|
|
6620
|
+
· 普通 relay:必须明确配置倍率才结算(旧债务 feeMultiplier>1 保持兼容),否则继续挂欠账。 */
|
|
6621
|
+
let effectiveEntryFee
|
|
6622
|
+
if (magpie === true) {
|
|
6623
|
+
const magpieEntryFee = relayPriceFee(entry)
|
|
6624
|
+
effectiveEntryFee = magpieEntryFee === null ? 1 : magpieEntryFee
|
|
6625
|
+
} else {
|
|
6626
|
+
const relayEntryFee = affiliation === 'relay' ? relayPriceFee(entry) : null
|
|
6627
|
+
if (affiliation === 'relay' && relayEntryFee === null && !(debt.feeMultiplier > 1)) { remaining.push(debt); continue }
|
|
6628
|
+
effectiveEntryFee = affiliation === 'relay' && relayEntryFee !== null ? relayEntryFee : 1
|
|
6629
|
+
}
|
|
6591
6630
|
const cost = (costOfTier(debt.peak, peakPrice) + costOfTier(debt.offPeak, offPeakPrice))
|
|
6592
6631
|
* debt.feeMultiplier * effectiveEntryFee
|
|
6593
6632
|
addDayCost(day, debt.model, cost)
|
|
@@ -6679,7 +6718,9 @@ async function auditProviderPricingHistory(ledger, book) {
|
|
|
6679
6718
|
slot.oldCost += officialCost
|
|
6680
6719
|
slot.oldCurrency[code] = numOrZero(slot.oldCurrency[code]) + officialCost
|
|
6681
6720
|
const entryFee = relayPriceFee(entry)
|
|
6682
|
-
|
|
6721
|
+
/* Magpie 缺倍率默认按 1(与 tokenCost 一致),不当欠账处理。 */
|
|
6722
|
+
const magpieAudit = isMagpieMainUsage(one.provider, one.model)
|
|
6723
|
+
if (entryFee === null && magpieAudit !== true) {
|
|
6683
6724
|
slot.debts.push({ provider: one.provider, model: one.model, parts: one.parts, peakTime: isPeakTime(one.time) })
|
|
6684
6725
|
} else {
|
|
6685
6726
|
const newCost = tokenCost(one.model, one.time, one.parts, one.provider, 1, auditBook)
|
|
@@ -7046,8 +7087,12 @@ async function collectFileIntoLedger(ledger, file, text, fromMs, rebuilding) {
|
|
|
7046
7087
|
v4 重算那一轮的钱由重建通道独立算出并在末尾覆盖,这里不吃双份。 */
|
|
7047
7088
|
const affiliation = providerAffiliation(one.provider, one.model)
|
|
7048
7089
|
const entry = priceEntryFor(one.model)
|
|
7090
|
+
/* Magpie 归属(provider 含 magpie / 模型 remote-magpie/、magpie/)即使价格条目没配倍率也
|
|
7091
|
+
视为「有价」(tokenCost 对 Magpie 缺倍率默认按 1 折),绝不能挂成欠账 —— 否则主会话
|
|
7092
|
+
走 Magpie 的调用会一直不计费,与子代理 Magpie 路径口径不一致。通用 relay 不变。 */
|
|
7093
|
+
const magpie = isMagpieMainUsage(one.provider, one.model)
|
|
7049
7094
|
const relayFee = affiliation === "relay" && entry !== null ? relayPriceFee(entry) : null
|
|
7050
|
-
const priced = entry !== null && (affiliation !== "relay" || relayFee !== null)
|
|
7095
|
+
const priced = entry !== null && (affiliation !== "relay" || relayFee !== null || magpie === true)
|
|
7051
7096
|
if (priced !== true) {
|
|
7052
7097
|
/* relay 没配倍率:记 provider/model 欠账(feeMultiplier 记 1),绝不按官方价结算。 */
|
|
7053
7098
|
addUnpricedByProvider(day, one.provider, one.model, one.parts, peakTime, affiliation === "relay" ? 1 : one.feeMultiplier)
|
package/package.json
CHANGED
package/tests/verify-context.js
CHANGED
|
@@ -112,8 +112,12 @@ assert.deepStrictEqual(Array.from(dash.rows), [], '空态没有图例行');
|
|
|
112
112
|
assert.deepStrictEqual(Array.from(dash.segments), [], '空态没有分段');
|
|
113
113
|
assert.strictEqual(dash.compact, null, '空态没有压缩点缺口');
|
|
114
114
|
const dashRing = api.contextRing(dash.percent, 'idle');
|
|
115
|
-
assert.strictEqual(Array.from(dashRing.children).length,
|
|
115
|
+
assert.strictEqual(Array.from(dashRing.children).length, 3, '圆环 = 底环 + 进度弧 + 环心数字');
|
|
116
116
|
assert.strictEqual(Array.from(dashRing.children)[1].props.strokeDashoffset, 2 * Math.PI * 5.5, '0% 时进度弧整段留空');
|
|
117
|
+
assert.strictEqual(Array.from(dashRing.children)[2].props.className, 'dsb-ring-percent', '第三项是环心占用数字');
|
|
118
|
+
/* 空态(没有占用数据)环心留空:contextMeter.empty === true / 没有数据时都不显示数字 */
|
|
119
|
+
assert.strictEqual(String(Array.from(dashRing.children)[2].children[0]), '', '空态环心留空');
|
|
120
|
+
assert.strictEqual(Array.from(api.contextRing(0, 'idle', null, null).children)[2].children[0], '', '没有 labelPercent 数据时环心也留空');
|
|
117
121
|
console.log('= 缺占用数据 → 空环 + 横杠(不再整块消失)');
|
|
118
122
|
|
|
119
123
|
/* ------------------------------------------------------------- 段渲染 */
|
|
@@ -141,7 +145,7 @@ assert.strictEqual(contextMeter.compact, null, '没有 capacity 时压缩点为
|
|
|
141
145
|
console.log('= 圆环带上下文占用气泡;压缩点随模型自适应;token 计数段已并入总计,峰谷可点');
|
|
142
146
|
|
|
143
147
|
/* ------------------------------------------------------------- 圆环几何 */
|
|
144
|
-
const ring = api.contextRing(62, 'idle');
|
|
148
|
+
const ring = api.contextRing(62, 'idle', null, 62);
|
|
145
149
|
assert.strictEqual(ring.type, 'svg', '圆环是 svg');
|
|
146
150
|
assert.ok(String(ring.props.className).indexOf('dsb-ring') === 0, '圆环类名');
|
|
147
151
|
const circles = Array.from(ring.children);
|
|
@@ -150,6 +154,22 @@ assert.strictEqual(circles[1].props.className, 'dsb-ring-fill', '进度弧');
|
|
|
150
154
|
assert.strictEqual(circles[1].props.transform, 'rotate(-90 7 7)', '起点在 12 点方向(整体转 -90°)');
|
|
151
155
|
assert.strictEqual(Math.round(circles[1].props.strokeDasharray), Math.round(2 * Math.PI * 5.5), '周长 = 2πr');
|
|
152
156
|
assert.strictEqual(Math.round(circles[1].props.strokeDashoffset), Math.round(2 * Math.PI * 5.5 * 0.38), '62% 时留 38% 的缺口');
|
|
157
|
+
/* 环心数字:显示**主会话自己**的占用(第 4 参 labelPercent),与弧长(第 1 参 percent)不同源。
|
|
158
|
+
用户拍板:弧长在团队运行时切到成员/深层数据,环心数字永远只显示主会话自己的百分比。 */
|
|
159
|
+
assert.strictEqual(circles[2].props.className, 'dsb-ring-percent', '环心是占用数字 text');
|
|
160
|
+
assert.strictEqual(String(circles[2].children[0]), '62', '环心数字 = labelPercent(无 % 号)');
|
|
161
|
+
assert.strictEqual(circles[2].props.fontSize, undefined, '不再写动态 fontSize(字号只由 CSS 固定 6px)');
|
|
162
|
+
assert.strictEqual(circles[2].props['aria-hidden'], 'true', '环心数字对读屏隐藏(气泡已读百分比)');
|
|
163
|
+
/* 主会话百分比 vs 团队弧长不同源:弧长 55% 但环心数字显示主会话自己的 20 */
|
|
164
|
+
const mixed = Array.from(api.contextRing(55, 'teamRunning', null, 20).children);
|
|
165
|
+
assert.ok(Math.abs(mixed[1].props.strokeDashoffset - 2 * Math.PI * 5.5 * 0.45) < 1e-9, '弧长按第 1 参 55%(团队级)');
|
|
166
|
+
assert.strictEqual(String(mixed[2].children[0]), '20', '环心数字按第 4 参 20(主会话自己),不是团队的 55');
|
|
167
|
+
/* 小数取整:32.6 → 33(四舍五入,不显示小数点) */
|
|
168
|
+
assert.strictEqual(String(Array.from(api.contextRing(32.6, 'idle', null, 32.6).children)[2].children[0]), '33', '小数四舍五入成整数');
|
|
169
|
+
assert.strictEqual(String(Array.from(api.contextRing(33.4, 'idle', null, 33.4).children)[2].children[0]), '33', '33.4 向下取整为 33');
|
|
170
|
+
/* 100 留空:14px 环心塞不下三位 */
|
|
171
|
+
assert.strictEqual(String(Array.from(api.contextRing(100, 'idle', null, 100).children)[2].children[0]), '', '达到 100 时环心留空');
|
|
172
|
+
assert.strictEqual(String(Array.from(api.contextRing(99.6, 'idle', null, 99.6).children)[2].children[0]), '', '99.6 四舍五入成 100 后同样留空');
|
|
153
173
|
assert.ok(String(api.contextRing(62, 'running').props.className).includes('dsb-ring-running'), '运行中 → 绿色');
|
|
154
174
|
assert.ok(String(api.contextRing(62, 'error').props.className).includes('dsb-ring-error'), '报错 → 红色');
|
|
155
175
|
assert.ok(String(api.contextRing(62, 'approval').props.className).includes('dsb-ring-approval'), '待审批 → 黄色');
|
|
@@ -164,7 +184,7 @@ assert.strictEqual(notchDashes.length, 3, '缺口 = 画-空-画 三段');
|
|
|
164
184
|
assert.strictEqual(notchDashes[1], 3, '空洞 = 净宽 1 + 描边 2(圆头各向洞内啃半个线宽)');
|
|
165
185
|
assert.ok(Math.abs(notchDashes[0] + notchDashes[1] + notchDashes[2] - 2 * Math.PI * 5.5) < 1e-12, '三段之和精确等于周长');
|
|
166
186
|
assert.ok(Math.abs((notchDashes[0] + notchDashes[1] / 2) - 2 * Math.PI * 5.5 * 0.550464) < 1e-12, '缺口中心落在压缩点上');
|
|
167
|
-
console.log('= 圆环:12
|
|
187
|
+
console.log('= 圆环:12 点起、周长与进度正确、颜色随状态;压缩点处开圆头缺口;环心同源显示占用数字');
|
|
168
188
|
|
|
169
189
|
/* 点击与收起的契约:圆环包在按钮里(hover/展开有灰底),面板点别处收起 */
|
|
170
190
|
const source = fs.readFileSync(PLUGIN, 'utf8');
|
package/tests/verify-fixes.js
CHANGED
|
@@ -513,6 +513,36 @@ const bookOf = (entry) => ({ x: entry });
|
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
console.log('\n===== ⑯ 官方状态栏只藏官方节点:官方选择器定位 + observer 过滤 =====');
|
|
517
|
+
/* 3.0.7 用户实测两条要求:
|
|
518
|
+
① 隐藏必须**只认官方节点**:旧的"从 .dsb-root 逐层向上把非本插件兄弟节点全 display:none"
|
|
519
|
+
会把第三方插件后插入的节点也误藏。改成与 CSS 相同的官方选择器精确定位、只藏官方节点。
|
|
520
|
+
② MutationObserver 只在新增节点匹配(或包含匹配)官方选择器时重扫一次,普通流式文字变化
|
|
521
|
+
不触发,避免卡顿;卸载只还原被我们藏过的官方节点。 */
|
|
522
|
+
assert.ok(/new MutationObserver\(/.test(clientCode), '藏官方底栏必须用 MutationObserver(不能只跑一次)');
|
|
523
|
+
assert.ok(/observer\.observe\(dock,\s*\{\s*childList:\s*true/.test(clientCode), '观察 dock 的 childList 变动(不观察 attributes,避免自激)');
|
|
524
|
+
assert.ok(/observer\.disconnect\(\)/.test(clientCode), '卸载时必须断开 observer');
|
|
525
|
+
assert.ok(/hidden\.forEach\(\(prev, el\) => \{ el\.style\.display = prev; \}\)/.test(clientCode),
|
|
526
|
+
'卸载时把藏过的节点逐个还原(关侧栏/关插件都不留异常)');
|
|
527
|
+
assert.ok(/typeof MutationObserver === "function"/.test(clientCode), '老环境无 MutationObserver 时要优雅降级(退回单次清扫)');
|
|
528
|
+
/* ① 只认官方选择器:三条官方选择器都在,且用 querySelectorAll 定位;
|
|
529
|
+
不许再出现"逐层向上扫兄弟节点"的 indexOf 循环(node = parent / parent.children)。 */
|
|
530
|
+
assert.ok(/aria-label\*="上下文"/.test(clientCode) && /aria-label\*="context used"/.test(clientCode),
|
|
531
|
+
'必须用官方上下文按钮的 aria-label 选择器定位');
|
|
532
|
+
assert.ok(/span\[class\$="_root"\]>button\[aria-haspopup="dialog"\]\[class\$="_trigger"\]/.test(clientCode),
|
|
533
|
+
'必须用官方用量按钮的结构选择器(span[class$=_root]>button[..._trigger])定位');
|
|
534
|
+
assert.ok(/const OFFICIAL_SELECTORS = \[/.test(clientCode), '官方选择器应集中成一个常量表,与 CSS 同源');
|
|
535
|
+
assert.ok(/dock\.querySelectorAll\(OFFICIAL\)/.test(clientCode), '只对官方选择器匹配的节点做隐藏(querySelectorAll(OFFICIAL))');
|
|
536
|
+
assert.ok(!/while \(node && node !== dock\)/.test(clientCode),
|
|
537
|
+
'不许再有"从 .dsb-root 逐层向上到 dock"的兄弟节点清扫循环(会误藏第三方插件节点)');
|
|
538
|
+
assert.ok(!/child\.contains\(barRoot\)/.test(clientCode),
|
|
539
|
+
'不许再用 child.contains(barRoot) 判断兄弟节点并整层 display:none');
|
|
540
|
+
/* ② observer 有官方节点过滤:回调里遍历 addedNodes,touchesOfficial(node) 命中才 sweep。 */
|
|
541
|
+
assert.ok(/const touchesOfficial = \(node\)/.test(clientCode), 'observer 回调必须有"是否牵涉官方节点"的过滤函数');
|
|
542
|
+
assert.ok(/record\.addedNodes/.test(clientCode), 'observer 只检查 addedNodes(新增节点)');
|
|
543
|
+
assert.ok(/if \(relevant\) sweep\(\);/.test(clientCode), '只有新增节点牵涉官方节点时才重扫(普通文字变化不触发)');
|
|
544
|
+
console.log(' 只认官方选择器、无兄弟全隐藏循环;observer 有官方节点过滤,卸载只还原官方节点');
|
|
545
|
+
|
|
516
546
|
console.log('\nFIX REGRESSION CHECKS PASSED');
|
|
517
547
|
})().catch((error) => {
|
|
518
548
|
console.error('FIX REGRESSION CHECKS FAILED:', error && error.message ? error.message : error);
|
|
@@ -590,7 +590,9 @@ assert.equal(fetched.length, magpieMark + 2, 'Magpie 走 quotas + models 两个
|
|
|
590
590
|
const costAfterDebt = await dayCostNow();
|
|
591
591
|
assert.equal(costAfterDebt - costWithDebt, 4, 'settled debt adds the multiplied amount to day cost');
|
|
592
592
|
|
|
593
|
-
/* Tolerant model-name matching: provider prefix + separator variants hit the same price entry.
|
|
593
|
+
/* Tolerant model-name matching: provider prefix + separator variants hit the same price entry.
|
|
594
|
+
remote-magpie/ 前缀归 Magpie,先清空通道配置让倍率=1,避免残留配置干扰命中价断言。 */
|
|
595
|
+
await removeMagpie();
|
|
594
596
|
const tolerantBefore = await dayCostNow();
|
|
595
597
|
priceBook = {
|
|
596
598
|
...priceBook,
|
|
@@ -902,6 +904,69 @@ assert.equal(fetched.length, magpieMark + 2, 'Magpie 走 quotas + models 两个
|
|
|
902
904
|
assert.equal(magpieRes.total.cost, 6, '恢复显式 Magpie 倍率 3 后准确乘算 2 × 3 = 6');
|
|
903
905
|
await postMagpie(1.5);
|
|
904
906
|
|
|
907
|
+
/* ---- Magpie 主会话(非子代理):走通用 tokenCost 也必须按「缺倍率默认 1」计价 ---- */
|
|
908
|
+
/* 用户报的缺陷:主会话里 provider=magpie / 模型 remote-magpie/ 时,providerAffiliation 判为 relay,
|
|
909
|
+
tokenCost 走「缺 feeConfigured 就返回 0 / 记欠账」,于是走 Magpie 的调用有时不被计费。
|
|
910
|
+
修复后:Magpie 归属缺倍率默认 1;配置了通道倍率 / 条目倍率仍照乘。 */
|
|
911
|
+
priceBook = Object.assign({}, priceBook, {
|
|
912
|
+
'magpie-main-model': plainTierPrice(2, 0),
|
|
913
|
+
'magpie-main-entry': Object.assign(tierPrice(1, 0), { feeMultiplier: 2 }),
|
|
914
|
+
});
|
|
915
|
+
await postPrices(priceBook);
|
|
916
|
+
const magpieDayCost = async () => {
|
|
917
|
+
const rep = await daily();
|
|
918
|
+
const d = rep.body.days.find((entry) => entry.date === DAY);
|
|
919
|
+
return d === undefined ? 0 : d.cost;
|
|
920
|
+
};
|
|
921
|
+
/* a) 主会话 provider=magpie,无任何倍率配置 ⇒ 按模型价 2 计(非零,且 ≠ 欠账) */
|
|
922
|
+
await removeMagpie();
|
|
923
|
+
let before = await magpieDayCost();
|
|
924
|
+
writeSession('main-magpie-nocfg', null, [assistantMessage(1, OFF_PEAK_AT, 'magpie', 'magpie-main-model', M)]);
|
|
925
|
+
let after = await magpieDayCost();
|
|
926
|
+
assert.equal(after - before, 2, '主会话 Magpie 无配置:按模型价 2 计(修复前为 0)');
|
|
927
|
+
{ const diskDay = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).days[DAY] || {};
|
|
928
|
+
assert.ok((diskDay.unpricedByProvider || []).every((one) => one.model !== 'magpie-main-model'),
|
|
929
|
+
'主会话 Magpie 无配置不再挂欠账'); }
|
|
930
|
+
|
|
931
|
+
/* b) remote-magpie/ 是局域网 Magpie 的模型命名空间:即使 provider 为空,模型前缀本身
|
|
932
|
+
也归 Magpie,按模型价计(非零)、不挂欠账。不再降级成通用 relay。 */
|
|
933
|
+
await removeMagpie();
|
|
934
|
+
before = await magpieDayCost();
|
|
935
|
+
writeSession('main-prefix-magpie', null, [assistantMessage(1, OFF_PEAK_AT, '', 'remote-magpie/group/magpie-main-model', M)]);
|
|
936
|
+
after = await magpieDayCost();
|
|
937
|
+
assert.equal(after - before, 2, 'provider 为空 + remote-magpie/ 前缀:按 Magpie 模型价 2 计(非零)');
|
|
938
|
+
/* 欠账读台账文件(/api/daily-usage 的响应体不暴露这类欠账,与其它审计用例一致从盘上读)。 */
|
|
939
|
+
const prefixDiskDay = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).days[DAY] || {};
|
|
940
|
+
assert.ok((prefixDiskDay.unpricedByProvider || []).every((one) => one.model !== 'remote-magpie/group/magpie-main-model'),
|
|
941
|
+
'provider 为空 + remote-magpie/ 前缀不再挂欠账');
|
|
942
|
+
|
|
943
|
+
/* c) 配置 Magpie 通道倍率 2 ⇒ 2 × 2 = 4(配置必须生效) */
|
|
944
|
+
await removeMagpie();
|
|
945
|
+
await postMagpie(2);
|
|
946
|
+
before = await magpieDayCost();
|
|
947
|
+
writeSession('main-magpie-chan2', null, [assistantMessage(1, OFF_PEAK_AT, 'magpie', 'magpie-main-model', M)]);
|
|
948
|
+
after = await magpieDayCost();
|
|
949
|
+
assert.equal(after - before, 4, '主会话 Magpie 通道倍率 2 ⇒ 2 × 2 = 4');
|
|
950
|
+
|
|
951
|
+
/* d) 通道倍率 1.5 × 价格条目 feeMultiplier 2 × 模型价 1 = 3(与子代理口径一致) */
|
|
952
|
+
await removeMagpie();
|
|
953
|
+
await postMagpie(1.5);
|
|
954
|
+
before = await magpieDayCost();
|
|
955
|
+
writeSession('main-magpie-entry', null, [assistantMessage(1, OFF_PEAK_AT, 'magpie', 'magpie-main-entry', M)]);
|
|
956
|
+
after = await magpieDayCost();
|
|
957
|
+
assert.equal(after - before, 3, '主会话 Magpie 通道 1.5 × 条目 2 × 模型价 1 = 3');
|
|
958
|
+
|
|
959
|
+
/* e) 反证:普通自建 relay(plain-provider)主会话缺 feeConfigured 仍记 0 / 欠账(行为不许改) */
|
|
960
|
+
await removeMagpie();
|
|
961
|
+
before = await magpieDayCost();
|
|
962
|
+
writeSession('main-plain-relay', null, [assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'plain-unpriced-model', M)]);
|
|
963
|
+
after = await magpieDayCost();
|
|
964
|
+
assert.equal(after - before, 0, '普通 relay 主会话缺倍率仍为 0(不按官方价误计)');
|
|
965
|
+
{ const diskDay = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).days[DAY] || {};
|
|
966
|
+
assert.ok((diskDay.unpricedByProvider || []).some((one) => one.provider === 'plain-provider' && one.model === 'plain-unpriced-model'),
|
|
967
|
+
'普通 relay 主会话缺倍率仍记欠账(行为不变)'); }
|
|
968
|
+
|
|
969
|
+
console.log('Magpie 主会话: 无配置按模型价非零 / remote-magpie 前缀同上 / 通道与条目倍率照乘 / 普通 relay 缺倍率仍 0 且记欠账。');
|
|
905
970
|
console.log('Magpie subagent: 默认模型价非零 / 无配置默认 1 倍 / 显式通道与条目倍率准确 / 普通 relay 缺倍率仍 0。');
|
|
906
971
|
console.log('PROVIDER FEE CHECKS PASSED');
|
|
907
972
|
console.log('Projection: message/attempt/summary providers, missing-provider defaults, provider-only calls (no event multiplier), replay version.');
|
package/tests/verify-render.js
CHANGED
|
@@ -370,6 +370,13 @@ function renderTree() {
|
|
|
370
370
|
assert.ok(reduced[0].includes('.dsb-ring-team') && reduced[0].includes('.dsb-ring-deep'),
|
|
371
371
|
'reduced-motion 那条必须同时包含蓝档与紫档(与绿色同待遇,不能只停一个):' + (reduced === null ? '' : reduced[0]));
|
|
372
372
|
|
|
373
|
+
/* ⑧-4b 环心占用数字的 CSS 必须存在:字号 / 填充 / pointer-events 缺一不可(用户 3.0.7) */
|
|
374
|
+
assert.ok(/\.dsb-ring-percent\{[^}]*pointer-events:none/.test(cssSource),
|
|
375
|
+
'环心数字 .dsb-ring-percent 必须 pointer-events:none(否则挡住圆环按钮的点击/悬停)');
|
|
376
|
+
assert.ok(/\.dsb-ring-percent\{[^}]*font-size:/.test(cssSource), '环心数字必须显式给字号,否则 SVG text 默认 16px 会溢出 14px 环');
|
|
377
|
+
assert.ok(/\.dsb-ring-percent\{[^}]*fill:/.test(cssSource), '环心数字必须有显式填充色(跟随主题文字色)');
|
|
378
|
+
|
|
379
|
+
|
|
373
380
|
/* ⑧-5 弧长:teamRunning 用成员级最大(55),不是 Lead 自己的占用 */
|
|
374
381
|
const circumference = api.METER_CIRCUMFERENCE;
|
|
375
382
|
const percentToOffset = (pc) => circumference * (1 - pc / 100);
|