@llblab/pi-telegram 0.11.2 → 0.12.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.
package/index.ts CHANGED
@@ -5,17 +5,11 @@
5
5
  */
6
6
 
7
7
  import * as Api from "./lib/api.ts";
8
+ import * as Bindings from "./lib/bindings.ts";
8
9
  import * as CommandTemplates from "./lib/command-templates.ts";
9
10
  import * as Commands from "./lib/commands.ts";
10
11
  import * as Config from "./lib/config.ts";
11
- import {
12
- createTelegramExtensionSectionRegistry,
13
- setGlobalTelegramSectionRegistry,
14
- type TelegramSectionRegistry,
15
- } from "./lib/extension-sections.ts";
16
- import { createTelegramExternalHandleUpdate } from "./lib/external-handlers.ts";
17
- import * as InboundHandlers from "./lib/inbound-handlers.ts";
18
- import * as Keyboard from "./lib/keyboard.ts";
12
+ import * as Inbound from "./lib/inbound.ts";
19
13
  import * as Lifecycle from "./lib/lifecycle.ts";
20
14
  import * as Locks from "./lib/locks.ts";
21
15
  import * as Media from "./lib/media.ts";
@@ -23,27 +17,23 @@ import * as MenuQueue from "./lib/menu-queue.ts";
23
17
  import * as MenuSettings from "./lib/menu-settings.ts";
24
18
  import * as Menu from "./lib/menu.ts";
25
19
  import * as Model from "./lib/model.ts";
26
- import * as OutboundAttachments from "./lib/outbound-attachments.ts";
27
- import * as OutboundHandlers from "./lib/outbound-handlers.ts";
20
+ import * as Outbound from "./lib/outbound.ts";
28
21
  import * as Pi from "./lib/pi.ts";
29
22
  import * as Polling from "./lib/polling.ts";
30
23
  import * as Preview from "./lib/preview.ts";
31
24
  import * as PromptTemplates from "./lib/prompt-templates.ts";
32
- import * as Prompts from "./lib/prompts.ts";
33
25
  import * as Queue from "./lib/queue.ts";
34
26
  import * as Replies from "./lib/replies.ts";
35
27
  import * as Routing from "./lib/routing.ts";
36
28
  import * as Runtime from "./lib/runtime.ts";
37
- import * as Setup from "./lib/setup.ts";
29
+ import * as Sections from "./lib/sections.ts";
38
30
  import * as Status from "./lib/status.ts";
39
31
  import * as TextGroups from "./lib/text-groups.ts";
40
32
  import * as TimeInjection from "./lib/time-injection.ts";
33
+ import * as Updates from "./lib/updates.ts";
41
34
  import * as Voice from "./lib/voice.ts";
42
35
 
43
- const VOICE_EVENT_RECORDER_KEY = "__piTelegramVoiceEventRecorder__";
44
-
45
36
  type ActivePiModel = NonNullable<Pi.ExtensionContext["model"]>;
46
- type RuntimeTelegramQueueItem = Queue.TelegramQueueItem<Pi.ExtensionContext>;
47
37
 
48
38
  // --- Extension Runtime ---
49
39
 
@@ -59,31 +49,8 @@ export default function (pi: Pi.ExtensionAPI) {
59
49
  const bridgeRuntime = Runtime.createTelegramBridgeRuntime();
60
50
  const { abort, lifecycle, queue, setup, typing } = bridgeRuntime;
61
51
  const configStore = Config.createTelegramConfigStore();
62
- Config.setGlobalTelegramConfigRuntime({
63
- updateVoiceConfig(voice) {
64
- const current = configStore.get();
65
- const next = {
66
- ...current,
67
- voice: { ...(current.voice ?? {}), ...voice },
68
- };
69
- configStore.set(next);
70
- void configStore.persist(next);
71
- },
72
- });
73
- const isProactivePushEnabled =
74
- Config.createTelegramProactivePushChecker(configStore);
75
- const setProactivePushEnabled =
76
- Config.createTelegramProactivePushSetter(configStore);
77
- const getVoiceReplyMode =
78
- Config.createTelegramVoiceReplyModeGetter(configStore);
79
- const isVoiceReplyModeConfigured =
80
- Config.createTelegramVoiceReplyModeConfiguredChecker(configStore);
81
- const setVoiceReplyMode =
82
- Config.createTelegramVoiceReplyModeSetter(configStore);
83
- const getTimeInjectionMode =
84
- Config.createTelegramTimeInjectionModeGetter(configStore);
85
- const setTimeInjectionMode =
86
- Config.createTelegramTimeInjectionModeSetter(configStore);
52
+ Config.bindGlobalTelegramConfigRuntime(configStore);
53
+ const configControls = Config.createTelegramConfigControls(configStore);
87
54
  const lockRuntime = Locks.createTelegramLockRuntime<Pi.ExtensionContext>();
88
55
  const lockOwnershipGuard =
89
56
  Locks.createTelegramLockOwnershipGuard(lockRuntime);
@@ -93,15 +60,13 @@ export default function (pi: Pi.ExtensionAPI) {
93
60
  getActiveTurnChatId: activeTurnRuntime.getChatId,
94
61
  getAllowedUserId: configStore.getAllowedUserId,
95
62
  });
