@omnixal/openclaw-nats-plugin 0.2.12 → 0.2.13

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/cli/bun-setup.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from './paths';
8
8
  import { downloadNatsServer, NATS_VERSION } from './download-nats';
9
9
  import { writeNatsConfig } from './nats-config';
10
- import { generateApiKey, getExistingApiKey, writeEnvVariables } from './env-writer';
10
+ import { generateApiKey, getExistingApiKey, getExistingHookToken, writeEnvVariables } from './env-writer';
11
11
  import {
12
12
  getServiceManager, generateSystemdUnit, generateLaunchdPlist,
13
13
  installSystemdUnit, installLaunchdPlist, startService, stopService,
@@ -48,6 +48,7 @@ export async function bunSetup(): Promise<void> {
48
48
 
49
49
  // 6. Reuse existing API key or generate new one
50
50
  const apiKey = getExistingApiKey() ?? generateApiKey();
51
+ const hookToken = getExistingHookToken() ?? generateApiKey();
51
52
 
52
53
  // 7. Write env variables (to OpenClaw .env for hooks, and sidecar .env for the service)
53
54
  const envVars: Record<string, string> = {
@@ -55,6 +56,7 @@ export async function bunSetup(): Promise<void> {
55
56
  NATS_PLUGIN_API_KEY: apiKey,
56
57
  NATS_SERVERS: 'nats://127.0.0.1:4222',
57
58
  OPENCLAW_GATEWAY_URL: 'http://127.0.0.1:18789',
59
+ OPENCLAW_HOOK_TOKEN: hookToken,
58
60
  };
59
61
  writeEnvVariables(envVars);
60
62
 
@@ -66,6 +68,7 @@ export async function bunSetup(): Promise<void> {
66
68
  `NATS_SERVERS=nats://127.0.0.1:4222`,
67
69
  `NATS_PLUGIN_API_KEY=${apiKey}`,
68
70
  `OPENCLAW_GATEWAY_URL=http://127.0.0.1:18789`,
71
+ `OPENCLAW_HOOK_TOKEN=${hookToken}`,
69
72
  ].join('\n');
70
73
  writeFileSync(join(SIDECAR_DIR, '.env'), sidecarEnv, 'utf-8');
71
74
 
@@ -2,7 +2,7 @@ import { mkdirSync, cpSync, writeFileSync, existsSync } from 'node:fs';
2
2
  import { execFileSync } from 'node:child_process';
3
3
  import { join, dirname } from 'node:path';
4
4
  import { PLUGIN_DIR, DOCKER_DIR, DASHBOARD_DIR, STATE_FILE, type PluginState } from './paths';
5
- import { generateApiKey, getExistingApiKey, writeEnvVariables } from './env-writer';
5
+ import { generateApiKey, getExistingApiKey, getExistingHookToken, writeEnvVariables } from './env-writer';
6
6
 
7
7
  /**
8
8
  * Try to copy dashboard dist into a running OpenClaw container's volume.
@@ -58,9 +58,10 @@ export async function dockerSetup(): Promise<void> {
58
58
  cpSync(templateDir, DOCKER_DIR, { recursive: true });
59
59
  cpSync(sidecarSrc, join(DOCKER_DIR, 'sidecar'), { recursive: true });
60
60
 
61
- // 2. Reuse existing API key or generate new one
61
+ // 2. Reuse existing API key and hook token or generate new ones
62
62
  const apiKey = getExistingApiKey() ?? generateApiKey();
63
- writeFileSync(join(DOCKER_DIR, '.env'), `NATS_PLUGIN_API_KEY=${apiKey}\n`);
63
+ const hookToken = getExistingHookToken() ?? generateApiKey();
64
+ writeFileSync(join(DOCKER_DIR, '.env'), `NATS_PLUGIN_API_KEY=${apiKey}\nOPENCLAW_HOOK_TOKEN=${hookToken}\n`);
64
65
 
65
66
  // 3. Build and start
66
67
  console.log('Building and starting containers...');
@@ -71,6 +72,8 @@ export async function dockerSetup(): Promise<void> {
71
72
  NATS_SIDECAR_URL: 'http://127.0.0.1:3104',
72
73
  NATS_PLUGIN_API_KEY: apiKey,
73
74
  NATS_SERVERS: 'nats://127.0.0.1:4222',
75
+ OPENCLAW_GATEWAY_URL: 'http://127.0.0.1:18789',
76
+ OPENCLAW_HOOK_TOKEN: hookToken,
74
77
  });
75
78
 
76
79
  // 5. Copy dashboard dist into OpenClaw container (host→container bridge)
package/cli/env-writer.ts CHANGED
@@ -14,6 +14,13 @@ export function getExistingApiKey(): string | null {
14
14
  return match?.[1]?.trim() || null;
15
15
  }
16
16
 
17
+ export function getExistingHookToken(): string | null {
18
+ if (!existsSync(OPENCLAW_ENV)) return null;
19
+ const content = readFileSync(OPENCLAW_ENV, 'utf-8');
20
+ const match = content.match(/^OPENCLAW_HOOK_TOKEN=(.+)$/m);
21
+ return match?.[1]?.trim() || null;
22
+ }
23
+
17
24
  export function mergeEnvContent(
18
25
  existingContent: string,
19
26
  variables: Record<string, string>,
@@ -31,6 +31,7 @@ services:
31
31
  - NATS_SERVERS=nats://nats:4222
32
32
  - OPENCLAW_GATEWAY_URL=http://host.docker.internal:18789
33
33
  - NATS_PLUGIN_API_KEY=${NATS_PLUGIN_API_KEY}
34
+ - OPENCLAW_HOOK_TOKEN=${OPENCLAW_HOOK_TOKEN}
34
35
  volumes:
35
36
  - sidecar-data:/app/data
36
37
  restart: unless-stopped
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixal/openclaw-nats-plugin",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "NATS JetStream event-driven plugin for OpenClaw",
5
5
  "license": "MIT",
6
6
  "type": "module",