@linxin666/dsh-client-ui-task-board 0.4.22 → 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 +6 -6
- package/README.zh.md +6 -6
- package/lib/client.js +410 -37
- package/lib/client.js.map +1 -1
- package/lib/index.js +45 -27
- package/lib/types/client/TaskBoardSettingsCard.d.ts +1 -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 +3 -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/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/NewTaskModal.tsx +8 -6
- package/src/client/board/TaskBoard.tsx +59 -13
- 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 +6 -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/dsh-home.ts +35 -12
- package/src/host/agent-tools.ts +8 -0
- 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/tool-surface.ts +17 -2
|
@@ -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
|
+
}
|
package/src/core/controller.ts
CHANGED
|
@@ -162,6 +162,14 @@ export interface ExecutionOptionsSnapshot {
|
|
|
162
162
|
*/
|
|
163
163
|
export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'extensionsRevision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'cardDefaults' | 'extensions' | 'attachmentLimits'>
|
|
164
164
|
|
|
165
|
+
/** Optional prefilled draft handed to the board's create-task modal (e.g. from a chat message action). */
|
|
166
|
+
export interface ComposeTaskDraft {
|
|
167
|
+
readonly title?: string
|
|
168
|
+
readonly description?: string
|
|
169
|
+
readonly prompt?: string
|
|
170
|
+
readonly workspaceId?: string
|
|
171
|
+
}
|
|
172
|
+
|
|
165
173
|
/** Immutable controller snapshot for UI subscriptions. */
|
|
166
174
|
export interface ControllerSnapshot {
|
|
167
175
|
tasks: readonly TaskRecord[]
|
|
@@ -226,6 +234,7 @@ export class BoardController {
|
|
|
226
234
|
private boardOpen = false
|
|
227
235
|
private archiveView = false
|
|
228
236
|
private selectedTaskId: string | undefined
|
|
237
|
+
private pendingComposeDraft: ComposeTaskDraft | undefined
|
|
229
238
|
private executionOptions: ExecutionOptionsSnapshot = { workspaces: [], presets: [], models: [] }
|
|
230
239
|
private workspaceCreator: WorkspaceCreator | undefined
|
|
231
240
|
private listeners = new Set<() => void>()
|
|
@@ -388,6 +397,27 @@ export class BoardController {
|
|
|
388
397
|
this.selectPanel(TASK_BOARD_PANEL_ID)
|
|
389
398
|
}
|
|
390
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Queue a prefilled draft for the create-task modal and open the board panel.
|
|
402
|
+
* Stored outside {@link BoardSnapshot} so existing snapshot equality holds;
|
|
403
|
+
* the mounted {@link TaskBoard} consumes it once on mount or update.
|
|
404
|
+
*/
|
|
405
|
+
openNewTaskWithDraft(draft: ComposeTaskDraft): void {
|
|
406
|
+
this.pendingComposeDraft = draft
|
|
407
|
+
if (!this.boardOpen) {
|
|
408
|
+
this.openBoard()
|
|
409
|
+
return
|
|
410
|
+
}
|
|
411
|
+
this.notify()
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Read and clear any queued create-task draft. */
|
|
415
|
+
consumeComposeDraft(): ComposeTaskDraft | undefined {
|
|
416
|
+
const draft = this.pendingComposeDraft
|
|
417
|
+
this.pendingComposeDraft = undefined
|
|
418
|
+
return draft
|
|
419
|
+
}
|
|
420
|
+
|
|
391
421
|
/**
|
|
392
422
|
* Return the center column to the conversation. The layout's own selection is
|
|
393
423
|
* the source of truth for what the column renders, so this asks for the
|
|
@@ -59,7 +59,7 @@ export function parseModelRoute(qualified: string | undefined): { provider: stri
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Normalize the raw `
|
|
62
|
+
* Normalize the raw `models/catalog` reply into the shape the board
|
|
63
63
|
* reads. Everything is optional in the wire value, so every level is checked:
|
|
64
64
|
* an unreadable catalog degrades to "unknown", never to a crash.
|
|
65
65
|
* @param value - the raw gateway reply.
|
package/src/dsh-home.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Generated by scripts/sync-shared.mjs from shared/host/dsh-home.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
2
|
/**
|
|
3
|
-
* DSH_HOME resolution shared by the plugin family's Host
|
|
4
|
-
* environment
|
|
5
|
-
*
|
|
3
|
+
* DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
|
|
4
|
+
* halves: environment overrides win (blank values treated as unset), then the
|
|
5
|
+
* platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { homedir } from 'node:os'
|
|
@@ -18,6 +18,21 @@ export function expandHome(path: string, home: string = homedir()): string {
|
|
|
18
18
|
return path
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function resolveUserRoot(
|
|
22
|
+
envValue: string | undefined,
|
|
23
|
+
defaultDirName: string,
|
|
24
|
+
home: string,
|
|
25
|
+
): string {
|
|
26
|
+
const isPosix = home.startsWith('/')
|
|
27
|
+
const j = isPosix ? posixJoin : join
|
|
28
|
+
const isAbs = isPosix ? posixIsAbsolute : isAbsolute
|
|
29
|
+
if (envValue !== undefined && envValue.trim() !== '') {
|
|
30
|
+
const expanded = expandHome(envValue.trim(), home)
|
|
31
|
+
return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
|
|
32
|
+
}
|
|
33
|
+
return j(home, defaultDirName)
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
/**
|
|
22
37
|
* Resolve the DSH home directory.
|
|
23
38
|
* @param env - process environment to read DSH_HOME from.
|
|
@@ -25,18 +40,26 @@ export function expandHome(path: string, home: string = homedir()): string {
|
|
|
25
40
|
* @returns the absolute DSH home path.
|
|
26
41
|
*/
|
|
27
42
|
export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
28
|
-
|
|
29
|
-
const j = isPosix ? posixJoin : join
|
|
30
|
-
const isAbs = isPosix ? posixIsAbsolute : isAbsolute
|
|
31
|
-
const raw = env.DSH_HOME
|
|
32
|
-
if (raw !== undefined && raw.trim() !== '') {
|
|
33
|
-
const expanded = expandHome(raw.trim(), home)
|
|
34
|
-
return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
|
|
35
|
-
}
|
|
36
|
-
return j(home, '.dsh')
|
|
43
|
+
return resolveUserRoot(env.DSH_HOME, '.dsh', home)
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
/** Resolve the DSH home directory from the live environment. */
|
|
40
47
|
export function dshHome(): string {
|
|
41
48
|
return resolveDshHome()
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
|
|
53
|
+
* to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
|
|
54
|
+
* @param env - process environment to read DSH_AGENTS_HOME from.
|
|
55
|
+
* @param home - platform home directory fallback (test seam).
|
|
56
|
+
* @returns the absolute shared agents home path.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveAgentsHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
59
|
+
return resolveUserRoot(env.DSH_AGENTS_HOME, '.agents', home)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Resolve the shared agent configuration root from the live environment. */
|
|
63
|
+
export function agentsHome(): string {
|
|
64
|
+
return resolveAgentsHome()
|
|
65
|
+
}
|