tts tts telegram commands with replicate + claude api rate limits + enforce authorized telegram id from env#101
Open
morandalex wants to merge 5 commits intoTinyAGI:mainfrom
Conversation
Author
|
reopened from closed pull req #35 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
.claudeignore,CLAUDE.mdsrc/lib/db.ts,db/migrations/*.sql,src/lib/config.tssrc/lib/invoke.tssrc/lib/transcribe.ts,src/channels/telegram-client.ts/stton/sttofftoggle commands, voice/audio transcriptionsrc/lib/synthesize.ts,src/channels/telegram-client.ts/ttson/ttsofftoggle commands, response voice synthesissrc/channels/telegram-client.ts/helpcommand, user whitelist viaTELEGRAM_USERS_ENABLEDenv varsrc/lib/types.ts,src/lib/invoke.tsenvfield on AgentConfig, passed torunCommandchild processsrc/visualizer/team-visualizer.tsxrate_limits_updatedevent handlersrc/queue-processor.tsdotenv/configimport,closeDb()on SIGINT/SIGTERMlib/daemon.shpackage.json,package-lock.jsonbetter-sqlite3+@types/better-sqlite3,db:migrate/db:rollbackscriptsPre-requisites
.envfile withTELEGRAM_BOT_TOKEN,ANTHROPIC_API_KEY,REPLICATE_API_TOKENdbmatefpr the migrationTest Cases
1. Build
npm run build— must compile with zero errors (both main + visualizer)npm run build:main— must compile with zero errorsnpm run build:visualizer— must compile with zero errorsdist/output containschannels/telegram-client.js,lib/db.js,lib/transcribe.js,lib/synthesize.js,queue-processor.js2. Database — with dbmate
~/.tinyclaw/tinyclaw.dbif it existsnpm run db:migrate— should create the database and apply both migrationssqlite3 ~/.tinyclaw/tinyclaw.db ".tables"should showtoken_usageandapi_rate_limitsnpm run db:rollbacktwice — should drop both tables cleanlynpm run db:migrateagain — idempotent re-apply3. Database — fallback (no dbmate)
~/.tinyclaw/tinyclaw.dbnpm run queue) — database should be auto-created with both tables viaCREATE TABLE IF NOT EXISTSDatabase schema created via fallback (dbmate not available)4. Daemon dbmate auto-migration
tinyclaw start5. Telegram — User Whitelist
TELEGRAM_USERS_ENABLED=""(empty) in.env→ start bot → all users can send messages (log should showWARN: No TELEGRAM_USERS_ENABLED set)TELEGRAM_USERS_ENABLED=<your_telegram_id>→ restart bot → log should showUser whitelist active: 1 user(s) allowedAccess denied. You are not authorized to use this bot.and log showsWARN: Unauthorized user ... blockedTELEGRAM_USERS_ENABLED=111,222,333(multiple IDs with no spaces) → restart → verify3 user(s) allowedTELEGRAM_USERS_ENABLED=111, 222, 333(with spaces) → restart → verify whitespace is trimmed and all 3 IDs work6. Telegram — /help Command
/helpto the bot → should receive the full command list including STT/TTS status!helpto the bot → same result (alternative prefix)/helpresponse includes:/agent,/team,/reset,/stton,/sttoff,/ttson,/ttsoff,/help7. Telegram — STT (Speech-to-Text)
/stton→ bot repliesSpeech-to-text enabled...~/.tinyclaw/stt_enabled_chats.jsonis created and contains the chat IDVoice transcribed: ...and the queue message contains[voice transcript: ...]/sttoff→ bot repliesSpeech-to-text disabled./sttoff)REPLICATE_API_TOKENunset or empty, enable STT and send a voice message → transcription silently returns null, no crash8. Telegram — TTS (Text-to-Speech)
/ttson→ bot repliesText-to-speech enabled...~/.tinyclaw/tts_enabled_chats.jsonis created and contains the chat IDtts_*.mp3deleted from~/.tinyclaw/files/)/ttsoff→ bot repliesText-to-speech disabled.REPLICATE_API_TOKENunset, enable TTS → response is text-only, log showsTTS failed: ..., no crash9. Token Usage Tracking
sqlite3 ~/.tinyclaw/tinyclaw.db "SELECT * FROM token_usage ORDER BY id DESC LIMIT 1"→ row exists withagent_id,provider,model,message_char_count,estimated_input_tokensresponse_char_count,estimated_output_tokens,duration_msfilled inestimated_input_tokens ≈ message_char_count / 4(ceiling)10. API Rate Limit Tracking (Anthropic)
sqlite3 ~/.tinyclaw/tinyclaw.db "SELECT * FROM api_rate_limits ORDER BY id DESC LIMIT 1"→ row with rate limit datainferred_tieris populated (e.g.,Tier 1,Tier 2, etc.)Rate limits checked — agent: ..., tier: ..., RPM: ...api_rate_limitsfor that agent)env(e.g., different API key) → rate limit check is skipped for that agent11. Agent
envConfig"env": { "SOME_VAR": "test" }to an agent insettings.jsonSOME_VARin its environmentenvfield → works as before (inherits parent process env)12. Visualizer — Rate Limit Display
npm run visualize)No rate limit data yet13. Queue Processor — dotenv & Graceful Shutdown
npm run queue→ verify it loads.env(no missing env var errors)Shutting down queue processor...and database is closed cleanlySQLITE_MISUSEor lock errors in logs after shutdown14. Existing Functionality (Regression)
/agentcommand still works/teamcommand still works/resetcommand still works@agent_idrouting still works@team_idrouting still works15. Edge Cases
REPLICATE_API_TOKENmissing → STT/TTS features degrade silently (return null)ANTHROPIC_API_KEYmissing → rate limit check skipped, no crashfromfield → whitelist check handlesundefinedgracefullyChecklist Before Merge
.envfile is NOT committed (.claudeignore+.gitignoreprotect it)npm run buildsucceeds cleanly/agent,/team,/reset) still work