@linxin666/dsh-client-ui-task-board 0.4.21 → 0.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +7 -6
- package/README.zh.md +7 -6
- package/lib/client.js +452 -95
- package/lib/client.js.map +1 -1
- package/lib/index.js +84 -47
- package/lib/types/client/TaskBoardSettingsCard.d.ts +1 -1
- package/lib/types/client/board/AttachmentField.d.ts +3 -1
- package/lib/types/client/board/NewTaskModal.d.ts +4 -2
- package/lib/types/client/board/TaskBoard.d.ts +16 -1
- package/lib/types/client/board/model-options.d.ts +2 -2
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/locales.d.ts +4 -0
- package/lib/types/client/native-panel.d.ts +19 -1
- package/lib/types/client/session-activity.d.ts +36 -0
- package/lib/types/client/user-message-action.d.ts +46 -0
- package/lib/types/core/controller.d.ts +16 -0
- package/lib/types/core/model-catalog.d.ts +1 -1
- package/lib/types/core/tasks.d.ts +9 -0
- package/lib/types/core/use-cases/task-update.d.ts +25 -17
- package/lib/types/dsh-home.d.ts +13 -3
- package/lib/types/host-routes.d.ts +2 -6
- package/lib/types/tool-surface.d.ts +6 -2
- package/package.json +33 -33
- package/src/client/TaskBoardSettingsCard.tsx +2 -2
- package/src/client/board/AttachmentField.tsx +6 -1
- package/src/client/board/EditTaskModal.tsx +4 -1
- package/src/client/board/NewTaskModal.tsx +8 -6
- package/src/client/board/TaskBoard.tsx +59 -13
- package/src/client/board/TaskDetail.tsx +16 -11
- package/src/client/board/model-options.ts +18 -8
- package/src/client/board.module.css +32 -0
- package/src/client/index.ts +31 -19
- package/src/client/locales.ts +8 -0
- package/src/client/native-panel.tsx +85 -5
- package/src/client/session-activity.tsx +163 -0
- package/src/client/user-message-action.tsx +211 -0
- package/src/core/controller.ts +30 -0
- package/src/core/model-catalog.ts +1 -1
- package/src/core/store.ts +2 -0
- package/src/core/tasks.ts +13 -0
- package/src/core/use-cases/task-update.ts +29 -19
- package/src/dsh-home.ts +35 -12
- package/src/host/agent-tools.ts +8 -0
- package/src/host-ledger.ts +11 -5
- package/src/host-routes.ts +7 -16
- package/src/host-runner.ts +4 -4
- package/src/host-service.ts +6 -1
- package/src/index.ts +2 -3
- package/src/protocol.ts +4 -0
- package/src/tool-surface.ts +17 -2
package/src/client/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { IWorkspaces } from '@deepseek-ai/dsh-api-workspace-controller/clie
|
|
|
15
15
|
import type { ConfigForm, ConfigForms } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
16
16
|
import type {} from '@deepseek-ai/dsh-api-remotes/client'
|
|
17
17
|
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
18
|
-
import type {} from '@deepseek-ai/dsh-client-ui-slots'
|
|
18
|
+
import type {} from '@deepseek-ai/dsh-client-ui-slots/client'
|
|
19
19
|
// Type-only: pulls the locale plugin's Context merge (ctx.locale) and its
|
|
20
20
|
// LocaleNamespaceMap merge table.
|
|
21
21
|
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
@@ -32,6 +32,8 @@ import { LocalStorageTaskStore } from '../core/store.ts'
|
|
|
32
32
|
import { hasOpenExecution } from '../core/tasks.ts'
|
|
33
33
|
import { claimTaskboardApply, releaseTaskboardApply } from './apply-guard.ts'
|
|
34
34
|
import { registerTaskBoardPanel } from './native-panel.tsx'
|
|
35
|
+
import { registerTaskBoardSessionActivity } from './session-activity.tsx'
|
|
36
|
+
import { registerUserMessageTaskAction } from './user-message-action.tsx'
|
|
35
37
|
import { TaskBoardSettingsCard, TaskBoardSettingsCardController, type TaskBoardSettings } from './TaskBoardSettingsCard.tsx'
|
|
36
38
|
import { en, zh, setRuntimeTranslate, type TaskBoardKey } from './locales.ts'
|
|
37
39
|
import { HttpTaskBoardHostTransport } from './host-api.ts'
|
|
@@ -94,7 +96,7 @@ export interface SettingsFormBinder {
|
|
|
94
96
|
bind<T>(spec: SettingsFormSpec<T>): ConfigForm<T>
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
99
|
+
declare module '@deepseek-ai/dsh-client-ui-slots/client' {
|
|
98
100
|
interface LocaleNamespaceMap {
|
|
99
101
|
/** Task-board surface copy. */
|
|
100
102
|
'task-board': TaskBoardKey
|
|
@@ -353,25 +355,27 @@ export function apply(ctx: ClientContext): void {
|
|
|
353
355
|
const created = await workspaces.create({ path })
|
|
354
356
|
return { workspaceId: created.workspaceId }
|
|
355
357
|
})
|
|
356
|
-
|
|
358
|
+
type ModelsCatalogRemote = { catalog?: () => Promise<{ ok: boolean; value?: unknown }> }
|
|
359
|
+
const pushModelOptions = async (scopedModels?: ModelsCatalogRemote): Promise<void> => {
|
|
357
360
|
try {
|
|
358
361
|
let models: ExecutionModelOption[] = []
|
|
359
|
-
let
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
let modelsRemote: ModelsCatalogRemote | undefined = scopedModels
|
|
363
|
+
if (modelsRemote === undefined) {
|
|
364
|
+
try {
|
|
365
|
+
modelsRemote = (remote as unknown as { models?: ModelsCatalogRemote }).models
|
|
366
|
+
} catch {
|
|
367
|
+
modelsRemote = undefined
|
|
368
|
+
}
|
|
364
369
|
}
|
|
365
|
-
if (typeof
|
|
366
|
-
const res = await
|
|
370
|
+
if (typeof modelsRemote?.catalog === 'function') {
|
|
371
|
+
const res = await modelsRemote.catalog()
|
|
367
372
|
if (res.ok) models = modelOptionsFromCatalog(res.value)
|
|
368
373
|
}
|
|
369
374
|
if (models.length === 0) {
|
|
370
375
|
const conn = ctx.get('connection') as {
|
|
371
376
|
api?: {
|
|
372
377
|
llm?: { discoverModels?: () => Promise<unknown> }
|
|
373
|
-
|
|
374
|
-
session?: { modelCatalog?: () => Promise<unknown> }
|
|
378
|
+
models?: { catalog?: () => Promise<unknown> }
|
|
375
379
|
}
|
|
376
380
|
} | undefined
|
|
377
381
|
if (conn?.api) {
|
|
@@ -379,13 +383,8 @@ export function apply(ctx: ClientContext): void {
|
|
|
379
383
|
const res = await conn.api.llm.discoverModels() as { result?: { value?: { models?: unknown } } }
|
|
380
384
|
models = modelOptionsFromDiscoveredModels(res?.result?.value?.models)
|
|
381
385
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
: typeof conn.api.sessions?.modelCatalog === 'function'
|
|
385
|
-
? conn.api.sessions.modelCatalog
|
|
386
|
-
: undefined
|
|
387
|
-
if (models.length === 0 && catalogFn !== undefined) {
|
|
388
|
-
const res = await catalogFn() as { result?: { value?: unknown } }
|
|
386
|
+
if (models.length === 0 && typeof conn.api.models?.catalog === 'function') {
|
|
387
|
+
const res = await conn.api.models.catalog() as { result?: { value?: unknown } }
|
|
389
388
|
models = modelOptionsFromCatalog(res?.result?.value)
|
|
390
389
|
}
|
|
391
390
|
}
|
|
@@ -397,6 +396,13 @@ export function apply(ctx: ClientContext): void {
|
|
|
397
396
|
console.error('[dsh-task-board] model options read failed', error)
|
|
398
397
|
}
|
|
399
398
|
}
|
|
399
|
+
const modelsCatalogFeed = ctx.inject(['remote.models' as never], (inner) => {
|
|
400
|
+
const modelsRemote = inner.get('remote.models' as never) as ModelsCatalogRemote | undefined
|
|
401
|
+
if (modelsRemote === undefined) return
|
|
402
|
+
void pushModelOptions(modelsRemote)
|
|
403
|
+
return inner.on('connection/reset', () => { void pushModelOptions(modelsRemote) })
|
|
404
|
+
})
|
|
405
|
+
disposers.push(() => { void modelsCatalogFeed.dispose() })
|
|
400
406
|
void pushModelOptions()
|
|
401
407
|
disposers.push(ctx.on('connection/reset', () => { void pushModelOptions() }))
|
|
402
408
|
// Native panel surfaces: one sidebar row and one center-column page, both
|
|
@@ -405,6 +411,12 @@ export function apply(ctx: ClientContext): void {
|
|
|
405
411
|
// view state follows the user clicking another panel row.
|
|
406
412
|
try {
|
|
407
413
|
disposers.push(registerTaskBoardPanel(ctx, controller))
|
|
414
|
+
disposers.push(registerTaskBoardSessionActivity(ctx, controller))
|
|
415
|
+
disposers.push(registerUserMessageTaskAction(ctx, controller, (sessionId) => {
|
|
416
|
+
const cwd = sessions.list.getSnapshot().byId[sessionId as never]?.cwd
|
|
417
|
+
if (cwd === undefined || cwd === '') return undefined
|
|
418
|
+
return workspaces.list.getSnapshot().items.find(item => item.path === cwd)?.workspaceId
|
|
419
|
+
}))
|
|
408
420
|
const layoutFace = ctx.get('layout') as { panelInfo?: { subscribe(listener: () => void): () => void; getSnapshot(): { activePanelId: unknown } } } | undefined
|
|
409
421
|
if (layoutFace?.panelInfo !== undefined) {
|
|
410
422
|
const sync = (): void => {
|
package/src/client/locales.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
/** zh dictionary (key-set source of truth). */
|
|
9
9
|
export const zh = {
|
|
10
10
|
'entry.label': '任务看板',
|
|
11
|
+
'activity.title': '任务看板',
|
|
11
12
|
'board.title': '任务看板',
|
|
12
13
|
'board.close': '返回会话',
|
|
13
14
|
'board.new': '新建任务',
|
|
@@ -42,8 +43,10 @@ export const zh = {
|
|
|
42
43
|
'board.projectNew': '新建项目…',
|
|
43
44
|
'board.projectNewPath': '项目目录(宿主上的绝对路径)',
|
|
44
45
|
'board.projectNewPathPlaceholder': '例如 C:\\work\\my-project 或 /home/me/project',
|
|
46
|
+
'board.projectBrowse': '浏览…',
|
|
45
47
|
'board.projectCreate': '创建项目',
|
|
46
48
|
'board.projectCreateFailed': '创建项目失败:{error}',
|
|
49
|
+
'chat.turnIntoTask': '转为任务卡片',
|
|
47
50
|
'new.aiParse': 'AI 解析',
|
|
48
51
|
'new.aiParseHint': '把从别处复制的一段话粘进来,让模型整理成标题、描述和执行 Prompt;解析结果只填进下面的表单,你可以先改再创建。',
|
|
49
52
|
'new.aiParsePlaceholder': '粘贴要变成任务的内容…',
|
|
@@ -159,6 +162,7 @@ export const zh = {
|
|
|
159
162
|
'detail.close': '关闭',
|
|
160
163
|
'edit.title': '编辑任务',
|
|
161
164
|
'edit.save': '保存',
|
|
165
|
+
'edit.attachmentsLocked': '附件已随首次执行固定:执行记录不快照附件,修改请用「复制为新任务」。',
|
|
162
166
|
'new.duplicateTitle': '新建任务(副本)',
|
|
163
167
|
'new.archiveOriginal': '创建后归档原任务',
|
|
164
168
|
'detail.prompt': '执行 Prompt',
|
|
@@ -407,6 +411,7 @@ export const zh = {
|
|
|
407
411
|
/** en dictionary, complete against the zh key set. */
|
|
408
412
|
export const en: Record<keyof typeof zh, string> = {
|
|
409
413
|
'entry.label': 'Task Board',
|
|
414
|
+
'activity.title': 'Task Board',
|
|
410
415
|
'board.title': 'Task Board',
|
|
411
416
|
'board.close': 'Back to chat',
|
|
412
417
|
'board.new': 'New Task',
|
|
@@ -441,8 +446,10 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
441
446
|
'board.projectNew': 'New project…',
|
|
442
447
|
'board.projectNewPath': 'Project directory (absolute path on the Host)',
|
|
443
448
|
'board.projectNewPathPlaceholder': 'e.g. C:\\work\\my-project or /home/me/project',
|
|
449
|
+
'board.projectBrowse': 'Browse…',
|
|
444
450
|
'board.projectCreate': 'Create project',
|
|
445
451
|
'board.projectCreateFailed': 'Could not create the project: {error}',
|
|
452
|
+
'chat.turnIntoTask': 'Turn into task card',
|
|
446
453
|
'new.aiParse': 'Parse with AI',
|
|
447
454
|
'new.aiParseHint': 'Paste text copied from somewhere else and let a model turn it into a title, description, and run prompt; the result only fills the form below, so you can edit it before creating the task.',
|
|
448
455
|
'new.aiParsePlaceholder': 'Paste the content to turn into a task…',
|
|
@@ -558,6 +565,7 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
558
565
|
'detail.close': 'Close',
|
|
559
566
|
'edit.title': 'Edit Task',
|
|
560
567
|
'edit.save': 'Save',
|
|
568
|
+
'edit.attachmentsLocked': 'Attachments froze with the first run: execution records do not snapshot attachments; use Duplicate as new copy to change them.',
|
|
561
569
|
'new.duplicateTitle': 'New Task (Copy)',
|
|
562
570
|
'new.archiveOriginal': 'Archive original task upon creation',
|
|
563
571
|
'detail.prompt': 'Run Prompt',
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
import { useMemo } from 'react'
|
|
20
20
|
import type { ReactNode } from 'react'
|
|
21
21
|
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
22
|
-
import type {} from '@deepseek-ai/dsh-client-ui-slots'
|
|
22
|
+
import type {} from '@deepseek-ai/dsh-client-ui-slots/client'
|
|
23
23
|
import type {} from '@deepseek-ai/dsh-client-ui-layout/client'
|
|
24
24
|
import type {} from '@deepseek-ai/dsh-client-ui-sidebar/client'
|
|
25
25
|
import { TASK_BOARD_PANEL_ID, type BoardController } from '../core/controller.ts'
|
|
26
|
-
import { TaskBoard } from './board/TaskBoard.tsx'
|
|
26
|
+
import { TaskBoard, type ProjectDirectoryDialogProps } from './board/TaskBoard.tsx'
|
|
27
27
|
import { seatsFromRenderSlot, TaskBoardSeatsProvider, type SlotRenderBinding } from './seats.tsx'
|
|
28
28
|
import { t } from './locales.ts'
|
|
29
29
|
import css from './board.module.css'
|
|
@@ -66,6 +66,54 @@ export function TaskBoardPanelIcon({ size }: { size: number; active: boolean }):
|
|
|
66
66
|
)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** Slot factory name owned by `@deepseek-ai/dsh-client-ui-directory-picker-browse`. */
|
|
70
|
+
export const DIRECTORY_BROWSER_DIALOG_FACTORY = 'directory.browser.dialog'
|
|
71
|
+
|
|
72
|
+
type RenderFactorySlotFn = (
|
|
73
|
+
name: string,
|
|
74
|
+
props: Record<string, unknown>,
|
|
75
|
+
options?: { readonly fallback?: ReactNode },
|
|
76
|
+
) => ReactNode
|
|
77
|
+
|
|
78
|
+
/** Minimal slice of `ctx.uiWorkspace` needed to drive `directory.browser.dialog`. */
|
|
79
|
+
export interface WorkspaceDirectorySource {
|
|
80
|
+
readonly listDirectory: (path?: string, signal?: AbortSignal) => Promise<unknown>
|
|
81
|
+
readonly createDirectory?: (path: string, name: string) => Promise<string>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Whether the host slot registry currently exposes the reusable `directory.browser.dialog` factory. */
|
|
85
|
+
export function hasDirectoryBrowserFactory(slots: unknown): boolean {
|
|
86
|
+
if (typeof slots !== 'object' || slots === null) return false
|
|
87
|
+
const snapshot = (slots as { snapshot?: (root?: string) => unknown }).snapshot
|
|
88
|
+
if (typeof snapshot !== 'function') return false
|
|
89
|
+
try {
|
|
90
|
+
const nodes = snapshot.call(slots, `factory:${DIRECTORY_BROWSER_DIALOG_FACTORY}`)
|
|
91
|
+
return Array.isArray(nodes) && nodes.length > 0
|
|
92
|
+
} catch {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readWorkspaceDirectorySource(ctx: ClientContext): WorkspaceDirectorySource | undefined {
|
|
98
|
+
try {
|
|
99
|
+
const raw = (ctx as unknown as { get?(name: string): unknown }).get?.('uiWorkspace')
|
|
100
|
+
if (typeof raw !== 'object' || raw === null) return undefined
|
|
101
|
+
const face = raw as {
|
|
102
|
+
listDirectory?: (path?: string, signal?: AbortSignal) => Promise<unknown>
|
|
103
|
+
createDirectory?: (path: string, name: string) => Promise<string>
|
|
104
|
+
}
|
|
105
|
+
if (typeof face.listDirectory !== 'function') return undefined
|
|
106
|
+
return {
|
|
107
|
+
listDirectory: (path, signal) => face.listDirectory!(path, signal),
|
|
108
|
+
...(typeof face.createDirectory === 'function'
|
|
109
|
+
? { createDirectory: (path: string, name: string) => face.createDirectory!(path, name) }
|
|
110
|
+
: {}),
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
return undefined
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
69
117
|
/**
|
|
70
118
|
* The main-slot page. The layout mounts it only while the board is the selected
|
|
71
119
|
* panel, so the conversation keeps the center column untouched the rest of the
|
|
@@ -75,16 +123,42 @@ export function TaskBoardPanelIcon({ size }: { size: number; active: boolean }):
|
|
|
75
123
|
* @param props - the framework main-slot share plus this entry's injected face.
|
|
76
124
|
* @returns the board page.
|
|
77
125
|
*/
|
|
78
|
-
export function TaskBoardPanel({ controller, renderSlot }: {
|
|
126
|
+
export function TaskBoardPanel({ controller, renderSlot, renderFactorySlot, directorySource, hasDirectoryDialog }: {
|
|
79
127
|
controller: BoardController
|
|
80
128
|
/** Child-slot renderer the registration declares (detail, card decoration, new-card section). */
|
|
81
129
|
renderSlot?: SlotRenderBinding
|
|
130
|
+
/** Factory-slot renderer supplied automatically by the shell slot renderer. */
|
|
131
|
+
renderFactorySlot?: RenderFactorySlotFn
|
|
132
|
+
/** Optional host directory listing/creation calls from `ctx.uiWorkspace`. */
|
|
133
|
+
directorySource?: WorkspaceDirectorySource
|
|
134
|
+
/** Live check for whether `directory.browser.dialog` is registered in `ctx.slots`. */
|
|
135
|
+
hasDirectoryDialog?: () => boolean
|
|
82
136
|
}): ReactNode {
|
|
83
137
|
const seats = useMemo(() => seatsFromRenderSlot(renderSlot), [renderSlot])
|
|
138
|
+
const dialogAvailable = renderFactorySlot !== undefined
|
|
139
|
+
&& directorySource !== undefined
|
|
140
|
+
&& (hasDirectoryDialog === undefined || hasDirectoryDialog())
|
|
141
|
+
const renderDirectoryDialog = useMemo(
|
|
142
|
+
() => (dialogAvailable
|
|
143
|
+
? (dialogProps: ProjectDirectoryDialogProps): ReactNode => renderFactorySlot!(
|
|
144
|
+
DIRECTORY_BROWSER_DIALOG_FACTORY,
|
|
145
|
+
{
|
|
146
|
+
open: dialogProps.open,
|
|
147
|
+
busy: dialogProps.busy,
|
|
148
|
+
listDirectory: directorySource!.listDirectory,
|
|
149
|
+
...(directorySource!.createDirectory === undefined ? {} : { createDirectory: directorySource!.createDirectory }),
|
|
150
|
+
onOpen: dialogProps.onOpen,
|
|
151
|
+
onClose: dialogProps.onClose,
|
|
152
|
+
},
|
|
153
|
+
{ fallback: null },
|
|
154
|
+
)
|
|
155
|
+
: undefined),
|
|
156
|
+
[dialogAvailable, directorySource, renderFactorySlot],
|
|
157
|
+
)
|
|
84
158
|
return (
|
|
85
159
|
<div className={css.panel} data-dsh-taskboard-view="" data-dsh-plugin="task-board">
|
|
86
160
|
<TaskBoardSeatsProvider value={seats}>
|
|
87
|
-
<TaskBoard controller={controller} />
|
|
161
|
+
<TaskBoard controller={controller} renderDirectoryDialog={renderDirectoryDialog} />
|
|
88
162
|
</TaskBoardSeatsProvider>
|
|
89
163
|
</div>
|
|
90
164
|
)
|
|
@@ -93,6 +167,8 @@ export function TaskBoardPanel({ controller, renderSlot }: {
|
|
|
93
167
|
/** The injected face both registrations receive. */
|
|
94
168
|
interface PanelFace {
|
|
95
169
|
controller: BoardController
|
|
170
|
+
directorySource?: WorkspaceDirectorySource
|
|
171
|
+
hasDirectoryDialog: () => boolean
|
|
96
172
|
}
|
|
97
173
|
|
|
98
174
|
/**
|
|
@@ -132,7 +208,11 @@ export function registerTaskBoardPanel(ctx: ClientContext, controller: BoardCont
|
|
|
132
208
|
'task-board.card.decoration': { kind: 'list', scope: 'root' },
|
|
133
209
|
'task-board.compose.section': { kind: 'list', scope: 'root' },
|
|
134
210
|
},
|
|
135
|
-
inject: (): PanelFace => ({
|
|
211
|
+
inject: (): PanelFace => ({
|
|
212
|
+
controller,
|
|
213
|
+
directorySource: readWorkspaceDirectorySource(ctx),
|
|
214
|
+
hasDirectoryDialog: () => hasDirectoryBrowserFactory(slots),
|
|
215
|
+
}),
|
|
136
216
|
}, TaskBoardPanel as never)))
|
|
137
217
|
|
|
138
218
|
return () => {
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session island activity source for `dsh-task-board`.
|
|
3
|
+
*
|
|
4
|
+
* Reports ongoing task-board executions tied to a Session (either the Session
|
|
5
|
+
* executing a card or the Session that initiated that card's execution) to the
|
|
6
|
+
* official `sessionActivities` service and contributes a matching 16px glyph
|
|
7
|
+
* to `conversation.session.panel.activity.icon`. Reads exclusively from the
|
|
8
|
+
* live {@link BoardController} mirror so observing a Session costs zero extra
|
|
9
|
+
* network traffic.
|
|
10
|
+
*/
|
|
11
|
+
import { createElement, type ReactNode } from 'react'
|
|
12
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
13
|
+
import type { BoardController } from '../core/controller.ts'
|
|
14
|
+
import type { TaskRecord } from '../core/tasks.ts'
|
|
15
|
+
import { t } from './locales.ts'
|
|
16
|
+
|
|
17
|
+
/** Stable source id shared with the keyed `conversation.session.panel.activity.icon` entry. */
|
|
18
|
+
export const TASK_BOARD_ACTIVITY_ID = 'dsh-task-board'
|
|
19
|
+
|
|
20
|
+
/** Official `SessionActivityStatus` subset reported to `sessionActivities`. */
|
|
21
|
+
export type TaskBoardActivityStatus = 'queued' | 'running' | 'stopping' | 'done' | 'failed' | 'inactive'
|
|
22
|
+
|
|
23
|
+
/** One reported activity unit matching `@deepseek-ai/dsh-client-ui-session-panel`. */
|
|
24
|
+
export interface TaskBoardSessionActivity {
|
|
25
|
+
readonly id: string
|
|
26
|
+
readonly status: TaskBoardActivityStatus
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ObservableActivities {
|
|
30
|
+
getSnapshot(): readonly TaskBoardSessionActivity[]
|
|
31
|
+
subscribe(listener: () => void): () => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface SessionActivitiesFace {
|
|
35
|
+
registerSource(source: {
|
|
36
|
+
readonly id: string
|
|
37
|
+
readonly title: () => string
|
|
38
|
+
readonly observe: (sessionId: unknown) => ObservableActivities
|
|
39
|
+
}): () => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ActivitySlotsFace {
|
|
43
|
+
inject(name: string, register: () => () => void): () => void
|
|
44
|
+
register(options: { name: string; key: string }, component: () => ReactNode): () => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const EMPTY_ACTIVITIES: readonly TaskBoardSessionActivity[] = []
|
|
48
|
+
|
|
49
|
+
function sameActivities(
|
|
50
|
+
left: readonly TaskBoardSessionActivity[],
|
|
51
|
+
right: readonly TaskBoardSessionActivity[],
|
|
52
|
+
): boolean {
|
|
53
|
+
return left.length === right.length
|
|
54
|
+
&& left.every((item, index) => item.id === right[index]?.id && item.status === right[index]?.status)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Derive the ongoing task activities linked to one Session id.
|
|
59
|
+
* A card counts when it has an unsettled execution (`endedAt === undefined`)
|
|
60
|
+
* whose own `sessionId` or `initiatedBy` matches `sessionId`.
|
|
61
|
+
*/
|
|
62
|
+
export function taskActivitiesForSession(
|
|
63
|
+
tasks: readonly TaskRecord[],
|
|
64
|
+
sessionId: string,
|
|
65
|
+
): readonly TaskBoardSessionActivity[] {
|
|
66
|
+
const active: TaskBoardSessionActivity[] = []
|
|
67
|
+
for (const task of tasks) {
|
|
68
|
+
const matches = task.executions.some(
|
|
69
|
+
exec => exec.endedAt === undefined && (exec.sessionId === sessionId || exec.initiatedBy === sessionId),
|
|
70
|
+
)
|
|
71
|
+
if (matches) active.push({ id: task.id, status: 'running' })
|
|
72
|
+
}
|
|
73
|
+
return active.length === 0 ? EMPTY_ACTIVITIES : active
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 16px task-board glyph rendered in the Session island header toggle. */
|
|
77
|
+
export function TaskBoardActivityIcon(): ReactNode {
|
|
78
|
+
return createElement(
|
|
79
|
+
'svg',
|
|
80
|
+
{
|
|
81
|
+
viewBox: '0 0 16 16',
|
|
82
|
+
width: 16,
|
|
83
|
+
height: 16,
|
|
84
|
+
fill: 'none',
|
|
85
|
+
stroke: 'currentColor',
|
|
86
|
+
strokeWidth: '1.3',
|
|
87
|
+
strokeLinecap: 'round',
|
|
88
|
+
strokeLinejoin: 'round',
|
|
89
|
+
'aria-hidden': 'true',
|
|
90
|
+
},
|
|
91
|
+
createElement('rect', { x: 2, y: 2.5, width: 12, height: 11, rx: 1.5 }),
|
|
92
|
+
createElement('path', { d: 'M2 6.5h12M6.5 6.5v7' }),
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Register the optional `sessionActivities` source and matching island icon.
|
|
98
|
+
* Returns a disposer releasing both when the board UI unmounts or disables.
|
|
99
|
+
*/
|
|
100
|
+
export function registerTaskBoardSessionActivity(
|
|
101
|
+
ctx: ClientContext,
|
|
102
|
+
controller: Pick<BoardController, 'getSnapshot' | 'subscribe'>,
|
|
103
|
+
): () => void {
|
|
104
|
+
const disposers: Array<() => void> = []
|
|
105
|
+
|
|
106
|
+
const injectFn = (ctx as unknown as { inject?: (deps: readonly string[], cb: (scope: ClientContext) => void) => { dispose(): unknown } }).inject
|
|
107
|
+
if (typeof injectFn === 'function') {
|
|
108
|
+
let stopSource: (() => void) | undefined
|
|
109
|
+
const releaseSource = (): void => {
|
|
110
|
+
const stop = stopSource
|
|
111
|
+
stopSource = undefined
|
|
112
|
+
stop?.()
|
|
113
|
+
}
|
|
114
|
+
const fork = injectFn.call(ctx, ['sessionActivities'], (scope) => {
|
|
115
|
+
const service = (scope as unknown as { get?(name: string): unknown }).get?.('sessionActivities') as SessionActivitiesFace | undefined
|
|
116
|
+
if (typeof service?.registerSource !== 'function') return
|
|
117
|
+
scope.effect(() => {
|
|
118
|
+
releaseSource()
|
|
119
|
+
stopSource = service.registerSource({
|
|
120
|
+
id: TASK_BOARD_ACTIVITY_ID,
|
|
121
|
+
title: () => t('activity.title'),
|
|
122
|
+
observe: (sessionId) => {
|
|
123
|
+
const key = String(sessionId)
|
|
124
|
+
let cachedTasks: readonly TaskRecord[] | undefined
|
|
125
|
+
let cached: readonly TaskBoardSessionActivity[] = EMPTY_ACTIVITIES
|
|
126
|
+
return {
|
|
127
|
+
getSnapshot: () => {
|
|
128
|
+
const tasks = controller.getSnapshot().tasks
|
|
129
|
+
if (tasks !== cachedTasks) {
|
|
130
|
+
cachedTasks = tasks
|
|
131
|
+
const next = taskActivitiesForSession(tasks, key)
|
|
132
|
+
if (!sameActivities(cached, next)) cached = next
|
|
133
|
+
}
|
|
134
|
+
return cached
|
|
135
|
+
},
|
|
136
|
+
subscribe: listener => controller.subscribe(listener),
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
|
+
return releaseSource
|
|
141
|
+
}, 'task-board: session activity source')
|
|
142
|
+
})
|
|
143
|
+
disposers.push(() => {
|
|
144
|
+
releaseSource()
|
|
145
|
+
void fork?.dispose?.()
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const slots = (ctx as unknown as { slots?: ActivitySlotsFace }).slots
|
|
150
|
+
if (typeof slots?.inject === 'function' && typeof slots?.register === 'function') {
|
|
151
|
+
disposers.push(slots.inject(
|
|
152
|
+
'conversation.session.panel.activity.icon',
|
|
153
|
+
() => slots.register({
|
|
154
|
+
name: 'conversation.session.panel.activity.icon',
|
|
155
|
+
key: TASK_BOARD_ACTIVITY_ID,
|
|
156
|
+
}, TaskBoardActivityIcon),
|
|
157
|
+
))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return () => {
|
|
161
|
+
for (const dispose of disposers.splice(0)) dispose()
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable user-message action ("Turn into task card") registered into the
|
|
3
|
+
* official `conversation.chat.user-actions` list slot (DSH 0.2.3-alpha.4+).
|
|
4
|
+
*
|
|
5
|
+
* Reads the user message text through the slot's standard `useChat` selector
|
|
6
|
+
* hook (never scraping the DOM), builds a draft with the first non-empty line
|
|
7
|
+
* as title and the full text as prompt, and opens the task board's create
|
|
8
|
+
* dialog prefilled with that draft and the session's workspace id when known.
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, useCallback, type ReactNode } from 'react'
|
|
11
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
12
|
+
import type { BoardController, ComposeTaskDraft } from '../core/controller.ts'
|
|
13
|
+
import { t } from './locales.ts'
|
|
14
|
+
import css from './board.module.css'
|
|
15
|
+
|
|
16
|
+
/** Stable slot entry id inside `conversation.chat.user-actions`. */
|
|
17
|
+
export const USER_ACTION_CREATE_TASK_ID = 'task-board-create-card'
|
|
18
|
+
|
|
19
|
+
/** Maximum character length for the derived draft title. */
|
|
20
|
+
const DRAFT_TITLE_MAX_CHARS = 80
|
|
21
|
+
|
|
22
|
+
interface ChatUserNodeLike {
|
|
23
|
+
readonly kind?: string
|
|
24
|
+
readonly data?: {
|
|
25
|
+
readonly messageId?: unknown
|
|
26
|
+
readonly content?: unknown
|
|
27
|
+
}
|
|
28
|
+
readonly messageId?: unknown
|
|
29
|
+
readonly content?: unknown
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Structural slice of the official `ChatSnapshot` exposed through `useChat`. */
|
|
33
|
+
export interface ChatSnapshotLike {
|
|
34
|
+
readonly nodes?: {
|
|
35
|
+
values?(): readonly ChatUserNodeLike[]
|
|
36
|
+
}
|
|
37
|
+
readonly legacy?: {
|
|
38
|
+
readonly nodes?: readonly ChatUserNodeLike[]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Standard props passed by the shell renderer to a `conversation.chat.user-actions` entry. */
|
|
43
|
+
export interface UserMessageTaskActionProps {
|
|
44
|
+
readonly messageId: unknown
|
|
45
|
+
readonly sessionId?: unknown
|
|
46
|
+
readonly useChat?: <T>(selector: (snapshot: ChatSnapshotLike) => T) => T
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Optional resolver mapping a session id to its owning task-board workspace id. */
|
|
50
|
+
export type WorkspaceIdResolver = (sessionId: string) => string | undefined
|
|
51
|
+
|
|
52
|
+
interface SlotsFace {
|
|
53
|
+
inject(name: string, register: () => () => void): () => void
|
|
54
|
+
register(
|
|
55
|
+
options: { name: string; id: string; order: number; label: () => string },
|
|
56
|
+
component: (props: UserMessageTaskActionProps) => ReactNode,
|
|
57
|
+
): () => void
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function textFromContent(content: unknown): string {
|
|
61
|
+
if (typeof content === 'string') return content.trim()
|
|
62
|
+
if (!Array.isArray(content)) return ''
|
|
63
|
+
const parts: string[] = []
|
|
64
|
+
for (const part of content) {
|
|
65
|
+
if (typeof part === 'string') {
|
|
66
|
+
if (part.length > 0) parts.push(part)
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
if (typeof part !== 'object' || part === null) continue
|
|
70
|
+
const record = part as { type?: unknown; text?: unknown }
|
|
71
|
+
if ((record.type === 'text' || record.type === undefined) && typeof record.text === 'string' && record.text.length > 0) {
|
|
72
|
+
parts.push(record.text)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return parts.join('\n').trim()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Extract the plain text of a durable user message identified by `messageId`
|
|
80
|
+
* from an official `ChatSnapshot`. Returns an empty string when absent.
|
|
81
|
+
*/
|
|
82
|
+
export function extractUserMessageText(snapshot: ChatSnapshotLike | undefined, messageId: unknown): string {
|
|
83
|
+
if (snapshot === undefined || messageId === undefined || messageId === null) return ''
|
|
84
|
+
const target = String(messageId)
|
|
85
|
+
if (target === '') return ''
|
|
86
|
+
|
|
87
|
+
const materialized = snapshot.nodes?.values?.()
|
|
88
|
+
if (Array.isArray(materialized)) {
|
|
89
|
+
for (const node of materialized) {
|
|
90
|
+
if (node?.kind !== 'user') continue
|
|
91
|
+
const id = node.data?.messageId ?? node.messageId
|
|
92
|
+
if (id !== undefined && id !== null && String(id) === target) {
|
|
93
|
+
return textFromContent(node.data?.content ?? node.content)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const legacy = snapshot.legacy?.nodes
|
|
99
|
+
if (Array.isArray(legacy)) {
|
|
100
|
+
for (const node of legacy) {
|
|
101
|
+
if (node?.kind !== 'user') continue
|
|
102
|
+
const id = node.data?.messageId ?? node.messageId
|
|
103
|
+
if (id !== undefined && id !== null && String(id) === target) {
|
|
104
|
+
return textFromContent(node.data?.content ?? node.content)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return ''
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Build a prefilled {@link ComposeTaskDraft} from a durable user message's text
|
|
114
|
+
* and optional owning workspace id.
|
|
115
|
+
*/
|
|
116
|
+
export function draftFromUserMessage(text: string, workspaceId?: string): ComposeTaskDraft {
|
|
117
|
+
const normalized = text.trim()
|
|
118
|
+
const firstLine = normalized
|
|
119
|
+
.split(/\r?\n/)
|
|
120
|
+
.map(line => line.trim())
|
|
121
|
+
.find(line => line.length > 0) ?? ''
|
|
122
|
+
const title = firstLine.length > DRAFT_TITLE_MAX_CHARS
|
|
123
|
+
? `${firstLine.slice(0, DRAFT_TITLE_MAX_CHARS - 1)}…`
|
|
124
|
+
: firstLine
|
|
125
|
+
return {
|
|
126
|
+
title,
|
|
127
|
+
prompt: normalized,
|
|
128
|
+
...(workspaceId !== undefined && workspaceId !== '' ? { workspaceId } : {}),
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function resolveSessionWorkspaceId(resolver: WorkspaceIdResolver | undefined, sessionId: unknown): string | undefined {
|
|
133
|
+
if (resolver === undefined || sessionId === undefined || sessionId === null) return undefined
|
|
134
|
+
const id = String(sessionId)
|
|
135
|
+
if (id === '') return undefined
|
|
136
|
+
try {
|
|
137
|
+
const raw = resolver(id)
|
|
138
|
+
return typeof raw === 'string' && raw !== '' ? raw : undefined
|
|
139
|
+
} catch {
|
|
140
|
+
return undefined
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function TaskActionGlyph(): ReactNode {
|
|
145
|
+
return createElement(
|
|
146
|
+
'svg',
|
|
147
|
+
{
|
|
148
|
+
viewBox: '0 0 16 16',
|
|
149
|
+
width: 15,
|
|
150
|
+
height: 15,
|
|
151
|
+
fill: 'none',
|
|
152
|
+
stroke: 'currentColor',
|
|
153
|
+
strokeWidth: '1.3',
|
|
154
|
+
strokeLinecap: 'round',
|
|
155
|
+
strokeLinejoin: 'round',
|
|
156
|
+
'aria-hidden': 'true',
|
|
157
|
+
},
|
|
158
|
+
createElement('rect', { x: 2, y: 2.5, width: 12, height: 11, rx: 1.5 }),
|
|
159
|
+
createElement('path', { d: 'M2 6.5h12M6.5 6.5v7' }),
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Register the "Turn into task card" icon action into `conversation.chat.user-actions`.
|
|
165
|
+
* When the shell does not declare that slot, nothing registers and nothing fails.
|
|
166
|
+
*/
|
|
167
|
+
export function registerUserMessageTaskAction(
|
|
168
|
+
ctx: ClientContext,
|
|
169
|
+
controller: Pick<BoardController, 'openNewTaskWithDraft'>,
|
|
170
|
+
resolveWorkspaceId?: WorkspaceIdResolver,
|
|
171
|
+
): () => void {
|
|
172
|
+
const slots = (ctx as unknown as { slots?: SlotsFace }).slots
|
|
173
|
+
if (typeof slots?.inject !== 'function' || typeof slots?.register !== 'function') {
|
|
174
|
+
return () => {}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function UserMessageTaskAction({ messageId, sessionId, useChat }: UserMessageTaskActionProps): ReactNode {
|
|
178
|
+
const selector = useCallback(
|
|
179
|
+
(snapshot: ChatSnapshotLike) => extractUserMessageText(snapshot, messageId),
|
|
180
|
+
[messageId],
|
|
181
|
+
)
|
|
182
|
+
const text = typeof useChat === 'function' ? useChat(selector) : ''
|
|
183
|
+
if (text === '') return null
|
|
184
|
+
const label = t('chat.turnIntoTask')
|
|
185
|
+
return createElement(
|
|
186
|
+
'button',
|
|
187
|
+
{
|
|
188
|
+
type: 'button',
|
|
189
|
+
className: css.chatUserAction,
|
|
190
|
+
'aria-label': label,
|
|
191
|
+
title: label,
|
|
192
|
+
'data-dsh-taskboard-action': 'turn-into-task',
|
|
193
|
+
onClick: () => {
|
|
194
|
+
const workspaceId = resolveSessionWorkspaceId(resolveWorkspaceId, sessionId)
|
|
195
|
+
controller.openNewTaskWithDraft(draftFromUserMessage(text, workspaceId))
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
createElement(TaskActionGlyph),
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return slots.inject(
|
|
203
|
+
'conversation.chat.user-actions',
|
|
204
|
+
() => slots.register({
|
|
205
|
+
name: 'conversation.chat.user-actions',
|
|
206
|
+
id: USER_ACTION_CREATE_TASK_ID,
|
|
207
|
+
order: 50,
|
|
208
|
+
label: () => t('chat.turnIntoTask'),
|
|
209
|
+
}, UserMessageTaskAction),
|
|
210
|
+
)
|
|
211
|
+
}
|