@llblab/pi-kit 0.27.5 → 0.28.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.
Files changed (194) hide show
  1. package/BACKLOG.md +3 -1
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +4 -4
  4. package/node_modules/@llblab/pi-state-flow/AGENTS.md +1 -1
  5. package/node_modules/@llblab/pi-state-flow/BACKLOG.md +6 -2
  6. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +4 -1
  7. package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.js +4 -3
  8. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +26 -13
  9. package/node_modules/@llblab/pi-state-flow/dist/package.json +1 -1
  10. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +3 -1
  11. package/node_modules/@llblab/pi-state-flow/docs/compatibility.md +2 -2
  12. package/node_modules/@llblab/pi-state-flow/docs/usage.md +2 -1
  13. package/node_modules/@llblab/pi-state-flow/lib/compaction.ts +4 -3
  14. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +25 -12
  15. package/node_modules/@llblab/pi-state-flow/package.json +1 -1
  16. package/node_modules/@llblab/pi-telegram/AGENTS.md +10 -8
  17. package/node_modules/@llblab/pi-telegram/BACKLOG.md +1 -9
  18. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +13 -0
  19. package/node_modules/@llblab/pi-telegram/LICENSE +21 -0
  20. package/node_modules/@llblab/pi-telegram/README.md +15 -5
  21. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.d.ts +1 -5
  22. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.js +5 -7
  23. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +5 -1
  24. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +6 -1
  25. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.js +4 -2
  26. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +54 -56
  27. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +206 -139
  28. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.d.ts +21 -2
  29. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.js +181 -25
  30. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.d.ts +4 -1
  31. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.js +28 -4
  32. package/node_modules/@llblab/pi-telegram/dist/lib/bus.d.ts +52 -56
  33. package/node_modules/@llblab/pi-telegram/dist/lib/bus.js +78 -246
  34. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.d.ts +1 -3
  35. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.js +23 -26
  36. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.d.ts +0 -5
  37. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.js +5 -5
  38. package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +0 -23
  39. package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +15 -15
  40. package/node_modules/@llblab/pi-telegram/dist/lib/config.d.ts +0 -17
  41. package/node_modules/@llblab/pi-telegram/dist/lib/config.js +12 -14
  42. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +0 -4
  43. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +2 -5
  44. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +255 -61
  45. package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.d.ts +0 -19
  46. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.d.ts +0 -2
  47. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.js +2 -2
  48. package/node_modules/@llblab/pi-telegram/dist/lib/journal.d.ts +177 -16
  49. package/node_modules/@llblab/pi-telegram/dist/lib/journal.js +1115 -249
  50. package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.d.ts +0 -2
  51. package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.js +2 -2
  52. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +1 -1
  53. package/node_modules/@llblab/pi-telegram/dist/lib/locks.d.ts +100 -12
  54. package/node_modules/@llblab/pi-telegram/dist/lib/locks.js +380 -14
  55. package/node_modules/@llblab/pi-telegram/dist/lib/logging.d.ts +30 -12
  56. package/node_modules/@llblab/pi-telegram/dist/lib/logging.js +129 -72
  57. package/node_modules/@llblab/pi-telegram/dist/lib/media.d.ts +28 -5
  58. package/node_modules/@llblab/pi-telegram/dist/lib/media.js +26 -8
  59. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.d.ts +0 -11
  60. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.js +8 -8
  61. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +0 -18
  62. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +18 -18
  63. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.d.ts +4 -4
  64. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.js +12 -7
  65. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.d.ts +1 -1
  66. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.js +1 -1
  67. package/node_modules/@llblab/pi-telegram/dist/lib/menu.d.ts +1 -0
  68. package/node_modules/@llblab/pi-telegram/dist/lib/menu.js +4 -3
  69. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.d.ts +0 -1
  70. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.js +1 -1
  71. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.js +1 -8
  72. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.d.ts +1 -6
  73. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.js +4 -21
  74. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.d.ts +0 -8
  75. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.js +5 -5
  76. package/node_modules/@llblab/pi-telegram/dist/lib/paths.d.ts +50 -7
  77. package/node_modules/@llblab/pi-telegram/dist/lib/paths.js +155 -17
  78. package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +1 -0
  79. package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +2 -1
  80. package/node_modules/@llblab/pi-telegram/dist/lib/polling.d.ts +0 -5
  81. package/node_modules/@llblab/pi-telegram/dist/lib/polling.js +5 -5
  82. package/node_modules/@llblab/pi-telegram/dist/lib/preview.d.ts +0 -3
  83. package/node_modules/@llblab/pi-telegram/dist/lib/preview.js +3 -3
  84. package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.d.ts +0 -1
  85. package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.js +1 -1
  86. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +3 -15
  87. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +69 -8
  88. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.d.ts +29 -9
  89. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.js +104 -33
  90. package/node_modules/@llblab/pi-telegram/dist/lib/replies.d.ts +0 -4
  91. package/node_modules/@llblab/pi-telegram/dist/lib/replies.js +1 -1
  92. package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +73 -8
  93. package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +2206 -307
  94. package/node_modules/@llblab/pi-telegram/dist/lib/sections.d.ts +0 -2
  95. package/node_modules/@llblab/pi-telegram/dist/lib/sections.js +1 -1
  96. package/node_modules/@llblab/pi-telegram/dist/lib/status.d.ts +44 -9
  97. package/node_modules/@llblab/pi-telegram/dist/lib/status.js +149 -27
  98. package/node_modules/@llblab/pi-telegram/dist/lib/sync.d.ts +0 -5
  99. package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +5 -4
  100. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.d.ts +11 -3
  101. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +34 -23
  102. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.d.ts +1 -0
  103. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.js +18 -21
  104. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.d.ts +32 -5
  105. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.js +191 -7
  106. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.d.ts +2 -0
  107. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.js +1 -1
  108. package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +291 -59
  109. package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +1647 -369
  110. package/node_modules/@llblab/pi-telegram/dist/lib/turns.d.ts +0 -1
  111. package/node_modules/@llblab/pi-telegram/dist/lib/turns.js +1 -1
  112. package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +184 -28
  113. package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +1032 -114
  114. package/node_modules/@llblab/pi-telegram/dist/lib/wire.d.ts +12 -0
  115. package/node_modules/@llblab/pi-telegram/dist/lib/wire.js +21 -0
  116. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.d.ts +25 -17
  117. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.js +95 -20
  118. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-identity.d.ts +20 -0
  119. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-identity.js +103 -0
  120. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +43 -8
  121. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +148 -52
  122. package/node_modules/@llblab/pi-telegram/dist/package.json +6 -6
  123. package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/SKILL.md +3 -3
  124. package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/diagnosis.md +3 -3
  125. package/node_modules/@llblab/pi-telegram/docs/README.md +1 -1
  126. package/node_modules/@llblab/pi-telegram/docs/activity.md +1 -1
  127. package/node_modules/@llblab/pi-telegram/docs/architecture.md +152 -34
  128. package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +1 -1
  129. package/node_modules/@llblab/pi-telegram/docs/delivery.md +1 -1
  130. package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +2 -2
  131. package/node_modules/@llblab/pi-telegram/docs/inbound.md +1 -1
  132. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +125 -19
  133. package/node_modules/@llblab/pi-telegram/docs/public-api.md +3 -1
  134. package/node_modules/@llblab/pi-telegram/docs/ui-style.md +22 -8
  135. package/node_modules/@llblab/pi-telegram/docs/updates.md +1 -1
  136. package/node_modules/@llblab/pi-telegram/lib/activity-verbosity.ts +5 -9
  137. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +6 -0
  138. package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +5 -2
  139. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +243 -224
  140. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +178 -31
  141. package/node_modules/@llblab/pi-telegram/lib/bus-transport.ts +30 -8
  142. package/node_modules/@llblab/pi-telegram/lib/bus.ts +110 -334
  143. package/node_modules/@llblab/pi-telegram/lib/channel-posts.ts +29 -29
  144. package/node_modules/@llblab/pi-telegram/lib/command-templates.ts +5 -5
  145. package/node_modules/@llblab/pi-telegram/lib/commands.ts +15 -15
  146. package/node_modules/@llblab/pi-telegram/lib/config.ts +12 -17
  147. package/node_modules/@llblab/pi-telegram/lib/delivery.ts +2 -8
  148. package/node_modules/@llblab/pi-telegram/lib/extension.ts +257 -72
  149. package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +0 -22
  150. package/node_modules/@llblab/pi-telegram/lib/inbound.ts +2 -2
  151. package/node_modules/@llblab/pi-telegram/lib/journal.ts +1182 -326
  152. package/node_modules/@llblab/pi-telegram/lib/keyboard.ts +2 -2
  153. package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +1 -1
  154. package/node_modules/@llblab/pi-telegram/lib/locks.ts +402 -23
  155. package/node_modules/@llblab/pi-telegram/lib/logging.ts +151 -101
  156. package/node_modules/@llblab/pi-telegram/lib/media.ts +51 -9
  157. package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +8 -8
  158. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +18 -18
  159. package/node_modules/@llblab/pi-telegram/lib/menu-status.ts +11 -0
  160. package/node_modules/@llblab/pi-telegram/lib/menu-thinking.ts +2 -2
  161. package/node_modules/@llblab/pi-telegram/lib/menu.ts +5 -1
  162. package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +1 -1
  163. package/node_modules/@llblab/pi-telegram/lib/outbound-buttons.ts +1 -10
  164. package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +5 -24
  165. package/node_modules/@llblab/pi-telegram/lib/outbound.ts +5 -5
  166. package/node_modules/@llblab/pi-telegram/lib/paths.ts +177 -17
  167. package/node_modules/@llblab/pi-telegram/lib/pi.ts +5 -2
  168. package/node_modules/@llblab/pi-telegram/lib/polling.ts +5 -5
  169. package/node_modules/@llblab/pi-telegram/lib/preview.ts +3 -3
  170. package/node_modules/@llblab/pi-telegram/lib/prompt-templates.ts +1 -1
  171. package/node_modules/@llblab/pi-telegram/lib/queue.ts +67 -9
  172. package/node_modules/@llblab/pi-telegram/lib/recovery.ts +104 -44
  173. package/node_modules/@llblab/pi-telegram/lib/replies.ts +1 -1
  174. package/node_modules/@llblab/pi-telegram/lib/routing.ts +1955 -375
  175. package/node_modules/@llblab/pi-telegram/lib/sections.ts +1 -1
  176. package/node_modules/@llblab/pi-telegram/lib/status.ts +156 -36
  177. package/node_modules/@llblab/pi-telegram/lib/sync.ts +4 -4
  178. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +48 -33
  179. package/node_modules/@llblab/pi-telegram/lib/thread-cleanup-manager.ts +24 -21
  180. package/node_modules/@llblab/pi-telegram/lib/thread-naming.ts +267 -9
  181. package/node_modules/@llblab/pi-telegram/lib/thread-reconciler.ts +3 -1
  182. package/node_modules/@llblab/pi-telegram/lib/threads.ts +1697 -488
  183. package/node_modules/@llblab/pi-telegram/lib/turns.ts +1 -1
  184. package/node_modules/@llblab/pi-telegram/lib/updates.ts +1072 -151
  185. package/node_modules/@llblab/pi-telegram/lib/wire.ts +28 -0
  186. package/node_modules/@llblab/pi-telegram/lib/workspace-admission.ts +97 -47
  187. package/node_modules/@llblab/pi-telegram/lib/workspace-identity.ts +147 -0
  188. package/node_modules/@llblab/pi-telegram/lib/workspace-retirement.ts +188 -89
  189. package/node_modules/@llblab/pi-telegram/package.json +6 -6
  190. package/node_modules/@llblab/pi-telegram/scripts/audit-exports.mjs +100 -0
  191. package/node_modules/@llblab/pi-telegram/scripts/check-downgrade.mjs +80 -43
  192. package/node_modules/@llblab/pi-telegram/skills/generated-control-surface/SKILL.md +3 -3
  193. package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/references/diagnosis.md +3 -3
  194. package/package.json +3 -3
