@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,574 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram activity lifecycle normalization and extension dispatch
|
|
3
|
+
* Zones: pi agent lifecycle, extension API, operational delivery
|
|
4
|
+
* Owns stable handler registration, evidence-based activity/source identity, assistant segment and reasoning normalization, ordered public-output projection, executed-tool and compaction events, isolated non-blocking queues, shutdown fencing, diagnostics, and fresh delivery contexts; excludes Pi hook wiring, Telegram rendering implementation, raw transport clients, and consumer-extension behavior
|
|
5
|
+
*/
|
|
6
|
+
import { deleteTelegramView, editTelegramView, sendTelegramChatAction, sendTelegramView, } from "./delivery.js";
|
|
7
|
+
const TELEGRAM_ACTIVITY_REGISTRY_KEY = "__piTelegramActivityRegistry__";
|
|
8
|
+
function getOrCreateTelegramActivityRegistry() {
|
|
9
|
+
const globals = globalThis;
|
|
10
|
+
const existing = globals[TELEGRAM_ACTIVITY_REGISTRY_KEY];
|
|
11
|
+
if (existing &&
|
|
12
|
+
typeof existing === "object" &&
|
|
13
|
+
"handlers" in existing &&
|
|
14
|
+
existing.handlers instanceof Map) {
|
|
15
|
+
return existing;
|
|
16
|
+
}
|
|
17
|
+
const registry = { handlers: new Map() };
|
|
18
|
+
globals[TELEGRAM_ACTIVITY_REGISTRY_KEY] = registry;
|
|
19
|
+
return registry;
|
|
20
|
+
}
|
|
21
|
+
export function registerTelegramActivityHandler(registration) {
|
|
22
|
+
const id = registration.id.trim();
|
|
23
|
+
if (!id)
|
|
24
|
+
throw new Error("Telegram activity handler id is required.");
|
|
25
|
+
const registry = getOrCreateTelegramActivityRegistry();
|
|
26
|
+
if (registry.handlers.has(id)) {
|
|
27
|
+
throw new Error(`Telegram activity handler is already registered: ${id}`);
|
|
28
|
+
}
|
|
29
|
+
const handler = {
|
|
30
|
+
...registration,
|
|
31
|
+
id,
|
|
32
|
+
order: registration.order ?? 0,
|
|
33
|
+
};
|
|
34
|
+
registry.handlers.set(id, handler);
|
|
35
|
+
return () => {
|
|
36
|
+
if (registry.handlers.get(id) === handler)
|
|
37
|
+
registry.handlers.delete(id);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
export function clearTelegramActivityHandlers() {
|
|
42
|
+
getOrCreateTelegramActivityRegistry().handlers.clear();
|
|
43
|
+
}
|
|
44
|
+
function getTelegramActivityHandlers() {
|
|
45
|
+
return Array.from(getOrCreateTelegramActivityRegistry().handlers.values()).sort(function (left, right) {
|
|
46
|
+
return left.order - right.order || left.id.localeCompare(right.id);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function cloneActivityTarget(target) {
|
|
50
|
+
return Object.freeze(target.threadId === undefined
|
|
51
|
+
? { chatId: target.chatId }
|
|
52
|
+
: { chatId: target.chatId, threadId: target.threadId });
|
|
53
|
+
}
|
|
54
|
+
function createTelegramActivityContext(event, isActive) {
|
|
55
|
+
const defaultScope = event.target
|
|
56
|
+
? { kind: "target", target: cloneActivityTarget(event.target) }
|
|
57
|
+
: event.source === "telegram"
|
|
58
|
+
? { kind: "active-turn" }
|
|
59
|
+
: { kind: "instance" };
|
|
60
|
+
const inactive = () => Promise.resolve({
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: "runtime-unavailable",
|
|
63
|
+
message: "Telegram activity context belongs to an inactive session.",
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
activityId: event.activityId,
|
|
67
|
+
sequence: event.sequence,
|
|
68
|
+
source: event.source,
|
|
69
|
+
defaultScope,
|
|
70
|
+
send(view, options) {
|
|
71
|
+
if (!isActive())
|
|
72
|
+
return inactive();
|
|
73
|
+
return sendTelegramView(view, {
|
|
74
|
+
scope: options?.scope ?? defaultScope,
|
|
75
|
+
replyToMessageId: options?.replyToMessageId,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
edit(handle, view) {
|
|
79
|
+
return isActive() ? editTelegramView(handle, view) : inactive();
|
|
80
|
+
},
|
|
81
|
+
delete(handle) {
|
|
82
|
+
return isActive() ? deleteTelegramView(handle) : inactive();
|
|
83
|
+
},
|
|
84
|
+
chatAction(action, options) {
|
|
85
|
+
if (!isActive())
|
|
86
|
+
return inactive();
|
|
87
|
+
return sendTelegramChatAction(action, {
|
|
88
|
+
scope: options?.scope ?? defaultScope,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function canCoalesceActivityEvents(previous, next) {
|
|
94
|
+
if (previous.activityId !== next.activityId ||
|
|
95
|
+
previous.type !== next.type) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (previous.type === "assistant-text-delta" &&
|
|
99
|
+
next.type === "assistant-text-delta") {
|
|
100
|
+
return previous.contentIndex === next.contentIndex;
|
|
101
|
+
}
|
|
102
|
+
if (previous.type === "reasoning-delta" &&
|
|
103
|
+
next.type === "reasoning-delta") {
|
|
104
|
+
return previous.contentIndex === next.contentIndex;
|
|
105
|
+
}
|
|
106
|
+
if (previous.type === "tool-update" && next.type === "tool-update") {
|
|
107
|
+
return previous.toolCallId === next.toolCallId;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function coalesceActivityEvents(previous, next) {
|
|
112
|
+
if (previous.type === "assistant-text-delta" &&
|
|
113
|
+
next.type === "assistant-text-delta") {
|
|
114
|
+
return { ...next, delta: previous.delta + next.delta };
|
|
115
|
+
}
|
|
116
|
+
if (previous.type === "reasoning-delta" &&
|
|
117
|
+
next.type === "reasoning-delta") {
|
|
118
|
+
return { ...next, delta: previous.delta + next.delta };
|
|
119
|
+
}
|
|
120
|
+
return next;
|
|
121
|
+
}
|
|
122
|
+
/** @internal */
|
|
123
|
+
export function createTelegramActivityDispatcher(deps = {}) {
|
|
124
|
+
const queues = new Map();
|
|
125
|
+
let stopped = false;
|
|
126
|
+
const drain = async (queue) => {
|
|
127
|
+
if (queue.running || !queue.active)
|
|
128
|
+
return;
|
|
129
|
+
queue.running = true;
|
|
130
|
+
try {
|
|
131
|
+
while (queue.active) {
|
|
132
|
+
const event = queue.events.shift();
|
|
133
|
+
if (!event)
|
|
134
|
+
break;
|
|
135
|
+
if (getOrCreateTelegramActivityRegistry().handlers.get(queue.registration.id) !== queue.registration) {
|
|
136
|
+
queue.active = false;
|
|
137
|
+
queue.events = [];
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
await queue.registration.handle(event, createTelegramActivityContext(event, () => queue.active &&
|
|
142
|
+
!stopped &&
|
|
143
|
+
getOrCreateTelegramActivityRegistry().handlers.get(queue.registration.id) === queue.registration));
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
deps.recordFailure?.(queue.registration.id, event, error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
queue.running = false;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
dispatch(event) {
|
|
156
|
+
if (stopped)
|
|
157
|
+
return;
|
|
158
|
+
for (const registration of getTelegramActivityHandlers()) {
|
|
159
|
+
let queue = queues.get(registration.id);
|
|
160
|
+
if (!queue || queue.registration !== registration) {
|
|
161
|
+
queue = {
|
|
162
|
+
registration,
|
|
163
|
+
events: [],
|
|
164
|
+
running: false,
|
|
165
|
+
active: true,
|
|
166
|
+
};
|
|
167
|
+
queues.set(registration.id, queue);
|
|
168
|
+
}
|
|
169
|
+
const previous = queue.events.at(-1);
|
|
170
|
+
if (previous && canCoalesceActivityEvents(previous, event)) {
|
|
171
|
+
queue.events[queue.events.length - 1] = coalesceActivityEvents(previous, event);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
queue.events.push(event);
|
|
175
|
+
}
|
|
176
|
+
queueMicrotask(function () {
|
|
177
|
+
void drain(queue);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
stop() {
|
|
182
|
+
stopped = true;
|
|
183
|
+
for (const queue of queues.values()) {
|
|
184
|
+
queue.active = false;
|
|
185
|
+
queue.events = [];
|
|
186
|
+
}
|
|
187
|
+
queues.clear();
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** @internal */
|
|
192
|
+
export function createTelegramActivityBridgeRuntime(deps) {
|
|
193
|
+
let generationSequence = 0;
|
|
194
|
+
let runtime;
|
|
195
|
+
const getRuntime = () => runtime;
|
|
196
|
+
return {
|
|
197
|
+
onSessionStart() {
|
|
198
|
+
runtime?.onSessionShutdown();
|
|
199
|
+
runtime = createTelegramActivityRuntime({
|
|
200
|
+
generation: `${deps.generation}:${++generationSequence}`,
|
|
201
|
+
dispatcher: createTelegramActivityDispatcher({
|
|
202
|
+
recordFailure: deps.recordFailure,
|
|
203
|
+
}),
|
|
204
|
+
observeEvent: deps.observeEvent,
|
|
205
|
+
recordObserverFailure: deps.recordFailure
|
|
206
|
+
? (event, error) => deps.recordFailure("@llblab/pi-telegram/proactive", event, error)
|
|
207
|
+
: undefined,
|
|
208
|
+
now: deps.now,
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
recordInputSource(source) {
|
|
212
|
+
getRuntime()?.recordInputSource(source);
|
|
213
|
+
},
|
|
214
|
+
onAgentStart(target, replyToMessageId) {
|
|
215
|
+
getRuntime()?.onAgentStart(target, replyToMessageId);
|
|
216
|
+
},
|
|
217
|
+
onAssistantEvent(event) {
|
|
218
|
+
getRuntime()?.onAssistantEvent(event);
|
|
219
|
+
},
|
|
220
|
+
onAssistantMessageEnd(stopReason) {
|
|
221
|
+
getRuntime()?.onAssistantMessageEnd(stopReason);
|
|
222
|
+
},
|
|
223
|
+
onToolStart(event) {
|
|
224
|
+
getRuntime()?.onToolStart(event);
|
|
225
|
+
},
|
|
226
|
+
onToolUpdate(event) {
|
|
227
|
+
getRuntime()?.onToolUpdate(event);
|
|
228
|
+
},
|
|
229
|
+
onToolEnd(event) {
|
|
230
|
+
getRuntime()?.onToolEnd(event);
|
|
231
|
+
},
|
|
232
|
+
onCompactionStart(reason) {
|
|
233
|
+
getRuntime()?.onCompactionStart(reason);
|
|
234
|
+
},
|
|
235
|
+
onCompactionEnd(reason) {
|
|
236
|
+
getRuntime()?.onCompactionEnd(reason);
|
|
237
|
+
},
|
|
238
|
+
onCompactionAbandoned() {
|
|
239
|
+
getRuntime()?.onCompactionAbandoned();
|
|
240
|
+
},
|
|
241
|
+
onUiPromptStart(kind, title) {
|
|
242
|
+
getRuntime()?.onUiPromptStart(kind, title);
|
|
243
|
+
},
|
|
244
|
+
onUiPromptEnd() {
|
|
245
|
+
getRuntime()?.onUiPromptEnd();
|
|
246
|
+
},
|
|
247
|
+
onAgentEnd() {
|
|
248
|
+
getRuntime()?.onAgentEnd();
|
|
249
|
+
},
|
|
250
|
+
onAgentSettled() {
|
|
251
|
+
getRuntime()?.onAgentSettled();
|
|
252
|
+
},
|
|
253
|
+
onSessionShutdown() {
|
|
254
|
+
runtime?.onSessionShutdown();
|
|
255
|
+
runtime = undefined;
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/** @internal */
|
|
260
|
+
export function createTelegramActivityRuntime(deps) {
|
|
261
|
+
const now = deps.now ?? Date.now;
|
|
262
|
+
let nextActivityNumber = 0;
|
|
263
|
+
let activityId;
|
|
264
|
+
let activitySource = "unknown";
|
|
265
|
+
let activityTarget;
|
|
266
|
+
let activityReplyToMessageId;
|
|
267
|
+
let sequence = 0;
|
|
268
|
+
let pendingInputSource = "unknown";
|
|
269
|
+
let pendingAssistantSegment;
|
|
270
|
+
let compactionInProgress = false;
|
|
271
|
+
let compactionOwnedActivity = false;
|
|
272
|
+
let uiPromptInProgress = false;
|
|
273
|
+
const ensureActivity = (activeTelegramTarget) => {
|
|
274
|
+
if (activityId)
|
|
275
|
+
return activityId;
|
|
276
|
+
nextActivityNumber += 1;
|
|
277
|
+
activityId = `${deps.generation}:${nextActivityNumber}`;
|
|
278
|
+
activitySource = activeTelegramTarget
|
|
279
|
+
? "telegram"
|
|
280
|
+
: pendingInputSource === "interactive" || pendingInputSource === "rpc"
|
|
281
|
+
? "local"
|
|
282
|
+
: pendingInputSource === "extension"
|
|
283
|
+
? "autonomous"
|
|
284
|
+
: "unknown";
|
|
285
|
+
activityTarget = activeTelegramTarget
|
|
286
|
+
? cloneActivityTarget(activeTelegramTarget)
|
|
287
|
+
: undefined;
|
|
288
|
+
sequence = 0;
|
|
289
|
+
pendingInputSource = "unknown";
|
|
290
|
+
return activityId;
|
|
291
|
+
};
|
|
292
|
+
const emit = (event) => {
|
|
293
|
+
const currentActivityId = ensureActivity();
|
|
294
|
+
sequence += 1;
|
|
295
|
+
const normalizedEvent = {
|
|
296
|
+
...event,
|
|
297
|
+
activityId: currentActivityId,
|
|
298
|
+
sequence,
|
|
299
|
+
source: activitySource,
|
|
300
|
+
...(activityTarget ? { target: activityTarget } : {}),
|
|
301
|
+
...(activityReplyToMessageId !== undefined ? { replyToMessageId: activityReplyToMessageId } : {}),
|
|
302
|
+
timestamp: now(),
|
|
303
|
+
};
|
|
304
|
+
try {
|
|
305
|
+
deps.observeEvent?.(normalizedEvent);
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
deps.recordObserverFailure?.(normalizedEvent, error);
|
|
309
|
+
}
|
|
310
|
+
deps.dispatcher.dispatch(normalizedEvent);
|
|
311
|
+
};
|
|
312
|
+
const flushPendingSegment = (placement) => {
|
|
313
|
+
const segment = pendingAssistantSegment;
|
|
314
|
+
pendingAssistantSegment = undefined;
|
|
315
|
+
if (!segment?.text.trim())
|
|
316
|
+
return;
|
|
317
|
+
emit({
|
|
318
|
+
type: "assistant-segment",
|
|
319
|
+
contentIndex: segment.contentIndex,
|
|
320
|
+
text: segment.text,
|
|
321
|
+
placement,
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
const clearActivity = () => {
|
|
325
|
+
activityId = undefined;
|
|
326
|
+
activitySource = "unknown";
|
|
327
|
+
activityTarget = undefined;
|
|
328
|
+
activityReplyToMessageId = undefined;
|
|
329
|
+
sequence = 0;
|
|
330
|
+
pendingAssistantSegment = undefined;
|
|
331
|
+
compactionInProgress = false;
|
|
332
|
+
compactionOwnedActivity = false;
|
|
333
|
+
uiPromptInProgress = false;
|
|
334
|
+
};
|
|
335
|
+
const abandonCompaction = () => {
|
|
336
|
+
if (!compactionInProgress)
|
|
337
|
+
return;
|
|
338
|
+
const shouldClearActivity = compactionOwnedActivity;
|
|
339
|
+
compactionInProgress = false;
|
|
340
|
+
compactionOwnedActivity = false;
|
|
341
|
+
if (shouldClearActivity)
|
|
342
|
+
clearActivity();
|
|
343
|
+
};
|
|
344
|
+
return {
|
|
345
|
+
recordInputSource(source) {
|
|
346
|
+
pendingInputSource = source;
|
|
347
|
+
},
|
|
348
|
+
onAgentStart(activeTelegramTarget, replyToMessageId) {
|
|
349
|
+
abandonCompaction();
|
|
350
|
+
ensureActivity(activeTelegramTarget);
|
|
351
|
+
activityReplyToMessageId = activitySource === "telegram" ? replyToMessageId : undefined;
|
|
352
|
+
emit({ type: "agent-start" });
|
|
353
|
+
},
|
|
354
|
+
onAssistantEvent(event) {
|
|
355
|
+
if (event.type === "text_start") {
|
|
356
|
+
flushPendingSegment("intermediate");
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (event.type === "text_delta") {
|
|
360
|
+
if (!event.delta)
|
|
361
|
+
return;
|
|
362
|
+
emit({
|
|
363
|
+
type: "assistant-text-delta",
|
|
364
|
+
contentIndex: event.contentIndex,
|
|
365
|
+
delta: event.delta,
|
|
366
|
+
});
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (event.type === "text_end") {
|
|
370
|
+
pendingAssistantSegment = {
|
|
371
|
+
contentIndex: event.contentIndex,
|
|
372
|
+
text: event.content,
|
|
373
|
+
};
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (event.type === "thinking_delta") {
|
|
377
|
+
if (!event.delta)
|
|
378
|
+
return;
|
|
379
|
+
emit({
|
|
380
|
+
type: "reasoning-delta",
|
|
381
|
+
contentIndex: event.contentIndex,
|
|
382
|
+
delta: event.delta,
|
|
383
|
+
});
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (event.type === "thinking_end") {
|
|
387
|
+
if (!event.content.trim())
|
|
388
|
+
return;
|
|
389
|
+
emit({
|
|
390
|
+
type: "reasoning-end",
|
|
391
|
+
contentIndex: event.contentIndex,
|
|
392
|
+
text: event.content,
|
|
393
|
+
});
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (event.type === "toolcall_start") {
|
|
397
|
+
flushPendingSegment("intermediate");
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (event.type === "done") {
|
|
401
|
+
flushPendingSegment("final");
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (event.type === "error")
|
|
405
|
+
flushPendingSegment("terminal-partial");
|
|
406
|
+
},
|
|
407
|
+
onAssistantMessageEnd(stopReason) {
|
|
408
|
+
if (stopReason === "aborted")
|
|
409
|
+
pendingAssistantSegment = undefined;
|
|
410
|
+
},
|
|
411
|
+
onToolStart(event) {
|
|
412
|
+
emit({ type: "tool-start", ...event });
|
|
413
|
+
},
|
|
414
|
+
onToolUpdate(event) {
|
|
415
|
+
emit({ type: "tool-update", ...event });
|
|
416
|
+
},
|
|
417
|
+
onToolEnd(event) {
|
|
418
|
+
emit({ type: "tool-end", ...event });
|
|
419
|
+
},
|
|
420
|
+
onCompactionStart(reason) {
|
|
421
|
+
abandonCompaction();
|
|
422
|
+
compactionOwnedActivity = !activityId;
|
|
423
|
+
compactionInProgress = true;
|
|
424
|
+
ensureActivity();
|
|
425
|
+
emit({ type: "compaction-start", reason });
|
|
426
|
+
},
|
|
427
|
+
onCompactionEnd(reason) {
|
|
428
|
+
if (!compactionInProgress || !activityId)
|
|
429
|
+
return;
|
|
430
|
+
const shouldClearActivity = compactionOwnedActivity;
|
|
431
|
+
compactionInProgress = false;
|
|
432
|
+
compactionOwnedActivity = false;
|
|
433
|
+
emit({ type: "compaction-end", reason });
|
|
434
|
+
if (shouldClearActivity)
|
|
435
|
+
clearActivity();
|
|
436
|
+
},
|
|
437
|
+
onCompactionAbandoned() {
|
|
438
|
+
abandonCompaction();
|
|
439
|
+
},
|
|
440
|
+
onUiPromptStart(kind, title) {
|
|
441
|
+
if (!activityId || uiPromptInProgress)
|
|
442
|
+
return;
|
|
443
|
+
uiPromptInProgress = true;
|
|
444
|
+
emit({ type: "ui-prompt-start", kind, title });
|
|
445
|
+
},
|
|
446
|
+
onUiPromptEnd() {
|
|
447
|
+
if (!activityId || !uiPromptInProgress)
|
|
448
|
+
return;
|
|
449
|
+
uiPromptInProgress = false;
|
|
450
|
+
emit({ type: "ui-prompt-end" });
|
|
451
|
+
},
|
|
452
|
+
onAgentEnd() {
|
|
453
|
+
if (activityId)
|
|
454
|
+
emit({ type: "agent-end" });
|
|
455
|
+
},
|
|
456
|
+
onAgentSettled() {
|
|
457
|
+
if (!activityId)
|
|
458
|
+
return;
|
|
459
|
+
flushPendingSegment("terminal-partial");
|
|
460
|
+
emit({ type: "agent-settled" });
|
|
461
|
+
clearActivity();
|
|
462
|
+
},
|
|
463
|
+
onSessionShutdown() {
|
|
464
|
+
pendingInputSource = "unknown";
|
|
465
|
+
clearActivity();
|
|
466
|
+
deps.dispatcher.stop();
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
export function createTelegramActivityPublicationRuntime() {
|
|
471
|
+
let generation = 0;
|
|
472
|
+
let tail = Promise.resolve();
|
|
473
|
+
const pending = new Set();
|
|
474
|
+
const reserve = () => {
|
|
475
|
+
const admittedGeneration = generation;
|
|
476
|
+
let state = "pending";
|
|
477
|
+
let resolve;
|
|
478
|
+
const ready = new Promise((accept) => { resolve = accept; });
|
|
479
|
+
const cancel = () => {
|
|
480
|
+
if (state !== "pending")
|
|
481
|
+
return;
|
|
482
|
+
state = "cancelled";
|
|
483
|
+
pending.delete(cancel);
|
|
484
|
+
resolve(undefined);
|
|
485
|
+
};
|
|
486
|
+
pending.add(cancel);
|
|
487
|
+
const result = tail.then(async () => {
|
|
488
|
+
const task = await ready;
|
|
489
|
+
if (admittedGeneration === generation && task)
|
|
490
|
+
await task();
|
|
491
|
+
});
|
|
492
|
+
tail = result.catch(() => { });
|
|
493
|
+
return {
|
|
494
|
+
publish(task) {
|
|
495
|
+
if (state === "cancelled")
|
|
496
|
+
return result;
|
|
497
|
+
if (state === "published")
|
|
498
|
+
return Promise.reject(new Error("Publication reservation already published."));
|
|
499
|
+
state = "published";
|
|
500
|
+
pending.delete(cancel);
|
|
501
|
+
resolve(task);
|
|
502
|
+
return result;
|
|
503
|
+
},
|
|
504
|
+
cancel,
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
return {
|
|
508
|
+
reserve,
|
|
509
|
+
enqueue: (task) => reserve().publish(task),
|
|
510
|
+
reset() {
|
|
511
|
+
generation += 1;
|
|
512
|
+
for (const cancel of pending)
|
|
513
|
+
cancel();
|
|
514
|
+
tail = Promise.resolve();
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
export function createTelegramAssistantOutputRuntime(deps) {
|
|
519
|
+
let generation = 0;
|
|
520
|
+
let running = false;
|
|
521
|
+
let tail = Promise.resolve();
|
|
522
|
+
const admitted = new Set();
|
|
523
|
+
const isEligibleEvent = (event) => (event.source === "telegram" && event.placement === "intermediate") ||
|
|
524
|
+
event.source === "local" ||
|
|
525
|
+
event.source === "autonomous" ||
|
|
526
|
+
event.source === "unknown";
|
|
527
|
+
return {
|
|
528
|
+
start() {
|
|
529
|
+
generation += 1;
|
|
530
|
+
running = true;
|
|
531
|
+
admitted.clear();
|
|
532
|
+
tail = Promise.resolve();
|
|
533
|
+
},
|
|
534
|
+
accept(event) {
|
|
535
|
+
if (!running || !isEligibleEvent(event) || !event.text.trim())
|
|
536
|
+
return;
|
|
537
|
+
const key = `${event.activityId}:${event.sequence}`;
|
|
538
|
+
if (admitted.has(key))
|
|
539
|
+
return;
|
|
540
|
+
admitted.add(key);
|
|
541
|
+
const admittedGeneration = generation;
|
|
542
|
+
const admittedAuthority = deps.captureAuthority?.();
|
|
543
|
+
const preparation = deps.prepareSend?.(event);
|
|
544
|
+
const enqueue = deps.enqueue ?? ((task) => tail.then(task));
|
|
545
|
+
tail = enqueue(async () => {
|
|
546
|
+
const isAdmittedAuthorityActive = () => running &&
|
|
547
|
+
generation === admittedGeneration &&
|
|
548
|
+
isEligibleEvent(event) &&
|
|
549
|
+
(deps.isAuthorityActive === undefined ||
|
|
550
|
+
deps.isAuthorityActive(admittedAuthority));
|
|
551
|
+
if (!isAdmittedAuthorityActive() || !deps.canDeliver(event))
|
|
552
|
+
return;
|
|
553
|
+
try {
|
|
554
|
+
if (preparation)
|
|
555
|
+
await preparation.wait();
|
|
556
|
+
if (!isAdmittedAuthorityActive() || !deps.canDeliver(event))
|
|
557
|
+
return;
|
|
558
|
+
await deps.send(event, admittedAuthority, isAdmittedAuthorityActive);
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
deps.recordFailure?.(event, error);
|
|
562
|
+
}
|
|
563
|
+
}).finally(() => preparation?.settle());
|
|
564
|
+
},
|
|
565
|
+
waitForIdle() {
|
|
566
|
+
return tail;
|
|
567
|
+
},
|
|
568
|
+
stop() {
|
|
569
|
+
generation += 1;
|
|
570
|
+
running = false;
|
|
571
|
+
admitted.clear();
|
|
572
|
+
},
|
|
573
|
+
};
|
|
574
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-instance Telegram agent message resolution and turn injection
|
|
3
|
+
* Zones: multi-instance bus, inbound routing, operational delivery
|
|
4
|
+
* Owns live target resolution, source attribution, same-target fencing, and synthetic turn construction; excludes Bot API delivery and bus transport.
|
|
5
|
+
*/
|
|
6
|
+
import type { TelegramBusAgentMessage, TelegramBusAgentTargetSelector, TelegramBusFollowerRegistry } from "./bus.ts";
|
|
7
|
+
import type { TelegramTarget } from "./target.ts";
|
|
8
|
+
export interface TelegramAgentMessageRuntimeDeps<TContext, TUpdate> {
|
|
9
|
+
instanceId: string;
|
|
10
|
+
getAllowedChatId: () => number | undefined;
|
|
11
|
+
getLeaderTarget: () => TelegramTarget | undefined;
|
|
12
|
+
getLeaderThreadName: () => string | undefined;
|
|
13
|
+
getDisplayTitle?: (target: TelegramTarget) => string | undefined;
|
|
14
|
+
followerRegistry: TelegramBusFollowerRegistry;
|
|
15
|
+
getContext: () => TContext | undefined;
|
|
16
|
+
handleUpdate: (update: TUpdate, ctx: TContext) => Promise<void>;
|
|
17
|
+
getNowMs?: () => number;
|
|
18
|
+
}
|
|
19
|
+
export declare function createTelegramAgentMessageRuntime<TContext, TUpdate>(deps: TelegramAgentMessageRuntimeDeps<TContext, TUpdate>): {
|
|
20
|
+
resolveTarget: (selector: TelegramBusAgentTargetSelector, sourceTarget?: TelegramTarget) => (TelegramTarget & {
|
|
21
|
+
threadId: number;
|
|
22
|
+
}) | undefined;
|
|
23
|
+
route(input: {
|
|
24
|
+
sourceTarget?: TelegramTarget;
|
|
25
|
+
sourceThreadName?: string;
|
|
26
|
+
message: TelegramBusAgentMessage;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-instance Telegram agent message resolution and turn injection
|
|
3
|
+
* Zones: multi-instance bus, inbound routing, operational delivery
|
|
4
|
+
* Owns live target resolution, source attribution, same-target fencing, and synthetic turn construction; excludes Bot API delivery and bus transport.
|
|
5
|
+
*/
|
|
6
|
+
import { TELEGRAM_INTERNAL_AGENT_MESSAGE } from "./updates.js";
|
|
7
|
+
export function createTelegramAgentMessageRuntime(deps) {
|
|
8
|
+
const getNowMs = deps.getNowMs ?? Date.now;
|
|
9
|
+
const sameTarget = (left, right) => left?.chatId === right?.chatId && left?.threadId === right?.threadId;
|
|
10
|
+
const listLiveTargets = () => {
|
|
11
|
+
const targets = [];
|
|
12
|
+
const leaderTarget = deps.getLeaderTarget();
|
|
13
|
+
if (leaderTarget?.threadId) {
|
|
14
|
+
targets.push({
|
|
15
|
+
target: { chatId: leaderTarget.chatId, threadId: leaderTarget.threadId },
|
|
16
|
+
threadName: deps.getDisplayTitle?.(leaderTarget) ?? deps.getLeaderThreadName(),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
for (const follower of deps.followerRegistry.list()) {
|
|
20
|
+
if (!follower.target?.threadId)
|
|
21
|
+
continue;
|
|
22
|
+
targets.push({
|
|
23
|
+
target: {
|
|
24
|
+
chatId: follower.target.chatId,
|
|
25
|
+
threadId: follower.target.threadId,
|
|
26
|
+
},
|
|
27
|
+
threadName: deps.getDisplayTitle?.(follower.target) ?? follower.threadName,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return targets;
|
|
31
|
+
};
|
|
32
|
+
const resolveTarget = (selector, sourceTarget) => {
|
|
33
|
+
const allowedChatId = deps.getAllowedChatId();
|
|
34
|
+
const chatId = selector.chatId ?? allowedChatId;
|
|
35
|
+
if (chatId === undefined || chatId !== allowedChatId)
|
|
36
|
+
return undefined;
|
|
37
|
+
const matches = listLiveTargets().filter((candidate) => {
|
|
38
|
+
if (candidate.target.chatId !== chatId)
|
|
39
|
+
return false;
|
|
40
|
+
if (selector.threadId !== undefined) {
|
|
41
|
+
return candidate.target.threadId === selector.threadId;
|
|
42
|
+
}
|
|
43
|
+
const requestedName = selector.threadName?.trim().toLocaleLowerCase();
|
|
44
|
+
return (requestedName !== undefined &&
|
|
45
|
+
requestedName.length > 0 &&
|
|
46
|
+
candidate.threadName?.trim().toLocaleLowerCase() === requestedName);
|
|
47
|
+
});
|
|
48
|
+
if (matches.length !== 1)
|
|
49
|
+
return undefined;
|
|
50
|
+
return sameTarget(matches[0].target, sourceTarget)
|
|
51
|
+
? undefined
|
|
52
|
+
: matches[0].target;
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
resolveTarget,
|
|
56
|
+
async route(input) {
|
|
57
|
+
const target = resolveTarget({
|
|
58
|
+
chatId: input.message.target.chatId,
|
|
59
|
+
threadId: input.message.target.threadId,
|
|
60
|
+
}, input.sourceTarget);
|
|
61
|
+
if (!target)
|
|
62
|
+
throw new Error("Telegram agent target is no longer live.");
|
|
63
|
+
const allowedChatId = deps.getAllowedChatId();
|
|
64
|
+
const ctx = deps.getContext();
|
|
65
|
+
if (allowedChatId === undefined || !ctx) {
|
|
66
|
+
throw new Error("Telegram agent turn routing is unavailable.");
|
|
67
|
+
}
|
|
68
|
+
const sourceTitle = (input.sourceTarget ? deps.getDisplayTitle?.(input.sourceTarget) : undefined)
|
|
69
|
+
?? input.sourceThreadName;
|
|
70
|
+
const sourceLabel = sourceTitle
|
|
71
|
+
?.replace(/[\r\n\[\]]+/g, " ")
|
|
72
|
+
.trim()
|
|
73
|
+
.slice(0, 64) || "Pi";
|
|
74
|
+
const message = {
|
|
75
|
+
message_id: input.message.messageId,
|
|
76
|
+
date: Math.floor(getNowMs() / 1000),
|
|
77
|
+
chat: { id: target.chatId, type: "private" },
|
|
78
|
+
from: { id: allowedChatId, is_bot: false, first_name: "Pi Agent" },
|
|
79
|
+
message_thread_id: target.threadId,
|
|
80
|
+
pi_telegram_agent_source_thread: sourceLabel,
|
|
81
|
+
text: input.message.text,
|
|
82
|
+
};
|
|
83
|
+
await deps.handleUpdate({ message, [TELEGRAM_INTERNAL_AGENT_MESSAGE]: true }, ctx);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|