@rk0429/agentic-relay 21.3.0 → 22.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/application/chat/chat-daemon-service.d.ts +81 -0
  2. package/dist/application/chat/chat-daemon-service.js +382 -0
  3. package/dist/application/chat/chat-daemon-service.js.map +1 -0
  4. package/dist/application/chat/chat-inbound-handler.d.ts +35 -0
  5. package/dist/application/chat/chat-inbound-handler.js +175 -0
  6. package/dist/application/chat/chat-inbound-handler.js.map +1 -0
  7. package/dist/application/chat/chat-logging.d.ts +8 -0
  8. package/dist/application/chat/chat-logging.js +16 -0
  9. package/dist/application/chat/chat-logging.js.map +1 -0
  10. package/dist/application/chat/chat-outbound-handler.d.ts +16 -0
  11. package/dist/application/chat/chat-outbound-handler.js +190 -0
  12. package/dist/application/chat/chat-outbound-handler.js.map +1 -0
  13. package/dist/application/chat/chat-question-service.d.ts +37 -0
  14. package/dist/application/chat/chat-question-service.js +135 -0
  15. package/dist/application/chat/chat-question-service.js.map +1 -0
  16. package/dist/application/chat/chat-setup-service.d.ts +27 -0
  17. package/dist/application/chat/chat-setup-service.js +183 -0
  18. package/dist/application/chat/chat-setup-service.js.map +1 -0
  19. package/dist/application/chat/message-queue-manager.d.ts +13 -0
  20. package/dist/application/chat/message-queue-manager.js +34 -0
  21. package/dist/application/chat/message-queue-manager.js.map +1 -0
  22. package/dist/application/routine-status-query-service.d.ts +17 -0
  23. package/dist/application/routine-status-query-service.js +111 -0
  24. package/dist/application/routine-status-query-service.js.map +1 -1
  25. package/dist/bin/relay.d.ts +4 -2
  26. package/dist/bin/relay.js +278 -11
  27. package/dist/bin/relay.js.map +1 -1
  28. package/dist/core/chat-types.d.ts +18 -0
  29. package/dist/core/chat-types.js +14 -0
  30. package/dist/core/chat-types.js.map +1 -0
  31. package/dist/core/types.d.ts +7 -0
  32. package/dist/domain/chat/message-cleaner.d.ts +11 -0
  33. package/dist/domain/chat/message-cleaner.js +45 -0
  34. package/dist/domain/chat/message-cleaner.js.map +1 -0
  35. package/dist/domain/chat/message-router.d.ts +8 -0
  36. package/dist/domain/chat/message-router.js +93 -0
  37. package/dist/domain/chat/message-router.js.map +1 -0
  38. package/dist/domain/chat/message-splitter.d.ts +3 -0
  39. package/dist/domain/chat/message-splitter.js +148 -0
  40. package/dist/domain/chat/message-splitter.js.map +1 -0
  41. package/dist/domain/chat/platform-connection.d.ts +31 -0
  42. package/dist/domain/chat/platform-connection.js +67 -0
  43. package/dist/domain/chat/platform-connection.js.map +1 -0
  44. package/dist/domain/chat/ports.d.ts +31 -0
  45. package/dist/domain/chat/ports.js +2 -0
  46. package/dist/domain/chat/ports.js.map +1 -0
  47. package/dist/domain/chat/session-bridge.d.ts +41 -0
  48. package/dist/domain/chat/session-bridge.js +93 -0
  49. package/dist/domain/chat/session-bridge.js.map +1 -0
  50. package/dist/domain/chat/types.d.ts +83 -0
  51. package/dist/domain/chat/types.js +2 -0
  52. package/dist/domain/chat/types.js.map +1 -0
  53. package/dist/domain/chat/user-question.d.ts +33 -0
  54. package/dist/domain/chat/user-question.js +73 -0
  55. package/dist/domain/chat/user-question.js.map +1 -0
  56. package/dist/domain/config.d.ts +3 -1
  57. package/dist/domain/config.js +9 -0
  58. package/dist/domain/config.js.map +1 -1
  59. package/dist/domain/routine-loader.d.ts +2 -0
  60. package/dist/domain/routine-loader.js +3 -0
  61. package/dist/domain/routine-loader.js.map +1 -1
  62. package/dist/infrastructure/chat/adapter-factory.d.ts +5 -0
  63. package/dist/infrastructure/chat/adapter-factory.js +15 -0
  64. package/dist/infrastructure/chat/adapter-factory.js.map +1 -0
  65. package/dist/infrastructure/chat/adapters/discord-adapter.d.ts +23 -0
  66. package/dist/infrastructure/chat/adapters/discord-adapter.js +199 -0
  67. package/dist/infrastructure/chat/adapters/discord-adapter.js.map +1 -0
  68. package/dist/infrastructure/chat/adapters/slack-adapter.d.ts +24 -0
  69. package/dist/infrastructure/chat/adapters/slack-adapter.js +155 -0
  70. package/dist/infrastructure/chat/adapters/slack-adapter.js.map +1 -0
  71. package/dist/infrastructure/chat/agent-gateway-impl.d.ts +21 -0
  72. package/dist/infrastructure/chat/agent-gateway-impl.js +101 -0
  73. package/dist/infrastructure/chat/agent-gateway-impl.js.map +1 -0
  74. package/dist/infrastructure/chat/chat-ipc-client.d.ts +33 -0
  75. package/dist/infrastructure/chat/chat-ipc-client.js +70 -0
  76. package/dist/infrastructure/chat/chat-ipc-client.js.map +1 -0
  77. package/dist/infrastructure/chat/chat-ipc-server.d.ts +19 -0
  78. package/dist/infrastructure/chat/chat-ipc-server.js +125 -0
  79. package/dist/infrastructure/chat/chat-ipc-server.js.map +1 -0
  80. package/dist/infrastructure/chat/chat-logger.d.ts +24 -0
  81. package/dist/infrastructure/chat/chat-logger.js +86 -0
  82. package/dist/infrastructure/chat/chat-logger.js.map +1 -0
  83. package/dist/infrastructure/chat/credentials-repository.d.ts +8 -0
  84. package/dist/infrastructure/chat/credentials-repository.js +84 -0
  85. package/dist/infrastructure/chat/credentials-repository.js.map +1 -0
  86. package/dist/infrastructure/chat/session-bridge-repository.d.ts +13 -0
  87. package/dist/infrastructure/chat/session-bridge-repository.js +120 -0
  88. package/dist/infrastructure/chat/session-bridge-repository.js.map +1 -0
  89. package/dist/infrastructure/chat/token-masking.d.ts +3 -0
  90. package/dist/infrastructure/chat/token-masking.js +22 -0
  91. package/dist/infrastructure/chat/token-masking.js.map +1 -0
  92. package/dist/infrastructure/store/relay-store.js +3 -1
  93. package/dist/infrastructure/store/relay-store.js.map +1 -1
  94. package/dist/interfaces/cli/chat-cli.d.ts +34 -0
  95. package/dist/interfaces/cli/chat-cli.js +68 -0
  96. package/dist/interfaces/cli/chat-cli.js.map +1 -0
  97. package/dist/interfaces/cli/relay-cli-args.d.ts +16 -1
  98. package/dist/interfaces/cli/relay-cli-args.js +135 -2
  99. package/dist/interfaces/cli/relay-cli-args.js.map +1 -1
  100. package/dist/interfaces/mcp/chat-tools.d.ts +33 -0
  101. package/dist/interfaces/mcp/chat-tools.js +129 -0
  102. package/dist/interfaces/mcp/chat-tools.js.map +1 -0
  103. package/dist/interfaces/mcp/relay-mcp-server.js +43 -6
  104. package/dist/interfaces/mcp/relay-mcp-server.js.map +1 -1
  105. package/package.json +3 -1
