@llblab/pi-kit 0.29.1 → 0.30.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 (222) hide show
  1. package/BACKLOG.md +3 -1
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +4 -4
  4. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +12 -0
  5. package/node_modules/@llblab/pi-state-flow/README.md +2 -2
  6. package/node_modules/@llblab/pi-state-flow/dist/lib/context.d.ts +2 -2
  7. package/node_modules/@llblab/pi-state-flow/dist/lib/context.js +17 -8
  8. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +7 -3
  9. package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.d.ts +2 -1
  10. package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.js +3 -2
  11. package/node_modules/@llblab/pi-state-flow/dist/package.json +1 -1
  12. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +3 -3
  13. package/node_modules/@llblab/pi-state-flow/docs/usage.md +3 -2
  14. package/node_modules/@llblab/pi-state-flow/lib/context.ts +17 -8
  15. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +6 -3
  16. package/node_modules/@llblab/pi-state-flow/lib/protocol.ts +4 -2
  17. package/node_modules/@llblab/pi-state-flow/package.json +1 -1
  18. package/node_modules/@llblab/pi-telegram/AGENTS.md +13 -10
  19. package/node_modules/@llblab/pi-telegram/BACKLOG.md +1 -1
  20. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +23 -0
  21. package/node_modules/@llblab/pi-telegram/README.md +10 -11
  22. package/node_modules/@llblab/pi-telegram/api/commands.ts +3 -0
  23. package/node_modules/@llblab/pi-telegram/dist/api/commands.d.ts +1 -1
  24. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.d.ts +1 -5
  25. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.js +15 -42
  26. package/node_modules/@llblab/pi-telegram/dist/lib/activity.d.ts +9 -0
  27. package/node_modules/@llblab/pi-telegram/dist/lib/activity.js +39 -10
  28. package/node_modules/@llblab/pi-telegram/dist/lib/agent-messages.js +7 -3
  29. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +43 -5
  30. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +164 -20
  31. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.d.ts +12 -0
  32. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.js +181 -77
  33. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +111 -31
  34. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +1324 -359
  35. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.d.ts +41 -91
  36. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.js +969 -637
  37. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.js +16 -9
  38. package/node_modules/@llblab/pi-telegram/dist/lib/bus.d.ts +215 -18
  39. package/node_modules/@llblab/pi-telegram/dist/lib/bus.js +1048 -327
  40. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.d.ts +5 -0
  41. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.js +434 -261
  42. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.d.ts +26 -5
  43. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.js +92 -176
  44. package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +168 -82
  45. package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +1409 -291
  46. package/node_modules/@llblab/pi-telegram/dist/lib/config.d.ts +1 -8
  47. package/node_modules/@llblab/pi-telegram/dist/lib/config.js +34 -76
  48. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +2 -2
  49. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +16 -16
  50. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +642 -170
  51. package/node_modules/@llblab/pi-telegram/dist/lib/generative-app-worker.mjs +19 -7
  52. package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.d.ts +0 -5
  53. package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.js +61 -49
  54. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.d.ts +5 -0
  55. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.js +35 -59
  56. package/node_modules/@llblab/pi-telegram/dist/lib/journal.d.ts +40 -4
  57. package/node_modules/@llblab/pi-telegram/dist/lib/journal.js +2102 -760
  58. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.d.ts +2 -6
  59. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +75 -58
  60. package/node_modules/@llblab/pi-telegram/dist/lib/locks.d.ts +34 -3
  61. package/node_modules/@llblab/pi-telegram/dist/lib/locks.js +318 -119
  62. package/node_modules/@llblab/pi-telegram/dist/lib/logging.js +50 -14
  63. package/node_modules/@llblab/pi-telegram/dist/lib/media.d.ts +22 -1
  64. package/node_modules/@llblab/pi-telegram/dist/lib/media.js +46 -28
  65. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.d.ts +19 -5
  66. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.js +53 -11
  67. package/node_modules/@llblab/pi-telegram/dist/lib/menu-queue.d.ts +5 -4
  68. package/node_modules/@llblab/pi-telegram/dist/lib/menu-queue.js +45 -63
  69. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +5 -4
  70. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +114 -78
  71. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.d.ts +1 -1
  72. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.js +8 -25
  73. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.d.ts +6 -1
  74. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.js +14 -21
  75. package/node_modules/@llblab/pi-telegram/dist/lib/menu.d.ts +8 -61
  76. package/node_modules/@llblab/pi-telegram/dist/lib/menu.js +92 -164
  77. package/node_modules/@llblab/pi-telegram/dist/lib/model.d.ts +1 -1
  78. package/node_modules/@llblab/pi-telegram/dist/lib/model.js +2 -16
  79. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.d.ts +6 -27
  80. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.js +45 -38
  81. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.js +22 -16
  82. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.d.ts +0 -2
  83. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.js +51 -64
  84. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-voice.js +6 -3
  85. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.d.ts +6 -6
  86. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.js +61 -51
  87. package/node_modules/@llblab/pi-telegram/dist/lib/ownership.js +6 -2
  88. package/node_modules/@llblab/pi-telegram/dist/lib/paths.d.ts +5 -0
  89. package/node_modules/@llblab/pi-telegram/dist/lib/paths.js +37 -21
  90. package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +2 -0
  91. package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +8 -1
  92. package/node_modules/@llblab/pi-telegram/dist/lib/polling.d.ts +23 -37
  93. package/node_modules/@llblab/pi-telegram/dist/lib/polling.js +71 -52
  94. package/node_modules/@llblab/pi-telegram/dist/lib/preview.js +39 -19
  95. package/node_modules/@llblab/pi-telegram/dist/lib/process-identity.d.ts +24 -0
  96. package/node_modules/@llblab/pi-telegram/dist/lib/process-identity.js +133 -0
  97. package/node_modules/@llblab/pi-telegram/dist/lib/prompts.js +2 -7
  98. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +16 -16
  99. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +261 -116
  100. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.d.ts +2 -83
  101. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.js +20 -274
  102. package/node_modules/@llblab/pi-telegram/dist/lib/replies.d.ts +16 -24
  103. package/node_modules/@llblab/pi-telegram/dist/lib/replies.js +99 -116
  104. package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +121 -7
  105. package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +4750 -1161
  106. package/node_modules/@llblab/pi-telegram/dist/lib/runtime.d.ts +1 -11
  107. package/node_modules/@llblab/pi-telegram/dist/lib/sections.d.ts +4 -29
  108. package/node_modules/@llblab/pi-telegram/dist/lib/sections.js +7 -20
  109. package/node_modules/@llblab/pi-telegram/dist/lib/skills.js +4 -3
  110. package/node_modules/@llblab/pi-telegram/dist/lib/status.js +86 -57
  111. package/node_modules/@llblab/pi-telegram/dist/lib/sync.d.ts +6 -3
  112. package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +112 -45
  113. package/node_modules/@llblab/pi-telegram/dist/lib/target.d.ts +4 -0
  114. package/node_modules/@llblab/pi-telegram/dist/lib/target.js +18 -0
  115. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.d.ts +18 -11
  116. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +165 -49
  117. package/node_modules/@llblab/pi-telegram/dist/lib/text-groups.js +4 -39
  118. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.d.ts +6 -27
  119. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.js +369 -186
  120. package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.d.ts +1 -2
  121. package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.js +58 -38
  122. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.d.ts +28 -8
  123. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.js +175 -66
  124. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.d.ts +42 -16
  125. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.js +90 -50
  126. package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +88 -24
  127. package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +2276 -842
  128. package/node_modules/@llblab/pi-telegram/dist/lib/time-injection.js +1 -2
  129. package/node_modules/@llblab/pi-telegram/dist/lib/turns.js +1 -19
  130. package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +178 -82
  131. package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +2438 -645
  132. package/node_modules/@llblab/pi-telegram/dist/lib/voice.d.ts +7 -22
  133. package/node_modules/@llblab/pi-telegram/dist/lib/voice.js +7 -22
  134. package/node_modules/@llblab/pi-telegram/dist/lib/wire.js +1 -1
  135. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.d.ts +3 -1
  136. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.js +425 -211
  137. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-identity.js +8 -13
  138. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +1 -1
  139. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +328 -140
  140. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.js +8 -4
  141. package/node_modules/@llblab/pi-telegram/dist/package.json +1 -1
  142. package/node_modules/@llblab/pi-telegram/docs/architecture.md +43 -35
  143. package/node_modules/@llblab/pi-telegram/docs/inbound.md +1 -1
  144. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +15 -3
  145. package/node_modules/@llblab/pi-telegram/docs/outbound.md +1 -1
  146. package/node_modules/@llblab/pi-telegram/docs/public-api.md +29 -1
  147. package/node_modules/@llblab/pi-telegram/docs/ui-style.md +25 -8
  148. package/node_modules/@llblab/pi-telegram/lib/activity-verbosity.ts +59 -82
  149. package/node_modules/@llblab/pi-telegram/lib/activity.ts +146 -102
  150. package/node_modules/@llblab/pi-telegram/lib/agent-messages.ts +12 -5
  151. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +390 -82
  152. package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +262 -99
  153. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +2440 -601
  154. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +2209 -1290
  155. package/node_modules/@llblab/pi-telegram/lib/bus-transport.ts +46 -12
  156. package/node_modules/@llblab/pi-telegram/lib/bus.ts +1673 -444
  157. package/node_modules/@llblab/pi-telegram/lib/channel-posts.ts +848 -327
  158. package/node_modules/@llblab/pi-telegram/lib/command-templates.ts +152 -265
  159. package/node_modules/@llblab/pi-telegram/lib/commands.ts +2398 -555
  160. package/node_modules/@llblab/pi-telegram/lib/config.ts +177 -170
  161. package/node_modules/@llblab/pi-telegram/lib/delivery.ts +41 -29
  162. package/node_modules/@llblab/pi-telegram/lib/extension.ts +1209 -431
  163. package/node_modules/@llblab/pi-telegram/lib/generative-app-worker.mjs +19 -7
  164. package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +324 -211
  165. package/node_modules/@llblab/pi-telegram/lib/inbound.ts +95 -97
  166. package/node_modules/@llblab/pi-telegram/lib/journal.ts +5329 -1712
  167. package/node_modules/@llblab/pi-telegram/lib/keyboard.ts +1 -3
  168. package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +128 -78
  169. package/node_modules/@llblab/pi-telegram/lib/locks.ts +703 -212
  170. package/node_modules/@llblab/pi-telegram/lib/logging.ts +147 -58
  171. package/node_modules/@llblab/pi-telegram/lib/media.ts +82 -43
  172. package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +85 -18
  173. package/node_modules/@llblab/pi-telegram/lib/menu-queue.ts +88 -129
  174. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +260 -155
  175. package/node_modules/@llblab/pi-telegram/lib/menu-status.ts +20 -60
  176. package/node_modules/@llblab/pi-telegram/lib/menu-thinking.ts +41 -56
  177. package/node_modules/@llblab/pi-telegram/lib/menu.ts +112 -285
  178. package/node_modules/@llblab/pi-telegram/lib/model.ts +8 -22
  179. package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +156 -125
  180. package/node_modules/@llblab/pi-telegram/lib/outbound-buttons.ts +76 -49
  181. package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +96 -94
  182. package/node_modules/@llblab/pi-telegram/lib/outbound-voice.ts +33 -27
  183. package/node_modules/@llblab/pi-telegram/lib/outbound.ts +125 -125
  184. package/node_modules/@llblab/pi-telegram/lib/ownership.ts +19 -10
  185. package/node_modules/@llblab/pi-telegram/lib/paths.ts +148 -49
  186. package/node_modules/@llblab/pi-telegram/lib/pi.ts +35 -15
  187. package/node_modules/@llblab/pi-telegram/lib/polling.ts +165 -149
  188. package/node_modules/@llblab/pi-telegram/lib/preview.ts +93 -40
  189. package/node_modules/@llblab/pi-telegram/lib/process-identity.ts +164 -0
  190. package/node_modules/@llblab/pi-telegram/lib/prompts.ts +4 -11
  191. package/node_modules/@llblab/pi-telegram/lib/queue.ts +523 -289
  192. package/node_modules/@llblab/pi-telegram/lib/recovery.ts +50 -454
  193. package/node_modules/@llblab/pi-telegram/lib/rendering.ts +1 -3
  194. package/node_modules/@llblab/pi-telegram/lib/replies.ts +248 -209
  195. package/node_modules/@llblab/pi-telegram/lib/routing.ts +8527 -2149
  196. package/node_modules/@llblab/pi-telegram/lib/runtime.ts +1 -12
  197. package/node_modules/@llblab/pi-telegram/lib/sections.ts +24 -89
  198. package/node_modules/@llblab/pi-telegram/lib/setup.ts +1 -3
  199. package/node_modules/@llblab/pi-telegram/lib/skills.ts +9 -4
  200. package/node_modules/@llblab/pi-telegram/lib/status.ts +215 -110
  201. package/node_modules/@llblab/pi-telegram/lib/sync.ts +488 -359
  202. package/node_modules/@llblab/pi-telegram/lib/target.ts +22 -3
  203. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +322 -122
  204. package/node_modules/@llblab/pi-telegram/lib/text-groups.ts +5 -39
  205. package/node_modules/@llblab/pi-telegram/lib/thread-cleanup-manager.ts +833 -331
  206. package/node_modules/@llblab/pi-telegram/lib/thread-display.ts +213 -97
  207. package/node_modules/@llblab/pi-telegram/lib/thread-naming.ts +232 -87
  208. package/node_modules/@llblab/pi-telegram/lib/thread-reconciler.ts +155 -72
  209. package/node_modules/@llblab/pi-telegram/lib/threads.ts +5329 -1817
  210. package/node_modules/@llblab/pi-telegram/lib/time-injection.ts +1 -4
  211. package/node_modules/@llblab/pi-telegram/lib/turns.ts +15 -28
  212. package/node_modules/@llblab/pi-telegram/lib/updates.ts +5194 -1600
  213. package/node_modules/@llblab/pi-telegram/lib/voice.ts +7 -35
  214. package/node_modules/@llblab/pi-telegram/lib/wire.ts +1 -1
  215. package/node_modules/@llblab/pi-telegram/lib/workspace-admission.ts +996 -416
  216. package/node_modules/@llblab/pi-telegram/lib/workspace-identity.ts +14 -17
  217. package/node_modules/@llblab/pi-telegram/lib/workspace-retirement.ts +878 -376
  218. package/node_modules/@llblab/pi-telegram/lib/workspace-slots.ts +22 -13
  219. package/node_modules/@llblab/pi-telegram/package.json +1 -1
  220. package/package.json +3 -3
  221. package/node_modules/@llblab/pi-telegram/scripts/check-downgrade.mjs +0 -472
  222. package/node_modules/@llblab/pi-telegram/scripts/measure-workspace.mjs +0 -108
