@llblab/pi-kit 0.27.6 → 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 (182) hide show
  1. package/BACKLOG.md +2 -5
  2. package/CHANGELOG.md +5 -0
  3. package/README.md +2 -2
  4. package/node_modules/@llblab/pi-telegram/AGENTS.md +10 -8
  5. package/node_modules/@llblab/pi-telegram/BACKLOG.md +1 -9
  6. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +13 -0
  7. package/node_modules/@llblab/pi-telegram/LICENSE +21 -0
  8. package/node_modules/@llblab/pi-telegram/README.md +15 -5
  9. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.d.ts +1 -5
  10. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.js +5 -7
  11. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +5 -1
  12. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +6 -1
  13. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.js +4 -2
  14. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +54 -56
  15. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +206 -139
  16. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.d.ts +21 -2
  17. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.js +181 -25
  18. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.d.ts +4 -1
  19. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.js +28 -4
  20. package/node_modules/@llblab/pi-telegram/dist/lib/bus.d.ts +52 -56
  21. package/node_modules/@llblab/pi-telegram/dist/lib/bus.js +78 -246
  22. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.d.ts +1 -3
  23. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.js +23 -26
  24. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.d.ts +0 -5
  25. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.js +5 -5
  26. package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +0 -23
  27. package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +15 -15
  28. package/node_modules/@llblab/pi-telegram/dist/lib/config.d.ts +0 -17
  29. package/node_modules/@llblab/pi-telegram/dist/lib/config.js +12 -14
  30. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +0 -4
  31. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +2 -5
  32. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +255 -61
  33. package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.d.ts +0 -19
  34. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.d.ts +0 -2
  35. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.js +2 -2
  36. package/node_modules/@llblab/pi-telegram/dist/lib/journal.d.ts +177 -16
  37. package/node_modules/@llblab/pi-telegram/dist/lib/journal.js +1115 -249
  38. package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.d.ts +0 -2
  39. package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.js +2 -2
  40. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +1 -1
  41. package/node_modules/@llblab/pi-telegram/dist/lib/locks.d.ts +100 -12
  42. package/node_modules/@llblab/pi-telegram/dist/lib/locks.js +380 -14
  43. package/node_modules/@llblab/pi-telegram/dist/lib/logging.d.ts +30 -12
  44. package/node_modules/@llblab/pi-telegram/dist/lib/logging.js +129 -72
  45. package/node_modules/@llblab/pi-telegram/dist/lib/media.d.ts +28 -5
  46. package/node_modules/@llblab/pi-telegram/dist/lib/media.js +26 -8
  47. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.d.ts +0 -11
  48. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.js +8 -8
  49. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +0 -18
  50. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +18 -18
  51. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.d.ts +4 -4
  52. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.js +12 -7
  53. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.d.ts +1 -1
  54. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.js +1 -1
  55. package/node_modules/@llblab/pi-telegram/dist/lib/menu.d.ts +1 -0
  56. package/node_modules/@llblab/pi-telegram/dist/lib/menu.js +4 -3
  57. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.d.ts +0 -1
  58. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.js +1 -1
  59. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.js +1 -8
  60. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.d.ts +1 -6
  61. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.js +4 -21
  62. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.d.ts +0 -8
  63. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.js +5 -5
  64. package/node_modules/@llblab/pi-telegram/dist/lib/paths.d.ts +50 -7
  65. package/node_modules/@llblab/pi-telegram/dist/lib/paths.js +155 -17
  66. package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +1 -0
  67. package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +2 -1
  68. package/node_modules/@llblab/pi-telegram/dist/lib/polling.d.ts +0 -5
  69. package/node_modules/@llblab/pi-telegram/dist/lib/polling.js +5 -5
  70. package/node_modules/@llblab/pi-telegram/dist/lib/preview.d.ts +0 -3
  71. package/node_modules/@llblab/pi-telegram/dist/lib/preview.js +3 -3
  72. package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.d.ts +0 -1
  73. package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.js +1 -1
  74. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +3 -15
  75. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +69 -8
  76. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.d.ts +29 -9
  77. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.js +104 -33
  78. package/node_modules/@llblab/pi-telegram/dist/lib/replies.d.ts +0 -4
  79. package/node_modules/@llblab/pi-telegram/dist/lib/replies.js +1 -1
  80. package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +73 -8
  81. package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +2206 -307
  82. package/node_modules/@llblab/pi-telegram/dist/lib/sections.d.ts +0 -2
  83. package/node_modules/@llblab/pi-telegram/dist/lib/sections.js +1 -1
  84. package/node_modules/@llblab/pi-telegram/dist/lib/status.d.ts +44 -9
  85. package/node_modules/@llblab/pi-telegram/dist/lib/status.js +149 -27
  86. package/node_modules/@llblab/pi-telegram/dist/lib/sync.d.ts +0 -5
  87. package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +5 -4
  88. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.d.ts +11 -3
  89. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +34 -23
  90. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.d.ts +1 -0
  91. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.js +18 -21
  92. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.d.ts +32 -5
  93. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.js +191 -7
  94. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.d.ts +2 -0
  95. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.js +1 -1
  96. package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +291 -59
  97. package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +1647 -369
  98. package/node_modules/@llblab/pi-telegram/dist/lib/turns.d.ts +0 -1
  99. package/node_modules/@llblab/pi-telegram/dist/lib/turns.js +1 -1
  100. package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +184 -28
  101. package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +1032 -114
  102. package/node_modules/@llblab/pi-telegram/dist/lib/wire.d.ts +12 -0
  103. package/node_modules/@llblab/pi-telegram/dist/lib/wire.js +21 -0
  104. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.d.ts +25 -17
  105. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.js +95 -20
  106. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-identity.d.ts +20 -0
  107. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-identity.js +103 -0
  108. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +43 -8
  109. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +148 -52
  110. package/node_modules/@llblab/pi-telegram/dist/package.json +6 -6
  111. package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/SKILL.md +3 -3
  112. package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/diagnosis.md +3 -3
  113. package/node_modules/@llblab/pi-telegram/docs/README.md +1 -1
  114. package/node_modules/@llblab/pi-telegram/docs/activity.md +1 -1
  115. package/node_modules/@llblab/pi-telegram/docs/architecture.md +152 -34
  116. package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +1 -1
  117. package/node_modules/@llblab/pi-telegram/docs/delivery.md +1 -1
  118. package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +2 -2
  119. package/node_modules/@llblab/pi-telegram/docs/inbound.md +1 -1
  120. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +125 -19
  121. package/node_modules/@llblab/pi-telegram/docs/public-api.md +3 -1
  122. package/node_modules/@llblab/pi-telegram/docs/ui-style.md +22 -8
  123. package/node_modules/@llblab/pi-telegram/docs/updates.md +1 -1
  124. package/node_modules/@llblab/pi-telegram/lib/activity-verbosity.ts +5 -9
  125. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +6 -0
  126. package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +5 -2
  127. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +243 -224
  128. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +178 -31
  129. package/node_modules/@llblab/pi-telegram/lib/bus-transport.ts +30 -8
  130. package/node_modules/@llblab/pi-telegram/lib/bus.ts +110 -334
  131. package/node_modules/@llblab/pi-telegram/lib/channel-posts.ts +29 -29
  132. package/node_modules/@llblab/pi-telegram/lib/command-templates.ts +5 -5
  133. package/node_modules/@llblab/pi-telegram/lib/commands.ts +15 -15
  134. package/node_modules/@llblab/pi-telegram/lib/config.ts +12 -17
  135. package/node_modules/@llblab/pi-telegram/lib/delivery.ts +2 -8
  136. package/node_modules/@llblab/pi-telegram/lib/extension.ts +257 -72
  137. package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +0 -22
  138. package/node_modules/@llblab/pi-telegram/lib/inbound.ts +2 -2
  139. package/node_modules/@llblab/pi-telegram/lib/journal.ts +1182 -326
  140. package/node_modules/@llblab/pi-telegram/lib/keyboard.ts +2 -2
  141. package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +1 -1
  142. package/node_modules/@llblab/pi-telegram/lib/locks.ts +402 -23
  143. package/node_modules/@llblab/pi-telegram/lib/logging.ts +151 -101
  144. package/node_modules/@llblab/pi-telegram/lib/media.ts +51 -9
  145. package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +8 -8
  146. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +18 -18
  147. package/node_modules/@llblab/pi-telegram/lib/menu-status.ts +11 -0
  148. package/node_modules/@llblab/pi-telegram/lib/menu-thinking.ts +2 -2
  149. package/node_modules/@llblab/pi-telegram/lib/menu.ts +5 -1
  150. package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +1 -1
  151. package/node_modules/@llblab/pi-telegram/lib/outbound-buttons.ts +1 -10
  152. package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +5 -24
  153. package/node_modules/@llblab/pi-telegram/lib/outbound.ts +5 -5
  154. package/node_modules/@llblab/pi-telegram/lib/paths.ts +177 -17
  155. package/node_modules/@llblab/pi-telegram/lib/pi.ts +5 -2
  156. package/node_modules/@llblab/pi-telegram/lib/polling.ts +5 -5
  157. package/node_modules/@llblab/pi-telegram/lib/preview.ts +3 -3
  158. package/node_modules/@llblab/pi-telegram/lib/prompt-templates.ts +1 -1
  159. package/node_modules/@llblab/pi-telegram/lib/queue.ts +67 -9
  160. package/node_modules/@llblab/pi-telegram/lib/recovery.ts +104 -44
  161. package/node_modules/@llblab/pi-telegram/lib/replies.ts +1 -1
  162. package/node_modules/@llblab/pi-telegram/lib/routing.ts +1955 -375
  163. package/node_modules/@llblab/pi-telegram/lib/sections.ts +1 -1
  164. package/node_modules/@llblab/pi-telegram/lib/status.ts +156 -36
  165. package/node_modules/@llblab/pi-telegram/lib/sync.ts +4 -4
  166. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +48 -33
  167. package/node_modules/@llblab/pi-telegram/lib/thread-cleanup-manager.ts +24 -21
  168. package/node_modules/@llblab/pi-telegram/lib/thread-naming.ts +267 -9
  169. package/node_modules/@llblab/pi-telegram/lib/thread-reconciler.ts +3 -1
  170. package/node_modules/@llblab/pi-telegram/lib/threads.ts +1697 -488
  171. package/node_modules/@llblab/pi-telegram/lib/turns.ts +1 -1
  172. package/node_modules/@llblab/pi-telegram/lib/updates.ts +1072 -151
  173. package/node_modules/@llblab/pi-telegram/lib/wire.ts +28 -0
  174. package/node_modules/@llblab/pi-telegram/lib/workspace-admission.ts +97 -47
  175. package/node_modules/@llblab/pi-telegram/lib/workspace-identity.ts +147 -0
  176. package/node_modules/@llblab/pi-telegram/lib/workspace-retirement.ts +188 -89
  177. package/node_modules/@llblab/pi-telegram/package.json +6 -6
  178. package/node_modules/@llblab/pi-telegram/scripts/audit-exports.mjs +100 -0
  179. package/node_modules/@llblab/pi-telegram/scripts/check-downgrade.mjs +80 -43
  180. package/node_modules/@llblab/pi-telegram/skills/generated-control-surface/SKILL.md +3 -3
  181. package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/references/diagnosis.md +3 -3
  182. package/package.json +2 -2
