@openacp/cli 0.4.2 → 0.4.4

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.
@@ -876,6 +876,13 @@ var SessionManager = class {
876
876
  await this.store.save({ ...record, status });
877
877
  }
878
878
  }
879
+ async updateSessionDangerousMode(sessionId, dangerousMode) {
880
+ if (!this.store) return;
881
+ const record = this.store.get(sessionId);
882
+ if (record) {
883
+ await this.store.save({ ...record, dangerousMode });
884
+ }
885
+ }
879
886
  async updateSessionName(sessionId, name) {
880
887
  if (!this.store) return;
881
888
  const record = this.store.get(sessionId);
@@ -1436,6 +1443,7 @@ var OpenACPCore = class {
1436
1443
  session.agentSessionId = agentInstance.sessionId;
1437
1444
  session.status = "active";
1438
1445
  session.name = record.name;
1446
+ session.dangerousMode = record.dangerousMode ?? false;
1439
1447
  this.sessionManager.registerSession(session);
1440
1448
  const adapter = this.adapters.get(message.channelId);
1441
1449
  if (adapter) {
@@ -2040,7 +2048,6 @@ function buildDeepLink(chatId, messageId) {
2040
2048
 
2041
2049
  // src/adapters/telegram/commands.ts
2042
2050
  import { InlineKeyboard } from "grammy";
2043
- import { nanoid as nanoid2 } from "nanoid";
2044
2051
  var log7 = createChildLogger({ module: "telegram-commands" });
2045
2052
  function setupCommands(bot, core, chatId, assistant) {
2046
2053
  bot.command("new", (ctx) => handleNew(ctx, core, chatId, assistant));
@@ -2199,6 +2206,11 @@ async function handleNewChat(ctx, core, chatId) {
2199
2206
  chatId,
2200
2207
  topicName
2201
2208
  );
2209
+ const topicLink = buildDeepLink(chatId, newThreadId);
2210
+ await ctx.reply(
2211
+ `\u2705 New chat created \u2192 <a href="${topicLink}">Open topic</a>`,
2212
+ { parse_mode: "HTML" }
2213
+ );
2202
2214
  await ctx.api.sendMessage(chatId, `\u23F3 Setting up session, please wait...`, {
2203
2215
  message_thread_id: newThreadId,
2204
2216
  parse_mode: "HTML"
@@ -2351,23 +2363,44 @@ function setupDangerousModeCallbacks(bot, core) {
2351
2363
  bot.callbackQuery(/^d:/, async (ctx) => {
2352
2364
  const sessionId = ctx.callbackQuery.data.slice(2);
2353
2365
  const session = core.sessionManager.getSession(sessionId);
2354
- if (!session) {
2366
+ if (session) {
2367
+ session.dangerousMode = !session.dangerousMode;
2368
+ log7.info({ sessionId, dangerousMode: session.dangerousMode }, "Dangerous mode toggled via button");
2369
+ core.sessionManager.updateSessionDangerousMode(sessionId, session.dangerousMode).catch(() => {
2370
+ });
2371
+ const toastText2 = session.dangerousMode ? "\u2620\uFE0F Dangerous mode enabled \u2014 permissions auto-approved" : "\u{1F510} Dangerous mode disabled \u2014 permissions shown normally";
2372
+ try {
2373
+ await ctx.answerCallbackQuery({ text: toastText2 });
2374
+ } catch {
2375
+ }
2376
+ try {
2377
+ await ctx.editMessageReplyMarkup({
2378
+ reply_markup: buildDangerousModeKeyboard(sessionId, session.dangerousMode)
2379
+ });
2380
+ } catch {
2381
+ }
2382
+ return;
2383
+ }
2384
+ const record = core.sessionManager.getSessionRecord(sessionId);
2385
+ if (!record || record.status === "cancelled" || record.status === "error") {
2355
2386
  try {
2356
2387
  await ctx.answerCallbackQuery({ text: "\u26A0\uFE0F Session not found or already ended." });
2357
2388
  } catch {
2358
2389
  }
2359
2390
  return;
2360
2391
  }
2361
- session.dangerousMode = !session.dangerousMode;
2362
- log7.info({ sessionId, dangerousMode: session.dangerousMode }, "Dangerous mode toggled via button");
2363
- const toastText = session.dangerousMode ? "\u2620\uFE0F Dangerous mode enabled \u2014 permissions auto-approved" : "\u{1F510} Dangerous mode disabled \u2014 permissions shown normally";
2392
+ const newDangerousMode = !(record.dangerousMode ?? false);
2393
+ core.sessionManager.updateSessionDangerousMode(sessionId, newDangerousMode).catch(() => {
2394
+ });
2395
+ log7.info({ sessionId, dangerousMode: newDangerousMode }, "Dangerous mode toggled via button (store-only, session not in memory)");
2396
+ const toastText = newDangerousMode ? "\u2620\uFE0F Dangerous mode enabled \u2014 permissions auto-approved" : "\u{1F510} Dangerous mode disabled \u2014 permissions shown normally";
2364
2397
  try {
2365
2398
  await ctx.answerCallbackQuery({ text: toastText });
2366
2399
  } catch {
2367
2400
  }
2368
2401
  try {
2369
2402
  await ctx.editMessageReplyMarkup({
2370
- reply_markup: buildDangerousModeKeyboard(sessionId, session.dangerousMode)
2403
+ reply_markup: buildDangerousModeKeyboard(sessionId, newDangerousMode)
2371
2404
  });
2372
2405
  } catch {
2373
2406
  }
@@ -2380,15 +2413,27 @@ async function handleEnableDangerous(ctx, core) {
2380
2413
  return;
2381
2414
  }
2382
2415
  const session = core.sessionManager.getSessionByThread("telegram", String(threadId));
2383
- if (!session) {
2384
- await ctx.reply("\u26A0\uFE0F No active session in this topic.", { parse_mode: "HTML" });
2385
- return;
2386
- }
2387
- if (session.dangerousMode) {
2388
- await ctx.reply("\u2620\uFE0F Dangerous mode is already enabled.", { parse_mode: "HTML" });
2389
- return;
2416
+ if (session) {
2417
+ if (session.dangerousMode) {
2418
+ await ctx.reply("\u2620\uFE0F Dangerous mode is already enabled.", { parse_mode: "HTML" });
2419
+ return;
2420
+ }
2421
+ session.dangerousMode = true;
2422
+ core.sessionManager.updateSessionDangerousMode(session.id, true).catch(() => {
2423
+ });
2424
+ } else {
2425
+ const record = core.sessionManager.getRecordByThread("telegram", String(threadId));
2426
+ if (!record || record.status === "cancelled" || record.status === "error") {
2427
+ await ctx.reply("\u26A0\uFE0F No active session in this topic.", { parse_mode: "HTML" });
2428
+ return;
2429
+ }
2430
+ if (record.dangerousMode) {
2431
+ await ctx.reply("\u2620\uFE0F Dangerous mode is already enabled.", { parse_mode: "HTML" });
2432
+ return;
2433
+ }
2434
+ core.sessionManager.updateSessionDangerousMode(record.sessionId, true).catch(() => {
2435
+ });
2390
2436
  }
2391
- session.dangerousMode = true;
2392
2437
  await ctx.reply(
2393
2438
  `\u26A0\uFE0F <b>Dangerous mode enabled</b>
2394
2439
 
@@ -2451,55 +2496,50 @@ async function handleDisableDangerous(ctx, core) {
2451
2496
  return;
2452
2497
  }
2453
2498
  const session = core.sessionManager.getSessionByThread("telegram", String(threadId));
2454
- if (!session) {
2455
- await ctx.reply("\u26A0\uFE0F No active session in this topic.", { parse_mode: "HTML" });
2456
- return;
2457
- }
2458
- if (!session.dangerousMode) {
2459
- await ctx.reply("\u{1F510} Dangerous mode is already disabled.", { parse_mode: "HTML" });
2460
- return;
2499
+ if (session) {
2500
+ if (!session.dangerousMode) {
2501
+ await ctx.reply("\u{1F510} Dangerous mode is already disabled.", { parse_mode: "HTML" });
2502
+ return;
2503
+ }
2504
+ session.dangerousMode = false;
2505
+ core.sessionManager.updateSessionDangerousMode(session.id, false).catch(() => {
2506
+ });
2507
+ } else {
2508
+ const record = core.sessionManager.getRecordByThread("telegram", String(threadId));
2509
+ if (!record || record.status === "cancelled" || record.status === "error") {
2510
+ await ctx.reply("\u26A0\uFE0F No active session in this topic.", { parse_mode: "HTML" });
2511
+ return;
2512
+ }
2513
+ if (!record.dangerousMode) {
2514
+ await ctx.reply("\u{1F510} Dangerous mode is already disabled.", { parse_mode: "HTML" });
2515
+ return;
2516
+ }
2517
+ core.sessionManager.updateSessionDangerousMode(record.sessionId, false).catch(() => {
2518
+ });
2461
2519
  }
2462
- session.dangerousMode = false;
2463
2520
  await ctx.reply("\u{1F510} <b>Dangerous mode disabled</b>\n\nPermission requests will be shown normally.", { parse_mode: "HTML" });
2464
2521
  }
2465
2522
  function botFromCtx(ctx) {
2466
2523
  return { api: ctx.api };
2467
2524
  }
2468
- var skillCallbackMap = /* @__PURE__ */ new Map();
2469
- function buildSkillKeyboard(sessionId, commands) {
2470
- const keyboard = new InlineKeyboard();
2525
+ var TELEGRAM_MSG_LIMIT = 4096;
2526
+ function buildSkillMessages(commands) {
2471
2527
  const sorted = [...commands].sort((a, b) => a.name.localeCompare(b.name));
2472
- for (let i = 0; i < sorted.length; i++) {
2473
- const cmd = sorted[i];
2474
- const key = nanoid2(8);
2475
- skillCallbackMap.set(key, { sessionId, commandName: cmd.name });
2476
- keyboard.text(`/${cmd.name}`, `s:${key}`);
2477
- if (i % 2 === 1 && i < sorted.length - 1) {
2478
- keyboard.row();
2479
- }
2480
- }
2481
- return keyboard;
2482
- }
2483
- function clearSkillCallbacks(sessionId) {
2484
- for (const [key, entry] of skillCallbackMap) {
2485
- if (entry.sessionId === sessionId) {
2486
- skillCallbackMap.delete(key);
2528
+ const header = "\u{1F6E0} <b>Available Skills</b>\n";
2529
+ const lines = sorted.map((c) => `<code>/${c.name}</code>`);
2530
+ const messages = [];
2531
+ let current = header;
2532
+ for (const line of lines) {
2533
+ const candidate = current + "\n" + line;
2534
+ if (candidate.length > TELEGRAM_MSG_LIMIT) {
2535
+ messages.push(current);
2536
+ current = line;
2537
+ } else {
2538
+ current = candidate;
2487
2539
  }
2488
2540
  }
2489
- }
2490
- function setupSkillCallbacks(bot, core) {
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
- });
2541
+ if (current) messages.push(current);
2542
+ return messages;
2503
2543
  }
2504
2544
  async function executeNewSession(bot, core, chatId, agentName, workspace) {
2505
2545
  const threadId = await createSessionTopic(bot, chatId, "\u{1F504} New Session");
@@ -2553,7 +2593,7 @@ var STATIC_COMMANDS = [
2553
2593
 
2554
2594
  // src/adapters/telegram/permissions.ts
2555
2595
  import { InlineKeyboard as InlineKeyboard2 } from "grammy";
2556
- import { nanoid as nanoid3 } from "nanoid";
2596
+ import { nanoid as nanoid2 } from "nanoid";
2557
2597
  var log8 = createChildLogger({ module: "telegram-permissions" });
2558
2598
  var PermissionHandler = class {
2559
2599
  constructor(bot, chatId, getSession, sendNotification) {
@@ -2565,7 +2605,7 @@ var PermissionHandler = class {
2565
2605
  pending = /* @__PURE__ */ new Map();
2566
2606
  async sendPermissionRequest(session, request) {
2567
2607
  const threadId = Number(session.threadId);
2568
- const callbackKey = nanoid3(8);
2608
+ const callbackKey = nanoid2(8);
2569
2609
  this.pending.set(callbackKey, {
2570
2610
  sessionId: session.id,
2571
2611
  requestId: request.id,
@@ -3034,7 +3074,7 @@ var TelegramSendQueue = class {
3034
3074
  };
3035
3075
 
3036
3076
  // src/adapters/telegram/action-detect.ts
3037
- import { nanoid as nanoid4 } from "nanoid";
3077
+ import { nanoid as nanoid3 } from "nanoid";
3038
3078
  import { InlineKeyboard as InlineKeyboard3 } from "grammy";
3039
3079
  var CMD_NEW_RE = /\/new(?:\s+([^\s\u0080-\uFFFF]+)(?:\s+([^\s\u0080-\uFFFF]+))?)?/;
3040
3080
  var CMD_CANCEL_RE = /\/cancel\b/;
@@ -3060,7 +3100,7 @@ function detectAction(text) {
3060
3100
  var ACTION_TTL_MS = 5 * 60 * 1e3;
3061
3101
  var actionMap = /* @__PURE__ */ new Map();
3062
3102
  function storeAction(action) {
3063
- const id = nanoid4(10);
3103
+ const id = nanoid3(10);
3064
3104
  actionMap.set(id, { action, createdAt: Date.now() });
3065
3105
  for (const [key, entry] of actionMap) {
3066
3106
  if (Date.now() - entry.createdAt > ACTION_TTL_MS) {
@@ -3288,7 +3328,6 @@ var TelegramAdapter = class extends ChannelAdapter {
3288
3328
  (sessionId) => this.core.sessionManager.getSession(sessionId),
3289
3329
  (notification) => this.sendNotification(notification)
3290
3330
  );
3291
- setupSkillCallbacks(this.bot, this.core);
3292
3331
  setupDangerousModeCallbacks(this.bot, this.core);
3293
3332
  setupActionCallbacks(
3294
3333
  this.bot,
@@ -3693,9 +3732,7 @@ Task completed.
3693
3732
  }
3694
3733
  async sendSkillCommands(sessionId, commands) {
3695
3734
  if (sessionId === this.assistantSession?.id) return;
3696
- const session = this.core.sessionManager.getSession(
3697
- sessionId
3698
- );
3735
+ const session = this.core.sessionManager.getSession(sessionId);
3699
3736
  if (!session) return;
3700
3737
  const threadId = Number(session.threadId);
3701
3738
  if (!threadId) return;
@@ -3710,54 +3747,52 @@ Task completed.
3710
3747
  await this.cleanupSkillCommands(sessionId);
3711
3748
  return;
3712
3749
  }
3713
- clearSkillCallbacks(sessionId);
3714
- const keyboard = buildSkillKeyboard(sessionId, commands);
3715
- const text = "\u{1F6E0} <b>Available commands:</b>";
3750
+ const messages = buildSkillMessages(commands);
3716
3751
  const existingMsgId = this.skillMessages.get(sessionId);
3717
3752
  if (existingMsgId) {
3718
3753
  try {
3719
3754
  await this.bot.api.editMessageText(
3720
3755
  this.telegramConfig.chatId,
3721
3756
  existingMsgId,
3722
- text,
3723
- { parse_mode: "HTML", reply_markup: keyboard }
3757
+ messages[0],
3758
+ { parse_mode: "HTML" }
3724
3759
  );
3725
3760
  return;
3726
3761
  } catch {
3727
3762
  }
3728
3763
  }
3729
3764
  try {
3730
- const msg = await this.sendQueue.enqueue(
3731
- () => this.bot.api.sendMessage(
3732
- this.telegramConfig.chatId,
3733
- text,
3734
- {
3735
- message_thread_id: threadId,
3736
- parse_mode: "HTML",
3737
- reply_markup: keyboard,
3738
- disable_notification: true
3739
- }
3740
- )
3741
- );
3742
- this.skillMessages.set(sessionId, msg.message_id);
3765
+ let firstMsgId;
3766
+ for (const text of messages) {
3767
+ const msg = await this.sendQueue.enqueue(
3768
+ () => this.bot.api.sendMessage(
3769
+ this.telegramConfig.chatId,
3770
+ text,
3771
+ {
3772
+ message_thread_id: threadId,
3773
+ parse_mode: "HTML",
3774
+ disable_notification: true
3775
+ }
3776
+ )
3777
+ );
3778
+ if (!firstMsgId) firstMsgId = msg.message_id;
3779
+ }
3780
+ this.skillMessages.set(sessionId, firstMsgId);
3743
3781
  const record = this.core.sessionManager.getSessionRecord(sessionId);
3744
3782
  if (record) {
3745
3783
  await this.core.sessionManager.updateSessionPlatform(
3746
3784
  sessionId,
3747
- { ...record.platform, skillMsgId: msg.message_id }
3785
+ { ...record.platform, skillMsgId: firstMsgId }
3748
3786
  );
3749
3787
  }
3750
3788
  await this.bot.api.pinChatMessage(
3751
3789
  this.telegramConfig.chatId,
3752
- msg.message_id,
3753
- {
3754
- disable_notification: true
3755
- }
3790
+ firstMsgId,
3791
+ { disable_notification: true }
3756
3792
  );
3757
3793
  } catch (err) {
3758
3794
  log11.error({ err, sessionId }, "Failed to send skill commands");
3759
3795
  }
3760
- await this.updateCommandAutocomplete(session.agentName, commands);
3761
3796
  }
3762
3797
  async cleanupSkillCommands(sessionId) {
3763
3798
  const msgId = this.skillMessages.get(sessionId);
@@ -3773,35 +3808,12 @@ Task completed.
3773
3808
  } catch {
3774
3809
  }
3775
3810
  this.skillMessages.delete(sessionId);
3776
- clearSkillCallbacks(sessionId);
3777
3811
  const record = this.core.sessionManager.getSessionRecord(sessionId);
3778
3812
  if (record) {
3779
3813
  const { skillMsgId: _removed, ...rest } = record.platform;
3780
3814
  await this.core.sessionManager.updateSessionPlatform(sessionId, rest);
3781
3815
  }
3782
3816
  }
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
3817
  async finalizeDraft(sessionId) {
3806
3818
  const draft = this.sessionDrafts.get(sessionId);
3807
3819
  if (!draft) return;
@@ -3849,4 +3861,4 @@ export {
3849
3861
  ApiServer,
3850
3862
  TelegramAdapter
3851
3863
  };
3852
- //# sourceMappingURL=chunk-WXPN5UOT.js.map
3864
+ //# sourceMappingURL=chunk-VRXFGWZJ.js.map