@huyooo/ai-chat-types 0.2.45 → 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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 前端扩展事件类型 + 依赖事件类型的工具函数
|
|
3
|
+
*
|
|
4
|
+
* billing 等元数据现在通过 DataEvent(type='data', name='billing')传递,
|
|
5
|
+
* 不再需要在此处硬编码扩展事件。
|
|
6
|
+
*
|
|
7
|
+
* compact/content_compress 事件已内置于 ChatEvent 联合类型,无需重复声明。
|
|
8
|
+
*/
|
|
9
|
+
import type { AssetApprovalPolicy, AssetHostDependency, AssetSideEffectLevel } from '@huyooo/ai-chat-core';
|
|
10
|
+
import type { ChatEvent, ToolApprovalReason, ToolApprovalRequestEvent, ToolCallResultEvent, ToolCallStartEvent } from '@huyooo/ai-chat-core/events';
|
|
11
|
+
export type FrontendChatEvent = ChatEvent;
|
|
12
|
+
export interface ToolGovernanceInfo {
|
|
13
|
+
approvalReason?: ToolApprovalReason;
|
|
14
|
+
approvalPolicy?: AssetApprovalPolicy;
|
|
15
|
+
sideEffectLevel?: AssetSideEffectLevel;
|
|
16
|
+
hostDependency?: AssetHostDependency;
|
|
17
|
+
}
|
|
18
|
+
type ToolGovernanceEventData = ToolApprovalRequestEvent['data'] | ToolCallStartEvent['data'] | ToolCallResultEvent['data'];
|
|
19
|
+
export declare function extractToolGovernance(data: ToolGovernanceEventData): ToolGovernanceInfo;
|
|
20
|
+
export declare function mergeToolGovernance<T extends object>(target: T, governance: ToolGovernanceInfo): T & ToolGovernanceInfo;
|
|
21
|
+
export declare function buildToolGovernanceLabels(governance: ToolGovernanceInfo): {
|
|
22
|
+
approvalReasonText?: string;
|
|
23
|
+
tags: string[];
|
|
24
|
+
};
|
|
25
|
+
/** 判断事件是否需要保存到数据库 */
|
|
26
|
+
export declare function shouldSaveEvent(event: FrontendChatEvent): boolean;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=chat-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-utils.d.ts","sourceRoot":"","sources":["../src/chat-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,6BAA6B,CAAA;AAEpC,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAA;AAEzC,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,kBAAkB,CAAA;IACnC,cAAc,CAAC,EAAE,mBAAmB,CAAA;IACpC,eAAe,CAAC,EAAE,oBAAoB,CAAA;IACtC,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC;AAED,KAAK,uBAAuB,GACxB,wBAAwB,CAAC,MAAM,CAAC,GAChC,kBAAkB,CAAC,MAAM,CAAC,GAC1B,mBAAmB,CAAC,MAAM,CAAC,CAAA;AAE/B,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,uBAAuB,GAAG,kBAAkB,CAOvF;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAClD,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,kBAAkB,GAC7B,CAAC,GAAG,kBAAkB,CAQxB;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,kBAAkB,GAAG;IACzE,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,IAAI,EAAE,MAAM,EAAE,CAAA;CACf,CAqCA;AAED,qBAAqB;AACrB,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CASjE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { AssetApprovalPolicy, AssetHostDependency, AssetSideEffectLevel, AssetSource, FinishReason, McpConnectionStatus, ToolUI } from '@huyooo/ai-chat-core';
|
|
2
|
+
/**
|
|
3
|
+
* @huyooo/ai-chat-types
|
|
4
|
+
*
|
|
5
|
+
* AI Chat 公共类型定义
|
|
6
|
+
*
|
|
7
|
+
* 架构层级:
|
|
8
|
+
* 1. ai-chat-core - 核心引擎(定义事件、工具等核心类型)
|
|
9
|
+
* 2. ai-chat-types - 公共接口(导出 ChatAdapter、重新导出 ChatEvent)
|
|
10
|
+
* 3. 各适配器包 - 实现 ChatAdapter 接口
|
|
11
|
+
*/
|
|
12
|
+
export type { ChatEvent, ChatEventType, AssistantSegmentReason, ToolApprovalReason, ToolCallStatus, ToolCallInfo, TokenUsage, ErrorCategory, ErrorDetails, ToolError, ToolUI, FinishReason, ToolFailureReason, ThinkingStartEvent, ThinkingDeltaEvent, ThinkingEndEvent, ThinkingEvent, ToolCallStartEvent, ToolCallResultEvent, ToolCallOutputEvent, ToolApprovalRequestEvent, ToolCallRequestEvent, ToolEvent, TextStartEvent, TextDeltaEvent, TextEndEvent, TextEvent, DataEvent, PlanStep, PlanStepStatus, DoneEvent, ErrorEvent, AbortEvent, StatusEvent, StepStartEvent, StepEndEvent, StepEvent, AssistantSegmentStartEvent, AssistantSegmentEvent, CompactStartEvent, CompactEndEvent, CompactEvent, ContentCompressStartEvent, ContentCompressEndEvent, ContentCompressEvent, } from '@huyooo/ai-chat-core/events';
|
|
13
|
+
export { createThinkingStart, createThinkingDelta, createThinkingEnd, createToolCallStart, createToolCallResult, createToolCallOutput, createTextStart, createTextDelta, createTextEnd, createDone, createData, createError, createApiError, createRateLimitError, createToolError, createTimeoutError, createParseError, createAbort, createStepStart, createStepEnd, createAssistantSegmentStart, isThinkingEvent, isToolEvent, isTextEvent, isDataEvent, isStatusEvent, isErrorEvent, isAbortEvent, isStepEvent, isAssistantSegmentEvent, isCompactEvent, isContentCompressEvent, isRetryableError, isToolError, createCompactStart, createCompactEnd, createContentCompressStart, createContentCompressEnd, } from '@huyooo/ai-chat-core/events';
|
|
14
|
+
export type { AssetApprovalPolicy, AssetHostDependency, AssetSideEffectLevel, AssetSource, ThinkingMode, AutoRunMode, AutoRunConfig, ModelOption, ProtocolId, McpServerConfig, McpConnectionStatus, McpConnectionInfo, } from '@huyooo/ai-chat-core';
|
|
15
|
+
/** 对话模式 */
|
|
16
|
+
export type ChatMode = 'agent' | 'ask';
|
|
17
|
+
/** 聊天历史消息(无状态架构传入,需包含完整工具调用上下文) */
|
|
18
|
+
export interface ChatHistoryMessage {
|
|
10
19
|
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
11
20
|
content: string;
|
|
21
|
+
/** 思考内容(工具调用循环需回传,如 DeepSeek/GLM) */
|
|
22
|
+
reasoning_content?: string;
|
|
23
|
+
/** 工具消息关联的 tool_call_id */
|
|
24
|
+
tool_call_id?: string;
|
|
25
|
+
/** assistant 消息的工具调用列表 */
|
|
26
|
+
tool_calls?: Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
type: 'function';
|
|
29
|
+
function: {
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: string;
|
|
32
|
+
};
|
|
33
|
+
/** Gemini 模型需要的 thought_signature */
|
|
34
|
+
thought_signature?: string;
|
|
35
|
+
}>;
|
|
12
36
|
}
|
|
13
37
|
/** 聊天选项(使用本地 ChatMode) */
|
|
14
|
-
interface ChatOptions {
|
|
38
|
+
export interface ChatOptions {
|
|
15
39
|
mode?: ChatMode;
|
|
16
40
|
model?: string;
|
|
17
41
|
provider?: string;
|
|
@@ -21,12 +45,16 @@ interface ChatOptions {
|
|
|
21
45
|
autoRunConfig?: {
|
|
22
46
|
mode?: 'run-everything' | 'manual';
|
|
23
47
|
};
|
|
48
|
+
maxIterations?: number;
|
|
49
|
+
maxDurationMs?: number;
|
|
50
|
+
maxToolCalls?: number;
|
|
51
|
+
maxTotalTokens?: number;
|
|
24
52
|
history?: ChatHistoryMessage[];
|
|
25
53
|
/** Skills 内容(启用的 Skills 的 content 数组,前端拼好传入) */
|
|
26
54
|
skillContents?: string[];
|
|
27
55
|
}
|
|
28
56
|
/** 会话记录 */
|
|
29
|
-
interface SessionRecord {
|
|
57
|
+
export interface SessionRecord {
|
|
30
58
|
id: string;
|
|
31
59
|
appId: string | null;
|
|
32
60
|
userId: string | null;
|
|
@@ -41,13 +69,15 @@ interface SessionRecord {
|
|
|
41
69
|
updatedAt: Date;
|
|
42
70
|
}
|
|
43
71
|
/** 消息记录 */
|
|
44
|
-
interface MessageRecord {
|
|
72
|
+
export interface MessageRecord {
|
|
45
73
|
id: string;
|
|
46
74
|
/** 前端关联 ID(本地模式与 id 相同,云端模式为前端生成的 UUID) */
|
|
47
75
|
clientId?: string | null;
|
|
48
76
|
sessionId: string;
|
|
49
|
-
role: 'user' | 'assistant';
|
|
77
|
+
role: 'user' | 'assistant' | 'system';
|
|
50
78
|
content: string;
|
|
79
|
+
/** 用户通过 @ 选择的上下文资源 */
|
|
80
|
+
atContextItems?: AtContextItem[] | null;
|
|
51
81
|
/** 用户消息附带的图片(data URL 或 base64) */
|
|
52
82
|
images: string[];
|
|
53
83
|
/** 生成此消息时使用的模型 */
|
|
@@ -58,20 +88,31 @@ interface MessageRecord {
|
|
|
58
88
|
webSearchEnabled?: boolean | null;
|
|
59
89
|
/** 生成此消息时是否启用深度思考 */
|
|
60
90
|
thinkingEnabled?: boolean | null;
|
|
61
|
-
/**
|
|
62
|
-
|
|
91
|
+
/** 子表中的消息内容 Part */
|
|
92
|
+
parts: MessagePartRecord[];
|
|
63
93
|
operationIds?: string | null;
|
|
64
94
|
/** Token 使用统计(JSON 字符串) */
|
|
65
95
|
usage?: string | null;
|
|
66
96
|
/** 响应耗时(毫秒) */
|
|
67
97
|
duration?: number | null;
|
|
98
|
+
/** 结束原因(done 事件携带) */
|
|
99
|
+
finishReason?: FinishReason | null;
|
|
68
100
|
/** 消息序号(会话内递增,用于分叉删除) */
|
|
69
101
|
sequence: number;
|
|
70
102
|
/** 时间戳(毫秒,Unix 时间戳) */
|
|
71
103
|
timestamp: number;
|
|
72
104
|
}
|
|
105
|
+
export interface GetMessagesPageParams {
|
|
106
|
+
limit?: number;
|
|
107
|
+
beforeSequence?: number;
|
|
108
|
+
}
|
|
109
|
+
export interface MessagePage {
|
|
110
|
+
messages: MessageRecord[];
|
|
111
|
+
hasMore: boolean;
|
|
112
|
+
nextBeforeSequence: number | null;
|
|
113
|
+
}
|
|
73
114
|
/** 操作记录 */
|
|
74
|
-
interface OperationRecord {
|
|
115
|
+
export interface OperationRecord {
|
|
75
116
|
id: string;
|
|
76
117
|
sessionId: string;
|
|
77
118
|
messageId?: string | null;
|
|
@@ -82,7 +123,7 @@ interface OperationRecord {
|
|
|
82
123
|
timestamp: Date;
|
|
83
124
|
}
|
|
84
125
|
/** 回收站记录 */
|
|
85
|
-
interface TrashRecord {
|
|
126
|
+
export interface TrashRecord {
|
|
86
127
|
id: string;
|
|
87
128
|
sessionId: string;
|
|
88
129
|
originalPath: string;
|
|
@@ -91,7 +132,7 @@ interface TrashRecord {
|
|
|
91
132
|
autoDeleteAt: Date;
|
|
92
133
|
}
|
|
93
134
|
/** Skill 记录(system prompt 片段,支持本地或云端管理) */
|
|
94
|
-
interface SkillRecord {
|
|
135
|
+
export interface SkillRecord {
|
|
95
136
|
id: string;
|
|
96
137
|
name: string;
|
|
97
138
|
description: string;
|
|
@@ -99,11 +140,13 @@ interface SkillRecord {
|
|
|
99
140
|
icon: string;
|
|
100
141
|
enabled: boolean;
|
|
101
142
|
builtIn: boolean;
|
|
143
|
+
extensionId?: string;
|
|
144
|
+
extensionName?: string;
|
|
102
145
|
createdAt: Date;
|
|
103
146
|
updatedAt: Date;
|
|
104
147
|
}
|
|
105
148
|
/** 文件信息 */
|
|
106
|
-
interface FileInfo {
|
|
149
|
+
export interface FileInfo {
|
|
107
150
|
name: string;
|
|
108
151
|
path: string;
|
|
109
152
|
isDirectory: boolean;
|
|
@@ -111,32 +154,273 @@ interface FileInfo {
|
|
|
111
154
|
modifiedAt: Date;
|
|
112
155
|
extension: string;
|
|
113
156
|
}
|
|
157
|
+
export type AtContextKind = 'file' | 'doc' | 'terminal' | 'chat';
|
|
158
|
+
interface AtContextItemBase {
|
|
159
|
+
kind: AtContextKind;
|
|
160
|
+
id: string;
|
|
161
|
+
label: string;
|
|
162
|
+
mention: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface AtFileContextItem extends AtContextItemBase {
|
|
166
|
+
kind: 'file';
|
|
167
|
+
path: string;
|
|
168
|
+
}
|
|
169
|
+
export interface AtDocumentContextItem extends AtContextItemBase {
|
|
170
|
+
kind: 'doc';
|
|
171
|
+
documentId: string;
|
|
172
|
+
source: string;
|
|
173
|
+
snippet?: string;
|
|
174
|
+
score?: number;
|
|
175
|
+
matchType?: 'exact' | 'semantic' | 'fulltext' | 'hybrid';
|
|
176
|
+
}
|
|
177
|
+
export interface AtTerminalContextItem extends AtContextItemBase {
|
|
178
|
+
kind: 'terminal';
|
|
179
|
+
sessionId: string;
|
|
180
|
+
cwd: string;
|
|
181
|
+
status: string;
|
|
182
|
+
updatedAt: string;
|
|
183
|
+
}
|
|
184
|
+
export interface AtChatContextItem extends AtContextItemBase {
|
|
185
|
+
kind: 'chat';
|
|
186
|
+
sessionId: string;
|
|
187
|
+
updatedAt: number;
|
|
188
|
+
preview?: string;
|
|
189
|
+
matchedMessageId?: string;
|
|
190
|
+
}
|
|
191
|
+
export type AtContextItem = AtFileContextItem | AtDocumentContextItem | AtTerminalContextItem | AtChatContextItem;
|
|
192
|
+
export type AtResourceKind = AtContextKind | 'directory';
|
|
193
|
+
export interface AtResourceLocator {
|
|
194
|
+
path?: string;
|
|
195
|
+
documentId?: string;
|
|
196
|
+
sessionId?: string;
|
|
197
|
+
cwd?: string;
|
|
198
|
+
messageId?: string;
|
|
199
|
+
}
|
|
200
|
+
export interface AtResourcePreview {
|
|
201
|
+
text?: string;
|
|
202
|
+
score?: number;
|
|
203
|
+
matchType?: 'exact' | 'semantic' | 'fulltext' | 'hybrid';
|
|
204
|
+
updatedAt?: string | number;
|
|
205
|
+
status?: string;
|
|
206
|
+
}
|
|
207
|
+
export interface AtResourceContent {
|
|
208
|
+
kind: 'full' | 'summary' | 'structure';
|
|
209
|
+
text: string;
|
|
210
|
+
truncated?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* 该正文在使用 TokenCounter 计数下的 token 数。
|
|
213
|
+
* 由 chat-utils 在应用 token budget 后写入,下游可据此做二次裁剪或调试展示。
|
|
214
|
+
*/
|
|
215
|
+
tokens?: number;
|
|
216
|
+
}
|
|
217
|
+
export interface AtResourceRecommendedTool {
|
|
218
|
+
alias: string;
|
|
219
|
+
displayName?: string;
|
|
220
|
+
purpose: string;
|
|
221
|
+
/** 该工具是否能继续读到资源更多正文 / 结构化内容(元信息 / 查找类为 false) */
|
|
222
|
+
canReadMore: boolean;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 文件格式能力契约 —— 整个 @ 文件链路的单一类型真相源。
|
|
226
|
+
*
|
|
227
|
+
* 同一套枚举同时被:
|
|
228
|
+
* - superx/src/shared/fileTypeCatalog.ts(在宿主侧填充具体格式表并派生默认策略)
|
|
229
|
+
* - ai-chat-shared/src/at-context-tools.ts(在前端侧按能力推荐工具)
|
|
230
|
+
* 共同使用,严禁在任何一侧再次重复声明,避免双写漂移。
|
|
231
|
+
*
|
|
232
|
+
* DocumentType 语义:
|
|
233
|
+
* - code/config/style/web/text/data → 原文按行读(super_filesystem__read)
|
|
234
|
+
* - word/pdf/excel/powerpoint/notebook → 已解析文档统一读取(super_filesystem__read)
|
|
235
|
+
* - ebook/opendocument → 同上
|
|
236
|
+
* - unknown → 只推按名搜索,不推读取
|
|
237
|
+
*/
|
|
238
|
+
export type DocumentType = 'code' | 'config' | 'style' | 'web' | 'text' | 'data' | 'word' | 'pdf' | 'excel' | 'powerpoint' | 'notebook' | 'ebook' | 'opendocument' | 'unknown';
|
|
239
|
+
export type ReadStrategy = 'line-range' | 'section' | 'page' | 'sheet-range' | 'slide' | 'cell' | 'symbol' | 'none';
|
|
240
|
+
export type SearchStrategy = 'grep' | 'document-index' | 'code-index' | 'none';
|
|
241
|
+
export type EditStrategy = 'text' | 'structured-code' | 'readonly' | 'none';
|
|
242
|
+
export interface AtResolvedFileContext {
|
|
243
|
+
title?: string;
|
|
244
|
+
content: string | null;
|
|
245
|
+
/** 文件格式分类,由宿主通过 fileTypeCatalog 解析得出 */
|
|
246
|
+
docType?: DocumentType;
|
|
247
|
+
/** 文件读取坐标能力:行 / 页 / cell / symbol 等 */
|
|
248
|
+
readStrategy?: ReadStrategy;
|
|
249
|
+
/** 文件内容搜索能力:grep / 文档索引 / 代码索引 */
|
|
250
|
+
searchStrategy?: SearchStrategy;
|
|
251
|
+
/** 文件编辑能力:文本替换 / 结构化代码 / 只读 */
|
|
252
|
+
editStrategy?: EditStrategy;
|
|
253
|
+
metadata?: Record<string, unknown>;
|
|
254
|
+
}
|
|
255
|
+
export interface AtResourceAccess {
|
|
256
|
+
/** 推荐工具里是否至少有一个能继续读到资源更多正文 / 结构化内容 */
|
|
257
|
+
canReadMore: boolean;
|
|
258
|
+
/**
|
|
259
|
+
* 资源正文当前是否还有"直读 / 直搜"通道可用。
|
|
260
|
+
* - file 资源:由 fileTypeCatalog 的 parser/readStrategy/searchStrategy 直接决定
|
|
261
|
+
* (unsupported 或 read=none + search=none 时为 false)
|
|
262
|
+
* - directory / doc / terminal / chat 等非文件资源:恒为 true
|
|
263
|
+
* 下游渲染层直接读此字段即可,无需再反推 metadata 字符串。
|
|
264
|
+
*/
|
|
265
|
+
directReadable: boolean;
|
|
266
|
+
recommendedTools: AtResourceRecommendedTool[];
|
|
267
|
+
/**
|
|
268
|
+
* 最终分配给该资源的 token 预算(预览 + 正文 + 元信息提示合计上限)。
|
|
269
|
+
* 由 chat-utils 在装配 prompt 时按全局 budget 分配得出;未开启 token budget 时为 undefined。
|
|
270
|
+
*/
|
|
271
|
+
allocatedTokens?: number;
|
|
272
|
+
}
|
|
273
|
+
export interface AtResourceDescriptor {
|
|
274
|
+
kind: AtResourceKind;
|
|
275
|
+
mention: string;
|
|
276
|
+
title: string;
|
|
277
|
+
locator: AtResourceLocator;
|
|
278
|
+
preview?: AtResourcePreview;
|
|
279
|
+
content?: AtResourceContent;
|
|
280
|
+
access: AtResourceAccess;
|
|
281
|
+
metadata?: Record<string, unknown>;
|
|
282
|
+
}
|
|
114
283
|
/** 工具信息 */
|
|
115
|
-
interface ToolInfo {
|
|
284
|
+
export interface ToolInfo {
|
|
285
|
+
name: string;
|
|
286
|
+
description: string;
|
|
287
|
+
displayName: string;
|
|
288
|
+
assetId: string;
|
|
289
|
+
source: AssetSource;
|
|
290
|
+
category: string;
|
|
291
|
+
parameters?: Record<string, unknown>;
|
|
292
|
+
outputSchema?: Record<string, unknown>;
|
|
293
|
+
errorSchema?: Record<string, unknown>;
|
|
294
|
+
approvalPolicy?: AssetApprovalPolicy;
|
|
295
|
+
sideEffectLevel?: AssetSideEffectLevel;
|
|
296
|
+
hostDependency?: AssetHostDependency;
|
|
297
|
+
}
|
|
298
|
+
export type ChatCapabilityGroupSource = AssetSource;
|
|
299
|
+
export interface ChatCapabilitySkillItem {
|
|
300
|
+
id: string;
|
|
116
301
|
name: string;
|
|
117
302
|
description: string;
|
|
303
|
+
source: AssetSource;
|
|
304
|
+
extensionId: string;
|
|
305
|
+
extensionName: string;
|
|
306
|
+
chatEnabled: boolean;
|
|
307
|
+
}
|
|
308
|
+
export interface ChatCapabilityToolItem {
|
|
309
|
+
alias: string;
|
|
310
|
+
displayName: string;
|
|
311
|
+
description: string;
|
|
312
|
+
source: AssetSource;
|
|
313
|
+
category: string;
|
|
314
|
+
extensionId: string;
|
|
315
|
+
extensionName: string;
|
|
316
|
+
runtimeInjected: boolean;
|
|
317
|
+
runtimeAvailable: boolean;
|
|
318
|
+
chatEnabled: boolean;
|
|
319
|
+
approvalPolicy?: AssetApprovalPolicy;
|
|
320
|
+
sideEffectLevel?: AssetSideEffectLevel;
|
|
321
|
+
hostDependency?: AssetHostDependency;
|
|
322
|
+
}
|
|
323
|
+
export interface ChatCapabilityMcpToolItem {
|
|
324
|
+
alias: string;
|
|
325
|
+
displayName: string;
|
|
326
|
+
description: string;
|
|
327
|
+
source: AssetSource;
|
|
328
|
+
extensionId: string;
|
|
329
|
+
extensionName: string;
|
|
330
|
+
runtimeInjected: boolean;
|
|
331
|
+
runtimeAvailable: boolean;
|
|
332
|
+
chatEnabled: boolean;
|
|
333
|
+
}
|
|
334
|
+
export interface ChatCapabilityMcpServerItem {
|
|
335
|
+
id: string;
|
|
336
|
+
name: string;
|
|
337
|
+
source: AssetSource;
|
|
338
|
+
extensionId: string;
|
|
339
|
+
extensionName: string;
|
|
340
|
+
runtimeInjected: boolean;
|
|
341
|
+
runtimeAvailable: boolean;
|
|
342
|
+
connectionStatus: McpConnectionStatus;
|
|
343
|
+
error?: string;
|
|
344
|
+
tools: ChatCapabilityMcpToolItem[];
|
|
345
|
+
}
|
|
346
|
+
export interface ChatCapabilityExtensionGroup {
|
|
347
|
+
id: string;
|
|
348
|
+
name: string;
|
|
349
|
+
source: ChatCapabilityGroupSource;
|
|
350
|
+
extensionEnabled: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Total capabilities owned by the extension, including items hidden while the
|
|
353
|
+
* extension is disabled. Renderers should use this for extension-level counts.
|
|
354
|
+
*/
|
|
355
|
+
availableCount?: number;
|
|
356
|
+
skills: ChatCapabilitySkillItem[];
|
|
357
|
+
tools: ChatCapabilityToolItem[];
|
|
358
|
+
mcpServers: ChatCapabilityMcpServerItem[];
|
|
359
|
+
}
|
|
360
|
+
export interface ChatCapabilitySnapshot {
|
|
361
|
+
extensions: ChatCapabilityExtensionGroup[];
|
|
362
|
+
}
|
|
363
|
+
export interface AgentCapabilityManifestTool {
|
|
364
|
+
alias: string;
|
|
365
|
+
displayName: string;
|
|
366
|
+
description: string;
|
|
367
|
+
kind: 'tool' | 'mcp-tool';
|
|
368
|
+
}
|
|
369
|
+
export interface AgentCapabilityManifestSkill {
|
|
370
|
+
id: string;
|
|
371
|
+
name: string;
|
|
372
|
+
description: string;
|
|
373
|
+
}
|
|
374
|
+
export interface AgentCapabilityManifestExtension {
|
|
375
|
+
id: string;
|
|
376
|
+
name: string;
|
|
377
|
+
source: string;
|
|
378
|
+
skills: AgentCapabilityManifestSkill[];
|
|
379
|
+
tools: AgentCapabilityManifestTool[];
|
|
380
|
+
}
|
|
381
|
+
export interface AgentCapabilityManifest {
|
|
382
|
+
version: '1';
|
|
383
|
+
extensions: AgentCapabilityManifestExtension[];
|
|
384
|
+
}
|
|
385
|
+
export interface ChatCapabilitySelection {
|
|
386
|
+
toolOverrides: Record<string, boolean>;
|
|
387
|
+
mcpToolOverrides: Record<string, boolean>;
|
|
388
|
+
}
|
|
389
|
+
export interface SkillEnabledItem {
|
|
390
|
+
id: string;
|
|
391
|
+
enabled: boolean;
|
|
392
|
+
}
|
|
393
|
+
export interface ChatCapabilityToolEnabledItem {
|
|
394
|
+
alias: string;
|
|
395
|
+
enabled: boolean;
|
|
396
|
+
}
|
|
397
|
+
export interface ChatCapabilityToolEnabledResult extends ChatCapabilityToolEnabledItem {
|
|
398
|
+
kind?: 'tool' | 'mcp';
|
|
399
|
+
error?: string;
|
|
118
400
|
}
|
|
119
401
|
/** 工具批准请求 */
|
|
120
|
-
interface ToolApprovalRequest {
|
|
402
|
+
export interface ToolApprovalRequest {
|
|
121
403
|
id: string;
|
|
122
404
|
name: string;
|
|
123
405
|
args: Record<string, unknown>;
|
|
124
406
|
}
|
|
125
407
|
/** 工具执行结果(executeTool 返回值) */
|
|
126
|
-
interface ToolExecutionResult {
|
|
408
|
+
export interface ToolExecutionResult {
|
|
127
409
|
success: boolean;
|
|
128
410
|
result: string;
|
|
129
411
|
error?: string;
|
|
130
412
|
/** 工具 UI 声明(成功时) */
|
|
131
|
-
ui?:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
413
|
+
ui?: ToolUI;
|
|
414
|
+
approvalPolicy?: AssetApprovalPolicy;
|
|
415
|
+
sideEffectLevel?: AssetSideEffectLevel;
|
|
416
|
+
hostDependency?: AssetHostDependency;
|
|
417
|
+
riskSummary?: string;
|
|
418
|
+
riskTags?: string[];
|
|
419
|
+
riskSignals?: string[];
|
|
420
|
+
toolError?: import('@huyooo/ai-chat-core/events').ToolError;
|
|
137
421
|
}
|
|
138
422
|
/** ASR 会话配置 */
|
|
139
|
-
interface AsrSessionConfig {
|
|
423
|
+
export interface AsrSessionConfig {
|
|
140
424
|
/** 音频格式 */
|
|
141
425
|
format?: 'pcm' | 'wav';
|
|
142
426
|
/** 采样率 */
|
|
@@ -151,7 +435,7 @@ interface AsrSessionConfig {
|
|
|
151
435
|
showUtterances?: boolean;
|
|
152
436
|
}
|
|
153
437
|
/** ASR 识别结果 */
|
|
154
|
-
interface AsrResultData {
|
|
438
|
+
export interface AsrResultData {
|
|
155
439
|
result?: {
|
|
156
440
|
text: string;
|
|
157
441
|
utterances?: Array<{
|
|
@@ -165,14 +449,13 @@ interface AsrResultData {
|
|
|
165
449
|
duration: number;
|
|
166
450
|
};
|
|
167
451
|
}
|
|
168
|
-
|
|
452
|
+
import type { ChatEvent, ModelOption } from '@huyooo/ai-chat-core';
|
|
169
453
|
/**
|
|
170
454
|
* ChatAdapter 接口
|
|
171
455
|
*
|
|
172
456
|
* 统一的聊天适配器接口,支持多种实现:
|
|
173
|
-
* - Electron IPC(ai-chat-bridge-electron)
|
|
457
|
+
* - Electron IPC(ai-chat-bridge-electron/renderer)
|
|
174
458
|
* - HTTP/SSE(ai-chat-adapter-http)
|
|
175
|
-
* - 直连(ai-chat-adapter-direct,CLI 用)
|
|
176
459
|
*
|
|
177
460
|
* 行为统一保证:无论使用哪种实现(本地直连 / HTTP / 混合),对调用方接口一致——
|
|
178
461
|
* getModels()、sendMessage()、getSessions() 等语义相同,sendMessage 产出的事件均为
|
|
@@ -180,17 +463,43 @@ interface AsrResultData {
|
|
|
180
463
|
* 不因适配器或模型而异。core 层通过契约测试(CHAT_EVENT_TYPES)保证 Orchestrator
|
|
181
464
|
* 产出合法事件。
|
|
182
465
|
*/
|
|
183
|
-
interface ChatAdapter {
|
|
466
|
+
export interface ChatAdapter {
|
|
184
467
|
/** 获取可用模型 */
|
|
185
468
|
getModels(): Promise<ModelOption[]>;
|
|
186
|
-
/**
|
|
469
|
+
/** 获取所有工具列表(用于工具设置或管理视图) */
|
|
187
470
|
getAllTools?(): Promise<ToolInfo[]>;
|
|
471
|
+
/** 获取聊天能力快照(扩展 -> 能力分类 -> 能力项) */
|
|
472
|
+
getChatCapabilitySnapshot?(): Promise<ChatCapabilitySnapshot>;
|
|
473
|
+
/** 监听聊天能力更新 */
|
|
474
|
+
onChatCapabilityUpdate?(callback: () => void): () => void;
|
|
188
475
|
/** 发送消息,返回异步迭代器 */
|
|
189
476
|
sendMessage(message: string, options?: ChatOptions, images?: string[], sessionId?: string): AsyncIterable<ChatEvent>;
|
|
190
477
|
/** 取消当前请求 */
|
|
191
478
|
cancel(): void;
|
|
192
479
|
/** 设置当前工作目录 */
|
|
193
480
|
setCwd?(dir: string): void;
|
|
481
|
+
/** 搜索可引用的文档上下文 */
|
|
482
|
+
searchAtDocuments?(query: string, options?: {
|
|
483
|
+
limit?: number;
|
|
484
|
+
}): Promise<AtDocumentContextItem[]>;
|
|
485
|
+
/** 列出可引用的终端会话 */
|
|
486
|
+
listAtTerminals?(options?: {
|
|
487
|
+
query?: string;
|
|
488
|
+
limit?: number;
|
|
489
|
+
workspaceRoot?: string;
|
|
490
|
+
}): Promise<AtTerminalContextItem[]>;
|
|
491
|
+
/** 搜索可引用的历史对话 */
|
|
492
|
+
searchAtChats?(query: string, options?: {
|
|
493
|
+
limit?: number;
|
|
494
|
+
}): Promise<AtChatContextItem[]>;
|
|
495
|
+
/** 读取可引用的文档上下文内容 */
|
|
496
|
+
readAtDocumentContext?(documentId: string): Promise<string | null>;
|
|
497
|
+
/** 读取可引用的终端上下文内容 */
|
|
498
|
+
readAtTerminalContext?(sessionId: string): Promise<string | null>;
|
|
499
|
+
/** 读取可引用的历史对话上下文内容 */
|
|
500
|
+
readAtChatContext?(sessionId: string): Promise<string | null>;
|
|
501
|
+
/** 解析 @ 文件上下文(供宿主接入高级文件解析器) */
|
|
502
|
+
resolveAtFileContext?(filePath: string): Promise<AtResolvedFileContext | null>;
|
|
194
503
|
/** 获取会话列表 */
|
|
195
504
|
getSessions(): Promise<SessionRecord[]>;
|
|
196
505
|
/** 获取单个会话 */
|
|
@@ -203,6 +512,8 @@ interface ChatAdapter {
|
|
|
203
512
|
deleteSession(id: string): Promise<void>;
|
|
204
513
|
/** 获取会话消息 */
|
|
205
514
|
getMessages(sessionId: string): Promise<MessageRecord[]>;
|
|
515
|
+
/** 分页获取会话消息(优先返回最近消息,按 sequence 升序返回当前页) */
|
|
516
|
+
getMessagesPage?(sessionId: string, params?: GetMessagesPageParams): Promise<MessagePage>;
|
|
206
517
|
/** 保存消息 */
|
|
207
518
|
saveMessage(params: SaveMessageParams): Promise<MessageRecord>;
|
|
208
519
|
/** 更新消息(增量保存) */
|
|
@@ -272,28 +583,28 @@ interface ChatAdapter {
|
|
|
272
583
|
stage: string;
|
|
273
584
|
error?: string;
|
|
274
585
|
}) => void): () => void;
|
|
275
|
-
/**
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
enabled?: boolean;
|
|
291
|
-
}): Promise<void>;
|
|
292
|
-
/** 删除 Skill */
|
|
293
|
-
deleteSkill?(id: string): Promise<void>;
|
|
294
|
-
/** 切换 Skill 启用状态 */
|
|
295
|
-
toggleSkill?(id: string): Promise<{
|
|
586
|
+
/** 批量设置 Skill 的聊天启用状态(聊天侧仅保留此能力) */
|
|
587
|
+
setSkillsChatEnabled?(items: SkillEnabledItem[]): Promise<Array<SkillEnabledItem & {
|
|
588
|
+
error?: string;
|
|
589
|
+
}>>;
|
|
590
|
+
/** 批量设置普通 Tool 的聊天启用状态(不改变扩展运行时启停) */
|
|
591
|
+
setToolsChatEnabled?(items: ChatCapabilityToolEnabledItem[]): Promise<ChatCapabilityToolEnabledResult[]>;
|
|
592
|
+
/** 批量设置 MCP Tool 的聊天启用状态(不改变扩展运行时启停) */
|
|
593
|
+
setMcpToolsChatEnabled?(items: ChatCapabilityToolEnabledItem[]): Promise<ChatCapabilityToolEnabledResult[]>;
|
|
594
|
+
/**
|
|
595
|
+
* 设置扩展的整体启停状态(Layer 1:影响 ChatRuntime 的 sessionTools)。
|
|
596
|
+
* 对比 setSkillsChatEnabled / setToolsChatEnabled,这里是"容器级"开关:
|
|
597
|
+
* 禁用扩展会让其所有 tool/skill/mcp 从会话工具集里卸下,直接减少 token 占用。
|
|
598
|
+
*/
|
|
599
|
+
setExtensionEnabled?(payload: {
|
|
600
|
+
id: string;
|
|
296
601
|
enabled: boolean;
|
|
602
|
+
source: AssetSource;
|
|
603
|
+
}): Promise<{
|
|
604
|
+
ok: true;
|
|
605
|
+
} | {
|
|
606
|
+
ok: false;
|
|
607
|
+
error: string;
|
|
297
608
|
}>;
|
|
298
609
|
onToolApprovalRequest?(callback: (request: ToolApprovalRequest) => void): () => void;
|
|
299
610
|
respondToolApproval?(id: string, approved: boolean): Promise<void>;
|
|
@@ -333,7 +644,7 @@ interface ChatAdapter {
|
|
|
333
644
|
openExternal?(url: string): Promise<void>;
|
|
334
645
|
}
|
|
335
646
|
/** 创建会话参数 */
|
|
336
|
-
interface CreateSessionParams {
|
|
647
|
+
export interface CreateSessionParams {
|
|
337
648
|
title?: string;
|
|
338
649
|
model?: string;
|
|
339
650
|
mode?: string;
|
|
@@ -342,7 +653,7 @@ interface CreateSessionParams {
|
|
|
342
653
|
hidden?: boolean;
|
|
343
654
|
}
|
|
344
655
|
/** 更新会话参数 */
|
|
345
|
-
interface UpdateSessionParams {
|
|
656
|
+
export interface UpdateSessionParams {
|
|
346
657
|
title?: string;
|
|
347
658
|
model?: string;
|
|
348
659
|
mode?: string;
|
|
@@ -351,32 +662,47 @@ interface UpdateSessionParams {
|
|
|
351
662
|
hidden?: boolean;
|
|
352
663
|
}
|
|
353
664
|
/** 保存消息参数 */
|
|
354
|
-
interface SaveMessageParams {
|
|
665
|
+
export interface SaveMessageParams {
|
|
355
666
|
id?: string;
|
|
356
667
|
sessionId: string;
|
|
357
|
-
role: 'user' | 'assistant';
|
|
668
|
+
role: 'user' | 'assistant' | 'system';
|
|
358
669
|
content: string;
|
|
670
|
+
atContextItems?: AtContextItem[];
|
|
359
671
|
images?: string[];
|
|
360
672
|
model?: string;
|
|
361
673
|
mode?: string;
|
|
362
674
|
webSearchEnabled?: boolean;
|
|
363
675
|
thinkingEnabled?: boolean;
|
|
364
|
-
|
|
676
|
+
parts?: MessagePartInput[];
|
|
365
677
|
operationIds?: string;
|
|
678
|
+
finishReason?: FinishReason;
|
|
366
679
|
}
|
|
367
680
|
/** 更新消息参数 */
|
|
368
|
-
interface UpdateMessageParams {
|
|
681
|
+
export interface UpdateMessageParams {
|
|
369
682
|
id: string;
|
|
370
683
|
content?: string;
|
|
371
|
-
|
|
684
|
+
atContextItems?: AtContextItem[] | null;
|
|
685
|
+
parts?: MessagePartInput[];
|
|
372
686
|
operationIds?: string;
|
|
373
687
|
/** Token 使用统计(JSON 字符串) */
|
|
374
688
|
usage?: string;
|
|
375
689
|
/** 响应耗时(毫秒) */
|
|
376
690
|
duration?: number;
|
|
691
|
+
/** 结束原因(done 事件携带) */
|
|
692
|
+
finishReason?: FinishReason;
|
|
693
|
+
}
|
|
694
|
+
export interface MessagePartRecord {
|
|
695
|
+
messageId: string;
|
|
696
|
+
sequence: number;
|
|
697
|
+
type: string;
|
|
698
|
+
payload: string;
|
|
699
|
+
}
|
|
700
|
+
export interface MessagePartInput {
|
|
701
|
+
type: string;
|
|
702
|
+
payload: string;
|
|
377
703
|
}
|
|
378
704
|
/** 发送消息参数 */
|
|
379
|
-
interface SendMessageParams {
|
|
705
|
+
export interface SendMessageParams {
|
|
380
706
|
message: string;
|
|
381
707
|
images?: string[];
|
|
382
708
|
sessionId?: string;
|
|
@@ -390,5 +716,5 @@ interface SendMessageParams {
|
|
|
390
716
|
history?: ChatHistoryMessage[];
|
|
391
717
|
};
|
|
392
718
|
}
|
|
393
|
-
|
|
394
|
-
|
|
719
|
+
export { buildToolGovernanceLabels, type FrontendChatEvent, type ToolGovernanceInfo, extractToolGovernance, mergeToolGovernance, shouldSaveEvent, } from './chat-utils';
|
|
720
|
+
//# sourceMappingURL=index.d.ts.map
|