@h-ai/ai 0.1.0-alpha.33 → 0.1.0-alpha.34

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.md CHANGED
@@ -91,11 +91,22 @@ for await (const chunk of ai.llm.chatStream({ messages })) {
91
91
  }
92
92
  }
93
93
 
94
+ // 请求取消:传入 AbortSignal,主持人打断/用户切换时 abort() 立即停止上游生成与计费
95
+ const controller = new AbortController()
96
+ const cancellable = ai.llm.chat({ messages, signal: controller.signal })
97
+ // controller.abort()
98
+
99
+ // 多协议:模型的 api 决定底层走 Chat Completions / Responses / Anthropic,公共请求响应形状不变
100
+ // - chat(默认):OpenAI Chat Completions(兼容绝大多数厂商)
101
+ // - responses:OpenAI Responses API(/v1/responses)
102
+ // - anthropic:Anthropic Messages API(Claude 原生协议,环境变量 ANTHROPIC_API_KEY / ANTHROPIC_BASE_URL)
103
+ const claude = await ai.llm.chat({ messages, model: 'claude' }) // 该模型配置 api: anthropic
104
+
94
105
  // 临时模型:单次请求绕过配置注册模型,直接指定端点与凭据(chat/chatStream/ask/askStream 均支持)
95
106
  // 临时客户端按 TTL 缓存(llm.tempModelCacheTtl,默认 10 分钟),与常驻模型客户端隔离
96
107
  const temp = await ai.llm.chat({
97
108
  messages,
98
- tempModel: { model: 'claude-3-5-sonnet', apiKey: 'sk-temp', baseUrl: 'https://temp.endpoint/v1' },
109
+ tempModel: { model: 'claude-3-5-sonnet', api: 'anthropic', apiKey: 'sk-temp' },
99
110
  })
100
111
  ```
101
112
 
@@ -165,8 +176,13 @@ llm:
165
176
  apiKey: ${HAI_AI_LLM_API_KEY:}
166
177
  baseUrl: ${HAI_AI_LLM_BASE_URL:https://api.openai.com/v1}
167
178
  model: ${HAI_AI_LLM_MODEL:gpt-4o-mini}
179
+ api: chat # chat(默认)| responses | anthropic —— 底层 API 协议,对使用方透明
168
180
  timeout: 60000
169
181
  tempModelCacheTtl: 600000 # 临时模型客户端缓存 TTL(毫秒,默认 10 分钟)
182
+ models: # 可为每个模型单独指定协议
183
+ - {id: fast, model: gpt-4o-mini}
184
+ - {id: strong, model: gpt-4.1, api: responses}
185
+ - {id: claude, model: claude-3-5-sonnet-latest, api: anthropic}
170
186
  scenarios:
171
187
  chat: fast
172
188
  reasoning: strong
@@ -188,12 +204,28 @@ knowledge:
188
204
  overlap: 200
189
205
 
190
206
  memory:
191
- maxEntries: 1000
207
+ provider: native # native | mem0
208
+ maxEntriesPerObject: 1000 # 单主体(objectId)最大记忆条数
209
+ maxEntriesGlobal: 100000 # 跨所有主体的全局上限
192
210
  recencyDecay: 0.95
193
211
  embeddingEnabled: true
194
212
  defaultTopK: 10
213
+ writebackRelatedTopK: 20
214
+ ```
215
+
216
+ 启用 mem0(真·嵌入式 mem0ai/oss 引擎):
217
+
218
+ ```yaml
219
+ memory:
220
+ provider: mem0
221
+ defaultTopK: 10
195
222
  ```
196
223
 
224
+ - **`native`(默认,推荐)**:HAI 原生引擎,复用同一套 vecdb(向量库)、reldb(关系库)、LLM 与 Embedding。`extract` 采用 **Mem0 式批量合并**——一次 LLM 调用对整批抽取事实与相关既有记忆做 ADD / UPDATE / DELETE / NONE 决策,实现增量更新、跨条去重与矛盾删除,并支持 `category` 主题标签。`maxEntriesPerObject`、`maxEntriesGlobal`、`recencyDecay`、`embeddingEnabled`、`writebackRelatedTopK` 均作用于此后端;淘汰按 `objectId` 分区触发,不会因某一主体写入过多而淘汰其他主体的记忆。
225
+ - **`mem0`(真·mem0ai/oss)**:直接使用 `mem0ai/oss` 的 `Memory` 引擎(嵌入式,无云服务)。LLM / Embedder 从 `llm` 配置提取(OpenAI 兼容,走 `baseUrl` / `apiKey` / 场景模型);向量库从底层 vecdb 后端提取——`qdrant` / `pgvector` 直接复用同一后端,`lancedb` / `chroma`(mem0 TS 不支持)则退回 mem0 自带的 in-memory 存储。历史记录默认禁用。需安装 `mem0ai`(已内置为依赖);复用 qdrant/pgvector 时需对应客户端。
226
+
227
+ 两个 Provider 对外 `ai.memory.*` API 完全一致(`extract` / `recall` / `injectMemories` / `add` / `update` / `get` / `remove` / `list` / `listPage` / `clear`),均支持 `objectId`(主体隔离)与 `scope`(业务作用域 key-value 过滤,如 `{ topicId, personaId }`)。`recall` / `list` / `listPage` / `clear` 均按 `scope` 严格过滤,`clear` 在传入 `types` / `scope` 时仅删除同时匹配项(避免误删)。一个差异:mem0 后端在 `update` 涉及 type/importance/metadata 时会重建记忆并重新分配 `id`(native 后端保持 id 稳定)。
228
+
197
229
  `ai.config` 返回脱敏后的配置快照;`apiKey`、`privateKey`、URL 内嵌凭证等敏感字段不会原样暴露。
198
230
 
199
231
  ## 错误处理
@@ -379,6 +379,34 @@ interface KnowledgeStore {
379
379
  */
380
380
  deleteCollection: (collection: string) => Promise<void>;
381
381
  }
