@ray-js/t-agent-plugin-aistream 0.2.3-beta-5 → 0.2.4-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.
@@ -0,0 +1 @@
1
+ export declare function authorizeAssistantPolicy(): Promise<boolean>;
@@ -0,0 +1,51 @@
1
+ import { authorizePolicyStatus, listenReceiveMessage, openMiniWidget, registerChannel } from './ttt';
2
+ import logger from './logger';
3
+ import { AuthorizePolicySign } from '../AIStreamTypes';
4
+ export async function authorizeAssistantPolicy() {
5
+ // @ts-ignore
6
+ if (!ty.authorizePolicyStatus) {
7
+ logger.warn('authorizeAssistantPolicy: ty.authorizePolicyStatus not found, check if BaseKit >= 3.20.4');
8
+ // 不支持权限状态查询,直接返回true
9
+ return true;
10
+ }
11
+ const {
12
+ sign
13
+ } = await authorizePolicyStatus({
14
+ type: 'ai_algorithm'
15
+ });
16
+ if (sign === AuthorizePolicySign.AUTHORIZED) {
17
+ // 已授权,直接返回true
18
+ return true;
19
+ }
20
+
21
+ // 未授权,打开小程序授权
22
+ await registerChannel({
23
+ eventName: 'AIAuthorization'
24
+ });
25
+ const resultPromise = new Promise(resolve => {
26
+ // 一次性事件
27
+ const cancel = listenReceiveMessage(res => {
28
+ const {
29
+ status
30
+ } = res.event || {};
31
+ if (status) {
32
+ // 同意,直接进入
33
+ resolve(true);
34
+ } else {
35
+ resolve(false);
36
+ }
37
+ cancel();
38
+ });
39
+ });
40
+
41
+ // 打开小程序授权
42
+ await openMiniWidget({
43
+ appId: 'ty9mvmbhtvwrp5zbla',
44
+ pagePath: 'cards/index',
45
+ autoDismiss: false,
46
+ autoCache: false,
47
+ // versionType: ty.WidgetVersionType.preview,
48
+ style: '0.68'
49
+ });
50
+ return resultPromise;
51
+ }
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.3-beta-5",
3
+ "version": "0.2.4-beta-2",
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": "a99e7ff0c22890381a0ba9a193060ab6d69cb915"
38
+ "gitHead": "3566263a43775a512420e832d5d9bef68ff82ded"
39
39
  }