anywhere-ai 0.0.18 → 0.0.19
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/cli.js +92 -14
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -6,11 +6,12 @@ import { readFileSync } from "fs";
|
|
|
6
6
|
import os from "os";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import crypto from "crypto";
|
|
9
|
-
import { spawnSync, execSync } from "child_process";
|
|
9
|
+
import { spawn, spawnSync, execSync } from "child_process";
|
|
10
10
|
import readline from "readline";
|
|
11
|
+
import qrcode from "qrcode-terminal";
|
|
11
12
|
var args = process.argv.slice(2);
|
|
12
13
|
if (args.includes("--version") || args.includes("-v")) {
|
|
13
|
-
console.log(`anywhere-ai v${"0.0.
|
|
14
|
+
console.log(`anywhere-ai v${"0.0.19"}`);
|
|
14
15
|
process.exit(0);
|
|
15
16
|
}
|
|
16
17
|
function ask(question, preserveCase = false) {
|
|
@@ -169,23 +170,100 @@ try {
|
|
|
169
170
|
} catch {
|
|
170
171
|
}
|
|
171
172
|
var isVPS = publicIP && localIP && publicIP !== localIP;
|
|
172
|
-
|
|
173
|
+
await import("./server-SPM3PZ5G.js");
|
|
174
|
+
var tunnelURL = null;
|
|
175
|
+
var tunnelProcess = null;
|
|
176
|
+
function printBanner(serverURL2) {
|
|
177
|
+
const qrData = `anywhere://connect?url=${encodeURIComponent(serverURL2)}&token=${encodeURIComponent(config.authToken)}`;
|
|
178
|
+
console.log(`
|
|
173
179
|
____ ____ ____ ____ ____ ____ ____ ____
|
|
174
180
|
||A |||N |||Y |||W |||H |||E |||R |||E ||
|
|
175
181
|
||__|||__|||__|||__|||__|||__|||__|||__||
|
|
176
182
|
|/__\\|/__\\|/__\\|/__\\|/__\\|/__\\|/__\\|/__\\|
|
|
177
183
|
`);
|
|
178
|
-
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
179
|
-
|
|
180
|
-
console.log("
|
|
184
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
185
|
+
console.log(" Server URL: " + serverURL2);
|
|
186
|
+
console.log(" Auth Token: " + config.authToken);
|
|
187
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
188
|
+
console.log();
|
|
189
|
+
console.log(" Scan this QR code in the Anywhere app:");
|
|
190
|
+
console.log();
|
|
191
|
+
qrcode.generate(qrData, { small: true }, (code) => {
|
|
192
|
+
for (const line of code.split("\n")) {
|
|
193
|
+
console.log(" " + line);
|
|
194
|
+
}
|
|
195
|
+
console.log();
|
|
196
|
+
console.log(" Or enter the URL and token manually in Settings.");
|
|
197
|
+
if (isVPS) {
|
|
198
|
+
console.log(" Make sure port " + port + " is open in your firewall.");
|
|
199
|
+
}
|
|
200
|
+
console.log();
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (!args.includes("--no-tunnel")) {
|
|
204
|
+
let cloudflaredBin = null;
|
|
205
|
+
try {
|
|
206
|
+
execSync("which cloudflared", { stdio: "ignore" });
|
|
207
|
+
cloudflaredBin = "cloudflared";
|
|
208
|
+
} catch {
|
|
209
|
+
try {
|
|
210
|
+
execSync("npx cloudflared --version", { stdio: "ignore", timeout: 1e4 });
|
|
211
|
+
cloudflaredBin = "npx";
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (cloudflaredBin) {
|
|
216
|
+
console.log("Starting tunnel...");
|
|
217
|
+
const tunnelArgs = cloudflaredBin === "npx" ? ["cloudflared", "tunnel", "--url", `http://localhost:${port}`] : ["tunnel", "--url", `http://localhost:${port}`];
|
|
218
|
+
tunnelProcess = spawn(cloudflaredBin, tunnelArgs, {
|
|
219
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
220
|
+
});
|
|
221
|
+
tunnelURL = await new Promise((resolve) => {
|
|
222
|
+
const timeout = setTimeout(() => resolve(null), 15e3);
|
|
223
|
+
const urlRegex = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/;
|
|
224
|
+
function onData(data) {
|
|
225
|
+
const line = data.toString();
|
|
226
|
+
const match = line.match(urlRegex);
|
|
227
|
+
if (match) {
|
|
228
|
+
clearTimeout(timeout);
|
|
229
|
+
tunnelProcess.stderr?.removeListener("data", onData);
|
|
230
|
+
tunnelProcess.stdout?.removeListener("data", onData);
|
|
231
|
+
resolve(match[0]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
tunnelProcess.stderr?.on("data", onData);
|
|
235
|
+
tunnelProcess.stdout?.on("data", onData);
|
|
236
|
+
tunnelProcess.on("error", () => {
|
|
237
|
+
clearTimeout(timeout);
|
|
238
|
+
resolve(null);
|
|
239
|
+
});
|
|
240
|
+
tunnelProcess.on("exit", () => {
|
|
241
|
+
clearTimeout(timeout);
|
|
242
|
+
resolve(null);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
if (tunnelURL) {
|
|
246
|
+
console.log("Tunnel established!");
|
|
247
|
+
} else {
|
|
248
|
+
console.log("Tunnel failed, using local address.");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
var serverURL;
|
|
253
|
+
if (tunnelURL) {
|
|
254
|
+
serverURL = tunnelURL;
|
|
255
|
+
} else if (isVPS) {
|
|
256
|
+
serverURL = "http://" + publicIP + ":" + port;
|
|
181
257
|
} else {
|
|
182
|
-
|
|
258
|
+
serverURL = "http://" + (localIP || "localhost") + ":" + port;
|
|
183
259
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
260
|
+
printBanner(serverURL);
|
|
261
|
+
function cleanup() {
|
|
262
|
+
if (tunnelProcess) {
|
|
263
|
+
tunnelProcess.kill();
|
|
264
|
+
tunnelProcess = null;
|
|
265
|
+
}
|
|
266
|
+
process.exit();
|
|
189
267
|
}
|
|
190
|
-
|
|
191
|
-
|
|
268
|
+
process.on("SIGINT", cleanup);
|
|
269
|
+
process.on("SIGTERM", cleanup);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anywhere-ai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Code on any repo from your phone",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"@good-ghosting/random-name-generator": "^1.0.3",
|
|
23
23
|
"@hono/node-server": "^1.19.11",
|
|
24
24
|
"dotenv": "^17.3.1",
|
|
25
|
-
"hono": "^4.12.5"
|
|
25
|
+
"hono": "^4.12.5",
|
|
26
|
+
"qrcode-terminal": "^0.12.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "^25.3.3",
|