Add an assistant tool to submit page feedback#4408
Conversation
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 detectedLatest commit: 2624776 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
💡 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]); |
There was a problem hiding this comment.
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 👍 / 👎.
| trackEvent( | ||
| { type: 'page_post_feedback', feedback: { rating: pageFeedbackRating } }, | ||
| undefined, | ||
| { immediate: !trimmedComment } |
There was a problem hiding this comment.
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: z | ||
| .string() | ||
| .optional() |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
he's right, we have a maxLength on the schema
| ai_chat_tools_submit_feedback: 'Envoyer mon avis', | ||
| ai_chat_tools_submitted_feedback: 'Avis envoyé', |
There was a problem hiding this comment.
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
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Overview
submitPageFeedbacktool to the GitBook Assistant, letting it record a visitor's feedback about the page they're currently viewing — on their behalf.page_post_feedbackevent (rating) plus apage_post_feedback_commentevent when the visitor also left a comment. No new endpoint or API wiring — visitor auth, session and page location are injected byInsightsProvider, exactly as for the rating widget.How it works
useSubmitPageFeedbackTool()(mirrorsuseNavigateToPageTool), registered as a built-in tool alongsidenavigateToPageinuseAIChat.rating(good/ok/bad) and an optionalcommentin the visitor's own words.useCurrentPage()); if no page is open it throws, which the chat surfaces as a generic tool error.ai_chat_tools_submit_feedback(confirm-button label) andai_chat_tools_submitted_feedback(result summary).Testing
bun run formatandbun run typecheckpass.— Authored by Claude