robot-resources 1.2.3 → 1.2.5
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 +16 -95
- package/package.json +1 -1
package/lib/tool-config.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, copyFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
-
import { execSync } from 'node:child_process';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
1
|
import { isOpenClawInstalled } from './detect.js';
|
|
6
2
|
|
|
7
|
-
const ROUTER_URL = 'http://localhost:3838';
|
|
8
|
-
|
|
9
3
|
/**
|
|
10
4
|
* Strip JSON5 features (comments + trailing commas) to produce valid JSON.
|
|
11
5
|
* Handles single-line comments (//), multi-line comments, and trailing
|
|
@@ -24,92 +18,23 @@ function stripJson5(text) {
|
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
/**
|
|
27
|
-
*
|
|
28
|
-
* Strips comments and trailing commas before parsing.
|
|
29
|
-
*/
|
|
30
|
-
function readJsonSafe(filePath) {
|
|
31
|
-
try {
|
|
32
|
-
const raw = readFileSync(filePath, 'utf-8');
|
|
33
|
-
return JSON.parse(stripJson5(raw));
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Write JSON with backup.
|
|
41
|
-
*/
|
|
42
|
-
function writeJsonSafe(filePath, data) {
|
|
43
|
-
const dir = join(filePath, '..');
|
|
44
|
-
mkdirSync(dir, { recursive: true });
|
|
45
|
-
if (existsSync(filePath)) {
|
|
46
|
-
copyFileSync(filePath, `${filePath}.bak`);
|
|
47
|
-
}
|
|
48
|
-
writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Configure OpenClaw to route through the Router.
|
|
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.
|
|
21
|
+
* Detect OpenClaw and report status.
|
|
62
22
|
*
|
|
63
|
-
* OpenClaw
|
|
64
|
-
*
|
|
23
|
+
* OpenClaw integration is pending — requires a plugin hook
|
|
24
|
+
* (openclaw/openclaw#9402) that hasn't shipped yet. Until then,
|
|
25
|
+
* we detect OpenClaw and return instructions instead of writing
|
|
26
|
+
* config that gets clobbered on gateway restart.
|
|
65
27
|
*/
|
|
66
28
|
function configureOpenClaw() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Ensure models.providers.anthropic path
|
|
77
|
-
config.models = config.models || {};
|
|
78
|
-
config.models.providers = config.models.providers || {};
|
|
79
|
-
config.models.providers.anthropic = config.models.providers.anthropic || {};
|
|
80
|
-
|
|
81
|
-
// Check if already proxied through Router
|
|
82
|
-
const anthropic = config.models.providers.anthropic;
|
|
83
|
-
if (anthropic.baseUrl === `${ROUTER_URL}/v1`) {
|
|
84
|
-
return { name: 'OpenClaw', action: 'already_configured' };
|
|
85
|
-
}
|
|
86
|
-
|
|
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'];
|
|
97
|
-
|
|
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
|
-
|
|
112
|
-
return { name: 'OpenClaw', action: 'configured' };
|
|
29
|
+
return {
|
|
30
|
+
name: 'OpenClaw',
|
|
31
|
+
action: 'instructions',
|
|
32
|
+
instructions: [
|
|
33
|
+
'OpenClaw detected — Router integration coming soon.',
|
|
34
|
+
'Track progress: https://github.com/openclaw/openclaw/issues/9402',
|
|
35
|
+
'Router works now with Claude Desktop, Cursor, and any OpenAI SDK app.',
|
|
36
|
+
],
|
|
37
|
+
};
|
|
113
38
|
}
|
|
114
39
|
|
|
115
40
|
/**
|
|
@@ -122,15 +47,11 @@ export function configureToolRouting() {
|
|
|
122
47
|
|
|
123
48
|
// OpenClaw
|
|
124
49
|
if (isOpenClawInstalled()) {
|
|
125
|
-
|
|
126
|
-
results.push(configureOpenClaw());
|
|
127
|
-
} catch (err) {
|
|
128
|
-
results.push({ name: 'OpenClaw', action: 'error', reason: err.message });
|
|
129
|
-
}
|
|
50
|
+
results.push(configureOpenClaw());
|
|
130
51
|
}
|
|
131
52
|
|
|
132
53
|
return results;
|
|
133
54
|
}
|
|
134
55
|
|
|
135
56
|
// Exported for testing
|
|
136
|
-
export { stripJson5,
|
|
57
|
+
export { stripJson5, configureOpenClaw };
|