🤖 AI Agent Widget
一行 JS 嵌入 AI 知识库助手到任何网站, 用户可直接在你的网站搜索本站内容.
特性
- ✅ 一行 JS 嵌入, 无依赖
- ✅ 自动调用
/api/search - ✅ 移动端响应式
- ✅ 暗色 / 亮色 / 位置可配
- ✅ 0 依赖 12KB
📋 嵌入代码
复制到任何 HTML 页面 </body> 之前:
<!-- 方式 1: 放在 </body> 之前 -->
<script src="https://ai-blog.example.com/widget/agent.js"
data-site="https://ai-blog.example.com"
data-position="bottom-right"
data-theme="dark"
data-title="AI 知识库助手"></script> ⚛️ React 集成
// React 组件
import { useEffect } from 'react';
export function AIWidget() {
useEffect(() => {
const s = document.createElement('script');
s.src = 'https://ai-blog.example.com/widget/agent.js';
s.setAttribute('data-site', 'https://ai-blog.example.com');
s.async = true;
document.body.appendChild(s);
return () => { document.body.removeChild(s); };
}, []);
return null;
} ⚙️ 配置项
| 属性 | 说明 | 默认 |
|---|---|---|
data-site | API 站点 URL | 当前域名 |
data-position | 位置 (bottom-right / bottom-left) | bottom-right |
data-theme | 主题 (dark / light) | dark |
data-title | 对话框标题 | AI 知识库助手 |
🧪 演示
本页面右下角已嵌入 Widget, 试试点击!
🔌 API 后端
Widget 调用以下 API:
- /ai-blog/api/search?q=keyword - 语义搜索
- /ai-blog/api/mcp - MCP Server
- /ai-blog/api/a2a - A2A Agent