robot-resources 1.2.1 → 1.2.3
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/lib/tool-config.js +38 -10
- package/package.json +1 -1
package/lib/tool-config.js
CHANGED
|
@@ -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';
|
|
@@ -50,7 +51,15 @@ function writeJsonSafe(filePath, data) {
|
|
|
50
51
|
/**
|
|
51
52
|
* Configure OpenClaw to route through the Router.
|
|
52
53
|
*
|
|
53
|
-
*
|
|
54
|
+
* Modifies the existing Anthropic provider's baseUrl to point at
|
|
55
|
+
* Router (localhost:3838). This way all Anthropic calls go through
|
|
56
|
+
* Router transparently — Router reads the x-api-key from the
|
|
57
|
+
* request and forwards to Anthropic.
|
|
58
|
+
*
|
|
59
|
+
* If no Anthropic provider exists, creates one with just the baseUrl.
|
|
60
|
+
* Removes any stale "robot-resources" custom provider from previous
|
|
61
|
+
* wizard versions that added it incorrectly.
|
|
62
|
+
*
|
|
54
63
|
* OpenClaw uses openclaw.json (JSON5 format) — we read with
|
|
55
64
|
* comment stripping and write back as standard JSON.
|
|
56
65
|
*/
|
|
@@ -64,23 +73,42 @@ function configureOpenClaw() {
|
|
|
64
73
|
const configPath = configPaths.find((p) => existsSync(p)) || configPaths[0];
|
|
65
74
|
let config = readJsonSafe(configPath) || {};
|
|
66
75
|
|
|
67
|
-
// Ensure models.providers path
|
|
76
|
+
// Ensure models.providers.anthropic path
|
|
68
77
|
config.models = config.models || {};
|
|
69
78
|
config.models.providers = config.models.providers || {};
|
|
79
|
+
config.models.providers.anthropic = config.models.providers.anthropic || {};
|
|
70
80
|
|
|
71
|
-
// Check if already
|
|
72
|
-
|
|
81
|
+
// Check if already proxied through Router
|
|
82
|
+
const anthropic = config.models.providers.anthropic;
|
|
83
|
+
if (anthropic.baseUrl === `${ROUTER_URL}/v1`) {
|
|
73
84
|
return { name: 'OpenClaw', action: 'already_configured' };
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
// Save original baseUrl so it can be restored if needed
|
|
88
|
+
if (anthropic.baseUrl && anthropic.baseUrl !== `${ROUTER_URL}/v1`) {
|
|
89
|
+
anthropic._originalBaseUrl = anthropic.baseUrl;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Point Anthropic provider at Router
|
|
93
|
+
anthropic.baseUrl = `${ROUTER_URL}/v1`;
|
|
94
|
+
|
|
95
|
+
// Clean up stale "robot-resources" provider from previous wizard versions
|
|
96
|
+
delete config.models.providers['robot-resources'];
|
|
82
97
|
|
|
83
98
|
writeJsonSafe(configPath, config);
|
|
99
|
+
|
|
100
|
+
// Graceful config reload via SIGUSR1 — doesn't kill the agent's session.
|
|
101
|
+
// openclaw gateway restart would terminate the active session.
|
|
102
|
+
try {
|
|
103
|
+
execSync('kill -USR1 $(pgrep -f openclaw-gateway)', {
|
|
104
|
+
stdio: 'ignore',
|
|
105
|
+
timeout: 5_000,
|
|
106
|
+
shell: true,
|
|
107
|
+
});
|
|
108
|
+
} catch {
|
|
109
|
+
// Gateway not running or pgrep not available — not fatal
|
|
110
|
+
}
|
|
111
|
+
|
|
84
112
|
return { name: 'OpenClaw', action: 'configured' };
|
|
85
113
|
}
|
|
86
114
|
|