diff --git a/AGENTS.md b/AGENTS.md index b2322c32a..487dbb9e3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,11 +46,13 @@ will not bring Algolia's changes into that package. Follow the accessible name (including its header translations), and linked-image Markdown rendering. Verify the behavior with the regression cases; keep unsafe URL scheme rejection and HTML escaping intact. -- If all three fixes are included, return to the official package and retire the - custom build and override. Update packaging-specific tests while retaining +- Check for a supported completed-answer component in both the modal and + sidepanel so the site can preserve its optional tutorial video. +- If all three fixes and the answer component are supported, return to the + official package and retire the custom build and override. Update packaging-specific tests while retaining the behavior checks. -- If a fix is still missing, update the custom build to the newer compatible - upstream release and retain only the fixes still needed. Refresh its source, +- If a fix or the slot still needs local support, update the custom build to the + newer compatible upstream release and retain the changes still needed. Refresh its source, provenance, reviewed diff, version, packaged artifact, and lockfile together. Keep related DocSearch packages compatible and run the diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bdc0548d0..69fe90fa0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -390,6 +390,10 @@ import video from '@site/src/data/css-anchor-tooltip-video.json'; ``` +Ask AI also uses the recording’s `watchPath` and `guidePath` to offer it +beside a relevant answer. Include the edition or section in `guidePath` when +it identifies which workflow the recording shows. + The next build generates the watch page, structured data, and video entry in `/sitemap.xml`. The [release checks](README.md#tutorial-release-checks) discover the guide and check the player, captions, links, duration, and sitemap against diff --git a/config/search/README.md b/config/search/README.md index 42fbff80f..40aa57d76 100644 --- a/config/search/README.md +++ b/config/search/README.md @@ -106,6 +106,13 @@ encoded URLs, give the Ask AI dialog an accessible name, and render linked screenshots safely. Do not edit installed dependencies, intercept global networking, or rewrite rendered citations. +The modal and the sidepanel can show one optional recording below a completed +answer. The site matches its citations to published video definitions. A direct +watch link takes priority, followed by a matching guide section, edition, or +unambiguous guide. New recordings use the same catalog as the watch pages. +Check a Community-only answer, an unrelated answer, and keyboard playback in +both chat views when updating the integration. + After changing the dependency, test an absolute URL containing `%20` in both an AI answer and its Sources menu; verify that it reaches the correct guide. Check full-page Ask AI submission, keyboard close/focus restoration, and desktop/mobile diff --git a/package-lock.json b/package-lock.json index 5b445b6a1..e71f37669 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@docsearch/css": "5.2.0", "@docsearch/docusaurus-adapter": "5.2.0", - "@docsearch/react": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz", + "@docsearch/react": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz", "@docusaurus/core": "3.10.2", "@docusaurus/plugin-client-redirects": "3.10.2", "@docusaurus/plugin-google-gtag": "3.10.2", @@ -3639,9 +3639,9 @@ } }, "node_modules/@docsearch/react": { - "version": "5.2.0-phcode.2", - "resolved": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz", - "integrity": "sha512-brhEFvLaVMb5+RGNIUOVfyHNLinWj4IOJHJEr9rOUaqSPn/H8eN5Rev7u9igruHZkdp638agTQ1i1Jz2L9kr1g==", + "version": "5.2.0-phcode.3", + "resolved": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz", + "integrity": "sha512-I0u2UAIJCrQjU1r6D39XHIdxGwTY+rDFSpmChJBxt2X6sYtay/vrwd+WVYBfhye8ct1qXrJoMS4QqTSEKTkMNg==", "license": "MIT", "dependencies": { "@ai-sdk/react": "^3.0.259", diff --git a/package.json b/package.json index 508f04b5c..789fd89c2 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "docusaurus": "docusaurus", "test:tutorials": "node --test --test-reporter=tap scripts/tutorial-release.test.cjs", "test:links": "node --test --test-reporter=tap scripts/verify-links.test.cjs", - "test:search": "node --test --test-reporter=tap scripts/search-tabs.test.cjs scripts/search-crawler.test.cjs scripts/docsearch-package.test.cjs scripts/tutorial-icons.test.cjs", + "test:search": "node --test --test-reporter=tap scripts/search-tabs.test.cjs scripts/search-crawler.test.cjs scripts/docsearch-package.test.cjs scripts/tutorial-icons.test.cjs scripts/ask-ai-video.test.mjs", "package:tutorials": "node scripts/package-tutorials.cjs", "verify:tutorials": "node scripts/verify-tutorials.cjs", "verify:links": "node scripts/verify-links.cjs", @@ -28,7 +28,7 @@ "dependencies": { "@docsearch/css": "5.2.0", "@docsearch/docusaurus-adapter": "5.2.0", - "@docsearch/react": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz", + "@docsearch/react": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz", "@docusaurus/core": "3.10.2", "@docusaurus/plugin-client-redirects": "3.10.2", "@docusaurus/plugin-google-gtag": "3.10.2", diff --git a/plugins/tutorial-media/index.js b/plugins/tutorial-media/index.js index 0a08c1e35..dcf80db4a 100644 --- a/plugins/tutorial-media/index.js +++ b/plugins/tutorial-media/index.js @@ -34,6 +34,13 @@ module.exports = function tutorialMediaPlugin({siteDir, baseUrl}, options) { }, async contentLoaded({content, actions}) { actions.setGlobalData({uploadDates: content.publications.videos}); + // Only the Ask AI answer component imports this catalog. Media loads on demand. + const answerVideos = content.videos.map(({watchPath, guidePath, title, poster, + source, captions, width, height, metadata}) => ({ + watchPath, guidePath, title, poster, source, captions, width, height, + seconds: Math.round(Number(metadata.duration.slice(2, -1))), + })); + await actions.createData('ask-ai-videos.json', JSON.stringify(answerVideos)); await Promise.all(content.videos.map(async video => { const data = await actions.createData(`${path.basename(video.watchPath)}.json`, JSON.stringify(video)); actions.addRoute({ diff --git a/scripts/ask-ai-video.test.mjs b/scripts/ask-ai-video.test.mjs new file mode 100644 index 000000000..1b787d0ad --- /dev/null +++ b/scripts/ask-ai-video.test.mjs @@ -0,0 +1,53 @@ +import assert from 'node:assert/strict'; +import {test} from 'node:test'; +import {fileURLToPath} from 'node:url'; +import catalog from '../plugins/tutorial-media/watch-videos.js'; +import {findAnswerVideo, prefersTextOnly} from '../src/components/SearchPageAskAi/find-answer-video.mjs'; + +const origin = 'https://docs.phcode.dev'; +const videos = catalog.readWatchVideos(fileURLToPath(new URL('../', import.meta.url))); +const match = (...urls) => findAnswerVideo(videos, urls.map(url => ({url})), origin)?.watchPath; + +test('every published watch page and edition or section-specific guide matches its recording', () => { + for (const video of videos) { + assert.equal(match(video.watchPath), video.watchPath); + assert.equal(match(origin + video.guidePath), video.watchPath); + } +}); + +test('one explicit watch link wins over guide links and repeated references', () => { + const watch = '/videos/add-image-phoenix-community'; + assert.equal(match('/docs/tutorials/find-and-replace', watch + '/?ref=chat', watch), watch); + assert.equal(match('/docs/tutorials/add-images?edition=pro#turn-on-visual-editing', + '/docs/tutorials/add-images?edition=community#copy-your-picture'), '/videos/add-image-phoenix-pro'); +}); + +test('distinguishes editions, operating systems and different tasks on the same page', () => { + assert.equal(match('/docs/tutorials/add-images?edition=community#copy-your-picture'), '/videos/add-image-phoenix-community'); + assert.equal(match('/docs/tutorials/add-html-table#community-insert-table'), '/videos/add-html-table-phoenix-community'); + assert.equal(match('/docs/startup-crash?source=help#linux'), '/videos/repair-phoenix-code-linux'); + assert.equal(match('/docs/Features/find-in-files?edition=community'), '/videos/find-in-files'); + assert.equal(match('/docs/tutorials/add-images'), undefined); + assert.equal(match('/docs/startup-crash'), undefined); + assert.equal(match('/docs/tutorials/image-text-layout?edition=community'), undefined); + assert.equal(match('/docs/tutorials/link-to-section#test-your-link'), undefined); + assert.equal(match('/docs/tutorials/add-html-table?edition=community#pro-insert-table'), undefined); + assert.equal(match('/docs/Features/keyboard-shortcuts'), undefined); +}); + +test('unknown media, malformed links and lookalike hosts cannot supply a player', () => { + for (const url of ['https://example.com/videos/find-in-files', '//example.com/videos/find-in-files', + 'https://docs.phcode.dev.example.com/videos/find-in-files', 'https://user@docs.phcode.dev/videos/find-in-files', + 'https://[', 'javascript:alert(1)', '/videos/missing', '/tutorials/media/find-in-files.mp4', '#windows']) { + assert.equal(match(url), undefined, url); + } + assert.equal(match('https://[', '/docs/Features/find-in-files#results'), '/videos/find-in-files'); + assert.equal(findAnswerVideo(videos, [{url: '/videos/find-in-files'}], origin + '/').watchPath, '/videos/find-in-files'); +}); + +test('respects plain-text requests and permits questions about text editing', () => { + for (const question of ['Text only, please.', 'Give me text-only instructions.', 'How do I add a photo without a video?']) { + assert.equal(prefersTextOnly(question), true); + } + assert.equal(prefersTextOnly('How can I find a text-only file?'), false); +}); diff --git a/scripts/docsearch-package.test.cjs b/scripts/docsearch-package.test.cjs index 919867e09..412ea491d 100644 --- a/scripts/docsearch-package.test.cjs +++ b/scripts/docsearch-package.test.cjs @@ -42,8 +42,29 @@ test('all DocSearch integrations use the integrity-locked package and the same R assert.equal(createRequire(entry).resolve('react-dom'), require.resolve('react-dom')); }); +test('the optional answer component receives citations and stays empty without a site component or links', async () => { + const React = require('react'); + const {renderToStaticMarkup} = require('react-dom/server'); + const {AnswerContent, AnswerContentContext} = await import('@docsearch/react/answerContent'); + const link = {url: '/videos/find-in-files'}; + const question = 'How do I find text?'; + function SiteContent(props) { + assert.deepEqual(props.links, [link]); + assert.equal(props.question, question); + return React.createElement('p', null, 'Optional recording'); + } + const answer = links => React.createElement(AnswerContent, {links, question}); + const withSite = links => React.createElement(AnswerContentContext.Provider, {value: SiteContent}, answer(links)); + assert.equal(renderToStaticMarkup(answer([link])), ''); + assert.equal(renderToStaticMarkup(withSite([])), ''); + assert.equal(renderToStaticMarkup(withSite([link])), '

