@kenz1117/dsh-ui-usage-billing 1.8.3-alpha.2 → 1.8.3-alpha.21
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 +30 -12
- package/README.md +52 -23
- package/lib/client.js +5 -5
- package/lib/index.js +2566 -407
- package/lib/types/aggregate.d.ts +46 -14
- package/lib/types/balance.d.ts +23 -2
- package/lib/types/builtin-catalog.d.ts +5 -0
- package/lib/types/client/PeakScheduleEditor.d.ts +9 -0
- package/lib/types/client/TaskQueuePanel.d.ts +5 -1
- package/lib/types/client/TokenPanel.d.ts +2 -0
- package/lib/types/client/UsageBilling.d.ts +2 -0
- package/lib/types/client/UsageBillingMainPanel.d.ts +7 -0
- package/lib/types/client/UsageBillingPanelIcon.d.ts +5 -0
- package/lib/types/client/api/balance.d.ts +1 -1
- package/lib/types/client/api/task-queue.d.ts +4 -0
- package/lib/types/client/api/usage-stats.d.ts +16 -2
- package/lib/types/client/constants.d.ts +9 -0
- package/lib/types/client/domain/channel-visibility.d.ts +68 -0
- package/lib/types/client/domain/floating-model.d.ts +31 -0
- package/lib/types/client/domain/types.d.ts +37 -1
- package/lib/types/client/footer-lane.d.ts +114 -0
- package/lib/types/client/live-cost.d.ts +10 -3
- package/lib/types/client/locales.d.ts +2 -1
- package/lib/types/client/panel-capability.d.ts +12 -0
- package/lib/types/client/peak-alert.d.ts +2 -1
- package/lib/types/client/peak-schedule-locales.d.ts +48 -0
- package/lib/types/client/price-drafts.d.ts +19 -0
- package/lib/types/client/price-picker.d.ts +17 -0
- package/lib/types/client/pricing.d.ts +22 -12
- package/lib/types/client/provider-display.d.ts +0 -2
- package/lib/types/client/queue-eligibility.d.ts +45 -0
- package/lib/types/client/round-chart.d.ts +5 -1
- package/lib/types/client/scheduled-band.d.ts +23 -0
- package/lib/types/client/task-queue-quick.d.ts +1 -1
- package/lib/types/client/usage-billing-settings.d.ts +62 -9
- package/lib/types/client/usage-command.d.ts +10 -5
- package/lib/types/config.d.ts +2 -0
- package/lib/types/guard.d.ts +30 -3
- package/lib/types/peak-ledger.d.ts +21 -0
- package/lib/types/peak-schedule-history.d.ts +7 -0
- package/lib/types/peak-schedule-models.d.ts +21 -0
- package/lib/types/peak-schedule-store.d.ts +10 -0
- package/lib/types/peak-schedule.d.ts +67 -0
- package/lib/types/pricing-shared.d.ts +81 -1
- package/lib/types/reconcile.d.ts +11 -2
- package/lib/types/routes/balance.d.ts +6 -3
- package/lib/types/routes/peak-schedule.d.ts +12 -0
- package/lib/types/routes/pricing-models.d.ts +11 -0
- package/lib/types/task-queue-band.d.ts +80 -0
- package/lib/types/task-queue-shared.d.ts +57 -0
- package/lib/types/task-queue.d.ts +110 -3
- package/package.json +75 -64
package/lib/types/aggregate.d.ts
CHANGED
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
* zero while their tokens still count. Pure functions only: the persistence
|
|
11
11
|
* handle is injected, so the fold is unit-testable without a host.
|
|
12
12
|
*/
|
|
13
|
+
import { type PeakSchedule, type ScheduleHistory } from './peak-schedule.ts';
|
|
13
14
|
import type { SessionEvent, SessionHeader, SessionId, SessionLogOffset as SessionLogOffsetT } from '@deepseek-ai/dsh-session/types';
|
|
14
15
|
import type { TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
15
16
|
import { resolveCatalogKey } from './client/pricing.ts';
|
|
17
|
+
import type { TokenUsageBuckets } from './client/pricing.ts';
|
|
16
18
|
import { BUILTIN_MODEL_KEY_ALIASES } from './builtin-catalog.ts';
|
|
19
|
+
import { type SiteRef } from './pricing-shared.ts';
|
|
20
|
+
export { siteBucketKey, type SiteRef, type SiteKind } from './pricing-shared.ts';
|
|
17
21
|
/** 会话日志偏移:宿主 0.1.2-alpha.4 前的 dsh-session/types 不导出 SessionLogOffset
|
|
18
22
|
* 值,具名导入让这些宿主装载即崩(v1.4.19~v1.4.22 实测,alpha.3 真机复现);
|
|
19
23
|
* namespace 导入不做具名导出校验,缺导出时退化为恒等——偏移类型是
|
|
@@ -79,16 +83,6 @@ export interface ProviderRouteView {
|
|
|
79
83
|
/** 该路由配置的端点地址;无值 = 直连厂商(非中转站)。 */
|
|
80
84
|
baseURL?: string;
|
|
81
85
|
}
|
|
82
|
-
/** 站点归属分类:site=中转站(有 baseURL origin);direct=直连;unknown=未知路由(配置已删)。 */
|
|
83
|
-
export type SiteKind = 'site' | 'direct' | 'unknown';
|
|
84
|
-
/** 一个 provider 路由归类后的站点引用。 */
|
|
85
|
-
export interface SiteRef {
|
|
86
|
-
kind: SiteKind;
|
|
87
|
-
/** 站点归一化 origin(仅 site)。 */
|
|
88
|
-
origin?: string;
|
|
89
|
-
/** 原 provider 路由名。 */
|
|
90
|
-
provider: string;
|
|
91
|
-
}
|
|
92
86
|
/** 由 baseURL 归一化出站点 origin(协议 + 主机 + 端口);解析失败回退原值。 */
|
|
93
87
|
export declare function siteOriginOf(baseURL: string): string;
|
|
94
88
|
/**
|
|
@@ -110,8 +104,6 @@ export declare function siteOriginOf(baseURL: string): string;
|
|
|
110
104
|
export declare function siteRefOf(provider: string, routes: Readonly<Record<string, ProviderRouteView>>, opts?: {
|
|
111
105
|
subscription?: boolean;
|
|
112
106
|
}): SiteRef;
|
|
113
|
-
/** 站点桶的稳定 key:`site:<origin>` 与 `direct:<provider>` 分开,`unknown` 单一桶。 */
|
|
114
|
-
export declare function siteBucketKey(ref: SiteRef): string;
|
|
115
107
|
/**
|
|
116
108
|
* 站点桶按范围求和(usage_stats 工具的 bySite/relay 口径):bySite 全量累计;
|
|
117
109
|
* relay 只计中转站桶(`site:<origin>` 键)——`direct:*` 与 `unknown` 不计入,
|
|
@@ -130,6 +122,8 @@ export declare function sumSiteBuckets(bySite: Readonly<Record<string, {
|
|
|
130
122
|
};
|
|
131
123
|
/** Aggregation tuning options. */
|
|
132
124
|
export interface AggregateOptions {
|
|
125
|
+
resolvePeakSchedule?: () => PeakSchedule;
|
|
126
|
+
resolvePeakHistory?: () => ScheduleHistory;
|
|
133
127
|
/** 订阅制 provider id 列表;缺省按订阅卡同款 id 判定(`isSubscriptionProviderId`)。 */
|
|
134
128
|
subscriptionProviders?: readonly string[];
|
|
135
129
|
/**
|
|
@@ -191,6 +185,11 @@ export interface AggregateOptions {
|
|
|
191
185
|
export declare const DEFAULT_MAX_CACHE_SESSIONS = 400;
|
|
192
186
|
/** One model's aggregated usage plus estimated cost in CNY. */
|
|
193
187
|
export interface ModelUsage {
|
|
188
|
+
/** Unpriced day/model/site cells only. Excludes free calls and separates account tokens. */
|
|
189
|
+
pendingPrice?: {
|
|
190
|
+
scheduled?: Required<TokenUsageBuckets>;
|
|
191
|
+
native?: Required<TokenUsageBuckets>;
|
|
192
|
+
};
|
|
194
193
|
calls: number;
|
|
195
194
|
input: number;
|
|
196
195
|
output: number;
|
|
@@ -206,6 +205,8 @@ export interface ModelUsage {
|
|
|
206
205
|
reasoning: number;
|
|
207
206
|
/** 该模型本次统计的所有调用是否都走订阅通道(coding/token plan);混合通道不置位。 */
|
|
208
207
|
plan?: boolean;
|
|
208
|
+
/** 模型 × 日期 × 站点格混有订阅和其他调用时,记录可确认的订阅次数。 */
|
|
209
|
+
planCalls?: number;
|
|
209
210
|
/** 走官方渠道的调用数(DeepSeek 官方直连;其余为三方)。 */
|
|
210
211
|
officialCalls: number;
|
|
211
212
|
/** 走官方渠道的费用(CNY);三方费用 = cost - officialCost。 */
|
|
@@ -293,6 +294,7 @@ export interface UsagePersistence {
|
|
|
293
294
|
}
|
|
294
295
|
/** The usage-stats document served to the billing dashboard. */
|
|
295
296
|
export interface UsageStatsDocument {
|
|
297
|
+
peakSchedule?: PeakSchedule;
|
|
296
298
|
version: number;
|
|
297
299
|
updatedAt: number;
|
|
298
300
|
source: 'session-logs';
|
|
@@ -324,6 +326,12 @@ export interface UsageStatsDocument {
|
|
|
324
326
|
byTool?: Record<string, number>;
|
|
325
327
|
/** 会话明细:按费用倒序,封顶 {@link SESSION_ROW_LIMIT} 行;旧快照可能缺失。 */
|
|
326
328
|
bySession: SessionUsageRow[];
|
|
329
|
+
/**
|
|
330
|
+
* 会话总数(未封顶):`bySession` 只带花费前 {@link SESSION_ROW_LIMIT} 行,
|
|
331
|
+
* 真实总数此前从未下发——会话数超过封顶时面板只能说「共 100 个会话」,是错的。
|
|
332
|
+
* 旧快照缺该字段,客户端回退按明细行数。
|
|
333
|
+
*/
|
|
334
|
+
bySessionTotal?: number;
|
|
327
335
|
/** 每轮费用明细:按起始时间倒序,封顶 {@link TURN_ROW_LIMIT} 行;旧快照可能缺失。 */
|
|
328
336
|
byTurn?: TurnUsageRow[];
|
|
329
337
|
/** 工作区聚合:按 cwd 末级目录归并,按费用倒序;旧快照可能缺失。 */
|
|
@@ -365,6 +373,12 @@ export interface UsageStatsDocument {
|
|
|
365
373
|
* (issue #103 加的 staleSnapshot 通道,此前无生产方),零新增客户端体积。
|
|
366
374
|
*/
|
|
367
375
|
staleSnapshot?: boolean;
|
|
376
|
+
/**
|
|
377
|
+
* 会话列表整体读不到时的降级原因(issue #119):目录里有读不了/对不上的
|
|
378
|
+
* 日志、宿主后端临时故障等。此时本档数字全部出自持久账本(可能是空),
|
|
379
|
+
* 客户端据此显示「读取失败」,而不是把空账本当成「没有用量」。
|
|
380
|
+
*/
|
|
381
|
+
sessionListError?: string;
|
|
368
382
|
}
|
|
369
383
|
/** 按角色费用归因:user / tool 为输入成本的启发式摊分,assistant 为输出成本实测。 */
|
|
370
384
|
export interface RoleCost {
|
|
@@ -452,6 +466,9 @@ export declare function subParentOf(meta: SessionHeader): string | undefined;
|
|
|
452
466
|
export declare function foldSubagentFamilies(rows: SessionUsageRow[]): void;
|
|
453
467
|
/** 每轮费用明细行:仪表盘「每轮费用」图的数据源。 */
|
|
454
468
|
export interface TurnUsageRow {
|
|
469
|
+
unpricedSource?: string | null;
|
|
470
|
+
scheduleSource?: string;
|
|
471
|
+
scheduleTier?: 'peak' | 'offPeak';
|
|
455
472
|
/** 会话 id(字符串形式):不同会话的轮次号相互独立,展示时需区分。 */
|
|
456
473
|
sessionId: string;
|
|
457
474
|
/** 会话内轮次号。 */
|
|
@@ -635,6 +652,8 @@ export interface UsageLedgerSession {
|
|
|
635
652
|
* 更早写入的行(配置不参与复用判定);与当前指纹不一致的行不复用、全量重折。
|
|
636
653
|
*/
|
|
637
654
|
fingerprint?: string;
|
|
655
|
+
/** Schedule prefix through this fold's latest event. */
|
|
656
|
+
scheduleFingerprint?: string;
|
|
638
657
|
/**
|
|
639
658
|
* 该行最近一次折叠落盘的时刻(epoch 毫秒)。多实例共享同一账本文件时,
|
|
640
659
|
* save 侧按它做行级合并(后折覆盖先折),防止整份覆盖式落盘丢掉另一实例
|
|
@@ -691,7 +710,7 @@ export declare function mergeUsageLedgerDocuments(document: UsageLedgerDocument,
|
|
|
691
710
|
* 会话费用只剩最近一段,issue #29)。
|
|
692
711
|
* 持久账本行据此区分新旧算法:日志已删/不可读而只能沿用旧行时,UI 标注置信度提示。
|
|
693
712
|
*/
|
|
694
|
-
export declare const FOLD_VERSION =
|
|
713
|
+
export declare const FOLD_VERSION = 24;
|
|
695
714
|
/** 账本里拒读记录的条数上限:防异常环境(大量损坏日志)把账本撑爆;
|
|
696
715
|
* 超限按 Map 插入序保留前 N 条(最早发现的先留,stamp 失效的自然被清理让位)。 */
|
|
697
716
|
export declare const LEDGER_REFUSED_CAP = 500;
|
|
@@ -753,7 +772,7 @@ export declare function foldSession(events: readonly {
|
|
|
753
772
|
time: number;
|
|
754
773
|
data: unknown;
|
|
755
774
|
seq?: number;
|
|
756
|
-
}[], subscriptionProviders: SubscriptionMatcher, officialProviderIds?: ReadonlySet<string>, routes?: Readonly<Record<string, ProviderRouteView>>, searchCallEstimateCny?: number, seedLength?: number, routeAliases?: Readonly<Record<string, string
|
|
775
|
+
}[], subscriptionProviders: SubscriptionMatcher, officialProviderIds?: ReadonlySet<string>, routes?: Readonly<Record<string, ProviderRouteView>>, searchCallEstimateCny?: number, seedLength?: number, routeAliases?: Readonly<Record<string, string>>, history?: ScheduleHistory): SessionFold;
|
|
757
776
|
/**
|
|
758
777
|
* 增量聚合器:按会话缓存折叠结果,用日志文件的 mtime+size 作失效键——
|
|
759
778
|
* 日志没动的会话直接复用,只有写过的会话重新折叠;整份文档另有短 TTL
|
|
@@ -765,6 +784,8 @@ export interface UsageAggregator {
|
|
|
765
784
|
/** Aggregate current usage, reusing cached per-session folds when their logs are untouched.
|
|
766
785
|
* 并发调用共享同一次进行中的折叠(in-flight 去重),不会多倍全量重读。 */
|
|
767
786
|
aggregate(): Promise<UsageStatsDocument>;
|
|
787
|
+
/** Publish a schedule change between folds using the latest timestamp already folded. */
|
|
788
|
+
withPeakScheduleChange<T>(save: (latestEventTime: number) => Promise<T>): Promise<T>;
|
|
768
789
|
/**
|
|
769
790
|
* 按会话 id 取该会话的完整累计用量。doc 的 `byTurn` 封顶(最近 200 轮),
|
|
770
791
|
* 用户回到旧会话续聊时其轮次已被挤出,从 doc 反推会低估——这里直接读该
|
|
@@ -801,6 +822,17 @@ export interface SessionUsageSummary {
|
|
|
801
822
|
* 判定函数无法序列化,统一记为 `fn`(任何函数形态互视为同一指纹)。
|
|
802
823
|
*/
|
|
803
824
|
export declare function configFingerprint(subscriptionMatcher: SubscriptionMatcher, officialProviderIds: ReadonlySet<string> | undefined, routeAliases: Readonly<Record<string, string>>, searchEstimate: number, modelKeyAliases?: Readonly<Record<string, string>>, registeredProviders?: ReadonlySet<string>, routeOrigins?: Readonly<Record<string, string>>): string;
|
|
825
|
+
/**
|
|
826
|
+
* 会话列表整体读不到(issue #119):宿主持久化后端整体故障,或会话目录里有
|
|
827
|
+
* 读不了/对不上的日志。聚合无法枚举会话,只能降级到持久账本或磁盘快照——
|
|
828
|
+
* 但「降级」必须让用户看得见,否则新装用户看到的是一片 ¥0(分不清没花钱
|
|
829
|
+
* 还是没读到)。携带原因随文档下发,客户端据此显示「读取失败」。
|
|
830
|
+
*/
|
|
831
|
+
export declare class SessionListUnavailableError extends Error {
|
|
832
|
+
/** 失败原因摘要(面向用户的中文/英文提示语,由调用方决定措辞)。 */
|
|
833
|
+
readonly reason: string;
|
|
834
|
+
constructor(reason: string, cause?: unknown);
|
|
835
|
+
}
|
|
804
836
|
/**
|
|
805
837
|
* Create the incremental usage aggregator.
|
|
806
838
|
* @param persistence - the session persistence service.
|
package/lib/types/balance.d.ts
CHANGED
|
@@ -13,7 +13,14 @@
|
|
|
13
13
|
* provider's key once and every surface reuses it.
|
|
14
14
|
*/
|
|
15
15
|
import type { Context } from '@deepseek-ai/cordis';
|
|
16
|
-
import type
|
|
16
|
+
import { type BalanceClientMetadata, type CustomBalanceConfig, type CustomBalanceExtract, type ProviderBalance } from './pricing-shared.ts';
|
|
17
|
+
/**
|
|
18
|
+
* 宿主内置平台通道(路由 id `deepseek-official`)的默认凭据 ref——宿主包
|
|
19
|
+
* `llm-deepseek-api-key` 的 `apiKeyEnv` 默认值(`0.1.2-alpha.1` ~ `0.2.3-alpha.3`)。
|
|
20
|
+
* 内置通道不在 llm-pi-ai 路由表里,只能按这个约定 ref 找回它的 key。
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEEPSEEK_PLATFORM_KEY_REF = "DEEPSEEK_API_KEY";
|
|
23
|
+
export declare function apiBalanceSource(row: ProviderBalance): string | undefined;
|
|
17
24
|
/**
|
|
18
25
|
* 从 TokenDance 余额响应提取剩余余额并换算为元。导出供测试:纯函数。
|
|
19
26
|
* 优先用服务端现成的 `balance.balance`(= credits - credits_used);缺失时
|
|
@@ -22,6 +29,17 @@ import type { CustomBalanceConfig, CustomBalanceExtract, ProviderBalance } from
|
|
|
22
29
|
* @returns 剩余余额(元);提取不到返回 undefined。
|
|
23
30
|
*/
|
|
24
31
|
export declare function pickTokenDanceBalanceCny(data: unknown): number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* 余额查询的额外口径(插件配置进不来时的唯一入口)。
|
|
34
|
+
*/
|
|
35
|
+
export interface BalanceQueryOptions {
|
|
36
|
+
/**
|
|
37
|
+
* 额外的凭据候选(按路由 id):插件配置里的 `balanceApiKeyEnv` 之类。排在路由
|
|
38
|
+
* 约定名之前——宿主内置通道的 key 由宿主自己存(默认 ref 固定),插件配置的
|
|
39
|
+
* ref 只是后备。
|
|
40
|
+
*/
|
|
41
|
+
extraKeyRefs?: Readonly<Record<string, readonly string[]>>;
|
|
42
|
+
}
|
|
25
43
|
/**
|
|
26
44
|
* Query every configured provider's account balance. A provider is queried only
|
|
27
45
|
* when its llm-pi-ai route has a key: an explicit `apiKeyEnv`, or — on hosts
|
|
@@ -30,11 +48,14 @@ export declare function pickTokenDanceBalanceCny(data: unknown): number | undefi
|
|
|
30
48
|
* dashboard shows a stable state instead of dropping the row.
|
|
31
49
|
* @param ctx - host context carrying the credentials seam.
|
|
32
50
|
* @param providers - the llm-pi-ai providers dict (`<route> → { apiKeyEnv? }`).
|
|
51
|
+
* @param client - UI metadata for the host login wallet service.
|
|
52
|
+
* @param options - extra credential candidates per route (plugin config).
|
|
33
53
|
* @returns the balance rows (one per provider).
|
|
34
54
|
*/
|
|
35
55
|
export declare function queryBalances(ctx: Context, providers: Readonly<Record<string, {
|
|
36
56
|
apiKeyEnv?: string;
|
|
37
|
-
|
|
57
|
+
baseURL?: string;
|
|
58
|
+
}>>, client?: BalanceClientMetadata, options?: BalanceQueryOptions): Promise<readonly ProviderBalance[]>;
|
|
38
59
|
/**
|
|
39
60
|
* 按 extract 规则从响应 JSON 求值。导出供测试:纯函数。
|
|
40
61
|
* @param rule - 提取规则(const / path / add / subtract / divide)。
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* (瘦身:lib/client.js 约 -30 KiB)。条目结构与消费逻辑见 ./client/pricing.ts。
|
|
5
5
|
*/
|
|
6
6
|
import type { ModelEntry } from './client/pricing.ts';
|
|
7
|
+
/**
|
|
8
|
+
* 内置计费目录(导出态):在原始条目上派生缓存写入单价(issue #123),
|
|
9
|
+
* 使「缓存写入」成为独立计价维度——厂商对写入缓存单独计价时(OpenAI/
|
|
10
|
+
* Anthropic/百炼),缓存写入 token 不再按普通输入价估算。
|
|
11
|
+
*/
|
|
7
12
|
export declare const BUILTIN_MODEL_CATALOG: readonly ModelEntry[];
|
|
8
13
|
/**
|
|
9
14
|
* 真实 provider model id → 计费目录键(`MODEL_CATALOG[].key`)的映射。未知 id
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ScheduleSnapshot } from '../peak-schedule.ts';
|
|
2
|
+
import type { UsageBillingKey } from './locales.ts';
|
|
3
|
+
type Translate = (key: UsageBillingKey) => string;
|
|
4
|
+
export declare function PeakScheduleEditor({ t, onSaved }: {
|
|
5
|
+
t: Translate;
|
|
6
|
+
onSaved?: (snapshot: ScheduleSnapshot) => void;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=PeakScheduleEditor.d.ts.map
|
|
@@ -6,6 +6,10 @@ interface TaskQueuePanelProps {
|
|
|
6
6
|
readonly t: (key: UsageBillingKey, params?: Record<string, unknown>) => string;
|
|
7
7
|
readonly language: BillingLanguage;
|
|
8
8
|
readonly navigateToSession: (sessionId: string) => 'opened' | 'unavailable' | 'failed';
|
|
9
|
+
/** 会话标题(issue #118):卡片显示「将在会话 X 继续」;取不到就显示 id 短码。 */
|
|
10
|
+
readonly sessionTitleOf?: (sessionId: string) => string | undefined;
|
|
11
|
+
/** 「在来源会话继续」开关当前状态:决定安全提示文案。 */
|
|
12
|
+
readonly reuseSourceSession?: boolean;
|
|
9
13
|
}
|
|
10
14
|
interface ImportDefaults {
|
|
11
15
|
readonly cwd: string;
|
|
@@ -14,6 +18,6 @@ interface ImportDefaults {
|
|
|
14
18
|
}
|
|
15
19
|
/** Normalize only the transport shape; authoritative validation stays atomic on the server. */
|
|
16
20
|
export declare function parseTaskQueueImport(text: string, defaults: ImportDefaults): TaskQueueInput[];
|
|
17
|
-
export declare function TaskQueuePanel({ t, language, navigateToSession }: TaskQueuePanelProps): React.ReactNode;
|
|
21
|
+
export declare function TaskQueuePanel({ t, language, navigateToSession, sessionTitleOf, reuseSourceSession }: TaskQueuePanelProps): React.ReactNode;
|
|
18
22
|
export {};
|
|
19
23
|
//# sourceMappingURL=TaskQueuePanel.d.ts.map
|
|
@@ -71,6 +71,8 @@ export declare function TokenPanel(props: {
|
|
|
71
71
|
models?: readonly TrendSeriesModel[];
|
|
72
72
|
/** 金额格式化(跟随仪表盘币种切换):费用构成区块展示用。 */
|
|
73
73
|
money: (cny: number) => string;
|
|
74
|
+
/** 通道桶 key → 通道显示名(issue #126:模型行标注提供方)。 */
|
|
75
|
+
channelName?: (siteKey: string) => string;
|
|
74
76
|
t: (key: UsageBillingKey) => string;
|
|
75
77
|
}): React.ReactNode;
|
|
76
78
|
export {};
|
|
@@ -25,6 +25,8 @@ type BillingBudgetStoreProps = PropsStore<ReturnType<typeof createBillingBudgetS
|
|
|
25
25
|
export type UsageBillingProps = PropsRuntime<'sidebar.footer.action'> & SidebarFooterActionOwnerProps & InjectFace<UsageBillingInjected> & PropsRenderSlots<'billing.dashboard.decor'> & BillingBudgetStoreProps & PropsLocale<typeof NS> & {
|
|
26
26
|
/** 原生设置页嵌入模式:只渲染完整设置分区,不渲染侧栏入口与弹窗外壳。 */
|
|
27
27
|
embeddedSettings?: boolean;
|
|
28
|
+
/** 宿主 main 主面板:渲染完整仪表盘内容,但不渲染触发器、Modal 与关闭按钮。 */
|
|
29
|
+
embeddedPanel?: boolean;
|
|
28
30
|
};
|
|
29
31
|
/**
|
|
30
32
|
* UsageBilling: sidebar trigger plus the billing dashboard modal.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** 宿主 main 主面板:复用完整仪表盘,不再套底部触发器或 Modal(issue #144)。 */
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import { type UsageBillingProps } from './UsageBilling.tsx';
|
|
4
|
+
type UsageBillingMainPanelProps = Omit<UsageBillingProps, 'wide' | 'embeddedSettings' | 'embeddedPanel' | 'renderSlot' | '__renders'>;
|
|
5
|
+
export declare function UsageBillingMainPanel(props: UsageBillingMainPanelProps): ReactNode;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=UsageBillingMainPanel.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** sidebar.panellist 的纯导航图标;宿主拥有外层按钮与选中态。 */
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
4
|
+
export declare function UsageBillingPanelIcon({ size }: PropsRuntime<'sidebar.panellist'>): ReactNode;
|
|
5
|
+
//# sourceMappingURL=UsageBillingPanelIcon.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* GET /api/billing/balance:余额 + 对账提示(同一响应体)。30s 轮询单端点
|
|
3
3
|
* 比拆成两个端点更省(余额查询本身已有熔断与重试),失败回退空值。
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
5
|
+
import { type ProviderBalance, type ReconcileNotice } from '../../pricing-shared.ts';
|
|
6
6
|
/** Path to the account-balance endpoint served by this plugin's node half. */
|
|
7
7
|
export declare const BALANCE_PATH = "/api/billing/balance";
|
|
8
8
|
/** 余额文档(服务端响应体的白名单切片)。 */
|
|
@@ -8,6 +8,10 @@ export type TaskQueueAction = {
|
|
|
8
8
|
cwd: string;
|
|
9
9
|
provider: string;
|
|
10
10
|
model: string;
|
|
11
|
+
/** 来源会话(issue #118):入队时所在的会话。 */
|
|
12
|
+
sourceSessionId?: string;
|
|
13
|
+
/** 是否授权在该来源会话内续跑(入队时冻结的开关状态)。 */
|
|
14
|
+
reuseSource?: boolean;
|
|
11
15
|
} | {
|
|
12
16
|
action: 'enqueueMany';
|
|
13
17
|
tasks: readonly TaskQueueInput[];
|
|
@@ -2,10 +2,24 @@
|
|
|
2
2
|
* GET /api/billing/usage-stats:服务端聚合文档(含 byDay/byModel/bySession/...)。
|
|
3
3
|
* 旧快照可能缺字段(聚合升级前落盘),解析时按字段白名单接受并兜底——避免
|
|
4
4
|
* 渲染路径读 undefined 抛错导致整个插件 surface 被卸载。
|
|
5
|
+
*
|
|
6
|
+
* 取数失败不再吞成空文档(issue #119):此前任何失败(非 2xx / 非 JSON /
|
|
7
|
+
* 超时)都返回 null,面板于是把「没取到」渲染成「用量是 0」——用户看到一片
|
|
8
|
+
* ¥0 却无从判断是没用还是没读到。现在失败带着原因(服务端错误文案 / HTTP
|
|
9
|
+
* 状态 / 异常信息)返回,由界面显示成错误态。
|
|
5
10
|
*/
|
|
6
11
|
import type { UsageStats } from '../domain/types.ts';
|
|
7
12
|
/** Path to the usage-stats endpoint served by this plugin's node half. */
|
|
8
13
|
export declare const USAGE_STATS_PATH = "/api/billing/usage-stats";
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
14
|
+
/** 取数结果:成功带文档;失败带可展示的原因。 */
|
|
15
|
+
export type UsageStatsLoad = {
|
|
16
|
+
ok: true;
|
|
17
|
+
stats: UsageStats;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
reason: string;
|
|
21
|
+
status?: number;
|
|
22
|
+
};
|
|
23
|
+
/** 取统计文档;失败时带原因(不再静默返回 null)。 */
|
|
24
|
+
export declare function loadUsageStats(): Promise<UsageStatsLoad>;
|
|
11
25
|
//# sourceMappingURL=usage-stats.d.ts.map
|
|
@@ -15,6 +15,15 @@ export declare const STATS_REFRESH_INTERVAL_MS = 30000;
|
|
|
15
15
|
/** 弹窗关闭后的统计刷新间隔(毫秒):侧栏触发器只需大致最新值,降到 5 分钟
|
|
16
16
|
* 省宿主聚合(每轮都是折叠 + 五个端点的串行响应)。 */
|
|
17
17
|
export declare const STATS_REFRESH_CLOSED_MS = 300000;
|
|
18
|
+
/**
|
|
19
|
+
* 插件自有 DOM 根容器标记(issue #124):动效压制规则只在本插件根容器内生效。
|
|
20
|
+
*
|
|
21
|
+
* 此前「动效强度」开关把 data-motion 写在 <html> 上,配 `*` 通配符 + !important,
|
|
22
|
+
* 会把宿主与第三方插件的全部动画一起压平(报告者实测右键菜单动画消失)。改为
|
|
23
|
+
* 给每个自有根容器挂这个类,压制规则收进根容器内,宿主与其他插件不受影响。
|
|
24
|
+
* 新增挂载点时记得一并打标——漏标只会让该处动画不再被压制,不会外溢。
|
|
25
|
+
*/
|
|
26
|
+
export declare const BILLING_ROOT_CLASS = "dsh-billing-root";
|
|
18
27
|
/** Empty snapshot: shown before (or without) real host data — zeros, never fabricated samples. */
|
|
19
28
|
export declare const EMPTY_STATS: UsageStats;
|
|
20
29
|
/**
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通道可见性(issue #126 需求):按**通道桶**隐藏部分提供商 / 通道。
|
|
3
|
+
*
|
|
4
|
+
* 报告者场景:通道一多(官方、直连、几个中转、未知路由)时账单列表很长,希望
|
|
5
|
+
* 在设置里勾掉不常看的几个,只留常看的通道。
|
|
6
|
+
*
|
|
7
|
+
* 口径与边界(写死在这里,避免各视图各算一套):
|
|
8
|
+
* - **过滤粒度 = 通道桶 key**(`site:<origin>` / `direct:<provider>` / `unknown`),
|
|
9
|
+
* 不是显示名——显示名随界面语言变(中英),桶 key 稳定,偏好能跨语言沿用。
|
|
10
|
+
* - **只扣可归属的用量**:隐藏通道的用量从 total / byDay / byDayModels /
|
|
11
|
+
* byModel / bySite / byDayModelsSite 中扣除;**无法归属通道的用量保留**
|
|
12
|
+
* (旧格式会话的账本行没有三维维度,无从判断属于哪个通道——宁可多算,
|
|
13
|
+
* 不可静默丢数)。
|
|
14
|
+
* - **无通道维度的维度保持全量口径**:会话 / 工具 / 角色 / 工作区 / 性能 /
|
|
15
|
+
* 峰谷等没有通道切分,隐藏通道不影响它们;界面需注明这一口径差。
|
|
16
|
+
* - 三维数据缺失(旧快照)时**整体不生效**:没有可归属数据就无从过滤,
|
|
17
|
+
* 此时按未过滤渲染,而不是把用量显示成 0。
|
|
18
|
+
*/
|
|
19
|
+
import type { UsageStats } from './types.ts';
|
|
20
|
+
/** 一个通道桶的用量汇总(全量日期)。 */
|
|
21
|
+
export interface ChannelUsage {
|
|
22
|
+
/** 通道桶 key(`site:<origin>` / `direct:<provider>` / `unknown`)。 */
|
|
23
|
+
siteKey: string;
|
|
24
|
+
calls: number;
|
|
25
|
+
input: number;
|
|
26
|
+
output: number;
|
|
27
|
+
cacheHit: number;
|
|
28
|
+
cacheMiss: number;
|
|
29
|
+
cost: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 汇总各通道桶的用量(全量日期,按费用降序;同费用按桶 key 稳定排序)。
|
|
33
|
+
* @param stats - usage-stats 文档(读 byDayModelsSite 三维格)。
|
|
34
|
+
* @returns 每个通道桶一行;无三维数据时返回空数组。
|
|
35
|
+
*/
|
|
36
|
+
export declare function channelUsageOf(stats: UsageStats): readonly ChannelUsage[];
|
|
37
|
+
/**
|
|
38
|
+
* 按显示名归并的通道分组(同名多桶合并:直连与官方同名的两个桶归一行)。
|
|
39
|
+
*/
|
|
40
|
+
export interface ChannelGroup {
|
|
41
|
+
/** 显示名(界面语言下的通道名;未知路由由渲染层兜底文案)。 */
|
|
42
|
+
name: string;
|
|
43
|
+
/** 组内全部通道桶 key —— 隐藏任一即整组隐藏(用户看到的是「这个名字」)。 */
|
|
44
|
+
siteKeys: readonly string[];
|
|
45
|
+
calls: number;
|
|
46
|
+
/** 组内 token 合计(输入 + 输出)。 */
|
|
47
|
+
tokens: number;
|
|
48
|
+
cost: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 把通道桶按显示名归并成组(同名多桶合并),按费用降序。
|
|
52
|
+
* @param rows - 通道桶用量(channelUsageOf 的产物)。
|
|
53
|
+
* @param nameOf - 桶 key → 显示名的解析函数(界面语言相关)。
|
|
54
|
+
* @returns 通道分组列表。
|
|
55
|
+
*/
|
|
56
|
+
export declare function groupChannelsByName(rows: readonly ChannelUsage[], nameOf: (siteKey: string) => string): readonly ChannelGroup[];
|
|
57
|
+
/**
|
|
58
|
+
* 按隐藏通道过滤统计文档。
|
|
59
|
+
*
|
|
60
|
+
* 扣除隐藏通道在 total / byDay / byDayModels / byModel / bySite /
|
|
61
|
+
* byDayModelsSite 中的用量;无通道维度的维度(会话 / 工具 / 角色 / 工作区 /
|
|
62
|
+
* 性能 / 峰谷 / reasoning / 官方口径)保持全量。三维数据缺失时整体原样返回。
|
|
63
|
+
* @param stats - 原始统计文档。
|
|
64
|
+
* @param hidden - 隐藏的通道桶 key 集合。
|
|
65
|
+
* @returns 过滤后的统计文档(未命中任何隐藏通道时返回原对象引用)。
|
|
66
|
+
*/
|
|
67
|
+
export declare function filterStatsByChannels(stats: UsageStats, hidden: ReadonlySet<string>): UsageStats;
|
|
68
|
+
//# sourceMappingURL=channel-visibility.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ProviderBalance, type RelayQuota, type SubscriptionQuota } from '../../pricing-shared.ts';
|
|
2
|
+
import type { BillingCardSpan } from '../usage-billing-settings.ts';
|
|
3
|
+
import type { UsageBillingKey } from '../locales.ts';
|
|
4
|
+
import type { UsageStats } from './types.ts';
|
|
5
|
+
type ModelStats = Pick<UsageStats, 'byDayModels' | 'byDayModelsSite' | 'byModel'>;
|
|
6
|
+
interface Lead {
|
|
7
|
+
name: string;
|
|
8
|
+
cost: number;
|
|
9
|
+
calls: number;
|
|
10
|
+
sources: Set<string>;
|
|
11
|
+
unattributedCalls: number;
|
|
12
|
+
}
|
|
13
|
+
/** Rank metered models on the same day/model costs as the dashboard, including custom prices. */
|
|
14
|
+
export declare function floatingLeads(stats: ModelStats, span: BillingCardSpan, today: string): {
|
|
15
|
+
paid: Lead | undefined;
|
|
16
|
+
plan: Lead | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare function floatingStatus(leads: ReturnType<typeof floatingLeads>, balances: readonly ProviderBalance[], relays: readonly RelayQuota[], quotas: readonly SubscriptionQuota[], threshold: number, t: (key: UsageBillingKey) => string): {
|
|
19
|
+
direct: {
|
|
20
|
+
name: string;
|
|
21
|
+
text: string;
|
|
22
|
+
low: boolean;
|
|
23
|
+
} | undefined;
|
|
24
|
+
sub: {
|
|
25
|
+
name: string;
|
|
26
|
+
text: string;
|
|
27
|
+
low: boolean;
|
|
28
|
+
} | undefined;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=floating-model.d.ts.map
|
|
@@ -137,7 +137,7 @@ export interface ProviderBillingGroup {
|
|
|
137
137
|
/** 归并到该厂商的订阅额度卡片。 */
|
|
138
138
|
subscriptions: readonly SubscriptionQuota[];
|
|
139
139
|
/** 该厂商余额(同厂商只显示一次)。 */
|
|
140
|
-
|
|
140
|
+
balances: readonly ProviderBalance[];
|
|
141
141
|
/** 健康点状态:按厂商名与 health 的在线/失效列表匹配。 */
|
|
142
142
|
dot: string | undefined;
|
|
143
143
|
/** 入口种类;纯订阅/余额组无入口为 vendor。 */
|
|
@@ -151,6 +151,9 @@ export interface UsageBillingInjected {
|
|
|
151
151
|
monthCost: number;
|
|
152
152
|
}) => void;
|
|
153
153
|
registerOpen: (handler: () => void) => () => void;
|
|
154
|
+
/** 宿主是否同时具备 main 与 sidebar.panellist;决定左侧入口能否安全独占(issue #144)。 */
|
|
155
|
+
leftPanelAvailable: () => boolean;
|
|
156
|
+
subscribeLeftPanelAvailable: (listener: () => void) => () => void;
|
|
154
157
|
/** 原生设置页或 /usage 是否至少一个可用;完全隐藏必须有恢复入口(issue #108 防锁死)。 */
|
|
155
158
|
recoveryEntryAvailable: boolean;
|
|
156
159
|
/**
|
|
@@ -158,9 +161,15 @@ export interface UsageBillingInjected {
|
|
|
158
161
|
* 返回 'opened' 已跳转 / 'unavailable' 宿主无通道(老到没有)/ 'failed' 通道报错。
|
|
159
162
|
*/
|
|
160
163
|
navigateToSession: (sessionId: string) => 'opened' | 'unavailable' | 'failed';
|
|
164
|
+
/**
|
|
165
|
+
* 会话标题(issue #118):队列卡片显示「将在会话 X 继续」时用。取不到时返回
|
|
166
|
+
* undefined,界面退化为会话 id 短码——不编造标题。
|
|
167
|
+
*/
|
|
168
|
+
sessionTitleOf: (sessionId: string) => string | undefined;
|
|
161
169
|
}
|
|
162
170
|
/** Usage stats structure from `.dsh-usage-stats.json`. */
|
|
163
171
|
export interface UsageStats {
|
|
172
|
+
peakSchedule?: import('../../peak-schedule.ts').PeakSchedule;
|
|
164
173
|
/** 服务端聚合时间戳(毫秒);旧快照可能缺失。 */
|
|
165
174
|
updatedAt?: number;
|
|
166
175
|
/**
|
|
@@ -169,6 +178,11 @@ export interface UsageStats {
|
|
|
169
178
|
* 避免把旧值(如重命名前的会话标题)当成最新值读。
|
|
170
179
|
*/
|
|
171
180
|
staleSnapshot?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* 会话列表整体读不到时的降级原因(issue #119):本档数字全部出自持久账本
|
|
183
|
+
* (可能是空)。面板据此显示「读取失败」,而不是把空账本当成「没有用量」。
|
|
184
|
+
*/
|
|
185
|
+
sessionListError?: string;
|
|
172
186
|
/** 宿主进程时区(IANA 名 + UTC 偏移):天按此切分,副标题据此标注;旧快照可能缺失。 */
|
|
173
187
|
timezone?: {
|
|
174
188
|
name: string;
|
|
@@ -180,6 +194,12 @@ export interface UsageStats {
|
|
|
180
194
|
lowBalanceThreshold?: number;
|
|
181
195
|
/** 会话明细(按费用倒序,服务端已封顶);旧快照可能缺失。 */
|
|
182
196
|
bySession?: readonly SessionBillingRow[];
|
|
197
|
+
/**
|
|
198
|
+
* 会话总数(未封顶):`bySession` 只带花费前 N 行,真实总数此前从未下发——
|
|
199
|
+
* 会话数超过封顶时面板只能说「共 100 个会话」,是错的。缺省回退按明细行数
|
|
200
|
+
* (旧快照没有该字段)。
|
|
201
|
+
*/
|
|
202
|
+
bySessionTotal?: number;
|
|
183
203
|
total: {
|
|
184
204
|
calls: number;
|
|
185
205
|
input: number;
|
|
@@ -200,6 +220,8 @@ export interface UsageStats {
|
|
|
200
220
|
output: number;
|
|
201
221
|
cacheHit: number;
|
|
202
222
|
cacheMiss: number;
|
|
223
|
+
/** 显式缓存写入(cacheMiss 子集,部分厂商单独报告);issue #123 起按其单价计价。 */
|
|
224
|
+
cacheWrite?: number;
|
|
203
225
|
cost: number;
|
|
204
226
|
reasoning: number;
|
|
205
227
|
/** Billed through a subscription plan (no per-token cost). */
|
|
@@ -215,6 +237,8 @@ export interface UsageStats {
|
|
|
215
237
|
output: number;
|
|
216
238
|
cacheHit: number;
|
|
217
239
|
cacheMiss: number;
|
|
240
|
+
/** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
|
|
241
|
+
cacheWrite?: number;
|
|
218
242
|
cost: number;
|
|
219
243
|
reasoning: number;
|
|
220
244
|
}>;
|
|
@@ -225,6 +249,8 @@ export interface UsageStats {
|
|
|
225
249
|
output: number;
|
|
226
250
|
cacheHit: number;
|
|
227
251
|
cacheMiss: number;
|
|
252
|
+
/** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
|
|
253
|
+
cacheWrite?: number;
|
|
228
254
|
cost: number;
|
|
229
255
|
}>>;
|
|
230
256
|
/** 模型 × 日期 × 站点 三维统计([date][modelKey][siteKey]):按 origin 绑定自定义价的
|
|
@@ -235,9 +261,13 @@ export interface UsageStats {
|
|
|
235
261
|
output: number;
|
|
236
262
|
cacheHit: number;
|
|
237
263
|
cacheMiss: number;
|
|
264
|
+
/** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
|
|
265
|
+
cacheWrite?: number;
|
|
238
266
|
cost: number;
|
|
239
267
|
/** 该格全部调用都走订阅通道(聚合侧按三维格置位);旧快照缺失,回退全局口径。 */
|
|
240
268
|
plan?: boolean;
|
|
269
|
+
/** 混合格中可确认的订阅调用次数(费用仅来自非订阅调用)。 */
|
|
270
|
+
planCalls?: number;
|
|
241
271
|
}>>>;
|
|
242
272
|
/**
|
|
243
273
|
* 峰谷分桶(全量逐调用真实判档):1.0.8 起服务端按调用时刻精确归桶,
|
|
@@ -260,6 +290,8 @@ export interface UsageStats {
|
|
|
260
290
|
sessionId: string;
|
|
261
291
|
turn: number;
|
|
262
292
|
model: string;
|
|
293
|
+
scheduleSource?: string;
|
|
294
|
+
scheduleTier?: 'peak' | 'offPeak';
|
|
263
295
|
input: number;
|
|
264
296
|
output: number;
|
|
265
297
|
cacheHit: number;
|
|
@@ -289,6 +321,10 @@ export interface UsageStats {
|
|
|
289
321
|
}>;
|
|
290
322
|
/** 不可计价模型 id(未收录/无价,费用按 0 计);旧快照可能缺失。 */
|
|
291
323
|
unpricedModels?: readonly string[];
|
|
324
|
+
/** Client-only catalog estimate for usage not covered by a user price. */
|
|
325
|
+
estimatedUnpricedTotal?: number;
|
|
326
|
+
/** Display-only: models with usage estimated from a sole, unverified source price. */
|
|
327
|
+
sourceEstimatedModels?: readonly string[];
|
|
292
328
|
/** 联网搜索请求的单次费用估算(人民币元,配置回显);0 或缺省 = 未启用估算。 */
|
|
293
329
|
searchCallEstimateCny?: number;
|
|
294
330
|
/** 按角色费用归因(估算口径:输出实测,输入按消息长度摊分);旧快照可能缺失。 */
|