feat: add ai explain buttons to code block#29533
Open
colbywhite wants to merge 3 commits intoproductionfrom
Open
feat: add ai explain buttons to code block#29533colbywhite wants to merge 3 commits intoproductionfrom
colbywhite wants to merge 3 commits intoproductionfrom
Conversation
Contributor
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
Contributor
|
Preview URL: https://9102463b.preview.developers.cloudflare.com |
later, we will stop being so precise. but for now we've got to be precise everywhere.
This somehow got lost during rebase.
4bc1be1 to
9102463
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds AI-powered code explanation functionality to the documentation site. Users can now click an "Explain Code"
button on code blocks with 10+ lines to get AI-generated explanations in a side panel.
Screenshots
Note: These screenshots may not be up-to-date. See the preview env for more.
TODOs
Feature Implementation
Core Components
Expressive Code Plugin (
src/plugins/expressive-code/explain-code.js)has-explain-buttonclass for CSS styling coordinationSheet Web Component (
src/components/sheet/)<cfdocs-sheet>component for slide-in side panelscfdocs-prefix convention for web componentssheet.node.test.ts)Explain Code Sheet (
src/components/explain-code-sheet/)<cfdocs-explain-code>component orchestrates the explanation flow/explain/{path}?codeBlock={position}API endpointPUBLIC_EXPLAIN_CODE_API_URLenvironment variable (intended for local development only)explain-code-sheet.node.test.ts)Client Script (
src/scripts/explain-code.ts)[data-explain-code]buttonsStyling
src/styles/code.css)src/styles/backdrop.css)Integration
ec.config.mjssrc/components/overrides/Head.astroDocumentation & Tooling Updates
AGENTS.md Documentation
Added new Web Components section documenting:
cfdocs-prefix for new componentsElementsuffixsrc/components/{component-name}/directoriesTesting Infrastructure
This PR introduces a new testing pattern for vanilla web components, which we haven't extensively tested in this project before:
@testing-library/domandhappy-domdependencies for DOM testing in Node.jsvitest.workspace.tssheet.node.test.tsandexplain-code-sheet.node.test.tsdemonstrate testing custom elements, shadow DOM, event handling, and async behaviorOther Changes
.gitignoreto ignore all.env*files (was only.env)Separate: GitHub Actions Updates
The Node.js version pinning changes in GitHub Actions workflows are unrelated to this feature and were part of separate
maintenance work:
24.14.0across all workflows24.xornode-version-fileto explicit versionci.yml,bonk.yml,bigbonk.yml,anchor-link-audit.yml,publish-production.ymlAPI Expectations
The feature expects an API endpoint at:
Request details:
workers/examples/return-json)codeBlock- 1-indexed position of the code block on the pageResponse requirements:
text/htmlcf-docs-finish-reason: stop(indicates successful completion)Default API base URL:
https://docs-ai-production.cloudflare-docs.workers.devInfrastructure: The API endpoint leverages Cloudflare's AI Gateway for caching, rate limiting, and request management to ensure reliable and cost-effective AI-powered explanations.
User Experience