@llblab/pi-telegram 0.27.7 → 0.27.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.27.9: Symmetric Agent-Turn Metadata Hotfix
4
+
5
+ - `Agent-Turn Prompt Shape`: Cross-instance turns now fold trusted source-thread attribution into the canonical Telegram prefix as `[telegram|thread:<destination>|from-thread:<source>] <message>` instead of emitting a separate `[agent|from-thread:<source>]` block. Impact: inter-thread prompts match the existing compact metadata grammar without allowing ordinary Telegram text to impersonate transport attribution.
6
+ - `Transport Preservation`: Source-thread metadata travels as an internal serialized message field so leader-to-follower bus forwarding preserves it across the local IPC boundary. Focused regressions prove synthetic construction and final prompt formatting.
7
+
8
+ ## 0.27.8: Bidirectional Thread Routing Hotfix
9
+
10
+ - `Directional Ownership`: Internal cross-instance turns now bypass only ownership of the already-sent Telegram message id while preserving ownership of the destination thread. Impact: follower-to-leader turns avoid bouncing back to their sender, while leader-to-follower and follower-to-follower turns still forward through the destination follower's live registration.
11
+ - `Regression Coverage`: Focused tests independently prove source-message ownership bypass, destination-thread ownership forwarding with exact registration generation, and preservation of the internal agent-turn marker. Impact: both routing directions remain explicit instead of one fix silently disabling the opposite direction.
12
+
3
13
  ## 0.27.7: Bidirectional Thread Messaging Hotfix
4
14
 
5
15
  - `Follower-to-Leader Agent Turns`: Internal cross-instance turns now bypass ownership lookup for the already-sent Telegram message id while retaining that id as reply context. Impact: a follower targeting the leader reaches the leader queue instead of ownership routing the synthetic turn back to the sending follower.
@@ -281,7 +281,7 @@ Follower instances receive normalized events, not raw Telegram transport interna
281
281
 
282
282
  Followers do not call Telegram Bot API directly for routed Telegram work. Instead, they call a leader-owned transport port:
283
283
 
284
- Explicit `telegram_message(..., thread)` delivery also uses the bus as an agent-message plane. The leader resolves the case-insensitive name or numeric id against live leader/follower registrations, rejects ambiguous, stale, same-instance, cross-chat, and replayed requests, then coordinates visible Bot API delivery with one source-attributed synthetic turn routed through the destination instance's ordinary queue. The destination sees `[agent|from-thread:<name>]`, not an impersonated user message. Generation fencing and request-ledger deduplication apply to both resolution and routing.
284
+ Explicit `telegram_message(..., thread)` delivery also uses the bus as an agent-message plane. The leader resolves the case-insensitive name or numeric id against live leader/follower registrations, rejects ambiguous, stale, same-instance, cross-chat, and replayed requests, then coordinates visible Bot API delivery with one source-attributed synthetic turn routed through the destination instance's ordinary queue. The destination sees `[telegram|thread:<destination>|from-thread:<source>]`, not an impersonated user message. Generation fencing and request-ledger deduplication apply to both resolution and routing.
285
285
 
286
286
  ```text
287
287
  follower reply/preview/upload/chat-action/download/callback-answer -> leader IPC -> Telegram API
@@ -109,7 +109,8 @@ export function createTelegramAgentMessageRuntime<TContext, TUpdate>(
109
109
  chat: { id: target.chatId, type: "private" as const },
110
110
  from: { id: allowedChatId, is_bot: false, first_name: "Pi Agent" },
111
111
  message_thread_id: target.threadId,
112
- text: `[agent|from-thread:${sourceLabel}]\n\n${input.message.text}`,
112
+ pi_telegram_agent_source_thread: sourceLabel,
113
+ text: input.message.text,
113
114
  } as TelegramRoutedMessage;
114
115
  await deps.handleUpdate(
115
116
  { message, [TELEGRAM_INTERNAL_AGENT_MESSAGE]: true } as TUpdate,
package/lib/turns.ts CHANGED
@@ -54,6 +54,7 @@ export interface TelegramTurnTarget {
54
54
  export interface TelegramTurnMessage {
55
55
  message_id: number;
56
56
  message_thread_id?: number;
57
+ pi_telegram_agent_source_thread?: string;
57
58
  chat: { id: number; type?: string };
58
59
  }
59
60
 
@@ -552,7 +553,10 @@ export function createTelegramPromptTurnRuntimeBuilder<
552
553
  const threadLabel = firstMessage
553
554
  ? deps.getTelegramThreadLabel?.(firstMessage)
554
555
  : undefined;
555
- const telegramPrefix = createTelegramTurnPrefix({ thread: threadLabel });
556
+ const telegramPrefix = createTelegramTurnPrefix({
557
+ thread: threadLabel,
558
+ "from-thread": firstMessage?.pi_telegram_agent_source_thread,
559
+ });
556
560
  return buildTelegramPromptTurnRuntime({
557
561
  telegramPrefix,
558
562
  messages,
package/lib/updates.ts CHANGED
@@ -129,6 +129,7 @@ export interface TelegramUpdateMessage {
129
129
  from?: TelegramUser;
130
130
  message_id?: number;
131
131
  message_thread_id?: number;
132
+ pi_telegram_agent_source_thread?: string;
132
133
  forum_topic_created?: unknown;
133
134
  forum_topic_closed?: unknown;
134
135
  forum_topic_reopened?: unknown;
@@ -813,12 +814,7 @@ export async function executeTelegramUpdate<
813
814
  >,
814
815
  ): Promise<void> {
815
816
  const runtimeDeps = update[TELEGRAM_INTERNAL_AGENT_MESSAGE]
816
- ? {
817
- ...deps,
818
- getMessageOwnership: undefined,
819
- getTargetOwnership: undefined,
820
- recordMessageOwnership: undefined,
821
- }
817
+ ? { ...deps, getMessageOwnership: undefined }
822
818
  : deps;
823
819
  await executeTelegramUpdatePlan(
824
820
  buildTelegramUpdateExecutionPlanFromUpdate(update, allowedUserId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llblab/pi-telegram",
3
- "version": "0.27.7",
3
+ "version": "0.27.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"