augnitoambientsdk
Advanced tools
Comparing version 1.0.1 to 1.1.1
{ | ||
"name": "augnitoambientsdk", | ||
"version": "1.0.1", | ||
"version": "1.1.1", | ||
"description": "Use this typescript SDK to integrate Augnito’s Ambient Tech within your EMR. To get access credentials or know more about how Augnito Ambient can benefit you, please visit our website and connect with our sales team: https://augnito.ai/", | ||
"main": "dist/index.js", | ||
"main": "dist/augnitoambientsdk.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "tsc" | ||
"build": "rollup -c" | ||
}, | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"Clinical Documentation", | ||
"Augnito", | ||
"Augnito", | ||
"Voice AI", | ||
@@ -22,4 +22,14 @@ "Ambient Intelligence" | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
"@babel/core": "^7.24.0", | ||
"@babel/preset-env": "^7.24.0", | ||
"typescript": "^5.3.3", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0" | ||
}, | ||
"dependencies": { | ||
"augnitorecorder": "^1.0.12", | ||
"rollup-plugin-typescript2": "^0.36.0" | ||
} | ||
} |
@@ -16,4 +16,3 @@ # Augnito Ambient SDK | ||
```js | ||
import AmbientConfig from 'augnitoambientsdk/src/config/AmbientConfig'; | ||
import {AugnitoAmbient} from 'augnitoambientsdk/src/AugnitoAmbient'; | ||
import {AugnitoAmbient,AmbientConfig} from 'augnitoambientsdk'; | ||
``` | ||
@@ -49,3 +48,4 @@ | ||
// Toggles the recodring | ||
augnitoAmbient.toggleListening(filetype:string, noteparams:JSON); | ||
augnitoAmbient.toggleListening(filetype:string, noteparams:string); | ||
example: augnitoAmbient.toggleListening("wav","noteparams={'Region': 801, 'Specialty': 200, 'NoteType': 40, 'Gender': 0}") | ||
@@ -52,0 +52,0 @@ //#region Callbacks |
@@ -1,7 +0,8 @@ | ||
import AmbientConfig from "./config/AmbientConfig"; | ||
import AmbientConfig from "./config/AmbientConfig"; | ||
import { socketConfig } from "./config/socketConfig"; | ||
import { AmbientRestAPI } from "./api/AmbientRestAPI"; | ||
import { websocketHandler } from "./handlers/websocketHandler"; | ||
import { Logger } from "./utils/Logger"; | ||
import { Guard } from "./utils/Guard"; | ||
import { AugnitoRecorder } from "augnitorecorder"; | ||
import { AugnitoSocketResponse } from "./support/AugnitoSocketResponse"; | ||
@@ -12,16 +13,15 @@ /** | ||
*/ | ||
export class AugnitoAmbient{ | ||
private _logTag = 'Augnito-Ambient'; | ||
export class AugnitoAmbient { | ||
private _logTag = "Augnito-Ambient"; | ||
private _ambientRestAPI: AmbientRestAPI; | ||
private _wsHandler: websocketHandler; | ||
constructor(config: AmbientConfig){ | ||
private config: socketConfig | null | undefined; | ||
private recorderIns: AugnitoRecorder | undefined; | ||
constructor(config: AmbientConfig) { | ||
this._ambientRestAPI = new AmbientRestAPI(this.validateConfig(config)); | ||
this._wsHandler = new websocketHandler( | ||
this.createSocketConfig(this.validateConfig(config)) | ||
); | ||
this.config = this.createSocketConfig(this.validateConfig(config)); | ||
} | ||
/** | ||
* @description Callback to receive the JOb Id | ||
*/ | ||
* @description Callback to receive the JOb Id | ||
*/ | ||
public onJobCreated?: (text: string) => void; | ||
@@ -34,9 +34,30 @@ | ||
/** | ||
/** | ||
* Callback triggered when an error occurs within the SDK | ||
*/ | ||
public onError?: (errorMessage: string) => void; | ||
public onOtherResult?: (text: string) => void; | ||
public onIdleMic?: () => void; | ||
private initRecorder(_filetype: string, _noteparams: string) { | ||
console.log(_filetype, _noteparams); | ||
this.recorderIns = new AugnitoRecorder({ | ||
// "{\"Region\": 801, \"Specialty\": 200, \"NoteType\": 40, \"Gender\": 0}" | ||
serverURL: this.config?.prepareWSSURL(_filetype, _noteparams) || "", | ||
enableLogs: true, | ||
isDebug: false, | ||
bufferInterval: 30, | ||
EOS_Message: | ||
'{\\"JobAction\\":\\"EOS\\",\\"Status\\":0,\\"Type\\":\\"meta\\"}', | ||
socketTimeoutInterval: 10000, | ||
}); | ||
this.recorderIns.onError = this.onErrorCallback.bind(this); | ||
this.recorderIns.onStateChanged = this.onStateChangeCallback.bind(this); | ||
this.recorderIns.onSessionEvent = | ||
this.onSessionEventCallback.bind(this); | ||
this.recorderIns.onOtherResults = | ||
this.onOtherResultsCallback.bind(this); | ||
} | ||
// #region Public Methods | ||
/** | ||
@@ -46,12 +67,11 @@ * Returns the Note parameters which need be use while doing toggle listeing | ||
*/ | ||
public async getNoteParams():Promise<any>{ | ||
try{ | ||
public async getNoteParams(): Promise<any> { | ||
try { | ||
if (!this._ambientRestAPI) { | ||
Logger.error('SDK not initialized', this._logTag); | ||
Logger.error("SDK not initialized", this._logTag); | ||
return; | ||
} | ||
return await this._ambientRestAPI.GetNoteParams(); | ||
} | ||
catch(e:any){ | ||
if(e instanceof Error){ | ||
} | ||
return await this._ambientRestAPI.GetNoteParams(); | ||
} catch (e: any) { | ||
if (e instanceof Error) { | ||
this.onErrorCallback(e.message); | ||
@@ -64,27 +84,22 @@ } | ||
* @param JobId to retrieve output for a specific audio file | ||
* @returns JSON object contains both Transcript and Note on sucess else fail resonse | ||
* @returns JSON object contains both Transcript and Note on sucess else fail resonse | ||
*/ | ||
public async getSummarizedNote(JobId:string):Promise<any>{ | ||
try{ | ||
public async getSummarizedNote(JobId: string): Promise<any> { | ||
try { | ||
if (!this._ambientRestAPI) { | ||
Logger.error('SDK not initialized', this._logTag); | ||
Logger.error("SDK not initialized", this._logTag); | ||
return; | ||
} | ||
var responseJson = await this._ambientRestAPI.FetchJob(JobId); | ||
if(responseJson) | ||
{ | ||
if(responseJson.Status === 200){ | ||
if (responseJson) { | ||
if (responseJson.Status === 200) { | ||
return responseJson; | ||
} | ||
else{ | ||
} else { | ||
this.onErrorCallback(responseJson.ErrorMessage); | ||
} | ||
} | ||
else | ||
{ | ||
} else { | ||
this.onErrorCallback("Unknown Error!"); | ||
} | ||
} | ||
catch(e:any){ | ||
if(e instanceof Error){ | ||
} catch (e: any) { | ||
if (e instanceof Error) { | ||
this.onErrorCallback(e.message); | ||
@@ -100,12 +115,14 @@ } | ||
*/ | ||
public async sendSummarizedNote(JobId:string, NoteDate:string):Promise<any>{ | ||
try{ | ||
public async sendSummarizedNote( | ||
JobId: string, | ||
NoteDate: string | ||
): Promise<any> { | ||
try { | ||
if (!this._ambientRestAPI) { | ||
Logger.error('SDK not initialized', this._logTag); | ||
Logger.error("SDK not initialized", this._logTag); | ||
return; | ||
} | ||
return await this._ambientRestAPI.SendFinalNote(JobId,NoteDate); | ||
} | ||
catch(e:any){ | ||
if(e instanceof Error){ | ||
return await this._ambientRestAPI.SendFinalNote(JobId, NoteDate); | ||
} catch (e: any) { | ||
if (e instanceof Error) { | ||
this.onErrorCallback(e.message); | ||
@@ -121,11 +138,9 @@ } | ||
*/ | ||
public toggleListening(filetype:string, noteparams:any): void { | ||
if (!this._wsHandler) { | ||
Logger.error('SDK not initialized', this._logTag); | ||
return; | ||
public toggleListening(_filetype: string, _noteparams: string): void { | ||
console.log("toggleListening:", _filetype, _noteparams); | ||
if (!this.recorderIns) { | ||
this.initRecorder(_filetype, _noteparams); | ||
} | ||
Guard.Against.NullOrEmpty(filetype, 'FileType'); | ||
Guard.Against.NullOrEmpty(noteparams, 'Note Params'); | ||
this._wsHandler.toggleListening(filetype,noteparams); | ||
} | ||
this.recorderIns?.toggleStartStopAudioStream(); | ||
} | ||
@@ -136,20 +151,87 @@ // #endregion | ||
private onEventCallback(data:string):void{ | ||
private onEventCallback(data: string): void { | ||
if (this.onJobCreated) { | ||
this.onJobCreated(data); | ||
} | ||
} | ||
} | ||
private onStateChangeCallback(isRecording:boolean):void{ | ||
private onStateChangeCallback(isRecording: boolean): void { | ||
if (this.onStateChanged) { | ||
this.onStateChanged(isRecording); | ||
} | ||
} | ||
} | ||
private onErrorCallback(errorMessage:string):void{ | ||
private onErrorCallback(errorMessage: string): void { | ||
if (this.onError) { | ||
this.onError(errorMessage); | ||
} | ||
} | ||
} | ||
private onOtherResultsCallback(data: string): void { | ||
if (this.onOtherResult) { | ||
this.onOtherResult(data); | ||
} | ||
} | ||
private onIdleMicCallback(): void { | ||
if (this.onIdleMic) { | ||
this.onIdleMic(); | ||
} | ||
} | ||
private onSessionEventCallback(data: string | AugnitoSocketResponse): void { | ||
if (!data) { | ||
return; | ||
} | ||
let json: any; | ||
try { | ||
json = typeof data === "string" ? JSON.parse(data) : data; | ||
} catch (error) { | ||
Logger.error( | ||
`Error parsing session event data: ${error}`, | ||
this._logTag | ||
); | ||
return; | ||
} | ||
if (!json || !("Type" in json)) { | ||
return; | ||
} | ||
if (json.Type.toLowerCase() === "meta" && this.config?.onMetaEvent) { | ||
if (!json.JobID) { | ||
Logger.error(`JobID is missing in meta event`, this._logTag); | ||
return; | ||
} | ||
this.config.onMetaEvent(json.JobID); | ||
} else if (json.Type.toLowerCase() === "error" && json.Data) { | ||
this.onErrorCallback(json.Data); | ||
} | ||
if (typeof json.Event !== "object" || json.Event === null) { | ||
return; | ||
} | ||
const { Type: eventType, Value: eventValue } = json.Event; | ||
if (!eventType) { | ||
return; | ||
} | ||
if (eventType === "SESSION_CREATED" && eventValue) { | ||
Logger.log(`session Token ${eventValue}`, this._logTag); | ||
} else if (eventType === "SERVICE_DOWN") { | ||
Logger.error(eventType, this._logTag); | ||
} else if (eventType === "NO_DICTATION_STOP_MIC") { | ||
Logger.log("NO_DICTATION_STOP_MIC", this._logTag); | ||
this.onIdleMicCallback(); | ||
} else if (eventType === "INVALID_AUTH_CREDENTIALS") { | ||
Logger.error("INVALID_AUTH_CREDENTIALS", this._logTag); | ||
} else if (eventType === "LOW_BANDWIDTH") { | ||
Logger.log( | ||
"LOW_BANDWIDTH: Check internet connection", | ||
this._logTag | ||
); | ||
} | ||
} | ||
// #endregion | ||
@@ -162,13 +244,14 @@ | ||
validateConfig(config: AmbientConfig): AmbientConfig { | ||
Guard.Against.NullOrEmpty(config.server, 'Server'); | ||
Guard.Against.NullOrEmpty(config.subscriptionCode, 'SubscriptionCode'); | ||
Guard.Against.NullOrEmpty(config.accessKey, 'AccessKey'); | ||
Guard.Against.NullOrEmpty(config.userTag, 'UserTag'); | ||
Guard.Against.NullOrEmpty(config.server, "Server"); | ||
Guard.Against.NullOrEmpty(config.subscriptionCode, "SubscriptionCode"); | ||
Guard.Against.NullOrEmpty(config.accessKey, "AccessKey"); | ||
Guard.Against.NullOrEmpty(config.userTag, "UserTag"); | ||
return config; | ||
}; | ||
} | ||
private createSocketConfig(config: AmbientConfig): socketConfig { | ||
const _socketConfig = new socketConfig(config); | ||
_socketConfig.onStartOfRecording = this.onStateChangeCallback.bind(this); | ||
_socketConfig.onStopOfRecording = this.onStateChangeCallback.bind(this); | ||
// _socketConfig.onStartOfRecording = | ||
// this.onStateChangeCallback.bind(this); | ||
// _socketConfig.onStopOfRecording = this.onStateChangeCallback.bind(this); | ||
_socketConfig.onError = this.onErrorCallback.bind(this); | ||
@@ -178,2 +261,2 @@ _socketConfig.onMetaEvent = this.onEventCallback.bind(this); | ||
} | ||
} | ||
} |
@@ -5,4 +5,4 @@ import AmbientConfig from "./AmbientConfig"; | ||
onStartOfRecording?: (isRecording: boolean) => void; | ||
onStopOfRecording?: (isRecording: boolean) => void; | ||
// onStartOfRecording?: (isRecording: boolean) => void; | ||
// onStopOfRecording?: (isRecording: boolean) => void; | ||
onError?: (errorMessage: string) => void; | ||
@@ -12,3 +12,3 @@ onMetaEvent?:(jobId: string) => void; | ||
constructor(private _config:AmbientConfig){ | ||
this.wssBaseURL = `wss://${_config.server}/ambient/process-job`; | ||
this.wssBaseURL = `wss://${_config.server}/ambient/stream-job`; | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -28,5 +28,5 @@ { | ||
/* Modules */ | ||
"module": "commonjs", /* Specify what module code is generated. */ | ||
"module": "ESNext", /* Specify what module code is generated. */ | ||
// "rootDir": "./", /* Specify the root folder within your source files. */ | ||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ | ||
@@ -33,0 +33,0 @@ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
208083
2113
2
7
15
3
+ Addedaugnitorecorder@^1.0.12
+ Added@rollup/pluginutils@4.2.1(transitive)
+ Added@rollup/rollup-android-arm-eabi@4.29.1(transitive)
+ Added@rollup/rollup-android-arm64@4.29.1(transitive)
+ Added@rollup/rollup-darwin-arm64@4.29.1(transitive)
+ Added@rollup/rollup-darwin-x64@4.29.1(transitive)
+ Added@rollup/rollup-freebsd-arm64@4.29.1(transitive)
+ Added@rollup/rollup-freebsd-x64@4.29.1(transitive)
+ Added@rollup/rollup-linux-arm-gnueabihf@4.29.1(transitive)
+ Added@rollup/rollup-linux-arm-musleabihf@4.29.1(transitive)
+ Added@rollup/rollup-linux-arm64-gnu@4.29.1(transitive)
+ Added@rollup/rollup-linux-arm64-musl@4.29.1(transitive)
+ Added@rollup/rollup-linux-loongarch64-gnu@4.29.1(transitive)
+ Added@rollup/rollup-linux-powerpc64le-gnu@4.29.1(transitive)
+ Added@rollup/rollup-linux-riscv64-gnu@4.29.1(transitive)
+ Added@rollup/rollup-linux-s390x-gnu@4.29.1(transitive)
+ Added@rollup/rollup-linux-x64-gnu@4.29.1(transitive)
+ Added@rollup/rollup-linux-x64-musl@4.29.1(transitive)
+ Added@rollup/rollup-win32-arm64-msvc@4.29.1(transitive)
+ Added@rollup/rollup-win32-ia32-msvc@4.29.1(transitive)
+ Added@rollup/rollup-win32-x64-msvc@4.29.1(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Addedaugnitorecorder@1.0.34(transitive)
+ Addedcommondir@1.0.1(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedfind-cache-dir@3.3.2(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedfs-extra@10.1.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpkg-dir@4.2.0(transitive)
+ Addedrollup@4.29.1(transitive)
+ Addedrollup-plugin-typescript2@0.36.0(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedtypescript@5.7.2(transitive)
+ Addeduniversalify@2.0.1(transitive)