@llblab/pi-telegram 0.24.11 โ 0.25.0
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 +2 -1
- package/BACKLOG.md +22 -1
- package/CHANGELOG.md +4 -1
- package/README.md +5 -4
- package/docs/activity.md +9 -7
- package/docs/architecture.md +3 -1
- package/docs/multi-instance-bus.md +11 -8
- package/docs/outbound.md +23 -1
- package/docs/public-api.md +2 -0
- package/docs/sections.md +4 -3
- package/docs/ui-style.md +2 -0
- package/index.ts +35 -1
- package/lib/activity-verbosity.ts +434 -0
- package/lib/bindings.ts +13 -2
- package/lib/config.ts +43 -1
- package/lib/menu-settings.ts +111 -45
- package/lib/queue.ts +4 -0
- package/lib/telegram-api.ts +32 -1
- package/package.json +1 -1
package/lib/menu-settings.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
+
TelegramActivityVerbosity,
|
|
8
9
|
TelegramAssistantRenderingMode,
|
|
9
10
|
TelegramTimeMode,
|
|
10
11
|
} from "./config.ts";
|
|
@@ -23,6 +24,7 @@ export interface TelegramSettingsStateDeps {
|
|
|
23
24
|
isProactivePushEnabled: () => boolean;
|
|
24
25
|
areDraftPreviewsEnabled: () => boolean;
|
|
25
26
|
getAssistantRenderingMode: () => TelegramAssistantRenderingMode;
|
|
27
|
+
getActivityVerbosity: () => TelegramActivityVerbosity;
|
|
26
28
|
getTimeInjectionMode: () => TelegramTimeMode;
|
|
27
29
|
getVoiceReplyMode: () => TelegramVoiceReplyMode;
|
|
28
30
|
isVoiceReplyModeConfigured: () => boolean;
|
|
@@ -35,6 +37,9 @@ export interface TelegramSettingsMutationDeps extends TelegramSettingsStateDeps
|
|
|
35
37
|
setAssistantRenderingMode: (
|
|
36
38
|
mode: TelegramAssistantRenderingMode,
|
|
37
39
|
) => Promise<void>;
|
|
40
|
+
setActivityVerbosity: (
|
|
41
|
+
verbosity: TelegramActivityVerbosity,
|
|
42
|
+
) => Promise<void>;
|
|
38
43
|
setVoiceReplyMode: (
|
|
39
44
|
mode: TelegramVoiceReplyMode | undefined,
|
|
40
45
|
) => Promise<void>;
|
|
@@ -138,6 +143,8 @@ export const PROACTIVE_PUSH_SETTINGS_TITLE = "<b>๐ Proactive push:</b>";
|
|
|
138
143
|
export const DRAFT_PREVIEWS_SETTINGS_TITLE = "<b>๐ Draft previews:</b>";
|
|
139
144
|
export const ASSISTANT_RENDERING_SETTINGS_TITLE =
|
|
140
145
|
"<b>๐งพ Assistant rendering:</b>";
|
|
146
|
+
export const ACTIVITY_VERBOSITY_SETTINGS_TITLE =
|
|
147
|
+
"<b>๐ฌ Activity:</b>";
|
|
141
148
|
export const TIME_INJECTION_MODE_SETTINGS_TITLE =
|
|
142
149
|
"<b>๐ Time injection mode:</b>";
|
|
143
150
|
export const VOICE_REPLY_MODE_SETTINGS_TITLE = "<b>๐ Voice reply mode:</b>";
|
|
@@ -213,6 +220,19 @@ export function buildAssistantRenderingSettingsText(
|
|
|
213
220
|
].join("\n");
|
|
214
221
|
}
|
|
215
222
|
|
|
223
|
+
export function buildActivityVerbositySettingsText(
|
|
224
|
+
verbosity: TelegramActivityVerbosity,
|
|
225
|
+
): string {
|
|
226
|
+
return [
|
|
227
|
+
`${ACTIVITY_VERBOSITY_SETTINGS_TITLE} <code>${verbosity}</code>`,
|
|
228
|
+
"",
|
|
229
|
+
"Choose how much technical model activity Telegram shows.",
|
|
230
|
+
"",
|
|
231
|
+
"<code>-</code> <code>quiet</code> (default): show public assistant output without reasoning or tool traffic.",
|
|
232
|
+
"<code>-</code> <code>verbose</code>: add ephemeral available reasoning and durable collapsed tool details.",
|
|
233
|
+
].join("\n");
|
|
234
|
+
}
|
|
235
|
+
|
|
216
236
|
export function buildVoiceReplyModeSettingsText(
|
|
217
237
|
mode: TelegramVoiceReplyMode,
|
|
218
238
|
configured = true,
|
|
@@ -255,6 +275,7 @@ export function buildTelegramSettingsMenuReplyMarkup(
|
|
|
255
275
|
sectionRegistryOrVoiceReplyModeConfigured?: TelegramSectionRegistry | boolean,
|
|
256
276
|
voiceReplyModeConfigured = true,
|
|
257
277
|
automaticThreadCleanupEnabled = true,
|
|
278
|
+
activityVerbosity: TelegramActivityVerbosity = "quiet",
|
|
258
279
|
): TelegramSettingsMenuReplyMarkup {
|
|
259
280
|
const hasRenderingMode =
|
|
260
281
|
assistantRenderingModeOrVoiceReplyMode === "rich" ||
|
|
@@ -280,23 +301,17 @@ export function buildTelegramSettingsMenuReplyMarkup(
|
|
|
280
301
|
const rows: Array<Array<{ text: string; callback_data: string }>> = [
|
|
281
302
|
[{ text: "โฌ๏ธ Main menu", callback_data: "menu:back" }],
|
|
282
303
|
];
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
callback_data: "settings:open:automatic-thread-cleanup",
|
|
295
|
-
},
|
|
296
|
-
],
|
|
297
|
-
[
|
|
298
|
-
{
|
|
299
|
-
text: `๐ Voice reply: ${getTelegramSettingsStateValueLabel(
|
|
304
|
+
const settingsButtons: Array<{ text: string; callback_data: string }> = [
|
|
305
|
+
{
|
|
306
|
+
text: `๐ Draft previews: ${draftPreviewsEnabled ? "on" : "off"}`,
|
|
307
|
+
callback_data: "settings:open:draft-previews",
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
text: `๐งพ Rendering: ${assistantRenderingMode}`,
|
|
311
|
+
callback_data: "settings:open:assistant-rendering",
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
text: `๐ Voice reply: ${getTelegramSettingsStateValueLabel(
|
|
300
315
|
getVoiceReplyModeLabel(
|
|
301
316
|
getVoiceReplyModeSetting(
|
|
302
317
|
voiceReplyMode,
|
|
@@ -304,34 +319,35 @@ export function buildTelegramSettingsMenuReplyMarkup(
|
|
|
304
319
|
),
|
|
305
320
|
),
|
|
306
321
|
)}`,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
{
|
|
330
|
-
text:
|
|
331
|
-
callback_data:
|
|
332
|
-
},
|
|
333
|
-
|
|
334
|
-
|
|
322
|
+
callback_data: "settings:open:voice-reply",
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
text: `๐ฌ Activity: ${activityVerbosity}`,
|
|
326
|
+
callback_data: "settings:open:activity-verbosity",
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
text: `๐ Proactive push: ${proactivePushEnabled ? "on" : "off"}`,
|
|
330
|
+
callback_data: "settings:open:proactive",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
text: `๐ Time injection: ${getTelegramSettingsStateValueLabel(timeInjectionMode)}`,
|
|
334
|
+
callback_data: "settings:open:time-injection",
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
text: `๐งน Thread cleanup: ${automaticThreadCleanupEnabled ? "on" : "off"}`,
|
|
338
|
+
callback_data: "settings:open:automatic-thread-cleanup",
|
|
339
|
+
},
|
|
340
|
+
];
|
|
341
|
+
if (sectionRegistry) {
|
|
342
|
+
const extensionRows = getTelegramExtensionSettingsRows(sectionRegistry);
|
|
343
|
+
settingsButtons.push(
|
|
344
|
+
...extensionRows.map((row) => ({
|
|
345
|
+
text: row.label,
|
|
346
|
+
callback_data: row.callback_data,
|
|
347
|
+
})),
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
rows.push(...settingsButtons.map((button) => [button]));
|
|
335
351
|
return { inline_keyboard: rows };
|
|
336
352
|
}
|
|
337
353
|
|
|
@@ -354,6 +370,7 @@ export async function openTelegramSettingsMenu<
|
|
|
354
370
|
sectionRegistry,
|
|
355
371
|
deps.isVoiceReplyModeConfigured(),
|
|
356
372
|
deps.isAutomaticThreadCleanupEnabled(),
|
|
373
|
+
deps.getActivityVerbosity(),
|
|
357
374
|
),
|
|
358
375
|
);
|
|
359
376
|
if (messageId === undefined) return;
|
|
@@ -439,6 +456,23 @@ export function buildAssistantRenderingSettingsReplyMarkup(
|
|
|
439
456
|
};
|
|
440
457
|
}
|
|
441
458
|
|
|
459
|
+
export function buildActivityVerbositySettingsReplyMarkup(
|
|
460
|
+
verbosity: TelegramActivityVerbosity,
|
|
461
|
+
): TelegramSettingsMenuReplyMarkup {
|
|
462
|
+
const values: TelegramActivityVerbosity[] = ["quiet", "verbose"];
|
|
463
|
+
return {
|
|
464
|
+
inline_keyboard: [
|
|
465
|
+
[{ text: "โฌ๏ธ Back", callback_data: "settings:list" }],
|
|
466
|
+
...values.map((value) => [
|
|
467
|
+
{
|
|
468
|
+
text: `${value === verbosity ? "๐ข " : ""}${value}`,
|
|
469
|
+
callback_data: `settings:set:activity-verbosity:${value}`,
|
|
470
|
+
},
|
|
471
|
+
]),
|
|
472
|
+
],
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
442
476
|
export function buildTimeInjectionModeSettingsReplyMarkup(
|
|
443
477
|
mode: TelegramTimeMode,
|
|
444
478
|
): TelegramSettingsMenuReplyMarkup {
|
|
@@ -490,6 +524,7 @@ export async function updateTelegramSettingsMenuMessage(
|
|
|
490
524
|
sectionRegistry,
|
|
491
525
|
deps.isVoiceReplyModeConfigured(),
|
|
492
526
|
deps.isAutomaticThreadCleanupEnabled(),
|
|
527
|
+
deps.getActivityVerbosity(),
|
|
493
528
|
),
|
|
494
529
|
);
|
|
495
530
|
}
|
|
@@ -534,6 +569,16 @@ export async function updateAssistantRenderingSettingsMessage(
|
|
|
534
569
|
);
|
|
535
570
|
}
|
|
536
571
|
|
|
572
|
+
export async function updateActivityVerbositySettingsMessage(
|
|
573
|
+
deps: TelegramSettingsMenuCallbackDeps,
|
|
574
|
+
): Promise<void> {
|
|
575
|
+
const verbosity = deps.getActivityVerbosity();
|
|
576
|
+
await deps.updateSettingsMessage(
|
|
577
|
+
buildActivityVerbositySettingsText(verbosity),
|
|
578
|
+
buildActivityVerbositySettingsReplyMarkup(verbosity),
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
|
|
537
582
|
export async function updateTimeInjectionModeSettingsMessage(
|
|
538
583
|
deps: TelegramSettingsMenuCallbackDeps,
|
|
539
584
|
): Promise<void> {
|
|
@@ -589,6 +634,11 @@ export async function handleTelegramSettingsMenuCallbackAction(
|
|
|
589
634
|
await deps.answerCallbackQuery(callbackQueryId);
|
|
590
635
|
return true;
|
|
591
636
|
}
|
|
637
|
+
if (data === "settings:open:activity-verbosity") {
|
|
638
|
+
await updateActivityVerbositySettingsMessage(deps);
|
|
639
|
+
await deps.answerCallbackQuery(callbackQueryId);
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
592
642
|
if (data === "settings:open:voice-reply") {
|
|
593
643
|
await updateVoiceReplyModeSettingsMessage(deps);
|
|
594
644
|
await deps.answerCallbackQuery(callbackQueryId);
|
|
@@ -660,6 +710,18 @@ export async function handleTelegramSettingsMenuCallbackAction(
|
|
|
660
710
|
return true;
|
|
661
711
|
}
|
|
662
712
|
}
|
|
713
|
+
if (data.startsWith("settings:set:activity-verbosity:")) {
|
|
714
|
+
const verbosity = data.slice("settings:set:activity-verbosity:".length);
|
|
715
|
+
if (verbosity === "quiet" || verbosity === "verbose") {
|
|
716
|
+
await deps.setActivityVerbosity(verbosity);
|
|
717
|
+
await updateActivityVerbositySettingsMessage(deps);
|
|
718
|
+
await deps.answerCallbackQuery(
|
|
719
|
+
callbackQueryId,
|
|
720
|
+
`Activity: ${verbosity}`,
|
|
721
|
+
);
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
663
725
|
if (
|
|
664
726
|
data === "settings:set:automatic-thread-cleanup:on" ||
|
|
665
727
|
data === "settings:set:automatic-thread-cleanup:off"
|
|
@@ -706,6 +768,7 @@ export function createTelegramSettingsMenuRuntime<
|
|
|
706
768
|
isProactivePushEnabled: deps.isProactivePushEnabled,
|
|
707
769
|
areDraftPreviewsEnabled: deps.areDraftPreviewsEnabled,
|
|
708
770
|
getAssistantRenderingMode: deps.getAssistantRenderingMode,
|
|
771
|
+
getActivityVerbosity: deps.getActivityVerbosity,
|
|
709
772
|
getVoiceReplyMode: deps.getVoiceReplyMode,
|
|
710
773
|
isVoiceReplyModeConfigured: deps.isVoiceReplyModeConfigured,
|
|
711
774
|
getTimeInjectionMode: deps.getTimeInjectionMode,
|
|
@@ -729,6 +792,7 @@ export function createTelegramSettingsMenuRuntime<
|
|
|
729
792
|
isProactivePushEnabled: deps.isProactivePushEnabled,
|
|
730
793
|
areDraftPreviewsEnabled: deps.areDraftPreviewsEnabled,
|
|
731
794
|
getAssistantRenderingMode: deps.getAssistantRenderingMode,
|
|
795
|
+
getActivityVerbosity: deps.getActivityVerbosity,
|
|
732
796
|
getVoiceReplyMode: deps.getVoiceReplyMode,
|
|
733
797
|
isVoiceReplyModeConfigured: deps.isVoiceReplyModeConfigured,
|
|
734
798
|
getTimeInjectionMode: deps.getTimeInjectionMode,
|
|
@@ -772,6 +836,7 @@ export function createTelegramSettingsMenuRuntime<
|
|
|
772
836
|
isProactivePushEnabled: deps.isProactivePushEnabled,
|
|
773
837
|
areDraftPreviewsEnabled: deps.areDraftPreviewsEnabled,
|
|
774
838
|
getAssistantRenderingMode: deps.getAssistantRenderingMode,
|
|
839
|
+
getActivityVerbosity: deps.getActivityVerbosity,
|
|
775
840
|
getVoiceReplyMode: deps.getVoiceReplyMode,
|
|
776
841
|
isVoiceReplyModeConfigured: deps.isVoiceReplyModeConfigured,
|
|
777
842
|
getTimeInjectionMode: deps.getTimeInjectionMode,
|
|
@@ -779,6 +844,7 @@ export function createTelegramSettingsMenuRuntime<
|
|
|
779
844
|
setProactivePushEnabled: deps.setProactivePushEnabled,
|
|
780
845
|
setDraftPreviewsEnabled: deps.setDraftPreviewsEnabled,
|
|
781
846
|
setAssistantRenderingMode: deps.setAssistantRenderingMode,
|
|
847
|
+
setActivityVerbosity: deps.setActivityVerbosity,
|
|
782
848
|
setVoiceReplyMode: deps.setVoiceReplyMode,
|
|
783
849
|
setTimeInjectionMode: deps.setTimeInjectionMode,
|
|
784
850
|
setAutomaticThreadCleanupEnabled: deps.setAutomaticThreadCleanupEnabled,
|
package/lib/queue.ts
CHANGED
|
@@ -968,6 +968,7 @@ export interface TelegramAgentEndRuntimeDeps<
|
|
|
968
968
|
isSessionActive?: () => boolean;
|
|
969
969
|
isTurnTransportActive?: (turn: TTurn) => boolean;
|
|
970
970
|
waitForTypingIdle?: () => Promise<void>;
|
|
971
|
+
waitForActivityIdle?: () => Promise<void>;
|
|
971
972
|
updateStatus: () => void;
|
|
972
973
|
dispatchNextQueuedTelegramTurn: () => void;
|
|
973
974
|
scheduleActiveTurnDelivery?: (task: () => Promise<void>) => void;
|
|
@@ -1047,6 +1048,7 @@ export interface TelegramAgentEndHookRuntimeDeps<
|
|
|
1047
1048
|
isSessionActive?: (ctx: TContext) => boolean;
|
|
1048
1049
|
isTurnTransportActive?: (turn: TTurn) => boolean;
|
|
1049
1050
|
waitForTypingIdle?: () => Promise<void>;
|
|
1051
|
+
waitForActivityIdle?: () => Promise<void>;
|
|
1050
1052
|
updateStatus: (ctx: TContext) => void;
|
|
1051
1053
|
dispatchNextQueuedTelegramTurn: (ctx: TContext) => void;
|
|
1052
1054
|
requestDeferredDispatchNextQueuedTelegramTurn: (
|
|
@@ -1188,6 +1190,7 @@ export function createTelegramAgentEndHook<
|
|
|
1188
1190
|
isSessionActive: () => deps.isSessionActive?.(ctx) ?? true,
|
|
1189
1191
|
isTurnTransportActive: deps.isTurnTransportActive,
|
|
1190
1192
|
waitForTypingIdle: deps.waitForTypingIdle,
|
|
1193
|
+
waitForActivityIdle: deps.waitForActivityIdle,
|
|
1191
1194
|
updateStatus: () => deps.updateStatus(ctx),
|
|
1192
1195
|
dispatchNextQueuedTelegramTurn: () => {
|
|
1193
1196
|
deps.requestDeferredDispatchNextQueuedTelegramTurn(
|
|
@@ -1358,6 +1361,7 @@ export async function handleTelegramAgentEndRuntime<
|
|
|
1358
1361
|
return;
|
|
1359
1362
|
}
|
|
1360
1363
|
const deliverActiveTurn = async () => {
|
|
1364
|
+
await deps.waitForActivityIdle?.();
|
|
1361
1365
|
if (!isDeliveryActive()) return;
|
|
1362
1366
|
if (finalText) deps.setPreviewPendingText(finalText);
|
|
1363
1367
|
if (!finalText && hasOutboundArtifacts)
|
package/lib/telegram-api.ts
CHANGED
|
@@ -274,6 +274,24 @@ type TelegramInputRichMessageCommon = {
|
|
|
274
274
|
skip_entity_detection?: boolean;
|
|
275
275
|
};
|
|
276
276
|
|
|
277
|
+
export type TelegramRichText =
|
|
278
|
+
| string
|
|
279
|
+
| TelegramRichText[]
|
|
280
|
+
| { type: "bold" | "code"; text: TelegramRichText };
|
|
281
|
+
|
|
282
|
+
export type TelegramInputRichBlock =
|
|
283
|
+
| { type: "pre"; text: TelegramRichText; language?: string }
|
|
284
|
+
| {
|
|
285
|
+
type: "details";
|
|
286
|
+
summary: TelegramRichText;
|
|
287
|
+
blocks: TelegramInputRichBlock[];
|
|
288
|
+
is_open?: true;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export type TelegramInputRichDraftBlock =
|
|
292
|
+
| TelegramInputRichBlock
|
|
293
|
+
| { type: "thinking"; text: TelegramRichText };
|
|
294
|
+
|
|
277
295
|
export type TelegramInputRichMessage = TelegramInputRichMessageCommon &
|
|
278
296
|
(
|
|
279
297
|
| {
|
|
@@ -288,6 +306,12 @@ export type TelegramInputRichMessage = TelegramInputRichMessageCommon &
|
|
|
288
306
|
blocks?: never;
|
|
289
307
|
media?: TelegramInputRichMessageMedia[];
|
|
290
308
|
}
|
|
309
|
+
| {
|
|
310
|
+
blocks: TelegramInputRichBlock[];
|
|
311
|
+
markdown?: never;
|
|
312
|
+
html?: never;
|
|
313
|
+
media?: never;
|
|
314
|
+
}
|
|
291
315
|
);
|
|
292
316
|
|
|
293
317
|
export type TelegramSendRichMessageBody = Record<string, unknown> & {
|
|
@@ -318,7 +342,14 @@ export type TelegramSendMessageDraftBody = Record<string, unknown> & {
|
|
|
318
342
|
export type TelegramSendRichMessageDraftBody = Record<string, unknown> & {
|
|
319
343
|
chat_id: number;
|
|
320
344
|
draft_id: number;
|
|
321
|
-
rich_message:
|
|
345
|
+
rich_message:
|
|
346
|
+
| TelegramInputRichMessage
|
|
347
|
+
| (TelegramInputRichMessageCommon & {
|
|
348
|
+
blocks: TelegramInputRichDraftBlock[];
|
|
349
|
+
markdown?: never;
|
|
350
|
+
html?: never;
|
|
351
|
+
media?: never;
|
|
352
|
+
});
|
|
322
353
|
message_thread_id?: number;
|
|
323
354
|
};
|
|
324
355
|
|