@llblab/pi-telegram 0.51.5 → 0.52.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 (181) hide show
  1. package/AGENTS.md +10 -8
  2. package/BACKLOG.md +1 -8
  3. package/CHANGELOG.md +23 -0
  4. package/LICENSE +21 -0
  5. package/README.md +16 -6
  6. package/dist/lib/activity-verbosity.d.ts +1 -5
  7. package/dist/lib/activity-verbosity.js +5 -7
  8. package/dist/lib/bindings.d.ts +9 -2
  9. package/dist/lib/bindings.js +22 -13
  10. package/dist/lib/bus-api.js +4 -2
  11. package/dist/lib/bus-follower.d.ts +55 -57
  12. package/dist/lib/bus-follower.js +213 -140
  13. package/dist/lib/bus-leader.d.ts +21 -2
  14. package/dist/lib/bus-leader.js +181 -25
  15. package/dist/lib/bus-transport.d.ts +4 -1
  16. package/dist/lib/bus-transport.js +28 -4
  17. package/dist/lib/bus.d.ts +52 -56
  18. package/dist/lib/bus.js +78 -246
  19. package/dist/lib/channel-posts.d.ts +1 -3
  20. package/dist/lib/channel-posts.js +23 -26
  21. package/dist/lib/command-templates.d.ts +0 -5
  22. package/dist/lib/command-templates.js +5 -5
  23. package/dist/lib/commands.d.ts +12 -26
  24. package/dist/lib/commands.js +152 -98
  25. package/dist/lib/config.d.ts +0 -17
  26. package/dist/lib/config.js +12 -14
  27. package/dist/lib/delivery.d.ts +0 -4
  28. package/dist/lib/delivery.js +2 -5
  29. package/dist/lib/extension.js +281 -61
  30. package/dist/lib/generative-apps.d.ts +0 -19
  31. package/dist/lib/inbound.d.ts +0 -2
  32. package/dist/lib/inbound.js +2 -2
  33. package/dist/lib/journal.d.ts +177 -16
  34. package/dist/lib/journal.js +1115 -249
  35. package/dist/lib/keyboard.d.ts +0 -2
  36. package/dist/lib/keyboard.js +2 -2
  37. package/dist/lib/lifecycle.d.ts +57 -2
  38. package/dist/lib/lifecycle.js +110 -5
  39. package/dist/lib/locks.d.ts +100 -12
  40. package/dist/lib/locks.js +380 -14
  41. package/dist/lib/logging.d.ts +30 -12
  42. package/dist/lib/logging.js +129 -72
  43. package/dist/lib/media.d.ts +28 -5
  44. package/dist/lib/media.js +26 -8
  45. package/dist/lib/menu-model.d.ts +0 -11
  46. package/dist/lib/menu-model.js +8 -8
  47. package/dist/lib/menu-settings.d.ts +0 -18
  48. package/dist/lib/menu-settings.js +18 -18
  49. package/dist/lib/menu-status.d.ts +4 -4
  50. package/dist/lib/menu-status.js +12 -7
  51. package/dist/lib/menu-thinking.d.ts +1 -1
  52. package/dist/lib/menu-thinking.js +1 -1
  53. package/dist/lib/menu.d.ts +1 -0
  54. package/dist/lib/menu.js +4 -3
  55. package/dist/lib/model.js +2 -4
  56. package/dist/lib/outbound-attachments.d.ts +0 -1
  57. package/dist/lib/outbound-attachments.js +1 -1
  58. package/dist/lib/outbound-buttons.js +1 -8
  59. package/dist/lib/outbound-markup.d.ts +1 -6
  60. package/dist/lib/outbound-markup.js +4 -21
  61. package/dist/lib/outbound.d.ts +0 -8
  62. package/dist/lib/outbound.js +5 -5
  63. package/dist/lib/paths.d.ts +50 -7
  64. package/dist/lib/paths.js +155 -17
  65. package/dist/lib/pi.d.ts +1 -0
  66. package/dist/lib/pi.js +2 -1
  67. package/dist/lib/polling.d.ts +0 -5
  68. package/dist/lib/polling.js +5 -5
  69. package/dist/lib/preview.d.ts +0 -3
  70. package/dist/lib/preview.js +3 -3
  71. package/dist/lib/prompt-templates.d.ts +0 -1
  72. package/dist/lib/prompt-templates.js +1 -1
  73. package/dist/lib/queue.d.ts +3 -15
  74. package/dist/lib/queue.js +69 -8
  75. package/dist/lib/recovery.d.ts +29 -9
  76. package/dist/lib/recovery.js +104 -33
  77. package/dist/lib/replies.d.ts +0 -4
  78. package/dist/lib/replies.js +1 -1
  79. package/dist/lib/routing.d.ts +73 -8
  80. package/dist/lib/routing.js +2206 -307
  81. package/dist/lib/sections.d.ts +0 -2
  82. package/dist/lib/sections.js +1 -1
  83. package/dist/lib/status.d.ts +46 -9
  84. package/dist/lib/status.js +179 -27
  85. package/dist/lib/sync.d.ts +0 -5
  86. package/dist/lib/sync.js +9 -8
  87. package/dist/lib/telegram-api.d.ts +11 -3
  88. package/dist/lib/telegram-api.js +34 -23
  89. package/dist/lib/thread-cleanup-manager.d.ts +1 -0
  90. package/dist/lib/thread-cleanup-manager.js +18 -21
  91. package/dist/lib/thread-naming.d.ts +32 -5
  92. package/dist/lib/thread-naming.js +191 -7
  93. package/dist/lib/thread-reconciler.d.ts +2 -0
  94. package/dist/lib/thread-reconciler.js +1 -1
  95. package/dist/lib/threads.d.ts +292 -59
  96. package/dist/lib/threads.js +1664 -373
  97. package/dist/lib/turns.d.ts +0 -1
  98. package/dist/lib/turns.js +1 -1
  99. package/dist/lib/updates.d.ts +184 -28
  100. package/dist/lib/updates.js +1032 -114
  101. package/dist/lib/wire.d.ts +12 -0
  102. package/dist/lib/wire.js +21 -0
  103. package/dist/lib/workspace-admission.d.ts +25 -17
  104. package/dist/lib/workspace-admission.js +95 -20
  105. package/dist/lib/workspace-identity.d.ts +20 -0
  106. package/dist/lib/workspace-identity.js +103 -0
  107. package/dist/lib/workspace-retirement.d.ts +45 -10
  108. package/dist/lib/workspace-retirement.js +196 -64
  109. package/dist/package.json +6 -6
  110. package/dist/skills/generated-control-surface/SKILL.md +3 -3
  111. package/dist/skills/telegram-bridge/references/diagnosis.md +3 -3
  112. package/docs/README.md +1 -1
  113. package/docs/activity.md +1 -1
  114. package/docs/architecture.md +158 -39
  115. package/docs/callback-namespaces.md +1 -1
  116. package/docs/delivery.md +1 -1
  117. package/docs/generative-apps.md +2 -2
  118. package/docs/inbound.md +1 -1
  119. package/docs/multi-instance-bus.md +127 -19
  120. package/docs/public-api.md +5 -3
  121. package/docs/ui-style.md +26 -8
  122. package/docs/updates.md +1 -1
  123. package/lib/activity-verbosity.ts +5 -9
  124. package/lib/bindings.ts +23 -10
  125. package/lib/bus-api.ts +5 -2
  126. package/lib/bus-follower.ts +251 -226
  127. package/lib/bus-leader.ts +178 -31
  128. package/lib/bus-transport.ts +30 -8
  129. package/lib/bus.ts +110 -334
  130. package/lib/channel-posts.ts +29 -29
  131. package/lib/command-templates.ts +5 -5
  132. package/lib/commands.ts +150 -112
  133. package/lib/config.ts +12 -17
  134. package/lib/delivery.ts +2 -8
  135. package/lib/extension.ts +282 -72
  136. package/lib/generative-apps.ts +0 -22
  137. package/lib/inbound.ts +2 -2
  138. package/lib/journal.ts +1182 -326
  139. package/lib/keyboard.ts +2 -2
  140. package/lib/lifecycle.ts +141 -5
  141. package/lib/locks.ts +402 -23
  142. package/lib/logging.ts +151 -101
  143. package/lib/media.ts +51 -9
  144. package/lib/menu-model.ts +8 -8
  145. package/lib/menu-settings.ts +18 -18
  146. package/lib/menu-status.ts +11 -0
  147. package/lib/menu-thinking.ts +2 -2
  148. package/lib/menu.ts +5 -1
  149. package/lib/model.ts +2 -4
  150. package/lib/outbound-attachments.ts +1 -1
  151. package/lib/outbound-buttons.ts +1 -10
  152. package/lib/outbound-markup.ts +5 -24
  153. package/lib/outbound.ts +5 -5
  154. package/lib/paths.ts +177 -17
  155. package/lib/pi.ts +5 -2
  156. package/lib/polling.ts +5 -5
  157. package/lib/preview.ts +3 -3
  158. package/lib/prompt-templates.ts +1 -1
  159. package/lib/queue.ts +67 -9
  160. package/lib/recovery.ts +104 -44
  161. package/lib/replies.ts +1 -1
  162. package/lib/routing.ts +1955 -375
  163. package/lib/sections.ts +1 -1
  164. package/lib/status.ts +185 -36
  165. package/lib/sync.ts +8 -8
  166. package/lib/telegram-api.ts +48 -33
  167. package/lib/thread-cleanup-manager.ts +24 -21
  168. package/lib/thread-naming.ts +267 -9
  169. package/lib/thread-reconciler.ts +3 -1
  170. package/lib/threads.ts +1718 -491
  171. package/lib/turns.ts +1 -1
  172. package/lib/updates.ts +1072 -151
  173. package/lib/wire.ts +28 -0
  174. package/lib/workspace-admission.ts +97 -47
  175. package/lib/workspace-identity.ts +147 -0
  176. package/lib/workspace-retirement.ts +234 -102
  177. package/package.json +6 -6
  178. package/scripts/audit-exports.mjs +100 -0
  179. package/scripts/check-downgrade.mjs +80 -43
  180. package/skills/generated-control-surface/SKILL.md +3 -3
  181. package/skills/telegram-bridge/references/diagnosis.md +3 -3
