@h-ai/ai 0.1.0-alpha.42 → 0.1.0-alpha.44
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 +16 -7
- package/dist/{ai-audio-ws-protocol-DrFmoxAc.d.ts → ai-audio-ws-protocol-CUIXMEkt.d.ts} +1 -1
- package/dist/{ai-reasoning-types-CiIOPCQw.d.ts → ai-reasoning-types-DsVJ4CE8.d.ts} +32 -21
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-GKFOJPSQ.js → chunk-E3W2H6FL.js} +17 -12
- package/dist/chunk-E3W2H6FL.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/chunk-GKFOJPSQ.js.map +0 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ import { ai } from '@h-ai/ai'
|
|
|
33
33
|
const init = await ai.init({
|
|
34
34
|
llm: {
|
|
35
35
|
model: 'gpt-4o-mini',
|
|
36
|
-
apiKey: process.env.
|
|
36
|
+
apiKey: process.env.HAI_AI_LLM_APIKEY,
|
|
37
37
|
},
|
|
38
38
|
})
|
|
39
39
|
if (!init.success)
|
|
@@ -61,7 +61,7 @@ await vecdb.init({ type: 'lancedb', path: './ai-vec.db' })
|
|
|
61
61
|
const init = await ai.init({
|
|
62
62
|
llm: {
|
|
63
63
|
model: 'gpt-4o-mini',
|
|
64
|
-
apiKey: process.env.
|
|
64
|
+
apiKey: process.env.HAI_AI_LLM_APIKEY,
|
|
65
65
|
},
|
|
66
66
|
})
|
|
67
67
|
if (!init.success) {
|
|
@@ -89,7 +89,7 @@ import { ai } from '@h-ai/ai'
|
|
|
89
89
|
const storeProvider: AIStoreProvider = createMyStoreProvider()
|
|
90
90
|
|
|
91
91
|
await ai.init(
|
|
92
|
-
{ llm: { model: 'gpt-4o-mini', apiKey: process.env.
|
|
92
|
+
{ llm: { model: 'gpt-4o-mini', apiKey: process.env.HAI_AI_LLM_APIKEY } },
|
|
93
93
|
{ storeProvider },
|
|
94
94
|
)
|
|
95
95
|
|
|
@@ -211,11 +211,15 @@ if (setup.success) {
|
|
|
211
211
|
|
|
212
212
|
### 语音(Audio)
|
|
213
213
|
|
|
214
|
-
先在 `ai.init()`
|
|
214
|
+
先在 `ai.init()` 中注册语音模型并映射默认识别/合成模型。凭据默认回退到平台环境变量;只有 LLM 与语音模型确认使用同一凭据时,才显式启用 `inheritLlmApiKey`:
|
|
215
215
|
|
|
216
216
|
```ts
|
|
217
217
|
await ai.init({
|
|
218
|
+
llm: {
|
|
219
|
+
apiKey: process.env.HAI_AI_LLM_APIKEY,
|
|
220
|
+
},
|
|
218
221
|
audio: {
|
|
222
|
+
inheritLlmApiKey: true,
|
|
219
223
|
models: [
|
|
220
224
|
{ id: 'asr', provider: 'qwen', model: 'qwen3-asr-flash-realtime', operations: ['transcribe'] },
|
|
221
225
|
{ id: 'tts', provider: 'qwen', model: 'qwen3-tts-flash-realtime', operations: ['synthesize'] },
|
|
@@ -262,6 +266,8 @@ const caps = ai.audio.getCapabilities({ operation: 'synthesize', model: 'tts' })
|
|
|
262
266
|
if (caps.success && caps.data.synthesize?.streamingAudioOutput) { /* 可实时 TTS */ }
|
|
263
267
|
```
|
|
264
268
|
|
|
269
|
+
`OptionalSecretSchema` 统一用于 LLM、Audio 与 Image 的可选密钥字段:YAML `null`、空字符串和纯空白字符串都会规范化为 `undefined`。语音密钥优先级为模型条目 `apiKey` → 启用继承后的 LLM `apiKey` → 对应平台环境变量;`inheritLlmApiKey` 默认关闭,避免跨供应商误用密钥。
|
|
270
|
+
|
|
265
271
|
> `synthesizeStream` 严格按 `segment_started → audio* → segment_done` 产出事件。`segment_started` 携带服务端解析 Provider 后的**真实输出音频参数**(`format` / `sampleRate` / `channels`),播放器据此正确解码,不应按请求参数猜测格式。播放器只有在对应音频真正播放完成后才应把该段文本计入 `spokenText`;播放状态仍由应用管理。
|
|
266
272
|
|
|
267
273
|
取消/超时/连接错误统一为领域错误:`AbortSignal` 触发 → `AUDIO_CANCELLED`(超时 → `AUDIO_TIMEOUT`),连接失败或 `end` 前异常断连 → `AUDIO_CONNECTION_FAILED`。实时连接时长受 `audio.maxStreamDurationMs`(默认 5 分钟)限制。
|
|
@@ -393,9 +399,9 @@ const manager = ai.context.createManager({
|
|
|
393
399
|
|
|
394
400
|
```yaml
|
|
395
401
|
llm:
|
|
396
|
-
apiKey:
|
|
397
|
-
baseUrl:
|
|
398
|
-
model:
|
|
402
|
+
apiKey: ''
|
|
403
|
+
baseUrl: https://api.openai.com/v1
|
|
404
|
+
model: gpt-4o-mini
|
|
399
405
|
api: chat # chat(默认)| responses | anthropic —— 底层 API 协议,对使用方透明
|
|
400
406
|
timeout: 60000
|
|
401
407
|
tempModelCacheTtl: 600000 # 临时模型客户端缓存 TTL(毫秒,默认 10 分钟)
|
|
@@ -434,6 +440,9 @@ memory:
|
|
|
434
440
|
writebackRelatedTopK: 20
|
|
435
441
|
```
|
|
436
442
|
|
|
443
|
+
通过 `core.config.load('ai', ...)` 加载时,约定环境变量优先于 YAML;
|
|
444
|
+
例如 `HAI_AI_LLM_APIKEY`、`HAI_AI_LLM_BASEURL`、`HAI_AI_LLM_MODEL`。
|
|
445
|
+
|
|
437
446
|
启用 mem0(真·嵌入式 mem0ai/oss 引擎):
|
|
438
447
|
|
|
439
448
|
```yaml
|
|
@@ -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 { aP as ChatMessage, ao as InteractionScope, U as MemoryType, bA as RagOptions, bE as ReasoningOptions, cb as ToolRegistryOperations, bm as MemoryEntry, bT as SessionInfo, bf as LLMOperations, bs as MemoryOperations, bz as RagOperations, bD as ReasoningOperations, c as AIConfig, d as AIConfigInput, aE as AIStoreProvider, cd as ToolsOperations, bX as StreamOperations, bK as RetrievalOperations, b9 as KnowledgeOperations, ay as A2AOperations, q as AudioOperations, l as AudioFormat } from './ai-reasoning-types-DsVJ4CE8.js';
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { Buffer } from 'node:buffer';
|
|
@@ -2214,6 +2214,13 @@ interface MemoryOperations extends MemoryCoreOperations {
|
|
|
2214
2214
|
* @module ai-config
|
|
2215
2215
|
*/
|
|
2216
2216
|
|
|
2217
|
+
/**
|
|
2218
|
+
* 可选密钥 Schema。
|
|
2219
|
+
*
|
|
2220
|
+
* 配置文件中的空插值、空白字符串或 YAML null 都表示“未配置”,输出统一为 undefined;
|
|
2221
|
+
* 非空密钥保持原值,避免模块调用方重复编写兼容清洗逻辑。
|
|
2222
|
+
*/
|
|
2223
|
+
declare const OptionalSecretSchema: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2217
2224
|
/**
|
|
2218
2225
|
* 模型场景枚举
|
|
2219
2226
|
*
|
|
@@ -2285,7 +2292,7 @@ declare const ModelEntrySchema: z.ZodObject<{
|
|
|
2285
2292
|
responses: "responses";
|
|
2286
2293
|
anthropic: "anthropic";
|
|
2287
2294
|
}>>;
|
|
2288
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2295
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2289
2296
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2290
2297
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
2291
2298
|
temperature: z.ZodOptional<z.ZodNumber>;
|
|
@@ -2325,7 +2332,7 @@ type ModelEntry = z.infer<typeof ModelEntrySchema>;
|
|
|
2325
2332
|
* ```
|
|
2326
2333
|
*/
|
|
2327
2334
|
declare const LLMConfigSchema: z.ZodObject<{
|
|
2328
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2335
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2329
2336
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2330
2337
|
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2331
2338
|
api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
@@ -2345,7 +2352,7 @@ declare const LLMConfigSchema: z.ZodObject<{
|
|
|
2345
2352
|
responses: "responses";
|
|
2346
2353
|
anthropic: "anthropic";
|
|
2347
2354
|
}>>;
|
|
2348
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2355
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2349
2356
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2350
2357
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
2351
2358
|
temperature: z.ZodOptional<z.ZodNumber>;
|
|
@@ -2787,10 +2794,10 @@ declare const AudioModelEntrySchema: z.ZodObject<{
|
|
|
2787
2794
|
}>;
|
|
2788
2795
|
model: z.ZodString;
|
|
2789
2796
|
operations: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"transcribe">], null>, z.ZodTuple<[z.ZodLiteral<"synthesize">], null>, z.ZodTuple<[z.ZodLiteral<"transcribe">, z.ZodLiteral<"synthesize">], null>]>;
|
|
2790
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2797
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2791
2798
|
baseUrl: z.ZodOptional<z.ZodString>;
|
|
2792
|
-
appKey: z.ZodOptional<z.ZodString
|
|
2793
|
-
accessKey: z.ZodOptional<z.ZodString
|
|
2799
|
+
appKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2800
|
+
accessKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2794
2801
|
resourceId: z.ZodOptional<z.ZodString>;
|
|
2795
2802
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2796
2803
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
@@ -2827,14 +2834,15 @@ declare const AudioConfigSchema: z.ZodObject<{
|
|
|
2827
2834
|
}>;
|
|
2828
2835
|
model: z.ZodString;
|
|
2829
2836
|
operations: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"transcribe">], null>, z.ZodTuple<[z.ZodLiteral<"synthesize">], null>, z.ZodTuple<[z.ZodLiteral<"transcribe">, z.ZodLiteral<"synthesize">], null>]>;
|
|
2830
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2837
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2831
2838
|
baseUrl: z.ZodOptional<z.ZodString>;
|
|
2832
|
-
appKey: z.ZodOptional<z.ZodString
|
|
2833
|
-
accessKey: z.ZodOptional<z.ZodString
|
|
2839
|
+
appKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2840
|
+
accessKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2834
2841
|
resourceId: z.ZodOptional<z.ZodString>;
|
|
2835
2842
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2836
2843
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
2837
2844
|
}, z.core.$strip>>>;
|
|
2845
|
+
inheritLlmApiKey: z.ZodDefault<z.ZodBoolean>;
|
|
2838
2846
|
transcribeModel: z.ZodOptional<z.ZodString>;
|
|
2839
2847
|
synthesizeModel: z.ZodOptional<z.ZodString>;
|
|
2840
2848
|
maxAudioBytes: z.ZodDefault<z.ZodNumber>;
|
|
@@ -2845,7 +2853,8 @@ type AudioConfig = z.infer<typeof AudioConfigSchema>;
|
|
|
2845
2853
|
/**
|
|
2846
2854
|
* 已解析的语音模型配置
|
|
2847
2855
|
*
|
|
2848
|
-
* 由 `resolveAudioModel()`
|
|
2856
|
+
* 由 `resolveAudioModel()` 返回,凭据已按模型条目、显式 LLM 继承、平台环境变量的顺序解析,
|
|
2857
|
+
* 端点已应用平台默认值。
|
|
2849
2858
|
*/
|
|
2850
2859
|
interface ResolvedAudioModel {
|
|
2851
2860
|
/** 模型条目 ID */
|
|
@@ -2854,7 +2863,7 @@ interface ResolvedAudioModel {
|
|
|
2854
2863
|
provider: AudioProviderName;
|
|
2855
2864
|
/** 厂商模型名 */
|
|
2856
2865
|
model: string;
|
|
2857
|
-
/** API Key
|
|
2866
|
+
/** API Key(模型条目 > 显式启用的 LLM 密钥继承 > 平台环境变量) */
|
|
2858
2867
|
apiKey: string | undefined;
|
|
2859
2868
|
/** 端点(条目 > 平台默认) */
|
|
2860
2869
|
baseUrl: string;
|
|
@@ -2877,9 +2886,10 @@ interface ResolvedAudioModel {
|
|
|
2877
2886
|
* @param audioConfig - Audio 配置
|
|
2878
2887
|
* @param operation - 操作类型(识别 / 合成),决定使用哪个默认模型
|
|
2879
2888
|
* @param explicit - 请求显式指定的模型 ID(最高优先级)
|
|
2889
|
+
* @param llmApiKey - LLM 全局密钥,仅在 `inheritLlmApiKey` 启用时参与解析
|
|
2880
2890
|
* @returns 成功返回已解析模型;无匹配模型返回 `AUDIO_MODEL_NOT_FOUND`;缺少凭据返回 `CONFIGURATION_ERROR`
|
|
2881
2891
|
*/
|
|
2882
|
-
declare function resolveAudioModel(audioConfig: AudioConfig, operation: 'transcribe' | 'synthesize', explicit?: string): HaiResult<ResolvedAudioModel>;
|
|
2892
|
+
declare function resolveAudioModel(audioConfig: AudioConfig, operation: 'transcribe' | 'synthesize', explicit?: string, llmApiKey?: string): HaiResult<ResolvedAudioModel>;
|
|
2883
2893
|
/**
|
|
2884
2894
|
* 文生图平台枚举
|
|
2885
2895
|
*
|
|
@@ -2909,7 +2919,7 @@ declare const ImageModelEntrySchema: z.ZodObject<{
|
|
|
2909
2919
|
pollinations: "pollinations";
|
|
2910
2920
|
}>;
|
|
2911
2921
|
model: z.ZodString;
|
|
2912
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2922
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2913
2923
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2914
2924
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2915
2925
|
timeout: z.ZodDefault<z.ZodNumber>;
|
|
@@ -2928,7 +2938,7 @@ declare const ImageConfigSchema: z.ZodObject<{
|
|
|
2928
2938
|
pollinations: "pollinations";
|
|
2929
2939
|
}>;
|
|
2930
2940
|
model: z.ZodString;
|
|
2931
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
2941
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
2932
2942
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
2933
2943
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
2934
2944
|
timeout: z.ZodDefault<z.ZodNumber>;
|
|
@@ -3000,7 +3010,7 @@ declare function resolveImageModel(imageConfig: ImageConfig, explicit?: string):
|
|
|
3000
3010
|
*/
|
|
3001
3011
|
declare const AIConfigSchema: z.ZodObject<{
|
|
3002
3012
|
llm: z.ZodDefault<z.ZodObject<{
|
|
3003
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
3013
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3004
3014
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
3005
3015
|
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
3006
3016
|
api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
@@ -3020,7 +3030,7 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
3020
3030
|
responses: "responses";
|
|
3021
3031
|
anthropic: "anthropic";
|
|
3022
3032
|
}>>;
|
|
3023
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
3033
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3024
3034
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
3025
3035
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
3026
3036
|
temperature: z.ZodOptional<z.ZodNumber>;
|
|
@@ -3168,14 +3178,15 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
3168
3178
|
}>;
|
|
3169
3179
|
model: z.ZodString;
|
|
3170
3180
|
operations: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"transcribe">], null>, z.ZodTuple<[z.ZodLiteral<"synthesize">], null>, z.ZodTuple<[z.ZodLiteral<"transcribe">, z.ZodLiteral<"synthesize">], null>]>;
|
|
3171
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
3181
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3172
3182
|
baseUrl: z.ZodOptional<z.ZodString>;
|
|
3173
|
-
appKey: z.ZodOptional<z.ZodString
|
|
3174
|
-
accessKey: z.ZodOptional<z.ZodString
|
|
3183
|
+
appKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3184
|
+
accessKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3175
3185
|
resourceId: z.ZodOptional<z.ZodString>;
|
|
3176
3186
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
3177
3187
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
3178
3188
|
}, z.core.$strip>>>;
|
|
3189
|
+
inheritLlmApiKey: z.ZodDefault<z.ZodBoolean>;
|
|
3179
3190
|
transcribeModel: z.ZodOptional<z.ZodString>;
|
|
3180
3191
|
synthesizeModel: z.ZodOptional<z.ZodString>;
|
|
3181
3192
|
maxAudioBytes: z.ZodDefault<z.ZodNumber>;
|
|
@@ -3192,7 +3203,7 @@ declare const AIConfigSchema: z.ZodObject<{
|
|
|
3192
3203
|
pollinations: "pollinations";
|
|
3193
3204
|
}>;
|
|
3194
3205
|
model: z.ZodString;
|
|
3195
|
-
apiKey: z.ZodOptional<z.ZodString
|
|
3206
|
+
apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
|
|
3196
3207
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
3197
3208
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
3198
3209
|
timeout: z.ZodDefault<z.ZodNumber>;
|
|
@@ -3736,4 +3747,4 @@ interface ReasoningOperations {
|
|
|
3736
3747
|
runStream: (query: string, options?: ReasoningOptions) => AsyncIterable<ReasoningStreamEvent>;
|
|
3737
3748
|
}
|
|
3738
3749
|
|
|
3739
|
-
export { type
|
|
3750
|
+
export { type ResolveRequiredModelEntryOptions as $, type A2AConfig as A, ImageModelEntrySchema as B, type CompressConfig as C, type ImageProviderName as D, type EmbeddingConfig as E, type FileConfig as F, ImageProviderSchema as G, KnowledgeConfigSchema as H, type ImageConfig as I, LLMConfigSchema as J, type KnowledgeConfig as K, type LLMConfig as L, type MCPConfig as M, MCPConfigSchema as N, type MCPServerCapabilities as O, MCPServerCapabilitiesSchema as P, type MCPServerConfig as Q, MCPServerConfigSchema as R, type MemoryConfig as S, MemoryConfigSchema as T, type MemoryType as U, MemoryTypeSchema as V, type ModelEntry as W, ModelEntrySchema as X, type ModelScenario as Y, ModelScenarioSchema as Z, OptionalSecretSchema as _, A2AConfigSchema as a, type KnowledgeAskResult as a$, type ResolvedAudioModel as a0, type ResolvedImageModel as a1, type ResolvedModelConfig as a2, type RetrievalConfig as a3, RetrievalConfigSchema as a4, type RetrievalSourceConfig as a5, RetrievalSourceSchema as a6, type SummaryConfig as a7, SummaryConfigSchema as a8, type SynthesisEvent as a9, type A2ATaskFilter as aA, type AILLMFunctionsDeps as aB, type AIRelStore as aC, type AIRelStoreOptions as aD, type AIStoreProvider as aE, type AIVectorBackend as aF, type AIVectorStore as aG, type AskOptions as aH, type AssistantMessage as aI, type ChatCompletionChoice as aJ, type ChatCompletionChunk as aK, type ChatCompletionDelta as aL, type ChatCompletionRequest as aM, type ChatCompletionResponse as aN, type ChatHistoryOptions as aO, type ChatMessage as aP, type ChatRecord as aQ, type Citation as aR, type DefineToolOptions as aS, type DeveloperMessage as aT, type EntityDocumentRelation as aU, type EntityDocumentResult as aV, type EntityListOptions as aW, type EntityQueryOptions as aX, type GenerateObjectRequest as aY, type ImageContent as aZ, type KnowledgeAskOptions as a_, type SynthesisRequest as aa, type SynthesisResult as ab, type SynthesisStreamRequest as ac, type SynthesisTextSegment as ad, type TokenConfig as ae, TokenConfigSchema as af, type TranscriptionEvent as ag, type TranscriptionRequest as ah, type TranscriptionResult as ai, type TranscriptionStreamRequest as aj, resolveAudioModel as ak, resolveImageModel as al, resolveModelApi as am, resolveModelEntry as an, type InteractionScope as ao, type A2AAgentCardConfig as ap, type A2AApiKeySecurity as aq, type A2AAuthenticator as ar, type A2ACallOptions as as, type A2ACallResult as at, type A2ACallerIdentity as au, type A2AContextInfo as av, type A2AHandleResult as aw, type A2AMessageRecord as ax, type A2AOperations as ay, type A2ASecurityConfig as az, A2ASkillConfigSchema as b, type TempModelConfig as b$, type KnowledgeDocumentInfo as b0, type KnowledgeDocumentListOptions as b1, type KnowledgeDocumentRemoveOptions as b2, type KnowledgeEntity as b3, type KnowledgeIngestBatchProgress as b4, type KnowledgeIngestBatchResult as b5, type KnowledgeIngestFileInput as b6, type KnowledgeIngestInput as b7, type KnowledgeIngestResult as b8, type KnowledgeOperations as b9, type RagOptions as bA, type RagResult as bB, type RagStreamEvent as bC, type ReasoningOperations as bD, type ReasoningOptions as bE, type ReasoningResult as bF, type ReasoningStep as bG, type ReasoningStepType as bH, type ReasoningStrategy as bI, type ReasoningStreamEvent as bJ, type RetrievalOperations as bK, type RetrievalRequest as bL, type RetrievalResult as bM, type RetrievalResultItem as bN, type RetrievalSource as bO, type SSEDecoder as bP, type SSEEvent as bQ, type ScopedMemoryBinding as bR, type ScopedMemoryOperations as bS, type SessionInfo as bT, type StoreFilter as bU, type StorePage as bV, type StoreScope as bW, type StreamOperations as bX, type StreamProcessor as bY, type StreamResult as bZ, type SystemMessage as b_, type KnowledgeRetrieveItem as ba, type KnowledgeRetrieveOptions as bb, type KnowledgeRetrieveResult as bc, type KnowledgeSetupOptions as bd, type KnowledgeStore as be, type LLMOperations as bf, type LLMProvider as bg, type MemoryAccessScope as bh, type MemoryAdminOperations as bi, type MemoryClearAllOptions as bj, type MemoryClearOptions as bk, type MemoryCoreOperations as bl, type MemoryEntry as bm, type MemoryEntryInput as bn, type MemoryExtractOptions as bo, type MemoryInjectionOptions as bp, type MemoryListOptions as bq, type MemoryListPageOptions as br, type MemoryOperations as bs, type MemoryRecallOptions as bt, type MemoryUpdateInput as bu, type MessageContent as bv, type MessageRole as bw, type ObjectRef as bx, type RagContextItem as by, type RagOperations as bz, type AIConfig as c, type TextContent as c0, type TokenUsage as c1, type Tool as c2, type ToolAuthorizationRequest as c3, type ToolAuthorizer as c4, type ToolCall as c5, type ToolDefinition as c6, type ToolErrorType as c7, type ToolExecutionContext as c8, type ToolExecutionOptions as c9, type ToolMessage as ca, type ToolRegistryOperations as cb, type ToolRegistryOptions as cc, type ToolsOperations as cd, type UserMessage as ce, type WhereClause as cf, type WhereOperator as cg, type WhereValue as ch, type AIConfigInput as d, AIConfigSchema as e, type ApiType as f, ApiTypeSchema as g, type AudioCapabilitiesRequest as h, type AudioConfig as i, AudioConfigSchema as j, type AudioContent as k, type AudioFormat as l, type AudioInputStream as m, type AudioModelCapabilities as n, type AudioModelEntry as o, AudioModelEntrySchema as p, type AudioOperations as q, type AudioProviderName as r, AudioProviderSchema as s, CompressConfigSchema as t, EmbeddingConfigSchema as u, type EntityType as v, EntityTypeSchema as w, FileConfigSchema as x, ImageConfigSchema as y, type ImageModelEntry as z };
|
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, f as ApiType, g as ApiTypeSchema, h as AudioCapabilitiesRequest, i as AudioConfig, j as AudioConfigSchema, k as AudioContent, l as AudioFormat, m as AudioInputStream, n as AudioModelCapabilities, o as AudioModelEntry, p as AudioModelEntrySchema, q as AudioOperations, r as AudioProviderName, s as AudioProviderSchema, C as CompressConfig, t as CompressConfigSchema, E as EmbeddingConfig, u as EmbeddingConfigSchema, v as EntityType, w as EntityTypeSchema, F as FileConfig, x as FileConfigSchema, I as ImageConfig, y as ImageConfigSchema, z as ImageModelEntry, B as ImageModelEntrySchema, D as ImageProviderName, G as ImageProviderSchema, K as KnowledgeConfig, H as KnowledgeConfigSchema, L as LLMConfig, J as LLMConfigSchema, M as MCPConfig, N as MCPConfigSchema, O as MCPServerCapabilities, P as MCPServerCapabilitiesSchema, Q as MCPServerConfig, R as MCPServerConfigSchema, S as MemoryConfig, T as MemoryConfigSchema, U as MemoryType, V as MemoryTypeSchema, W as ModelEntry, X as ModelEntrySchema, Y as ModelScenario, Z as ModelScenarioSchema, _ as
|
|
2
|
-
export { A as AIFunctions, a as AIInitOptions, b as AUDIO_WS_PATH, c as AudioFormatSchema, d as AudioWsClientMessage, e as AudioWsClientMessageSchema, f as AudioWsDoneMessage, g as AudioWsDoneMessageSchema, h as AudioWsEndMessage, i as AudioWsErrorMessage, j as AudioWsSegmentDoneMessage, k as AudioWsSegmentStartedMessage, l as AudioWsServerMessage, m as AudioWsSpeechMessage, n as AudioWsStartMessage, o as AudioWsStartMessageSchema, p as AudioWsTextMessage, q as AudioWsTextMessageSchema, r as AudioWsTranscriptMessage, C as CompressionStrategy, s as CompressionStrategySchema, G as GenerateImageRequest, t as GenerateImageResult, u as GeneratedImage, H as HaiAIError, I as ImageOperations, v as ImageSize, R as ReferenceImage } from './ai-audio-ws-protocol-
|
|
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, h as AudioCapabilitiesRequest, i as AudioConfig, j as AudioConfigSchema, k as AudioContent, l as AudioFormat, m as AudioInputStream, n as AudioModelCapabilities, o as AudioModelEntry, p as AudioModelEntrySchema, q as AudioOperations, r as AudioProviderName, s as AudioProviderSchema, C as CompressConfig, t as CompressConfigSchema, E as EmbeddingConfig, u as EmbeddingConfigSchema, v as EntityType, w as EntityTypeSchema, F as FileConfig, x as FileConfigSchema, I as ImageConfig, y as ImageConfigSchema, z as ImageModelEntry, B as ImageModelEntrySchema, D as ImageProviderName, G as ImageProviderSchema, K as KnowledgeConfig, H as KnowledgeConfigSchema, L as LLMConfig, J as LLMConfigSchema, M as MCPConfig, N as MCPConfigSchema, O as MCPServerCapabilities, P as MCPServerCapabilitiesSchema, Q as MCPServerConfig, R as MCPServerConfigSchema, S as MemoryConfig, T as MemoryConfigSchema, U as MemoryType, V as MemoryTypeSchema, W as ModelEntry, X as ModelEntrySchema, Y as ModelScenario, Z as ModelScenarioSchema, _ as OptionalSecretSchema, $ as ResolveRequiredModelEntryOptions, a0 as ResolvedAudioModel, a1 as ResolvedImageModel, a2 as ResolvedModelConfig, a3 as RetrievalConfig, a4 as RetrievalConfigSchema, a5 as RetrievalSourceConfig, a6 as RetrievalSourceSchema, a7 as SummaryConfig, a8 as SummaryConfigSchema, a9 as SynthesisEvent, aa as SynthesisRequest, ab as SynthesisResult, ac as SynthesisStreamRequest, ad as SynthesisTextSegment, ae as TokenConfig, af as TokenConfigSchema, ag as TranscriptionEvent, ah as TranscriptionRequest, ai as TranscriptionResult, aj as TranscriptionStreamRequest, ak as resolveAudioModel, al as resolveImageModel, am as resolveModelApi, an as resolveModelEntry } from './ai-reasoning-types-DsVJ4CE8.js';
|
|
2
|
+
export { A as AIFunctions, a as AIInitOptions, b as AUDIO_WS_PATH, c as AudioFormatSchema, d as AudioWsClientMessage, e as AudioWsClientMessageSchema, f as AudioWsDoneMessage, g as AudioWsDoneMessageSchema, h as AudioWsEndMessage, i as AudioWsErrorMessage, j as AudioWsSegmentDoneMessage, k as AudioWsSegmentStartedMessage, l as AudioWsServerMessage, m as AudioWsSpeechMessage, n as AudioWsStartMessage, o as AudioWsStartMessageSchema, p as AudioWsTextMessage, q as AudioWsTextMessageSchema, r as AudioWsTranscriptMessage, C as CompressionStrategy, s as CompressionStrategySchema, G as GenerateImageRequest, t as GenerateImageResult, u as GeneratedImage, H as HaiAIError, I as ImageOperations, v as ImageSize, R as ReferenceImage } from './ai-audio-ws-protocol-CUIXMEkt.js';
|
|
3
3
|
export { A2AClientOperations, AIApiAdapter, AIClient, AIClientConfig, AudioClientConfig, AudioClientOperations, AudioTicketRequest, StreamOptions, StreamProgress, collectStreamContent, createA2AClient, createAIClient, createAudioClient, createUnconfiguredAudioClient, 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, AUDIO_WS_PATH, ApiTypeSchema, AudioConfigSchema, AudioFormatSchema, AudioModelEntrySchema, AudioProviderSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, ImageConfigSchema, ImageModelEntrySchema, ImageProviderSchema, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry } from './chunk-
|
|
1
|
+
export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, AUDIO_WS_PATH, ApiTypeSchema, AudioConfigSchema, AudioFormatSchema, AudioModelEntrySchema, AudioProviderSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, ImageConfigSchema, ImageModelEntrySchema, ImageProviderSchema, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, OptionalSecretSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry } from './chunk-E3W2H6FL.js';
|
|
2
2
|
export { collectStreamContent, createA2AClient, createAIClient, createAudioClient, createUnconfiguredAudioClient, parseSSE } from './chunk-6RWS5OWJ.js';
|
|
3
3
|
export { HaiAIError } from './chunk-JC7QBT3C.js';
|
|
4
4
|
//# sourceMappingURL=browser.js.map
|
|
@@ -216,6 +216,9 @@ var aiM = core.i18n.createMessageGetter({
|
|
|
216
216
|
});
|
|
217
217
|
|
|
218
218
|
// src/ai-config.ts
|
|
219
|
+
var OptionalSecretSchema = z.string().nullable().transform(
|
|
220
|
+
(value) => value === null || value.trim() === "" ? void 0 : value
|
|
221
|
+
).optional();
|
|
219
222
|
var ModelScenarioSchema = z.enum(["default", "chat", "reasoning", "plan", "execute", "extraction", "summary", "embedding", "rerank", "ocr", "fast"]);
|
|
220
223
|
var ApiTypeSchema = z.enum(["chat", "responses", "anthropic"]);
|
|
221
224
|
var ModelEntrySchema = z.object({
|
|
@@ -226,7 +229,7 @@ var ModelEntrySchema = z.object({
|
|
|
226
229
|
/** API 协议(可选,未指定时回退全局 `api`,再回退 `chat`;决定走 Chat Completions / Responses / Anthropic) */
|
|
227
230
|
api: ApiTypeSchema.optional(),
|
|
228
231
|
/** API Key 覆盖(可选,未提供时使用全局配置) */
|
|
229
|
-
apiKey:
|
|
232
|
+
apiKey: OptionalSecretSchema,
|
|
230
233
|
/** Base URL 覆盖(可选) */
|
|
231
234
|
baseUrl: z.url().optional(),
|
|
232
235
|
/** 最大 Token 数覆盖(可选) */
|
|
@@ -238,7 +241,7 @@ var ModelEntrySchema = z.object({
|
|
|
238
241
|
});
|
|
239
242
|
var LLMConfigSchema = z.object({
|
|
240
243
|
/** 全局 API Key(各模型 fallback;未提供时回退到 `process.env.HAI_AI_LLM_API_KEY` 或 `process.env.OPENAI_API_KEY`) */
|
|
241
|
-
apiKey:
|
|
244
|
+
apiKey: OptionalSecretSchema,
|
|
242
245
|
/** 全局 API 基础 URL(各模型 fallback;未提供时回退到 `process.env.HAI_AI_LLM_BASE_URL` 或 `process.env.OPENAI_BASE_URL`) */
|
|
243
246
|
baseUrl: z.url().optional(),
|
|
244
247
|
/** 默认模型名称(默认 `'gpt-4o-mini'`) */
|
|
@@ -486,14 +489,14 @@ var AudioModelEntrySchema = z.object({
|
|
|
486
489
|
z.tuple([z.literal("synthesize")]),
|
|
487
490
|
z.tuple([z.literal("transcribe"), z.literal("synthesize")])
|
|
488
491
|
]),
|
|
489
|
-
/** API Key
|
|
490
|
-
apiKey:
|
|
492
|
+
/** API Key 覆盖(未提供时可按 Audio 配置继承 LLM 密钥,最后回退对应平台环境变量) */
|
|
493
|
+
apiKey: OptionalSecretSchema,
|
|
491
494
|
/** HTTP / WebSocket 端点覆盖(未提供时使用平台默认端点) */
|
|
492
495
|
baseUrl: z.string().optional(),
|
|
493
496
|
/** 火山引擎 App Key(`X-Api-App-Key`,旧版控制台 ASR 需要) */
|
|
494
|
-
appKey:
|
|
497
|
+
appKey: OptionalSecretSchema,
|
|
495
498
|
/** 火山引擎 Access Key(`X-Api-Access-Key`,旧版控制台 ASR 需要) */
|
|
496
|
-
accessKey:
|
|
499
|
+
accessKey: OptionalSecretSchema,
|
|
497
500
|
/** 火山引擎资源 ID(`X-Api-Resource-Id`;未提供时使用平台默认资源 ID) */
|
|
498
501
|
resourceId: z.string().optional(),
|
|
499
502
|
/** 阿里云百炼业务空间 ID(`X-DashScope-WorkSpace`,可选) */
|
|
@@ -504,6 +507,8 @@ var AudioModelEntrySchema = z.object({
|
|
|
504
507
|
var AudioConfigSchema = z.object({
|
|
505
508
|
/** 注册的语音模型列表 */
|
|
506
509
|
models: z.array(AudioModelEntrySchema).optional(),
|
|
510
|
+
/** 是否允许未单独配置密钥的语音模型继承 LLM 全局密钥;跨供应商部署应保持关闭。 */
|
|
511
|
+
inheritLlmApiKey: z.boolean().default(false),
|
|
507
512
|
/** 默认识别模型 ID(`ai.audio.transcribe*` 未指定 model 时使用) */
|
|
508
513
|
transcribeModel: z.string().optional(),
|
|
509
514
|
/** 默认合成模型 ID(`ai.audio.synthesize*` 未指定 model 时使用) */
|
|
@@ -534,7 +539,7 @@ function audioProviderEnvApiKey(provider) {
|
|
|
534
539
|
return process.env.HAI_AI_AUDIO_DOUBAO_API_KEY ?? process.env.VOLC_API_KEY;
|
|
535
540
|
}
|
|
536
541
|
}
|
|
537
|
-
function resolveAudioModel(audioConfig, operation, explicit) {
|
|
542
|
+
function resolveAudioModel(audioConfig, operation, explicit, llmApiKey) {
|
|
538
543
|
const targetId = explicit ?? (operation === "transcribe" ? audioConfig.transcribeModel : audioConfig.synthesizeModel);
|
|
539
544
|
if (!targetId)
|
|
540
545
|
return err(HaiAIError.AUDIO_MODEL_NOT_FOUND, aiM("ai_audioModelNotFound", { params: { model: `<${operation}>` } }));
|
|
@@ -548,7 +553,7 @@ function resolveAudioModel(audioConfig, operation, explicit) {
|
|
|
548
553
|
aiM("ai_audioUnsupportedInput", { params: { provider: entry.provider, reason: `model ${entry.id} does not support ${operation}` } })
|
|
549
554
|
);
|
|
550
555
|
}
|
|
551
|
-
const apiKey = entry.apiKey ?? audioProviderEnvApiKey(entry.provider);
|
|
556
|
+
const apiKey = entry.apiKey ?? (audioConfig.inheritLlmApiKey ? llmApiKey : void 0) ?? audioProviderEnvApiKey(entry.provider);
|
|
552
557
|
const hasDoubaoLegacy = Boolean(entry.appKey && entry.accessKey);
|
|
553
558
|
if (!apiKey && !(entry.provider === "doubao" && hasDoubaoLegacy))
|
|
554
559
|
return err(HaiAIError.CONFIGURATION_ERROR, aiM("ai_audioMissingApiKey", { params: { provider: entry.provider } }));
|
|
@@ -574,7 +579,7 @@ var ImageModelEntrySchema = z.object({
|
|
|
574
579
|
/** 厂商模型名 */
|
|
575
580
|
model: z.string(),
|
|
576
581
|
/** API Key 覆盖;未提供时回退厂商环境变量 */
|
|
577
|
-
apiKey:
|
|
582
|
+
apiKey: OptionalSecretSchema,
|
|
578
583
|
/** API 基础 URL 覆盖 */
|
|
579
584
|
baseUrl: z.url().optional(),
|
|
580
585
|
/** 阿里云百炼业务空间 ID(可选) */
|
|
@@ -671,6 +676,6 @@ var AudioWsTextMessageSchema = AudioWsTextMessageSchema$1;
|
|
|
671
676
|
var AudioWsDoneMessageSchema = AudioWsDoneMessageSchema$1;
|
|
672
677
|
var AudioWsClientMessageSchema = AudioWsClientMessageSchema$1;
|
|
673
678
|
|
|
674
|
-
export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, AUDIO_WS_PATH, ApiTypeSchema, AudioConfigSchema, AudioFormatSchema, AudioModelEntrySchema, AudioProviderSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, ImageConfigSchema, ImageModelEntrySchema, ImageProviderSchema, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, aiM, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry };
|
|
675
|
-
//# sourceMappingURL=chunk-
|
|
676
|
-
//# sourceMappingURL=chunk-
|
|
679
|
+
export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, AUDIO_WS_PATH, ApiTypeSchema, AudioConfigSchema, AudioFormatSchema, AudioModelEntrySchema, AudioProviderSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, ImageConfigSchema, ImageModelEntrySchema, ImageProviderSchema, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, OptionalSecretSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, aiM, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry };
|
|
680
|
+
//# sourceMappingURL=chunk-E3W2H6FL.js.map
|
|
681
|
+
//# sourceMappingURL=chunk-E3W2H6FL.js.map
|