@@ -5,22 +5,16 @@
5
5
  * heartbeat, forwarded-update receiving, and follower-routed API calls.
6
6
  * It must not spawn Pi processes or create hidden Telegram-originated instances.
7
7
  */
8
- import * as Sync from "./sync.ts";
8
+ import type { TelegramWorkspaceRestoreExecutor, TelegramWorkspaceRestoreIntent } from "./threads.ts";
9
9
  import * as Threads from "./threads.ts";
10
10
  import { type TelegramUpdateJournalStoreOptions } from "./journal.ts";
11
11
  import { type TelegramLockEntry, type TelegramLockState } from "./locks.ts";
12
12
  import type { TelegramQueueHandoffPayload, TelegramQueueHandoffStageResult } from "./queue.ts";
13
13
  import type { TelegramTarget } from "./target.ts";
14
- import { type TelegramBusAgentMessage, type TelegramBusAgentTargetSelector, type TelegramBusEnvelope, type TelegramBusForwardOwnership, type TelegramBusProtocolIdentity, type TelegramBusSocketPathSource } from "./bus.ts";
14
+ import { type TelegramBusAgentMessage, type TelegramBusAgentTargetSelector, type TelegramBusEnvelope, type TelegramBusWorkspaceRestoreObservation, type TelegramBusForwardOwnership, type TelegramBusProtocolIdentity, type TelegramBusSocketPathSource } from "./bus.ts";
15
15
  import type { TelegramConfigStore, TelegramThreadDisplayMode } from "./config.ts";
