Skip to content

feat(tts): add MiniMax TTS integration for web search results - #234

Closed
almazom wants to merge 153 commits into
openclaw:mainfrom
almazom:feature/web-search-tts
Closed

almazom wants to merge 153 commits into
openclaw:mainfrom
almazom:feature/web-search-tts

Conversation

@almazom

@almazom almazom commented Jan 5, 2026

Copy link
Copy Markdown

Summary

Add "Озвучить" (Voice) button under /web command results that generates audio narration using MiniMax TTS 2.6.

Features

  • ✅ TTS button with progress updates (0% → 25% → 50% → 75% → 100%)
  • ✅ MiniMax API integration with speech-2.6-hd model
  • ✅ Audio caching by result hash (7 day TTL)
  • ✅ Voice: English_CalmWoman, emotion: fluent
  • ✅ Error handling with user-friendly Russian messages

User Flow

/web weather in Moscow
  → Web search result displayed
  → [🔊 Озвучить] button appears
  → User clicks button
  → Progress: ⏳ 0% → ⏳ 25% → ⏳ 50% → ⏳ 75% → ⏳ 100%
  → Audio file sent to chat
  → Button removed

Implementation

  • 7 cards, 15 SP completed via SDD flow
  • Files created:
    • src/tts/types.ts - TTS types
    • src/tts/client.ts - MiniMaxTTSClient
    • src/tts/provider.ts - Provider factory
    • src/tts/button.ts - TTS button factory
    • src/tts/index.ts - Module exports
  • Files modified:
    • src/config/config.ts - TTS config schema
    • src/telegram/bot.ts - Callback handler + web search integration

Configuration

{
  tts: {
    enabled: true,
    minimaxApiKey: "your-api-key",
    model: "speech-2.6-hd",
    voiceId: "English_CalmWoman",
    emotion: "fluent",
    cacheTtlSec: 604800
  }
}

Test Plan

  • Send /web weather in Moscow
  • Verify "🔊 Озвучить" button appears
  • Click button and verify progress updates
  • Verify audio file sent to chat
  • Test cache hit (run same query again)
  • Test error handling

🤖 Generated with Claude Code

almazom and others added 30 commits December 29, 2025 10:57
- Exclude local config files (models.json, settings.json)
- Exclude debug/test scripts (*.mjs, *.js)
- Exclude draft docs (*-SUMMARY.md, investigation.md)
- Exclude deployment files (*.service, ecosystem.config.cjs)
- Exclude backup archives (*.zip)
- Exclude transcription cache (.transcriptions/)
- Exclude temp directories (temp_/)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Ensures consistent pnpm version across environments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Introduces health monitoring for Telegram bot to detect and recover
from unresponsive states. The probe periodically checks bot API
accessibility and logs health status.

