@llblab/pi-kit 0.22.0 → 0.22.1

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 (37) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/node_modules/@llblab/pi-telegram/AGENTS.md +2 -1
  4. package/node_modules/@llblab/pi-telegram/BACKLOG.md +3 -8
  5. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +6 -0
  6. package/node_modules/@llblab/pi-telegram/README.md +1 -1
  7. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +1 -4
  8. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.d.ts +0 -1
  9. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.js +0 -3
  10. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +1 -2
  11. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.d.ts +3 -3
  12. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.js +17 -3
  13. package/node_modules/@llblab/pi-telegram/dist/lib/menu.d.ts +5 -7
  14. package/node_modules/@llblab/pi-telegram/dist/lib/menu.js +4 -5
  15. package/node_modules/@llblab/pi-telegram/dist/lib/model.d.ts +12 -12
  16. package/node_modules/@llblab/pi-telegram/dist/lib/model.js +49 -35
  17. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +0 -2
  18. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +1 -8
  19. package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +0 -1
  20. package/node_modules/@llblab/pi-telegram/dist/lib/runtime.d.ts +3 -6
  21. package/node_modules/@llblab/pi-telegram/dist/lib/runtime.js +4 -55
  22. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +36 -10
  23. package/node_modules/@llblab/pi-telegram/dist/package.json +1 -1
  24. package/node_modules/@llblab/pi-telegram/docs/architecture.md +8 -8
  25. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +2 -2
  26. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +7 -4
  27. package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +0 -7
  28. package/node_modules/@llblab/pi-telegram/lib/extension.ts +1 -3
  29. package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +25 -4
  30. package/node_modules/@llblab/pi-telegram/lib/menu.ts +14 -9
  31. package/node_modules/@llblab/pi-telegram/lib/model.ts +77 -44
  32. package/node_modules/@llblab/pi-telegram/lib/queue.ts +1 -8
  33. package/node_modules/@llblab/pi-telegram/lib/routing.ts +0 -1
  34. package/node_modules/@llblab/pi-telegram/lib/runtime.ts +7 -58
  35. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +43 -17
  36. package/node_modules/@llblab/pi-telegram/package.json +1 -1
  37. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to `@llblab/pi-kit` are documented here.
4
4
 
5
+ ## 0.22.1 - 2026-09-24
6
+
7
+ - `In-Flight Model Switching`: Advances the exact Telegram pin to `0.51.2`. Telegram model selection can stop, switch, and continue any interruptible run in the current Pi session, including local/TUI work, while preserving the authorized chat, Thread, and reply target and deferring abort until active tools settle.
8
+ - `Typing Continuity`: Native presence refreshes only the assigned Thread, coalesces concurrent chat actions, shares Telegram cooldown across Thread keys, and preserves an existing agent typing loop through compaction. Best-effort typing failures no longer replace healthy leader/follower status with an error.
9
+ - `Package Cohort`: Keeps every other bundled package at its current exact version. Package membership, resource paths, load order, Pi minimum, and bundled Skill ownership remain unchanged.
10
+
5
11
  ## 0.22.0 - 2026-09-23
6
12
 
7
13
  - `Named npm Extensions`: Advances the exact Clean Room pin to `0.2.0`. `/clean-room <package-name>` now loads installed npm Pi extensions by name, including scoped packages, while preserving explicit resource isolation and project-local precedence.
