sloth-d2c-mcp 1.0.4-beta75 → 1.0.4-beta77

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,139 @@
1
+ import * as os from 'os';
2
+ import axios from 'axios';
3
+ import pkg from 'node-machine-id';
4
+ import { Logger } from './logger.js';
5
+ const { machineIdSync } = pkg;
6
+ /*
7
+ * 统计上报
8
+ */
9
+ const isOnline = process.env.NODE_ENV === 'production';
10
+ let lastEvent = '';
11
+ /**
12
+ * 获取设备信息
13
+ */
14
+ const getDeviceInfo = () => {
15
+ return {
16
+ platform: os.platform(), // darwin, win32, linux
17
+ arch: os.arch(), // x64, arm64
18
+ osVersion: os.release(),
19
+ hostname: os.hostname(),
20
+ nodeVersion: process.version,
21
+ };
22
+ };
23
+ /**
24
+ * 获取用户信息(从环境变量或系统)
25
+ */
26
+ const getUserInfo = () => {
27
+ // 尝试从环境变量获取
28
+ const userId = process.env.USER_ID || String(os.userInfo().uid) || os.hostname();
29
+ const userName = process.env.USER || process.env.LOGNAME || os.userInfo().username;
30
+ return {
31
+ id: userId,
32
+ name: userName,
33
+ };
34
+ };
35
+ /**
36
+ * 自定义 beacon 上报
37
+ */
38
+ const customizebeaconReport = (eventName, params) => {
39
+ const user = getUserInfo();
40
+ const device = getDeviceInfo();
41
+ const machineId = machineIdSync(true);
42
+ const uniqueKey = `${machineId}/${user.id || 'unknown'}/${user.name || 'anonymous'}`;
43
+ // 设备标识
44
+ const deviceIdentifier = `${device.platform || 'Unknown'} ${device.arch || ''} ${device.osVersion || ''} Node${device.nodeVersion || ''}`;
45
+ axios
46
+ .post('https://otheve.beacon.qq.com/analytics/v2_upload?appkey=0WEB0IK7H05E5K4S', {
47
+ appVersion: '',
48
+ sdkId: 'js',
49
+ sdkVersion: '4.5.9-web',
50
+ mainAppKey: '0WEB0IK7H05E5K4S',
51
+ platformId: 3,
52
+ common: {
53
+ bizType: 'd2c_mcp',
54
+ platCode: '0',
55
+ utm_source: '',
56
+ plat: 'tme',
57
+ abtestName: '',
58
+ userStatus: '1',
59
+ accountType: '1',
60
+ uniqueKey: uniqueKey,
61
+ A2: '59x14SkHQFdNp6HrSnYmiSWGeT9tBBFY',
62
+ A8: '',
63
+ A12: 'zh-CN',
64
+ A17: '',
65
+ A23: '',
66
+ A50: '2846217',
67
+ A76: '0WEB0IK7H05E5K4S_' + Date.now(),
68
+ A101: deviceIdentifier, // 设备信息
69
+ A102: '',
70
+ A104: '',
71
+ A119: '',
72
+ A153: '',
73
+ },
74
+ events: [
75
+ {
76
+ eventCode: eventName,
77
+ eventTime: '' + Date.now(),
78
+ mapValue: {
79
+ ...params,
80
+ // 附加设备信息
81
+ devicePlatform: device.platform,
82
+ deviceArch: device.arch,
83
+ deviceOsVersion: device.osVersion,
84
+ nodeVersion: device.nodeVersion,
85
+ A99: 'Y',
86
+ A100: '370',
87
+ A72: '4.5.9-web',
88
+ A88: '1744294371735',
89
+ },
90
+ },
91
+ ],
92
+ })
93
+ .then((res) => {
94
+ Logger.info('Beacon report success:', res);
95
+ })
96
+ .catch((err) => {
97
+ // 静默处理上报错误,避免影响主流程
98
+ console.error('Beacon report error:', err.message);
99
+ });
100
+ };
101
+ /**
102
+ * 向 beacon 服务上报事件
103
+ */
104
+ const trackEvent = (eventName, params) => {
105
+ if (!eventName) {
106
+ return;
107
+ }
108
+ try {
109
+ customizebeaconReport(eventName, {
110
+ lastEvent,
111
+ eventCode: eventName,
112
+ ...params,
113
+ });
114
+ lastEvent = eventName;
115
+ }
116
+ catch (err) {
117
+ console.error('Track event error:', err);
118
+ }
119
+ };
120
+ /**
121
+ * 上报工具调用事件
122
+ */
123
+ export const trackToolCall = (toolName, extParam) => {
124
+ try {
125
+ if (toolName) {
126
+ trackEvent('mcp_tool_call', {
127
+ toolName,
128
+ ...extParam,
129
+ });
130
+ }
131
+ }
132
+ catch (err) {
133
+ console.error('Track tool call error:', err);
134
+ }
135
+ };
136
+ /**
137
+ * 导出获取设备信息和用户信息的工具函数
138
+ */
139
+ export { getDeviceInfo, getUserInfo };
@@ -10,11 +10,11 @@ import path from 'path';
10
10
  * @returns Promise<number> 返回可用的端口号
11
11
  */
12
12
  export async function getAvailablePort(startPort = 3100, maxAttempts = 10) {
13
- for (let port = startPort; port < startPort + maxAttempts; port++) {
14
- if (await isPortAvailable(port)) {
15
- return port;
16
- }
17
- }
13
+ // for (let port = startPort; port < startPort + maxAttempts; port++) {
14
+ // if (await isPortAvailable(port)) {
15
+ // return port
16
+ // }
17
+ // }
18
18
  return 3100;
19
19
  // throw new Error(`No available port found in range ${startPort}-${startPort + maxAttempts - 1}`)
20
20
  }
@@ -1,18 +1,18 @@
1
1
  {
2
- "buildTime": "2025-12-02T10:30:59.228Z",
2
+ "buildTime": "2025-12-10T09:06:44.786Z",
3
3
  "mode": "build",
4
4
  "pages": {
5
5
  "main": {
6
6
  "file": "index.html",
7
- "size": 1494620,
8
- "sizeFormatted": "1.43 MB"
7
+ "size": 1604168,
8
+ "sizeFormatted": "1.53 MB"
9
9
  },
10
10
  "detail": {
11
11
  "file": "detail.html",
12
- "size": 280311,
13
- "sizeFormatted": "273.74 KB"
12
+ "size": 280964,
13
+ "sizeFormatted": "274.38 KB"
14
14
  }
15
15
  },
16
- "totalSize": 1774931,
17
- "totalSizeFormatted": "1.69 MB"
16
+ "totalSize": 1885132,
17
+ "totalSizeFormatted": "1.8 MB"
18
18
  }