@h-ai/ai 0.1.0-alpha.10

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,462 @@
1
+ import { core, err, ok } from '@h-ai/core';
2
+ import { z } from 'zod';
3
+ import process from 'process';
4
+ import { ChunkOptionsSchema, CleanOptionsSchema } from '@h-ai/datapipe';
5
+
6
+ // src/ai-types.ts
7
+ var AIErrorInfo = {
8
+ // 通用 (000-009)
9
+ INTERNAL_ERROR: "000:500",
10
+ // 初始化 (010-019)
11
+ NOT_INITIALIZED: "010:500",
12
+ CONFIGURATION_ERROR: "011:500",
13
+ INIT_IN_PROGRESS: "012:500",
14
+ RERANK_API_ERROR: "020:502",
15
+ RERANK_INVALID_REQUEST: "021:400",
16
+ // LLM (100-199)
17
+ API_ERROR: "100:502",
18
+ INVALID_REQUEST: "101:400",
19
+ RATE_LIMITED: "102:429",
20
+ TIMEOUT: "103:504",
21
+ MODEL_NOT_FOUND: "104:404",
22
+ CONTEXT_LENGTH_EXCEEDED: "105:400",
23
+ LLM_RECORD_FAILED: "106:500",
24
+ LLM_HISTORY_FAILED: "107:500",
25
+ // MCP (200-299)
26
+ MCP_CONNECTION_ERROR: "200:502",
27
+ MCP_PROTOCOL_ERROR: "201:502",
28
+ MCP_TOOL_ERROR: "202:500",
29
+ MCP_RESOURCE_ERROR: "203:500",
30
+ MCP_SERVER_ERROR: "204:502",
31
+ // Embedding (300-399)
32
+ EMBEDDING_API_ERROR: "300:502",
33
+ EMBEDDING_MODEL_NOT_FOUND: "301:404",
34
+ EMBEDDING_INPUT_TOO_LONG: "302:400",
35
+ // 工具 (400-499)
36
+ TOOL_NOT_FOUND: "400:404",
37
+ TOOL_VALIDATION_FAILED: "401:400",
38
+ TOOL_EXECUTION_FAILED: "402:500",
39
+ TOOL_TIMEOUT: "403:504",
40
+ // Reasoning (500-599)
41
+ REASONING_FAILED: "500:500",
42
+ REASONING_MAX_ROUNDS: "501:400",
43
+ REASONING_STRATEGY_NOT_FOUND: "502:404",
44
+ // Retrieval (600-699)
45
+ RETRIEVAL_FAILED: "600:500",
46
+ RETRIEVAL_SOURCE_NOT_FOUND: "601:404",
47
+ // RAG (700-799)
48
+ RAG_FAILED: "700:500",
49
+ RAG_CONTEXT_BUILD_FAILED: "701:500",
50
+ // Knowledge (800-899)
51
+ KNOWLEDGE_SETUP_FAILED: "800:500",
52
+ KNOWLEDGE_INGEST_FAILED: "801:500",
53
+ KNOWLEDGE_RETRIEVE_FAILED: "802:500",
54
+ KNOWLEDGE_ENTITY_EXTRACT_FAILED: "803:500",
55
+ KNOWLEDGE_NOT_SETUP: "804:500",
56
+ KNOWLEDGE_COLLECTION_NOT_FOUND: "805:404",
57
+ // Memory (900-949)
58
+ MEMORY_EXTRACT_FAILED: "900:500",
59
+ MEMORY_STORE_FAILED: "901:500",
60
+ MEMORY_RECALL_FAILED: "902:500",
61
+ MEMORY_NOT_FOUND: "903:404",
62
+ MEMORY_ENRICH_FAILED: "904:500",
63
+ // File (030-049)
64
+ FILE_PARSE_FAILED: "030:500",
65
+ FILE_UNSUPPORTED_FORMAT: "031:400",
66
+ FILE_OCR_FAILED: "032:500",
67
+ FILE_INVALID_CONTENT: "033:400",
68
+ // Context (950-999)
69
+ CONTEXT_COMPRESS_FAILED: "950:500",
70
+ CONTEXT_SUMMARIZE_FAILED: "951:500",
71
+ CONTEXT_TOKEN_ESTIMATE_FAILED: "952:500",
72
+ CONTEXT_BUDGET_EXCEEDED: "953:400",
73
+ // Store (960-969)
74
+ STORE_FAILED: "960:500",
75
+ STORE_NOT_AVAILABLE: "961:503",
76
+ // Session (970-979)
77
+ SESSION_NOT_FOUND: "970:404",
78
+ SESSION_FAILED: "971:500",
79
+ // A2A (980-999)
80
+ A2A_NOT_CONFIGURED: "980:500",
81
+ A2A_HANDLE_FAILED: "981:500",
82
+ A2A_REMOTE_CALL_FAILED: "982:502",
83
+ A2A_AUTH_FAILED: "983:401",
84
+ A2A_LIST_MESSAGES_FAILED: "984:500"
85
+ };
86
+ var HaiAIError = core.error.buildHaiErrorsDef("ai", AIErrorInfo);
87
+ var CompressionStrategySchema = z.enum(["summary", "sliding-window", "hybrid"]);
88
+ var EntityTypeSchema = z.enum(["person", "project", "concept", "organization", "location", "event", "other"]);
89
+ var MemoryTypeSchema = z.enum(["fact", "preference", "event", "entity", "instruction"]);
90
+
91
+ // messages/en-US.json
92
+ var en_US_default = {
93
+ $schema: "https://inlang.com/schema/inlang-message-format",
94
+ ai_notInitialized: "AI service not initialized. Call ai.init() first.",
95
+ ai_initFailed: "Failed to initialize AI service: {error}",
96
+ ai_initInProgress: "AI service initialization is already in progress.",
97
+ ai_requestTimeout: "Request timeout",
98
+ ai_internalError: "Internal error: {error}",
99
+ ai_mcpToolNotFound: "MCP tool '{name}' not found",
100
+ ai_mcpToolFailed: "MCP tool '{name}' execution failed: {error}",
101
+ ai_mcpResourceNotFound: "MCP resource '{uri}' not found",
102
+ ai_mcpResourceFailed: "MCP resource '{uri}' read failed: {error}",
103
+ ai_mcpPromptNotFound: "MCP prompt '{name}' not found",
104
+ ai_mcpPromptMissingArg: "MCP prompt '{name}' missing required argument '{arg}'",
105
+ ai_mcpPromptFailed: "MCP prompt '{name}' execution failed: {error}",
106
+ ai_toolNotFound: "Tool '{name}' not found",
107
+ ai_toolInvalidJson: "Invalid JSON in tool call arguments",
108
+ ai_configError: "AI config validation failed: {error}",
109
+ ai_llmRecordFailed: "Chat record save failed: {error}",
110
+ ai_llmHistoryFailed: "Chat history query failed: {error}",
111
+ ai_embeddingApiFailed: "Embedding API call failed: {error}",
112
+ ai_embeddingModelNotFound: "Embedding model '{model}' not found",
113
+ ai_embeddingInputTooLong: "Embedding input text exceeds maximum length",
114
+ ai_reasoningFailed: "Reasoning execution failed: {error}",
115
+ ai_reasoningMaxRounds: "Reasoning rounds limit reached ({rounds} rounds)",
116
+ ai_reasoningStrategyNotFound: "Reasoning strategy '{strategy}' not found",
117
+ ai_retrievalFailed: "Retrieval execution failed: {error}",
118
+ ai_retrievalSourceNotFound: "Retrieval source '{source}' not configured",
119
+ ai_ragFailed: "RAG execution failed: {error}",
120
+ ai_ragContextBuildFailed: "RAG context build failed: {error}",
121
+ ai_knowledgeSetupFailed: "Knowledge base setup failed: {error}",
122
+ ai_knowledgeIngestFailed: "Knowledge ingestion failed: {error}",
123
+ ai_knowledgeRetrieveFailed: "Knowledge retrieval failed: {error}",
124
+ ai_knowledgeEntityExtractFailed: "Entity extraction failed: {error}",
125
+ ai_knowledgeNotSetup: "Knowledge base not initialized. Call ai.knowledge.setup() first.",
126
+ ai_knowledgeCollectionNotFound: "Knowledge collection '{collection}' not found",
127
+ ai_memoryExtractFailed: "Memory extraction failed: {error}",
128
+ ai_memoryStoreFailed: "Memory storage failed: {error}",
129
+ ai_memoryRecallFailed: "Memory recall failed: {error}",
130
+ ai_memoryNotFound: "Memory entry '{id}' not found",
131
+ ai_memoryEnrichFailed: "Memory enrichment failed: {error}",
132
+ ai_contextCompressFailed: "Context compression failed: {error}",
133
+ ai_contextSummarizeFailed: "Context summarization failed: {error}",
134
+ ai_contextTokenEstimateFailed: "Token estimation failed: {error}",
135
+ ai_storeFailed: "Store operation failed: {error}",
136
+ ai_storeNotAvailable: "Store backend not available, degraded to memory mode",
137
+ ai_sessionNotFound: "Session '{id}' not found",
138
+ ai_sessionFailed: "Session operation failed: {error}",
139
+ ai_rerankApiFailed: "Rerank API call failed: {error}",
140
+ ai_rerankInvalidRequest: "Invalid rerank request: {reason}",
141
+ ai_fileParseFailed: "File parsing failed: {error}",
142
+ ai_fileUnsupportedFormat: "Unsupported file format: {mimeType}",
143
+ ai_fileOcrFailed: "OCR recognition failed: {error}",
144
+ ai_fileInvalidContent: "Invalid file content: {reason}",
145
+ ai_configMissingApiKey: "API Key is required for scenario '{scenario}'",
146
+ ai_a2aNotConfigured: "A2A service not configured. Provide 'a2a' config in ai.init().",
147
+ ai_a2aHandleFailed: "A2A request handling failed: {error}",
148
+ ai_a2aRemoteCallFailed: "A2A remote call to '{url}' failed: {error}",
149
+ ai_a2aAuthFailed: "A2A authentication failed: {error}",
150
+ ai_a2aListMessagesFailed: "A2A message listing failed: {error}"
151
+ };
152
+
153
+ // messages/zh-CN.json
154
+ var zh_CN_default = {
155
+ $schema: "https://inlang.com/schema/inlang-message-format",
156
+ ai_notInitialized: "AI \u670D\u52A1\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 ai.init()",
157
+ ai_initFailed: "AI \u670D\u52A1\u521D\u59CB\u5316\u5931\u8D25\uFF1A{error}",
158
+ ai_initInProgress: "AI \u670D\u52A1\u6B63\u5728\u521D\u59CB\u5316\u4E2D\uFF0C\u8BF7\u52FF\u91CD\u590D\u8C03\u7528\u3002",
159
+ ai_requestTimeout: "\u8BF7\u6C42\u8D85\u65F6",
160
+ ai_internalError: "\u5185\u90E8\u9519\u8BEF\uFF1A{error}",
161
+ ai_mcpToolNotFound: "MCP \u5DE5\u5177 '{name}' \u672A\u627E\u5230",
162
+ ai_mcpToolFailed: "MCP \u5DE5\u5177 '{name}' \u6267\u884C\u5931\u8D25\uFF1A{error}",
163
+ ai_mcpResourceNotFound: "MCP \u8D44\u6E90 '{uri}' \u672A\u627E\u5230",
164
+ ai_mcpResourceFailed: "MCP \u8D44\u6E90 '{uri}' \u8BFB\u53D6\u5931\u8D25\uFF1A{error}",
165
+ ai_mcpPromptNotFound: "MCP \u63D0\u793A\u8BCD '{name}' \u672A\u627E\u5230",
166
+ ai_mcpPromptMissingArg: "MCP \u63D0\u793A\u8BCD '{name}' \u7F3A\u5C11\u5FC5\u9700\u53C2\u6570 '{arg}'",
167
+ ai_mcpPromptFailed: "MCP \u63D0\u793A\u8BCD '{name}' \u6267\u884C\u5931\u8D25\uFF1A{error}",
168
+ ai_toolNotFound: "\u5DE5\u5177 '{name}' \u672A\u627E\u5230",
169
+ ai_toolInvalidJson: "\u5DE5\u5177\u8C03\u7528\u53C2\u6570 JSON \u683C\u5F0F\u65E0\u6548",
170
+ ai_configError: "AI \u914D\u7F6E\u6821\u9A8C\u5931\u8D25\uFF1A{error}",
171
+ ai_llmRecordFailed: "\u5BF9\u8BDD\u8BB0\u5F55\u4FDD\u5B58\u5931\u8D25\uFF1A{error}",
172
+ ai_llmHistoryFailed: "\u5BF9\u8BDD\u5386\u53F2\u67E5\u8BE2\u5931\u8D25\uFF1A{error}",
173
+ ai_embeddingApiFailed: "Embedding API \u8C03\u7528\u5931\u8D25\uFF1A{error}",
174
+ ai_embeddingModelNotFound: "Embedding \u6A21\u578B '{model}' \u672A\u627E\u5230",
175
+ ai_embeddingInputTooLong: "Embedding \u8F93\u5165\u6587\u672C\u8D85\u8FC7\u6700\u5927\u957F\u5EA6\u9650\u5236",
176
+ ai_reasoningFailed: "\u63A8\u7406\u6267\u884C\u5931\u8D25\uFF1A{error}",
177
+ ai_reasoningMaxRounds: "\u63A8\u7406\u8F6E\u6B21\u5DF2\u8FBE\u4E0A\u9650\uFF08{rounds} \u8F6E\uFF09",
178
+ ai_reasoningStrategyNotFound: "\u63A8\u7406\u7B56\u7565 '{strategy}' \u4E0D\u5B58\u5728",
179
+ ai_retrievalFailed: "\u68C0\u7D22\u6267\u884C\u5931\u8D25\uFF1A{error}",
180
+ ai_retrievalSourceNotFound: "\u68C0\u7D22\u6E90 '{source}' \u672A\u914D\u7F6E",
181
+ ai_ragFailed: "RAG \u6267\u884C\u5931\u8D25\uFF1A{error}",
182
+ ai_ragContextBuildFailed: "RAG \u4E0A\u4E0B\u6587\u6784\u5EFA\u5931\u8D25\uFF1A{error}",
183
+ ai_knowledgeSetupFailed: "\u77E5\u8BC6\u5E93\u521D\u59CB\u5316\u5931\u8D25\uFF1A{error}",
184
+ ai_knowledgeIngestFailed: "\u77E5\u8BC6\u5165\u5E93\u5931\u8D25\uFF1A{error}",
185
+ ai_knowledgeRetrieveFailed: "\u77E5\u8BC6\u68C0\u7D22\u5931\u8D25\uFF1A{error}",
186
+ ai_knowledgeEntityExtractFailed: "\u5B9E\u4F53\u63D0\u53D6\u5931\u8D25\uFF1A{error}",
187
+ ai_knowledgeNotSetup: "\u77E5\u8BC6\u5E93\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 ai.knowledge.setup()",
188
+ ai_knowledgeCollectionNotFound: "\u77E5\u8BC6\u96C6\u5408 '{collection}' \u4E0D\u5B58\u5728",
189
+ ai_memoryExtractFailed: "\u8BB0\u5FC6\u63D0\u53D6\u5931\u8D25\uFF1A{error}",
190
+ ai_memoryStoreFailed: "\u8BB0\u5FC6\u5B58\u50A8\u5931\u8D25\uFF1A{error}",
191
+ ai_memoryRecallFailed: "\u8BB0\u5FC6\u53EC\u56DE\u5931\u8D25\uFF1A{error}",
192
+ ai_memoryNotFound: "\u8BB0\u5FC6\u6761\u76EE '{id}' \u4E0D\u5B58\u5728",
193
+ ai_memoryEnrichFailed: "\u8BB0\u5FC6\u6CE8\u5165\u5931\u8D25\uFF1A{error}",
194
+ ai_contextCompressFailed: "\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25\uFF1A{error}",
195
+ ai_contextSummarizeFailed: "\u4E0A\u4E0B\u6587\u603B\u7ED3\u5931\u8D25\uFF1A{error}",
196
+ ai_contextTokenEstimateFailed: "Token \u4F30\u7B97\u5931\u8D25\uFF1A{error}",
197
+ ai_storeFailed: "\u5B58\u50A8\u64CD\u4F5C\u5931\u8D25\uFF1A{error}",
198
+ ai_storeNotAvailable: "\u5B58\u50A8\u540E\u7AEF\u4E0D\u53EF\u7528\uFF0C\u5DF2\u964D\u7EA7\u4E3A\u5185\u5B58\u6A21\u5F0F",
199
+ ai_sessionNotFound: "\u4F1A\u8BDD '{id}' \u4E0D\u5B58\u5728",
200
+ ai_sessionFailed: "\u4F1A\u8BDD\u64CD\u4F5C\u5931\u8D25\uFF1A{error}",
201
+ ai_rerankApiFailed: "Rerank API \u8C03\u7528\u5931\u8D25\uFF1A{error}",
202
+ ai_rerankInvalidRequest: "Rerank \u8BF7\u6C42\u53C2\u6570\u65E0\u6548\uFF1A{reason}",
203
+ ai_fileParseFailed: "\u6587\u4EF6\u89E3\u6790\u5931\u8D25\uFF1A{error}",
204
+ ai_fileUnsupportedFormat: "\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u683C\u5F0F\uFF1A{mimeType}",
205
+ ai_fileOcrFailed: "OCR \u8BC6\u522B\u5931\u8D25\uFF1A{error}",
206
+ ai_fileInvalidContent: "\u6587\u4EF6\u5185\u5BB9\u65E0\u6548\uFF1A{reason}",
207
+ ai_configMissingApiKey: "\u573A\u666F '{scenario}' \u9700\u8981\u63D0\u4F9B API Key",
208
+ ai_a2aNotConfigured: "A2A \u670D\u52A1\u672A\u914D\u7F6E\uFF0C\u8BF7\u5728 ai.init() \u4E2D\u63D0\u4F9B 'a2a' \u914D\u7F6E\u3002",
209
+ ai_a2aHandleFailed: "A2A \u8BF7\u6C42\u5904\u7406\u5931\u8D25\uFF1A{error}",
210
+ ai_a2aRemoteCallFailed: "A2A \u8FDC\u7AEF\u8C03\u7528 '{url}' \u5931\u8D25\uFF1A{error}",
211
+ ai_a2aAuthFailed: "A2A \u8BA4\u8BC1\u5931\u8D25\uFF1A{error}",
212
+ ai_a2aListMessagesFailed: "A2A \u6D88\u606F\u67E5\u8BE2\u5931\u8D25\uFF1A{error}"
213
+ };
214
+
215
+ // src/ai-i18n.ts
216
+ var aiM = core.i18n.createMessageGetter({
217
+ "zh-CN": zh_CN_default,
218
+ "en-US": en_US_default
219
+ });
220
+
221
+ // src/ai-config.ts
222
+ var ModelScenarioSchema = z.enum(["default", "chat", "reasoning", "plan", "execute", "extraction", "summary", "embedding", "rerank", "ocr", "fast"]);
223
+ var ModelEntrySchema = z.object({
224
+ /** 模型唯一标识(用于 ModelResolver 解析) */
225
+ id: z.string(),
226
+ /** 模型名称(传给 API 的实际模型名) */
227
+ model: z.string(),
228
+ /** API Key 覆盖(可选,未提供时使用全局配置) */
229
+ apiKey: z.string().optional(),
230
+ /** Base URL 覆盖(可选) */
231
+ baseUrl: z.url().optional(),
232
+ /** 最大 Token 数覆盖(可选) */
233
+ maxTokens: z.number().positive().optional(),
234
+ /** 温度覆盖(可选) */
235
+ temperature: z.number().min(0).max(2).optional(),
236
+ /** 超时覆盖(可选,毫秒) */
237
+ timeout: z.number().positive().optional()
238
+ });
239
+ var LLMConfigSchema = z.object({
240
+ /** 全局 API Key(各模型 fallback;未提供时回退到 `process.env.HAI_AI_LLM_API_KEY` 或 `process.env.OPENAI_API_KEY`) */
241
+ apiKey: z.string().optional(),
242
+ /** 全局 API 基础 URL(各模型 fallback;未提供时回退到 `process.env.HAI_AI_LLM_BASE_URL` 或 `process.env.OPENAI_BASE_URL`) */
243
+ baseUrl: z.url().optional(),
244
+ /** 默认模型名称(默认 `'gpt-4o-mini'`) */
245
+ model: z.string().optional().default("gpt-4o-mini"),
246
+ /** 全局最大 Token 数(各模型 fallback,默认 `4096`) */
247
+ maxTokens: z.number().positive().optional().default(4096),
248
+ /** 全局采样温度(各模型 fallback,范围 `[0, 2]`,默认 `0.7`) */
249
+ temperature: z.number().min(0).max(2).optional().default(0.7),
250
+ /** 全局请求超时时间(各模型 fallback,毫秒,默认 `60000`) */
251
+ timeout: z.number().positive().optional().default(6e4),
252
+ /** 多模型配置列表(各字段可选,未指定时回退到全局默认值) */
253
+ models: z.array(ModelEntrySchema).optional(),
254
+ /** 场景模型映射(场景名 → 模型 ID 或直接模型名称,各场景均可选) */
255
+ scenarios: z.object(Object.fromEntries(ModelScenarioSchema.options.map((k) => [k, z.string().optional()]))).optional()
256
+ });
257
+ function resolveModelEntry(llmConfig, scenario, explicit, options) {
258
+ let entry;
259
+ let modelName;
260
+ if (explicit) {
261
+ entry = llmConfig.models?.find((m) => m.id === explicit || m.model === explicit);
262
+ modelName = entry?.model ?? explicit;
263
+ } else {
264
+ const modelId = llmConfig.scenarios?.[scenario] ?? llmConfig.scenarios?.default;
265
+ if (modelId) {
266
+ entry = llmConfig.models?.find((m) => m.id === modelId);
267
+ modelName = entry?.model ?? modelId;
268
+ } else {
269
+ modelName = llmConfig.model ?? "gpt-4o-mini";
270
+ }
271
+ }
272
+ const resolved = {
273
+ model: modelName,
274
+ apiKey: entry?.apiKey ?? llmConfig.apiKey ?? process.env.HAI_AI_LLM_API_KEY ?? process.env.OPENAI_API_KEY,
275
+ baseUrl: entry?.baseUrl ?? llmConfig.baseUrl ?? process.env.HAI_AI_LLM_BASE_URL ?? process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1",
276
+ maxTokens: entry?.maxTokens ?? llmConfig.maxTokens ?? 4096,
277
+ temperature: entry?.temperature ?? llmConfig.temperature ?? 0.7,
278
+ timeout: entry?.timeout ?? llmConfig.timeout ?? 6e4
279
+ };
280
+ if (!resolved.apiKey) {
281
+ return err(HaiAIError.CONFIGURATION_ERROR, options?.missingApiKeyMessage ?? aiM("ai_configMissingApiKey", { params: { scenario } }));
282
+ }
283
+ return ok(resolved);
284
+ }
285
+ var MCPServerCapabilitiesSchema = z.object({
286
+ /** 是否支持工具调用(默认 `true`) */
287
+ tools: z.boolean().optional().default(true),
288
+ /** 是否支持资源访问(默认 `true`) */
289
+ resources: z.boolean().optional().default(true),
290
+ /** 是否支持提示词模板(默认 `true`) */
291
+ prompts: z.boolean().optional().default(true)
292
+ });
293
+ var MCPServerConfigSchema = z.object({
294
+ /** 服务器名称 */
295
+ name: z.string(),
296
+ /** 服务器版本(默认 `'1.0.0'`) */
297
+ version: z.string().optional().default("1.0.0"),
298
+ /** 服务器能力声明 */
299
+ capabilities: MCPServerCapabilitiesSchema.optional()
300
+ });
301
+ var MCPConfigSchema = z.object({
302
+ /** 服务器配置 */
303
+ server: MCPServerConfigSchema.optional()
304
+ });
305
+ var EmbeddingConfigSchema = z.object({
306
+ /** 向量维度(可选,部分模型支持指定维度) */
307
+ dimensions: z.number().int().positive().optional(),
308
+ /** 批量大小(单次请求最多处理的文本数,默认 100) */
309
+ batchSize: z.number().int().positive().default(100)
310
+ });
311
+ var KnowledgeConfigSchema = z.object({
312
+ /** 默认向量集合名(默认 'hai_ai_knowledge') */
313
+ collection: z.string().default("hai_ai_knowledge"),
314
+ /** 向量维度(默认 1536,需与 embedding 模型匹配) */
315
+ dimension: z.number().int().positive().default(1536),
316
+ /** 是否启用实体提取(默认 true) */
317
+ enableEntityExtraction: z.boolean().default(true),
318
+ /**
319
+ * 默认文本清洗选项
320
+ *
321
+ * 字段含义与 @h-ai/datapipe CleanOptionsInput 完全一致,
322
+ * 支持 removeHtml、removeUrls、normalizeWhitespace、customReplacements 等。
323
+ */
324
+ cleanOptions: CleanOptionsSchema.default(CleanOptionsSchema.parse({})),
325
+ /**
326
+ * 默认分块选项
327
+ *
328
+ * 字段含义与 @h-ai/datapipe ChunkOptionsInput 完全一致,
329
+ * 支持 mode、maxSize、overlap、separator、markdownMinLevel 等完整选项。
330
+ */
331
+ chunkOptions: ChunkOptionsSchema.default(ChunkOptionsSchema.parse({
332
+ mode: "markdown",
333
+ maxSize: 1500,
334
+ overlap: 200
335
+ })),
336
+ /** 实体查询命中的额外加权系数(默认 0.15,叠加到向量分数上) */
337
+ entityBoostWeight: z.number().min(0).max(1).default(0.15),
338
+ /** 自定义实体类型列表(不指定时使用内置默认类型) */
339
+ entityTypes: z.array(z.string()).optional(),
340
+ /** 自定义实体提取系统提示词(不指定时使用内置默认提示词) */
341
+ systemPrompt: z.string().optional()
342
+ });
343
+ var MemoryConfigSchema = z.object({
344
+ /** 最大记忆条数(默认 1000) */
345
+ maxEntries: z.number().int().positive().default(1e3),
346
+ /** 自定义记忆提取 systemPrompt(可选,覆盖内置默认提示词) */
347
+ systemPrompt: z.string().optional(),
348
+ /** 时间衰减系数(默认 0.95,每次检索乘以此系数调整 recency 权重) */
349
+ recencyDecay: z.number().min(0).max(1).default(0.95),
350
+ /** 是否启用向量检索(默认 true,关闭则仅使用关键词匹配) */
351
+ embeddingEnabled: z.boolean().default(true),
352
+ /** 检索时默认返回数量(默认 10) */
353
+ defaultTopK: z.number().int().positive().default(10)
354
+ });
355
+ var TokenConfigSchema = z.object({
356
+ /** Token 估算每字符系数(默认 0.25,即 4 字符 ≈ 1 token) */
357
+ tokenRatio: z.number().positive().default(0.25)
358
+ });
359
+ var SummaryConfigSchema = z.object({
360
+ /** 自定义摘要 systemPrompt(可选,覆盖内置默认提示词) */
361
+ systemPrompt: z.string().optional()
362
+ });
363
+ var CompressConfigSchema = z.object({
364
+ /** 默认压缩策略(默认 'hybrid') */
365
+ defaultStrategy: CompressionStrategySchema.default("hybrid"),
366
+ /** 默认 Token 预算(默认 0 表示取模型上限的 80%) */
367
+ defaultMaxTokens: z.number().int().min(0).default(0),
368
+ /** 默认保留最近消息数(默认 4) */
369
+ preserveLastN: z.number().int().min(0).default(4)
370
+ });
371
+ var FileConfigSchema = z.object({
372
+ /** OCR 系统提示词(可选,覆盖内置默认提示词) */
373
+ systemPrompt: z.string().optional()
374
+ });
375
+ var RetrievalSourceSchema = z.object({
376
+ /** 来源唯一标识 */
377
+ id: z.string(),
378
+ /** vecdb collection 名称 */
379
+ collection: z.string(),
380
+ /** 信源显示名 */
381
+ name: z.string().optional(),
382
+ /** 信源 URL / 路径 */
383
+ url: z.string().optional(),
384
+ /** 最大返回条数(默认 5) */
385
+ topK: z.number().int().positive().optional(),
386
+ /** 最低相似度 0~1(低于此值的结果被过滤) */
387
+ minScore: z.number().min(0).max(1).optional(),
388
+ /** 元数据过滤条件 */
389
+ filter: z.record(z.string(), z.unknown()).optional()
390
+ });
391
+ var RetrievalConfigSchema = z.object({
392
+ /** 预注册检索源列表 */
393
+ sources: z.array(RetrievalSourceSchema).optional()
394
+ });
395
+ var A2ASkillConfigSchema = z.object({
396
+ /** 技能 ID */
397
+ id: z.string(),
398
+ /** 技能名称 */
399
+ name: z.string(),
400
+ /** 技能描述 */
401
+ description: z.string().optional(),
402
+ /** 标签列表 */
403
+ tags: z.array(z.string()).optional()
404
+ });
405
+ var A2AConfigSchema = z.object({
406
+ /** Agent Card 配置 */
407
+ agentCard: z.object({
408
+ /** Agent 名称 */
409
+ name: z.string(),
410
+ /** Agent 描述 */
411
+ description: z.string().optional(),
412
+ /** Agent 对外 URL */
413
+ url: z.string(),
414
+ /** Agent 版本 */
415
+ version: z.string().optional(),
416
+ /** Agent 技能列表 */
417
+ skills: z.array(A2ASkillConfigSchema).optional()
418
+ }),
419
+ /** A2A 安全认证配置 */
420
+ security: z.object({
421
+ /** API Key 认证(通过 IAM apiKey.verifyApiKey 验证) */
422
+ apiKey: z.object({
423
+ /** API Key 的传递位置(默认 header) */
424
+ in: z.enum(["header", "query"]).default("header"),
425
+ /** 参数名(默认 x-api-key) */
426
+ name: z.string().default("x-api-key")
427
+ }).optional()
428
+ }).optional()
429
+ });
430
+ var AIConfigSchema = z.object({
431
+ /** LLM 配置(可选,所有字段有默认值) */
432
+ llm: LLMConfigSchema.default({
433
+ model: "gpt-4o-mini",
434
+ maxTokens: 4096,
435
+ temperature: 0.7,
436
+ timeout: 6e4
437
+ }),
438
+ /** MCP 配置 */
439
+ mcp: MCPConfigSchema.optional(),
440
+ /** Embedding 配置 */
441
+ embedding: EmbeddingConfigSchema.optional(),
442
+ /** Knowledge 配置 */
443
+ knowledge: KnowledgeConfigSchema.optional(),
444
+ /** Memory 配置 */
445
+ memory: MemoryConfigSchema.optional(),
446
+ /** Token 配置 */
447
+ token: TokenConfigSchema.optional(),
448
+ /** Summary 配置 */
449
+ summary: SummaryConfigSchema.optional(),
450
+ /** Compress 配置 */
451
+ compress: CompressConfigSchema.optional(),
452
+ /** Retrieval 配置(预注册检索源) */
453
+ retrieval: RetrievalConfigSchema.optional(),
454
+ /** File 解析配置 */
455
+ file: FileConfigSchema.optional(),
456
+ /** A2A 配置(Agent-to-Agent 协议) */
457
+ a2a: A2AConfigSchema.optional()
458
+ });
459
+
460
+ export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, HaiAIError, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, aiM, resolveModelEntry };
461
+ //# sourceMappingURL=chunk-6PPXWQ7I.js.map
462
+ //# sourceMappingURL=chunk-6PPXWQ7I.js.map