@rspress/core 2.0.23 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/b~0.js +1 -3
- package/dist/cli/index.js +1 -1
- package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Link/getHref.ts +1 -0
- package/dist/eject-theme/components/Link/index.tsx +0 -3
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +29 -54
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +4 -1
- package/dist/eject-theme/components/Search/useSearchPanel.ts +103 -36
- package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
- package/dist/entry/worker.js +1 -1
- package/dist/{a~0.js → h~0.js} +18 -15
- package/dist/index.d.ts +1 -1
- package/dist/node/PluginDriver.js +8 -2
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +1 -1
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/eject.js +1 -1
- package/dist/node/initRsbuild.js +8 -4
- package/dist/node/llms.d.ts +1 -1
- package/dist/node/llms.js +2 -2
- package/dist/node/logger/hint.d.ts +1 -0
- package/dist/node/logger/hint.js +8 -2
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
- package/dist/node/runtimeModule/i18n.js +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +2 -2
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/sitemap.d.ts +2 -0
- package/dist/node/sitemap.js +103 -0
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/renderPages.js +1 -1
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/renderPage.js +5 -4
- package/dist/node/ssg-md/renderPages.js +1 -1
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +5 -2
- package/dist/runtime/App.js +12 -25
- package/dist/runtime/ClientApp.d.ts +3 -2
- package/dist/runtime/ClientApp.js +27 -21
- package/dist/runtime/ErrorRoute.d.ts +1 -0
- package/dist/runtime/ErrorRoute.js +30 -0
- package/dist/runtime/PageRoute.d.ts +2 -0
- package/dist/runtime/PageRoute.js +58 -0
- package/dist/runtime/createServerRouter.d.ts +4 -0
- package/dist/runtime/createServerRouter.js +17 -0
- package/dist/runtime/csrClientEntry.js +5 -2
- package/dist/runtime/hooks/useWebMcp.d.ts +36 -0
- package/dist/runtime/hooks/useWebMcp.js +80 -0
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.js +3 -1
- package/dist/runtime/initPageData.d.ts +0 -3
- package/dist/runtime/initPageData.js +9 -45
- package/dist/runtime/pageDataLoader.d.ts +11 -0
- package/dist/runtime/pageDataLoader.js +7 -0
- package/dist/runtime/ssrClientEntry.js +14 -6
- package/dist/runtime/ssrMdServerEntry.js +10 -21
- package/dist/runtime/ssrServerEntry.js +10 -21
- package/dist/static/assets/package.json +58 -0
- package/dist/theme/components/Link/index.js +0 -4
- package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
- package/dist/theme/components/Link/useLinkNavigate.js +13 -35
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
- package/dist/theme/components/Search/useSearchPanel.js +74 -26
- package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
- package/dist/theme/hooks/useWebMcpNavigation.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpNavigation.js +123 -0
- package/dist/theme/hooks/useWebMcpPageList.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpPageList.js +25 -0
- package/dist/theme/hooks/useWebMcpPageReading.d.ts +7 -0
- package/dist/theme/hooks/useWebMcpPageReading.js +23 -0
- package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpSiteInfo.js +22 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/index.js +5 -0
- package/dist/theme/layout/ErrorLayout/index.css +52 -0
- package/dist/theme/layout/ErrorLayout/index.d.ts +8 -0
- package/dist/theme/layout/ErrorLayout/index.js +76 -0
- package/dist/theme/webMcp/tools.d.ts +56 -0
- package/dist/theme/webMcp/tools.js +122 -0
- package/dist/theme/webMcp/types.d.ts +35 -0
- package/dist/theme/webMcp/types.js +0 -0
- package/dist/tinypool~0.js +19 -49
- package/dist/tu~0.js +3 -0
- package/package.json +12 -12
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { usePageData, useSearchHooks } from "@rspress/core/runtime";
|
|
1
|
+
import { usePageData, useSearchHooks, useWebMcp } from "@rspress/core/runtime";
|
|
2
2
|
import { debounce } from "@rspress/shared/lodash-es";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { getSearchIndexURL } from "./logic/providers/LocalProvider.js";
|
|
5
5
|
import { PageSearcher } from "./logic/search.js";
|
|
6
6
|
import { RenderType } from "./logic/types.js";
|
|
7
|
+
import { defineTool, queryField, toWebMcpSearchResults } from "../../webMcp/tools.js";
|
|
7
8
|
const useDebounce = (cb)=>{
|
|
8
9
|
const cbRef = useRef(cb);
|
|
9
10
|
cbRef.current = cb;
|
|
@@ -22,6 +23,8 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
22
23
|
const [searchError, setSearchError] = useState();
|
|
23
24
|
const pageSearcherRef = useRef(null);
|
|
24
25
|
const pageSearcherConfigRef = useRef(null);
|
|
26
|
+
const pageSearcherURLRef = useRef(void 0);
|
|
27
|
+
const initializationRef = useRef(void 0);
|
|
25
28
|
const searchEnabled = false !== search;
|
|
26
29
|
const searchOptions = false === search ? {} : search;
|
|
27
30
|
const versionedSearch = searchEnabled && (search?.versioned ?? true);
|
|
@@ -34,7 +37,8 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
34
37
|
}
|
|
35
38
|
];
|
|
36
39
|
const createSearcher = ()=>{
|
|
37
|
-
|
|
40
|
+
const previous = pageSearcherConfigRef.current;
|
|
41
|
+
if (pageSearcherRef.current && previous?.currentLang === lang && (!versionedSearch || previous.currentVersion === version) && pageSearcherURLRef.current === searchIndexURL) return pageSearcherRef.current;
|
|
38
42
|
const pageSearcherConfig = {
|
|
39
43
|
currentLang: lang,
|
|
40
44
|
currentVersion: version
|
|
@@ -46,15 +50,62 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
46
50
|
});
|
|
47
51
|
pageSearcherRef.current = pageSearcher;
|
|
48
52
|
pageSearcherConfigRef.current = pageSearcherConfig;
|
|
53
|
+
pageSearcherURLRef.current = searchIndexURL;
|
|
49
54
|
return pageSearcher;
|
|
50
55
|
};
|
|
56
|
+
const initializeSearcher = (searcher)=>{
|
|
57
|
+
if (initializationRef.current?.searcher === searcher) return initializationRef.current.promise;
|
|
58
|
+
const promise = searcher.init().catch((error)=>{
|
|
59
|
+
if (initializationRef.current?.searcher === searcher) initializationRef.current = void 0;
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
initializationRef.current = {
|
|
63
|
+
searcher,
|
|
64
|
+
promise
|
|
65
|
+
};
|
|
66
|
+
return promise;
|
|
67
|
+
};
|
|
68
|
+
const searchDocs = async (value, limit)=>{
|
|
69
|
+
const searcher = createSearcher();
|
|
70
|
+
let newQuery = value;
|
|
71
|
+
const result = [];
|
|
72
|
+
if (userSearchHooks.beforeSearch) {
|
|
73
|
+
const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
|
|
74
|
+
if (transformedQuery) newQuery = transformedQuery;
|
|
75
|
+
}
|
|
76
|
+
await initializeSearcher(searcher);
|
|
77
|
+
const defaultSearchResult = await searcher.match(newQuery, limit);
|
|
78
|
+
result.push(...defaultSearchResult);
|
|
79
|
+
if (userSearchHooks.onSearch) {
|
|
80
|
+
const customSearchResult = await userSearchHooks.onSearch(newQuery, result);
|
|
81
|
+
if (customSearchResult) result.push(...customSearchResult.map((item)=>({
|
|
82
|
+
renderType: RenderType.Custom,
|
|
83
|
+
...item
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
86
|
+
await userSearchHooks.afterSearch?.(newQuery, result);
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
if (import.meta.env.ENABLE_WEBMCP) useWebMcp({
|
|
90
|
+
...defineTool('search_docs', 'Search documentation through the active local search component.', {
|
|
91
|
+
query: queryField,
|
|
92
|
+
limit: {
|
|
93
|
+
type: 'integer',
|
|
94
|
+
minimum: 1,
|
|
95
|
+
maximum: 20
|
|
96
|
+
}
|
|
97
|
+
}, [
|
|
98
|
+
'query'
|
|
99
|
+
], async (args)=>toWebMcpSearchResults(await searchDocs(args.query, args.limit ?? 10))),
|
|
100
|
+
enabled: searchEnabled && Boolean(searchIndexURL || userSearchHooks.onSearch)
|
|
101
|
+
});
|
|
51
102
|
const initSearch = async ()=>{
|
|
52
103
|
if ('initial' !== initStatus) return;
|
|
53
104
|
const searcher = createSearcher();
|
|
54
105
|
setSearchError(void 0);
|
|
55
106
|
setInitStatus('initing');
|
|
56
107
|
try {
|
|
57
|
-
await searcher
|
|
108
|
+
await initializeSearcher(searcher);
|
|
58
109
|
} catch (error) {
|
|
59
110
|
if (pageSearcherRef.current !== searcher) return;
|
|
60
111
|
setSearchError(error instanceof Error ? error.message : String(error));
|
|
@@ -87,42 +138,39 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
87
138
|
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
|
|
88
139
|
const isLangChanged = lang !== currentLang;
|
|
89
140
|
const isVersionChanged = versionedSearch && version !== currentVersion;
|
|
90
|
-
|
|
141
|
+
const isIndexChanged = pageSearcherURLRef.current !== searchIndexURL;
|
|
142
|
+
if (isLangChanged || isVersionChanged || isIndexChanged) {
|
|
91
143
|
setInitStatus('initial');
|
|
92
144
|
setSearchError(void 0);
|
|
93
145
|
setIsSearching(false);
|
|
94
146
|
pageSearcherRef.current = null;
|
|
95
|
-
createSearcher().fetchSearchIndex().catch(()=>{});
|
|
96
147
|
}
|
|
97
148
|
}, [
|
|
98
149
|
lang,
|
|
99
150
|
version,
|
|
100
151
|
versionedSearch,
|
|
101
|
-
searchEnabled
|
|
152
|
+
searchEnabled,
|
|
153
|
+
searchIndexURL
|
|
102
154
|
]);
|
|
103
155
|
const handleQueryChangedImpl = async (value)=>{
|
|
104
|
-
|
|
156
|
+
const newQuery = value;
|
|
105
157
|
setQuery(newQuery);
|
|
106
158
|
if (!newQuery) return void setIsSearching(false);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (searchInputRef.current?.value === newQuery) {
|
|
123
|
-
setCurrentSuggestionIndex(0);
|
|
124
|
-
setSearchResult(result || DEFAULT_RESULT);
|
|
125
|
-
setIsSearching(false);
|
|
159
|
+
try {
|
|
160
|
+
const result = await searchDocs(value);
|
|
161
|
+
if (searchInputRef.current?.value === newQuery) {
|
|
162
|
+
setSearchError(void 0);
|
|
163
|
+
setInitStatus('inited');
|
|
164
|
+
setCurrentSuggestionIndex(0);
|
|
165
|
+
setSearchResult(result || DEFAULT_RESULT);
|
|
166
|
+
setIsSearching(false);
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (searchInputRef.current?.value === newQuery) {
|
|
170
|
+
setSearchError(error instanceof Error ? error.message : String(error));
|
|
171
|
+
setInitStatus('error');
|
|
172
|
+
setIsSearching(false);
|
|
173
|
+
}
|
|
126
174
|
}
|
|
127
175
|
};
|
|
128
176
|
const handleQueryChange = useDebounce(handleQueryChangedImpl);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useStorageValue } from "@rspress/core/theme";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
|
-
import { useStorageValue } from "../../logic/useStorageValue.js";
|
|
4
4
|
const TTL_MS = 3600000;
|
|
5
5
|
function storageKey(repo) {
|
|
6
6
|
return `rp-github-stars:${repo}`;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { useLocation, useNavigate, useNavigation } from "react-router-dom";
|
|
3
|
+
import { normalizeHrefInRuntime, pathnameToRouteService, usePage, useWebMcp } from "@rspress/core/runtime";
|
|
4
|
+
import { usePrevNextPage } from "../logic/usePrevNextPage.js";
|
|
5
|
+
import { defineTool, resolveInternalRoute, routePathField } from "../webMcp/tools.js";
|
|
6
|
+
function useAwaitedNavigation(result) {
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
const navigation = useNavigation();
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
const snapshot = useRef({
|
|
11
|
+
result,
|
|
12
|
+
location,
|
|
13
|
+
state: navigation.state
|
|
14
|
+
});
|
|
15
|
+
const pending = useRef(void 0);
|
|
16
|
+
const settle = useCallback(()=>{
|
|
17
|
+
const request = pending.current;
|
|
18
|
+
const current = snapshot.current;
|
|
19
|
+
if (!request?.done || 'idle' !== current.state || current.location.key === request.startKey) return;
|
|
20
|
+
pending.current = void 0;
|
|
21
|
+
request.cleanup();
|
|
22
|
+
if (current.result.routePath === request.target) request.resolve(current.result);
|
|
23
|
+
else request.reject(new Error('Navigation was superseded by another route.'));
|
|
24
|
+
}, []);
|
|
25
|
+
useLayoutEffect(()=>{
|
|
26
|
+
snapshot.current = {
|
|
27
|
+
result,
|
|
28
|
+
location,
|
|
29
|
+
state: navigation.state
|
|
30
|
+
};
|
|
31
|
+
settle();
|
|
32
|
+
});
|
|
33
|
+
useLayoutEffect(()=>()=>{
|
|
34
|
+
pending.current?.cleanup();
|
|
35
|
+
pending.current?.reject(new Error('Navigation failed or the page runtime was unmounted.'));
|
|
36
|
+
pending.current = void 0;
|
|
37
|
+
}, []);
|
|
38
|
+
return useCallback((target, signal)=>{
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
pending.current?.cleanup();
|
|
41
|
+
pending.current?.reject(new Error('Navigation was superseded by another tool call.'));
|
|
42
|
+
pending.current = void 0;
|
|
43
|
+
return new Promise((resolve, reject)=>{
|
|
44
|
+
const cancel = ()=>{
|
|
45
|
+
if (pending.current === request) pending.current = void 0;
|
|
46
|
+
request.cleanup();
|
|
47
|
+
reject(signal?.reason ?? new DOMException('Navigation cancelled.', 'AbortError'));
|
|
48
|
+
};
|
|
49
|
+
const request = {
|
|
50
|
+
target,
|
|
51
|
+
startKey: snapshot.current.location.key,
|
|
52
|
+
done: false,
|
|
53
|
+
resolve,
|
|
54
|
+
reject,
|
|
55
|
+
cleanup: ()=>signal?.removeEventListener('abort', cancel)
|
|
56
|
+
};
|
|
57
|
+
pending.current = request;
|
|
58
|
+
signal?.addEventListener('abort', cancel, {
|
|
59
|
+
once: true
|
|
60
|
+
});
|
|
61
|
+
Promise.resolve().then(()=>{
|
|
62
|
+
if (pending.current === request) return navigate(normalizeHrefInRuntime(target));
|
|
63
|
+
}).then(()=>{
|
|
64
|
+
if (pending.current !== request) return;
|
|
65
|
+
request.done = true;
|
|
66
|
+
settle();
|
|
67
|
+
}).catch((error)=>{
|
|
68
|
+
if (pending.current === request) pending.current = void 0;
|
|
69
|
+
request.cleanup();
|
|
70
|
+
reject(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}, [
|
|
74
|
+
navigate,
|
|
75
|
+
settle
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
function useWebMcpNavigation() {
|
|
79
|
+
const { page } = usePage();
|
|
80
|
+
const location = useLocation();
|
|
81
|
+
const resolveRoute = (pathname)=>pathnameToRouteService(pathname)?.path;
|
|
82
|
+
const { prevPage, nextPage } = usePrevNextPage();
|
|
83
|
+
const toLink = (item)=>{
|
|
84
|
+
if (!item?.link) return null;
|
|
85
|
+
try {
|
|
86
|
+
return {
|
|
87
|
+
title: item.text,
|
|
88
|
+
routePath: resolveInternalRoute(item.link, {
|
|
89
|
+
origin: window.location.origin,
|
|
90
|
+
resolveRoute
|
|
91
|
+
})
|
|
92
|
+
};
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const result = {
|
|
98
|
+
routePath: `${page.routePath}${location.search}${location.hash}`,
|
|
99
|
+
page: {
|
|
100
|
+
title: page.title,
|
|
101
|
+
description: page.description,
|
|
102
|
+
lang: page.lang,
|
|
103
|
+
version: page.version
|
|
104
|
+
},
|
|
105
|
+
sections: page.toc.map((section)=>({
|
|
106
|
+
title: section.text,
|
|
107
|
+
depth: section.depth,
|
|
108
|
+
routePath: `${page.routePath}${location.search}#${section.id}`
|
|
109
|
+
})),
|
|
110
|
+
previousPage: toLink(prevPage),
|
|
111
|
+
nextPage: toLink(nextPage)
|
|
112
|
+
};
|
|
113
|
+
const navigate = useAwaitedNavigation(result);
|
|
114
|
+
useWebMcp(defineTool('navigate', 'Navigate to a known internal documentation route and return the rendered page metadata, section routes and adjacent pages. Paths are relative to the site base and may include a query or hash.', {
|
|
115
|
+
routePath: routePathField
|
|
116
|
+
}, [
|
|
117
|
+
'routePath'
|
|
118
|
+
], (args, signal)=>navigate(resolveInternalRoute(args.routePath, {
|
|
119
|
+
origin: window.location.origin,
|
|
120
|
+
resolveRoute
|
|
121
|
+
}), signal)));
|
|
122
|
+
}
|
|
123
|
+
export { useWebMcpNavigation };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { usePage, usePages, useWebMcp } from "@rspress/core/runtime";
|
|
2
|
+
import { defineTool, listPages, queryField } from "../webMcp/tools.js";
|
|
3
|
+
function useWebMcpPageList() {
|
|
4
|
+
const { page } = usePage();
|
|
5
|
+
const { pages } = usePages();
|
|
6
|
+
useWebMcp(defineTool('list_pages', "List documentation pages, optionally filtering titles, descriptions and headings. Defaults to the active language and version.", {
|
|
7
|
+
query: queryField,
|
|
8
|
+
lang: {
|
|
9
|
+
type: 'string'
|
|
10
|
+
},
|
|
11
|
+
version: {
|
|
12
|
+
type: 'string'
|
|
13
|
+
},
|
|
14
|
+
limit: {
|
|
15
|
+
type: 'integer',
|
|
16
|
+
minimum: 1,
|
|
17
|
+
maximum: 100
|
|
18
|
+
},
|
|
19
|
+
offset: {
|
|
20
|
+
type: 'integer',
|
|
21
|
+
minimum: 0
|
|
22
|
+
}
|
|
23
|
+
}, [], (args)=>listPages(pages, page, args)));
|
|
24
|
+
}
|
|
25
|
+
export { useWebMcpPageList };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers `rspress_get_page` and `rspress_get_current_page` to read page
|
|
3
|
+
* metadata and generated SSG-MD without navigating. The app registers these
|
|
4
|
+
* tools when Markdown generation is enabled, independently of the theme UI.
|
|
5
|
+
* @unstable
|
|
6
|
+
*/
|
|
7
|
+
export declare function useWebMcpPageReading(): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { pathnameToRouteService, usePage, usePages, useSite, useWebMcp } from "@rspress/core/runtime";
|
|
2
|
+
import { defineTool, readPage, resolveInternalRoute, routePathField } from "../webMcp/tools.js";
|
|
3
|
+
function useWebMcpPageReading() {
|
|
4
|
+
const { page } = usePage();
|
|
5
|
+
const { site } = useSite();
|
|
6
|
+
const { pages } = usePages();
|
|
7
|
+
useWebMcp(defineTool('get_page', 'Read metadata and generated Markdown for a known documentation route without navigating. Paths are relative to the site base.', {
|
|
8
|
+
routePath: routePathField
|
|
9
|
+
}, [
|
|
10
|
+
'routePath'
|
|
11
|
+
], (args, signal)=>{
|
|
12
|
+
const target = resolveInternalRoute(args.routePath, {
|
|
13
|
+
origin: window.location.origin,
|
|
14
|
+
resolveRoute: (pathname)=>pathnameToRouteService(pathname)?.path
|
|
15
|
+
});
|
|
16
|
+
const path = pathnameToRouteService(new URL(target, window.location.origin).pathname)?.path;
|
|
17
|
+
const targetPage = pages.find((page)=>page.routePath === path);
|
|
18
|
+
if (!targetPage) throw new TypeError(`Unknown internal route: ${path}`);
|
|
19
|
+
return readPage(targetPage, site.base, signal);
|
|
20
|
+
}));
|
|
21
|
+
useWebMcp(defineTool('get_current_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the current documentation page.', {}, [], (_args, signal)=>readPage(page, site.base, signal)));
|
|
22
|
+
}
|
|
23
|
+
export { useWebMcpPageReading };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useNav, usePage, useSidebar, useSite, useWebMcp } from "@rspress/core/runtime";
|
|
2
|
+
import { defineTool } from "../webMcp/tools.js";
|
|
3
|
+
function useWebMcpSiteInfo() {
|
|
4
|
+
const { site } = useSite();
|
|
5
|
+
const { page } = usePage();
|
|
6
|
+
const nav = useNav();
|
|
7
|
+
const sidebar = useSidebar();
|
|
8
|
+
useWebMcp(defineTool('get_site_info', 'Get documentation site metadata, languages, versions, navigation and the active sidebar.', {}, [], ()=>({
|
|
9
|
+
title: site.title,
|
|
10
|
+
description: site.description,
|
|
11
|
+
base: site.base,
|
|
12
|
+
siteOrigin: site.siteOrigin,
|
|
13
|
+
lang: page.lang,
|
|
14
|
+
version: page.version,
|
|
15
|
+
locales: site.locales,
|
|
16
|
+
versions: site.multiVersion.versions,
|
|
17
|
+
defaultVersion: site.multiVersion.default,
|
|
18
|
+
nav,
|
|
19
|
+
sidebar
|
|
20
|
+
})));
|
|
21
|
+
}
|
|
22
|
+
export { useWebMcpSiteInfo };
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -54,11 +54,16 @@ export { Tag } from './components/Tag/index.js';
|
|
|
54
54
|
export { Toc } from './components/Toc/index.js';
|
|
55
55
|
export { useActiveAnchor } from './hooks/useActiveAnchor.js';
|
|
56
56
|
export { useDynamicToc, useWatchToc } from './hooks/useDynamicToc.js';
|
|
57
|
+
export { useWebMcpNavigation } from './hooks/useWebMcpNavigation.js';
|
|
58
|
+
export { useWebMcpPageList } from './hooks/useWebMcpPageList.js';
|
|
59
|
+
export { useWebMcpPageReading } from './hooks/useWebMcpPageReading.js';
|
|
60
|
+
export { useWebMcpSiteInfo } from './hooks/useWebMcpSiteInfo.js';
|
|
57
61
|
export * from './icons.js';
|
|
58
62
|
export { DocLayout, type DocLayoutProps } from './layout/DocLayout/index.js';
|
|
59
63
|
export { HomeLayout, type HomeLayoutProps } from './layout/HomeLayout/index.js';
|
|
60
64
|
export { Layout, type LayoutProps } from './layout/Layout/index.js';
|
|
61
65
|
export { NotFoundLayout } from './layout/NotFountLayout/index.js';
|
|
66
|
+
export { ErrorLayout, type ErrorLayoutProps } from './layout/ErrorLayout/index.js';
|
|
62
67
|
export { copyToClipboard } from './logic/copyToClipboard.js';
|
|
63
68
|
export { getCopyableText } from './logic/getCopyableText.js';
|
|
64
69
|
export { mergeRefs } from './logic/mergeRefs.js';
|
package/dist/theme/index.js
CHANGED
|
@@ -53,10 +53,15 @@ export { Tag } from "./components/Tag/index.js";
|
|
|
53
53
|
export { Toc } from "./components/Toc/index.js";
|
|
54
54
|
export { useActiveAnchor } from "./hooks/useActiveAnchor.js";
|
|
55
55
|
export { useDynamicToc, useWatchToc } from "./hooks/useDynamicToc.js";
|
|
56
|
+
export { useWebMcpNavigation } from "./hooks/useWebMcpNavigation.js";
|
|
57
|
+
export { useWebMcpPageList } from "./hooks/useWebMcpPageList.js";
|
|
58
|
+
export { useWebMcpPageReading } from "./hooks/useWebMcpPageReading.js";
|
|
59
|
+
export { useWebMcpSiteInfo } from "./hooks/useWebMcpSiteInfo.js";
|
|
56
60
|
export { DocLayout } from "./layout/DocLayout/index.js";
|
|
57
61
|
export { HomeLayout } from "./layout/HomeLayout/index.js";
|
|
58
62
|
export { Layout } from "./layout/Layout/index.js";
|
|
59
63
|
export { NotFoundLayout } from "./layout/NotFountLayout/index.js";
|
|
64
|
+
export { ErrorLayout } from "./layout/ErrorLayout/index.js";
|
|
60
65
|
export { copyToClipboard } from "./logic/copyToClipboard.js";
|
|
61
66
|
export { getCopyableText } from "./logic/getCopyableText.js";
|
|
62
67
|
export { mergeRefs } from "./logic/mergeRefs.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
.rp-error {
|
|
2
|
+
min-height: 100dvh;
|
|
3
|
+
padding-top: 20vh;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.rp-error__description {
|
|
7
|
+
max-width: 28rem;
|
|
8
|
+
color: var(--rp-c-text-2);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.rp-error__actions {
|
|
12
|
+
flex-wrap: wrap;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
gap: .75rem;
|
|
15
|
+
display: flex;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.rp-error__actions button {
|
|
19
|
+
font: inherit;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
background: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.rp-error__actions :focus-visible {
|
|
25
|
+
outline: 2px solid var(--rp-c-brand);
|
|
26
|
+
outline-offset: 4px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.rp-error__details {
|
|
30
|
+
border: 1px solid var(--rp-c-divider);
|
|
31
|
+
background: var(--rp-c-bg-soft);
|
|
32
|
+
text-align: left;
|
|
33
|
+
border-radius: .75rem;
|
|
34
|
+
width: 100%;
|
|
35
|
+
max-width: 56rem;
|
|
36
|
+
margin-top: 2.5rem;
|
|
37
|
+
padding: 1rem 1.25rem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rp-error__details summary {
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
font-weight: 500;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rp-error__details pre {
|
|
46
|
+
max-height: 20rem;
|
|
47
|
+
margin-top: 1rem;
|
|
48
|
+
font-size: .8125rem;
|
|
49
|
+
line-height: 1.7;
|
|
50
|
+
overflow: auto;
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../NotFountLayout/index.scss';
|
|
2
|
+
import './index.scss';
|
|
3
|
+
export interface ErrorLayoutProps {
|
|
4
|
+
error: unknown;
|
|
5
|
+
lang: string;
|
|
6
|
+
homeHref: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function ErrorLayout({ error, lang, homeHref }: ErrorLayoutProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useI18nText } from "@rspress/core/runtime";
|
|
3
|
+
import { useHead } from "@unhead/react";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { isRouteErrorResponse } from "react-router-dom";
|
|
6
|
+
import "../NotFountLayout/index.css";
|
|
7
|
+
import "./index.css";
|
|
8
|
+
function ErrorLayout({ error, lang, homeHref }) {
|
|
9
|
+
const i18n = useI18nText();
|
|
10
|
+
const title = useRef(null);
|
|
11
|
+
const text = (key, fallback)=>i18n[key]?.[lang] || fallback;
|
|
12
|
+
const heading = text('errorTitleText', 'Something went wrong');
|
|
13
|
+
useHead({
|
|
14
|
+
title: heading
|
|
15
|
+
});
|
|
16
|
+
const response = isRouteErrorResponse(error);
|
|
17
|
+
const details = import.meta.env.DEV ? error instanceof Error ? error.stack || error.message : response ? `${error.status} ${error.statusText}` : 'string' == typeof error ? error : 'Unknown error' : void 0;
|
|
18
|
+
useEffect(()=>{
|
|
19
|
+
title.current?.focus();
|
|
20
|
+
}, [
|
|
21
|
+
heading
|
|
22
|
+
]);
|
|
23
|
+
return /*#__PURE__*/ jsxs("main", {
|
|
24
|
+
className: "rp-not-found rp-error",
|
|
25
|
+
"aria-labelledby": "rp-error-title",
|
|
26
|
+
children: [
|
|
27
|
+
/*#__PURE__*/ jsx("p", {
|
|
28
|
+
className: "rp-not-found__error-code",
|
|
29
|
+
children: response ? error.status : 'ERROR'
|
|
30
|
+
}),
|
|
31
|
+
/*#__PURE__*/ jsx("h1", {
|
|
32
|
+
className: "rp-not-found__title",
|
|
33
|
+
id: "rp-error-title",
|
|
34
|
+
ref: title,
|
|
35
|
+
tabIndex: -1,
|
|
36
|
+
children: heading
|
|
37
|
+
}),
|
|
38
|
+
/*#__PURE__*/ jsx("div", {
|
|
39
|
+
className: "rp-not-found__divider"
|
|
40
|
+
}),
|
|
41
|
+
/*#__PURE__*/ jsx("p", {
|
|
42
|
+
className: "rp-error__description",
|
|
43
|
+
children: text("errorDescriptionText", 'This page could not be loaded. Try reloading it or return to the home page.')
|
|
44
|
+
}),
|
|
45
|
+
/*#__PURE__*/ jsxs("div", {
|
|
46
|
+
className: "rp-not-found__action rp-error__actions",
|
|
47
|
+
children: [
|
|
48
|
+
/*#__PURE__*/ jsx("button", {
|
|
49
|
+
type: "button",
|
|
50
|
+
className: "rp-not-found__home-link",
|
|
51
|
+
onClick: ()=>window.location.reload(),
|
|
52
|
+
children: text('reloadPageText', 'Reload page')
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ jsx("a", {
|
|
55
|
+
className: "rp-not-found__home-link",
|
|
56
|
+
href: homeHref,
|
|
57
|
+
children: text('takeMeHomeText', 'Take me home')
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
}),
|
|
61
|
+
details && /*#__PURE__*/ jsxs("details", {
|
|
62
|
+
className: "rp-error__details",
|
|
63
|
+
open: true,
|
|
64
|
+
children: [
|
|
65
|
+
/*#__PURE__*/ jsx("summary", {
|
|
66
|
+
children: text('errorDetailsText', 'Error details')
|
|
67
|
+
}),
|
|
68
|
+
/*#__PURE__*/ jsx("pre", {
|
|
69
|
+
children: details
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export { ErrorLayout };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { WebMcpOptions } from '@rspress/core/runtime';
|
|
2
|
+
import type { PageInfo } from './types.js';
|
|
3
|
+
type Field = {
|
|
4
|
+
type: 'string';
|
|
5
|
+
minLength?: number;
|
|
6
|
+
} | {
|
|
7
|
+
type: 'integer';
|
|
8
|
+
minimum: number;
|
|
9
|
+
maximum?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const queryField: Field;
|
|
12
|
+
export declare const routePathField: Field;
|
|
13
|
+
export declare function toWebMcpSearchResults(groups: {
|
|
14
|
+
group: string;
|
|
15
|
+
result: unknown;
|
|
16
|
+
}[]): {
|
|
17
|
+
group: string;
|
|
18
|
+
results: unknown;
|
|
19
|
+
}[];
|
|
20
|
+
export declare function resolveInternalRoute(value: string, context: {
|
|
21
|
+
origin: string;
|
|
22
|
+
resolveRoute(pathname: string): string | undefined;
|
|
23
|
+
}): string;
|
|
24
|
+
export declare function metadata(page: PageInfo): {
|
|
25
|
+
title: string;
|
|
26
|
+
description: string | undefined;
|
|
27
|
+
routePath: string;
|
|
28
|
+
lang: string;
|
|
29
|
+
version: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function readPage(page: PageInfo, base: string, signal?: AbortSignal, fetcher?: typeof fetch): Promise<{
|
|
32
|
+
title: string;
|
|
33
|
+
description: string | undefined;
|
|
34
|
+
routePath: string;
|
|
35
|
+
lang: string;
|
|
36
|
+
version: string;
|
|
37
|
+
frontmatter: import("@rspress/shared").FrontMatterMeta;
|
|
38
|
+
toc: import("@rspress/shared").Header[];
|
|
39
|
+
markdown: string;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function listPages(pages: PageInfo[], current: Pick<PageInfo, 'lang' | 'version'>, args: Record<string, unknown>): {
|
|
42
|
+
pages: {
|
|
43
|
+
title: string;
|
|
44
|
+
description: string | undefined;
|
|
45
|
+
routePath: string;
|
|
46
|
+
lang: string;
|
|
47
|
+
version: string;
|
|
48
|
+
toc: import("@rspress/shared").Header[];
|
|
49
|
+
}[];
|
|
50
|
+
total: number;
|
|
51
|
+
offset: number;
|
|
52
|
+
limit: number;
|
|
53
|
+
};
|
|
54
|
+
/** Shared validation and defaults for Rspress's built-in tools. */
|
|
55
|
+
export declare function defineTool(name: string, description: string, fields: Record<string, Field>, required: string[], execute: (args: Record<string, unknown>, signal?: AbortSignal) => unknown): WebMcpOptions;
|
|
56
|
+
export {};
|