@llblab/pi-telegram 0.9.9 → 0.10.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/AGENTS.md +19 -2
- package/BACKLOG.md +0 -2
- package/CHANGELOG.md +24 -1
- package/README.md +8 -3
- package/docs/README.md +1 -1
- package/docs/callback-namespaces.md +1 -1
- package/docs/extension-sections.md +304 -163
- package/index.ts +25 -12
- package/lib/commands.ts +0 -36
- package/lib/extension-sections.ts +627 -0
- package/lib/menu-model.ts +1 -1
- package/lib/menu-settings.ts +68 -33
- package/lib/menu-status.ts +18 -0
- package/lib/menu.ts +130 -1
- package/lib/replies.ts +1 -2
- package/lib/routing.ts +63 -16
- package/package.json +2 -2
package/index.ts
CHANGED
|
@@ -8,6 +8,11 @@ import * as Api from "./lib/api.ts";
|
|
|
8
8
|
import * as CommandTemplates from "./lib/command-templates.ts";
|
|
9
9
|
import * as Commands from "./lib/commands.ts";
|
|
10
10
|
import * as Config from "./lib/config.ts";
|
|
11
|
+
import {
|
|
12
|
+
createTelegramExtensionSectionRegistry,
|
|
13
|
+
setGlobalTelegramSectionRegistry,
|
|
14
|
+
type TelegramSectionRegistry,
|
|
15
|
+
} from "./lib/extension-sections.ts";
|
|
11
16
|
import { createTelegramExternalHandleUpdate } from "./lib/external-handlers.ts";
|
|
12
17
|
import * as InboundHandlers from "./lib/inbound-handlers.ts";
|
|
13
18
|
import * as Keyboard from "./lib/keyboard.ts";
|
|
@@ -69,6 +74,9 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
69
74
|
Model.ScopedTelegramModel<ActivePiModel>
|
|
70
75
|
>();
|
|
71
76
|
const modelMenuRuntime = Menu.createTelegramModelMenuRuntime<ActivePiModel>();
|
|
77
|
+
const sectionRegistry: TelegramSectionRegistry =
|
|
78
|
+
createTelegramExtensionSectionRegistry();
|
|
79
|
+
setGlobalTelegramSectionRegistry(sectionRegistry);
|
|
72
80
|
const runtimeEvents = Status.createTelegramRuntimeEventRecorder({
|
|
73
81
|
getBotToken: configStore.getBotToken,
|
|
74
82
|
});
|
|
@@ -277,6 +285,7 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
277
285
|
sendTextReply,
|
|
278
286
|
editInteractiveMessage,
|
|
279
287
|
sendInteractiveMessage,
|
|
288
|
+
sectionRegistry,
|
|
280
289
|
});
|
|
281
290
|
|
|
282
291
|
// --- Queue Menu ---
|
|
@@ -298,16 +307,19 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
298
307
|
updateStatusMessage: menuActions.updateStatusMessage,
|
|
299
308
|
updateStatus,
|
|
300
309
|
});
|
|
301
|
-
const settingsMenuRuntime = MenuSettings.createTelegramSettingsMenuRuntime(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
310
|
+
const settingsMenuRuntime = MenuSettings.createTelegramSettingsMenuRuntime(
|
|
311
|
+
{
|
|
312
|
+
getModelMenuState: getQueueMenuState,
|
|
313
|
+
getStoredModelMenuState: modelMenuRuntime.getState,
|
|
314
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
315
|
+
editInteractiveMessage,
|
|
316
|
+
sendInteractiveMessage,
|
|
317
|
+
answerCallbackQuery,
|
|
318
|
+
isProactivePushEnabled,
|
|
319
|
+
setProactivePushEnabled,
|
|
320
|
+
},
|
|
321
|
+
sectionRegistry,
|
|
322
|
+
);
|
|
311
323
|
|
|
312
324
|
// --- Polling ---
|
|
313
325
|
|
|
@@ -334,11 +346,14 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
334
346
|
queueMenuCallbackHandler: queueMenuRuntime.handleCallbackQuery,
|
|
335
347
|
openSettingsMenu: settingsMenuRuntime.openSettingsMenu,
|
|
336
348
|
settingsMenuCallbackHandler: settingsMenuRuntime.handleCallbackQuery,
|
|
349
|
+
sectionRegistry,
|
|
337
350
|
buttonActionStore,
|
|
338
351
|
inboundHandlerRuntime,
|
|
339
352
|
updateStatus,
|
|
340
353
|
dispatchNextQueuedTelegramTurn,
|
|
341
354
|
answerCallbackQuery,
|
|
355
|
+
editInteractiveMessage,
|
|
356
|
+
sendInteractiveMessage,
|
|
342
357
|
answerGuestQuery,
|
|
343
358
|
sendTextReply,
|
|
344
359
|
setMyCommands,
|
|
@@ -439,8 +454,6 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
439
454
|
startPolling: lockedPollingRuntime.start,
|
|
440
455
|
stopPolling: lockedPollingRuntime.stop,
|
|
441
456
|
updateStatus,
|
|
442
|
-
isProactivePushEnabled,
|
|
443
|
-
setProactivePushEnabled,
|
|
444
457
|
});
|
|
445
458
|
|
|
446
459
|
// --- Lifecycle Hooks ---
|
package/lib/commands.ts
CHANGED
|
@@ -135,10 +135,6 @@ export interface TelegramBridgeCommandStartPollingResult {
|
|
|
135
135
|
owner?: string;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
interface TelegramBridgeSettingsSelectUi {
|
|
139
|
-
select?: (title: string, items: string[]) => Promise<string | undefined>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
138
|
export interface TelegramBridgeCommandRegistrationDeps {
|
|
143
139
|
promptForConfig: (ctx: ExtensionCommandContext) => Promise<void>;
|
|
144
140
|
getStatusLines: () => string[];
|
|
@@ -153,8 +149,6 @@ export interface TelegramBridgeCommandRegistrationDeps {
|
|
|
153
149
|
| TelegramBridgeCommandStartPollingResult;
|
|
154
150
|
stopPolling: () => Promise<void | string>;
|
|
155
151
|
updateStatus: (ctx: ExtensionCommandContext) => void;
|
|
156
|
-
isProactivePushEnabled?: () => boolean;
|
|
157
|
-
setProactivePushEnabled?: (enabled: boolean) => Promise<void>;
|
|
158
152
|
}
|
|
159
153
|
|
|
160
154
|
function formatTelegramTakeoverTitle(ctx: ExtensionCommandContext): string {
|
|
@@ -189,36 +183,6 @@ export function registerTelegramBridgeCommands(
|
|
|
189
183
|
ctx.ui.notify(deps.getStatusLines().join("\n"), "info");
|
|
190
184
|
},
|
|
191
185
|
});
|
|
192
|
-
pi.registerCommand("telegram-settings", {
|
|
193
|
-
description: "Open Telegram bridge settings",
|
|
194
|
-
handler: async (_args, ctx) => {
|
|
195
|
-
if (!deps.isProactivePushEnabled || !deps.setProactivePushEnabled) {
|
|
196
|
-
ctx.ui.notify("Telegram settings are unavailable.", "warning");
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
await deps.reloadConfig();
|
|
200
|
-
const enabled = deps.isProactivePushEnabled();
|
|
201
|
-
const nextEnabled = !enabled;
|
|
202
|
-
const label = `${enabled ? "🟢" : "⚫️"} Proactive push`;
|
|
203
|
-
const action = `${nextEnabled ? "Enable" : "Disable"} proactive push`;
|
|
204
|
-
const select = (ctx.ui as TelegramBridgeSettingsSelectUi).select;
|
|
205
|
-
if (!select) {
|
|
206
|
-
ctx.ui.notify(
|
|
207
|
-
`${label}\n${action}: /telegram-settings requires interactive mode.`,
|
|
208
|
-
"info",
|
|
209
|
-
);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const selected = await select("Telegram settings", [label, "Cancel"]);
|
|
213
|
-
if (selected !== label) return;
|
|
214
|
-
await deps.setProactivePushEnabled(nextEnabled);
|
|
215
|
-
deps.updateStatus(ctx);
|
|
216
|
-
ctx.ui.notify(
|
|
217
|
-
`Proactive push ${nextEnabled ? "enabled" : "disabled"}.`,
|
|
218
|
-
"info",
|
|
219
|
-
);
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
186
|
pi.registerCommand("telegram-connect", {
|
|
223
187
|
description: "Start the Telegram bridge in this π session",
|
|
224
188
|
handler: async (_args, ctx) => {
|