Optional recording

'); +}); + test('the installed artifact contains the reviewed source fixes', () => { const expectedFiles = [ + 'src/AnswerContent.tsx', + 'src/AskAiScreen.tsx', + 'src/Sidepanel/ConversationScreen.tsx', 'src/utils/markdown.ts', 'src/utils/sanitize.ts', 'src/Sidepanel/Sidepanel.tsx', diff --git a/scripts/tutorial-release.test.cjs b/scripts/tutorial-release.test.cjs index 6a19e3218..8883faedd 100644 --- a/scripts/tutorial-release.test.cjs +++ b/scripts/tutorial-release.test.cjs @@ -42,7 +42,8 @@ async function fixture(t, publishedFiles = {}) { await fs.mkdir(path.dirname(file), {recursive: true}); await fs.writeFile(file, 'Fixture: existence only; real media timing is verified after build.'); const slug = path.basename(file, '.mp4'); - const video = {source, watchPath: '/videos/' + slug, captions: source.replace(/\.mp4$/, '.vtt')}; + const video = {source, watchPath: '/videos/' + slug, captions: source.replace(/\.mp4$/, '.vtt'), + guidePath: '/docs/example', metadata: {duration: 'PT2S'}}; await fs.writeFile(path.join(siteDir, 'static', video.captions), 'WEBVTT\r\n\r\nNOTE editor note\r\n\r\nstep-one\r\n00:00.000 --> 00:02.000 align:start\r\n1. Open the\r\nproject.\r\n'); await fs.writeFile(path.join(siteDir, 'src/data', slug + '-video.json'), JSON.stringify(video)); @@ -69,6 +70,7 @@ test('first deployment assigns publication dates and saves the same dates used b }}); assert.deepEqual(routes.map(route => route.path).sort(), [pro, community].map(source => '/help/videos/' + path.basename(source, '.mp4')).sort()); + assert.deepEqual(data.get('ask-ai-videos.json').map(video => video.seconds), [2, 2]); for (const route of routes) { const video = data.get(route.modules.video); assert.equal(route.path, '/help' + video.watchPath); diff --git a/src/components/SearchPageAskAi/TutorialVideoAnswer.jsx b/src/components/SearchPageAskAi/TutorialVideoAnswer.jsx new file mode 100644 index 000000000..950d41d93 --- /dev/null +++ b/src/components/SearchPageAskAi/TutorialVideoAnswer.jsx @@ -0,0 +1,58 @@ +import React, {useId, useState} from 'react'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import useBaseUrl from '@docusaurus/useBaseUrl'; +import videos from '@generated/phoenix-tutorial-media/default/ask-ai-videos.json'; +import {findAnswerVideo, prefersTextOnly} from './find-answer-video.mjs'; +import styles from './TutorialVideoAnswer.module.css'; + +function VideoPreview({video}) { + const [open, setOpen] = useState(false); + const [failed, setFailed] = useState(false); + const playerId = useId(); + const poster = useBaseUrl(video.poster); + const source = useBaseUrl(video.source); + const captions = useBaseUrl(video.captions); + const watchPage = useBaseUrl(video.watchPath); + const minutes = Math.floor(video.seconds / 60); + const duration = minutes ? `${minutes} min ${video.seconds % 60} sec` : `${video.seconds} sec`; + const action = open ? 'Hide video' : 'Play video'; + + return
+ + +
; +} + +export default function TutorialVideoAnswer({links, question}) { + const origin = useDocusaurusContext().siteConfig.url; + if (prefersTextOnly(question)) return null; + const video = findAnswerVideo(videos, links, origin); + return video ? : null; +} diff --git a/src/components/SearchPageAskAi/TutorialVideoAnswer.module.css b/src/components/SearchPageAskAi/TutorialVideoAnswer.module.css new file mode 100644 index 000000000..4c2e01e53 --- /dev/null +++ b/src/components/SearchPageAskAi/TutorialVideoAnswer.module.css @@ -0,0 +1,107 @@ +.preview { + margin-block: .75rem .25rem; + color: var(--docsearch-text-color, var(--ifm-font-color-base)); +} + +.toggle { + display: flex; + align-items: center; + gap: .75rem; + width: 100%; + padding: .5rem; + background: transparent; + color: inherit; + border: 1px solid var(--ifm-color-emphasis-300); + border-radius: .5rem; + font: inherit; + text-align: start; + cursor: pointer; +} + +.toggle:hover { + background: var(--ifm-hover-overlay); +} + +.thumbnail { + position: relative; + flex: 0 0 5rem; + aspect-ratio: 8 / 5; + overflow: hidden; + border-radius: .25rem; + background: var(--ifm-color-emphasis-200); +} + +.thumbnail img { + width: 100%; + height: 100%; + object-fit: cover; + display: block; +} + +.icon { + position: absolute; + inset: 0; + margin: auto; + display: grid; + place-items: center; + width: 1.75rem; + height: 1.75rem; + border-radius: 50%; + color: white; + background: rgb(0 0 0 / 78%); +} + +.label { + display: grid; + gap: .125rem; + min-width: 0; + line-height: 1.35; + overflow-wrap: anywhere; +} + +.label strong { + font-size: .9375rem; +} + +.label > span, .watchLink { + font-size: .8125rem; +} + +.label > span { + color: var(--ifm-color-content-secondary); +} + +.preview video { + display: block; + width: 100%; + height: auto; + max-height: 52vh; + margin-block-start: .375rem; + border-radius: .375rem; + background: black; +} + +.watchLink { + display: inline-flex; + align-items: center; + min-height: 32px; + color: var(--ifm-color-primary-darkest); + text-decoration: underline; +} + +[data-theme='dark'] .watchLink { + color: var(--ifm-color-primary); +} + +.watchLink:hover { + color: var(--ifm-font-color-base); +} + +.toggle:focus-visible, .watchLink:focus-visible { + outline: 2px solid var(--docsearch-primary-color, var(--ifm-color-primary)); + outline-offset: 2px; +} + +.error { + margin: .5rem 0 0; +} diff --git a/src/components/SearchPageAskAi/find-answer-video.mjs b/src/components/SearchPageAskAi/find-answer-video.mjs new file mode 100644 index 000000000..501d83332 --- /dev/null +++ b/src/components/SearchPageAskAi/find-answer-video.mjs @@ -0,0 +1,46 @@ +// The answer's cited links determine relevance. Tool results can include discarded matches. +export function findAnswerVideo(videos, links, origin) { + const siteOrigin = new URL(origin).origin; + const citations = []; + for (const {url} of links) { + if (typeof url !== 'string' || !/^(?:\/(?!\/)|https:\/\/)/i.test(url)) continue; + let citation; + try { + citation = new URL(url, origin); + } catch { + continue; + } + if (citation.origin !== siteOrigin || citation.username || citation.password) continue; + citation.pathname = citation.pathname.replace(/\/$/, ''); + const direct = videos.find(video => video.watchPath === citation.pathname); + if (direct) return direct; + citations.push(citation); + } + + const catalog = videos.map(video => ({video, guide: new URL(video.guidePath, origin)})); + let editionMatch; + let pageMatch; + for (const citation of citations) { + const edition = citation.searchParams.get('edition'); + const page = catalog.filter(({guide}) => guide.pathname === citation.pathname); + // A single recording for both editions can be cited from either tab. + const shared = page.length === 1 && !page[0].guide.searchParams.has('edition'); + const candidates = !edition || shared ? page : + page.filter(({guide}) => guide.searchParams.get('edition') === edition); + if (citation.hash) { + const section = candidates.filter(({guide}) => guide.hash === citation.hash); + if (section.length === 1) return section[0].video; + } + if (candidates.length !== 1) continue; + const {video, guide} = candidates[0]; + // A different named step can describe a different task on the same page. + if (guide.hash && citation.hash) continue; + if (edition) editionMatch ??= video; + else if (!guide.searchParams.has('edition')) pageMatch ??= video; + } + return editionMatch ?? pageMatch; +} + +export function prefersTextOnly(question) { + return /\b(?:no|without|skip) (?:(?:a|the|any) )?(?:videos?|visuals?)\b|\b(?:text[- ]only|only text)\b(?:\s*(?:[,.!?]|$)|\s+(?:answer|instructions|steps|please)\b)/i.test(question); +} diff --git a/src/theme/Root.js b/src/theme/Root.js new file mode 100644 index 000000000..49cf05dc9 --- /dev/null +++ b/src/theme/Root.js @@ -0,0 +1,16 @@ +import React, {lazy, Suspense} from 'react'; +import {AnswerContentContext} from '@docsearch/react/answerContent'; + +const TutorialVideoAnswer = lazy(() => + import('@site/src/components/SearchPageAskAi/TutorialVideoAnswer') + // A stale or offline browser can still read the answer and open its citations. + .catch(() => ({default: () => null})), +); + +function AnswerContent(props) { + return ; +} + +export default function Root({children}) { + return {children}; +} diff --git a/vendor/docsearch-react/README.md b/vendor/docsearch-react/README.md index 0334d1845..13495e6da 100644 --- a/vendor/docsearch-react/README.md +++ b/vendor/docsearch-react/README.md @@ -1,7 +1,7 @@ # Phoenix Code DocSearch source dependency This is a narrowly maintained source fork of `@docsearch/react` **5.2.0**, released -locally as **5.2.0-phcode.2**. The application consumes the package in `releases/`; +locally as **5.2.0-phcode.3**. The application consumes the package in `releases/`; it does not rewrite installed dependencies or modify DocSearch's DOM at runtime. ## Upstream provenance @@ -34,11 +34,15 @@ The reviewed source differences are recorded in [upstream.patch](upstream.patch) tokens through the existing safe Markdown renderers. Previously, a screenshot wrapped in a link appeared as literal Markdown. Image and link URLs still pass through the sanitizer; embedded HTML and attribute values remain escaped. -4. **Identify the maintained build.** `src/version.ts` reports `5.2.0-phcode.2`. +4. **Offer a completed-answer slot.** The modal and sidepanel pass the finished + answer’s existing citations and question to an optional React component. + The site provides it through `@docsearch/react/answerContent`. Both views + use the same React context. Video selection and playback live in the site. +5. **Identify the maintained build.** `src/version.ts` reports `5.2.0-phcode.3`. The build configuration only relocates upstream's shared configuration into this directory. It preserves the public exports, ESM and UMD outputs, CSS entry points, -and ES2017 browser target. Development dependencies are locked locally; no new +and ES2017 browser target, and adds the answer-content entry point. Development dependencies are locked locally; no new build tool is required by the application's normal installation. ## Rebuild and verify @@ -74,13 +78,16 @@ modal, and sidepanel integrations share the corrected package. Before upgrading, check upstream for fixes to the URL sanitizer, the Sidepanel accessible name, and linked-image rendering. Run the same regression cases against the candidate release and verify full-page Ask AI submission, encoded citation/source links, mobile layout, -and keyboard close/focus behavior. Once an official release passes, replace the +and keyboard close/focus behavior. Also check whether both reply views offer an +equivalent React slot and migrate the site’s video component to it. Once an official release passes, replace the file dependency with that release, remove the override, and remove this directory. -Checked on **18 November 2026**: the live npm registry and official release notes -still list DocSearch **5.2.0** and Docusaurus **3.10.2** as latest stable. The -upstream Markdown renderer still escapes the raw link label instead of rendering -its child tokens. Keep the three fixes until upstream passes all regression cases. +Checked on **4 December 2026**. The live npm registry lists DocSearch **5.2.0** +and Docusaurus **3.10.2** as stable. The [DocSearch changelog](https://github.com/algolia/docsearch/blob/db3337978a2c9be6ec9187e73105a94dc0b1bbf3/packages/docsearch-react/CHANGELOG.md) +and [Docusaurus release](https://github.com/facebook/docusaurus/releases/tag/v3.10.2) +match the installed upstream versions. DocSearch 5.2.0 renders answer text and +source links directly in each chat view. Retain the existing fixes and the +optional slot while these versions are in use. Relevant upstream implementation and documentation: diff --git a/vendor/docsearch-react/package-lock.json b/vendor/docsearch-react/package-lock.json index bd227bbb4..f0e728b82 100644 --- a/vendor/docsearch-react/package-lock.json +++ b/vendor/docsearch-react/package-lock.json @@ -1,12 +1,12 @@ { "name": "@docsearch/react", - "version": "5.2.0-phcode.2", + "version": "5.2.0-phcode.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@docsearch/react", - "version": "5.2.0-phcode.2", + "version": "5.2.0-phcode.3", "license": "MIT", "dependencies": { "@ai-sdk/react": "^3.0.259", diff --git a/vendor/docsearch-react/package.json b/vendor/docsearch-react/package.json index b4fd1a445..8ce7fc364 100644 --- a/vendor/docsearch-react/package.json +++ b/vendor/docsearch-react/package.json @@ -1,7 +1,7 @@ { "name": "@docsearch/react", "description": "React package for DocSearch, the best search experience for docs.", - "version": "5.2.0-phcode.2", + "version": "5.2.0-phcode.3", "license": "MIT", "homepage": "https://docsearch.algolia.com", "repository": { @@ -24,6 +24,7 @@ ], "exports": { ".": "./dist/esm/index.js", + "./answerContent": "./dist/esm/answerContent.js", "./askaiModal": "./dist/esm/askaiModal.js", "./button": "./dist/esm/button.js", "./docsearch": "./dist/esm/docsearch.js", diff --git a/vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz b/vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz deleted file mode 100644 index 195899a20..000000000 Binary files a/vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz and /dev/null differ diff --git a/vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz b/vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz new file mode 100644 index 000000000..fbdfa17f6 Binary files /dev/null and b/vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz differ diff --git a/vendor/docsearch-react/src/AnswerContent.tsx b/vendor/docsearch-react/src/AnswerContent.tsx new file mode 100644 index 000000000..92c81a6ad --- /dev/null +++ b/vendor/docsearch-react/src/AnswerContent.tsx @@ -0,0 +1,17 @@ +import React from 'react'; + +import type { ExtractedLink } from './utils/ai'; + +export interface AnswerContentProps { + links: ExtractedLink[]; + question: string; +} + +/** Optional site content below a completed, cited answer in either chat UI. */ +export const AnswerContentContext = + React.createContext | null>(null); + +export function AnswerContent(props: AnswerContentProps): React.JSX.Element | null { + const Component = React.useContext(AnswerContentContext); + return Component && props.links.length > 0 ? : null; +} diff --git a/vendor/docsearch-react/src/AskAiScreen.tsx b/vendor/docsearch-react/src/AskAiScreen.tsx index 3e3bda2ae..bef7b0d3f 100644 --- a/vendor/docsearch-react/src/AskAiScreen.tsx +++ b/vendor/docsearch-react/src/AskAiScreen.tsx @@ -2,6 +2,7 @@ import type { UseChatHelpers } from '@ai-sdk/react'; import React, { type JSX, useMemo } from 'react'; import { AggregatedSearchBlock } from './AggregatedSearchBlock'; +import { AnswerContent } from './AnswerContent'; import type { AskAiScreenStateProps } from './AskAiScreenState'; import { ConversationPromptSuggestions } from './components/ConversationPromptSuggestions'; import { FeedbackActions } from './components/FeedbackActions'; @@ -355,6 +356,9 @@ function AskAiExchangeCard({ })} + {showActions && ( + + )} {wasStopped && (

{stoppedStreamingText} diff --git a/vendor/docsearch-react/src/Sidepanel/ConversationScreen.tsx b/vendor/docsearch-react/src/Sidepanel/ConversationScreen.tsx index 82fbb130e..7282b0480 100644 --- a/vendor/docsearch-react/src/Sidepanel/ConversationScreen.tsx +++ b/vendor/docsearch-react/src/Sidepanel/ConversationScreen.tsx @@ -4,6 +4,7 @@ import React, { memo, useMemo } from 'react'; import { type Exchange } from '../AskAiScreen'; import { ConversationPromptSuggestions } from '../components/ConversationPromptSuggestions'; +import { AnswerContent } from '../AnswerContent'; import { FeedbackActions } from '../components/FeedbackActions'; import { SourcesPanel } from '../components/SourcesPanel'; import { ToolCall, type ToolCallTranslations } from '../components/ToolCall'; @@ -277,6 +278,9 @@ const ConversationExchange = React.forwardRef< )} + {showActions && ( + + )} {wasStopped && (

{stoppedStreamingText} diff --git a/vendor/docsearch-react/src/version.ts b/vendor/docsearch-react/src/version.ts index 993b6f8ac..b18a1a6e4 100644 --- a/vendor/docsearch-react/src/version.ts +++ b/vendor/docsearch-react/src/version.ts @@ -1 +1 @@ -export const version = '5.2.0-phcode.2'; +export const version = '5.2.0-phcode.3'; diff --git a/vendor/docsearch-react/tests/regressions.test.cjs b/vendor/docsearch-react/tests/regressions.test.cjs index fec84beab..0eb057ae0 100644 --- a/vendor/docsearch-react/tests/regressions.test.cjs +++ b/vendor/docsearch-react/tests/regressions.test.cjs @@ -132,6 +132,8 @@ test('vendored production source differs only in the reviewed fixes and version' if (actual !== expected) changed.push(relative); } assert.deepEqual(changed.sort(), [ + 'src/AskAiScreen.tsx', + 'src/Sidepanel/ConversationScreen.tsx', 'src/Sidepanel/Sidepanel.tsx', 'src/Sidepanel/SidepanelHeader.tsx', 'src/utils/markdown.ts', diff --git a/vendor/docsearch-react/tsdown.config.mts b/vendor/docsearch-react/tsdown.config.mts index a30969a73..58bbed50a 100644 --- a/vendor/docsearch-react/tsdown.config.mts +++ b/vendor/docsearch-react/tsdown.config.mts @@ -28,6 +28,7 @@ export default defineConfig([ docsearch: 'src/DocSearch.tsx', docsearchAi: 'src/DocSearchAI.tsx', askaiModal: 'src/DocSearchAskAiModal.tsx', + answerContent: 'src/AnswerContent.tsx', button: 'src/DocSearchButton.tsx', modal: 'src/DocSearchModal.tsx', useDocSearchKeyboardEvents: 'src/useDocSearchKeyboardEvents.ts', diff --git a/vendor/docsearch-react/upstream.patch b/vendor/docsearch-react/upstream.patch index 29d7a027c..0c2f4c323 100644 --- a/vendor/docsearch-react/upstream.patch +++ b/vendor/docsearch-react/upstream.patch @@ -105,4 +105,71 @@ index 6f577f97..e92e8d8f 100644 +++ b/src/version.ts @@ -1 +1 @@ -export const version = '5.2.0'; -+export const version = '5.2.0-phcode.2'; ++export const version = '5.2.0-phcode.3'; +diff --git a/src/AskAiScreen.tsx b/src/AskAiScreen.tsx +index 3e3bda2a..bef7b0d3 100644 +--- a/src/AskAiScreen.tsx ++++ b/src/AskAiScreen.tsx +@@ -2,6 +2,7 @@ import type { UseChatHelpers } from '@ai-sdk/react'; + import React, { type JSX, useMemo } from 'react'; + + import { AggregatedSearchBlock } from './AggregatedSearchBlock'; ++import { AnswerContent } from './AnswerContent'; + import type { AskAiScreenStateProps } from './AskAiScreenState'; + import { ConversationPromptSuggestions } from './components/ConversationPromptSuggestions'; + import { FeedbackActions } from './components/FeedbackActions'; +@@ -355,6 +356,9 @@ function AskAiExchangeCard({ + })} + + ++ {showActions && ( ++ ++ )} + {wasStopped && ( +

+ {stoppedStreamingText} +diff --git a/src/Sidepanel/ConversationScreen.tsx b/src/Sidepanel/ConversationScreen.tsx +index 82fbb130..7282b048 100644 +--- a/src/Sidepanel/ConversationScreen.tsx ++++ b/src/Sidepanel/ConversationScreen.tsx +@@ -4,6 +4,7 @@ import React, { memo, useMemo } from 'react'; + + import { type Exchange } from '../AskAiScreen'; + import { ConversationPromptSuggestions } from '../components/ConversationPromptSuggestions'; ++import { AnswerContent } from '../AnswerContent'; + import { FeedbackActions } from '../components/FeedbackActions'; + import { SourcesPanel } from '../components/SourcesPanel'; + import { ToolCall, type ToolCallTranslations } from '../components/ToolCall'; +@@ -277,6 +278,9 @@ const ConversationExchange = React.forwardRef< + )} + + ++ {showActions && ( ++ ++ )} + {wasStopped && ( +

+ {stoppedStreamingText} +diff --git a/src/AnswerContent.tsx b/src/AnswerContent.tsx +new file mode 100644 +index 00000000..92c81a6a +--- /dev/null ++++ b/src/AnswerContent.tsx +@@ -0,0 +1,17 @@ ++import React from 'react'; ++ ++import type { ExtractedLink } from './utils/ai'; ++ ++export interface AnswerContentProps { ++ links: ExtractedLink[]; ++ question: string; ++} ++ ++/** Optional site content below a completed, cited answer in either chat UI. */ ++export const AnswerContentContext = ++ React.createContext | null>(null); ++ ++export function AnswerContent(props: AnswerContentProps): React.JSX.Element | null { ++ const Component = React.useContext(AnswerContentContext); ++ return Component && props.links.length > 0 ? : null; ++}