@omnixal/openclaw-nats-plugin 0.1.6 → 0.1.8

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
@@ -10,7 +10,7 @@ import { writeNatsConfig } from './nats-config';
10
10
  import { generateApiKey, writeEnvVariables } from './env-writer';
11
11
  import {
12
12
  getServiceManager, generateSystemdUnit, generateLaunchdPlist,
13
- installSystemdUnit, installLaunchdPlist, startService,
13
+ installSystemdUnit, installLaunchdPlist, startService, stopService,
14
14
  } from './service-units';
15
15
 
16
16
  const NATS_SERVICE = 'openclaw-nats';
@@ -49,12 +49,22 @@ export async function bunSetup(): Promise<void> {
49
49
  // 6. Generate API key
50
50
  const apiKey = generateApiKey();
51
51
 
52
- // 7. Write env variables
53
- writeEnvVariables({
52
+ // 7. Write env variables (to OpenClaw .env for hooks, and sidecar .env for the service)
53
+ const envVars: Record<string, string> = {
54
54
  NATS_SIDECAR_URL: 'http://127.0.0.1:3104',
55
55
  NATS_PLUGIN_API_KEY: apiKey,
56
56
  NATS_SERVERS: 'nats://127.0.0.1:4222',
57
- });
57
+ };
58
+ writeEnvVariables(envVars);
59
+
60
+ // Write .env into sidecar dir so loadDotEnv picks it up
61
+ const sidecarEnv = [
62
+ `PORT=3104`,
63
+ `DB_PATH=${join(DATA_DIR, 'nats-sidecar.db')}`,
64
+ `NATS_SERVERS=nats://127.0.0.1:4222`,
65
+ `NATS_PLUGIN_API_KEY=${apiKey}`,
66
+ ].join('\n');
67
+ writeFileSync(join(SIDECAR_DIR, '.env'), sidecarEnv, 'utf-8');
58
68
 
59
69
  // 8. Generate and install service units
60
70
  const manager = getServiceManager();
@@ -99,7 +109,10 @@ export async function bunSetup(): Promise<void> {
99
109
  console.log('No init system detected, using direct process management');
100
110
  }
101
111
 
102
- // 9. Start services
112
+ // 9. Stop old processes if running, then start
113
+ try { stopService(SIDECAR_SERVICE); } catch { /* not running */ }
114
+ try { stopService(NATS_SERVICE); } catch { /* not running */ }
115
+
103
116
  console.log('\nStarting services...');
104
117
  startService(NATS_SERVICE);
105
118
  await waitForPort(8222, 10_000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixal/openclaw-nats-plugin",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "NATS JetStream event-driven plugin for OpenClaw",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,8 +14,9 @@ export class DedupService extends BaseService implements OnModuleInit, OnModuleD
14
14
  this.ttlSeconds = this.config.get('dedup.ttlSeconds');
15
15
  const cleanupIntervalMs = this.config.get('dedup.cleanupIntervalMs');
16
16
 
17
- await this.cleanup();
18
- this.cleanupTimer = setInterval(() => this.cleanup(), cleanupIntervalMs);
17
+ this.cleanupTimer = setInterval(() => this.cleanup().catch((e) => {
18
+ this.logger.warn('Dedup cleanup failed', { error: String(e) });
19
+ }), cleanupIntervalMs);
19
20
  }
20
21
 
21
22
  async onModuleDestroy(): Promise<void> {