package/lib/config.ts CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  export { TELEGRAM_DEFAULT_PROFILE_NAME } from "./paths.ts";
25
25
 
26
26
  import type { CommandTemplateObjectConfig } from "./command-templates.ts";
27
+ import { isWireRecord as isPlainConfigRecord } from "./wire.ts";
27
28
  import type { TelegramInboundHandlerConfig } from "./inbound.ts";
28
29
  import { withTelegramFileTransaction } from "./locks.ts";
29
30
 
@@ -75,7 +76,7 @@ export type TelegramBotTokenReference =
75
76
  * environment-variable references. Any other `$`-prefixed value is malformed
76
77
  * rather than a literal secret so a broken reference fails closed.
77
78
  */
78
- export function getTelegramBotTokenReference(
79
+ function getTelegramBotTokenReference(
79
80
  value: string | undefined,
80
81
  ): TelegramBotTokenReference | undefined {
81
82
  const trimmed = value?.trim();
@@ -115,8 +116,6 @@ export function getTelegramBotTokenDiagnostic(
115
116
  return `Telegram bot token environment variable ${reference.variable} is not set.`;
116
117
  }
117
118
 
118
- export type TelegramOutboundCommandTemplateConfig =
119
- string | CommandTemplateObjectConfig;
120
119
  export interface TelegramOutboundHandlerConfig extends CommandTemplateObjectConfig {
121
120
  type?: string;
122
121
  match?: string | string[];
@@ -465,10 +464,6 @@ export async function writeTelegramConfig(
465
464
  await chmod(configPath, 0o600);
466
465
  }
467
466
 
468
- function isPlainConfigRecord(value: unknown): value is Record<string, unknown> {
469
- return !!value && typeof value === "object" && !Array.isArray(value);
470
- }
471
-
472
467
  function cloneTelegramConfig<T>(value: T): T {
473
468
  return structuredClone(value);
474
469
  }
@@ -963,7 +958,7 @@ export function createTelegramConfigStore(
963
958
  };
964
959
  }
965
960
 
966
- export function createTelegramDraftPreviewsChecker(
961
+ function createTelegramDraftPreviewsChecker(
967
962
  configStore: Pick<TelegramConfigStore, "get">,
968
963
  ): () => boolean {
969
964
  return () => {
@@ -977,7 +972,7 @@ export function createTelegramDraftPreviewsChecker(
977
972
  };
978
973
  }
979
974
 
980
- export function createTelegramDraftPreviewsSetter(
975
+ function createTelegramDraftPreviewsSetter(
981
976
  configStore: TelegramMutableConfigStore,
982
977
  ): (enabled: boolean) => Promise<void> {
983
978
  return async (enabled) => {
@@ -996,7 +991,7 @@ export function createTelegramDraftPreviewsSetter(
996
991
  };
997
992
  }
998
993
 
999
- export function createTelegramAssistantRenderingModeGetter(
994
+ function createTelegramAssistantRenderingModeGetter(
1000
995
  configStore: Pick<TelegramConfigStore, "get">,
1001
996
  ): () => TelegramAssistantRenderingMode {
1002
997
  return () => {
@@ -1006,7 +1001,7 @@ export function createTelegramAssistantRenderingModeGetter(
1006
1001
  };
1007
1002
  }
1008
1003
 
1009
- export function createTelegramAssistantRenderingModeSetter(
1004
+ function createTelegramAssistantRenderingModeSetter(
1010
1005
  configStore: TelegramMutableConfigStore,
1011
1006
  ): (mode: TelegramAssistantRenderingMode) => Promise<void> {
1012
1007
  return async (mode) => {
@@ -1022,7 +1017,7 @@ export function createTelegramAssistantRenderingModeSetter(
1022
1017
  };
1023
1018
  }
1024
1019
 
1025
- export function createTelegramActivityVerbosityGetter(
1020
+ function createTelegramActivityVerbosityGetter(
1026
1021
  configStore: Pick<TelegramConfigStore, "get">,
1027
1022
  ): () => TelegramActivityVerbosity {
1028
1023
  return () => {
@@ -1044,13 +1039,13 @@ export function createTelegramActivityVerbosityGetter(
1044
1039
  };
1045
1040
  }
1046
1041
 
1047
- export function createTelegramActivityVerbosityRefresher(
1042
+ function createTelegramActivityVerbosityRefresher(
1048
1043
  configStore: TelegramMutableConfigStore,
1049
1044
  ): () => Promise<void> {
1050
1045
  return () => loadLatestTelegramConfig(configStore);
1051
1046
  }
1052
1047
 
1053
- export function createTelegramActivityVerbositySetter(
1048
+ function createTelegramActivityVerbositySetter(
1054
1049
  configStore: TelegramMutableConfigStore,
1055
1050
  ): (verbosity: TelegramActivityVerbosity) => Promise<void> {
1056
1051
  return async (verbosity) => {
@@ -1210,13 +1205,13 @@ export function createTelegramProactivePushTargetGetter(deps: {
1210
1205
  };
1211
1206
  }
1212
1207
 
1213
- export function createTelegramAutomaticThreadCleanupChecker(
1208
+ function createTelegramAutomaticThreadCleanupChecker(
1214
1209
  configStore: Pick<TelegramConfigStore, "get">,
1215
1210
  ): () => boolean {
1216
1211
  return () => configStore.get().threads?.automaticCleanup ?? true;
1217
1212
  }
1218
1213
 
1219
- export function createTelegramAutomaticThreadCleanupResolver(
1214
+ function createTelegramAutomaticThreadCleanupResolver(
1220
1215
  configStore: TelegramMutableConfigStore,
1221
1216
  ): () => Promise<boolean> {
1222
1217
  return async () => {
@@ -1230,7 +1225,7 @@ export function createTelegramAutomaticThreadCleanupResolver(
1230
1225
  };
1231
1226
  }
1232
1227
 
1233
- export function createTelegramAutomaticThreadCleanupSetter(
1228
+ function createTelegramAutomaticThreadCleanupSetter(
1234
1229
  configStore: TelegramMutableConfigStore,
1235
1230
  ): (enabled: boolean) => Promise<void> {
1236
1231
  return async (enabled) => {
package/lib/delivery.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  renderTelegramMessage,
15
15
  } from "./replies.ts";
16
16
  import {
17
+ areTelegramTargetsEqual as areDeliveryTargetsEqual,
17
18
  getTelegramTargetThreadParams,
18
19
  type TelegramTarget,
19
20
  } from "./target.ts";
@@ -262,7 +263,7 @@ function failure<T>(
262
263
  : { ok: false, reason, message, partial, ...retry };
263
264
  }
264
265
 
265
- export function classifyTelegramDeliveryTransportError(error: unknown): {
266
+ function classifyTelegramDeliveryTransportError(error: unknown): {
266
267
  reason: Extract<TelegramDeliveryFailureReason,
267
268
  "commit-unknown" | "message-unavailable" | "rate-limited" |
268
269
  "transport-retryable" | "transport-failed">;
@@ -374,13 +375,6 @@ export function isTelegramDeliveryExplicitTargetAuthorized(
374
375
  });
375
376
  }
376
377
 
377
- function areDeliveryTargetsEqual(
378
- left: TelegramDeliveryTarget,
379
- right: TelegramDeliveryTarget,
380
- ): boolean {
381
- return left.chatId === right.chatId && left.threadId === right.threadId;
382
- }
383
-
384
378
  function cloneTarget(target: TelegramDeliveryTarget): TelegramDeliveryTarget {
385
379
  return target.threadId === undefined
386
380
  ? { chatId: target.chatId }