- Add startLivenessProbe() function with configurable intervals
- Integrate probe into createTelegramBot() with enable/disable option
- Enable by default for long-polling mode, disable for webhooks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Converts AGENTS.md symlink to a standalone repository guidelines
document for better portability and clarity.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Aligns test file indentation with project formatting standards.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds test coverage for authentication issues specific to Linux
environments. Tests verify credential discovery and API key
retrieval mechanisms.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Provides convenient make targets for common development tasks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds comprehensive documentation for Telegram bot deployment,
testing, and debugging in production environments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Documents authentication issues on Linux and operational
procedures for development and deployment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds shell scripts for Telegram bot lifecycle management:
- Start/stop for PM2 and standalone modes
- Health checks and liveness probes
- Bot status and resume operations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Provides systemd service overrides for production deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Documents investigation and fixes applied to improve Telegram
bot reliability in production.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add transcribe-giga.sh wrapper for vtt_giga_sh/giga.sh with optional
ffmpeg transcoding, temp file cleanup, and error handling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Document GigaAM setup via transcribe-giga.sh wrapper with environment
variables for giga.sh path, transcoding, model, and device.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add test for {{MediaPath}} template variable without download path.
Verify runExec receives correct file path and fetch is bypassed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace scattered module-level test variables with a single
testState object hoisted via vi.hoisted() for better test
isolation and clarity.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Use correct fnm exec --using syntax and default to v22.21.1
via FNM_NODE_VERSION for consistent Node runtime across restarts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Exclude tests/fixtures/ for local test data like audio samples.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add short aliases (start, stop, restart, status, health) and common
pipeline commands (install, build, lint, test, dev, pipeline).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Read proxy config from clawdis.json for Telegram API checks
- Support both .env and ~/.clawdis/secrets.env for token lookup
- Fix token parsing to preserve values with '=' characters

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add get_telegram_proxy() helper for config-based proxy lookup
- Add find_gateway_pid() for flexible process discovery patterns
- Support multi-path env loading (.env and secrets.env)
- Remove 'pipefail' to allow graceful error handling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add load_env() helper for multi-path .env sourcing
- Add get_telegram_proxy() for config-based proxy lookup
- Pass proxy arg to Telegram API webhook checks
- Improve health check output logging for debugging
- Use set -u with set +u guard blocks for env loading

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add TalkModeManager for directive-based audio playback
- Add TalkOrbOverlay UI for visual feedback during talk mode
- Add StreamingMediaDataSource for audio stream handling
- Add TalkDirectiveParser for parsing talk mode commands
- Add JpegSizeLimiter for camera JPEG size optimization
- Add unit tests for parser and size limiter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Tatalmazomam and others added 19 commits January 5, 2026 15:14
Add global tracker to prevent tool abuse/infinite loops with 10 calls/min limit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Instruct agents to pass exact user queries and respect rate limits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add *.mjs pattern for temporary JS modules
- Ignore docs/e2e-telega-v2/ test results directory
- Ignore *_FINAL_REPORT.md and web-search-*-example.md drafts
Replace extensive web search documentation with concise SSOT reference:
- Point to skills/web-search-with-gemini/ as single source of truth
- Keep usage examples and architecture diagram
- Remove verbose patterns, checklists, and best practices
- Focus on when to use vs not use web search
Remove obsolete CLI wrapper script and symlink:
- Delete google-web-cli.sh (173 lines, superseded by skill)
- Delete google_web symlink
- Web search now handled by scripts/web_search_with_gemini.sh (SSOT)
Add [email protected] dependency:
- Convert standard Markdown to Telegram MarkdownV2 format
- Required for proper message formatting in Telegram bot
Enhance web_search_with_gemini.sh script:
- Better error messages and exit codes
- Improve timeout handling
- Add model selection option
Refresh skill documentation to reflect current implementation:
- Update usage examples
- Clarify model selection options
- Document timeout and configuration options
Update Pi agent tool configuration:
- Add google_web_search to available tools
- Configure tool call rate limiting
- Improve web search execution handling
Remove obsolete Gemini CLI wrapper:
- Functionality moved to scripts/web_search_with_gemini.sh
- Simplifies codebase architecture
- SSOT is now shell script based
Refactor web search executor implementation:
- Direct shell script execution instead of Node.js wrapper
- Remove deprecated gemini-cli.ts dependency
- Improve error handling and timeout management
- Simplify code flow for better maintainability
Improve Russian messaging for web search:
- Enhance error messages clarity
- Update status indicators
- Better timeout and failure handling messages
Add Telegram markdown formatting support:
- New formatter.ts with telegramify-markdown integration
- Add formatter.test.ts unit tests
- Integrate formatter into bot.ts for message formatting
- Ensure proper MarkdownV2 escaping for Telegram API
Update deep research module messages:
- Add web search status messages
- Improve error handling text
- Better integration with web search workflow
Update web search configuration:
- Refactor Gemini backend settings
- Add timeout and model selection options
- Improve configuration structure for shell script execution
Generated complete SDD package with requirements, UI flow, gaps, tests, and executable cards
Add "Озвучить" (Voice) button under /web command results that
generates audio narration using MiniMax TTS 2.6.

