convo-ai-sdk 1.2.0 → 1.2.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/dist/index.d.ts +5 -1
- package/dist/index.js +32 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,11 @@ export declare class ChatClient {
|
|
|
18
18
|
submitDataMessage(submitType: string | undefined, data: Record<string, any>): Promise<void>;
|
|
19
19
|
requestWidget(widgetType: string, widgetData: any): Promise<void>;
|
|
20
20
|
sendToolResult(toolCallId: string, toolCallName: any, result: any): Promise<void>;
|
|
21
|
-
transcribeAudio(audioBlob: Blob): Promise<
|
|
21
|
+
transcribeAudio(audioBlob: Blob): Promise<{
|
|
22
|
+
text: string;
|
|
23
|
+
transcriptionKey: string;
|
|
24
|
+
cost_analysis: any;
|
|
25
|
+
} | null>;
|
|
22
26
|
sendMessage(text: string): Promise<void>;
|
|
23
27
|
toolCall(tool_call: any): Promise<void>;
|
|
24
28
|
sendStreamMessage(message: ChatMessage): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -223,26 +223,52 @@ export class ChatClient {
|
|
|
223
223
|
async transcribeAudio(audioBlob) {
|
|
224
224
|
if (this.status !== 'connected') {
|
|
225
225
|
console.error('Cannot transcribe audio, not connected.');
|
|
226
|
-
return
|
|
226
|
+
return null;
|
|
227
227
|
}
|
|
228
228
|
if (!this.config.transcribeApiEndpoint) {
|
|
229
229
|
console.error('Transcribe API endpoint not available.');
|
|
230
|
-
return
|
|
230
|
+
return null;
|
|
231
231
|
}
|
|
232
|
-
const
|
|
233
|
-
|
|
232
|
+
const contentType = audioBlob.type || 'application/octet-stream';
|
|
233
|
+
const arrayBuffer = await audioBlob.arrayBuffer();
|
|
234
|
+
const fileBuffer = Buffer.from(arrayBuffer);
|
|
235
|
+
// 1. Get Presigned URL
|
|
236
|
+
const uploadUrlResponse = await fetch(`${this.config.transcribeApiEndpoint}upload-url?contentType=${contentType}`, {
|
|
237
|
+
method: "GET",
|
|
238
|
+
headers: {
|
|
239
|
+
"Authorization": `Bearer ${this.config.sessionToken}`
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
if (!uploadUrlResponse.ok) {
|
|
243
|
+
throw new Error(`HTTP error! status: ${uploadUrlResponse.status}`);
|
|
244
|
+
}
|
|
245
|
+
const { uploadUrl, key } = await uploadUrlResponse.json();
|
|
246
|
+
// 2. Upload File to S3
|
|
247
|
+
// Note: In Node environment with native fetch, we can pass Buffer directly for PUT body
|
|
248
|
+
const uploadResponse = await fetch(uploadUrl, {
|
|
249
|
+
method: "PUT",
|
|
250
|
+
headers: {
|
|
251
|
+
"Content-Type": contentType
|
|
252
|
+
},
|
|
253
|
+
body: fileBuffer
|
|
254
|
+
});
|
|
255
|
+
if (!uploadResponse.ok) {
|
|
256
|
+
throw new Error(`Failed to upload file to S3: ${uploadResponse.statusText}`);
|
|
257
|
+
}
|
|
258
|
+
console.log("File uploaded successfully, key:", key);
|
|
259
|
+
// transcribe file.
|
|
234
260
|
const response = await fetch(this.config.transcribeApiEndpoint + 'transcribe', {
|
|
235
261
|
method: 'POST',
|
|
236
262
|
headers: {
|
|
237
263
|
'Authorization': `Bearer ${this.config.sessionToken}`,
|
|
238
264
|
},
|
|
239
|
-
body:
|
|
265
|
+
body: JSON.stringify({ fileKey: key }),
|
|
240
266
|
});
|
|
241
267
|
if (!response.ok) {
|
|
242
268
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
243
269
|
}
|
|
244
270
|
const responseData = await response.json();
|
|
245
|
-
return responseData
|
|
271
|
+
return responseData;
|
|
246
272
|
}
|
|
247
273
|
async sendMessage(text) {
|
|
248
274
|
if (this.status !== 'connected') {
|