@poncho-ai/messaging 0.7.7 → 0.7.8

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,5 @@
1
1
 
2
- > @poncho-ai/messaging@0.7.7 build /home/runner/work/poncho-ai/poncho-ai/packages/messaging
2
+ > @poncho-ai/messaging@0.7.8 build /home/runner/work/poncho-ai/poncho-ai/packages/messaging
3
3
  > tsup src/index.ts --format esm --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -7,8 +7,8 @@
7
7
  CLI tsup v8.5.1
8
8
  CLI Target: es2022
9
9
  ESM Build start
10
- ESM dist/index.js 52.41 KB
11
- ESM ⚡️ Build success in 89ms
10
+ ESM dist/index.js 51.91 KB
11
+ ESM ⚡️ Build success in 49ms
12
12
  DTS Build start
13
- DTS ⚡️ Build success in 5653ms
14
- DTS dist/index.d.ts 11.72 KB
13
+ DTS ⚡️ Build success in 5402ms
14
+ DTS dist/index.d.ts 11.66 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @poncho-ai/messaging
2
2
 
3
+ ## 0.7.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [`30026c5`](https://github.com/cesr/poncho-ai/commit/30026c5eba3f714bb80c2402c5e8f32c6fd38d87) Thanks [@cesr](https://github.com/cesr)! - Fix Telegram conversation instability on serverless: use stable platformThreadId instead of in-memory session counter.
8
+
3
9
  ## 0.7.7
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -233,7 +233,6 @@ declare class TelegramAdapter implements MessagingAdapter {
233
233
  private handler;
234
234
  private resetHandler;
235
235
  private approvalDecisionHandler;
236
- private readonly sessionCounters;
237
236
  private readonly approvalMessageIds;
238
237
  private lastUpdateId;
239
238
  constructor(options?: TelegramAdapterOptions);
@@ -252,7 +251,6 @@ declare class TelegramAdapter implements MessagingAdapter {
252
251
  updateApprovalMessage(approvalId: string, decision: "approved" | "denied", tool: string): Promise<void>;
253
252
  private handleRequest;
254
253
  private handleCallbackQuery;
255
- private sessionKey;
256
254
  private extractFiles;
257
255
  }
258
256
 
package/dist/index.js CHANGED
@@ -1218,7 +1218,6 @@ var TelegramAdapter = class {
1218
1218
  handler;
1219
1219
  resetHandler;
1220
1220
  approvalDecisionHandler;
1221
- sessionCounters = /* @__PURE__ */ new Map();
1222
1221
  approvalMessageIds = /* @__PURE__ */ new Map();
1223
1222
  lastUpdateId = 0;
1224
1223
  constructor(options = {}) {
@@ -1436,18 +1435,15 @@ ${inputSummary}` : "(no input)"
1436
1435
  res.end();
1437
1436
  return;
1438
1437
  }
1439
- const key2 = this.sessionKey(message);
1440
- const current = this.sessionCounters.get(key2) ?? 0;
1441
- this.sessionCounters.set(key2, current + 1);
1442
1438
  res.writeHead(200);
1443
1439
  res.end();
1444
1440
  if (this.resetHandler) {
1445
1441
  const topicId2 = message.message_thread_id;
1446
- const prevThreadId = topicId2 ? `${chatId}:${topicId2}:${current}` : `${chatId}:${current}`;
1442
+ const threadId = topicId2 ? `${chatId}:${topicId2}:0` : `${chatId}:0`;
1447
1443
  try {
1448
1444
  await this.resetHandler("telegram", {
1449
1445
  channelId: chatId,
1450
- platformThreadId: prevThreadId
1446
+ platformThreadId: threadId
1451
1447
  });
1452
1448
  } catch (err) {
1453
1449
  console.error("[telegram-adapter] reset handler error:", err instanceof Error ? err.message : err);
@@ -1481,10 +1477,8 @@ ${inputSummary}` : "(no input)"
1481
1477
  res.end();
1482
1478
  if (!this.handler) return;
1483
1479
  const files = await this.extractFiles(message);
1484
- const key = this.sessionKey(message);
1485
- const session = this.sessionCounters.get(key) ?? 0;
1486
1480
  const topicId = message.message_thread_id;
1487
- const platformThreadId = topicId ? `${chatId}:${topicId}:${session}` : `${chatId}:${session}`;
1481
+ const platformThreadId = topicId ? `${chatId}:${topicId}:0` : `${chatId}:0`;
1488
1482
  const userId = String(message.from?.id ?? "unknown");
1489
1483
  const userName = [message.from?.first_name, message.from?.last_name].filter(Boolean).join(" ") || void 0;
1490
1484
  const ponchoMessage = {
@@ -1540,10 +1534,6 @@ ${inputSummary}` : "(no input)"
1540
1534
  // -----------------------------------------------------------------------
1541
1535
  // Helpers
1542
1536
  // -----------------------------------------------------------------------
1543
- sessionKey(message) {
1544
- const chatId = String(message.chat.id);
1545
- return message.message_thread_id ? `${chatId}:${message.message_thread_id}` : chatId;
1546
- }
1547
1537
  async extractFiles(message) {
1548
1538
  const files = [];
1549
1539
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poncho-ai/messaging",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "Messaging platform adapters for Poncho agents (Slack, Telegram, etc.)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -85,7 +85,6 @@ export class TelegramAdapter implements MessagingAdapter {
85
85
  private handler: IncomingMessageHandler | undefined;
86
86
  private resetHandler: ResetHandler | undefined;
87
87
  private approvalDecisionHandler: TelegramApprovalDecisionHandler | undefined;
88
- private readonly sessionCounters = new Map<string, number>();
89
88
  private readonly approvalMessageIds = new Map<string, { chatId: string; messageId: number }>();
90
89
  private lastUpdateId = 0;
91
90
 
@@ -374,25 +373,19 @@ export class TelegramAdapter implements MessagingAdapter {
374
373
  return;
375
374
  }
376
375
 
377
- const key = this.sessionKey(message);
378
- const current = this.sessionCounters.get(key) ?? 0;
379
- this.sessionCounters.set(key, current + 1);
380
-
381
376
  res.writeHead(200);
382
377
  res.end();
383
378
 
384
- // Persist the reset so it survives serverless cold starts.
385
- // The in-memory counter handles long-running processes; the bridge
386
- // clears messages in the conversation store for serverless.
379
+ // Clear conversation in the store so the next message starts fresh.
387
380
  if (this.resetHandler) {
388
381
  const topicId = message.message_thread_id;
389
- const prevThreadId = topicId
390
- ? `${chatId}:${topicId}:${current}`
391
- : `${chatId}:${current}`;
382
+ const threadId = topicId
383
+ ? `${chatId}:${topicId}:0`
384
+ : `${chatId}:0`;
392
385
  try {
393
386
  await this.resetHandler("telegram", {
394
387
  channelId: chatId,
395
- platformThreadId: prevThreadId,
388
+ platformThreadId: threadId,
396
389
  });
397
390
  } catch (err) {
398
391
  console.error("[telegram-adapter] reset handler error:", err instanceof Error ? err.message : err);
@@ -440,12 +433,12 @@ export class TelegramAdapter implements MessagingAdapter {
440
433
  const files = await this.extractFiles(message);
441
434
 
442
435
  // -- Build thread ref -------------------------------------------------
443
- const key = this.sessionKey(message);
444
- const session = this.sessionCounters.get(key) ?? 0;
436
+ // Always use a fixed session component so the conversationId is stable
437
+ // across serverless cold starts. /new resets via the store instead.
445
438
  const topicId = message.message_thread_id;
446
439
  const platformThreadId = topicId
447
- ? `${chatId}:${topicId}:${session}`
448
- : `${chatId}:${session}`;
440
+ ? `${chatId}:${topicId}:0`
441
+ : `${chatId}:0`;
449
442
 
450
443
  const userId = String(message.from?.id ?? "unknown");
451
444
  const userName =
@@ -520,13 +513,6 @@ export class TelegramAdapter implements MessagingAdapter {
520
513
  // Helpers
521
514
  // -----------------------------------------------------------------------
522
515
 
523
- private sessionKey(message: TelegramMessage): string {
524
- const chatId = String(message.chat.id);
525
- return message.message_thread_id
526
- ? `${chatId}:${message.message_thread_id}`
527
- : chatId;
528
- }
529
-
530
516
  private async extractFiles(
531
517
  message: TelegramMessage,
532
518
  ): Promise<FileAttachment[]> {