@linxin666/dsh-client-ui-task-board-team 0.0.0-stage → 0.4.13
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 +1117 -0
- package/lib/index.js +2968 -0
- package/lib/types/client/index.d.ts +58 -0
- package/lib/types/client/locales.d.ts +83 -0
- package/lib/types/client/optional-service.d.ts +22 -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 +41 -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 +83 -3
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +139 -0
- package/src/client/locales.ts +154 -0
- package/src/client/optional-service.ts +30 -0
- package/src/client/team/extension.ts +185 -0
- package/src/client/team/sections.tsx +159 -0
- package/src/client/team/settings.tsx +242 -0
- package/src/client/team/summary.ts +156 -0
- package/src/client/team/team.module.css +122 -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
package/src/index.ts
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the task-board team provider extension.
|
|
3
|
+
*
|
|
4
|
+
* This package is an EXTERNAL PROVIDER EXTENSION for the task board
|
|
5
|
+
* (@linxin666/dsh-client-ui-task-board). It owns the team-hub configuration,
|
|
6
|
+
* the Host Token custody, the claim and lease lifecycle, the question routing
|
|
7
|
+
* and the comment tool; it reaches the board through the board's provider
|
|
8
|
+
* service and imports no board module.
|
|
9
|
+
*
|
|
10
|
+
* Two boundaries are load-bearing here: the Host Token is a credential (read
|
|
11
|
+
* host-side only, never part of a snapshot, a published summary or an agent
|
|
12
|
+
* payload, and the browser sends a pasted value exactly once), and only
|
|
13
|
+
* user-questions/request is ever claimed. Tool permission approvals
|
|
14
|
+
* (approval/request) belong to this machine's own security domain, so this file
|
|
15
|
+
* registers no listener for them at all (team-hub/PROTOCOL.md section 6).
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-task-board-team
|
|
18
|
+
*/
|
|
19
|
+
import type { Context, Volatile } from '@deepseek-ai/cordis'
|
|
20
|
+
import z from '@deepseek-ai/schemastery'
|
|
21
|
+
import { installTeamWaterfall } from './host/waterfall.ts'
|
|
22
|
+
import { resolveTaskBoardActionSeat, resolveTaskBoardHostFace } from './core/contract.ts'
|
|
23
|
+
import { processTimers } from './core/timers.ts'
|
|
24
|
+
import {
|
|
25
|
+
agentsLedgerPath,
|
|
26
|
+
readAgentsLedger,
|
|
27
|
+
resolveBindings,
|
|
28
|
+
type BoundAgent,
|
|
29
|
+
type TeamAgentBinding,
|
|
30
|
+
} from './host/bindings.ts'
|
|
31
|
+
import { platformSocket, teamSocketHeaders, teamSocketUrl, type SocketHandlers, type SocketLike } from './host/channel.ts'
|
|
32
|
+
import { DEFAULT_TOKEN_REF, resolveHostToken } from './host/credentials.ts'
|
|
33
|
+
import { createTeamExtension } from './host/extension.ts'
|
|
34
|
+
import { HubClient } from './host/hub-client.ts'
|
|
35
|
+
import { normalizeBindings, TeamSetup } from './host/setup.ts'
|
|
36
|
+
import type { TeamExtensionSummary, TeamSyncService } from './host/service.ts'
|
|
37
|
+
|
|
38
|
+
/** npm identity shared by every install source of this package. */
|
|
39
|
+
export const PACKAGE_NAME = '@linxin666/dsh-client-ui-task-board-team'
|
|
40
|
+
|
|
41
|
+
/** Order of this extension's announcement section, just after the board's own. */
|
|
42
|
+
const SECTION_ORDER = 260
|
|
43
|
+
|
|
44
|
+
/** The tool this extension registers, named in its announcement. */
|
|
45
|
+
export const TEAM_TOOL_NAME = 'team_comment'
|
|
46
|
+
|
|
47
|
+
/** Model-facing announcement: what the extension does and the words that name it. */
|
|
48
|
+
export const TEAM_GUIDANCE = '本机已安装 dsh-task-board-team 扩展(DSH Web GUI 任务看板的团队协作提供方):把云端 team-hub 上指派给本机 dsh-agents 成员的 issue 领取为看板镜像卡并在本机执行,执行结算写回 hub,执行会话里的 ask_user_question 会转给团队审阅人回答;另注册 team_comment 工具供模型发表评论,评论里 @ 到本机 Agent 时会作为后续消息投递进会话。工具权限审批一律只在本机处理,绝不进入 hub。用户提到「团队任务 / team-hub / 领取团队 issue / 给团队留言」时即指本扩展,请据此协作。'
|
|
49
|
+
|
|
50
|
+
/** The single-instance guard key; two install sources must not double register. */
|
|
51
|
+
const MOUNTED_KEY = Symbol.for('dsh-task-board-team:mounted')
|
|
52
|
+
|
|
53
|
+
/** One configured member binding. */
|
|
54
|
+
export interface TeamAgentBindingInput {
|
|
55
|
+
/** dsh-agents member id to bind as a team Agent. */
|
|
56
|
+
memberId: string
|
|
57
|
+
/** Name the hub resolves mentions by; empty falls back to the member's own name. */
|
|
58
|
+
name?: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Plugin config, validated by the same-named schemastery schema. */
|
|
62
|
+
export interface Config {
|
|
63
|
+
/** Master switch for the extension. */
|
|
64
|
+
enabled?: Volatile<boolean>
|
|
65
|
+
/** Whether this extension announces itself in every agent system prompt. */
|
|
66
|
+
announceToAgent?: Volatile<boolean>
|
|
67
|
+
/** Team-hub base URL, e.g. https://hub.example.com. */
|
|
68
|
+
hubUrl?: Volatile<string>
|
|
69
|
+
/** Team id the Host registers into. */
|
|
70
|
+
teamId?: Volatile<string>
|
|
71
|
+
/**
|
|
72
|
+
* Workspace this mount runs its mirror cards in; empty falls back to the
|
|
73
|
+
* workspace the member's dsh-agents team pins.
|
|
74
|
+
*
|
|
75
|
+
* A card with neither cannot be started by the board, and the hub keeps its
|
|
76
|
+
* issue `running` for as long as this Host holds the lease, so this Host claims
|
|
77
|
+
* nothing until one resolves and reports that in its summary instead.
|
|
78
|
+
*/
|
|
79
|
+
workspaceId?: Volatile<string>
|
|
80
|
+
/** Credential reference the Host Token is stored under. */
|
|
81
|
+
hostTokenRef?: Volatile<string>
|
|
82
|
+
/** dsh-agents members bound as team Agents on this machine. */
|
|
83
|
+
agents?: Volatile<TeamAgentBindingInput[]>
|
|
84
|
+
/** Hostname this Host registers under; empty means the platform hostname. */
|
|
85
|
+
hostname?: Volatile<string>
|
|
86
|
+
/**
|
|
87
|
+
* Optional local fallback wait for a claimed question, in minutes.
|
|
88
|
+
*
|
|
89
|
+
* Zero (the default) waits for the hub's own terminal state — answered,
|
|
90
|
+
* expired or withdrawn — which is what lets a member answer from a lock-screen
|
|
91
|
+
* push hours later. A positive value withdraws the question after that long and
|
|
92
|
+
* hands the ask back to the local answerer.
|
|
93
|
+
*/
|
|
94
|
+
questionWaitMinutes?: Volatile<number>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Profile-patch shape of {@link Config}. */
|
|
98
|
+
export interface ConfigInput {
|
|
99
|
+
enabled?: boolean
|
|
100
|
+
announceToAgent?: boolean
|
|
101
|
+
hubUrl?: string
|
|
102
|
+
teamId?: string
|
|
103
|
+
workspaceId?: string
|
|
104
|
+
hostTokenRef?: string
|
|
105
|
+
agents?: TeamAgentBindingInput[]
|
|
106
|
+
hostname?: string
|
|
107
|
+
questionWaitMinutes?: number
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Schema default of the announcement switch. */
|
|
111
|
+
export const DEFAULT_ANNOUNCE_TO_AGENT = false
|
|
112
|
+
|
|
113
|
+
/** Schema default of the Host Token reference. */
|
|
114
|
+
export const DEFAULT_HOST_TOKEN_REF = DEFAULT_TOKEN_REF
|
|
115
|
+
|
|
116
|
+
const AgentBindingSchema = z.object({
|
|
117
|
+
memberId: z.string(),
|
|
118
|
+
name: z.string().default(''),
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
export const Config: z<ConfigInput, Config> = z.object({
|
|
122
|
+
enabled: z.boolean().default(true).volatile(),
|
|
123
|
+
announceToAgent: z.boolean().default(false).volatile(),
|
|
124
|
+
hubUrl: z.string().default('').volatile(),
|
|
125
|
+
teamId: z.string().default('').volatile(),
|
|
126
|
+
workspaceId: z.string().default('').volatile(),
|
|
127
|
+
hostTokenRef: z.string().default(DEFAULT_TOKEN_REF).volatile(),
|
|
128
|
+
agents: z.array(AgentBindingSchema).default([]).volatile(),
|
|
129
|
+
hostname: z.string().default('').volatile(),
|
|
130
|
+
questionWaitMinutes: z.number().default(0).volatile(),
|
|
131
|
+
})
|
|
132
|
+
/**
|
|
133
|
+
* Read one config field's live value.
|
|
134
|
+
* @param field - the field as the Loader handed it.
|
|
135
|
+
* @param fallback - value when the field is absent.
|
|
136
|
+
* @returns the effective value.
|
|
137
|
+
*/
|
|
138
|
+
export function readConfigField<T>(field: Volatile<T> | T | undefined, fallback: T): T {
|
|
139
|
+
if (field === undefined) return fallback
|
|
140
|
+
if (typeof field === 'object' && field !== null && typeof (field as { get?: unknown }).get === 'function') {
|
|
141
|
+
return (field as Volatile<T>).get() as T
|
|
142
|
+
}
|
|
143
|
+
return field as T
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The effective settings of one mount. */
|
|
147
|
+
export interface TeamProviderSettings {
|
|
148
|
+
enabled: boolean
|
|
149
|
+
announceToAgent: boolean
|
|
150
|
+
hubUrl: string
|
|
151
|
+
teamId: string
|
|
152
|
+
workspaceId: string
|
|
153
|
+
hostTokenRef: string
|
|
154
|
+
agents: readonly TeamAgentBinding[]
|
|
155
|
+
hostname: string
|
|
156
|
+
questionWaitMinutes: number
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Resolve the effective settings of one mount.
|
|
161
|
+
* @param config - the row's config as the Host handed it.
|
|
162
|
+
* @param hostname - platform hostname fallback.
|
|
163
|
+
* @returns the settings the registration consumes.
|
|
164
|
+
*/
|
|
165
|
+
export function resolveProviderSettings(config?: Config, hostname = ''): TeamProviderSettings {
|
|
166
|
+
const bindings = readConfigField<TeamAgentBindingInput[]>(config?.agents, []).map(entry => ({
|
|
167
|
+
memberId: typeof entry?.memberId === 'string' ? entry.memberId : '',
|
|
168
|
+
...(typeof entry?.name === 'string' && entry.name !== '' ? { name: entry.name } : {}),
|
|
169
|
+
}))
|
|
170
|
+
const configured = readConfigField(config?.hostname, '').trim()
|
|
171
|
+
return {
|
|
172
|
+
enabled: readConfigField(config?.enabled, true),
|
|
173
|
+
announceToAgent: readConfigField(config?.announceToAgent, DEFAULT_ANNOUNCE_TO_AGENT),
|
|
174
|
+
hubUrl: readConfigField(config?.hubUrl, '').trim(),
|
|
175
|
+
teamId: readConfigField(config?.teamId, '').trim(),
|
|
176
|
+
workspaceId: readConfigField(config?.workspaceId, '').trim(),
|
|
177
|
+
hostTokenRef: readConfigField(config?.hostTokenRef, DEFAULT_TOKEN_REF).trim(),
|
|
178
|
+
agents: normalizeBindings(bindings),
|
|
179
|
+
hostname: configured === '' ? hostname : configured,
|
|
180
|
+
questionWaitMinutes: Math.max(0, Math.trunc(readConfigField(config?.questionWaitMinutes, 0))),
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The slice of the system-prompt service this extension announces through. */
|
|
185
|
+
interface SystemPromptFace {
|
|
186
|
+
section(spec: { name: string; order: number; text: string | ((context: { scope?: unknown }) => string) }): () => void
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The lookup face of the tool registry, when this deployment serves one. */
|
|
190
|
+
interface ToolLookupFace {
|
|
191
|
+
get(name: string, scope?: unknown): unknown
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Resolve an optional service by name.
|
|
196
|
+
* @param ctx - host context.
|
|
197
|
+
* @param name - service name.
|
|
198
|
+
* @returns the service, or undefined when this deployment serves none.
|
|
199
|
+
*/
|
|
200
|
+
function resolveOptional<T>(ctx: Context, name: string): T | undefined {
|
|
201
|
+
try {
|
|
202
|
+
const get = (ctx as { get?: (service: string) => unknown }).get
|
|
203
|
+
if (typeof get !== 'function') return undefined
|
|
204
|
+
return get.call(ctx, name) as T | undefined
|
|
205
|
+
} catch {
|
|
206
|
+
return undefined
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Resolve the announcement text, or undefined when the tool it names is not
|
|
212
|
+
* reachable: guidance for a tool the session cannot see only wastes context.
|
|
213
|
+
* @param ctx - host context.
|
|
214
|
+
* @returns the text to publish, or undefined.
|
|
215
|
+
*/
|
|
216
|
+
export function resolveAnnouncement(ctx: Context): string | undefined {
|
|
217
|
+
const tools = resolveOptional<ToolLookupFace>(ctx, 'tools')
|
|
218
|
+
if (tools === undefined || typeof tools.get !== 'function') return undefined
|
|
219
|
+
try {
|
|
220
|
+
return tools.get(TEAM_TOOL_NAME) === undefined ? undefined : TEAM_GUIDANCE
|
|
221
|
+
} catch {
|
|
222
|
+
return undefined
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
declare module '@deepseek-ai/cordis' {
|
|
227
|
+
interface Events {
|
|
228
|
+
/**
|
|
229
|
+
* Volatile config values were committed into the running fiber without a
|
|
230
|
+
* remount; dispatched to the owning fiber only.
|
|
231
|
+
* @param paths - changed config paths as key arrays.
|
|
232
|
+
* @mode emit
|
|
233
|
+
*/
|
|
234
|
+
'loader/volatile-update'(paths: readonly (readonly string[])[]): void
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Mount the plugin once per Host process, whichever install source loaded it.
|
|
240
|
+
* @param key - the process-wide guard key.
|
|
241
|
+
* @param apply - the real entry.
|
|
242
|
+
* @returns the guarded entry.
|
|
243
|
+
*/
|
|
244
|
+
export function mountOnce<T extends (ctx: Context, config?: Config) => void>(key: symbol, apply: T): T {
|
|
245
|
+
return ((ctx: Context, config?: Config) => {
|
|
246
|
+
const global = globalThis as unknown as Record<symbol, unknown>
|
|
247
|
+
if (global[key] === true) return
|
|
248
|
+
global[key] = true
|
|
249
|
+
try {
|
|
250
|
+
apply(ctx, config)
|
|
251
|
+
} catch (error) {
|
|
252
|
+
global[key] = false
|
|
253
|
+
throw error
|
|
254
|
+
}
|
|
255
|
+
}) as T
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Resolve the local agents the configured bindings name.
|
|
260
|
+
* @param settings - live settings of this mount.
|
|
261
|
+
* @returns the resolved agents and one problem line per unusable binding.
|
|
262
|
+
*/
|
|
263
|
+
async function resolveBoundAgents(settings: TeamProviderSettings): Promise<{ agents: BoundAgent[]; problems: string[] }> {
|
|
264
|
+
const view = await readAgentsLedger(agentsLedgerPath())
|
|
265
|
+
const resolved = resolveBindings(settings.agents, view)
|
|
266
|
+
return {
|
|
267
|
+
agents: resolved.agents,
|
|
268
|
+
problems: [...(view.problem === undefined ? [] : [view.problem]), ...resolved.problems],
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export const apply = mountOnce(MOUNTED_KEY, applyImpl)
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Activate the extension's host half.
|
|
275
|
+
*
|
|
276
|
+
* The provider is admitted through the board's own registration service, so it
|
|
277
|
+
* follows the board's master switch as well as this extension's. Registration
|
|
278
|
+
* lives behind a cordis dependency scope (ctx.inject) because the Host loads
|
|
279
|
+
* plugin rows in an order this package does not own: the board's service may
|
|
280
|
+
* genuinely not exist yet when this row activates, and the scope mounts when it
|
|
281
|
+
* appears and unloads when it is withdrawn.
|
|
282
|
+
* @param ctx - the plugin context.
|
|
283
|
+
* @param config - resolved plugin config.
|
|
284
|
+
*/
|
|
285
|
+
function applyImpl(ctx: Context, config?: Config): void {
|
|
286
|
+
const fallbackHostname = platformHostname()
|
|
287
|
+
const settings = (): TeamProviderSettings => resolveProviderSettings(config, fallbackHostname)
|
|
288
|
+
|
|
289
|
+
let injection: ReturnType<Context['inject']> | undefined
|
|
290
|
+
let mounted: string | undefined
|
|
291
|
+
let liveService: TeamSyncService | undefined
|
|
292
|
+
let disposeSection: (() => void) | undefined
|
|
293
|
+
let announceLive = false
|
|
294
|
+
let disposed = false
|
|
295
|
+
|
|
296
|
+
const provider = (): TeamExtensionSummary | undefined => liveService?.summary()
|
|
297
|
+
|
|
298
|
+
const setup = new TeamSetup({
|
|
299
|
+
ctx,
|
|
300
|
+
current: () => {
|
|
301
|
+
const current = settings()
|
|
302
|
+
return {
|
|
303
|
+
hubUrl: current.hubUrl,
|
|
304
|
+
teamId: current.teamId,
|
|
305
|
+
agents: current.agents,
|
|
306
|
+
hostname: current.hostname,
|
|
307
|
+
tokenRef: current.hostTokenRef,
|
|
308
|
+
questionWaitMinutes: current.questionWaitMinutes,
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
provider,
|
|
312
|
+
reload: () => { requestSync() },
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
/** The socket factory: the token is resolved per connection, so a rotation works. */
|
|
316
|
+
const connect = async (sinceSeq: number, handlers: SocketHandlers): Promise<SocketLike | undefined> => {
|
|
317
|
+
const current = settings()
|
|
318
|
+
if (current.hubUrl === '' || current.teamId === '') return undefined
|
|
319
|
+
const token = await resolveHostToken(ctx, current.hostTokenRef)
|
|
320
|
+
if (token === undefined) return undefined
|
|
321
|
+
return platformSocket(teamSocketUrl(current.hubUrl, current.teamId, sinceSeq), handlers, teamSocketHeaders(token))
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Ask the board to run one card through its own action applier. */
|
|
325
|
+
const requestRun = (taskId: string): void => {
|
|
326
|
+
const seat = resolveTaskBoardActionSeat(ctx)
|
|
327
|
+
if (seat === undefined) throw new Error('this board revision serves no action applier, so a claimed card cannot be started')
|
|
328
|
+
seat.apply('team-run-' + taskId + '-' + String(Date.now()), { kind: 'run', taskId }, 'team-hub')
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// A configuration write from the settings section republishes the summary, so
|
|
332
|
+
// the card renders what was just stored instead of a stale document.
|
|
333
|
+
setup.onWrite = () => { liveService?.publishNow() }
|
|
334
|
+
|
|
335
|
+
const teardownProvider = (): void => {
|
|
336
|
+
const current = injection
|
|
337
|
+
injection = undefined
|
|
338
|
+
mounted = undefined
|
|
339
|
+
if (current !== undefined) void current.dispose()
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const sync = async (): Promise<void> => {
|
|
343
|
+
if (disposed) return
|
|
344
|
+
const next = settings()
|
|
345
|
+
const wantAnnounce = next.enabled && next.announceToAgent
|
|
346
|
+
if (wantAnnounce !== announceLive) {
|
|
347
|
+
announceLive = wantAnnounce
|
|
348
|
+
try { disposeSection?.() } catch { /* best-effort */ }
|
|
349
|
+
disposeSection = undefined
|
|
350
|
+
if (wantAnnounce) {
|
|
351
|
+
const systemPrompt = resolveOptional<SystemPromptFace>(ctx, 'systemPrompt')
|
|
352
|
+
const text = resolveAnnouncement(ctx)
|
|
353
|
+
if (systemPrompt !== undefined && text !== undefined) {
|
|
354
|
+
try {
|
|
355
|
+
disposeSection = systemPrompt.section({ name: 'plugin:task-board-team', order: SECTION_ORDER, text })
|
|
356
|
+
} catch {
|
|
357
|
+
// A refused section costs the announcement only.
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (!next.enabled) {
|
|
363
|
+
teardownProvider()
|
|
364
|
+
return
|
|
365
|
+
}
|
|
366
|
+
const desired = JSON.stringify({
|
|
367
|
+
hubUrl: next.hubUrl,
|
|
368
|
+
teamId: next.teamId,
|
|
369
|
+
hostTokenRef: next.hostTokenRef,
|
|
370
|
+
agents: next.agents,
|
|
371
|
+
hostname: next.hostname,
|
|
372
|
+
})
|
|
373
|
+
if (desired === mounted) return
|
|
374
|
+
teardownProvider()
|
|
375
|
+
mounted = desired
|
|
376
|
+
injection = ctx.inject(['taskBoard'], (scope: Context) => {
|
|
377
|
+
scope.effect(() => {
|
|
378
|
+
const face = resolveTaskBoardHostFace(scope)
|
|
379
|
+
if (face === undefined) {
|
|
380
|
+
console.error('[dsh-task-board-team] the taskBoard service does not answer the registration contract')
|
|
381
|
+
return () => {}
|
|
382
|
+
}
|
|
383
|
+
void setup.refreshToken().then(() => { liveService?.publishNow() }).catch(() => {})
|
|
384
|
+
const dispose = face.registerExtension(createTeamExtension({
|
|
385
|
+
hub: new HubClient({
|
|
386
|
+
hubUrl: () => settings().hubUrl,
|
|
387
|
+
teamId: () => settings().teamId,
|
|
388
|
+
token: async () => await resolveHostToken(ctx, settings().hostTokenRef),
|
|
389
|
+
}),
|
|
390
|
+
settings: () => ({
|
|
391
|
+
enabled: settings().enabled,
|
|
392
|
+
hostname: settings().hostname,
|
|
393
|
+
bindings: settings().agents,
|
|
394
|
+
workspaceId: settings().workspaceId,
|
|
395
|
+
questionWaitMinutes: settings().questionWaitMinutes,
|
|
396
|
+
}),
|
|
397
|
+
resolveAgents: async () => await resolveBoundAgents(settings()),
|
|
398
|
+
connect,
|
|
399
|
+
requestRun,
|
|
400
|
+
actionSeat: () => resolveTaskBoardActionSeat(scope) !== undefined,
|
|
401
|
+
configuration: () => ({
|
|
402
|
+
hubUrl: settings().hubUrl,
|
|
403
|
+
teamId: settings().teamId,
|
|
404
|
+
hostname: settings().hostname,
|
|
405
|
+
tokenConfigured: setup.tokenConfigured(),
|
|
406
|
+
questionWaitMinutes: settings().questionWaitMinutes,
|
|
407
|
+
}),
|
|
408
|
+
timers: processTimers,
|
|
409
|
+
enabled: () => settings().enabled,
|
|
410
|
+
setup,
|
|
411
|
+
onService: service => { liveService = service },
|
|
412
|
+
log: (message, detail) => {
|
|
413
|
+
if (detail === undefined) console.error('[dsh-task-board-team] ' + message)
|
|
414
|
+
else console.error('[dsh-task-board-team] ' + message, detail)
|
|
415
|
+
},
|
|
416
|
+
}))
|
|
417
|
+
return () => {
|
|
418
|
+
liveService = undefined
|
|
419
|
+
dispose()
|
|
420
|
+
}
|
|
421
|
+
}, 'task-board-team: provider registration')
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Serialize sync requests: a config write and a volatile commit can arrive together. */
|
|
426
|
+
let chain: Promise<void> = Promise.resolve()
|
|
427
|
+
const requestSync = (): void => {
|
|
428
|
+
chain = chain.then(() => sync()).catch(error => { console.error('[dsh-task-board-team] sync failed', error) })
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
ctx.on('loader/volatile-update', () => { requestSync() })
|
|
432
|
+
ctx.on('credentials/reference-updated', () => { requestSync() })
|
|
433
|
+
|
|
434
|
+
// The one waterfall this extension claims (see host/waterfall.ts). Tool
|
|
435
|
+
// permission approvals have no listener here by design.
|
|
436
|
+
installTeamWaterfall(ctx, () => liveService?.questions)
|
|
437
|
+
|
|
438
|
+
ctx.effect(() => {
|
|
439
|
+
requestSync()
|
|
440
|
+
return () => {
|
|
441
|
+
disposed = true
|
|
442
|
+
teardownProvider()
|
|
443
|
+
try { disposeSection?.() } catch { /* best-effort */ }
|
|
444
|
+
disposeSection = undefined
|
|
445
|
+
}
|
|
446
|
+
}, 'task-board-team: provider lifecycle')
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** The platform hostname this Host registers under. */
|
|
450
|
+
function platformHostname(): string {
|
|
451
|
+
return process.env.HOSTNAME ?? process.env.COMPUTERNAME ?? 'dsh-host'
|
|
452
|
+
}
|