@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.
- package/.env.example.client +42 -50
- package/.env.example.gateway +49 -61
- package/CHANGELOG.md +3 -3
- package/README-ru.md +205 -384
- package/README.md +195 -1194
- package/TOOLS.md +294 -377
- package/VERSION.md +36 -10
- package/config/codex/plugins/telly-workflows/.codex-plugin/plugin.json +18 -0
- package/config/codex/plugins/telly-workflows/references/invariants.md +10 -0
- package/config/codex/plugins/telly-workflows/skills/telly-browser-screenshot/SKILL.md +27 -0
- package/config/codex/plugins/telly-workflows/skills/telly-collab-artifact/SKILL.md +22 -0
- package/config/codex/plugins/telly-workflows/skills/telly-human-telegram/SKILL.md +31 -0
- package/config/codex/plugins/telly-workflows/skills/telly-partner-note/SKILL.md +36 -0
- package/config/templates/env.both.template +40 -20
- package/config/templates/env.client.template +34 -18
- package/config/templates/env.gateway.template +38 -22
- package/dist/cli.js +322 -75
- package/dist/codexPluginInstaller.js +215 -0
- package/dist/lib/mixins/session.errors.js +34 -1
- package/dist/lib/pinoTargets.js +2 -2
- package/dist/moleculer.config.js +7 -5
- package/dist/services/features/telegram-mcp/approval.service.js +1 -1
- package/dist/services/features/telegram-mcp/browser.service.js +95 -2
- package/dist/services/features/telegram-mcp/collaboration.service.js +41 -4
- package/dist/services/features/telegram-mcp/ensuredb.service.js +145 -26
- package/dist/services/features/telegram-mcp/gateway-delivery.service.js +285 -103
- package/dist/services/features/telegram-mcp/gateway-rmq.service.js +3 -2
- package/dist/services/features/telegram-mcp/gateway-socket.service.js +905 -87
- package/dist/services/features/telegram-mcp/gateway.service.js +876 -81
- package/dist/services/features/telegram-mcp/mcp-http.service.js +9 -1
- package/dist/services/features/telegram-mcp/mcp-server.service.js +17 -26
- package/dist/services/features/telegram-mcp/notify.service.js +128 -2
- package/dist/services/features/telegram-mcp/runtime.service.js +27 -7
- package/dist/services/features/telegram-mcp/session-context.service.js +29 -2
- package/dist/services/features/telegram-mcp/src/app/bootstrap/runtime.js +133 -10
- package/dist/services/features/telegram-mcp/src/app/config/env.js +161 -51
- package/dist/services/features/telegram-mcp/src/app/http.js +375 -42
- package/dist/services/features/telegram-mcp/src/app/webapp/assets.js +386 -58
- package/dist/services/features/telegram-mcp/src/app/webapp/auth.js +3 -0
- package/dist/services/features/telegram-mcp/src/app/webapp/terminal.js +12 -0
- package/dist/services/features/telegram-mcp/src/entities/request/model/schema.js +116 -104
- package/dist/services/features/telegram-mcp/src/entities/xchange/model/types.js +2 -0
- package/dist/services/features/telegram-mcp/src/features/ask-user/model/askUserTelegram.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserScreenshotTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserService.js +249 -19
- package/dist/services/features/telegram-mcp/src/features/collaboration/model/gatewaySessionsService.js +71 -0
- package/dist/services/features/telegram-mcp/src/features/collaboration/model/listGatewaySessionsTool.js +33 -0
- package/dist/services/features/telegram-mcp/src/features/collaboration/model/localCollaborationBackend.js +93 -82
- package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerFileService.js +47 -5
- package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerFileTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/collaboration/model/sendPartnerNoteTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/distributed-client/model/gatewayClientAccess.js +82 -0
- package/dist/services/features/telegram-mcp/src/features/distributed-client/model/gatewayCollaborationBackend.js +22 -14
- package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/gatewayHttpService.js +649 -75
- package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/remoteConsoleActionClient.js +76 -0
- package/dist/services/features/telegram-mcp/src/features/embedded-runtime/model/embeddedRuntimeBroker.js +92 -0
- package/dist/services/features/telegram-mcp/src/features/foreground-terminal/model/foregroundTerminalRuntime.js +192 -0
- package/dist/services/features/telegram-mcp/src/features/notify/model/notifyService.js +382 -3
- package/dist/services/features/telegram-mcp/src/features/notify/model/notifyTelegramTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/notify/model/sendFileToTelegramTool.js +33 -0
- package/dist/services/features/telegram-mcp/src/features/session-context/model/clearSessionContextTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/session-context/model/getSessionContextTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/session-context/model/renameSessionTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/session-context/model/sessionContextService.js +42 -200
- package/dist/services/features/telegram-mcp/src/features/session-context/model/setSessionContextTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/terminal-buffer/model/terminalBufferService.js +96 -0
- package/dist/services/features/telegram-mcp/src/features/terminal-input/model/terminalInputService.js +97 -0
- package/dist/services/features/telegram-mcp/src/features/tools-sync/model/refreshToolsMarkdownService.js +107 -58
- package/dist/services/features/telegram-mcp/src/features/tools-sync/model/refreshToolsMarkdownTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/xchange/model/getXchangeRecordTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/xchange/model/listXchangeRecordsTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/xchange/model/markXchangeRecordReadTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/xchange/model/xchangeService.js +169 -0
- package/dist/services/features/telegram-mcp/src/processes/human-approval/model/orchestrator.js +5 -4
- package/dist/services/features/telegram-mcp/src/shared/i18n/index.js +46 -0
- package/dist/services/features/telegram-mcp/src/shared/i18n/resources/en.js +652 -0
- package/dist/services/features/telegram-mcp/src/shared/i18n/resources/ru.js +652 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/memory/processLocalSessionStore.js +27 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/object-storage/minioExchangeStore.js +11 -8
- package/dist/services/features/telegram-mcp/src/shared/integrations/redis/stateStore.js +51 -71
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/proxyFetch.js +21 -22
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transport.js +411 -6524
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportAttachmentStore.js +93 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportBroadcastActions.js +385 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConsoleRegistry.js +143 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConstructorWiring.js +633 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportContent.js +84 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportContext.js +78 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportDocumentActions.js +36 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportEventActions.js +292 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportFileHandoffActions.js +352 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportFormatting.js +75 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportGatewayActions.js +44 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLifecycleActions.js +161 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLive.js +56 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportLiveActions.js +77 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuCallbacks.js +254 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFactories.js +538 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFingerprints.js +93 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuFlow.js +344 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuShell.js +62 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuState.js +408 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuText.js +216 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMessageFlow.js +452 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportOutputActions.js +189 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPartnerActions.js +286 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPayloadState.js +101 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectActions.js +463 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectEntryActions.js +202 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectEvents.js +99 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectMenus.js +138 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectState.js +308 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportProjectView.js +426 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportRequestFlow.js +278 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportSessionActions.js +143 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalActions.js +468 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalRuntime.js +171 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTypes.js +2 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportUtils.js +330 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportXchangeState.js +107 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/terminal/client.js +255 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/terminal/ptyRegistry.js +543 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/xchange/sqliteRecordStore.js +223 -0
- package/dist/services/features/telegram-mcp/src/shared/lib/gatewayScope.js +24 -0
- package/dist/services/features/telegram-mcp/src/shared/lib/logger/logger.js +6 -0
- package/dist/services/features/telegram-mcp/src/shared/lib/project-identity/projectIdentity.js +147 -76
- package/dist/services/features/telegram-mcp/src/shared/lib/telegramXchangeRecords.js +72 -0
- package/dist/services/features/telegram-mcp/src/shared/lib/terminalPromptDetection.js +237 -0
- package/dist/services/features/telegram-mcp/src/shared/lib/version/versionHandshake.js +129 -1
- package/dist/services/features/telegram-mcp/src/shared/lib/xchangeRecordHints.js +98 -0
- package/dist/services/features/telegram-mcp/standalone-http.service.js +13 -1
- package/dist/services/features/telegram-mcp/terminal-buffer.service.js +42 -0
- package/dist/services/features/telegram-mcp/terminal-input.service.js +41 -0
- package/dist/services/features/telegram-mcp/tools-sync.service.js +16 -2
- package/dist/services/features/telegram-mcp/xchange.service.js +123 -0
- package/docs/STANDALONE-ru.md +172 -0
- package/docs/STANDALONE.md +172 -0
- package/package.json +11 -5
- package/scripts/build-package-artifact.sh +27 -0
- package/scripts/deploy-gateway.sh +64 -0
- package/scripts/deploy-onebot-branch.sh +27 -0
- package/scripts/postinstall.js +11 -36
- package/STANDALONE-ru.md +0 -274
- package/STANDALONE.md +0 -274
- package/dist/services/features/telegram-mcp/inbox.service.js +0 -33
- package/dist/services/features/telegram-mcp/pair.service.js +0 -33
- package/dist/services/features/telegram-mcp/src/app/webapp/tmux.js +0 -10
- package/dist/services/features/telegram-mcp/src/features/inbox/model/deleteTelegramInboxMessageTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/features/inbox/model/getTelegramInboxCountTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/features/inbox/model/getTelegramInboxTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/features/inbox/model/inboxService.js +0 -77
- package/dist/services/features/telegram-mcp/src/features/pair-session/model/clearSessionPairingTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/features/pair-session/model/createSessionPairCodeTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/features/pair-session/model/generatePairCode.js +0 -202
- package/dist/services/features/telegram-mcp/src/features/session-context/model/getTmuxTargetTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/features/session-context/model/setTmuxTargetTool.js +0 -33
- package/dist/services/features/telegram-mcp/src/shared/integrations/tmux/client.js +0 -363
package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportRequestFlow.js
ADDED
|
@@ -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;
|