1.1.39 • Published 5 months ago
@alicloud-panxi/aicoach-sdk v1.1.39
磐曦 AI Coach 运行时 SDK 使用文档
1. 安装 H5-SDK
npm install @alicloud-panxi/aicoach-sdk --save
2. 快速接入
2.1. 依赖
引入前置依赖包:
react、react-dom、moment(React 推荐 18+)
2.2. 引入
// React
import PanxiAicoachSDK from '@alicloud-panxi/aicoach-sdk';
// Vue
// import PanxiAicoachSdk from '@alicloud-panxi/aicoach-sdk/dist/index.es.vue';
import '@alicloud-panxi/aicoach-sdk/dist/aicoach-sdk.css';
const params: SDKOptions = {
// 通过第一步服务端对接后,服务端会透出一个api接口,这个接口地址就是apiPath
apiPath: 'https://xxx.com/path/to/server',
// 要渲染的容器dom节点
container: containerRef.current,
// 对练场景
type: 'practice',
taskId: '843025256126496768',
interact: 'text',
userId: '1524004782438033',
// 报告场景
type: 'report',
sessionId: '',
// UI自定义参数 - 按需
customOptions: {
global: {
// backgroundColor: '#000',
},
headerPanel: {
// isHideTitle: true,
},
},
// css主题自定义 - 按需
cssToken: {
'--panxi-color-brand': 'rgba(255, 0, 0, 1)', // 主题色
'--panxi-font-family': 'PingFang SC' // 字体
'--panxi-layout': 'loose' // 宽松布局,不设置则默认紧凑布局,只对报告页生效
}
};
// 实例化一个渲染对象
const newSdkInstance = new PanxiAicoachSDK(params);
// 获取sessionId
const sessionId = newSdkInstance.getSessionId();
// 关闭对练任务,返回Promise,可异步获取结果
newSdkInstance.closeTask();
// 完成对练任务,返回Promise,可异步获取结果
newSdkInstance.finishTask();
// 销毁渲染对象
newSdkInstance.stop();
interface SDKOptions {
apiPath: string;
container: HTMLElement;
type?: 'practice' | 'report';
interact?: 'text' | 'chat' | 'call' | 'video' | 'gif';
apiPathOptions?: Record<string, any>;
framework?: 'vue' | 'react';
taskId?: string;
sessionId?: string;
userId?: string;
customOptions?: CustomOptions;
cssToken?: cssToken;
onStart?: (data) => void;
onEnd?: (data) => void;
onSend?: (data) => void;
onReceive?: (data) => void;
onShowReport?: () => void;
}
2.3. 参数说明
参数名 | 描述 | 类型 | 是否必填 | 默认值 |
---|---|---|---|---|
apiPath | 接口地址-服务端对接后,提供的接口地址 | string | 是 | - |
container | 需要渲染到的容器的 DOM 节点 | HTMLElement | 是 | - |
apiPathOptions | apiPath 接口请求的配置(如 timeout,headers,method,withCredentials 等) | Record<string, any> | 否 | - |
type | 渲染类型,枚举值:practice-对练,report-报告 | string | 否 | practice |
interact | 互动形式,枚举值:chat-1:消息对练(含语音),text-2:消息对练(纯文本),call-3:电话对练,video-4:视频对练(数字人),gif-5:视频对练(动图) | string | 否 | chat |
taskId | 对练任务 id,当 type=practice 时必传 | string | 否 | - |
sessionId | 会话 id,当 type=report 时必传 | string | 否 | - |
userId | 用户 id,按需,服务端如果可以从 cookie 等地方获取,则不用传 | string | 否 | - |
onStart | 开始对练的回调 | function | 否 | - |
onEnd | 结束对练的回调 | function | 否 | - |
onSend | 发送消息的回调,回调内容为发送的消息体 | function | 否 | - |
onReceive | 收到消息的回调,回调内容为收到的消息体 | function | 否 | - |
onShowReport | 点击查看对练报告的回调 | function | 否 | - |
framework | 用到的技术栈,枚举:react,vue | string | 否 | react |
customOptions | UI 自定义参数,定义见下 | CustomOptions | 否 | - |
cssToken | css自定义主题 | cssToken | 否 | - |
2.4. 方法说明
方法名 | 描述 | 类型 | 是否有返回 | 返回值 |
---|---|---|---|---|
getSessionId | 获取对练任务sessionId | function | 是 | sessionId: string |
closeTask | 关闭对练任务 | function | 是 | res: Promise |
finishTask | 完成对练任务 | function | 是 | res: Promise |
stop | 销毁当前实例 | function | 否 | - |
2.5. UI 自定义参数类型 CustomOptions
⚠️ boolean 类型的数据默认值都为 false
- global:全局对象
参数名 | 描述 | 类型 | 上下文 |
---|---|---|---|
backgroundImage | 背景图片 | string | - |
backgroundColor | 背景颜色 | string | - |
- headerPanel:头部面板
参数名 | 描述 | 类型 | 扩展字段 | 上下文 | |
---|---|---|---|---|---|
isHideTitle | 是否隐藏标题 | boolean | - | - | |
isHideFinishButton | 是否隐藏完成测试按钮 | boolean | - | - | |
isHideCountDown | 是否隐藏倒计时 | boolean | - | - | |
textReplace | 文案替换 | object | tips | remainingTimeText'剩余对练时长' | - |
reportText'本次考核已结束' (报告页面-对练历史内容) | |||||
finishButtonText '完成对练' | - | ||||
CustomHeader | 自定义头部组件 | HTMLElement | - | 字段: title 标题 remainingTime 剩余时间 isfirstRoundFinish 是否完成一轮有效对话 interactTypeList 输入方式列表 | |
方法: close() 关闭对话任务 finishTask() 完成对练 finishTaskCheck() 完成对练(二次确认) handleChangeInteractType(key) 切换输入方式(continuous-持续收音,voiceInput-语音输入,textInput-打字聊天) |
- messagePanel:消息面板
参数名 | 描述 | 类型 | 扩展字段 | 上下文 |
---|---|---|---|---|
isHideMuteButton | 是否隐藏静音按钮 | boolean | - | - |
isHideWordsTipButton | 是否隐藏话术提示按钮 | boolean | - | - |
inputFocus | 输入框聚焦事件 | function | - | - |
inputBlur | 输入框失焦事件 | function | - | - |
CustomMessage | 自定义消息面板组件 | HTMLElement | - | 字段: ws websocket 对象 rtcInstance AliRtc 实例 messagesList 消息列表 inputType (多输入交互下)当前输入方式 isfirstRoundFinish 是否完成一轮对话isAgentAnswering 智能体是否正在回答realtimeWords 话术提示(流式返回) isUserTalking 用户是否正在录音 scriptInfo 剧本信息 ![]() |
方法: startRecord() 开始录音 handleCancel() 取消录音 handleSend(type, content?) 发送消息,type='text'为发送文本消息,type='voice'为发送音频,只有发送文本消息时需要传 content handleVolume() 智能体声音播放控制(默认播放智能体声音)handleClickRealtimeWords() 点击生成话术提示字聊天) |
- confirmPanel:确认面板(弹窗面板)
参数名 | 描述 | 类型 | 扩展字段 | 上下文 | |
---|---|---|---|---|---|
CustomStart | 自定义开始面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 开始 onCancel 退出 | |||||
customStartOptions | 开始面板文案替换 | object | textReplace | confirmText'开始' | - |
cancelText'退出' | - | ||||
CustomReStart | 自定义继续对练面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 确认 | |||||
CustomFinishConfirm | 自定义完成对练提示面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 确定 onCancel 取消 | |||||
CustomCloseConfirm | 自定义退出考核提示面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 退出onCancel 取消 | |||||
CustomFinishOverlay | 自定义考核点覆盖完成提示面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 确定onCancel 取消 | |||||
CustomRemind | 自定义资源/网络错误提示面板 | HTMLElement | - | 字段: title 标题 content 内容 type 弹窗提示类型(finish-fail 倒计时结束无法完成会话,ws-disconnect ws断连,resource-out 资源过期) | |
方法: onConfirm 退出 | |||||
CustomAsrFailedRemind | 自定义 ASR 识别失败提示面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 确定 | |||||
CustomComplete | 自定义对练完成提示面板 | HTMLElement | - | 字段: title 标题 content 内容 | |
方法: onConfirm 确定 |
- resultPanel:结果面板(抽屉组件)
参数名 | 描述 | 类型 | 扩展字段 | 上下文 | |
---|---|---|---|---|---|
fullReportUrl | 查看完整报告跳转链接 | string | - | - | |
textReplace | 文案替换 | object | title // 标题 | processingText'对练完成,教练评测中' | - |
successText'对练未通过' | |||||
violation'对练已结束,存在违规行为' | |||||
pass'对练已通过' | |||||
finish '对练已结束' | |||||
failText'报告生成失败' | |||||
practiceTimeText'考试时长' | |||||
loadingText'评测报告生成中,可能需要1-2分钟,请耐心等待' | |||||
CustomResult | 自定义结果面板 | HTMLElement | - | 字段: reportData 测评报告数据 reportStatus 报告状态 scriptInfo 剧本信息 finishSessionResult 完成对练接口返回 | |
方法: gotoReport 查看报告 |
- reportPanel:报告面板(报告页)
参数名 | 描述 | 类型 | 扩展字段 | 上下文 |
---|---|---|---|---|
isHidePracticeButton | 是否隐藏查看对练内容按钮 | boolean | - | - |
isHideSwitchReportTypeButton | 是否隐藏查看完整/精简报告按钮 | boolean | - | - |
practiceHistoryUrl | 查看对练内容跳转链接 | string | - | - |
customButtonProps | 自定义按钮参数注:text 和 action 都存在才会生效 | object | text 按钮文案 | - |
action 方法 | - | |||
textReplace | 文案替换 | object | practiceTimeText'练习时长' | - |
gotoHistoryButtonText'查看对练内容' | - | |||
CustomReport | 自定义报告页面 | HTMLElement | - | 字段: reportData 完整报告数据 |
方法: gotoSessionHistory() 打开会话历史视图 closeInstance() 关闭 sdk 实例 | ||||
OverallRatingTab | 综合得分tab | object | isHideCoachComments: boolean;// 是否隐藏教练评语 | - |
isHideFeedBack : boolean; // 隐藏评价 | ||||
CheckPointTab | 考核重点tab | object | isHideCoachComments: boolean;// 是否隐藏教练评语 | - |
isHideFeedBack : boolean; // 是否隐藏评价 | ||||
isHidePromotionProposal: boolean; // 是否隐藏提升建议 | ||||
isHideScoringPoint: boolean; // 是否隐藏得分点 | ||||
QuestionScoreTab | 问题得分tab | object | isHideCoachComments: boolean;// 是否隐藏教练评语 | - |
isHideFeedBack : boolean; // 是否隐藏评价 | ||||
isHidePromotionProposal: boolean; // 是否隐藏提升建议 | ||||
isHideScoringPoint: boolean; // 是否隐藏得分点 | ||||
ExpressiveAbilityTab | 表达能力tab | object | isHideCoachComments: boolean;// 是否隐藏教练评语 | - |
isHidePromotionProposal: boolean; // 是否隐藏提升建议 | ||||
isHideFeedBack : boolean; // 是否隐藏评价 |
2.6. 版本说明
版本说明;
1.1.39
5 months ago
1.1.38-beta.1
5 months ago
1.1.38-beta.0
5 months ago
1.1.38
5 months ago
1.1.37
5 months ago
1.1.36
6 months ago
1.1.35
6 months ago
1.1.34
6 months ago
1.1.33
6 months ago
1.1.32
6 months ago
1.1.31
6 months ago
1.1.30
6 months ago
1.1.29
6 months ago
1.1.27
7 months ago
1.1.26
7 months ago
1.1.25
7 months ago
1.1.24
7 months ago
1.1.23
7 months ago
1.1.22
7 months ago
1.1.21
7 months ago
1.1.20
7 months ago
1.1.19
7 months ago
1.1.18
7 months ago
1.1.17
7 months ago
1.1.16
7 months ago
1.1.15
7 months ago
1.1.14
7 months ago
1.1.13
7 months ago
1.1.12
8 months ago
1.1.11
8 months ago
1.1.10
8 months ago
1.1.9
8 months ago
1.1.8
8 months ago
1.1.7
9 months ago
1.1.6
9 months ago
1.1.5
9 months ago
1.1.4
9 months ago
1.1.3
9 months ago
1.1.2
9 months ago
1.1.1
9 months ago
1.1.0
9 months ago
1.0.2
10 months ago
1.0.1
10 months ago