@fenwave/agent 1.1.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/.claude/settings.local.json +11 -0
- package/Dockerfile +12 -0
- package/LICENSE +29 -0
- package/README.md +434 -0
- package/auth.js +276 -0
- package/cli-commands.js +1185 -0
- package/containerManager.js +385 -0
- package/convert-to-esm.sh +62 -0
- package/docker-actions/apps.js +3256 -0
- package/docker-actions/config-transformer.js +380 -0
- package/docker-actions/containers.js +346 -0
- package/docker-actions/general.js +171 -0
- package/docker-actions/images.js +1128 -0
- package/docker-actions/logs.js +188 -0
- package/docker-actions/metrics.js +270 -0
- package/docker-actions/registry.js +1100 -0
- package/docker-actions/terminal.js +247 -0
- package/docker-actions/volumes.js +696 -0
- package/helper-functions.js +193 -0
- package/index.html +60 -0
- package/index.js +988 -0
- package/package.json +49 -0
- package/setup/setupWizard.js +499 -0
- package/store/agentSessionStore.js +51 -0
- package/store/agentStore.js +113 -0
- package/store/configStore.js +174 -0
- package/store/deviceCredentialStore.js +107 -0
- package/store/npmTokenStore.js +65 -0
- package/store/registryStore.js +329 -0
- package/store/setupState.js +147 -0
- package/utils/deviceInfo.js +98 -0
- package/utils/ecrAuth.js +225 -0
- package/utils/encryption.js +112 -0
- package/utils/envSetup.js +54 -0
- package/utils/errorHandler.js +327 -0
- package/utils/prerequisites.js +323 -0
- package/utils/prompts.js +318 -0
- package/websocket-server.js +364 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import { formatUptime } from '../helper-functions.js';
|
|
3
|
+
import { docker } from './containers.js';
|
|
4
|
+
import agentStore from '../store/agentStore.js';
|
|
5
|
+
import { loadSession } from '../auth.js';
|
|
6
|
+
import agentSessionStore from '../store/agentSessionStore.js';
|
|
7
|
+
|
|
8
|
+
// Version from package.json
|
|
9
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
10
|
+
const { version } = packageJson;
|
|
11
|
+
|
|
12
|
+
// Agent informations - startTime will be loaded from store or set when server starts
|
|
13
|
+
let agentStartTime = new Date();
|
|
14
|
+
const agentInfo = {
|
|
15
|
+
version,
|
|
16
|
+
hostname: os.hostname(),
|
|
17
|
+
startTime: agentStartTime,
|
|
18
|
+
cpus: os.cpus().length,
|
|
19
|
+
memory: {
|
|
20
|
+
total: Math.round(os.totalmem() / (1024 * 1024)), // MB
|
|
21
|
+
free: Math.round(os.freemem() / (1024 * 1024)), // MB
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initialize agent start time - called when server actually starts
|
|
27
|
+
* Always creates a fresh start time when the server starts
|
|
28
|
+
*/
|
|
29
|
+
async function initializeAgentStartTime() {
|
|
30
|
+
try {
|
|
31
|
+
// Always create a fresh start time when the server starts
|
|
32
|
+
agentStartTime = new Date();
|
|
33
|
+
agentInfo.startTime = agentStartTime;
|
|
34
|
+
await agentStore.saveAgentStartTime(agentStartTime);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('Failed to initialize agent start time:', err);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function handleGeneralAction(ws, clientId, action, payload) {
|
|
41
|
+
switch (action) {
|
|
42
|
+
case 'getAgentInfo':
|
|
43
|
+
return await handleGetAgentInfo(ws, payload);
|
|
44
|
+
case 'getDockerInfo':
|
|
45
|
+
return await handleGetDockerInfo(ws, payload);
|
|
46
|
+
case 'execInContainer':
|
|
47
|
+
return await handleExecInContainer(ws, clientId, payload);
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Unknown general action: ${action}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function handleGetAgentInfo(ws, payload = {}) {
|
|
54
|
+
try {
|
|
55
|
+
const currentTime = Date.now();
|
|
56
|
+
const uptimeMs = currentTime - new Date(agentInfo.startTime).getTime();
|
|
57
|
+
const formattedUptime = formatUptime(uptimeMs);
|
|
58
|
+
|
|
59
|
+
// Get session info
|
|
60
|
+
const sessionInfo = agentSessionStore.getAgentSessionInfo();
|
|
61
|
+
const session = loadSession();
|
|
62
|
+
|
|
63
|
+
const info = {
|
|
64
|
+
...agentInfo,
|
|
65
|
+
timestamp: Date.now(),
|
|
66
|
+
uptime: formattedUptime,
|
|
67
|
+
agentId: sessionInfo.agentId,
|
|
68
|
+
userEntityRef:
|
|
69
|
+
sessionInfo.userEntityRef || (session && session.userEntityRef),
|
|
70
|
+
sessionExpiresAt:
|
|
71
|
+
sessionInfo.sessionExpiresAt || (session && session.expiresAt),
|
|
72
|
+
status: 'connected', // Agent is connected if responding
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
ws.send(
|
|
76
|
+
JSON.stringify({
|
|
77
|
+
type: 'agentInfo',
|
|
78
|
+
info,
|
|
79
|
+
requestId: payload.requestId,
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Error getting agent info:', error);
|
|
84
|
+
ws.send(
|
|
85
|
+
JSON.stringify({
|
|
86
|
+
type: 'error',
|
|
87
|
+
error: 'Failed to get agent info: ' + error.message,
|
|
88
|
+
requestId: payload.requestId,
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function handleExecInContainer(ws, clientId, payload) {
|
|
95
|
+
try {
|
|
96
|
+
const { containerId, command, requestId } = payload;
|
|
97
|
+
|
|
98
|
+
const container = docker.getContainer(containerId);
|
|
99
|
+
const exec = await container.exec({
|
|
100
|
+
AttachStdin: false,
|
|
101
|
+
AttachStdout: true,
|
|
102
|
+
AttachStderr: true,
|
|
103
|
+
Tty: false,
|
|
104
|
+
Cmd: ['/bin/sh', '-c', command],
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const stream = await exec.start({ hijack: true, stdin: false });
|
|
108
|
+
let output = '';
|
|
109
|
+
|
|
110
|
+
stream.on('data', (chunk) => {
|
|
111
|
+
output += chunk.toString();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
stream.on('end', () => {
|
|
115
|
+
ws.send(
|
|
116
|
+
JSON.stringify({
|
|
117
|
+
type: 'execResult',
|
|
118
|
+
containerId,
|
|
119
|
+
output,
|
|
120
|
+
requestId,
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
stream.on('error', (err) => {
|
|
126
|
+
ws.send(
|
|
127
|
+
JSON.stringify({
|
|
128
|
+
type: 'error',
|
|
129
|
+
error: `Error executing command: ${err.message}`,
|
|
130
|
+
requestId,
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error('Error executing command in container:', error);
|
|
136
|
+
ws.send(
|
|
137
|
+
JSON.stringify({
|
|
138
|
+
type: 'error',
|
|
139
|
+
error: 'Failed to execute command in container: ' + error.message,
|
|
140
|
+
requestId: payload.requestId,
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function handleGetDockerInfo(ws, payload = {}) {
|
|
147
|
+
try {
|
|
148
|
+
const info = await docker.info();
|
|
149
|
+
|
|
150
|
+
ws.send(
|
|
151
|
+
JSON.stringify({
|
|
152
|
+
type: 'dockerInfo',
|
|
153
|
+
info,
|
|
154
|
+
requestId: payload.requestId,
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error('Error getting Docker info:', error);
|
|
159
|
+
ws.send(
|
|
160
|
+
JSON.stringify({
|
|
161
|
+
type: 'error',
|
|
162
|
+
error: 'Failed to get Docker info: ' + error.message,
|
|
163
|
+
requestId: payload.requestId,
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default { handleGeneralAction, agentInfo, initializeAgentStartTime };
|
|
170
|
+
|
|
171
|
+
export { handleGeneralAction, agentInfo, initializeAgentStartTime };
|