@h-ai/ai 0.1.0-alpha.67 → 0.1.0-alpha.69
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.en.md +104 -35
- package/README.ja.md +104 -35
- package/README.md +128 -36
- package/dist/ai-audio-types-4R5yUAVl.d.ts +614 -0
- package/dist/ai-audio-ws-protocol-nfhO0tOo.d.ts +7605 -0
- package/dist/browser.d.ts +6 -6
- package/dist/browser.js +3 -3
- package/dist/chunk-GMQFIWND.js +254 -0
- package/dist/chunk-GMQFIWND.js.map +1 -0
- package/dist/{chunk-Q7NORWP4.js → chunk-HEVXR252.js} +236 -15
- package/dist/chunk-HEVXR252.js.map +1 -0
- package/dist/{chunk-JC7QBT3C.js → chunk-HYMP57AC.js} +6 -2
- package/dist/chunk-HYMP57AC.js.map +1 -0
- package/dist/client/index.d.ts +38 -274
- package/dist/client/index.js +2 -2
- package/dist/index.d.ts +18 -40
- package/dist/index.js +2179 -1321
- package/dist/index.js.map +1 -1
- package/package.json +20 -8
- package/dist/ai-audio-ws-protocol-S4N8-LBa.d.ts +0 -1739
- package/dist/ai-reasoning-types-DZd_6Umd.d.ts +0 -3936
- package/dist/chunk-7SMQSE4S.js +0 -578
- package/dist/chunk-7SMQSE4S.js.map +0 -1
- package/dist/chunk-JC7QBT3C.js.map +0 -1
- package/dist/chunk-Q7NORWP4.js.map +0 -1
|
@@ -1,3936 +0,0 @@
|
|
|
1
|
-
import { HaiResult, HaiError } from '@h-ai/core';
|
|
2
|
-
import { CleanOptionsInput, ChunkOptionsInput } from '@h-ai/datapipe';
|
|
3
|
-
import { ZodType, z } from 'zod';
|
|
4
|
-
import { AgentCard } from '@a2a-js/sdk';
|
|
5
|
-
import { AgentExecutor } from '@a2a-js/sdk/server';
|
|
6
|
-
import OpenAI from 'openai';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @h-ai/ai — Store 存储抽象类型
|
|
10
|
-
*
|
|
11
|
-
* 定义统一的键值式 CRUD + 查询接口,所有需要状态持久化的子系统通过此接口存取数据。
|
|
12
|
-
* @module ai-store-types
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* 存储作用域——用于索引列加速查询
|
|
16
|
-
*
|
|
17
|
-
* 在 save 时传入 scope,值将写入独立索引列(object_id / session_id),
|
|
18
|
-
* 后续 query / removeBy 可通过 StoreFilter.objectId / sessionId 使用索引过滤。
|
|
19
|
-
*/
|
|
20
|
-
interface StoreScope {
|
|
21
|
-
/** 交互主体 ID(写入 object_id 索引列) */
|
|
22
|
-
objectId?: string;
|
|
23
|
-
/** 会话 ID(写入 session_id 索引列) */
|
|
24
|
-
sessionId?: string;
|
|
25
|
-
/** 状态(写入 status 索引列) */
|
|
26
|
-
status?: string;
|
|
27
|
-
/** 引用 ID(写入 ref_id 索引列,关联外部实体) */
|
|
28
|
-
refId?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* where 条件中单个字段的值——纯值表示等值匹配,对象表示操作符
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* // 等值:type === 'fact'
|
|
36
|
-
* { type: 'fact' }
|
|
37
|
-
*
|
|
38
|
-
* // IN:type ∈ ['fact', 'preference']
|
|
39
|
-
* { type: { $in: ['fact', 'preference'] } }
|
|
40
|
-
*
|
|
41
|
-
* // 范围:importance >= 0.5
|
|
42
|
-
* { importance: { $gte: 0.5 } }
|
|
43
|
-
*
|
|
44
|
-
* // 组合:objectId === 'user-1' AND type ∈ ['fact'] AND importance >= 0.3
|
|
45
|
-
* { objectId: 'user-1', type: { $in: ['fact'] }, importance: { $gte: 0.3 } }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
interface WhereOperator<V> {
|
|
49
|
-
/** 值在给定列表中(IN 语义) */
|
|
50
|
-
$in?: V[];
|
|
51
|
-
/** 大于等于 */
|
|
52
|
-
$gte?: V;
|
|
53
|
-
/** 大于 */
|
|
54
|
-
$gt?: V;
|
|
55
|
-
/** 小于等于 */
|
|
56
|
-
$lte?: V;
|
|
57
|
-
/** 小于 */
|
|
58
|
-
$lt?: V;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 单字段条件:纯值 = 等值匹配,WhereOperator 对象 = 操作符匹配
|
|
62
|
-
*/
|
|
63
|
-
type WhereValue<V> = V | WhereOperator<V>;
|
|
64
|
-
/**
|
|
65
|
-
* where 子句类型——每个字段可以是等值匹配或操作符对象
|
|
66
|
-
*/
|
|
67
|
-
type WhereClause<T> = {
|
|
68
|
-
[K in keyof T]?: WhereValue<T[K]>;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* 存储查询过滤条件
|
|
72
|
-
*
|
|
73
|
-
* @typeParam T - 记录类型
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* // 等值匹配(兼容旧写法)
|
|
78
|
-
* store.query({ where: { type: 'fact', objectId: 'user-1' } })
|
|
79
|
-
*
|
|
80
|
-
* // 操作符匹配
|
|
81
|
-
* store.query({ where: { type: { $in: ['fact', 'preference'] }, importance: { $gte: 0.5 } } })
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
interface StoreFilter<T> {
|
|
85
|
-
/** 字段匹配条件(等值或操作符) */
|
|
86
|
-
where?: WhereClause<T>;
|
|
87
|
-
/** 按 object_id 索引列过滤(需要 AIRelStoreOptions.hasObjectId 启用) */
|
|
88
|
-
objectId?: string;
|
|
89
|
-
/** 按 session_id 索引列过滤(需要 AIRelStoreOptions.hasSessionId 启用) */
|
|
90
|
-
sessionId?: string;
|
|
91
|
-
/** 按 status 索引列过滤(需要 AIRelStoreOptions.hasStatus 启用,支持单值或多值 IN 匹配) */
|
|
92
|
-
status?: string | string[];
|
|
93
|
-
/** 按 ref_id 索引列过滤(需要 AIRelStoreOptions.hasRefId 启用) */
|
|
94
|
-
refId?: string;
|
|
95
|
-
/**
|
|
96
|
-
* 按业务作用域过滤(`data.scope` JSON 字段的 key-value 包含匹配)。
|
|
97
|
-
*
|
|
98
|
-
* 仅在 PostgreSQL 上下推为 `data @> ?::jsonb`(配合 GIN 索引加速);
|
|
99
|
-
* SQLite / MySQL 上为 no-op(不影响结果,由调用方在内存中完成 scope 匹配)。
|
|
100
|
-
*/
|
|
101
|
-
scope?: Record<string, unknown>;
|
|
102
|
-
/** 排序 */
|
|
103
|
-
orderBy?: {
|
|
104
|
-
field: keyof T;
|
|
105
|
-
direction: 'asc' | 'desc';
|
|
106
|
-
};
|
|
107
|
-
/** 数量限制 */
|
|
108
|
-
limit?: number;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* 分页查询结果
|
|
112
|
-
*/
|
|
113
|
-
interface StorePage<T> {
|
|
114
|
-
/** 当前页数据 */
|
|
115
|
-
items: T[];
|
|
116
|
-
/** 总记录数 */
|
|
117
|
-
total: number;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* AIRelStore 配置选项
|
|
121
|
-
*
|
|
122
|
-
* 控制存储实例需要创建哪些索引列(object_id / session_id / status / ref_id)。
|
|
123
|
-
*/
|
|
124
|
-
interface AIRelStoreOptions {
|
|
125
|
-
/** 是否创建 object_id 索引列 */
|
|
126
|
-
hasObjectId?: boolean;
|
|
127
|
-
/** 是否创建 session_id 索引列 */
|
|
128
|
-
hasSessionId?: boolean;
|
|
129
|
-
/** 是否创建 status 索引列 */
|
|
130
|
-
hasStatus?: boolean;
|
|
131
|
-
/** 是否创建 ref_id 索引列 */
|
|
132
|
-
hasRefId?: boolean;
|
|
133
|
-
/**
|
|
134
|
-
* 是否为业务作用域(记录内 `data.scope` JSON 字段)建立索引以加速 scope 过滤。
|
|
135
|
-
*
|
|
136
|
-
* 仅 PostgreSQL 生效:在 JSONB `data` 列上建 GIN 索引,配合 `StoreFilter.scope`
|
|
137
|
-
* 的 `data @> ?::jsonb` 包含查询下推,避免加载全部候选再在内存过滤。
|
|
138
|
-
* SQLite / MySQL 不建索引,`scope` 过滤退回调用方内存匹配(当前行为不变)。
|
|
139
|
-
*/
|
|
140
|
-
hasScopeIndex?: boolean;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* AI 关系存储适配器
|
|
144
|
-
*
|
|
145
|
-
* 提供统一的 KV 式 CRUD + 查询能力,由 AIStoreProvider 创建具体实现。
|
|
146
|
-
*
|
|
147
|
-
* @typeParam T - 记录类型
|
|
148
|
-
*/
|
|
149
|
-
interface AIRelStore<T> {
|
|
150
|
-
/** 保存一条记录(upsert 语义) */
|
|
151
|
-
save: (id: string, data: T, scope?: StoreScope) => Promise<void>;
|
|
152
|
-
/** 批量保存 */
|
|
153
|
-
saveMany: (items: Array<{
|
|
154
|
-
id: string;
|
|
155
|
-
data: T;
|
|
156
|
-
scope?: StoreScope;
|
|
157
|
-
}>) => Promise<void>;
|
|
158
|
-
/** 按 ID 获取 */
|
|
159
|
-
get: (id: string) => Promise<T | undefined>;
|
|
160
|
-
/** 按条件查询 */
|
|
161
|
-
query: (filter: StoreFilter<T>) => Promise<T[]>;
|
|
162
|
-
/** 分页查询 */
|
|
163
|
-
queryPage: (filter: StoreFilter<T>, page: {
|
|
164
|
-
offset: number;
|
|
165
|
-
limit: number;
|
|
166
|
-
}) => Promise<StorePage<T>>;
|
|
167
|
-
/** 删除一条记录 */
|
|
168
|
-
remove: (id: string) => Promise<boolean>;
|
|
169
|
-
/** 按条件删除 */
|
|
170
|
-
removeBy: (filter: StoreFilter<T>) => Promise<number>;
|
|
171
|
-
/** 计数 */
|
|
172
|
-
count: (filter?: StoreFilter<T>) => Promise<number>;
|
|
173
|
-
/** 清空(可选按条件) */
|
|
174
|
-
clear: (filter?: StoreFilter<T>) => Promise<void>;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* AI 向量存储适配器
|
|
178
|
-
*
|
|
179
|
-
* 专用于需要向量检索的场景(如 Memory),由 AIStoreProvider 创建具体实现。
|
|
180
|
-
*/
|
|
181
|
-
interface AIVectorStore {
|
|
182
|
-
/** 存储向量 */
|
|
183
|
-
upsert: (id: string, vector: number[], metadata?: Record<string, unknown>) => Promise<void>;
|
|
184
|
-
/** 向量相似度检索 */
|
|
185
|
-
search: (vector: number[], options?: {
|
|
186
|
-
topK?: number;
|
|
187
|
-
minScore?: number;
|
|
188
|
-
filter?: Record<string, unknown>;
|
|
189
|
-
}) => Promise<Array<{
|
|
190
|
-
id: string;
|
|
191
|
-
score: number;
|
|
192
|
-
content?: string;
|
|
193
|
-
metadata?: Record<string, unknown>;
|
|
194
|
-
}>>;
|
|
195
|
-
/** 删除向量 */
|
|
196
|
-
remove: (id: string) => Promise<void>;
|
|
197
|
-
/** 清空 */
|
|
198
|
-
clear: (filter?: Record<string, unknown>) => Promise<void>;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* 交互主体引用
|
|
202
|
-
*
|
|
203
|
-
* 代表"和谁"交互 — 可以是人、AI Agent、或系统自身。
|
|
204
|
-
*/
|
|
205
|
-
interface ObjectRef {
|
|
206
|
-
/** 主体唯一 ID */
|
|
207
|
-
objectId: string;
|
|
208
|
-
/** 主体类型 */
|
|
209
|
-
objectType?: 'human' | 'agent' | 'system';
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* 完整的交互作用域 = Object + Session
|
|
213
|
-
*/
|
|
214
|
-
interface InteractionScope {
|
|
215
|
-
/** 交互主体 ID */
|
|
216
|
-
objectId: string;
|
|
217
|
-
/** 会话 ID */
|
|
218
|
-
sessionId: string;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* 会话信息
|
|
222
|
-
*/
|
|
223
|
-
interface SessionInfo {
|
|
224
|
-
/** 会话 ID */
|
|
225
|
-
sessionId: string;
|
|
226
|
-
/** 所属主体 ID */
|
|
227
|
-
objectId: string;
|
|
228
|
-
/** 会话标题 */
|
|
229
|
-
title?: string;
|
|
230
|
-
/** 创建时间(Unix 毫秒) */
|
|
231
|
-
createdAt: number;
|
|
232
|
-
/** 更新时间(Unix 毫秒) */
|
|
233
|
-
updatedAt: number;
|
|
234
|
-
/** 附加元数据 */
|
|
235
|
-
metadata?: Record<string, unknown>;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Knowledge 专用存储接口
|
|
239
|
-
*
|
|
240
|
-
* 封装知识库的实体索引、文档元数据和向量操作。
|
|
241
|
-
* 默认实现使用 reldb 归一化表 + vecdb 向量检索;
|
|
242
|
-
* SaaS 实现可对接远端知识库 API。
|
|
243
|
-
*/
|
|
244
|
-
interface KnowledgeStore {
|
|
245
|
-
/** 初始化存储(建表 / 建集合 / 建索引,幂等) */
|
|
246
|
-
initialize: (collection: string, dimension: number) => Promise<void>;
|
|
247
|
-
/** 插入或更新实体 */
|
|
248
|
-
upsertEntity: (entity: {
|
|
249
|
-
id: string;
|
|
250
|
-
name: string;
|
|
251
|
-
type: string;
|
|
252
|
-
collection: string;
|
|
253
|
-
aliases?: string[];
|
|
254
|
-
description?: string;
|
|
255
|
-
}) => Promise<void>;
|
|
256
|
-
/** 按名称模糊搜索实体(匹配 name 和 aliases,可按 collection 过滤) */
|
|
257
|
-
findEntitiesByName: (keyword: string, collection?: string) => Promise<Array<{
|
|
258
|
-
id: string;
|
|
259
|
-
name: string;
|
|
260
|
-
type: string;
|
|
261
|
-
aliases: string[];
|
|
262
|
-
}>>;
|
|
263
|
-
/** 列出实体(支持 collection / 类型 / 关键词搜索) */
|
|
264
|
-
listEntities: (options?: {
|
|
265
|
-
collection?: string;
|
|
266
|
-
type?: string;
|
|
267
|
-
keyword?: string;
|
|
268
|
-
limit?: number;
|
|
269
|
-
}) => Promise<Array<{
|
|
270
|
-
id: string;
|
|
271
|
-
name: string;
|
|
272
|
-
type: string;
|
|
273
|
-
aliases: string[];
|
|
274
|
-
description: string | null;
|
|
275
|
-
createdAt: string | null;
|
|
276
|
-
updatedAt: string | null;
|
|
277
|
-
}>>;
|
|
278
|
-
/** 批量删除实体本体 */
|
|
279
|
-
deleteEntities: (entityIds: string[]) => Promise<void>;
|
|
280
|
-
/**
|
|
281
|
-
* 删除指定文档在指定 collection 中的所有实体本体
|
|
282
|
-
*
|
|
283
|
-
* 使用子查询,必须在 removeDocumentEntityRelations 之前调用(关联行删除后子查询结果为空)。
|
|
284
|
-
* removeDocument 使用此方法完成实体数据闭环,无需两步查询。
|
|
285
|
-
*/
|
|
286
|
-
deleteDocumentEntities: (documentId: string, collection: string) => Promise<void>;
|
|
287
|
-
/** 插入文档-实体关联 */
|
|
288
|
-
insertEntityDocument: (relation: {
|
|
289
|
-
entityId: string;
|
|
290
|
-
documentId: string;
|
|
291
|
-
chunkId?: string;
|
|
292
|
-
collection: string;
|
|
293
|
-
relevance?: number;
|
|
294
|
-
context?: string;
|
|
295
|
-
}) => Promise<void>;
|
|
296
|
-
/** 按实体 ID 列表查询关联文档 */
|
|
297
|
-
findDocumentsByEntityIds: (entityIds: string[], collection?: string) => Promise<Array<{
|
|
298
|
-
entityId: string;
|
|
299
|
-
documentId: string;
|
|
300
|
-
chunkId: string;
|
|
301
|
-
collection: string;
|
|
302
|
-
relevance: number;
|
|
303
|
-
context: string | null;
|
|
304
|
-
}>>;
|
|
305
|
-
/** 按实体名称查询实体及其关联文档 */
|
|
306
|
-
findByEntityName: (entityName: string, options?: {
|
|
307
|
-
collection?: string;
|
|
308
|
-
type?: string;
|
|
309
|
-
}) => Promise<Array<{
|
|
310
|
-
entity: {
|
|
311
|
-
id: string;
|
|
312
|
-
name: string;
|
|
313
|
-
type: string;
|
|
314
|
-
aliases: string[];
|
|
315
|
-
description: string | null;
|
|
316
|
-
};
|
|
317
|
-
documents: Array<{
|
|
318
|
-
documentId: string;
|
|
319
|
-
chunkId: string;
|
|
320
|
-
collection: string;
|
|
321
|
-
relevance: number;
|
|
322
|
-
context: string | null;
|
|
323
|
-
}>;
|
|
324
|
-
}>>;
|
|
325
|
-
/**
|
|
326
|
-
* 删除文档相关的实体关联行
|
|
327
|
-
*
|
|
328
|
-
* 仅删除 entity_document 关联行,不删除实体本体。
|
|
329
|
-
* 调用前应先执行 deleteDocumentEntities,否则子查询结果为空导致实体无法清理。
|
|
330
|
-
*/
|
|
331
|
-
removeDocumentEntityRelations: (documentId: string, collection: string) => Promise<void>;
|
|
332
|
-
/** 保存文档元数据 */
|
|
333
|
-
upsertDocument: (doc: {
|
|
334
|
-
documentId: string;
|
|
335
|
-
collection: string;
|
|
336
|
-
title?: string;
|
|
337
|
-
url?: string;
|
|
338
|
-
chunkCount: number;
|
|
339
|
-
createdAt: number;
|
|
340
|
-
}) => Promise<void>;
|
|
341
|
-
/** 按 documentId + collection 获取单个文档元数据 */
|
|
342
|
-
getDocument: (documentId: string, collection: string) => Promise<{
|
|
343
|
-
documentId: string;
|
|
344
|
-
collection: string;
|
|
345
|
-
title: string | null;
|
|
346
|
-
url: string | null;
|
|
347
|
-
chunkCount: number;
|
|
348
|
-
createdAt: number;
|
|
349
|
-
} | undefined>;
|
|
350
|
-
/** 列出文档元数据 */
|
|
351
|
-
listDocuments: (collection: string, options?: {
|
|
352
|
-
offset?: number;
|
|
353
|
-
limit?: number;
|
|
354
|
-
}) => Promise<Array<{
|
|
355
|
-
documentId: string;
|
|
356
|
-
collection: string;
|
|
357
|
-
title: string | null;
|
|
358
|
-
url: string | null;
|
|
359
|
-
chunkCount: number;
|
|
360
|
-
createdAt: number;
|
|
361
|
-
}>>;
|
|
362
|
-
/** 查询每个文档的实体关联数 */
|
|
363
|
-
listDocumentEntityCounts: (documentIds: string[], collection: string) => Promise<Map<string, number>>;
|
|
364
|
-
/** 删除文档元数据 */
|
|
365
|
-
removeDocument: (documentId: string, collection: string) => Promise<void>;
|
|
366
|
-
/** 批量写入向量 */
|
|
367
|
-
upsertVectors: (collection: string, vectors: Array<{
|
|
368
|
-
id: string;
|
|
369
|
-
vector: number[];
|
|
370
|
-
content?: string;
|
|
371
|
-
metadata?: Record<string, unknown>;
|
|
372
|
-
}>) => Promise<void>;
|
|
373
|
-
/** 向量相似度检索 */
|
|
374
|
-
searchVectors: (collection: string, vector: number[], options?: {
|
|
375
|
-
topK?: number;
|
|
376
|
-
minScore?: number;
|
|
377
|
-
filter?: Record<string, unknown>;
|
|
378
|
-
}) => Promise<Array<{
|
|
379
|
-
id: string;
|
|
380
|
-
score: number;
|
|
381
|
-
content?: string;
|
|
382
|
-
metadata?: Record<string, unknown>;
|
|
383
|
-
}>>;
|
|
384
|
-
/** 批量删除向量 */
|
|
385
|
-
removeVectors: (collection: string, ids: string[]) => Promise<void>;
|
|
386
|
-
/** 确保向量集合存在 */
|
|
387
|
-
ensureCollection: (collection: string, dimension: number) => Promise<void>;
|
|
388
|
-
/** 注册 collection(setup 时持久化,幂等) */
|
|
389
|
-
registerCollection: (collection: string, dimension: number) => Promise<void>;
|
|
390
|
-
/** 检查 collection 是否已在注册表中存在(跨节点/重启后仍有效) */
|
|
391
|
-
collectionExists: (collection: string) => Promise<boolean>;
|
|
392
|
-
/**
|
|
393
|
-
* 删除整个 collection(清理 vecdb 集合 + 所有 reldb 关联数据)
|
|
394
|
-
* 幂等:collection 不存在时静默成功
|
|
395
|
-
*/
|
|
396
|
-
deleteCollection: (collection: string) => Promise<void>;
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* 向量库后端连接信息
|
|
400
|
-
*
|
|
401
|
-
* 由 Provider 暴露底层向量库的原始连接,供需要复用同一后端的外部引擎(如 mem0 OSS)
|
|
402
|
-
* 直连。字段按后端类型填充;包含凭证,仅供同进程内集成使用。
|
|
403
|
-
*/
|
|
404
|
-
interface AIVectorBackend {
|
|
405
|
-
/** 后端类型(如 'qdrant'、'pgvector'、'lancedb'、'chroma') */
|
|
406
|
-
type: string;
|
|
407
|
-
/** 服务 URL(qdrant / chroma) */
|
|
408
|
-
url?: string;
|
|
409
|
-
/** API Key(qdrant / chroma) */
|
|
410
|
-
apiKey?: string;
|
|
411
|
-
/** 主机(pgvector) */
|
|
412
|
-
host?: string;
|
|
413
|
-
/** 端口(pgvector / chroma) */
|
|
414
|
-
port?: number;
|
|
415
|
-
/** 数据库名(pgvector) */
|
|
416
|
-
database?: string;
|
|
417
|
-
/** 用户名(pgvector) */
|
|
418
|
-
user?: string;
|
|
419
|
-
/** 密码(pgvector) */
|
|
420
|
-
password?: string;
|
|
421
|
-
/** 连接串(pgvector) */
|
|
422
|
-
connectionString?: string;
|
|
423
|
-
/** 本地路径(lancedb / chroma 嵌入式) */
|
|
424
|
-
path?: string;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* AI 存储 Provider 接口
|
|
428
|
-
*
|
|
429
|
-
* 负责创建 AIRelStore / AIVectorStore 实例,并管理存储层生命周期。
|
|
430
|
-
* reldb + vecdb 已初始化时默认使用持久化 DB 实现,否则使用进程内临时实现;
|
|
431
|
-
* 也可对接 SaaS API 或其他后端。
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```ts
|
|
435
|
-
* await ai.init(config, { storeProvider: myProvider })
|
|
436
|
-
* ```
|
|
437
|
-
*/
|
|
438
|
-
interface AIStoreProvider {
|
|
439
|
-
/** Provider 名称(如 'db'、'api') */
|
|
440
|
-
readonly name: string;
|
|
441
|
-
/** 创建关系数据存储实例 */
|
|
442
|
-
createRelStore: <T>(name: string, options?: AIRelStoreOptions) => AIRelStore<T>;
|
|
443
|
-
/** 创建向量数据存储实例 */
|
|
444
|
-
createVectorStore: (name: string) => AIVectorStore;
|
|
445
|
-
/**
|
|
446
|
-
* 暴露底层向量库后端连接(可选)
|
|
447
|
-
*
|
|
448
|
-
* 供需要直连同一向量库的外部引擎(如 mem0 OSS)复用后端。未初始化或不支持时返回
|
|
449
|
-
* `undefined`。返回值含凭证,仅供同进程内集成使用,禁止写入日志。
|
|
450
|
-
*/
|
|
451
|
-
getVectorBackend?: () => AIVectorBackend | undefined;
|
|
452
|
-
/**
|
|
453
|
-
* 创建 knowledge 专用存储(可选)
|
|
454
|
-
*
|
|
455
|
-
* 如果 Provider 不提供此方法,knowledge 子系统将不可用。
|
|
456
|
-
* 默认 db Provider 提供基于 reldb 归一化表 + vecdb 的高效实现。
|
|
457
|
-
*/
|
|
458
|
-
createKnowledgeStore?: () => KnowledgeStore;
|
|
459
|
-
/**
|
|
460
|
-
* 初始化所有已创建的存储(建表、建连接等)
|
|
461
|
-
*
|
|
462
|
-
* 由 ai.init() 在创建完所有 store 实例后统一调用。
|
|
463
|
-
*/
|
|
464
|
-
initialize: () => Promise<void>;
|
|
465
|
-
/** 关闭所有存储(释放连接等),由 ai.close() 调用 */
|
|
466
|
-
close?: () => Promise<void>;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* @h-ai/ai — LLM 子功能类型
|
|
471
|
-
*
|
|
472
|
-
* 定义 LLM 消息、请求、响应、流、工具等公共类型。
|
|
473
|
-
* @module ai-llm-types
|
|
474
|
-
*/
|
|
475
|
-
|
|
476
|
-
/** 消息角色枚举:`'system'` | `'developer'` | `'user'` | `'assistant'` | `'tool'` */
|
|
477
|
-
type MessageRole = 'system' | 'developer' | 'user' | 'assistant' | 'tool';
|
|
478
|
-
/** 文本内容块(多模态消息中的纯文本部分) */
|
|
479
|
-
type TextContent = OpenAI.Chat.Completions.ChatCompletionContentPartText;
|
|
480
|
-
/** 图片内容块(多模态消息中的图片部分) */
|
|
481
|
-
type ImageContent = OpenAI.Chat.Completions.ChatCompletionContentPartImage;
|
|
482
|
-
/** 消息内容(纯文本字符串,或由内容块组成的多模态数组) */
|
|
483
|
-
type MessageContent = string | OpenAI.Chat.Completions.ChatCompletionContentPart[];
|
|
484
|
-
/** 系统消息,用于设定对话的行为规则 */
|
|
485
|
-
type SystemMessage = OpenAI.Chat.Completions.ChatCompletionSystemMessageParam;
|
|
486
|
-
/** 开发者消息(高优先级运行时约束) */
|
|
487
|
-
interface DeveloperMessage {
|
|
488
|
-
role: 'developer';
|
|
489
|
-
content: string | TextContent[];
|
|
490
|
-
name?: string;
|
|
491
|
-
}
|
|
492
|
-
/** 用户消息 */
|
|
493
|
-
type UserMessage = OpenAI.Chat.Completions.ChatCompletionUserMessageParam;
|
|
494
|
-
/** 工具调用描述,由助手消息中的 `tool_calls` 字段携带 */
|
|
495
|
-
type ToolCall = OpenAI.Chat.Completions.ChatCompletionMessageToolCall;
|
|
496
|
-
/** 助手消息(模型生成的回复,或传入对话上下文的助手轮次) */
|
|
497
|
-
type AssistantMessage = OpenAI.Chat.Completions.ChatCompletionAssistantMessageParam & {
|
|
498
|
-
/**
|
|
499
|
-
* 推理模型额外返回的思维链内容。
|
|
500
|
-
*
|
|
501
|
-
* DeepSeek thinking mode 在 function calling 多轮续写时要求回传该字段。
|
|
502
|
-
*/
|
|
503
|
-
reasoning_content?: string | null;
|
|
504
|
-
};
|
|
505
|
-
/** 工具消息(工具执行结果,用于回传给模型) */
|
|
506
|
-
type ToolMessage = OpenAI.Chat.Completions.ChatCompletionToolMessageParam;
|
|
507
|
-
/** 聊天消息联合类型,涵盖对话中所有角色的消息 */
|
|
508
|
-
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam | DeveloperMessage;
|
|
509
|
-
/** OpenAI function calling 工具定义格式 */
|
|
510
|
-
type ToolDefinition = OpenAI.Chat.Completions.ChatCompletionTool;
|
|
511
|
-
/**
|
|
512
|
-
* 临时模型配置
|
|
513
|
-
*
|
|
514
|
-
* 单次请求级别的临时模型端点,绕过配置中注册的模型与场景映射,
|
|
515
|
-
* 直接指定 API Key / Base URL / 模型名等参数。适用于运行时动态切换模型、
|
|
516
|
-
* 多租户各自携带凭据等场景。其客户端实例按 TTL 缓存(见 `LLMConfig.tempModelCacheTtl`),
|
|
517
|
-
* 与常驻模型客户端缓存隔离。
|
|
518
|
-
*
|
|
519
|
-
* 未指定的字段回退到全局 LLM 配置:`apiKey` / `baseUrl` 回退全局值或环境变量,
|
|
520
|
-
* `maxTokens` / `temperature` / `timeout` 回退全局默认值。
|
|
521
|
-
*/
|
|
522
|
-
interface TempModelConfig {
|
|
523
|
-
/** 模型名称(传给 API 的实际模型名) */
|
|
524
|
-
model: string;
|
|
525
|
-
/** API 协议(未指定时回退全局 `api`,再回退 `chat`;决定走 Chat Completions / Responses / Anthropic) */
|
|
526
|
-
api?: ApiType;
|
|
527
|
-
/** API Key(未指定时回退全局配置 / 环境变量) */
|
|
528
|
-
apiKey?: string;
|
|
529
|
-
/** API 基础 URL(未指定时回退全局配置 / 环境变量 / 默认 OpenAI) */
|
|
530
|
-
baseUrl?: string;
|
|
531
|
-
/** 最大 Token 数(未指定时回退全局配置;请求显式指定 `max_tokens` 时以请求为准) */
|
|
532
|
-
maxTokens?: number;
|
|
533
|
-
/** 采样温度(未指定时回退全局配置;请求显式指定 `temperature` 时以请求为准) */
|
|
534
|
-
temperature?: number;
|
|
535
|
-
/** 请求超时时间(毫秒,未指定时回退全局配置) */
|
|
536
|
-
timeout?: number;
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* 聊天完成请求参数
|
|
540
|
-
*
|
|
541
|
-
* 继承 OpenAI SDK 全部标准请求字段,并扩展框架专属字段(`objectId`、`sessionId`)。
|
|
542
|
-
* `model` 改为可选(未指定时使用配置中的默认模型)。
|
|
543
|
-
* `stream` 字段由框架内部控制,不对外暴露。
|
|
544
|
-
*/
|
|
545
|
-
type ChatCompletionRequest = Omit<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming, 'model' | 'stream' | 'messages'> & {
|
|
546
|
-
/** 对话消息列表 */
|
|
547
|
-
messages: ChatMessage[];
|
|
548
|
-
/** 模型名称(可选,未指定时使用配置中的默认模型) */
|
|
549
|
-
model?: string;
|
|
550
|
-
/** 交互主体 ID(传入后 LLM 会自动关联到该主体) */
|
|
551
|
-
objectId?: string;
|
|
552
|
-
/** 会话 ID(传入后 LLM 会自动关联到该会话) */
|
|
553
|
-
sessionId?: string;
|
|
554
|
-
/** 是否持久化对话记录(默认 true;传入 false 时跳过记录,适用于内部调用如实体提取) */
|
|
555
|
-
enablePersist?: boolean;
|
|
556
|
-
/** 临时模型配置(传入后绕过配置注册的模型,使用临时端点;优先级高于 `model`) */
|
|
557
|
-
tempModel?: TempModelConfig;
|
|
558
|
-
/**
|
|
559
|
-
* 请求取消信号
|
|
560
|
-
*
|
|
561
|
-
* 传入后透传给底层 SDK(OpenAI / Anthropic)的请求取消参数。主持人打断、
|
|
562
|
-
* 用户切换等场景可 `abortController.abort()` 立即停止上游生成与计费。
|
|
563
|
-
*/
|
|
564
|
-
signal?: AbortSignal;
|
|
565
|
-
};
|
|
566
|
-
/** Token 使用统计 */
|
|
567
|
-
type TokenUsage = OpenAI.CompletionUsage;
|
|
568
|
-
/** 聊天完成响应中的单个选择 */
|
|
569
|
-
type ChatCompletionChoice = OpenAI.Chat.ChatCompletion.Choice;
|
|
570
|
-
/** 聊天完成响应(非流式) */
|
|
571
|
-
type ChatCompletionResponse = OpenAI.Chat.ChatCompletion;
|
|
572
|
-
/** 流式增量内容(每个 chunk 中的变化部分) */
|
|
573
|
-
type ChatCompletionDelta = OpenAI.Chat.ChatCompletionChunk.Choice.Delta;
|
|
574
|
-
/** 流式响应块(SSE 传输的单个数据帧) */
|
|
575
|
-
type ChatCompletionChunk = OpenAI.Chat.ChatCompletionChunk;
|
|
576
|
-
/** 流处理结果(完整消费流后的累积数据) */
|
|
577
|
-
interface StreamResult {
|
|
578
|
-
/** 累积的完整文本内容 */
|
|
579
|
-
content: string;
|
|
580
|
-
/** 累积的完整 reasoning 内容 */
|
|
581
|
-
reasoningContent: string;
|
|
582
|
-
/** 累积的完整工具调用列表 */
|
|
583
|
-
toolCalls: ToolCall[];
|
|
584
|
-
/** 完成原因(流未结束时为 `null`) */
|
|
585
|
-
finishReason: string | null;
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* 流处理器接口
|
|
589
|
-
*
|
|
590
|
-
* 逐 chunk 喂入,内部累积文本和工具调用,支持 reset 复用。
|
|
591
|
-
*/
|
|
592
|
-
interface StreamProcessor {
|
|
593
|
-
/** 处理单个 chunk,返回增量 delta;空 choices 时返回 `null` */
|
|
594
|
-
process: (chunk: ChatCompletionChunk) => ChatCompletionDelta | null;
|
|
595
|
-
/** 获取当前累积结果(不重置状态) */
|
|
596
|
-
getResult: () => StreamResult;
|
|
597
|
-
/** 将累积结果转换为 AssistantMessage(有 tool_calls 时 content 为 `null`) */
|
|
598
|
-
toAssistantMessage: () => AssistantMessage;
|
|
599
|
-
/** 重置内部状态,可重新处理新一轮流 */
|
|
600
|
-
reset: () => void;
|
|
601
|
-
}
|
|
602
|
-
/** SSE(Server-Sent Events)事件结构 */
|
|
603
|
-
interface SSEEvent {
|
|
604
|
-
/** 事件类型(`event:` 字段) */
|
|
605
|
-
event?: string;
|
|
606
|
-
/** 事件 ID(`id:` 字段) */
|
|
607
|
-
id?: string;
|
|
608
|
-
/** 重连间隔(毫秒,`retry:` 字段) */
|
|
609
|
-
retry?: number;
|
|
610
|
-
/** 数据载荷(`data:` 字段,多行数据以 `\n` 合并) */
|
|
611
|
-
data?: string;
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* SSE 解码器接口
|
|
615
|
-
*
|
|
616
|
-
* 内部维护缓冲区,支持跨 chunk 的不完整数据拼接。
|
|
617
|
-
*/
|
|
618
|
-
interface SSEDecoder {
|
|
619
|
-
/** 追加文本并解码出完整事件;未完成的部分留在缓冲区 */
|
|
620
|
-
decode: (text: string) => Iterable<SSEEvent>;
|
|
621
|
-
/** 清空缓冲区 */
|
|
622
|
-
reset: () => void;
|
|
623
|
-
}
|
|
624
|
-
/** 流处理操作接口(通过 `ai.stream` 访问,纯函数,无需初始化) */
|
|
625
|
-
interface StreamOperations {
|
|
626
|
-
/** 创建新的流处理器实例 */
|
|
627
|
-
createProcessor: () => StreamProcessor;
|
|
628
|
-
/** 完整消费流并返回累积结果 */
|
|
629
|
-
collect: (stream: AsyncIterable<ChatCompletionChunk>) => Promise<StreamResult>;
|
|
630
|
-
/** 创建新的 SSE 解码器实例 */
|
|
631
|
-
createSSEDecoder: () => SSEDecoder;
|
|
632
|
-
/** 将 SSE 事件编码为符合规范的文本(以 `\n\n` 结尾) */
|
|
633
|
-
encodeSSE: (event: SSEEvent) => string;
|
|
634
|
-
}
|
|
635
|
-
/** 工具错误类型枚举 */
|
|
636
|
-
type ToolErrorType = 'TOOL_NOT_FOUND' | 'TOOL_ALREADY_REGISTERED' | 'VALIDATION_FAILED' | 'EXECUTION_FAILED' | 'FORBIDDEN' | 'TIMEOUT';
|
|
637
|
-
/**
|
|
638
|
-
* 工具执行上下文(传给 handler)
|
|
639
|
-
*
|
|
640
|
-
* 由框架在 `execute` / `executeAll` 时构造并透传给工具 handler,使工具能够:
|
|
641
|
-
* - 响应取消(主持人打断、上层 AbortSignal)提前中止耗时操作(DB 查询 / HTTP 请求);
|
|
642
|
-
* - 感知超时截止时间;
|
|
643
|
-
* - 获知当前交互主体 / 会话,做数据隔离或审计。
|
|
644
|
-
*
|
|
645
|
-
* `signal` 始终存在:即便调用方未传入信号,框架也会依据默认超时构造一个。
|
|
646
|
-
*/
|
|
647
|
-
interface ToolExecutionContext {
|
|
648
|
-
/** 取消信号(始终存在;结合调用方信号与超时截止) */
|
|
649
|
-
signal: AbortSignal;
|
|
650
|
-
/** 交互主体 ID(透传自 Context / Reasoning 作用域) */
|
|
651
|
-
objectId?: string;
|
|
652
|
-
/** 会话 ID(透传自 Context / Reasoning 作用域) */
|
|
653
|
-
sessionId?: string;
|
|
654
|
-
/** 截止时间(Unix 毫秒;到期自动取消) */
|
|
655
|
-
deadline?: number;
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* 工具授权请求
|
|
659
|
-
*
|
|
660
|
-
* `input` 已通过工具的 Zod schema 校验;授权函数在 handler 执行前调用。
|
|
661
|
-
*/
|
|
662
|
-
interface ToolAuthorizationRequest<TInput = unknown> {
|
|
663
|
-
/** 工具名称 */
|
|
664
|
-
toolName: string;
|
|
665
|
-
/** 已校验的工具输入 */
|
|
666
|
-
input: TInput;
|
|
667
|
-
/** 本次执行上下文 */
|
|
668
|
-
context: ToolExecutionContext;
|
|
669
|
-
}
|
|
670
|
-
/** 工具授权函数;返回 `false` 或抛出异常时均拒绝执行(fail-closed) */
|
|
671
|
-
type ToolAuthorizer = (request: ToolAuthorizationRequest) => Promise<boolean> | boolean;
|
|
672
|
-
/**
|
|
673
|
-
* 工具执行入参(调用方传给 `execute` / `executeAll`)
|
|
674
|
-
*
|
|
675
|
-
* 所有字段可选。框架据此解析出传给 handler 的 {@link ToolExecutionContext}:
|
|
676
|
-
* 组合调用方 `signal` 与超时信号,超时优先级 `deadline` > `timeoutMs` > 工具默认 > 全局默认。
|
|
677
|
-
*/
|
|
678
|
-
interface ToolExecutionOptions {
|
|
679
|
-
/** 调用方取消信号(与超时信号组合) */
|
|
680
|
-
signal?: AbortSignal;
|
|
681
|
-
/** 交互主体 ID */
|
|
682
|
-
objectId?: string;
|
|
683
|
-
/** 会话 ID */
|
|
684
|
-
sessionId?: string;
|
|
685
|
-
/** 截止时间(Unix 毫秒;优先级高于 timeoutMs) */
|
|
686
|
-
deadline?: number;
|
|
687
|
-
/** 本次执行超时(毫秒;覆盖工具默认超时) */
|
|
688
|
-
timeoutMs?: number;
|
|
689
|
-
/**
|
|
690
|
-
* 本次执行授权函数
|
|
691
|
-
*
|
|
692
|
-
* 与 Registry 级授权同时存在时必须全部通过。授权异常不会进入 handler,统一返回
|
|
693
|
-
* `TOOL_FORBIDDEN`,避免因授权服务故障而放行高风险操作。
|
|
694
|
-
*/
|
|
695
|
-
authorize?: ToolAuthorizer;
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* 工具定义选项(传给 `ai.tools.define()`)
|
|
699
|
-
*
|
|
700
|
-
* @typeParam TInput - 参数类型(由 Zod schema 推断)
|
|
701
|
-
* @typeParam TOutput - 返回值类型
|
|
702
|
-
*/
|
|
703
|
-
interface DefineToolOptions<TInput, TOutput> {
|
|
704
|
-
/** 工具名称(需唯一,用于 function calling name 字段) */
|
|
705
|
-
name: string;
|
|
706
|
-
/** 工具功能描述(供模型理解何时调用) */
|
|
707
|
-
description: string;
|
|
708
|
-
/** Zod schema,用于参数校验和 JSON Schema 转换 */
|
|
709
|
-
parameters: ZodType<TInput>;
|
|
710
|
-
/**
|
|
711
|
-
* 执行函数,接收校验后的参数与执行上下文,支持同步/异步
|
|
712
|
-
*
|
|
713
|
-
* `context.signal` 用于响应取消:长耗时操作应把它透传给 DB / HTTP 客户端,
|
|
714
|
-
* 以便打断或超时时提前中止。
|
|
715
|
-
*/
|
|
716
|
-
handler: (input: TInput, context: ToolExecutionContext) => Promise<TOutput> | TOutput;
|
|
717
|
-
/** 本工具默认执行超时(毫秒;execute 未指定 deadline/timeoutMs 时生效) */
|
|
718
|
-
timeoutMs?: number;
|
|
719
|
-
}
|
|
720
|
-
/**
|
|
721
|
-
* 工具实例(由 `ai.tools.define()` 创建)
|
|
722
|
-
*
|
|
723
|
-
* @typeParam TInput - 参数类型
|
|
724
|
-
* @typeParam TOutput - 返回值类型
|
|
725
|
-
*/
|
|
726
|
-
interface Tool<TInput = unknown, TOutput = unknown> {
|
|
727
|
-
/** 工具名称 */
|
|
728
|
-
name: string;
|
|
729
|
-
/** 工具功能描述 */
|
|
730
|
-
description: string;
|
|
731
|
-
/** Zod 参数 schema */
|
|
732
|
-
parameters: ZodType<TInput>;
|
|
733
|
-
/** 执行工具(自动校验参数),失败返回 ToolError;超时 / 取消返回 TOOL_TIMEOUT */
|
|
734
|
-
execute: (input: TInput, options?: ToolExecutionOptions) => Promise<HaiResult<TOutput>>;
|
|
735
|
-
/** 转换为 OpenAI function calling 定义格式($schema 字段已移除) */
|
|
736
|
-
toDefinition: () => ToolDefinition;
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* 工具注册表接口(由 `ai.tools.createRegistry()` 创建)
|
|
740
|
-
*
|
|
741
|
-
* 管理一组工具的注册、查询与批量执行。注册方法返回 `HaiResult<void>`,
|
|
742
|
-
* 调用方应显式处理重名等配置错误。
|
|
743
|
-
*/
|
|
744
|
-
interface ToolRegistryOperations {
|
|
745
|
-
/** 注册工具;同名工具已存在时返回 `TOOL_ALREADY_REGISTERED` */
|
|
746
|
-
register: <TInput, TOutput>(tool: Tool<TInput, TOutput>) => HaiResult<void>;
|
|
747
|
-
/** 原子批量注册;列表内或注册表内存在重名时不写入任何工具 */
|
|
748
|
-
registerMany: (tools: Tool<unknown, unknown>[]) => HaiResult<void>;
|
|
749
|
-
/** 显式替换已注册工具;目标不存在时返回 `TOOL_NOT_FOUND` */
|
|
750
|
-
replace: <TInput, TOutput>(tool: Tool<TInput, TOutput>) => HaiResult<void>;
|
|
751
|
-
/** 注销指定名称的工具,成功返回 `true`,不存在返回 `false` */
|
|
752
|
-
unregister: (name: string) => boolean;
|
|
753
|
-
/** 按名称获取工具实例,不存在返回 `undefined` */
|
|
754
|
-
get: (name: string) => Tool | undefined;
|
|
755
|
-
/** 判断指定名称的工具是否已注册 */
|
|
756
|
-
has: (name: string) => boolean;
|
|
757
|
-
/** 获取所有已注册的工具名称列表 */
|
|
758
|
-
getNames: () => string[];
|
|
759
|
-
/** 获取所有工具的 OpenAI function calling 定义(用于传入 ChatCompletionRequest.tools) */
|
|
760
|
-
getDefinitions: () => ToolDefinition[];
|
|
761
|
-
/** 执行单个工具调用,自动解析 JSON 参数并校验;失败返回 ToolError,超时 / 取消返回 TOOL_TIMEOUT */
|
|
762
|
-
execute: (toolCall: ToolCall, options?: ToolExecutionOptions) => Promise<HaiResult<ToolMessage>>;
|
|
763
|
-
/** 批量执行工具调用(默认串行),任一失败立即返回错误;仅显式 `parallel: true` 时并行 */
|
|
764
|
-
executeAll: (toolCalls: ToolCall[], options?: ToolExecutionOptions & {
|
|
765
|
-
parallel?: boolean;
|
|
766
|
-
}) => Promise<HaiResult<ToolMessage[]>>;
|
|
767
|
-
/** 清空所有已注册的工具 */
|
|
768
|
-
clear: () => void;
|
|
769
|
-
/** 当前已注册的工具数量 */
|
|
770
|
-
readonly size: number;
|
|
771
|
-
}
|
|
772
|
-
/** 工具注册表创建选项 */
|
|
773
|
-
interface ToolRegistryOptions {
|
|
774
|
-
/**
|
|
775
|
-
* Registry 级授权函数
|
|
776
|
-
*
|
|
777
|
-
* 适合统一执行租户、角色、资源归属和高风险操作确认。它不能替代 handler 内针对最终资源的
|
|
778
|
-
* 业务校验;两层校验应共同采用最小权限原则。
|
|
779
|
-
*/
|
|
780
|
-
authorize?: ToolAuthorizer;
|
|
781
|
-
}
|
|
782
|
-
/** 工具操作接口(通过 `ai.tools` 访问,纯函数,无需初始化) */
|
|
783
|
-
interface ToolsOperations {
|
|
784
|
-
/** 定义工具(Zod schema 类型推断 + 自动参数校验) */
|
|
785
|
-
define: <TInput, TOutput>(options: DefineToolOptions<TInput, TOutput>) => Tool<TInput, TOutput>;
|
|
786
|
-
/** 创建新的工具注册表实例,可注入统一授权函数 */
|
|
787
|
-
createRegistry: (options?: ToolRegistryOptions) => ToolRegistryOperations;
|
|
788
|
-
}
|
|
789
|
-
/** 对话记录查询选项 */
|
|
790
|
-
interface ChatHistoryOptions {
|
|
791
|
-
/** 返回数量限制 */
|
|
792
|
-
limit?: number;
|
|
793
|
-
/** 排序方向(默认 `'desc'` 最新在前) */
|
|
794
|
-
order?: 'asc' | 'desc';
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* ask/askStream 便捷方法选项
|
|
798
|
-
*/
|
|
799
|
-
interface AskOptions {
|
|
800
|
-
/** 系统提示词 */
|
|
801
|
-
systemPrompt?: string;
|
|
802
|
-
/** 使用的模型 */
|
|
803
|
-
model?: string;
|
|
804
|
-
/** 交互主体 ID */
|
|
805
|
-
objectId?: string;
|
|
806
|
-
/** 会话 ID */
|
|
807
|
-
sessionId?: string;
|
|
808
|
-
/** 温度(0~2) */
|
|
809
|
-
temperature?: number;
|
|
810
|
-
/** 是否持久化对话记录(默认 true;传入 false 时跳过记录) */
|
|
811
|
-
enablePersist?: boolean;
|
|
812
|
-
/** 临时模型配置(传入后绕过配置注册的模型,使用临时端点;优先级高于 `model`) */
|
|
813
|
-
tempModel?: TempModelConfig;
|
|
814
|
-
/** 请求取消信号(透传给底层 SDK,支持主动打断上游生成) */
|
|
815
|
-
signal?: AbortSignal;
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* 对话记录
|
|
819
|
-
*
|
|
820
|
-
* 每次 `llm.chat()` 调用在传入 `objectId` 时自动保存的请求+响应快照。
|
|
821
|
-
*/
|
|
822
|
-
interface ChatRecord {
|
|
823
|
-
/** 记录唯一 ID */
|
|
824
|
-
id: string;
|
|
825
|
-
/** 交互主体 ID */
|
|
826
|
-
objectId: string;
|
|
827
|
-
/** 会话 ID */
|
|
828
|
-
sessionId: string;
|
|
829
|
-
/** 请求摘要 */
|
|
830
|
-
request: {
|
|
831
|
-
model: string;
|
|
832
|
-
messages: ChatMessage[];
|
|
833
|
-
};
|
|
834
|
-
/** 响应摘要 */
|
|
835
|
-
response: {
|
|
836
|
-
content: string;
|
|
837
|
-
toolCalls?: ToolCall[];
|
|
838
|
-
finishReason: string;
|
|
839
|
-
usage: TokenUsage;
|
|
840
|
-
};
|
|
841
|
-
/** 创建时间(Unix 毫秒) */
|
|
842
|
-
createdAt: number;
|
|
843
|
-
/** 耗时(毫秒) */
|
|
844
|
-
duration: number;
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* LLM Provider 接口
|
|
848
|
-
*
|
|
849
|
-
* 底层 API 适配层,当前内置 OpenAI 兼容实现。
|
|
850
|
-
*/
|
|
851
|
-
interface LLMProvider {
|
|
852
|
-
/** 发送聊天请求并获取完整响应 */
|
|
853
|
-
chat: (request: ChatCompletionRequest) => Promise<HaiResult<ChatCompletionResponse>>;
|
|
854
|
-
/** 发送聊天请求并获取流式响应(逐 chunk 产出) */
|
|
855
|
-
chatStream: (request: ChatCompletionRequest) => AsyncIterable<ChatCompletionChunk>;
|
|
856
|
-
/** 获取可用模型列表 */
|
|
857
|
-
listModels: () => Promise<HaiResult<string[]>>;
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
* 结构化输出请求
|
|
861
|
-
*
|
|
862
|
-
* 给定 Zod schema,让模型返回严格符合结构的 JSON(内部使用 `json_schema` response_format),
|
|
863
|
-
* 解析失败时自动带错误修复重试,避免调用方手写 `JSON.parse` 的不稳定性。
|
|
864
|
-
*/
|
|
865
|
-
interface GenerateObjectRequest<T> {
|
|
866
|
-
/** 输出结构的 Zod schema */
|
|
867
|
-
schema: ZodType<T>;
|
|
868
|
-
/** 对话消息 */
|
|
869
|
-
messages: ChatMessage[];
|
|
870
|
-
/** 模型名(可选,不传时使用默认模型) */
|
|
871
|
-
model?: string;
|
|
872
|
-
/** 系统提示词(可选,追加为首条 system 消息) */
|
|
873
|
-
systemPrompt?: string;
|
|
874
|
-
/** 温度覆盖 */
|
|
875
|
-
temperature?: number;
|
|
876
|
-
/** 临时模型配置 */
|
|
877
|
-
tempModel?: TempModelConfig;
|
|
878
|
-
/** schema 名称(用于 json_schema response_format,默认 `result`) */
|
|
879
|
-
schemaName?: string;
|
|
880
|
-
/** 解析失败时的修复重试次数(默认 1) */
|
|
881
|
-
maxRepairs?: number;
|
|
882
|
-
/** 取消信号 */
|
|
883
|
-
signal?: AbortSignal;
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* LLM 操作接口(通过 `ai.llm` 访问)
|
|
887
|
-
*
|
|
888
|
-
* 需要先调用 `ai.init()` 初始化,否则返回 `NOT_INITIALIZED` 错误。
|
|
889
|
-
*/
|
|
890
|
-
interface LLMOperations {
|
|
891
|
-
/** 发送聊天请求,返回 `HaiResult<ChatCompletionResponse>` */
|
|
892
|
-
chat: (request: ChatCompletionRequest) => Promise<HaiResult<ChatCompletionResponse>>;
|
|
893
|
-
/** 发送流式聊天请求,逐 chunk 产出 `ChatCompletionChunk` */
|
|
894
|
-
chatStream: (request: ChatCompletionRequest) => AsyncIterable<ChatCompletionChunk>;
|
|
895
|
-
/** 获取可用模型名称列表 */
|
|
896
|
-
listModels: () => Promise<HaiResult<string[]>>;
|
|
897
|
-
/** 查询对话历史记录(需传入 objectId;可选 sessionId 以按会话过滤) */
|
|
898
|
-
getHistory: (scope: InteractionScope, options?: ChatHistoryOptions) => Promise<HaiResult<ChatRecord[]>>;
|
|
899
|
-
/** 列出指定 objectId 下的所有会话 */
|
|
900
|
-
listSessions: (objectId: string) => Promise<HaiResult<SessionInfo[]>>;
|
|
901
|
-
/**
|
|
902
|
-
* 便捷方法:发送纯文本问题,返回回复文本
|
|
903
|
-
*
|
|
904
|
-
* 内部构建 ChatCompletionRequest 并调用 `chat()`,只返回第一个 choice 的文本。
|
|
905
|
-
*
|
|
906
|
-
* @param question - 用户问题文本
|
|
907
|
-
* @param options - 可选的模型、systemPrompt、objectId、sessionId 等
|
|
908
|
-
* @returns 回复文本
|
|
909
|
-
*/
|
|
910
|
-
ask: (question: string, options?: AskOptions) => Promise<HaiResult<string>>;
|
|
911
|
-
/**
|
|
912
|
-
* 便捷方法:流式发送纯文本问题,返回文本片段异步迭代器
|
|
913
|
-
*
|
|
914
|
-
* @param question - 用户问题文本
|
|
915
|
-
* @param options - 可选配置
|
|
916
|
-
* @returns 文本片段的异步迭代器
|
|
917
|
-
*/
|
|
918
|
-
askStream: (question: string, options?: AskOptions) => AsyncIterable<string>;
|
|
919
|
-
/**
|
|
920
|
-
* 结构化输出:按 Zod schema 约束模型输出并解析为对象
|
|
921
|
-
*
|
|
922
|
-
* 内部使用 `json_schema` response_format 约束输出,解析/校验失败时自动带错误提示重试。
|
|
923
|
-
*
|
|
924
|
-
* @param request - 包含 schema、messages 及可选模型/修复次数等
|
|
925
|
-
* @returns 符合 schema 的对象;多次重试仍无法解析时返回 `INVALID_REQUEST`
|
|
926
|
-
*/
|
|
927
|
-
generateObject: <T>(request: GenerateObjectRequest<T>) => Promise<HaiResult<T>>;
|
|
928
|
-
}
|
|
929
|
-
/** LLM 子功能工厂依赖(内部使用) */
|
|
930
|
-
interface AILLMFunctionsDeps {
|
|
931
|
-
/** 校验后的 AI 配置 */
|
|
932
|
-
config: AIConfig;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
/**
|
|
936
|
-
* @h-ai/ai — Retrieval 子功能类型
|
|
937
|
-
*
|
|
938
|
-
* 定义检索操作的类型接口,支持向量检索和混合检索。
|
|
939
|
-
* @module ai-retrieval-types
|
|
940
|
-
*/
|
|
941
|
-
|
|
942
|
-
/**
|
|
943
|
-
* 信源引用——结构化描述检索结果的来源信息
|
|
944
|
-
*
|
|
945
|
-
* 用于在 RAG 回答中追踪每段内容的出处。
|
|
946
|
-
*
|
|
947
|
-
* @example
|
|
948
|
-
* ```ts
|
|
949
|
-
* const citation: Citation = {
|
|
950
|
-
* documentId: 'doc-001',
|
|
951
|
-
* title: '项目文档',
|
|
952
|
-
* url: 'https://docs.example.com/project',
|
|
953
|
-
* position: 'section:2',
|
|
954
|
-
* chunkId: 'chunk-003',
|
|
955
|
-
* }
|
|
956
|
-
* ```
|
|
957
|
-
*/
|
|
958
|
-
interface Citation {
|
|
959
|
-
/** 原始文档 ID(入库时的文档级唯一标识) */
|
|
960
|
-
documentId?: string;
|
|
961
|
-
/** 原始文档标题 */
|
|
962
|
-
title?: string;
|
|
963
|
-
/** 原始文档 URL / 路径 */
|
|
964
|
-
url?: string;
|
|
965
|
-
/** 位置信息(页码、段落、section 等) */
|
|
966
|
-
position?: string;
|
|
967
|
-
/** 分块 ID(对应 vecdb 中的向量记录 ID) */
|
|
968
|
-
chunkId?: string;
|
|
969
|
-
/** 信源集合名 */
|
|
970
|
-
collection?: string;
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* 检索源——描述一个可查询的知识来源
|
|
974
|
-
*/
|
|
975
|
-
interface RetrievalSource {
|
|
976
|
-
/** 来源唯一标识 */
|
|
977
|
-
id: string;
|
|
978
|
-
/** collection / table 名称 */
|
|
979
|
-
collection: string;
|
|
980
|
-
/** 信源显示名(用于 UI 展示) */
|
|
981
|
-
name?: string;
|
|
982
|
-
/** 信源 URL / 路径 */
|
|
983
|
-
url?: string;
|
|
984
|
-
/** 最大返回条数(默认 5) */
|
|
985
|
-
topK?: number;
|
|
986
|
-
/** 最低相似度(低于此值的结果被过滤) */
|
|
987
|
-
minScore?: number;
|
|
988
|
-
/** 元数据过滤条件 */
|
|
989
|
-
filter?: Record<string, unknown>;
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* 检索请求参数
|
|
993
|
-
*/
|
|
994
|
-
interface RetrievalRequest {
|
|
995
|
-
/** 查询文本 */
|
|
996
|
-
query: string;
|
|
997
|
-
/** 使用的检索源(不指定则使用全部已注册源) */
|
|
998
|
-
sources?: string[];
|
|
999
|
-
/** 全局 topK 覆盖 */
|
|
1000
|
-
topK?: number;
|
|
1001
|
-
/** 全局 minScore 覆盖 */
|
|
1002
|
-
minScore?: number;
|
|
1003
|
-
/** 是否启用 Rerank 重排序(需要已初始化 ai.rerank) */
|
|
1004
|
-
enableRerank?: boolean;
|
|
1005
|
-
/** Rerank 使用的模型名称覆盖 */
|
|
1006
|
-
rerankModel?: string;
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* 单条检索结果
|
|
1010
|
-
*/
|
|
1011
|
-
interface RetrievalResultItem {
|
|
1012
|
-
/** 文档 ID */
|
|
1013
|
-
id: string;
|
|
1014
|
-
/** 内容文本 */
|
|
1015
|
-
content: string;
|
|
1016
|
-
/** 相似度分数 [0, 1] */
|
|
1017
|
-
score: number;
|
|
1018
|
-
/** 来源 id */
|
|
1019
|
-
sourceId: string;
|
|
1020
|
-
/** 元数据 */
|
|
1021
|
-
metadata?: Record<string, unknown>;
|
|
1022
|
-
/** 结构化信源引用 */
|
|
1023
|
-
citation?: Citation;
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* 检索结果
|
|
1027
|
-
*/
|
|
1028
|
-
interface RetrievalResult {
|
|
1029
|
-
/** 检索结果列表(按分数降序) */
|
|
1030
|
-
items: RetrievalResultItem[];
|
|
1031
|
-
/** 查询文本 */
|
|
1032
|
-
query: string;
|
|
1033
|
-
/** 查询耗时(毫秒) */
|
|
1034
|
-
duration: number;
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* 检索操作接口
|
|
1038
|
-
*/
|
|
1039
|
-
interface RetrievalOperations {
|
|
1040
|
-
/**
|
|
1041
|
-
* 注册一个检索源(持久化到 DB)
|
|
1042
|
-
*
|
|
1043
|
-
* @param source - 检索源配置
|
|
1044
|
-
* @returns 成功返回 ok,重复 id 返回错误
|
|
1045
|
-
*/
|
|
1046
|
-
addSource: (source: RetrievalSource) => Promise<HaiResult<void>>;
|
|
1047
|
-
/**
|
|
1048
|
-
* 移除一个检索源(从 DB 删除)
|
|
1049
|
-
*
|
|
1050
|
-
* @param sourceId - 检索源 ID
|
|
1051
|
-
* @returns 成功返回 ok,未找到返回错误
|
|
1052
|
-
*/
|
|
1053
|
-
removeSource: (sourceId: string) => Promise<HaiResult<void>>;
|
|
1054
|
-
/**
|
|
1055
|
-
* 列出所有已注册的检索源(从 DB 读取,分布式一致)
|
|
1056
|
-
*/
|
|
1057
|
-
listSources: () => Promise<RetrievalSource[]>;
|
|
1058
|
-
/**
|
|
1059
|
-
* 执行检索
|
|
1060
|
-
*
|
|
1061
|
-
* @param request - 检索请求
|
|
1062
|
-
* @returns 检索结果
|
|
1063
|
-
*/
|
|
1064
|
-
retrieve: (request: RetrievalRequest) => Promise<HaiResult<RetrievalResult>>;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
/**
|
|
1068
|
-
* @h-ai/ai — Knowledge 子功能类型
|
|
1069
|
-
*
|
|
1070
|
-
* 定义知识库操作的类型接口:文档导入、实体索引、信源追踪检索。
|
|
1071
|
-
* @module ai-knowledge-types
|
|
1072
|
-
*/
|
|
1073
|
-
|
|
1074
|
-
/**
|
|
1075
|
-
* 内置实体类型枚举(预设值,可通过配置 `entityTypes` 扩展)
|
|
1076
|
-
*/
|
|
1077
|
-
declare const EntityTypeSchema: z.ZodEnum<{
|
|
1078
|
-
event: "event";
|
|
1079
|
-
person: "person";
|
|
1080
|
-
project: "project";
|
|
1081
|
-
concept: "concept";
|
|
1082
|
-
organization: "organization";
|
|
1083
|
-
location: "location";
|
|
1084
|
-
other: "other";
|
|
1085
|
-
}>;
|
|
1086
|
-
/** 实体类型(字符串,支持内置类型及用户自定义类型) */
|
|
1087
|
-
type EntityType = string;
|
|
1088
|
-
/**
|
|
1089
|
-
* 知识实体
|
|
1090
|
-
*
|
|
1091
|
-
* 表示从文档中提取的命名实体(人名、项目名、概念等),
|
|
1092
|
-
* 存储在 KnowledgeStore 中用于倒排索引查询。
|
|
1093
|
-
*
|
|
1094
|
-
* @example
|
|
1095
|
-
* ```ts
|
|
1096
|
-
* const entity: KnowledgeEntity = {
|
|
1097
|
-
* id: 'ent-001',
|
|
1098
|
-
* name: '张三',
|
|
1099
|
-
* type: 'person',
|
|
1100
|
-
* aliases: ['小张', 'Zhang San'],
|
|
1101
|
-
* }
|
|
1102
|
-
* ```
|
|
1103
|
-
*/
|
|
1104
|
-
interface KnowledgeEntity {
|
|
1105
|
-
/** 实体唯一标识 */
|
|
1106
|
-
id: string;
|
|
1107
|
-
/** 实体名称 */
|
|
1108
|
-
name: string;
|
|
1109
|
-
/** 实体类型 */
|
|
1110
|
-
type: EntityType;
|
|
1111
|
-
/** 别名列表(可选) */
|
|
1112
|
-
aliases?: string[];
|
|
1113
|
-
/** 描述(可选) */
|
|
1114
|
-
description?: string;
|
|
1115
|
-
/** 创建时间 */
|
|
1116
|
-
createdAt?: string;
|
|
1117
|
-
/** 更新时间 */
|
|
1118
|
-
updatedAt?: string;
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* 文档-实体关联记录
|
|
1122
|
-
*
|
|
1123
|
-
* 倒排索引中的一条记录,记录实体与文档/分块的关联关系。
|
|
1124
|
-
*/
|
|
1125
|
-
interface EntityDocumentRelation {
|
|
1126
|
-
/** 实体 ID */
|
|
1127
|
-
entityId: string;
|
|
1128
|
-
/** 文档 ID(对应向量存储中的 documentId) */
|
|
1129
|
-
documentId: string;
|
|
1130
|
-
/** 分块 ID(对应向量存储中的向量记录 ID) */
|
|
1131
|
-
chunkId?: string;
|
|
1132
|
-
/** 集合名 */
|
|
1133
|
-
collection: string;
|
|
1134
|
-
/** 关联强度 [0, 1](默认 1.0) */
|
|
1135
|
-
relevance?: number;
|
|
1136
|
-
/** 实体在该文档中的上下文片段(可选) */
|
|
1137
|
-
context?: string;
|
|
1138
|
-
/** 创建时间 */
|
|
1139
|
-
createdAt?: string;
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* 知识库初始化选项
|
|
1143
|
-
*/
|
|
1144
|
-
interface KnowledgeSetupOptions {
|
|
1145
|
-
/** 集合名(可选,默认使用配置中的 collection) */
|
|
1146
|
-
collection?: string;
|
|
1147
|
-
/** 向量维度(可选,默认使用配置中的 dimension) */
|
|
1148
|
-
dimension?: number;
|
|
1149
|
-
}
|
|
1150
|
-
/**
|
|
1151
|
-
* 文档导入输入
|
|
1152
|
-
*
|
|
1153
|
-
* @example
|
|
1154
|
-
* ```ts
|
|
1155
|
-
* const input: KnowledgeIngestInput = {
|
|
1156
|
-
* documentId: 'doc-001',
|
|
1157
|
-
* content: '# 项目文档\n\n张三负责了核心模块...',
|
|
1158
|
-
* title: '项目文档',
|
|
1159
|
-
* url: 'https://docs.example.com/project',
|
|
1160
|
-
* metadata: { author: '李四' },
|
|
1161
|
-
* }
|
|
1162
|
-
* ```
|
|
1163
|
-
*/
|
|
1164
|
-
interface KnowledgeIngestInput {
|
|
1165
|
-
/** 文档唯一标识(必填,用于关联信源和实体) */
|
|
1166
|
-
documentId: string;
|
|
1167
|
-
/** 文档原始内容文本 */
|
|
1168
|
-
content: string;
|
|
1169
|
-
/** 文档标题(可选,存入 metadata 用于信源展示) */
|
|
1170
|
-
title?: string;
|
|
1171
|
-
/** 文档 URL / 路径(可选,存入 metadata 用于信源展示) */
|
|
1172
|
-
url?: string;
|
|
1173
|
-
/** 集合名(可选,默认使用配置中的 collection) */
|
|
1174
|
-
collection?: string;
|
|
1175
|
-
/** 附加元数据(可选,合并到每个 chunk 的 metadata 中) */
|
|
1176
|
-
metadata?: Record<string, unknown>;
|
|
1177
|
-
/** 是否启用实体提取(可选,覆盖全局配置) */
|
|
1178
|
-
enableEntityExtraction?: boolean;
|
|
1179
|
-
/**
|
|
1180
|
-
* 文本清洗选项(可选,覆盖全局配置默认值)
|
|
1181
|
-
*
|
|
1182
|
-
* 字段含义与 @h-ai/datapipe CleanOptionsInput 完全一致,
|
|
1183
|
-
* 支持 removeHtml、removeUrls、normalizeWhitespace、customReplacements 等。
|
|
1184
|
-
*/
|
|
1185
|
-
cleanOptions?: CleanOptionsInput;
|
|
1186
|
-
/**
|
|
1187
|
-
* 分块选项(可选,覆盖全局配置默认值)
|
|
1188
|
-
*
|
|
1189
|
-
* 字段含义与 @h-ai/datapipe ChunkOptionsInput 完全一致,
|
|
1190
|
-
* 支持 mode、maxSize、overlap、separator、markdownMinLevel 等完整选项。
|
|
1191
|
-
*/
|
|
1192
|
-
chunkOptions?: ChunkOptionsInput;
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* 文档导入结果
|
|
1196
|
-
*/
|
|
1197
|
-
interface KnowledgeIngestResult {
|
|
1198
|
-
/** 文档 ID */
|
|
1199
|
-
documentId: string;
|
|
1200
|
-
/** 生成的分块数量 */
|
|
1201
|
-
chunkCount: number;
|
|
1202
|
-
/** 提取的实体列表(未启用实体提取时为空数组) */
|
|
1203
|
-
entities: KnowledgeEntity[];
|
|
1204
|
-
/** 处理耗时(毫秒) */
|
|
1205
|
-
duration: number;
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* 知识检索选项
|
|
1209
|
-
*/
|
|
1210
|
-
interface KnowledgeRetrieveOptions {
|
|
1211
|
-
/** 集合名(可选,默认使用配置中的 collection) */
|
|
1212
|
-
collection?: string;
|
|
1213
|
-
/** 返回的最大结果数(默认 10) */
|
|
1214
|
-
topK?: number;
|
|
1215
|
-
/** 最低相似度(默认无限制) */
|
|
1216
|
-
minScore?: number;
|
|
1217
|
-
/** 是否启用实体增强检索(默认 true) */
|
|
1218
|
-
enableEntityBoost?: boolean;
|
|
1219
|
-
/** 元数据过滤条件 */
|
|
1220
|
-
filter?: Record<string, unknown>;
|
|
1221
|
-
}
|
|
1222
|
-
/**
|
|
1223
|
-
* 知识检索结果项
|
|
1224
|
-
*/
|
|
1225
|
-
interface KnowledgeRetrieveItem {
|
|
1226
|
-
/** 分块 ID */
|
|
1227
|
-
id: string;
|
|
1228
|
-
/** 分块内容 */
|
|
1229
|
-
content: string;
|
|
1230
|
-
/** 综合得分(向量相似度 + 实体加权) */
|
|
1231
|
-
score: number;
|
|
1232
|
-
/** 结构化信源引用 */
|
|
1233
|
-
citation: Citation;
|
|
1234
|
-
/** 元数据 */
|
|
1235
|
-
metadata?: Record<string, unknown>;
|
|
1236
|
-
/** 命中的实体名称列表(实体增强检索时填充) */
|
|
1237
|
-
matchedEntities?: string[];
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* 知识检索结果
|
|
1241
|
-
*/
|
|
1242
|
-
interface KnowledgeRetrieveResult {
|
|
1243
|
-
/** 检索结果列表(按综合分数降序) */
|
|
1244
|
-
items: KnowledgeRetrieveItem[];
|
|
1245
|
-
/** 去重后的信源引用列表 */
|
|
1246
|
-
citations: Citation[];
|
|
1247
|
-
/** 查询文本 */
|
|
1248
|
-
query: string;
|
|
1249
|
-
/** 查询耗时(毫秒) */
|
|
1250
|
-
duration: number;
|
|
1251
|
-
}
|
|
1252
|
-
/**
|
|
1253
|
-
* 知识问答选项
|
|
1254
|
-
*/
|
|
1255
|
-
interface KnowledgeAskOptions extends KnowledgeRetrieveOptions {
|
|
1256
|
-
/** LLM 模型名称覆盖 */
|
|
1257
|
-
model?: string;
|
|
1258
|
-
/** 系统提示词覆盖 */
|
|
1259
|
-
systemPrompt?: string;
|
|
1260
|
-
/** 温度覆盖 */
|
|
1261
|
-
temperature?: number;
|
|
1262
|
-
/** 消息历史(多轮对话) */
|
|
1263
|
-
messages?: ChatMessage[];
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* 知识问答结果
|
|
1267
|
-
*/
|
|
1268
|
-
interface KnowledgeAskResult {
|
|
1269
|
-
/** LLM 生成的回答 */
|
|
1270
|
-
answer: string;
|
|
1271
|
-
/** 使用的上下文 */
|
|
1272
|
-
context: KnowledgeRetrieveItem[];
|
|
1273
|
-
/** 去重后的信源引用列表 */
|
|
1274
|
-
citations: Citation[];
|
|
1275
|
-
/** 查询文本 */
|
|
1276
|
-
query: string;
|
|
1277
|
-
/** 使用的模型 */
|
|
1278
|
-
model: string;
|
|
1279
|
-
/** Token 使用统计 */
|
|
1280
|
-
usage?: {
|
|
1281
|
-
prompt_tokens: number;
|
|
1282
|
-
completion_tokens: number;
|
|
1283
|
-
total_tokens: number;
|
|
1284
|
-
};
|
|
1285
|
-
}
|
|
1286
|
-
/**
|
|
1287
|
-
* 实体查询选项
|
|
1288
|
-
*/
|
|
1289
|
-
interface EntityQueryOptions {
|
|
1290
|
-
/** 集合名(可选,默认使用配置中的 collection) */
|
|
1291
|
-
collection?: string;
|
|
1292
|
-
/** 实体类型过滤 */
|
|
1293
|
-
type?: EntityType;
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* 实体关联文档结果
|
|
1297
|
-
*/
|
|
1298
|
-
interface EntityDocumentResult {
|
|
1299
|
-
/** 实体信息 */
|
|
1300
|
-
entity: KnowledgeEntity;
|
|
1301
|
-
/** 关联文档列表 */
|
|
1302
|
-
documents: Array<{
|
|
1303
|
-
documentId: string;
|
|
1304
|
-
chunkId?: string;
|
|
1305
|
-
collection: string;
|
|
1306
|
-
relevance: number;
|
|
1307
|
-
context?: string;
|
|
1308
|
-
}>;
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* 实体列表查询选项
|
|
1312
|
-
*/
|
|
1313
|
-
interface EntityListOptions {
|
|
1314
|
-
/** 集合名过滤(不指定则返回所有 collection 的实体) */
|
|
1315
|
-
collection?: string;
|
|
1316
|
-
/** 实体类型过滤 */
|
|
1317
|
-
type?: EntityType;
|
|
1318
|
-
/** 关键词搜索(模糊匹配实体名称和别名) */
|
|
1319
|
-
keyword?: string;
|
|
1320
|
-
/** 最大返回数 */
|
|
1321
|
-
limit?: number;
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* 文件导入输入(从文件路径读取内容后自动 ingest)
|
|
1325
|
-
*
|
|
1326
|
-
* 仅 Node.js 端可用。
|
|
1327
|
-
*
|
|
1328
|
-
* @example
|
|
1329
|
-
* ```ts
|
|
1330
|
-
* await knowledge.ingestFile({
|
|
1331
|
-
* filePath: '/data/docs/README.md',
|
|
1332
|
-
* documentId: 'readme',
|
|
1333
|
-
* })
|
|
1334
|
-
* ```
|
|
1335
|
-
*/
|
|
1336
|
-
interface KnowledgeIngestFileInput {
|
|
1337
|
-
/** 文件路径(绝对路径或相对路径) */
|
|
1338
|
-
filePath: string;
|
|
1339
|
-
/** 文档唯一标识(可选,默认从文件名派生) */
|
|
1340
|
-
documentId?: string;
|
|
1341
|
-
/** 文档标题(可选,默认为文件名) */
|
|
1342
|
-
title?: string;
|
|
1343
|
-
/** 文件编码(默认 'utf-8') */
|
|
1344
|
-
encoding?: BufferEncoding;
|
|
1345
|
-
/** 集合名(可选,默认使用配置中的 collection) */
|
|
1346
|
-
collection?: string;
|
|
1347
|
-
/** 附加元数据 */
|
|
1348
|
-
metadata?: Record<string, unknown>;
|
|
1349
|
-
/** 是否启用实体提取 */
|
|
1350
|
-
enableEntityExtraction?: boolean;
|
|
1351
|
-
/** 清洗选项 */
|
|
1352
|
-
cleanOptions?: CleanOptionsInput;
|
|
1353
|
-
/** 分块选项 */
|
|
1354
|
-
chunkOptions?: ChunkOptionsInput;
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* 文档信息(列表展示用)
|
|
1358
|
-
*/
|
|
1359
|
-
interface KnowledgeDocumentInfo {
|
|
1360
|
-
/** 文档 ID */
|
|
1361
|
-
documentId: string;
|
|
1362
|
-
/** 文档标题 */
|
|
1363
|
-
title?: string;
|
|
1364
|
-
/** 文档来源 URL / 路径 */
|
|
1365
|
-
url?: string;
|
|
1366
|
-
/** 分块数量 */
|
|
1367
|
-
chunkCount: number;
|
|
1368
|
-
/** 关联实体数 */
|
|
1369
|
-
entityCount: number;
|
|
1370
|
-
/** 创建时间(Unix 毫秒) */
|
|
1371
|
-
createdAt: number;
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* 文档列表查询选项
|
|
1375
|
-
*/
|
|
1376
|
-
interface KnowledgeDocumentListOptions {
|
|
1377
|
-
/** 集合名覆盖(不指定则使用配置中的 default) */
|
|
1378
|
-
collection?: string;
|
|
1379
|
-
/** 偏移量 */
|
|
1380
|
-
offset?: number;
|
|
1381
|
-
/** 每页数量(默认 20) */
|
|
1382
|
-
limit?: number;
|
|
1383
|
-
}
|
|
1384
|
-
/**
|
|
1385
|
-
* 文档删除选项
|
|
1386
|
-
*/
|
|
1387
|
-
interface KnowledgeDocumentRemoveOptions {
|
|
1388
|
-
/** 集合名覆盖 */
|
|
1389
|
-
collection?: string;
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* 批量导入进度回调参数
|
|
1393
|
-
*/
|
|
1394
|
-
interface KnowledgeIngestBatchProgress {
|
|
1395
|
-
/** 已完成数量 */
|
|
1396
|
-
completed: number;
|
|
1397
|
-
/** 总数量 */
|
|
1398
|
-
total: number;
|
|
1399
|
-
/** 当前文档 ID */
|
|
1400
|
-
currentDocumentId: string;
|
|
1401
|
-
/** 当前文档导入结果(失败时为 undefined) */
|
|
1402
|
-
result?: KnowledgeIngestResult;
|
|
1403
|
-
/** 当前文档导入错误(成功时为 undefined) */
|
|
1404
|
-
error?: HaiError;
|
|
1405
|
-
}
|
|
1406
|
-
/**
|
|
1407
|
-
* 批量导入结果
|
|
1408
|
-
*/
|
|
1409
|
-
interface KnowledgeIngestBatchResult {
|
|
1410
|
-
/** 成功导入的文档数 */
|
|
1411
|
-
successCount: number;
|
|
1412
|
-
/** 失败的文档数 */
|
|
1413
|
-
failureCount: number;
|
|
1414
|
-
/** 各文档导入结果 */
|
|
1415
|
-
results: Array<{
|
|
1416
|
-
documentId: string;
|
|
1417
|
-
result?: KnowledgeIngestResult;
|
|
1418
|
-
error?: HaiError;
|
|
1419
|
-
}>;
|
|
1420
|
-
/** 总耗时(毫秒) */
|
|
1421
|
-
duration: number;
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Knowledge 操作接口(通过 `ai.knowledge` 访问)
|
|
1425
|
-
*
|
|
1426
|
-
* 知识库管理与检索的统一入口,编排 datapipe + KnowledgeStore + embedding + LLM。
|
|
1427
|
-
*
|
|
1428
|
-
* ## 生命周期
|
|
1429
|
-
*
|
|
1430
|
-
* 每个 collection 在使用前必须先调用 `setup()`,支持多次调用以初始化不同分区:
|
|
1431
|
-
*
|
|
1432
|
-
* ```ts
|
|
1433
|
-
* await ai.knowledge.setup() // 使用配置默认 collection
|
|
1434
|
-
* await ai.knowledge.setup({ collection: 'kb-prod' }) // 初始化额外分区
|
|
1435
|
-
* ```
|
|
1436
|
-
*
|
|
1437
|
-
* ## 单 collection 示例
|
|
1438
|
-
*
|
|
1439
|
-
* ```ts
|
|
1440
|
-
* // 初始化
|
|
1441
|
-
* await ai.knowledge.setup()
|
|
1442
|
-
*
|
|
1443
|
-
* // 导入文档
|
|
1444
|
-
* await ai.knowledge.ingest({
|
|
1445
|
-
* documentId: 'doc-001',
|
|
1446
|
-
* content: markdownContent,
|
|
1447
|
-
* title: '项目文档',
|
|
1448
|
-
* })
|
|
1449
|
-
*
|
|
1450
|
-
* // 查询(带信源追踪)
|
|
1451
|
-
* const result = await ai.knowledge.retrieve('张三负责了哪些模块?')
|
|
1452
|
-
*
|
|
1453
|
-
* // 问答(RAG + 信源引用)
|
|
1454
|
-
* const answer = await ai.knowledge.ask('张三负责了哪些模块?')
|
|
1455
|
-
* ```
|
|
1456
|
-
*
|
|
1457
|
-
* ## 多 collection(多分区)示例
|
|
1458
|
-
*
|
|
1459
|
-
* ```ts
|
|
1460
|
-
* // 分别初始化两个知识库分区
|
|
1461
|
-
* await ai.knowledge.setup({ collection: 'kb-product' })
|
|
1462
|
-
* await ai.knowledge.setup({ collection: 'kb-support' })
|
|
1463
|
-
*
|
|
1464
|
-
* // 写入不同分区
|
|
1465
|
-
* await ai.knowledge.ingest({ documentId: 'p-001', content: '...', collection: 'kb-product' })
|
|
1466
|
-
* await ai.knowledge.ingest({ documentId: 's-001', content: '...', collection: 'kb-support' })
|
|
1467
|
-
*
|
|
1468
|
-
* // 从指定分区检索(对未 setup 的 collection 发起任何操作都会返回 KNOWLEDGE_NOT_SETUP 错误)
|
|
1469
|
-
* const result = await ai.knowledge.retrieve('query', { collection: 'kb-support' })
|
|
1470
|
-
* ```
|
|
1471
|
-
*/
|
|
1472
|
-
interface KnowledgeOperations {
|
|
1473
|
-
/**
|
|
1474
|
-
* 初始化知识库(幂等,支持多次调用以初始化不同 collection)
|
|
1475
|
-
*
|
|
1476
|
-
* 创建向量集合和实体表。每个 collection 需独立调用本方法,
|
|
1477
|
-
* 未 setup 的 collection 执行以下操作时均会返回 `KNOWLEDGE_NOT_SETUP` 错误:
|
|
1478
|
-
* `ingest` / `ingestFile` / `ingestBatch` / `retrieve` / `ask` /
|
|
1479
|
-
* `findByEntity` / `listDocuments` / `removeDocument`。
|
|
1480
|
-
*
|
|
1481
|
-
* @param options - 初始化选项(collection 名称、向量维度)
|
|
1482
|
-
* @returns 成功返回 ok(undefined)
|
|
1483
|
-
*/
|
|
1484
|
-
setup: (options?: KnowledgeSetupOptions) => Promise<HaiResult<void>>;
|
|
1485
|
-
/**
|
|
1486
|
-
* 导入文档
|
|
1487
|
-
*
|
|
1488
|
-
* 执行流程:clean → chunk → embed → 向量存储 → 实体提取 → 实体存储
|
|
1489
|
-
*
|
|
1490
|
-
* @param input - 文档导入输入
|
|
1491
|
-
* @returns 导入结果(分块数、实体列表等)
|
|
1492
|
-
*/
|
|
1493
|
-
ingest: (input: KnowledgeIngestInput) => Promise<HaiResult<KnowledgeIngestResult>>;
|
|
1494
|
-
/**
|
|
1495
|
-
* 知识检索(带实体增强 + 信源追踪)
|
|
1496
|
-
*
|
|
1497
|
-
* @param query - 查询文本
|
|
1498
|
-
* @param options - 检索选项
|
|
1499
|
-
* @returns 检索结果(带 citations)
|
|
1500
|
-
*/
|
|
1501
|
-
retrieve: (query: string, options?: KnowledgeRetrieveOptions) => Promise<HaiResult<KnowledgeRetrieveResult>>;
|
|
1502
|
-
/**
|
|
1503
|
-
* 知识问答(RAG + 信源引用)
|
|
1504
|
-
*
|
|
1505
|
-
* @param query - 用户问题
|
|
1506
|
-
* @param options - 问答选项
|
|
1507
|
-
* @returns 问答结果(回答 + 信源)
|
|
1508
|
-
*/
|
|
1509
|
-
ask: (query: string, options?: KnowledgeAskOptions) => Promise<HaiResult<KnowledgeAskResult>>;
|
|
1510
|
-
/**
|
|
1511
|
-
* 按实体查询关联文档
|
|
1512
|
-
*
|
|
1513
|
-
* @param entityName - 实体名称
|
|
1514
|
-
* @param options - 查询选项
|
|
1515
|
-
* @returns 实体关联文档列表
|
|
1516
|
-
*/
|
|
1517
|
-
findByEntity: (entityName: string, options?: EntityQueryOptions) => Promise<HaiResult<EntityDocumentResult[]>>;
|
|
1518
|
-
/**
|
|
1519
|
-
* 列出所有实体
|
|
1520
|
-
*
|
|
1521
|
-
* @param options - 列表选项
|
|
1522
|
-
* @returns 实体列表
|
|
1523
|
-
*/
|
|
1524
|
-
listEntities: (options?: EntityListOptions) => Promise<HaiResult<KnowledgeEntity[]>>;
|
|
1525
|
-
/**
|
|
1526
|
-
* 列出已导入的文档列表
|
|
1527
|
-
*
|
|
1528
|
-
* @param options - 列表选项
|
|
1529
|
-
* @returns 文档信息列表
|
|
1530
|
-
*/
|
|
1531
|
-
listDocuments: (options?: KnowledgeDocumentListOptions) => Promise<HaiResult<KnowledgeDocumentInfo[]>>;
|
|
1532
|
-
/**
|
|
1533
|
-
* 删除已导入的文档(同时删除向量和实体关联)
|
|
1534
|
-
*
|
|
1535
|
-
* @param documentId - 文档 ID
|
|
1536
|
-
* @param options - 删除选项
|
|
1537
|
-
* @returns 成功返回 ok(undefined)
|
|
1538
|
-
*/
|
|
1539
|
-
removeDocument: (documentId: string, options?: KnowledgeDocumentRemoveOptions) => Promise<HaiResult<void>>;
|
|
1540
|
-
/**
|
|
1541
|
-
* 从文件路径导入文档(仅 Node.js 端可用)
|
|
1542
|
-
*
|
|
1543
|
-
* 读取文件内容后自动调用 ingest() 完成导入。
|
|
1544
|
-
*
|
|
1545
|
-
* @param input - 文件导入输入
|
|
1546
|
-
* @returns 导入结果
|
|
1547
|
-
*/
|
|
1548
|
-
ingestFile: (input: KnowledgeIngestFileInput) => Promise<HaiResult<KnowledgeIngestResult>>;
|
|
1549
|
-
/**
|
|
1550
|
-
* 批量导入文档
|
|
1551
|
-
*
|
|
1552
|
-
* 依次执行 ingest(),通过 onProgress 回调报告进度,单个文档失败不中断整体流程。
|
|
1553
|
-
*
|
|
1554
|
-
* @param inputs - 文档导入输入列表
|
|
1555
|
-
* @param onProgress - 每完成一个文档后的回调
|
|
1556
|
-
* @returns 批量导入汇总结果
|
|
1557
|
-
*/
|
|
1558
|
-
ingestBatch: (inputs: KnowledgeIngestInput[], onProgress?: (progress: KnowledgeIngestBatchProgress) => void) => Promise<HaiResult<KnowledgeIngestBatchResult>>;
|
|
1559
|
-
/**
|
|
1560
|
-
* 删除整个 collection(幂等)
|
|
1561
|
-
*
|
|
1562
|
-
* 同时清除:vecdb 向量集合、实体-文档关联、文档元数据、collection 注册记录。
|
|
1563
|
-
* 删除后 collection 需重新执行 `setup` 才可使用。
|
|
1564
|
-
*
|
|
1565
|
-
* @param collection - 要删除的 collection 名称,默认使用 config.collection
|
|
1566
|
-
* @returns 成功返回 ok(undefined);store 不可用时返回 `KNOWLEDGE_SETUP_FAILED`
|
|
1567
|
-
*/
|
|
1568
|
-
deleteCollection: (collection?: string) => Promise<HaiResult<void>>;
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
/**
|
|
1572
|
-
* @h-ai/ai — Memory 子功能类型
|
|
1573
|
-
*
|
|
1574
|
-
* 定义记忆管理操作的类型接口:提取、存储、检索、注入。
|
|
1575
|
-
* 支持从对话中自动提取关键事实、偏好、事件等记忆,并在后续对话中检索注入。
|
|
1576
|
-
* @module ai-memory-types
|
|
1577
|
-
*/
|
|
1578
|
-
|
|
1579
|
-
/**
|
|
1580
|
-
* 记忆类型枚举 Schema
|
|
1581
|
-
*
|
|
1582
|
-
* 定义系统支持的五种记忆类型,用于对提取和存储的记忆进行分类:
|
|
1583
|
-
* - `fact` — 客观事实(如「用户是后端工程师」「项目使用 TypeScript」)
|
|
1584
|
-
* - `preference` — 用户偏好(如「喜欢简洁的代码风格」「偏好中文回复」)
|
|
1585
|
-
* - `event` — 事件/时间线信息(如「上周部署了 v2.0」「昨天修复了登录 Bug」)
|
|
1586
|
-
* - `entity` — 命名实体(如人名、产品名、组织名等,便于后续实体关联)
|
|
1587
|
-
* - `instruction` — 用户给出的持久指令(如「以后都用函数式写法」「回复不超过 200 字」)
|
|
1588
|
-
*
|
|
1589
|
-
* @example
|
|
1590
|
-
* ```ts
|
|
1591
|
-
* import { MemoryTypeSchema } from '@h-ai/ai'
|
|
1592
|
-
*
|
|
1593
|
-
* // 校验字符串是否为合法记忆类型
|
|
1594
|
-
* const result = MemoryTypeSchema.safeParse('preference') // { success: true }
|
|
1595
|
-
*
|
|
1596
|
-
* // 用于配置或过滤
|
|
1597
|
-
* await ai.memory.recall('编程语言', { types: ['preference', 'fact'] })
|
|
1598
|
-
* ```
|
|
1599
|
-
*/
|
|
1600
|
-
declare const MemoryTypeSchema: z.ZodEnum<{
|
|
1601
|
-
fact: "fact";
|
|
1602
|
-
preference: "preference";
|
|
1603
|
-
event: "event";
|
|
1604
|
-
entity: "entity";
|
|
1605
|
-
instruction: "instruction";
|
|
1606
|
-
}>;
|
|
1607
|
-
/** 记忆类型 */
|
|
1608
|
-
type MemoryType = z.infer<typeof MemoryTypeSchema>;
|
|
1609
|
-
/**
|
|
1610
|
-
* 记忆条目输入(手动添加时使用)
|
|
1611
|
-
*
|
|
1612
|
-
* @example
|
|
1613
|
-
* ```ts
|
|
1614
|
-
* const input: MemoryEntryInput = {
|
|
1615
|
-
* content: '用户偏好使用中文回复',
|
|
1616
|
-
* type: 'preference',
|
|
1617
|
-
* importance: 0.8,
|
|
1618
|
-
* objectId: 'user-001',
|
|
1619
|
-
* }
|
|
1620
|
-
* ```
|
|
1621
|
-
*/
|
|
1622
|
-
interface MemoryEntryInput {
|
|
1623
|
-
/** 记忆内容 */
|
|
1624
|
-
content: string;
|
|
1625
|
-
/** 记忆类型 */
|
|
1626
|
-
type: MemoryType;
|
|
1627
|
-
/** 重要性评分 [0, 1](可选,默认 0.5) */
|
|
1628
|
-
importance?: number;
|
|
1629
|
-
/** 所属主体 ID(不指定时为全局记忆) */
|
|
1630
|
-
objectId?: string;
|
|
1631
|
-
/** 作用域(JSON 对象,key-value 匹配过滤。用于子 session 记忆隔离等场景) */
|
|
1632
|
-
scope?: Record<string, unknown>;
|
|
1633
|
-
/** 附加元数据 */
|
|
1634
|
-
metadata?: Record<string, unknown>;
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* 完整的记忆条目
|
|
1638
|
-
*/
|
|
1639
|
-
interface MemoryEntry {
|
|
1640
|
-
/** 记忆唯一标识 */
|
|
1641
|
-
id: string;
|
|
1642
|
-
/** 记忆内容 */
|
|
1643
|
-
content: string;
|
|
1644
|
-
/** 记忆类型 */
|
|
1645
|
-
type: MemoryType;
|
|
1646
|
-
/** 重要性评分 [0, 1] */
|
|
1647
|
-
importance: number;
|
|
1648
|
-
/** 所属主体 ID */
|
|
1649
|
-
objectId?: string;
|
|
1650
|
-
/** 作用域(JSON 对象,key-value 匹配过滤。用于子 session 记忆隔离等场景) */
|
|
1651
|
-
scope?: Record<string, unknown>;
|
|
1652
|
-
/** 附加元数据 */
|
|
1653
|
-
metadata?: Record<string, unknown>;
|
|
1654
|
-
/** 向量(embedding 已计算时填充) */
|
|
1655
|
-
vector?: number[];
|
|
1656
|
-
/** 创建时间(Unix 毫秒) */
|
|
1657
|
-
createdAt: number;
|
|
1658
|
-
/** 最近访问时间(Unix 毫秒) */
|
|
1659
|
-
lastAccessedAt: number;
|
|
1660
|
-
/** 被检索次数 */
|
|
1661
|
-
accessCount: number;
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* 记忆提取选项
|
|
1665
|
-
*/
|
|
1666
|
-
interface MemoryExtractOptions {
|
|
1667
|
-
/** 只提取指定类型 */
|
|
1668
|
-
types?: MemoryType[];
|
|
1669
|
-
/** 指定提取用的模型 */
|
|
1670
|
-
model?: string;
|
|
1671
|
-
/** 自定义提取 systemPrompt(覆盖模块配置与内置默认提示词) */
|
|
1672
|
-
systemPrompt?: string;
|
|
1673
|
-
/** 过滤低重要性条目(默认 0) */
|
|
1674
|
-
minImportance?: number;
|
|
1675
|
-
/** 所属主体 ID(关联到提取结果) */
|
|
1676
|
-
objectId?: string;
|
|
1677
|
-
/** 作用域(JSON 对象,提取的记忆将关联此 scope) */
|
|
1678
|
-
scope?: Record<string, unknown>;
|
|
1679
|
-
/**
|
|
1680
|
-
* 临时模型配置(携带凭据的模型请求)。
|
|
1681
|
-
*
|
|
1682
|
-
* 用于传递运行时解析的 apiKey / baseUrl 等凭证,
|
|
1683
|
-
* 避免回退到全局 .env 配置。优先级高于全局 config.models 查找。
|
|
1684
|
-
*/
|
|
1685
|
-
tempModel?: TempModelConfig;
|
|
1686
|
-
/** 取消整条记忆提取链(包括事实抽取与 native 对账 LLM 调用) */
|
|
1687
|
-
signal?: AbortSignal;
|
|
1688
|
-
}
|
|
1689
|
-
/**
|
|
1690
|
-
* 记忆检索选项
|
|
1691
|
-
*/
|
|
1692
|
-
interface MemoryRecallOptions {
|
|
1693
|
-
/** 返回数量(默认使用配置的 defaultTopK) */
|
|
1694
|
-
topK?: number;
|
|
1695
|
-
/**
|
|
1696
|
-
* 候选池倍数(覆盖配置的 candidateMultiplier)
|
|
1697
|
-
*
|
|
1698
|
-
* 检索时先取回 `topK × candidateMultiplier` 条候选再按 scope / 类型 / 重要性过滤,
|
|
1699
|
-
* 最后截取 topK。scope 过滤较严(如按 topic / persona 隔离)时应调大,避免漏召回。
|
|
1700
|
-
*/
|
|
1701
|
-
candidateMultiplier?: number;
|
|
1702
|
-
/** 过滤类型 */
|
|
1703
|
-
types?: MemoryType[];
|
|
1704
|
-
/** 最低重要性 */
|
|
1705
|
-
minImportance?: number;
|
|
1706
|
-
/** 时间衰减权重 [0, 1](0 = 不考虑时间,1 = 仅按时间排序) */
|
|
1707
|
-
recencyWeight?: number;
|
|
1708
|
-
/** 限定主体 ID */
|
|
1709
|
-
objectId?: string;
|
|
1710
|
-
/** 限定作用域(key-value 匹配过滤,用于子 session 记忆隔离等场景) */
|
|
1711
|
-
scope?: Record<string, unknown>;
|
|
1712
|
-
}
|
|
1713
|
-
/**
|
|
1714
|
-
* 记忆注入选项(`injectMemories` 使用)
|
|
1715
|
-
*
|
|
1716
|
-
* 控制记忆注入行为:检索数量、Token 预算、注入位置等。
|
|
1717
|
-
*/
|
|
1718
|
-
interface MemoryInjectionOptions {
|
|
1719
|
-
/** 注入的记忆数量(默认 5) */
|
|
1720
|
-
topK?: number;
|
|
1721
|
-
/**
|
|
1722
|
-
* 候选池倍数(覆盖配置的 candidateMultiplier)
|
|
1723
|
-
*
|
|
1724
|
-
* 透传给底层 `recall`,scope 过滤较严时应调大以避免漏召回。
|
|
1725
|
-
*/
|
|
1726
|
-
candidateMultiplier?: number;
|
|
1727
|
-
/** 记忆占用的最大 token 预算(默认不限) */
|
|
1728
|
-
maxTokens?: number;
|
|
1729
|
-
/** 注入位置:system = 追加到 system 消息末尾,before-last = 插入在最后一条用户消息之前 */
|
|
1730
|
-
position?: 'system' | 'before-last';
|
|
1731
|
-
/** 限定主体 ID */
|
|
1732
|
-
objectId?: string;
|
|
1733
|
-
/** 限定作用域(key-value 匹配过滤,用于子 session 记忆隔离等场景) */
|
|
1734
|
-
scope?: Record<string, unknown>;
|
|
1735
|
-
/** 限定记忆类型 */
|
|
1736
|
-
types?: MemoryType[];
|
|
1737
|
-
/** 最低重要性阈值 */
|
|
1738
|
-
minImportance?: number;
|
|
1739
|
-
}
|
|
1740
|
-
/**
|
|
1741
|
-
* 记忆列表选项
|
|
1742
|
-
*/
|
|
1743
|
-
interface MemoryListOptions {
|
|
1744
|
-
/** 过滤类型 */
|
|
1745
|
-
types?: MemoryType[];
|
|
1746
|
-
/** 限定主体 ID */
|
|
1747
|
-
objectId?: string;
|
|
1748
|
-
/** 限定作用域(key-value 匹配过滤,用于子 session / 主题 / 角色记忆隔离等场景) */
|
|
1749
|
-
scope?: Record<string, unknown>;
|
|
1750
|
-
/** 最大返回数 */
|
|
1751
|
-
limit?: number;
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* 记忆分页选项
|
|
1755
|
-
*/
|
|
1756
|
-
interface MemoryListPageOptions {
|
|
1757
|
-
/** 过滤类型 */
|
|
1758
|
-
types?: MemoryType[];
|
|
1759
|
-
/** 限定主体 ID */
|
|
1760
|
-
objectId?: string;
|
|
1761
|
-
/** 限定作用域(key-value 匹配过滤,用于子 session / 主题 / 角色记忆隔离等场景) */
|
|
1762
|
-
scope?: Record<string, unknown>;
|
|
1763
|
-
/** 偏移量 */
|
|
1764
|
-
offset?: number;
|
|
1765
|
-
/** 每页数量(默认 20) */
|
|
1766
|
-
limit?: number;
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* 记忆清空选项
|
|
1770
|
-
*
|
|
1771
|
-
* 安全语义:未传任何过滤条件时清空全部;传入 objectId / types / scope 时
|
|
1772
|
-
* 仅删除同时匹配所有给定条件的记忆,避免误删其他主体或类型的记忆。
|
|
1773
|
-
*/
|
|
1774
|
-
interface MemoryClearOptions {
|
|
1775
|
-
/** 仅清空指定类型 */
|
|
1776
|
-
types?: MemoryType[];
|
|
1777
|
-
/** 仅清空指定主体 */
|
|
1778
|
-
objectId?: string;
|
|
1779
|
-
/** 仅清空匹配指定作用域的记忆(key-value 匹配过滤) */
|
|
1780
|
-
scope?: Record<string, unknown>;
|
|
1781
|
-
}
|
|
1782
|
-
/**
|
|
1783
|
-
* 记忆条目更新输入
|
|
1784
|
-
*
|
|
1785
|
-
* 所有字段均为可选,仅传入需要更新的字段。
|
|
1786
|
-
*/
|
|
1787
|
-
interface MemoryUpdateInput {
|
|
1788
|
-
/** 更新记忆内容(同时重新计算向量) */
|
|
1789
|
-
content?: string;
|
|
1790
|
-
/** 更新记忆类型 */
|
|
1791
|
-
type?: MemoryType;
|
|
1792
|
-
/** 更新重要性 */
|
|
1793
|
-
importance?: number;
|
|
1794
|
-
/** 更新元数据 */
|
|
1795
|
-
metadata?: Record<string, unknown>;
|
|
1796
|
-
}
|
|
1797
|
-
/**
|
|
1798
|
-
* Memory 操作接口(通过 `ai.memory` 访问)
|
|
1799
|
-
*
|
|
1800
|
-
* 管理对话中产生的关键事实、用户偏好、长期知识的提取、存储与检索。
|
|
1801
|
-
* 需要先调用 `ai.init()` 初始化后使用。
|
|
1802
|
-
*
|
|
1803
|
-
* @example
|
|
1804
|
-
* ```ts
|
|
1805
|
-
* // 从对话中自动提取记忆
|
|
1806
|
-
* const extracted = await ai.memory.extract(messages, {
|
|
1807
|
-
* objectId: 'user-001',
|
|
1808
|
-
* systemPrompt: 'Only extract durable user preferences and explicit long-term instructions.',
|
|
1809
|
-
* })
|
|
1810
|
-
*
|
|
1811
|
-
* // 手动添加记忆
|
|
1812
|
-
* await ai.memory.add({ content: '用户偏好中文', type: 'preference', objectId: 'user-001' })
|
|
1813
|
-
*
|
|
1814
|
-
* // 检索相关记忆
|
|
1815
|
-
* const memories = await ai.memory.recall('用户的语言偏好', { objectId: 'user-001' })
|
|
1816
|
-
*
|
|
1817
|
-
* // 将记忆注入消息列表
|
|
1818
|
-
* const enriched = await ai.memory.injectMemories(newMessages, { objectId: 'user-001' })
|
|
1819
|
-
* const response = await ai.llm.chat({ messages: enriched.value })
|
|
1820
|
-
* ```
|
|
1821
|
-
*/
|
|
1822
|
-
/**
|
|
1823
|
-
* 按 ID 访问单条记忆(get / update / remove)时的归属校验作用域。
|
|
1824
|
-
*
|
|
1825
|
-
* 传入后,Provider 先读取记忆再校验:`entry.objectId` 必须等于 `objectId`,且 `entry.scope`
|
|
1826
|
-
* 包含 `scope` 的全部 key-value;不匹配时统一返回 `MEMORY_NOT_FOUND`(避免通过错误差异
|
|
1827
|
-
* 枚举其他主体的记忆)。不传时不做归属校验(向后兼容);处理不可信输入的 memoryId 时必须传入。
|
|
1828
|
-
*/
|
|
1829
|
-
interface MemoryAccessScope {
|
|
1830
|
-
/** 归属主体 ID(必须与记忆 entry.objectId 一致) */
|
|
1831
|
-
objectId: string;
|
|
1832
|
-
/** 业务作用域(entry.scope 必须包含这些 key-value) */
|
|
1833
|
-
scope?: Record<string, unknown>;
|
|
1834
|
-
}
|
|
1835
|
-
/**
|
|
1836
|
-
* 记忆作用域绑定(`ai.memory.scoped()` 使用)
|
|
1837
|
-
*
|
|
1838
|
-
* 绑定后,所有操作自动携带 `objectId` 与 `scope`,无需每次手动传入,
|
|
1839
|
-
* 从根本上避免「忘记传 objectId 导致跨租户越权」的安全隐患。
|
|
1840
|
-
*/
|
|
1841
|
-
interface ScopedMemoryBinding {
|
|
1842
|
-
/** 归属主体 ID(所有操作自动绑定) */
|
|
1843
|
-
objectId: string;
|
|
1844
|
-
/** 业务作用域(所有操作自动绑定并作为归属校验的一部分,如 `{ topicId, personaId }`) */
|
|
1845
|
-
scope?: Record<string, unknown>;
|
|
1846
|
-
}
|
|
1847
|
-
/**
|
|
1848
|
-
* 全局清空选项(`ai.memory.admin.clearAll()` 使用)
|
|
1849
|
-
*
|
|
1850
|
-
* 危险操作:清空整个记忆后端的全部数据。必须显式传入 `confirm: true`,
|
|
1851
|
-
* 防止误调用;普通 `clear()` 不再支持通过省略参数隐式清空全局。
|
|
1852
|
-
*/
|
|
1853
|
-
interface MemoryClearAllOptions {
|
|
1854
|
-
/** 必须显式为 `true`,否则拒绝执行 */
|
|
1855
|
-
confirm: true;
|
|
1856
|
-
}
|
|
1857
|
-
/**
|
|
1858
|
-
* 记忆管理接口(`ai.memory.admin`)
|
|
1859
|
-
*
|
|
1860
|
-
* 承载危险的全局操作,与业务作用域操作明确分离。
|
|
1861
|
-
*/
|
|
1862
|
-
interface MemoryAdminOperations {
|
|
1863
|
-
/**
|
|
1864
|
-
* 清空整个记忆后端的全部数据(跨所有主体 / 作用域)
|
|
1865
|
-
*
|
|
1866
|
-
* @param options - 必须传入 `{ confirm: true }`
|
|
1867
|
-
* @returns 成功返回 ok(undefined);未确认返回 MEMORY_STORE_FAILED
|
|
1868
|
-
*/
|
|
1869
|
-
clearAll: (options: MemoryClearAllOptions) => Promise<HaiResult<void>>;
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* 记忆核心操作(Provider 实现层)
|
|
1873
|
-
*
|
|
1874
|
-
* 各 Provider(native / mem0)实现这一组操作。公共入口 `ai.memory` 在其基础上
|
|
1875
|
-
* 叠加作用域绑定(`scoped`)与管理接口(`admin`),并对 `clear` 施加空过滤保护。
|
|
1876
|
-
*/
|
|
1877
|
-
interface MemoryCoreOperations {
|
|
1878
|
-
/**
|
|
1879
|
-
* 从对话消息中自动提取记忆条目
|
|
1880
|
-
*
|
|
1881
|
-
* 使用 LLM 分析对话内容,提取值得记住的事实、偏好、事件等。
|
|
1882
|
-
* 提取的记忆会自动持久化到 Store(含向量计算)。
|
|
1883
|
-
*
|
|
1884
|
-
* @param messages - 对话消息列表
|
|
1885
|
-
* @param options - 提取选项
|
|
1886
|
-
* @returns 提取到的记忆条目列表
|
|
1887
|
-
*/
|
|
1888
|
-
extract: (messages: ChatMessage[], options?: MemoryExtractOptions) => Promise<HaiResult<MemoryEntry[]>>;
|
|
1889
|
-
/**
|
|
1890
|
-
* 根据查询检索最相关的记忆
|
|
1891
|
-
*
|
|
1892
|
-
* 综合向量相似度、重要性、时间衰减进行排序。
|
|
1893
|
-
*
|
|
1894
|
-
* @param query - 查询文本
|
|
1895
|
-
* @param options - 检索选项
|
|
1896
|
-
* @returns 相关记忆列表
|
|
1897
|
-
*/
|
|
1898
|
-
recall: (query: string, options?: MemoryRecallOptions) => Promise<HaiResult<MemoryEntry[]>>;
|
|
1899
|
-
/**
|
|
1900
|
-
* 将相关记忆注入到消息列表中
|
|
1901
|
-
*
|
|
1902
|
-
* 工作流程:
|
|
1903
|
-
* 1. 从消息列表中提取最后一条用户消息作为检索查询
|
|
1904
|
-
* 2. 调用 `recall` 检索最相关的记忆条目
|
|
1905
|
-
* 3. 将记忆格式化为文本块,按指定位置注入消息列表
|
|
1906
|
-
*
|
|
1907
|
-
* @param messages - 原始消息列表
|
|
1908
|
-
* @param options - 注入选项(数量、位置、Token 预算等)
|
|
1909
|
-
* @returns 注入记忆后的新消息列表(不修改原数组)
|
|
1910
|
-
*/
|
|
1911
|
-
injectMemories: (messages: ChatMessage[], options?: MemoryInjectionOptions) => Promise<HaiResult<ChatMessage[]>>;
|
|
1912
|
-
/**
|
|
1913
|
-
* 手动添加一条记忆
|
|
1914
|
-
*
|
|
1915
|
-
* 记忆会自动持久化到 Store(含向量计算)。
|
|
1916
|
-
*
|
|
1917
|
-
* @param entry - 记忆条目输入
|
|
1918
|
-
* @returns 存储后的完整记忆条目
|
|
1919
|
-
*/
|
|
1920
|
-
add: (entry: MemoryEntryInput) => Promise<HaiResult<MemoryEntry>>;
|
|
1921
|
-
/**
|
|
1922
|
-
* 更新一条已有记忆
|
|
1923
|
-
*
|
|
1924
|
-
* 仅更新传入的字段,其余字段保持不变。
|
|
1925
|
-
* 若 content 被更新,会重新计算向量。
|
|
1926
|
-
* 更新结果自动持久化到 Store。
|
|
1927
|
-
*
|
|
1928
|
-
* @param memoryId - 记忆 ID
|
|
1929
|
-
* @param updates - 需要更新的字段
|
|
1930
|
-
* @param accessScope - 可选归属校验(不匹配返回 MEMORY_NOT_FOUND)
|
|
1931
|
-
* @returns 更新后的完整记忆条目
|
|
1932
|
-
*/
|
|
1933
|
-
update: (memoryId: string, updates: MemoryUpdateInput, accessScope?: MemoryAccessScope) => Promise<HaiResult<MemoryEntry>>;
|
|
1934
|
-
/**
|
|
1935
|
-
* 按 ID 获取单条记忆
|
|
1936
|
-
*
|
|
1937
|
-
* @param memoryId - 记忆 ID
|
|
1938
|
-
* @param accessScope - 可选归属校验(不匹配返回 MEMORY_NOT_FOUND)
|
|
1939
|
-
* @returns 记忆条目,不存在时返回 MEMORY_NOT_FOUND
|
|
1940
|
-
*/
|
|
1941
|
-
get: (memoryId: string, accessScope?: MemoryAccessScope) => Promise<HaiResult<MemoryEntry>>;
|
|
1942
|
-
/**
|
|
1943
|
-
* 删除单条记忆
|
|
1944
|
-
*
|
|
1945
|
-
* 同时从 Store 中移除持久化数据。
|
|
1946
|
-
*
|
|
1947
|
-
* @param memoryId - 记忆 ID
|
|
1948
|
-
* @param accessScope - 可选归属校验(不匹配返回 MEMORY_NOT_FOUND)
|
|
1949
|
-
* @returns 成功返回 ok(undefined)
|
|
1950
|
-
*/
|
|
1951
|
-
remove: (memoryId: string, accessScope?: MemoryAccessScope) => Promise<HaiResult<void>>;
|
|
1952
|
-
/**
|
|
1953
|
-
* 获取记忆列表
|
|
1954
|
-
*
|
|
1955
|
-
* @param options - 列表选项
|
|
1956
|
-
* @returns 记忆条目列表
|
|
1957
|
-
*/
|
|
1958
|
-
list: (options?: MemoryListOptions) => Promise<HaiResult<MemoryEntry[]>>;
|
|
1959
|
-
/**
|
|
1960
|
-
* 分页获取记忆列表
|
|
1961
|
-
*
|
|
1962
|
-
* @param options - 分页选项
|
|
1963
|
-
* @returns 分页结果
|
|
1964
|
-
*/
|
|
1965
|
-
listPage: (options?: MemoryListPageOptions) => Promise<HaiResult<StorePage<MemoryEntry>>>;
|
|
1966
|
-
/**
|
|
1967
|
-
* 清空记忆
|
|
1968
|
-
*
|
|
1969
|
-
* 同时从 Store 中移除持久化数据。
|
|
1970
|
-
*
|
|
1971
|
-
* @param options - 清空选项(可按类型/主体过滤)
|
|
1972
|
-
*/
|
|
1973
|
-
clear: (options?: MemoryClearOptions) => Promise<HaiResult<void>>;
|
|
1974
|
-
}
|
|
1975
|
-
/**
|
|
1976
|
-
* 作用域绑定的记忆操作(`ai.memory.scoped()` 返回)
|
|
1977
|
-
*
|
|
1978
|
-
* 所有操作自动携带绑定的 `objectId` 与 `scope`,无需重复传入;`get` / `update` / `remove`
|
|
1979
|
-
* 自动施加归属校验(跨租户访问返回 `MEMORY_NOT_FOUND`);`clear` 仅清空绑定作用域内的记忆,
|
|
1980
|
-
* 永远不会误清全局。
|
|
1981
|
-
*/
|
|
1982
|
-
interface ScopedMemoryOperations {
|
|
1983
|
-
/** 从对话中提取记忆(自动绑定 objectId / scope) */
|
|
1984
|
-
extract: (messages: ChatMessage[], options?: Omit<MemoryExtractOptions, 'objectId' | 'scope'>) => Promise<HaiResult<MemoryEntry[]>>;
|
|
1985
|
-
/** 检索相关记忆(自动绑定 objectId / scope) */
|
|
1986
|
-
recall: (query: string, options?: Omit<MemoryRecallOptions, 'objectId' | 'scope'>) => Promise<HaiResult<MemoryEntry[]>>;
|
|
1987
|
-
/** 注入相关记忆(自动绑定 objectId / scope) */
|
|
1988
|
-
injectMemories: (messages: ChatMessage[], options?: Omit<MemoryInjectionOptions, 'objectId' | 'scope'>) => Promise<HaiResult<ChatMessage[]>>;
|
|
1989
|
-
/** 添加记忆(自动绑定 objectId / scope) */
|
|
1990
|
-
add: (entry: Omit<MemoryEntryInput, 'objectId' | 'scope'>) => Promise<HaiResult<MemoryEntry>>;
|
|
1991
|
-
/** 更新记忆(自动施加归属校验) */
|
|
1992
|
-
update: (memoryId: string, updates: MemoryUpdateInput) => Promise<HaiResult<MemoryEntry>>;
|
|
1993
|
-
/** 按 ID 获取记忆(自动施加归属校验) */
|
|
1994
|
-
get: (memoryId: string) => Promise<HaiResult<MemoryEntry>>;
|
|
1995
|
-
/** 删除记忆(自动施加归属校验) */
|
|
1996
|
-
remove: (memoryId: string) => Promise<HaiResult<void>>;
|
|
1997
|
-
/** 列出记忆(自动绑定 objectId / scope) */
|
|
1998
|
-
list: (options?: Omit<MemoryListOptions, 'objectId' | 'scope'>) => Promise<HaiResult<MemoryEntry[]>>;
|
|
1999
|
-
/** 分页列出记忆(自动绑定 objectId / scope) */
|
|
2000
|
-
listPage: (options?: Omit<MemoryListPageOptions, 'objectId' | 'scope'>) => Promise<HaiResult<StorePage<MemoryEntry>>>;
|
|
2001
|
-
/** 清空绑定作用域内的记忆(自动绑定 objectId / scope,不会误清全局) */
|
|
2002
|
-
clear: (options?: Omit<MemoryClearOptions, 'objectId' | 'scope'>) => Promise<HaiResult<void>>;
|
|
2003
|
-
}
|
|
2004
|
-
/**
|
|
2005
|
-
* 公共记忆操作接口(通过 `ai.memory` 访问)
|
|
2006
|
-
*
|
|
2007
|
-
* 在核心操作基础上增加:
|
|
2008
|
-
* - `scoped(binding)`:返回自动绑定 objectId / scope 的安全实例(多租户推荐入口);
|
|
2009
|
-
* - `admin`:承载危险的全局操作(如 `clearAll`);
|
|
2010
|
-
* - `clear`:拒绝空过滤调用(无 objectId / types / scope 时返回错误),防止误清全局。
|
|
2011
|
-
*/
|
|
2012
|
-
interface MemoryOperations extends MemoryCoreOperations {
|
|
2013
|
-
/**
|
|
2014
|
-
* 创建绑定作用域的记忆实例
|
|
2015
|
-
*
|
|
2016
|
-
* @param binding - 作用域绑定(objectId + 可选 scope)
|
|
2017
|
-
* @returns 所有操作自动携带该作用域的记忆实例
|
|
2018
|
-
*/
|
|
2019
|
-
scoped: (binding: ScopedMemoryBinding) => ScopedMemoryOperations;
|
|
2020
|
-
/** 管理接口(危险的全局操作,需显式确认) */
|
|
2021
|
-
admin: MemoryAdminOperations;
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
|
-
/**
|
|
2025
|
-
* @h-ai/ai — 错误码 + 配置 Schema
|
|
2026
|
-
*
|
|
2027
|
-
* 定义 AI 模块的错误码常量、Zod Schema 和配置类型。
|
|
2028
|
-
* @module ai-config
|
|
2029
|
-
*/
|
|
2030
|
-
|
|
2031
|
-
/**
|
|
2032
|
-
* 可选密钥 Schema。
|
|
2033
|
-
*
|
|
2034
|
-
* 配置文件中的空插值、空白字符串或 YAML null 都表示“未配置”,输出统一为 undefined;
|
|
2035
|
-
* 非空密钥保持原值,避免模块调用方重复编写兼容清洗逻辑。
|
|
2036
|
-
*/
|
|
2037
|
-
declare const OptionalSecretSchema: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2038
|
-
/**
|
|
2039
|
-
* 模型场景枚举
|
|
2040
|
-
*
|
|
2041
|
-
* 预定义的模型使用场景,用于自动选择合适的模型。
|
|
2042
|
-
*
|
|
2043
|
-
* - `default` — 默认场景(兜底)
|
|
2044
|
-
* - `chat` — 对话场景
|
|
2045
|
-
* - `reasoning` — 推理场景(ReAct、CoT,需要强逻辑能力)
|
|
2046
|
-
* - `plan` — Plan-Execute 规划阶段(需要强推理)
|
|
2047
|
-
* - `execute` — Plan-Execute 执行阶段(需要工具调用能力)
|
|
2048
|
-
* - `extraction` — 信息提取场景(记忆提取、实体抽取)
|
|
2049
|
-
* - `summary` — 摘要/压缩场景(上下文摘要)
|
|
2050
|
-
* - `embedding` — 向量嵌入场景
|
|
2051
|
-
* - `rerank` — 文档重排序场景
|
|
2052
|
-
* - `ocr` — 图片 OCR 识别场景(视觉模型)
|
|
2053
|
-
* - `fast` — 快速响应场景(低延迟优先)
|
|
2054
|
-
*/
|
|
2055
|
-
declare const ModelScenarioSchema: z.ZodEnum<{
|
|
2056
|
-
chat: "chat";
|
|
2057
|
-
default: "default";
|
|
2058
|
-
reasoning: "reasoning";
|
|
2059
|
-
plan: "plan";
|
|
2060
|
-
execute: "execute";
|
|
2061
|
-
extraction: "extraction";
|
|
2062
|
-
summary: "summary";
|
|
2063
|
-
embedding: "embedding";
|
|
2064
|
-
rerank: "rerank";
|
|
2065
|
-
ocr: "ocr";
|
|
2066
|
-
fast: "fast";
|
|
2067
|
-
}>;
|
|
2068
|
-
/** 模型场景类型 */
|
|
2069
|
-
type ModelScenario = z.infer<typeof ModelScenarioSchema>;
|
|
2070
|
-
/**
|
|
2071
|
-
* LLM API 协议枚举
|
|
2072
|
-
*
|
|
2073
|
-
* 决定底层通过哪种 API 协议与模型交互(对使用方透明,公共请求/响应形状保持一致):
|
|
2074
|
-
*
|
|
2075
|
-
* - `chat` — OpenAI Chat Completions API(`/v1/chat/completions`,默认,兼容绝大多数厂商)
|
|
2076
|
-
* - `responses` — OpenAI Responses API(`/v1/responses`,新一代有状态接口)
|
|
2077
|
-
* - `anthropic` — Anthropic Messages API(Claude 原生协议,需安装 `@anthropic-ai/sdk`)
|
|
2078
|
-
*/
|
|
2079
|
-
declare const ApiTypeSchema: z.ZodEnum<{
|
|
2080
|
-
chat: "chat";
|
|
2081
|
-
responses: "responses";
|
|
2082
|
-
anthropic: "anthropic";
|
|
2083
|
-
}>;
|
|
2084
|
-
/** LLM API 协议类型 */
|
|
2085
|
-
type ApiType = z.infer<typeof ApiTypeSchema>;
|
|
2086
|
-
/**
|
|
2087
|
-
* 模型条目 Schema
|
|
2088
|
-
*
|
|
2089
|
-
* 定义单个模型的配置信息,包含唯一 ID、模型名称和可选参数覆盖。
|
|
2090
|
-
*
|
|
2091
|
-
* @example
|
|
2092
|
-
* ```ts
|
|
2093
|
-
* const model = {
|
|
2094
|
-
* id: 'gpt-4o',
|
|
2095
|
-
* model: 'gpt-4o',
|
|
2096
|
-
* maxTokens: 8192,
|
|
2097
|
-
* temperature: 0.3,
|
|
2098
|
-
* }
|
|
2099
|
-
* ```
|
|
2100
|
-
*/
|
|
2101
|
-
declare const ModelEntrySchema: z.ZodObject<{
|
|
2102
|
-
id: z.ZodString;
|
|
2103
|
-
model: z.ZodString;
|
|
2104
|
-
api: z.ZodOptional<z.ZodEnum<{
|
|
2105
|
-
chat: "chat";
|
|
2106
|
-
responses: "responses";
|
|
2107
|
-
anthropic: "anthropic";
|
|
2108
|
-
}>>;
|
|
2109
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2110
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2111
|
-
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
2112
|
-
temperature: z.ZodOptional<z.ZodNumber>;
|
|
2113
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2114
|
-
}, z.core.$strip>;
|
|
2115
|
-
/** 模型条目类型 */
|
|
2116
|
-
type ModelEntry = z.infer<typeof ModelEntrySchema>;
|
|
2117
|
-
/**
|
|
2118
|
-
* LLM 配置 Schema
|
|
2119
|
-
*
|
|
2120
|
-
* 配置大模型调用参数:模型名称、API Key、Base URL、温度等。
|
|
2121
|
-
* 支持多模型注册和场景映射。
|
|
2122
|
-
*
|
|
2123
|
-
* 顶层 `apiKey`、`baseUrl`、`maxTokens`、`temperature`、`timeout` 作为全局默认值,
|
|
2124
|
-
* 当 `models` 条目中未指定对应字段时,自动回退到这些全局默认值。
|
|
2125
|
-
* 通过 `resolveModelEntry()` 统一解析。
|
|
2126
|
-
*
|
|
2127
|
-
* @example
|
|
2128
|
-
* ```ts
|
|
2129
|
-
* const llmConfig = {
|
|
2130
|
-
* // 全局默认值(各模型未指定时回退到此处)
|
|
2131
|
-
* apiKey: 'sk-xxx',
|
|
2132
|
-
* baseUrl: 'https://api.openai.com/v1',
|
|
2133
|
-
* model: 'gpt-4o-mini',
|
|
2134
|
-
* maxTokens: 4096,
|
|
2135
|
-
* temperature: 0.7,
|
|
2136
|
-
* timeout: 60000,
|
|
2137
|
-
* // 多模型注册(各字段可选,未指定时回退到全局默认值)
|
|
2138
|
-
* models: [
|
|
2139
|
-
* { id: 'fast', model: 'gpt-4o-mini', temperature: 0.3 },
|
|
2140
|
-
* { id: 'strong', model: 'gpt-4o', maxTokens: 8192 },
|
|
2141
|
-
* { id: 'rerank', model: 'rerank-english-v3.0', baseUrl: 'https://api.cohere.com' },
|
|
2142
|
-
* ],
|
|
2143
|
-
* // 场景映射(场景名 → 模型 ID 或模型名称)
|
|
2144
|
-
* scenarios: { chat: 'fast', reasoning: 'strong', rerank: 'rerank' },
|
|
2145
|
-
* }
|
|
2146
|
-
* ```
|
|
2147
|
-
*/
|
|
2148
|
-
declare const LLMConfigSchema: z.ZodObject<{
|
|
2149
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2150
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2151
|
-
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2152
|
-
api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
2153
|
-
chat: "chat";
|
|
2154
|
-
responses: "responses";
|
|
2155
|
-
anthropic: "anthropic";
|
|
2156
|
-
}>>>;
|
|
2157
|
-
maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2158
|
-
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2159
|
-
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2160
|
-
tempModelCacheTtl: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2161
|
-
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2162
|
-
id: z.ZodString;
|
|
2163
|
-
model: z.ZodString;
|
|
2164
|
-
api: z.ZodOptional<z.ZodEnum<{
|
|
2165
|
-
chat: "chat";
|
|
2166
|
-
responses: "responses";
|
|
2167
|
-
anthropic: "anthropic";
|
|
2168
|
-
}>>;
|
|
2169
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2170
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2171
|
-
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
2172
|
-
temperature: z.ZodOptional<z.ZodNumber>;
|
|
2173
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2174
|
-
}, z.core.$strip>>>;
|
|
2175
|
-
scenarios: z.ZodOptional<z.ZodObject<{
|
|
2176
|
-
chat: z.ZodOptional<z.ZodString>;
|
|
2177
|
-
default: z.ZodOptional<z.ZodString>;
|
|
2178
|
-
reasoning: z.ZodOptional<z.ZodString>;
|
|
2179
|
-
plan: z.ZodOptional<z.ZodString>;
|
|
2180
|
-
execute: z.ZodOptional<z.ZodString>;
|
|
2181
|
-
extraction: z.ZodOptional<z.ZodString>;
|
|
2182
|
-
summary: z.ZodOptional<z.ZodString>;
|
|
2183
|
-
embedding: z.ZodOptional<z.ZodString>;
|
|
2184
|
-
rerank: z.ZodOptional<z.ZodString>;
|
|
2185
|
-
ocr: z.ZodOptional<z.ZodString>;
|
|
2186
|
-
fast: z.ZodOptional<z.ZodString>;
|
|
2187
|
-
}, z.core.$strip>>;
|
|
2188
|
-
}, z.core.$strip>;
|
|
2189
|
-
/** LLM 配置类型 */
|
|
2190
|
-
type LLMConfig = z.infer<typeof LLMConfigSchema>;
|
|
2191
|
-
/**
|
|
2192
|
-
* 已解析的模型配置
|
|
2193
|
-
*
|
|
2194
|
-
* 由 `resolveModelEntry()` 返回,包含模型名称和完整的参数配置(已合并全局默认值和环境变量)。
|
|
2195
|
-
*/
|
|
2196
|
-
interface ResolvedModelConfig {
|
|
2197
|
-
/** 模型名称(传给 API 的实际模型名) */
|
|
2198
|
-
model: string;
|
|
2199
|
-
/** API 协议(模型条目 > 全局配置 > `chat`) */
|
|
2200
|
-
api: ApiType;
|
|
2201
|
-
/** API Key(模型条目 > 全局配置 > 环境变量) */
|
|
2202
|
-
apiKey: string | undefined;
|
|
2203
|
-
/** API 基础 URL(模型条目 > 全局配置 > 环境变量 > 默认 OpenAI) */
|
|
2204
|
-
baseUrl: string;
|
|
2205
|
-
/** 最大 Token 数(模型条目 > 全局配置) */
|
|
2206
|
-
maxTokens: number;
|
|
2207
|
-
/** 采样温度(模型条目 > 全局配置) */
|
|
2208
|
-
temperature: number;
|
|
2209
|
-
/** 请求超时时间(毫秒)(模型条目 > 全局配置) */
|
|
2210
|
-
timeout: number;
|
|
2211
|
-
}
|
|
2212
|
-
/**
|
|
2213
|
-
* 必需模型解析选项
|
|
2214
|
-
*/
|
|
2215
|
-
interface ResolveRequiredModelEntryOptions {
|
|
2216
|
-
/** 缺少 API Key 时的自定义错误消息 */
|
|
2217
|
-
missingApiKeyMessage?: string;
|
|
2218
|
-
}
|
|
2219
|
-
/**
|
|
2220
|
-
* 根据场景解析完整模型配置,并要求必须存在 API Key
|
|
2221
|
-
*
|
|
2222
|
-
* 用于需要访问远程模型 API 的场景,避免各子模块重复编写
|
|
2223
|
-
* `if (!resolved.apiKey)` 之类的配置校验逻辑。
|
|
2224
|
-
*
|
|
2225
|
-
* @param llmConfig - LLM 配置
|
|
2226
|
-
* @param scenario - 使用场景
|
|
2227
|
-
* @param explicit - 调用方显式指定的模型名称(最高优先级)
|
|
2228
|
-
* @param options - 必需校验选项
|
|
2229
|
-
* @returns 成功返回已解析模型配置,失败返回 `CONFIGURATION_ERROR`
|
|
2230
|
-
*/
|
|
2231
|
-
declare function resolveModelEntry(llmConfig: LLMConfig, scenario: ModelScenario, explicit?: string, options?: ResolveRequiredModelEntryOptions): HaiResult<ResolvedModelConfig>;
|
|
2232
|
-
/**
|
|
2233
|
-
* 解析某次 chat 请求应使用的 API 协议(不校验 API Key)
|
|
2234
|
-
*
|
|
2235
|
-
* 供 LLM Provider 路由层选择底层实现使用:优先取显式模型条目的 `api`,
|
|
2236
|
-
* 其次全局 `api`,最后回退 `chat`。临时模型的 `api` 由调用方单独传入优先。
|
|
2237
|
-
*
|
|
2238
|
-
* @param llmConfig - LLM 配置
|
|
2239
|
-
* @param explicitModel - 显式指定的模型名/ID(可选)
|
|
2240
|
-
* @param tempApi - 临时模型显式指定的 API 协议(可选,最高优先级)
|
|
2241
|
-
* @returns 解析出的 API 协议
|
|
2242
|
-
*/
|
|
2243
|
-
declare function resolveModelApi(llmConfig: LLMConfig, explicitModel?: string, tempApi?: ApiType): ApiType;
|
|
2244
|
-
/** MCP 服务器能力 Schema */
|
|
2245
|
-
declare const MCPServerCapabilitiesSchema: z.ZodObject<{
|
|
2246
|
-
tools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2247
|
-
resources: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2248
|
-
prompts: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2249
|
-
}, z.core.$strip>;
|
|
2250
|
-
/** MCP 服务器能力类型 */
|
|
2251
|
-
type MCPServerCapabilities = z.infer<typeof MCPServerCapabilitiesSchema>;
|
|
2252
|
-
/** MCP 服务器配置 Schema */
|
|
2253
|
-
declare const MCPServerConfigSchema: z.ZodObject<{
|
|
2254
|
-
name: z.ZodString;
|
|
2255
|
-
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2256
|
-
capabilities: z.ZodOptional<z.ZodObject<{
|
|
2257
|
-
tools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2258
|
-
resources: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2259
|
-
prompts: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2260
|
-
}, z.core.$strip>>;
|
|
2261
|
-
}, z.core.$strip>;
|
|
2262
|
-
/** MCP 服务器配置类型 */
|
|
2263
|
-
type MCPServerConfig = z.infer<typeof MCPServerConfigSchema>;
|
|
2264
|
-
/**
|
|
2265
|
-
* MCP 配置 Schema
|
|
2266
|
-
*
|
|
2267
|
-
* 配置 MCP(Model Context Protocol)服务器参数。
|
|
2268
|
-
*
|
|
2269
|
-
* @example
|
|
2270
|
-
* ```ts
|
|
2271
|
-
* const mcpConfig = {
|
|
2272
|
-
* server: {
|
|
2273
|
-
* name: 'my-app',
|
|
2274
|
-
* version: '1.0.0',
|
|
2275
|
-
* capabilities: { tools: true, resources: true, prompts: true },
|
|
2276
|
-
* },
|
|
2277
|
-
* }
|
|
2278
|
-
* ```
|
|
2279
|
-
*/
|
|
2280
|
-
declare const MCPConfigSchema: z.ZodObject<{
|
|
2281
|
-
server: z.ZodOptional<z.ZodObject<{
|
|
2282
|
-
name: z.ZodString;
|
|
2283
|
-
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2284
|
-
capabilities: z.ZodOptional<z.ZodObject<{
|
|
2285
|
-
tools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2286
|
-
resources: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2287
|
-
prompts: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2288
|
-
}, z.core.$strip>>;
|
|
2289
|
-
}, z.core.$strip>>;
|
|
2290
|
-
}, z.core.$strip>;
|
|
2291
|
-
/** MCP 配置类型 */
|
|
2292
|
-
type MCPConfig = z.infer<typeof MCPConfigSchema>;
|
|
2293
|
-
/**
|
|
2294
|
-
* Embedding 配置 Schema
|
|
2295
|
-
*
|
|
2296
|
-
* 配置文本向量化参数。
|
|
2297
|
-
* 模型通过 LLMConfigSchema.scenarios.embedding 解析,
|
|
2298
|
-
* apiKey / baseUrl 统一使用 LLM 配置。
|
|
2299
|
-
*
|
|
2300
|
-
* @example
|
|
2301
|
-
* ```ts
|
|
2302
|
-
* const embeddingConfig = {
|
|
2303
|
-
* dimensions: 1536,
|
|
2304
|
-
* batchSize: 100,
|
|
2305
|
-
* }
|
|
2306
|
-
* ```
|
|
2307
|
-
*/
|
|
2308
|
-
declare const EmbeddingConfigSchema: z.ZodObject<{
|
|
2309
|
-
dimensions: z.ZodOptional<z.ZodNumber>;
|
|
2310
|
-
batchSize: z.ZodDefault<z.ZodNumber>;
|
|
2311
|
-
}, z.core.$strip>;
|
|
2312
|
-
/** Embedding 配置类型 */
|
|
2313
|
-
type EmbeddingConfig = z.infer<typeof EmbeddingConfigSchema>;
|
|
2314
|
-
|
|
2315
|
-
/**
|
|
2316
|
-
* Knowledge 配置 Schema
|
|
2317
|
-
*
|
|
2318
|
-
* 配置知识库管理参数:向量集合、分块策略、实体提取等。
|
|
2319
|
-
* 模型通过 LLMConfigSchema.scenarios 解析,
|
|
2320
|
-
* apiKey / baseUrl 统一使用 LLM 配置。
|
|
2321
|
-
*
|
|
2322
|
-
* @example
|
|
2323
|
-
* ```ts
|
|
2324
|
-
* const knowledgeConfig = {
|
|
2325
|
-
* collection: 'my-knowledge',
|
|
2326
|
-
* dimension: 1536,
|
|
2327
|
-
* enableEntityExtraction: true
|
|
2328
|
-
* }
|
|
2329
|
-
* ```
|
|
2330
|
-
*/
|
|
2331
|
-
declare const KnowledgeConfigSchema: z.ZodObject<{
|
|
2332
|
-
collection: z.ZodDefault<z.ZodString>;
|
|
2333
|
-
dimension: z.ZodDefault<z.ZodNumber>;
|
|
2334
|
-
enableEntityExtraction: z.ZodDefault<z.ZodBoolean>;
|
|
2335
|
-
cleanOptions: z.ZodDefault<z.ZodObject<{
|
|
2336
|
-
removeHtml: z.ZodDefault<z.ZodBoolean>;
|
|
2337
|
-
removeUrls: z.ZodDefault<z.ZodBoolean>;
|
|
2338
|
-
removeEmails: z.ZodDefault<z.ZodBoolean>;
|
|
2339
|
-
normalizeWhitespace: z.ZodDefault<z.ZodBoolean>;
|
|
2340
|
-
trim: z.ZodDefault<z.ZodBoolean>;
|
|
2341
|
-
customReplacements: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2342
|
-
pattern: z.ZodString;
|
|
2343
|
-
replacement: z.ZodString;
|
|
2344
|
-
}, z.core.$strip>>>;
|
|
2345
|
-
}, z.core.$strip>>;
|
|
2346
|
-
chunkOptions: z.ZodDefault<z.ZodObject<{
|
|
2347
|
-
mode: z.ZodEnum<{
|
|
2348
|
-
custom: "custom";
|
|
2349
|
-
sentence: "sentence";
|
|
2350
|
-
paragraph: "paragraph";
|
|
2351
|
-
markdown: "markdown";
|
|
2352
|
-
page: "page";
|
|
2353
|
-
word: "word";
|
|
2354
|
-
character: "character";
|
|
2355
|
-
}>;
|
|
2356
|
-
maxSize: z.ZodDefault<z.ZodNumber>;
|
|
2357
|
-
overlap: z.ZodDefault<z.ZodNumber>;
|
|
2358
|
-
separator: z.ZodOptional<z.ZodString>;
|
|
2359
|
-
markdownMinLevel: z.ZodDefault<z.ZodNumber>;
|
|
2360
|
-
markdownKeepTitle: z.ZodDefault<z.ZodBoolean>;
|
|
2361
|
-
}, z.core.$strip>>;
|
|
2362
|
-
entityBoostWeight: z.ZodDefault<z.ZodNumber>;
|
|
2363
|
-
entityTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
2364
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2365
|
-
}, z.core.$strip>;
|
|
2366
|
-
/** Knowledge 配置类型 */
|
|
2367
|
-
type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
|
|
2368
|
-
|
|
2369
|
-
/**
|
|
2370
|
-
* Memory 配置 Schema
|
|
2371
|
-
*
|
|
2372
|
-
* 配置对话记忆的提取、存储与检索参数。两种 provider 均为嵌入式,复用同一套
|
|
2373
|
-
* vecdb / reldb / LLM / Embedding;模型通过 LLMConfigSchema.scenarios.extraction
|
|
2374
|
-
* 解析,apiKey / baseUrl 统一使用 LLM 配置。
|
|
2375
|
-
*
|
|
2376
|
-
* @example
|
|
2377
|
-
* ```ts
|
|
2378
|
-
* const memoryConfig = {
|
|
2379
|
-
* provider: 'native',
|
|
2380
|
-
* maxEntriesPerObject: 1000,
|
|
2381
|
-
* maxEntriesGlobal: 100000,
|
|
2382
|
-
* embeddingEnabled: true,
|
|
2383
|
-
* recencyDecay: 0.95,
|
|
2384
|
-
* defaultTopK: 10,
|
|
2385
|
-
* }
|
|
2386
|
-
* ```
|
|
2387
|
-
*/
|
|
2388
|
-
declare const MemoryConfigSchema: z.ZodObject<{
|
|
2389
|
-
provider: z.ZodDefault<z.ZodEnum<{
|
|
2390
|
-
native: "native";
|
|
2391
|
-
mem0: "mem0";
|
|
2392
|
-
}>>;
|
|
2393
|
-
allowEphemeralFallback: z.ZodDefault<z.ZodBoolean>;
|
|
2394
|
-
maxEntriesPerObject: z.ZodDefault<z.ZodNumber>;
|
|
2395
|
-
maxEntriesGlobal: z.ZodDefault<z.ZodNumber>;
|
|
2396
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2397
|
-
recencyDecay: z.ZodDefault<z.ZodNumber>;
|
|
2398
|
-
embeddingEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
2399
|
-
defaultTopK: z.ZodDefault<z.ZodNumber>;
|
|
2400
|
-
candidateMultiplier: z.ZodDefault<z.ZodNumber>;
|
|
2401
|
-
writebackRelatedTopK: z.ZodDefault<z.ZodNumber>;
|
|
2402
|
-
}, z.core.$strip>;
|
|
2403
|
-
/** Memory 配置类型 */
|
|
2404
|
-
type MemoryConfig = z.infer<typeof MemoryConfigSchema>;
|
|
2405
|
-
|
|
2406
|
-
/**
|
|
2407
|
-
* Token 配置 Schema
|
|
2408
|
-
*
|
|
2409
|
-
* 配置 Token 估算参数。
|
|
2410
|
-
*
|
|
2411
|
-
* @example
|
|
2412
|
-
* ```ts
|
|
2413
|
-
* const tokenConfig = { tokenRatio: 0.25 }
|
|
2414
|
-
* ```
|
|
2415
|
-
*/
|
|
2416
|
-
declare const TokenConfigSchema: z.ZodObject<{
|
|
2417
|
-
tokenRatio: z.ZodDefault<z.ZodNumber>;
|
|
2418
|
-
}, z.core.$strip>;
|
|
2419
|
-
/** Token 配置类型 */
|
|
2420
|
-
type TokenConfig = z.infer<typeof TokenConfigSchema>;
|
|
2421
|
-
/**
|
|
2422
|
-
* Summary 配置 Schema
|
|
2423
|
-
*
|
|
2424
|
-
* 配置摘要生成参数。
|
|
2425
|
-
* 模型通过 LLMConfigSchema.scenarios.summary 解析,
|
|
2426
|
-
* apiKey / baseUrl 统一使用 LLM 配置。
|
|
2427
|
-
*
|
|
2428
|
-
* @example
|
|
2429
|
-
* ```ts
|
|
2430
|
-
* const summaryConfig = { systemPrompt: 'You are a summarizer.' }
|
|
2431
|
-
* ```
|
|
2432
|
-
*/
|
|
2433
|
-
declare const SummaryConfigSchema: z.ZodObject<{
|
|
2434
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2435
|
-
}, z.core.$strip>;
|
|
2436
|
-
/** Summary 配置类型 */
|
|
2437
|
-
type SummaryConfig = z.infer<typeof SummaryConfigSchema>;
|
|
2438
|
-
/**
|
|
2439
|
-
* Compress 配置 Schema
|
|
2440
|
-
*
|
|
2441
|
-
* 配置上下文压缩参数:压缩策略、Token 预算、保留消息数。
|
|
2442
|
-
*
|
|
2443
|
-
* @example
|
|
2444
|
-
* ```ts
|
|
2445
|
-
* const compressConfig = {
|
|
2446
|
-
* defaultStrategy: 'hybrid',
|
|
2447
|
-
* defaultMaxTokens: 4000,
|
|
2448
|
-
* preserveLastN: 4,
|
|
2449
|
-
* }
|
|
2450
|
-
* ```
|
|
2451
|
-
*/
|
|
2452
|
-
declare const CompressConfigSchema: z.ZodObject<{
|
|
2453
|
-
defaultStrategy: z.ZodDefault<z.ZodEnum<{
|
|
2454
|
-
summary: "summary";
|
|
2455
|
-
"sliding-window": "sliding-window";
|
|
2456
|
-
hybrid: "hybrid";
|
|
2457
|
-
}>>;
|
|
2458
|
-
defaultMaxTokens: z.ZodDefault<z.ZodNumber>;
|
|
2459
|
-
preserveLastN: z.ZodDefault<z.ZodNumber>;
|
|
2460
|
-
}, z.core.$strip>;
|
|
2461
|
-
/** Compress 配置类型 */
|
|
2462
|
-
type CompressConfig = z.infer<typeof CompressConfigSchema>;
|
|
2463
|
-
/**
|
|
2464
|
-
* File 配置 Schema
|
|
2465
|
-
*
|
|
2466
|
-
* 配置文件解析参数:OCR 提示词。
|
|
2467
|
-
* OCR 使用的视觉模型通过 `llm.scenarios.ocr` 指定。
|
|
2468
|
-
*/
|
|
2469
|
-
declare const FileConfigSchema: z.ZodObject<{
|
|
2470
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2471
|
-
}, z.core.$strip>;
|
|
2472
|
-
/** File 配置类型 */
|
|
2473
|
-
type FileConfig = z.infer<typeof FileConfigSchema>;
|
|
2474
|
-
/**
|
|
2475
|
-
* 检索源配置 Schema
|
|
2476
|
-
*
|
|
2477
|
-
* 与 `RetrievalSource` 接口字段对齐,支持在 `ai.init()` 中预注册检索源。
|
|
2478
|
-
*/
|
|
2479
|
-
declare const RetrievalSourceSchema: z.ZodObject<{
|
|
2480
|
-
id: z.ZodString;
|
|
2481
|
-
collection: z.ZodString;
|
|
2482
|
-
name: z.ZodOptional<z.ZodString>;
|
|
2483
|
-
url: z.ZodOptional<z.ZodString>;
|
|
2484
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
2485
|
-
minScore: z.ZodOptional<z.ZodNumber>;
|
|
2486
|
-
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2487
|
-
}, z.core.$strip>;
|
|
2488
|
-
/** 检索源配置类型 */
|
|
2489
|
-
type RetrievalSourceConfig = z.infer<typeof RetrievalSourceSchema>;
|
|
2490
|
-
/**
|
|
2491
|
-
* Retrieval 配置 Schema
|
|
2492
|
-
*
|
|
2493
|
-
* 在 `ai.init()` 时预注册检索源,等价于初始化后逐条调用 `ai.retrieval.addSource()`。
|
|
2494
|
-
*
|
|
2495
|
-
* @example
|
|
2496
|
-
* ```ts
|
|
2497
|
-
* ai.init({
|
|
2498
|
-
* llm: { apiKey: 'sk-xxx', model: 'gpt-4o-mini' },
|
|
2499
|
-
* retrieval: {
|
|
2500
|
-
* sources: [
|
|
2501
|
-
* { id: 'docs', collection: 'documentation', name: '产品文档', topK: 5, minScore: 0.7 },
|
|
2502
|
-
* { id: 'faq', collection: 'faq', name: '常见问题' },
|
|
2503
|
-
* ],
|
|
2504
|
-
* },
|
|
2505
|
-
* })
|
|
2506
|
-
* ```
|
|
2507
|
-
*/
|
|
2508
|
-
declare const RetrievalConfigSchema: z.ZodObject<{
|
|
2509
|
-
sources: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2510
|
-
id: z.ZodString;
|
|
2511
|
-
collection: z.ZodString;
|
|
2512
|
-
name: z.ZodOptional<z.ZodString>;
|
|
2513
|
-
url: z.ZodOptional<z.ZodString>;
|
|
2514
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
2515
|
-
minScore: z.ZodOptional<z.ZodNumber>;
|
|
2516
|
-
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2517
|
-
}, z.core.$strip>>>;
|
|
2518
|
-
}, z.core.$strip>;
|
|
2519
|
-
/** Retrieval 配置类型 */
|
|
2520
|
-
type RetrievalConfig = z.infer<typeof RetrievalConfigSchema>;
|
|
2521
|
-
/** A2A Agent Skill 配置 Schema */
|
|
2522
|
-
declare const A2ASkillConfigSchema: z.ZodObject<{
|
|
2523
|
-
id: z.ZodString;
|
|
2524
|
-
name: z.ZodString;
|
|
2525
|
-
description: z.ZodOptional<z.ZodString>;
|
|
2526
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
2527
|
-
}, z.core.$strip>;
|
|
2528
|
-
/**
|
|
2529
|
-
* A2A 配置 Schema
|
|
2530
|
-
*
|
|
2531
|
-
* 配置 Agent-to-Agent 协议参数:Agent Card、认证等。
|
|
2532
|
-
*
|
|
2533
|
-
* @example
|
|
2534
|
-
* ```ts
|
|
2535
|
-
* ai.init({
|
|
2536
|
-
* llm: { apiKey: 'sk-xxx', model: 'gpt-4o-mini' },
|
|
2537
|
-
* a2a: {
|
|
2538
|
-
* agentCard: {
|
|
2539
|
-
* name: 'my-agent',
|
|
2540
|
-
* description: 'An example agent',
|
|
2541
|
-
* url: 'https://example.com',
|
|
2542
|
-
* skills: [{ id: 'chat', name: 'General Chat' }],
|
|
2543
|
-
* },
|
|
2544
|
-
* },
|
|
2545
|
-
* })
|
|
2546
|
-
* ```
|
|
2547
|
-
*/
|
|
2548
|
-
declare const A2AConfigSchema: z.ZodObject<{
|
|
2549
|
-
agentCard: z.ZodObject<{
|
|
2550
|
-
name: z.ZodString;
|
|
2551
|
-
description: z.ZodOptional<z.ZodString>;
|
|
2552
|
-
url: z.ZodString;
|
|
2553
|
-
version: z.ZodOptional<z.ZodString>;
|
|
2554
|
-
skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2555
|
-
id: z.ZodString;
|
|
2556
|
-
name: z.ZodString;
|
|
2557
|
-
description: z.ZodOptional<z.ZodString>;
|
|
2558
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
2559
|
-
}, z.core.$strip>>>;
|
|
2560
|
-
}, z.core.$strip>;
|
|
2561
|
-
security: z.ZodOptional<z.ZodObject<{
|
|
2562
|
-
apiKey: z.ZodOptional<z.ZodObject<{
|
|
2563
|
-
in: z.ZodDefault<z.ZodEnum<{
|
|
2564
|
-
header: "header";
|
|
2565
|
-
query: "query";
|
|
2566
|
-
}>>;
|
|
2567
|
-
name: z.ZodDefault<z.ZodString>;
|
|
2568
|
-
}, z.core.$strip>>;
|
|
2569
|
-
}, z.core.$strip>>;
|
|
2570
|
-
}, z.core.$strip>;
|
|
2571
|
-
/** A2A 配置类型 */
|
|
2572
|
-
type A2AConfig = z.infer<typeof A2AConfigSchema>;
|
|
2573
|
-
/**
|
|
2574
|
-
* 语音平台枚举
|
|
2575
|
-
*
|
|
2576
|
-
* 决定 `ai.audio` 底层调用哪个厂商 / 协议(对使用方透明,公共请求/响应形状保持一致):
|
|
2577
|
-
*
|
|
2578
|
-
* - `openai` — OpenAI Audio API(transcriptions / speech)
|
|
2579
|
-
* - `mimo` — 小米 MiMo(Chat Completions 风格 ASR / TTS)
|
|
2580
|
-
* - `qwen` — 阿里云百炼 Qwen Realtime(DashScope WebSocket ASR / TTS)
|
|
2581
|
-
* - `doubao` — 火山引擎豆包语音(二进制 WebSocket ASR / TTS)
|
|
2582
|
-
* - `whisper` — hai-framework Whisper Service 协议(HTTP 文件识别,可自托管)
|
|
2583
|
-
* - `indextts` — hai-framework IndexTTS Service 协议(HTTP 合成,可自托管)
|
|
2584
|
-
*
|
|
2585
|
-
* 平台仅表示「用哪种协议调用」,不表示服务部署在哪里;`whisper` / `indextts` 需显式配置 `baseUrl`。
|
|
2586
|
-
*/
|
|
2587
|
-
declare const AudioProviderSchema: z.ZodEnum<{
|
|
2588
|
-
openai: "openai";
|
|
2589
|
-
mimo: "mimo";
|
|
2590
|
-
qwen: "qwen";
|
|
2591
|
-
doubao: "doubao";
|
|
2592
|
-
whisper: "whisper";
|
|
2593
|
-
indextts: "indextts";
|
|
2594
|
-
}>;
|
|
2595
|
-
/** 语音平台类型 */
|
|
2596
|
-
type AudioProviderName = z.infer<typeof AudioProviderSchema>;
|
|
2597
|
-
/** 单个语音操作类型 */
|
|
2598
|
-
declare const AudioOperationSchema: z.ZodEnum<{
|
|
2599
|
-
transcribe: "transcribe";
|
|
2600
|
-
synthesize: "synthesize";
|
|
2601
|
-
}>;
|
|
2602
|
-
/** 语音操作类型 */
|
|
2603
|
-
type AudioOperation = z.infer<typeof AudioOperationSchema>;
|
|
2604
|
-
/**
|
|
2605
|
-
* 语音模型允许的操作列表
|
|
2606
|
-
*
|
|
2607
|
-
* 至少一项,且不允许重复。
|
|
2608
|
-
*/
|
|
2609
|
-
declare const AudioOperationsSchema: z.ZodArray<z.ZodEnum<{
|
|
2610
|
-
transcribe: "transcribe";
|
|
2611
|
-
synthesize: "synthesize";
|
|
2612
|
-
}>>;
|
|
2613
|
-
/**
|
|
2614
|
-
* 语音模型条目 Schema
|
|
2615
|
-
*
|
|
2616
|
-
* 定义单个语音模型:唯一 ID、所属平台、厂商模型名及凭据。凭据未提供时回退到对应平台的环境变量。
|
|
2617
|
-
*
|
|
2618
|
-
* @example
|
|
2619
|
-
* ```ts
|
|
2620
|
-
* const model = { id: 'asr', provider: 'qwen', model: 'qwen3-asr-flash-realtime', operations: ['transcribe'] }
|
|
2621
|
-
* ```
|
|
2622
|
-
*/
|
|
2623
|
-
declare const AudioModelEntrySchema: z.ZodObject<{
|
|
2624
|
-
id: z.ZodString;
|
|
2625
|
-
provider: z.ZodEnum<{
|
|
2626
|
-
openai: "openai";
|
|
2627
|
-
mimo: "mimo";
|
|
2628
|
-
qwen: "qwen";
|
|
2629
|
-
doubao: "doubao";
|
|
2630
|
-
whisper: "whisper";
|
|
2631
|
-
indextts: "indextts";
|
|
2632
|
-
}>;
|
|
2633
|
-
model: z.ZodString;
|
|
2634
|
-
operations: z.ZodArray<z.ZodEnum<{
|
|
2635
|
-
transcribe: "transcribe";
|
|
2636
|
-
synthesize: "synthesize";
|
|
2637
|
-
}>>;
|
|
2638
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2639
|
-
baseUrl: z.ZodOptional<z.ZodString>;
|
|
2640
|
-
appKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2641
|
-
accessKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2642
|
-
resourceId: z.ZodOptional<z.ZodString>;
|
|
2643
|
-
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2644
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2645
|
-
}, z.core.$strip>;
|
|
2646
|
-
/** 语音模型条目类型 */
|
|
2647
|
-
type AudioModelEntry = z.infer<typeof AudioModelEntrySchema>;
|
|
2648
|
-
/**
|
|
2649
|
-
* Audio 配置 Schema
|
|
2650
|
-
*
|
|
2651
|
-
* 注册语音模型并映射默认识别 / 合成模型。调用方通常无需指定模型,仅在临时切换时通过 `request.model` 覆盖。
|
|
2652
|
-
*
|
|
2653
|
-
* @example
|
|
2654
|
-
* ```ts
|
|
2655
|
-
* ai.init({
|
|
2656
|
-
* audio: {
|
|
2657
|
-
* models: [
|
|
2658
|
-
* { id: 'asr', provider: 'qwen', model: 'qwen3-asr-flash-realtime', operations: ['transcribe'] },
|
|
2659
|
-
* { id: 'tts', provider: 'qwen', model: 'qwen3-tts-flash-realtime', operations: ['synthesize'] },
|
|
2660
|
-
* ],
|
|
2661
|
-
* transcribeModel: 'asr',
|
|
2662
|
-
* synthesizeModel: 'tts',
|
|
2663
|
-
* },
|
|
2664
|
-
* })
|
|
2665
|
-
* ```
|
|
2666
|
-
*/
|
|
2667
|
-
declare const AudioConfigSchema: z.ZodObject<{
|
|
2668
|
-
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2669
|
-
id: z.ZodString;
|
|
2670
|
-
provider: z.ZodEnum<{
|
|
2671
|
-
openai: "openai";
|
|
2672
|
-
mimo: "mimo";
|
|
2673
|
-
qwen: "qwen";
|
|
2674
|
-
doubao: "doubao";
|
|
2675
|
-
whisper: "whisper";
|
|
2676
|
-
indextts: "indextts";
|
|
2677
|
-
}>;
|
|
2678
|
-
model: z.ZodString;
|
|
2679
|
-
operations: z.ZodArray<z.ZodEnum<{
|
|
2680
|
-
transcribe: "transcribe";
|
|
2681
|
-
synthesize: "synthesize";
|
|
2682
|
-
}>>;
|
|
2683
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2684
|
-
baseUrl: z.ZodOptional<z.ZodString>;
|
|
2685
|
-
appKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2686
|
-
accessKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2687
|
-
resourceId: z.ZodOptional<z.ZodString>;
|
|
2688
|
-
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2689
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2690
|
-
}, z.core.$strip>>>;
|
|
2691
|
-
inheritLlmApiKey: z.ZodDefault<z.ZodBoolean>;
|
|
2692
|
-
transcribeModel: z.ZodOptional<z.ZodString>;
|
|
2693
|
-
synthesizeModel: z.ZodOptional<z.ZodString>;
|
|
2694
|
-
maxAudioBytes: z.ZodDefault<z.ZodNumber>;
|
|
2695
|
-
maxStreamDurationMs: z.ZodDefault<z.ZodNumber>;
|
|
2696
|
-
}, z.core.$strip>;
|
|
2697
|
-
/** Audio 配置类型 */
|
|
2698
|
-
type AudioConfig = z.infer<typeof AudioConfigSchema>;
|
|
2699
|
-
/**
|
|
2700
|
-
* 已解析的语音模型配置
|
|
2701
|
-
*
|
|
2702
|
-
* 由 `resolveAudioModel()` 返回,凭据已按模型条目、显式 LLM 继承、平台环境变量的顺序解析,
|
|
2703
|
-
* 端点已应用平台默认值。
|
|
2704
|
-
*/
|
|
2705
|
-
interface ResolvedAudioModel {
|
|
2706
|
-
/** 模型条目 ID */
|
|
2707
|
-
id: string;
|
|
2708
|
-
/** 所属平台 */
|
|
2709
|
-
provider: AudioProviderName;
|
|
2710
|
-
/** 厂商模型名 */
|
|
2711
|
-
model: string;
|
|
2712
|
-
/** API Key(模型条目 > 显式启用的 LLM 密钥继承 > 平台环境变量) */
|
|
2713
|
-
apiKey: string | undefined;
|
|
2714
|
-
/** 端点(条目 > 平台默认) */
|
|
2715
|
-
baseUrl: string;
|
|
2716
|
-
/** 火山引擎 App Key */
|
|
2717
|
-
appKey: string | undefined;
|
|
2718
|
-
/** 火山引擎 Access Key */
|
|
2719
|
-
accessKey: string | undefined;
|
|
2720
|
-
/** 火山引擎资源 ID(条目 > 平台默认) */
|
|
2721
|
-
resourceId: string;
|
|
2722
|
-
/** 阿里云百炼业务空间 ID */
|
|
2723
|
-
workspaceId: string | undefined;
|
|
2724
|
-
/** 请求超时(毫秒) */
|
|
2725
|
-
timeout: number;
|
|
2726
|
-
}
|
|
2727
|
-
/**
|
|
2728
|
-
* 解析语音操作应使用的模型配置
|
|
2729
|
-
*
|
|
2730
|
-
* 解析优先级:请求显式 `model` > 场景默认(transcribe/synthesize);凭据回退到平台环境变量。
|
|
2731
|
-
*
|
|
2732
|
-
* @param audioConfig - Audio 配置
|
|
2733
|
-
* @param operation - 操作类型(识别 / 合成),决定使用哪个默认模型
|
|
2734
|
-
* @param explicit - 请求显式指定的模型 ID(最高优先级)
|
|
2735
|
-
* @param llmApiKey - LLM 全局密钥,仅在 `inheritLlmApiKey` 启用时参与解析
|
|
2736
|
-
* @returns 成功返回已解析模型;无匹配模型返回 `AUDIO_MODEL_NOT_FOUND`;缺少凭据返回 `CONFIGURATION_ERROR`
|
|
2737
|
-
*/
|
|
2738
|
-
declare function resolveAudioModel(audioConfig: AudioConfig, operation: 'transcribe' | 'synthesize', explicit?: string, llmApiKey?: string): HaiResult<ResolvedAudioModel>;
|
|
2739
|
-
/**
|
|
2740
|
-
* 校验已解析模型是否具备该平台协议所需的凭据
|
|
2741
|
-
*
|
|
2742
|
-
* 凭据是否必需由平台协议决定:自托管的 `whisper` / `indextts` 可无凭据;豆包允许 API Key
|
|
2743
|
-
* 或 App/Access Key 组合;其余云平台必须提供 API Key。仅在真正发起识别 / 合成前调用,
|
|
2744
|
-
* 能力查询(`getCapabilities`)不需要凭据。
|
|
2745
|
-
*
|
|
2746
|
-
* @param model - 已解析模型
|
|
2747
|
-
* @returns 缺少必需凭据时返回 `CONFIGURATION_ERROR`,否则返回 `null`
|
|
2748
|
-
*/
|
|
2749
|
-
declare function ensureAudioCredential(model: ResolvedAudioModel): HaiError | null;
|
|
2750
|
-
/**
|
|
2751
|
-
* 文生图平台枚举
|
|
2752
|
-
*
|
|
2753
|
-
* - `openai` — OpenAI GPT Image(Image API)
|
|
2754
|
-
* - `google` — Google Gemini Image / Nano Banana(Generate Content API)
|
|
2755
|
-
* - `qwen` — 阿里云百炼 Qwen-Image 2.0 / 3.0
|
|
2756
|
-
* - `seedream` — 火山方舟 Seedream 4.x / 5.x
|
|
2757
|
-
* - `pollinations` — Pollinations 免费额度图片 API
|
|
2758
|
-
*/
|
|
2759
|
-
declare const ImageProviderSchema: z.ZodEnum<{
|
|
2760
|
-
openai: "openai";
|
|
2761
|
-
qwen: "qwen";
|
|
2762
|
-
google: "google";
|
|
2763
|
-
seedream: "seedream";
|
|
2764
|
-
pollinations: "pollinations";
|
|
2765
|
-
}>;
|
|
2766
|
-
/** 文生图平台类型 */
|
|
2767
|
-
type ImageProviderName = z.infer<typeof ImageProviderSchema>;
|
|
2768
|
-
/** 文生图模型条目 Schema */
|
|
2769
|
-
declare const ImageModelEntrySchema: z.ZodObject<{
|
|
2770
|
-
id: z.ZodString;
|
|
2771
|
-
provider: z.ZodEnum<{
|
|
2772
|
-
openai: "openai";
|
|
2773
|
-
qwen: "qwen";
|
|
2774
|
-
google: "google";
|
|
2775
|
-
seedream: "seedream";
|
|
2776
|
-
pollinations: "pollinations";
|
|
2777
|
-
}>;
|
|
2778
|
-
model: z.ZodString;
|
|
2779
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2780
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2781
|
-
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2782
|
-
timeout: z.ZodDefault<z.ZodNumber>;
|
|
2783
|
-
}, z.core.$strip>;
|
|
2784
|
-
/** 文生图模型条目类型 */
|
|
2785
|
-
type ImageModelEntry = z.infer<typeof ImageModelEntrySchema>;
|
|
2786
|
-
/** 文生图配置 Schema */
|
|
2787
|
-
declare const ImageConfigSchema: z.ZodObject<{
|
|
2788
|
-
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2789
|
-
id: z.ZodString;
|
|
2790
|
-
provider: z.ZodEnum<{
|
|
2791
|
-
openai: "openai";
|
|
2792
|
-
qwen: "qwen";
|
|
2793
|
-
google: "google";
|
|
2794
|
-
seedream: "seedream";
|
|
2795
|
-
pollinations: "pollinations";
|
|
2796
|
-
}>;
|
|
2797
|
-
model: z.ZodString;
|
|
2798
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2799
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2800
|
-
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2801
|
-
timeout: z.ZodDefault<z.ZodNumber>;
|
|
2802
|
-
}, z.core.$strip>>>;
|
|
2803
|
-
generateModel: z.ZodOptional<z.ZodString>;
|
|
2804
|
-
}, z.core.$strip>;
|
|
2805
|
-
/** 文生图配置类型 */
|
|
2806
|
-
type ImageConfig = z.infer<typeof ImageConfigSchema>;
|
|
2807
|
-
/** 已解析的文生图模型 */
|
|
2808
|
-
interface ResolvedImageModel {
|
|
2809
|
-
id: string;
|
|
2810
|
-
provider: ImageProviderName;
|
|
2811
|
-
model: string;
|
|
2812
|
-
apiKey: string;
|
|
2813
|
-
baseUrl: string;
|
|
2814
|
-
workspaceId?: string;
|
|
2815
|
-
timeout: number;
|
|
2816
|
-
}
|
|
2817
|
-
/**
|
|
2818
|
-
* 解析文生图模型配置
|
|
2819
|
-
*
|
|
2820
|
-
* @param imageConfig - 文生图配置
|
|
2821
|
-
* @param explicit - 请求显式模型 ID 或厂商模型名
|
|
2822
|
-
* @returns 已解析模型;模型或凭据缺失时返回 HaiResult 错误
|
|
2823
|
-
*/
|
|
2824
|
-
declare function resolveImageModel(imageConfig: ImageConfig, explicit?: string): HaiResult<ResolvedImageModel>;
|
|
2825
|
-
/**
|
|
2826
|
-
* AI 配置 Schema
|
|
2827
|
-
*
|
|
2828
|
-
* 统一 AI 模块配置:LLM、MCP、Embedding、Knowledge、Retrieval、Memory、Token、Summary、Compress、File。
|
|
2829
|
-
* 模型通过 LLM.scenarios 映射场景,子系统不再独立配置 apiKey / baseUrl / model。
|
|
2830
|
-
*
|
|
2831
|
-
* @example
|
|
2832
|
-
* ```ts
|
|
2833
|
-
* ai.init({
|
|
2834
|
-
* llm: {
|
|
2835
|
-
* apiKey: 'sk-xxx',
|
|
2836
|
-
* model: 'gpt-4o-mini',
|
|
2837
|
-
* maxTokens: 4096,
|
|
2838
|
-
* models: [
|
|
2839
|
-
* { id: 'rerank', model: 'rerank-english-v3.0', baseUrl: 'https://api.cohere.com' },
|
|
2840
|
-
* ],
|
|
2841
|
-
* scenarios: {
|
|
2842
|
-
* extraction: 'gpt-4o',
|
|
2843
|
-
* summary: 'gpt-4o-mini',
|
|
2844
|
-
* embedding: 'text-embedding-3-small',
|
|
2845
|
-
* rerank: 'rerank',
|
|
2846
|
-
* ocr: 'gpt-4o',
|
|
2847
|
-
* },
|
|
2848
|
-
* },
|
|
2849
|
-
* embedding: { dimensions: 1536 },
|
|
2850
|
-
* knowledge: {
|
|
2851
|
-
* collection: 'docs',
|
|
2852
|
-
* enableEntityExtraction: true,
|
|
2853
|
-
* cleanOptions: { removeHtml: true },
|
|
2854
|
-
* chunkOptions: { mode: 'markdown', maxSize: 1500, overlap: 200 },
|
|
2855
|
-
* },
|
|
2856
|
-
* retrieval: {
|
|
2857
|
-
* sources: [
|
|
2858
|
-
* { id: 'docs', collection: 'documentation', name: '产品文档', topK: 5, minScore: 0.7 },
|
|
2859
|
-
* ],
|
|
2860
|
-
* },
|
|
2861
|
-
* memory: { maxEntriesPerObject: 500, embeddingEnabled: true },
|
|
2862
|
-
* token: { tokenRatio: 0.25 },
|
|
2863
|
-
* summary: { systemPrompt: 'You are a summarizer.' },
|
|
2864
|
-
* compress: { defaultStrategy: 'hybrid', preserveLastN: 4 },
|
|
2865
|
-
* })
|
|
2866
|
-
* ```
|
|
2867
|
-
*/
|
|
2868
|
-
declare const AIConfigSchema: z.ZodObject<{
|
|
2869
|
-
llm: z.ZodDefault<z.ZodObject<{
|
|
2870
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2871
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2872
|
-
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2873
|
-
api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
2874
|
-
chat: "chat";
|
|
2875
|
-
responses: "responses";
|
|
2876
|
-
anthropic: "anthropic";
|
|
2877
|
-
}>>>;
|
|
2878
|
-
maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2879
|
-
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2880
|
-
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2881
|
-
tempModelCacheTtl: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2882
|
-
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2883
|
-
id: z.ZodString;
|
|
2884
|
-
model: z.ZodString;
|
|
2885
|
-
api: z.ZodOptional<z.ZodEnum<{
|
|
2886
|
-
chat: "chat";
|
|
2887
|
-
responses: "responses";
|
|
2888
|
-
anthropic: "anthropic";
|
|
2889
|
-
}>>;
|
|
2890
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2891
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2892
|
-
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
2893
|
-
temperature: z.ZodOptional<z.ZodNumber>;
|
|
2894
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2895
|
-
}, z.core.$strip>>>;
|
|
2896
|
-
scenarios: z.ZodOptional<z.ZodObject<{
|
|
2897
|
-
chat: z.ZodOptional<z.ZodString>;
|
|
2898
|
-
default: z.ZodOptional<z.ZodString>;
|
|
2899
|
-
reasoning: z.ZodOptional<z.ZodString>;
|
|
2900
|
-
plan: z.ZodOptional<z.ZodString>;
|
|
2901
|
-
execute: z.ZodOptional<z.ZodString>;
|
|
2902
|
-
extraction: z.ZodOptional<z.ZodString>;
|
|
2903
|
-
summary: z.ZodOptional<z.ZodString>;
|
|
2904
|
-
embedding: z.ZodOptional<z.ZodString>;
|
|
2905
|
-
rerank: z.ZodOptional<z.ZodString>;
|
|
2906
|
-
ocr: z.ZodOptional<z.ZodString>;
|
|
2907
|
-
fast: z.ZodOptional<z.ZodString>;
|
|
2908
|
-
}, z.core.$strip>>;
|
|
2909
|
-
}, z.core.$strip>>;
|
|
2910
|
-
mcp: z.ZodOptional<z.ZodObject<{
|
|
2911
|
-
server: z.ZodOptional<z.ZodObject<{
|
|
2912
|
-
name: z.ZodString;
|
|
2913
|
-
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2914
|
-
capabilities: z.ZodOptional<z.ZodObject<{
|
|
2915
|
-
tools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2916
|
-
resources: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2917
|
-
prompts: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2918
|
-
}, z.core.$strip>>;
|
|
2919
|
-
}, z.core.$strip>>;
|
|
2920
|
-
}, z.core.$strip>>;
|
|
2921
|
-
embedding: z.ZodOptional<z.ZodObject<{
|
|
2922
|
-
dimensions: z.ZodOptional<z.ZodNumber>;
|
|
2923
|
-
batchSize: z.ZodDefault<z.ZodNumber>;
|
|
2924
|
-
}, z.core.$strip>>;
|
|
2925
|
-
knowledge: z.ZodOptional<z.ZodObject<{
|
|
2926
|
-
collection: z.ZodDefault<z.ZodString>;
|
|
2927
|
-
dimension: z.ZodDefault<z.ZodNumber>;
|
|
2928
|
-
enableEntityExtraction: z.ZodDefault<z.ZodBoolean>;
|
|
2929
|
-
cleanOptions: z.ZodDefault<z.ZodObject<{
|
|
2930
|
-
removeHtml: z.ZodDefault<z.ZodBoolean>;
|
|
2931
|
-
removeUrls: z.ZodDefault<z.ZodBoolean>;
|
|
2932
|
-
removeEmails: z.ZodDefault<z.ZodBoolean>;
|
|
2933
|
-
normalizeWhitespace: z.ZodDefault<z.ZodBoolean>;
|
|
2934
|
-
trim: z.ZodDefault<z.ZodBoolean>;
|
|
2935
|
-
customReplacements: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2936
|
-
pattern: z.ZodString;
|
|
2937
|
-
replacement: z.ZodString;
|
|
2938
|
-
}, z.core.$strip>>>;
|
|
2939
|
-
}, z.core.$strip>>;
|
|
2940
|
-
chunkOptions: z.ZodDefault<z.ZodObject<{
|
|
2941
|
-
mode: z.ZodEnum<{
|
|
2942
|
-
custom: "custom";
|
|
2943
|
-
sentence: "sentence";
|
|
2944
|
-
paragraph: "paragraph";
|
|
2945
|
-
markdown: "markdown";
|
|
2946
|
-
page: "page";
|
|
2947
|
-
word: "word";
|
|
2948
|
-
character: "character";
|
|
2949
|
-
}>;
|
|
2950
|
-
maxSize: z.ZodDefault<z.ZodNumber>;
|
|
2951
|
-
overlap: z.ZodDefault<z.ZodNumber>;
|
|
2952
|
-
separator: z.ZodOptional<z.ZodString>;
|
|
2953
|
-
markdownMinLevel: z.ZodDefault<z.ZodNumber>;
|
|
2954
|
-
markdownKeepTitle: z.ZodDefault<z.ZodBoolean>;
|
|
2955
|
-
}, z.core.$strip>>;
|
|
2956
|
-
entityBoostWeight: z.ZodDefault<z.ZodNumber>;
|
|
2957
|
-
entityTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
2958
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2959
|
-
}, z.core.$strip>>;
|
|
2960
|
-
memory: z.ZodOptional<z.ZodObject<{
|
|
2961
|
-
provider: z.ZodDefault<z.ZodEnum<{
|
|
2962
|
-
native: "native";
|
|
2963
|
-
mem0: "mem0";
|
|
2964
|
-
}>>;
|
|
2965
|
-
allowEphemeralFallback: z.ZodDefault<z.ZodBoolean>;
|
|
2966
|
-
maxEntriesPerObject: z.ZodDefault<z.ZodNumber>;
|
|
2967
|
-
maxEntriesGlobal: z.ZodDefault<z.ZodNumber>;
|
|
2968
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2969
|
-
recencyDecay: z.ZodDefault<z.ZodNumber>;
|
|
2970
|
-
embeddingEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
2971
|
-
defaultTopK: z.ZodDefault<z.ZodNumber>;
|
|
2972
|
-
candidateMultiplier: z.ZodDefault<z.ZodNumber>;
|
|
2973
|
-
writebackRelatedTopK: z.ZodDefault<z.ZodNumber>;
|
|
2974
|
-
}, z.core.$strip>>;
|
|
2975
|
-
token: z.ZodOptional<z.ZodObject<{
|
|
2976
|
-
tokenRatio: z.ZodDefault<z.ZodNumber>;
|
|
2977
|
-
}, z.core.$strip>>;
|
|
2978
|
-
summary: z.ZodOptional<z.ZodObject<{
|
|
2979
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2980
|
-
}, z.core.$strip>>;
|
|
2981
|
-
compress: z.ZodOptional<z.ZodObject<{
|
|
2982
|
-
defaultStrategy: z.ZodDefault<z.ZodEnum<{
|
|
2983
|
-
summary: "summary";
|
|
2984
|
-
"sliding-window": "sliding-window";
|
|
2985
|
-
hybrid: "hybrid";
|
|
2986
|
-
}>>;
|
|
2987
|
-
defaultMaxTokens: z.ZodDefault<z.ZodNumber>;
|
|
2988
|
-
preserveLastN: z.ZodDefault<z.ZodNumber>;
|
|
2989
|
-
}, z.core.$strip>>;
|
|
2990
|
-
retrieval: z.ZodOptional<z.ZodObject<{
|
|
2991
|
-
sources: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2992
|
-
id: z.ZodString;
|
|
2993
|
-
collection: z.ZodString;
|
|
2994
|
-
name: z.ZodOptional<z.ZodString>;
|
|
2995
|
-
url: z.ZodOptional<z.ZodString>;
|
|
2996
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
2997
|
-
minScore: z.ZodOptional<z.ZodNumber>;
|
|
2998
|
-
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2999
|
-
}, z.core.$strip>>>;
|
|
3000
|
-
}, z.core.$strip>>;
|
|
3001
|
-
file: z.ZodOptional<z.ZodObject<{
|
|
3002
|
-
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
3003
|
-
}, z.core.$strip>>;
|
|
3004
|
-
a2a: z.ZodOptional<z.ZodObject<{
|
|
3005
|
-
agentCard: z.ZodObject<{
|
|
3006
|
-
name: z.ZodString;
|
|
3007
|
-
description: z.ZodOptional<z.ZodString>;
|
|
3008
|
-
url: z.ZodString;
|
|
3009
|
-
version: z.ZodOptional<z.ZodString>;
|
|
3010
|
-
skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
3011
|
-
id: z.ZodString;
|
|
3012
|
-
name: z.ZodString;
|
|
3013
|
-
description: z.ZodOptional<z.ZodString>;
|
|
3014
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
3015
|
-
}, z.core.$strip>>>;
|
|
3016
|
-
}, z.core.$strip>;
|
|
3017
|
-
security: z.ZodOptional<z.ZodObject<{
|
|
3018
|
-
apiKey: z.ZodOptional<z.ZodObject<{
|
|
3019
|
-
in: z.ZodDefault<z.ZodEnum<{
|
|
3020
|
-
header: "header";
|
|
3021
|
-
query: "query";
|
|
3022
|
-
}>>;
|
|
3023
|
-
name: z.ZodDefault<z.ZodString>;
|
|
3024
|
-
}, z.core.$strip>>;
|
|
3025
|
-
}, z.core.$strip>>;
|
|
3026
|
-
}, z.core.$strip>>;
|
|
3027
|
-
audio: z.ZodOptional<z.ZodObject<{
|
|
3028
|
-
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
3029
|
-
id: z.ZodString;
|
|
3030
|
-
provider: z.ZodEnum<{
|
|
3031
|
-
openai: "openai";
|
|
3032
|
-
mimo: "mimo";
|
|
3033
|
-
qwen: "qwen";
|
|
3034
|
-
doubao: "doubao";
|
|
3035
|
-
whisper: "whisper";
|
|
3036
|
-
indextts: "indextts";
|
|
3037
|
-
}>;
|
|
3038
|
-
model: z.ZodString;
|
|
3039
|
-
operations: z.ZodArray<z.ZodEnum<{
|
|
3040
|
-
transcribe: "transcribe";
|
|
3041
|
-
synthesize: "synthesize";
|
|
3042
|
-
}>>;
|
|
3043
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3044
|
-
baseUrl: z.ZodOptional<z.ZodString>;
|
|
3045
|
-
appKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3046
|
-
accessKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3047
|
-
resourceId: z.ZodOptional<z.ZodString>;
|
|
3048
|
-
workspaceId: z.ZodOptional<z.ZodString>;
|
|
3049
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
3050
|
-
}, z.core.$strip>>>;
|
|
3051
|
-
inheritLlmApiKey: z.ZodDefault<z.ZodBoolean>;
|
|
3052
|
-
transcribeModel: z.ZodOptional<z.ZodString>;
|
|
3053
|
-
synthesizeModel: z.ZodOptional<z.ZodString>;
|
|
3054
|
-
maxAudioBytes: z.ZodDefault<z.ZodNumber>;
|
|
3055
|
-
maxStreamDurationMs: z.ZodDefault<z.ZodNumber>;
|
|
3056
|
-
}, z.core.$strip>>;
|
|
3057
|
-
image: z.ZodOptional<z.ZodObject<{
|
|
3058
|
-
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
3059
|
-
id: z.ZodString;
|
|
3060
|
-
provider: z.ZodEnum<{
|
|
3061
|
-
openai: "openai";
|
|
3062
|
-
qwen: "qwen";
|
|
3063
|
-
google: "google";
|
|
3064
|
-
seedream: "seedream";
|
|
3065
|
-
pollinations: "pollinations";
|
|
3066
|
-
}>;
|
|
3067
|
-
model: z.ZodString;
|
|
3068
|
-
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3069
|
-
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
3070
|
-
workspaceId: z.ZodOptional<z.ZodString>;
|
|
3071
|
-
timeout: z.ZodDefault<z.ZodNumber>;
|
|
3072
|
-
}, z.core.$strip>>>;
|
|
3073
|
-
generateModel: z.ZodOptional<z.ZodString>;
|
|
3074
|
-
}, z.core.$strip>>;
|
|
3075
|
-
}, z.core.$strip>;
|
|
3076
|
-
/** AI 配置类型(校验后的完整类型) */
|
|
3077
|
-
type AIConfig = z.infer<typeof AIConfigSchema>;
|
|
3078
|
-
/** AI 配置输入类型(允许部分字段) */
|
|
3079
|
-
type AIConfigInput = z.input<typeof AIConfigSchema>;
|
|
3080
|
-
|
|
3081
|
-
/**
|
|
3082
|
-
* @h-ai/ai — A2A(Agent-to-Agent)子功能类型
|
|
3083
|
-
*
|
|
3084
|
-
* 定义 A2A 协议集成所需的类型、SDK 类型再导出、操作接口。
|
|
3085
|
-
* @module ai-a2a-types
|
|
3086
|
-
*/
|
|
3087
|
-
|
|
3088
|
-
/** A2A 调用方身份信息 */
|
|
3089
|
-
interface A2ACallerIdentity {
|
|
3090
|
-
/** 调用方 Agent ID(如 AgentCard.name 或自定义标识) */
|
|
3091
|
-
agentId: string;
|
|
3092
|
-
/** 调用方显示名 */
|
|
3093
|
-
name?: string;
|
|
3094
|
-
/** 调用方 URL(AgentCard 地址) */
|
|
3095
|
-
url?: string;
|
|
3096
|
-
}
|
|
3097
|
-
/** A2A 消息记录(存储每条 A2A 交互) */
|
|
3098
|
-
interface A2AMessageRecord {
|
|
3099
|
-
/** 记录 ID(自动生成) */
|
|
3100
|
-
id: string;
|
|
3101
|
-
/** 关联的 A2A Task ID */
|
|
3102
|
-
taskId: string;
|
|
3103
|
-
/** 所属会话上下文 ID(历史记录可能缺失) */
|
|
3104
|
-
contextId?: string;
|
|
3105
|
-
/** 消息角色:user(入站请求)/ agent(出站响应) */
|
|
3106
|
-
role: 'user' | 'agent';
|
|
3107
|
-
/** 消息内容(JSON 序列化的 Part[] 数组) */
|
|
3108
|
-
parts: unknown[];
|
|
3109
|
-
/** 调用方身份信息(仅 role=user 时) */
|
|
3110
|
-
caller?: A2ACallerIdentity;
|
|
3111
|
-
/** 创建时间戳(毫秒) */
|
|
3112
|
-
createdAt: number;
|
|
3113
|
-
}
|
|
3114
|
-
/** A2A 上下文信息(对话/会话级别) */
|
|
3115
|
-
interface A2AContextInfo {
|
|
3116
|
-
/** 上下文 ID(对应 SDK 的 contextId) */
|
|
3117
|
-
id: string;
|
|
3118
|
-
/** 关联的 Agent 标识 */
|
|
3119
|
-
agentId?: string;
|
|
3120
|
-
/** 上下文标题(可选) */
|
|
3121
|
-
title?: string;
|
|
3122
|
-
/** 创建时间戳 */
|
|
3123
|
-
createdAt: number;
|
|
3124
|
-
/** 最后更新时间戳 */
|
|
3125
|
-
updatedAt: number;
|
|
3126
|
-
}
|
|
3127
|
-
/**
|
|
3128
|
-
* A2A 认证器接口
|
|
3129
|
-
*
|
|
3130
|
-
* 纯接口设计,由应用层实现,Kit 模块做胶水集成。
|
|
3131
|
-
* 用于验证入站 A2A 请求的身份。
|
|
3132
|
-
*/
|
|
3133
|
-
interface A2AAuthenticator {
|
|
3134
|
-
/**
|
|
3135
|
-
* 验证入站请求
|
|
3136
|
-
*
|
|
3137
|
-
* @param headers - HTTP 请求头
|
|
3138
|
-
* @returns 成功返回调用方身份信息,失败返回错误
|
|
3139
|
-
*/
|
|
3140
|
-
authenticate: (headers: Record<string, string | undefined>) => Promise<HaiResult<A2ACallerIdentity>>;
|
|
3141
|
-
}
|
|
3142
|
-
/** A2A 任务查询过滤器 */
|
|
3143
|
-
interface A2ATaskFilter {
|
|
3144
|
-
/** 按消息角色过滤(user / agent),不是任务生命周期状态 */
|
|
3145
|
-
status?: string | string[];
|
|
3146
|
-
/** 按上下文 ID 过滤 */
|
|
3147
|
-
contextId?: string;
|
|
3148
|
-
/** 按调用方 Agent ID 过滤 */
|
|
3149
|
-
callerId?: string;
|
|
3150
|
-
/** 时间范围起始(毫秒) */
|
|
3151
|
-
since?: number;
|
|
3152
|
-
/** 最大返回数 */
|
|
3153
|
-
limit?: number;
|
|
3154
|
-
/** 偏移量 */
|
|
3155
|
-
offset?: number;
|
|
3156
|
-
}
|
|
3157
|
-
/**
|
|
3158
|
-
* A2A 操作接口
|
|
3159
|
-
*
|
|
3160
|
-
* 提供 Agent-to-Agent 协议能力:Agent Card 管理、请求处理、客户端调用。
|
|
3161
|
-
*/
|
|
3162
|
-
interface A2AOperations {
|
|
3163
|
-
/**
|
|
3164
|
-
* 注册 Agent 执行器
|
|
3165
|
-
*
|
|
3166
|
-
* 需要先调用 `ai.init()` 并配置 `a2a` 后才能注册。
|
|
3167
|
-
* 注册后 `handleRequest()`、`listMessages()` 等方法即可使用。
|
|
3168
|
-
*
|
|
3169
|
-
* @param executor - Agent 执行器(由应用层实现)
|
|
3170
|
-
* @returns 注册成功返回 `ok(undefined)`;未配置/未初始化返回 `err(HaiAIError.*)`
|
|
3171
|
-
*/
|
|
3172
|
-
registerExecutor: (executor: AgentExecutor) => HaiResult<void>;
|
|
3173
|
-
/**
|
|
3174
|
-
* 获取当前 Agent Card
|
|
3175
|
-
*
|
|
3176
|
-
* 配置了 a2a 后即可使用,无需注册 executor。
|
|
3177
|
-
*
|
|
3178
|
-
* @returns 符合 A2A 0.3 的完整 Agent Card(含能力与安全方案)
|
|
3179
|
-
*/
|
|
3180
|
-
getAgentCard: () => HaiResult<AgentCard>;
|
|
3181
|
-
/**
|
|
3182
|
-
* 处理入站 JSON-RPC 请求
|
|
3183
|
-
*
|
|
3184
|
-
* 将 HTTP 请求体路由到 SDK 的 JsonRpcTransportHandler。
|
|
3185
|
-
*
|
|
3186
|
-
* @param requestBody - JSON-RPC 请求体
|
|
3187
|
-
* @param context - 可信 HTTP 层认证上下文;agentId 映射为 SDK user.userName
|
|
3188
|
-
* @returns JSON-RPC 响应(单条或流式);未初始化也返回 JSON-RPC 错误,不混入 HaiResult
|
|
3189
|
-
*/
|
|
3190
|
-
handleRequest: (requestBody: unknown, context?: Record<string, unknown>) => Promise<A2AHandleResult>;
|
|
3191
|
-
/**
|
|
3192
|
-
* 查询 A2A 消息列表(服务端管理接口,不自动推断调用方权限)
|
|
3193
|
-
*
|
|
3194
|
-
* @param filter - 查询过滤器
|
|
3195
|
-
* @returns 分页的消息记录列表
|
|
3196
|
-
*/
|
|
3197
|
-
listMessages: (filter: A2ATaskFilter) => Promise<HaiResult<StorePage<A2AMessageRecord>>>;
|
|
3198
|
-
/**
|
|
3199
|
-
* 作为客户端调用远端 Agent
|
|
3200
|
-
*
|
|
3201
|
-
* remoteUrl 只应来自受信配置。框架校验协议和内嵌凭据,应用仍须按部署环境实施来源白名单与出口策略。
|
|
3202
|
-
*
|
|
3203
|
-
* @param remoteUrl - 远端 Agent 的 A2A 端点 URL
|
|
3204
|
-
* @param message - 发送的消息文本
|
|
3205
|
-
* @param options - 调用选项
|
|
3206
|
-
* @returns 远端响应
|
|
3207
|
-
*/
|
|
3208
|
-
callRemoteAgent: (remoteUrl: string, message: string, options?: A2ACallOptions) => Promise<HaiResult<A2ACallResult>>;
|
|
3209
|
-
}
|
|
3210
|
-
/** A2A API Key 安全配置 */
|
|
3211
|
-
interface A2AApiKeySecurity {
|
|
3212
|
-
/** API Key 的传递位置 */
|
|
3213
|
-
in: 'header' | 'query';
|
|
3214
|
-
/** 参数名 */
|
|
3215
|
-
name: string;
|
|
3216
|
-
}
|
|
3217
|
-
/** A2A 安全认证配置 */
|
|
3218
|
-
interface A2ASecurityConfig {
|
|
3219
|
-
/** API Key 认证配置 */
|
|
3220
|
-
apiKey?: A2AApiKeySecurity;
|
|
3221
|
-
}
|
|
3222
|
-
/** Agent Card 配置(应用层提供) */
|
|
3223
|
-
interface A2AAgentCardConfig {
|
|
3224
|
-
/** Agent 名称 */
|
|
3225
|
-
name: string;
|
|
3226
|
-
/** Agent 描述 */
|
|
3227
|
-
description?: string;
|
|
3228
|
-
/** Agent URL(对外可访问的 base URL) */
|
|
3229
|
-
url: string;
|
|
3230
|
-
/** Agent 版本 */
|
|
3231
|
-
version?: string;
|
|
3232
|
-
/** Agent 能力声明 */
|
|
3233
|
-
skills?: Array<{
|
|
3234
|
-
id: string;
|
|
3235
|
-
name: string;
|
|
3236
|
-
description?: string;
|
|
3237
|
-
tags?: string[];
|
|
3238
|
-
}>;
|
|
3239
|
-
/** 安全认证配置(体现在 Agent Card 的 securitySchemes / security 字段) */
|
|
3240
|
-
security?: A2ASecurityConfig;
|
|
3241
|
-
}
|
|
3242
|
-
/** 处理结果(单条或流式) */
|
|
3243
|
-
interface A2AHandleResult {
|
|
3244
|
-
/** 是否为流式响应 */
|
|
3245
|
-
streaming: boolean;
|
|
3246
|
-
/** 单条 JSON-RPC 响应体(非流式时) */
|
|
3247
|
-
body?: unknown;
|
|
3248
|
-
/** 流式 JSON-RPC 响应迭代器(流式时) */
|
|
3249
|
-
stream?: AsyncGenerator<unknown, void, undefined>;
|
|
3250
|
-
}
|
|
3251
|
-
/** 远端调用选项 */
|
|
3252
|
-
interface A2ACallOptions {
|
|
3253
|
-
/** 超时时间(毫秒),默认 60 秒。 */
|
|
3254
|
-
timeout?: number;
|
|
3255
|
-
/** 额外请求头 */
|
|
3256
|
-
headers?: Record<string, string>;
|
|
3257
|
-
}
|
|
3258
|
-
/** 远端调用结果 */
|
|
3259
|
-
interface A2ACallResult {
|
|
3260
|
-
/** 远端任务 ID */
|
|
3261
|
-
taskId?: string;
|
|
3262
|
-
/** 任务最终状态 */
|
|
3263
|
-
taskState?: string;
|
|
3264
|
-
/** 响应消息文本 */
|
|
3265
|
-
responseText?: string;
|
|
3266
|
-
/** 响应消息 Part 数组 */
|
|
3267
|
-
responseParts?: unknown[];
|
|
3268
|
-
}
|
|
3269
|
-
|
|
3270
|
-
/**
|
|
3271
|
-
* @h-ai/ai — Audio 子功能公共类型
|
|
3272
|
-
*
|
|
3273
|
-
* 仅定义语音识别(ASR)与语音合成(TTS)的对外业务类型。
|
|
3274
|
-
* 不暴露 WebSocket、SSE、厂商事件、Session/Commit、二进制帧等传输细节,
|
|
3275
|
-
* 也不暴露内部 Provider 接口与厂商报文结构。
|
|
3276
|
-
* @module audio/ai-audio-types
|
|
3277
|
-
*/
|
|
3278
|
-
|
|
3279
|
-
/**
|
|
3280
|
-
* 音频编码格式
|
|
3281
|
-
*
|
|
3282
|
-
* - `pcm16` — 16bit 小端裸 PCM(必须提供 `sampleRate`)
|
|
3283
|
-
* - `wav` — WAV 容器(自描述采样率,可不传 `sampleRate`)
|
|
3284
|
-
* - `mp3` — MP3 容器
|
|
3285
|
-
* - `opus` — Opus 编码
|
|
3286
|
-
*/
|
|
3287
|
-
type AudioFormat = 'pcm16' | 'wav' | 'mp3' | 'opus';
|
|
3288
|
-
/**
|
|
3289
|
-
* 完整音频内容(一次性输入/输出)
|
|
3290
|
-
*
|
|
3291
|
-
* `data` 统一使用二进制字节;Node.js 中的 `Buffer` 可直接作为 `Uint8Array` 传入。
|
|
3292
|
-
* Provider 内部会按厂商要求转换为 Base64 / Multipart / 二进制帧,调用方无需感知。
|
|
3293
|
-
*/
|
|
3294
|
-
interface AudioContent {
|
|
3295
|
-
/** 音频二进制数据 */
|
|
3296
|
-
data: Uint8Array;
|
|
3297
|
-
/** 音频编码格式 */
|
|
3298
|
-
format: AudioFormat;
|
|
3299
|
-
/** 采样率(Hz);`pcm16` 等裸音频必填,`wav` / `mp3` 等自描述格式可省略 */
|
|
3300
|
-
sampleRate?: number;
|
|
3301
|
-
/** 声道数(默认单声道) */
|
|
3302
|
-
channels?: 1 | 2;
|
|
3303
|
-
}
|
|
3304
|
-
/** 可直接作为浏览器音频响应传输的负载 */
|
|
3305
|
-
interface PlayableAudio {
|
|
3306
|
-
/** Base64 编码的音频字节 */
|
|
3307
|
-
audioBase64: string;
|
|
3308
|
-
/** 浏览器可播放的容器格式 */
|
|
3309
|
-
format: 'wav' | 'mp3';
|
|
3310
|
-
/** 浏览器播放所需的 MIME 类型 */
|
|
3311
|
-
mimeType: 'audio/wav' | 'audio/mpeg';
|
|
3312
|
-
}
|
|
3313
|
-
/**
|
|
3314
|
-
* 实时音频输入流(持续到达的音频分片)
|
|
3315
|
-
*
|
|
3316
|
-
* 仅表达「音频分片持续到达」这一业务语义,不包含 WebSocket、Session、Commit 等传输概念。
|
|
3317
|
-
*/
|
|
3318
|
-
interface AudioInputStream {
|
|
3319
|
-
/** 持续到达的音频分片 */
|
|
3320
|
-
chunks: AsyncIterable<Uint8Array>;
|
|
3321
|
-
/** 音频编码格式 */
|
|
3322
|
-
format: AudioFormat;
|
|
3323
|
-
/** 采样率(Hz) */
|
|
3324
|
-
sampleRate: number;
|
|
3325
|
-
/** 声道数(默认单声道) */
|
|
3326
|
-
channels?: 1 | 2;
|
|
3327
|
-
}
|
|
3328
|
-
/**
|
|
3329
|
-
* ASR 时间戳粒度
|
|
3330
|
-
*
|
|
3331
|
-
* - `segment` — 语义段 / 句级时间轴
|
|
3332
|
-
* - `word` — 词级时间轴
|
|
3333
|
-
*/
|
|
3334
|
-
type TranscriptionTimestampGranularity = 'segment' | 'word';
|
|
3335
|
-
/** 单个 ASR 词级识别结果 */
|
|
3336
|
-
interface TranscriptionWord {
|
|
3337
|
-
/** 识别出的文字、单词或 Token */
|
|
3338
|
-
text: string;
|
|
3339
|
-
/** 起始时间(毫秒) */
|
|
3340
|
-
startMs: number;
|
|
3341
|
-
/** 结束时间(毫秒) */
|
|
3342
|
-
endMs: number;
|
|
3343
|
-
/** 置信度(仅 Provider 能提供明确概率语义时返回) */
|
|
3344
|
-
confidence?: number;
|
|
3345
|
-
}
|
|
3346
|
-
/** ASR 分段结果 */
|
|
3347
|
-
interface TranscriptionSegment {
|
|
3348
|
-
/** Provider 返回或 Framework 生成的 Segment ID */
|
|
3349
|
-
id?: string;
|
|
3350
|
-
/** 当前 Segment 完整文本 */
|
|
3351
|
-
text: string;
|
|
3352
|
-
/** Segment 起始位置(毫秒) */
|
|
3353
|
-
startMs: number;
|
|
3354
|
-
/** Segment 结束位置(毫秒) */
|
|
3355
|
-
endMs: number;
|
|
3356
|
-
/** 当前 Segment 下的词级时间轴 */
|
|
3357
|
-
words?: TranscriptionWord[];
|
|
3358
|
-
/** 为后续 Speaker Diarization 预留的说话人 ID */
|
|
3359
|
-
speakerId?: string;
|
|
3360
|
-
}
|
|
3361
|
-
/**
|
|
3362
|
-
* ASR 公共请求选项
|
|
3363
|
-
*
|
|
3364
|
-
* 完整识别与流式识别共用;所有高级能力字段均为可选,不支持的平台会忽略或(在
|
|
3365
|
-
* `strictCapabilities` 为真时)提前失败。
|
|
3366
|
-
*/
|
|
3367
|
-
interface TranscriptionOptions {
|
|
3368
|
-
/** 语言提示(如 `zh` / `en`;不传时由模型自动检测) */
|
|
3369
|
-
language?: string;
|
|
3370
|
-
/**
|
|
3371
|
-
* 领域提示词 / 热词(如角色名、专有名词、当前主题关键词)
|
|
3372
|
-
*
|
|
3373
|
-
* Provider 按能力映射为热词表 / phrase list / vocabulary / 提示词;不支持的平台会忽略。
|
|
3374
|
-
*/
|
|
3375
|
-
contextHints?: string[];
|
|
3376
|
-
/** 请求返回的时间戳粒度(`segment` / `word`) */
|
|
3377
|
-
timestampGranularities?: TranscriptionTimestampGranularity[];
|
|
3378
|
-
/** 是否启用模型 / 服务端 VAD */
|
|
3379
|
-
vad?: boolean;
|
|
3380
|
-
/** 是否严格要求高级能力全部被支持(true 时不支持则提前失败,false 为 best effort) */
|
|
3381
|
-
strictCapabilities?: boolean;
|
|
3382
|
-
/** 模型 ID(不传时使用配置中的默认识别模型) */
|
|
3383
|
-
model?: string;
|
|
3384
|
-
/** 取消信号 */
|
|
3385
|
-
signal?: AbortSignal;
|
|
3386
|
-
}
|
|
3387
|
-
/** 完整语音识别请求 */
|
|
3388
|
-
interface TranscriptionRequest extends TranscriptionOptions {
|
|
3389
|
-
/** 待识别的完整音频 */
|
|
3390
|
-
audio: AudioContent;
|
|
3391
|
-
}
|
|
3392
|
-
/** 流式语音识别请求(支持完整音频或持续音频输入) */
|
|
3393
|
-
interface TranscriptionStreamRequest extends TranscriptionOptions {
|
|
3394
|
-
/** 完整音频,或持续到达的音频输入流 */
|
|
3395
|
-
audio: AudioContent | AudioInputStream;
|
|
3396
|
-
}
|
|
3397
|
-
/** 完整语音识别结果 */
|
|
3398
|
-
interface TranscriptionResult {
|
|
3399
|
-
/** 识别文本 */
|
|
3400
|
-
text: string;
|
|
3401
|
-
/** 实际检测或使用的语言 */
|
|
3402
|
-
language?: string;
|
|
3403
|
-
/** 输入音频总时长(毫秒) */
|
|
3404
|
-
durationMs?: number;
|
|
3405
|
-
/**
|
|
3406
|
-
* 结构化识别时间轴
|
|
3407
|
-
*
|
|
3408
|
-
* Word Timestamp 统一存储在 `segments[].words`,不在顶层重复。
|
|
3409
|
-
*/
|
|
3410
|
-
segments?: TranscriptionSegment[];
|
|
3411
|
-
}
|
|
3412
|
-
/**
|
|
3413
|
-
* 流式语音识别领域事件
|
|
3414
|
-
*
|
|
3415
|
-
* 统一的语音领域事件(非厂商协议)。支持服务端 VAD 的平台(如 Qwen 实时识别)会在检测到
|
|
3416
|
-
* 语音起止时额外产出 `speech_started` / `speech_stopped`,使调用方可在「开始说话」的瞬间做出
|
|
3417
|
-
* 反应(如取消当前上游生成),而无需自行运行 VAD;不产出 VAD 事件的平台(如豆包)仅产出
|
|
3418
|
-
* `transcript`,此时是否需要 VAD 由调用方自行决定。
|
|
3419
|
-
*
|
|
3420
|
-
* `transcript.text` 表示当前语句的完整识别文本(非字符增量),实时 ASR 会修订前一次临时结果,
|
|
3421
|
-
* 调用方可直接用 `text` 覆盖当前临时文本。
|
|
3422
|
-
*/
|
|
3423
|
-
type TranscriptionEvent = {
|
|
3424
|
-
type: 'speech_started';
|
|
3425
|
-
} | {
|
|
3426
|
-
type: 'transcript';
|
|
3427
|
-
text: string;
|
|
3428
|
-
final: boolean;
|
|
3429
|
-
startMs?: number;
|
|
3430
|
-
endMs?: number;
|
|
3431
|
-
words?: TranscriptionWord[];
|
|
3432
|
-
} | {
|
|
3433
|
-
type: 'speech_stopped';
|
|
3434
|
-
};
|
|
3435
|
-
/**
|
|
3436
|
-
* TTS 通用参考音频
|
|
3437
|
-
*
|
|
3438
|
-
* 不绑定任何具体 TTS 模型。既可表达「谁在说话」(说话人参考),也可表达「怎么说」(风格参考),
|
|
3439
|
-
* 由 `SynthesisOptions.speakerReference` / `styleReference` 决定用途。
|
|
3440
|
-
*/
|
|
3441
|
-
interface AudioReference {
|
|
3442
|
-
/** 参考音频 */
|
|
3443
|
-
audio: AudioContent;
|
|
3444
|
-
/** 参考音频对应文本(仅需要参考 Transcript 的 Provider 使用) */
|
|
3445
|
-
transcript?: string;
|
|
3446
|
-
/** 参考音频语言 */
|
|
3447
|
-
language?: string;
|
|
3448
|
-
}
|
|
3449
|
-
/**
|
|
3450
|
-
* TTS 公共请求选项
|
|
3451
|
-
*
|
|
3452
|
-
* 完整合成与流式合成共用;所有高级能力字段均为可选,不支持的平台会忽略或(在
|
|
3453
|
-
* `strictCapabilities` 为真时)提前失败。
|
|
3454
|
-
*/
|
|
3455
|
-
interface SynthesisOptions {
|
|
3456
|
-
/** 目标语言 */
|
|
3457
|
-
language?: string;
|
|
3458
|
-
/** 音色(厂商音色名,不传时使用模型默认音色) */
|
|
3459
|
-
voice?: string;
|
|
3460
|
-
/** 说话人 / 音色参考(表达「谁在说话」) */
|
|
3461
|
-
speakerReference?: AudioReference;
|
|
3462
|
-
/** 风格、情绪、韵律参考(表达「怎么说」) */
|
|
3463
|
-
styleReference?: AudioReference;
|
|
3464
|
-
/** 风格参考影响强度,统一为 `[0, 1]` */
|
|
3465
|
-
styleStrength?: number;
|
|
3466
|
-
/**
|
|
3467
|
-
* 自然语言风格指令(如语速、情绪、角色语气)
|
|
3468
|
-
*
|
|
3469
|
-
* Provider 按能力映射(如 MiMo 放入 user 消息、Qwen instructions);不支持的平台会忽略。
|
|
3470
|
-
*/
|
|
3471
|
-
instruction?: string;
|
|
3472
|
-
/**
|
|
3473
|
-
* 语速倍数
|
|
3474
|
-
*
|
|
3475
|
-
* `1.0` 正常、`>1` 更快、`<1` 更慢。
|
|
3476
|
-
*/
|
|
3477
|
-
speed?: number;
|
|
3478
|
-
/** 输出音频格式(不传时使用模型默认格式) */
|
|
3479
|
-
format?: AudioFormat;
|
|
3480
|
-
/** 输出采样率(Hz) */
|
|
3481
|
-
sampleRate?: number;
|
|
3482
|
-
/** 模型 ID(不传时使用配置中的默认合成模型) */
|
|
3483
|
-
model?: string;
|
|
3484
|
-
/** 是否严格要求高级能力全部被支持(true 时不支持则提前失败,false 为 best effort) */
|
|
3485
|
-
strictCapabilities?: boolean;
|
|
3486
|
-
/** 取消信号 */
|
|
3487
|
-
signal?: AbortSignal;
|
|
3488
|
-
}
|
|
3489
|
-
/** 完整语音合成请求 */
|
|
3490
|
-
interface SynthesisRequest extends SynthesisOptions {
|
|
3491
|
-
/** 待合成文本 */
|
|
3492
|
-
text: string;
|
|
3493
|
-
/**
|
|
3494
|
-
* 最终音频目标时长(毫秒)
|
|
3495
|
-
*
|
|
3496
|
-
* 表达 Framework 业务目标,不对应某个模型私有参数;由支持的 Provider / Model Service 闭环逼近。
|
|
3497
|
-
*/
|
|
3498
|
-
targetDurationMs?: number;
|
|
3499
|
-
/** 目标时长允许误差(毫秒) */
|
|
3500
|
-
durationToleranceMs?: number;
|
|
3501
|
-
}
|
|
3502
|
-
/** 带稳定 ID 的合成文本段 */
|
|
3503
|
-
interface SynthesisTextSegment {
|
|
3504
|
-
/** 调用方分配的稳定 ID,用于关联文本、音频与播放完成状态 */
|
|
3505
|
-
id: string;
|
|
3506
|
-
/** 本段待合成文本 */
|
|
3507
|
-
text: string;
|
|
3508
|
-
}
|
|
3509
|
-
/** 流式语音合成请求(支持单段或持续文本段输入) */
|
|
3510
|
-
interface SynthesisStreamRequest extends SynthesisOptions {
|
|
3511
|
-
/** 单个文本段,或持续到达的文本段流 */
|
|
3512
|
-
text: SynthesisTextSegment | AsyncIterable<SynthesisTextSegment>;
|
|
3513
|
-
}
|
|
3514
|
-
/** 完整语音合成结果 */
|
|
3515
|
-
interface SynthesisResult extends AudioContent {
|
|
3516
|
-
/** 实际输出音频时长(毫秒) */
|
|
3517
|
-
durationMs?: number;
|
|
3518
|
-
/** 通用生成元数据 */
|
|
3519
|
-
metadata?: {
|
|
3520
|
-
/** 是否满足调用方指定的时长容差(无法判断时保持 undefined) */
|
|
3521
|
-
durationMatched?: boolean;
|
|
3522
|
-
/** Provider 最终使用的 Framework speed */
|
|
3523
|
-
speed?: number;
|
|
3524
|
-
};
|
|
3525
|
-
}
|
|
3526
|
-
/**
|
|
3527
|
-
* 流式语音合成领域事件
|
|
3528
|
-
*
|
|
3529
|
-
* 每个文本段严格按 `segment_started → audio* → segment_done` 顺序产出,调用方可在
|
|
3530
|
-
* 对应音频真正播放完成后提交该段文本,不需要按字节数反推文本边界。
|
|
3531
|
-
*
|
|
3532
|
-
* `segment_started` 携带服务端解析 Provider 后的**真实输出音频参数**(format / sampleRate / channels),
|
|
3533
|
-
* 调用方据此正确解码、设置 PCM 播放参数、选择保存扩展名,而非根据请求参数猜测。
|
|
3534
|
-
*/
|
|
3535
|
-
type SynthesisEvent = {
|
|
3536
|
-
type: 'segment_started';
|
|
3537
|
-
segmentId: string;
|
|
3538
|
-
text: string;
|
|
3539
|
-
format: AudioFormat;
|
|
3540
|
-
sampleRate?: number;
|
|
3541
|
-
channels?: 1 | 2;
|
|
3542
|
-
} | {
|
|
3543
|
-
type: 'audio';
|
|
3544
|
-
segmentId: string;
|
|
3545
|
-
data: Uint8Array;
|
|
3546
|
-
} | {
|
|
3547
|
-
type: 'segment_done';
|
|
3548
|
-
segmentId: string;
|
|
3549
|
-
};
|
|
3550
|
-
/**
|
|
3551
|
-
* 语音模型的实时能力声明
|
|
3552
|
-
*
|
|
3553
|
-
* 由 `ai.audio.getCapabilities({ operation, model })` 返回,供实时会话在启动前校验:不同平台对「持续音频输入 /
|
|
3554
|
-
* 服务端 VAD / 增量文本输入 / 流式输出」的原生支持不同,同一方法签名在不同平台下的实时语义并不一致。
|
|
3555
|
-
* 调用方应据此选择模型或调整策略(如实时 ASR 要求 `realtimeAudioInput` 与 `speechBoundaryEvents`,
|
|
3556
|
-
* 实时 TTS 要求 `streamingAudioOutput`)。
|
|
3557
|
-
*/
|
|
3558
|
-
interface AudioModelCapabilities {
|
|
3559
|
-
/** 语音识别能力;模型未声明识别操作时不返回 */
|
|
3560
|
-
transcribe?: {
|
|
3561
|
-
/** 是否支持 ASR */
|
|
3562
|
-
supported: boolean;
|
|
3563
|
-
/** 是否原生支持持续实时音频输入 */
|
|
3564
|
-
realtimeAudioInput: boolean;
|
|
3565
|
-
/** 是否产生语音边界事件(speech_started / speech_stopped) */
|
|
3566
|
-
speechBoundaryEvents: boolean;
|
|
3567
|
-
/** 是否原生输出增量 Transcript */
|
|
3568
|
-
streamingTranscriptOutput: boolean;
|
|
3569
|
-
/** 是否接受 Language Hint */
|
|
3570
|
-
languageHint?: boolean;
|
|
3571
|
-
/** 是否支持自动语言检测 */
|
|
3572
|
-
languageDetection?: boolean;
|
|
3573
|
-
/** 是否支持 Segment Timestamp */
|
|
3574
|
-
segmentTimestamps?: boolean;
|
|
3575
|
-
/** 是否支持 Word Timestamp */
|
|
3576
|
-
wordTimestamps?: boolean;
|
|
3577
|
-
/** 是否支持 Context Hints */
|
|
3578
|
-
contextHints?: boolean;
|
|
3579
|
-
/** 是否支持 VAD */
|
|
3580
|
-
vad?: boolean;
|
|
3581
|
-
/** 是否支持 Speaker Diarization */
|
|
3582
|
-
speakerDiarization?: boolean;
|
|
3583
|
-
};
|
|
3584
|
-
/** 语音合成能力;模型未声明合成操作时不返回 */
|
|
3585
|
-
synthesize?: {
|
|
3586
|
-
/** 是否支持 TTS */
|
|
3587
|
-
supported: boolean;
|
|
3588
|
-
/** 是否原生支持增量文本输入 */
|
|
3589
|
-
incrementalTextInput: boolean;
|
|
3590
|
-
/** 是否原生支持流式音频输出 */
|
|
3591
|
-
streamingAudioOutput: boolean;
|
|
3592
|
-
/** 是否支持指定目标语言 */
|
|
3593
|
-
languageSelection?: boolean;
|
|
3594
|
-
/** 是否支持预置 Voice */
|
|
3595
|
-
presetVoice?: boolean;
|
|
3596
|
-
/** 是否支持 Speaker Reference */
|
|
3597
|
-
speakerReference?: boolean;
|
|
3598
|
-
/** 是否必须提供 Speaker Reference */
|
|
3599
|
-
speakerReferenceRequired?: boolean;
|
|
3600
|
-
/** 是否支持 Style Reference */
|
|
3601
|
-
styleReference?: boolean;
|
|
3602
|
-
/** 是否支持通用自然语言 Instruction */
|
|
3603
|
-
instruction?: boolean;
|
|
3604
|
-
/** 是否支持 Framework Speed */
|
|
3605
|
-
speedControl?: boolean;
|
|
3606
|
-
/** 是否支持 Framework Target Duration */
|
|
3607
|
-
targetDuration?: boolean;
|
|
3608
|
-
/** 已知支持语言 */
|
|
3609
|
-
supportedLanguages?: string[];
|
|
3610
|
-
};
|
|
3611
|
-
}
|
|
3612
|
-
/** 查询语音模型能力的参数 */
|
|
3613
|
-
interface AudioCapabilitiesRequest {
|
|
3614
|
-
/** 要查询的操作,决定默认模型和返回的能力分支 */
|
|
3615
|
-
operation: 'transcribe' | 'synthesize';
|
|
3616
|
-
/** 模型 ID;不传时使用该操作配置的默认模型 */
|
|
3617
|
-
model?: string;
|
|
3618
|
-
}
|
|
3619
|
-
/**
|
|
3620
|
-
* Audio 操作接口(通过 `ai.audio` 访问)
|
|
3621
|
-
*
|
|
3622
|
-
* 提供语音识别与语音合成的完整与流式能力。普通方法返回 `HaiResult`;
|
|
3623
|
-
* 流式方法返回 `AsyncIterable`,迭代期间发生的连接/协议/上游错误会终止异步迭代(抛出异常)。
|
|
3624
|
-
*/
|
|
3625
|
-
interface AudioOperations {
|
|
3626
|
-
/** 将完整音频识别为完整文本 */
|
|
3627
|
-
transcribe: (request: TranscriptionRequest) => Promise<HaiResult<TranscriptionResult>>;
|
|
3628
|
-
/** 持续输入音频或增量返回识别文本(含语音起止领域事件) */
|
|
3629
|
-
transcribeStream: (request: TranscriptionStreamRequest) => AsyncIterable<TranscriptionEvent>;
|
|
3630
|
-
/** 将完整文本合成为完整音频 */
|
|
3631
|
-
synthesize: (request: SynthesisRequest) => Promise<HaiResult<SynthesisResult>>;
|
|
3632
|
-
/** 持续输入文本段并按段输出结构化音频事件 */
|
|
3633
|
-
synthesizeStream: (request: SynthesisStreamRequest) => AsyncIterable<SynthesisEvent>;
|
|
3634
|
-
/**
|
|
3635
|
-
* 查询指定模型的实时能力声明
|
|
3636
|
-
*
|
|
3637
|
-
* @param request - 操作类型与可选模型 ID
|
|
3638
|
-
* @returns 该模型对应操作的能力;模型不存在或操作不匹配时返回失败结果
|
|
3639
|
-
*/
|
|
3640
|
-
getCapabilities: (request: AudioCapabilitiesRequest) => HaiResult<AudioModelCapabilities>;
|
|
3641
|
-
}
|
|
3642
|
-
|
|
3643
|
-
/**
|
|
3644
|
-
* @h-ai/ai — RAG(Retrieval-Augmented Generation)子功能类型
|
|
3645
|
-
*
|
|
3646
|
-
* 定义 RAG 操作的类型接口:检索 + 生成。
|
|
3647
|
-
* @module ai-rag-types
|
|
3648
|
-
*/
|
|
3649
|
-
|
|
3650
|
-
/**
|
|
3651
|
-
* RAG 选项
|
|
3652
|
-
*/
|
|
3653
|
-
interface RagOptions {
|
|
3654
|
-
/** 交互主体 ID */
|
|
3655
|
-
objectId?: string;
|
|
3656
|
-
/** 会话 ID */
|
|
3657
|
-
sessionId?: string;
|
|
3658
|
-
/** 使用的检索源(不指定则使用全部已注册源) */
|
|
3659
|
-
sources?: string[];
|
|
3660
|
-
/** 返回的上下文条数(默认 5) */
|
|
3661
|
-
topK?: number;
|
|
3662
|
-
/** 最低相似度 */
|
|
3663
|
-
minScore?: number;
|
|
3664
|
-
/** 是否启用 Rerank 重排序 */
|
|
3665
|
-
enableRerank?: boolean;
|
|
3666
|
-
/** Rerank 使用的模型名称覆盖 */
|
|
3667
|
-
rerankModel?: string;
|
|
3668
|
-
/** LLM 模型名称覆盖 */
|
|
3669
|
-
model?: string;
|
|
3670
|
-
/** 系统提示词(可选,会自动注入检索上下文) */
|
|
3671
|
-
systemPrompt?: string;
|
|
3672
|
-
/** 温度覆盖 */
|
|
3673
|
-
temperature?: number;
|
|
3674
|
-
/** 自定义上下文格式化函数 */
|
|
3675
|
-
formatContext?: (items: RagContextItem[]) => string;
|
|
3676
|
-
/** 是否保留消息历史(用于多轮对话) */
|
|
3677
|
-
messages?: ChatMessage[];
|
|
3678
|
-
/** 是否启用内部 LLM 调用的持久化(默认 true;Context 层调用时传 false 避免重复记录) */
|
|
3679
|
-
enablePersist?: boolean;
|
|
3680
|
-
/** 请求取消信号(透传给内部 LLM 调用,支持中途取消生成) */
|
|
3681
|
-
signal?: AbortSignal;
|
|
3682
|
-
}
|
|
3683
|
-
/**
|
|
3684
|
-
* RAG 上下文项
|
|
3685
|
-
*/
|
|
3686
|
-
interface RagContextItem {
|
|
3687
|
-
/** 文档内容 */
|
|
3688
|
-
content: string;
|
|
3689
|
-
/** 相似度分数 */
|
|
3690
|
-
score: number;
|
|
3691
|
-
/** 来源 */
|
|
3692
|
-
sourceId: string;
|
|
3693
|
-
/** 元数据 */
|
|
3694
|
-
metadata?: Record<string, unknown>;
|
|
3695
|
-
/** 结构化信源引用 */
|
|
3696
|
-
citation?: Citation;
|
|
3697
|
-
}
|
|
3698
|
-
/**
|
|
3699
|
-
* RAG 结果
|
|
3700
|
-
*/
|
|
3701
|
-
interface RagResult {
|
|
3702
|
-
/** LLM 生成的回答 */
|
|
3703
|
-
answer: string;
|
|
3704
|
-
/** 使用的上下文 */
|
|
3705
|
-
context: RagContextItem[];
|
|
3706
|
-
/** 去重后的信源引用列表(方便 UI 展示引用栏) */
|
|
3707
|
-
citations: Citation[];
|
|
3708
|
-
/** 查询文本 */
|
|
3709
|
-
query: string;
|
|
3710
|
-
/** 使用的模型 */
|
|
3711
|
-
model: string;
|
|
3712
|
-
/** Token 使用统计 */
|
|
3713
|
-
usage?: {
|
|
3714
|
-
prompt_tokens: number;
|
|
3715
|
-
completion_tokens: number;
|
|
3716
|
-
total_tokens: number;
|
|
3717
|
-
};
|
|
3718
|
-
}
|
|
3719
|
-
/**
|
|
3720
|
-
* RAG 流式事件
|
|
3721
|
-
*
|
|
3722
|
-
* queryStream 产出的事件序列:
|
|
3723
|
-
* 1. `context` — 检索结果就绪,携带上下文列表
|
|
3724
|
-
* 2. `delta` — LLM 增量文本
|
|
3725
|
-
* 3. `done` — 生成完成,携带完整结果汇总
|
|
3726
|
-
*/
|
|
3727
|
-
type RagStreamEvent = {
|
|
3728
|
-
type: 'context';
|
|
3729
|
-
items: RagContextItem[];
|
|
3730
|
-
citations: Citation[];
|
|
3731
|
-
} | {
|
|
3732
|
-
type: 'delta';
|
|
3733
|
-
text: string;
|
|
3734
|
-
} | {
|
|
3735
|
-
type: 'done';
|
|
3736
|
-
answer: string;
|
|
3737
|
-
model: string;
|
|
3738
|
-
usage?: {
|
|
3739
|
-
prompt_tokens: number;
|
|
3740
|
-
completion_tokens: number;
|
|
3741
|
-
total_tokens: number;
|
|
3742
|
-
};
|
|
3743
|
-
};
|
|
3744
|
-
/**
|
|
3745
|
-
* RAG 操作接口
|
|
3746
|
-
*/
|
|
3747
|
-
interface RagOperations {
|
|
3748
|
-
/**
|
|
3749
|
-
* 执行 RAG(检索增强生成)
|
|
3750
|
-
*
|
|
3751
|
-
* 1. 将查询文本向量化
|
|
3752
|
-
* 2. 从已注册的检索源中检索相关文档
|
|
3753
|
-
* 3. 将检索上下文注入 LLM 提示词
|
|
3754
|
-
* 4. 调用 LLM 生成回答
|
|
3755
|
-
*
|
|
3756
|
-
* @param query - 用户查询文本
|
|
3757
|
-
* @param options - RAG 选项
|
|
3758
|
-
* @returns RAG 结果
|
|
3759
|
-
*/
|
|
3760
|
-
query: (query: string, options?: RagOptions) => Promise<HaiResult<RagResult>>;
|
|
3761
|
-
/**
|
|
3762
|
-
* 流式 RAG 查询
|
|
3763
|
-
*
|
|
3764
|
-
* 产出事件序列:context → delta* → done
|
|
3765
|
-
*
|
|
3766
|
-
* @param query - 用户查询文本
|
|
3767
|
-
* @param options - RAG 选项
|
|
3768
|
-
* @returns 异步可迭代的 RagStreamEvent
|
|
3769
|
-
*/
|
|
3770
|
-
queryStream: (query: string, options?: RagOptions) => AsyncIterable<RagStreamEvent>;
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
/**
|
|
3774
|
-
* @h-ai/ai — Reasoning 子功能类型
|
|
3775
|
-
*
|
|
3776
|
-
* 定义推理策略和推理操作的类型接口。
|
|
3777
|
-
* 支持 ReAct、Chain-of-Thought(CoT)、Plan-and-Execute 三种策略。
|
|
3778
|
-
* @module ai-reasoning-types
|
|
3779
|
-
*/
|
|
3780
|
-
|
|
3781
|
-
/**
|
|
3782
|
-
* 推理策略类型
|
|
3783
|
-
*
|
|
3784
|
-
* - `react` — ReAct(Reasoning + Acting):交替 思考→行动→观察 循环
|
|
3785
|
-
* - `cot` — Chain-of-Thought:将问题分解为思维链逐步推理
|
|
3786
|
-
* - `plan-execute` — Plan-and-Execute:先生成计划再逐步执行
|
|
3787
|
-
*/
|
|
3788
|
-
type ReasoningStrategy = 'react' | 'cot' | 'plan-execute';
|
|
3789
|
-
/**
|
|
3790
|
-
* 推理执行选项
|
|
3791
|
-
*/
|
|
3792
|
-
interface ReasoningOptions {
|
|
3793
|
-
/** 交互主体 ID */
|
|
3794
|
-
objectId?: string;
|
|
3795
|
-
/** 会话 ID */
|
|
3796
|
-
sessionId?: string;
|
|
3797
|
-
/** 推理策略(默认 `'react'`) */
|
|
3798
|
-
strategy?: ReasoningStrategy;
|
|
3799
|
-
/** 最大推理轮次(默认 10) */
|
|
3800
|
-
maxRounds?: number;
|
|
3801
|
-
/** 使用的模型 ID 或名称(可选,默认使用 reasoning 场景的模型) */
|
|
3802
|
-
model?: string;
|
|
3803
|
-
/** Plan-Execute 规划阶段模型(可选,默认回退到 `model` → 场景 `plan` → 场景 `reasoning`) */
|
|
3804
|
-
planModel?: string;
|
|
3805
|
-
/** Plan-Execute 执行阶段模型(可选,默认回退到 `model` → 场景 `execute` → 场景 `reasoning`) */
|
|
3806
|
-
executeModel?: string;
|
|
3807
|
-
/** 系统提示词(可选,覆盖默认的策略提示词) */
|
|
3808
|
-
systemPrompt?: string;
|
|
3809
|
-
/** 是否启用内部 LLM 调用的持久化(默认 true;Context 层调用时传 false 避免重复记录) */
|
|
3810
|
-
enablePersist?: boolean;
|
|
3811
|
-
/**
|
|
3812
|
-
* 前置对话上下文(可选)
|
|
3813
|
-
*
|
|
3814
|
-
* 插入到系统提示词之后、当前问题之前,用于注入:
|
|
3815
|
-
* - 历史对话轮次(连续对话场景)
|
|
3816
|
-
* - `ai.memory.injectMemories()` 处理后的记忆增强消息
|
|
3817
|
-
* - RAG 检索到的内容片段(构造为 system 消息)
|
|
3818
|
-
*
|
|
3819
|
-
* @example
|
|
3820
|
-
* ```ts
|
|
3821
|
-
* // 将记忆注入推理上下文
|
|
3822
|
-
* const withMemory = await ai.memory.injectMemories(
|
|
3823
|
-
* [{ role: 'user', content: query }],
|
|
3824
|
-
* { objectId: 'user-001' },
|
|
3825
|
-
* )
|
|
3826
|
-
* await ai.reasoning.run(query, { messages: withMemory.data })
|
|
3827
|
-
* ```
|
|
3828
|
-
*/
|
|
3829
|
-
messages?: ChatMessage[];
|
|
3830
|
-
/** 可用工具注册表(可选,ReAct 和 Plan-Execute 策略可用) */
|
|
3831
|
-
tools?: ToolRegistryOperations;
|
|
3832
|
-
/** 温度覆盖 */
|
|
3833
|
-
temperature?: number;
|
|
3834
|
-
/** 请求取消信号(透传给内部 LLM 调用,支持中途取消推理) */
|
|
3835
|
-
signal?: AbortSignal;
|
|
3836
|
-
}
|
|
3837
|
-
/**
|
|
3838
|
-
* 推理步骤类型
|
|
3839
|
-
*/
|
|
3840
|
-
type ReasoningStepType = 'thought' | 'action' | 'observation' | 'plan' | 'answer';
|
|
3841
|
-
/**
|
|
3842
|
-
* 单个推理步骤
|
|
3843
|
-
*/
|
|
3844
|
-
interface ReasoningStep {
|
|
3845
|
-
/** 步骤类型 */
|
|
3846
|
-
type: ReasoningStepType;
|
|
3847
|
-
/** 步骤内容 */
|
|
3848
|
-
content: string;
|
|
3849
|
-
/** 工具调用信息(仅 action 类型) */
|
|
3850
|
-
toolCall?: {
|
|
3851
|
-
name: string;
|
|
3852
|
-
arguments: Record<string, unknown>;
|
|
3853
|
-
result?: string;
|
|
3854
|
-
};
|
|
3855
|
-
/** 步骤索引(从 0 开始) */
|
|
3856
|
-
index: number;
|
|
3857
|
-
}
|
|
3858
|
-
/**
|
|
3859
|
-
* 推理执行结果
|
|
3860
|
-
*/
|
|
3861
|
-
interface ReasoningResult {
|
|
3862
|
-
/** 最终答案 */
|
|
3863
|
-
answer: string;
|
|
3864
|
-
/** 推理步骤列表 */
|
|
3865
|
-
steps: ReasoningStep[];
|
|
3866
|
-
/** 使用的策略 */
|
|
3867
|
-
strategy: ReasoningStrategy;
|
|
3868
|
-
/** 总推理轮次 */
|
|
3869
|
-
rounds: number;
|
|
3870
|
-
/** 完整的消息历史 */
|
|
3871
|
-
messages: ChatMessage[];
|
|
3872
|
-
}
|
|
3873
|
-
/**
|
|
3874
|
-
* 推理流式事件
|
|
3875
|
-
*
|
|
3876
|
-
* runStream 产出的事件序列:
|
|
3877
|
-
* - `step` — 推理步骤完成(思考/行动/观察/计划)
|
|
3878
|
-
* - `delta` — LLM 增量文本(最终答案的流式输出)
|
|
3879
|
-
* - `done` — 推理完成,携带完整结果
|
|
3880
|
-
*/
|
|
3881
|
-
type ReasoningStreamEvent = {
|
|
3882
|
-
type: 'step';
|
|
3883
|
-
step: ReasoningStep;
|
|
3884
|
-
} | {
|
|
3885
|
-
type: 'delta';
|
|
3886
|
-
text: string;
|
|
3887
|
-
} | {
|
|
3888
|
-
type: 'done';
|
|
3889
|
-
result: ReasoningResult;
|
|
3890
|
-
};
|
|
3891
|
-
/**
|
|
3892
|
-
* 推理操作接口(通过 `ai.reasoning` 访问)
|
|
3893
|
-
*
|
|
3894
|
-
* 需要先调用 `ai.init()` 初始化后使用。
|
|
3895
|
-
*
|
|
3896
|
-
* @example
|
|
3897
|
-
* ```ts
|
|
3898
|
-
* // ReAct 推理(带工具)
|
|
3899
|
-
* const result = await ai.reasoning.run(
|
|
3900
|
-
* '分析这份数据...',
|
|
3901
|
-
* {
|
|
3902
|
-
* strategy: 'react',
|
|
3903
|
-
* tools: registry,
|
|
3904
|
-
* maxRounds: 5,
|
|
3905
|
-
* },
|
|
3906
|
-
* )
|
|
3907
|
-
*
|
|
3908
|
-
* // CoT 推理
|
|
3909
|
-
* const result = await ai.reasoning.run(
|
|
3910
|
-
* '解释量子纠缠',
|
|
3911
|
-
* { strategy: 'cot' },
|
|
3912
|
-
* )
|
|
3913
|
-
* ```
|
|
3914
|
-
*/
|
|
3915
|
-
interface ReasoningOperations {
|
|
3916
|
-
/**
|
|
3917
|
-
* 执行推理
|
|
3918
|
-
*
|
|
3919
|
-
* @param query - 用户问题或任务描述
|
|
3920
|
-
* @param options - 推理选项
|
|
3921
|
-
* @returns 推理结果
|
|
3922
|
-
*/
|
|
3923
|
-
run: (query: string, options?: ReasoningOptions) => Promise<HaiResult<ReasoningResult>>;
|
|
3924
|
-
/**
|
|
3925
|
-
* 流式推理(逐步产出推理步骤 + 最终答案增量文本)
|
|
3926
|
-
*
|
|
3927
|
-
* 产出事件序列:step* → delta* → done
|
|
3928
|
-
*
|
|
3929
|
-
* @param query - 用户问题或任务描述
|
|
3930
|
-
* @param options - 推理选项
|
|
3931
|
-
* @returns 异步可迭代的 ReasoningStreamEvent
|
|
3932
|
-
*/
|
|
3933
|
-
runStream: (query: string, options?: ReasoningOptions) => AsyncIterable<ReasoningStreamEvent>;
|
|
3934
|
-
}
|
|
3935
|
-
|
|
3936
|
-
export { ModelEntrySchema as $, type A2AConfig as A, EntityTypeSchema as B, type CompressConfig as C, FileConfigSchema as D, type EmbeddingConfig as E, type FileConfig as F, ImageConfigSchema as G, type ImageModelEntry as H, type ImageConfig as I, ImageModelEntrySchema as J, type ImageProviderName as K, ImageProviderSchema as L, type KnowledgeConfig as M, KnowledgeConfigSchema as N, type LLMConfig as O, LLMConfigSchema as P, type MCPConfig as Q, MCPConfigSchema as R, type MCPServerCapabilities as S, MCPServerCapabilitiesSchema as T, type MCPServerConfig as U, MCPServerConfigSchema as V, type MemoryConfig as W, MemoryConfigSchema as X, type MemoryType as Y, MemoryTypeSchema as Z, type ModelEntry as _, A2AConfigSchema as a, type ChatRecord as a$, type ModelScenario as a0, ModelScenarioSchema as a1, OptionalSecretSchema as a2, type PlayableAudio as a3, type ResolveRequiredModelEntryOptions as a4, type ResolvedAudioModel as a5, type ResolvedImageModel as a6, type ResolvedModelConfig as a7, type RetrievalConfig as a8, RetrievalConfigSchema as a9, type A2AAgentCardConfig as aA, type A2AApiKeySecurity as aB, type A2AAuthenticator as aC, type A2ACallOptions as aD, type A2ACallResult as aE, type A2ACallerIdentity as aF, type A2AContextInfo as aG, type A2AHandleResult as aH, type A2AMessageRecord as aI, type A2AOperations as aJ, type A2ASecurityConfig as aK, type A2ATaskFilter as aL, type AILLMFunctionsDeps as aM, type AIRelStore as aN, type AIRelStoreOptions as aO, type AIStoreProvider as aP, type AIVectorBackend as aQ, type AIVectorStore as aR, type AskOptions as aS, type AssistantMessage as aT, type ChatCompletionChoice as aU, type ChatCompletionChunk as aV, type ChatCompletionDelta as aW, type ChatCompletionRequest as aX, type ChatCompletionResponse as aY, type ChatHistoryOptions as aZ, type ChatMessage as a_, type RetrievalSourceConfig as aa, RetrievalSourceSchema as ab, type SummaryConfig as ac, SummaryConfigSchema as ad, type SynthesisEvent as ae, type SynthesisOptions as af, type SynthesisRequest as ag, type SynthesisResult as ah, type SynthesisStreamRequest as ai, type SynthesisTextSegment as aj, type TokenConfig as ak, TokenConfigSchema as al, type TranscriptionEvent as am, type TranscriptionOptions as an, type TranscriptionRequest as ao, type TranscriptionResult as ap, type TranscriptionSegment as aq, type TranscriptionStreamRequest as ar, type TranscriptionTimestampGranularity as as, type TranscriptionWord as at, ensureAudioCredential as au, resolveAudioModel as av, resolveImageModel as aw, resolveModelApi as ax, resolveModelEntry as ay, type InteractionScope as az, A2ASkillConfigSchema as b, type SSEEvent as b$, type Citation as b0, type DefineToolOptions as b1, type DeveloperMessage as b2, type EntityDocumentRelation as b3, type EntityDocumentResult as b4, type EntityListOptions as b5, type EntityQueryOptions as b6, type GenerateObjectRequest as b7, type ImageContent as b8, type KnowledgeAskOptions as b9, type MemoryInjectionOptions as bA, type MemoryListOptions as bB, type MemoryListPageOptions as bC, type MemoryOperations as bD, type MemoryRecallOptions as bE, type MemoryUpdateInput as bF, type MessageContent as bG, type MessageRole as bH, type ObjectRef as bI, type RagContextItem as bJ, type RagOperations as bK, type RagOptions as bL, type RagResult as bM, type RagStreamEvent as bN, type ReasoningOperations as bO, type ReasoningOptions as bP, type ReasoningResult as bQ, type ReasoningStep as bR, type ReasoningStepType as bS, type ReasoningStrategy as bT, type ReasoningStreamEvent as bU, type RetrievalOperations as bV, type RetrievalRequest as bW, type RetrievalResult as bX, type RetrievalResultItem as bY, type RetrievalSource as bZ, type SSEDecoder as b_, type KnowledgeAskResult as ba, type KnowledgeDocumentInfo as bb, type KnowledgeDocumentListOptions as bc, type KnowledgeDocumentRemoveOptions as bd, type KnowledgeEntity as be, type KnowledgeIngestBatchProgress as bf, type KnowledgeIngestBatchResult as bg, type KnowledgeIngestFileInput as bh, type KnowledgeIngestInput as bi, type KnowledgeIngestResult as bj, type KnowledgeOperations as bk, type KnowledgeRetrieveItem as bl, type KnowledgeRetrieveOptions as bm, type KnowledgeRetrieveResult as bn, type KnowledgeSetupOptions as bo, type KnowledgeStore as bp, type LLMOperations as bq, type LLMProvider as br, type MemoryAccessScope as bs, type MemoryAdminOperations as bt, type MemoryClearAllOptions as bu, type MemoryClearOptions as bv, type MemoryCoreOperations as bw, type MemoryEntry as bx, type MemoryEntryInput as by, type MemoryExtractOptions as bz, type AIConfig as c, type ScopedMemoryBinding as c0, type ScopedMemoryOperations as c1, type SessionInfo as c2, type StoreFilter as c3, type StorePage as c4, type StoreScope as c5, type StreamOperations as c6, type StreamProcessor as c7, type StreamResult as c8, type SystemMessage as c9, type TempModelConfig as ca, type TextContent as cb, type TokenUsage as cc, type Tool as cd, type ToolAuthorizationRequest as ce, type ToolAuthorizer as cf, type ToolCall as cg, type ToolDefinition as ch, type ToolErrorType as ci, type ToolExecutionContext as cj, type ToolExecutionOptions as ck, type ToolMessage as cl, type ToolRegistryOperations as cm, type ToolRegistryOptions as cn, type ToolsOperations as co, type UserMessage as cp, type WhereClause as cq, type WhereOperator as cr, type WhereValue as cs, type AIConfigInput as d, AIConfigSchema as e, type ApiType as f, ApiTypeSchema as g, type AudioCapabilitiesRequest as h, type AudioConfig as i, AudioConfigSchema as j, type AudioContent as k, type AudioFormat as l, type AudioInputStream as m, type AudioModelCapabilities as n, type AudioModelEntry as o, AudioModelEntrySchema as p, type AudioOperation as q, AudioOperationSchema as r, type AudioOperations as s, AudioOperationsSchema as t, type AudioProviderName as u, AudioProviderSchema as v, type AudioReference as w, CompressConfigSchema as x, EmbeddingConfigSchema as y, type EntityType as z };
|