@kenz1117/dsh-ui-usage-billing 1.0.19 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +12 -7
- package/README.md +23 -13
- package/lib/client.js +5 -5
- package/lib/index.js +16 -243
- package/lib/types/aggregate.d.ts +8 -13
- package/lib/types/balance.d.ts +0 -20
- package/lib/types/client/PerfPanel.d.ts +8 -10
- package/lib/types/client/TokenPanel.d.ts +3 -53
- package/lib/types/client/apply.d.ts +3 -10
- package/lib/types/client/budget-store.d.ts +1 -1
- package/lib/types/client/completion-notify.d.ts +2 -2
- package/lib/types/client/live-cost.d.ts +9 -9
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/pricing.d.ts +0 -54
- package/lib/types/client/usage-billing-settings.d.ts +0 -40
- package/package.json +11 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Locale dictionaries for the usage billing surface. */
|
|
2
|
-
export type UsageBillingKey = '
|
|
2
|
+
export type UsageBillingKey = 'title' | 'subtitle' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'liveTurn' | 'liveSession' | 'totalCost' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'trendEmpty' | 'budget' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'project' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'estimated' | 'actual' | 'pricing' | 'showPricing' | 'hidePricing' | 'pricePerM' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'peakHours' | 'band' | 'openDashboard' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptions' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'triggerMonthTokens' | 'floatPrev' | 'floatNext' | 'subscriptionsStale' | 'staleLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemove' | 'sessionStaleBadge' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'workspaces' | 'workspacesHint' | 'plan' | 'remaining' | 'unknownModel' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'currentRound' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabDetails' | 'tabPricing' | 'tabSettings' | 'settingsHead' | 'settingsHint' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionIncluded' | 'free' | 'official' | 'thirdParty' | 'officialCost' | 'thirdPartyCost' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'heatmapYear' | 'heatmapMonth' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginInfo' | 'pluginName' | 'pluginDescription' | 'pluginVersion' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenCacheHitRate' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popQuotaAlert' | 'popRiskNone' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'popBalanceNormal' | 'popBalanceLow' | 'popQuotaNormal' | 'popQuotaLow' | 'alertBalanceLow' | 'alertQuotaLow' | 'unpricedHint' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'exportCsvSite' | 'panelRelay' | 'relaySite' | 'relayDirect' | 'relayUnknown' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'relayCalls';
|
|
3
3
|
export declare const NS = "usageBilling";
|
|
4
4
|
export declare const zh: Record<UsageBillingKey, string>;
|
|
5
5
|
export declare const en: Record<UsageBillingKey, string>;
|
|
@@ -41,12 +41,6 @@ export interface UserPrice {
|
|
|
41
41
|
output: number;
|
|
42
42
|
/** 计价币种;缺省 CNY。 */
|
|
43
43
|
currency?: 'CNY' | 'USD';
|
|
44
|
-
/** 低谷档三桶(元或美元 / 每百万 token);缺省 = 平档(峰谷同价)。 */
|
|
45
|
-
offPeak?: {
|
|
46
|
-
input: number;
|
|
47
|
-
cacheHit: number;
|
|
48
|
-
output: number;
|
|
49
|
-
};
|
|
50
44
|
}
|
|
51
45
|
/** 一条用户自定义价:绑定「模型(计费目录键)+ 可选来源(中转站 origin)」。
|
|
52
46
|
* origin 缺省 = 该模型的默认价;带 origin = 仅该中转站的同名模型用此价。 */
|
|
@@ -56,22 +50,6 @@ export interface UserPriceEntry extends UserPrice {
|
|
|
56
50
|
/** 绑定来源(中转站 origin,如 `https://api.my-relay.com`);缺省 = 默认价。 */
|
|
57
51
|
origin?: string;
|
|
58
52
|
}
|
|
59
|
-
/**
|
|
60
|
-
* 中转站 origin 宽松匹配:双方规范化到 `protocol://host[:port]` 后比较。
|
|
61
|
-
* 宿主侧站点桶的 origin 来自 `new URL(baseURL).origin`,用户手填的来源常缺
|
|
62
|
-
* 协议、带路径或尾斜杠——精确全等会让自定义价静默失效(issue #18)。
|
|
63
|
-
* 规范化失败(无法解析成 URL)时回退小写去尾斜杠的字面比较。
|
|
64
|
-
* @param a - 用户录入的来源(可缺协议/带路径)。
|
|
65
|
-
* @param b - 宿主站点桶的 origin(`new URL().origin` 形态)。
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* 把用户手填的中转站来源规范化为 `protocol://host[:port]` 形态:缺协议补
|
|
69
|
-
* `https://`、带路径取 origin。无法解析时回退小写去尾斜杠的字面值。
|
|
70
|
-
* 与 {@link originsMatch} 的比较口径一致——保存前规范化一次,匹配时双向兜底。
|
|
71
|
-
* @param raw - 用户录入的来源(可缺协议/带路径)。
|
|
72
|
-
*/
|
|
73
|
-
export declare function normalizeOriginInput(raw: string): string;
|
|
74
|
-
export declare function originsMatch(a: string, b: string): boolean;
|
|
75
53
|
/**
|
|
76
54
|
* 注入用户自定义单价列表。每条含模型目录键 + 可选来源(origin)。空数组 = 清除全部
|
|
77
55
|
* 自定义价,回退内置目录。
|
|
@@ -87,20 +65,6 @@ export declare function getUserPrices(): Readonly<UserPriceEntry[]> | undefined;
|
|
|
87
65
|
* @param origin - 调用来源(中转站 origin);缺省仅查默认价。
|
|
88
66
|
*/
|
|
89
67
|
export declare function userPriceOf(key: string, origin?: string): UserPrice | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* 查一个模型(可选来源)的完整用户价条目(含 origin 绑定信息)。
|
|
92
|
-
* 匹配优先级:origin 宽松精确命中(模型×来源)→ 无来源默认价。
|
|
93
|
-
* @param key - 计费目录键。
|
|
94
|
-
* @param origin - 调用来源(中转站 origin);缺省仅查默认价。
|
|
95
|
-
*/
|
|
96
|
-
export declare function userPriceEntryOf(key: string, origin?: string): UserPriceEntry | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* 查一个模型的「带来源」用户价条目(无视来源值,取第一条命中模型名的
|
|
99
|
-
* 带 origin 条目)。供 recost 在三维站点数据缺失时兜底:用户填了来源价
|
|
100
|
-
* 就按它重估,而不是静默回退宿主原价(issue #18)。
|
|
101
|
-
* @param key - 计费目录键。
|
|
102
|
-
*/
|
|
103
|
-
export declare function userOriginPriceEntryOf(key: string): UserPriceEntry | undefined;
|
|
104
68
|
/**
|
|
105
69
|
* Apply the node half's live pricing snapshot. Absent fields keep the
|
|
106
70
|
* built-in catalog and rate; callers never fabricate values.
|
|
@@ -378,24 +342,6 @@ export declare function resolveToken(name: string): string;
|
|
|
378
342
|
* @returns the estimated cost in CNY.
|
|
379
343
|
*/
|
|
380
344
|
export declare function computeCost(entry: ModelEntry, buckets: TokenUsageBuckets, peakShare?: number, nowMs?: number): number;
|
|
381
|
-
/**
|
|
382
|
-
* 按调用时刻精确判定高峰/空闲档并计价(P0-1:替代固定比例混合)。时刻未知
|
|
383
|
-
* (null/NaN,理论不发生在真实事件流)时回退 {@link DEFAULT_PEAK_SHARE} 混合,
|
|
384
|
-
* 保持旧语义不低估。平档模型(无 offPeak)两个时段同价。限时促销与峰谷档
|
|
385
|
-
* 同口径:按事件时刻判定该笔流量当时享受的单价。
|
|
386
|
-
*
|
|
387
|
-
* 历史正确性(按变更节点分段适用规则,不统一套现行价重算历史):
|
|
388
|
-
* - 早于 {@link PEAK_ERA_START_MS} 的事件按当时官方基础价
|
|
389
|
-
* ({@link LEGACY_DEEPSEEK_BANDS})计费;
|
|
390
|
-
* - 峰谷开闸至 {@link WEEKEND_OFFPEAK_START_MS} 之间按 v1 规则(周末不豁免,
|
|
391
|
-
* 周六日 9-12 / 14-18 计峰);
|
|
392
|
-
* - 周末全谷分界起按现行规则({@link tierAt},周六日全天低谷)。
|
|
393
|
-
* @param entry - the catalog entry whose prices apply.
|
|
394
|
-
* @param buckets - token usage counts.
|
|
395
|
-
* @param timeMs - the call's wall-clock time (epoch ms); null falls back to the peak-share mix.
|
|
396
|
-
* @param peakShare - fallback mix used only when `timeMs` is missing.
|
|
397
|
-
* @returns the estimated cost in CNY(USD 计价模型已按当前汇率折算)。
|
|
398
|
-
*/
|
|
399
345
|
export declare function computeCostAt(entry: ModelEntry, buckets: TokenUsageBuckets, timeMs: number | null | undefined, peakShare?: number): number;
|
|
400
346
|
/** 人民币 → 美元(显示换算用):用当前生效汇率(实时优先,缺失回退内置),
|
|
401
347
|
* 与计价链路的 `currentRate()` 同口径,避免实时汇率生效时 USD 显示与计价不一致。 */
|
|
@@ -73,26 +73,6 @@ export declare const SITE_LIST_STORAGE_KEY = "dsh.ui-usage-billing.sites";
|
|
|
73
73
|
export declare function loadSiteListPrefs(): SiteListPrefs;
|
|
74
74
|
/** 写入站点列表偏好。失败静默(展示偏好非关键)。 */
|
|
75
75
|
export declare function saveSiteListPrefs(prefs: SiteListPrefs): void;
|
|
76
|
-
/**
|
|
77
|
-
* 即时代费条(平价消耗胶囊,composer dock 的 LiveCostBar)的显示偏好。
|
|
78
|
-
* 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema);
|
|
79
|
-
* 设置 Tab 与 LiveCostBar 分属两个 React 树,跨树同步走 localStorage +
|
|
80
|
-
* `LIVE_COST_BAR_PREF_EVENT` CustomEvent(同文档即时生效,跨标签页靠 storage 事件)。
|
|
81
|
-
*/
|
|
82
|
-
export interface LiveCostBarPrefs {
|
|
83
|
-
/** 是否显示输入框下方的即时代费条胶囊(默认 true:保持历史行为)。 */
|
|
84
|
-
show: boolean;
|
|
85
|
-
}
|
|
86
|
-
/** 默认即时代费条偏好:显示(升级用户零感知)。 */
|
|
87
|
-
export declare const DEFAULT_LIVE_COST_BAR_PREFS: LiveCostBarPrefs;
|
|
88
|
-
/** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
|
|
89
|
-
export declare const LIVE_COST_BAR_STORAGE_KEY = "dsh.ui-usage-billing.livecost";
|
|
90
|
-
/** 设置 Tab 切换后派发的 CustomEvent 名(LiveCostBar 监听它即时显隐)。 */
|
|
91
|
-
export declare const LIVE_COST_BAR_PREF_EVENT = "dsh.ui-usage-billing.livecost-pref";
|
|
92
|
-
/** 读取即时代费条偏好(含损坏/缺失回退到默认)。仅在浏览器半区调用。 */
|
|
93
|
-
export declare function loadLiveCostBarPrefs(): LiveCostBarPrefs;
|
|
94
|
-
/** 写入即时代费条偏好。失败静默(展示偏好非关键)。 */
|
|
95
|
-
export declare function saveLiveCostBarPrefs(prefs: LiveCostBarPrefs): void;
|
|
96
76
|
/** 用户自定义单价(与 client/pricing.ts 的 `UserPriceEntry` 同形;type import,无运行时依赖)。 */
|
|
97
77
|
export type StoredUserPrice = UserPriceEntry;
|
|
98
78
|
/** 自定义价表:模型(+可选来源)→ 单价,条目列表(支持同名模型绑定不同中转站 origin)。 */
|
|
@@ -107,24 +87,4 @@ export declare const USER_PRICES_STORAGE_KEY = "dsh.ui-usage-billing.prices";
|
|
|
107
87
|
export declare function loadUserPrices(): UserPriceMap;
|
|
108
88
|
/** 写入用户自定义价。失败静默(展示偏好非关键)。 */
|
|
109
89
|
export declare function saveUserPrices(prices: UserPriceMap): void;
|
|
110
|
-
/** 性能曲线的指标视角。 */
|
|
111
|
-
export type PerfMetric = 'ttft' | 'tps';
|
|
112
|
-
/**
|
|
113
|
-
* 性能面板的视图偏好:当前指标 tab 与点亮的模型曲线集合。
|
|
114
|
-
* 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema)。
|
|
115
|
-
*/
|
|
116
|
-
export interface PerfViewPrefs {
|
|
117
|
-
/** 当前指标:首字延时(ms)/ 生成速度(tok/s)。 */
|
|
118
|
-
metric: PerfMetric;
|
|
119
|
-
/** 点亮的模型键列表;缺省 = 按样本数前 5(用户未碰过图例时跟随默认)。 */
|
|
120
|
-
models?: string[];
|
|
121
|
-
}
|
|
122
|
-
/** 默认性能视图偏好:首字延时 tab;模型集合跟随默认(前 5)。 */
|
|
123
|
-
export declare const DEFAULT_PERF_VIEW_PREFS: PerfViewPrefs;
|
|
124
|
-
/** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
|
|
125
|
-
export declare const PERF_VIEW_STORAGE_KEY = "dsh.ui-usage-billing.perf";
|
|
126
|
-
/** 读取性能视图偏好(含损坏/缺失回退到默认)。仅在浏览器半区调用。 */
|
|
127
|
-
export declare function loadPerfViewPrefs(): PerfViewPrefs;
|
|
128
|
-
/** 写入性能视图偏好。失败静默(展示偏好非关键)。 */
|
|
129
|
-
export declare function savePerfViewPrefs(prefs: PerfViewPrefs): void;
|
|
130
90
|
//# sourceMappingURL=usage-billing-settings.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-ui-usage-billing",
|
|
3
3
|
"description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"client": {
|
|
36
36
|
"inject": [
|
|
37
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
37
38
|
"@deepseek-ai/dsh-client-locale",
|
|
38
39
|
"@deepseek-ai/dsh-client-ui-conversation"
|
|
39
40
|
],
|
|
@@ -41,14 +42,17 @@
|
|
|
41
42
|
},
|
|
42
43
|
"compatibility": {
|
|
43
44
|
"dshReleases": {
|
|
44
|
-
"0.1.
|
|
45
|
+
"0.1.0-rc.8": "compatible",
|
|
46
|
+
"0.1.1-rc.1": "compatible",
|
|
47
|
+
"0.1.1-rc.2": "compatible"
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
},
|
|
48
51
|
"scripts": {
|
|
49
52
|
"bundle": "tsdown",
|
|
50
53
|
"watch": "tsdown --watch",
|
|
51
|
-
"test": "vitest run"
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"build": "bash build.sh"
|
|
52
56
|
},
|
|
53
57
|
"license": "MIT",
|
|
54
58
|
"engines": {
|
|
@@ -56,15 +60,14 @@
|
|
|
56
60
|
},
|
|
57
61
|
"peerDependencies": {
|
|
58
62
|
"@deepseek-ai/dsh-api-remotes": "*",
|
|
59
|
-
"@deepseek-ai/dsh-api-session-controller": "*",
|
|
60
63
|
"@deepseek-ai/dsh-atomic-write": "*",
|
|
64
|
+
"@deepseek-ai/dsh-client-connection": "*",
|
|
61
65
|
"@deepseek-ai/dsh-host-webserver": "*",
|
|
62
66
|
"@deepseek-ai/dsh-client-locale": "*",
|
|
63
|
-
"@deepseek-ai/dsh-client-
|
|
67
|
+
"@deepseek-ai/dsh-client-runtime": "*",
|
|
64
68
|
"@deepseek-ai/dsh-client-ui-conversation": "*",
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-primitives": "*",
|
|
66
|
-
"@deepseek-ai/dsh-client-ui-renderer": "*",
|
|
67
69
|
"@deepseek-ai/dsh-client-ui-sidebar": "*",
|
|
70
|
+
"@deepseek-ai/dsh-client-ui-primitives": "*",
|
|
68
71
|
"@deepseek-ai/dsh-client-ui-slots": "*",
|
|
69
72
|
"@deepseek-ai/dsh-credentials": "*",
|
|
70
73
|
"@deepseek-ai/dsh-invariants": "*",
|
|
@@ -81,14 +84,11 @@
|
|
|
81
84
|
"clsx": "^2.1.1"
|
|
82
85
|
},
|
|
83
86
|
"devDependencies": {
|
|
84
|
-
"@deepseek-ai/dsh-api-remotes": "*",
|
|
85
|
-
"@deepseek-ai/dsh-api-session-controller": "*",
|
|
86
87
|
"@deepseek-ai/dsh-client-locale": "*",
|
|
87
|
-
"@deepseek-ai/dsh-client-
|
|
88
|
+
"@deepseek-ai/dsh-client-runtime": "*",
|
|
88
89
|
"@deepseek-ai/dsh-client-test-runtime": "*",
|
|
89
90
|
"@deepseek-ai/dsh-client-ui-conversation": "*",
|
|
90
91
|
"@deepseek-ai/dsh-client-ui-primitives": "*",
|
|
91
|
-
"@deepseek-ai/dsh-client-ui-renderer": "*",
|
|
92
92
|
"@deepseek-ai/dsh-client-ui-slots": "*",
|
|
93
93
|
"@deepseek-ai/dsh-invariants": "*",
|
|
94
94
|
"@testing-library/react": "^16.1.0",
|