@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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configuration surface this extension's settings section drives.
|
|
3
|
+
*
|
|
4
|
+
* One module owns every write, so the settings section, a profile patch and an
|
|
5
|
+
* agent all produce the same stored value: the hub URL, the team id and the
|
|
6
|
+
* member bindings are volatile fields of this plugin's own settings entry, and
|
|
7
|
+
* the Host Token goes to the credential store instead (`credentials.ts`). The
|
|
8
|
+
* read half reports status only — never a token, never a value a browser could
|
|
9
|
+
* replay.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-task-board-team/host/setup
|
|
12
|
+
*/
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
14
|
+
import type { TeamAgentBinding } from './bindings.ts'
|
|
15
|
+
import { clearHostToken, describeHostToken, setHostToken } from './credentials.ts'
|
|
16
|
+
import type { TeamExtensionSummary } from './service.ts'
|
|
17
|
+
|
|
18
|
+
/** Settings entry ids this package's rows carry, most specific first. */
|
|
19
|
+
export const TEAM_ENTRY_IDS: readonly string[] = ['web-ui-task-board-team', 'ui-task-board-team', 'task-board-team']
|
|
20
|
+
|
|
21
|
+
/** One entry the settings surface reports. */
|
|
22
|
+
interface SettingsDescriptor {
|
|
23
|
+
ns?: unknown
|
|
24
|
+
value?: unknown
|
|
25
|
+
revision?: unknown
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One path-addressed edit the settings surface accepts. */
|
|
29
|
+
type SettingsPathOp =
|
|
30
|
+
| { op: 'set'; path: readonly string[]; value: unknown }
|
|
31
|
+
| { op: 'unset'; path: readonly string[] }
|
|
32
|
+
|
|
33
|
+
/** The slice of the Host settings surface this extension uses. */
|
|
34
|
+
export interface SettingsFace {
|
|
35
|
+
readonly writable: boolean
|
|
36
|
+
describe(options?: { redactSecrets?: boolean }): SettingsDescriptor[]
|
|
37
|
+
mutate(ns: string, ops: readonly SettingsPathOp[], expectedRevision?: number): Promise<void>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the optional settings service.
|
|
42
|
+
* @param ctx - host context.
|
|
43
|
+
* @returns the surface, or undefined when this deployment serves none.
|
|
44
|
+
*/
|
|
45
|
+
export function resolveSettingsFace(ctx: Context): SettingsFace | undefined {
|
|
46
|
+
try {
|
|
47
|
+
const get = (ctx as { get?: (name: string) => unknown }).get
|
|
48
|
+
if (typeof get !== 'function') return undefined
|
|
49
|
+
const face = get.call(ctx, 'settings') as SettingsFace | undefined
|
|
50
|
+
if (face === undefined) return undefined
|
|
51
|
+
return typeof face.describe === 'function' && typeof face.mutate === 'function' ? face : undefined
|
|
52
|
+
} catch {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Find this extension's own entry in the settings surface.
|
|
59
|
+
* @param face - the settings surface.
|
|
60
|
+
* @returns the entry id and its current revision, or undefined.
|
|
61
|
+
*/
|
|
62
|
+
export function findTeamSettingsEntry(face: SettingsFace): { ns: string; revision: number } | undefined {
|
|
63
|
+
let descriptors: SettingsDescriptor[]
|
|
64
|
+
try {
|
|
65
|
+
descriptors = face.describe({ redactSecrets: true })
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
for (const wanted of TEAM_ENTRY_IDS) {
|
|
70
|
+
const hit = descriptors.find(descriptor => descriptor.ns === wanted)
|
|
71
|
+
if (hit !== undefined) {
|
|
72
|
+
return { ns: wanted, revision: typeof hit.revision === 'number' ? hit.revision : 0 }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** What the settings section renders. */
|
|
79
|
+
export interface TeamSetupStatus {
|
|
80
|
+
/** Configured hub base URL. */
|
|
81
|
+
hubUrl: string
|
|
82
|
+
/** Configured team id. */
|
|
83
|
+
teamId: string
|
|
84
|
+
/** Whether a Host Token is configured; never the value. */
|
|
85
|
+
token: { configured: boolean; writable: boolean; ref: string; source?: string }
|
|
86
|
+
/** Configured member bindings. */
|
|
87
|
+
agents: readonly TeamAgentBinding[]
|
|
88
|
+
/** Hostname this Host registers under. */
|
|
89
|
+
hostname: string
|
|
90
|
+
/** Optional local fallback wait for a claimed question, in minutes; 0 means none. */
|
|
91
|
+
questionWaitMinutes: number
|
|
92
|
+
/** The live connection and capability summary, when the provider is mounted. */
|
|
93
|
+
provider?: TeamExtensionSummary
|
|
94
|
+
/** Whether this deployment exposes a settings form for this extension. */
|
|
95
|
+
writable: boolean
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The settings a caller may write. */
|
|
99
|
+
export interface TeamSetupPatch {
|
|
100
|
+
hubUrl?: string
|
|
101
|
+
teamId?: string
|
|
102
|
+
agents?: readonly TeamAgentBinding[]
|
|
103
|
+
hostname?: string
|
|
104
|
+
questionWaitMinutes?: number
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface TeamSetupOptions {
|
|
108
|
+
ctx: Context
|
|
109
|
+
/** Current configured values, read live from the plugin config. */
|
|
110
|
+
current: () => {
|
|
111
|
+
hubUrl: string
|
|
112
|
+
teamId: string
|
|
113
|
+
agents: readonly TeamAgentBinding[]
|
|
114
|
+
hostname: string
|
|
115
|
+
tokenRef: string
|
|
116
|
+
questionWaitMinutes?: number
|
|
117
|
+
}
|
|
118
|
+
/** The live provider summary, when the extension is mounted. */
|
|
119
|
+
provider: () => TeamExtensionSummary | undefined
|
|
120
|
+
/** Called after a successful write so the mount can follow it immediately. */
|
|
121
|
+
reload?: () => void
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The configuration surface one mount owns. */
|
|
125
|
+
export class TeamSetup {
|
|
126
|
+
readonly #options: TeamSetupOptions
|
|
127
|
+
/** Last known credential facts; refreshed on mount and after every write. */
|
|
128
|
+
#token: { configured: boolean; writable: boolean; ref: string; source?: string } | undefined
|
|
129
|
+
/** Called after any write so the live mount can republish its summary. */
|
|
130
|
+
onWrite: (() => void) | undefined
|
|
131
|
+
|
|
132
|
+
constructor(options: TeamSetupOptions) {
|
|
133
|
+
this.#options = options
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Whether a Host Token is currently configured, as of the last refresh. */
|
|
137
|
+
tokenConfigured(): boolean {
|
|
138
|
+
return this.#token?.configured === true
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Re-read the credential facts without exposing the value. */
|
|
142
|
+
async refreshToken(): Promise<void> {
|
|
143
|
+
const current = this.#options.current()
|
|
144
|
+
this.#token = await describeHostToken(this.#options.ctx, current.tokenRef)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Store one pasted Host Token.
|
|
149
|
+
*
|
|
150
|
+
* This is the only path a token value travels: the browser sends it once, the
|
|
151
|
+
* host half stores it in the credential seam, and nothing ever reads it back
|
|
152
|
+
* out to a client.
|
|
153
|
+
* @param value - the token the operator pasted.
|
|
154
|
+
*/
|
|
155
|
+
async saveToken(value: string): Promise<void> {
|
|
156
|
+
const trimmed = value.trim()
|
|
157
|
+
if (trimmed === '') throw new Error('the Host Token must be a non-empty value')
|
|
158
|
+
const current = this.#options.current()
|
|
159
|
+
await setHostToken(this.#options.ctx, current.tokenRef, trimmed)
|
|
160
|
+
await this.refreshToken()
|
|
161
|
+
this.onWrite?.()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Remove the stored Host Token. */
|
|
165
|
+
async clearToken(): Promise<void> {
|
|
166
|
+
const current = this.#options.current()
|
|
167
|
+
await clearHostToken(this.#options.ctx, current.tokenRef)
|
|
168
|
+
await this.refreshToken()
|
|
169
|
+
this.onWrite?.()
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Read the current configuration status. */
|
|
173
|
+
async status(): Promise<TeamSetupStatus> {
|
|
174
|
+
const current = this.#options.current()
|
|
175
|
+
const token = await describeHostToken(this.#options.ctx, current.tokenRef)
|
|
176
|
+
this.#token = token
|
|
177
|
+
return {
|
|
178
|
+
hubUrl: current.hubUrl,
|
|
179
|
+
teamId: current.teamId,
|
|
180
|
+
agents: current.agents.map(binding => ({ ...binding })),
|
|
181
|
+
hostname: current.hostname,
|
|
182
|
+
questionWaitMinutes: current.questionWaitMinutes ?? 0,
|
|
183
|
+
token,
|
|
184
|
+
writable: resolveSettingsFace(this.#options.ctx)?.writable !== false,
|
|
185
|
+
...(this.#options.provider() === undefined ? {} : { provider: this.#options.provider() as TeamExtensionSummary }),
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Store the hub URL, the team id, the member bindings or the hostname.
|
|
191
|
+
*
|
|
192
|
+
* Every field is written in one batch against the revision just read, so a
|
|
193
|
+
* hub URL and the team it belongs to cannot be stored split by a concurrent
|
|
194
|
+
* edit, and the Loader commits the result into the running mount without a
|
|
195
|
+
* restart.
|
|
196
|
+
* @param patch - the fields to replace.
|
|
197
|
+
* @returns the status after the write.
|
|
198
|
+
*/
|
|
199
|
+
async save(patch: TeamSetupPatch): Promise<TeamSetupStatus> {
|
|
200
|
+
const operations: SettingsPathOp[] = []
|
|
201
|
+
if (patch.hubUrl !== undefined) operations.push({ op: 'set', path: ['hubUrl'], value: normalizeHubUrl(patch.hubUrl) })
|
|
202
|
+
if (patch.teamId !== undefined) operations.push({ op: 'set', path: ['teamId'], value: patch.teamId.trim() })
|
|
203
|
+
if (patch.hostname !== undefined) operations.push({ op: 'set', path: ['hostname'], value: patch.hostname.trim() })
|
|
204
|
+
if (patch.agents !== undefined) operations.push({ op: 'set', path: ['agents'], value: normalizeBindings(patch.agents) })
|
|
205
|
+
if (patch.questionWaitMinutes !== undefined) {
|
|
206
|
+
operations.push({ op: 'set', path: ['questionWaitMinutes'], value: Math.max(0, Math.trunc(patch.questionWaitMinutes)) })
|
|
207
|
+
}
|
|
208
|
+
if (operations.length > 0) {
|
|
209
|
+
const face = resolveSettingsFace(this.#options.ctx)
|
|
210
|
+
if (face === undefined) throw new Error('this deployment serves no settings surface, so the team settings cannot be written')
|
|
211
|
+
if (face.writable === false) throw new Error('this deployment serves configuration read-only')
|
|
212
|
+
const entry = findTeamSettingsEntry(face)
|
|
213
|
+
if (entry === undefined) throw new Error('this deployment exposes no settings form for the team extension')
|
|
214
|
+
await face.mutate(entry.ns, operations, entry.revision)
|
|
215
|
+
}
|
|
216
|
+
this.#options.reload?.()
|
|
217
|
+
this.onWrite?.()
|
|
218
|
+
return await this.status()
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Normalize one hub URL to an absolute http(s) base without a trailing slash.
|
|
224
|
+
* @param raw - the value the operator typed.
|
|
225
|
+
* @returns the normalized URL.
|
|
226
|
+
* @throws when the value is not a usable absolute URL.
|
|
227
|
+
*/
|
|
228
|
+
export function normalizeHubUrl(raw: string): string {
|
|
229
|
+
const trimmed = raw.trim().replace(/\/+$/, '')
|
|
230
|
+
if (trimmed === '') return ''
|
|
231
|
+
let url: URL
|
|
232
|
+
try {
|
|
233
|
+
url = new URL(trimmed)
|
|
234
|
+
} catch {
|
|
235
|
+
throw new Error('the hub URL must be an absolute http(s) URL')
|
|
236
|
+
}
|
|
237
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
238
|
+
throw new Error('the hub URL must be an absolute http(s) URL')
|
|
239
|
+
}
|
|
240
|
+
return trimmed
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Keep only bindings that name a member, dropping duplicates.
|
|
245
|
+
* @param raw - the bindings one caller proposed.
|
|
246
|
+
* @returns the normalized list.
|
|
247
|
+
*/
|
|
248
|
+
export function normalizeBindings(raw: readonly TeamAgentBinding[]): TeamAgentBinding[] {
|
|
249
|
+
const seen = new Set<string>()
|
|
250
|
+
const result: TeamAgentBinding[] = []
|
|
251
|
+
for (const binding of raw) {
|
|
252
|
+
const memberId = typeof binding?.memberId === 'string' ? binding.memberId.trim() : ''
|
|
253
|
+
if (memberId === '' || seen.has(memberId)) continue
|
|
254
|
+
seen.add(memberId)
|
|
255
|
+
const name = typeof binding.name === 'string' ? binding.name.trim() : ''
|
|
256
|
+
result.push({ memberId, ...(name === '' ? {} : { name }) })
|
|
257
|
+
}
|
|
258
|
+
return result
|
|
259
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one model-visible tool this extension contributes: `team_comment`.
|
|
3
|
+
*
|
|
4
|
+
* Comments are the agent's half of the collaboration surface — the reviewer
|
|
5
|
+
* reads them on the issue, and a mention in one is delivered into the session.
|
|
6
|
+
* The tool registers through the board's capability face, so it lives exactly as
|
|
7
|
+
* long as the board runs this extension, and it accepts no shell text, path or
|
|
8
|
+
* permission: a comment is prose and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-task-board-team/host/tools
|
|
11
|
+
*/
|
|
12
|
+
import { defineTool, type ToolDefinition } from '@deepseek-ai/dsh-tools'
|
|
13
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
14
|
+
import { COMMENT_LIMIT_BYTES } from '../core/hub-protocol.ts'
|
|
15
|
+
import type { TeamSyncService } from './service.ts'
|
|
16
|
+
|
|
17
|
+
type Json = null | boolean | number | string | Json[] | { [key: string]: Json }
|
|
18
|
+
|
|
19
|
+
function renderJson(_args: unknown, value: unknown): ContentBlock[] {
|
|
20
|
+
return [{ type: 'text' as const, text: JSON.stringify(value, null, 2) }]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function json(value: unknown): Json {
|
|
24
|
+
return value as Json
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Byte length of one comment body, as the hub measures its own cap. */
|
|
28
|
+
function byteLength(text: string): number {
|
|
29
|
+
return new TextEncoder().encode(text).length
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Build the comment tool.
|
|
34
|
+
* @param service - the running sync service.
|
|
35
|
+
* @returns the tool definition the board registers.
|
|
36
|
+
*/
|
|
37
|
+
export function buildTeamTools(service: TeamSyncService): ToolDefinition[] {
|
|
38
|
+
return [defineTool({
|
|
39
|
+
name: 'team_comment',
|
|
40
|
+
description: 'Post one comment on the team issue behind a task board card. Use it to report progress, ask a question that does not need to block, or explain a decision to the human reviewer. Accepts taskId (the card you are working on) or issueId. The body is Markdown, must stay under the byte cap and must not carry secrets.',
|
|
41
|
+
parameters: {
|
|
42
|
+
taskId: { type: 'string', description: 'Task board card id that mirrors a team issue.' },
|
|
43
|
+
issueId: { type: 'string', description: 'Team issue id, when the card id is not known.' },
|
|
44
|
+
text: { type: 'string', required: true, description: 'Markdown comment body. Must be non-empty and under the byte cap.' },
|
|
45
|
+
},
|
|
46
|
+
output: { schema: { type: 'json' }, render: renderJson },
|
|
47
|
+
async execute(args) {
|
|
48
|
+
const text = typeof args.text === 'string' ? args.text : ''
|
|
49
|
+
if (text.trim() === '') return json({ ok: false, code: 'text-required', message: 'text must be a non-empty comment body' })
|
|
50
|
+
if (byteLength(text) > COMMENT_LIMIT_BYTES) {
|
|
51
|
+
return json({ ok: false, code: 'text-too-long', message: 'the comment body exceeds the byte cap' })
|
|
52
|
+
}
|
|
53
|
+
const taskId = typeof args.taskId === 'string' && args.taskId !== '' ? args.taskId : undefined
|
|
54
|
+
const issueId = typeof args.issueId === 'string' && args.issueId !== '' ? args.issueId : undefined
|
|
55
|
+
if (taskId === undefined && issueId === undefined) {
|
|
56
|
+
return json({ ok: false, code: 'target-required', message: 'name the card (taskId) or the issue (issueId) to comment on' })
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const posted = await service.postComment({
|
|
60
|
+
text,
|
|
61
|
+
...(taskId === undefined ? {} : { taskId }),
|
|
62
|
+
...(issueId === undefined ? {} : { issueId }),
|
|
63
|
+
})
|
|
64
|
+
return json({ ok: true, ...posted })
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return json({ ok: false, code: 'comment-refused', message: error instanceof Error ? error.message : String(error) })
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
})]
|
|
70
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single claim this provider makes on the Host's process-wide answerer
|
|
3
|
+
* waterfalls.
|
|
4
|
+
*
|
|
5
|
+
* Exactly one event is subscribed: `user-questions/request`, the decision
|
|
6
|
+
* question a session asks through `ask_user_question`. `approval/request` — the
|
|
7
|
+
* tool permission question — is deliberately absent, because it belongs to the
|
|
8
|
+
* local machine's own security domain (`team-hub/PROTOCOL.md` section 6): a
|
|
9
|
+
* remote reviewer must never be able to authorize a tool on this host. Keeping
|
|
10
|
+
* the subscription list in one function is what makes that absence reviewable
|
|
11
|
+
* and testable instead of an implicit property of a large entry file.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-task-board-team/host/waterfall
|
|
14
|
+
*/
|
|
15
|
+
import type { QuestionAnswer, QuestionRequestShape } from '../core/question-report.ts'
|
|
16
|
+
import type { QuestionRouter } from './questions.ts'
|
|
17
|
+
|
|
18
|
+
/** The event names this provider may subscribe to. */
|
|
19
|
+
export const CLAIMED_EVENTS = ['user-questions/request'] as const
|
|
20
|
+
|
|
21
|
+
/** The event this provider must never subscribe to. */
|
|
22
|
+
export const NEVER_CLAIMED_EVENTS = ['approval/request'] as const
|
|
23
|
+
|
|
24
|
+
/** The cordis slice the installer needs. */
|
|
25
|
+
export interface WaterfallSeat {
|
|
26
|
+
/** Subscribe one waterfall listener; the returned disposer unsubscribes. */
|
|
27
|
+
on(
|
|
28
|
+
event: 'user-questions/request',
|
|
29
|
+
listener: (request: QuestionRequestShape, next: () => Promise<QuestionAnswer>) => Promise<QuestionAnswer>,
|
|
30
|
+
options?: { prepend?: boolean },
|
|
31
|
+
): () => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Install the provider's one waterfall claim.
|
|
36
|
+
*
|
|
37
|
+
* The listener is prepended so the team routing is consulted before the desktop
|
|
38
|
+
* answerer for a team card's session; every request that is not such a session's
|
|
39
|
+
* is delegated straight back down the chain, so the local surface keeps working
|
|
40
|
+
* exactly as it did before this provider existed.
|
|
41
|
+
* @param seat - the host context's event seat.
|
|
42
|
+
* @param router - resolves the question router of the live mount, if any.
|
|
43
|
+
* @returns disposer removing the subscription.
|
|
44
|
+
*/
|
|
45
|
+
export function installTeamWaterfall(seat: WaterfallSeat, router: () => QuestionRouter | undefined): () => void {
|
|
46
|
+
return seat.on('user-questions/request', (request, next) => {
|
|
47
|
+
const live = router()
|
|
48
|
+
if (live === undefined) return next()
|
|
49
|
+
return live.request(request, next)
|
|
50
|
+
}, { prepend: true })
|
|
51
|
+
}
|