@coclaw/openclaw-coclaw 0.1.4 → 0.1.6

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 CHANGED
@@ -117,8 +117,8 @@ const plugin = {
117
117
  }
118
118
 
119
119
  try {
120
- const serverUrl = options.server ?? api.pluginConfig?.serverUrl;
121
120
  if (action === 'bind') {
121
+ const serverUrl = options.server ?? api.pluginConfig?.serverUrl;
122
122
  const result = await bindBot({
123
123
  code: positionals[0],
124
124
  serverUrl,
@@ -128,7 +128,7 @@ const plugin = {
128
128
  }
129
129
 
130
130
  if (action === 'unbind') {
131
- const result = await unbindBot({ serverUrl });
131
+ const result = await unbindBot({ serverUrl: options.server });
132
132
  await stopRealtimeBridge();
133
133
  return { text: unbindOk(result) };
134
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coclaw/openclaw-coclaw",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "OpenClaw CoClaw channel plugin for remote chat",
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  function resolveServerUrl(opts, config) {
10
10
  return opts?.server
11
- ?? config?.plugins?.entries?.['coclaw']?.config?.serverUrl
11
+ ?? config?.plugins?.entries?.['openclaw-coclaw']?.config?.serverUrl
12
12
  ?? process.env.COCLAW_SERVER_URL;
13
13
  }
14
14
 
@@ -69,8 +69,7 @@ export function registerCoclawCli({ program, config, logger }, deps = {}) {
69
69
  .option('--server <url>', 'CoClaw server URL')
70
70
  .action(async (opts) => {
71
71
  try {
72
- const serverUrl = resolveServerUrl(opts, config);
73
- const result = await unbindBot({ serverUrl });
72
+ const result = await unbindBot({ serverUrl: opts?.server });
74
73
  /* c8 ignore next */
75
74
  console.log(unbindOk(result));
76
75
  await notifyGateway('coclaw.stopBridge');
@@ -80,8 +79,10 @@ export function registerCoclawCli({ program, config, logger }, deps = {}) {
80
79
  process.exitCode = 1;
81
80
  return;
82
81
  }
82
+ /* c8 ignore start -- 防御性兜底,unbindBot 当前仅抛 NOT_BOUND */
83
83
  console.error(`Error: ${resolveErrorMessage(err)}`);
84
84
  process.exitCode = 1;
85
85
  }
86
+ /* c8 ignore stop */
86
87
  });
87
88
  }
package/src/cli.js CHANGED
@@ -98,8 +98,10 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
98
98
  console.error(notBound());
99
99
  return 1;
100
100
  }
101
+ /* c8 ignore start -- 防御性兜底,unbindBot 当前仅抛 NOT_BOUND */
101
102
  throw err;
102
103
  }
104
+ /* c8 ignore stop */
103
105
  }
104
106
 
105
107
  throw new Error(`unknown command: ${command}`);
@@ -1,7 +1,7 @@
1
1
  import { bindWithServer, unbindWithServer } from '../api.js';
2
2
  import { clearConfig, readConfig, writeConfig } from '../config.js';
3
3
 
4
- const DEFAULT_SERVER_URL = 'http://127.0.0.1:3000';
4
+ const DEFAULT_SERVER_URL = 'https://im.coclaw.net';
5
5
 
6
6
  export async function bindBot({ code, serverUrl }) {
7
7
  if (!code) {
@@ -50,27 +50,27 @@ export async function unbindBot({ serverUrl }) {
50
50
  throw err;
51
51
  }
52
52
 
53
- /* c8 ignore next */
54
- const baseUrl = serverUrl ?? config.serverUrl ?? process.env.COCLAW_SERVER_URL ?? DEFAULT_SERVER_URL;
53
+ const baseUrl = serverUrl ?? config.serverUrl;
54
+
55
+ // 用户主动解绑:无论 server 通知成功与否,都清理本地绑定
55
56
  let data = null;
56
- let alreadyServerUnbound = false;
57
- try {
58
- data = await unbindWithServer({
59
- baseUrl,
60
- token: config.token,
61
- });
62
- }
63
- catch (err) {
64
- if (err?.response?.data?.code !== 'UNAUTHORIZED') {
65
- throw err;
57
+ let serverError = null;
58
+ if (baseUrl) {
59
+ try {
60
+ data = await unbindWithServer({
61
+ baseUrl,
62
+ token: config.token,
63
+ });
64
+ }
65
+ catch (err) {
66
+ serverError = err;
66
67
  }
67
- alreadyServerUnbound = true;
68
68
  }
69
69
 
70
70
  await clearConfig();
71
71
 
72
72
  return {
73
73
  botId: data?.botId ?? config.botId,
74
- alreadyServerUnbound,
74
+ serverError,
75
75
  };
76
76
  }
@@ -5,10 +5,10 @@ export function bindOk({ botId, rebound }) {
5
5
  return `OK. Bot (${botId}) ${action} to CoClaw.`;
6
6
  }
7
7
 
8
- export function unbindOk({ botId, alreadyServerUnbound }) {
8
+ export function unbindOk({ botId, serverError }) {
9
9
  const id = botId ?? 'unknown';
10
- const tag = alreadyServerUnbound
11
- ? ' (server side already cleared, local config removed)'
10
+ const tag = serverError
11
+ ? ' (server notification failed; you can unbind the orphan bot in the CoClaw app)'
12
12
  : '';
13
13
  return `OK. Bot (${id}) unbound from CoClaw.${tag}`;
14
14
  }
@@ -6,7 +6,6 @@ import nodePath from 'node:path';
6
6
  import { clearConfig, getBindingsPath, readConfig } from './config.js';
7
7
  import { getRuntime } from './runtime.js';
8
8
 
9
- const DEFAULT_SERVER_URL = 'http://127.0.0.1:3000';
10
9
  const DEFAULT_GATEWAY_WS_URL = 'ws://127.0.0.1:18789';
11
10
  const RECONNECT_MS = 10_000;
12
11
  const CONNECT_TIMEOUT_MS = 10_000;
@@ -410,7 +409,11 @@ async function connectIfNeeded() {
410
409
  return;
411
410
  }
412
411
 
413
- const baseUrl = currentPluginConfig?.serverUrl ?? cfg.serverUrl ?? process.env.COCLAW_SERVER_URL ?? DEFAULT_SERVER_URL;
412
+ const baseUrl = cfg.serverUrl;
413
+ if (!baseUrl) {
414
+ currentLogger.warn?.(`[coclaw] realtime bridge skip connect: missing serverUrl in ${bindingsPath}`);
415
+ return;
416
+ }
414
417
  const target = toServerWsUrl(baseUrl, cfg.token);
415
418
  const WebSocketCtor = globalThis.WebSocket;
416
419
  if (!WebSocketCtor) {