Skip to content

Add page awareness: ground the chatbot in the visitor's current page - #207

Open
HardeepAsrani wants to merge 3 commits into
feat/connectfrom
feat/page-context
Open

Add page awareness: ground the chatbot in the visitor's current page#207
HardeepAsrani wants to merge 3 commits into
feat/connectfrom
feat/page-context

Conversation

@HardeepAsrani

@HardeepAsrani HardeepAsrani commented Jul 18, 2026

Copy link
Copy Markdown
Member

Closes Codeinwp/hyve#249
Pro PR: https://github.com/Codeinwp/hyve/pull/267
Agent PR: https://github.com/Codeinwp/agents/pull/134

This makes the chatbot aware of the page the visitor is chatting from. Questions like "how much does this cost?" used to fail even when the answer was right there on the page, because retrieval had no idea what "this" was.

How it works:

  • The widget sends the page URL with every chat turn.
  • The server only accepts same-origin URLs (this is a public endpoint that can trigger a server-side fetch, so anything else is rejected) and resolves the URL to a post with url_to_postid().
  • If the page is already in the Knowledge Base, its stored chunks get pinned into the chat context, skipping anything the similarity search already picked up. No re-processing.
  • If it's not in the KB, the rendered page is fetched over a loopback request and scraped (Pro's scraper, same pipeline as URL imports), so builder pages and Woo products work even though their content never reaches post_content. The result is trimmed to ~1000 tokens and cached per post, or per URL for index/archive pages.
  • The page title is blended into the retrieval query, so vague questions still retrieve the right content.
  • In Connect mode the plugin sends a page object with the chat payload and the platform pins the chunks server-side.

The whole thing is Pro-only: lite ships the plumbing behind the hyve_page_context_enabled filter (default off), and Pro flips it from the new "Page awareness" toggle (Conversation card, default on, needs an active license).

Also in this PR:

  • Fixed Connect streaming losing the chat history on navigation. The widget never adopted the platform-minted thread_id from the terminal done event, so the saved conversation looked invalid and was discarded on every page load.
  • Loopback scrapes skip SSL verification via the standard https_local_ssl_verify filter, same as core cron and Site Health loopbacks, so self-signed local certs don't break extraction.

Manual QA

Needs Pro with an active license. The toggle lives in Chat Behavior > Conversation ("Page awareness", on by default).

  1. Unindexed page: create a post with a concrete fact in it (a price works well), don't add it to the KB, open it on the frontend and ask the chatbot about it. It should answer from the page. The first message pays a one-time scrape, so expect a few extra seconds.
  2. Ask again or reload and ask: fast now, the content is cached per post. Editing the post busts the cache.
  3. Indexed page: on a post that IS in the KB, ask something vague like "what is this page about?". It should answer without you naming the post.
  4. Blog index / archives: from an index page, ask about a post whose teaser is visible there. Heads up: the scrape is anonymous, so if you're logged in and the site has private posts, your pagination differs from what visitors see. Verify logged out.
  5. Source links: with "show source link" enabled, the reply should never link back to the page you're currently on.
  6. Toggle off (or deactivate the license): chat behaves exactly as before, no page context anywhere.
  7. Connect mode: repeat 1 and 3 while connected. Also start a conversation, navigate to another page mid-thread, and confirm the history is still there (this was broken before this PR).
  8. Security: POST to /wp-json/hyve/v1/chat with a page_url pointing at another site, or at a draft/private post (/?p=ID). The reply must never use that content.

The widget sends the page URL with each chat turn. The server accepts same-origin URLs only, resolves them to a post when possible, pins the post's KB chunks into the context when indexed, and falls back to extracted page content (cached per post or per URL) when not. Connect mode forwards a page object so the platform can do the same. Pro-only, behind the hyve_page_context_enabled filter.

Also adopt the platform-minted thread_id from the streaming done event so Connect chat history survives page navigation.
@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown

Plugin build for cdbd8f3 is ready 🛎️!

@HardeepAsrani
HardeepAsrani requested a review from abaicus July 18, 2026 10:27
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.

2 participants