@dahawa/hawa-cli-analysis 1.0.7 → 1.0.8
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/.tools.json +6 -6
- package/.vscode/launch.json +26 -26
- package/_uclaude.js +0 -0
- package/anthropic-transformer.js +986 -986
- package/api-anthropic.js +279 -279
- package/api-openai.js +538 -538
- package/clogger-openai.js +190 -190
- package/clogger.js +318 -318
- package/codex/mcp-client.js +556 -556
- package/codex/mcpclient.js +117 -117
- package/codex/mcpserver.js +374 -374
- package/codex/mcpserverproxy.js +143 -143
- package/codex/test.js +30 -30
- package/mcp/claude-mcpproxy-launcher.js +4 -4
- package/package.json +2 -1
- package/simple-transform-example.js +212 -212
- package/tests/test-lazy-load.js +35 -35
- package/tests/test_mcp_proxy.js +50 -50
- package/tests/test_supabase_mcp.js +41 -41
- package/uclaude.js +3 -3
- package/ucodex-proxy.js +172 -172
- package/ucodex.js +127 -127
package/codex/mcpclient.js
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import net from 'node:net';
|
|
2
|
-
import { getPipePath } from '../untils.js';
|
|
3
|
-
import LogManager from '../logger-manager.js';
|
|
4
|
-
const logger = LogManager.getSystemLogger();
|
|
5
|
-
|
|
6
|
-
const PIPE_PATH = await getPipePath();
|
|
7
|
-
logger.debug("JsonRpcClient PIPE_PATH:" + PIPE_PATH);
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 使用文件协议通信的 JSON-RPC 客户端
|
|
11
|
-
*/
|
|
12
|
-
export default class JsonRpcClient {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.socket = net.createConnection(PIPE_PATH);
|
|
15
|
-
this.nextId = 1;
|
|
16
|
-
this.pending = new Map();
|
|
17
|
-
this.connectionError = null;
|
|
18
|
-
this.connected = false;
|
|
19
|
-
this.connectionTimeout = 5000; // 5秒连接超时
|
|
20
|
-
let buf = '';
|
|
21
|
-
|
|
22
|
-
// 连接成功
|
|
23
|
-
this.socket.on('connect', () => {
|
|
24
|
-
logger.info('JSON-RPC client connected to', PIPE_PATH);
|
|
25
|
-
this.connected = true;
|
|
26
|
-
this.connectionError = null;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// 连接错误
|
|
30
|
-
this.socket.on('error', (e) => {
|
|
31
|
-
logger.error('JSON-RPC client connection error:', e.message);
|
|
32
|
-
this.connectionError = e;
|
|
33
|
-
this.connected = false;
|
|
34
|
-
for (const [, p] of this.pending) p.reject(e);
|
|
35
|
-
this.pending.clear();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// 连接关闭
|
|
39
|
-
this.socket.on('close', () => {
|
|
40
|
-
logger.info('JSON-RPC client connection closed');
|
|
41
|
-
let con = this.connected;
|
|
42
|
-
this.connected = false;
|
|
43
|
-
if(con){
|
|
44
|
-
this.connectionError = new Error('Connection closed');
|
|
45
|
-
//如果根本没有链接过,应该是链接失败
|
|
46
|
-
}else{
|
|
47
|
-
this.connectionError = new Error('Connection closed ,请检查服务是否启动');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// 数据接收处理
|
|
53
|
-
this.socket.on('data', (chunk) => {
|
|
54
|
-
buf += chunk;
|
|
55
|
-
for (let i = buf.indexOf('\n'); i >= 0; i = buf.indexOf('\n')) {
|
|
56
|
-
const line = buf.slice(0, i).trim(); buf = buf.slice(i + 1);
|
|
57
|
-
if (!line) continue;
|
|
58
|
-
let msg; try { msg = JSON.parse(line); } catch { continue; }
|
|
59
|
-
const p = this.pending.get(msg.id);
|
|
60
|
-
if (p) {
|
|
61
|
-
this.pending.delete(msg.id);
|
|
62
|
-
msg.error ? p.reject(new Error(msg.error.message)) : p.resolve(msg.result);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 等待连接建立或超时
|
|
70
|
-
async waitForConnection() {
|
|
71
|
-
if (this.connected) return;
|
|
72
|
-
if (this.connectionError) throw this.connectionError;
|
|
73
|
-
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
const timeout = setTimeout(() => {
|
|
76
|
-
reject(new Error(`Connection timeout: Server not responding at ${PIPE_PATH}`));
|
|
77
|
-
}, this.connectionTimeout);
|
|
78
|
-
|
|
79
|
-
this.socket.once('connect', () => {
|
|
80
|
-
clearTimeout(timeout);
|
|
81
|
-
resolve();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
this.socket.once('error', (err) => {
|
|
85
|
-
clearTimeout(timeout);
|
|
86
|
-
reject(new Error(`Connection failed: ${err.message}`));
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async call(method, params) {
|
|
92
|
-
// 检查连接状态
|
|
93
|
-
await this.waitForConnection();
|
|
94
|
-
|
|
95
|
-
const id = this.nextId++;
|
|
96
|
-
const req = { jsonrpc: '2.0', id, method, params };
|
|
97
|
-
return new Promise((resolve, reject) => {
|
|
98
|
-
this.pending.set(id, { resolve, reject });
|
|
99
|
-
this.socket.write(JSON.stringify(req) + '\n');
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
// demo
|
|
106
|
-
(async () => {
|
|
107
|
-
const cli = new JsonRpcClient(PIPE_PATH);
|
|
108
|
-
try {
|
|
109
|
-
logger.debug('ping =>', await cli.call('ping'));
|
|
110
|
-
logger.debug('echo =>', await cli.call('echo', 'hello'));
|
|
111
|
-
logger.debug('add =>', await cli.call('add', [1, 2]));
|
|
112
|
-
} catch (e) {
|
|
113
|
-
logger.error('RPC error:', e.message);
|
|
114
|
-
} finally {
|
|
115
|
-
setTimeout(() => process.exit(0), 200);
|
|
116
|
-
}
|
|
117
|
-
})();
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
import { getPipePath } from '../untils.js';
|
|
3
|
+
import LogManager from '../logger-manager.js';
|
|
4
|
+
const logger = LogManager.getSystemLogger();
|
|
5
|
+
|
|
6
|
+
const PIPE_PATH = await getPipePath();
|
|
7
|
+
logger.debug("JsonRpcClient PIPE_PATH:" + PIPE_PATH);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 使用文件协议通信的 JSON-RPC 客户端
|
|
11
|
+
*/
|
|
12
|
+
export default class JsonRpcClient {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.socket = net.createConnection(PIPE_PATH);
|
|
15
|
+
this.nextId = 1;
|
|
16
|
+
this.pending = new Map();
|
|
17
|
+
this.connectionError = null;
|
|
18
|
+
this.connected = false;
|
|
19
|
+
this.connectionTimeout = 5000; // 5秒连接超时
|
|
20
|
+
let buf = '';
|
|
21
|
+
|
|
22
|
+
// 连接成功
|
|
23
|
+
this.socket.on('connect', () => {
|
|
24
|
+
logger.info('JSON-RPC client connected to', PIPE_PATH);
|
|
25
|
+
this.connected = true;
|
|
26
|
+
this.connectionError = null;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 连接错误
|
|
30
|
+
this.socket.on('error', (e) => {
|
|
31
|
+
logger.error('JSON-RPC client connection error:', e.message);
|
|
32
|
+
this.connectionError = e;
|
|
33
|
+
this.connected = false;
|
|
34
|
+
for (const [, p] of this.pending) p.reject(e);
|
|
35
|
+
this.pending.clear();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 连接关闭
|
|
39
|
+
this.socket.on('close', () => {
|
|
40
|
+
logger.info('JSON-RPC client connection closed');
|
|
41
|
+
let con = this.connected;
|
|
42
|
+
this.connected = false;
|
|
43
|
+
if(con){
|
|
44
|
+
this.connectionError = new Error('Connection closed');
|
|
45
|
+
//如果根本没有链接过,应该是链接失败
|
|
46
|
+
}else{
|
|
47
|
+
this.connectionError = new Error('Connection closed ,请检查服务是否启动');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// 数据接收处理
|
|
53
|
+
this.socket.on('data', (chunk) => {
|
|
54
|
+
buf += chunk;
|
|
55
|
+
for (let i = buf.indexOf('\n'); i >= 0; i = buf.indexOf('\n')) {
|
|
56
|
+
const line = buf.slice(0, i).trim(); buf = buf.slice(i + 1);
|
|
57
|
+
if (!line) continue;
|
|
58
|
+
let msg; try { msg = JSON.parse(line); } catch { continue; }
|
|
59
|
+
const p = this.pending.get(msg.id);
|
|
60
|
+
if (p) {
|
|
61
|
+
this.pending.delete(msg.id);
|
|
62
|
+
msg.error ? p.reject(new Error(msg.error.message)) : p.resolve(msg.result);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 等待连接建立或超时
|
|
70
|
+
async waitForConnection() {
|
|
71
|
+
if (this.connected) return;
|
|
72
|
+
if (this.connectionError) throw this.connectionError;
|
|
73
|
+
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const timeout = setTimeout(() => {
|
|
76
|
+
reject(new Error(`Connection timeout: Server not responding at ${PIPE_PATH}`));
|
|
77
|
+
}, this.connectionTimeout);
|
|
78
|
+
|
|
79
|
+
this.socket.once('connect', () => {
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
this.socket.once('error', (err) => {
|
|
85
|
+
clearTimeout(timeout);
|
|
86
|
+
reject(new Error(`Connection failed: ${err.message}`));
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async call(method, params) {
|
|
92
|
+
// 检查连接状态
|
|
93
|
+
await this.waitForConnection();
|
|
94
|
+
|
|
95
|
+
const id = this.nextId++;
|
|
96
|
+
const req = { jsonrpc: '2.0', id, method, params };
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
this.pending.set(id, { resolve, reject });
|
|
99
|
+
this.socket.write(JSON.stringify(req) + '\n');
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
// demo
|
|
106
|
+
(async () => {
|
|
107
|
+
const cli = new JsonRpcClient(PIPE_PATH);
|
|
108
|
+
try {
|
|
109
|
+
logger.debug('ping =>', await cli.call('ping'));
|
|
110
|
+
logger.debug('echo =>', await cli.call('echo', 'hello'));
|
|
111
|
+
logger.debug('add =>', await cli.call('add', [1, 2]));
|
|
112
|
+
} catch (e) {
|
|
113
|
+
logger.error('RPC error:', e.message);
|
|
114
|
+
} finally {
|
|
115
|
+
setTimeout(() => process.exit(0), 200);
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
118
|
*/
|