@coclaw/openclaw-coclaw 0.3.1 → 0.3.2
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/index.js +5 -6
- package/package.json +1 -1
- package/src/realtime-bridge.js +15 -14
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { registerCoclawCli } from './src/cli-registrar.js';
|
|
|
3
3
|
import { resolveErrorMessage } from './src/common/errors.js';
|
|
4
4
|
import { notBound, bindOk, unbindOk } from './src/common/messages.js';
|
|
5
5
|
import { coclawChannelPlugin } from './src/channel-plugin.js';
|
|
6
|
-
import { ensureAgentSession,
|
|
6
|
+
import { ensureAgentSession, restartRealtimeBridge, stopRealtimeBridge } from './src/realtime-bridge.js';
|
|
7
7
|
import { setRuntime } from './src/runtime.js';
|
|
8
8
|
import { createSessionManager } from './src/session-manager/manager.js';
|
|
9
9
|
import { AutoUpgradeScheduler } from './src/auto-upgrade/updater.js';
|
|
@@ -61,7 +61,7 @@ const plugin = {
|
|
|
61
61
|
api.registerService({
|
|
62
62
|
id: 'coclaw-realtime-bridge',
|
|
63
63
|
async start() {
|
|
64
|
-
await
|
|
64
|
+
await restartRealtimeBridge({ logger, pluginConfig: api.pluginConfig });
|
|
65
65
|
},
|
|
66
66
|
async stop() {
|
|
67
67
|
await stopRealtimeBridge();
|
|
@@ -70,7 +70,7 @@ const plugin = {
|
|
|
70
70
|
|
|
71
71
|
api.registerGatewayMethod('coclaw.refreshBridge', async ({ respond }) => {
|
|
72
72
|
try {
|
|
73
|
-
await
|
|
73
|
+
await restartRealtimeBridge({ logger, pluginConfig: api.pluginConfig });
|
|
74
74
|
respond(true, { status: 'refreshed' });
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
@@ -141,14 +141,13 @@ const plugin = {
|
|
|
141
141
|
|
|
142
142
|
try {
|
|
143
143
|
if (action === 'bind') {
|
|
144
|
-
//
|
|
145
|
-
await stopRealtimeBridge();
|
|
144
|
+
await stopRealtimeBridge(); // 先断开,避免 bindBot 内 unbind 触发 bot.unbound 竞态
|
|
146
145
|
const serverUrl = options.server ?? api.pluginConfig?.serverUrl;
|
|
147
146
|
const result = await bindBot({
|
|
148
147
|
code: positionals[0],
|
|
149
148
|
serverUrl,
|
|
150
149
|
});
|
|
151
|
-
await
|
|
150
|
+
await restartRealtimeBridge({ logger, pluginConfig: api.pluginConfig });
|
|
152
151
|
return { text: bindOk(result) };
|
|
153
152
|
}
|
|
154
153
|
|
package/package.json
CHANGED
package/src/realtime-bridge.js
CHANGED
|
@@ -352,7 +352,7 @@ export class RealtimeBridge {
|
|
|
352
352
|
platform: process.platform,
|
|
353
353
|
mode: 'backend',
|
|
354
354
|
},
|
|
355
|
-
caps: [],
|
|
355
|
+
caps: ['tool-events'],
|
|
356
356
|
role: 'operator',
|
|
357
357
|
scopes: ['operator.admin'],
|
|
358
358
|
auth: authToken ? { token: authToken } : undefined,
|
|
@@ -713,31 +713,32 @@ export class RealtimeBridge {
|
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
// --- 单例便捷 API(供 index.js 使用)---
|
|
716
|
+
// 仅暴露 restartRealtimeBridge / stopRealtimeBridge 两个操作:
|
|
717
|
+
// restart(opts) — 无论当前状态,确保 bridge 以给定 opts 运行(幂等)
|
|
718
|
+
// stop() — 停止并销毁 singleton
|
|
719
|
+
// 调用方无需感知 singleton 是否为 null,选"要运行"或"要停止"即可。
|
|
716
720
|
|
|
717
721
|
let singleton = null;
|
|
718
722
|
|
|
719
|
-
|
|
723
|
+
/**
|
|
724
|
+
* 确保 bridge 运行:已有实例则 stop 后重建,无则直接创建。opts 必传。
|
|
725
|
+
* @param {{ logger, pluginConfig }} opts
|
|
726
|
+
*/
|
|
727
|
+
export async function restartRealtimeBridge(opts) {
|
|
728
|
+
if (singleton) {
|
|
729
|
+
await singleton.stop();
|
|
730
|
+
singleton = null;
|
|
731
|
+
}
|
|
720
732
|
singleton = new RealtimeBridge();
|
|
721
733
|
await singleton.start(opts);
|
|
722
734
|
}
|
|
723
735
|
|
|
724
|
-
export async function refreshRealtimeBridge(opts) {
|
|
725
|
-
if (!singleton) {
|
|
726
|
-
// stop 后 singleton 被清除,需重新创建(如 bind 后重连)
|
|
727
|
-
if (opts) {
|
|
728
|
-
await startRealtimeBridge(opts);
|
|
729
|
-
}
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
await singleton.refresh();
|
|
733
|
-
}
|
|
734
|
-
|
|
735
736
|
export async function stopRealtimeBridge() {
|
|
736
737
|
if (!singleton) {
|
|
737
738
|
return;
|
|
738
739
|
}
|
|
739
740
|
await singleton.stop();
|
|
740
|
-
singleton = null;
|
|
741
|
+
singleton = null; // 置 null 后须通过 restartRealtimeBridge 重建
|
|
741
742
|
}
|
|
742
743
|
|
|
743
744
|
export async function ensureAgentSession(agentId) {
|