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