@omnixal/openclaw-nats-plugin 0.1.4 → 0.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.
package/cli/bun-setup.ts CHANGED
@@ -11,7 +11,6 @@ import { generateApiKey, writeEnvVariables } from './env-writer';
11
11
  import {
12
12
  getServiceManager, generateSystemdUnit, generateLaunchdPlist,
13
13
  installSystemdUnit, installLaunchdPlist, startService,
14
- registerDirectCommand,
15
14
  } from './service-units';
16
15
 
17
16
  const NATS_SERVICE = 'openclaw-nats';
@@ -59,7 +58,6 @@ export async function bunSetup(): Promise<void> {
59
58
 
60
59
  // 8. Generate and install service units
61
60
  const manager = getServiceManager();
62
- const logsDir = join(PLUGIN_DIR, 'logs');
63
61
 
64
62
  if (manager === 'systemd') {
65
63
  const natsUnit = generateSystemdUnit({
@@ -99,8 +97,6 @@ export async function bunSetup(): Promise<void> {
99
97
  } else {
100
98
  // Direct mode — containers or systems without init
101
99
  console.log('No init system detected, using direct process management');
102
- registerDirectCommand(NATS_SERVICE, NATS_SERVER_BIN, ['-c', NATS_CONF], PLUGIN_DIR, join(logsDir, 'nats.log'));
103
- registerDirectCommand(SIDECAR_SERVICE, 'bun', ['run', join(SIDECAR_DIR, 'src/index.ts')], SIDECAR_DIR, join(logsDir, 'sidecar.log'));
104
100
  }
105
101
 
106
102
  // 9. Start services
@@ -11,8 +11,7 @@ export function generateNatsConfig(opts: NatsConfigOptions): string {
11
11
  return `# Auto-generated by @omnixal/openclaw-nats-plugin
12
12
  # Do not edit manually — regenerated on setup
13
13
 
14
- listen: 127.0.0.1
15
- port: ${port}
14
+ listen: "127.0.0.1:${port}"
16
15
 
17
16
  jetstream {
18
17
  store_dir: "${opts.dataDir}"
@@ -21,7 +20,7 @@ jetstream {
21
20
  }
22
21
 
23
22
  # Monitoring
24
- http: 127.0.0.1:8222
23
+ http: "127.0.0.1:8222"
25
24
  `;
26
25
  }
27
26
 
@@ -1,7 +1,8 @@
1
- import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'node:fs';
1
+ import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, openSync } from 'node:fs';
2
2
  import { execFileSync, spawn } from 'node:child_process';
3
3
  import { join } from 'node:path';
4
4
  import { homedir, platform } from 'node:os';
5
+ import { NATS_SERVER_BIN, NATS_CONF, PLUGIN_DIR, SIDECAR_DIR } from './paths';
5
6
 
6
7
  // --- Interfaces ---
7
8
 
@@ -144,19 +145,25 @@ function readPid(name: string): number | null {
144
145
  }
145
146
  }
146
147
 
147
- // Stored commands for direct-mode start
148
- const directCommands = new Map<string, { cmd: string; args: string[]; cwd: string; logFile: string }>();
148
+ const NATS_SERVICE_NAME = 'openclaw-nats';
149
+ const SIDECAR_SERVICE_NAME = 'openclaw-nats-sidecar';
149
150
 
150
- export function registerDirectCommand(name: string, cmd: string, args: string[], cwd: string, logFile: string): void {
151
- directCommands.set(name, { cmd, args, cwd, logFile });
151
+ function getDirectCommand(name: string): { cmd: string; args: string[]; cwd: string; logFile: string } {
152
+ const logsDir = join(PLUGIN_DIR, 'logs');
153
+ mkdirSync(logsDir, { recursive: true });
154
+
155
+ if (name === NATS_SERVICE_NAME) {
156
+ return { cmd: NATS_SERVER_BIN, args: ['-c', NATS_CONF], cwd: PLUGIN_DIR, logFile: join(logsDir, 'nats.log') };
157
+ }
158
+ if (name === SIDECAR_SERVICE_NAME) {
159
+ return { cmd: 'bun', args: ['run', join(SIDECAR_DIR, 'src/index.ts')], cwd: SIDECAR_DIR, logFile: join(logsDir, 'sidecar.log') };
160
+ }
161
+ throw new Error(`Unknown service "${name}"`);
152
162
  }
153
163
 
154
164
  function startDirect(name: string): void {
155
- const entry = directCommands.get(name);
156
- if (!entry) throw new Error(`No command registered for service "${name}". Call registerDirectCommand first.`);
157
-
158
- const { cmd, args, cwd, logFile } = entry;
159
- const out = require('node:fs').openSync(logFile, 'a');
165
+ const { cmd, args, cwd, logFile } = getDirectCommand(name);
166
+ const out = openSync(logFile, 'a');
160
167
  const child = spawn(cmd, args, {
161
168
  cwd,
162
169
  stdio: ['ignore', out, out],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnixal/openclaw-nats-plugin",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "NATS JetStream event-driven plugin for OpenClaw",
5
5
  "license": "MIT",
6
6
  "type": "module",