Skip to content

Add an assistant tool to submit page feedback#4408

Open
zenoachtig wants to merge 2 commits into
mainfrom
claude/gitbook-feedback-tool-3eabec
Open

Add an assistant tool to submit page feedback#4408
zenoachtig wants to merge 2 commits into
mainfrom
claude/gitbook-feedback-tool-3eabec

Conversation

@zenoachtig

Copy link
Copy Markdown
Contributor

Overview

  • Adds a new built-in submitPageFeedback tool to the GitBook Assistant, letting it record a visitor's feedback about the page they're currently viewing — on their behalf.
  • Feedback flows through the same insights pipeline as the "Was this helpful?" widget: a page_post_feedback event (rating) plus a page_post_feedback_comment event when the visitor also left a comment. No new endpoint or API wiring — visitor auth, session and page location are injected by InsightsProvider, exactly as for the rating widget.
  • The tool asks the visitor to confirm before anything is recorded (Cancel / "Submit feedback"), since it acts on their behalf.

How it works

  • New hook useSubmitPageFeedbackTool() (mirrors useNavigateToPageTool), registered as a built-in tool alongside navigateToPage in useAIChat.
  • Input: a rating (good / ok / bad) and an optional comment in the visitor's own words.
  • Scoped to the current page (useCurrentPage()); if no page is open it throws, which the chat surfaces as a generic tool error.
  • Adds two intl keys across all 39 locales: ai_chat_tools_submit_feedback (confirm-button label) and ai_chat_tools_submitted_feedback (result summary).

Testing

  • bun run format and bun run typecheck pass.
  • Not yet exercised end-to-end against the live assistant — invoking the tool requires the backend model to call it mid-conversation. Happy to capture a demo if useful.

— Authored by Claude

zenoachtig and others added 2 commits July 16, 2026 21:00
Add a `submitPageFeedback` built-in tool to the GitBook Assistant so it can
record a visitor's feedback about the page they're viewing, on their behalf.
It reuses the same insights pipeline as the "Was this helpful?" widget
(page_post_feedback / page_post_feedback_comment) and asks the visitor to
confirm before submitting.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2624776

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2624776e00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let toolToExecute: AIStreamResponseToolCallPending | null = null;
try {
const tools = getTools([navigateToPageTool]);
const tools = getTools([navigateToPageTool, submitPageFeedbackTool]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the page-feedback setting before exposing the tool

On sites where customization.feedback.enabled is false, SitePage.tsx:286 suppresses the existing feedback UI, but this provider still unconditionally exposes submitPageFeedback to the assistant. Consequently, visitors can submit and record page-feedback events after the site owner has disabled that feature (including with the repository's default customization, where feedback is disabled); only register this tool when page feedback is enabled.

Useful? React with 👍 / 👎.

Comment on lines +84 to +87
trackEvent(
{ type: 'page_post_feedback', feedback: { rating: pageFeedbackRating } },
undefined,
{ immediate: !trimmedComment }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass the current page context when tracking embedded feedback

When a visitor switches from the embed's docs tab to its assistant tab, useCurrentPage() retains the last visited documentation page, but EmbeddableAIChat.tsx establishes the assistant pathname's insights context with pageId: null. Passing undefined here therefore reuses that null-page context, so both feedback events are recorded with location.page = null even though the tool reports a concrete currentPage.pageId; feedback submitted through this common embed flow cannot be attributed to the page it concerns.

Useful? React with 👍 / 👎.

Comment on lines +19 to +21
comment: z
.string()
.optional()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the existing feedback-comment length limit

When a user supplies more than 512 characters of feedback, this unbounded schema allows the assistant to copy the entire text into the insights event, while PageFeedbackForm.tsx deliberately caps the same comment field at 512 characters. This bypass permits arbitrarily large immediate keepalive request bodies; sufficiently large comments can exceed the browser's keepalive quota and never be recorded even though the tool returns submitted: true, so the schema should enforce the same maximum.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he's right, we have a maxLength on the schema

Comment on lines +150 to +151
ai_chat_tools_submit_feedback: 'Envoyer mon avis',
ai_chat_tools_submitted_feedback: 'Avis envoyé',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ai_chat_tools_submit_feedback: 'Envoyer', 
ai_chat_tools_submitted_feedback: 'Merci pour votre retour',

I think it's more natural this way in french

@argos-ci

argos-ci Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2-cloudflare (Inspect) ⚠️ Changes detected (Review) 3 changed, 6 ignored Jul 16, 2026, 7:13 PM
customers-v2-vercel (Inspect) ⚠️ Changes detected (Review) 4 changed, 4 removed, 1 failure, 4 ignored Jul 16, 2026, 7:09 PM
v2-cloudflare (Inspect) ⚠️ Changes detected (Review) 4 changed, 4 removed, 2 failures, 4 ignored Jul 16, 2026, 7:15 PM
v2-vercel (Inspect) 📭 Waiting for screenshots - Jul 16, 2026, 7:12 PM

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