@deadragdoll/tellymcp 0.0.10 → 0.0.12

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 (154) hide show
  1. package/.env.example.client +42 -52
  2. package/.env.example.gateway +48 -62
  3. package/CHANGELOG.md +3 -3
  4. package/README-ru.md +226 -376
  5. package/README.md +213 -1184
  6. package/TOOLS.md +320 -377
  7. package/VERSION.md +13 -13
  8. package/config/codex/plugins/telly-workflows/.codex-plugin/plugin.json +18 -0
  9. package/config/codex/plugins/telly-workflows/references/invariants.md +10 -0
  10. package/config/codex/plugins/telly-workflows/skills/telly-browser-screenshot/SKILL.md +27 -0
  11. package/config/codex/plugins/telly-workflows/skills/telly-collab-artifact/SKILL.md +22 -0
  12. package/config/codex/plugins/telly-workflows/skills/telly-human-telegram/SKILL.md +31 -0
  13. package/config/codex/plugins/telly-workflows/skills/telly-partner-note/SKILL.md +36 -0
  14. package/config/templates/env.both.template +39 -20
  15. package/config/templates/env.client.template +34 -19
  16. package/config/templates/env.gateway.template +37 -22
  17. package/dist/cli.js +322 -75
  18. package/dist/codexPluginInstaller.js +215 -0
  19. package/dist/lib/mixins/session.errors.js +34 -1
  20. package/dist/lib/pinoTargets.js +2 -2
  21. package/dist/moleculer.config.js +7 -5
  22. package/dist/services/features/telegram-mcp/browser.service.js +94 -1
  23. package/dist/services/features/telegram-mcp/collaboration.service.js +40 -3
  24. package/dist/services/features/telegram-mcp/ensuredb.service.js +145 -26
  25. package/dist/services/features/telegram-mcp/gateway-delivery.service.js +285 -103
  26. package/dist/services/features/telegram-mcp/gateway-socket.service.js +907 -85
  27. package/dist/services/features/telegram-mcp/gateway.service.js +876 -81
  28. package/dist/services/features/telegram-mcp/mcp-http.service.js +8 -0
  29. package/dist/services/features/telegram-mcp/mcp-server.service.js +17 -26
  30. package/dist/services/features/telegram-mcp/notify.service.js +127 -1
  31. package/dist/services/features/telegram-mcp/session-context.service.js +28 -1
  32. package/dist/services/features/telegram-mcp/src/app/bootstrap/runtime.js +132 -10
  33. package/dist/services/features/telegram-mcp/src/app/config/env.js +158 -52
  34. package/dist/services/features/telegram-mcp/src/app/http.js +375 -42
  35. package/dist/services/features/telegram-mcp/src/app/webapp/assets.js +386 -58
  36. package/dist/services/features/telegram-mcp/src/app/webapp/auth.js +3 -0
  37. package/dist/services/features/telegram-mcp/src/app/webapp/terminal.js +12 -0
  38. package/dist/services/features/telegram-mcp/src/entities/request/model/schema.js +120 -104
  39. package/dist/services/features/telegram-mcp/src/entities/xchange/model/types.js +2 -0
  40. package/dist/services/features/telegram-mcp/src/features/ask-user/model/askUserTelegram.js +1 -1
  41. package/dist/services/features/telegram-mcp/src/features/browser/model/browserOpenTool.js +1 -1
  42. package/dist/services/features/telegram-mcp/src/features/browser/model/browserScreenshotTool.js +1 -1
  43. package/dist/services/features/telegram-mcp/src/features/browser/model/browserService.js +306 -26
  44. package/dist/services/features/telegram-mcp/src/features/collaboration/model/gatewaySessionsService.js +71 -0
  45. package/dist/services/features/telegram-mcp/src/features/collaboration/model/listGatewaySessionsTool.js +33 -0
  46. package/dist/services/features/telegram-mcp/src/features/collaboration/model/localCollaborationBackend.js +93 -82
  47. package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerFileService.js +47 -5
  48. package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerFileTool.js +1 -1
  49. package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerNoteTool.js +1 -1
  50. package/dist/services/features/telegram-mcp/src/features/distributed-client/model/gatewayClientAccess.js +82 -0
  51. package/dist/services/features/telegram-mcp/src/features/distributed-client/model/gatewayCollaborationBackend.js +22 -14
  52. package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/gatewayHttpService.js +697 -75
  53. package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/remoteConsoleActionClient.js +76 -0
  54. package/dist/services/features/telegram-mcp/src/features/embedded-runtime/model/embeddedRuntimeBroker.js +92 -0
  55. package/dist/services/features/telegram-mcp/src/features/foreground-terminal/model/foregroundTerminalRuntime.js +192 -0
  56. package/dist/services/features/telegram-mcp/src/features/notify/model/notifyService.js +382 -3
  57. package/dist/services/features/telegram-mcp/src/features/notify/model/notifyTelegramTool.js +1 -1
  58. package/dist/services/features/telegram-mcp/src/features/notify/model/sendFileToTelegramTool.js +33 -0
  59. package/dist/services/features/telegram-mcp/src/features/session-context/model/clearSessionContextTool.js +1 -1
  60. package/dist/services/features/telegram-mcp/src/features/session-context/model/getSessionContextTool.js +1 -1
  61. package/dist/services/features/telegram-mcp/src/features/session-context/model/renameSessionTool.js +1 -1
  62. package/dist/services/features/telegram-mcp/src/features/session-context/model/sessionContextService.js +42 -200
  63. package/dist/services/features/telegram-mcp/src/features/session-context/model/setSessionContextTool.js +1 -1
  64. package/dist/services/features/telegram-mcp/src/features/terminal-buffer/model/terminalBufferService.js +96 -0
  65. package/dist/services/features/telegram-mcp/src/features/terminal-input/model/terminalInputService.js +97 -0
  66. package/dist/services/features/telegram-mcp/src/features/tools-sync/model/refreshToolsMarkdownService.js +107 -58
  67. package/dist/services/features/telegram-mcp/src/features/tools-sync/model/refreshToolsMarkdownTool.js +1 -1
  68. package/dist/services/features/telegram-mcp/src/features/xchange/model/getXchangeRecordTool.js +28 -0
  69. package/dist/services/features/telegram-mcp/src/features/xchange/model/listXchangeRecordsTool.js +28 -0
  70. package/dist/services/features/telegram-mcp/src/features/xchange/model/markXchangeRecordReadTool.js +28 -0
  71. package/dist/services/features/telegram-mcp/src/features/xchange/model/xchangeService.js +169 -0
  72. package/dist/services/features/telegram-mcp/src/processes/human-approval/model/orchestrator.js +5 -4
  73. package/dist/services/features/telegram-mcp/src/shared/i18n/resources/en.js +143 -42
  74. package/dist/services/features/telegram-mcp/src/shared/i18n/resources/ru.js +139 -38
  75. package/dist/services/features/telegram-mcp/src/shared/integrations/memory/processLocalSessionStore.js +27 -0
  76. package/dist/services/features/telegram-mcp/src/shared/integrations/object-storage/minioExchangeStore.js +11 -8
  77. package/dist/services/features/telegram-mcp/src/shared/integrations/redis/stateStore.js +69 -70
  78. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/proxyFetch.js +21 -22
  79. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transport.js +444 -7093
  80. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportAttachmentStore.js +93 -0
  81. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportBroadcastActions.js +385 -0
  82. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConsoleRegistry.js +149 -0
  83. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConstructorWiring.js +642 -0
  84. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportContent.js +84 -0
  85. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportContext.js +78 -0
  86. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportDocumentActions.js +36 -0
  87. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportEventActions.js +292 -0
  88. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportFileHandoffActions.js +352 -0
  89. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportFormatting.js +75 -0
  90. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportGatewayActions.js +44 -0
  91. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLifecycleActions.js +161 -0
  92. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLive.js +56 -0
  93. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLiveActions.js +77 -0
  94. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuCallbacks.js +254 -0
  95. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFactories.js +538 -0
  96. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFingerprints.js +93 -0
  97. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFlow.js +344 -0
  98. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuShell.js +65 -0
  99. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuState.js +408 -0
  100. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuText.js +216 -0
  101. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMessageFlow.js +452 -0
  102. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportOutputActions.js +189 -0
  103. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPartnerActions.js +286 -0
  104. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPayloadState.js +108 -0
  105. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectActions.js +463 -0
  106. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectEntryActions.js +202 -0
  107. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectEvents.js +99 -0
  108. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectMenus.js +138 -0
  109. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectState.js +308 -0
  110. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectView.js +426 -0
  111. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportRequestFlow.js +278 -0
  112. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportSessionActions.js +143 -0
  113. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalActions.js +665 -0
  114. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalRuntime.js +226 -0
  115. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTypes.js +2 -0
  116. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportUtils.js +330 -0
  117. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportXchangeState.js +107 -0
  118. package/dist/services/features/telegram-mcp/src/shared/integrations/terminal/client.js +255 -0
  119. package/dist/services/features/telegram-mcp/src/shared/integrations/terminal/ptyRegistry.js +543 -0
  120. package/dist/services/features/telegram-mcp/src/shared/integrations/xchange/sqliteRecordStore.js +223 -0
  121. package/dist/services/features/telegram-mcp/src/shared/lib/gatewayScope.js +24 -0
  122. package/dist/services/features/telegram-mcp/src/shared/lib/logger/logger.js +6 -0
  123. package/dist/services/features/telegram-mcp/src/shared/lib/project-identity/projectIdentity.js +147 -76
  124. package/dist/services/features/telegram-mcp/src/shared/lib/telegramXchangeRecords.js +72 -0
  125. package/dist/services/features/telegram-mcp/src/shared/lib/terminalPromptDetection.js +409 -0
  126. package/dist/services/features/telegram-mcp/src/shared/lib/version/versionHandshake.js +129 -1
  127. package/dist/services/features/telegram-mcp/src/shared/lib/xchangeRecordHints.js +98 -0
  128. package/dist/services/features/telegram-mcp/standalone-http.service.js +12 -0
  129. package/dist/services/features/telegram-mcp/terminal-buffer.service.js +42 -0
  130. package/dist/services/features/telegram-mcp/terminal-input.service.js +41 -0
  131. package/dist/services/features/telegram-mcp/tools-sync.service.js +15 -1
  132. package/dist/services/features/telegram-mcp/xchange.service.js +123 -0
  133. package/docs/STANDALONE-ru.md +172 -0
  134. package/docs/STANDALONE.md +172 -0
  135. package/package.json +10 -5
  136. package/scripts/build-package-artifact.sh +27 -0
  137. package/scripts/deploy-gateway.sh +64 -0
  138. package/scripts/deploy-onebot-branch.sh +27 -0
  139. package/scripts/postinstall.js +11 -36
  140. package/STANDALONE-ru.md +0 -274
  141. package/STANDALONE.md +0 -274
  142. package/dist/services/features/telegram-mcp/inbox.service.js +0 -33
  143. package/dist/services/features/telegram-mcp/pair.service.js +0 -33
  144. package/dist/services/features/telegram-mcp/src/app/webapp/tmux.js +0 -10
  145. package/dist/services/features/telegram-mcp/src/features/inbox/model/deleteTelegramInboxMessageTool.js +0 -33
  146. package/dist/services/features/telegram-mcp/src/features/inbox/model/getTelegramInboxCountTool.js +0 -33
  147. package/dist/services/features/telegram-mcp/src/features/inbox/model/getTelegramInboxTool.js +0 -33
  148. package/dist/services/features/telegram-mcp/src/features/inbox/model/inboxService.js +0 -77
  149. package/dist/services/features/telegram-mcp/src/features/pair-session/model/clearSessionPairingTool.js +0 -33
  150. package/dist/services/features/telegram-mcp/src/features/pair-session/model/createSessionPairCodeTool.js +0 -33
  151. package/dist/services/features/telegram-mcp/src/features/pair-session/model/generatePairCode.js +0 -202
  152. package/dist/services/features/telegram-mcp/src/features/session-context/model/getTmuxTargetTool.js +0 -33
  153. package/dist/services/features/telegram-mcp/src/features/session-context/model/setTmuxTargetTool.js +0 -33
  154. package/dist/services/features/telegram-mcp/src/shared/integrations/tmux/client.js +0 -363
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransportRequestFlow = void 0;
4
+ const messageFormat_1 = require("./messageFormat");
5
+ class TransportRequestFlow {
6
+ host;
7
+ constructor(host) {
8
+ this.host = host;
9
+ }
10
+ async sendAdminGatewayRegistrationNotifications(input) {
11
+ if (!this.host.isTelegramEnabled()) {
12
+ return;
13
+ }
14
+ const ownerRoute = await this.host.callGatewayJson("/user/route", {
15
+ client_uuid: input.clientUuid,
16
+ ...(input.gatewayUserUuid ? { gateway_user_uuid: input.gatewayUserUuid } : {}),
17
+ });
18
+ if (typeof ownerRoute.telegram_user_id !== "number" ||
19
+ typeof ownerRoute.telegram_chat_id !== "number") {
20
+ this.host.logger.debug("Skipping gateway registration notification because owner Telegram route is unavailable", {
21
+ clientUuid: input.clientUuid,
22
+ gatewayUserUuid: input.gatewayUserUuid ?? null,
23
+ });
24
+ return;
25
+ }
26
+ const principal = {
27
+ telegramChatId: ownerRoute.telegram_chat_id,
28
+ telegramUserId: ownerRoute.telegram_user_id,
29
+ };
30
+ const locale = await this.host.resolveLocaleForTelegramUserId(principal.telegramUserId);
31
+ const lines = [
32
+ this.host.t(locale, input.isNewClient
33
+ ? "menu:notices.admin.gateway_client_registered_title"
34
+ : "menu:notices.admin.gateway_session_registered_title"),
35
+ this.host.t(locale, "menu:notices.admin.gateway_client_uuid", {
36
+ value: input.clientUuid,
37
+ }),
38
+ ...(input.nodeId
39
+ ? [
40
+ this.host.t(locale, "menu:notices.admin.gateway_node_id", {
41
+ value: input.nodeId,
42
+ }),
43
+ ]
44
+ : []),
45
+ ...(input.packageVersion
46
+ ? [
47
+ this.host.t(locale, "menu:notices.admin.gateway_package_version", {
48
+ value: input.packageVersion,
49
+ }),
50
+ ]
51
+ : []),
52
+ this.host.t(locale, "menu:notices.admin.gateway_session_count", {
53
+ count: input.totalSessions,
54
+ }),
55
+ ...(input.newSessions.length > 0
56
+ ? [
57
+ "",
58
+ this.host.t(locale, "menu:notices.admin.gateway_new_sessions"),
59
+ ...input.newSessions.map((session) => this.host.t(locale, "menu:notices.admin.gateway_session_item", {
60
+ label: session.session_label?.trim() || session.local_session_id,
61
+ localSessionId: session.local_session_id,
62
+ })),
63
+ ]
64
+ : []),
65
+ ];
66
+ try {
67
+ await this.sendNotification({
68
+ sessionId: `gateway-owner:${input.clientUuid}`,
69
+ sessionLabel: "Gateway",
70
+ recipient: principal,
71
+ message: lines.join("\n"),
72
+ });
73
+ }
74
+ catch (error) {
75
+ this.host.logger.warn("Failed to deliver gateway registration owner notification", {
76
+ telegramChatId: principal.telegramChatId,
77
+ telegramUserId: principal.telegramUserId,
78
+ clientUuid: input.clientUuid,
79
+ error: error instanceof Error ? error.message : String(error),
80
+ });
81
+ }
82
+ }
83
+ async sendRequest(input) {
84
+ if (!this.host.isTelegramEnabled()) {
85
+ return this.sendRequestViaGateway(input);
86
+ }
87
+ const text = (0, messageFormat_1.formatTelegramMessage)(input, {
88
+ maxQuestionChars: this.host.config.telegram.maxQuestionChars,
89
+ maxContextChars: this.host.config.telegram.maxContextChars,
90
+ maxMessageChars: this.host.config.telegram.maxMessageChars,
91
+ });
92
+ const sentChunks = await this.host.sendTextChunks(input.recipient.telegramChatId, text, {
93
+ sessionId: input.sessionId,
94
+ requestId: input.requestId,
95
+ kind: "request",
96
+ });
97
+ const response = sentChunks.at(-1);
98
+ if (!response) {
99
+ throw new Error("Telegram request send produced no message chunks");
100
+ }
101
+ this.host.waiters.set(input.requestId, {
102
+ requestId: input.requestId,
103
+ telegramChatId: input.recipient.telegramChatId,
104
+ telegramUserId: input.recipient.telegramUserId,
105
+ telegramMessageId: response.messageId,
106
+ sentAtMs: Date.now(),
107
+ });
108
+ return { externalMessageId: response.messageId };
109
+ }
110
+ async sendRequestForGatewayBoundSession(input) {
111
+ const result = await this.sendRequest(input);
112
+ const waiter = this.host.waiters.get(input.requestId);
113
+ if (waiter) {
114
+ waiter.sourceClientUuid = input.sourceClientUuid;
115
+ }
116
+ return result;
117
+ }
118
+ async sendNotification(input) {
119
+ if (!this.host.isTelegramEnabled()) {
120
+ return this.sendNotificationViaGateway(input);
121
+ }
122
+ const text = (0, messageFormat_1.formatTelegramNotification)(input, {
123
+ maxQuestionChars: this.host.config.telegram.maxQuestionChars,
124
+ maxContextChars: this.host.config.telegram.maxContextChars,
125
+ maxMessageChars: this.host.config.telegram.maxMessageChars,
126
+ });
127
+ const sentChunks = await this.host.sendTextChunks(input.recipient.telegramChatId, text, {
128
+ sessionId: input.sessionId,
129
+ kind: "notification",
130
+ });
131
+ const response = sentChunks.at(-1);
132
+ if (!response) {
133
+ throw new Error("Telegram notification send produced no message chunks");
134
+ }
135
+ this.host.logger.info("Telegram notification delivered", {
136
+ sessionId: input.sessionId,
137
+ telegramChatId: input.recipient.telegramChatId,
138
+ telegramUserId: input.recipient.telegramUserId,
139
+ messageId: response.messageId,
140
+ chunks: sentChunks.length,
141
+ });
142
+ return { externalMessageId: response.messageId };
143
+ }
144
+ async waitForReply(requestId, timeoutSeconds) {
145
+ const waiter = this.host.waiters.get(requestId);
146
+ if (!waiter) {
147
+ throw new Error(`Transport waiter not found for request ${requestId}`);
148
+ }
149
+ if (waiter.reply) {
150
+ this.clearWaiter(requestId);
151
+ return waiter.reply;
152
+ }
153
+ return new Promise((resolve) => {
154
+ waiter.resolve = (reply) => {
155
+ if (waiter.timeout) {
156
+ clearTimeout(waiter.timeout);
157
+ }
158
+ this.clearWaiter(requestId);
159
+ resolve(reply);
160
+ };
161
+ waiter.timeout = setTimeout(() => {
162
+ waiter.resolve?.(null);
163
+ }, timeoutSeconds * 1000);
164
+ });
165
+ }
166
+ async handleGatewayTransportReplyEvent(input) {
167
+ const waiter = this.host.waiters.get(input.request_id);
168
+ if (!waiter) {
169
+ this.host.logger.debug("Gateway transport reply ignored because waiter was not found", {
170
+ requestId: input.request_id,
171
+ });
172
+ return;
173
+ }
174
+ const reply = {
175
+ requestId: input.request_id,
176
+ answer: input.answer,
177
+ receivedAt: input.received_at,
178
+ };
179
+ this.host.logger.info("Gateway transport reply received", {
180
+ requestId: input.request_id,
181
+ telegramChatId: waiter.telegramChatId,
182
+ telegramUserId: waiter.telegramUserId,
183
+ });
184
+ if (waiter.resolve) {
185
+ waiter.resolve(reply);
186
+ return;
187
+ }
188
+ waiter.reply = reply;
189
+ }
190
+ clearWaiter(requestId) {
191
+ const waiter = this.host.waiters.get(requestId);
192
+ if (waiter?.timeout) {
193
+ clearTimeout(waiter.timeout);
194
+ }
195
+ this.host.waiters.delete(requestId);
196
+ }
197
+ async sendRequestViaGateway(input) {
198
+ if (!this.host.config.distributed.gatewayPublicUrl) {
199
+ throw new Error("Gateway is not configured for Telegram request proxying.");
200
+ }
201
+ const clientUuid = await this.host.maintenanceStore.getGatewayClientUuid();
202
+ if (!clientUuid) {
203
+ throw new Error("Gateway client UUID is unavailable for Telegram request proxying.");
204
+ }
205
+ this.host.waiters.set(input.requestId, {
206
+ requestId: input.requestId,
207
+ telegramChatId: input.recipient.telegramChatId,
208
+ telegramUserId: input.recipient.telegramUserId,
209
+ telegramMessageId: 0,
210
+ sentAtMs: Date.now(),
211
+ });
212
+ try {
213
+ const response = await this.host.callGatewayJson("/transport/request", {
214
+ client_uuid: clientUuid,
215
+ local_session_id: input.sessionId,
216
+ request_id: input.requestId,
217
+ ...(input.sessionLabel ? { session_label: input.sessionLabel } : {}),
218
+ telegram_chat_id: input.recipient.telegramChatId,
219
+ telegram_user_id: input.recipient.telegramUserId,
220
+ question: input.question,
221
+ ...(input.task ? { task: input.task } : {}),
222
+ ...(input.context ? { context: input.context } : {}),
223
+ ...(input.affectedFiles ? { affected_files: input.affectedFiles } : {}),
224
+ ...(input.options ? { options: input.options } : {}),
225
+ ...(input.recommendedOption
226
+ ? { recommended_option: input.recommendedOption }
227
+ : {}),
228
+ ...(input.riskLevel ? { risk_level: input.riskLevel } : {}),
229
+ ...(input.fallbackIfTimeout
230
+ ? { fallback_if_timeout: input.fallbackIfTimeout }
231
+ : {}),
232
+ });
233
+ const waiter = this.host.waiters.get(input.requestId);
234
+ if (waiter && typeof response.message_id === "number") {
235
+ waiter.telegramMessageId = response.message_id;
236
+ }
237
+ return typeof response.message_id === "undefined"
238
+ ? {}
239
+ : { externalMessageId: response.message_id };
240
+ }
241
+ catch (error) {
242
+ this.clearWaiter(input.requestId);
243
+ throw error;
244
+ }
245
+ }
246
+ async sendNotificationViaGateway(input) {
247
+ if (!this.host.config.distributed.gatewayPublicUrl) {
248
+ throw new Error("Gateway is not configured for Telegram notification proxying.");
249
+ }
250
+ const clientUuid = await this.host.maintenanceStore.getGatewayClientUuid();
251
+ if (!clientUuid) {
252
+ throw new Error("Gateway client UUID is unavailable for Telegram notification proxying.");
253
+ }
254
+ const response = await this.host.callGatewayJson("/transport/notify", {
255
+ client_uuid: clientUuid,
256
+ local_session_id: input.sessionId,
257
+ ...(input.sessionLabel ? { session_label: input.sessionLabel } : {}),
258
+ telegram_chat_id: input.recipient.telegramChatId,
259
+ telegram_user_id: input.recipient.telegramUserId,
260
+ message: input.message,
261
+ ...(input.task ? { task: input.task } : {}),
262
+ ...(input.context ? { context: input.context } : {}),
263
+ ...(input.riskLevel ? { risk_level: input.riskLevel } : {}),
264
+ });
265
+ this.host.logger.info("Gateway transport notification delivered", {
266
+ sessionId: input.sessionId,
267
+ telegramChatId: input.recipient.telegramChatId,
268
+ telegramUserId: input.recipient.telegramUserId,
269
+ ...(typeof response.message_id !== "undefined"
270
+ ? { messageId: response.message_id }
271
+ : {}),
272
+ });
273
+ return typeof response.message_id === "undefined"
274
+ ? {}
275
+ : { externalMessageId: response.message_id };
276
+ }
277
+ }
278
+ exports.TransportRequestFlow = TransportRequestFlow;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransportSessionActions = void 0;
4
+ const transportUtils_1 = require("./transportUtils");
5
+ const redactSecrets_1 = require("../../lib/redact-secrets/redactSecrets");
6
+ class TransportSessionActions {
7
+ host;
8
+ constructor(host) {
9
+ this.host = host;
10
+ }
11
+ async unpairActiveSession(ctx) {
12
+ const locale = await this.host.resolveLocaleForContext(ctx);
13
+ const principal = this.host.getPrincipalFromContext(ctx);
14
+ if (!principal) {
15
+ await ctx.answerCallbackQuery({
16
+ text: this.host.t(locale, "common:errors.no_telegram_identity"),
17
+ show_alert: true,
18
+ });
19
+ return;
20
+ }
21
+ const sessionId = await this.host.bindingStore.getActiveSessionIdForPrincipal(principal);
22
+ if (!sessionId) {
23
+ await ctx.answerCallbackQuery({
24
+ text: this.host.t(locale, "common:errors.no_active_session"),
25
+ show_alert: true,
26
+ });
27
+ return;
28
+ }
29
+ const session = await this.host.sessionStore.getSession(sessionId);
30
+ if (session && this.host.config.distributed.gatewayPublicUrl) {
31
+ await this.host.sessionStore.setSession({
32
+ ...session,
33
+ activeProjectUuid: undefined,
34
+ activeProjectName: undefined,
35
+ updatedAt: new Date().toISOString(),
36
+ });
37
+ }
38
+ await this.host.bindingStore.clearBinding(sessionId);
39
+ this.host.logger.info("Telegram active session route cleared from menu", {
40
+ sessionId,
41
+ chatId: ctx.chat?.id,
42
+ userId: ctx.from?.id,
43
+ });
44
+ this.host.clearPendingInteractionsForContext(ctx);
45
+ await ctx.answerCallbackQuery({
46
+ text: this.host.t(locale, "menu:unpair.done", {
47
+ sessionName: session?.label ?? sessionId,
48
+ }),
49
+ });
50
+ await this.host.showSessionsMenu(ctx, this.host.t(locale, "menu:unpair.shown", {
51
+ sessionName: session?.label ?? sessionId,
52
+ }));
53
+ }
54
+ async beginRenameActiveSession(ctx) {
55
+ const locale = await this.host.resolveLocaleForContext(ctx);
56
+ const principal = this.host.getPrincipalFromContext(ctx);
57
+ if (!principal) {
58
+ await ctx.answerCallbackQuery({
59
+ text: this.host.t(locale, "common:errors.no_telegram_identity"),
60
+ show_alert: true,
61
+ });
62
+ return;
63
+ }
64
+ const sessionId = await this.host.bindingStore.getActiveSessionIdForPrincipal(principal);
65
+ if (!sessionId) {
66
+ await ctx.answerCallbackQuery({
67
+ text: this.host.t(locale, "common:errors.no_active_session"),
68
+ show_alert: true,
69
+ });
70
+ return;
71
+ }
72
+ const principalKey = (0, transportUtils_1.buildPrincipalKey)(principal);
73
+ this.host.pendingBroadcasts.delete(principalKey);
74
+ this.host.pendingRenames.set(principalKey, { sessionId });
75
+ await ctx.answerCallbackQuery({
76
+ text: this.host.t(locale, "menu:settings.actions.rename_prompt"),
77
+ });
78
+ await this.host.replyText(ctx, ["✏ Rename session", "", this.host.t(locale, "menu:settings.actions.rename_body")].join("\n"), { kind: "menu", sessionId });
79
+ }
80
+ async pruneAllSessions(ctx) {
81
+ await ctx.answerCallbackQuery({ text: "Pruning all state..." });
82
+ let prunedGateway = false;
83
+ if (this.host.config.distributed.gatewayPublicUrl) {
84
+ try {
85
+ await this.host.callGatewayJson("/admin/prune-state", {});
86
+ prunedGateway = true;
87
+ }
88
+ catch (error) {
89
+ this.host.logger.warn("Gateway DB prune failed", {
90
+ error: error instanceof Error ? error.message : String(error),
91
+ });
92
+ }
93
+ }
94
+ const result = await this.host.maintenanceStore.pruneAll();
95
+ this.host.clearPendingInteractionsForContext(ctx);
96
+ this.host.clearTerminalNudgeDebounceTimers();
97
+ await this.host.showSessionsMenu(ctx, `Prune complete. Deleted ${result.deletedKeys} Redis keys.${prunedGateway ? " Gateway DB cleared." : ""}`);
98
+ }
99
+ async handlePendingRename(ctx, text) {
100
+ const principal = this.host.getPrincipalFromContext(ctx);
101
+ if (!principal) {
102
+ return false;
103
+ }
104
+ const pending = this.host.pendingRenames.get((0, transportUtils_1.buildPrincipalKey)(principal));
105
+ if (!pending) {
106
+ return false;
107
+ }
108
+ if (text.startsWith("/")) {
109
+ this.host.pendingRenames.delete((0, transportUtils_1.buildPrincipalKey)(principal));
110
+ return false;
111
+ }
112
+ const session = await this.host.sessionStore.getSession(pending.sessionId);
113
+ const updatedAt = new Date().toISOString();
114
+ const label = (0, redactSecrets_1.redactSecrets)(text);
115
+ await this.host.sessionStore.setSession({
116
+ sessionId: pending.sessionId,
117
+ label,
118
+ ...(session?.cwd ? { cwd: session.cwd } : {}),
119
+ ...(session?.task ? { task: session.task } : {}),
120
+ ...(session?.summary ? { summary: session.summary } : {}),
121
+ ...(session?.files ? { files: session.files } : {}),
122
+ ...(session?.decisions ? { decisions: session.decisions } : {}),
123
+ ...(session?.risks ? { risks: session.risks } : {}),
124
+ ...(session?.terminalTarget ? { terminalTarget: session.terminalTarget } : {}),
125
+ ...(session?.lastTerminalNudgeAt
126
+ ? { lastTerminalNudgeAt: session.lastTerminalNudgeAt }
127
+ : {}),
128
+ updatedAt,
129
+ });
130
+ this.host.pendingRenames.delete((0, transportUtils_1.buildPrincipalKey)(principal));
131
+ this.host.logger.info("Telegram session renamed from menu", {
132
+ sessionId: pending.sessionId,
133
+ sessionLabel: label,
134
+ chatId: ctx.chat?.id,
135
+ userId: ctx.from?.id,
136
+ });
137
+ await this.host.replyText(ctx, `Session renamed: ${label}`, { kind: "menu", sessionId: pending.sessionId }, {
138
+ reply_markup: this.host.getMainMenu(),
139
+ });
140
+ return true;
141
+ }
142
+ }
143
+ exports.TransportSessionActions = TransportSessionActions;