@convai/web-sdk 1.2.0 → 1.2.1-beta.1
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.
- package/README.md +202 -27
- package/dist/core/ConvaiClient.d.ts +8 -7
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +109 -33
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/MessageHandler.d.ts +1 -7
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +35 -27
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/types.d.ts +124 -8
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lipsync-helpers/mappingTypes.d.ts +1 -1
- package/dist/lipsync-helpers/mappingTypes.js +4 -4
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +1 -1
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +2 -1
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/types/index.d.ts +122 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +1 -1
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/index.d.ts +2 -1
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +2 -0
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/types.d.ts +0 -1
- package/dist/vanilla/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/dev.d.ts +0 -12
- package/dist/dev.d.ts.map +0 -1
- package/dist/dev.js +0 -12
- package/dist/dev.js.map +0 -1
- package/dist/utils/LatencyMonitor.d.ts +0 -88
- package/dist/utils/LatencyMonitor.d.ts.map +0 -1
- package/dist/utils/LatencyMonitor.js +0 -136
- package/dist/utils/LatencyMonitor.js.map +0 -1
- package/dist/utils/speakerManagement.d.ts +0 -22
- package/dist/utils/speakerManagement.d.ts.map +0 -1
- package/dist/utils/speakerManagement.js +0 -64
- package/dist/utils/speakerManagement.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LatencyMonitor.d.ts","sourceRoot":"","sources":["../../src/utils/LatencyMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,kBAAkB,CAKV;IAChB,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,SAAS,CAAkB;gBAEvB,OAAO,GAAE,OAAe;IAKpC;;OAEG;IACH,MAAM,IAAI,IAAI;IAKd;;OAEG;IACH,OAAO,IAAI,IAAI;IAKf;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAYpE;;OAEG;IACH,cAAc,IAAI,IAAI;IA+BtB;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;OAEG;IACH,eAAe,IAAI,kBAAkB,EAAE;IAIvC;;OAEG;IACH,oBAAoB,IAAI,kBAAkB,GAAG,IAAI;IAMjD;;OAEG;IACH,QAAQ,IAAI,YAAY,GAAG,IAAI;IAkB/B;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAED;;OAEG;IACH,qBAAqB;YApJf,MAAM;mBACC,MAAM;cACX,MAAM,GAAG,OAAO;sBACR,MAAM;;CAoJvB"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "../core/EventEmitter";
|
|
2
|
-
/**
|
|
3
|
-
* LatencyMonitor - Tracks and manages latency measurements
|
|
4
|
-
* This is for dev/debugging purposes only
|
|
5
|
-
*/
|
|
6
|
-
export class LatencyMonitor extends EventEmitter {
|
|
7
|
-
constructor(enabled = false) {
|
|
8
|
-
super();
|
|
9
|
-
this.measurements = [];
|
|
10
|
-
this.pendingMeasurement = null;
|
|
11
|
-
this.maxMeasurements = 100; // Keep last 100 measurements
|
|
12
|
-
this.isEnabled = false;
|
|
13
|
-
this.isEnabled = enabled;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Enable latency monitoring
|
|
17
|
-
*/
|
|
18
|
-
enable() {
|
|
19
|
-
this.isEnabled = true;
|
|
20
|
-
this.emit("enabledChange", true);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Disable latency monitoring
|
|
24
|
-
*/
|
|
25
|
-
disable() {
|
|
26
|
-
this.isEnabled = false;
|
|
27
|
-
this.emit("enabledChange", false);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if monitoring is enabled
|
|
31
|
-
*/
|
|
32
|
-
get enabled() {
|
|
33
|
-
return this.isEnabled;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Start a new latency measurement
|
|
37
|
-
*/
|
|
38
|
-
startMeasurement(type, userMessage) {
|
|
39
|
-
if (!this.isEnabled)
|
|
40
|
-
return;
|
|
41
|
-
const id = `${type}-${Date.now()}-${Math.random()}`;
|
|
42
|
-
this.pendingMeasurement = {
|
|
43
|
-
id,
|
|
44
|
-
startTime: Date.now(),
|
|
45
|
-
type,
|
|
46
|
-
userMessage: userMessage?.substring(0, 50), // Keep first 50 chars
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Complete the current measurement
|
|
51
|
-
*/
|
|
52
|
-
endMeasurement() {
|
|
53
|
-
if (!this.isEnabled || !this.pendingMeasurement)
|
|
54
|
-
return;
|
|
55
|
-
const endTime = Date.now();
|
|
56
|
-
const latency = endTime - this.pendingMeasurement.startTime;
|
|
57
|
-
const measurement = {
|
|
58
|
-
id: this.pendingMeasurement.id,
|
|
59
|
-
startTime: this.pendingMeasurement.startTime,
|
|
60
|
-
endTime,
|
|
61
|
-
latency,
|
|
62
|
-
type: this.pendingMeasurement.type,
|
|
63
|
-
userMessage: this.pendingMeasurement.userMessage,
|
|
64
|
-
};
|
|
65
|
-
// Add to measurements array
|
|
66
|
-
this.measurements.push(measurement);
|
|
67
|
-
// Keep only the last N measurements
|
|
68
|
-
if (this.measurements.length > this.maxMeasurements) {
|
|
69
|
-
this.measurements.shift();
|
|
70
|
-
}
|
|
71
|
-
// Clear pending measurement
|
|
72
|
-
this.pendingMeasurement = null;
|
|
73
|
-
// Emit new measurement
|
|
74
|
-
this.emit("measurement", measurement);
|
|
75
|
-
this.emit("measurementsChange", this.measurements);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Cancel the current pending measurement
|
|
79
|
-
*/
|
|
80
|
-
cancelMeasurement() {
|
|
81
|
-
this.pendingMeasurement = null;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get all measurements
|
|
85
|
-
*/
|
|
86
|
-
getMeasurements() {
|
|
87
|
-
return [...this.measurements];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get the latest measurement
|
|
91
|
-
*/
|
|
92
|
-
getLatestMeasurement() {
|
|
93
|
-
return this.measurements.length > 0
|
|
94
|
-
? this.measurements[this.measurements.length - 1]
|
|
95
|
-
: null;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get latency statistics
|
|
99
|
-
*/
|
|
100
|
-
getStats() {
|
|
101
|
-
if (this.measurements.length === 0)
|
|
102
|
-
return null;
|
|
103
|
-
const latencies = this.measurements.map((m) => m.latency).sort((a, b) => a - b);
|
|
104
|
-
const sum = latencies.reduce((acc, val) => acc + val, 0);
|
|
105
|
-
const p95Index = Math.floor(latencies.length * 0.95);
|
|
106
|
-
return {
|
|
107
|
-
average: sum / latencies.length,
|
|
108
|
-
min: latencies[0],
|
|
109
|
-
max: latencies[latencies.length - 1],
|
|
110
|
-
median: latencies[Math.floor(latencies.length / 2)],
|
|
111
|
-
p95: latencies[p95Index],
|
|
112
|
-
count: latencies.length,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Clear all measurements
|
|
117
|
-
*/
|
|
118
|
-
clear() {
|
|
119
|
-
this.measurements = [];
|
|
120
|
-
this.pendingMeasurement = null;
|
|
121
|
-
this.emit("measurementsChange", this.measurements);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Check if there's a pending measurement
|
|
125
|
-
*/
|
|
126
|
-
get hasPendingMeasurement() {
|
|
127
|
-
return this.pendingMeasurement !== null;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Get pending measurement info
|
|
131
|
-
*/
|
|
132
|
-
getPendingMeasurement() {
|
|
133
|
-
return this.pendingMeasurement ? { ...this.pendingMeasurement } : null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=LatencyMonitor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LatencyMonitor.js","sourceRoot":"","sources":["../../src/utils/LatencyMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA0BpD;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IAW9C,YAAY,UAAmB,KAAK;QAClC,KAAK,EAAE,CAAC;QAXF,iBAAY,GAAyB,EAAE,CAAC;QACxC,uBAAkB,GAKf,IAAI,CAAC;QACR,oBAAe,GAAW,GAAG,CAAC,CAAC,6BAA6B;QAC5D,cAAS,GAAY,KAAK,CAAC;QAIjC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,IAAsB,EAAE,WAAoB;QAC3D,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,MAAM,EAAE,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC,kBAAkB,GAAG;YACxB,EAAE;YACF,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,IAA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IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,IAAI,qBAAqB;QACvB,OAAO,IAAI,CAAC,kBAAkB,KAAK,IAAI,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,qBAAqB;QACnB,OAAO,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves the speaker ID based on the end user ID.
|
|
3
|
-
*
|
|
4
|
-
* - If endUserId is not provided (anonymous mode), returns null (no speaker ID sent to API)
|
|
5
|
-
* - If endUserId is provided, calls Convai API to get or create a speaker ID for the user
|
|
6
|
-
*
|
|
7
|
-
* @param endUserId - The end user identifier (optional). If not provided, anonymous mode is used.
|
|
8
|
-
* @param apiKey - Convai API key for authentication
|
|
9
|
-
* @returns Promise resolving to the speaker ID or null if no endUserId provided
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolveSpeakerId(endUserId: string | undefined, apiKey: string): Promise<string | null>;
|
|
12
|
-
/**
|
|
13
|
-
* Gets or creates a speaker ID from Convai's speaker management API.
|
|
14
|
-
* If the same endUserId is used multiple times, the same speaker ID is returned (idempotent).
|
|
15
|
-
*
|
|
16
|
-
* @param endUserId - The device or user identifier
|
|
17
|
-
* @param apiKey - Convai API key for authentication
|
|
18
|
-
* @returns Promise resolving to the speaker ID
|
|
19
|
-
* @throws Error if API request fails
|
|
20
|
-
*/
|
|
21
|
-
export declare function getOrCreateSpeakerId(endUserId: string, apiKey: string): Promise<string>;
|
|
22
|
-
//# sourceMappingURL=speakerManagement.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"speakerManagement.d.ts","sourceRoot":"","sources":["../../src/utils/speakerManagement.ts"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAaxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves the speaker ID based on the end user ID.
|
|
3
|
-
*
|
|
4
|
-
* - If endUserId is not provided (anonymous mode), returns null (no speaker ID sent to API)
|
|
5
|
-
* - If endUserId is provided, calls Convai API to get or create a speaker ID for the user
|
|
6
|
-
*
|
|
7
|
-
* @param endUserId - The end user identifier (optional). If not provided, anonymous mode is used.
|
|
8
|
-
* @param apiKey - Convai API key for authentication
|
|
9
|
-
* @returns Promise resolving to the speaker ID or null if no endUserId provided
|
|
10
|
-
*/
|
|
11
|
-
export async function resolveSpeakerId(endUserId, apiKey) {
|
|
12
|
-
// Anonymous mode: No speaker ID (no persistent memory or analytics)
|
|
13
|
-
if (!endUserId) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
// User tracking mode: Get or create speaker ID via Convai API (enables memory and analytics)
|
|
17
|
-
try {
|
|
18
|
-
const speakerId = await getOrCreateSpeakerId(endUserId, apiKey);
|
|
19
|
-
return speakerId;
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Gets or creates a speaker ID from Convai's speaker management API.
|
|
27
|
-
* If the same endUserId is used multiple times, the same speaker ID is returned (idempotent).
|
|
28
|
-
*
|
|
29
|
-
* @param endUserId - The device or user identifier
|
|
30
|
-
* @param apiKey - Convai API key for authentication
|
|
31
|
-
* @returns Promise resolving to the speaker ID
|
|
32
|
-
* @throws Error if API request fails
|
|
33
|
-
*/
|
|
34
|
-
export async function getOrCreateSpeakerId(endUserId, apiKey) {
|
|
35
|
-
const url = 'https://api.convai.com/user/speaker/new';
|
|
36
|
-
try {
|
|
37
|
-
const response = await fetch(url, {
|
|
38
|
-
method: 'POST',
|
|
39
|
-
headers: {
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
'CONVAI-API-KEY': apiKey,
|
|
42
|
-
},
|
|
43
|
-
body: JSON.stringify({
|
|
44
|
-
deviceId: endUserId,
|
|
45
|
-
}),
|
|
46
|
-
});
|
|
47
|
-
if (!response.ok) {
|
|
48
|
-
const errorText = await response.text();
|
|
49
|
-
throw new Error(`Speaker API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
50
|
-
}
|
|
51
|
-
const data = await response.json();
|
|
52
|
-
if (!data.speakerId) {
|
|
53
|
-
throw new Error('Speaker API did not return a speaker ID');
|
|
54
|
-
}
|
|
55
|
-
return data.speakerId;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
throw new Error(`Failed to get speaker ID: ${error.message}`);
|
|
60
|
-
}
|
|
61
|
-
throw new Error('Failed to get speaker ID: Unknown error');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=speakerManagement.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"speakerManagement.js","sourceRoot":"","sources":["../../src/utils/speakerManagement.ts"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA6B,EAC7B,MAAc;IAEd,oEAAoE;IACpE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6FAA6F;IAC7F,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC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