@@ -43,10 +43,7 @@ interface RegisteredTelegramExtensionCommand {
43
43
  emoji?: string;
44
44
  handler: TelegramExtensionCommandRegistration["handler"];
45
45
  }
46
- export declare function normalizeTelegramExtensionCommandName(name: string): string;
47
- export declare function isTelegramExtensionCommandName(name: string): boolean;
48
46
  export declare function registerTelegramCommand(registration: TelegramExtensionCommandRegistration): () => void;
49
- export declare function getTelegramExtensionCommands(): RegisteredTelegramExtensionCommand[];
50
47
  export declare function findTelegramExtensionCommand(name: string | undefined): RegisteredTelegramExtensionCommand | undefined;
51
48
  export declare function clearTelegramExtensionCommands(): void;
52
49
  export declare const TELEGRAM_COMMAND_EMOJI: {
@@ -65,18 +62,14 @@ export declare const TELEGRAM_COMMAND_EMOJI: {
65
62
  readonly new: "🆕";
66
63
  };
67
64
  export type TelegramCommandEmojiName = keyof typeof TELEGRAM_COMMAND_EMOJI;
68
- export declare function getTelegramCommandEmoji(command: TelegramCommandEmojiName): string;
69
65
  export declare function formatTelegramCommandEmojiPrefix(command: TelegramCommandEmojiName): string;
70
66
  export declare function formatTelegramPiCommandHtml(command: string): string;
71
67
  export declare function formatTelegramInformationHeading(emoji: string, text: string): string;
72
68
  export declare function formatTelegramInvalidInstanceName(validationError: string): string;
73
69
  export declare function formatTelegramThreadDisplayNameSavedHeading(name: string): string;
74
70
  export declare function formatTelegramAutomaticThreadDisplayNameRestoredHeading(name: string): string;
75
- export declare const TELEGRAM_COMPACTION_STARTED_TEXT: string;
76
- export declare const TELEGRAM_COMPACTION_COMPLETED_TEXT: string;
77
71
  export declare const TELEGRAM_COMPACTION_STARTED_MARKDOWN: string;
78
72
  export declare const TELEGRAM_COMPACTION_COMPLETED_MARKDOWN = "**\u2705 Compaction completed.**";
79
- export declare const TELEGRAM_BUILTIN_BOT_COMMANDS: readonly TelegramBotCommandDefinition[];
80
73
  export declare const TELEGRAM_BOT_COMMANDS: readonly TelegramBotCommandDefinition[];
81
74
  export declare function getTelegramReservedCommandNames(): string[];
82
75
  export interface TelegramBotCommandRegistrationDeps {
@@ -542,16 +535,8 @@ export declare function handleTelegramNextCommand(deps: {
542
535
  parseMode?: "HTML";
543
536
  }) => Promise<void>) | undefined;
544
537
  }): Promise<void>;