@@ -0,0 +1,81 @@
1
+ import type { ChatStructuredLogger } from "./chat-logging.js";
2
+ import { ConnectionState, PlatformType } from "../../core/chat-types.js";
3
+ import type { RelayConfig } from "../../core/types.js";
4
+ import type { ChatPlatformAdapter, CredentialsRepository, SessionBridgeRepository } from "../../domain/chat/ports.js";
5
+ import type { ChatCredentials } from "../../domain/chat/types.js";
6
+ import { ChatInboundHandler } from "./chat-inbound-handler.js";
7
+ import { ChatOutboundHandler } from "./chat-outbound-handler.js";
8
+ import { ChatQuestionService } from "./chat-question-service.js";
9
+ export interface ChatProcessStatus {
10
+ alive: boolean;
11
+ startedAt?: string | null;
12
+ }
13
+ export interface ChatDaemonStatus {
14
+ running: boolean;
15
+ pid?: number;
16
+ startedAt?: string | null;
17
+ platforms: Array<{
18
+ platform: PlatformType;
19
+ state: ConnectionState;
20
+ }>;
21
+ activeSessionCount: number;
22
+ }
23
+ export interface ChatDaemonSignalTarget {
24
+ on(event: "SIGTERM" | "SIGINT", listener: () => void): void;
25
+ off(event: "SIGTERM" | "SIGINT", listener: () => void): void;
26
+ }
27
+ export declare class ChatDaemonService {
28
+ private readonly deps;
29
+ private readonly now;
30
+ private readonly ownerPid;
31
+ private readonly signalTarget;
32
+ private readonly getProcessStatus;
33
+ private readonly platformConnections;
34
+ private readonly disconnectingPlatforms;
35
+ private adapters;
36
+ private stopping;
37
+ private stoppedResolver?;
38
+ private stoppedPromise?;
39
+ private logger;
40
+ constructor(deps: {
41
+ store: {
42
+ rootDir: string;
43
+ ensureLayout(): Promise<void>;
44
+ readConfig(): Promise<RelayConfig | null>;
45
+ };
46
+ credentialsRepository: CredentialsRepository;
47
+ sessionBridgeRepository: SessionBridgeRepository;
48
+ adapterFactory: {
49
+ createAdapters(credentials: ChatCredentials): Promise<ChatPlatformAdapter[]> | ChatPlatformAdapter[];
50
+ };
51
+ inboundHandler: ChatInboundHandler;
52
+ outboundHandler: ChatOutboundHandler;
53
+ questionService: ChatQuestionService;
54
+ ipcServer: {
55
+ listen(): Promise<void>;
56
+ close(): Promise<void>;
57
+ };
58
+ signalTarget?: ChatDaemonSignalTarget;
59
+ getProcessStatus?: (pid: number) => Promise<ChatProcessStatus>;
60
+ now?: () => Date;
61
+ ownerPid?: number;
62
+ createLogger?: (options: {
63
+ rootDir: string;
64
+ ensureLayout: () => Promise<void>;
65
+ now: () => Date;
66
+ logLevel: "info" | "warn" | "error";
67
+ }) => ChatStructuredLogger;
68
+ });
69
+ start(_foreground?: boolean): Promise<void>;
70
+ stop(): Promise<boolean>;
71
+ status(): Promise<ChatDaemonStatus>;
72
+ acquirePidFile(): Promise<void>;
73
+ releasePidFile(): Promise<void>;
74
+ getProcessStatusForPid(pid: number): Promise<ChatProcessStatus>;
75
+ private shutdown;
76
+ private handleConnectionStateChange;
77
+ private markPlatformConnected;
78
+ private resetPlatformDisconnected;
79
+ private readPidFile;
80
+ private pidFilePath;
81
+ }
@@ -0,0 +1,382 @@
1
+ import { execFile } from "node:child_process";
2
+ import { readFile, rm } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { noopChatLogger } from "./chat-logging.js";
6
+ import { ValidationError } from "../../core/errors.js";
7
+ import { ConnectionState, PlatformType } from "../../core/chat-types.js";
8
+ import { resolveChatConfig } from "../../domain/config.js";
9
+ import { PlatformConnection } from "../../domain/chat/platform-connection.js";
10
+ import { isProcessAlive } from "../housekeeping.js";
11
+ const execFileAsync = promisify(execFile);
12
+ export class ChatDaemonService {
13
+ deps;
14
+ now;
15
+ ownerPid;
16
+ signalTarget;
17
+ getProcessStatus;
18
+ platformConnections = new Map();
19
+ disconnectingPlatforms = new Set();
20
+ adapters = [];
21
+ stopping = false;
22
+ stoppedResolver;
23
+ stoppedPromise;
24
+ logger = noopChatLogger;
25
+ constructor(deps) {
26
+ this.deps = deps;
27
+ this.now = deps.now ?? (() => new Date());
28
+ this.ownerPid = deps.ownerPid ?? process.pid;
29
+ this.signalTarget = deps.signalTarget ?? process;
30
+ this.getProcessStatus = deps.getProcessStatus ?? defaultGetProcessStatus;
31
+ }
32
+ async start(_foreground = true) {
33
+ await this.deps.store.ensureLayout();
34
+ this.stopping = false;
35
+ this.platformConnections.clear();
36
+ this.disconnectingPlatforms.clear();
37
+ await this.acquirePidFile();
38
+ const onSignal = () => {
39
+ void this.shutdown();
40
+ };
41
+ this.signalTarget.on("SIGTERM", onSignal);
42
+ this.signalTarget.on("SIGINT", onSignal);
43
+ try {
44
+ const relayConfig = await this.deps.store.readConfig();
45
+ const chatConfig = resolveChatConfig(relayConfig);
46
+ this.logger =
47
+ this.deps.createLogger?.({
48
+ rootDir: this.deps.store.rootDir,
49
+ ensureLayout: () => this.deps.store.ensureLayout(),
50
+ now: this.now,
51
+ logLevel: chatConfig.log_level,
52
+ }) ?? noopChatLogger;
53
+ this.deps.inboundHandler.configure?.({
54
+ sessionTimeoutMinutes: chatConfig.session_timeout_minutes,
55
+ maxMessageLength: chatConfig.max_message_length,
56
+ messageQueueMaxSize: chatConfig.message_queue_max_size,
57
+ logger: this.logger,
58
+ });
59
+ this.deps.questionService.configure?.({
60
+ maxMessageLength: chatConfig.max_message_length,
61
+ });
62
+ await this.logger.info("chat daemon starting", {
63
+ rootDir: this.deps.store.rootDir,
64
+ chatConfig,
65
+ });
66
+ const credentials = await this.deps.credentialsRepository.load();
67
+ if (!credentials?.slack && !credentials?.discord) {
68
+ await this.logger.error("chat daemon credentials missing");
69
+ throw new ValidationError("Chat credentials are not configured. Run `relay chat setup` first.");
70
+ }
71
+ await this.logger.info("chat daemon credentials loaded", {
72
+ credentials,
73
+ });
74
+ this.adapters = await Promise.resolve(this.deps.adapterFactory.createAdapters(credentials));
75
+ if (this.adapters.length === 0) {
76
+ await this.logger.error("chat daemon adapters unavailable");
77
+ throw new ValidationError("No chat platform adapters could be created.");
78
+ }
79
+ this.deps.outboundHandler.setAdapters(this.adapters);
80
+ this.deps.questionService.setAdapters(this.adapters);
81
+ for (const adapter of this.adapters) {
82
+ this.platformConnections.set(adapter.platform, new PlatformConnection({
83
+ platform: adapter.platform,
84
+ state: ConnectionState.Connecting,
85
+ }));
86
+ adapter.onMessage((event) => {
87
+ void this.deps.inboundHandler.handleInbound(event);
88
+ });
89
+ adapter.onConnectionStateChange((state) => {
90
+ void this.handleConnectionStateChange(adapter, state);
91
+ });
92
+ await this.logger.info("chat adapter connecting", {
93
+ platform: adapter.platform,
94
+ });
95
+ try {
96
+ await adapter.connect();
97
+ await this.markPlatformConnected(adapter.platform);
98
+ }
99
+ catch (error) {
100
+ const connection = this.platformConnections.get(adapter.platform);
101
+ connection?.markDisconnected();
102
+ connection?.handleReconnectResult(false);
103
+ await this.logger.error("chat adapter connection failed", {
104
+ platform: adapter.platform,
105
+ error: toErrorMetadata(error),
106
+ });
107
+ throw error;
108
+ }
109
+ }
110
+ await this.deps.ipcServer.listen();
111
+ await this.logger.info("chat daemon started", {
112
+ platforms: [...this.platformConnections.keys()],
113
+ });
114
+ this.stoppedPromise = new Promise((resolve) => {
115
+ this.stoppedResolver = resolve;
116
+ });
117
+ await this.stoppedPromise;
118
+ }
119
+ finally {
120
+ this.signalTarget.off("SIGTERM", onSignal);
121
+ this.signalTarget.off("SIGINT", onSignal);
122
+ await this.releasePidFile();
123
+ }
124
+ }
125
+ async stop() {
126
+ if (this.adapters.length > 0 && this.ownerPid === process.pid) {
127
+ await this.shutdown();
128
+ return true;
129
+ }
130
+ const existing = await this.readPidFile();
131
+ if (!existing) {
132
+ return false;
133
+ }
134
+ const status = await this.getProcessStatus(existing.pid);
135
+ if (!status.alive) {
136
+ await this.releasePidFile();
137
+ return false;
138
+ }
139
+ process.kill(existing.pid, "SIGTERM");
140
+ const deadline = Date.now() + 30_000;
141
+ while (Date.now() < deadline) {
142
+ const current = await this.getProcessStatus(existing.pid);
143
+ if (!current.alive) {
144
+ await this.releasePidFile();
145
+ return true;
146
+ }
147
+ await sleep(250);
148
+ }
149
+ return true;
150
+ }
151
+ async status() {
152
+ const existing = await this.readPidFile();
153
+ const chatConfig = resolveChatConfig(await this.deps.store.readConfig());
154
+ const credentials = await this.deps.credentialsRepository.load();
155
+ const activeSessionCount = this.deps.sessionBridgeRepository.findAllActive(chatConfig.session_timeout_minutes).length;
156
+ if (!existing) {
157
+ return {
158
+ running: false,
159
+ platforms: inferPlatforms(credentials, false),
160
+ activeSessionCount,
161
+ };
162
+ }
163
+ const processStatus = await this.getProcessStatus(existing.pid);
164
+ if (!processStatus.alive) {
165
+ await this.releasePidFile();
166
+ return {
167
+ running: false,
168
+ platforms: inferPlatforms(credentials, false),
169
+ activeSessionCount,
170
+ };
171
+ }
172
+ const platforms = this.platformConnections.size > 0
173
+ ? [...this.platformConnections.entries()].map(([platform, connection]) => ({
174
+ platform,
175
+ state: connection.state,
176
+ }))
177
+ : inferPlatforms(credentials, true);
178
+ return {
179
+ running: true,
180
+ pid: existing.pid,
181
+ startedAt: existing.startedAt,
182
+ platforms,
183
+ activeSessionCount,
184
+ };
185
+ }
186
+ async acquirePidFile() {
187
+ const existing = await this.readPidFile();
188
+ if (existing) {
189
+ const status = await this.getProcessStatus(existing.pid);
190
+ if (status.alive &&
191
+ (!status.startedAt || Date.parse(status.startedAt) <= Date.parse(existing.startedAt))) {
192
+ throw new ValidationError("Chat daemon is already running.", {
193
+ recoveryHint: "Stop the existing chat daemon before starting a new one.",
194
+ });
195
+ }
196
+ await rm(this.pidFilePath(), { force: true });
197
+ }
198
+ await import("../../infrastructure/store/file-utils.js").then(({ writeJsonAtomic }) => writeJsonAtomic(this.pidFilePath(), {
199
+ pid: this.ownerPid,
200
+ startedAt: this.now().toISOString(),
201
+ }));
202
+ }
203
+ async releasePidFile() {
204
+ await rm(this.pidFilePath(), { force: true });
205
+ }
206
+ async getProcessStatusForPid(pid) {
207
+ return this.getProcessStatus(pid);
208
+ }
209
+ async shutdown() {
210
+ if (this.stopping) {
211
+ return;
212
+ }
213
+ this.stopping = true;
214
+ await this.logger.info("chat daemon shutting down");
215
+ await this.deps.inboundHandler.waitForIdle(30_000);
216
+ await this.deps.ipcServer.close();
217
+ await Promise.all(this.adapters.map(async (adapter) => {
218
+ try {
219
+ await this.logger.info("chat adapter disconnecting", {
220
+ platform: adapter.platform,
221
+ });
222
+ await adapter.disconnect();
223
+ this.resetPlatformDisconnected(adapter.platform);
224
+ await this.logger.info("chat adapter disconnected", {
225
+ platform: adapter.platform,
226
+ });
227
+ }
228
+ catch {
229
+ // Ignore disconnect errors during shutdown.
230
+ }
231
+ }));
232
+ this.adapters = [];
233
+ this.disconnectingPlatforms.clear();
234
+ await this.logger.info("chat daemon stopped");
235
+ this.stoppedResolver?.();
236
+ }
237
+ async handleConnectionStateChange(adapter, state) {
238
+ const connection = this.platformConnections.get(adapter.platform);
239
+ if (!connection) {
240
+ return;
241
+ }
242
+ if (this.stopping || this.disconnectingPlatforms.has(adapter.platform)) {
243
+ if (this.stopping) {
244
+ this.resetPlatformDisconnected(adapter.platform);
245
+ }
246
+ return;
247
+ }
248
+ if (state === ConnectionState.Connected) {
249
+ await this.markPlatformConnected(adapter.platform);
250
+ return;
251
+ }
252
+ connection.markDisconnected();
253
+ connection.handleReconnectResult(false);
254
+ if (connection.isExhausted()) {
255
+ if (this.disconnectingPlatforms.has(adapter.platform)) {
256
+ return;
257
+ }
258
+ this.disconnectingPlatforms.add(adapter.platform);
259
+ await this.logger.error("chat adapter reconnection exhausted", {
260
+ platform: adapter.platform,
261
+ consecutiveFailures: connection.consecutiveFailures,
262
+ });
263
+ try {
264
+ await adapter.disconnect();
265
+ }
266
+ finally {
267
+ this.disconnectingPlatforms.delete(adapter.platform);
268
+ }
269
+ const allTerminal = [...this.platformConnections.values()].every((platformConnection) => platformConnection.state === ConnectionState.Failed ||
270
+ platformConnection.state === ConnectionState.Disconnected);
271
+ if (allTerminal) {
272
+ await this.logger.error("all chat adapters exhausted, shutting down daemon");
273
+ void this.shutdown();
274
+ }
275
+ return;
276
+ }
277
+ await this.logger.warn("chat adapter reconnecting", {
278
+ platform: adapter.platform,
279
+ state,
280
+ consecutiveFailures: connection.consecutiveFailures,
281
+ nextRetryDelayMs: connection.nextRetryDelay(),
282
+ });
283
+ }
284
+ async markPlatformConnected(platform) {
285
+ const connection = this.platformConnections.get(platform);
286
+ if (!connection) {
287
+ return;
288
+ }
289
+ const wasConnected = connection.state === ConnectionState.Connected &&
290
+ connection.consecutiveFailures === 0;
291
+ connection.markConnected();
292
+ if (!wasConnected) {
293
+ await this.logger.info("chat adapter connected", {
294
+ platform,
295
+ });
296
+ }
297
+ }
298
+ resetPlatformDisconnected(platform) {
299
+ const connection = this.platformConnections.get(platform);
300
+ if (!connection) {
301
+ return;
302
+ }
303
+ connection.state = ConnectionState.Disconnected;
304
+ connection.consecutiveFailures = 0;
305
+ }
306
+ async readPidFile() {
307
+ try {
308
+ const raw = await readFile(this.pidFilePath(), "utf8");
309
+ const parsed = JSON.parse(raw);
310
+ if (typeof parsed.pid !== "number" ||
311
+ !Number.isInteger(parsed.pid) ||
312
+ parsed.pid <= 0 ||
313
+ typeof parsed.startedAt !== "string" ||
314
+ Number.isNaN(Date.parse(parsed.startedAt))) {
315
+ throw new ValidationError("Invalid chat daemon PID file.", {
316
+ recoveryHint: "Delete the corrupted PID file and restart the daemon.",
317
+ });
318
+ }
319
+ return {
320
+ pid: parsed.pid,
321
+ startedAt: parsed.startedAt,
322
+ };
323
+ }
324
+ catch (error) {
325
+ if (typeof error === "object" &&
326
+ error !== null &&
327
+ "code" in error &&
328
+ error.code === "ENOENT") {
329
+ return null;
330
+ }
331
+ throw error;
332
+ }
333
+ }
334
+ pidFilePath() {
335
+ return path.join(this.deps.store.rootDir, "chat.pid");
336
+ }
337
+ }
338
+ function inferPlatforms(credentials, running) {
339
+ const normalizedState = running ? ConnectionState.Connected : ConnectionState.Disconnected;
340
+ const platforms = [];
341
+ if (credentials?.slack) {
342
+ platforms.push({ platform: PlatformType.Slack, state: normalizedState });
343
+ }
344
+ if (credentials?.discord) {
345
+ platforms.push({ platform: PlatformType.Discord, state: normalizedState });
346
+ }
347
+ return platforms;
348
+ }
349
+ async function defaultGetProcessStatus(pid) {
350
+ if (!isProcessAlive(pid)) {
351
+ return { alive: false };
352
+ }
353
+ try {
354
+ const { stdout } = await execFileAsync("ps", ["-o", "lstart=", "-p", String(pid)]);
355
+ const startedAt = stdout.trim();
356
+ const parsed = new Date(startedAt);
357
+ return {
358
+ alive: true,
359
+ startedAt: Number.isNaN(parsed.getTime()) ? null : parsed.toISOString(),
360
+ };
361
+ }
362
+ catch {
363
+ return {
364
+ alive: true,
365
+ };
366
+ }
367
+ }
368
+ function sleep(ms) {
369
+ return new Promise((resolve) => setTimeout(resolve, ms));
370
+ }
371
+ function toErrorMetadata(error) {
372
+ if (error instanceof Error) {
373
+ return {
374
+ name: error.name,
375
+ message: error.message,
376
+ };
377
+ }
378
+ return {
379
+ value: String(error),
380
+ };
381
+ }
382
+ //# sourceMappingURL=chat-daemon-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-daemon-service.js","sourceRoot":"","sources":["../../../src/application/chat/chat-daemon-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE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CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE;SACxE,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,KAAK,EAAE,IAAI;SACZ,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type ChatLoggerLike } from "./chat-logging.js";
2
+ import type { AgentGateway, SessionBridgeRepository } from "../../domain/chat/ports.js";
3
+ import type { InboundChatEvent } from "../../domain/chat/types.js";
4
+ import { ChatOutboundHandler } from "./chat-outbound-handler.js";
5
+ import { ChatQuestionService } from "./chat-question-service.js";
6
+ import { MessageQueueManager } from "./message-queue-manager.js";
7
+ export declare class ChatInboundHandler {
8
+ private readonly deps;
9
+ private activeOperations;
10
+ private readonly idleWaiters;
11
+ private sessionTimeoutMinutes;
12
+ private maxMessageLength;
13
+ private logger?;
14
+ constructor(deps: {
15
+ agentGateway: AgentGateway;
16
+ sessionBridgeRepository: SessionBridgeRepository;
17
+ outboundHandler: ChatOutboundHandler;
18
+ questionService: ChatQuestionService;
19
+ messageQueueManager: MessageQueueManager;
20
+ sessionTimeoutMinutes?: number;
21
+ maxMessageLength?: number;
22
+ logger?: ChatLoggerLike;
23
+ });
24
+ configure(options: {
25
+ sessionTimeoutMinutes?: number;
26
+ maxMessageLength?: number;
27
+ messageQueueMaxSize?: number;
28
+ logger?: ChatLoggerLike;
29
+ }): void;
30
+ handleInbound(event: InboundChatEvent): Promise<void>;
31
+ waitForIdle(timeoutMs: number): Promise<void>;
32
+ private handleNewSession;
33
+ private handleContinuation;
34
+ private log;
35
+ }