@ray-js/t-agent-plugin-aistream 0.2.0-beta-1

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.
Files changed (46) hide show
  1. package/LICENSE.md +21 -0
  2. package/README-zh_CN.md +12 -0
  3. package/README.md +12 -0
  4. package/dist/AIStreamTypes.d.ts +1413 -0
  5. package/dist/AIStreamTypes.js +216 -0
  6. package/dist/ChatHistoryStore.d.ts +66 -0
  7. package/dist/ChatHistoryStore.js +160 -0
  8. package/dist/global.d.ts +4 -0
  9. package/dist/global.js +4 -0
  10. package/dist/index.d.ts +4 -0
  11. package/dist/index.js +4 -0
  12. package/dist/polyfill.d.ts +1 -0
  13. package/dist/polyfill.js +8 -0
  14. package/dist/utils/AIStream.d.ts +137 -0
  15. package/dist/utils/AIStream.js +486 -0
  16. package/dist/utils/abort.d.ts +38 -0
  17. package/dist/utils/abort.js +177 -0
  18. package/dist/utils/actions.d.ts +48 -0
  19. package/dist/utils/actions.js +76 -0
  20. package/dist/utils/apis.d.ts +15 -0
  21. package/dist/utils/apis.js +10 -0
  22. package/dist/utils/defaultMock.d.ts +1 -0
  23. package/dist/utils/defaultMock.js +429 -0
  24. package/dist/utils/index.d.ts +11 -0
  25. package/dist/utils/index.js +11 -0
  26. package/dist/utils/logger.d.ts +2 -0
  27. package/dist/utils/logger.js +3 -0
  28. package/dist/utils/mock.d.ts +48 -0
  29. package/dist/utils/mock.js +72 -0
  30. package/dist/utils/observer.d.ts +61 -0
  31. package/dist/utils/observer.js +152 -0
  32. package/dist/utils/parsers.d.ts +10 -0
  33. package/dist/utils/parsers.js +13 -0
  34. package/dist/utils/promisify.d.ts +18 -0
  35. package/dist/utils/promisify.js +82 -0
  36. package/dist/utils/sendMessage.d.ts +21 -0
  37. package/dist/utils/sendMessage.js +241 -0
  38. package/dist/utils/ttt.d.ts +99 -0
  39. package/dist/utils/ttt.js +97 -0
  40. package/dist/utils/url.d.ts +11 -0
  41. package/dist/utils/url.js +31 -0
  42. package/dist/utils/version.d.ts +1 -0
  43. package/dist/utils/version.js +63 -0
  44. package/dist/withAIStream.d.ts +64 -0
  45. package/dist/withAIStream.js +420 -0
  46. package/package.json +39 -0
