@kenz1117/dsh-ui-usage-billing 1.8.12 → 1.8.13
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 +7 -4
- package/README.md +8 -5
- package/lib/client.js +5 -5
- package/lib/index.js +54 -9
- package/lib/types/balance.d.ts +20 -1
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/queue-eligibility.d.ts +30 -0
- package/lib/types/client/task-queue-quick.d.ts +1 -1
- package/lib/types/pricing-shared.d.ts +14 -0
- package/lib/types/task-queue-shared.d.ts +12 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -4807,6 +4807,20 @@ const BALANCE_CLIENT_HEADERS = {
|
|
|
4807
4807
|
locale: "x-dsh-billing-client-locale",
|
|
4808
4808
|
timezone: "x-dsh-billing-client-timezone-offset"
|
|
4809
4809
|
};
|
|
4810
|
+
/**
|
|
4811
|
+
* 宿主内置的两条 DeepSeek 通道的路由 id(宿主包 `llm-deepseek-api-key` /
|
|
4812
|
+
* `llm-deepseek-account` 注册,`0.1.2-alpha.1` ~ `0.2.3-alpha.3` 全程稳定):
|
|
4813
|
+
*
|
|
4814
|
+
* - `deepseek-official`:平台 API key 通道,花的是用户自己的 DeepSeek 平台
|
|
4815
|
+
* 账户余额(凭据 ref 默认 `DEEPSEEK_API_KEY`);
|
|
4816
|
+
* - `deepseek-account`:登录账号通道,花的是宿主登录钱包的余额。
|
|
4817
|
+
*
|
|
4818
|
+
* 两条通道都**不在 llm-pi-ai 路由表里**(插件自造的 `deepseek` 路由 id 与它们
|
|
4819
|
+
* 不同)。钱包归属必须按宿主通道 id 认,否则内置通道的用量桶认不到任何钱包
|
|
4820
|
+
* (issue #141:悬浮卡显示「余额不可确认」)。
|
|
4821
|
+
*/
|
|
4822
|
+
const DEEPSEEK_PLATFORM_ROUTE = "deepseek-official";
|
|
4823
|
+
const DEEPSEEK_LOGIN_ROUTE = "deepseek-account";
|
|
4810
4824
|
function siteBucketKey(ref) {
|
|
4811
4825
|
if (ref.kind === "site" && ref.origin) return `site:${ref.origin}`;
|
|
4812
4826
|
if (ref.kind === "direct" && ref.provider) return `direct:${ref.provider}`;
|
|
@@ -7252,6 +7266,12 @@ const customGate = createCooldownGate({
|
|
|
7252
7266
|
});
|
|
7253
7267
|
/** DeepSeek 官方余额接口(官方文档 api-docs.deepseek.com/api/get-user-balance)。 */
|
|
7254
7268
|
const DEEPSEEK_BALANCE_URL = "https://api.deepseek.com/user/balance";
|
|
7269
|
+
/**
|
|
7270
|
+
* 宿主内置平台通道(路由 id `deepseek-official`)的默认凭据 ref——宿主包
|
|
7271
|
+
* `llm-deepseek-api-key` 的 `apiKeyEnv` 默认值(`0.1.2-alpha.1` ~ `0.2.3-alpha.3`)。
|
|
7272
|
+
* 内置通道不在 llm-pi-ai 路由表里,只能按这个约定 ref 找回它的 key。
|
|
7273
|
+
*/
|
|
7274
|
+
const DEEPSEEK_PLATFORM_KEY_REF = "DEEPSEEK_API_KEY";
|
|
7255
7275
|
/** Moonshot/Kimi 官方余额接口(platform.kimi.com/docs/api/balance)。 */
|
|
7256
7276
|
const MOONSHOT_BALANCE_URL = "https://api.moonshot.cn/v1/users/me/balance";
|
|
7257
7277
|
/** 阶跃星辰 StepFun 官方账户信息接口(platform.stepfun.com/docs/api-reference/accounts/get)。 */
|
|
@@ -7348,11 +7368,16 @@ function parseDeepSeekBalance(data) {
|
|
|
7348
7368
|
...isAvailable !== void 0 ? { isAvailable } : {}
|
|
7349
7369
|
};
|
|
7350
7370
|
}
|
|
7371
|
+
/**
|
|
7372
|
+
* 登录钱包(宿主 DeepSeek 账号通道):归属宿主内置的登录通道路由 id
|
|
7373
|
+
* `deepseek-account`(宿主包 `llm-deepseek-account` 注册)——它供的是登录通道,
|
|
7374
|
+
* 不是 API key 路由,两只钱包不能共认一条路由(issue #141)。
|
|
7375
|
+
*/
|
|
7351
7376
|
const ACCOUNT_WALLET = {
|
|
7352
7377
|
provider: "deepseek",
|
|
7353
7378
|
displayName: "DeepSeek",
|
|
7354
7379
|
sourceRoute: "deepseek",
|
|
7355
|
-
attributedRoutes: [
|
|
7380
|
+
attributedRoutes: [DEEPSEEK_LOGIN_ROUTE],
|
|
7356
7381
|
walletKind: "account"
|
|
7357
7382
|
};
|
|
7358
7383
|
const warnedAccountFailures = /* @__PURE__ */ new Set();
|
|
@@ -7577,6 +7602,14 @@ function bearer(route, displayName, endpoint, query) {
|
|
|
7577
7602
|
}
|
|
7578
7603
|
const QUERIERS = [
|
|
7579
7604
|
bearer("deepseek", "deepseek", DEEPSEEK_BALANCE_URL, queryDeepSeek),
|
|
7605
|
+
{
|
|
7606
|
+
route: DEEPSEEK_PLATFORM_ROUTE,
|
|
7607
|
+
displayName: "deepseek",
|
|
7608
|
+
endpoint: DEEPSEEK_BALANCE_URL,
|
|
7609
|
+
keyRefs: [DEEPSEEK_PLATFORM_KEY_REF],
|
|
7610
|
+
keyOnly: true,
|
|
7611
|
+
query: (key) => queryDeepSeek(DEEPSEEK_BALANCE_URL, key)
|
|
7612
|
+
},
|
|
7580
7613
|
bearer("moonshot", "月之暗面", MOONSHOT_BALANCE_URL, queryMoonshot),
|
|
7581
7614
|
bearer("stepfun", "阶跃星辰", STEPFUN_BALANCE_URL, queryStepFun),
|
|
7582
7615
|
bearer("siliconflow", "硅基流动", SILICONFLOW_BALANCE_URL, querySiliconFlow),
|
|
@@ -7614,9 +7647,11 @@ const QUERIERS = [
|
|
|
7614
7647
|
* dashboard shows a stable state instead of dropping the row.
|
|
7615
7648
|
* @param ctx - host context carrying the credentials seam.
|
|
7616
7649
|
* @param providers - the llm-pi-ai providers dict (`<route> → { apiKeyEnv? }`).
|
|
7650
|
+
* @param client - UI metadata for the host login wallet service.
|
|
7651
|
+
* @param options - extra credential candidates per route (plugin config).
|
|
7617
7652
|
* @returns the balance rows (one per provider).
|
|
7618
7653
|
*/
|
|
7619
|
-
async function queryBalances(ctx, providers, client) {
|
|
7654
|
+
async function queryBalances(ctx, providers, client, options) {
|
|
7620
7655
|
const resolveRef = async (name) => {
|
|
7621
7656
|
try {
|
|
7622
7657
|
const hit = await ctx.credentials.resolve(credentialRef(name));
|
|
@@ -7638,7 +7673,12 @@ async function queryBalances(ctx, providers, client) {
|
|
|
7638
7673
|
const resolved = await Promise.all(QUERIERS.map(async (spec) => {
|
|
7639
7674
|
const { route, endpoint } = spec;
|
|
7640
7675
|
const env = providers[route]?.apiKeyEnv;
|
|
7641
|
-
const hit = await firstResolvedRef([
|
|
7676
|
+
const hit = await firstResolvedRef([
|
|
7677
|
+
...env ? [env] : [],
|
|
7678
|
+
...spec.keyRefs ?? [],
|
|
7679
|
+
...options?.extraKeyRefs?.[route] ?? [],
|
|
7680
|
+
...routeKeyRefCandidates(route)
|
|
7681
|
+
], resolveRef);
|
|
7642
7682
|
const expectedOrigin = endpoint && new URL(endpoint).origin;
|
|
7643
7683
|
const configuredOrigin = origins.get(route);
|
|
7644
7684
|
const verified = configuredOrigin === void 0 || expectedOrigin !== void 0 && configuredOrigin === expectedOrigin;
|
|
@@ -7649,7 +7689,7 @@ async function queryBalances(ctx, providers, client) {
|
|
|
7649
7689
|
verified
|
|
7650
7690
|
};
|
|
7651
7691
|
}));
|
|
7652
|
-
const present = (item) => item.key !== void 0 || Object.hasOwn(providers, item.route);
|
|
7692
|
+
const present = (item) => item.key !== void 0 || !item.keyOnly && Object.hasOwn(providers, item.route);
|
|
7653
7693
|
const presentVendors = new Set(resolved.filter(present).map((item) => item.displayName));
|
|
7654
7694
|
const targets = [];
|
|
7655
7695
|
for (const item of resolved) {
|
|
@@ -11329,8 +11369,10 @@ var TaskQueueEngine = class {
|
|
|
11329
11369
|
if (!refresh && this.modelCache !== void 0 && this.now() - this.modelCache.at < OPTIONS_CACHE_MS) return this.modelCache;
|
|
11330
11370
|
const catalog = await controller.modelCatalog();
|
|
11331
11371
|
const models = [];
|
|
11372
|
+
let officialRoute = false;
|
|
11332
11373
|
for (const group of catalog.groups) {
|
|
11333
11374
|
if (group.id !== "deepseek-official") continue;
|
|
11375
|
+
officialRoute = true;
|
|
11334
11376
|
for (const model of group.models) {
|
|
11335
11377
|
if (rateChannelOf(model.id, false) !== "deepseek-metered") continue;
|
|
11336
11378
|
models.push({
|
|
@@ -11346,14 +11388,17 @@ var TaskQueueEngine = class {
|
|
|
11346
11388
|
provider: candidate.provider,
|
|
11347
11389
|
model: candidate.model
|
|
11348
11390
|
};
|
|
11391
|
+
const blockedReason = models.length > 0 ? void 0 : officialRoute ? "no-official-model" : "no-official-route";
|
|
11349
11392
|
this.modelCache = {
|
|
11350
11393
|
at: this.now(),
|
|
11351
11394
|
models,
|
|
11352
|
-
defaultModel
|
|
11395
|
+
defaultModel,
|
|
11396
|
+
blockedReason
|
|
11353
11397
|
};
|
|
11354
11398
|
return {
|
|
11355
11399
|
models,
|
|
11356
|
-
defaultModel
|
|
11400
|
+
defaultModel,
|
|
11401
|
+
blockedReason
|
|
11357
11402
|
};
|
|
11358
11403
|
}
|
|
11359
11404
|
async pump() {
|
|
@@ -11867,8 +11912,8 @@ const QUOTA_RESPONSE_BUDGET_MS = 8e3;
|
|
|
11867
11912
|
* 取 5 分钟:与 usage-stats 的 30s 轮询 + 5 分钟快照节流同一量级。
|
|
11868
11913
|
*/
|
|
11869
11914
|
const RECONCILE_BASIS_MAX_AGE_MS = 3e5;
|
|
11870
|
-
/** DeepSeek
|
|
11871
|
-
const DEFAULT_BALANCE_API_KEY_ENV =
|
|
11915
|
+
/** DeepSeek 余额查询的默认凭据引用(与宿主内置平台通道的默认引用一致)。 */
|
|
11916
|
+
const DEFAULT_BALANCE_API_KEY_ENV = DEEPSEEK_PLATFORM_KEY_REF;
|
|
11872
11917
|
/**
|
|
11873
11918
|
* 本插件版本号:从包自身的 package.json 读取(单一来源),随 usage-stats
|
|
11874
11919
|
* 下发,供「设置 → 插件信息卡」展示。发布版 lib/index.js 相对包根解析。
|
|
@@ -12742,7 +12787,7 @@ function apply(ctx, config = {}) {
|
|
|
12742
12787
|
...providers["deepseek"],
|
|
12743
12788
|
apiKeyEnv: config.balanceApiKeyEnv ?? DEFAULT_BALANCE_API_KEY_ENV
|
|
12744
12789
|
};
|
|
12745
|
-
const balances = await queryBalances(ctx, providers, client);
|
|
12790
|
+
const balances = await queryBalances(ctx, providers, client, config.balanceApiKeyEnv === void 0 ? void 0 : { extraKeyRefs: { [DEEPSEEK_PLATFORM_ROUTE]: [config.balanceApiKeyEnv] } });
|
|
12746
12791
|
const custom = await queryCustomBalances(ctx, config.customBalances ?? []);
|
|
12747
12792
|
const declared = await queryDeclaredEndpoints(ctx, piProviders, config.declaredEndpoints ?? []);
|
|
12748
12793
|
for (const row of [
|
package/lib/types/balance.d.ts
CHANGED
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { Context } from '@deepseek-ai/cordis';
|
|
16
16
|
import { type BalanceClientMetadata, type CustomBalanceConfig, type CustomBalanceExtract, type ProviderBalance } from './pricing-shared.ts';
|
|
17
|
+
/**
|
|
18
|
+
* 宿主内置平台通道(路由 id `deepseek-official`)的默认凭据 ref——宿主包
|
|
19
|
+
* `llm-deepseek-api-key` 的 `apiKeyEnv` 默认值(`0.1.2-alpha.1` ~ `0.2.3-alpha.3`)。
|
|
20
|
+
* 内置通道不在 llm-pi-ai 路由表里,只能按这个约定 ref 找回它的 key。
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEEPSEEK_PLATFORM_KEY_REF = "DEEPSEEK_API_KEY";
|
|
17
23
|
export declare function apiBalanceSource(row: ProviderBalance): string | undefined;
|
|
18
24
|
/**
|
|
19
25
|
* 从 TokenDance 余额响应提取剩余余额并换算为元。导出供测试:纯函数。
|
|
@@ -23,6 +29,17 @@ export declare function apiBalanceSource(row: ProviderBalance): string | undefin
|
|
|
23
29
|
* @returns 剩余余额(元);提取不到返回 undefined。
|
|
24
30
|
*/
|
|
25
31
|
export declare function pickTokenDanceBalanceCny(data: unknown): number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* 余额查询的额外口径(插件配置进不来时的唯一入口)。
|
|
34
|
+
*/
|
|
35
|
+
export interface BalanceQueryOptions {
|
|
36
|
+
/**
|
|
37
|
+
* 额外的凭据候选(按路由 id):插件配置里的 `balanceApiKeyEnv` 之类。排在路由
|
|
38
|
+
* 约定名之前——宿主内置通道的 key 由宿主自己存(默认 ref 固定),插件配置的
|
|
39
|
+
* ref 只是后备。
|
|
40
|
+
*/
|
|
41
|
+
extraKeyRefs?: Readonly<Record<string, readonly string[]>>;
|
|
42
|
+
}
|
|
26
43
|
/**
|
|
27
44
|
* Query every configured provider's account balance. A provider is queried only
|
|
28
45
|
* when its llm-pi-ai route has a key: an explicit `apiKeyEnv`, or — on hosts
|
|
@@ -31,12 +48,14 @@ export declare function pickTokenDanceBalanceCny(data: unknown): number | undefi
|
|
|
31
48
|
* dashboard shows a stable state instead of dropping the row.
|
|
32
49
|
* @param ctx - host context carrying the credentials seam.
|
|
33
50
|
* @param providers - the llm-pi-ai providers dict (`<route> → { apiKeyEnv? }`).
|
|
51
|
+
* @param client - UI metadata for the host login wallet service.
|
|
52
|
+
* @param options - extra credential candidates per route (plugin config).
|
|
34
53
|
* @returns the balance rows (one per provider).
|
|
35
54
|
*/
|
|
36
55
|
export declare function queryBalances(ctx: Context, providers: Readonly<Record<string, {
|
|
37
56
|
apiKeyEnv?: string;
|
|
38
57
|
baseURL?: string;
|
|
39
|
-
}>>, client?: BalanceClientMetadata): Promise<readonly ProviderBalance[]>;
|
|
58
|
+
}>>, client?: BalanceClientMetadata, options?: BalanceQueryOptions): Promise<readonly ProviderBalance[]>;
|
|
40
59
|
/**
|
|
41
60
|
* 按 extract 规则从响应 JSON 求值。导出供测试:纯函数。
|
|
42
61
|
* @param rule - 提取规则(const / path / add / subtract / divide)。
|
|
@@ -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' | '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' | '
|
|
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';
|
|
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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 队列候选为空时的原因分层(issue #143)。
|
|
3
|
+
*
|
|
4
|
+
* 面板(队列 Tab)与会话入队入口共用这一份判定与文案来源:只说「模型不
|
|
5
|
+
* 支持」用户无从下手,必须分清「宿主没有官方通道」与「官方通道里没有可用
|
|
6
|
+
* 模型」——两者的下一步动作完全不同(配 API Key 通道 vs 看模型清单)。
|
|
7
|
+
*/
|
|
8
|
+
import type { TaskQueueBlockedReason } from '../task-queue-shared.ts';
|
|
9
|
+
import type { UsageBillingKey } from './locales.ts';
|
|
10
|
+
/** 判定所需的最小事实面(面板快照与会话入队读到的都是它的子集)。 */
|
|
11
|
+
export interface QueueEligibilityFacts {
|
|
12
|
+
/** 宿主登记的工作区。 */
|
|
13
|
+
readonly workspaces: readonly {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
}[];
|
|
16
|
+
/** 官方峰谷候选模型。 */
|
|
17
|
+
readonly models: readonly {
|
|
18
|
+
readonly provider: string;
|
|
19
|
+
readonly id: string;
|
|
20
|
+
}[];
|
|
21
|
+
/** 服务端给出的根因(models 为空时才有值)。 */
|
|
22
|
+
readonly blockedReason?: TaskQueueBlockedReason | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 候选/工作区缺失时的提示键;一切就绪时返回 undefined。
|
|
26
|
+
* @param facts - 快照里的工作区、候选与根因。
|
|
27
|
+
* @returns 对应的文案键,或 undefined(无需提示)。
|
|
28
|
+
*/
|
|
29
|
+
export declare function queueBlockedKey(facts: QueueEligibilityFacts): UsageBillingKey | undefined;
|
|
30
|
+
//# sourceMappingURL=queue-eligibility.d.ts.map
|
|
@@ -11,7 +11,7 @@ import type { InputActions, InputState } from '@deepseek-ai/dsh-client-ui-conver
|
|
|
11
11
|
import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store';
|
|
12
12
|
import type { SessionProjectionMap } from '@deepseek-ai/dsh-api-session-controller/client';
|
|
13
13
|
import type { UsageBillingKey } from './locales.ts';
|
|
14
|
-
type Translate = (key: UsageBillingKey) => string;
|
|
14
|
+
type Translate = (key: UsageBillingKey, params?: Record<string, unknown>) => string;
|
|
15
15
|
type ProjectionKey = Extract<keyof SessionProjectionMap, string>;
|
|
16
16
|
/** Optional selector shape: old hosts may omit the standard input kit. */
|
|
17
17
|
type ReadInput = <S>(selector: (state: InputState) => S, eq?: (a: S, b: S) => boolean) => S | undefined;
|
|
@@ -70,6 +70,20 @@ export declare const BALANCE_CLIENT_HEADERS: {
|
|
|
70
70
|
readonly locale: "x-dsh-billing-client-locale";
|
|
71
71
|
readonly timezone: "x-dsh-billing-client-timezone-offset";
|
|
72
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* 宿主内置的两条 DeepSeek 通道的路由 id(宿主包 `llm-deepseek-api-key` /
|
|
75
|
+
* `llm-deepseek-account` 注册,`0.1.2-alpha.1` ~ `0.2.3-alpha.3` 全程稳定):
|
|
76
|
+
*
|
|
77
|
+
* - `deepseek-official`:平台 API key 通道,花的是用户自己的 DeepSeek 平台
|
|
78
|
+
* 账户余额(凭据 ref 默认 `DEEPSEEK_API_KEY`);
|
|
79
|
+
* - `deepseek-account`:登录账号通道,花的是宿主登录钱包的余额。
|
|
80
|
+
*
|
|
81
|
+
* 两条通道都**不在 llm-pi-ai 路由表里**(插件自造的 `deepseek` 路由 id 与它们
|
|
82
|
+
* 不同)。钱包归属必须按宿主通道 id 认,否则内置通道的用量桶认不到任何钱包
|
|
83
|
+
* (issue #141:悬浮卡显示「余额不可确认」)。
|
|
84
|
+
*/
|
|
85
|
+
export declare const DEEPSEEK_PLATFORM_ROUTE = "deepseek-official";
|
|
86
|
+
export declare const DEEPSEEK_LOGIN_ROUTE = "deepseek-account";
|
|
73
87
|
/** Wire format shared by the aggregation buckets and their consumers. */
|
|
74
88
|
export type SiteKind = 'site' | 'direct' | 'unknown';
|
|
75
89
|
export interface SiteRef {
|
|
@@ -45,6 +45,16 @@ export interface TaskQueueModelSelection {
|
|
|
45
45
|
readonly provider: string;
|
|
46
46
|
readonly model: string;
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* 候选为空时的根因分层(issue #143):只说「模型不支持」用户无从下手,必须
|
|
50
|
+
* 分清「宿主没有官方通道」与「官方通道里没有可用模型」——两者的下一步动作
|
|
51
|
+
* 完全不同(配 API Key 通道 vs 看模型清单)。
|
|
52
|
+
*/
|
|
53
|
+
export type TaskQueueBlockedReason =
|
|
54
|
+
/** 宿主没有内置的 DeepSeek 官方按量通道(路由 id `deepseek-official`)。 */
|
|
55
|
+
'no-official-route'
|
|
56
|
+
/** 官方通道在,但其中没有任何带官方峰谷价的模型。 */
|
|
57
|
+
| 'no-official-model';
|
|
48
58
|
export interface TaskQueueSnapshot {
|
|
49
59
|
/** All required host Session-control methods are available. */
|
|
50
60
|
readonly supported: boolean;
|
|
@@ -55,6 +65,8 @@ export interface TaskQueueSnapshot {
|
|
|
55
65
|
readonly models: readonly TaskQueueModel[];
|
|
56
66
|
/** Host default route for an unconfigured Session; eligibility is checked separately. */
|
|
57
67
|
readonly defaultModel?: TaskQueueModelSelection | undefined;
|
|
68
|
+
/** 候选为空的根因(models 为空时才有值)。 */
|
|
69
|
+
readonly blockedReason?: TaskQueueBlockedReason | undefined;
|
|
58
70
|
readonly optionsError?: string;
|
|
59
71
|
}
|
|
60
72
|
/** Lightweight alert polling shape: never transports Prompt or Session content. */
|
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.13",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|