Features:
- TTS button with progress updates (0% → 100%)
- MiniMax API integration with speech-2.6-hd model
- Audio caching by result hash (7 day TTL)
- Voice: English_CalmWoman, emotion: fluent
- Error handling with user-friendly messages

Implementation (7 cards, 15 SP):
- src/tts/types.ts - TTS types
- src/tts/client.ts - MiniMaxTTSClient
- src/tts/provider.ts - Provider factory
- src/tts/button.ts - TTS button factory
- src/telegram/bot.ts - Callback handler
- src/config/config.ts - TTS config schema

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Critical fixes:
- Add AbortController timeout to fetch (prevents bot hang)
- Redact API key in error messages (security)
- Make file operations async (prevent event loop blocking)
- Use config.maxChars instead of hardcoded MAX_TEXT_LENGTH
- Add input validation for text content (sanitize, min length)
- Add logging for cache failures (debugging)
- Fix hash collision risk (use 16 chars instead of 12)
- Add hex validation for audio response
- Add TTL-based cleanup to ttsInFlight Map (memory leak fix)

Details:
- client.ts: Added timeoutSec, maxChars options; async file ops;
  sanitizeText(), validateHex(), redactError() methods
- types.ts: Added truncated flag to TTSResponse
- provider.ts: Pass maxChars and timeoutSec to client
- button.ts: Use 16 chars (64 bits) for hash instead of 12 (48 bits)
- bot.ts: Convert ttsInFlight from Set to Map with timestamps;
  add periodic cleanup interval (5 min TTL, 1 min cleanup)

Resolves issues from Kimi/Claude code review:
- Missing request timeout
- API key exposure
- Memory leak in ttsInFlight
- Synchronous file operations
- No input validation
- Silent cache failures
- Hash collision risk
- Invalid hex handling
- Config not used (maxChars vs MAX_TEXT_LENGTH)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Improvements:
- Cache stampede protection (promise caching for concurrent requests)
- Periodic cache cleanup (removes expired files every 24h)
- MP3 header validation (ID3/MPEG sync bytes check)
- Config hash-based client invalidation (auto-recreate on config change)
- Truncation notification in voice caption
- Reset mechanism for testing

Details:
- client.ts: Added PendingRequest tracking, cleanupExpiredCache(),
  validateMP3(), cleanupPendingRequests(), doSynthesize() refactor
- provider.ts: getConfigHash(), CachedClient interface, resetTTSClient()
- bot.ts: Caption now shows "(текст укорочен)" when truncated

Confidence boost: 80.5% → 95%
- Fixed cache stampede (HIGH)
- Fixed duplicate config loading (MEDIUM)
- Fixed truncation notification (MEDIUM)
- Fixed cache cleanup (LOW)
- Fixed MP3 validation (LOW)
- Fixed global state (LOW)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@steipete

steipete commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Thank you! Been thinking about this - this should be a skill, ideally on clawdhub.com

@steipete steipete closed this Jan 8, 2026
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 22, 2026
Fato07 referenced this pull request in Fato07/elav Mar 26, 2026
resolveAdapterConfigForRuntime now returns a secretKeys set tracking
which env vars came from secret_ref bindings. The onAdapterMeta
callback uses this to redact them regardless of key name.

Fixes DenchHQ#234

Co-Authored-By: Claude Opus 4.6 <[email protected]>
saml212 added a commit to Rockielab/rockie-claw that referenced this pull request May 18, 2026
…openclaw#234) (#9)

Codex device-flow OAuth races against the broker's /chat handler. The
platform-context auth poller hits /chat?binary=codex every ~4s during
login; each call spawns a fresh `codex exec` in the same tenant HOME
that the held `codex login --device-auth` process is mid-flight on.
Reproduced live on tenant t-99562d476fef: device code expired before
the held login could redeem it; token_exchange_user_error / HTTP 400.

