robot-resources 1.2.2 → 1.2.4

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 +79 -17
  2. package/package.json +1 -1
@@ -51,43 +51,105 @@ function writeJsonSafe(filePath, data) {
51
51
  /**
52
52
  * Configure OpenClaw to route through the Router.
53
53
  *
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.
54
+ * Writes to TWO files (both required for OpenClaw to honor the override):
55
+ *
56
+ * 1. openclaw.json config-level override. Needs baseUrl + models[] array
57
+ * or OpenClaw rejects the config as invalid.
58
+ *
59
+ * 2. models.json (~/.openclaw/agents/main/agent/models.json) — runtime file
60
+ * that OpenClaw actually reads. The baseUrl here is what gets used for
61
+ * API calls. openclaw.json alone is not enough.
62
+ *
63
+ * Restarts the gateway via systemctl (SIGUSR1 doesn't reload config).
64
+ * The restart kills the current agent session, but it reconnects
65
+ * automatically within seconds.
57
66
  */
58
67
  function configureOpenClaw() {
59
68
  const home = homedir();
69
+
70
+ // ── 1. Find and update openclaw.json ────────────────────────
60
71
  const configPaths = [
61
72
  join(home, '.openclaw', 'openclaw.json'),
62
73
  join(home, 'openclaw.json'),
63
74
  ];
64
-
65
75
  const configPath = configPaths.find((p) => existsSync(p)) || configPaths[0];
66
76
  let config = readJsonSafe(configPath) || {};
67
77
 
68
- // Ensure models.providers path
78
+ // Ensure models.providers.anthropic path
69
79
  config.models = config.models || {};
70
80
  config.models.providers = config.models.providers || {};
81
+ config.models.providers.anthropic = config.models.providers.anthropic || {};
82
+
83
+ const anthropic = config.models.providers.anthropic;
84
+
85
+ // Check if already proxied through Router
86
+ if (anthropic.baseUrl === `${ROUTER_URL}/v1`) {
87
+ // Also verify models.json is in sync
88
+ const modelsJsonPath = join(home, '.openclaw', 'agents', 'main', 'agent', 'models.json');
89
+ const modelsJson = readJsonSafe(modelsJsonPath);
90
+ const runtimeUrl = modelsJson?.providers?.anthropic?.baseUrl;
91
+ if (runtimeUrl === `${ROUTER_URL}/v1`) {
92
+ return { name: 'OpenClaw', action: 'already_configured' };
93
+ }
94
+ // openclaw.json is set but models.json is not — fall through to fix it
95
+ }
96
+
97
+ // Save original baseUrl for rollback
98
+ if (anthropic.baseUrl && anthropic.baseUrl !== `${ROUTER_URL}/v1`) {
99
+ anthropic._originalBaseUrl = anthropic.baseUrl;
100
+ }
101
+
102
+ // Point Anthropic provider at Router
103
+ anthropic.baseUrl = `${ROUTER_URL}/v1`;
71
104
 
72
- // Check if already configured
73
- if (config.models.providers['robot-resources']) {
74
- return { name: 'OpenClaw', action: 'already_configured' };
105
+ // OpenClaw requires models array on provider entries
106
+ if (!Array.isArray(anthropic.models)) {
107
+ anthropic.models = [];
75
108
  }
76
109
 
77
- // Add RR as a custom provider anthropic-messages format matches
78
- // OpenClaw's native API format and Router's /v1/messages endpoint
79
- config.models.providers['robot-resources'] = {
80
- baseUrl: `${ROUTER_URL}/v1`,
81
- api: 'anthropic-messages',
82
- };
110
+ // Clean up stale "robot-resources" provider from previous wizard versions
111
+ delete config.models.providers['robot-resources'];
83
112
 
84
113
  writeJsonSafe(configPath, config);
85
114
 
86
- // Restart gateway so the new provider takes effect immediately
115
+ // ── 2. Update models.json (runtime file) ────────────────────
116
+ const modelsJsonPath = join(home, '.openclaw', 'agents', 'main', 'agent', 'models.json');
117
+ let modelsJson = readJsonSafe(modelsJsonPath) || {};
118
+
119
+ modelsJson.providers = modelsJson.providers || {};
120
+ modelsJson.providers.anthropic = modelsJson.providers.anthropic || {};
121
+
122
+ // Save original for rollback
123
+ const runtimeUrl = modelsJson.providers.anthropic.baseUrl;
124
+ if (runtimeUrl && runtimeUrl !== `${ROUTER_URL}/v1`) {
125
+ modelsJson.providers.anthropic._originalBaseUrl = runtimeUrl;
126
+ }
127
+
128
+ modelsJson.providers.anthropic.baseUrl = `${ROUTER_URL}/v1`;
129
+
130
+ // Clean up stale robot-resources provider
131
+ delete modelsJson.providers['robot-resources'];
132
+
133
+ writeJsonSafe(modelsJsonPath, modelsJson);
134
+
135
+ // ── 3. Restart gateway ──────────────────────────────────────
136
+ // SIGUSR1 doesn't reload config on OpenClaw. Full restart needed.
137
+ // systemctl --user restart is preferred (auto-reconnects).
138
+ // Falls back to openclaw gateway restart, then kill+start.
87
139
  try {
88
- execSync('openclaw gateway restart', { stdio: 'ignore', timeout: 10_000 });
140
+ execSync('systemctl --user restart openclaw-gateway', {
141
+ stdio: 'ignore',
142
+ timeout: 10_000,
143
+ });
89
144
  } catch {
90
- // OpenClaw CLI may not be in PATH or gateway not running — not fatal
145
+ try {
146
+ execSync('openclaw gateway restart', {
147
+ stdio: 'ignore',
148
+ timeout: 10_000,
149
+ });
150
+ } catch {
151
+ // Gateway not running or not installed as service — not fatal
152
+ }
91
153
  }
92
154
 
93
155
  return { name: 'OpenClaw', action: 'configured' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robot-resources",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Robot Resources — AI agent runtime tools. One command to install everything.",
5
5
  "type": "module",
6
6
  "bin": {