96
- const buttonActionStore = OutboundHandlers.createTelegramButtonActionStore();
63
+ const buttonActionStore = Outbound.createTelegramButtonActionStore();
97
64
  const pendingModelSwitchStore =
98
65
  Model.createPendingModelSwitchStore<
99
66
  Model.ScopedTelegramModel<ActivePiModel>
100
67
  >();
101
68
  const modelMenuRuntime = Menu.createTelegramModelMenuRuntime<ActivePiModel>();
102
- const sectionRegistry: TelegramSectionRegistry =
103
- createTelegramExtensionSectionRegistry();
104
- setGlobalTelegramSectionRegistry(sectionRegistry);
69
+ const sectionRegistry = Sections.createAndBindTelegramSectionRegistry();
105
70
 
106
71
  const runtimeEvents = Status.createTelegramRuntimeEventRecorder({
107
72
  getBotToken: configStore.getBotToken,
@@ -111,8 +76,7 @@ export default function (pi: Pi.ExtensionAPI) {
111
76
  getConfig: Config.createTelegramTimeConfigGetter(configStore),
112
77
  recordRuntimeEvent,
113
78
  });
114
- (globalThis as Record<string, unknown>)[VOICE_EVENT_RECORDER_KEY] =
115
- recordRuntimeEvent;
79
+ Outbound.bindTelegramRuntimeEventRecorder(recordRuntimeEvent);
116
80
  const getContextModel = Pi.getExtensionContextModel;
117
81
  const isIdle = Pi.isExtensionContextIdle;
118
82
  const hasPendingMessages = Pi.hasExtensionContextPendingMessages;
@@ -136,7 +100,7 @@ export default function (pi: Pi.ExtensionAPI) {
136
100
  const { getStatusLines, updateStatus } =
137
101
  Status.createTelegramBridgeStatusRuntime<
138
102
  Pi.ExtensionContext,
139
- RuntimeTelegramQueueItem
103
+ Queue.TelegramQueueItem<Pi.ExtensionContext>
140
104
  >({
141
105
  getConfig: configStore.get,
142
106
  isPollingActive: Polling.createTelegramPollingActivityReader(
@@ -153,28 +117,23 @@ export default function (pi: Pi.ExtensionAPI) {
153
117
  getRecentRuntimeEvents: runtimeEvents.getEvents,
154
118
  getRuntimeLockState: lockRuntime.getStatusLabel,
155
119
  });
156
- const currentModelRuntime = Model.createCurrentModelRuntime<
157
- Pi.ExtensionContext,
158
- ActivePiModel
159
- >({
120
+ const currentModelRuntime = Model.createCurrentModelRuntime({
160
121
  getContextModel,
161
122
  updateStatus,
162
123
  });
163
- const queueMutationRuntime =
164
- Queue.createTelegramQueueMutationController<Pi.ExtensionContext>({
165
- ...telegramQueueStore,
166
- getNextPriorityReactionOrder: queue.getNextPriorityReactionOrder,
167
- incrementNextPriorityReactionOrder:
168
- queue.incrementNextPriorityReactionOrder,
169
- updateStatus,
170
- });
171
- const inboundHandlerRuntime =
172
- InboundHandlers.createTelegramInboundHandlerRuntime<Pi.ExtensionContext>({
173
- getHandlers: configStore.getInboundHandlers,
174
- execCommand: CommandTemplates.execCommandTemplate,
175
- getCwd: Pi.getExtensionContextCwd,
176
- recordRuntimeEvent,
177
- });
124
+ const queueMutationRuntime = Queue.createTelegramQueueMutationController({
125
+ ...telegramQueueStore,
126
+ getNextPriorityReactionOrder: queue.getNextPriorityReactionOrder,
127
+ incrementNextPriorityReactionOrder:
128
+ queue.incrementNextPriorityReactionOrder,
129
+ updateStatus,
130
+ });
131
+ const inboundHandlerRuntime = Inbound.createTelegramInboundHandlerRuntime({
132
+ getHandlers: configStore.getInboundHandlers,
133
+ execCommand: CommandTemplates.execCommandTemplate,
134
+ getCwd: Pi.getExtensionContextCwd,
135
+ recordRuntimeEvent,
136
+ });
178
137
 
179
138
  // --- Telegram API ---
180
139
 
@@ -199,36 +158,32 @@ export default function (pi: Pi.ExtensionAPI) {
199
158
  recordRuntimeEvent,
200
159
  });
201
160
 
202
- // --- Message Delivery & Preview ---
161
+ // --- Message Delivery ---
203
162
 
204
163
  const sendGuestReply = Replies.createGuestMarkdownReplySender({
205
164
  renderTelegramMessage: Replies.renderTelegramMessage,
206
165
  answerGuestQuery,
207
166
  });
208
167
 
209
- const promptDispatchRuntime =
210
- Runtime.createTelegramPromptDispatchRuntime<Pi.ExtensionContext>({
211
- lifecycle,
212
- typing,
213
- getDefaultChatId: activeTurnRuntime.getChatId,
214
- sendTypingAction,
215
- updateStatus,
216
- recordRuntimeEvent,
217
- });
168
+ const promptDispatchRuntime = Runtime.createTelegramPromptDispatchRuntime({
169
+ lifecycle,
170
+ typing,
171
+ getDefaultChatId: proactivePushChatIdGetter,
172
+ sendTypingAction,
173
+ updateStatus,
174
+ recordRuntimeEvent,
175
+ });
218
176
 
219
- // --- Reply Runtime Wiring ---
177
+ // --- Reply Runtime & Preview ---
220
178
 
221
- const replyRuntime =
222
- Replies.createTelegramRenderedMessageDeliveryRuntime<Keyboard.TelegramInlineKeyboardMarkup>(
223
- {
224
- sendMessage,
225
- editMessage: editTelegramMessageText,
226
- },
227
- );
179
+ const replyRuntime = Replies.createTelegramRenderedMessageDeliveryRuntime({
180
+ sendMessage,
181
+ editMessage: editTelegramMessageText,
182
+ });
228
183
  const { replyTransport, editInteractiveMessage, sendInteractiveMessage } =
229
184
  replyRuntime;
230
185
  const { sendTextReply, sendMarkdownReply } =
231
- OutboundHandlers.createTelegramOutboundTextReplyRuntime({
186
+ Outbound.createTelegramOutboundTextReplyRuntime({
232
187
  sendTextReply: replyRuntime.sendTextReply,
233
188
  sendMarkdownReply: replyRuntime.sendMarkdownReply,
234
189
  execCommand: CommandTemplates.execCommandTemplate,
@@ -236,7 +191,7 @@ export default function (pi: Pi.ExtensionAPI) {
236
191
  recordRuntimeEvent,
237
192
  });
238
193
  const dispatchNextQueuedTelegramTurn =
239
- Queue.createTelegramQueueDispatchRuntime<Pi.ExtensionContext>({
194
+ Queue.createTelegramQueueDispatchRuntime({
240
195
  ...telegramQueueStore,
241
196
  isCompactionInProgress: lifecycle.isCompactionInProgress,
242
197
  hasActiveTurn: activeTurnRuntime.has,
@@ -250,10 +205,7 @@ export default function (pi: Pi.ExtensionAPI) {
250
205
  ...promptDispatchRuntime,
251
206
  sendUserMessage,
252
207
  }).dispatchNext;
253
- const previewRuntime = Preview.createTelegramAssistantPreviewRuntime<
254
- unknown,
255
- Keyboard.TelegramInlineKeyboardMarkup
256
- >({
208
+ const previewRuntime = Preview.createTelegramAssistantPreviewRuntime({
257
209
  getActiveTurn: activeTurnRuntime.get,
258
210
  isAssistantMessage: Replies.isAssistantAgentMessage,
259
211
  getMessageText: Replies.getAgentMessageText,
@@ -266,20 +218,17 @@ export default function (pi: Pi.ExtensionAPI) {
266
218
  ...replyTransport,
267
219
  });
268
220
  const { finalizeMarkdownPreview } =
269
- OutboundHandlers.createTelegramOutboundTextPreviewRuntime({
221
+ Outbound.createTelegramOutboundTextPreviewRuntime({
270
222
  finalizeMarkdownPreview: previewRuntime.finalizeMarkdown,
271
223
  execCommand: CommandTemplates.execCommandTemplate,
272
224
  getHandlers: configStore.getOutboundHandlers,
273
225
  recordRuntimeEvent,
274
226
  });
275
227
 
276
- // --- Bridge Setup ---
228
+ // --- Model And Menu Setup ---
277
229
 
278
230
  const modelSwitchController =
279
- Model.createTelegramModelSwitchControllerRuntime<
280
- Pi.ExtensionContext,
281
- Model.ScopedTelegramModel<ActivePiModel>
282
- >({
231
+ Model.createTelegramModelSwitchControllerRuntime({
283
232
  isIdle,
284
233
  getPendingModelSwitch: pendingModelSwitchStore.get,
285
234
  setPendingModelSwitch: pendingModelSwitchStore.set,
@@ -299,10 +248,7 @@ export default function (pi: Pi.ExtensionAPI) {
299
248
  getCommands,
300
249
  reservedCommandNames: Commands.TELEGRAM_RESERVED_COMMAND_NAMES,
301
250
  });
302
- const menuActions = Menu.createTelegramMenuActionRuntimeWithStateBuilder<
303
- ActivePiModel,
304
- Pi.ExtensionContext
305
- >({
251
+ const menuActions = Menu.createTelegramMenuActionRuntimeWithStateBuilder({
306
252
  runtime: modelMenuRuntime,
307
253
  createSettingsManager: Pi.createSettingsManager,
308
254
  getActiveModel: currentModelRuntime.get,
@@ -323,14 +269,14 @@ export default function (pi: Pi.ExtensionAPI) {
323
269
  sendInteractiveMessage,
324
270
  sectionRegistry,
325
271
 
326
- // Used by the menu/status system to know whether the current turn is a voice reply
272
+ // Menu/status UI uses this to reflect whether the active Telegram turn expects voice delivery.
327
273
  isVoiceReplyActive: function () {
328
274
  const turn = activeTurnRuntime.get();
329
275
  return Voice.isVoiceTurn(turn);
330
276
  },
331
277
  });
332
278
 
333
- // --- Queue Menu ---
279
+ // --- Queue And Settings Menus ---
334
280
 
335
281
  const getQueueMenuState = Menu.createTelegramModelMenuStateBuilder({
336
282
  runtime: modelMenuRuntime,
@@ -357,26 +303,14 @@ export default function (pi: Pi.ExtensionAPI) {
357
303
  editInteractiveMessage,
358
304
  sendInteractiveMessage,
359
305
  answerCallbackQuery,
360
- isProactivePushEnabled,
361
- getVoiceReplyMode,
362
- isVoiceReplyModeConfigured,
363
- getTimeInjectionMode,
364
- setProactivePushEnabled,
365
- setVoiceReplyMode,
366
- setTimeInjectionMode,
306
+ ...configControls,
367
307
  },
368
308
  sectionRegistry,
369
309
  );
370
310
 
371
311
  // --- Polling ---
372
312
 
373
- const inboundRouteRuntime = Routing.createTelegramInboundRouteRuntime<
374
- Api.TelegramUpdate,
375
- Api.TelegramMessage,
376
- Api.TelegramCallbackQuery,
377
- Pi.ExtensionContext,
378
- ActivePiModel
379
- >({
313
+ const inboundRouteRuntime = Routing.createTelegramInboundRouteRuntime({
380
314
  configStore,
381
315
  bridgeRuntime,
382
316
  activeTurnRuntime,
@@ -425,17 +359,14 @@ export default function (pi: Pi.ExtensionAPI) {
425
359
  compact,
426
360
  recordRuntimeEvent,
427
361
  });
428
- const pollingRuntime = Polling.createTelegramPollingControllerRuntime<
429
- Api.TelegramUpdate,
430
- Pi.ExtensionContext
431
- >({
362
+ const pollingRuntime = Polling.createTelegramPollingControllerRuntime({
432
363
  state: pollingControllerState,
433
364
  getConfig: configStore.get,
434
365
  hasBotToken: configStore.hasBotToken,
435
366
  deleteWebhook,
436
367
  getUpdates,
437
368
  persistConfig: configStore.persist,
438
- handleUpdate: createTelegramExternalHandleUpdate({
369
+ handleUpdate: Updates.createTelegramUpdateHandle({
439
370
  defaultHandle: inboundRouteRuntime.handleUpdate,
440
371
  }),
441
372
  stopTypingLoop: typing.stop,
@@ -450,11 +381,7 @@ export default function (pi: Pi.ExtensionAPI) {
450
381
  updateStatus,
451
382
  recordRuntimeEvent,
452
383
  });
453
- const queueSessionLifecycle = Queue.createTelegramSessionLifecycleRuntime<
454
- Pi.ExtensionContext,
455
- RuntimeTelegramQueueItem,
456
- ActivePiModel
457
- >({
384
+ const queueSessionLifecycle = Queue.createTelegramSessionLifecycleRuntime({
458
385
  getCurrentModel: getContextModel,
459
386
  loadConfig: configStore.load,
460
387
  setQueuedItems: telegramQueueStore.setQueuedItems,
@@ -487,131 +414,50 @@ export default function (pi: Pi.ExtensionAPI) {
487
414
 
488
415
  // --- Extension API Bindings ---
489
416
 
490
- OutboundAttachments.registerTelegramOutboundAttachmentTool(pi, {
491
- getActiveTurn: activeTurnRuntime.get,
492
- recordRuntimeEvent,
493
- });
494
-
495
- Commands.registerTelegramBridgeCommands(pi, {
496
- promptForConfig: Setup.createTelegramSetupPromptRuntime({
497
- getConfig: configStore.get,
498
- setConfig: configStore.set,
499
- setupGuard: setup,
500
- getMe: Api.fetchTelegramBotIdentity,
501
- persistConfig: configStore.persist,
502
- startPolling: lockedPollingRuntime.start,
503
- updateStatus,
504
- recordRuntimeEvent,
505
- }),
417
+ Bindings.registerTelegramCommandsAndTools({
418
+ pi,
419
+ configStore,
420
+ setup,
421
+ activeTurnRuntime,
422
+ lockedPollingRuntime,
506
423
  getStatusLines,
507
- reloadConfig: configStore.load,
508
- hasBotToken: configStore.hasBotToken,
509
- startPolling: lockedPollingRuntime.start,
510
- stopPolling: lockedPollingRuntime.stop,
511
424
  updateStatus,
425
+ recordRuntimeEvent,
512
426
  });
513
427
 
514
428
  // --- Lifecycle Hooks ---
515
429
 
516
- const agentEndResetter = Runtime.createTelegramAgentEndResetter({
430
+ Bindings.registerTelegramLifecycleRuntimeHooks({
431
+ pi,
432
+ sessionLifecycleRuntime: {
433
+ ...sessionLifecycleRuntime,
434
+ onModelSelect: currentModelRuntime.onModelSelect,
435
+ },
436
+ queueSessionLifecycle,
437
+ configStore,
517
438
  abort,
518
439
  typing,
519
- clearActiveTurn: activeTurnRuntime.clear,
520
- resetToolExecutions: lifecycle.resetActiveToolExecutions,
521
- clearPendingModelSwitch: modelSwitchController.clearPendingSwitch,
522
- clearDispatchPending: lifecycle.clearDispatchPending,
523
- });
524
- const queuedAttachmentSender =
525
- OutboundAttachments.createTelegramQueuedOutboundAttachmentSender({
526
- sendMultipart: callMultipart,
527
- sendTextReply,
528
- recordRuntimeEvent,
529
- });
530
- const outboundReplyPlanner =
531
- OutboundHandlers.createTelegramOutboundReplyPlanner(buttonActionStore);
532
- const outboundReplyArtifactSender =
533
- OutboundHandlers.createTelegramOutboundReplyArtifactSender({
534
- execCommand: CommandTemplates.execCommandTemplate,
535
- sendMultipart: callMultipart,
536
- sendTextReply,
537
- sendChatAction,
538
- sendRecordVoiceAction,
539
- getHandlers: configStore.getOutboundHandlers,
540
- recordRuntimeEvent,
541
- });
542
- const agentLifecycleHooks = Queue.createTelegramAgentLifecycleHooks<
543
- Queue.PendingTelegramTurn,
544
- Pi.ExtensionContext,
545
- unknown,
546
- Keyboard.TelegramInlineKeyboardMarkup
547
- >({
548
- setAbortHandler: Runtime.createTelegramContextAbortHandlerSetter(abort),
549
- getQueuedItems: telegramQueueStore.getQueuedItems,
550
- hasPendingDispatch: lifecycle.hasDispatchPending,
551
- hasActiveTurn: activeTurnRuntime.has,
552
- resetToolExecutions: lifecycle.resetActiveToolExecutions,
553
- resetPendingModelSwitch: modelSwitchController.clearPendingSwitch,
554
- setQueuedItems: telegramQueueStore.setQueuedItems,
555
- clearDispatchPending: lifecycle.clearDispatchPending,
556
- setActiveTurn: activeTurnRuntime.set,
557
- createPreviewState: previewRuntime.resetState,
558
- startTypingLoop: promptDispatchRuntime.startTypingLoop,
559
- updateStatus,
560
- getActiveTurn: activeTurnRuntime.get,
561
- extractAssistant: Replies.extractLatestAssistantMessageText,
562
- getPreserveQueuedTurnsAsHistory:
563
- lifecycle.shouldPreserveQueuedTurnsAsHistory,
564
- resetRuntimeState: agentEndResetter,
565
- dispatchNextQueuedTelegramTurn,
566
- requestDeferredDispatchNextQueuedTelegramTurn:
567
- deferredQueueDispatchRuntime.request,
568
- clearPreview: previewRuntime.clear,
569
- setPreviewPendingText: previewRuntime.setPendingText,
570
- finalizeMarkdownPreview,
440
+ lifecycle,
441
+ activeTurnRuntime,
442
+ telegramQueueStore,
443
+ modelSwitchController,
444
+ previewRuntime,
445
+ promptDispatchRuntime,
446
+ deferredQueueDispatchRuntime,
447
+ lockOwnershipGuard,
448
+ buttonActionStore,
449
+ callMultipart,
450
+ sendChatAction,
451
+ sendRecordVoiceAction,
571
452
  sendMarkdownReply,
572
453
  sendTextReply,
573
- sendQueuedAttachments: queuedAttachmentSender,
454
+ dispatchNextQueuedTelegramTurn,
574
455
  answerGuestQuery,
575
456
  sendGuestReply,
576
- planOutboundReply: outboundReplyPlanner,
577
- sendOutboundReplyArtifacts: outboundReplyArtifactSender,
578
- isCurrentOwner: lockOwnershipGuard.ownsContext,
579
- getDefaultChatId: proactivePushChatIdGetter,
580
- isProactivePushEnabled,
581
- recordRuntimeEvent,
582
- getActiveToolExecutions: lifecycle.getActiveToolExecutions,
583
- setActiveToolExecutions: lifecycle.setActiveToolExecutions,
584
- triggerPendingModelSwitchAbort: modelSwitchController.triggerPendingAbort,
585
- });
586
- // Wire transport-level reply dedup reset via lifecycle
587
- Lifecycle.setResetTransportReplyDedup(Replies.resetTransportReplyDedup);
588
- const agentStartWithDedupReset = Lifecycle.createAgentStartDedupHook(
589
- agentLifecycleHooks.onAgentStart,
590
- );
591
- const compactionObserver = Lifecycle.createTelegramCompactionObserverRuntime({
592
- setCompactionInProgress: lifecycle.setCompactionInProgress,
457
+ finalizeMarkdownPreview,
458
+ proactivePushChatIdGetter,
459
+ isProactivePushEnabled: configControls.isProactivePushEnabled,
593
460
  updateStatus,
594
- requestDeferredDispatchNextQueuedTelegramTurn:
595
- deferredQueueDispatchRuntime.request,
596
- dispatchNextQueuedTelegramTurn,
597
461
  recordRuntimeEvent,
598
462
  });
599
- Lifecycle.registerTelegramLifecycleHooks(pi, {
600
- ...sessionLifecycleRuntime,
601
- ...agentLifecycleHooks,
602
- async onSessionShutdown(event, ctx) {
603
- compactionObserver.onSessionShutdown();
604
- await sessionLifecycleRuntime.onSessionShutdown(event, ctx);
605
- },
606
- onSessionBeforeCompact: compactionObserver.onSessionBeforeCompact,
607
- onSessionCompact: compactionObserver.onSessionCompact,
608
- onAgentStart: agentStartWithDedupReset,
609
- onBeforeAgentStart: Prompts.createTelegramProactiveBeforeAgentStartHook({
610
- isProactivePushEnabled,
611
- isCurrentOwner: lockOwnershipGuard.ownsContext,
612
- }),
613
- onModelSelect: currentModelRuntime.onModelSelect,
614
- onMessageStart: previewRuntime.onMessageStart,
615
- onMessageUpdate: previewRuntime.onMessageUpdate,
616
- });
617
463
  }