pi-harness-runtime 1.1.397 → 1.1.402
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 +44 -2
- package/CHANGELOG.md +21 -0
- package/RULES.md +28 -0
- package/harness/agent-handoff.ts +2 -3
- package/harness/autonomous-review.ts +1 -1
- package/harness/blackboard.ts +2 -3
- package/harness/context-compact-orchestrator.ts +1 -1
- package/harness/context-window-manager.ts +2 -2
- package/harness/e2e/playwright-runner.ts +6 -4
- package/harness/herdr-agents.ts +1 -1
- package/harness/job-state-machine.ts +1 -1
- package/harness/langchain/daemon.ts +3 -3
- package/harness/langchain/graph.ts +2 -2
- package/harness/langchain/ping-pong-middleware.ts +2 -2
- package/harness/loop-code-agent.ts +6 -4
- package/harness/loop-controller.ts +1 -1
- package/harness/loop-review-agent.ts +1 -1
- package/harness/loop-types.ts +1 -1
- package/harness/master-planner.ts +1 -1
- package/harness/notification-events.ts +6 -6
- package/harness/project-detector/detector.ts +1 -2
- package/harness/repair-engine.ts +2 -4
- package/harness/service-diagnostics.ts +1 -1
- package/harness/skill-sync.ts +3 -3
- package/index.ts +276 -55
- package/mirror.ts +1 -1
- package/package.json +5 -3
- package/packages/a2a-adapter/dist/discovery.d.ts.map +1 -1
- package/packages/a2a-adapter/dist/discovery.js +0 -1
- package/packages/a2a-adapter/dist/discovery.js.map +1 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/a2a-adapter/src/discovery.ts +0 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/dist/index.d.ts +9 -0
- package/packages/auth/dist/index.d.ts.map +1 -0
- package/packages/auth/dist/index.js +9 -0
- package/packages/auth/dist/index.js.map +1 -0
- package/packages/auth/package.json +1 -1
- package/packages/auth/src/index.ts +9 -0
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/dist/index.d.ts +52 -0
- package/packages/config-capture/dist/index.d.ts.map +1 -0
- package/packages/config-capture/dist/index.js +261 -0
- package/packages/config-capture/dist/index.js.map +1 -0
- package/packages/config-capture/package.json +1 -1
- package/packages/connection-runtime/package.json +1 -1
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/durable-review/package.json +1 -1
- package/packages/e2e-tester/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-sink/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/dist/extension.d.ts +15 -0
- package/packages/file-copy-helper/dist/extension.d.ts.map +1 -0
- package/packages/file-copy-helper/dist/extension.debug.d.ts +15 -0
- package/packages/file-copy-helper/dist/extension.debug.d.ts.map +1 -0
- package/packages/file-copy-helper/dist/extension.debug.js +215 -0
- package/packages/file-copy-helper/dist/extension.debug.js.map +1 -0
- package/packages/file-copy-helper/dist/extension.js +222 -0
- package/packages/file-copy-helper/dist/extension.js.map +1 -0
- package/packages/file-copy-helper/dist/index.d.ts +3 -0
- package/packages/file-copy-helper/dist/index.d.ts.map +1 -0
- package/packages/file-copy-helper/dist/index.js +3 -0
- package/packages/file-copy-helper/dist/index.js.map +1 -0
- package/packages/file-copy-helper/dist/intent-detector.d.ts +21 -0
- package/packages/file-copy-helper/dist/intent-detector.d.ts.map +1 -0
- package/packages/file-copy-helper/dist/intent-detector.js +348 -0
- package/packages/file-copy-helper/dist/intent-detector.js.map +1 -0
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/auto-continue.d.ts +161 -2
- package/packages/jev-judge/dist/auto-continue.d.ts.map +1 -1
- package/packages/jev-judge/dist/auto-continue.js +267 -22
- package/packages/jev-judge/dist/auto-continue.js.map +1 -1
- package/packages/jev-judge/dist/index.d.ts +2 -0
- package/packages/jev-judge/dist/index.d.ts.map +1 -1
- package/packages/jev-judge/dist/index.js +2 -0
- package/packages/jev-judge/dist/index.js.map +1 -1
- package/packages/jev-judge/dist/question-risk.d.ts +50 -0
- package/packages/jev-judge/dist/question-risk.d.ts.map +1 -0
- package/packages/jev-judge/dist/question-risk.js +100 -0
- package/packages/jev-judge/dist/question-risk.js.map +1 -0
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/auto-continue.ts +426 -29
- package/packages/jev-judge/src/index.ts +4 -0
- package/packages/jev-judge/src/question-risk.ts +151 -0
- package/packages/jev-judge/tests/auto-continue-context.test.ts +221 -0
- package/packages/jev-judge/tests/outcome-application.test.ts +132 -0
- package/packages/jev-judge/tests/question-risk.test.ts +116 -0
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/README.md +36 -3
- package/packages/logging/dist/config.d.ts +7 -0
- package/packages/logging/dist/config.d.ts.map +1 -1
- package/packages/logging/dist/config.js +14 -0
- package/packages/logging/dist/config.js.map +1 -1
- package/packages/logging/dist/incidents/schema.d.ts +111 -0
- package/packages/logging/dist/incidents/schema.d.ts.map +1 -0
- package/packages/logging/dist/incidents/schema.js +0 -0
- package/packages/logging/dist/incidents/schema.js.map +1 -0
- package/packages/logging/dist/index.d.ts +2 -0
- package/packages/logging/dist/index.d.ts.map +1 -1
- package/packages/logging/dist/index.js +2 -0
- package/packages/logging/dist/index.js.map +1 -1
- package/packages/logging/dist/server/http.d.ts +4 -3
- package/packages/logging/dist/server/http.d.ts.map +1 -1
- package/packages/logging/dist/server/http.js +35 -3
- package/packages/logging/dist/server/http.js.map +1 -1
- package/packages/logging/dist/server/incident-qdrant.d.ts +83 -0
- package/packages/logging/dist/server/incident-qdrant.d.ts.map +1 -0
- package/packages/logging/dist/server/incident-qdrant.js +129 -0
- package/packages/logging/dist/server/incident-qdrant.js.map +1 -0
- package/packages/logging/dist/server/incident-store.d.ts +76 -0
- package/packages/logging/dist/server/incident-store.d.ts.map +1 -0
- package/packages/logging/dist/server/incident-store.js +157 -0
- package/packages/logging/dist/server/incident-store.js.map +1 -0
- package/packages/logging/dist/server/index.d.ts +4 -0
- package/packages/logging/dist/server/index.d.ts.map +1 -1
- package/packages/logging/dist/server/index.js +2 -0
- package/packages/logging/dist/server/index.js.map +1 -1
- package/packages/logging/dist/server/service.d.ts +33 -0
- package/packages/logging/dist/server/service.d.ts.map +1 -1
- package/packages/logging/dist/server/service.js +63 -0
- package/packages/logging/dist/server/service.js.map +1 -1
- package/packages/logging/dist/shipper.d.ts +74 -3
- package/packages/logging/dist/shipper.d.ts.map +1 -1
- package/packages/logging/dist/shipper.js +88 -5
- package/packages/logging/dist/shipper.js.map +1 -1
- package/packages/logging/dist/singleton.d.ts.map +1 -1
- package/packages/logging/dist/singleton.js +1 -0
- package/packages/logging/dist/singleton.js.map +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/logging/src/config.ts +22 -0
- package/packages/logging/src/incidents/schema.ts +0 -0
- package/packages/logging/src/index.ts +17 -0
- package/packages/logging/src/server/http.ts +42 -3
- package/packages/logging/src/server/incident-qdrant.ts +177 -0
- package/packages/logging/src/server/incident-store.ts +192 -0
- package/packages/logging/src/server/index.ts +21 -0
- package/packages/logging/src/server/service.ts +79 -0
- package/packages/logging/src/shipper.ts +120 -5
- package/packages/logging/src/singleton.ts +1 -0
- package/packages/logging/test/fanout.test.ts +186 -0
- package/packages/logging/test/incidents.test.ts +404 -0
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/dist/adapters/detail-format.d.ts +42 -0
- package/packages/notification/dist/adapters/detail-format.d.ts.map +1 -0
- package/packages/notification/dist/adapters/detail-format.js +94 -0
- package/packages/notification/dist/adapters/detail-format.js.map +1 -0
- package/packages/notification/dist/adapters/email-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/email-adapter.js +3 -2
- package/packages/notification/dist/adapters/email-adapter.js.map +1 -1
- package/packages/notification/dist/adapters/line-adapter.d.ts +33 -0
- package/packages/notification/dist/adapters/line-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/line-adapter.js +87 -9
- package/packages/notification/dist/adapters/line-adapter.js.map +1 -1
- package/packages/notification/dist/adapters/ntfy-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/ntfy-adapter.js +3 -2
- package/packages/notification/dist/adapters/ntfy-adapter.js.map +1 -1
- package/packages/notification/dist/adapters/telegram-adapter.d.ts +14 -0
- package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/telegram-adapter.js +89 -69
- package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
- package/packages/notification/dist/notification-center.d.ts.map +1 -1
- package/packages/notification/dist/notification-center.js +60 -7
- package/packages/notification/dist/notification-center.js.map +1 -1
- package/packages/notification/dist/pending-question.d.ts +69 -2
- package/packages/notification/dist/pending-question.d.ts.map +1 -1
- package/packages/notification/dist/pending-question.js +88 -2
- package/packages/notification/dist/pending-question.js.map +1 -1
- package/packages/notification/dist/types.d.ts +21 -0
- package/packages/notification/dist/types.d.ts.map +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/notification/src/adapters/detail-format.ts +114 -0
- package/packages/notification/src/adapters/email-adapter.ts +3 -2
- package/packages/notification/src/adapters/line-adapter.ts +97 -9
- package/packages/notification/src/adapters/ntfy-adapter.ts +3 -2
- package/packages/notification/src/adapters/telegram-adapter.ts +98 -76
- package/packages/notification/src/notification-center.ts +66 -8
- package/packages/notification/src/pending-question.ts +160 -8
- package/packages/notification/src/types.ts +21 -0
- package/packages/notification/test/approval-payload.test.ts +269 -0
- package/packages/notification/test/detail-format.test.ts +106 -0
- package/packages/notification/test/pending-question-lifecycle.test.ts +195 -0
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/dist/index.d.ts +9 -0
- package/packages/okf-indexer/dist/index.d.ts.map +1 -0
- package/packages/okf-indexer/dist/index.js +9 -0
- package/packages/okf-indexer/dist/index.js.map +1 -0
- package/packages/okf-indexer/package.json +1 -1
- package/packages/okf-indexer/src/index.ts +9 -0
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/permission-mode/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/dist/provider-router.d.ts.map +1 -1
- package/packages/provider-router/dist/types.d.ts +2 -2
- package/packages/provider-router/dist/types.d.ts.map +1 -1
- package/packages/provider-router/dist/types.js +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-router/src/types.ts +2 -2
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/dist/index.d.ts +9 -0
- package/packages/scheduler/dist/index.d.ts.map +1 -0
- package/packages/scheduler/dist/index.js +9 -0
- package/packages/scheduler/dist/index.js.map +1 -0
- package/packages/scheduler/dist/scheduler.d.ts +17 -0
- package/packages/scheduler/dist/scheduler.d.ts.map +1 -0
- package/packages/scheduler/dist/scheduler.js +41 -0
- package/packages/scheduler/dist/scheduler.js.map +1 -0
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler/src/index.ts +9 -0
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/dist/index.d.ts +7 -0
- package/packages/shared-context/dist/index.d.ts.map +1 -0
- package/packages/shared-context/dist/index.js +7 -0
- package/packages/shared-context/dist/index.js.map +1 -0
- package/packages/shared-context/dist/shared-context.d.ts +12 -0
- package/packages/shared-context/dist/shared-context.d.ts.map +1 -0
- package/packages/shared-context/dist/shared-context.js +39 -0
- package/packages/shared-context/dist/shared-context.js.map +1 -0
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/dist/client.d.ts +56 -0
- package/packages/skill-mcp-client/dist/client.d.ts.map +1 -0
- package/packages/skill-mcp-client/dist/client.js +101 -0
- package/packages/skill-mcp-client/dist/client.js.map +1 -0
- package/packages/skill-mcp-client/dist/errors.d.ts +44 -0
- package/packages/skill-mcp-client/dist/errors.d.ts.map +1 -0
- package/packages/skill-mcp-client/dist/errors.js +68 -0
- package/packages/skill-mcp-client/dist/errors.js.map +1 -0
- package/packages/skill-mcp-client/dist/index.d.ts +9 -0
- package/packages/skill-mcp-client/dist/index.d.ts.map +1 -0
- package/packages/skill-mcp-client/dist/index.js +9 -0
- package/packages/skill-mcp-client/dist/index.js.map +1 -0
- package/packages/skill-mcp-client/dist/types.d.ts +106 -0
- package/packages/skill-mcp-client/dist/types.d.ts.map +1 -0
- package/packages/skill-mcp-client/dist/types.js +14 -0
- package/packages/skill-mcp-client/dist/types.js.map +1 -0
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/package.json +1 -5
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/telegram/package.json +1 -1
- package/packages/telegram/src/agent-messages.d.ts +28 -0
- package/packages/telegram/src/agent-messages.js +90 -0
- package/packages/telegram/src/bindings.d.ts +296 -0
- package/packages/telegram/src/bindings.js +1086 -0
- package/packages/telegram/src/bus.d.ts +759 -0
- package/packages/telegram/src/bus.js +2732 -0
- package/packages/telegram/src/commands.d.ts +761 -0
- package/packages/telegram/src/commands.js +2622 -0
- package/packages/telegram/src/config.d.ts +222 -0
- package/packages/telegram/src/config.js +844 -0
- package/packages/telegram/src/delivery.d.ts +161 -0
- package/packages/telegram/src/delivery.js +550 -0
- package/packages/telegram/src/extension.d.ts +7 -0
- package/packages/telegram/src/extension.js +2444 -0
- package/packages/telegram/src/inbound.d.ts +94 -0
- package/packages/telegram/src/inbound.js +478 -0
- package/packages/telegram/src/index.d.ts +6 -0
- package/packages/telegram/src/index.js +6 -0
- package/packages/telegram/src/keyboard.d.ts +21 -0
- package/packages/telegram/src/keyboard.js +37 -0
- package/packages/telegram/src/lifecycle.d.ts +210 -0
- package/packages/telegram/src/lifecycle.js +538 -0
- package/packages/telegram/src/pi.d.ts +76 -0
- package/packages/telegram/src/pi.js +130 -0
- package/packages/telegram/src/polling.d.ts +332 -0
- package/packages/telegram/src/polling.js +1219 -0
- package/packages/telegram/src/replies.d.ts +210 -0
- package/packages/telegram/src/replies.js +752 -0
- package/packages/telegram/src/routing.d.ts +388 -0
- package/packages/telegram/src/routing.js +7886 -0
- package/packages/telegram/src/runtime.d.ts +159 -0
- package/packages/telegram/src/runtime.js +351 -0
- package/packages/telegram/src/telegram-api.d.ts +564 -0
- package/packages/telegram/src/telegram-api.js +1332 -0
- package/packages/telegram/src/turns.d.ts +108 -0
- package/packages/telegram/src/turns.js +482 -0
- package/packages/telegram/src/updates.d.ts +1545 -0
- package/packages/telegram/src/updates.js +6420 -0
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/dist/detector.d.ts +54 -0
- package/packages/todo-bd-sync/dist/detector.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/detector.js +132 -0
- package/packages/todo-bd-sync/dist/detector.js.map +1 -0
- package/packages/todo-bd-sync/dist/extension.d.ts +30 -0
- package/packages/todo-bd-sync/dist/extension.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/extension.js +35 -0
- package/packages/todo-bd-sync/dist/extension.js.map +1 -0
- package/packages/todo-bd-sync/dist/index.d.ts +87 -0
- package/packages/todo-bd-sync/dist/index.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/index.js +296 -0
- package/packages/todo-bd-sync/dist/index.js.map +1 -0
- package/packages/todo-bd-sync/dist/sync.d.ts +72 -0
- package/packages/todo-bd-sync/dist/sync.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/sync.js +290 -0
- package/packages/todo-bd-sync/dist/sync.js.map +1 -0
- package/packages/todo-bd-sync/dist/task-analyzer.d.ts +49 -0
- package/packages/todo-bd-sync/dist/task-analyzer.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/task-analyzer.js +240 -0
- package/packages/todo-bd-sync/dist/task-analyzer.js.map +1 -0
- package/packages/todo-bd-sync/dist/todo-reminder.d.ts +126 -0
- package/packages/todo-bd-sync/dist/todo-reminder.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/todo-reminder.js +329 -0
- package/packages/todo-bd-sync/dist/todo-reminder.js.map +1 -0
- package/packages/todo-bd-sync/dist/types.d.ts +65 -0
- package/packages/todo-bd-sync/dist/types.d.ts.map +1 -0
- package/packages/todo-bd-sync/dist/types.js +67 -0
- package/packages/todo-bd-sync/dist/types.js.map +1 -0
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/dist/index.d.ts +94 -0
- package/packages/token-estimation/dist/index.d.ts.map +1 -0
- package/packages/token-estimation/dist/index.js +115 -0
- package/packages/token-estimation/dist/index.js.map +1 -0
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/types/dist/ai-providers.d.ts +36 -0
- package/packages/types/dist/ai-providers.d.ts.map +1 -0
- package/packages/types/dist/ai-providers.js +66 -0
- package/packages/types/dist/ai-providers.js.map +1 -0
- package/packages/types/dist/index.d.ts +12 -0
- package/packages/types/dist/index.d.ts.map +1 -0
- package/packages/types/dist/index.js +12 -0
- package/packages/types/dist/index.js.map +1 -0
- package/packages/types/package.json +5 -5
- package/packages/types/src/index.ts +12 -0
- package/packages/voice-api/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/worktree/worktree.ts +1 -1
- package/packages/write-review/package.json +1 -1
- package/renderer.ts +1 -1
- package/scripts/build-packages.ts +162 -0
- package/scripts/relay-client.ts +2 -2
- package/scripts/typecheck-packages.mjs +3 -3
- package/scripts/unified-webhook-server.ts +22 -10
- package/scripts/verify-package-contents.ts +345 -0
- package/scripts/ws-server.ts +1 -1
- package/tracker.ts +1 -1
- package/harness/browser-scrapers/base-browser-scraper.d.ts +0 -91
- package/harness/browser-scrapers/chrome-profile-manager.d.ts +0 -80
- package/harness/browser-scrapers/codex-browser-scraper.d.ts +0 -60
- package/harness/browser-scrapers/index.d.ts +0 -29
- package/harness/browser-scrapers/zai-browser-scraper.d.ts +0 -79
- package/harness/e2e/browser-scrapers/base-browser-scraper.d.ts +0 -92
- package/harness/e2e/browser-scrapers/chrome-profile-manager.d.ts +0 -81
- package/harness/e2e/browser-scrapers/codex-browser-scraper.d.ts +0 -61
- package/harness/e2e/browser-scrapers/index.d.ts +0 -30
- package/harness/e2e/browser-scrapers/zai-browser-scraper.d.ts +0 -80
- package/harness/langchain/agents.d.ts +0 -143
- package/harness/langchain/agents.test.d.ts +0 -2
- package/harness/langchain/checkpointer.d.ts +0 -48
- package/harness/langchain/checkpointer.test.d.ts +0 -8
- package/harness/langchain/cron-cli.d.ts +0 -12
- package/harness/langchain/daemon.d.ts +0 -161
- package/harness/langchain/daemon.test.d.ts +0 -11
- package/harness/langchain/file-tools.d.ts +0 -97
- package/harness/langchain/graph.d.ts +0 -706
- package/harness/langchain/model-router.d.ts +0 -63
- package/harness/langchain/model-router.test.d.ts +0 -2
- package/harness/langchain/models.d.ts +0 -72
- package/harness/langchain/ping-pong-middleware.d.ts +0 -28
- package/harness/langchain/ping-pong-middleware.test.d.ts +0 -2
- package/harness/langchain/run.d.ts +0 -15
- package/harness/langchain/scoreboard.test.d.ts +0 -13
- package/harness/langchain/status-line.d.ts +0 -91
- package/harness/langchain/status-line.test.d.ts +0 -8
- package/harness/langchain/surge.d.ts +0 -111
- package/harness/langchain/surge.test.d.ts +0 -10
- package/harness/langchain/widget.d.ts +0 -105
- package/harness/langchain/widget.test.d.ts +0 -8
- package/packages/autonomous-runtime/dist/worker.d.ts +0 -63
- package/packages/autonomous-runtime/dist/worker.js +0 -133
- package/packages/capability-registry/src/types.d.ts +0 -47
- package/packages/clipboard/dist/clipboard.d.ts +0 -11
- package/packages/clipboard/dist/clipboard.js +0 -40
- package/packages/clipboard/dist/index.d.ts +0 -2
- package/packages/clipboard/dist/index.js +0 -2
- package/packages/clipboard/dist/types.d.ts +0 -13
- package/packages/clipboard/dist/types.js +0 -5
- package/packages/context-discovery/dist/discover.d.ts +0 -3
- package/packages/context-discovery/dist/discover.js +0 -42
- package/packages/context-discovery/dist/discovery.d.ts +0 -28
- package/packages/context-discovery/dist/discovery.js +0 -21
- package/packages/context-discovery/dist/index.d.ts +0 -3
- package/packages/context-discovery/dist/index.js +0 -2
- package/packages/context-discovery/dist/types.d.ts +0 -16
- package/packages/context-discovery/dist/types.js +0 -2
- package/packages/event-bus/dist/bus.d.ts +0 -15
- package/packages/event-bus/dist/bus.js +0 -90
- package/packages/event-bus/dist/index.d.ts +0 -4
- package/packages/event-bus/dist/index.js +0 -3
- package/packages/event-bus/dist/test/bus.test.js +0 -52
- package/packages/event-bus/dist/types.d.ts +0 -27
- package/packages/event-bus/dist/types.js +0 -10
- package/packages/event-store/dist/index.d.ts +0 -3
- package/packages/event-store/dist/index.js +0 -2
- package/packages/event-store/dist/store.d.ts +0 -15
- package/packages/event-store/dist/store.js +0 -131
- package/packages/event-store/dist/test/store.test.js +0 -57
- package/packages/event-store/dist/types.d.ts +0 -48
- package/packages/event-store/dist/types.js +0 -5
- package/packages/event-store/src/types.d.ts +0 -48
- package/packages/file-copy-helper/dist/src/extension.js +0 -186
- package/packages/model-registry/src/types.d.ts +0 -63
- package/packages/notification/dist/src/adapters/email-adapter.d.ts +0 -17
- package/packages/notification/dist/src/adapters/email-adapter.d.ts.map +0 -1
- package/packages/notification/dist/src/adapters/email-adapter.js +0 -89
- package/packages/notification/dist/src/adapters/email-adapter.js.map +0 -1
- package/packages/notification/dist/src/adapters/line-adapter.d.ts +0 -17
- package/packages/notification/dist/src/adapters/line-adapter.d.ts.map +0 -1
- package/packages/notification/dist/src/adapters/line-adapter.js +0 -99
- package/packages/notification/dist/src/adapters/line-adapter.js.map +0 -1
- package/packages/notification/dist/src/adapters/ntfy-adapter.d.ts +0 -17
- package/packages/notification/dist/src/adapters/ntfy-adapter.d.ts.map +0 -1
- package/packages/notification/dist/src/adapters/ntfy-adapter.js +0 -84
- package/packages/notification/dist/src/adapters/ntfy-adapter.js.map +0 -1
- package/packages/notification/dist/src/adapters/telegram-adapter.d.ts +0 -56
- package/packages/notification/dist/src/adapters/telegram-adapter.d.ts.map +0 -1
- package/packages/notification/dist/src/adapters/telegram-adapter.js +0 -251
- package/packages/notification/dist/src/adapters/telegram-adapter.js.map +0 -1
- package/packages/notification/dist/src/adapters/webhook-adapter.d.ts +0 -15
- package/packages/notification/dist/src/adapters/webhook-adapter.d.ts.map +0 -1
- package/packages/notification/dist/src/adapters/webhook-adapter.js +0 -64
- package/packages/notification/dist/src/adapters/webhook-adapter.js.map +0 -1
- package/packages/notification/dist/src/base-adapter.d.ts +0 -36
- package/packages/notification/dist/src/base-adapter.d.ts.map +0 -1
- package/packages/notification/dist/src/base-adapter.js +0 -39
- package/packages/notification/dist/src/base-adapter.js.map +0 -1
- package/packages/notification/dist/src/index.d.ts +0 -12
- package/packages/notification/dist/src/index.d.ts.map +0 -1
- package/packages/notification/dist/src/index.js +0 -12
- package/packages/notification/dist/src/index.js.map +0 -1
- package/packages/notification/dist/src/notification-center.d.ts +0 -89
- package/packages/notification/dist/src/notification-center.d.ts.map +0 -1
- package/packages/notification/dist/src/notification-center.js +0 -356
- package/packages/notification/dist/src/notification-center.js.map +0 -1
- package/packages/notification/dist/src/notification-policy.d.ts +0 -66
- package/packages/notification/dist/src/notification-policy.d.ts.map +0 -1
- package/packages/notification/dist/src/notification-policy.js +0 -153
- package/packages/notification/dist/src/notification-policy.js.map +0 -1
- package/packages/notification/dist/src/telegram-webhook-handler.d.ts +0 -86
- package/packages/notification/dist/src/telegram-webhook-handler.d.ts.map +0 -1
- package/packages/notification/dist/src/telegram-webhook-handler.js +0 -149
- package/packages/notification/dist/src/telegram-webhook-handler.js.map +0 -1
- package/packages/notification/dist/src/types.d.ts +0 -106
- package/packages/notification/dist/src/types.d.ts.map +0 -1
- package/packages/notification/dist/src/types.js +0 -7
- package/packages/notification/dist/src/types.js.map +0 -1
- package/packages/projection-engine/dist/engine.d.ts +0 -61
- package/packages/projection-engine/dist/engine.js +0 -76
- package/packages/projection-engine/dist/index.d.ts +0 -2
- package/packages/projection-engine/dist/index.js +0 -2
- package/packages/projection-engine/dist/project.d.ts +0 -3
- package/packages/projection-engine/dist/project.js +0 -24
- package/packages/projection-engine/dist/types.d.ts +0 -55
- package/packages/projection-engine/dist/types.js +0 -5
- package/packages/projection-engine/src/types.d.ts +0 -55
- package/packages/provider-adapter-sdk/dist/src/builder.d.ts +0 -140
- package/packages/provider-adapter-sdk/dist/src/builder.d.ts.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/builder.js +0 -332
- package/packages/provider-adapter-sdk/dist/src/builder.js.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/errors.d.ts +0 -71
- package/packages/provider-adapter-sdk/dist/src/errors.d.ts.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/errors.js +0 -111
- package/packages/provider-adapter-sdk/dist/src/errors.js.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/index.d.ts +0 -15
- package/packages/provider-adapter-sdk/dist/src/index.d.ts.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/index.js +0 -19
- package/packages/provider-adapter-sdk/dist/src/index.js.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/registry.d.ts +0 -108
- package/packages/provider-adapter-sdk/dist/src/registry.d.ts.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/registry.js +0 -301
- package/packages/provider-adapter-sdk/dist/src/registry.js.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/tester.d.ts +0 -71
- package/packages/provider-adapter-sdk/dist/src/tester.d.ts.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/tester.js +0 -392
- package/packages/provider-adapter-sdk/dist/src/tester.js.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/types.d.ts +0 -182
- package/packages/provider-adapter-sdk/dist/src/types.d.ts.map +0 -1
- package/packages/provider-adapter-sdk/dist/src/types.js +0 -11
- package/packages/provider-adapter-sdk/dist/src/types.js.map +0 -1
- package/packages/provider-router/dist/capability-registry/src/types.d.ts +0 -47
- package/packages/provider-router/dist/capability-registry/src/types.d.ts.map +0 -1
- package/packages/provider-router/dist/capability-registry/src/types.js +0 -10
- package/packages/provider-router/dist/capability-registry/src/types.js.map +0 -1
- package/packages/provider-router/dist/provider-router/src/index.d.ts +0 -23
- package/packages/provider-router/dist/provider-router/src/index.d.ts.map +0 -1
- package/packages/provider-router/dist/provider-router/src/index.js +0 -25
- package/packages/provider-router/dist/provider-router/src/index.js.map +0 -1
- package/packages/provider-router/dist/provider-router/src/policy.d.ts +0 -10
- package/packages/provider-router/dist/provider-router/src/policy.d.ts.map +0 -1
- package/packages/provider-router/dist/provider-router/src/policy.js +0 -45
- package/packages/provider-router/dist/provider-router/src/policy.js.map +0 -1
- package/packages/provider-router/dist/provider-router/src/provider-router.d.ts +0 -56
- package/packages/provider-router/dist/provider-router/src/provider-router.d.ts.map +0 -1
- package/packages/provider-router/dist/provider-router/src/provider-router.js +0 -222
- package/packages/provider-router/dist/provider-router/src/provider-router.js.map +0 -1
- package/packages/provider-router/dist/provider-router/src/strategies.d.ts +0 -19
- package/packages/provider-router/dist/provider-router/src/strategies.d.ts.map +0 -1
- package/packages/provider-router/dist/provider-router/src/strategies.js +0 -110
- package/packages/provider-router/dist/provider-router/src/strategies.js.map +0 -1
- package/packages/provider-router/dist/provider-router/src/types.d.ts +0 -91
- package/packages/provider-router/dist/provider-router/src/types.d.ts.map +0 -1
- package/packages/provider-router/dist/provider-router/src/types.js +0 -10
- package/packages/provider-router/dist/provider-router/src/types.js.map +0 -1
- package/packages/provider-router/dist/src/index.d.ts +0 -23
- package/packages/provider-router/dist/src/index.d.ts.map +0 -1
- package/packages/provider-router/dist/src/index.js +0 -25
- package/packages/provider-router/dist/src/index.js.map +0 -1
- package/packages/provider-router/dist/src/policy.d.ts +0 -10
- package/packages/provider-router/dist/src/policy.d.ts.map +0 -1
- package/packages/provider-router/dist/src/policy.js +0 -45
- package/packages/provider-router/dist/src/policy.js.map +0 -1
- package/packages/provider-router/dist/src/provider-router.d.ts +0 -56
- package/packages/provider-router/dist/src/provider-router.d.ts.map +0 -1
- package/packages/provider-router/dist/src/provider-router.js +0 -222
- package/packages/provider-router/dist/src/provider-router.js.map +0 -1
- package/packages/provider-router/dist/src/strategies.d.ts +0 -19
- package/packages/provider-router/dist/src/strategies.d.ts.map +0 -1
- package/packages/provider-router/dist/src/strategies.js +0 -110
- package/packages/provider-router/dist/src/strategies.js.map +0 -1
- package/packages/provider-router/dist/src/types.d.ts +0 -91
- package/packages/provider-router/dist/src/types.d.ts.map +0 -1
- package/packages/provider-router/dist/src/types.js +0 -10
- package/packages/provider-router/dist/src/types.js.map +0 -1
- package/packages/provider-router/dist/types/src/runtime-types.d.ts +0 -412
- package/packages/provider-router/dist/types/src/runtime-types.d.ts.map +0 -1
- package/packages/provider-router/dist/types/src/runtime-types.js +0 -2
- package/packages/provider-router/dist/types/src/runtime-types.js.map +0 -1
- package/packages/session-api/dist/api.d.ts +0 -83
- package/packages/session-api/dist/api.js +0 -35
- package/packages/session-api/dist/index.d.ts +0 -2
- package/packages/session-api/dist/index.js +0 -2
- package/packages/session-api/dist/types.d.ts +0 -22
- package/packages/session-api/dist/types.js +0 -5
- package/packages/session-export/dist/exporter.d.ts +0 -28
- package/packages/session-export/dist/exporter.js +0 -38
- package/packages/session-export/dist/index.d.ts +0 -2
- package/packages/session-export/dist/index.js +0 -2
- package/packages/session-export/dist/types.d.ts +0 -20
- package/packages/session-export/dist/types.js +0 -5
- package/packages/subscription-engine/dist/engine.d.ts +0 -13
- package/packages/subscription-engine/dist/engine.js +0 -40
- package/packages/subscription-engine/dist/index.d.ts +0 -2
- package/packages/subscription-engine/dist/index.js +0 -2
- package/packages/subscription-engine/dist/subscriptions.d.ts +0 -19
- package/packages/subscription-engine/dist/subscriptions.js +0 -32
- package/packages/subscription-engine/dist/types.d.ts +0 -24
- package/packages/subscription-engine/dist/types.js +0 -5
- package/packages/trajectory/test/store.test.d.ts +0 -2
- package/packages/workflow-events/dist/events.d.ts +0 -38
- package/packages/workflow-events/dist/events.js +0 -46
- package/packages/workflow-events/dist/index.d.ts +0 -2
- package/packages/workflow-events/dist/index.js +0 -2
- package/packages/workflow-events/dist/pipeline.d.ts +0 -21
- package/packages/workflow-events/dist/pipeline.js +0 -27
- package/packages/workflow-events/dist/types.d.ts +0 -110
- package/packages/workflow-events/dist/types.js +0 -5
- package/packages/workflow-events/src/types.d.ts +0 -110
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram turn-building helpers
|
|
3
|
+
* Zones: telegram inbound, pi agent prompt content, queue
|
|
4
|
+
* Owns prompt-turn summary and content construction so queued Telegram turns are assembled consistently
|
|
5
|
+
*/
|
|
6
|
+
import { type DownloadedTelegramMessageFile, type DownloadTelegramMessageFilesDeps, type TelegramMediaMessage } from "./media.ts";
|
|
7
|
+
import { truncateTelegramQueueSummary, type PendingTelegramTurn, type TelegramPreparedPromptTurn, type TelegramQueueItem, type TelegramQueueStore } from "./queue.ts";
|
|
8
|
+
import { type TelegramVoiceReplyMode } from "./voice.ts";
|
|
9
|
+
export declare const TELEGRAM_PREFIX = "[telegram]";
|
|
10
|
+
export declare const TELEGRAM_GUEST_TURN_NOTE = "[guest] delivery: answer quickly with one concise, self-contained reply";
|
|
11
|
+
export interface TelegramTurnTarget {
|
|
12
|
+
chatId: number;
|
|
13
|
+
threadId?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TelegramTurnMessage {
|
|
16
|
+
message_id: number;
|
|
17
|
+
message_thread_id?: number;
|
|
18
|
+
pi_telegram_agent_source_thread?: string;
|
|
19
|
+
pi_telegram_source_update_id?: number;
|
|
20
|
+
chat: {
|
|
21
|
+
id: number;
|
|
22
|
+
type?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export type DownloadedTelegramTurnFile = DownloadedTelegramMessageFile;
|
|
26
|
+
export declare function createTelegramTurnPrefix(attributes?: Record<string, string | undefined>): string;
|
|
27
|
+
export { truncateTelegramQueueSummary };
|
|
28
|
+
export declare function formatTelegramTurnStatusSummary(rawText: string, files: DownloadedTelegramTurnFile[], handlerOutputs?: string[]): string;
|
|
29
|
+
export declare function buildTelegramTurnPrompt(options: {
|
|
30
|
+
telegramPrefix: string;
|
|
31
|
+
rawText: string;
|
|
32
|
+
files: DownloadedTelegramTurnFile[];
|
|
33
|
+
promptFiles?: DownloadedTelegramTurnFile[];
|
|
34
|
+
displayFiles?: DownloadedTelegramTurnFile[];
|
|
35
|
+
handlerOutputs?: string[];
|
|
36
|
+
sourceContext?: string;
|
|
37
|
+
historyTurns?: Pick<PendingTelegramTurn, "historyText">[];
|
|
38
|
+
timeLine?: string | null;
|
|
39
|
+
voiceContext?: Record<string, string>;
|
|
40
|
+
guestTurn?: boolean;
|
|
41
|
+
}): string;
|
|
42
|
+
export declare function updateTelegramPromptTurnText(options: {
|
|
43
|
+
turn: PendingTelegramTurn;
|
|
44
|
+
telegramPrefix: string;
|
|
45
|
+
rawText: string;
|
|
46
|
+
statusText?: string;
|
|
47
|
+
}): PendingTelegramTurn;
|
|
48
|
+
export declare function updateQueuedTelegramPromptTurnText<TContext = unknown>(options: {
|
|
49
|
+
items: TelegramQueueItem<TContext>[];
|
|
50
|
+
sourceMessageId: number | undefined;
|
|
51
|
+
telegramPrefix: string;
|
|
52
|
+
rawText: string;
|
|
53
|
+
statusText?: string;
|
|
54
|
+
}): {
|
|
55
|
+
items: TelegramQueueItem<TContext>[];
|
|
56
|
+
changed: boolean;
|
|
57
|
+
};
|
|
58
|
+
export interface TelegramQueuedPromptEditRuntimeDeps<TContext = unknown> extends TelegramQueueStore<TContext> {
|
|
59
|
+
updateStatus: (ctx: TContext) => void;
|
|
60
|
+
}
|
|
61
|
+
export declare function createTelegramQueuedPromptEditRuntime<TMessage extends TelegramMediaMessage, TContext = unknown>(deps: TelegramQueuedPromptEditRuntimeDeps<TContext>): {
|
|
62
|
+
updateFromEditedMessage: (message: TMessage, ctx: TContext) => boolean;
|
|
63
|
+
};
|
|
64
|
+
export interface BuildTelegramPromptTurnOptions {
|
|
65
|
+
telegramPrefix: string;
|
|
66
|
+
messages: TelegramTurnMessage[];
|
|
67
|
+
historyTurns?: PendingTelegramTurn[];
|
|
68
|
+
queueOrder: number;
|
|
69
|
+
rawText: string;
|
|
70
|
+
statusText?: string;
|
|
71
|
+
files: DownloadedTelegramTurnFile[];
|
|
72
|
+
promptFiles?: DownloadedTelegramTurnFile[];
|
|
73
|
+
displayFiles?: DownloadedTelegramTurnFile[];
|
|
74
|
+
handlerOutputs?: string[];
|
|
75
|
+
sourceContext?: string;
|
|
76
|
+
timeLine?: string | null;
|
|
77
|
+
readBinaryFile: (path: string) => Promise<Uint8Array>;
|
|
78
|
+
inferImageMimeType: (path: string) => string | undefined;
|
|
79
|
+
voiceReplyMode?: TelegramVoiceReplyMode;
|
|
80
|
+
voicePromptContribution?: string;
|
|
81
|
+
admissionScope?: string;
|
|
82
|
+
admissionJournalBinding?: string;
|
|
83
|
+
}
|
|
84
|
+
export type BuildTelegramPromptTurnRuntimeOptions = Omit<BuildTelegramPromptTurnOptions, "readBinaryFile">;
|
|
85
|
+
export interface TelegramPromptTurnRuntimeBuilderDeps<TContext = unknown> extends DownloadTelegramMessageFilesDeps {
|
|
86
|
+
allocateQueueOrder: () => number;
|
|
87
|
+
processAttachments?: (files: DownloadedTelegramTurnFile[], rawText: string, ctx: TContext) => Promise<{
|
|
88
|
+
rawText: string;
|
|
89
|
+
promptFiles?: DownloadedTelegramTurnFile[];
|
|
90
|
+
handlerOutputs?: string[];
|
|
91
|
+
}>;
|
|
92
|
+
resolveTimeLine?: (chatId: number) => string | null;
|
|
93
|
+
getVoiceReplyMode?: () => TelegramVoiceReplyMode;
|
|
94
|
+
/** Returns the visible thread label for a message target, used to add thread context to the prompt prefix. */
|
|
95
|
+
getTelegramThreadLabel?: (message: {
|
|
96
|
+
chat: {
|
|
97
|
+
id: number;
|
|
98
|
+
};
|
|
99
|
+
message_thread_id?: number;
|
|
100
|
+
}) => string | undefined;
|
|
101
|
+
getAllowedUserId?: () => number | undefined;
|
|
102
|
+
getAdmissionScope?: () => string | undefined;
|
|
103
|
+
getAdmissionJournalBinding?: () => string | undefined;
|
|
104
|
+
assertExecutionCurrent?: (message: TelegramTurnMessage) => void;
|
|
105
|
+
}
|
|
106
|
+
export declare function createTelegramPromptTurnRuntimePreparer<TMessage extends TelegramTurnMessage & TelegramMediaMessage, TContext = unknown>(deps: TelegramPromptTurnRuntimeBuilderDeps<TContext>): (messages: TMessage[], ctx?: TContext) => Promise<TelegramPreparedPromptTurn>;
|
|
107
|
+
export declare function buildTelegramPromptTurn(options: BuildTelegramPromptTurnOptions): Promise<PendingTelegramTurn>;
|
|
108
|
+
export declare function buildTelegramPromptTurnRuntime(options: BuildTelegramPromptTurnRuntimeOptions): Promise<PendingTelegramTurn>;
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram turn-building helpers
|
|
3
|
+
* Zones: telegram inbound, pi agent prompt content, queue
|
|
4
|
+
* Owns prompt-turn summary and content construction so queued Telegram turns are assembled consistently
|
|
5
|
+
*/
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import { appendTelegramAttachmentSection, appendTelegramListSection, buildTelegramReplyContextBlock, collectTelegramFileInfos, collectTelegramMessageIds, downloadTelegramMessageFiles, extractTelegramForwardContextText, extractTelegramMessagesPromptText, extractTelegramMessagesText, extractTelegramMessageText, formatTelegramHistoryText, guessMediaType, } from "./media.js";
|
|
9
|
+
import { createTelegramQueueAdmissionReceipt, truncateTelegramQueueSummary, } from "./queue.js";
|
|
10
|
+
import { computeVoicePromptContribution, computeVoiceTurnFlags, getTelegramVoiceReplyMode, } from "./voice.js";
|
|
11
|
+
export const TELEGRAM_PREFIX = "[telegram]";
|
|
12
|
+
export const TELEGRAM_GUEST_TURN_NOTE = "[guest] delivery: answer quickly with one concise, self-contained reply";
|
|
13
|
+
function getTelegramTurnTarget(message) {
|
|
14
|
+
return Number.isInteger(message.message_thread_id)
|
|
15
|
+
? { chatId: message.chat.id, threadId: message.message_thread_id }
|
|
16
|
+
: { chatId: message.chat.id };
|
|
17
|
+
}
|
|
18
|
+
function formatTelegramPrefixAttributeValue(value) {
|
|
19
|
+
return value
|
|
20
|
+
.replace(/[\]\n\r|]+/g, " ")
|
|
21
|
+
.replace(/\s+/g, " ")
|
|
22
|
+
.trim();
|
|
23
|
+
}
|
|
24
|
+
export function createTelegramTurnPrefix(attributes = {}) {
|
|
25
|
+
const parts = [TELEGRAM_PREFIX.slice(1, -1)];
|
|
26
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
27
|
+
const normalized = value ? formatTelegramPrefixAttributeValue(value) : "";
|
|
28
|
+
if (normalized)
|
|
29
|
+
parts.push(`${key}:${normalized}`);
|
|
30
|
+
}
|
|
31
|
+
return `[${parts.join("|")}]`;
|
|
32
|
+
}
|
|
33
|
+
function formatTelegramTurnPrefix(_message, basePrefix = TELEGRAM_PREFIX) {
|
|
34
|
+
return basePrefix;
|
|
35
|
+
}
|
|
36
|
+
export { truncateTelegramQueueSummary };
|
|
37
|
+
export function formatTelegramTurnStatusSummary(rawText, files, handlerOutputs = []) {
|
|
38
|
+
const textSummary = truncateTelegramQueueSummary(rawText);
|
|
39
|
+
if (textSummary)
|
|
40
|
+
return textSummary;
|
|
41
|
+
const handlerSummary = truncateTelegramQueueSummary(handlerOutputs.join(" "));
|
|
42
|
+
if (handlerSummary)
|
|
43
|
+
return handlerSummary;
|
|
44
|
+
if (files.length === 1) {
|
|
45
|
+
const fileName = basename(files[0]?.fileName || files[0]?.path || "attachment");
|
|
46
|
+
return `📎 ${truncateTelegramQueueSummary(fileName, 4, 32) || "attachment"}`;
|
|
47
|
+
}
|
|
48
|
+
if (files.length > 1)
|
|
49
|
+
return `📎 ${files.length} attachments`;
|
|
50
|
+
return "(empty message)";
|
|
51
|
+
}
|
|
52
|
+
function appendTelegramSourceContext(text, sourceContext) {
|
|
53
|
+
if (!sourceContext)
|
|
54
|
+
return text;
|
|
55
|
+
return text ? `${text}\n\n${sourceContext}` : sourceContext;
|
|
56
|
+
}
|
|
57
|
+
function buildTelegramForwardContextBlock(options) {
|
|
58
|
+
const metadata = options.context.replace(/:\s+/g, ":");
|
|
59
|
+
const from = metadata.match(/^from:(.+)$/)?.[1];
|
|
60
|
+
let block = `[forward|${metadata}]${options.text ? ` ${options.text}` : ""}`;
|
|
61
|
+
if (options.files.length === 0)
|
|
62
|
+
return block;
|
|
63
|
+
const dirs = [...new Set(options.files.map((file) => dirname(file.path)))];
|
|
64
|
+
const sameDir = dirs.length === 1;
|
|
65
|
+
const header = `[attachments${from ? `|from:${from}` : ""}]${sameDir ? ` ${dirs[0]}` : ""}`;
|
|
66
|
+
const items = sameDir
|
|
67
|
+
? options.files.map((file) => `/${basename(file.path)}`)
|
|
68
|
+
: options.files.map((file) => file.path);
|
|
69
|
+
block += `\n\n${header}\n${items.map((item) => `- ${item}`).join("\n")}`;
|
|
70
|
+
return block;
|
|
71
|
+
}
|
|
72
|
+
function appendTelegramPromptText(prompt, rawText) {
|
|
73
|
+
if (!rawText)
|
|
74
|
+
return prompt;
|
|
75
|
+
if (rawText.startsWith("\n"))
|
|
76
|
+
return `${prompt}${rawText}`;
|
|
77
|
+
return `${prompt} ${rawText}`;
|
|
78
|
+
}
|
|
79
|
+
function appendTelegramVoiceContext(prompt, entries) {
|
|
80
|
+
const prefix = prompt.length > 0 ? `${prompt}\n\n` : "";
|
|
81
|
+
const pairs = Object.entries(entries);
|
|
82
|
+
if (pairs.length === 1) {
|
|
83
|
+
const [key, value] = pairs[0];
|
|
84
|
+
return `${prefix}[voice] ${key}: ${value}`;
|
|
85
|
+
}
|
|
86
|
+
return `${prefix}[voice]\n${pairs
|
|
87
|
+
.map(([key, value]) => `- ${key}: ${value}`)
|
|
88
|
+
.join("\n")}`;
|
|
89
|
+
}
|
|
90
|
+
// --- Voice Policy And Tagging ---
|
|
91
|
+
export function buildTelegramTurnPrompt(options) {
|
|
92
|
+
let prompt = options.telegramPrefix;
|
|
93
|
+
if ((options.historyTurns?.length ?? 0) > 0) {
|
|
94
|
+
prompt +=
|
|
95
|
+
"\n\nEarlier Telegram messages arrived after an aborted turn. Treat them as prior user messages, in order:";
|
|
96
|
+
for (const [index, turn] of (options.historyTurns ?? []).entries()) {
|
|
97
|
+
prompt += `\n\n${index + 1}. ${turn.historyText}`;
|
|
98
|
+
}
|
|
99
|
+
prompt += "\n\nCurrent Telegram message:";
|
|
100
|
+
}
|
|
101
|
+
if (options.rawText.length > 0) {
|
|
102
|
+
prompt =
|
|
103
|
+
(options.historyTurns?.length ?? 0) > 0
|
|
104
|
+
? `${prompt}\n${options.rawText}`
|
|
105
|
+
: appendTelegramPromptText(prompt, options.rawText);
|
|
106
|
+
}
|
|
107
|
+
const displayFiles = options.displayFiles ?? options.promptFiles ?? options.files;
|
|
108
|
+
prompt = appendTelegramAttachmentSection(prompt, displayFiles);
|
|
109
|
+
prompt = appendTelegramListSection(prompt, "outputs", options.handlerOutputs ?? []);
|
|
110
|
+
prompt = appendTelegramSourceContext(prompt, options.sourceContext);
|
|
111
|
+
if (options.voiceContext) {
|
|
112
|
+
prompt = appendTelegramVoiceContext(prompt, options.voiceContext);
|
|
113
|
+
}
|
|
114
|
+
if (options.timeLine) {
|
|
115
|
+
prompt = `${prompt}\n\n[time] ${options.timeLine}`;
|
|
116
|
+
}
|
|
117
|
+
if (options.guestTurn) {
|
|
118
|
+
prompt = `${prompt}\n\n${TELEGRAM_GUEST_TURN_NOTE}`;
|
|
119
|
+
}
|
|
120
|
+
return prompt;
|
|
121
|
+
}
|
|
122
|
+
function splitTelegramPromptAttachmentSuffix(prompt) {
|
|
123
|
+
const marker = "\n\n[attachments]";
|
|
124
|
+
const markerIndex = prompt.indexOf(marker);
|
|
125
|
+
if (markerIndex === -1) {
|
|
126
|
+
return {
|
|
127
|
+
promptWithoutAttachments: prompt,
|
|
128
|
+
attachmentSuffix: "",
|
|
129
|
+
attachmentFiles: [],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const promptWithoutAttachments = prompt.slice(0, markerIndex);
|
|
133
|
+
const attachmentSuffix = prompt.slice(markerIndex);
|
|
134
|
+
const attachmentLines = [];
|
|
135
|
+
let readingAttachments = false;
|
|
136
|
+
let attachmentDir;
|
|
137
|
+
for (const line of attachmentSuffix.split("\n")) {
|
|
138
|
+
const trimmed = line.trim();
|
|
139
|
+
const attachmentMatch = trimmed.match(/^\[attachments\](?:\s+(.+))?$/);
|
|
140
|
+
if (attachmentMatch) {
|
|
141
|
+
readingAttachments = true;
|
|
142
|
+
attachmentDir = attachmentMatch[1]?.trim();
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (readingAttachments && /^\[[^\]]+\](?:\s+.*)?$/.test(trimmed))
|
|
146
|
+
break;
|
|
147
|
+
if (readingAttachments)
|
|
148
|
+
attachmentLines.push(line);
|
|
149
|
+
}
|
|
150
|
+
const attachmentFiles = attachmentLines
|
|
151
|
+
.map((line) => line.match(/^- (.+)$/)?.[1]?.trim())
|
|
152
|
+
.filter((path) => !!path)
|
|
153
|
+
.map((path) => attachmentDir ? join(attachmentDir, path.replace(/^\/+/, "")) : path)
|
|
154
|
+
.map((path) => ({
|
|
155
|
+
path,
|
|
156
|
+
fileName: basename(path),
|
|
157
|
+
isImage: false,
|
|
158
|
+
kind: "document",
|
|
159
|
+
}));
|
|
160
|
+
return { promptWithoutAttachments, attachmentSuffix, attachmentFiles };
|
|
161
|
+
}
|
|
162
|
+
function buildEditedTelegramPromptText(options) {
|
|
163
|
+
const { promptWithoutAttachments, attachmentSuffix, attachmentFiles } = splitTelegramPromptAttachmentSuffix(options.existingPrompt);
|
|
164
|
+
const currentMessageMarker = "Current Telegram message:";
|
|
165
|
+
const currentMessageIndex = promptWithoutAttachments.lastIndexOf(currentMessageMarker);
|
|
166
|
+
if (currentMessageIndex !== -1) {
|
|
167
|
+
const prefix = promptWithoutAttachments.slice(0, currentMessageIndex + currentMessageMarker.length);
|
|
168
|
+
const separator = options.rawText.length > 0 ? "\n" : "";
|
|
169
|
+
return {
|
|
170
|
+
text: `${prefix}${separator}${options.rawText}${attachmentSuffix}`,
|
|
171
|
+
attachmentFiles,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
text: `${appendTelegramPromptText(options.telegramPrefix, options.rawText)}${attachmentSuffix}`,
|
|
176
|
+
attachmentFiles,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export function updateTelegramPromptTurnText(options) {
|
|
180
|
+
let attachmentFiles = [];
|
|
181
|
+
const nextContent = options.turn.content.map((block, index) => {
|
|
182
|
+
if (index !== 0 || block.type !== "text")
|
|
183
|
+
return block;
|
|
184
|
+
const updated = buildEditedTelegramPromptText({
|
|
185
|
+
existingPrompt: block.text,
|
|
186
|
+
telegramPrefix: options.telegramPrefix,
|
|
187
|
+
rawText: options.rawText,
|
|
188
|
+
});
|
|
189
|
+
attachmentFiles = updated.attachmentFiles;
|
|
190
|
+
return {
|
|
191
|
+
...block,
|
|
192
|
+
text: updated.text,
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
...options.turn,
|
|
197
|
+
content: nextContent,
|
|
198
|
+
historyText: formatTelegramHistoryText(options.rawText, attachmentFiles),
|
|
199
|
+
statusSummary: formatTelegramTurnStatusSummary(options.statusText ?? options.rawText, attachmentFiles),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export function updateQueuedTelegramPromptTurnText(options) {
|
|
203
|
+
if (options.sourceMessageId === undefined) {
|
|
204
|
+
return { items: options.items, changed: false };
|
|
205
|
+
}
|
|
206
|
+
let changed = false;
|
|
207
|
+
const items = options.items.map((item) => {
|
|
208
|
+
if (item.kind !== "prompt" ||
|
|
209
|
+
!item.sourceMessageIds.includes(options.sourceMessageId)) {
|
|
210
|
+
return item;
|
|
211
|
+
}
|
|
212
|
+
changed = true;
|
|
213
|
+
return updateTelegramPromptTurnText({
|
|
214
|
+
turn: item,
|
|
215
|
+
telegramPrefix: options.telegramPrefix,
|
|
216
|
+
rawText: options.rawText,
|
|
217
|
+
statusText: options.statusText,
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
return { items, changed };
|
|
221
|
+
}
|
|
222
|
+
export function createTelegramQueuedPromptEditRuntime(deps) {
|
|
223
|
+
return {
|
|
224
|
+
updateFromEditedMessage: (message, ctx) => {
|
|
225
|
+
const { changed, items } = updateQueuedTelegramPromptTurnText({
|
|
226
|
+
items: deps.getQueuedItems(),
|
|
227
|
+
sourceMessageId: message.message_id,
|
|
228
|
+
telegramPrefix: TELEGRAM_PREFIX,
|
|
229
|
+
rawText: extractTelegramMessagesPromptText([message]),
|
|
230
|
+
statusText: extractTelegramMessagesText([message]),
|
|
231
|
+
});
|
|
232
|
+
deps.setQueuedItems(items);
|
|
233
|
+
if (changed)
|
|
234
|
+
deps.updateStatus(ctx);
|
|
235
|
+
return changed;
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
export function createTelegramPromptTurnRuntimePreparer(deps) {
|
|
240
|
+
return async (messages, ctx) => {
|
|
241
|
+
const rawText = extractTelegramMessagesText(messages);
|
|
242
|
+
const firstMessage = messages[0];
|
|
243
|
+
if (firstMessage)
|
|
244
|
+
deps.assertExecutionCurrent?.(firstMessage);
|
|
245
|
+
const replyFiles = firstMessage?.reply_to_message
|
|
246
|
+
? await downloadTelegramMessageFiles([firstMessage.reply_to_message], { downloadFile: deps.downloadFile })
|
|
247
|
+
: [];
|
|
248
|
+
if (firstMessage)
|
|
249
|
+
deps.assertExecutionCurrent?.(firstMessage);
|
|
250
|
+
const processedReply = deps.processAttachments && replyFiles.length > 0
|
|
251
|
+
? await deps.processAttachments(replyFiles, "", ctx)
|
|
252
|
+
: undefined;
|
|
253
|
+
if (firstMessage)
|
|
254
|
+
deps.assertExecutionCurrent?.(firstMessage);
|
|
255
|
+
const replyContext = firstMessage
|
|
256
|
+
? buildTelegramReplyContextBlock(firstMessage, processedReply?.promptFiles ?? replyFiles, processedReply?.handlerOutputs)
|
|
257
|
+
: "";
|
|
258
|
+
const forwardEntries = messages.flatMap((message) => {
|
|
259
|
+
const context = extractTelegramForwardContextText(message, deps.getAllowedUserId?.());
|
|
260
|
+
return context
|
|
261
|
+
? [
|
|
262
|
+
{
|
|
263
|
+
context,
|
|
264
|
+
text: extractTelegramMessageText(message),
|
|
265
|
+
message,
|
|
266
|
+
fileNames: new Set(collectTelegramFileInfos([message]).map((file) => file.fileName)),
|
|
267
|
+
},
|
|
268
|
+
]
|
|
269
|
+
: [];
|
|
270
|
+
});
|
|
271
|
+
const files = await downloadTelegramMessageFiles(messages, {
|
|
272
|
+
downloadFile: deps.downloadFile,
|
|
273
|
+
});
|
|
274
|
+
if (firstMessage)
|
|
275
|
+
deps.assertExecutionCurrent?.(firstMessage);
|
|
276
|
+
const processed = deps.processAttachments
|
|
277
|
+
? await deps.processAttachments(files, rawText, ctx)
|
|
278
|
+
: { rawText, promptFiles: files };
|
|
279
|
+
if (firstMessage)
|
|
280
|
+
deps.assertExecutionCurrent?.(firstMessage);
|
|
281
|
+
const sourceBlocks = [];
|
|
282
|
+
let promptRawText = processed.rawText;
|
|
283
|
+
const forwardedFilePaths = new Set();
|
|
284
|
+
const getForwardFiles = (entry) => (processed.promptFiles ?? files).filter((file) => {
|
|
285
|
+
if (!entry.fileNames.has(file.fileName))
|
|
286
|
+
return false;
|
|
287
|
+
forwardedFilePaths.add(file.path);
|
|
288
|
+
return true;
|
|
289
|
+
});
|
|
290
|
+
if (forwardEntries.length === 1 && messages.length === 1) {
|
|
291
|
+
const [forward] = forwardEntries;
|
|
292
|
+
sourceBlocks.push(buildTelegramForwardContextBlock({
|
|
293
|
+
context: forward.context,
|
|
294
|
+
text: processed.rawText,
|
|
295
|
+
files: getForwardFiles(forward),
|
|
296
|
+
}));
|
|
297
|
+
promptRawText = "";
|
|
298
|
+
}
|
|
299
|
+
else if (forwardEntries.length > 0 && processed.rawText === rawText) {
|
|
300
|
+
const forwardedMessages = new Set(forwardEntries.map((entry) => entry.message));
|
|
301
|
+
promptRawText = messages
|
|
302
|
+
.filter((message) => !forwardedMessages.has(message))
|
|
303
|
+
.map(extractTelegramMessageText)
|
|
304
|
+
.filter(Boolean)
|
|
305
|
+
.join("\n\n");
|
|
306
|
+
sourceBlocks.push(...forwardEntries.map((entry) => buildTelegramForwardContextBlock({
|
|
307
|
+
context: entry.context,
|
|
308
|
+
text: entry.text,
|
|
309
|
+
files: getForwardFiles(entry),
|
|
310
|
+
})));
|
|
311
|
+
}
|
|
312
|
+
else if (forwardEntries.length > 0) {
|
|
313
|
+
sourceBlocks.push(...forwardEntries.map((entry) => buildTelegramForwardContextBlock({
|
|
314
|
+
context: entry.context,
|
|
315
|
+
text: "",
|
|
316
|
+
files: getForwardFiles(entry),
|
|
317
|
+
})));
|
|
318
|
+
}
|
|
319
|
+
if (replyContext)
|
|
320
|
+
sourceBlocks.push(replyContext);
|
|
321
|
+
const sourceContext = sourceBlocks.join("\n\n");
|
|
322
|
+
// Compute voice mode once and pass it to both the turn builder and the prompt contribution helper
|
|
323
|
+
const voiceReplyMode = deps.getVoiceReplyMode?.();
|
|
324
|
+
const chatId = messages[0]?.chat.id;
|
|
325
|
+
const timeLine = deps.resolveTimeLine && chatId !== undefined
|
|
326
|
+
? deps.resolveTimeLine(chatId)
|
|
327
|
+
: null;
|
|
328
|
+
const threadLabel = firstMessage
|
|
329
|
+
? deps.getTelegramThreadLabel?.(firstMessage)
|
|
330
|
+
: undefined;
|
|
331
|
+
const telegramPrefix = createTelegramTurnPrefix({
|
|
332
|
+
thread: threadLabel,
|
|
333
|
+
"from-thread": firstMessage?.pi_telegram_agent_source_thread,
|
|
334
|
+
});
|
|
335
|
+
const buildTurn = await prepareTelegramPromptTurn({
|
|
336
|
+
telegramPrefix,
|
|
337
|
+
messages,
|
|
338
|
+
readBinaryFile: readFile,
|
|
339
|
+
rawText: promptRawText,
|
|
340
|
+
sourceContext,
|
|
341
|
+
statusText: processed.rawText,
|
|
342
|
+
files,
|
|
343
|
+
promptFiles: processed.promptFiles,
|
|
344
|
+
displayFiles: (processed.promptFiles ?? files).filter((file) => !forwardedFilePaths.has(file.path)),
|
|
345
|
+
handlerOutputs: processed.handlerOutputs,
|
|
346
|
+
timeLine,
|
|
347
|
+
inferImageMimeType: guessMediaType,
|
|
348
|
+
voiceReplyMode,
|
|
349
|
+
voicePromptContribution: computeVoicePromptContribution(voiceReplyMode, files, rawText),
|
|
350
|
+
admissionScope: deps.getAdmissionScope?.(),
|
|
351
|
+
admissionJournalBinding: deps.getAdmissionJournalBinding?.(),
|
|
352
|
+
});
|
|
353
|
+
return (historyTurns) => {
|
|
354
|
+
if (firstMessage)
|
|
355
|
+
deps.assertExecutionCurrent?.(firstMessage);
|
|
356
|
+
return buildTurn(deps.allocateQueueOrder(), historyTurns);
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function getTelegramVoicePromptContext(voiceReplyMode, hasVoiceFile) {
|
|
361
|
+
if (voiceReplyMode !== "always" &&
|
|
362
|
+
!(voiceReplyMode === "mirror" && hasVoiceFile)) {
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
return { delivery: "automatic voice" };
|
|
366
|
+
}
|
|
367
|
+
function collectTelegramTurnAdmissionReceipts(messages, historyTurns, admissionScope, admissionJournalBinding) {
|
|
368
|
+
const receipts = new Map();
|
|
369
|
+
const addReceipt = (receipt) => {
|
|
370
|
+
const existing = receipts.get(receipt.receiptId);
|
|
371
|
+
if (existing) {
|
|
372
|
+
if (existing.queueKind !== receipt.queueKind ||
|
|
373
|
+
existing.journalBindingKey !== receipt.journalBindingKey ||
|
|
374
|
+
existing.sourceUpdateIds.length !== receipt.sourceUpdateIds.length ||
|
|
375
|
+
existing.sourceUpdateIds.some((updateId, index) => updateId !== receipt.sourceUpdateIds[index])) {
|
|
376
|
+
throw new Error(`Conflicting Telegram turn receipt: ${receipt.receiptId}`);
|
|
377
|
+
}
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
receipts.set(receipt.receiptId, structuredClone(receipt));
|
|
381
|
+
};
|
|
382
|
+
for (const turn of historyTurns) {
|
|
383
|
+
for (const receipt of turn.admissionReceipts ?? [])
|
|
384
|
+
addReceipt(receipt);
|
|
385
|
+
}
|
|
386
|
+
const sourceUpdateIds = messages.flatMap((message) => typeof message.pi_telegram_source_update_id === "number"
|
|
387
|
+
? [message.pi_telegram_source_update_id]
|
|
388
|
+
: []);
|
|
389
|
+
if (sourceUpdateIds.length > 0) {
|
|
390
|
+
const currentReceipt = createTelegramQueueAdmissionReceipt({
|
|
391
|
+
queueKind: "prompt",
|
|
392
|
+
scope: admissionScope ?? "",
|
|
393
|
+
sourceUpdateIds,
|
|
394
|
+
});
|
|
395
|
+
if (currentReceipt) {
|
|
396
|
+
addReceipt({
|
|
397
|
+
...currentReceipt,
|
|
398
|
+
...(admissionJournalBinding
|
|
399
|
+
? { journalBindingKey: admissionJournalBinding }
|
|
400
|
+
: {}),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return [...receipts.values()];
|
|
405
|
+
}
|
|
406
|
+
async function prepareTelegramPromptTurn(options) {
|
|
407
|
+
const images = [];
|
|
408
|
+
for (const file of options.files) {
|
|
409
|
+
if (!file.isImage)
|
|
410
|
+
continue;
|
|
411
|
+
const mediaType = file.mimeType || options.inferImageMimeType(file.path);
|
|
412
|
+
if (!mediaType)
|
|
413
|
+
continue;
|
|
414
|
+
const buffer = await options.readBinaryFile(file.path);
|
|
415
|
+
images.push({
|
|
416
|
+
type: "image",
|
|
417
|
+
data: Buffer.from(buffer).toString("base64"),
|
|
418
|
+
mimeType: mediaType,
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return (queueOrder, historyTurns) => buildPreparedTelegramPromptTurn({ ...options, queueOrder, historyTurns }, images);
|
|
422
|
+
}
|
|
423
|
+
function buildPreparedTelegramPromptTurn(options, images) {
|
|
424
|
+
const firstMessage = options.messages[0];
|
|
425
|
+
if (!firstMessage) {
|
|
426
|
+
throw new Error("Missing Telegram message for turn creation");
|
|
427
|
+
}
|
|
428
|
+
const hasVoiceFile = options.files.some((f) => f.kind === "voice" || f.kind === "audio");
|
|
429
|
+
const voiceReplyMode = options.voiceReplyMode ?? getTelegramVoiceReplyMode();
|
|
430
|
+
const content = [
|
|
431
|
+
{
|
|
432
|
+
type: "text",
|
|
433
|
+
text: buildTelegramTurnPrompt({
|
|
434
|
+
telegramPrefix: formatTelegramTurnPrefix(firstMessage, options.telegramPrefix),
|
|
435
|
+
rawText: options.rawText,
|
|
436
|
+
files: options.files,
|
|
437
|
+
promptFiles: options.promptFiles,
|
|
438
|
+
displayFiles: options.displayFiles,
|
|
439
|
+
handlerOutputs: options.handlerOutputs,
|
|
440
|
+
sourceContext: options.sourceContext,
|
|
441
|
+
historyTurns: options.historyTurns,
|
|
442
|
+
timeLine: options.timeLine,
|
|
443
|
+
voiceContext: getTelegramVoicePromptContext(voiceReplyMode, hasVoiceFile),
|
|
444
|
+
}),
|
|
445
|
+
},
|
|
446
|
+
...images,
|
|
447
|
+
];
|
|
448
|
+
if (options.voicePromptContribution?.trim()) {
|
|
449
|
+
const textItem = content.find((c) => c.type === "text");
|
|
450
|
+
if (textItem) {
|
|
451
|
+
textItem.text = `${textItem.text}\n\n${options.voicePromptContribution.trim()}`;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const admissionReceipts = collectTelegramTurnAdmissionReceipts(options.messages, options.historyTurns ?? [], options.admissionScope, options.admissionJournalBinding);
|
|
455
|
+
return {
|
|
456
|
+
kind: "prompt",
|
|
457
|
+
chatId: firstMessage.chat.id,
|
|
458
|
+
target: getTelegramTurnTarget(firstMessage),
|
|
459
|
+
replyToMessageId: firstMessage.message_id,
|
|
460
|
+
sourceMessageIds: collectTelegramMessageIds(options.messages),
|
|
461
|
+
queueOrder: options.queueOrder,
|
|
462
|
+
queueLane: "default",
|
|
463
|
+
laneOrder: options.queueOrder,
|
|
464
|
+
queuedAttachments: [],
|
|
465
|
+
content,
|
|
466
|
+
historyText: appendTelegramSourceContext(formatTelegramHistoryText(options.rawText, options.displayFiles ?? options.promptFiles ?? options.files, options.handlerOutputs), options.sourceContext),
|
|
467
|
+
statusSummary: formatTelegramTurnStatusSummary(options.statusText ?? options.rawText, options.displayFiles ?? options.promptFiles ?? options.files, options.handlerOutputs),
|
|
468
|
+
...(admissionReceipts.length > 0 ? { admissionReceipts } : {}),
|
|
469
|
+
// Voice tagging (used for preview suppression and prompt guidance)
|
|
470
|
+
...computeVoiceTurnFlags(voiceReplyMode, hasVoiceFile),
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
export async function buildTelegramPromptTurn(options) {
|
|
474
|
+
const buildTurn = await prepareTelegramPromptTurn(options);
|
|
475
|
+
return buildTurn(options.queueOrder, options.historyTurns ?? []);
|
|
476
|
+
}
|
|
477
|
+
export async function buildTelegramPromptTurnRuntime(options) {
|
|
478
|
+
return buildTelegramPromptTurn({
|
|
479
|
+
...options,
|
|
480
|
+
readBinaryFile: readFile,
|
|
481
|
+
});
|
|
482
|
+
}
|