1.1.39 • Published 5 months ago

@alicloud-panxi/aicoach-sdk v1.1.39

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

磐曦 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-
apiPathOptionsapiPath 接口请求的配置(如 timeout,headers,method,withCredentials 等)Record<string, any>-
type渲染类型,枚举值:practice-对练,report-报告stringpractice
interact互动形式,枚举值:chat-1:消息对练(含语音),text-2:消息对练(纯文本),call-3:电话对练,video-4:视频对练(数字人),gif-5:视频对练(动图)stringchat
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,vuestringreact
customOptionsUI 自定义参数,定义见下CustomOptions-
cssTokencss自定义主题cssToken-

2.4. 方法说明

方法名描述类型是否有返回返回值
getSessionId获取对练任务sessionIdfunctionsessionId: string
closeTask关闭对练任务functionres: Promise
finishTask完成对练任务functionres: Promise
stop销毁当前实例function-

2.5. UI 自定义参数类型 CustomOptions

⚠️ boolean 类型的数据默认值都为 false

  • global:全局对象
参数名描述类型上下文
backgroundImage背景图片string-
backgroundColor背景颜色string-
  • headerPanel:头部面板
参数名描述类型扩展字段上下文
isHideTitle是否隐藏标题boolean--
isHideFinishButton是否隐藏完成测试按钮boolean--
isHideCountDown是否隐藏倒计时boolean--
textReplace文案替换objecttipsremainingTimeText'剩余对练时长'-
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 剧本信息 npm.io
方法 startRecord() 开始录音 handleCancel() 取消录音 handleSend(type, content?) 发送消息,type='text'为发送文本消息,type='voice'为发送音频,只有发送文本消息时需要传 content handleVolume() 智能体声音播放控制(默认播放智能体声音)handleClickRealtimeWords() 点击生成话术提示字聊天)
  • confirmPanel:确认面板(弹窗面板)
参数名描述类型扩展字段上下文
CustomStart自定义开始面板HTMLElement-字段: title 标题 content 内容
方法: onConfirm 开始 onCancel 退出
customStartOptions开始面板文案替换objecttextReplaceconfirmText'开始'-
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文案替换objecttitle // 标题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 都存在才会生效objecttext 按钮文案-
action 方法-
textReplace文案替换objectpracticeTimeText'练习时长'-
gotoHistoryButtonText'查看对练内容'-
CustomReport自定义报告页面HTMLElement-字段: reportData 完整报告数据
方法: gotoSessionHistory() 打开会话历史视图 closeInstance() 关闭 sdk 实例
OverallRatingTab综合得分tabobjectisHideCoachComments: boolean;// 是否隐藏教练评语-
isHideFeedBack : boolean; // 隐藏评价
CheckPointTab考核重点tabobjectisHideCoachComments: boolean;// 是否隐藏教练评语-
isHideFeedBack : boolean; // 是否隐藏评价
isHidePromotionProposal: boolean; // 是否隐藏提升建议
isHideScoringPoint: boolean; // 是否隐藏得分点
QuestionScoreTab问题得分tabobjectisHideCoachComments: boolean;// 是否隐藏教练评语-
isHideFeedBack : boolean; // 是否隐藏评价
isHidePromotionProposal: boolean; // 是否隐藏提升建议
isHideScoringPoint: boolean; // 是否隐藏得分点
ExpressiveAbilityTab表达能力tabobjectisHideCoachComments: 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