apps/cli: Route studio_mobile_* bot replies to studio-mobile-client endpoint (PoC)#3493
Open
gcsecsey wants to merge 4 commits into
Open
apps/cli: Route studio_mobile_* bot replies to studio-mobile-client endpoint (PoC)#3493gcsecsey wants to merge 4 commits into
gcsecsey wants to merge 4 commits into
Conversation
…ndpoint When the polled message comes from a bot whose name starts with studio_mobile_, the remote-session controller now POSTs the reply to /wpcom/v2/studio-mobile-client/respond with an agent_message envelope alongside the existing chat_id and bot routing keys. Other bots keep hitting /local-agent-respond unchanged.
…i-mobile-respond-routing
Collaborator
📊 Performance Test ResultsComparing 98dee4c vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
…ing fork Move machine_id into the remote-session config schema with a sanitized os.hostname() default and a STUDIO_REMOTE_MACHINE_ID env override. Removes the MobileTarget struct, the empty-suffix throw in the NDJSON reader path, and the silent base_url misroute when /telegram-bot is missing.
…pond router The mobile and Telegram message shapes were both living inside telegram-client.ts alongside the dispatch logic, which made the file the de-facto home for the entire wire protocol. Move the studio-mobile shape into its own studio-mobile-client.ts, the Telegram-only code stays in telegram-client.ts, and introduce respond-router.ts as the dispatcher (fork + retry loop). Shared HTTP primitives (errors, URL helpers, backoff) move to remote-http.ts; the Telegram-flavored error class names become Remote*Error to reflect that they're transport-layer concerns shared by both clients.
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.
Related issues
How AI was used in this PR
Used Claude Code to implement the flow described in the SPEC. Reviewed the diff manually, and tested end-to-end against a local daemon talking to mobile app through wpcom.
Proposed Changes
The Studio CLI's remote-session loop currently posts every reply to
/wpcom/v2/telegram-bot/local-agent-respondregardless of which client originated the message. That endpoint only knows how to forward to Telegram, so replies destined for the studio-mobile PoC client (polled withbot: "studio_mobile_<machine_id>") get rejected withrest_missing_callback_param. The wpcom side now exposes a parallel/wpcom/v2/studio-mobile-client/respondendpoint that accepts anagent_messageenvelope; this PR teaches the CLI to use it.respondMessage(): when the effectivebotstarts withstudio_mobile_, hit/wpcom/v2/studio-mobile-client/respond(derived by swapping the trailingtelegram-botsegment inbase_urlso dev hosts still resolve). Other bots keep using/local-agent-respondunchanged.{ chat_id, bot, machine_id, envelope: { type: "agent_message", id, text } }.chat_idandbotare the queue routing keys today;machine_idis forward-compat for when wpcom switches the queue key in Phase 2 of the SPEC;envelope.textis what the server reads instead of the old top-leveltextfield. Telegram path is unchanged.media.shareevent lands on astudio_mobile_*bot the photo bytes are dropped and the caption (or a placeholder) is promoted to the envelope text, with a warning logged. Telegram still gets the multipartsendPhotopath.Testing Instructions
npm run cli:build.export STUDIO_ENABLE_REMOTE_SESSION=truenode apps/cli/dist/cli/main.mjs code remote-session stop.node apps/cli/dist/cli/main.mjs code remote-session start.~/.studio/remote-session.logshould show a successfulPosting replyfollowed by noRespond 4xx.studio_mobile_*bot suffix). The reply should land in the mobile app, and the log should again show a successfulPosting replywith no 4xx.npm test -- apps/cli/remote-sessionto exercise the unit tests covering the routing and body shape.Pre-merge Checklist