@@ -45,8 +45,7 @@ export function createTimeInjectionRuntime(deps) {
45
45
  return line;
46
46
  const previous = lastInjectedAt.get(chatId);
47
47
  const nowMs = now.getTime();
48
- if (previous !== undefined &&
49
- nowMs - previous < config.interval) {
48
+ if (previous !== undefined && nowMs - previous < config.interval) {
50
49
  return null;
51
50
  }
52
51
  lastInjectedAt.set(chatId, nowMs);
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { readFile } from "node:fs/promises";
7
7
  import { basename, dirname, join } from "node:path";
8
- import { buildTelegramReplyContextBlock, collectTelegramFileInfos, collectTelegramMessageIds, downloadTelegramMessageFiles, extractTelegramForwardContextText, extractTelegramMessagesPromptText, extractTelegramMessagesText, extractTelegramMessageText, formatTelegramHistoryText, guessMediaType, } from "./media.js";
8
+ import { appendTelegramAttachmentSection, appendTelegramListSection, buildTelegramReplyContextBlock, collectTelegramFileInfos, collectTelegramMessageIds, downloadTelegramMessageFiles, extractTelegramForwardContextText, extractTelegramMessagesPromptText, extractTelegramMessagesText, extractTelegramMessageText, formatTelegramHistoryText, guessMediaType, } from "./media.js";
9
9
  import { createTelegramQueueAdmissionReceipt, truncateTelegramQueueSummary, } from "./queue.js";
10
10
  import { computeVoicePromptContribution, computeVoiceTurnFlags, getTelegramVoiceReplyMode, } from "./voice.js";
11
11
  export const TELEGRAM_PREFIX = "[telegram]";
@@ -49,24 +49,6 @@ export function formatTelegramTurnStatusSummary(rawText, files, handlerOutputs =
49
49
  return `📎 ${files.length} attachments`;
50
50
  return "(empty message)";
51
51
  }
52
- function appendTelegramListSection(text, title, items) {
53
- if (items.length === 0)
54
- return text;
55
- const prefix = text.length > 0 ? `${text}\n\n` : "";
56
- return `${prefix}[${title}]\n${items.map((item) => `- ${item}`).join("\n")}`;
57
- }
58
- function appendTelegramAttachmentSection(text, files) {
59
- if (files.length === 0)
60
- return text;
61
- const dirs = [...new Set(files.map((file) => dirname(file.path)))];
62
- const sameDir = dirs.length === 1;
63
- const header = sameDir ? `[attachments] ${dirs[0]}` : "[attachments]";
64
- const items = sameDir
65
- ? files.map((file) => `/${basename(file.path)}`)
66
- : files.map((file) => file.path);
67
- const prefix = text.length > 0 ? `${text}\n\n` : "";
68
- return `${prefix}${header}\n${items.map((item) => `- ${item}`).join("\n")}`;
69
- }
70
52
  function appendTelegramSourceContext(text, sourceContext) {
71
53
  if (!sourceContext)
72
54
  return text;
@@ -3,12 +3,13 @@
3
3
  * Zones: telegram inbound, authorization, routing plans
4
4
  * Owns update extraction, authorization, execution planning, generation-fenced journal draining, and the public update-handler registry
5
5
  */
6
- import { type TelegramTarget } from "./target.ts";
7
- import type { TelegramBusEnvelope, TelegramBusFollowerView, TelegramBusForwardOwnership, TelegramBusForeignUpdateSettlement, TelegramProcessLiveness } from "./bus.ts";
8
- import type { TelegramMessageOwnershipStore } from "./ownership.ts";
9
- import { TELEGRAM_UPDATE_JOURNAL_VERSION, TELEGRAM_UPDATE_JOURNAL_EXCLUSION_VERSION, TELEGRAM_UPDATE_JOURNAL_CUSTODY_VERSION, type TelegramUpdateJournalEntryDigest, type TelegramUpdateJournalSourceCompletion, type TelegramUpdateJournalQueuedCompletion, type TelegramUpdateJournalQueuedReceiptEvidence, type TelegramInputJournalReceipt, type TelegramInputJournalSourceReference, type TelegramInputJournalStore, type TelegramJournaledUpdate, type TelegramUpdateJournalDeadQueueOwnerRecoveryResult, type TelegramUpdateJournalAppendResult, type TelegramUpdateJournalInputClaim, type TelegramUpdateJournalOperatorDispositionInput, type TelegramUpdateJournalOperatorDispositionResult, type TelegramUpdateJournalPendingAbandonmentInput, type TelegramUpdateJournalPendingAbandonmentResult, type TelegramUpdateJournalPendingRetentionEvidence, type TelegramUpdateJournalEntry, type TelegramUpdateJournalRoutingInput, type TelegramRoutingInputJournal, type TelegramUpdateJournalQueueDiscardResult, type TelegramUpdateJournalQueueHandoffAcceptResult, type TelegramUpdateJournalQueueHandoffCancelResult, type TelegramUpdateJournalQueueHandoffInput, type TelegramUpdateJournalQueueHandoffOfferResult, type TelegramUpdateJournalQueueOwner, type TelegramUpdateJournalQueueOwnerIdentity } from "./journal.ts";
10
- import { type PendingTelegramControlItem, type TelegramControlQueueHandoffPayload, type TelegramQueueAdmissionReceipt, type TelegramQueueHandoffPayload, type TelegramQueueHandoffStageResult, type TelegramQueueReactionDisposition, type TelegramQueueHandoffStagingRuntime, type TelegramQueueItem } from "./queue.ts";
6
+ import type { TelegramBusEnvelope, TelegramBusFollowerView, TelegramBusForeignUpdateSettlement, TelegramBusFollowerQueueHandoffOffer, TelegramBusForwardOwnership, TelegramBusLeaderQueueHandoffOffer } from "./bus.ts";
11
7
  import { type TelegramAuthorizationState, type TelegramUserPairingRuntimeDeps } from "./config.ts";
8
+ import { TELEGRAM_UPDATE_JOURNAL_CUSTODY_VERSION, TELEGRAM_UPDATE_JOURNAL_EXCLUSION_VERSION, TELEGRAM_UPDATE_JOURNAL_VERSION, type TelegramInputJournalReceipt, type TelegramInputJournalSourceReference, type TelegramInputJournalStore, type TelegramJournaledUpdate, type TelegramRoutingInputExpiryResult, type TelegramRoutingInputJournal, type TelegramUpdateJournalAppendResult, type TelegramUpdateJournalDeadQueueOwnerRecoveryResult, type TelegramUpdateJournalEntry, type TelegramUpdateJournalEntryDigest, type TelegramUpdateJournalInputClaim, type TelegramUpdateJournalOperatorDispositionInput, type TelegramUpdateJournalOperatorDispositionResult, type TelegramUpdateJournalPendingAbandonmentInput, type TelegramUpdateJournalPendingAbandonmentResult, type TelegramUpdateJournalPendingRetentionEvidence, type TelegramUpdateJournalQueueDiscardResult, type TelegramUpdateJournalQueueHandoffAcceptResult, type TelegramUpdateJournalQueueHandoffCancelResult, type TelegramUpdateJournalQueueHandoffInput, type TelegramUpdateJournalQueueHandoffOfferResult, type TelegramUpdateJournalQueueOwner, type TelegramUpdateJournalQueueOwnerIdentity, type TelegramUpdateJournalQueuedCompletion, type TelegramUpdateJournalQueuedReceiptEvidence, type TelegramUpdateJournalRoutingChooser, type TelegramUpdateJournalRoutingInput, type TelegramUpdateJournalSourceCompletion } from "./journal.ts";
9
+ import type { TelegramMessageOwnershipStore } from "./ownership.ts";
10
+ import type { TelegramProcessLiveness } from "./process-identity.ts";
11
+ import { type PendingTelegramControlItem, type TelegramControlQueueHandoffPayload, type TelegramQueueAdmissionReceipt, type TelegramQueueHandoffPayload, type TelegramQueueHandoffStageResult, type TelegramQueueHandoffStagingRuntime, type TelegramQueueItem, type TelegramQueueReactionDisposition } from "./queue.ts";
12
+ import { type TelegramTarget } from "./target.ts";
12
13
  export interface TelegramReactionTypeEmoji {
13
14
  type: "emoji";
14
15
  emoji: string;
@@ -68,7 +69,6 @@ export interface TelegramUpdateDeletion {
68
69
  }
69
70
  export declare function normalizeTelegramReactionEmoji(emoji: string): string;
70
71
  export declare function collectTelegramReactionEmojis(reactions: TelegramReactionType[]): Set<string>;
71
- export declare function extractDeletedTelegramMessageIds(update: TelegramUpdateDeletion): number[];
72
72
  export interface TelegramUser {
73
73
  id: number;
74
74
  is_bot: boolean;
@@ -189,6 +189,8 @@ export interface TelegramHeldSourcePreparation<TContext> {
189
189
  /** Exact prepared worker owner, context, key and authority; the consumer adds its own domain fences. */
190
190
  isCurrent: () => boolean;
191
191
  signal: AbortSignal;
192
+ /** Chooser-clock sources that must survive cold spending until their fixed expiry. */
193
+ routingSourceIds?: readonly number[];
192
194
  }
193
195
  export interface TelegramDeferredAbandonmentRecoveryPage {
194
196
  sources: {
@@ -205,13 +207,31 @@ export interface TelegramDeferredSourceEvidence extends TelegramUpdateJournalEnt
205
207
  /** Supplied only after caller-owned acceptance publication; requires a durable removal ACK. */
206
208
  completionSha256?: string;
207
209
  }
210
+ /** Fresh source-owner projection; the payload is copied from the retained journal, never a routed carrier. */
211
+ export interface TelegramDeferredSourceSnapshot {
212
+ source: TelegramDeferredSourceEvidence;
213
+ update: TelegramJournaledUpdate;
214
+ }
215
+ /** Warm exact-removal ACK plus its issuing worker lifetime; never persisted or sent over IPC. */
216
+ interface TelegramDeferredSourceCompletion {
217
+ source: TelegramDeferredSourceEvidence;
218
+ isCurrent(): boolean;
219
+ }
208
220
  interface TelegramUpdateAdmissionBinding {
209
221
  sourceUpdateId: number;
210
222
  report: (outcome: TelegramUpdateAdmissionOutcome) => void;
211
223
  abandon?: (authority: TelegramDeferredUpdateAbandonmentAuthority) => TelegramUpdateJournalPendingAbandonmentResult | undefined;
212
- armRoutingInput?: (operatorUserId: number, sourceUpdateIds: readonly number[]) => TelegramUpdateJournalRoutingInput | undefined;
224
+ armRoutingInput?: (operatorUserId: number, sourceUpdateIds: readonly number[], chooser?: TelegramUpdateJournalRoutingChooser) => TelegramUpdateJournalRoutingInput | undefined;
225
+ /** The source's saved routing clock, including where its chooser was published. */
226
+ getRoutingInput?: () => TelegramUpdateJournalRoutingInput | undefined;
213
227
  acquireRouting?: (select?: boolean, sourceUpdateIds?: readonly number[]) => () => void;
214
228
  inspectSource?: () => TelegramDeferredSourceEvidence | undefined;
229
+ inspectSourceSnapshot?: () => TelegramDeferredSourceSnapshot | undefined;
230
+ inspectCompletion?: () => TelegramDeferredSourceEvidence | undefined;
231
+ isSourceUnsettled?: () => boolean;
232
+ prepareLiveInput?: (sourceUpdateIds: readonly number[], isCurrent: () => boolean) => TelegramLiveDeferredInputPreparation | undefined;
233
+ prepareQueueAdmission?: () => TelegramDeferredQueueAdmissionPreparation | undefined;
234
+ prepareSourceCompletion?: () => Pick<TelegramDeferredSourceCompletionPreparation, "source" | "isCurrent"> | undefined;
215
235
  supportsAbandonment?: (journalBindingKey: string) => boolean;
216
236
  inspectAbandoning?: (request: TelegramDeferredAbandonmentRecoveryRequest) => TelegramDeferredAbandonmentRecoveryPage | undefined;
217
237
  inspectHistorical?: (request: TelegramDeferredAbandonmentRecoveryRequest) => TelegramDeferredAbandonmentRecoveryPage | undefined;
@@ -221,10 +241,11 @@ interface TelegramUpdateAdmissionBinding {
221
241
  export type TelegramQueueAdmissionReceiptLike = TelegramQueueAdmissionReceipt;
222
242
  export declare function bindTelegramUpdateAdmissionSource<TUpdate extends TelegramUpdateFlow & {
223
243
  update_id: number;
224
- }>(update: TUpdate, report: TelegramUpdateAdmissionBinding["report"], controls?: Pick<TelegramUpdateAdmissionBinding, "abandon" | "armRoutingInput" | "acquireRouting" | "inspectSource" | "supportsAbandonment" | "inspectAbandoning" | "inspectHistorical" | "isHistorical" | "isHistoricalReviewHeld">): TUpdate;
244
+ }>(update: TUpdate, report: TelegramUpdateAdmissionBinding["report"], controls?: Pick<TelegramUpdateAdmissionBinding, "abandon" | "armRoutingInput" | "getRoutingInput" | "acquireRouting" | "inspectSource" | "inspectSourceSnapshot" | "inspectCompletion" | "isSourceUnsettled" | "prepareLiveInput" | "prepareQueueAdmission" | "prepareSourceCompletion" | "supportsAbandonment" | "inspectAbandoning" | "inspectHistorical" | "isHistorical" | "isHistoricalReviewHeld">): TUpdate;
225
245
  /**
226
246
  * Conservative read-only census: any retained entry naming this Thread, in any nested Telegram object or state,
227
- * is unresolved custody. It cannot see updates still in transit before journal append.
247
+ * is unresolved custody, except a lone button tap, which carries no input (the in-flight Cancel itself).
248
+ * It cannot see updates still in transit before journal append.
228
249
  */
229
250
  export declare function collectTelegramJournalThreadUpdateIds(entries: readonly {
230
251
  updateId: number;
@@ -236,6 +257,12 @@ export declare function collectTelegramJournalThreadUpdateIds(entries: readonly
236
257
  export declare function collectTelegramAdmissionSourceUpdateIds(values: readonly unknown[]): number[];
237
258
  /** Observe the original journal entry, never the mutable routed carrier, through current worker authority. */
238
259
  export declare function inspectTelegramDeferredSource(value: unknown): TelegramDeferredSourceEvidence | undefined;
260
+ /** Read an exact current original for peer preparation without another payload authority. */
261
+ export declare function inspectTelegramDeferredSourceSnapshot(value: unknown): TelegramDeferredSourceSnapshot | undefined;
262
+ /** Exact warm removal ACK only; reporting, source absence and a replaced worker cannot supply it. */
263
+ export declare function inspectTelegramDeferredSourceCompletion(value: unknown): TelegramDeferredSourceEvidence | undefined;
264
+ /** Reuse only live bound deferred originals; raw IDs or cold/adopted input cannot mint this carrier. */
265
+ export declare function prepareTelegramLiveDeferredInput(values: readonly unknown[], isCurrent: () => boolean): TelegramLiveDeferredInputPreparation | undefined;
239
266
  /** A route-owned pre-disposition acceptance publisher; wraps only this carrier, never the shared worker binding. */
240
267
  export declare function bindTelegramUpdateCompletionAcceptance<TValue>(value: TValue, publish: () => TelegramDeferredSourceEvidence): TValue;
241
268
  /** Report source completion; true means reported, not a durable settlement acknowledgement. */
@@ -253,9 +280,15 @@ export declare function isTelegramHistoricalInput(value: unknown, matchesOrigina
253
280
  /** Routing's last-boundary hold when ownership changed after early classification. */
254
281
  export declare function reportTelegramHistoricalRoutingReview(value: unknown): boolean;
255
282
  /** Arm only a positively published chooser; the journal owns the immutable hour deadline. */
256
- export declare function armTelegramRoutingInputs(values: readonly unknown[], operatorUserId: number): TelegramUpdateJournalRoutingInput | undefined;
283
+ export declare function armTelegramRoutingInputs(values: readonly unknown[], operatorUserId: number, chooser?: TelegramUpdateJournalRoutingChooser): TelegramUpdateJournalRoutingInput | undefined;
284
+ /** A routed carrier's saved routing clock; a revived chooser reuses its recorded message. */
285
+ export declare function getTelegramUpdateRoutingInput(value: unknown): TelegramUpdateJournalRoutingInput | undefined;
257
286
  /** Reserve source execution; an actual choice must also freeze its durable TTL before any effect. */
258
287
  export declare function acquireTelegramUpdateRouting(value: unknown, select?: boolean, sourceUpdateIds?: readonly number[]): () => void;
288
+ /** Capture existing warm completion authority; only explicit reporting may dispose this exact original. */
289
+ export declare function prepareTelegramDeferredSourceCompletion(value: unknown): TelegramDeferredSourceCompletionPreparation | undefined;
290
+ /** Read-only warm owner availability; no source freeze, admission, report or receipt reconstruction. */
291
+ export declare function prepareTelegramDeferredQueueAdmission(value: unknown): TelegramDeferredQueueAdmissionPreparation | undefined;
259
292
  export declare function reportTelegramQueueAdmission(values: readonly unknown[], receipts: readonly TelegramQueueAdmissionReceiptLike[]): boolean;
260
293
  export type TelegramUpdateFlowAction<TReactionUpdate extends TelegramMessageReactionUpdated = TelegramMessageReactionUpdated, TCallbackQuery extends TelegramCallbackQuery = TelegramCallbackQuery, TMessage extends TelegramUpdateMessage = TelegramUpdateMessage, TGuestMessage extends TelegramGuestMessage = TelegramGuestMessage> = {
261
294
  kind: "ignore";
@@ -341,18 +374,13 @@ interface TelegramUnauthorizedReplyOptions {
341
374
  threadId?: number;
342
375
  };
343
376
  }
344
- export interface TelegramUpdateRuntimeDeps<TContext = unknown, TReactionUpdate extends TelegramMessageReactionUpdated = TelegramMessageReactionUpdated, TCallbackQuery extends TelegramCallbackQuery = TelegramCallbackQuery, TMessage extends TelegramUpdateMessage = TelegramUpdateMessage> {
345
- ctx: TContext;
346
- execution?: TelegramUpdateExecutionFence;
377
+ /** Ownership lookups and authorized-update handlers shared by the per-update runtime and its controller. */
378
+ export interface TelegramUpdateHandlerPorts<TContext, TCallbackQuery extends TelegramCallbackQuery, TMessage extends TelegramUpdateMessage> {
347
379
  getCurrentInstanceId?: () => string | undefined;
348
380
  getMessageOwnership?: TelegramMessageOwnershipLookup;
349
381
  getTargetOwnership?: TelegramTargetOwnershipLookup;
350
382
  recordMessageOwnership?: TelegramMessageOwnershipRecorder;
351
- foreignOwnedUpdateForwarder?: TelegramForeignOwnedUpdateForwarder<TContext, TReactionUpdate, TCallbackQuery, TMessage>;
352
383
  removePendingMediaGroupMessages: (messageIds: number[]) => void;
353
- removeQueuedTelegramTurnsByMessageIds: (messageIds: number[], ctx: TContext) => number;
354
- handleAuthorizedTelegramReactionUpdate: (reactionUpdate: TReactionUpdate, ctx: TContext) => Promise<void>;
355
- handleTelegramTopicLifecycleUpdate?: (lifecycle: TelegramTopicLifecycleUpdate<TMessage>, ctx: TContext) => Promise<void> | void;
356
384
  pairTelegramUserIfNeeded: (userId: number, ctx: TContext, assertExecutionCurrent?: () => void) => Promise<boolean>;
357
385
  answerCallbackQuery: (callbackQueryId: string, text?: string) => Promise<void>;
358
386
  answerGuestQuery: (guestQueryId: string, text?: string, options?: Pick<TelegramUnauthorizedReplyOptions, "parseMode">) => Promise<void>;
@@ -363,19 +391,22 @@ export interface TelegramUpdateRuntimeDeps<TContext = unknown, TReactionUpdate e
363
391
  handleAuthorizedTelegramGuestMessage?: (guestMessage: TelegramGuestMessage & {
364
392
  from: TelegramUser;
365
393
  }, ctx: TContext) => Promise<void>;
394
+ handleTelegramTopicLifecycleUpdate?: (lifecycle: TelegramTopicLifecycleUpdate<TMessage>, ctx: TContext) => Promise<void> | void;
366
395
  /** Called when the owner writes in an unbound thread no live instance owns. */
367
396
  handleUnboundTelegramTopicMessage?: (message: TMessage & {
368
397
  from: TelegramUser;
369
398
  }, ctx: TContext) => Promise<void>;
370
399
  }
371
- export interface TelegramUpdateRuntimeControllerDeps<TContext = unknown, TCallbackQuery extends TelegramCallbackQuery = TelegramCallbackQuery, TMessage extends TelegramUpdateMessage = TelegramUpdateMessage> {
400
+ export interface TelegramUpdateRuntimeDeps<TContext = unknown, TReactionUpdate extends TelegramMessageReactionUpdated = TelegramMessageReactionUpdated, TCallbackQuery extends TelegramCallbackQuery = TelegramCallbackQuery, TMessage extends TelegramUpdateMessage = TelegramUpdateMessage> extends TelegramUpdateHandlerPorts<TContext, TCallbackQuery, TMessage> {
401
+ ctx: TContext;
402
+ execution?: TelegramUpdateExecutionFence;
403
+ foreignOwnedUpdateForwarder?: TelegramForeignOwnedUpdateForwarder<TContext, TReactionUpdate, TCallbackQuery, TMessage>;
404
+ removeQueuedTelegramTurnsByMessageIds: (messageIds: number[], ctx: TContext) => number;
405
+ handleAuthorizedTelegramReactionUpdate: (reactionUpdate: TReactionUpdate, ctx: TContext) => Promise<void>;
406
+ }
407
+ export interface TelegramUpdateRuntimeControllerDeps<TContext = unknown, TCallbackQuery extends TelegramCallbackQuery = TelegramCallbackQuery, TMessage extends TelegramUpdateMessage = TelegramUpdateMessage> extends TelegramUpdateHandlerPorts<TContext, TCallbackQuery, TMessage> {
372
408
  getAllowedUserId: () => number | undefined;
373
- getCurrentInstanceId?: () => string | undefined;
374
- getMessageOwnership?: TelegramMessageOwnershipLookup;
375
- getTargetOwnership?: TelegramTargetOwnershipLookup;
376
- recordMessageOwnership?: TelegramMessageOwnershipRecorder;
377
409
  foreignOwnedUpdateForwarder?: TelegramForeignOwnedUpdateForwarder<TContext, TelegramMessageReactionUpdated, TCallbackQuery, TMessage>;
378
- removePendingMediaGroupMessages: (messageIds: number[]) => void;
379
410
  flushPendingMediaGroupMessage?: (messageId: number) => Promise<boolean>;
380
411
  flushPendingTextGroupMessage?: (messageId: number) => Promise<boolean>;
381
412
  removeQueuedTelegramTurnsByMessageIds: (messageIds: number[], ctx: TContext, scope?: {
@@ -386,21 +417,6 @@ export interface TelegramUpdateRuntimeControllerDeps<TContext = unknown, TCallba
386
417
  chatId?: number;
387
418
  threadId?: number;
388
419
  }) => boolean;
389
- pairTelegramUserIfNeeded: (userId: number, ctx: TContext, assertExecutionCurrent?: () => void) => Promise<boolean>;
390
- answerCallbackQuery: (callbackQueryId: string, text?: string) => Promise<void>;
391
- answerGuestQuery: (guestQueryId: string, text?: string, options?: Pick<TelegramUnauthorizedReplyOptions, "parseMode">) => Promise<void>;
392
- handleAuthorizedTelegramCallbackQuery: (query: TCallbackQuery, ctx: TContext) => Promise<void>;
393
- sendTextReply: (chatId: number, replyToMessageId: number, text: string, options?: TelegramUnauthorizedReplyOptions) => Promise<number | undefined>;
394
- handleAuthorizedTelegramMessage: (message: TMessage, ctx: TContext) => Promise<void>;
395
- handleAuthorizedTelegramEditedMessage: (message: TMessage, ctx: TContext) => unknown;
396
- handleAuthorizedTelegramGuestMessage?: (guestMessage: TelegramGuestMessage & {
397
- from: TelegramUser;
398
- }, ctx: TContext) => Promise<void>;
399
- handleTelegramTopicLifecycleUpdate?: (lifecycle: TelegramTopicLifecycleUpdate<TMessage>, ctx: TContext) => Promise<void> | void;
400
- /** Called when the owner writes in an unbound thread no live instance owns. */
401
- handleUnboundTelegramTopicMessage?: (message: TMessage & {
402
- from: TelegramUser;
403
- }, ctx: TContext) => Promise<void>;
404
420
  }
405
421
  export interface TelegramUpdateRuntimeController<TContext = unknown, TUpdate extends TelegramUpdateFlow = TelegramUpdateFlow> {
406
422
  handleAuthorizedReactionUpdate: (reactionUpdate: NonNullable<TUpdate["message_reaction"]>, ctx: TContext) => Promise<void>;
@@ -446,6 +462,8 @@ export interface TelegramUpdateWorkerStateSnapshot {
446
462
  abandoningClaimCount?: number;
447
463
  /** Historical sources held before routing, not evidence of prior non-delivery. */
448
464
  historicalClaimCount?: number;
465
+ /** Fresh recipient inputs reserved before append; not executable prompt-queue work. */
466
+ preparedInputCount?: number;
449
467
  queuedClaimCount: number;
450
468
  foreignQueuedCount: number;
451
469
  foreignQueuedOwner?: TelegramUpdateJournalQueueOwner;
@@ -504,7 +522,7 @@ export interface TelegramRoutingInputExpirySource {
504
522
  original: TelegramUpdateJournalEntry;
505
523
  journalBindingKey: string;
506
524
  isCurrent(): boolean;
507
- expire(): TelegramUpdateJournalPendingAbandonmentResult | undefined;
525
+ expire(): TelegramRoutingInputExpiryResult | undefined;
508
526
  }
509
527
  export interface TelegramUpdateWorkerJournalPort {
510
528
  routingInputs?: TelegramRoutingInputJournal;
@@ -558,7 +576,7 @@ export interface TelegramUpdateWorkerJournalPort {
558
576
  removedUpdateIds: readonly number[];
559
577
  };
560
578
  /** No ID-only fallback is allowed for a guarded completion report. */
561
- removeCompletedExact?: (updateIds: readonly number[], expectedSources: readonly TelegramUpdateJournalEntryDigest[], completions?: readonly TelegramUpdateJournalSourceCompletion[]) => {
579
+ removeCompletedExact?: (updateIds: readonly number[], expectedSources: readonly TelegramUpdateJournalEntryDigest[], completions?: readonly TelegramUpdateJournalSourceCompletion[], isCurrent?: () => boolean) => {
562
580
  removedUpdateIds: readonly number[];
563
581
  sourceCompletions?: readonly TelegramUpdateJournalSourceCompletion[];
564
582
  };
@@ -579,13 +597,21 @@ export interface TelegramUpdateExecutionFailureClassification {
579
597
  export interface TelegramUpdateWorkerRuntimeDeps<TContext> {
580
598
  journal: TelegramUpdateWorkerJournalPort;
581
599
  executeUpdate: (update: TelegramJournaledUpdate, ctx: TContext, signal: AbortSignal) => Promise<TelegramUpdateAdmissionOutcome> | TelegramUpdateAdmissionOutcome;
600
+ /** Native source-only binding, installed by the admission-worker assembly rather than ordinary dispatch. */
601
+ admitPreparedLiveInput?: (update: TelegramJournaledUpdate, ctx: TContext, signal: AbortSignal) => Promise<{
602
+ outcome: TelegramUpdateAdmissionOutcome;
603
+ carrier: unknown;
604
+ }>;
582
605
  executeCustodiedUpdate?: (update: TelegramJournaledUpdate, ctx: TContext, signal: AbortSignal) => Promise<TelegramCustodiedExecutionResult>;
583
606
  hasAuthority: (ctx: TContext) => boolean;
584
607
  getJournalBindingKey?: () => string | undefined;
585
608
  getRecipientBindingKey?: () => string | undefined;
586
- /** True selects legacy historical review/spending; retain protects unsupported originals without disposition authority. */
587
- shouldReviewHistoricalInput?: (entry: TelegramUpdateJournalEntry, ctx: TContext, signal: AbortSignal) => boolean | "retain" | Promise<boolean | "retain">;
588
- /** New-world restart: spend previous-process routing inputs (classified or armed) without delivery, copy or completion observers. Interrupted private abandonment keeps its own exact recovery. */
609
+ /**
610
+ * True selects legacy historical review/spending; retain protects unsupported originals without disposition
611
+ * authority; revive re-admits a still-waiting chooser source as this generation's live input.
612
+ */
613
+ shouldReviewHistoricalInput?: (entry: TelegramUpdateJournalEntry, ctx: TContext, signal: AbortSignal) => TelegramHistoricalReviewVerdict | Promise<TelegramHistoricalReviewVerdict>;
614
+ /** New-world restart: spend unclocked classified routing input without delivery, copy or completion. Chooser clocks wait for expiry; interrupted private abandonment keeps exact recovery. */
589
615
  spendHistoricalInput?: boolean;
590
616
  /** Holds protected live or retry sources before execution; never cancels or disposes them. */
591
617
  shouldHoldPendingInput?: (entry: TelegramUpdateJournalEntry, ctx: TContext, signal: AbortSignal) => boolean | Promise<boolean>;
@@ -613,19 +639,92 @@ export interface TelegramUpdateWorkerRuntimeDeps<TContext> {
613
639
  recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
614
640
  }
615
641
  export type TelegramQueueReceiptCompletionReason = "prompt-handoff" | "control-settlement" | "discard";
642
+ /** Read-only singleton hold projection; only the exact warm post-release admission carrier may supply completion. */
643
+ export interface TelegramLiveSourceCompletionReadiness {
644
+ readonly snapshot: TelegramDeferredSourceSnapshot;
645
+ /** Captured issuing owner/ports only; not a source disposition or canonical-release grant. */
646
+ isCurrent(): boolean;
647
+ bindCarrier(value: unknown): TelegramDeferredSourceCompletionPreparation | undefined;
648
+ }
649
+ /** Process-local gate for fresh recipient input; never durable replay/custody or a binding grant. */
650
+ export interface TelegramLiveInputPreparation {
651
+ readonly sourceUpdateIds: readonly number[];
652
+ /** Authority-only observation: no nested journal transaction under a Workspace snapshot. */
653
+ isCurrent(): boolean;
654
+ /** Same captured worker/source lifetime, including a finished warm preparation. */
655
+ isOwnerCurrent(): boolean;
656
+ confirmSaved(): boolean;
657
+ /** Read/copy completion-owner availability after save, without claiming/admitting/dispatching the held input. */
658
+ prepareSourceCompletion?(): TelegramLiveSourceCompletionReadiness | undefined;
659
+ /** Captures one same-source status continuation without activating future recipient authority. */
660
+ prepareStatusConsumption?(input: TelegramLiveStatusConsumption): boolean;
661
+ /** Native owner availability before recipient append; not admission or future target activation. */
662
+ canPrepareStatusConsumption?(): boolean;
663
+ release(canRelease: () => boolean): boolean;
664
+ /** Ends a failed pre-append attempt only when no selected input was saved. */
665
+ cancelEmpty(): boolean;
666
+ /** One fenced removal of this never-dispatched recipient copy; unknown issuance cannot be retried. */
667
+ discardSaved(canDiscard: () => boolean): "discarded" | "protected" | "unknown";
668
+ }
669
+ /** Routing owns continuation or positively released peer transfer; preparation never appends or reexecutes originals. */
670
+ export interface TelegramLiveDeferredInputPreparation extends Pick<TelegramLiveInputPreparation, "sourceUpdateIds" | "isCurrent" | "isOwnerCurrent" | "confirmSaved"> {
671
+ beginRelease(canRelease: () => boolean): boolean;
672
+ /** One exact donor-group removal after routing confirms peer release; unknown issuance never retries. */
673
+ settleTransferred(canSettle: () => boolean): "settled" | "protected" | "unknown";
674
+ cancel(): boolean;
675
+ }
676
+ export interface TelegramDeferredSourceCompletionPreparation {
677
+ readonly source: TelegramDeferredSourceEvidence;
678
+ /** Issuer lifetime remains observable after reporting/removal; never a settled/source-absence inference. */
679
+ isCurrent(): boolean;
680
+ /** One exact report after required command semantics; true is report acceptance, not a removal ACK. */
681
+ reportCompleted(): boolean;
682
+ /** Existing warm worker ACK only, read-only and without journal I/O or another report/removal. */
683
+ inspectCompletion(): TelegramDeferredSourceEvidence | undefined;
684
+ }
685
+ export interface TelegramDeferredQueueAdmissionPreparation {
686
+ /** Worker/session/journal/acquiring-owner lifetime, independent of the source's later queued report. */
687
+ isCurrent(): boolean;
688
+ /** Only the existing warm committed receipt owner can certify the same original; absence never permits replay. */
689
+ inspectReceipt(receipt: TelegramQueueAdmissionReceiptLike): {
690
+ source: TelegramDeferredSourceEvidence;
691
+ receipt: TelegramUpdateJournalQueuedCompletion;
692
+ } | undefined;
693
+ /** Read-only original/queued-owner CAS scope for the existing pre-publication boundary; never readiness or disposal. */
694
+ prepareCompletionScope(receipt: TelegramQueueAdmissionReceiptLike, queueOwner: TelegramUpdateJournalQueueOwner, completionSha256: string): TelegramQueueSourceCompletion | undefined;
695
+ /** Exact previously observed receipt object's native whole-removal ACK; never admission, absence or another disposal. */
696
+ inspectCompletion(receipt: TelegramQueueAdmissionReceiptLike): TelegramDeferredSourceEvidence | undefined;
697
+ }
616
698
  export interface TelegramUpdateWorkerRuntime<TContext> {
617
699
  start: (ctx: TContext) => void;
700
+ /** Reserve absent IDs before recipient append; existing leader deferred sources use their original carrier. */
701
+ prepareLiveInput?: (ctx: TContext, sourceUpdateIds: readonly number[], isCurrent?: () => boolean) => TelegramLiveInputPreparation | undefined;
702
+ prepareDeferredLiveInput?: (input: {
703
+ updateId: number;
704
+ sourceUpdateIds: readonly number[];
705
+ signal: AbortSignal;
706
+ isCurrent(): boolean;
707
+ }) => TelegramLiveDeferredInputPreparation | undefined;
708
+ prepareDeferredQueueAdmission?: (input: {
709
+ updateId: number;
710
+ signal: AbortSignal;
711
+ }) => TelegramDeferredQueueAdmissionPreparation | undefined;
712
+ prepareDeferredSourceCompletion?: (input: {
713
+ updateId: number;
714
+ signal: AbortSignal;
715
+ }) => Pick<TelegramDeferredSourceCompletionPreparation, "source" | "isCurrent"> | undefined;
618
716
  signal: () => void;
619
717
  settleDeferred: (input: {
620
718
  updateId: number;
621
719
  outcome: TelegramUpdateAdmissionOutcome;
622
720
  signal: AbortSignal;
623
- }) => void;
721
+ }) => void | TelegramDeferredSourceCompletion | Promise<void | TelegramDeferredSourceCompletion>;
624
722
  armRoutingInput?: (input: {
625
723
  updateId: number;
626
724
  signal: AbortSignal;
627
725
  operatorUserId: number;
628
726
  sourceUpdateIds: readonly number[];
727
+ chooser?: TelegramUpdateJournalRoutingChooser;
629
728
  }) => TelegramUpdateJournalRoutingInput | undefined;
630
729
  selectRoutingInput?: (input: {
631
730
  updateId: number;
@@ -633,6 +732,14 @@ export interface TelegramUpdateWorkerRuntime<TContext> {
633
732
  operatorUserId: number;
634
733
  sourceUpdateIds: readonly number[];
635
734
  }) => boolean;
735
+ isRoutingInputCurrent?: (input: {
736
+ updateId: number;
737
+ signal: AbortSignal;
738
+ }) => boolean;
739
+ getRoutingInput?: (input: {
740
+ updateId: number;
741
+ signal: AbortSignal;
742
+ }) => TelegramUpdateJournalRoutingInput | undefined;
636
743
  supportsDeferredAbandonment?: (input: {
637
744
  updateId: number;
638
745
  signal: AbortSignal;
@@ -648,6 +755,10 @@ export interface TelegramUpdateWorkerRuntime<TContext> {
648
755
  updateId: number;
649
756
  signal: AbortSignal;
650
757
  }) => TelegramDeferredSourceEvidence | undefined;
758
+ inspectDeferredSourceSnapshot?: (input: {
759
+ updateId: number;
760
+ signal: AbortSignal;
761
+ }) => TelegramDeferredSourceSnapshot | undefined;
651
762
  isHistoricalSource?: (input: {
652
763
  updateId: number;
653
764
  signal: AbortSignal;
@@ -677,6 +788,15 @@ export interface TelegramUpdateWorkerRuntime<TContext> {
677
788
  waitForDrain: () => Promise<void>;
678
789
  getState: () => TelegramUpdateWorkerStateSnapshot;
679
790
  }
791
+ export interface TelegramLiveStatusConsumption {
792
+ readonly source: TelegramDeferredSourceEvidence;
793
+ assertCurrent(): void;
794
+ bindCarrier(value: unknown): boolean;
795
+ execute(): Promise<boolean>;
796
+ }
797
+ export type TelegramHistoricalReviewVerdict = boolean | "retain" | "revive";
798
+ /** A saved chooser clock that proves an untouched, unexpired choice whose chooser message can be revived. */
799
+ export declare function isRevivableTelegramRoutingInput(entry: Pick<TelegramUpdateJournalEntry, "state" | "routingInput">, nowMs: number): boolean;
680
800
  export declare function createTelegramUpdateWorkerRuntime<TContext>(deps: TelegramUpdateWorkerRuntimeDeps<TContext>): TelegramUpdateWorkerRuntime<TContext>;
681
801
  /**
682
802
  * Verdict returned by a public Telegram update handler.
@@ -722,14 +842,6 @@ export interface TelegramUpdateHandlerRegistry {
722
842
  * {@link registerTelegramUpdateHandler} instead.
723
843
  */
724
844
  export declare function getTelegramUpdateHandlerRegistry(): TelegramUpdateHandlerRegistry;
725
- export interface TelegramUpdateHandlerWrapDeps<TUpdate, TContext> {
726
- defaultHandle: (update: TUpdate, ctx: TContext) => Promise<void>;
727
- registry?: TelegramUpdateHandlerRegistry;
728
- }
729
- /**
730
- * Wrap a default polling `handleUpdate` with the public update handler registry.
731
- */
732
- export declare function createTelegramUpdateHandle<TUpdate, TContext>(deps: TelegramUpdateHandlerWrapDeps<TUpdate, TContext>): (update: TUpdate, ctx: TContext) => Promise<void>;
733
845
  export interface TelegramUpdateAdmissionHandleDeps<TUpdate extends TelegramUpdateFlow & {
734
846
  update_id: number;
735
847
  }, TContext> {
@@ -739,15 +851,21 @@ export interface TelegramUpdateAdmissionHandleDeps<TUpdate extends TelegramUpdat
739
851
  updateId: number;
740
852
  ctx: TContext;
741
853
  signal: AbortSignal;
742
- }) => void | Promise<void>;
854
+ }) => void | TelegramDeferredSourceCompletion | Promise<void | TelegramDeferredSourceCompletion>;
743
855
  onLateOutcomeError?: (error: unknown, updateId: number) => void;
744
856
  abandonDeferred?: TelegramUpdateWorkerRuntime<TContext>["abandonDeferred"];
745
857
  armRoutingInput?: TelegramUpdateWorkerRuntime<TContext>["armRoutingInput"];
746
858
  selectRoutingInput?: TelegramUpdateWorkerRuntime<TContext>["selectRoutingInput"];
859
+ isRoutingInputCurrent?: TelegramUpdateWorkerRuntime<TContext>["isRoutingInputCurrent"];
860
+ getRoutingInput?: TelegramUpdateWorkerRuntime<TContext>["getRoutingInput"];
747
861
  supportsDeferredAbandonment?: TelegramUpdateWorkerRuntime<TContext>["supportsDeferredAbandonment"];
748
862
  inspectAbandoning?: TelegramUpdateWorkerRuntime<TContext>["inspectAbandoning"];
749
863
  inspectHistorical?: TelegramUpdateWorkerRuntime<TContext>["inspectHistorical"];
750
864
  inspectDeferredSource?: TelegramUpdateWorkerRuntime<TContext>["inspectDeferredSource"];
865
+ inspectDeferredSourceSnapshot?: TelegramUpdateWorkerRuntime<TContext>["inspectDeferredSourceSnapshot"];
866
+ prepareDeferredLiveInput?: TelegramUpdateWorkerRuntime<TContext>["prepareDeferredLiveInput"];
867
+ prepareDeferredQueueAdmission?: TelegramUpdateWorkerRuntime<TContext>["prepareDeferredQueueAdmission"];
868
+ prepareDeferredSourceCompletion?: TelegramUpdateWorkerRuntime<TContext>["prepareDeferredSourceCompletion"];
751
869
  isHistoricalSource?: TelegramUpdateWorkerRuntime<TContext>["isHistoricalSource"];
752
870
  }
753
871
  export type TelegramCustodiedExecutionResult = {
@@ -1135,7 +1253,7 @@ export declare function executeTelegramCustodiedInput(input: {
1135
1253
  export declare function createTelegramUpdateAdmissionHandle<TUpdate extends TelegramUpdateFlow & {
1136
1254
  update_id: number;
1137
1255
  }, TContext>(deps: TelegramUpdateAdmissionHandleDeps<TUpdate, TContext>): (update: TUpdate, ctx: TContext, signal: AbortSignal) => Promise<TelegramUpdateAdmissionOutcome>;
1138
- export declare function createTelegramCustodiedUpdateAdmissionHandle<TUpdate extends TelegramJournaledUpdate & TelegramUpdateFlow, TContext>(deps: Omit<TelegramUpdateAdmissionHandleDeps<TUpdate, TContext>, "onLateOutcome" | "onLateOutcomeError" | "abandonDeferred" | "armRoutingInput" | "selectRoutingInput" | "supportsDeferredAbandonment" | "inspectAbandoning" | "inspectHistorical" | "inspectDeferredSource" | "isHistoricalSource"> & {
1256
+ export declare function createTelegramCustodiedUpdateAdmissionHandle<TUpdate extends TelegramJournaledUpdate & TelegramUpdateFlow, TContext>(deps: Omit<TelegramUpdateAdmissionHandleDeps<TUpdate, TContext>, "onLateOutcome" | "onLateOutcomeError" | "abandonDeferred" | "armRoutingInput" | "getRoutingInput" | "selectRoutingInput" | "isRoutingInputCurrent" | "supportsDeferredAbandonment" | "inspectAbandoning" | "inspectHistorical" | "inspectDeferredSource" | "inspectDeferredSourceSnapshot" | "prepareDeferredLiveInput" | "prepareDeferredQueueAdmission" | "prepareDeferredSourceCompletion" | "isHistoricalSource"> & {
1139
1257
  journal: TelegramCustodyExecutionJournal;
1140
1258
  recipientBindingKey: string;
1141
1259
  onLateOutcomeError(error: unknown, updateId: number): void;
@@ -1250,21 +1368,7 @@ export interface TelegramQueueHandoffReconcilerDeps<TContext> {
1250
1368
  handoffToken: string;
1251
1369
  payload: TelegramQueueHandoffPayload;
1252
1370
  }) => Promise<TelegramQueueHandoffStageResult>;
1253
- routeThroughLeader: (input: {
1254
- requestId: string;
1255
- auth?: string;
1256
- recipientInstanceId: string;
1257
- recipientRegistrationGeneration: string;
1258
- donorInstanceId: string;
1259
- donorProcessId: number;
1260
- donorProcessBirthId: string;
1261
- donorSessionGeneration: number;
1262
- donorAcquisitionId: string;
1263
- donorAcquiredAtMs: number;
1264
- handoffToken: string;
1265
- payload: TelegramQueueHandoffPayload;
1266
- sentAtMs: number;
1267
- }) => Promise<TelegramBusEnvelope>;
1371
+ routeThroughLeader: (input: TelegramBusLeaderQueueHandoffOffer) => Promise<TelegramBusEnvelope>;
1268
1372
  removeDonorItem: (receipt: TelegramQueueAdmissionReceipt, ctx: TContext) => boolean;
1269
1373
  recordFailure?: (error: unknown, details: Record<string, unknown>) => void;
1270
1374
  }
@@ -1274,9 +1378,9 @@ export interface TelegramQueueHandoffReconciliationRuntimeAssemblyDeps<TContext>
1274
1378
  isBusEnabled: () => boolean;
1275
1379
  canHandoffWithLeader?: () => boolean;
1276
1380
  listFollowers: () => readonly TelegramBusFollowerView[];
1277
- createRecipientJournalResolver: (profileKey: string, sessionId: string) => (() => {
1381
+ createRecipientJournalResolver: (profileKey: string, sessionId: string) => () => {
1278
1382
  recoveryKey: string;
1279
- } | undefined);
1383
+ } | undefined;
1280
1384
  queueStore: {
1281
1385
  getQueuedItems: () => TelegramQueueItem<TContext>[];
1282
1386
  setQueuedItems: (items: TelegramQueueItem<TContext>[]) => void;
@@ -1286,17 +1390,7 @@ export interface TelegramQueueHandoffReconciliationRuntimeAssemblyDeps<TContext>
1286
1390
  createRequestId: () => string;
1287
1391
  donorInstanceId: string;
1288
1392
  authSecret?: string;
1289
- stageThroughFollower: (input: {
1290
- recipientInstanceId: string;
1291
- recipientRegistrationGeneration: string;
1292
- donorProcessId: number;
1293
- donorProcessBirthId: string;
1294
- donorSessionGeneration: number;
1295
- donorAcquisitionId: string;
1296
- donorAcquiredAtMs: number;
1297
- handoffToken: string;
1298
- payload: TelegramQueueHandoffPayload;
1299
- }) => Promise<TelegramQueueHandoffStageResult>;
1393
+ stageThroughFollower: (input: TelegramBusFollowerQueueHandoffOffer) => Promise<TelegramQueueHandoffStageResult>;
1300
1394
  routeThroughLeader: TelegramQueueHandoffReconcilerDeps<TContext>["routeThroughLeader"];
1301
1395
  recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
1302
1396
  }
@@ -1354,6 +1448,8 @@ export interface TelegramUpdateAdmissionLifecycleRuntime<TContext> extends Teleg
1354
1448
  getForeignQueueOwnerLiveness: () => TelegramProcessLiveness | undefined;
1355
1449
  hasPendingQueueMutationForItem: (item: TelegramQueueMutationDependencyItem) => boolean;
1356
1450
  signal: () => void;
1451
+ /** Fresh recipient input only; the leader's existing deferred original keeps its original carrier. */
1452
+ prepareLiveInput?: TelegramUpdateWorkerRuntime<TContext>["prepareLiveInput"];
1357
1453
  getState: () => TelegramUpdateWorkerStateSnapshot | undefined;
1358
1454
  }
1359
1455
  export interface TelegramUpdateWorkerOwnerRuntime<TContext> {