@kenz1117/dsh-ui-usage-billing 1.8.13 → 1.8.14
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 +4 -4
- package/README.md +4 -4
- package/lib/client.js +5 -5
- package/lib/index.js +20 -9
- 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/domain/types.d.ts +3 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/panel-capability.d.ts +12 -0
- package/lib/types/client/usage-billing-settings.d.ts +14 -0
- package/lib/types/guard.d.ts +13 -3
- package/package.json +3 -1
package/lib/index.js
CHANGED
|
@@ -10130,15 +10130,26 @@ function isLoopbackHost(req, trustedHosts = /* @__PURE__ */ new Set()) {
|
|
|
10130
10130
|
if (name === "localhost" || name === "::1" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(name)) return true;
|
|
10131
10131
|
return name !== "" && trustedHosts.has(name);
|
|
10132
10132
|
}
|
|
10133
|
-
/** 校验 Origin
|
|
10133
|
+
/** 校验 Origin 头是否可信(写操作用,防止跨站表单/fetch 改写设置)。Origin 缺失
|
|
10134
10134
|
* (curl 或同源 fetch 不带)视为放行,交给下方的 Content-Type 校验兜底;Origin 存在
|
|
10135
|
-
*
|
|
10136
|
-
|
|
10135
|
+
* 但主机既非回环、也不在 trustedHosts 里则拒绝——跨站脚本发起的写请求必带攻击者
|
|
10136
|
+
* 域名的 Origin。
|
|
10137
|
+
*
|
|
10138
|
+
* 反向代理场景:浏览器把页面自身的地址写进 Origin(`https://dash.example.com`)。
|
|
10139
|
+
* Host 头因为同一域名被 trustedHosts 放行,Origin 却是同一个非回环域名——只认回环
|
|
10140
|
+
* 字面量会让「已显式信任的主机」在写操作上必然 403(读操作正常),表现为面板能
|
|
10141
|
+
* 打开、点任何保存/入队都报 `forbidden: loopback only`。因此 Origin 与 Host 共用
|
|
10142
|
+
* 同一份 trustedHosts:用户显式信任某个主机,就等于接受该主机的同源写请求。
|
|
10143
|
+
* @param origin - 原始 Origin 头(可能缺失)。
|
|
10144
|
+
* @param trustedHosts - 已归一化的可信主机名集合,与 {@link isLoopbackHost} 同口径。
|
|
10145
|
+
*/
|
|
10146
|
+
function isLoopbackOrigin(origin, trustedHosts = /* @__PURE__ */ new Set()) {
|
|
10137
10147
|
if (origin === void 0 || origin === "") return true;
|
|
10138
10148
|
try {
|
|
10139
10149
|
const raw = new URL(origin).hostname;
|
|
10140
10150
|
const host = raw.startsWith("[") && raw.endsWith("]") ? raw.slice(1, -1) : raw;
|
|
10141
|
-
|
|
10151
|
+
if (host === "localhost" || host === "::1" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(host)) return true;
|
|
10152
|
+
return host !== "" && trustedHosts.has(host.toLowerCase());
|
|
10142
10153
|
} catch {
|
|
10143
10154
|
return false;
|
|
10144
10155
|
}
|
|
@@ -10342,7 +10353,7 @@ function registerPeakScheduleRoute(ctx, deps) {
|
|
|
10342
10353
|
if (!guardLoopback(req, res, deps.trustedHosts)) return;
|
|
10343
10354
|
let raw;
|
|
10344
10355
|
if (req.method === "POST") {
|
|
10345
|
-
if (!isLoopbackOrigin(req.headers.origin)) return reply(res, 403, {
|
|
10356
|
+
if (!isLoopbackOrigin(req.headers.origin, deps.trustedHosts)) return reply(res, 403, {
|
|
10346
10357
|
error: "forbidden: loopback only",
|
|
10347
10358
|
message: "仅限本机请求"
|
|
10348
10359
|
});
|
|
@@ -10517,7 +10528,7 @@ function registerNotifyClaimRoute(ctx, deps) {
|
|
|
10517
10528
|
res.end(JSON.stringify({ error: "method not allowed" }));
|
|
10518
10529
|
return;
|
|
10519
10530
|
}
|
|
10520
|
-
if (!isLoopbackOrigin(req.headers.origin) || !(req.headers["content-type"] ?? "").toLowerCase().includes("application/json")) {
|
|
10531
|
+
if (!isLoopbackOrigin(req.headers.origin, deps.trustedHosts) || !(req.headers["content-type"] ?? "").toLowerCase().includes("application/json")) {
|
|
10521
10532
|
res.writeHead(403, { "content-type": "application/json; charset=utf-8" });
|
|
10522
10533
|
res.end(JSON.stringify({ error: "forbidden: loopback only" }));
|
|
10523
10534
|
return;
|
|
@@ -10739,7 +10750,7 @@ function registerRefreshRoute(ctx, deps) {
|
|
|
10739
10750
|
res.end(JSON.stringify({ error: "method not allowed" }));
|
|
10740
10751
|
return;
|
|
10741
10752
|
}
|
|
10742
|
-
if (!isLoopbackOrigin(req.headers.origin)) {
|
|
10753
|
+
if (!isLoopbackOrigin(req.headers.origin, deps.trustedHosts)) {
|
|
10743
10754
|
res.writeHead(403, { "content-type": "application/json; charset=utf-8" });
|
|
10744
10755
|
res.end(JSON.stringify({ error: "forbidden: loopback only" }));
|
|
10745
10756
|
return;
|
|
@@ -10854,7 +10865,7 @@ function registerUsageToolRoute(ctx, deps) {
|
|
|
10854
10865
|
return;
|
|
10855
10866
|
}
|
|
10856
10867
|
if (req.method === "POST") {
|
|
10857
|
-
if (!isLoopbackOrigin(req.headers.origin)) {
|
|
10868
|
+
if (!isLoopbackOrigin(req.headers.origin, deps.trustedHosts)) {
|
|
10858
10869
|
res.writeHead(403, { "content-type": "application/json; charset=utf-8" });
|
|
10859
10870
|
res.end(JSON.stringify({ error: "forbidden: loopback only" }));
|
|
10860
10871
|
return;
|
|
@@ -11738,7 +11749,7 @@ function registerTaskQueueRoute(ctx, deps) {
|
|
|
11738
11749
|
return;
|
|
11739
11750
|
}
|
|
11740
11751
|
if (req.method === "POST") {
|
|
11741
|
-
if (!isLoopbackOrigin(req.headers.origin)) {
|
|
11752
|
+
if (!isLoopbackOrigin(req.headers.origin, deps.trustedHosts)) {
|
|
11742
11753
|
send(res, 403, { error: "forbidden: loopback only" });
|
|
11743
11754
|
return;
|
|
11744
11755
|
}
|
|
@@ -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
|
|
@@ -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
|
/**
|
|
@@ -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' | 'cardModeFull' | 'cardModeFullHint' | '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';
|
|
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
|
|
@@ -41,6 +41,20 @@ 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 反馈)。 */
|
package/lib/types/guard.d.ts
CHANGED
|
@@ -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
|
|
37
|
+
/** 校验 Origin 头是否可信(写操作用,防止跨站表单/fetch 改写设置)。Origin 缺失
|
|
38
38
|
* (curl 或同源 fetch 不带)视为放行,交给下方的 Content-Type 校验兜底;Origin 存在
|
|
39
|
-
*
|
|
40
|
-
|
|
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
|
*
|
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.
|
|
4
|
+
"version": "1.8.14",
|
|
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",
|