@kenz1117/dsh-ui-usage-billing 1.8.3-alpha.20 → 1.8.3-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +2 -2
- package/lib/index.js +269 -23
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/queue-eligibility.d.ts +17 -2
- package/lib/types/task-queue-band.d.ts +80 -0
- package/lib/types/task-queue-shared.d.ts +35 -1
- package/lib/types/task-queue.d.ts +70 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -11176,6 +11176,128 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
11176
11176
|
}), "usage-billing: usage-stats route");
|
|
11177
11177
|
}
|
|
11178
11178
|
//#endregion
|
|
11179
|
+
//#region lib/types/client/scheduled-band.js
|
|
11180
|
+
const MINUTE = 6e4;
|
|
11181
|
+
const DAY = 1440 * MINUTE;
|
|
11182
|
+
/** Only wall-clock boundaries can change a band. Infinity means no future transition. */
|
|
11183
|
+
function scheduledCountdown(now, channel, rule) {
|
|
11184
|
+
if (!rule || channel !== "deepseek-metered") return channelCountdown(now, channel);
|
|
11185
|
+
const tier = customTier(now, rule);
|
|
11186
|
+
const offset = rule.utcOffsetMinutes * MINUTE;
|
|
11187
|
+
const midnight = Math.floor((now + offset) / DAY) * DAY - offset;
|
|
11188
|
+
const boundaries = [.../* @__PURE__ */ new Set([0, ...rule.windows.filter((m) => m < 1440)])];
|
|
11189
|
+
const days = /* @__PURE__ */ new Set([
|
|
11190
|
+
0,
|
|
11191
|
+
1,
|
|
11192
|
+
2,
|
|
11193
|
+
3,
|
|
11194
|
+
4,
|
|
11195
|
+
5,
|
|
11196
|
+
6,
|
|
11197
|
+
7
|
|
11198
|
+
]);
|
|
11199
|
+
for (const date of rule.holidays) {
|
|
11200
|
+
const day = (Date.parse(`${date.slice(0, 4)}-${date.slice(4, 6)}-${date.slice(6)}T00:00Z`) - offset - midnight) / DAY;
|
|
11201
|
+
if (day < 0) continue;
|
|
11202
|
+
for (let i = 0; i <= 7; i++) days.add(day + i);
|
|
11203
|
+
}
|
|
11204
|
+
for (const day of [...days].sort((a, b) => a - b)) for (const m of boundaries) {
|
|
11205
|
+
const at = midnight + day * DAY + m * MINUTE;
|
|
11206
|
+
if (at > now && customTier(at, rule) !== tier) return {
|
|
11207
|
+
tier,
|
|
11208
|
+
nextSwitchInMs: at - now
|
|
11209
|
+
};
|
|
11210
|
+
}
|
|
11211
|
+
return {
|
|
11212
|
+
tier,
|
|
11213
|
+
nextSwitchInMs: Infinity
|
|
11214
|
+
};
|
|
11215
|
+
}
|
|
11216
|
+
//#endregion
|
|
11217
|
+
//#region lib/types/task-queue-band.js
|
|
11218
|
+
/**
|
|
11219
|
+
* 低谷队列的**按来源判档**(issue #143)。
|
|
11220
|
+
*
|
|
11221
|
+
* 背景:报告者实测发现两件事——①订阅通道(如 `dsh-opencode-go`)确实有峰谷
|
|
11222
|
+
* 倍率(其模型目录里 `deepseek-v4.1-flash` / `deepseek-v4-pro` 在 UTC 周一至
|
|
11223
|
+
* 周五 01:00–04:00 / 06:00–10:00 时 `factor: 2`,其余为 1,即北京时间
|
|
11224
|
+
* 09:00–12:00 / 14:00–18:00 倍率 2);②插件的「按模型配峰谷时段」已经能让
|
|
11225
|
+
* 订阅通道的模型进入配置(`eligibleScheduleModel` 只要求目录里有 offPeak 价),
|
|
11226
|
+
* 但低谷队列此前**硬过滤官方路由**且用全局 `tierAt` 判档——用户配了、计费认了、
|
|
11227
|
+
* 队列不认。
|
|
11228
|
+
*
|
|
11229
|
+
* 本模块把「某个来源 × 某个模型此刻处于哪一档」收敛成一处判定,供队列的
|
|
11230
|
+
* 候选筛选、启动闸门与展示共用(**同一件事不许两处各写一套**)。
|
|
11231
|
+
*
|
|
11232
|
+
* 两条纪律:
|
|
11233
|
+
* 1. **来源桶与聚合层同源**——`site:` / `direct:` 的映射由调用方注入(用
|
|
11234
|
+
* `siteRefOf` + `siteBucketKey`),本模块不自己猜,避免队列与计费对同一
|
|
11235
|
+
* 条路由得出两个来源桶。
|
|
11236
|
+
* 2. **窗口语义分列**——官方按量通道的谷档省**现金**,订阅通道的谷段省**套餐
|
|
11237
|
+
* 额度**(倍率 2→1)。两者窗口数值可能相同,但省的东西不同;界面必须分开
|
|
11238
|
+
* 表述,混说就是假声明。
|
|
11239
|
+
*/
|
|
11240
|
+
/**
|
|
11241
|
+
* 官方按量通道的来源桶前缀。宿主内置的 DeepSeek API Key 通道
|
|
11242
|
+
* (路由 id `deepseek-official`)不在 llm-pi-ai 路由表里,按直连归位。
|
|
11243
|
+
*/
|
|
11244
|
+
const OFFICIAL_SOURCE_RE = /^direct:deepseek(?:-|$)|^site:https:\/\/api\.deepseek\.com$/i;
|
|
11245
|
+
/**
|
|
11246
|
+
* 用户为该来源 × 模型配置的规则(未配置则 undefined)。
|
|
11247
|
+
*
|
|
11248
|
+
* @param facts - 判档事实。
|
|
11249
|
+
* @returns 命中的规则,未命中时 undefined。
|
|
11250
|
+
*/
|
|
11251
|
+
function ruleOf(facts) {
|
|
11252
|
+
if (facts.channel === void 0 || facts.schedule === void 0) return void 0;
|
|
11253
|
+
return facts.schedule.models[scheduleKey(facts.channel.source, facts.catalogKey)];
|
|
11254
|
+
}
|
|
11255
|
+
/**
|
|
11256
|
+
* 某来源 × 某模型此刻处于哪一档。
|
|
11257
|
+
*
|
|
11258
|
+
* 判定顺序:
|
|
11259
|
+
* 1. 用户配了该来源 × 模型的时段 → 用它(`effectiveRule` 补齐该来源的缺省:
|
|
11260
|
+
* 窗口、周末、时区;官方来源另补中国法定节假日);
|
|
11261
|
+
* 2. 未配 → 官方来源走全局 `tierAt`(含节假日),订阅来源走**同一组官方窗口
|
|
11262
|
+
* 但不含中国节假日**——订阅厂商的倍率表里没有中国节假日这一项,套上去会
|
|
11263
|
+
* 把本该计倍率的时段误判成低谷。
|
|
11264
|
+
*
|
|
11265
|
+
* @param facts - 判档事实。
|
|
11266
|
+
* @param at - 判定时刻(epoch ms)。
|
|
11267
|
+
* @returns `peak` / `offPeak`。
|
|
11268
|
+
*/
|
|
11269
|
+
function tierOf(facts, at) {
|
|
11270
|
+
const channel = facts.channel;
|
|
11271
|
+
if (channel === void 0) return tierAt(at);
|
|
11272
|
+
const rule = ruleOf(facts);
|
|
11273
|
+
if (rule !== void 0) return customTier(at, effectiveRule(channel.source, rule));
|
|
11274
|
+
if (OFFICIAL_SOURCE_RE.test(channel.source)) return tierAt(at);
|
|
11275
|
+
return customTier(at, effectiveRule(channel.source, {}));
|
|
11276
|
+
}
|
|
11277
|
+
/**
|
|
11278
|
+
* 该来源 × 模型距离下一次档位切换还有多久(毫秒)。
|
|
11279
|
+
*
|
|
11280
|
+
* 复用客户端同源的倒计时实现(`scheduledCountdown`)——它已按「自定义规则」
|
|
11281
|
+
* 算切换点(含周末与节假日例外),与面板里显示的倒计时是同一份逻辑,不会
|
|
11282
|
+
* 出现「面板说还有 5 分钟、队列说还有 1 小时」的分裂。
|
|
11283
|
+
*
|
|
11284
|
+
* @param facts - 判档事实。
|
|
11285
|
+
* @param at - 判定时刻(epoch ms)。
|
|
11286
|
+
* @returns 距下次切换的毫秒数;无未来切换点时为 `Infinity`。
|
|
11287
|
+
*/
|
|
11288
|
+
function nextSwitchMsOf(facts, at) {
|
|
11289
|
+
const channel = facts.channel;
|
|
11290
|
+
if (channel === void 0) return switchMsOf(scheduledCountdown(at, "deepseek-metered"));
|
|
11291
|
+
const rule = ruleOf(facts);
|
|
11292
|
+
if (rule !== void 0) return switchMsOf(scheduledCountdown(at, "deepseek-metered", effectiveRule(channel.source, rule)));
|
|
11293
|
+
if (OFFICIAL_SOURCE_RE.test(channel.source)) return switchMsOf(scheduledCountdown(at, "deepseek-metered"));
|
|
11294
|
+
return switchMsOf(scheduledCountdown(at, "deepseek-metered", effectiveRule(channel.source, {})));
|
|
11295
|
+
}
|
|
11296
|
+
/** 倒计时可能缺席(通道无窗口)——缺席时按「无切换点」处理(Infinity)。 */
|
|
11297
|
+
function switchMsOf(countdown) {
|
|
11298
|
+
return countdown?.nextSwitchInMs ?? Infinity;
|
|
11299
|
+
}
|
|
11300
|
+
//#endregion
|
|
11179
11301
|
//#region lib/types/task-queue.js
|
|
11180
11302
|
/**
|
|
11181
11303
|
* Durable off-peak FIFO task queue (issue #106, new-host capability preview).
|
|
@@ -11253,6 +11375,12 @@ var TaskQueueEngine = class {
|
|
|
11253
11375
|
taskAbort;
|
|
11254
11376
|
stopped = true;
|
|
11255
11377
|
pumping = false;
|
|
11378
|
+
/**
|
|
11379
|
+
* 模型目录缓存(issue #143)。
|
|
11380
|
+
*
|
|
11381
|
+
* 只缓存**目录事实**(候选清单与根因),**不缓存档位**——档位随时间变化,
|
|
11382
|
+
* 缓存 60 秒会让面板显示过期的「距高峰还有 N 分钟」。每次快照现算档位。
|
|
11383
|
+
*/
|
|
11256
11384
|
modelCache;
|
|
11257
11385
|
constructor(options) {
|
|
11258
11386
|
this.options = options;
|
|
@@ -11279,42 +11407,70 @@ var TaskQueueEngine = class {
|
|
|
11279
11407
|
this.taskAbort?.abort();
|
|
11280
11408
|
}
|
|
11281
11409
|
async snapshot(refreshModels = false) {
|
|
11282
|
-
const countdown = channelCountdown(this.now(), "deepseek-metered");
|
|
11283
11410
|
const controller = usableController(this.options.getController());
|
|
11284
11411
|
const base = {
|
|
11285
11412
|
supported: controller !== void 0,
|
|
11286
|
-
tier: tierAt(this.now()),
|
|
11287
|
-
nextSwitchInMs: countdown?.nextSwitchInMs ?? 0,
|
|
11288
11413
|
tasks: (await this.readDocument()).tasks.map(publicTask),
|
|
11289
11414
|
workspaces: this.options.getWorkspaces()
|
|
11290
11415
|
};
|
|
11291
11416
|
if (controller === void 0) return {
|
|
11292
11417
|
...base,
|
|
11418
|
+
...this.officialBand(),
|
|
11293
11419
|
models: []
|
|
11294
11420
|
};
|
|
11295
11421
|
try {
|
|
11422
|
+
const options = await this.modelOptions(controller, refreshModels);
|
|
11296
11423
|
return {
|
|
11297
11424
|
...base,
|
|
11298
|
-
...
|
|
11425
|
+
...this.bandOf(options),
|
|
11426
|
+
...options
|
|
11299
11427
|
};
|
|
11300
11428
|
} catch (error) {
|
|
11301
11429
|
return {
|
|
11302
11430
|
...base,
|
|
11431
|
+
...this.officialBand(),
|
|
11303
11432
|
models: [],
|
|
11304
11433
|
optionsError: messageOf(error)
|
|
11305
11434
|
};
|
|
11306
11435
|
}
|
|
11307
11436
|
}
|
|
11308
11437
|
async summary() {
|
|
11309
|
-
const countdown = channelCountdown(this.now(), "deepseek-metered");
|
|
11310
11438
|
const document = await this.readDocument();
|
|
11311
11439
|
return {
|
|
11312
11440
|
supported: usableController(this.options.getController()) !== void 0,
|
|
11313
|
-
|
|
11314
|
-
nextSwitchInMs: countdown?.nextSwitchInMs ?? 0,
|
|
11441
|
+
...this.bandOf(this.modelCache === void 0 ? void 0 : this.modelOptionsOf(this.modelCache)),
|
|
11315
11442
|
queuedCount: document.tasks.filter((task) => task.status === "queued").length
|
|
11316
11443
|
};
|
|
11317
11444
|
}
|
|
11445
|
+
/** 官方全局档位(无候选时的兜底口径,与旧行为逐字一致)。 */
|
|
11446
|
+
officialBand() {
|
|
11447
|
+
const countdown = channelCountdown(this.now(), "deepseek-metered");
|
|
11448
|
+
return {
|
|
11449
|
+
tier: tierAt(this.now()),
|
|
11450
|
+
nextSwitchInMs: countdown?.nextSwitchInMs ?? 0
|
|
11451
|
+
};
|
|
11452
|
+
}
|
|
11453
|
+
/**
|
|
11454
|
+
* 档位按**默认候选模型**判定(issue #143)。
|
|
11455
|
+
*
|
|
11456
|
+
* 候选为空 → 回落到官方全局档位(没有可判的来源);默认模型不在候选内
|
|
11457
|
+
* (宿主默认路由未配峰谷价)→ 用第一个候选。摘要接口不探测模型目录,
|
|
11458
|
+
* 因此复用已缓存的候选;缓存为空时同样回落到官方全局档位。
|
|
11459
|
+
*/
|
|
11460
|
+
bandOf(options) {
|
|
11461
|
+
const models = options?.models ?? [];
|
|
11462
|
+
if (models.length === 0) return this.officialBand();
|
|
11463
|
+
const defaultModel = options?.defaultModel;
|
|
11464
|
+
const selected = defaultModel !== void 0 && models.some((model) => model.provider === defaultModel.provider && model.id === defaultModel.model) ? defaultModel : {
|
|
11465
|
+
provider: models[0].provider,
|
|
11466
|
+
model: models[0].id
|
|
11467
|
+
};
|
|
11468
|
+
const now = this.now();
|
|
11469
|
+
return {
|
|
11470
|
+
tier: this.tierOfTask(selected.provider, selected.model, now),
|
|
11471
|
+
nextSwitchInMs: this.nextSwitchMsOfTask(selected.provider, selected.model, now)
|
|
11472
|
+
};
|
|
11473
|
+
}
|
|
11318
11474
|
async enqueue(input) {
|
|
11319
11475
|
await this.enqueueMany([input]);
|
|
11320
11476
|
}
|
|
@@ -11377,47 +11533,109 @@ var TaskQueueEngine = class {
|
|
|
11377
11533
|
});
|
|
11378
11534
|
}
|
|
11379
11535
|
async modelOptions(controller, refresh = false) {
|
|
11380
|
-
if (!refresh && this.modelCache !== void 0 && this.now() - this.modelCache.at < OPTIONS_CACHE_MS) return this.modelCache;
|
|
11536
|
+
if (!refresh && this.modelCache !== void 0 && this.now() - this.modelCache.at < OPTIONS_CACHE_MS) return this.modelOptionsOf(this.modelCache);
|
|
11381
11537
|
const catalog = await controller.modelCatalog();
|
|
11382
|
-
const
|
|
11538
|
+
const candidates = [];
|
|
11383
11539
|
let officialRoute = false;
|
|
11540
|
+
let otherRouteWithPeakModel = false;
|
|
11384
11541
|
for (const group of catalog.groups) {
|
|
11385
|
-
|
|
11386
|
-
|
|
11542
|
+
const channel = this.options.resolveRouteChannel?.(group.id);
|
|
11543
|
+
const official = group.id === DEEPSEEK_PLATFORM_ROUTE;
|
|
11544
|
+
if (official) officialRoute = true;
|
|
11545
|
+
if (!official && channel === void 0) continue;
|
|
11387
11546
|
for (const model of group.models) {
|
|
11388
11547
|
if (rateChannelOf(model.id, false) !== "deepseek-metered") continue;
|
|
11389
|
-
|
|
11548
|
+
if (!official) otherRouteWithPeakModel = true;
|
|
11549
|
+
if (!official && !this.hasPeakRule(channel.source, resolveCatalogKey(model.id))) continue;
|
|
11550
|
+
candidates.push({
|
|
11390
11551
|
provider: group.id,
|
|
11391
11552
|
providerName: group.name,
|
|
11392
11553
|
id: model.id,
|
|
11393
|
-
name: model.name
|
|
11554
|
+
name: model.name,
|
|
11555
|
+
saving: official ? "cash" : channel.saving
|
|
11394
11556
|
});
|
|
11395
11557
|
}
|
|
11396
11558
|
}
|
|
11559
|
+
const blockedReason = candidates.length > 0 ? void 0 : officialRoute && !otherRouteWithPeakModel ? "no-official-model" : otherRouteWithPeakModel ? "no-scheduled-model" : "no-official-route";
|
|
11397
11560
|
const candidate = catalog.default;
|
|
11398
11561
|
const defaultModel = candidate === void 0 ? void 0 : {
|
|
11399
11562
|
provider: candidate.provider,
|
|
11400
11563
|
model: candidate.model
|
|
11401
11564
|
};
|
|
11402
|
-
const blockedReason = models.length > 0 ? void 0 : officialRoute ? "no-official-model" : "no-official-route";
|
|
11403
11565
|
this.modelCache = {
|
|
11404
11566
|
at: this.now(),
|
|
11405
|
-
|
|
11567
|
+
candidates,
|
|
11406
11568
|
defaultModel,
|
|
11407
11569
|
blockedReason
|
|
11408
11570
|
};
|
|
11571
|
+
return this.modelOptionsOf(this.modelCache);
|
|
11572
|
+
}
|
|
11573
|
+
/** 缓存的目录事实 + 现算的档位 → 快照用的候选清单。 */
|
|
11574
|
+
modelOptionsOf(cache) {
|
|
11575
|
+
return {
|
|
11576
|
+
models: cache.candidates.map((entry) => this.decorateModel(entry)),
|
|
11577
|
+
defaultModel: cache.defaultModel,
|
|
11578
|
+
blockedReason: cache.blockedReason
|
|
11579
|
+
};
|
|
11580
|
+
}
|
|
11581
|
+
/**
|
|
11582
|
+
* 候选模型 + 它当前所处的档位(issue #143)。
|
|
11583
|
+
*
|
|
11584
|
+
* 档位按**该候选自己的来源**判定——不同来源可能同一时刻处于不同档位,
|
|
11585
|
+
* 逐候选给出,界面才能对所选模型说准话。
|
|
11586
|
+
*/
|
|
11587
|
+
decorateModel(entry) {
|
|
11588
|
+
const now = this.now();
|
|
11409
11589
|
return {
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11590
|
+
...entry,
|
|
11591
|
+
tier: this.tierOfTask(entry.provider, entry.id, now),
|
|
11592
|
+
nextSwitchInMs: this.nextSwitchMsOfTask(entry.provider, entry.id, now)
|
|
11413
11593
|
};
|
|
11414
11594
|
}
|
|
11595
|
+
/**
|
|
11596
|
+
* 用户是否为该来源 × 模型配了峰谷时段(issue #143)。
|
|
11597
|
+
*
|
|
11598
|
+
* 这是**用户显式声明「这个来源有峰谷分时」**的信号——与峰谷设置页同一份
|
|
11599
|
+
* 数据。订阅通道(如 `dsh-opencode-go`)的倍率表在厂商侧,插件无从探测;
|
|
11600
|
+
* 用户配了时段就说明他知道这个通道的分时规则,队列据此放行并按它排程。
|
|
11601
|
+
*
|
|
11602
|
+
* 注意判定键与峰谷设置页一致:`scheduleKey(source, 目录键)`——用**目录键**
|
|
11603
|
+
* (`resolveCatalogKey` 归一后)而非宿主原始模型 id,否则同一个模型在两处
|
|
11604
|
+
* 会对不上(#125 的同类坑)。
|
|
11605
|
+
*/
|
|
11606
|
+
hasPeakRule(source, catalogKey) {
|
|
11607
|
+
const schedule = this.options.resolvePeakSchedule?.();
|
|
11608
|
+
if (schedule === void 0) return false;
|
|
11609
|
+
return schedule.models[scheduleKey(source, catalogKey)] !== void 0;
|
|
11610
|
+
}
|
|
11611
|
+
/**
|
|
11612
|
+
* 某条路由 × 某个模型此刻处于哪一档(issue #143:按来源判档)。
|
|
11613
|
+
*
|
|
11614
|
+
* 用户为该来源 × 模型配了时段就用它;没配时官方来源走全局窗口(含中国
|
|
11615
|
+
* 节假日),订阅来源走厂商倍率窗口(不含中国节假日——订阅厂商的倍率表里
|
|
11616
|
+
* 没有这一项)。
|
|
11617
|
+
*/
|
|
11618
|
+
tierOfTask(provider, model, at) {
|
|
11619
|
+
return tierOf({
|
|
11620
|
+
channel: this.options.resolveRouteChannel?.(provider),
|
|
11621
|
+
schedule: this.options.resolvePeakSchedule?.(),
|
|
11622
|
+
catalogKey: resolveCatalogKey(model)
|
|
11623
|
+
}, at);
|
|
11624
|
+
}
|
|
11625
|
+
/** 某条路由 × 某个模型距下一次档位切换还有多久。 */
|
|
11626
|
+
nextSwitchMsOfTask(provider, model, at) {
|
|
11627
|
+
return nextSwitchMsOf({
|
|
11628
|
+
channel: this.options.resolveRouteChannel?.(provider),
|
|
11629
|
+
schedule: this.options.resolvePeakSchedule?.(),
|
|
11630
|
+
catalogKey: resolveCatalogKey(model)
|
|
11631
|
+
}, at);
|
|
11632
|
+
}
|
|
11415
11633
|
async pump() {
|
|
11416
11634
|
if (this.stopped || this.pumping) return;
|
|
11417
11635
|
this.pumping = true;
|
|
11418
11636
|
try {
|
|
11419
11637
|
await this.recoverExpired();
|
|
11420
|
-
if (this.stopped
|
|
11638
|
+
if (this.stopped) return;
|
|
11421
11639
|
if (usableController(this.options.getController()) === void 0) return;
|
|
11422
11640
|
const task = await this.claimNext();
|
|
11423
11641
|
if (task !== void 0) await this.execute(task);
|
|
@@ -11427,10 +11645,20 @@ var TaskQueueEngine = class {
|
|
|
11427
11645
|
this.pumping = false;
|
|
11428
11646
|
}
|
|
11429
11647
|
}
|
|
11648
|
+
/**
|
|
11649
|
+
* 领取下一个可执行的任务(issue #143:按来源判档)。
|
|
11650
|
+
*
|
|
11651
|
+
* 档位闸门落在**任务自己**的来源 × 模型上,而不是全局单一窗口——不同来源
|
|
11652
|
+
* 可能同一时刻处于不同档位(订阅通道的倍率窗口与官方窗口不一定重合),
|
|
11653
|
+
* 逐任务判定才能让「现在能跑的那一路」先跑。全局闸门会让所有任务一起等。
|
|
11654
|
+
*
|
|
11655
|
+
* FIFO 语义保持不变:按入队顺序找**第一个**当前处于低谷的任务。
|
|
11656
|
+
*/
|
|
11430
11657
|
async claimNext() {
|
|
11431
11658
|
let claimed;
|
|
11659
|
+
const now = this.now();
|
|
11432
11660
|
await this.update((tasks) => {
|
|
11433
|
-
const task = tasks.find((candidate) => candidate.status === "queued");
|
|
11661
|
+
const task = tasks.find((candidate) => candidate.status === "queued" && this.tierOfTask(candidate.provider, candidate.model, now) === "offPeak");
|
|
11434
11662
|
if (task === void 0) return;
|
|
11435
11663
|
const next = {
|
|
11436
11664
|
...task,
|
|
@@ -11479,7 +11707,7 @@ var TaskQueueEngine = class {
|
|
|
11479
11707
|
this.heartbeat = heartbeat;
|
|
11480
11708
|
try {
|
|
11481
11709
|
if (!this.options.getWorkspaces().some((workspace) => workspace.path === claimed.cwd)) throw new TaskQueueError("workspace is no longer available", 409);
|
|
11482
|
-
if (
|
|
11710
|
+
if (this.tierOfTask(claimed.provider, claimed.model, this.now()) !== "offPeak") {
|
|
11483
11711
|
await this.requeue(claimed.id);
|
|
11484
11712
|
return;
|
|
11485
11713
|
}
|
|
@@ -11491,7 +11719,7 @@ var TaskQueueEngine = class {
|
|
|
11491
11719
|
if (!await this.patch(claimed.id, { fallbackReason: reuse.reason })) return;
|
|
11492
11720
|
}
|
|
11493
11721
|
const { models: availableModels } = await this.modelOptions(controller, true);
|
|
11494
|
-
if (!availableModels.some((model) => model.provider === claimed.provider && model.id === claimed.model)) throw new TaskQueueError("the selected
|
|
11722
|
+
if (!availableModels.some((model) => model.provider === claimed.provider && model.id === claimed.model)) throw new TaskQueueError("the selected DeepSeek model is no longer available", 409);
|
|
11495
11723
|
sessionId = (await this.createGroupedSession(controller, claimed.cwd)).sessionId;
|
|
11496
11724
|
}
|
|
11497
11725
|
const sessionPatch = { sessionId };
|
|
@@ -11502,7 +11730,7 @@ var TaskQueueEngine = class {
|
|
|
11502
11730
|
provider: claimed.provider,
|
|
11503
11731
|
model: claimed.model
|
|
11504
11732
|
});
|
|
11505
|
-
if (
|
|
11733
|
+
if (this.tierOfTask(claimed.provider, claimed.model, this.now()) !== "offPeak") {
|
|
11506
11734
|
await this.requeue(claimed.id);
|
|
11507
11735
|
return;
|
|
11508
11736
|
}
|
|
@@ -12534,6 +12762,24 @@ function apply(ctx, config = {}) {
|
|
|
12534
12762
|
});
|
|
12535
12763
|
const taskQueue = new TaskQueueEngine({
|
|
12536
12764
|
filePath: config.taskQueuePath ?? join(dshHome, ".dsh-usage-task-queue.json"),
|
|
12765
|
+
resolveRouteChannel: (route) => {
|
|
12766
|
+
if (route === "deepseek-official") return {
|
|
12767
|
+
source: `direct:${route}`,
|
|
12768
|
+
saving: "cash"
|
|
12769
|
+
};
|
|
12770
|
+
const subscription = subscriptionRoutes.has(route);
|
|
12771
|
+
const source = siteBucketKey(siteRefOf(route, readPiAiProviderRoutes(ctx.settings), { subscription }));
|
|
12772
|
+
if (source === "unknown") return void 0;
|
|
12773
|
+
if (subscription) return {
|
|
12774
|
+
source,
|
|
12775
|
+
saving: "quota"
|
|
12776
|
+
};
|
|
12777
|
+
return {
|
|
12778
|
+
source,
|
|
12779
|
+
saving: source.startsWith("site:") ? "cash" : "schedule"
|
|
12780
|
+
};
|
|
12781
|
+
},
|
|
12782
|
+
resolvePeakSchedule: schedules.current,
|
|
12537
12783
|
getController: () => {
|
|
12538
12784
|
try {
|
|
12539
12785
|
return ctx.get("sessionController");
|
|
@@ -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' | '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' | '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>;
|
|
@@ -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;
|
|
@@ -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;
|