@docker-digital/dockernet-agent 0.0.1

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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -0
  3. package/dist/agent/agent.module.d.ts +2 -0
  4. package/dist/agent/agent.module.js +47 -0
  5. package/dist/agent/agent.module.js.map +1 -0
  6. package/dist/agent/commands/agent.command.d.ts +58 -0
  7. package/dist/agent/commands/agent.command.js +417 -0
  8. package/dist/agent/commands/agent.command.js.map +1 -0
  9. package/dist/agent/services/api.service.d.ts +13 -0
  10. package/dist/agent/services/api.service.js +116 -0
  11. package/dist/agent/services/api.service.js.map +1 -0
  12. package/dist/agent/services/config.service.d.ts +28 -0
  13. package/dist/agent/services/config.service.js +100 -0
  14. package/dist/agent/services/config.service.js.map +1 -0
  15. package/dist/agent/services/docker-event.service.d.ts +44 -0
  16. package/dist/agent/services/docker-event.service.js +141 -0
  17. package/dist/agent/services/docker-event.service.js.map +1 -0
  18. package/dist/agent/services/docker.service.d.ts +16 -0
  19. package/dist/agent/services/docker.service.js +170 -0
  20. package/dist/agent/services/docker.service.js.map +1 -0
  21. package/dist/agent/services/event-websocket-client.service.d.ts +49 -0
  22. package/dist/agent/services/event-websocket-client.service.js +248 -0
  23. package/dist/agent/services/event-websocket-client.service.js.map +1 -0
  24. package/dist/agent/services/event.service.d.ts +27 -0
  25. package/dist/agent/services/event.service.js +242 -0
  26. package/dist/agent/services/event.service.js.map +1 -0
  27. package/dist/agent/services/log.service.d.ts +19 -0
  28. package/dist/agent/services/log.service.js +176 -0
  29. package/dist/agent/services/log.service.js.map +1 -0
  30. package/dist/agent/services/machine.service.d.ts +15 -0
  31. package/dist/agent/services/machine.service.js +148 -0
  32. package/dist/agent/services/machine.service.js.map +1 -0
  33. package/dist/agent/services/profile.service.d.ts +33 -0
  34. package/dist/agent/services/profile.service.js +438 -0
  35. package/dist/agent/services/profile.service.js.map +1 -0
  36. package/dist/agent/services/volume-sync.service.d.ts +9 -0
  37. package/dist/agent/services/volume-sync.service.js +87 -0
  38. package/dist/agent/services/volume-sync.service.js.map +1 -0
  39. package/dist/agent/services/websocket-client.service.d.ts +48 -0
  40. package/dist/agent/services/websocket-client.service.js +278 -0
  41. package/dist/agent/services/websocket-client.service.js.map +1 -0
  42. package/dist/app.module.d.ts +2 -0
  43. package/dist/app.module.js +31 -0
  44. package/dist/app.module.js.map +1 -0
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +19 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/main.d.ts +2 -0
  49. package/dist/main.js +12 -0
  50. package/dist/main.js.map +1 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -0
  52. package/package.json +103 -0
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var DockerService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DockerService = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const Docker = require("dockerode");
16
+ const fs = require("fs-extra");
17
+ const path = require("path");
18
+ const child_process_1 = require("child_process");
19
+ const util_1 = require("util");
20
+ const config_service_1 = require("./config.service");
21
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
22
+ let DockerService = DockerService_1 = class DockerService {
23
+ constructor(configService) {
24
+ this.configService = configService;
25
+ this.logger = new common_1.Logger(DockerService_1.name);
26
+ this.docker = new Docker();
27
+ }
28
+ async checkDependencies() {
29
+ try {
30
+ await this.docker.ping();
31
+ }
32
+ catch (error) {
33
+ throw new Error('Docker is not available or not running');
34
+ }
35
+ }
36
+ async getContainerStatus(containerName) {
37
+ try {
38
+ const container = this.docker.getContainer(containerName);
39
+ const inspect = await container.inspect();
40
+ return inspect.State.Status.toLowerCase();
41
+ }
42
+ catch (error) {
43
+ if (error.statusCode === 404) {
44
+ return null;
45
+ }
46
+ this.logger.error(`Error getting container status for ${containerName}: ${error.message}`);
47
+ return null;
48
+ }
49
+ }
50
+ async getServiceStatus(serviceName, profileDir, profileId) {
51
+ try {
52
+ const composeFile = path.join(profileDir, `docker-compose_${profileId}.yaml`);
53
+ if (fs.existsSync(composeFile)) {
54
+ const containers = await this.docker.listContainers({
55
+ all: true,
56
+ filters: {
57
+ label: [
58
+ `com.docker.compose.service=${serviceName}`,
59
+ `com.docker.compose.project=${profileId}`,
60
+ ],
61
+ },
62
+ });
63
+ if (containers.length > 0) {
64
+ const container = containers[0];
65
+ const status = container.State || container.Status || 'unknown';
66
+ const normalizedStatus = status.toLowerCase();
67
+ this.logger.debug(`Service ${serviceName} in profile ${profileId}: Docker State=${container.State}, Status=${container.Status}, normalized=${normalizedStatus}`);
68
+ return normalizedStatus;
69
+ }
70
+ const containersByService = await this.docker.listContainers({
71
+ all: true,
72
+ filters: {
73
+ label: [`com.docker.compose.service=${serviceName}`],
74
+ },
75
+ });
76
+ if (containersByService.length > 0) {
77
+ const container = containersByService[0];
78
+ const status = container.State || container.Status || 'unknown';
79
+ const normalizedStatus = status.toLowerCase();
80
+ this.logger.debug(`Service ${serviceName} (by service label only): Docker State=${container.State}, Status=${container.Status}, normalized=${normalizedStatus}`);
81
+ return normalizedStatus;
82
+ }
83
+ }
84
+ const allContainers = await this.docker.listContainers({
85
+ all: true,
86
+ });
87
+ const exactMatch = allContainers.find((c) => c.Names.some((n) => n.includes(`${profileId}-${serviceName}`) ||
88
+ n === `/${profileId}-${serviceName}-1` ||
89
+ n === `/${profileId}-${serviceName}`));
90
+ if (exactMatch) {
91
+ const status = exactMatch.State || exactMatch.Status || 'unknown';
92
+ const normalizedStatus = status.toLowerCase();
93
+ this.logger.debug(`Service ${serviceName} (exact match): Docker State=${exactMatch.State}, Status=${exactMatch.Status}, normalized=${normalizedStatus}`);
94
+ return normalizedStatus;
95
+ }
96
+ const partialMatch = allContainers.find((c) => c.Names.some((n) => n.includes(serviceName) || n.includes(profileId)));
97
+ if (partialMatch) {
98
+ const status = partialMatch.State || partialMatch.Status || 'unknown';
99
+ const normalizedStatus = status.toLowerCase();
100
+ this.logger.debug(`Service ${serviceName} (partial match): Docker State=${partialMatch.State}, Status=${partialMatch.Status}, normalized=${normalizedStatus}`);
101
+ return normalizedStatus;
102
+ }
103
+ return 'unknown';
104
+ }
105
+ catch (error) {
106
+ this.logger.error(`Error getting service status for ${serviceName} in profile ${profileId}: ${error.message}`);
107
+ return 'unknown';
108
+ }
109
+ }
110
+ async getContainerLogs(containerName, tail = 50) {
111
+ try {
112
+ const container = this.docker.getContainer(containerName);
113
+ const stream = container.logs({
114
+ follow: true,
115
+ stdout: true,
116
+ stderr: true,
117
+ tail,
118
+ timestamps: true,
119
+ });
120
+ return stream;
121
+ }
122
+ catch (error) {
123
+ this.logger.error(`Error getting logs for container ${containerName}: ${error.message}`);
124
+ throw error;
125
+ }
126
+ }
127
+ async listContainers(filters) {
128
+ return this.docker.listContainers({ all: true, filters });
129
+ }
130
+ async dockerLogin(registryUrl, username, password) {
131
+ try {
132
+ const command = `echo "${password}" | docker login "${registryUrl}" -u "${username}" --password-stdin`;
133
+ const { stdout, stderr } = await execAsync(command);
134
+ if (stderr && !stderr.includes('Login Succeeded')) {
135
+ this.logger.warn(`Docker login warnings: ${stderr}`);
136
+ }
137
+ this.logger.log(`Docker login successful for registry: ${registryUrl}`);
138
+ return true;
139
+ }
140
+ catch (error) {
141
+ this.logger.error(`Docker login failed for registry ${registryUrl}: ${error.message}`);
142
+ return false;
143
+ }
144
+ }
145
+ async getProfileContainers(profileId) {
146
+ try {
147
+ const containers = await this.docker.listContainers({
148
+ all: true,
149
+ filters: {
150
+ label: [`com.docker.compose.project=${profileId}`],
151
+ },
152
+ });
153
+ return containers;
154
+ }
155
+ catch (error) {
156
+ this.logger.error(`Error getting containers for profile ${profileId}: ${error.message}`);
157
+ return [];
158
+ }
159
+ }
160
+ async isContainerRunning(containerName) {
161
+ const status = await this.getContainerStatus(containerName);
162
+ return status === 'running';
163
+ }
164
+ };
165
+ exports.DockerService = DockerService;
166
+ exports.DockerService = DockerService = DockerService_1 = __decorate([
167
+ (0, common_1.Injectable)(),
168
+ __metadata("design:paramtypes", [config_service_1.ConfigService])
169
+ ], DockerService);
170
+ //# sourceMappingURL=docker.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker.service.js","sourceRoot":"","sources":["../../../src/agent/services/docker.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,oCAAoC;AACpC,+BAA+B;AAC/B,6BAA6B;AAC7B,iDAAqC;AACrC,+BAAiC;AACjC,qDAAiD;AAEjD,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAG3B,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAIxB,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAH/B,WAAM,GAAG,IAAI,eAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAC;QAIvD,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;I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AAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,oCAAoC,WAAW,KAAK,KAAK,CAAC,OAAO,EAAE,CACpE,CAAC;YACF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAKD,KAAK,CAAC,oBAAoB,CACxB,SAAiB;QAEjB,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;gBAClD,GAAG,EAAE,IAAI;gBACT,OAAO,EAAE;oBACP,KAAK,EAAE,CAAC,8BAA8B,SAAS,EAAE,CAAC;iBACnD;aACF,CAAC,CAAC;YACH,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,wCAAwC,SAAS,KAAK,KAAK,CAAC,OAAO,EAAE,CACtE,CAAC;YACF,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAKD,KAAK,CAAC,kBAAkB,CAAC,aAAqB;QAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;QAC5D,OAAO,MAAM,KAAK,SAAS,CAAC;IAC9B,CAAC;CACF,CAAA;AArNY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAKwB,8BAAa;GAJrC,aAAa,CAqNzB"}
@@ -0,0 +1,49 @@
1
+ import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { ConfigService } from './config.service';
3
+ export interface EventData {
4
+ key: string;
5
+ type: string;
6
+ profile_id: string;
7
+ workspace_id?: string;
8
+ status: string;
9
+ is_executed: boolean;
10
+ error?: string;
11
+ user_id?: string;
12
+ created_at?: string | Date;
13
+ updated_at?: string | Date;
14
+ }
15
+ export interface EventUpdateMessage {
16
+ type: 'event_update';
17
+ machine_id: string;
18
+ event: EventData;
19
+ }
20
+ export type EventHandler = (event: EventData) => void;
21
+ export declare class EventWebSocketClientService implements OnModuleInit, OnModuleDestroy {
22
+ private configService;
23
+ private readonly logger;
24
+ private socket;
25
+ private isConnected;
26
+ private reconnectAttempts;
27
+ private readonly maxReconnectAttempts;
28
+ private readonly baseReconnectDelay;
29
+ private readonly maxReconnectDelay;
30
+ private eventHandlers;
31
+ private connectionPromise;
32
+ private pendingConnectionPromise;
33
+ private currentMachineId;
34
+ private isSubscribed;
35
+ constructor(configService: ConfigService);
36
+ onModuleInit(): Promise<void>;
37
+ connect(machineId: string): Promise<void>;
38
+ private setupSocketHandlers;
39
+ private subscribeToEvents;
40
+ onEvent(handler: EventHandler): void;
41
+ removeEventHandler(handler: EventHandler): void;
42
+ clearEventHandlers(): void;
43
+ private getWebSocketUrl;
44
+ disconnect(): void;
45
+ onModuleDestroy(): void;
46
+ isWebSocketConnected(): boolean;
47
+ isSubscribedToEvents(): boolean;
48
+ getCurrentMachineId(): string | null;
49
+ }
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var EventWebSocketClientService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.EventWebSocketClientService = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const socket_io_client_1 = require("socket.io-client");
16
+ const config_service_1 = require("./config.service");
17
+ let EventWebSocketClientService = EventWebSocketClientService_1 = class EventWebSocketClientService {
18
+ constructor(configService) {
19
+ this.configService = configService;
20
+ this.logger = new common_1.Logger(EventWebSocketClientService_1.name);
21
+ this.socket = null;
22
+ this.isConnected = false;
23
+ this.reconnectAttempts = 0;
24
+ this.maxReconnectAttempts = 10;
25
+ this.baseReconnectDelay = 1000;
26
+ this.maxReconnectDelay = 30000;
27
+ this.eventHandlers = [];
28
+ this.connectionPromise = null;
29
+ this.pendingConnectionPromise = null;
30
+ this.currentMachineId = null;
31
+ this.isSubscribed = false;
32
+ }
33
+ async onModuleInit() {
34
+ }
35
+ async connect(machineId) {
36
+ this.currentMachineId = machineId;
37
+ if (this.isConnected && this.socket?.connected) {
38
+ this.logger.debug('Event WebSocket already connected');
39
+ this.subscribeToEvents(machineId);
40
+ return;
41
+ }
42
+ if (this.pendingConnectionPromise) {
43
+ this.logger.debug('Connection attempt already in progress, waiting...');
44
+ return this.pendingConnectionPromise;
45
+ }
46
+ try {
47
+ const wsUrl = await this.getWebSocketUrl();
48
+ const apiKey = await this.configService.getApiKey();
49
+ this.logger.log(`Connecting to Event WebSocket server: ${wsUrl}`);
50
+ this.pendingConnectionPromise = new Promise((resolve, reject) => {
51
+ const connectionTimeout = setTimeout(() => {
52
+ if (!this.isConnected && this.connectionPromise) {
53
+ this.logger.warn('Event WebSocket connection timeout');
54
+ this.connectionPromise = null;
55
+ this.pendingConnectionPromise = null;
56
+ reject(new Error('Connection timeout'));
57
+ }
58
+ }, 10000);
59
+ this.connectionPromise = {
60
+ resolve,
61
+ reject,
62
+ timeout: connectionTimeout,
63
+ };
64
+ if (this.socket) {
65
+ if (this.socket.connected) {
66
+ this.logger.debug('Socket already connected, reusing existing connection');
67
+ this.setupSocketHandlers(machineId);
68
+ clearTimeout(connectionTimeout);
69
+ this.connectionPromise.resolve();
70
+ this.connectionPromise = null;
71
+ this.pendingConnectionPromise = null;
72
+ return;
73
+ }
74
+ else {
75
+ this.logger.debug('Cleaning up disconnected socket before reconnecting...');
76
+ this.socket.removeAllListeners();
77
+ this.socket.disconnect();
78
+ }
79
+ this.socket = null;
80
+ }
81
+ this.socket = (0, socket_io_client_1.io)(`${wsUrl}/v1/api/agent/ws/agent-events`, {
82
+ auth: {
83
+ api_key: apiKey,
84
+ },
85
+ reconnection: true,
86
+ reconnectionDelay: this.baseReconnectDelay,
87
+ reconnectionDelayMax: this.maxReconnectDelay,
88
+ reconnectionAttempts: this.maxReconnectAttempts,
89
+ timeout: 10000,
90
+ transports: ['websocket', 'polling'],
91
+ path: '/socket.io/',
92
+ });
93
+ this.setupSocketHandlers(machineId);
94
+ });
95
+ return this.pendingConnectionPromise;
96
+ }
97
+ catch (error) {
98
+ this.connectionPromise = null;
99
+ this.pendingConnectionPromise = null;
100
+ this.logger.error(`Failed to connect to Event WebSocket server: ${error.message}`);
101
+ throw error;
102
+ }
103
+ }
104
+ setupSocketHandlers(machineId) {
105
+ if (!this.socket) {
106
+ return;
107
+ }
108
+ this.socket.on('connect', () => {
109
+ this.isConnected = true;
110
+ this.reconnectAttempts = 0;
111
+ this.logger.log(`Event WebSocket connected (socket ID: ${this.socket?.id})`);
112
+ if (this.connectionPromise) {
113
+ clearTimeout(this.connectionPromise.timeout);
114
+ this.connectionPromise.resolve();
115
+ this.connectionPromise = null;
116
+ this.pendingConnectionPromise = null;
117
+ }
118
+ this.subscribeToEvents(machineId);
119
+ });
120
+ this.socket.on('connect_error', (error) => {
121
+ this.logger.error(`Event WebSocket connection error: ${error.message}`);
122
+ this.isConnected = false;
123
+ if (this.connectionPromise) {
124
+ clearTimeout(this.connectionPromise.timeout);
125
+ this.connectionPromise.reject(new Error(error.message || 'Connection failed'));
126
+ this.connectionPromise = null;
127
+ this.pendingConnectionPromise = null;
128
+ }
129
+ });
130
+ this.socket.on('disconnect', (reason) => {
131
+ if (reason === 'io client disconnect') {
132
+ this.logger.debug(`Event WebSocket disconnected: ${reason}`);
133
+ }
134
+ else {
135
+ this.logger.warn(`Event WebSocket disconnected: ${reason}`);
136
+ }
137
+ this.isConnected = false;
138
+ this.isSubscribed = false;
139
+ });
140
+ this.socket.on('error', (error) => {
141
+ this.logger.error(`Event WebSocket error: ${error.message}`);
142
+ });
143
+ this.socket.on('reconnect_attempt', (attemptNumber) => {
144
+ this.reconnectAttempts = attemptNumber;
145
+ this.logger.debug(`Event WebSocket reconnection attempt ${attemptNumber}`);
146
+ });
147
+ this.socket.on('reconnect', (attemptNumber) => {
148
+ this.logger.log(`Event WebSocket reconnected after ${attemptNumber} attempts`);
149
+ if (this.currentMachineId) {
150
+ this.subscribeToEvents(this.currentMachineId);
151
+ }
152
+ });
153
+ this.socket.on('reconnect_failed', () => {
154
+ this.logger.error('Event WebSocket reconnection failed');
155
+ this.isConnected = false;
156
+ });
157
+ this.socket.on('event_update', (data) => {
158
+ this.logger.log(`Received event update: ${data.event?.type || 'unknown'} for machine ${data.machine_id || 'unknown'}`);
159
+ this.logger.debug(`Event details: ${JSON.stringify(data)}`);
160
+ if (data.event) {
161
+ if (data.machine_id && data.machine_id !== machineId) {
162
+ this.logger.warn(`Event machine_id (${data.machine_id}) does not match subscribed machine_id (${machineId})`);
163
+ }
164
+ this.eventHandlers.forEach((handler) => {
165
+ try {
166
+ handler(data.event);
167
+ }
168
+ catch (error) {
169
+ this.logger.error(`Error in event handler: ${error.message}`);
170
+ }
171
+ });
172
+ }
173
+ });
174
+ this.socket.on('subscribed', (data) => {
175
+ this.isSubscribed = true;
176
+ this.logger.log(`Successfully subscribed to events for machine: ${data.machine_id || 'unknown'}`);
177
+ this.logger.debug(`Subscription confirmation: ${JSON.stringify(data)}`);
178
+ });
179
+ this.socket.on('connected', (data) => {
180
+ this.logger.debug(`Event WebSocket connected: ${JSON.stringify(data)}`);
181
+ });
182
+ }
183
+ subscribeToEvents(machineId) {
184
+ if (!this.socket || !this.socket.connected) {
185
+ this.logger.warn('Cannot subscribe to events: socket not connected');
186
+ this.isSubscribed = false;
187
+ return;
188
+ }
189
+ this.logger.log(`Subscribing to events for machine: ${machineId}`);
190
+ this.isSubscribed = false;
191
+ this.socket.emit('subscribe_events', {
192
+ type: 'subscribe_events',
193
+ machine_id: machineId,
194
+ });
195
+ }
196
+ onEvent(handler) {
197
+ this.eventHandlers.push(handler);
198
+ this.logger.debug(`Registered event handler (total: ${this.eventHandlers.length})`);
199
+ }
200
+ removeEventHandler(handler) {
201
+ const index = this.eventHandlers.indexOf(handler);
202
+ if (index > -1) {
203
+ this.eventHandlers.splice(index, 1);
204
+ this.logger.debug(`Removed event handler (total: ${this.eventHandlers.length})`);
205
+ }
206
+ }
207
+ clearEventHandlers() {
208
+ this.eventHandlers = [];
209
+ this.logger.debug('Cleared all event handlers');
210
+ }
211
+ async getWebSocketUrl() {
212
+ const serverUrl = this.configService.serverUrl;
213
+ let wsUrl = serverUrl.replace(/^http/, 'ws');
214
+ wsUrl = wsUrl.replace(/\/$/, '');
215
+ return wsUrl;
216
+ }
217
+ disconnect() {
218
+ if (this.socket && (this.socket.connected || this.isConnected)) {
219
+ this.logger.log('Disconnecting Event WebSocket...');
220
+ }
221
+ else {
222
+ this.logger.debug('Disconnect called but no active connection');
223
+ }
224
+ this.isConnected = false;
225
+ if (this.socket) {
226
+ this.socket.disconnect();
227
+ this.socket = null;
228
+ }
229
+ }
230
+ onModuleDestroy() {
231
+ this.logger.debug('onModuleDestroy called - keeping Event WebSocket connection alive for daemon mode');
232
+ }
233
+ isWebSocketConnected() {
234
+ return this.isConnected && this.socket?.connected === true;
235
+ }
236
+ isSubscribedToEvents() {
237
+ return (this.isSubscribed && this.isConnected && this.socket?.connected === true);
238
+ }
239
+ getCurrentMachineId() {
240
+ return this.currentMachineId;
241
+ }
242
+ };
243
+ exports.EventWebSocketClientService = EventWebSocketClientService;
244
+ exports.EventWebSocketClientService = EventWebSocketClientService = EventWebSocketClientService_1 = __decorate([
245
+ (0, common_1.Injectable)(),
246
+ __metadata("design:paramtypes", [config_service_1.ConfigService])
247
+ ], EventWebSocketClientService);
248
+ //# sourceMappingURL=event-websocket-client.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-websocket-client.service.js","sourceRoot":"","sources":["../../../src/agent/services/event-websocket-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKwB;AACxB,uDAA8C;AAC9C,qDAAiD;AAwB1C,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAoBtC,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAjB/B,WAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;QAC/D,WAAM,GAAkB,IAAI,CAAC;QAC7B,gBAAW,GAAG,KAAK,CAAC;QACpB,sBAAiB,GAAG,CAAC,CAAC;QACb,yBAAoB,GAAG,EAAE,CAAC;QAC1B,uBAAkB,GAAG,IAAI,CAAC;QAC1B,sBAAiB,GAAG,KAAK,CAAC;QACnC,kBAAa,GAAmB,EAAE,CAAC;QACnC,sBAAiB,GAId,IAAI,CAAC;QACR,6BAAwB,GAAyB,IAAI,CAAC;QACtD,qBAAgB,GAAkB,IAAI,CAAC;QACvC,iBAAY,GAAY,KAAK,CAAC;IAEa,CAAC;IAEpD,KAAK,CAAC,YAAY;IAGlB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,SAAiB;QAE7B,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAGlC,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;YAEvD,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;QAGD,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACxE,OAAO,IAAI,CAAC,wBAAwB,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,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IAC/B,CAAC;CACF,CAAA;AA3VY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;qCAqBwB,8BAAa;GApBrC,2BAA2B,CA2VvC"}
@@ -0,0 +1,27 @@
1
+ import { ApiService } from './api.service';
2
+ import { ConfigService } from './config.service';
3
+ import { ProfileService } from './profile.service';
4
+ import { WebSocketClientService } from './websocket-client.service';
5
+ import { EventWebSocketClientService } from './event-websocket-client.service';
6
+ export declare class EventService {
7
+ private apiService;
8
+ private configService;
9
+ private profileService;
10
+ private websocketClientService;
11
+ private eventWebSocketClientService;
12
+ private readonly logger;
13
+ private isPolling;
14
+ private useEventDrivenUpdates;
15
+ private isWebSocketListening;
16
+ constructor(apiService: ApiService, configService: ConfigService, profileService: ProfileService, websocketClientService: WebSocketClientService, eventWebSocketClientService: EventWebSocketClientService);
17
+ startPolling(): Promise<void>;
18
+ private startWebSocketListening;
19
+ private startPollingFallback;
20
+ private handleWebSocketEvent;
21
+ stopPolling(): void;
22
+ checkSubscriptionStatus(): void;
23
+ private pollEvents;
24
+ private handleEvent;
25
+ updateSavedProfiles(): Promise<void>;
26
+ private sleep;
27
+ }