@openclaw-cloud/agent-controller 0.1.4 → 0.1.6
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/.husky/pre-commit +1 -0
- package/BIZPLAN.md +530 -0
- package/CLAUDE.md +64 -0
- package/__tests__/api.test.ts +123 -0
- package/__tests__/chat.test.ts +191 -0
- package/__tests__/config.test.ts +100 -0
- package/__tests__/connection.test.ts +171 -14
- package/__tests__/file-delete.test.ts +90 -0
- package/__tests__/file-write.test.ts +119 -0
- package/__tests__/gateway-adapter.test.ts +366 -0
- package/__tests__/gateway-client.test.ts +272 -0
- package/__tests__/onboarding.test.ts +55 -0
- package/__tests__/package-install.test.ts +109 -0
- package/__tests__/pair.test.ts +60 -0
- package/__tests__/self-update.test.ts +123 -0
- package/__tests__/stop.test.ts +38 -0
- package/bin/agent-controller.js +15 -2
- package/dist/commands/self-update.d.ts +1 -0
- package/dist/commands/self-update.js +41 -0
- package/dist/commands/self-update.js.map +1 -0
- package/dist/connection.d.ts +1 -1
- package/dist/connection.js +49 -29
- package/dist/connection.js.map +1 -1
- package/dist/handlers/board-handler.d.ts +1 -0
- package/dist/handlers/board-handler.js +5 -2
- package/dist/handlers/board-handler.js.map +1 -1
- package/dist/handlers/chat.d.ts +4 -0
- package/dist/handlers/chat.js +62 -0
- package/dist/handlers/chat.js.map +1 -0
- package/dist/handlers/file-delete.d.ts +2 -0
- package/dist/handlers/file-delete.js +41 -0
- package/dist/handlers/file-delete.js.map +1 -0
- package/dist/handlers/file-write.d.ts +2 -0
- package/dist/handlers/file-write.js +59 -0
- package/dist/handlers/file-write.js.map +1 -0
- package/dist/handlers/onboarding.d.ts +2 -0
- package/dist/handlers/onboarding.js +18 -0
- package/dist/handlers/onboarding.js.map +1 -0
- package/dist/handlers/package-install.d.ts +2 -0
- package/dist/handlers/package-install.js +59 -0
- package/dist/handlers/package-install.js.map +1 -0
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/dist/openclaw/gateway-adapter.d.ts +22 -0
- package/dist/openclaw/gateway-adapter.js +108 -0
- package/dist/openclaw/gateway-adapter.js.map +1 -0
- package/dist/openclaw/gateway-client.d.ts +21 -0
- package/dist/openclaw/gateway-client.js +114 -0
- package/dist/openclaw/gateway-client.js.map +1 -0
- package/dist/openclaw/index.d.ts +8 -0
- package/dist/openclaw/index.js +12 -0
- package/dist/openclaw/index.js.map +1 -0
- package/dist/openclaw/types.d.ts +36 -0
- package/dist/openclaw/types.js +2 -0
- package/dist/openclaw/types.js.map +1 -0
- package/dist/types.d.ts +2 -1
- package/package.json +4 -2
- package/src/commands/self-update.ts +43 -0
- package/src/connection.ts +31 -28
- package/src/handlers/file-delete.ts +46 -0
- package/src/handlers/file-write.ts +65 -0
- package/src/handlers/onboarding.ts +19 -0
- package/src/handlers/package-install.ts +69 -0
- package/src/index.ts +3 -5
- package/src/types.ts +2 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
|
+
import type { AgentCommand, AgentResponse } from '../types.js';
|
|
3
|
+
|
|
4
|
+
const INSTALL_TIMEOUT_MS = 300_000; // 5 minutes total
|
|
5
|
+
|
|
6
|
+
function execPackage(cmd: string, timeoutMs: number): Promise<void> {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
exec(cmd, { timeout: timeoutMs }, (error) => {
|
|
9
|
+
if (error) reject(error);
|
|
10
|
+
else resolve();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function handlePackageInstall(command: AgentCommand): Promise<AgentResponse> {
|
|
16
|
+
const packages = command.payload.packages as {
|
|
17
|
+
apt?: string[];
|
|
18
|
+
npm?: string[];
|
|
19
|
+
pip?: string[];
|
|
20
|
+
} | undefined;
|
|
21
|
+
|
|
22
|
+
const apt = packages?.apt ?? [];
|
|
23
|
+
const npm = packages?.npm ?? [];
|
|
24
|
+
const pip = packages?.pip ?? [];
|
|
25
|
+
|
|
26
|
+
if (apt.length === 0 && npm.length === 0 && pip.length === 0) {
|
|
27
|
+
return {
|
|
28
|
+
id: command.id,
|
|
29
|
+
type: 'package_install',
|
|
30
|
+
success: true,
|
|
31
|
+
data: { installed: { apt: [], npm: [], pip: [] }, errors: [] },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const installed: { apt: string[]; npm: string[]; pip: string[] } = { apt: [], npm: [], pip: [] };
|
|
36
|
+
const errors: Array<{ name: string; error: string }> = [];
|
|
37
|
+
const deadline = Date.now() + INSTALL_TIMEOUT_MS;
|
|
38
|
+
|
|
39
|
+
async function tryInstall(pkg: string, cmd: string, type: 'apt' | 'npm' | 'pip'): Promise<void> {
|
|
40
|
+
const remaining = deadline - Date.now();
|
|
41
|
+
if (remaining <= 0) {
|
|
42
|
+
errors.push({ name: pkg, error: 'Install timeout exceeded' });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await execPackage(cmd, remaining);
|
|
47
|
+
installed[type].push(pkg);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
errors.push({ name: pkg, error: err instanceof Error ? err.message : String(err) });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const pkg of apt) {
|
|
54
|
+
await tryInstall(pkg, `apt-get install -y ${pkg}`, 'apt');
|
|
55
|
+
}
|
|
56
|
+
for (const pkg of npm) {
|
|
57
|
+
await tryInstall(pkg, `npm install -g ${pkg}`, 'npm');
|
|
58
|
+
}
|
|
59
|
+
for (const pkg of pip) {
|
|
60
|
+
await tryInstall(pkg, `pip install ${pkg}`, 'pip');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
id: command.id,
|
|
65
|
+
type: 'package_install',
|
|
66
|
+
success: errors.length === 0,
|
|
67
|
+
data: { installed, errors },
|
|
68
|
+
};
|
|
69
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,16 +20,14 @@ export function main(): void {
|
|
|
20
20
|
const url = rawUrl.replace(/^http:\/\//, 'ws://').replace(/^https:\/\//, 'wss://') + '/connection/websocket';
|
|
21
21
|
const token = requireEnv('AGENT_TOKEN');
|
|
22
22
|
const agentId = requireEnv('AGENT_ID');
|
|
23
|
-
const backendUrl =
|
|
23
|
+
const backendUrl = requireEnv('BACKEND_INTERNAL_URL');
|
|
24
24
|
const centrifugoInternalUrl = process.env.CENTRIFUGO_INTERNAL_URL || '';
|
|
25
25
|
const centrifugoApiKey = process.env.CENTRIFUGO_API_KEY || '';
|
|
26
26
|
|
|
27
27
|
console.log(`Starting agent-controller for agent: ${agentId}`);
|
|
28
|
-
|
|
29
|
-
console.log(`Backend URL: ${backendUrl} (JWT mode)`);
|
|
30
|
-
}
|
|
28
|
+
console.log(`Backend URL: ${backendUrl} (JWT mode)`);
|
|
31
29
|
|
|
32
|
-
const { client } = createConnection({ url, token, agentId, backendUrl
|
|
30
|
+
const { client } = createConnection({ url, token, agentId, backendUrl });
|
|
33
31
|
|
|
34
32
|
// Chat provider via OpenClaw Gateway WS
|
|
35
33
|
const gatewayWsUrl = process.env.OPENCLAW_GATEWAY_WS || 'ws://localhost:18789';
|
package/src/types.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
export type CommandType =
|
|
8
8
|
| 'exec' | 'restart' | 'deploy' | 'config' | 'pair' | 'stop' | 'backup'
|
|
9
|
-
| 'chat_list_sessions' | 'chat_history' | 'chat_send'
|
|
9
|
+
| 'chat_list_sessions' | 'chat_history' | 'chat_send'
|
|
10
|
+
| 'package_install' | 'file_write' | 'file_delete' | 'onboarding_complete';
|
|
10
11
|
|
|
11
12
|
export interface AgentCommand {
|
|
12
13
|
id: string;
|