agent-relay 3.1.4 → 3.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.
Files changed (42) hide show
  1. package/package.json +8 -8
  2. package/packages/acp-bridge/package.json +2 -2
  3. package/packages/config/package.json +1 -1
  4. package/packages/hooks/package.json +4 -4
  5. package/packages/memory/package.json +2 -2
  6. package/packages/openclaw/dist/config.d.ts +2 -0
  7. package/packages/openclaw/dist/config.d.ts.map +1 -1
  8. package/packages/openclaw/dist/config.js +17 -6
  9. package/packages/openclaw/dist/config.js.map +1 -1
  10. package/packages/openclaw/dist/gateway.d.ts +20 -2
  11. package/packages/openclaw/dist/gateway.d.ts.map +1 -1
  12. package/packages/openclaw/dist/gateway.js +113 -14
  13. package/packages/openclaw/dist/gateway.js.map +1 -1
  14. package/packages/openclaw/dist/inject.d.ts +1 -1
  15. package/packages/openclaw/dist/inject.d.ts.map +1 -1
  16. package/packages/openclaw/dist/inject.js +2 -1
  17. package/packages/openclaw/dist/inject.js.map +1 -1
  18. package/packages/openclaw/dist/setup.d.ts.map +1 -1
  19. package/packages/openclaw/dist/setup.js +81 -10
  20. package/packages/openclaw/dist/setup.js.map +1 -1
  21. package/packages/openclaw/dist/spawn/docker.d.ts.map +1 -1
  22. package/packages/openclaw/dist/spawn/docker.js +2 -1
  23. package/packages/openclaw/dist/spawn/docker.js.map +1 -1
  24. package/packages/openclaw/dist/types.d.ts +2 -0
  25. package/packages/openclaw/dist/types.d.ts.map +1 -1
  26. package/packages/openclaw/dist/types.js +2 -1
  27. package/packages/openclaw/dist/types.js.map +1 -1
  28. package/packages/openclaw/package.json +2 -2
  29. package/packages/openclaw/skill/SKILL.md +142 -80
  30. package/packages/openclaw/src/config.ts +19 -6
  31. package/packages/openclaw/src/gateway.ts +134 -15
  32. package/packages/openclaw/src/inject.ts +2 -2
  33. package/packages/openclaw/src/setup.ts +86 -11
  34. package/packages/openclaw/src/spawn/docker.ts +2 -1
  35. package/packages/openclaw/src/types.ts +3 -0
  36. package/packages/policy/package.json +2 -2
  37. package/packages/sdk/package.json +2 -2
  38. package/packages/sdk-py/pyproject.toml +1 -1
  39. package/packages/telemetry/package.json +1 -1
  40. package/packages/trajectory/package.json +2 -2
  41. package/packages/user-directory/package.json +2 -2
  42. package/packages/utils/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import { mkdir, writeFile, readFile, copyFile } from 'node:fs/promises';
2
+ import { createConnection } from 'node:net';
2
3
  import { join, dirname } from 'node:path';
3
4
  import { existsSync } from 'node:fs';
4
5
  import { hostname } from 'node:os';
@@ -8,7 +9,21 @@ import { spawn as spawnProcess, execFileSync } from 'node:child_process';
8
9
  import { RelayCast } from '@relaycast/sdk';
9
10
 
10
11
  import { detectOpenClaw, saveGatewayConfig } from './config.js';
11
- import type { GatewayConfig } from './types.js';
12
+ import { InboundGateway } from './gateway.js';
13
+ import { DEFAULT_OPENCLAW_GATEWAY_PORT, type GatewayConfig } from './types.js';
14
+
15
+ /**
16
+ * Safely traverse a nested object by dot-separated path.
17
+ * Returns undefined if any segment is missing.
18
+ */
19
+ function extractNestedValue(obj: unknown, path: string): unknown {
20
+ let current: unknown = obj;
21
+ for (const key of path.split('.')) {
22
+ if (current == null || typeof current !== 'object') return undefined;
23
+ current = (current as Record<string, unknown>)[key];
24
+ }
25
+ return current;
26
+ }
12
27
 
