@ray-js/t-agent-plugin-aistream 0.2.6 → 0.2.7-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-zh_CN.md +60 -2
- package/README.md +60 -2
- package/dist/AIStreamTypes.d.ts +53 -35
- package/dist/AIStreamTypes.js +1 -2
- package/dist/asr/AsrAgent.js +6 -3
- package/dist/asr/createAsrAgent.js +4 -0
- package/dist/buildIn/withBuildIn.js +14 -8
- package/dist/utils/AIStream.d.ts +8 -15
- package/dist/utils/AIStream.js +30 -45
- package/dist/utils/defaultMock.js +21 -17
- package/dist/utils/mock.d.ts +2 -3
- package/dist/utils/mock.js +2 -1
- package/dist/utils/object.d.ts +1 -0
- package/dist/utils/object.js +24 -1
- package/dist/utils/sendMessage.d.ts +4 -4
- package/dist/utils/sendMessage.js +20 -9
- package/dist/utils/track.d.ts +1 -0
- package/dist/utils/track.js +29 -0
- package/dist/utils/ttt.d.ts +3 -1
- package/dist/utils/ttt.js +4 -1
- package/dist/withAIStream.d.ts +11 -5
- package/dist/withAIStream.js +40 -9
- package/package.json +2 -2
package/README-zh_CN.md
CHANGED
|
@@ -771,6 +771,7 @@ const createAgent = () => {
|
|
|
771
771
|
- `indexId` 索引 ID,默认为 'default'
|
|
772
772
|
- `homeId` 家庭 ID,不填默认当前家庭
|
|
773
773
|
- `earlyStart` 是否在 onAgentStart 阶段就建立连接
|
|
774
|
+
- `eventIdPrefix` eventId 前缀,用于方便云端调试和日志追踪
|
|
774
775
|
- `tokenOptions` 获取 agent token 的参数
|
|
775
776
|
- `api` API 接口名
|
|
776
777
|
- `version` 接口版本
|
|
@@ -779,14 +780,30 @@ const createAgent = () => {
|
|
|
779
780
|
|
|
780
781
|
方法:
|
|
781
782
|
|
|
782
|
-
- `agent.plugins.aiStream.send` 向智能体发送一条消息
|
|
783
|
-
- `
|
|
783
|
+
- `agent.plugins.aiStream.send(blocks, signal, userData)` 向智能体发送一条消息
|
|
784
|
+
- `blocks` 输入块数组
|
|
785
|
+
- `signal` 可选的 AbortSignal,用于中断请求
|
|
786
|
+
- `userData` 可选的用户数据,会附带在发送的消息中
|
|
787
|
+
- `agent.plugins.aiStream.chat(blocks, signal, options)` 向智能体发送一条消息,并生成提问 ChatMessage 对象和 AI 回答 ChatMessage 对象,流式更新
|
|
788
|
+
- `blocks` 输入块数组
|
|
789
|
+
- `signal` 可选的 AbortSignal
|
|
790
|
+
- `options.sendBy` 发送者角色,默认为 'user'
|
|
791
|
+
- `options.responseBy` 响应者角色,默认为 'assistant'
|
|
792
|
+
- `options.userData` 可选的用户数据
|
|
793
|
+
- `agent.plugins.aiStream.getChatId()` 获取当前会话的 chatId,返回 Promise<string>
|
|
784
794
|
|
|
785
795
|
Hooks:
|
|
786
796
|
|
|
787
797
|
- `onMessageParse` 当读取历史消息,解析消息时触发,可以在这个 Hook 里修改消息
|
|
788
798
|
- `msgItem` 存储的消息对象
|
|
789
799
|
- `result.messages` 解析后的消息列表
|
|
800
|
+
- `onChatMessageSent` 当用户消息和响应消息创建后触发
|
|
801
|
+
- `userMessage` 用户发送的消息
|
|
802
|
+
- `respMessage` AI 的响应消息
|
|
803
|
+
- `onTextCompose` 当收到文本数据时触发,用于处理文本的渲染
|
|
804
|
+
- `respMsg` 响应消息
|
|
805
|
+
- `status` 消息状态
|
|
806
|
+
- `result.text` 文本内容,可以修改
|
|
790
807
|
- `onSkillCompose` 当收到技能数据时触发,用于处理技能的渲染
|
|
791
808
|
- `skill` 技能数据数组 (ReceivedTextSkillPacketBody[])
|
|
792
809
|
- `respMsg` 响应消息
|
|
@@ -801,6 +818,47 @@ Hooks:
|
|
|
801
818
|
- `onCardsReceived` 当收到卡片数据时触发
|
|
802
819
|
- `skills` 技能数据列表 (ReceivedTextSkillPacketBody[])
|
|
803
820
|
- `result.cards` 卡片列表
|
|
821
|
+
- `onUserDataRead` **(0.2.x 新增)** 当需要读取用户自定义数据时触发,用于向 AI 平台传递额外的上下文信息
|
|
822
|
+
- `type` 触发类型,可以是 'create-session' 或 'start-event'
|
|
823
|
+
- `'create-session'` 创建会话时触发,只触发一次
|
|
824
|
+
- `'start-event'` 每次发送消息时触发
|
|
825
|
+
- `data` 上下文数据
|
|
826
|
+
- `data.blocks` 当 type 为 'start-event' 时,包含本次发送的输入块
|
|
827
|
+
- `result.userData` 返回的用户数据对象,会被合并后发送给 AI 平台
|
|
828
|
+
|
|
829
|
+
**使用示例**:
|
|
830
|
+
|
|
831
|
+
```tsx
|
|
832
|
+
const agent = createChatAgent(
|
|
833
|
+
withUI(),
|
|
834
|
+
withAIStream({
|
|
835
|
+
agentId: 'your-agent-id',
|
|
836
|
+
})
|
|
837
|
+
);
|
|
838
|
+
|
|
839
|
+
agent.plugins.aiStream.onUserDataRead((type, data, result) => {
|
|
840
|
+
// 在创建会话时传递用户信息
|
|
841
|
+
if (type === 'create-session') {
|
|
842
|
+
result.sessionAttributes = {
|
|
843
|
+
'custom.param': {
|
|
844
|
+
userName: { value: 'John' },
|
|
845
|
+
userLevel: { value: 'Plus' },
|
|
846
|
+
},
|
|
847
|
+
};
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
// 在每次发送消息时传递动态上下文
|
|
851
|
+
if (type === 'start-event') {
|
|
852
|
+
result.userData = {
|
|
853
|
+
'custom.param': {
|
|
854
|
+
timestamp: { value: Date.now() },
|
|
855
|
+
pid: { value: '123456' },
|
|
856
|
+
},
|
|
857
|
+
};
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
```
|
|
804
862
|
|
|
805
863
|
### withBuildIn 插件
|
|
806
864
|
|
package/README.md
CHANGED
|
@@ -766,6 +766,7 @@ Parameters:
|
|
|
766
766
|
- `indexId` Index ID, defaults to 'default'
|
|
767
767
|
- `homeId` Home ID, defaults to current home if not provided
|
|
768
768
|
- `earlyStart` Whether to establish connection during onAgentStart phase
|
|
769
|
+
- `eventIdPrefix` Event ID prefix for cloud debugging and log tracing
|
|
769
770
|
- `tokenOptions` Parameters for getting agent token
|
|
770
771
|
- `api` API interface name
|
|
771
772
|
- `version` Interface version
|
|
@@ -774,14 +775,30 @@ Parameters:
|
|
|
774
775
|
|
|
775
776
|
Methods:
|
|
776
777
|
|
|
777
|
-
- `agent.plugins.aiStream.send
|
|
778
|
-
- `
|
|
778
|
+
- `agent.plugins.aiStream.send(blocks, signal, userData)` Send a message to the agent
|
|
779
|
+
- `blocks` Input block array
|
|
780
|
+
- `signal` Optional AbortSignal for interrupting requests
|
|
781
|
+
- `userData` Optional user data to be included with the message
|
|
782
|
+
- `agent.plugins.aiStream.chat(blocks, signal, options)` Send a message to the agent while generating a ChatMessage object for the question and the AI's answer, updating in a streaming manner
|
|
783
|
+
- `blocks` Input block array
|
|
784
|
+
- `signal` Optional AbortSignal
|
|
785
|
+
- `options.sendBy` Sender role, defaults to 'user'
|
|
786
|
+
- `options.responseBy` Responder role, defaults to 'assistant'
|
|
787
|
+
- `options.userData` Optional user data
|
|
788
|
+
- `agent.plugins.aiStream.getChatId()` Get the current session's chatId, returns Promise<string>
|
|
779
789
|
|
|
780
790
|
Hooks:
|
|
781
791
|
|
|
782
792
|
- `onMessageParse` Triggered when reading history messages and parsing them, allowing for message modification in this Hook
|
|
783
793
|
- `msgItem` Stored message object
|
|
784
794
|
- `result.messages` Parsed message list
|
|
795
|
+
- `onChatMessageSent` Triggered after user message and response message are created
|
|
796
|
+
- `userMessage` User's sent message
|
|
797
|
+
- `respMessage` AI's response message
|
|
798
|
+
- `onTextCompose` Triggered when receiving text data, used for handling text rendering
|
|
799
|
+
- `respMsg` Response message
|
|
800
|
+
- `status` Message status
|
|
801
|
+
- `result.text` Text content, can be modified
|
|
785
802
|
- `onSkillCompose` Triggered when receiving skill data, used for handling skill rendering
|
|
786
803
|
- `skill` Skill data array (ReceivedTextSkillPacketBody[])
|
|
787
804
|
- `respMsg` Response message
|
|
@@ -796,6 +813,47 @@ Hooks:
|
|
|
796
813
|
- `onCardsReceived` Triggered when receiving card data
|
|
797
814
|
- `skills` Skill data list (ReceivedTextSkillPacketBody[])
|
|
798
815
|
- `result.cards` Card list
|
|
816
|
+
- `onUserDataRead` **(0.2.x New)** Triggered when user custom data needs to be read, used to pass additional context information to the AI platform
|
|
817
|
+
- `type` Trigger type, can be 'create-session' or 'start-event'
|
|
818
|
+
- `'create-session'` Triggered when creating a session, only once
|
|
819
|
+
- `'start-event'` Triggered each time a message is sent
|
|
820
|
+
- `data` Context data
|
|
821
|
+
- `data.blocks` When type is 'start-event', contains the input blocks for this send
|
|
822
|
+
- `result.userData` Returned user data object, will be merged and sent to the AI platform
|
|
823
|
+
|
|
824
|
+
**Usage Example**:
|
|
825
|
+
|
|
826
|
+
```tsx
|
|
827
|
+
const agent = createChatAgent(
|
|
828
|
+
withUI(),
|
|
829
|
+
withAIStream({
|
|
830
|
+
agentId: 'your-agent-id',
|
|
831
|
+
})
|
|
832
|
+
);
|
|
833
|
+
|
|
834
|
+
agent.plugins.aiStream.onUserDataRead((type, data, result) => {
|
|
835
|
+
// Pass user information when creating a session
|
|
836
|
+
if (type === 'create-session') {
|
|
837
|
+
result.sessionAttributes = {
|
|
838
|
+
'custom.param': {
|
|
839
|
+
userName: { value: 'John' },
|
|
840
|
+
userLevel: { value: 'Plus' },
|
|
841
|
+
},
|
|
842
|
+
};
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
// Pass dynamic context each time a message is sent
|
|
846
|
+
if (type === 'start-event') {
|
|
847
|
+
result.userData = {
|
|
848
|
+
'custom.param': {
|
|
849
|
+
timestamp: { value: Date.now() },
|
|
850
|
+
pid: { value: '123456' },
|
|
851
|
+
},
|
|
852
|
+
};
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
```
|
|
799
857
|
|
|
800
858
|
### withBuildIn Plugin
|
|
801
859
|
|
package/dist/AIStreamTypes.d.ts
CHANGED
|
@@ -216,6 +216,23 @@ export type MiniProgramAccountInfo = {
|
|
|
216
216
|
/** 小程序图标 */
|
|
217
217
|
appIcon: string;
|
|
218
218
|
};
|
|
219
|
+
export interface CustomParamItem {
|
|
220
|
+
value: any;
|
|
221
|
+
/** 生效次数,不传一直生效 */
|
|
222
|
+
effectiveCount?: number;
|
|
223
|
+
}
|
|
224
|
+
export type AIStreamUserData = {
|
|
225
|
+
sessionAttributes?: {
|
|
226
|
+
'custom.param'?: Record<string, CustomParamItem>;
|
|
227
|
+
[key: string]: any;
|
|
228
|
+
};
|
|
229
|
+
eventAttributes?: {
|
|
230
|
+
'custom.param'?: Record<string, CustomParamItem>;
|
|
231
|
+
[key: string]: any;
|
|
232
|
+
};
|
|
233
|
+
chatAttributes?: AIStreamChatAttribute;
|
|
234
|
+
[key: string]: any;
|
|
235
|
+
};
|
|
219
236
|
/**
|
|
220
237
|
* 获取小程序账号信息
|
|
221
238
|
*/
|
|
@@ -630,9 +647,7 @@ export declare enum EventType {
|
|
|
630
647
|
/** 聊天中断 */
|
|
631
648
|
CHAT_BREAK = 4,
|
|
632
649
|
/** 服务端 VAD */
|
|
633
|
-
SERVER_VAD = 5
|
|
634
|
-
/** 服务端错误 */
|
|
635
|
-
SERVER_ERROR = 6
|
|
650
|
+
SERVER_VAD = 5
|
|
636
651
|
}
|
|
637
652
|
export declare enum StreamFlag {
|
|
638
653
|
/** 仅一包 */
|
|
@@ -821,8 +836,6 @@ export type EventBody = {
|
|
|
821
836
|
sessionId: string;
|
|
822
837
|
/** 事件类型: 0-Event Start, 1-Event Payload End, 2-Event End, 3 - OneShot, 4-Chat Break, 5-Server VAD */
|
|
823
838
|
eventType: EventType;
|
|
824
|
-
/** 属性列表 */
|
|
825
|
-
userData?: Attribute[];
|
|
826
839
|
};
|
|
827
840
|
export type AudioBody = {
|
|
828
841
|
/** 接收数据通道 Code */
|
|
@@ -831,8 +844,6 @@ export type AudioBody = {
|
|
|
831
844
|
streamFlag: number;
|
|
832
845
|
/** 音频缓存路径 */
|
|
833
846
|
path: string;
|
|
834
|
-
/** 扩展属性 */
|
|
835
|
-
userData?: Attribute[];
|
|
836
847
|
/** SessionId 列表, 云端返回,可能为空 */
|
|
837
848
|
sessionIdList?: string[];
|
|
838
849
|
/**
|
|
@@ -945,8 +956,6 @@ export type VideoBody = {
|
|
|
945
956
|
streamFlag: StreamFlag;
|
|
946
957
|
/** 视频缓存路径,传输结束后可访问(streamFlag == 1 || StreamFlag == 3) */
|
|
947
958
|
path: string;
|
|
948
|
-
/** 扩展属性 */
|
|
949
|
-
userData?: Attribute[];
|
|
950
959
|
/** SessionId 列表, 云端返回,可能为空 */
|
|
951
960
|
sessionIdList?: string[];
|
|
952
961
|
};
|
|
@@ -961,8 +970,6 @@ export type ImageBody = {
|
|
|
961
970
|
width: number;
|
|
962
971
|
/** 图片高度 */
|
|
963
972
|
height: number;
|
|
964
|
-
/** 扩展属性 */
|
|
965
|
-
userData?: Attribute[];
|
|
966
973
|
/** SessionId 列表, 云端返回,可能为空 */
|
|
967
974
|
sessionIdList?: string[];
|
|
968
975
|
};
|
|
@@ -973,8 +980,6 @@ export type TextBody = {
|
|
|
973
980
|
streamFlag: StreamFlag;
|
|
974
981
|
/** 文本内容(JSON String,见云端文档定义) */
|
|
975
982
|
text: string;
|
|
976
|
-
/** 扩展属性 */
|
|
977
|
-
userData?: Attribute[];
|
|
978
983
|
/** SessionId 列表, 云端返回,可能为空 */
|
|
979
984
|
sessionIdList?: string[];
|
|
980
985
|
};
|
|
@@ -987,8 +992,6 @@ export type FileBody = {
|
|
|
987
992
|
path: string;
|
|
988
993
|
/** 文件类型: 1 - MP4, 2 - OGG_OPUS, 3 - PDF, 4 - JSON, 5 - IPC_LOG, 6 - SweeperMap */
|
|
989
994
|
format: FileFormat;
|
|
990
|
-
/** 扩展属性 */
|
|
991
|
-
userData?: Attribute[];
|
|
992
995
|
/** SessionId 列表, 云端返回,可能为空 */
|
|
993
996
|
sessionIdList?: string[];
|
|
994
997
|
};
|
|
@@ -1037,6 +1040,22 @@ export type GetNetworkTypeParams = {
|
|
|
1037
1040
|
};
|
|
1038
1041
|
}) => void;
|
|
1039
1042
|
};
|
|
1043
|
+
export type EventParams = {
|
|
1044
|
+
/** 事件id */
|
|
1045
|
+
eventId: string;
|
|
1046
|
+
/** 事件点对象 */
|
|
1047
|
+
event: Record<string, any>;
|
|
1048
|
+
complete?: () => void;
|
|
1049
|
+
success?: (params: null) => void;
|
|
1050
|
+
fail?: (params: {
|
|
1051
|
+
errorMsg: string;
|
|
1052
|
+
errorCode: string | number;
|
|
1053
|
+
innerError: {
|
|
1054
|
+
errorCode: string | number;
|
|
1055
|
+
errorMsg: string;
|
|
1056
|
+
};
|
|
1057
|
+
}) => void;
|
|
1058
|
+
};
|
|
1040
1059
|
export type CheckConnectParams = {
|
|
1041
1060
|
/** client 类型: 1-作为设备代理, 2-作为 App */
|
|
1042
1061
|
clientType: ConnectClientType;
|
|
@@ -1142,8 +1161,13 @@ export type CreateSessionParams = {
|
|
|
1142
1161
|
sessionId?: string;
|
|
1143
1162
|
/** 业务配置定义(通过 queryAgentToken 传递) */
|
|
1144
1163
|
bizConfig: BizConfig;
|
|
1145
|
-
/**
|
|
1164
|
+
/**
|
|
1165
|
+
* 扩展属性
|
|
1166
|
+
* @deprecated
|
|
1167
|
+
*/
|
|
1146
1168
|
userData?: Attribute[];
|
|
1169
|
+
/** 扩展属性 */
|
|
1170
|
+
userDataJson?: string;
|
|
1147
1171
|
/** 是否复用数据通道,默认不复用 */
|
|
1148
1172
|
reuseDataChannel?: boolean;
|
|
1149
1173
|
success?: (params: {
|
|
@@ -1211,8 +1235,13 @@ export type SendEventStartParams = {
|
|
|
1211
1235
|
/** 会话 id */
|
|
1212
1236
|
sessionId: string;
|
|
1213
1237
|
eventIdPrefix?: string;
|
|
1214
|
-
/**
|
|
1238
|
+
/**
|
|
1239
|
+
* 扩展属性
|
|
1240
|
+
* @deprecated
|
|
1241
|
+
*/
|
|
1215
1242
|
userData?: Attribute[];
|
|
1243
|
+
/** 扩展属性 */
|
|
1244
|
+
userDataJson?: string;
|
|
1216
1245
|
success?: (params: {
|
|
1217
1246
|
/** 事件 id。此后 sendEventPayloadEnd、sendEventEnd、sendEventChatBreak 都需要使用该 eventId 直到下发一次 sendEventStart 生成新 eventId 之前。 */
|
|
1218
1247
|
eventId: string;
|
|
@@ -1228,7 +1257,7 @@ export type SendEventStartParams = {
|
|
|
1228
1257
|
complete?: () => void;
|
|
1229
1258
|
};
|
|
1230
1259
|
/**
|
|
1231
|
-
|
|
1260
|
+
* @description 某个数据流传输结束事件
|
|
1232
1261
|
*/
|
|
1233
1262
|
export type SendEventPayloadEndParams = {
|
|
1234
1263
|
/** 事件 id */
|
|
@@ -1237,8 +1266,6 @@ export type SendEventPayloadEndParams = {
|
|
|
1237
1266
|
sessionId: string;
|
|
1238
1267
|
/** 发送结束 的 dataChannel */
|
|
1239
1268
|
dataChannel: string;
|
|
1240
|
-
/** 扩展属性 */
|
|
1241
|
-
userData?: Attribute[];
|
|
1242
1269
|
success?: (params: null) => void;
|
|
1243
1270
|
fail?: (params: {
|
|
1244
1271
|
errorMsg: string;
|
|
@@ -1258,8 +1285,6 @@ export type SendEventEndParams = {
|
|
|
1258
1285
|
eventId: string;
|
|
1259
1286
|
/** 会话 id */
|
|
1260
1287
|
sessionId: string;
|
|
1261
|
-
/** 扩展属性 */
|
|
1262
|
-
userData?: Attribute[];
|
|
1263
1288
|
success?: (params: null) => void;
|
|
1264
1289
|
fail?: (params: {
|
|
1265
1290
|
errorMsg: string;
|
|
@@ -1279,8 +1304,13 @@ export type SendEventChatBreakParams = {
|
|
|
1279
1304
|
eventId: string;
|
|
1280
1305
|
/** 会话 id */
|
|
1281
1306
|
sessionId: string;
|
|
1282
|
-
/**
|
|
1307
|
+
/**
|
|
1308
|
+
* 扩展属性
|
|
1309
|
+
* @deprecated
|
|
1310
|
+
*/
|
|
1283
1311
|
userData?: Attribute[];
|
|
1312
|
+
/** 扩展属性 */
|
|
1313
|
+
userDataJson?: string;
|
|
1284
1314
|
success?: (params: null) => void;
|
|
1285
1315
|
fail?: (params: {
|
|
1286
1316
|
errorMsg: string;
|
|
@@ -1304,8 +1334,6 @@ export type StartRecordAndSendAudioDataParams = {
|
|
|
1304
1334
|
sessionId: string;
|
|
1305
1335
|
/** 下发数据通道,当音频只有单路的时候,可以不传 */
|
|
1306
1336
|
dataChannel?: string;
|
|
1307
|
-
/** 扩展属性 */
|
|
1308
|
-
userData?: Attribute[];
|
|
1309
1337
|
success?: (params: null) => void;
|
|
1310
1338
|
fail?: (params: {
|
|
1311
1339
|
errorMsg: string;
|
|
@@ -1322,8 +1350,6 @@ export type StopRecordAndSendAudioDataParams = {
|
|
|
1322
1350
|
sessionId: string;
|
|
1323
1351
|
/** 下发数据通道,当音频只有单路的时候,可以不传 */
|
|
1324
1352
|
dataChannel?: string;
|
|
1325
|
-
/** 扩展属性 */
|
|
1326
|
-
userData?: Attribute[];
|
|
1327
1353
|
success?: (params: AIStreamAudioFile | null) => void;
|
|
1328
1354
|
fail?: (params: {
|
|
1329
1355
|
errorMsg: string;
|
|
@@ -1372,8 +1398,6 @@ export type StopRecordAndSendVideoDataParams = {
|
|
|
1372
1398
|
* 1-前置摄像头, 2-后置摄像头
|
|
1373
1399
|
*/
|
|
1374
1400
|
cameraType: VideoCameraType;
|
|
1375
|
-
/** 扩展属性 */
|
|
1376
|
-
userData?: Attribute[];
|
|
1377
1401
|
success?: (params: null) => void;
|
|
1378
1402
|
fail?: (params: {
|
|
1379
1403
|
errorMsg: string;
|
|
@@ -1392,8 +1416,6 @@ export type SendImageDataParams = {
|
|
|
1392
1416
|
dataChannel?: string;
|
|
1393
1417
|
/** 图片路径 */
|
|
1394
1418
|
path: string;
|
|
1395
|
-
/** 扩展属性 */
|
|
1396
|
-
userData?: Attribute[];
|
|
1397
1419
|
success?: (params: null) => void;
|
|
1398
1420
|
fail?: (params: {
|
|
1399
1421
|
errorMsg: string;
|
|
@@ -1412,8 +1434,6 @@ export type SendTextDataParams = {
|
|
|
1412
1434
|
dataChannel?: string;
|
|
1413
1435
|
/** 文本内容 */
|
|
1414
1436
|
text: string;
|
|
1415
|
-
/** 扩展属性 */
|
|
1416
|
-
userData?: Attribute[];
|
|
1417
1437
|
success?: (params: null) => void;
|
|
1418
1438
|
fail?: (params: {
|
|
1419
1439
|
errorMsg: string;
|
|
@@ -1447,8 +1467,6 @@ export type SendFileDataParams = {
|
|
|
1447
1467
|
path: string;
|
|
1448
1468
|
/** 文件类型: 1 - MP4, 2 - OGG_OPUS, 3 - PDF, 4 - JSON, 5 - IPC_LOG, 6 - SweeperMap */
|
|
1449
1469
|
format: FileFormat;
|
|
1450
|
-
/** 扩展属性 */
|
|
1451
|
-
userData?: Attribute[];
|
|
1452
1470
|
success?: (params: null) => void;
|
|
1453
1471
|
fail?: (params: {
|
|
1454
1472
|
errorMsg: string;
|
package/dist/AIStreamTypes.js
CHANGED
|
@@ -100,7 +100,6 @@ export let EventType = /*#__PURE__*/function (EventType) {
|
|
|
100
100
|
EventType[EventType["ONE_SHOT"] = 3] = "ONE_SHOT";
|
|
101
101
|
EventType[EventType["CHAT_BREAK"] = 4] = "CHAT_BREAK";
|
|
102
102
|
EventType[EventType["SERVER_VAD"] = 5] = "SERVER_VAD";
|
|
103
|
-
EventType[EventType["SERVER_ERROR"] = 6] = "SERVER_ERROR";
|
|
104
103
|
return EventType;
|
|
105
104
|
}({});
|
|
106
105
|
export let StreamFlag = /*#__PURE__*/function (StreamFlag) {
|
|
@@ -228,7 +227,7 @@ export let NetworkType = /*#__PURE__*/function (NetworkType) {
|
|
|
228
227
|
*/
|
|
229
228
|
|
|
230
229
|
/**
|
|
231
|
-
|
|
230
|
+
* @description 某个数据流传输结束事件
|
|
232
231
|
*/
|
|
233
232
|
|
|
234
233
|
/**
|
package/dist/asr/AsrAgent.js
CHANGED
|
@@ -177,7 +177,7 @@ export class AsrAgent {
|
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
179
|
const activeSession = await this.createSession();
|
|
180
|
-
const
|
|
180
|
+
const chatAttributes = {
|
|
181
181
|
'processing.interrupt': 'false',
|
|
182
182
|
'asr.enableVad': 'false'
|
|
183
183
|
};
|
|
@@ -186,8 +186,11 @@ export class AsrAgent {
|
|
|
186
186
|
userData: [{
|
|
187
187
|
type: AIStreamAttributeType.AI_CHAT,
|
|
188
188
|
payloadType: AIStreamAttributePayloadType.STRING,
|
|
189
|
-
value: JSON.stringify(
|
|
190
|
-
}]
|
|
189
|
+
value: JSON.stringify(chatAttributes)
|
|
190
|
+
}],
|
|
191
|
+
userDataJson: JSON.stringify({
|
|
192
|
+
chatAttributes
|
|
193
|
+
})
|
|
191
194
|
}));
|
|
192
195
|
if (startEventError) {
|
|
193
196
|
finish(startEventError);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsrAgent } from './AsrAgent';
|
|
2
|
+
import { trackEvent } from '../utils/track';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 创建一个AsrAgent实例,用于语音转文本
|
|
@@ -31,5 +32,8 @@ import { AsrAgent } from './AsrAgent';
|
|
|
31
32
|
*/
|
|
32
33
|
export function createAsrAgent(options) {
|
|
33
34
|
const asrAgent = new AsrAgent(options);
|
|
35
|
+
trackEvent(options.agentId, 'create_asr_agent', {
|
|
36
|
+
recordingOptions: options.recordingOptions
|
|
37
|
+
});
|
|
34
38
|
return asrAgent;
|
|
35
39
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
2
1
|
import { BuildInSkillCode, ReceivedSmartHomeSkillAction } from '../AIStreamTypes';
|
|
3
2
|
export function withBuildIn() {
|
|
4
3
|
return _agent => {
|
|
@@ -56,13 +55,15 @@ export function withBuildIn() {
|
|
|
56
55
|
sceneInfo: [],
|
|
57
56
|
changeInfo: []
|
|
58
57
|
};
|
|
59
|
-
for (
|
|
58
|
+
for (let i = 0; i < skills.length; i++) {
|
|
59
|
+
const skill = skills[i];
|
|
60
60
|
if (skill.code !== BuildInSkillCode.SMART_HOME) {
|
|
61
61
|
continue;
|
|
62
62
|
}
|
|
63
63
|
const content = skill;
|
|
64
64
|
if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_SCENE) {
|
|
65
|
-
for (
|
|
65
|
+
for (let i1 = 0; i1 < content.general.data.scenes.length; i1++) {
|
|
66
|
+
const scene = content.general.data.scenes[i1];
|
|
66
67
|
executeData.sceneInfo.push({
|
|
67
68
|
type: scene.type,
|
|
68
69
|
enabled: scene.enable,
|
|
@@ -76,7 +77,8 @@ export function withBuildIn() {
|
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
} else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_SCENE) {
|
|
79
|
-
for (
|
|
80
|
+
for (let i1 = 0; i1 < content.general.data.scenes.length; i1++) {
|
|
81
|
+
const scene = content.general.data.scenes[i1];
|
|
80
82
|
operateData.sceneInfo.push({
|
|
81
83
|
type: scene.type,
|
|
82
84
|
icon: scene.icon,
|
|
@@ -89,7 +91,8 @@ export function withBuildIn() {
|
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
} else if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_DEVICE) {
|
|
92
|
-
for (
|
|
94
|
+
for (let i1 = 0; i1 < content.general.data.devices.length; i1++) {
|
|
95
|
+
const dev = content.general.data.devices[i1];
|
|
93
96
|
executeData.deviceInfo.push({
|
|
94
97
|
icon: dev.icon,
|
|
95
98
|
name: dev.name,
|
|
@@ -100,7 +103,8 @@ export function withBuildIn() {
|
|
|
100
103
|
});
|
|
101
104
|
}
|
|
102
105
|
} else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_DEVICE) {
|
|
103
|
-
for (
|
|
106
|
+
for (let i1 = 0; i1 < content.general.data.devices.length; i1++) {
|
|
107
|
+
const dev = content.general.data.devices[i1];
|
|
104
108
|
operateData.deviceInfo.push({
|
|
105
109
|
icon: dev.icon,
|
|
106
110
|
name: dev.name,
|
|
@@ -128,8 +132,9 @@ export function withBuildIn() {
|
|
|
128
132
|
const data = {
|
|
129
133
|
documents: []
|
|
130
134
|
};
|
|
131
|
-
for (
|
|
135
|
+
for (let i = 0; i < skills.length; i++) {
|
|
132
136
|
var _content$custom;
|
|
137
|
+
const skill = skills[i];
|
|
133
138
|
if (skill.code !== BuildInSkillCode.SEARCH_KNOWLEDGE) {
|
|
134
139
|
continue;
|
|
135
140
|
}
|
|
@@ -137,7 +142,8 @@ export function withBuildIn() {
|
|
|
137
142
|
if (!((_content$custom = content.custom) !== null && _content$custom !== void 0 && (_content$custom = _content$custom.data) !== null && _content$custom !== void 0 && _content$custom.documents)) {
|
|
138
143
|
continue;
|
|
139
144
|
}
|
|
140
|
-
for (
|
|
145
|
+
for (let i1 = 0; i1 < content.custom.data.documents.length; i1++) {
|
|
146
|
+
const doc = content.custom.data.documents[i1];
|
|
141
147
|
data.documents.push({
|
|
142
148
|
title: doc.title,
|
|
143
149
|
url: doc.url
|
package/dist/utils/AIStream.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AIStreamAudioFile, Attribute, BizTag, ConnectClientType, ConnectState, FileFormat, VideoCameraType } from '../AIStreamTypes';
|
|
1
|
+
import { AIStreamAudioFile, AIStreamUserData, Attribute, BizTag, ConnectClientType, ConnectState, FileFormat, VideoCameraType } from '../AIStreamTypes';
|
|
2
2
|
import { AIStreamDataEntry, AIStreamObserverPool } from './observer';
|
|
3
|
+
import { AbortSignalObject } from '@ray-js/t-agent';
|
|
3
4
|
import { AIStreamError } from './errors';
|
|
4
5
|
interface AIStreamConnectionOptions {
|
|
5
6
|
/** client 类型: 1-作为设备代理, 2-作为 App */
|
|
@@ -40,12 +41,13 @@ interface AIStreamSessionOptions {
|
|
|
40
41
|
apiVersion?: string;
|
|
41
42
|
/** 业务额外参数 */
|
|
42
43
|
extParams?: any;
|
|
43
|
-
|
|
44
|
+
getSessionUserData?: () => Promise<AIStreamUserData>;
|
|
44
45
|
}
|
|
45
46
|
interface AIStreamEventOptions {
|
|
46
|
-
signal?:
|
|
47
|
-
userData?: Attribute[];
|
|
47
|
+
signal?: AbortSignalObject;
|
|
48
48
|
eventIdPrefix?: string;
|
|
49
|
+
userData?: Attribute[];
|
|
50
|
+
userDataJson?: string;
|
|
49
51
|
}
|
|
50
52
|
export declare class AIStreamSession {
|
|
51
53
|
private connection;
|
|
@@ -75,30 +77,25 @@ type AIStreamEventWriteChunk = {
|
|
|
75
77
|
type: 'text';
|
|
76
78
|
text: string;
|
|
77
79
|
dataChannel?: string;
|
|
78
|
-
userData?: Attribute[];
|
|
79
80
|
} | {
|
|
80
81
|
type: 'file';
|
|
81
82
|
path: string;
|
|
82
83
|
format: FileFormat;
|
|
83
84
|
dataChannel?: string;
|
|
84
|
-
userData?: Attribute[];
|
|
85
85
|
} | {
|
|
86
86
|
type: 'image';
|
|
87
87
|
path: string;
|
|
88
88
|
dataChannel?: string;
|
|
89
|
-
userData?: Attribute[];
|
|
90
89
|
};
|
|
91
90
|
type AIStreamEventSource = {
|
|
92
91
|
type: 'audio';
|
|
93
92
|
dataChannel?: string;
|
|
94
|
-
userData?: Attribute[];
|
|
95
93
|
saveFile?: boolean;
|
|
96
94
|
sampleRate?: number;
|
|
97
95
|
} | {
|
|
98
96
|
type: 'video';
|
|
99
97
|
dataChannel?: string;
|
|
100
98
|
cameraType?: VideoCameraType;
|
|
101
|
-
userData?: Attribute[];
|
|
102
99
|
};
|
|
103
100
|
export interface AIStreamEventStream {
|
|
104
101
|
type: 'video' | 'audio';
|
|
@@ -123,12 +120,8 @@ export declare class AIStreamEvent {
|
|
|
123
120
|
private findFirstCode;
|
|
124
121
|
write(chunk: AIStreamEventWriteChunk): Promise<void>;
|
|
125
122
|
stream(source: AIStreamEventSource): AIStreamEventStream;
|
|
126
|
-
end(
|
|
127
|
-
|
|
128
|
-
}): Promise<void>;
|
|
129
|
-
abort(options?: {
|
|
130
|
-
userData?: Attribute[];
|
|
131
|
-
}): void;
|
|
123
|
+
end(): Promise<void>;
|
|
124
|
+
abort(): void;
|
|
132
125
|
on(name: 'close', callback: () => void): void;
|
|
133
126
|
on(name: 'finish', callback: () => void): void;
|
|
134
127
|
on(name: 'error', callback: (error: AIStreamError) => void): void;
|