@iletai/nzb 1.3.0 → 1.3.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.
@@ -1,5 +1,6 @@
1
1
  import { autoRetry } from "@grammyjs/auto-retry";
2
- import { Bot, InlineKeyboard } from "grammy";
2
+ import { Menu } from "@grammyjs/menu";
3
+ import { Bot } from "grammy";
3
4
  import { Agent as HttpsAgent } from "https";
4
5
  import { config, persistEnvVar, persistModel } from "../config.js";
5
6
  import { cancelCurrentMessage, getQueueSize, getWorkers, sendToOrchestrator } from "../copilot/orchestrator.js";
@@ -10,18 +11,94 @@ import { chunkMessage, formatToolSummaryExpandable, toTelegramMarkdown } from ".
10
11
  import { initLogChannel, logDebug, logError, logInfo } from "./log-channel.js";
11
12
  let bot;
12
13
  const startedAt = Date.now();
13
- // Inline keyboard menu for quick actions
14
- const mainMenu = new InlineKeyboard()
15
- .text("📊 Status", "action:status")
16
- .text("🤖 Model", "action:model")
14
+ // Helper: build uptime string
15
+ function getUptimeStr() {
16
+ const uptime = Math.floor((Date.now() - startedAt) / 1000);
17
+ const hours = Math.floor(uptime / 3600);
18
+ const minutes = Math.floor((uptime % 3600) / 60);
19
+ const seconds = uptime % 60;
20
+ return hours > 0 ? `${hours}h ${minutes}m ${seconds}s` : minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;
21
+ }
22
+ // Settings sub-menu
23
+ const settingsMenu = new Menu("settings-menu")
24
+ .text((ctx) => `${config.showReasoning ? "✅" : "❌"} Show Reasoning`, async (ctx) => {
25
+ config.showReasoning = !config.showReasoning;
26
+ persistEnvVar("SHOW_REASONING", config.showReasoning ? "true" : "false");
27
+ ctx.menu.update();
28
+ await ctx.answerCallbackQuery(`Reasoning ${config.showReasoning ? "ON" : "OFF"}`);
29
+ })
17
30
  .row()
18
- .text("👥 Workers", "action:workers")
19
- .text("🧠 Skills", "action:skills")
31
+ .back("🔙 Back", async (ctx) => {
32
+ await ctx.editMessageText("NZB Menu:");
33
+ });
34
+ // Main interactive menu with navigation
35
+ const mainMenu = new Menu("main-menu")
36
+ .text("📊 Status", async (ctx) => {
37
+ const workers = Array.from(getWorkers().values());
38
+ const lines = [
39
+ "📊 NZB Status",
40
+ `Model: ${config.copilotModel}`,
41
+ `Uptime: ${getUptimeStr()}`,
42
+ `Workers: ${workers.length} active`,
43
+ `Queue: ${getQueueSize()} pending`,
44
+ ];
45
+ await ctx.answerCallbackQuery();
46
+ await ctx.reply(lines.join("\n"));
47
+ })
48
+ .text("🤖 Model", async (ctx) => {
49
+ await ctx.answerCallbackQuery();
50
+ await ctx.reply(`Current model: ${config.copilotModel}`);
51
+ })
20
52
  .row()
21
- .text("🗂 Memory", "action:memory")
22
- .text("⚙️ Settings", "action:settings")
53
+ .text("👥 Workers", async (ctx) => {
54
+ await ctx.answerCallbackQuery();
55
+ const workers = Array.from(getWorkers().values());
56
+ if (workers.length === 0) {
57
+ await ctx.reply("No active worker sessions.");
58
+ }
59
+ else {
60
+ const lines = workers.map((w) => `• ${w.name} (${w.workingDir}) — ${w.status}`);
61
+ await ctx.reply(lines.join("\n"));
62
+ }
63
+ })
64
+ .text("🧠 Skills", async (ctx) => {
65
+ await ctx.answerCallbackQuery();
66
+ const skills = listSkills();
67
+ if (skills.length === 0) {
68
+ await ctx.reply("No skills installed.");
69
+ }
70
+ else {
71
+ const lines = skills.map((s) => `• ${s.name} (${s.source}) — ${s.description}`);
72
+ await ctx.reply(lines.join("\n"));
73
+ }
74
+ })
23
75
  .row()
