@ray-js/t-agent-plugin-aistream 0.2.3-beta-5 → 0.2.4-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.
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-plugin-aistream",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4-beta-1",
|
|
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": "
|
|
38
|
+
"gitHead": "83f32cc9add5ebd4c30b426b3593d51c1893b2eb"
|
|
39
39
|
}
|