@iletai/nzb 1.1.7 → 1.1.8

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.
@@ -1,4 +1,3 @@
1
- import { appendFileSync } from "fs";
2
1
  import { Bot, InlineKeyboard } from "grammy";
3
2
  import { Agent as HttpsAgent } from "https";
4
3
  import { config, persistEnvVar, persistModel } from "../config.js";
@@ -325,10 +324,6 @@ export function createBot() {
325
324
  .catch(() => { });
326
325
  };
327
326
  const onToolEvent = (event) => {
328
- try {
329
- appendFileSync("/tmp/nzb-tool-debug.log", `${new Date().toISOString()} BOT ${event.type} ${event.toolName}\n`);
330
- }
331
- catch { }
332
327
  console.log(`[nzb] Bot received tool event: ${event.type} ${event.toolName}`);
333
328
  if (event.type === "tool_start") {
334
329
  currentToolName = event.toolName;
@@ -412,21 +407,9 @@ export function createBot() {
412
407
  }
413
408
  const formatted = toTelegramMarkdown(textWithMeta);
414
409
  let fullFormatted = formatted;
415
- try {
416
- appendFileSync("/tmp/nzb-tool-debug.log", `${new Date().toISOString()} FINAL showReasoning=${config.showReasoning} toolHistory=${toolHistory.length}\n`);
417
- }
418
- catch { }
419
410
  if (config.showReasoning && toolHistory.length > 0) {
420
411
  const expandable = formatToolSummaryExpandable(toolHistory.map((t) => ({ name: t.name, durationMs: t.durationMs })));
421
412
  fullFormatted += expandable;
422
- try {
423
- appendFileSync("/tmp/nzb-tool-debug.log", `${new Date().toISOString()} EXPANDABLE=${JSON.stringify(expandable)}\n`);
424
- }
425
- catch { }
426
- try {
427
- appendFileSync("/tmp/nzb-tool-debug.log", `${new Date().toISOString()} FULL_LAST200=${JSON.stringify(fullFormatted.slice(-200))}\n`);
428
- }
429
- catch { }
430
413
  }
431
414
  const chunks = chunkMessage(fullFormatted);
432
415
  const fallbackChunks = chunkMessage(textWithMeta);
@@ -446,18 +429,10 @@ export function createBot() {
446
429
  }
447
430
  }
448
431
  }
449
- // Multi-chunk or no placeholder: delete placeholder and send chunks
450
- if (placeholderMsgId) {
451
- try {
452
- await bot.api.deleteMessage(chatId, placeholderMsgId);
453
- }
454
- catch {
455
- /* ignore */
456
- }
457
- }
432
+ // Multi-chunk or edit fallthrough: send new chunks FIRST, then delete placeholder
458
433
  const totalChunks = chunks.length;
459
434
  const sendChunk = async (chunk, fallback, index) => {
460
- const isFirst = index === 0;
435
+ const isFirst = index === 0 && !placeholderMsgId;
461
436
  // Pagination header for multi-chunk messages
462
437
  const pageTag = totalChunks > 1 ? `📄 ${index + 1}/${totalChunks}\n` : "";
463
438
  const opts = isFirst
@@ -467,12 +442,14 @@ export function createBot() {
467
442
  .reply(pageTag + chunk, opts)
468
443
  .catch(() => ctx.reply(pageTag + fallback, isFirst ? { reply_parameters: replyParams } : {}));
469
444
  };
445
+ let sendSucceeded = false;
470
446
  try {
471
447
  for (let i = 0; i < chunks.length; i++) {
472
448
  if (i > 0)
473
449
  await new Promise((r) => setTimeout(r, 300));
474
450
  await sendChunk(chunks[i], fallbackChunks[i] ?? chunks[i], i);
475
451
  }
452
+ sendSucceeded = true;
476
453
  }
477
454
  catch {
478
455
  try {
@@ -482,11 +459,21 @@ export function createBot() {
482
459
  const pageTag = fallbackChunks.length > 1 ? `📄 ${i + 1}/${fallbackChunks.length}\n` : "";
483
460
  await ctx.reply(pageTag + fallbackChunks[i], i === 0 ? { reply_parameters: replyParams } : {});
484
461
  }
462
+ sendSucceeded = true;
485
463
  }
486
464
  catch {
487
465
  /* nothing more we can do */
488
466
  }
489
467
  }
468
+ // Only delete placeholder AFTER new messages sent successfully
469
+ if (placeholderMsgId && sendSucceeded) {
470
+ try {
471
+ await bot.api.deleteMessage(chatId, placeholderMsgId);
472
+ }
473
+ catch {
474
+ /* ignore — placeholder stays but user has the real message */
475
+ }
476
+ }
490
477
  });
491
478
  }
492
479
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iletai/nzb",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "NZB — a personal AI assistant for developers, built on the GitHub Copilot SDK",
5
5
  "bin": {
6
6
  "nzb": "dist/cli.js"
@@ -61,4 +61,4 @@
61
61
  "tsx": "^4.21.0",
62
62
  "typescript": "^5.9.3"
63
63
  }
64
- }
64
+ }