@kenz1117/dsh-ui-usage-billing 1.8.3-alpha.2 → 1.8.3-alpha.3
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 -7
- package/README.md +7 -7
- package/lib/client.js +5 -5
- package/lib/index.js +113 -8
- package/lib/types/client/TaskQueuePanel.d.ts +5 -1
- package/lib/types/client/api/task-queue.d.ts +4 -0
- package/lib/types/client/domain/types.d.ts +5 -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 +1 -1
package/lib/index.js
CHANGED
|
@@ -9490,6 +9490,15 @@ const QUEUE_VERSION = 1;
|
|
|
9490
9490
|
const MAX_TASKS = 100;
|
|
9491
9491
|
const MAX_QUEUED = 50;
|
|
9492
9492
|
const MAX_PROMPT_LENGTH = 32e3;
|
|
9493
|
+
/** 会话 id 长度上限(宿主的 id 是 uuid;超长的入参一律当作没有来源会话)。 */
|
|
9494
|
+
const MAX_SESSION_ID_LENGTH = 200;
|
|
9495
|
+
/** 会话列表读面的超时(毫秒):拿不到就降级新建会话,不让队列卡住。 */
|
|
9496
|
+
const SESSION_LIST_TIMEOUT_MS = 1e4;
|
|
9497
|
+
/** 目录是否落在某个项目内(相等或为其子目录)。 */
|
|
9498
|
+
function isInsideDirectory(cwd, project) {
|
|
9499
|
+
if (project === "") return false;
|
|
9500
|
+
return cwd === project || cwd.startsWith(`${project}/`);
|
|
9501
|
+
}
|
|
9493
9502
|
const LOCK_WAIT_MS = 5e3;
|
|
9494
9503
|
const LEASE_MS = 45e3;
|
|
9495
9504
|
const HEARTBEAT_MS = 15e3;
|
|
@@ -9517,7 +9526,7 @@ function validStoredTask(value) {
|
|
|
9517
9526
|
"running",
|
|
9518
9527
|
"completed",
|
|
9519
9528
|
"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");
|
|
9529
|
+
].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
9530
|
}
|
|
9522
9531
|
function publicTask(task) {
|
|
9523
9532
|
const { owner: _owner, leaseUntil: _leaseUntil, ...pub } = task;
|
|
@@ -9628,11 +9637,14 @@ var TaskQueueEngine = class {
|
|
|
9628
9637
|
if (!workspaces.some((workspace) => workspace.path === cwd)) throw new TaskQueueError("workspace is no longer available", 409);
|
|
9629
9638
|
if (typeof provider !== "string" || typeof model !== "string") throw new TaskQueueError("model is required");
|
|
9630
9639
|
if (!models.some((candidate) => candidate.provider === provider && candidate.id === model)) throw new TaskQueueError("select an available DeepSeek time-of-day model", 409);
|
|
9640
|
+
const sourceSessionId = typeof input.sourceSessionId === "string" && input.sourceSessionId.trim() !== "" && input.sourceSessionId.length <= MAX_SESSION_ID_LENGTH ? input.sourceSessionId : void 0;
|
|
9631
9641
|
return {
|
|
9632
9642
|
prompt,
|
|
9633
9643
|
cwd,
|
|
9634
9644
|
provider,
|
|
9635
|
-
model
|
|
9645
|
+
model,
|
|
9646
|
+
sourceSessionId,
|
|
9647
|
+
reuseSource: input.reuseSource === true && sourceSessionId !== void 0
|
|
9636
9648
|
};
|
|
9637
9649
|
} catch (error) {
|
|
9638
9650
|
if (inputs.length > 1 && error instanceof TaskQueueError) throw new TaskQueueError(`task ${String(index + 1)}: ${error.message}`, error.status);
|
|
@@ -9767,11 +9779,21 @@ var TaskQueueEngine = class {
|
|
|
9767
9779
|
await this.requeue(claimed.id);
|
|
9768
9780
|
return;
|
|
9769
9781
|
}
|
|
9770
|
-
const
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9782
|
+
const reuse = await this.resolveSourceSession(claimed, controller);
|
|
9783
|
+
let sessionId;
|
|
9784
|
+
if (reuse.ok) sessionId = reuse.sessionId;
|
|
9785
|
+
else {
|
|
9786
|
+
if (reuse.reason !== void 0) {
|
|
9787
|
+
if (!await this.patch(claimed.id, { fallbackReason: reuse.reason })) return;
|
|
9788
|
+
}
|
|
9789
|
+
const { models: availableModels } = await this.modelOptions(controller, true);
|
|
9790
|
+
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);
|
|
9791
|
+
sessionId = (await this.createGroupedSession(controller, claimed.cwd)).sessionId;
|
|
9792
|
+
}
|
|
9793
|
+
const sessionPatch = { sessionId };
|
|
9794
|
+
if (reuse.ok) sessionPatch.fallbackReason = void 0;
|
|
9795
|
+
if (!await this.patch(claimed.id, sessionPatch)) return;
|
|
9796
|
+
if (!reuse.ok) await controller.selectModel({
|
|
9775
9797
|
sessionId,
|
|
9776
9798
|
provider: claimed.provider,
|
|
9777
9799
|
model: claimed.model
|
|
@@ -9810,6 +9832,74 @@ var TaskQueueEngine = class {
|
|
|
9810
9832
|
this.taskAbort = void 0;
|
|
9811
9833
|
}
|
|
9812
9834
|
}
|
|
9835
|
+
/**
|
|
9836
|
+
* issue #118:判断来源会话能否续跑。不能就给出降级原因(写进卡片)。
|
|
9837
|
+
*
|
|
9838
|
+
* 判据来自 issue 的安全边界:来源会话已删除 / 正在跑别的轮次 / 工作区变了时,
|
|
9839
|
+
* 回退为新建会话,不要往用户正在使用的会话里硬塞一轮。另外子智能体会话与
|
|
9840
|
+
* 归档会话也不能复用——前者归属子智能体路由,后者轮次会以 blocked 结束、
|
|
9841
|
+
* 看起来跑了其实没跑。
|
|
9842
|
+
*/
|
|
9843
|
+
async resolveSourceSession(claimed, controller) {
|
|
9844
|
+
if (claimed.reuseSource !== true) return { ok: false };
|
|
9845
|
+
const sourceSessionId = claimed.sourceSessionId;
|
|
9846
|
+
if (sourceSessionId === void 0) return { ok: false };
|
|
9847
|
+
const list = controller.list;
|
|
9848
|
+
if (typeof list !== "function") return {
|
|
9849
|
+
ok: false,
|
|
9850
|
+
reason: "this host cannot inspect Sessions"
|
|
9851
|
+
};
|
|
9852
|
+
let items;
|
|
9853
|
+
try {
|
|
9854
|
+
items = (await list.call(controller, {}, AbortSignal.timeout(SESSION_LIST_TIMEOUT_MS)))?.items ?? [];
|
|
9855
|
+
} catch (error) {
|
|
9856
|
+
return {
|
|
9857
|
+
ok: false,
|
|
9858
|
+
reason: `source session lookup failed: ${messageOf(error)}`
|
|
9859
|
+
};
|
|
9860
|
+
}
|
|
9861
|
+
const summary = items.find((item) => item.sessionId === sourceSessionId);
|
|
9862
|
+
if (summary === void 0) return {
|
|
9863
|
+
ok: false,
|
|
9864
|
+
reason: "source session no longer exists"
|
|
9865
|
+
};
|
|
9866
|
+
if (summary.origin === "subagent") return {
|
|
9867
|
+
ok: false,
|
|
9868
|
+
reason: "source session belongs to a subagent"
|
|
9869
|
+
};
|
|
9870
|
+
const archived = this.options.getWorkspaceContext?.()?.archivedSessionIds;
|
|
9871
|
+
if (archived !== void 0 && archived.includes(sourceSessionId)) return {
|
|
9872
|
+
ok: false,
|
|
9873
|
+
reason: "source session is archived"
|
|
9874
|
+
};
|
|
9875
|
+
if (summary.running === true) return {
|
|
9876
|
+
ok: false,
|
|
9877
|
+
reason: "source session is busy"
|
|
9878
|
+
};
|
|
9879
|
+
const project = typeof summary.cwd === "string" ? summary.cwd : void 0;
|
|
9880
|
+
if (project !== void 0 && !isInsideDirectory(claimed.cwd, project)) return {
|
|
9881
|
+
ok: false,
|
|
9882
|
+
reason: "source session working directory changed"
|
|
9883
|
+
};
|
|
9884
|
+
return {
|
|
9885
|
+
ok: true,
|
|
9886
|
+
sessionId: sourceSessionId
|
|
9887
|
+
};
|
|
9888
|
+
}
|
|
9889
|
+
/**
|
|
9890
|
+
* 新建会话:cwd 恰好等于某个工作区时用 create({ workspaceId }),让宿主把会话挂进
|
|
9891
|
+
* 该工作区——create({ cwd }) 从不归组,这正是队列会话在侧栏里没有分组的原因。
|
|
9892
|
+
* 两者互斥:带 workspaceId 时不能再带 cwd。
|
|
9893
|
+
*/
|
|
9894
|
+
async createGroupedSession(controller, cwd) {
|
|
9895
|
+
const workspaceId = this.options.getWorkspaceContext?.()?.workspaceIdOfPath(cwd);
|
|
9896
|
+
if (workspaceId !== void 0) try {
|
|
9897
|
+
return await controller.create({ workspaceId });
|
|
9898
|
+
} catch (error) {
|
|
9899
|
+
console.warn("[usage-billing] task queue workspace Session creation failed:", error);
|
|
9900
|
+
}
|
|
9901
|
+
return await controller.create({ cwd });
|
|
9902
|
+
}
|
|
9813
9903
|
async watch(frames, requestId) {
|
|
9814
9904
|
let admitted = false;
|
|
9815
9905
|
for await (const raw of frames) {
|
|
@@ -9847,7 +9937,8 @@ var TaskQueueEngine = class {
|
|
|
9847
9937
|
owner: void 0,
|
|
9848
9938
|
leaseUntil: void 0,
|
|
9849
9939
|
startedAt: void 0,
|
|
9850
|
-
sessionId: void 0
|
|
9940
|
+
sessionId: void 0,
|
|
9941
|
+
fallbackReason: void 0
|
|
9851
9942
|
});
|
|
9852
9943
|
}
|
|
9853
9944
|
async finish(id, status, error) {
|
|
@@ -10679,6 +10770,20 @@ function apply(ctx, config = {}) {
|
|
|
10679
10770
|
} catch {
|
|
10680
10771
|
return [];
|
|
10681
10772
|
}
|
|
10773
|
+
},
|
|
10774
|
+
getWorkspaceContext: () => {
|
|
10775
|
+
try {
|
|
10776
|
+
const registry = ctx.get("workspaceRegistry");
|
|
10777
|
+
if (registry === void 0) return void 0;
|
|
10778
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
10779
|
+
for (const workspace of registry.list?.() ?? []) if (typeof workspace.path === "string" && workspace.path !== "" && typeof workspace.id === "string") byPath.set(workspace.path, workspace.id);
|
|
10780
|
+
return {
|
|
10781
|
+
archivedSessionIds: registry.archivedSessionIds ?? [],
|
|
10782
|
+
workspaceIdOfPath: (path) => byPath.get(path)
|
|
10783
|
+
};
|
|
10784
|
+
} catch {
|
|
10785
|
+
return;
|
|
10786
|
+
}
|
|
10682
10787
|
}
|
|
10683
10788
|
});
|
|
10684
10789
|
registerTaskQueueRoute(ctx, {
|
|
@@ -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[];
|
|
@@ -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 {
|
|
@@ -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' | '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
|
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.3-alpha.
|
|
4
|
+
"version": "1.8.3-alpha.3",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|