@lark-apaas/aily-web-sdk
v0.0.12
Published
Aily Web SDK - iframe-based chat panel integration
Keywords
Readme
Aily-Web-SDK
Aily Web SDK 是飞书 Aily 团队推出的轻量级 SDK,帮助你快速接入 Aily AI 能力。
特点
- 轻量级: 接入成本低,无 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',
});import { initAgentChat } from '@lark-apaas/aily-web-sdk'
const container = document.querySelector('.container');
const sdk = await initAgentChat(container, {
channelToken: 'wsk_xxx',
customParams: {
employee_id: {
value: '12345',
desc: '员工工号,可作为查询型技能的 user_id 入参'
}
}
});import { initAgentChat } from '@lark-apaas/aily-web-sdk'
const container = document.querySelector('.container');
const sdk = await initAgentChat(container, {
channelToken: 'wsk_xxx',
customParamsToken: 'jwt-token'
});API
initAilyChat(root, config)
初始化 Aily 工作流应用 Chat 面板。
适用场景:
- 宿主页面需要接入 Aily 工作流应用的 Chat 能力
- 需要使用
ChatPanel提供的消息发送、清空、更新配置等控制方法
参数:
root(HTMLElement) - 挂载容器元素config(WebSDKConfig) - 配置项appKey(string) - 应用 Keyuuid(string, 可选) - 用户标识device('pc' | 'mobile', 可选) - 设备类型common(WebSDKCommonConfig) - 通用配置baseURL(string) - Aily 服务地址headers(Record<string, string>, 可选) - 自定义请求头
events(WebSDKEvents, 可选) - 事件回调onReady- 面板就绪回调onError- 错误回调onMessage- 消息回调
返回: Promise<ChatPanel>
initAgentChat(root, config)
初始化 Aily 自定义智能体 Chat 面板。
适用场景:
- 宿主页面需要接入 Aily 自定义智能体的 Chat 能力
- 只需要完成智能体 Chat 面板的初始化与销毁管理
参数:
root(HTMLElement) - 挂载容器元素config(AgentSDKInitConfig) - 配置项channelToken(string) - agent 渠道 tokencustomParams(CustomParams, 可选) - 宿主初始化时注入的上下文;如有需要,也可在 JWT 模式下一并传入customParamsToken(string, 可选) - 宿主初始化时注入的 JWT 验签 token,JWT 模式下可单独传入
明文模式下可传
customParams;JWT 模式下传customParamsToken即可,如有需要也可同时传入customParams。
customParams/customParamsToken属于可选增强能力。如果
customParamsToken为空,或当前接入环境暂不支持该能力,custom context 将不会生效,但基础初始化流程仍会继续。
返回: Promise<AgentSDKInstance>
ChatPanel
| 方法 | 说明 |
| --- | --- |
| sendMessage(data) | 发送消息 |
| clear() | 清空聊天记录 |
| cancelMessage(messageItem) | 取消消息 |
| clearAndStop() | 清空消息并停止当前响应 |
| updateWelcomeMessage() | 刷新欢迎消息 |
| updateConfig(config) | 更新面板配置 |
| destroy() | 销毁实例 |
AgentSDKInstance
| 方法 | 说明 |
| --- | --- |
| destroy() | 销毁 agent 实例 |
License
MIT
