UNPKG

@iqai/adk-cli

Version:

CLI tool for creating, running, and testing ADK-TS agents

84 lines 2.81 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HotReloadService = void 0; const common_1 = require("@nestjs/common"); let HotReloadService = class HotReloadService { clients = new Set(); keepAliveTimers = new Map(); addClient(res) { this.clients.add(res); // Remove on close res.on("close", () => { this.removeClient(res); }); // Initial comment to open stream try { res.write(": connected\n\n"); } catch { // ignore } // Keepalive to prevent proxies from closing the connection const timer = setInterval(() => { try { res.write(`: ping ${Date.now()}\n\n`); } catch { this.removeClient(res); } }, 25000); this.keepAliveTimers.set(res, timer); } removeClient(res) { if (this.keepAliveTimers.has(res)) { clearInterval(this.keepAliveTimers.get(res)); this.keepAliveTimers.delete(res); } if (this.clients.has(res)) { try { res.end(); } catch { // ignore } this.clients.delete(res); } } emit(payload) { const data = `data: ${JSON.stringify(payload)}\n\n`; for (const res of Array.from(this.clients)) { try { res.write(data); } catch { this.removeClient(res); } } } broadcastReload(filename) { this.emit({ type: "reload", filename: filename ?? null, timestamp: Date.now(), }); } broadcastState(agentPath, sessionId) { this.emit({ type: "state", agentPath, sessionId, timestamp: Date.now() }); } closeAll() { for (const res of Array.from(this.clients)) { this.removeClient(res); } } }; exports.HotReloadService = HotReloadService; exports.HotReloadService = HotReloadService = __decorate([ (0, common_1.Injectable)() ], HotReloadService); //# sourceMappingURL=hot-reload.service.js.map