@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,782 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram activity lifecycle normalization and extension dispatch
|
|
3
|
+
* Zones: pi agent lifecycle, extension API, operational delivery
|
|
4
|
+
* Owns stable handler registration, evidence-based activity/source identity, assistant segment and reasoning normalization, ordered public-output projection, executed-tool and compaction events, isolated non-blocking queues, shutdown fencing, diagnostics, and fresh delivery contexts; excludes Pi hook wiring, Telegram rendering implementation, raw transport clients, and consumer-extension behavior
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
deleteTelegramView,
|
|
9
|
+
editTelegramView,
|
|
10
|
+
sendTelegramChatAction,
|
|
11
|
+
sendTelegramView,
|
|
12
|
+
type TelegramDeliveryChatAction,
|
|
13
|
+
type TelegramDeliveryHandle,
|
|
14
|
+
type TelegramDeliveryResult,
|
|
15
|
+
type TelegramDeliveryScope,
|
|
16
|
+
type TelegramDeliveryTarget,
|
|
17
|
+
type TelegramDeliveryView,
|
|
18
|
+
} from "./delivery.ts";
|
|
19
|
+
|
|
20
|
+
const TELEGRAM_ACTIVITY_REGISTRY_KEY = "__piTelegramActivityRegistry__";
|
|
21
|
+
|
|
22
|
+
export type TelegramActivitySource =
|
|
23
|
+
| "telegram"
|
|
24
|
+
| "local"
|
|
25
|
+
| "autonomous"
|
|
26
|
+
| "unknown";
|
|
27
|
+
|
|
28
|
+
export type TelegramActivityTarget = Readonly<TelegramDeliveryTarget>;
|
|
29
|
+
|
|
30
|
+
export interface TelegramActivityEnvelope {
|
|
31
|
+
activityId: string;
|
|
32
|
+
sequence: number;
|
|
33
|
+
source: TelegramActivitySource;
|
|
34
|
+
target?: TelegramActivityTarget;
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TelegramActivityPayload =
|
|
39
|
+
| { type: "agent-start" }
|
|
40
|
+
| {
|
|
41
|
+
type: "assistant-text-delta";
|
|
42
|
+
contentIndex: number;
|
|
43
|
+
delta: string;
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
type: "assistant-segment";
|
|
47
|
+
contentIndex: number;
|
|
48
|
+
text: string;
|
|
49
|
+
placement: "intermediate" | "final" | "terminal-partial";
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
type: "reasoning-delta";
|
|
53
|
+
contentIndex: number;
|
|
54
|
+
delta: string;
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
type: "reasoning-end";
|
|
58
|
+
contentIndex: number;
|
|
59
|
+
text: string;
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
type: "tool-start";
|
|
63
|
+
toolCallId: string;
|
|
64
|
+
toolName: string;
|
|
65
|
+
args: unknown;
|
|
66
|
+
}
|
|
67
|
+
| {
|
|
68
|
+
type: "tool-update";
|
|
69
|
+
toolCallId: string;
|
|
70
|
+
toolName: string;
|
|
71
|
+
update: unknown;
|
|
72
|
+
}
|
|
73
|
+
| {
|
|
74
|
+
type: "tool-end";
|
|
75
|
+
toolCallId: string;
|
|
76
|
+
toolName: string;
|
|
77
|
+
result: unknown;
|
|
78
|
+
isError: boolean;
|
|
79
|
+
}
|
|
80
|
+
| {
|
|
81
|
+
type: "compaction-start";
|
|
82
|
+
reason: "manual" | "threshold" | "overflow" | "unknown";
|
|
83
|
+
}
|
|
84
|
+
| {
|
|
85
|
+
type: "compaction-end";
|
|
86
|
+
reason: "manual" | "threshold" | "overflow" | "unknown";
|
|
87
|
+
}
|
|
88
|
+
| { type: "agent-end" }
|
|
89
|
+
| { type: "agent-settled" };
|
|
90
|
+
|
|
91
|
+
export type TelegramActivityEvent = TelegramActivityEnvelope &
|
|
92
|
+
TelegramActivityPayload;
|
|
93
|
+
|
|
94
|
+
export type TelegramAssistantSegmentEvent = TelegramActivityEnvelope &
|
|
95
|
+
Extract<TelegramActivityPayload, { type: "assistant-segment" }>;
|
|
96
|
+
|
|
97
|
+
export interface TelegramActivityContext {
|
|
98
|
+
activityId: string;
|
|
99
|
+
sequence: number;
|
|
100
|
+
source: TelegramActivitySource;
|
|
101
|
+
defaultScope: TelegramDeliveryScope;
|
|
102
|
+
send: (
|
|
103
|
+
view: TelegramDeliveryView,
|
|
104
|
+
options?: {
|
|
105
|
+
scope?: TelegramDeliveryScope;
|
|
106
|
+
replyToMessageId?: number;
|
|
107
|
+
},
|
|
108
|
+
) => Promise<TelegramDeliveryResult<TelegramDeliveryHandle>>;
|
|
109
|
+
edit: (
|
|
110
|
+
handle: TelegramDeliveryHandle,
|
|
111
|
+
view: TelegramDeliveryView,
|
|
112
|
+
) => Promise<TelegramDeliveryResult<TelegramDeliveryHandle>>;
|
|
113
|
+
delete: (
|
|
114
|
+
handle: TelegramDeliveryHandle,
|
|
115
|
+
) => Promise<TelegramDeliveryResult<void>>;
|
|
116
|
+
chatAction: (
|
|
117
|
+
action: TelegramDeliveryChatAction,
|
|
118
|
+
options?: { scope?: TelegramDeliveryScope },
|
|
119
|
+
) => Promise<TelegramDeliveryResult<void>>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface TelegramActivityHandlerRegistration {
|
|
123
|
+
id: string;
|
|
124
|
+
order?: number;
|
|
125
|
+
handle: (
|
|
126
|
+
event: TelegramActivityEvent,
|
|
127
|
+
ctx: TelegramActivityContext,
|
|
128
|
+
) => void | Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface RegisteredTelegramActivityHandler
|
|
132
|
+
extends TelegramActivityHandlerRegistration {
|
|
133
|
+
id: string;
|
|
134
|
+
order: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface TelegramActivityRegistry {
|
|
138
|
+
handlers: Map<string, RegisteredTelegramActivityHandler>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getOrCreateTelegramActivityRegistry(): TelegramActivityRegistry {
|
|
142
|
+
const globals = globalThis as Record<string, unknown>;
|
|
143
|
+
const existing = globals[TELEGRAM_ACTIVITY_REGISTRY_KEY];
|
|
144
|
+
if (
|
|
145
|
+
existing &&
|
|
146
|
+
typeof existing === "object" &&
|
|
147
|
+
"handlers" in existing &&
|
|
148
|
+
existing.handlers instanceof Map
|
|
149
|
+
) {
|
|
150
|
+
return existing as TelegramActivityRegistry;
|
|
151
|
+
}
|
|
152
|
+
const registry: TelegramActivityRegistry = { handlers: new Map() };
|
|
153
|
+
globals[TELEGRAM_ACTIVITY_REGISTRY_KEY] = registry;
|
|
154
|
+
return registry;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function registerTelegramActivityHandler(
|
|
158
|
+
registration: TelegramActivityHandlerRegistration,
|
|
159
|
+
): () => void {
|
|
160
|
+
const id = registration.id.trim();
|
|
161
|
+
if (!id) throw new Error("Telegram activity handler id is required.");
|
|
162
|
+
const registry = getOrCreateTelegramActivityRegistry();
|
|
163
|
+
if (registry.handlers.has(id)) {
|
|
164
|
+
throw new Error(`Telegram activity handler is already registered: ${id}`);
|
|
165
|
+
}
|
|
166
|
+
const handler: RegisteredTelegramActivityHandler = {
|
|
167
|
+
...registration,
|
|
168
|
+
id,
|
|
169
|
+
order: registration.order ?? 0,
|
|
170
|
+
};
|
|
171
|
+
registry.handlers.set(id, handler);
|
|
172
|
+
return () => {
|
|
173
|
+
if (registry.handlers.get(id) === handler) registry.handlers.delete(id);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** @internal */
|
|
178
|
+
export function clearTelegramActivityHandlers(): void {
|
|
179
|
+
getOrCreateTelegramActivityRegistry().handlers.clear();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getTelegramActivityHandlers(): RegisteredTelegramActivityHandler[] {
|
|
183
|
+
return Array.from(
|
|
184
|
+
getOrCreateTelegramActivityRegistry().handlers.values(),
|
|
185
|
+
).sort(function (left, right) {
|
|
186
|
+
return left.order - right.order || left.id.localeCompare(right.id);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function cloneActivityTarget(
|
|
191
|
+
target: TelegramActivityTarget,
|
|
192
|
+
): TelegramActivityTarget {
|
|
193
|
+
return Object.freeze(
|
|
194
|
+
target.threadId === undefined
|
|
195
|
+
? { chatId: target.chatId }
|
|
196
|
+
: { chatId: target.chatId, threadId: target.threadId },
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function createTelegramActivityContext(
|
|
201
|
+
event: TelegramActivityEvent,
|
|
202
|
+
isActive: () => boolean,
|
|
203
|
+
): TelegramActivityContext {
|
|
204
|
+
const defaultScope: TelegramDeliveryScope = event.target
|
|
205
|
+
? { kind: "target", target: cloneActivityTarget(event.target) }
|
|
206
|
+
: event.source === "telegram"
|
|
207
|
+
? { kind: "active-turn" }
|
|
208
|
+
: { kind: "instance" };
|
|
209
|
+
const inactive = <T>(): Promise<TelegramDeliveryResult<T>> =>
|
|
210
|
+
Promise.resolve({
|
|
211
|
+
ok: false,
|
|
212
|
+
reason: "runtime-unavailable",
|
|
213
|
+
message: "Telegram activity context belongs to an inactive session.",
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
activityId: event.activityId,
|
|
217
|
+
sequence: event.sequence,
|
|
218
|
+
source: event.source,
|
|
219
|
+
defaultScope,
|
|
220
|
+
send(view, options) {
|
|
221
|
+
if (!isActive()) return inactive();
|
|
222
|
+
return sendTelegramView(view, {
|
|
223
|
+
scope: options?.scope ?? defaultScope,
|
|
224
|
+
replyToMessageId: options?.replyToMessageId,
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
edit(handle, view) {
|
|
228
|
+
return isActive() ? editTelegramView(handle, view) : inactive();
|
|
229
|
+
},
|
|
230
|
+
delete(handle) {
|
|
231
|
+
return isActive() ? deleteTelegramView(handle) : inactive();
|
|
232
|
+
},
|
|
233
|
+
chatAction(action, options) {
|
|
234
|
+
if (!isActive()) return inactive();
|
|
235
|
+
return sendTelegramChatAction(action, {
|
|
236
|
+
scope: options?.scope ?? defaultScope,
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface TelegramActivityHandlerQueue {
|
|
243
|
+
registration: RegisteredTelegramActivityHandler;
|
|
244
|
+
events: TelegramActivityEvent[];
|
|
245
|
+
running: boolean;
|
|
246
|
+
active: boolean;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function canCoalesceActivityEvents(
|
|
250
|
+
previous: TelegramActivityEvent,
|
|
251
|
+
next: TelegramActivityEvent,
|
|
252
|
+
): boolean {
|
|
253
|
+
if (
|
|
254
|
+
previous.activityId !== next.activityId ||
|
|
255
|
+
previous.type !== next.type
|
|
256
|
+
) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
if (
|
|
260
|
+
previous.type === "assistant-text-delta" &&
|
|
261
|
+
next.type === "assistant-text-delta"
|
|
262
|
+
) {
|
|
263
|
+
return previous.contentIndex === next.contentIndex;
|
|
264
|
+
}
|
|
265
|
+
if (
|
|
266
|
+
previous.type === "reasoning-delta" &&
|
|
267
|
+
next.type === "reasoning-delta"
|
|
268
|
+
) {
|
|
269
|
+
return previous.contentIndex === next.contentIndex;
|
|
270
|
+
}
|
|
271
|
+
if (previous.type === "tool-update" && next.type === "tool-update") {
|
|
272
|
+
return previous.toolCallId === next.toolCallId;
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function coalesceActivityEvents(
|
|
278
|
+
previous: TelegramActivityEvent,
|
|
279
|
+
next: TelegramActivityEvent,
|
|
280
|
+
): TelegramActivityEvent {
|
|
281
|
+
if (
|
|
282
|
+
previous.type === "assistant-text-delta" &&
|
|
283
|
+
next.type === "assistant-text-delta"
|
|
284
|
+
) {
|
|
285
|
+
return { ...next, delta: previous.delta + next.delta };
|
|
286
|
+
}
|
|
287
|
+
if (
|
|
288
|
+
previous.type === "reasoning-delta" &&
|
|
289
|
+
next.type === "reasoning-delta"
|
|
290
|
+
) {
|
|
291
|
+
return { ...next, delta: previous.delta + next.delta };
|
|
292
|
+
}
|
|
293
|
+
return next;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** @internal */
|
|
297
|
+
export interface TelegramActivityDispatcher {
|
|
298
|
+
dispatch: (event: TelegramActivityEvent) => void;
|
|
299
|
+
stop: () => void;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** @internal */
|
|
303
|
+
export function createTelegramActivityDispatcher(deps: {
|
|
304
|
+
recordFailure?: (
|
|
305
|
+
handlerId: string,
|
|
306
|
+
event: TelegramActivityEvent,
|
|
307
|
+
error: unknown,
|
|
308
|
+
) => void;
|
|
309
|
+
} = {}): TelegramActivityDispatcher {
|
|
310
|
+
const queues = new Map<string, TelegramActivityHandlerQueue>();
|
|
311
|
+
let stopped = false;
|
|
312
|
+
const drain = async (queue: TelegramActivityHandlerQueue): Promise<void> => {
|
|
313
|
+
if (queue.running || !queue.active) return;
|
|
314
|
+
queue.running = true;
|
|
315
|
+
try {
|
|
316
|
+
while (queue.active) {
|
|
317
|
+
const event = queue.events.shift();
|
|
318
|
+
if (!event) break;
|
|
319
|
+
if (
|
|
320
|
+
getOrCreateTelegramActivityRegistry().handlers.get(
|
|
321
|
+
queue.registration.id,
|
|
322
|
+
) !== queue.registration
|
|
323
|
+
) {
|
|
324
|
+
queue.active = false;
|
|
325
|
+
queue.events = [];
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
await queue.registration.handle(
|
|
330
|
+
event,
|
|
331
|
+
createTelegramActivityContext(event, () =>
|
|
332
|
+
queue.active &&
|
|
333
|
+
!stopped &&
|
|
334
|
+
getOrCreateTelegramActivityRegistry().handlers.get(
|
|
335
|
+
queue.registration.id,
|
|
336
|
+
) === queue.registration,
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
deps.recordFailure?.(queue.registration.id, event, error);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
} finally {
|
|
344
|
+
queue.running = false;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
dispatch(event) {
|
|
349
|
+
if (stopped) return;
|
|
350
|
+
for (const registration of getTelegramActivityHandlers()) {
|
|
351
|
+
let queue = queues.get(registration.id);
|
|
352
|
+
if (!queue || queue.registration !== registration) {
|
|
353
|
+
queue = {
|
|
354
|
+
registration,
|
|
355
|
+
events: [],
|
|
356
|
+
running: false,
|
|
357
|
+
active: true,
|
|
358
|
+
};
|
|
359
|
+
queues.set(registration.id, queue);
|
|
360
|
+
}
|
|
361
|
+
const previous = queue.events.at(-1);
|
|
362
|
+
if (previous && canCoalesceActivityEvents(previous, event)) {
|
|
363
|
+
queue.events[queue.events.length - 1] = coalesceActivityEvents(
|
|
364
|
+
previous,
|
|
365
|
+
event,
|
|
366
|
+
);
|
|
367
|
+
} else {
|
|
368
|
+
queue.events.push(event);
|
|
369
|
+
}
|
|
370
|
+
queueMicrotask(function () {
|
|
371
|
+
void drain(queue!);
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
stop() {
|
|
376
|
+
stopped = true;
|
|
377
|
+
for (const queue of queues.values()) {
|
|
378
|
+
queue.active = false;
|
|
379
|
+
queue.events = [];
|
|
380
|
+
}
|
|
381
|
+
queues.clear();
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** @internal */
|
|
387
|
+
export function createTelegramActivityBridgeRuntime(deps: {
|
|
388
|
+
generation: string;
|
|
389
|
+
observeEvent?: (event: TelegramActivityEvent) => void;
|
|
390
|
+
recordFailure?: (
|
|
391
|
+
handlerId: string,
|
|
392
|
+
event: TelegramActivityEvent,
|
|
393
|
+
error: unknown,
|
|
394
|
+
) => void;
|
|
395
|
+
now?: () => number;
|
|
396
|
+
}): TelegramActivityRuntime {
|
|
397
|
+
let generationSequence = 0;
|
|
398
|
+
let runtime: TelegramActivityRuntime | undefined;
|
|
399
|
+
const getRuntime = (): TelegramActivityRuntime | undefined => runtime;
|
|
400
|
+
return {
|
|
401
|
+
onSessionStart() {
|
|
402
|
+
runtime?.onSessionShutdown();
|
|
403
|
+
runtime = createTelegramActivityRuntime({
|
|
404
|
+
generation: `${deps.generation}:${++generationSequence}`,
|
|
405
|
+
dispatcher: createTelegramActivityDispatcher({
|
|
406
|
+
recordFailure: deps.recordFailure,
|
|
407
|
+
}),
|
|
408
|
+
observeEvent: deps.observeEvent,
|
|
409
|
+
recordObserverFailure: deps.recordFailure
|
|
410
|
+
? (event, error) =>
|
|
411
|
+
deps.recordFailure!("@llblab/pi-telegram/proactive", event, error)
|
|
412
|
+
: undefined,
|
|
413
|
+
now: deps.now,
|
|
414
|
+
});
|
|
415
|
+
},
|
|
416
|
+
recordInputSource(source) {
|
|
417
|
+
getRuntime()?.recordInputSource(source);
|
|
418
|
+
},
|
|
419
|
+
onAgentStart(target) {
|
|
420
|
+
getRuntime()?.onAgentStart(target);
|
|
421
|
+
},
|
|
422
|
+
onAssistantEvent(event) {
|
|
423
|
+
getRuntime()?.onAssistantEvent(event);
|
|
424
|
+
},
|
|
425
|
+
onToolStart(event) {
|
|
426
|
+
getRuntime()?.onToolStart(event);
|
|
427
|
+
},
|
|
428
|
+
onToolUpdate(event) {
|
|
429
|
+
getRuntime()?.onToolUpdate(event);
|
|
430
|
+
},
|
|
431
|
+
onToolEnd(event) {
|
|
432
|
+
getRuntime()?.onToolEnd(event);
|
|
433
|
+
},
|
|
434
|
+
onCompactionStart(reason) {
|
|
435
|
+
getRuntime()?.onCompactionStart(reason);
|
|
436
|
+
},
|
|
437
|
+
onCompactionEnd(reason) {
|
|
438
|
+
getRuntime()?.onCompactionEnd(reason);
|
|
439
|
+
},
|
|
440
|
+
onCompactionAbandoned() {
|
|
441
|
+
getRuntime()?.onCompactionAbandoned();
|
|
442
|
+
},
|
|
443
|
+
onAgentEnd() {
|
|
444
|
+
getRuntime()?.onAgentEnd();
|
|
445
|
+
},
|
|
446
|
+
onAgentSettled() {
|
|
447
|
+
getRuntime()?.onAgentSettled();
|
|
448
|
+
},
|
|
449
|
+
onSessionShutdown() {
|
|
450
|
+
runtime?.onSessionShutdown();
|
|
451
|
+
runtime = undefined;
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export type TelegramActivityInputSource =
|
|
457
|
+
| "interactive"
|
|
458
|
+
| "rpc"
|
|
459
|
+
| "extension"
|
|
460
|
+
| "unknown";
|
|
461
|
+
|
|
462
|
+
export type TelegramAssistantStreamEvent =
|
|
463
|
+
| { type: "start" }
|
|
464
|
+
| { type: "text_start"; contentIndex: number }
|
|
465
|
+
| { type: "text_delta"; contentIndex: number; delta: string }
|
|
466
|
+
| { type: "text_end"; contentIndex: number; content: string }
|
|
467
|
+
| { type: "thinking_delta"; contentIndex: number; delta: string }
|
|
468
|
+
| { type: "thinking_end"; contentIndex: number; content: string }
|
|
469
|
+
| { type: "thinking_start"; contentIndex: number }
|
|
470
|
+
| { type: "toolcall_start"; contentIndex: number }
|
|
471
|
+
| { type: "toolcall_delta"; contentIndex: number; delta: string }
|
|
472
|
+
| { type: "toolcall_end"; contentIndex: number }
|
|
473
|
+
| { type: "done" }
|
|
474
|
+
| { type: "error" };
|
|
475
|
+
|
|
476
|
+
/** @internal */
|
|
477
|
+
export interface TelegramActivityRuntime {
|
|
478
|
+
onSessionStart?: () => void;
|
|
479
|
+
recordInputSource: (source: TelegramActivityInputSource) => void;
|
|
480
|
+
onAgentStart: (activeTelegramTarget?: TelegramActivityTarget) => void;
|
|
481
|
+
onAssistantEvent: (event: TelegramAssistantStreamEvent) => void;
|
|
482
|
+
onToolStart: (event: {
|
|
483
|
+
toolCallId: string;
|
|
484
|
+
toolName: string;
|
|
485
|
+
args: unknown;
|
|
486
|
+
}) => void;
|
|
487
|
+
onToolUpdate: (event: {
|
|
488
|
+
toolCallId: string;
|
|
489
|
+
toolName: string;
|
|
490
|
+
update: unknown;
|
|
491
|
+
}) => void;
|
|
492
|
+
onToolEnd: (event: {
|
|
493
|
+
toolCallId: string;
|
|
494
|
+
toolName: string;
|
|
495
|
+
result: unknown;
|
|
496
|
+
isError: boolean;
|
|
497
|
+
}) => void;
|
|
498
|
+
onCompactionStart: (
|
|
499
|
+
reason: "manual" | "threshold" | "overflow" | "unknown",
|
|
500
|
+
) => void;
|
|
501
|
+
onCompactionEnd: (
|
|
502
|
+
reason: "manual" | "threshold" | "overflow" | "unknown",
|
|
503
|
+
) => void;
|
|
504
|
+
onCompactionAbandoned: () => void;
|
|
505
|
+
onAgentEnd: () => void;
|
|
506
|
+
onAgentSettled: () => void;
|
|
507
|
+
onSessionShutdown: () => void;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
interface PendingAssistantSegment {
|
|
511
|
+
contentIndex: number;
|
|
512
|
+
text: string;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** @internal */
|
|
516
|
+
export function createTelegramActivityRuntime(deps: {
|
|
517
|
+
generation: string;
|
|
518
|
+
dispatcher: TelegramActivityDispatcher;
|
|
519
|
+
observeEvent?: (event: TelegramActivityEvent) => void;
|
|
520
|
+
recordObserverFailure?: (
|
|
521
|
+
event: TelegramActivityEvent,
|
|
522
|
+
error: unknown,
|
|
523
|
+
) => void;
|
|
524
|
+
now?: () => number;
|
|
525
|
+
}): TelegramActivityRuntime {
|
|
526
|
+
const now = deps.now ?? Date.now;
|
|
527
|
+
let nextActivityNumber = 0;
|
|
528
|
+
let activityId: string | undefined;
|
|
529
|
+
let activitySource: TelegramActivitySource = "unknown";
|
|
530
|
+
let activityTarget: TelegramActivityTarget | undefined;
|
|
531
|
+
let sequence = 0;
|
|
532
|
+
let pendingInputSource: TelegramActivityInputSource = "unknown";
|
|
533
|
+
let pendingAssistantSegment: PendingAssistantSegment | undefined;
|
|
534
|
+
let compactionInProgress = false;
|
|
535
|
+
let compactionOwnedActivity = false;
|
|
536
|
+
const ensureActivity = (
|
|
537
|
+
activeTelegramTarget?: TelegramActivityTarget,
|
|
538
|
+
): string => {
|
|
539
|
+
if (activityId) return activityId;
|
|
540
|
+
nextActivityNumber += 1;
|
|
541
|
+
activityId = `${deps.generation}:${nextActivityNumber}`;
|
|
542
|
+
activitySource = activeTelegramTarget
|
|
543
|
+
? "telegram"
|
|
544
|
+
: pendingInputSource === "interactive" || pendingInputSource === "rpc"
|
|
545
|
+
? "local"
|
|
546
|
+
: pendingInputSource === "extension"
|
|
547
|
+
? "autonomous"
|
|
548
|
+
: "unknown";
|
|
549
|
+
activityTarget = activeTelegramTarget
|
|
550
|
+
? cloneActivityTarget(activeTelegramTarget)
|
|
551
|
+
: undefined;
|
|
552
|
+
sequence = 0;
|
|
553
|
+
pendingInputSource = "unknown";
|
|
554
|
+
return activityId;
|
|
555
|
+
};
|
|
556
|
+
const emit = (event: TelegramActivityPayload): void => {
|
|
557
|
+
const currentActivityId = ensureActivity();
|
|
558
|
+
sequence += 1;
|
|
559
|
+
const normalizedEvent = {
|
|
560
|
+
...event,
|
|
561
|
+
activityId: currentActivityId,
|
|
562
|
+
sequence,
|
|
563
|
+
source: activitySource,
|
|
564
|
+
...(activityTarget ? { target: activityTarget } : {}),
|
|
565
|
+
timestamp: now(),
|
|
566
|
+
} as TelegramActivityEvent;
|
|
567
|
+
try {
|
|
568
|
+
deps.observeEvent?.(normalizedEvent);
|
|
569
|
+
} catch (error) {
|
|
570
|
+
deps.recordObserverFailure?.(normalizedEvent, error);
|
|
571
|
+
}
|
|
572
|
+
deps.dispatcher.dispatch(normalizedEvent);
|
|
573
|
+
};
|
|
574
|
+
const flushPendingSegment = (
|
|
575
|
+
placement: "intermediate" | "final" | "terminal-partial",
|
|
576
|
+
): void => {
|
|
577
|
+
const segment = pendingAssistantSegment;
|
|
578
|
+
pendingAssistantSegment = undefined;
|
|
579
|
+
if (!segment?.text.trim()) return;
|
|
580
|
+
emit({
|
|
581
|
+
type: "assistant-segment",
|
|
582
|
+
contentIndex: segment.contentIndex,
|
|
583
|
+
text: segment.text,
|
|
584
|
+
placement,
|
|
585
|
+
});
|
|
586
|
+
};
|
|
587
|
+
const clearActivity = (): void => {
|
|
588
|
+
activityId = undefined;
|
|
589
|
+
activitySource = "unknown";
|
|
590
|
+
activityTarget = undefined;
|
|
591
|
+
sequence = 0;
|
|
592
|
+
pendingAssistantSegment = undefined;
|
|
593
|
+
compactionInProgress = false;
|
|
594
|
+
compactionOwnedActivity = false;
|
|
595
|
+
};
|
|
596
|
+
const abandonCompaction = (): void => {
|
|
597
|
+
if (!compactionInProgress) return;
|
|
598
|
+
const shouldClearActivity = compactionOwnedActivity;
|
|
599
|
+
compactionInProgress = false;
|
|
600
|
+
compactionOwnedActivity = false;
|
|
601
|
+
if (shouldClearActivity) clearActivity();
|
|
602
|
+
};
|
|
603
|
+
return {
|
|
604
|
+
recordInputSource(source) {
|
|
605
|
+
pendingInputSource = source;
|
|
606
|
+
},
|
|
607
|
+
onAgentStart(activeTelegramTarget) {
|
|
608
|
+
abandonCompaction();
|
|
609
|
+
ensureActivity(activeTelegramTarget);
|
|
610
|
+
emit({ type: "agent-start" });
|
|
611
|
+
},
|
|
612
|
+
onAssistantEvent(event) {
|
|
613
|
+
if (event.type === "text_start") {
|
|
614
|
+
flushPendingSegment("intermediate");
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (event.type === "text_delta") {
|
|
618
|
+
if (!event.delta) return;
|
|
619
|
+
emit({
|
|
620
|
+
type: "assistant-text-delta",
|
|
621
|
+
contentIndex: event.contentIndex,
|
|
622
|
+
delta: event.delta,
|
|
623
|
+
});
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (event.type === "text_end") {
|
|
627
|
+
pendingAssistantSegment = {
|
|
628
|
+
contentIndex: event.contentIndex,
|
|
629
|
+
text: event.content,
|
|
630
|
+
};
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (event.type === "thinking_delta") {
|
|
634
|
+
if (!event.delta) return;
|
|
635
|
+
emit({
|
|
636
|
+
type: "reasoning-delta",
|
|
637
|
+
contentIndex: event.contentIndex,
|
|
638
|
+
delta: event.delta,
|
|
639
|
+
});
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (event.type === "thinking_end") {
|
|
643
|
+
if (!event.content.trim()) return;
|
|
644
|
+
emit({
|
|
645
|
+
type: "reasoning-end",
|
|
646
|
+
contentIndex: event.contentIndex,
|
|
647
|
+
text: event.content,
|
|
648
|
+
});
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (event.type === "toolcall_start") {
|
|
652
|
+
flushPendingSegment("intermediate");
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (event.type === "done") {
|
|
656
|
+
flushPendingSegment("final");
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (event.type === "error") flushPendingSegment("terminal-partial");
|
|
660
|
+
},
|
|
661
|
+
onToolStart(event) {
|
|
662
|
+
emit({ type: "tool-start", ...event });
|
|
663
|
+
},
|
|
664
|
+
onToolUpdate(event) {
|
|
665
|
+
emit({ type: "tool-update", ...event });
|
|
666
|
+
},
|
|
667
|
+
onToolEnd(event) {
|
|
668
|
+
emit({ type: "tool-end", ...event });
|
|
669
|
+
},
|
|
670
|
+
onCompactionStart(reason) {
|
|
671
|
+
abandonCompaction();
|
|
672
|
+
compactionOwnedActivity = !activityId;
|
|
673
|
+
compactionInProgress = true;
|
|
674
|
+
ensureActivity();
|
|
675
|
+
emit({ type: "compaction-start", reason });
|
|
676
|
+
},
|
|
677
|
+
onCompactionEnd(reason) {
|
|
678
|
+
if (!compactionInProgress || !activityId) return;
|
|
679
|
+
const shouldClearActivity = compactionOwnedActivity;
|
|
680
|
+
compactionInProgress = false;
|
|
681
|
+
compactionOwnedActivity = false;
|
|
682
|
+
emit({ type: "compaction-end", reason });
|
|
683
|
+
if (shouldClearActivity) clearActivity();
|
|
684
|
+
},
|
|
685
|
+
onCompactionAbandoned() {
|
|
686
|
+
abandonCompaction();
|
|
687
|
+
},
|
|
688
|
+
onAgentEnd() {
|
|
689
|
+
if (activityId) emit({ type: "agent-end" });
|
|
690
|
+
},
|
|
691
|
+
onAgentSettled() {
|
|
692
|
+
if (!activityId) return;
|
|
693
|
+
flushPendingSegment("terminal-partial");
|
|
694
|
+
emit({ type: "agent-settled" });
|
|
695
|
+
clearActivity();
|
|
696
|
+
},
|
|
697
|
+
onSessionShutdown() {
|
|
698
|
+
pendingInputSource = "unknown";
|
|
699
|
+
clearActivity();
|
|
700
|
+
deps.dispatcher.stop();
|
|
701
|
+
},
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// --- Public Assistant Output Projection ---
|
|
706
|
+
|
|
707
|
+
export interface TelegramAssistantOutputRuntime {
|
|
708
|
+
start: () => void;
|
|
709
|
+
accept: (event: TelegramAssistantSegmentEvent) => void;
|
|
710
|
+
waitForIdle: () => Promise<void>;
|
|
711
|
+
stop: () => void;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export function createTelegramAssistantOutputRuntime<TAuthority = undefined>(deps: {
|
|
715
|
+
isEnabled: () => boolean;
|
|
716
|
+
captureAuthority?: () => TAuthority;
|
|
717
|
+
isAuthorityActive?: (authority: TAuthority) => boolean;
|
|
718
|
+
canDeliver: (event: TelegramAssistantSegmentEvent) => boolean;
|
|
719
|
+
send: (
|
|
720
|
+
event: TelegramAssistantSegmentEvent,
|
|
721
|
+
authority: TAuthority,
|
|
722
|
+
isAuthorityActive: () => boolean,
|
|
723
|
+
) => Promise<void>;
|
|
724
|
+
recordFailure?: (
|
|
725
|
+
event: TelegramAssistantSegmentEvent,
|
|
726
|
+
error: unknown,
|
|
727
|
+
) => void;
|
|
728
|
+
}): TelegramAssistantOutputRuntime {
|
|
729
|
+
let generation = 0;
|
|
730
|
+
let running = false;
|
|
731
|
+
let tail: Promise<void> = Promise.resolve();
|
|
732
|
+
const admitted = new Set<string>();
|
|
733
|
+
const isEligibleEvent = (event: TelegramAssistantSegmentEvent): boolean =>
|
|
734
|
+
(event.source === "telegram" && event.placement === "intermediate") ||
|
|
735
|
+
((event.source === "local" ||
|
|
736
|
+
event.source === "autonomous" ||
|
|
737
|
+
event.source === "unknown") &&
|
|
738
|
+
deps.isEnabled());
|
|
739
|
+
|
|
740
|
+
return {
|
|
741
|
+
start() {
|
|
742
|
+
generation += 1;
|
|
743
|
+
running = true;
|
|
744
|
+
admitted.clear();
|
|
745
|
+
tail = Promise.resolve();
|
|
746
|
+
},
|
|
747
|
+
accept(event) {
|
|
748
|
+
if (!running || !isEligibleEvent(event) || !event.text.trim()) return;
|
|
749
|
+
const key = `${event.activityId}:${event.sequence}`;
|
|
750
|
+
if (admitted.has(key)) return;
|
|
751
|
+
admitted.add(key);
|
|
752
|
+
const admittedGeneration = generation;
|
|
753
|
+
const admittedAuthority = deps.captureAuthority?.();
|
|
754
|
+
tail = tail.then(async () => {
|
|
755
|
+
const isAdmittedAuthorityActive = () =>
|
|
756
|
+
running &&
|
|
757
|
+
generation === admittedGeneration &&
|
|
758
|
+
isEligibleEvent(event) &&
|
|
759
|
+
(deps.isAuthorityActive === undefined ||
|
|
760
|
+
deps.isAuthorityActive(admittedAuthority as TAuthority));
|
|
761
|
+
if (!isAdmittedAuthorityActive() || !deps.canDeliver(event)) return;
|
|
762
|
+
try {
|
|
763
|
+
await deps.send(
|
|
764
|
+
event,
|
|
765
|
+
admittedAuthority as TAuthority,
|
|
766
|
+
isAdmittedAuthorityActive,
|
|
767
|
+
);
|
|
768
|
+
} catch (error) {
|
|
769
|
+
deps.recordFailure?.(event, error);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
},
|
|
773
|
+
waitForIdle() {
|
|
774
|
+
return tail;
|
|
775
|
+
},
|
|
776
|
+
stop() {
|
|
777
|
+
generation += 1;
|
|
778
|
+
running = false;
|
|
779
|
+
admitted.clear();
|
|
780
|
+
},
|
|
781
|
+
};
|
|
782
|
+
}
|