545
- export declare function handleTelegramContinueCommand<TMessage, TContext>(message: TMessage, ctx: TContext, deps: {
546
- enqueueContinueTurn: (message: TMessage, ctx: TContext) => Promise<void>;
547
- }): Promise<void>;
548
- export declare function buildTelegramNewConfirmationReplyMarkup(): TelegramCompactConfirmationReplyMarkup;
549
- export declare function getTelegramNewConfirmationHtml(): string;
550
538
  export declare function openTelegramNewConfirmation(target: TelegramCommandMessageTarget, deps: TelegramCompactConfirmationDeps): Promise<void>;
551
539
  export declare function handleTelegramNewConfirmationCallback<TContext>(query: TelegramCompactConfirmationCallbackQuery, deps: TelegramNewConfirmationCallbackDeps<TContext>): Promise<boolean>;
552
- export declare function buildTelegramCompactConfirmationReplyMarkup(): TelegramCompactConfirmationReplyMarkup;
553
- export declare function getTelegramCompactConfirmationHtml(): string;
554
- export declare function openTelegramCompactConfirmation(target: TelegramCommandMessageTarget, deps: TelegramCompactConfirmationDeps): Promise<void>;
555
540
  export declare function handleTelegramCompactConfirmationCallback<TContext>(query: TelegramCompactConfirmationCallbackQuery, deps: TelegramCompactConfirmationCallbackDeps<TContext>): Promise<boolean>;
