assistant-robot 0.0.2-epsilon → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,18 +5,35 @@ import { EUserDetectorStatus } from "./constants";
5
5
  import { EventListener } from "./utils";
6
6
  import type { LanguageModel } from "./LanguageModel";
7
7
  import type { IAssistantRobotConfig, IActionConfig } from "./type";
8
+ /**
9
+ * the main class of the assistant robot.
10
+ * After the class is instantiated, a fill funtion assistant robot will be show on the page.
11
+ */
8
12
  export declare class Assistant<T extends LanguageModel> extends EventListener {
9
13
  assistantModel: AssistantModel;
10
14
  userDetector: UserDetector;
11
- questionManager: OperationManager | undefined;
15
+ operationManager: OperationManager | undefined;
12
16
  languageModel: T;
13
17
  options: IAssistantRobotConfig<T>;
14
18
  constructor(el: Element, options: IAssistantRobotConfig<T>);
15
19
  handleLanguageModelLoad: () => void;
16
20
  handleUserDetectorStatusChange: (status: EUserDetectorStatus) => void;
17
21
  onMenuClick: (key: string) => void;
22
+ /**
23
+ * ask the assistant robot a question
24
+ * @param question question go ask
25
+ */
18
26
  ask: (question: string) => Promise<void>;
27
+ /**
28
+ * make the robot say something
29
+ * @param text what the robot should say
30
+ */
19
31
  assistantSay(text: string): void;
32
+ /**
33
+ * make the robot play a action
34
+ * @param name name of the action
35
+ * @param config config of the action
36
+ */
20
37
  assistantPlay(name: string, config?: IActionConfig): void;
21
38
  lookAtUser(): Promise<void>;
22
39
  }
@@ -1,5 +1,10 @@
1
1
  import { PerspectiveCamera, Scene, WebGL1Renderer, Object3D, AnimationMixer, AnimationClip, AnimationAction, Clock } from "three";
2
2
  import type { TRobotModelConfig, IModelConfig, IActionConfig } from "./type";
