ai-world-sdk 1.5.0 → 1.5.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.
- package/dist/cli/commands/auth.js +21 -11
- package/dist/cli/commands/version.d.ts +2 -0
- package/dist/cli/commands/version.js +62 -0
- package/dist/cli/index.js +3 -0
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/package.json +1 -1
|
@@ -20,11 +20,11 @@ function applyRootDebug(program) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
function registerAuthCommands(program) {
|
|
23
|
-
|
|
24
|
-
auth
|
|
23
|
+
program
|
|
25
24
|
.command('login')
|
|
26
|
-
.
|
|
27
|
-
.option('--
|
|
25
|
+
.description('登录 AI World(浏览器 OAuth 或直接设置 token)')
|
|
26
|
+
.option('--token <jwt>', '直接设置 JWT token')
|
|
27
|
+
.option('--timeout <ms>', 'OAuth 超时毫秒数', (v) => parseInt(v, 10))
|
|
28
28
|
.action(async (opts) => {
|
|
29
29
|
try {
|
|
30
30
|
applyRootDebug(program);
|
|
@@ -54,10 +54,13 @@ function registerAuthCommands(program) {
|
|
|
54
54
|
(0, output_1.output)({ ok: true, baseUrl: merged.baseUrl, pluginId: pluginId ?? merged.pluginId }, format);
|
|
55
55
|
}
|
|
56
56
|
catch (e) {
|
|
57
|
-
(0, utils_1.handleError)(e, '
|
|
57
|
+
(0, utils_1.handleError)(e, 'login');
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
-
|
|
60
|
+
program
|
|
61
|
+
.command('logout')
|
|
62
|
+
.description('退出登录(清除缓存 token)')
|
|
63
|
+
.action(() => {
|
|
61
64
|
try {
|
|
62
65
|
const cfg = (0, config_2.readConfig)();
|
|
63
66
|
delete cfg.token;
|
|
@@ -66,13 +69,17 @@ function registerAuthCommands(program) {
|
|
|
66
69
|
(0, output_1.output)({ ok: true, loggedOut: true }, format);
|
|
67
70
|
}
|
|
68
71
|
catch (e) {
|
|
69
|
-
(0, utils_1.handleError)(e, '
|
|
72
|
+
(0, utils_1.handleError)(e, 'logout');
|
|
70
73
|
}
|
|
71
74
|
});
|
|
72
|
-
|
|
75
|
+
program
|
|
76
|
+
.command('me')
|
|
77
|
+
.description('查看当前用户信息')
|
|
78
|
+
.action(async () => {
|
|
73
79
|
try {
|
|
74
80
|
applyRootDebug(program);
|
|
75
81
|
const merged = (0, config_2.resolveAuth)(program.opts());
|
|
82
|
+
resetSdkAuthState();
|
|
76
83
|
(0, utils_1.initSDK)(merged);
|
|
77
84
|
const client = new auth_1.AuthClient();
|
|
78
85
|
const user = await client.getCurrentUserInfo();
|
|
@@ -80,10 +87,13 @@ function registerAuthCommands(program) {
|
|
|
80
87
|
(0, output_1.output)(user, format);
|
|
81
88
|
}
|
|
82
89
|
catch (e) {
|
|
83
|
-
(0, utils_1.handleError)(e, '
|
|
90
|
+
(0, utils_1.handleError)(e, 'me');
|
|
84
91
|
}
|
|
85
92
|
});
|
|
86
|
-
|
|
93
|
+
program
|
|
94
|
+
.command('status')
|
|
95
|
+
.description('检查认证状态')
|
|
96
|
+
.action(async () => {
|
|
87
97
|
try {
|
|
88
98
|
applyRootDebug(program);
|
|
89
99
|
const merged = (0, config_2.resolveAuth)(program.opts());
|
|
@@ -104,7 +114,7 @@ function registerAuthCommands(program) {
|
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
catch (e) {
|
|
107
|
-
(0, utils_1.handleError)(e, '
|
|
117
|
+
(0, utils_1.handleError)(e, 'status');
|
|
108
118
|
}
|
|
109
119
|
});
|
|
110
120
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerVersionCommand = registerVersionCommand;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const output_1 = require("../output");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
function getLatestVersion() {
|
|
8
|
+
try {
|
|
9
|
+
return (0, child_process_1.execSync)('npm view ai-world-sdk version', {
|
|
10
|
+
encoding: 'utf-8',
|
|
11
|
+
timeout: 10000,
|
|
12
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
13
|
+
}).trim();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function compareVersions(current, latest) {
|
|
20
|
+
const a = current.split('.').map(Number);
|
|
21
|
+
const b = latest.split('.').map(Number);
|
|
22
|
+
for (let i = 0; i < 3; i++) {
|
|
23
|
+
if ((a[i] || 0) < (b[i] || 0))
|
|
24
|
+
return -1;
|
|
25
|
+
if ((a[i] || 0) > (b[i] || 0))
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
function registerVersionCommand(program) {
|
|
31
|
+
program
|
|
32
|
+
.command('version')
|
|
33
|
+
.description('显示版本号并检查更新')
|
|
34
|
+
.action(() => {
|
|
35
|
+
try {
|
|
36
|
+
const currentVersion = require('../../../package.json').version;
|
|
37
|
+
const latest = getLatestVersion();
|
|
38
|
+
const result = {
|
|
39
|
+
current: currentVersion,
|
|
40
|
+
};
|
|
41
|
+
if (latest) {
|
|
42
|
+
result.latest = latest;
|
|
43
|
+
const cmp = compareVersions(currentVersion, latest);
|
|
44
|
+
if (cmp < 0) {
|
|
45
|
+
result.updateAvailable = true;
|
|
46
|
+
result.updateCommand = 'npm install -g ai-world-sdk';
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
result.updateAvailable = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
result.latest = null;
|
|
54
|
+
result.updateAvailable = null;
|
|
55
|
+
}
|
|
56
|
+
(0, output_1.outputJSON)(result);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
(0, utils_1.handleError)(e, 'version');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
4
5
|
const commander_1 = require("commander");
|
|
5
6
|
const utils_1 = require("./utils");
|
|
6
7
|
const program = new commander_1.Command();
|
|
@@ -13,6 +14,7 @@ program
|
|
|
13
14
|
.option('--plugin-id <id>', '插件 ID')
|
|
14
15
|
.option('--format <fmt>', '输出格式: json | table', 'json')
|
|
15
16
|
.option('--debug', '启用调试输出');
|
|
17
|
+
const version_1 = require("./commands/version");
|
|
16
18
|
const auth_1 = require("./commands/auth");
|
|
17
19
|
const config_cmd_1 = require("./commands/config-cmd");
|
|
18
20
|
const text_1 = require("./commands/text");
|
|
@@ -27,6 +29,7 @@ const admin_1 = require("./commands/admin");
|
|
|
27
29
|
const stats_1 = require("./commands/stats");
|
|
28
30
|
const shared_1 = require("./commands/shared");
|
|
29
31
|
const chrome_1 = require("./commands/chrome");
|
|
32
|
+
(0, version_1.registerVersionCommand)(program);
|
|
30
33
|
(0, auth_1.registerAuthCommands)(program);
|
|
31
34
|
(0, config_cmd_1.registerConfigCommands)(program);
|
|
32
35
|
(0, text_1.registerTextCommands)(program);
|
package/dist/config.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
11
11
|
*/
|
|
12
|
-
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.
|
|
12
|
+
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.2";
|
|
13
13
|
/**
|
|
14
14
|
* 版本兼容性错误
|
|
15
15
|
*/
|
|
@@ -34,8 +34,8 @@ declare class SDKConfig {
|
|
|
34
34
|
private _authenticated;
|
|
35
35
|
private _authCheckPromise;
|
|
36
36
|
private _currentUser;
|
|
37
|
-
readonly sdkSignature = "AI_WORLD_SDK_V:1.5.
|
|
38
|
-
readonly sdkVersion = "1.5.
|
|
37
|
+
readonly sdkSignature = "AI_WORLD_SDK_V:1.5.2";
|
|
38
|
+
readonly sdkVersion = "1.5.2";
|
|
39
39
|
constructor();
|
|
40
40
|
/**
|
|
41
41
|
* Set global base URL
|
package/dist/config.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.sdkConfig = exports.VersionCompatibilityError = exports.SDK_SIGNATURE = void 0;
|
|
8
8
|
// SDK 版本号(构建时自动从 package.json 更新)
|
|
9
9
|
// 此版本号会在运行 npm run build 时自动从 package.json 读取并更新
|
|
10
|
-
const SDK_VERSION = "1.5.
|
|
10
|
+
const SDK_VERSION = "1.5.2";
|
|
11
11
|
/**
|
|
12
12
|
* SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
|
|
13
13
|
* 格式: AI_WORLD_SDK_V:版本号
|
|
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.5.0";
|
|
|
15
15
|
*
|
|
16
16
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
17
17
|
*/
|
|
18
|
-
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.
|
|
18
|
+
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.2";
|
|
19
19
|
/**
|
|
20
20
|
* 版本兼容性错误
|
|
21
21
|
*/
|
package/package.json
CHANGED