556
541
  export interface TelegramNewCommandDeps extends TelegramRuntimeEventRecorderPort {
557
542
  isIdle: () => boolean;
@@ -588,7 +573,6 @@ export declare function createTelegramCommandOrPromptRuntime<TMessage, TContext>
588
573
  export declare const TELEGRAM_INTERNAL_COMMAND_NAME = "telegram-internal";
589
574
  export declare const TELEGRAM_INTERNAL_COMMAND_DESCRIPTION = "Internal Telegram command cannot be run manually";
590
575
  export declare const TELEGRAM_INTERNAL_MANUAL_USE_MESSAGE = "This internal Telegram command cannot be run manually.";
591
- export declare function delayTelegramSessionAction(delayMs: number): Promise<void>;
592
576
  export interface TelegramSessionActionRuntimeDeps {
593
577
  registerCommand: Pi.ExtensionAPI["registerCommand"];
594
578
  sendUserMessage: Pi.ExtensionAPI["sendUserMessage"];
@@ -621,13 +605,6 @@ export interface TelegramSessionReplacementSettlementDeps {
621
605
  isCurrent?: () => boolean;
622
606
  }
623
607
  export declare function settleTelegramSessionReplacement(deps: TelegramSessionReplacementSettlementDeps): Promise<"none" | "settled" | "expired" | "failed" | "stale">;
624
- export declare function createTelegramSessionReplacementSettlementRuntime<TContext>(deps: {
625
- resolve: (ctx: TContext) => TelegramSessionReplacementSettlementDeps | undefined;
626
- onResult?: (result: "none" | "settled" | "expired" | "failed" | "stale") => void;
627
- onError?: (error: unknown) => void;
628
- }): {
629
- onSessionStart: (ctx: TContext) => void;
630
- };
631
608
  export interface TelegramSessionActionAssemblyDeps {
632
609
  registerCommand: Pi.ExtensionAPI["registerCommand"];
633
610
  sendUserMessage: Pi.ExtensionAPI["sendUserMessage"];
@@ -23,10 +23,10 @@ function getOrCreateTelegramCommandRegistry() {
23
23
  globalThis[TELEGRAM_EXTENSION_COMMAND_REGISTRY_KEY] = registry;
24
24
  return registry;
25
25
  }
26
- export function normalizeTelegramExtensionCommandName(name) {
26
+ function normalizeTelegramExtensionCommandName(name) {
27
27
  return name.trim().replace(/^\/+/, "").toLowerCase();
28
28
  }
29
- export function isTelegramExtensionCommandName(name) {
29
+ function isTelegramExtensionCommandName(name) {
30
30
  return TELEGRAM_BOT_COMMAND_NAME_PATTERN.test(name);
31
31
  }
32
32
  function normalizeTelegramExtensionCommandEmoji(emoji) {
@@ -67,7 +67,7 @@ export function registerTelegramCommand(registration) {
67
67
  registry.commands.delete(name);
68
68
  };
69
69
  }
70
- export function getTelegramExtensionCommands() {
70
+ function getTelegramExtensionCommands() {
71
71
  return Array.from(getOrCreateTelegramCommandRegistry().commands.values()).sort((a, b) => a.order - b.order || a.name.localeCompare(b.name));
72
72
  }
73
73
  export function findTelegramExtensionCommand(name) {
@@ -93,7 +93,7 @@ export const TELEGRAM_COMMAND_EMOJI = {
93
93
  name: "🏷️",
94
94
  new: "🆕",
95
95
  };
96
- export function getTelegramCommandEmoji(command) {
96
+ function getTelegramCommandEmoji(command) {
97
97
  return TELEGRAM_COMMAND_EMOJI[command];
98
98
  }
99
99
  export function formatTelegramCommandEmojiPrefix(command) {
@@ -124,14 +124,14 @@ export function formatTelegramThreadDisplayNameSavedHeading(name) {
124
124
  export function formatTelegramAutomaticThreadDisplayNameRestoredHeading(name) {
125
125
  return `<b>✅ Automatic Thread display name restored as <i>${escapeHtml(name)}</i>.</b>`;
126
126
  }
127
- export const TELEGRAM_COMPACTION_STARTED_TEXT = formatTelegramInformationHeading(getTelegramCommandEmoji("compact"), "Compaction started.");
128
- export const TELEGRAM_COMPACTION_COMPLETED_TEXT = formatTelegramInformationHeading("✅", "Compaction completed.");
127
+ const TELEGRAM_COMPACTION_STARTED_TEXT = formatTelegramInformationHeading(getTelegramCommandEmoji("compact"), "Compaction started.");
128
+ const TELEGRAM_COMPACTION_COMPLETED_TEXT = formatTelegramInformationHeading("✅", "Compaction completed.");
129
129
  export const TELEGRAM_COMPACTION_STARTED_MARKDOWN = `**${formatTelegramCommandEmojiPrefix("compact")}Compaction started.**`;
130
130
  export const TELEGRAM_COMPACTION_COMPLETED_MARKDOWN = "**✅ Compaction completed.**";
131
131
  function formatTelegramBotCommandDescription(command, description) {
132
132
  return `${formatTelegramCommandEmojiPrefix(command)}${description}`;
133
133
  }
134
- export const TELEGRAM_BUILTIN_BOT_COMMANDS = [
134
+ const TELEGRAM_BUILTIN_BOT_COMMANDS = [
135
135
  {
136
136
  command: "start",
137
137
  description: formatTelegramBotCommandDescription("start", "Open menu / Pair bridge"),
@@ -738,7 +738,7 @@ export async function handleTelegramNextCommand(deps) {
738
738
  deps.dispatchNextQueuedTurn();
739
739
  deps.updateStatus();
740
740
  }
741
- export async function handleTelegramContinueCommand(message, ctx, deps) {
741
+ async function handleTelegramContinueCommand(message, ctx, deps) {
742
742
  await deps.enqueueContinueTurn(message, ctx);
743
743
  }
744
744
  function dispatchNextQueuedTelegramTurnAfterCompact(deps) {
@@ -748,7 +748,7 @@ function dispatchNextQueuedTelegramTurnAfterCompact(deps) {
748
748
  }
749
749
  deps.dispatchNextQueuedTelegramTurn();
750
750
  }
751
- export function buildTelegramNewConfirmationReplyMarkup() {
751
+ function buildTelegramNewConfirmationReplyMarkup() {
752
752
  return {
753
753
  inline_keyboard: [
754
754
  [
@@ -758,7 +758,7 @@ export function buildTelegramNewConfirmationReplyMarkup() {
758
758
  ],
759
759
  };
760
760
  }
761
- export function getTelegramNewConfirmationHtml() {
761
+ function getTelegramNewConfirmationHtml() {
762
762
  return "<b>Start a new session?</b>";
763
763
  }
764
764
  export async function openTelegramNewConfirmation(target, deps) {
@@ -785,7 +785,7 @@ export async function handleTelegramNewConfirmationCallback(query, deps) {
785
785
  await deps.runNew(deps.ctx);
786
786
  return true;
787
787
  }
788
- export function buildTelegramCompactConfirmationReplyMarkup() {
788
+ function buildTelegramCompactConfirmationReplyMarkup() {
789
789
  return {
790
790
  inline_keyboard: [
791
791
  [
@@ -795,10 +795,10 @@ export function buildTelegramCompactConfirmationReplyMarkup() {
795
795
  ],
796
796
  };
797
797
  }
798
- export function getTelegramCompactConfirmationHtml() {
798
+ function getTelegramCompactConfirmationHtml() {
799
799
  return "<b>Compact session?</b>";
800
800
  }
801
- export async function openTelegramCompactConfirmation(target, deps) {
801
+ async function openTelegramCompactConfirmation(target, deps) {
802
802
  await deps.sendInteractiveMessage(target.chatId, getTelegramCompactConfirmationHtml(), "html", buildTelegramCompactConfirmationReplyMarkup(), target.threadId !== undefined
803
803
  ? { target: { chatId: target.chatId, threadId: target.threadId } }
804
804
  : undefined);
@@ -1277,7 +1277,7 @@ async function handleTelegramCommandRuntime(commandName, message, ctx, deps, com
1277
1277
  export const TELEGRAM_INTERNAL_COMMAND_NAME = "telegram-internal";
1278
1278
  export const TELEGRAM_INTERNAL_COMMAND_DESCRIPTION = "Internal Telegram command cannot be run manually";
1279
1279
  export const TELEGRAM_INTERNAL_MANUAL_USE_MESSAGE = "This internal Telegram command cannot be run manually.";
1280
- export function delayTelegramSessionAction(delayMs) {
1280
+ function delayTelegramSessionAction(delayMs) {
1281
1281
  return new Promise((resolve) => setTimeout(resolve, delayMs));
1282
1282
  }
1283
1283
  export async function settleTelegramSessionReplacement(deps) {
@@ -1309,7 +1309,7 @@ export async function settleTelegramSessionReplacement(deps) {
1309
1309
  }
1310
1310
  return "stale";
1311
1311
  }
1312
- export function createTelegramSessionReplacementSettlementRuntime(deps) {
1312
+ function createTelegramSessionReplacementSettlementRuntime(deps) {
1313
1313
  let generation = 0;
1314
1314
  return {
1315
1315
  onSessionStart(ctx) {
@@ -16,17 +16,10 @@ export type TelegramBotTokenReference = {
16
16
  } | {
17
17
  kind: "malformed";
18
18
  };
19
- /**
20
- * Parse a persisted bot-token value. `$NAME` and `${NAME}` are exact
21
- * environment-variable references. Any other `$`-prefixed value is malformed
22
- * rather than a literal secret so a broken reference fails closed.
23
- */
24
- export declare function getTelegramBotTokenReference(value: string | undefined): TelegramBotTokenReference | undefined;
25
19
  /** Resolve a persisted token at a validation/activation boundary. */
26
20
  export declare function resolveTelegramBotToken(value: string | undefined, env?: NodeJS.ProcessEnv): string | undefined;
27
21
  /** Redacted diagnostic for an unresolved or malformed token reference. */
28
22
  export declare function getTelegramBotTokenDiagnostic(value: string | undefined, env?: NodeJS.ProcessEnv): string | undefined;
29
- export type TelegramOutboundCommandTemplateConfig = string | CommandTemplateObjectConfig;
30
23
  export interface TelegramOutboundHandlerConfig extends CommandTemplateObjectConfig {
31
24
  type?: string;
32
25
  match?: string | string[];
@@ -179,13 +172,6 @@ export declare function normalizeTelegramDefaultProfileConfig(config: TelegramCo
179
172
  changed: boolean;
180
173
  };
181
174
  export declare function createTelegramConfigStore(options?: TelegramConfigStoreOptions): TelegramConfigStore;
182
- export declare function createTelegramDraftPreviewsChecker(configStore: Pick<TelegramConfigStore, "get">): () => boolean;
183
- export declare function createTelegramDraftPreviewsSetter(configStore: TelegramMutableConfigStore): (enabled: boolean) => Promise<void>;
184
- export declare function createTelegramAssistantRenderingModeGetter(configStore: Pick<TelegramConfigStore, "get">): () => TelegramAssistantRenderingMode;
185
- export declare function createTelegramAssistantRenderingModeSetter(configStore: TelegramMutableConfigStore): (mode: TelegramAssistantRenderingMode) => Promise<void>;
186
- export declare function createTelegramActivityVerbosityGetter(configStore: Pick<TelegramConfigStore, "get">): () => TelegramActivityVerbosity;
187
- export declare function createTelegramActivityVerbosityRefresher(configStore: TelegramMutableConfigStore): () => Promise<void>;
188
- export declare function createTelegramActivityVerbositySetter(configStore: TelegramMutableConfigStore): (verbosity: TelegramActivityVerbosity) => Promise<void>;
189
175
  export declare function createTelegramVoiceReplyModeGetter(configStore: Pick<TelegramConfigStore, "get">): () => "manual" | "mirror" | "always";
190
176
  export declare function createTelegramVoiceReplyModeConfiguredChecker(configStore: Pick<TelegramConfigStore, "get">): () => boolean;
191
177
  export declare function createTelegramVoiceReplyModeSetter(configStore: TelegramMutableConfigStore): (replyMode: "manual" | "hidden" | "mirror" | "always" | undefined) => Promise<void>;
@@ -203,9 +189,6 @@ export declare function createTelegramProactivePushTargetGetter(deps: {
203
189
  getAssignedTarget: () => TelegramProactivePushTarget | undefined;
204
190
  getAllowedUserId: () => number | undefined;
205
191
  }): () => TelegramProactivePushTarget | undefined;
206
- export declare function createTelegramAutomaticThreadCleanupChecker(configStore: Pick<TelegramConfigStore, "get">): () => boolean;
207
- export declare function createTelegramAutomaticThreadCleanupResolver(configStore: TelegramMutableConfigStore): () => Promise<boolean>;
208
- export declare function createTelegramAutomaticThreadCleanupSetter(configStore: TelegramMutableConfigStore): (enabled: boolean) => Promise<void>;
209
192
  export declare function createTelegramConfigControls(configStore: TelegramMutableConfigStore): {
210
193
  areDraftPreviewsEnabled: () => boolean;
211
194
  setDraftPreviewsEnabled: (enabled: boolean) => Promise<void>;
@@ -8,6 +8,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, u
8
8
  import { chmod, mkdir, rename, writeFile } from "node:fs/promises";
9
9
  import { resolveAgentDir, resolveTelegramConfigPath, TELEGRAM_DEFAULT_PROFILE_NAME, } from "./paths.js";
10
10
  export { TELEGRAM_DEFAULT_PROFILE_NAME } from "./paths.js";
11
+ import { isWireRecord as isPlainConfigRecord } from "./wire.js";
11
12
  import { withTelegramFileTransaction } from "./locks.js";
12
13
  const CONFIG_RUNTIME_KEY = "__piTelegramConfigRuntime__";
13
14
  const CONFIG_REPLACE_RETRY_ATTEMPTS = 5;
@@ -45,7 +46,7 @@ const TELEGRAM_BOT_TOKEN_ENV_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
45
46
  * environment-variable references. Any other `$`-prefixed value is malformed
46
47
  * rather than a literal secret so a broken reference fails closed.
47
48
  */
48
- export function getTelegramBotTokenReference(value) {
49
+ function getTelegramBotTokenReference(value) {
49
50
  const trimmed = value?.trim();
50
51
  if (!trimmed)
51
52
  return undefined;
@@ -211,9 +212,6 @@ export async function writeTelegramConfig(agentDir, configPath, config) {
211
212
  await rename(tempConfigPath, configPath);
212
213
  await chmod(configPath, 0o600);
213
214
  }
214
- function isPlainConfigRecord(value) {
215
- return !!value && typeof value === "object" && !Array.isArray(value);
216
- }
217
215
  function cloneTelegramConfig(value) {
218
216
  return structuredClone(value);
219
217
  }
@@ -628,7 +626,7 @@ export function createTelegramConfigStore(options = {}) {
628
626
  },
629
627
  };
630
628
  }
631
- export function createTelegramDraftPreviewsChecker(configStore) {
629
+ function createTelegramDraftPreviewsChecker(configStore) {
632
630
  return () => {
633
631
  const config = configStore.get();
634
632
  return (config.assistant?.draftPreviews ??
@@ -637,7 +635,7 @@ export function createTelegramDraftPreviewsChecker(configStore) {
637
635
  true);
638
636
  };
639
637
  }
640
- export function createTelegramDraftPreviewsSetter(configStore) {
638
+ function createTelegramDraftPreviewsSetter(configStore) {
641
639
  return async (enabled) => {
642
640
  await loadLatestTelegramConfig(configStore);
643
641
  const { draftPreviews: _legacyDraftPreviews, richDraftPreviews: _legacyRichDraftPreviews, ...current } = configStore.get();
@@ -649,14 +647,14 @@ export function createTelegramDraftPreviewsSetter(configStore) {
649
647
  await configStore.persist(config);
650
648
  };
651
649
  }
652
- export function createTelegramAssistantRenderingModeGetter(configStore) {
650
+ function createTelegramAssistantRenderingModeGetter(configStore) {
653
651
  return () => {
654
652
  const config = configStore.get();
655
653
  const mode = config.assistant?.rendering ?? config.assistantRendering;
656
654
  return mode === "html" ? "html" : "rich";
657
655
  };
658
656
  }
659
- export function createTelegramAssistantRenderingModeSetter(configStore) {
657
+ function createTelegramAssistantRenderingModeSetter(configStore) {
660
658
  return async (mode) => {
661
659
  await loadLatestTelegramConfig(configStore);
662
660
  const { assistantRendering: _legacyAssistantRendering, ...current } = configStore.get();
@@ -668,7 +666,7 @@ export function createTelegramAssistantRenderingModeSetter(configStore) {
668
666
  await configStore.persist(config);
669
667
  };
670
668
  }
671
- export function createTelegramActivityVerbosityGetter(configStore) {
669
+ function createTelegramActivityVerbosityGetter(configStore) {
672
670
  return () => {
673
671
  const assistant = configStore.get().assistant;
674
672
  if (assistant?.activity !== undefined) {
@@ -685,10 +683,10 @@ export function createTelegramActivityVerbosityGetter(configStore) {
685
683
  return "verbose";
686
684
  };
687
685
  }
688
- export function createTelegramActivityVerbosityRefresher(configStore) {
686
+ function createTelegramActivityVerbosityRefresher(configStore) {
689
687
  return () => loadLatestTelegramConfig(configStore);
690
688
  }
691
- export function createTelegramActivityVerbositySetter(configStore) {
689
+ function createTelegramActivityVerbositySetter(configStore) {
692
690
  return async (verbosity) => {
693
691
  await loadLatestTelegramConfig(configStore);
694
692
  const current = configStore.get();
@@ -801,10 +799,10 @@ export function createTelegramProactivePushTargetGetter(deps) {
801
799
  return typeof chatId === "number" ? { chatId } : undefined;
802
800
  };
803
801
  }
804
- export function createTelegramAutomaticThreadCleanupChecker(configStore) {
802
+ function createTelegramAutomaticThreadCleanupChecker(configStore) {
805
803
  return () => configStore.get().threads?.automaticCleanup ?? true;
806
804
  }
807
- export function createTelegramAutomaticThreadCleanupResolver(configStore) {
805
+ function createTelegramAutomaticThreadCleanupResolver(configStore) {
808
806
  return async () => {
809
807
  await loadLatestTelegramConfig(configStore);
810
808
  if (configStore.didLastLoadRecoverInvalidConfig?.()) {
@@ -813,7 +811,7 @@ export function createTelegramAutomaticThreadCleanupResolver(configStore) {
813
811
  return createTelegramAutomaticThreadCleanupChecker(configStore)();
814
812
  };
815
813
  }
816
- export function createTelegramAutomaticThreadCleanupSetter(configStore) {
814
+ function createTelegramAutomaticThreadCleanupSetter(configStore) {
817
815
  return async (enabled) => {
818
816
  await loadLatestTelegramConfig(configStore);
819
817
  const current = configStore.get();
@@ -108,10 +108,6 @@ export declare function createTelegramBridgeDeliveryLifecycleHooks<TTransportSta
108
108
  getTransportStamp?: () => TTransportStamp;
109
109
  isTransportStampActive?: (stamp: TTransportStamp) => boolean;
110
110
  }): ReturnType<typeof createTelegramDeliveryLifecycleHooks>;
111
- export declare function classifyTelegramDeliveryTransportError(error: unknown): {
112
- reason: Extract<TelegramDeliveryFailureReason, "commit-unknown" | "message-unavailable" | "rate-limited" | "transport-retryable" | "transport-failed">;
113
- retryAfterMs?: number;
114
- };
115
111
  /** @internal */
116
112
  export interface TelegramDeliveryTargetPolicyView {
117
113
  canDeliver: boolean;
@@ -6,7 +6,7 @@
6
6
  import { markTelegramBusAggregateDelivery } from "./bus.js";
7
7
  import { assertTelegramInlineKeyboardCallbackData, } from "./keyboard.js";
8
8
  import { withTelegramReplyParameters, renderTelegramMessage, } from "./replies.js";
9
- import { getTelegramTargetThreadParams, } from "./target.js";
9
+ import { areTelegramTargetsEqual as areDeliveryTargetsEqual, getTelegramTargetThreadParams, } from "./target.js";
10
10
  import { getTelegramApiRetryAfterMs, isRetryableTelegramApiError, isTelegramApiCommitUnknownError, isTelegramMessageUnavailableError, } from "./telegram-api.js";
11
11
  const TELEGRAM_DELIVERY_RUNTIME_KEY = "__piTelegramDeliveryRuntime__";
12
12
  class TelegramDeliveryTransportGenerationError extends Error {
@@ -69,7 +69,7 @@ function failure(reason, message, partial, retryAfterMs) {
69
69
  ? { ok: false, reason, message, ...retry }
70
70
  : { ok: false, reason, message, partial, ...retry };
71
71
  }
72
- export function classifyTelegramDeliveryTransportError(error) {
72
+ function classifyTelegramDeliveryTransportError(error) {
73
73
  if (isTelegramApiCommitUnknownError(error))
74
74
  return { reason: "commit-unknown" };
75
75
  if (isTelegramMessageUnavailableError(error))
@@ -140,9 +140,6 @@ export function isTelegramDeliveryExplicitTargetAuthorized(candidate, view) {
140
140
  return areDeliveryTargetsEqual(candidate, target);
141
141
  });
142
142
  }
143
- function areDeliveryTargetsEqual(left, right) {
144
- return left.chatId === right.chatId && left.threadId === right.threadId;
145
- }
146
143
  function cloneTarget(target) {
147
144
  return target.threadId === undefined
148
145
  ? { chatId: target.chatId }