Fix shape (broker-side state machine):

- New `loginState` (apps/broker/auth_state.go) tracks per-binary
  logging-in flags under a mutex. Process-local; broker is per-tenant
  so process-local == per-tenant.

- `wsHandler` sniffs frameStdin payloads for `codex login`,
  `claude setup-token`, `claude /login`. On match, marks the relevant
  binary as logging-in. Marks clear when the WS closes.

- `chatHandler` and `chatPTYHandler` check the flag before spawning.
  When set, return 200 + a single ndjson `{type: error, code:
  auth_in_progress, ...}` frame matching the existing
  `broker_runner_failed` contract — platform-context's /auth probe
  and the unified-agent router both already handle ndjson error
  frames cleanly.

Edge cases verified by tests:
- Per-binary isolation: marking codex doesn't block claude /chat.
- Concurrent mark/clear races (50-way parallel).
- WS close clears all flags set during the session, including
  multiple binaries in one shell.

Reference: rockie-workspace#234.

Co-authored-by: NeverClaudeCode <[email protected]>
saml212 added a commit to Rockielab/rockie-claw that referenced this pull request May 19, 2026
…13)

PR #9 (openclaw#234) closed the race where /chat poll spawns interfered with
an in-flight /login. But it did not cover the symmetric case where
the user "completed" a device-flow that silently failed: the token
exchange returned HTTP 400 (device code expired), auth.json was
never written, and every subsequent /chat invocation spawned codex
which hit HTTP 401 on wss://api.openai.com/v1/responses, retried
five times, and exited non-zero — surfacing in the UI as the generic
"codex exited with: exit status 1" that gave the user no actionable
guidance and ate ~8 seconds per send.

Verified live on tenant rockielab-tenant-t-99562d476fef 2026-05-18:
- /home/runtime/.codex/auth.json is absent
- /home/runtime/.codex/log/codex-login.log shows
  token_exchange_user_error / HTTP 400 at 16:59:42
- codex exec --skip-git-repo-check --json hangs ~10s retrying 401,
  then emits multiple error frames and exits 1
- frontend renders "codex exited with: exit status 1" via the
  existing broker_runner_failed translator

Fix shape:

- authFilePath(binary) returns ~/.codex/auth.json (codex) and
  ~/.claude/.credentials.json (claude); empty for bash so the gate
  is no-op on the PTY shell path.
- authFileExists(binary) checks presence AND non-zero size; a
  0-byte file is treated as missing (codex writes the file atomically
  at the END of device-code exchange, so 0-byte = mid-write or
  corrupt).
- writeAuthRequiredFrame emits a one-line ndjson
  {"type":"error","code":"auth_required","message":...} on the same
  wire shape as auth_in_progress, just a different code so the
  frontend can route to /settings/token-source instead of
  /settings/api-keys.
- Both /chat (chatHandler) and /chat-pty (chatPTYHandler) call the
  gate AFTER the existing login-in-flight gate. Order is important:
  if a login IS in flight, we still want auth_in_progress copy, not
  auth_required.

Tests:
- TestAuthFilePath: HOME-relative path resolution for codex/claude;
  bash returns "".
- TestAuthFileExistsMissing / Present / ZeroByteTreatedAsMissing.
- TestChatHandlerRefusesWhenAuthMissing: end-to-end gate fires with
  the actionable /settings/token-source pointer in the message.
- TestChatHandlerProceedsWhenAuthPresent: gate clears when the file
  exists (downstream spawn may fail in CI, but auth_required must not
  leak).
- Existing TestChatHandlerIsolatesBinariesDuringLogin updated to
  writeAuthFile() so it still exercises the per-binary isolation it
  was written to verify.
- Existing chat_pty end-to-end + concurrent-turn tests get the same
  treatment so the spawn-pool path is reachable.

go test ./apps/broker/... passes locally (1.438s).

Co-authored-by: Sam Larson <[email protected]>
Co-authored-by: NeverClaudeCode <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants