@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.
Files changed (66) hide show
  1. package/index.ts +25 -25
  2. package/package.json +5 -5
  3. package/src/apis/claw-cloud.ts +124 -124
  4. package/src/apis/helpers.ts +10 -10
  5. package/src/apis/honor-auth.ts +158 -158
  6. package/src/apis/http-client.ts +239 -239
  7. package/src/apis/index.ts +8 -8
  8. package/src/apis/types.ts +77 -73
  9. package/src/cloud-channel/channel.ts +117 -117
  10. package/src/cloud-channel/client.ts +3 -3
  11. package/src/cloud-channel/index.ts +4 -4
  12. package/src/cloud-channel/message-handler.ts +50 -42
  13. package/src/cloud-channel/session-manager.ts +14 -9
  14. package/src/cloud-channel/types.ts +115 -115
  15. package/src/commands/env/impl.ts +58 -58
  16. package/src/commands/env/index.ts +1 -1
  17. package/src/commands/index.ts +30 -30
  18. package/src/commands/login/impl.ts +30 -30
  19. package/src/commands/login/index.ts +1 -1
  20. package/src/commands/logout/index.ts +1 -1
  21. package/src/commands/status/index.ts +194 -194
  22. package/src/gateway-client/client.ts +90 -90
  23. package/src/gateway-client/device/auth.ts +57 -57
  24. package/src/gateway-client/device/builder.ts +105 -105
  25. package/src/gateway-client/device/helpers.ts +40 -40
  26. package/src/gateway-client/device/identity.ts +251 -251
  27. package/src/gateway-client/device/index.ts +40 -40
  28. package/src/gateway-client/device/types.ts +57 -57
  29. package/src/gateway-client/index.ts +5 -5
  30. package/src/gateway-client/protocol-client.ts +49 -34
  31. package/src/honor-auth/browser.ts +2 -2
  32. package/src/honor-auth/callback-server.ts +109 -109
  33. package/src/honor-auth/cloud.ts +57 -57
  34. package/src/honor-auth/config.ts +43 -43
  35. package/src/honor-auth/index.ts +3 -3
  36. package/src/honor-auth/token-manager.ts +90 -90
  37. package/src/honor-auth/types.ts +50 -50
  38. package/src/index.ts +10 -10
  39. package/src/modules/claw-configs/config-manager.ts +409 -409
  40. package/src/modules/claw-configs/hosts.ts +48 -48
  41. package/src/modules/claw-configs/index.ts +8 -8
  42. package/src/modules/claw-configs/provider.ts +394 -394
  43. package/src/modules/claw-configs/types.ts +34 -34
  44. package/src/modules/device/device-info.ts +1 -1
  45. package/src/modules/device/index.ts +3 -3
  46. package/src/modules/device/providers/base.ts +32 -32
  47. package/src/modules/device/providers/pad.ts +107 -107
  48. package/src/modules/device/providers/windows.ts +130 -130
  49. package/src/modules/device/registry.ts +48 -43
  50. package/src/modules/login/impl.ts +31 -26
  51. package/src/modules/login/index.ts +6 -6
  52. package/src/schemas.ts +23 -23
  53. package/src/services/connection/impl.ts +339 -339
  54. package/src/services/connection/status-tracker/events.ts +127 -127
  55. package/src/services/connection/status-tracker/index.ts +31 -31
  56. package/src/services/connection/status-tracker/storage.ts +133 -133
  57. package/src/services/connection/status-tracker/tracker.ts +370 -370
  58. package/src/services/connection/status-tracker/types.ts +131 -131
  59. package/src/services/connection/types.ts +20 -20
  60. package/src/types.ts +64 -64
  61. package/src/utils/id.ts +8 -8
  62. package/src/utils/jwt.ts +37 -37
  63. package/src/utils/logger.ts +20 -20
  64. package/src/utils/proxy.ts +58 -58
  65. package/src/utils/version.ts +29 -29
  66. package/src/utils/ws.ts +21 -21
@@ -1,34 +1,34 @@
1
- /**
2
- * Claw 配置类型定义
3
- */
4
-
5
- import type { OpenClawConfig } from 'openclaw/plugin-sdk';
6
-
7
- /**
8
- * Gateway 认证配置
9
- */
10
- export type GatewayAuthConfig = Pick<OpenClawConfig['gateway']['auth'], 'token' | 'password'>;
11
-
12
- /**
13
- * 用户配置信息
14
- */
15
- export interface UserConfig {
16
- token?: string;
17
- expired?: number;
18
- userId?: string;
19
- userName?: string;
20
- }
21
-
22
- /**
23
- * YoyoClaw 插件配置
24
- */
25
- export interface YoyoClawPluginConfig {
26
- enabled?: boolean;
27
- config?: {
28
- user?: UserConfig;
29
- /** 运行环境:test 或 production */
30
- env?: 'dev' | 'test' | 'production';
31
- /** 灰度标签 */
32
- gray?: string;
33
- };
34
- }
1
+ /**
2
+ * Claw 配置类型定义
3
+ */
4
+
5
+ import type { OpenClawConfig } from 'openclaw/plugin-sdk';
6
+
7
+ /**
8
+ * Gateway 认证配置
9
+ */
10
+ export type GatewayAuthConfig = Pick<NonNullable<NonNullable<OpenClawConfig['gateway']>['auth']>, 'token' | 'password'>;
11
+
12
+ /**
13
+ * 用户配置信息
14
+ */
15
+ export interface UserConfig {
16
+ token?: string;
17
+ expired?: number;
18
+ userId?: string;
19
+ userName?: string;
20
+ }
21
+
22
+ /**
23
+ * YoyoClaw 插件配置
24
+ */
25
+ export interface YoyoClawPluginConfig {
26
+ enabled?: boolean;
27
+ config?: {
28
+ user?: UserConfig;
29
+ /** 运行环境:test 或 production */
30
+ env?: 'dev' | 'test' | 'production';
31
+ /** 灰度标签 */
32
+ gray?: string;
33
+ };
34
+ }
@@ -77,6 +77,6 @@ export function getDeviceInfo(): DeviceInfo {
77
77
  port: configManager.getGatewayPort(),
78
78
  };
79
79
 
80
- useClawLogger().info(`[yoyoclaw-device] device info: ${JSON.stringify(deviceInfo)}`);
80
+ useClawLogger().debug?.(`[yoyoclaw-device] device info: ${JSON.stringify(deviceInfo)}`);
81
81
  return deviceInfo;
82
82
  }
@@ -1,3 +1,3 @@
1
- export * from './registry.js';
2
- export * from './device-info.js';
3
- export * from './providers/base.js';
1
+ export * from './registry.js';
2
+ export * from './device-info.js';
3
+ export * from './providers/base.js';
@@ -1,32 +1,32 @@
1
- import type { DeviceType } from "../../../types.js";
2
-
3
-
4
- /**
5
- * 设备信息提供者基础接口
6
- */
7
- export interface DeviceInfoProvider {
8
- /**
9
- * 获取设备唯一ID
10
- */
11
- getDeviceId(): string;
12
-
13
- /**
14
- * 获取设备名称
15
- */
16
- getDeviceName(): string;
17
-
18
- /**
19
- * 获取设备型号
20
- */
21
- getDeviceModel(): string;
22
-
23
- /**
24
- * 获取设备类型
25
- */
26
- getDeviceType(): DeviceType;
27
-
28
- /**
29
- * 获取设备品牌
30
- */
31
- getDeviceBrand(): string;
32
- }
1
+ import type { DeviceType } from "../../../types.js";
2
+
3
+
4
+ /**
5
+ * 设备信息提供者基础接口
6
+ */
7
+ export interface DeviceInfoProvider {
8
+ /**
9
+ * 获取设备唯一ID
10
+ */
11
+ getDeviceId(): string;
12
+
13
+ /**
14
+ * 获取设备名称
15
+ */
16
+ getDeviceName(): string;
17
+
18
+ /**
19
+ * 获取设备型号
20
+ */
21
+ getDeviceModel(): string;
22
+
23
+ /**
24
+ * 获取设备类型
25
+ */
26
+ getDeviceType(): DeviceType;
27
+
28
+ /**
29
+ * 获取设备品牌
30
+ */
31
+ getDeviceBrand(): string;
32
+ }
@@ -1,107 +1,107 @@
1
- /**
2
- * Pad 设备信息提供者
3
- */
4
- import { execSync } from 'child_process';
5
- import { createHash } from 'crypto';
6
- import type { DeviceInfoProvider } from './base.js';
7
- import type { DeviceType } from '../../../types.js';
8
-
9
- export class PadDevice implements DeviceInfoProvider {
10
- /**
11
- * 通过 /system/bin/getprop 获取 Android 系统属性
12
- */
13
- private getAndroidProp(prop: string): string {
14
- try {
15
- const result = execSync(`/system/bin/getprop ${prop}`, {
16
- encoding: 'utf-8',
17
- timeout: 5000,
18
- });
19
- const value = result.trim();
20
- return value || '';
21
- } catch {
22
- return '';
23
- }
24
- }
25
-
26
- /**
27
- * 获取 Android ID
28
- */
29
- private getAndroidId(): string {
30
- try {
31
- const result = execSync('/system/bin/settings get secure android_id', {
32
- encoding: 'utf-8',
33
- timeout: 5000,
34
- });
35
- const value = result.trim();
36
- return value && value !== 'null' ? value : '';
37
- } catch {
38
- return '';
39
- }
40
- }
41
-
42
- /**
43
- * 获取 Android 设备唯一ID (SHA256 哈希)
44
- */
45
- private getAndroidDeviceId(): string {
46
- const androidId = this.getAndroidId();
47
- const brand = this.getAndroidProp('ro.product.brand');
48
- const model = this.getAndroidProp('ro.product.model');
49
- const device = this.getAndroidProp('ro.product.device');
50
-
51
- const raw = `${androidId}_${brand}_${model}_${device}`;
52
- return createHash('sha256').update(raw, 'utf-8').digest('hex');
53
- }
54
-
55
- /**
56
- * 获取 Android 设备型号
57
- */
58
- private getAndroidDeviceModel(): string {
59
- const model = this.getAndroidProp('ro.product.model');
60
- return model || 'Android Device';
61
- }
62
-
63
- /**
64
- * 获取 Android 设备名称
65
- */
66
- private getAndroidDeviceName(): string {
67
- return this.getAndroidDeviceModel();
68
- }
69
-
70
- /**
71
- * 获取设备唯一ID
72
- */
73
- getDeviceId(): string {
74
- const deviceId = this.getAndroidDeviceId();
75
- return deviceId || 'invalid';
76
- }
77
-
78
- /**
79
- * 获取设备名称
80
- */
81
- getDeviceName(): string {
82
- return this.getAndroidDeviceName();
83
- }
84
-
85
- /**
86
- * 获取设备型号
87
- */
88
- getDeviceModel(): string {
89
- return this.getAndroidDeviceModel();
90
- }
91
-
92
- /**
93
- * 获取设备类型
94
- */
95
- getDeviceType(): DeviceType {
96
- return 'pad';
97
- }
98
-
99
- /**
100
- * 获取设备品牌
101
- */
102
- getDeviceBrand(): string {
103
- const brand = this.getAndroidProp('ro.product.brand');
104
-
105
- return brand.toLowerCase() === 'honor' ? 'HONOR' : '';
106
- }
107
- }
1
+ /**
2
+ * Pad 设备信息提供者
3
+ */
4
+ import { execSync } from 'child_process';
5
+ import { createHash } from 'crypto';
6
+ import type { DeviceInfoProvider } from './base.js';
7
+ import type { DeviceType } from '../../../types.js';
8
+
9
+ export class PadDevice implements DeviceInfoProvider {
10
+ /**
11
+ * 通过 /system/bin/getprop 获取 Android 系统属性
12
+ */
13
+ private getAndroidProp(prop: string): string {
14
+ try {
15
+ const result = execSync(`/system/bin/getprop ${prop}`, {
16
+ encoding: 'utf-8',
17
+ timeout: 5000,
18
+ });
19
+ const value = result.trim();
20
+ return value || '';
21
+ } catch {
22
+ return '';
23
+ }
24
+ }
25
+
26
+ /**
27
+ * 获取 Android ID
28
+ */
29
+ private getAndroidId(): string {
30
+ try {
31
+ const result = execSync('/system/bin/settings get secure android_id', {
32
+ encoding: 'utf-8',
33
+ timeout: 5000,
34
+ });
35
+ const value = result.trim();
36
+ return value && value !== 'null' ? value : '';
37
+ } catch {
38
+ return '';
39
+ }
40
+ }
41
+
42
+ /**
43
+ * 获取 Android 设备唯一ID (SHA256 哈希)
44
+ */
45
+ private getAndroidDeviceId(): string {
46
+ const androidId = this.getAndroidId();
47
+ const brand = this.getAndroidProp('ro.product.brand');
48
+ const model = this.getAndroidProp('ro.product.model');
49
+ const device = this.getAndroidProp('ro.product.device');
50
+
51
+ const raw = `${androidId}_${brand}_${model}_${device}`;
52
+ return createHash('sha256').update(raw, 'utf-8').digest('hex');
53
+ }
54
+
55
+ /**
56
+ * 获取 Android 设备型号
57
+ */
58
+ private getAndroidDeviceModel(): string {
59
+ const model = this.getAndroidProp('ro.product.model');
60
+ return model || 'Android Device';
61
+ }
62
+
63
+ /**
64
+ * 获取 Android 设备名称
65
+ */
66
+ private getAndroidDeviceName(): string {
67
+ return this.getAndroidDeviceModel();
68
+ }
69
+
70
+ /**
71
+ * 获取设备唯一ID
72
+ */
73
+ getDeviceId(): string {
74
+ const deviceId = this.getAndroidDeviceId();
75
+ return deviceId || 'invalid';
76
+ }
77
+
78
+ /**
79
+ * 获取设备名称
80
+ */
81
+ getDeviceName(): string {
82
+ return this.getAndroidDeviceName();
83
+ }
84
+
85
+ /**
86
+ * 获取设备型号
87
+ */
88
+ getDeviceModel(): string {
89
+ return this.getAndroidDeviceModel();
90
+ }
91
+
92
+ /**
93
+ * 获取设备类型
94
+ */
95
+ getDeviceType(): DeviceType {
96
+ return 'pad';
97
+ }
98
+
99
+ /**
100
+ * 获取设备品牌
101
+ */
102
+ getDeviceBrand(): string {
103
+ const brand = this.getAndroidProp('ro.product.brand');
104
+
105
+ return brand.toLowerCase() === 'honor' ? 'HONOR' : '';
106
+ }
107
+ }
@@ -1,130 +1,130 @@
1
- /**
2
- * Windows 设备信息提供者
3
- */
4
- import { v4 as uuidv4 } from 'uuid';
5
- import os from 'os';
6
- import { execSync } from 'child_process';
7
- import type { DeviceInfoProvider } from './base.js';
8
- import type { DeviceType } from '../../../types.js';
9
-
10
- export class WindowsDeviceInfoProvider implements DeviceInfoProvider {
11
- /**
12
- * 执行 PowerShell 命令并获取输出
13
- */
14
- private execPowerShell(command: string): string {
15
- try {
16
- return execSync(`powershell -Command "${command}"`, { encoding: 'utf-8' }).trim();
17
- } catch {
18
- return '';
19
- }
20
- }
21
-
22
- /**
23
- * 获取 Windows 设备型号
24
- */
25
- private getWindowsDeviceModel(): string {
26
- try {
27
- const model = this.execPowerShell(
28
- "(Get-CimInstance -ClassName Win32_ComputerSystem).Model"
29
- );
30
- return model || 'Windows PC';
31
- } catch {
32
- return 'Windows PC';
33
- }
34
- }
35
-
36
- /**
37
- * 获取 Windows 设备名称
38
- */
39
- private getWindowsDeviceName(): string {
40
- const hostname = os.hostname();
41
- const model = this.getWindowsDeviceModel();
42
- return `${hostname} (${model})`;
43
- }
44
-
45
- /**
46
- * 获取设备唯一ID
47
- */
48
- getDeviceId(): string {
49
- try {
50
- // 优先使用 MachineGuid
51
- const machineGuid = this.execPowerShell(
52
- '(Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Cryptography").MachineGuid'
53
- );
54
- if (machineGuid) {
55
- return machineGuid;
56
- }
57
-
58
- // 备用方案:使用主板序列号
59
- const serial = this.execPowerShell(
60
- '(Get-CimInstance -ClassName Win32_BIOS).SerialNumber'
61
- );
62
- if (serial) {
63
- return serial;
64
- }
65
-
66
- // 最后备用方案:使用 UUID
67
- return uuidv4();
68
- } catch {
69
- return uuidv4();
70
- }
71
- }
72
-
73
- /**
74
- * 获取设备名称
75
- */
76
- getDeviceName(): string {
77
- return this.getWindowsDeviceName();
78
- }
79
-
80
- /**
81
- * 获取设备型号
82
- */
83
- getDeviceModel(): string {
84
- return this.getWindowsDeviceModel();
85
- }
86
-
87
- /**
88
- * 获取设备品牌
89
- */
90
- getDeviceBrand(): string {
91
- try {
92
- // 方法1:检查注册表(快速但可能不准确)
93
- const honorRegistry = this.execPowerShell(
94
- 'Get-ItemProperty "HKLM:\\SOFTWARE\\HONOR" -ErrorAction SilentlyContinue'
95
- );
96
- if (honorRegistry.length > 0) {
97
- return 'HONOR';
98
- }
99
-
100
- // 方法2:通过计算机系统制造商判断(更可靠)
101
- const manufacturer = this.execPowerShell(
102
- "(Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer"
103
- );
104
- console.log(manufacturer)
105
- if (manufacturer && manufacturer.toLowerCase().includes('honor')) {
106
- return 'HONOR';
107
- }
108
-
109
- // 方法3:通过BIOS信息判断(最可靠)
110
- const biosManufacturer = this.execPowerShell(
111
- "(Get-CimInstance -ClassName Win32_BIOS).Manufacturer"
112
- );
113
- console.log(biosManufacturer)
114
- if (biosManufacturer && biosManufacturer.toLowerCase().includes('honor')) {
115
- return 'HONOR';
116
- }
117
-
118
- return '';
119
- } catch {
120
- return '';
121
- }
122
- }
123
-
124
- /**
125
- * 获取设备类型
126
- */
127
- getDeviceType(): DeviceType {
128
- return 'pc';
129
- }
130
- }
1
+ /**
2
+ * Windows 设备信息提供者
3
+ */
4
+ import { v4 as uuidv4 } from 'uuid';
5
+ import os from 'os';
6
+ import { execSync } from 'child_process';
7
+ import type { DeviceInfoProvider } from './base.js';
8
+ import type { DeviceType } from '../../../types.js';
9
+
10
+ export class WindowsDeviceInfoProvider implements DeviceInfoProvider {
11
+ /**
12
+ * 执行 PowerShell 命令并获取输出
13
+ */
14
+ private execPowerShell(command: string): string {
15
+ try {
16
+ return execSync(`powershell -Command "${command}"`, { encoding: 'utf-8' }).trim();
17
+ } catch {
18
+ return '';
19
+ }
20
+ }
21
+
22
+ /**
23
+ * 获取 Windows 设备型号
24
+ */
25
+ private getWindowsDeviceModel(): string {
26
+ try {
27
+ const model = this.execPowerShell(
28
+ "(Get-CimInstance -ClassName Win32_ComputerSystem).Model"
29
+ );
30
+ return model || 'Windows PC';
31
+ } catch {
32
+ return 'Windows PC';
33
+ }
34
+ }
35
+
36
+ /**
37
+ * 获取 Windows 设备名称
38
+ */
39
+ private getWindowsDeviceName(): string {
40
+ const hostname = os.hostname();
41
+ const model = this.getWindowsDeviceModel();
42
+ return `${hostname} (${model})`;
43
+ }
44
+
45
+ /**
46
+ * 获取设备唯一ID
47
+ */
48
+ getDeviceId(): string {
49
+ try {
50
+ // 优先使用 MachineGuid
51
+ const machineGuid = this.execPowerShell(
52
+ '(Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Cryptography").MachineGuid'
53
+ );
54
+ if (machineGuid) {
55
+ return machineGuid;
56
+ }
57
+
58
+ // 备用方案:使用主板序列号
59
+ const serial = this.execPowerShell(
60
+ '(Get-CimInstance -ClassName Win32_BIOS).SerialNumber'
61
+ );
62
+ if (serial) {
63
+ return serial;
64
+ }
65
+
66
+ // 最后备用方案:使用 UUID
67
+ return uuidv4();
68
+ } catch {
69
+ return uuidv4();
70
+ }
71
+ }
72
+
73
+ /**
74
+ * 获取设备名称
75
+ */
76
+ getDeviceName(): string {
77
+ return this.getWindowsDeviceName();
78
+ }
79
+
80
+ /**
81
+ * 获取设备型号
82
+ */
83
+ getDeviceModel(): string {
84
+ return this.getWindowsDeviceModel();
85
+ }
86
+
87
+ /**
88
+ * 获取设备品牌
89
+ */
90
+ getDeviceBrand(): string {
91
+ try {
92
+ // 方法1:检查注册表(快速但可能不准确)
93
+ const honorRegistry = this.execPowerShell(
94
+ 'Get-ItemProperty "HKLM:\\SOFTWARE\\HONOR" -ErrorAction SilentlyContinue'
95
+ );
96
+ if (honorRegistry.length > 0) {
97
+ return 'HONOR';
98
+ }
99
+
100
+ // 方法2:通过计算机系统制造商判断(更可靠)
101
+ const manufacturer = this.execPowerShell(
102
+ "(Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer"
103
+ );
104
+ console.log(manufacturer)
105
+ if (manufacturer && manufacturer.toLowerCase().includes('honor')) {
106
+ return 'HONOR';
107
+ }
108
+
109
+ // 方法3:通过BIOS信息判断(最可靠)
110
+ const biosManufacturer = this.execPowerShell(
111
+ "(Get-CimInstance -ClassName Win32_BIOS).Manufacturer"
112
+ );
113
+ console.log(biosManufacturer)
114
+ if (biosManufacturer && biosManufacturer.toLowerCase().includes('honor')) {
115
+ return 'HONOR';
116
+ }
117
+
118
+ return '';
119
+ } catch {
120
+ return '';
121
+ }
122
+ }
123
+
124
+ /**
125
+ * 获取设备类型
126
+ */
127
+ getDeviceType(): DeviceType {
128
+ return 'pc';
129
+ }
130
+ }