@h-ai/ai 0.1.0-alpha.34 → 0.1.0-alpha.36
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 +158 -5
- package/dist/{ai-types-BZjo_rWW.d.ts → ai-audio-ws-protocol-CsmuWetO.d.ts} +438 -8
- package/dist/{ai-reasoning-types-Cm3-HVVN.d.ts → ai-reasoning-types-DLLzpn6T.d.ts} +480 -31
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +2 -2
- package/dist/{chunk-Y5BQR7QA.js → chunk-535CQURK.js} +249 -4
- package/dist/chunk-535CQURK.js.map +1 -0
- package/dist/{chunk-CXO3YSIG.js → chunk-UROBPUCF.js} +166 -4
- package/dist/chunk-UROBPUCF.js.map +1 -0
- package/dist/client/index.d.ts +56 -2
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +34 -4
- package/dist/index.js +2161 -718
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/dist/chunk-CXO3YSIG.js.map +0 -1
- package/dist/chunk-Y5BQR7QA.js.map +0 -1
|
@@ -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 { aF as ChatMessage, aQ as InteractionScope, O as MemoryType, bo as RagOptions, bs as ReasoningOptions, bV as ToolRegistryOperations, ba as MemoryEntry, bF as SessionInfo, b6 as LLMOperations, bg as MemoryOperations, bn as RagOperations, br as ReasoningOperations, c as AIConfig, d as AIConfigInput, au as AIStoreProvider, bW as ToolsOperations, bJ as StreamOperations, by as RetrievalOperations, b0 as KnowledgeOperations, ao as A2AOperations, q as AudioOperations, l as AudioFormat } from './ai-reasoning-types-DLLzpn6T.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { Buffer } from 'node:buffer';
|
|
6
6
|
|
|
@@ -177,6 +177,82 @@ interface ContextDeps {
|
|
|
177
177
|
rag?: RagOperations;
|
|
178
178
|
/** Reasoning 操作(推理引擎需要) */
|
|
179
179
|
reasoning?: ReasoningOperations;
|
|
180
|
+
/** Summary 操作(会话固化 consolidate 需要) */
|
|
181
|
+
summary?: SummaryOperations;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 会话固化选项(`ContextManager.consolidate` 使用)
|
|
185
|
+
*
|
|
186
|
+
* 把「短期会话记忆 + 摘要」固化为「长期记忆」,形成
|
|
187
|
+
* `Session Memory → Summary → Long-term Memory` 的生命周期闭环。
|
|
188
|
+
*/
|
|
189
|
+
interface ConsolidateOptions {
|
|
190
|
+
/**
|
|
191
|
+
* 长期记忆作用域。
|
|
192
|
+
*
|
|
193
|
+
* 默认使用管理器 `memory.scope`。通常应传入**不含 sessionId** 的作用域
|
|
194
|
+
* (如 `{ userId, personaId }`),使固化后的记忆跨会话持久,而非绑定单次会话。
|
|
195
|
+
*/
|
|
196
|
+
scope?: Record<string, unknown>;
|
|
197
|
+
/** 固化提取的记忆类型限制 */
|
|
198
|
+
types?: MemoryType[];
|
|
199
|
+
/** 摘要 / 提取使用的模型 */
|
|
200
|
+
model?: string;
|
|
201
|
+
/** 固化提取的自定义 systemPrompt */
|
|
202
|
+
extractionSystemPrompt?: string;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 会话固化结果
|
|
206
|
+
*/
|
|
207
|
+
interface ConsolidateResult {
|
|
208
|
+
/** 本次会话的整合摘要 */
|
|
209
|
+
summary: string;
|
|
210
|
+
/** 固化到长期记忆的条目 */
|
|
211
|
+
memories: MemoryEntry[];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 对话轮次状态
|
|
215
|
+
*
|
|
216
|
+
* 描述一次 assistant 生成从「模型产出」到「真实进入对话」的生命周期:
|
|
217
|
+
* - `generating` — 模型正在/已生成,但尚未确定实际对外表达的内容
|
|
218
|
+
* - `speaking` — 已进入下游表达(如 TTS 合成 / 播放)
|
|
219
|
+
* - `completed` — 已提交,完整生成文本即为真实文本
|
|
220
|
+
* - `interrupted` — 被打断,仅实际表达出去的部分(committed)进入对话
|
|
221
|
+
*/
|
|
222
|
+
type ConversationTurnStatus = 'generating' | 'speaking' | 'completed' | 'interrupted';
|
|
223
|
+
/**
|
|
224
|
+
* 对话轮次
|
|
225
|
+
*
|
|
226
|
+
* 区分「模型生成的文本」与「真实进入对话的文本」,解决多智能体 / 语音访谈等场景中
|
|
227
|
+
* 「AI 说到一半被打断,下一轮所有参与者应看到真实发生了什么」的问题。
|
|
228
|
+
*/
|
|
229
|
+
interface ConversationTurn {
|
|
230
|
+
/** 轮次唯一标识 */
|
|
231
|
+
id: string;
|
|
232
|
+
/** 发言者 */
|
|
233
|
+
speaker: 'user' | 'assistant';
|
|
234
|
+
/** 模型生成的完整文本 */
|
|
235
|
+
generated: string;
|
|
236
|
+
/** 实际提交进入上下文的文本(`completed` 时通常等于 generated;`interrupted` 时为真实表达部分) */
|
|
237
|
+
committed: string;
|
|
238
|
+
/** 轮次状态 */
|
|
239
|
+
status: ConversationTurnStatus;
|
|
240
|
+
/** 创建时间(Unix 毫秒) */
|
|
241
|
+
createdAt: number;
|
|
242
|
+
/** 提交时间(Unix 毫秒,未提交时为 undefined) */
|
|
243
|
+
committedAt?: number;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 提交 / 打断轮次的输入
|
|
247
|
+
*/
|
|
248
|
+
interface CommitTurnInput {
|
|
249
|
+
/**
|
|
250
|
+
* 实际进入对话的文本。
|
|
251
|
+
*
|
|
252
|
+
* - `commitTurn` 不传时默认使用模型生成的完整文本(generated)。
|
|
253
|
+
* - `interruptTurn` 不传时默认视为「未表达任何内容」(空串,不写入上下文)。
|
|
254
|
+
*/
|
|
255
|
+
text?: string;
|
|
180
256
|
}
|
|
181
257
|
/**
|
|
182
258
|
* 有状态上下文管理器配置
|
|
@@ -192,6 +268,17 @@ interface ContextManagerOptions {
|
|
|
192
268
|
model?: string;
|
|
193
269
|
/** 温度覆盖 */
|
|
194
270
|
temperature?: number;
|
|
271
|
+
/**
|
|
272
|
+
* 对话提交模式(默认 `auto`)
|
|
273
|
+
*
|
|
274
|
+
* - `auto`:`chat` / `chatStream` 生成结束后,自动把**模型生成的完整文本**写入上下文并触发记忆提取。
|
|
275
|
+
* - `manual`:生成结束后**不写入**上下文,仅登记一个待提交轮次并返回 `turnId`;由调用方在确定
|
|
276
|
+
* 「实际发生了什么」后,通过 `commitTurn` / `interruptTurn` 写入**真实文本**。
|
|
277
|
+
*
|
|
278
|
+
* 用于「模型生成 → TTS 合成 → 实际播放」链路:AI 说到一半被打断时,只有真正播放出去的
|
|
279
|
+
* 部分才应进入下一轮所有参与者可见的对话状态,而不是模型本想说完的全文。
|
|
280
|
+
*/
|
|
281
|
+
turnCommit?: 'auto' | 'manual';
|
|
195
282
|
/**
|
|
196
283
|
* 压缩配置(覆盖全局 compress 配置)
|
|
197
284
|
*
|
|
@@ -271,7 +358,7 @@ interface ContextChatOptions {
|
|
|
271
358
|
/**
|
|
272
359
|
* 请求取消信号
|
|
273
360
|
*
|
|
274
|
-
* 透传给底层 LLM
|
|
361
|
+
* 透传给底层 LLM 调用;打断、用户切换等场景可 `abortController.abort()`
|
|
275
362
|
* 立即停止上游生成与计费。
|
|
276
363
|
*/
|
|
277
364
|
signal?: AbortSignal;
|
|
@@ -284,6 +371,13 @@ interface ContextChatResult {
|
|
|
284
371
|
reply: string;
|
|
285
372
|
/** 使用的模型 */
|
|
286
373
|
model: string;
|
|
374
|
+
/**
|
|
375
|
+
* 本次生成对应的对话轮次 ID
|
|
376
|
+
*
|
|
377
|
+
* `turnCommit: 'manual'` 时,用于后续 `commitTurn` / `interruptTurn` 提交真实文本;
|
|
378
|
+
* `auto` 模式下该轮已自动提交(`completed`)。
|
|
379
|
+
*/
|
|
380
|
+
turnId: string;
|
|
287
381
|
/** Token 使用统计 */
|
|
288
382
|
usage?: {
|
|
289
383
|
prompt_tokens: number;
|
|
@@ -293,8 +387,15 @@ interface ContextChatResult {
|
|
|
293
387
|
}
|
|
294
388
|
/**
|
|
295
389
|
* chatStream() 产出的事件
|
|
390
|
+
*
|
|
391
|
+
* 事件序列:`turn_started` → `delta`* → `done`;中途取消(AbortSignal)时为
|
|
392
|
+
* `turn_started` → `delta`* → `cancelled`。`cancelled` 保留 turnId 与已生成文本,
|
|
393
|
+
* 调用方可用真实内容调用 `commitTurn` / `interruptTurn` 提交。
|
|
296
394
|
*/
|
|
297
395
|
type ContextStreamEvent = {
|
|
396
|
+
type: 'turn_started';
|
|
397
|
+
turnId: string;
|
|
398
|
+
} | {
|
|
298
399
|
type: 'delta';
|
|
299
400
|
text: string;
|
|
300
401
|
} | {
|
|
@@ -310,11 +411,16 @@ type ContextStreamEvent = {
|
|
|
310
411
|
type: 'done';
|
|
311
412
|
reply: string;
|
|
312
413
|
model: string;
|
|
414
|
+
turnId: string;
|
|
313
415
|
usage?: {
|
|
314
416
|
prompt_tokens: number;
|
|
315
417
|
completion_tokens: number;
|
|
316
418
|
total_tokens: number;
|
|
317
419
|
};
|
|
420
|
+
} | {
|
|
421
|
+
type: 'cancelled';
|
|
422
|
+
turnId: string;
|
|
423
|
+
generated: string;
|
|
318
424
|
};
|
|
319
425
|
/**
|
|
320
426
|
* 有状态上下文管理器接口
|
|
@@ -404,6 +510,57 @@ interface ContextManager {
|
|
|
404
510
|
* 重置管理器(清空所有消息和摘要)
|
|
405
511
|
*/
|
|
406
512
|
reset: () => void;
|
|
513
|
+
/**
|
|
514
|
+
* 获取对话轮次列表(Conversation Commit Layer)
|
|
515
|
+
*
|
|
516
|
+
* 记录每次 chat/chatStream 生成的轮次及其 `generated` / `committed` / `status`,
|
|
517
|
+
* 供应用侧观测「模型生成」与「真实进入对话」的差异。
|
|
518
|
+
*
|
|
519
|
+
* @returns 轮次列表(按发生顺序)
|
|
520
|
+
*/
|
|
521
|
+
getTurns: () => HaiResult<ConversationTurn[]>;
|
|
522
|
+
/**
|
|
523
|
+
* 标记某轮次进入「表达中」(如 TTS 开始播放)
|
|
524
|
+
*
|
|
525
|
+
* 仅更新状态用于观测,不改变上下文内容。
|
|
526
|
+
*
|
|
527
|
+
* @param turnId - 轮次 ID
|
|
528
|
+
* @returns 成功返回 ok(undefined);轮次不存在返回 CONTEXT_TURN_NOT_FOUND
|
|
529
|
+
*/
|
|
530
|
+
markTurnSpeaking: (turnId: string) => HaiResult<void>;
|
|
531
|
+
/**
|
|
532
|
+
* 提交轮次(`turnCommit: 'manual'` 场景)
|
|
533
|
+
*
|
|
534
|
+
* 把真实文本写入上下文并触发记忆提取;`text` 缺省时使用模型生成的完整文本。
|
|
535
|
+
* 提交后该轮 `status` 变为 `completed`。
|
|
536
|
+
*
|
|
537
|
+
* @param turnId - 轮次 ID
|
|
538
|
+
* @param input - 提交内容(可覆盖为真实表达文本)
|
|
539
|
+
* @returns 成功返回 ok(undefined);轮次不存在或已提交返回对应错误
|
|
540
|
+
*/
|
|
541
|
+
commitTurn: (turnId: string, input?: CommitTurnInput) => Promise<HaiResult<void>>;
|
|
542
|
+
/**
|
|
543
|
+
* 打断轮次(`turnCommit: 'manual'` 场景)
|
|
544
|
+
*
|
|
545
|
+
* 只把「实际表达出去的部分」写入上下文;`text` 缺省时视为未表达任何内容(不写入)。
|
|
546
|
+
* 打断后该轮 `status` 变为 `interrupted`。
|
|
547
|
+
*
|
|
548
|
+
* @param turnId - 轮次 ID
|
|
549
|
+
* @param input - 实际表达出去的文本
|
|
550
|
+
* @returns 成功返回 ok(undefined);轮次不存在或已提交返回对应错误
|
|
551
|
+
*/
|
|
552
|
+
interruptTurn: (turnId: string, input?: CommitTurnInput) => Promise<HaiResult<void>>;
|
|
553
|
+
/**
|
|
554
|
+
* 将当前会话固化为长期记忆(Memory 生命周期)
|
|
555
|
+
*
|
|
556
|
+
* 流程:整合会话摘要(历史摘要 + 当前消息)→ 从摘要中提取长期记忆 → 以持久作用域写入。
|
|
557
|
+
* 需要 deps.summary + deps.memory 可用。用于会话结束时把「短期会话记忆」沉淀为
|
|
558
|
+
* 「跨会话长期记忆」,形成 Session → Summary → Long-term Memory 闭环。
|
|
559
|
+
*
|
|
560
|
+
* @param options - 固化选项(长期作用域、类型、模型等)
|
|
561
|
+
* @returns 会话摘要与固化的记忆条目
|
|
562
|
+
*/
|
|
563
|
+
consolidate: (options?: ConsolidateOptions) => Promise<HaiResult<ConsolidateResult>>;
|
|
407
564
|
/**
|
|
408
565
|
* 发送消息并获取回复(需 deps.llm 可用)
|
|
409
566
|
*
|
|
@@ -417,7 +574,7 @@ interface ContextManager {
|
|
|
417
574
|
/**
|
|
418
575
|
* 流式发送消息并获取回复(需 deps.llm 可用)
|
|
419
576
|
*
|
|
420
|
-
* 产出事件序列:delta* → done
|
|
577
|
+
* 产出事件序列:turn_started → delta* → done(中途取消时 → cancelled)
|
|
421
578
|
*
|
|
422
579
|
* @param message - 用户消息文本
|
|
423
580
|
* @param options - 单次请求覆盖选项
|
|
@@ -476,18 +633,18 @@ interface ContextOperations {
|
|
|
476
633
|
/**
|
|
477
634
|
* 重命名会话
|
|
478
635
|
*
|
|
479
|
-
* @param
|
|
636
|
+
* @param scope - 交互作用域(objectId + sessionId,用于多租户隔离)
|
|
480
637
|
* @param title - 新标题
|
|
481
638
|
* @returns 成功返回 ok(undefined)
|
|
482
639
|
*/
|
|
483
|
-
renameSession: (
|
|
640
|
+
renameSession: (scope: InteractionScope, title: string) => Promise<HaiResult<void>>;
|
|
484
641
|
/**
|
|
485
642
|
* 删除会话(删除会话元数据和对应的上下文数据)
|
|
486
643
|
*
|
|
487
|
-
* @param
|
|
644
|
+
* @param scope - 交互作用域(objectId + sessionId,用于多租户隔离)
|
|
488
645
|
* @returns 成功返回 ok(undefined)
|
|
489
646
|
*/
|
|
490
|
-
removeSession: (
|
|
647
|
+
removeSession: (scope: InteractionScope) => Promise<HaiResult<void>>;
|
|
491
648
|
}
|
|
492
649
|
|
|
493
650
|
/**
|
|
@@ -841,6 +998,164 @@ interface AIMCPFunctionsDeps {
|
|
|
841
998
|
config: AIConfig;
|
|
842
999
|
}
|
|
843
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* @h-ai/ai — Persona 子功能类型
|
|
1003
|
+
*
|
|
1004
|
+
* 定义「AI 角色人格」的持久化与组合接口。Persona 解决的是「AI 是谁」的问题:
|
|
1005
|
+
* 多智能体场景(如多位专家同台访谈)中,每个 AI 有稳定的系统提示词、性格特征与
|
|
1006
|
+
* 长期人格。它与 Memory 正交——Memory 用 `objectId` / `scope` 回答「谁的记忆」,
|
|
1007
|
+
* Persona 回答「这个 AI 的身份与人设」,二者通过 `scope: { personaId }` 关联。
|
|
1008
|
+
* @module ai-persona-types
|
|
1009
|
+
*/
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* Persona 档案输入(创建 / 覆盖保存时使用)
|
|
1013
|
+
*
|
|
1014
|
+
* @example
|
|
1015
|
+
* ```ts
|
|
1016
|
+
* const input: PersonaProfileInput = {
|
|
1017
|
+
* id: 'xiaop',
|
|
1018
|
+
* name: '小P',
|
|
1019
|
+
* systemPrompt: '你是一位社会学家,善于从群体行为视角分析问题。',
|
|
1020
|
+
* traits: ['谨慎', '喜欢引用真实案例'],
|
|
1021
|
+
* }
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
interface PersonaProfileInput {
|
|
1025
|
+
/** 角色唯一标识(业务侧稳定 ID,如 `xiaop`) */
|
|
1026
|
+
id: string;
|
|
1027
|
+
/**
|
|
1028
|
+
* 所属主体 ID(多租户隔离)
|
|
1029
|
+
*
|
|
1030
|
+
* 不同主体可创建同名角色而互不覆盖;不传时归为平台内置角色 `system`。
|
|
1031
|
+
*/
|
|
1032
|
+
objectId?: string;
|
|
1033
|
+
/** 角色显示名(如「小P」) */
|
|
1034
|
+
name?: string;
|
|
1035
|
+
/** 角色系统提示词(定义身份、职责、语气) */
|
|
1036
|
+
systemPrompt: string;
|
|
1037
|
+
/** 性格 / 风格特征(组合进系统提示词,如「谨慎」「喜欢引用案例」) */
|
|
1038
|
+
traits?: string[];
|
|
1039
|
+
/** 附加元数据 */
|
|
1040
|
+
metadata?: Record<string, unknown>;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* 完整的 Persona 档案
|
|
1044
|
+
*/
|
|
1045
|
+
interface PersonaProfile {
|
|
1046
|
+
/** 角色唯一标识 */
|
|
1047
|
+
id: string;
|
|
1048
|
+
/** 所属主体 ID(多租户隔离;平台内置角色为 `system`) */
|
|
1049
|
+
objectId: string;
|
|
1050
|
+
/** 角色显示名 */
|
|
1051
|
+
name?: string;
|
|
1052
|
+
/** 角色系统提示词 */
|
|
1053
|
+
systemPrompt: string;
|
|
1054
|
+
/** 性格 / 风格特征 */
|
|
1055
|
+
traits: string[];
|
|
1056
|
+
/** 附加元数据 */
|
|
1057
|
+
metadata?: Record<string, unknown>;
|
|
1058
|
+
/** 创建时间(Unix 毫秒) */
|
|
1059
|
+
createdAt: number;
|
|
1060
|
+
/** 更新时间(Unix 毫秒) */
|
|
1061
|
+
updatedAt: number;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Persona 档案更新输入
|
|
1065
|
+
*
|
|
1066
|
+
* 所有字段可选,仅更新传入的字段。
|
|
1067
|
+
*/
|
|
1068
|
+
interface PersonaProfileUpdate {
|
|
1069
|
+
/** 更新显示名 */
|
|
1070
|
+
name?: string;
|
|
1071
|
+
/** 更新系统提示词 */
|
|
1072
|
+
systemPrompt?: string;
|
|
1073
|
+
/** 更新特征列表(整体替换) */
|
|
1074
|
+
traits?: string[];
|
|
1075
|
+
/** 更新元数据 */
|
|
1076
|
+
metadata?: Record<string, unknown>;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Persona 操作接口(通过 `ai.persona` 访问)
|
|
1080
|
+
*
|
|
1081
|
+
* 管理 AI 角色人格的持久化与系统提示词组合。需要先调用 `ai.init()` 初始化后使用。
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* ```ts
|
|
1085
|
+
* // 定义一个 AI 角色
|
|
1086
|
+
* await ai.persona.save({
|
|
1087
|
+
* id: 'xiaoq',
|
|
1088
|
+
* name: '小Q',
|
|
1089
|
+
* systemPrompt: '你是一位经济学家。',
|
|
1090
|
+
* traits: ['数据驱动', '偏好长期视角'],
|
|
1091
|
+
* })
|
|
1092
|
+
*
|
|
1093
|
+
* // 组合出可直接喂给 ContextManager 的系统提示词
|
|
1094
|
+
* const composed = await ai.persona.compose('xiaoq')
|
|
1095
|
+
* const manager = ai.context.createManager({
|
|
1096
|
+
* systemPrompt: composed.data,
|
|
1097
|
+
* // 该角色的长期记忆用 scope 关联
|
|
1098
|
+
* memory: { enable: true, enableExtract: true, scope: { personaId: 'xiaoq' } },
|
|
1099
|
+
* })
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
interface PersonaOperations {
|
|
1103
|
+
/**
|
|
1104
|
+
* 创建或覆盖保存一个角色档案(upsert 语义)
|
|
1105
|
+
*
|
|
1106
|
+
* @param profile - 角色档案输入
|
|
1107
|
+
* @returns 保存后的完整档案
|
|
1108
|
+
*/
|
|
1109
|
+
save: (profile: PersonaProfileInput) => Promise<HaiResult<PersonaProfile>>;
|
|
1110
|
+
/**
|
|
1111
|
+
* 按 ID 获取角色档案
|
|
1112
|
+
*
|
|
1113
|
+
* @param id - 角色 ID
|
|
1114
|
+
* @returns 角色档案,不存在时返回 PERSONA_NOT_FOUND
|
|
1115
|
+
*/
|
|
1116
|
+
get: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile>>;
|
|
1117
|
+
/**
|
|
1118
|
+
* 更新角色档案(仅更新传入字段)
|
|
1119
|
+
*
|
|
1120
|
+
* @param id - 角色 ID
|
|
1121
|
+
* @param updates - 需要更新的字段
|
|
1122
|
+
* @param options - 主体作用域(默认 `system`)
|
|
1123
|
+
* @returns 更新后的完整档案
|
|
1124
|
+
*/
|
|
1125
|
+
update: (id: string, updates: PersonaProfileUpdate, options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile>>;
|
|
1126
|
+
/**
|
|
1127
|
+
* 删除角色档案
|
|
1128
|
+
*
|
|
1129
|
+
* @param id - 角色 ID
|
|
1130
|
+
* @param options - 主体作用域(默认 `system`)
|
|
1131
|
+
* @returns 成功返回 ok(undefined)
|
|
1132
|
+
*/
|
|
1133
|
+
remove: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<void>>;
|
|
1134
|
+
/**
|
|
1135
|
+
* 列出指定主体的角色档案
|
|
1136
|
+
*
|
|
1137
|
+
* @param options - 主体作用域(默认 `system`)
|
|
1138
|
+
* @returns 角色档案列表
|
|
1139
|
+
*/
|
|
1140
|
+
list: (options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile[]>>;
|
|
1141
|
+
/**
|
|
1142
|
+
* 组合角色的完整系统提示词
|
|
1143
|
+
*
|
|
1144
|
+
* 将 `systemPrompt` 与 `traits` 拼装为一段可直接作为 system 消息的文本,
|
|
1145
|
+
* 供 `ai.context.createManager({ systemPrompt })` 使用。
|
|
1146
|
+
*
|
|
1147
|
+
* @param id - 角色 ID
|
|
1148
|
+
* @param options - 主体作用域(默认 `system`)
|
|
1149
|
+
* @returns 组合后的系统提示词,角色不存在时返回 PERSONA_NOT_FOUND
|
|
1150
|
+
*/
|
|
1151
|
+
compose: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<string>>;
|
|
1152
|
+
}
|
|
1153
|
+
/** Persona 操作的主体作用域选项 */
|
|
1154
|
+
interface PersonaScopeOptions {
|
|
1155
|
+
/** 所属主体 ID(不传时归为平台内置角色 `system`) */
|
|
1156
|
+
objectId?: string;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
844
1159
|
/**
|
|
845
1160
|
* @h-ai/ai — Rerank 子功能类型
|
|
846
1161
|
*
|
|
@@ -1030,14 +1345,29 @@ declare const HaiAIError: {
|
|
|
1030
1345
|
readonly MEMORY_RECALL_FAILED: _h_ai_core.HaiErrorDef;
|
|
1031
1346
|
readonly MEMORY_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
1032
1347
|
readonly MEMORY_ENRICH_FAILED: _h_ai_core.HaiErrorDef;
|
|
1348
|
+
readonly MEMORY_PROMOTE_FAILED: _h_ai_core.HaiErrorDef;
|
|
1349
|
+
readonly PERSONA_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
1350
|
+
readonly PERSONA_SAVE_FAILED: _h_ai_core.HaiErrorDef;
|
|
1033
1351
|
readonly FILE_PARSE_FAILED: _h_ai_core.HaiErrorDef;
|
|
1034
1352
|
readonly FILE_UNSUPPORTED_FORMAT: _h_ai_core.HaiErrorDef;
|
|
1035
1353
|
readonly FILE_OCR_FAILED: _h_ai_core.HaiErrorDef;
|
|
1036
1354
|
readonly FILE_INVALID_CONTENT: _h_ai_core.HaiErrorDef;
|
|
1355
|
+
readonly AUDIO_INVALID_REQUEST: _h_ai_core.HaiErrorDef;
|
|
1356
|
+
readonly AUDIO_MODEL_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
1357
|
+
readonly AUDIO_PROVIDER_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
1358
|
+
readonly AUDIO_UNSUPPORTED_INPUT: _h_ai_core.HaiErrorDef;
|
|
1359
|
+
readonly AUDIO_UPSTREAM_ERROR: _h_ai_core.HaiErrorDef;
|
|
1360
|
+
readonly AUDIO_PROTOCOL_ERROR: _h_ai_core.HaiErrorDef;
|
|
1361
|
+
readonly AUDIO_CONNECTION_FAILED: _h_ai_core.HaiErrorDef;
|
|
1362
|
+
readonly AUDIO_TIMEOUT: _h_ai_core.HaiErrorDef;
|
|
1363
|
+
readonly AUDIO_INPUT_TOO_LARGE: _h_ai_core.HaiErrorDef;
|
|
1364
|
+
readonly AUDIO_CANCELLED: _h_ai_core.HaiErrorDef;
|
|
1037
1365
|
readonly CONTEXT_COMPRESS_FAILED: _h_ai_core.HaiErrorDef;
|
|
1038
1366
|
readonly CONTEXT_SUMMARIZE_FAILED: _h_ai_core.HaiErrorDef;
|
|
1039
1367
|
readonly CONTEXT_TOKEN_ESTIMATE_FAILED: _h_ai_core.HaiErrorDef;
|
|
1040
1368
|
readonly CONTEXT_BUDGET_EXCEEDED: _h_ai_core.HaiErrorDef;
|
|
1369
|
+
readonly CONTEXT_TURN_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
1370
|
+
readonly CONTEXT_TURN_INVALID_STATE: _h_ai_core.HaiErrorDef;
|
|
1041
1371
|
readonly STORE_FAILED: _h_ai_core.HaiErrorDef;
|
|
1042
1372
|
readonly STORE_NOT_AVAILABLE: _h_ai_core.HaiErrorDef;
|
|
1043
1373
|
readonly SESSION_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
@@ -1121,6 +1451,8 @@ interface AIFunctions {
|
|
|
1121
1451
|
readonly knowledge: KnowledgeOperations;
|
|
1122
1452
|
/** Memory 操作(记忆提取、存储、检索、注入),需要先调用 `init()` */
|
|
1123
1453
|
readonly memory: MemoryOperations;
|
|
1454
|
+
/** Persona 操作(AI 角色人格档案与系统提示词组合),需要先调用 `init()` */
|
|
1455
|
+
readonly persona: PersonaOperations;
|
|
1124
1456
|
/** Token 操作(Token 估算),需要先调用 `init()` */
|
|
1125
1457
|
readonly token: TokenOperations;
|
|
1126
1458
|
/** Summary 操作(消息摘要生成),需要先调用 `init()` */
|
|
@@ -1135,6 +1467,104 @@ interface AIFunctions {
|
|
|
1135
1467
|
readonly file: FileOperations;
|
|
1136
1468
|
/** A2A 操作(Agent-to-Agent 协议),需要先调用 `init()` 并配置 `a2a` */
|
|
1137
1469
|
readonly a2a: A2AOperations;
|
|
1470
|
+
/** Audio 操作(语音识别 / 语音合成),需要先调用 `init()` 并配置 `audio` */
|
|
1471
|
+
readonly audio: AudioOperations;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* @h-ai/ai — 统一语音 WebSocket 协议
|
|
1476
|
+
*
|
|
1477
|
+
* 定义浏览器 / 远程客户端与 `@h-ai/serv` 语音入口之间的统一 WebSocket 消息协议。
|
|
1478
|
+
* 客户端与服务端共享此协议,客户端不接收任何厂商原生事件;音频以二进制帧传输,
|
|
1479
|
+
* 控制与文本以 JSON 帧传输。
|
|
1480
|
+
* @module audio/ai-audio-ws-protocol
|
|
1481
|
+
*/
|
|
1482
|
+
|
|
1483
|
+
/** 统一语音入口的默认路径(相对 API 前缀) */
|
|
1484
|
+
declare const AUDIO_WS_PATH = "/ai/audio";
|
|
1485
|
+
/**
|
|
1486
|
+
* 会话起始消息(客户端首个 JSON 帧)
|
|
1487
|
+
*
|
|
1488
|
+
* 表达本次语音操作:识别或合成,及可选的模型 / 语言 / 音色 / 格式等参数。
|
|
1489
|
+
*/
|
|
1490
|
+
interface AudioWsStartMessage {
|
|
1491
|
+
type: 'start';
|
|
1492
|
+
/** 操作类型 */
|
|
1493
|
+
operation: 'transcribe' | 'synthesize';
|
|
1494
|
+
/**
|
|
1495
|
+
* 是否流式返回增量结果
|
|
1496
|
+
*
|
|
1497
|
+
* 识别操作:`true` 时服务端桥接为持续音频输入并流式返回临时结果;
|
|
1498
|
+
* `false`(默认)时服务端缓冲完整音频后返回单条最终结果。
|
|
1499
|
+
*/
|
|
1500
|
+
stream?: boolean;
|
|
1501
|
+
/** 模型 ID(不传时使用服务端默认模型) */
|
|
1502
|
+
model?: string;
|
|
1503
|
+
/** 识别语言提示 */
|
|
1504
|
+
language?: string;
|
|
1505
|
+
/** 领域提示词 / 热词(识别) */
|
|
1506
|
+
contextHints?: string[];
|
|
1507
|
+
/** 合成音色 */
|
|
1508
|
+
voice?: string;
|
|
1509
|
+
/** 合成自然语言风格指令 */
|
|
1510
|
+
instruction?: string;
|
|
1511
|
+
/** 音频格式(识别时为输入格式,合成时为输出格式) */
|
|
1512
|
+
format?: AudioFormat;
|
|
1513
|
+
/** 采样率 */
|
|
1514
|
+
sampleRate?: number;
|
|
1515
|
+
/** 声道数 */
|
|
1516
|
+
channels?: 1 | 2;
|
|
1517
|
+
}
|
|
1518
|
+
/** 文本输入帧(合成操作时携带待合成文本) */
|
|
1519
|
+
interface AudioWsTextMessage {
|
|
1520
|
+
type: 'text';
|
|
1521
|
+
/** 调用方分配的稳定文本段 ID */
|
|
1522
|
+
segmentId: string;
|
|
1523
|
+
/** 待合成文本片段 */
|
|
1524
|
+
text: string;
|
|
1525
|
+
}
|
|
1526
|
+
/** 输入结束帧(音频 / 文本输入全部发送完毕) */
|
|
1527
|
+
interface AudioWsDoneMessage {
|
|
1528
|
+
type: 'done';
|
|
1529
|
+
}
|
|
1530
|
+
/** 客户端 JSON 控制消息(音频输入以二进制帧发送,不走 JSON) */
|
|
1531
|
+
type AudioWsClientMessage = AudioWsStartMessage | AudioWsTextMessage | AudioWsDoneMessage;
|
|
1532
|
+
/** 语音起止事件(识别操作时服务端 VAD 检测到语音开始 / 结束) */
|
|
1533
|
+
interface AudioWsSpeechMessage {
|
|
1534
|
+
type: 'speech_started' | 'speech_stopped';
|
|
1535
|
+
}
|
|
1536
|
+
/** 识别结果帧(识别操作时返回当前语句的完整文本) */
|
|
1537
|
+
interface AudioWsTranscriptMessage {
|
|
1538
|
+
type: 'transcript';
|
|
1539
|
+
/** 当前语句的完整识别文本 */
|
|
1540
|
+
text: string;
|
|
1541
|
+
/** 是否为该语句的最终结果 */
|
|
1542
|
+
final: boolean;
|
|
1543
|
+
}
|
|
1544
|
+
/** 合成文本段开始;后续二进制帧均属于该段,直到收到对应的 `segment_done`。 */
|
|
1545
|
+
interface AudioWsSegmentStartedMessage {
|
|
1546
|
+
type: 'segment_started';
|
|
1547
|
+
segmentId: string;
|
|
1548
|
+
text: string;
|
|
1549
|
+
}
|
|
1550
|
+
/** 合成文本段的音频已全部发送。 */
|
|
1551
|
+
interface AudioWsSegmentDoneMessage {
|
|
1552
|
+
type: 'segment_done';
|
|
1553
|
+
segmentId: string;
|
|
1554
|
+
}
|
|
1555
|
+
/** 错误帧(领域语义错误码,不暴露厂商协议细节) */
|
|
1556
|
+
interface AudioWsErrorMessage {
|
|
1557
|
+
type: 'error';
|
|
1558
|
+
/** 领域错误码(如 `hai:ai:054`) */
|
|
1559
|
+
code: string;
|
|
1560
|
+
/** 错误消息 */
|
|
1561
|
+
message: string;
|
|
1562
|
+
}
|
|
1563
|
+
/** 结束帧(服务端已发送全部结果,随后关闭连接) */
|
|
1564
|
+
interface AudioWsEndMessage {
|
|
1565
|
+
type: 'end';
|
|
1138
1566
|
}
|
|
1567
|
+
/** 服务端 JSON 消息(合成音频以二进制帧返回,不走 JSON) */
|
|
1568
|
+
type AudioWsServerMessage = AudioWsSpeechMessage | AudioWsTranscriptMessage | AudioWsSegmentStartedMessage | AudioWsSegmentDoneMessage | AudioWsErrorMessage | AudioWsEndMessage;
|
|
1139
1569
|
|
|
1140
|
-
export { type AIFunctions as A, type
|
|
1570
|
+
export { type MCPToolDefinition as $, type AIFunctions as A, type ContextOperations as B, type CompressionStrategy as C, type ContextStreamEvent as D, type ConversationTurn as E, type ConversationTurnStatus as F, type EmbeddingItem as G, HaiAIError as H, type EmbeddingOperations as I, type EmbeddingProvider as J, type EmbeddingRequest as K, type EmbeddingResponse as L, type McpServerOptions as M, type FileOperations as N, type FileParseMethod as O, type FileParseOptions as P, type FileParseRequest as Q, type FileParseResult as R, type MCPContext as S, type MCPOperations as T, type MCPPrompt as U, type MCPPromptArgument as V, type MCPPromptContent as W, type MCPPromptMessage as X, type MCPProvider as Y, type MCPResource as Z, type MCPResourceContent as _, type AIInitOptions as a, type MCPToolHandler as a0, type OutputFormat as a1, type PersonaOperations as a2, type PersonaProfile as a3, type PersonaProfileInput as a4, type PersonaProfileUpdate as a5, type PersonaScopeOptions as a6, type RerankDocument as a7, type RerankItem as a8, type RerankOperations as a9, type RerankRequest as aa, type RerankResponse as ab, type SummaryOperations as ac, type SummaryOptions as ad, type SummaryResult as ae, type TokenOperations as af, AUDIO_WS_PATH as b, type AudioWsClientMessage as c, type AudioWsDoneMessage as d, type AudioWsEndMessage as e, type AudioWsErrorMessage as f, type AudioWsSegmentDoneMessage as g, type AudioWsSegmentStartedMessage as h, type AudioWsServerMessage as i, type AudioWsSpeechMessage as j, type AudioWsStartMessage as k, type AudioWsTextMessage as l, type AudioWsTranscriptMessage as m, CompressionStrategySchema as n, type AIMCPFunctionsDeps as o, type CommitTurnInput as p, type CompressOperations as q, type CompressOptions as r, type CompressResult as s, type ConsolidateOptions as t, type ConsolidateResult as u, type ContextChatOptions as v, type ContextChatResult as w, type ContextDeps as x, type ContextManager as y, type ContextManagerOptions as z };
|