@openacp/cli 0.4.2 → 0.4.3
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/{chunk-WXPN5UOT.js → chunk-GA26H6JY.js} +48 -89
- package/dist/chunk-GA26H6JY.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/{main-5QGMP7VG.js → main-3WJFOTNT.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-WXPN5UOT.js.map +0 -1
- /package/dist/{main-5QGMP7VG.js.map → main-3WJFOTNT.js.map} +0 -0
|
@@ -2040,7 +2040,6 @@ function buildDeepLink(chatId, messageId) {
|
|
|
2040
2040
|
|
|
2041
2041
|
// src/adapters/telegram/commands.ts
|
|
2042
2042
|
import { InlineKeyboard } from "grammy";
|
|
2043
|
-
import { nanoid as nanoid2 } from "nanoid";
|
|
2044
2043
|
var log7 = createChildLogger({ module: "telegram-commands" });
|
|
2045
2044
|
function setupCommands(bot, core, chatId, assistant) {
|
|
2046
2045
|
bot.command("new", (ctx) => handleNew(ctx, core, chatId, assistant));
|
|
@@ -2199,6 +2198,11 @@ async function handleNewChat(ctx, core, chatId) {
|
|
|
2199
2198
|
chatId,
|
|
2200
2199
|
topicName
|
|
2201
2200
|
);
|
|
2201
|
+
const topicLink = buildDeepLink(chatId, newThreadId);
|
|
2202
|
+
await ctx.reply(
|
|
2203
|
+
`\u2705 New chat created \u2192 <a href="${topicLink}">Open topic</a>`,
|
|
2204
|
+
{ parse_mode: "HTML" }
|
|
2205
|
+
);
|
|
2202
2206
|
await ctx.api.sendMessage(chatId, `\u23F3 Setting up session, please wait...`, {
|
|
2203
2207
|
message_thread_id: newThreadId,
|
|
2204
2208
|
parse_mode: "HTML"
|
|
@@ -2465,41 +2469,24 @@ async function handleDisableDangerous(ctx, core) {
|
|
|
2465
2469
|
function botFromCtx(ctx) {
|
|
2466
2470
|
return { api: ctx.api };
|
|
2467
2471
|
}
|
|
2468
|
-
var
|
|
2469
|
-
function
|
|
2470
|
-
const keyboard = new InlineKeyboard();
|
|
2472
|
+
var TELEGRAM_MSG_LIMIT = 4096;
|
|
2473
|
+
function buildSkillMessages(commands) {
|
|
2471
2474
|
const sorted = [...commands].sort((a, b) => a.name.localeCompare(b.name));
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
function clearSkillCallbacks(sessionId) {
|
|
2484
|
-
for (const [key, entry] of skillCallbackMap) {
|
|
2485
|
-
if (entry.sessionId === sessionId) {
|
|
2486
|
-
skillCallbackMap.delete(key);
|
|
2475
|
+
const header = "\u{1F6E0} <b>Available Skills</b>\n";
|
|
2476
|
+
const lines = sorted.map((c) => `<code>/${c.name}</code>`);
|
|
2477
|
+
const messages = [];
|
|
2478
|
+
let current = header;
|
|
2479
|
+
for (const line of lines) {
|
|
2480
|
+
const candidate = current + "\n" + line;
|
|
2481
|
+
if (candidate.length > TELEGRAM_MSG_LIMIT) {
|
|
2482
|
+
messages.push(current);
|
|
2483
|
+
current = line;
|
|
2484
|
+
} else {
|
|
2485
|
+
current = candidate;
|
|
2487
2486
|
}
|
|
2488
2487
|
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
bot.callbackQuery(/^s:/, async (ctx) => {
|
|
2492
|
-
try {
|
|
2493
|
-
await ctx.answerCallbackQuery();
|
|
2494
|
-
} catch {
|
|
2495
|
-
}
|
|
2496
|
-
const key = ctx.callbackQuery.data.slice(2);
|
|
2497
|
-
const entry = skillCallbackMap.get(key);
|
|
2498
|
-
if (!entry) return;
|
|
2499
|
-
const session = core.sessionManager.getSession(entry.sessionId);
|
|
2500
|
-
if (!session || session.status !== "active") return;
|
|
2501
|
-
await session.enqueuePrompt(`/${entry.commandName}`);
|
|
2502
|
-
});
|
|
2488
|
+
if (current) messages.push(current);
|
|
2489
|
+
return messages;
|
|
2503
2490
|
}
|
|
2504
2491
|
async function executeNewSession(bot, core, chatId, agentName, workspace) {
|
|
2505
2492
|
const threadId = await createSessionTopic(bot, chatId, "\u{1F504} New Session");
|
|
@@ -2553,7 +2540,7 @@ var STATIC_COMMANDS = [
|
|
|
2553
2540
|
|
|
2554
2541
|
// src/adapters/telegram/permissions.ts
|
|
2555
2542
|
import { InlineKeyboard as InlineKeyboard2 } from "grammy";
|
|
2556
|
-
import { nanoid as
|
|
2543
|
+
import { nanoid as nanoid2 } from "nanoid";
|
|
2557
2544
|
var log8 = createChildLogger({ module: "telegram-permissions" });
|
|
2558
2545
|
var PermissionHandler = class {
|
|
2559
2546
|
constructor(bot, chatId, getSession, sendNotification) {
|
|
@@ -2565,7 +2552,7 @@ var PermissionHandler = class {
|
|
|
2565
2552
|
pending = /* @__PURE__ */ new Map();
|
|
2566
2553
|
async sendPermissionRequest(session, request) {
|
|
2567
2554
|
const threadId = Number(session.threadId);
|
|
2568
|
-
const callbackKey =
|
|
2555
|
+
const callbackKey = nanoid2(8);
|
|
2569
2556
|
this.pending.set(callbackKey, {
|
|
2570
2557
|
sessionId: session.id,
|
|
2571
2558
|
requestId: request.id,
|
|
@@ -3034,7 +3021,7 @@ var TelegramSendQueue = class {
|
|
|
3034
3021
|
};
|
|
3035
3022
|
|
|
3036
3023
|
// src/adapters/telegram/action-detect.ts
|
|
3037
|
-
import { nanoid as
|
|
3024
|
+
import { nanoid as nanoid3 } from "nanoid";
|
|
3038
3025
|
import { InlineKeyboard as InlineKeyboard3 } from "grammy";
|
|
3039
3026
|
var CMD_NEW_RE = /\/new(?:\s+([^\s\u0080-\uFFFF]+)(?:\s+([^\s\u0080-\uFFFF]+))?)?/;
|
|
3040
3027
|
var CMD_CANCEL_RE = /\/cancel\b/;
|
|
@@ -3060,7 +3047,7 @@ function detectAction(text) {
|
|
|
3060
3047
|
var ACTION_TTL_MS = 5 * 60 * 1e3;
|
|
3061
3048
|
var actionMap = /* @__PURE__ */ new Map();
|
|
3062
3049
|
function storeAction(action) {
|
|
3063
|
-
const id =
|
|
3050
|
+
const id = nanoid3(10);
|
|
3064
3051
|
actionMap.set(id, { action, createdAt: Date.now() });
|
|
3065
3052
|
for (const [key, entry] of actionMap) {
|
|
3066
3053
|
if (Date.now() - entry.createdAt > ACTION_TTL_MS) {
|
|
@@ -3288,7 +3275,6 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
3288
3275
|
(sessionId) => this.core.sessionManager.getSession(sessionId),
|
|
3289
3276
|
(notification) => this.sendNotification(notification)
|
|
3290
3277
|
);
|
|
3291
|
-
setupSkillCallbacks(this.bot, this.core);
|
|
3292
3278
|
setupDangerousModeCallbacks(this.bot, this.core);
|
|
3293
3279
|
setupActionCallbacks(
|
|
3294
3280
|
this.bot,
|
|
@@ -3693,9 +3679,7 @@ Task completed.
|
|
|
3693
3679
|
}
|
|
3694
3680
|
async sendSkillCommands(sessionId, commands) {
|
|
3695
3681
|
if (sessionId === this.assistantSession?.id) return;
|
|
3696
|
-
const session = this.core.sessionManager.getSession(
|
|
3697
|
-
sessionId
|
|
3698
|
-
);
|
|
3682
|
+
const session = this.core.sessionManager.getSession(sessionId);
|
|
3699
3683
|
if (!session) return;
|
|
3700
3684
|
const threadId = Number(session.threadId);
|
|
3701
3685
|
if (!threadId) return;
|
|
@@ -3710,54 +3694,52 @@ Task completed.
|
|
|
3710
3694
|
await this.cleanupSkillCommands(sessionId);
|
|
3711
3695
|
return;
|
|
3712
3696
|
}
|
|
3713
|
-
|
|
3714
|
-
const keyboard = buildSkillKeyboard(sessionId, commands);
|
|
3715
|
-
const text = "\u{1F6E0} <b>Available commands:</b>";
|
|
3697
|
+
const messages = buildSkillMessages(commands);
|
|
3716
3698
|
const existingMsgId = this.skillMessages.get(sessionId);
|
|
3717
3699
|
if (existingMsgId) {
|
|
3718
3700
|
try {
|
|
3719
3701
|
await this.bot.api.editMessageText(
|
|
3720
3702
|
this.telegramConfig.chatId,
|
|
3721
3703
|
existingMsgId,
|
|
3722
|
-
|
|
3723
|
-
{ parse_mode: "HTML"
|
|
3704
|
+
messages[0],
|
|
3705
|
+
{ parse_mode: "HTML" }
|
|
3724
3706
|
);
|
|
3725
3707
|
return;
|
|
3726
3708
|
} catch {
|
|
3727
3709
|
}
|
|
3728
3710
|
}
|
|
3729
3711
|
try {
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3712
|
+
let firstMsgId;
|
|
3713
|
+
for (const text of messages) {
|
|
3714
|
+
const msg = await this.sendQueue.enqueue(
|
|
3715
|
+
() => this.bot.api.sendMessage(
|
|
3716
|
+
this.telegramConfig.chatId,
|
|
3717
|
+
text,
|
|
3718
|
+
{
|
|
3719
|
+
message_thread_id: threadId,
|
|
3720
|
+
parse_mode: "HTML",
|
|
3721
|
+
disable_notification: true
|
|
3722
|
+
}
|
|
3723
|
+
)
|
|
3724
|
+
);
|
|
3725
|
+
if (!firstMsgId) firstMsgId = msg.message_id;
|
|
3726
|
+
}
|
|
3727
|
+
this.skillMessages.set(sessionId, firstMsgId);
|
|
3743
3728
|
const record = this.core.sessionManager.getSessionRecord(sessionId);
|
|
3744
3729
|
if (record) {
|
|
3745
3730
|
await this.core.sessionManager.updateSessionPlatform(
|
|
3746
3731
|
sessionId,
|
|
3747
|
-
{ ...record.platform, skillMsgId:
|
|
3732
|
+
{ ...record.platform, skillMsgId: firstMsgId }
|
|
3748
3733
|
);
|
|
3749
3734
|
}
|
|
3750
3735
|
await this.bot.api.pinChatMessage(
|
|
3751
3736
|
this.telegramConfig.chatId,
|
|
3752
|
-
|
|
3753
|
-
{
|
|
3754
|
-
disable_notification: true
|
|
3755
|
-
}
|
|
3737
|
+
firstMsgId,
|
|
3738
|
+
{ disable_notification: true }
|
|
3756
3739
|
);
|
|
3757
3740
|
} catch (err) {
|
|
3758
3741
|
log11.error({ err, sessionId }, "Failed to send skill commands");
|
|
3759
3742
|
}
|
|
3760
|
-
await this.updateCommandAutocomplete(session.agentName, commands);
|
|
3761
3743
|
}
|
|
3762
3744
|
async cleanupSkillCommands(sessionId) {
|
|
3763
3745
|
const msgId = this.skillMessages.get(sessionId);
|
|
@@ -3773,35 +3755,12 @@ Task completed.
|
|
|
3773
3755
|
} catch {
|
|
3774
3756
|
}
|
|
3775
3757
|
this.skillMessages.delete(sessionId);
|
|
3776
|
-
clearSkillCallbacks(sessionId);
|
|
3777
3758
|
const record = this.core.sessionManager.getSessionRecord(sessionId);
|
|
3778
3759
|
if (record) {
|
|
3779
3760
|
const { skillMsgId: _removed, ...rest } = record.platform;
|
|
3780
3761
|
await this.core.sessionManager.updateSessionPlatform(sessionId, rest);
|
|
3781
3762
|
}
|
|
3782
3763
|
}
|
|
3783
|
-
async updateCommandAutocomplete(agentName, skillCommands) {
|
|
3784
|
-
const prefix = `[${agentName}] `;
|
|
3785
|
-
const validSkills = skillCommands.map((c) => ({
|
|
3786
|
-
command: c.name.toLowerCase().replace(/[^a-z0-9_]/g, "_").slice(0, 32),
|
|
3787
|
-
description: (prefix + (c.description || c.name).replace(/\n/g, " ")).slice(0, 256)
|
|
3788
|
-
})).filter((c) => c.command.length > 0);
|
|
3789
|
-
const all = [...STATIC_COMMANDS, ...validSkills];
|
|
3790
|
-
try {
|
|
3791
|
-
await this.bot.api.setMyCommands(all, {
|
|
3792
|
-
scope: { type: "chat", chat_id: this.telegramConfig.chatId }
|
|
3793
|
-
});
|
|
3794
|
-
log11.info(
|
|
3795
|
-
{ count: all.length, skills: validSkills.length },
|
|
3796
|
-
"Updated command autocomplete"
|
|
3797
|
-
);
|
|
3798
|
-
} catch (err) {
|
|
3799
|
-
log11.error(
|
|
3800
|
-
{ err, commands: all },
|
|
3801
|
-
"Failed to update command autocomplete"
|
|
3802
|
-
);
|
|
3803
|
-
}
|
|
3804
|
-
}
|
|
3805
3764
|
async finalizeDraft(sessionId) {
|
|
3806
3765
|
const draft = this.sessionDrafts.get(sessionId);
|
|
3807
3766
|
if (!draft) return;
|
|
@@ -3849,4 +3808,4 @@ export {
|
|
|
3849
3808
|
ApiServer,
|
|
3850
3809
|
TelegramAdapter
|
|
3851
3810
|
};
|
|
3852
|
-
//# sourceMappingURL=chunk-
|
|
3811
|
+
//# sourceMappingURL=chunk-GA26H6JY.js.map
|