@ahxlo/lite-ai-websdk
@ahxlo/lite-ai-websdk
Ahxlo 智能体 Web 嵌入聊天 SDK。支持 npm(ESM) 与 CDN(IIFE) 接入。
对接后端: ahxlo-cloud-core-v2 开放嵌入接口(/indexApi/open/embed/**)。应用需开启嵌入(embedEnabled=1)。
要求
| 项 | 说明 |
|---|---|
| 开放 API | 已部署 Ahxlo cloud-core-v2 开放接口,基路径形如 https://your-api.example.com/indexApi;应用已开启嵌入 |
| npm 宿主 | vue@^3.5(peerDependency,ESM 接入时由宿主提供) |
| 浏览器 | ES2020+、SSE |
开放接口(v2)
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /open/embed/app/{appId} |
公开应用配置(含 modelConfig / dialogueExperience / webSdkConfig) |
| GET | /open/embed/app/{appId}/sessions |
访客会话列表 |
| GET | /open/embed/app/{appId}/messages |
会话消息分页 |
| DELETE | /open/embed/app/{appId}/sessions/{conversationId} |
删除会话 |
| POST | /open/embed/completions |
SSE 流式对话(JSON:appId、prompt、enableThink、media…) |
| POST | /open/embed/upload |
访客附件上传(图片/视频) |
| POST | /open/embed/follow-up-questions |
追问建议 |
身份头:X-Embed-Guest-Key(必填)、可选 X-Embed-User-Id / X-Embed-User-Name。
SSE 载荷对齐 AigcSsePayload:meta / text / think / tool / citation / done / error(含 chatId)。
生成参数(temperature、sandbox、知识库等)由服务端按应用 modelConfig 注入,无需在 SDK 请求中传递。SDK 仅传访客身份、appId、prompt、conversationId、enableThink 与可选 media。
安装
npm
npm install @ahxlo/lite-ai-websdk
CDN
从 npm 发布产物加载(推荐固定版本号):
| 源 | 地址 |
|---|---|
| jsDelivr | https://cdn.jsdelivr.net/npm/@ahxlo/lite-ai-websdk@1/dist/aigc-widget.js |
| unpkg | https://unpkg.com/@ahxlo/lite-ai-websdk@1/dist/aigc-widget.js |
- 使用
@1:始终解析为最新 1.x(如1.0.2),一般无需每次 patch 改 URL。 - 使用
@1.0.2:锁定该版本,升级 SDK 时需手动改地址。 - 亦可自托管
dist/aigc-widget.js。
快速接入
CDN(IIFE)
<script src="https://cdn.jsdelivr.net/npm/@ahxlo/lite-ai-websdk@1/dist/aigc-widget.js"></script>
<script>
window.AigcEmbed.init({
appId: 'YOUR_APP_ID',
apiBase: 'https://your-api.example.com/indexApi',
user: { id: 'user-1', name: '访客' }
});
</script>
- 加载完成后调用
window.AigcEmbed.init,必须传入appId、apiBase。 - 样式已内联,无需额外 CSS。
- 脚本使用
async/defer时,在onload或DOMContentLoaded后再调用init。
npm(ESM)
import { createAigcEmbed } from '@ahxlo/lite-ai-websdk';
const embed = createAigcEmbed({
appId: 'YOUR_APP_ID',
apiBase: 'https://your-api.example.com/indexApi'
});
embed.init({ user: { id: 'user-1', name: '访客' } });
embed.open();
embed.close();
embed.destroy();
- 不挂载
window.AigcEmbed。 - 同一
appId多次调用createAigcEmbed返回同一实例。
API
window.AigcEmbed(CDN)
| 方法 | 签名 | 说明 |
|---|---|---|
init |
(options: EmbedInitOptions) => void |
挂载;appId、apiBase 必填 |
open |
(appId?: string | number) => void |
打开面板 |
close |
(appId?: string | number) => void |
关闭面板 |
destroy |
(appId?: string | number) => void |
销毁实例 |
createAigcEmbed(npm)
function createAigcEmbed(options: {
appId: string | number;
apiBase: string;
cssUrl?: string;
webSdkConfig?: EmbedWebSdkConfigInput;
}): AigcEmbedInstance;
| 成员 | 签名 | 说明 |
|---|---|---|
init |
(options?: EmbedInitOptions) => void |
挂载 |
open |
() => void |
打开面板 |
close |
() => void |
关闭面板 |
destroy |
() => void |
销毁实例 |
EmbedInitOptions
| 字段 | 类型 | 说明 |
|---|---|---|
appId |
string | number |
应用 ID |
apiBase |
string |
开放 API 根路径(含 /indexApi) |
cssUrl |
string |
外链样式表(可选) |
user |
EmbedUserInfo |
访客身份 |
user.id |
string |
业务用户 ID |
user.name |
string |
展示名称 |
position |
'right-bottom' | 'left-bottom' |
FAB 位置,默认 right-bottom |
zIndex |
number |
层级,默认 2147483000 |
webSdkConfig |
EmbedWebSdkConfigInput |
窗体 / FAB 外观覆盖 |
类型见 dist/index.d.ts、dist/types.d.ts。
应用配置(体验对齐)
SDK 从公开 config 读取并生效:
| 配置 | 行为 |
|---|---|
modelConfig.enableThink / showThink |
深度思考默认值与 UI 展示 |
modelConfig.enableVisionImage / enableVisionVideo |
输入区附件入口;发送带 media[] |
dialogueExperience.followUp.enabled |
回复后追问建议芯片 |
dialogueExperience.shortcuts / bubbleTheme / chatBackground |
快捷指令、气泡主题、背景 |
webSdkConfig |
窗体 / FAB 外观 |
包内容
| 路径 | 说明 |
|---|---|
dist/index.esm.js |
ESM |
dist/aigc-widget.js |
IIFE(CDN) |
dist/index.d.ts |
入口类型 |
dist/types.d.ts |
选项类型 |
发布
发版到 npm 的步骤、检查项与常见问题见 PUBLISH.md。
许可证
Apache License 2.0
Related Packages
@menni/chatbot
A modern React and Vue chatbot component with customizable UI for integration in...
8,474
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 1.0.8 | ^3.5.0 | Apache-2.0 | |
| 1.0.7 | ^3.5.0 | Apache-2.0 | |
| 1.0.6 | ^3.5.0 | Apache-2.0 | |
| 1.0.5 | ^3.5.0 | Apache-2.0 | |
| 1.0.4 | ^3.5.0 | Apache-2.0 | |
| 1.0.3 | ^3.5.0 | Apache-2.0 | |
| 1.0.2 | ^3.5.0 | Apache-2.0 | |
| 1.0.1 | ^3.5.0 | MIT |