@lark-apaas/aily-web-sdk
v0.0.11
Published
Aily Web SDK - iframe-based chat panel integration
Keywords
Readme
Aily-Web-SDK
Aily Web SDK 是飞书 Aily 团队推出的轻量级 SDK,通过 iframe + postMessage 方式让你快速接入 Aily AI 能力。
特点
- 轻量级: 纯 iframe 实现,无 CDN 资源加载
- 高隔离性: 完全隔离的运行环境
- 简单易用: 简洁的 API 设计
安装
npm install @lark-apaas/aily-web-sdk使用
@lark-apaas/aily-web-sdk 当前提供两个初始化 API,分别面向不同的 Aily Chat 场景:
initAilyChat:用于初始化 Aily 工作流应用 Chat 面板,适合接入已有工作流应用的对话能力。initAgentChat:用于初始化 Aily 新版智能体 Chat 面板,适合接入新版智能体会话页面。
import { initAilyChat } from '@lark-apaas/aily-web-sdk'
const container = document.querySelector('.container');
const chatPanel = await initAilyChat(container, {
appKey: 'your-app-key',
common: {},
events: {
onReady: () => console.log('ready'),
onError: (error) => console.error(error)
}
});import { initAgentChat } from '@lark-apaas/aily-web-sdk'
const container = document.querySelector('.container');
const sdk = await initAgentChat(container, {
channelToken: 'wsk_xxx',
});API
initAilyChat(root, config)
初始化 Aily 工作流应用 Chat 面板。
适用场景:
- 宿主页面需要接入 Aily 工作流应用的 Chat 能力
- 需要使用
ChatPanel提供的消息发送、清空、更新配置等控制方法
参数:
root(HTMLElement) - iframe 挂载的容器元素config(WebSDKConfig) - 配置项appKey(string) - 应用 Keyuuid(string, 可选) - 用户标识device('pc' | 'mobile', 可选) - 设备类型common(WebSDKCommonConfig) - 通用配置baseURL(string) - Aily 服务地址headers(Record<string, string>, 可选) - 自定义请求头
events(WebSDKEvents, 可选) - 事件回调onReady- iframe 就绪回调onError- 错误回调onMessage- 消息回调
返回: Promise<ChatPanel>
initAgentChat(root, config)
初始化 Aily 新版智能体 Chat 面板。
适用场景:
- 宿主页面需要嵌入 Aily 新版智能体的 Chat 页面
- 只需要完成智能体 Chat 面板的初始化与销毁管理
参数:
root(HTMLElement) - iframe 挂载的容器元素config(AgentSDKInitConfig) - 配置项channelToken(string) - agent 渠道 token
返回: Promise<AgentSDKInstance>
ChatPanel
| 方法 | 说明 |
| --- | --- |
| sendMessage(data) | 发送消息 |
| clear() | 清空聊天记录 |
| cancelMessage(messageItem) | 取消消息 |
| clearAndStop() | 清空消息并停止当前响应 |
| updateWelcomeMessage() | 刷新欢迎消息 |
| updateConfig(config) | 更新面板配置 |
| destroy() | 销毁实例 |
AgentSDKInstance
| 方法 | 说明 |
| --- | --- |
| destroy() | 销毁 agent iframe 实例 |
License
MIT
