@llblab/pi-kit 0.1.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/AGENTS.md +35 -0
- package/BACKLOG.md +3 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/node_modules/@llblab/pi-actors/AGENTS.md +150 -0
- package/node_modules/@llblab/pi-actors/BACKLOG.md +6 -0
- package/node_modules/@llblab/pi-actors/CHANGELOG.md +865 -0
- package/node_modules/@llblab/pi-actors/README.md +231 -0
- package/node_modules/@llblab/pi-actors/banner.jpg +0 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/artifact-manifest.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/control-endpoint.json +6 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/control-record.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/recipe-summary.json +8 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/run-state.json +10 -0
- package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/trace-event.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/index.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/index.js +17 -0
- package/node_modules/@llblab/pi-actors/dist/lib/async-runs.d.ts +146 -0
- package/node_modules/@llblab/pi-actors/dist/lib/async-runs.js +800 -0
- package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.js +103 -0
- package/node_modules/@llblab/pi-actors/dist/lib/command-templates.d.ts +85 -0
- package/node_modules/@llblab/pi-actors/dist/lib/command-templates.js +804 -0
- package/node_modules/@llblab/pi-actors/dist/lib/config.d.ts +34 -0
- package/node_modules/@llblab/pi-actors/dist/lib/config.js +216 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control-projection.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control-projection.js +66 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control.d.ts +15 -0
- package/node_modules/@llblab/pi-actors/dist/lib/control.js +97 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation-transaction.d.ts +65 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation-transaction.js +610 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation.d.ts +35 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation.js +126 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-review.d.ts +56 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-review.js +254 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-sleep.d.ts +65 -0
- package/node_modules/@llblab/pi-actors/dist/lib/draft-sleep.js +467 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-output.d.ts +25 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-output.js +88 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.d.ts +17 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.js +85 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution.d.ts +99 -0
- package/node_modules/@llblab/pi-actors/dist/lib/execution.js +725 -0
- package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.js +141 -0
- package/node_modules/@llblab/pi-actors/dist/lib/file-state.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/file-state.js +310 -0
- package/node_modules/@llblab/pi-actors/dist/lib/identity.d.ts +9 -0
- package/node_modules/@llblab/pi-actors/dist/lib/identity.js +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.d.ts +16 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.js +57 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.js +37 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.d.ts +100 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.js +824 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/inspector.js +136 -0
- package/node_modules/@llblab/pi-actors/dist/lib/limits.d.ts +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/limits.js +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/model-context.d.ts +56 -0
- package/node_modules/@llblab/pi-actors/dist/lib/model-context.js +220 -0
- package/node_modules/@llblab/pi-actors/dist/lib/observability.d.ts +186 -0
- package/node_modules/@llblab/pi-actors/dist/lib/observability.js +951 -0
- package/node_modules/@llblab/pi-actors/dist/lib/paths.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/paths.js +72 -0
- package/node_modules/@llblab/pi-actors/dist/lib/pi.d.ts +19 -0
- package/node_modules/@llblab/pi-actors/dist/lib/pi.js +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/preflight-diagnostics.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/preflight-diagnostics.js +86 -0
- package/node_modules/@llblab/pi-actors/dist/lib/prompts.d.ts +24 -0
- package/node_modules/@llblab/pi-actors/dist/lib/prompts.js +49 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipe-control.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipe-control.js +43 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.d.ts +36 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.js +197 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-discovery.d.ts +77 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-discovery.js +783 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-references.d.ts +113 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-references.js +1108 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-usage.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/recipes-usage.js +494 -0
- package/node_modules/@llblab/pi-actors/dist/lib/registry.d.ts +67 -0
- package/node_modules/@llblab/pi-actors/dist/lib/registry.js +504 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-control.d.ts +14 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-control.js +110 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-diagnostics.d.ts +11 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-diagnostics.js +148 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-projection.d.ts +14 -0
- package/node_modules/@llblab/pi-actors/dist/lib/review-projection.js +166 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-evidence-policy.d.ts +95 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-evidence-policy.js +177 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.js +125 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.js +68 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.d.ts +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.js +150 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-control.js +89 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.d.ts +39 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.js +283 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-identity.d.ts +5 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-identity.js +11 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-index.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-index.js +142 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.js +96 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-parent-teardown.d.ts +51 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-parent-teardown.js +172 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-process.d.ts +22 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-process.js +125 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.js +108 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-start.d.ts +12 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-start.js +68 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-status.d.ts +10 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-status.js +68 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.d.ts +48 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.js +491 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-identity.d.ts +7 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-identity.js +35 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-triage.d.ts +29 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime-triage.js +60 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime.d.ts +69 -0
- package/node_modules/@llblab/pi-actors/dist/lib/runtime.js +339 -0
- package/node_modules/@llblab/pi-actors/dist/lib/schema.d.ts +60 -0
- package/node_modules/@llblab/pi-actors/dist/lib/schema.js +428 -0
- package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.d.ts +45 -0
- package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.js +204 -0
- package/node_modules/@llblab/pi-actors/dist/lib/state-readers.d.ts +21 -0
- package/node_modules/@llblab/pi-actors/dist/lib/state-readers.js +74 -0
- package/node_modules/@llblab/pi-actors/dist/lib/temp.d.ts +10 -0
- package/node_modules/@llblab/pi-actors/dist/lib/temp.js +90 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage-transaction.d.ts +27 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage-transaction.js +597 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage.d.ts +24 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage.js +98 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-scheduler.d.ts +80 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-scheduler.js +494 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-transaction.d.ts +50 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review-transaction.js +362 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review.d.ts +56 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tool-review.js +197 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-access.d.ts +19 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-access.js +44 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.d.ts +15 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.js +532 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-local.d.ts +17 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-local.js +191 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-message.d.ts +9 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-message.js +139 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-register.d.ts +18 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-register.js +41 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-response.d.ts +20 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-response.js +243 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.d.ts +15 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.js +133 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools.d.ts +28 -0
- package/node_modules/@llblab/pi-actors/dist/lib/tools.js +49 -0
- package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.d.ts +22 -0
- package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.js +231 -0
- package/node_modules/@llblab/pi-actors/dist/pi-actors/index.js +1 -0
- package/node_modules/@llblab/pi-actors/dist/scripts/async-runner.mjs +555 -0
- package/node_modules/@llblab/pi-actors/dist/scripts/build-dist.mjs +60 -0
- package/node_modules/@llblab/pi-actors/dist/scripts/conformance.mjs +63 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/SKILL.md +126 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/command-validate.json +13 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/jsonl-tail.json +10 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/recipe-validate.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/resource-locker-snapshot.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/resource-locker.json +25 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-ops-snapshot.json +15 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-state-files.json +13 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/diagnostics.md +44 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/persistent-tools.md +76 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/recipes.md +51 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/references/runs.md +41 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/resource-locker.mjs +425 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/run-utils.mjs +164 -0
- package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/validate-recipe.mjs +370 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/SKILL.md +33 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/bundle.json +77 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/file-write.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/manifest.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/report.json +39 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/write.json +53 -0
- package/node_modules/@llblab/pi-actors/dist/skills/artifacts/scripts/artifact-utils.mjs +63 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/SKILL.md +57 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/genapps/music-player.mjs +360 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/recipes/playback.json +29 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/scripts/playback-client.mjs +143 -0
- package/node_modules/@llblab/pi-actors/dist/skills/music-player/scripts/playback.mjs +1446 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/SKILL.md +37 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/changelog-head.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/changelog-section.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/docs-maintenance.json +66 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/git-log.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/git-status.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/markdown-index.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/package-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/release-readiness.json +115 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/release-summary.json +74 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/repo-health.json +75 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/run-ops.json +56 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/skill-summary.json +11 -0
- package/node_modules/@llblab/pi-actors/dist/skills/project-work/scripts/project-utils.mjs +89 -0
- package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/SKILL.md +36 -0
- package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/recipes/draft-review.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/recipes/tool-review.json +14 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/SKILL.md +84 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/architect.json +82 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/checkpoint-continuation.json +51 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/development-tasking.json +67 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/lens-review.json +63 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/quorum-review.json +65 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/research-synthesis.json +81 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/review-readiness.json +59 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-artifact.json +21 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-checkpoint.json +21 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-conflict-report.json +19 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-contradiction-map.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-critic.json +22 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-evidence-map.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-followup.json +21 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-judge.json +22 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-merge.json +24 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-normalize.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-plan.json +20 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-preflight.json +18 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-prompt.json +16 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-prompts.json +39 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-quorum.json +31 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-review-coordinator.json +170 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-review.json +26 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-task-card.json +22 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-tools.json +15 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-verify.json +23 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/references/development-swarm.md +189 -0
- package/node_modules/@llblab/pi-actors/dist/skills/swarm/references/review-swarms.md +115 -0
- package/node_modules/@llblab/pi-actors/docs/README.md +20 -0
- package/node_modules/@llblab/pi-actors/docs/actor-inspector.md +50 -0
- package/node_modules/@llblab/pi-actors/docs/async-runs.md +141 -0
- package/node_modules/@llblab/pi-actors/docs/command-templates.md +321 -0
- package/node_modules/@llblab/pi-actors/docs/recipe-library.md +89 -0
- package/node_modules/@llblab/pi-actors/docs/releasing.md +28 -0
- package/node_modules/@llblab/pi-actors/docs/template-recipes.md +175 -0
- package/node_modules/@llblab/pi-actors/docs/tool-registry.md +90 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/artifact-manifest.json +9 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/control-endpoint.json +6 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/control-record.json +9 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/recipe-summary.json +8 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/run-state.json +10 -0
- package/node_modules/@llblab/pi-actors/fixtures/protocol/trace-event.json +9 -0
- package/node_modules/@llblab/pi-actors/index.ts +30 -0
- package/node_modules/@llblab/pi-actors/lib/async-runs.ts +1245 -0
- package/node_modules/@llblab/pi-actors/lib/automatic-review-runtime.ts +148 -0
- package/node_modules/@llblab/pi-actors/lib/command-templates.ts +1116 -0
- package/node_modules/@llblab/pi-actors/lib/config.ts +261 -0
- package/node_modules/@llblab/pi-actors/lib/control-projection.ts +105 -0
- package/node_modules/@llblab/pi-actors/lib/control.ts +117 -0
- package/node_modules/@llblab/pi-actors/lib/draft-consolidation-transaction.ts +821 -0
- package/node_modules/@llblab/pi-actors/lib/draft-consolidation.ts +181 -0
- package/node_modules/@llblab/pi-actors/lib/draft-review.ts +325 -0
- package/node_modules/@llblab/pi-actors/lib/draft-sleep.ts +575 -0
- package/node_modules/@llblab/pi-actors/lib/execution-output.ts +123 -0
- package/node_modules/@llblab/pi-actors/lib/execution-sessions.ts +111 -0
- package/node_modules/@llblab/pi-actors/lib/execution.ts +1153 -0
- package/node_modules/@llblab/pi-actors/lib/extension-runtime.ts +181 -0
- package/node_modules/@llblab/pi-actors/lib/file-state.ts +306 -0
- package/node_modules/@llblab/pi-actors/lib/identity.ts +29 -0
- package/node_modules/@llblab/pi-actors/lib/inspector-actions.ts +79 -0
- package/node_modules/@llblab/pi-actors/lib/inspector-command.ts +54 -0
- package/node_modules/@llblab/pi-actors/lib/inspector-overlay.ts +901 -0
- package/node_modules/@llblab/pi-actors/lib/inspector.ts +204 -0
- package/node_modules/@llblab/pi-actors/lib/limits.ts +29 -0
- package/node_modules/@llblab/pi-actors/lib/model-context.ts +359 -0
- package/node_modules/@llblab/pi-actors/lib/observability.ts +1337 -0
- package/node_modules/@llblab/pi-actors/lib/paths.ts +111 -0
- package/node_modules/@llblab/pi-actors/lib/pi.ts +47 -0
- package/node_modules/@llblab/pi-actors/lib/preflight-diagnostics.ts +132 -0
- package/node_modules/@llblab/pi-actors/lib/prompts.ts +69 -0
- package/node_modules/@llblab/pi-actors/lib/recipe-control.ts +52 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-context.ts +268 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-discovery.ts +1060 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-references.ts +1598 -0
- package/node_modules/@llblab/pi-actors/lib/recipes-usage.ts +638 -0
- package/node_modules/@llblab/pi-actors/lib/registry.ts +806 -0
- package/node_modules/@llblab/pi-actors/lib/review-control.ts +136 -0
- package/node_modules/@llblab/pi-actors/lib/review-diagnostics.ts +164 -0
- package/node_modules/@llblab/pi-actors/lib/review-projection.ts +196 -0
- package/node_modules/@llblab/pi-actors/lib/run-evidence-policy.ts +242 -0
- package/node_modules/@llblab/pi-actors/lib/run-ui-runtime.ts +155 -0
- package/node_modules/@llblab/pi-actors/lib/runs-artifacts.ts +96 -0
- package/node_modules/@llblab/pi-actors/lib/runs-control-delivery.ts +209 -0
- package/node_modules/@llblab/pi-actors/lib/runs-control.ts +148 -0
- package/node_modules/@llblab/pi-actors/lib/runs-controls.ts +282 -0
- package/node_modules/@llblab/pi-actors/lib/runs-identity.ts +14 -0
- package/node_modules/@llblab/pi-actors/lib/runs-index.ts +192 -0
- package/node_modules/@llblab/pi-actors/lib/runs-ownership.ts +136 -0
- package/node_modules/@llblab/pi-actors/lib/runs-parent-teardown.ts +257 -0
- package/node_modules/@llblab/pi-actors/lib/runs-process.ts +174 -0
- package/node_modules/@llblab/pi-actors/lib/runs-retention.ts +140 -0
- package/node_modules/@llblab/pi-actors/lib/runs-start.ts +113 -0
- package/node_modules/@llblab/pi-actors/lib/runs-status.ts +101 -0
- package/node_modules/@llblab/pi-actors/lib/runs-trace.ts +611 -0
- package/node_modules/@llblab/pi-actors/lib/runtime-identity.ts +39 -0
- package/node_modules/@llblab/pi-actors/lib/runtime-triage.ts +106 -0
- package/node_modules/@llblab/pi-actors/lib/runtime.ts +430 -0
- package/node_modules/@llblab/pi-actors/lib/schema.ts +525 -0
- package/node_modules/@llblab/pi-actors/lib/session-evidence.ts +302 -0
- package/node_modules/@llblab/pi-actors/lib/state-readers.ts +93 -0
- package/node_modules/@llblab/pi-actors/lib/temp.ts +99 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-lineage-transaction.ts +881 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-lineage.ts +145 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-scheduler.ts +635 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review-transaction.ts +563 -0
- package/node_modules/@llblab/pi-actors/lib/tool-review.ts +270 -0
- package/node_modules/@llblab/pi-actors/lib/tools-access.ts +68 -0
- package/node_modules/@llblab/pi-actors/lib/tools-inspect.ts +673 -0
- package/node_modules/@llblab/pi-actors/lib/tools-local.ts +303 -0
- package/node_modules/@llblab/pi-actors/lib/tools-message.ts +176 -0
- package/node_modules/@llblab/pi-actors/lib/tools-register.ts +63 -0
- package/node_modules/@llblab/pi-actors/lib/tools-response.ts +285 -0
- package/node_modules/@llblab/pi-actors/lib/tools-spawn.ts +212 -0
- package/node_modules/@llblab/pi-actors/lib/tools.ts +88 -0
- package/node_modules/@llblab/pi-actors/lib/trace-projection.ts +306 -0
- package/node_modules/@llblab/pi-actors/package.json +76 -0
- package/node_modules/@llblab/pi-actors/scripts/async-runner.mjs +555 -0
- package/node_modules/@llblab/pi-actors/scripts/build-dist.mjs +60 -0
- package/node_modules/@llblab/pi-actors/scripts/conformance.mjs +63 -0
- package/node_modules/@llblab/pi-actors/skills/actors/SKILL.md +126 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/command-validate.json +13 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/jsonl-tail.json +10 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/recipe-validate.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/resource-locker-snapshot.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/resource-locker.json +25 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-ops-snapshot.json +15 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-state-files.json +13 -0
- package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/diagnostics.md +44 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/persistent-tools.md +76 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/recipes.md +51 -0
- package/node_modules/@llblab/pi-actors/skills/actors/references/runs.md +41 -0
- package/node_modules/@llblab/pi-actors/skills/actors/scripts/resource-locker.mjs +425 -0
- package/node_modules/@llblab/pi-actors/skills/actors/scripts/run-utils.mjs +164 -0
- package/node_modules/@llblab/pi-actors/skills/actors/scripts/validate-recipe.mjs +370 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/SKILL.md +33 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/bundle.json +77 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/file-write.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/manifest.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/report.json +39 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/write.json +53 -0
- package/node_modules/@llblab/pi-actors/skills/artifacts/scripts/artifact-utils.mjs +63 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/SKILL.md +57 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/genapps/music-player.mjs +360 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/recipes/playback.json +29 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/scripts/playback-client.mjs +143 -0
- package/node_modules/@llblab/pi-actors/skills/music-player/scripts/playback.mjs +1446 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/SKILL.md +37 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/changelog-head.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/changelog-section.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/docs-maintenance.json +66 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/git-log.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/git-status.json +9 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/markdown-index.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/package-summary.json +9 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/release-readiness.json +115 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/release-summary.json +74 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/repo-health.json +75 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/run-ops.json +56 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/recipes/skill-summary.json +11 -0
- package/node_modules/@llblab/pi-actors/skills/project-work/scripts/project-utils.mjs +89 -0
- package/node_modules/@llblab/pi-actors/skills/recipe-memory/SKILL.md +36 -0
- package/node_modules/@llblab/pi-actors/skills/recipe-memory/recipes/draft-review.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/recipe-memory/recipes/tool-review.json +14 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/SKILL.md +84 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/architect.json +82 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/checkpoint-continuation.json +51 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/development-tasking.json +67 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/lens-review.json +63 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/quorum-review.json +65 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/research-synthesis.json +81 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/review-readiness.json +59 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-artifact.json +21 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-checkpoint.json +21 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-conflict-report.json +19 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-contradiction-map.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-critic.json +22 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-evidence-map.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-followup.json +21 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-judge.json +22 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-merge.json +24 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-normalize.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-plan.json +20 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-preflight.json +18 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-prompt.json +16 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-prompts.json +39 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-quorum.json +31 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-review-coordinator.json +170 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-review.json +26 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-task-card.json +22 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-tools.json +15 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-verify.json +23 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/references/development-swarm.md +189 -0
- package/node_modules/@llblab/pi-actors/skills/swarm/references/review-swarms.md +115 -0
- package/node_modules/@llblab/pi-codex-usage/AGENTS.md +17 -0
- package/node_modules/@llblab/pi-codex-usage/BACKLOG.md +8 -0
- package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +80 -0
- package/node_modules/@llblab/pi-codex-usage/LICENSE +22 -0
- package/node_modules/@llblab/pi-codex-usage/README.md +113 -0
- package/node_modules/@llblab/pi-codex-usage/banner.jpg +0 -0
- package/node_modules/@llblab/pi-codex-usage/index.ts +1525 -0
- package/node_modules/@llblab/pi-codex-usage/package.json +59 -0
- package/node_modules/@llblab/pi-grow-loop/AGENTS.md +56 -0
- package/node_modules/@llblab/pi-grow-loop/BACKLOG.md +3 -0
- package/node_modules/@llblab/pi-grow-loop/CHANGELOG.md +126 -0
- package/node_modules/@llblab/pi-grow-loop/README.md +216 -0
- package/node_modules/@llblab/pi-grow-loop/banner.jpg +0 -0
- package/node_modules/@llblab/pi-grow-loop/index.ts +219 -0
- package/node_modules/@llblab/pi-grow-loop/package.json +64 -0
- package/node_modules/@llblab/pi-grow-loop/skills/grow-loop/SKILL.md +131 -0
- package/node_modules/@llblab/pi-grow-loop/skills/while-true/SKILL.md +233 -0
- package/node_modules/@llblab/pi-telegram/AGENTS.md +157 -0
- package/node_modules/@llblab/pi-telegram/BACKLOG.md +15 -0
- package/node_modules/@llblab/pi-telegram/CHANGELOG.md +886 -0
- package/node_modules/@llblab/pi-telegram/README.md +330 -0
- package/node_modules/@llblab/pi-telegram/api/activity.ts +15 -0
- package/node_modules/@llblab/pi-telegram/api/commands.ts +11 -0
- package/node_modules/@llblab/pi-telegram/api/delivery.ts +21 -0
- package/node_modules/@llblab/pi-telegram/api/inbound.ts +14 -0
- package/node_modules/@llblab/pi-telegram/api/keyboard.ts +11 -0
- package/node_modules/@llblab/pi-telegram/api/outbound.ts +11 -0
- package/node_modules/@llblab/pi-telegram/api/sections.ts +17 -0
- package/node_modules/@llblab/pi-telegram/api/status.ts +12 -0
- package/node_modules/@llblab/pi-telegram/api/updates.ts +16 -0
- package/node_modules/@llblab/pi-telegram/api/voice.ts +24 -0
- package/node_modules/@llblab/pi-telegram/docs/README.md +25 -0
- package/node_modules/@llblab/pi-telegram/docs/activity.md +304 -0
- package/node_modules/@llblab/pi-telegram/docs/architecture.md +418 -0
- package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +48 -0
- package/node_modules/@llblab/pi-telegram/docs/command-templates.md +365 -0
- package/node_modules/@llblab/pi-telegram/docs/compact-matrix-literal.md +176 -0
- package/node_modules/@llblab/pi-telegram/docs/delivery.md +225 -0
- package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +310 -0
- package/node_modules/@llblab/pi-telegram/docs/inbound.md +136 -0
- package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +467 -0
- package/node_modules/@llblab/pi-telegram/docs/outbound.md +193 -0
- package/node_modules/@llblab/pi-telegram/docs/public-api.md +599 -0
- package/node_modules/@llblab/pi-telegram/docs/sections.md +452 -0
- package/node_modules/@llblab/pi-telegram/docs/ui-style.md +256 -0
- package/node_modules/@llblab/pi-telegram/docs/updates.md +171 -0
- package/node_modules/@llblab/pi-telegram/docs/voice.md +217 -0
- package/node_modules/@llblab/pi-telegram/index.ts +1336 -0
- package/node_modules/@llblab/pi-telegram/lib/activity-verbosity.ts +714 -0
- package/node_modules/@llblab/pi-telegram/lib/activity.ts +782 -0
- package/node_modules/@llblab/pi-telegram/lib/agent-messages.ts +121 -0
- package/node_modules/@llblab/pi-telegram/lib/bindings.ts +1129 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +379 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +1941 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +2119 -0
- package/node_modules/@llblab/pi-telegram/lib/bus-transport.ts +244 -0
- package/node_modules/@llblab/pi-telegram/lib/bus.ts +2645 -0
- package/node_modules/@llblab/pi-telegram/lib/command-templates.ts +954 -0
- package/node_modules/@llblab/pi-telegram/lib/commands.ts +1854 -0
- package/node_modules/@llblab/pi-telegram/lib/config.ts +1143 -0
- package/node_modules/@llblab/pi-telegram/lib/delivery.ts +891 -0
- package/node_modules/@llblab/pi-telegram/lib/generative-app-worker.mjs +104 -0
- package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +958 -0
- package/node_modules/@llblab/pi-telegram/lib/inbound.ts +824 -0
- package/node_modules/@llblab/pi-telegram/lib/journal.ts +3140 -0
- package/node_modules/@llblab/pi-telegram/lib/keyboard.ts +59 -0
- package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +623 -0
- package/node_modules/@llblab/pi-telegram/lib/locks.ts +1422 -0
- package/node_modules/@llblab/pi-telegram/lib/logs.ts +393 -0
- package/node_modules/@llblab/pi-telegram/lib/media.ts +921 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +1182 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-queue.ts +926 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +876 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-status.ts +274 -0
- package/node_modules/@llblab/pi-telegram/lib/menu-thinking.ts +185 -0
- package/node_modules/@llblab/pi-telegram/lib/menu.ts +867 -0
- package/node_modules/@llblab/pi-telegram/lib/model.ts +672 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +981 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-buttons.ts +331 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +515 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound-voice.ts +285 -0
- package/node_modules/@llblab/pi-telegram/lib/outbound.ts +1007 -0
- package/node_modules/@llblab/pi-telegram/lib/ownership.ts +298 -0
- package/node_modules/@llblab/pi-telegram/lib/paths.ts +127 -0
- package/node_modules/@llblab/pi-telegram/lib/pi.ts +197 -0
- package/node_modules/@llblab/pi-telegram/lib/polling.ts +1588 -0
- package/node_modules/@llblab/pi-telegram/lib/preview.ts +846 -0
- package/node_modules/@llblab/pi-telegram/lib/prompt-templates.ts +158 -0
- package/node_modules/@llblab/pi-telegram/lib/prompts.ts +218 -0
- package/node_modules/@llblab/pi-telegram/lib/queue.ts +3075 -0
- package/node_modules/@llblab/pi-telegram/lib/recovery.ts +464 -0
- package/node_modules/@llblab/pi-telegram/lib/rendering.ts +1213 -0
- package/node_modules/@llblab/pi-telegram/lib/replies.ts +892 -0
- package/node_modules/@llblab/pi-telegram/lib/routing.ts +2889 -0
- package/node_modules/@llblab/pi-telegram/lib/runtime.ts +628 -0
- package/node_modules/@llblab/pi-telegram/lib/sections.ts +710 -0
- package/node_modules/@llblab/pi-telegram/lib/setup.ts +220 -0
- package/node_modules/@llblab/pi-telegram/lib/skills.ts +21 -0
- package/node_modules/@llblab/pi-telegram/lib/status.ts +1550 -0
- package/node_modules/@llblab/pi-telegram/lib/sync.ts +883 -0
- package/node_modules/@llblab/pi-telegram/lib/target.ts +49 -0
- package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +1747 -0
- package/node_modules/@llblab/pi-telegram/lib/text-groups.ts +487 -0
- package/node_modules/@llblab/pi-telegram/lib/thread-reconciler.ts +1002 -0
- package/node_modules/@llblab/pi-telegram/lib/threads.ts +3183 -0
- package/node_modules/@llblab/pi-telegram/lib/time-injection.ts +78 -0
- package/node_modules/@llblab/pi-telegram/lib/turns.ts +753 -0
- package/node_modules/@llblab/pi-telegram/lib/updates.ts +4950 -0
- package/node_modules/@llblab/pi-telegram/lib/voice.ts +340 -0
- package/node_modules/@llblab/pi-telegram/package.json +83 -0
- package/node_modules/@llblab/pi-telegram/screenshot.png +0 -0
- package/node_modules/@llblab/pi-telegram/scripts/check-downgrade.mjs +435 -0
- package/node_modules/@llblab/pi-telegram/skills/generated-control-surface/SKILL.md +241 -0
- package/node_modules/@llblab/pi-telegram/skills/generative-apps/SKILL.md +114 -0
- package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/SKILL.md +149 -0
- package/package.json +67 -0
|
@@ -0,0 +1,1336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram bridge extension entrypoint and orchestration layer
|
|
3
|
+
* Zones: telegram, pi agent, orchestration
|
|
4
|
+
* Keeps the runtime wiring in one place while delegating reusable domain logic to /lib modules
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as AgentMessages from "./lib/agent-messages.ts";
|
|
8
|
+
import * as Bindings from "./lib/bindings.ts";
|
|
9
|
+
import * as BusApi from "./lib/bus-api.ts";
|
|
10
|
+
import * as BusFollower from "./lib/bus-follower.ts";
|
|
11
|
+
import * as BusLeader from "./lib/bus-leader.ts";
|
|
12
|
+
import * as BusTransport from "./lib/bus-transport.ts";
|
|
13
|
+
import * as Bus from "./lib/bus.ts";
|
|
14
|
+
import * as CommandTemplates from "./lib/command-templates.ts";
|
|
15
|
+
import * as Commands from "./lib/commands.ts";
|
|
16
|
+
import * as Config from "./lib/config.ts";
|
|
17
|
+
import * as Delivery from "./lib/delivery.ts";
|
|
18
|
+
import * as Inbound from "./lib/inbound.ts";
|
|
19
|
+
import * as Journal from "./lib/journal.ts";
|
|
20
|
+
import * as Lifecycle from "./lib/lifecycle.ts";
|
|
21
|
+
import * as Locks from "./lib/locks.ts";
|
|
22
|
+
import * as Logs from "./lib/logs.ts";
|
|
23
|
+
import * as Media from "./lib/media.ts";
|
|
24
|
+
import * as MenuQueue from "./lib/menu-queue.ts";
|
|
25
|
+
import * as MenuSettings from "./lib/menu-settings.ts";
|
|
26
|
+
import * as Menu from "./lib/menu.ts";
|
|
27
|
+
import * as Model from "./lib/model.ts";
|
|
28
|
+
import * as Outbound from "./lib/outbound.ts";
|
|
29
|
+
import * as Ownership from "./lib/ownership.ts";
|
|
30
|
+
import * as Paths from "./lib/paths.ts";
|
|
31
|
+
import * as Pi from "./lib/pi.ts";
|
|
32
|
+
import * as Polling from "./lib/polling.ts";
|
|
33
|
+
import * as Preview from "./lib/preview.ts";
|
|
34
|
+
import * as PromptTemplates from "./lib/prompt-templates.ts";
|
|
35
|
+
import * as Prompts from "./lib/prompts.ts";
|
|
36
|
+
import * as Queue from "./lib/queue.ts";
|
|
37
|
+
import * as Recovery from "./lib/recovery.ts";
|
|
38
|
+
import * as Replies from "./lib/replies.ts";
|
|
39
|
+
import * as Routing from "./lib/routing.ts";
|
|
40
|
+
import * as Runtime from "./lib/runtime.ts";
|
|
41
|
+
import * as Sections from "./lib/sections.ts";
|
|
42
|
+
import * as Skills from "./lib/skills.ts";
|
|
43
|
+
import * as Status from "./lib/status.ts";
|
|
44
|
+
import * as Sync from "./lib/sync.ts";
|
|
45
|
+
import * as TelegramApi from "./lib/telegram-api.ts";
|
|
46
|
+
import * as TextGroups from "./lib/text-groups.ts";
|
|
47
|
+
import * as ThreadReconciler from "./lib/thread-reconciler.ts";
|
|
48
|
+
import * as Threads from "./lib/threads.ts";
|
|
49
|
+
import * as TimeInjection from "./lib/time-injection.ts";
|
|
50
|
+
import * as Updates from "./lib/updates.ts";
|
|
51
|
+
import * as Voice from "./lib/voice.ts";
|
|
52
|
+
|
|
53
|
+
type ActivePiModel = NonNullable<Pi.ExtensionContext["model"]>;
|
|
54
|
+
|
|
55
|
+
const telegramBusProtocolIdentity =
|
|
56
|
+
Bus.createTelegramCurrentBusProtocolIdentity([
|
|
57
|
+
Bus.TELEGRAM_BUS_CAPABILITY_DURABLE_FOLLOWER_ADMISSION,
|
|
58
|
+
Bus.TELEGRAM_BUS_CAPABILITY_QUEUE_HANDOFF,
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
// --- Extension Runtime ---
|
|
62
|
+
|
|
63
|
+
export default function (pi: Pi.ExtensionAPI) {
|
|
64
|
+
Skills.registerTelegramSkillDiscovery(pi);
|
|
65
|
+
const piRuntime = Pi.createExtensionApiRuntimePorts(pi);
|
|
66
|
+
const {
|
|
67
|
+
getActiveTools,
|
|
68
|
+
getCommands,
|
|
69
|
+
getThinkingLevel,
|
|
70
|
+
sendUserMessage,
|
|
71
|
+
setActiveTools,
|
|
72
|
+
setModel,
|
|
73
|
+
setThinkingLevel,
|
|
74
|
+
} = piRuntime;
|
|
75
|
+
const bridgeRuntime = Runtime.createTelegramBridgeRuntime();
|
|
76
|
+
const runtimeDiagnostics =
|
|
77
|
+
Logs.createTelegramRuntimeDiagnosticsRuntime<Pi.ExtensionContext>();
|
|
78
|
+
const runtimeEvents = runtimeDiagnostics.events;
|
|
79
|
+
const recordRuntimeEvent = runtimeDiagnostics.recordRuntimeEvent;
|
|
80
|
+
const configStore = Config.createTelegramConfigStore({ recordRuntimeEvent });
|
|
81
|
+
const busProcessRuntime = Bus.createCurrentTelegramBusProcessRuntime({
|
|
82
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
83
|
+
});
|
|
84
|
+
const {
|
|
85
|
+
instanceId: telegramInstanceId,
|
|
86
|
+
processId: telegramProcessId,
|
|
87
|
+
processBirthId: telegramQueueProcessBirthId,
|
|
88
|
+
manualFollowerOwnerId: telegramManualFollowerOwnerId,
|
|
89
|
+
getLeaderSocketPath: getTelegramBusSocketPath,
|
|
90
|
+
getFollowerSocketPath: getTelegramBusFollowerSocketPath,
|
|
91
|
+
} = busProcessRuntime;
|
|
92
|
+
const getTelegramBotId = Config.createTelegramConfigBotIdGetter(configStore);
|
|
93
|
+
const getTelegramActiveProfileKey =
|
|
94
|
+
Config.createTelegramActiveProfileKeyGetter(configStore);
|
|
95
|
+
const getTelegramManualFollowerProfileKey =
|
|
96
|
+
BusFollower.createTelegramManualFollowerProfileKeyResolver({
|
|
97
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
98
|
+
manualFollowerOwnerId: telegramManualFollowerOwnerId,
|
|
99
|
+
});
|
|
100
|
+
const telegramBusAuthSecret = Bus.createTelegramBusAuthSecret();
|
|
101
|
+
const telegramBusFollowerControlState =
|
|
102
|
+
BusFollower.createTelegramBusFollowerControlState();
|
|
103
|
+
const telegramBusFollowerRegistry = Bus.createTelegramBusFollowerRegistry();
|
|
104
|
+
const modelContextAvailabilityBinding =
|
|
105
|
+
Prompts.createTelegramModelContextAvailabilityBinding();
|
|
106
|
+
const telegramBusFollowerRegistrationState =
|
|
107
|
+
BusFollower.createTelegramBusFollowerRegistrationState({
|
|
108
|
+
onAvailabilityChanged: modelContextAvailabilityBinding.reconcile,
|
|
109
|
+
});
|
|
110
|
+
const telegramBusLeaderState =
|
|
111
|
+
Threads.createTelegramLeaderThreadStateRuntime();
|
|
112
|
+
const telegramThreadCapabilityState =
|
|
113
|
+
Polling.createTelegramThreadCapabilityStateRuntime();
|
|
114
|
+
const telegramProvisioningActivity =
|
|
115
|
+
Sync.createTelegramProvisioningActivityRuntime();
|
|
116
|
+
const messageOwnershipRuntime =
|
|
117
|
+
Ownership.createTelegramBusMessageOwnershipRuntime({
|
|
118
|
+
instanceId: telegramInstanceId,
|
|
119
|
+
getProfileKey: getTelegramActiveProfileKey,
|
|
120
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
121
|
+
});
|
|
122
|
+
const { abort, lifecycle, queue, setup, typing } = bridgeRuntime;
|
|
123
|
+
const getTelegramUpdateAdmissionScope =
|
|
124
|
+
Journal.createTelegramUpdateJournalReceiptScopeResolver({
|
|
125
|
+
getProfileName: configStore.getActiveProfileName,
|
|
126
|
+
getBotToken: configStore.getBotToken,
|
|
127
|
+
getBotId: getTelegramBotId,
|
|
128
|
+
});
|
|
129
|
+
const telegramJournalBindingRuntime =
|
|
130
|
+
Journal.createTelegramUpdateJournalBindingRuntime({
|
|
131
|
+
base: {
|
|
132
|
+
getProfileName: configStore.getActiveProfileName,
|
|
133
|
+
getBotToken: configStore.getBotToken,
|
|
134
|
+
getBotId: getTelegramBotId,
|
|
135
|
+
getQueueRuntimeIdentity() {
|
|
136
|
+
return {
|
|
137
|
+
instanceId: telegramInstanceId,
|
|
138
|
+
processId: telegramProcessId,
|
|
139
|
+
processBirthId: telegramQueueProcessBirthId,
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
getLeaderJournalPath: Paths.resolveTelegramUpdateJournalPath,
|
|
144
|
+
getFollowerJournalPath(bindingKey, profileName) {
|
|
145
|
+
return Paths.resolveTelegramFollowerJournalPath(
|
|
146
|
+
bindingKey,
|
|
147
|
+
undefined,
|
|
148
|
+
profileName,
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
getActiveFollowerBindingKey: getTelegramManualFollowerProfileKey,
|
|
152
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
153
|
+
});
|
|
154
|
+
const resolveTelegramUpdateJournalBinding =
|
|
155
|
+
telegramJournalBindingRuntime.resolveLeader;
|
|
156
|
+
const resolveTelegramFollowerJournalBinding =
|
|
157
|
+
telegramJournalBindingRuntime.resolveFollower;
|
|
158
|
+
const getTelegramQueueJournalBinding =
|
|
159
|
+
telegramJournalBindingRuntime.getActiveRecoveryKey;
|
|
160
|
+
const isTelegramBusRuntimeEnabled =
|
|
161
|
+
telegramThreadCapabilityState.isBusRuntimeEnabled;
|
|
162
|
+
Config.bindGlobalTelegramConfigRuntime(configStore);
|
|
163
|
+
const configControls = Config.createTelegramConfigControls(configStore);
|
|
164
|
+
const lockRuntime = Locks.createTelegramLockRuntime<Pi.ExtensionContext>({
|
|
165
|
+
key: Locks.createTelegramLockKeyResolver(configStore),
|
|
166
|
+
instanceId: telegramInstanceId,
|
|
167
|
+
busSecret: telegramBusAuthSecret,
|
|
168
|
+
staleHeartbeatMs: Locks.TELEGRAM_BUS_LEADER_STALE_HEARTBEAT_MS,
|
|
169
|
+
});
|
|
170
|
+
const threadStore = Threads.createTelegramTopicTargetStore({
|
|
171
|
+
path: function () {
|
|
172
|
+
return Threads.getTelegramTopicTargetsPath(
|
|
173
|
+
undefined,
|
|
174
|
+
configStore.getActiveProfileName(),
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
canPersist: lockRuntime.owns,
|
|
178
|
+
commitPersist: lockRuntime.commitIfOwned,
|
|
179
|
+
});
|
|
180
|
+
runtimeDiagnostics.bindStorage({
|
|
181
|
+
getBotToken: configStore.getBotToken,
|
|
182
|
+
getProfileName: configStore.getActiveProfileName,
|
|
183
|
+
canReset: lockRuntime.owns,
|
|
184
|
+
commitReset: lockRuntime.commitIfOwned,
|
|
185
|
+
});
|
|
186
|
+
const lockOwnershipGuard =
|
|
187
|
+
Locks.createTelegramLockOwnershipGuard(lockRuntime);
|
|
188
|
+
const getCurrentLeaderEpoch = lockRuntime.getOwnedLeaderEpoch;
|
|
189
|
+
const telegramSessionContextStore =
|
|
190
|
+
Lifecycle.createTelegramSessionContextStore<Pi.ExtensionContext>({
|
|
191
|
+
getIdentity(ctx) {
|
|
192
|
+
return ctx.sessionManager ?? ctx.cwd;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
const ownsTelegramDirectDelivery =
|
|
196
|
+
Locks.createTelegramDirectDeliveryOwnershipChecker({
|
|
197
|
+
lock: lockRuntime,
|
|
198
|
+
contextStore: telegramSessionContextStore,
|
|
199
|
+
});
|
|
200
|
+
const modelContextAvailabilityRuntime =
|
|
201
|
+
Prompts.createTelegramModelContextAvailabilityRuntime({
|
|
202
|
+
getActiveTools,
|
|
203
|
+
setActiveTools,
|
|
204
|
+
isAvailable() {
|
|
205
|
+
return (
|
|
206
|
+
ownsTelegramDirectDelivery() ||
|
|
207
|
+
telegramBusFollowerRegistrationState.isRegistered()
|
|
208
|
+
);
|
|
209
|
+
},
|
|
210
|
+
canReconcile() {
|
|
211
|
+
const ctx = telegramSessionContextStore.get();
|
|
212
|
+
return !ctx || Pi.isExtensionContextIdle(ctx);
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
modelContextAvailabilityBinding.bind(modelContextAvailabilityRuntime);
|
|
216
|
+
const activeTurnRuntime = Queue.createTelegramActiveTurnStore();
|
|
217
|
+
const proactivePushTargetGetter =
|
|
218
|
+
Config.createTelegramProactivePushTargetGetter({
|
|
219
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
220
|
+
getAssignedTarget() {
|
|
221
|
+
return (
|
|
222
|
+
telegramBusFollowerRegistrationState.getTarget() ??
|
|
223
|
+
telegramBusLeaderState.getTarget()
|
|
224
|
+
);
|
|
225
|
+
},
|
|
226
|
+
getAllowedUserId: configStore.getAllowedUserId,
|
|
227
|
+
});
|
|
228
|
+
const proactivePushChatIdGetter =
|
|
229
|
+
Config.createTelegramProactivePushChatIdGetter(proactivePushTargetGetter);
|
|
230
|
+
const buttonActionStore = Outbound.createTelegramButtonActionStore();
|
|
231
|
+
const planGenerativeAppOutput =
|
|
232
|
+
Outbound.createTelegramOutboundReplyPlanner(buttonActionStore);
|
|
233
|
+
const pendingModelSwitchStore =
|
|
234
|
+
Model.createPendingModelSwitchStore<
|
|
235
|
+
Model.ScopedTelegramModel<ActivePiModel>
|
|
236
|
+
>();
|
|
237
|
+
const modelMenuRuntime = Menu.createTelegramModelMenuRuntime<ActivePiModel>();
|
|
238
|
+
const sectionRegistry = Sections.createAndBindTelegramSectionRegistry();
|
|
239
|
+
|
|
240
|
+
const timeInjectionRuntime = TimeInjection.createTimeInjectionRuntime({
|
|
241
|
+
getConfig: Config.createTelegramTimeConfigGetter(configStore),
|
|
242
|
+
recordRuntimeEvent,
|
|
243
|
+
});
|
|
244
|
+
Outbound.bindTelegramRuntimeEventRecorder(recordRuntimeEvent);
|
|
245
|
+
const getContextModel = Pi.getExtensionContextModel;
|
|
246
|
+
const isIdle = Pi.isExtensionContextIdle;
|
|
247
|
+
const hasPendingMessages = Pi.hasExtensionContextPendingMessages;
|
|
248
|
+
const compact = Pi.compactExtensionContext;
|
|
249
|
+
const mediaGroupRuntime = Media.createTelegramMediaGroupController<
|
|
250
|
+
TelegramApi.TelegramMessage,
|
|
251
|
+
Pi.ExtensionContext
|
|
252
|
+
>();
|
|
253
|
+
const textGroupRuntime = TextGroups.createTelegramTextGroupController<
|
|
254
|
+
TelegramApi.TelegramMessage,
|
|
255
|
+
Pi.ExtensionContext
|
|
256
|
+
>();
|
|
257
|
+
const rawTelegramQueueStore =
|
|
258
|
+
Queue.createTelegramQueueStore<Pi.ExtensionContext>();
|
|
259
|
+
const telegramTransportStampRuntime =
|
|
260
|
+
Queue.createTelegramTransportStampRuntime({
|
|
261
|
+
getProfileName: configStore.getActiveProfileName,
|
|
262
|
+
getBotToken: configStore.getBotToken,
|
|
263
|
+
});
|
|
264
|
+
const telegramQueueStore = Queue.createTelegramTransportStampedQueueStore(
|
|
265
|
+
rawTelegramQueueStore,
|
|
266
|
+
telegramTransportStampRuntime.getStamp,
|
|
267
|
+
);
|
|
268
|
+
const updateAdmissionRuntimeBinding =
|
|
269
|
+
Updates.createTelegramUpdateAdmissionRuntimeBinding<Pi.ExtensionContext>({
|
|
270
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
271
|
+
});
|
|
272
|
+
const deferredQueueDispatchRuntime =
|
|
273
|
+
Queue.createTelegramDeferredQueueDispatchRuntime<Pi.ExtensionContext>({
|
|
274
|
+
recordRuntimeEvent,
|
|
275
|
+
});
|
|
276
|
+
const pollingControllerState = Polling.createTelegramPollingControllerState();
|
|
277
|
+
const telegramSyncStateRuntime = Sync.createTelegramSyncStateRuntime();
|
|
278
|
+
const threadReconciliationRuntime =
|
|
279
|
+
ThreadReconciler.createThreadReconciliationRuntime({
|
|
280
|
+
recordRuntimeEvent,
|
|
281
|
+
scheduleSnapshotPersist: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
282
|
+
});
|
|
283
|
+
const recordThreadReconciliationPlan = threadReconciliationRuntime.recordPlan;
|
|
284
|
+
const persistTelegramConfigWithSync =
|
|
285
|
+
Sync.createTelegramConfigSyncPersister<Config.TelegramConfig>({
|
|
286
|
+
persist: configStore.persist,
|
|
287
|
+
markConfigChange: telegramSyncStateRuntime.markConfigChange,
|
|
288
|
+
});
|
|
289
|
+
const persistTelegramPollingOffset =
|
|
290
|
+
Config.createTelegramPollingOffsetPersister(
|
|
291
|
+
configStore,
|
|
292
|
+
persistTelegramConfigWithSync,
|
|
293
|
+
);
|
|
294
|
+
const {
|
|
295
|
+
current: currentInstanceThreadRuntime,
|
|
296
|
+
status: threadStatusProjectionRuntime,
|
|
297
|
+
} = Threads.createTelegramCurrentThreadAssembly({
|
|
298
|
+
instanceId: telegramInstanceId,
|
|
299
|
+
listRecords: threadStore.list,
|
|
300
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
301
|
+
getFollowerTarget: telegramBusFollowerRegistrationState.getTarget,
|
|
302
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
303
|
+
getFollowerSlot: telegramBusFollowerRegistrationState.getSlot,
|
|
304
|
+
getFollowerThreadName: telegramBusFollowerRegistrationState.getThreadName,
|
|
305
|
+
getLeaderIdentity: telegramBusLeaderState.getIdentity,
|
|
306
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
307
|
+
getLeaderProtocol: telegramBusFollowerRegistrationState.getLeaderProtocol,
|
|
308
|
+
status: {
|
|
309
|
+
getThreadMode: function () {
|
|
310
|
+
return threadStore.getBotState().threadMode;
|
|
311
|
+
},
|
|
312
|
+
isBusPollingStarted: telegramThreadCapabilityState.isBusPollingStarted,
|
|
313
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
314
|
+
listReservations: threadStore.listReservations,
|
|
315
|
+
listSyncObservations: threadStore.listSyncObservations,
|
|
316
|
+
getLeaderSocketPath: getTelegramBusSocketPath,
|
|
317
|
+
getFollowerSocketPath: getTelegramBusFollowerSocketPath,
|
|
318
|
+
getTransportKind: BusTransport.getTelegramBusTransportKind,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
const findCurrentThreadRecord = currentInstanceThreadRuntime.findRecord;
|
|
322
|
+
const getCurrentInstanceThreadIdentity =
|
|
323
|
+
currentInstanceThreadRuntime.getIdentity;
|
|
324
|
+
const statusRuntime = Status.createTelegramBridgeStatusRuntime<
|
|
325
|
+
Pi.ExtensionContext,
|
|
326
|
+
Queue.TelegramQueueItem<Pi.ExtensionContext>
|
|
327
|
+
>({
|
|
328
|
+
getConfig: configStore.get,
|
|
329
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
330
|
+
getDiagnosticPaths: Paths.getTelegramDiagnosticsDisplayPaths,
|
|
331
|
+
isPollingActive: Polling.createTelegramPollingActivityReader(
|
|
332
|
+
pollingControllerState,
|
|
333
|
+
),
|
|
334
|
+
getPollingState: Polling.createTelegramPollingStateReader(
|
|
335
|
+
pollingControllerState,
|
|
336
|
+
),
|
|
337
|
+
getInboundWorkerState() {
|
|
338
|
+
return updateAdmissionRuntimeBinding.getActive()?.getState();
|
|
339
|
+
},
|
|
340
|
+
getActiveSourceMessageIds: activeTurnRuntime.getSourceMessageIds,
|
|
341
|
+
hasActiveTurn: activeTurnRuntime.has,
|
|
342
|
+
hasDispatchPending: lifecycle.hasDispatchPending,
|
|
343
|
+
isCompactionInProgress: lifecycle.isCompactionInProgress,
|
|
344
|
+
getActiveToolExecutions: lifecycle.getActiveToolExecutions,
|
|
345
|
+
hasPendingModelSwitch: pendingModelSwitchStore.has,
|
|
346
|
+
getQueuedItems: telegramQueueStore.getQueuedItems,
|
|
347
|
+
formatQueuedStatus: Queue.formatQueuedTelegramItemsStatus,
|
|
348
|
+
getRecentRuntimeEvents: runtimeEvents.getEvents,
|
|
349
|
+
getRuntimeLockState: lockRuntime.getStatusLabel,
|
|
350
|
+
...threadStatusProjectionRuntime,
|
|
351
|
+
getBusProtocol() {
|
|
352
|
+
return telegramBusProtocolIdentity;
|
|
353
|
+
},
|
|
354
|
+
getBusLifecyclePhase: telegramBusFollowerControlState.getLifecyclePhase,
|
|
355
|
+
getBotThreadMode() {
|
|
356
|
+
return threadStore.getBotState();
|
|
357
|
+
},
|
|
358
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
359
|
+
getThreadReconciliationState() {
|
|
360
|
+
return threadReconciliationRuntime.getState();
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
runtimeDiagnostics.bindStatus({
|
|
364
|
+
instanceId: telegramInstanceId,
|
|
365
|
+
updateStatus: statusRuntime.updateStatus,
|
|
366
|
+
getStatusState: statusRuntime.getStatusState,
|
|
367
|
+
async persistSnapshot(snapshot) {
|
|
368
|
+
threadStore.setStatusSnapshot(snapshot);
|
|
369
|
+
await threadStore.persist();
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
const updateStatus = runtimeDiagnostics.updateStatus;
|
|
373
|
+
const getStatusLines = runtimeDiagnostics.getStatusLines;
|
|
374
|
+
const inboundHandlerRuntime = Inbound.createTelegramInboundHandlerRuntime({
|
|
375
|
+
getHandlers: configStore.getInboundHandlers,
|
|
376
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
377
|
+
getCwd: Pi.getExtensionContextCwd,
|
|
378
|
+
recordRuntimeEvent,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// --- Telegram API ---
|
|
382
|
+
|
|
383
|
+
const directTelegramApiRuntime =
|
|
384
|
+
TelegramApi.createDefaultTelegramBridgeApiRuntime({
|
|
385
|
+
getBotToken: configStore.getBotToken,
|
|
386
|
+
recordRuntimeEvent,
|
|
387
|
+
});
|
|
388
|
+
const telegramBusFollowerClients =
|
|
389
|
+
BusFollower.createTelegramBusFollowerClientRuntime<
|
|
390
|
+
Pi.ExtensionContext,
|
|
391
|
+
Updates.TelegramMessageReactionUpdated,
|
|
392
|
+
Routing.TelegramRoutedCallbackQuery,
|
|
393
|
+
Routing.TelegramRoutedMessage
|
|
394
|
+
>({
|
|
395
|
+
socketPath: getTelegramBusSocketPath,
|
|
396
|
+
instanceId: telegramInstanceId,
|
|
397
|
+
getApiAuthSecret: telegramBusFollowerControlState.getActiveAuthSecret,
|
|
398
|
+
getForwardingAuthSecret() {
|
|
399
|
+
return telegramBusAuthSecret;
|
|
400
|
+
},
|
|
401
|
+
getRegistrationGeneration:
|
|
402
|
+
telegramBusFollowerRegistrationState.getGeneration,
|
|
403
|
+
getForwardCommentBatchPosition:
|
|
404
|
+
textGroupRuntime.getPreparedForwardingPosition,
|
|
405
|
+
recordRuntimeEvent,
|
|
406
|
+
});
|
|
407
|
+
const telegramApiRuntime = BusApi.createTelegramBusAwareApiRuntime({
|
|
408
|
+
directRuntime: directTelegramApiRuntime,
|
|
409
|
+
ownsDirect() {
|
|
410
|
+
return lockRuntime.owns();
|
|
411
|
+
},
|
|
412
|
+
getDefaultTarget: proactivePushTargetGetter,
|
|
413
|
+
callFollowerApi: telegramBusFollowerClients.callApi,
|
|
414
|
+
});
|
|
415
|
+
const {
|
|
416
|
+
call: callTelegramApi,
|
|
417
|
+
callMultipart,
|
|
418
|
+
deleteWebhook,
|
|
419
|
+
getUpdates,
|
|
420
|
+
setMyCommands,
|
|
421
|
+
sendTypingAction,
|
|
422
|
+
sendChatAction,
|
|
423
|
+
sendRecordVoiceAction,
|
|
424
|
+
sendMessageDraft,
|
|
425
|
+
sendMessage,
|
|
426
|
+
sendRichMessage,
|
|
427
|
+
sendRichMessageDraft,
|
|
428
|
+
downloadFile: downloadTelegramBridgeFile,
|
|
429
|
+
editMessageText: editTelegramMessageText,
|
|
430
|
+
editMessageReplyMarkup: editTelegramMessageReplyMarkup,
|
|
431
|
+
answerCallbackQuery,
|
|
432
|
+
answerGuestQuery,
|
|
433
|
+
deleteMessage: deleteTelegramMessage,
|
|
434
|
+
prepareTempDir,
|
|
435
|
+
} = telegramApiRuntime;
|
|
436
|
+
|
|
437
|
+
// --- Message Delivery ---
|
|
438
|
+
|
|
439
|
+
const sendGuestReply = Replies.createGuestMarkdownReplySender({
|
|
440
|
+
answerGuestQuery,
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
const promptDispatchRuntime = Runtime.createTelegramPromptDispatchRuntime({
|
|
444
|
+
lifecycle,
|
|
445
|
+
typing,
|
|
446
|
+
getDefaultChatId: proactivePushChatIdGetter,
|
|
447
|
+
sendTypingAction,
|
|
448
|
+
sendAggregateTypingAction:
|
|
449
|
+
BusApi.createTelegramAggregateTypingActionSender(telegramApiRuntime),
|
|
450
|
+
updateStatus,
|
|
451
|
+
isContextActive: telegramSessionContextStore.isCurrent,
|
|
452
|
+
recordRuntimeEvent,
|
|
453
|
+
});
|
|
454
|
+
const currentModelRuntime = Model.createCurrentModelRuntime({
|
|
455
|
+
getContextModel,
|
|
456
|
+
updateStatus,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// --- Reply Runtime & Preview ---
|
|
460
|
+
|
|
461
|
+
const replyRuntime = Replies.createTelegramRenderedMessageDeliveryRuntime({
|
|
462
|
+
recordOwnership: messageOwnershipRuntime.recordLocal,
|
|
463
|
+
sendMessage,
|
|
464
|
+
sendRichMessage,
|
|
465
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
466
|
+
editMessage: editTelegramMessageText,
|
|
467
|
+
});
|
|
468
|
+
const { replyTransport, editInteractiveMessage, sendInteractiveMessage } =
|
|
469
|
+
replyRuntime;
|
|
470
|
+
const deliveryTargetPolicyRuntime =
|
|
471
|
+
Delivery.createTelegramDeliveryTargetPolicyRuntime({
|
|
472
|
+
ownsDirect: lockRuntime.owns,
|
|
473
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
474
|
+
getAllowedChatId: configStore.getAllowedUserId,
|
|
475
|
+
getFollowerTarget: telegramBusFollowerRegistrationState.getTarget,
|
|
476
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
477
|
+
listThreadRecords: threadStore.list,
|
|
478
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
479
|
+
getActiveGuestQueryId: activeTurnRuntime.getGuestQueryId,
|
|
480
|
+
});
|
|
481
|
+
const deliveryGenerationSeed =
|
|
482
|
+
Delivery.createTelegramDeliveryGenerationSeed(telegramInstanceId);
|
|
483
|
+
const deliveryLifecycleRuntime =
|
|
484
|
+
Delivery.createTelegramBridgeDeliveryLifecycleHooks({
|
|
485
|
+
generationSeed: deliveryGenerationSeed,
|
|
486
|
+
getTargetPolicyView: deliveryTargetPolicyRuntime.getTargetPolicyView,
|
|
487
|
+
getTransportStamp: telegramTransportStampRuntime.getStamp,
|
|
488
|
+
isTransportStampActive: telegramTransportStampRuntime.isActive,
|
|
489
|
+
getActiveTurnTarget: deliveryTargetPolicyRuntime.getActiveTurnTarget,
|
|
490
|
+
api: telegramApiRuntime,
|
|
491
|
+
recordOwnership: messageOwnershipRuntime.recordLocal,
|
|
492
|
+
recordFailure(operation, error, target) {
|
|
493
|
+
recordRuntimeEvent("delivery", error, {
|
|
494
|
+
operation,
|
|
495
|
+
scope: target?.threadId === undefined ? "aggregate" : "thread",
|
|
496
|
+
});
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
const { sendTextReply, sendMarkdownReply } =
|
|
500
|
+
Outbound.createTelegramOutboundTextReplyRuntime({
|
|
501
|
+
sendTextReply: replyRuntime.sendTextReply,
|
|
502
|
+
sendMarkdownReply: replyRuntime.sendMarkdownReply,
|
|
503
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
504
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
505
|
+
recordRuntimeEvent,
|
|
506
|
+
});
|
|
507
|
+
const invokeGenerativeAppBoundButtonAction =
|
|
508
|
+
Bindings.createTelegramGenerativeAppBoundButtonActionInvoker({
|
|
509
|
+
agentDir: Paths.resolveAgentDir(),
|
|
510
|
+
assertExecutionCurrent: Updates.assertTelegramUpdateExecutionCurrent,
|
|
511
|
+
getExecutionFence: Updates.getTelegramUpdateExecutionFence,
|
|
512
|
+
planOutput: planGenerativeAppOutput,
|
|
513
|
+
sendMarkdownReply,
|
|
514
|
+
editInteractiveMessage,
|
|
515
|
+
recordRuntimeEvent,
|
|
516
|
+
});
|
|
517
|
+
const {
|
|
518
|
+
activityRuntime,
|
|
519
|
+
activityVerbosityRuntime,
|
|
520
|
+
assistantOutputRuntime,
|
|
521
|
+
} = Bindings.createTelegramActivityBindingRuntime({
|
|
522
|
+
generation: deliveryGenerationSeed,
|
|
523
|
+
assistantOutput: {
|
|
524
|
+
isEnabled: configControls.isProactivePushEnabled,
|
|
525
|
+
authority: {
|
|
526
|
+
getPreferredTarget: proactivePushTargetGetter,
|
|
527
|
+
getFallbackChatId: proactivePushChatIdGetter,
|
|
528
|
+
getTransportStamp: telegramTransportStampRuntime.getStamp,
|
|
529
|
+
isTransportStampActive: telegramTransportStampRuntime.isActive,
|
|
530
|
+
ownsDirect: lockRuntime.owns,
|
|
531
|
+
getDirectEpoch: lockRuntime.getOwnedLeaderEpoch,
|
|
532
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
533
|
+
getFollowerGeneration:
|
|
534
|
+
telegramBusFollowerRegistrationState.getGeneration,
|
|
535
|
+
},
|
|
536
|
+
sender: {
|
|
537
|
+
recordOwnership: messageOwnershipRuntime.recordLocal,
|
|
538
|
+
sendMessage,
|
|
539
|
+
sendRichMessage,
|
|
540
|
+
editMessage: editTelegramMessageText,
|
|
541
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
542
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
543
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
544
|
+
recordRuntimeEvent,
|
|
545
|
+
},
|
|
546
|
+
recordRuntimeEvent,
|
|
547
|
+
},
|
|
548
|
+
activityVerbosity: {
|
|
549
|
+
getActivityMode: configControls.getActivityVerbosity,
|
|
550
|
+
refreshActivityMode: configControls.refreshActivityVerbosity,
|
|
551
|
+
resolveTarget(event) {
|
|
552
|
+
return event.target ?? proactivePushTargetGetter();
|
|
553
|
+
},
|
|
554
|
+
sendMessage,
|
|
555
|
+
sendRichMessage,
|
|
556
|
+
editMessageText: editTelegramMessageText,
|
|
557
|
+
},
|
|
558
|
+
});
|
|
559
|
+
const {
|
|
560
|
+
mutation: queueMutationRuntime,
|
|
561
|
+
dispatchNext: dispatchNextQueuedTelegramTurn,
|
|
562
|
+
watchdog: queueDispatchWatchdogRuntime,
|
|
563
|
+
} = Bindings.createTelegramQueueBindingRuntime({
|
|
564
|
+
store: telegramQueueStore,
|
|
565
|
+
queue,
|
|
566
|
+
lifecycle,
|
|
567
|
+
activeTurn: activeTurnRuntime,
|
|
568
|
+
admission: updateAdmissionRuntimeBinding,
|
|
569
|
+
transportStamp: telegramTransportStampRuntime,
|
|
570
|
+
deferredDispatch: deferredQueueDispatchRuntime,
|
|
571
|
+
promptDispatch: promptDispatchRuntime,
|
|
572
|
+
isIdle,
|
|
573
|
+
hasPendingMessages,
|
|
574
|
+
updateStatus,
|
|
575
|
+
sendTextReply,
|
|
576
|
+
sendUserMessage,
|
|
577
|
+
recordRuntimeEvent,
|
|
578
|
+
});
|
|
579
|
+
const nativeMarkdownDraftSender =
|
|
580
|
+
TelegramApi.createTelegramAssistantDraftSender({
|
|
581
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
582
|
+
renderMarkdownToHtmlDraft: Replies.renderTelegramMarkdownToHtmlDraft,
|
|
583
|
+
sendMessageDraft,
|
|
584
|
+
sendRichMessageDraft,
|
|
585
|
+
});
|
|
586
|
+
const previewRuntime = Preview.createTelegramAssistantPreviewRuntime({
|
|
587
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
588
|
+
isAssistantMessage: Replies.isAssistantAgentMessage,
|
|
589
|
+
getMessageText: Replies.getAgentMessageText,
|
|
590
|
+
getDefaultReplyToMessageId: activeTurnRuntime.getReplyToMessageId,
|
|
591
|
+
sendDraft: nativeMarkdownDraftSender,
|
|
592
|
+
canSend: configControls.areDraftPreviewsEnabled,
|
|
593
|
+
sendMarkdownReply,
|
|
594
|
+
recordRuntimeEvent,
|
|
595
|
+
...replyTransport,
|
|
596
|
+
});
|
|
597
|
+
const { finalizeMarkdownPreview } =
|
|
598
|
+
Outbound.createTelegramOutboundTextPreviewRuntime({
|
|
599
|
+
finalizeMarkdownPreview: previewRuntime.finalizeMarkdown,
|
|
600
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
601
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
602
|
+
recordRuntimeEvent,
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
// --- Model And Menu Setup ---
|
|
606
|
+
|
|
607
|
+
const modelSwitchController =
|
|
608
|
+
Model.createTelegramModelSwitchControllerRuntime({
|
|
609
|
+
isIdle,
|
|
610
|
+
getPendingModelSwitch: pendingModelSwitchStore.get,
|
|
611
|
+
setPendingModelSwitch: pendingModelSwitchStore.set,
|
|
612
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
613
|
+
getAbortHandler: abort.getHandler,
|
|
614
|
+
hasAbortHandler: abort.hasHandler,
|
|
615
|
+
getActiveToolExecutions: lifecycle.getActiveToolExecutions,
|
|
616
|
+
allocateItemOrder: queue.allocateItemOrder,
|
|
617
|
+
allocateControlOrder: queue.allocateControlOrder,
|
|
618
|
+
appendQueuedItem: queueMutationRuntime.append,
|
|
619
|
+
updateStatus,
|
|
620
|
+
});
|
|
621
|
+
const getQueueItemCount =
|
|
622
|
+
Queue.createTelegramQueueItemCountGetter(telegramQueueStore);
|
|
623
|
+
const getPromptTemplateCommands =
|
|
624
|
+
PromptTemplates.createTelegramPromptTemplateCommandGetter({
|
|
625
|
+
getCommands,
|
|
626
|
+
getReservedCommandNames: Commands.getTelegramReservedCommandNames,
|
|
627
|
+
});
|
|
628
|
+
const menuActions = Menu.createTelegramMenuActionRuntimeWithStateBuilder({
|
|
629
|
+
runtime: modelMenuRuntime,
|
|
630
|
+
createSettingsManager: Pi.createSettingsManager,
|
|
631
|
+
getActiveModel: currentModelRuntime.get,
|
|
632
|
+
getThinkingLevel,
|
|
633
|
+
getQueueItemCount,
|
|
634
|
+
buildStatusHtml: Commands.createTelegramAppMenuHtmlBuilder({
|
|
635
|
+
buildStatusHtml: Status.createTelegramStatusHtmlBuilder({
|
|
636
|
+
getActiveModel: currentModelRuntime.get,
|
|
637
|
+
isCompactionInProgress: lifecycle.isCompactionInProgress,
|
|
638
|
+
getBridgeStatusLineState: statusRuntime.getStatusState,
|
|
639
|
+
}),
|
|
640
|
+
getPromptTemplateCommands,
|
|
641
|
+
}),
|
|
642
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
643
|
+
isIdle,
|
|
644
|
+
canOfferInFlightModelSwitch: modelSwitchController.canOfferInFlightSwitch,
|
|
645
|
+
sendTextReply,
|
|
646
|
+
editInteractiveMessage,
|
|
647
|
+
sendInteractiveMessage,
|
|
648
|
+
sectionRegistry,
|
|
649
|
+
|
|
650
|
+
// Menu/status UI uses this to reflect whether the active Telegram turn expects voice delivery.
|
|
651
|
+
isVoiceReplyActive: function () {
|
|
652
|
+
const turn = activeTurnRuntime.get();
|
|
653
|
+
return Voice.isVoiceTurn(turn);
|
|
654
|
+
},
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
// --- Queue And Settings Menus ---
|
|
658
|
+
|
|
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
|
+
{
|
|
678
|
+
reloadConfig: configStore.load,
|
|
679
|
+
getModelMenuState: getQueueMenuState,
|
|
680
|
+
getStoredModelMenuState: modelMenuRuntime.getState,
|
|
681
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
682
|
+
editInteractiveMessage,
|
|
683
|
+
sendInteractiveMessage,
|
|
684
|
+
answerCallbackQuery,
|
|
685
|
+
...configControls,
|
|
686
|
+
},
|
|
687
|
+
sectionRegistry,
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
// --- Polling ---
|
|
691
|
+
|
|
692
|
+
const foreignOwnedUpdateForwarder =
|
|
693
|
+
telegramBusFollowerClients.foreignOwnedUpdateForwarder;
|
|
694
|
+
const followerTargetController = telegramBusFollowerClients.targetController;
|
|
695
|
+
const restoreFollowerThreadTarget =
|
|
696
|
+
Bus.createTelegramBusFollowerThreadRestoreHandler({
|
|
697
|
+
followerRegistry: telegramBusFollowerRegistry,
|
|
698
|
+
followerTargetController,
|
|
699
|
+
onRestored() {
|
|
700
|
+
telegramSyncStateRuntime.markSliceFresh(
|
|
701
|
+
Sync.TELEGRAM_SYNC_SLICE_TARGET_BINDINGS,
|
|
702
|
+
{
|
|
703
|
+
nowMs: Date.now(),
|
|
704
|
+
action: "follower-thread-restore",
|
|
705
|
+
},
|
|
706
|
+
);
|
|
707
|
+
},
|
|
708
|
+
});
|
|
709
|
+
const observedThreadTargetBinding =
|
|
710
|
+
Polling.createTelegramThreadTargetObservationBinding<Pi.ExtensionContext>();
|
|
711
|
+
const topicLifecycleSync =
|
|
712
|
+
Sync.createTelegramObservedTopicLifecycleSyncHandler({
|
|
713
|
+
topicTargetStore: threadStore,
|
|
714
|
+
isBusEnabled: isTelegramBusRuntimeEnabled,
|
|
715
|
+
callApi: callTelegramApi,
|
|
716
|
+
isTopicProvisioningActive: telegramProvisioningActivity.isActive,
|
|
717
|
+
getCurrentLeaderEpoch,
|
|
718
|
+
getThreadReconciliationMachineState: threadReconciliationRuntime.getState,
|
|
719
|
+
recordThreadReconciliationPlan,
|
|
720
|
+
assertExecutionCurrent(message) {
|
|
721
|
+
Updates.assertTelegramUpdateExecutionCurrent(message);
|
|
722
|
+
},
|
|
723
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
724
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
725
|
+
recordEvent: recordRuntimeEvent,
|
|
726
|
+
});
|
|
727
|
+
const inboundBusProjectionRuntime =
|
|
728
|
+
Routing.createTelegramInboundBusProjectionRuntime({
|
|
729
|
+
instanceId: telegramInstanceId,
|
|
730
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
731
|
+
listThreadRecords: threadStore.list,
|
|
732
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
733
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
734
|
+
getFollowerTarget: telegramBusFollowerRegistrationState.getTarget,
|
|
735
|
+
getCurrentIdentity: getCurrentInstanceThreadIdentity,
|
|
736
|
+
});
|
|
737
|
+
const inboundRouteRuntime = Routing.createTelegramInboundRouteRuntime({
|
|
738
|
+
configStore,
|
|
739
|
+
callApi: callTelegramApi,
|
|
740
|
+
getCurrentInstanceId() {
|
|
741
|
+
return telegramInstanceId;
|
|
742
|
+
},
|
|
743
|
+
getAdmissionScope: getTelegramUpdateAdmissionScope,
|
|
744
|
+
getAdmissionJournalBinding: getTelegramQueueJournalBinding,
|
|
745
|
+
getMessageOwnership: messageOwnershipRuntime.store.get,
|
|
746
|
+
recordMessageOwnership: messageOwnershipRuntime.recordRouted,
|
|
747
|
+
...inboundBusProjectionRuntime,
|
|
748
|
+
getCurrentLeaderEpoch,
|
|
749
|
+
setCurrentLeaderIdentity: telegramBusLeaderState.set,
|
|
750
|
+
getThreadReconciliationMachineState: threadReconciliationRuntime.getState,
|
|
751
|
+
recordThreadReconciliationPlan,
|
|
752
|
+
handleTelegramTopicLifecycleUpdate: topicLifecycleSync,
|
|
753
|
+
handleTelegramThreadTargetObserved(_target, ctx) {
|
|
754
|
+
return observedThreadTargetBinding.handle(ctx);
|
|
755
|
+
},
|
|
756
|
+
foreignOwnedUpdateForwarder,
|
|
757
|
+
replaceFollowerThreadTarget: restoreFollowerThreadTarget,
|
|
758
|
+
bridgeRuntime,
|
|
759
|
+
activeTurnRuntime,
|
|
760
|
+
mediaGroupRuntime,
|
|
761
|
+
textGroupRuntime,
|
|
762
|
+
telegramQueueStore,
|
|
763
|
+
queueMutationRuntime,
|
|
764
|
+
modelMenuRuntime,
|
|
765
|
+
currentModelRuntime,
|
|
766
|
+
modelSwitchController,
|
|
767
|
+
menuActions,
|
|
768
|
+
updateSettingsMenuMessage: settingsMenuRuntime.updateSettingsMenuMessage,
|
|
769
|
+
openQueueMenu: queueMenuRuntime.openQueueMenu,
|
|
770
|
+
queueMenuCallbackHandler: queueMenuRuntime.handleCallbackQuery,
|
|
771
|
+
openSettingsMenu: settingsMenuRuntime.openSettingsMenu,
|
|
772
|
+
settingsMenuCallbackHandler: settingsMenuRuntime.handleCallbackQuery,
|
|
773
|
+
sectionRegistry,
|
|
774
|
+
buttonActionStore,
|
|
775
|
+
invokeBoundButtonAction: invokeGenerativeAppBoundButtonAction,
|
|
776
|
+
inboundHandlerRuntime,
|
|
777
|
+
threadStore,
|
|
778
|
+
updateStatus,
|
|
779
|
+
isContextActive: telegramSessionContextStore.isCurrent,
|
|
780
|
+
dispatchNextQueuedTelegramTurn,
|
|
781
|
+
requestDeferredDispatchNextQueuedTelegramTurn:
|
|
782
|
+
deferredQueueDispatchRuntime.request,
|
|
783
|
+
hasDeferredDispatchContext: deferredQueueDispatchRuntime.isBound,
|
|
784
|
+
startTypingLoop: promptDispatchRuntime.startTypingLoop,
|
|
785
|
+
stopTypingLoop: typing.stop,
|
|
786
|
+
answerCallbackQuery,
|
|
787
|
+
editInteractiveMessage,
|
|
788
|
+
editMessageReplyMarkup: editTelegramMessageReplyMarkup,
|
|
789
|
+
sendInteractiveMessage,
|
|
790
|
+
deleteMessage: deleteTelegramMessage,
|
|
791
|
+
answerGuestQuery,
|
|
792
|
+
sendTextReply,
|
|
793
|
+
setMyCommands,
|
|
794
|
+
getCommands,
|
|
795
|
+
downloadFile: downloadTelegramBridgeFile,
|
|
796
|
+
resolveTimeLine: timeInjectionRuntime.resolveLine,
|
|
797
|
+
getThinkingLevel,
|
|
798
|
+
setThinkingLevel,
|
|
799
|
+
persistScopedModelPatterns: Pi.createScopedModelPatternPersister({
|
|
800
|
+
createSettingsManager: Pi.createSettingsManager,
|
|
801
|
+
clearCachedModelMenuInputs: modelMenuRuntime.clearCachedInputs,
|
|
802
|
+
}),
|
|
803
|
+
setModel,
|
|
804
|
+
sendUserMessage,
|
|
805
|
+
isIdle,
|
|
806
|
+
hasPendingMessages,
|
|
807
|
+
compact,
|
|
808
|
+
recordRuntimeEvent,
|
|
809
|
+
});
|
|
810
|
+
const queueHandoffReconciliationBinding =
|
|
811
|
+
Updates.createTelegramQueueHandoffReconciliationBinding<Pi.ExtensionContext>(
|
|
812
|
+
function (error) {
|
|
813
|
+
recordRuntimeEvent("inbound-worker", error, {
|
|
814
|
+
phase: "queue-handoff-reconcile",
|
|
815
|
+
});
|
|
816
|
+
},
|
|
817
|
+
);
|
|
818
|
+
const {
|
|
819
|
+
owner: updateWorkerOwnerRuntime,
|
|
820
|
+
leader: updateAdmissionLifecycleRuntime,
|
|
821
|
+
follower: followerAdmissionLifecycleRuntime,
|
|
822
|
+
} = Updates.createTelegramUpdateAdmissionRuntimeAssembly<
|
|
823
|
+
Parameters<typeof inboundRouteRuntime.handleUpdate>[0] &
|
|
824
|
+
Journal.TelegramJournaledUpdate,
|
|
825
|
+
Pi.ExtensionContext
|
|
826
|
+
>({
|
|
827
|
+
runtimeBinding: updateAdmissionRuntimeBinding,
|
|
828
|
+
owner: {
|
|
829
|
+
instanceId: telegramInstanceId,
|
|
830
|
+
processId: telegramProcessId,
|
|
831
|
+
processBirthId: telegramQueueProcessBirthId,
|
|
832
|
+
getSessionGeneration: telegramSessionContextStore.getGeneration,
|
|
833
|
+
isContextCurrent: telegramSessionContextStore.isCurrent,
|
|
834
|
+
dispatchNext: dispatchNextQueuedTelegramTurn,
|
|
835
|
+
requestQueueHandoffReconciliation:
|
|
836
|
+
queueHandoffReconciliationBinding.request,
|
|
837
|
+
},
|
|
838
|
+
worker: {
|
|
839
|
+
defaultHandle: inboundRouteRuntime.handleUpdate,
|
|
840
|
+
onStateChange: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
841
|
+
},
|
|
842
|
+
leader: {
|
|
843
|
+
resolveBinding: resolveTelegramUpdateJournalBinding,
|
|
844
|
+
hasAuthority: lockRuntime.owns,
|
|
845
|
+
},
|
|
846
|
+
follower: {
|
|
847
|
+
resolveBinding: resolveTelegramFollowerJournalBinding,
|
|
848
|
+
isRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
849
|
+
getGeneration: telegramBusFollowerRegistrationState.getGeneration,
|
|
850
|
+
prepareUpdateForExecution(update) {
|
|
851
|
+
return BusFollower.prepareTelegramBusFollowerJournaledUpdateForExecution(
|
|
852
|
+
update,
|
|
853
|
+
textGroupRuntime.prepareForwardedMessage,
|
|
854
|
+
);
|
|
855
|
+
},
|
|
856
|
+
},
|
|
857
|
+
recordRuntimeEvent,
|
|
858
|
+
});
|
|
859
|
+
const queueHandoffStagingRuntime =
|
|
860
|
+
Queue.createTelegramQueueHandoffStagingRuntime({
|
|
861
|
+
liveStore: telegramQueueStore,
|
|
862
|
+
createControlExecution:
|
|
863
|
+
Updates.createTelegramQueueHandoffControlExecutionFactory({
|
|
864
|
+
isContextCurrent: telegramSessionContextStore.isCurrent,
|
|
865
|
+
showStatus: menuActions.sendStatusMessage,
|
|
866
|
+
openModelMenu: menuActions.openModelMenu,
|
|
867
|
+
}),
|
|
868
|
+
});
|
|
869
|
+
const acceptStagedQueueHandoff =
|
|
870
|
+
Updates.createTelegramQueueHandoffRecipientRuntime({
|
|
871
|
+
staging: queueHandoffStagingRuntime,
|
|
872
|
+
getRecipientOwner: updateWorkerOwnerRuntime.getQueueOwnerIdentity,
|
|
873
|
+
getLifecycleForBinding:
|
|
874
|
+
updateAdmissionRuntimeBinding.getLifecycleForJournalBinding,
|
|
875
|
+
isTransportStampActive: telegramTransportStampRuntime.isActive,
|
|
876
|
+
dispatchNext: dispatchNextQueuedTelegramTurn,
|
|
877
|
+
});
|
|
878
|
+
const followerDurableAdmissionRuntime =
|
|
879
|
+
BusFollower.createTelegramBusFollowerDurableAdmissionRuntime({
|
|
880
|
+
journal: {
|
|
881
|
+
appendBatch(updates) {
|
|
882
|
+
return followerAdmissionLifecycleRuntime.appendBatch(updates);
|
|
883
|
+
},
|
|
884
|
+
},
|
|
885
|
+
signalWorker() {
|
|
886
|
+
followerAdmissionLifecycleRuntime.signal();
|
|
887
|
+
},
|
|
888
|
+
});
|
|
889
|
+
const promoteTelegramBusFollowerToLeader: BusFollower.TelegramBusFollowerPromotionHandler<Pi.ExtensionContext> =
|
|
890
|
+
BusFollower.createTelegramBusFollowerPromotionHandler<Pi.ExtensionContext>({
|
|
891
|
+
topicTargetStore: threadStore,
|
|
892
|
+
instanceId: telegramInstanceId,
|
|
893
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
894
|
+
async startLeader(ctx, election, onAcquired): Promise<boolean> {
|
|
895
|
+
const result = await lockedPollingRuntime.start(ctx, {
|
|
896
|
+
election,
|
|
897
|
+
onAcquired,
|
|
898
|
+
});
|
|
899
|
+
return result.ok;
|
|
900
|
+
},
|
|
901
|
+
recordRuntimeEvent,
|
|
902
|
+
});
|
|
903
|
+
const agentMessageRuntime = AgentMessages.createTelegramAgentMessageRuntime({
|
|
904
|
+
instanceId: telegramInstanceId,
|
|
905
|
+
getAllowedChatId: configStore.getAllowedUserId,
|
|
906
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
907
|
+
getLeaderThreadName() {
|
|
908
|
+
return findCurrentThreadRecord()?.threadName;
|
|
909
|
+
},
|
|
910
|
+
followerRegistry: telegramBusFollowerRegistry,
|
|
911
|
+
getContext: telegramSessionContextStore.get,
|
|
912
|
+
handleUpdate: inboundRouteRuntime.handleUpdate,
|
|
913
|
+
});
|
|
914
|
+
const agentMessageToolRoutingRuntime =
|
|
915
|
+
Bindings.createTelegramAgentMessageToolRoutingRuntime({
|
|
916
|
+
ownsLeader: lockRuntime.owns,
|
|
917
|
+
ownsDirectDelivery: ownsTelegramDirectDelivery,
|
|
918
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
919
|
+
getSourceTarget: proactivePushTargetGetter,
|
|
920
|
+
getSourceThreadName() {
|
|
921
|
+
return findCurrentThreadRecord()?.threadName;
|
|
922
|
+
},
|
|
923
|
+
local: agentMessageRuntime,
|
|
924
|
+
follower: telegramBusFollowerClients.agentMessages,
|
|
925
|
+
});
|
|
926
|
+
const telegramBusFollowerAssembly: BusFollower.TelegramBusFollowerRuntimeAssembly<Pi.ExtensionContext> =
|
|
927
|
+
BusFollower.createTelegramBusFollowerRuntimeAssembly<Pi.ExtensionContext>({
|
|
928
|
+
instanceId: telegramInstanceId,
|
|
929
|
+
registrationState: telegramBusFollowerRegistrationState,
|
|
930
|
+
recordRuntimeEvent,
|
|
931
|
+
receiver: {
|
|
932
|
+
socketPath: getTelegramBusFollowerSocketPath,
|
|
933
|
+
getContext: telegramSessionContextStore.get,
|
|
934
|
+
getAuthSecret: telegramBusFollowerControlState.getActiveAuthSecret,
|
|
935
|
+
getRecipientBindingKey: getTelegramManualFollowerProfileKey,
|
|
936
|
+
durableAdmission: followerDurableAdmissionRuntime,
|
|
937
|
+
handleQueueHandoff: acceptStagedQueueHandoff,
|
|
938
|
+
},
|
|
939
|
+
targetReplacement: {
|
|
940
|
+
topicTargetStore: threadStore,
|
|
941
|
+
getManualFollowerProfileKey: getTelegramManualFollowerProfileKey,
|
|
942
|
+
manualFollowerOwnerId: telegramManualFollowerOwnerId,
|
|
943
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
944
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
945
|
+
updateStatus,
|
|
946
|
+
},
|
|
947
|
+
recovery: {
|
|
948
|
+
getLeaderState: lockRuntime.getState,
|
|
949
|
+
setLifecyclePhase: telegramBusFollowerControlState.setLifecyclePhase,
|
|
950
|
+
updateStatus,
|
|
951
|
+
promoteToLeader: promoteTelegramBusFollowerToLeader,
|
|
952
|
+
getActiveContext: telegramSessionContextStore.get,
|
|
953
|
+
},
|
|
954
|
+
registration: {
|
|
955
|
+
protocolIdentity: telegramBusProtocolIdentity,
|
|
956
|
+
getFollowerBusSocketPath: getTelegramBusFollowerSocketPath,
|
|
957
|
+
getLeaderSocketPath: getTelegramBusSocketPath,
|
|
958
|
+
isContextActive: telegramSessionContextStore.isCurrent,
|
|
959
|
+
createRequestId: telegramBusFollowerClients.createRequestId,
|
|
960
|
+
setActiveAuthSecret:
|
|
961
|
+
telegramBusFollowerControlState.setActiveAuthSecret,
|
|
962
|
+
getProfileKey: getTelegramManualFollowerProfileKey,
|
|
963
|
+
getProcessBirthId() {
|
|
964
|
+
return telegramQueueProcessBirthId;
|
|
965
|
+
},
|
|
966
|
+
getSessionGeneration: telegramSessionContextStore.getGeneration,
|
|
967
|
+
async onRegistered(ctx) {
|
|
968
|
+
await followerAdmissionLifecycleRuntime.onTransportChanged(ctx);
|
|
969
|
+
queueHandoffReconciliationBinding.request(ctx);
|
|
970
|
+
},
|
|
971
|
+
},
|
|
972
|
+
});
|
|
973
|
+
const telegramBusFollowerRegistration =
|
|
974
|
+
telegramBusFollowerAssembly.registration;
|
|
975
|
+
const { admission: pollingAdmissionRuntime } =
|
|
976
|
+
Polling.createTelegramDurablePollingRuntimeAssembly<
|
|
977
|
+
TelegramApi.TelegramUpdate,
|
|
978
|
+
Pi.ExtensionContext
|
|
979
|
+
>({
|
|
980
|
+
state: pollingControllerState,
|
|
981
|
+
getConfig: configStore.get,
|
|
982
|
+
hasBotToken: configStore.hasBotToken,
|
|
983
|
+
deleteWebhook,
|
|
984
|
+
getUpdates,
|
|
985
|
+
persistConfig: persistTelegramPollingOffset,
|
|
986
|
+
prepareUpdateBatch: textGroupRuntime.prepareUpdateBatch,
|
|
987
|
+
journal: {
|
|
988
|
+
appendBatch(updates) {
|
|
989
|
+
return updateAdmissionLifecycleRuntime.appendBatch(
|
|
990
|
+
updates as Journal.TelegramJournaledUpdate[],
|
|
991
|
+
);
|
|
992
|
+
},
|
|
993
|
+
getEntryCount: updateAdmissionLifecycleRuntime.getJournalEntryCount,
|
|
994
|
+
signalWorker: updateAdmissionLifecycleRuntime.signal,
|
|
995
|
+
getBootstrapEntryCount() {
|
|
996
|
+
return (
|
|
997
|
+
resolveTelegramUpdateJournalBinding()?.journal.read().entries
|
|
998
|
+
.length ?? 0
|
|
999
|
+
);
|
|
1000
|
+
},
|
|
1001
|
+
onSessionStart: updateAdmissionLifecycleRuntime.onSessionStart,
|
|
1002
|
+
},
|
|
1003
|
+
stopTypingLoop: typing.stop,
|
|
1004
|
+
updateStatus,
|
|
1005
|
+
onPollingStateChange: runtimeDiagnostics.scheduleSnapshotPersist,
|
|
1006
|
+
recordRuntimeEvent,
|
|
1007
|
+
});
|
|
1008
|
+
const recoverStaleTelegramTopicApiError =
|
|
1009
|
+
Sync.createTelegramStaleTopicApiErrorRecoveryRuntime({
|
|
1010
|
+
topicTargetStore: threadStore,
|
|
1011
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1012
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1013
|
+
recordEvent: recordRuntimeEvent,
|
|
1014
|
+
});
|
|
1015
|
+
const authorizeFollowerApiCall = Bus.createTelegramFollowerApiCallAuthorizer({
|
|
1016
|
+
isMessageOwned: messageOwnershipRuntime.isOwnedByFollower,
|
|
1017
|
+
});
|
|
1018
|
+
const telegramBusLeaderRuntime =
|
|
1019
|
+
BusLeader.createTelegramBusLeaderRuntimeAssembly<Pi.ExtensionContext>({
|
|
1020
|
+
runtime: {
|
|
1021
|
+
socketPath: getTelegramBusSocketPath,
|
|
1022
|
+
commitEndpointPublication(commit) {
|
|
1023
|
+
return lockRuntime.commitIfOwned(commit);
|
|
1024
|
+
},
|
|
1025
|
+
followerRegistry: telegramBusFollowerRegistry,
|
|
1026
|
+
authSecret: telegramBusAuthSecret,
|
|
1027
|
+
protocolIdentity: telegramBusProtocolIdentity,
|
|
1028
|
+
startPolling: pollingAdmissionRuntime.start,
|
|
1029
|
+
stopPolling: pollingAdmissionRuntime.stop,
|
|
1030
|
+
authorizeFollowerApiCall,
|
|
1031
|
+
resolveAgentTarget(follower, selector) {
|
|
1032
|
+
return agentMessageRuntime.resolveTarget(selector, follower.target);
|
|
1033
|
+
},
|
|
1034
|
+
routeAgentMessage(follower, message) {
|
|
1035
|
+
return agentMessageRuntime.route({
|
|
1036
|
+
sourceTarget: follower.target,
|
|
1037
|
+
sourceThreadName: follower.threadName,
|
|
1038
|
+
message,
|
|
1039
|
+
});
|
|
1040
|
+
},
|
|
1041
|
+
isFollowerProcessAlive: Locks.isProcessAlive,
|
|
1042
|
+
shouldCleanupConfirmedDeadFollower:
|
|
1043
|
+
configControls.resolveAutomaticThreadCleanupEnabled,
|
|
1044
|
+
recordFollowerMessageOwnership(record) {
|
|
1045
|
+
messageOwnershipRuntime.recordFollower(record);
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
getAllowedUserId: configStore.getAllowedUserId,
|
|
1049
|
+
instanceId: telegramInstanceId,
|
|
1050
|
+
getCwd: Pi.getExtensionContextCwd,
|
|
1051
|
+
getTelegramProfile: configStore.getActiveProfileName,
|
|
1052
|
+
shouldForceFreshUnnamed:
|
|
1053
|
+
telegramThreadCapabilityState.shouldForceFreshLeaderThread,
|
|
1054
|
+
topicTargetStore: threadStore,
|
|
1055
|
+
callApi(method, body) {
|
|
1056
|
+
return directTelegramApiRuntime.call(method, body);
|
|
1057
|
+
},
|
|
1058
|
+
callMultipart: directTelegramApiRuntime.callMultipart,
|
|
1059
|
+
downloadFile: directTelegramApiRuntime.downloadFile,
|
|
1060
|
+
recoverStaleTargetError: recoverStaleTelegramTopicApiError,
|
|
1061
|
+
getCurrentLeaderEpoch,
|
|
1062
|
+
getThreadReconciliationMachineState: threadReconciliationRuntime.getState,
|
|
1063
|
+
recordThreadReconciliationPlan,
|
|
1064
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1065
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1066
|
+
setLeaderTarget: telegramBusLeaderState.set,
|
|
1067
|
+
onProvisioningStart: telegramProvisioningActivity.start,
|
|
1068
|
+
onProvisioningEnd: telegramProvisioningActivity.end,
|
|
1069
|
+
recordRuntimeEvent,
|
|
1070
|
+
});
|
|
1071
|
+
queueHandoffReconciliationBinding.set(
|
|
1072
|
+
Updates.createTelegramQueueHandoffReconciliationRuntimeAssembly({
|
|
1073
|
+
ownsDirect: lockRuntime.owns,
|
|
1074
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
1075
|
+
isBusEnabled: isTelegramBusRuntimeEnabled,
|
|
1076
|
+
canHandoffWithLeader() {
|
|
1077
|
+
return Bus.hasTelegramBusCapability(
|
|
1078
|
+
telegramBusFollowerRegistrationState.getLeaderProtocol(),
|
|
1079
|
+
Bus.TELEGRAM_BUS_CAPABILITY_QUEUE_HANDOFF,
|
|
1080
|
+
);
|
|
1081
|
+
},
|
|
1082
|
+
listFollowers: telegramBusFollowerRegistry.list,
|
|
1083
|
+
createRecipientJournalResolver:
|
|
1084
|
+
telegramJournalBindingRuntime.createRecipientResolver,
|
|
1085
|
+
queueStore: telegramQueueStore,
|
|
1086
|
+
admission: updateAdmissionRuntimeBinding,
|
|
1087
|
+
createHandoffToken: Journal.createTelegramUpdateQueueHandoffToken,
|
|
1088
|
+
createRequestId: telegramBusFollowerClients.createRequestId,
|
|
1089
|
+
donorInstanceId: telegramInstanceId,
|
|
1090
|
+
authSecret: telegramBusAuthSecret,
|
|
1091
|
+
stageThroughFollower: telegramBusFollowerClients.queueHandoff,
|
|
1092
|
+
routeThroughLeader: telegramBusLeaderRuntime.routeQueueHandoff,
|
|
1093
|
+
recordRuntimeEvent,
|
|
1094
|
+
}),
|
|
1095
|
+
);
|
|
1096
|
+
const telegramLeaderHealthRuntime = Sync.createTelegramLeaderHealthRuntime({
|
|
1097
|
+
callGetMe() {
|
|
1098
|
+
return directTelegramApiRuntime.call("getMe", {});
|
|
1099
|
+
},
|
|
1100
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1101
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1102
|
+
recordEvent: recordRuntimeEvent,
|
|
1103
|
+
});
|
|
1104
|
+
const telegramThreadCapabilityRuntime =
|
|
1105
|
+
Polling.createTelegramThreadCapabilityOrchestration<
|
|
1106
|
+
Pi.ExtensionContext,
|
|
1107
|
+
Locks.TelegramLockEntry
|
|
1108
|
+
>({
|
|
1109
|
+
state: telegramThreadCapabilityState,
|
|
1110
|
+
getAllowedUserId: configStore.getAllowedUserId,
|
|
1111
|
+
callApi: callTelegramApi,
|
|
1112
|
+
topicTargetStore: threadStore,
|
|
1113
|
+
isBusRuntimeEnabled: isTelegramBusRuntimeEnabled,
|
|
1114
|
+
ownsLock: lockRuntime.owns,
|
|
1115
|
+
isFollowerRegistered: telegramBusFollowerRegistrationState.isRegistered,
|
|
1116
|
+
startClassicPolling: pollingAdmissionRuntime.start,
|
|
1117
|
+
stopClassicPolling: pollingAdmissionRuntime.stop,
|
|
1118
|
+
startBusLeaderPolling: telegramBusLeaderRuntime.startPolling,
|
|
1119
|
+
stopBusLeaderPolling: telegramBusLeaderRuntime.stopPolling,
|
|
1120
|
+
startLeaderHealth: telegramLeaderHealthRuntime.start,
|
|
1121
|
+
stopLeaderHealth: telegramLeaderHealthRuntime.stop,
|
|
1122
|
+
registerFollowerWithLeader:
|
|
1123
|
+
telegramBusFollowerRegistration.registerWithLeader,
|
|
1124
|
+
stopFollowerRegistration: telegramBusFollowerRegistration.stop,
|
|
1125
|
+
isTopicModeUnavailableError: Threads.isTelegramTopicModeUnavailableError,
|
|
1126
|
+
updateStatus,
|
|
1127
|
+
recordEvent: recordRuntimeEvent,
|
|
1128
|
+
});
|
|
1129
|
+
const telegramThreadCapabilityMonitor =
|
|
1130
|
+
telegramThreadCapabilityRuntime.monitor;
|
|
1131
|
+
observedThreadTargetBinding.set(
|
|
1132
|
+
telegramThreadCapabilityRuntime.observeTarget,
|
|
1133
|
+
);
|
|
1134
|
+
const threadAwarePollingPorts = telegramThreadCapabilityRuntime.pollingPorts;
|
|
1135
|
+
const lockedPollingRuntime = Locks.createTelegramLockedPollingRuntime({
|
|
1136
|
+
lock: lockRuntime,
|
|
1137
|
+
hasBotToken: configStore.hasBotToken,
|
|
1138
|
+
canStartPolling: Pi.canStartPollingInExtensionContext,
|
|
1139
|
+
formatStartBlockedMessage: Pi.formatPollingStartBlockedByRunMode,
|
|
1140
|
+
startPolling: threadAwarePollingPorts.startPolling,
|
|
1141
|
+
stopPolling: threadAwarePollingPorts.stopPolling,
|
|
1142
|
+
registerFollowerWithOwner:
|
|
1143
|
+
threadAwarePollingPorts.registerFollowerWithOwner,
|
|
1144
|
+
stopFollowerRegistration: threadAwarePollingPorts.stopFollowerRegistration,
|
|
1145
|
+
onTransportAvailabilityChanged() {
|
|
1146
|
+
modelContextAvailabilityRuntime.reconcile();
|
|
1147
|
+
const ctx = telegramSessionContextStore.get();
|
|
1148
|
+
if (ctx) queueHandoffReconciliationBinding.request(ctx);
|
|
1149
|
+
},
|
|
1150
|
+
updateStatus,
|
|
1151
|
+
recordRuntimeEvent,
|
|
1152
|
+
});
|
|
1153
|
+
const {
|
|
1154
|
+
disconnect: disconnectTelegramAndDeleteCurrentThread,
|
|
1155
|
+
cleanupForSessionRestart: cleanupTelegramThreadForSessionRestart,
|
|
1156
|
+
} = Sync.createTelegramThreadDisconnectAssembly({
|
|
1157
|
+
instanceId: telegramInstanceId,
|
|
1158
|
+
getCurrentThreadRecord: findCurrentThreadRecord,
|
|
1159
|
+
topicTargetStore: threadStore,
|
|
1160
|
+
callApi: callTelegramApi,
|
|
1161
|
+
getCurrentLeaderEpoch,
|
|
1162
|
+
getLeaderTarget: telegramBusLeaderState.getTarget,
|
|
1163
|
+
clearLeaderTarget: telegramBusLeaderState.clear,
|
|
1164
|
+
disconnectFollowerThread:
|
|
1165
|
+
telegramBusFollowerRegistration.disconnectFromLeader,
|
|
1166
|
+
getSyncState: telegramSyncStateRuntime.getState,
|
|
1167
|
+
setSyncState: telegramSyncStateRuntime.setState,
|
|
1168
|
+
stopPolling: lockedPollingRuntime.stop,
|
|
1169
|
+
suspendPolling: lockedPollingRuntime.suspend,
|
|
1170
|
+
recordRuntimeEvent,
|
|
1171
|
+
});
|
|
1172
|
+
const telegramBridgeSessionLifecycleDeps =
|
|
1173
|
+
Lifecycle.createTelegramBridgeSessionLifecycleDeps({
|
|
1174
|
+
contextStore: telegramSessionContextStore,
|
|
1175
|
+
queue: {
|
|
1176
|
+
getCurrentModel: getContextModel,
|
|
1177
|
+
loadConfig: configStore.load,
|
|
1178
|
+
setQueuedItems: telegramQueueStore.setQueuedItems,
|
|
1179
|
+
setCurrentModel: currentModelRuntime.set,
|
|
1180
|
+
setPendingModelSwitch: pendingModelSwitchStore.set,
|
|
1181
|
+
syncCounters: queue.syncCounters,
|
|
1182
|
+
syncFlags: lifecycle.syncFlags,
|
|
1183
|
+
bindDeferredDispatchContext: deferredQueueDispatchRuntime.bind,
|
|
1184
|
+
prepareTempDir,
|
|
1185
|
+
updateStatus,
|
|
1186
|
+
unbindDeferredDispatchContext: deferredQueueDispatchRuntime.unbind,
|
|
1187
|
+
clearModelMenuState: modelMenuRuntime.clear,
|
|
1188
|
+
getActiveTurnChatId: activeTurnRuntime.getChatId,
|
|
1189
|
+
getActiveTurnTarget: activeTurnRuntime.getTarget,
|
|
1190
|
+
clearPreview: previewRuntime.clear,
|
|
1191
|
+
clearActiveTurn: activeTurnRuntime.clear,
|
|
1192
|
+
clearAbort: abort.clearHandler,
|
|
1193
|
+
recordRuntimeEvent,
|
|
1194
|
+
},
|
|
1195
|
+
follower: {
|
|
1196
|
+
registrationState: telegramBusFollowerRegistrationState,
|
|
1197
|
+
registrationRuntime: telegramBusFollowerRegistration,
|
|
1198
|
+
instanceId: telegramInstanceId,
|
|
1199
|
+
suspendPolling: lockedPollingRuntime.suspend,
|
|
1200
|
+
isLeader: lockRuntime.owns,
|
|
1201
|
+
getLeaderBinding: currentInstanceThreadRuntime.getRestorationIdentity,
|
|
1202
|
+
getActiveContext: telegramSessionContextStore.get,
|
|
1203
|
+
getActiveProfileName: configStore.getActiveProfileName,
|
|
1204
|
+
getLeaderState: lockRuntime.getState,
|
|
1205
|
+
updateStatus,
|
|
1206
|
+
recordRuntimeEvent,
|
|
1207
|
+
},
|
|
1208
|
+
services: {
|
|
1209
|
+
mediaGroup: {
|
|
1210
|
+
resume: mediaGroupRuntime.resume,
|
|
1211
|
+
suspend: mediaGroupRuntime.suspend,
|
|
1212
|
+
},
|
|
1213
|
+
textGroup: {
|
|
1214
|
+
resume: textGroupRuntime.resume,
|
|
1215
|
+
suspend: textGroupRuntime.suspend,
|
|
1216
|
+
},
|
|
1217
|
+
delivery: deliveryLifecycleRuntime,
|
|
1218
|
+
polling: lockedPollingRuntime,
|
|
1219
|
+
inboundWorker: {
|
|
1220
|
+
onSessionShutdown: updateAdmissionRuntimeBinding.onSessionShutdown,
|
|
1221
|
+
},
|
|
1222
|
+
capabilityMonitor: telegramThreadCapabilityMonitor,
|
|
1223
|
+
queueWatchdog: queueDispatchWatchdogRuntime,
|
|
1224
|
+
},
|
|
1225
|
+
});
|
|
1226
|
+
const sessionLifecycleRuntime =
|
|
1227
|
+
Lifecycle.createTelegramBridgeSessionLifecycleAssembly(
|
|
1228
|
+
telegramBridgeSessionLifecycleDeps,
|
|
1229
|
+
);
|
|
1230
|
+
|
|
1231
|
+
// --- Extension API Bindings ---
|
|
1232
|
+
|
|
1233
|
+
Bindings.registerTelegramCommandsAndTools({
|
|
1234
|
+
pi,
|
|
1235
|
+
agentDir: Paths.resolveAgentDir(),
|
|
1236
|
+
configStore,
|
|
1237
|
+
persistConfig: persistTelegramConfigWithSync,
|
|
1238
|
+
setup,
|
|
1239
|
+
activeTurnRuntime,
|
|
1240
|
+
lockedPollingRuntime,
|
|
1241
|
+
stopPolling: disconnectTelegramAndDeleteCurrentThread,
|
|
1242
|
+
recoverPollingStart: Recovery.createTelegramPollingStartRecoveryHandler({
|
|
1243
|
+
getOwnersPath: Paths.resolveTelegramOwnersPath,
|
|
1244
|
+
getStatePaths() {
|
|
1245
|
+
return [
|
|
1246
|
+
Threads.getTelegramTopicTargetsPath(
|
|
1247
|
+
undefined,
|
|
1248
|
+
configStore.getActiveProfileName(),
|
|
1249
|
+
),
|
|
1250
|
+
];
|
|
1251
|
+
},
|
|
1252
|
+
suspendPolling: lockedPollingRuntime.suspend,
|
|
1253
|
+
releaseOwnership: lockRuntime.release,
|
|
1254
|
+
recordRuntimeEvent,
|
|
1255
|
+
}),
|
|
1256
|
+
getDisconnectThreadName() {
|
|
1257
|
+
const record = findCurrentThreadRecord();
|
|
1258
|
+
if (!record?.target.threadId) return undefined;
|
|
1259
|
+
return record.threadName ?? "current Telegram thread";
|
|
1260
|
+
},
|
|
1261
|
+
onTransportChanged() {
|
|
1262
|
+
deliveryLifecycleRuntime.onSessionStart();
|
|
1263
|
+
activityVerbosityRuntime.reset();
|
|
1264
|
+
modelContextAvailabilityRuntime.reconcile();
|
|
1265
|
+
},
|
|
1266
|
+
getStatusLines,
|
|
1267
|
+
buttonActionStore,
|
|
1268
|
+
sendMarkdownReply,
|
|
1269
|
+
callMultipart,
|
|
1270
|
+
getDefaultChatId: proactivePushChatIdGetter,
|
|
1271
|
+
getDefaultTarget: proactivePushTargetGetter,
|
|
1272
|
+
...agentMessageToolRoutingRuntime,
|
|
1273
|
+
updateStatus,
|
|
1274
|
+
recordRuntimeEvent,
|
|
1275
|
+
});
|
|
1276
|
+
|
|
1277
|
+
// --- Lifecycle Hooks ---
|
|
1278
|
+
|
|
1279
|
+
Bindings.registerTelegramLifecycleRuntimeHooks({
|
|
1280
|
+
pi,
|
|
1281
|
+
sessionLifecycleRuntime: {
|
|
1282
|
+
...sessionLifecycleRuntime,
|
|
1283
|
+
onModelSelect: currentModelRuntime.onModelSelect,
|
|
1284
|
+
},
|
|
1285
|
+
activityRuntime,
|
|
1286
|
+
activityVerbosityRuntime,
|
|
1287
|
+
assistantOutputRuntime,
|
|
1288
|
+
configStore,
|
|
1289
|
+
abort,
|
|
1290
|
+
typing,
|
|
1291
|
+
lifecycle,
|
|
1292
|
+
activeTurnRuntime,
|
|
1293
|
+
telegramQueueStore,
|
|
1294
|
+
modelSwitchController,
|
|
1295
|
+
previewRuntime,
|
|
1296
|
+
promptDispatchRuntime,
|
|
1297
|
+
deferredQueueDispatchRuntime,
|
|
1298
|
+
modelContextAvailabilityRuntime,
|
|
1299
|
+
disconnectOnQuit: cleanupTelegramThreadForSessionRestart,
|
|
1300
|
+
resolveAutomaticThreadCleanupEnabled:
|
|
1301
|
+
configControls.resolveAutomaticThreadCleanupEnabled,
|
|
1302
|
+
buttonActionStore,
|
|
1303
|
+
callMultipart,
|
|
1304
|
+
sendChatAction,
|
|
1305
|
+
sendRecordVoiceAction,
|
|
1306
|
+
sendMarkdownReply,
|
|
1307
|
+
sendTextReply,
|
|
1308
|
+
dispatchNextQueuedTelegramTurn,
|
|
1309
|
+
onPromptHandedOff(turn, ctx) {
|
|
1310
|
+
updateAdmissionRuntimeBinding
|
|
1311
|
+
.getSettlement()
|
|
1312
|
+
?.onPromptHandedOff(turn, ctx);
|
|
1313
|
+
},
|
|
1314
|
+
answerGuestQuery,
|
|
1315
|
+
deleteMessage: deleteTelegramMessage,
|
|
1316
|
+
sendGuestReply,
|
|
1317
|
+
finalizeMarkdownPreview,
|
|
1318
|
+
proactivePushTargetGetter,
|
|
1319
|
+
getAssistantRenderingMode: configControls.getAssistantRenderingMode,
|
|
1320
|
+
recordMessageOwnership: messageOwnershipRuntime.recordLocal,
|
|
1321
|
+
canSendAgentActivity(ctx) {
|
|
1322
|
+
return (
|
|
1323
|
+
lockOwnershipGuard.ownsContext(ctx) ||
|
|
1324
|
+
telegramBusFollowerRegistrationState.isRegistered()
|
|
1325
|
+
);
|
|
1326
|
+
},
|
|
1327
|
+
isSessionContextActive(ctx) {
|
|
1328
|
+
return telegramSessionContextStore.isCurrent(ctx);
|
|
1329
|
+
},
|
|
1330
|
+
isTurnTransportActive(turn) {
|
|
1331
|
+
return telegramTransportStampRuntime.isActive(turn.transportStamp);
|
|
1332
|
+
},
|
|
1333
|
+
updateStatus,
|
|
1334
|
+
recordRuntimeEvent,
|
|
1335
|
+
});
|
|
1336
|
+
}
|