16
16
  import { type TelegramWorkspaceAdmissionLedger } from "./workspace-admission.ts";
17
- export declare const TELEGRAM_BUS_FOLLOWER_PROMOTION_GRACE_MS = 2500;
18
- export declare const TELEGRAM_FOLLOWER_SESSION_HANDOFF_TTL_MS = 30000;
19
- export declare const TELEGRAM_BUS_FOLLOWER_CLIENT_TIMEOUT_MS = 30000;
20
- export declare const TELEGRAM_BUS_FOLLOWER_REGISTRATION_WAIT_MS = 30000;
21
17
  export declare const TELEGRAM_BUS_FOLLOWER_HEARTBEAT_TIMEOUT_MS = 8000;
22
- export declare const TELEGRAM_BUS_FOLLOWER_REGISTRATION_RETRY_ATTEMPTS: number;
23
- export declare const TELEGRAM_BUS_FOLLOWER_REGISTRATION_RETRY_DELAY_MS: number;
24
18
  export interface TelegramFollowerSessionHandoff {
25
19
  pid: number;
26
20
  instanceId: string;
@@ -31,11 +25,6 @@ export interface TelegramFollowerSessionHandoff {
31
25
  }
32
26
  export declare function getTelegramFollowerSessionHandoff(): TelegramFollowerSessionHandoff | undefined;
33
27
  export declare function setTelegramFollowerSessionHandoff(handoff: TelegramFollowerSessionHandoff | undefined): void;
34
- export declare function isTelegramFollowerSessionHandoffFresh(handoff: TelegramFollowerSessionHandoff | undefined, options?: {
35
- pid?: number;
36
- nowMs?: number;
37
- ttlMs?: number;
38
- }): handoff is TelegramFollowerSessionHandoff;
39
28
  export interface TelegramBusFollowerRegistrationRuntime<TContext> {
40
29
  registerWithLeader: (ctx: TContext, leader: {
41
30
  busSocketPath?: string;
@@ -95,6 +84,8 @@ export interface TelegramBusFollowerRegistrationState {
95
84
  getDisplayTitle: () => string | undefined;
96
85
  setDisplayTitle: (title: string, generation: string) => boolean;
97
86
  getGeneration: () => string | undefined;
87
+ /** Return the acknowledged session only when it matches the caller's current context. */
88
+ getSessionId: (currentSessionId: string | undefined) => string | undefined;
98
89
  beginRecovery: () => number;
99
90
  cancelRecovery: () => void;
100
91
  waitForGeneration: (timeoutMs?: number) => Promise<string | undefined>;
@@ -106,6 +97,7 @@ export interface TelegramBusFollowerRegistrationState {
106
97
  threadName?: string;
107
98
  displayTitle?: string;
108
99
  generation?: string;
100
+ sessionId?: string;
109
101
  leaderProtocol?: TelegramBusProtocolIdentity;
110
102
  }) => void;
111
103
  }
@@ -204,19 +196,6 @@ export declare function createTelegramBusFollowerPromotionHandler<TContext exten
204
196
  getPid?: () => number;
205
197
  getWorkspaceAdmission?: TelegramBusFollowerWorkspaceAdmissionDeps["getWorkspaceAdmission"];
206
198
  }): TelegramBusFollowerPromotionHandler<TContext>;
207
- export interface TelegramBusFollowerTargetReplacementHandlerDeps<TContext> {
208
- topicTargetStore: Pick<Threads.TelegramTopicTargetStore, "load" | "list" | "markStaleByTarget" | "upsert" | "persist">;
209
- registrationState: Pick<TelegramBusFollowerRegistrationState, "getTarget" | "getSlot" | "setRegistered" | "getGeneration">;
210
- instanceId: string;
211
- getManualFollowerProfileKey: () => string;
212
- manualFollowerOwnerId: string;
213
- getSyncState: () => Sync.TelegramSyncState;
214
- setSyncState: (state: Sync.TelegramSyncState) => void;
215
- getNowMs?: () => number;
216
- updateStatus: (ctx: TContext) => void;
217
- recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
218
- getWorkspaceAdmission?: TelegramBusFollowerWorkspaceAdmissionDeps["getWorkspaceAdmission"];
219
- }
220
199
  export type TelegramBusFollowerLeaderState = {
221
200
  kind: "inactive";
222
201
  } | {
@@ -265,21 +244,18 @@ export interface TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext> {
265
244
  handleQueueHandoff?: (envelope: Extract<TelegramBusEnvelope, {
266
245
  kind: "leader.offerQueueHandoff";
267
246
  }>, ctx: TContext) => Promise<TelegramQueueHandoffStageResult> | TelegramQueueHandoffStageResult;
268
- handleReplaceTarget?: (input: {
269
- target: TelegramTarget & {
270
- threadId: number;
271
- };
272
- oldTarget?: TelegramTarget & {
273
- threadId: number;
274
- };
275
- reason: "thread-restore";
247
+ isWorkspaceRestoreEnabled?: () => boolean;
248
+ handleWorkspaceRestore?: (input: {
249
+ operationId: string;
276
250
  registrationGeneration: string;
277
- }, ctx: TContext) => Promise<void> | void;
251
+ mode: "apply" | "inspect";
252
+ }, ctx: TContext) => Promise<TelegramBusWorkspaceRestoreObservation>;
278
253
  recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
279
254
  }
280
255
  export interface TelegramBusFollowerRuntimeAssembly<TContext> {
281
256
  receiver: TelegramBusForwardedUpdateReceiverRuntime;
282
257
  registration: TelegramBusFollowerRegistrationRuntime<TContext>;
258
+ getReadySessionId: () => string | undefined;
283
259
  }
284
260
  export interface TelegramBusFollowerRuntimeAssemblyPorts<TContext extends {
285
261
  cwd?: string;
@@ -287,8 +263,7 @@ export interface TelegramBusFollowerRuntimeAssemblyPorts<TContext extends {
287
263
  instanceId: string;
288
264
  registrationState: TelegramBusFollowerRegistrationState;
289
265
  recordRuntimeEvent: (category: string, error: unknown, details?: Record<string, unknown>) => void;
290
- receiver: Omit<TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext>, "handleReplaceTarget" | "instanceId" | "recordRuntimeEvent" | "getRegistrationGeneration">;
291
- targetReplacement: Omit<TelegramBusFollowerTargetReplacementHandlerDeps<TContext>, "registrationState" | "instanceId" | "recordRuntimeEvent">;
266
+ receiver: Omit<TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext>, "instanceId" | "recordRuntimeEvent" | "getRegistrationGeneration">;
292
267
  recovery: Omit<TelegramBusFollowerHeartbeatRecoveryHandlerDeps<TContext>, "getRegistrationRuntime" | "registrationState" | "recordRuntimeEvent">;
293
268
  registration: Omit<TelegramBusFollowerRegistrationRuntimeDeps<TContext>, "startReceiving" | "stopReceiving" | "onHeartbeatFailure" | "instanceId" | "registrationState" | "recordRuntimeEvent" | "protocolIdentity"> & {
294
269
  protocolIdentity: TelegramBusProtocolIdentity;
@@ -297,7 +272,42 @@ export interface TelegramBusFollowerRuntimeAssemblyPorts<TContext extends {
297
272
  export declare function createTelegramBusFollowerRuntimeAssembly<TContext extends {
298
273
  cwd?: string;
299
274
  }>(ports: TelegramBusFollowerRuntimeAssemblyPorts<TContext>): TelegramBusFollowerRuntimeAssembly<TContext>;
300
- export declare function createTelegramBusFollowerTargetReplacementHandler<TContext>(deps: TelegramBusFollowerTargetReplacementHandlerDeps<TContext>): NonNullable<TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext>["handleReplaceTarget"]>;
275
+ export interface TelegramBusFollowerRestoreContext {
276
+ executor: TelegramWorkspaceRestoreExecutor;
277
+ profileBindingKey: string;
278
+ operatorUserId: number;
279
+ cwd: string;
280
+ sessionId: string;
281
+ generation: string | number;
282
+ leaderProtocol?: TelegramBusProtocolIdentity;
283
+ }
284
+ /** Binds Restore to real Pi lifetime and the current authenticated transport owner, not request fields. */
285
+ export declare function createTelegramBusFollowerRestoreContextGetter<TContext>(deps: {
286
+ isContextCurrent: (ctx: TContext) => boolean;
287
+ getSessionId: (ctx: TContext) => string | undefined;
288
+ getCwd: (ctx: TContext) => string | undefined;
289
+ getGeneration: () => number;
290
+ getProfileBindingKey: () => string | undefined;
291
+ getOperatorUserId: () => number | undefined;
292
+ getLeaderState: () => TelegramLockState;
293
+ getAuthenticatedSecret: () => string | undefined;
294
+ getLeaderProtocol: () => TelegramBusProtocolIdentity | undefined;
295
+ }): (ctx: TContext) => TelegramBusFollowerRestoreContext | undefined;
296
+ /** Prepared receiver: its caller authenticates the envelope; no canonical writes, dispatch or cleanup. */
297
+ export declare function createTelegramBusFollowerWorkspaceRestoreHandler<TContext>(deps: {
298
+ instanceId: string;
299
+ /** Captures actual Pi lifetime and authenticated leader/profile authority, never request-derived values. */
300
+ getContextAuthority: (ctx: TContext) => TelegramBusFollowerRestoreContext | undefined;
301
+ readRestoreIntent: (operationId: string, profileBindingKey: string) => TelegramWorkspaceRestoreIntent | undefined;
302
+ topicTargetStore: Pick<Threads.TelegramTopicTargetStore, "load" | "withWorkspaceRestoreSnapshot">;
303
+ registrationState: Pick<TelegramBusFollowerRegistrationState, "getTarget" | "getSlot" | "getGeneration" | "setRegistered" | "getLeaderProtocol">;
304
+ getWorkspaceAdmission: NonNullable<TelegramBusFollowerWorkspaceAdmissionDeps["getWorkspaceAdmission"]>;
305
+ recordRuntimeEvent?: TelegramBusFollowerWorkspaceAdmissionDeps["recordRuntimeEvent"];
306
+ }): (input: {
307
+ operationId: string;
308
+ registrationGeneration: string;
309
+ mode: "apply" | "inspect";
310
+ }, ctx: TContext) => Promise<TelegramBusWorkspaceRestoreObservation>;
301
311
  export declare function createTelegramBusFollowerClientRuntime<TContext, TReactionUpdate, TCallbackQuery, TMessage = unknown>(deps: TelegramBusFollowerClientRuntimeDeps<TMessage>): {
302
312
  createRequestId: () => string;
303
313
  callApi: (method: string, args: unknown[]) => Promise<unknown>;
@@ -340,18 +350,6 @@ export declare function createTelegramBusFollowerClientRuntime<TContext, TReacti
340
350
  handoffToken: string;
341
351
  payload: TelegramQueueHandoffPayload;
342
352
  }) => Promise<TelegramQueueHandoffStageResult>;
343
- targetController: {
344
- replaceTarget: (input: {
345
- follower: import("./bus.ts").TelegramBusFollowerView;
346
- target: TelegramTarget & {
347
- threadId: number;
348
- };
349
- oldTarget?: TelegramTarget & {
350
- threadId: number;
351
- };
352
- reason: "thread-restore";
353
- }) => Promise<boolean>;
354
- };
355
353
  };
356
354
  export declare function createTelegramBusFollowerQueueHandoffClient(deps: TelegramBusFollowerApiCallerDeps): (input: {
357
355
  recipientInstanceId: string;
@@ -364,12 +362,6 @@ export declare function createTelegramBusFollowerQueueHandoffClient(deps: Telegr
364
362
  handoffToken: string;
365
363
  payload: TelegramQueueHandoffPayload;
366
364
  }) => Promise<TelegramQueueHandoffStageResult>;
367
- export declare function createTelegramBusAgentMessageClient(deps: TelegramBusFollowerApiCallerDeps): {
368
- resolveTarget: (selector: TelegramBusAgentTargetSelector) => Promise<TelegramTarget & {
369
- threadId: number;
370
- }>;
371
- routeMessage: (message: TelegramBusAgentMessage) => Promise<void>;
372
- };
373
365
  export declare function createTelegramBusFollowerApiCaller(deps: TelegramBusFollowerApiCallerDeps): (method: string, args: unknown[]) => Promise<unknown>;
374
366
  export declare function createTelegramBusFollowerSessionReplacementSuspender(deps: TelegramBusFollowerSessionReplacementSuspenderDeps): (preserveTarget?: boolean) => Promise<void>;
375
367
  export declare function createTelegramBusFollowerSessionRefreshHook<TContext>(deps: TelegramBusFollowerSessionRefreshHookDeps<TContext>): (_event: unknown, ctx: TContext) => Promise<void>;
@@ -398,6 +390,12 @@ export declare function createTelegramBusFollowerDurableAdmissionRuntime<TContex
398
390
  } & Record<string, unknown>)[]): unknown;
399
391
  };
400
392
  signalWorker: (ctx: TContext) => void;
393
+ getNowMs?: () => number;
394
+ /** Bounded process-local replay window; omit for the production 24 h / 4,096-delivery defaults. */
395
+ recentDeliveryLimit?: {
396
+ maxAgeMs: number;
397
+ maxEntries: number;
398
+ };
401
399
  }): TelegramBusFollowerDurableAdmissionPort<TContext>;
402
400
  export interface TelegramBusFollowerInputCustodyBundle<TContext> {
403
401
  acceptHandoff(input: {