@linxin666/dsh-client-ui-task-board 0.4.6 → 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 +15 -6
- package/README.zh.md +15 -6
- package/lib/client.js +1634 -822
- package/lib/client.js.map +1 -1
- package/lib/index.js +1072 -125
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +39 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +56 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/model-options.d.ts +67 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/team-run-promotion.d.ts +26 -0
- package/lib/types/client/locales.d.ts +18 -0
- package/lib/types/client/telemetry.d.ts +14 -2
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +32 -7
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +34 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +30 -8
- package/lib/types/core/tasks.d.ts +51 -1
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-update.d.ts +1 -1
- package/lib/types/host/launch-admission.d.ts +72 -0
- package/lib/types/host-ledger.d.ts +33 -6
- package/lib/types/host-runner.d.ts +83 -5
- package/lib/types/host-service.d.ts +116 -2
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +98 -0
- package/lib/types/loopback.d.ts +20 -1
- package/lib/types/protocol.d.ts +13 -0
- package/package.json +28 -28
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +63 -3
- package/src/client/TaskBoardSettingsCard.tsx +251 -16
- package/src/client/board/LinkSubtaskModal.tsx +8 -0
- package/src/client/board/NewTaskModal.tsx +86 -40
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TaskDetail.tsx +42 -6
- package/src/client/board/model-options.ts +178 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/team-run-promotion.ts +39 -0
- package/src/client/index.ts +98 -94
- package/src/client/locales.ts +38 -2
- package/src/client/settings-card.module.css +70 -1
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/telemetry.ts +47 -2
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +44 -9
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +34 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +9 -0
- package/src/core/subtask.ts +48 -13
- package/src/core/tasks.ts +63 -1
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-update.ts +6 -1
- package/src/host/agent-tools.ts +21 -8
- package/src/host/launch-admission.ts +140 -0
- package/src/host-ledger.ts +80 -10
- package/src/host-runner.ts +199 -25
- package/src/host-service.ts +340 -27
- package/src/host-spend.ts +105 -0
- package/src/index.ts +182 -2
- package/src/loopback.ts +25 -1
- package/src/protocol.ts +28 -4
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* New-card defaults: the execution targets a freshly created card starts from,
|
|
3
|
+
* and how they combine with what the caller picked and with the card a subtask
|
|
4
|
+
* or a duplicate is created from.
|
|
5
|
+
*
|
|
6
|
+
* Framework-free (no cordis, no runtime imports) because BOTH halves compile
|
|
7
|
+
* it: the Host resolves the seed when it writes the card, and the browser
|
|
8
|
+
* resolves the same seed to open the new-task dialog on it. One pure function
|
|
9
|
+
* is the only place the rules live, so the dialog and the ledger cannot drift.
|
|
10
|
+
*
|
|
11
|
+
* Every target is resolved in ONE order: what the caller picked wins over the
|
|
12
|
+
* value carried over from the card this one is created from, which wins over
|
|
13
|
+
* the board's new-card defaults, and a target nothing supplies stays blank
|
|
14
|
+
* ("no pin, resolved at run time"). A duplicate is a copy of its source and a
|
|
15
|
+
* subtask is derived from its parent, so both keep the source's own pins and
|
|
16
|
+
* fill only the fields that source left unset.
|
|
17
|
+
*
|
|
18
|
+
* The permission of a PARENT is the one exception: it never participates. The
|
|
19
|
+
* permission is not copied onto a card at creation — doing so would also have
|
|
20
|
+
* to copy the parent's human confirmation to stay runnable, and a detached
|
|
21
|
+
* child would keep both, so one confirmed parent would mint unbounded confirmed
|
|
22
|
+
* elevated roots. It is resolved along the ancestor chain at launch instead
|
|
23
|
+
* (core/subtask.ts), which is what makes detaching remove the inheritance by
|
|
24
|
+
* construction. A duplicate is not a hierarchy link, so it copies the
|
|
25
|
+
* permission like every other target. The board's own default permission is not
|
|
26
|
+
* a parent binding either and does apply to a subtask; it only pre-fills the
|
|
27
|
+
* card, and a value above the session baseline still needs a human
|
|
28
|
+
* confirmation before the card may run.
|
|
29
|
+
*
|
|
30
|
+
* The reasoning level is bound to the model route it was chosen for and never
|
|
31
|
+
* crosses to another one:
|
|
32
|
+
*
|
|
33
|
+
* - a level the caller picked is used as it stands;
|
|
34
|
+
* - a caller that pinned a model of its own inherits no level at all, not
|
|
35
|
+
* even one the same model happens to carry on the source card;
|
|
36
|
+
* - otherwise the source card's level travels with the source value it was
|
|
37
|
+
* stored on, exactly as the card's own model/level pair does, and wins over
|
|
38
|
+
* the board default level, so a board that configures none behaves exactly
|
|
39
|
+
* as the create path always has;
|
|
40
|
+
* - a board default level applies only while the card's final model IS the
|
|
41
|
+
* configured default model, and a blank default model makes it inert —
|
|
42
|
+
* a level the resolved model does not declare could only be refused by
|
|
43
|
+
* model selection at run time.
|
|
44
|
+
*/
|
|
45
|
+
import type { TaskRecord } from './tasks.ts'
|
|
46
|
+
|
|
47
|
+
/** The board's configured new-card defaults; a blank target means "not set". */
|
|
48
|
+
export interface CardDefaults {
|
|
49
|
+
/** Agent preset a new card starts from. */
|
|
50
|
+
mode?: string
|
|
51
|
+
/** Permission a new card starts from. */
|
|
52
|
+
permission?: string
|
|
53
|
+
/** Model a new card starts from. */
|
|
54
|
+
model?: string
|
|
55
|
+
/** Reasoning level a new card starts from, for the model above. */
|
|
56
|
+
reasoningEffort?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The card a new one is created from, and how it is derived from it. */
|
|
60
|
+
export interface CardTargetSource {
|
|
61
|
+
/** A copy of the source card, or a subtask of it. */
|
|
62
|
+
kind: 'duplicate' | 'parent'
|
|
63
|
+
/** The source card's execution targets. */
|
|
64
|
+
task: Pick<TaskRecord, 'mode' | 'permission' | 'model' | 'reasoningEffort'>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The resolved targets of the card about to be created; blank means "unset". */
|
|
68
|
+
export interface CardTargetSeed {
|
|
69
|
+
mode: string
|
|
70
|
+
permission: string
|
|
71
|
+
model: string
|
|
72
|
+
reasoningEffort: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Trim one optional target: blank text means "not set", like every stored pin. */
|
|
76
|
+
function textOf(value: string | undefined): string {
|
|
77
|
+
return value?.trim() ?? ''
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Resolve the execution targets a new card starts from.
|
|
82
|
+
* @param defaults - the board's configured new-card defaults, if any.
|
|
83
|
+
* @param source - the card this one is created from (a duplicate or a parent), if any.
|
|
84
|
+
* @param picked - what the caller chose explicitly; a non-blank value wins.
|
|
85
|
+
* @returns the four targets, blank where nothing supplies a value.
|
|
86
|
+
*/
|
|
87
|
+
export function resolveCardTargets(
|
|
88
|
+
defaults: CardDefaults | undefined,
|
|
89
|
+
source: CardTargetSource | undefined,
|
|
90
|
+
picked?: Partial<CardTargetSeed>,
|
|
91
|
+
): CardTargetSeed {
|
|
92
|
+
const defaultMode = textOf(defaults?.mode)
|
|
93
|
+
const defaultPermission = textOf(defaults?.permission)
|
|
94
|
+
const defaultModel = textOf(defaults?.model)
|
|
95
|
+
// A default level with no default model of its own names no route to bind to
|
|
96
|
+
// (only a hand-edited settings document can express that), so it is inert.
|
|
97
|
+
const defaultEffort = defaultModel === '' ? '' : textOf(defaults?.reasoningEffort)
|
|
98
|
+
const chosen = {
|
|
99
|
+
mode: textOf(picked?.mode),
|
|
100
|
+
permission: textOf(picked?.permission),
|
|
101
|
+
model: textOf(picked?.model),
|
|
102
|
+
reasoningEffort: textOf(picked?.reasoningEffort),
|
|
103
|
+
}
|
|
104
|
+
const copied = source === undefined ? undefined : {
|
|
105
|
+
mode: textOf(source.task.mode),
|
|
106
|
+
permission: textOf(source.task.permission),
|
|
107
|
+
model: textOf(source.task.model),
|
|
108
|
+
reasoningEffort: textOf(source.task.reasoningEffort),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The value carried over from the source card, or the board default. */
|
|
112
|
+
const inherited = (key: 'mode' | 'permission' | 'model'): string => {
|
|
113
|
+
const fallback = key === 'mode' ? defaultMode : key === 'model' ? defaultModel : defaultPermission
|
|
114
|
+
// A parent's binding never travels; a duplicate's does (it is not a link).
|
|
115
|
+
if (copied === undefined || (key === 'permission' && source?.kind === 'parent')) return fallback
|
|
116
|
+
return copied[key] === '' ? fallback : copied[key]
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const mode = chosen.mode === '' ? inherited('mode') : chosen.mode
|
|
120
|
+
const permission = chosen.permission === '' ? inherited('permission') : chosen.permission
|
|
121
|
+
const model = chosen.model === '' ? inherited('model') : chosen.model
|
|
122
|
+
|
|
123
|
+
let reasoningEffort = chosen.reasoningEffort
|
|
124
|
+
if (reasoningEffort === '' && chosen.model === '') {
|
|
125
|
+
// The caller pinned no model of its own, so the level follows the source
|
|
126
|
+
// pair first and the board default second.
|
|
127
|
+
const sourced = copied === undefined ? '' : copied.reasoningEffort
|
|
128
|
+
reasoningEffort = sourced !== '' ? sourced : (model !== '' && model === defaultModel ? defaultEffort : '')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return { mode, permission, model, reasoningEffort }
|
|
132
|
+
}
|
package/src/core/controller.ts
CHANGED
|
@@ -127,6 +127,17 @@ export interface ExecutionModelOption {
|
|
|
127
127
|
name?: string
|
|
128
128
|
label?: string
|
|
129
129
|
provider?: string
|
|
130
|
+
/**
|
|
131
|
+
* Reasoning metadata the adapter declares for this exact route. An effort
|
|
132
|
+
* picker is offered only while `supported`, and its choices are `efforts` —
|
|
133
|
+
* the ids the target model really accepts, so the UI never offers (or keeps)
|
|
134
|
+
* a level the model would reject. Absent means the deployment published no
|
|
135
|
+
* capability for this model; the card value is then left untouched.
|
|
136
|
+
*/
|
|
137
|
+
reasoning?: {
|
|
138
|
+
supported: boolean
|
|
139
|
+
efforts?: readonly string[]
|
|
140
|
+
}
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
/** The execution-target option sets the UI feeds into the controller. */
|
|
@@ -141,7 +152,7 @@ export interface ExecutionOptionsSnapshot {
|
|
|
141
152
|
* (revision/scheduler/power); a full snapshot also carries the deployment
|
|
142
153
|
* constants the UI reads (session default permission, subtask depth).
|
|
143
154
|
*/
|
|
144
|
-
export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'teamRunAvailable' | 'goalRunEnabled' | 'extensions'>
|
|
155
|
+
export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'teamRunAvailable' | 'goalRunEnabled' | 'cardDefaults' | 'extensions'>
|
|
145
156
|
|
|
146
157
|
/** Immutable controller snapshot for UI subscriptions. */
|
|
147
158
|
export interface ControllerSnapshot {
|
|
@@ -318,6 +329,22 @@ export class BoardController {
|
|
|
318
329
|
return await this.initializeRemote()
|
|
319
330
|
}
|
|
320
331
|
|
|
332
|
+
/**
|
|
333
|
+
* Re-read the authoritative Host snapshot.
|
|
334
|
+
*
|
|
335
|
+
* The board's volatile deployment configuration — the new-card defaults among
|
|
336
|
+
* it — is republished the moment the settings document is written, but the SSE
|
|
337
|
+
* frame that republish emits carries the value as of BEFORE the write (the
|
|
338
|
+
* loader hands the update to the fiber while the new document is not yet
|
|
339
|
+
* visible to it), so a mirror that followed frames alone would stay one edit
|
|
340
|
+
* behind and the create dialog would prefill from the previous defaults for
|
|
341
|
+
* the rest of the session. The surface that owns the write asks for the
|
|
342
|
+
* snapshot again instead of trusting the frame.
|
|
343
|
+
*/
|
|
344
|
+
refreshHostState(): void {
|
|
345
|
+
void this.refreshRemote()
|
|
346
|
+
}
|
|
347
|
+
|
|
321
348
|
// --- view state -------------------------------------------------------------
|
|
322
349
|
|
|
323
350
|
/**
|
|
@@ -407,7 +434,7 @@ export class BoardController {
|
|
|
407
434
|
|
|
408
435
|
createTask(input: NewTaskInput): TaskRecord | undefined {
|
|
409
436
|
const id = this.uuid()
|
|
410
|
-
const { task, tasks } = applyCreateTask(this.tasks, input, this.now(), id, this.mirrorDepth())
|
|
437
|
+
const { task, tasks } = applyCreateTask(this.tasks, input, this.now(), id, this.mirrorDepth(), undefined, this.hostState?.cardDefaults)
|
|
411
438
|
if (task === undefined) return undefined
|
|
412
439
|
this.tasks = [...tasks]
|
|
413
440
|
this.persistAndNotify()
|
|
@@ -421,7 +448,7 @@ export class BoardController {
|
|
|
421
448
|
// The preview must obey the SAME lineage gate the Host will: a browser-side
|
|
422
449
|
// default of one level would reject a legal subtask-of-subtask before the
|
|
423
450
|
// request is ever sent.
|
|
424
|
-
const preview = applyCreateTask(this.tasks, input, this.now(), id, this.mirrorDepth()).task
|
|
451
|
+
const preview = applyCreateTask(this.tasks, input, this.now(), id, this.mirrorDepth(), undefined, this.hostState?.cardDefaults).task
|
|
425
452
|
if (preview === undefined) return undefined
|
|
426
453
|
return await this.commitRemote({ kind: 'create', id, input }, id)
|
|
427
454
|
? this.tasks.find(task => task.id === id)
|
|
@@ -804,18 +831,25 @@ export class BoardController {
|
|
|
804
831
|
}
|
|
805
832
|
|
|
806
833
|
/**
|
|
807
|
-
* Project a Host snapshot onto the browser's mirror.
|
|
808
|
-
*
|
|
809
|
-
* deployment constants the UI reads
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
834
|
+
* Project a Host snapshot onto the browser's mirror. Every snapshot the
|
|
835
|
+
* transport serves is a full document (bootstrap/state/action all answer
|
|
836
|
+
* `TaskBoardHostService.snapshot()`), so the deployment constants the UI reads
|
|
837
|
+
* — the session-default permission the confirmation banner compares against,
|
|
838
|
+
* the subtask depth limit, the platform switches and the extensions a provider
|
|
839
|
+
* published — are taken as published, carried over only where the snapshot
|
|
840
|
+
* itself omits the key.
|
|
813
841
|
*/
|
|
814
842
|
private mirrorOf(snapshot: TaskBoardSnapshot): HostMirror {
|
|
815
843
|
const sessionDefaultPermission = snapshot.sessionDefaultPermission ?? this.hostState?.sessionDefaultPermission
|
|
816
844
|
const maxSubtaskDepth = snapshot.maxSubtaskDepth ?? this.hostState?.maxSubtaskDepth
|
|
817
845
|
const teamRunAvailable = snapshot.teamRunAvailable ?? this.hostState?.teamRunAvailable
|
|
818
846
|
const goalRunEnabled = snapshot.goalRunEnabled ?? this.hostState?.goalRunEnabled
|
|
847
|
+
// The new-card defaults are NOT carried over: the Host publishes a target
|
|
848
|
+
// nothing configures by omitting it (protocol.ts states that explicitly), so
|
|
849
|
+
// an absent key means "this deployment configures none". Carrying the last
|
|
850
|
+
// value over would keep a CLEARED default alive in the create dialog, which
|
|
851
|
+
// is the mirror image of the staleness this key is re-read for.
|
|
852
|
+
const cardDefaults = snapshot.cardDefaults
|
|
819
853
|
const extensions = snapshot.extensions ?? this.hostState?.extensions
|
|
820
854
|
return {
|
|
821
855
|
revision: snapshot.revision,
|
|
@@ -825,6 +859,7 @@ export class BoardController {
|
|
|
825
859
|
...(maxSubtaskDepth === undefined ? {} : { maxSubtaskDepth }),
|
|
826
860
|
...(teamRunAvailable === undefined ? {} : { teamRunAvailable }),
|
|
827
861
|
...(goalRunEnabled === undefined ? {} : { goalRunEnabled }),
|
|
862
|
+
...(cardDefaults === undefined ? {} : { cardDefaults }),
|
|
828
863
|
...(extensions === undefined ? {} : { extensions }),
|
|
829
864
|
}
|
|
830
865
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 { EXECUTION_SUMMARY_LIMIT, type ExecutionSummary } from './tasks.ts'
|
|
17
|
+
|
|
18
|
+
/** Structural view of one session event, as both readers expose it. */
|
|
19
|
+
export interface SummaryEvent {
|
|
20
|
+
type?: unknown
|
|
21
|
+
seq?: unknown
|
|
22
|
+
time?: unknown
|
|
23
|
+
data?: unknown
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** One rendered content block of an assistant message, or '' when it has no prose. */
|
|
27
|
+
function blockProse(block: unknown): string {
|
|
28
|
+
if (typeof block !== 'object' || block === null) return ''
|
|
29
|
+
const row = block as Record<string, unknown>
|
|
30
|
+
// Only prose: reasoning and tool traffic are the acceptance evidence's job,
|
|
31
|
+
// and a summary that opened with a tool call would bury the conclusion.
|
|
32
|
+
return row.type === 'text' && typeof row.text === 'string' ? row.text : ''
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The assistant's own prose of one message: its text blocks joined and trimmed. */
|
|
36
|
+
function messageProse(content: unknown): string {
|
|
37
|
+
if (!Array.isArray(content)) return ''
|
|
38
|
+
return content.map(blockProse).filter(part => part !== '').join('\n').trim()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Bound one summary, keeping its tail: the closing paragraphs carry the
|
|
43
|
+
* conclusion a reader is after, and the omitted opening is announced instead of
|
|
44
|
+
* silently dropped. Mirrors the evidence reader's tail bound.
|
|
45
|
+
*/
|
|
46
|
+
export function truncateExecutionSummary(text: string, limit = EXECUTION_SUMMARY_LIMIT): string {
|
|
47
|
+
if (text.length <= limit) return text
|
|
48
|
+
const notice = '[truncated ' + String(text.length - limit) + ' chars] '
|
|
49
|
+
return notice.length >= limit ? text.slice(-limit) : notice + text.slice(-(limit - notice.length))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The summary one execution's own events support.
|
|
54
|
+
*
|
|
55
|
+
* Only events at or after `startedAt` belong to this run: a reused session
|
|
56
|
+
* carries the history of earlier executions, which must not be reported as this
|
|
57
|
+
* one's output. The last assistant message WITH prose wins — a trailing
|
|
58
|
+
* tool-call or reasoning-only message has nothing to leave behind, so the reader
|
|
59
|
+
* walks back to the last one that speaks.
|
|
60
|
+
* @param events - the session events the inspection already read.
|
|
61
|
+
* @param startedAt - the execution's start instant (ms epoch); 0 means "all".
|
|
62
|
+
* @returns the bounded summary with the seq it came from, or undefined when the
|
|
63
|
+
* run left no usable text.
|
|
64
|
+
*/
|
|
65
|
+
export function executionSummaryOf(events: readonly SummaryEvent[], startedAt: number): ExecutionSummary | undefined {
|
|
66
|
+
const own = events
|
|
67
|
+
.filter(event => typeof event.time !== 'number' || startedAt <= 0 || event.time >= startedAt)
|
|
68
|
+
.filter(event => event.type === 'assistant/message' && typeof event.seq === 'number')
|
|
69
|
+
.sort((a, b) => (a.seq as number) - (b.seq as number))
|
|
70
|
+
for (let index = own.length - 1; index >= 0; index -= 1) {
|
|
71
|
+
const event = own[index]
|
|
72
|
+
const data = typeof event.data === 'object' && event.data !== null ? event.data as Record<string, unknown> : {}
|
|
73
|
+
const message = typeof data.message === 'object' && data.message !== null ? data.message as Record<string, unknown> : {}
|
|
74
|
+
const text = messageProse(message.content)
|
|
75
|
+
if (text === '') continue
|
|
76
|
+
return { text: truncateExecutionSummary(text), seq: event.seq as number }
|
|
77
|
+
}
|
|
78
|
+
return undefined
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Repair one persisted or reported summary.
|
|
83
|
+
*
|
|
84
|
+
* A summary is informational, so an unreadable one is dropped on its own rather
|
|
85
|
+
* than costing the execution (or the task row) it hangs on. A hand-edited
|
|
86
|
+
* overlong text is bounded on the way in, so no reader ever holds more than the
|
|
87
|
+
* limit.
|
|
88
|
+
*/
|
|
89
|
+
export function normalizeExecutionSummary(value: unknown): ExecutionSummary | undefined {
|
|
90
|
+
if (typeof value !== 'object' || value === null) return undefined
|
|
91
|
+
const row = value as Record<string, unknown>
|
|
92
|
+
if (typeof row.text !== 'string' || typeof row.seq !== 'number' || !Number.isFinite(row.seq)) return undefined
|
|
93
|
+
const text = row.text.trim()
|
|
94
|
+
if (text === '') return undefined
|
|
95
|
+
return { text: truncateExecutionSummary(text), seq: row.seq }
|
|
96
|
+
}
|
package/src/core/extension.ts
CHANGED
|
@@ -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
|
|
|
17
18
|
/** Cordis service name the host and browser halves each publish. */
|
|
@@ -338,6 +339,39 @@ export interface TaskBoardHostFace {
|
|
|
338
339
|
registerExtension(extension: TaskBoardExtension): () => void
|
|
339
340
|
/** Whether the board currently runs a given extension (board x extension). */
|
|
340
341
|
isExtensionEnabled(extensionId: string): boolean
|
|
342
|
+
/**
|
|
343
|
+
* The whole ledger as the board builds it, tasks included.
|
|
344
|
+
*
|
|
345
|
+
* Part of the read/write face an IN-PROCESS consumer drives the board through
|
|
346
|
+
* (the remote bridge plugin forwarding it to a paired phone); a browser half
|
|
347
|
+
* reads the same document over the board's own HTTP surface. Forwards
|
|
348
|
+
* {@link ../host-service.ts | TaskBoardHostService.snapshot}, so nothing is
|
|
349
|
+
* interpreted between the ledger and the caller.
|
|
350
|
+
*/
|
|
351
|
+
snapshot(): TaskBoardSnapshot
|
|
352
|
+
/**
|
|
353
|
+
* Apply one action through every gate the board already has — the running
|
|
354
|
+
* lock, the permission confirmation, the subtask depth, the schedule budget —
|
|
355
|
+
* and answer the resulting snapshot.
|
|
356
|
+
*
|
|
357
|
+
* The `requestId` is the ledger's own idempotency key, so a caller that
|
|
358
|
+
* retries one envelope does not apply it twice. Refusals are the ledger's:
|
|
359
|
+
* they throw with the Host's own text, which is why this face adds no code
|
|
360
|
+
* table of its own.
|
|
361
|
+
*/
|
|
362
|
+
apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
|
|
363
|
+
/**
|
|
364
|
+
* Follow the board's change notifications. The listener receives no payload —
|
|
365
|
+
* a consumer that needs the state reads {@link snapshot} — and the returned
|
|
366
|
+
* disposer unsubscribes.
|
|
367
|
+
*/
|
|
368
|
+
subscribe(listener: () => void): () => void
|
|
369
|
+
/**
|
|
370
|
+
* The acceptance settings, the contract they resolve to right now, and the
|
|
371
|
+
* model catalog the choices come from. The same document the board's own
|
|
372
|
+
* `/verification` route serves.
|
|
373
|
+
*/
|
|
374
|
+
verificationOptions(): Promise<TaskBoardVerificationOptions>
|
|
341
375
|
}
|
|
342
376
|
|
|
343
377
|
declare module '@deepseek-ai/cordis' {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run-launch admission width: the one bound on how many sessions this board
|
|
3
|
+
* starts at the same time.
|
|
4
|
+
*
|
|
5
|
+
* One board action opens a whole subtree, and a team run hands every member of
|
|
6
|
+
* it to the Lead at once, so without a bound the Host asks DSH for dozens of
|
|
7
|
+
* sessions in a single tick. The repository's own measured guidance caps heavy
|
|
8
|
+
* implementation subagents at three (docs/multi-agent-resources.md) and no
|
|
9
|
+
* runtime mechanism enforced it; this setting is that mechanism.
|
|
10
|
+
*
|
|
11
|
+
* The bounds and the default live here rather than in either half, exactly like
|
|
12
|
+
* the roster cadence: the settings card validates a draft against the same
|
|
13
|
+
* range the Host clamps a hand-edited configuration to, and a programmatic
|
|
14
|
+
* mount that names no width gets the default.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-task-board/core/launch-width
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** Width used when neither the settings document nor the mount names one. */
|
|
20
|
+
export const DEFAULT_RUN_LAUNCH_WIDTH = 3
|
|
21
|
+
|
|
22
|
+
/** Narrowest accepted width: one launch at a time. */
|
|
23
|
+
export const RUN_LAUNCH_WIDTH_MIN = 1
|
|
24
|
+
|
|
25
|
+
/** Widest accepted width. */
|
|
26
|
+
export const RUN_LAUNCH_WIDTH_MAX = 16
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Clamp a configured width into the supported range. A value the schema would
|
|
30
|
+
* refuse (non-finite, below the floor, above the ceiling) still leaves the
|
|
31
|
+
* board launching: an out-of-range setting never stalls a run.
|
|
32
|
+
* @param width - configured width, or undefined for the default.
|
|
33
|
+
* @returns the effective width.
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeRunLaunchWidth(width: number | undefined): number {
|
|
36
|
+
if (width === undefined || !Number.isFinite(width)) return DEFAULT_RUN_LAUNCH_WIDTH
|
|
37
|
+
return Math.min(Math.max(Math.trunc(width), RUN_LAUNCH_WIDTH_MIN), RUN_LAUNCH_WIDTH_MAX)
|
|
38
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which reasoning effort one execution may actually send.
|
|
3
|
+
*
|
|
4
|
+
* The rule lives here, in one pure place, so the launch path cannot drift from
|
|
5
|
+
* what the picker promises: an effort is sent ONLY for the exact model route
|
|
6
|
+
* whose adapter declares that id. An unsupported value is dropped rather than
|
|
7
|
+
* passed through — the Host validates the selection against the same
|
|
8
|
+
* capability (`resolveCallConfig` rejects an unsupported effort) and the whole
|
|
9
|
+
* model selection would fail with it. An absent effort stays absent: the SDK
|
|
10
|
+
* then materializes the model's own default, which is exactly what "inherit
|
|
11
|
+
* the model" means.
|
|
12
|
+
*
|
|
13
|
+
* A card that pins a bare model id also gets its provider resolved here: the
|
|
14
|
+
* session wire contract requires `provider` (ModelSelection), so the catalog is
|
|
15
|
+
* the only place that can complete the documented `provider/model` or model-id
|
|
16
|
+
* pin.
|
|
17
|
+
*/
|
|
18
|
+
import type { CatalogModel, ModelCatalogView } from './verification.ts'
|
|
19
|
+
|
|
20
|
+
/** One execution route an effort resolves against: `provider/model`, or a bare model id. */
|
|
21
|
+
export interface ReasoningRoute {
|
|
22
|
+
provider?: string
|
|
23
|
+
model: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The catalog entry a route names, once the catalog can complete it. */
|
|
27
|
+
export interface DeclaredReasoningRoute {
|
|
28
|
+
provider: string
|
|
29
|
+
model: string
|
|
30
|
+
/** The adapter's reasoning metadata; absent when it exposes none. */
|
|
31
|
+
reasoning?: CatalogModel['reasoning']
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What one card's effort resolves to for one route. */
|
|
35
|
+
export interface ReasoningEffortDecision {
|
|
36
|
+
/** The effort to send; absent means "send none". */
|
|
37
|
+
effort?: string
|
|
38
|
+
/** The card's own value when it will NOT be sent. */
|
|
39
|
+
dropped?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Trim one optional effort: blank text means "not set", like every other pinned target. */
|
|
43
|
+
export function normalizeReasoningEffort(value: string | undefined): string | undefined {
|
|
44
|
+
const trimmed = value?.trim()
|
|
45
|
+
return trimmed === undefined || trimmed === '' ? undefined : trimmed
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Complete one route through the host catalog: a qualified route must match its
|
|
50
|
+
* provider group, and a bare model id matches the first group carrying it —
|
|
51
|
+
* which is the provider the request then names.
|
|
52
|
+
* @param catalog - the host model catalog, when this deployment serves one.
|
|
53
|
+
* @param route - the route as the card pins it.
|
|
54
|
+
* @returns the completed route with its reasoning metadata, or undefined when
|
|
55
|
+
* the catalog declares no such model.
|
|
56
|
+
*/
|
|
57
|
+
export function declaredRoute(
|
|
58
|
+
catalog: ModelCatalogView | undefined,
|
|
59
|
+
route: ReasoningRoute,
|
|
60
|
+
): DeclaredReasoningRoute | undefined {
|
|
61
|
+
const groups = catalog?.groups ?? []
|
|
62
|
+
const matched = route.provider === undefined || route.provider === ''
|
|
63
|
+
? groups.find(group => group.models.some(model => model.id === route.model))
|
|
64
|
+
: groups.find(group => group.id === route.provider)
|
|
65
|
+
const model = matched?.models.find(candidate => candidate.id === route.model)
|
|
66
|
+
if (matched === undefined || model === undefined) return undefined
|
|
67
|
+
return {
|
|
68
|
+
provider: matched.id,
|
|
69
|
+
model: model.id,
|
|
70
|
+
...(model.reasoning === undefined ? {} : { reasoning: model.reasoning }),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the effort one execution sends.
|
|
76
|
+
* @param requested - the card's stored effort (absent or blank = inherit).
|
|
77
|
+
* @param catalog - the host model catalog, when this deployment serves one.
|
|
78
|
+
* @param route - the route the execution will actually run at.
|
|
79
|
+
* @returns the effort to send, or the dropped value that will not be sent.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveReasoningEffort(
|
|
82
|
+
requested: string | undefined,
|
|
83
|
+
catalog: ModelCatalogView | undefined,
|
|
84
|
+
route: ReasoningRoute | undefined,
|
|
85
|
+
): ReasoningEffortDecision {
|
|
86
|
+
const effort = normalizeReasoningEffort(requested)
|
|
87
|
+
if (effort === undefined) return {}
|
|
88
|
+
if (route === undefined) return { dropped: effort }
|
|
89
|
+
const declared = declaredRoute(catalog, route)
|
|
90
|
+
const supported = declared?.reasoning?.efforts.some(option => option.id === effort) === true
|
|
91
|
+
return supported ? { effort } : { dropped: effort }
|
|
92
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
13
|
+
/** Token cap one board day may spend; 0 disables the gate. */
|
|
14
|
+
export const DEFAULT_SPEND_BUDGET_TOKENS = 0
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a day's measured spend already reached the cap.
|
|
18
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
19
|
+
* @param cap - the configured cap, 0 for "no gate".
|
|
20
|
+
* @returns true when a run must be refused.
|
|
21
|
+
*/
|
|
22
|
+
export function spendCapReached(usedTokens: number, cap: number): boolean {
|
|
23
|
+
return cap > 0 && usedTokens >= cap
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The refusal text both gates report: the thrown message a client sees as
|
|
28
|
+
* board-refused, and the scheduler error a due occurrence records.
|
|
29
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
30
|
+
* @param cap - the configured cap.
|
|
31
|
+
* @returns the refusal message.
|
|
32
|
+
*/
|
|
33
|
+
export function spendCapMessage(usedTokens: number, cap: number): string {
|
|
34
|
+
return `spend cap reached: ${usedTokens} tokens of ${cap} today; raise the cap in the task board settings`
|
|
35
|
+
}
|
package/src/core/store.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { isValidCron, isValidTimeZone } from './schedule.ts'
|
|
13
13
|
import { SCHEDULE_STOP_REASONS, isTaskPermission, isTaskStatus, normalizeTags, normalizeTargetId, type ScheduleRule, type ScheduleStopReason, type TaskFreeze, type TaskRecord, type TaskPermission, type TaskStatus } from './tasks.ts'
|
|
14
14
|
import { isExecutionOutcome } from './subtask.ts'
|
|
15
|
+
import { normalizeExecutionSummary } from './execution-summary.ts'
|
|
15
16
|
import type { TaskHandover } from './handover.ts'
|
|
16
17
|
import { sanitizeFreezeSnapshot } from './freeze-snapshot.ts'
|
|
17
18
|
import { sanitizeHandover } from './handover.ts'
|
|
@@ -68,6 +69,7 @@ function isTaskRecordShape(value: unknown): value is Omit<TaskRecord, 'status'>
|
|
|
68
69
|
if (record.parentId !== undefined && typeof record.parentId !== 'string') return false
|
|
69
70
|
if (record.workspaceId !== undefined && typeof record.workspaceId !== 'string') return false
|
|
70
71
|
if (record.mode !== undefined && typeof record.mode !== 'string') return false
|
|
72
|
+
if (record.reasoningEffort !== undefined && typeof record.reasoningEffort !== 'string') return false
|
|
71
73
|
if (record.permission !== undefined && typeof record.permission !== 'string') return false
|
|
72
74
|
if (record.integrations !== undefined && (typeof record.integrations !== 'object' || record.integrations === null || Array.isArray(record.integrations))) return false
|
|
73
75
|
if (record.hidden !== undefined && typeof record.hidden !== 'boolean') return false
|
|
@@ -255,6 +257,9 @@ export function parseLedger(raw: string | null): TaskRecord[] {
|
|
|
255
257
|
runGroupId: normalizeTargetId(execution.runGroupId),
|
|
256
258
|
ownResult: isExecutionOutcome(execution.ownResult) ? execution.ownResult : undefined,
|
|
257
259
|
ownError: typeof execution.ownError === 'string' ? execution.ownError : undefined,
|
|
260
|
+
// A summary a reader does not recognize (an older document has none) is
|
|
261
|
+
// simply absent; a malformed one is dropped without costing the run.
|
|
262
|
+
summary: normalizeExecutionSummary(execution.summary),
|
|
258
263
|
// A malformed acceptance block is dropped rather than dropping the
|
|
259
264
|
// execution record: the board then treats that run as unverified.
|
|
260
265
|
verification: normalizeVerification(execution.verification),
|
|
@@ -265,6 +270,10 @@ export function parseLedger(raw: string | null): TaskRecord[] {
|
|
|
265
270
|
// fall back to the session default instead of dropping the row.
|
|
266
271
|
task.workspaceId = normalizeTargetId(row.workspaceId)
|
|
267
272
|
task.mode = normalizeTargetId(row.mode)
|
|
273
|
+
// The effort is repaired like the other execution-target strings: blank text
|
|
274
|
+
// from a hand-edited document clears the pin instead of dropping the row,
|
|
275
|
+
// and the card then runs at its model's own default level.
|
|
276
|
+
task.reasoningEffort = normalizeTargetId(row.reasoningEffort)
|
|
268
277
|
task.archivedAt = typeof row.archivedAt === 'number' && Number.isFinite(row.archivedAt) ? row.archivedAt : undefined
|
|
269
278
|
task.permission = isTaskPermission(row.permission) ? row.permission as TaskPermission : undefined
|
|
270
279
|
task.reuseSession = row.reuseSession === true ? true : undefined
|