@ray-js/t-agent-plugin-aistream 0.2.4-beta-1 → 0.2.4-beta-3

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.
@@ -3,7 +3,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
3
  import "core-js/modules/es.json.stringify.js";
4
4
  import "core-js/modules/es.promise.finally.js";
5
5
  import "core-js/modules/web.dom-collections.iterator.js";
6
- import { authorize, getCurrentHomeInfo, initAudioRecorder } from '../utils';
6
+ import { authorize, authorizeStatus, getCurrentHomeInfo, initAudioRecorder } from '../utils';
7
7
  import { AIStreamAttributePayloadType, AIStreamAttributeType, ConnectClientType, ConnectState, ReceivedTextPacketType, SessionState } from '../AIStreamTypes';
8
8
  import { DEFAULT_TOKEN_API, DEFAULT_TOKEN_API_VERSION, globalAIStreamClient } from '../global';
9
9
  import { Logger, safeParseJSON } from '@ray-js/t-agent';
@@ -46,10 +46,20 @@ export class AsrAgent {
46
46
  } = options;
47
47
  const sampleRate = recordingOptions === null || recordingOptions === void 0 ? void 0 : recordingOptions.sampleRate;
48
48
  // 如果需要提前启动,直接初始化和创建连接
49
- this.createSession().then(session => session.ensureSession()).then(() => initAudioRecorder(sampleRate ? {
50
- sampleRate
51
- } : {})).catch(error => {
52
- logger.error('EarlyStart Failed to create ASR session:', error);
49
+ this.createSession().then(session => session.ensureSession()).then(() => authorizeStatus({
50
+ scope: 'scope.record'
51
+ }).then(() => true, () => false)).then(authorized => {
52
+ this.authorized = authorized;
53
+ if (!authorized) {
54
+ logger.log('AsrAgent EarlyStart: No record permission granted');
55
+ return Promise.resolve();
56
+ }
57
+ // 初始化录音
58
+ return initAudioRecorder(sampleRate ? {
59
+ sampleRate
60
+ } : {});
61
+ }).catch(error => {
62
+ logger.error('AsrAgent EarlyStart Failed to create ASR session:', error);
53
63
  });
54
64
  }
55
65
  if (this.options.enableLog) {
@@ -10,4 +10,5 @@ export * from './observer';
10
10
  export * from './sendMessage';
11
11
  export * from './version';
12
12
  export * from './actions';
13
+ export * from './authorizePolicy';
13
14
  export { mock };
@@ -10,4 +10,5 @@ export * from './observer';
10
10
  export * from './sendMessage';
11
11
  export * from './version';
12
12
  export * from './actions';
13
+ export * from './authorizePolicy';
13
14
  export { mock };
@@ -27,6 +27,7 @@ export declare const getCurrentHomeInfo: (options?: Omit<GetCurrentHomeInfoParam
27
27
  admin: boolean;
28
28
  }>;
29
29
  export declare const authorize: (options?: Omit<AuthorizeParams, "success" | "fail"> | undefined) => Promise<null>;
30
+ export declare const authorizeStatus: (options?: Omit<AuthorizeParams, "success" | "fail"> | undefined) => Promise<null>;
30
31
  export declare const getAppInfo: (options?: Omit<GetAppInfoParams, "success" | "fail"> | undefined) => Promise<{
31
32
  serverTimestamp: number;
32
33
  appVersion: string;
package/dist/utils/ttt.js CHANGED
@@ -18,6 +18,7 @@ export const createNativeEventManager = options => {
18
18
  };
19
19
  export const getCurrentHomeInfo = promisify(ty.home.getCurrentHomeInfo);
20
20
  export const authorize = promisify(ty.authorize, true);
21
+ export const authorizeStatus = promisify(ty.authorizeStatus, true);
21
22
  export const getAppInfo = promisify(ty.getAppInfo);
22
23
  export const canIUseRouter = promisify(ty.canIUseRouter);
23
24
  export const router = promisify(ty.router);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.4-beta-1",
3
+ "version": "0.2.4-beta-3",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@types/url-parse": "^1.4.11"
37
37
  },
38
- "gitHead": "83f32cc9add5ebd4c30b426b3593d51c1893b2eb"
38
+ "gitHead": "016df89f662740579e1135f25954cbd3ceabbd27"
39
39
  }