382
+ /**
383
+ * 向量库后端连接信息
384
+ *
385
+ * 由 Provider 暴露底层向量库的原始连接,供需要复用同一后端的外部引擎(如 mem0 OSS)
386
+ * 直连。字段按后端类型填充;包含凭证,仅供同进程内集成使用。
387
+ */
388
+ interface AIVectorBackend {
389
+ /** 后端类型(如 'qdrant'、'pgvector'、'lancedb'、'chroma') */
390
+ type: string;
391
+ /** 服务 URL(qdrant / chroma) */
392
+ url?: string;
393
+ /** API Key(qdrant / chroma) */
394
+ apiKey?: string;
395
+ /** 主机(pgvector) */
396
+ host?: string;
397
+ /** 端口(pgvector / chroma) */
398
+ port?: number;
399
+ /** 数据库名(pgvector) */
400
+ database?: string;
401
+ /** 用户名(pgvector) */
402
+ user?: string;
403
+ /** 密码(pgvector) */
404
+ password?: string;
405
+ /** 连接串(pgvector) */
406
+ connectionString?: string;
407
+ /** 本地路径(lancedb / chroma 嵌入式) */
408
+ path?: string;
409
+ }
382
410
  /**
383
411
  * AI 存储 Provider 接口
384
412
  *
@@ -401,6 +429,13 @@ interface AIStoreProvider {
401
429
  createRelStore: <T>(name: string, options?: AIRelStoreOptions) => AIRelStore<T>;
402
430
  /** 创建向量数据存储实例 */
403
431
  createVectorStore: (name: string) => AIVectorStore;
432
+ /**
433
+ * 暴露底层向量库后端连接(可选)
434
+ *
435
+ * 供需要直连同一向量库的外部引擎(如 mem0 OSS)复用后端。未初始化或不支持时返回
436
+ * `undefined`。返回值含凭证,仅供同进程内集成使用,禁止写入日志。
437
+ */
438
+ getVectorBackend?: () => AIVectorBackend | undefined;
404
439
  /**
405
440
  * 创建 knowledge 专用存储(可选)
406
441
  *
@@ -680,6 +715,8 @@ type ToolDefinition = OpenAI.Chat.Completions.ChatCompletionTool;
680
715
  interface TempModelConfig {
681
716
  /** 模型名称(传给 API 的实际模型名) */
682
717
  model: string;
718
+ /** API 协议(未指定时回退全局 `api`,再回退 `chat`;决定走 Chat Completions / Responses / Anthropic) */
719
+ api?: ApiType;
683
720
  /** API Key(未指定时回退全局配置 / 环境变量) */
684
721
  apiKey?: string;
685
722
  /** API 基础 URL(未指定时回退全局配置 / 环境变量 / 默认 OpenAI) */
@@ -711,6 +748,13 @@ type ChatCompletionRequest = Omit<OpenAI.Chat.ChatCompletionCreateParamsNonStrea
711
748
  enablePersist?: boolean;
712
749
  /** 临时模型配置(传入后绕过配置注册的模型,使用临时端点;优先级高于 `model`) */
713
750
  tempModel?: TempModelConfig;
751
+ /**
752
+ * 请求取消信号
753
+ *
754
+ * 传入后透传给底层 SDK(OpenAI / Anthropic)的请求取消参数。主持人打断、
755
+ * 用户切换等场景可 `abortController.abort()` 立即停止上游生成与计费。
756
+ */
757
+ signal?: AbortSignal;
714
758
  };
715
759
  /** Token 使用统计 */
716
760
  type TokenUsage = OpenAI.CompletionUsage;
@@ -880,6 +924,8 @@ interface AskOptions {
880
924
  enablePersist?: boolean;
881
925
  /** 临时模型配置(传入后绕过配置注册的模型,使用临时端点;优先级高于 `model`) */
882
926
  tempModel?: TempModelConfig;
927
+ /** 请求取消信号(透传给底层 SDK,支持主动打断上游生成) */
928
+ signal?: AbortSignal;
883
929
  }
884
930
  /**
885
931
  * 对话记录
@@ -1749,6 +1795,10 @@ interface MemoryInjectionOptions {
1749
1795
  objectId?: string;
1750
1796
  /** 限定作用域(key-value 匹配过滤,用于子 session 记忆隔离等场景) */
1751
1797
  scope?: Record<string, unknown>;
1798
+ /** 限定记忆类型 */
1799
+ types?: MemoryType[];
1800
+ /** 最低重要性阈值 */
1801
+ minImportance?: number;
1752
1802
  }
1753
1803
  /**
1754
1804
  * 记忆列表选项
@@ -1758,6 +1808,8 @@ interface MemoryListOptions {
1758
1808
  types?: MemoryType[];
1759
1809
  /** 限定主体 ID */
1760
1810
  objectId?: string;
1811
+ /** 限定作用域(key-value 匹配过滤,用于子 session / 主题 / 角色记忆隔离等场景) */
1812
+ scope?: Record<string, unknown>;
1761
1813
  /** 最大返回数 */
1762
1814
  limit?: number;
1763
1815
  }
