clawnexus 0.2.8 → 0.3.1

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.
@@ -59,25 +59,38 @@ class AutoRegister extends node_events_1.EventEmitter {
59
59
  this.emit("skip", "No local OpenClaw instance detected");
60
60
  return;
61
61
  }
62
- // Try agentId, then agentId-2, agentId-3, ... if name already taken by another owner
62
+ // Build list of base names to try: agentId first, then auto_name as fallback
63
+ const selfInstance = this.store.getAll().find((i) => i.is_self);
64
+ const autoName = selfInstance?.auto_name;
65
+ const bases = [agentId];
66
+ if (autoName && autoName !== agentId)
67
+ bases.push(autoName);
68
+ // Try each base with suffixes -1, -2, ... up to MAX_SUFFIX if taken by another owner
63
69
  const MAX_SUFFIX = 10;
64
70
  let result = null;
65
- for (let i = 0; i <= MAX_SUFFIX; i++) {
66
- const clawId = i === 0 ? agentId : `${agentId}-${i}`;
67
- try {
68
- result = await this.client.register({ claw_id: clawId });
69
- break;
70
- }
71
- catch (err) {
72
- if (err instanceof client_js_1.RegistryError && err.statusCode === 409 && i < MAX_SUFFIX) {
73
- continue; // name taken by another owner, try next suffix
71
+ outer: for (const base of bases) {
72
+ for (let i = 0; i <= MAX_SUFFIX; i++) {
73
+ const clawId = i === 0 ? base : `${base}-${i}`;
74
+ try {
75
+ result = await this.client.register({ claw_id: clawId });
76
+ break outer;
77
+ }
78
+ catch (err) {
79
+ if (err instanceof client_js_1.RegistryError && err.statusCode === 409 && i < MAX_SUFFIX) {
80
+ continue; // name taken by another owner, try next suffix
81
+ }
82
+ if (err instanceof client_js_1.RegistryError && err.statusCode === 409 && i === MAX_SUFFIX) {
83
+ break; // exhausted suffixes for this base, try next base
84
+ }
85
+ this.emit("error", err);
86
+ return;
74
87
  }
75
- this.emit("error", err);
76
- return;
77
88
  }
78
89
  }
79
- if (!result)
90
+ if (!result) {
91
+ this.emit("error", new Error(`All candidate names exhausted (bases: ${bases.join(", ")})`));
80
92
  return;
93
+ }
81
94
  this.registeredClawName = result.record.name;
82
95
  // Start heartbeat on first successful registration
83
96
  if (!this.heartbeatTimer) {
@@ -85,13 +98,12 @@ class AutoRegister extends node_events_1.EventEmitter {
85
98
  this.tryRegister().catch(() => { });
86
99
  }, HEARTBEAT_INTERVAL_MS);
87
100
  }
88
- // Write claw_name back to the local instance in store
89
- const instances = this.store.getAll();
90
- const selfInstance = instances.find((i) => i.is_self && i.agent_id === agentId);
91
- if (selfInstance) {
92
- selfInstance.claw_name = result.record.name;
93
- selfInstance.owner_pubkey = result.record.ownerPubkey;
94
- this.store.upsert(selfInstance);
101
+ // Write claw_name back to the local instance in store (re-fetch after possible state change)
102
+ const registeredSelf = this.store.getAll().find((i) => i.is_self && i.agent_id === agentId);
103
+ if (registeredSelf) {
104
+ registeredSelf.claw_name = result.record.name;
105
+ registeredSelf.owner_pubkey = result.record.ownerPubkey;
106
+ this.store.upsert(registeredSelf);
95
107
  }
96
108
  this.emit("registered", {
97
109
  action: result.action,
@@ -8,7 +8,7 @@ export interface RelayConnectorOptions {
8
8
  autoAccept?: boolean;
9
9
  }
10
10
  export declare class RelayConnector extends EventEmitter {
11
- private readonly options;
11
+ private options;
12
12
  private ws;
13
13
  private state;
14
14
  private rooms;
@@ -17,10 +17,14 @@ export declare class RelayConnector extends EventEmitter {
17
17
  private reconnectTimer;
18
18
  private closed;
19
19
  constructor(options: RelayConnectorOptions);
20
+ /** Update the auth token (e.g. after token refresh). */
21
+ updateAuthToken(token: string): void;
20
22
  /** Connect to the relay and REGISTER this claw_id. */
21
23
  connect(): void;
22
24
  /** Disconnect and stop reconnecting. */
23
25
  disconnect(): void;
26
+ private pendingJoins;
27
+ private lastJoinTarget;
24
28
  /** Initiate a connection to a remote claw_id through the relay. */
25
29
  join(targetClawId: string): void;
26
30
  /** Send an encrypted message to a peer in a room. */
@@ -20,6 +20,10 @@ class RelayConnector extends node_events_1.EventEmitter {
20
20
  this.options = options;
21
21
  this.keyPair = (0, crypto_js_1.generateKeyPair)();
22
22
  }
23
+ /** Update the auth token (e.g. after token refresh). */
24
+ updateAuthToken(token) {
25
+ this.options = { ...this.options, authToken: token };
26
+ }
23
27
  /** Connect to the relay and REGISTER this claw_id. */
24
28
  connect() {
25
29
  if (this.state !== "disconnected")
@@ -66,8 +70,12 @@ class RelayConnector extends node_events_1.EventEmitter {
66
70
  this.ws?.close();
67
71
  this.cleanup();
68
72
  }
73
+ // Tracks target claw_id for pending JOIN requests
74
+ pendingJoins = new Map(); // target_claw_id → target_claw_id (for JOINED room_id lookup)
75
+ lastJoinTarget = null;
69
76
  /** Initiate a connection to a remote claw_id through the relay. */
70
77
  join(targetClawId) {
78
+ this.lastJoinTarget = targetClawId;
71
79
  this.send({
72
80
  type: "JOIN",
73
81
  claw_id: this.options.clawId,
@@ -78,8 +86,10 @@ class RelayConnector extends node_events_1.EventEmitter {
78
86
  /** Send an encrypted message to a peer in a room. */
79
87
  sendData(roomId, plaintext) {
80
88
  const room = this.rooms.get(roomId);
81
- if (!room || !room.session_key)
89
+ if (!room || !room.session_key) {
90
+ console.log(`[clawnexus] [Relay] sendData failed: room=${roomId} exists=${!!room} hasKey=${!!room?.session_key}`);
82
91
  return false;
92
+ }
83
93
  const payload = (0, crypto_js_1.encrypt)(room.session_key, plaintext);
84
94
  this.send({ type: "DATA", room_id: roomId, payload });
85
95
  return true;
@@ -98,6 +108,7 @@ class RelayConnector extends node_events_1.EventEmitter {
98
108
  room_id: r.room_id,
99
109
  peer_claw_id: r.peer_claw_id,
100
110
  state: r.state,
111
+ has_session_key: !!r.session_key,
101
112
  })),
102
113
  };
103
114
  }
@@ -139,7 +150,7 @@ class RelayConnector extends node_events_1.EventEmitter {
139
150
  // We are the initiator — create room entry
140
151
  this.rooms.set(msg.room_id, {
141
152
  room_id: msg.room_id,
142
- peer_claw_id: "", // will be known after key exchange
153
+ peer_claw_id: this.lastJoinTarget ?? "",
143
154
  state: "active",
144
155
  });
145
156
  // Send our public key
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type ClawImplementation = "openclaw" | "goclaw" | "zeroclaw" | "picoclaw" | "nanoclaw" | "nanobot" | "unknown";
1
+ export type ClawImplementation = "openclaw" | "goclaw" | "zeroclaw" | "picoclaw" | "nanoclaw" | "nanobot" | "openfang" | "unknown";
2
2
  export interface ClawInstance {
3
3
  agent_id: string;
4
4
  auto_name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawnexus",
3
- "version": "0.2.8",
3
+ "version": "0.3.1",
4
4
  "description": "ClawNexus daemon and CLI — AI instance registry for OpenClaw",
5
5
  "license": "MIT",
6
6
  "author": "alan-silverstreams <alan@silverstream.tech>",