Skip to content

feat(ui): show and copy the prompt a refresh would send; fix web search count - #54

Merged
audemed44 merged 2 commits into
mainfrom
feat/recommendation-prompt-preview
Oct 13, 2026
Merged

audemed44 merged 2 commits into
mainfrom
feat/recommendation-prompt-preview

Conversation

@audemed44

@audemed44 audemed44 commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

What

A Prompt button on the For You page's Read next and Discover tabs. It opens the exact prompt a refresh would send right now, built from the library as it is:

  • System and user messages, each in full.
  • The model, an approximate token count (about 4 characters a token), and whether web search is on.
  • Copy prompt (system + user) and Copy full request (the JSON body sent to OpenRouter: messages, answer schema, require_parameters and the web search tool). A collapsible section shows the full request in the dialog too.

Copying falls back to execCommand('copy') where the Clipboard API is missing (plain http).

How

GET /api/recommendations/prompt?kind=read_next|discover builds the request with buildRecPrompt. The refresh now uses that same function, so the preview and what is actually sent can't drift apart. It doesn't call OpenRouter and works without a key.

Testing

  • Go: the preview's messages equal what a refresh then sends to a fake OpenRouter; Discover includes the web search tool; a bad kind returns 400.
  • Vitest: the dialog loads the prompt for the current tab, shows the token count and web search state, and both copy buttons copy the right text.
  • Checked on a copy of the live database at desktop and phone widths: the Discover prompt is about 6.5k tokens.

Fix: web search count

Discover runs always showed 0 web searches. A real chat completion with the web search tool (one tiny request, 2026-10-13) reports the count under usage.server_tool_use_details.web_search_requests, not server_tool_use. Both are read now, and the tests use the real response shape. The recorded cost was already right.

A Prompt button on the Read next and Discover tabs opens the exact
system and user messages a refresh would send right now, built from the
library as it is, with the model, an approximate token count and
whether web search is on. Copy prompt copies both messages; Copy full
request copies the JSON body OpenRouter gets, with the answer schema
and the web search tool.

GET /api/recommendations/prompt?kind=read_next|discover builds it with
the same code as a refresh (shared buildRecPrompt), so the preview can't
drift from what is sent. It needs no API key.
Chat completions report OpenRouter's web searches under
usage.server_tool_use_details.web_search_requests (checked with a real
request), not server_tool_use, so every Discover run showed 0 searches.
Both names are read now.
@audemed44 audemed44 changed the title feat(ui): show and copy the prompt a refresh would send feat(ui): show and copy the prompt a refresh would send; fix web search count Oct 13, 2026
@audemed44
audemed44 merged commit 98661e9 into main Oct 13, 2026
2 checks passed
@audemed44
audemed44 deleted the feat/recommendation-prompt-preview branch October 13, 2026 09:04
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