@@ -0,0 +1,216 @@
1
+ export let ButtonRouterType = /*#__PURE__*/function (ButtonRouterType) {
2
+ ButtonRouterType["CREATE_SCENE"] = "routeSceneCreate";
3
+ ButtonRouterType["HOME_LOCATION"] = "routeHomeLocation";
4
+ ButtonRouterType["HELP_DOC"] = "routeHelpDoc";
5
+ ButtonRouterType["SUPPORT_DEVICES"] = "routeSupportDevices";
6
+ ButtonRouterType["FAMILY_MANAGE"] = "routeHomeManage";
7
+ ButtonRouterType["ROOM_MANAGE"] = "routeRoomManage";
8
+ ButtonRouterType["MESSAGE_WARN"] = "routeWarnMessage";
9
+ ButtonRouterType["MESSAGE_HOME"] = "routeHomeMessage";
10
+ ButtonRouterType["MESSAGE_NOTICE"] = "routeNotice";
11
+ ButtonRouterType["MESSAGE_SETTING"] = "routeMessageSetting";
12
+ ButtonRouterType["USER_INFO"] = "routeUserInfo";
13
+ ButtonRouterType["ACCOUNT_SECURITY"] = "routeAccountSecurity";
14
+ ButtonRouterType["SETTING"] = "routeSetting";
15
+ ButtonRouterType["VOICE_SERVICE"] = "routeVoiceOrThirdService";
16
+ ButtonRouterType["TICKETS"] = "routeProblemTickets";
17
+ ButtonRouterType["QUESTIONNAIRE"] = "routeAiQuestionnaire";
18
+ ButtonRouterType["PARING"] = "routeAddDevice";
19
+ ButtonRouterType["DEVICE_SHARE"] = "routeDeviceShare";
20
+ return ButtonRouterType;
21
+ }({});
22
+
23
+ /**
24
+ * 发送 type 是 AI 多模态时,block 参数需要传递的JSON格式
25
+ */
26
+
27
+ /**
28
+ * 获取小程序自定义配置
29
+ */
30
+
31
+ /**
32
+ * 获取小程序账号信息
33
+ */
34
+
35
+ /**
36
+ * atop接口
37
+ */
38
+
39
+ export let HighwayMethod = /*#__PURE__*/function (HighwayMethod) {
40
+ HighwayMethod["OPTIONS"] = "OPTIONS";
41
+ HighwayMethod["GET"] = "GET";
42
+ HighwayMethod["HEAD"] = "HEAD";
43
+ HighwayMethod["POST"] = "POST";
44
+ HighwayMethod["PUT"] = "PUT";
45
+ HighwayMethod["DELETE"] = "DELETE";
46
+ HighwayMethod["TRACE"] = "TRACE";
47
+ HighwayMethod["CONNECT"] = "CONNECT";
48
+ return HighwayMethod;
49
+ }({});
50
+ /**
51
+ * Highway接口
52
+ */
53
+
54
+ // 0: 未签署,1:需重签,2:已签署,0和1需要弹窗提示用户
55
+ export let AuthorizePolicySign = /*#__PURE__*/function (AuthorizePolicySign) {
56
+ AuthorizePolicySign[AuthorizePolicySign["UNAUTHORIZED"] = 0] = "UNAUTHORIZED";
57
+ AuthorizePolicySign[AuthorizePolicySign["REAUTHORIZATION"] = 1] = "REAUTHORIZATION";
58
+ AuthorizePolicySign[AuthorizePolicySign["AUTHORIZED"] = 2] = "AUTHORIZED";
59
+ return AuthorizePolicySign;
60
+ }({});
61
+ export let WidgetVersionType = /*#__PURE__*/function (WidgetVersionType) {
62
+ WidgetVersionType["release"] = "release";
63
+ WidgetVersionType["preview"] = "preview";
64
+ return WidgetVersionType;
65
+ }({});
66
+ export let WidgetPosition = /*#__PURE__*/function (WidgetPosition) {
67
+ WidgetPosition["bottom"] = "bottom";
68
+ WidgetPosition["top"] = "top";
69
+ WidgetPosition["center"] = "center";
70
+ return WidgetPosition;
71
+ }({});
72
+ /**
73
+ * AIStream 相关
74
+ */
75
+ export let ConnectState = /*#__PURE__*/function (ConnectState) {
76
+ ConnectState[ConnectState["INIT"] = 0] = "INIT";
77
+ ConnectState[ConnectState["CONNECTING"] = 1] = "CONNECTING";
78
+ ConnectState[ConnectState["AUTHORIZING"] = 2] = "AUTHORIZING";
79
+ ConnectState[ConnectState["CONNECTED"] = 3] = "CONNECTED";
80
+ ConnectState[ConnectState["DISCONNECTED"] = 4] = "DISCONNECTED";
81
+ ConnectState[ConnectState["CLOSED"] = 5] = "CLOSED";
82
+ return ConnectState;
83
+ }({});
84
+ export let SessionState = /*#__PURE__*/function (SessionState) {
85
+ SessionState[SessionState["CREATED"] = 0] = "CREATED";
86
+ SessionState[SessionState["CREATE_FAILED"] = 1] = "CREATE_FAILED";
87
+ SessionState[SessionState["CLOSED"] = 2] = "CLOSED";
88
+ return SessionState;
89
+ }({});
90
+ export let ConnectClientType = /*#__PURE__*/function (ConnectClientType) {
91
+ ConnectClientType[ConnectClientType["DEVICE"] = 1] = "DEVICE";
92
+ ConnectClientType[ConnectClientType["APP"] = 2] = "APP";
93
+ return ConnectClientType;
94
+ }({});
95
+ export let EventType = /*#__PURE__*/function (EventType) {
96
+ EventType[EventType["EVENT_START"] = 0] = "EVENT_START";
97
+ EventType[EventType["EVENT_PAYLOAD_END"] = 1] = "EVENT_PAYLOAD_END";
98
+ EventType[EventType["EVENT_END"] = 2] = "EVENT_END";
99
+ EventType[EventType["ONE_SHOT"] = 3] = "ONE_SHOT";
100
+ EventType[EventType["CHAT_BREAK"] = 4] = "CHAT_BREAK";
101
+ EventType[EventType["SERVER_VAD"] = 5] = "SERVER_VAD";
102
+ return EventType;
103
+ }({});
104
+ export let StreamFlag = /*#__PURE__*/function (StreamFlag) {
105
+ StreamFlag[StreamFlag["ONLY_ONE"] = 0] = "ONLY_ONE";
106
+ StreamFlag[StreamFlag["START"] = 1] = "START";
107
+ StreamFlag[StreamFlag["IN_PROGRESS"] = 2] = "IN_PROGRESS";
108
+ StreamFlag[StreamFlag["END"] = 3] = "END";
109
+ return StreamFlag;
110
+ }({});
111
+ export let FileFormat = /*#__PURE__*/function (FileFormat) {
112
+ FileFormat[FileFormat["MP4"] = 1] = "MP4";
113
+ FileFormat[FileFormat["OGG_OPUS"] = 2] = "OGG_OPUS";
114
+ FileFormat[FileFormat["PDF"] = 3] = "PDF";
115
+ FileFormat[FileFormat["JSON"] = 4] = "JSON";
116
+ FileFormat[FileFormat["IPC_LOG"] = 5] = "IPC_LOG";
117
+ FileFormat[FileFormat["SWEEPER_MAP"] = 6] = "SWEEPER_MAP";
118
+ return FileFormat;
119
+ }({});
120
+ export let AIStreamErrorCode = /*#__PURE__*/function (AIStreamErrorCode) {
121
+ AIStreamErrorCode[AIStreamErrorCode["OK"] = 200] = "OK";
122
+ AIStreamErrorCode[AIStreamErrorCode["BadRequest"] = 400] = "BadRequest";
123
+ AIStreamErrorCode[AIStreamErrorCode["Unauthenticated"] = 401] = "Unauthenticated";
124
+ AIStreamErrorCode[AIStreamErrorCode["NotFound"] = 404] = "NotFound";
125
+ AIStreamErrorCode[AIStreamErrorCode["RequestTimeout"] = 408] = "RequestTimeout";
126
+ AIStreamErrorCode[AIStreamErrorCode["InternalServerError"] = 500] = "InternalServerError";
127
+ AIStreamErrorCode[AIStreamErrorCode["GatewayTimeout"] = 504] = "GatewayTimeout";
128
+ AIStreamErrorCode[AIStreamErrorCode["CloseByClient"] = 601] = "CloseByClient";
129
+ AIStreamErrorCode[AIStreamErrorCode["CloseByReuse"] = 602] = "CloseByReuse";
130
+ AIStreamErrorCode[AIStreamErrorCode["CloseByIO"] = 603] = "CloseByIO";
131
+ AIStreamErrorCode[AIStreamErrorCode["CloseByKeepalive"] = 604] = "CloseByKeepalive";
132
+ AIStreamErrorCode[AIStreamErrorCode["CloseByExpire"] = 605] = "CloseByExpire";
133
+ return AIStreamErrorCode;
134
+ }({});
135
+ export let BizCode = /*#__PURE__*/function (BizCode) {
136
+ BizCode[BizCode["CHAT"] = 65537] = "CHAT";
137
+ return BizCode;
138
+ }({});
139
+ export let BizTag = /*#__PURE__*/function (BizTag) {
140
+ BizTag[BizTag["DEFAULT"] = 0] = "DEFAULT";
141
+ return BizTag;
142
+ }({});
143
+ export let AIStreamAttributeType = /*#__PURE__*/function (AIStreamAttributeType) {
144
+ AIStreamAttributeType[AIStreamAttributeType["AI_CHAT"] = 1003] = "AI_CHAT";
145
+ return AIStreamAttributeType;
146
+ }({});
147
+ export let AIStreamAttributePayloadType = /*#__PURE__*/function (AIStreamAttributePayloadType) {
148
+ AIStreamAttributePayloadType[AIStreamAttributePayloadType["U_INT8"] = 1] = "U_INT8";
149
+ AIStreamAttributePayloadType[AIStreamAttributePayloadType["U_INT16"] = 2] = "U_INT16";
150
+ AIStreamAttributePayloadType[AIStreamAttributePayloadType["U_INT32"] = 3] = "U_INT32";
151
+ AIStreamAttributePayloadType[AIStreamAttributePayloadType["U_INT64"] = 4] = "U_INT64";
152
+ AIStreamAttributePayloadType[AIStreamAttributePayloadType["BYTES"] = 5] = "BYTES";
153
+ AIStreamAttributePayloadType[AIStreamAttributePayloadType["STRING"] = 6] = "STRING";
154
+ return AIStreamAttributePayloadType;
155
+ }({});
156
+ export let AIStreamChatSysWorkflow = /*#__PURE__*/function (AIStreamChatSysWorkflow) {
157
+ AIStreamChatSysWorkflow["ASR_LLM_TTS"] = "asr-llm-tts";
158
+ AIStreamChatSysWorkflow["ASR_LLM"] = "asr-llm";
159
+ AIStreamChatSysWorkflow["ASR"] = "asr";
160
+ AIStreamChatSysWorkflow["LLM"] = "llm";
161
+ AIStreamChatSysWorkflow["LLM_TTS"] = "llm-tts";
162
+ return AIStreamChatSysWorkflow;
163
+ }({});
164
+
165
+ /**
166
+ *@description 发起通道连接,若此前已连接会直接回调成功
167
+ */
168
+
169
+ /**
170
+ *@description 查询智能体 token,传递给 createSession
171
+ */
172
+
173
+ /**
174
+ *@description 创建会话
175
+ */
176
+
177
+ /**
178
+ *@description 关闭会话
179
+ */
180
+
181
+ /**
182
+ *@description 关闭连接,主要针对作为设备代理的情况,以App身份使用时不需要调用
183
+ */
184
+
185
+ /**
186
+ *@description 某个数据流传输结束事件
187
+ */
188
+
189
+ /**
190
+ *@description 结束事件
191
+ */
192
+
193
+ /**
194
+ *@description 打断事件。用于:1. 中止自己的发送,2. 中止接收云端的回复
195
+ */
196
+
197
+ /**
198
+ *@description 开始录制并发送音频数据
199
+ */
200
+
201
+ export let VideoCameraType = /*#__PURE__*/function (VideoCameraType) {
202
+ VideoCameraType[VideoCameraType["FRONT"] = 1] = "FRONT";
203
+ VideoCameraType[VideoCameraType["BACK"] = 2] = "BACK";
204
+ return VideoCameraType;
205
+ }({});
206
+ export let ReceivedTextPacketType = /*#__PURE__*/function (ReceivedTextPacketType) {
207
+ ReceivedTextPacketType["ASR"] = "ASR";
208
+ ReceivedTextPacketType["SKILL"] = "SKILL";
209
+ ReceivedTextPacketType["NLG"] = "NLG";
210
+ return ReceivedTextPacketType;
211
+ }({});
212
+ export let ReceivedTextPacketEof = /*#__PURE__*/function (ReceivedTextPacketEof) {
213
+ ReceivedTextPacketEof[ReceivedTextPacketEof["CONTINUE"] = 0] = "CONTINUE";
214
+ ReceivedTextPacketEof[ReceivedTextPacketEof["END"] = 1] = "END";
215
+ return ReceivedTextPacketEof;
216
+ }({});
@@ -0,0 +1,66 @@
1
+ import { ChatMessageObject } from '@ray-js/t-agent';
2
+ import { QueryRecordListParams } from './AIStreamTypes';
3
+ export interface StoredMessageObject {
4
+ message: ChatMessageObject;
5
+ id: number;
6
+ createdAt?: number;
7
+ updatedAt?: number;
8
+ agentId?: string;
9
+ deviceId?: string;
10
+ homeId?: number;
11
+ indexId?: string;
12
+ }
13
+ type Condition = Omit<QueryRecordListParams, 'success' | 'fail' | 'complete' | 'offset' | 'limit' | 'index2'>;
14
+ type DeleteCondition = Pick<QueryRecordListParams, 'id' | 'bizCode' | 'devId' | 'homeId' | 'index' | 'index1'>;
15
+ interface Pagination {
16
+ sort?: 'asc' | 'desc';
17
+ pageSize: number;
18
+ pageNo: number;
19
+ }
20
+ export declare abstract class ChatHistoryStore {
21
+ /** 查询消息 */
22
+ abstract query(id: number): Promise<StoredMessageObject>;
23
+ /** 批量查询 */
24
+ abstract queryBy(condition: Condition, pagination: Pagination): Promise<{
25
+ total: number;
26
+ records: StoredMessageObject[];
27
+ }>;
28
+ /** 更新消息 */
29
+ abstract update(id: number, body: ChatMessageObject): Promise<void>;
30
+ abstract remove(id: number): Promise<void>;
31
+ abstract removeBy(condition: Condition): Promise<void>;
32
+ abstract insert(body: Partial<ChatMessageObject>): Promise<{
33
+ id: number;
34
+ }>;
35
+ }
36
+ export interface ChatHistoryStoreOptions {
37
+ /** 家庭ID */
38
+ homeId?: number;
39
+ /** 索引ID */
40
+ indexId: string;
41
+ /** 自定义agentId;智能解决方案 code可以使用该字段 */
42
+ agentId?: string;
43
+ deviceId?: string;
44
+ /** biz Code 大类目 */
45
+ bizCode?: number;
46
+ }
47
+ export declare class ChatHistoryLocalStore implements ChatHistoryStore {
48
+ /** 版本号,会作为内部索引的一部分 */
49
+ private readonly version;
50
+ /** 消息的meta数据,新增查询都会以此为条件 */
51
+ private messageMeta;
52
+ private getAgentIndexId;
53
+ constructor(options: ChatHistoryStoreOptions);
54
+ query(id: number): Promise<StoredMessageObject>;
55
+ queryBy(condition: Condition, pagination: Pagination): Promise<{
56
+ total: number;
57
+ records: StoredMessageObject[];
58
+ }>;
59
+ update(id: number, body: ChatMessageObject): Promise<void>;
60
+ remove(id: number): Promise<void>;
61
+ removeBy(condition: DeleteCondition): Promise<void>;
62
+ insert(body: Partial<ChatMessageObject>): Promise<{
63
+ id: number;
64
+ }>;
65
+ }
66
+ export {};
@@ -0,0 +1,160 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import "core-js/modules/es.array.sort.js";
4
+ import "core-js/modules/es.json.stringify.js";
5
+ import "core-js/modules/esnext.iterator.constructor.js";
6
+ import "core-js/modules/esnext.iterator.map.js";
7
+ import { safeParseJSON } from '@ray-js/t-agent';
8
+ import { insertRecord, deleteRecordList, updateRecord, queryRecordList } from './utils/ttt';
9
+ import { safeParseInt } from './utils/parsers';
10
+ import logger from './utils/logger';
11
+ export class ChatHistoryStore {}
12
+ export class ChatHistoryLocalStore {
13
+ getAgentIndexId() {
14
+ return "t-agent-".concat(this.version);
15
+ }
16
+ constructor(options) {
17
+ /** 版本号,会作为内部索引的一部分 */
18
+ _defineProperty(this, "version", 'v1');
19
+ /** 消息的meta数据,新增查询都会以此为条件 */
20
+ _defineProperty(this, "messageMeta", {});
21
+ this.messageMeta = {
22
+ bizCode: options.bizCode,
23
+ solutionCode: options.agentId,
24
+ // 使用 agentId 填充
25
+ agentId: options.agentId,
26
+ devId: options.deviceId,
27
+ homeId: options.homeId,
28
+ index: this.getAgentIndexId(),
29
+ index2: options.indexId
30
+ };
31
+ }
32
+ async query(id) {
33
+ if (typeof id !== 'number') {
34
+ logger.warn('query id is not number', {
35
+ id
36
+ });
37
+ return null;
38
+ }
39
+ const msgList = await this.queryBy({
40
+ id: [id]
41
+ }, {
42
+ pageSize: 1,
43
+ pageNo: 0
44
+ });
45
+ return msgList.records[0];
46
+ }
47
+ async queryBy(condition, pagination) {
48
+ var _msgListRes, _msgListRes2;
49
+ const queryCondition = {};
50
+ // 参数严格校验,过滤空值和空[]
51
+ if (condition && typeof condition === 'object') {
52
+ for (const key in condition) {
53
+ if (!(condition[key] === undefined || condition[key] === null || Array.isArray(condition[key]) && condition[key].length === 0)) {
54
+ queryCondition[key] = condition[key];
55
+ }
56
+ }
57
+ }
58
+ // 系统使用index索引,这里使用index2填充业务的index
59
+ if (Array.isArray(condition.index) && condition.index.length > 0) {
60
+ queryCondition.index2 = condition.index;
61
+ }
62
+ queryCondition.index = [this.getAgentIndexId()];
63
+ let {
64
+ pageNo,
65
+ pageSize
66
+ } = pagination || {};
67
+ pageNo = safeParseInt(pageNo, 0);
68
+ pageSize = safeParseInt(pageSize, 0);
69
+ queryCondition.offset = pageNo * pageSize;
70
+ if (pageSize) {
71
+ queryCondition.limit = pageSize;
72
+ }
73
+ queryCondition.sortType = pagination.sort === 'desc' ? 0 : 1;
74
+ let msgListRes = null;
75
+ try {
76
+ msgListRes = await queryRecordList(queryCondition);
77
+ } catch (error) {
78
+ logger.error('queryRecordList error', error);
79
+ msgListRes = {
80
+ total: 0,
81
+ records: []
82
+ };
83
+ }
84
+ const msgList = (((_msgListRes = msgListRes) === null || _msgListRes === void 0 ? void 0 : _msgListRes.records) || []).map(item => {
85
+ const messageInfo = safeParseJSON(item.data) || {};
86
+ return _objectSpread(_objectSpread({}, item), {}, {
87
+ createdAt: messageInfo.createdAt,
88
+ updatedAt: messageInfo.updatedAt,
89
+ message: messageInfo.message
90
+ });
91
+ });
92
+ return {
93
+ total: (_msgListRes2 = msgListRes) === null || _msgListRes2 === void 0 ? void 0 : _msgListRes2.total,
94
+ records: msgList
95
+ };
96
+ }
97
+ async update(id, body) {
98
+ if (typeof id !== 'number') {
99
+ logger.warn('query id is not number', {
100
+ id
101
+ });
102
+ return null;
103
+ }
104
+ const messageInfo = await this.query(id);
105
+ if (!messageInfo) {
106
+ logger.error('query messageInfo is null', {
107
+ id
108
+ });
109
+ return null;
110
+ }
111
+ const nowTime = Date.now();
112
+ const msgObject = {
113
+ message: body,
114
+ createdAt: messageInfo.createdAt,
115
+ updatedAt: nowTime
116
+ };
117
+ return updateRecord(_objectSpread(_objectSpread({}, this.messageMeta), {}, {
118
+ id,
119
+ data: JSON.stringify(msgObject)
120
+ }));
121
+ }
122
+ async remove(id) {
123
+ if (typeof id !== 'number') {
124
+ logger.warn('query id is not number', {
125
+ id
126
+ });
127
+ return null;
128
+ }
129
+ const isExist = await this.query(id);
130
+ if (!isExist) {
131
+ logger.error('query messageInfo is null', {
132
+ id
133
+ });
134
+ return null;
135
+ }
136
+ return deleteRecordList({
137
+ id: [id]
138
+ });
139
+ }
140
+ async removeBy(condition) {
141
+ const deleteCondition = _objectSpread(_objectSpread({}, condition), {}, {
142
+ index: [this.getAgentIndexId()]
143
+ });
144
+ // 系统使用index索引,这里使用index2填充业务的index
145
+ if (condition.index) {
146
+ deleteCondition.index2 = condition.index;
147
+ }
148
+ return deleteRecordList(condition);
149
+ }
150
+ async insert(body) {
151
+ const nowTime = Date.now();
152
+ return insertRecord(_objectSpread(_objectSpread({}, this.messageMeta), {}, {
153
+ data: JSON.stringify({
154
+ message: body,
155
+ createdAt: nowTime,
156
+ updatedAt: nowTime
157
+ })
158
+ }));
159
+ }
160
+ }
@@ -0,0 +1,4 @@
1
+ import { AIStreamClient } from './utils';
2
+ export declare const globalAIStreamClient: AIStreamClient;
3
+ export declare const DEFAULT_TOKEN_API = "m.thing.aigc.basic.server.token";
4
+ export declare const DEFAULT_TOKEN_API_VERSION = "1.0";
package/dist/global.js ADDED
@@ -0,0 +1,4 @@
1
+ import { AIStreamClient } from './utils';
2
+ export const globalAIStreamClient = new AIStreamClient();
3
+ export const DEFAULT_TOKEN_API = 'm.thing.aigc.basic.server.token';
4
+ export const DEFAULT_TOKEN_API_VERSION = '1.0';
@@ -0,0 +1,4 @@
1
+ export * from './utils';
2
+ export * from './AIStreamTypes';
3
+ export * from './withAIStream';
4
+ export * from './ChatHistoryStore';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './utils';
2
+ export * from './AIStreamTypes';
3
+ export * from './withAIStream';
4
+ export * from './ChatHistoryStore';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import "core-js/modules/web.queue-microtask.js";
2
+ // @ts-ignore
3
+ globalThis.queueMicrotask = callback => {
4
+ Promise.resolve().then(callback).catch(err => {
5
+ throw err;
6
+ });
7
+ };
8
+ export {};
@@ -0,0 +1,137 @@
1
+ import { Attribute, BizTag, ConnectClientType, FileFormat, VideoCameraType } from '../AIStreamTypes';
2
+ import { AIStreamDataEntry, AIStreamObserverPool } from './observer';
3
+ interface AIStreamConnectionOptions {
4
+ /** client 类型: 1-作为设备代理, 2-作为 App */
5
+ clientType: ConnectClientType;
6
+ /** 代理的设备ID, clientType == 1 时必传 */
7
+ deviceId?: string;
8
+ }
9
+ export declare class AIStreamClient {
10
+ pool: AIStreamObserverPool;
11
+ private cached;
12
+ getConnection(options: AIStreamConnectionOptions): AIStreamConnection;
13
+ }
14
+ export declare class AIStreamConnection {
15
+ private readonly pool;
16
+ readonly options: AIStreamConnectionOptions;
17
+ private connectionId;
18
+ private state;
19
+ private activeSessions;
20
+ private promise;
21
+ private observer;
22
+ constructor(pool: AIStreamObserverPool, options: AIStreamConnectionOptions);
23
+ _ensureConnected(): Promise<void>;
24
+ private onStateChanged;
25
+ private cleanup;
26
+ createSession(options: AIStreamSessionOptions): AIStreamSession;
27
+ closeSession(session: AIStreamSession): Promise<void>;
28
+ close(): Promise<void>;
29
+ }
30
+ interface AIStreamSessionOptions {
31
+ bizTag?: BizTag;
32
+ /** Owner ID: HomeID 或 设备id */
33
+ ownerId?: string;
34
+ /** 智能解决方案 code */
35
+ solutionCode: string;
36
+ /** 业务接口 */
37
+ api: string;
38
+ /** 接口版本 */
39
+ apiVersion: string;
40
+ /** 业务额外参数 */
41
+ extParams?: any;
42
+ userData?: Attribute[];
43
+ }
44
+ interface AIStreamEventOptions {
45
+ userData?: Attribute[];
46
+ }
47
+ export declare class AIStreamSession {
48
+ private connection;
49
+ private pool;
50
+ readonly options: AIStreamSessionOptions;
51
+ sessionId: string | null;
52
+ sendDataChannels: string[];
53
+ revDataChannels: string[];
54
+ private activeEvent?;
55
+ private activeObserver?;
56
+ private promise;
57
+ constructor(connection: AIStreamConnection, pool: AIStreamObserverPool, options: AIStreamSessionOptions);
58
+ private ensureSession;
59
+ _onStateChanged: (entry: AIStreamDataEntry) => void;
60
+ startEvent(options?: AIStreamEventOptions): Promise<AIStreamEvent>;
61
+ private onDataEntry;
62
+ private cleanupEvent;
63
+ cleanup(): void;
64
+ close(): Promise<void>;
65
+ }
66
+ type AIStreamEventWriteChunk = {
67
+ type: 'text';
68
+ text: string;
69
+ dataChannel?: string;
70
+ userData?: Attribute[];
71
+ } | {
72
+ type: 'file';
73
+ path: string;
74
+ format: FileFormat;
75
+ dataChannel?: string;
76
+ userData?: Attribute[];
77
+ } | {
78
+ type: 'image';
79
+ path: string;
80
+ dataChannel?: string;
81
+ userData?: Attribute[];
82
+ };
83
+ type AIStreamEventSource = {
84
+ type: 'audio';
85
+ dataChannel?: string;
86
+ amplitudeCount?: number;
87
+ userData?: Attribute[];
88
+ } | {
89
+ type: 'video';
90
+ dataChannel?: string;
91
+ cameraType?: VideoCameraType;
92
+ userData?: Attribute[];
93
+ };
94
+ interface AIStreamEventStream {
95
+ type: 'video' | 'audio';
96
+ dataChannel: string;
97
+ started: boolean;
98
+ start: () => Promise<void>;
99
+ stop: () => Promise<void>;
100
+ }
101
+ export declare class AIStreamEvent {
102
+ readonly eventId: string;
103
+ sessionId: string;
104
+ readonly sendDataChannels: string[];
105
+ private closed;
106
+ private chains;
107
+ private streams;
108
+ private listeners;
109
+ constructor(init: {
110
+ eventId: string;
111
+ sessionId: string;
112
+ sendDataChannels: string[];
113
+ });
114
+ private findFirstCode;
115
+ write(chunk: AIStreamEventWriteChunk): Promise<void>;
116
+ stream(source: AIStreamEventSource): AIStreamEventStream;
117
+ end(options?: {
118
+ userData?: Attribute[];
119
+ }): Promise<void>;
120
+ abort(options?: {
121
+ userData?: Attribute[];
122
+ }): Promise<void>;
123
+ on(name: 'close', callback: () => void): void;
124
+ on(name: 'finish', callback: () => void): void;
125
+ on(name: 'error', callback: (error: any) => void): void;
126
+ on(name: 'data', callback: (entry: AIStreamDataEntry) => void): void;
127
+ off(name: 'finish', callback: () => void): void;
128
+ off(name: 'close', callback: () => void): void;
129
+ off(name: 'error', callback: (error: any) => void): void;
130
+ off(name: 'data', callback: (entry: AIStreamDataEntry) => void): void;
131
+ emit(name: 'finish'): void;
132
+ emit(name: 'close'): void;
133
+ emit(name: 'error', data: Error): void;
134
+ emit(name: 'data', data: AIStreamDataEntry): void;
135
+ private dispose;
136
+ }
137
+ export {};