mobilecoder-mcp 2.0.0 → 2.0.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/dist/agent.d.ts +1 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +87 -38
- package/dist/agent.js.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +98 -40
package/dist/agent.d.ts
CHANGED
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAaA,qBAAa,YAAY;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAwC;;IASvD,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,cAAc;IAwCtB,OAAO,CAAC,qBAAqB;YAwDf,cAAc;IAyC5B,OAAO,CAAC,iBAAiB;IAsCzB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,WAAW;CAYtB"}
|
package/dist/agent.js
CHANGED
|
@@ -4,6 +4,8 @@ import * as pty from 'node-pty';
|
|
|
4
4
|
import CryptoJS from 'crypto-js';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import ora from 'ora';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
7
9
|
// 🚨 BURAYI KENDİ DOMAIN ADRESİNLE DEĞİŞTİR!
|
|
8
10
|
const RELAY_SERVER_URL = 'https://api.mobilecoder.xyz';
|
|
9
11
|
export class ZKRelayAgent {
|
|
@@ -55,8 +57,6 @@ export class ZKRelayAgent {
|
|
|
55
57
|
this.spinner.succeed(chalk.green('Connected to Relay Node!'));
|
|
56
58
|
// Odaya Katıl (Sadece Hash ID gönderilir)
|
|
57
59
|
this.socket.emit('join_room', { code: this.roomId, type: 'agent' });
|
|
58
|
-
// Note: Changed 'join_secure_room' to 'join_room' to match server implementation
|
|
59
|
-
// Server implementation in index.ts: socket.on('join_room', (data: { code: string; type: 'agent' | 'client' }) => ...)
|
|
60
60
|
this.printBanner();
|
|
61
61
|
});
|
|
62
62
|
this.socket.on('disconnect', () => {
|
|
@@ -68,27 +68,7 @@ export class ZKRelayAgent {
|
|
|
68
68
|
this.sendEnvInfo();
|
|
69
69
|
});
|
|
70
70
|
// Mobilden şifreli veri geldiğinde
|
|
71
|
-
// RelayManager emits 'term_data' and 'meta_data'.
|
|
72
|
-
// Server implementation:
|
|
73
|
-
// socket.on('term_data', ...) -> pass through term_data
|
|
74
|
-
// socket.on('meta_data', ...) -> pass through meta_data
|
|
75
|
-
// Agent connects to /, Server index.ts uses / (global namespace) BUT has:
|
|
76
|
-
// const relayNamespace = io.of('/terminal');
|
|
77
|
-
// WAIT. Previous user setup had /terminal.
|
|
78
|
-
// My previous edit REMOVED /terminal and used RelayManager on root io.
|
|
79
|
-
// But RelayManager implementation listens on 'relay_data'.
|
|
80
|
-
// My RelayManager uses: socket.on('relay_data', ...)
|
|
81
|
-
// But user snippet provided for Agent uses 'relay_encrypted' and listens on 'stream_encrypted'.
|
|
82
|
-
// I need to align Agent and Server.
|
|
83
|
-
// The previous edit to server/index.ts instantiates RelayManager.
|
|
84
|
-
// RelayManager listens to 'relay_data'.
|
|
85
|
-
// So the Agent MUST emit 'relay_data'.
|
|
86
71
|
this.socket.on('relay_data', (message) => {
|
|
87
|
-
// RelayManager checks payload structure?
|
|
88
|
-
// Wait, RelayManager implementation:
|
|
89
|
-
// socket.on('relay_data', (data) => { ... socket.to(room).emit('relay_data', data.payload) ... })
|
|
90
|
-
// So client receives `payload`.
|
|
91
|
-
// If payload is encrypted string, handle it.
|
|
92
72
|
this.handleIncomingMessage(message);
|
|
93
73
|
});
|
|
94
74
|
// Also listen for connect_error
|
|
@@ -111,15 +91,31 @@ export class ZKRelayAgent {
|
|
|
111
91
|
// Veri JSON mu? (Resize komutu vs olabilir)
|
|
112
92
|
try {
|
|
113
93
|
const cmd = JSON.parse(originalText);
|
|
94
|
+
// 1. Terminal Input (Keystrokes)
|
|
95
|
+
if (cmd.type === 'input') {
|
|
96
|
+
this.ptyProcess.write(cmd.data);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// 2. Terminal Resize
|
|
114
100
|
if (cmd.type === 'resize') {
|
|
115
101
|
this.ptyProcess.resize(cmd.cols, cmd.rows);
|
|
116
102
|
return;
|
|
117
103
|
}
|
|
118
|
-
|
|
119
|
-
|
|
104
|
+
// 3. Chat Commands (e.g. "ls -la")
|
|
105
|
+
if (cmd.type === 'command') {
|
|
106
|
+
this.ptyProcess.write(cmd.text + '\r');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// 4. CLI Tool/Button Commands (e.g. "git status")
|
|
110
|
+
if (cmd.type === 'cli_command') {
|
|
111
|
+
this.ptyProcess.write(cmd.command + '\r');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// 5. Tool Calls (File System Access)
|
|
115
|
+
if (cmd.type === 'tool_call') {
|
|
116
|
+
this.handleToolCall(cmd.tool, cmd.data, cmd.id);
|
|
120
117
|
return;
|
|
121
118
|
}
|
|
122
|
-
// Fallback checks
|
|
123
119
|
}
|
|
124
120
|
catch (e) {
|
|
125
121
|
// JSON değilse saf terminal girdisidir
|
|
@@ -130,21 +126,74 @@ export class ZKRelayAgent {
|
|
|
130
126
|
// Şifre çözülemezse (Yanlış anahtar vb.) sessizce yut
|
|
131
127
|
}
|
|
132
128
|
}
|
|
129
|
+
async handleToolCall(tool, args, id) {
|
|
130
|
+
try {
|
|
131
|
+
let result = null;
|
|
132
|
+
if (tool === 'list_directory') {
|
|
133
|
+
const dirPath = args.path ? path.resolve(args.path) : process.cwd();
|
|
134
|
+
const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
|
|
135
|
+
const files = entries.map(entry => ({
|
|
136
|
+
name: entry.name,
|
|
137
|
+
type: entry.isDirectory() ? 'directory' : 'file',
|
|
138
|
+
size: 0 // Simplification for speed
|
|
139
|
+
}));
|
|
140
|
+
result = { files };
|
|
141
|
+
}
|
|
142
|
+
else if (tool === 'read_file') {
|
|
143
|
+
const filePath = path.resolve(args.path);
|
|
144
|
+
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
145
|
+
result = { content };
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new Error(`Unknown tool: ${tool}`);
|
|
149
|
+
}
|
|
150
|
+
this.sendSecurePayload('tool_result', {
|
|
151
|
+
id,
|
|
152
|
+
result
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.sendSecurePayload('tool_result', {
|
|
157
|
+
id,
|
|
158
|
+
error: error.message,
|
|
159
|
+
type: 'error'
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
133
163
|
// Veriyi şifrele ve gönder
|
|
134
164
|
sendSecurePayload(type, data) {
|
|
135
|
-
let payloadStr =
|
|
136
|
-
if (type === 'meta') {
|
|
165
|
+
let payloadStr = '';
|
|
166
|
+
if (type === 'meta' || type === 'tool_result') {
|
|
137
167
|
// Standardize format
|
|
138
|
-
|
|
168
|
+
// For tool_result, data already contains id/result/error
|
|
169
|
+
// We wrap it in the top level object structure expected by client
|
|
170
|
+
// Client expects: { type: 'result', id: ..., result: ... } OR { type: 'error', id: ..., error: ... }
|
|
171
|
+
if (type === 'tool_result') {
|
|
172
|
+
// data is { id, result } or { id, error, type: 'error' }
|
|
173
|
+
if (data.type === 'error') {
|
|
174
|
+
payloadStr = JSON.stringify({ ...data });
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
payloadStr = JSON.stringify({ type: 'result', ...data });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
payloadStr = JSON.stringify(data);
|
|
182
|
+
}
|
|
139
183
|
}
|
|
140
|
-
else if (type === 'term_data'
|
|
141
|
-
// Wrap output in { type: 'output', data: ... }
|
|
142
|
-
|
|
143
|
-
|
|
184
|
+
else if (type === 'term_data') {
|
|
185
|
+
// Wrap output in { type: 'output', data: ... }
|
|
186
|
+
if (typeof data === 'string') {
|
|
187
|
+
payloadStr = JSON.stringify({ type: 'output', data: data });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
payloadStr = JSON.stringify(data);
|
|
191
|
+
}
|
|
144
192
|
}
|
|
193
|
+
// Fallback if empty (shouldn't happen with above logic)
|
|
194
|
+
if (!payloadStr)
|
|
195
|
+
payloadStr = JSON.stringify(data);
|
|
145
196
|
const encrypted = CryptoJS.AES.encrypt(payloadStr, this.encryptionKey).toString();
|
|
146
|
-
// RelayManager expects 'relay_data' event with { room, payload }
|
|
147
|
-
// It emits 'relay_data' with just payload to other peer.
|
|
148
197
|
this.socket.emit('relay_data', {
|
|
149
198
|
room: this.roomId,
|
|
150
199
|
payload: { e: encrypted }
|
|
@@ -152,16 +201,16 @@ export class ZKRelayAgent {
|
|
|
152
201
|
}
|
|
153
202
|
sendEnvInfo() {
|
|
154
203
|
const info = {
|
|
155
|
-
type: 'host_info',
|
|
156
|
-
username: os.userInfo().username,
|
|
157
|
-
hostname: os.hostname(),
|
|
204
|
+
type: 'host_info',
|
|
205
|
+
username: os.userInfo().username,
|
|
206
|
+
hostname: os.hostname(),
|
|
158
207
|
platform: os.platform(),
|
|
159
208
|
cwd: process.cwd()
|
|
160
209
|
};
|
|
161
210
|
this.sendSecurePayload('meta', info);
|
|
162
211
|
}
|
|
163
212
|
printBanner() {
|
|
164
|
-
console.log('\n' + chalk.bgBlue.bold(' MOBILECODER ZK-RELAY v2.0 '));
|
|
213
|
+
console.log('\n' + chalk.bgBlue.bold(' MOBILECODER ZK-RELAY v2.0.1 '));
|
|
165
214
|
console.log(chalk.gray('Secure, End-to-End Encrypted Terminal Bridge\n'));
|
|
166
215
|
console.log(chalk.yellow('┌──────────────────────────────────────┐'));
|
|
167
216
|
console.log(chalk.yellow('│ 🔑 CONNECTION CODE (ENTER ON APP) │'));
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAU,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAU,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,6CAA6C;AAC7C,MAAM,gBAAgB,GAAG,6BAA6B,CAAC;AAEvD,MAAM,OAAO,YAAY;IACb,MAAM,CAAS;IACf,UAAU,CAAM;IAChB,UAAU,CAAS;IACnB,MAAM,CAAS;IACf,aAAa,CAAS;IACtB,OAAO,GAAG,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAEvD;QACI,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,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G,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC,CAAC;QACvE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC,CAAC;QAE1E,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9I,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC,CAAC;IAClE,CAAC;CACJ"}
|
package/package.json
CHANGED
package/src/agent.ts
CHANGED
|
@@ -5,6 +5,8 @@ import * as pty from 'node-pty';
|
|
|
5
5
|
import CryptoJS from 'crypto-js';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import ora from 'ora';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
8
10
|
|
|
9
11
|
// 🚨 BURAYI KENDİ DOMAIN ADRESİNLE DEĞİŞTİR!
|
|
10
12
|
const RELAY_SERVER_URL = 'https://api.mobilecoder.xyz';
|
|
@@ -69,8 +71,6 @@ export class ZKRelayAgent {
|
|
|
69
71
|
|
|
70
72
|
// Odaya Katıl (Sadece Hash ID gönderilir)
|
|
71
73
|
this.socket.emit('join_room', { code: this.roomId, type: 'agent' });
|
|
72
|
-
// Note: Changed 'join_secure_room' to 'join_room' to match server implementation
|
|
73
|
-
// Server implementation in index.ts: socket.on('join_room', (data: { code: string; type: 'agent' | 'client' }) => ...)
|
|
74
74
|
|
|
75
75
|
this.printBanner();
|
|
76
76
|
});
|
|
@@ -80,34 +80,13 @@ export class ZKRelayAgent {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
// Mobilden biri bağlandığında
|
|
83
|
-
this.socket.on('peer_joined', () => {
|
|
83
|
+
this.socket.on('peer_joined', () => {
|
|
84
84
|
console.log(chalk.green('\n📱 Mobile Client Connected via Encrypted Tunnel!'));
|
|
85
85
|
this.sendEnvInfo();
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
// Mobilden şifreli veri geldiğinde
|
|
89
|
-
// RelayManager emits 'term_data' and 'meta_data'.
|
|
90
|
-
// Server implementation:
|
|
91
|
-
// socket.on('term_data', ...) -> pass through term_data
|
|
92
|
-
// socket.on('meta_data', ...) -> pass through meta_data
|
|
93
|
-
// Agent connects to /, Server index.ts uses / (global namespace) BUT has:
|
|
94
|
-
// const relayNamespace = io.of('/terminal');
|
|
95
|
-
// WAIT. Previous user setup had /terminal.
|
|
96
|
-
// My previous edit REMOVED /terminal and used RelayManager on root io.
|
|
97
|
-
// But RelayManager implementation listens on 'relay_data'.
|
|
98
|
-
// My RelayManager uses: socket.on('relay_data', ...)
|
|
99
|
-
// But user snippet provided for Agent uses 'relay_encrypted' and listens on 'stream_encrypted'.
|
|
100
|
-
// I need to align Agent and Server.
|
|
101
|
-
// The previous edit to server/index.ts instantiates RelayManager.
|
|
102
|
-
// RelayManager listens to 'relay_data'.
|
|
103
|
-
// So the Agent MUST emit 'relay_data'.
|
|
104
|
-
|
|
105
89
|
this.socket.on('relay_data', (message: { room: string, payload: any }) => {
|
|
106
|
-
// RelayManager checks payload structure?
|
|
107
|
-
// Wait, RelayManager implementation:
|
|
108
|
-
// socket.on('relay_data', (data) => { ... socket.to(room).emit('relay_data', data.payload) ... })
|
|
109
|
-
// So client receives `payload`.
|
|
110
|
-
// If payload is encrypted string, handle it.
|
|
111
90
|
this.handleIncomingMessage(message as any);
|
|
112
91
|
});
|
|
113
92
|
|
|
@@ -134,15 +113,37 @@ export class ZKRelayAgent {
|
|
|
134
113
|
// Veri JSON mu? (Resize komutu vs olabilir)
|
|
135
114
|
try {
|
|
136
115
|
const cmd = JSON.parse(originalText);
|
|
116
|
+
|
|
117
|
+
// 1. Terminal Input (Keystrokes)
|
|
118
|
+
if (cmd.type === 'input') {
|
|
119
|
+
this.ptyProcess.write(cmd.data);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 2. Terminal Resize
|
|
137
124
|
if (cmd.type === 'resize') {
|
|
138
125
|
this.ptyProcess.resize(cmd.cols, cmd.rows);
|
|
139
126
|
return;
|
|
140
127
|
}
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
|
|
129
|
+
// 3. Chat Commands (e.g. "ls -la")
|
|
130
|
+
if (cmd.type === 'command') {
|
|
131
|
+
this.ptyProcess.write(cmd.text + '\r');
|
|
143
132
|
return;
|
|
144
133
|
}
|
|
145
|
-
|
|
134
|
+
|
|
135
|
+
// 4. CLI Tool/Button Commands (e.g. "git status")
|
|
136
|
+
if (cmd.type === 'cli_command') {
|
|
137
|
+
this.ptyProcess.write(cmd.command + '\r');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 5. Tool Calls (File System Access)
|
|
142
|
+
if (cmd.type === 'tool_call') {
|
|
143
|
+
this.handleToolCall(cmd.tool, cmd.data, cmd.id);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
146
147
|
} catch (e) {
|
|
147
148
|
// JSON değilse saf terminal girdisidir
|
|
148
149
|
this.ptyProcess.write(originalText);
|
|
@@ -152,22 +153,79 @@ export class ZKRelayAgent {
|
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
private async handleToolCall(tool: string, args: any, id: string) {
|
|
157
|
+
try {
|
|
158
|
+
let result: any = null;
|
|
159
|
+
|
|
160
|
+
if (tool === 'list_directory') {
|
|
161
|
+
const dirPath = args.path ? path.resolve(args.path) : process.cwd();
|
|
162
|
+
const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
|
|
163
|
+
|
|
164
|
+
const files = entries.map(entry => ({
|
|
165
|
+
name: entry.name,
|
|
166
|
+
type: entry.isDirectory() ? 'directory' : 'file',
|
|
167
|
+
size: 0 // Simplification for speed
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
result = { files };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
else if (tool === 'read_file') {
|
|
174
|
+
const filePath = path.resolve(args.path);
|
|
175
|
+
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
176
|
+
result = { content };
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new Error(`Unknown tool: ${tool}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.sendSecurePayload('tool_result', {
|
|
183
|
+
id,
|
|
184
|
+
result
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
} catch (error: any) {
|
|
188
|
+
this.sendSecurePayload('tool_result', {
|
|
189
|
+
id,
|
|
190
|
+
error: error.message,
|
|
191
|
+
type: 'error'
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
155
196
|
// Veriyi şifrele ve gönder
|
|
156
197
|
private sendSecurePayload(type: string, data: any) {
|
|
157
|
-
let payloadStr =
|
|
158
|
-
|
|
198
|
+
let payloadStr = '';
|
|
199
|
+
|
|
200
|
+
if (type === 'meta' || type === 'tool_result') {
|
|
159
201
|
// Standardize format
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
|
|
202
|
+
// For tool_result, data already contains id/result/error
|
|
203
|
+
// We wrap it in the top level object structure expected by client
|
|
204
|
+
// Client expects: { type: 'result', id: ..., result: ... } OR { type: 'error', id: ..., error: ... }
|
|
205
|
+
if (type === 'tool_result') {
|
|
206
|
+
// data is { id, result } or { id, error, type: 'error' }
|
|
207
|
+
if (data.type === 'error') {
|
|
208
|
+
payloadStr = JSON.stringify({ ...data });
|
|
209
|
+
} else {
|
|
210
|
+
payloadStr = JSON.stringify({ type: 'result', ...data });
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
payloadStr = JSON.stringify(data);
|
|
214
|
+
}
|
|
215
|
+
} else if (type === 'term_data') {
|
|
216
|
+
// Wrap output in { type: 'output', data: ... }
|
|
217
|
+
if (typeof data === 'string') {
|
|
218
|
+
payloadStr = JSON.stringify({ type: 'output', data: data });
|
|
219
|
+
} else {
|
|
220
|
+
payloadStr = JSON.stringify(data);
|
|
221
|
+
}
|
|
165
222
|
}
|
|
166
223
|
|
|
224
|
+
// Fallback if empty (shouldn't happen with above logic)
|
|
225
|
+
if (!payloadStr) payloadStr = JSON.stringify(data);
|
|
226
|
+
|
|
167
227
|
const encrypted = CryptoJS.AES.encrypt(payloadStr, this.encryptionKey).toString();
|
|
168
228
|
|
|
169
|
-
// RelayManager expects 'relay_data' event with { room, payload }
|
|
170
|
-
// It emits 'relay_data' with just payload to other peer.
|
|
171
229
|
this.socket.emit('relay_data', {
|
|
172
230
|
room: this.roomId,
|
|
173
231
|
payload: { e: encrypted }
|
|
@@ -176,9 +234,9 @@ export class ZKRelayAgent {
|
|
|
176
234
|
|
|
177
235
|
private sendEnvInfo() {
|
|
178
236
|
const info = {
|
|
179
|
-
type: 'host_info',
|
|
180
|
-
username: os.userInfo().username,
|
|
181
|
-
hostname: os.hostname(),
|
|
237
|
+
type: 'host_info',
|
|
238
|
+
username: os.userInfo().username,
|
|
239
|
+
hostname: os.hostname(),
|
|
182
240
|
platform: os.platform(),
|
|
183
241
|
cwd: process.cwd()
|
|
184
242
|
};
|
|
@@ -186,7 +244,7 @@ export class ZKRelayAgent {
|
|
|
186
244
|
}
|
|
187
245
|
|
|
188
246
|
private printBanner() {
|
|
189
|
-
console.log('\n' + chalk.bgBlue.bold(' MOBILECODER ZK-RELAY v2.0 '));
|
|
247
|
+
console.log('\n' + chalk.bgBlue.bold(' MOBILECODER ZK-RELAY v2.0.1 '));
|
|
190
248
|
console.log(chalk.gray('Secure, End-to-End Encrypted Terminal Bridge\n'));
|
|
191
249
|
|
|
192
250
|
console.log(chalk.yellow('┌──────────────────────────────────────┐'));
|