@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,981 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram outbound attachment helpers
|
|
3
|
+
* Zones: telegram outbound, pi agent tool, filesystem
|
|
4
|
+
* Owns telegram_attach registration, outbound attachment queueing, and delivery so Telegram file output stays in one domain module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { stat } from "node:fs/promises";
|
|
8
|
+
import { basename } from "node:path";
|
|
9
|
+
|
|
10
|
+
import { Type } from "@sinclair/typebox";
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
TelegramBusAgentMessage,
|
|
14
|
+
TelegramBusAgentTargetSelector,
|
|
15
|
+
} from "./bus.ts";
|
|
16
|
+
import type { ExtensionAPI } from "./pi.ts";
|
|
17
|
+
import {
|
|
18
|
+
TELEGRAM_ATTACH_PROMPT_GUIDELINES,
|
|
19
|
+
TELEGRAM_ATTACH_PROMPT_SNIPPET,
|
|
20
|
+
TELEGRAM_MESSAGE_PROMPT_GUIDELINES,
|
|
21
|
+
TELEGRAM_MESSAGE_PROMPT_SNIPPET,
|
|
22
|
+
} from "./prompts.ts";
|
|
23
|
+
import {
|
|
24
|
+
buildTelegramMultipartReplyParameters,
|
|
25
|
+
normalizeTelegramNativeMarkdown,
|
|
26
|
+
} from "./replies.ts";
|
|
27
|
+
import {
|
|
28
|
+
getTelegramTargetThreadParams,
|
|
29
|
+
type TelegramTarget,
|
|
30
|
+
} from "./target.ts";
|
|
31
|
+
|
|
32
|
+
const MAX_ATTACHMENTS_PER_TURN = 10;
|
|
33
|
+
|
|
34
|
+
export const TELEGRAM_OUTBOUND_ATTACHMENT_DEFAULT_MAX_BYTES = 50 * 1024 * 1024;
|
|
35
|
+
|
|
36
|
+
export function getTelegramOutboundAttachmentByteLimitFromEnv(
|
|
37
|
+
env: NodeJS.ProcessEnv,
|
|
38
|
+
names: string[],
|
|
39
|
+
defaultValue = TELEGRAM_OUTBOUND_ATTACHMENT_DEFAULT_MAX_BYTES,
|
|
40
|
+
): number {
|
|
41
|
+
for (const name of names) {
|
|
42
|
+
const rawValue = env[name]?.trim();
|
|
43
|
+
if (!rawValue) continue;
|
|
44
|
+
const parsed = Number(rawValue);
|
|
45
|
+
if (Number.isSafeInteger(parsed) && parsed > 0) return parsed;
|
|
46
|
+
}
|
|
47
|
+
return defaultValue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const TELEGRAM_OUTBOUND_ATTACHMENT_MAX_BYTES =
|
|
51
|
+
getTelegramOutboundAttachmentByteLimitFromEnv(process.env, [
|
|
52
|
+
"PI_TELEGRAM_OUTBOUND_ATTACHMENT_MAX_BYTES",
|
|
53
|
+
"TELEGRAM_MAX_ATTACHMENT_SIZE_BYTES",
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
export interface TelegramOutboundAttachmentToolResult {
|
|
57
|
+
content: Array<{ type: "text"; text: string }>;
|
|
58
|
+
details: { paths: string[] };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface TelegramOutboundAttachmentRuntimeEventRecorderPort {
|
|
62
|
+
recordRuntimeEvent?: (
|
|
63
|
+
category: string,
|
|
64
|
+
error: unknown,
|
|
65
|
+
details?: Record<string, unknown>,
|
|
66
|
+
) => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface TelegramOutboundAttachmentToolRegistrationDeps extends TelegramOutboundAttachmentRuntimeEventRecorderPort {
|
|
70
|
+
maxAttachmentsPerTurn?: number;
|
|
71
|
+
maxAttachmentSizeBytes?: number;
|
|
72
|
+
getActiveTurn: () => TelegramOutboundAttachmentQueueTargetView | undefined;
|
|
73
|
+
getDefaultChatId?: () => number | undefined;
|
|
74
|
+
getDefaultTarget?: () => TelegramTarget | undefined;
|
|
75
|
+
canSendDirect?: () => boolean;
|
|
76
|
+
sendMultipart?: TelegramQueuedOutboundAttachmentDeliveryDeps["sendMultipart"];
|
|
77
|
+
statPath?: (path: string) => Promise<{ isFile(): boolean; size?: number }>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface TelegramOutboundMessagePlan {
|
|
81
|
+
markdown: string;
|
|
82
|
+
replyMarkup?: unknown;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface TelegramOutboundMessageToolRegistrationDeps extends TelegramOutboundAttachmentRuntimeEventRecorderPort {
|
|
86
|
+
getDefaultChatId: () => number | undefined;
|
|
87
|
+
getDefaultTarget?: () => TelegramTarget | undefined;
|
|
88
|
+
getActiveTurn?: () =>
|
|
89
|
+
| { chatId: number; target?: TelegramTarget }
|
|
90
|
+
| undefined;
|
|
91
|
+
resolveAgentTarget?: (
|
|
92
|
+
selector: TelegramBusAgentTargetSelector,
|
|
93
|
+
) => Promise<TelegramTarget & { threadId: number }>;
|
|
94
|
+
routeAgentMessage?: (message: TelegramBusAgentMessage) => Promise<void>;
|
|
95
|
+
canSendDirect: () => boolean;
|
|
96
|
+
planMessage: (markdown: string) => TelegramOutboundMessagePlan;
|
|
97
|
+
sendMarkdownMessage: (
|
|
98
|
+
chatId: number,
|
|
99
|
+
markdown: string,
|
|
100
|
+
options?: { replyMarkup?: unknown; target?: TelegramTarget },
|
|
101
|
+
) => Promise<number | undefined>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface TelegramQueuedOutboundAttachmentView {
|
|
105
|
+
path: string;
|
|
106
|
+
fileName: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface TelegramOutboundAttachmentQueueTargetView {
|
|
110
|
+
queuedAttachments: TelegramQueuedOutboundAttachmentView[];
|
|
111
|
+
guestQueryId?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface TelegramQueuedOutboundAttachmentTurnView extends TelegramOutboundAttachmentQueueTargetView {
|
|
115
|
+
chatId: number;
|
|
116
|
+
replyToMessageId: number;
|
|
117
|
+
target?: TelegramTarget;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
class TelegramRichAttachmentCommitUnknownError extends Error {
|
|
121
|
+
readonly kind = "commit-unknown" as const;
|
|
122
|
+
|
|
123
|
+
constructor(cause: unknown) {
|
|
124
|
+
super("Telegram Rich media upload may have committed without a message id.");
|
|
125
|
+
this.name = "TelegramRichAttachmentCommitUnknownError";
|
|
126
|
+
this.cause = cause;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function isTelegramRichAttachmentCommitUnknownError(error: unknown): boolean {
|
|
131
|
+
return (
|
|
132
|
+
error instanceof TelegramRichAttachmentCommitUnknownError ||
|
|
133
|
+
(typeof error === "object" &&
|
|
134
|
+
error !== null &&
|
|
135
|
+
(error as { kind?: unknown }).kind === "commit-unknown")
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface TelegramRichOutboundAttachmentPlan {
|
|
140
|
+
method: "sendRichMessage";
|
|
141
|
+
fields: Record<string, string>;
|
|
142
|
+
fileField: "rich_media_upload";
|
|
143
|
+
filePath: string;
|
|
144
|
+
fileName: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface TelegramRichOutboundAttachmentSenderDeps extends TelegramOutboundAttachmentRuntimeEventRecorderPort {
|
|
148
|
+
sendMultipart: TelegramQueuedOutboundAttachmentDeliveryDeps["sendMultipart"];
|
|
149
|
+
getRenderingMode: () => "rich" | "html";
|
|
150
|
+
recordOwnership?: (input: {
|
|
151
|
+
chatId: number;
|
|
152
|
+
messageId: number;
|
|
153
|
+
target?: TelegramTarget;
|
|
154
|
+
}) => void;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function planTelegramRichOutboundAttachment(options: {
|
|
158
|
+
turn: TelegramQueuedOutboundAttachmentTurnView;
|
|
159
|
+
markdown: string;
|
|
160
|
+
renderingMode: "rich" | "html";
|
|
161
|
+
replyMarkup?: unknown;
|
|
162
|
+
}): TelegramRichOutboundAttachmentPlan | undefined {
|
|
163
|
+
if (options.renderingMode !== "rich") return undefined;
|
|
164
|
+
if (!options.markdown.trim()) return undefined;
|
|
165
|
+
if (options.turn.queuedAttachments.length !== 1) return undefined;
|
|
166
|
+
const attachment = options.turn.queuedAttachments[0]!;
|
|
167
|
+
const normalizedPath = attachment.path.toLowerCase();
|
|
168
|
+
const mediaType = normalizedPath.endsWith(".jpg") ||
|
|
169
|
+
normalizedPath.endsWith(".jpeg") ||
|
|
170
|
+
normalizedPath.endsWith(".png")
|
|
171
|
+
? "photo"
|
|
172
|
+
: normalizedPath.endsWith(".mp4")
|
|
173
|
+
? "video"
|
|
174
|
+
: normalizedPath.endsWith(".mp3")
|
|
175
|
+
? "audio"
|
|
176
|
+
: undefined;
|
|
177
|
+
if (!mediaType) return undefined;
|
|
178
|
+
const mediaId = "artifact";
|
|
179
|
+
const richMessage = {
|
|
180
|
+
markdown: `${normalizeTelegramNativeMarkdown(options.markdown)}\n\n`,
|
|
181
|
+
media: [
|
|
182
|
+
{
|
|
183
|
+
id: mediaId,
|
|
184
|
+
media: {
|
|
185
|
+
type: mediaType,
|
|
186
|
+
media: "attach://rich_media_upload",
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
skip_entity_detection: true,
|
|
191
|
+
};
|
|
192
|
+
const replyParameters =
|
|
193
|
+
options.turn.replyToMessageId > 0
|
|
194
|
+
? JSON.stringify({
|
|
195
|
+
message_id: options.turn.replyToMessageId,
|
|
196
|
+
allow_sending_without_reply: true,
|
|
197
|
+
})
|
|
198
|
+
: undefined;
|
|
199
|
+
return {
|
|
200
|
+
method: "sendRichMessage",
|
|
201
|
+
fields: {
|
|
202
|
+
chat_id: String(options.turn.chatId),
|
|
203
|
+
...(replyParameters ? { reply_parameters: replyParameters } : {}),
|
|
204
|
+
...getTelegramMultipartTargetFields(options.turn.target),
|
|
205
|
+
rich_message: JSON.stringify(richMessage),
|
|
206
|
+
...(options.replyMarkup
|
|
207
|
+
? { reply_markup: JSON.stringify(options.replyMarkup) }
|
|
208
|
+
: {}),
|
|
209
|
+
},
|
|
210
|
+
fileField: "rich_media_upload",
|
|
211
|
+
filePath: attachment.path,
|
|
212
|
+
fileName: attachment.fileName,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function createTelegramRichOutboundAttachmentSender(
|
|
217
|
+
deps: TelegramRichOutboundAttachmentSenderDeps,
|
|
218
|
+
) {
|
|
219
|
+
return async (
|
|
220
|
+
turn: TelegramQueuedOutboundAttachmentTurnView,
|
|
221
|
+
markdown: string,
|
|
222
|
+
options?: { replyMarkup?: unknown },
|
|
223
|
+
): Promise<boolean> => {
|
|
224
|
+
const plan = planTelegramRichOutboundAttachment({
|
|
225
|
+
turn,
|
|
226
|
+
markdown,
|
|
227
|
+
renderingMode: deps.getRenderingMode(),
|
|
228
|
+
replyMarkup: options?.replyMarkup,
|
|
229
|
+
});
|
|
230
|
+
if (!plan) return false;
|
|
231
|
+
try {
|
|
232
|
+
const result = await deps.sendMultipart(
|
|
233
|
+
plan.method,
|
|
234
|
+
plan.fields,
|
|
235
|
+
plan.fileField,
|
|
236
|
+
plan.filePath,
|
|
237
|
+
plan.fileName,
|
|
238
|
+
);
|
|
239
|
+
const messageId =
|
|
240
|
+
result && typeof result === "object" &&
|
|
241
|
+
Number.isInteger((result as { message_id?: unknown }).message_id)
|
|
242
|
+
? (result as { message_id: number }).message_id
|
|
243
|
+
: undefined;
|
|
244
|
+
if (messageId === undefined) {
|
|
245
|
+
throw new TelegramRichAttachmentCommitUnknownError(
|
|
246
|
+
new Error("Successful Rich media upload omitted message_id."),
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
deps.recordOwnership?.({
|
|
250
|
+
chatId: turn.chatId,
|
|
251
|
+
messageId,
|
|
252
|
+
target: turn.target,
|
|
253
|
+
});
|
|
254
|
+
return true;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (isTelegramRichAttachmentCommitUnknownError(error)) throw error;
|
|
257
|
+
deps.recordRuntimeEvent?.("attachment", error, {
|
|
258
|
+
phase: "rich-media-known-failure",
|
|
259
|
+
fileName: plan.fileName,
|
|
260
|
+
});
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export type TelegramGuestCachedAttachmentResult =
|
|
267
|
+
| {
|
|
268
|
+
type: "document";
|
|
269
|
+
id: string;
|
|
270
|
+
title: string;
|
|
271
|
+
document_file_id: string;
|
|
272
|
+
caption?: string;
|
|
273
|
+
}
|
|
274
|
+
| {
|
|
275
|
+
type: "photo";
|
|
276
|
+
id: string;
|
|
277
|
+
photo_file_id: string;
|
|
278
|
+
caption?: string;
|
|
279
|
+
}
|
|
280
|
+
| {
|
|
281
|
+
type: "audio";
|
|
282
|
+
id: string;
|
|
283
|
+
audio_file_id: string;
|
|
284
|
+
caption?: string;
|
|
285
|
+
}
|
|
286
|
+
| {
|
|
287
|
+
type: "voice";
|
|
288
|
+
id: string;
|
|
289
|
+
voice_file_id: string;
|
|
290
|
+
title: string;
|
|
291
|
+
caption?: string;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
interface TelegramGuestStagingMessage {
|
|
295
|
+
message_id?: number;
|
|
296
|
+
document?: { file_id?: string };
|
|
297
|
+
photo?: Array<{ file_id?: string; file_size?: number }>;
|
|
298
|
+
audio?: { file_id?: string };
|
|
299
|
+
voice?: { file_id?: string };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function isTelegramOutboundPhotoAttachmentPath(path: string): boolean {
|
|
303
|
+
const normalized = path.toLowerCase();
|
|
304
|
+
return (
|
|
305
|
+
normalized.endsWith(".jpg") ||
|
|
306
|
+
normalized.endsWith(".jpeg") ||
|
|
307
|
+
normalized.endsWith(".png") ||
|
|
308
|
+
normalized.endsWith(".webp") ||
|
|
309
|
+
normalized.endsWith(".gif")
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function getTelegramGuestAttachmentTransport(path: string): {
|
|
314
|
+
method: "sendDocument" | "sendPhoto" | "sendAudio" | "sendVoice";
|
|
315
|
+
fileField: "document" | "photo" | "audio" | "voice";
|
|
316
|
+
} {
|
|
317
|
+
const normalized = path.toLowerCase();
|
|
318
|
+
if (
|
|
319
|
+
normalized.endsWith(".jpg") ||
|
|
320
|
+
normalized.endsWith(".jpeg") ||
|
|
321
|
+
normalized.endsWith(".png")
|
|
322
|
+
) {
|
|
323
|
+
return { method: "sendPhoto", fileField: "photo" };
|
|
324
|
+
}
|
|
325
|
+
if (normalized.endsWith(".ogg") || normalized.endsWith(".opus")) {
|
|
326
|
+
return { method: "sendVoice", fileField: "voice" };
|
|
327
|
+
}
|
|
328
|
+
if (normalized.endsWith(".mp3")) {
|
|
329
|
+
return { method: "sendAudio", fileField: "audio" };
|
|
330
|
+
}
|
|
331
|
+
return { method: "sendDocument", fileField: "document" };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function formatTelegramOutboundAttachmentSizeLimitError(
|
|
335
|
+
size: number,
|
|
336
|
+
maxSize: number,
|
|
337
|
+
path?: string,
|
|
338
|
+
): string {
|
|
339
|
+
const message = `Attachment exceeds size limit (${size} bytes > ${maxSize} bytes)`;
|
|
340
|
+
return path ? `${message}: ${path}` : message;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function formatTelegramOutboundAttachmentToolResultText(
|
|
344
|
+
count: number,
|
|
345
|
+
mode: "queued" | "sent" = "queued",
|
|
346
|
+
): string {
|
|
347
|
+
// Pi's compact tool rows need one leading newline to visually separate header and result.
|
|
348
|
+
const verb = mode === "queued" ? "Queued" : "Sent";
|
|
349
|
+
return ["", `${verb} ${count} Telegram attachment(s).`].join("\n");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function formatTelegramOutboundMessageToolResultText(chatId: number): string {
|
|
353
|
+
return ["", `Sent Telegram message to ${chatId}.`].join("\n");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function getTelegramMultipartTargetFields(
|
|
357
|
+
target: TelegramTarget | undefined,
|
|
358
|
+
): Record<string, string> {
|
|
359
|
+
if (!target) return {};
|
|
360
|
+
return Object.fromEntries(
|
|
361
|
+
Object.entries(getTelegramTargetThreadParams(target)).map(
|
|
362
|
+
([key, value]) => [key, String(value)],
|
|
363
|
+
),
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function assertTelegramDirectDeliveryAllowed(
|
|
368
|
+
canSendDirect: (() => boolean) | undefined,
|
|
369
|
+
): void {
|
|
370
|
+
if (canSendDirect?.()) return;
|
|
371
|
+
throw new Error(
|
|
372
|
+
"Telegram direct delivery requires this Pi instance to own /telegram-connect or be registered with the Telegram multi-instance bus",
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function resolveTelegramOutboundTarget(options: {
|
|
377
|
+
chatId?: number;
|
|
378
|
+
threadId?: number;
|
|
379
|
+
target?: TelegramTarget;
|
|
380
|
+
getDefaultChatId?: () => number | undefined;
|
|
381
|
+
getDefaultTarget?: () => TelegramTarget | undefined;
|
|
382
|
+
}): { chatId: number; target?: TelegramTarget } {
|
|
383
|
+
if (options.target)
|
|
384
|
+
return { chatId: options.target.chatId, target: options.target };
|
|
385
|
+
if (options.chatId !== undefined) {
|
|
386
|
+
return {
|
|
387
|
+
chatId: options.chatId,
|
|
388
|
+
target:
|
|
389
|
+
options.threadId !== undefined
|
|
390
|
+
? { chatId: options.chatId, threadId: options.threadId }
|
|
391
|
+
: undefined,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const defaultTarget = options.getDefaultTarget?.();
|
|
395
|
+
if (defaultTarget) {
|
|
396
|
+
return { chatId: defaultTarget.chatId, target: defaultTarget };
|
|
397
|
+
}
|
|
398
|
+
const defaultChatId = options.getDefaultChatId?.();
|
|
399
|
+
if (defaultChatId === undefined) {
|
|
400
|
+
throw new Error(
|
|
401
|
+
"Telegram chat_id is required when no paired/default Telegram chat is available",
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
return { chatId: defaultChatId };
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function buildTelegramOutboundAttachmentViews(options: {
|
|
408
|
+
paths: string[];
|
|
409
|
+
maxAttachmentSizeBytes?: number;
|
|
410
|
+
statPath?: (path: string) => Promise<{ isFile(): boolean; size?: number }>;
|
|
411
|
+
}): Promise<TelegramQueuedOutboundAttachmentView[]> {
|
|
412
|
+
const pendingAttachments: TelegramQueuedOutboundAttachmentView[] = [];
|
|
413
|
+
for (const inputPath of options.paths) {
|
|
414
|
+
const stats = await (options.statPath ?? stat)(inputPath);
|
|
415
|
+
if (!stats.isFile()) {
|
|
416
|
+
throw new Error(`Not a file: ${inputPath}`);
|
|
417
|
+
}
|
|
418
|
+
if (
|
|
419
|
+
options.maxAttachmentSizeBytes !== undefined &&
|
|
420
|
+
stats.size !== undefined &&
|
|
421
|
+
stats.size > options.maxAttachmentSizeBytes
|
|
422
|
+
) {
|
|
423
|
+
throw new Error(
|
|
424
|
+
formatTelegramOutboundAttachmentSizeLimitError(
|
|
425
|
+
stats.size,
|
|
426
|
+
options.maxAttachmentSizeBytes,
|
|
427
|
+
inputPath,
|
|
428
|
+
),
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
pendingAttachments.push({
|
|
432
|
+
path: inputPath,
|
|
433
|
+
fileName: basename(inputPath),
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
return pendingAttachments;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export function registerTelegramOutboundAttachmentTool(
|
|
440
|
+
pi: ExtensionAPI,
|
|
441
|
+
deps: TelegramOutboundAttachmentToolRegistrationDeps,
|
|
442
|
+
): void {
|
|
443
|
+
const maxAttachmentsPerTurn =
|
|
444
|
+
deps.maxAttachmentsPerTurn ?? MAX_ATTACHMENTS_PER_TURN;
|
|
445
|
+
const maxAttachmentSizeBytes =
|
|
446
|
+
deps.maxAttachmentSizeBytes ?? TELEGRAM_OUTBOUND_ATTACHMENT_MAX_BYTES;
|
|
447
|
+
pi.registerTool({
|
|
448
|
+
name: "telegram_attach",
|
|
449
|
+
label: "Telegram Attach",
|
|
450
|
+
description:
|
|
451
|
+
"Queue one or more local files for the active Telegram reply, or send them immediately to Telegram when no Telegram turn is active.",
|
|
452
|
+
promptSnippet: TELEGRAM_ATTACH_PROMPT_SNIPPET,
|
|
453
|
+
promptGuidelines: [...TELEGRAM_ATTACH_PROMPT_GUIDELINES],
|
|
454
|
+
parameters: Type.Object({
|
|
455
|
+
paths: Type.Array(
|
|
456
|
+
Type.String({ description: "Local file path to attach" }),
|
|
457
|
+
{ minItems: 1, maxItems: maxAttachmentsPerTurn },
|
|
458
|
+
),
|
|
459
|
+
chat_id: Type.Optional(
|
|
460
|
+
Type.Number({
|
|
461
|
+
description:
|
|
462
|
+
"Optional Telegram chat id for immediate delivery when no Telegram turn is active",
|
|
463
|
+
}),
|
|
464
|
+
),
|
|
465
|
+
thread_id: Type.Optional(
|
|
466
|
+
Type.Number({
|
|
467
|
+
description:
|
|
468
|
+
"Optional Telegram topic thread id for immediate delivery with chat_id",
|
|
469
|
+
}),
|
|
470
|
+
),
|
|
471
|
+
caption: Type.Optional(
|
|
472
|
+
Type.String({
|
|
473
|
+
description:
|
|
474
|
+
"Optional caption for immediate delivery; ignored when queued for an active turn",
|
|
475
|
+
}),
|
|
476
|
+
),
|
|
477
|
+
}),
|
|
478
|
+
async execute(_toolCallId, params) {
|
|
479
|
+
try {
|
|
480
|
+
return await queueTelegramOutboundAttachments({
|
|
481
|
+
activeTurn: deps.getActiveTurn(),
|
|
482
|
+
paths: params.paths,
|
|
483
|
+
chatId: params.chat_id,
|
|
484
|
+
threadId: params.thread_id,
|
|
485
|
+
caption: params.caption,
|
|
486
|
+
maxAttachmentsPerTurn,
|
|
487
|
+
maxAttachmentSizeBytes,
|
|
488
|
+
sendMultipart: deps.sendMultipart,
|
|
489
|
+
getDefaultChatId: deps.getDefaultChatId,
|
|
490
|
+
getDefaultTarget: deps.getDefaultTarget,
|
|
491
|
+
canSendDirect: deps.canSendDirect,
|
|
492
|
+
statPath: deps.statPath,
|
|
493
|
+
});
|
|
494
|
+
} catch (error) {
|
|
495
|
+
deps.recordRuntimeEvent?.("attachment", error, {
|
|
496
|
+
phase: "queue",
|
|
497
|
+
count: params.paths.length,
|
|
498
|
+
});
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export function registerTelegramOutboundMessageTool(
|
|
506
|
+
pi: ExtensionAPI,
|
|
507
|
+
deps: TelegramOutboundMessageToolRegistrationDeps,
|
|
508
|
+
): void {
|
|
509
|
+
pi.registerTool({
|
|
510
|
+
name: "telegram_message",
|
|
511
|
+
label: "Telegram Message",
|
|
512
|
+
description:
|
|
513
|
+
"Send a Markdown text message directly to the paired/default Telegram chat or an explicit chat_id. Hidden telegram_button comments in the text become attached inline prompt buttons.",
|
|
514
|
+
promptSnippet: TELEGRAM_MESSAGE_PROMPT_SNIPPET,
|
|
515
|
+
promptGuidelines: [...TELEGRAM_MESSAGE_PROMPT_GUIDELINES],
|
|
516
|
+
parameters: Type.Object({
|
|
517
|
+
text: Type.String({ description: "Message text to send" }),
|
|
518
|
+
chat_id: Type.Optional(
|
|
519
|
+
Type.Number({ description: "Optional Telegram chat id" }),
|
|
520
|
+
),
|
|
521
|
+
thread_id: Type.Optional(
|
|
522
|
+
Type.Number({
|
|
523
|
+
description: "Optional Telegram topic thread id with chat_id",
|
|
524
|
+
}),
|
|
525
|
+
),
|
|
526
|
+
thread: Type.Optional(
|
|
527
|
+
Type.Union([Type.String(), Type.Number()], {
|
|
528
|
+
description:
|
|
529
|
+
"Optional live Pi thread name or numeric id for visible delivery plus a target-agent turn",
|
|
530
|
+
}),
|
|
531
|
+
),
|
|
532
|
+
}),
|
|
533
|
+
async execute(_toolCallId, params) {
|
|
534
|
+
try {
|
|
535
|
+
return await sendTelegramOutboundMessage({
|
|
536
|
+
text: params.text,
|
|
537
|
+
chatId: params.chat_id,
|
|
538
|
+
threadId: params.thread_id,
|
|
539
|
+
agentThread: params.thread,
|
|
540
|
+
getDefaultChatId: deps.getDefaultChatId,
|
|
541
|
+
getDefaultTarget: deps.getDefaultTarget,
|
|
542
|
+
getActiveTurn: deps.getActiveTurn,
|
|
543
|
+
resolveAgentTarget: deps.resolveAgentTarget,
|
|
544
|
+
routeAgentMessage: deps.routeAgentMessage,
|
|
545
|
+
canSendDirect: deps.canSendDirect,
|
|
546
|
+
planMessage: deps.planMessage,
|
|
547
|
+
sendMarkdownMessage: deps.sendMarkdownMessage,
|
|
548
|
+
});
|
|
549
|
+
} catch (error) {
|
|
550
|
+
deps.recordRuntimeEvent?.("message", error, { phase: "direct" });
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export interface TelegramQueuedOutboundAttachmentDeliveryDeps {
|
|
558
|
+
sendMultipart: (
|
|
559
|
+
method: string,
|
|
560
|
+
fields: Record<string, string>,
|
|
561
|
+
fileField: string,
|
|
562
|
+
filePath: string,
|
|
563
|
+
fileName: string,
|
|
564
|
+
) => Promise<unknown>;
|
|
565
|
+
sendTextReply: (
|
|
566
|
+
chatId: number,
|
|
567
|
+
replyToMessageId: number,
|
|
568
|
+
text: string,
|
|
569
|
+
options?: { target?: TelegramTarget },
|
|
570
|
+
) => Promise<unknown>;
|
|
571
|
+
recordRuntimeEvent?: (
|
|
572
|
+
category: string,
|
|
573
|
+
error: unknown,
|
|
574
|
+
details?: Record<string, unknown>,
|
|
575
|
+
) => void;
|
|
576
|
+
statPath?: (path: string) => Promise<{ size: number }>;
|
|
577
|
+
maxAttachmentSizeBytes?: number;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export async function queueTelegramOutboundAttachments(options: {
|
|
581
|
+
activeTurn: TelegramOutboundAttachmentQueueTargetView | undefined;
|
|
582
|
+
paths: string[];
|
|
583
|
+
chatId?: number;
|
|
584
|
+
threadId?: number;
|
|
585
|
+
caption?: string;
|
|
586
|
+
maxAttachmentsPerTurn: number;
|
|
587
|
+
maxAttachmentSizeBytes?: number;
|
|
588
|
+
sendMultipart?: TelegramQueuedOutboundAttachmentDeliveryDeps["sendMultipart"];
|
|
589
|
+
getDefaultChatId?: () => number | undefined;
|
|
590
|
+
getDefaultTarget?: () => TelegramTarget | undefined;
|
|
591
|
+
canSendDirect?: () => boolean;
|
|
592
|
+
statPath?: (path: string) => Promise<{ isFile(): boolean; size?: number }>;
|
|
593
|
+
}): Promise<TelegramOutboundAttachmentToolResult> {
|
|
594
|
+
if (!options.activeTurn) {
|
|
595
|
+
if (!options.sendMultipart) {
|
|
596
|
+
throw new Error(
|
|
597
|
+
"telegram_attach can only queue files while replying to an active Telegram turn; provide Telegram send ports for immediate delivery",
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
return sendTelegramOutboundFiles({
|
|
601
|
+
paths: options.paths,
|
|
602
|
+
chatId: options.chatId,
|
|
603
|
+
threadId: options.threadId,
|
|
604
|
+
caption: options.caption,
|
|
605
|
+
maxAttachmentsPerTurn: options.maxAttachmentsPerTurn,
|
|
606
|
+
maxAttachmentSizeBytes: options.maxAttachmentSizeBytes,
|
|
607
|
+
sendMultipart: options.sendMultipart,
|
|
608
|
+
getDefaultChatId: options.getDefaultChatId,
|
|
609
|
+
getDefaultTarget: options.getDefaultTarget,
|
|
610
|
+
canSendDirect: options.canSendDirect,
|
|
611
|
+
statPath: options.statPath,
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
if (
|
|
615
|
+
options.activeTurn.guestQueryId &&
|
|
616
|
+
options.activeTurn.queuedAttachments.length + options.paths.length > 1
|
|
617
|
+
) {
|
|
618
|
+
throw new Error(
|
|
619
|
+
"Telegram Guest Mode supports one attachment per reply; no attachment was queued",
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
if (
|
|
623
|
+
options.activeTurn.queuedAttachments.length + options.paths.length >
|
|
624
|
+
options.maxAttachmentsPerTurn
|
|
625
|
+
) {
|
|
626
|
+
throw new Error(
|
|
627
|
+
`Attachment limit reached (${options.maxAttachmentsPerTurn})`,
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
const pendingAttachments = await buildTelegramOutboundAttachmentViews({
|
|
631
|
+
paths: options.paths,
|
|
632
|
+
maxAttachmentSizeBytes: options.maxAttachmentSizeBytes,
|
|
633
|
+
statPath: options.statPath,
|
|
634
|
+
});
|
|
635
|
+
options.activeTurn.queuedAttachments.push(...pendingAttachments);
|
|
636
|
+
const added = pendingAttachments.map((attachment) => attachment.path);
|
|
637
|
+
return {
|
|
638
|
+
content: [
|
|
639
|
+
{
|
|
640
|
+
type: "text",
|
|
641
|
+
text: formatTelegramOutboundAttachmentToolResultText(added.length),
|
|
642
|
+
},
|
|
643
|
+
],
|
|
644
|
+
details: { paths: added },
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export async function deliverTelegramGuestCachedAttachment(options: {
|
|
649
|
+
guestQueryId: string;
|
|
650
|
+
stagingChatId: number;
|
|
651
|
+
stagingTarget?: TelegramTarget;
|
|
652
|
+
attachment: TelegramQueuedOutboundAttachmentView;
|
|
653
|
+
caption?: string;
|
|
654
|
+
sendMultipart: TelegramQueuedOutboundAttachmentDeliveryDeps["sendMultipart"];
|
|
655
|
+
answerGuestQuery: (
|
|
656
|
+
guestQueryId: string,
|
|
657
|
+
result: TelegramGuestCachedAttachmentResult,
|
|
658
|
+
) => Promise<void>;
|
|
659
|
+
answerGuestText?: (guestQueryId: string, text: string) => Promise<void>;
|
|
660
|
+
fallbackText?: string;
|
|
661
|
+
deleteMessage: (chatId: number, messageId: number) => Promise<void>;
|
|
662
|
+
recordRuntimeEvent?: TelegramOutboundAttachmentRuntimeEventRecorderPort["recordRuntimeEvent"];
|
|
663
|
+
}): Promise<void> {
|
|
664
|
+
const transport = getTelegramGuestAttachmentTransport(options.attachment.path);
|
|
665
|
+
let stagingMessageId: number | undefined;
|
|
666
|
+
let answerAttempted = false;
|
|
667
|
+
try {
|
|
668
|
+
const message = (await options.sendMultipart(
|
|
669
|
+
transport.method,
|
|
670
|
+
{
|
|
671
|
+
chat_id: String(options.stagingChatId),
|
|
672
|
+
...getTelegramMultipartTargetFields(options.stagingTarget),
|
|
673
|
+
},
|
|
674
|
+
transport.fileField,
|
|
675
|
+
options.attachment.path,
|
|
676
|
+
options.attachment.fileName,
|
|
677
|
+
)) as TelegramGuestStagingMessage;
|
|
678
|
+
stagingMessageId = message.message_id;
|
|
679
|
+
const caption = options.caption
|
|
680
|
+
? Array.from(options.caption).slice(0, 1024).join("")
|
|
681
|
+
: undefined;
|
|
682
|
+
let result: TelegramGuestCachedAttachmentResult;
|
|
683
|
+
if (transport.fileField === "photo") {
|
|
684
|
+
const photo = [...(message.photo ?? [])]
|
|
685
|
+
.sort((left, right) => (left.file_size ?? 0) - (right.file_size ?? 0))
|
|
686
|
+
.at(-1);
|
|
687
|
+
if (!photo?.file_id) throw new Error("Guest staging upload returned no photo file_id");
|
|
688
|
+
result = {
|
|
689
|
+
type: "photo",
|
|
690
|
+
id: "attachment-1",
|
|
691
|
+
photo_file_id: photo.file_id,
|
|
692
|
+
...(caption ? { caption } : {}),
|
|
693
|
+
};
|
|
694
|
+
} else if (transport.fileField === "audio") {
|
|
695
|
+
if (!message.audio?.file_id)
|
|
696
|
+
throw new Error("Guest staging upload returned no audio file_id");
|
|
697
|
+
result = {
|
|
698
|
+
type: "audio",
|
|
699
|
+
id: "attachment-1",
|
|
700
|
+
audio_file_id: message.audio.file_id,
|
|
701
|
+
...(caption ? { caption } : {}),
|
|
702
|
+
};
|
|
703
|
+
} else if (transport.fileField === "voice") {
|
|
704
|
+
if (!message.voice?.file_id)
|
|
705
|
+
throw new Error("Guest staging upload returned no voice file_id");
|
|
706
|
+
result = {
|
|
707
|
+
type: "voice",
|
|
708
|
+
id: "attachment-1",
|
|
709
|
+
voice_file_id: message.voice.file_id,
|
|
710
|
+
title: options.attachment.fileName,
|
|
711
|
+
...(caption ? { caption } : {}),
|
|
712
|
+
};
|
|
713
|
+
} else {
|
|
714
|
+
if (!message.document?.file_id)
|
|
715
|
+
throw new Error("Guest staging upload returned no document file_id");
|
|
716
|
+
result = {
|
|
717
|
+
type: "document",
|
|
718
|
+
id: "attachment-1",
|
|
719
|
+
title: options.attachment.fileName,
|
|
720
|
+
document_file_id: message.document.file_id,
|
|
721
|
+
...(caption ? { caption } : {}),
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
answerAttempted = true;
|
|
725
|
+
await options.answerGuestQuery(options.guestQueryId, result);
|
|
726
|
+
} catch (error) {
|
|
727
|
+
if (
|
|
728
|
+
!answerAttempted &&
|
|
729
|
+
options.answerGuestText &&
|
|
730
|
+
options.fallbackText
|
|
731
|
+
) {
|
|
732
|
+
answerAttempted = true;
|
|
733
|
+
await options.answerGuestText(options.guestQueryId, options.fallbackText);
|
|
734
|
+
} else {
|
|
735
|
+
throw error;
|
|
736
|
+
}
|
|
737
|
+
} finally {
|
|
738
|
+
if (stagingMessageId !== undefined) {
|
|
739
|
+
try {
|
|
740
|
+
await options.deleteMessage(options.stagingChatId, stagingMessageId);
|
|
741
|
+
} catch (error) {
|
|
742
|
+
options.recordRuntimeEvent?.("attachment", error, {
|
|
743
|
+
phase: "guest-staging-cleanup",
|
|
744
|
+
chatId: options.stagingChatId,
|
|
745
|
+
messageId: stagingMessageId,
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export async function sendTelegramOutboundMessage(options: {
|
|
753
|
+
text: string;
|
|
754
|
+
chatId?: number;
|
|
755
|
+
threadId?: number;
|
|
756
|
+
agentThread?: string | number;
|
|
757
|
+
target?: TelegramTarget;
|
|
758
|
+
getDefaultChatId?: () => number | undefined;
|
|
759
|
+
getDefaultTarget?: () => TelegramTarget | undefined;
|
|
760
|
+
getActiveTurn?: () =>
|
|
761
|
+
| { chatId: number; target?: TelegramTarget }
|
|
762
|
+
| undefined;
|
|
763
|
+
resolveAgentTarget?: (
|
|
764
|
+
selector: TelegramBusAgentTargetSelector,
|
|
765
|
+
) => Promise<TelegramTarget & { threadId: number }>;
|
|
766
|
+
routeAgentMessage?: (message: TelegramBusAgentMessage) => Promise<void>;
|
|
767
|
+
canSendDirect: () => boolean;
|
|
768
|
+
planMessage: (markdown: string) => TelegramOutboundMessagePlan;
|
|
769
|
+
sendMarkdownMessage: (
|
|
770
|
+
chatId: number,
|
|
771
|
+
markdown: string,
|
|
772
|
+
options?: { replyMarkup?: unknown; target?: TelegramTarget },
|
|
773
|
+
) => Promise<number | undefined>;
|
|
774
|
+
}): Promise<{
|
|
775
|
+
content: Array<{ type: "text"; text: string }>;
|
|
776
|
+
details: { chatId: number; messageId?: number };
|
|
777
|
+
}> {
|
|
778
|
+
assertTelegramDirectDeliveryAllowed(options.canSendDirect);
|
|
779
|
+
const activeTurn = options.getActiveTurn?.();
|
|
780
|
+
const requestedAgentSelector: TelegramBusAgentTargetSelector | undefined =
|
|
781
|
+
options.agentThread !== undefined
|
|
782
|
+
? typeof options.agentThread === "number"
|
|
783
|
+
? { chatId: options.chatId, threadId: options.agentThread }
|
|
784
|
+
: { chatId: options.chatId, threadName: options.agentThread }
|
|
785
|
+
: activeTurn &&
|
|
786
|
+
options.resolveAgentTarget &&
|
|
787
|
+
options.routeAgentMessage &&
|
|
788
|
+
((options.target?.threadId !== undefined) ||
|
|
789
|
+
(options.chatId !== undefined && options.threadId !== undefined))
|
|
790
|
+
? {
|
|
791
|
+
chatId: options.target?.chatId ?? options.chatId,
|
|
792
|
+
threadId: options.target?.threadId ?? options.threadId,
|
|
793
|
+
}
|
|
794
|
+
: undefined;
|
|
795
|
+
let agentTarget: (TelegramTarget & { threadId: number }) | undefined;
|
|
796
|
+
if (requestedAgentSelector) {
|
|
797
|
+
if (!options.resolveAgentTarget || !options.routeAgentMessage) {
|
|
798
|
+
throw new Error("Telegram agent turn routing is unavailable.");
|
|
799
|
+
}
|
|
800
|
+
agentTarget = await options.resolveAgentTarget(requestedAgentSelector);
|
|
801
|
+
}
|
|
802
|
+
const { chatId, target } = resolveTelegramOutboundTarget({
|
|
803
|
+
chatId: agentTarget?.chatId ?? options.chatId,
|
|
804
|
+
threadId: agentTarget?.threadId ?? options.threadId,
|
|
805
|
+
target: agentTarget ?? options.target,
|
|
806
|
+
getDefaultChatId: options.getDefaultChatId,
|
|
807
|
+
getDefaultTarget: options.getDefaultTarget,
|
|
808
|
+
});
|
|
809
|
+
if (activeTurn) {
|
|
810
|
+
const hasExplicitTarget =
|
|
811
|
+
options.chatId !== undefined ||
|
|
812
|
+
options.target !== undefined ||
|
|
813
|
+
options.agentThread !== undefined;
|
|
814
|
+
const activeTarget = activeTurn.target ?? { chatId: activeTurn.chatId };
|
|
815
|
+
const requestedTarget = target ?? { chatId };
|
|
816
|
+
const targetsMatch =
|
|
817
|
+
activeTarget.chatId === requestedTarget.chatId &&
|
|
818
|
+
activeTarget.threadId === requestedTarget.threadId;
|
|
819
|
+
if (!hasExplicitTarget || targetsMatch) {
|
|
820
|
+
throw new Error(
|
|
821
|
+
"telegram_message cannot send directly to the active Telegram turn target; return the text normally so the bridge can deliver it once",
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
const plan = options.planMessage(options.text);
|
|
826
|
+
const messageId = await options.sendMarkdownMessage(chatId, plan.markdown, {
|
|
827
|
+
replyMarkup: plan.replyMarkup,
|
|
828
|
+
target,
|
|
829
|
+
});
|
|
830
|
+
if (agentTarget) {
|
|
831
|
+
if (messageId === undefined) {
|
|
832
|
+
throw new Error(
|
|
833
|
+
"Telegram message was sent but no message id was returned for agent routing.",
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
await options.routeAgentMessage!({
|
|
837
|
+
target: agentTarget,
|
|
838
|
+
messageId,
|
|
839
|
+
text: options.text,
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
return {
|
|
843
|
+
content: [
|
|
844
|
+
{
|
|
845
|
+
type: "text",
|
|
846
|
+
text: formatTelegramOutboundMessageToolResultText(chatId),
|
|
847
|
+
},
|
|
848
|
+
],
|
|
849
|
+
details: { chatId, messageId },
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
export async function sendTelegramOutboundFiles(options: {
|
|
854
|
+
paths: string[];
|
|
855
|
+
chatId?: number;
|
|
856
|
+
threadId?: number;
|
|
857
|
+
target?: TelegramTarget;
|
|
858
|
+
caption?: string;
|
|
859
|
+
maxAttachmentsPerTurn: number;
|
|
860
|
+
maxAttachmentSizeBytes?: number;
|
|
861
|
+
sendMultipart: TelegramQueuedOutboundAttachmentDeliveryDeps["sendMultipart"];
|
|
862
|
+
getDefaultChatId?: () => number | undefined;
|
|
863
|
+
getDefaultTarget?: () => TelegramTarget | undefined;
|
|
864
|
+
canSendDirect?: () => boolean;
|
|
865
|
+
statPath?: (path: string) => Promise<{ isFile(): boolean; size?: number }>;
|
|
866
|
+
}): Promise<
|
|
867
|
+
TelegramOutboundAttachmentToolResult & {
|
|
868
|
+
details: { paths: string[]; chatId: number };
|
|
869
|
+
}
|
|
870
|
+
> {
|
|
871
|
+
assertTelegramDirectDeliveryAllowed(options.canSendDirect);
|
|
872
|
+
if (options.paths.length > options.maxAttachmentsPerTurn) {
|
|
873
|
+
throw new Error(
|
|
874
|
+
`Attachment limit reached (${options.maxAttachmentsPerTurn})`,
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
const { chatId, target } = resolveTelegramOutboundTarget({
|
|
878
|
+
chatId: options.chatId,
|
|
879
|
+
threadId: options.threadId,
|
|
880
|
+
target: options.target,
|
|
881
|
+
getDefaultChatId: options.getDefaultChatId,
|
|
882
|
+
getDefaultTarget: options.getDefaultTarget,
|
|
883
|
+
});
|
|
884
|
+
const pendingAttachments = await buildTelegramOutboundAttachmentViews({
|
|
885
|
+
paths: options.paths,
|
|
886
|
+
maxAttachmentSizeBytes: options.maxAttachmentSizeBytes,
|
|
887
|
+
statPath: options.statPath,
|
|
888
|
+
});
|
|
889
|
+
for (const [index, attachment] of pendingAttachments.entries()) {
|
|
890
|
+
const isPhoto = isTelegramOutboundPhotoAttachmentPath(attachment.path);
|
|
891
|
+
const method = isPhoto ? "sendPhoto" : "sendDocument";
|
|
892
|
+
const fieldName = isPhoto ? "photo" : "document";
|
|
893
|
+
await options.sendMultipart(
|
|
894
|
+
method,
|
|
895
|
+
{
|
|
896
|
+
chat_id: String(chatId),
|
|
897
|
+
...(options.caption && index === 0 ? { caption: options.caption } : {}),
|
|
898
|
+
...getTelegramMultipartTargetFields(target),
|
|
899
|
+
},
|
|
900
|
+
fieldName,
|
|
901
|
+
attachment.path,
|
|
902
|
+
attachment.fileName,
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
const added = pendingAttachments.map((attachment) => attachment.path);
|
|
906
|
+
return {
|
|
907
|
+
content: [
|
|
908
|
+
{
|
|
909
|
+
type: "text",
|
|
910
|
+
text: formatTelegramOutboundAttachmentToolResultText(
|
|
911
|
+
added.length,
|
|
912
|
+
"sent",
|
|
913
|
+
),
|
|
914
|
+
},
|
|
915
|
+
],
|
|
916
|
+
details: { paths: added, chatId },
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
export function createTelegramQueuedOutboundAttachmentSender(
|
|
921
|
+
deps: TelegramQueuedOutboundAttachmentDeliveryDeps,
|
|
922
|
+
) {
|
|
923
|
+
return async (turn: TelegramQueuedOutboundAttachmentTurnView): Promise<void> => {
|
|
924
|
+
await sendQueuedTelegramOutboundAttachments(turn, {
|
|
925
|
+
...deps,
|
|
926
|
+
maxAttachmentSizeBytes:
|
|
927
|
+
deps.maxAttachmentSizeBytes ?? TELEGRAM_OUTBOUND_ATTACHMENT_MAX_BYTES,
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
export async function sendQueuedTelegramOutboundAttachments(
|
|
933
|
+
turn: TelegramQueuedOutboundAttachmentTurnView,
|
|
934
|
+
deps: TelegramQueuedOutboundAttachmentDeliveryDeps,
|
|
935
|
+
): Promise<void> {
|
|
936
|
+
for (const attachment of turn.queuedAttachments) {
|
|
937
|
+
try {
|
|
938
|
+
if (deps.maxAttachmentSizeBytes !== undefined) {
|
|
939
|
+
const stats = await (deps.statPath ?? stat)(attachment.path);
|
|
940
|
+
if (stats.size > deps.maxAttachmentSizeBytes) {
|
|
941
|
+
throw new Error(
|
|
942
|
+
formatTelegramOutboundAttachmentSizeLimitError(
|
|
943
|
+
stats.size,
|
|
944
|
+
deps.maxAttachmentSizeBytes,
|
|
945
|
+
),
|
|
946
|
+
);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
const isPhoto = isTelegramOutboundPhotoAttachmentPath(attachment.path);
|
|
950
|
+
const method = isPhoto ? "sendPhoto" : "sendDocument";
|
|
951
|
+
const fieldName = isPhoto ? "photo" : "document";
|
|
952
|
+
const replyParameters = buildTelegramMultipartReplyParameters(
|
|
953
|
+
turn.chatId,
|
|
954
|
+
turn.replyToMessageId,
|
|
955
|
+
turn.target,
|
|
956
|
+
);
|
|
957
|
+
await deps.sendMultipart(
|
|
958
|
+
method,
|
|
959
|
+
{
|
|
960
|
+
chat_id: String(turn.chatId),
|
|
961
|
+
...(replyParameters ? { reply_parameters: replyParameters } : {}),
|
|
962
|
+
...getTelegramMultipartTargetFields(turn.target),
|
|
963
|
+
},
|
|
964
|
+
fieldName,
|
|
965
|
+
attachment.path,
|
|
966
|
+
attachment.fileName,
|
|
967
|
+
);
|
|
968
|
+
} catch (error) {
|
|
969
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
970
|
+
deps.recordRuntimeEvent?.("attachment", error, {
|
|
971
|
+
fileName: attachment.fileName,
|
|
972
|
+
});
|
|
973
|
+
await deps.sendTextReply(
|
|
974
|
+
turn.chatId,
|
|
975
|
+
turn.replyToMessageId,
|
|
976
|
+
`Failed to send attachment ${attachment.fileName}: ${message}`,
|
|
977
|
+
{ target: turn.target },
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|