@honor-claw/yoyo 1.1.2 → 1.1.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.
- package/index.ts +25 -25
- package/package.json +5 -5
- package/src/apis/claw-cloud.ts +124 -124
- package/src/apis/helpers.ts +10 -10
- package/src/apis/honor-auth.ts +158 -158
- package/src/apis/http-client.ts +239 -239
- package/src/apis/index.ts +8 -8
- package/src/apis/types.ts +77 -73
- package/src/cloud-channel/channel.ts +117 -117
- package/src/cloud-channel/client.ts +3 -3
- package/src/cloud-channel/index.ts +4 -4
- package/src/cloud-channel/message-handler.ts +50 -42
- package/src/cloud-channel/session-manager.ts +14 -9
- package/src/cloud-channel/types.ts +115 -115
- package/src/commands/env/impl.ts +58 -58
- package/src/commands/env/index.ts +1 -1
- package/src/commands/index.ts +30 -30
- package/src/commands/login/impl.ts +30 -30
- package/src/commands/login/index.ts +1 -1
- package/src/commands/logout/index.ts +1 -1
- package/src/commands/status/index.ts +194 -194
- package/src/gateway-client/client.ts +90 -90
- package/src/gateway-client/device/auth.ts +57 -57
- package/src/gateway-client/device/builder.ts +105 -105
- package/src/gateway-client/device/helpers.ts +40 -40
- package/src/gateway-client/device/identity.ts +251 -251
- package/src/gateway-client/device/index.ts +40 -40
- package/src/gateway-client/device/types.ts +57 -57
- package/src/gateway-client/index.ts +5 -5
- package/src/gateway-client/protocol-client.ts +49 -34
- package/src/honor-auth/browser.ts +2 -2
- package/src/honor-auth/callback-server.ts +109 -109
- package/src/honor-auth/cloud.ts +57 -57
- package/src/honor-auth/config.ts +43 -43
- package/src/honor-auth/index.ts +3 -3
- package/src/honor-auth/token-manager.ts +90 -90
- package/src/honor-auth/types.ts +50 -50
- package/src/index.ts +10 -10
- package/src/modules/claw-configs/config-manager.ts +409 -409
- package/src/modules/claw-configs/hosts.ts +48 -48
- package/src/modules/claw-configs/index.ts +8 -8
- package/src/modules/claw-configs/provider.ts +394 -394
- package/src/modules/claw-configs/types.ts +34 -34
- package/src/modules/device/device-info.ts +1 -1
- package/src/modules/device/index.ts +3 -3
- package/src/modules/device/providers/base.ts +32 -32
- package/src/modules/device/providers/pad.ts +107 -107
- package/src/modules/device/providers/windows.ts +130 -130
- package/src/modules/device/registry.ts +48 -43
- package/src/modules/login/impl.ts +31 -26
- package/src/modules/login/index.ts +6 -6
- package/src/schemas.ts +23 -23
- package/src/services/connection/impl.ts +339 -339
- package/src/services/connection/status-tracker/events.ts +127 -127
- package/src/services/connection/status-tracker/index.ts +31 -31
- package/src/services/connection/status-tracker/storage.ts +133 -133
- package/src/services/connection/status-tracker/tracker.ts +370 -370
- package/src/services/connection/status-tracker/types.ts +131 -131
- package/src/services/connection/types.ts +20 -20
- package/src/types.ts +64 -64
- package/src/utils/id.ts +8 -8
- package/src/utils/jwt.ts +37 -37
- package/src/utils/logger.ts +20 -20
- package/src/utils/proxy.ts +58 -58
- package/src/utils/version.ts +29 -29
- package/src/utils/ws.ts +21 -21
package/src/honor-auth/config.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 荣耀认证配置管理
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { HonorAuthConfig } from "./types.js";
|
|
6
|
-
import { getYoyoEnv } from "../runtime.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 默认配置
|
|
10
|
-
*/
|
|
11
|
-
const TEST_ENV_CONFIG: HonorAuthConfig = {
|
|
12
|
-
authHost: "https://hnoauth-login-test-drcn.cloud.honor.com",
|
|
13
|
-
clientId: "221641491",
|
|
14
|
-
redirectUri: "http://127.0.0.1:8081/deepLink",
|
|
15
|
-
localPort: 8081,
|
|
16
|
-
scope: "openid profile",
|
|
17
|
-
reqClientType: "110",
|
|
18
|
-
loginChannel: "99011000",
|
|
19
|
-
};
|
|
20
|
-
const PRD_ENV_CONFIG: HonorAuthConfig = {
|
|
21
|
-
authHost: "https://hnoauth-login-drcn.cloud.honor.com",
|
|
22
|
-
clientId: "221000597",
|
|
23
|
-
redirectUri: "http://127.0.0.1:8081/deepLink",
|
|
24
|
-
localPort: 8081,
|
|
25
|
-
scope: "openid profile",
|
|
26
|
-
reqClientType: "110",
|
|
27
|
-
loginChannel: "99011000",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 获取配置(支持自定义覆盖)
|
|
32
|
-
* 根据当前运行环境自动选择对应的配置
|
|
33
|
-
*/
|
|
34
|
-
export function getConfig(
|
|
35
|
-
overrides?: Partial<HonorAuthConfig>
|
|
36
|
-
): HonorAuthConfig {
|
|
37
|
-
const env = getYoyoEnv();
|
|
38
|
-
const baseConfig = env === 'production' ? PRD_ENV_CONFIG : TEST_ENV_CONFIG;
|
|
39
|
-
return {
|
|
40
|
-
...baseConfig,
|
|
41
|
-
...overrides,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 荣耀认证配置管理
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HonorAuthConfig } from "./types.js";
|
|
6
|
+
import { getYoyoEnv } from "../runtime.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 默认配置
|
|
10
|
+
*/
|
|
11
|
+
const TEST_ENV_CONFIG: HonorAuthConfig = {
|
|
12
|
+
authHost: "https://hnoauth-login-test-drcn.cloud.honor.com",
|
|
13
|
+
clientId: "221641491",
|
|
14
|
+
redirectUri: "http://127.0.0.1:8081/deepLink",
|
|
15
|
+
localPort: 8081,
|
|
16
|
+
scope: "openid profile",
|
|
17
|
+
reqClientType: "110",
|
|
18
|
+
loginChannel: "99011000",
|
|
19
|
+
};
|
|
20
|
+
const PRD_ENV_CONFIG: HonorAuthConfig = {
|
|
21
|
+
authHost: "https://hnoauth-login-drcn.cloud.honor.com",
|
|
22
|
+
clientId: "221000597",
|
|
23
|
+
redirectUri: "http://127.0.0.1:8081/deepLink",
|
|
24
|
+
localPort: 8081,
|
|
25
|
+
scope: "openid profile",
|
|
26
|
+
reqClientType: "110",
|
|
27
|
+
loginChannel: "99011000",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 获取配置(支持自定义覆盖)
|
|
32
|
+
* 根据当前运行环境自动选择对应的配置
|
|
33
|
+
*/
|
|
34
|
+
export function getConfig(
|
|
35
|
+
overrides?: Partial<HonorAuthConfig>
|
|
36
|
+
): HonorAuthConfig {
|
|
37
|
+
const env = getYoyoEnv();
|
|
38
|
+
const baseConfig = env === 'production' ? PRD_ENV_CONFIG : TEST_ENV_CONFIG;
|
|
39
|
+
return {
|
|
40
|
+
...baseConfig,
|
|
41
|
+
...overrides,
|
|
42
|
+
};
|
|
43
|
+
}
|
package/src/honor-auth/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './browser.js';
|
|
2
|
-
export * from './cloud.js';
|
|
3
|
-
export * from './token-manager.js';
|
|
1
|
+
export * from './browser.js';
|
|
2
|
+
export * from './cloud.js';
|
|
3
|
+
export * from './token-manager.js';
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token管理器 - 负责token的读写缓存
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { TokenResponse } from "./types.js";
|
|
6
|
-
import type { HonorUserInfo } from "../types.js";
|
|
7
|
-
import { getConfigManager } from "../modules/claw-configs/index.js";
|
|
8
|
-
import { useClawLogger } from "../utils/logger.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 保存Token到openclaw配置文件
|
|
12
|
-
*/
|
|
13
|
-
export async function saveToken(
|
|
14
|
-
token: TokenResponse,
|
|
15
|
-
saveToFile: boolean = true
|
|
16
|
-
): Promise<void> {
|
|
17
|
-
try {
|
|
18
|
-
if (!saveToFile) {
|
|
19
|
-
console.log("💾 Token已获取(未保存到文件)");
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const configManager = getConfigManager();
|
|
24
|
-
|
|
25
|
-
// 计算过期时间(假设token有效期为30天)
|
|
26
|
-
const expired = Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60;
|
|
27
|
-
|
|
28
|
-
// 更新用户配置
|
|
29
|
-
await configManager.updateUserConfig({
|
|
30
|
-
token: token.token,
|
|
31
|
-
expired,
|
|
32
|
-
userId: token.userInfo?.userId,
|
|
33
|
-
userName: token.userInfo?.displayName,
|
|
34
|
-
});
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
`保存Token失败: ${error instanceof Error ? error.message : String(error)}`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 从openclaw配置文件加载Token
|
|
44
|
-
*/
|
|
45
|
-
export async function loadToken(): Promise<HonorUserInfo | null> {
|
|
46
|
-
try {
|
|
47
|
-
const configManager = getConfigManager();
|
|
48
|
-
const userConfig = configManager.getUserConfig();
|
|
49
|
-
|
|
50
|
-
// todo 上线前移除
|
|
51
|
-
if (!userConfig?.token) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 检查是否过期
|
|
56
|
-
if (
|
|
57
|
-
userConfig.expired &&
|
|
58
|
-
userConfig.expired < Math.floor(Date.now() / 1000)
|
|
59
|
-
) {
|
|
60
|
-
// Token已过期,从配置中移除
|
|
61
|
-
await configManager.clearUserConfig();
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
userId: userConfig.userId || "",
|
|
67
|
-
token: userConfig.token,
|
|
68
|
-
userName: userConfig.userName,
|
|
69
|
-
};
|
|
70
|
-
} catch (error) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
`加载Token失败: ${error instanceof Error ? error.message : String(error)}`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 清除Token(用于登出或设备未注册场景)
|
|
79
|
-
*/
|
|
80
|
-
export async function clearToken(): Promise<void> {
|
|
81
|
-
try {
|
|
82
|
-
const configManager = getConfigManager();
|
|
83
|
-
await configManager.clearUserConfig();
|
|
84
|
-
useClawLogger().info("[yoyoclaw-auth] token cleared");
|
|
85
|
-
} catch (error) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`清除Token失败: ${error instanceof Error ? error.message : String(error)}`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Token管理器 - 负责token的读写缓存
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { TokenResponse } from "./types.js";
|
|
6
|
+
import type { HonorUserInfo } from "../types.js";
|
|
7
|
+
import { getConfigManager } from "../modules/claw-configs/index.js";
|
|
8
|
+
import { useClawLogger } from "../utils/logger.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 保存Token到openclaw配置文件
|
|
12
|
+
*/
|
|
13
|
+
export async function saveToken(
|
|
14
|
+
token: TokenResponse,
|
|
15
|
+
saveToFile: boolean = true
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
try {
|
|
18
|
+
if (!saveToFile) {
|
|
19
|
+
console.log("💾 Token已获取(未保存到文件)");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const configManager = getConfigManager();
|
|
24
|
+
|
|
25
|
+
// 计算过期时间(假设token有效期为30天)
|
|
26
|
+
const expired = Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60;
|
|
27
|
+
|
|
28
|
+
// 更新用户配置
|
|
29
|
+
await configManager.updateUserConfig({
|
|
30
|
+
token: token.token,
|
|
31
|
+
expired,
|
|
32
|
+
userId: token.userInfo?.userId,
|
|
33
|
+
userName: token.userInfo?.displayName,
|
|
34
|
+
});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`保存Token失败: ${error instanceof Error ? error.message : String(error)}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 从openclaw配置文件加载Token
|
|
44
|
+
*/
|
|
45
|
+
export async function loadToken(): Promise<HonorUserInfo | null> {
|
|
46
|
+
try {
|
|
47
|
+
const configManager = getConfigManager();
|
|
48
|
+
const userConfig = configManager.getUserConfig();
|
|
49
|
+
|
|
50
|
+
// todo 上线前移除
|
|
51
|
+
if (!userConfig?.token) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 检查是否过期
|
|
56
|
+
if (
|
|
57
|
+
userConfig.expired &&
|
|
58
|
+
userConfig.expired < Math.floor(Date.now() / 1000)
|
|
59
|
+
) {
|
|
60
|
+
// Token已过期,从配置中移除
|
|
61
|
+
await configManager.clearUserConfig();
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
userId: userConfig.userId || "",
|
|
67
|
+
token: userConfig.token,
|
|
68
|
+
userName: userConfig.userName,
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`加载Token失败: ${error instanceof Error ? error.message : String(error)}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 清除Token(用于登出或设备未注册场景)
|
|
79
|
+
*/
|
|
80
|
+
export async function clearToken(): Promise<void> {
|
|
81
|
+
try {
|
|
82
|
+
const configManager = getConfigManager();
|
|
83
|
+
await configManager.clearUserConfig();
|
|
84
|
+
useClawLogger().info("[yoyoclaw-auth] token cleared");
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`清除Token失败: ${error instanceof Error ? error.message : String(error)}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/honor-auth/types.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 荣耀OAuth2认证相关类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 荣耀认证配置
|
|
7
|
-
*/
|
|
8
|
-
export interface HonorAuthConfig {
|
|
9
|
-
/** 认证服务器地址 */
|
|
10
|
-
authHost: string;
|
|
11
|
-
/** 客户端ID */
|
|
12
|
-
clientId: string;
|
|
13
|
-
/** 回调地址 */
|
|
14
|
-
redirectUri: string;
|
|
15
|
-
/** 本地监听端口 */
|
|
16
|
-
localPort: number;
|
|
17
|
-
/** 授权范围 */
|
|
18
|
-
scope: string;
|
|
19
|
-
/** 请求客户端类型 */
|
|
20
|
-
reqClientType: string;
|
|
21
|
-
/** 登录渠道 */
|
|
22
|
-
loginChannel: string;
|
|
23
|
-
/** 代理地址,例如:http://127.0.0.1:7890 */
|
|
24
|
-
proxy?: string;
|
|
25
|
-
/** 是否保存token到配置文件,默认为true */
|
|
26
|
-
saveToFile?: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Token响应
|
|
31
|
-
*/
|
|
32
|
-
export type TokenResponse = {
|
|
33
|
-
token?: string;
|
|
34
|
-
userInfo?: ApiUserInfo;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Token响应
|
|
39
|
-
*/
|
|
40
|
-
export type TokenResponseV2 = {
|
|
41
|
-
jwtToken?: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 用户信息
|
|
46
|
-
*/
|
|
47
|
-
export interface ApiUserInfo {
|
|
48
|
-
userId: string;
|
|
49
|
-
displayName: string;
|
|
50
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 荣耀OAuth2认证相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 荣耀认证配置
|
|
7
|
+
*/
|
|
8
|
+
export interface HonorAuthConfig {
|
|
9
|
+
/** 认证服务器地址 */
|
|
10
|
+
authHost: string;
|
|
11
|
+
/** 客户端ID */
|
|
12
|
+
clientId: string;
|
|
13
|
+
/** 回调地址 */
|
|
14
|
+
redirectUri: string;
|
|
15
|
+
/** 本地监听端口 */
|
|
16
|
+
localPort: number;
|
|
17
|
+
/** 授权范围 */
|
|
18
|
+
scope: string;
|
|
19
|
+
/** 请求客户端类型 */
|
|
20
|
+
reqClientType: string;
|
|
21
|
+
/** 登录渠道 */
|
|
22
|
+
loginChannel: string;
|
|
23
|
+
/** 代理地址,例如:http://127.0.0.1:7890 */
|
|
24
|
+
proxy?: string;
|
|
25
|
+
/** 是否保存token到配置文件,默认为true */
|
|
26
|
+
saveToFile?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Token响应
|
|
31
|
+
*/
|
|
32
|
+
export type TokenResponse = {
|
|
33
|
+
token?: string;
|
|
34
|
+
userInfo?: ApiUserInfo;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Token响应
|
|
39
|
+
*/
|
|
40
|
+
export type TokenResponseV2 = {
|
|
41
|
+
jwtToken?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 用户信息
|
|
46
|
+
*/
|
|
47
|
+
export interface ApiUserInfo {
|
|
48
|
+
userId: string;
|
|
49
|
+
displayName: string;
|
|
50
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* YOYO Claw Extension 主入口
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from './honor-auth/index.js';
|
|
6
|
-
export * from './cloud-channel/index.js';
|
|
7
|
-
export * from './modules/login/index.js';
|
|
8
|
-
export * from './services/connection/index.js';
|
|
9
|
-
export * from './schemas.js';
|
|
10
|
-
export * from './types.js';
|
|
1
|
+
/**
|
|
2
|
+
* YOYO Claw Extension 主入口
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './honor-auth/index.js';
|
|
6
|
+
export * from './cloud-channel/index.js';
|
|
7
|
+
export * from './modules/login/index.js';
|
|
8
|
+
export * from './services/connection/index.js';
|
|
9
|
+
export * from './schemas.js';
|
|
10
|
+
export * from './types.js';
|