agentlife 1.1.2 → 1.1.3

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.
Files changed (2) hide show
  1. package/dist/index.js +31 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2164,6 +2164,29 @@ import * as fsSync2 from "node:fs";
2164
2164
  import { createRequire as createRequire3 } from "node:module";
2165
2165
  import * as os2 from "node:os";
2166
2166
  import * as path6 from "node:path";
2167
+ async function detectTunnelUrl(port) {
2168
+ try {
2169
+ const cfgPath = path6.join(os2.homedir(), ".cloudflared", "config.yml");
2170
+ if (!fsSync2.existsSync(cfgPath))
2171
+ return null;
2172
+ const cfg = fsSync2.readFileSync(cfgPath, "utf-8");
2173
+ const lines = cfg.split(`
2174
+ `);
2175
+ for (let i = 0;i < lines.length; i++) {
2176
+ const hostMatch = lines[i].match(/hostname:\s*(.+)/);
2177
+ if (hostMatch) {
2178
+ const nextLine = lines[i + 1] || "";
2179
+ const svcMatch = nextLine.match(/service:\s*http:\/\/localhost:(\d+)/);
2180
+ if (svcMatch && parseInt(svcMatch[1]) === port) {
2181
+ return `wss://${hostMatch[1].trim()}`;
2182
+ }
2183
+ }
2184
+ }
2185
+ return null;
2186
+ } catch {
2187
+ return null;
2188
+ }
2189
+ }
2167
2190
  function registerPairingServices(api) {
2168
2191
  api.registerService({
2169
2192
  id: "agentlife-pairing-qr",
@@ -2175,15 +2198,18 @@ function registerPairingServices(api) {
2175
2198
  const token = cfg.gateway?.auth?.token;
2176
2199
  if (!token)
2177
2200
  return;
2178
- let host;
2179
- if (bind === "lan" || bind === "auto" || bind === "custom") {
2201
+ let url;
2202
+ const tunnelUrl = await detectTunnelUrl(port);
2203
+ if (tunnelUrl) {
2204
+ url = tunnelUrl;
2205
+ } else if (bind === "lan" || bind === "auto" || bind === "custom") {
2180
2206
  const nets = os2.networkInterfaces();
2181
2207
  const lanIp = Object.values(nets).flat().find((n) => n && !n.internal && n.family === "IPv4")?.address;
2182
- host = lanIp ?? "127.0.0.1";
2208
+ url = `ws://${lanIp ?? "127.0.0.1"}:${port}`;
2183
2209
  } else {
2184
- host = "127.0.0.1";
2210
+ url = `ws://127.0.0.1:${port}`;
2185
2211
  }
2186
- const payload = JSON.stringify({ url: `ws://${host}:${port}`, token });
2212
+ const payload = JSON.stringify({ url, token });
2187
2213
  const setupCode = Buffer.from(payload).toString("base64");
2188
2214
  let qrTerminal = null;
2189
2215
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentlife",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "bun build index.ts --outfile dist/index.js --target node --external openclaw/plugin-sdk",