@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.
Files changed (74) hide show
  1. package/LICENSE +202 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +66 -2
  4. package/README.zh.md +67 -0
  5. package/cordis.patch.yml +14 -0
  6. package/icon.svg +3 -0
  7. package/lib/client.js +1490 -0
  8. package/lib/index.js +2968 -0
  9. package/lib/types/client/PluginSettingsCard.d.ts +255 -0
  10. package/lib/types/client/RangeBubble.d.ts +46 -0
  11. package/lib/types/client/SegmentGroup.d.ts +28 -0
  12. package/lib/types/client/index.d.ts +58 -0
  13. package/lib/types/client/locales.d.ts +90 -0
  14. package/lib/types/client/optional-service.d.ts +22 -0
  15. package/lib/types/client/settings-form.d.ts +235 -0
  16. package/lib/types/client/team/extension.d.ts +29 -0
  17. package/lib/types/client/team/sections.d.ts +38 -0
  18. package/lib/types/client/team/settings.d.ts +67 -0
  19. package/lib/types/client/team/summary.d.ts +34 -0
  20. package/lib/types/core/contract.d.ts +269 -0
  21. package/lib/types/core/hub-protocol.d.ts +175 -0
  22. package/lib/types/core/identity.d.ts +96 -0
  23. package/lib/types/core/mirror.d.ts +51 -0
  24. package/lib/types/core/question-report.d.ts +84 -0
  25. package/lib/types/core/settlement.d.ts +49 -0
  26. package/lib/types/core/task-record.d.ts +59 -0
  27. package/lib/types/core/timers.d.ts +20 -0
  28. package/lib/types/host/bindings.d.ts +92 -0
  29. package/lib/types/host/channel.d.ts +44 -0
  30. package/lib/types/host/credentials.d.ts +63 -0
  31. package/lib/types/host/extension.d.ts +57 -0
  32. package/lib/types/host/hub-client.d.ts +157 -0
  33. package/lib/types/host/questions.d.ts +105 -0
  34. package/lib/types/host/service.d.ts +209 -0
  35. package/lib/types/host/setup.d.ts +152 -0
  36. package/lib/types/host/tools.d.ts +19 -0
  37. package/lib/types/host/waterfall.d.ts +39 -0
  38. package/lib/types/index.d.ts +152 -0
  39. package/locale/en.json +6 -0
  40. package/locale/zh.json +6 -0
  41. package/package.json +84 -3
  42. package/src/client/PluginSettingsCard.tsx +838 -0
  43. package/src/client/RangeBubble.tsx +164 -0
  44. package/src/client/SegmentGroup.tsx +93 -0
  45. package/src/client/css-modules.d.ts +5 -0
  46. package/src/client/index.ts +139 -0
  47. package/src/client/locales.ts +168 -0
  48. package/src/client/optional-service.ts +30 -0
  49. package/src/client/settings-card.module.css +821 -0
  50. package/src/client/settings-form.ts +510 -0
  51. package/src/client/team/extension.ts +185 -0
  52. package/src/client/team/sections.tsx +159 -0
  53. package/src/client/team/settings.tsx +348 -0
  54. package/src/client/team/summary.ts +156 -0
  55. package/src/client/team/team.module.css +193 -0
  56. package/src/core/contract.ts +326 -0
  57. package/src/core/hub-protocol.ts +217 -0
  58. package/src/core/identity.ts +193 -0
  59. package/src/core/mirror.ts +88 -0
  60. package/src/core/question-report.ts +144 -0
  61. package/src/core/settlement.ts +84 -0
  62. package/src/core/task-record.ts +65 -0
  63. package/src/core/timers.ts +34 -0
  64. package/src/host/bindings.ts +211 -0
  65. package/src/host/channel.ts +97 -0
  66. package/src/host/credentials.ts +147 -0
  67. package/src/host/extension.ts +197 -0
  68. package/src/host/hub-client.ts +287 -0
  69. package/src/host/questions.ts +275 -0
  70. package/src/host/service.ts +1421 -0
  71. package/src/host/setup.ts +259 -0
  72. package/src/host/tools.ts +70 -0
  73. package/src/host/waterfall.ts +51 -0
  74. package/src/index.ts +452 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * The two rendering seats of the team provider: the task-detail section and the