13
28
  /**
14
29
  * Resolve how to invoke mcporter. Prefers a global binary, falls back to npx.
@@ -28,6 +43,26 @@ function resolveMcporter(): { cmd: string; prefix: string[] } {
28
43
  }
29
44
  }
30
45
 
46
+ /** Check if a port is already in use by attempting a TCP connection. */
47
+ function isPortInUse(port: number): Promise<boolean> {
48
+ return new Promise((resolve) => {
49
+ const socket = createConnection({ port, host: '127.0.0.1' });
50
+ socket.setTimeout(2000);
51
+ socket.once('connect', () => {
52
+ socket.destroy();
53
+ resolve(true);
54
+ });
55
+ socket.once('timeout', () => {
56
+ socket.destroy();
57
+ resolve(false);
58
+ });
59
+ socket.once('error', () => {
60
+ socket.destroy();
61
+ resolve(false);
62
+ });
63
+ });
64
+ }
65
+
31
66
  export interface SetupOptions {
32
67
  /** If provided, join this workspace. Otherwise create a new one. */
33
68
  apiKey?: string;
@@ -185,12 +220,29 @@ export async function setup(options: SetupOptions): Promise<SetupResult> {
185
220
  );
186
221
  }
187
222
 
223
+ // Extract gateway auth from openclaw.json (if available)
224
+ const openclawGatewayToken =
225
+ process.env.OPENCLAW_GATEWAY_TOKEN ??
226
+ (extractNestedValue(detection.config, 'gateway.auth.token') as string | undefined);
227
+ const openclawGatewayPortRaw =
228
+ process.env.OPENCLAW_GATEWAY_PORT ??
229
+ (extractNestedValue(detection.config, 'gateway.port') as number | string | undefined);
230
+ const openclawGatewayPort = openclawGatewayPortRaw ? Number(openclawGatewayPortRaw) : undefined;
231
+
232
+ if (!openclawGatewayToken) {
233
+ console.warn('[setup] No gateway token found in openclaw.json or OPENCLAW_GATEWAY_TOKEN env.');
234
+ console.warn('[setup] Inbound gateway may fail to pair. Set it manually:');
235
+ console.warn('[setup] export OPENCLAW_GATEWAY_TOKEN=$(cat ~/.openclaw/openclaw.json | jq -r .gateway.auth.token)');
236
+ }
237
+
188
238
  // Save gateway config (.env)
189
239
  const gatewayConfig: GatewayConfig = {
190
240
  apiKey,
191
241
  clawName,
192
242
  baseUrl,
193
243
  channels,
244
+ openclawGatewayToken,
245
+ openclawGatewayPort: Number.isFinite(openclawGatewayPort) ? openclawGatewayPort : undefined,
194
246
  };
195
247
  await saveGatewayConfig(gatewayConfig);
196
248
 
@@ -281,18 +333,41 @@ export async function setup(options: SetupOptions): Promise<SetupResult> {
281
333
  }
282
334
  }
283
335
 
284
- // Auto-start the inbound gateway in the background
336
+ // Auto-start the inbound gateway in the background, but only if one isn't
337
+ // already running. Re-running setup without this check spawns duplicates
338
+ // that fight over the control port.
285
339
  let gatewayStarted = false;