24
- .text(" Cancel", "action:cancel");
76
+ .text("🗂 Memory", async (ctx) => {
77
+ await ctx.answerCallbackQuery();
78
+ const memories = searchMemories(undefined, undefined, 50);
79
+ if (memories.length === 0) {
80
+ await ctx.reply("No memories stored.");
81
+ }
82
+ else {
83
+ const lines = memories.map((m) => `#${m.id} [${m.category}] ${m.content}`);
84
+ await ctx.reply(lines.join("\n") + `\n\n${memories.length} total`);
85
+ }
86
+ })
87
+ .submenu("⚙️ Settings", "settings-menu", async (ctx) => {
88
+ await ctx.editMessageText("⚙️ Settings\n\n" +
89
+ `🔧 Show Reasoning: ${config.showReasoning ? "✅ ON" : "❌ OFF"}\n` +
90
+ ` └ Hiển thị tools đã dùng + thời gian cuối mỗi phản hồi\n\n` +
91
+ `🤖 Model: ${config.copilotModel}\n` +
92
+ ` └ Dùng /model <name> để đổi`);
93
+ })
94
+ .row()
95
+ .text("❌ Cancel", async (ctx) => {
96
+ await ctx.answerCallbackQuery();
97
+ const cancelled = await cancelCurrentMessage();
98
+ await ctx.reply(cancelled ? "Cancelled." : "Nothing to cancel.");
99
+ });
100
+ // Register sub-menu as child
101
+ mainMenu.register(settingsMenu);
25
102
  // Direct-connection HTTPS agent for Telegram API requests.
26
103
  // This bypasses corporate proxy (HTTP_PROXY/HTTPS_PROXY env vars) without
27
104
  // modifying process.env, so other services (Copilot SDK, MCP, npm) are unaffected.
@@ -53,6 +130,8 @@ export function createBot() {
53
130
  }
54
131
  await next();
55
132
  });
133
+ // Register interactive menu plugin
134
+ bot.use(mainMenu);
56
135
  // /start and /help — with inline menu
57
136
  bot.command("start", (ctx) => ctx.reply("NZB is online. Send me anything, or use the menu below:", { reply_markup: mainMenu }));
58
137
  bot.command("help", (ctx) => ctx.reply("I'm NZB, your AI daemon.\n\n" +
@@ -156,92 +235,12 @@ export function createBot() {
156
235
  });
157
236
  }, 500);
158
237
  });
