@openacp/cli 2026.405.1 → 2026.406.1
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/dist/cli.js +286 -235
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +132 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2774,6 +2774,8 @@ declare class TelegramAdapter extends MessagingAdapter {
|
|
|
2774
2774
|
private controlMsgIds;
|
|
2775
2775
|
private _threadReadyHandler?;
|
|
2776
2776
|
private _configChangedHandler?;
|
|
2777
|
+
/** Mutable ref passed to callbacks before topics are ready; updated in-place by initTopicDependentFeatures */
|
|
2778
|
+
private _systemTopicIds;
|
|
2777
2779
|
/** True once topics are initialized and Phase 2 is complete */
|
|
2778
2780
|
private _topicsInitialized;
|
|
2779
2781
|
/** Background watcher timer — cancelled on stop() or when topics succeed */
|
package/dist/index.js
CHANGED
|
@@ -8096,7 +8096,10 @@ function setupAllCallbacks(bot, core, chatId, systemTopicIds, getAssistantSessio
|
|
|
8096
8096
|
const menuRegistry = core.lifecycleManager?.serviceRegistry?.get("menu-registry");
|
|
8097
8097
|
if (!menuRegistry) return;
|
|
8098
8098
|
const item = menuRegistry.getItem(itemId);
|
|
8099
|
-
if (!item)
|
|
8099
|
+
if (!item) {
|
|
8100
|
+
log30.warn({ itemId }, "Menu item not found in registry");
|
|
8101
|
+
return;
|
|
8102
|
+
}
|
|
8100
8103
|
const topicId = ctx.callbackQuery.message?.message_thread_id;
|
|
8101
8104
|
const registry = core.lifecycleManager?.serviceRegistry?.get("command-registry");
|
|
8102
8105
|
switch (item.action.type) {
|
|
@@ -8180,7 +8183,7 @@ ${lines}`, { parse_mode: "HTML" }).catch(() => {
|
|
|
8180
8183
|
}
|
|
8181
8184
|
});
|
|
8182
8185
|
}
|
|
8183
|
-
var STATIC_COMMANDS;
|
|
8186
|
+
var log30, STATIC_COMMANDS;
|
|
8184
8187
|
var init_commands = __esm({
|
|
8185
8188
|
"src/plugins/telegram/commands/index.ts"() {
|
|
8186
8189
|
"use strict";
|
|
@@ -8193,6 +8196,7 @@ var init_commands = __esm({
|
|
|
8193
8196
|
init_tunnel2();
|
|
8194
8197
|
init_switch();
|
|
8195
8198
|
init_telegram_overrides();
|
|
8199
|
+
init_log();
|
|
8196
8200
|
init_menu();
|
|
8197
8201
|
init_menu();
|
|
8198
8202
|
init_telegram_overrides();
|
|
@@ -8204,6 +8208,7 @@ var init_commands = __esm({
|
|
|
8204
8208
|
init_settings();
|
|
8205
8209
|
init_doctor2();
|
|
8206
8210
|
init_resume();
|
|
8211
|
+
log30 = createChildLogger({ module: "telegram-menu-callbacks" });
|
|
8207
8212
|
STATIC_COMMANDS = [
|
|
8208
8213
|
{ command: "new", description: "Create new session" },
|
|
8209
8214
|
{ command: "newchat", description: "New chat, same agent & workspace" },
|
|
@@ -8239,14 +8244,14 @@ var init_commands = __esm({
|
|
|
8239
8244
|
// src/plugins/telegram/permissions.ts
|
|
8240
8245
|
import { InlineKeyboard as InlineKeyboard11 } from "grammy";
|
|
8241
8246
|
import { nanoid as nanoid4 } from "nanoid";
|
|
8242
|
-
var
|
|
8247
|
+
var log31, PermissionHandler;
|
|
8243
8248
|
var init_permissions = __esm({
|
|
8244
8249
|
"src/plugins/telegram/permissions.ts"() {
|
|
8245
8250
|
"use strict";
|
|
8246
8251
|
init_formatting();
|
|
8247
8252
|
init_topics();
|
|
8248
8253
|
init_log();
|
|
8249
|
-
|
|
8254
|
+
log31 = createChildLogger({ module: "telegram-permissions" });
|
|
8250
8255
|
PermissionHandler = class {
|
|
8251
8256
|
constructor(bot, chatId, getSession, sendNotification) {
|
|
8252
8257
|
this.bot = bot;
|
|
@@ -8290,11 +8295,11 @@ ${escapeHtml(request.description)}`,
|
|
|
8290
8295
|
});
|
|
8291
8296
|
}
|
|
8292
8297
|
setupCallbackHandler() {
|
|
8293
|
-
this.bot.on("callback_query:data", async (ctx) => {
|
|
8298
|
+
this.bot.on("callback_query:data", async (ctx, next) => {
|
|
8294
8299
|
const data = ctx.callbackQuery.data;
|
|
8295
|
-
if (!data.startsWith("p:")) return;
|
|
8300
|
+
if (!data.startsWith("p:")) return next();
|
|
8296
8301
|
const parts = data.split(":");
|
|
8297
|
-
if (parts.length < 3) return;
|
|
8302
|
+
if (parts.length < 3) return next();
|
|
8298
8303
|
const [, callbackKey, optionId] = parts;
|
|
8299
8304
|
const pending = this.pending.get(callbackKey);
|
|
8300
8305
|
if (!pending) {
|
|
@@ -8306,7 +8311,7 @@ ${escapeHtml(request.description)}`,
|
|
|
8306
8311
|
}
|
|
8307
8312
|
const session = this.getSession(pending.sessionId);
|
|
8308
8313
|
const isAllow = pending.options.find((o) => o.id === optionId)?.isAllow ?? false;
|
|
8309
|
-
|
|
8314
|
+
log31.info({ requestId: pending.requestId, optionId, isAllow }, "Permission responded");
|
|
8310
8315
|
if (session?.permissionGate.requestId === pending.requestId) {
|
|
8311
8316
|
session.permissionGate.resolve(optionId);
|
|
8312
8317
|
}
|
|
@@ -8326,7 +8331,7 @@ ${escapeHtml(request.description)}`,
|
|
|
8326
8331
|
});
|
|
8327
8332
|
|
|
8328
8333
|
// src/plugins/telegram/activity.ts
|
|
8329
|
-
var
|
|
8334
|
+
var log32, THINKING_REFRESH_MS, THINKING_MAX_MS, ThinkingIndicator, ToolCard, ActivityTracker2;
|
|
8330
8335
|
var init_activity = __esm({
|
|
8331
8336
|
"src/plugins/telegram/activity.ts"() {
|
|
8332
8337
|
"use strict";
|
|
@@ -8336,7 +8341,7 @@ var init_activity = __esm({
|
|
|
8336
8341
|
init_stream_accumulator();
|
|
8337
8342
|
init_stream_accumulator();
|
|
8338
8343
|
init_display_spec_builder();
|
|
8339
|
-
|
|
8344
|
+
log32 = createChildLogger({ module: "telegram:activity" });
|
|
8340
8345
|
THINKING_REFRESH_MS = 15e3;
|
|
8341
8346
|
THINKING_MAX_MS = 3 * 60 * 1e3;
|
|
8342
8347
|
ThinkingIndicator = class {
|
|
@@ -8377,7 +8382,7 @@ var init_activity = __esm({
|
|
|
8377
8382
|
}
|
|
8378
8383
|
}
|
|
8379
8384
|
} catch (err) {
|
|
8380
|
-
|
|
8385
|
+
log32.warn({ err }, "ThinkingIndicator.show() failed");
|
|
8381
8386
|
} finally {
|
|
8382
8387
|
this.sending = false;
|
|
8383
8388
|
}
|
|
@@ -8545,7 +8550,7 @@ var init_activity = __esm({
|
|
|
8545
8550
|
this.tracer?.log("telegram", { action: "telegram:delete:overflow", sessionId: this.sessionId, msgId: staleId });
|
|
8546
8551
|
}
|
|
8547
8552
|
} catch (err) {
|
|
8548
|
-
|
|
8553
|
+
log32.warn({ err }, "[ToolCard] send/edit failed");
|
|
8549
8554
|
}
|
|
8550
8555
|
}
|
|
8551
8556
|
};
|
|
@@ -8649,7 +8654,7 @@ var init_activity = __esm({
|
|
|
8649
8654
|
const entry = this.toolStateMap.merge(id, status, rawInput, content, viewerLinks, diffStats);
|
|
8650
8655
|
if (!existed || !entry) return;
|
|
8651
8656
|
if (viewerLinks || entry.viewerLinks) {
|
|
8652
|
-
|
|
8657
|
+
log32.debug({ toolId: id, status, hasIncomingLinks: !!viewerLinks, hasEntryLinks: !!entry.viewerLinks, entryLinks: entry.viewerLinks }, "toolUpdate: viewer links trace");
|
|
8653
8658
|
}
|
|
8654
8659
|
const spec = this.specBuilder.buildToolSpec(entry, this._outputMode, this.sessionContext);
|
|
8655
8660
|
this.toolCard.updateFromSpec(spec);
|
|
@@ -8968,13 +8973,13 @@ var init_draft_manager = __esm({
|
|
|
8968
8973
|
});
|
|
8969
8974
|
|
|
8970
8975
|
// src/plugins/telegram/skill-command-manager.ts
|
|
8971
|
-
var
|
|
8976
|
+
var log33, SkillCommandManager;
|
|
8972
8977
|
var init_skill_command_manager = __esm({
|
|
8973
8978
|
"src/plugins/telegram/skill-command-manager.ts"() {
|
|
8974
8979
|
"use strict";
|
|
8975
8980
|
init_commands();
|
|
8976
8981
|
init_log();
|
|
8977
|
-
|
|
8982
|
+
log33 = createChildLogger({ module: "skill-commands" });
|
|
8978
8983
|
SkillCommandManager = class {
|
|
8979
8984
|
// sessionId → pinned msgId
|
|
8980
8985
|
constructor(bot, chatId, sendQueue, sessionManager) {
|
|
@@ -9040,7 +9045,7 @@ var init_skill_command_manager = __esm({
|
|
|
9040
9045
|
disable_notification: true
|
|
9041
9046
|
});
|
|
9042
9047
|
} catch (err) {
|
|
9043
|
-
|
|
9048
|
+
log33.error({ err, sessionId }, "Failed to send skill commands");
|
|
9044
9049
|
}
|
|
9045
9050
|
}
|
|
9046
9051
|
async cleanup(sessionId) {
|
|
@@ -9219,6 +9224,10 @@ async function validateBotAdmin(token, chatId) {
|
|
|
9219
9224
|
};
|
|
9220
9225
|
}
|
|
9221
9226
|
const { status } = data.result;
|
|
9227
|
+
log34.info(
|
|
9228
|
+
{ status, can_manage_topics: data.result.can_manage_topics, raw_result: data.result },
|
|
9229
|
+
"validateBotAdmin: getChatMember raw result"
|
|
9230
|
+
);
|
|
9222
9231
|
if (status === "creator") {
|
|
9223
9232
|
return { ok: true, canManageTopics: true };
|
|
9224
9233
|
}
|
|
@@ -9235,6 +9244,7 @@ async function validateBotAdmin(token, chatId) {
|
|
|
9235
9244
|
}
|
|
9236
9245
|
async function checkTopicsPrerequisites(token, chatId) {
|
|
9237
9246
|
const issues = [];
|
|
9247
|
+
log34.info({ chatId }, "checkTopicsPrerequisites: starting checks");
|
|
9238
9248
|
try {
|
|
9239
9249
|
const res = await fetch(`https://api.telegram.org/bot${token}/getChat`, {
|
|
9240
9250
|
method: "POST",
|
|
@@ -9242,15 +9252,24 @@ async function checkTopicsPrerequisites(token, chatId) {
|
|
|
9242
9252
|
body: JSON.stringify({ chat_id: chatId })
|
|
9243
9253
|
});
|
|
9244
9254
|
const data = await res.json();
|
|
9255
|
+
log34.info(
|
|
9256
|
+
{ chatId, apiOk: data.ok, is_forum: data.result?.is_forum, type: data.result?.type, title: data.result?.title },
|
|
9257
|
+
"checkTopicsPrerequisites: getChat result"
|
|
9258
|
+
);
|
|
9245
9259
|
if (data.ok && data.result && !data.result.is_forum) {
|
|
9246
9260
|
issues.push(
|
|
9247
9261
|
'\u274C Topics are not enabled on this group.\n\u2192 Go to Group Settings \u2192 Edit \u2192 enable "Topics"'
|
|
9248
9262
|
);
|
|
9249
9263
|
}
|
|
9250
|
-
} catch {
|
|
9264
|
+
} catch (err) {
|
|
9265
|
+
log34.warn({ err, chatId }, "checkTopicsPrerequisites: getChat failed (network error)");
|
|
9251
9266
|
issues.push("\u274C Could not check if Topics are enabled (network error).");
|
|
9252
9267
|
}
|
|
9253
9268
|
const adminResult = await validateBotAdmin(token, chatId);
|
|
9269
|
+
log34.info(
|
|
9270
|
+
{ chatId, adminOk: adminResult.ok, canManageTopics: adminResult.ok ? adminResult.canManageTopics : void 0, error: !adminResult.ok ? adminResult.error : void 0 },
|
|
9271
|
+
"checkTopicsPrerequisites: validateBotAdmin result"
|
|
9272
|
+
);
|
|
9254
9273
|
if (!adminResult.ok) {
|
|
9255
9274
|
issues.push(
|
|
9256
9275
|
`\u274C Bot is not an admin.
|
|
@@ -9261,12 +9280,16 @@ async function checkTopicsPrerequisites(token, chatId) {
|
|
|
9261
9280
|
'\u274C Bot cannot manage topics.\n\u2192 In Admin settings, enable the "Manage Topics" permission'
|
|
9262
9281
|
);
|
|
9263
9282
|
}
|
|
9283
|
+
log34.info({ chatId, issueCount: issues.length, ok: issues.length === 0 }, "checkTopicsPrerequisites: result");
|
|
9264
9284
|
if (issues.length > 0) return { ok: false, issues };
|
|
9265
9285
|
return { ok: true };
|
|
9266
9286
|
}
|
|
9287
|
+
var log34;
|
|
9267
9288
|
var init_validators = __esm({
|
|
9268
9289
|
"src/plugins/telegram/validators.ts"() {
|
|
9269
9290
|
"use strict";
|
|
9291
|
+
init_log();
|
|
9292
|
+
log34 = createChildLogger({ module: "telegram-validators" });
|
|
9270
9293
|
}
|
|
9271
9294
|
});
|
|
9272
9295
|
|
|
@@ -9285,7 +9308,7 @@ function patchedFetch(input2, init) {
|
|
|
9285
9308
|
}
|
|
9286
9309
|
return fetch(input2, init);
|
|
9287
9310
|
}
|
|
9288
|
-
var
|
|
9311
|
+
var log35, TelegramAdapter;
|
|
9289
9312
|
var init_adapter = __esm({
|
|
9290
9313
|
"src/plugins/telegram/adapter.ts"() {
|
|
9291
9314
|
"use strict";
|
|
@@ -9304,7 +9327,7 @@ var init_adapter = __esm({
|
|
|
9304
9327
|
init_messaging_adapter();
|
|
9305
9328
|
init_renderer2();
|
|
9306
9329
|
init_output_mode_resolver();
|
|
9307
|
-
|
|
9330
|
+
log35 = createChildLogger({ module: "telegram" });
|
|
9308
9331
|
TelegramAdapter = class extends MessagingAdapter {
|
|
9309
9332
|
name = "telegram";
|
|
9310
9333
|
renderer = new TelegramRenderer();
|
|
@@ -9339,6 +9362,8 @@ var init_adapter = __esm({
|
|
|
9339
9362
|
controlMsgIds = /* @__PURE__ */ new Map();
|
|
9340
9363
|
_threadReadyHandler;
|
|
9341
9364
|
_configChangedHandler;
|
|
9365
|
+
/** Mutable ref passed to callbacks before topics are ready; updated in-place by initTopicDependentFeatures */
|
|
9366
|
+
_systemTopicIds = { notificationTopicId: 0, assistantTopicId: 0 };
|
|
9342
9367
|
/** True once topics are initialized and Phase 2 is complete */
|
|
9343
9368
|
_topicsInitialized = false;
|
|
9344
9369
|
/** Background watcher timer — cancelled on stop() or when topics succeed */
|
|
@@ -9429,7 +9454,7 @@ var init_adapter = __esm({
|
|
|
9429
9454
|
);
|
|
9430
9455
|
this.bot.catch((err) => {
|
|
9431
9456
|
const rootCause = err.error instanceof Error ? err.error : err;
|
|
9432
|
-
|
|
9457
|
+
log35.error({ err: rootCause }, "Telegram bot error");
|
|
9433
9458
|
});
|
|
9434
9459
|
this.bot.api.config.use(async (prev, method, payload, signal) => {
|
|
9435
9460
|
const maxRetries = 3;
|
|
@@ -9447,7 +9472,7 @@ var init_adapter = __esm({
|
|
|
9447
9472
|
if (rateLimitedMethods.includes(method)) {
|
|
9448
9473
|
this.sendQueue.onRateLimited();
|
|
9449
9474
|
}
|
|
9450
|
-
|
|
9475
|
+
log35.warn(
|
|
9451
9476
|
{ method, retryAfter, attempt: attempt + 1 },
|
|
9452
9477
|
"Rate limited by Telegram, retrying"
|
|
9453
9478
|
);
|
|
@@ -9606,20 +9631,57 @@ var init_adapter = __esm({
|
|
|
9606
9631
|
setupVerbosityCallbacks(this.bot, this.core);
|
|
9607
9632
|
setupIntegrateCallbacks(this.bot, this.core);
|
|
9608
9633
|
this.permissionHandler.setupCallbackHandler();
|
|
9634
|
+
setupAllCallbacks(
|
|
9635
|
+
this.bot,
|
|
9636
|
+
this.core,
|
|
9637
|
+
this.telegramConfig.chatId,
|
|
9638
|
+
this._systemTopicIds,
|
|
9639
|
+
() => {
|
|
9640
|
+
const assistant = this.core.assistantManager?.get("telegram");
|
|
9641
|
+
if (!assistant) return void 0;
|
|
9642
|
+
return {
|
|
9643
|
+
topicId: this.assistantTopicId,
|
|
9644
|
+
enqueuePrompt: (p) => {
|
|
9645
|
+
const pending = this.core.assistantManager?.consumePendingSystemPrompt("telegram");
|
|
9646
|
+
const text3 = pending ? `${pending}
|
|
9647
|
+
|
|
9648
|
+
---
|
|
9649
|
+
|
|
9650
|
+
User message:
|
|
9651
|
+
${p}` : p;
|
|
9652
|
+
return assistant.enqueuePrompt(text3);
|
|
9653
|
+
}
|
|
9654
|
+
};
|
|
9655
|
+
},
|
|
9656
|
+
(sessionId, msgId) => {
|
|
9657
|
+
this.storeControlMsgId(sessionId, msgId);
|
|
9658
|
+
}
|
|
9659
|
+
);
|
|
9660
|
+
this.setupRoutes();
|
|
9609
9661
|
this.bot.start({
|
|
9610
9662
|
allowed_updates: ["message", "callback_query"],
|
|
9611
|
-
onStart: () =>
|
|
9663
|
+
onStart: () => log35.info({ chatId: this.telegramConfig.chatId }, "Telegram bot started")
|
|
9612
9664
|
});
|
|
9665
|
+
log35.info(
|
|
9666
|
+
{
|
|
9667
|
+
chatId: this.telegramConfig.chatId,
|
|
9668
|
+
notificationTopicId: this.telegramConfig.notificationTopicId,
|
|
9669
|
+
assistantTopicId: this.telegramConfig.assistantTopicId
|
|
9670
|
+
},
|
|
9671
|
+
"Telegram adapter: starting prerequisite check (existing topic IDs shown)"
|
|
9672
|
+
);
|
|
9613
9673
|
const { checkTopicsPrerequisites: checkTopicsPrerequisites2 } = await Promise.resolve().then(() => (init_validators(), validators_exports));
|
|
9614
9674
|
const prereqResult = await checkTopicsPrerequisites2(
|
|
9615
9675
|
this.telegramConfig.botToken,
|
|
9616
9676
|
this.telegramConfig.chatId
|
|
9617
9677
|
);
|
|
9618
9678
|
if (prereqResult.ok) {
|
|
9679
|
+
log35.info("Telegram adapter: prerequisites OK, initializing topic-dependent features");
|
|
9619
9680
|
await this.initTopicDependentFeatures();
|
|
9620
9681
|
} else {
|
|
9682
|
+
log35.warn({ issues: prereqResult.issues }, "Telegram adapter: prerequisites NOT met, starting watcher");
|
|
9621
9683
|
for (const issue of prereqResult.issues) {
|
|
9622
|
-
|
|
9684
|
+
log35.warn({ issue }, "Telegram prerequisite not met");
|
|
9623
9685
|
}
|
|
9624
9686
|
this.startPrerequisiteWatcher(prereqResult.issues);
|
|
9625
9687
|
}
|
|
@@ -9635,7 +9697,7 @@ var init_adapter = __esm({
|
|
|
9635
9697
|
} catch (err) {
|
|
9636
9698
|
if (attempt === maxRetries) throw err;
|
|
9637
9699
|
const delay = baseDelayMs * Math.pow(2, attempt - 1);
|
|
9638
|
-
|
|
9700
|
+
log35.warn(
|
|
9639
9701
|
{ err, attempt, maxRetries, delayMs: delay, operation: label },
|
|
9640
9702
|
`${label} failed, retrying in ${delay}ms`
|
|
9641
9703
|
);
|
|
@@ -9655,11 +9717,15 @@ var init_adapter = __esm({
|
|
|
9655
9717
|
}),
|
|
9656
9718
|
"setMyCommands"
|
|
9657
9719
|
).catch((err) => {
|
|
9658
|
-
|
|
9720
|
+
log35.warn({ err }, "Failed to register Telegram commands after retries (non-critical)");
|
|
9659
9721
|
});
|
|
9660
9722
|
}
|
|
9661
9723
|
async initTopicDependentFeatures() {
|
|
9662
9724
|
if (this._topicsInitialized) return;
|
|
9725
|
+
log35.info(
|
|
9726
|
+
{ notificationTopicId: this.telegramConfig.notificationTopicId, assistantTopicId: this.telegramConfig.assistantTopicId },
|
|
9727
|
+
"initTopicDependentFeatures: starting (existing IDs in config)"
|
|
9728
|
+
);
|
|
9663
9729
|
const topics = await this.retryWithBackoff(
|
|
9664
9730
|
() => ensureTopics(
|
|
9665
9731
|
this.bot,
|
|
@@ -9679,34 +9745,11 @@ var init_adapter = __esm({
|
|
|
9679
9745
|
);
|
|
9680
9746
|
this.notificationTopicId = topics.notificationTopicId;
|
|
9681
9747
|
this.assistantTopicId = topics.assistantTopicId;
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
this.
|
|
9686
|
-
|
|
9687
|
-
notificationTopicId: this.notificationTopicId,
|
|
9688
|
-
assistantTopicId: this.assistantTopicId
|
|
9689
|
-
},
|
|
9690
|
-
() => {
|
|
9691
|
-
const assistant = this.core.assistantManager?.get("telegram");
|
|
9692
|
-
if (!assistant) return void 0;
|
|
9693
|
-
return {
|
|
9694
|
-
topicId: this.assistantTopicId,
|
|
9695
|
-
enqueuePrompt: (p) => {
|
|
9696
|
-
const pending = this.core.assistantManager?.consumePendingSystemPrompt("telegram");
|
|
9697
|
-
const text3 = pending ? `${pending}
|
|
9698
|
-
|
|
9699
|
-
---
|
|
9700
|
-
|
|
9701
|
-
User message:
|
|
9702
|
-
${p}` : p;
|
|
9703
|
-
return assistant.enqueuePrompt(text3);
|
|
9704
|
-
}
|
|
9705
|
-
};
|
|
9706
|
-
},
|
|
9707
|
-
(sessionId, msgId) => {
|
|
9708
|
-
this.storeControlMsgId(sessionId, msgId);
|
|
9709
|
-
}
|
|
9748
|
+
this._systemTopicIds.notificationTopicId = topics.notificationTopicId;
|
|
9749
|
+
this._systemTopicIds.assistantTopicId = topics.assistantTopicId;
|
|
9750
|
+
log35.info(
|
|
9751
|
+
{ notificationTopicId: this.notificationTopicId, assistantTopicId: this.assistantTopicId },
|
|
9752
|
+
"initTopicDependentFeatures: topics ready"
|
|
9710
9753
|
);
|
|
9711
9754
|
this._threadReadyHandler = ({ sessionId, channelId, threadId }) => {
|
|
9712
9755
|
if (channelId !== "telegram") return;
|
|
@@ -9735,7 +9778,7 @@ ${p}` : p;
|
|
|
9735
9778
|
).then((msg) => {
|
|
9736
9779
|
if (msg) this.storeControlMsgId(sessionId, msg.message_id);
|
|
9737
9780
|
}).catch((err) => {
|
|
9738
|
-
|
|
9781
|
+
log35.warn({ err, sessionId }, "Failed to send initial messages for new session");
|
|
9739
9782
|
});
|
|
9740
9783
|
};
|
|
9741
9784
|
this.core.eventBus.on("session:threadReady", this._threadReadyHandler);
|
|
@@ -9744,7 +9787,7 @@ ${p}` : p;
|
|
|
9744
9787
|
});
|
|
9745
9788
|
};
|
|
9746
9789
|
this.core.eventBus.on("session:configChanged", this._configChangedHandler);
|
|
9747
|
-
this.
|
|
9790
|
+
log35.info({ assistantTopicId: this.assistantTopicId }, "initTopicDependentFeatures: sending welcome message");
|
|
9748
9791
|
try {
|
|
9749
9792
|
const config = this.core.configManager.get();
|
|
9750
9793
|
const agents = this.core.agentManager.getAvailableAgents();
|
|
@@ -9766,16 +9809,17 @@ ${p}` : p;
|
|
|
9766
9809
|
this.core.lifecycleManager?.serviceRegistry?.get("menu-registry")
|
|
9767
9810
|
)
|
|
9768
9811
|
});
|
|
9812
|
+
log35.info("initTopicDependentFeatures: welcome message sent");
|
|
9769
9813
|
} catch (err) {
|
|
9770
|
-
|
|
9814
|
+
log35.warn({ err }, "Failed to send welcome message");
|
|
9771
9815
|
}
|
|
9772
9816
|
try {
|
|
9773
9817
|
await this.core.assistantManager.spawn("telegram", String(this.assistantTopicId));
|
|
9774
9818
|
} catch (err) {
|
|
9775
|
-
|
|
9819
|
+
log35.error({ err }, "Failed to spawn assistant");
|
|
9776
9820
|
}
|
|
9777
9821
|
this._topicsInitialized = true;
|
|
9778
|
-
|
|
9822
|
+
log35.info("Telegram adapter fully initialized");
|
|
9779
9823
|
}
|
|
9780
9824
|
startPrerequisiteWatcher(issues) {
|
|
9781
9825
|
const setupMessage = `\u26A0\uFE0F <b>OpenACP needs setup before it can start.</b>
|
|
@@ -9786,7 +9830,7 @@ OpenACP will automatically retry until this is resolved.`;
|
|
|
9786
9830
|
this.bot.api.sendMessage(this.telegramConfig.chatId, setupMessage, {
|
|
9787
9831
|
parse_mode: "HTML"
|
|
9788
9832
|
}).catch((err) => {
|
|
9789
|
-
|
|
9833
|
+
log35.warn({ err }, "Failed to send setup guidance to General topic");
|
|
9790
9834
|
});
|
|
9791
9835
|
const schedule = [5e3, 1e4, 3e4];
|
|
9792
9836
|
let attempt = 1;
|
|
@@ -9799,7 +9843,7 @@ OpenACP will automatically retry until this is resolved.`;
|
|
|
9799
9843
|
);
|
|
9800
9844
|
if (result.ok) {
|
|
9801
9845
|
this._prerequisiteWatcher = null;
|
|
9802
|
-
|
|
9846
|
+
log35.info("Prerequisites met \u2014 completing Telegram adapter initialization");
|
|
9803
9847
|
try {
|
|
9804
9848
|
await this.initTopicDependentFeatures();
|
|
9805
9849
|
await this.bot.api.sendMessage(
|
|
@@ -9808,11 +9852,11 @@ OpenACP will automatically retry until this is resolved.`;
|
|
|
9808
9852
|
{ parse_mode: "HTML" }
|
|
9809
9853
|
);
|
|
9810
9854
|
} catch (err) {
|
|
9811
|
-
|
|
9855
|
+
log35.error({ err }, "Failed to complete initialization after prerequisites met");
|
|
9812
9856
|
}
|
|
9813
9857
|
return;
|
|
9814
9858
|
}
|
|
9815
|
-
|
|
9859
|
+
log35.debug({ issues: result.issues }, "Prerequisites not yet met, retrying");
|
|
9816
9860
|
const delay = schedule[Math.min(attempt, schedule.length - 1)];
|
|
9817
9861
|
attempt++;
|
|
9818
9862
|
this._prerequisiteWatcher = setTimeout(retry, delay);
|
|
@@ -9838,7 +9882,7 @@ OpenACP will automatically retry until this is resolved.`;
|
|
|
9838
9882
|
}
|
|
9839
9883
|
this.sendQueue.clear();
|
|
9840
9884
|
await this.bot.stop();
|
|
9841
|
-
|
|
9885
|
+
log35.info("Telegram bot stopped");
|
|
9842
9886
|
}
|
|
9843
9887
|
// --- CommandRegistry response rendering ---
|
|
9844
9888
|
async renderCommandResponse(response, chatId, topicId) {
|
|
@@ -9923,6 +9967,13 @@ ${lines.join("\n")}`;
|
|
|
9923
9967
|
}
|
|
9924
9968
|
setupRoutes() {
|
|
9925
9969
|
this.bot.on("message:text", async (ctx) => {
|
|
9970
|
+
if (!this._topicsInitialized) {
|
|
9971
|
+
await ctx.reply(
|
|
9972
|
+
"\u23F3 OpenACP is still setting up. Check the General topic for instructions."
|
|
9973
|
+
).catch(() => {
|
|
9974
|
+
});
|
|
9975
|
+
return;
|
|
9976
|
+
}
|
|
9926
9977
|
const threadId = ctx.message.message_thread_id;
|
|
9927
9978
|
const text3 = ctx.message.text;
|
|
9928
9979
|
if (!threadId) {
|
|
@@ -9955,7 +10006,7 @@ ${lines.join("\n")}`;
|
|
|
9955
10006
|
threadId: String(threadId),
|
|
9956
10007
|
userId: String(ctx.from.id),
|
|
9957
10008
|
text: forwardText
|
|
9958
|
-
}).catch((err) =>
|
|
10009
|
+
}).catch((err) => log35.error({ err }, "handleMessage error"));
|
|
9959
10010
|
});
|
|
9960
10011
|
this.bot.on("message:photo", async (ctx) => {
|
|
9961
10012
|
const threadId = ctx.message.message_thread_id;
|
|
@@ -10044,7 +10095,7 @@ ${lines.join("\n")}`;
|
|
|
10044
10095
|
if (session.archiving) return;
|
|
10045
10096
|
const threadId = Number(session.threadId);
|
|
10046
10097
|
if (!threadId || isNaN(threadId)) {
|
|
10047
|
-
|
|
10098
|
+
log35.warn(
|
|
10048
10099
|
{ sessionId, threadId: session.threadId },
|
|
10049
10100
|
"Session has no valid threadId, skipping message"
|
|
10050
10101
|
);
|
|
@@ -10060,7 +10111,7 @@ ${lines.join("\n")}`;
|
|
|
10060
10111
|
this._sessionThreadIds.delete(sessionId);
|
|
10061
10112
|
}
|
|
10062
10113
|
}).catch((err) => {
|
|
10063
|
-
|
|
10114
|
+
log35.warn({ err, sessionId }, "Dispatch queue error");
|
|
10064
10115
|
});
|
|
10065
10116
|
this._dispatchQueues.set(sessionId, next);
|
|
10066
10117
|
await next;
|
|
@@ -10182,7 +10233,7 @@ ${lines.join("\n")}`;
|
|
|
10182
10233
|
);
|
|
10183
10234
|
usageMsgId = result?.message_id;
|
|
10184
10235
|
} catch (err) {
|
|
10185
|
-
|
|
10236
|
+
log35.warn({ err, sessionId }, "Failed to send usage message");
|
|
10186
10237
|
}
|
|
10187
10238
|
if (this.notificationTopicId && sessionId !== this.core.assistantManager?.get("telegram")?.id) {
|
|
10188
10239
|
const sess = this.core.sessionManager.getSession(sessionId);
|
|
@@ -10210,7 +10261,7 @@ Task completed.
|
|
|
10210
10261
|
if (!content.attachment) return;
|
|
10211
10262
|
const { attachment } = content;
|
|
10212
10263
|
if (attachment.size > 50 * 1024 * 1024) {
|
|
10213
|
-
|
|
10264
|
+
log35.warn(
|
|
10214
10265
|
{
|
|
10215
10266
|
sessionId,
|
|
10216
10267
|
fileName: attachment.fileName,
|
|
@@ -10254,7 +10305,7 @@ Task completed.
|
|
|
10254
10305
|
);
|
|
10255
10306
|
}
|
|
10256
10307
|
} catch (err) {
|
|
10257
|
-
|
|
10308
|
+
log35.error(
|
|
10258
10309
|
{ err, sessionId, fileName: attachment.fileName },
|
|
10259
10310
|
"Failed to send attachment"
|
|
10260
10311
|
);
|
|
@@ -10353,7 +10404,7 @@ Task completed.
|
|
|
10353
10404
|
}
|
|
10354
10405
|
async sendPermissionRequest(sessionId, request) {
|
|
10355
10406
|
this.getTracer(sessionId)?.log("telegram", { action: "permission:send", sessionId, requestId: request.id, description: request.description });
|
|
10356
|
-
|
|
10407
|
+
log35.info({ sessionId, requestId: request.id }, "Permission request sent");
|
|
10357
10408
|
const session = this.core.sessionManager.getSession(sessionId);
|
|
10358
10409
|
if (!session) return;
|
|
10359
10410
|
await this.sendQueue.enqueue(
|
|
@@ -10363,7 +10414,7 @@ Task completed.
|
|
|
10363
10414
|
async sendNotification(notification) {
|
|
10364
10415
|
this.getTracer(notification.sessionId)?.log("telegram", { action: "notification:send", sessionId: notification.sessionId, type: notification.type });
|
|
10365
10416
|
if (notification.sessionId === this.core.assistantManager?.get("telegram")?.id) return;
|
|
10366
|
-
|
|
10417
|
+
log35.info(
|
|
10367
10418
|
{ sessionId: notification.sessionId, type: notification.type },
|
|
10368
10419
|
"Notification sent"
|
|
10369
10420
|
);
|
|
@@ -10402,7 +10453,7 @@ Task completed.
|
|
|
10402
10453
|
}
|
|
10403
10454
|
async createSessionThread(sessionId, name) {
|
|
10404
10455
|
this.getTracer(sessionId)?.log("telegram", { action: "thread:create", sessionId, name });
|
|
10405
|
-
|
|
10456
|
+
log35.info({ sessionId, name }, "Session topic created");
|
|
10406
10457
|
return String(
|
|
10407
10458
|
await createSessionTopic(this.bot, this.telegramConfig.chatId, name)
|
|
10408
10459
|
);
|
|
@@ -10413,7 +10464,7 @@ Task completed.
|
|
|
10413
10464
|
if (!session) return;
|
|
10414
10465
|
const threadId = Number(session.threadId);
|
|
10415
10466
|
if (!threadId) {
|
|
10416
|
-
|
|
10467
|
+
log35.debug({ sessionId, newName }, "Cannot rename thread \u2014 threadId not set yet");
|
|
10417
10468
|
return;
|
|
10418
10469
|
}
|
|
10419
10470
|
await renameSessionTopic(
|
|
@@ -10432,7 +10483,7 @@ Task completed.
|
|
|
10432
10483
|
try {
|
|
10433
10484
|
await this.bot.api.deleteForumTopic(this.telegramConfig.chatId, topicId);
|
|
10434
10485
|
} catch (err) {
|
|
10435
|
-
|
|
10486
|
+
log35.warn(
|
|
10436
10487
|
{ err, sessionId, topicId },
|
|
10437
10488
|
"Failed to delete forum topic (may already be deleted)"
|
|
10438
10489
|
);
|
|
@@ -10476,7 +10527,7 @@ Task completed.
|
|
|
10476
10527
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
10477
10528
|
return { buffer, filePath: file.file_path };
|
|
10478
10529
|
} catch (err) {
|
|
10479
|
-
|
|
10530
|
+
log35.error({ err }, "Failed to download file from Telegram");
|
|
10480
10531
|
return null;
|
|
10481
10532
|
}
|
|
10482
10533
|
}
|
|
@@ -10497,7 +10548,7 @@ Task completed.
|
|
|
10497
10548
|
try {
|
|
10498
10549
|
buffer = await this.fileService.convertOggToWav(buffer);
|
|
10499
10550
|
} catch (err) {
|
|
10500
|
-
|
|
10551
|
+
log35.warn({ err }, "OGG\u2192WAV conversion failed, saving original OGG");
|
|
10501
10552
|
fileName = "voice.ogg";
|
|
10502
10553
|
mimeType = "audio/ogg";
|
|
10503
10554
|
originalFilePath = void 0;
|
|
@@ -10529,7 +10580,7 @@ Task completed.
|
|
|
10529
10580
|
userId: String(userId),
|
|
10530
10581
|
text: text3,
|
|
10531
10582
|
attachments: [att]
|
|
10532
|
-
}).catch((err) =>
|
|
10583
|
+
}).catch((err) => log35.error({ err }, "handleMessage error"));
|
|
10533
10584
|
}
|
|
10534
10585
|
async cleanupSkillCommands(sessionId) {
|
|
10535
10586
|
this._pendingSkillCommands.delete(sessionId);
|
|
@@ -14901,7 +14952,7 @@ function createPluginContext(opts) {
|
|
|
14901
14952
|
}
|
|
14902
14953
|
};
|
|
14903
14954
|
const baseLog = opts.log ?? noopLog;
|
|
14904
|
-
const
|
|
14955
|
+
const log36 = typeof baseLog.child === "function" ? baseLog.child({ plugin: pluginName }) : baseLog;
|
|
14905
14956
|
const storageImpl = new PluginStorageImpl(storagePath);
|
|
14906
14957
|
const storage = {
|
|
14907
14958
|
async get(key) {
|
|
@@ -14928,7 +14979,7 @@ function createPluginContext(opts) {
|
|
|
14928
14979
|
const ctx = {
|
|
14929
14980
|
pluginName,
|
|
14930
14981
|
pluginConfig,
|
|
14931
|
-
log:
|
|
14982
|
+
log: log36,
|
|
14932
14983
|
storage,
|
|
14933
14984
|
on(event, handler) {
|
|
14934
14985
|
requirePermission(permissions, "events:read", "on()");
|
|
@@ -14963,7 +15014,7 @@ function createPluginContext(opts) {
|
|
|
14963
15014
|
const registry = serviceRegistry.get("command-registry");
|
|
14964
15015
|
if (registry && typeof registry.register === "function") {
|
|
14965
15016
|
registry.register(def, pluginName);
|
|
14966
|
-
|
|
15017
|
+
log36.debug(`Command '/${def.name}' registered`);
|
|
14967
15018
|
}
|
|
14968
15019
|
},
|
|
14969
15020
|
async sendMessage(_sessionId, _content) {
|
|
@@ -15006,7 +15057,7 @@ function createPluginContext(opts) {
|
|
|
15006
15057
|
const registry = serviceRegistry.get("field-registry");
|
|
15007
15058
|
if (registry && typeof registry.register === "function") {
|
|
15008
15059
|
registry.register(pluginName, fields);
|
|
15009
|
-
|
|
15060
|
+
log36.debug(`Registered ${fields.length} editable field(s) for ${pluginName}`);
|
|
15010
15061
|
}
|
|
15011
15062
|
},
|
|
15012
15063
|
get sessions() {
|