286
- try {
287
- const child = spawnProcess('npx', ['@agent-relay/openclaw', 'gateway'], {
288
- stdio: 'ignore',
289
- detached: true,
290
- env: { ...process.env, RELAY_API_KEY: apiKey, RELAY_CLAW_NAME: clawName, RELAY_BASE_URL: baseUrl },
291
- });
292
- child.unref();
340
+ // Check the inbound gateway's control port (18790), NOT the OpenClaw
341
+ // gateway WS port (18789) they are different processes.
342
+ const controlPort = Number(process.env.RELAYCAST_CONTROL_PORT) || InboundGateway.DEFAULT_CONTROL_PORT;
343
+ const gatewayAlreadyRunning = await isPortInUse(controlPort);
344
+ if (gatewayAlreadyRunning) {
345
+ console.log('[setup] Inbound gateway already running — skipping spawn.');
293
346
  gatewayStarted = true;
294
- } catch {
295
- // Non-fatal — user can start manually
347
+ } else {
348
+ try {
349
+ const gatewayEnv: Record<string, string> = {
350
+ ...process.env as Record<string, string>,
351
+ RELAY_API_KEY: apiKey,
352
+ RELAY_CLAW_NAME: clawName,
353
+ RELAY_BASE_URL: baseUrl,
354
+ };
355
+ if (openclawGatewayToken) {
356
+ gatewayEnv.OPENCLAW_GATEWAY_TOKEN = openclawGatewayToken;
357
+ }
358
+ if (openclawGatewayPort && Number.isFinite(openclawGatewayPort)) {
359
+ gatewayEnv.OPENCLAW_GATEWAY_PORT = String(openclawGatewayPort);
360
+ }
361
+ const child = spawnProcess('npx', ['@agent-relay/openclaw', 'gateway'], {
362
+ stdio: 'ignore',
363
+ detached: true,
364
+ env: gatewayEnv,
365
+ });
366
+ child.unref();
367
+ gatewayStarted = true;
368
+ } catch {
369
+ // Non-fatal — user can start manually
370
+ }
296
371
  }
297
372
 
298
373
  const parts = [
@@ -8,6 +8,7 @@ import { normalizeModelRef } from '../identity/model.js';
8
8
  import { buildIdentityTask } from '../identity/contract.js';
9
9
  import { buildAgentName } from '../identity/naming.js';
10
10
  import { convertCodexAuth } from '../auth/converter.js';
11
+ import { DEFAULT_OPENCLAW_GATEWAY_PORT } from '../types.js';
11
12
 
12
13
  async function pathExists(targetPath: string): Promise<boolean> {
13
14
  try {
@@ -152,7 +153,7 @@ export class DockerSpawnProvider implements SpawnProvider {
152
153
  const modelRef = normalizeModelRef(options.model, preferredProvider);
153
154
  const workspaceId = options.workspaceId ?? `local-${Date.now().toString(36)}`;
154
155
  const agentName = buildAgentName(workspaceId, options.name);
155
- const gatewayPort = 18789; // Internal to container — each container is isolated
156
+ const gatewayPort = DEFAULT_OPENCLAW_GATEWAY_PORT; // Internal to container — each container is isolated
156
157
  const identityTask = buildIdentityTask(agentName, workspaceId, modelRef);
157
158
  const channels = options.channels?.length ? options.channels : ['general'];
158
159
  const gatewayToken = randomUUID().replace(/-/g, '').slice(0, 32);
@@ -1,3 +1,6 @@
1
+ /** Default port for the local OpenClaw gateway WebSocket API. */
2
+ export const DEFAULT_OPENCLAW_GATEWAY_PORT = 18789;
3
+
1
4
  export interface GatewayConfig {
2
5
  /** Relaycast workspace API key (rk_live_*). */
3
6
  apiKey: string;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/policy",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "Agent policy management with multi-level fallback (repo, local PRPM, cloud workspace)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@agent-relay/config": "3.1.4"
25
+ "@agent-relay/config": "3.1.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.19.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/sdk",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -81,7 +81,7 @@
81
81
  "typescript": "^5.7.3"
82
82
  },
83
83
  "dependencies": {
84
- "@agent-relay/config": "3.1.4",
84
+ "@agent-relay/config": "3.1.6",
85
85
  "@relaycast/sdk": "^0.4.0",
86
86
  "yaml": "^2.7.0"
87
87
  }
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agent-relay-sdk"
7
- version = "3.1.4"
7
+ version = "3.1.6"
8
8
  description = "Python SDK for Agent Relay workflows"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/telemetry",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "Anonymous telemetry for Agent Relay usage analytics",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/trajectory",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "Trajectory integration utilities (trail/PDERO) for Relay",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@agent-relay/config": "3.1.4"
25
+ "@agent-relay/config": "3.1.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.19.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/user-directory",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "User directory service for agent-relay (per-user credential storage)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@agent-relay/utils": "3.1.4"
25
+ "@agent-relay/utils": "3.1.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.19.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-relay/utils",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "Shared utilities for agent-relay: logging, name generation, command resolution, update checking",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",
@@ -112,7 +112,7 @@
112
112
  "vitest": "^3.2.4"
113
113
  },
114
114
  "dependencies": {
115
- "@agent-relay/config": "3.1.4",
115
+ "@agent-relay/config": "3.1.6",
116
116
  "compare-versions": "^6.1.1"
117
117
  },
118
118
  "publishConfig": {