@kenz1117/dsh-ui-usage-billing 1.8.2 → 1.8.3-alpha.10

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.
@@ -365,6 +365,12 @@ export interface UsageStatsDocument {
365
365
  * (issue #103 加的 staleSnapshot 通道,此前无生产方),零新增客户端体积。
366
366
  */
367
367
  staleSnapshot?: boolean;
368
+ /**
369
+ * 会话列表整体读不到时的降级原因(issue #119):目录里有读不了/对不上的
370
+ * 日志、宿主后端临时故障等。此时本档数字全部出自持久账本(可能是空),
371
+ * 客户端据此显示「读取失败」,而不是把空账本当成「没有用量」。
372
+ */
373
+ sessionListError?: string;
368
374
  }
369
375
  /** 按角色费用归因:user / tool 为输入成本的启发式摊分,assistant 为输出成本实测。 */
370
376
  export interface RoleCost {
@@ -691,7 +697,7 @@ export declare function mergeUsageLedgerDocuments(document: UsageLedgerDocument,
691
697
  * 会话费用只剩最近一段,issue #29)。
692
698
  * 持久账本行据此区分新旧算法:日志已删/不可读而只能沿用旧行时,UI 标注置信度提示。
693
699
  */
694
- export declare const FOLD_VERSION = 23;
700
+ export declare const FOLD_VERSION = 24;
695
701
  /** 账本里拒读记录的条数上限:防异常环境(大量损坏日志)把账本撑爆;
696
702
  * 超限按 Map 插入序保留前 N 条(最早发现的先留,stamp 失效的自然被清理让位)。 */
697
703
  export declare const LEDGER_REFUSED_CAP = 500;
@@ -801,6 +807,17 @@ export interface SessionUsageSummary {
801
807
  * 判定函数无法序列化,统一记为 `fn`(任何函数形态互视为同一指纹)。
802
808
  */
803
809
  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;
810
+ /**
811
+ * 会话列表整体读不到(issue #119):宿主持久化后端整体故障,或会话目录里有
812
+ * 读不了/对不上的日志。聚合无法枚举会话,只能降级到持久账本或磁盘快照——
813
+ * 但「降级」必须让用户看得见,否则新装用户看到的是一片 ¥0(分不清没花钱
814
+ * 还是没读到)。携带原因随文档下发,客户端据此显示「读取失败」。
815
+ */
816
+ export declare class SessionListUnavailableError extends Error {
817
+ /** 失败原因摘要(面向用户的中文/英文提示语,由调用方决定措辞)。 */
818
+ readonly reason: string;
819
+ constructor(reason: string, cause?: unknown);
820
+ }
804
821
  /**
805
822
  * Create the incremental usage aggregator.
806
823
  * @param persistence - the session persistence service.
@@ -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
@@ -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 {};
@@ -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
- /** Try to load stats from the server; returns null when no valid JSON stats are served. */
10
- export declare function loadUsageStats(): Promise<UsageStats | null>;
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
@@ -158,6 +158,11 @@ export interface UsageBillingInjected {
158
158
  * 返回 'opened' 已跳转 / 'unavailable' 宿主无通道(老到没有)/ 'failed' 通道报错。
159
159
  */
160
160
  navigateToSession: (sessionId: string) => 'opened' | 'unavailable' | 'failed';
161
+ /**
162
+ * 会话标题(issue #118):队列卡片显示「将在会话 X 继续」时用。取不到时返回
163
+ * undefined,界面退化为会话 id 短码——不编造标题。
164
+ */
165
+ sessionTitleOf: (sessionId: string) => string | undefined;
161
166
  }
162
167
  /** Usage stats structure from `.dsh-usage-stats.json`. */
163
168
  export interface UsageStats {
@@ -169,6 +174,11 @@ export interface UsageStats {
169
174
  * 避免把旧值(如重命名前的会话标题)当成最新值读。
170
175
  */
171
176
  staleSnapshot?: boolean;
177
+ /**
178
+ * 会话列表整体读不到时的降级原因(issue #119):本档数字全部出自持久账本
179
+ * (可能是空)。面板据此显示「读取失败」,而不是把空账本当成「没有用量」。
180
+ */
181
+ sessionListError?: string;
172
182
  /** 宿主进程时区(IANA 名 + UTC 偏移):天按此切分,副标题据此标注;旧快照可能缺失。 */
173
183
  timezone?: {
174
184
  name: string;
@@ -200,6 +210,8 @@ export interface UsageStats {
200
210
  output: number;
201
211
  cacheHit: number;
202
212
  cacheMiss: number;
213
+ /** 显式缓存写入(cacheMiss 子集,部分厂商单独报告);issue #123 起按其单价计价。 */
214
+ cacheWrite?: number;
203
215
  cost: number;
204
216
  reasoning: number;
205
217
  /** Billed through a subscription plan (no per-token cost). */
@@ -215,6 +227,8 @@ export interface UsageStats {
215
227
  output: number;
216
228
  cacheHit: number;
217
229
  cacheMiss: number;
230
+ /** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
231
+ cacheWrite?: number;
218
232
  cost: number;
219
233
  reasoning: number;
220
234
  }>;
@@ -225,6 +239,8 @@ export interface UsageStats {
225
239
  output: number;
226
240
  cacheHit: number;
227
241
  cacheMiss: number;
242
+ /** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
243
+ cacheWrite?: number;
228
244
  cost: number;
229
245
  }>>;
230
246
  /** 模型 × 日期 × 站点 三维统计([date][modelKey][siteKey]):按 origin 绑定自定义价的
@@ -235,6 +251,8 @@ export interface UsageStats {
235
251
  output: number;
236
252
  cacheHit: number;
237
253
  cacheMiss: number;
254
+ /** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
255
+ cacheWrite?: number;
238
256
  cost: number;
239
257
  /** 该格全部调用都走订阅通道(聚合侧按三维格置位);旧快照缺失,回退全局口径。 */
240
258
  plan?: boolean;
@@ -1,5 +1,5 @@
1
1
  /** Locale dictionaries for the usage billing surface. */
2
- export type UsageBillingKey = 'title' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'monthProjectedHint' | 'liveTurn' | 'liveSession' | 'liveSessionSub' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'kpiRange' | 'avgRangeToday' | 'avgRange7d' | 'avgRangeWeek' | 'avgRangeMonth' | 'avgRangeAll' | 'avgRangeCustom' | 'customRangeStart' | 'customRangeEnd' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'pricingSearch' | 'bandPinHint' | 'trendEmpty' | 'trendTotal' | 'roundsUnit' | 'healthModelsLive' | 'healthVendorsDown' | 'healthVendorsUnavailable' | 'budget' | 'budgetRemain' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'channelUnknown' | 'directTag' | 'relayTag' | 'unknownTag' | 'unknownChannelHint' | 'planCountUnit' | 'actual' | 'pricing' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'band' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'pricingSyncedAt' | 'pricingSyncNow' | 'pricingSyncing' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'recharge' | 'rechargeHint' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatPrimaryToday' | 'floatPrimaryWeek' | 'floatPrimaryMonth' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMode' | 'cardModeFull' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'cardSpan' | 'cardSpanDay' | 'cardSpanWeek' | 'cardSpanMonth' | 'cardDeltaBadge' | 'cardDeltaShow' | 'cardDeltaHide' | 'triggerMonthTokens' | 'triggerTodayTokens' | 'triggerWeekTokens' | 'subscriptionsStale' | 'balanceStaleNotice' | 'staleLedgerNotice' | 'staleSnapshotNotice' | 'unreadableNotice' | 'unreadableFormatNotice' | 'unreadableNoLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceOffPeak' | 'userPriceNormal' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemoveSelected' | 'userPriceSelect' | 'sessionStaleBadge' | 'sessionUntitled' | 'sessionSubCost' | 'sessionSubCalls' | 'sessionSubRow' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'currencyEur' | 'language' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabPricing' | 'tabSettings' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'peakAlertDescPeakZhipu' | 'peakAlertDescOffZhipu' | 'peakAlertQueuePeak' | 'peakAlertQueueOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'tierAlertEnterPeakZhipu' | 'tierAlertEnterOffZhipu' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionTag' | 'cellEstimateHint' | 'free' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'perfAll' | 'perfChartEmpty' | 'heatmapYear' | 'heatmapHalf' | 'heatmapMonth' | 'metricCost' | 'metricTokens' | 'heatmapTotal' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'densityLabel' | 'densityHint' | 'densityCompact' | 'densityDefault' | 'densityComfortable' | 'motionLabel' | 'motionHint' | 'motionOff' | 'motionSubtle' | 'motionRich' | 'settingsNavDisplayPref' | 'settingsNavBudget' | 'settingsNavAlert' | 'settingsNavDisplay' | 'settingsNavAdvanced' | 'settingsNavAbout' | 'settingsSearchPlaceholder' | 'settingsSearchEmpty' | 'sessionsViewAll' | 'sessionViewerSearch' | 'modelBudgetTitle' | 'modelBudgetHint' | 'modelBudgetBody' | 'modelBudgetPlaceholder' | 'moreWorksTitle' | 'adEngramName' | 'adEngramDesc' | 'adRainbowName' | 'adRainbowDesc' | 'kpiDescCacheHit' | 'kpiDescTokens' | 'kpiDescAvgCost' | 'kpiDescCalls' | 'kpiDescReasoning' | 'kpiDescIo' | 'kpiDescPeak' | 'healthDotLive' | 'healthDotFailed' | 'healthDotUnknown' | 'settingsSectionDisplay' | 'emptyHint' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenViewStructure' | 'tokenViewModel' | 'tokenHitShort' | 'tokenMissShort' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'unpricedHint' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'liveCostBar' | 'liveCostBarHint' | 'liveCostBarPosition' | 'liveCostBarPosBelow' | 'liveCostBarPosAbove' | 'liveCostBarPosToolbar' | 'exportCsvSite' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'expandAll' | 'collapseAll' | 'todayOnly' | 'todayNoConsumption' | 'commandUsageLabel' | 'commandUsageDescription' | 'sessionOpen' | 'sessionOpenFailed' | 'sessionOpenUnavailable' | 'tabAgents' | 'tabQueue' | 'queueSubtitle' | 'queueUntilPeak' | 'queueUntilOffPeak' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queuePromptLabel' | 'queuePromptPlaceholder' | 'queuePrivacy' | 'queueEnqueue' | 'queueImport' | 'queueImportHint' | 'queueImported' | 'queueImportFormat' | 'queueImportTooLarge' | 'queueActive' | 'queueClearFinished' | 'queueEmpty' | 'queueLoading' | 'queueOpenSession' | 'queueRemoveQueued' | 'queueRemoveHistory' | 'queueStatusQueued' | 'queueStatusStarting' | 'queueStatusRunning' | 'queueStatusCompleted' | 'queueStatusFailed' | 'quickQueueToggle' | 'quickQueueEntry' | 'quickQueueEntryHint' | 'quickQueueEnqueue' | 'quickQueueEnqueueing' | 'quickQueueWaiting' | 'quickQueueClear' | 'quickQueueEnqueued' | 'quickQueueEmpty' | 'quickQueueBusy' | 'quickQueueAttachments' | 'quickQueueContext' | 'quickQueueRoute' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
2
+ export type UsageBillingKey = 'title' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'monthProjectedHint' | 'liveTurn' | 'liveSession' | 'liveSessionSub' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'kpiRange' | 'avgRangeToday' | 'avgRange7d' | 'avgRangeWeek' | 'avgRangeMonth' | 'avgRangeAll' | 'avgRangeCustom' | 'customRangeStart' | 'customRangeEnd' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'pricingSearch' | 'bandPinHint' | 'trendEmpty' | 'trendTotal' | 'roundsUnit' | 'healthModelsLive' | 'healthVendorsDown' | 'healthVendorsUnavailable' | 'budget' | 'budgetRemain' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'channelUnknown' | 'directTag' | 'relayTag' | 'unknownTag' | 'unknownChannelHint' | 'planCountUnit' | 'actual' | 'pricing' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'band' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'pricingSyncedAt' | 'pricingSyncNow' | 'pricingSyncing' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'recharge' | 'rechargeHint' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatPrimaryToday' | 'floatPrimaryWeek' | 'floatPrimaryMonth' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMode' | 'cardModeFull' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'cardSpan' | 'cardSpanDay' | 'cardSpanWeek' | 'cardSpanMonth' | 'cardDeltaBadge' | 'cardDeltaShow' | 'cardDeltaHide' | 'triggerMonthTokens' | 'triggerTodayTokens' | 'triggerWeekTokens' | 'subscriptionsStale' | 'balanceStaleNotice' | 'staleLedgerNotice' | 'staleSnapshotNotice' | 'statsLoadFailed' | 'unreadableNotice' | 'unreadableFormatNotice' | 'unreadableNoLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceOffPeak' | 'userPriceNormal' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemoveSelected' | 'userPriceSelect' | 'sessionStaleBadge' | 'sessionUntitled' | 'sessionSubCost' | 'sessionSubCalls' | 'sessionSubRow' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'currencyEur' | 'language' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabPricing' | 'tabSettings' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'peakAlertDescPeakZhipu' | 'peakAlertDescOffZhipu' | 'peakAlertQueuePeak' | 'peakAlertQueueOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'tierAlertEnterPeakZhipu' | 'tierAlertEnterOffZhipu' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionTag' | 'cellEstimateHint' | 'free' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'perfAll' | 'perfChartEmpty' | 'heatmapYear' | 'heatmapHalf' | 'heatmapMonth' | 'metricCost' | 'metricTokens' | 'heatmapTotal' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'densityLabel' | 'densityHint' | 'densityCompact' | 'densityDefault' | 'densityComfortable' | 'motionLabel' | 'motionHint' | 'motionOff' | 'motionSubtle' | 'motionRich' | 'settingsNavDisplayPref' | 'settingsNavBudget' | 'settingsNavAlert' | 'settingsNavDisplay' | 'settingsNavAdvanced' | 'settingsNavAbout' | 'settingsSearchPlaceholder' | 'settingsSearchEmpty' | 'sessionsViewAll' | 'sessionViewerSearch' | 'modelBudgetTitle' | 'modelBudgetHint' | 'modelBudgetBody' | 'modelBudgetPlaceholder' | 'moreWorksTitle' | 'adEngramName' | 'adEngramDesc' | 'adRainbowName' | 'adRainbowDesc' | 'kpiDescCacheHit' | 'kpiDescTokens' | 'kpiDescAvgCost' | 'kpiDescCalls' | 'kpiDescReasoning' | 'kpiDescIo' | 'kpiDescPeak' | 'healthDotLive' | 'healthDotFailed' | 'healthDotUnknown' | 'settingsSectionDisplay' | 'emptyHint' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenViewStructure' | 'tokenViewModel' | 'tokenHitShort' | 'tokenMissShort' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'unpricedHint' | 'channelVisibility' | 'channelVisibilityHint' | 'channelVisibilityShowAll' | 'channelVisibilityHidden' | 'channelVisibilityEmpty' | 'unpricedMore' | 'unpricedFix' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'liveCostBar' | 'liveCostBarHint' | 'liveCostBarPosition' | 'liveCostBarPosBelow' | 'liveCostBarPosAbove' | 'liveCostBarPosToolbar' | 'exportCsvSite' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'expandAll' | 'collapseAll' | 'todayOnly' | 'todayNoConsumption' | 'commandUsageLabel' | 'commandUsageDescription' | 'sessionOpen' | 'sessionOpenFailed' | 'sessionOpenUnavailable' | 'tabAgents' | 'tabQueue' | 'queueSubtitle' | 'queueUntilPeak' | 'queueUntilOffPeak' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueSafetyIsolated' | 'queueSafetyReuse' | 'queueReusePlanned' | 'queueReuseDone' | 'queueFallbackReason' | 'queueReuseModelNote' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queuePromptLabel' | 'queuePromptPlaceholder' | 'queuePrivacy' | 'queueEnqueue' | 'queueImport' | 'queueImportHint' | 'queueImported' | 'queueImportFormat' | 'queueImportTooLarge' | 'queueActive' | 'queueClearFinished' | 'queueEmpty' | 'queueLoading' | 'queueOpenSession' | 'queueRemoveQueued' | 'queueRemoveHistory' | 'queueStatusQueued' | 'queueStatusStarting' | 'queueStatusRunning' | 'queueStatusCompleted' | 'queueStatusFailed' | 'quickQueueToggle' | 'quickQueueEntry' | 'quickQueueEntryHint' | 'quickQueueReuseEntry' | 'quickQueueReuseEntryHint' | 'quickQueueEnqueue' | 'quickQueueEnqueueing' | 'quickQueueWaiting' | 'quickQueueClear' | 'quickQueueEnqueued' | 'quickQueueEmpty' | 'quickQueueBusy' | 'quickQueueAttachments' | 'quickQueueContext' | 'quickQueueRoute' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
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>;
@@ -252,6 +252,12 @@ export interface TokenUsageBuckets {
252
252
  cacheHit: number;
253
253
  /** Cache-miss input tokens (already included in `input` by some providers). */
254
254
  cacheMiss: number;
255
+ /**
256
+ * 显式缓存写入 token(issue #123):**已包含在 `cacheMiss` 内**的子集——
257
+ * 厂商对「写入缓存」单独计价时(OpenAI/Anthropic 恒为输入价 125%),
258
+ * 这部分按缓存写入价计,不再按普通输入价。
259
+ */
260
+ cacheWrite?: number;
255
261
  /** Output tokens. */
256
262
  output: number;
257
263
  }
@@ -263,6 +269,13 @@ export interface PriceBand {
263
269
  cacheHit: number;
264
270
  /** Cache-miss input price per 1M tokens (absent when folded into `input`). */
265
271
  cacheMiss?: number;
272
+ /**
273
+ * 缓存写入单价(每百万 token,issue #123):厂商对「把内容写入缓存」单独
274
+ * 计价时给出(models.dev 原生 `cache_write`:OpenAI/Anthropic 恒为输入价
275
+ * 125%)。**缺省 = 按 `input` 价计**——厂商不单列缓存写入费时(如 DeepSeek、
276
+ * 月之暗面)缓存写入本就按输入价出账,与旧口径一致。
277
+ */
278
+ cacheWrite?: number;
266
279
  /** Output price per 1M tokens. */
267
280
  output: number;
268
281
  }
@@ -280,12 +293,20 @@ export interface ModelPrice extends PriceBand {
280
293
  export interface PricePromo {
281
294
  /** 折扣系数(0.5 = 五折,0 = 活动期免费);仅 [0,1) 区间有效,非法值视为无促销。 */
282
295
  factor: number;
296
+ /**
297
+ * 生效起始时刻(epoch ms):该时刻起才按折扣计价。缺省表示自模型上线起
298
+ * 持续生效(多数厂商的「限时折扣」只公布截止日)。给出起点时,早于该
299
+ * 时刻的历史事件按刊例价计——与「按事件发生时刻适用当时的官方规则」
300
+ * 同一口径(如 Hy4 正式版:2026-11-03 上线,官方价目页同日挂出 5 折说明,
301
+ * 上线前不存在的流量不受折扣影响)。
302
+ */
303
+ startsAtMs?: number;
283
304
  /**
284
305
  * 分档折扣覆盖:厂商对不同档位给不同折扣时逐档指定(如 GPT-5.6 Sol 促销为
285
306
  * 缓存 0.8 / 输入 0.8 / 输出 2/3)。缺省档位沿用 {@link factor};单档取值
286
307
  * 仅 [0,1) 区间有效(0 = 该档活动期免费),非法值回落 factor。
287
308
  */
288
- factors?: Partial<Record<'input' | 'cacheHit' | 'cacheMiss' | 'output', number>>;
309
+ factors?: Partial<Record<'input' | 'cacheHit' | 'cacheMiss' | 'cacheWrite' | 'output', number>>;
289
310
  /**
290
311
  * 截止时刻(epoch ms):该时刻及之后恢复刊例价。缺省表示厂商未公布截止日
291
312
  * 的长期活动(如「限时 5 折直至另行通知」),持续生效直至收到公告后补填。
@@ -383,7 +404,8 @@ export declare function modelOf(key: string): ModelEntry;
383
404
  export declare function isPriced(key: string): boolean;
384
405
  /**
385
406
  * 促销在 nowMs 是否生效:factor 必须落在 [0,1) 区间(0 = 活动期免费,issue #86),
386
- * 截止时刻及之后视为过期;endsAtMs 缺省表示长期活动,在 factor 合法期间持续生效。
407
+ * 截止时刻及之后视为过期;endsAtMs 缺省表示长期活动,在 factor 合法期间持续生效;
408
+ * startsAtMs 给出时,该时刻之前尚未开始(按刊例价计,不套折扣)。
387
409
  * 导出供测试:纯函数。
388
410
  * @param promo - 待判定的促销窗口。
389
411
  * @param nowMs - 判定时刻(epoch ms)。
@@ -109,6 +109,25 @@ export declare const SITE_LIST_STORAGE_KEY = "dsh.ui-usage-billing.sites";
109
109
  export declare function loadSiteListPrefs(): SiteListPrefs;
110
110
  /** 写入站点列表偏好。失败静默(展示偏好非关键)。 */
111
111
  export declare function saveSiteListPrefs(prefs: SiteListPrefs): void;
112
+ /**
113
+ * 通道可见性偏好(issue #126 需求):隐藏部分提供商 / 通道。
114
+ * 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema)。
115
+ *
116
+ * 存**通道桶 key**(`site:<origin>` / `direct:<provider>` / `unknown`)而不是
117
+ * 显示名——显示名随界面语言变(中英),桶 key 稳定,偏好能跨语言沿用。
118
+ */
119
+ export interface ChannelVisibilityPrefs {
120
+ /** 隐藏的通道桶 key 列表;空 = 全部显示。 */
121
+ hidden: readonly string[];
122
+ }
123
+ /** 默认通道可见性偏好:全部显示(保持历史行为)。 */
124
+ export declare const DEFAULT_CHANNEL_VISIBILITY_PREFS: ChannelVisibilityPrefs;
125
+ /** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
126
+ export declare const CHANNEL_VISIBILITY_STORAGE_KEY = "dsh.ui-usage-billing.channels";
127
+ /** 读取通道可见性偏好(含损坏/缺失回退到默认)。仅在浏览器半区调用。 */
128
+ export declare function loadChannelVisibilityPrefs(): ChannelVisibilityPrefs;
129
+ /** 写入通道可见性偏好。失败静默(展示偏好非关键)。 */
130
+ export declare function saveChannelVisibilityPrefs(prefs: ChannelVisibilityPrefs): void;
112
131
  /**
113
132
  * 即时代费条(平价消耗胶囊,composer dock 的 LiveCostBar)的显示偏好。
114
133
  * 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema);
@@ -234,8 +253,9 @@ export declare function loadPerfViewPrefs(): PerfViewPrefs;
234
253
  export declare function savePerfViewPrefs(prefs: PerfViewPrefs): void;
235
254
  /**
236
255
  * 显示密度档位(v1.5 新增)。紧凑档减小行高/字号/内边距,舒适档加大;
237
- * 默认档保持历史感官。client 端写到 `documentElement.dataset.density`,
238
- * CSS `[data-density="..."]` 选择器派生 `--ds-density-*` 变量。
256
+ * 默认档保持历史感官。client 端写到 `documentElement.dataset.dshBillingDensity`
257
+ * (= `data-dsh-billing-density`,命名空间化防同名属性互相覆盖,issue #124),
258
+ * CSS `[data-dsh-billing-density="..."]` 选择器派生 `--ds-density-*` 变量。
239
259
  */
240
260
  export type DensityPref = 'compact' | 'default' | 'comfortable';
241
261
  /** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
@@ -250,9 +270,11 @@ export declare function loadDensity(): DensityPref;
250
270
  * 失败静默(展示偏好非关键)。 */
251
271
  export declare function saveDensity(density: DensityPref): void;
252
272
  /**
253
- * 动效强度档位(v1.5 新增)。`off` 冻结全部 transition+animation,
254
- * `subtle` 抑制 240ms 以上的入场/计数动画但保留 160ms 微交互,
255
- * `rich` 即默认(全开)。写到 `documentElement.dataset.motion`。
273
+ * 动效强度档位(v1.5 新增)。`off` 冻结本插件内的全部 transition+animation,
274
+ * `subtle` 保留 transition 微交互、把关键帧动画压成瞬时,`rich` 即默认(全开)。
275
+ * 写到 `documentElement.dataset.dshBillingMotion`(= `data-dsh-billing-motion`),
276
+ * 且压制规则只作用在本插件根容器 `.dsh-billing-root` 之内(issue #124:
277
+ * 此前通用属性 + 通配符会把宿主与第三方插件的动画一起压平)。
256
278
  */
257
279
  export type MotionPref = 'off' | 'subtle' | 'rich';
258
280
  /** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
@@ -279,6 +301,15 @@ export interface QuickQueuePrefs {
279
301
  * touched the setting.
280
302
  */
281
303
  showEntry: boolean;
304
+ /**
305
+ * Run a queued task inside the Session it was queued from (issue #118).
306
+ *
307
+ * Off keeps every task in its own Session. On prefers continuing in the
308
+ * source Session — same context, same workspace grouping — and falls back to
309
+ * a new Session when the source is gone, busy or archived. Default off: the
310
+ * isolated-Session design is the safe default.
311
+ */
312
+ reuseSourceSession: boolean;
282
313
  }
283
314
  export declare const DEFAULT_QUICK_QUEUE_PREFS: QuickQueuePrefs;
284
315
  export declare const QUICK_QUEUE_STORAGE_KEY = "dsh.ui-usage-billing.quick-queue";
@@ -12,6 +12,12 @@ export interface LivePrice {
12
12
  cacheHit: number;
13
13
  /** Output price per 1M tokens. */
14
14
  output: number;
15
+ /**
16
+ * 缓存写入单价(每百万 token,issue #123):厂商对「写入缓存」单独计价时给出
17
+ * (models.dev 原生 `cache_write`)。**缺省 = 按 `input` 价计**——上游未声明
18
+ * 时不猜(与 `cacheHit` 的声明优先口径一致)。
19
+ */
20
+ cacheWrite?: number;
15
21
  }
16
22
  /** Response of `/api/billing/pricing` consumed by the dashboard. */
17
23
  export interface LivePricing {
@@ -6,6 +6,10 @@ export interface TaskQueueInput {
6
6
  readonly cwd?: unknown;
7
7
  readonly provider?: unknown;
8
8
  readonly model?: unknown;
9
+ /** 来源会话(issue #118):入队时所在的会话,执行期据此续跑。 */
10
+ readonly sourceSessionId?: unknown;
11
+ /** 入队时是否授权复用来源会话(把设置开关的状态冻结进任务)。 */
12
+ readonly reuseSource?: unknown;
9
13
  }
10
14
  export interface TaskQueueTask {
11
15
  readonly id: string;
@@ -17,7 +21,14 @@ export interface TaskQueueTask {
17
21
  readonly createdAt: number;
18
22
  readonly startedAt?: number | undefined;
19
23
  readonly finishedAt?: number | undefined;
24
+ /** 实际执行任务的会话(复用来源会话时等于 sourceSessionId)。 */
20
25
  readonly sessionId?: string | undefined;
26
+ /** 来源会话 id(issue #118):入队时所在的会话。 */
27
+ readonly sourceSessionId?: string | undefined;
28
+ /** 是否授权在该来源会话内续跑(入队时冻结的开关状态)。 */
29
+ readonly reuseSource?: boolean | undefined;
30
+ /** 从「续跑来源会话」降级为「新建会话」的原因(卡片展示)。 */
31
+ readonly fallbackReason?: string | undefined;
21
32
  readonly error?: string | undefined;
22
33
  }
23
34
  export interface TaskQueueWorkspace {
@@ -9,11 +9,34 @@
9
9
  import type { SessionController } from '@deepseek-ai/dsh-api-session-controller';
10
10
  import type { TaskQueueInput, TaskQueueSnapshot, TaskQueueSummary, TaskQueueWorkspace } from './task-queue-shared.ts';
11
11
  export type TaskQueueController = Pick<SessionController, 'create' | 'selectModel' | 'prompt' | 'follow' | 'modelCatalog'>;
12
- type ControllerFace = TaskQueueController;
12
+ /**
13
+ * 会话列表读面(可选能力,issue #118):复用来源会话前用它校验该会话是否仍可用
14
+ * (存在 / 非子智能体 / 空闲 / 项目未变)。**缺席不降级整个队列**——只是复用
15
+ * 路径不可用,任务一律走新建会话。
16
+ */
17
+ export type TaskQueueSessionLister = Pick<SessionController, 'list'>;
18
+ /** 引擎看到的宿主会话控制面:基本 5 方法必备,list 可选。 */
19
+ export type TaskQueueControllerFace = TaskQueueController & Partial<TaskQueueSessionLister>;
20
+ /**
21
+ * 工作区上下文(可选能力):新建会话归组 + 来源会话归档判定。宿主没有这个服务
22
+ * 时一律降级(不归组、归档不可判),队列其余行为不变。
23
+ */
24
+ export interface TaskQueueWorkspaceContext {
25
+ /** 已归档的会话 id:归档会话的轮次会以 blocked 结束,不会真的跑。 */
26
+ readonly archivedSessionIds: readonly string[];
27
+ /**
28
+ * 路径 → 工作区 id。**必须严格相等**:宿主的成员资格规则是「account slot +
29
+ * canonical cwd 严格等于工作区 path」,前缀匹配不算数——本仓计费口径里的子目录
30
+ * 前缀匹配只用于账单归组,不能拿来给会话归组。
31
+ */
32
+ readonly workspaceIdOfPath: (path: string) => string | undefined;
33
+ }
13
34
  export interface TaskQueueEngineOptions {
14
35
  readonly filePath: string;
15
- readonly getController: () => ControllerFace | undefined;
36
+ readonly getController: () => TaskQueueControllerFace | undefined;
16
37
  readonly getWorkspaces: () => readonly TaskQueueWorkspace[];
38
+ /** 工作区上下文(可选):缺席 → 不归组、复用路径不可用。 */
39
+ readonly getWorkspaceContext?: () => TaskQueueWorkspaceContext | undefined;
17
40
  readonly now?: () => number;
18
41
  readonly createId?: () => string;
19
42
  readonly ownerId?: string;
@@ -50,6 +73,21 @@ export declare class TaskQueueEngine {
50
73
  private claimNext;
51
74
  private recoverExpired;
52
75
  private execute;
76
+ /**
77
+ * issue #118:判断来源会话能否续跑。不能就给出降级原因(写进卡片)。
78
+ *
79
+ * 判据来自 issue 的安全边界:来源会话已删除 / 正在跑别的轮次 / 工作区变了时,
80
+ * 回退为新建会话,不要往用户正在使用的会话里硬塞一轮。另外子智能体会话与
81
+ * 归档会话也不能复用——前者归属子智能体路由,后者轮次会以 blocked 结束、
82
+ * 看起来跑了其实没跑。
83
+ */
84
+ private resolveSourceSession;
85
+ /**
86
+ * 新建会话:cwd 恰好等于某个工作区时用 create({ workspaceId }),让宿主把会话挂进
87
+ * 该工作区——create({ cwd }) 从不归组,这正是队列会话在侧栏里没有分组的原因。
88
+ * 两者互斥:带 workspaceId 时不能再带 cwd。
89
+ */
90
+ private createGroupedSession;
53
91
  private watch;
54
92
  private renewLease;
55
93
  private requeue;
@@ -59,5 +97,4 @@ export declare class TaskQueueEngine {
59
97
  private readDocument;
60
98
  private readDocumentWithRaw;
61
99
  }
62
- export {};
63
100
  //# sourceMappingURL=task-queue.d.ts.map