@huyooo/ai-chat-types 0.2.44 → 0.3.2
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/dist/chat-utils.d.ts +28 -0
- package/dist/chat-utils.d.ts.map +1 -0
- package/dist/index.d.ts +392 -66
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +8 -5
- package/src/chat-utils.ts +111 -0
- package/src/index.ts +470 -41
package/src/index.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AssetApprovalPolicy,
|
|
3
|
+
AssetHostDependency,
|
|
4
|
+
AssetSideEffectLevel,
|
|
5
|
+
AssetSource,
|
|
6
|
+
FinishReason,
|
|
7
|
+
McpConnectionStatus,
|
|
8
|
+
ToolUI,
|
|
9
|
+
} from '@huyooo/ai-chat-core'
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* @huyooo/ai-chat-types
|
|
3
13
|
*
|
|
@@ -11,22 +21,25 @@
|
|
|
11
21
|
|
|
12
22
|
// ==================== 从 ai-chat-core/events 重新导出事件类型 ====================
|
|
13
23
|
// 使用子路径导出,避免在 renderer 中拉入 ai-chat-core 整个模块图
|
|
14
|
-
// (ai-chat-core 主入口包含
|
|
24
|
+
// (ai-chat-core 主入口包含 ChatRuntime → MCP SDK 等 Node.js 依赖)
|
|
15
25
|
|
|
16
26
|
export type {
|
|
17
27
|
// 聚合类型
|
|
18
28
|
ChatEvent,
|
|
19
29
|
ChatEventType,
|
|
30
|
+
AssistantSegmentReason,
|
|
31
|
+
ToolApprovalReason,
|
|
20
32
|
|
|
21
33
|
// 基础类型
|
|
22
|
-
SearchResult,
|
|
23
34
|
ToolCallStatus,
|
|
24
35
|
ToolCallInfo,
|
|
25
36
|
TokenUsage,
|
|
26
37
|
ErrorCategory,
|
|
27
38
|
ErrorDetails,
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
ToolError,
|
|
40
|
+
ToolUI,
|
|
41
|
+
FinishReason,
|
|
42
|
+
ToolFailureReason,
|
|
30
43
|
|
|
31
44
|
// 思考事件
|
|
32
45
|
ThinkingStartEvent,
|
|
@@ -34,23 +47,23 @@ export type {
|
|
|
34
47
|
ThinkingEndEvent,
|
|
35
48
|
ThinkingEvent,
|
|
36
49
|
|
|
37
|
-
// 搜索事件
|
|
38
|
-
SearchStartEvent,
|
|
39
|
-
SearchResultEvent,
|
|
40
|
-
SearchEndEvent,
|
|
41
|
-
SearchEvent,
|
|
42
|
-
|
|
43
50
|
// 工具事件
|
|
44
51
|
ToolCallStartEvent,
|
|
45
52
|
ToolCallResultEvent,
|
|
46
53
|
ToolCallOutputEvent,
|
|
47
54
|
ToolApprovalRequestEvent,
|
|
55
|
+
ToolCallRequestEvent,
|
|
48
56
|
ToolEvent,
|
|
49
57
|
|
|
50
58
|
// 文本事件
|
|
59
|
+
TextStartEvent,
|
|
51
60
|
TextDeltaEvent,
|
|
61
|
+
TextEndEvent,
|
|
52
62
|
TextEvent,
|
|
53
63
|
|
|
64
|
+
// 数据事件
|
|
65
|
+
DataEvent,
|
|
66
|
+
|
|
54
67
|
// 计划类型
|
|
55
68
|
PlanStep,
|
|
56
69
|
PlanStepStatus,
|
|
@@ -65,11 +78,18 @@ export type {
|
|
|
65
78
|
StepStartEvent,
|
|
66
79
|
StepEndEvent,
|
|
67
80
|
StepEvent,
|
|
81
|
+
AssistantSegmentStartEvent,
|
|
82
|
+
AssistantSegmentEvent,
|
|
68
83
|
|
|
69
84
|
// 上下文压缩事件
|
|
70
85
|
CompactStartEvent,
|
|
71
86
|
CompactEndEvent,
|
|
72
87
|
CompactEvent,
|
|
88
|
+
|
|
89
|
+
// 单条消息内容压缩事件
|
|
90
|
+
ContentCompressStartEvent,
|
|
91
|
+
ContentCompressEndEvent,
|
|
92
|
+
ContentCompressEvent,
|
|
73
93
|
} from '@huyooo/ai-chat-core/events'
|
|
74
94
|
|
|
75
95
|
// 重新导出事件创建函数和类型守卫(从子路径导入,renderer 安全)
|
|
@@ -77,14 +97,14 @@ export {
|
|
|
77
97
|
createThinkingStart,
|
|
78
98
|
createThinkingDelta,
|
|
79
99
|
createThinkingEnd,
|
|
80
|
-
createSearchStart,
|
|
81
|
-
createSearchResult,
|
|
82
|
-
createSearchEnd,
|
|
83
100
|
createToolCallStart,
|
|
84
101
|
createToolCallResult,
|
|
85
102
|
createToolCallOutput,
|
|
103
|
+
createTextStart,
|
|
86
104
|
createTextDelta,
|
|
105
|
+
createTextEnd,
|
|
87
106
|
createDone,
|
|
107
|
+
createData,
|
|
88
108
|
createError,
|
|
89
109
|
createApiError,
|
|
90
110
|
createRateLimitError,
|
|
@@ -94,32 +114,41 @@ export {
|
|
|
94
114
|
createAbort,
|
|
95
115
|
createStepStart,
|
|
96
116
|
createStepEnd,
|
|
117
|
+
createAssistantSegmentStart,
|
|
97
118
|
isThinkingEvent,
|
|
98
|
-
isSearchEvent,
|
|
99
119
|
isToolEvent,
|
|
100
120
|
isTextEvent,
|
|
121
|
+
isDataEvent,
|
|
101
122
|
isStatusEvent,
|
|
102
123
|
isErrorEvent,
|
|
103
124
|
isAbortEvent,
|
|
104
125
|
isStepEvent,
|
|
126
|
+
isAssistantSegmentEvent,
|
|
105
127
|
isCompactEvent,
|
|
128
|
+
isContentCompressEvent,
|
|
106
129
|
isRetryableError,
|
|
107
|
-
|
|
130
|
+
isToolError,
|
|
108
131
|
createCompactStart,
|
|
109
132
|
createCompactEnd,
|
|
133
|
+
createContentCompressStart,
|
|
134
|
+
createContentCompressEnd,
|
|
110
135
|
} from '@huyooo/ai-chat-core/events'
|
|
111
136
|
|
|
112
137
|
// ==================== 从 ai-chat-core 重新导出配置类型 ====================
|
|
113
138
|
|
|
114
139
|
export type {
|
|
115
140
|
// 模式类型(ChatMode 本地定义以支持更多值)
|
|
141
|
+
AssetApprovalPolicy,
|
|
142
|
+
AssetHostDependency,
|
|
143
|
+
AssetSideEffectLevel,
|
|
144
|
+
AssetSource,
|
|
116
145
|
ThinkingMode,
|
|
117
146
|
AutoRunMode,
|
|
118
147
|
AutoRunConfig,
|
|
119
148
|
|
|
120
149
|
// 模型类型
|
|
121
150
|
ModelOption,
|
|
122
|
-
|
|
151
|
+
ProtocolId,
|
|
123
152
|
|
|
124
153
|
// 聊天选项(使用本地 ChatOptions)
|
|
125
154
|
|
|
@@ -129,15 +158,30 @@ export type {
|
|
|
129
158
|
McpConnectionInfo,
|
|
130
159
|
} from '@huyooo/ai-chat-core'
|
|
131
160
|
|
|
132
|
-
/**
|
|
133
|
-
export type ChatMode = 'agent' | 'ask'
|
|
161
|
+
/** 对话模式 */
|
|
162
|
+
export type ChatMode = 'agent' | 'ask'
|
|
134
163
|
|
|
135
164
|
// ==================== 适配器专用类型(本包定义)====================
|
|
136
165
|
|
|
137
|
-
/**
|
|
166
|
+
/** 聊天历史消息(无状态架构传入,需包含完整工具调用上下文) */
|
|
138
167
|
export interface ChatHistoryMessage {
|
|
139
168
|
role: 'user' | 'assistant' | 'system' | 'tool'
|
|
140
169
|
content: string
|
|
170
|
+
/** 思考内容(工具调用循环需回传,如 DeepSeek/GLM) */
|
|
171
|
+
reasoning_content?: string
|
|
172
|
+
/** 工具消息关联的 tool_call_id */
|
|
173
|
+
tool_call_id?: string
|
|
174
|
+
/** assistant 消息的工具调用列表 */
|
|
175
|
+
tool_calls?: Array<{
|
|
176
|
+
id: string
|
|
177
|
+
type: 'function'
|
|
178
|
+
function: {
|
|
179
|
+
name: string
|
|
180
|
+
arguments: string
|
|
181
|
+
}
|
|
182
|
+
/** Gemini 模型需要的 thought_signature */
|
|
183
|
+
thought_signature?: string
|
|
184
|
+
}>
|
|
141
185
|
}
|
|
142
186
|
|
|
143
187
|
/** 聊天选项(使用本地 ChatMode) */
|
|
@@ -151,6 +195,10 @@ export interface ChatOptions {
|
|
|
151
195
|
autoRunConfig?: {
|
|
152
196
|
mode?: 'run-everything' | 'manual'
|
|
153
197
|
}
|
|
198
|
+
maxIterations?: number
|
|
199
|
+
maxDurationMs?: number
|
|
200
|
+
maxToolCalls?: number
|
|
201
|
+
maxTotalTokens?: number
|
|
154
202
|
history?: ChatHistoryMessage[]
|
|
155
203
|
/** Skills 内容(启用的 Skills 的 content 数组,前端拼好传入) */
|
|
156
204
|
skillContents?: string[]
|
|
@@ -178,8 +226,10 @@ export interface MessageRecord {
|
|
|
178
226
|
/** 前端关联 ID(本地模式与 id 相同,云端模式为前端生成的 UUID) */
|
|
179
227
|
clientId?: string | null
|
|
180
228
|
sessionId: string
|
|
181
|
-
role: 'user' | 'assistant'
|
|
229
|
+
role: 'user' | 'assistant' | 'system'
|
|
182
230
|
content: string
|
|
231
|
+
/** 用户通过 @ 选择的上下文资源 */
|
|
232
|
+
atContextItems?: AtContextItem[] | null
|
|
183
233
|
/** 用户消息附带的图片(data URL 或 base64) */
|
|
184
234
|
images: string[]
|
|
185
235
|
/** 生成此消息时使用的模型 */
|
|
@@ -190,19 +240,32 @@ export interface MessageRecord {
|
|
|
190
240
|
webSearchEnabled?: boolean | null
|
|
191
241
|
/** 生成此消息时是否启用深度思考 */
|
|
192
242
|
thinkingEnabled?: boolean | null
|
|
193
|
-
/**
|
|
194
|
-
|
|
243
|
+
/** 子表中的消息内容 Part */
|
|
244
|
+
parts: MessagePartRecord[]
|
|
195
245
|
operationIds?: string | null
|
|
196
246
|
/** Token 使用统计(JSON 字符串) */
|
|
197
247
|
usage?: string | null
|
|
198
248
|
/** 响应耗时(毫秒) */
|
|
199
249
|
duration?: number | null
|
|
250
|
+
/** 结束原因(done 事件携带) */
|
|
251
|
+
finishReason?: FinishReason | null
|
|
200
252
|
/** 消息序号(会话内递增,用于分叉删除) */
|
|
201
253
|
sequence: number
|
|
202
254
|
/** 时间戳(毫秒,Unix 时间戳) */
|
|
203
255
|
timestamp: number
|
|
204
256
|
}
|
|
205
257
|
|
|
258
|
+
export interface GetMessagesPageParams {
|
|
259
|
+
limit?: number
|
|
260
|
+
beforeSequence?: number
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface MessagePage {
|
|
264
|
+
messages: MessageRecord[]
|
|
265
|
+
hasMore: boolean
|
|
266
|
+
nextBeforeSequence: number | null
|
|
267
|
+
}
|
|
268
|
+
|
|
206
269
|
/** 操作记录 */
|
|
207
270
|
export interface OperationRecord {
|
|
208
271
|
id: string
|
|
@@ -234,6 +297,8 @@ export interface SkillRecord {
|
|
|
234
297
|
icon: string
|
|
235
298
|
enabled: boolean
|
|
236
299
|
builtIn: boolean
|
|
300
|
+
extensionId?: string
|
|
301
|
+
extensionName?: string
|
|
237
302
|
createdAt: Date
|
|
238
303
|
updatedAt: Date
|
|
239
304
|
}
|
|
@@ -248,10 +313,317 @@ export interface FileInfo {
|
|
|
248
313
|
extension: string
|
|
249
314
|
}
|
|
250
315
|
|
|
316
|
+
export type AtContextKind = 'file' | 'doc' | 'terminal' | 'chat'
|
|
317
|
+
|
|
318
|
+
interface AtContextItemBase {
|
|
319
|
+
kind: AtContextKind
|
|
320
|
+
id: string
|
|
321
|
+
label: string
|
|
322
|
+
mention: string
|
|
323
|
+
description?: string
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface AtFileContextItem extends AtContextItemBase {
|
|
327
|
+
kind: 'file'
|
|
328
|
+
path: string
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface AtDocumentContextItem extends AtContextItemBase {
|
|
332
|
+
kind: 'doc'
|
|
333
|
+
documentId: string
|
|
334
|
+
source: string
|
|
335
|
+
snippet?: string
|
|
336
|
+
score?: number
|
|
337
|
+
matchType?: 'exact' | 'semantic' | 'fulltext' | 'hybrid'
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface AtTerminalContextItem extends AtContextItemBase {
|
|
341
|
+
kind: 'terminal'
|
|
342
|
+
sessionId: string
|
|
343
|
+
cwd: string
|
|
344
|
+
status: string
|
|
345
|
+
updatedAt: string
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface AtChatContextItem extends AtContextItemBase {
|
|
349
|
+
kind: 'chat'
|
|
350
|
+
sessionId: string
|
|
351
|
+
updatedAt: number
|
|
352
|
+
preview?: string
|
|
353
|
+
matchedMessageId?: string
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export type AtContextItem =
|
|
357
|
+
| AtFileContextItem
|
|
358
|
+
| AtDocumentContextItem
|
|
359
|
+
| AtTerminalContextItem
|
|
360
|
+
| AtChatContextItem
|
|
361
|
+
|
|
362
|
+
export type AtResourceKind = AtContextKind | 'directory'
|
|
363
|
+
|
|
364
|
+
export interface AtResourceLocator {
|
|
365
|
+
path?: string
|
|
366
|
+
documentId?: string
|
|
367
|
+
sessionId?: string
|
|
368
|
+
cwd?: string
|
|
369
|
+
messageId?: string
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface AtResourcePreview {
|
|
373
|
+
text?: string
|
|
374
|
+
score?: number
|
|
375
|
+
matchType?: 'exact' | 'semantic' | 'fulltext' | 'hybrid'
|
|
376
|
+
updatedAt?: string | number
|
|
377
|
+
status?: string
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface AtResourceContent {
|
|
381
|
+
kind: 'full' | 'summary' | 'structure'
|
|
382
|
+
text: string
|
|
383
|
+
truncated?: boolean
|
|
384
|
+
/**
|
|
385
|
+
* 该正文在使用 TokenCounter 计数下的 token 数。
|
|
386
|
+
* 由 chat-utils 在应用 token budget 后写入,下游可据此做二次裁剪或调试展示。
|
|
387
|
+
*/
|
|
388
|
+
tokens?: number
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface AtResourceRecommendedTool {
|
|
392
|
+
alias: string
|
|
393
|
+
displayName?: string
|
|
394
|
+
purpose: string
|
|
395
|
+
/** 该工具是否能继续读到资源更多正文 / 结构化内容(元信息 / 查找类为 false) */
|
|
396
|
+
canReadMore: boolean
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* 文件格式能力契约 —— 整个 @ 文件链路的单一类型真相源。
|
|
401
|
+
*
|
|
402
|
+
* 同一套枚举同时被:
|
|
403
|
+
* - superx/src/shared/fileTypeCatalog.ts(在宿主侧填充具体格式表并派生默认策略)
|
|
404
|
+
* - ai-chat-shared/src/at-context-tools.ts(在前端侧按能力推荐工具)
|
|
405
|
+
* 共同使用,严禁在任何一侧再次重复声明,避免双写漂移。
|
|
406
|
+
*
|
|
407
|
+
* DocumentType 语义:
|
|
408
|
+
* - code/config/style/web/text/data → 原文按行读(super_filesystem__read)
|
|
409
|
+
* - word/pdf/excel/powerpoint/notebook → 已解析文档统一读取(super_filesystem__read)
|
|
410
|
+
* - ebook/opendocument → 同上
|
|
411
|
+
* - unknown → 只推按名搜索,不推读取
|
|
412
|
+
*/
|
|
413
|
+
export type DocumentType =
|
|
414
|
+
| 'code'
|
|
415
|
+
| 'config'
|
|
416
|
+
| 'style'
|
|
417
|
+
| 'web'
|
|
418
|
+
| 'text'
|
|
419
|
+
| 'data'
|
|
420
|
+
| 'word'
|
|
421
|
+
| 'pdf'
|
|
422
|
+
| 'excel'
|
|
423
|
+
| 'powerpoint'
|
|
424
|
+
| 'notebook'
|
|
425
|
+
| 'ebook'
|
|
426
|
+
| 'opendocument'
|
|
427
|
+
| 'unknown'
|
|
428
|
+
|
|
429
|
+
export type ReadStrategy =
|
|
430
|
+
| 'line-range'
|
|
431
|
+
| 'section'
|
|
432
|
+
| 'page'
|
|
433
|
+
| 'sheet-range'
|
|
434
|
+
| 'slide'
|
|
435
|
+
| 'cell'
|
|
436
|
+
| 'symbol'
|
|
437
|
+
| 'none'
|
|
438
|
+
|
|
439
|
+
export type SearchStrategy =
|
|
440
|
+
| 'grep'
|
|
441
|
+
| 'document-index'
|
|
442
|
+
| 'code-index'
|
|
443
|
+
| 'none'
|
|
444
|
+
|
|
445
|
+
export type EditStrategy =
|
|
446
|
+
| 'text'
|
|
447
|
+
| 'structured-code'
|
|
448
|
+
| 'readonly'
|
|
449
|
+
| 'none'
|
|
450
|
+
|
|
451
|
+
export interface AtResolvedFileContext {
|
|
452
|
+
title?: string
|
|
453
|
+
content: string | null
|
|
454
|
+
/** 文件格式分类,由宿主通过 fileTypeCatalog 解析得出 */
|
|
455
|
+
docType?: DocumentType
|
|
456
|
+
/** 文件读取坐标能力:行 / 页 / cell / symbol 等 */
|
|
457
|
+
readStrategy?: ReadStrategy
|
|
458
|
+
/** 文件内容搜索能力:grep / 文档索引 / 代码索引 */
|
|
459
|
+
searchStrategy?: SearchStrategy
|
|
460
|
+
/** 文件编辑能力:文本替换 / 结构化代码 / 只读 */
|
|
461
|
+
editStrategy?: EditStrategy
|
|
462
|
+
metadata?: Record<string, unknown>
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export interface AtResourceAccess {
|
|
466
|
+
/** 推荐工具里是否至少有一个能继续读到资源更多正文 / 结构化内容 */
|
|
467
|
+
canReadMore: boolean
|
|
468
|
+
/**
|
|
469
|
+
* 资源正文当前是否还有"直读 / 直搜"通道可用。
|
|
470
|
+
* - file 资源:由 fileTypeCatalog 的 parser/readStrategy/searchStrategy 直接决定
|
|
471
|
+
* (unsupported 或 read=none + search=none 时为 false)
|
|
472
|
+
* - directory / doc / terminal / chat 等非文件资源:恒为 true
|
|
473
|
+
* 下游渲染层直接读此字段即可,无需再反推 metadata 字符串。
|
|
474
|
+
*/
|
|
475
|
+
directReadable: boolean
|
|
476
|
+
recommendedTools: AtResourceRecommendedTool[]
|
|
477
|
+
/**
|
|
478
|
+
* 最终分配给该资源的 token 预算(预览 + 正文 + 元信息提示合计上限)。
|
|
479
|
+
* 由 chat-utils 在装配 prompt 时按全局 budget 分配得出;未开启 token budget 时为 undefined。
|
|
480
|
+
*/
|
|
481
|
+
allocatedTokens?: number
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export interface AtResourceDescriptor {
|
|
485
|
+
kind: AtResourceKind
|
|
486
|
+
mention: string
|
|
487
|
+
title: string
|
|
488
|
+
locator: AtResourceLocator
|
|
489
|
+
preview?: AtResourcePreview
|
|
490
|
+
content?: AtResourceContent
|
|
491
|
+
access: AtResourceAccess
|
|
492
|
+
metadata?: Record<string, unknown>
|
|
493
|
+
}
|
|
494
|
+
|
|
251
495
|
/** 工具信息 */
|
|
252
496
|
export interface ToolInfo {
|
|
253
497
|
name: string
|
|
254
498
|
description: string
|
|
499
|
+
displayName: string
|
|
500
|
+
assetId: string
|
|
501
|
+
source: AssetSource
|
|
502
|
+
category: string
|
|
503
|
+
parameters?: Record<string, unknown>
|
|
504
|
+
outputSchema?: Record<string, unknown>
|
|
505
|
+
errorSchema?: Record<string, unknown>
|
|
506
|
+
approvalPolicy?: AssetApprovalPolicy
|
|
507
|
+
sideEffectLevel?: AssetSideEffectLevel
|
|
508
|
+
hostDependency?: AssetHostDependency
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export type ChatCapabilityGroupSource = AssetSource
|
|
512
|
+
|
|
513
|
+
export interface ChatCapabilitySkillItem {
|
|
514
|
+
id: string
|
|
515
|
+
name: string
|
|
516
|
+
description: string
|
|
517
|
+
source: AssetSource
|
|
518
|
+
extensionId: string
|
|
519
|
+
extensionName: string
|
|
520
|
+
chatEnabled: boolean
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export interface ChatCapabilityToolItem {
|
|
524
|
+
alias: string
|
|
525
|
+
displayName: string
|
|
526
|
+
description: string
|
|
527
|
+
source: AssetSource
|
|
528
|
+
category: string
|
|
529
|
+
extensionId: string
|
|
530
|
+
extensionName: string
|
|
531
|
+
runtimeInjected: boolean
|
|
532
|
+
runtimeAvailable: boolean
|
|
533
|
+
chatEnabled: boolean
|
|
534
|
+
approvalPolicy?: AssetApprovalPolicy
|
|
535
|
+
sideEffectLevel?: AssetSideEffectLevel
|
|
536
|
+
hostDependency?: AssetHostDependency
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export interface ChatCapabilityMcpToolItem {
|
|
540
|
+
alias: string
|
|
541
|
+
displayName: string
|
|
542
|
+
description: string
|
|
543
|
+
source: AssetSource
|
|
544
|
+
extensionId: string
|
|
545
|
+
extensionName: string
|
|
546
|
+
runtimeInjected: boolean
|
|
547
|
+
runtimeAvailable: boolean
|
|
548
|
+
chatEnabled: boolean
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export interface ChatCapabilityMcpServerItem {
|
|
552
|
+
id: string
|
|
553
|
+
name: string
|
|
554
|
+
source: AssetSource
|
|
555
|
+
extensionId: string
|
|
556
|
+
extensionName: string
|
|
557
|
+
runtimeInjected: boolean
|
|
558
|
+
runtimeAvailable: boolean
|
|
559
|
+
connectionStatus: McpConnectionStatus
|
|
560
|
+
error?: string
|
|
561
|
+
tools: ChatCapabilityMcpToolItem[]
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export interface ChatCapabilityExtensionGroup {
|
|
565
|
+
id: string
|
|
566
|
+
name: string
|
|
567
|
+
source: ChatCapabilityGroupSource
|
|
568
|
+
extensionEnabled: boolean
|
|
569
|
+
/**
|
|
570
|
+
* Total capabilities owned by the extension, including items hidden while the
|
|
571
|
+
* extension is disabled. Renderers should use this for extension-level counts.
|
|
572
|
+
*/
|
|
573
|
+
availableCount?: number
|
|
574
|
+
skills: ChatCapabilitySkillItem[]
|
|
575
|
+
tools: ChatCapabilityToolItem[]
|
|
576
|
+
mcpServers: ChatCapabilityMcpServerItem[]
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export interface ChatCapabilitySnapshot {
|
|
580
|
+
extensions: ChatCapabilityExtensionGroup[]
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export interface AgentCapabilityManifestTool {
|
|
584
|
+
alias: string
|
|
585
|
+
displayName: string
|
|
586
|
+
description: string
|
|
587
|
+
kind: 'tool' | 'mcp-tool'
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export interface AgentCapabilityManifestSkill {
|
|
591
|
+
id: string
|
|
592
|
+
name: string
|
|
593
|
+
description: string
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export interface AgentCapabilityManifestExtension {
|
|
597
|
+
id: string
|
|
598
|
+
name: string
|
|
599
|
+
source: string
|
|
600
|
+
skills: AgentCapabilityManifestSkill[]
|
|
601
|
+
tools: AgentCapabilityManifestTool[]
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export interface AgentCapabilityManifest {
|
|
605
|
+
version: '1'
|
|
606
|
+
extensions: AgentCapabilityManifestExtension[]
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export interface ChatCapabilitySelection {
|
|
610
|
+
toolOverrides: Record<string, boolean>
|
|
611
|
+
mcpToolOverrides: Record<string, boolean>
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
export interface SkillEnabledItem {
|
|
615
|
+
id: string
|
|
616
|
+
enabled: boolean
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export interface ChatCapabilityToolEnabledItem {
|
|
620
|
+
alias: string
|
|
621
|
+
enabled: boolean
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export interface ChatCapabilityToolEnabledResult extends ChatCapabilityToolEnabledItem {
|
|
625
|
+
kind?: 'tool' | 'mcp'
|
|
626
|
+
error?: string
|
|
255
627
|
}
|
|
256
628
|
|
|
257
629
|
/** 工具批准请求 */
|
|
@@ -267,8 +639,14 @@ export interface ToolExecutionResult {
|
|
|
267
639
|
result: string
|
|
268
640
|
error?: string
|
|
269
641
|
/** 工具 UI 声明(成功时) */
|
|
270
|
-
ui?:
|
|
271
|
-
|
|
642
|
+
ui?: ToolUI
|
|
643
|
+
approvalPolicy?: AssetApprovalPolicy
|
|
644
|
+
sideEffectLevel?: AssetSideEffectLevel
|
|
645
|
+
hostDependency?: AssetHostDependency
|
|
646
|
+
riskSummary?: string
|
|
647
|
+
riskTags?: string[]
|
|
648
|
+
riskSignals?: string[]
|
|
649
|
+
toolError?: import('@huyooo/ai-chat-core/events').ToolError
|
|
272
650
|
}
|
|
273
651
|
|
|
274
652
|
// ==================== ASR 语音识别 ====================
|
|
@@ -308,16 +686,15 @@ export interface AsrResultData {
|
|
|
308
686
|
// ==================== ChatAdapter 接口 ====================
|
|
309
687
|
|
|
310
688
|
// 导入 ChatEvent 和 ModelOption 用于 ChatAdapter 接口
|
|
311
|
-
// ChatOptions
|
|
689
|
+
// ChatOptions 使用本地定义(含 ChatMode)
|
|
312
690
|
import type { ChatEvent, ModelOption } from '@huyooo/ai-chat-core'
|
|
313
691
|
|
|
314
692
|
/**
|
|
315
693
|
* ChatAdapter 接口
|
|
316
694
|
*
|
|
317
695
|
* 统一的聊天适配器接口,支持多种实现:
|
|
318
|
-
* - Electron IPC(ai-chat-bridge-electron)
|
|
696
|
+
* - Electron IPC(ai-chat-bridge-electron/renderer)
|
|
319
697
|
* - HTTP/SSE(ai-chat-adapter-http)
|
|
320
|
-
* - 直连(ai-chat-adapter-direct,CLI 用)
|
|
321
698
|
*
|
|
322
699
|
* 行为统一保证:无论使用哪种实现(本地直连 / HTTP / 混合),对调用方接口一致——
|
|
323
700
|
* getModels()、sendMessage()、getSessions() 等语义相同,sendMessage 产出的事件均为
|
|
@@ -329,8 +706,12 @@ export interface ChatAdapter {
|
|
|
329
706
|
// ============ Chat API ============
|
|
330
707
|
/** 获取可用模型 */
|
|
331
708
|
getModels(): Promise<ModelOption[]>
|
|
332
|
-
/**
|
|
709
|
+
/** 获取所有工具列表(用于工具设置或管理视图) */
|
|
333
710
|
getAllTools?(): Promise<ToolInfo[]>
|
|
711
|
+
/** 获取聊天能力快照(扩展 -> 能力分类 -> 能力项) */
|
|
712
|
+
getChatCapabilitySnapshot?(): Promise<ChatCapabilitySnapshot>
|
|
713
|
+
/** 监听聊天能力更新 */
|
|
714
|
+
onChatCapabilityUpdate?(callback: () => void): () => void
|
|
334
715
|
/** 发送消息,返回异步迭代器 */
|
|
335
716
|
sendMessage(
|
|
336
717
|
message: string,
|
|
@@ -342,6 +723,20 @@ export interface ChatAdapter {
|
|
|
342
723
|
cancel(): void
|
|
343
724
|
/** 设置当前工作目录 */
|
|
344
725
|
setCwd?(dir: string): void
|
|
726
|
+
/** 搜索可引用的文档上下文 */
|
|
727
|
+
searchAtDocuments?(query: string, options?: { limit?: number }): Promise<AtDocumentContextItem[]>
|
|
728
|
+
/** 列出可引用的终端会话 */
|
|
729
|
+
listAtTerminals?(options?: { query?: string; limit?: number; workspaceRoot?: string }): Promise<AtTerminalContextItem[]>
|
|
730
|
+
/** 搜索可引用的历史对话 */
|
|
731
|
+
searchAtChats?(query: string, options?: { limit?: number }): Promise<AtChatContextItem[]>
|
|
732
|
+
/** 读取可引用的文档上下文内容 */
|
|
733
|
+
readAtDocumentContext?(documentId: string): Promise<string | null>
|
|
734
|
+
/** 读取可引用的终端上下文内容 */
|
|
735
|
+
readAtTerminalContext?(sessionId: string): Promise<string | null>
|
|
736
|
+
/** 读取可引用的历史对话上下文内容 */
|
|
737
|
+
readAtChatContext?(sessionId: string): Promise<string | null>
|
|
738
|
+
/** 解析 @ 文件上下文(供宿主接入高级文件解析器) */
|
|
739
|
+
resolveAtFileContext?(filePath: string): Promise<AtResolvedFileContext | null>
|
|
345
740
|
|
|
346
741
|
// ============ Sessions API ============
|
|
347
742
|
/** 获取会话列表 */
|
|
@@ -358,6 +753,8 @@ export interface ChatAdapter {
|
|
|
358
753
|
// ============ Messages API ============
|
|
359
754
|
/** 获取会话消息 */
|
|
360
755
|
getMessages(sessionId: string): Promise<MessageRecord[]>
|
|
756
|
+
/** 分页获取会话消息(优先返回最近消息,按 sequence 升序返回当前页) */
|
|
757
|
+
getMessagesPage?(sessionId: string, params?: GetMessagesPageParams): Promise<MessagePage>
|
|
361
758
|
/** 保存消息 */
|
|
362
759
|
saveMessage(params: SaveMessageParams): Promise<MessageRecord>
|
|
363
760
|
/** 更新消息(增量保存) */
|
|
@@ -407,16 +804,20 @@ export interface ChatAdapter {
|
|
|
407
804
|
onIndexProgress?(callback: (progress: { indexed: number; total: number; currentFile?: string; stage: string; error?: string }) => void): () => void
|
|
408
805
|
|
|
409
806
|
// ============ Skills API(可选)============
|
|
410
|
-
/**
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
|
|
807
|
+
/** 批量设置 Skill 的聊天启用状态(聊天侧仅保留此能力) */
|
|
808
|
+
setSkillsChatEnabled?(items: SkillEnabledItem[]): Promise<Array<SkillEnabledItem & { error?: string }>>
|
|
809
|
+
/** 批量设置普通 Tool 的聊天启用状态(不改变扩展运行时启停) */
|
|
810
|
+
setToolsChatEnabled?(items: ChatCapabilityToolEnabledItem[]): Promise<ChatCapabilityToolEnabledResult[]>
|
|
811
|
+
/** 批量设置 MCP Tool 的聊天启用状态(不改变扩展运行时启停) */
|
|
812
|
+
setMcpToolsChatEnabled?(items: ChatCapabilityToolEnabledItem[]): Promise<ChatCapabilityToolEnabledResult[]>
|
|
813
|
+
|
|
814
|
+
// ============ Extension Toggle API(可选)============
|
|
815
|
+
/**
|
|
816
|
+
* 设置扩展的整体启停状态(Layer 1:影响 ChatRuntime 的 sessionTools)。
|
|
817
|
+
* 对比 setSkillsChatEnabled / setToolsChatEnabled,这里是"容器级"开关:
|
|
818
|
+
* 禁用扩展会让其所有 tool/skill/mcp 从会话工具集里卸下,直接减少 token 占用。
|
|
819
|
+
*/
|
|
820
|
+
setExtensionEnabled?(payload: { id: string; enabled: boolean; source: AssetSource }): Promise<{ ok: true } | { ok: false; error: string }>
|
|
420
821
|
|
|
421
822
|
// ============ Tool Approval API ============
|
|
422
823
|
onToolApprovalRequest?(callback: (request: ToolApprovalRequest) => void): () => void
|
|
@@ -467,27 +868,44 @@ export interface UpdateSessionParams {
|
|
|
467
868
|
export interface SaveMessageParams {
|
|
468
869
|
id?: string
|
|
469
870
|
sessionId: string
|
|
470
|
-
role: 'user' | 'assistant'
|
|
871
|
+
role: 'user' | 'assistant' | 'system'
|
|
471
872
|
content: string
|
|
873
|
+
atContextItems?: AtContextItem[]
|
|
472
874
|
images?: string[]
|
|
473
875
|
model?: string
|
|
474
876
|
mode?: string
|
|
475
877
|
webSearchEnabled?: boolean
|
|
476
878
|
thinkingEnabled?: boolean
|
|
477
|
-
|
|
879
|
+
parts?: MessagePartInput[]
|
|
478
880
|
operationIds?: string
|
|
881
|
+
finishReason?: FinishReason
|
|
479
882
|
}
|
|
480
883
|
|
|
481
884
|
/** 更新消息参数 */
|
|
482
885
|
export interface UpdateMessageParams {
|
|
483
886
|
id: string
|
|
484
887
|
content?: string
|
|
485
|
-
|
|
888
|
+
atContextItems?: AtContextItem[] | null
|
|
889
|
+
parts?: MessagePartInput[]
|
|
486
890
|
operationIds?: string
|
|
487
891
|
/** Token 使用统计(JSON 字符串) */
|
|
488
892
|
usage?: string
|
|
489
893
|
/** 响应耗时(毫秒) */
|
|
490
894
|
duration?: number
|
|
895
|
+
/** 结束原因(done 事件携带) */
|
|
896
|
+
finishReason?: FinishReason
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
export interface MessagePartRecord {
|
|
900
|
+
messageId: string
|
|
901
|
+
sequence: number
|
|
902
|
+
type: string
|
|
903
|
+
payload: string
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
export interface MessagePartInput {
|
|
907
|
+
type: string
|
|
908
|
+
payload: string
|
|
491
909
|
}
|
|
492
910
|
|
|
493
911
|
// ==================== 发送消息参数(用于 IPC)====================
|
|
@@ -507,3 +925,14 @@ export interface SendMessageParams {
|
|
|
507
925
|
history?: ChatHistoryMessage[]
|
|
508
926
|
}
|
|
509
927
|
}
|
|
928
|
+
|
|
929
|
+
// ==================== 前端扩展事件类型 + 事件工具 ====================
|
|
930
|
+
|
|
931
|
+
export {
|
|
932
|
+
buildToolGovernanceLabels,
|
|
933
|
+
type FrontendChatEvent,
|
|
934
|
+
type ToolGovernanceInfo,
|
|
935
|
+
extractToolGovernance,
|
|
936
|
+
mergeToolGovernance,
|
|
937
|
+
shouldSaveEvent,
|
|
938
|
+
} from './chat-utils'
|