openclaw-bridge 0.5.2 → 0.5.4
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 +41 -0
- package/dist/heartbeat.js +17 -4
- package/dist/index.js +21 -0
- package/dist/manager/hub-client.js +2 -11
- package/dist/project-manager.js +2 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -852,6 +852,47 @@ function checkAndFixBridgeConfig() {
|
|
|
852
852
|
console.log(` [${configPath}] WARNING: registry and fileRelay point to different hosts (${regUrl} vs ${relayUrl})`);
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
|
+
// Fix 6: Auto-add localManager from fileRelay if missing
|
|
856
|
+
if (!bridgeConfig.localManager && bridgeConfig.fileRelay?.baseUrl) {
|
|
857
|
+
bridgeConfig.localManager = {
|
|
858
|
+
enabled: true,
|
|
859
|
+
hubUrl: bridgeConfig.fileRelay.baseUrl,
|
|
860
|
+
managerPass: "",
|
|
861
|
+
};
|
|
862
|
+
console.log(` [${configPath}] Added localManager (hubUrl = ${bridgeConfig.fileRelay.baseUrl})`);
|
|
863
|
+
changed = true;
|
|
864
|
+
fixes++;
|
|
865
|
+
}
|
|
866
|
+
// Fix 7: Auto-detect discordId from Discord token and store in bridge config
|
|
867
|
+
const discordAccounts = config.channels?.discord?.accounts;
|
|
868
|
+
if (discordAccounts && !bridgeConfig.discordId) {
|
|
869
|
+
for (const [accountId, account] of Object.entries(discordAccounts)) {
|
|
870
|
+
const acc = account;
|
|
871
|
+
if (!acc.token)
|
|
872
|
+
continue;
|
|
873
|
+
try {
|
|
874
|
+
const firstSegment = acc.token.split(".")[0];
|
|
875
|
+
const decoded = Buffer.from(firstSegment, "base64").toString("utf-8");
|
|
876
|
+
if (/^\d+$/.test(decoded)) {
|
|
877
|
+
console.log(` [${configPath}] Detected discordId ${decoded} from account "${accountId}"`);
|
|
878
|
+
break; // Just report, heartbeat handles the rest at runtime
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
catch { /* skip */ }
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
// Fix 8: Set dmHistoryLimit to 0 for Discord accounts with dmPolicy (OpenViking handles memory)
|
|
885
|
+
if (discordAccounts) {
|
|
886
|
+
for (const [accountId, account] of Object.entries(discordAccounts)) {
|
|
887
|
+
const acc = account;
|
|
888
|
+
if (acc.dmPolicy && acc.dmHistoryLimit === undefined) {
|
|
889
|
+
acc.dmHistoryLimit = 0;
|
|
890
|
+
console.log(` [${configPath}] Set dmHistoryLimit=0 for discord account "${accountId}"`);
|
|
891
|
+
changed = true;
|
|
892
|
+
fixes++;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
855
896
|
if (changed) {
|
|
856
897
|
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
857
898
|
}
|
package/dist/heartbeat.js
CHANGED
|
@@ -103,10 +103,23 @@ export class BridgeHeartbeat {
|
|
|
103
103
|
const config = JSON.parse(raw);
|
|
104
104
|
// Find this agent's Discord binding
|
|
105
105
|
const binding = config.bindings?.find((b) => b.agentId === this.entry.agentId && b.match.channel === "discord");
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
let token;
|
|
107
|
+
if (binding) {
|
|
108
|
+
const accountId = binding.match.accountId;
|
|
109
|
+
token = config.channels?.discord?.accounts?.[accountId]?.token;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// No bindings configured — fallback: use first enabled Discord account
|
|
113
|
+
const accounts = config.channels?.discord?.accounts;
|
|
114
|
+
if (accounts) {
|
|
115
|
+
for (const account of Object.values(accounts)) {
|
|
116
|
+
if (account.token) {
|
|
117
|
+
token = account.token;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
110
123
|
if (!token)
|
|
111
124
|
return;
|
|
112
125
|
// Extract Discord user ID from token (first segment is base64-encoded user ID)
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,27 @@ function autoPatchConfig(logger) {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
// 4. Auto-add localManager from fileRelay if missing
|
|
77
|
+
if (bridgeConfig && !bridgeConfig.localManager && bridgeConfig.fileRelay?.baseUrl) {
|
|
78
|
+
bridgeConfig.localManager = {
|
|
79
|
+
enabled: true,
|
|
80
|
+
hubUrl: bridgeConfig.fileRelay.baseUrl,
|
|
81
|
+
managerPass: '',
|
|
82
|
+
};
|
|
83
|
+
changes.push(`Added localManager (hubUrl = ${bridgeConfig.fileRelay.baseUrl})`);
|
|
84
|
+
}
|
|
85
|
+
// 5. Auto-add gateway.auth.token if missing
|
|
86
|
+
if (bridgeConfig && !config.gateway?.auth?.token) {
|
|
87
|
+
config.gateway = config.gateway || {};
|
|
88
|
+
config.gateway.auth = config.gateway.auth || {};
|
|
89
|
+
if (!config.gateway.auth.mode)
|
|
90
|
+
config.gateway.auth.mode = 'token';
|
|
91
|
+
if (!config.gateway.auth.token) {
|
|
92
|
+
const token = `bridge-${bridgeConfig.agentId || 'agent'}-${Date.now().toString(36)}`;
|
|
93
|
+
config.gateway.auth.token = token;
|
|
94
|
+
changes.push('Added gateway.auth.token');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
76
97
|
if (changes.length > 0) {
|
|
77
98
|
writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
78
99
|
logger.info(`[bridge] Auto-patched openclaw.json (${changes.length} changes):`);
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
|
-
import {
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
|
-
function readMachineId() {
|
|
6
|
-
try {
|
|
7
|
-
const id = readFileSync(join(homedir(), ".openclaw", ".machine-id"), "utf-8").trim();
|
|
8
|
-
if (id) return id;
|
|
9
|
-
} catch {}
|
|
10
|
-
return hostname();
|
|
11
|
-
}
|
|
2
|
+
import { getMachineId } from "../config.js";
|
|
12
3
|
export class ManagerHubClient {
|
|
13
4
|
hubUrl;
|
|
14
5
|
apiKey;
|
|
@@ -23,7 +14,7 @@ export class ManagerHubClient {
|
|
|
23
14
|
this.hubUrl = hubUrl;
|
|
24
15
|
this.apiKey = apiKey;
|
|
25
16
|
this.managerPass = managerPass;
|
|
26
|
-
this.machineId =
|
|
17
|
+
this.machineId = getMachineId();
|
|
27
18
|
this.logger = logger;
|
|
28
19
|
}
|
|
29
20
|
get connected() {
|
package/dist/project-manager.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, copyFileSync, } from "node:fs";
|
|
2
2
|
import { join, basename } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
const SOFT_ROUND_LIMIT = 8;
|
|
4
5
|
const HARD_ROUND_LIMIT = 15;
|
|
5
6
|
function nowIso() {
|
|
@@ -21,7 +22,7 @@ export class ProjectManager {
|
|
|
21
22
|
baseDir;
|
|
22
23
|
logger;
|
|
23
24
|
constructor(workspacePath, logger) {
|
|
24
|
-
this.baseDir = join(workspacePath, "_projects");
|
|
25
|
+
this.baseDir = join(workspacePath || join(homedir(), ".openclaw"), "_projects");
|
|
25
26
|
this.logger = logger;
|
|
26
27
|
mkdirSync(this.baseDir, { recursive: true });
|
|
27
28
|
this.logger.info(`[ProjectManager] base dir: ${this.baseDir}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-bridge",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"author": "Bill Zhao (https://www.linkedin.com/in/billzhaodi/)",
|
|
5
5
|
"description": "OpenClaw plugin for cross-gateway communication — agent discovery, file transfer, real-time messaging, session handoff, and local process management. Install as plugin: openclaw plugins install openclaw-bridge",
|
|
6
6
|
"type": "module",
|