@omnixal/openclaw-nats-plugin 0.1.8 → 0.1.10

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, writeEnvVariables } from './env-writer';
10
+ import { generateApiKey, getExistingApiKey, writeEnvVariables } from './env-writer';
11
11
  import {
12
12
  getServiceManager, generateSystemdUnit, generateLaunchdPlist,
13
13
  installSystemdUnit, installLaunchdPlist, startService, stopService,
@@ -46,8 +46,8 @@ export async function bunSetup(): Promise<void> {
46
46
  // 5. Generate NATS config
47
47
  writeNatsConfig();
48
48
 
49
- // 6. Generate API key
50
- const apiKey = generateApiKey();
49
+ // 6. Reuse existing API key or generate new one
50
+ const apiKey = getExistingApiKey() ?? generateApiKey();
51
51
 
52
52
  // 7. Write env variables (to OpenClaw .env for hooks, and sidecar .env for the service)
53
53
  const envVars: Record<string, string> = {
@@ -58,11 +58,13 @@ export async function bunSetup(): Promise<void> {
58
58
  writeEnvVariables(envVars);
59
59
 
60
60
  // Write .env into sidecar dir so loadDotEnv picks it up
61
+ // Explicit localhost values override any container-level env (e.g. OPENCLAW_WS_URL=ws://openclaw:...)
61
62
  const sidecarEnv = [
62
63
  `PORT=3104`,
63
64
  `DB_PATH=${join(DATA_DIR, 'nats-sidecar.db')}`,
64
65
  `NATS_SERVERS=nats://127.0.0.1:4222`,
65
66
  `NATS_PLUGIN_API_KEY=${apiKey}`,
67
+ `OPENCLAW_WS_URL=ws://127.0.0.1:18789`,
66
68
  ].join('\n');
67
69
  writeFileSync(join(SIDECAR_DIR, '.env'), sidecarEnv, 'utf-8');
68
70
 
package/cli/env-writer.ts CHANGED
@@ -7,6 +7,13 @@ export function generateApiKey(): string {
7
7
  return randomBytes(32).toString('hex');
8
8
  }
9
9
 
10
+ export function getExistingApiKey(): string | null {
11
+ if (!existsSync(OPENCLAW_ENV)) return null;
12
+ const content = readFileSync(OPENCLAW_ENV, 'utf-8');
13
+ const match = content.match(/^NATS_PLUGIN_API_KEY=(.+)$/m);
14
+ return match?.[1]?.trim() || null;
15
+ }
16
+
10
17
  export function mergeEnvContent(
11
18
  existingContent: string,
12
19
  variables: Record<string, string>,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixal/openclaw-nats-plugin",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "NATS JetStream event-driven plugin for OpenClaw",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -55,7 +55,7 @@ export class NatsAdapterService extends BaseService implements OnModuleInit, OnM
55
55
  }
56
56
 
57
57
  isConnected(): boolean {
58
- return this._connected && this.adapter !== null && this.adapter.isConnected();
58
+ return this._connected && this.adapter !== null;
59
59
  }
60
60
 
61
61
  async publish<T>(pattern: string, data: T, options?: PublishOptions): Promise<string | null> {