@ray-js/t-agent-plugin-aistream 0.2.8-beta.1 → 0.2.8-beta.2

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.
@@ -692,18 +692,18 @@ export declare enum AIStreamErrorCode {
692
692
  ASR_EMPTY = "asr-empty"
693
693
  }
694
694
  export declare enum AIStreamAppErrorCode {
695
- GENERIC_ERROR = 39001,
696
- INVALID_PARAMS = 39002,
697
- HTTP_REQUEST_FAILED = 39003,
698
- CONNECTION_INVALID = 39004,
699
- SESSION_ID_INVALID = 39005,
700
- EVENT_ID_INVALID = 39006,
701
- DATA_CHANNEL_NOT_FOUND = 39007,
702
- INVALID_DATA_PACKET = 39008,
703
- FILE_DATA_READ_ERROR = 39009,
704
- DATA_SEND_FAILED = 39010,
705
- CONNECTION_CLOSED_BY_REMOTE = 39012,
706
- AUDIO_UNEXPECTEDLY_RESET = 39014,
695
+ GENERIC_ERROR = 39001,// 通用错误,用于一些杂项错误
696
+ INVALID_PARAMS = 39002,// 参数不合法,详见备注
697
+ HTTP_REQUEST_FAILED = 39003,// HTTP 请求失败
698
+ CONNECTION_INVALID = 39004,// Connection 未连接
699
+ SESSION_ID_INVALID = 39005,// SessionId 不存在
700
+ EVENT_ID_INVALID = 39006,// EventId 为空
701
+ DATA_CHANNEL_NOT_FOUND = 39007,// DataChannel 不存在
702
+ INVALID_DATA_PACKET = 39008,// 数据包不合法
703
+ FILE_DATA_READ_ERROR = 39009,// 文件数据读取异常
704
+ DATA_SEND_FAILED = 39010,// 发送数据失败
705
+ CONNECTION_CLOSED_BY_REMOTE = 39012,// Connection 被远端关闭
706
+ AUDIO_UNEXPECTEDLY_RESET = 39014,// 音频组件被重置
707
707
  RECONNECT = 39016
708
708
  }
