@h-ai/ai 0.1.0-alpha.32 → 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 +34 -2
- package/dist/{ai-reasoning-types-Dtsg32tx.d.ts → ai-reasoning-types-Cm3-HVVN.d.ts} +147 -11
- package/dist/{ai-types-D3cT4zTc.d.ts → ai-types-BZjo_rWW.d.ts} +45 -3
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-TPHVO2QP.js → chunk-CXO3YSIG.js} +32 -5
- package/dist/chunk-CXO3YSIG.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1318 -461
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/dist/chunk-TPHVO2QP.js.map +0 -1
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',
|
|
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
|
-
|
|
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
|
* 对话记录
|
|
@@ -1660,6 +1706,8 @@ interface MemoryEntryInput {
|
|
|
1660
1706
|
importance?: number;
|
|
1661
1707
|
/** 所属主体 ID(不指定时为全局记忆) */
|
|
1662
1708
|
objectId?: string;
|
|
1709
|
+
/** 作用域(JSON 对象,key-value 匹配过滤。用于子 session 记忆隔离等场景) */
|
|
1710
|
+
scope?: Record<string, unknown>;
|
|
1663
1711
|
/** 附加元数据 */
|
|
1664
1712
|
metadata?: Record<string, unknown>;
|
|
1665
1713
|
}
|
|
@@ -1677,6 +1725,8 @@ interface MemoryEntry {
|
|
|
1677
1725
|
importance: number;
|
|
1678
1726
|
/** 所属主体 ID */
|
|
1679
1727
|
objectId?: string;
|
|
1728
|
+
/** 作用域(JSON 对象,key-value 匹配过滤。用于子 session 记忆隔离等场景) */
|
|
1729
|
+
scope?: Record<string, unknown>;
|
|
1680
1730
|
/** 附加元数据 */
|
|
1681
1731
|
metadata?: Record<string, unknown>;
|
|
1682
1732
|
/** 向量(embedding 已计算时填充) */
|
|
@@ -1702,6 +1752,8 @@ interface MemoryExtractOptions {
|
|
|
1702
1752
|
minImportance?: number;
|
|
1703
1753
|
/** 所属主体 ID(关联到提取结果) */
|
|
1704
1754
|
objectId?: string;
|
|
1755
|
+
/** 作用域(JSON 对象,提取的记忆将关联此 scope) */
|
|
1756
|
+
scope?: Record<string, unknown>;
|
|
1705
1757
|
/**
|
|
1706
1758
|
* 临时模型配置(携带凭据的模型请求)。
|
|
1707
1759
|
*
|
|
@@ -1724,6 +1776,8 @@ interface MemoryRecallOptions {
|
|
|
1724
1776
|
recencyWeight?: number;
|
|
1725
1777
|
/** 限定主体 ID */
|
|
1726
1778
|
objectId?: string;
|
|
1779
|
+
/** 限定作用域(key-value 匹配过滤,用于子 session 记忆隔离等场景) */
|
|
1780
|
+
scope?: Record<string, unknown>;
|
|
1727
1781
|
}
|
|
1728
1782
|
/**
|
|
1729
1783
|
* 记忆注入选项(`injectMemories` 使用)
|
|
@@ -1739,6 +1793,12 @@ interface MemoryInjectionOptions {
|
|
|
1739
1793
|
position?: 'system' | 'before-last';
|
|
1740
1794
|
/** 限定主体 ID */
|
|
1741
1795
|
objectId?: string;
|
|
1796
|
+
/** 限定作用域(key-value 匹配过滤,用于子 session 记忆隔离等场景) */
|
|
1797
|
+
scope?: Record<string, unknown>;
|
|
1798
|
+
/** 限定记忆类型 */
|
|
1799
|
+
types?: MemoryType[];
|
|
1800
|
+
/** 最低重要性阈值 */
|
|
1801
|
+
minImportance?: number;
|
|
1742
1802
|
}
|
|
1743
1803
|
/**
|
|
1744
1804
|
* 记忆列表选项
|
|
@@ -1748,6 +1808,8 @@ interface MemoryListOptions {
|
|
|
1748
1808
|
types?: MemoryType[];
|
|
1749
1809
|
/** 限定主体 ID */
|
|
1750
1810
|
objectId?: string;
|
|
1811
|
+
/** 限定作用域(key-value 匹配过滤,用于子 session / 主题 / 角色记忆隔离等场景) */
|
|
1812
|
+
scope?: Record<string, unknown>;
|
|
1751
1813
|
/** 最大返回数 */
|
|
1752
1814
|
limit?: number;
|
|
1753
1815
|
}
|
|
@@ -1759,6 +1821,8 @@ interface MemoryListPageOptions {
|
|
|
1759
1821
|
types?: MemoryType[];
|
|
1760
1822
|
/** 限定主体 ID */
|
|
1761
1823
|
objectId?: string;
|
|
1824
|
+
/** 限定作用域(key-value 匹配过滤,用于子 session / 主题 / 角色记忆隔离等场景) */
|
|
1825
|
+
scope?: Record<string, unknown>;
|
|
1762
1826
|
/** 偏移量 */
|
|
1763
1827
|
offset?: number;
|
|
1764
1828
|
/** 每页数量(默认 20) */
|
|
@@ -1766,12 +1830,17 @@ interface MemoryListPageOptions {
|
|
|
1766
1830
|
}
|
|
1767
1831
|
/**
|
|
1768
1832
|
* 记忆清空选项
|
|
1833
|
+
*
|
|
1834
|
+
* 安全语义:未传任何过滤条件时清空全部;传入 objectId / types / scope 时
|
|
1835
|
+
* 仅删除同时匹配所有给定条件的记忆,避免误删其他主体或类型的记忆。
|
|
1769
1836
|
*/
|
|
1770
1837
|
interface MemoryClearOptions {
|
|
1771
1838
|
/** 仅清空指定类型 */
|
|
1772
1839
|
types?: MemoryType[];
|
|
1773
1840
|
/** 仅清空指定主体 */
|
|
1774
1841
|
objectId?: string;
|
|
1842
|
+
/** 仅清空匹配指定作用域的记忆(key-value 匹配过滤) */
|
|
1843
|
+
scope?: Record<string, unknown>;
|
|
1775
1844
|
}
|
|
1776
1845
|
/**
|
|
1777
1846
|
* 记忆条目更新输入
|
|
@@ -1934,8 +2003,8 @@ interface MemoryOperations {
|
|
|
1934
2003
|
* - `fast` — 快速响应场景(低延迟优先)
|
|
1935
2004
|
*/
|
|
1936
2005
|
declare const ModelScenarioSchema: z.ZodEnum<{
|
|
1937
|
-
default: "default";
|
|
1938
2006
|
chat: "chat";
|
|
2007
|
+
default: "default";
|
|
1939
2008
|
reasoning: "reasoning";
|
|
1940
2009
|
plan: "plan";
|
|
1941
2010
|
execute: "execute";
|
|
@@ -1948,6 +2017,22 @@ declare const ModelScenarioSchema: z.ZodEnum<{
|
|
|
1948
2017
|
}>;
|
|
1949
2018
|
/** 模型场景类型 */
|
|
1950
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>;
|
|
1951
2036
|
/**
|
|
1952
2037
|
* 模型条目 Schema
|
|
1953
2038
|
*
|
|
@@ -1966,6 +2051,11 @@ type ModelScenario = z.infer<typeof ModelScenarioSchema>;
|
|
|
1966
2051
|
declare const ModelEntrySchema: z.ZodObject<{
|
|
1967
2052
|
id: z.ZodString;
|
|
1968
2053
|
model: z.ZodString;
|
|
2054
|
+
api: z.ZodOptional<z.ZodEnum<{
|
|
2055
|
+
chat: "chat";
|
|
2056
|
+
responses: "responses";
|
|
2057
|
+
anthropic: "anthropic";
|
|
2058
|
+
}>>;
|
|
1969
2059
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
1970
2060
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
1971
2061
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -2009,6 +2099,11 @@ declare const LLMConfigSchema: z.ZodObject<{
|
|
|
2009
2099
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
2010
2100
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2011
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
|
+
}>>>;
|
|
2012
2107
|
maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2013
2108
|
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2014
2109
|
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -2016,6 +2111,11 @@ declare const LLMConfigSchema: z.ZodObject<{
|
|
|
2016
2111
|
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2017
2112
|
id: z.ZodString;
|
|
2018
2113
|
model: z.ZodString;
|
|
2114
|
+
api: z.ZodOptional<z.ZodEnum<{
|
|
2115
|
+
chat: "chat";
|
|
2116
|
+
responses: "responses";
|
|
2117
|
+
anthropic: "anthropic";
|
|
2118
|
+
}>>;
|
|
2019
2119
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
2020
2120
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2021
2121
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -2023,8 +2123,8 @@ declare const LLMConfigSchema: z.ZodObject<{
|
|
|
2023
2123
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2024
2124
|
}, z.core.$strip>>>;
|
|
2025
2125
|
scenarios: z.ZodOptional<z.ZodObject<{
|
|
2026
|
-
default: z.ZodOptional<z.ZodString>;
|
|
2027
2126
|
chat: z.ZodOptional<z.ZodString>;
|
|
2127
|
+
default: z.ZodOptional<z.ZodString>;
|
|
2028
2128
|
reasoning: z.ZodOptional<z.ZodString>;
|
|
2029
2129
|
plan: z.ZodOptional<z.ZodString>;
|
|
2030
2130
|
execute: z.ZodOptional<z.ZodString>;
|
|
@@ -2046,6 +2146,8 @@ type LLMConfig = z.infer<typeof LLMConfigSchema>;
|
|
|
2046
2146
|
interface ResolvedModelConfig {
|
|
2047
2147
|
/** 模型名称(传给 API 的实际模型名) */
|
|
2048
2148
|
model: string;
|
|
2149
|
+
/** API 协议(模型条目 > 全局配置 > `chat`) */
|
|
2150
|
+
api: ApiType;
|
|
2049
2151
|
/** API Key(模型条目 > 全局配置 > 环境变量) */
|
|
2050
2152
|
apiKey: string | undefined;
|
|
2051
2153
|
/** API 基础 URL(模型条目 > 全局配置 > 环境变量 > 默认 OpenAI) */
|
|
@@ -2077,6 +2179,18 @@ interface ResolveRequiredModelEntryOptions {
|
|
|
2077
2179
|
* @returns 成功返回已解析模型配置,失败返回 `CONFIGURATION_ERROR`
|
|
2078
2180
|
*/
|
|
2079
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;
|
|
2080
2194
|
/** MCP 服务器能力 Schema */
|
|
2081
2195
|
declare const MCPServerCapabilitiesSchema: z.ZodObject<{
|
|
2082
2196
|
tools: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -2205,14 +2319,16 @@ type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
|
|
|
2205
2319
|
/**
|
|
2206
2320
|
* Memory 配置 Schema
|
|
2207
2321
|
*
|
|
2208
|
-
*
|
|
2209
|
-
*
|
|
2210
|
-
* apiKey / baseUrl 统一使用 LLM 配置。
|
|
2322
|
+
* 配置对话记忆的提取、存储与检索参数。两种 provider 均为嵌入式,复用同一套
|
|
2323
|
+
* vecdb / reldb / LLM / Embedding;模型通过 LLMConfigSchema.scenarios.extraction
|
|
2324
|
+
* 解析,apiKey / baseUrl 统一使用 LLM 配置。
|
|
2211
2325
|
*
|
|
2212
2326
|
* @example
|
|
2213
2327
|
* ```ts
|
|
2214
2328
|
* const memoryConfig = {
|
|
2215
|
-
*
|
|
2329
|
+
* provider: 'native',
|
|
2330
|
+
* maxEntriesPerObject: 1000,
|
|
2331
|
+
* maxEntriesGlobal: 100000,
|
|
2216
2332
|
* embeddingEnabled: true,
|
|
2217
2333
|
* recencyDecay: 0.95,
|
|
2218
2334
|
* defaultTopK: 10,
|
|
@@ -2220,7 +2336,12 @@ type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
|
|
|
2220
2336
|
* ```
|
|
2221
2337
|
*/
|
|
2222
2338
|
declare const MemoryConfigSchema: z.ZodObject<{
|
|
2223
|
-
|
|
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>;
|
|
2224
2345
|
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2225
2346
|
recencyDecay: z.ZodDefault<z.ZodNumber>;
|
|
2226
2347
|
embeddingEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -2433,7 +2554,7 @@ type A2AConfig = z.infer<typeof A2AConfigSchema>;
|
|
|
2433
2554
|
* { id: 'docs', collection: 'documentation', name: '产品文档', topK: 5, minScore: 0.7 },
|
|
2434
2555
|
* ],
|
|
2435
2556
|
* },
|
|
2436
|
-
* memory: {
|
|
2557
|
+
* memory: { maxEntriesPerObject: 500, embeddingEnabled: true },
|
|
2437
2558
|
* token: { tokenRatio: 0.25 },
|
|
2438
2559
|
* summary: { systemPrompt: 'You are a summarizer.' },
|
|
2439
2560
|
* compress: { defaultStrategy: 'hybrid', preserveLastN: 4 },
|
|
@@ -2445,6 +2566,11 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
2445
2566
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
2446
2567
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2447
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
|
+
}>>>;
|
|
2448
2574
|
maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2449
2575
|
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2450
2576
|
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -2452,6 +2578,11 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
2452
2578
|
models: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2453
2579
|
id: z.ZodString;
|
|
2454
2580
|
model: z.ZodString;
|
|
2581
|
+
api: z.ZodOptional<z.ZodEnum<{
|
|
2582
|
+
chat: "chat";
|
|
2583
|
+
responses: "responses";
|
|
2584
|
+
anthropic: "anthropic";
|
|
2585
|
+
}>>;
|
|
2455
2586
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
2456
2587
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2457
2588
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -2459,8 +2590,8 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
2459
2590
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2460
2591
|
}, z.core.$strip>>>;
|
|
2461
2592
|
scenarios: z.ZodOptional<z.ZodObject<{
|
|
2462
|
-
default: z.ZodOptional<z.ZodString>;
|
|
2463
2593
|
chat: z.ZodOptional<z.ZodString>;
|
|
2594
|
+
default: z.ZodOptional<z.ZodString>;
|
|
2464
2595
|
reasoning: z.ZodOptional<z.ZodString>;
|
|
2465
2596
|
plan: z.ZodOptional<z.ZodString>;
|
|
2466
2597
|
execute: z.ZodOptional<z.ZodString>;
|
|
@@ -2523,7 +2654,12 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
2523
2654
|
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2524
2655
|
}, z.core.$strip>>;
|
|
2525
2656
|
memory: z.ZodOptional<z.ZodObject<{
|
|
2526
|
-
|
|
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>;
|
|
2527
2663
|
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
2528
2664
|
recencyDecay: z.ZodDefault<z.ZodNumber>;
|
|
2529
2665
|
embeddingEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -2877,4 +3013,4 @@ interface ReasoningOperations {
|
|
|
2877
3013
|
runStream: (query: string, options?: ReasoningOptions) => AsyncIterable<ReasoningStreamEvent>;
|
|
2878
3014
|
}
|
|
2879
3015
|
|
|
2880
|
-
export { type
|
|
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 {
|
|
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
|
-
*
|
|
207
|
+
* 控制记忆注入与提取。`scope` / `types` / `minImportance` 会完整透传给 Memory 的
|
|
208
|
+
* `injectMemories` 与 `extract`,用于表达「用户 + 主题 + 角色」等多维隔离
|
|
209
|
+
* (如 `{ userId, topicId, personaId }`)。
|
|
208
210
|
*/
|
|
209
|
-
memory?:
|
|
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,
|
|
2
|
-
export { A as AIFunctions, a as AIInitOptions, C as CompressionStrategy, b as CompressionStrategySchema, H as HaiAIError } from './ai-types-
|
|
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-
|
|
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
|
-
/**
|
|
347
|
-
|
|
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-
|
|
466
|
-
//# sourceMappingURL=chunk-
|
|
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
|