@@ -1769,6 +1821,8 @@ interface MemoryListPageOptions {
1769
1821
  types?: MemoryType[];
1770
1822
  /** 限定主体 ID */
1771
1823
  objectId?: string;
1824
+ /** 限定作用域(key-value 匹配过滤,用于子 session / 主题 / 角色记忆隔离等场景) */
1825
+ scope?: Record<string, unknown>;
1772
1826
  /** 偏移量 */
1773
1827
  offset?: number;
1774
1828
  /** 每页数量(默认 20) */
@@ -1776,12 +1830,17 @@ interface MemoryListPageOptions {
1776
1830
  }
1777
1831
  /**
1778
1832
  * 记忆清空选项
1833
+ *
1834
+ * 安全语义:未传任何过滤条件时清空全部;传入 objectId / types / scope 时
1835
+ * 仅删除同时匹配所有给定条件的记忆,避免误删其他主体或类型的记忆。
1779
1836
  */
1780
1837
  interface MemoryClearOptions {
1781
1838
  /** 仅清空指定类型 */
1782
1839
  types?: MemoryType[];
1783
1840
  /** 仅清空指定主体 */
1784
1841
  objectId?: string;
1842
+ /** 仅清空匹配指定作用域的记忆(key-value 匹配过滤) */
1843
+ scope?: Record<string, unknown>;
1785
1844
  }
1786
1845
  /**
1787
1846
  * 记忆条目更新输入
@@ -1944,8 +2003,8 @@ interface MemoryOperations {
1944
2003
  * - `fast` — 快速响应场景(低延迟优先)
1945
2004
  */
1946
2005
  declare const ModelScenarioSchema: z.ZodEnum<{
1947
- default: "default";
1948
2006
  chat: "chat";
2007
+ default: "default";
1949
2008
  reasoning: "reasoning";
1950
2009
  plan: "plan";
1951
2010
  execute: "execute";
@@ -1958,6 +2017,22 @@ declare const ModelScenarioSchema: z.ZodEnum<{
1958
2017
  }>;
1959
2018
  /** 模型场景类型 */
1960
2019
  type ModelScenario = z.infer<typeof ModelScenarioSchema>;
2020
+ /**
2021
+ * LLM API 协议枚举
2022
+ *
2023
+ * 决定底层通过哪种 API 协议与模型交互(对使用方透明,公共请求/响应形状保持一致):
2024
+ *
2025
+ * - `chat` — OpenAI Chat Completions API(`/v1/chat/completions`,默认,兼容绝大多数厂商)
2026
+ * - `responses` — OpenAI Responses API(`/v1/responses`,新一代有状态接口)
2027
+ * - `anthropic` — Anthropic Messages API(Claude 原生协议,需安装 `@anthropic-ai/sdk`)
2028
+ */
2029
+ declare const ApiTypeSchema: z.ZodEnum<{
2030
+ chat: "chat";
2031
+ responses: "responses";
2032
+ anthropic: "anthropic";
2033
+ }>;
2034
+ /** LLM API 协议类型 */
2035
+ type ApiType = z.infer<typeof ApiTypeSchema>;
1961
2036
  /**
1962
2037
  * 模型条目 Schema
1963
2038
  *
@@ -1976,6 +2051,11 @@ type ModelScenario = z.infer<typeof ModelScenarioSchema>;
1976
2051
  declare const ModelEntrySchema: z.ZodObject<{
1977
2052
  id: z.ZodString;
1978
2053
  model: z.ZodString;
2054
+ api: z.ZodOptional<z.ZodEnum<{
2055
+ chat: "chat";
2056
+ responses: "responses";
2057
+ anthropic: "anthropic";
2058
+ }>>;
1979
2059
  apiKey: z.ZodOptional<z.ZodString>;
1980
2060
  baseUrl: z.ZodOptional<z.ZodURL>;
1981
2061
  maxTokens: z.ZodOptional<z.ZodNumber>;
@@ -2019,6 +2099,11 @@ declare const LLMConfigSchema: z.ZodObject<{
2019
2099
  apiKey: z.ZodOptional<z.ZodString>;
2020
2100
  baseUrl: z.ZodOptional<z.ZodURL>;
2021
2101
  model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
2102
+ api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
2103
+ chat: "chat";
2104
+ responses: "responses";
2105
+ anthropic: "anthropic";
2106
+ }>>>;
2022
2107
  maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
2023
2108
  temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
2024
2109
  timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
@@ -2026,6 +2111,11 @@ declare const LLMConfigSchema: z.ZodObject<{
2026
2111
  models: z.ZodOptional<z.ZodArray<z.ZodObject<{
2027
2112
  id: z.ZodString;
2028
2113
  model: z.ZodString;
2114
+ api: z.ZodOptional<z.ZodEnum<{
2115
+ chat: "chat";
2116
+ responses: "responses";
2117
+ anthropic: "anthropic";
2118
+ }>>;
2029
2119
  apiKey: z.ZodOptional<z.ZodString>;
2030
2120
  baseUrl: z.ZodOptional<z.ZodURL>;
2031
2121
  maxTokens: z.ZodOptional<z.ZodNumber>;
@@ -2033,8 +2123,8 @@ declare const LLMConfigSchema: z.ZodObject<{
2033
2123
  timeout: z.ZodOptional<z.ZodNumber>;
2034
2124
  }, z.core.$strip>>>;
2035
2125
  scenarios: z.ZodOptional<z.ZodObject<{
2036
- default: z.ZodOptional<z.ZodString>;
2037
2126
  chat: z.ZodOptional<z.ZodString>;
2127
+ default: z.ZodOptional<z.ZodString>;
2038
2128
  reasoning: z.ZodOptional<z.ZodString>;
2039
2129
  plan: z.ZodOptional<z.ZodString>;
2040
2130
  execute: z.ZodOptional<z.ZodString>;
@@ -2056,6 +2146,8 @@ type LLMConfig = z.infer<typeof LLMConfigSchema>;
2056
2146
  interface ResolvedModelConfig {
2057
2147
  /** 模型名称(传给 API 的实际模型名) */
2058
2148
  model: string;
2149
+ /** API 协议(模型条目 > 全局配置 > `chat`) */
2150
+ api: ApiType;
2059
2151
  /** API Key(模型条目 > 全局配置 > 环境变量) */
2060
2152
  apiKey: string | undefined;
2061
2153
  /** API 基础 URL(模型条目 > 全局配置 > 环境变量 > 默认 OpenAI) */
@@ -2087,6 +2179,18 @@ interface ResolveRequiredModelEntryOptions {
2087
2179
  * @returns 成功返回已解析模型配置,失败返回 `CONFIGURATION_ERROR`
2088
2180
  */
2089
2181
  declare function resolveModelEntry(llmConfig: LLMConfig, scenario: ModelScenario, explicit?: string, options?: ResolveRequiredModelEntryOptions): HaiResult<ResolvedModelConfig>;
2182
+ /**
2183
+ * 解析某次 chat 请求应使用的 API 协议(不校验 API Key)
2184
+ *
2185
+ * 供 LLM Provider 路由层选择底层实现使用:优先取显式模型条目的 `api`,
2186
+ * 其次全局 `api`,最后回退 `chat`。临时模型的 `api` 由调用方单独传入优先。
2187
+ *
2188
+ * @param llmConfig - LLM 配置
2189
+ * @param explicitModel - 显式指定的模型名/ID(可选)
2190
+ * @param tempApi - 临时模型显式指定的 API 协议(可选,最高优先级)
2191
+ * @returns 解析出的 API 协议
2192
+ */
2193
+ declare function resolveModelApi(llmConfig: LLMConfig, explicitModel?: string, tempApi?: ApiType): ApiType;
2090
2194
  /** MCP 服务器能力 Schema */
2091
2195
  declare const MCPServerCapabilitiesSchema: z.ZodObject<{
2092
2196
  tools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
@@ -2215,14 +2319,16 @@ type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
2215
2319
  /**
2216
2320
  * Memory 配置 Schema
2217
2321
  *
2218
- * 配置对话记忆的提取、存储与检索参数。
2219
- * 模型通过 LLMConfigSchema.scenarios.extraction 解析,
2220
- * apiKey / baseUrl 统一使用 LLM 配置。
2322
+ * 配置对话记忆的提取、存储与检索参数。两种 provider 均为嵌入式,复用同一套
2323
+ * vecdb / reldb / LLM / Embedding;模型通过 LLMConfigSchema.scenarios.extraction
2324
+ * 解析,apiKey / baseUrl 统一使用 LLM 配置。
2221
2325
  *
2222
2326
  * @example
2223
2327
  * ```ts
2224
2328
  * const memoryConfig = {
2225
- * maxEntries: 1000,
2329
+ * provider: 'native',
2330
+ * maxEntriesPerObject: 1000,
2331
+ * maxEntriesGlobal: 100000,
2226
2332
  * embeddingEnabled: true,
2227
2333
  * recencyDecay: 0.95,
2228
2334
  * defaultTopK: 10,
@@ -2230,7 +2336,12 @@ type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
2230
2336
  * ```
2231
2337
  */
2232
2338
  declare const MemoryConfigSchema: z.ZodObject<{
2233
- maxEntries: z.ZodDefault<z.ZodNumber>;
2339
+ provider: z.ZodDefault<z.ZodEnum<{
2340
+ native: "native";
2341
+ mem0: "mem0";
2342
+ }>>;
2343
+ maxEntriesPerObject: z.ZodDefault<z.ZodNumber>;
2344
+ maxEntriesGlobal: z.ZodDefault<z.ZodNumber>;
2234
2345
  systemPrompt: z.ZodOptional<z.ZodString>;
2235
2346
  recencyDecay: z.ZodDefault<z.ZodNumber>;
2236
2347
  embeddingEnabled: z.ZodDefault<z.ZodBoolean>;
@@ -2443,7 +2554,7 @@ type A2AConfig = z.infer<typeof A2AConfigSchema>;
2443
2554
  * { id: 'docs', collection: 'documentation', name: '产品文档', topK: 5, minScore: 0.7 },
2444
2555
  * ],
2445
2556
  * },
2446
- * memory: { maxEntries: 500, embeddingEnabled: true },
2557
+ * memory: { maxEntriesPerObject: 500, embeddingEnabled: true },
2447
2558
  * token: { tokenRatio: 0.25 },
2448
2559
  * summary: { systemPrompt: 'You are a summarizer.' },
2449
2560
  * compress: { defaultStrategy: 'hybrid', preserveLastN: 4 },
@@ -2455,6 +2566,11 @@ declare const AIConfigSchema: z.ZodObject<{
2455
2566
  apiKey: z.ZodOptional<z.ZodString>;
2456
2567
  baseUrl: z.ZodOptional<z.ZodURL>;
2457
2568
  model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
2569
+ api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
2570
+ chat: "chat";
2571
+ responses: "responses";
2572
+ anthropic: "anthropic";
2573
+ }>>>;
2458
2574
  maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
2459
2575
  temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
2460
2576
  timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
@@ -2462,6 +2578,11 @@ declare const AIConfigSchema: z.ZodObject<{
2462
2578
  models: z.ZodOptional<z.ZodArray<z.ZodObject<{
2463
2579
  id: z.ZodString;
2464
2580
  model: z.ZodString;
2581
+ api: z.ZodOptional<z.ZodEnum<{
2582
+ chat: "chat";
2583
+ responses: "responses";
2584
+ anthropic: "anthropic";
2585
+ }>>;
2465
2586
  apiKey: z.ZodOptional<z.ZodString>;
2466
2587
  baseUrl: z.ZodOptional<z.ZodURL>;
2467
2588
  maxTokens: z.ZodOptional<z.ZodNumber>;
@@ -2469,8 +2590,8 @@ declare const AIConfigSchema: z.ZodObject<{
2469
2590
  timeout: z.ZodOptional<z.ZodNumber>;
2470
2591
  }, z.core.$strip>>>;
2471
2592
  scenarios: z.ZodOptional<z.ZodObject<{
2472
- default: z.ZodOptional<z.ZodString>;
2473
2593
  chat: z.ZodOptional<z.ZodString>;
2594
+ default: z.ZodOptional<z.ZodString>;
2474
2595
  reasoning: z.ZodOptional<z.ZodString>;
2475
2596
  plan: z.ZodOptional<z.ZodString>;
2476
2597
  execute: z.ZodOptional<z.ZodString>;
@@ -2533,7 +2654,12 @@ declare const AIConfigSchema: z.ZodObject<{
2533
2654
  systemPrompt: z.ZodOptional<z.ZodString>;
2534
2655
  }, z.core.$strip>>;
2535
2656
  memory: z.ZodOptional<z.ZodObject<{
2536
- maxEntries: z.ZodDefault<z.ZodNumber>;
2657
+ provider: z.ZodDefault<z.ZodEnum<{
2658
+ native: "native";
2659
+ mem0: "mem0";
2660
+ }>>;
2661
+ maxEntriesPerObject: z.ZodDefault<z.ZodNumber>;
2662
+ maxEntriesGlobal: z.ZodDefault<z.ZodNumber>;
2537
2663
  systemPrompt: z.ZodOptional<z.ZodString>;
2538
2664
  recencyDecay: z.ZodDefault<z.ZodNumber>;
2539
2665
  embeddingEnabled: z.ZodDefault<z.ZodBoolean>;
@@ -2887,4 +3013,4 @@ interface ReasoningOperations {
2887
3013
  runStream: (query: string, options?: ReasoningOptions) => AsyncIterable<ReasoningStreamEvent>;
2888
3014
  }
2889
3015
 
2890
- export { type A2AOperations as $, type A2AConfig as A, type RetrievalConfig as B, type CompressConfig as C, RetrievalConfigSchema as D, type EmbeddingConfig as E, type FileConfig as F, type RetrievalSourceConfig as G, RetrievalSourceSchema as H, SummaryConfigSchema as I, TokenConfigSchema as J, type KnowledgeConfig as K, type LLMConfig as L, type MCPConfig as M, resolveModelEntry as N, type A2AAgentCardConfig as O, type A2AApiKeySecurity as P, type A2AAuthenticator as Q, type ResolveRequiredModelEntryOptions as R, type SummaryConfig as S, type TokenConfig as T, type A2ACallOptions as U, type A2ACallResult as V, type A2ACallerIdentity as W, type A2AClientCallRecord as X, type A2AContextInfo as Y, type A2AHandleResult as Z, type A2AMessageRecord as _, A2AConfigSchema as a, type ReasoningOperations as a$, type A2ASecurityConfig as a0, type A2ATaskFilter as a1, type AILLMFunctionsDeps as a2, type AIRelStore as a3, type AIRelStoreOptions as a4, type AIStoreProvider as a5, type AIVectorStore as a6, type AskOptions as a7, type AssistantMessage as a8, type ChatCompletionChoice as a9, type KnowledgeIngestResult as aA, type KnowledgeOperations as aB, type KnowledgeRetrieveItem as aC, type KnowledgeRetrieveOptions as aD, type KnowledgeRetrieveResult as aE, type KnowledgeSetupOptions as aF, type KnowledgeStore as aG, type LLMOperations as aH, type LLMProvider as aI, type MemoryClearOptions as aJ, type MemoryEntry as aK, type MemoryEntryInput as aL, type MemoryExtractOptions as aM, type MemoryInjectionOptions as aN, type MemoryListOptions as aO, type MemoryListPageOptions as aP, type MemoryOperations as aQ, type MemoryRecallOptions as aR, type MemoryUpdateInput as aS, type MessageContent as aT, type MessageRole as aU, type ObjectRef as aV, type RagContextItem as aW, type RagOperations as aX, type RagOptions as aY, type RagResult as aZ, type RagStreamEvent as a_, type ChatCompletionChunk as aa, type ChatCompletionDelta as ab, type ChatCompletionRequest as ac, type ChatCompletionResponse as ad, type ChatHistoryOptions as ae, type ChatMessage as af, type ChatRecord as ag, type Citation as ah, type DefineToolOptions as ai, type DeveloperMessage as aj, type EntityDocumentRelation as ak, type EntityDocumentResult as al, type EntityListOptions as am, type EntityQueryOptions as an, type ImageContent as ao, type InteractionScope as ap, type KnowledgeAskOptions as aq, type KnowledgeAskResult as ar, type KnowledgeDocumentInfo as as, type KnowledgeDocumentListOptions as at, type KnowledgeDocumentRemoveOptions as au, type KnowledgeEntity as av, type KnowledgeIngestBatchProgress as aw, type KnowledgeIngestBatchResult as ax, type KnowledgeIngestFileInput as ay, type KnowledgeIngestInput as az, A2ASkillConfigSchema as b, type ReasoningOptions as b0, type ReasoningResult as b1, type ReasoningStep as b2, type ReasoningStepType as b3, type ReasoningStrategy as b4, type ReasoningStreamEvent as b5, type RetrievalOperations as b6, type RetrievalRequest as b7, type RetrievalResult as b8, type RetrievalResultItem as b9, type RetrievalSource as ba, type SSEDecoder as bb, type SSEEvent as bc, type SessionInfo as bd, type StoreFilter as be, type StorePage as bf, type StoreScope as bg, type StreamOperations as bh, type StreamProcessor as bi, type StreamResult as bj, type SystemMessage as bk, type TempModelConfig as bl, type TextContent as bm, type TokenUsage as bn, type Tool as bo, type ToolCall as bp, type ToolDefinition as bq, type ToolErrorType as br, type ToolMessage as bs, type ToolRegistryOperations as bt, type ToolsOperations as bu, type UserMessage as bv, type WhereClause as bw, type WhereOperator as bx, type WhereValue as by, type AIConfig as c, type AIConfigInput as d, AIConfigSchema as e, CompressConfigSchema as f, EmbeddingConfigSchema as g, type EntityType as h, EntityTypeSchema as i, FileConfigSchema as j, KnowledgeConfigSchema as k, LLMConfigSchema as l, MCPConfigSchema as m, type MCPServerCapabilities as n, MCPServerCapabilitiesSchema as o, type MCPServerConfig as p, MCPServerConfigSchema as q, type MemoryConfig as r, MemoryConfigSchema as s, type MemoryType as t, MemoryTypeSchema as u, type ModelEntry as v, ModelEntrySchema as w, type ModelScenario as x, ModelScenarioSchema as y, type ResolvedModelConfig as z };
3016
+ export { type A2AContextInfo as $, type A2AConfig as A, ModelScenarioSchema as B, type CompressConfig as C, type ResolvedModelConfig as D, type EmbeddingConfig as E, type FileConfig as F, type RetrievalConfig as G, RetrievalConfigSchema as H, type RetrievalSourceConfig as I, RetrievalSourceSchema as J, type KnowledgeConfig as K, type LLMConfig as L, type MCPConfig as M, SummaryConfigSchema as N, TokenConfigSchema as O, resolveModelApi as P, resolveModelEntry as Q, type ResolveRequiredModelEntryOptions as R, type SummaryConfig as S, type TokenConfig as T, type A2AAgentCardConfig as U, type A2AApiKeySecurity as V, type A2AAuthenticator as W, type A2ACallOptions as X, type A2ACallResult as Y, type A2ACallerIdentity as Z, type A2AClientCallRecord as _, A2AConfigSchema as a, type RagOperations as a$, type A2AHandleResult as a0, type A2AMessageRecord as a1, type A2AOperations as a2, type A2ASecurityConfig as a3, type A2ATaskFilter as a4, type AILLMFunctionsDeps as a5, type AIRelStore as a6, type AIRelStoreOptions as a7, type AIStoreProvider as a8, type AIVectorBackend as a9, type KnowledgeIngestBatchProgress as aA, type KnowledgeIngestBatchResult as aB, type KnowledgeIngestFileInput as aC, type KnowledgeIngestInput as aD, type KnowledgeIngestResult as aE, type KnowledgeOperations as aF, type KnowledgeRetrieveItem as aG, type KnowledgeRetrieveOptions as aH, type KnowledgeRetrieveResult as aI, type KnowledgeSetupOptions as aJ, type KnowledgeStore as aK, type LLMOperations as aL, type LLMProvider as aM, type MemoryClearOptions as aN, type MemoryEntry as aO, type MemoryEntryInput as aP, type MemoryExtractOptions as aQ, type MemoryInjectionOptions as aR, type MemoryListOptions as aS, type MemoryListPageOptions as aT, type MemoryOperations as aU, type MemoryRecallOptions as aV, type MemoryUpdateInput as aW, type MessageContent as aX, type MessageRole as aY, type ObjectRef as aZ, type RagContextItem as a_, type AIVectorStore as aa, type AskOptions as ab, type AssistantMessage as ac, type ChatCompletionChoice as ad, type ChatCompletionChunk as ae, type ChatCompletionDelta as af, type ChatCompletionRequest as ag, type ChatCompletionResponse as ah, type ChatHistoryOptions as ai, type ChatMessage as aj, type ChatRecord as ak, type Citation as al, type DefineToolOptions as am, type DeveloperMessage as an, type EntityDocumentRelation as ao, type EntityDocumentResult as ap, type EntityListOptions as aq, type EntityQueryOptions as ar, type ImageContent as as, type InteractionScope as at, type KnowledgeAskOptions as au, type KnowledgeAskResult as av, type KnowledgeDocumentInfo as aw, type KnowledgeDocumentListOptions as ax, type KnowledgeDocumentRemoveOptions as ay, type KnowledgeEntity as az, A2ASkillConfigSchema as b, type RagOptions as b0, type RagResult as b1, type RagStreamEvent as b2, type ReasoningOperations as b3, type ReasoningOptions as b4, type ReasoningResult as b5, type ReasoningStep as b6, type ReasoningStepType as b7, type ReasoningStrategy as b8, type ReasoningStreamEvent as b9, type WhereClause as bA, type WhereOperator as bB, type WhereValue as bC, type RetrievalOperations as ba, type RetrievalRequest as bb, type RetrievalResult as bc, type RetrievalResultItem as bd, type RetrievalSource as be, type SSEDecoder as bf, type SSEEvent as bg, type SessionInfo as bh, type StoreFilter as bi, type StorePage as bj, type StoreScope as bk, type StreamOperations as bl, type StreamProcessor as bm, type StreamResult as bn, type SystemMessage as bo, type TempModelConfig as bp, type TextContent as bq, type TokenUsage as br, type Tool as bs, type ToolCall as bt, type ToolDefinition as bu, type ToolErrorType as bv, type ToolMessage as bw, type ToolRegistryOperations as bx, type ToolsOperations as by, type UserMessage as bz, type AIConfig as c, type AIConfigInput as d, AIConfigSchema as e, type ApiType as f, ApiTypeSchema as g, CompressConfigSchema as h, EmbeddingConfigSchema as i, type EntityType as j, EntityTypeSchema as k, FileConfigSchema as l, KnowledgeConfigSchema as m, LLMConfigSchema as n, MCPConfigSchema as o, type MCPServerCapabilities as p, MCPServerCapabilitiesSchema as q, type MCPServerConfig as r, MCPServerConfigSchema as s, type MemoryConfig as t, MemoryConfigSchema as u, type MemoryType as v, MemoryTypeSchema as w, type ModelEntry as x, ModelEntrySchema as y, type ModelScenario as z };
@@ -1,6 +1,6 @@
1
1
  import * as _h_ai_core from '@h-ai/core';
2
2
  import { HaiResult } from '@h-ai/core';
3
- import { af as ChatMessage, ap as InteractionScope, aN as MemoryInjectionOptions, aY as RagOptions, b0 as ReasoningOptions, bt as ToolRegistryOperations, bd as SessionInfo, aH as LLMOperations, aQ as MemoryOperations, aX as RagOperations, a$ as ReasoningOperations, c as AIConfig, d as AIConfigInput, a5 as AIStoreProvider, bu as ToolsOperations, bh as StreamOperations, b6 as RetrievalOperations, aB as KnowledgeOperations, $ as A2AOperations } from './ai-reasoning-types-DhlmaxTq.js';
3
+ import { aj as ChatMessage, at as InteractionScope, v as MemoryType, b0 as RagOptions, b4 as ReasoningOptions, bx as ToolRegistryOperations, bh as SessionInfo, aL as LLMOperations, aU as MemoryOperations, a$ as RagOperations, b3 as ReasoningOperations, c as AIConfig, d as AIConfigInput, a8 as AIStoreProvider, by as ToolsOperations, bl as StreamOperations, ba as RetrievalOperations, aF as KnowledgeOperations, a2 as A2AOperations } from './ai-reasoning-types-Cm3-HVVN.js';
4
4
  import { z } from 'zod';
5
5
  import { Buffer } from 'node:buffer';
6
6
 
@@ -204,13 +204,31 @@ interface ContextManagerOptions {
204
204
  /**
205
205
  * 记忆配置
206
206
  *
207
- * 引用 MemoryInjectionOptions 的检索控制字段,加上 enable/enableExtract 开关。
207
+ * 控制记忆注入与提取。`scope` / `types` / `minImportance` 会完整透传给 Memory 的
208
+ * `injectMemories` 与 `extract`,用于表达「用户 + 主题 + 角色」等多维隔离
209
+ * (如 `{ userId, topicId, personaId }`)。
208
210
  */
209
- memory?: Pick<MemoryInjectionOptions, 'topK' | 'maxTokens' | 'position'> & {
211
+ memory?: {
210
212
  /** 是否启用记忆注入(默认 false) */
211
213
  enable?: boolean;
212
214
  /** 是否启用自动记忆提取(默认 false) */
213
215
  enableExtract?: boolean;
216
+ /** 业务作用域(透传给 injectMemories / extract,key-value 匹配隔离) */
217
+ scope?: Record<string, unknown>;
218
+ /** 注入 / 提取时限定的记忆类型 */
219
+ types?: MemoryType[];
220
+ /** 注入时的最低重要性阈值 */
221
+ minImportance?: number;
222
+ /** 注入的记忆数量 */
223
+ topK?: number;
224
+ /** 注入记忆占用的最大 token 预算 */
225
+ maxTokens?: number;
226
+ /** 注入位置:system 追加或最后一条用户消息前插入 */
227
+ position?: 'system' | 'before-last';
228
+ /** 记忆提取使用的模型(覆盖默认提取模型) */
229
+ extractionModel?: string;
230
+ /** 记忆提取的自定义 systemPrompt */
231
+ extractionSystemPrompt?: string;
214
232
  };
215
233
  /**
216
234
  * RAG 配置
@@ -250,6 +268,13 @@ interface ContextChatOptions {
250
268
  temperature?: number;
251
269
  /** 是否启用本次 LLM 调用的持久化(默认 false,Context 自行管理状态) */
252
270
  enablePersist?: boolean;
271
+ /**
272
+ * 请求取消信号
273
+ *
274
+ * 透传给底层 LLM 调用;主持人打断、用户切换等场景可 `abortController.abort()`
275
+ * 立即停止上游生成与计费。
276
+ */
277
+ signal?: AbortSignal;
253
278
  }
254
279
  /**
255
280
  * chat() 返回的结果
@@ -356,8 +381,25 @@ interface ContextManager {
356
381
  getSummaries: () => HaiResult<SummaryResult[]>;
357
382
  /**
358
383
  * 持久化当前状态(需要 scope + 存储可用)
384
+ *
385
+ * 内部会先 `flush()` 等待所有后台记忆提取完成,确保持久化时记忆已写入。
359
386
  */
360
387
  save: () => Promise<HaiResult<void>>;
388
+ /**
389
+ * 等待所有后台记忆提取任务完成
390
+ *
391
+ * chat/chatStream 的自动记忆提取是「即发即忘」的后台任务;在开始下一轮召回、
392
+ * 生成总结或关闭前调用 `flush()`,可避免「上一轮记忆尚未写完」的时序问题(issue #14)。
393
+ *
394
+ * @returns 全部任务完成返回 ok(undefined)
395
+ */
396
+ flush: () => Promise<HaiResult<void>>;
397
+ /**
398
+ * 当前挂起的后台记忆提取任务数量
399
+ *
400
+ * 供应用侧观测;为 0 表示无待写入的记忆任务。
401
+ */
402
+ readonly pendingMemoryTasks: number;
361
403
  /**
362
404
  * 重置管理器(清空所有消息和摘要)
363
405
  */
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { A as A2AConfig, a as A2AConfigSchema, b as A2ASkillConfigSchema, c as AIConfig, d as AIConfigInput, e as AIConfigSchema, C as CompressConfig, f as CompressConfigSchema, E as EmbeddingConfig, g as EmbeddingConfigSchema, h as EntityType, i as EntityTypeSchema, F as FileConfig, j as FileConfigSchema, K as KnowledgeConfig, k as KnowledgeConfigSchema, L as LLMConfig, l as LLMConfigSchema, M as MCPConfig, m as MCPConfigSchema, n as MCPServerCapabilities, o as MCPServerCapabilitiesSchema, p as MCPServerConfig, q as MCPServerConfigSchema, r as MemoryConfig, s as MemoryConfigSchema, t as MemoryType, u as MemoryTypeSchema, v as ModelEntry, w as ModelEntrySchema, x as ModelScenario, y as ModelScenarioSchema, R as ResolveRequiredModelEntryOptions, z as ResolvedModelConfig, B as RetrievalConfig, D as RetrievalConfigSchema, G as RetrievalSourceConfig, H as RetrievalSourceSchema, S as SummaryConfig, I as SummaryConfigSchema, T as TokenConfig, J as TokenConfigSchema, N as resolveModelEntry } from './ai-reasoning-types-DhlmaxTq.js';
2
- export { A as AIFunctions, a as AIInitOptions, C as CompressionStrategy, b as CompressionStrategySchema, H as HaiAIError } from './ai-types-gdhSgQGc.js';
1
+ export { A as A2AConfig, a as A2AConfigSchema, b as A2ASkillConfigSchema, c as AIConfig, d as AIConfigInput, e as AIConfigSchema, f as ApiType, g as ApiTypeSchema, C as CompressConfig, h as CompressConfigSchema, E as EmbeddingConfig, i as EmbeddingConfigSchema, j as EntityType, k as EntityTypeSchema, F as FileConfig, l as FileConfigSchema, K as KnowledgeConfig, m as KnowledgeConfigSchema, L as LLMConfig, n as LLMConfigSchema, M as MCPConfig, o as MCPConfigSchema, p as MCPServerCapabilities, q as MCPServerCapabilitiesSchema, r as MCPServerConfig, s as MCPServerConfigSchema, t as MemoryConfig, u as MemoryConfigSchema, v as MemoryType, w as MemoryTypeSchema, x as ModelEntry, y as ModelEntrySchema, z as ModelScenario, B as ModelScenarioSchema, R as ResolveRequiredModelEntryOptions, D as ResolvedModelConfig, G as RetrievalConfig, H as RetrievalConfigSchema, I as RetrievalSourceConfig, J as RetrievalSourceSchema, S as SummaryConfig, N as SummaryConfigSchema, T as TokenConfig, O as TokenConfigSchema, P as resolveModelApi, Q as resolveModelEntry } from './ai-reasoning-types-Cm3-HVVN.js';
2
+ export { A as AIFunctions, a as AIInitOptions, C as CompressionStrategy, b as CompressionStrategySchema, H as HaiAIError } from './ai-types-BZjo_rWW.js';
3
3
  export { A2AClientOperations, AIApiAdapter, AIClient, AIClientConfig, StreamOptions, StreamProgress, collectStreamContent, createA2AClient, createAIClient, parseSSE } from './client/index.js';
4
4
  import '@a2a-js/sdk/server';
5
5
  import '@h-ai/core';
package/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, HaiAIError, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, resolveModelEntry } from './chunk-YTGCR77F.js';
1
+ export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, ApiTypeSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, HaiAIError, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, resolveModelApi, resolveModelEntry } from './chunk-CXO3YSIG.js';
2
2
  export { collectStreamContent, createA2AClient, createAIClient, parseSSE } from './chunk-Y5BQR7QA.js';
3
3
  //# sourceMappingURL=browser.js.map
4
4
  //# sourceMappingURL=browser.js.map
@@ -220,11 +220,14 @@ var aiM = core.i18n.createMessageGetter({
220
220
 
221
221
  // src/ai-config.ts
222
222
  var ModelScenarioSchema = z.enum(["default", "chat", "reasoning", "plan", "execute", "extraction", "summary", "embedding", "rerank", "ocr", "fast"]);
223
+ var ApiTypeSchema = z.enum(["chat", "responses", "anthropic"]);
223
224
  var ModelEntrySchema = z.object({
224
225
  /** 模型唯一标识(用于 ModelResolver 解析) */
225
226
  id: z.string(),
226
227
  /** 模型名称(传给 API 的实际模型名) */
227
228
  model: z.string(),
229
+ /** API 协议(可选,未指定时回退全局 `api`,再回退 `chat`;决定走 Chat Completions / Responses / Anthropic) */
230
+ api: ApiTypeSchema.optional(),
228
231
  /** API Key 覆盖(可选,未提供时使用全局配置) */
229
232
  apiKey: z.string().optional(),
230
233
  /** Base URL 覆盖(可选) */
@@ -243,6 +246,8 @@ var LLMConfigSchema = z.object({
243
246
  baseUrl: z.url().optional(),
244
247
  /** 默认模型名称(默认 `'gpt-4o-mini'`) */
245
248
  model: z.string().optional().default("gpt-4o-mini"),
249
+ /** 全局 API 协议(各模型 fallback,默认 `'chat'`;可选 `chat` / `responses` / `anthropic`) */
250
+ api: ApiTypeSchema.optional().default("chat"),
246
251
  /** 全局最大 Token 数(各模型 fallback,默认 `4096`) */
247
252
  maxTokens: z.number().positive().optional().default(4096),
248
253
  /** 全局采样温度(各模型 fallback,范围 `[0, 2]`,默认 `0.7`) */
@@ -273,6 +278,7 @@ function resolveModelEntry(llmConfig, scenario, explicit, options) {
273
278
  }
274
279
  const resolved = {
275
280
  model: modelName,
281
+ api: entry?.api ?? llmConfig.api ?? "chat",
276
282
  apiKey: entry?.apiKey ?? llmConfig.apiKey ?? process.env.HAI_AI_LLM_API_KEY ?? process.env.OPENAI_API_KEY,
277
283
  baseUrl: entry?.baseUrl ?? llmConfig.baseUrl ?? process.env.HAI_AI_LLM_BASE_URL ?? process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1",
278
284
  maxTokens: entry?.maxTokens ?? llmConfig.maxTokens ?? 4096,
@@ -284,6 +290,12 @@ function resolveModelEntry(llmConfig, scenario, explicit, options) {
284
290
  }
285
291
  return ok(resolved);
286
292
  }
293
+ function resolveModelApi(llmConfig, explicitModel, tempApi) {
294
+ if (tempApi)
295
+ return tempApi;
296
+ const entry = explicitModel ? llmConfig.models?.find((m) => m.id === explicitModel || m.model === explicitModel) : void 0;
297
+ return entry?.api ?? llmConfig.api ?? "chat";
298
+ }
287
299
  var MCPServerCapabilitiesSchema = z.object({
288
300
  /** 是否支持工具调用(默认 `true`) */
289
301
  tools: z.boolean().optional().default(true),
@@ -343,8 +355,21 @@ var KnowledgeConfigSchema = z.object({
343
355
  systemPrompt: z.string().optional()
344
356
  });
345
357
  var MemoryConfigSchema = z.object({
346
- /** 最大记忆条数(默认 1000) */
347
- maxEntries: z.number().int().positive().default(1e3),
358
+ /** 记忆后端:native = 逐条写回;mem0 = 批量 ADD/UPDATE/DELETE 合并(均为嵌入式,复用 HAI 组件) */
359
+ provider: z.enum(["native", "mem0"]).default("native"),
360
+ /**
361
+ * 单个主体(objectId)的最大记忆条数(默认 1000)
362
+ *
363
+ * native 淘汰按 objectId 分区触发:某个主体写入超过此上限时,只淘汰该主体自身
364
+ * 最低优先级的条目,不会波及其他主体的记忆。
365
+ */
366
+ maxEntriesPerObject: z.number().int().positive().default(1e3),
367
+ /**
368
+ * 全局最大记忆条数(默认 100000)
369
+ *
370
+ * 跨所有主体的总量上限,作为整体保护阈值;超过时淘汰全局最低优先级条目。
371
+ */
372
+ maxEntriesGlobal: z.number().int().positive().default(1e5),
348
373
  /** 自定义记忆提取 systemPrompt(可选,覆盖内置默认提示词) */
349
374
  systemPrompt: z.string().optional(),
350
375
  /** 时间衰减系数(默认 0.95,每次检索乘以此系数调整 recency 权重) */
@@ -353,6 +378,7 @@ var MemoryConfigSchema = z.object({
353
378
  embeddingEnabled: z.boolean().default(true),
354
379
  /** 检索时默认返回数量(默认 10) */
355
380
  defaultTopK: z.number().int().positive().default(10),
381
+ /** 写回 / 合并时检索相关记忆的数量(native 与 mem0 共用,默认 20) */
356
382
  writebackRelatedTopK: z.number().int().positive().default(20)
357
383
  });
358
384
  var TokenConfigSchema = z.object({
@@ -434,6 +460,7 @@ var AIConfigSchema = z.object({
434
460
  /** LLM 配置(可选,所有字段有默认值) */
435
461
  llm: LLMConfigSchema.default({
436
462
  model: "gpt-4o-mini",
463
+ api: "chat",
437
464
  maxTokens: 4096,
438
465
  temperature: 0.7,
439
466
  timeout: 6e4,
@@ -461,6 +488,6 @@ var AIConfigSchema = z.object({
461
488
  a2a: A2AConfigSchema.optional()
462
489
  });
463
490
 
464
- 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 };
465
- //# sourceMappingURL=chunk-YTGCR77F.js.map
466
- //# sourceMappingURL=chunk-YTGCR77F.js.map
491
+ export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, ApiTypeSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, HaiAIError, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, aiM, resolveModelApi, resolveModelEntry };
492
+ //# sourceMappingURL=chunk-CXO3YSIG.js.map
493
+ //# sourceMappingURL=chunk-CXO3YSIG.js.map