@llblab/pi-kit 0.12.1 → 0.14.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/CHANGELOG.md +8 -0
- package/README.md +2 -2
- package/node_modules/@llblab/pi-state-flow/AGENTS.md +7 -7
- package/node_modules/@llblab/pi-state-flow/BACKLOG.md +8 -9
- package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +26 -0
- package/node_modules/@llblab/pi-state-flow/README.md +1 -3
- package/node_modules/@llblab/pi-state-flow/dist/index.d.ts +21 -0
- package/node_modules/@llblab/pi-state-flow/dist/index.js +20 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/acquisition.d.ts +39 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/acquisition.js +78 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/artifact.d.ts +110 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/artifact.js +334 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.d.ts +49 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.js +67 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/config.d.ts +11 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/config.js +53 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/context.d.ts +23 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/context.js +109 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/continuation.d.ts +111 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/continuation.js +189 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/discovery.d.ts +21 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/discovery.js +125 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/durable.d.ts +102 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/durable.js +507 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/episode.d.ts +8 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/episode.js +27 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/extension.d.ts +22 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +1263 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/git.d.ts +72 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/git.js +565 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/history.d.ts +22 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/history.js +79 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/json.d.ts +12 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/json.js +109 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/logging.d.ts +25 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/logging.js +24 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/maintenance.d.ts +36 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/maintenance.js +98 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/memory.d.ts +15 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/memory.js +42 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/migration.d.ts +13 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/migration.js +133 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.d.ts +7 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.js +59 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/publication.d.ts +69 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/publication.js +335 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/query.d.ts +27 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/query.js +35 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/recovery.d.ts +8 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/recovery.js +27 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/rehydration.d.ts +36 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/rehydration.js +38 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.d.ts +142 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.js +529 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/session.d.ts +21 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/session.js +44 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/skills.d.ts +25 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/skills.js +131 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.d.ts +88 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.js +255 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/state.d.ts +55 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/state.js +31 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/status.d.ts +38 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/status.js +79 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/storage.d.ts +46 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/storage.js +217 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.d.ts +98 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.js +231 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/temporal.d.ts +39 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/temporal.js +203 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/transition.d.ts +25 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/transition.js +204 -0
- package/node_modules/@llblab/pi-state-flow/dist/package.json +79 -0
- package/node_modules/@llblab/pi-state-flow/dist/pi-state-flow/index.js +1 -0
- package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-memory/SKILL.md +138 -0
- package/node_modules/@llblab/pi-state-flow/docs/architecture.md +11 -5
- package/node_modules/@llblab/pi-state-flow/docs/compatibility.md +5 -1
- package/node_modules/@llblab/pi-state-flow/docs/filesystem-recovery.md +3 -3
- package/node_modules/@llblab/pi-state-flow/docs/usage.md +6 -4
- package/node_modules/@llblab/pi-state-flow/index.ts +1 -0
- package/node_modules/@llblab/pi-state-flow/lib/compaction.ts +17 -1
- package/node_modules/@llblab/pi-state-flow/lib/config.ts +6 -1
- package/node_modules/@llblab/pi-state-flow/lib/durable.ts +88 -96
- package/node_modules/@llblab/pi-state-flow/lib/extension.ts +64 -12
- package/node_modules/@llblab/pi-state-flow/lib/git.ts +32 -188
- package/node_modules/@llblab/pi-state-flow/lib/migration.ts +84 -48
- package/node_modules/@llblab/pi-state-flow/lib/query.ts +40 -0
- package/node_modules/@llblab/pi-state-flow/lib/recovery.ts +7 -30
- package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +48 -50
- package/node_modules/@llblab/pi-state-flow/lib/snapshot.ts +41 -97
- package/node_modules/@llblab/pi-state-flow/lib/storage.ts +17 -12
- package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +4 -4
- package/node_modules/@llblab/pi-state-flow/package.json +23 -6
- package/node_modules/@llblab/pi-state-flow/skills/state-flow-memory/SKILL.md +3 -1
- package/node_modules/@llblab/pi-telegram/AGENTS.md +5 -3
- package/node_modules/@llblab/pi-telegram/BACKLOG.md +0 -6
- package/node_modules/@llblab/pi-telegram/CHANGELOG.md +22 -0
- package/node_modules/@llblab/pi-telegram/README.md +6 -3
- package/node_modules/@llblab/pi-telegram/dist/api/activity.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/activity.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/commands.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/commands.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/delivery.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/delivery.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/inbound.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/inbound.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/keyboard.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/keyboard.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/outbound.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/outbound.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/sections.d.ts +7 -0
- package/node_modules/@llblab/pi-telegram/dist/api/sections.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/status.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/status.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/updates.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/updates.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/voice.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/api/voice.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/index.d.ts +6 -0
- package/node_modules/@llblab/pi-telegram/dist/index.js +6 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.d.ts +52 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.js +596 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/activity.d.ts +220 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/activity.js +574 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/agent-messages.d.ts +28 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/agent-messages.js +86 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +250 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +936 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.d.ts +18 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.js +254 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +464 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +1689 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.d.ts +292 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.js +2242 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.d.ts +64 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.js +140 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus.d.ts +518 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bus.js +2055 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.d.ts +170 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.js +611 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.d.ts +70 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.js +744 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +541 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +1155 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/config.d.ts +252 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/config.js +889 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +163 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +542 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/extension.d.ts +7 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +1604 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/generative-app-worker.mjs +104 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.d.ts +212 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.js +1006 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/inbound.d.ts +91 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/inbound.js +502 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/journal.d.ts +665 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/journal.js +3701 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.d.ts +23 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.js +37 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.d.ts +157 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +395 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/locks.d.ts +164 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/locks.js +1208 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/logging.d.ts +50 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/logging.js +274 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/media.d.ts +181 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/media.js +602 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.d.ts +217 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.js +663 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-queue.d.ts +37 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-queue.js +408 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +115 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +595 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.d.ts +32 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.js +112 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.d.ts +29 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.js +82 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu.d.ts +171 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/menu.js +323 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/model.d.ts +127 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/model.js +409 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.d.ts +241 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.js +639 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.d.ts +69 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.js +248 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.d.ts +42 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.js +678 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-voice.d.ts +55 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound-voice.js +152 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound.d.ts +185 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/outbound.js +516 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/ownership.d.ts +77 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/ownership.js +174 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/paths.d.ts +40 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/paths.js +94 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +72 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +121 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/polling.d.ts +351 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/polling.js +1196 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/preview.d.ts +192 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/preview.js +614 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.d.ts +24 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.js +118 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/prompts.d.ts +57 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/prompts.js +167 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +766 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +1965 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/recovery.d.ts +86 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/recovery.js +285 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/rendering.d.ts +20 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/rendering.js +983 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/replies.d.ts +214 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/replies.js +737 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +207 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +2282 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/runtime.d.ts +172 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/runtime.js +402 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/sections.d.ts +165 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/sections.js +327 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/setup.d.ts +82 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/setup.js +150 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/skills.d.ts +8 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/skills.js +12 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/status.d.ts +442 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/status.js +1000 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/sync.d.ts +179 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +782 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/target.d.ts +20 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/target.js +27 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.d.ts +541 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +1159 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/text-groups.d.ts +89 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/text-groups.js +317 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.d.ts +288 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.js +560 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.d.ts +46 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.js +257 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.d.ts +46 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.js +78 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.d.ts +239 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.js +644 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +621 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +3679 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/time-injection.d.ts +15 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/time-injection.js +56 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/turns.d.ts +109 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/turns.js +500 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +1290 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +3634 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/voice.d.ts +117 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/voice.js +174 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.d.ts +264 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.js +1136 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +219 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +587 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.d.ts +30 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.js +54 -0
- package/node_modules/@llblab/pi-telegram/dist/package.json +126 -0
- package/node_modules/@llblab/pi-telegram/dist/pi-telegram/index.js +1 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/SKILL.md +107 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/references/capability-adapters.md +27 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/references/layout-and-state.md +37 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/generative-apps/SKILL.md +115 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/show-me/SKILL.md +166 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/show-me/references/telegram-surfaces.md +43 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/SKILL.md +129 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/configuration.md +15 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/delivery-and-threads.md +27 -0
- package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/diagnosis.md +18 -0
- package/node_modules/@llblab/pi-telegram/docs/README.md +2 -0
- package/node_modules/@llblab/pi-telegram/docs/architecture.md +4 -2
- package/node_modules/@llblab/pi-telegram/docs/compact-matrix-literal.md +10 -3
- package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +15 -13
- package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +6 -4
- package/node_modules/@llblab/pi-telegram/docs/outbound.md +1 -1
- package/node_modules/@llblab/pi-telegram/docs/public-api.md +3 -3
- package/node_modules/@llblab/pi-telegram/lib/bindings.ts +89 -6
- package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +12 -5
- package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +44 -19
- package/node_modules/@llblab/pi-telegram/lib/bus.ts +4 -1
- package/node_modules/@llblab/pi-telegram/lib/commands.ts +2 -2
- package/node_modules/@llblab/pi-telegram/lib/config.ts +14 -7
- package/node_modules/@llblab/pi-telegram/lib/delivery.ts +38 -6
- package/node_modules/@llblab/pi-telegram/lib/extension.ts +7 -0
- package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +379 -13
- package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +20 -6
- package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +16 -7
- package/node_modules/@llblab/pi-telegram/lib/status.ts +9 -15
- package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +12 -1
- package/node_modules/@llblab/pi-telegram/lib/thread-display.ts +96 -18
- package/node_modules/@llblab/pi-telegram/package.json +56 -13
- package/node_modules/@llblab/pi-telegram/scripts/build-dist.mjs +44 -0
- package/node_modules/@llblab/pi-telegram/scripts/measure-bus.mjs +8 -1
- package/node_modules/@llblab/pi-telegram/scripts/measure-workspace.mjs +8 -1
- package/node_modules/@llblab/pi-telegram/skills/generative-apps/SKILL.md +1 -1
- package/node_modules/@llblab/pi-telegram/skills/show-me/SKILL.md +1 -1
- package/node_modules/@llblab/pi-telegram/skills/show-me/references/telegram-surfaces.md +1 -1
- package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/SKILL.md +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,1604 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram bridge extension composition and orchestration layer
|
|
3
|
+
* Zones: telegram, pi agent, orchestration
|
|
4
|
+
* Keeps runtime wiring in one place while the package entrypoint remains a thin re-export
|
|
5
|
+
*/
|
|
6
|
+
import * as AgentMessages from "./agent-messages.js";
|
|
7
|
+
import * as Bindings from "./bindings.js";
|
|
8
|
+
import * as BusApi from "./bus-api.js";
|
|
9
|
+
import * as BusFollower from "./bus-follower.js";
|
|
10
|
+
import * as BusLeader from "./bus-leader.js";
|
|
11
|
+
import * as BusTransport from "./bus-transport.js";
|
|
12
|
+
import * as Bus from "./bus.js";
|
|
13
|
+
import * as ChannelPosts from "./channel-posts.js";
|
|
14
|
+
import * as ThreadCleanupManager from "./thread-cleanup-manager.js";
|
|
15
|
+
import * as CommandTemplates from "./command-templates.js";
|
|
16
|
+
import * as Commands from "./commands.js";
|
|
17
|
+
import * as Config from "./config.js";
|
|
18
|
+
import * as Delivery from "./delivery.js";
|
|
19
|
+
import * as Inbound from "./inbound.js";
|
|
20
|
+
import * as Journal from "./journal.js";
|
|
21
|
+
import * as Lifecycle from "./lifecycle.js";
|
|
22
|
+
import * as Locks from "./locks.js";
|
|
23
|
+
import * as Logging from "./logging.js";
|
|
24
|
+
import * as Media from "./media.js";
|
|
25
|
+
import * as MenuQueue from "./menu-queue.js";
|
|
26
|
+
import * as MenuSettings from "./menu-settings.js";
|
|
27
|
+
import * as Menu from "./menu.js";
|
|
28
|
+
import * as Model from "./model.js";
|
|
29
|
+
import * as Outbound from "./outbound.js";
|
|
30
|
+
import * as Ownership from "./ownership.js";
|
|
31
|
+
import * as Paths from "./paths.js";
|
|
32
|
+
import * as Pi from "./pi.js";
|
|
33
|
+
import * as Polling from "./polling.js";
|
|
34
|
+
import * as Preview from "./preview.js";
|
|
35
|
+
import * as PromptTemplates from "./prompt-templates.js";
|
|
36
|
+
import * as Prompts from "./prompts.js";
|
|
37
|
+
import * as Queue from "./queue.js";
|
|
38
|
+
import * as Recovery from "./recovery.js";
|
|
39
|
+
import * as Replies from "./replies.js";
|
|
40
|
+
import * as Routing from "./routing.js";
|
|
41
|
+
import * as Runtime from "./runtime.js";
|
|
42
|
+
import * as Sections from "./sections.js";
|
|
43
|
+
import * as Skills from "./skills.js";
|
|
44
|
+
import * as Status from "./status.js";
|
|
45
|
+
import * as Sync from "./sync.js";
|
|
46
|
+
import * as TelegramApi from "./telegram-api.js";
|
|
47
|
+
import * as TextGroups from "./text-groups.js";
|
|
48
|
+
import * as ThreadReconciler from "./thread-reconciler.js";
|
|
49
|
+
import * as ThreadDisplay from "./thread-display.js";
|
|
50
|
+
import * as Threads from "./threads.js";
|
|
51
|
+
import * as TimeInjection from "./time-injection.js";
|
|
52
|
+
import * as Updates from "./updates.js";
|
|
53
|
+
import * as Voice from "./voice.js";
|
|
54
|
+
import * as WorkspaceAdmission from "./workspace-admission.js";
|
|
55
|
+
import * as WorkspaceRetirement from "./workspace-retirement.js";
|
|
56
|
+
const telegramBusProtocolIdentity = Bus.createTelegramCurrentBusProtocolIdentity([
|
|
57
|
+
Bus.TELEGRAM_BUS_CAPABILITY_DURABLE_FOLLOWER_ADMISSION,
|
|
58
|
+
Bus.TELEGRAM_BUS_CAPABILITY_QUEUE_HANDOFF,
|
|
59
|
+
Bus.TELEGRAM_BUS_CAPABILITY_WORKSPACE_FOLLOWER_AUTO_CONNECT,
|
|
60
|
+
Bus.TELEGRAM_BUS_CAPABILITY_WORKSPACE_THREAD_RENAME,
|
|
61
|
+
Bus.TELEGRAM_BUS_CAPABILITY_THREAD_DISPLAY_MODE,
|
|
62
|
+
Bus.TELEGRAM_BUS_CAPABILITY_DIRECTORY_DISPLAY_FORMAT,
|
|
63
|
+
]);
|
|
64
|
+
// --- Extension Runtime ---
|
|
65
|
+
export default function (pi) {
|
|
66
|
+
Skills.registerTelegramSkillDiscovery(pi);
|
|
67
|
+
const piRuntime = Pi.createExtensionApiRuntimePorts(pi);
|
|
68
|
+
const { getActiveTools, getCommands, getThinkingLevel, sendUserMessage, setActiveTools, setModel, setThinkingLevel, } = piRuntime;
|
|
69
|
+
const bridgeRuntime = Runtime.createTelegramBridgeRuntime();
|
|
70
|
+
const runtimeDiagnostics = Logging.createTelegramRuntimeDiagnosticsRuntime();
|
|
71
|
+
const runtimeEvents = runtimeDiagnostics.events;
|
|
72
|
+
const recordRuntimeEvent = runtimeDiagnostics.recordRuntimeEvent;
|
|
73
|
+
const configStore = Config.createTelegramConfigStore({ recordRuntimeEvent });
|
|
74
|
+
const busProcessRuntime = Bus.createCurrentTelegramBusProcessRuntime({
|
|
75
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
76
|
+
});
|
|
77
|
+
const { instanceId: telegramInstanceId, processId: telegramProcessId, processBirthId: telegramQueueProcessBirthId, manualFollowerOwnerId: telegramManualFollowerOwnerId, getLeaderSocketPath: getTelegramBusSocketPath, getFollowerSocketPath: getTelegramBusFollowerSocketPath, } = busProcessRuntime;
|
|
78
|
+
const getTelegramBotId = Config.createTelegramConfigBotIdGetter(configStore);
|
|
79
|
+
const workspaceAdmissionRuntime = WorkspaceAdmission.createTelegramWorkspaceAdmissionRuntimeBinding({
|
|
80
|
+
getProfileName: configStore.getActiveProfileName,
|
|
81
|
+
getBotToken: configStore.getBotToken,
|
|
82
|
+
getPath: Paths.resolveTelegramWorkspaceAdmissionPath,
|
|
83
|
+
owner: {
|
|
84
|
+
processId: telegramProcessId,
|
|
85
|
+
processBirthId: telegramQueueProcessBirthId,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const telegramWorkspaceOperationRuntime = WorkspaceRetirement.createTelegramWorkspaceOperationRuntime({
|
|
89
|
+
getWorkspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
90
|
+
onReleaseError(error, operationKind) {
|
|
91
|
+
recordRuntimeEvent("bus", error, {
|
|
92
|
+
phase: "workspace-admission-release",
|
|
93
|
+
operationKind,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const getTelegramActiveProfileKey = Config.createTelegramActiveProfileKeyGetter(configStore);
|
|
98
|
+
const getTelegramManualFollowerProfileKey = BusFollower.createTelegramManualFollowerProfileKeyResolver({
|
|
99
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
100
|
+
manualFollowerOwnerId: telegramManualFollowerOwnerId,
|
|
101
|
+
});
|
|
102
|
+
const telegramBusAuthSecret = Bus.createTelegramBusAuthSecret();
|
|
103
|
+
const telegramBusFollowerControlState = BusFollower.createTelegramBusFollowerControlState();
|
|
104
|
+
const telegramBusFollowerRegistry = Bus.createTelegramBusFollowerRegistry();
|
|
105
|
+
const modelContextAvailabilityBinding = Prompts.createTelegramModelContextAvailabilityBinding();
|
|
106
|
+
const telegramBusFollowerRegistrationState = BusFollower.createTelegramBusFollowerRegistrationState({
|
|
107
|
+
onAvailabilityChanged: modelContextAvailabilityBinding.reconcile,
|
|
108
|
+
});
|
|
109
|
+
const telegramBusLeaderState = Threads.createTelegramLeaderThreadStateRuntime();
|
|
110
|
+
const telegramThreadCapabilityState = Polling.createTelegramThreadCapabilityStateRuntime();
|
|
111
|
+
const telegramProvisioningActivity = Sync.createTelegramProvisioningActivityRuntime();
|
|
112
|
+
const messageOwnershipRuntime = Ownership.createTelegramBusMessageOwnershipRuntime({
|
|
113
|
+
instanceId: telegramInstanceId,
|
|
114
|
+
getProfileKey: getTelegramActiveProfileKey,
|
|
115
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
116
|
+
});
|
|
117
|
+
const { abort, lifecycle, queue, setup, typing } = bridgeRuntime;
|
|
118
|
+
const getTelegramUpdateAdmissionScope = Journal.createTelegramUpdateJournalReceiptScopeResolver({
|
|
119
|
+
getProfileName: configStore.getActiveProfileName,
|
|
120
|
+
getBotToken: configStore.getBotToken,
|
|
121
|
+
getBotId: getTelegramBotId,
|
|
122
|
+
});
|
|
123
|
+
const telegramJournalBindingRuntime = Journal.createTelegramUpdateJournalBindingRuntime({
|
|
124
|
+
base: {
|
|
125
|
+
getProfileName: configStore.getActiveProfileName,
|
|
126
|
+
getBotToken: configStore.getBotToken,
|
|
127
|
+
getBotId: getTelegramBotId,
|
|
128
|
+
onRecovery(event) {
|
|
129
|
+
recordRuntimeEvent("recovery", event.kind === "repaired"
|
|
130
|
+
? "Telegram update journal was repaired automatically."
|
|
131
|
+
: "Telegram update journal was reset after its damaged files were quarantined.", {
|
|
132
|
+
phase: "journal-auto-recovery",
|
|
133
|
+
recoveryKind: event.kind,
|
|
134
|
+
journalPath: event.path,
|
|
135
|
+
revision: event.revision,
|
|
136
|
+
quarantinePath: event.quarantinePath,
|
|
137
|
+
reason: event.reason,
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
getQueueRuntimeIdentity() {
|
|
141
|
+
return {
|
|
142
|
+
instanceId: telegramInstanceId,
|
|
143
|
+
processId: telegramProcessId,
|
|
144
|
+
processBirthId: telegramQueueProcessBirthId,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
getWorkspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
148
|
+
},
|
|
149
|
+
getLeaderJournalPath: Paths.resolveTelegramUpdateJournalPath,
|
|
150
|
+
getFollowerJournalPath(bindingKey, profileName) {
|
|
151
|
+
return Paths.resolveTelegramFollowerJournalPath(bindingKey, undefined, profileName);
|
|
152
|
+
},
|
|
153
|
+
getActiveFollowerBindingKey: getTelegramManualFollowerProfileKey,
|
|
154
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
155
|
+
});
|
|
156
|
+
const telegramJournalReferenceRegistry = Journal.createTelegramUpdateJournalReferenceRegistry();
|
|
157
|
+
const resolveTelegramUpdateJournalBinding = telegramJournalBindingRuntime.resolveLeader;
|
|
158
|
+
const resolveTelegramFollowerJournalBinding = telegramJournalBindingRuntime.resolveFollower;
|
|
159
|
+
const getTelegramQueueJournalBinding = telegramJournalBindingRuntime.getActiveRecoveryKey;
|
|
160
|
+
const isTelegramBusRuntimeEnabled = telegramThreadCapabilityState.isBusRuntimeEnabled;
|
|
161
|
+
Config.bindGlobalTelegramConfigRuntime(configStore);
|
|
162
|
+
const configControls = Config.createTelegramConfigControls(configStore);
|
|
163
|
+
const lockRuntime = Locks.createTelegramLockRuntime({
|
|
164
|
+
key: Locks.createTelegramLockKeyResolver(configStore),
|
|
165
|
+
instanceId: telegramInstanceId,
|
|
166
|
+
busSecret: telegramBusAuthSecret,
|
|
167
|
+
staleHeartbeatMs: Locks.TELEGRAM_BUS_LEADER_STALE_HEARTBEAT_MS,
|
|
168
|
+
});
|
|
169
|
+
const threadStore = Threads.createTelegramTopicTargetStore({
|
|
170
|
+
path: function () {
|
|
171
|
+
return Threads.getTelegramTopicTargetsPath(undefined, configStore.getActiveProfileName());
|
|
172
|
+
},
|
|
173
|
+
telegramProfile: function () {
|
|
174
|
+
return configStore.getActiveProfileName();
|
|
175
|
+
},
|
|
176
|
+
canPersist: lockRuntime.owns,
|
|
177
|
+
commitPersist: lockRuntime.commitIfOwned,
|
|
178
|
+
getExternalReservedSlots: function () {
|
|
179
|
+
return workspaceAdmissionRuntime.resolve()?.listReservedSlots() ?? [];
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
runtimeDiagnostics.bindStorage({
|
|
183
|
+
getBotToken: configStore.getBotToken,
|
|
184
|
+
getProfileName: configStore.getActiveProfileName,
|
|
185
|
+
canReset: lockRuntime.owns,
|
|
186
|
+
commitReset: lockRuntime.commitIfOwned,
|
|
187
|
+
});
|
|
188
|
+
const lockOwnershipGuard = Locks.createTelegramLockOwnershipGuard(lockRuntime);
|
|
189
|
+
const getCurrentLeaderEpoch = lockRuntime.getOwnedLeaderEpoch;
|
|
190
|
+
const telegramSessionContextStore = Lifecycle.createTelegramSessionContextStore({
|
|
191
|
+
getIdentity(ctx) {
|
|
192
|
+
return ctx.sessionManager ?? ctx.cwd;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
const ownsTelegramDirectDelivery = Locks.createTelegramDirectDeliveryOwnershipChecker({
|
|
196
|
+
lock: lockRuntime,
|
|
197
|
+
contextStore: telegramSessionContextStore,
|
|
198
|
+
});
|
|
199
|
+
const modelContextAvailabilityRuntime = Prompts.createTelegramModelContextAvailabilityRuntime({
|
|
200
|
+
getActiveTools,
|
|
201
|
+
setActiveTools,
|
|
202
|
+
isAvailable() {
|
|
203
|
+
return (ownsTelegramDirectDelivery() ||
|
|
204
|
+
telegramBusFollowerRegistrationState.isRegistered());
|
|
205
|
+
},
|
|
206
|
+
canReconcile() {
|
|
207
|
+
const ctx = telegramSessionContextStore.get();
|
|
208
|
+
return !ctx || Pi.isExtensionContextIdle(ctx);
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
modelContextAvailabilityBinding.bind(modelContextAvailabilityRuntime);
|
|
212
|
+
const activeTurnRuntime = Queue.createTelegramActiveTurnStore();
|
|
213
|
+
const proactivePushTargetGetter = Config.createTelegramProactivePushTargetGetter({
|
|
214
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
215
|
+
getAssignedTarget() {
|
|
216
|
+
return (telegramBusFollowerRegistrationState.getTarget() ??
|
|
217
|
+
telegramBusLeaderState.getTarget());
|
|
218
|
+
},
|
|
219
|
+
getAllowedUserId: configStore.getAllowedUserId,
|
|
220
|
+
});
|
|
221
|
+
const proactivePushChatIdGetter = Config.createTelegramProactivePushChatIdGetter(proactivePushTargetGetter);
|
|
222
|
+
const buttonActionStore = Outbound.createTelegramButtonActionStore();
|
|
223
|
+
const planGenerativeAppOutput = Outbound.createTelegramOutboundReplyPlanner(buttonActionStore, configControls.getAssistantRenderingMode);
|
|
224
|
+
const pendingModelSwitchStore = Model.createPendingModelSwitchStore();
|
|
225
|
+
const modelMenuRuntime = Menu.createTelegramModelMenuRuntime();
|
|
226
|
+
const sectionRegistry = Sections.createAndBindTelegramSectionRegistry();
|
|
227
|
+
const timeInjectionRuntime = TimeInjection.createTimeInjectionRuntime({
|
|
228
|
+
getConfig: Config.createTelegramTimeConfigGetter(configStore),
|
|
229
|
+
recordRuntimeEvent,
|
|
230
|
+
});
|
|
231
|
+
Outbound.bindTelegramRuntimeEventRecorder(recordRuntimeEvent);
|
|
232
|
+
const getContextModel = Pi.getExtensionContextModel;
|
|
233
|
+
const isIdle = Pi.isExtensionContextIdle;
|
|
234
|
+
const hasPendingMessages = Pi.hasExtensionContextPendingMessages;
|
|
235
|
+
const compact = Pi.compactExtensionContext;
|
|
236
|
+
const mediaGroupRuntime = Media.createTelegramMediaGroupController();
|
|
237
|
+
const textGroupRuntime = TextGroups.createTelegramTextGroupController();
|
|
238
|
+
const rawTelegramQueueStore = Queue.createTelegramQueueStore();
|
|
239
|
+
const telegramTransportStampRuntime = Queue.createTelegramTransportStampRuntime({
|
|
240
|
+
getProfileName: configStore.getActiveProfileName,
|
|
241
|
+
getBotToken: configStore.getBotToken,
|
|
242
|
+
});
|
|
243
|
+
const telegramQueueStore = Queue.createTelegramTransportStampedQueueStore(rawTelegramQueueStore, telegramTransportStampRuntime.getStamp);
|
|
244
|
+
const telegramApiTargetActivityRuntime = TelegramApi.createTelegramApiTargetActivityRuntime();
|
|
245
|
+
const captureWorkspaceExternalProtection = WorkspaceRetirement.createTelegramWorkspaceExternalProtectionCapture({
|
|
246
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
247
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
248
|
+
getQueuedItems: telegramQueueStore.getQueuedItems,
|
|
249
|
+
resolveLeaderJournal: resolveTelegramUpdateJournalBinding,
|
|
250
|
+
createFollowerJournalResolver: telegramJournalBindingRuntime.createRecipientResolver,
|
|
251
|
+
withJournalReference(binding, operation) {
|
|
252
|
+
if (!binding.recoveryKey)
|
|
253
|
+
throw new Error("Telegram workspace journal reference identity is unavailable.");
|
|
254
|
+
return telegramJournalReferenceRegistry.withReference({
|
|
255
|
+
referenceClass: "workspace-retirement",
|
|
256
|
+
recoveryKey: binding.recoveryKey,
|
|
257
|
+
}, operation);
|
|
258
|
+
},
|
|
259
|
+
discoverFollowerJournals() {
|
|
260
|
+
return Journal.discoverTelegramFollowerJournalPaths({
|
|
261
|
+
directory: Paths.resolveTelegramTempDir(),
|
|
262
|
+
profileName: configStore.getActiveProfileName(),
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
createJournalPathResolver: telegramJournalBindingRuntime.createPathResolver,
|
|
266
|
+
getJournalWriterProtection(journalBindingKey) {
|
|
267
|
+
const owner = Threads.getTelegramThreadOwnerFromProfileKey(journalBindingKey);
|
|
268
|
+
if (owner.kind !== "manual-follower")
|
|
269
|
+
return "unknown";
|
|
270
|
+
const liveness = Bus.getTelegramProcessBirthIdentityLiveness(owner.instanceId);
|
|
271
|
+
return liveness === "alive"
|
|
272
|
+
? "protected"
|
|
273
|
+
: liveness === "dead" ? "clear" : "unknown";
|
|
274
|
+
},
|
|
275
|
+
getDeliveryAuthorityProtection(binding) {
|
|
276
|
+
return telegramApiTargetActivityRuntime.hasPendingTarget(binding.target)
|
|
277
|
+
? "protected"
|
|
278
|
+
: "clear";
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
const inactiveThreadCleanupReviewRuntime = ThreadCleanupManager.createTelegramInactiveThreadCleanupReviewRuntime({
|
|
282
|
+
getProfileName() { return configStore.getActiveProfileName() ?? "default"; },
|
|
283
|
+
listBindings: threadStore.listWorkspaceBindings,
|
|
284
|
+
getProtection: captureWorkspaceExternalProtection,
|
|
285
|
+
listReservations: threadStore.listReservations,
|
|
286
|
+
listPendingProvisions: threadStore.listPendingProvisions,
|
|
287
|
+
listPendingCleanups: threadStore.listPendingCleanups,
|
|
288
|
+
getWorkStore() {
|
|
289
|
+
const profileName = configStore.getActiveProfileName() ?? "default";
|
|
290
|
+
const botToken = configStore.getBotToken();
|
|
291
|
+
if (!botToken)
|
|
292
|
+
throw new Error("Telegram Thread cleanup review requires an active bot token.");
|
|
293
|
+
return ThreadCleanupManager.createTelegramThreadCleanupWorkStore({
|
|
294
|
+
path: Paths.resolveTelegramThreadCleanupWorkPath(undefined, profileName),
|
|
295
|
+
profileName,
|
|
296
|
+
tokenSha256: Journal.createTelegramUpdateJournalBotIdentity({ botToken }).tokenSha256,
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
runWorkspaceOperation: telegramWorkspaceOperationRuntime.run,
|
|
300
|
+
});
|
|
301
|
+
const updateAdmissionRuntimeBinding = Updates.createTelegramUpdateAdmissionRuntimeBinding({
|
|
302
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
303
|
+
});
|
|
304
|
+
const deferredQueueDispatchRuntime = Queue.createTelegramDeferredQueueDispatchRuntime({
|
|
305
|
+
recordRuntimeEvent,
|
|
306
|
+
});
|
|
307
|
+
const pollingControllerState = Polling.createTelegramPollingControllerState();
|
|
308
|
+
const telegramSyncStateRuntime = Sync.createTelegramSyncStateRuntime();
|
|
309
|
+
const threadReconciliationRuntime = ThreadReconciler.createThreadReconciliationRuntime({
|
|
310
|
+
recordRuntimeEvent,
|
|
311
|
+
scheduleSnapshotPersist: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
312
|
+
});
|
|
313
|
+
const recordThreadReconciliationPlan = threadReconciliationRuntime.recordPlan;
|
|
314
|
+
const persistTelegramConfigWithSync = Sync.createTelegramConfigSyncPersister({
|
|
315
|
+
persist: configStore.persist,
|
|
316
|
+
markConfigChange: telegramSyncStateRuntime.markConfigChange,
|
|
317
|
+
});
|
|
318
|
+
const { current: currentInstanceThreadRuntime, status: threadStatusProjectionRuntime, getDisplayTitle: getThreadDisplayTitle, } = Threads.createTelegramCurrentThreadAssembly({
|
|
319
|
+
instanceId: telegramInstanceId,
|
|
320
|
+
listRecords: threadStore.list,
|
|
321
|
+
listWorkspaceBindings: threadStore.listWorkspaceBindings,
|
|
322
|
+
getFollowerDisplayTitle: telegramBusFollowerRegistrationState.getDisplayTitle,
|
|
323
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
324
|
+
getFollowerTarget: telegramBusFollowerRegistrationState.getTarget,
|
|
325
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
326
|
+
getFollowerSlot: telegramBusFollowerRegistrationState.getSlot,
|
|
327
|
+
getFollowerThreadName: telegramBusFollowerRegistrationState.getThreadName,
|
|
328
|
+
getLeaderIdentity: telegramBusLeaderState.getIdentity,
|
|
329
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
330
|
+
getLeaderProtocol: telegramBusFollowerRegistrationState.getLeaderProtocol,
|
|
331
|
+
status: {
|
|
332
|
+
getThreadMode: function () {
|
|
333
|
+
return threadStore.getBotState().threadMode;
|
|
334
|
+
},
|
|
335
|
+
isBusPollingStarted: telegramThreadCapabilityState.isBusPollingStarted,
|
|
336
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
337
|
+
listReservations: threadStore.listReservations,
|
|
338
|
+
listSyncObservations: threadStore.listSyncObservations,
|
|
339
|
+
getLeaderSocketPath: getTelegramBusSocketPath,
|
|
340
|
+
getFollowerSocketPath: getTelegramBusFollowerSocketPath,
|
|
341
|
+
getTransportKind: BusTransport.getTelegramBusTransportKind,
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
const findCurrentThreadRecord = currentInstanceThreadRuntime.findRecord;
|
|
345
|
+
const getCurrentInstanceThreadIdentity = currentInstanceThreadRuntime.getIdentity;
|
|
346
|
+
const statusRuntime = Status.createTelegramBridgeStatusRuntime({
|
|
347
|
+
getConfig: Status.createTelegramBridgeStatusConfigGetter(configStore),
|
|
348
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
349
|
+
getDiagnosticPaths: Paths.getTelegramDiagnosticsDisplayPaths,
|
|
350
|
+
isPollingActive: Polling.createTelegramPollingActivityReader(pollingControllerState),
|
|
351
|
+
getPollingState: Polling.createTelegramPollingStateReader(pollingControllerState),
|
|
352
|
+
getInboundWorkerState() {
|
|
353
|
+
return updateAdmissionRuntimeBinding.getActive()?.getState();
|
|
354
|
+
},
|
|
355
|
+
getAcceptedThroughUpdateId() {
|
|
356
|
+
return Journal.withTelegramResolvedUpdateJournalReference({
|
|
357
|
+
registry: telegramJournalReferenceRegistry,
|
|
358
|
+
resolveBinding: resolveTelegramUpdateJournalBinding,
|
|
359
|
+
referenceClass: "polling-cursor",
|
|
360
|
+
operation(binding) { return binding.journal.read().acceptedThroughUpdateId; },
|
|
361
|
+
});
|
|
362
|
+
},
|
|
363
|
+
getActiveSourceMessageIds: activeTurnRuntime.getSourceMessageIds,
|
|
364
|
+
hasActiveTurn: activeTurnRuntime.has,
|
|
365
|
+
hasDispatchPending: lifecycle.hasDispatchPending,
|
|
366
|
+
isCompactionInProgress: lifecycle.isCompactionInProgress,
|
|
367
|
+
getActiveToolExecutions: lifecycle.getActiveToolExecutions,
|
|
368
|
+
hasPendingModelSwitch: pendingModelSwitchStore.has,
|
|
369
|
+
getQueuedItems: telegramQueueStore.getQueuedItems,
|
|
370
|
+
getQueuedItemCount: Queue.countExecutableTelegramQueueItems,
|
|
371
|
+
formatQueuedStatus: Queue.formatQueuedTelegramItemsStatus,
|
|
372
|
+
getRecentRuntimeEvents: runtimeEvents.getEvents,
|
|
373
|
+
getRuntimeLockState: lockRuntime.getStatusLabel,
|
|
374
|
+
...threadStatusProjectionRuntime,
|
|
375
|
+
getBusProtocol() {
|
|
376
|
+
return telegramBusProtocolIdentity;
|
|
377
|
+
},
|
|
378
|
+
getBusLifecyclePhase: telegramBusFollowerControlState.getLifecyclePhase,
|
|
379
|
+
getBotThreadMode() {
|
|
380
|
+
return threadStore.getBotState();
|
|
381
|
+
},
|
|
382
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
383
|
+
getThreadReconciliationState() {
|
|
384
|
+
return threadReconciliationRuntime.getState();
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
runtimeDiagnostics.bindStatus({
|
|
388
|
+
instanceId: telegramInstanceId,
|
|
389
|
+
updateStatus: statusRuntime.updateStatus,
|
|
390
|
+
getStatusState: statusRuntime.getStatusState,
|
|
391
|
+
async persistSnapshot(snapshot) {
|
|
392
|
+
threadStore.setStatusSnapshot(snapshot);
|
|
393
|
+
await threadStore.persist();
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
const updateStatus = runtimeDiagnostics.updateStatus;
|
|
397
|
+
const getStatusLines = runtimeDiagnostics.getStatusLines;
|
|
398
|
+
const inboundHandlerRuntime = Inbound.createTelegramInboundHandlerRuntime({
|
|
399
|
+
getHandlers: configStore.getInboundHandlers,
|
|
400
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
401
|
+
getCwd: Pi.getExtensionContextCwd,
|
|
402
|
+
recordRuntimeEvent,
|
|
403
|
+
});
|
|
404
|
+
// --- Telegram API ---
|
|
405
|
+
const directTelegramApiRuntime = TelegramApi.createDefaultTelegramBridgeApiRuntime({
|
|
406
|
+
getBotToken: configStore.getBotToken,
|
|
407
|
+
recordRuntimeEvent,
|
|
408
|
+
targetActivity: telegramApiTargetActivityRuntime,
|
|
409
|
+
workspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
410
|
+
captureRequestErrorHandler(body) {
|
|
411
|
+
return Sync.captureTelegramStaleTargetRequestRecovery(body, {
|
|
412
|
+
...staleTopicApiErrorRecoveryDeps,
|
|
413
|
+
getCurrentLeaderEpoch,
|
|
414
|
+
getSessionGeneration: telegramSessionContextStore.getGeneration,
|
|
415
|
+
getProfileName: configStore.getActiveProfileName,
|
|
416
|
+
onRecovered: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
const telegramBusFollowerClients = BusFollower.createTelegramBusFollowerClientRuntime({
|
|
421
|
+
socketPath: getTelegramBusSocketPath,
|
|
422
|
+
instanceId: telegramInstanceId,
|
|
423
|
+
getApiAuthSecret: telegramBusFollowerControlState.getActiveAuthSecret,
|
|
424
|
+
getForwardingAuthSecret() {
|
|
425
|
+
return telegramBusAuthSecret;
|
|
426
|
+
},
|
|
427
|
+
getRegistrationGeneration: telegramBusFollowerRegistrationState.getGeneration,
|
|
428
|
+
waitForRegistrationGeneration: telegramBusFollowerRegistrationState.waitForGeneration,
|
|
429
|
+
getForwardCommentBatchPosition: textGroupRuntime.getPreparedForwardingPosition,
|
|
430
|
+
validateForwardOwnership: Bus.createTelegramBusForwardOwnershipValidator(telegramBusFollowerRegistry),
|
|
431
|
+
recordRuntimeEvent,
|
|
432
|
+
});
|
|
433
|
+
const telegramApiRuntime = BusApi.createTelegramBusAwareApiRuntime({
|
|
434
|
+
directRuntime: directTelegramApiRuntime,
|
|
435
|
+
ownsDirect() {
|
|
436
|
+
return lockRuntime.owns();
|
|
437
|
+
},
|
|
438
|
+
getDefaultTarget: proactivePushTargetGetter,
|
|
439
|
+
callFollowerApi: telegramBusFollowerClients.callApi,
|
|
440
|
+
});
|
|
441
|
+
const { call: callTelegramApi, callMultipart, deleteWebhook, getUpdates, setMyCommands, sendTypingAction, sendChatAction, sendRecordVoiceAction, sendMessageDraft, sendMessage, sendRichMessage, sendRichMessageDraft, downloadFile: downloadTelegramBridgeFile, editMessageText: editTelegramMessageText, editMessageReplyMarkup: editTelegramMessageReplyMarkup, answerCallbackQuery, answerGuestQuery, deleteMessage: deleteTelegramMessage, prepareTempDir, } = telegramApiRuntime;
|
|
442
|
+
// --- Message Delivery ---
|
|
443
|
+
const sendGuestReply = Replies.createGuestMarkdownReplySender({
|
|
444
|
+
answerGuestQuery,
|
|
445
|
+
});
|
|
446
|
+
// Answer guest queries immediately and replace the ACK with the final text.
|
|
447
|
+
const answerGuestQueryForInlineMessage = telegramApiRuntime.answerGuestQueryForInlineMessage;
|
|
448
|
+
const editGuestReply = Replies.createGuestMarkdownReplyEditor({
|
|
449
|
+
editGuestInlineMessage: telegramApiRuntime.editGuestInlineMessage,
|
|
450
|
+
});
|
|
451
|
+
// Rotate the guest placeholder frames until the final replacement stops them.
|
|
452
|
+
const guestPlaceholderRuntime = Replies.createTelegramGuestPlaceholderRuntime({
|
|
453
|
+
editGuestInlineMessage: telegramApiRuntime.editGuestInlineMessage,
|
|
454
|
+
recordRuntimeEvent,
|
|
455
|
+
});
|
|
456
|
+
const promptDispatchRuntime = Runtime.createTelegramPromptDispatchRuntime({
|
|
457
|
+
lifecycle,
|
|
458
|
+
typing,
|
|
459
|
+
getDefaultChatId: proactivePushChatIdGetter,
|
|
460
|
+
sendTypingAction,
|
|
461
|
+
sendAggregateTypingAction: BusApi.createTelegramAggregateTypingActionSender(telegramApiRuntime),
|
|
462
|
+
updateStatus,
|
|
463
|
+
isContextActive: telegramSessionContextStore.isCurrent,
|
|
464
|
+
getTransportAuthority() {
|
|
465
|
+
if (ownsTelegramDirectDelivery()) {
|
|
466
|
+
const epoch = getCurrentLeaderEpoch();
|
|
467
|
+
return epoch === undefined ? undefined : `direct:${epoch}`;
|
|
468
|
+
}
|
|
469
|
+
if (!telegramBusFollowerRegistrationState.isRegistered())
|
|
470
|
+
return undefined;
|
|
471
|
+
const generation = telegramBusFollowerRegistrationState.getGeneration();
|
|
472
|
+
return generation ? `follower:${generation}` : undefined;
|
|
473
|
+
},
|
|
474
|
+
recordRuntimeEvent,
|
|
475
|
+
});
|
|
476
|
+
const currentModelRuntime = Model.createCurrentModelRuntime({
|
|
477
|
+
getContextModel,
|
|
478
|
+
updateStatus,
|
|
479
|
+
});
|
|
480
|
+
// --- Reply Runtime & Preview ---
|
|
481
|
+
const replyRuntime = Replies.createTelegramRenderedMessageDeliveryRuntime({
|
|
482
|
+
recordOwnership: messageOwnershipRuntime.recordLocal,
|
|
483
|
+
sendMessage,
|
|
484
|
+
sendRichMessage,
|
|
485
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
486
|
+
editMessage: editTelegramMessageText,
|
|
487
|
+
});
|
|
488
|
+
const { replyTransport, editInteractiveMessage, sendInteractiveMessage, sendSectionRichMessage, } = replyRuntime;
|
|
489
|
+
const deliveryTargetPolicyRuntime = Delivery.createTelegramDeliveryTargetPolicyRuntime({
|
|
490
|
+
ownsDirect: lockRuntime.owns,
|
|
491
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
492
|
+
getAllowedChatId: configStore.getAllowedUserId,
|
|
493
|
+
getFollowerTarget: telegramBusFollowerRegistrationState.getTarget,
|
|
494
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
495
|
+
listThreadRecords: threadStore.list,
|
|
496
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
497
|
+
getActiveGuestQueryId: activeTurnRuntime.getGuestQueryId,
|
|
498
|
+
});
|
|
499
|
+
const deliveryGenerationSeed = Delivery.createTelegramDeliveryGenerationSeed(telegramInstanceId);
|
|
500
|
+
const deliveryLifecycleRuntime = Delivery.createTelegramBridgeDeliveryLifecycleHooks({
|
|
501
|
+
generationSeed: deliveryGenerationSeed,
|
|
502
|
+
getTargetPolicyView: deliveryTargetPolicyRuntime.getTargetPolicyView,
|
|
503
|
+
getTransportStamp: telegramTransportStampRuntime.getStamp,
|
|
504
|
+
isTransportStampActive: telegramTransportStampRuntime.isActive,
|
|
505
|
+
getActiveTurnTarget: deliveryTargetPolicyRuntime.getActiveTurnTarget,
|
|
506
|
+
api: telegramApiRuntime,
|
|
507
|
+
recordOwnership: messageOwnershipRuntime.recordLocal,
|
|
508
|
+
recordFailure(operation, error, target) {
|
|
509
|
+
recordRuntimeEvent("delivery", error, {
|
|
510
|
+
operation,
|
|
511
|
+
scope: target?.threadId === undefined ? "aggregate" : "thread",
|
|
512
|
+
});
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
const { sendTextReply, sendMarkdownReply } = Outbound.createTelegramOutboundTextReplyRuntime({
|
|
516
|
+
sendTextReply: replyRuntime.sendTextReply,
|
|
517
|
+
sendMarkdownReply: replyRuntime.sendMarkdownReply,
|
|
518
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
519
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
520
|
+
recordRuntimeEvent,
|
|
521
|
+
});
|
|
522
|
+
const generativeAppLiveSurfaceBinding = Bindings.createTelegramGenerativeAppLiveSurfaceBinding();
|
|
523
|
+
const invokeGenerativeAppBoundButtonAction = Bindings.createTelegramGenerativeAppBoundButtonActionInvoker({
|
|
524
|
+
agentDir: Paths.resolveAgentDir(),
|
|
525
|
+
assertExecutionCurrent: Updates.assertTelegramUpdateExecutionCurrent,
|
|
526
|
+
getExecutionFence: Updates.getTelegramUpdateExecutionFence,
|
|
527
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
528
|
+
getLiveSurfaceRuntime: generativeAppLiveSurfaceBinding.get,
|
|
529
|
+
planOutput: planGenerativeAppOutput,
|
|
530
|
+
sendMarkdownReply,
|
|
531
|
+
editInteractiveMessage,
|
|
532
|
+
recordRuntimeEvent,
|
|
533
|
+
});
|
|
534
|
+
const nativeMarkdownDraftSender = TelegramApi.createTelegramAssistantDraftSender({
|
|
535
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
536
|
+
renderMarkdownToHtmlDraft: Replies.renderTelegramMarkdownToHtmlDraft,
|
|
537
|
+
sendMessageDraft,
|
|
538
|
+
sendRichMessageDraft,
|
|
539
|
+
});
|
|
540
|
+
const previewRuntime = Preview.createTelegramAssistantPreviewRuntime({
|
|
541
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
542
|
+
isAssistantMessage: Replies.isAssistantAgentMessage,
|
|
543
|
+
getMessageText: Replies.getAgentMessageText,
|
|
544
|
+
getDefaultReplyToMessageId: activeTurnRuntime.getReplyToMessageId,
|
|
545
|
+
sendDraft: nativeMarkdownDraftSender,
|
|
546
|
+
canSend: configControls.areDraftPreviewsEnabled,
|
|
547
|
+
sendMarkdownReply,
|
|
548
|
+
recordRuntimeEvent,
|
|
549
|
+
...replyTransport,
|
|
550
|
+
});
|
|
551
|
+
const { activityRuntime, activityVerbosityRuntime, assistantOutputRuntime, publicationRuntime, } = Bindings.createTelegramActivityBindingRuntime({
|
|
552
|
+
generation: deliveryGenerationSeed,
|
|
553
|
+
assistantOutput: {
|
|
554
|
+
prepareTelegramPreview: previewRuntime.preparePublication,
|
|
555
|
+
authority: {
|
|
556
|
+
getPreferredTarget: proactivePushTargetGetter,
|
|
557
|
+
getFallbackChatId: proactivePushChatIdGetter,
|
|
558
|
+
getTransportStamp: telegramTransportStampRuntime.getStamp,
|
|
559
|
+
isTransportStampActive: telegramTransportStampRuntime.isActive,
|
|
560
|
+
ownsDirect: lockRuntime.owns,
|
|
561
|
+
getDirectEpoch: lockRuntime.getOwnedLeaderEpoch,
|
|
562
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
563
|
+
getFollowerGeneration: telegramBusFollowerRegistrationState.getGeneration,
|
|
564
|
+
},
|
|
565
|
+
sender: {
|
|
566
|
+
recordOwnership: messageOwnershipRuntime.recordLocal,
|
|
567
|
+
sendMessage,
|
|
568
|
+
sendRichMessage,
|
|
569
|
+
editMessage: editTelegramMessageText,
|
|
570
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
571
|
+
planButtonReply: Outbound.createTelegramButtonReplyPlanner(buttonActionStore),
|
|
572
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
573
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
574
|
+
recordRuntimeEvent,
|
|
575
|
+
},
|
|
576
|
+
recordRuntimeEvent,
|
|
577
|
+
},
|
|
578
|
+
activityVerbosity: {
|
|
579
|
+
getActivityMode: configControls.getActivityVerbosity,
|
|
580
|
+
refreshActivityMode: configControls.refreshActivityVerbosity,
|
|
581
|
+
resolveTarget(event) {
|
|
582
|
+
return event.target ?? proactivePushTargetGetter();
|
|
583
|
+
},
|
|
584
|
+
sendMessage,
|
|
585
|
+
sendRichMessage,
|
|
586
|
+
editMessageText: editTelegramMessageText,
|
|
587
|
+
},
|
|
588
|
+
});
|
|
589
|
+
const { mutation: queueMutationRuntime, dispatchNext: dispatchNextQueuedTelegramTurn, requestNextDispatchAnnouncement, watchdog: queueDispatchWatchdogRuntime, } = Bindings.createTelegramQueueBindingRuntime({
|
|
590
|
+
store: telegramQueueStore,
|
|
591
|
+
queue,
|
|
592
|
+
lifecycle,
|
|
593
|
+
activeTurn: activeTurnRuntime,
|
|
594
|
+
admission: updateAdmissionRuntimeBinding,
|
|
595
|
+
transportStamp: telegramTransportStampRuntime,
|
|
596
|
+
deferredDispatch: deferredQueueDispatchRuntime,
|
|
597
|
+
promptDispatch: promptDispatchRuntime,
|
|
598
|
+
isIdle,
|
|
599
|
+
hasPendingMessages,
|
|
600
|
+
updateStatus,
|
|
601
|
+
sendTextReply,
|
|
602
|
+
sendUserMessage,
|
|
603
|
+
recordRuntimeEvent,
|
|
604
|
+
});
|
|
605
|
+
const { finalizeMarkdownPreview, preparePreviewDelivery } = Outbound.createTelegramOutboundTextPreviewRuntime({
|
|
606
|
+
finalizeMarkdownPreview: previewRuntime.finalizeMarkdown,
|
|
607
|
+
preparePreviewDelivery: previewRuntime.prepareDelivery,
|
|
608
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
609
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
610
|
+
recordRuntimeEvent,
|
|
611
|
+
});
|
|
612
|
+
// --- Model And Menu Setup ---
|
|
613
|
+
const modelSwitchController = Model.createTelegramModelSwitchControllerRuntime({
|
|
614
|
+
isIdle,
|
|
615
|
+
getPendingModelSwitch: pendingModelSwitchStore.get,
|
|
616
|
+
setPendingModelSwitch: pendingModelSwitchStore.set,
|
|
617
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
618
|
+
getAbortHandler: abort.getHandler,
|
|
619
|
+
hasAbortHandler: abort.hasHandler,
|
|
620
|
+
getActiveToolExecutions: lifecycle.getActiveToolExecutions,
|
|
621
|
+
allocateItemOrder: queue.allocateItemOrder,
|
|
622
|
+
allocateControlOrder: queue.allocateControlOrder,
|
|
623
|
+
appendQueuedItem: queueMutationRuntime.append,
|
|
624
|
+
updateStatus,
|
|
625
|
+
});
|
|
626
|
+
const getQueueItemCount = Queue.createTelegramQueueItemCountGetter(telegramQueueStore);
|
|
627
|
+
const getPromptTemplateCommands = PromptTemplates.createTelegramPromptTemplateCommandGetter({
|
|
628
|
+
getCommands,
|
|
629
|
+
getReservedCommandNames: Commands.getTelegramReservedCommandNames,
|
|
630
|
+
});
|
|
631
|
+
const menuActions = Menu.createTelegramMenuActionRuntimeWithStateBuilder({
|
|
632
|
+
runtime: modelMenuRuntime,
|
|
633
|
+
createSettingsManager: Pi.createSettingsManager,
|
|
634
|
+
getActiveModel: currentModelRuntime.get,
|
|
635
|
+
getThinkingLevel,
|
|
636
|
+
getQueueItemCount,
|
|
637
|
+
buildStatusHtml: Commands.createTelegramAppMenuHtmlBuilder({
|
|
638
|
+
buildStatusHtml: Status.createTelegramStatusHtmlBuilder({
|
|
639
|
+
getActiveModel: currentModelRuntime.get,
|
|
640
|
+
isCompactionInProgress: lifecycle.isCompactionInProgress,
|
|
641
|
+
getBridgeStatusLineState: statusRuntime.getStatusState,
|
|
642
|
+
}),
|
|
643
|
+
getPromptTemplateCommands,
|
|
644
|
+
}),
|
|
645
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
646
|
+
isIdle,
|
|
647
|
+
canOfferInFlightModelSwitch: modelSwitchController.canOfferInFlightSwitch,
|
|
648
|
+
sendTextReply,
|
|
649
|
+
editInteractiveMessage,
|
|
650
|
+
sendInteractiveMessage,
|
|
651
|
+
sectionRegistry,
|
|
652
|
+
// Menu/status UI uses this to reflect whether the active Telegram turn expects voice delivery.
|
|
653
|
+
isVoiceReplyActive: function () {
|
|
654
|
+
const turn = activeTurnRuntime.get();
|
|
655
|
+
return Voice.isVoiceTurn(turn);
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
// --- Queue And Settings Menus ---
|
|
659
|
+
const getQueueMenuState = Menu.createTelegramModelMenuStateBuilder({
|
|
660
|
+
runtime: modelMenuRuntime,
|
|
661
|
+
createSettingsManager: Pi.createSettingsManager,
|
|
662
|
+
getActiveModel: currentModelRuntime.get,
|
|
663
|
+
});
|
|
664
|
+
const queueMenuRuntime = MenuQueue.createTelegramQueueMenuRuntime({
|
|
665
|
+
telegramQueueStore,
|
|
666
|
+
queueMutationRuntime,
|
|
667
|
+
sendInteractiveMessage,
|
|
668
|
+
editInteractiveMessage,
|
|
669
|
+
answerCallbackQuery,
|
|
670
|
+
getModelMenuState: getQueueMenuState,
|
|
671
|
+
getStoredModelMenuState: modelMenuRuntime.getState,
|
|
672
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
673
|
+
updateStatusMessage: menuActions.updateStatusMessage,
|
|
674
|
+
updateStatus,
|
|
675
|
+
});
|
|
676
|
+
const settingsMenuRuntime = MenuSettings.createTelegramSettingsMenuRuntime({
|
|
677
|
+
reloadConfig: configStore.load,
|
|
678
|
+
getModelMenuState: getQueueMenuState,
|
|
679
|
+
getStoredModelMenuState: modelMenuRuntime.getState,
|
|
680
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
681
|
+
editInteractiveMessage,
|
|
682
|
+
sendInteractiveMessage,
|
|
683
|
+
answerCallbackQuery,
|
|
684
|
+
...configControls,
|
|
685
|
+
reviewInactiveThreads: inactiveThreadCleanupReviewRuntime.review,
|
|
686
|
+
getThreadDisplayMode() {
|
|
687
|
+
return threadStore.getBotState().threadMode === "enabled"
|
|
688
|
+
? Config.resolveTelegramThreadDisplayMode(configStore.get()) : undefined;
|
|
689
|
+
},
|
|
690
|
+
async setThreadDisplayMode(mode) {
|
|
691
|
+
try {
|
|
692
|
+
await ThreadDisplay.applyTelegramThreadDisplaySetting(mode, {
|
|
693
|
+
getProfileKey: configStore.getActiveProfileName,
|
|
694
|
+
ownsLeader() { return getCurrentLeaderEpoch() !== undefined; },
|
|
695
|
+
getLeaderSetter() { return telegramBusLeaderRuntime.setThreadDisplayMode; },
|
|
696
|
+
getFollowerSetter() { return telegramBusFollowerRegistration.setThreadDisplayMode; },
|
|
697
|
+
reloadConfig: configStore.load,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
recordRuntimeEvent("bus", error, { phase: "thread-display-setting" });
|
|
702
|
+
throw error;
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
}, sectionRegistry);
|
|
706
|
+
// --- Polling ---
|
|
707
|
+
const foreignOwnedUpdateForwarder = telegramBusFollowerClients.foreignOwnedUpdateForwarder;
|
|
708
|
+
const followerTargetController = telegramBusFollowerClients.targetController;
|
|
709
|
+
const restoreFollowerThreadTarget = Bus.createTelegramBusFollowerThreadRestoreHandler({
|
|
710
|
+
followerRegistry: telegramBusFollowerRegistry,
|
|
711
|
+
followerTargetController,
|
|
712
|
+
onRestored() {
|
|
713
|
+
telegramSyncStateRuntime.markSliceFresh(Sync.TELEGRAM_SYNC_SLICE_TARGET_BINDINGS, {
|
|
714
|
+
nowMs: Date.now(),
|
|
715
|
+
action: "follower-thread-restore",
|
|
716
|
+
});
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
const observedThreadTargetBinding = Polling.createTelegramThreadTargetObservationBinding();
|
|
720
|
+
const topicLifecycleSync = Sync.createTelegramObservedTopicLifecycleSyncHandler({
|
|
721
|
+
topicTargetStore: threadStore,
|
|
722
|
+
isBusEnabled: isTelegramBusRuntimeEnabled,
|
|
723
|
+
callApi: callTelegramApi,
|
|
724
|
+
isTopicProvisioningActive: telegramProvisioningActivity.isActive,
|
|
725
|
+
getCurrentLeaderEpoch,
|
|
726
|
+
getThreadReconciliationMachineState: threadReconciliationRuntime.getState,
|
|
727
|
+
recordThreadReconciliationPlan,
|
|
728
|
+
runWorkspaceOperation: telegramWorkspaceOperationRuntime.run,
|
|
729
|
+
assertExecutionCurrent(message) {
|
|
730
|
+
Updates.assertTelegramUpdateExecutionCurrent(message);
|
|
731
|
+
},
|
|
732
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
733
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
734
|
+
recordEvent: recordRuntimeEvent,
|
|
735
|
+
});
|
|
736
|
+
const inboundBusProjectionRuntime = Routing.createTelegramInboundBusProjectionRuntime({
|
|
737
|
+
instanceId: telegramInstanceId,
|
|
738
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
739
|
+
listThreadRecords: threadStore.list,
|
|
740
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
741
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
742
|
+
getFollowerTarget: telegramBusFollowerRegistrationState.getTarget,
|
|
743
|
+
getCurrentIdentity: getCurrentInstanceThreadIdentity,
|
|
744
|
+
});
|
|
745
|
+
const telegramThreadDisplayNameRenameBinding = Commands.createTelegramThreadDisplayNameRenameBinding();
|
|
746
|
+
const telegramThreadDisplayNameResetBinding = Commands.createTelegramThreadDisplayNameResetBinding();
|
|
747
|
+
const inboundRouteRuntime = Routing.createTelegramInboundRouteRuntime({
|
|
748
|
+
configStore,
|
|
749
|
+
callApi: callTelegramApi,
|
|
750
|
+
getCurrentInstanceId() {
|
|
751
|
+
return telegramInstanceId;
|
|
752
|
+
},
|
|
753
|
+
getAdmissionScope: getTelegramUpdateAdmissionScope,
|
|
754
|
+
getAdmissionJournalBinding: getTelegramQueueJournalBinding,
|
|
755
|
+
getMessageOwnership: messageOwnershipRuntime.getForwardOwnership,
|
|
756
|
+
recordMessageOwnership: messageOwnershipRuntime.recordRouted,
|
|
757
|
+
...inboundBusProjectionRuntime,
|
|
758
|
+
getDisplayTitle: getThreadDisplayTitle,
|
|
759
|
+
getCurrentLeaderEpoch,
|
|
760
|
+
setCurrentLeaderIdentity: telegramBusLeaderState.set,
|
|
761
|
+
getThreadReconciliationMachineState: threadReconciliationRuntime.getState,
|
|
762
|
+
recordThreadReconciliationPlan,
|
|
763
|
+
handleTelegramTopicLifecycleUpdate: topicLifecycleSync,
|
|
764
|
+
handleTelegramThreadTargetObserved(_target, ctx) {
|
|
765
|
+
return observedThreadTargetBinding.handle(ctx);
|
|
766
|
+
},
|
|
767
|
+
foreignOwnedUpdateForwarder,
|
|
768
|
+
replaceFollowerThreadTarget: restoreFollowerThreadTarget,
|
|
769
|
+
bridgeRuntime,
|
|
770
|
+
activeTurnRuntime,
|
|
771
|
+
mediaGroupRuntime,
|
|
772
|
+
textGroupRuntime,
|
|
773
|
+
telegramQueueStore,
|
|
774
|
+
queueMutationRuntime,
|
|
775
|
+
modelMenuRuntime,
|
|
776
|
+
currentModelRuntime,
|
|
777
|
+
modelSwitchController,
|
|
778
|
+
menuActions,
|
|
779
|
+
updateSettingsMenuMessage: settingsMenuRuntime.updateSettingsMenuMessage,
|
|
780
|
+
openQueueMenu: queueMenuRuntime.openQueueMenu,
|
|
781
|
+
queueMenuCallbackHandler: queueMenuRuntime.handleCallbackQuery,
|
|
782
|
+
openSettingsMenu: settingsMenuRuntime.openSettingsMenu,
|
|
783
|
+
settingsMenuCallbackHandler: settingsMenuRuntime.handleCallbackQuery,
|
|
784
|
+
sectionRegistry,
|
|
785
|
+
sendSectionRichMessage,
|
|
786
|
+
buttonActionStore,
|
|
787
|
+
invokeBoundButtonAction: invokeGenerativeAppBoundButtonAction,
|
|
788
|
+
inboundHandlerRuntime,
|
|
789
|
+
threadStore,
|
|
790
|
+
runWorkspaceOperation: telegramWorkspaceOperationRuntime.run,
|
|
791
|
+
updateStatus,
|
|
792
|
+
isContextActive: telegramSessionContextStore.isCurrent,
|
|
793
|
+
dispatchNextQueuedTelegramTurn,
|
|
794
|
+
requestNextDispatchAnnouncement,
|
|
795
|
+
requestDeferredDispatchNextQueuedTelegramTurn: deferredQueueDispatchRuntime.request,
|
|
796
|
+
hasDeferredDispatchContext: deferredQueueDispatchRuntime.isBound,
|
|
797
|
+
startTypingLoop: promptDispatchRuntime.startTypingLoop,
|
|
798
|
+
stopTypingLoop: typing.stop,
|
|
799
|
+
answerCallbackQuery,
|
|
800
|
+
editInteractiveMessage,
|
|
801
|
+
editMessageReplyMarkup: editTelegramMessageReplyMarkup,
|
|
802
|
+
sendInteractiveMessage,
|
|
803
|
+
deleteMessage: deleteTelegramMessage,
|
|
804
|
+
answerGuestQuery,
|
|
805
|
+
answerGuestQueryForInlineMessage,
|
|
806
|
+
startGuestPlaceholder: guestPlaceholderRuntime.start,
|
|
807
|
+
sendTextReply,
|
|
808
|
+
setMyCommands,
|
|
809
|
+
validateThreadName(threadName) {
|
|
810
|
+
return Threads.getTelegramManualThreadDisplayNameValidationError(threadName);
|
|
811
|
+
},
|
|
812
|
+
renameCurrentThread: telegramThreadDisplayNameRenameBinding.rename,
|
|
813
|
+
resetCurrentThreadName: telegramThreadDisplayNameResetBinding.reset,
|
|
814
|
+
getCommands,
|
|
815
|
+
downloadFile: downloadTelegramBridgeFile,
|
|
816
|
+
resolveTimeLine: timeInjectionRuntime.resolveLine,
|
|
817
|
+
getThinkingLevel,
|
|
818
|
+
setThinkingLevel,
|
|
819
|
+
persistScopedModelPatterns: Pi.createScopedModelPatternPersister({
|
|
820
|
+
createSettingsManager: Pi.createSettingsManager,
|
|
821
|
+
clearCachedModelMenuInputs: modelMenuRuntime.clearCachedInputs,
|
|
822
|
+
}),
|
|
823
|
+
setModel,
|
|
824
|
+
sendUserMessage,
|
|
825
|
+
isIdle,
|
|
826
|
+
hasPendingMessages,
|
|
827
|
+
compact,
|
|
828
|
+
recordRuntimeEvent,
|
|
829
|
+
});
|
|
830
|
+
const queueHandoffReconciliationBinding = Updates.createTelegramQueueHandoffReconciliationBinding(function (error) {
|
|
831
|
+
recordRuntimeEvent("inbound-worker", error, {
|
|
832
|
+
phase: "queue-handoff-reconcile",
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
const staleTopicApiErrorRecoveryDeps = {
|
|
836
|
+
topicTargetStore: threadStore,
|
|
837
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
838
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
839
|
+
recordEvent: recordRuntimeEvent,
|
|
840
|
+
getWorkspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
841
|
+
};
|
|
842
|
+
const recoverStaleTelegramTopicApiError = Sync.createTelegramStaleTopicApiErrorRecoveryRuntime(staleTopicApiErrorRecoveryDeps);
|
|
843
|
+
const { owner: updateWorkerOwnerRuntime, leader: updateAdmissionLifecycleRuntime, follower: followerAdmissionLifecycleRuntime, } = Updates.createTelegramUpdateAdmissionRuntimeAssembly({
|
|
844
|
+
runtimeBinding: updateAdmissionRuntimeBinding,
|
|
845
|
+
acquireSourceReference(role, binding) {
|
|
846
|
+
return telegramJournalReferenceRegistry.acquire({
|
|
847
|
+
referenceClass: role === "leader" ? "leader-lifecycle" : "follower-lifecycle",
|
|
848
|
+
recoveryKey: binding.recoveryKey,
|
|
849
|
+
});
|
|
850
|
+
},
|
|
851
|
+
owner: {
|
|
852
|
+
instanceId: telegramInstanceId,
|
|
853
|
+
processId: telegramProcessId,
|
|
854
|
+
processBirthId: telegramQueueProcessBirthId,
|
|
855
|
+
getSessionGeneration: telegramSessionContextStore.getGeneration,
|
|
856
|
+
isContextCurrent: telegramSessionContextStore.isCurrent,
|
|
857
|
+
dispatchNext: dispatchNextQueuedTelegramTurn,
|
|
858
|
+
requestQueueHandoffReconciliation: queueHandoffReconciliationBinding.request,
|
|
859
|
+
},
|
|
860
|
+
worker: {
|
|
861
|
+
defaultHandle: inboundRouteRuntime.handleUpdate,
|
|
862
|
+
onStateChange: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
863
|
+
settleTerminalExecutionFailure(error) {
|
|
864
|
+
return Sync.settleStaleTelegramTopicExecutionFailure(error, staleTopicApiErrorRecoveryDeps);
|
|
865
|
+
},
|
|
866
|
+
},
|
|
867
|
+
leader: {
|
|
868
|
+
resolveBinding: resolveTelegramUpdateJournalBinding,
|
|
869
|
+
hasAuthority: lockRuntime.owns,
|
|
870
|
+
},
|
|
871
|
+
follower: {
|
|
872
|
+
resolveBinding: resolveTelegramFollowerJournalBinding,
|
|
873
|
+
isRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
874
|
+
getGeneration: telegramBusFollowerRegistrationState.getGeneration,
|
|
875
|
+
prepareUpdateForExecution(update) {
|
|
876
|
+
return BusFollower.prepareTelegramBusFollowerJournaledUpdateForExecution(update, textGroupRuntime.prepareForwardedMessage);
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
recordRuntimeEvent,
|
|
880
|
+
});
|
|
881
|
+
const queueHandoffStagingRuntime = Queue.createTelegramQueueHandoffStagingRuntime({
|
|
882
|
+
liveStore: telegramQueueStore,
|
|
883
|
+
createControlExecution: Updates.createTelegramQueueHandoffControlExecutionFactory({
|
|
884
|
+
isContextCurrent: telegramSessionContextStore.isCurrent,
|
|
885
|
+
showStatus: menuActions.sendStatusMessage,
|
|
886
|
+
openModelMenu: menuActions.openModelMenu,
|
|
887
|
+
}),
|
|
888
|
+
});
|
|
889
|
+
const acceptStagedQueueHandoff = Updates.createTelegramQueueHandoffRecipientRuntime({
|
|
890
|
+
staging: queueHandoffStagingRuntime,
|
|
891
|
+
getRecipientOwner: updateWorkerOwnerRuntime.getQueueOwnerIdentity,
|
|
892
|
+
getLifecycleForBinding: updateAdmissionRuntimeBinding.getLifecycleForJournalBinding,
|
|
893
|
+
isTransportStampActive: telegramTransportStampRuntime.isActive,
|
|
894
|
+
dispatchNext: dispatchNextQueuedTelegramTurn,
|
|
895
|
+
});
|
|
896
|
+
const followerDurableAdmissionRuntime = BusFollower.createTelegramBusFollowerDurableAdmissionRuntime({
|
|
897
|
+
journal: {
|
|
898
|
+
appendBatch(updates) {
|
|
899
|
+
return followerAdmissionLifecycleRuntime.appendBatch(updates);
|
|
900
|
+
},
|
|
901
|
+
},
|
|
902
|
+
signalWorker() {
|
|
903
|
+
followerAdmissionLifecycleRuntime.signal();
|
|
904
|
+
},
|
|
905
|
+
});
|
|
906
|
+
const promoteTelegramBusFollowerToLeader = BusFollower.createTelegramBusFollowerPromotionHandler({
|
|
907
|
+
topicTargetStore: threadStore,
|
|
908
|
+
instanceId: telegramInstanceId,
|
|
909
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
910
|
+
getSessionId: Pi.getExtensionContextSessionId,
|
|
911
|
+
getWorkspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
912
|
+
async startLeader(ctx, election, onAcquired) {
|
|
913
|
+
const result = await lockedPollingRuntime.start(ctx, {
|
|
914
|
+
election,
|
|
915
|
+
onAcquired,
|
|
916
|
+
});
|
|
917
|
+
return result.ok;
|
|
918
|
+
},
|
|
919
|
+
recordRuntimeEvent,
|
|
920
|
+
});
|
|
921
|
+
const agentMessageRuntime = AgentMessages.createTelegramAgentMessageRuntime({
|
|
922
|
+
instanceId: telegramInstanceId,
|
|
923
|
+
getAllowedChatId: configStore.getAllowedUserId,
|
|
924
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
925
|
+
getLeaderThreadName() {
|
|
926
|
+
return findCurrentThreadRecord()?.threadName;
|
|
927
|
+
},
|
|
928
|
+
followerRegistry: telegramBusFollowerRegistry,
|
|
929
|
+
getDisplayTitle: getThreadDisplayTitle,
|
|
930
|
+
getContext: telegramSessionContextStore.get,
|
|
931
|
+
handleUpdate: inboundRouteRuntime.handleUpdate,
|
|
932
|
+
});
|
|
933
|
+
const agentMessageToolRoutingRuntime = Bindings.createTelegramAgentMessageToolRoutingRuntime({
|
|
934
|
+
ownsLeader: lockRuntime.owns,
|
|
935
|
+
ownsDirectDelivery: ownsTelegramDirectDelivery,
|
|
936
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
937
|
+
getSourceTarget: proactivePushTargetGetter,
|
|
938
|
+
getSourceThreadName() {
|
|
939
|
+
return findCurrentThreadRecord()?.threadName;
|
|
940
|
+
},
|
|
941
|
+
local: agentMessageRuntime,
|
|
942
|
+
follower: telegramBusFollowerClients.agentMessages,
|
|
943
|
+
});
|
|
944
|
+
const telegramBusFollowerAssembly = BusFollower.createTelegramBusFollowerRuntimeAssembly({
|
|
945
|
+
instanceId: telegramInstanceId,
|
|
946
|
+
registrationState: telegramBusFollowerRegistrationState,
|
|
947
|
+
recordRuntimeEvent,
|
|
948
|
+
receiver: {
|
|
949
|
+
socketPath: getTelegramBusFollowerSocketPath,
|
|
950
|
+
getContext: telegramSessionContextStore.get,
|
|
951
|
+
getAuthSecret: telegramBusFollowerControlState.getActiveAuthSecret,
|
|
952
|
+
getRecipientBindingKey: getTelegramManualFollowerProfileKey,
|
|
953
|
+
durableAdmission: followerDurableAdmissionRuntime,
|
|
954
|
+
handleQueueHandoff: acceptStagedQueueHandoff,
|
|
955
|
+
},
|
|
956
|
+
targetReplacement: {
|
|
957
|
+
topicTargetStore: threadStore,
|
|
958
|
+
getManualFollowerProfileKey: getTelegramManualFollowerProfileKey,
|
|
959
|
+
manualFollowerOwnerId: telegramManualFollowerOwnerId,
|
|
960
|
+
getWorkspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
961
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
962
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
963
|
+
updateStatus,
|
|
964
|
+
},
|
|
965
|
+
recovery: {
|
|
966
|
+
getLeaderState: lockRuntime.getState,
|
|
967
|
+
setLifecyclePhase: telegramBusFollowerControlState.setLifecyclePhase,
|
|
968
|
+
updateStatus,
|
|
969
|
+
promoteToLeader: promoteTelegramBusFollowerToLeader,
|
|
970
|
+
getActiveContext: telegramSessionContextStore.get,
|
|
971
|
+
},
|
|
972
|
+
registration: {
|
|
973
|
+
protocolIdentity: telegramBusProtocolIdentity,
|
|
974
|
+
getFollowerBusSocketPath: getTelegramBusFollowerSocketPath,
|
|
975
|
+
getLeaderSocketPath: getTelegramBusSocketPath,
|
|
976
|
+
isContextActive: telegramSessionContextStore.isCurrent,
|
|
977
|
+
createRequestId: telegramBusFollowerClients.createRequestId,
|
|
978
|
+
setActiveAuthSecret: telegramBusFollowerControlState.setActiveAuthSecret,
|
|
979
|
+
getProfileKey: getTelegramManualFollowerProfileKey,
|
|
980
|
+
getThreadName() {
|
|
981
|
+
return telegramThreadCapabilityState.getRequestedThreadName();
|
|
982
|
+
},
|
|
983
|
+
getProcessBirthId() {
|
|
984
|
+
return telegramQueueProcessBirthId;
|
|
985
|
+
},
|
|
986
|
+
getSessionId: Pi.getExtensionContextSessionId,
|
|
987
|
+
getSessionGeneration: telegramSessionContextStore.getGeneration,
|
|
988
|
+
async onRegistered(ctx) {
|
|
989
|
+
await followerAdmissionLifecycleRuntime.onTransportChanged(ctx);
|
|
990
|
+
queueHandoffReconciliationBinding.request(ctx);
|
|
991
|
+
},
|
|
992
|
+
onDisplayTitleChanged: updateStatus,
|
|
993
|
+
},
|
|
994
|
+
});
|
|
995
|
+
const telegramBusFollowerRegistration = telegramBusFollowerAssembly.registration;
|
|
996
|
+
const { admission: pollingAdmissionRuntime } = Polling.createTelegramDurablePollingRuntimeAssembly({
|
|
997
|
+
state: pollingControllerState,
|
|
998
|
+
canStart(ctx) {
|
|
999
|
+
return telegramSessionContextStore.isCurrent(ctx) && lockRuntime.owns(ctx);
|
|
1000
|
+
},
|
|
1001
|
+
onPersistentConflict(ctx, count) {
|
|
1002
|
+
return lockedPollingRuntime.onPersistentConflict(ctx, count);
|
|
1003
|
+
},
|
|
1004
|
+
getConfig: configStore.get,
|
|
1005
|
+
hasBotToken: configStore.hasBotToken,
|
|
1006
|
+
deleteWebhook,
|
|
1007
|
+
getUpdates,
|
|
1008
|
+
persistConfig: persistTelegramConfigWithSync,
|
|
1009
|
+
prepareUpdateBatch: textGroupRuntime.prepareUpdateBatch,
|
|
1010
|
+
journal: {
|
|
1011
|
+
appendBatch(updates, acceptedThroughUpdateId) {
|
|
1012
|
+
return updateAdmissionLifecycleRuntime.appendBatch(updates, acceptedThroughUpdateId);
|
|
1013
|
+
},
|
|
1014
|
+
getAcceptedThroughUpdateId() {
|
|
1015
|
+
return Journal.withTelegramResolvedUpdateJournalReference({
|
|
1016
|
+
registry: telegramJournalReferenceRegistry,
|
|
1017
|
+
resolveBinding: resolveTelegramUpdateJournalBinding,
|
|
1018
|
+
referenceClass: "polling-cursor",
|
|
1019
|
+
operation(binding) { return binding.journal.read().acceptedThroughUpdateId; },
|
|
1020
|
+
});
|
|
1021
|
+
},
|
|
1022
|
+
async prepareCursorCutover() {
|
|
1023
|
+
const cutover = Journal.withTelegramResolvedUpdateJournalReference({
|
|
1024
|
+
registry: telegramJournalReferenceRegistry,
|
|
1025
|
+
resolveBinding: resolveTelegramUpdateJournalBinding,
|
|
1026
|
+
referenceClass: "polling-cursor",
|
|
1027
|
+
operation(binding) {
|
|
1028
|
+
return Polling.cutOverTelegramPollingCursor({
|
|
1029
|
+
getLegacyCursor: configStore.getLegacyPollingCursor,
|
|
1030
|
+
readJournal: binding.journal.read,
|
|
1031
|
+
publishJournalCursor(acceptedThroughUpdateId) {
|
|
1032
|
+
binding.journal.appendBatch([], acceptedThroughUpdateId);
|
|
1033
|
+
},
|
|
1034
|
+
async removeLegacyCursor() {
|
|
1035
|
+
configStore.removeLegacyPollingCursor();
|
|
1036
|
+
await persistTelegramConfigWithSync();
|
|
1037
|
+
},
|
|
1038
|
+
});
|
|
1039
|
+
},
|
|
1040
|
+
});
|
|
1041
|
+
if (!cutover)
|
|
1042
|
+
throw new Error("Telegram update journal binding is unavailable.");
|
|
1043
|
+
await cutover;
|
|
1044
|
+
},
|
|
1045
|
+
getEntryCount: updateAdmissionLifecycleRuntime.getJournalEntryCount,
|
|
1046
|
+
signalWorker: updateAdmissionLifecycleRuntime.signal,
|
|
1047
|
+
getBootstrapEntryCount() {
|
|
1048
|
+
return Journal.withTelegramResolvedUpdateJournalReference({
|
|
1049
|
+
registry: telegramJournalReferenceRegistry,
|
|
1050
|
+
resolveBinding: resolveTelegramUpdateJournalBinding,
|
|
1051
|
+
referenceClass: "polling-bootstrap",
|
|
1052
|
+
operation(binding) { return binding.journal.read().entries.length; },
|
|
1053
|
+
}) ?? 0;
|
|
1054
|
+
},
|
|
1055
|
+
onSessionStart: updateAdmissionLifecycleRuntime.onSessionStart,
|
|
1056
|
+
},
|
|
1057
|
+
stopTypingLoop: typing.stop,
|
|
1058
|
+
updateStatus,
|
|
1059
|
+
onPollingStateChange: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
1060
|
+
recordRuntimeEvent,
|
|
1061
|
+
});
|
|
1062
|
+
const authorizeFollowerApiCall = Bus.createTelegramFollowerApiCallAuthorizer({
|
|
1063
|
+
isMessageOwned: messageOwnershipRuntime.isOwnedByFollower,
|
|
1064
|
+
});
|
|
1065
|
+
const telegramBusLeaderRuntime = BusLeader.createTelegramBusLeaderRuntimeAssembly({
|
|
1066
|
+
runtime: {
|
|
1067
|
+
socketPath: getTelegramBusSocketPath,
|
|
1068
|
+
commitEndpointPublication(commit) {
|
|
1069
|
+
return lockRuntime.commitIfOwned(commit);
|
|
1070
|
+
},
|
|
1071
|
+
followerRegistry: telegramBusFollowerRegistry,
|
|
1072
|
+
authSecret: telegramBusAuthSecret,
|
|
1073
|
+
protocolIdentity: telegramBusProtocolIdentity,
|
|
1074
|
+
startPolling: pollingAdmissionRuntime.start,
|
|
1075
|
+
stopPolling: pollingAdmissionRuntime.stop,
|
|
1076
|
+
authorizeFollowerApiCall,
|
|
1077
|
+
resolveAgentTarget(follower, selector) {
|
|
1078
|
+
return agentMessageRuntime.resolveTarget(selector, follower.target);
|
|
1079
|
+
},
|
|
1080
|
+
routeAgentMessage(follower, message) {
|
|
1081
|
+
return agentMessageRuntime.route({
|
|
1082
|
+
sourceTarget: follower.target,
|
|
1083
|
+
sourceThreadName: follower.threadName,
|
|
1084
|
+
message,
|
|
1085
|
+
});
|
|
1086
|
+
},
|
|
1087
|
+
isFollowerProcessAlive: Locks.isProcessAlive,
|
|
1088
|
+
shouldCleanupConfirmedDeadFollower: configControls.resolveAutomaticThreadCleanupEnabled,
|
|
1089
|
+
recordFollowerMessageOwnership(record) {
|
|
1090
|
+
messageOwnershipRuntime.recordFollower(record);
|
|
1091
|
+
},
|
|
1092
|
+
},
|
|
1093
|
+
getAllowedUserId: configStore.getAllowedUserId,
|
|
1094
|
+
instanceId: telegramInstanceId,
|
|
1095
|
+
getCwd: Pi.getExtensionContextCwd,
|
|
1096
|
+
getSessionId: Pi.getExtensionContextSessionId,
|
|
1097
|
+
getTelegramProfile: configStore.getActiveProfileName,
|
|
1098
|
+
getThreadDisplayMode() {
|
|
1099
|
+
return Config.resolveTelegramThreadDisplayMode(configStore.get());
|
|
1100
|
+
},
|
|
1101
|
+
persistThreadDisplayMode(mode, isCurrent) {
|
|
1102
|
+
return Config.setTelegramThreadDisplayMode(configStore, mode, isCurrent);
|
|
1103
|
+
},
|
|
1104
|
+
onThreadDisplayChanged() {
|
|
1105
|
+
const ctx = telegramSessionContextStore.get();
|
|
1106
|
+
if (ctx)
|
|
1107
|
+
updateStatus(ctx);
|
|
1108
|
+
},
|
|
1109
|
+
shouldForceFreshUnnamed: telegramThreadCapabilityState.shouldForceFreshLeaderThread,
|
|
1110
|
+
getRequestedThreadName: telegramThreadCapabilityState.getRequestedThreadName,
|
|
1111
|
+
topicTargetStore: threadStore,
|
|
1112
|
+
getWorkspaceAdmission: workspaceAdmissionRuntime.resolve,
|
|
1113
|
+
runWorkspaceOperation: telegramWorkspaceOperationRuntime.run,
|
|
1114
|
+
captureWorkspaceExternalProtection,
|
|
1115
|
+
callApi(method, body, options) {
|
|
1116
|
+
return directTelegramApiRuntime.call(method, body, options);
|
|
1117
|
+
},
|
|
1118
|
+
callMultipart: directTelegramApiRuntime.callMultipart,
|
|
1119
|
+
downloadFile: directTelegramApiRuntime.downloadFile,
|
|
1120
|
+
recoverStaleTargetError: recoverStaleTelegramTopicApiError,
|
|
1121
|
+
getCurrentLeaderEpoch,
|
|
1122
|
+
getThreadReconciliationMachineState: threadReconciliationRuntime.getState,
|
|
1123
|
+
recordThreadReconciliationPlan,
|
|
1124
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1125
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1126
|
+
setLeaderTarget: telegramBusLeaderState.set,
|
|
1127
|
+
onProvisioningStart: telegramProvisioningActivity.start,
|
|
1128
|
+
onProvisioningEnd: telegramProvisioningActivity.end,
|
|
1129
|
+
recordRuntimeEvent,
|
|
1130
|
+
});
|
|
1131
|
+
queueHandoffReconciliationBinding.set(Updates.createTelegramQueueHandoffReconciliationRuntimeAssembly({
|
|
1132
|
+
ownsDirect: lockRuntime.owns,
|
|
1133
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
1134
|
+
isBusEnabled: isTelegramBusRuntimeEnabled,
|
|
1135
|
+
canHandoffWithLeader() {
|
|
1136
|
+
return Bus.hasTelegramBusCapability(telegramBusFollowerRegistrationState.getLeaderProtocol(), Bus.TELEGRAM_BUS_CAPABILITY_QUEUE_HANDOFF);
|
|
1137
|
+
},
|
|
1138
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
1139
|
+
createRecipientJournalResolver: telegramJournalBindingRuntime.createRecipientResolver,
|
|
1140
|
+
queueStore: telegramQueueStore,
|
|
1141
|
+
admission: updateAdmissionRuntimeBinding,
|
|
1142
|
+
createHandoffToken: Journal.createTelegramUpdateQueueHandoffToken,
|
|
1143
|
+
createRequestId: telegramBusFollowerClients.createRequestId,
|
|
1144
|
+
donorInstanceId: telegramInstanceId,
|
|
1145
|
+
authSecret: telegramBusAuthSecret,
|
|
1146
|
+
stageThroughFollower: telegramBusFollowerClients.queueHandoff,
|
|
1147
|
+
routeThroughLeader: telegramBusLeaderRuntime.routeQueueHandoff,
|
|
1148
|
+
recordRuntimeEvent,
|
|
1149
|
+
}));
|
|
1150
|
+
const telegramLeaderHealthRuntime = Sync.createTelegramLeaderHealthRuntime({
|
|
1151
|
+
callGetMe() {
|
|
1152
|
+
return directTelegramApiRuntime.call("getMe", {});
|
|
1153
|
+
},
|
|
1154
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1155
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1156
|
+
recordEvent: recordRuntimeEvent,
|
|
1157
|
+
});
|
|
1158
|
+
const telegramThreadCapabilityRuntime = Polling.createTelegramThreadCapabilityOrchestration({
|
|
1159
|
+
state: telegramThreadCapabilityState,
|
|
1160
|
+
getAllowedUserId: configStore.getAllowedUserId,
|
|
1161
|
+
callApi: callTelegramApi,
|
|
1162
|
+
topicTargetStore: threadStore,
|
|
1163
|
+
isBusRuntimeEnabled: isTelegramBusRuntimeEnabled,
|
|
1164
|
+
ownsLock: lockRuntime.owns,
|
|
1165
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
1166
|
+
startClassicPolling: pollingAdmissionRuntime.start,
|
|
1167
|
+
stopClassicPolling: pollingAdmissionRuntime.stop,
|
|
1168
|
+
startBusLeaderPolling: telegramBusLeaderRuntime.startPolling,
|
|
1169
|
+
stopBusLeaderPolling: telegramBusLeaderRuntime.stopPolling,
|
|
1170
|
+
startLeaderHealth: telegramLeaderHealthRuntime.start,
|
|
1171
|
+
stopLeaderHealth: telegramLeaderHealthRuntime.stop,
|
|
1172
|
+
registerFollowerWithLeader: telegramBusFollowerRegistration.registerWithLeader,
|
|
1173
|
+
restoreFollowerWithLeader(ctx, owner) {
|
|
1174
|
+
return telegramBusFollowerRegistration.registerWithLeader(ctx, owner, {
|
|
1175
|
+
restoreWorkspace: true,
|
|
1176
|
+
});
|
|
1177
|
+
},
|
|
1178
|
+
hasRememberedWorkspaceBinding(ctx) {
|
|
1179
|
+
return threadStore.hasWorkspaceBinding(Pi.getExtensionContextCwd(ctx), Pi.getExtensionContextSessionId(ctx));
|
|
1180
|
+
},
|
|
1181
|
+
suspendLiveThreadTarget: telegramBusLeaderState.clear,
|
|
1182
|
+
stopFollowerRegistration: telegramBusFollowerRegistration.stop,
|
|
1183
|
+
isTopicModeUnavailableError: Threads.isTelegramTopicModeUnavailableError,
|
|
1184
|
+
updateStatus,
|
|
1185
|
+
recordEvent: recordRuntimeEvent,
|
|
1186
|
+
});
|
|
1187
|
+
const telegramThreadCapabilityMonitor = telegramThreadCapabilityRuntime.monitor;
|
|
1188
|
+
observedThreadTargetBinding.set(telegramThreadCapabilityRuntime.observeTarget);
|
|
1189
|
+
const threadAwarePollingPorts = telegramThreadCapabilityRuntime.pollingPorts;
|
|
1190
|
+
const lockedPollingRuntime = Locks.createTelegramLockedPollingRuntime({
|
|
1191
|
+
lock: lockRuntime,
|
|
1192
|
+
transportMonitor: telegramThreadCapabilityMonitor,
|
|
1193
|
+
hasBotToken: configStore.hasBotToken,
|
|
1194
|
+
getBotTokenDiagnostic: configStore.getBotTokenDiagnostic,
|
|
1195
|
+
canStartPolling: Pi.canStartPollingInExtensionContext,
|
|
1196
|
+
isContextCurrent: telegramSessionContextStore.isCurrent,
|
|
1197
|
+
formatStartBlockedMessage: Pi.formatPollingStartBlockedByRunMode,
|
|
1198
|
+
startPolling: threadAwarePollingPorts.startPolling,
|
|
1199
|
+
stopPolling: threadAwarePollingPorts.stopPolling,
|
|
1200
|
+
registerFollowerWithOwner: threadAwarePollingPorts.registerFollowerWithOwner,
|
|
1201
|
+
restoreFollowerWithOwner: threadAwarePollingPorts.restoreFollowerWithOwner,
|
|
1202
|
+
stopFollowerRegistration: threadAwarePollingPorts.stopFollowerRegistration,
|
|
1203
|
+
onTransportAvailabilityChanged() {
|
|
1204
|
+
modelContextAvailabilityRuntime.reconcile();
|
|
1205
|
+
const ctx = telegramSessionContextStore.get();
|
|
1206
|
+
if (ctx)
|
|
1207
|
+
queueHandoffReconciliationBinding.request(ctx);
|
|
1208
|
+
},
|
|
1209
|
+
updateStatus,
|
|
1210
|
+
recordRuntimeEvent,
|
|
1211
|
+
});
|
|
1212
|
+
const { disconnect: disconnectTelegramAndDeleteCurrentThread, cleanupForSessionRestart: cleanupTelegramThreadForSessionRestart, } = Sync.createTelegramThreadDisconnectAssembly({
|
|
1213
|
+
instanceId: telegramInstanceId,
|
|
1214
|
+
getCurrentThreadRecord: findCurrentThreadRecord,
|
|
1215
|
+
topicTargetStore: threadStore,
|
|
1216
|
+
callApi: callTelegramApi,
|
|
1217
|
+
getCurrentLeaderEpoch,
|
|
1218
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
1219
|
+
clearLeaderTarget: telegramBusLeaderState.clear,
|
|
1220
|
+
disconnectFollowerThread: telegramBusFollowerRegistration.disconnectFromLeader,
|
|
1221
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1222
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1223
|
+
stopPolling: lockedPollingRuntime.stop,
|
|
1224
|
+
suspendPolling: lockedPollingRuntime.suspend,
|
|
1225
|
+
recordRuntimeEvent,
|
|
1226
|
+
runWorkspaceOperation: telegramWorkspaceOperationRuntime.run,
|
|
1227
|
+
});
|
|
1228
|
+
const telegramBridgeSessionLifecycleDeps = Lifecycle.createTelegramBridgeSessionLifecycleDeps({
|
|
1229
|
+
contextStore: telegramSessionContextStore,
|
|
1230
|
+
queue: {
|
|
1231
|
+
getCurrentModel: getContextModel,
|
|
1232
|
+
loadConfig: configStore.load,
|
|
1233
|
+
setQueuedItems: telegramQueueStore.setQueuedItems,
|
|
1234
|
+
setCurrentModel: currentModelRuntime.set,
|
|
1235
|
+
setPendingModelSwitch: pendingModelSwitchStore.set,
|
|
1236
|
+
syncCounters: queue.syncCounters,
|
|
1237
|
+
syncFlags: lifecycle.syncFlags,
|
|
1238
|
+
bindDeferredDispatchContext: deferredQueueDispatchRuntime.bind,
|
|
1239
|
+
prepareTempDir,
|
|
1240
|
+
updateStatus,
|
|
1241
|
+
unbindDeferredDispatchContext: deferredQueueDispatchRuntime.unbind,
|
|
1242
|
+
discardQueuedItems: queueMutationRuntime.clear,
|
|
1243
|
+
clearModelMenuState: modelMenuRuntime.clear,
|
|
1244
|
+
getActiveTurnChatId: activeTurnRuntime.getChatId,
|
|
1245
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
1246
|
+
clearPreview: previewRuntime.clear,
|
|
1247
|
+
clearActiveTurn: activeTurnRuntime.clear,
|
|
1248
|
+
clearAbort: abort.clearHandler,
|
|
1249
|
+
recordRuntimeEvent,
|
|
1250
|
+
},
|
|
1251
|
+
follower: {
|
|
1252
|
+
registrationState: telegramBusFollowerRegistrationState,
|
|
1253
|
+
registrationRuntime: telegramBusFollowerRegistration,
|
|
1254
|
+
instanceId: telegramInstanceId,
|
|
1255
|
+
suspendPolling: lockedPollingRuntime.suspend,
|
|
1256
|
+
isLeader: lockRuntime.owns,
|
|
1257
|
+
getLeaderBinding: currentInstanceThreadRuntime.getRestorationIdentity,
|
|
1258
|
+
getActiveContext: telegramSessionContextStore.get,
|
|
1259
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
1260
|
+
getLeaderState: lockRuntime.getState,
|
|
1261
|
+
updateStatus,
|
|
1262
|
+
recordRuntimeEvent,
|
|
1263
|
+
},
|
|
1264
|
+
services: {
|
|
1265
|
+
mediaGroup: {
|
|
1266
|
+
resume: mediaGroupRuntime.resume,
|
|
1267
|
+
suspend: mediaGroupRuntime.suspend,
|
|
1268
|
+
},
|
|
1269
|
+
textGroup: {
|
|
1270
|
+
resume: textGroupRuntime.resume,
|
|
1271
|
+
suspend: textGroupRuntime.suspend,
|
|
1272
|
+
},
|
|
1273
|
+
delivery: deliveryLifecycleRuntime,
|
|
1274
|
+
polling: lockedPollingRuntime,
|
|
1275
|
+
inboundWorker: {
|
|
1276
|
+
onSessionShutdown: updateAdmissionRuntimeBinding.onSessionShutdown,
|
|
1277
|
+
},
|
|
1278
|
+
capabilityMonitor: telegramThreadCapabilityMonitor,
|
|
1279
|
+
queueWatchdog: queueDispatchWatchdogRuntime,
|
|
1280
|
+
guestPlaceholder: { stopAll: guestPlaceholderRuntime.stopAll },
|
|
1281
|
+
},
|
|
1282
|
+
});
|
|
1283
|
+
const sessionLifecycleRuntime = Lifecycle.createTelegramBridgeSessionLifecycleAssembly(telegramBridgeSessionLifecycleDeps);
|
|
1284
|
+
// --- Extension API Bindings ---
|
|
1285
|
+
telegramThreadDisplayNameRenameBinding.bind({
|
|
1286
|
+
async rename(expectedTarget, threadName) {
|
|
1287
|
+
try {
|
|
1288
|
+
if (telegramBusFollowerRegistrationState.isRegistered()) {
|
|
1289
|
+
if (typeof expectedTarget.threadId !== "number") {
|
|
1290
|
+
return { ok: false, message: "Telegram Workspace Thread target is unavailable." };
|
|
1291
|
+
}
|
|
1292
|
+
const renamedThreadName = await telegramBusFollowerRegistration.renameThread?.({ chatId: expectedTarget.chatId, threadId: expectedTarget.threadId }, threadName);
|
|
1293
|
+
if (!renamedThreadName) {
|
|
1294
|
+
return {
|
|
1295
|
+
ok: false,
|
|
1296
|
+
message: "Telegram follower Workspace Thread rename is unavailable.",
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
return {
|
|
1300
|
+
ok: true,
|
|
1301
|
+
threadName: renamedThreadName,
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
if (!ownsTelegramDirectDelivery()) {
|
|
1305
|
+
return {
|
|
1306
|
+
ok: false,
|
|
1307
|
+
message: "Telegram Workspace Thread rename requires an active leader or follower connection.",
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
if (typeof expectedTarget.threadId !== "number") {
|
|
1311
|
+
return { ok: false, message: "Telegram Workspace Thread target is unavailable." };
|
|
1312
|
+
}
|
|
1313
|
+
const renamed = await telegramBusLeaderRuntime.renameLeaderThreadAdmitted(threadName, { chatId: expectedTarget.chatId, threadId: expectedTarget.threadId });
|
|
1314
|
+
telegramBusLeaderState.set({
|
|
1315
|
+
target: renamed.target,
|
|
1316
|
+
slot: renamed.slot,
|
|
1317
|
+
threadName: renamed.manualThreadName ?? renamed.threadName,
|
|
1318
|
+
});
|
|
1319
|
+
return {
|
|
1320
|
+
ok: true,
|
|
1321
|
+
threadName: renamed.manualThreadName,
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
catch (error) {
|
|
1325
|
+
return {
|
|
1326
|
+
ok: false,
|
|
1327
|
+
message: error instanceof Error
|
|
1328
|
+
? error.message
|
|
1329
|
+
: "Telegram Workspace Thread rename failed.",
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
},
|
|
1333
|
+
}.rename);
|
|
1334
|
+
telegramThreadDisplayNameResetBinding.bind({
|
|
1335
|
+
async reset(expectedTarget) {
|
|
1336
|
+
try {
|
|
1337
|
+
if (typeof expectedTarget.threadId !== "number") {
|
|
1338
|
+
return { ok: false, message: "Telegram Workspace Thread target is unavailable." };
|
|
1339
|
+
}
|
|
1340
|
+
const target = {
|
|
1341
|
+
chatId: expectedTarget.chatId,
|
|
1342
|
+
threadId: expectedTarget.threadId,
|
|
1343
|
+
};
|
|
1344
|
+
const wasFollower = telegramBusFollowerRegistrationState.isRegistered();
|
|
1345
|
+
const result = wasFollower
|
|
1346
|
+
? await telegramBusFollowerRegistration.resetThreadName?.(target)
|
|
1347
|
+
: (await telegramBusLeaderRuntime.resetLeaderThreadName(target)).threadName;
|
|
1348
|
+
if (!result) {
|
|
1349
|
+
return { ok: false, message: "Thread display name reset is unavailable." };
|
|
1350
|
+
}
|
|
1351
|
+
const leaderTarget = telegramBusLeaderState.getTarget();
|
|
1352
|
+
if (!wasFollower && leaderTarget) {
|
|
1353
|
+
telegramBusLeaderState.set({ target: leaderTarget, threadName: result });
|
|
1354
|
+
}
|
|
1355
|
+
return {
|
|
1356
|
+
ok: true,
|
|
1357
|
+
threadName: result,
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
catch (error) {
|
|
1361
|
+
return {
|
|
1362
|
+
ok: false,
|
|
1363
|
+
message: error instanceof Error
|
|
1364
|
+
? error.message : "Thread display name reset failed.",
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
}.reset);
|
|
1369
|
+
Bindings.registerTelegramCommandsAndTools({
|
|
1370
|
+
pi,
|
|
1371
|
+
agentDir: Paths.resolveAgentDir(),
|
|
1372
|
+
configStore,
|
|
1373
|
+
persistConfig: persistTelegramConfigWithSync,
|
|
1374
|
+
setup,
|
|
1375
|
+
activeTurnRuntime,
|
|
1376
|
+
lockedPollingRuntime,
|
|
1377
|
+
stopPolling: disconnectTelegramAndDeleteCurrentThread,
|
|
1378
|
+
recoverPollingStart: Recovery.createTelegramPollingStartRecoveryHandler({
|
|
1379
|
+
getOwnersPath: Paths.resolveTelegramOwnersPath,
|
|
1380
|
+
getStatePaths() {
|
|
1381
|
+
return [
|
|
1382
|
+
Threads.getTelegramTopicTargetsPath(undefined, configStore.getActiveProfileName()),
|
|
1383
|
+
];
|
|
1384
|
+
},
|
|
1385
|
+
suspendPolling: lockedPollingRuntime.suspend,
|
|
1386
|
+
releaseOwnership: lockRuntime.release,
|
|
1387
|
+
recordRuntimeEvent,
|
|
1388
|
+
}),
|
|
1389
|
+
getDisconnectThreadName() {
|
|
1390
|
+
const record = findCurrentThreadRecord();
|
|
1391
|
+
if (!record?.target.threadId)
|
|
1392
|
+
return undefined;
|
|
1393
|
+
return record.threadName ?? "current Telegram thread";
|
|
1394
|
+
},
|
|
1395
|
+
setRequestedThreadNameForPollingStart: telegramThreadCapabilityState.setRequestedThreadName,
|
|
1396
|
+
validateThreadName(threadName) {
|
|
1397
|
+
return Threads.getTelegramTopicThreadNameValidationError(threadName, undefined);
|
|
1398
|
+
},
|
|
1399
|
+
onTransportChanged() {
|
|
1400
|
+
deliveryLifecycleRuntime.onSessionStart();
|
|
1401
|
+
activityVerbosityRuntime.reset();
|
|
1402
|
+
modelContextAvailabilityRuntime.reconcile();
|
|
1403
|
+
},
|
|
1404
|
+
getStatusLines,
|
|
1405
|
+
buttonActionStore,
|
|
1406
|
+
sendMarkdownReply,
|
|
1407
|
+
async sendChannelMarkdownMessage(channel, markdown, options) {
|
|
1408
|
+
if (!lockRuntime.owns()) {
|
|
1409
|
+
throw new Error("Telegram channel delivery requires direct leader transport ownership.");
|
|
1410
|
+
}
|
|
1411
|
+
const profileName = configStore.getActiveProfileName() ?? "default";
|
|
1412
|
+
const botToken = configStore.getBotToken();
|
|
1413
|
+
if (!botToken)
|
|
1414
|
+
throw new Error("Telegram channel delivery requires an active bot token.");
|
|
1415
|
+
const store = ChannelPosts.createTelegramChannelPostJournalStore({
|
|
1416
|
+
path: Paths.resolveTelegramChannelPostJournalPath(undefined, profileName),
|
|
1417
|
+
profileName,
|
|
1418
|
+
tokenSha256: Journal.createTelegramUpdateJournalBotIdentity({ botToken }).tokenSha256,
|
|
1419
|
+
});
|
|
1420
|
+
const record = await ChannelPosts.publishTelegramChannelPost({
|
|
1421
|
+
store, operationId: options.operationId,
|
|
1422
|
+
channel: channel, markdown,
|
|
1423
|
+
async observeChannel(channelAddress) {
|
|
1424
|
+
return telegramApiRuntime.call("getChat", { chat_id: channelAddress });
|
|
1425
|
+
},
|
|
1426
|
+
async send(channelAddress, body) {
|
|
1427
|
+
const sent = await telegramApiRuntime.call("sendRichMessage", { chat_id: channelAddress, rich_message: { markdown: body },
|
|
1428
|
+
...(options.replyMarkup ? { reply_markup: options.replyMarkup } : {}) });
|
|
1429
|
+
return { messageId: sent.message_id, chat: sent.chat };
|
|
1430
|
+
},
|
|
1431
|
+
});
|
|
1432
|
+
return record.state === "published" ? record.messageId : undefined;
|
|
1433
|
+
},
|
|
1434
|
+
async sendChannelMediaMessage(channel, mediaPath, markdown, options) {
|
|
1435
|
+
if (!lockRuntime.owns()) {
|
|
1436
|
+
throw new Error("Telegram channel media delivery requires direct leader transport ownership.");
|
|
1437
|
+
}
|
|
1438
|
+
const profileName = configStore.getActiveProfileName() ?? "default";
|
|
1439
|
+
const botToken = configStore.getBotToken();
|
|
1440
|
+
if (!botToken)
|
|
1441
|
+
throw new Error("Telegram channel media delivery requires an active bot token.");
|
|
1442
|
+
const media = await ChannelPosts.inspectTelegramChannelPostMedia(mediaPath);
|
|
1443
|
+
const caption = Replies.renderTelegramMarkdownToHtmlDraft(markdown);
|
|
1444
|
+
ChannelPosts.assertTelegramChannelPostCaptionWithinLimit(caption);
|
|
1445
|
+
const store = ChannelPosts.createTelegramChannelPostJournalStore({
|
|
1446
|
+
path: Paths.resolveTelegramChannelPostJournalPath(undefined, profileName),
|
|
1447
|
+
profileName,
|
|
1448
|
+
tokenSha256: Journal.createTelegramUpdateJournalBotIdentity({ botToken }).tokenSha256,
|
|
1449
|
+
});
|
|
1450
|
+
const record = await ChannelPosts.publishTelegramChannelPost({
|
|
1451
|
+
store, operationId: options.operationId,
|
|
1452
|
+
channel: channel, markdown, media,
|
|
1453
|
+
async observeChannel(channelAddress) {
|
|
1454
|
+
return telegramApiRuntime.call("getChat", { chat_id: channelAddress });
|
|
1455
|
+
},
|
|
1456
|
+
async send(channelAddress) {
|
|
1457
|
+
const sent = await telegramApiRuntime.callMultipart(media.kind === "photo" ? "sendPhoto" : "sendVideo", {
|
|
1458
|
+
chat_id: String(channelAddress),
|
|
1459
|
+
caption,
|
|
1460
|
+
parse_mode: "HTML",
|
|
1461
|
+
...(options.replyMarkup ? { reply_markup: JSON.stringify(options.replyMarkup) } : {}),
|
|
1462
|
+
}, media.kind === "photo" ? "photo" : "video", mediaPath, media.fileName);
|
|
1463
|
+
return { messageId: sent.message_id, chat: sent.chat };
|
|
1464
|
+
},
|
|
1465
|
+
});
|
|
1466
|
+
return record.state === "published" ? record.messageId : undefined;
|
|
1467
|
+
},
|
|
1468
|
+
listChannelPosts(input) {
|
|
1469
|
+
const profileName = configStore.getActiveProfileName() ?? "default";
|
|
1470
|
+
const botToken = configStore.getBotToken();
|
|
1471
|
+
if (!botToken)
|
|
1472
|
+
throw new Error("Telegram channel posts require an active bot token.");
|
|
1473
|
+
return ChannelPosts.createTelegramChannelPostJournalStore({
|
|
1474
|
+
path: Paths.resolveTelegramChannelPostJournalPath(undefined, profileName),
|
|
1475
|
+
profileName,
|
|
1476
|
+
tokenSha256: Journal.createTelegramUpdateJournalBotIdentity({ botToken }).tokenSha256,
|
|
1477
|
+
}).list(input);
|
|
1478
|
+
},
|
|
1479
|
+
async mutateChannelPost(input) {
|
|
1480
|
+
if (!lockRuntime.owns())
|
|
1481
|
+
throw new Error("Telegram channel post mutation requires direct leader ownership.");
|
|
1482
|
+
const profileName = configStore.getActiveProfileName() ?? "default";
|
|
1483
|
+
const botToken = configStore.getBotToken();
|
|
1484
|
+
if (!botToken)
|
|
1485
|
+
throw new Error("Telegram channel post mutation requires an active bot token.");
|
|
1486
|
+
const store = ChannelPosts.createTelegramChannelPostJournalStore({
|
|
1487
|
+
path: Paths.resolveTelegramChannelPostJournalPath(undefined, profileName), profileName,
|
|
1488
|
+
tokenSha256: Journal.createTelegramUpdateJournalBotIdentity({ botToken }).tokenSha256,
|
|
1489
|
+
});
|
|
1490
|
+
if (input.action === "edit") {
|
|
1491
|
+
if (!input.markdown)
|
|
1492
|
+
throw new Error("Telegram channel post edit requires markdown.");
|
|
1493
|
+
const current = store.get(input.operationId);
|
|
1494
|
+
const caption = current?.media
|
|
1495
|
+
? Replies.renderTelegramMarkdownToHtmlDraft(input.markdown) : undefined;
|
|
1496
|
+
if (caption !== undefined) {
|
|
1497
|
+
ChannelPosts.assertTelegramChannelPostCaptionWithinLimit(caption);
|
|
1498
|
+
}
|
|
1499
|
+
const begun = store.beginEdit({ operationId: input.operationId,
|
|
1500
|
+
mutationId: input.mutationId, markdown: input.markdown });
|
|
1501
|
+
if (!begun.began) {
|
|
1502
|
+
if (begun.record.state === "published" && begun.record.lastMutationId === input.mutationId)
|
|
1503
|
+
return begun.record;
|
|
1504
|
+
throw new Error("Telegram channel post edit outcome is unknown; refusing automatic replay.");
|
|
1505
|
+
}
|
|
1506
|
+
if (begun.record.state !== "edit-outcome-unknown")
|
|
1507
|
+
throw new Error("Telegram channel post edit authority is invalid.");
|
|
1508
|
+
if (begun.record.media) {
|
|
1509
|
+
if (caption === undefined) {
|
|
1510
|
+
throw new Error("Telegram channel post media caption edit requires retained media identity.");
|
|
1511
|
+
}
|
|
1512
|
+
await telegramApiRuntime.call("editMessageCaption", { chat_id: begun.record.channelId,
|
|
1513
|
+
message_id: begun.record.messageId, caption, parse_mode: "HTML" });
|
|
1514
|
+
}
|
|
1515
|
+
else {
|
|
1516
|
+
await telegramApiRuntime.call("editMessageText", { chat_id: begun.record.channelId,
|
|
1517
|
+
message_id: begun.record.messageId,
|
|
1518
|
+
text: Replies.renderTelegramMarkdownToHtmlDraft(input.markdown), parse_mode: "HTML" });
|
|
1519
|
+
}
|
|
1520
|
+
return store.confirmEdited({ operationId: input.operationId, mutationId: input.mutationId }).record;
|
|
1521
|
+
}
|
|
1522
|
+
if (input.markdown !== undefined)
|
|
1523
|
+
throw new Error("Telegram channel post deletion does not accept markdown.");
|
|
1524
|
+
const begun = store.beginDelete({ operationId: input.operationId, mutationId: input.mutationId });
|
|
1525
|
+
if (!begun.began) {
|
|
1526
|
+
if (begun.record.state === "deleted" && begun.record.mutationId === input.mutationId)
|
|
1527
|
+
return begun.record;
|
|
1528
|
+
throw new Error("Telegram channel post deletion outcome is unknown; refusing automatic replay.");
|
|
1529
|
+
}
|
|
1530
|
+
if (begun.record.state !== "delete-outcome-unknown")
|
|
1531
|
+
throw new Error("Telegram channel post deletion authority is invalid.");
|
|
1532
|
+
await telegramApiRuntime.call("deleteMessage", { chat_id: begun.record.channelId,
|
|
1533
|
+
message_id: begun.record.messageId });
|
|
1534
|
+
return store.confirmDeleted({ operationId: input.operationId, mutationId: input.mutationId }).record;
|
|
1535
|
+
},
|
|
1536
|
+
callMultipart,
|
|
1537
|
+
getDefaultChatId: proactivePushChatIdGetter,
|
|
1538
|
+
getDefaultTarget: proactivePushTargetGetter,
|
|
1539
|
+
...agentMessageToolRoutingRuntime,
|
|
1540
|
+
setGenerativeAppLiveSurfaceRuntime: generativeAppLiveSurfaceBinding.set,
|
|
1541
|
+
updateStatus,
|
|
1542
|
+
recordRuntimeEvent,
|
|
1543
|
+
});
|
|
1544
|
+
// --- Lifecycle Hooks ---
|
|
1545
|
+
Bindings.registerTelegramLifecycleRuntimeHooks({
|
|
1546
|
+
pi,
|
|
1547
|
+
sessionLifecycleRuntime: {
|
|
1548
|
+
...sessionLifecycleRuntime,
|
|
1549
|
+
onModelSelect: currentModelRuntime.onModelSelect,
|
|
1550
|
+
},
|
|
1551
|
+
activityRuntime,
|
|
1552
|
+
activityVerbosityRuntime,
|
|
1553
|
+
assistantOutputRuntime,
|
|
1554
|
+
publicationRuntime,
|
|
1555
|
+
configStore,
|
|
1556
|
+
abort,
|
|
1557
|
+
typing,
|
|
1558
|
+
lifecycle,
|
|
1559
|
+
activeTurnRuntime,
|
|
1560
|
+
telegramQueueStore,
|
|
1561
|
+
modelSwitchController,
|
|
1562
|
+
previewRuntime,
|
|
1563
|
+
promptDispatchRuntime,
|
|
1564
|
+
deferredQueueDispatchRuntime,
|
|
1565
|
+
modelContextAvailabilityRuntime,
|
|
1566
|
+
disconnectOnQuit: cleanupTelegramThreadForSessionRestart,
|
|
1567
|
+
shutdownGenerativeAppLiveSurfaces: generativeAppLiveSurfaceBinding.shutdown,
|
|
1568
|
+
resolveAutomaticThreadCleanupEnabled: configControls.resolveAutomaticThreadCleanupEnabled,
|
|
1569
|
+
buttonActionStore,
|
|
1570
|
+
callMultipart,
|
|
1571
|
+
sendChatAction,
|
|
1572
|
+
sendRecordVoiceAction,
|
|
1573
|
+
sendMarkdownReply,
|
|
1574
|
+
sendTextReply,
|
|
1575
|
+
dispatchNextQueuedTelegramTurn,
|
|
1576
|
+
onPromptHandedOff(turn, ctx) {
|
|
1577
|
+
updateAdmissionRuntimeBinding
|
|
1578
|
+
.getSettlement()
|
|
1579
|
+
?.onPromptHandedOff(turn, ctx);
|
|
1580
|
+
},
|
|
1581
|
+
answerGuestQuery,
|
|
1582
|
+
deleteMessage: deleteTelegramMessage,
|
|
1583
|
+
sendGuestReply,
|
|
1584
|
+
editGuestReply,
|
|
1585
|
+
stopGuestPlaceholder: guestPlaceholderRuntime.stop,
|
|
1586
|
+
finalizeMarkdownPreview,
|
|
1587
|
+
preparePreviewDelivery,
|
|
1588
|
+
proactivePushTargetGetter,
|
|
1589
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
1590
|
+
recordMessageOwnership: messageOwnershipRuntime.recordLocal,
|
|
1591
|
+
canSendAgentActivity(ctx) {
|
|
1592
|
+
return (lockOwnershipGuard.ownsContext(ctx) ||
|
|
1593
|
+
telegramBusFollowerRegistrationState.isRegistered());
|
|
1594
|
+
},
|
|
1595
|
+
isSessionContextActive(ctx) {
|
|
1596
|
+
return telegramSessionContextStore.isCurrent(ctx);
|
|
1597
|
+
},
|
|
1598
|
+
isTurnTransportActive(turn) {
|
|
1599
|
+
return telegramTransportStampRuntime.isActive(turn.transportStamp);
|
|
1600
|
+
},
|
|
1601
|
+
updateStatus,
|
|
1602
|
+
recordRuntimeEvent,
|
|
1603
|
+
});
|
|
1604
|
+
}
|