@leuria/docusaurus 0.1.0
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/LICENSE +202 -0
- package/README.md +19 -0
- package/dist/client/index.d.ts +22 -0
- package/dist/client/index.js +61 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +127 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @leuria/docusaurus
|
|
2
|
+
|
|
3
|
+
Ask AI for any Docusaurus site, on the reader's own AI: an assistant that answers from your docs with links to the pages. No API keys, nothing to pay per question.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @leuria/docusaurus
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// docusaurus.config.js
|
|
11
|
+
plugins: [["@leuria/docusaurus", { suggestions: ["How do I get started?"] }]]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- **Ask AI** in the navbar: answers from your docs, knows the page the reader has open and the text they selected.
|
|
15
|
+
- **Search** (`search: true`): ⌘K, by words at once and by meaning once the reader has an embedding model.
|
|
16
|
+
- **WebMCP**: the same docs tools for the browser's own agents.
|
|
17
|
+
- **Next to your search**: no theme component is replaced, so Algolia DocSearch and local search plugins keep working.
|
|
18
|
+
|
|
19
|
+
Every option, and what readers see: [Ask AI for your Docusaurus site](../../docs/developers/docusaurus.md). Built on [`@leuria/docs`](../docs). Docusaurus 3.6+. Apache-2.0.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Leuria } from '@leuria/client';
|
|
2
|
+
import { Docs } from '@leuria/docs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The client module: starts Leuria in the browser once, and keeps the Ask
|
|
6
|
+
* panel and its conversation across the site's page changes. Nothing runs
|
|
7
|
+
* while Docusaurus renders pages at build time.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The site's Leuria client and docs, once started in the browser (never
|
|
12
|
+
* during the build). For the site's own components:
|
|
13
|
+
*
|
|
14
|
+
* import { leuria } from "@leuria/docusaurus/client"
|
|
15
|
+
* const { ai } = await leuria
|
|
16
|
+
*/
|
|
17
|
+
declare const leuria: Promise<{
|
|
18
|
+
ai: Leuria;
|
|
19
|
+
docs: Docs;
|
|
20
|
+
}>;
|
|
21
|
+
|
|
22
|
+
export { leuria };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/client/index.ts
|
|
2
|
+
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
|
|
3
|
+
import config from "@leuria-docusaurus/config";
|
|
4
|
+
import loadEmbedder from "@leuria-docusaurus/embedder";
|
|
5
|
+
function navigate(url) {
|
|
6
|
+
const target = new URL(url, location.href);
|
|
7
|
+
if (target.origin !== location.origin) {
|
|
8
|
+
location.assign(target.href);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (target.pathname === location.pathname && target.search === location.search) {
|
|
12
|
+
location.hash = target.hash;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
history.pushState(null, "", `${target.pathname}${target.search}${target.hash}`);
|
|
16
|
+
dispatchEvent(new PopStateEvent("popstate", { state: null }));
|
|
17
|
+
}
|
|
18
|
+
function followTheme(setDefaultAppearance) {
|
|
19
|
+
const html = document.documentElement;
|
|
20
|
+
const apply = () => setDefaultAppearance(html.dataset.theme === "dark" ? "dark" : "light");
|
|
21
|
+
apply();
|
|
22
|
+
new MutationObserver(apply).observe(html, { attributes: true, attributeFilter: ["data-theme"] });
|
|
23
|
+
}
|
|
24
|
+
var started;
|
|
25
|
+
var leuria = new Promise((resolve) => {
|
|
26
|
+
started = resolve;
|
|
27
|
+
});
|
|
28
|
+
async function start(settings) {
|
|
29
|
+
const [{ bridge, browserAI, createLeuria, server }, { setDefaultAppearance, setDefaultClient }, { createDocs, setupDocs }] = await Promise.all([
|
|
30
|
+
import("@leuria/client"),
|
|
31
|
+
import("@leuria/connect"),
|
|
32
|
+
import("@leuria/docs")
|
|
33
|
+
]);
|
|
34
|
+
const providers = [bridge({ app: settings.app, needs: settings.needs }), browserAI()];
|
|
35
|
+
if (loadEmbedder) providers.push(await loadEmbedder());
|
|
36
|
+
if (settings.server) providers.push(server({ url: settings.server.url }));
|
|
37
|
+
const ai = createLeuria({ providers, fallback: settings.fallback });
|
|
38
|
+
setDefaultClient(ai);
|
|
39
|
+
followTheme(setDefaultAppearance);
|
|
40
|
+
const docs = createDocs(ai, {
|
|
41
|
+
corpus: () => import("@leuria-docusaurus/corpus").then((m) => m.default),
|
|
42
|
+
navigate
|
|
43
|
+
});
|
|
44
|
+
setupDocs(docs, { title: settings.title, suggestions: settings.suggestions, system: settings.system });
|
|
45
|
+
started({ ai, docs });
|
|
46
|
+
if (settings.askButton === "floating") {
|
|
47
|
+
const button = document.createElement("leuria-ask-button");
|
|
48
|
+
button.setAttribute("floating", "");
|
|
49
|
+
document.body.append(button);
|
|
50
|
+
}
|
|
51
|
+
if (settings.webmcp) {
|
|
52
|
+
await docs.load();
|
|
53
|
+
docs.expose();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
57
|
+
start(config).catch((error) => console.warn("[leuria] Ask AI could not start:", error));
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
leuria
|
|
61
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { LoadContext, Plugin } from '@docusaurus/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @leuria/docusaurus: Ask AI for any Docusaurus site, on the reader's own
|
|
5
|
+
* AI. The site holds no API keys and pays nothing per question.
|
|
6
|
+
*
|
|
7
|
+
* // docusaurus.config.js
|
|
8
|
+
* plugins: [["@leuria/docusaurus", { suggestions: ["How do I get started?"] }]]
|
|
9
|
+
*
|
|
10
|
+
* It adds an "Ask AI" button to the navbar, and a panel that answers from
|
|
11
|
+
* the site's docs with links to the pages. It works next to any search
|
|
12
|
+
* (Algolia DocSearch, local search): it replaces no theme component. Sites
|
|
13
|
+
* without a search can add Leuria's (`search: true`), by words and by meaning.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface Options {
|
|
17
|
+
/** The name Leuria shows when the reader connects the site. Default: the site's title. */
|
|
18
|
+
app?: string;
|
|
19
|
+
/** The name the assistant gives the docs. Default: the site's title. */
|
|
20
|
+
site?: string;
|
|
21
|
+
/** The Ask panel's title. Default "Ask the docs". */
|
|
22
|
+
title?: string;
|
|
23
|
+
/** Questions offered before the first one. */
|
|
24
|
+
suggestions?: string[];
|
|
25
|
+
/** Replaces the assistant's instructions. */
|
|
26
|
+
system?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Where the Ask button goes: `navbar` (default), `floating` (bottom
|
|
29
|
+
* right), or `none` (you place `<leuria-ask-button>` yourself).
|
|
30
|
+
*/
|
|
31
|
+
askButton?: "navbar" | "floating" | "none";
|
|
32
|
+
/**
|
|
33
|
+
* Add a search to the navbar (⌘K), by words and by meaning. For sites
|
|
34
|
+
* without one: leave it off next to Algolia DocSearch or a local search.
|
|
35
|
+
* Default false.
|
|
36
|
+
*/
|
|
37
|
+
search?: boolean;
|
|
38
|
+
/** Also put the "Connect your AI" button in the navbar. Default false: the Ask panel offers it when needed. */
|
|
39
|
+
connectButton?: boolean;
|
|
40
|
+
/** Offer the docs tools to the browser's own agents (WebMCP). Default true. */
|
|
41
|
+
webmcp?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* A small embedding model in the page (`@leuria/web-embed`, about 40 MB,
|
|
44
|
+
* downloaded when the reader agrees) for readers whose AI can't embed.
|
|
45
|
+
* Its runtime comes from a CDN (jsDelivr) and the model from Hugging
|
|
46
|
+
* Face. Install `@leuria/web-embed` to use it. Default false.
|
|
47
|
+
*/
|
|
48
|
+
pageEmbeddings?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* What the Ask panel needs, so Leuria recommends a model that fits and no
|
|
51
|
+
* bigger. Default `{ tools: true, effort: "light" }`: it searches and reads
|
|
52
|
+
* your pages, then answers.
|
|
53
|
+
*/
|
|
54
|
+
needs?: {
|
|
55
|
+
tools?: boolean;
|
|
56
|
+
images?: boolean;
|
|
57
|
+
effort?: "light" | "standard" | "deep";
|
|
58
|
+
context?: number;
|
|
59
|
+
};
|
|
60
|
+
/** Your server as the last resort, for readers with no AI of their own. */
|
|
61
|
+
server?: {
|
|
62
|
+
url: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Readers without Leuria: `ask` (default) proposes Leuria first, and this
|
|
66
|
+
* browser's AI or your server answer only once the reader picks one (for
|
|
67
|
+
* the page); `auto` uses them at once.
|
|
68
|
+
*/
|
|
69
|
+
fallback?: "ask" | "auto";
|
|
70
|
+
/** Only these docs plugin instances. Default: every one. */
|
|
71
|
+
docsPluginIds?: string[];
|
|
72
|
+
}
|
|
73
|
+
/** What the client module gets, as JSON. */
|
|
74
|
+
interface ClientConfig {
|
|
75
|
+
app: string;
|
|
76
|
+
title?: string;
|
|
77
|
+
suggestions?: string[];
|
|
78
|
+
system?: string;
|
|
79
|
+
askButton: "navbar" | "floating" | "none";
|
|
80
|
+
webmcp: boolean;
|
|
81
|
+
server?: {
|
|
82
|
+
url: string;
|
|
83
|
+
};
|
|
84
|
+
fallback: "ask" | "auto";
|
|
85
|
+
needs: {
|
|
86
|
+
tools?: boolean;
|
|
87
|
+
images?: boolean;
|
|
88
|
+
effort?: "light" | "standard" | "deep";
|
|
89
|
+
context?: number;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
declare function leuriaDocusaurus(context: LoadContext, options?: Options): Plugin;
|
|
93
|
+
declare function validateOptions({ options }: {
|
|
94
|
+
options?: Options & {
|
|
95
|
+
id?: string;
|
|
96
|
+
};
|
|
97
|
+
}): Options & {
|
|
98
|
+
id: string;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { type ClientConfig, type Options, leuriaDocusaurus as default, validateOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { buildCorpus } from "@leuria/docs/build";
|
|
6
|
+
var NAME = "@leuria/docusaurus";
|
|
7
|
+
function docsPages(context, allContent, ids) {
|
|
8
|
+
const pages = [];
|
|
9
|
+
let defaultVersion;
|
|
10
|
+
const instances = allContent["docusaurus-plugin-content-docs"] ?? {};
|
|
11
|
+
for (const [id, content] of Object.entries(instances)) {
|
|
12
|
+
if (ids && !ids.includes(id)) continue;
|
|
13
|
+
const versions = content.loadedVersions ?? [];
|
|
14
|
+
const versioned = versions.length > 1;
|
|
15
|
+
for (const version of versions) {
|
|
16
|
+
if (versioned && version.isLast) defaultVersion ??= version.versionName;
|
|
17
|
+
for (const doc of version.docs) {
|
|
18
|
+
if (doc.unlisted || doc.draft) continue;
|
|
19
|
+
const file = doc.source.replace(/^@site\//, `${context.siteDir}/`);
|
|
20
|
+
let markdown;
|
|
21
|
+
try {
|
|
22
|
+
markdown = readFileSync(file, "utf8");
|
|
23
|
+
} catch {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
pages.push({
|
|
27
|
+
url: doc.permalink,
|
|
28
|
+
title: doc.title,
|
|
29
|
+
description: doc.description,
|
|
30
|
+
markdown,
|
|
31
|
+
version: versioned ? version.versionName : void 0
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { pages, defaultVersion };
|
|
37
|
+
}
|
|
38
|
+
function addNavbarItems(context, items) {
|
|
39
|
+
const navbar = context.siteConfig.themeConfig.navbar;
|
|
40
|
+
if (!navbar) return;
|
|
41
|
+
navbar.items ??= [];
|
|
42
|
+
for (const item of items) {
|
|
43
|
+
if (!navbar.items.some((existing) => existing.value === item.value)) navbar.items.push(item);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function leuriaDocusaurus(context, options = {}) {
|
|
47
|
+
const dir = join(context.generatedFilesDir, "leuria");
|
|
48
|
+
const files = {
|
|
49
|
+
config: join(dir, "config.json"),
|
|
50
|
+
corpus: join(dir, "corpus.json"),
|
|
51
|
+
embedder: join(dir, "embedder.js")
|
|
52
|
+
};
|
|
53
|
+
const title = context.siteConfig.title;
|
|
54
|
+
const askButton = options.askButton ?? "navbar";
|
|
55
|
+
const config = {
|
|
56
|
+
app: options.app ?? title,
|
|
57
|
+
title: options.title,
|
|
58
|
+
suggestions: options.suggestions,
|
|
59
|
+
system: options.system,
|
|
60
|
+
askButton,
|
|
61
|
+
webmcp: options.webmcp ?? true,
|
|
62
|
+
server: options.server,
|
|
63
|
+
fallback: options.fallback ?? "ask",
|
|
64
|
+
needs: options.needs ?? { tools: true, effort: "light" }
|
|
65
|
+
};
|
|
66
|
+
mkdirSync(dir, { recursive: true });
|
|
67
|
+
writeFileSync(files.config, JSON.stringify(config));
|
|
68
|
+
writeFileSync(files.corpus, JSON.stringify({ pages: [], sections: [] }));
|
|
69
|
+
writeFileSync(
|
|
70
|
+
files.embedder,
|
|
71
|
+
options.pageEmbeddings ? `export default function load() { return import("@leuria/web-embed/cdn").then((m) => m.pageEmbedder()); }
|
|
72
|
+
` : "export default null;\n"
|
|
73
|
+
);
|
|
74
|
+
const items = [];
|
|
75
|
+
if (options.search) items.push({ type: "html", position: "right", value: "<leuria-search-button></leuria-search-button>", className: "leuria-navbar-item" });
|
|
76
|
+
if (askButton === "navbar") items.push({ type: "html", position: "right", value: "<leuria-ask-button></leuria-ask-button>", className: "leuria-navbar-item" });
|
|
77
|
+
if (options.connectButton) {
|
|
78
|
+
items.push({ type: "html", position: "right", value: '<leuria-connect-button size="1" hide-byline></leuria-connect-button>', className: "leuria-navbar-item" });
|
|
79
|
+
}
|
|
80
|
+
addNavbarItems(context, items);
|
|
81
|
+
return {
|
|
82
|
+
name: NAME,
|
|
83
|
+
async allContentLoaded({ allContent }) {
|
|
84
|
+
const { pages, defaultVersion } = docsPages(context, allContent, options.docsPluginIds);
|
|
85
|
+
const corpus = buildCorpus(pages, { site: options.site ?? title, defaultVersion });
|
|
86
|
+
writeFileSync(files.corpus, JSON.stringify(corpus));
|
|
87
|
+
},
|
|
88
|
+
configureWebpack() {
|
|
89
|
+
return {
|
|
90
|
+
resolve: {
|
|
91
|
+
alias: {
|
|
92
|
+
"@leuria-docusaurus/config": files.config,
|
|
93
|
+
"@leuria-docusaurus/corpus": files.corpus,
|
|
94
|
+
"@leuria-docusaurus/embedder": files.embedder
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
getClientModules() {
|
|
100
|
+
return [fileURLToPath(new URL("./client/index.js", import.meta.url))];
|
|
101
|
+
},
|
|
102
|
+
injectHtmlTags() {
|
|
103
|
+
return {
|
|
104
|
+
headTags: [
|
|
105
|
+
{
|
|
106
|
+
tagName: "style",
|
|
107
|
+
innerHTML: ".leuria-navbar-item{display:inline-flex;align-items:center;padding:0 var(--ifm-navbar-item-padding-horizontal,.75rem)}leuria-ask{--leuria-ask-top:calc(var(--ifm-navbar-height,3.75rem) + 8px)}"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function validateOptions({ options }) {
|
|
115
|
+
const value = options ?? {};
|
|
116
|
+
if (value.askButton && !["navbar", "floating", "none"].includes(value.askButton)) {
|
|
117
|
+
throw new Error(`${NAME}: askButton must be "navbar", "floating" or "none".`);
|
|
118
|
+
}
|
|
119
|
+
if (value.suggestions && !Array.isArray(value.suggestions)) throw new Error(`${NAME}: suggestions must be a list of questions.`);
|
|
120
|
+
if (value.server && typeof value.server.url !== "string") throw new Error(`${NAME}: server needs a url.`);
|
|
121
|
+
if (value.fallback && !["ask", "auto"].includes(value.fallback)) throw new Error(`${NAME}: fallback must be "ask" or "auto".`);
|
|
122
|
+
return { ...value, id: value.id ?? "default" };
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
leuriaDocusaurus as default,
|
|
126
|
+
validateOptions
|
|
127
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leuria/docusaurus",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Ask AI for any Docusaurus site, on the reader's own AI: no API keys, nothing to pay per question. Plus the Connect button and WebMCP tools for the browser's agents.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/leur-ia/leuria.git",
|
|
10
|
+
"directory": "packages/docusaurus"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://leuria.dev",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"docusaurus",
|
|
15
|
+
"docusaurus-plugin",
|
|
16
|
+
"ai",
|
|
17
|
+
"ask-ai",
|
|
18
|
+
"search",
|
|
19
|
+
"webmcp"
|
|
20
|
+
],
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./client": {
|
|
29
|
+
"types": "./dist/client/index.d.ts",
|
|
30
|
+
"default": "./dist/client/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@leuria/client": "^0.1.0",
|
|
38
|
+
"@leuria/connect": "^0.1.0",
|
|
39
|
+
"@leuria/docs": "^0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@docusaurus/core": "^3.6.0",
|
|
43
|
+
"@leuria/web-embed": "^0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@leuria/web-embed": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@docusaurus/types": "^3.10.2",
|
|
52
|
+
"@types/node": "^22.0.0",
|
|
53
|
+
"tsup": "^8.4.0",
|
|
54
|
+
"typescript": "^5.9.0",
|
|
55
|
+
"vitest": "^3.2.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"check": "tsc --noEmit",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
62
|
+
}
|