augnitoambientsdk
Advanced tools
Comparing version 1.0.1 to 1.0.5
{ | ||
"name": "augnitoambientsdk", | ||
"version": "1.0.1", | ||
"version": "1.0.5", | ||
"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.5", | ||
"rollup-plugin-typescript2": "^0.36.0" | ||
} | ||
} |
@@ -1,7 +0,9 @@ | ||
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 { 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 +14,40 @@ /** | ||
*/ | ||
export class AugnitoAmbient{ | ||
private _logTag = 'Augnito-Ambient'; | ||
export class AugnitoAmbient { | ||
private _logTag = "Augnito-Ambient"; | ||
private _ambientRestAPI: AmbientRestAPI; | ||
private _wsHandler: websocketHandler; | ||
constructor(config: AmbientConfig){ | ||
// private _wsHandler: websocketHandler; | ||
private config: socketConfig | null | undefined; | ||
private recorderIns: AugnitoRecorder; | ||
constructor(config: AmbientConfig) { | ||
this._ambientRestAPI = new AmbientRestAPI(this.validateConfig(config)); | ||
this._wsHandler = new websocketHandler( | ||
this.createSocketConfig(this.validateConfig(config)) | ||
); | ||
// this._wsHandler = new websocketHandler( | ||
// this.createSocketConfig(this.validateConfig(config)) | ||
// ); | ||
this.recorderIns = new AugnitoRecorder({ | ||
serverURL: this.config?.prepareWSSURL("wav", "") || "", | ||
enableLogs: true, | ||
isDebug: false, | ||
bufferInterval: 1, | ||
EOS_Message: '{"JobAction":"EOS","Status":0,"Type":"meta"}', | ||
socketTimeoutInterval: 10000, | ||
}); | ||
this.recorderIns.onError = this.onErrorCallback.bind(this); | ||
this.recorderIns.onPartialResult = | ||
this.onPartialResultsCallback.bind(this); | ||
this.recorderIns.onFinalResult = this.onSocketFinalResult.bind(this); | ||
this.recorderIns.onStateChanged = this.onStateChangeCallback.bind(this); | ||
this.recorderIns.onSessionEvent = | ||
this.onSessionEventCallback.bind(this); | ||
const _socketConfig = new socketConfig(config); | ||
_socketConfig.onStartOfRecording = | ||
this.recorderIns.onStateChanged.bind(this); | ||
_socketConfig.onStopOfRecording = this.recorderIns.onStateChanged.bind(this);; | ||
_socketConfig.onError = this.recorderIns.onError.bind(this); | ||
_socketConfig.onMetaEvent = this.recorderIns.onSessionEvent.bind(this); | ||
} | ||
/** | ||
* @description Callback to receive the JOb Id | ||
*/ | ||
* @description Callback to receive the JOb Id | ||
*/ | ||
public onJobCreated?: (text: string) => void; | ||
@@ -34,3 +60,3 @@ | ||
/** | ||
/** | ||
* Callback triggered when an error occurs within the SDK | ||
@@ -40,4 +66,11 @@ */ | ||
public onPartialResult?: (text: string) => void; | ||
public onFinalResult?: (text: string) => void; | ||
public onSessionEvent?: (text: string) => void; | ||
public onIdleMic?: () => void; | ||
// #region Public Methods | ||
/** | ||
@@ -47,12 +80,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); | ||
@@ -65,27 +97,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); | ||
@@ -101,12 +128,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); | ||
@@ -122,11 +151,9 @@ } | ||
*/ | ||
public toggleListening(filetype:string, noteparams:any): void { | ||
if (!this._wsHandler) { | ||
Logger.error('SDK not initialized', this._logTag); | ||
return; | ||
public toggleListening(): void { | ||
if (!this.recorderIns) { | ||
Logger.error("SDK not initialized", this._logTag); | ||
return; | ||
} | ||
Guard.Against.NullOrEmpty(filetype, 'FileType'); | ||
Guard.Against.NullOrEmpty(noteparams, 'Note Params'); | ||
this._wsHandler.toggleListening(filetype,noteparams); | ||
} | ||
this.recorderIns.toggleStartStopAudioStream(); | ||
} | ||
@@ -137,20 +164,80 @@ // #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 onPartialResultsCallback(data: string): void { | ||
if (this.onPartialResult) { | ||
this.onPartialResult(data); | ||
} | ||
} | ||
private onSocketFinalResult(data: string): void { | ||
if (this.onFinalResult) { | ||
this.onFinalResult(data); | ||
} | ||
} | ||
private onIdleMicCallback(): void { | ||
if (this.onIdleMic) { | ||
this.onIdleMic(); | ||
} | ||
} | ||
private onSessionEventCallback(data: string | AugnitoSocketResponse): void { | ||
var json = undefined; | ||
if (typeof data === "string") { | ||
json = JSON.parse(data); | ||
} else { | ||
json = data; | ||
} | ||
Logger.log({ type: "onSessionEvent", data: data }, this._logTag); | ||
if (this.onSessionEvent) { | ||
this.onSessionEvent(json); | ||
} | ||
if (typeof json.Event == "string" && json.Event === "None") { | ||
return; | ||
} | ||
const eventType = json.Event.Type; | ||
const eventValue = json.Event.Value; | ||
if (eventType === "SESSION_CREATED") { | ||
const sessionToken = eventValue; | ||
Logger.log("session Token " + sessionToken, this._logTag); | ||
} else if (eventType === "SERVICE_DOWN") { | ||
// Very rare, But This event will come when Speech server's any internal component 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") { | ||
// This event happens when one of following is invalid. | ||
// AccountCode, AccessKey, Active subscription for trial or paid. lmid. | ||
Logger.error("INVALID_AUTH_CREDENTIALS", this._logTag); | ||
Logger.log( | ||
"Invalid authentication, Please check your Account Status, Lm Id and Access Key." | ||
); | ||
} else if (eventType === "LOW_BANDWIDTH") { | ||
// Speech API need continues upload speed of 32KBps if it raw audio data with 16k sampling rate. | ||
// If fluctuation in internet than speech output may be delayed. It's good to notify that speech may delayed due to poor network connection. | ||
// Client app can use this event to show un attendant popup to indicate network status. | ||
Logger.log( | ||
"LOW_BANDWIDTH: Check internet connection", | ||
this._logTag | ||
); | ||
} | ||
} | ||
// #endregion | ||
@@ -163,12 +250,13 @@ | ||
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.onStartOfRecording = | ||
this.onStateChangeCallback.bind(this); | ||
_socketConfig.onStopOfRecording = this.onStateChangeCallback.bind(this); | ||
@@ -179,2 +267,2 @@ _socketConfig.onError = this.onErrorCallback.bind(this); | ||
} | ||
} | ||
} |
@@ -11,3 +11,3 @@ import AmbientConfig from "./AmbientConfig"; | ||
constructor(private _config:AmbientConfig){ | ||
this.wssBaseURL = `wss://${_config.server}/ambient/process-job`; | ||
this.wssBaseURL = `wss://${_config.server}/ambient/stream-job`; | ||
} | ||
@@ -14,0 +14,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
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
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
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
214339
2306
0
2
7
16
3
+ Addedaugnitorecorder@^1.0.5
+ 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)