@llblab/pi-telegram 0.46.0 → 0.48.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 (204) hide show
  1. package/AGENTS.md +4 -2
  2. package/BACKLOG.md +0 -6
  3. package/CHANGELOG.md +14 -0
  4. package/README.md +5 -2
  5. package/dist/api/activity.d.ts +6 -0
  6. package/dist/api/activity.js +6 -0
  7. package/dist/api/commands.d.ts +6 -0
  8. package/dist/api/commands.js +6 -0
  9. package/dist/api/delivery.d.ts +6 -0
  10. package/dist/api/delivery.js +6 -0
  11. package/dist/api/inbound.d.ts +6 -0
  12. package/dist/api/inbound.js +6 -0
  13. package/dist/api/keyboard.d.ts +6 -0
  14. package/dist/api/keyboard.js +6 -0
  15. package/dist/api/outbound.d.ts +6 -0
  16. package/dist/api/outbound.js +6 -0
  17. package/dist/api/sections.d.ts +7 -0
  18. package/dist/api/sections.js +6 -0
  19. package/dist/api/status.d.ts +6 -0
  20. package/dist/api/status.js +6 -0
  21. package/dist/api/updates.d.ts +6 -0
  22. package/dist/api/updates.js +6 -0
  23. package/dist/api/voice.d.ts +6 -0
  24. package/dist/api/voice.js +6 -0
  25. package/dist/index.d.ts +6 -0
  26. package/dist/index.js +6 -0
  27. package/dist/lib/activity-verbosity.d.ts +52 -0
  28. package/dist/lib/activity-verbosity.js +596 -0
  29. package/dist/lib/activity.d.ts +220 -0
  30. package/dist/lib/activity.js +574 -0
  31. package/dist/lib/agent-messages.d.ts +28 -0
  32. package/dist/lib/agent-messages.js +86 -0
  33. package/dist/lib/bindings.d.ts +250 -0
  34. package/dist/lib/bindings.js +936 -0
  35. package/dist/lib/bus-api.d.ts +18 -0
  36. package/dist/lib/bus-api.js +254 -0
  37. package/dist/lib/bus-follower.d.ts +464 -0
  38. package/dist/lib/bus-follower.js +1686 -0
  39. package/dist/lib/bus-leader.d.ts +292 -0
  40. package/dist/lib/bus-leader.js +2242 -0
  41. package/dist/lib/bus-transport.d.ts +64 -0
  42. package/dist/lib/bus-transport.js +140 -0
  43. package/dist/lib/bus.d.ts +518 -0
  44. package/dist/lib/bus.js +2055 -0
  45. package/dist/lib/channel-posts.d.ts +170 -0
  46. package/dist/lib/channel-posts.js +611 -0
  47. package/dist/lib/command-templates.d.ts +70 -0
  48. package/dist/lib/command-templates.js +744 -0
  49. package/dist/lib/commands.d.ts +541 -0
  50. package/dist/lib/commands.js +1155 -0
  51. package/dist/lib/config.d.ts +252 -0
  52. package/dist/lib/config.js +889 -0
  53. package/dist/lib/delivery.d.ts +163 -0
  54. package/dist/lib/delivery.js +542 -0
  55. package/dist/lib/extension.d.ts +7 -0
  56. package/dist/lib/extension.js +1604 -0
  57. package/dist/lib/generative-app-worker.mjs +104 -0
  58. package/dist/lib/generative-apps.d.ts +212 -0
  59. package/dist/lib/generative-apps.js +1006 -0
  60. package/dist/lib/inbound.d.ts +91 -0
  61. package/dist/lib/inbound.js +502 -0
  62. package/dist/lib/journal.d.ts +665 -0
  63. package/dist/lib/journal.js +3701 -0
  64. package/dist/lib/keyboard.d.ts +23 -0
  65. package/dist/lib/keyboard.js +37 -0
  66. package/dist/lib/lifecycle.d.ts +157 -0
  67. package/dist/lib/lifecycle.js +395 -0
  68. package/dist/lib/locks.d.ts +164 -0
  69. package/dist/lib/locks.js +1208 -0
  70. package/dist/lib/logging.d.ts +50 -0
  71. package/dist/lib/logging.js +274 -0
  72. package/dist/lib/media.d.ts +181 -0
  73. package/dist/lib/media.js +602 -0
  74. package/dist/lib/menu-model.d.ts +217 -0
  75. package/dist/lib/menu-model.js +663 -0
  76. package/dist/lib/menu-queue.d.ts +37 -0
  77. package/dist/lib/menu-queue.js +408 -0
  78. package/dist/lib/menu-settings.d.ts +115 -0
  79. package/dist/lib/menu-settings.js +595 -0
  80. package/dist/lib/menu-status.d.ts +32 -0
  81. package/dist/lib/menu-status.js +112 -0
  82. package/dist/lib/menu-thinking.d.ts +29 -0
  83. package/dist/lib/menu-thinking.js +82 -0
  84. package/dist/lib/menu.d.ts +171 -0
  85. package/dist/lib/menu.js +323 -0
  86. package/dist/lib/model.d.ts +127 -0
  87. package/dist/lib/model.js +409 -0
  88. package/dist/lib/outbound-attachments.d.ts +241 -0
  89. package/dist/lib/outbound-attachments.js +639 -0
  90. package/dist/lib/outbound-buttons.d.ts +69 -0
  91. package/dist/lib/outbound-buttons.js +248 -0
  92. package/dist/lib/outbound-markup.d.ts +42 -0
  93. package/dist/lib/outbound-markup.js +678 -0
  94. package/dist/lib/outbound-voice.d.ts +55 -0
  95. package/dist/lib/outbound-voice.js +152 -0
  96. package/dist/lib/outbound.d.ts +185 -0
  97. package/dist/lib/outbound.js +516 -0
  98. package/dist/lib/ownership.d.ts +77 -0
  99. package/dist/lib/ownership.js +174 -0
  100. package/dist/lib/paths.d.ts +40 -0
  101. package/dist/lib/paths.js +94 -0
  102. package/dist/lib/pi.d.ts +72 -0
  103. package/dist/lib/pi.js +121 -0
  104. package/dist/lib/polling.d.ts +351 -0
  105. package/dist/lib/polling.js +1196 -0
  106. package/dist/lib/preview.d.ts +192 -0
  107. package/dist/lib/preview.js +614 -0
  108. package/dist/lib/prompt-templates.d.ts +24 -0
  109. package/dist/lib/prompt-templates.js +118 -0
  110. package/dist/lib/prompts.d.ts +57 -0
  111. package/dist/lib/prompts.js +167 -0
  112. package/dist/lib/queue.d.ts +766 -0
  113. package/dist/lib/queue.js +1965 -0
  114. package/dist/lib/recovery.d.ts +86 -0
  115. package/dist/lib/recovery.js +285 -0
  116. package/dist/lib/rendering.d.ts +20 -0
  117. package/dist/lib/rendering.js +983 -0
  118. package/dist/lib/replies.d.ts +214 -0
  119. package/dist/lib/replies.js +737 -0
  120. package/dist/lib/routing.d.ts +207 -0
  121. package/dist/lib/routing.js +2282 -0
  122. package/dist/lib/runtime.d.ts +172 -0
  123. package/dist/lib/runtime.js +402 -0
  124. package/dist/lib/sections.d.ts +165 -0
  125. package/dist/lib/sections.js +327 -0
  126. package/dist/lib/setup.d.ts +82 -0
  127. package/dist/lib/setup.js +150 -0
  128. package/dist/lib/skills.d.ts +8 -0
  129. package/dist/lib/skills.js +12 -0
  130. package/dist/lib/status.d.ts +442 -0
  131. package/dist/lib/status.js +1008 -0
  132. package/dist/lib/sync.d.ts +179 -0
  133. package/dist/lib/sync.js +782 -0
  134. package/dist/lib/target.d.ts +20 -0
  135. package/dist/lib/target.js +27 -0
  136. package/dist/lib/telegram-api.d.ts +541 -0
  137. package/dist/lib/telegram-api.js +1159 -0
  138. package/dist/lib/text-groups.d.ts +89 -0
  139. package/dist/lib/text-groups.js +317 -0
  140. package/dist/lib/thread-cleanup-manager.d.ts +288 -0
  141. package/dist/lib/thread-cleanup-manager.js +560 -0
  142. package/dist/lib/thread-display.d.ts +46 -0
  143. package/dist/lib/thread-display.js +257 -0
  144. package/dist/lib/thread-naming.d.ts +46 -0
  145. package/dist/lib/thread-naming.js +78 -0
  146. package/dist/lib/thread-reconciler.d.ts +239 -0
  147. package/dist/lib/thread-reconciler.js +644 -0
  148. package/dist/lib/threads.d.ts +621 -0
  149. package/dist/lib/threads.js +3679 -0
  150. package/dist/lib/time-injection.d.ts +15 -0
  151. package/dist/lib/time-injection.js +56 -0
  152. package/dist/lib/turns.d.ts +109 -0
  153. package/dist/lib/turns.js +500 -0
  154. package/dist/lib/updates.d.ts +1290 -0
  155. package/dist/lib/updates.js +3634 -0
  156. package/dist/lib/voice.d.ts +117 -0
  157. package/dist/lib/voice.js +174 -0
  158. package/dist/lib/workspace-admission.d.ts +264 -0
  159. package/dist/lib/workspace-admission.js +1136 -0
  160. package/dist/lib/workspace-retirement.d.ts +219 -0
  161. package/dist/lib/workspace-retirement.js +587 -0
  162. package/dist/lib/workspace-slots.d.ts +30 -0
  163. package/dist/lib/workspace-slots.js +54 -0
  164. package/dist/package.json +126 -0
  165. package/dist/pi-telegram/index.js +1 -0
  166. package/dist/skills/generated-control-surface/SKILL.md +107 -0
  167. package/dist/skills/generated-control-surface/references/capability-adapters.md +27 -0
  168. package/dist/skills/generated-control-surface/references/layout-and-state.md +37 -0
  169. package/dist/skills/generative-apps/SKILL.md +115 -0
  170. package/dist/skills/show-me/SKILL.md +166 -0
  171. package/dist/skills/show-me/references/telegram-surfaces.md +43 -0
  172. package/dist/skills/telegram-bridge/SKILL.md +129 -0
  173. package/dist/skills/telegram-bridge/references/configuration.md +15 -0
  174. package/dist/skills/telegram-bridge/references/delivery-and-threads.md +27 -0
  175. package/dist/skills/telegram-bridge/references/diagnosis.md +18 -0
  176. package/docs/README.md +2 -0
  177. package/docs/architecture.md +1 -1
  178. package/docs/compact-matrix-literal.md +10 -3
  179. package/docs/generative-apps.md +15 -13
  180. package/docs/multi-instance-bus.md +6 -4
  181. package/docs/outbound.md +1 -1
  182. package/docs/public-api.md +3 -3
  183. package/lib/bindings.ts +89 -6
  184. package/lib/bus-follower.ts +7 -3
  185. package/lib/bus-leader.ts +44 -19
  186. package/lib/bus.ts +4 -1
  187. package/lib/commands.ts +2 -2
  188. package/lib/config.ts +14 -7
  189. package/lib/delivery.ts +38 -6
  190. package/lib/extension.ts +7 -0
  191. package/lib/generative-apps.ts +379 -13
  192. package/lib/menu-settings.ts +20 -6
  193. package/lib/outbound-markup.ts +16 -7
  194. package/lib/status.ts +15 -12
  195. package/lib/telegram-api.ts +12 -1
  196. package/lib/thread-display.ts +96 -18
  197. package/package.json +56 -13
  198. package/scripts/build-dist.mjs +44 -0
  199. package/scripts/measure-bus.mjs +8 -1
  200. package/scripts/measure-workspace.mjs +8 -1
  201. package/skills/generative-apps/SKILL.md +1 -1
  202. package/skills/show-me/SKILL.md +1 -1
  203. package/skills/show-me/references/telegram-surfaces.md +1 -1
  204. package/skills/telegram-bridge/SKILL.md +1 -1
@@ -0,0 +1,464 @@
1
+ /**
2
+ * Telegram bus follower runtime
3
+ * Zones: multi-instance bus, follower lifecycle, manual registration
4
+ * Owns this Pi instance's follower-side bus behavior: manual registration,
5
+ * heartbeat, forwarded-update receiving, and follower-routed API calls.
6
+ * It must not spawn Pi processes or create hidden Telegram-originated instances.
7
+ */
8
+ import * as Sync from "./sync.ts";
9
+ import * as Threads from "./threads.ts";
10
+ import { type TelegramUpdateJournalStoreOptions } from "./journal.ts";
11
+ import type { TelegramLockEntry, TelegramLockState } from "./locks.ts";
12
+ import type { TelegramQueueHandoffPayload, TelegramQueueHandoffStageResult } from "./queue.ts";
13
+ import type { TelegramTarget } from "./target.ts";
14
+ import { type TelegramBusAgentMessage, type TelegramBusAgentTargetSelector, type TelegramBusEnvelope, type TelegramBusForwardOwnership, type TelegramBusProtocolIdentity, type TelegramBusSocketPathSource } from "./bus.ts";
15
+ import type { TelegramConfigStore, TelegramThreadDisplayMode } from "./config.ts";
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
+ export declare const TELEGRAM_BUS_FOLLOWER_REGISTRATION_RETRY_ATTEMPTS: number;
22
+ export declare const TELEGRAM_BUS_FOLLOWER_REGISTRATION_RETRY_DELAY_MS: number;
23
+ export interface TelegramFollowerSessionHandoff {
24
+ pid: number;
25
+ instanceId: string;
26
+ createdAtMs: number;
27
+ target: TelegramTarget;
28
+ slot?: string;
29
+ threadName?: string;
30
+ }
31
+ export declare function getTelegramFollowerSessionHandoff(): TelegramFollowerSessionHandoff | undefined;
32
+ export declare function setTelegramFollowerSessionHandoff(handoff: TelegramFollowerSessionHandoff | undefined): void;
33
+ export declare function isTelegramFollowerSessionHandoffFresh(handoff: TelegramFollowerSessionHandoff | undefined, options?: {
34
+ pid?: number;
35
+ nowMs?: number;
36
+ ttlMs?: number;
37
+ }): handoff is TelegramFollowerSessionHandoff;
38
+ export interface TelegramBusFollowerRegistrationRuntime<TContext> {
39
+ registerWithLeader: (ctx: TContext, leader: {
40
+ busSocketPath?: string;
41
+ busSecret?: string;
42
+ }, options?: {
43
+ target?: TelegramTarget;
44
+ previousInstanceId?: string;
45
+ restoreWorkspace?: boolean;
46
+ }) => Promise<boolean>;
47
+ setContext: (ctx: TContext) => void;
48
+ disconnectFromLeader?: () => Promise<boolean>;
49
+ renameThread?: (target: TelegramTarget & {
50
+ threadId: number;
51
+ }, threadName: string) => Promise<string>;
52
+ resetThreadName?: (target: TelegramTarget & {
53
+ threadId: number;
54
+ }) => Promise<string>;
55
+ setThreadDisplayMode?: (mode: TelegramThreadDisplayMode) => Promise<void>;
56
+ stop: () => void;
57
+ }
58
+ export interface TelegramBusFollowerSessionReplacementSuspenderDeps {
59
+ registrationState: Pick<TelegramBusFollowerRegistrationState, "isRegistered" | "getTarget" | "getSlot" | "getThreadName">;
60
+ instanceId: string;
61
+ suspendPolling: () => Promise<void>;
62
+ isLeader?: () => boolean;
63
+ getLeaderBinding?: () => TelegramBusFollowerPromotedBinding | undefined;
64
+ getActiveContext?: () => {
65
+ cwd?: string;
66
+ } | undefined;
67
+ getActiveProfileName?: () => string | undefined;
68
+ recordRuntimeEvent: (category: string, error: unknown, details?: Record<string, unknown>) => void;
69
+ getNowMs?: () => number;
70
+ getPid?: () => number;
71
+ }
72
+ export interface TelegramBusFollowerSessionRefreshHookDeps<TContext> {
73
+ registrationState: Pick<TelegramBusFollowerRegistrationState, "isRegistered">;
74
+ registrationRuntime: Pick<TelegramBusFollowerRegistrationRuntime<TContext>, "registerWithLeader" | "setContext">;
75
+ getLeaderState: () => TelegramLockState;
76
+ isSessionActive?: (ctx: TContext) => boolean;
77
+ updateStatus: (ctx: TContext) => void;
78
+ recordRuntimeEvent: (category: string, error: unknown, details?: Record<string, unknown>) => void;
79
+ }
80
+ export type TelegramBusFollowerControlLifecyclePhase = "electing";
81
+ export interface TelegramBusFollowerControlState {
82
+ getActiveAuthSecret: () => string | undefined;
83
+ setActiveAuthSecret: (secret: string | undefined) => void;
84
+ getLifecyclePhase: () => TelegramBusFollowerControlLifecyclePhase | undefined;
85
+ setLifecyclePhase: (phase: TelegramBusFollowerControlLifecyclePhase | undefined) => void;
86
+ }
87
+ export interface TelegramBusFollowerRegistrationState {
88
+ isRegistered: () => boolean;
89
+ getTarget: () => TelegramTarget | undefined;
90
+ getSlot: () => string | undefined;
91
+ getThreadName: () => string | undefined;
92
+ getDisplayTitle: () => string | undefined;
93
+ setDisplayTitle: (title: string, generation: string) => boolean;
94
+ getGeneration: () => string | undefined;
95
+ beginRecovery: () => number;
96
+ cancelRecovery: () => void;
97
+ waitForGeneration: (timeoutMs?: number) => Promise<string | undefined>;
98
+ getLeaderProtocol: () => TelegramBusProtocolIdentity | undefined;
99
+ getEligibleElectionSlots: () => readonly string[];
100
+ setEligibleElectionSlots: (slots: readonly string[]) => void;
101
+ setRegistered: (registered: boolean, target?: TelegramTarget, metadata?: {
102
+ slot?: string;
103
+ threadName?: string;
104
+ displayTitle?: string;
105
+ generation?: string;
106
+ leaderProtocol?: TelegramBusProtocolIdentity;
107
+ }) => void;
108
+ }
109
+ export interface TelegramBusForwardedUpdateReceiverRuntime {
110
+ start: () => Promise<void>;
111
+ stop: () => Promise<void>;
112
+ }
113
+ export interface TelegramBusFollowerDurableAdmissionResult {
114
+ deliveryId: string;
115
+ sourceUpdateId: number;
116
+ }
117
+ export interface TelegramBusFollowerDurableAdmissionPort<TContext> {
118
+ admit: (envelope: Extract<TelegramBusEnvelope, {
119
+ kind: "leader.forwardCallback" | "leader.forwardReaction" | "leader.forwardMessage" | "leader.forwardEditedMessage" | "leader.wakeInputCustody";
120
+ }>, ctx: TContext) => Promise<TelegramBusFollowerDurableAdmissionResult>;
121
+ }
122
+ export interface TelegramBusFollowerClientRuntimeDeps<TMessage = unknown> {
123
+ socketPath: TelegramBusSocketPathSource;
124
+ instanceId: string;
125
+ getApiAuthSecret?: () => string | undefined;
126
+ getForwardingAuthSecret?: () => string | undefined;
127
+ getRegistrationGeneration: () => string | undefined;
128
+ waitForRegistrationGeneration?: (timeoutMs?: number) => Promise<string | undefined>;
129
+ getForwardCommentBatchPosition?: (message: TMessage) => "comment" | "forward" | undefined;
130
+ validateForwardOwnership?: (ownership: TelegramBusForwardOwnership) => boolean;
131
+ recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
132
+ timeoutMs?: number;
133
+ }
134
+ export interface TelegramBusFollowerApiCallerDeps {
135
+ socketPath: TelegramBusSocketPathSource;
136
+ instanceId: string;
137
+ createRequestId: () => string;
138
+ getAuthSecret?: () => string | undefined;
139
+ getRegistrationGeneration: () => string | undefined;
140
+ waitForRegistrationGeneration?: (timeoutMs?: number) => Promise<string | undefined>;
141
+ getNowMs?: () => number;
142
+ timeoutMs?: number;
143
+ }
144
+ export interface TelegramBusFollowerRegistrationRuntimeDeps<TContext extends {
145
+ cwd?: string;
146
+ }> {
147
+ instanceId: string;
148
+ createRequestId: () => string;
149
+ protocolIdentity: TelegramBusProtocolIdentity;
150
+ getLeaderAuthSecret?: (leader: {
151
+ busSecret?: string;
152
+ }) => string | undefined;
153
+ setActiveAuthSecret?: (secret: string | undefined) => void;
154
+ followerBusSocketPath?: string;
155
+ getFollowerBusSocketPath?: () => string;
156
+ getLeaderSocketPath?: () => string;
157
+ startReceiving?: () => Promise<void>;
158
+ stopReceiving?: () => Promise<void> | void;
159
+ registrationState?: TelegramBusFollowerRegistrationState;
160
+ isContextActive?: (ctx: TContext) => boolean;
161
+ getProfileKey?: (ctx: TContext) => string | undefined;
162
+ getThreadName?: (ctx: TContext) => string | undefined;
163
+ getNowMs?: () => number;
164
+ getPid?: () => number;
165
+ getProcessBirthId?: () => string;
166
+ getSessionId?: (ctx: TContext) => string | undefined;
167
+ getSessionGeneration?: () => number;
168
+ timeoutMs?: number;
169
+ registrationTimeoutMs?: number;
170
+ registrationRetryAttempts?: number;
171
+ registrationRetryDelayMs?: number;
172
+ heartbeatMs?: number;
173
+ recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
174
+ onHeartbeatFailure?: (error: unknown, ctx: TContext) => Promise<void> | void;
175
+ onRegistered?: (ctx: TContext) => Promise<void> | void;
176
+ onDisplayTitleChanged?: (ctx: TContext) => void;
177
+ }
178
+ export declare function createTelegramManualFollowerProfileKeyResolver(input: {
179
+ getActiveProfileName: () => string | undefined;
180
+ manualFollowerOwnerId: string;
181
+ }): () => string;
182
+ export interface TelegramBusFollowerElection {
183
+ expectedOwner?: TelegramLockEntry;
184
+ }
185
+ export type TelegramBusFollowerPromotionHandler<TContext> = (ctx: TContext, binding: TelegramBusFollowerPromotedBinding, election: TelegramBusFollowerElection) => Promise<boolean>;
186
+ type TelegramBusFollowerWorkspaceAdmissionDeps = {
187
+ getWorkspaceAdmission?: () => Pick<TelegramWorkspaceAdmissionLedger, "acquireAdmission" | "releaseAdmission"> | undefined;
188
+ recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
189
+ };
190
+ export declare function createTelegramBusFollowerPromotionHandler<TContext extends {
191
+ cwd: string;
192
+ }>(input: {
193
+ topicTargetStore: Threads.TelegramTopicTargetStore;
194
+ instanceId: string;
195
+ getActiveProfileName: () => string | undefined;
196
+ getSessionId?: (ctx: TContext) => string | undefined;
197
+ startLeader: (ctx: TContext, election: TelegramBusFollowerElection, onAcquired: () => Promise<void>) => Promise<boolean>;
198
+ recordRuntimeEvent: (category: string, error: unknown, details?: Record<string, unknown>) => void;
199
+ getNowMs?: () => number;
200
+ getPid?: () => number;
201
+ getWorkspaceAdmission?: TelegramBusFollowerWorkspaceAdmissionDeps["getWorkspaceAdmission"];
202
+ }): TelegramBusFollowerPromotionHandler<TContext>;
203
+ export interface TelegramBusFollowerTargetReplacementHandlerDeps<TContext> {
204
+ topicTargetStore: Pick<Threads.TelegramTopicTargetStore, "load" | "list" | "markStaleByTarget" | "upsert" | "persist">;
205
+ registrationState: Pick<TelegramBusFollowerRegistrationState, "getTarget" | "getSlot" | "setRegistered" | "getGeneration">;
206
+ instanceId: string;
207
+ getManualFollowerProfileKey: () => string;
208
+ manualFollowerOwnerId: string;
209
+ getSyncState: () => Sync.TelegramSyncState;
210
+ setSyncState: (state: Sync.TelegramSyncState) => void;
211
+ getNowMs?: () => number;
212
+ updateStatus: (ctx: TContext) => void;
213
+ recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
214
+ getWorkspaceAdmission?: TelegramBusFollowerWorkspaceAdmissionDeps["getWorkspaceAdmission"];
215
+ }
216
+ export type TelegramBusFollowerLeaderState = {
217
+ kind: "inactive";
218
+ } | {
219
+ kind: "active-here";
220
+ lock: TelegramBusFollowerLeaderLock;
221
+ } | {
222
+ kind: "active-elsewhere";
223
+ lock: TelegramBusFollowerLeaderLock;
224
+ } | {
225
+ kind: "stale";
226
+ lock: TelegramBusFollowerLeaderLock;
227
+ };
228
+ export type TelegramBusFollowerLeaderLock = TelegramLockEntry;
229
+ export interface TelegramBusFollowerPromotedBinding {
230
+ target?: TelegramTarget;
231
+ slot?: string;
232
+ threadName?: string;
233
+ }
234
+ export interface TelegramBusFollowerHeartbeatRecoveryHandlerDeps<TContext> {
235
+ registrationState: Pick<TelegramBusFollowerRegistrationState, "getTarget" | "getSlot" | "getThreadName" | "getEligibleElectionSlots" | "beginRecovery" | "setRegistered">;
236
+ getRegistrationRuntime: () => TelegramBusFollowerRegistrationRuntime<TContext>;
237
+ getLeaderState: () => TelegramBusFollowerLeaderState;
238
+ setLifecyclePhase: (phase: "electing" | undefined) => void;
239
+ updateStatus: (ctx: TContext) => void;
240
+ promoteToLeader: (ctx: TContext, binding: TelegramBusFollowerPromotedBinding, election: TelegramBusFollowerElection) => Promise<boolean>;
241
+ sleep?: (ms: number) => Promise<void>;
242
+ scheduleRetry?: (retry: () => void, delayMs: number) => void;
243
+ getActiveContext?: () => TContext | undefined;
244
+ promotionGraceMs?: number;
245
+ recordRuntimeEvent: (category: string, error: unknown, details?: Record<string, unknown>) => void;
246
+ }
247
+ export interface TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext> {
248
+ socketPath: TelegramBusSocketPathSource;
249
+ instanceId: string;
250
+ getAuthSecret?: () => string | undefined;
251
+ getRegistrationGeneration: () => string | undefined;
252
+ getRecipientBindingKey: () => string | undefined;
253
+ durableAdmission: TelegramBusFollowerDurableAdmissionPort<TContext>;
254
+ sourceReferenceAdmission?: TelegramBusFollowerDurableAdmissionPort<TContext>;
255
+ isSourceReferenceAdmissionEnabled?: () => boolean;
256
+ hasAuthenticatedSourceReferenceTransport?: () => boolean;
257
+ getContext: () => TContext | undefined;
258
+ handleInputCustodyHandoff?: (envelope: Extract<TelegramBusEnvelope, {
259
+ kind: "leader.offerInputCustodyHandoff";
260
+ }>, ctx: TContext) => Promise<unknown> | unknown;
261
+ handleQueueHandoff?: (envelope: Extract<TelegramBusEnvelope, {
262
+ kind: "leader.offerQueueHandoff";
263
+ }>, ctx: TContext) => Promise<TelegramQueueHandoffStageResult> | TelegramQueueHandoffStageResult;
264
+ handleReplaceTarget?: (input: {
265
+ target: TelegramTarget & {
266
+ threadId: number;
267
+ };
268
+ oldTarget?: TelegramTarget & {
269
+ threadId: number;
270
+ };
271
+ reason: "thread-restore";
272
+ registrationGeneration: string;
273
+ }, ctx: TContext) => Promise<void> | void;
274
+ recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
275
+ }
276
+ export interface TelegramBusFollowerRuntimeAssembly<TContext> {
277
+ receiver: TelegramBusForwardedUpdateReceiverRuntime;
278
+ registration: TelegramBusFollowerRegistrationRuntime<TContext>;
279
+ }
280
+ export interface TelegramBusFollowerRuntimeAssemblyPorts<TContext extends {
281
+ cwd?: string;
282
+ }> {
283
+ instanceId: string;
284
+ registrationState: TelegramBusFollowerRegistrationState;
285
+ recordRuntimeEvent: (category: string, error: unknown, details?: Record<string, unknown>) => void;
286
+ receiver: Omit<TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext>, "handleReplaceTarget" | "instanceId" | "recordRuntimeEvent" | "getRegistrationGeneration">;
287
+ targetReplacement: Omit<TelegramBusFollowerTargetReplacementHandlerDeps<TContext>, "registrationState" | "instanceId" | "recordRuntimeEvent">;
288
+ recovery: Omit<TelegramBusFollowerHeartbeatRecoveryHandlerDeps<TContext>, "getRegistrationRuntime" | "registrationState" | "recordRuntimeEvent">;
289
+ registration: Omit<TelegramBusFollowerRegistrationRuntimeDeps<TContext>, "startReceiving" | "stopReceiving" | "onHeartbeatFailure" | "instanceId" | "registrationState" | "recordRuntimeEvent" | "protocolIdentity"> & {
290
+ protocolIdentity: TelegramBusProtocolIdentity;
291
+ };
292
+ }
293
+ export declare function createTelegramBusFollowerRuntimeAssembly<TContext extends {
294
+ cwd?: string;
295
+ }>(ports: TelegramBusFollowerRuntimeAssemblyPorts<TContext>): TelegramBusFollowerRuntimeAssembly<TContext>;
296
+ export declare function createTelegramBusFollowerTargetReplacementHandler<TContext>(deps: TelegramBusFollowerTargetReplacementHandlerDeps<TContext>): NonNullable<TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext>["handleReplaceTarget"]>;
297
+ export declare function createTelegramBusFollowerClientRuntime<TContext, TReactionUpdate, TCallbackQuery, TMessage = unknown>(deps: TelegramBusFollowerClientRuntimeDeps<TMessage>): {
298
+ createRequestId: () => string;
299
+ callApi: (method: string, args: unknown[]) => Promise<unknown>;
300
+ agentMessages: {
301
+ resolveTarget: (selector: TelegramBusAgentTargetSelector) => Promise<TelegramTarget & {
302
+ threadId: number;
303
+ }>;
304
+ routeMessage: (message: TelegramBusAgentMessage) => Promise<void>;
305
+ };
306
+ foreignOwnedUpdateForwarder: {
307
+ forwardCallback: (input: {
308
+ query: TCallbackQuery;
309
+ ownership: TelegramBusForwardOwnership;
310
+ ctx: TContext;
311
+ }) => Promise<import("./bus.ts").TelegramBusForeignUpdateSettlement>;
312
+ forwardReaction: (input: {
313
+ reactionUpdate: TReactionUpdate;
314
+ ownership: TelegramBusForwardOwnership;
315
+ ctx: TContext;
316
+ }) => Promise<import("./bus.ts").TelegramBusForeignUpdateSettlement>;
317
+ forwardMessage: (input: {
318
+ message: TMessage;
319
+ ownership: TelegramBusForwardOwnership;
320
+ ctx: TContext;
321
+ }) => Promise<import("./bus.ts").TelegramBusForeignUpdateSettlement>;
322
+ forwardEditedMessage: (input: {
323
+ message: TMessage;
324
+ ownership: TelegramBusForwardOwnership;
325
+ ctx: TContext;
326
+ }) => Promise<import("./bus.ts").TelegramBusForeignUpdateSettlement>;
327
+ };
328
+ queueHandoff: (input: {
329
+ recipientInstanceId: string;
330
+ recipientRegistrationGeneration: string;
331
+ donorProcessId: number;
332
+ donorProcessBirthId: string;
333
+ donorSessionGeneration: number;
334
+ donorAcquisitionId: string;
335
+ donorAcquiredAtMs: number;
336
+ handoffToken: string;
337
+ payload: TelegramQueueHandoffPayload;
338
+ }) => Promise<TelegramQueueHandoffStageResult>;
339
+ targetController: {
340
+ replaceTarget: (input: {
341
+ follower: import("./bus.ts").TelegramBusFollowerView;
342
+ target: TelegramTarget & {
343
+ threadId: number;
344
+ };
345
+ oldTarget?: TelegramTarget & {
346
+ threadId: number;
347
+ };
348
+ reason: "thread-restore";
349
+ }) => Promise<boolean>;
350
+ };
351
+ };
352
+ export declare function createTelegramBusFollowerQueueHandoffClient(deps: TelegramBusFollowerApiCallerDeps): (input: {
353
+ recipientInstanceId: string;
354
+ recipientRegistrationGeneration: string;
355
+ donorProcessId: number;
356
+ donorProcessBirthId: string;
357
+ donorSessionGeneration: number;
358
+ donorAcquisitionId: string;
359
+ donorAcquiredAtMs: number;
360
+ handoffToken: string;
361
+ payload: TelegramQueueHandoffPayload;
362
+ }) => Promise<TelegramQueueHandoffStageResult>;
363
+ export declare function createTelegramBusAgentMessageClient(deps: TelegramBusFollowerApiCallerDeps): {
364
+ resolveTarget: (selector: TelegramBusAgentTargetSelector) => Promise<TelegramTarget & {
365
+ threadId: number;
366
+ }>;
367
+ routeMessage: (message: TelegramBusAgentMessage) => Promise<void>;
368
+ };
369
+ export declare function createTelegramBusFollowerApiCaller(deps: TelegramBusFollowerApiCallerDeps): (method: string, args: unknown[]) => Promise<unknown>;
370
+ export declare function createTelegramBusFollowerSessionReplacementSuspender(deps: TelegramBusFollowerSessionReplacementSuspenderDeps): () => Promise<void>;
371
+ export declare function createTelegramBusFollowerSessionRefreshHook<TContext>(deps: TelegramBusFollowerSessionRefreshHookDeps<TContext>): (_event: unknown, ctx: TContext) => Promise<void>;
372
+ export declare function createTelegramBusFollowerControlState(): TelegramBusFollowerControlState;
373
+ export declare function createTelegramBusFollowerRegistrationState(options?: {
374
+ onAvailabilityChanged?: () => void;
375
+ }): TelegramBusFollowerRegistrationState;
376
+ export declare function createTelegramBusFollowerHeartbeatRecoveryHandler<TContext>(deps: TelegramBusFollowerHeartbeatRecoveryHandlerDeps<TContext>): (error: unknown, ctx: TContext) => Promise<void>;
377
+ export declare function createTelegramBusFollowerRegistrationRuntime<TContext extends {
378
+ cwd?: string;
379
+ }>(deps: TelegramBusFollowerRegistrationRuntimeDeps<TContext>): TelegramBusFollowerRegistrationRuntime<TContext>;
380
+ /** Bind source-owned sender checks to the journal's already-admitted synchronous v1 hook. */
381
+ export declare function createTelegramBusFollowerPairedAdmission(deps: {
382
+ profileName: string;
383
+ tokenSha256: string;
384
+ configStore: Pick<TelegramConfigStore, "withPairedUserAdmission">;
385
+ assertExecutionCurrent: () => void;
386
+ }): NonNullable<TelegramUpdateJournalStoreOptions["withPairedAdmission"]>;
387
+ export declare function prepareTelegramBusFollowerJournaledUpdateForExecution<TUpdate extends {
388
+ message?: unknown;
389
+ } & Record<string, unknown>>(update: TUpdate, prepareForwardedMessage: (message: NonNullable<TUpdate["message"]>, position: "comment" | "forward") => void): TUpdate;
390
+ export declare function createTelegramBusFollowerDurableAdmissionRuntime<TContext>(deps: {
391
+ journal: {
392
+ appendBatch(updates: readonly ({
393
+ update_id: number;
394
+ } & Record<string, unknown>)[]): unknown;
395
+ };
396
+ signalWorker: (ctx: TContext) => void;
397
+ }): TelegramBusFollowerDurableAdmissionPort<TContext>;
398
+ export interface TelegramBusFollowerInputCustodyBundle<TContext> {
399
+ acceptHandoff(input: {
400
+ sourceRecoveryKey: string;
401
+ recipientBindingKey: string;
402
+ source: {
403
+ journalBindingKey: string;
404
+ tokenSha256: string;
405
+ updateId: number;
406
+ };
407
+ handoffId: string;
408
+ }, ctx: TContext): unknown;
409
+ wakeSource(input: TelegramBusFollowerDurableAdmissionResult & {
410
+ recipientBindingKey: string;
411
+ sourceRecoveryKey: string;
412
+ sourceClaim: {
413
+ acquisitionId: string;
414
+ handoffId: string;
415
+ };
416
+ }, ctx: TContext): void;
417
+ resolveForwardReference(input: {
418
+ sourceUpdateId: number;
419
+ recipientBindingKey: string;
420
+ }): {
421
+ sourceRecoveryKey: string;
422
+ source: {
423
+ updateId: number;
424
+ owner: {
425
+ acquisitionId: string;
426
+ handoffId: string;
427
+ };
428
+ };
429
+ } | undefined;
430
+ }
431
+ export declare function createTelegramBusFollowerInputCustodyPorts<TContext>(deps: {
432
+ getInputCustodyBus(): TelegramBusFollowerInputCustodyBundle<TContext> | undefined;
433
+ }): {
434
+ isSourceReferenceAdmissionEnabled: () => boolean;
435
+ handleInputCustodyHandoff(envelope: Extract<TelegramBusEnvelope, {
436
+ kind: "leader.offerInputCustodyHandoff";
437
+ }>, ctx: TContext): unknown;
438
+ sourceReferenceAdmission: TelegramBusFollowerDurableAdmissionPort<TContext>;
439
+ resolveInputCustodyReference(input: {
440
+ sourceUpdateId: number;
441
+ recipientBindingKey: string;
442
+ }): {
443
+ sourceRecoveryKey: string;
444
+ source: {
445
+ updateId: number;
446
+ owner: {
447
+ acquisitionId: string;
448
+ handoffId: string;
449
+ };
450
+ };
451
+ } | undefined;
452
+ };
453
+ export declare function createTelegramBusFollowerSourceReferenceAdmissionRuntime<TContext>(deps: {
454
+ wakeSource: (input: TelegramBusFollowerDurableAdmissionResult & {
455
+ recipientBindingKey: string;
456
+ sourceRecoveryKey: string;
457
+ sourceClaim: {
458
+ acquisitionId: string;
459
+ handoffId: string;
460
+ };
461
+ }, ctx: TContext) => Promise<void> | void;
462
+ }): TelegramBusFollowerDurableAdmissionPort<TContext>;
463
+ export declare function createTelegramBusForwardedUpdateReceiverRuntime<TContext>(deps: TelegramBusForwardedUpdateReceiverRuntimeDeps<TContext>): TelegramBusForwardedUpdateReceiverRuntime;
464
+ export {};