@agentplugged/claw 0.1.1 → 0.2.0
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/dist/cli.js +3 -7
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -5
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -40
- package/dist/index.js.map +1 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +363 -77
- package/dist/router/index.js.map +1 -1
- package/dist/router/logger.d.ts +3 -0
- package/dist/router/logger.d.ts.map +1 -1
- package/dist/router/logger.js +8 -5
- package/dist/router/logger.js.map +1 -1
- package/dist/router/types.d.ts +6 -9
- package/dist/router/types.d.ts.map +1 -1
- package/dist/sidecar/auth.d.ts.map +1 -1
- package/dist/sidecar/auth.js +7 -11
- package/dist/sidecar/auth.js.map +1 -1
- package/dist/sidecar/index.js +104 -21
- package/dist/sidecar/index.js.map +1 -1
- package/dist/sidecar/routes/addons.d.ts.map +1 -1
- package/dist/sidecar/routes/addons.js +3 -13
- package/dist/sidecar/routes/addons.js.map +1 -1
- package/dist/sidecar/routes/api-keys.d.ts +4 -0
- package/dist/sidecar/routes/api-keys.d.ts.map +1 -0
- package/dist/sidecar/routes/api-keys.js +221 -0
- package/dist/sidecar/routes/api-keys.js.map +1 -0
- package/dist/sidecar/routes/bindings.d.ts +5 -0
- package/dist/sidecar/routes/bindings.d.ts.map +1 -0
- package/dist/sidecar/routes/bindings.js +64 -0
- package/dist/sidecar/routes/bindings.js.map +1 -0
- package/dist/sidecar/routes/channels.d.ts.map +1 -1
- package/dist/sidecar/routes/channels.js +71 -75
- package/dist/sidecar/routes/channels.js.map +1 -1
- package/dist/sidecar/routes/crons.d.ts +5 -0
- package/dist/sidecar/routes/crons.d.ts.map +1 -0
- package/dist/sidecar/routes/crons.js +81 -0
- package/dist/sidecar/routes/crons.js.map +1 -0
- package/dist/sidecar/routes/health.d.ts.map +1 -1
- package/dist/sidecar/routes/health.js +1 -5
- package/dist/sidecar/routes/health.js.map +1 -1
- package/dist/sidecar/routes/kitchen-proxy.d.ts +5 -0
- package/dist/sidecar/routes/kitchen-proxy.d.ts.map +1 -0
- package/dist/sidecar/routes/kitchen-proxy.js +29 -0
- package/dist/sidecar/routes/kitchen-proxy.js.map +1 -0
- package/dist/sidecar/routes/memory.d.ts +0 -2
- package/dist/sidecar/routes/memory.d.ts.map +1 -1
- package/dist/sidecar/routes/memory.js +116 -113
- package/dist/sidecar/routes/memory.js.map +1 -1
- package/dist/sidecar/routes/metrics.js +5 -5
- package/dist/sidecar/routes/restart.d.ts.map +1 -1
- package/dist/sidecar/routes/restart.js +11 -2
- package/dist/sidecar/routes/restart.js.map +1 -1
- package/dist/sidecar/routes/router-config.d.ts +0 -1
- package/dist/sidecar/routes/router-config.d.ts.map +1 -1
- package/dist/sidecar/routes/router-config.js +2 -139
- package/dist/sidecar/routes/router-config.js.map +1 -1
- package/dist/sidecar/routes/soul.d.ts +11 -0
- package/dist/sidecar/routes/soul.d.ts.map +1 -1
- package/dist/sidecar/routes/soul.js +58 -33
- package/dist/sidecar/routes/soul.js.map +1 -1
- package/dist/sidecar/routes/system.d.ts +7 -0
- package/dist/sidecar/routes/system.d.ts.map +1 -0
- package/dist/sidecar/routes/system.js +49 -0
- package/dist/sidecar/routes/system.js.map +1 -0
- package/dist/sidecar/routes/team.d.ts.map +1 -1
- package/dist/sidecar/routes/team.js +121 -74
- package/dist/sidecar/routes/team.js.map +1 -1
- package/dist/sidecar/routes/update.d.ts.map +1 -1
- package/dist/sidecar/routes/update.js +24 -10
- package/dist/sidecar/routes/update.js.map +1 -1
- package/dist/sidecar/routes/workflow.d.ts +8 -0
- package/dist/sidecar/routes/workflow.d.ts.map +1 -0
- package/dist/sidecar/routes/workflow.js +232 -0
- package/dist/sidecar/routes/workflow.js.map +1 -0
- package/dist/sidecar/utils.d.ts +14 -0
- package/dist/sidecar/utils.d.ts.map +1 -1
- package/dist/sidecar/utils.js +35 -1
- package/dist/sidecar/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -32,142 +32,143 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.handleListMemory = handleListMemory;
|
|
40
|
-
exports.handleCreateMemory = handleCreateMemory;
|
|
41
|
-
exports.handleDeleteMemory = handleDeleteMemory;
|
|
42
37
|
exports.handleListSessions = handleListSessions;
|
|
43
|
-
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
44
38
|
const fs = __importStar(require("fs"));
|
|
45
39
|
const url = __importStar(require("url"));
|
|
46
40
|
const utils_1 = require("../utils");
|
|
41
|
+
/**
|
|
42
|
+
* Counts rows in a SQLite table without loading all data.
|
|
43
|
+
* Returns 0 if the DB or table doesn't exist.
|
|
44
|
+
*/
|
|
45
|
+
function countRows(dbPath, table) {
|
|
46
|
+
if (!fs.existsSync(dbPath))
|
|
47
|
+
return 0;
|
|
48
|
+
let db = null;
|
|
49
|
+
try {
|
|
50
|
+
const Database = require("better-sqlite3");
|
|
51
|
+
db = new Database(dbPath, { readonly: true });
|
|
52
|
+
// Check table exists
|
|
53
|
+
const row = db
|
|
54
|
+
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?")
|
|
55
|
+
.get(table);
|
|
56
|
+
if (!row)
|
|
57
|
+
return 0;
|
|
58
|
+
const countRow = db.prepare(`SELECT COUNT(*) as cnt FROM "${table}"`).get();
|
|
59
|
+
return countRow?.cnt ?? 0;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
if (db)
|
|
66
|
+
db.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// GET /memory — return memory stats from all sources (read-only)
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
47
72
|
function handleListMemory(config) {
|
|
48
73
|
return async (req, res) => {
|
|
49
|
-
const memoryDb = `${config.runtimeDir}/data/memory.db`;
|
|
50
|
-
if (!fs.existsSync(memoryDb)) {
|
|
51
|
-
(0, utils_1.sendJson)(res, 200, { memories: [], total: 0, page: 1, pageSize: 20 });
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Parse pagination from query string
|
|
55
74
|
const parsedUrl = url.parse(req.url ?? "", true);
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
page,
|
|
83
|
-
pageSize,
|
|
84
|
-
totalPages: Math.ceil(total / pageSize),
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
db?.close();
|
|
89
|
-
(0, utils_1.sendError)(res, 500, `Failed to query memory: ${err.message}`);
|
|
75
|
+
const mode = parsedUrl.query["mode"] ?? "stats";
|
|
76
|
+
const workspaceDir = `${config.runtimeDir}/workspace`;
|
|
77
|
+
const vectorStoreDbPath = `${workspaceDir}/vector_store.db`;
|
|
78
|
+
const legacyMemoryDbPath = `${config.dataDir}/memory.db`;
|
|
79
|
+
const openclawMemoryDb = `${config.dataDir}/.openclaw/memory/main.sqlite`;
|
|
80
|
+
const sources = [
|
|
81
|
+
{
|
|
82
|
+
source: "mem0",
|
|
83
|
+
count: countRows(vectorStoreDbPath, "vectors"),
|
|
84
|
+
available: fs.existsSync(vectorStoreDbPath),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
source: "legacy",
|
|
88
|
+
count: countRows(legacyMemoryDbPath, "memories"),
|
|
89
|
+
available: fs.existsSync(legacyMemoryDbPath),
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
source: "openclaw",
|
|
93
|
+
count: countRows(openclawMemoryDb, "chunks"),
|
|
94
|
+
available: fs.existsSync(openclawMemoryDb),
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
const total = sources.reduce((sum, s) => sum + s.count, 0);
|
|
98
|
+
if (mode === "stats") {
|
|
99
|
+
(0, utils_1.sendJson)(res, 200, { total, sources });
|
|
100
|
+
return;
|
|
90
101
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
// For mode=full, read actual memories from mem0 (primary source)
|
|
103
|
+
// This is for the dashboard memory viewer — read-only
|
|
104
|
+
if (mode === "full" && fs.existsSync(vectorStoreDbPath)) {
|
|
105
|
+
const page = Math.max(1, parseInt(parsedUrl.query["page"] ?? "1", 10));
|
|
106
|
+
const pageSize = Math.min(100, Math.max(1, parseInt(parsedUrl.query["pageSize"] ?? "20", 10)));
|
|
107
|
+
const offset = (page - 1) * pageSize;
|
|
108
|
+
let db = null;
|
|
109
|
+
try {
|
|
110
|
+
const Database = require("better-sqlite3");
|
|
111
|
+
db = new Database(vectorStoreDbPath, { readonly: true });
|
|
112
|
+
const rows = db
|
|
113
|
+
.prepare("SELECT id, payload FROM vectors LIMIT ? OFFSET ?")
|
|
114
|
+
.all(pageSize, offset);
|
|
115
|
+
const memories = rows.map((r) => {
|
|
116
|
+
try {
|
|
117
|
+
const payload = JSON.parse(r.payload);
|
|
118
|
+
return {
|
|
119
|
+
id: `mem0:${r.id}`,
|
|
120
|
+
content: payload.data ?? "",
|
|
121
|
+
type: "fact",
|
|
122
|
+
source: `mem0/${payload.runId ?? payload.userId ?? "default"}`,
|
|
123
|
+
createdAt: payload.createdAt ?? null,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return {
|
|
128
|
+
id: `mem0:${r.id}`,
|
|
129
|
+
content: r.payload,
|
|
130
|
+
type: "fact",
|
|
131
|
+
source: "mem0/unknown",
|
|
132
|
+
createdAt: null,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
(0, utils_1.sendJson)(res, 200, {
|
|
137
|
+
memories,
|
|
138
|
+
total,
|
|
139
|
+
page,
|
|
140
|
+
pageSize,
|
|
141
|
+
totalPages: Math.ceil(total / pageSize),
|
|
142
|
+
sources,
|
|
143
|
+
});
|
|
105
144
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const confidence = body.confidence ?? 1.0;
|
|
109
|
-
const content = body.content.trim();
|
|
110
|
-
db = new better_sqlite3_1.default(memoryDbPath);
|
|
111
|
-
const result = db
|
|
112
|
-
.prepare("INSERT INTO memories (type, content, source, confidence) VALUES (?, ?, ?, ?)")
|
|
113
|
-
.run(type, content, source, confidence);
|
|
114
|
-
const inserted = db
|
|
115
|
-
.prepare("SELECT id, type, content, source, confidence, created_at FROM memories WHERE id = ?")
|
|
116
|
-
.get(result.lastInsertRowid);
|
|
117
|
-
(0, utils_1.sendJson)(res, 201, {
|
|
118
|
-
ok: true,
|
|
119
|
-
id: result.lastInsertRowid,
|
|
120
|
-
memory: inserted,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
(0, utils_1.sendError)(res, 500, `Failed to create memory: ${err.message}`);
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
db?.close();
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function handleDeleteMemory(config) {
|
|
132
|
-
return async (req, res) => {
|
|
133
|
-
const memoryDbPath = `${config.runtimeDir}/data/memory.db`;
|
|
134
|
-
let db = null;
|
|
135
|
-
try {
|
|
136
|
-
const match = req.url?.match(/\/memory\/(\d+)/);
|
|
137
|
-
if (!match) {
|
|
138
|
-
(0, utils_1.sendError)(res, 400, "Invalid URL — expected /memory/:id");
|
|
139
|
-
return;
|
|
145
|
+
catch (err) {
|
|
146
|
+
(0, utils_1.sendError)(res, 500, `Failed to read memories: ${err.message}`);
|
|
140
147
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
.prepare("DELETE FROM memories WHERE id = ?")
|
|
145
|
-
.run(parsedId);
|
|
146
|
-
if (result.changes === 0) {
|
|
147
|
-
(0, utils_1.sendError)(res, 404, "Memory not found");
|
|
148
|
-
return;
|
|
148
|
+
finally {
|
|
149
|
+
if (db)
|
|
150
|
+
db.close();
|
|
149
151
|
}
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
(0, utils_1.sendError)(res, 500, `Failed to delete memory: ${err.message}`);
|
|
154
|
-
}
|
|
155
|
-
finally {
|
|
156
|
-
db?.close();
|
|
152
|
+
return;
|
|
157
153
|
}
|
|
154
|
+
// Default: just stats
|
|
155
|
+
(0, utils_1.sendJson)(res, 200, { total, sources });
|
|
158
156
|
};
|
|
159
157
|
}
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
// GET /sessions — list recent sessions from router.db (unchanged)
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
160
161
|
function handleListSessions(config) {
|
|
161
162
|
return async (_req, res) => {
|
|
162
|
-
const routerDb = `${config.
|
|
163
|
+
const routerDb = `${config.dataDir}/router.db`;
|
|
163
164
|
if (!fs.existsSync(routerDb)) {
|
|
164
165
|
(0, utils_1.sendJson)(res, 200, { sessions: [], total: 0 });
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
167
168
|
let db = null;
|
|
168
169
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
const Database = require("better-sqlite3");
|
|
171
|
+
db = new Database(routerDb, { readonly: true });
|
|
171
172
|
let sessions = [];
|
|
172
173
|
try {
|
|
173
174
|
sessions = db
|
|
@@ -210,6 +211,7 @@ function handleListSessions(config) {
|
|
|
210
211
|
return;
|
|
211
212
|
}
|
|
212
213
|
db.close();
|
|
214
|
+
db = null;
|
|
213
215
|
(0, utils_1.sendJson)(res, 200, {
|
|
214
216
|
sessions: sessions.map((s) => ({
|
|
215
217
|
sessionId: s.session_id,
|
|
@@ -226,7 +228,8 @@ function handleListSessions(config) {
|
|
|
226
228
|
});
|
|
227
229
|
}
|
|
228
230
|
catch (err) {
|
|
229
|
-
db
|
|
231
|
+
if (db)
|
|
232
|
+
db.close();
|
|
230
233
|
(0, utils_1.sendError)(res, 500, `Failed to query sessions: ${err.message}`);
|
|
231
234
|
}
|
|
232
235
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/sidecar/routes/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/sidecar/routes/memory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,4CAwGC;AAMD,gDA+GC;AAjRD,uCAAyB;AACzB,yCAA2B;AAE3B,oCAA+C;AAe/C;;;GAGG;AACH,SAAS,SAAS,CAAC,MAAc,EAAE,KAAa;IAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,CAAC,CAAC;IAErC,IAAI,EAAE,GAAG,IAAI,CAAC;IACd,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAA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AAC;gBACH,KAAK,EAAE,QAAQ,CAAC,MAAM;aACvB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,EAAE;gBAAE,EAAE,CAAC,KAAK,EAAE,CAAC;YACnB,IAAA,iBAAS,EACP,GAAG,EACH,GAAG,EACH,6BAA8B,GAAa,CAAC,OAAO,EAAE,CACtD,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -57,10 +57,10 @@ function queryRouterStats(db) {
|
|
|
57
57
|
const today = db
|
|
58
58
|
.prepare(`SELECT
|
|
59
59
|
COUNT(*) as total_requests,
|
|
60
|
-
SUM(
|
|
61
|
-
SUM(
|
|
60
|
+
SUM(input_tokens) as total_input_tokens,
|
|
61
|
+
SUM(output_tokens) as total_output_tokens,
|
|
62
62
|
SUM(cost) as total_cost,
|
|
63
|
-
AVG(
|
|
63
|
+
AVG(latency_ms) as avg_latency,
|
|
64
64
|
SUM(CASE WHEN success = 0 THEN 1 ELSE 0 END) as error_count
|
|
65
65
|
FROM router_logs
|
|
66
66
|
WHERE timestamp >= datetime('now', '-1 day')`)
|
|
@@ -84,7 +84,7 @@ function queryRouterStats(db) {
|
|
|
84
84
|
model,
|
|
85
85
|
COUNT(*) as count,
|
|
86
86
|
SUM(cost) as total_cost,
|
|
87
|
-
SUM(
|
|
87
|
+
SUM(input_tokens + output_tokens) as total_tokens
|
|
88
88
|
FROM router_logs
|
|
89
89
|
WHERE timestamp >= datetime('now', '-30 days')
|
|
90
90
|
GROUP BY model
|
|
@@ -232,7 +232,7 @@ function handleLiveMetrics(routerDbPath) {
|
|
|
232
232
|
const live = db
|
|
233
233
|
.prepare(`SELECT
|
|
234
234
|
COUNT(*) as messages_today,
|
|
235
|
-
SUM(
|
|
235
|
+
SUM(input_tokens + output_tokens) as tokens_today,
|
|
236
236
|
SUM(cost) as cost_today
|
|
237
237
|
FROM router_logs
|
|
238
238
|
WHERE timestamp >= datetime('now', 'start of day')`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restart.d.ts","sourceRoot":"","sources":["../../../src/sidecar/routes/restart.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"restart.d.ts","sourceRoot":"","sources":["../../../src/sidecar/routes/restart.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWxC,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY,CAiD/D"}
|
|
@@ -35,6 +35,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.handleRestart = handleRestart;
|
|
37
37
|
const utils_1 = require("../utils");
|
|
38
|
+
/** Strict whitelist of service names that can be restarted */
|
|
39
|
+
const ALLOWED_SERVICES = new Set([
|
|
40
|
+
"openclaw", "ironclaw", "claw-router", "claw-sidecar", "caddy",
|
|
41
|
+
]);
|
|
38
42
|
function handleRestart(_config) {
|
|
39
43
|
return async (req, res) => {
|
|
40
44
|
let body = {};
|
|
@@ -48,8 +52,13 @@ function handleRestart(_config) {
|
|
|
48
52
|
const service = body.service ?? "openclaw";
|
|
49
53
|
const results = {};
|
|
50
54
|
const restart = async (svc) => {
|
|
55
|
+
// SECURITY: validate service name against whitelist before exec
|
|
56
|
+
if (!ALLOWED_SERVICES.has(svc)) {
|
|
57
|
+
results[svc] = "rejected: invalid service name";
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
51
60
|
try {
|
|
52
|
-
const { stdout, stderr } = await (0, utils_1.
|
|
61
|
+
const { stdout, stderr } = await (0, utils_1.execSafeCommand)("sudo", ["systemctl", "restart", svc]);
|
|
53
62
|
results[svc] = stdout || stderr || "restarted";
|
|
54
63
|
}
|
|
55
64
|
catch (err) {
|
|
@@ -65,7 +74,7 @@ function handleRestart(_config) {
|
|
|
65
74
|
await restart("claw-router");
|
|
66
75
|
}
|
|
67
76
|
else {
|
|
68
|
-
await restart(
|
|
77
|
+
await restart(service);
|
|
69
78
|
}
|
|
70
79
|
(0, utils_1.sendJson)(res, 200, {
|
|
71
80
|
restarted: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restart.js","sourceRoot":"","sources":["../../../src/sidecar/routes/restart.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"restart.js","sourceRoot":"","sources":["../../../src/sidecar/routes/restart.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,sCAiDC;AA7DD,oCAAgE;AAOhE,8DAA8D;AAC9D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO;CAC/D,CAAC,CAAC;AAEH,SAAgB,aAAa,CAAC,OAAmB;IAC/C,OAAO,KAAK,EAAE,GAAoB,EAAE,GAAmB,EAAiB,EAAE;QACxE,IAAI,IAAI,GAAgB,EAAE,CAAC;QAE3B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,kDAAO,UAAU,IAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACtE,IAAI,GAAI,MAAsB,IAAI,EAAE,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,+BAA+B;QACjC,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,UAAU,CAAC;QAC3C,MAAM,OAAO,GAA2B,EAAE,CAAC;QAE3C,MAAM,OAAO,GAAG,KAAK,EAAE,GAAW,EAAiB,EAA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Handler } from "./health";
|
|
3
3
|
export declare function handleGetRouterConfig(config: ClawConfig): RouteHandler;
|
|
4
|
-
export declare function handleUpdateStrategy(config: ClawConfig): RouteHandler;
|
|
5
4
|
//# sourceMappingURL=router-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-config.d.ts","sourceRoot":"","sources":["../../../src/sidecar/routes/router-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router-config.d.ts","sourceRoot":"","sources":["../../../src/sidecar/routes/router-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAOtE"}
|
|
@@ -1,149 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.handleGetRouterConfig = handleGetRouterConfig;
|
|
37
|
-
exports.handleUpdateStrategy = handleUpdateStrategy;
|
|
38
|
-
const fs = __importStar(require("fs/promises"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
4
|
const utils_1 = require("../utils");
|
|
41
|
-
const VALID_STRATEGIES = ["economy", "balanced", "quality"];
|
|
42
|
-
/**
|
|
43
|
-
* Signal the router to reload by writing a .reload sentinel file.
|
|
44
|
-
* The router watches this file and reloads configuration on change.
|
|
45
|
-
*/
|
|
46
|
-
async function signalRouterReload(runtimeDir) {
|
|
47
|
-
const reloadFile = path.join(runtimeDir, "data", ".reload");
|
|
48
|
-
try {
|
|
49
|
-
await fs.mkdir(path.dirname(reloadFile), { recursive: true });
|
|
50
|
-
await fs.writeFile(reloadFile, new Date().toISOString(), "utf-8");
|
|
51
|
-
return "reload signal sent";
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// Fall back to restarting the router service
|
|
55
|
-
try {
|
|
56
|
-
const { stdout, stderr } = await (0, utils_1.execCommand)("systemctl reload-or-restart claw-router");
|
|
57
|
-
return stdout || stderr || "router restarted";
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
return `reload failed: ${err.message}`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
5
|
function handleGetRouterConfig(config) {
|
|
65
6
|
return async (_req, res) => {
|
|
66
|
-
// Read the config file to get the persisted strategy, if any
|
|
67
|
-
let fileStrategy;
|
|
68
|
-
try {
|
|
69
|
-
const raw = await fs.readFile(config.configFile, "utf-8");
|
|
70
|
-
const cleaned = raw
|
|
71
|
-
.replace(/\/\/[^\n]*/g, "")
|
|
72
|
-
.replace(/,\s*([\]}])/g, "$1");
|
|
73
|
-
const parsed = JSON.parse(cleaned);
|
|
74
|
-
if (typeof parsed["strategy"] === "string") {
|
|
75
|
-
fileStrategy = parsed["strategy"];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
// Config file missing or unreadable — fall back to runtime config
|
|
80
|
-
}
|
|
81
|
-
const strategy = fileStrategy ?? config.strategy;
|
|
82
|
-
const providers = config.providers.map((p) => ({
|
|
83
|
-
name: p.name,
|
|
84
|
-
enabled: p.enabled,
|
|
85
|
-
models: p.models.map((m) => m.id),
|
|
86
|
-
}));
|
|
87
|
-
(0, utils_1.sendJson)(res, 200, {
|
|
88
|
-
strategy,
|
|
89
|
-
providers,
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function handleUpdateStrategy(config) {
|
|
94
|
-
return async (req, res) => {
|
|
95
|
-
let body;
|
|
96
|
-
try {
|
|
97
|
-
body = (await (0, utils_1.parseBody)(req));
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
(0, utils_1.sendError)(res, 400, "Invalid JSON body");
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (!body.strategy) {
|
|
104
|
-
(0, utils_1.sendError)(res, 422, "'strategy' field is required");
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (!VALID_STRATEGIES.includes(body.strategy)) {
|
|
108
|
-
(0, utils_1.sendError)(res, 422, `Invalid strategy '${body.strategy}'. Valid values: ${VALID_STRATEGIES.join(", ")}`);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
// Read existing config
|
|
112
|
-
let existingConfig = {};
|
|
113
|
-
try {
|
|
114
|
-
const raw = await fs.readFile(config.configFile, "utf-8");
|
|
115
|
-
// Basic JSON5 parsing — strip single-line comments and trailing commas
|
|
116
|
-
const cleaned = raw
|
|
117
|
-
.replace(/\/\/[^\n]*/g, "")
|
|
118
|
-
.replace(/,\s*([\]}])/g, "$1");
|
|
119
|
-
existingConfig = JSON.parse(cleaned);
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
const error = err;
|
|
123
|
-
if (error.code !== "ENOENT") {
|
|
124
|
-
(0, utils_1.sendError)(res, 500, `Failed to read config file: ${error.message}`);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// Update strategy
|
|
129
|
-
existingConfig["strategy"] = body.strategy;
|
|
130
|
-
// Write back
|
|
131
|
-
try {
|
|
132
|
-
await fs.mkdir(path.dirname(config.configFile), { recursive: true });
|
|
133
|
-
await fs.writeFile(config.configFile, JSON.stringify(existingConfig, null, 2), "utf-8");
|
|
134
|
-
}
|
|
135
|
-
catch (err) {
|
|
136
|
-
(0, utils_1.sendError)(res, 500, `Failed to write config: ${err.message}`);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
// Signal router to reload
|
|
140
|
-
const reloadResult = await signalRouterReload(config.runtimeDir);
|
|
141
7
|
(0, utils_1.sendJson)(res, 200, {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
previousStrategy: config.strategy,
|
|
145
|
-
configFile: config.configFile,
|
|
146
|
-
reload: reloadResult,
|
|
8
|
+
mode: "passthrough",
|
|
9
|
+
routerPort: config.routerPort,
|
|
147
10
|
});
|
|
148
11
|
};
|
|
149
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-config.js","sourceRoot":"","sources":["../../../src/sidecar/routes/router-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router-config.js","sourceRoot":"","sources":["../../../src/sidecar/routes/router-config.ts"],"names":[],"mappings":";;AAKA,sDAOC;AAVD,oCAAoC;AAGpC,SAAgB,qBAAqB,CAAC,MAAkB;IACtD,OAAO,KAAK,EAAE,IAAqB,EAAE,GAAmB,EAAiB,EAAE;QACzE,IAAA,gBAAQ,EAAC,GAAG,EAAE,GAAG,EAAE;YACjB,IAAI,EAAE,aAAa;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { ClawConfig } from "../../config";
|
|
2
2
|
import { RouteHandler } from "./health";
|
|
3
|
+
/**
|
|
4
|
+
* GET /soul — Read the current persona from persona.md
|
|
5
|
+
*/
|
|
6
|
+
export declare function handleGetSoul(config: ClawConfig): RouteHandler;
|
|
7
|
+
/**
|
|
8
|
+
* PUT /soul — Update the persona
|
|
9
|
+
*
|
|
10
|
+
* Accepts two formats:
|
|
11
|
+
* 1. Free text: { persona: "raw markdown text" }
|
|
12
|
+
* 2. Structured: { name, personality, language, rules, template }
|
|
13
|
+
*/
|
|
3
14
|
export declare function handleUpdateSoul(config: ClawConfig): RouteHandler;
|
|
4
15
|
//# sourceMappingURL=soul.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soul.d.ts","sourceRoot":"","sources":["../../../src/sidecar/routes/soul.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"soul.d.ts","sourceRoot":"","sources":["../../../src/sidecar/routes/soul.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAyB9D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAqFjE"}
|