@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,1129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram bridge binding composition
|
|
3
|
+
* Zones: telegram, pi agent, orchestration
|
|
4
|
+
* Owns pi-facing tool, command, and lifecycle hook registration for the entrypoint
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as Activity from "./activity.ts";
|
|
8
|
+
import * as ActivityVerbosity from "./activity-verbosity.ts";
|
|
9
|
+
import * as CommandTemplates from "./command-templates.ts";
|
|
10
|
+
import * as Commands from "./commands.ts";
|
|
11
|
+
import * as Config from "./config.ts";
|
|
12
|
+
import * as Keyboard from "./keyboard.ts";
|
|
13
|
+
import * as Lifecycle from "./lifecycle.ts";
|
|
14
|
+
import * as Locks from "./locks.ts";
|
|
15
|
+
import * as Model from "./model.ts";
|
|
16
|
+
import * as OutboundAttachments from "./outbound-attachments.ts";
|
|
17
|
+
import * as OutboundHandlers from "./outbound.ts";
|
|
18
|
+
import * as Pi from "./pi.ts";
|
|
19
|
+
import * as Preview from "./preview.ts";
|
|
20
|
+
import * as Prompts from "./prompts.ts";
|
|
21
|
+
import * as Queue from "./queue.ts";
|
|
22
|
+
import * as Replies from "./replies.ts";
|
|
23
|
+
import * as Routing from "./routing.ts";
|
|
24
|
+
import * as Runtime from "./runtime.ts";
|
|
25
|
+
import * as Setup from "./setup.ts";
|
|
26
|
+
import * as Status from "./status.ts";
|
|
27
|
+
import * as TelegramApi from "./telegram-api.ts";
|
|
28
|
+
import type { TelegramTarget } from "./target.ts";
|
|
29
|
+
import * as GenerativeApps from "./generative-apps.ts";
|
|
30
|
+
|
|
31
|
+
type ActivePiModel = NonNullable<Pi.ExtensionContext["model"]>;
|
|
32
|
+
|
|
33
|
+
type TelegramRuntimeEventRecorder = (
|
|
34
|
+
category: string,
|
|
35
|
+
error: unknown,
|
|
36
|
+
details?: Record<string, unknown>,
|
|
37
|
+
) => void;
|
|
38
|
+
|
|
39
|
+
type TelegramBridgeStatusUpdater =
|
|
40
|
+
Status.TelegramStatusRuntime<Pi.ExtensionContext>["updateStatus"];
|
|
41
|
+
|
|
42
|
+
type TelegramAgentTargetResolver = NonNullable<
|
|
43
|
+
OutboundAttachments.TelegramOutboundMessageToolRegistrationDeps["resolveAgentTarget"]
|
|
44
|
+
>;
|
|
45
|
+
type TelegramAgentMessageRouter = NonNullable<
|
|
46
|
+
OutboundAttachments.TelegramOutboundMessageToolRegistrationDeps["routeAgentMessage"]
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
export interface TelegramQueueBindingRuntime<TContext> {
|
|
50
|
+
mutation: Queue.TelegramQueueMutationController<TContext>;
|
|
51
|
+
dispatchNext: (ctx: TContext) => void;
|
|
52
|
+
watchdog: Queue.TelegramQueueDispatchWatchdogRuntime<TContext>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createTelegramQueueBindingRuntime<TContext>(deps: {
|
|
56
|
+
store: Queue.TelegramQueueStateStore<TContext>;
|
|
57
|
+
queue: Pick<Runtime.TelegramBridgeRuntime["queue"], "allocateItemOrder">;
|
|
58
|
+
lifecycle: Pick<
|
|
59
|
+
Runtime.TelegramBridgeRuntime["lifecycle"],
|
|
60
|
+
"isCompactionInProgress" | "hasDispatchPending"
|
|
61
|
+
>;
|
|
62
|
+
activeTurn: Pick<Queue.TelegramActiveTurnStore, "has">;
|
|
63
|
+
admission: {
|
|
64
|
+
getSettlement: () =>
|
|
65
|
+
| {
|
|
66
|
+
onItemsDiscarded: (
|
|
67
|
+
items: readonly Queue.TelegramQueueItem<TContext>[],
|
|
68
|
+
ctx: TContext,
|
|
69
|
+
) => void;
|
|
70
|
+
isItemReady: (item: Queue.TelegramQueueItem<TContext>) => boolean;
|
|
71
|
+
onControlSettled: (
|
|
72
|
+
item: Queue.PendingTelegramControlItem<TContext>,
|
|
73
|
+
ctx: TContext,
|
|
74
|
+
) => void;
|
|
75
|
+
}
|
|
76
|
+
| undefined;
|
|
77
|
+
hasPendingQueueMutationForItem: (
|
|
78
|
+
item: Queue.TelegramQueueItem<TContext>,
|
|
79
|
+
) => boolean;
|
|
80
|
+
};
|
|
81
|
+
transportStamp: Pick<Queue.TelegramTransportStampRuntime, "isActive">;
|
|
82
|
+
deferredDispatch: Pick<
|
|
83
|
+
Queue.TelegramDeferredQueueDispatchRuntime<TContext>,
|
|
84
|
+
"isBound" | "getGeneration" | "isGenerationActive"
|
|
85
|
+
>;
|
|
86
|
+
promptDispatch: Runtime.TelegramPromptDispatchRuntime<TContext>;
|
|
87
|
+
isIdle: (ctx: TContext) => boolean;
|
|
88
|
+
hasPendingMessages: (ctx: TContext) => boolean;
|
|
89
|
+
updateStatus: (ctx: TContext, error?: string) => void;
|
|
90
|
+
sendTextReply: Queue.TelegramQueueDispatchRuntimeDeps<TContext>["sendTextReply"];
|
|
91
|
+
sendUserMessage: Queue.TelegramQueueDispatchRuntimeDeps<TContext>["sendUserMessage"];
|
|
92
|
+
recordRuntimeEvent?: TelegramRuntimeEventRecorder;
|
|
93
|
+
}): TelegramQueueBindingRuntime<TContext> {
|
|
94
|
+
const mutation = Queue.createTelegramQueueMutationController({
|
|
95
|
+
...deps.store,
|
|
96
|
+
allocateLaneOrder: deps.queue.allocateItemOrder,
|
|
97
|
+
onItemsDiscarded(items, ctx) {
|
|
98
|
+
deps.admission.getSettlement()?.onItemsDiscarded(items, ctx);
|
|
99
|
+
},
|
|
100
|
+
updateStatus: deps.updateStatus,
|
|
101
|
+
recordRuntimeEvent: deps.recordRuntimeEvent,
|
|
102
|
+
});
|
|
103
|
+
const dispatchNext = Queue.createTelegramQueueDispatchRuntime({
|
|
104
|
+
...deps.store,
|
|
105
|
+
isCompactionInProgress: deps.lifecycle.isCompactionInProgress,
|
|
106
|
+
hasActiveTurn: deps.activeTurn.has,
|
|
107
|
+
hasDispatchPending: deps.lifecycle.hasDispatchPending,
|
|
108
|
+
isIdle: deps.isIdle,
|
|
109
|
+
hasPendingMessages: deps.hasPendingMessages,
|
|
110
|
+
hasDispatchContext: deps.deferredDispatch.isBound,
|
|
111
|
+
getDispatchGeneration: deps.deferredDispatch.getGeneration,
|
|
112
|
+
isDispatchGenerationActive: deps.deferredDispatch.isGenerationActive,
|
|
113
|
+
isQueueItemTransportActive(item) {
|
|
114
|
+
return deps.transportStamp.isActive(item.transportStamp);
|
|
115
|
+
},
|
|
116
|
+
hasPendingInboundQueueMutationForItem(item) {
|
|
117
|
+
return deps.admission.hasPendingQueueMutationForItem(item);
|
|
118
|
+
},
|
|
119
|
+
isQueueItemAdmissionReady(item) {
|
|
120
|
+
return (
|
|
121
|
+
deps.admission.getSettlement()?.isItemReady(item) ??
|
|
122
|
+
(item.admissionReceipts?.length ?? 0) === 0
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
onControlSettled(item, ctx) {
|
|
126
|
+
deps.admission.getSettlement()?.onControlSettled(item, ctx);
|
|
127
|
+
},
|
|
128
|
+
updateStatus: deps.updateStatus,
|
|
129
|
+
sendTextReply: deps.sendTextReply,
|
|
130
|
+
recordRuntimeEvent: deps.recordRuntimeEvent,
|
|
131
|
+
...deps.promptDispatch,
|
|
132
|
+
sendUserMessage: deps.sendUserMessage,
|
|
133
|
+
}).dispatchNext;
|
|
134
|
+
return {
|
|
135
|
+
mutation,
|
|
136
|
+
dispatchNext,
|
|
137
|
+
watchdog: Queue.createTelegramQueueDispatchWatchdogRuntime({
|
|
138
|
+
hasQueuedItems: deps.store.hasQueuedItems,
|
|
139
|
+
dispatchNextQueuedTelegramTurn: dispatchNext,
|
|
140
|
+
recordRuntimeEvent: deps.recordRuntimeEvent,
|
|
141
|
+
}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function createTelegramGenerativeAppBoundButtonActionInvoker<
|
|
146
|
+
TQuery extends {
|
|
147
|
+
message?: { chat?: { id?: number }; message_id?: number };
|
|
148
|
+
},
|
|
149
|
+
>(deps: {
|
|
150
|
+
agentDir: string;
|
|
151
|
+
assertExecutionCurrent: (query: TQuery) => void;
|
|
152
|
+
getExecutionFence: (query: TQuery) => GenerativeApps.GenerativeAppExecutionFence | undefined;
|
|
153
|
+
planOutput: ReturnType<typeof OutboundHandlers.createTelegramOutboundReplyPlanner>;
|
|
154
|
+
sendMarkdownReply: (
|
|
155
|
+
chatId: number,
|
|
156
|
+
replyToMessageId: number,
|
|
157
|
+
markdown: string,
|
|
158
|
+
options?: { replyMarkup?: OutboundHandlers.TelegramOutboundButtonMarkup },
|
|
159
|
+
) => Promise<unknown>;
|
|
160
|
+
editInteractiveMessage?: (
|
|
161
|
+
chatId: number,
|
|
162
|
+
messageId: number,
|
|
163
|
+
markdown: string,
|
|
164
|
+
mode: "markdown",
|
|
165
|
+
replyMarkup: OutboundHandlers.TelegramOutboundButtonMarkup,
|
|
166
|
+
) => Promise<void>;
|
|
167
|
+
recordRuntimeEvent: TelegramRuntimeEventRecorder;
|
|
168
|
+
}): (
|
|
169
|
+
action: OutboundHandlers.TelegramOutboundButtonAction,
|
|
170
|
+
query: TQuery,
|
|
171
|
+
) => Promise<false | "new" | "edit"> {
|
|
172
|
+
return async (action, query) => {
|
|
173
|
+
let boundAction: GenerativeApps.GenerativeAppBoundAction | undefined;
|
|
174
|
+
try {
|
|
175
|
+
boundAction = GenerativeApps.parseGenerativeAppBoundAction(action.prompt);
|
|
176
|
+
if (!boundAction) return false;
|
|
177
|
+
deps.assertExecutionCurrent(query);
|
|
178
|
+
const result = await GenerativeApps.invokeGenerativeApp({
|
|
179
|
+
agentDir: deps.agentDir,
|
|
180
|
+
...(deps.getExecutionFence(query)
|
|
181
|
+
? { execution: deps.getExecutionFence(query) }
|
|
182
|
+
: {}),
|
|
183
|
+
...(boundAction.argument !== undefined
|
|
184
|
+
? { argument: boundAction.argument }
|
|
185
|
+
: {}),
|
|
186
|
+
...(action.binding?.app === boundAction.app
|
|
187
|
+
? {
|
|
188
|
+
expectedGeneration: action.binding.generation,
|
|
189
|
+
expectedRevision: action.binding.revision,
|
|
190
|
+
}
|
|
191
|
+
: {}),
|
|
192
|
+
method: boundAction.method,
|
|
193
|
+
app: boundAction.app,
|
|
194
|
+
});
|
|
195
|
+
deps.assertExecutionCurrent(query);
|
|
196
|
+
const chatId = query.message?.chat?.id;
|
|
197
|
+
const messageId = query.message?.message_id;
|
|
198
|
+
if (typeof chatId !== "number" || typeof messageId !== "number") {
|
|
199
|
+
throw new Error("Generative App callback target is unavailable.");
|
|
200
|
+
}
|
|
201
|
+
const reply = deps.planOutput(result.output, {
|
|
202
|
+
binding: {
|
|
203
|
+
generation: result.generation,
|
|
204
|
+
app: result.app,
|
|
205
|
+
revision: result.revision,
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
if (result.viewMode === "edit" && deps.editInteractiveMessage) {
|
|
209
|
+
let editFailed = false;
|
|
210
|
+
try {
|
|
211
|
+
await deps.editInteractiveMessage(
|
|
212
|
+
chatId,
|
|
213
|
+
messageId,
|
|
214
|
+
reply.markdown,
|
|
215
|
+
"markdown",
|
|
216
|
+
reply.replyMarkup ?? { inline_keyboard: [] },
|
|
217
|
+
);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
editFailed = true;
|
|
220
|
+
deps.recordRuntimeEvent("generative-app", error, {
|
|
221
|
+
phase: "bound-action-edit-fallback",
|
|
222
|
+
app: boundAction.app,
|
|
223
|
+
method: boundAction.method,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
deps.assertExecutionCurrent(query);
|
|
227
|
+
if (!editFailed) return "edit";
|
|
228
|
+
}
|
|
229
|
+
deps.assertExecutionCurrent(query);
|
|
230
|
+
await deps.sendMarkdownReply(chatId, messageId, reply.markdown, {
|
|
231
|
+
replyMarkup: reply.replyMarkup,
|
|
232
|
+
});
|
|
233
|
+
deps.assertExecutionCurrent(query);
|
|
234
|
+
return "new";
|
|
235
|
+
} catch (error) {
|
|
236
|
+
deps.recordRuntimeEvent("generative-app", error, {
|
|
237
|
+
phase: "bound-action",
|
|
238
|
+
...(boundAction
|
|
239
|
+
? { app: boundAction.app, method: boundAction.method }
|
|
240
|
+
: {}),
|
|
241
|
+
});
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface TelegramAgentMessageToolRoutingRuntime {
|
|
248
|
+
resolveAgentTarget: TelegramAgentTargetResolver;
|
|
249
|
+
routeAgentMessage: TelegramAgentMessageRouter;
|
|
250
|
+
canSendDirect: () => boolean;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function createTelegramAgentMessageToolRoutingRuntime(deps: {
|
|
254
|
+
ownsLeader: () => boolean;
|
|
255
|
+
ownsDirectDelivery: () => boolean;
|
|
256
|
+
isFollowerRegistered: () => boolean;
|
|
257
|
+
getSourceTarget: () => TelegramTarget | undefined;
|
|
258
|
+
getSourceThreadName: () => string | undefined;
|
|
259
|
+
local: {
|
|
260
|
+
resolveTarget: (
|
|
261
|
+
selector: Parameters<TelegramAgentTargetResolver>[0],
|
|
262
|
+
sourceTarget?: TelegramTarget,
|
|
263
|
+
) => Awaited<ReturnType<TelegramAgentTargetResolver>> | undefined;
|
|
264
|
+
route: (input: {
|
|
265
|
+
sourceTarget?: TelegramTarget;
|
|
266
|
+
sourceThreadName?: string;
|
|
267
|
+
message: Parameters<TelegramAgentMessageRouter>[0];
|
|
268
|
+
}) => Promise<void>;
|
|
269
|
+
};
|
|
270
|
+
follower: {
|
|
271
|
+
resolveTarget: TelegramAgentTargetResolver;
|
|
272
|
+
routeMessage: TelegramAgentMessageRouter;
|
|
273
|
+
};
|
|
274
|
+
}): TelegramAgentMessageToolRoutingRuntime {
|
|
275
|
+
return {
|
|
276
|
+
async resolveAgentTarget(selector) {
|
|
277
|
+
if (!deps.ownsLeader()) return deps.follower.resolveTarget(selector);
|
|
278
|
+
const target = deps.local.resolveTarget(selector, deps.getSourceTarget());
|
|
279
|
+
if (!target) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
"Telegram agent target is unavailable, ambiguous, or not live.",
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return target;
|
|
285
|
+
},
|
|
286
|
+
async routeAgentMessage(message) {
|
|
287
|
+
if (!deps.ownsLeader()) return deps.follower.routeMessage(message);
|
|
288
|
+
await deps.local.route({
|
|
289
|
+
sourceTarget: deps.getSourceTarget(),
|
|
290
|
+
sourceThreadName: deps.getSourceThreadName(),
|
|
291
|
+
message,
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
canSendDirect() {
|
|
295
|
+
return deps.ownsDirectDelivery() || deps.isFollowerRegistered();
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface TelegramAssistantOutputBindingRuntime<TTransportStamp> {
|
|
301
|
+
runtime: Activity.TelegramAssistantOutputRuntime;
|
|
302
|
+
observeEvent: (event: Activity.TelegramActivityEvent) => void;
|
|
303
|
+
authority: Routing.TelegramAssistantOutputAuthorityRuntime<TTransportStamp>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function createTelegramAssistantOutputBindingRuntime<
|
|
307
|
+
TTransportStamp,
|
|
308
|
+
>(deps: {
|
|
309
|
+
isEnabled: () => boolean;
|
|
310
|
+
authority: {
|
|
311
|
+
getPreferredTarget: () =>
|
|
312
|
+
| OutboundAttachments.TelegramQueuedOutboundAttachmentTurnView["target"]
|
|
313
|
+
| undefined;
|
|
314
|
+
getFallbackChatId: () => number | undefined;
|
|
315
|
+
getTransportStamp: () => TTransportStamp;
|
|
316
|
+
isTransportStampActive: (stamp: TTransportStamp) => boolean;
|
|
317
|
+
ownsDirect: () => boolean;
|
|
318
|
+
getDirectEpoch: () => number | string | undefined;
|
|
319
|
+
isFollowerRegistered: () => boolean;
|
|
320
|
+
getFollowerGeneration: () => string | undefined;
|
|
321
|
+
};
|
|
322
|
+
sender: Parameters<
|
|
323
|
+
typeof OutboundHandlers.createTelegramAssistantOutputSender<TTransportStamp>
|
|
324
|
+
>[0];
|
|
325
|
+
waitForActivityIdle?: () => Promise<void>;
|
|
326
|
+
recordRuntimeEvent: TelegramRuntimeEventRecorder;
|
|
327
|
+
}): TelegramAssistantOutputBindingRuntime<TTransportStamp> {
|
|
328
|
+
const authority = Routing.createTelegramAssistantOutputAuthorityRuntime(
|
|
329
|
+
deps.authority,
|
|
330
|
+
);
|
|
331
|
+
const sendOutput =
|
|
332
|
+
OutboundHandlers.createTelegramAssistantOutputSender<TTransportStamp>(
|
|
333
|
+
deps.sender,
|
|
334
|
+
);
|
|
335
|
+
const runtime = Activity.createTelegramAssistantOutputRuntime({
|
|
336
|
+
isEnabled: deps.isEnabled,
|
|
337
|
+
...authority,
|
|
338
|
+
async send(event, authority, isAuthorityActive) {
|
|
339
|
+
await deps.waitForActivityIdle?.();
|
|
340
|
+
if (!isAuthorityActive()) return;
|
|
341
|
+
await sendOutput(event, authority, isAuthorityActive);
|
|
342
|
+
},
|
|
343
|
+
recordFailure(event, error) {
|
|
344
|
+
deps.recordRuntimeEvent("proactive-push", error, {
|
|
345
|
+
activityId: event.activityId,
|
|
346
|
+
sequence: event.sequence,
|
|
347
|
+
placement: event.placement,
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
return {
|
|
352
|
+
runtime,
|
|
353
|
+
authority,
|
|
354
|
+
observeEvent(event) {
|
|
355
|
+
if (event.type === "assistant-segment") runtime.accept(event);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
type TelegramAssistantOutputAuthority<TTransportStamp> = ReturnType<
|
|
361
|
+
Routing.TelegramAssistantOutputAuthorityRuntime<TTransportStamp>["captureAuthority"]
|
|
362
|
+
>;
|
|
363
|
+
|
|
364
|
+
export interface TelegramActivityBindingRuntime {
|
|
365
|
+
activityRuntime: Activity.TelegramActivityRuntime;
|
|
366
|
+
activityVerbosityRuntime: ActivityVerbosity.TelegramActivityVerbosityRuntime;
|
|
367
|
+
assistantOutputRuntime: Activity.TelegramAssistantOutputRuntime;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** Compose public activity fanout, verbosity, and assistant output ordering. */
|
|
371
|
+
export function createTelegramActivityBindingRuntime<TTransportStamp>(deps: {
|
|
372
|
+
generation: string;
|
|
373
|
+
assistantOutput: Omit<
|
|
374
|
+
Parameters<
|
|
375
|
+
typeof createTelegramAssistantOutputBindingRuntime<TTransportStamp>
|
|
376
|
+
>[0],
|
|
377
|
+
"waitForActivityIdle"
|
|
378
|
+
>;
|
|
379
|
+
activityVerbosity: Omit<
|
|
380
|
+
Parameters<
|
|
381
|
+
typeof ActivityVerbosity.createTelegramActivityVerbosityRuntime<
|
|
382
|
+
TelegramAssistantOutputAuthority<TTransportStamp>
|
|
383
|
+
>
|
|
384
|
+
>[0],
|
|
385
|
+
"captureAuthority" | "isAuthorityActive" | "recordFailure"
|
|
386
|
+
>;
|
|
387
|
+
}): TelegramActivityBindingRuntime {
|
|
388
|
+
const activityVerbosityBinding =
|
|
389
|
+
ActivityVerbosity.createTelegramActivityVerbosityBinding();
|
|
390
|
+
const assistantOutputBinding =
|
|
391
|
+
createTelegramAssistantOutputBindingRuntime({
|
|
392
|
+
...deps.assistantOutput,
|
|
393
|
+
waitForActivityIdle: activityVerbosityBinding.waitForIdle,
|
|
394
|
+
});
|
|
395
|
+
const activityVerbosityRuntime =
|
|
396
|
+
ActivityVerbosity.createTelegramActivityVerbosityRuntime({
|
|
397
|
+
...deps.activityVerbosity,
|
|
398
|
+
captureAuthority: assistantOutputBinding.authority.captureAuthority,
|
|
399
|
+
isAuthorityActive: assistantOutputBinding.authority.isAuthorityActive,
|
|
400
|
+
recordFailure(operation, event, error) {
|
|
401
|
+
deps.assistantOutput.recordRuntimeEvent("activity", error, {
|
|
402
|
+
operation,
|
|
403
|
+
eventType: event.type,
|
|
404
|
+
activityId: event.activityId,
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
activityVerbosityBinding.bind(activityVerbosityRuntime);
|
|
409
|
+
const activityRuntime = Activity.createTelegramActivityBridgeRuntime({
|
|
410
|
+
generation: deps.generation,
|
|
411
|
+
observeEvent(event) {
|
|
412
|
+
assistantOutputBinding.observeEvent(event);
|
|
413
|
+
activityVerbosityRuntime.accept(event);
|
|
414
|
+
},
|
|
415
|
+
recordFailure(handlerId, event, error) {
|
|
416
|
+
deps.assistantOutput.recordRuntimeEvent("activity", error, {
|
|
417
|
+
handlerId,
|
|
418
|
+
eventType: event.type,
|
|
419
|
+
activityId: event.activityId,
|
|
420
|
+
});
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
return {
|
|
424
|
+
activityRuntime,
|
|
425
|
+
activityVerbosityRuntime,
|
|
426
|
+
assistantOutputRuntime: assistantOutputBinding.runtime,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
interface TelegramCommandsAndToolsBindingDeps {
|
|
431
|
+
pi: Pi.ExtensionAPI;
|
|
432
|
+
agentDir: string;
|
|
433
|
+
configStore: Config.TelegramConfigStore;
|
|
434
|
+
persistConfig: (config?: Config.TelegramConfig) => Promise<void>;
|
|
435
|
+
setup: Setup.TelegramSetupGuard;
|
|
436
|
+
activeTurnRuntime: Queue.TelegramActiveTurnStore<Queue.PendingTelegramTurn>;
|
|
437
|
+
lockedPollingRuntime: Locks.TelegramLockedPollingRuntime<Pi.ExtensionContext>;
|
|
438
|
+
stopPolling?: () => Promise<void | string>;
|
|
439
|
+
recoverPollingStart?: Commands.TelegramBridgeCommandRegistrationDeps["recoverPollingStart"];
|
|
440
|
+
getDisconnectThreadName?: () => string | undefined;
|
|
441
|
+
onTransportChanged?: () => Promise<void> | void;
|
|
442
|
+
getStatusLines: (
|
|
443
|
+
options?: Status.TelegramBridgeStatusLineOptions,
|
|
444
|
+
) => string[];
|
|
445
|
+
buttonActionStore: OutboundHandlers.TelegramButtonActionStore;
|
|
446
|
+
sendMarkdownReply: (
|
|
447
|
+
chatId: number,
|
|
448
|
+
replyToMessageId: number | undefined,
|
|
449
|
+
markdown: string,
|
|
450
|
+
options?: {
|
|
451
|
+
replyMarkup?: unknown;
|
|
452
|
+
target?: { chatId: number; threadId?: number };
|
|
453
|
+
},
|
|
454
|
+
) => Promise<number | undefined>;
|
|
455
|
+
callMultipart: OutboundHandlers.TelegramVoiceReplySenderDeps["sendMultipart"];
|
|
456
|
+
getDefaultChatId: () => number | undefined;
|
|
457
|
+
getDefaultTarget?: () => OutboundAttachments.TelegramQueuedOutboundAttachmentTurnView["target"];
|
|
458
|
+
resolveAgentTarget?: OutboundAttachments.TelegramOutboundMessageToolRegistrationDeps["resolveAgentTarget"];
|
|
459
|
+
routeAgentMessage?: OutboundAttachments.TelegramOutboundMessageToolRegistrationDeps["routeAgentMessage"];
|
|
460
|
+
canSendDirect: () => boolean;
|
|
461
|
+
updateStatus: TelegramBridgeStatusUpdater;
|
|
462
|
+
recordRuntimeEvent: TelegramRuntimeEventRecorder;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export function registerTelegramCommandsAndTools({
|
|
466
|
+
pi,
|
|
467
|
+
agentDir,
|
|
468
|
+
configStore,
|
|
469
|
+
persistConfig,
|
|
470
|
+
setup,
|
|
471
|
+
activeTurnRuntime,
|
|
472
|
+
lockedPollingRuntime,
|
|
473
|
+
stopPolling,
|
|
474
|
+
recoverPollingStart,
|
|
475
|
+
getDisconnectThreadName,
|
|
476
|
+
onTransportChanged,
|
|
477
|
+
getStatusLines,
|
|
478
|
+
buttonActionStore,
|
|
479
|
+
sendMarkdownReply,
|
|
480
|
+
callMultipart,
|
|
481
|
+
getDefaultChatId,
|
|
482
|
+
getDefaultTarget,
|
|
483
|
+
resolveAgentTarget,
|
|
484
|
+
routeAgentMessage,
|
|
485
|
+
canSendDirect,
|
|
486
|
+
recordRuntimeEvent,
|
|
487
|
+
updateStatus,
|
|
488
|
+
}: TelegramCommandsAndToolsBindingDeps): void {
|
|
489
|
+
GenerativeApps.registerTelegramBindTool(pi, {
|
|
490
|
+
agentDir,
|
|
491
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
492
|
+
planOutput: OutboundHandlers.createTelegramOutboundReplyPlanner(buttonActionStore),
|
|
493
|
+
sendMarkdownReply,
|
|
494
|
+
recordRuntimeEvent,
|
|
495
|
+
});
|
|
496
|
+
OutboundAttachments.registerTelegramOutboundAttachmentTool(pi, {
|
|
497
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
498
|
+
getDefaultChatId,
|
|
499
|
+
getDefaultTarget,
|
|
500
|
+
canSendDirect,
|
|
501
|
+
sendMultipart: callMultipart,
|
|
502
|
+
recordRuntimeEvent,
|
|
503
|
+
});
|
|
504
|
+
OutboundAttachments.registerTelegramOutboundMessageTool(pi, {
|
|
505
|
+
getDefaultChatId,
|
|
506
|
+
getDefaultTarget,
|
|
507
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
508
|
+
resolveAgentTarget,
|
|
509
|
+
routeAgentMessage,
|
|
510
|
+
canSendDirect,
|
|
511
|
+
planMessage:
|
|
512
|
+
OutboundHandlers.createTelegramOutboundReplyPlanner(buttonActionStore),
|
|
513
|
+
sendMarkdownMessage: (chatId, markdown, options) =>
|
|
514
|
+
sendMarkdownReply(chatId, undefined, markdown, options),
|
|
515
|
+
recordRuntimeEvent,
|
|
516
|
+
});
|
|
517
|
+
Commands.registerTelegramBridgeCommands(pi, {
|
|
518
|
+
promptForConfig: async (ctx, profileName) => {
|
|
519
|
+
const nextProfileName = profileName ?? undefined;
|
|
520
|
+
if (profileName && !Config.isValidTelegramProfileName(profileName)) {
|
|
521
|
+
ctx.ui.notify(`Invalid Telegram profile name: ${profileName}`, "error");
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const previousProfileName = configStore.getActiveProfileName();
|
|
525
|
+
let setupConfigStore = configStore;
|
|
526
|
+
let persistSetupConfig = persistConfig;
|
|
527
|
+
if (!profileName) {
|
|
528
|
+
if (previousProfileName !== nextProfileName) {
|
|
529
|
+
await (stopPolling ?? lockedPollingRuntime.stop)();
|
|
530
|
+
}
|
|
531
|
+
configStore.activateProfile(undefined);
|
|
532
|
+
await onTransportChanged?.();
|
|
533
|
+
} else {
|
|
534
|
+
const storedConfig = configStore.getStoredConfig();
|
|
535
|
+
setupConfigStore = Config.createTelegramConfigStore({
|
|
536
|
+
initialConfig: {
|
|
537
|
+
...storedConfig,
|
|
538
|
+
profiles: {
|
|
539
|
+
...(storedConfig.profiles ?? {}),
|
|
540
|
+
[profileName]: storedConfig.profiles?.[profileName] ?? {
|
|
541
|
+
botToken: "",
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
setupConfigStore.activateProfile(profileName);
|
|
547
|
+
persistSetupConfig = async () => {
|
|
548
|
+
try {
|
|
549
|
+
if (previousProfileName !== profileName) {
|
|
550
|
+
await (stopPolling ?? lockedPollingRuntime.stop)();
|
|
551
|
+
}
|
|
552
|
+
const profile = Config.getTelegramProfileFields(
|
|
553
|
+
setupConfigStore.get(),
|
|
554
|
+
);
|
|
555
|
+
if (!profile) {
|
|
556
|
+
throw new Error(
|
|
557
|
+
`Telegram profile "${profileName}" has no token.`,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
await configStore.load();
|
|
561
|
+
configStore.setProfile(profileName, profile);
|
|
562
|
+
configStore.activateProfile(profileName);
|
|
563
|
+
await onTransportChanged?.();
|
|
564
|
+
await persistConfig(configStore.get());
|
|
565
|
+
} catch (error) {
|
|
566
|
+
await configStore.load().catch(() => undefined);
|
|
567
|
+
configStore.activateProfile(previousProfileName);
|
|
568
|
+
await onTransportChanged?.();
|
|
569
|
+
throw error;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
const runSetup = Setup.createTelegramSetupPromptRuntime({
|
|
574
|
+
getConfig: setupConfigStore.get,
|
|
575
|
+
setConfig: setupConfigStore.set,
|
|
576
|
+
setupGuard: setup,
|
|
577
|
+
getMe: TelegramApi.fetchTelegramBotIdentity,
|
|
578
|
+
persistConfig: persistSetupConfig,
|
|
579
|
+
startPolling: lockedPollingRuntime.start,
|
|
580
|
+
updateStatus,
|
|
581
|
+
recordRuntimeEvent,
|
|
582
|
+
});
|
|
583
|
+
const completion = await runSetup(ctx);
|
|
584
|
+
if (profileName && completion.status === "success") {
|
|
585
|
+
ctx.ui.notify(`Profile "${profileName}" saved and connected.`, "info");
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
getStatusLines,
|
|
589
|
+
reloadConfig: configStore.load,
|
|
590
|
+
hasBotToken: configStore.hasBotToken,
|
|
591
|
+
startPolling: async (ctx, options) => {
|
|
592
|
+
try {
|
|
593
|
+
return await lockedPollingRuntime.start(ctx, options);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
recordRuntimeEvent("recovery", error, { phase: "polling-start" });
|
|
596
|
+
throw error;
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
stopPolling: stopPolling ?? lockedPollingRuntime.stop,
|
|
600
|
+
recoverPollingStart,
|
|
601
|
+
getDisconnectThreadName,
|
|
602
|
+
updateStatus,
|
|
603
|
+
getProfileNames: () =>
|
|
604
|
+
Config.getTelegramProfileNames(configStore.getStoredConfig()),
|
|
605
|
+
activateDefaultProfileConfig: async () => {
|
|
606
|
+
const previousProfileName = configStore.getActiveProfileName();
|
|
607
|
+
await configStore.load();
|
|
608
|
+
if (previousProfileName) {
|
|
609
|
+
await (stopPolling ?? lockedPollingRuntime.stop)();
|
|
610
|
+
}
|
|
611
|
+
configStore.activateProfile(undefined);
|
|
612
|
+
await onTransportChanged?.();
|
|
613
|
+
},
|
|
614
|
+
activateProfileConfig: async (_ctx, profileName) => {
|
|
615
|
+
const previousProfileName = configStore.getActiveProfileName();
|
|
616
|
+
await configStore.load();
|
|
617
|
+
if (!Config.isValidTelegramProfileName(profileName)) return false;
|
|
618
|
+
const storedConfig = configStore.getStoredConfig();
|
|
619
|
+
if (!storedConfig.profiles?.[profileName]) return false;
|
|
620
|
+
if (previousProfileName !== profileName) {
|
|
621
|
+
await (stopPolling ?? lockedPollingRuntime.stop)();
|
|
622
|
+
}
|
|
623
|
+
if (!configStore.activateProfile(profileName)) return false;
|
|
624
|
+
await onTransportChanged?.();
|
|
625
|
+
return true;
|
|
626
|
+
},
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
interface TelegramLifecycleBindingDeps {
|
|
631
|
+
pi: Pi.ExtensionAPI;
|
|
632
|
+
activityRuntime: Activity.TelegramActivityRuntime;
|
|
633
|
+
activityVerbosityRuntime?: ActivityVerbosity.TelegramActivityVerbosityRuntime;
|
|
634
|
+
assistantOutputRuntime: Pick<
|
|
635
|
+
Activity.TelegramAssistantOutputRuntime,
|
|
636
|
+
"start" | "waitForIdle" | "stop"
|
|
637
|
+
>;
|
|
638
|
+
sessionLifecycleRuntime: Pick<
|
|
639
|
+
Lifecycle.TelegramLifecycleRegistrationDeps,
|
|
640
|
+
"onSessionStart" | "onSessionShutdown" | "onModelSelect"
|
|
641
|
+
>;
|
|
642
|
+
configStore: Pick<
|
|
643
|
+
Config.TelegramConfigStore,
|
|
644
|
+
"get" | "getOutboundHandlers" | "hasBotToken" | "load"
|
|
645
|
+
>;
|
|
646
|
+
abort: Runtime.TelegramRuntimeAbortPort;
|
|
647
|
+
typing: Runtime.TelegramRuntimeTypingPort;
|
|
648
|
+
lifecycle: Runtime.TelegramRuntimeLifecyclePort;
|
|
649
|
+
activeTurnRuntime: Queue.TelegramActiveTurnStore<Queue.PendingTelegramTurn>;
|
|
650
|
+
telegramQueueStore: Queue.TelegramQueueStore<Pi.ExtensionContext>;
|
|
651
|
+
modelSwitchController: Model.TelegramModelSwitchController<
|
|
652
|
+
Pi.ExtensionContext,
|
|
653
|
+
Model.ScopedTelegramModel<ActivePiModel>
|
|
654
|
+
>;
|
|
655
|
+
previewRuntime: Preview.TelegramAssistantPreviewRuntime<
|
|
656
|
+
Pi.AgentEndEvent["messages"][number],
|
|
657
|
+
Keyboard.TelegramInlineKeyboardMarkup
|
|
658
|
+
>;
|
|
659
|
+
promptDispatchRuntime: Runtime.TelegramPromptDispatchRuntime<Pi.ExtensionContext>;
|
|
660
|
+
deferredQueueDispatchRuntime: Queue.TelegramDeferredQueueDispatchRuntime<Pi.ExtensionContext>;
|
|
661
|
+
modelContextAvailabilityRuntime: Prompts.TelegramModelContextAvailabilityRuntime;
|
|
662
|
+
disconnectOnQuit?: () => Promise<unknown>;
|
|
663
|
+
resolveAutomaticThreadCleanupEnabled?: () => boolean | Promise<boolean>;
|
|
664
|
+
buttonActionStore: OutboundHandlers.TelegramButtonActionStore;
|
|
665
|
+
callMultipart: OutboundHandlers.TelegramVoiceReplySenderDeps["sendMultipart"];
|
|
666
|
+
sendChatAction: NonNullable<
|
|
667
|
+
OutboundHandlers.TelegramVoiceReplySenderDeps["sendChatAction"]
|
|
668
|
+
>;
|
|
669
|
+
sendRecordVoiceAction: NonNullable<
|
|
670
|
+
OutboundHandlers.TelegramVoiceReplySenderDeps["sendRecordVoiceAction"]
|
|
671
|
+
>;
|
|
672
|
+
sendMarkdownReply: Queue.TelegramAgentEndHookRuntimeDeps<
|
|
673
|
+
Queue.PendingTelegramTurn,
|
|
674
|
+
Pi.ExtensionContext,
|
|
675
|
+
Pi.AgentEndEvent["messages"][number],
|
|
676
|
+
Keyboard.TelegramInlineKeyboardMarkup
|
|
677
|
+
>["sendMarkdownReply"];
|
|
678
|
+
sendTextReply: Queue.TelegramAgentEndHookRuntimeDeps<
|
|
679
|
+
Queue.PendingTelegramTurn,
|
|
680
|
+
Pi.ExtensionContext,
|
|
681
|
+
Pi.AgentEndEvent["messages"][number],
|
|
682
|
+
Keyboard.TelegramInlineKeyboardMarkup
|
|
683
|
+
>["sendTextReply"] &
|
|
684
|
+
NonNullable<OutboundHandlers.TelegramVoiceReplySenderDeps["sendTextReply"]>;
|
|
685
|
+
dispatchNextQueuedTelegramTurn: (ctx: Pi.ExtensionContext) => void;
|
|
686
|
+
onPromptHandedOff?: (
|
|
687
|
+
turn: Queue.PendingTelegramTurn,
|
|
688
|
+
ctx: Pi.ExtensionContext,
|
|
689
|
+
) => void;
|
|
690
|
+
answerGuestQuery: TelegramApi.TelegramBridgeApiRuntime["answerGuestQuery"];
|
|
691
|
+
deleteMessage: TelegramApi.TelegramBridgeApiRuntime["deleteMessage"];
|
|
692
|
+
sendGuestReply: NonNullable<
|
|
693
|
+
Queue.TelegramAgentEndHookRuntimeDeps<
|
|
694
|
+
Queue.PendingTelegramTurn,
|
|
695
|
+
Pi.ExtensionContext,
|
|
696
|
+
Pi.AgentEndEvent["messages"][number],
|
|
697
|
+
Keyboard.TelegramInlineKeyboardMarkup
|
|
698
|
+
>["sendGuestReply"]
|
|
699
|
+
>;
|
|
700
|
+
finalizeMarkdownPreview: Queue.TelegramAgentEndHookRuntimeDeps<
|
|
701
|
+
Queue.PendingTelegramTurn,
|
|
702
|
+
Pi.ExtensionContext,
|
|
703
|
+
Pi.AgentEndEvent["messages"][number],
|
|
704
|
+
Keyboard.TelegramInlineKeyboardMarkup
|
|
705
|
+
>["finalizeMarkdownPreview"];
|
|
706
|
+
proactivePushTargetGetter: () => Queue.TelegramQueueTarget | undefined;
|
|
707
|
+
getAssistantRenderingMode: () => "rich" | "html";
|
|
708
|
+
recordMessageOwnership?: (input: {
|
|
709
|
+
chatId: number;
|
|
710
|
+
messageId: number;
|
|
711
|
+
target?: Queue.TelegramQueueTarget;
|
|
712
|
+
}) => void;
|
|
713
|
+
canSendAgentActivity: (ctx: Pi.ExtensionContext) => boolean;
|
|
714
|
+
isSessionContextActive: (ctx: Pi.ExtensionContext) => boolean;
|
|
715
|
+
isTurnTransportActive?: (turn: Queue.PendingTelegramTurn) => boolean;
|
|
716
|
+
updateStatus: TelegramBridgeStatusUpdater;
|
|
717
|
+
recordRuntimeEvent: TelegramRuntimeEventRecorder;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export function registerTelegramLifecycleRuntimeHooks({
|
|
721
|
+
pi,
|
|
722
|
+
activityRuntime,
|
|
723
|
+
activityVerbosityRuntime,
|
|
724
|
+
assistantOutputRuntime,
|
|
725
|
+
sessionLifecycleRuntime,
|
|
726
|
+
configStore,
|
|
727
|
+
abort,
|
|
728
|
+
typing,
|
|
729
|
+
lifecycle,
|
|
730
|
+
activeTurnRuntime,
|
|
731
|
+
telegramQueueStore,
|
|
732
|
+
modelSwitchController,
|
|
733
|
+
previewRuntime,
|
|
734
|
+
promptDispatchRuntime,
|
|
735
|
+
deferredQueueDispatchRuntime,
|
|
736
|
+
modelContextAvailabilityRuntime,
|
|
737
|
+
disconnectOnQuit,
|
|
738
|
+
resolveAutomaticThreadCleanupEnabled,
|
|
739
|
+
buttonActionStore,
|
|
740
|
+
callMultipart,
|
|
741
|
+
sendChatAction,
|
|
742
|
+
sendRecordVoiceAction,
|
|
743
|
+
sendMarkdownReply,
|
|
744
|
+
sendTextReply,
|
|
745
|
+
dispatchNextQueuedTelegramTurn,
|
|
746
|
+
onPromptHandedOff,
|
|
747
|
+
answerGuestQuery,
|
|
748
|
+
deleteMessage,
|
|
749
|
+
sendGuestReply,
|
|
750
|
+
finalizeMarkdownPreview,
|
|
751
|
+
proactivePushTargetGetter,
|
|
752
|
+
getAssistantRenderingMode,
|
|
753
|
+
recordMessageOwnership,
|
|
754
|
+
canSendAgentActivity,
|
|
755
|
+
isSessionContextActive = () => true,
|
|
756
|
+
isTurnTransportActive,
|
|
757
|
+
updateStatus,
|
|
758
|
+
recordRuntimeEvent,
|
|
759
|
+
}: TelegramLifecycleBindingDeps): void {
|
|
760
|
+
const agentEndResetter = Runtime.createTelegramAgentEndResetter({
|
|
761
|
+
abort,
|
|
762
|
+
typing,
|
|
763
|
+
clearActiveTurn: activeTurnRuntime.clear,
|
|
764
|
+
resetToolExecutions: lifecycle.resetActiveToolExecutions,
|
|
765
|
+
clearPendingModelSwitch: modelSwitchController.clearPendingSwitch,
|
|
766
|
+
clearDispatchPending: lifecycle.clearDispatchPending,
|
|
767
|
+
});
|
|
768
|
+
const queuedAttachmentSender =
|
|
769
|
+
OutboundAttachments.createTelegramQueuedOutboundAttachmentSender({
|
|
770
|
+
sendMultipart: callMultipart,
|
|
771
|
+
sendTextReply,
|
|
772
|
+
recordRuntimeEvent,
|
|
773
|
+
});
|
|
774
|
+
const richAttachmentSender =
|
|
775
|
+
OutboundAttachments.createTelegramRichOutboundAttachmentSender({
|
|
776
|
+
sendMultipart: callMultipart,
|
|
777
|
+
getRenderingMode: getAssistantRenderingMode,
|
|
778
|
+
recordOwnership: recordMessageOwnership,
|
|
779
|
+
recordRuntimeEvent,
|
|
780
|
+
});
|
|
781
|
+
const sendGuestAttachment = async (
|
|
782
|
+
turn: Queue.PendingTelegramTurn,
|
|
783
|
+
attachment: Queue.QueuedAttachment,
|
|
784
|
+
caption?: string,
|
|
785
|
+
): Promise<void> => {
|
|
786
|
+
const stagingTarget = proactivePushTargetGetter();
|
|
787
|
+
const stagingChatId = stagingTarget?.chatId;
|
|
788
|
+
if (stagingChatId === undefined) {
|
|
789
|
+
throw new Error(
|
|
790
|
+
"Guest attachment staging requires a paired Telegram chat",
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
await OutboundAttachments.deliverTelegramGuestCachedAttachment({
|
|
794
|
+
guestQueryId: turn.guestQueryId!,
|
|
795
|
+
stagingChatId,
|
|
796
|
+
stagingTarget,
|
|
797
|
+
attachment,
|
|
798
|
+
caption,
|
|
799
|
+
sendMultipart: callMultipart,
|
|
800
|
+
answerGuestQuery: (guestQueryId, result) =>
|
|
801
|
+
answerGuestQuery(guestQueryId, undefined, { result }),
|
|
802
|
+
answerGuestText: (guestQueryId, text) =>
|
|
803
|
+
answerGuestQuery(guestQueryId, text),
|
|
804
|
+
fallbackText:
|
|
805
|
+
caption ||
|
|
806
|
+
"Telegram bridge could not deliver the requested attachment.",
|
|
807
|
+
deleteMessage,
|
|
808
|
+
recordRuntimeEvent,
|
|
809
|
+
});
|
|
810
|
+
};
|
|
811
|
+
const outboundReplyPlanner =
|
|
812
|
+
OutboundHandlers.createTelegramOutboundReplyPlanner(buttonActionStore);
|
|
813
|
+
const voiceReplySenderDeps = {
|
|
814
|
+
execCommand: CommandTemplates.execCommandTemplate,
|
|
815
|
+
sendMultipart: callMultipart,
|
|
816
|
+
sendTextReply,
|
|
817
|
+
sendChatAction,
|
|
818
|
+
sendRecordVoiceAction,
|
|
819
|
+
getHandlers: configStore.getOutboundHandlers,
|
|
820
|
+
recordRuntimeEvent,
|
|
821
|
+
};
|
|
822
|
+
const outboundReplyArtifactSender =
|
|
823
|
+
OutboundHandlers.createTelegramOutboundReplyArtifactSender(
|
|
824
|
+
voiceReplySenderDeps,
|
|
825
|
+
);
|
|
826
|
+
const sendGuestVoiceReply = async (
|
|
827
|
+
turn: Queue.PendingTelegramTurn,
|
|
828
|
+
plan: OutboundHandlers.TelegramOutboundReplyPlan,
|
|
829
|
+
caption?: string,
|
|
830
|
+
): Promise<void> => {
|
|
831
|
+
const stagingTarget = proactivePushTargetGetter();
|
|
832
|
+
const stagingChatId = stagingTarget?.chatId;
|
|
833
|
+
if (stagingChatId === undefined) {
|
|
834
|
+
throw new Error("Guest voice staging requires a paired Telegram chat");
|
|
835
|
+
}
|
|
836
|
+
const guestVoiceSender =
|
|
837
|
+
OutboundHandlers.createTelegramOutboundReplyArtifactSender({
|
|
838
|
+
...voiceReplySenderDeps,
|
|
839
|
+
sendChatAction: undefined,
|
|
840
|
+
sendRecordVoiceAction: undefined,
|
|
841
|
+
sendMultipart: async (
|
|
842
|
+
_method,
|
|
843
|
+
_fields,
|
|
844
|
+
_fileField,
|
|
845
|
+
filePath,
|
|
846
|
+
fileName,
|
|
847
|
+
) => {
|
|
848
|
+
try {
|
|
849
|
+
await OutboundAttachments.deliverTelegramGuestCachedAttachment({
|
|
850
|
+
guestQueryId: turn.guestQueryId!,
|
|
851
|
+
stagingChatId,
|
|
852
|
+
stagingTarget,
|
|
853
|
+
attachment: { path: filePath, fileName },
|
|
854
|
+
caption,
|
|
855
|
+
sendMultipart: callMultipart,
|
|
856
|
+
answerGuestQuery: (guestQueryId, result) =>
|
|
857
|
+
answerGuestQuery(guestQueryId, undefined, { result }),
|
|
858
|
+
answerGuestText: (guestQueryId, text) =>
|
|
859
|
+
answerGuestQuery(guestQueryId, text),
|
|
860
|
+
fallbackText:
|
|
861
|
+
caption || "Telegram bridge could not deliver the voice reply.",
|
|
862
|
+
deleteMessage,
|
|
863
|
+
recordRuntimeEvent,
|
|
864
|
+
});
|
|
865
|
+
} catch (error) {
|
|
866
|
+
recordRuntimeEvent("delivery", error, {
|
|
867
|
+
phase: "guest-voice-answer",
|
|
868
|
+
guestQueryId: turn.guestQueryId,
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
return {};
|
|
872
|
+
},
|
|
873
|
+
});
|
|
874
|
+
await guestVoiceSender(
|
|
875
|
+
turn,
|
|
876
|
+
{
|
|
877
|
+
...plan,
|
|
878
|
+
...(plan.voiceReplies?.length
|
|
879
|
+
? { voiceReplies: [plan.voiceReplies[0]!] }
|
|
880
|
+
: {}),
|
|
881
|
+
},
|
|
882
|
+
{ replyToPrompt: false },
|
|
883
|
+
);
|
|
884
|
+
};
|
|
885
|
+
const agentLifecycleHooks = Queue.createTelegramAgentLifecycleHooks<
|
|
886
|
+
Queue.PendingTelegramTurn,
|
|
887
|
+
Pi.ExtensionContext,
|
|
888
|
+
unknown,
|
|
889
|
+
Keyboard.TelegramInlineKeyboardMarkup
|
|
890
|
+
>({
|
|
891
|
+
setAbortHandler: Runtime.createTelegramContextAbortHandlerSetter(abort),
|
|
892
|
+
getQueuedItems: telegramQueueStore.getQueuedItems,
|
|
893
|
+
hasPendingDispatch: lifecycle.hasDispatchPending,
|
|
894
|
+
hasActiveTurn: activeTurnRuntime.has,
|
|
895
|
+
resetToolExecutions: lifecycle.resetActiveToolExecutions,
|
|
896
|
+
resetPendingModelSwitch: modelSwitchController.clearPendingSwitch,
|
|
897
|
+
setQueuedItems: telegramQueueStore.setQueuedItems,
|
|
898
|
+
clearDispatchPending: lifecycle.clearDispatchPending,
|
|
899
|
+
setFoldQueuedPromptsIntoHistory: lifecycle.setFoldQueuedPromptsIntoHistory,
|
|
900
|
+
setActiveTurn: activeTurnRuntime.set,
|
|
901
|
+
onPromptHandedOff,
|
|
902
|
+
createPreviewState: previewRuntime.resetState,
|
|
903
|
+
startTypingLoop: (ctx) => {
|
|
904
|
+
const turn = activeTurnRuntime.get();
|
|
905
|
+
promptDispatchRuntime.startTypingLoop(ctx, turn?.chatId, {
|
|
906
|
+
target: turn?.target,
|
|
907
|
+
});
|
|
908
|
+
},
|
|
909
|
+
updateStatus,
|
|
910
|
+
getActiveTurn: activeTurnRuntime.get,
|
|
911
|
+
loadConfig: configStore.load,
|
|
912
|
+
extractAssistant: Replies.extractLatestAssistantMessageText,
|
|
913
|
+
getFoldQueuedPromptsIntoHistory:
|
|
914
|
+
lifecycle.shouldFoldQueuedPromptsIntoHistory,
|
|
915
|
+
resetRuntimeState: agentEndResetter,
|
|
916
|
+
isSessionActive: isSessionContextActive,
|
|
917
|
+
isTurnTransportActive,
|
|
918
|
+
waitForTypingIdle: typing.waitForIdle,
|
|
919
|
+
async waitForActivityIdle() {
|
|
920
|
+
await activityVerbosityRuntime?.waitForIdle();
|
|
921
|
+
await assistantOutputRuntime.waitForIdle();
|
|
922
|
+
},
|
|
923
|
+
dispatchNextQueuedTelegramTurn,
|
|
924
|
+
requestDeferredDispatchNextQueuedTelegramTurn:
|
|
925
|
+
deferredQueueDispatchRuntime.request,
|
|
926
|
+
scheduleActiveTurnDelivery(task) {
|
|
927
|
+
const timer = setTimeout(() => {
|
|
928
|
+
void task().catch((error) => {
|
|
929
|
+
recordRuntimeEvent("delivery", error, {
|
|
930
|
+
phase: "agent-end-background-delivery",
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
}, 0);
|
|
934
|
+
timer.unref?.();
|
|
935
|
+
},
|
|
936
|
+
clearPreview: previewRuntime.clear,
|
|
937
|
+
setPreviewPendingText: previewRuntime.setPendingText,
|
|
938
|
+
finalizeMarkdownPreview,
|
|
939
|
+
sendMarkdownReply,
|
|
940
|
+
sendTextReply,
|
|
941
|
+
sendQueuedAttachments: queuedAttachmentSender,
|
|
942
|
+
sendRichAttachmentReply: richAttachmentSender,
|
|
943
|
+
answerGuestQuery,
|
|
944
|
+
sendGuestReply,
|
|
945
|
+
sendGuestAttachment,
|
|
946
|
+
sendGuestVoiceReply,
|
|
947
|
+
planOutboundReply: outboundReplyPlanner,
|
|
948
|
+
sendOutboundReplyArtifacts: outboundReplyArtifactSender,
|
|
949
|
+
recordRuntimeEvent,
|
|
950
|
+
getActiveToolExecutions: lifecycle.getActiveToolExecutions,
|
|
951
|
+
setActiveToolExecutions: lifecycle.setActiveToolExecutions,
|
|
952
|
+
triggerPendingModelSwitchAbort: modelSwitchController.triggerPendingAbort,
|
|
953
|
+
});
|
|
954
|
+
Lifecycle.setResetTransportReplyDedup(Replies.resetTransportReplyDedup);
|
|
955
|
+
const agentStartWithDedupReset = Lifecycle.createAgentStartDedupHook(
|
|
956
|
+
agentLifecycleHooks.onAgentStart,
|
|
957
|
+
);
|
|
958
|
+
const startAgentActivityTypingLoop = (ctx: Pi.ExtensionContext): boolean => {
|
|
959
|
+
if (!canSendAgentActivity(ctx)) return false;
|
|
960
|
+
const turn = activeTurnRuntime.get();
|
|
961
|
+
const target = turn?.target ?? proactivePushTargetGetter();
|
|
962
|
+
promptDispatchRuntime.startTypingLoop(ctx, turn?.chatId ?? target?.chatId, {
|
|
963
|
+
target,
|
|
964
|
+
});
|
|
965
|
+
return true;
|
|
966
|
+
};
|
|
967
|
+
const startActiveTurnTypingLoop = (ctx: Pi.ExtensionContext): void => {
|
|
968
|
+
const turn = activeTurnRuntime.get();
|
|
969
|
+
promptDispatchRuntime.startTypingLoop(ctx, turn?.chatId, {
|
|
970
|
+
target: turn?.target,
|
|
971
|
+
});
|
|
972
|
+
};
|
|
973
|
+
let observedAutomaticCompaction = false;
|
|
974
|
+
const sendCompactionNotice = async (text: string): Promise<void> => {
|
|
975
|
+
const turn = activeTurnRuntime.get();
|
|
976
|
+
const target = turn?.target ?? proactivePushTargetGetter?.();
|
|
977
|
+
if (!target) return;
|
|
978
|
+
try {
|
|
979
|
+
await sendMarkdownReply(target.chatId, turn?.replyToMessageId, text, {
|
|
980
|
+
target,
|
|
981
|
+
});
|
|
982
|
+
} catch (error) {
|
|
983
|
+
recordRuntimeEvent("delivery", error, {
|
|
984
|
+
phase: "compaction-notice",
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
const compactionObserver = Lifecycle.createTelegramCompactionObserverRuntime({
|
|
989
|
+
isContextActive: isSessionContextActive,
|
|
990
|
+
setCompactionInProgress: lifecycle.setCompactionInProgress,
|
|
991
|
+
updateStatus,
|
|
992
|
+
startTypingLoop: startAgentActivityTypingLoop,
|
|
993
|
+
stopTypingLoop: typing.stop,
|
|
994
|
+
requestDeferredDispatchNextQueuedTelegramTurn:
|
|
995
|
+
deferredQueueDispatchRuntime.request,
|
|
996
|
+
dispatchNextQueuedTelegramTurn,
|
|
997
|
+
recordRuntimeEvent,
|
|
998
|
+
onCompactionAbandoned: () => {
|
|
999
|
+
observedAutomaticCompaction = false;
|
|
1000
|
+
activityRuntime.onCompactionAbandoned();
|
|
1001
|
+
},
|
|
1002
|
+
});
|
|
1003
|
+
const messageActivityTypingHooks =
|
|
1004
|
+
Lifecycle.createTelegramMessageActivityTypingHooks({
|
|
1005
|
+
hasActiveTurn: activeTurnRuntime.has,
|
|
1006
|
+
startTypingLoop: startActiveTurnTypingLoop,
|
|
1007
|
+
onMessageStart: previewRuntime.onMessageStart,
|
|
1008
|
+
onMessageUpdate: previewRuntime.onMessageUpdate,
|
|
1009
|
+
recordRuntimeEvent,
|
|
1010
|
+
});
|
|
1011
|
+
const messageActivityHooks = messageActivityTypingHooks;
|
|
1012
|
+
Lifecycle.registerTelegramLifecycleHooks(pi, {
|
|
1013
|
+
isSessionActive: isSessionContextActive,
|
|
1014
|
+
...sessionLifecycleRuntime,
|
|
1015
|
+
...agentLifecycleHooks,
|
|
1016
|
+
onInput(event) {
|
|
1017
|
+
activityRuntime.recordInputSource(event.source ?? "unknown");
|
|
1018
|
+
},
|
|
1019
|
+
async onSessionStart(event, ctx) {
|
|
1020
|
+
previewRuntime.invalidate();
|
|
1021
|
+
assistantOutputRuntime.start();
|
|
1022
|
+
activityRuntime.onSessionStart?.();
|
|
1023
|
+
activityVerbosityRuntime?.reset();
|
|
1024
|
+
modelContextAvailabilityRuntime.reconcile();
|
|
1025
|
+
await sessionLifecycleRuntime.onSessionStart(event, ctx);
|
|
1026
|
+
},
|
|
1027
|
+
async onSessionShutdown(event, ctx) {
|
|
1028
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1029
|
+
agentLifecycleHooks.clearRetainedAgentEnd();
|
|
1030
|
+
activityRuntime.onSessionShutdown();
|
|
1031
|
+
activityVerbosityRuntime?.reset();
|
|
1032
|
+
assistantOutputRuntime.stop();
|
|
1033
|
+
observedAutomaticCompaction = false;
|
|
1034
|
+
compactionObserver.onSessionShutdown();
|
|
1035
|
+
if (event.reason === "quit" && disconnectOnQuit) {
|
|
1036
|
+
try {
|
|
1037
|
+
const automaticCleanupEnabled =
|
|
1038
|
+
(await resolveAutomaticThreadCleanupEnabled?.()) ?? true;
|
|
1039
|
+
if (automaticCleanupEnabled) await disconnectOnQuit();
|
|
1040
|
+
} catch (error) {
|
|
1041
|
+
recordRuntimeEvent("session", error, {
|
|
1042
|
+
phase: "automatic-disconnect-on-quit",
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
await sessionLifecycleRuntime.onSessionShutdown(event, ctx);
|
|
1047
|
+
},
|
|
1048
|
+
async onSessionBeforeCompact(event, ctx) {
|
|
1049
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1050
|
+
const shouldNotify = !(lifecycle.isCompactionInProgress?.() ?? false);
|
|
1051
|
+
if (shouldNotify) observedAutomaticCompaction = true;
|
|
1052
|
+
activityRuntime.onCompactionStart(Pi.getSessionCompactionReason(event));
|
|
1053
|
+
compactionObserver.onSessionBeforeCompact(event, ctx);
|
|
1054
|
+
if (shouldNotify) {
|
|
1055
|
+
await sendCompactionNotice(Commands.TELEGRAM_COMPACTION_STARTED_TEXT);
|
|
1056
|
+
}
|
|
1057
|
+
},
|
|
1058
|
+
async onSessionCompact(event, ctx) {
|
|
1059
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1060
|
+
activityRuntime.onCompactionEnd(Pi.getSessionCompactionReason(event));
|
|
1061
|
+
compactionObserver.onSessionCompact(event, ctx);
|
|
1062
|
+
if (observedAutomaticCompaction) {
|
|
1063
|
+
observedAutomaticCompaction = false;
|
|
1064
|
+
await sendCompactionNotice(Commands.TELEGRAM_COMPACTION_COMPLETED_TEXT);
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
async onAgentStart(event, ctx) {
|
|
1068
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1069
|
+
await agentStartWithDedupReset(event, ctx);
|
|
1070
|
+
activityRuntime.onAgentStart(activeTurnRuntime.get()?.target);
|
|
1071
|
+
startAgentActivityTypingLoop(ctx);
|
|
1072
|
+
},
|
|
1073
|
+
async onToolExecutionStart(event, ctx) {
|
|
1074
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1075
|
+
agentLifecycleHooks.onToolExecutionStart();
|
|
1076
|
+
activityRuntime.onToolStart({
|
|
1077
|
+
toolCallId: event.toolCallId,
|
|
1078
|
+
toolName: event.toolName,
|
|
1079
|
+
args: event.args,
|
|
1080
|
+
});
|
|
1081
|
+
},
|
|
1082
|
+
onToolExecutionUpdate(event, ctx) {
|
|
1083
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1084
|
+
activityRuntime.onToolUpdate({
|
|
1085
|
+
toolCallId: event.toolCallId,
|
|
1086
|
+
toolName: event.toolName,
|
|
1087
|
+
update: event.partialResult,
|
|
1088
|
+
});
|
|
1089
|
+
},
|
|
1090
|
+
async onToolExecutionEnd(event, ctx) {
|
|
1091
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1092
|
+
activityRuntime.onToolEnd({
|
|
1093
|
+
toolCallId: event.toolCallId,
|
|
1094
|
+
toolName: event.toolName,
|
|
1095
|
+
result: event.result,
|
|
1096
|
+
isError: event.isError,
|
|
1097
|
+
});
|
|
1098
|
+
agentLifecycleHooks.onToolExecutionEnd(event, ctx);
|
|
1099
|
+
},
|
|
1100
|
+
async onMessageStart(event, ctx) {
|
|
1101
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1102
|
+
await messageActivityHooks.onMessageStart(event, ctx);
|
|
1103
|
+
},
|
|
1104
|
+
async onMessageUpdate(event, ctx) {
|
|
1105
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1106
|
+
if (event.assistantMessageEvent) {
|
|
1107
|
+
activityRuntime.onAssistantEvent(
|
|
1108
|
+
event.assistantMessageEvent as Activity.TelegramAssistantStreamEvent,
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1111
|
+
await messageActivityHooks.onMessageUpdate(event, ctx);
|
|
1112
|
+
},
|
|
1113
|
+
async onAgentEnd(event, ctx) {
|
|
1114
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1115
|
+
activityRuntime.onAgentEnd();
|
|
1116
|
+
await agentLifecycleHooks.onAgentEnd(event, ctx);
|
|
1117
|
+
},
|
|
1118
|
+
async onAgentSettled(event, ctx) {
|
|
1119
|
+
if (!isSessionContextActive(ctx)) return;
|
|
1120
|
+
await agentLifecycleHooks.onAgentSettled(event, ctx);
|
|
1121
|
+
activityRuntime.onAgentSettled();
|
|
1122
|
+
modelContextAvailabilityRuntime.reconcile();
|
|
1123
|
+
},
|
|
1124
|
+
onBeforeAgentStart: Prompts.createTelegramProactiveBeforeAgentStartHook({
|
|
1125
|
+
reconcileAvailability: modelContextAvailabilityRuntime.reconcile,
|
|
1126
|
+
isAvailable: canSendAgentActivity,
|
|
1127
|
+
}),
|
|
1128
|
+
});
|
|
1129
|
+
}
|