robot-resources 1.2.0 → 1.2.2

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 (2) hide show
  1. package/lib/tool-config.js +39 -5
  2. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import { readFileSync, writeFileSync, copyFileSync, existsSync, mkdirSync } from 'node:fs';
2
+ import { execSync } from 'node:child_process';
2
3
  import { join } from 'node:path';
3
4
  import { homedir } from 'node:os';
4
5
  import { isOpenClawInstalled } from './detect.js';
@@ -6,11 +7,30 @@ import { isOpenClawInstalled } from './detect.js';
6
7
  const ROUTER_URL = 'http://localhost:3838';
7
8
 
8
9
  /**
9
- * Read a JSON file safely. Returns null on failure.
10
+ * Strip JSON5 features (comments + trailing commas) to produce valid JSON.
11
+ * Handles single-line comments (//), multi-line comments, and trailing
12
+ * commas before } or ]. Preserves // inside quoted strings (e.g. URLs).
13
+ * No external dependency needed.
14
+ */
15
+ function stripJson5(text) {
16
+ // Match quoted strings (keep) or comments (remove) in one pass.
17
+ // Strings are matched first so // inside "http://..." is preserved.
18
+ const clean = text.replace(
19
+ /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\/\/.*$|\/\*[\s\S]*?\*\//gm,
20
+ (match) => (match.startsWith('"') || match.startsWith("'") ? match : ''),
21
+ );
22
+ // Remove trailing commas before } or ]
23
+ return clean.replace(/,\s*([\]}])/g, '$1');
24
+ }
25
+
26
+ /**
27
+ * Read a JSON/JSON5 file safely. Returns null on failure.
28
+ * Strips comments and trailing commas before parsing.
10
29
  */
11
30
  function readJsonSafe(filePath) {
12
31
  try {
13
- return JSON.parse(readFileSync(filePath, 'utf-8'));
32
+ const raw = readFileSync(filePath, 'utf-8');
33
+ return JSON.parse(stripJson5(raw));
14
34
  } catch {
15
35
  return null;
16
36
  }
@@ -32,11 +52,13 @@ function writeJsonSafe(filePath, data) {
32
52
  * Configure OpenClaw to route through the Router.
33
53
  *
34
54
  * Adds a custom provider entry in the OpenClaw config.
55
+ * OpenClaw uses openclaw.json (JSON5 format) — we read with
56
+ * comment stripping and write back as standard JSON.
35
57
  */
36
58
  function configureOpenClaw() {
37
59
  const home = homedir();
38
60
  const configPaths = [
39
- join(home, '.openclaw', 'config.json'),
61
+ join(home, '.openclaw', 'openclaw.json'),
40
62
  join(home, 'openclaw.json'),
41
63
  ];
42
64
 
@@ -52,13 +74,22 @@ function configureOpenClaw() {
52
74
  return { name: 'OpenClaw', action: 'already_configured' };
53
75
  }
54
76
 
55
- // Add RR as a custom provider
77
+ // Add RR as a custom provider — anthropic-messages format matches
78
+ // OpenClaw's native API format and Router's /v1/messages endpoint
56
79
  config.models.providers['robot-resources'] = {
57
80
  baseUrl: `${ROUTER_URL}/v1`,
58
- api: 'openai-completions',
81
+ api: 'anthropic-messages',
59
82
  };
60
83
 
61
84
  writeJsonSafe(configPath, config);
85
+
86
+ // Restart gateway so the new provider takes effect immediately
87
+ try {
88
+ execSync('openclaw gateway restart', { stdio: 'ignore', timeout: 10_000 });
89
+ } catch {
90
+ // OpenClaw CLI may not be in PATH or gateway not running — not fatal
91
+ }
92
+
62
93
  return { name: 'OpenClaw', action: 'configured' };
63
94
  }
64
95
 
@@ -81,3 +112,6 @@ export function configureToolRouting() {
81
112
 
82
113
  return results;
83
114
  }
115
+
116
+ // Exported for testing
117
+ export { stripJson5, readJsonSafe, configureOpenClaw };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robot-resources",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Robot Resources — AI agent runtime tools. One command to install everything.",
5
5
  "type": "module",
6
6
  "bin": {