Skip to content

feat: include source page link in chat responses - #180

Merged
HardeepAsrani merged 12 commits into
developmentfrom
feat/chat-source-link
Jul 8, 2026
Merged

feat: include source page link in chat responses#180
HardeepAsrani merged 12 commits into
developmentfrom
feat/chat-source-link

Conversation

@HardeepAsrani

@HardeepAsrani HardeepAsrani commented Jun 30, 2026

Copy link
Copy Markdown
Member

The Pro companion is Codeinwp/hyve#236.
Closes: https://github.com/Codeinwp/hyve/issues/152

What this adds

When Hyve answers a question, it can now show where the answer came from — the knowledge base content it drew on — as small numbered citations under the reply.

Screenshot 2026-07-04 at 3 25 47 AM

Highlights:

  • Off by default. Turn it on under Settings → General → “Show Source Link in Chat Responses.”
  • Numbered citations. Sources appear as a compact Sources 1 2 3 row beneath the answer; hovering (or focusing) a number reveals the page title, and clicking opens it in a new tab.
  • Only what’s relevant. Sources are ranked by how well they match the question, and weak stragglers are dropped — so a question that’s really about one page shows one source, not three padded ones. At most three are shown.
  • Only what’s public. A link is added only for publicly accessible content. Private posts, password-protected posts, and content with no public URL (e.g. custom data) are never linked.
  • Theme-aware. The label and numbers follow the chat’s text color, so they stay legible on both light and custom/dark chat backgrounds.
  • Works with both the streaming and non-streaming reply flows.

For developers

Three filters are available for fine-tuning:

  • hyve_source_link_limit — max number of sources shown (default 3).
  • hyve_source_link_score_ratio — how close to the best match a source must score to be shown, as a ratio of the top score (default 0.8; 0 shows everything above the relevance threshold).
  • hyve_chat_source_link — resolve/override the URL for a given source (used by the Pro plugin for website-link and sitemap sources, and to suppress links for custom data).

Base branch is feat/streaming-responses and this builds on #179 (it reuses the post-visibility helper for the public-accessibility check).

Manual QA

Prerequisite: add a few public Posts/Pages to the Knowledge Base and make sure the chat answers from them.

  1. Enable the setting. Go to Settings → General, set “Show Source Link in Chat Responses” to Enable, and save.
  2. Ask a grounded question. Ask something clearly covered by one of your KB pages. Under the answer you should see a “Sources” label followed by numbered chips.
    • Hover/focus a number → the page title appears as a tooltip.
    • Click a number → the source page opens in a new tab.
  3. Relevance. Ask a question that only one page really covers → you should see just that one source, not three. Ask a broad question covered by several pages → you should see up to three.
  4. Public-only.
    • Set a KB source Post to Private (or add a password), ask a question it would answer → that page must not be linked.
    • Confirm no link is shown for sources that have no public URL.
  5. Both reply modes. Repeat step 2 with streaming responses on and off — citations should appear in both.
  6. Theming. Under Settings → Appearance, set a dark chat/assistant background → the “Sources” label and numbers should remain readable (they switch to a light color); hover fill uses the accent color.
  7. Off state. Set the setting back to Disable and save → answers should no longer show any source citations.
  8. No sources case. Ask an off-topic question the KB can’t answer → no “Sources” row should appear.

With the Pro plugin (Codeinwp/hyve#236) active, also confirm: website-link and sitemap sources link to their original public URL, and custom-data sources show no link.

HardeepAsrani and others added 6 commits June 29, 2026 06:42
- Redesign the frontend chat widget (header with avatar/name/status,
  modern bubbles, pill input, refined launcher, entrance animation).
- Add a global "Chat Sound" toggle and a per-visitor mute control in the
  chat menu; remove the open/close click sound.
- Add a "Message Timestamp" show/hide toggle.
- Show the welcome message and suggested questions on first load of the
  inline chat block.
- Inline the chat-button SVGs server-side (no runtime fetch / icon flash)
  and use a bundled SVG as the default icon instead of an emoji.
- Keep the typing dots, suggestion chips, and menu legible on similar
  colors, and theme the menu from the chat colors.
- Resolve outstanding PHPStan issues (gmdate guard, require_once ignore).
Reveal the assistant's reply progressively over Server-Sent Events, with a
graceful fallback to the existing background + polling flow on hosts that
buffer or cannot stream, so the bot keeps working everywhere.

- Add a custom admin-ajax streaming endpoint (Stream) that proxies OpenAI's
  stream to the browser; the API key stays server-side.
- Share a single prompt, JSON schema and response interpreter across the
  streaming and poll paths so replies never diverge by transport.
- The widget tries streaming first and falls back to polling when no event
  arrives in time; the outcome is cached per browser and re-probed after 24h.
- Decode the streamed `response` field incrementally via json_decode so
  escapes and surrogate-pair emoji render correctly while streaming.
- Preserve existing contracts: moderation stays up front, hyve_chat_request
  and hyve_chat_response fire once per reply, analytics unaffected.

Closes Codeinwp/hyve#183
… Base

Private posts were excluded from the Add Data list because the listing and
re-index queries filtered to the 'publish' status only. Include the 'private'
status so private posts can be added and stay in sync when edited.
(Password-protected posts already matched 'publish' and were addable.)

Because added content is surfaced to any chat visitor regardless of the post's
original visibility, adding a private or password-protected post now requires
an explicit confirmation.
Append a compact source citation to chat answers, shown only for publicly
accessible sources. Adds a Settings toggle and a hyve_chat_source_link filter
for source-type-specific resolution.
- Redesign the frontend chat widget (header with avatar/name/status,
  modern bubbles, pill input, refined launcher, entrance animation).
- Add a global "Chat Sound" toggle and a per-visitor mute control in the
  chat menu; remove the open/close click sound.
- Add a "Message Timestamp" show/hide toggle.
- Show the welcome message and suggested questions on first load of the
  inline chat block.
- Inline the chat-button SVGs server-side (no runtime fetch / icon flash)
  and use a bundled SVG as the default icon instead of an emoji.
- Keep the typing dots, suggestion chips, and menu legible on similar
  colors, and theme the menu from the chat colors.
- Resolve outstanding PHPStan issues (gmdate guard, require_once ignore).
# Conflicts:
#	inc/Main.php
#	src/frontend/App.js

Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>
@HardeepAsrani
HardeepAsrani marked this pull request as ready for review July 3, 2026 20:01
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Plugin build for 219d69e is ready 🛎️!

@HardeepAsrani
HardeepAsrani changed the base branch from feat/private-password-kb-content to development July 3, 2026 20:04
…g-responses

Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>
@HardeepAsrani

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Fixed in 7cf3c51.

@HardeepAsrani
HardeepAsrani changed the base branch from development to feat/streaming-responses July 3, 2026 20:30
@HardeepAsrani

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Fixed in d6ea24c.

@HardeepAsrani
HardeepAsrani changed the base branch from feat/streaming-responses to development July 8, 2026 20:44
@HardeepAsrani

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Fixed in e7c89b4.

@HardeepAsrani

Copy link
Copy Markdown
Member Author

@codex[agent] Fix the PHPStan/lint errors.

@Codex

Codex AI commented Jul 8, 2026

Copy link
Copy Markdown

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • openaipublic.blob.core.windows.net
    • Triggering command: /usr/bin/php php /home/REDACTED/work/hyve-lite/hyve-lite/vendor/bin/phpunit (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@HardeepAsrani
HardeepAsrani merged commit de49754 into development Jul 8, 2026
7 checks passed
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.

4 participants