(name: string, serviceName: string, credential: APICredential, viewClass: BaseViewType, options?: Partial<WebServiceOptions>)
| 93 | } |
| 94 | |
| 95 | createAssistant(name: string, serviceName: string, credential: APICredential, viewClass: BaseViewType, options?: Partial<WebServiceOptions>) { |
| 96 | const service = serviceManager.createService(name, serviceName, credential, options); |
| 97 | // Do runtime check of API type compatibility. |
| 98 | const {viewClasses} = serviceManager.getServiceByName(serviceName); |
| 99 | if (!viewClasses.find(V => matchClass(V, viewClass))) |
| 100 | throw new Error(`Service "${service.constructor.name}" does not support View type "${viewClass.name}".`); |
| 101 | // Create a new assistant of service. |
| 102 | const ids = this.#assistants.map(assistant => assistant.id); |
| 103 | const id = getNextId(service.name, ids); |
| 104 | const assistant = new Assistant(id, service, viewClass); |
| 105 | this.#assistants.push(assistant); |
| 106 | this.onNewAssistant.emit(assistant, ids.length); |
| 107 | this.saveConfig(); |
| 108 | return assistant; |
| 109 | } |
| 110 | |
| 111 | removeAssistantById(id: string) { |
| 112 | const index = this.#assistants.findIndex(assistant => assistant.id == id); |
no test coverage detected