709
709
  export declare enum AIStreamServerErrorCode {
@@ -1031,7 +1031,7 @@ export type RecordAmplitudesBody = {
1031
1031
  amplitudes: number[];
1032
1032
  };
1033
1033
  export declare enum NetworkType {
1034
- NONE = "none",
1034
+ NONE = "none",// 无网络
1035
1035
  CELL_2G = "2g",
1036
1036
  CELL_3G = "3g",
1037
1037
  CELL_4G = "4g",
@@ -1703,8 +1703,8 @@ export type InsertRecordParams = {
1703
1703
  complete?: () => void;
1704
1704
  };
1705
1705
  export declare enum ReceivedTextPacketType {
1706
- ASR = "ASR",
1707
- SKILL = "SKILL",
1706
+ ASR = "ASR",// ASR 识别的文本
1707
+ SKILL = "SKILL",// 数据
1708
1708
  NLG = "NLG"
1709
1709
  }
1710
1710
  export declare enum ReceivedTextPacketEof {
@@ -1731,7 +1731,7 @@ export type ReceivedTextNlgPacket = ReceivedTextPacketBase<ReceivedTextPacketTyp
1731
1731
  finish: boolean;
1732
1732
  }>;
1733
1733
  export declare enum BuildInSkillCode {
1734
- SEARCH_KNOWLEDGE = "searchKnowledge",
1734
+ SEARCH_KNOWLEDGE = "searchKnowledge",// 知识库搜索
1735
1735
  SMART_HOME = "smart_home"
1736
1736
  }
1737
1737
  export type ReceivedTextSkillPacketBody<Code = BuildInSkillCode | string, G = any, C = any> = {
@@ -36,9 +36,9 @@ export interface AsrAgentOptions {
36
36
  eventIdPrefix?: string;
37
37
  }
38
38
  export declare enum AsrAgentStatus {
39
- PENDING = "pending",
40
- RECORDING = "recording",
41
- ASR = "asr",
39
+ PENDING = "pending",// 等待开始
40
+ RECORDING = "recording",// 录音中
41
+ ASR = "asr",// ASR 处理中
42
42
  ABORTING = "aborting"
43
43
  }
44
44
  export declare class AsrAgent {
@@ -347,6 +347,7 @@ export class AsrAgent {
347
347
  if (this.disposed) {
348
348
  return;
349
349
  }
350
+ this.disposed = true;
350
351
  if (this.activeSession) {
351
352
  this.activeSession.close();
352
353
  }
package/dist/polyfill.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import "core-js/modules/web.queue-microtask.js";
2
+ /* istanbul ignore file */
2
3
  // @ts-ignore
3
4
  globalThis.queueMicrotask = callback => {
4
5
  Promise.resolve().then(callback).catch(err => {
@@ -70,7 +70,7 @@ export declare class AIStreamSession {
70
70
  private promise;
71
71
  tokenExtParamsResolvable: import("./object").Resolvable<{
72
72
  [key: string]: any;
73
- chatId?: string | undefined;
73
+ chatId?: string;
74
74
  }>;
75
75
  private listeners;
76
76
  constructor(connection: AIStreamConnection, pool: AIStreamObserverPool, options: AIStreamSessionOptions);
@@ -23,6 +23,7 @@ export class AIStreamClient {
23
23
  let connection = this.cached.get(key);
24
24
  if (!connection) {
25
25
  connection = new AIStreamConnection(this.pool, options);
26
+ this.cached.set(key, connection);
26
27
  }
27
28
  return connection;
28
29
  }
@@ -287,7 +288,7 @@ export class AIStreamSession {
287
288
  }));
288
289
  if (err) {
289
290
  finErr = err;
290
- if (err.code === AIStreamAppErrorCode.RECONNECT) {
291
+ if (err.originalCode === AIStreamAppErrorCode.RECONNECT) {
291
292
  // 200 毫秒后再试
292
293
  await new Promise(resolve => {
293
294
  setTimeout(resolve, 200);
@@ -96,9 +96,11 @@ export async function tryCatchTTT(fn) {
96
96
  code,
97
97
  message
98
98
  } = error;
99
- message = "".concat(message, " (original_code: ").concat(code || '-', ")");
99
+ const originalCode = code;
100
+ message = "".concat(message, " (original_code: ").concat(originalCode || '-', ")");
100
101
  code = transformErrorCode(code);
101
102
  const e = removeTopStackFrame(new AIStreamError(message, code));
103
+ e.originalCode = originalCode;
102
104
  return [e, null];
103
105
  }
104
106
  return [null, result];
@@ -54,9 +54,9 @@ declare const mock: {
54
54
  emitter: Emitter;
55
55
  hooks: import("hookable").Hookable<MockHooks, string>;
56
56
  getRecords: <T = any>() => Row<T>[];
57
- getRecord: <T_1 = any>(id: number) => Row<T_1> | undefined;
58
- setRecord: <T_2 = any>(entry: Row<T_2>) => void;
59
- updateRecord: <T_3 = any>(entry: Row<T_3>) => void;
57
+ getRecord: <T = any>(id: number) => Row<T> | undefined;
58
+ setRecord: <T = any>(entry: Row<T>) => void;
59
+ updateRecord: <T = any>(entry: Row<T>) => void;
60
60
  deleteRecord: (id: number) => void;
61
61
  clearRecords: () => void;
62
62
  getId: () => number;
@@ -13,6 +13,6 @@ interface AsyncTTTFnParams<P> {
13
13
  }
14
14
  export declare const getEnableMock: () => boolean;
15
15
  export declare const setEnableMock: (enable: boolean) => boolean;
16
- export declare function promisify<T extends AsyncTTTFnParams<any>>(fn: (options: any) => void, enableMock?: boolean): (options?: Omit<T, 'success' | 'fail'>) => Promise<Parameters<NonNullable<T["success"]>>[0]>;
16
+ export declare function promisify<T extends AsyncTTTFnParams<any>>(fn: (options: any) => void, enableMock?: boolean): (options?: Omit<T, "success" | "fail">) => Promise<Parameters<NonNullable<T["success"]>>[0]>;
17
17
  export declare function listening<T>(on: (listener: (params: T) => void) => void, off: (listener: (params: T) => void) => void, enableMock?: boolean): (listener: (params: T) => void) => () => void;
18
18
  export {};
@@ -65,8 +65,10 @@ export function sendBlocksToAIStream(params) {
65
65
  if (!closed) {
66
66
  logger.debug('sendBlocksToAIStream close');
67
67
  closed = true;
68
- if (!canceled && !(signal !== null && signal !== void 0 && signal.aborted)) {
68
+ try {
69
69
  controller.close();
70
+ } catch (error) {
71
+ logger.debug('sendBlocksToAIStream close ignored', error);
70
72
  }
71
73
  }
72
74
  };
@@ -251,7 +253,7 @@ export function sendBlocksToAIStream(params) {
251
253
  if (data.body.sessionState === SessionState.CLOSED || data.body.sessionState === SessionState.CREATE_FAILED) {
252
254
  const msg = SessionState[data.body.sessionState];
253
255
  const e = new AIStreamError("Session Error: ".concat(msg, ", (original_code: ").concat(data.body.code, ")"), transformErrorCode(data.body.code));
254
- emitError(error);
256
+ emitError(e);
255
257
  if (audioEmitter) {
256
258
  audioEmitter.dispatchEvent(new EmitterEvent('error', {
257
259
  detail: e
@@ -262,7 +264,7 @@ export function sendBlocksToAIStream(params) {
262
264
  } else if (data.type === 'connectionState') {
263
265
  if (data.body.connectState === ConnectState.DISCONNECTED || data.body.connectState === ConnectState.CLOSED) {
264
266
  const e = new AIStreamError("Session disconnected, (original_code: ".concat(data.body.code, ")"), transformErrorCode(data.body.code));
265
- emitError(error);
267
+ emitError(e);
266
268
  if (audioEmitter) {
267
269
  audioEmitter.dispatchEvent(new EmitterEvent('error', {
268
270
  detail: e
@@ -303,14 +305,14 @@ export function sendBlocksToAIStream(params) {
303
305
  } else if (block.type === 'file_path') {
304
306
  event.write({
305
307
  type: 'file',
306
- format: mimeTypeToFormatMap[block.file_url.mimeType] || 0,
308
+ format: mimeTypeToFormatMap[block.file_path.mimeType] || 0,
307
309
  path: block.file_path.path
308
310
  }).catch(emitError);
309
311
  } else if (block.type === 'video_path') {
310
312
  event.write({
311
313
  type: 'file',
312
314
  format: FileFormat.MP4,
313
- path: block.file_path.path
315
+ path: block.video_path.path
314
316
  }).catch(emitError);
315
317
  }
316
318
  }
@@ -36,11 +36,11 @@ export declare const getAppInfo: (options?: Omit<GetAppInfoParams, "success" | "
36
36
  regionCode: string;
37
37
  appName: string;
38
38
  appIcon: string;
39
- appEnv?: number | undefined;
39
+ appEnv?: number;
40
40
  appBundleId: string;
41
41
  appScheme: string;
42
42
  appId: string;
43
- clientId?: string | undefined;
43
+ clientId?: string;
44
44
  }>;
45
45
  export declare const canIUseRouter: (options?: Omit<CanIUseRouterParams, "success" | "fail"> | undefined) => Promise<{
46
46
  result: boolean;
@@ -57,7 +57,7 @@ export declare const openMiniWidget: (options?: Omit<OpenMiniWidgetParams, "succ
57
57
  export declare const isConnected: (options?: Omit<IsConnectedParams, "success" | "fail"> | undefined) => Promise<{
58
58
  connected: boolean;
59
59
  state: number;
60
- connectionId?: string | undefined;
60
+ connectionId?: string;
61
61
  }>;
62
62
  export declare const connect: (options?: Omit<ConnectParams, "success" | "fail"> | undefined) => Promise<{
63
63
  connectionId: string;
@@ -66,7 +66,7 @@ export declare const disconnect: (options?: Omit<DisconnectParams, "success" | "
66
66
  export declare const queryAgentToken: (options?: Omit<QueryAgentTokenParams, "success" | "fail"> | undefined) => Promise<{
67
67
  agentToken: string;
68
68
  bizConfig: import("../AIStreamTypes").BizConfig;
69
- extParams?: string | undefined;
69
+ extParams?: string;
70
70
  }>;
71
71
  export declare const createSession: (options?: Omit<CreateSessionParams, "success" | "fail"> | undefined) => Promise<{
72
72
  sessionId: string;
@@ -73,10 +73,10 @@ export declare function withAIStream(options?: AIStreamOptions): (agent: ChatAge
73
73
  metaPromise: Promise<Record<string, any>>;
74
74
  };
75
75
  chat: (blocks: InputBlock[], signal?: AbortSignalObject, options?: {
76
- sendBy?: string | undefined;
77
- responseBy?: string | undefined;
78
- userData?: AIStreamUserData | undefined;
79
- } | undefined) => Promise<ChatMessage[]>;
76
+ sendBy?: string;
77
+ responseBy?: string;
78
+ userData?: AIStreamUserData;
79
+ }) => Promise<ChatMessage[]>;
80
80
  options: AIStreamOptions;
81
81
  removeMessage: (message: ChatMessage) => Promise<void>;
82
82
  clearAllMessages: () => Promise<void>;
@@ -87,15 +87,15 @@ export declare function withAIStream(options?: AIStreamOptions): (agent: ChatAge
87
87
  thingjson?: any;
88
88
  data: string;
89
89
  }>;
90
- onSkillCompose: (fn: AIStreamHooks['onSkillCompose']) => () => void;
91
- onChatMessageSent: (fn: AIStreamHooks['onChatMessageSent']) => () => void;
92
- onTextCompose: (fn: AIStreamHooks['onTextCompose']) => () => void;
93
- onSkillsEnd: (fn: AIStreamHooks['onSkillsEnd']) => () => void;
94
- onCardsReceived: (fn: AIStreamHooks['onCardsReceived']) => () => void;
95
- onUserDataRead: (fn: AIStreamHooks['onUserDataRead']) => () => void;
96
- onSessionEventReceived: (fn: AIStreamHooks['onSessionEventReceived']) => () => void;
90
+ onSkillCompose: (fn: AIStreamHooks["onSkillCompose"]) => () => void;
91
+ onChatMessageSent: (fn: AIStreamHooks["onChatMessageSent"]) => () => void;
92
+ onTextCompose: (fn: AIStreamHooks["onTextCompose"]) => () => void;
93
+ onSkillsEnd: (fn: AIStreamHooks["onSkillsEnd"]) => () => void;
94
+ onCardsReceived: (fn: AIStreamHooks["onCardsReceived"]) => () => void;
95
+ onUserDataRead: (fn: AIStreamHooks["onUserDataRead"]) => () => void;
96
+ onSessionEventReceived: (fn: AIStreamHooks["onSessionEventReceived"]) => () => void;
97
97
  sendEvent: (params: SendAIStreamEventParams) => Promise<null>;
98
- onTTTAction: (fn: AIStreamHooks['onTTTAction']) => () => void;
98
+ onTTTAction: (fn: AIStreamHooks["onTTTAction"]) => () => void;
99
99
  getChatId: () => Promise<string>;
100
100
  };
101
101
  };
@@ -611,7 +611,7 @@ export function withAIStream() {
611
611
  }
612
612
  }
613
613
  if ((_skill$general = skill.general) !== null && _skill$general !== void 0 && (_skill$general = _skill$general.data) !== null && _skill$general !== void 0 && _skill$general.aiCards) {
614
- for (const card of skill.custom.data.aiCards) {
614
+ for (const card of skill.general.data.aiCards) {
615
615
  cards.push(card);
616
616
  }
617
617
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.8-beta.1",
3
+ "version": "0.2.8-beta.2",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -21,7 +21,9 @@
21
21
  "scripts": {
22
22
  "dev": "ray start --type=component --output dist --emit-declaration-dev",
23
23
  "build": "ray build --type=component --output dist",
24
- "clean": "rimraf ./dist"
24
+ "clean": "rimraf ./dist",
25
+ "test": "jest --runInBand",
26
+ "test:coverage": "jest --runInBand --coverage"
25
27
  },
26
28
  "dependencies": {
27
29
  "dayjs": "^1.10.4",
@@ -35,5 +37,5 @@
35
37
  "devDependencies": {
36
38
  "@types/url-parse": "^1.4.11"
37
39
  },
38
- "gitHead": "040499ca11aedda3246121f880807da0f8af3cc9"
40
+ "gitHead": "450ca8d41536094b3bea57198fd7724ba6812438"
39
41
  }