@h-ai/ai 0.1.0-alpha5

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.
@@ -0,0 +1,1095 @@
1
+ import * as _h_ai_core from '@h-ai/core';
2
+ import { HaiResult } from '@h-ai/core';
3
+ import { af as ChatMessage, ao as InteractionScope, aM as MemoryInjectionOptions, aX as RagOptions, a$ as ReasoningOptions, br as ToolRegistryOperations, bc as SessionInfo, aG as LLMOperations, aP as MemoryOperations, aW as RagOperations, a_ as ReasoningOperations, c as AIConfig, d as AIConfigInput, a5 as AIStoreProvider, bs as ToolsOperations, bg as StreamOperations, b5 as RetrievalOperations, aA as KnowledgeOperations, $ as A2AOperations } from './ai-reasoning-types-ZRy23rSK.js';
4
+ import { z } from 'zod';
5
+ import { Buffer } from 'node:buffer';
6
+
7
+ /**
8
+ * @h-ai/ai — Compress 子功能类型
9
+ *
10
+ * 定义上下文压缩操作的类型接口:滑动窗口、摘要、混合三种策略。
11
+ * 在对话超出模型上下文窗口时,自动压缩历史消息以保持对话连续性。
12
+ * @module ai-compress-types
13
+ */
14
+
15
+ /** 压缩策略枚举 */
16
+ declare const CompressionStrategySchema: z.ZodEnum<{
17
+ summary: "summary";
18
+ "sliding-window": "sliding-window";
19
+ hybrid: "hybrid";
20
+ }>;
21
+ /** 压缩策略类型 */
22
+ type CompressionStrategy = z.infer<typeof CompressionStrategySchema>;
23
+ /**
24
+ * 上下文压缩选项
25
+ */
26
+ interface CompressOptions {
27
+ /** 压缩策略(默认使用配置的 defaultStrategy) */
28
+ strategy?: CompressionStrategy;
29
+ /** 目标 token 数(默认使用配置的 defaultMaxTokens,0 表示取模型 maxTokens 的 80%) */
30
+ maxTokens?: number;
31
+ /** 保留 system 消息(默认 true) */
32
+ preserveSystem?: boolean;
33
+ /** 保留最近 N 条消息不压缩(默认使用配置的 preserveLastN) */
34
+ preserveLastN?: number;
35
+ /** 摘要用的模型 */
36
+ summaryModel?: string;
37
+ }
38
+ /**
39
+ * 上下文压缩结果
40
+ */
41
+ interface CompressResult {
42
+ /** 压缩后的消息列表 */
43
+ messages: ChatMessage[];
44
+ /** 原始消息的估算 token 数 */
45
+ originalTokens: number;
46
+ /** 压缩后的估算 token 数 */
47
+ compressedTokens: number;
48
+ /** 被移除/合并的消息数 */
49
+ removedCount: number;
50
+ /** 生成的摘要文本(仅 summary/hybrid 策略有值) */
51
+ summary?: string;
52
+ }
53
+ /**
54
+ * Compress 操作接口
55
+ *
56
+ * 管理对话消息的压缩,支持三种策略:
57
+ * - `sliding-window`:移除最旧的消息,保留最近 N 条
58
+ * - `summary`:使用 LLM 生成摘要替换旧消息
59
+ * - `hybrid`:先滑动窗口,不够则回退到摘要
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const result = await compressOps.tryCompress(messages, {
64
+ * strategy: 'hybrid',
65
+ * maxTokens: 4000,
66
+ * })
67
+ * if (result.success) {
68
+ * const compressed = result.data.messages
69
+ * }
70
+ * ```
71
+ */
72
+ interface CompressOperations {
73
+ /**
74
+ * 尝试压缩消息列表,使其不超过指定 Token 预算
75
+ *
76
+ * 如果当前 token 数未超限则直接返回(不压缩),因此命名为 tryCompress。
77
+ *
78
+ * @param messages - 消息列表
79
+ * @param options - 压缩选项
80
+ * @returns 压缩结果
81
+ */
82
+ tryCompress: (messages: ChatMessage[], options?: CompressOptions) => Promise<HaiResult<CompressResult>>;
83
+ }
84
+
85
+ /**
86
+ * @h-ai/ai — Summary 子功能类型
87
+ *
88
+ * 定义摘要生成操作的类型接口:使用 LLM 对对话消息生成摘要,支持增量摘要。
89
+ * @module ai-summary-types
90
+ */
91
+
92
+ /**
93
+ * 摘要生成选项
94
+ */
95
+ interface SummaryOptions {
96
+ /** 摘要用的模型 */
97
+ model?: string;
98
+ /** 温度覆盖 */
99
+ temperature?: number;
100
+ /** 自定义摘要 systemPrompt(覆盖模块配置与内置默认提示词) */
101
+ systemPrompt?: string;
102
+ /** 前序摘要文本(用于增量摘要) */
103
+ previousSummary?: string;
104
+ }
105
+ /**
106
+ * 摘要生成结果
107
+ */
108
+ interface SummaryResult {
109
+ /** 摘要文本 */
110
+ summary: string;
111
+ /** 摘要的估算 Token 数 */
112
+ tokenCount: number;
113
+ /** 覆盖的原始消息数 */
114
+ coveredMessages: number;
115
+ }
116
+ /**
117
+ * Summary 操作接口
118
+ *
119
+ * 使用 LLM 对消息列表生成摘要,支持全量摘要与增量摘要。
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * // 生成摘要(含元数据)
124
+ * const result = await summaryOps.summarize(messages)
125
+ * // result.data: { summary, tokenCount, coveredMessages }
126
+ *
127
+ * // 仅获取摘要文本
128
+ * const text = await summaryOps.generate(messages)
129
+ *
130
+ * // 增量摘要
131
+ * const updated = await summaryOps.summarize(newMessages, {
132
+ * systemPrompt: 'Focus on product decisions and pending action items.',
133
+ * previousSummary: oldSummary,
134
+ * })
135
+ * ```
136
+ */
137
+ interface SummaryOperations {
138
+ /**
139
+ * 生成摘要文本
140
+ *
141
+ * @param messages - 消息列表
142
+ * @param options - 摘要选项
143
+ * @returns 摘要文本
144
+ */
145
+ generate: (messages: ChatMessage[], options?: SummaryOptions) => Promise<HaiResult<string>>;
146
+ /**
147
+ * 生成摘要(含元数据)
148
+ *
149
+ * @param messages - 消息列表
150
+ * @param options - 摘要选项
151
+ * @returns 摘要结果(含 Token 数、覆盖消息数)
152
+ */
153
+ summarize: (messages: ChatMessage[], options?: SummaryOptions) => Promise<HaiResult<SummaryResult>>;
154
+ }
155
+
156
+ /**
157
+ * @h-ai/ai — Context 子功能类型
158
+ *
159
+ * 定义上下文管理操作的类型接口。
160
+ * Context 是全部子模块的聚合层,提供有状态的 ContextManager:
161
+ * 多轮对话自动压缩 + 可选 LLM / Memory / RAG / Reasoning / Tools 编排。
162
+ * @module ai-context-types
163
+ */
164
+
165
+ /**
166
+ * Context 子功能可选依赖
167
+ *
168
+ * 传入后 ContextManager 可提供 chat/chatStream 等高层编排能力。
169
+ * 各依赖按需传入,未传入的能力不可用。
170
+ */
171
+ interface ContextDeps {
172
+ /** LLM 操作(chat/chatStream 必需) */
173
+ llm?: LLMOperations;
174
+ /** Memory 操作(记忆注入/提取需要) */
175
+ memory?: MemoryOperations;
176
+ /** RAG 操作(检索增强生成需要) */
177
+ rag?: RagOperations;
178
+ /** Reasoning 操作(推理引擎需要) */
179
+ reasoning?: ReasoningOperations;
180
+ }
181
+ /**
182
+ * 有状态上下文管理器配置
183
+ *
184
+ * 通过嵌套子对象直接引用各子模块的配置类型,避免字段重复声明。
185
+ */
186
+ interface ContextManagerOptions {
187
+ /** 交互作用域(objectId + sessionId) */
188
+ scope?: InteractionScope;
189
+ /** 系统提示词(创建时作为首条 system 消息追加) */
190
+ systemPrompt?: string;
191
+ /** LLM 模型名覆盖 */
192
+ model?: string;
193
+ /** 温度覆盖 */
194
+ temperature?: number;
195
+ /**
196
+ * 压缩配置(覆盖全局 compress 配置)
197
+ *
198
+ * 直接引用 CompressOptions,加上 auto 开关。
199
+ */
200
+ compress?: CompressOptions & {
201
+ /** 是否自动触发压缩(默认 true) */
202
+ auto?: boolean;
203
+ };
204
+ /**
205
+ * 记忆配置
206
+ *
207
+ * 引用 MemoryInjectionOptions 的检索控制字段,加上 enable/enableExtract 开关。
208
+ */
209
+ memory?: Pick<MemoryInjectionOptions, 'topK' | 'maxTokens' | 'position'> & {
210
+ /** 是否启用记忆注入(默认 false) */
211
+ enable?: boolean;
212
+ /** 是否启用自动记忆提取(默认 false) */
213
+ enableExtract?: boolean;
214
+ };
215
+ /**
216
+ * RAG 配置
217
+ *
218
+ * 引用 RagOptions 中检索相关的字段。
219
+ */
220
+ rag?: Pick<RagOptions, 'sources' | 'topK' | 'minScore' | 'enableRerank' | 'rerankModel'> & {
221
+ /** 是否启用 RAG 检索增强(默认 false) */
222
+ enable?: boolean;
223
+ };
224
+ /**
225
+ * 推理配置
226
+ *
227
+ * 引用 ReasoningOptions 中策略相关的字段。
228
+ */
229
+ reasoning?: Pick<ReasoningOptions, 'strategy' | 'maxRounds'> & {
230
+ /** 是否启用推理引擎替代普通 LLM(默认 false) */
231
+ enable?: boolean;
232
+ };
233
+ /** 工具注册表(传入后 chat/chatStream 支持 function calling) */
234
+ tools?: ToolRegistryOperations;
235
+ /**
236
+ * 工具调用最大轮次(默认 10)
237
+ *
238
+ * 当 LLM 返回 tool_calls 时,自动执行工具并将结果回传 LLM,
239
+ * 重复此过程直到 LLM 给出文本回复或达到最大轮次。
240
+ */
241
+ maxToolRounds?: number;
242
+ }
243
+ /**
244
+ * 单次 chat/chatStream 请求的覆盖选项
245
+ */
246
+ interface ContextChatOptions {
247
+ /** LLM 模型名覆盖 */
248
+ model?: string;
249
+ /** 温度覆盖 */
250
+ temperature?: number;
251
+ /** 是否启用本次 LLM 调用的持久化(默认 false,Context 自行管理状态) */
252
+ enablePersist?: boolean;
253
+ }
254
+ /**
255
+ * chat() 返回的结果
256
+ */
257
+ interface ContextChatResult {
258
+ /** LLM 回复内容 */
259
+ reply: string;
260
+ /** 使用的模型 */
261
+ model: string;
262
+ /** Token 使用统计 */
263
+ usage?: {
264
+ prompt_tokens: number;
265
+ completion_tokens: number;
266
+ total_tokens: number;
267
+ };
268
+ }
269
+ /**
270
+ * chatStream() 产出的事件
271
+ */
272
+ type ContextStreamEvent = {
273
+ type: 'delta';
274
+ text: string;
275
+ } | {
276
+ type: 'tool_call';
277
+ name: string;
278
+ arguments: string;
279
+ } | {
280
+ type: 'tool_result';
281
+ name: string;
282
+ content: string;
283
+ success: boolean;
284
+ } | {
285
+ type: 'done';
286
+ reply: string;
287
+ model: string;
288
+ usage?: {
289
+ prompt_tokens: number;
290
+ completion_tokens: number;
291
+ total_tokens: number;
292
+ };
293
+ };
294
+ /**
295
+ * 有状态上下文管理器接口
296
+ *
297
+ * 适用于多轮对话场景。追加消息并在超限时自动压缩;
298
+ * 若传入 deps.llm 则可直接通过 chat/chatStream 进行对话编排。
299
+ *
300
+ * @example
301
+ * ```ts
302
+ * // 创建管理器并直接对话
303
+ * const managerResult = ai.context.createManager({
304
+ * scope: { objectId: 'user-001', sessionId: 'sess-001' },
305
+ * systemPrompt: '你是一个友好的助手。',
306
+ * compress: { maxTokens: 8000, strategy: 'hybrid' },
307
+ * memory: { enable: true, enableExtract: true },
308
+ * })
309
+ * const manager = managerResult.data
310
+ *
311
+ * const result = await manager.chat('你好')
312
+ * console.log(result.data.reply)
313
+ *
314
+ * for await (const event of manager.chatStream('讲个故事')) {
315
+ * if (event.type === 'delta') process.stdout.write(event.text)
316
+ * }
317
+ *
318
+ * await manager.save()
319
+ * ```
320
+ */
321
+ interface ContextManager {
322
+ /** 当前作用域(如已配置) */
323
+ readonly scope?: InteractionScope;
324
+ /**
325
+ * 追加消息
326
+ *
327
+ * 自动在超限时触发压缩(如果启用了 compress.auto)。
328
+ *
329
+ * @param message - 要追加的消息
330
+ * @returns 成功返回 ok(undefined)
331
+ */
332
+ addMessage: (message: ChatMessage) => Promise<HaiResult<void>>;
333
+ /**
334
+ * 获取当前消息列表(压缩后)
335
+ *
336
+ * @returns 当前消息列表
337
+ */
338
+ getMessages: () => HaiResult<ChatMessage[]>;
339
+ /**
340
+ * 获取当前 token 使用量
341
+ *
342
+ * @returns 当前 token 数和预算
343
+ */
344
+ getTokenUsage: () => HaiResult<{
345
+ current: number;
346
+ budget: number;
347
+ }>;
348
+ /**
349
+ * 获取历史摘要列表
350
+ *
351
+ * @returns 每次压缩产生的摘要
352
+ */
353
+ getSummaries: () => HaiResult<SummaryResult[]>;
354
+ /**
355
+ * 持久化当前状态(需要 scope + 存储可用)
356
+ */
357
+ save: () => Promise<HaiResult<void>>;
358
+ /**
359
+ * 重置管理器(清空所有消息和摘要)
360
+ */
361
+ reset: () => void;
362
+ /**
363
+ * 发送消息并获取回复(需 deps.llm 可用)
364
+ *
365
+ * 流程:追加用户消息 → 自动压缩 → 注入记忆(可选) → RAG(可选) → LLM/Reasoning → 追加助手消息 → 提取记忆(可选)
366
+ *
367
+ * @param message - 用户消息文本
368
+ * @param options - 单次请求覆盖选项
369
+ * @returns 对话结果
370
+ */
371
+ chat: (message: string, options?: ContextChatOptions) => Promise<HaiResult<ContextChatResult>>;
372
+ /**
373
+ * 流式发送消息并获取回复(需 deps.llm 可用)
374
+ *
375
+ * 产出事件序列:delta* → done
376
+ *
377
+ * @param message - 用户消息文本
378
+ * @param options - 单次请求覆盖选项
379
+ * @returns 异步可迭代的 ContextStreamEvent
380
+ */
381
+ chatStream: (message: string, options?: ContextChatOptions) => AsyncIterable<ContextStreamEvent>;
382
+ }
383
+ /**
384
+ * Context 操作接口(通过 `ai.context` 访问)
385
+ *
386
+ * 提供有状态的 ContextManager,管理多轮对话的消息追加、自动压缩与对话编排。
387
+ * 原子操作(token / summary / compress)已独立暴露在 `ai.token`、`ai.summary`、`ai.compress`。
388
+ * 需要先调用 `ai.init()` 初始化后使用。
389
+ *
390
+ * @example
391
+ * ```ts
392
+ * // 创建管理器并对话
393
+ * const managerResult = ai.context.createManager({
394
+ * scope: { objectId: 'user-001', sessionId: 'sess-001' },
395
+ * compress: { maxTokens: 8000 },
396
+ * memory: { enable: true },
397
+ * })
398
+ * const manager = managerResult.data
399
+ * const result = await manager.chat('你好')
400
+ *
401
+ * // 从持久化恢复管理器
402
+ * const restored = await ai.context.restoreManager(
403
+ * { objectId: 'user-001', sessionId: 'sess-001' },
404
+ * { memory: { enable: true } },
405
+ * )
406
+ * ```
407
+ */
408
+ interface ContextOperations {
409
+ /**
410
+ * 创建有状态上下文管理器
411
+ *
412
+ * @param options - 管理器配置
413
+ * @returns 管理器实例
414
+ */
415
+ createManager: (options?: ContextManagerOptions) => HaiResult<ContextManager>;
416
+ /**
417
+ * 从持久化恢复上下文管理器
418
+ *
419
+ * @param scope - 交互作用域
420
+ * @param options - 管理器配置覆盖
421
+ * @returns 恢复的管理器实例
422
+ */
423
+ restoreManager: (scope: InteractionScope, options?: Omit<ContextManagerOptions, 'scope'>) => Promise<HaiResult<ContextManager>>;
424
+ /**
425
+ * 列出指定主体的所有会话
426
+ *
427
+ * @param objectId - 主体 ID
428
+ * @returns 会话信息列表
429
+ */
430
+ listSessions: (objectId: string) => Promise<HaiResult<SessionInfo[]>>;
431
+ /**
432
+ * 重命名会话
433
+ *
434
+ * @param sessionId - 会话 ID
435
+ * @param title - 新标题
436
+ * @returns 成功返回 ok(undefined)
437
+ */
438
+ renameSession: (sessionId: string, title: string) => Promise<HaiResult<void>>;
439
+ /**
440
+ * 删除会话(删除会话元数据和对应的上下文数据)
441
+ *
442
+ * @param sessionId - 会话 ID
443
+ * @returns 成功返回 ok(undefined)
444
+ */
445
+ removeSession: (sessionId: string) => Promise<HaiResult<void>>;
446
+ }
447
+
448
+ /**
449
+ * @h-ai/ai — Embedding 子功能类型
450
+ *
451
+ * 定义向量嵌入操作的类型接口。
452
+ * @module ai-embedding-types
453
+ */
454
+
455
+ /**
456
+ * Embedding 请求参数
457
+ */
458
+ interface EmbeddingRequest {
459
+ /** 输入文本(单条或批量) */
460
+ input: string | string[];
461
+ /** 模型名称(可选,未指定时使用配置中的默认模型) */
462
+ model?: string;
463
+ /** 向量维度(可选,部分模型支持) */
464
+ dimensions?: number;
465
+ }
466
+ /**
467
+ * 单条 Embedding 结果
468
+ */
469
+ interface EmbeddingItem {
470
+ /** 在输入列表中的索引 */
471
+ index: number;
472
+ /** 向量数据 */
473
+ embedding: number[];
474
+ }
475
+ /**
476
+ * Embedding 响应
477
+ */
478
+ interface EmbeddingResponse {
479
+ /** 模型名称 */
480
+ model: string;
481
+ /** Embedding 结果列表 */
482
+ data: EmbeddingItem[];
483
+ /** Token 使用统计 */
484
+ usage: {
485
+ prompt_tokens: number;
486
+ total_tokens: number;
487
+ };
488
+ }
489
+ /**
490
+ * Embedding Provider 接口
491
+ *
492
+ * 底层嵌入 API 适配层。
493
+ */
494
+ interface EmbeddingProvider {
495
+ /** 生成向量嵌入 */
496
+ embed: (request: EmbeddingRequest) => Promise<HaiResult<EmbeddingResponse>>;
497
+ }
498
+ /**
499
+ * Embedding 操作接口(通过 `ai.embedding` 访问)
500
+ *
501
+ * 需要先调用 `ai.init()` 初始化后使用。
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * // 单条文本嵌入
506
+ * const result = await ai.embedding.embed({ input: 'Hello World' })
507
+ *
508
+ * // 批量嵌入
509
+ * const result = await ai.embedding.embed({
510
+ * input: ['文本1', '文本2', '文本3'],
511
+ * })
512
+ * ```
513
+ */
514
+ interface EmbeddingOperations {
515
+ /**
516
+ * 生成向量嵌入
517
+ *
518
+ * @param request - Embedding 请求
519
+ * @returns Embedding 响应
520
+ */
521
+ embed: (request: EmbeddingRequest) => Promise<HaiResult<EmbeddingResponse>>;
522
+ /**
523
+ * 便捷方法:嵌入单条文本,直接返回向量
524
+ *
525
+ * @param text - 输入文本
526
+ * @returns 向量数组
527
+ */
528
+ embedText: (text: string) => Promise<HaiResult<number[]>>;
529
+ /**
530
+ * 便捷方法:批量嵌入文本,返回向量列表
531
+ *
532
+ * @param texts - 输入文本列表
533
+ * @returns 向量数组列表(与输入顺序一致)
534
+ */
535
+ embedBatch: (texts: string[]) => Promise<HaiResult<number[][]>>;
536
+ }
537
+
538
+ /**
539
+ * @h-ai/ai — File 子功能类型
540
+ *
541
+ * 定义文件解析操作的类型接口。
542
+ * @module ai-file-types
543
+ */
544
+
545
+ /**
546
+ * 文件解析方法
547
+ *
548
+ * - `text` — 直接解码为 UTF-8 文本(txt / md / csv / 等文本格式)
549
+ * - `html` — HTML 标签剥除后提取文本
550
+ * - `pdf` — 使用 pdfjs-dist 解析 PDF(需安装可选依赖)
551
+ * - `docx` — 使用 mammoth 解析 Word 文档(需安装可选依赖)
552
+ * - `ocr` — 通过视觉 LLM 进行 OCR 识别(图片及无原生解析器的格式)
553
+ */
554
+ type FileParseMethod = 'text' | 'html' | 'pdf' | 'docx' | 'ocr';
555
+ /**
556
+ * 文件解析输出格式
557
+ * - `text` — 纯文本(默认),适合程序处理
558
+ * - `markdown` — Markdown 格式,保留文档结构(标题、列表、粗斜体等),
559
+ * 适用于 HTML、PDF、DOCX;图片 OCR 会提示模型输出 Markdown
560
+ */
561
+ type OutputFormat = 'text' | 'markdown';
562
+ /**
563
+ * 文件解析选项
564
+ */
565
+ interface FileParseOptions {
566
+ /** 强制使用指定 MIME 类型(覆盖自动检测) */
567
+ mimeType?: string;
568
+ /** 强制使用 OCR(即使有原生解析器支持) */
569
+ useOcr?: boolean;
570
+ /**
571
+ * OCR 使用的视觉模型(请求级覆盖)
572
+ *
573
+ * 最高优先级,覆盖 `llm.scenarios.ocr` 场景映射。
574
+ * 未指定时通过 `llm.scenarios.ocr` 解析。
575
+ */
576
+ model?: string;
577
+ /** OCR 系统提示词(覆盖全局 `file.systemPrompt` 配置) */
578
+ systemPrompt?: string;
579
+ /** PDF 最大解析页数(默认解析全部页) */
580
+ maxPages?: number;
581
+ /**
582
+ * 输出格式(默认 `'text'`)
583
+ */
584
+ outputFormat?: OutputFormat;
585
+ }
586
+ /**
587
+ * 文件解析请求
588
+ */
589
+ interface FileParseRequest {
590
+ /**
591
+ * 文件内容
592
+ *
593
+ * - `Buffer` — 二进制文件(图片、PDF、DOCX 等)
594
+ * - `string` — 文本内容(直接传入文本格式文件)
595
+ */
596
+ content: Buffer | string;
597
+ /** 文件名(用于 MIME 类型自动检测,可选) */
598
+ filename?: string;
599
+ /** 解析选项 */
600
+ options?: FileParseOptions;
601
+ }
602
+ /**
603
+ * 文件解析结果
604
+ */
605
+ interface FileParseResult {
606
+ /** 提取的文本内容(当 `outputFormat` 为 `'markdown'` 时为 Markdown 格式) */
607
+ text: string;
608
+ /** 解析方法 */
609
+ method: FileParseMethod;
610
+ /** 页数(PDF 解析时) */
611
+ pageCount?: number;
612
+ /** 元数据 */
613
+ metadata?: {
614
+ filename?: string;
615
+ mimeType?: string;
616
+ charCount?: number;
617
+ };
618
+ }
619
+ /**
620
+ * File 操作接口(通过 `ai.file` 访问)
621
+ *
622
+ * 需要先调用 `ai.init()` 初始化后使用(OCR 功能需要 LLM 配置)。
623
+ *
624
+ * 支持的格式:
625
+ * - 文本格式(txt、md、csv 等):直接解码
626
+ * - HTML:剥除标签后提取文本
627
+ * - PDF:使用 pdfjs-dist(需安装),否则回退到 OCR
628
+ * - DOCX:使用 mammoth(需安装),否则回退到 OCR
629
+ * - 图片(JPEG、PNG、GIF、WebP):通过视觉 LLM OCR 识别
630
+ *
631
+ * @example
632
+ * ```ts
633
+ * import { readFile } from 'node:fs/promises'
634
+ *
635
+ * // 解析 PDF(OCR 模型通过 llm.scenarios.ocr 配置)
636
+ * ai.init({ llm: { apiKey: 'sk-...', scenarios: { ocr: 'gpt-4o' } } })
637
+ *
638
+ * const pdf = await readFile('document.pdf')
639
+ * const result = await ai.file.parse({ content: pdf, filename: 'document.pdf' })
640
+ *
641
+ * // 解析图片(OCR)
642
+ * const image = await readFile('screenshot.png')
643
+ * const result = await ai.file.parse({ content: image, filename: 'screenshot.png' })
644
+ *
645
+ * // 便捷方法:直接获取文本
646
+ * const text = await ai.file.parseText(content, 'document.pdf')
647
+ * ```
648
+ */
649
+ interface FileOperations {
650
+ /**
651
+ * 解析文件内容,提取文本
652
+ *
653
+ * 自动检测文件格式,选择最优解析方法。
654
+ *
655
+ * @param request - 文件解析请求
656
+ * @returns 解析结果,包含文本内容、解析方法和元数据
657
+ */
658
+ parse: (request: FileParseRequest) => Promise<HaiResult<FileParseResult>>;
659
+ /**
660
+ * 便捷方法:直接返回提取的文本字符串
661
+ *
662
+ * @param content - 文件内容(Buffer 或文本字符串)
663
+ * @param filename - 文件名(用于格式检测,可选)
664
+ * @returns 提取的文本内容
665
+ */
666
+ parseText: (content: Buffer | string, filename?: string) => Promise<HaiResult<string>>;
667
+ }
668
+
669
+ /**
670
+ * @h-ai/ai — MCP 子功能类型
671
+ *
672
+ * 定义 MCP 工具、资源、提示词的注册与调用接口。
673
+ * @module ai-mcp-types
674
+ */
675
+
676
+ /** MCP 工具定义(注册工具时的元数据) */
677
+ interface MCPToolDefinition {
678
+ /** 工具名称(需唯一) */
679
+ name: string;
680
+ /** 工具功能描述 */
681
+ description: string;
682
+ /** 输入参数的 JSON Schema */
683
+ inputSchema: Record<string, unknown>;
684
+ }
685
+ /** MCP 工具处理器,接收输入参数和执行上下文 */
686
+ type MCPToolHandler<TInput = unknown, TOutput = unknown> = (input: TInput, context: MCPContext) => Promise<TOutput> | TOutput;
687
+ /** MCP 执行上下文,携带请求元数据 */
688
+ interface MCPContext {
689
+ /** 请求唯一标识(未传入时自动生成 UUID) */
690
+ requestId?: string;
691
+ /** 客户端信息(可选) */
692
+ clientInfo?: {
693
+ name: string;
694
+ version: string;
695
+ };
696
+ /** 自定义元数据(可选) */
697
+ metadata?: Record<string, unknown>;
698
+ }
699
+ /** MCP 资源描述(注册资源时的元数据) */
700
+ interface MCPResource {
701
+ /** 资源 URI(唯一标识) */
702
+ uri: string;
703
+ /** 资源名称 */
704
+ name: string;
705
+ /** 资源描述(可选) */
706
+ description?: string;
707
+ /** MIME 类型(可选,如 `'application/json'`) */
708
+ mimeType?: string;
709
+ }
710
+ /** MCP 资源内容(readResource 的返回值) */
711
+ interface MCPResourceContent {
712
+ /** 资源 URI */
713
+ uri: string;
714
+ /** MIME 类型(可选) */
715
+ mimeType?: string;
716
+ /** 文本内容(与 blob 二选一) */
717
+ text?: string;
718
+ /** Base64 编码的二进制内容(与 text 二选一) */
719
+ blob?: string;
720
+ }
721
+ /** MCP 提示词模板描述 */
722
+ interface MCPPrompt {
723
+ /** 提示词名称(唯一标识) */
724
+ name: string;
725
+ /** 提示词描述(可选) */
726
+ description?: string;
727
+ /** 参数定义列表(可选) */
728
+ arguments?: MCPPromptArgument[];
729
+ }
730
+ /** MCP 提示词参数定义 */
731
+ interface MCPPromptArgument {
732
+ /** 参数名称 */
733
+ name: string;
734
+ /** 参数描述(可选) */
735
+ description?: string;
736
+ /** 是否必填(默认 `false`) */
737
+ required?: boolean;
738
+ }
739
+ /** MCP 提示词消息(getPrompt 的返回值元素) */
740
+ interface MCPPromptMessage {
741
+ /** 消息角色 */
742
+ role: 'user' | 'assistant';
743
+ /** 消息内容 */
744
+ content: MCPPromptContent;
745
+ }
746
+ /** MCP 提示词内容(支持纯文本或资源引用) */
747
+ interface MCPPromptContent {
748
+ /** 内容类型:`'text'` 纯文本 | `'resource'` 资源引用 */
749
+ type: 'text' | 'resource';
750
+ /** 文本内容(type 为 `'text'` 时) */
751
+ text?: string;
752
+ /** 资源引用(type 为 `'resource'` 时) */
753
+ resource?: {
754
+ uri: string;
755
+ text?: string;
756
+ blob?: string;
757
+ mimeType?: string;
758
+ };
759
+ }
760
+ /** MCP 服务器创建选项 */
761
+ interface McpServerOptions {
762
+ /** 服务器名称 */
763
+ name: string;
764
+ /** 服务器版本(默认 `'1.0.0'`) */
765
+ version?: string;
766
+ }
767
+ /**
768
+ * MCP Provider 接口
769
+ *
770
+ * 定义 MCP 工具/资源/提示词的注册与调用能力。
771
+ */
772
+ interface MCPProvider {
773
+ registerTool: <TInput, TOutput>(definition: MCPToolDefinition, handler: MCPToolHandler<TInput, TOutput>) => HaiResult<void>;
774
+ registerResource: (resource: MCPResource, handler: () => Promise<MCPResourceContent>) => HaiResult<void>;
775
+ registerPrompt: (prompt: MCPPrompt, handler: (args: Record<string, string>) => Promise<MCPPromptMessage[]>) => HaiResult<void>;
776
+ callTool: (name: string, args: unknown, context?: MCPContext) => Promise<HaiResult<unknown>>;
777
+ readResource: (uri: string) => Promise<HaiResult<MCPResourceContent>>;
778
+ getPrompt: (name: string, args: Record<string, string>) => Promise<HaiResult<MCPPromptMessage[]>>;
779
+ }
780
+ /**
781
+ * MCP 操作接口(通过 `ai.mcp` 访问)
782
+ *
783
+ * 需要先调用 `ai.init()` 初始化,否则所有方法返回 `NOT_INITIALIZED` 错误。
784
+ */
785
+ interface MCPOperations {
786
+ registerTool: <TInput, TOutput>(definition: MCPToolDefinition, handler: MCPToolHandler<TInput, TOutput>) => HaiResult<void>;
787
+ registerResource: (resource: MCPResource, handler: () => Promise<MCPResourceContent>) => HaiResult<void>;
788
+ registerPrompt: (prompt: MCPPrompt, handler: (args: Record<string, string>) => Promise<MCPPromptMessage[]>) => HaiResult<void>;
789
+ callTool: (name: string, args: unknown, context?: MCPContext) => Promise<HaiResult<unknown>>;
790
+ readResource: (uri: string) => Promise<HaiResult<MCPResourceContent>>;
791
+ getPrompt: (name: string, args: Record<string, string>) => Promise<HaiResult<MCPPromptMessage[]>>;
792
+ }
793
+ /** MCP 子功能工厂依赖(内部使用) */
794
+ interface AIMCPFunctionsDeps {
795
+ /** 校验后的 AI 配置 */
796
+ config: AIConfig;
797
+ }
798
+
799
+ /**
800
+ * @h-ai/ai — Rerank 子功能类型
801
+ *
802
+ * 定义文档重排序操作的类型接口。
803
+ * @module ai-rerank-types
804
+ */
805
+
806
+ /**
807
+ * 单条待排序文档
808
+ */
809
+ interface RerankDocument {
810
+ /** 文档唯一标识(可选,便于结果追踪) */
811
+ id?: string;
812
+ /** 文档文本内容 */
813
+ text: string;
814
+ }
815
+ /**
816
+ * Rerank 请求参数
817
+ */
818
+ interface RerankRequest {
819
+ /** 查询文本 */
820
+ query: string;
821
+ /** 待排序文档列表(字符串数组或带 id 的文档对象数组) */
822
+ documents: string[] | RerankDocument[];
823
+ /** 模型名称(可选,未指定时使用配置中的默认模型) */
824
+ model?: string;
825
+ /** 返回结果数量(可选,默认返回全部文档) */
826
+ topN?: number;
827
+ /** 是否在结果中返回文档原文(默认 false) */
828
+ returnDocuments?: boolean;
829
+ }
830
+ /**
831
+ * 单条 Rerank 结果
832
+ */
833
+ interface RerankItem {
834
+ /** 文档在原始输入中的索引 */
835
+ index: number;
836
+ /** 文档 ID(当输入为带 id 的文档对象时) */
837
+ id?: string;
838
+ /** 相关性分数(越高越相关) */
839
+ relevanceScore: number;
840
+ /** 文档原文(当 returnDocuments 为 true 时) */
841
+ document?: string;
842
+ }
843
+ /**
844
+ * Rerank 响应
845
+ */
846
+ interface RerankResponse {
847
+ /** 使用的模型名称 */
848
+ model: string;
849
+ /** 重排序结果列表(按相关性分数降序排列) */
850
+ results: RerankItem[];
851
+ }
852
+ /**
853
+ * Rerank 操作接口(通过 `ai.rerank` 访问)
854
+ *
855
+ * 需要先调用 `ai.init()` 初始化后使用。
856
+ * 通过专用 Rerank API(兼容 Cohere 格式)对文档进行相关性重排序。
857
+ *
858
+ * @example
859
+ * ```ts
860
+ * // 对检索结果重排序
861
+ * const result = await ai.rerank.rerank({
862
+ * query: '机器学习入门',
863
+ * documents: [
864
+ * '深度学习是机器学习的一个分支',
865
+ * '今天天气真好',
866
+ * '神经网络是深度学习的基础',
867
+ * ],
868
+ * topN: 2,
869
+ * })
870
+ *
871
+ * // 便捷方法:直接传入文本数组
872
+ * const items = await ai.rerank.rerankTexts('query', ['doc1', 'doc2'])
873
+ * ```
874
+ */
875
+ interface RerankOperations {
876
+ /**
877
+ * 对文档列表进行相关性重排序
878
+ *
879
+ * @param request - Rerank 请求
880
+ * @returns 重排序响应,结果按相关性分数降序排列
881
+ */
882
+ rerank: (request: RerankRequest) => Promise<HaiResult<RerankResponse>>;
883
+ /**
884
+ * 便捷方法:对文本数组重排序,直接返回结果列表
885
+ *
886
+ * @param query - 查询文本
887
+ * @param texts - 待排序文本列表
888
+ * @param topN - 返回条数(可选)
889
+ * @returns RerankItem 列表,按相关性分数降序排列
890
+ */
891
+ rerankTexts: (query: string, texts: string[], topN?: number) => Promise<HaiResult<RerankItem[]>>;
892
+ }
893
+
894
+ /**
895
+ * @h-ai/ai — Token 子功能类型
896
+ *
897
+ * 定义 Token 估算操作的类型接口:文本与消息级别的 Token 数估算。
898
+ * 使用 CJK 感知的字符级估算算法,无需外部分词库依赖。
899
+ * @module ai-token-types
900
+ */
901
+
902
+ /**
903
+ * Token 操作接口
904
+ *
905
+ * 提供 Token 估算能力,使用配置的 `tokenRatio` 做估算。
906
+ *
907
+ * @example
908
+ * ```ts
909
+ * const tokens = tokenOps.estimateText('Hello 世界')
910
+ * const total = tokenOps.estimateMessages(messages)
911
+ * ```
912
+ */
913
+ interface TokenOperations {
914
+ /**
915
+ * 估算单条文本的 Token 数
916
+ *
917
+ * 使用字符级估算:中文约每字 1.5 token,英文约每 4 字符 1 token。
918
+ *
919
+ * @param text - 文本内容
920
+ * @returns 估算 Token 数
921
+ */
922
+ estimateText: (text: string) => number;
923
+ /**
924
+ * 估算消息列表的总 Token 数
925
+ *
926
+ * 包含消息结构开销(每条消息约 4 token 用于角色标记和分隔)。
927
+ *
928
+ * @param messages - 消息列表
929
+ * @returns 估算 Token 总数
930
+ */
931
+ estimateMessages: (messages: ChatMessage[]) => number;
932
+ }
933
+
934
+ /**
935
+ * AI 模块标准错误定义对象。
936
+ *
937
+ * 通过 `HaiAIError.ERROR_CODE_NAME` 访问具体错误定义,如:
938
+ * ```ts
939
+ * const def = HaiAIError.NOT_INITIALIZED
940
+ * // => { code: 'hai:ai:010', httpStatus: 500, system: 'hai', module: 'ai' }
941
+ * ```
942
+ */
943
+ declare const HaiAIError: {
944
+ readonly INTERNAL_ERROR: _h_ai_core.HaiErrorDef;
945
+ readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
946
+ readonly CONFIGURATION_ERROR: _h_ai_core.HaiErrorDef;
947
+ readonly INIT_IN_PROGRESS: _h_ai_core.HaiErrorDef;
948
+ readonly RERANK_API_ERROR: _h_ai_core.HaiErrorDef;
949
+ readonly RERANK_INVALID_REQUEST: _h_ai_core.HaiErrorDef;
950
+ readonly API_ERROR: _h_ai_core.HaiErrorDef;
951
+ readonly INVALID_REQUEST: _h_ai_core.HaiErrorDef;
952
+ readonly RATE_LIMITED: _h_ai_core.HaiErrorDef;
953
+ readonly TIMEOUT: _h_ai_core.HaiErrorDef;
954
+ readonly MODEL_NOT_FOUND: _h_ai_core.HaiErrorDef;
955
+ readonly CONTEXT_LENGTH_EXCEEDED: _h_ai_core.HaiErrorDef;
956
+ readonly LLM_RECORD_FAILED: _h_ai_core.HaiErrorDef;
957
+ readonly LLM_HISTORY_FAILED: _h_ai_core.HaiErrorDef;
958
+ readonly MCP_CONNECTION_ERROR: _h_ai_core.HaiErrorDef;
959
+ readonly MCP_PROTOCOL_ERROR: _h_ai_core.HaiErrorDef;
960
+ readonly MCP_TOOL_ERROR: _h_ai_core.HaiErrorDef;
961
+ readonly MCP_RESOURCE_ERROR: _h_ai_core.HaiErrorDef;
962
+ readonly MCP_SERVER_ERROR: _h_ai_core.HaiErrorDef;
963
+ readonly EMBEDDING_API_ERROR: _h_ai_core.HaiErrorDef;
964
+ readonly EMBEDDING_MODEL_NOT_FOUND: _h_ai_core.HaiErrorDef;
965
+ readonly EMBEDDING_INPUT_TOO_LONG: _h_ai_core.HaiErrorDef;
966
+ readonly TOOL_NOT_FOUND: _h_ai_core.HaiErrorDef;
967
+ readonly TOOL_VALIDATION_FAILED: _h_ai_core.HaiErrorDef;
968
+ readonly TOOL_EXECUTION_FAILED: _h_ai_core.HaiErrorDef;
969
+ readonly TOOL_TIMEOUT: _h_ai_core.HaiErrorDef;
970
+ readonly REASONING_FAILED: _h_ai_core.HaiErrorDef;
971
+ readonly REASONING_MAX_ROUNDS: _h_ai_core.HaiErrorDef;
972
+ readonly REASONING_STRATEGY_NOT_FOUND: _h_ai_core.HaiErrorDef;
973
+ readonly RETRIEVAL_FAILED: _h_ai_core.HaiErrorDef;
974
+ readonly RETRIEVAL_SOURCE_NOT_FOUND: _h_ai_core.HaiErrorDef;
975
+ readonly RAG_FAILED: _h_ai_core.HaiErrorDef;
976
+ readonly RAG_CONTEXT_BUILD_FAILED: _h_ai_core.HaiErrorDef;
977
+ readonly KNOWLEDGE_SETUP_FAILED: _h_ai_core.HaiErrorDef;
978
+ readonly KNOWLEDGE_INGEST_FAILED: _h_ai_core.HaiErrorDef;
979
+ readonly KNOWLEDGE_RETRIEVE_FAILED: _h_ai_core.HaiErrorDef;
980
+ readonly KNOWLEDGE_ENTITY_EXTRACT_FAILED: _h_ai_core.HaiErrorDef;
981
+ readonly KNOWLEDGE_NOT_SETUP: _h_ai_core.HaiErrorDef;
982
+ readonly KNOWLEDGE_COLLECTION_NOT_FOUND: _h_ai_core.HaiErrorDef;
983
+ readonly MEMORY_EXTRACT_FAILED: _h_ai_core.HaiErrorDef;
984
+ readonly MEMORY_STORE_FAILED: _h_ai_core.HaiErrorDef;
985
+ readonly MEMORY_RECALL_FAILED: _h_ai_core.HaiErrorDef;
986
+ readonly MEMORY_NOT_FOUND: _h_ai_core.HaiErrorDef;
987
+ readonly MEMORY_ENRICH_FAILED: _h_ai_core.HaiErrorDef;
988
+ readonly FILE_PARSE_FAILED: _h_ai_core.HaiErrorDef;
989
+ readonly FILE_UNSUPPORTED_FORMAT: _h_ai_core.HaiErrorDef;
990
+ readonly FILE_OCR_FAILED: _h_ai_core.HaiErrorDef;
991
+ readonly FILE_INVALID_CONTENT: _h_ai_core.HaiErrorDef;
992
+ readonly CONTEXT_COMPRESS_FAILED: _h_ai_core.HaiErrorDef;
993
+ readonly CONTEXT_SUMMARIZE_FAILED: _h_ai_core.HaiErrorDef;
994
+ readonly CONTEXT_TOKEN_ESTIMATE_FAILED: _h_ai_core.HaiErrorDef;
995
+ readonly CONTEXT_BUDGET_EXCEEDED: _h_ai_core.HaiErrorDef;
996
+ readonly STORE_FAILED: _h_ai_core.HaiErrorDef;
997
+ readonly STORE_NOT_AVAILABLE: _h_ai_core.HaiErrorDef;
998
+ readonly SESSION_NOT_FOUND: _h_ai_core.HaiErrorDef;
999
+ readonly SESSION_FAILED: _h_ai_core.HaiErrorDef;
1000
+ readonly A2A_NOT_CONFIGURED: _h_ai_core.HaiErrorDef;
1001
+ readonly A2A_HANDLE_FAILED: _h_ai_core.HaiErrorDef;
1002
+ readonly A2A_REMOTE_CALL_FAILED: _h_ai_core.HaiErrorDef;
1003
+ readonly A2A_AUTH_FAILED: _h_ai_core.HaiErrorDef;
1004
+ readonly A2A_LIST_MESSAGES_FAILED: _h_ai_core.HaiErrorDef;
1005
+ };
1006
+ /**
1007
+ * AI 初始化运行时选项
1008
+ *
1009
+ * 用于传入运行时对象(如自定义 StoreProvider),
1010
+ * 这些对象无法通过 Zod 配置 Schema 传递。
1011
+ */
1012
+ interface AIInitOptions {
1013
+ /**
1014
+ * 自定义存储 Provider
1015
+ *
1016
+ * 提供后 AI 模块将使用此 Provider 而非默认的 reldb+vecdb 实现,
1017
+ * 此时不需要提前初始化 reldb/vecdb。
1018
+ */
1019
+ storeProvider?: AIStoreProvider;
1020
+ }
1021
+ /**
1022
+ * AI 服务接口(通过 `ai` 对象访问)
1023
+ *
1024
+ * 所有 AI 功能的统一入口,需先调用 `init()` 初始化后才能使用 `llm`、`mcp` 操作。
1025
+ * `tools` 和 `stream` 为纯函数,无需初始化即可使用。
1026
+ *
1027
+ * @example
1028
+ * ```ts
1029
+ * import { ai } from '@h-ai/ai'
1030
+ *
1031
+ * await ai.init({ llm: { model: 'gpt-4o-mini' } })
1032
+ * const result = await ai.llm.chat({ messages: [{ role: 'user', content: '你好' }] })
1033
+ * ai.close()
1034
+ * ```
1035
+ */
1036
+ interface AIFunctions {
1037
+ /**
1038
+ * 初始化 AI 服务
1039
+ *
1040
+ * 使用 Zod Schema 校验配置,失败返回 `CONFIGURATION_ERROR`。
1041
+ * 重复调用会先关闭旧实例再重新初始化。
1042
+ *
1043
+ * @param config - AI 配置(可选,默认使用空对象并应用 Schema 默认值)
1044
+ * @param options - 运行时选项(可选,用于传入自定义 StoreProvider 等运行时对象)
1045
+ * @returns 成功返回 `ok(undefined)`;配置校验失败返回 `err(HaiAIError.CONFIGURATION_ERROR)`
1046
+ */
1047
+ init: (config?: AIConfigInput, options?: AIInitOptions) => Promise<HaiResult<void>>;
1048
+ /**
1049
+ * 关闭 AI 服务,释放内部状态
1050
+ *
1051
+ * 关闭后 `llm`、`mcp` 操作将返回 `NOT_INITIALIZED` 错误。
1052
+ * 重复关闭不会报错。
1053
+ */
1054
+ close: () => void;
1055
+ /** 当前配置(未初始化时为 `null`) */
1056
+ readonly config: AIConfig | null;
1057
+ /** 是否已初始化(`init()` 成功后为 `true`,`close()` 后为 `false`) */
1058
+ readonly isInitialized: boolean;
1059
+ /** LLM 操作(聊天、流式、模型列表),需要先调用 `init()` */
1060
+ readonly llm: LLMOperations;
1061
+ /** MCP 操作(工具/资源/提示词注册与调用),需要先调用 `init()` */
1062
+ readonly mcp: MCPOperations;
1063
+ /** 工具操作(定义工具与注册表),纯函数,无需初始化 */
1064
+ readonly tools: ToolsOperations;
1065
+ /** 流处理操作(流处理器、SSE 编解码),纯函数,无需初始化 */
1066
+ readonly stream: StreamOperations;
1067
+ /** Embedding 操作(向量嵌入),需要先调用 `init()` */
1068
+ readonly embedding: EmbeddingOperations;
1069
+ /** 推理操作(ReAct / CoT / Plan-Execute),需要先调用 `init()` */
1070
+ readonly reasoning: ReasoningOperations;
1071
+ /** 检索操作(向量检索),需要先调用 `init()` */
1072
+ readonly retrieval: RetrievalOperations;
1073
+ /** RAG 操作(检索增强生成),需要先调用 `init()` */
1074
+ readonly rag: RagOperations;
1075
+ /** Knowledge 操作(知识库管理与检索),需要先调用 `init()` 和 `knowledge.setup()` */
1076
+ readonly knowledge: KnowledgeOperations;
1077
+ /** Memory 操作(记忆提取、存储、检索、注入),需要先调用 `init()` */
1078
+ readonly memory: MemoryOperations;
1079
+ /** Token 操作(Token 估算),需要先调用 `init()` */
1080
+ readonly token: TokenOperations;
1081
+ /** Summary 操作(消息摘要生成),需要先调用 `init()` */
1082
+ readonly summary: SummaryOperations;
1083
+ /** Compress 操作(上下文压缩),需要先调用 `init()` */
1084
+ readonly compress: CompressOperations;
1085
+ /** Context 操作(有状态上下文管理器,编排 LLM + Memory + RAG + Reasoning),需要先调用 `init()` */
1086
+ readonly context: ContextOperations;
1087
+ /** Rerank 操作(文档重排序),需要先调用 `init()` */
1088
+ readonly rerank: RerankOperations;
1089
+ /** File 操作(文件内容解析),需要先调用 `init()` */
1090
+ readonly file: FileOperations;
1091
+ /** A2A 操作(Agent-to-Agent 协议),需要先调用 `init()` 并配置 `a2a` */
1092
+ readonly a2a: A2AOperations;
1093
+ }
1094
+
1095
+ export { type AIFunctions as A, type MCPProvider as B, type CompressionStrategy as C, type MCPResource as D, type EmbeddingItem as E, type FileOperations as F, type MCPResourceContent as G, HaiAIError as H, type MCPToolDefinition as I, type MCPToolHandler as J, type McpServerOptions as K, type RerankItem as L, type MCPContext as M, type RerankOperations as N, type OutputFormat as O, type RerankRequest as P, type RerankResponse as Q, type RerankDocument as R, type SummaryOperations as S, type SummaryOptions as T, type SummaryResult as U, type TokenOperations as V, type AIInitOptions as a, CompressionStrategySchema as b, type AIMCPFunctionsDeps as c, type CompressOperations as d, type CompressOptions as e, type CompressResult as f, type ContextChatOptions as g, type ContextChatResult as h, type ContextDeps as i, type ContextManager as j, type ContextManagerOptions as k, type ContextOperations as l, type ContextStreamEvent as m, type EmbeddingOperations as n, type EmbeddingProvider as o, type EmbeddingRequest as p, type EmbeddingResponse as q, type FileParseMethod as r, type FileParseOptions as s, type FileParseRequest as t, type FileParseResult as u, type MCPOperations as v, type MCPPrompt as w, type MCPPromptArgument as x, type MCPPromptContent as y, type MCPPromptMessage as z };