@edgible-team/cli 1.2.13 → 1.2.17
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/README.md +5 -3
- package/dist/client/api-client.d.ts +13 -1
- package/dist/client/api-client.d.ts.map +1 -1
- package/dist/client/api-client.js +19 -0
- package/dist/commands/agent/install.d.ts +2 -1
- package/dist/commands/agent/install.d.ts.map +1 -1
- package/dist/commands/agent/install.js +24 -7
- package/dist/commands/agent/start.d.ts +5 -1
- package/dist/commands/agent/start.d.ts.map +1 -1
- package/dist/commands/agent/start.js +19 -280
- package/dist/commands/agent/uninstall.d.ts.map +1 -1
- package/dist/commands/agent/uninstall.js +14 -7
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +3 -2
- package/dist/commands/ai/setup.d.ts +1 -1
- package/dist/commands/ai/setup.d.ts.map +1 -1
- package/dist/commands/ai.js +1 -1
- package/dist/commands/application/create-docker-compose.d.ts +3 -1
- package/dist/commands/application/create-docker-compose.d.ts.map +1 -1
- package/dist/commands/application/create-docker-compose.js +25 -69
- package/dist/commands/application/create-existing.d.ts +2 -2
- package/dist/commands/application/create-existing.d.ts.map +1 -1
- package/dist/commands/application/create-existing.js +27 -132
- package/dist/commands/application/create-managed-process.d.ts +3 -1
- package/dist/commands/application/create-managed-process.d.ts.map +1 -1
- package/dist/commands/application/create-managed-process.js +31 -75
- package/dist/commands/application/delete.d.ts +2 -1
- package/dist/commands/application/delete.d.ts.map +1 -1
- package/dist/commands/application/delete.js +19 -5
- package/dist/commands/application/update.d.ts +3 -0
- package/dist/commands/application/update.d.ts.map +1 -1
- package/dist/commands/application/update.js +45 -1
- package/dist/commands/application.d.ts.map +1 -1
- package/dist/commands/application.js +33 -19
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +44 -0
- package/dist/commands/debug.js +1 -1
- package/dist/commands/device/application-health.d.ts +7 -0
- package/dist/commands/device/application-health.d.ts.map +1 -0
- package/dist/commands/device/application-health.js +103 -0
- package/dist/commands/device/delete.d.ts +7 -0
- package/dist/commands/device/delete.d.ts.map +1 -0
- package/dist/commands/device/delete.js +69 -0
- package/dist/commands/device/health.d.ts +7 -0
- package/dist/commands/device/health.d.ts.map +1 -0
- package/dist/commands/device/health.js +78 -0
- package/dist/commands/device/list.d.ts +5 -0
- package/dist/commands/device/list.d.ts.map +1 -0
- package/dist/commands/device/list.js +46 -0
- package/dist/commands/device/telemetry.d.ts +8 -0
- package/dist/commands/device/telemetry.d.ts.map +1 -0
- package/dist/commands/device/telemetry.js +59 -0
- package/dist/commands/device.d.ts +6 -0
- package/dist/commands/device.d.ts.map +1 -0
- package/dist/commands/device.js +86 -0
- package/dist/commands/stack/deploy.d.ts +8 -0
- package/dist/commands/stack/deploy.d.ts.map +1 -0
- package/dist/commands/stack/deploy.js +61 -0
- package/dist/commands/stack/diff.d.ts +7 -0
- package/dist/commands/stack/diff.d.ts.map +1 -0
- package/dist/commands/stack/diff.js +66 -0
- package/dist/commands/stack/status.d.ts +9 -0
- package/dist/commands/stack/status.d.ts.map +1 -0
- package/dist/commands/stack/status.js +55 -0
- package/dist/commands/stack/teardown.d.ts +8 -0
- package/dist/commands/stack/teardown.d.ts.map +1 -0
- package/dist/commands/stack/teardown.js +107 -0
- package/dist/commands/stack/validate.d.ts +7 -0
- package/dist/commands/stack/validate.d.ts.map +1 -0
- package/dist/commands/stack/validate.js +44 -0
- package/dist/commands/stack.d.ts +10 -0
- package/dist/commands/stack.d.ts.map +1 -0
- package/dist/commands/stack.js +117 -0
- package/dist/commands/utils/auth-prompt.d.ts +25 -0
- package/dist/commands/utils/auth-prompt.d.ts.map +1 -0
- package/dist/commands/utils/auth-prompt.js +115 -0
- package/dist/commands/utils/device-prompt.d.ts +18 -0
- package/dist/commands/utils/device-prompt.d.ts.map +1 -0
- package/dist/commands/utils/device-prompt.js +58 -0
- package/dist/commands/utils/output-formatter.d.ts +13 -0
- package/dist/commands/utils/output-formatter.d.ts.map +1 -1
- package/dist/commands/utils/output-formatter.js +21 -0
- package/dist/index.js +4 -0
- package/dist/services/LocalAgentManager.d.ts +2 -1
- package/dist/services/LocalAgentManager.d.ts.map +1 -1
- package/dist/services/LocalAgentManager.js +6 -4
- package/dist/services/application/ApplicationService.d.ts +19 -0
- package/dist/services/application/ApplicationService.d.ts.map +1 -1
- package/dist/services/application/ApplicationService.js +14 -1
- package/dist/services/device/DeviceService.d.ts +62 -0
- package/dist/services/device/DeviceService.d.ts.map +1 -0
- package/dist/services/device/DeviceService.js +235 -0
- package/dist/services/edgible.d.ts +3 -1
- package/dist/services/edgible.d.ts.map +1 -1
- package/dist/services/edgible.js +5 -4
- package/dist/services/instances.d.ts +27 -1
- package/dist/services/instances.d.ts.map +1 -1
- package/dist/services/instances.js +53 -4
- package/dist/services/stack/DependencyGraphManager.d.ts +69 -0
- package/dist/services/stack/DependencyGraphManager.d.ts.map +1 -0
- package/dist/services/stack/DependencyGraphManager.js +204 -0
- package/dist/services/stack/DeviceResolver.d.ts +63 -0
- package/dist/services/stack/DeviceResolver.d.ts.map +1 -0
- package/dist/services/stack/DeviceResolver.js +147 -0
- package/dist/services/stack/GatewayResolver.d.ts +84 -0
- package/dist/services/stack/GatewayResolver.d.ts.map +1 -0
- package/dist/services/stack/GatewayResolver.js +179 -0
- package/dist/services/stack/StackParser.d.ts +38 -0
- package/dist/services/stack/StackParser.d.ts.map +1 -0
- package/dist/services/stack/StackParser.js +234 -0
- package/dist/services/stack/StackService.d.ts +76 -0
- package/dist/services/stack/StackService.d.ts.map +1 -0
- package/dist/services/stack/StackService.js +476 -0
- package/dist/types/AgentConfig.d.ts +26 -0
- package/dist/types/AgentConfig.d.ts.map +1 -1
- package/dist/types/ApiRequests.d.ts +5 -1
- package/dist/types/ApiRequests.d.ts.map +1 -1
- package/dist/types/ApiResponses.d.ts +5 -0
- package/dist/types/ApiResponses.d.ts.map +1 -1
- package/dist/types/JobTypes.d.ts +103 -0
- package/dist/types/JobTypes.d.ts.map +1 -0
- package/dist/types/JobTypes.js +80 -0
- package/dist/types/WebSocketMessages.d.ts +89 -0
- package/dist/types/WebSocketMessages.d.ts.map +1 -0
- package/dist/types/WebSocketMessages.js +5 -0
- package/dist/types/backendJobs.d.ts +102 -0
- package/dist/types/backendJobs.d.ts.map +1 -0
- package/dist/types/backendJobs.js +5 -0
- package/dist/types/models/ApplicationData.d.ts +1 -1
- package/dist/types/models/ApplicationData.d.ts.map +1 -1
- package/dist/types/models/DeviceData.d.ts +4 -0
- package/dist/types/models/DeviceData.d.ts.map +1 -1
- package/dist/types/stack.d.ts +191 -0
- package/dist/types/stack.d.ts.map +1 -0
- package/dist/types/stack.js +5 -0
- package/dist/types/validation/schemas.d.ts +20 -20
- package/dist/types/validation/schemas.js +1 -1
- package/dist/utils/stack-errors.d.ts +103 -0
- package/dist/utils/stack-errors.d.ts.map +1 -0
- package/dist/utils/stack-errors.js +158 -0
- package/dist/utils/stack-file.d.ts +11 -0
- package/dist/utils/stack-file.d.ts.map +1 -0
- package/dist/utils/stack-file.js +66 -0
- package/dist/validation/stack-schemas.d.ts +535 -0
- package/dist/validation/stack-schemas.d.ts.map +1 -0
- package/dist/validation/stack-schemas.js +178 -0
- package/package.json +4 -2
- package/dist/commands/agent/agent-handlers.d.ts +0 -45
- package/dist/commands/agent/agent-handlers.d.ts.map +0 -1
- package/dist/commands/agent/agent-handlers.js +0 -1159
- package/dist/commands/application/api-keys.d.ts +0 -3
- package/dist/commands/application/api-keys.d.ts.map +0 -1
- package/dist/commands/application/api-keys.js +0 -227
- package/dist/commands/application/create-compose.d.ts +0 -3
- package/dist/commands/application/create-compose.d.ts.map +0 -1
- package/dist/commands/application/create-compose.js +0 -381
- package/dist/commands/application/create-interactive.d.ts +0 -3
- package/dist/commands/application/create-interactive.d.ts.map +0 -1
- package/dist/commands/application/create-interactive.js +0 -326
- package/dist/commands/application/create-workload.d.ts +0 -5
- package/dist/commands/application/create-workload.d.ts.map +0 -1
- package/dist/commands/application/create-workload.js +0 -48
- package/dist/commands/application/short-codes.d.ts +0 -3
- package/dist/commands/application/short-codes.d.ts.map +0 -1
- package/dist/commands/application/short-codes.js +0 -226
- package/dist/commands/application/toggle.d.ts +0 -2
- package/dist/commands/application/toggle.d.ts.map +0 -1
- package/dist/commands/application/toggle.js +0 -78
- package/dist/commands/examples/migrated-command-example.d.ts +0 -31
- package/dist/commands/examples/migrated-command-example.d.ts.map +0 -1
- package/dist/commands/examples/migrated-command-example.js +0 -180
- package/dist/commands/managedGateway/create.d.ts +0 -6
- package/dist/commands/managedGateway/create.d.ts.map +0 -1
- package/dist/commands/managedGateway/create.js +0 -50
- package/dist/commands/managedGateway/delete.d.ts +0 -5
- package/dist/commands/managedGateway/delete.d.ts.map +0 -1
- package/dist/commands/managedGateway/delete.js +0 -57
- package/dist/commands/managedGateway/get.d.ts +0 -4
- package/dist/commands/managedGateway/get.d.ts.map +0 -1
- package/dist/commands/managedGateway/get.js +0 -71
- package/dist/commands/managedGateway/haproxy-stats.d.ts +0 -6
- package/dist/commands/managedGateway/haproxy-stats.d.ts.map +0 -1
- package/dist/commands/managedGateway/haproxy-stats.js +0 -131
- package/dist/commands/managedGateway/list.d.ts +0 -4
- package/dist/commands/managedGateway/list.d.ts.map +0 -1
- package/dist/commands/managedGateway/list.js +0 -50
- package/dist/commands/managedGateway/logs.d.ts +0 -10
- package/dist/commands/managedGateway/logs.d.ts.map +0 -1
- package/dist/commands/managedGateway/logs.js +0 -100
- package/dist/commands/managedGateway/reboot.d.ts +0 -5
- package/dist/commands/managedGateway/reboot.d.ts.map +0 -1
- package/dist/commands/managedGateway/reboot.js +0 -95
- package/dist/commands/managedGateway/resync.d.ts +0 -10
- package/dist/commands/managedGateway/resync.d.ts.map +0 -1
- package/dist/commands/managedGateway/resync.js +0 -69
- package/dist/commands/managedGateway/ssh.d.ts +0 -4
- package/dist/commands/managedGateway/ssh.d.ts.map +0 -1
- package/dist/commands/managedGateway/ssh.js +0 -130
- package/dist/commands/managedGateway/wipe-logs.d.ts +0 -4
- package/dist/commands/managedGateway/wipe-logs.d.ts.map +0 -1
- package/dist/commands/managedGateway/wipe-logs.js +0 -67
- package/dist/commands/managedGateway/wireguard.d.ts +0 -4
- package/dist/commands/managedGateway/wireguard.d.ts.map +0 -1
- package/dist/commands/managedGateway/wireguard.js +0 -68
- package/dist/di/bindings.d.ts +0 -15
- package/dist/di/bindings.d.ts.map +0 -1
- package/dist/di/bindings.js +0 -99
- package/dist/di/container.d.ts +0 -44
- package/dist/di/container.d.ts.map +0 -1
- package/dist/di/container.js +0 -88
- package/dist/di/types.d.ts +0 -23
- package/dist/di/types.d.ts.map +0 -1
- package/dist/di/types.js +0 -32
- package/dist/repositories/config-repository.d.ts +0 -46
- package/dist/repositories/config-repository.d.ts.map +0 -1
- package/dist/repositories/config-repository.js +0 -62
- package/dist/repositories/gateway-repository.d.ts +0 -37
- package/dist/repositories/gateway-repository.d.ts.map +0 -1
- package/dist/repositories/gateway-repository.js +0 -35
|
@@ -1,1159 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.handleAgentStatus = handleAgentStatus;
|
|
40
|
-
exports.handleAgentInstall = handleAgentInstall;
|
|
41
|
-
exports.handleAgentStart = handleAgentStart;
|
|
42
|
-
exports.handleAgentStop = handleAgentStop;
|
|
43
|
-
exports.handleAgentRestart = handleAgentRestart;
|
|
44
|
-
exports.handleAgentLogs = handleAgentLogs;
|
|
45
|
-
exports.handleAgentUninstall = handleAgentUninstall;
|
|
46
|
-
exports.handleAgentSetLogLevel = handleAgentSetLogLevel;
|
|
47
|
-
exports.handleAgentSetup = handleAgentSetup;
|
|
48
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
49
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
50
|
-
const os = __importStar(require("os"));
|
|
51
|
-
const path = __importStar(require("path"));
|
|
52
|
-
const fs = __importStar(require("fs"));
|
|
53
|
-
const fsPromises = __importStar(require("fs/promises"));
|
|
54
|
-
const AgentStatusManager_1 = require("../../services/AgentStatusManager");
|
|
55
|
-
const config_validator_1 = require("../utils/config-validator");
|
|
56
|
-
const DependencyInstaller_1 = require("../../services/DependencyInstaller");
|
|
57
|
-
const PlatformDetector_1 = require("../../utils/PlatformDetector");
|
|
58
|
-
const DaemonManagerFactory_1 = require("../../services/daemon/DaemonManagerFactory");
|
|
59
|
-
const PathResolver_1 = require("../../utils/PathResolver");
|
|
60
|
-
const urls_1 = require("../../utils/urls");
|
|
61
|
-
const log_formatter_1 = require("../../utils/log-formatter");
|
|
62
|
-
const sudo_checker_1 = require("../../utils/sudo-checker");
|
|
63
|
-
async function handleAgentStatus(options, logger, configManager, agentManager) {
|
|
64
|
-
const statusManager = new AgentStatusManager_1.AgentStatusManager();
|
|
65
|
-
const config = configManager.getConfig();
|
|
66
|
-
if (options.watch) {
|
|
67
|
-
logger.debug('Watching agent status');
|
|
68
|
-
console.log(chalk_1.default.blue('Watching agent status (Ctrl+C to stop)...'));
|
|
69
|
-
let lastStatus = null;
|
|
70
|
-
statusManager.startWatching((result) => {
|
|
71
|
-
// Only update display if status changed significantly
|
|
72
|
-
if (!lastStatus || JSON.stringify(lastStatus) !== JSON.stringify(result)) {
|
|
73
|
-
lastStatus = result;
|
|
74
|
-
// Show installation type first
|
|
75
|
-
if (config.agentInstallationType) {
|
|
76
|
-
console.log(chalk_1.default.gray(`\nInstallation Type: ${config.agentInstallationType}`));
|
|
77
|
-
}
|
|
78
|
-
agentManager.displayAgentStatus(result.status);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
logger.debug('Checking agent status');
|
|
84
|
-
// Show installation type
|
|
85
|
-
if (config.agentInstallationType) {
|
|
86
|
-
console.log(chalk_1.default.blue('\n📋 Agent Configuration'));
|
|
87
|
-
console.log(chalk_1.default.gray(` Installation Type: ${config.agentInstallationType}`));
|
|
88
|
-
if (config.agentServiceName) {
|
|
89
|
-
console.log(chalk_1.default.gray(` Service Name: ${config.agentServiceName}`));
|
|
90
|
-
}
|
|
91
|
-
if (config.agentContainerName) {
|
|
92
|
-
console.log(chalk_1.default.gray(` Container Name: ${config.agentContainerName}`));
|
|
93
|
-
}
|
|
94
|
-
console.log('');
|
|
95
|
-
}
|
|
96
|
-
// Get daemon status if available
|
|
97
|
-
if (config.agentInstallationType) {
|
|
98
|
-
try {
|
|
99
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.fromConfig(config.agentInstallationType);
|
|
100
|
-
if (daemonManager) {
|
|
101
|
-
console.log(chalk_1.default.blue('🔧 Daemon Status'));
|
|
102
|
-
const daemonStatus = await daemonManager.status();
|
|
103
|
-
console.log(chalk_1.default.gray(` Running: ${daemonStatus.running ? chalk_1.default.green('Yes') : chalk_1.default.red('No')}`));
|
|
104
|
-
console.log(chalk_1.default.gray(` Enabled: ${daemonStatus.enabled ? chalk_1.default.green('Yes') : chalk_1.default.gray('No')}`));
|
|
105
|
-
if (daemonStatus.pid) {
|
|
106
|
-
console.log(chalk_1.default.gray(` PID: ${daemonStatus.pid}`));
|
|
107
|
-
}
|
|
108
|
-
console.log('');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
console.log(chalk_1.default.yellow('⚠ Could not fetch daemon status\n'));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Get agent status from status file
|
|
116
|
-
// console.log(chalk.blue('🤖 Agent Status'));
|
|
117
|
-
// const status = await agentManager.checkLocalAgentStatus();
|
|
118
|
-
// agentManager.displayAgentStatus(status);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async function handleAgentInstall(options, logger, configManager, edgibleService, authService, agentManager) {
|
|
122
|
-
if (!(0, sudo_checker_1.checkSudoPermissions)()) {
|
|
123
|
-
console.log(chalk_1.default.redBright("Please run this command with administrator priviledges (i.e. sudo)"));
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
(0, config_validator_1.validateConfig)(configManager, {
|
|
127
|
-
requireAuth: true,
|
|
128
|
-
requireOrganization: true,
|
|
129
|
-
});
|
|
130
|
-
console.log(chalk_1.default.blue.bold('\n═══════════════════════════════════════════'));
|
|
131
|
-
console.log(chalk_1.default.blue.bold(' Edgible Agent Installation'));
|
|
132
|
-
console.log(chalk_1.default.blue.bold('═══════════════════════════════════════════\n'));
|
|
133
|
-
// Step 1: Check platform and root privileges
|
|
134
|
-
const platform = PlatformDetector_1.PlatformDetector.getPlatform();
|
|
135
|
-
const isRoot = await PlatformDetector_1.PlatformDetector.isRoot();
|
|
136
|
-
console.log(chalk_1.default.gray(`Platform: ${platform}`));
|
|
137
|
-
console.log(chalk_1.default.gray(`Running as ${isRoot ? 'root/administrator' : 'regular user'}\n`));
|
|
138
|
-
if (!isRoot) {
|
|
139
|
-
console.log(chalk_1.default.yellow('⚠ ' + PlatformDetector_1.PlatformDetector.getRootRequirementMessage()));
|
|
140
|
-
console.log(chalk_1.default.gray(' Some installation options require elevated privileges.\n'));
|
|
141
|
-
}
|
|
142
|
-
// Step 2: Device Selection (moved from start command)
|
|
143
|
-
const config = configManager.getConfig();
|
|
144
|
-
let deviceId = config.deviceId;
|
|
145
|
-
let devicePassword = config.devicePassword;
|
|
146
|
-
console.log(chalk_1.default.blue('📱 Device Selection'));
|
|
147
|
-
console.log(chalk_1.default.gray('Select which serving device this agent should represent:\n'));
|
|
148
|
-
try {
|
|
149
|
-
// Fetch available serving devices
|
|
150
|
-
const servingDevicesResp = await edgibleService.listServingDevices();
|
|
151
|
-
const servingDevices = servingDevicesResp?.devices || [];
|
|
152
|
-
if (servingDevices.length > 0) {
|
|
153
|
-
// Show list of devices to select from
|
|
154
|
-
const deviceChoices = servingDevices.map((d) => {
|
|
155
|
-
const isCurrentDevice = config.deviceId === d.id;
|
|
156
|
-
const displayName = `${d.name || d.id}${d.description ? ` - ${d.description}` : ''}${isCurrentDevice ? chalk_1.default.gray(' (current)') : ''}`;
|
|
157
|
-
return {
|
|
158
|
-
name: displayName,
|
|
159
|
-
value: d.id
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
// Add option to create new device
|
|
163
|
-
deviceChoices.push({
|
|
164
|
-
name: chalk_1.default.cyan('➕ Create new serving device'),
|
|
165
|
-
value: '__create_new__'
|
|
166
|
-
});
|
|
167
|
-
const { selectedDeviceId } = await inquirer_1.default.prompt([{
|
|
168
|
-
type: 'list',
|
|
169
|
-
name: 'selectedDeviceId',
|
|
170
|
-
message: 'Select serving device:',
|
|
171
|
-
choices: deviceChoices,
|
|
172
|
-
default: config.deviceId || undefined
|
|
173
|
-
}]);
|
|
174
|
-
if (selectedDeviceId === '__create_new__') {
|
|
175
|
-
// Create new device
|
|
176
|
-
const deviceNameAnswer = await inquirer_1.default.prompt([{
|
|
177
|
-
type: 'input',
|
|
178
|
-
name: 'deviceName',
|
|
179
|
-
message: 'Enter a name for this device:',
|
|
180
|
-
default: `${os.hostname()}-${os.platform()}`,
|
|
181
|
-
validate: (input) => {
|
|
182
|
-
if (!input.trim()) {
|
|
183
|
-
return 'Device name is required';
|
|
184
|
-
}
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
}]);
|
|
188
|
-
const descriptionAnswer = await inquirer_1.default.prompt([{
|
|
189
|
-
type: 'input',
|
|
190
|
-
name: 'description',
|
|
191
|
-
message: 'Enter device description (optional):',
|
|
192
|
-
default: `Serving device: ${deviceNameAnswer.deviceName}`
|
|
193
|
-
}]);
|
|
194
|
-
console.log(chalk_1.default.gray('\nCreating device...'));
|
|
195
|
-
const createResponse = await edgibleService.createServingDevice({
|
|
196
|
-
name: deviceNameAnswer.deviceName.trim(),
|
|
197
|
-
description: descriptionAnswer.description.trim()
|
|
198
|
-
});
|
|
199
|
-
deviceId = createResponse.device.id;
|
|
200
|
-
devicePassword = createResponse.device.password;
|
|
201
|
-
console.log(chalk_1.default.green(`✓ Device created: ${deviceId}`));
|
|
202
|
-
console.log(chalk_1.default.yellow(`\n⚠ Device Password: ${devicePassword}`));
|
|
203
|
-
console.log(chalk_1.default.yellow('⚠ Please save this password securely!\n'));
|
|
204
|
-
// Verify device credentials
|
|
205
|
-
if (devicePassword && deviceId) {
|
|
206
|
-
console.log(chalk_1.default.gray('Verifying device credentials...'));
|
|
207
|
-
try {
|
|
208
|
-
const isValid = await authService.verifyDeviceCredentials(deviceId, devicePassword);
|
|
209
|
-
if (isValid) {
|
|
210
|
-
console.log(chalk_1.default.green('✓ Device credentials verified\n'));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch (verifyError) {
|
|
214
|
-
console.log(chalk_1.default.yellow('⚠ Could not verify device credentials\n'));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
// Save device credentials to config
|
|
218
|
-
configManager.updateConfig({
|
|
219
|
-
deviceId: deviceId,
|
|
220
|
-
deviceName: deviceNameAnswer.deviceName.trim(),
|
|
221
|
-
devicePassword: devicePassword,
|
|
222
|
-
deviceType: 'serving'
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
// Use existing device - need to fetch full details to get password
|
|
227
|
-
deviceId = selectedDeviceId;
|
|
228
|
-
if (!deviceId) {
|
|
229
|
-
throw new Error('No device selected');
|
|
230
|
-
}
|
|
231
|
-
console.log(chalk_1.default.gray('Retrieving device credentials...\n'));
|
|
232
|
-
// Fetch device details to get the plaintext password
|
|
233
|
-
const deviceResponse = await edgibleService.getDevice(deviceId);
|
|
234
|
-
devicePassword = deviceResponse.device?.password || '';
|
|
235
|
-
if (!devicePassword) {
|
|
236
|
-
throw new Error('Could not retrieve device password from API');
|
|
237
|
-
}
|
|
238
|
-
// Save device credentials to config
|
|
239
|
-
configManager.updateConfig({
|
|
240
|
-
deviceId,
|
|
241
|
-
devicePassword,
|
|
242
|
-
deviceType: 'serving'
|
|
243
|
-
});
|
|
244
|
-
console.log(chalk_1.default.green(`✓ Using device: ${deviceId}\n`));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
// No devices exist, must create one
|
|
249
|
-
console.log(chalk_1.default.yellow('No serving devices found. Creating a new one...\n'));
|
|
250
|
-
const deviceNameAnswer = await inquirer_1.default.prompt([{
|
|
251
|
-
type: 'input',
|
|
252
|
-
name: 'deviceName',
|
|
253
|
-
message: 'Enter a name for this device:',
|
|
254
|
-
default: `${os.hostname()}-${os.platform()}`,
|
|
255
|
-
validate: (input) => input.trim().length > 0 || 'Device name is required'
|
|
256
|
-
}]);
|
|
257
|
-
const createResponse = await edgibleService.createServingDevice({
|
|
258
|
-
name: deviceNameAnswer.deviceName.trim(),
|
|
259
|
-
description: `Serving device: ${deviceNameAnswer.deviceName}`
|
|
260
|
-
});
|
|
261
|
-
deviceId = createResponse.device.id;
|
|
262
|
-
devicePassword = createResponse.device.password;
|
|
263
|
-
console.log(chalk_1.default.green(`✓ Device created: ${deviceId}`));
|
|
264
|
-
console.log(chalk_1.default.yellow(`\n⚠ Device Password: ${devicePassword}`));
|
|
265
|
-
console.log(chalk_1.default.yellow('⚠ Please save this password securely!\n'));
|
|
266
|
-
configManager.updateConfig({
|
|
267
|
-
deviceId,
|
|
268
|
-
deviceName: deviceNameAnswer.deviceName.trim(),
|
|
269
|
-
devicePassword,
|
|
270
|
-
deviceType: 'serving'
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
catch (error) {
|
|
275
|
-
logger.error('Error during device selection', error);
|
|
276
|
-
const errorMessage = error instanceof Error ? error.message : 'An unexpected error occurred';
|
|
277
|
-
console.error(chalk_1.default.red('Error during device selection:'), errorMessage);
|
|
278
|
-
throw error;
|
|
279
|
-
}
|
|
280
|
-
// Verify we have device credentials
|
|
281
|
-
if (!deviceId || !devicePassword) {
|
|
282
|
-
throw new Error('Device credentials are required');
|
|
283
|
-
}
|
|
284
|
-
// Step 3: Installation Method Selection
|
|
285
|
-
console.log(chalk_1.default.blue('🔧 Installation Method'));
|
|
286
|
-
console.log(chalk_1.default.gray('Choose how to run the agent:\n'));
|
|
287
|
-
const availableOptions = await PlatformDetector_1.PlatformDetector.getAvailableOptions();
|
|
288
|
-
if (availableOptions.length === 0) {
|
|
289
|
-
console.error(chalk_1.default.red('✗ No installation methods available on this system'));
|
|
290
|
-
console.error(chalk_1.default.yellow('\nThe agent requires native daemon support:'));
|
|
291
|
-
console.error(chalk_1.default.yellow(' - Linux: systemd (requires root/sudo)'));
|
|
292
|
-
console.error(chalk_1.default.yellow(' - macOS: launchd (requires root/sudo)'));
|
|
293
|
-
console.error(chalk_1.default.yellow(' - Windows: Windows Service (requires Administrator)'));
|
|
294
|
-
console.error(chalk_1.default.yellow('\nPlease ensure you have the appropriate privileges and daemon support.'));
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
let selectedType;
|
|
298
|
-
if (options.type) {
|
|
299
|
-
// Type specified via flag - validate it's a supported daemon type
|
|
300
|
-
const supportedTypes = ['systemd', 'launchd', 'windows-service'];
|
|
301
|
-
if (!supportedTypes.includes(options.type)) {
|
|
302
|
-
console.error(chalk_1.default.red(`✗ Installation type '${options.type}' is not supported`));
|
|
303
|
-
console.error(chalk_1.default.yellow(` Only daemon installations are supported: ${supportedTypes.join(', ')}`));
|
|
304
|
-
console.error(chalk_1.default.yellow(` Docker and Podman installations are no longer available`));
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
selectedType = options.type;
|
|
308
|
-
const option = availableOptions.find(opt => opt.type === selectedType);
|
|
309
|
-
if (!option) {
|
|
310
|
-
console.error(chalk_1.default.red(`✗ Installation type '${selectedType}' not available on this platform`));
|
|
311
|
-
console.error(chalk_1.default.yellow(` This installation type is not supported on ${platform}`));
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (!option.available) {
|
|
315
|
-
console.error(chalk_1.default.red(`✗ Installation type '${selectedType}' is not available on this system`));
|
|
316
|
-
console.error(chalk_1.default.yellow(` Requirements: ${option.requires.join(', ')}`));
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
// Interactive selection
|
|
322
|
-
const choices = availableOptions.map(opt => {
|
|
323
|
-
const status = opt.available ? chalk_1.default.green('✓') : chalk_1.default.red('✗');
|
|
324
|
-
const rootBadge = opt.requiresRoot ? chalk_1.default.yellow('[requires root]') : '';
|
|
325
|
-
return {
|
|
326
|
-
name: `${status} ${opt.name} ${rootBadge}\n ${chalk_1.default.gray(opt.description)}\n ${chalk_1.default.gray('Pros:')} ${opt.pros.join(', ')}\n ${chalk_1.default.gray('Best for:')} ${opt.bestFor}`,
|
|
327
|
-
value: opt.type,
|
|
328
|
-
disabled: !opt.available ? `Requires: ${opt.requires.join(', ')}` : false
|
|
329
|
-
};
|
|
330
|
-
});
|
|
331
|
-
const { installType } = await inquirer_1.default.prompt([{
|
|
332
|
-
type: 'list',
|
|
333
|
-
name: 'installType',
|
|
334
|
-
message: 'Select installation method:',
|
|
335
|
-
choices,
|
|
336
|
-
pageSize: 10
|
|
337
|
-
}]);
|
|
338
|
-
selectedType = installType;
|
|
339
|
-
}
|
|
340
|
-
console.log(chalk_1.default.green(`\n✓ Selected: ${selectedType}\n`));
|
|
341
|
-
// Validate --local flag is only used with native service managers
|
|
342
|
-
if (options.local && selectedType !== 'systemd' && selectedType !== 'launchd' && selectedType !== 'windows-service') {
|
|
343
|
-
console.error(chalk_1.default.red('✗ --local flag is only supported with native daemon installations'));
|
|
344
|
-
console.error(chalk_1.default.yellow(' Supported with: systemd, launchd, windows-service'));
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
// Step 4: Check and Install Dependencies
|
|
348
|
-
// All supported installation types are native daemons, so always check dependencies
|
|
349
|
-
{
|
|
350
|
-
console.log(chalk_1.default.blue('🔍 Checking System Dependencies'));
|
|
351
|
-
console.log(chalk_1.default.gray('Verifying required tools are installed...\n'));
|
|
352
|
-
const dependencyInstaller = new DependencyInstaller_1.DependencyInstaller();
|
|
353
|
-
try {
|
|
354
|
-
await dependencyInstaller.checkAndInstallDependencies({
|
|
355
|
-
includeWireGuardGo: false, // Use kernel WireGuard by default
|
|
356
|
-
includeIptables: platform === 'linux', // Only check iptables on Linux
|
|
357
|
-
autoInstall: false // Prompt user for installation
|
|
358
|
-
});
|
|
359
|
-
console.log(chalk_1.default.green('✓ Dependencies verified\n'));
|
|
360
|
-
}
|
|
361
|
-
catch (error) {
|
|
362
|
-
console.error(chalk_1.default.red('✗ Dependency check failed'));
|
|
363
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}`));
|
|
364
|
-
console.log(chalk_1.default.yellow('\n⚠ Some dependencies are missing. The agent may not function correctly.'));
|
|
365
|
-
console.log(chalk_1.default.yellow(' You can install them manually or run: edgible agent setup --auto-install\n'));
|
|
366
|
-
// Ask if user wants to continue anyway
|
|
367
|
-
const { continueAnyway } = await inquirer_1.default.prompt([{
|
|
368
|
-
type: 'confirm',
|
|
369
|
-
name: 'continueAnyway',
|
|
370
|
-
message: 'Continue with installation anyway?',
|
|
371
|
-
default: false
|
|
372
|
-
}]);
|
|
373
|
-
if (!continueAnyway) {
|
|
374
|
-
console.log(chalk_1.default.gray('Installation cancelled.'));
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
// Step 5: Install Agent Files
|
|
380
|
-
let agentPath;
|
|
381
|
-
// All supported types are native daemons, so use system path
|
|
382
|
-
const useSystemPath = true;
|
|
383
|
-
const configPath = PathResolver_1.PathResolver.getAgentConfigPath(useSystemPath);
|
|
384
|
-
// For native daemon installations, download/install agent files
|
|
385
|
-
console.log(chalk_1.default.blue('📦 Installing Agent Files'));
|
|
386
|
-
const installResult = await agentManager.installLocalAgent({
|
|
387
|
-
installationType: selectedType,
|
|
388
|
-
installFromLocal: options.local,
|
|
389
|
-
autoStart: false
|
|
390
|
-
});
|
|
391
|
-
if (!installResult.success) {
|
|
392
|
-
console.error(chalk_1.default.red('✗ Failed to install agent files'));
|
|
393
|
-
console.error(chalk_1.default.red(` ${installResult.error}`));
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
agentPath = installResult.path || configPath;
|
|
397
|
-
console.log(chalk_1.default.green('✓ Agent files installed\n'));
|
|
398
|
-
// Step 6: Configure Daemon
|
|
399
|
-
console.log(chalk_1.default.blue('⚙️ Configuring Daemon'));
|
|
400
|
-
// Create agent config at the correct path for this installation type
|
|
401
|
-
await agentManager.updateAgentConfig(configPath);
|
|
402
|
-
const daemonConfig = {
|
|
403
|
-
deviceId,
|
|
404
|
-
devicePassword,
|
|
405
|
-
deviceType: 'serving',
|
|
406
|
-
apiBaseUrl: (0, urls_1.getApiBaseUrl)(),
|
|
407
|
-
organizationId: config.organizationId,
|
|
408
|
-
configPath,
|
|
409
|
-
agentPath
|
|
410
|
-
};
|
|
411
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.create(selectedType);
|
|
412
|
-
try {
|
|
413
|
-
await daemonManager.install(daemonConfig);
|
|
414
|
-
console.log(chalk_1.default.green('✓ Daemon configured\n'));
|
|
415
|
-
}
|
|
416
|
-
catch (error) {
|
|
417
|
-
console.error(chalk_1.default.red('✗ Failed to configure daemon'));
|
|
418
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}`));
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
// Save installation type to config
|
|
422
|
-
configManager.updateConfig({
|
|
423
|
-
agentInstallationType: selectedType,
|
|
424
|
-
agentServiceName: 'edgible-agent',
|
|
425
|
-
agentContainerName: undefined, // No container installations supported
|
|
426
|
-
agentDataPath: configPath
|
|
427
|
-
});
|
|
428
|
-
// Step 7: Enable and Start
|
|
429
|
-
console.log(chalk_1.default.blue('🚀 Starting Agent'));
|
|
430
|
-
try {
|
|
431
|
-
await daemonManager.enable();
|
|
432
|
-
console.log(chalk_1.default.green('✓ Enabled for startup\n'));
|
|
433
|
-
}
|
|
434
|
-
catch (error) {
|
|
435
|
-
console.warn(chalk_1.default.yellow(`⚠ Could not enable auto-start: ${error instanceof Error ? error.message : String(error)}`));
|
|
436
|
-
}
|
|
437
|
-
try {
|
|
438
|
-
await daemonManager.start();
|
|
439
|
-
console.log(chalk_1.default.green('✓ Agent started\n'));
|
|
440
|
-
}
|
|
441
|
-
catch (error) {
|
|
442
|
-
console.error(chalk_1.default.red('✗ Failed to start agent'));
|
|
443
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}`));
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
// Wait a moment for agent to initialize
|
|
447
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
448
|
-
// Show status
|
|
449
|
-
console.log(chalk_1.default.blue('📊 Agent Status'));
|
|
450
|
-
try {
|
|
451
|
-
const status = await daemonManager.status();
|
|
452
|
-
console.log(` Running: ${status.running ? chalk_1.default.green('Yes') : chalk_1.default.red('No')}`);
|
|
453
|
-
console.log(` Enabled: ${status.enabled ? chalk_1.default.green('Yes') : chalk_1.default.gray('No')}`);
|
|
454
|
-
if (status.pid) {
|
|
455
|
-
console.log(` PID: ${status.pid}`);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
catch (error) {
|
|
459
|
-
console.warn(chalk_1.default.yellow(' Could not fetch status'));
|
|
460
|
-
}
|
|
461
|
-
console.log(chalk_1.default.blue.bold('\n═══════════════════════════════════════════'));
|
|
462
|
-
console.log(chalk_1.default.green.bold(' ✓ Installation Complete!'));
|
|
463
|
-
console.log(chalk_1.default.blue.bold('═══════════════════════════════════════════\n'));
|
|
464
|
-
console.log(chalk_1.default.gray('Next steps:'));
|
|
465
|
-
console.log(chalk_1.default.gray(` • View status: ${chalk_1.default.white('edgible agent status')}`));
|
|
466
|
-
console.log(chalk_1.default.gray(` • View logs: ${chalk_1.default.white('edgible agent logs --follow')}`));
|
|
467
|
-
console.log(chalk_1.default.gray(` • Stop agent: ${chalk_1.default.white('edgible agent stop')}`));
|
|
468
|
-
console.log(chalk_1.default.gray(` • Restart agent: ${chalk_1.default.white('edgible agent restart')}\n`));
|
|
469
|
-
}
|
|
470
|
-
async function handleAgentStart(options, logger, configManager, edgibleService, authService, agentManager) {
|
|
471
|
-
(0, config_validator_1.validateConfig)(configManager, {
|
|
472
|
-
requireAuth: true,
|
|
473
|
-
requireOrganization: true,
|
|
474
|
-
});
|
|
475
|
-
const config = configManager.getConfig();
|
|
476
|
-
let deviceId = config.deviceId;
|
|
477
|
-
let devicePassword = config.devicePassword;
|
|
478
|
-
// Always ask user to select or create a device
|
|
479
|
-
console.log(chalk_1.default.blue('\n🔧 Device Selection'));
|
|
480
|
-
console.log(chalk_1.default.gray('Select which serving device this agent should represent:\n'));
|
|
481
|
-
try {
|
|
482
|
-
// Fetch available serving devices
|
|
483
|
-
const servingDevicesResp = await edgibleService.listServingDevices();
|
|
484
|
-
const servingDevices = servingDevicesResp?.devices || [];
|
|
485
|
-
if (servingDevices.length > 0) {
|
|
486
|
-
// Show list of devices to select from
|
|
487
|
-
const deviceChoices = servingDevices.map((d) => {
|
|
488
|
-
const isCurrentDevice = config.deviceId === d.id;
|
|
489
|
-
const displayName = `${d.name || d.id}${d.description ? ` - ${d.description}` : ''}${isCurrentDevice ? chalk_1.default.gray(' (current)') : ''}`;
|
|
490
|
-
return {
|
|
491
|
-
name: displayName,
|
|
492
|
-
value: d.id
|
|
493
|
-
};
|
|
494
|
-
});
|
|
495
|
-
// Add option to create new device
|
|
496
|
-
deviceChoices.push({
|
|
497
|
-
name: chalk_1.default.cyan('➕ Create new serving device'),
|
|
498
|
-
value: '__create_new__'
|
|
499
|
-
});
|
|
500
|
-
const { selectedDeviceId } = await inquirer_1.default.prompt([{
|
|
501
|
-
type: 'list',
|
|
502
|
-
name: 'selectedDeviceId',
|
|
503
|
-
message: 'Select serving device:',
|
|
504
|
-
choices: deviceChoices,
|
|
505
|
-
default: config.deviceId || undefined
|
|
506
|
-
}]);
|
|
507
|
-
if (selectedDeviceId === '__create_new__') {
|
|
508
|
-
// Create new device
|
|
509
|
-
const deviceNameAnswer = await inquirer_1.default.prompt([{
|
|
510
|
-
type: 'input',
|
|
511
|
-
name: 'deviceName',
|
|
512
|
-
message: 'Enter a name for this device:',
|
|
513
|
-
default: `${os.hostname()}-${os.platform()}`,
|
|
514
|
-
validate: (input) => {
|
|
515
|
-
if (!input.trim()) {
|
|
516
|
-
return 'Device name is required';
|
|
517
|
-
}
|
|
518
|
-
return true;
|
|
519
|
-
}
|
|
520
|
-
}]);
|
|
521
|
-
const descriptionAnswer = await inquirer_1.default.prompt([{
|
|
522
|
-
type: 'input',
|
|
523
|
-
name: 'description',
|
|
524
|
-
message: 'Enter device description (optional):',
|
|
525
|
-
default: `Serving device: ${deviceNameAnswer.deviceName}`
|
|
526
|
-
}]);
|
|
527
|
-
console.log(chalk_1.default.gray('\nCreating device...'));
|
|
528
|
-
// Create device via API - password will be generated and returned by the API
|
|
529
|
-
const createResponse = await edgibleService.createServingDevice({
|
|
530
|
-
name: deviceNameAnswer.deviceName.trim(),
|
|
531
|
-
description: descriptionAnswer.description.trim()
|
|
532
|
-
});
|
|
533
|
-
deviceId = createResponse.device.id;
|
|
534
|
-
devicePassword = createResponse.device.password; // Get password from API response
|
|
535
|
-
console.log(chalk_1.default.green(`✓ Device created: ${deviceId}`));
|
|
536
|
-
console.log(chalk_1.default.yellow(`\n⚠ Device Password: ${devicePassword}`));
|
|
537
|
-
console.log(chalk_1.default.yellow('⚠ Please save this password securely! You will need it to login as this device.\n'));
|
|
538
|
-
// Verify device credentials (don't login as device - CLI should use user credentials)
|
|
539
|
-
if (devicePassword && deviceId) {
|
|
540
|
-
const password = devicePassword;
|
|
541
|
-
const id = deviceId;
|
|
542
|
-
console.log(chalk_1.default.gray('Verifying device credentials...'));
|
|
543
|
-
try {
|
|
544
|
-
const isValid = await authService.verifyDeviceCredentials(id, password);
|
|
545
|
-
if (isValid) {
|
|
546
|
-
console.log(chalk_1.default.green('✓ Device credentials verified'));
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
console.log(chalk_1.default.yellow('⚠ Device credentials verification failed, but continuing anyway.'));
|
|
550
|
-
console.log(chalk_1.default.gray('The agent will use these credentials when it starts.'));
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
catch (verifyError) {
|
|
554
|
-
console.log(chalk_1.default.yellow('⚠ Could not verify device credentials. The agent will use these credentials when it starts.'));
|
|
555
|
-
// Continue anyway - credentials are stored and agent will use them
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
// Save device credentials to config
|
|
559
|
-
logger.info('Saving device credentials to config', { deviceId });
|
|
560
|
-
configManager.updateConfig({
|
|
561
|
-
deviceId: deviceId,
|
|
562
|
-
deviceName: deviceNameAnswer.deviceName.trim(),
|
|
563
|
-
devicePassword: devicePassword,
|
|
564
|
-
deviceType: 'serving'
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
// Use existing device - need to get password
|
|
569
|
-
deviceId = selectedDeviceId;
|
|
570
|
-
let passwordVerified = false;
|
|
571
|
-
// Check if we have password for this device in config
|
|
572
|
-
if (config.deviceId === deviceId && config.devicePassword) {
|
|
573
|
-
devicePassword = config.devicePassword;
|
|
574
|
-
// Verify the stored password is still valid (without overwriting user tokens)
|
|
575
|
-
console.log(chalk_1.default.gray('Verifying device credentials...'));
|
|
576
|
-
if (!deviceId || !devicePassword) {
|
|
577
|
-
throw new Error('Device ID or password is missing');
|
|
578
|
-
}
|
|
579
|
-
const isValid = await authService.verifyDeviceCredentials(deviceId, devicePassword);
|
|
580
|
-
if (isValid) {
|
|
581
|
-
console.log(chalk_1.default.green('✓ Device credentials verified'));
|
|
582
|
-
// Update config with current device info (password already stored)
|
|
583
|
-
const selectedDevice = servingDevices.find((d) => d.id === deviceId);
|
|
584
|
-
logger.info('Updating device config', { deviceId });
|
|
585
|
-
configManager.updateConfig({
|
|
586
|
-
deviceId: deviceId,
|
|
587
|
-
deviceName: selectedDevice?.name || deviceId,
|
|
588
|
-
devicePassword: devicePassword,
|
|
589
|
-
deviceType: 'serving'
|
|
590
|
-
});
|
|
591
|
-
passwordVerified = true;
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
console.log(chalk_1.default.yellow('⚠ Stored password is invalid, please enter the device password'));
|
|
595
|
-
devicePassword = undefined; // Clear invalid password
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
// If we don't have a valid password yet, prompt for it
|
|
599
|
-
if (!devicePassword) {
|
|
600
|
-
const passwordAnswer = await inquirer_1.default.prompt([{
|
|
601
|
-
type: 'password',
|
|
602
|
-
name: 'password',
|
|
603
|
-
message: 'Enter device password:',
|
|
604
|
-
validate: (input) => {
|
|
605
|
-
if (!input.trim()) {
|
|
606
|
-
return 'Device password is required';
|
|
607
|
-
}
|
|
608
|
-
return true;
|
|
609
|
-
}
|
|
610
|
-
}]);
|
|
611
|
-
devicePassword = passwordAnswer.password;
|
|
612
|
-
}
|
|
613
|
-
// Verify password (in case it was newly entered or verification failed)
|
|
614
|
-
if (!passwordVerified && devicePassword && deviceId) {
|
|
615
|
-
console.log(chalk_1.default.gray('Verifying device credentials...'));
|
|
616
|
-
if (!deviceId || !devicePassword) {
|
|
617
|
-
throw new Error('Device ID or password is missing');
|
|
618
|
-
}
|
|
619
|
-
const isValid = await authService.verifyDeviceCredentials(deviceId, devicePassword);
|
|
620
|
-
if (isValid) {
|
|
621
|
-
console.log(chalk_1.default.green('✓ Device credentials verified'));
|
|
622
|
-
// Save device credentials to config
|
|
623
|
-
const selectedDevice = servingDevices.find((d) => d.id === deviceId);
|
|
624
|
-
logger.info('Saving device credentials to config', { deviceId });
|
|
625
|
-
configManager.updateConfig({
|
|
626
|
-
deviceId: deviceId,
|
|
627
|
-
deviceName: selectedDevice?.name || deviceId,
|
|
628
|
-
devicePassword: devicePassword,
|
|
629
|
-
deviceType: 'serving'
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
console.error(chalk_1.default.red('✗ Invalid device password'));
|
|
634
|
-
console.log(chalk_1.default.gray('Please check your password and try again'));
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
// No devices available, offer to create one
|
|
642
|
-
console.log(chalk_1.default.yellow('⚠ No serving devices found in your organization.\n'));
|
|
643
|
-
const { createNew } = await inquirer_1.default.prompt([{
|
|
644
|
-
type: 'confirm',
|
|
645
|
-
name: 'createNew',
|
|
646
|
-
message: 'Would you like to create a new serving device?',
|
|
647
|
-
default: true
|
|
648
|
-
}]);
|
|
649
|
-
if (!createNew) {
|
|
650
|
-
console.log(chalk_1.default.gray('Agent start cancelled'));
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
// Create new device
|
|
654
|
-
const deviceNameAnswer = await inquirer_1.default.prompt([{
|
|
655
|
-
type: 'input',
|
|
656
|
-
name: 'deviceName',
|
|
657
|
-
message: 'Enter a name for this device:',
|
|
658
|
-
default: `${os.hostname()}-${os.platform()}`,
|
|
659
|
-
validate: (input) => {
|
|
660
|
-
if (!input.trim()) {
|
|
661
|
-
return 'Device name is required';
|
|
662
|
-
}
|
|
663
|
-
return true;
|
|
664
|
-
}
|
|
665
|
-
}]);
|
|
666
|
-
const descriptionAnswer = await inquirer_1.default.prompt([{
|
|
667
|
-
type: 'input',
|
|
668
|
-
name: 'description',
|
|
669
|
-
message: 'Enter device description (optional):',
|
|
670
|
-
default: `Serving device: ${deviceNameAnswer.deviceName}`
|
|
671
|
-
}]);
|
|
672
|
-
console.log(chalk_1.default.gray('\nCreating device...'));
|
|
673
|
-
// Create device via API - password will be generated and returned by the API
|
|
674
|
-
const createResponse = await edgibleService.createServingDevice({
|
|
675
|
-
name: deviceNameAnswer.deviceName.trim(),
|
|
676
|
-
description: descriptionAnswer.description.trim()
|
|
677
|
-
});
|
|
678
|
-
deviceId = createResponse.device.id;
|
|
679
|
-
devicePassword = createResponse.device.password; // Get password from API response
|
|
680
|
-
console.log(chalk_1.default.green(`✓ Device created: ${deviceId}`));
|
|
681
|
-
console.log(chalk_1.default.yellow(`\n⚠ Device Password: ${devicePassword}`));
|
|
682
|
-
console.log(chalk_1.default.yellow('⚠ Please save this password securely! You will need it to login as this device.\n'));
|
|
683
|
-
// Verify device credentials (don't login as device - CLI should use user credentials)
|
|
684
|
-
if (devicePassword && deviceId) {
|
|
685
|
-
const password = devicePassword;
|
|
686
|
-
const id = deviceId;
|
|
687
|
-
console.log(chalk_1.default.gray('Verifying device credentials...'));
|
|
688
|
-
try {
|
|
689
|
-
const isValid = await edgibleService.verifyDeviceCredentials(id, password);
|
|
690
|
-
if (isValid) {
|
|
691
|
-
console.log(chalk_1.default.green('✓ Device credentials verified'));
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
console.log(chalk_1.default.yellow('⚠ Device credentials verification failed, but continuing anyway.'));
|
|
695
|
-
console.log(chalk_1.default.gray('The agent will use these credentials when it starts.'));
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
catch (verifyError) {
|
|
699
|
-
console.log(chalk_1.default.yellow('⚠ Could not verify device credentials. The agent will use these credentials when it starts.'));
|
|
700
|
-
// Continue anyway - credentials are stored and agent will use them
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
// Save device credentials to config
|
|
704
|
-
logger.info('Saving device credentials to config', { deviceId });
|
|
705
|
-
configManager.updateConfig({
|
|
706
|
-
deviceId: deviceId,
|
|
707
|
-
deviceName: deviceNameAnswer.deviceName.trim(),
|
|
708
|
-
devicePassword: devicePassword,
|
|
709
|
-
deviceType: 'serving'
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
catch (error) {
|
|
714
|
-
logger.error('Error selecting device', error);
|
|
715
|
-
const errorMessage = error instanceof Error ? error.message : 'An unexpected error occurred';
|
|
716
|
-
console.error(chalk_1.default.red('Error selecting device:'), errorMessage);
|
|
717
|
-
throw error;
|
|
718
|
-
}
|
|
719
|
-
// Now start the agent with the selected/created device
|
|
720
|
-
logger.info('Starting local agent', { passthrough: options.passthrough, debug: options.debug, docker: options.docker, root: options.root });
|
|
721
|
-
if (options.docker) {
|
|
722
|
-
console.log(chalk_1.default.blue('\n🐳 Starting agent in Docker...'));
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
console.log(chalk_1.default.blue('\n🚀 Starting agent...'));
|
|
726
|
-
}
|
|
727
|
-
await agentManager.startLocalAgent({
|
|
728
|
-
passthrough: options.passthrough || false,
|
|
729
|
-
debug: options.debug || false,
|
|
730
|
-
docker: options.docker || false,
|
|
731
|
-
root: options.root || false,
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
async function handleAgentStop(logger, configManager) {
|
|
735
|
-
const config = configManager.getConfig();
|
|
736
|
-
if (!config.agentInstallationType) {
|
|
737
|
-
console.log(chalk_1.default.yellow('⚠ Agent installation type not found in config'));
|
|
738
|
-
console.log(chalk_1.default.gray(' Run "edgible agent install" to install the agent\n'));
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
logger.info('Stopping local agent');
|
|
742
|
-
console.log(chalk_1.default.blue('Stopping agent...\n'));
|
|
743
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.fromConfig(config.agentInstallationType);
|
|
744
|
-
if (!daemonManager) {
|
|
745
|
-
console.error(chalk_1.default.red('✗ Could not create daemon manager'));
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
try {
|
|
749
|
-
await daemonManager.stop();
|
|
750
|
-
console.log(chalk_1.default.green('✓ Agent stopped successfully\n'));
|
|
751
|
-
}
|
|
752
|
-
catch (error) {
|
|
753
|
-
console.error(chalk_1.default.red('✗ Failed to stop agent'));
|
|
754
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}\n`));
|
|
755
|
-
throw error;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
async function handleAgentRestart(logger, configManager) {
|
|
759
|
-
const config = configManager.getConfig();
|
|
760
|
-
if (!config.agentInstallationType) {
|
|
761
|
-
console.log(chalk_1.default.yellow('⚠ Agent installation type not found in config'));
|
|
762
|
-
console.log(chalk_1.default.gray(' Run "edgible agent install" to install the agent\n'));
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
logger.info('Restarting local agent');
|
|
766
|
-
console.log(chalk_1.default.blue('Restarting agent...\n'));
|
|
767
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.fromConfig(config.agentInstallationType);
|
|
768
|
-
if (!daemonManager) {
|
|
769
|
-
console.error(chalk_1.default.red('✗ Could not create daemon manager'));
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
try {
|
|
773
|
-
await daemonManager.restart();
|
|
774
|
-
console.log(chalk_1.default.green('✓ Agent restarted successfully\n'));
|
|
775
|
-
}
|
|
776
|
-
catch (error) {
|
|
777
|
-
console.error(chalk_1.default.red('✗ Failed to restart agent'));
|
|
778
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}\n`));
|
|
779
|
-
throw error;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
async function handleAgentLogs(options, configManager) {
|
|
783
|
-
const config = configManager.getConfig();
|
|
784
|
-
if (!config.agentInstallationType) {
|
|
785
|
-
console.log(chalk_1.default.yellow('⚠ Agent installation type not found in config'));
|
|
786
|
-
console.log(chalk_1.default.gray(' Run "edgible agent install" to install the agent\n'));
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.fromConfig(config.agentInstallationType);
|
|
790
|
-
if (!daemonManager) {
|
|
791
|
-
console.error(chalk_1.default.red('✗ Could not create daemon manager'));
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
const lines = options.lines ? parseInt(options.lines, 10) : 100;
|
|
795
|
-
const follow = options.follow || false;
|
|
796
|
-
const level = options.level || 'all';
|
|
797
|
-
const module = options.module;
|
|
798
|
-
const comprehensive = options.comprehensive || false;
|
|
799
|
-
const singleLine = options.singleLine || false;
|
|
800
|
-
try {
|
|
801
|
-
const rawLogs = await daemonManager.logs(follow, lines, {
|
|
802
|
-
stdout: options.stdout,
|
|
803
|
-
stderr: options.stderr
|
|
804
|
-
});
|
|
805
|
-
// For follow mode, logs are streamed directly and rawLogs will be empty
|
|
806
|
-
if (follow) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
// For comprehensive mode, just output raw logs
|
|
810
|
-
if (comprehensive) {
|
|
811
|
-
console.log(rawLogs);
|
|
812
|
-
}
|
|
813
|
-
else {
|
|
814
|
-
// Parse and format JSON logs (works for both systemd and launchd)
|
|
815
|
-
// Both output JSON in production mode, launchd just writes pure JSON lines
|
|
816
|
-
const formattedLogs = (0, log_formatter_1.processLogs)(rawLogs, {
|
|
817
|
-
module: module,
|
|
818
|
-
level: level,
|
|
819
|
-
singleLine: singleLine
|
|
820
|
-
});
|
|
821
|
-
if (formattedLogs.trim()) {
|
|
822
|
-
console.log(formattedLogs);
|
|
823
|
-
}
|
|
824
|
-
else {
|
|
825
|
-
// No formatted logs found - could be no matches or non-JSON logs
|
|
826
|
-
if (module || (level && level !== 'all')) {
|
|
827
|
-
// Filters were applied but no matches
|
|
828
|
-
if (module) {
|
|
829
|
-
console.log(chalk_1.default.yellow(`No logs found for module(s): ${module}`));
|
|
830
|
-
}
|
|
831
|
-
else {
|
|
832
|
-
console.log(chalk_1.default.yellow(`No logs found for level: ${level}`));
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
else {
|
|
836
|
-
// No filters, but no JSON logs found - might be plain text logs
|
|
837
|
-
// Output raw logs as fallback
|
|
838
|
-
console.log(rawLogs);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
catch (error) {
|
|
844
|
-
console.error(chalk_1.default.red('✗ Failed to read logs'));
|
|
845
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}\n`));
|
|
846
|
-
throw error;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
async function handleAgentUninstall(options, logger, configManager) {
|
|
850
|
-
if (!(0, sudo_checker_1.checkSudoPermissions)()) {
|
|
851
|
-
console.log(chalk_1.default.redBright("Please run this command with administrator priviledges (i.e. sudo)"));
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
const config = configManager.getConfig();
|
|
855
|
-
if (!config.agentInstallationType) {
|
|
856
|
-
console.log(chalk_1.default.yellow('⚠ Agent installation type not found in config'));
|
|
857
|
-
console.log(chalk_1.default.gray(' No agent installation detected.\n'));
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
console.log(chalk_1.default.blue.bold('\n═══════════════════════════════════════════'));
|
|
861
|
-
console.log(chalk_1.default.blue.bold(' Edgible Agent Uninstallation'));
|
|
862
|
-
console.log(chalk_1.default.blue.bold('═══════════════════════════════════════════\n'));
|
|
863
|
-
console.log(chalk_1.default.gray(`Installation Type: ${config.agentInstallationType}`));
|
|
864
|
-
if (config.agentServiceName) {
|
|
865
|
-
console.log(chalk_1.default.gray(`Service Name: ${config.agentServiceName}`));
|
|
866
|
-
}
|
|
867
|
-
if (config.agentContainerName) {
|
|
868
|
-
console.log(chalk_1.default.gray(`Container Name: ${config.agentContainerName}`));
|
|
869
|
-
}
|
|
870
|
-
if (config.agentDataPath) {
|
|
871
|
-
console.log(chalk_1.default.gray(`Data Path: ${config.agentDataPath}`));
|
|
872
|
-
}
|
|
873
|
-
console.log('');
|
|
874
|
-
// Confirm uninstallation unless --force is used
|
|
875
|
-
if (!options.force) {
|
|
876
|
-
const { confirm } = await inquirer_1.default.prompt([
|
|
877
|
-
{
|
|
878
|
-
type: 'confirm',
|
|
879
|
-
name: 'confirm',
|
|
880
|
-
message: 'Are you sure you want to uninstall the agent?',
|
|
881
|
-
default: false
|
|
882
|
-
}
|
|
883
|
-
]);
|
|
884
|
-
if (!confirm) {
|
|
885
|
-
console.log(chalk_1.default.gray('\nUninstallation cancelled.\n'));
|
|
886
|
-
return;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
logger.info('Uninstalling agent', { installationType: config.agentInstallationType });
|
|
890
|
-
// Get daemon manager
|
|
891
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.fromConfig(config.agentInstallationType);
|
|
892
|
-
if (!daemonManager) {
|
|
893
|
-
console.error(chalk_1.default.red('✗ Could not create daemon manager'));
|
|
894
|
-
console.error(chalk_1.default.red(` Invalid installation type: ${config.agentInstallationType}\n`));
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
// Step 1: Uninstall daemon
|
|
898
|
-
console.log(chalk_1.default.blue('🔧 Uninstalling Daemon'));
|
|
899
|
-
try {
|
|
900
|
-
await daemonManager.uninstall();
|
|
901
|
-
console.log(chalk_1.default.green('✓ Daemon uninstalled successfully\n'));
|
|
902
|
-
}
|
|
903
|
-
catch (error) {
|
|
904
|
-
console.error(chalk_1.default.red('✗ Failed to uninstall daemon'));
|
|
905
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}\n`));
|
|
906
|
-
// Continue with cleanup even if daemon uninstall partially failed
|
|
907
|
-
}
|
|
908
|
-
// Step 2: Optionally remove agent files and configuration
|
|
909
|
-
let removeFiles = options.removeFiles;
|
|
910
|
-
if (removeFiles === undefined && !options.force) {
|
|
911
|
-
const { removeFilesAnswer } = await inquirer_1.default.prompt([
|
|
912
|
-
{
|
|
913
|
-
type: 'confirm',
|
|
914
|
-
name: 'removeFilesAnswer',
|
|
915
|
-
message: 'Do you want to remove agent files and configuration?',
|
|
916
|
-
default: false
|
|
917
|
-
}
|
|
918
|
-
]);
|
|
919
|
-
removeFiles = removeFilesAnswer;
|
|
920
|
-
}
|
|
921
|
-
if (removeFiles) {
|
|
922
|
-
console.log(chalk_1.default.blue('🗑️ Removing Agent Files'));
|
|
923
|
-
const agentDataPath = config.agentDataPath || PathResolver_1.PathResolver.resolveAgentConfigPath(config.agentInstallationType);
|
|
924
|
-
const agentConfigPath = PathResolver_1.PathResolver.resolveAgentConfigPath(config.agentInstallationType);
|
|
925
|
-
try {
|
|
926
|
-
// Remove agent data directory if it exists
|
|
927
|
-
if (agentDataPath && fs.existsSync(agentDataPath)) {
|
|
928
|
-
await fsPromises.rm(agentDataPath, { recursive: true, force: true });
|
|
929
|
-
console.log(chalk_1.default.green(`✓ Removed agent data directory: ${agentDataPath}`));
|
|
930
|
-
}
|
|
931
|
-
// Also try removing config path if different
|
|
932
|
-
if (agentConfigPath !== agentDataPath && fs.existsSync(agentConfigPath)) {
|
|
933
|
-
await fsPromises.rm(agentConfigPath, { recursive: true, force: true });
|
|
934
|
-
console.log(chalk_1.default.green(`✓ Removed agent config directory: ${agentConfigPath}`));
|
|
935
|
-
}
|
|
936
|
-
console.log('');
|
|
937
|
-
}
|
|
938
|
-
catch (error) {
|
|
939
|
-
console.warn(chalk_1.default.yellow('⚠ Could not remove all agent files'));
|
|
940
|
-
console.warn(chalk_1.default.yellow(` ${error instanceof Error ? error.message : String(error)}`));
|
|
941
|
-
console.warn(chalk_1.default.gray(' You may need to remove them manually with appropriate permissions\n'));
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
console.log(chalk_1.default.gray(' Agent files and configuration preserved\n'));
|
|
946
|
-
}
|
|
947
|
-
// Step 3: Clean up CLI config
|
|
948
|
-
console.log(chalk_1.default.blue('🧹 Cleaning Up Configuration'));
|
|
949
|
-
try {
|
|
950
|
-
// Note: ConfigManager filters out undefined values, so fields may remain in config.json
|
|
951
|
-
// However, the daemon is uninstalled which is the important part
|
|
952
|
-
// The installation type check will fail if agentInstallationType is undefined,
|
|
953
|
-
// effectively treating it as uninstalled
|
|
954
|
-
console.log(chalk_1.default.green('✓ CLI configuration cleaned up\n'));
|
|
955
|
-
console.log(chalk_1.default.gray(' Note: Agent installation fields may remain in config.json'));
|
|
956
|
-
console.log(chalk_1.default.gray(' but the agent is uninstalled and will not be used.\n'));
|
|
957
|
-
}
|
|
958
|
-
catch (error) {
|
|
959
|
-
console.warn(chalk_1.default.yellow('⚠ Could not clean up CLI configuration'));
|
|
960
|
-
console.warn(chalk_1.default.yellow(` ${error instanceof Error ? error.message : String(error)}\n`));
|
|
961
|
-
}
|
|
962
|
-
console.log(chalk_1.default.blue.bold('═══════════════════════════════════════════'));
|
|
963
|
-
console.log(chalk_1.default.green.bold(' ✓ Uninstallation Complete!'));
|
|
964
|
-
console.log(chalk_1.default.blue.bold('═══════════════════════════════════════════\n'));
|
|
965
|
-
if (!removeFiles) {
|
|
966
|
-
console.log(chalk_1.default.gray('Note: Agent files and configuration were preserved.'));
|
|
967
|
-
console.log(chalk_1.default.gray('To remove them, run: edgible agent uninstall --remove-files\n'));
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
async function handleAgentSetLogLevel(options, logger, configManager, agentManager) {
|
|
971
|
-
const validLevels = ['debug', 'info', 'warn', 'error'];
|
|
972
|
-
let logLevel;
|
|
973
|
-
if (options.level) {
|
|
974
|
-
const level = options.level.toLowerCase();
|
|
975
|
-
if (!validLevels.includes(level)) {
|
|
976
|
-
console.error(chalk_1.default.red(`✗ Invalid log level: ${options.level}`));
|
|
977
|
-
console.error(chalk_1.default.red(` Valid levels are: ${validLevels.join(', ')}\n`));
|
|
978
|
-
return;
|
|
979
|
-
}
|
|
980
|
-
logLevel = level;
|
|
981
|
-
}
|
|
982
|
-
else {
|
|
983
|
-
// Interactive selection
|
|
984
|
-
const { selectedLevel } = await inquirer_1.default.prompt([
|
|
985
|
-
{
|
|
986
|
-
type: 'list',
|
|
987
|
-
name: 'selectedLevel',
|
|
988
|
-
message: 'Select log level:',
|
|
989
|
-
choices: validLevels.map(level => ({
|
|
990
|
-
name: level.charAt(0).toUpperCase() + level.slice(1),
|
|
991
|
-
value: level
|
|
992
|
-
})),
|
|
993
|
-
default: 'info'
|
|
994
|
-
}
|
|
995
|
-
]);
|
|
996
|
-
logLevel = selectedLevel;
|
|
997
|
-
}
|
|
998
|
-
try {
|
|
999
|
-
// Determine the correct config file path based on installation type
|
|
1000
|
-
const userConfig = configManager.getConfig();
|
|
1001
|
-
const configFilePath = PathResolver_1.PathResolver.resolveAgentConfigFilePath(userConfig.agentInstallationType);
|
|
1002
|
-
if (!fs.existsSync(configFilePath)) {
|
|
1003
|
-
console.error(chalk_1.default.red('✗ Agent configuration file not found'));
|
|
1004
|
-
console.error(chalk_1.default.red(` Expected at: ${configFilePath}`));
|
|
1005
|
-
console.error(chalk_1.default.red(' Run "edgible agent install" to install the agent first\n'));
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
const configData = await fsPromises.readFile(configFilePath, 'utf8');
|
|
1009
|
-
const agentConfig = JSON.parse(configData);
|
|
1010
|
-
// Check if log level is already set to this value
|
|
1011
|
-
if (agentConfig.logLevel === logLevel) {
|
|
1012
|
-
console.log(chalk_1.default.yellow(`⚠ Log level is already set to: ${logLevel}\n`));
|
|
1013
|
-
return;
|
|
1014
|
-
}
|
|
1015
|
-
// Update log level
|
|
1016
|
-
agentConfig.logLevel = logLevel;
|
|
1017
|
-
// Write back to file
|
|
1018
|
-
await fsPromises.writeFile(configFilePath, JSON.stringify(agentConfig, null, 2), 'utf8');
|
|
1019
|
-
logger.info('Agent log level updated', { logLevel, configFilePath });
|
|
1020
|
-
console.log(chalk_1.default.green(`✓ Log level set to: ${logLevel}`));
|
|
1021
|
-
console.log(chalk_1.default.gray(` Updated: ${configFilePath}\n`));
|
|
1022
|
-
// Restart agent if it's installed and running (unless --no-restart is specified)
|
|
1023
|
-
const shouldRestart = options.restart !== false && userConfig.agentInstallationType;
|
|
1024
|
-
if (shouldRestart && userConfig.agentInstallationType) {
|
|
1025
|
-
try {
|
|
1026
|
-
const daemonManager = DaemonManagerFactory_1.DaemonManagerFactory.fromConfig(userConfig.agentInstallationType);
|
|
1027
|
-
if (daemonManager) {
|
|
1028
|
-
const status = await daemonManager.status();
|
|
1029
|
-
if (status.running) {
|
|
1030
|
-
console.log(chalk_1.default.gray('\nRestarting agent to apply new log level...'));
|
|
1031
|
-
await daemonManager.restart();
|
|
1032
|
-
console.log(chalk_1.default.green('✓ Agent restarted\n'));
|
|
1033
|
-
}
|
|
1034
|
-
else {
|
|
1035
|
-
console.log(chalk_1.default.gray('\nAgent is not running. Start it with "edgible agent start" to apply the new log level.\n'));
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
catch (restartError) {
|
|
1040
|
-
console.warn(chalk_1.default.yellow('⚠ Could not restart agent automatically'));
|
|
1041
|
-
console.warn(chalk_1.default.yellow(` ${restartError instanceof Error ? restartError.message : String(restartError)}`));
|
|
1042
|
-
console.log(chalk_1.default.gray('\nPlease restart the agent manually for the log level change to take effect.\n'));
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
else {
|
|
1046
|
-
console.log(chalk_1.default.gray('\nRestart the agent for the log level change to take effect:\n'));
|
|
1047
|
-
console.log(chalk_1.default.gray(' edgible agent restart\n'));
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
catch (error) {
|
|
1051
|
-
logger.error('Failed to update log level', error);
|
|
1052
|
-
console.error(chalk_1.default.red('✗ Failed to update log level'));
|
|
1053
|
-
console.error(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}\n`));
|
|
1054
|
-
throw error;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
async function handleAgentSetup(options, logger, configManager, agentManager) {
|
|
1058
|
-
logger.info('Setting up agent dependencies and configuration');
|
|
1059
|
-
console.log(chalk_1.default.blue('\n🔧 Agent Setup'));
|
|
1060
|
-
console.log(chalk_1.default.gray('This will check and install dependencies, then configure the agent.\n'));
|
|
1061
|
-
// Step 1: Check and install dependencies
|
|
1062
|
-
console.log(chalk_1.default.blue('Step 1: Checking dependencies...\n'));
|
|
1063
|
-
const dependencyInstaller = new DependencyInstaller_1.DependencyInstaller();
|
|
1064
|
-
// Determine if we should check for wireguard-go based on mode
|
|
1065
|
-
const wireguardMode = (options.wireguardMode || 'kernel').toLowerCase();
|
|
1066
|
-
const includeWireGuardGo = wireguardMode === 'userspace';
|
|
1067
|
-
await dependencyInstaller.checkAndInstallDependencies({
|
|
1068
|
-
includeWireGuardGo,
|
|
1069
|
-
includeIptables: true,
|
|
1070
|
-
autoInstall: options.autoInstall || false
|
|
1071
|
-
});
|
|
1072
|
-
console.log(chalk_1.default.green('\n✓ Dependencies check complete\n'));
|
|
1073
|
-
// Step 2: Configure WireGuard mode
|
|
1074
|
-
let selectedMode = wireguardMode;
|
|
1075
|
-
if (!options.wireguardMode) {
|
|
1076
|
-
// Prompt user for WireGuard mode if not provided
|
|
1077
|
-
const { mode } = await inquirer_1.default.prompt([
|
|
1078
|
-
{
|
|
1079
|
-
type: 'list',
|
|
1080
|
-
name: 'mode',
|
|
1081
|
-
message: 'Select WireGuard implementation mode:',
|
|
1082
|
-
choices: [
|
|
1083
|
-
{
|
|
1084
|
-
name: 'Kernel (default, requires kernel module support)',
|
|
1085
|
-
value: 'kernel'
|
|
1086
|
-
},
|
|
1087
|
-
{
|
|
1088
|
-
name: 'Userspace (wireguard-go, works without kernel module)',
|
|
1089
|
-
value: 'userspace'
|
|
1090
|
-
}
|
|
1091
|
-
],
|
|
1092
|
-
default: 'kernel'
|
|
1093
|
-
}
|
|
1094
|
-
]);
|
|
1095
|
-
selectedMode = mode;
|
|
1096
|
-
}
|
|
1097
|
-
// Step 3: Update CLI config with WireGuard settings
|
|
1098
|
-
const currentConfig = configManager.getConfig();
|
|
1099
|
-
configManager.updateConfig({
|
|
1100
|
-
wireguardMode: selectedMode,
|
|
1101
|
-
wireguardGoBinary: options.wireguardGoBinary || 'wireguard-go'
|
|
1102
|
-
});
|
|
1103
|
-
console.log(chalk_1.default.green(`✓ WireGuard mode set to: ${selectedMode}`));
|
|
1104
|
-
if (selectedMode === 'userspace') {
|
|
1105
|
-
console.log(chalk_1.default.gray(` wireguard-go binary: ${options.wireguardGoBinary || 'wireguard-go'}`));
|
|
1106
|
-
}
|
|
1107
|
-
// Step 4: Update agent config
|
|
1108
|
-
console.log(chalk_1.default.blue('\nStep 2: Updating agent configuration...\n'));
|
|
1109
|
-
// Check if device credentials exist
|
|
1110
|
-
if (!currentConfig.deviceId || !currentConfig.devicePassword) {
|
|
1111
|
-
console.log(chalk_1.default.yellow('⚠ No device credentials found in CLI config.'));
|
|
1112
|
-
console.log(chalk_1.default.yellow('⚠ You will need to run "edgible agent start" to set up device credentials.'));
|
|
1113
|
-
console.log(chalk_1.default.yellow('⚠ The agent config will be created with default values.\n'));
|
|
1114
|
-
}
|
|
1115
|
-
try {
|
|
1116
|
-
await agentManager.updateAgentConfig();
|
|
1117
|
-
console.log(chalk_1.default.green('✓ Agent configuration updated\n'));
|
|
1118
|
-
}
|
|
1119
|
-
catch (error) {
|
|
1120
|
-
// If update fails due to missing credentials, create a basic config
|
|
1121
|
-
if (error instanceof Error && error.message.includes('No device credentials')) {
|
|
1122
|
-
console.log(chalk_1.default.yellow('⚠ Creating agent config with default values (device credentials will be set when you start the agent)\n'));
|
|
1123
|
-
// Create a basic config file
|
|
1124
|
-
const agentConfigPath = path.join(os.homedir(), '.edgible', 'agent', 'agent.config.json');
|
|
1125
|
-
const defaultConfig = {
|
|
1126
|
-
deviceId: 'your-device-id',
|
|
1127
|
-
devicePassword: 'your-device-password',
|
|
1128
|
-
deviceType: 'serving',
|
|
1129
|
-
apiBaseUrl: (0, urls_1.getApiBaseUrl)(),
|
|
1130
|
-
organizationId: currentConfig.organizationId,
|
|
1131
|
-
firewallEnabled: true,
|
|
1132
|
-
pollingInterval: 60000,
|
|
1133
|
-
healthCheckTimeout: 5000,
|
|
1134
|
-
maxRetries: 3,
|
|
1135
|
-
logLevel: 'info',
|
|
1136
|
-
updateEnabled: true,
|
|
1137
|
-
updateCheckInterval: 3600000,
|
|
1138
|
-
wireguardMode: selectedMode,
|
|
1139
|
-
wireguardGoBinary: options.wireguardGoBinary || 'wireguard-go'
|
|
1140
|
-
};
|
|
1141
|
-
const configDir = path.dirname(agentConfigPath);
|
|
1142
|
-
await fsPromises.mkdir(configDir, { recursive: true });
|
|
1143
|
-
await fsPromises.writeFile(agentConfigPath, JSON.stringify(defaultConfig, null, 2));
|
|
1144
|
-
console.log(chalk_1.default.green('✓ Agent configuration file created\n'));
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
throw error;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
console.log(chalk_1.default.green('✓ Agent setup complete!\n'));
|
|
1151
|
-
console.log(chalk_1.default.blue('Next steps:'));
|
|
1152
|
-
console.log(chalk_1.default.gray(' 1. Run "edgible agent start" to start the agent'));
|
|
1153
|
-
console.log(chalk_1.default.gray(' 2. The agent will use the configured WireGuard mode'));
|
|
1154
|
-
if (selectedMode === 'userspace') {
|
|
1155
|
-
console.log(chalk_1.default.gray(' 3. Ensure wireguard-go is available in your PATH'));
|
|
1156
|
-
}
|
|
1157
|
-
console.log('');
|
|
1158
|
-
}
|
|
1159
|
-
//# sourceMappingURL=agent-handlers.js.map
|