yymaxapi 1.0.0

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,88 @@
1
+ const https = require('https');
2
+ const http = require('http');
3
+
4
+ // 测试 URL 的响应时间
5
+ async function testSpeed(url) {
6
+ return new Promise((resolve) => {
7
+ const startTime = Date.now();
8
+ const urlObj = new URL(url);
9
+ const protocol = urlObj.protocol === 'https:' ? https : http;
10
+
11
+ const timeout = 5000; // 5秒超时
12
+
13
+ const req = protocol.get(url, { timeout }, (res) => {
14
+ const endTime = Date.now();
15
+ const latency = endTime - startTime;
16
+
17
+ // 读取响应数据(避免连接挂起)
18
+ res.on('data', () => {});
19
+ res.on('end', () => {
20
+ resolve({
21
+ success: true,
22
+ latency,
23
+ statusCode: res.statusCode
24
+ });
25
+ });
26
+ });
27
+
28
+ req.on('timeout', () => {
29
+ req.destroy();
30
+ resolve({
31
+ success: false,
32
+ latency: timeout,
33
+ error: '超时'
34
+ });
35
+ });
36
+
37
+ req.on('error', (error) => {
38
+ const endTime = Date.now();
39
+ resolve({
40
+ success: false,
41
+ latency: endTime - startTime,
42
+ error: error.message
43
+ });
44
+ });
45
+ });
46
+ }
47
+
48
+ // 测试多个中转站的速度
49
+ async function testMultipleRelays(relays) {
50
+ const results = [];
51
+
52
+ for (const relay of relays) {
53
+ // 构建测试 URL(去掉 /v1 后缀,只测试基础域名)
54
+ const baseUrl = relay.baseUrl.replace(/\/v1$/, '');
55
+ const testUrl = baseUrl;
56
+
57
+ const result = await testSpeed(testUrl);
58
+ results.push({
59
+ name: relay.name,
60
+ url: relay.baseUrl,
61
+ ...result
62
+ });
63
+ }
64
+
65
+ return results;
66
+ }
67
+
68
+ // 根据速度排序中转站
69
+ function sortBySpeed(results) {
70
+ return results
71
+ .filter(r => r.success)
72
+ .sort((a, b) => a.latency - b.latency);
73
+ }
74
+
75
+ // 格式化延迟显示
76
+ function formatLatency(latency) {
77
+ if (latency < 100) return 'excellent';
78
+ if (latency < 300) return 'good';
79
+ if (latency < 1000) return 'fair';
80
+ return 'poor';
81
+ }
82
+
83
+ module.exports = {
84
+ testSpeed,
85
+ testMultipleRelays,
86
+ sortBySpeed,
87
+ formatLatency
88
+ };
package/lib/ui.js ADDED
@@ -0,0 +1,38 @@
1
+ const chalk = require('chalk');
2
+
3
+ // 显示菜单
4
+ function displayMenu(title, options) {
5
+ console.log(chalk.cyan.bold(`\n${title}\n`));
6
+ options.forEach((opt, index) => {
7
+ console.log(` ${chalk.yellow(index + 1)}. ${opt}`);
8
+ });
9
+ console.log();
10
+ }
11
+
12
+ // 显示成功消息
13
+ function displaySuccess(message) {
14
+ console.log(chalk.green(`\n${message}\n`));
15
+ }
16
+
17
+ // 显示错误消息
18
+ function displayError(message) {
19
+ console.log(chalk.red(`\n❌ ${message}\n`));
20
+ }
21
+
22
+ // 显示信息消息
23
+ function displayInfo(message) {
24
+ console.log(chalk.blue(`\nℹ️ ${message}\n`));
25
+ }
26
+
27
+ // 显示警告消息
28
+ function displayWarning(message) {
29
+ console.log(chalk.yellow(`\n⚠️ ${message}\n`));
30
+ }
31
+
32
+ module.exports = {
33
+ displayMenu,
34
+ displaySuccess,
35
+ displayError,
36
+ displayInfo,
37
+ displayWarning
38
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "yymaxapi",
3
+ "version": "1.0.0",
4
+ "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
+ "main": "bin/yymaxapi.js",
6
+ "bin": {
7
+ "yymaxapi": "bin/yymaxapi.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node cli.js",
11
+ "test": "node bin/yymaxapi.js test",
12
+ "feishu:publish": "node scripts/feishu-docx-publish.js"
13
+ },
14
+ "keywords": [
15
+ "openclaw",
16
+ "clawdbot",
17
+ "config",
18
+ "cli",
19
+ "api-relay",
20
+ "model-management",
21
+ "speed-test",
22
+ "yymax"
23
+ ],
24
+ "author": "OpenClaw Community",
25
+ "license": "MIT",
26
+ "files": [
27
+ "bin/",
28
+ "lib/",
29
+ "README.md",
30
+ "config/API节点设置.md"
31
+ ],
32
+ "dependencies": {
33
+ "inquirer": "^8.2.5",
34
+ "chalk": "^4.1.2",
35
+ "fs-extra": "^11.1.1",
36
+ "json5": "^2.2.3",
37
+ "ora": "^5.4.1"
38
+ },
39
+ "engines": {
40
+ "node": ">=14.0.0"
41
+ },
42
+ "preferGlobal": true
43
+ }