@roaming-ai/dsh-group-chat 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/cordis.patch.yml +12 -0
- package/lib/client.js +3308 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +2583 -0
- package/lib/types/client/Bubble.d.ts +10 -0
- package/lib/types/client/Glyph.d.ts +12 -0
- package/lib/types/client/GroupChatPanel.d.ts +10 -0
- package/lib/types/client/GroupChatPanel.old.d.ts +10 -0
- package/lib/types/client/GroupChatSettingsSection.d.ts +15 -0
- package/lib/types/client/PermissionSelect.d.ts +13 -0
- package/lib/types/client/RoleDrawer.d.ts +17 -0
- package/lib/types/client/ThinkRow.d.ts +9 -0
- package/lib/types/client/ToolRow.d.ts +9 -0
- package/lib/types/client/api.d.ts +8 -0
- package/lib/types/client/components/AsidePanel.d.ts +31 -0
- package/lib/types/client/components/Bubble.d.ts +19 -0
- package/lib/types/client/components/ChatPanel.d.ts +57 -0
- package/lib/types/client/components/Composer.d.ts +48 -0
- package/lib/types/client/components/Glyph.d.ts +12 -0
- package/lib/types/client/components/GroupChatSettingsSection.d.ts +15 -0
- package/lib/types/client/components/MessageFlow.d.ts +15 -0
- package/lib/types/client/components/NavPanel.d.ts +40 -0
- package/lib/types/client/components/PermissionSelect.d.ts +13 -0
- package/lib/types/client/components/RoleDrawer.d.ts +17 -0
- package/lib/types/client/components/ThinkRow.d.ts +9 -0
- package/lib/types/client/components/ToolRow.d.ts +9 -0
- package/lib/types/client/components/index.d.ts +9 -0
- package/lib/types/client/components.d.ts +22 -0
- package/lib/types/client/drawer.d.ts +17 -0
- package/lib/types/client/glyph.d.ts +12 -0
- package/lib/types/client/hooks/index.d.ts +6 -0
- package/lib/types/client/hooks/useComposer.d.ts +27 -0
- package/lib/types/client/hooks/useFileSearch.d.ts +19 -0
- package/lib/types/client/hooks/useGroupChatState.d.ts +95 -0
- package/lib/types/client/hooks/useMentionState.d.ts +27 -0
- package/lib/types/client/index.d.ts +52 -0
- package/lib/types/client/lib/api.d.ts +8 -0
- package/lib/types/client/lib/model.d.ts +80 -0
- package/lib/types/client/lib/styles.d.ts +10 -0
- package/lib/types/client/lib/ui.d.ts +17 -0
- package/lib/types/client/model.d.ts +78 -0
- package/lib/types/client/panel.d.ts +10 -0
- package/lib/types/client/settings.d.ts +15 -0
- package/lib/types/client/styles.d.ts +10 -0
- package/lib/types/client/ui.d.ts +17 -0
- package/lib/types/client/utils/utils.d.ts +29 -0
- package/lib/types/client/utils.d.ts +22 -0
- package/lib/types/core/json.d.ts +9 -0
- package/lib/types/core/status.d.ts +18 -0
- package/lib/types/core/tools.d.ts +59 -0
- package/lib/types/core/types.d.ts +256 -0
- package/lib/types/host/actions.d.ts +34 -0
- package/lib/types/host/api/actions.d.ts +36 -0
- package/lib/types/host/api/http.d.ts +16 -0
- package/lib/types/host/api/index.d.ts +7 -0
- package/lib/types/host/api/routes.d.ts +11 -0
- package/lib/types/host/broadcast.d.ts +20 -0
- package/lib/types/host/conversation.d.ts +25 -0
- package/lib/types/host/engine/conversation.d.ts +25 -0
- package/lib/types/host/engine/index.d.ts +7 -0
- package/lib/types/host/engine/retitle.d.ts +20 -0
- package/lib/types/host/http.d.ts +16 -0
- package/lib/types/host/index.d.ts +8 -0
- package/lib/types/host/materials/index.d.ts +6 -0
- package/lib/types/host/materials/materials.d.ts +40 -0
- package/lib/types/host/materials.d.ts +32 -0
- package/lib/types/host/persistence/index.d.ts +6 -0
- package/lib/types/host/persistence/persistence.d.ts +31 -0
- package/lib/types/host/persistence/store.d.ts +65 -0
- package/lib/types/host/persistence.d.ts +31 -0
- package/lib/types/host/routes.d.ts +11 -0
- package/lib/types/host/service.d.ts +28 -0
- package/lib/types/host/state.d.ts +45 -0
- package/lib/types/host/store.d.ts +65 -0
- package/lib/types/host/tools/index.d.ts +6 -0
- package/lib/types/host/tools/tools.d.ts +28 -0
- package/lib/types/host/tools.d.ts +28 -0
- package/lib/types/index.d.ts +41 -0
- package/lib/types/mount-once.d.ts +9 -0
- package/lib/types/shared/file-mention-grammar.d.ts +37 -0
- package/lib/types/shared/file-mention-grammar.test.d.ts +5 -0
- package/package.json +98 -0
- package/src/client/GroupChatPanel.tsx +385 -0
- package/src/client/components/AsidePanel.tsx +188 -0
- package/src/client/components/Bubble.tsx +76 -0
- package/src/client/components/ChatPanel.tsx +214 -0
- package/src/client/components/Composer.tsx +238 -0
- package/src/client/components/Glyph.tsx +27 -0
- package/src/client/components/GroupChatSettingsSection.tsx +74 -0
- package/src/client/components/MessageFlow.tsx +97 -0
- package/src/client/components/NavPanel.tsx +249 -0
- package/src/client/components/PermissionSelect.tsx +159 -0
- package/src/client/components/RoleDrawer.tsx +186 -0
- package/src/client/components/ThinkRow.tsx +32 -0
- package/src/client/components/ToolRow.tsx +51 -0
- package/src/client/components/index.ts +10 -0
- package/src/client/hooks/index.ts +7 -0
- package/src/client/hooks/useComposer.ts +272 -0
- package/src/client/hooks/useFileSearch.ts +115 -0
- package/src/client/hooks/useGroupChatState.ts +214 -0
- package/src/client/hooks/useMentionState.ts +56 -0
- package/src/client/index.ts +110 -0
- package/src/client/lib/api.ts +23 -0
- package/src/client/lib/model.ts +119 -0
- package/src/client/lib/styles.ts +317 -0
- package/src/client/lib/ui.ts +27 -0
- package/src/client/react-dom-shim.d.ts +13 -0
- package/src/client/utils/utils.ts +104 -0
- package/src/core/json.ts +28 -0
- package/src/core/status.ts +33 -0
- package/src/core/tools.ts +41 -0
- package/src/core/types.ts +222 -0
- package/src/host/api/actions.ts +335 -0
- package/src/host/api/http.ts +80 -0
- package/src/host/api/index.ts +8 -0
- package/src/host/api/routes.ts +95 -0
- package/src/host/broadcast.ts +65 -0
- package/src/host/engine/conversation.ts +331 -0
- package/src/host/engine/index.ts +8 -0
- package/src/host/engine/retitle.ts +135 -0
- package/src/host/index.ts +9 -0
- package/src/host/materials/index.ts +7 -0
- package/src/host/materials/materials.ts +193 -0
- package/src/host/persistence/index.ts +7 -0
- package/src/host/persistence/persistence.ts +311 -0
- package/src/host/persistence/store.ts +375 -0
- package/src/host/service.ts +78 -0
- package/src/host/state.ts +85 -0
- package/src/host/tools/index.ts +7 -0
- package/src/host/tools/tools.ts +194 -0
- package/src/index.ts +99 -0
- package/src/mount-once.ts +49 -0
- package/src/shared/file-mention-grammar.test.ts +77 -0
- package/src/shared/file-mention-grammar.ts +82 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 群聊数据模型(core 层,无 cordis 依赖)。
|
|
3
|
+
* 数据模型:Group 1..N Session,消息挂在会话上;角色与工作区目录挂在群组上。
|
|
4
|
+
* @module dsh-group-chat/core/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 群组权限档位(对齐主会话 /permission 三档):
|
|
8
|
+
* - view_only 仅可查看:只保留 read_file/list_dir,run_command 从 schema 剔除
|
|
9
|
+
* - workspace_write 工作区内修改:run_command 可用,每条命令逐条确认
|
|
10
|
+
* - full_access 完全权限:run_command 免确认直接执行
|
|
11
|
+
*/
|
|
12
|
+
export type PermissionTier = 'view_only' | 'workspace_write' | 'full_access';
|
|
13
|
+
/** 全部合法档位(展示顺序)。 */
|
|
14
|
+
export declare const PERMISSION_TIERS: readonly PermissionTier[];
|
|
15
|
+
/** 档位安全化:合法字符串原样,其余 undefined。 */
|
|
16
|
+
export declare function asPermissionTier(value: unknown): PermissionTier | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* ledger 行档位归一(v2→v3 兼容):显式 permissionTier 优先;
|
|
19
|
+
* 缺失时按旧布尔迁移——allowCommands=true → workspace_write(今日语义即
|
|
20
|
+
* 「可执行命令但逐条确认」),false/无字段 → view_only。
|
|
21
|
+
*/
|
|
22
|
+
export declare function migrateTier(permissionTier: unknown, allowCommands: unknown): PermissionTier;
|
|
23
|
+
/** 群组:角色与工作区目录的宿主。 */
|
|
24
|
+
export interface GroupRecord {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
workspaceDir: string;
|
|
28
|
+
permissionTier: PermissionTier;
|
|
29
|
+
roleIds: string[];
|
|
30
|
+
sessionIds: string[];
|
|
31
|
+
}
|
|
32
|
+
/** 会话:消息挂在会话上。 */
|
|
33
|
+
export interface SessionRecord {
|
|
34
|
+
id: string;
|
|
35
|
+
groupId: string;
|
|
36
|
+
name: string;
|
|
37
|
+
topic: string;
|
|
38
|
+
/** 名称已被手动编辑:自动命名永久跳过(隐式固定)。 */
|
|
39
|
+
namePinned?: boolean;
|
|
40
|
+
/** 主题已被手动编辑:自动整理永久跳过(隐式固定)。 */
|
|
41
|
+
topicPinned?: boolean;
|
|
42
|
+
messageIds: string[];
|
|
43
|
+
createdAt: number;
|
|
44
|
+
}
|
|
45
|
+
/** 角色:绑定 provider/model 的群成员身份。 */
|
|
46
|
+
export interface RoleRecord {
|
|
47
|
+
id: string;
|
|
48
|
+
groupId: string;
|
|
49
|
+
name: string;
|
|
50
|
+
color?: string;
|
|
51
|
+
persona: string;
|
|
52
|
+
provider: string;
|
|
53
|
+
model: string;
|
|
54
|
+
temperature?: number;
|
|
55
|
+
reasoningEffort?: string;
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
thinking: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** 一次工具调用的落盘/快照形态(TOOLS.md §3.3 回注契约的展示面)。 */
|
|
60
|
+
export interface ToolCallRecord {
|
|
61
|
+
tool: string;
|
|
62
|
+
args: unknown;
|
|
63
|
+
status: string;
|
|
64
|
+
output: string;
|
|
65
|
+
durationMs?: number;
|
|
66
|
+
}
|
|
67
|
+
/** 消息(user / system / 角色发言共用一条记录)。 */
|
|
68
|
+
export interface MessageRecord {
|
|
69
|
+
id: string;
|
|
70
|
+
sessionId: string;
|
|
71
|
+
seq: number;
|
|
72
|
+
speaker: string;
|
|
73
|
+
text: string;
|
|
74
|
+
reasoning?: string;
|
|
75
|
+
reasoningFull?: string;
|
|
76
|
+
thinkingSummary?: string;
|
|
77
|
+
model?: string;
|
|
78
|
+
error?: boolean;
|
|
79
|
+
toolCalls?: ToolCallRecord[];
|
|
80
|
+
ts: number;
|
|
81
|
+
}
|
|
82
|
+
/** run_command 确认闸门的待确认载荷。 */
|
|
83
|
+
export interface PendingConfirm {
|
|
84
|
+
toolCallId: string;
|
|
85
|
+
tool: string;
|
|
86
|
+
args: {
|
|
87
|
+
command?: string;
|
|
88
|
+
} & Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
/** 最近一次创建的群组/会话,供客户端定位选中项。 */
|
|
91
|
+
export interface LastCreated {
|
|
92
|
+
kind: 'group' | 'session';
|
|
93
|
+
groupId: string;
|
|
94
|
+
sessionId: string;
|
|
95
|
+
}
|
|
96
|
+
/** run 结束后的「输出完毕」标记(内存态不持久化,重启即清;reason 取 ok/error)。 */
|
|
97
|
+
export interface RunFinished {
|
|
98
|
+
sessionId: string;
|
|
99
|
+
reason: 'ok' | 'error';
|
|
100
|
+
}
|
|
101
|
+
/** 对话进行时状态(run)。 */
|
|
102
|
+
export interface RunState {
|
|
103
|
+
running: boolean;
|
|
104
|
+
sessionId: string | null;
|
|
105
|
+
currentRoleId: string | null;
|
|
106
|
+
partial: string;
|
|
107
|
+
partialReasoning: string;
|
|
108
|
+
stopping: boolean;
|
|
109
|
+
queue: string[];
|
|
110
|
+
pendingConfirm: PendingConfirm | null;
|
|
111
|
+
confirmSignal: {
|
|
112
|
+
resolve: (allowed: boolean) => void;
|
|
113
|
+
} | null;
|
|
114
|
+
childProc: import('node:child_process').ChildProcess | null;
|
|
115
|
+
/** 最近一次 run 的结束标记:会话列表「已完成/已出错」状态的数据源。 */
|
|
116
|
+
finished: RunFinished | null;
|
|
117
|
+
}
|
|
118
|
+
/** 角色发言的引擎产物。 */
|
|
119
|
+
export interface SpeakResult {
|
|
120
|
+
text: string;
|
|
121
|
+
reasoning: string | undefined;
|
|
122
|
+
toolCalls: ToolCallRecord[];
|
|
123
|
+
}
|
|
124
|
+
/** 工具执行结果(host 内部约定)。 */
|
|
125
|
+
export interface ToolExecution {
|
|
126
|
+
status: 'ok' | 'error' | 'denied';
|
|
127
|
+
output: string;
|
|
128
|
+
args: Record<string, unknown>;
|
|
129
|
+
durationMs: number;
|
|
130
|
+
}
|
|
131
|
+
/** 模型目录(models action 的缓存载荷)。 */
|
|
132
|
+
export interface ModelCatalog {
|
|
133
|
+
at: number;
|
|
134
|
+
providers: {
|
|
135
|
+
id: string;
|
|
136
|
+
name: string;
|
|
137
|
+
}[];
|
|
138
|
+
modelsByProvider: Record<string, {
|
|
139
|
+
id: string;
|
|
140
|
+
name?: string;
|
|
141
|
+
}[]>;
|
|
142
|
+
}
|
|
143
|
+
/** 推理级别选项(efforts action 的载荷)。 */
|
|
144
|
+
export interface EffortOptions {
|
|
145
|
+
efforts: {
|
|
146
|
+
id: string;
|
|
147
|
+
name: string;
|
|
148
|
+
description?: string;
|
|
149
|
+
}[];
|
|
150
|
+
defaultEffort: string | undefined;
|
|
151
|
+
error?: string;
|
|
152
|
+
}
|
|
153
|
+
/** 目录浏览结果(browse action 的载荷)。 */
|
|
154
|
+
export interface BrowseResult {
|
|
155
|
+
ok: boolean;
|
|
156
|
+
path?: string;
|
|
157
|
+
home?: string;
|
|
158
|
+
parent?: string;
|
|
159
|
+
entries?: {
|
|
160
|
+
name: string;
|
|
161
|
+
type: string;
|
|
162
|
+
path: string;
|
|
163
|
+
size?: number;
|
|
164
|
+
hidden: boolean;
|
|
165
|
+
}[];
|
|
166
|
+
error?: string;
|
|
167
|
+
}
|
|
168
|
+
/** 群工作区 @ 文件检索结果(fileSearch action 的载荷)。 */
|
|
169
|
+
export interface FileSearchResult {
|
|
170
|
+
ok: boolean;
|
|
171
|
+
candidates?: {
|
|
172
|
+
path: string;
|
|
173
|
+
isDir: boolean;
|
|
174
|
+
}[];
|
|
175
|
+
error?: string;
|
|
176
|
+
}
|
|
177
|
+
/** 发到客户端的全量快照(wire 形态)。 */
|
|
178
|
+
export interface Snapshot {
|
|
179
|
+
revision: number;
|
|
180
|
+
run: {
|
|
181
|
+
running: boolean;
|
|
182
|
+
sessionId: string | null;
|
|
183
|
+
currentRoleId: string | null;
|
|
184
|
+
partial: string;
|
|
185
|
+
partialReasoning: string;
|
|
186
|
+
pendingConfirm: PendingConfirm | null;
|
|
187
|
+
finished: RunFinished | null;
|
|
188
|
+
};
|
|
189
|
+
lastCreated: LastCreated | null;
|
|
190
|
+
groups: {
|
|
191
|
+
id: string;
|
|
192
|
+
name: string;
|
|
193
|
+
workspaceDir: string;
|
|
194
|
+
permissionTier: PermissionTier;
|
|
195
|
+
roleIds: string[];
|
|
196
|
+
sessionIds: string[];
|
|
197
|
+
}[];
|
|
198
|
+
sessions: {
|
|
199
|
+
id: string;
|
|
200
|
+
groupId: string;
|
|
201
|
+
name: string;
|
|
202
|
+
topic: string;
|
|
203
|
+
messageIds: string[];
|
|
204
|
+
createdAt: number;
|
|
205
|
+
}[];
|
|
206
|
+
roles: {
|
|
207
|
+
id: string;
|
|
208
|
+
groupId: string;
|
|
209
|
+
name: string;
|
|
210
|
+
color?: string;
|
|
211
|
+
persona: string;
|
|
212
|
+
provider: string;
|
|
213
|
+
model: string;
|
|
214
|
+
temperature?: number;
|
|
215
|
+
reasoningEffort?: string;
|
|
216
|
+
enabled: boolean;
|
|
217
|
+
thinking: boolean;
|
|
218
|
+
}[];
|
|
219
|
+
messages: {
|
|
220
|
+
id: string;
|
|
221
|
+
sessionId: string;
|
|
222
|
+
seq: number;
|
|
223
|
+
speaker: string;
|
|
224
|
+
text: string;
|
|
225
|
+
reasoning?: string;
|
|
226
|
+
model?: string;
|
|
227
|
+
error?: boolean;
|
|
228
|
+
toolCalls?: ToolCallRecord[];
|
|
229
|
+
ts: number;
|
|
230
|
+
}[];
|
|
231
|
+
error?: string;
|
|
232
|
+
}
|
|
233
|
+
/** mutate 动作的参数形态(op 分发见 host/service)。 */
|
|
234
|
+
export interface MutateArgs {
|
|
235
|
+
op: string;
|
|
236
|
+
groupId?: string;
|
|
237
|
+
sessionId?: string;
|
|
238
|
+
roleId?: string;
|
|
239
|
+
role?: Partial<RoleRecord>;
|
|
240
|
+
name?: string;
|
|
241
|
+
topic?: string;
|
|
242
|
+
path?: string;
|
|
243
|
+
tier?: string;
|
|
244
|
+
enabled?: boolean;
|
|
245
|
+
}
|
|
246
|
+
/** send 动作的参数形态。 */
|
|
247
|
+
export interface SendArgs {
|
|
248
|
+
sessionId: string;
|
|
249
|
+
text?: string;
|
|
250
|
+
participantRoleIds?: string[];
|
|
251
|
+
rounds?: number;
|
|
252
|
+
}
|
|
253
|
+
/** 可选数值参数安全化:数字则原样,否则 undefined。 */
|
|
254
|
+
export declare function asNumber(value: unknown): number | undefined;
|
|
255
|
+
/** 可选字符串参数安全化:非 default 的非空字符串则原样,否则 undefined。 */
|
|
256
|
+
export declare function asEffort(value: unknown): string | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动作分发(handleAction,POST /api/group-chat/action 的载荷):
|
|
3
|
+
* mutate(12 种 CRUD/配置操作)| send | stop | confirmCommand | models | efforts。
|
|
4
|
+
* @module dsh-group-chat/host/actions
|
|
5
|
+
*/
|
|
6
|
+
import type { BrowseResult, Snapshot } from '../core/types.ts';
|
|
7
|
+
import type { HostState } from './state.ts';
|
|
8
|
+
/** 动作面。 */
|
|
9
|
+
export interface Actions {
|
|
10
|
+
handleAction: (body: Record<string, unknown>) => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** 创建动作分发面。 */
|
|
13
|
+
export declare function createActions(core: HostState, deps: {
|
|
14
|
+
touch: () => void;
|
|
15
|
+
snapshot: () => Snapshot;
|
|
16
|
+
schedulePersist: (targets?: {
|
|
17
|
+
ledger?: boolean;
|
|
18
|
+
session?: string | null;
|
|
19
|
+
roles?: string | null;
|
|
20
|
+
workspace?: string | null;
|
|
21
|
+
}) => void;
|
|
22
|
+
dropDirty: (targets: {
|
|
23
|
+
session?: string | null;
|
|
24
|
+
roles?: string | null;
|
|
25
|
+
workspace?: string | null;
|
|
26
|
+
}) => void;
|
|
27
|
+
appendMessage: import('./conversation.ts').Conversation['appendMessage'];
|
|
28
|
+
runLoop: import('./conversation.ts').Conversation['runLoop'];
|
|
29
|
+
wakeConfirm: () => void;
|
|
30
|
+
killChild: () => void;
|
|
31
|
+
browse: (args: {
|
|
32
|
+
path?: string;
|
|
33
|
+
} | undefined) => Promise<BrowseResult>;
|
|
34
|
+
}): Actions;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动作分发(handleAction,POST /api/group-chat/action 的载荷):
|
|
3
|
+
* mutate(12 种 CRUD/配置操作)| send | stop | confirmCommand | models | efforts。
|
|
4
|
+
* @module dsh-group-chat/host/api/actions
|
|
5
|
+
*/
|
|
6
|
+
import type { Snapshot } from '../../core/types.ts';
|
|
7
|
+
import type { HostState } from '../state.ts';
|
|
8
|
+
import type { Conversation } from '../engine/index.ts';
|
|
9
|
+
import type { Materials } from '../materials/index.ts';
|
|
10
|
+
/** 动作面。 */
|
|
11
|
+
export interface Actions {
|
|
12
|
+
handleAction: (body: Record<string, unknown>) => Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
/** 创建动作分发面。 */
|
|
15
|
+
export declare function createActions(core: HostState, deps: {
|
|
16
|
+
touch: () => void;
|
|
17
|
+
snapshot: () => Snapshot;
|
|
18
|
+
schedulePersist: (targets?: {
|
|
19
|
+
ledger?: boolean;
|
|
20
|
+
session?: string | null;
|
|
21
|
+
roles?: string | null;
|
|
22
|
+
workspace?: string | null;
|
|
23
|
+
}) => void;
|
|
24
|
+
dropDirty: (targets: {
|
|
25
|
+
session?: string | null;
|
|
26
|
+
roles?: string | null;
|
|
27
|
+
workspace?: string | null;
|
|
28
|
+
}) => void;
|
|
29
|
+
appendMessage: Conversation['appendMessage'];
|
|
30
|
+
runLoop: Conversation['runLoop'];
|
|
31
|
+
wakeConfirm: () => void;
|
|
32
|
+
killChild: () => void;
|
|
33
|
+
browse: Materials['browse'];
|
|
34
|
+
fileSearch: Materials['fileSearch'];
|
|
35
|
+
disposeFileSearch: Materials['disposeFileSearch'];
|
|
36
|
+
}): Actions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host HTTP 工具:回环信任栏(对齐 dsh-web shared/host/loopback.ts 语义 +
|
|
3
|
+
* 浏览器同源标记栏)、有界 JSON 请求体读取、JSON 响应写出。
|
|
4
|
+
* @module dsh-group-chat/host/api/http
|
|
5
|
+
*/
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
7
|
+
/**
|
|
8
|
+
* 请求级信任栏:浏览器同源标记(sec-fetch-site / Origin)必须存在且回环
|
|
9
|
+
* socket + 回环 Host 全过;X-Forwarded-For 一律不信任。无任何同源标记的
|
|
10
|
+
* 非浏览器请求(如裸 curl)一律拒绝。
|
|
11
|
+
*/
|
|
12
|
+
export declare function isTrustedRequest(req: IncomingMessage): boolean;
|
|
13
|
+
/** 读有界 JSON 请求体;超限抛 'body-too-large'(路由映射 413)。 */
|
|
14
|
+
export declare function readBody(req: IncomingMessage): Promise<unknown>;
|
|
15
|
+
/** 写 JSON 响应;调用方可追加/覆盖默认头。 */
|
|
16
|
+
export declare function writeJson(res: ServerResponse, status: number, body: unknown, headers?: Record<string, string | number>): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 路由(经 webServer 暴露):
|
|
3
|
+
* GET /api/group-chat/state 全量快照
|
|
4
|
+
* POST /api/group-chat/action { kind: mutate|send|stop|confirmCommand|models|efforts|browse|fileSearch, ... }
|
|
5
|
+
* GET /api/group-chat/events SSE,状态变化时推送节流后的全量快照
|
|
6
|
+
* @module dsh-group-chat/host/api/routes
|
|
7
|
+
*/
|
|
8
|
+
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver';
|
|
9
|
+
import type { GroupChatService } from '../service.ts';
|
|
10
|
+
/** 构建群聊的三条 HTTP 路由。 */
|
|
11
|
+
export declare function makeGroupChatRoutes(service: GroupChatService): WebRoute[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE 广播(节流)+ touch + 全量快照:变更经 touch()(revision++ + 节流广播)
|
|
3
|
+
* 通知 /api/group-chat/events 订阅者;快照读容器当前状态。
|
|
4
|
+
* @module dsh-group-chat/host/broadcast
|
|
5
|
+
*/
|
|
6
|
+
import type { HostState } from './state.ts';
|
|
7
|
+
import type { Snapshot } from '../core/types.ts';
|
|
8
|
+
/** 广播面。 */
|
|
9
|
+
export interface Broadcast {
|
|
10
|
+
/** revision++ 并节流广播。 */
|
|
11
|
+
touch: () => void;
|
|
12
|
+
/** 全量快照(客户端唯一读取面)。 */
|
|
13
|
+
snapshot: () => Snapshot;
|
|
14
|
+
/** 订阅推送;返回退订函数。 */
|
|
15
|
+
subscribePush: (push: () => void) => () => void;
|
|
16
|
+
/** dispose:清掉挂起的节流定时器。 */
|
|
17
|
+
dispose: () => void;
|
|
18
|
+
}
|
|
19
|
+
/** 创建广播面。 */
|
|
20
|
+
export declare function createBroadcast(core: HostState): Broadcast;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对话引擎:消息追加、群聊记录转写、角色发言(speak:prompt 构建 + 流式
|
|
3
|
+
* 轮次 + 工具回注循环)、多轮 runLoop,以及会话标题/主题自动整理(retitle)。
|
|
4
|
+
* @module dsh-group-chat/host/conversation
|
|
5
|
+
*/
|
|
6
|
+
import type { MessageRecord, SessionRecord } from '../core/types.ts';
|
|
7
|
+
import type { HostState } from './state.ts';
|
|
8
|
+
import type { Materials } from './materials.ts';
|
|
9
|
+
import type { Tools } from './tools.ts';
|
|
10
|
+
/** 对话引擎面。 */
|
|
11
|
+
export interface Conversation {
|
|
12
|
+
/** 追加一条消息到会话(touch + 落盘调度)。 */
|
|
13
|
+
appendMessage: (sess: SessionRecord, speaker: string, text: string, extra?: Partial<MessageRecord>) => MessageRecord;
|
|
14
|
+
/** 多轮 round-robin 主循环(send 触发;finally 复位 run)。 */
|
|
15
|
+
runLoop: (sess: SessionRecord) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** 创建对话引擎。 */
|
|
18
|
+
export declare function createConversation(core: HostState, deps: {
|
|
19
|
+
touch: () => void;
|
|
20
|
+
schedulePersist: (targets?: {
|
|
21
|
+
session?: string | null;
|
|
22
|
+
}) => void;
|
|
23
|
+
materials: Materials;
|
|
24
|
+
tools: Tools;
|
|
25
|
+
}): Conversation;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对话引擎:消息追加、群聊记录转写、角色发言(speak:prompt 构建 + 流式
|
|
3
|
+
* 轮次 + 工具回注循环)、多轮 runLoop(每轮结束触发 retitle 标题整理)。
|
|
4
|
+
* @module dsh-group-chat/host/engine/conversation
|
|
5
|
+
*/
|
|
6
|
+
import type { MessageRecord, SessionRecord } from '../../core/types.ts';
|
|
7
|
+
import type { HostState } from '../state.ts';
|
|
8
|
+
import type { Materials } from '../materials/index.ts';
|
|
9
|
+
import type { Tools } from '../tools/index.ts';
|
|
10
|
+
/** 对话引擎面。 */
|
|
11
|
+
export interface Conversation {
|
|
12
|
+
/** 追加一条消息到会话(touch + 落盘调度)。 */
|
|
13
|
+
appendMessage: (sess: SessionRecord, speaker: string, text: string, extra?: Partial<MessageRecord>) => MessageRecord;
|
|
14
|
+
/** 多轮 round-robin 主循环(send 触发;finally 复位 run)。 */
|
|
15
|
+
runLoop: (sess: SessionRecord) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** 创建对话引擎。 */
|
|
18
|
+
export declare function createConversation(core: HostState, deps: {
|
|
19
|
+
touch: () => void;
|
|
20
|
+
schedulePersist: (targets?: {
|
|
21
|
+
session?: string | null;
|
|
22
|
+
}) => void;
|
|
23
|
+
materials: Materials;
|
|
24
|
+
tools: Tools;
|
|
25
|
+
}): Conversation;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话标题/主题自动整理(参照 oil-codex-title):每轮结束后用 DSH 默认模型
|
|
3
|
+
* 后台生成「类别 emoji + 对象|目标」名称与演进式主题;手动编辑过的字段
|
|
4
|
+
* 永久跳过(隐式固定)。
|
|
5
|
+
* @module dsh-group-chat/host/engine/retitle
|
|
6
|
+
*/
|
|
7
|
+
import type { SessionRecord } from '../../core/types.ts';
|
|
8
|
+
import type { HostState } from '../state.ts';
|
|
9
|
+
/**
|
|
10
|
+
* 每轮结束后根据聊天内容整理会话名称与主题:后台 fire-and-forget、不产生
|
|
11
|
+
* 消息、静默失败。名称 =「类别 emoji + 对象|目标」(类别固定、对象稳定、
|
|
12
|
+
* 目标实质变化才改);主题 = 演进式一句话摘要(对象+目标+当前焦点),注入
|
|
13
|
+
* 后续轮次的角色上下文。手动编辑过的字段永久跳过(隐式固定,apply 时复查)。
|
|
14
|
+
*/
|
|
15
|
+
export declare function createRetitle(core: HostState, deps: {
|
|
16
|
+
touch: () => void;
|
|
17
|
+
schedulePersist: (targets?: {
|
|
18
|
+
session?: string | null;
|
|
19
|
+
}) => void;
|
|
20
|
+
}): (sess: SessionRecord) => Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host HTTP 工具:回环信任栏(对齐 dsh-web shared/host/loopback.ts 语义 +
|
|
3
|
+
* 浏览器同源标记栏)、有界 JSON 请求体读取、JSON 响应写出。
|
|
4
|
+
* @module dsh-group-chat/host/http
|
|
5
|
+
*/
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
7
|
+
/**
|
|
8
|
+
* 请求级信任栏:浏览器同源标记(sec-fetch-site / Origin)必须存在且回环
|
|
9
|
+
* socket + 回环 Host 全过;X-Forwarded-For 一律不信任。无任何同源标记的
|
|
10
|
+
* 非浏览器请求(如裸 curl)一律拒绝。
|
|
11
|
+
*/
|
|
12
|
+
export declare function isTrustedRequest(req: IncomingMessage): boolean;
|
|
13
|
+
/** 读有界 JSON 请求体;超限抛 'body-too-large'(路由映射 413)。 */
|
|
14
|
+
export declare function readBody(req: IncomingMessage): Promise<unknown>;
|
|
15
|
+
/** 写 JSON 响应;调用方可追加/覆盖默认头。 */
|
|
16
|
+
export declare function writeJson(res: ServerResponse, status: number, body: unknown, headers?: Record<string, string | number>): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 群聊宿主半对外门面(对齐浏览器半 src/client/index.ts 的入口角色):
|
|
3
|
+
* 插件入口(src/index.ts)只从这里取宿主面的装配件。
|
|
4
|
+
* @module dsh-group-chat/host
|
|
5
|
+
*/
|
|
6
|
+
export { createGroupChatService } from './service.ts';
|
|
7
|
+
export type { GroupChatService } from './service.ts';
|
|
8
|
+
export { makeGroupChatRoutes } from './api/routes.ts';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资料读取与路径解析:群组工作区目录 → 注入文件清单 + 目录浏览器 + @ 文件检索。
|
|
3
|
+
* 路径解析顺序:~ 展开到 home;绝对路径直用;相对路径先试各工作区根,
|
|
4
|
+
* 再试 dsh web 进程 cwd。目录浏览器、资料读取与文件检索共用同一套解析。
|
|
5
|
+
* 无独立笔记/文件清单:共享资料 = workspaceDir 根下一层文本文件。
|
|
6
|
+
* @module dsh-group-chat/host/materials
|
|
7
|
+
*/
|
|
8
|
+
import type { BrowseResult, FileSearchResult, GroupRecord } from '../../core/types.ts';
|
|
9
|
+
import type { HostState } from '../state.ts';
|
|
10
|
+
/** 资料面。 */
|
|
11
|
+
export interface Materials {
|
|
12
|
+
/** 群组工作区目录 → 注入文件清单(dir 为解析后的展示路径)。 */
|
|
13
|
+
loadWorkspaceFiles: (g: GroupRecord) => Promise<{
|
|
14
|
+
dir: string;
|
|
15
|
+
parts: {
|
|
16
|
+
name: string;
|
|
17
|
+
content: string;
|
|
18
|
+
error?: string;
|
|
19
|
+
}[];
|
|
20
|
+
}>;
|
|
21
|
+
/** 文件清单 → system 提示词内的「共享资料」块(单文件 16k / 总量 48k 截断)。 */
|
|
22
|
+
materialBlock: (parts: {
|
|
23
|
+
name: string;
|
|
24
|
+
content: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
}[], dir: string) => string;
|
|
27
|
+
/** 目录浏览:返回文件+目录条目(绝对路径由 Host 解析,客户端不拼路径)。 */
|
|
28
|
+
browse: (args: {
|
|
29
|
+
path?: string;
|
|
30
|
+
} | undefined) => Promise<BrowseResult>;
|
|
31
|
+
/** 群工作区 @ 文件检索(WorkspaceFileSearch,根 = 解析后的 workspaceDir)。 */
|
|
32
|
+
fileSearch: (args: {
|
|
33
|
+
groupId?: string;
|
|
34
|
+
query?: string;
|
|
35
|
+
} | undefined) => Promise<FileSearchResult>;
|
|
36
|
+
/** 释放某群(或全部)文件检索索引。 */
|
|
37
|
+
disposeFileSearch: (groupId?: string) => void;
|
|
38
|
+
}
|
|
39
|
+
/** 创建资料面。 */
|
|
40
|
+
export declare function createMaterials(core: HostState): Materials;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资料读取与路径解析:群组工作区目录 → 注入文件清单 + 目录浏览器。
|
|
3
|
+
* 路径解析顺序:~ 展开到 home;绝对路径直用;相对路径先试各工作区根,
|
|
4
|
+
* 再试 dsh web 进程 cwd。目录浏览器与资料读取共用同一套解析。
|
|
5
|
+
* @module dsh-group-chat/host/materials
|
|
6
|
+
*/
|
|
7
|
+
import type { BrowseResult, GroupRecord } from '../core/types.ts';
|
|
8
|
+
import type { HostState } from './state.ts';
|
|
9
|
+
/** 资料面。 */
|
|
10
|
+
export interface Materials {
|
|
11
|
+
/** 群组工作区目录 → 注入文件清单(dir 为解析后的展示路径)。 */
|
|
12
|
+
loadWorkspaceFiles: (g: GroupRecord) => Promise<{
|
|
13
|
+
dir: string;
|
|
14
|
+
parts: {
|
|
15
|
+
name: string;
|
|
16
|
+
content: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
}[];
|
|
19
|
+
}>;
|
|
20
|
+
/** 文件清单 → system 提示词内的「共享资料」块(单文件 16k / 总量 48k 截断)。 */
|
|
21
|
+
materialBlock: (parts: {
|
|
22
|
+
name: string;
|
|
23
|
+
content: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}[], dir: string) => string;
|
|
26
|
+
/** 目录浏览:返回文件+目录条目(绝对路径由 Host 解析,客户端不拼路径)。 */
|
|
27
|
+
browse: (args: {
|
|
28
|
+
path?: string;
|
|
29
|
+
} | undefined) => Promise<BrowseResult>;
|
|
30
|
+
}
|
|
31
|
+
/** 创建资料面。 */
|
|
32
|
+
export declare function createMaterials(core: HostState): Materials;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 持久化(PERSISTENCE.md v2.1):事件驱动脏标记合并落盘 + 启动恢复。
|
|
3
|
+
* 锁失败/写失败时降级为内存态运行(console 告警)。
|
|
4
|
+
* @module dsh-group-chat/host/persistence
|
|
5
|
+
*/
|
|
6
|
+
import type { HostState } from '../state.ts';
|
|
7
|
+
/** 持久化面。 */
|
|
8
|
+
export interface Persistence {
|
|
9
|
+
/** 事件驱动落盘;同一 tick 内多次变更合并为一次写。 */
|
|
10
|
+
schedulePersist: (targets?: {
|
|
11
|
+
ledger?: boolean;
|
|
12
|
+
session?: string | null;
|
|
13
|
+
roles?: string | null;
|
|
14
|
+
workspace?: string | null;
|
|
15
|
+
}) => void;
|
|
16
|
+
/** 同步 flush:写全部脏文件(dispose 最终落盘用)。 */
|
|
17
|
+
flushNow: () => void;
|
|
18
|
+
/** 删除群组/会话后摘除脏标记(对应文件已删/将删,flush 跳过)。 */
|
|
19
|
+
dropDirty: (targets: {
|
|
20
|
+
session?: string | null;
|
|
21
|
+
roles?: string | null;
|
|
22
|
+
workspace?: string | null;
|
|
23
|
+
}) => void;
|
|
24
|
+
/** dispose:同步最终 flush → 释放锁 → 摘除句柄。 */
|
|
25
|
+
release: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 创建持久化面:构造即完成 store 初始化 + hydrate(v1 迁移 → 残留清理 →
|
|
29
|
+
* 清单 → 群组数据 → 会话文件;缺文件空重建;补建默认会话/群组立即落盘)。
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPersistence(core: HostState): Persistence;
|