mkdocs-ai-chatbot 1.0.0__py3-none-any.whl
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.
- mkdocs_ai_chatbot/__init__.py +4 -0
- mkdocs_ai_chatbot/plugin.py +102 -0
- mkdocs_ai_chatbot-1.0.0.dist-info/METADATA +94 -0
- mkdocs_ai_chatbot-1.0.0.dist-info/RECORD +8 -0
- mkdocs_ai_chatbot-1.0.0.dist-info/WHEEL +5 -0
- mkdocs_ai_chatbot-1.0.0.dist-info/entry_points.txt +2 -0
- mkdocs_ai_chatbot-1.0.0.dist-info/licenses/LICENSE +21 -0
- mkdocs_ai_chatbot-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Asyntai AI chatbot for MkDocs.
|
|
3
|
+
|
|
4
|
+
Adds the Asyntai chat widget to every page that MkDocs builds. The plugin
|
|
5
|
+
writes the ordinary embed snippet in front of the closing body tag of each
|
|
6
|
+
page. Nothing else about the site changes: no theme files are overridden and
|
|
7
|
+
no CSS is added.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
from mkdocs.config import config_options
|
|
13
|
+
from mkdocs.exceptions import PluginError
|
|
14
|
+
from mkdocs.plugins import BasePlugin
|
|
15
|
+
|
|
16
|
+
DEFAULT_SCRIPT_URL = "https://widget.asyntai.com/static/js/chat-widget.js"
|
|
17
|
+
WIDGET_ID_PATTERN = re.compile(r"^asyntai_[A-Za-z0-9]+$")
|
|
18
|
+
|
|
19
|
+
# The last closing body tag of the page. A page can quote "</body>" inside a
|
|
20
|
+
# code block, so only the final one is the real end of the document.
|
|
21
|
+
_BODY_END = re.compile(r"</body\s*>", re.IGNORECASE)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def build_tag(widget_id, script_url):
|
|
25
|
+
return (
|
|
26
|
+
'<script async src="{src}" data-asyntai-id="{wid}"></script>'.format(
|
|
27
|
+
src=script_url.replace('"', """),
|
|
28
|
+
wid=widget_id,
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def insert_tag(html, tag):
|
|
34
|
+
"""Put the tag in front of the last </body>, or at the end if there is none."""
|
|
35
|
+
matches = list(_BODY_END.finditer(html))
|
|
36
|
+
if not matches:
|
|
37
|
+
return html + tag
|
|
38
|
+
end = matches[-1].start()
|
|
39
|
+
return html[:end] + tag + "\n" + html[end:]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class AsyntaiPlugin(BasePlugin):
|
|
43
|
+
config_scheme = (
|
|
44
|
+
("widget_id", config_options.Type(str, default="")),
|
|
45
|
+
# Set to false to keep the widget off the site during `mkdocs serve`.
|
|
46
|
+
("enable_on_serve", config_options.Type(bool, default=True)),
|
|
47
|
+
# Advanced. Load the widget from another URL.
|
|
48
|
+
("script_url", config_options.Type(str, default=DEFAULT_SCRIPT_URL)),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def __init__(self):
|
|
52
|
+
super().__init__()
|
|
53
|
+
self._command = "build"
|
|
54
|
+
self._tag = ""
|
|
55
|
+
|
|
56
|
+
def on_startup(self, *, command, dirty):
|
|
57
|
+
self._command = command
|
|
58
|
+
|
|
59
|
+
def on_config(self, config):
|
|
60
|
+
widget_id = (self.config.get("widget_id") or "").strip()
|
|
61
|
+
if not widget_id:
|
|
62
|
+
raise PluginError(
|
|
63
|
+
'mkdocs-ai-chatbot: "widget_id" is required. Copy it from the '
|
|
64
|
+
"Install page of your Asyntai dashboard, for example "
|
|
65
|
+
"asyntai_1a2b3c4d5e6f."
|
|
66
|
+
)
|
|
67
|
+
if not WIDGET_ID_PATTERN.match(widget_id):
|
|
68
|
+
raise PluginError(
|
|
69
|
+
'mkdocs-ai-chatbot: "{0}" does not look like a widget ID. It '
|
|
70
|
+
"starts with asyntai_, for example asyntai_1a2b3c4d5e6f.".format(
|
|
71
|
+
widget_id
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
script_url = (self.config.get("script_url") or "").strip() or DEFAULT_SCRIPT_URL
|
|
75
|
+
self._tag = build_tag(widget_id, script_url)
|
|
76
|
+
return config
|
|
77
|
+
|
|
78
|
+
def _active(self):
|
|
79
|
+
if self._command == "serve" and not self.config.get("enable_on_serve"):
|
|
80
|
+
return False
|
|
81
|
+
return bool(self._tag)
|
|
82
|
+
|
|
83
|
+
def _add(self, html):
|
|
84
|
+
if not self._active():
|
|
85
|
+
return html
|
|
86
|
+
# The site owner already pasted the snippet in a theme override. Two
|
|
87
|
+
# loaders would only fight over one chat bubble, so keep theirs.
|
|
88
|
+
if "data-asyntai-id" in html:
|
|
89
|
+
return html
|
|
90
|
+
return insert_tag(html, self._tag)
|
|
91
|
+
|
|
92
|
+
def on_post_page(self, output, *, page, config):
|
|
93
|
+
return self._add(output)
|
|
94
|
+
|
|
95
|
+
def on_post_template(self, output_content, *, template_name, config):
|
|
96
|
+
# Static templates such as 404.html, and search.html in the Read the
|
|
97
|
+
# Docs theme, are not pages, so on_post_page never sees them. A
|
|
98
|
+
# visitor on a dead link or a failed search needs the chat most.
|
|
99
|
+
# sitemap.xml and other non-HTML templates stay as they are.
|
|
100
|
+
if template_name.lower().endswith((".html", ".htm")):
|
|
101
|
+
return self._add(output_content)
|
|
102
|
+
return output_content
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mkdocs-ai-chatbot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Add the Asyntai AI chat assistant to your MkDocs site. It answers visitor questions from your own documentation.
|
|
5
|
+
Author-email: Asyntai <hello@asyntai.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://asyntai.com/documentation/integrations/mkdocs/
|
|
8
|
+
Project-URL: Documentation, https://asyntai.com/documentation/integrations/mkdocs/
|
|
9
|
+
Project-URL: Source, https://github.com/asyntai/mkdocs-ai-chatbot
|
|
10
|
+
Project-URL: Issues, https://github.com/asyntai/mkdocs-ai-chatbot/issues
|
|
11
|
+
Keywords: mkdocs,mkdocs-plugin,chatbot,ai,chat,support,documentation,asyntai
|
|
12
|
+
Classifier: Framework :: MkDocs
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Documentation
|
|
15
|
+
Classifier: Topic :: Communications :: Chat
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: mkdocs>=1.4
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# mkdocs-ai-chatbot
|
|
23
|
+
|
|
24
|
+
Add the [Asyntai](https://asyntai.com) AI chat assistant to your MkDocs site.
|
|
25
|
+
It answers visitor questions from your own documentation, day and night.
|
|
26
|
+
|
|
27
|
+
Works with every MkDocs theme, including Material for MkDocs and Read the Docs.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install mkdocs-ai-chatbot
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Then add the plugin in `mkdocs.yml`:
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
plugins:
|
|
39
|
+
- search
|
|
40
|
+
- asyntai:
|
|
41
|
+
widget_id: asyntai_1a2b3c4d5e6f
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Build the site. The chat bubble is on every page.
|
|
45
|
+
|
|
46
|
+
Keep `search` in the list if you use it. When `mkdocs.yml` has a `plugins`
|
|
47
|
+
section, MkDocs only loads the plugins named there.
|
|
48
|
+
|
|
49
|
+
## Where the widget ID comes from
|
|
50
|
+
|
|
51
|
+
Open the Install page in your [Asyntai dashboard](https://asyntai.com/dashboard).
|
|
52
|
+
The widget ID is the value of `data-asyntai-id` in the snippet shown there. It
|
|
53
|
+
starts with `asyntai_`.
|
|
54
|
+
|
|
55
|
+
Creating an account is free, and the Free plan is enough to try the widget.
|
|
56
|
+
|
|
57
|
+
## Options
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | What it does |
|
|
60
|
+
| --- | --- | --- | --- |
|
|
61
|
+
| `widget_id` | string | required | Your Asyntai widget ID |
|
|
62
|
+
| `enable_on_serve` | boolean | `true` | Set to `false` to keep the widget off the site during `mkdocs serve` |
|
|
63
|
+
| `script_url` | string | the Asyntai CDN | Advanced. Load the widget from another URL |
|
|
64
|
+
|
|
65
|
+
A missing or malformed `widget_id` stops the build with a message that says how
|
|
66
|
+
to fix it.
|
|
67
|
+
|
|
68
|
+
## What the plugin does
|
|
69
|
+
|
|
70
|
+
- It adds one `<script>` tag in front of the closing body tag of every page.
|
|
71
|
+
- It marks the tag `async`, so your documentation renders first.
|
|
72
|
+
- It changes nothing else. No theme files are overridden and no CSS is added.
|
|
73
|
+
- If a page already has the Asyntai snippet, for example from a theme
|
|
74
|
+
override, the plugin leaves that page alone.
|
|
75
|
+
|
|
76
|
+
## Answering from your documentation
|
|
77
|
+
|
|
78
|
+
Asyntai reads your published pages. Add your site URL in the dashboard, and the
|
|
79
|
+
assistant answers from the same documentation the widget sits on. You can also
|
|
80
|
+
add documents, and question and answer pairs.
|
|
81
|
+
|
|
82
|
+
## Removing it
|
|
83
|
+
|
|
84
|
+
Delete the `asyntai` entry from `mkdocs.yml` and build again. The widget is
|
|
85
|
+
gone.
|
|
86
|
+
|
|
87
|
+
## Support
|
|
88
|
+
|
|
89
|
+
Email [hello@asyntai.com](mailto:hello@asyntai.com), or read the
|
|
90
|
+
[MkDocs guide](https://asyntai.com/documentation/integrations/mkdocs/).
|
|
91
|
+
|
|
92
|
+
## Licence
|
|
93
|
+
|
|
94
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
mkdocs_ai_chatbot/__init__.py,sha256=v3LZicucHNaZKzOxDTGEkVG-hRolcsT81Wntgw8QMbg,127
|
|
2
|
+
mkdocs_ai_chatbot/plugin.py,sha256=4CkU4huow3xnyNYM6N_adr5zDYIsji5_f68PBrJLDkY,3763
|
|
3
|
+
mkdocs_ai_chatbot-1.0.0.dist-info/licenses/LICENSE,sha256=jGsodKzosaT2Pr7P3ahTkLrMTHQ6uvf111OMRXeGYUM,1064
|
|
4
|
+
mkdocs_ai_chatbot-1.0.0.dist-info/METADATA,sha256=fuvSA6riXy9W2xfCxRrR6Sj9aN74sUYrGxgQ4uKyud0,3255
|
|
5
|
+
mkdocs_ai_chatbot-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
6
|
+
mkdocs_ai_chatbot-1.0.0.dist-info/entry_points.txt,sha256=U5gzeZGsakSRvvUO8YnKzjxgpqfgLlYLkbQpmLDNDy0,66
|
|
7
|
+
mkdocs_ai_chatbot-1.0.0.dist-info/top_level.txt,sha256=DjEphkVuJzJrQ4z64GXe7ZyJkicG3fNig4U7uVIRGaQ,18
|
|
8
|
+
mkdocs_ai_chatbot-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asyntai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mkdocs_ai_chatbot
|