@deadragdoll/tellymcp 0.0.9 → 0.0.11

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 (157) hide show
  1. package/.env.example.client +42 -50
  2. package/.env.example.gateway +49 -61
  3. package/CHANGELOG.md +3 -3
  4. package/README-ru.md +205 -384
  5. package/README.md +195 -1194
  6. package/TOOLS.md +294 -377
  7. package/VERSION.md +36 -10
  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 +40 -20
  15. package/config/templates/env.client.template +34 -18
  16. package/config/templates/env.gateway.template +38 -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/approval.service.js +1 -1
  23. package/dist/services/features/telegram-mcp/browser.service.js +95 -2
  24. package/dist/services/features/telegram-mcp/collaboration.service.js +41 -4
  25. package/dist/services/features/telegram-mcp/ensuredb.service.js +145 -26
  26. package/dist/services/features/telegram-mcp/gateway-delivery.service.js +285 -103
  27. package/dist/services/features/telegram-mcp/gateway-rmq.service.js +3 -2
  28. package/dist/services/features/telegram-mcp/gateway-socket.service.js +905 -87
  29. package/dist/services/features/telegram-mcp/gateway.service.js +876 -81
  30. package/dist/services/features/telegram-mcp/mcp-http.service.js +9 -1
  31. package/dist/services/features/telegram-mcp/mcp-server.service.js +17 -26
  32. package/dist/services/features/telegram-mcp/notify.service.js +128 -2
  33. package/dist/services/features/telegram-mcp/runtime.service.js +27 -7
  34. package/dist/services/features/telegram-mcp/session-context.service.js +29 -2
  35. package/dist/services/features/telegram-mcp/src/app/bootstrap/runtime.js +133 -10
  36. package/dist/services/features/telegram-mcp/src/app/config/env.js +161 -51
  37. package/dist/services/features/telegram-mcp/src/app/http.js +375 -42
  38. package/dist/services/features/telegram-mcp/src/app/webapp/assets.js +386 -58
  39. package/dist/services/features/telegram-mcp/src/app/webapp/auth.js +3 -0
  40. package/dist/services/features/telegram-mcp/src/app/webapp/terminal.js +12 -0
  41. package/dist/services/features/telegram-mcp/src/entities/request/model/schema.js +116 -104
  42. package/dist/services/features/telegram-mcp/src/entities/xchange/model/types.js +2 -0
  43. package/dist/services/features/telegram-mcp/src/features/ask-user/model/askUserTelegram.js +1 -1
  44. package/dist/services/features/telegram-mcp/src/features/browser/model/browserScreenshotTool.js +1 -1
  45. package/dist/services/features/telegram-mcp/src/features/browser/model/browserService.js +249 -19
  46. package/dist/services/features/telegram-mcp/src/features/collaboration/model/gatewaySessionsService.js +71 -0
  47. package/dist/services/features/telegram-mcp/src/features/collaboration/model/listGatewaySessionsTool.js +33 -0
  48. package/dist/services/features/telegram-mcp/src/features/collaboration/model/localCollaborationBackend.js +93 -82
  49. package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerFileService.js +47 -5
  50. package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerFileTool.js +1 -1
  51. package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerNoteTool.js +1 -1
  52. package/dist/services/features/telegram-mcp/src/features/distributed-client/model/gatewayClientAccess.js +82 -0
  53. package/dist/services/features/telegram-mcp/src/features/distributed-client/model/gatewayCollaborationBackend.js +22 -14
  54. package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/gatewayHttpService.js +649 -75
  55. package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/remoteConsoleActionClient.js +76 -0
  56. package/dist/services/features/telegram-mcp/src/features/embedded-runtime/model/embeddedRuntimeBroker.js +92 -0
  57. package/dist/services/features/telegram-mcp/src/features/foreground-terminal/model/foregroundTerminalRuntime.js +192 -0
  58. package/dist/services/features/telegram-mcp/src/features/notify/model/notifyService.js +382 -3
  59. package/dist/services/features/telegram-mcp/src/features/notify/model/notifyTelegramTool.js +1 -1
  60. package/dist/services/features/telegram-mcp/src/features/notify/model/sendFileToTelegramTool.js +33 -0
  61. package/dist/services/features/telegram-mcp/src/features/session-context/model/clearSessionContextTool.js +1 -1
  62. package/dist/services/features/telegram-mcp/src/features/session-context/model/getSessionContextTool.js +1 -1
  63. package/dist/services/features/telegram-mcp/src/features/session-context/model/renameSessionTool.js +1 -1
  64. package/dist/services/features/telegram-mcp/src/features/session-context/model/sessionContextService.js +42 -200
  65. package/dist/services/features/telegram-mcp/src/features/session-context/model/setSessionContextTool.js +1 -1
  66. package/dist/services/features/telegram-mcp/src/features/terminal-buffer/model/terminalBufferService.js +96 -0
  67. package/dist/services/features/telegram-mcp/src/features/terminal-input/model/terminalInputService.js +97 -0
  68. package/dist/services/features/telegram-mcp/src/features/tools-sync/model/refreshToolsMarkdownService.js +107 -58
  69. package/dist/services/features/telegram-mcp/src/features/tools-sync/model/refreshToolsMarkdownTool.js +1 -1
  70. package/dist/services/features/telegram-mcp/src/features/xchange/model/getXchangeRecordTool.js +28 -0
  71. package/dist/services/features/telegram-mcp/src/features/xchange/model/listXchangeRecordsTool.js +28 -0
  72. package/dist/services/features/telegram-mcp/src/features/xchange/model/markXchangeRecordReadTool.js +28 -0
  73. package/dist/services/features/telegram-mcp/src/features/xchange/model/xchangeService.js +169 -0
  74. package/dist/services/features/telegram-mcp/src/processes/human-approval/model/orchestrator.js +5 -4
  75. package/dist/services/features/telegram-mcp/src/shared/i18n/index.js +46 -0
  76. package/dist/services/features/telegram-mcp/src/shared/i18n/resources/en.js +652 -0
  77. package/dist/services/features/telegram-mcp/src/shared/i18n/resources/ru.js +652 -0
  78. package/dist/services/features/telegram-mcp/src/shared/integrations/memory/processLocalSessionStore.js +27 -0
  79. package/dist/services/features/telegram-mcp/src/shared/integrations/object-storage/minioExchangeStore.js +11 -8
  80. package/dist/services/features/telegram-mcp/src/shared/integrations/redis/stateStore.js +51 -71
  81. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/proxyFetch.js +21 -22
  82. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transport.js +411 -6524
  83. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportAttachmentStore.js +93 -0
  84. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportBroadcastActions.js +385 -0
  85. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConsoleRegistry.js +143 -0
  86. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConstructorWiring.js +633 -0
  87. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportContent.js +84 -0
  88. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportContext.js +78 -0
  89. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportDocumentActions.js +36 -0
  90. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportEventActions.js +292 -0
  91. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportFileHandoffActions.js +352 -0
  92. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportFormatting.js +75 -0
  93. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportGatewayActions.js +44 -0
  94. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLifecycleActions.js +161 -0
  95. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLive.js +56 -0
  96. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLiveActions.js +77 -0
  97. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuCallbacks.js +254 -0
  98. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFactories.js +538 -0
  99. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFingerprints.js +93 -0
  100. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFlow.js +344 -0
  101. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuShell.js +62 -0
  102. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuState.js +408 -0
  103. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuText.js +216 -0
  104. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMessageFlow.js +452 -0
  105. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportOutputActions.js +189 -0
  106. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPartnerActions.js +286 -0
  107. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPayloadState.js +101 -0
  108. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectActions.js +463 -0
  109. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectEntryActions.js +202 -0
  110. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectEvents.js +99 -0
  111. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectMenus.js +138 -0
  112. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectState.js +308 -0
  113. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectView.js +426 -0
  114. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportRequestFlow.js +278 -0
  115. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportSessionActions.js +143 -0
  116. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalActions.js +468 -0
  117. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalRuntime.js +171 -0
  118. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTypes.js +2 -0
  119. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportUtils.js +330 -0
  120. package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportXchangeState.js +107 -0
  121. package/dist/services/features/telegram-mcp/src/shared/integrations/terminal/client.js +255 -0
  122. package/dist/services/features/telegram-mcp/src/shared/integrations/terminal/ptyRegistry.js +543 -0
  123. package/dist/services/features/telegram-mcp/src/shared/integrations/xchange/sqliteRecordStore.js +223 -0
  124. package/dist/services/features/telegram-mcp/src/shared/lib/gatewayScope.js +24 -0
  125. package/dist/services/features/telegram-mcp/src/shared/lib/logger/logger.js +6 -0
  126. package/dist/services/features/telegram-mcp/src/shared/lib/project-identity/projectIdentity.js +147 -76
  127. package/dist/services/features/telegram-mcp/src/shared/lib/telegramXchangeRecords.js +72 -0
  128. package/dist/services/features/telegram-mcp/src/shared/lib/terminalPromptDetection.js +237 -0
  129. package/dist/services/features/telegram-mcp/src/shared/lib/version/versionHandshake.js +129 -1
  130. package/dist/services/features/telegram-mcp/src/shared/lib/xchangeRecordHints.js +98 -0
  131. package/dist/services/features/telegram-mcp/standalone-http.service.js +13 -1
  132. package/dist/services/features/telegram-mcp/terminal-buffer.service.js +42 -0
  133. package/dist/services/features/telegram-mcp/terminal-input.service.js +41 -0
  134. package/dist/services/features/telegram-mcp/tools-sync.service.js +16 -2
  135. package/dist/services/features/telegram-mcp/xchange.service.js +123 -0
  136. package/docs/STANDALONE-ru.md +172 -0
  137. package/docs/STANDALONE.md +172 -0
  138. package/package.json +11 -5
  139. package/scripts/build-package-artifact.sh +27 -0
  140. package/scripts/deploy-gateway.sh +64 -0
  141. package/scripts/deploy-onebot-branch.sh +27 -0
  142. package/scripts/postinstall.js +11 -36
  143. package/STANDALONE-ru.md +0 -274
  144. package/STANDALONE.md +0 -274
  145. package/dist/services/features/telegram-mcp/inbox.service.js +0 -33
  146. package/dist/services/features/telegram-mcp/pair.service.js +0 -33
  147. package/dist/services/features/telegram-mcp/src/app/webapp/tmux.js +0 -10
  148. package/dist/services/features/telegram-mcp/src/features/inbox/model/deleteTelegramInboxMessageTool.js +0 -33
  149. package/dist/services/features/telegram-mcp/src/features/inbox/model/getTelegramInboxCountTool.js +0 -33
  150. package/dist/services/features/telegram-mcp/src/features/inbox/model/getTelegramInboxTool.js +0 -33
  151. package/dist/services/features/telegram-mcp/src/features/inbox/model/inboxService.js +0 -77
  152. package/dist/services/features/telegram-mcp/src/features/pair-session/model/clearSessionPairingTool.js +0 -33
  153. package/dist/services/features/telegram-mcp/src/features/pair-session/model/createSessionPairCodeTool.js +0 -33
  154. package/dist/services/features/telegram-mcp/src/features/pair-session/model/generatePairCode.js +0 -202
  155. package/dist/services/features/telegram-mcp/src/features/session-context/model/getTmuxTargetTool.js +0 -33
  156. package/dist/services/features/telegram-mcp/src/features/session-context/model/setTmuxTargetTool.js +0 -33
  157. package/dist/services/features/telegram-mcp/src/shared/integrations/tmux/client.js +0 -363
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatStorageDetail = formatStorageDetail;
7
+ exports.formatFileDetail = formatFileDetail;
8
+ exports.formatScreenshotDetail = formatScreenshotDetail;
9
+ exports.extractIncomingText = extractIncomingText;
10
+ exports.collectIncomingAttachments = collectIncomingAttachments;
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const transportFormatting_1 = require("./transportFormatting");
13
+ function formatStorageDetail(sessionId, filePath, meta) {
14
+ return [
15
+ "📦 Storage entry",
16
+ "",
17
+ `Session: ${sessionId}`,
18
+ `File: ${(0, transportFormatting_1.formatFilePreviewLabel)(filePath, meta)}`,
19
+ ...(meta?.source ? [`Source: ${meta.source}`] : []),
20
+ ...(meta?.uploadedAt ? [`Saved: ${meta.uploadedAt}`] : []),
21
+ ...(meta?.relativePath ? [`Relative: ${meta.relativePath}`] : []),
22
+ ...(meta?.mimeType ? [`MIME: ${meta.mimeType}`] : []),
23
+ ...(typeof meta?.sizeBytes === "number"
24
+ ? [`Size: ${meta.sizeBytes} bytes`]
25
+ : []),
26
+ `Path: ${filePath}`,
27
+ ...(meta?.caption ? ["", "Caption:", meta.caption] : []),
28
+ ].join("\n");
29
+ }
30
+ function formatFileDetail(sessionId, filePath, meta) {
31
+ const displayName = meta?.originalName ||
32
+ (meta?.relativePath ? node_path_1.default.basename(meta.relativePath) : undefined) ||
33
+ node_path_1.default.basename(filePath);
34
+ return [
35
+ "Session file",
36
+ "",
37
+ `Session: ${sessionId}`,
38
+ `File: ${displayName}`,
39
+ ...(meta?.uploadedAt ? [`Uploaded: ${meta.uploadedAt}`] : []),
40
+ `Path: ${filePath}`,
41
+ ...(meta?.caption ? ["", "Description:", meta.caption] : []),
42
+ ].join("\n");
43
+ }
44
+ function formatScreenshotDetail(sessionId, filePath, meta) {
45
+ return [
46
+ "Browser screenshot",
47
+ "",
48
+ `Session: ${sessionId}`,
49
+ `File: ${node_path_1.default.basename(filePath)}`,
50
+ ...(meta?.uploadedAt ? [`Created: ${meta.uploadedAt}`] : []),
51
+ `Path: ${filePath}`,
52
+ ...(meta?.caption ? ["", "Caption:", meta.caption] : []),
53
+ ].join("\n");
54
+ }
55
+ function extractIncomingText(message) {
56
+ const text = message?.text?.trim() || message?.caption?.trim();
57
+ return text && text.length > 0 ? text : null;
58
+ }
59
+ function collectIncomingAttachments(message) {
60
+ if (!message) {
61
+ return [];
62
+ }
63
+ const attachments = [];
64
+ if (Array.isArray(message.photo) && message.photo.length > 0) {
65
+ const largestPhoto = [...message.photo].sort((left, right) => right.width * right.height - left.width * left.height)[0];
66
+ if (largestPhoto?.file_id) {
67
+ attachments.push({
68
+ fileId: largestPhoto.file_id,
69
+ preferredName: `photo-${message.message_id}.jpg`,
70
+ mimeType: "image/jpeg",
71
+ });
72
+ }
73
+ }
74
+ if (message.document?.file_id) {
75
+ attachments.push({
76
+ fileId: message.document.file_id,
77
+ preferredName: message.document.file_name || `document-${message.message_id}.bin`,
78
+ ...(message.document.mime_type
79
+ ? { mimeType: message.document.mime_type }
80
+ : {}),
81
+ });
82
+ }
83
+ return attachments;
84
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransportContext = void 0;
4
+ const i18n_1 = require("../../i18n");
5
+ class TransportContext {
6
+ host;
7
+ constructor(host) {
8
+ this.host = host;
9
+ }
10
+ getPrincipalFromContext(ctx) {
11
+ const chatId = ctx.chat?.id;
12
+ const userId = ctx.from?.id;
13
+ if (!chatId || !userId) {
14
+ return null;
15
+ }
16
+ return {
17
+ telegramChatId: chatId,
18
+ telegramUserId: userId,
19
+ };
20
+ }
21
+ async resolveLocaleForContext(ctx) {
22
+ if (this.host.config?.telegram?.debugLanguage) {
23
+ return (0, i18n_1.normalizeLocale)(this.host.config.telegram.debugLanguage);
24
+ }
25
+ const telegramUserId = ctx.from?.id;
26
+ const telegramLanguageCode = ctx.from?.language_code;
27
+ if (!telegramUserId) {
28
+ return (0, i18n_1.normalizeLocale)(telegramLanguageCode);
29
+ }
30
+ const storedLocale = await this.host.localeStore?.getUserLocale?.(telegramUserId);
31
+ if (storedLocale) {
32
+ return (0, i18n_1.normalizeLocale)(storedLocale);
33
+ }
34
+ const detectedLocale = (0, i18n_1.normalizeLocale)(telegramLanguageCode);
35
+ await this.host.localeStore?.setUserLocale?.(telegramUserId, detectedLocale);
36
+ return detectedLocale;
37
+ }
38
+ async resolveLocaleForTelegramUserId(telegramUserId, telegramLanguageCode) {
39
+ if (this.host.config?.telegram?.debugLanguage) {
40
+ return (0, i18n_1.normalizeLocale)(this.host.config.telegram.debugLanguage);
41
+ }
42
+ if (!telegramUserId) {
43
+ return (0, i18n_1.normalizeLocale)(telegramLanguageCode);
44
+ }
45
+ const storedLocale = await this.host.localeStore?.getUserLocale?.(telegramUserId);
46
+ if (storedLocale) {
47
+ return (0, i18n_1.normalizeLocale)(storedLocale);
48
+ }
49
+ const detectedLocale = (0, i18n_1.normalizeLocale)(telegramLanguageCode);
50
+ await this.host.localeStore?.setUserLocale?.(telegramUserId, detectedLocale);
51
+ return detectedLocale;
52
+ }
53
+ async tForContext(ctx, key, options) {
54
+ return this.t(await this.resolveLocaleForContext(ctx), key, options);
55
+ }
56
+ async tForTelegramUserId(telegramUserId, key, options) {
57
+ return this.t(await this.resolveLocaleForTelegramUserId(telegramUserId), key, options);
58
+ }
59
+ t(locale, key, options) {
60
+ return (0, i18n_1.translate)(locale, key, options);
61
+ }
62
+ getGatewayActorFromContext(ctx) {
63
+ const firstName = ctx.from?.first_name?.trim();
64
+ const lastName = ctx.from?.last_name?.trim();
65
+ const username = ctx.from?.username?.trim();
66
+ const displayName = [firstName, lastName].filter(Boolean).join(" ").trim();
67
+ if (!firstName && !lastName && !username) {
68
+ return undefined;
69
+ }
70
+ return {
71
+ ...(username ? { telegramUsername: username } : {}),
72
+ ...(firstName ? { telegramFirstName: firstName } : {}),
73
+ ...(lastName ? { telegramLastName: lastName } : {}),
74
+ ...(displayName ? { telegramDisplayName: displayName } : {}),
75
+ };
76
+ }
77
+ }
78
+ exports.TransportContext = TransportContext;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransportDocumentActions = void 0;
4
+ const grammy_1 = require("grammy");
5
+ class TransportDocumentActions {
6
+ host;
7
+ constructor(host) {
8
+ this.host = host;
9
+ }
10
+ async replyDocumentWithRetry(ctx, document, options = {}, meta) {
11
+ let attempt = 0;
12
+ while (true) {
13
+ attempt += 1;
14
+ try {
15
+ await ctx.replyWithDocument(document, options);
16
+ return;
17
+ }
18
+ catch (error) {
19
+ if (!(error instanceof grammy_1.GrammyError) || error.error_code !== 429) {
20
+ throw error;
21
+ }
22
+ const retryAfterSeconds = Math.max(1, error.parameters.retry_after ?? 1);
23
+ this.host.logger.warn("Telegram rate limit hit while sending document, cooling down", {
24
+ kind: meta.kind,
25
+ sessionId: meta.sessionId,
26
+ requestId: meta.requestId,
27
+ attempt,
28
+ retryAfterSeconds,
29
+ description: error.description,
30
+ });
31
+ await new Promise((resolve) => setTimeout(resolve, retryAfterSeconds * 1000));
32
+ }
33
+ }
34
+ }
35
+ }
36
+ exports.TransportDocumentActions = TransportDocumentActions;
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransportEventActions = void 0;
4
+ const grammy_1 = require("grammy");
5
+ const relay_1 = require("../../../app/webapp/relay");
6
+ const projectIdentity_1 = require("../../lib/project-identity/projectIdentity");
7
+ const telegramXchangeRecords_1 = require("../../lib/telegramXchangeRecords");
8
+ class TransportEventActions {
9
+ host;
10
+ constructor(host) {
11
+ this.host = host;
12
+ }
13
+ async handleToolsUpdatedEvent(input) {
14
+ const session = await this.host.sessionStore.getSession(input.local_session_id);
15
+ if (!session) {
16
+ this.host.logger.warn("Skipping tools update event because local session is unavailable", {
17
+ sessionId: input.local_session_id,
18
+ reason: input.reason,
19
+ });
20
+ return;
21
+ }
22
+ this.host.logger.info("TOOLS.md update event received for console", {
23
+ sessionId: session.sessionId,
24
+ sessionLabel: session.label ?? input.session_label ?? session.sessionId,
25
+ reason: input.reason,
26
+ gatewayToolsHash: input.gateway_tools_hash,
27
+ clientToolsHash: input.client_tools_hash,
28
+ });
29
+ const binding = await this.host.bindingStore.getBinding(session.sessionId);
30
+ if (!binding) {
31
+ return;
32
+ }
33
+ await this.host.sendNotification({
34
+ sessionId: session.sessionId,
35
+ ...(session.label ? { sessionLabel: session.label } : {}),
36
+ recipient: {
37
+ telegramChatId: binding.telegramChatId,
38
+ telegramUserId: binding.telegramUserId,
39
+ },
40
+ message: [
41
+ await this.host.tForTelegramUserId(binding.telegramUserId, "menu:notices.tools.changed"),
42
+ await this.host.tForTelegramUserId(binding.telegramUserId, "menu:notices.tools.session", {
43
+ sessionName: session.label ?? input.session_label ?? session.sessionId,
44
+ }),
45
+ await this.host.tForTelegramUserId(binding.telegramUserId, "menu:notices.tools.action_required"),
46
+ ].join("\n"),
47
+ });
48
+ await this.host.sessionStore.setSession({
49
+ ...session,
50
+ lastNotifiedToolsHash: input.gateway_tools_hash,
51
+ updatedAt: new Date().toISOString(),
52
+ });
53
+ if (session.cwd?.trim()) {
54
+ (0, projectIdentity_1.writeSessionMarkerState)({
55
+ cwd: session.cwd,
56
+ localSessionId: session.sessionId,
57
+ lastSeenToolsHash: session.lastSeenToolsHash,
58
+ lastNotifiedToolsHash: input.gateway_tools_hash,
59
+ logger: this.host.logger,
60
+ });
61
+ }
62
+ }
63
+ async handleGatewayVersionCompatibilityEvent(input) {
64
+ const session = await this.host.sessionStore.getSession(input.local_session_id);
65
+ if (!session) {
66
+ this.host.logger.warn("Skipping gateway version compatibility event because local session is unavailable", {
67
+ sessionId: input.local_session_id,
68
+ compatibility: input.compatibility,
69
+ });
70
+ return;
71
+ }
72
+ const title = input.compatibility === "reject"
73
+ ? "Gateway/client protocol mismatch blocks transport."
74
+ : "Gateway/client version mismatch detected.";
75
+ await (0, telegramXchangeRecords_1.writeLocalTaskXchangeRecord)({
76
+ config: this.host.config,
77
+ session,
78
+ sessionId: session.sessionId,
79
+ summary: title,
80
+ kind: input.compatibility,
81
+ text: [
82
+ title,
83
+ `Session: ${session.label ?? input.session_label ?? session.sessionId}`,
84
+ `Compatibility: ${input.compatibility}`,
85
+ `Client package: ${input.client_package_version}`,
86
+ `Client protocol: ${input.client_protocol_version}`,
87
+ `Gateway package: ${input.gateway_package_version}`,
88
+ `Gateway protocol: ${input.gateway_protocol_version}`,
89
+ `Client capabilities: ${input.client_capabilities.join(", ") || "none"}`,
90
+ `Gateway capabilities: ${input.gateway_capabilities.join(", ") || "none"}`,
91
+ ...(input.reasons.length > 0
92
+ ? ["", "# Reasons", ...input.reasons.map((reason) => `- ${reason}`)]
93
+ : []),
94
+ "",
95
+ "# Action Required",
96
+ input.instruction,
97
+ ...(input.compatibility === "reject"
98
+ ? [
99
+ "Do not continue collaboration, delivery, or live relay work until this client is upgraded.",
100
+ ]
101
+ : [
102
+ "Upgrade the older side soon and verify the updated tools content before continuing sensitive work.",
103
+ ]),
104
+ ].join("\n"),
105
+ createdAt: new Date().toISOString(),
106
+ actionDesc: "Read the compatibility details, stop sensitive work on this console if required, then upgrade the incompatible side before continuing.",
107
+ tools: ["get_xchange_record", "mark_xchange_record_read", "refresh_tools_markdown"],
108
+ tags: ["system", "version", input.compatibility],
109
+ });
110
+ await this.host.nudgeSessionInbox(session.sessionId);
111
+ const binding = await this.host.bindingStore.getBinding(session.sessionId);
112
+ if (!binding) {
113
+ return;
114
+ }
115
+ await this.host.sendNotification({
116
+ sessionId: session.sessionId,
117
+ ...(session.label ? { sessionLabel: session.label } : {}),
118
+ recipient: {
119
+ telegramChatId: binding.telegramChatId,
120
+ telegramUserId: binding.telegramUserId,
121
+ },
122
+ message: [
123
+ await this.host.tForTelegramUserId(binding.telegramUserId, input.compatibility === "reject"
124
+ ? "menu:notices.version.reject"
125
+ : "menu:notices.version.warn"),
126
+ await this.host.tForTelegramUserId(binding.telegramUserId, "menu:notices.version.session", {
127
+ sessionName: session.label ?? input.session_label ?? session.sessionId,
128
+ }),
129
+ await this.host.tForTelegramUserId(binding.telegramUserId, "menu:notices.version.client", {
130
+ packageVersion: input.client_package_version,
131
+ protocolVersion: input.client_protocol_version,
132
+ }),
133
+ await this.host.tForTelegramUserId(binding.telegramUserId, "menu:notices.version.gateway", {
134
+ packageVersion: input.gateway_package_version,
135
+ protocolVersion: input.gateway_protocol_version,
136
+ }),
137
+ input.instruction,
138
+ ].join("\n"),
139
+ });
140
+ }
141
+ async handleLiveViewApprovalRequestEvent(input) {
142
+ const targetSession = (await this.host.sessionStore.getSession(input.target_local_session_id)) ??
143
+ (await this.host.sessionStore.getSession((0, relay_1.buildLiveRelaySessionId)(input.target_client_uuid, input.target_local_session_id)));
144
+ if (!targetSession) {
145
+ this.host.logger.warn("Skipping live approval request because target session is unavailable", {
146
+ targetLocalSessionId: input.target_local_session_id,
147
+ sourceLocalSessionId: input.source_local_session_id,
148
+ });
149
+ return;
150
+ }
151
+ const binding = await this.host.bindingStore.getBinding(targetSession.sessionId);
152
+ if (!binding) {
153
+ this.host.logger.warn("Skipping live approval request because target session has no active Telegram route", {
154
+ sessionId: targetSession.sessionId,
155
+ sourceLocalSessionId: input.source_local_session_id,
156
+ });
157
+ return;
158
+ }
159
+ const locale = await this.host.resolveLocaleForTelegramUserId(binding.telegramUserId);
160
+ const payloadKey = await this.host.createLiveApprovalMenuPayload({
161
+ sessionId: targetSession.sessionId,
162
+ sourceSessionId: input.source_session_id,
163
+ sourceSessionLabel: input.source_session_label,
164
+ sourceClientUuid: input.source_client_uuid,
165
+ sourceLocalSessionId: input.source_local_session_id,
166
+ targetSessionId: input.target_session_id,
167
+ targetSessionLabel: input.target_session_label,
168
+ targetClientUuid: input.target_client_uuid,
169
+ targetLocalSessionId: input.target_local_session_id,
170
+ ...(input.project_uuid ? { projectUuid: input.project_uuid } : {}),
171
+ ...(input.project_name ? { projectName: input.project_name } : {}),
172
+ });
173
+ const sent = await this.host.sendChatMessage(binding.telegramChatId, [
174
+ this.host.t(locale, "menu:live.approval.request_title"),
175
+ "",
176
+ ...(input.project_name
177
+ ? [
178
+ this.host.t(locale, "menu:live.approval.project", {
179
+ projectName: input.project_name,
180
+ }),
181
+ ]
182
+ : []),
183
+ this.host.t(locale, "menu:live.approval.route", {
184
+ sourceSessionName: input.source_session_label,
185
+ targetSessionName: input.target_session_label,
186
+ }),
187
+ "",
188
+ this.host.t(locale, "menu:live.approval.request_message", {
189
+ sourceSessionName: input.source_session_label,
190
+ }),
191
+ ].join("\n"), {
192
+ reply_markup: new grammy_1.InlineKeyboard()
193
+ .text(`✅ ${this.host.t(locale, "menu:live.approval.approve")}`, `live-approval:approve:${payloadKey}`)
194
+ .text(`❌ ${this.host.t(locale, "menu:live.approval.deny")}`, `live-approval:deny:${payloadKey}`),
195
+ }, {
196
+ kind: "notification",
197
+ sessionId: targetSession.sessionId,
198
+ });
199
+ this.host.logger.info("Telegram live approval request delivered", {
200
+ sessionId: targetSession.sessionId,
201
+ telegramChatId: binding.telegramChatId,
202
+ telegramUserId: binding.telegramUserId,
203
+ messageId: sent.message_id,
204
+ sourceLocalSessionId: input.source_local_session_id,
205
+ });
206
+ }
207
+ async handleLiveViewApprovalResolvedEvent(input) {
208
+ const sourceSession = (await this.host.sessionStore.getSession(input.source_local_session_id)) ??
209
+ (await this.host.sessionStore.getSession((0, relay_1.buildLiveRelaySessionId)(input.source_client_uuid, input.source_local_session_id)));
210
+ if (!sourceSession) {
211
+ this.host.logger.warn("Skipping live approval resolution because source session is unavailable", {
212
+ sourceLocalSessionId: input.source_local_session_id,
213
+ targetLocalSessionId: input.target_local_session_id,
214
+ });
215
+ return;
216
+ }
217
+ const binding = await this.host.bindingStore.getBinding(sourceSession.sessionId);
218
+ if (!binding) {
219
+ this.host.logger.warn("Skipping live approval resolution because source session has no active Telegram route", {
220
+ sessionId: sourceSession.sessionId,
221
+ targetLocalSessionId: input.target_local_session_id,
222
+ });
223
+ return;
224
+ }
225
+ const locale = await this.host.resolveLocaleForTelegramUserId(binding.telegramUserId);
226
+ if (!input.approved) {
227
+ await this.host.sendNotification({
228
+ sessionId: sourceSession.sessionId,
229
+ ...(sourceSession.label ? { sessionLabel: sourceSession.label } : {}),
230
+ recipient: {
231
+ telegramChatId: binding.telegramChatId,
232
+ telegramUserId: binding.telegramUserId,
233
+ },
234
+ message: [
235
+ this.host.t(locale, "menu:live.approval.denied"),
236
+ ...(input.project_name
237
+ ? [
238
+ this.host.t(locale, "menu:live.approval.project", {
239
+ projectName: input.project_name,
240
+ }),
241
+ ]
242
+ : []),
243
+ this.host.t(locale, "menu:live.approval.route", {
244
+ sourceSessionName: input.source_session_label,
245
+ targetSessionName: input.target_session_label,
246
+ }),
247
+ ].join("\n"),
248
+ });
249
+ return;
250
+ }
251
+ const liveViewUrl = this.host.buildLiveViewUrl({
252
+ targetSessionId: input.target_session_id,
253
+ targetClientUuid: input.target_client_uuid,
254
+ targetLocalSessionId: input.target_local_session_id,
255
+ });
256
+ if (!liveViewUrl) {
257
+ throw new Error("Unable to build Live View URL for approved request.");
258
+ }
259
+ const sent = await this.host.sendChatMessage(binding.telegramChatId, [
260
+ this.host.t(locale, "menu:live.approval.approved"),
261
+ "",
262
+ ...(input.project_name
263
+ ? [
264
+ this.host.t(locale, "menu:live.approval.project", {
265
+ projectName: input.project_name,
266
+ }),
267
+ ]
268
+ : []),
269
+ this.host.t(locale, "menu:live.approval.route", {
270
+ sourceSessionName: input.source_session_label,
271
+ targetSessionName: input.target_session_label,
272
+ }),
273
+ "",
274
+ this.host.t(locale, "menu:live.actions.choose_mode"),
275
+ ].join("\n"), {
276
+ reply_markup: this.host.buildLiveViewKeyboard((mode) => this.host.buildLiveViewUrl({
277
+ targetSessionId: input.target_session_id,
278
+ targetClientUuid: input.target_client_uuid,
279
+ targetLocalSessionId: input.target_local_session_id,
280
+ launchMode: mode,
281
+ }), locale),
282
+ }, {
283
+ kind: "notification",
284
+ sessionId: sourceSession.sessionId,
285
+ });
286
+ this.host.webAppLaunchRegistry.set(binding.telegramUserId, sourceSession.sessionId, this.host.config.webapp.initDataTtlSeconds, {
287
+ telegramChatId: binding.telegramChatId,
288
+ telegramMessageId: sent.message_id,
289
+ });
290
+ }
291
+ }
292
+ exports.TransportEventActions = TransportEventActions;