@kenz1117/dsh-ui-usage-billing 1.8.13 → 1.8.15

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.
@@ -14,15 +14,22 @@
14
14
  * - 数同排的可见占位者(展开 display:contents 的子项,排除自己与不可见元素);
15
15
  * - 读行的 `flex-direction`(`column` = 纵向栈)。
16
16
  *
17
- * 判定(§25 方案 A:卡片型占用者有邻居时降级为按钮形态):
18
- * - 横向行且有邻居 → 收成 36×36 图标钮(此时禁止 `width:100%`);
19
- * - 纵向座位 → 只有「放不下宽卡」的窄座才收成图标钮;**整行宽座**(第三方
20
- * 皮肤显式给出的宽座,客人被拉满整行、宽卡放得下)保留宽卡(issue #140);
21
- * - 其余(独占一行 / 测不到行)→ 保持宽卡。
17
+ * 判定分四档(issue #148;前两档沿用社区约定 §25 方案 A):
18
+ * - `full`(用户显式选择):**无条件宽卡**,不做邻居 / 容量判断——用户的显式
19
+ * 意图优先于自动收窄;代价(同槽邻居被挤压)由触发卡悬停提示写明;
20
+ * - `compact`:无条件 36×36 图标钮;
21
+ * - `auto`(默认):按**座位容量**决定(社区约定 §20 的容量公式)——横向行用
22
+ * 「行宽 − 容器内边距 − 邻居占位」算出留给宽卡的空间,放得下出宽卡、放不下
23
+ * 收成图标钮;纵向座位仍按 §25.6:「整行宽座」保留宽卡,窄竖条收成图标钮
24
+ * (issue #140)。
25
+ *
26
+ * 宽度测不到时(未布局 / 座位不可见)**fail-closed 先收窄**,等 `ResizeObserver`
27
+ * 拿到真实尺寸再切回宽卡——宁可短暂多一个图标钮,也不要先把邻居挤出面板。
22
28
  *
23
29
  * 本模块只做测量与判定,不碰宿主容器(不得注入 `flex-wrap` /
24
30
  * `flex-direction` / `order`,见 §25 硬规则 2)。
25
31
  */
32
+ import type { BillingCardMode } from './usage-billing-settings.ts';
26
33
  /** 同槽占位事实。 */
27
34
  export interface FooterLaneFacts {
28
35
  /** 真正的行容器(最近的 flex 祖先);找不到时为 null(此时没有横向挤占问题)。 */
@@ -52,11 +59,45 @@ export interface FooterLaneWatch {
52
59
  */
53
60
  export declare function measureFooterLane(self: HTMLElement): FooterLaneFacts;
54
61
  /**
55
- * 由占位事实判定触发卡形态(社区约定 §25 方案 A)。
62
+ * 横向座位放不放得下宽卡(社区约定 §20 的容量公式)。
63
+ *
64
+ * `available = 行宽 − 容器内边距 − 邻居数 × (占位 112 + 间距 4)`,
65
+ * `available ≥ 141` 才放得下宽卡(卡面在 ≤140px 时只剩仪表图标)。
66
+ * 等价于「行宽 ≥ 157 + 邻居数 × 116」:0 邻居 → 157px、1 邻居 → 273px、
67
+ * 2 邻居 → 389px、3 邻居 → 505px。
68
+ *
69
+ * 宽度测不到(未布局 / 座位不可见)时 **fail-closed 返回 false**:宁可先收成
70
+ * 图标钮,也不要先把邻居挤出面板;`ResizeObserver` 拿到真实尺寸后会重算并切回。
71
+ * 刻意不用 `offsetParent` 判可见性——`position:fixed` 的行 `offsetParent` 为
72
+ * null,但它是**有**布局盒的(宽度可测),不该被误判成测不到。
73
+ *
74
+ * @param facts - 同槽占位事实。
75
+ * @returns 放得下宽卡返回 true。
76
+ */
77
+ export declare function fitsWideCard(facts: FooterLaneFacts): boolean;
78
+ /**
79
+ * 由占位事实 + 用户选择的形态档判定触发卡形态。
80
+ *
81
+ * - `full`:**无条件宽卡**——用户的显式意图优先于自动收窄(issue #148);
82
+ * 代价(同槽邻居被挤压)由调用方用 `facts.neighbors` 写进悬停提示;
83
+ * - `compact`:无条件图标钮;
84
+ * - `auto`(默认):按座位容量判断——横向行用 §20 容量公式,纵向座位沿用
85
+ * §25.6(「整行宽座」保留宽卡,窄竖条收成图标钮);
86
+ * - `hidden`:入口整体不渲染,形态判定无意义(调用方提前返回 null),这里按
87
+ * `auto` 处理。
88
+ *
56
89
  * @param facts - 同槽占位事实。
90
+ * @param mode - 侧栏入口形态档。
57
91
  * @returns `icon` = 收成 36×36 图标钮;`card` = 保持宽卡。
58
92
  */
59
- export declare function resolveTriggerForm(facts: FooterLaneFacts): TriggerForm;
93
+ export declare function resolveTriggerForm(facts: FooterLaneFacts, mode: BillingCardMode): TriggerForm;
94
+ /** 同槽占位状态:形态 + 邻居数(邻居数用于「强制宽卡挤压了几个」的提示)。 */
95
+ export interface FooterLaneState {
96
+ /** 触发卡形态(宽卡 / 图标钮)。 */
97
+ form: TriggerForm;
98
+ /** 同行可见占位者数量(不含自己)。 */
99
+ neighbors: number;
100
+ }
60
101
  /**
61
102
  * 观察同槽占位变化,形态变化时回调。
62
103
  *
@@ -65,8 +106,9 @@ export declare function resolveTriggerForm(facts: FooterLaneFacts): TriggerForm;
65
106
  * 只在**形态真的变了**时回调,避免自触发成环。
66
107
  *
67
108
  * @param self - 本插件在行内的元素。
68
- * @param onForm - 形态变化回调。
109
+ * @param mode - 侧栏入口形态档(`full` / `compact` 会在判定里直接短路)。
110
+ * @param onState - 形态 / 邻居数变化回调。
69
111
  * @returns 观察句柄。
70
112
  */
71
- export declare function watchFooterLane(self: HTMLElement, onForm: (form: TriggerForm) => void): FooterLaneWatch;
113
+ export declare function watchFooterLane(self: HTMLElement, mode: BillingCardMode, onState: (state: FooterLaneState) => void): FooterLaneWatch;
72
114
  //# sourceMappingURL=footer-lane.d.ts.map
@@ -1,6 +1,6 @@
1
1
  /** Locale dictionaries for the usage billing surface. */
2
2
  import { peakZh } from './peak-schedule-locales.ts';
3
- export type UsageBillingKey = keyof typeof peakZh | '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' | 'walletLogin' | 'walletPlatform' | 'walletInvalid' | 'walletNoService' | 'walletNoMetadata' | 'walletSignedOut' | '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' | 'shortcutOpenDashboard' | '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' | 'priceSaved' | 'userPriceEditIdentity' | 'pricePicker' | 'priceModelsPartial' | 'priceModelsPending' | 'priceModelDefault' | 'priceIncomplete' | 'priceUnpriced' | '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' | 'sessionsViewTop' | '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' | 'popBalanceUnavailable' | 'popQuotaUnavailable' | 'popSourceUnknown' | 'popPartialSource' | 'popMultipleSources' | 'popUnknownUnit' | 'popDirectLead' | 'popSubLead' | 'sourceEstimate' | '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' | 'queueNoWorkspace' | 'queueNoOfficialRoute' | 'queueNoOfficialModel' | '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' | 'quickQueueModelNotEligible' | 'quickQueueWorkspaceUnknown' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
3
+ export type UsageBillingKey = keyof typeof peakZh | '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' | 'walletLogin' | 'walletPlatform' | 'walletInvalid' | 'walletNoService' | 'walletNoMetadata' | 'walletSignedOut' | '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' | 'displayPlacement' | 'displayPlacementFooter' | 'displayPlacementLeft' | 'displayPlacementBoth' | 'displayPlacementHint' | 'displayPlacementFallback' | 'cardMode' | 'cardModeAuto' | 'cardModeAutoHint' | 'cardModeFull' | 'cardModeFullHint' | 'cardModeFullSqueezeHint' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'shortcutOpenDashboard' | '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' | 'priceSaved' | 'userPriceEditIdentity' | 'pricePicker' | 'priceModelsPartial' | 'priceModelsPending' | 'priceModelDefault' | 'priceIncomplete' | 'priceUnpriced' | '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' | 'sessionsViewTop' | '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' | 'popBalanceUnavailable' | 'popQuotaUnavailable' | 'popSourceUnknown' | 'popPartialSource' | 'popMultipleSources' | 'popUnknownUnit' | 'popDirectLead' | 'popSubLead' | 'sourceEstimate' | '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' | 'queueSavingCash' | 'queueSavingQuota' | 'queueSavingSchedule' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueSafetyIsolated' | 'queueSafetyReuse' | 'queueReusePlanned' | 'queueReuseDone' | 'queueFallbackReason' | 'queueReuseModelNote' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queueNoWorkspace' | 'queueNoOfficialRoute' | 'queueNoOfficialModel' | 'queueNoScheduledModel' | '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' | 'quickQueueModelNotEligible' | 'quickQueueWorkspaceUnknown' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
4
4
  export declare const NS = "usageBilling";
5
5
  export declare const zh: Record<UsageBillingKey, string>;
6
6
  export declare const en: Record<UsageBillingKey, string>;
@@ -0,0 +1,12 @@
1
+ /** 左侧主面板双槽位(main + sidebar.panellist)的运行时能力(issue #144)。 */
2
+ export interface BillingPanelCapability {
3
+ /** 两个宿主槽位是否同时可用。 */
4
+ available: () => boolean;
5
+ /** 订阅能力变化;组件挂载时另读 available() 取初值。 */
6
+ subscribe: (listener: () => void) => () => void;
7
+ setMain: (present: boolean) => void;
8
+ setNavigation: (present: boolean) => void;
9
+ }
10
+ /** 只有双槽位同时存在才允许隐藏底部入口,避免单侧能力造成不可恢复的空白。 */
11
+ export declare function createBillingPanelCapability(): BillingPanelCapability;
12
+ //# sourceMappingURL=panel-capability.d.ts.map
@@ -4,16 +4,31 @@
4
4
  * 面板(队列 Tab)与会话入队入口共用这一份判定与文案来源:只说「模型不
5
5
  * 支持」用户无从下手,必须分清「宿主没有官方通道」与「官方通道里没有可用
6
6
  * 模型」——两者的下一步动作完全不同(配 API Key 通道 vs 看模型清单)。
7
+ *
8
+ * 2026-12-04 扩展:订阅通道(其模型目录带峰谷倍率)也能进候选,于是根因多
9
+ * 了一种「有订阅通道但其模型没有峰谷价」——下一步是看该通道暴露了哪些模型,
10
+ * 与「配一条官方通道」不是同一件事。
7
11
  */
8
- import type { TaskQueueBlockedReason } from '../task-queue-shared.ts';
12
+ import type { TaskQueueBlockedReason, TaskQueueSaving } from '../task-queue-shared.ts';
9
13
  import type { UsageBillingKey } from './locales.ts';
14
+ /**
15
+ * 「省什么」的文案键(issue #143)。
16
+ *
17
+ * 三档对应插件**能核实**的通道性质:官方按量 / 中转站按量 → 省现金;已知
18
+ * 订阅套餐 → 省额度;其它来源 → 只声明按用户配置的时段排程,不猜省的是钱
19
+ * 还是额度。面板与队列文案共用这一份映射。
20
+ *
21
+ * @param saving - 候选模型的「省什么」属性。
22
+ * @returns 对应的文案键。
23
+ */
24
+ export declare function savingKey(saving: TaskQueueSaving): UsageBillingKey;
10
25
  /** 判定所需的最小事实面(面板快照与会话入队读到的都是它的子集)。 */
11
26
  export interface QueueEligibilityFacts {
12
27
  /** 宿主登记的工作区。 */
13
28
  readonly workspaces: readonly {
14
29
  readonly path: string;
15
30
  }[];
16
- /** 官方峰谷候选模型。 */
31
+ /** 峰谷候选模型。 */
17
32
  readonly models: readonly {
18
33
  readonly provider: string;
19
34
  readonly id: string;
@@ -41,18 +41,40 @@ export declare const FLOAT_WINDOW_STORAGE_KEY = "dsh.ui-usage-billing.float";
41
41
  export declare function loadFloatWindowPrefs(): FloatWindowPrefs;
42
42
  /** 写入浮窗偏好。失败静默(展示偏好非关键)。 */
43
43
  export declare function saveFloatWindowPrefs(prefs: FloatWindowPrefs): void;
44
+ /** 仪表盘入口的挂载位置:底部触发器 / 左侧主面板 / 两者同时显示(issue #144)。 */
45
+ export type BillingDisplayPlacement = 'footer' | 'left' | 'both';
46
+ /** 默认保持既有底部入口,升级后不改变用户界面。 */
47
+ export declare const DEFAULT_BILLING_DISPLAY_PLACEMENT: BillingDisplayPlacement;
48
+ export declare const BILLING_DISPLAY_PLACEMENT_STORAGE_KEY = "dsh.ui-usage-billing.display-placement";
49
+ export declare const BILLING_DISPLAY_PLACEMENT_EVENT = "dsh.ui-usage-billing.display-placement-changed";
50
+ /** 读取展示位置;缺失与非法值一律回退底部。 */
51
+ export declare function loadBillingDisplayPlacement(): BillingDisplayPlacement;
52
+ /** 写入并广播展示位置,apply 的槽位注册与各 React 树共用同一份偏好。 */
53
+ export declare function saveBillingDisplayPlacement(placement: BillingDisplayPlacement): void;
54
+ /** 同文档跨 React 树 + 跨标签页同步。 */
55
+ export declare function subscribeBillingDisplayPlacement(listener: () => void): () => void;
56
+ /** 宿主没有左侧双槽位时不得把唯一入口藏掉;设置里另行显示降级原因。 */
57
+ export declare function resolveBillingDisplayPlacement(placement: BillingDisplayPlacement, leftPanelAvailable: boolean): BillingDisplayPlacement;
44
58
  /** 左下角计费卡的主指标视角。 */
45
59
  export type BillingCardMetric = 'money' | 'tokens';
46
60
  /** 计费卡主数字的统计范围(单值卡面,issue #47 反馈)。 */
47
61
  export type BillingCardSpan = 'day' | 'week' | 'month';
48
- /** 侧栏入口显示模式:完整卡片 / 紧凑图标 / 完全隐藏(issue #108)。 */
49
- export type BillingCardMode = 'full' | 'compact' | 'hidden';
62
+ /**
63
+ * 侧栏入口显示模式(issue #108 / #148):
64
+ * - `auto`:按座位容量自动决定形态——放得下完整卡片就显示卡片,放不下收为图标钮(**默认**);
65
+ * - `full`:**无条件**显示完整卡片,不做邻居/容量判断(同槽邻居会被挤压,触发卡悬停提示写明挤了几个);
66
+ * - `compact`:36×36 图标钮;
67
+ * - `hidden`:不渲染(宿主没有恢复入口时降级为 `compact`)。
68
+ *
69
+ * `full` 是用户的显式意图,优先于「有邻居就收窄」的自动策略(issue #148)。
70
+ */
71
+ export type BillingCardMode = 'auto' | 'full' | 'compact' | 'hidden';
50
72
  /**
51
73
  * 计费卡显示偏好:侧栏入口模式 + 卡面主数字与迷你柱的计价视角 + 主数字统计范围。
52
74
  * 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema)。
53
75
  */
54
76
  export interface BillingCardPrefs {
55
- /** 侧栏入口模式(默认完整卡片;老偏好缺字段时保持原体验)。 */
77
+ /** 侧栏入口模式(默认 `auto`:按座位容量自动决定;老偏好缺字段时按自动处理)。 */
56
78
  mode: BillingCardMode;
57
79
  /** 主指标:花费金额(CNY/USD 按币种)/ Token 消耗。 */
58
80
  metric: BillingCardMetric;
@@ -61,7 +83,7 @@ export interface BillingCardPrefs {
61
83
  /** 是否显示「今日环比」涨跌徽章(默认显示;issue #93:部分用户觉得红色横条太醒目)。 */
62
84
  showDelta: boolean;
63
85
  }
64
- /** 默认计费卡偏好:完整卡片 + 花费金额 + 今日口径 + 显示环比徽章。 */
86
+ /** 默认计费卡偏好:自动形态 + 花费金额 + 今日口径 + 显示环比徽章。 */
65
87
  export declare const DEFAULT_BILLING_CARD_PREFS: BillingCardPrefs;
66
88
  /** localStorage key(与 budget store 的 `dsh.ui-usage-billing.*` 命名空间一致)。 */
67
89
  export declare const BILLING_CARD_STORAGE_KEY = "dsh.ui-usage-billing.card";
@@ -101,6 +101,18 @@ export interface UsageBillingConfig {
101
101
  * 如 `{ "hy4-preview": "hunyuan" }`)。聚合折叠与客户端渲染共用同一映射。
102
102
  */
103
103
  modelKeyAliases?: Record<string, string>;
104
+ /**
105
+ * 中转站额度探测的排除项(issue #152):命中的路由**完全不发探测请求**,
106
+ * 也不在「中转站额度」面板里占位。
107
+ *
108
+ * 用于自建网关——只实现 OpenAI 兼容接口、没有余额/额度端点,探测必然 404;
109
+ * 且识别失败不写指纹缓存(每轮都重新探测),污染网关日志与错误率告警。
110
+ *
111
+ * 每项可写**路由名**(如 `nas`)或 **origin**(如 `http://192.168.1.10:8080`),
112
+ * **精确匹配**、不支持通配或后缀(与 `trustedHosts` 同姿态)。缺省空 = 行为与
113
+ * 此前逐字一致。
114
+ */
115
+ relayQuotaExclusions?: string[];
104
116
  /**
105
117
  * 启动后延迟全量折叠的时长(毫秒,issue #105):聚合器创建起 `replayDelayMs`
106
118
  * 之内,`/api/billing/*` 只出账本轻文档(不读任何会话日志,面板以「数据滞后」
@@ -34,10 +34,20 @@ export declare function normalizeTrustedHosts(hosts: readonly string[] | undefin
34
34
  * 拒绝 `127.0.0.1.attacker.com` 这类以 `127.` 开头但解析到外部的 DNS rebinding 域名:
35
35
  * 只用 `startsWith('127.')` 会被它穿透,必须精确匹配回环 IP 的字面量。 */
36
36
  export declare function isLoopbackHost(req: IncomingMessage, trustedHosts?: ReadonlySet<string>): boolean;
37
- /** 校验 Origin 头是否回环(写操作用,防止跨站表单/fetch 改写设置)。Origin 缺失
37
+ /** 校验 Origin 头是否可信(写操作用,防止跨站表单/fetch 改写设置)。Origin 缺失
38
38
  * (curl 或同源 fetch 不带)视为放行,交给下方的 Content-Type 校验兜底;Origin 存在
39
- * 但主机非回环则拒绝——跨站脚本发起的写请求必带攻击者域名的 Origin。 */
40
- export declare function isLoopbackOrigin(origin: string | undefined): boolean;
39
+ * 但主机既非回环、也不在 trustedHosts 里则拒绝——跨站脚本发起的写请求必带攻击者
40
+ * 域名的 Origin。
41
+ *
42
+ * 反向代理场景:浏览器把页面自身的地址写进 Origin(`https://dash.example.com`)。
43
+ * Host 头因为同一域名被 trustedHosts 放行,Origin 却是同一个非回环域名——只认回环
44
+ * 字面量会让「已显式信任的主机」在写操作上必然 403(读操作正常),表现为面板能
45
+ * 打开、点任何保存/入队都报 `forbidden: loopback only`。因此 Origin 与 Host 共用
46
+ * 同一份 trustedHosts:用户显式信任某个主机,就等于接受该主机的同源写请求。
47
+ * @param origin - 原始 Origin 头(可能缺失)。
48
+ * @param trustedHosts - 已归一化的可信主机名集合,与 {@link isLoopbackHost} 同口径。
49
+ */
50
+ export declare function isLoopbackOrigin(origin: string | undefined, trustedHosts?: ReadonlySet<string>): boolean;
41
51
  /**
42
52
  * 路由准入声明(宿主 0.2.3-alpha.1 起必需)。
43
53
  *
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 中转站额度探测的**排除项**(issue #152)。
3
+ *
4
+ * 背景:报告者的自建网关只实现 OpenAI 兼容的 `/v1/chat/completions`、`/v1/models`,
5
+ * 没有余额/额度端点。插件的 `refreshRelay` 把「配了非官方 baseURL + 能解析到 key」
6
+ * 的路由一律当疑似中转站探测,两个端点必然 404;而**识别失败不写指纹缓存**
7
+ * (`fingerprintCache` 只在解析成功时写),于是每轮都重新探测——网关日志被稳定
8
+ * 污染(每 10 分钟两条 404),按 4xx 统计错误率的告警持续误报,面板上却完全
9
+ * 无感知。
10
+ *
11
+ * 熔断挡不住这个场景:`relayGate` 是 3 次失败冷却 60 秒,而轮询周期是 10 分钟,
12
+ * 冷却早已过期。
13
+ *
14
+ * 排除项是**纯增量**:未配置时行为与此前逐字一致(存量中转站用户不受影响)。
15
+ * 匹配语义刻意保守——**精确匹配**路由名或 origin,不支持通配/后缀:
16
+ * 排除错了会让用户以为额度还在,代价(漏看余额)比多探测一次更大。
17
+ */
18
+ /**
19
+ * 该路由是否被排除在额度探测之外。
20
+ *
21
+ * @param route - llm-pi-ai 路由名(如 `nas`)。
22
+ * @param baseURL - 该路由的端点地址。
23
+ * @param exclusions - 用户配置的排除项;每项可写路由名或 origin。
24
+ * @returns 命中排除项返回 true。
25
+ */
26
+ export declare function isRelayQuotaExcluded(route: string, baseURL: string, exclusions: readonly string[] | undefined): boolean;
27
+ /** 一条待探测路由的最小事实面。 */
28
+ export interface RelayQuotaCandidate {
29
+ /** llm-pi-ai 路由名。 */
30
+ readonly route: string;
31
+ /** 该路由的端点地址。 */
32
+ readonly baseURL: string;
33
+ }
34
+ /**
35
+ * 从 provider 路由表里挑出**可探测**的路由(issue #152)。
36
+ *
37
+ * 三道门,顺序固定:
38
+ * 1. 没有 `baseURL` → 不是中转站形态,跳过;
39
+ * 2. 官方厂商端点 → 卖的是官方按量余额而非中转站额度,跳过;
40
+ * 3. 用户显式排除 → 命中即跳过,**不发任何请求**。
41
+ *
42
+ * @param providers - llm-pi-ai 的 provider 路由表。
43
+ * @param isOfficial - 该 baseURL 是否指向官方厂商端点。
44
+ * @param exclusions - 用户配置的排除项。
45
+ * @returns 可探测的路由(保持配置里的顺序)。
46
+ */
47
+ export declare function selectRelayQuotaCandidates(providers: Readonly<Record<string, {
48
+ readonly baseURL?: string;
49
+ }>>, isOfficial: (baseURL: string) => boolean, exclusions: readonly string[] | undefined): readonly RelayQuotaCandidate[];
50
+ //# sourceMappingURL=relay-exclusion.d.ts.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * 低谷队列的**按来源判档**(issue #143)。
3
+ *
4
+ * 背景:报告者实测发现两件事——①订阅通道(如 `dsh-opencode-go`)确实有峰谷
5
+ * 倍率(其模型目录里 `deepseek-v4.1-flash` / `deepseek-v4-pro` 在 UTC 周一至
6
+ * 周五 01:00–04:00 / 06:00–10:00 时 `factor: 2`,其余为 1,即北京时间
7
+ * 09:00–12:00 / 14:00–18:00 倍率 2);②插件的「按模型配峰谷时段」已经能让
8
+ * 订阅通道的模型进入配置(`eligibleScheduleModel` 只要求目录里有 offPeak 价),
9
+ * 但低谷队列此前**硬过滤官方路由**且用全局 `tierAt` 判档——用户配了、计费认了、
10
+ * 队列不认。
11
+ *
12
+ * 本模块把「某个来源 × 某个模型此刻处于哪一档」收敛成一处判定,供队列的
13
+ * 候选筛选、启动闸门与展示共用(**同一件事不许两处各写一套**)。
14
+ *
15
+ * 两条纪律:
16
+ * 1. **来源桶与聚合层同源**——`site:` / `direct:` 的映射由调用方注入(用
17
+ * `siteRefOf` + `siteBucketKey`),本模块不自己猜,避免队列与计费对同一
18
+ * 条路由得出两个来源桶。
19
+ * 2. **窗口语义分列**——官方按量通道的谷档省**现金**,订阅通道的谷段省**套餐
20
+ * 额度**(倍率 2→1)。两者窗口数值可能相同,但省的东西不同;界面必须分开
21
+ * 表述,混说就是假声明。
22
+ */
23
+ import { type PeakRule, type PeakSchedule } from './peak-schedule.ts';
24
+ import { type PriceTierId } from './client/pricing.ts';
25
+ import type { TaskQueueSaving } from './task-queue-shared.ts';
26
+ /**
27
+ * 一条路由的通道属性。
28
+ *
29
+ * - `source`:来源桶键(`direct:<route>` / `site:<origin>`),与聚合层、峰谷
30
+ * 设置页同一套映射;
31
+ * - `saving`:该通道「省」什么——官方按量省现金,订阅通道省套餐额度。
32
+ */
33
+ export interface RouteChannel {
34
+ readonly source: string;
35
+ readonly saving: TaskQueueSaving;
36
+ }
37
+ /** 判档所需的最小事实面。 */
38
+ export interface BandFacts {
39
+ /** 该路由的来源桶与「省什么」。 */
40
+ readonly channel: RouteChannel | undefined;
41
+ /** 用户配置的模型级规则(按 `scheduleKey(source, model)` 查)。 */
42
+ readonly schedule: PeakSchedule | undefined;
43
+ /** 目录键(归一后的模型 key),与峰谷设置页存规则的键一致。 */
44
+ readonly catalogKey: string;
45
+ }
46
+ /**
47
+ * 用户为该来源 × 模型配置的规则(未配置则 undefined)。
48
+ *
49
+ * @param facts - 判档事实。
50
+ * @returns 命中的规则,未命中时 undefined。
51
+ */
52
+ export declare function ruleOf(facts: BandFacts): PeakRule | undefined;
53
+ /**
54
+ * 某来源 × 某模型此刻处于哪一档。
55
+ *
56
+ * 判定顺序:
57
+ * 1. 用户配了该来源 × 模型的时段 → 用它(`effectiveRule` 补齐该来源的缺省:
58
+ * 窗口、周末、时区;官方来源另补中国法定节假日);
59
+ * 2. 未配 → 官方来源走全局 `tierAt`(含节假日),订阅来源走**同一组官方窗口
60
+ * 但不含中国节假日**——订阅厂商的倍率表里没有中国节假日这一项,套上去会
61
+ * 把本该计倍率的时段误判成低谷。
62
+ *
63
+ * @param facts - 判档事实。
64
+ * @param at - 判定时刻(epoch ms)。
65
+ * @returns `peak` / `offPeak`。
66
+ */
67
+ export declare function tierOf(facts: BandFacts, at: number): PriceTierId;
68
+ /**
69
+ * 该来源 × 模型距离下一次档位切换还有多久(毫秒)。
70
+ *
71
+ * 复用客户端同源的倒计时实现(`scheduledCountdown`)——它已按「自定义规则」
72
+ * 算切换点(含周末与节假日例外),与面板里显示的倒计时是同一份逻辑,不会
73
+ * 出现「面板说还有 5 分钟、队列说还有 1 小时」的分裂。
74
+ *
75
+ * @param facts - 判档事实。
76
+ * @param at - 判定时刻(epoch ms)。
77
+ * @returns 距下次切换的毫秒数;无未来切换点时为 `Infinity`。
78
+ */
79
+ export declare function nextSwitchMsOf(facts: BandFacts, at: number): number;
80
+ //# sourceMappingURL=task-queue-band.d.ts.map
@@ -40,7 +40,29 @@ export interface TaskQueueModel {
40
40
  readonly providerName: string;
41
41
  readonly id: string;
42
42
  readonly name: string;
43
+ /**
44
+ * 该候选「省」的是什么(issue #143):官方按量通道省**现金**(谷档价更低),
45
+ * 订阅通道省**订阅额度**(该通道的峰谷倍率)。两者窗口数值可能相同但语义
46
+ * 不同,界面必须分开表述——混说就是假声明。
47
+ */
48
+ readonly saving: TaskQueueSaving;
49
+ /** 该候选此刻所处的档位(按**它自己的**来源判定,不同来源可同时不同档)。 */
50
+ readonly tier: 'peak' | 'offPeak';
51
+ /** 该候选距下一次档位切换还有多久(毫秒)。 */
52
+ readonly nextSwitchInMs: number;
43
53
  }
54
+ /**
55
+ * 候选模型所属通道的「省什么」(issue #143)。
56
+ *
57
+ * 三档而非两档,是因为插件**只能核实一部分**通道的计费性质:
58
+ * - `cash`:官方按量通道 / 中转站——低谷时段**单价**更低,省的是现金;
59
+ * - `quota`:订阅套餐通道——低谷消耗的**套餐额度**更少,省的是额度(不省钱);
60
+ * - `schedule`:其它来源——插件无从核实该通道的低谷到底省什么(既可能是
61
+ * 单价、也可能是额度),只按用户配的时段排程,不作任何「省了什么」的声明。
62
+ *
63
+ * 宁可少说也不说错:猜错会让用户以为省了钱,实际没省。
64
+ */
65
+ export type TaskQueueSaving = 'cash' | 'quota' | 'schedule';
44
66
  export interface TaskQueueModelSelection {
45
67
  readonly provider: string;
46
68
  readonly model: string;
@@ -54,10 +76,21 @@ export type TaskQueueBlockedReason =
54
76
  /** 宿主没有内置的 DeepSeek 官方按量通道(路由 id `deepseek-official`)。 */
55
77
  'no-official-route'
56
78
  /** 官方通道在,但其中没有任何带官方峰谷价的模型。 */
57
- | 'no-official-model';
79
+ | 'no-official-model'
80
+ /**
81
+ * 有订阅通道,但其中的模型都没有目录峰谷价(订阅额度倍率需要目录里有
82
+ * offPeak 价才能判档)——下一步是看该通道暴露了哪些模型,而不是配通道。
83
+ */
84
+ | 'no-scheduled-model';
58
85
  export interface TaskQueueSnapshot {
59
86
  /** All required host Session-control methods are available. */
60
87
  readonly supported: boolean;
88
+ /**
89
+ * 档位语义(issue #143):**按候选模型各自的来源判档**,不再是全局单一档位。
90
+ * 取「默认候选模型」当前的档位(默认模型不可用时取第一个候选);候选为空
91
+ * 时取官方全局档位。同一时刻不同来源可能处于不同档位——这正是按来源判档
92
+ * 的意义(订阅通道的倍率窗口与官方窗口可能不同)。
93
+ */
61
94
  readonly tier: 'peak' | 'offPeak';
62
95
  readonly nextSwitchInMs: number;
63
96
  readonly tasks: readonly TaskQueueTask[];
@@ -72,6 +105,7 @@ export interface TaskQueueSnapshot {
72
105
  /** Lightweight alert polling shape: never transports Prompt or Session content. */
73
106
  export interface TaskQueueSummary {
74
107
  readonly supported: boolean;
108
+ /** 与 {@link TaskQueueSnapshot.tier} 同语义:默认候选模型当前的档位。 */
75
109
  readonly tier: 'peak' | 'offPeak';
76
110
  readonly nextSwitchInMs: number;
77
111
  readonly queuedCount: number;
@@ -7,6 +7,8 @@
7
7
  * from submitting the same task. Prompts are persisted with mode 0600.
8
8
  */
9
9
  import type { SessionController } from '@deepseek-ai/dsh-api-session-controller';
10
+ import { type RouteChannel } from './task-queue-band.ts';
11
+ import { type PeakSchedule } from './peak-schedule.ts';
10
12
  import type { TaskQueueInput, TaskQueueSnapshot, TaskQueueSummary, TaskQueueWorkspace } from './task-queue-shared.ts';
11
13
  export type TaskQueueController = Pick<SessionController, 'create' | 'selectModel' | 'prompt' | 'follow' | 'modelCatalog'>;
12
14
  /**
@@ -37,6 +39,18 @@ export interface TaskQueueEngineOptions {
37
39
  readonly getWorkspaces: () => readonly TaskQueueWorkspace[];
38
40
  /** 工作区上下文(可选):缺席 → 不归组、复用路径不可用。 */
39
41
  readonly getWorkspaceContext?: () => TaskQueueWorkspaceContext | undefined;
42
+ /**
43
+ * 路由 → 通道属性(可选能力,issue #143):来源桶与「省现金还是省额度」。
44
+ *
45
+ * 缺席 → 只认官方按量通道(旧的单档口径),订阅通道不进候选。
46
+ * 存在时按它给出的来源桶查用户配置的模型级峰谷规则,逐任务判档。
47
+ */
48
+ readonly resolveRouteChannel?: (route: string) => RouteChannel | undefined;
49
+ /**
50
+ * 用户配置的模型级峰谷规则(可选能力,issue #143):按 `scheduleKey(source, model)`
51
+ * 查。缺席 → 只用各来源的默认窗口。
52
+ */
53
+ readonly resolvePeakSchedule?: () => PeakSchedule;
40
54
  readonly now?: () => number;
41
55
  readonly createId?: () => string;
42
56
  readonly ownerId?: string;
@@ -57,19 +71,75 @@ export declare class TaskQueueEngine {
57
71
  private taskAbort;
58
72
  private stopped;
59
73
  private pumping;
74
+ /**
75
+ * 模型目录缓存(issue #143)。
76
+ *
77
+ * 只缓存**目录事实**(候选清单与根因),**不缓存档位**——档位随时间变化,
78
+ * 缓存 60 秒会让面板显示过期的「距高峰还有 N 分钟」。每次快照现算档位。
79
+ */
60
80
  private modelCache;
61
81
  constructor(options: TaskQueueEngineOptions);
62
82
  start(): void;
63
83
  stop(): void;
64
84
  snapshot(refreshModels?: boolean): Promise<TaskQueueSnapshot>;
65
85
  summary(): Promise<TaskQueueSummary>;
86
+ /** 官方全局档位(无候选时的兜底口径,与旧行为逐字一致)。 */
87
+ private officialBand;
88
+ /**
89
+ * 档位按**默认候选模型**判定(issue #143)。
90
+ *
91
+ * 候选为空 → 回落到官方全局档位(没有可判的来源);默认模型不在候选内
92
+ * (宿主默认路由未配峰谷价)→ 用第一个候选。摘要接口不探测模型目录,
93
+ * 因此复用已缓存的候选;缓存为空时同样回落到官方全局档位。
94
+ */
95
+ private bandOf;
66
96
  enqueue(input: TaskQueueInput): Promise<void>;
67
97
  /** Validate the whole batch before one locked append: no partially admitted import. */
68
98
  enqueueMany(inputs: readonly TaskQueueInput[]): Promise<void>;
69
99
  remove(id: string): Promise<void>;
70
100
  clearFinished(): Promise<void>;
71
101
  private modelOptions;
102
+ /** 缓存的目录事实 + 现算的档位 → 快照用的候选清单。 */
103
+ private modelOptionsOf;
104
+ /**
105
+ * 候选模型 + 它当前所处的档位(issue #143)。
106
+ *
107
+ * 档位按**该候选自己的来源**判定——不同来源可能同一时刻处于不同档位,
108
+ * 逐候选给出,界面才能对所选模型说准话。
109
+ */
110
+ private decorateModel;
111
+ /**
112
+ * 用户是否为该来源 × 模型配了峰谷时段(issue #143)。
113
+ *
114
+ * 这是**用户显式声明「这个来源有峰谷分时」**的信号——与峰谷设置页同一份
115
+ * 数据。订阅通道(如 `dsh-opencode-go`)的倍率表在厂商侧,插件无从探测;
116
+ * 用户配了时段就说明他知道这个通道的分时规则,队列据此放行并按它排程。
117
+ *
118
+ * 注意判定键与峰谷设置页一致:`scheduleKey(source, 目录键)`——用**目录键**
119
+ * (`resolveCatalogKey` 归一后)而非宿主原始模型 id,否则同一个模型在两处
120
+ * 会对不上(#125 的同类坑)。
121
+ */
122
+ private hasPeakRule;
123
+ /**
124
+ * 某条路由 × 某个模型此刻处于哪一档(issue #143:按来源判档)。
125
+ *
126
+ * 用户为该来源 × 模型配了时段就用它;没配时官方来源走全局窗口(含中国
127
+ * 节假日),订阅来源走厂商倍率窗口(不含中国节假日——订阅厂商的倍率表里
128
+ * 没有这一项)。
129
+ */
130
+ private tierOfTask;
131
+ /** 某条路由 × 某个模型距下一次档位切换还有多久。 */
132
+ private nextSwitchMsOfTask;
72
133
  private pump;
134
+ /**
135
+ * 领取下一个可执行的任务(issue #143:按来源判档)。
136
+ *
137
+ * 档位闸门落在**任务自己**的来源 × 模型上,而不是全局单一窗口——不同来源
138
+ * 可能同一时刻处于不同档位(订阅通道的倍率窗口与官方窗口不一定重合),
139
+ * 逐任务判定才能让「现在能跑的那一路」先跑。全局闸门会让所有任务一起等。
140
+ *
141
+ * FIFO 语义保持不变:按入队顺序找**第一个**当前处于低谷的任务。
142
+ */
73
143
  private claimNext;
74
144
  private recoverExpired;
75
145
  private execute;
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.8.13",
4
+ "version": "1.8.15",
5
5
  "keywords": [
6
6
  "deepseek-harness",
7
7
  "deepseek",
@@ -122,6 +122,7 @@
122
122
  "@deepseek-ai/dsh-client-store": "*",
123
123
  "@deepseek-ai/dsh-client-ui-commands": "*",
124
124
  "@deepseek-ai/dsh-client-ui-conversation": "*",
125
+ "@deepseek-ai/dsh-client-ui-layout": "*",
125
126
  "@deepseek-ai/dsh-client-ui-primitives": "*",
126
127
  "@deepseek-ai/dsh-client-ui-settings": "*",
127
128
  "@deepseek-ai/dsh-client-ui-sidebar": "*",
@@ -163,6 +164,7 @@
163
164
  "@deepseek-ai/dsh-client-store": "0.2.3-alpha.3",
164
165
  "@deepseek-ai/dsh-client-ui-commands": "0.2.3-alpha.3",
165
166
  "@deepseek-ai/dsh-client-ui-conversation": "0.2.3-alpha.3",
167
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.3-alpha.3",
166
168
  "@deepseek-ai/dsh-client-ui-primitives": "0.2.3-alpha.3",
167
169
  "@deepseek-ai/dsh-client-ui-renderer": "0.2.3-alpha.3",
168
170
  "@deepseek-ai/dsh-client-ui-settings": "0.2.3-alpha.3",