robot-resources 1.2.3 → 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.
- package/lib/tool-config.js +62 -19
- package/package.json +1 -1
package/lib/tool-config.js
CHANGED
|
@@ -51,25 +51,27 @@ function writeJsonSafe(filePath, data) {
|
|
|
51
51
|
/**
|
|
52
52
|
* Configure OpenClaw to route through the Router.
|
|
53
53
|
*
|
|
54
|
-
*
|
|
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.
|
|
54
|
+
* Writes to TWO files (both required for OpenClaw to honor the override):
|
|
58
55
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* wizard versions that added it incorrectly.
|
|
56
|
+
* 1. openclaw.json — config-level override. Needs baseUrl + models[] array
|
|
57
|
+
* or OpenClaw rejects the config as invalid.
|
|
62
58
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
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.
|
|
65
66
|
*/
|
|
66
67
|
function configureOpenClaw() {
|
|
67
68
|
const home = homedir();
|
|
69
|
+
|
|
70
|
+
// ── 1. Find and update openclaw.json ────────────────────────
|
|
68
71
|
const configPaths = [
|
|
69
72
|
join(home, '.openclaw', 'openclaw.json'),
|
|
70
73
|
join(home, 'openclaw.json'),
|
|
71
74
|
];
|
|
72
|
-
|
|
73
75
|
const configPath = configPaths.find((p) => existsSync(p)) || configPaths[0];
|
|
74
76
|
let config = readJsonSafe(configPath) || {};
|
|
75
77
|
|
|
@@ -78,13 +80,21 @@ function configureOpenClaw() {
|
|
|
78
80
|
config.models.providers = config.models.providers || {};
|
|
79
81
|
config.models.providers.anthropic = config.models.providers.anthropic || {};
|
|
80
82
|
|
|
81
|
-
// Check if already proxied through Router
|
|
82
83
|
const anthropic = config.models.providers.anthropic;
|
|
84
|
+
|
|
85
|
+
// Check if already proxied through Router
|
|
83
86
|
if (anthropic.baseUrl === `${ROUTER_URL}/v1`) {
|
|
84
|
-
|
|
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
|
|
85
95
|
}
|
|
86
96
|
|
|
87
|
-
// Save original baseUrl
|
|
97
|
+
// Save original baseUrl for rollback
|
|
88
98
|
if (anthropic.baseUrl && anthropic.baseUrl !== `${ROUTER_URL}/v1`) {
|
|
89
99
|
anthropic._originalBaseUrl = anthropic.baseUrl;
|
|
90
100
|
}
|
|
@@ -92,21 +102,54 @@ function configureOpenClaw() {
|
|
|
92
102
|
// Point Anthropic provider at Router
|
|
93
103
|
anthropic.baseUrl = `${ROUTER_URL}/v1`;
|
|
94
104
|
|
|
105
|
+
// OpenClaw requires models array on provider entries
|
|
106
|
+
if (!Array.isArray(anthropic.models)) {
|
|
107
|
+
anthropic.models = [];
|
|
108
|
+
}
|
|
109
|
+
|
|
95
110
|
// Clean up stale "robot-resources" provider from previous wizard versions
|
|
96
111
|
delete config.models.providers['robot-resources'];
|
|
97
112
|
|
|
98
113
|
writeJsonSafe(configPath, config);
|
|
99
114
|
|
|
100
|
-
//
|
|
101
|
-
|
|
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.
|
|
102
139
|
try {
|
|
103
|
-
execSync('
|
|
140
|
+
execSync('systemctl --user restart openclaw-gateway', {
|
|
104
141
|
stdio: 'ignore',
|
|
105
|
-
timeout:
|
|
106
|
-
shell: true,
|
|
142
|
+
timeout: 10_000,
|
|
107
143
|
});
|
|
108
144
|
} catch {
|
|
109
|
-
|
|
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
|
+
}
|
|
110
153
|
}
|
|
111
154
|
|
|
112
155
|
return { name: 'OpenClaw', action: 'configured' };
|