159
- // /settings — show toggleable settings with inline keyboard
160
- const buildSettingsKeyboard = () => new InlineKeyboard()
161
- .text(`${config.showReasoning ? "✅" : "❌"} Show Reasoning`, "setting:toggle:reasoning")
162
- .row()
163
- .text("🔙 Back to Menu", "action:menu");
164
- const buildSettingsText = () => "⚙️ Settings\n\n" +
165
- `🔧 Show Reasoning: ${config.showReasoning ? "✅ ON" : "❌ OFF"}\n` +
166
- ` └ Hiển thị tools đã dùng + thời gian cuối mỗi phản hồi\n\n` +
167
- `🤖 Model: ${config.copilotModel}\n` +
168
- ` └ Dùng /model <name> để đổi`;
169
238
  bot.command("settings", async (ctx) => {
170
- await ctx.reply(buildSettingsText(), { reply_markup: buildSettingsKeyboard() });
171
- });
172
- // Callback query handlers for inline menu buttons
173
- bot.callbackQuery("action:status", async (ctx) => {
174
- await ctx.answerCallbackQuery();
175
- const uptime = Math.floor((Date.now() - startedAt) / 1000);
176
- const hours = Math.floor(uptime / 3600);
177
- const minutes = Math.floor((uptime % 3600) / 60);
178
- const seconds = uptime % 60;
179
- const uptimeStr = hours > 0 ? `${hours}h ${minutes}m ${seconds}s` : minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;
180
- const workers = Array.from(getWorkers().values());
181
- const lines = [
182
- "📊 NZB Status",
183
- `Model: ${config.copilotModel}`,
184
- `Uptime: ${uptimeStr}`,
185
- `Workers: ${workers.length} active`,
186
- `Queue: ${getQueueSize()} pending`,
187
- ];
188
- await ctx.reply(lines.join("\n"));
189
- });
190
- bot.callbackQuery("action:model", async (ctx) => {
191
- await ctx.answerCallbackQuery();
192
- await ctx.reply(`Current model: ${config.copilotModel}`);
193
- });
194
- bot.callbackQuery("action:workers", async (ctx) => {
195
- await ctx.answerCallbackQuery();
196
- const workers = Array.from(getWorkers().values());
197
- if (workers.length === 0) {
198
- await ctx.reply("No active worker sessions.");
199
- }
200
- else {
201
- const lines = workers.map((w) => `• ${w.name} (${w.workingDir}) — ${w.status}`);
202
- await ctx.reply(lines.join("\n"));
203
- }
204
- });
205
- bot.callbackQuery("action:skills", async (ctx) => {
206
- await ctx.answerCallbackQuery();
207
- const skills = listSkills();
208
- if (skills.length === 0) {
209
- await ctx.reply("No skills installed.");
210
- }
211
- else {
212
- const lines = skills.map((s) => `• ${s.name} (${s.source}) — ${s.description}`);
213
- await ctx.reply(lines.join("\n"));
214
- }
215
- });
216
- bot.callbackQuery("action:memory", async (ctx) => {
217
- await ctx.answerCallbackQuery();
218
- const memories = searchMemories(undefined, undefined, 50);
219
- if (memories.length === 0) {
220
- await ctx.reply("No memories stored.");
221
- }
222
- else {
223
- const lines = memories.map((m) => `#${m.id} [${m.category}] ${m.content}`);
224
- await ctx.reply(lines.join("\n") + `\n\n${memories.length} total`);
225
- }
226
- });
227
- bot.callbackQuery("action:cancel", async (ctx) => {
228
- await ctx.answerCallbackQuery();
229
- const cancelled = await cancelCurrentMessage();
230
- await ctx.reply(cancelled ? "Cancelled." : "Nothing to cancel.");
231
- });
232
- bot.callbackQuery("action:settings", async (ctx) => {
233
- await ctx.answerCallbackQuery();
234
- await ctx.reply(buildSettingsText(), { reply_markup: buildSettingsKeyboard() });
235
- });
236
- bot.callbackQuery("action:menu", async (ctx) => {
237
- await ctx.answerCallbackQuery();
238
- await ctx.editMessageText("NZB Menu:", { reply_markup: mainMenu });
239
- });
240
- bot.callbackQuery("setting:toggle:reasoning", async (ctx) => {
241
- config.showReasoning = !config.showReasoning;
242
- persistEnvVar("SHOW_REASONING", config.showReasoning ? "true" : "false");
243
- await ctx.answerCallbackQuery(`Reasoning ${config.showReasoning ? "ON" : "OFF"}`);
244
- await ctx.editMessageText(buildSettingsText(), { reply_markup: buildSettingsKeyboard() });
239
+ await ctx.reply("⚙️ Settings\n\n" +
240
+ `🔧 Show Reasoning: ${config.showReasoning ? "✅ ON" : "❌ OFF"}\n` +
241
+ ` └ Hiển thị tools đã dùng + thời gian cuối mỗi phản hồi\n\n` +
242
+ `🤖 Model: ${config.copilotModel}\n` +
243
+ ` └ Dùng /model <name> để đổi`, { reply_markup: settingsMenu });
245
244
  });
246
245
  // Handle all text messages — progressive streaming with tool event feedback
247
246
  bot.on("message:text", async (ctx) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iletai/nzb",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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"
@@ -48,6 +48,7 @@
48
48
  "dependencies": {
49
49
  "@github/copilot-sdk": "^0.1.26",
50
50
  "@grammyjs/auto-retry": "^2.0.2",
51
+ "@grammyjs/menu": "^1.3.1",
51
52
  "better-sqlite3": "^12.6.2",
52
53
  "dotenv": "^17.3.1",
53
54
  "express": "^5.2.1",