@kenz1117/dsh-ui-usage-billing 1.8.3 → 1.8.4
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 +6 -6
- package/README.md +6 -6
- package/lib/client.js +3 -3
- package/lib/index.js +154 -14
- package/lib/types/aggregate.d.ts +17 -0
- package/lib/types/client/TaskQueuePanel.d.ts +5 -1
- package/lib/types/client/api/task-queue.d.ts +4 -0
- package/lib/types/client/api/usage-stats.d.ts +16 -2
- package/lib/types/client/domain/types.d.ts +10 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/usage-billing-settings.d.ts +9 -0
- package/lib/types/task-queue-shared.d.ts +11 -0
- package/lib/types/task-queue.d.ts +40 -3
- package/package.json +61 -59
package/lib/index.js
CHANGED
|
@@ -5285,6 +5285,28 @@ function configFingerprint(subscriptionMatcher, officialProviderIds, routeAliase
|
|
|
5285
5285
|
origins
|
|
5286
5286
|
].join("|");
|
|
5287
5287
|
}
|
|
5288
|
+
/** 失败原因摘要:给文档与日志用的短文本(截断,避免超长路径撑爆响应体)。
|
|
5289
|
+
* Error 取 message;非 Error 取字符串化值。截断上限与 task-queue 路由一致(300)。 */
|
|
5290
|
+
function reasonOf(error) {
|
|
5291
|
+
const trimmed = (error instanceof Error ? error.message : String(error)).trim();
|
|
5292
|
+
return trimmed.length > 300 ? `${trimmed.slice(0, 300)}…` : trimmed;
|
|
5293
|
+
}
|
|
5294
|
+
/**
|
|
5295
|
+
* 会话列表整体读不到(issue #119):宿主持久化后端整体故障,或会话目录里有
|
|
5296
|
+
* 读不了/对不上的日志。聚合无法枚举会话,只能降级到持久账本或磁盘快照——
|
|
5297
|
+
* 但「降级」必须让用户看得见,否则新装用户看到的是一片 ¥0(分不清没花钱
|
|
5298
|
+
* 还是没读到)。携带原因随文档下发,客户端据此显示「读取失败」。
|
|
5299
|
+
*/
|
|
5300
|
+
var SessionListUnavailableError = class extends Error {
|
|
5301
|
+
/** 失败原因摘要(面向用户的中文/英文提示语,由调用方决定措辞)。 */
|
|
5302
|
+
reason;
|
|
5303
|
+
constructor(reason, cause) {
|
|
5304
|
+
super(`session list unavailable: ${reason}`);
|
|
5305
|
+
this.name = "SessionListUnavailableError";
|
|
5306
|
+
this.reason = reason;
|
|
5307
|
+
if (cause !== void 0) this.cause = cause;
|
|
5308
|
+
}
|
|
5309
|
+
};
|
|
5288
5310
|
/** 会话格式拒读(宿主 SessionFormatUnsupportedError):日志完好,仅本构建读不了。
|
|
5289
5311
|
* 宿主错误类显式落 error.name;经包装/重建的路径只在 message 里保留类名,两处都认。
|
|
5290
5312
|
* 据此把「格式不受支持」与「损坏/其他读取失败」分开计数,供面板按原因归因(issue #84)。 */
|
|
@@ -5454,13 +5476,16 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5454
5476
|
let formatUnreadable = 0;
|
|
5455
5477
|
let noLedgerUnreadable = 0;
|
|
5456
5478
|
let staleLedgerSessions = 0;
|
|
5479
|
+
let sessionListError;
|
|
5457
5480
|
if (mode === "full") {
|
|
5458
5481
|
let metas;
|
|
5459
5482
|
try {
|
|
5460
5483
|
metas = await persistence.list();
|
|
5461
5484
|
} catch (error) {
|
|
5462
|
-
|
|
5485
|
+
const reason = reasonOf(error);
|
|
5486
|
+
sessionListError = reason;
|
|
5463
5487
|
console.warn("[usage-billing] session list unavailable; serving durable usage ledger:", error);
|
|
5488
|
+
if (options.ledger === void 0 || ledger.size === 0) throw new SessionListUnavailableError(reason, error);
|
|
5464
5489
|
metas = [];
|
|
5465
5490
|
}
|
|
5466
5491
|
let sliceAt = Date.now();
|
|
@@ -5824,7 +5849,8 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5824
5849
|
tool: roles.inputCost * (1 - userShare)
|
|
5825
5850
|
};
|
|
5826
5851
|
})(),
|
|
5827
|
-
...mode === "ledger-only" ? { staleSnapshot: true } : {}
|
|
5852
|
+
...mode === "ledger-only" ? { staleSnapshot: true } : {},
|
|
5853
|
+
...sessionListError === void 0 ? {} : { sessionListError }
|
|
5828
5854
|
};
|
|
5829
5855
|
if (mode === "full") {
|
|
5830
5856
|
lastDoc = document;
|
|
@@ -9442,6 +9468,7 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
9442
9468
|
deps.persistSnapshot(decorate(stats));
|
|
9443
9469
|
}, () => {});
|
|
9444
9470
|
let fresh;
|
|
9471
|
+
let sessionListError;
|
|
9445
9472
|
try {
|
|
9446
9473
|
fresh = await Promise.race([aggregating.then((stats) => stats), new Promise((resolve) => {
|
|
9447
9474
|
setTimeout(() => {
|
|
@@ -9450,16 +9477,19 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
9450
9477
|
})]);
|
|
9451
9478
|
} catch (error) {
|
|
9452
9479
|
console.error("[usage-billing] usage-stats aggregate failed, falling back to snapshot:", error);
|
|
9480
|
+
if (error instanceof SessionListUnavailableError) sessionListError = error.reason;
|
|
9453
9481
|
}
|
|
9454
9482
|
if (fresh !== void 0) {
|
|
9455
9483
|
res.end(statsBodyOf(fresh));
|
|
9456
9484
|
return;
|
|
9457
9485
|
}
|
|
9486
|
+
const degraded = sessionListError === void 0 ? {} : { sessionListError };
|
|
9458
9487
|
const recent = deps.lastDoc?.();
|
|
9459
9488
|
if (recent !== void 0) {
|
|
9460
9489
|
res.end(JSON.stringify({
|
|
9461
9490
|
...decorate(recent),
|
|
9462
|
-
staleSnapshot: true
|
|
9491
|
+
staleSnapshot: true,
|
|
9492
|
+
...degraded
|
|
9463
9493
|
}));
|
|
9464
9494
|
return;
|
|
9465
9495
|
}
|
|
@@ -9468,11 +9498,15 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
9468
9498
|
if (doc === null) continue;
|
|
9469
9499
|
res.end(JSON.stringify({
|
|
9470
9500
|
...decorate(doc),
|
|
9471
|
-
staleSnapshot: true
|
|
9501
|
+
staleSnapshot: true,
|
|
9502
|
+
...degraded
|
|
9472
9503
|
}));
|
|
9473
9504
|
return;
|
|
9474
9505
|
}
|
|
9475
|
-
res.end(JSON.stringify({
|
|
9506
|
+
res.end(JSON.stringify({
|
|
9507
|
+
error: "usage stats unavailable",
|
|
9508
|
+
...degraded
|
|
9509
|
+
}));
|
|
9476
9510
|
}
|
|
9477
9511
|
}), "usage-billing: usage-stats route");
|
|
9478
9512
|
}
|
|
@@ -9490,6 +9524,15 @@ const QUEUE_VERSION = 1;
|
|
|
9490
9524
|
const MAX_TASKS = 100;
|
|
9491
9525
|
const MAX_QUEUED = 50;
|
|
9492
9526
|
const MAX_PROMPT_LENGTH = 32e3;
|
|
9527
|
+
/** 会话 id 长度上限(宿主的 id 是 uuid;超长的入参一律当作没有来源会话)。 */
|
|
9528
|
+
const MAX_SESSION_ID_LENGTH = 200;
|
|
9529
|
+
/** 会话列表读面的超时(毫秒):拿不到就降级新建会话,不让队列卡住。 */
|
|
9530
|
+
const SESSION_LIST_TIMEOUT_MS = 1e4;
|
|
9531
|
+
/** 目录是否落在某个项目内(相等或为其子目录)。 */
|
|
9532
|
+
function isInsideDirectory(cwd, project) {
|
|
9533
|
+
if (project === "") return false;
|
|
9534
|
+
return cwd === project || cwd.startsWith(`${project}/`);
|
|
9535
|
+
}
|
|
9493
9536
|
const LOCK_WAIT_MS = 5e3;
|
|
9494
9537
|
const LEASE_MS = 45e3;
|
|
9495
9538
|
const HEARTBEAT_MS = 15e3;
|
|
@@ -9517,7 +9560,7 @@ function validStoredTask(value) {
|
|
|
9517
9560
|
"running",
|
|
9518
9561
|
"completed",
|
|
9519
9562
|
"failed"
|
|
9520
|
-
].includes(task.status ?? "") && (task.sessionId === void 0 || typeof task.sessionId === "string") && (task.owner === void 0 || typeof task.owner === "string") && (task.leaseUntil === void 0 || typeof task.leaseUntil === "number");
|
|
9563
|
+
].includes(task.status ?? "") && (task.sessionId === void 0 || typeof task.sessionId === "string") && (task.sourceSessionId === void 0 || typeof task.sourceSessionId === "string") && (task.reuseSource === void 0 || typeof task.reuseSource === "boolean") && (task.fallbackReason === void 0 || typeof task.fallbackReason === "string") && (task.owner === void 0 || typeof task.owner === "string") && (task.leaseUntil === void 0 || typeof task.leaseUntil === "number");
|
|
9521
9564
|
}
|
|
9522
9565
|
function publicTask(task) {
|
|
9523
9566
|
const { owner: _owner, leaseUntil: _leaseUntil, ...pub } = task;
|
|
@@ -9628,11 +9671,14 @@ var TaskQueueEngine = class {
|
|
|
9628
9671
|
if (!workspaces.some((workspace) => workspace.path === cwd)) throw new TaskQueueError("workspace is no longer available", 409);
|
|
9629
9672
|
if (typeof provider !== "string" || typeof model !== "string") throw new TaskQueueError("model is required");
|
|
9630
9673
|
if (!models.some((candidate) => candidate.provider === provider && candidate.id === model)) throw new TaskQueueError("select an available DeepSeek time-of-day model", 409);
|
|
9674
|
+
const sourceSessionId = typeof input.sourceSessionId === "string" && input.sourceSessionId.trim() !== "" && input.sourceSessionId.length <= MAX_SESSION_ID_LENGTH ? input.sourceSessionId : void 0;
|
|
9631
9675
|
return {
|
|
9632
9676
|
prompt,
|
|
9633
9677
|
cwd,
|
|
9634
9678
|
provider,
|
|
9635
|
-
model
|
|
9679
|
+
model,
|
|
9680
|
+
sourceSessionId,
|
|
9681
|
+
reuseSource: input.reuseSource === true && sourceSessionId !== void 0
|
|
9636
9682
|
};
|
|
9637
9683
|
} catch (error) {
|
|
9638
9684
|
if (inputs.length > 1 && error instanceof TaskQueueError) throw new TaskQueueError(`task ${String(index + 1)}: ${error.message}`, error.status);
|
|
@@ -9767,11 +9813,21 @@ var TaskQueueEngine = class {
|
|
|
9767
9813
|
await this.requeue(claimed.id);
|
|
9768
9814
|
return;
|
|
9769
9815
|
}
|
|
9770
|
-
const
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9816
|
+
const reuse = await this.resolveSourceSession(claimed, controller);
|
|
9817
|
+
let sessionId;
|
|
9818
|
+
if (reuse.ok) sessionId = reuse.sessionId;
|
|
9819
|
+
else {
|
|
9820
|
+
if (reuse.reason !== void 0) {
|
|
9821
|
+
if (!await this.patch(claimed.id, { fallbackReason: reuse.reason })) return;
|
|
9822
|
+
}
|
|
9823
|
+
const { models: availableModels } = await this.modelOptions(controller, true);
|
|
9824
|
+
if (!availableModels.some((model) => model.provider === claimed.provider && model.id === claimed.model)) throw new TaskQueueError("the selected official DeepSeek model is no longer available", 409);
|
|
9825
|
+
sessionId = (await this.createGroupedSession(controller, claimed.cwd)).sessionId;
|
|
9826
|
+
}
|
|
9827
|
+
const sessionPatch = { sessionId };
|
|
9828
|
+
if (reuse.ok) sessionPatch.fallbackReason = void 0;
|
|
9829
|
+
if (!await this.patch(claimed.id, sessionPatch)) return;
|
|
9830
|
+
if (!reuse.ok) await controller.selectModel({
|
|
9775
9831
|
sessionId,
|
|
9776
9832
|
provider: claimed.provider,
|
|
9777
9833
|
model: claimed.model
|
|
@@ -9810,6 +9866,74 @@ var TaskQueueEngine = class {
|
|
|
9810
9866
|
this.taskAbort = void 0;
|
|
9811
9867
|
}
|
|
9812
9868
|
}
|
|
9869
|
+
/**
|
|
9870
|
+
* issue #118:判断来源会话能否续跑。不能就给出降级原因(写进卡片)。
|
|
9871
|
+
*
|
|
9872
|
+
* 判据来自 issue 的安全边界:来源会话已删除 / 正在跑别的轮次 / 工作区变了时,
|
|
9873
|
+
* 回退为新建会话,不要往用户正在使用的会话里硬塞一轮。另外子智能体会话与
|
|
9874
|
+
* 归档会话也不能复用——前者归属子智能体路由,后者轮次会以 blocked 结束、
|
|
9875
|
+
* 看起来跑了其实没跑。
|
|
9876
|
+
*/
|
|
9877
|
+
async resolveSourceSession(claimed, controller) {
|
|
9878
|
+
if (claimed.reuseSource !== true) return { ok: false };
|
|
9879
|
+
const sourceSessionId = claimed.sourceSessionId;
|
|
9880
|
+
if (sourceSessionId === void 0) return { ok: false };
|
|
9881
|
+
const list = controller.list;
|
|
9882
|
+
if (typeof list !== "function") return {
|
|
9883
|
+
ok: false,
|
|
9884
|
+
reason: "this host cannot inspect Sessions"
|
|
9885
|
+
};
|
|
9886
|
+
let items;
|
|
9887
|
+
try {
|
|
9888
|
+
items = (await list.call(controller, {}, AbortSignal.timeout(SESSION_LIST_TIMEOUT_MS)))?.items ?? [];
|
|
9889
|
+
} catch (error) {
|
|
9890
|
+
return {
|
|
9891
|
+
ok: false,
|
|
9892
|
+
reason: `source session lookup failed: ${messageOf(error)}`
|
|
9893
|
+
};
|
|
9894
|
+
}
|
|
9895
|
+
const summary = items.find((item) => item.sessionId === sourceSessionId);
|
|
9896
|
+
if (summary === void 0) return {
|
|
9897
|
+
ok: false,
|
|
9898
|
+
reason: "source session no longer exists"
|
|
9899
|
+
};
|
|
9900
|
+
if (summary.origin === "subagent") return {
|
|
9901
|
+
ok: false,
|
|
9902
|
+
reason: "source session belongs to a subagent"
|
|
9903
|
+
};
|
|
9904
|
+
const archived = this.options.getWorkspaceContext?.()?.archivedSessionIds;
|
|
9905
|
+
if (archived !== void 0 && archived.includes(sourceSessionId)) return {
|
|
9906
|
+
ok: false,
|
|
9907
|
+
reason: "source session is archived"
|
|
9908
|
+
};
|
|
9909
|
+
if (summary.running === true) return {
|
|
9910
|
+
ok: false,
|
|
9911
|
+
reason: "source session is busy"
|
|
9912
|
+
};
|
|
9913
|
+
const project = typeof summary.cwd === "string" ? summary.cwd : void 0;
|
|
9914
|
+
if (project !== void 0 && !isInsideDirectory(claimed.cwd, project)) return {
|
|
9915
|
+
ok: false,
|
|
9916
|
+
reason: "source session working directory changed"
|
|
9917
|
+
};
|
|
9918
|
+
return {
|
|
9919
|
+
ok: true,
|
|
9920
|
+
sessionId: sourceSessionId
|
|
9921
|
+
};
|
|
9922
|
+
}
|
|
9923
|
+
/**
|
|
9924
|
+
* 新建会话:cwd 恰好等于某个工作区时用 create({ workspaceId }),让宿主把会话挂进
|
|
9925
|
+
* 该工作区——create({ cwd }) 从不归组,这正是队列会话在侧栏里没有分组的原因。
|
|
9926
|
+
* 两者互斥:带 workspaceId 时不能再带 cwd。
|
|
9927
|
+
*/
|
|
9928
|
+
async createGroupedSession(controller, cwd) {
|
|
9929
|
+
const workspaceId = this.options.getWorkspaceContext?.()?.workspaceIdOfPath(cwd);
|
|
9930
|
+
if (workspaceId !== void 0) try {
|
|
9931
|
+
return await controller.create({ workspaceId });
|
|
9932
|
+
} catch (error) {
|
|
9933
|
+
console.warn("[usage-billing] task queue workspace Session creation failed:", error);
|
|
9934
|
+
}
|
|
9935
|
+
return await controller.create({ cwd });
|
|
9936
|
+
}
|
|
9813
9937
|
async watch(frames, requestId) {
|
|
9814
9938
|
let admitted = false;
|
|
9815
9939
|
for await (const raw of frames) {
|
|
@@ -9847,7 +9971,8 @@ var TaskQueueEngine = class {
|
|
|
9847
9971
|
owner: void 0,
|
|
9848
9972
|
leaseUntil: void 0,
|
|
9849
9973
|
startedAt: void 0,
|
|
9850
|
-
sessionId: void 0
|
|
9974
|
+
sessionId: void 0,
|
|
9975
|
+
fallbackReason: void 0
|
|
9851
9976
|
});
|
|
9852
9977
|
}
|
|
9853
9978
|
async finish(id, status, error) {
|
|
@@ -10627,7 +10752,8 @@ function apply(ctx, config = {}) {
|
|
|
10627
10752
|
const now = Date.now();
|
|
10628
10753
|
if (now - lastSnapshotAt < SNAPSHOT_INTERVAL_MS) return;
|
|
10629
10754
|
lastSnapshotAt = now;
|
|
10630
|
-
const
|
|
10755
|
+
const { sessionListError: _liveError, ...data } = doc;
|
|
10756
|
+
const payload = JSON.stringify(data);
|
|
10631
10757
|
(async () => {
|
|
10632
10758
|
try {
|
|
10633
10759
|
const existing = await readFile(snapshotPath, "utf8");
|
|
@@ -10679,6 +10805,20 @@ function apply(ctx, config = {}) {
|
|
|
10679
10805
|
} catch {
|
|
10680
10806
|
return [];
|
|
10681
10807
|
}
|
|
10808
|
+
},
|
|
10809
|
+
getWorkspaceContext: () => {
|
|
10810
|
+
try {
|
|
10811
|
+
const registry = ctx.get("workspaceRegistry");
|
|
10812
|
+
if (registry === void 0) return void 0;
|
|
10813
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
10814
|
+
for (const workspace of registry.list?.() ?? []) if (typeof workspace.path === "string" && workspace.path !== "" && typeof workspace.id === "string") byPath.set(workspace.path, workspace.id);
|
|
10815
|
+
return {
|
|
10816
|
+
archivedSessionIds: registry.archivedSessionIds ?? [],
|
|
10817
|
+
workspaceIdOfPath: (path) => byPath.get(path)
|
|
10818
|
+
};
|
|
10819
|
+
} catch {
|
|
10820
|
+
return;
|
|
10821
|
+
}
|
|
10682
10822
|
}
|
|
10683
10823
|
});
|
|
10684
10824
|
registerTaskQueueRoute(ctx, {
|
package/lib/types/aggregate.d.ts
CHANGED
|
@@ -365,6 +365,12 @@ export interface UsageStatsDocument {
|
|
|
365
365
|
* (issue #103 加的 staleSnapshot 通道,此前无生产方),零新增客户端体积。
|
|
366
366
|
*/
|
|
367
367
|
staleSnapshot?: boolean;
|
|
368
|
+
/**
|
|
369
|
+
* 会话列表整体读不到时的降级原因(issue #119):目录里有读不了/对不上的
|
|
370
|
+
* 日志、宿主后端临时故障等。此时本档数字全部出自持久账本(可能是空),
|
|
371
|
+
* 客户端据此显示「读取失败」,而不是把空账本当成「没有用量」。
|
|
372
|
+
*/
|
|
373
|
+
sessionListError?: string;
|
|
368
374
|
}
|
|
369
375
|
/** 按角色费用归因:user / tool 为输入成本的启发式摊分,assistant 为输出成本实测。 */
|
|
370
376
|
export interface RoleCost {
|
|
@@ -801,6 +807,17 @@ export interface SessionUsageSummary {
|
|
|
801
807
|
* 判定函数无法序列化,统一记为 `fn`(任何函数形态互视为同一指纹)。
|
|
802
808
|
*/
|
|
803
809
|
export declare function configFingerprint(subscriptionMatcher: SubscriptionMatcher, officialProviderIds: ReadonlySet<string> | undefined, routeAliases: Readonly<Record<string, string>>, searchEstimate: number, modelKeyAliases?: Readonly<Record<string, string>>, registeredProviders?: ReadonlySet<string>, routeOrigins?: Readonly<Record<string, string>>): string;
|
|
810
|
+
/**
|
|
811
|
+
* 会话列表整体读不到(issue #119):宿主持久化后端整体故障,或会话目录里有
|
|
812
|
+
* 读不了/对不上的日志。聚合无法枚举会话,只能降级到持久账本或磁盘快照——
|
|
813
|
+
* 但「降级」必须让用户看得见,否则新装用户看到的是一片 ¥0(分不清没花钱
|
|
814
|
+
* 还是没读到)。携带原因随文档下发,客户端据此显示「读取失败」。
|
|
815
|
+
*/
|
|
816
|
+
export declare class SessionListUnavailableError extends Error {
|
|
817
|
+
/** 失败原因摘要(面向用户的中文/英文提示语,由调用方决定措辞)。 */
|
|
818
|
+
readonly reason: string;
|
|
819
|
+
constructor(reason: string, cause?: unknown);
|
|
820
|
+
}
|
|
804
821
|
/**
|
|
805
822
|
* Create the incremental usage aggregator.
|
|
806
823
|
* @param persistence - the session persistence service.
|
|
@@ -6,6 +6,10 @@ interface TaskQueuePanelProps {
|
|
|
6
6
|
readonly t: (key: UsageBillingKey, params?: Record<string, unknown>) => string;
|
|
7
7
|
readonly language: BillingLanguage;
|
|
8
8
|
readonly navigateToSession: (sessionId: string) => 'opened' | 'unavailable' | 'failed';
|
|
9
|
+
/** 会话标题(issue #118):卡片显示「将在会话 X 继续」;取不到就显示 id 短码。 */
|
|
10
|
+
readonly sessionTitleOf?: (sessionId: string) => string | undefined;
|
|
11
|
+
/** 「在来源会话继续」开关当前状态:决定安全提示文案。 */
|
|
12
|
+
readonly reuseSourceSession?: boolean;
|
|
9
13
|
}
|
|
10
14
|
interface ImportDefaults {
|
|
11
15
|
readonly cwd: string;
|
|
@@ -14,6 +18,6 @@ interface ImportDefaults {
|
|
|
14
18
|
}
|
|
15
19
|
/** Normalize only the transport shape; authoritative validation stays atomic on the server. */
|
|
16
20
|
export declare function parseTaskQueueImport(text: string, defaults: ImportDefaults): TaskQueueInput[];
|
|
17
|
-
export declare function TaskQueuePanel({ t, language, navigateToSession }: TaskQueuePanelProps): React.ReactNode;
|
|
21
|
+
export declare function TaskQueuePanel({ t, language, navigateToSession, sessionTitleOf, reuseSourceSession }: TaskQueuePanelProps): React.ReactNode;
|
|
18
22
|
export {};
|
|
19
23
|
//# sourceMappingURL=TaskQueuePanel.d.ts.map
|
|
@@ -8,6 +8,10 @@ export type TaskQueueAction = {
|
|
|
8
8
|
cwd: string;
|
|
9
9
|
provider: string;
|
|
10
10
|
model: string;
|
|
11
|
+
/** 来源会话(issue #118):入队时所在的会话。 */
|
|
12
|
+
sourceSessionId?: string;
|
|
13
|
+
/** 是否授权在该来源会话内续跑(入队时冻结的开关状态)。 */
|
|
14
|
+
reuseSource?: boolean;
|
|
11
15
|
} | {
|
|
12
16
|
action: 'enqueueMany';
|
|
13
17
|
tasks: readonly TaskQueueInput[];
|
|
@@ -2,10 +2,24 @@
|
|
|
2
2
|
* GET /api/billing/usage-stats:服务端聚合文档(含 byDay/byModel/bySession/...)。
|
|
3
3
|
* 旧快照可能缺字段(聚合升级前落盘),解析时按字段白名单接受并兜底——避免
|
|
4
4
|
* 渲染路径读 undefined 抛错导致整个插件 surface 被卸载。
|
|
5
|
+
*
|
|
6
|
+
* 取数失败不再吞成空文档(issue #119):此前任何失败(非 2xx / 非 JSON /
|
|
7
|
+
* 超时)都返回 null,面板于是把「没取到」渲染成「用量是 0」——用户看到一片
|
|
8
|
+
* ¥0 却无从判断是没用还是没读到。现在失败带着原因(服务端错误文案 / HTTP
|
|
9
|
+
* 状态 / 异常信息)返回,由界面显示成错误态。
|
|
5
10
|
*/
|
|
6
11
|
import type { UsageStats } from '../domain/types.ts';
|
|
7
12
|
/** Path to the usage-stats endpoint served by this plugin's node half. */
|
|
8
13
|
export declare const USAGE_STATS_PATH = "/api/billing/usage-stats";
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
14
|
+
/** 取数结果:成功带文档;失败带可展示的原因。 */
|
|
15
|
+
export type UsageStatsLoad = {
|
|
16
|
+
ok: true;
|
|
17
|
+
stats: UsageStats;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
reason: string;
|
|
21
|
+
status?: number;
|
|
22
|
+
};
|
|
23
|
+
/** 取统计文档;失败时带原因(不再静默返回 null)。 */
|
|
24
|
+
export declare function loadUsageStats(): Promise<UsageStatsLoad>;
|
|
11
25
|
//# sourceMappingURL=usage-stats.d.ts.map
|
|
@@ -158,6 +158,11 @@ export interface UsageBillingInjected {
|
|
|
158
158
|
* 返回 'opened' 已跳转 / 'unavailable' 宿主无通道(老到没有)/ 'failed' 通道报错。
|
|
159
159
|
*/
|
|
160
160
|
navigateToSession: (sessionId: string) => 'opened' | 'unavailable' | 'failed';
|
|
161
|
+
/**
|
|
162
|
+
* 会话标题(issue #118):队列卡片显示「将在会话 X 继续」时用。取不到时返回
|
|
163
|
+
* undefined,界面退化为会话 id 短码——不编造标题。
|
|
164
|
+
*/
|
|
165
|
+
sessionTitleOf: (sessionId: string) => string | undefined;
|
|
161
166
|
}
|
|
162
167
|
/** Usage stats structure from `.dsh-usage-stats.json`. */
|
|
163
168
|
export interface UsageStats {
|
|
@@ -169,6 +174,11 @@ export interface UsageStats {
|
|
|
169
174
|
* 避免把旧值(如重命名前的会话标题)当成最新值读。
|
|
170
175
|
*/
|
|
171
176
|
staleSnapshot?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* 会话列表整体读不到时的降级原因(issue #119):本档数字全部出自持久账本
|
|
179
|
+
* (可能是空)。面板据此显示「读取失败」,而不是把空账本当成「没有用量」。
|
|
180
|
+
*/
|
|
181
|
+
sessionListError?: string;
|
|
172
182
|
/** 宿主进程时区(IANA 名 + UTC 偏移):天按此切分,副标题据此标注;旧快照可能缺失。 */
|
|
173
183
|
timezone?: {
|
|
174
184
|
name: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Locale dictionaries for the usage billing surface. */
|
|
2
|
-
export type UsageBillingKey = 'title' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'monthProjectedHint' | 'liveTurn' | 'liveSession' | 'liveSessionSub' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'kpiRange' | 'avgRangeToday' | 'avgRange7d' | 'avgRangeWeek' | 'avgRangeMonth' | 'avgRangeAll' | 'avgRangeCustom' | 'customRangeStart' | 'customRangeEnd' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'pricingSearch' | 'bandPinHint' | 'trendEmpty' | 'trendTotal' | 'roundsUnit' | 'healthModelsLive' | 'healthVendorsDown' | 'healthVendorsUnavailable' | 'budget' | 'budgetRemain' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'channelUnknown' | 'directTag' | 'relayTag' | 'unknownTag' | 'unknownChannelHint' | 'planCountUnit' | 'actual' | 'pricing' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'band' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'pricingSyncedAt' | 'pricingSyncNow' | 'pricingSyncing' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'recharge' | 'rechargeHint' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatPrimaryToday' | 'floatPrimaryWeek' | 'floatPrimaryMonth' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMode' | 'cardModeFull' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'cardSpan' | 'cardSpanDay' | 'cardSpanWeek' | 'cardSpanMonth' | 'cardDeltaBadge' | 'cardDeltaShow' | 'cardDeltaHide' | 'triggerMonthTokens' | 'triggerTodayTokens' | 'triggerWeekTokens' | 'subscriptionsStale' | 'balanceStaleNotice' | 'staleLedgerNotice' | 'staleSnapshotNotice' | 'unreadableNotice' | 'unreadableFormatNotice' | 'unreadableNoLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceOffPeak' | 'userPriceNormal' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemoveSelected' | 'userPriceSelect' | 'sessionStaleBadge' | 'sessionUntitled' | 'sessionSubCost' | 'sessionSubCalls' | 'sessionSubRow' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'currencyEur' | 'language' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabPricing' | 'tabSettings' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'peakAlertDescPeakZhipu' | 'peakAlertDescOffZhipu' | 'peakAlertQueuePeak' | 'peakAlertQueueOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'tierAlertEnterPeakZhipu' | 'tierAlertEnterOffZhipu' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionTag' | 'cellEstimateHint' | 'free' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'perfAll' | 'perfChartEmpty' | 'heatmapYear' | 'heatmapHalf' | 'heatmapMonth' | 'metricCost' | 'metricTokens' | 'heatmapTotal' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'densityLabel' | 'densityHint' | 'densityCompact' | 'densityDefault' | 'densityComfortable' | 'motionLabel' | 'motionHint' | 'motionOff' | 'motionSubtle' | 'motionRich' | 'settingsNavDisplayPref' | 'settingsNavBudget' | 'settingsNavAlert' | 'settingsNavDisplay' | 'settingsNavAdvanced' | 'settingsNavAbout' | 'settingsSearchPlaceholder' | 'settingsSearchEmpty' | 'sessionsViewAll' | 'sessionViewerSearch' | 'modelBudgetTitle' | 'modelBudgetHint' | 'modelBudgetBody' | 'modelBudgetPlaceholder' | 'moreWorksTitle' | 'adEngramName' | 'adEngramDesc' | 'adRainbowName' | 'adRainbowDesc' | 'kpiDescCacheHit' | 'kpiDescTokens' | 'kpiDescAvgCost' | 'kpiDescCalls' | 'kpiDescReasoning' | 'kpiDescIo' | 'kpiDescPeak' | 'healthDotLive' | 'healthDotFailed' | 'healthDotUnknown' | 'settingsSectionDisplay' | 'emptyHint' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenViewStructure' | 'tokenViewModel' | 'tokenHitShort' | 'tokenMissShort' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'unpricedHint' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'liveCostBar' | 'liveCostBarHint' | 'liveCostBarPosition' | 'liveCostBarPosBelow' | 'liveCostBarPosAbove' | 'liveCostBarPosToolbar' | 'exportCsvSite' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'expandAll' | 'collapseAll' | 'todayOnly' | 'todayNoConsumption' | 'commandUsageLabel' | 'commandUsageDescription' | 'sessionOpen' | 'sessionOpenFailed' | 'sessionOpenUnavailable' | 'tabAgents' | 'tabQueue' | 'queueSubtitle' | 'queueUntilPeak' | 'queueUntilOffPeak' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queuePromptLabel' | 'queuePromptPlaceholder' | 'queuePrivacy' | 'queueEnqueue' | 'queueImport' | 'queueImportHint' | 'queueImported' | 'queueImportFormat' | 'queueImportTooLarge' | 'queueActive' | 'queueClearFinished' | 'queueEmpty' | 'queueLoading' | 'queueOpenSession' | 'queueRemoveQueued' | 'queueRemoveHistory' | 'queueStatusQueued' | 'queueStatusStarting' | 'queueStatusRunning' | 'queueStatusCompleted' | 'queueStatusFailed' | 'quickQueueToggle' | 'quickQueueEntry' | 'quickQueueEntryHint' | 'quickQueueEnqueue' | 'quickQueueEnqueueing' | 'quickQueueWaiting' | 'quickQueueClear' | 'quickQueueEnqueued' | 'quickQueueEmpty' | 'quickQueueBusy' | 'quickQueueAttachments' | 'quickQueueContext' | 'quickQueueRoute' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
|
|
2
|
+
export type UsageBillingKey = 'title' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'monthProjectedHint' | 'liveTurn' | 'liveSession' | 'liveSessionSub' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'kpiRange' | 'avgRangeToday' | 'avgRange7d' | 'avgRangeWeek' | 'avgRangeMonth' | 'avgRangeAll' | 'avgRangeCustom' | 'customRangeStart' | 'customRangeEnd' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'pricingSearch' | 'bandPinHint' | 'trendEmpty' | 'trendTotal' | 'roundsUnit' | 'healthModelsLive' | 'healthVendorsDown' | 'healthVendorsUnavailable' | 'budget' | 'budgetRemain' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'channelUnknown' | 'directTag' | 'relayTag' | 'unknownTag' | 'unknownChannelHint' | 'planCountUnit' | 'actual' | 'pricing' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'band' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'pricingSyncedAt' | 'pricingSyncNow' | 'pricingSyncing' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'recharge' | 'rechargeHint' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatPrimaryToday' | 'floatPrimaryWeek' | 'floatPrimaryMonth' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMode' | 'cardModeFull' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'cardSpan' | 'cardSpanDay' | 'cardSpanWeek' | 'cardSpanMonth' | 'cardDeltaBadge' | 'cardDeltaShow' | 'cardDeltaHide' | 'triggerMonthTokens' | 'triggerTodayTokens' | 'triggerWeekTokens' | 'subscriptionsStale' | 'balanceStaleNotice' | 'staleLedgerNotice' | 'staleSnapshotNotice' | 'statsLoadFailed' | 'unreadableNotice' | 'unreadableFormatNotice' | 'unreadableNoLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceOffPeak' | 'userPriceNormal' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemoveSelected' | 'userPriceSelect' | 'sessionStaleBadge' | 'sessionUntitled' | 'sessionSubCost' | 'sessionSubCalls' | 'sessionSubRow' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'currencyEur' | 'language' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabPricing' | 'tabSettings' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'peakAlertDescPeakZhipu' | 'peakAlertDescOffZhipu' | 'peakAlertQueuePeak' | 'peakAlertQueueOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'tierAlertEnterPeakZhipu' | 'tierAlertEnterOffZhipu' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionTag' | 'cellEstimateHint' | 'free' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'perfAll' | 'perfChartEmpty' | 'heatmapYear' | 'heatmapHalf' | 'heatmapMonth' | 'metricCost' | 'metricTokens' | 'heatmapTotal' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'densityLabel' | 'densityHint' | 'densityCompact' | 'densityDefault' | 'densityComfortable' | 'motionLabel' | 'motionHint' | 'motionOff' | 'motionSubtle' | 'motionRich' | 'settingsNavDisplayPref' | 'settingsNavBudget' | 'settingsNavAlert' | 'settingsNavDisplay' | 'settingsNavAdvanced' | 'settingsNavAbout' | 'settingsSearchPlaceholder' | 'settingsSearchEmpty' | 'sessionsViewAll' | 'sessionViewerSearch' | 'modelBudgetTitle' | 'modelBudgetHint' | 'modelBudgetBody' | 'modelBudgetPlaceholder' | 'moreWorksTitle' | 'adEngramName' | 'adEngramDesc' | 'adRainbowName' | 'adRainbowDesc' | 'kpiDescCacheHit' | 'kpiDescTokens' | 'kpiDescAvgCost' | 'kpiDescCalls' | 'kpiDescReasoning' | 'kpiDescIo' | 'kpiDescPeak' | 'healthDotLive' | 'healthDotFailed' | 'healthDotUnknown' | 'settingsSectionDisplay' | 'emptyHint' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenViewStructure' | 'tokenViewModel' | 'tokenHitShort' | 'tokenMissShort' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'unpricedHint' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'liveCostBar' | 'liveCostBarHint' | 'liveCostBarPosition' | 'liveCostBarPosBelow' | 'liveCostBarPosAbove' | 'liveCostBarPosToolbar' | 'exportCsvSite' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'expandAll' | 'collapseAll' | 'todayOnly' | 'todayNoConsumption' | 'commandUsageLabel' | 'commandUsageDescription' | 'sessionOpen' | 'sessionOpenFailed' | 'sessionOpenUnavailable' | 'tabAgents' | 'tabQueue' | 'queueSubtitle' | 'queueUntilPeak' | 'queueUntilOffPeak' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueSafetyIsolated' | 'queueSafetyReuse' | 'queueReusePlanned' | 'queueReuseDone' | 'queueFallbackReason' | 'queueReuseModelNote' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queuePromptLabel' | 'queuePromptPlaceholder' | 'queuePrivacy' | 'queueEnqueue' | 'queueImport' | 'queueImportHint' | 'queueImported' | 'queueImportFormat' | 'queueImportTooLarge' | 'queueActive' | 'queueClearFinished' | 'queueEmpty' | 'queueLoading' | 'queueOpenSession' | 'queueRemoveQueued' | 'queueRemoveHistory' | 'queueStatusQueued' | 'queueStatusStarting' | 'queueStatusRunning' | 'queueStatusCompleted' | 'queueStatusFailed' | 'quickQueueToggle' | 'quickQueueEntry' | 'quickQueueEntryHint' | 'quickQueueReuseEntry' | 'quickQueueReuseEntryHint' | 'quickQueueEnqueue' | 'quickQueueEnqueueing' | 'quickQueueWaiting' | 'quickQueueClear' | 'quickQueueEnqueued' | 'quickQueueEmpty' | 'quickQueueBusy' | 'quickQueueAttachments' | 'quickQueueContext' | 'quickQueueRoute' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
|
|
3
3
|
export declare const NS = "usageBilling";
|
|
4
4
|
export declare const zh: Record<UsageBillingKey, string>;
|
|
5
5
|
export declare const en: Record<UsageBillingKey, string>;
|
|
@@ -279,6 +279,15 @@ export interface QuickQueuePrefs {
|
|
|
279
279
|
* touched the setting.
|
|
280
280
|
*/
|
|
281
281
|
showEntry: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Run a queued task inside the Session it was queued from (issue #118).
|
|
284
|
+
*
|
|
285
|
+
* Off keeps every task in its own Session. On prefers continuing in the
|
|
286
|
+
* source Session — same context, same workspace grouping — and falls back to
|
|
287
|
+
* a new Session when the source is gone, busy or archived. Default off: the
|
|
288
|
+
* isolated-Session design is the safe default.
|
|
289
|
+
*/
|
|
290
|
+
reuseSourceSession: boolean;
|
|
282
291
|
}
|
|
283
292
|
export declare const DEFAULT_QUICK_QUEUE_PREFS: QuickQueuePrefs;
|
|
284
293
|
export declare const QUICK_QUEUE_STORAGE_KEY = "dsh.ui-usage-billing.quick-queue";
|
|
@@ -6,6 +6,10 @@ export interface TaskQueueInput {
|
|
|
6
6
|
readonly cwd?: unknown;
|
|
7
7
|
readonly provider?: unknown;
|
|
8
8
|
readonly model?: unknown;
|
|
9
|
+
/** 来源会话(issue #118):入队时所在的会话,执行期据此续跑。 */
|
|
10
|
+
readonly sourceSessionId?: unknown;
|
|
11
|
+
/** 入队时是否授权复用来源会话(把设置开关的状态冻结进任务)。 */
|
|
12
|
+
readonly reuseSource?: unknown;
|
|
9
13
|
}
|
|
10
14
|
export interface TaskQueueTask {
|
|
11
15
|
readonly id: string;
|
|
@@ -17,7 +21,14 @@ export interface TaskQueueTask {
|
|
|
17
21
|
readonly createdAt: number;
|
|
18
22
|
readonly startedAt?: number | undefined;
|
|
19
23
|
readonly finishedAt?: number | undefined;
|
|
24
|
+
/** 实际执行任务的会话(复用来源会话时等于 sourceSessionId)。 */
|
|
20
25
|
readonly sessionId?: string | undefined;
|
|
26
|
+
/** 来源会话 id(issue #118):入队时所在的会话。 */
|
|
27
|
+
readonly sourceSessionId?: string | undefined;
|
|
28
|
+
/** 是否授权在该来源会话内续跑(入队时冻结的开关状态)。 */
|
|
29
|
+
readonly reuseSource?: boolean | undefined;
|
|
30
|
+
/** 从「续跑来源会话」降级为「新建会话」的原因(卡片展示)。 */
|
|
31
|
+
readonly fallbackReason?: string | undefined;
|
|
21
32
|
readonly error?: string | undefined;
|
|
22
33
|
}
|
|
23
34
|
export interface TaskQueueWorkspace {
|
|
@@ -9,11 +9,34 @@
|
|
|
9
9
|
import type { SessionController } from '@deepseek-ai/dsh-api-session-controller';
|
|
10
10
|
import type { TaskQueueInput, TaskQueueSnapshot, TaskQueueSummary, TaskQueueWorkspace } from './task-queue-shared.ts';
|
|
11
11
|
export type TaskQueueController = Pick<SessionController, 'create' | 'selectModel' | 'prompt' | 'follow' | 'modelCatalog'>;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 会话列表读面(可选能力,issue #118):复用来源会话前用它校验该会话是否仍可用
|
|
14
|
+
* (存在 / 非子智能体 / 空闲 / 项目未变)。**缺席不降级整个队列**——只是复用
|
|
15
|
+
* 路径不可用,任务一律走新建会话。
|
|
16
|
+
*/
|
|
17
|
+
export type TaskQueueSessionLister = Pick<SessionController, 'list'>;
|
|
18
|
+
/** 引擎看到的宿主会话控制面:基本 5 方法必备,list 可选。 */
|
|
19
|
+
export type TaskQueueControllerFace = TaskQueueController & Partial<TaskQueueSessionLister>;
|
|
20
|
+
/**
|
|
21
|
+
* 工作区上下文(可选能力):新建会话归组 + 来源会话归档判定。宿主没有这个服务
|
|
22
|
+
* 时一律降级(不归组、归档不可判),队列其余行为不变。
|
|
23
|
+
*/
|
|
24
|
+
export interface TaskQueueWorkspaceContext {
|
|
25
|
+
/** 已归档的会话 id:归档会话的轮次会以 blocked 结束,不会真的跑。 */
|
|
26
|
+
readonly archivedSessionIds: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* 路径 → 工作区 id。**必须严格相等**:宿主的成员资格规则是「account slot +
|
|
29
|
+
* canonical cwd 严格等于工作区 path」,前缀匹配不算数——本仓计费口径里的子目录
|
|
30
|
+
* 前缀匹配只用于账单归组,不能拿来给会话归组。
|
|
31
|
+
*/
|
|
32
|
+
readonly workspaceIdOfPath: (path: string) => string | undefined;
|
|
33
|
+
}
|
|
13
34
|
export interface TaskQueueEngineOptions {
|
|
14
35
|
readonly filePath: string;
|
|
15
|
-
readonly getController: () =>
|
|
36
|
+
readonly getController: () => TaskQueueControllerFace | undefined;
|
|
16
37
|
readonly getWorkspaces: () => readonly TaskQueueWorkspace[];
|
|
38
|
+
/** 工作区上下文(可选):缺席 → 不归组、复用路径不可用。 */
|
|
39
|
+
readonly getWorkspaceContext?: () => TaskQueueWorkspaceContext | undefined;
|
|
17
40
|
readonly now?: () => number;
|
|
18
41
|
readonly createId?: () => string;
|
|
19
42
|
readonly ownerId?: string;
|
|
@@ -50,6 +73,21 @@ export declare class TaskQueueEngine {
|
|
|
50
73
|
private claimNext;
|
|
51
74
|
private recoverExpired;
|
|
52
75
|
private execute;
|
|
76
|
+
/**
|
|
77
|
+
* issue #118:判断来源会话能否续跑。不能就给出降级原因(写进卡片)。
|
|
78
|
+
*
|
|
79
|
+
* 判据来自 issue 的安全边界:来源会话已删除 / 正在跑别的轮次 / 工作区变了时,
|
|
80
|
+
* 回退为新建会话,不要往用户正在使用的会话里硬塞一轮。另外子智能体会话与
|
|
81
|
+
* 归档会话也不能复用——前者归属子智能体路由,后者轮次会以 blocked 结束、
|
|
82
|
+
* 看起来跑了其实没跑。
|
|
83
|
+
*/
|
|
84
|
+
private resolveSourceSession;
|
|
85
|
+
/**
|
|
86
|
+
* 新建会话:cwd 恰好等于某个工作区时用 create({ workspaceId }),让宿主把会话挂进
|
|
87
|
+
* 该工作区——create({ cwd }) 从不归组,这正是队列会话在侧栏里没有分组的原因。
|
|
88
|
+
* 两者互斥:带 workspaceId 时不能再带 cwd。
|
|
89
|
+
*/
|
|
90
|
+
private createGroupedSession;
|
|
53
91
|
private watch;
|
|
54
92
|
private renewLease;
|
|
55
93
|
private requeue;
|
|
@@ -59,5 +97,4 @@ export declare class TaskQueueEngine {
|
|
|
59
97
|
private readDocument;
|
|
60
98
|
private readDocumentWithRaw;
|
|
61
99
|
}
|
|
62
|
-
export {};
|
|
63
100
|
//# sourceMappingURL=task-queue.d.ts.map
|