@linxin666/dsh-client-ui-task-board-team 0.0.0-stage → 0.4.14
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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +66 -2
- package/README.zh.md +67 -0
- package/cordis.patch.yml +14 -0
- package/icon.svg +3 -0
- package/lib/client.js +1490 -0
- package/lib/index.js +2968 -0
- package/lib/types/client/PluginSettingsCard.d.ts +255 -0
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/index.d.ts +58 -0
- package/lib/types/client/locales.d.ts +90 -0
- package/lib/types/client/optional-service.d.ts +22 -0
- package/lib/types/client/settings-form.d.ts +235 -0
- package/lib/types/client/team/extension.d.ts +29 -0
- package/lib/types/client/team/sections.d.ts +38 -0
- package/lib/types/client/team/settings.d.ts +67 -0
- package/lib/types/client/team/summary.d.ts +34 -0
- package/lib/types/core/contract.d.ts +269 -0
- package/lib/types/core/hub-protocol.d.ts +175 -0
- package/lib/types/core/identity.d.ts +96 -0
- package/lib/types/core/mirror.d.ts +51 -0
- package/lib/types/core/question-report.d.ts +84 -0
- package/lib/types/core/settlement.d.ts +49 -0
- package/lib/types/core/task-record.d.ts +59 -0
- package/lib/types/core/timers.d.ts +20 -0
- package/lib/types/host/bindings.d.ts +92 -0
- package/lib/types/host/channel.d.ts +44 -0
- package/lib/types/host/credentials.d.ts +63 -0
- package/lib/types/host/extension.d.ts +57 -0
- package/lib/types/host/hub-client.d.ts +157 -0
- package/lib/types/host/questions.d.ts +105 -0
- package/lib/types/host/service.d.ts +209 -0
- package/lib/types/host/setup.d.ts +152 -0
- package/lib/types/host/tools.d.ts +19 -0
- package/lib/types/host/waterfall.d.ts +39 -0
- package/lib/types/index.d.ts +152 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +84 -3
- package/src/client/PluginSettingsCard.tsx +838 -0
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +139 -0
- package/src/client/locales.ts +168 -0
- package/src/client/optional-service.ts +30 -0
- package/src/client/settings-card.module.css +821 -0
- package/src/client/settings-form.ts +510 -0
- package/src/client/team/extension.ts +185 -0
- package/src/client/team/sections.tsx +159 -0
- package/src/client/team/settings.tsx +348 -0
- package/src/client/team/summary.ts +156 -0
- package/src/client/team/team.module.css +193 -0
- package/src/core/contract.ts +326 -0
- package/src/core/hub-protocol.ts +217 -0
- package/src/core/identity.ts +193 -0
- package/src/core/mirror.ts +88 -0
- package/src/core/question-report.ts +144 -0
- package/src/core/settlement.ts +84 -0
- package/src/core/task-record.ts +65 -0
- package/src/core/timers.ts +34 -0
- package/src/host/bindings.ts +211 -0
- package/src/host/channel.ts +97 -0
- package/src/host/credentials.ts +147 -0
- package/src/host/extension.ts +197 -0
- package/src/host/hub-client.ts +287 -0
- package/src/host/questions.ts +275 -0
- package/src/host/service.ts +1421 -0
- package/src/host/setup.ts +259 -0
- package/src/host/tools.ts +70 -0
- package/src/host/waterfall.ts +51 -0
- package/src/index.ts +452 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settlement one finished execution reports to the hub.
|
|
3
|
+
*
|
|
4
|
+
* The board owns the execution verdict and the hub owns the collaboration
|
|
5
|
+
* status, so this module is the whole mapping between them: a passed automated
|
|
6
|
+
* acceptance becomes `succeeded` (the hub moves the issue to `in_review`), and
|
|
7
|
+
* every other outcome — including a cancelled run — becomes `failed`, because a
|
|
8
|
+
* card the Host stopped never earned a human review. The summary is clipped to
|
|
9
|
+
* the character cap the protocol fixes (section 13), which mirrors the board's
|
|
10
|
+
* own execution-summary limit.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-task-board-team/core/settlement
|
|
13
|
+
*/
|
|
14
|
+
import { EXECUTION_SUMMARY_LIMIT } from './hub-protocol.ts'
|
|
15
|
+
import type { ExecutionOutcome, TaskRecord } from './task-record.ts'
|
|
16
|
+
|
|
17
|
+
/** The body one settlement write-back sends. */
|
|
18
|
+
export interface SettleRequestBody {
|
|
19
|
+
outcome: 'succeeded' | 'failed'
|
|
20
|
+
summary: string
|
|
21
|
+
error?: string
|
|
22
|
+
/**
|
|
23
|
+
* The attempt this settlement belongs to.
|
|
24
|
+
*
|
|
25
|
+
* The hub keeps it optional, but a lease that expired while the run was still
|
|
26
|
+
* going is only accepted when the attempt matches: presenting it is what lets a
|
|
27
|
+
* long execution report its own result instead of having it refused as stale.
|
|
28
|
+
*/
|
|
29
|
+
execution_attempt_id?: string
|
|
30
|
+
/**
|
|
31
|
+
* What the Host itself verified, in the shape the frozen settlement sample
|
|
32
|
+
* shows. It is the local evidence a reviewer reads next to the outcome.
|
|
33
|
+
*/
|
|
34
|
+
verification_evidence?: Record<string, unknown>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Map one execution outcome onto the hub's settlement vocabulary.
|
|
39
|
+
* @param outcome - the board's own verdict.
|
|
40
|
+
* @returns `succeeded` only for a passed run.
|
|
41
|
+
*/
|
|
42
|
+
export function settleOutcome(outcome: ExecutionOutcome): 'succeeded' | 'failed' {
|
|
43
|
+
return outcome === 'succeeded' ? 'succeeded' : 'failed'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Clip one summary to the protocol's character cap.
|
|
48
|
+
* @param text - the text to clip.
|
|
49
|
+
* @returns text of at most {@link EXECUTION_SUMMARY_LIMIT} characters.
|
|
50
|
+
*/
|
|
51
|
+
export function clipSummary(text: string): string {
|
|
52
|
+
if (text.length <= EXECUTION_SUMMARY_LIMIT) return text
|
|
53
|
+
return text.slice(0, EXECUTION_SUMMARY_LIMIT - 3) + '...'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Build the settlement body for one settled execution.
|
|
58
|
+
*
|
|
59
|
+
* The summary names the run and what it produced, so a reviewer reading the hub
|
|
60
|
+
* sees which attempt this was without opening the Host: the card title, the
|
|
61
|
+
* attempt id and, on a failure, the recorded reason.
|
|
62
|
+
* @param input - the settlement event and the card it belongs to.
|
|
63
|
+
* @returns the body to post.
|
|
64
|
+
*/
|
|
65
|
+
export function buildSettleRequest(input: {
|
|
66
|
+
task: TaskRecord
|
|
67
|
+
executionId: string
|
|
68
|
+
outcome: ExecutionOutcome
|
|
69
|
+
error?: string
|
|
70
|
+
/** Attempt the card was claimed under, when the payload still records one. */
|
|
71
|
+
attemptId?: string
|
|
72
|
+
}): SettleRequestBody {
|
|
73
|
+
const outcome = settleOutcome(input.outcome)
|
|
74
|
+
const lines = [
|
|
75
|
+
`${input.task.title} — ${outcome === 'succeeded' ? 'automated acceptance passed' : 'automated acceptance did not pass'}`,
|
|
76
|
+
`attempt: ${input.executionId}`,
|
|
77
|
+
]
|
|
78
|
+
if (input.error !== undefined && input.error.trim() !== '') lines.push(`reason: ${input.error.trim()}`)
|
|
79
|
+
const body: SettleRequestBody = { outcome, summary: clipSummary(lines.join('\n')) }
|
|
80
|
+
if (input.error !== undefined && input.error.trim() !== '') body.error = clipSummary(input.error.trim())
|
|
81
|
+
if (input.attemptId !== undefined) body.execution_attempt_id = input.attemptId
|
|
82
|
+
body.verification_evidence = { execution_id: input.executionId, outcome }
|
|
83
|
+
return body
|
|
84
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural view of the task-board vocabulary this extension reads.
|
|
3
|
+
*
|
|
4
|
+
* The extension is a separate bundle and may not import the board's internals,
|
|
5
|
+
* so it restates the record shape the provider contract hands it. These are
|
|
6
|
+
* read-only structural declarations: the board's own values satisfy them and
|
|
7
|
+
* nothing here is constructed by the board.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-task-board-team/core/task-record
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Column a card occupies. */
|
|
13
|
+
export type TaskStatus = 'backlog' | 'todo' | 'running' | 'done' | 'failed'
|
|
14
|
+
|
|
15
|
+
/** Settlement of one execution. */
|
|
16
|
+
export type ExecutionOutcome = 'succeeded' | 'failed' | 'cancelled'
|
|
17
|
+
|
|
18
|
+
/** One execution of a card, as a provider reads it. */
|
|
19
|
+
export interface ExecutionRecord {
|
|
20
|
+
/** Stable execution id. */
|
|
21
|
+
id: string
|
|
22
|
+
/** Session the execution runs in, once one was opened. */
|
|
23
|
+
sessionId?: string | undefined
|
|
24
|
+
/** Instant the execution started (ms epoch). */
|
|
25
|
+
startedAt: number
|
|
26
|
+
/** Instant the execution settled (ms epoch), absent while it runs. */
|
|
27
|
+
endedAt?: number | undefined
|
|
28
|
+
/** Settlement, absent while the execution is still running. */
|
|
29
|
+
result?: ExecutionOutcome | undefined
|
|
30
|
+
/** Human failure text when the run failed. */
|
|
31
|
+
error?: string | undefined
|
|
32
|
+
/** Rework instructions this execution carries, when a run was sent back. */
|
|
33
|
+
rework?: { instructions?: string } | undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One card, as a provider reads it through the capability face. */
|
|
37
|
+
export interface TaskRecord {
|
|
38
|
+
id: string
|
|
39
|
+
title: string
|
|
40
|
+
description: string
|
|
41
|
+
prompt: string
|
|
42
|
+
status: TaskStatus
|
|
43
|
+
createdAt: number
|
|
44
|
+
updatedAt: number
|
|
45
|
+
parentId?: string
|
|
46
|
+
workspaceId?: string
|
|
47
|
+
/** Agent preset the card's execution must be composed from. */
|
|
48
|
+
mode?: string
|
|
49
|
+
hidden?: boolean
|
|
50
|
+
archivedAt?: number
|
|
51
|
+
executions: ExecutionRecord[]
|
|
52
|
+
tags?: ReadonlyArray<{ name: string }>
|
|
53
|
+
/** Opaque provider payloads, keyed by extension id. */
|
|
54
|
+
integrations?: Record<string, unknown>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether one card still occupies a column the board calls unfinished. */
|
|
58
|
+
export function isOpenTask(task: TaskRecord): boolean {
|
|
59
|
+
return task.archivedAt === undefined && task.status !== 'done' && task.status !== 'failed'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Whether one card currently has an execution the board has not settled. */
|
|
63
|
+
export function hasOpenExecution(task: TaskRecord): boolean {
|
|
64
|
+
return task.executions.some(execution => execution.result === undefined)
|
|
65
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timer seat the team sync service schedules through.
|
|
3
|
+
*
|
|
4
|
+
* The extension never reaches for a global timer directly: the Host entry
|
|
5
|
+
* injects the timer face, so heartbeats, lease renewals and reconnect backoff
|
|
6
|
+
* are observable and cancellable under fake timers without patching globals.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-task-board-team/core/timers
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** The timer operations this provider needs, each returning its own canceller. */
|
|
12
|
+
export interface HostTimerFace {
|
|
13
|
+
/** Run `callback` once after `delay` ms. */
|
|
14
|
+
timeout(callback: () => void, delay: number): () => void
|
|
15
|
+
/** Run `callback` every `delay` ms. */
|
|
16
|
+
interval(callback: () => void, delay: number): () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The process timer face: what a real Host mount uses. */
|
|
20
|
+
export const processTimers: HostTimerFace = {
|
|
21
|
+
timeout(callback, delay) {
|
|
22
|
+
const handle = setTimeout(callback, delay)
|
|
23
|
+
handle.unref?.()
|
|
24
|
+
return () => { clearTimeout(handle) }
|
|
25
|
+
},
|
|
26
|
+
interval(callback, delay) {
|
|
27
|
+
const handle = setInterval(callback, delay)
|
|
28
|
+
handle.unref?.()
|
|
29
|
+
return () => { clearInterval(handle) }
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One clock the service reads; injectable so tests can pin time. */
|
|
34
|
+
export type Clock = () => number
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which local agents this Host registers with the hub.
|
|
3
|
+
*
|
|
4
|
+
* dsh-agents owns the member definitions and writes them to
|
|
5
|
+
* `$DSH_HOME/dsh-agents/ledger.json`; it serves no cordis service for them, so
|
|
6
|
+
* this module reads that ledger file directly, read-only and tolerantly. A
|
|
7
|
+
* missing file, an unreadable one, or a document from another revision leaves
|
|
8
|
+
* the binding list empty and reports why — the Host keeps running, it simply
|
|
9
|
+
* claims nothing, which is the safe direction for a machine that would
|
|
10
|
+
* otherwise execute somebody else's work.
|
|
11
|
+
*
|
|
12
|
+
* The binding itself is a member id: the name, preset and workspace always come
|
|
13
|
+
* from the member definition, never from the browser, so a settings edit can
|
|
14
|
+
* point at a member but cannot invent one.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-task-board-team/host/bindings
|
|
17
|
+
*/
|
|
18
|
+
import { readFile } from 'node:fs/promises'
|
|
19
|
+
import { homedir } from 'node:os'
|
|
20
|
+
import { join } from 'node:path'
|
|
21
|
+
|
|
22
|
+
/** The plugin directory dsh-agents keeps under the DSH home. */
|
|
23
|
+
export const AGENTS_HOME_DIRECTORY = 'dsh-agents'
|
|
24
|
+
|
|
25
|
+
/** The ledger file dsh-agents writes its teams and members into. */
|
|
26
|
+
export const AGENTS_LEDGER_FILE = 'ledger.json'
|
|
27
|
+
|
|
28
|
+
/** One member definition, as the agents ledger stores it. */
|
|
29
|
+
export interface AgentsMemberDefinition {
|
|
30
|
+
id: string
|
|
31
|
+
teamId: string
|
|
32
|
+
name: string
|
|
33
|
+
preset?: string
|
|
34
|
+
permission?: 'read-only' | 'workspace-write' | 'danger-full-access'
|
|
35
|
+
model?: string
|
|
36
|
+
reasoningEffort?: string
|
|
37
|
+
brief?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** One team in the agents ledger. */
|
|
41
|
+
export interface AgentsTeamDefinition {
|
|
42
|
+
id: string
|
|
43
|
+
name: string
|
|
44
|
+
workspaceId?: string
|
|
45
|
+
members: AgentsMemberDefinition[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What this module reads out of the agents ledger. */
|
|
49
|
+
export interface AgentsLedgerView {
|
|
50
|
+
teams: AgentsTeamDefinition[]
|
|
51
|
+
/** Why the ledger could not be read, when it could not. */
|
|
52
|
+
problem?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One member this Host binds as a team Agent. */
|
|
56
|
+
export interface BoundAgent {
|
|
57
|
+
/** dsh-agents member id. */
|
|
58
|
+
memberId: string
|
|
59
|
+
/** Team the member belongs to. */
|
|
60
|
+
teamId: string
|
|
61
|
+
/** Team name, for the operator. */
|
|
62
|
+
teamName: string
|
|
63
|
+
/** Name the hub resolves mentions by. */
|
|
64
|
+
name: string
|
|
65
|
+
/** Agent preset the member definition pins. */
|
|
66
|
+
preset?: string
|
|
67
|
+
/** Model the member definition pins. */
|
|
68
|
+
model?: string
|
|
69
|
+
/** Reasoning effort the member definition pins for that model. */
|
|
70
|
+
reasoningEffort?: string
|
|
71
|
+
/** Workspace the member's team pins, so the mirror card runs where the member does. */
|
|
72
|
+
workspaceId?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One configured binding, as the settings entry stores it. */
|
|
76
|
+
export interface TeamAgentBinding {
|
|
77
|
+
/** dsh-agents member id to bind. */
|
|
78
|
+
memberId: string
|
|
79
|
+
/** Name the hub resolves mentions by; empty falls back to the member's own name. */
|
|
80
|
+
name?: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the DSH home directory the way every other plugin does.
|
|
85
|
+
* @param env - process environment.
|
|
86
|
+
* @param home - platform home fallback (test seam).
|
|
87
|
+
* @returns the absolute DSH home path.
|
|
88
|
+
*/
|
|
89
|
+
export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
90
|
+
const raw = env.DSH_HOME
|
|
91
|
+
if (raw !== undefined && raw.trim() !== '') {
|
|
92
|
+
const value = raw.trim()
|
|
93
|
+
if (value.startsWith('~')) return join(home, value.slice(1))
|
|
94
|
+
return value.startsWith('/') || /^[A-Za-z]:[\\/]/.test(value) ? value : join(process.cwd(), value)
|
|
95
|
+
}
|
|
96
|
+
return join(home, '.dsh')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Resolve the path of the agents ledger file.
|
|
101
|
+
* @param env - process environment.
|
|
102
|
+
* @param home - platform home fallback (test seam).
|
|
103
|
+
* @returns the absolute ledger path.
|
|
104
|
+
*/
|
|
105
|
+
export function agentsLedgerPath(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
106
|
+
return join(resolveDshHome(env, home), AGENTS_HOME_DIRECTORY, AGENTS_LEDGER_FILE)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Read the agents ledger as a member-definition view.
|
|
111
|
+
*
|
|
112
|
+
* Anything unexpected reads as an empty binding list with a reason instead of an
|
|
113
|
+
* exception: this Host has to keep working when dsh-agents is not installed, and
|
|
114
|
+
* a half-written ledger must never turn into a claim of somebody else's work.
|
|
115
|
+
* @param read - file reader seam, defaulting to the filesystem.
|
|
116
|
+
* @returns the teams it found, plus why it found none when that is the case.
|
|
117
|
+
*/
|
|
118
|
+
export async function readAgentsLedger(
|
|
119
|
+
file: string,
|
|
120
|
+
read: (path: string) => Promise<string> = async path => await readFile(path, 'utf8'),
|
|
121
|
+
): Promise<AgentsLedgerView> {
|
|
122
|
+
let raw: string
|
|
123
|
+
try {
|
|
124
|
+
raw = await read(file)
|
|
125
|
+
} catch {
|
|
126
|
+
return { teams: [], problem: 'the dsh-agents ledger is not readable at ' + file }
|
|
127
|
+
}
|
|
128
|
+
let parsed: unknown
|
|
129
|
+
try {
|
|
130
|
+
parsed = JSON.parse(raw)
|
|
131
|
+
} catch {
|
|
132
|
+
return { teams: [], problem: 'the dsh-agents ledger at ' + file + ' is not valid JSON' }
|
|
133
|
+
}
|
|
134
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
135
|
+
return { teams: [], problem: 'the dsh-agents ledger at ' + file + ' has an unknown shape' }
|
|
136
|
+
}
|
|
137
|
+
const rawTeams = (parsed as { teams?: unknown }).teams
|
|
138
|
+
if (!Array.isArray(rawTeams)) return { teams: [], problem: 'the dsh-agents ledger at ' + file + ' lists no teams' }
|
|
139
|
+
const teams: AgentsTeamDefinition[] = []
|
|
140
|
+
for (const entry of rawTeams) {
|
|
141
|
+
if (typeof entry !== 'object' || entry === null) continue
|
|
142
|
+
const team = entry as Record<string, unknown>
|
|
143
|
+
if (typeof team.id !== 'string' || typeof team.name !== 'string') continue
|
|
144
|
+
const members: AgentsMemberDefinition[] = []
|
|
145
|
+
for (const rawMember of Array.isArray(team.members) ? team.members : []) {
|
|
146
|
+
if (typeof rawMember !== 'object' || rawMember === null) continue
|
|
147
|
+
const member = rawMember as Record<string, unknown>
|
|
148
|
+
if (typeof member.id !== 'string' || typeof member.name !== 'string') continue
|
|
149
|
+
members.push({
|
|
150
|
+
id: member.id,
|
|
151
|
+
teamId: team.id,
|
|
152
|
+
name: member.name,
|
|
153
|
+
...(typeof member.preset === 'string' && member.preset !== '' ? { preset: member.preset } : {}),
|
|
154
|
+
...(typeof member.brief === 'string' && member.brief !== '' ? { brief: member.brief } : {}),
|
|
155
|
+
...(typeof member.model === 'string' && member.model !== '' ? { model: member.model } : {}),
|
|
156
|
+
...(typeof member.reasoningEffort === 'string' && member.reasoningEffort !== '' ? { reasoningEffort: member.reasoningEffort } : {}),
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
teams.push({
|
|
160
|
+
id: team.id,
|
|
161
|
+
name: team.name,
|
|
162
|
+
...(typeof team.workspaceId === 'string' && team.workspaceId !== '' ? { workspaceId: team.workspaceId } : {}),
|
|
163
|
+
members,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
return teams.length === 0
|
|
167
|
+
? { teams, problem: 'the dsh-agents ledger at ' + file + ' defines no team' }
|
|
168
|
+
: { teams }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Project configured bindings onto the member definitions they name.
|
|
173
|
+
*
|
|
174
|
+
* A binding whose member no longer exists is reported and skipped: the hub keeps
|
|
175
|
+
* the agent record it already has, and this Host simply stops claiming for it,
|
|
176
|
+
* which is what an operator unpublishing a member means.
|
|
177
|
+
* @param bindings - the configured member ids.
|
|
178
|
+
* @param view - the members read out of the agents ledger.
|
|
179
|
+
* @returns the resolved agents and one problem line per unusable binding.
|
|
180
|
+
*/
|
|
181
|
+
export function resolveBindings(
|
|
182
|
+
bindings: readonly TeamAgentBinding[],
|
|
183
|
+
view: AgentsLedgerView,
|
|
184
|
+
): { agents: BoundAgent[]; problems: string[] } {
|
|
185
|
+
const agents: BoundAgent[] = []
|
|
186
|
+
const problems: string[] = []
|
|
187
|
+
const seen = new Set<string>()
|
|
188
|
+
for (const binding of bindings) {
|
|
189
|
+
const memberId = binding.memberId.trim()
|
|
190
|
+
if (memberId === '' || seen.has(memberId)) continue
|
|
191
|
+
seen.add(memberId)
|
|
192
|
+
const team = view.teams.find(candidate => candidate.members.some(member => member.id === memberId))
|
|
193
|
+
const member = team?.members.find(candidate => candidate.id === memberId)
|
|
194
|
+
if (team === undefined || member === undefined) {
|
|
195
|
+
problems.push('the bound member ' + memberId + ' is not defined in the dsh-agents ledger')
|
|
196
|
+
continue
|
|
197
|
+
}
|
|
198
|
+
const name = binding.name !== undefined && binding.name.trim() !== '' ? binding.name.trim() : member.name
|
|
199
|
+
agents.push({
|
|
200
|
+
memberId,
|
|
201
|
+
teamId: team.id,
|
|
202
|
+
teamName: team.name,
|
|
203
|
+
name,
|
|
204
|
+
...(member.preset === undefined ? {} : { preset: member.preset }),
|
|
205
|
+
...(member.model === undefined ? {} : { model: member.model }),
|
|
206
|
+
...(member.reasoningEffort === undefined ? {} : { reasoningEffort: member.reasoningEffort }),
|
|
207
|
+
...(team.workspaceId === undefined ? {} : { workspaceId: team.workspaceId }),
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
return { agents, problems }
|
|
211
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team channel: the WebSocket the hub pushes events over.
|
|
3
|
+
*
|
|
4
|
+
* Both halves of the transport live here rather than in the sync service: the
|
|
5
|
+
* URL is derived from the configured hub (http becomes ws), and one socket is
|
|
6
|
+
* a thin wrapper over whatever the deployment's WebSocket constructor is. The
|
|
7
|
+
* reconnect policy stays with the service, because only it knows whether a
|
|
8
|
+
* dropped connection is a lease-ending outage or a quiet restart.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-task-board-team/host/channel
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** One open socket, as the service drives it. */
|
|
14
|
+
export interface SocketLike {
|
|
15
|
+
/** Send one text frame. */
|
|
16
|
+
send(data: string): void
|
|
17
|
+
/** Close the connection; a later close event is not reported again. */
|
|
18
|
+
close(): void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What one socket reports back. */
|
|
22
|
+
export interface SocketHandlers {
|
|
23
|
+
/** One decoded text frame. */
|
|
24
|
+
message(data: string): void
|
|
25
|
+
/** The connection ended; the service decides whether to reconnect. */
|
|
26
|
+
closed(reason?: string): void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Open one socket at `url`, presenting `headers` on the upgrade, and wire its handlers. */
|
|
30
|
+
export type ConnectSocket = (url: string, handlers: SocketHandlers, headers: Record<string, string>) => SocketLike
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Derive the team channel URL for one hub. The Host Token never travels in the
|
|
34
|
+
* URL; it rides the upgrade's Authorization header (see {@link teamSocketHeaders}).
|
|
35
|
+
* @param hubUrl - configured hub base URL (http/https or ws/wss).
|
|
36
|
+
* @param teamId - team the channel belongs to.
|
|
37
|
+
* @param sinceSeq - last event sequence this Host saw; 0 asks for a full replay.
|
|
38
|
+
* @returns the absolute WebSocket URL.
|
|
39
|
+
*/
|
|
40
|
+
export function teamSocketUrl(hubUrl: string, teamId: string, sinceSeq: number): string {
|
|
41
|
+
const base = hubUrl.trim().replace(/\/+$/, '')
|
|
42
|
+
const socketBase = base.replace(/^http(s?):\/\//i, 'ws$1://')
|
|
43
|
+
const path = '/api/v1/teams/' + encodeURIComponent(teamId) + '/ws'
|
|
44
|
+
const query = '?since_seq=' + String(Math.max(0, Math.floor(sinceSeq)))
|
|
45
|
+
+ '&protocol_version=' + encodeURIComponent('1.0.0')
|
|
46
|
+
return socketBase + path + query
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The upgrade headers the hub authenticates a Host channel with.
|
|
51
|
+
* @param token - Host Token the handshake presents.
|
|
52
|
+
* @returns the Authorization and protocol version headers.
|
|
53
|
+
*/
|
|
54
|
+
export function teamSocketHeaders(token: string): Record<string, string> {
|
|
55
|
+
return { Authorization: 'Bearer ' + token, 'X-Team-Hub-Protocol-Version': '1.0.0' }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The platform constructor with the init form the Host runtime accepts (headers on the upgrade). */
|
|
59
|
+
type HeaderedWebSocket = new (url: string, init: { headers: Record<string, string> }) => WebSocket
|
|
60
|
+
|
|
61
|
+
/** The default socket factory: the platform WebSocket, with the headers on the upgrade. */
|
|
62
|
+
export const platformSocket: ConnectSocket = (url, handlers, headers) => {
|
|
63
|
+
const socket = new (WebSocket as unknown as HeaderedWebSocket)(url, { headers })
|
|
64
|
+
let closed = false
|
|
65
|
+
socket.addEventListener('message', event => {
|
|
66
|
+
const data = (event as { data?: unknown }).data
|
|
67
|
+
if (typeof data === 'string') handlers.message(data)
|
|
68
|
+
})
|
|
69
|
+
socket.addEventListener('close', event => {
|
|
70
|
+
if (closed) return
|
|
71
|
+
closed = true
|
|
72
|
+
handlers.closed((event as { reason?: string }).reason)
|
|
73
|
+
})
|
|
74
|
+
socket.addEventListener('error', () => {
|
|
75
|
+
// A transport error is always followed by a close event on this platform;
|
|
76
|
+
// reporting it here as well would schedule two reconnects for one failure.
|
|
77
|
+
})
|
|
78
|
+
return {
|
|
79
|
+
send(data) {
|
|
80
|
+
if (closed) return
|
|
81
|
+
try {
|
|
82
|
+
socket.send(data)
|
|
83
|
+
} catch {
|
|
84
|
+
// A send racing a close is not a decision this layer makes.
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
close() {
|
|
88
|
+
if (closed) return
|
|
89
|
+
closed = true
|
|
90
|
+
try {
|
|
91
|
+
socket.close()
|
|
92
|
+
} catch {
|
|
93
|
+
// Already gone.
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side custody of the team-hub Host Token.
|
|
3
|
+
*
|
|
4
|
+
* The token is a credential, so it lives where the harness keeps credentials —
|
|
5
|
+
* never in this extension's own settings entry, never in a board snapshot, never
|
|
6
|
+
* in a published summary and never in any agent payload. The browser sends a
|
|
7
|
+
* pasted value exactly once; the host half stores it and afterwards only reports
|
|
8
|
+
* whether one is configured, where it came from and whether it can be written.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-task-board-team/host/credentials
|
|
11
|
+
*/
|
|
12
|
+
import { credentialRef, isCredentialRefName } from '@deepseek-ai/dsh-credentials'
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
14
|
+
|
|
15
|
+
/** Credential reference name the Host Token is stored under by default. */
|
|
16
|
+
export const DEFAULT_TOKEN_REF = 'DSH_TEAM_HUB_TOKEN'
|
|
17
|
+
|
|
18
|
+
/** Credential facts one reference reports; no slot carries a value. */
|
|
19
|
+
interface CredentialInfo {
|
|
20
|
+
configured: boolean
|
|
21
|
+
source?: string
|
|
22
|
+
writable: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The slice of the credential seam this extension uses. */
|
|
26
|
+
export interface CredentialFace {
|
|
27
|
+
resolve(ref: unknown): Promise<{ value: string; source?: string } | undefined>
|
|
28
|
+
describe(ref: unknown): Promise<CredentialInfo>
|
|
29
|
+
set(ref: unknown, value: string): Promise<void>
|
|
30
|
+
unset(ref: unknown): Promise<void>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the optional credential service without declaring a required
|
|
35
|
+
* injection: a deployment that serves none keeps working on the environment.
|
|
36
|
+
* @param ctx - host context.
|
|
37
|
+
* @returns the seam, or undefined.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveCredentialFace(ctx: Context): CredentialFace | undefined {
|
|
40
|
+
try {
|
|
41
|
+
const get = (ctx as { get?: (name: string) => unknown }).get
|
|
42
|
+
if (typeof get !== 'function') return undefined
|
|
43
|
+
const face = get.call(ctx, 'credentials') as CredentialFace | undefined
|
|
44
|
+
if (face === undefined) return undefined
|
|
45
|
+
const usable = typeof face.resolve === 'function'
|
|
46
|
+
&& typeof face.describe === 'function'
|
|
47
|
+
&& typeof face.set === 'function'
|
|
48
|
+
&& typeof face.unset === 'function'
|
|
49
|
+
return usable ? face : undefined
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The ambient fallback: the configured reference name only. */
|
|
56
|
+
function ambientToken(env: Record<string, string | undefined>, ref: string): string | undefined {
|
|
57
|
+
const value = env[ref]
|
|
58
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Report one reference's credential facts for a settings surface.
|
|
63
|
+
* @param ctx - host context.
|
|
64
|
+
* @param ref - the configured reference name.
|
|
65
|
+
* @param env - environment consulted for the ambient fallback.
|
|
66
|
+
* @returns the status the settings section renders.
|
|
67
|
+
*/
|
|
68
|
+
export async function describeHostToken(
|
|
69
|
+
ctx: Context,
|
|
70
|
+
ref: string,
|
|
71
|
+
env: Record<string, string | undefined> = process.env,
|
|
72
|
+
): Promise<{ configured: boolean; writable: boolean; source?: string; ref: string }> {
|
|
73
|
+
const face = resolveCredentialFace(ctx)
|
|
74
|
+
let info: CredentialInfo | undefined
|
|
75
|
+
if (face !== undefined && isCredentialRefName(ref)) {
|
|
76
|
+
try {
|
|
77
|
+
info = await face.describe(credentialRef(ref))
|
|
78
|
+
} catch {
|
|
79
|
+
info = undefined
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const ambient = ambientToken(env, ref)
|
|
83
|
+
if (info !== undefined && info.configured) {
|
|
84
|
+
return {
|
|
85
|
+
configured: true,
|
|
86
|
+
writable: info.writable,
|
|
87
|
+
ref,
|
|
88
|
+
...(info.source === undefined ? {} : { source: info.source }),
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (ambient !== undefined) {
|
|
92
|
+
return { configured: true, writable: info?.writable ?? false, ref, source: 'environment' }
|
|
93
|
+
}
|
|
94
|
+
return { configured: false, writable: info?.writable ?? face !== undefined, ref }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolve the effective Host Token for one reference.
|
|
99
|
+
* @param ctx - host context.
|
|
100
|
+
* @param ref - the configured reference name.
|
|
101
|
+
* @param env - environment consulted for the ambient fallback.
|
|
102
|
+
* @returns the token, or undefined when none is configured.
|
|
103
|
+
*/
|
|
104
|
+
export async function resolveHostToken(
|
|
105
|
+
ctx: Context,
|
|
106
|
+
ref: string,
|
|
107
|
+
env: Record<string, string | undefined> = process.env,
|
|
108
|
+
): Promise<string | undefined> {
|
|
109
|
+
if (ref.trim() === '') return undefined
|
|
110
|
+
const face = resolveCredentialFace(ctx)
|
|
111
|
+
if (face !== undefined && isCredentialRefName(ref)) {
|
|
112
|
+
try {
|
|
113
|
+
const resolved = await face.resolve(credentialRef(ref))
|
|
114
|
+
if (resolved?.value !== undefined && resolved.value.trim() !== '') return resolved.value.trim()
|
|
115
|
+
} catch {
|
|
116
|
+
// An unreadable store falls through to the environment.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return ambientToken(env, ref)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Store one Host Token in the credential seam.
|
|
124
|
+
* @param ctx - host context.
|
|
125
|
+
* @param ref - the reference to write.
|
|
126
|
+
* @param token - the secret value.
|
|
127
|
+
* @throws when no credential store is served or the store refuses the write.
|
|
128
|
+
*/
|
|
129
|
+
export async function setHostToken(ctx: Context, ref: string, token: string): Promise<void> {
|
|
130
|
+
const face = resolveCredentialFace(ctx)
|
|
131
|
+
if (face === undefined) throw new Error('this deployment serves no credential store; set the Host Token through the environment instead')
|
|
132
|
+
if (!isCredentialRefName(ref)) throw new Error('"' + ref + '" is not a valid credential reference name')
|
|
133
|
+
await face.set(credentialRef(ref), token)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Remove one stored Host Token. Absent values are a no-op.
|
|
138
|
+
* @param ctx - host context.
|
|
139
|
+
* @param ref - the reference to clear.
|
|
140
|
+
* @throws when no credential store is served.
|
|
141
|
+
*/
|
|
142
|
+
export async function clearHostToken(ctx: Context, ref: string): Promise<void> {
|
|
143
|
+
const face = resolveCredentialFace(ctx)
|
|
144
|
+
if (face === undefined) throw new Error('this deployment serves no credential store')
|
|
145
|
+
if (!isCredentialRefName(ref)) throw new Error('"' + ref + '" is not a valid credential reference name')
|
|
146
|
+
await face.unset(credentialRef(ref))
|
|
147
|
+
}
|