@linxin666/dsh-client-ui-task-board 0.4.7 → 0.4.8
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.i18n.yaml +2 -2
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/lib/client.js +134 -4
- package/lib/client.js.map +1 -1
- package/lib/index.js +401 -53
- package/lib/types/client/PluginSettingsCard.d.ts +39 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +7 -0
- package/lib/types/client/locales.d.ts +2 -0
- package/lib/types/client/telemetry.d.ts +14 -2
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +34 -0
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/tasks.d.ts +32 -1
- package/lib/types/host-ledger.d.ts +24 -2
- package/lib/types/host-runner.d.ts +4 -1
- package/lib/types/host-service.d.ts +31 -0
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +11 -0
- package/lib/types/loopback.d.ts +20 -1
- package/package.json +1 -1
- package/src/client/PluginSettingsCard.tsx +63 -3
- package/src/client/TaskBoardSettingsCard.tsx +37 -0
- package/src/client/locales.ts +4 -0
- package/src/client/settings-card.module.css +70 -1
- package/src/client/telemetry.ts +47 -2
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +34 -0
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +4 -0
- package/src/core/tasks.ts +43 -1
- package/src/host-ledger.ts +63 -5
- package/src/host-runner.ts +15 -7
- package/src/host-service.ts +94 -5
- package/src/host-spend.ts +105 -0
- package/src/index.ts +33 -0
- package/src/loopback.ts +25 -1
|
@@ -37,6 +37,19 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
37
37
|
onSave: () => void;
|
|
38
38
|
/** Drop every staged edit. */
|
|
39
39
|
onDiscard: () => void;
|
|
40
|
+
/**
|
|
41
|
+
* Id applied to the card's title element, so a header control (an immediate
|
|
42
|
+
* toggle in `headerAction`) can name itself through `aria-labelledby`
|
|
43
|
+
* instead of repeating the title as a string.
|
|
44
|
+
*/
|
|
45
|
+
titleId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Render the header only, with no body region. A card whose whole setting is
|
|
48
|
+
* the header control (a switch whose explanation is the description) has no
|
|
49
|
+
* controls to lay out below it, and an empty body would draw a divider line
|
|
50
|
+
* with nothing under it.
|
|
51
|
+
*/
|
|
52
|
+
headerOnly?: boolean;
|
|
40
53
|
/**
|
|
41
54
|
* Render the controls expanded on arrival (still collapsible). Defaults to
|
|
42
55
|
* true: promoted first-level sections show their settings immediately.
|
|
@@ -54,6 +67,13 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
54
67
|
* edits, so the footer would sit there permanently disabled.
|
|
55
68
|
*/
|
|
56
69
|
hideFooter?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Optional control rendered at the header's trailing edge, before the pending
|
|
72
|
+
* badge and the chevron. A card whose setting is one immediate flip (it
|
|
73
|
+
* applies outside the staged form) puts its ToggleSwitch here, so the control
|
|
74
|
+
* is reachable without opening the card and matches a plugin card's shape.
|
|
75
|
+
*/
|
|
76
|
+
headerAction?: ReactNode;
|
|
57
77
|
/** Render children even when the settings namespace is not exposed by the host. */
|
|
58
78
|
renderChildrenWhenNotExposed?: boolean;
|
|
59
79
|
/** Hide the 'not exposed' warning banner when the settings namespace is not exposed. */
|
|
@@ -141,4 +161,23 @@ export declare function ChoiceField(props: FieldProps & {
|
|
|
141
161
|
label: string;
|
|
142
162
|
}>;
|
|
143
163
|
}): import("react").JSX.Element;
|
|
164
|
+
/**
|
|
165
|
+
* An immediate boolean toggle drawn as a switch track, for a setting that
|
|
166
|
+
* applies on flip rather than through a staged save. It is a real button with
|
|
167
|
+
* `role="switch"` and `aria-checked`, so keyboard and assistive activation
|
|
168
|
+
* arrive as a click and the state is announced instead of inferred from a
|
|
169
|
+
* checkbox tick.
|
|
170
|
+
*/
|
|
171
|
+
export declare function ToggleSwitch(props: {
|
|
172
|
+
/** Id of the element naming the switch (the card's title). */
|
|
173
|
+
labelledBy?: string;
|
|
174
|
+
/** Accessible name when no element labels it. */
|
|
175
|
+
ariaLabel?: string;
|
|
176
|
+
/** Current state. */
|
|
177
|
+
checked: boolean;
|
|
178
|
+
/** Disables the switch while a write is in flight or the Host refuses writes. */
|
|
179
|
+
disabled?: boolean;
|
|
180
|
+
/** Called with the requested next state. */
|
|
181
|
+
onChange: (next: boolean) => void;
|
|
182
|
+
}): import("react").JSX.Element;
|
|
144
183
|
export {};
|
|
@@ -27,6 +27,11 @@ export interface TaskBoardSettings {
|
|
|
27
27
|
* action creates; members enter the running column in batches, none is dropped.
|
|
28
28
|
*/
|
|
29
29
|
runLaunchWidth?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Daily token ceiling for the work this board dispatches; 0 means no gate.
|
|
32
|
+
* Tokens, not money: only DeepSeek's own routes are priced.
|
|
33
|
+
*/
|
|
34
|
+
spendBudgetTokens?: number;
|
|
30
35
|
/**
|
|
31
36
|
* GLOBAL native /goal switch (default off): the master control over whether
|
|
32
37
|
* this board starts a run with dsh's built-in /goal at all. Frozen per
|
|
@@ -68,6 +73,8 @@ export interface TaskBoardSettingsCardState extends CardShell {
|
|
|
68
73
|
sessionPollSeconds: CardFieldState;
|
|
69
74
|
/** Run-launch admission width field. */
|
|
70
75
|
runLaunchWidth: CardFieldState;
|
|
76
|
+
/** Daily token cap field. */
|
|
77
|
+
spendBudgetTokens: CardFieldState;
|
|
71
78
|
/** GLOBAL native /goal switch. */
|
|
72
79
|
goalRunEnabled: CardFieldState;
|
|
73
80
|
/** Goal-acceptance switch. */
|
|
@@ -298,6 +298,8 @@ export declare const zh: {
|
|
|
298
298
|
'settings.maxSubtaskDepthOption': string;
|
|
299
299
|
'settings.runLaunchWidth': string;
|
|
300
300
|
'settings.runLaunchWidthHint': string;
|
|
301
|
+
'settings.spendBudgetTokens': string;
|
|
302
|
+
'settings.spendBudgetTokensHint': string;
|
|
301
303
|
'settings.runBehaviorTitle': string;
|
|
302
304
|
'settings.runBehaviorCardHint': string;
|
|
303
305
|
'settings.goalRunGlobal': string;
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
* The payload carries no conversation data and no identifiers beyond a random
|
|
7
7
|
* UUID generated in localStorage; the server hashes it with a deployment salt
|
|
8
8
|
* before storage and never persists IP addresses. Sends are fire-and-forget:
|
|
9
|
-
* failures stay silent and simply retry on a later mount or day.
|
|
10
|
-
* is
|
|
9
|
+
* failures stay silent and simply retry on a later mount or day. Frames where
|
|
10
|
+
* storage is unavailable report nothing.
|
|
11
|
+
*
|
|
12
|
+
* The family-wide opt-out and the browser's Do Not Track signal both suppress
|
|
13
|
+
* the heartbeat; the Web Plugins settings switch writes the same localStorage
|
|
14
|
+
* key. The system is documented in docs/telemetry.md.
|
|
11
15
|
*/
|
|
12
16
|
export type TelemetryChannel = 'market' | 'npm' | 'unknown';
|
|
13
17
|
export interface TelemetryItem {
|
|
@@ -18,6 +22,14 @@ export interface TelemetryItem {
|
|
|
18
22
|
/** Install channel when determinable (market = Workshop install). */
|
|
19
23
|
channel?: TelemetryChannel;
|
|
20
24
|
}
|
|
25
|
+
/** localStorage key carrying the family-wide telemetry opt-out ('1' = off). */
|
|
26
|
+
export declare const TELEMETRY_OPT_OUT_KEY = "dsh-web-ui-telemetry-opt-out";
|
|
27
|
+
/** Whether the user switched the family-wide opt-out on (reads storage only). */
|
|
28
|
+
export declare function isTelemetryOptedOut(): boolean;
|
|
29
|
+
/** Turn the family-wide opt-out on or off (writing '1' / removing the key); never throws. */
|
|
30
|
+
export declare function setTelemetryOptedOut(optedOut: boolean): void;
|
|
31
|
+
/** Whether a heartbeat must be suppressed right now: opt-out stored, or the browser asks not to be tracked. */
|
|
32
|
+
export declare function isTelemetrySuppressed(): boolean;
|
|
21
33
|
/**
|
|
22
34
|
* Fire the daily heartbeat for the given items at most once per UTC day per
|
|
23
35
|
* browser. Never throws and never blocks the caller. Items without an explicit
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one execution left behind: the text of its last assistant message,
|
|
3
|
+
* recorded on the execution record next to the verdict it belongs to.
|
|
4
|
+
*
|
|
5
|
+
* A settled execution used to carry only a verdict, so a parent card could see
|
|
6
|
+
* that a subtask succeeded without ever seeing what it produced, and had to
|
|
7
|
+
* guess or redo the work. The card's own content cannot answer that: card
|
|
8
|
+
* content is the plan and freezes at the first execution
|
|
9
|
+
* (`canEditTaskContent`), so the closing words of a run are recorded on the
|
|
10
|
+
* execution record instead.
|
|
11
|
+
*
|
|
12
|
+
* Pure (no cordis, no runtime imports) so the settlement path is unit-testable
|
|
13
|
+
* without a session, and so a text-less run degrades to "no field" rather than
|
|
14
|
+
* to an empty string.
|
|
15
|
+
*/
|
|
16
|
+
import { type ExecutionSummary } from './tasks.ts';
|
|
17
|
+
/** Structural view of one session event, as both readers expose it. */
|
|
18
|
+
export interface SummaryEvent {
|
|
19
|
+
type?: unknown;
|
|
20
|
+
seq?: unknown;
|
|
21
|
+
time?: unknown;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Bound one summary, keeping its tail: the closing paragraphs carry the
|
|
26
|
+
* conclusion a reader is after, and the omitted opening is announced instead of
|
|
27
|
+
* silently dropped. Mirrors the evidence reader's tail bound.
|
|
28
|
+
*/
|
|
29
|
+
export declare function truncateExecutionSummary(text: string, limit?: number): string;
|
|
30
|
+
/**
|
|
31
|
+
* The summary one execution's own events support.
|
|
32
|
+
*
|
|
33
|
+
* Only events at or after `startedAt` belong to this run: a reused session
|
|
34
|
+
* carries the history of earlier executions, which must not be reported as this
|
|
35
|
+
* one's output. The last assistant message WITH prose wins — a trailing
|
|
36
|
+
* tool-call or reasoning-only message has nothing to leave behind, so the reader
|
|
37
|
+
* walks back to the last one that speaks.
|
|
38
|
+
* @param events - the session events the inspection already read.
|
|
39
|
+
* @param startedAt - the execution's start instant (ms epoch); 0 means "all".
|
|
40
|
+
* @returns the bounded summary with the seq it came from, or undefined when the
|
|
41
|
+
* run left no usable text.
|
|
42
|
+
*/
|
|
43
|
+
export declare function executionSummaryOf(events: readonly SummaryEvent[], startedAt: number): ExecutionSummary | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Repair one persisted or reported summary.
|
|
46
|
+
*
|
|
47
|
+
* A summary is informational, so an unreadable one is dropped on its own rather
|
|
48
|
+
* than costing the execution (or the task row) it hangs on. A hand-edited
|
|
49
|
+
* overlong text is bounded on the way in, so no reader ever holds more than the
|
|
50
|
+
* limit.
|
|
51
|
+
*/
|
|
52
|
+
export declare function normalizeExecutionSummary(value: unknown): ExecutionSummary | undefined;
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* @module dsh-task-board/core/extension
|
|
13
13
|
*/
|
|
14
14
|
import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
15
|
+
import type { TaskBoardAction, TaskBoardSnapshot, TaskBoardVerificationOptions } from '../protocol.ts';
|
|
15
16
|
import type { ExecutionOutcome, TaskRecord, TaskStatus } from './tasks.ts';
|
|
16
17
|
/** Cordis service name the host and browser halves each publish. */
|
|
17
18
|
export declare const TASK_BOARD_SERVICE_NAME = "taskBoard";
|
|
@@ -255,6 +256,39 @@ export interface TaskBoardHostFace {
|
|
|
255
256
|
registerExtension(extension: TaskBoardExtension): () => void;
|
|
256
257
|
/** Whether the board currently runs a given extension (board x extension). */
|
|
257
258
|
isExtensionEnabled(extensionId: string): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* The whole ledger as the board builds it, tasks included.
|
|
261
|
+
*
|
|
262
|
+
* Part of the read/write face an IN-PROCESS consumer drives the board through
|
|
263
|
+
* (the remote bridge plugin forwarding it to a paired phone); a browser half
|
|
264
|
+
* reads the same document over the board's own HTTP surface. Forwards
|
|
265
|
+
* {@link ../host-service.ts | TaskBoardHostService.snapshot}, so nothing is
|
|
266
|
+
* interpreted between the ledger and the caller.
|
|
267
|
+
*/
|
|
268
|
+
snapshot(): TaskBoardSnapshot;
|
|
269
|
+
/**
|
|
270
|
+
* Apply one action through every gate the board already has — the running
|
|
271
|
+
* lock, the permission confirmation, the subtask depth, the schedule budget —
|
|
272
|
+
* and answer the resulting snapshot.
|
|
273
|
+
*
|
|
274
|
+
* The `requestId` is the ledger's own idempotency key, so a caller that
|
|
275
|
+
* retries one envelope does not apply it twice. Refusals are the ledger's:
|
|
276
|
+
* they throw with the Host's own text, which is why this face adds no code
|
|
277
|
+
* table of its own.
|
|
278
|
+
*/
|
|
279
|
+
apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot>;
|
|
280
|
+
/**
|
|
281
|
+
* Follow the board's change notifications. The listener receives no payload —
|
|
282
|
+
* a consumer that needs the state reads {@link snapshot} — and the returned
|
|
283
|
+
* disposer unsubscribes.
|
|
284
|
+
*/
|
|
285
|
+
subscribe(listener: () => void): () => void;
|
|
286
|
+
/**
|
|
287
|
+
* The acceptance settings, the contract they resolve to right now, and the
|
|
288
|
+
* model catalog the choices come from. The same document the board's own
|
|
289
|
+
* `/verification` route serves.
|
|
290
|
+
*/
|
|
291
|
+
verificationOptions(): Promise<TaskBoardVerificationOptions>;
|
|
258
292
|
}
|
|
259
293
|
declare module '@deepseek-ai/cordis' {
|
|
260
294
|
interface Context {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The daily token ceiling both spend gates share, as pure rules: the cap
|
|
3
|
+
* comparison and the one refusal wording.
|
|
4
|
+
*
|
|
5
|
+
* The unit is tokens, not money. The usage ledger the board reads prices only
|
|
6
|
+
* DeepSeek's own routes, so a cost cap would read 0 on every other route and
|
|
7
|
+
* refuse nothing on exactly the deployments that need it. A cap of 0 is the
|
|
8
|
+
* shipped default and means "no gate": both gates answer before they read a
|
|
9
|
+
* file, subscribe to an event, or compute anything.
|
|
10
|
+
* @module @linxin666/dsh-task-board/core/spend-budget
|
|
11
|
+
*/
|
|
12
|
+
/** Token cap one board day may spend; 0 disables the gate. */
|
|
13
|
+
export declare const DEFAULT_SPEND_BUDGET_TOKENS = 0;
|
|
14
|
+
/**
|
|
15
|
+
* Whether a day's measured spend already reached the cap.
|
|
16
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
17
|
+
* @param cap - the configured cap, 0 for "no gate".
|
|
18
|
+
* @returns true when a run must be refused.
|
|
19
|
+
*/
|
|
20
|
+
export declare function spendCapReached(usedTokens: number, cap: number): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The refusal text both gates report: the thrown message a client sees as
|
|
23
|
+
* board-refused, and the scheduler error a due occurrence records.
|
|
24
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
25
|
+
* @param cap - the configured cap.
|
|
26
|
+
* @returns the refusal message.
|
|
27
|
+
*/
|
|
28
|
+
export declare function spendCapMessage(usedTokens: number, cap: number): string;
|
|
@@ -12,6 +12,27 @@ import { type TaskBoardExtensionPayload } from './extension.ts';
|
|
|
12
12
|
export type TaskStatus = 'backlog' | 'todo' | 'running' | 'done' | 'failed';
|
|
13
13
|
/** Settled outcome of one execution attempt. */
|
|
14
14
|
export type ExecutionOutcome = 'succeeded' | 'failed' | 'cancelled';
|
|
15
|
+
/**
|
|
16
|
+
* What one execution left behind: the text of the run's last assistant message
|
|
17
|
+
* and the session event it was read from.
|
|
18
|
+
*
|
|
19
|
+
* The board records a verdict per execution but no output, so a parent card
|
|
20
|
+
* could see that a subtask succeeded without seeing what it produced. Card
|
|
21
|
+
* content cannot answer that (it is the plan and freezes at the first
|
|
22
|
+
* execution), so the closing text rides the execution record instead.
|
|
23
|
+
*/
|
|
24
|
+
export interface ExecutionSummary {
|
|
25
|
+
/** Last assistant message text of the run, bounded by {@link EXECUTION_SUMMARY_LIMIT}. */
|
|
26
|
+
text: string;
|
|
27
|
+
/** Seq of the session event that text came from; absent text has no seq either. */
|
|
28
|
+
seq: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Upper bound of one recorded summary, in characters. The ledger stores a
|
|
32
|
+
* conclusion, not a transcript: a reader that needs the whole message follows
|
|
33
|
+
* {@link ExecutionSummary.seq} into the session history.
|
|
34
|
+
*/
|
|
35
|
+
export declare const EXECUTION_SUMMARY_LIMIT = 4000;
|
|
15
36
|
/**
|
|
16
37
|
* One real execution attempt: the run's own id, the dsh session that ran it
|
|
17
38
|
* (filled once the session is created), and the settled outcome once the
|
|
@@ -69,6 +90,16 @@ export interface ExecutionRecord {
|
|
|
69
90
|
ownResult?: ExecutionOutcome;
|
|
70
91
|
/** Human failure text that arrived with {@link ownResult}. */
|
|
71
92
|
ownError?: string;
|
|
93
|
+
/**
|
|
94
|
+
* What this run left behind: the text of its last assistant message, taken
|
|
95
|
+
* when the settlement read the session and recorded with the verdict.
|
|
96
|
+
*
|
|
97
|
+
* Absent — never an empty string — when the session could not be read or
|
|
98
|
+
* carried no assistant prose, so "recorded nothing" stays distinguishable
|
|
99
|
+
* from "produced nothing". Settling never fails over it: a summary is
|
|
100
|
+
* informational, and every field above is what the board decides with.
|
|
101
|
+
*/
|
|
102
|
+
summary?: ExecutionSummary;
|
|
72
103
|
/**
|
|
73
104
|
* Goal acceptance state of this execution (task-board goal verification).
|
|
74
105
|
* Fixed when the execution starts and never rewritten from later settings:
|
|
@@ -615,6 +646,6 @@ export declare function settledStatus(task: TaskRecord, outcome: ExecutionOutcom
|
|
|
615
646
|
* matching column. No-op (returns the input task) when the execution is not
|
|
616
647
|
* the task's latest or is already settled.
|
|
617
648
|
*/
|
|
618
|
-
export declare function settleExecution(task: TaskRecord, executionId: string, outcome: ExecutionOutcome, now: number, error: string | undefined): TaskRecord;
|
|
649
|
+
export declare function settleExecution(task: TaskRecord, executionId: string, outcome: ExecutionOutcome, now: number, error: string | undefined, summary?: ExecutionSummary): TaskRecord;
|
|
619
650
|
/** A settled-execution summary string for the detail view. */
|
|
620
651
|
export declare function executionLabel(execution: ExecutionRecord): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExecutionOutcome, type ExecutionRecord, type ScheduleMode, type TaskRecord } from './core/tasks.ts';
|
|
1
|
+
import { type ExecutionOutcome, type ExecutionRecord, type ExecutionSummary, type ScheduleMode, type TaskRecord } from './core/tasks.ts';
|
|
2
2
|
import type { CardDefaults } from './core/card-defaults.ts';
|
|
3
3
|
import { type TaskBoardAction, type TaskBoardSchedulerSnapshot } from './protocol.ts';
|
|
4
4
|
import { type ExecutionVerification } from './core/verification.ts';
|
|
@@ -128,10 +128,20 @@ export declare class HostTaskLedger {
|
|
|
128
128
|
private depthLimit;
|
|
129
129
|
/** Live reader of the deployment's new-card defaults (a volatile config read). */
|
|
130
130
|
private readonly cardDefaults;
|
|
131
|
+
/**
|
|
132
|
+
* Live reader of the daily token cap (0 = no gate). The scheduled path asks it
|
|
133
|
+
* per due occurrence, so a cap raised after a skipped occurrence admits the
|
|
134
|
+
* next one without a restart.
|
|
135
|
+
*/
|
|
136
|
+
private readonly spendBudget;
|
|
137
|
+
/** Today's measured spend in tokens, or undefined when nothing can be measured. */
|
|
138
|
+
private readonly spendUsed;
|
|
131
139
|
constructor(dir?: string, now?: () => number, options?: {
|
|
132
140
|
sessionDefaultPermission?: TaskPermission | (() => TaskPermission);
|
|
133
141
|
maxSubtaskDepth?: number;
|
|
134
142
|
cardDefaults?: () => CardDefaults;
|
|
143
|
+
spendBudgetTokens?: () => number;
|
|
144
|
+
spendUsedToday?: (now: number) => number | undefined;
|
|
135
145
|
});
|
|
136
146
|
/** Current subtask depth limit (1..3). */
|
|
137
147
|
get maxSubtaskDepth(): number;
|
|
@@ -188,6 +198,14 @@ export declare class HostTaskLedger {
|
|
|
188
198
|
* @returns the executions this occurrence opened.
|
|
189
199
|
*/
|
|
190
200
|
openScheduled(taskId: string, triggeredAt: number): OpenedRun[];
|
|
201
|
+
/**
|
|
202
|
+
* Why a due occurrence may not open a run because the day already spent the
|
|
203
|
+
* cap, or undefined when it may. A cap of 0 — the default — answers before the
|
|
204
|
+
* measurement is read, so a board with no gate reads no ledger file.
|
|
205
|
+
* @param now - clock instant (ms epoch).
|
|
206
|
+
* @returns the refusal message, when the cap is reached.
|
|
207
|
+
*/
|
|
208
|
+
private spendRefusal;
|
|
191
209
|
/**
|
|
192
210
|
* Record a due occurrence that opened no execution: roll a recurring rule to
|
|
193
211
|
* its next occurrence (budget untouched), or stop it when there is none. A
|
|
@@ -223,8 +241,12 @@ export declare class HostTaskLedger {
|
|
|
223
241
|
* and only finalizes once every child execution in its run group has
|
|
224
242
|
* settled, so a parent card leaves 'running' with the whole tree's verdict
|
|
225
243
|
* rather than its own turn alone.
|
|
244
|
+
*
|
|
245
|
+
* `summary` is what the run left behind (see `ExecutionSummary`), passed in
|
|
246
|
+
* by whichever reader observed the session. It is informational: a caller
|
|
247
|
+
* without one settles exactly as before, and a settlement never waits on it.
|
|
226
248
|
*/
|
|
227
|
-
settle(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string): void;
|
|
249
|
+
settle(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string, summary?: ExecutionSummary): void;
|
|
228
250
|
attachSession(taskId: string, executionId: string, sessionId: string): void;
|
|
229
251
|
allTasks(): readonly TaskRecord[];
|
|
230
252
|
getTask(id: string): TaskRecord | undefined;
|
|
@@ -4,7 +4,7 @@ import type { SessionSummary } from '@deepseek-ai/dsh-api-session-controller/typ
|
|
|
4
4
|
import type { CommandResult } from '@deepseek-ai/dsh-commands/types';
|
|
5
5
|
import type { Workspace } from '@deepseek-ai/dsh-workspace/types';
|
|
6
6
|
import type { ModelCatalogView } from './core/verification.ts';
|
|
7
|
-
import type { TaskRecord } from './core/tasks.ts';
|
|
7
|
+
import type { ExecutionSummary, TaskRecord } from './core/tasks.ts';
|
|
8
8
|
/**
|
|
9
9
|
* Host services needed to validate a task's workspace before creating a
|
|
10
10
|
* session, and to resolve the workspace an unpinned card runs in.
|
|
@@ -77,12 +77,15 @@ export type ExecutionInspection =
|
|
|
77
77
|
reason?: string;
|
|
78
78
|
} | {
|
|
79
79
|
outcome: 'succeeded';
|
|
80
|
+
summary?: ExecutionSummary;
|
|
80
81
|
} | {
|
|
81
82
|
outcome: 'failed';
|
|
82
83
|
error: string;
|
|
84
|
+
summary?: ExecutionSummary;
|
|
83
85
|
} | {
|
|
84
86
|
outcome: 'cancelled';
|
|
85
87
|
error: string;
|
|
88
|
+
summary?: ExecutionSummary;
|
|
86
89
|
};
|
|
87
90
|
/** A post-create launch failure that still identifies the session to the ledger. */
|
|
88
91
|
export declare class SessionLaunchError extends Error {
|
|
@@ -131,6 +131,13 @@ export declare class TaskBoardHostService {
|
|
|
131
131
|
* launch without remounting the row. Absent means the default.
|
|
132
132
|
*/
|
|
133
133
|
private readonly runLaunchWidth;
|
|
134
|
+
/**
|
|
135
|
+
* Live reader of the daily token cap; 0 means no gate. Read at each run
|
|
136
|
+
* action, so closing or raising the cap binds the next action.
|
|
137
|
+
*/
|
|
138
|
+
private readonly spendBudgetTokens;
|
|
139
|
+
/** Today's measured spend: absent measurement reads as "cannot see", never as zero. */
|
|
140
|
+
private readonly spendUsedToday;
|
|
134
141
|
private lastPowerJson;
|
|
135
142
|
private readonly now;
|
|
136
143
|
/** The deployment's workspaces, consulted to resolve a card that pins none. */
|
|
@@ -192,6 +199,18 @@ export declare class TaskBoardHostService {
|
|
|
192
199
|
* is still queueing. Absent means the default width.
|
|
193
200
|
*/
|
|
194
201
|
runLaunchWidth?: () => number;
|
|
202
|
+
/**
|
|
203
|
+
* Live daily token cap (a volatile config read). 0 — the default, and what
|
|
204
|
+
* every deployment that never configured one keeps — ends the gate before
|
|
205
|
+
* anything is measured. A positive cap refuses a run whose day already spent
|
|
206
|
+
* it, on both the action path and the cron path.
|
|
207
|
+
*/
|
|
208
|
+
spendBudgetTokens?: () => number;
|
|
209
|
+
/**
|
|
210
|
+
* Today's measured spend in tokens, or undefined when this deployment keeps
|
|
211
|
+
* no readable usage ledger. Defaults to the family usage ledger reader.
|
|
212
|
+
*/
|
|
213
|
+
spendUsedToday?: (now: number) => number | undefined;
|
|
195
214
|
});
|
|
196
215
|
start(): void;
|
|
197
216
|
/**
|
|
@@ -258,6 +277,18 @@ export declare class TaskBoardHostService {
|
|
|
258
277
|
* never disagree about a card.
|
|
259
278
|
*/
|
|
260
279
|
private applyBoardAction;
|
|
280
|
+
/**
|
|
281
|
+
* Refuse a run whose day already spent the cap.
|
|
282
|
+
*
|
|
283
|
+
* A cap of 0 — the shipped default — answers before the measurement is read:
|
|
284
|
+
* no ledger file is opened and nothing is summed, which is what keeps a board
|
|
285
|
+
* that never configured a cap identical to the one before it existed.
|
|
286
|
+
*
|
|
287
|
+
* The refusal is a thrown message rather than a code: the wire hands its text
|
|
288
|
+
* to the caller as board-refused, exactly like every other refusal this board
|
|
289
|
+
* makes.
|
|
290
|
+
*/
|
|
291
|
+
private assertSpendCap;
|
|
261
292
|
/** Route one provider action and answer the resulting board snapshot. */
|
|
262
293
|
private handleExtensionAction;
|
|
263
294
|
/** Current task id -> status map, for change detection around a mutation. */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Today's measured spend, read from the usage ledger this deployment keeps at
|
|
3
|
+
* `$DSH_HOME/dsh-usage/usage-ledger.json`.
|
|
4
|
+
*
|
|
5
|
+
* The measure is the family usage ledger rather than a counter this plugin
|
|
6
|
+
* accumulates from `session/event`, for two reasons. The ledger is durable, so
|
|
7
|
+
* a cap cannot be reset by restarting the Host (the Loader remounts a row on
|
|
8
|
+
* any config change, and a spend counter that lived only in memory would forget
|
|
9
|
+
* the day). And a second fold of the same events inside the board would have to
|
|
10
|
+
* persist its own totals to be worth anything, which means a second writer of
|
|
11
|
+
* spend state in one process.
|
|
12
|
+
*
|
|
13
|
+
* What that costs: the file belongs to the dsh-usage plugin, so a deployment
|
|
14
|
+
* that does not mount it keeps no ledger and the cap cannot measure anything.
|
|
15
|
+
* That case is reported once per process and the gate then refuses nothing —
|
|
16
|
+
* wedging the board because a sibling plugin is absent would be worse than a
|
|
17
|
+
* cap that says it cannot see. The 3 s flush debounce of that plugin is the
|
|
18
|
+
* other cost: the reading trails the busiest moments by at most one debounce.
|
|
19
|
+
* @module @linxin666/dsh-task-board/host-spend
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Local-date key (`YYYY-MM-DD`) of an instant, the bucketing the usage ledger
|
|
23
|
+
* itself uses: the cap and the usage panel therefore roll over at the same
|
|
24
|
+
* local midnight.
|
|
25
|
+
* @param ms - clock instant (ms epoch).
|
|
26
|
+
* @returns the day key.
|
|
27
|
+
*/
|
|
28
|
+
export declare function spendDateKey(ms: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* Total tokens one ledger day recorded, across every provider and model of that
|
|
31
|
+
* day. Anything that is not a finite token count contributes 0, so a ledger
|
|
32
|
+
* written by another version degrades to a smaller reading instead of NaN.
|
|
33
|
+
* @param day - one day bucket as the ledger stores it, when it is one.
|
|
34
|
+
* @returns the day's token total.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ledgerDayTokens(day: unknown): number;
|
|
37
|
+
/**
|
|
38
|
+
* Path of the usage ledger for this DSH home.
|
|
39
|
+
* @returns the absolute ledger path.
|
|
40
|
+
*/
|
|
41
|
+
export declare function spendLedgerPath(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Tokens already spent today, or undefined when no measurement is available.
|
|
44
|
+
*
|
|
45
|
+
* Undefined is "cannot see", not "spent nothing": the caller fails open and
|
|
46
|
+
* reports it, because a spend cap that cannot read its own source must never
|
|
47
|
+
* decide that no work may run.
|
|
48
|
+
* @param now - clock instant (ms epoch).
|
|
49
|
+
* @param path - ledger path (test seam).
|
|
50
|
+
* @returns today's token total, or undefined when the ledger is unreadable.
|
|
51
|
+
*/
|
|
52
|
+
export declare function usedTokensToday(now?: number, path?: string): number | undefined;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -80,6 +80,15 @@ export interface Config {
|
|
|
80
80
|
* queueing.
|
|
81
81
|
*/
|
|
82
82
|
runLaunchWidth?: Volatile<number>;
|
|
83
|
+
/**
|
|
84
|
+
* Daily token ceiling for the work this board dispatches (default 0 = no
|
|
85
|
+
* gate). Tokens, not money: the ledger the board measures against prices
|
|
86
|
+
* DeepSeek's own routes only, so a cost cap would read 0 elsewhere. Read at
|
|
87
|
+
* each gate, so an edit binds the next run without a remount; a manual
|
|
88
|
+
* run/rerun whose day already spent the cap is refused, and a due occurrence
|
|
89
|
+
* is skipped onto the scheduler with its run budget untouched.
|
|
90
|
+
*/
|
|
91
|
+
spendBudgetTokens?: Volatile<number>;
|
|
83
92
|
/**
|
|
84
93
|
* Continuable-subagent provider the Agent Teams service uses to compose a
|
|
85
94
|
* teammate. Matches the Agent Teams tool plugin's `freshProvider` default;
|
|
@@ -206,6 +215,8 @@ export interface ConfigInput {
|
|
|
206
215
|
sessionPollSeconds?: number;
|
|
207
216
|
/** Concurrent run launches allowed at once, 1..16. */
|
|
208
217
|
runLaunchWidth?: number;
|
|
218
|
+
/** Daily token ceiling for board runs; 0 disables the gate. */
|
|
219
|
+
spendBudgetTokens?: number;
|
|
209
220
|
/** Continuable-subagent provider the Agent Teams service composes a teammate from. */
|
|
210
221
|
teamProvider?: string;
|
|
211
222
|
/** Global native /goal switch; default off, frozen per execution. */
|
package/lib/types/loopback.d.ts
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
* Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
|
|
8
8
|
* remote-web-ui gate), localhost hostnames, plus the browser same-origin
|
|
9
9
|
* markers (sec-fetch-site and Origin) for the request-level fence.
|
|
10
|
+
*
|
|
11
|
+
* A reverse proxy in front of the host rewrites the Host header to its own
|
|
12
|
+
* upstream literal (a Cloudflare tunnel, frp and an nginx reverse proxy all
|
|
13
|
+
* dial 127.0.0.1:<port>), and the socket the origin sees is the proxy's, which
|
|
14
|
+
* is loopback by construction. Both halves of the fence then hold for a public
|
|
15
|
+
* request. Forwarding headers are the signal that a hop stands in between: a
|
|
16
|
+
* request that carries CF-Connecting-IP or X-Forwarded-For is answered through
|
|
17
|
+
* a proxy and is never treated as a local one (issue #1906).
|
|
10
18
|
* @module dsh-web-shared/host/loopback
|
|
11
19
|
*/
|
|
12
20
|
import type { IncomingMessage } from 'node:http';
|
|
@@ -16,9 +24,20 @@ export declare function isIPv4Loopback(v4: string): boolean;
|
|
|
16
24
|
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
17
25
|
/** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
|
|
18
26
|
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a reverse proxy stood between the client and this host: the request
|
|
29
|
+
* carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
|
|
30
|
+
* hop that forwards traffic, so the request did not originate on this machine.
|
|
31
|
+
* @param request - node HTTP request.
|
|
32
|
+
* @returns true when a forwarding header is present.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isProxiedRequest(request: IncomingMessage): boolean;
|
|
19
35
|
/**
|
|
20
36
|
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
21
37
|
* header, plus browser same-origin markers. The socket address is
|
|
22
|
-
* authoritative;
|
|
38
|
+
* authoritative for a direct connection; a request that carries a forwarding
|
|
39
|
+
* header is refused outright, because a proxy in front of the host makes both
|
|
40
|
+
* the socket address and the Host header describe the proxy rather than the
|
|
41
|
+
* client. X-Forwarded-For is therefore never evidence *for* loopback.
|
|
23
42
|
*/
|
|
24
43
|
export declare function isLoopbackRequest(request: IncomingMessage): boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-client-ui-task-board",
|
|
3
3
|
"description": "Host-authoritative task board for the DSH Web GUI with real session execution, Host cron scheduling, and optional cross-platform idle-sleep protection; mounted without DSH source changes.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.8",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|