Skip to content

Server-side /generate routing + UI autocomplete + MCP tool#44

Merged
jonnyparris merged 1 commit intomainfrom
feat/generate-server-routing
Apr 23, 2026
Merged

Server-side /generate routing + UI autocomplete + MCP tool#44
jonnyparris merged 1 commit intomainfrom
feat/generate-server-routing

Conversation

@jonnyparris
Copy link
Copy Markdown
Owner

Summary

Follow-up to #42. Makes /generate actually work from every entry point, adds slash-command autocomplete to the UI, and exposes a generate_image MCP tool.

Why

After #42 shipped, I tried /generate a cyberpunk cat via the Dodo MCP send_message tool and got GPT-5.4 offering to write a prompt for me. Turned out the slash command only worked in the browser — the server was happily passing /generate ... through to the LLM. So I fixed that.

What changed

Server-side slash routing

  • handleMessage and handlePrompt now detect /generate content and delegate to runImageGeneration before touching the LLM.
  • Works from the browser UI, MCP tools (send_message, send_prompt), and any future HTTP clients.
  • Behaviour matches the dedicated /generate endpoint — same 409 on concurrent prompts, same 400 on prompt >2048 chars, same message_attachments SSE event.

UI autocomplete

  • Typing / in the chat input pops a suggestions menu above the textarea.
  • Arrow keys navigate, Enter/Tab completes, Escape dismisses.
  • Mouse click also works (mousedown is trapped so the textarea doesn't lose focus).
  • Driven off a single SLASH_COMMANDS array — adding a new command = one edit.

New MCP tool

  • generate_image(sessionId, prompt) calls /generate directly. Lets LLM agents invoke FLUX from conversations without going through the chat model.

Refactor

  • Extract runImageGeneration(...) core from handleGenerate so the endpoint handler and the slash-routed handlers share a single image-generation code path.
  • New extractGeneratePrompt() helper + GENERATE_SLASH_REGEX constant in shared-index.ts. Browser and server now reference the same regex.

Tests

Test plan

  • npx tsc --noEmit passes
  • npx vitest run — all 401 tests pass
  • Manual: type / in the chat UI, verify autocomplete menu appears
  • Manual: call the generate_image MCP tool and verify FLUX responds

Notes

  • The client-side /generate intercept in dodo-chat.js is kept on purpose — it routes straight to the synchronous /generate endpoint for snappier UX than going through /prompt (which would queue).
  • Image uploads alongside a /generate prompt are ignored. FLUX-1-schnell is text-to-image only; multi-reference inputs are a FLUX.2 feature.

beep-boop-🤖

Follow-up to #42. Three things:

1. Slash command autocomplete in the chat input. Type '/' to see a menu of
   available commands (currently just /generate). Arrow keys + Enter/Tab
   complete, Escape dismisses. Menu positioned above the input, styled to
   match the rest of the app.

2. Server-side /generate routing. handleMessage and handlePrompt now detect
   /generate in the content and delegate to the image-generation core
   (runImageGeneration). This means /generate works from:
     - Browser UI (client intercept + this server fallback)
     - MCP send_message / send_prompt tools
     - Any future HTTP clients

   Previously the slash command only worked in the browser because the
   client JS was the only layer that knew about it.

3. New MCP tool: generate_image. Calls /generate directly with a prompt
   string. Lets LLM agents (incl. myself) invoke FLUX from conversations.

Refactor:
- Extract runImageGeneration() core from handleGenerate — shared entry
  point for the dedicated endpoint and slash-routed messages.
- GENERATE_SLASH_REGEX + extractGeneratePrompt() in shared-index so the
  browser and server agree on what counts as a /generate request.

Tests:
- 6 new unit tests for extractGeneratePrompt (happy path, null on non-/
  messages, whitespace handling, multi-line, case-insensitive)
- Updated existing slash-regex tests to use the canonical shared export
- All 401 tests pass
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
dodo e1386a2 Apr 23 2026, 09:40 PM

@jonnyparris jonnyparris marked this pull request as ready for review April 23, 2026 21:42
@jonnyparris jonnyparris merged commit a340e3a into main Apr 23, 2026
3 checks passed
@jonnyparris jonnyparris deleted the feat/generate-server-routing branch April 25, 2026 19:03
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.

1 participant