package/README.md CHANGED
@@ -15,7 +15,7 @@ Package links lead to the owning repositories for usage, documentation, issues,
15
15
  | [`@llblab/pi-codex-usage`](https://github.com/llblab/pi-codex-usage) | `0.10.0` | Compact Codex/Spark subscription-limit and Business credit-usage status |
16
16
  | [`@llblab/pi-grow-loop`](https://github.com/llblab/pi-grow-loop) | `0.8.1` | Visible continuation scheduling and bounded worker Skills |
17
17
  | [`@llblab/pi-state-flow`](https://github.com/llblab/pi-state-flow) | `0.18.1` | Incremental scoped context/memory compiler with independent scope revisions, canonical file persistence, bounded and diagnosable Git backup replication, native working context within each run, and targeted historical reads |
18
- | [`@llblab/pi-telegram`](https://github.com/llblab/pi-telegram) | `0.51.1` | Telegram companion with stable follower heartbeats, exact queue-transition notices, pressure-safe Workspace rotation, adaptive Thread continuity, files, voice, controls, and bundled Telegram interaction Skills |
18
+ | [`@llblab/pi-telegram`](https://github.com/llblab/pi-telegram) | `0.51.2` | Telegram companion with in-flight model switching, continuous exact-Thread typing, truthful transport status, pressure-safe Workspace rotation, files, voice, controls, and bundled Telegram interaction Skills |
19
19
  | [`@llblab/skills`](https://github.com/llblab/skills) | `1.15.0` | Portable workflows for engineering, review, design, context maintenance, and other focused tasks |
20
20
 
21
21
  Versions are exact by design. An upstream release does not change an installed kit until this repository explicitly advances the dependency and publishes a new kit version. Runtime defects and package-specific feature requests belong in the linked repository; package selection and kit installation issues belong here.
@@ -96,10 +96,11 @@ Use the relevant local skill before non-trivial work in its domain. Keep skill o
96
96
 
97
97
  - Queue lane/kind admission is explicit. Dispatch waits for active-turn, pending-dispatch, control, compaction, `ctx.isIdle()`, and Pi pending-message guards; a dispatched prompt stays queued until `agent_start` consumes it. The terminal `+N` suffix is a yellow count of executable prompts still waiting, excludes the dispatched head immediately, and never counts current agent work from any source. Each prompt is one object with one active lane and no reserved return slot. Normal and Priority are separate FIFO lanes: crossing lanes removes it from the source and appends it at the destination tail, while Keep/Skip and same-category emoji changes preserve lane position. Complete reaction sets independently derive Priority from recognized positive emoji and Skip from recognized negative emoji; both may coexist, suppressed turns retain durable receipts while waiting, and Skip settles them only when the prompt reaches dispatch before dropping it without inference. Suppressed turns remain visible at a struck-through physical ordinal without contributing to executable queue counters, while graceful session shutdown discards all remaining queue authority before clearing memory.
98
98
  - `/stop`, `/abort`, `/next`, and `/continue` respectively reset+abort, abort while preserving queue, force the next turn, and enqueue a control-lane continuation. Abort-history folding applies only to Telegram-owned active turns. A busy `/next` marks only its exact active Telegram turn: terminal abort settlement attempts one explicit abort notice before the exact selected queued prompt receives its dispatch notice. Notice failure is diagnostic and cannot block dispatch; a later `/abort` or `/stop` cancels both pending transition notices before taking ownership. Target command adapters must forward these transition ports. A successful dispatch notice keeps the queued prompt's one reply-header claim across agent start, so later messages in that turn never repeat it.
99
+ - A model selection from an authorized Telegram target may stop and continue any interruptible active agent run in that same Pi session, including local/TUI work. Queue the synthetic control-lane continuation before aborting; when no Telegram prompt owns the run, bind continuation and reply ownership to the exact model-menu chat/Thread/message. Delay abort until every active tool execution settles, and clear both selection and fallback target on cancellation, agent start, settlement, or session replacement.
99
100
  - Telegram extension side effects must not hold Pi's core lifecycle hostage after semantic completion. Preserve ordering in extension-owned background work, record failures, and fence target/profile/transport/session authority.
100
101
  - Complete assistant/guest model answers use Telegram-native Rich Markdown. Harness-owned menus, status, diagnostics, thinking, and tool evidence remain explicit HTML/plain or their documented native surface. Before Telegram preview or final delivery, strip every assistant-authored HTML comment regardless of Markdown position while keeping action activation top-level-only; a comment-only result sends no text message. Preserve literal code outside comments and structurally safe chunking; never split invalid markup.
101
102
  - `preview` owns streaming lifecycle only, not assistant rendering. Finalization waits for active preview flushes and must not issue pre/post-final draft-clear calls that create transient Telegram draft UI. Turns that already answer as one atomic reply (voice replies, Guest Mode queries) never stream previews.
102
- - Native `sendChatAction(typing)` is the automatic activity signal for unsettled agent and compaction work while Telegram transport is authorized. Extension-owned blocking UI prompts pause it and completion resumes it while either work owner remains active. Do not invent extra in-chat work indicators or emit activity for startup/connect/reload/recovery alone.
103
+ - Native `sendChatAction(typing)` is the automatic activity signal for unsettled agent and compaction work while Telegram transport is authorized. Extension-owned blocking UI prompts pause it and completion resumes it while either work owner remains active. Compaction may stop only a typing loop it actually started; it must preserve a pre-existing agent-owned loop. Refresh only the assigned Thread on a conservative three-second cadence; do not mirror typing to aggregate `All` and multiply shared-chat flood pressure. Typing is best-effort presence only: a failed exact-target action remains a structured diagnostic and must not replace a healthy connected/leader/follower status with `error`. Do not invent extra in-chat work indicators or emit activity for startup/connect/reload/recovery alone.
103
104
  - Public activity handlers and connected companion delivery are asynchronous, target-bound, generation-fenced surfaces. Connected companion projection has no independent opt-out: disconnect or authority loss is its boundary. Token deltas, hidden reasoning, unknown sources, and stale authority never enter public projection.
104
105
  - Thread display defaults to the profile-scoped Letters strategy, with Names, Directory Snake, and Directory Title as the other automatic choices; Names projects the generated dictionary name for the slot. Unsupported retained display keys resolve to Letters without rewriting persisted configuration. A durable manual Thread display name retained on its Workspace binding overrides any automatic projection until exact reset; keep generated/recovery identity separate from manual and acknowledged display fields. After leader startup, automatic display contraction waits one follower-staleness window so election and follower re-registration cannot briefly remove and restore an acknowledged same-cwd suffix; stop/start generation cancels stale reconciliation. UI labels, emoji semantics, navigation, settings controls, callback namespaces, voice behavior, command templates, and assistant markup follow the linked `/docs` contracts. Generated human-readable prompt-button labels use `emoji + space + text`; emoji-free text is only a reasoned no-semantic-marker fallback. Non-spatial generated controls default to top-level vertical cells, with nested rows reserved for unmistakably compact peers. Do not restate other evolving UI details here.
105
106
 
@@ -2,16 +2,11 @@
2
2
 
3
3
  _This file owns unresolved project work only. Completed behavior belongs in `CHANGELOG.md`; durable contracts belong in `AGENTS.md` and `/docs`._
4
4
 
5
- - [ ] `Unified Telegram /new continuity` ([#81](https://github.com/llblab/pi-telegram/issues/81), `live-acceptance-gated`): Run operator-authorized Classic and Threaded live smoke for the implemented one-shot successor handoff, then close the issue. Verify confirmation deletion, exact-target/session continuity, one terminal result, and no duplicate settlement.
6
- - [ ] `Manual Thread naming` (`live-acceptance-gated`): Exercise command ordering, dialog/cancel, invalid input, duplicate callbacks, leader/follower rename, manual override, and reset against disposable Threads. Local generation/target fencing and Bot-API-wait replacement regressions are complete.
7
- - [ ] [`Workspace Thread recovery`](./docs/multi-instance-bus.md) (`operator-/environment-gated`): Finish live and platform evidence without weakening exact owner, admission, journal, or deletion fences.
8
- - [ ] Confirm the retired K Thread/history is absent after the successful full-A–Z pressure rotation, and repeat the rebuilt leader-election smoke to verify a returning same-directory follower causes no temporary suffix contraction.
9
- - [ ] Complete follower Restore, inaccessible-callback, already-absent chooser, stale-target, Singleton↔Threaded, and native-Windows acceptance with disposable targets; preserve accepted work and current ownership.
5
+ - [ ] [`Workspace Thread recovery`](./docs/multi-instance-bus.md) (`environment-gated`): Complete native-Windows coverage for follower restore, inaccessible callbacks, stale targets, and Singleton↔Threaded transitions while preserving accepted work and current ownership.
10
6
  - [ ] Select an approved exact-absence observation before implementing ambiguous `deletion-issued` recovery. Never replay an unknown deletion or infer absence from cache, heartbeat silence, empty `editForumTopic`, or `sendChatAction` success.
11
7
  - [ ] [`Automatic pairing and follower input custody`](./docs/architecture.md#automatic-pairing-confirmation-design) (`activation-gated`): Keep production custody disabled until historical sources and physical references are reconciled, all legacy writers/consumers are retired or excluded under operator authority, migration is complete, and every participating peer supports the final protocol. Preserve outcome-unknown running work, exact receipt/group authority, authenticated handoff, and rollback/downgrade safety. Then compose the prepared v3 lifecycle/bus ports, add bounded operator disposition for retained legacy retry state, and run real-process plus native-Windows acceptance.
12
- - [ ] `Thread Cleanup Manager` (`activation-gated`): Production currently exposes non-destructive review only. Before enabling deletion, compose the exact cleanup fence/permit coordinator, prove successor recovery for `commit-ready` without transport replay, and run operator-authorized live acceptance against disposable inactive Threads. Unknown outcomes remain retained.
13
- - [ ] `Channel operations` (`live-acceptance-gated`): On a disposable channel with real sender rights, verify media rejection, duplicate-send suppression, caption edit, and the durable authored-post create/list/edit/delete flow. Preserve direct-leader authority and outcome-unknown no-replay semantics.
8
+ - [ ] `Thread Cleanup Manager` (`activation-gated`): Production currently exposes non-destructive review only. Before enabling deletion, compose the exact cleanup fence/permit coordinator and prove successor recovery for `commit-ready` without transport replay. Unknown outcomes remain retained.
14
9
  - [ ] [`Inference-bypass Generative Apps`](./docs/generative-apps.md) (`hardening`): Complete removal/replacement recovery, process-birth lock recovery, follower routing, refresh/backoff, stale revision rejection, redacted failure diagnostics, CML/JSON parity, and no-model-turn acceptance. Extend the Music Player adapter evidence across volume, toggle, previous, status, restart, unavailable backend, and bounded process failures.
15
10
  - [ ] `External compatibility acceptance` (`environment-gated`): Confirm one `telegram_bind` request through the reporter's OMP + llama-server build ([#267](https://github.com/llblab/pi-telegram/issues/267)); validate environment-backed bot-token setup/status for default and named profiles; and extend native in-body controls to a second client, follower routing, disabled cells, and app-method revision rejection.
16
- - [ ] `Queue recovery evidence` (`operator-gated`): Establish a supported preservation/discard path for any already-wedged in-memory queue before mutation. Optional disposable-follower smoke may overlap delayed voice processing with turn completion to confirm one-time ordered consumption. Never clear journals, replay settled input, or treat restart as repair.
11
+ - [ ] `Queue recovery evidence` (`operator-gated`): Establish a supported preservation/discard path for any already-wedged in-memory queue before mutation. Never clear journals, replay settled input, or treat restart as repair.
17
12
  - [ ] `Show Me ownership transfer` (`release-coordination`): After a pi-telegram release containing the bundled `show-me` Skill is available, remove the former copy from `@llblab/skills` under that package's release policy, then update Pi Kit. The coordinated final install must expose exactly one Skill identity.
@@ -4,6 +4,12 @@
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.51.2: Model switching and typing continuity
8
+
9
+ - `In-flight model switching`: Telegram model selection can again stop, switch, and continue any interruptible agent run in the current Pi session, including local/TUI work without an active Telegram prompt. The exact model-menu chat/Thread/message supplies fallback continuation ownership, active tools defer abort until settlement, and cancellation/session boundaries clear both selection and target state instead of returning a false busy response.
10
+ - `Typing continuity`: Native presence now refreshes only the assigned Thread every three seconds instead of duplicating each action into aggregate `All`. The leader admits at most one concurrent action per chat and shares Telegram 429 cooldown across that chat's Thread keys. Compaction preserves a pre-existing agent typing loop instead of claiming and stopping it, addressing both multi-instance flicker and lifecycle gaps.
11
+ - `Typing status truthfulness`: Failed `sendChatAction(typing)` calls remain bounded structured diagnostics but no longer replace a healthy connected/leader/follower status with `error`. Optional presence failures therefore cannot misreport transport health after the actual turn and delivery continue successfully.
12
+
7
13
  ## 0.51.1: Queue transitions and follower heartbeat stability
8
14
 
9
15
  - `/next lifecycle notices`: Target command composition now forwards request, exact-turn marker, and cancellation ports. Busy `/next` orders abort then selected-prompt dispatch notices; failures cannot block dispatch, and `/abort`/`/stop` cancel stale notices. A successful dispatch notice keeps first-reply ownership through agent start, so later answer messages do not repeat the queued-prompt reply. Rapid ordinary messages remain distinct turns.
@@ -123,7 +123,7 @@ Enable the optional capabilities the bridge needs in the [@BotFather](https://t.
123
123
  | Queue control | Inspect waiting turns, keep or skip stale work, promote important prompts, continue, abort, stop, or force the next queued item. | Long Pi tasks keep running while new mobile prompts stay visible and controllable instead of interrupting or disappearing. |
124
124
  | Operator menu | Use `/start` for status, prompt templates, model, thinking, settings, queue, extension sections, and diagnostics. | The bot is an operator panel, not a command cheat sheet. |
125
125
  | Prompt templates | Run Pi prompt templates as Telegram-safe commands such as `/fix_tests`. | Reusable local workflows become phone-accessible without exposing arbitrary terminal commands. |
126
- | Model and thinking | Switch model or thinking level from Telegram through safe continuation flows. | Mobile control can adjust execution strategy without tearing down the current session. |
126
+ | Model and thinking | Switch model or thinking level from Telegram through safe continuation flows, including an active local/TUI agent run. | Mobile control can stop, switch, and resume in the same session context instead of returning a false busy dead end. |
127
127
  | Compaction | Confirm `/compact`, show native active status during compaction, and preserve Telegram-owned turn semantics. | Context maintenance is visible and safe from the phone. |
128
128
  | Draft previews | Show Telegram's native `…typing` indicator whenever the connected instance is doing agent work, or enable Rich Draft previews for streamed answer text. | Local prompts, Telegram turns, and autonomous continuations remain visibly active while draft visibility stays independent from final rendering. |
129
129
  | Activity | Keep the default `verbose` technical surface, show only `thinking`, show only `tools`, or select `quiet` for answer-only delivery. Every instance reloads this shared file-backed choice before a new agent run; thinking accumulates for two seconds and then updates at most every two seconds in a headerless expandable quote, while each tool uses one iconless closed root row containing nested evidence details. | Persistent collapsed technical activity minimizes chat height and stays bounded, redacted, target-fenced, free of URL previews, and visually separate from semantic assistant answers. |
@@ -676,10 +676,7 @@ export function registerTelegramLifecycleRuntimeHooks({ pi, publicationRuntime,
676
676
  return false;
677
677
  const turn = activeTurnRuntime.get();
678
678
  const target = turn?.target ?? proactivePushTargetGetter();
679
- promptDispatchRuntime.startTypingLoop(ctx, turn?.chatId ?? target?.chatId, {
680
- target,
681
- });
682
- return true;
679
+ return (promptDispatchRuntime.startTypingLoop(ctx, turn?.chatId ?? target?.chatId, { target }) !== false);
683
680
  };
684
681
  const startActiveTurnTypingLoop = (ctx) => {
685
682
  if (uiPromptActive)
@@ -14,5 +14,4 @@ export interface TelegramBusAwareApiRuntimeDeps {
14
14
  threadId?: number;
15
15
  } | undefined;
16
16
  }
17
- export declare function createTelegramAggregateTypingActionSender(runtime: Pick<TelegramBridgeApiRuntime, "call">): (chatId: number) => Promise<unknown>;
18
17
  export declare function createTelegramBusAwareApiRuntime(deps: TelegramBusAwareApiRuntimeDeps): TelegramBridgeApiRuntime;
@@ -37,9 +37,6 @@ function markFollowerCrossTargetDelivery(body, defaultTarget) {
37
37
  function rejectTelegramDirectOwnership(method) {
38
38
  return Promise.reject(new Error(`Telegram ${method} requires direct transport ownership.`));
39
39
  }
40
- export function createTelegramAggregateTypingActionSender(runtime) {
41
- return (chatId) => runtime.call("sendChatAction", { chat_id: chatId, action: "typing" });
42
- }
43
40
  export function createTelegramBusAwareApiRuntime(deps) {
44
41
  return {
45
42
  call(method, body, options) {
@@ -514,7 +514,6 @@ export default function (pi) {
514
514
  typing,
515
515
  getDefaultChatId: proactivePushChatIdGetter,
516
516
  sendTypingAction,
517
- sendAggregateTypingAction: BusApi.createTelegramAggregateTypingActionSender(telegramApiRuntime),
518
517
  updateStatus,
519
518
  isContextActive: telegramSessionContextStore.isCurrent,
520
519
  getTransportAuthority() {
@@ -1353,7 +1352,7 @@ export default function (pi) {
1353
1352
  loadConfig: configStore.load,
1354
1353
  setQueuedItems: telegramQueueStore.setQueuedItems,
1355
1354
  setCurrentModel: currentModelRuntime.set,
1356
- setPendingModelSwitch: pendingModelSwitchStore.set,
1355
+ setPendingModelSwitch: modelSwitchController.clearPendingSwitch,
1357
1356
  syncCounters: queue.syncCounters,
1358
1357
  syncFlags: lifecycle.syncFlags,
1359
1358
  bindDeferredDispatchContext: deferredQueueDispatchRuntime.bind,
@@ -4,7 +4,7 @@
4
4
  * Owns model-menu state, scoped model pages, model callback planning, and model-menu message rendering
5
5
  */
6
6
  import type { TelegramInlineKeyboardMarkup } from "./keyboard.ts";
7
- import { type MenuModel, type ScopedTelegramModel, type ThinkingLevel } from "./model.ts";
7
+ import { type MenuModel, type ScopedTelegramModel, type TelegramModelSwitchContinuationSource, type ThinkingLevel } from "./model.ts";
8
8
  export type TelegramModelScope = "all" | "scoped";
9
9
  export interface TelegramModelMenuState<TModel extends MenuModel = MenuModel> {
10
10
  chatId: number;
@@ -93,8 +93,8 @@ export type TelegramModelMenuCallbackDeps<TModel extends MenuModel = MenuModel>
93
93
  setModel: (model: TModel) => Promise<boolean>;
94
94
  setCurrentModel: (model: TModel) => void;
95
95
  setThinkingLevel: (level: ThinkingLevel) => void;
96
- stagePendingModelSwitch: (selection: ScopedTelegramModel<TModel>) => void;
97
- restartInterruptedTelegramTurn: (selection: ScopedTelegramModel<TModel>) => Promise<boolean> | boolean;
96
+ stagePendingModelSwitch: (selection: ScopedTelegramModel<TModel>, continuationTurn: TelegramModelSwitchContinuationSource) => void;
97
+ restartInterruptedTelegramTurn: (selection: ScopedTelegramModel<TModel>, continuationTurn: TelegramModelSwitchContinuationSource) => Promise<boolean> | boolean;
98
98
  };
99
99
  export interface TelegramModelMenuOpenDeps<TModel extends MenuModel = MenuModel> {
100
100
  isIdle: () => boolean;
@@ -506,19 +506,33 @@ export async function handleTelegramModelMenuCallbackAction(callbackQueryId, par
506
506
  if (plan.selection.thinkingLevel) {
507
507
  deps.setThinkingLevel(plan.selection.thinkingLevel);
508
508
  }
509
- await deps.updateModelMenuMessage();
509
+ const continuationTurn = {
510
+ chatId: params.state.chatId,
511
+ replyToMessageId: params.state.messageId,
512
+ target: {
513
+ chatId: params.state.chatId,
514
+ ...(params.state.threadId === undefined
515
+ ? {}
516
+ : { threadId: params.state.threadId }),
517
+ },
518
+ };
510
519
  if (plan.mode === "restart-after-tool") {
511
- deps.stagePendingModelSwitch(plan.selection);
520
+ deps.stagePendingModelSwitch(plan.selection, continuationTurn);
521
+ await deps.updateModelMenuMessage();
512
522
  await deps.answerCallbackQuery(callbackQueryId, plan.callbackText);
513
523
  return true;
514
524
  }
515
525
  if (plan.mode === "restart-now") {
516
- const restarted = await deps.restartInterruptedTelegramTurn(plan.selection);
526
+ const restarted = await deps.restartInterruptedTelegramTurn(plan.selection, continuationTurn);
527
+ await deps.updateModelMenuMessage();
517
528
  if (!restarted) {
518
529
  await deps.answerCallbackQuery(callbackQueryId, "Pi is busy. Send /abort, /next, or /stop.");
519
530
  return true;
520
531
  }
521
532
  }
533
+ else {
534
+ await deps.updateModelMenuMessage();
535
+ }
522
536
  await deps.answerCallbackQuery(callbackQueryId, plan.callbackText);
523
537
  return true;
524
538
  }
@@ -4,7 +4,7 @@
4
4
  * Owns app-menu/status state, inline UI text, and callback composition while model/thinking/queue menu details live in dedicated domains
5
5
  */
6
6
  import { type TelegramMenuMessageRuntimeDeps, type TelegramModelMenuState, type TelegramModelMenuStateBuilderContext, type TelegramModelMenuStateBuilderDeps, type TelegramReplyMarkup } from "./menu-model.ts";
7
- import { type MenuModel, type ScopedTelegramModel, type ThinkingLevel } from "./model.ts";
7
+ import { type MenuModel, type ScopedTelegramModel, type TelegramModelSwitchContinuationSource, type ThinkingLevel } from "./model.ts";
8
8
  import type { TelegramInputRichMessage } from "./telegram-api.ts";
9
9
  import { type TelegramSectionRegistry } from "./sections.ts";
10
10
  export { applyTelegramModelPageSelection, applyTelegramModelScopeSelection, buildModelMenuReplyMarkup, buildModelPageMenuReplyMarkup, buildTelegramModelCallbackPlan, buildTelegramModelMenuRenderPayload, buildTelegramModelMenuState, buildTelegramModelMenuStateRuntime, buildTelegramModelPageMenuRenderPayload, createTelegramModelMenuRuntime, createTelegramModelMenuStateBuilder, formatScopedModelButtonText, getModelMenuItems, getStoredTelegramModelMenuState, getTelegramModelMenuPage, getTelegramModelSelection, handleTelegramModelMenuCallbackAction, MODEL_MENU_TITLE, MODEL_PAGE_MENU_TITLE, openTelegramModelMenu, pruneStoredTelegramModelMenus, resolveCachedTelegramModelMenuInputs, sendTelegramModelMenuMessage, storeTelegramModelMenuState, TELEGRAM_MODEL_PAGE_SIZE, updateTelegramModelMenuMessage, } from "./menu-model.ts";
@@ -49,14 +49,13 @@ export interface TelegramMenuCallbackRuntimeDeps<TContext, TModel extends MenuMo
49
49
  updateSettingsMenuMessage?: (state: TelegramModelMenuState<TModel>, ctx: TContext) => Promise<void>;
50
50
  answerCallbackQuery: (callbackQueryId: string, text?: string) => Promise<void>;
51
51
  isIdle: (ctx: TContext) => boolean;
52
- hasActiveTelegramTurn: () => boolean;
53
52
  hasAbortHandler: () => boolean;
54
53
  hasActiveToolExecutions: () => boolean;
55
54
  persistScopedModelPatterns?: (patterns: string[], ctx: TContext) => Promise<void>;
56
55
  setModel: (model: TModel) => Promise<boolean>;
57
56
  setCurrentModel: (model: TModel, ctx: TContext) => void;
58
- stagePendingModelSwitch: (selection: ScopedTelegramModel<TModel>, ctx: TContext) => void;
59
- restartInterruptedTelegramTurn: (selection: ScopedTelegramModel<TModel>, ctx: TContext) => Promise<boolean> | boolean;
57
+ stagePendingModelSwitch: (selection: ScopedTelegramModel<TModel>, ctx: TContext, continuationTurn: TelegramModelSwitchContinuationSource) => void;
58
+ restartInterruptedTelegramTurn: (selection: ScopedTelegramModel<TModel>, ctx: TContext, continuationTurn: TelegramModelSwitchContinuationSource) => Promise<boolean> | boolean;
60
59
  sectionRegistry?: TelegramSectionRegistry;
61
60
  editInteractiveMessage?: (chatId: number, messageId: number, text: string, mode: "markdown" | "html" | "plain", replyMarkup: TelegramReplyMarkup) => Promise<void>;
62
61
  sendInteractiveMessage?: (chatId: number, text: string, mode: "markdown" | "html" | "plain", replyMarkup: TelegramReplyMarkup, options?: {
@@ -133,14 +132,13 @@ export interface TelegramMenuCallbackRuntimeAdapterDeps<TContext, TModel extends
133
132
  updateSettingsMenuMessage?: (state: TelegramModelMenuState<TModel>, ctx: TContext) => Promise<void>;
134
133
  answerCallbackQuery: (callbackQueryId: string, text?: string) => Promise<void>;
135
134
  isIdle: (ctx: TContext) => boolean;
136
- hasActiveTelegramTurn: () => boolean;
137
135
  hasAbortHandler: () => boolean;
138
136
  getActiveToolExecutions: () => number;
139
137
  persistScopedModelPatterns?: (patterns: string[], ctx: TContext) => Promise<void>;
140
138
  setModel: (model: TModel) => Promise<boolean>;
141
139
  setCurrentModel: (model: TModel, ctx: TContext) => void;
142
- stagePendingModelSwitch: (selection: ScopedTelegramModel<TModel>, ctx: TContext) => void;
143
- restartInterruptedTelegramTurn: (selection: ScopedTelegramModel<TModel>, ctx: TContext) => Promise<boolean> | boolean;
140
+ stagePendingModelSwitch: (selection: ScopedTelegramModel<TModel>, ctx: TContext, continuationTurn: TelegramModelSwitchContinuationSource) => void;
141
+ restartInterruptedTelegramTurn: (selection: ScopedTelegramModel<TModel>, ctx: TContext, continuationTurn: TelegramModelSwitchContinuationSource) => Promise<boolean> | boolean;
144
142
  sectionRegistry?: TelegramSectionRegistry;
145
143
  editInteractiveMessage?: (chatId: number, messageId: number, text: string, mode: "markdown" | "html" | "plain", replyMarkup: TelegramReplyMarkup) => Promise<void>;
146
144
  sendInteractiveMessage?: (chatId: number, text: string, mode: "markdown" | "html" | "plain", replyMarkup: TelegramReplyMarkup, options?: {
@@ -99,7 +99,6 @@ export function createTelegramMenuCallbackHandlerForContext(deps) {
99
99
  updateSettingsMenuMessage: deps.updateSettingsMenuMessage,
100
100
  answerCallbackQuery: deps.answerCallbackQuery,
101
101
  isIdle: deps.isIdle,
102
- hasActiveTelegramTurn: deps.hasActiveTelegramTurn,
103
102
  hasAbortHandler: deps.hasAbortHandler,
104
103
  hasActiveToolExecutions: () => deps.getActiveToolExecutions() > 0,
105
104
  persistScopedModelPatterns: deps.persistScopedModelPatterns,
@@ -228,7 +227,7 @@ export async function handleTelegramMenuCallbackRuntime(query, ctx, deps) {
228
227
  activeModel: deps.getActiveModel(ctx),
229
228
  currentThinkingLevel: deps.getThinkingLevel(),
230
229
  isIdle: deps.isIdle(ctx),
231
- canRestartBusyRun: deps.hasActiveTelegramTurn() && deps.hasAbortHandler(),
230
+ canRestartBusyRun: deps.hasAbortHandler(),
232
231
  hasActiveToolExecutions: deps.hasActiveToolExecutions(),
233
232
  }, {
234
233
  updateModelMenuMessage: () => deps.updateModelMenuMessage(state, ctx),
@@ -243,10 +242,10 @@ export async function handleTelegramMenuCallbackRuntime(query, ctx, deps) {
243
242
  deps.setThinkingLevel(level);
244
243
  deps.updateStatus(ctx);
245
244
  },
246
- stagePendingModelSwitch: (selection) => {
247
- deps.stagePendingModelSwitch(selection, ctx);
245
+ stagePendingModelSwitch: (selection, continuationTurn) => {
246
+ deps.stagePendingModelSwitch(selection, ctx, continuationTurn);
248
247
  },
249
- restartInterruptedTelegramTurn: (selection) => deps.restartInterruptedTelegramTurn(selection, ctx),
248
+ restartInterruptedTelegramTurn: (selection, continuationTurn) => deps.restartInterruptedTelegramTurn(selection, ctx, continuationTurn),
250
249
  });
251
250
  }
252
251
  catch (error) {
@@ -52,14 +52,13 @@ export interface PendingModelSwitchStore<TSelection> {
52
52
  }
53
53
  export interface TelegramInFlightModelSwitchState {
54
54
  isIdle: boolean;
55
- hasActiveTelegramTurn: boolean;
56
55
  hasAbortHandler: boolean;
57
56
  }
58
57
  export declare function createPendingModelSwitchStore<TSelection>(): PendingModelSwitchStore<TSelection>;
59
- export declare function canRestartTelegramTurnForModelSwitch(state: TelegramInFlightModelSwitchState): boolean;
58
+ export declare function canRestartAgentRunForTelegramModelSwitch(state: TelegramInFlightModelSwitchState): boolean;
60
59
  export declare function shouldTriggerPendingTelegramModelSwitchAbort(state: {
61
60
  hasPendingModelSwitch: boolean;
62
- hasActiveTelegramTurn: boolean;
61
+ hasContinuationTurn: boolean;
63
62
  hasAbortHandler: boolean;
64
63
  activeToolExecutions: number;
65
64
  }): boolean;
@@ -70,8 +69,9 @@ export declare function restartTelegramModelSwitchContinuation<TTurn, TSelection
70
69
  queueContinuation: (turn: TTurn, selection: TSelection) => void;
71
70
  }): boolean;
72
71
  export declare function buildTelegramModelSwitchContinuationText<TModel extends MenuModel>(telegramPrefix: string, model: TModel, thinkingLevel?: ScopedTelegramModel<TModel>["thinkingLevel"]): string;
72
+ export type TelegramModelSwitchContinuationSource = Pick<PendingTelegramTurn, "chatId" | "replyToMessageId" | "target">;
73
73
  export declare function buildTelegramModelSwitchContinuationTurn<TModel extends MenuModel>(options: {
74
- turn: Pick<PendingTelegramTurn, "chatId" | "replyToMessageId" | "target">;
74
+ turn: TelegramModelSwitchContinuationSource;
75
75
  selection: ScopedTelegramModel<TModel>;
76
76
  telegramPrefix?: string;
77
77
  queueOrder: number;
@@ -82,22 +82,22 @@ export declare function createTelegramModelSwitchContinuationTurnBuilder<TModel
82
82
  allocateItemOrder: () => number;
83
83
  allocateControlOrder: () => number;
84
84
  }): (options: {
85
- turn: Pick<PendingTelegramTurn, "chatId" | "replyToMessageId" | "target">;
85
+ turn: TelegramModelSwitchContinuationSource;
86
86
  selection: ScopedTelegramModel<TModel>;
87
87
  }) => PendingTelegramTurn;
88
88
  export declare function createTelegramModelSwitchContinuationQueue<TContext, TSelection extends ScopedTelegramModel>(deps: {
89
89
  createContinuationTurn: (options: {
90
- turn: Pick<PendingTelegramTurn, "chatId" | "replyToMessageId" | "target">;
90
+ turn: TelegramModelSwitchContinuationSource;
91
91
  selection: TSelection;
92
92
  }) => PendingTelegramTurn;
93
93
  appendQueuedItem: (item: PendingTelegramTurn, ctx: TContext) => void;
94
- }): (turn: PendingTelegramTurn, selection: TSelection, ctx: TContext) => void;
94
+ }): (turn: TelegramModelSwitchContinuationSource, selection: TSelection, ctx: TContext) => void;
95
95
  export declare function createTelegramModelSwitchContinuationQueueRuntime<TContext, TSelection extends ScopedTelegramModel>(deps: {
96
96
  telegramPrefix?: string;
97
97
  allocateItemOrder: () => number;
98
98
  allocateControlOrder: () => number;
99
99
  appendQueuedItem: (item: PendingTelegramTurn, ctx: TContext) => void;
100
- }): (turn: PendingTelegramTurn, selection: TSelection, ctx: TContext) => void;
100
+ }): (turn: TelegramModelSwitchContinuationSource, selection: TSelection, ctx: TContext) => void;
101
101
  export interface TelegramModelSwitchControllerDeps<TContext, TSelection> {
102
102
  isIdle: (ctx: TContext) => boolean;
103
103
  getPendingModelSwitch: () => TSelection | undefined;
@@ -106,16 +106,16 @@ export interface TelegramModelSwitchControllerDeps<TContext, TSelection> {
106
106
  getAbortHandler: () => (() => void) | undefined;
107
107
  hasAbortHandler: () => boolean;
108
108
  getActiveToolExecutions: () => number;
109
- queueContinuation: (turn: PendingTelegramTurn, selection: TSelection, ctx: TContext) => void;
109
+ queueContinuation: (turn: TelegramModelSwitchContinuationSource, selection: TSelection, ctx: TContext) => void;
110
110
  updateStatus: (ctx: TContext) => void;
111
111
  }
112
112
  export interface TelegramModelSwitchController<TContext, TSelection> {
113
113
  canOfferInFlightSwitch: (ctx: TContext) => boolean;
114
- stagePendingSwitch: (selection: TSelection, ctx: TContext) => void;
114
+ stagePendingSwitch: (selection: TSelection, ctx: TContext, continuationTurn?: TelegramModelSwitchContinuationSource) => void;
115
115
  clearPendingSwitch: () => void;
116
- queueContinuation: (turn: PendingTelegramTurn, selection: TSelection, ctx: TContext) => void;
116
+ queueContinuation: (turn: TelegramModelSwitchContinuationSource, selection: TSelection, ctx: TContext) => void;
117
117
  triggerPendingAbort: (ctx: TContext) => boolean;
118
- restartInterruptedTurn: (selection: TSelection, ctx: TContext) => boolean;
118
+ restartInterruptedTurn: (selection: TSelection, ctx: TContext, continuationTurn?: TelegramModelSwitchContinuationSource) => boolean;
119
119
  }
120
120
  export interface TelegramModelSwitchControllerRuntimeDeps<TContext, TSelection extends ScopedTelegramModel> extends Omit<TelegramModelSwitchControllerDeps<TContext, TSelection>, "queueContinuation"> {
121
121
  telegramPrefix?: string;
@@ -261,12 +261,12 @@ export function createPendingModelSwitchStore() {
261
261
  has: () => selection !== undefined,
262
262
  };
263
263
  }
264
- export function canRestartTelegramTurnForModelSwitch(state) {
265
- return !state.isIdle && state.hasActiveTelegramTurn && state.hasAbortHandler;
264
+ export function canRestartAgentRunForTelegramModelSwitch(state) {
265
+ return !state.isIdle && state.hasAbortHandler;
266
266
  }
267
267
  export function shouldTriggerPendingTelegramModelSwitchAbort(state) {
268
268
  return (state.hasPendingModelSwitch &&
269
- state.hasActiveTelegramTurn &&
269
+ state.hasContinuationTurn &&
270
270
  state.hasAbortHandler &&
271
271
  state.activeToolExecutions === 0);
272
272
  }
@@ -297,7 +297,7 @@ export function buildTelegramModelSwitchContinuationText(telegramPrefix, model,
297
297
  const thinkingSuffix = thinkingLevel
298
298
  ? ` Keep the selected thinking level (${thinkingLevel}) if it still applies.`
299
299
  : "";
300
- return `${telegramPrefix} Continue the interrupted previous Telegram request using the newly selected model (${modelLabel}). Resume from the last unfinished step instead of restarting from scratch unless necessary.${thinkingSuffix}`;
300
+ return `${telegramPrefix} Continue the interrupted previous request using the newly selected model (${modelLabel}). Resume from the last unfinished step instead of restarting from scratch unless necessary.${thinkingSuffix}`;
301
301
  }
302
302
  export function buildTelegramModelSwitchContinuationTurn(options) {
303
303
  const modelLabel = `${options.selection.model.provider}/${options.selection.model.id}`;
@@ -318,7 +318,7 @@ export function buildTelegramModelSwitchContinuationTurn(options) {
318
318
  text: buildTelegramModelSwitchContinuationText(options.telegramPrefix ?? TELEGRAM_PREFIX, options.selection.model, options.selection.thinkingLevel),
319
319
  },
320
320
  ],
321
- historyText: `Continue interrupted Telegram request on ${modelLabel}`,
321
+ historyText: `Continue interrupted request on ${modelLabel}`,
322
322
  statusSummary: `↻ ${statusLabel || "continue"}`,
323
323
  };
324
324
  }
@@ -364,46 +364,60 @@ export function createTelegramModelSwitchControllerRuntime(deps) {
364
364
  });
365
365
  }
366
366
  export function createTelegramModelSwitchController(deps) {
367
+ let pendingContinuationTurn;
368
+ const triggerPendingAbort = (ctx) => {
369
+ const turn = pendingContinuationTurn ?? deps.getActiveTurn();
370
+ if (!shouldTriggerPendingTelegramModelSwitchAbort({
371
+ hasPendingModelSwitch: !!deps.getPendingModelSwitch(),
372
+ hasContinuationTurn: !!turn,
373
+ hasAbortHandler: deps.hasAbortHandler(),
374
+ activeToolExecutions: deps.getActiveToolExecutions(),
375
+ })) {
376
+ return false;
377
+ }
378
+ const selection = deps.getPendingModelSwitch();
379
+ const abort = deps.getAbortHandler();
380
+ if (!selection || !turn || !abort)
381
+ return false;
382
+ pendingContinuationTurn = undefined;
383
+ deps.setPendingModelSwitch(undefined);
384
+ deps.queueContinuation(turn, selection, ctx);
385
+ abort();
386
+ return true;
387
+ };
367
388
  return {
368
- canOfferInFlightSwitch: (ctx) => canRestartTelegramTurnForModelSwitch({
389
+ canOfferInFlightSwitch: (ctx) => canRestartAgentRunForTelegramModelSwitch({
369
390
  isIdle: deps.isIdle(ctx),
370
- hasActiveTelegramTurn: !!deps.getActiveTurn(),
371
391
  hasAbortHandler: deps.hasAbortHandler(),
372
392
  }),
373
- stagePendingSwitch: (selection, ctx) => {
393
+ stagePendingSwitch: (selection, ctx, continuationTurn) => {
394
+ pendingContinuationTurn = deps.getActiveTurn() ?? continuationTurn;
374
395
  deps.setPendingModelSwitch(selection);
375
- deps.updateStatus(ctx);
396
+ try {
397
+ deps.updateStatus(ctx);
398
+ }
399
+ finally {
400
+ triggerPendingAbort(ctx);
401
+ }
376
402
  },
377
403
  clearPendingSwitch: () => {
404
+ pendingContinuationTurn = undefined;
378
405
  deps.setPendingModelSwitch(undefined);
379
406
  },
380
407
  queueContinuation: deps.queueContinuation,
381
- triggerPendingAbort: (ctx) => {
382
- if (!shouldTriggerPendingTelegramModelSwitchAbort({
383
- hasPendingModelSwitch: !!deps.getPendingModelSwitch(),
384
- hasActiveTelegramTurn: !!deps.getActiveTurn(),
385
- hasAbortHandler: deps.hasAbortHandler(),
386
- activeToolExecutions: deps.getActiveToolExecutions(),
387
- })) {
388
- return false;
389
- }
390
- const selection = deps.getPendingModelSwitch();
391
- const turn = deps.getActiveTurn();
392
- const abort = deps.getAbortHandler();
393
- if (!selection || !turn || !abort)
394
- return false;
395
- deps.setPendingModelSwitch(undefined);
396
- deps.queueContinuation(turn, selection, ctx);
397
- abort();
398
- return true;
408
+ triggerPendingAbort,
409
+ restartInterruptedTurn: (selection, ctx, continuationTurn) => {
410
+ const restarted = restartTelegramModelSwitchContinuation({
411
+ activeTurn: deps.getActiveTurn() ?? continuationTurn,
412
+ abort: deps.getAbortHandler(),
413
+ selection,
414
+ queueContinuation: (turn, nextSelection) => {
415
+ deps.queueContinuation(turn, nextSelection, ctx);
416
+ },
417
+ });
418
+ if (restarted)
419
+ pendingContinuationTurn = undefined;
420
+ return restarted;
399
421
  },
400
- restartInterruptedTurn: (selection, ctx) => restartTelegramModelSwitchContinuation({
401
- activeTurn: deps.getActiveTurn(),
402
- abort: deps.getAbortHandler(),
403
- selection,
404
- queueContinuation: (turn, nextSelection) => {
405
- deps.queueContinuation(turn, nextSelection, ctx);
406
- },
407
- }),
408
422
  };
409
423
  }
@@ -353,7 +353,6 @@ export interface TelegramAgentStartHookRuntimeDeps<TTurn extends PendingTelegram
353
353
  }
354
354
  export type TelegramAgentStartHookEvent = unknown;
355
355
  export interface TelegramToolExecutionRuntimeDeps {
356
- hasActiveTurn: () => boolean;
357
356
  getActiveToolExecutions: () => number;
358
357
  setActiveToolExecutions: (count: number) => void;
359
358
  }
@@ -372,7 +371,6 @@ export declare function buildTelegramAgentStartPlan<TContext = unknown>(options:
372
371
  export declare function handleTelegramAgentStartRuntime<TTurn extends PendingTelegramTurn, TContext = unknown>(deps: TelegramAgentStartRuntimeDeps<TTurn, TContext>): void;
373
372
  export declare function createTelegramAgentStartHook<TTurn extends PendingTelegramTurn, TContext = unknown>(deps: TelegramAgentStartHookRuntimeDeps<TTurn, TContext>): (_event: TelegramAgentStartHookEvent, ctx: TContext) => Promise<void>;
374
373
  export declare function getNextTelegramToolExecutionCount(options: {
375
- hasActiveTurn: boolean;
376
374
  currentCount: number;
377
375
  event: "start" | "end";
378
376
  }): number;
@@ -741,8 +741,6 @@ export function createTelegramAgentStartHook(deps) {
741
741
  };
742
742
  }
743
743
  export function getNextTelegramToolExecutionCount(options) {
744
- if (!options.hasActiveTurn)
745
- return options.currentCount;
746
744
  if (options.event === "start") {
747
745
  return options.currentCount + 1;
748
746
  }
@@ -750,20 +748,16 @@ export function getNextTelegramToolExecutionCount(options) {
750
748
  }
751
749
  export function handleTelegramToolExecutionStartRuntime(deps) {
752
750
  deps.setActiveToolExecutions(getNextTelegramToolExecutionCount({
753
- hasActiveTurn: deps.hasActiveTurn(),
754
751
  currentCount: deps.getActiveToolExecutions(),
755
752
  event: "start",
756
753
  }));
757
754
  }
758
755
  export function handleTelegramToolExecutionEndRuntime(deps) {
759
- const hasActiveTurn = deps.hasActiveTurn();
760
756
  deps.setActiveToolExecutions(getNextTelegramToolExecutionCount({
761
- hasActiveTurn,
762
757
  currentCount: deps.getActiveToolExecutions(),
763
758
  event: "end",
764
759
  }));
765
- if (hasActiveTurn)
766
- deps.triggerPendingModelSwitchAbort();
760
+ deps.triggerPendingModelSwitchAbort();
767
761
  }
768
762
  export function createTelegramAgentLifecycleHooks(deps) {
769
763
  const onAgentStart = createTelegramAgentStartHook(deps);
@@ -806,7 +800,6 @@ export function createTelegramToolExecutionHooks(deps) {
806
800
  },
807
801
  onToolExecutionEnd: (_event, ctx) => {
808
802
  handleTelegramToolExecutionEndRuntime({
809
- hasActiveTurn: deps.hasActiveTurn,
810
803
  getActiveToolExecutions: deps.getActiveToolExecutions,
811
804
  setActiveToolExecutions: deps.setActiveToolExecutions,
812
805
  triggerPendingModelSwitchAbort: () => {
@@ -535,7 +535,6 @@ export function createTelegramInboundRouteRuntime(deps) {
535
535
  updateSettingsMenuMessage: deps.updateSettingsMenuMessage,
536
536
  answerCallbackQuery: deps.answerCallbackQuery,
537
537
  isIdle: deps.isIdle,
538
- hasActiveTelegramTurn: deps.activeTurnRuntime.has,
539
538
  hasAbortHandler: deps.bridgeRuntime.abort.hasHandler,
540
539
  getActiveToolExecutions: deps.bridgeRuntime.lifecycle.getActiveToolExecutions,
541
540
  persistScopedModelPatterns: deps.persistScopedModelPatterns,
@@ -98,7 +98,6 @@ export interface TelegramTypingLoopDeps {
98
98
  sendTypingAction: (chatId: number, options?: {
99
99
  message_thread_id?: number;
100
100
  }) => Promise<unknown>;
101
- sendAggregateTypingAction?: (chatId: number) => Promise<unknown>;
102
101
  shouldContinue?: () => boolean;
103
102
  onStopped?: () => void;
104
103
  }
@@ -111,7 +110,6 @@ export interface TelegramTypingLoopStarterDeps<TContext> extends TelegramRuntime
111
110
  sendTypingAction: (chatId: number, options?: {
112
111
  message_thread_id?: number;
113
112
  }) => Promise<unknown>;
114
- sendAggregateTypingAction?: (chatId: number) => Promise<unknown>;
115
113
  updateStatus: (ctx: TContext, error?: string) => void;
116
114
  isContextActive?: (ctx: TContext) => boolean;
117
115
  isTransportAvailable?: () => boolean;
@@ -120,7 +118,7 @@ export interface TelegramTypingLoopStarterDeps<TContext> extends TelegramRuntime
120
118
  }
121
119
  export declare function createTelegramTypingLoopStarter<TContext>(deps: TelegramTypingLoopStarterDeps<TContext>): (ctx: TContext, chatId?: number, options?: {
122
120
  target?: TelegramTypingLoopTarget;
123
- }) => void;
121
+ }) => boolean;
124
122
  export declare function startTelegramTypingLoop(state: TelegramBridgeRuntimeState, deps: TelegramTypingLoopDeps): boolean;
125
123
  export declare function stopTelegramTypingLoop(state: TelegramBridgeRuntimeState): boolean;
126
124
  export declare function waitForTelegramTypingLoopIdle(state: TelegramBridgeRuntimeState, timeoutMs?: number): Promise<void>;
@@ -141,7 +139,7 @@ export interface TelegramPromptDispatchLifecycleDeps<TContext> extends TelegramR
141
139
  typing: Pick<TelegramRuntimeTypingPort, "stop">;
142
140
  startTypingLoop: (ctx: TContext, chatId?: number, options?: {
143
141
  target?: TelegramTypingLoopTarget;
144
- }) => void;
142
+ }) => boolean | void;
145
143
  updateStatus: (ctx: TContext, error?: string) => void;
146
144
  }
147
145
  export interface TelegramPromptDispatchRuntimeDeps<TContext> extends TelegramRuntimeEventRecorderPort {
@@ -151,7 +149,6 @@ export interface TelegramPromptDispatchRuntimeDeps<TContext> extends TelegramRun
151
149
  sendTypingAction: (chatId: number, options?: {
152
150
  message_thread_id?: number;
153
151
  }) => Promise<unknown>;
154
- sendAggregateTypingAction?: (chatId: number) => Promise<unknown>;
155
152
  updateStatus: (ctx: TContext, error?: string) => void;
156
153
  isContextActive?: (ctx: TContext) => boolean;
157
154
  isTransportAvailable?: () => boolean;
@@ -161,7 +158,7 @@ export interface TelegramPromptDispatchRuntimeDeps<TContext> extends TelegramRun
161
158
  export interface TelegramPromptDispatchRuntime<TContext> {
162
159
  startTypingLoop: (ctx: TContext, chatId?: number, options?: {
163
160
  target?: TelegramTypingLoopTarget;
164
- }) => void;
161
+ }) => boolean | void;
165
162
  onPromptDispatchStart: (ctx: TContext, chatId?: number) => void;
166
163
  onPromptDispatchFailure: (ctx: TContext, message: string) => void;
167
164
  }