@llblab/pi-telegram 0.6.2 → 0.7.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 +152 -0
- package/BACKLOG.md +5 -0
- package/CHANGELOG.md +142 -0
- package/README.md +49 -42
- package/docs/architecture.md +49 -40
- package/docs/attachment-handlers.md +4 -6
- package/docs/command-templates.md +53 -9
- package/docs/locks.md +4 -0
- package/docs/outbound-handlers.md +20 -14
- package/index.ts +217 -153
- package/lib/api.ts +1 -0
- package/lib/attachment-handlers.ts +16 -9
- package/lib/attachments.ts +1 -0
- package/lib/command-templates.ts +32 -3
- package/lib/commands.ts +367 -80
- package/lib/config.ts +10 -8
- package/lib/keyboard.ts +14 -0
- package/lib/lifecycle.ts +26 -0
- package/lib/locks.ts +3 -2
- package/lib/media.ts +1 -0
- package/lib/menu-model.ts +881 -0
- package/lib/menu-queue.ts +608 -0
- package/lib/menu-status.ts +226 -0
- package/lib/menu-thinking.ts +171 -0
- package/lib/menu.ts +143 -1019
- package/lib/model.ts +1 -0
- package/lib/outbound-handlers.ts +120 -45
- package/lib/pi.ts +8 -0
- package/lib/polling.ts +1 -0
- package/lib/preview.ts +97 -50
- package/lib/prompt-templates.ts +150 -0
- package/lib/prompts.ts +17 -9
- package/lib/queue.ts +51 -15
- package/lib/rendering.ts +1 -0
- package/lib/replies.ts +86 -2
- package/lib/routing.ts +76 -14
- package/lib/runtime.ts +2 -0
- package/lib/setup.ts +1 -0
- package/lib/status.ts +15 -6
- package/lib/turns.ts +1 -0
- package/lib/updates.ts +36 -6
- package/package.json +4 -1
package/lib/status.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Telegram status rendering helpers
|
|
3
|
+
* Zones: telegram ui, pi agent diagnostics, tui
|
|
3
4
|
* Builds usage, cost, and context summaries for the interactive Telegram status view
|
|
4
5
|
*/
|
|
5
6
|
|
|
@@ -41,6 +42,8 @@ export interface TelegramStatusActiveModel {
|
|
|
41
42
|
export interface TelegramStatusContext {
|
|
42
43
|
sessionManager: { getEntries(): TelegramStatusSessionEntry[] };
|
|
43
44
|
getContextUsage(): TelegramContextUsage | undefined;
|
|
45
|
+
isIdle?: () => boolean;
|
|
46
|
+
hasPendingMessages?: () => boolean;
|
|
44
47
|
modelRegistry: {
|
|
45
48
|
isUsingOAuth(model: TelegramStatusActiveModel): boolean;
|
|
46
49
|
};
|
|
@@ -406,12 +409,14 @@ export function buildTelegramStatusBarText(
|
|
|
406
409
|
return `${label} ${theme.fg("muted", "disconnected")}`;
|
|
407
410
|
if (!state.paired)
|
|
408
411
|
return `${label} ${theme.fg("warning", "awaiting pairing")}`;
|
|
409
|
-
const queued = theme.fg("muted", state.queuedStatus);
|
|
412
|
+
const queued = state.queuedStatus ? theme.fg("muted", state.queuedStatus) : "";
|
|
410
413
|
if (state.compactionInProgress) {
|
|
411
414
|
return `${label} ${theme.fg("accent", "compacting")}${queued}`;
|
|
412
415
|
}
|
|
413
416
|
if (state.processing) {
|
|
414
|
-
|
|
417
|
+
const processingStatus = state.processingStatus ?? "processing";
|
|
418
|
+
const processingToken = processingStatus === "active" ? "warning" : "accent";
|
|
419
|
+
return `${label} ${theme.fg(processingToken, processingStatus)}${queued}`;
|
|
415
420
|
}
|
|
416
421
|
return `${label} ${theme.fg("success", "connected")}`;
|
|
417
422
|
}
|
|
@@ -528,6 +533,13 @@ function buildContextSummary(
|
|
|
528
533
|
return `${percent}/${formatTokens(contextWindow)}`;
|
|
529
534
|
}
|
|
530
535
|
|
|
536
|
+
function buildStatusSummary(ctx: TelegramStatusContext): string {
|
|
537
|
+
if (ctx.hasPendingMessages?.()) return "pending";
|
|
538
|
+
if (ctx.isIdle?.() === false) return "active";
|
|
539
|
+
if (ctx.isIdle?.() === true) return "idle";
|
|
540
|
+
return "unknown";
|
|
541
|
+
}
|
|
542
|
+
|
|
531
543
|
export function buildStatusHtml(
|
|
532
544
|
ctx: TelegramStatusContext,
|
|
533
545
|
activeModel: TelegramStatusActiveModel | undefined,
|
|
@@ -536,7 +548,7 @@ export function buildStatusHtml(
|
|
|
536
548
|
const usesSubscription = activeModel
|
|
537
549
|
? ctx.modelRegistry.isUsingOAuth(activeModel)
|
|
538
550
|
: false;
|
|
539
|
-
const lines: string[] = [];
|
|
551
|
+
const lines: string[] = [buildStatusRow("Status", buildStatusSummary(ctx))];
|
|
540
552
|
const usageSummary = buildUsageSummary(stats);
|
|
541
553
|
const costSummary = buildCostSummary(stats, usesSubscription);
|
|
542
554
|
if (usageSummary) {
|
|
@@ -546,8 +558,5 @@ export function buildStatusHtml(
|
|
|
546
558
|
lines.push(buildStatusRow("Cost", costSummary));
|
|
547
559
|
}
|
|
548
560
|
lines.push(buildStatusRow("Context", buildContextSummary(ctx, activeModel)));
|
|
549
|
-
if (lines.length === 0) {
|
|
550
|
-
lines.push(buildStatusRow("Status", "No usage data yet."));
|
|
551
|
-
}
|
|
552
561
|
return lines.join("\n");
|
|
553
562
|
}
|
package/lib/turns.ts
CHANGED
package/lib/updates.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Telegram updates domain helpers
|
|
3
|
+
* Zones: telegram inbound, authorization, routing plans
|
|
3
4
|
* Owns update extraction, authorization, classification, execution planning, and runtime execution for Telegram updates
|
|
4
5
|
*/
|
|
5
6
|
|
|
@@ -25,6 +26,9 @@ export type TelegramReactionType =
|
|
|
25
26
|
| TelegramReactionTypeEmoji
|
|
26
27
|
| TelegramReactionTypeNonEmoji;
|
|
27
28
|
|
|
29
|
+
export const TELEGRAM_PRIORITY_REACTION_EMOJIS = ["👍", "⚡", "❤", "🕊"] as const;
|
|
30
|
+
export const TELEGRAM_REMOVAL_REACTION_EMOJIS = ["👎", "👻", "💔", "💩"] as const;
|
|
31
|
+
|
|
28
32
|
export interface TelegramUpdateDeletion {
|
|
29
33
|
deleted_business_messages?: { message_ids?: unknown };
|
|
30
34
|
}
|
|
@@ -50,6 +54,21 @@ export function collectTelegramReactionEmojis(
|
|
|
50
54
|
);
|
|
51
55
|
}
|
|
52
56
|
|
|
57
|
+
function hasAnyTelegramReactionEmoji(
|
|
58
|
+
emojis: Set<string>,
|
|
59
|
+
candidates: readonly string[],
|
|
60
|
+
): boolean {
|
|
61
|
+
return candidates.some((emoji) => emojis.has(emoji));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function hasAddedTelegramReactionEmoji(
|
|
65
|
+
oldEmojis: Set<string>,
|
|
66
|
+
newEmojis: Set<string>,
|
|
67
|
+
candidates: readonly string[],
|
|
68
|
+
): boolean {
|
|
69
|
+
return candidates.some((emoji) => !oldEmojis.has(emoji) && newEmojis.has(emoji));
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
export function extractDeletedTelegramMessageIds(
|
|
54
73
|
update: TelegramUpdateDeletion,
|
|
55
74
|
): number[] {
|
|
@@ -579,8 +598,13 @@ export async function handleAuthorizedTelegramReactionUpdate<TContext>(
|
|
|
579
598
|
}
|
|
580
599
|
const oldEmojis = collectTelegramReactionEmojis(reactionUpdate.old_reaction);
|
|
581
600
|
const newEmojis = collectTelegramReactionEmojis(reactionUpdate.new_reaction);
|
|
582
|
-
|
|
583
|
-
|
|
601
|
+
if (
|
|
602
|
+
hasAddedTelegramReactionEmoji(
|
|
603
|
+
oldEmojis,
|
|
604
|
+
newEmojis,
|
|
605
|
+
TELEGRAM_REMOVAL_REACTION_EMOJIS,
|
|
606
|
+
)
|
|
607
|
+
) {
|
|
584
608
|
deps.removePendingMediaGroupMessages([reactionUpdate.message_id]);
|
|
585
609
|
deps.removeQueuedTelegramTurnsByMessageIds(
|
|
586
610
|
[reactionUpdate.message_id],
|
|
@@ -588,15 +612,21 @@ export async function handleAuthorizedTelegramReactionUpdate<TContext>(
|
|
|
588
612
|
);
|
|
589
613
|
return;
|
|
590
614
|
}
|
|
591
|
-
const
|
|
592
|
-
|
|
615
|
+
const hadPriorityReaction = hasAnyTelegramReactionEmoji(
|
|
616
|
+
oldEmojis,
|
|
617
|
+
TELEGRAM_PRIORITY_REACTION_EMOJIS,
|
|
618
|
+
);
|
|
619
|
+
const hasPriorityReaction = hasAnyTelegramReactionEmoji(
|
|
620
|
+
newEmojis,
|
|
621
|
+
TELEGRAM_PRIORITY_REACTION_EMOJIS,
|
|
622
|
+
);
|
|
623
|
+
if (hadPriorityReaction && !hasPriorityReaction) {
|
|
593
624
|
deps.clearQueuedTelegramTurnPriorityByMessageId(
|
|
594
625
|
reactionUpdate.message_id,
|
|
595
626
|
deps.ctx,
|
|
596
627
|
);
|
|
597
628
|
}
|
|
598
|
-
|
|
599
|
-
if (!likeAdded) return;
|
|
629
|
+
if (!hasAddedTelegramReactionEmoji(oldEmojis, newEmojis, TELEGRAM_PRIORITY_REACTION_EMOJIS)) return;
|
|
600
630
|
deps.prioritizeQueuedTelegramTurnByMessageId(
|
|
601
631
|
reactionUpdate.message_id,
|
|
602
632
|
deps.ctx,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llblab/pi-telegram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Better Telegram DM bridge extension for pi",
|
|
6
6
|
"type": "module",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"index.ts",
|
|
32
32
|
"lib/",
|
|
33
33
|
"README.md",
|
|
34
|
+
"AGENTS.md",
|
|
35
|
+
"BACKLOG.md",
|
|
36
|
+
"CHANGELOG.md",
|
|
34
37
|
"docs/",
|
|
35
38
|
"screenshot.png"
|
|
36
39
|
],
|