3
+ * card decoration.
4
+ *
5
+ * Both read the published summary the Host pushes through the board mirror; the
6
+ * card payload itself (the issue id, attempt id and lease) is read off the card
7
+ * the seat was handed, so a mirror card is recognizable even before the first
8
+ * summary arrives.
9
+ *
10
+ * @module dsh-task-board-team/client/team/sections
11
+ */
12
+ import type { CSSProperties, ReactElement } from 'react'
13
+ import type { TaskBoardCardDecorationProps, TaskBoardDetailSectionProps } from '../../core/contract.ts'
14
+ import { readTaskIssueLink, type TeamIssueLink } from '../../core/identity.ts'
15
+ import type { TeamCardView } from '../../host/service.ts'
16
+ import { t, type TeamKey } from '../locales.ts'
17
+ import { useTeamSummary } from './summary.ts'
18
+ import styles from './team.module.css'
19
+
20
+ /** Hub status the badge renders; the key set is the protocol's own status column. */
21
+ const STATUS_KEYS: Record<string, TeamKey> = {
22
+ todo: 'status.todo',
23
+ assigned: 'status.assigned',
24
+ waiting_host: 'status.waiting_host',
25
+ running: 'status.running',
26
+ in_review: 'status.in_review',
27
+ done: 'status.done',
28
+ canceled: 'status.canceled',
29
+ failed: 'status.failed',
30
+ }
31
+
32
+ /**
33
+ * Translate one hub status.
34
+ * @param status - the collaboration status the hub reported.
35
+ * @returns the localized label, or the raw status for a value this build predates.
36
+ */
37
+ export function statusLabel(status: string | undefined): string {
38
+ if (status === undefined) return t('detail.empty')
39
+ const key = STATUS_KEYS[status]
40
+ return key === undefined ? status : t(key)
41
+ }
42
+
43
+ /**
44
+ * The hub status badge of one mirrored card.
45
+ * @param props - the card the board renders.
46
+ * @returns the badge, or nothing for a card that mirrors no issue.
47
+ */
48
+ export function TeamCardDecoration({ task }: TaskBoardCardDecorationProps): ReactElement | null {
49
+ useTeamSummary()
50
+ const link = readTaskIssueLink(task as never)
51
+ if (link === undefined) return null
52
+ const status = link.hubStatus
53
+ if (status === undefined) {
54
+ return <span className={styles.badge} data-dsh-plugin="task-board-team" data-dsh-part="team-badge">{t('detail.title')}</span>
55
+ }
56
+ return (
57
+ <span className={styles.badge} data-dsh-plugin="task-board-team" data-dsh-part="team-badge" data-hub-status={status}>
58
+ {statusLabel(status)}
59
+ </span>
60
+ )
61
+ }
62
+
63
+ /** One line of the detail block: label and value. */
64
+ function Field({ label, value }: { label: string; value: string }): ReactElement {
65
+ return (
66
+ <div className={styles.row}>
67
+ <span className={styles.label}>{label}</span>
68
+ <span className={styles.value}>{value}</span>
69
+ </div>
70
+ )
71
+ }
72
+
73
+ /** The comments and activity one card carries, newest last. */
74
+ function Streams({ view }: { view: TeamCardView | undefined }): ReactElement {
75
+ const comments = view?.comments ?? []
76
+ const activity = view?.activity ?? []
77
+ return (
78
+ <>
79
+ <div>
80
+ <p className={styles.title}>{t('detail.comments')}</p>
81
+ {comments.length === 0
82
+ ? <p className={styles.empty}>{t('detail.empty')}</p>
83
+ : (
84
+ <ul className={styles.list} data-dsh-part="team-comments">
85
+ {comments.map(comment => (
86
+ <li key={comment.id} className={styles.entry}>
87
+ <span className={styles.meta}>{comment.author}</span>
88
+ <span className={styles.body}>{comment.content}</span>
89
+ </li>
90
+ ))}
91
+ </ul>
92
+ )}
93
+ </div>
94
+ <div>
95
+ <p className={styles.title}>{t('detail.activity')}</p>
96
+ {activity.length === 0
97
+ ? <p className={styles.empty}>{t('detail.empty')}</p>
98
+ : (
99
+ <ul className={styles.list} data-dsh-part="team-activity">
100
+ {activity.map(entry => (
101
+ <li key={entry.id} className={styles.entry}>
102
+ <span className={styles.meta}>{entry.type}</span>
103
+ <span className={styles.body}>{entry.text}</span>
104
+ </li>
105
+ ))}
106
+ </ul>
107
+ )}
108
+ </div>
109
+ </>
110
+ )
111
+ }
112
+
113
+ /**
114
+ * The team section of one card's detail view.
115
+ * @param props - the card the board renders, plus the action dispatcher.
116
+ * @returns the section, or nothing for a card that mirrors no issue.
117
+ */
118
+ export function TeamDetailSection({ task }: TaskBoardDetailSectionProps): ReactElement | null {
119
+ const summary = useTeamSummary()
120
+ const link = readTaskIssueLink(task as never)
121
+ if (link === undefined) return null
122
+ const view = summary?.cards[task.id]
123
+ const pending = (summary?.pendingQuestions ?? []).filter(question => question.taskId === task.id)
124
+ const agent = summary?.agents.find(candidate => candidate.memberId === link.agentMemberId)
125
+ const style: CSSProperties = {}
126
+ return (
127
+ <div className={styles.section} data-dsh-plugin="task-board-team" data-dsh-part="team-detail" style={style}>
128
+ <p className={styles.title}>{t('detail.title')}</p>
129
+ <Field label={t('detail.issue')} value={issueLabel(link)} />
130
+ <Field label={t('detail.status')} value={statusLabel(view?.hubStatus ?? link.hubStatus)} />
131
+ <Field label={t('detail.agent')} value={agent?.name ?? link.agentId ?? t('detail.empty')} />
132
+ <Field label={t('detail.assignee')} value={link.assignee ?? t('detail.empty')} />
133
+ <Field label={t('detail.reviewer')} value={link.reviewer ?? t('detail.empty')} />
134
+ {pending.length === 0 ? null : (
135
+ <div>
136
+ <p className={styles.title}>{t('detail.pending')}</p>
137
+ <ul className={styles.list} data-dsh-part="team-questions">
138
+ {pending.map(question => (
139
+ <li key={question.id} className={styles.entry}>
140
+ <span className={styles.body}>{question.question}</span>
141
+ </li>
142
+ ))}
143
+ </ul>
144
+ </div>
145
+ )}
146
+ <Streams view={view} />
147
+ {view?.lastError === undefined ? null : <p className={styles.error}>{t('detail.error')}: {view.lastError}</p>}
148
+ </div>
149
+ )
150
+ }
151
+
152
+ /**
153
+ * Render the issue identity of one linkage.
154
+ * @param link - the card's linkage back to the hub.
155
+ * @returns the label, e.g. "issue #12".
156
+ */
157
+ export function issueLabel(link: TeamIssueLink): string {
158
+ return link.issueNumber === undefined ? link.issueId : 'issue #' + String(link.issueNumber)
159
+ }
@@ -0,0 +1,348 @@
1
+ /**
2
+ * The team configuration block inside the board's own settings card.
3
+ *
4
+ * It renders what the Host published (hub URL, team id, hostname, whether a Host
5
+ * Token is configured, the live connection state and which optional board
6
+ * capabilities this deployment really serves) and it writes through the board's
7
+ * same-origin action channel, which is the only channel a provider has. A token
8
+ * value travels exactly once, from this input to the Host, and is never read
9
+ * back: the field always renders empty and the status line says whether one is
10
+ * stored.
11
+ *
12
+ * The block is one nested settings card of the board's topic list, exactly like
13
+ * the sibling provider sections: the family card chrome supplies the border, the
14
+ * header, the body insets and the hairline between rows, so this module owns only
15
+ * the rows themselves. Its rows use the shared field grid (label and hint on the
16
+ * left, the control at the trailing edge) instead of a hand-rolled flex row, so a
17
+ * label is never squeezed into a character-per-line column by the control beside
18
+ * it.
19
+ *
20
+ * The block stays reachable while the extension is switched off, because it is
21
+ * where the switch is turned back on; it only reports that fact instead of
22
+ * pretending the forms still apply.
23
+ *
24
+ * @module dsh-task-board-team/client/team/settings
25
+ */
26
+ import { useState, type ReactElement } from 'react'
27
+ import type { CardShell } from '../settings-form.ts'
28
+ import { PluginSettingsCard } from '../PluginSettingsCard.tsx'
29
+ import card from '../settings-card.module.css'
30
+ import type { TaskBoardExtensionDispatch, TaskBoardSettingsSectionProps } from '../../core/contract.ts'
31
+ import { TEAM_EXTENSION_ID } from '../../core/identity.ts'
32
+ import type { TeamExtensionSummary } from '../../host/service.ts'
33
+ import { t, type TeamKey } from '../locales.ts'
34
+ import { useTeamSummary } from './summary.ts'
35
+ import styles from './team.module.css'
36
+
37
+ /** What the published summary carries about the configuration itself. */
38
+ interface PublishedConfiguration {
39
+ hubUrl?: string
40
+ teamId?: string
41
+ hostname?: string
42
+ tokenConfigured?: boolean
43
+ questionWaitMinutes?: number
44
+ }
45
+
46
+ /**
47
+ * The card state this block reports: the chrome asks for the family shape, and
48
+ * this block answers every field immediately through its own action channel, so
49
+ * there is never a pending draft or an invalid one.
50
+ * @param failed - whether the last write was refused.
51
+ * @returns the shell the card renders.
52
+ */
53
+ function shellOf(failed: boolean): CardShell {
54
+ return {
55
+ available: true,
56
+ exposed: true,
57
+ writable: true,
58
+ dirty: false,
59
+ invalid: false,
60
+ saving: false,
61
+ failed,
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Read the configuration half of one summary.
67
+ * @param summary - the published summary, or undefined.
68
+ * @returns the configuration fields the card renders.
69
+ */
70
+ export function readConfiguration(summary: TeamExtensionSummary | undefined): PublishedConfiguration {
71
+ const configuration = summary?.configuration
72
+ if (configuration === undefined) return {}
73
+ return {
74
+ ...(configuration.hubUrl === undefined ? {} : { hubUrl: configuration.hubUrl }),
75
+ ...(configuration.teamId === undefined ? {} : { teamId: configuration.teamId }),
76
+ ...(configuration.hostname === undefined ? {} : { hostname: configuration.hostname }),
77
+ ...(configuration.tokenConfigured === undefined ? {} : { tokenConfigured: configuration.tokenConfigured }),
78
+ ...(configuration.questionWaitMinutes === undefined ? {} : { questionWaitMinutes: configuration.questionWaitMinutes }),
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Dispatch one action of this extension.
84
+ * @param dispatch - the board's action dispatcher.
85
+ * @param action - provider-owned action name.
86
+ * @param payload - opaque payload.
87
+ * @returns whether the board accepted the action.
88
+ */
89
+ async function send(
90
+ dispatch: TaskBoardExtensionDispatch,
91
+ action: string,
92
+ payload?: Record<string, unknown>,
93
+ ): Promise<boolean> {
94
+ try {
95
+ return await dispatch({
96
+ extensionId: TEAM_EXTENSION_ID,
97
+ action,
98
+ ...(payload === undefined ? {} : { payload }),
99
+ })
100
+ } catch {
101
+ return false
102
+ }
103
+ }
104
+
105
+ /** A label with its control at the row's trailing edge. */
106
+ function ValueRow({ label, value }: { label: string; value: string }): ReactElement {
107
+ return (
108
+ <div className={card.field}>
109
+ <span className={card.head}><span className={card.label}>{label}</span></span>
110
+ <span className={styles.value}>{value}</span>
111
+ </div>
112
+ )
113
+ }
114
+
115
+ /** A label with a text input: the hint sits under the label, the field at the trailing edge. */
116
+ function TextRow(props: {
117
+ id: string
118
+ label: string
119
+ hint?: string
120
+ value: string
121
+ placeholder?: string
122
+ numeric?: boolean
123
+ onEdit: (next: string) => void
124
+ }): ReactElement {
125
+ return (
126
+ <div className={card.field}>
127
+ <span className={card.head}>
128
+ <label className={card.label} htmlFor={props.id}>{props.label}</label>
129
+ </span>
130
+ {props.hint === undefined ? null : <p className={card.hint}>{props.hint}</p>}
131
+ <input
132
+ id={props.id}
133
+ className={card.input}
134
+ {...(props.placeholder === undefined ? {} : { placeholder: props.placeholder })}
135
+ {...(props.numeric === true ? { inputMode: 'numeric' as const } : {})}
136
+ value={props.value}
137
+ onChange={event => { props.onEdit(event.target.value) }}
138
+ />
139
+ </div>
140
+ )
141
+ }
142
+
143
+ /**
144
+ * One capability line of the settings block: the name, whether this deployment
145
+ * serves it, and what a reader can do when it does not.
146
+ */
147
+ function Capability({ label, available, missing }: { label: string; available: boolean; missing: string }): ReactElement {
148
+ return (
149
+ <div className={card.field} data-dsh-part="team-capability">
150
+ <span className={card.head}><span className={card.label}>{label}</span></span>
151
+ {available ? null : <p className={card.hint}>{missing}</p>}
152
+ <span className={styles.value}>
153
+ {available ? t('section.capability.available') : t('section.capability.missing')}
154
+ </span>
155
+ </div>
156
+ )
157
+ }
158
+
159
+ /**
160
+ * The body of the settings card: the configuration form and what the Host
161
+ * reports about it. It is its own component so the card can own the disclosure
162
+ * and the write report while this half owns the drafts.
163
+ * @param props - the board's action dispatcher, plus the write report the card
164
+ * renders in its footer.
165
+ * @returns the card body.
166
+ */
167
+ export function TeamSettingsBody({ dispatch, onSaved }: {
168
+ dispatch: TaskBoardSettingsSectionProps['dispatch']
169
+ onSaved: (accepted: boolean) => void
170
+ }): ReactElement {
171
+ const summary = useTeamSummary()
172
+ const configuration = readConfiguration(summary)
173
+ const [hubUrl, setHubUrl] = useState<string | undefined>(undefined)
174
+ const [teamId, setTeamId] = useState<string | undefined>(undefined)
175
+ const [members, setMembers] = useState<string | undefined>(undefined)
176
+ const [waitMinutes, setWaitMinutes] = useState<string | undefined>(undefined)
177
+ const [token, setToken] = useState('')
178
+ const [saved, setSaved] = useState<boolean | undefined>(undefined)
179
+
180
+ const connection = summary?.connection.state ?? 'idle'
181
+ const membersValue = members ?? (summary?.agents ?? []).map(agent => agent.memberId).join(', ')
182
+ const stateKey = ('section.connection.' + connection) as TeamKey
183
+
184
+ const saveSettings = async (): Promise<void> => {
185
+ const bindings = (membersValue ?? '')
186
+ .split(',')
187
+ .map(entry => entry.trim())
188
+ .filter(entry => entry !== '')
189
+ .map(memberId => ({ memberId }))
190
+ const ok = await send(dispatch, 'setup-save', {
191
+ ...(hubUrl === undefined ? {} : { hubUrl }),
192
+ ...(teamId === undefined ? {} : { teamId }),
193
+ agents: bindings,
194
+ questionWaitMinutes: Number.parseInt(waitMinutes ?? String(configuration.questionWaitMinutes ?? 0), 10) || 0,
195
+ })
196
+ setSaved(ok)
197
+ onSaved(ok)
198
+ }
199
+
200
+ return (
201
+ <div data-dsh-plugin="task-board-team" data-dsh-part="team-settings">
202
+ <ValueRow label={t('section.connection')} value={t(stateKey)} />
203
+ {summary?.connection.hostId === undefined
204
+ ? null
205
+ : <ValueRow label={t('section.host')} value={summary.connection.hostId} />}
206
+ <TextRow
207
+ id="task-board-team-hub"
208
+ label={t('section.hub')}
209
+ placeholder="https://hub.example.com"
210
+ value={hubUrl ?? configuration.hubUrl ?? ''}
211
+ onEdit={setHubUrl}
212
+ />
213
+ <TextRow
214
+ id="task-board-team-team"
215
+ label={t('section.team')}
216
+ placeholder="team_..."
217
+ value={teamId ?? configuration.teamId ?? ''}
218
+ onEdit={setTeamId}
219
+ />
220
+ <div className={card.field}>
221
+ <span className={card.head}>
222
+ <label className={card.label} htmlFor="task-board-team-token">{t('section.token')}</label>
223
+ <span className={styles.status} data-dsh-part="team-token-state">
224
+ {configuration.tokenConfigured === true ? t('section.token.configured') : t('section.token.missing')}
225
+ </span>
226
+ </span>
227
+ <p className={card.hint}>{t('section.token.placeholder')}</p>
228
+ <input
229
+ id="task-board-team-token"
230
+ className={card.input}
231
+ type="password"
232
+ autoComplete="off"
233
+ spellCheck={false}
234
+ placeholder={t('section.token.placeholderShort')}
235
+ value={token}
236
+ onChange={event => { setToken(event.target.value) }}
237
+ />
238
+ </div>
239
+ <TextRow
240
+ id="task-board-team-agents"
241
+ label={t('section.agents')}
242
+ hint={t('section.agents.hint')}
243
+ placeholder="member_..."
244
+ value={membersValue ?? ''}
245
+ onEdit={setMembers}
246
+ />
247
+ <TextRow
248
+ id="task-board-team-wait"
249
+ label={t('section.questionWait')}
250
+ hint={t('section.questionWait.hint')}
251
+ numeric
252
+ value={waitMinutes ?? String(configuration.questionWaitMinutes ?? 0)}
253
+ onEdit={setWaitMinutes}
254
+ />
255
+ {(summary?.agents ?? []).length === 0 ? <p className={styles.empty}>{t('section.agents.empty')}</p> : null}
256
+ <div className={styles.actions}>
257
+ <button className={styles.primaryButton} type="button" onClick={() => { void saveSettings() }}>
258
+ {t('section.save')}
259
+ </button>
260
+ <button
261
+ className={styles.button}
262
+ type="button"
263
+ disabled={token.trim() === ''}
264
+ onClick={() => {
265
+ void send(dispatch, 'set-token', { token }).then(ok => {
266
+ setSaved(ok)
267
+ if (ok) setToken('')
268
+ })
269
+ }}
270
+ >
271
+ {t('section.token.save')}
272
+ </button>
273
+ <button className={styles.button} type="button" onClick={() => { void send(dispatch, 'clear-token') }}>
274
+ {t('section.token.clear')}
275
+ </button>
276
+ <button className={styles.button} type="button" onClick={() => { void send(dispatch, 'refresh') }}>
277
+ {t('section.refresh')}
278
+ </button>
279
+ </div>
280
+ {saved === true ? <p className={styles.saved}>{t('section.saved')}</p> : null}
281
+ <p className={styles.groupTitle}>{t('section.capabilities')}</p>
282
+ <Capability
283
+ label={t('section.capability.followUp')}
284
+ available={summary?.capabilities.followUp === true}
285
+ missing={t('section.capability.followUpMissing')}
286
+ />
287
+ <Capability
288
+ label={t('section.capability.rework')}
289
+ available={summary?.capabilities.rework === true}
290
+ missing={t('section.capability.reworkMissing')}
291
+ />
292
+ <Capability
293
+ label={t('section.capability.run')}
294
+ available={summary?.capabilities.run === true}
295
+ missing={t('section.capability.runMissing')}
296
+ />
297
+ <Capability
298
+ label={t('section.capability.presetPin')}
299
+ available={summary?.presetPin === 'supported'}
300
+ missing={t('section.capability.presetPinMissing')}
301
+ />
302
+ {(summary?.problems ?? []).length === 0 ? null : (
303
+ <>
304
+ <p className={styles.groupTitle}>{t('section.problems')}</p>
305
+ <ul className={styles.list}>
306
+ {(summary?.problems ?? []).map(problem => (
307
+ <li key={problem} className={styles.entry}><span className={styles.body}>{problem}</span></li>
308
+ ))}
309
+ </ul>
310
+ </>
311
+ )}
312
+ {summary?.connection.lastError === undefined ? null : (
313
+ <p className={styles.error}>{summary.connection.lastError}</p>
314
+ )}
315
+ </div>
316
+ )
317
+ }
318
+
319
+ /**
320
+ * The settings block: one topic of the board's own settings card.
321
+ *
322
+ * Closed on arrival like the sibling provider card — the settings page opens as
323
+ * a topic list, and this topic is one of them. The body is read only by a reader
324
+ * who opens it, and its rows are written through the board's action channel, so
325
+ * the card holds no staged draft: save and discard are the no-ops of an
326
+ * always-committed form, and the footer reports a refused write.
327
+ * @param props - the board's settings seat props.
328
+ * @returns the block.
329
+ */
330
+ export function TeamSettingsSection({ dispatch }: TaskBoardSettingsSectionProps): ReactElement {
331
+ const [saved, setSaved] = useState<boolean | undefined>(undefined)
332
+ return (
333
+ <PluginSettingsCard
334
+ t={t}
335
+ titleKey="section.title"
336
+ descriptionKey="section.description"
337
+ // One topic inside the board's own settings card, so it takes the same
338
+ // compact chrome its sibling provider and topic cards use.
339
+ density="nested"
340
+ defaultOpen={false}
341
+ state={shellOf(saved === false)}
342
+ onSave={() => {}}
343
+ onDiscard={() => {}}
344
+ >
345
+ <TeamSettingsBody dispatch={dispatch} onSaved={setSaved} />
346
+ </PluginSettingsCard>
347
+ )
348
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The published summary this extension's browser half renders.
3
+ *
4
+ * The Host publishes one opaque payload per extension; the board forwards it
5
+ * verbatim in the snapshot and this module is the only place that interprets it.
6
+ * It is a store rather than a hook so the seats (which receive only their owner
7
+ * props) can read one live value and re-render when the board pushes a new one.
8
+ *
9
+ * @module dsh-task-board-team/client/team/summary
10
+ */
11
+ import { useSyncExternalStore } from 'react'
12
+ import type { TeamExtensionSummary } from '../../host/service.ts'
13
+
14
+ /** The value the seats read. */
15
+ const EMPTY: TeamExtensionSummary | undefined = undefined
16
+
17
+ let current: TeamExtensionSummary | undefined = EMPTY
18
+ const listeners = new Set<() => void>()
19
+
20
+ /**
21
+ * Take the summaries the board snapshot carries.
22
+ * @param extensions - the snapshot's published extension summaries.
23
+ */
24
+ export function acceptPublishedSummaries(extensions: Readonly<Record<string, unknown>> | undefined): void {
25
+ const entry = extensions?.['task-board-team']
26
+ const next = readSummary(entry)
27
+ if (next === undefined && current === undefined) return
28
+ current = next
29
+ for (const listener of [...listeners]) listener()
30
+ }
31
+
32
+ /** Drop the published summary: a hidden provider must not look like live state. */
33
+ export function clearSummary(): void {
34
+ if (current === undefined) return
35
+ current = undefined
36
+ for (const listener of [...listeners]) listener()
37
+ }
38
+
39
+ /**
40
+ * Read the live summary.
41
+ * @returns the summary, or undefined before the Host published one.
42
+ */
43
+ export function getSummary(): TeamExtensionSummary | undefined {
44
+ return current
45
+ }
46
+
47
+ /**
48
+ * Read one card's collaboration view.
49
+ * @param taskId - the board card id.
50
+ * @returns the view, or undefined when this card mirrors no issue.
51
+ */
52
+ export function cardViewOf(taskId: string): TeamExtensionSummary['cards'][string] | undefined {
53
+ return current?.cards[taskId]
54
+ }
55
+
56
+ function subscribe(listener: () => void): () => void {
57
+ listeners.add(listener)
58
+ return () => { listeners.delete(listener) }
59
+ }
60
+
61
+ /**
62
+ * Subscribe one component to the live summary.
63
+ * @returns the current summary and a re-render on every change.
64
+ */
65
+ export function useTeamSummary(): TeamExtensionSummary | undefined {
66
+ return useSyncExternalStore(subscribe, getSummary, getSummary)
67
+ }
68
+
69
+ /**
70
+ * Validate one published payload into the summary shape.
71
+ *
72
+ * A payload from another revision of this extension is read for the fields it
73
+ * does carry and never trusted for the ones it does not, so a version skew
74
+ * degrades one section instead of throwing inside the board's render.
75
+ * @param raw - the opaque payload the board forwarded.
76
+ * @returns the summary, or undefined when it carries no usable shape.
77
+ */
78
+ export function readSummary(raw: unknown): TeamExtensionSummary | undefined {
79
+ if (typeof raw !== 'object' || raw === null) return undefined
80
+ const value = raw as Partial<TeamExtensionSummary>
81
+ if (typeof value.connection !== 'object' || value.connection === null) return undefined
82
+ const connection = value.connection as TeamExtensionSummary['connection']
83
+ return {
84
+ connection: {
85
+ state: readState(connection.state),
86
+ ...(typeof connection.hostId === 'string' ? { hostId: connection.hostId } : {}),
87
+ ...(typeof connection.lastHeartbeatAt === 'number' ? { lastHeartbeatAt: connection.lastHeartbeatAt } : {}),
88
+ reconnects: typeof connection.reconnects === 'number' ? connection.reconnects : 0,
89
+ ...(typeof connection.lastError === 'string' ? { lastError: connection.lastError } : {}),
90
+ },
91
+ capabilities: {
92
+ followUp: value.capabilities?.followUp === true,
93
+ rework: value.capabilities?.rework === true,
94
+ run: value.capabilities?.run === true,
95
+ },
96
+ agents: Array.isArray(value.agents)
97
+ ? value.agents.flatMap(agent => typeof agent?.memberId === 'string' && typeof agent?.name === 'string'
98
+ ? [{
99
+ memberId: agent.memberId,
100
+ name: agent.name,
101
+ ...(typeof agent.preset === 'string' ? { preset: agent.preset } : {}),
102
+ ...(typeof agent.hubAgentId === 'string' ? { hubAgentId: agent.hubAgentId } : {}),
103
+ }]
104
+ : [])
105
+ : [],
106
+ problems: Array.isArray(value.problems) ? value.problems.filter((line): line is string => typeof line === 'string') : [],
107
+ presetPin: value.presetPin === 'supported' || value.presetPin === 'missing' ? value.presetPin : 'unknown',
108
+ cards: typeof value.cards === 'object' && value.cards !== null ? value.cards : {},
109
+ ...(readConfigurationField(value.configuration) === undefined
110
+ ? {}
111
+ : { configuration: readConfigurationField(value.configuration) as NonNullable<TeamExtensionSummary['configuration']> }),
112
+ pendingQuestions: Array.isArray(value.pendingQuestions)
113
+ ? value.pendingQuestions.flatMap(question => typeof question?.taskId === 'string'
114
+ ? [{
115
+ id: typeof question.id === 'string' ? question.id : '',
116
+ taskId: question.taskId,
117
+ issueId: typeof question.issueId === 'string' ? question.issueId : '',
118
+ question: typeof question.question === 'string' ? question.question : '',
119
+ askedAt: typeof question.askedAt === 'number' ? question.askedAt : 0,
120
+ ...(typeof question.hubQuestionId === 'string' ? { hubQuestionId: question.hubQuestionId } : {}),
121
+ }]
122
+ : [])
123
+ : [],
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Read the configuration half of one published payload.
129
+ * @param raw - the opaque member.
130
+ * @returns the fields this build understands, or undefined when there are none.
131
+ */
132
+ function readConfigurationField(raw: unknown): TeamExtensionSummary['configuration'] | undefined {
133
+ if (typeof raw !== 'object' || raw === null) return undefined
134
+ const value = raw as Record<string, unknown>
135
+ const configuration: NonNullable<TeamExtensionSummary['configuration']> = {
136
+ ...(typeof value.hubUrl === 'string' ? { hubUrl: value.hubUrl } : {}),
137
+ ...(typeof value.teamId === 'string' ? { teamId: value.teamId } : {}),
138
+ ...(typeof value.hostname === 'string' ? { hostname: value.hostname } : {}),
139
+ ...(typeof value.tokenConfigured === 'boolean' ? { tokenConfigured: value.tokenConfigured } : {}),
140
+ ...(typeof value.questionWaitMinutes === 'number' ? { questionWaitMinutes: value.questionWaitMinutes } : {}),
141
+ }
142
+ return Object.keys(configuration).length === 0 ? undefined : configuration
143
+ }
144
+
145
+ function readState(raw: unknown): TeamExtensionSummary['connection']['state'] {
146
+ switch (raw) {
147
+ case 'idle':
148
+ case 'connecting':
149
+ case 'online':
150
+ case 'reconnecting':
151
+ case 'error':
152
+ return raw
153
+ default:
154
+ return 'idle'
155
+ }
156
+ }