3
+ /**
4
+ * assistant robot's 3d model manager.
5
+ * include the inition of the scene and the 3d model.
6
+ * include the methods to make the 3d model play an action or speek something
7
+ */
3
8
  export declare class AssistantModel {
4
9
  clock: Clock;
5
10
  container: Element;
@@ -14,14 +19,41 @@ export declare class AssistantModel {
14
19
  options: TRobotModelConfig;
15
20
  idleAction: AnimationAction | undefined;
16
21
  constructor(container: Element, options: TRobotModelConfig);
22
+ /**
23
+ * init the 3d scene an 3d model for the robot
24
+ * @param options configs
25
+ */
17
26
  init(options?: TRobotModelConfig): void;
27
+ /**
28
+ * to load the 3d model
29
+ * @param modelUrl the url to load 3d model, default to use MR Potato
30
+ * @param param1 the config for the 3d model
31
+ */
18
32
  loadModel(modelUrl: string, { position, rotation }?: Partial<IModelConfig>): void;
19
33
  startIdleAction(): void;
20
- haltIdleAction(durationInSeconds: number): void;
34
+ /**
35
+ * halt idle action
36
+ * @param duration how long time to halt
37
+ */
38
+ haltIdleAction(duration: number): void;
21
39
  hello(): void;
40
+ /**
41
+ * make the robot play a action
42
+ * @param name name of the action
43
+ * @param config config of the action
44
+ */
22
45
  play(name: string, { loop, weight, timeScale, repetitions, }?: IActionConfig): void;
23
46
  hideTip(): void;
47
+ /**
48
+ * make the robot say something
49
+ * @param text what the robot should say
50
+ */
24
51
  say(text: string): void;
25
52
  animate(): void;
53
+ /**
54
+ * make the robot rotate
55
+ * @param x the rotate angle on x axis
56
+ * @param y the rotate angle on y axis
57
+ */
26
58
  rotate(x?: number, y?: number): void;
27
59
  }
@@ -4,6 +4,10 @@ import "@tensorflow/tfjs-backend-cpu";
4
4
  import "@tensorflow/tfjs-backend-webgl";
5
5
  import { ELanguageModelStatus } from "./constants";
6
6
  import type { TCallback, ILanguageModelOptions } from "./type";
7
+ /**
8
+ * the abstract class to use a language model.
9
+ * The language model manager should to extend this class to used in the assistant.
10
+ */
7
11
  export declare abstract class LanguageModel {
8
12
  status: ELanguageModelStatus;
9
13
  onLoadList: TCallback[];
@@ -13,11 +17,21 @@ export declare abstract class LanguageModel {
13
17
  abstract findAnswers(question: string): Promise<string>;
14
18
  constructor();
15
19
  }
20
+ /**
21
+ * The default language model implementation to used in assistant robot.
22
+ * It used mobile bert(https://openreview.net/forum?id=SJxjVaNKwB).
23
+ * It is faster and smaller, but it's not very good.
24
+ */
16
25
  export declare class MobileBertModel extends LanguageModel {
17
26
  passage: string;
18
27
  modelUrl: string;
19
28
  model: QuestionAndAnswer | undefined;
20
29
  constructor({ passage, modelUrl }: ILanguageModelOptions);
21
30
  init(): Promise<void>;
31
+ /**
32
+ * ask model question
33
+ * @param question question to ask
34
+ * @returns answer of the question
35
+ */
22
36
  findAnswers(question: string): Promise<string>;
23
37
  }
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var d=(s,t,e)=>t in s?l(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>(d(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@tensorflow-models/qna");require("@tensorflow/tfjs-core");require("@tensorflow/tfjs-backend-cpu");require("@tensorflow/tfjs-backend-webgl");const r=require("./utils-ybKQi2Om.js");function c(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const g=c(u);class i{constructor(){a(this,"status",r.ELanguageModelStatus.loading);a(this,"onLoadList",[])}loaded(){this.status=r.ELanguageModelStatus.ready,this.onLoadList.forEach(t=>t())}onLoad(t){this.onLoadList.push(t)}removeLoadCb(t){this.onLoadList=this.onLoadList.filter(e=>e!=t)}}class h extends i{constructor({passage:e,modelUrl:o}){super();a(this,"passage");a(this,"modelUrl");a(this,"model");this.passage=e,this.modelUrl=o,this.init()}async init(){this.status=r.ELanguageModelStatus.loading;try{const e=this.modelUrl?{modelUrl:this.modelUrl}:void 0;this.model=await g.load(e),this.loaded()}catch(e){console.warn(e),this.status=r.ELanguageModelStatus.error}}async findAnswers(e){if(this.model){const o=await this.model.findAnswers(e,this.passage),n=r.findHighestScoreItem(o);return n?n.text:""}return""}}exports.LanguageModel=i;exports.MobileBertModel=h;
1
+ "use strict";var l=Object.defineProperty;var d=(s,t,e)=>t in s?l(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>(d(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@tensorflow-models/qna");require("@tensorflow/tfjs-core");require("@tensorflow/tfjs-backend-cpu");require("@tensorflow/tfjs-backend-webgl");const r=require("./utils-_ulwJfGD.js");function c(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const g=c(u);class i{constructor(){a(this,"status",r.ELanguageModelStatus.loading);a(this,"onLoadList",[])}loaded(){this.status=r.ELanguageModelStatus.ready,this.onLoadList.forEach(t=>t())}onLoad(t){this.onLoadList.push(t)}removeLoadCb(t){this.onLoadList=this.onLoadList.filter(e=>e!=t)}}class h extends i{constructor({passage:e,modelUrl:o}){super();a(this,"passage");a(this,"modelUrl");a(this,"model");this.passage=e,this.modelUrl=o,this.init()}async init(){this.status=r.ELanguageModelStatus.loading;try{const e=this.modelUrl?{modelUrl:this.modelUrl}:void 0;this.model=await g.load(e),this.loaded()}catch(e){console.warn(e),this.status=r.ELanguageModelStatus.error}}async findAnswers(e){if(this.model){const o=await this.model.findAnswers(e,this.passage),n=r.findHighestScoreItem(o);return n?n.text:""}return""}}exports.LanguageModel=i;exports.MobileBertModel=h;
@@ -5,7 +5,7 @@ import * as l from "@tensorflow-models/qna";
5
5
  import "@tensorflow/tfjs-core";
6
6
  import "@tensorflow/tfjs-backend-cpu";
7
7
  import "@tensorflow/tfjs-backend-webgl";
8
- import { o as i, q as h } from "./utils-u6rFqFWg.mjs";
8
+ import { o as i, q as h } from "./utils-FAxjgnse.mjs";
9
9
  class m {
10
10
  constructor() {
11
11
  a(this, "status", i.loading);
@@ -24,11 +24,15 @@ class m {
24
24
  class f extends m {
25
25
  constructor({ passage: s, modelUrl: e }) {
26
26
  super();
27
+ // The content to extract answers from.
27
28
  a(this, "passage");
29
+ // specifies custom url of the model. This is useful for area/countries that don't have access to the model hosted on GCP.
28
30
  a(this, "modelUrl");
31
+ // the real language model
29
32
  a(this, "model");
30
33
  this.passage = s, this.modelUrl = e, this.init();
31
34
  }
35
+ // to load real language model
32
36
  async init() {
33
37
  this.status = i.loading;
34
38
  try {
@@ -38,6 +42,11 @@ class f extends m {
38
42
  console.warn(s), this.status = i.error;
39
43
  }
40
44
  }
45
+ /**
46
+ * ask model question
47
+ * @param question question to ask
48
+ * @returns answer of the question
49
+ */
41
50
  async findAnswers(s) {
42
51
  if (this.model) {
43
52
  const e = await this.model.findAnswers(s, this.passage), r = h(e);
@@ -1,4 +1,9 @@
1
- import { IOperationBoxBoxConfig } from "./type";
1
+ import { IOperationBoxConfig } from "./type";
2
+ /**
3
+ * the manager to manage the operation of assistant robot.
4
+ * include the operation box's render.
5
+ * include the operation's implementation.
6
+ */
2
7
  export declare class OperationManager {
3
8
  btnDom: HTMLButtonElement | undefined;
4
9
  inputDom: HTMLInputElement | undefined;
@@ -6,7 +11,7 @@ export declare class OperationManager {
6
11
  menuDom: HTMLElement | undefined;
7
12
  onAsk: (question: string) => void;
8
13
  onMenuClick: (key: string) => void;
9
- constructor(container: Element, onAsk: (question: string) => void, onMenuClick: (key: string) => void, options?: IOperationBoxBoxConfig);
10
- initChatBox(container: Element, options?: IOperationBoxBoxConfig): void;
14
+ constructor(container: Element, onAsk: (question: string) => void, onMenuClick: (key: string) => void, options?: IOperationBoxConfig);
15
+ initOperationBox(container: Element, options?: IOperationBoxConfig): void;
11
16
  addEventListener(): void;
12
17
  }
@@ -3,6 +3,9 @@ import type { FaceDetector } from "@tensorflow-models/face-detection";
3
3
  import { EUserDetectorStatus } from "./constants";
4
4
  import { EventListener } from "./utils";
5
5
  import { IUserDetectorConfig } from "./type";
6
+ /**
7
+ * user detect module.open the camera to detect the user's face.
8
+ */
6
9
  export declare class UserDetector extends EventListener {
7
10
  video: HTMLVideoElement;
8
11
  detector: FaceDetector | undefined;
@@ -11,6 +14,7 @@ export declare class UserDetector extends EventListener {
11
14
  options: IUserDetectorConfig;
12
15
  status: EUserDetectorStatus;
13
16
  constructor(options?: IUserDetectorConfig);
17
+ init(): void;
14
18
  initVideo(): Promise<void>;
15
19
  createDetector(): Promise<void>;
16
20
  getFaces(): Promise<faceDetection.Face[]>;
@@ -26,11 +26,11 @@ export declare enum EMenuKey {
26
26
  }
27
27
  export declare const ROBOT_OPERATION_INPUT_CLASS = "assistant-robot-input";
28
28
  export declare const ROBOT_OPERATION_BTN_CLASS = "assistant-robot-btn";
29
- export declare const OPERATION_CONTAINER_CLASS = "assistant-robot-operation_container";
30
- export declare const MENU_BTN_CLASS = "assistant-robot-menu_btn";
31
- export declare const MENU_LIST_CLASS = "assistant-robot-menu_list";
32
- export declare const ROBOT_OPERATION_BOX_HEAD = "<div class=\"assistant-robot-chartbox";
33
- export declare const ROBOT_OPERATION_BOX_BODY = "\">\n<style>\n .assistant-robot-chartbox{\n box-sizing: content-box;\n width: 100%;\n height: 32px;\n display: flex;\n flex: 0 0 auto;\n flex-wrap: wrap;\n align-items: center;\n border-radius: 54px;\n box-shadow: 0 1px 2px -2px rgba(0, 0, 0, 0.16),\n 0 3px 6px 0 rgba(0, 0, 0, 0.12),\n 0 5px 12px 4px rgba(0, 0, 0, 0.09);\n background-color: #fff;\n padding: 10px 12px;\n }\n .assistant-robot-input{\n flex: 1;\n min-width: 200px;\n background: rgba(0,0,0,0);\n border: 1px solid #dedede;\n height: 28px;\n margin-right: 6px;\n outline:none;\n color: #666666;\n }\n .assistant-robot-btn{\n flex: 0 0 auto;\n height: 24px;\n }\n\n .assistant-robot-operation_container{\n position: relative;\n height: 24px;\n }\n .assistant-robot-menu_btn{\n color: #dedede;\n width:24px;\n height: 24px;\n cursor: pointer;\n }\n\n .assistant-robot-menu_list {\n display: none;\n position: absolute;\n top: 30px;\n left: 0px;\n background-color: #fff;\n border: 1px solid #ccc;\n box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);\n padding: 10px;\n border-radius: 5px;\n animation: fadeInOut 0.4s ease-in-out;\n list-style: none;\n }\n\n .assistant-robot-menu_list li{\n line-height: 32px;\n text-wrap: nowrap;\n border-bottom: 1px solid #dedede;\n cursor: pointer;\n }\n\n .assistant-robot-menu_list li:last-child{\n border-bottom: none;\n }\n\n @keyframes fadeInOut {\n 0% { opacity: 0; }\n 100% { opacity: 1; }\n }\n</style>\n<span class=\"assistant-robot-operation_container\">\n <svg\n t=\"1702017878997\"\n class=\"assistant-robot-menu_btn\"\n viewBox=\"0 0 1024 1024\"\n version=\"1.1\"\n p-id=\"1322\"\n width=\"32\"\n height=\"32\"\n >\n <path\n d=\"M512 512m-116.949333 0a116.949333 116.949333 0 1 0 233.898666 0 116.949333 116.949333 0 1 0-233.898666 0Z\"\n fill=\"currentColor\"\n p-id=\"1323\"\n ></path>\n <path\n d=\"M512 159.616m-116.949333 0a116.949333 116.949333 0 1 0 233.898666 0 116.949333 116.949333 0 1 0-233.898666 0Z\"\n fill=\"currentColor\"\n p-id=\"1324\"\n ></path>\n <path\n d=\"M512 864.384m-116.949333 0a116.949333 116.949333 0 1 0 233.898666 0 116.949333 116.949333 0 1 0-233.898666 0Z\"\n fill=\"currentColor\"\n p-id=\"1325\"\n ></path>\n </svg>\n <ul class=\"assistant-robot-menu_list\">\n <li data-id=\"openCamera\">Open the Camera</li>\n";
29
+ export declare const OPERATION_CONTAINER_CLASS = "assistant-robot-operation-container";
30
+ export declare const MENU_BTN_CLASS = "assistant-robot-menu-btn";
31
+ export declare const MENU_LIST_CLASS = "assistant-robot-menu-list";
32
+ export declare const ROBOT_OPERATION_BOX_HEAD = "<div class=\"assistant-robot-operationbox";
33
+ export declare const ROBOT_OPERATION_BOX_BODY = "\">\n<style>\n .assistant-robot-operationbox{\n box-sizing: border-box;\n width: 100%;\n height: 52px;\n display: flex;\n flex: 0 0 auto;\n flex-wrap: wrap;\n align-items: center;\n border-radius: 54px;\n box-shadow: 0 1px 2px -2px rgba(0, 0, 0, 0.16),\n 0 3px 6px 0 rgba(0, 0, 0, 0.12),\n 0 5px 12px 4px rgba(0, 0, 0, 0.09);\n background-color: #fff;\n padding: 10px 12px;\n }\n .assistant-robot-input{\n flex: 1;\n min-width: 200px;\n background: rgba(0,0,0,0);\n border: 1px solid #dedede;\n height: 28px;\n margin-right: 6px;\n outline:none;\n color: #666666;\n }\n .assistant-robot-btn{\n flex: 0 0 auto;\n height: 24px;\n }\n\n .assistant-robot-operation-container{\n position: relative;\n height: 24px;\n }\n .assistant-robot-menu-btn{\n color: #aaaaaa;\n width:24px;\n height: 24px;\n cursor: pointer;\n }\n\n .assistant-robot-menu-list {\n display: none;\n position: absolute;\n top: 30px;\n left: 0px;\n background-color: #fff;\n border: 1px solid #ccc;\n box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);\n padding: 10px;\n border-radius: 5px;\n animation: fadeInOut 0.4s ease-in-out;\n list-style: none;\n }\n\n .assistant-robot-menu-list li{\n line-height: 32px;\n text-wrap: nowrap;\n border-bottom: 1px solid #dedede;\n cursor: pointer;\n }\n\n .assistant-robot-menu-list li:last-child{\n border-bottom: none;\n }\n\n @keyframes fadeInOut {\n 0% { opacity: 0; }\n 100% { opacity: 1; }\n }\n</style>\n<span class=\"assistant-robot-operation-container\">\n <svg\n t=\"1702017878997\"\n class=\"assistant-robot-menu-btn\"\n viewBox=\"0 0 1024 1024\"\n version=\"1.1\"\n p-id=\"1322\"\n width=\"32\"\n height=\"32\"\n >\n <path\n d=\"M512 512m-116.949333 0a116.949333 116.949333 0 1 0 233.898666 0 116.949333 116.949333 0 1 0-233.898666 0Z\"\n fill=\"currentColor\"\n p-id=\"1323\"\n ></path>\n <path\n d=\"M512 159.616m-116.949333 0a116.949333 116.949333 0 1 0 233.898666 0 116.949333 116.949333 0 1 0-233.898666 0Z\"\n fill=\"currentColor\"\n p-id=\"1324\"\n ></path>\n <path\n d=\"M512 864.384m-116.949333 0a116.949333 116.949333 0 1 0 233.898666 0 116.949333 116.949333 0 1 0-233.898666 0Z\"\n fill=\"currentColor\"\n p-id=\"1325\"\n ></path>\n </svg>\n <ul class=\"assistant-robot-menu-list\">\n <li data-id=\"openCamera\">eye contact</li>\n";
34
34
  export declare const ROBOT_OPERATION_BOX_TAIL = "</ul>\n</span>\n<input class=\"assistant-robot-input\" type=\"text\" />\n<button class=\"assistant-robot-btn\">ask</button>\n</div>";
35
35
  export declare enum ELanguageModelStatus {
36
36
  loading = 1,